Annotation of loncom/interface/loncreateuser.pm, revision 1.463
1.20 harris41 1: # The LearningOnline Network with CAPA
1.1 www 2: # Create a user
3: #
1.463 ! raeburn 4: # $Id: loncreateuser.pm,v 1.462 2022/11/14 22:33:28 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" ';
1.463 ! raeburn 299: $curr_access =
1.275 raeburn 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: }
1.463 ! raeburn 3430: if ($changed{'aboutme'}) {
! 3431: &Apache::loncommon::devalidate_aboutme_cache($env{'form.ccuname'},
! 3432: $env{'form.ccdomain'});
! 3433: }
1.267 raeburn 3434: }
1.204 raeburn 3435: }
1.334 raeburn 3436: if (keys(%namechanged) > 0) {
1.337 raeburn 3437: foreach my $field (@userinfo) {
3438: $changeHash{$field} = $env{'form.c'.$field};
3439: }
3440: # Make the change
1.204 raeburn 3441: $namechgresult =
3442: &Apache::lonnet::modifyuser($env{'form.ccdomain'},
3443: $env{'form.ccuname'},$changeHash{'id'},undef,undef,
3444: $changeHash{'firstname'},$changeHash{'middlename'},
3445: $changeHash{'lastname'},$changeHash{'generation'},
1.337 raeburn 3446: $changeHash{'id'},undef,$changeHash{'permanentemail'},undef,\@userinfo);
1.220 raeburn 3447: %userupdate = (
3448: lastname => $env{'form.clastname'},
3449: middlename => $env{'form.cmiddlename'},
3450: firstname => $env{'form.cfirstname'},
3451: generation => $env{'form.cgeneration'},
3452: id => $env{'form.cid'},
3453: );
1.204 raeburn 3454: }
1.334 raeburn 3455: if (((keys(%namechanged) > 0) && $namechgresult eq 'ok') ||
1.267 raeburn 3456: ((keys(%changed) > 0) && $chgresult eq 'ok')) {
1.28 matthew 3457: # Tell the user we changed the name
1.334 raeburn 3458: &display_userinfo($r,1,\@disporder,\%canshow,\@requestcourses,
1.362 raeburn 3459: \@usertools,\@requestauthor,\%userenv,\%changed,\%namechanged,
1.334 raeburn 3460: \%oldsettings, \%oldsettingstext,\%newsettings,
3461: \%newsettingstext);
1.203 raeburn 3462: if ($env{'form.cid'} ne $userenv{'id'}) {
3463: &Apache::lonnet::idput($env{'form.ccdomain'},
1.407 raeburn 3464: {$env{'form.ccuname'} => $env{'form.cid'}},$uhome,'ids');
1.203 raeburn 3465: if (($recurseid) &&
3466: (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'}))) {
3467: my $idresult =
3468: &Apache::lonuserutils::propagate_id_change(
3469: $env{'form.ccuname'},$env{'form.ccdomain'},
3470: \%userupdate);
3471: $r->print('<br />'.$idresult.'<br />');
3472: }
1.196 raeburn 3473: }
1.149 raeburn 3474: if (($env{'form.ccdomain'} eq $env{'user.domain'}) &&
3475: ($env{'form.ccuname'} eq $env{'user.name'})) {
3476: my %newenvhash;
3477: foreach my $key (keys(%changeHash)) {
3478: $newenvhash{'environment.'.$key} = $changeHash{$key};
3479: }
1.238 raeburn 3480: &Apache::lonnet::appenv(\%newenvhash);
1.149 raeburn 3481: }
1.28 matthew 3482: } else { # error occurred
1.389 bisitz 3483: $r->print(
3484: '<p class="LC_error">'
3485: .&mt('Unable to successfully change environment for [_1] in domain [_2].',
3486: '"'.$env{'form.ccuname'}.'"',
3487: '"'.$env{'form.ccdomain'}.'"')
3488: .'</p>');
1.28 matthew 3489: }
1.334 raeburn 3490: } else { # End of if ($env ... ) logic
1.275 raeburn 3491: # They did not want to change the users name, quota, tool availability,
3492: # or ability to request creation of courses,
1.267 raeburn 3493: # but we can still tell them what the name and quota and availabilities are
1.334 raeburn 3494: &display_userinfo($r,undef,\@disporder,\%canshow,\@requestcourses,
1.362 raeburn 3495: \@usertools,\@requestauthor,\%userenv,\%changed,\%namechanged,\%oldsettings,
1.334 raeburn 3496: \%oldsettingstext,\%newsettings,\%newsettingstext);
1.28 matthew 3497: }
1.206 raeburn 3498: if (@mod_disallowed) {
3499: my ($rolestr,$contextname);
3500: if (@longroles > 0) {
3501: $rolestr = join(', ',@longroles);
3502: } else {
3503: $rolestr = &mt('No roles');
3504: }
3505: if ($context eq 'course') {
1.399 bisitz 3506: $contextname = 'course';
1.206 raeburn 3507: } elsif ($context eq 'author') {
1.399 bisitz 3508: $contextname = 'co-author';
1.206 raeburn 3509: }
3510: $r->print(&mt('The following fields were not updated: ').'<ul>');
3511: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
3512: foreach my $field (@mod_disallowed) {
3513: $r->print('<li>'.$fieldtitles{$field}.'</li>'."\n");
3514: }
1.207 raeburn 3515: $r->print('</ul>');
3516: if (@mod_disallowed == 1) {
1.399 bisitz 3517: $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 3518: } else {
1.399 bisitz 3519: $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 3520: }
1.292 bisitz 3521: my $helplink = 'javascript:helpMenu('."'display'".')';
3522: $r->print('<span class="LC_cusr_emph">'.$rolestr.'</span><br />'
3523: .&mt('Please contact your [_1]helpdesk[_2] for more information.'
3524: ,'<a href="'.$helplink.'">','</a>')
3525: .'<br />');
1.206 raeburn 3526: }
1.259 bisitz 3527: $r->print('<span class="LC_warning">'
3528: .$no_forceid_alert
3529: .&Apache::lonuserutils::print_namespacing_alerts($env{'form.ccdomain'},\%alerts,\%curr_rules)
3530: .'</span>');
1.4 www 3531: }
1.367 golterma 3532: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
1.220 raeburn 3533: if ($env{'form.action'} eq 'singlestudent') {
1.375 raeburn 3534: &enroll_single_student($r,$uhome,$amode,$genpwd,$now,$newuser,$context,
3535: $crstype,$showcredits,$defaultcredits);
1.386 bisitz 3536: my $linktext = ($crstype eq 'Community' ?
3537: &mt('Enroll Another Member') : &mt('Enroll Another Student'));
3538: $r->print(
3539: &Apache::lonhtmlcommon::actionbox([
3540: '<a href="javascript:backPage(document.userupdate)">'
3541: .($crstype eq 'Community' ?
3542: &mt('Enroll Another Member') : &mt('Enroll Another Student'))
3543: .'</a>']));
1.220 raeburn 3544: } else {
1.375 raeburn 3545: my @rolechanges = &update_roles($r,$context,$showcredits);
1.334 raeburn 3546: if (keys(%namechanged) > 0) {
1.220 raeburn 3547: if ($context eq 'course') {
3548: if (@userroles > 0) {
1.225 raeburn 3549: if ((@rolechanges == 0) ||
3550: (!(grep(/^st$/,@rolechanges)))) {
3551: if (grep(/^st$/,@userroles)) {
3552: my $classlistupdated =
3553: &Apache::lonuserutils::update_classlist($cdom,
1.220 raeburn 3554: $cnum,$env{'form.ccdomain'},
3555: $env{'form.ccuname'},\%userupdate);
1.225 raeburn 3556: }
1.220 raeburn 3557: }
3558: }
3559: }
3560: }
1.226 raeburn 3561: my $userinfo = &Apache::loncommon::plainname($env{'form.ccuname'},
1.233 raeburn 3562: $env{'form.ccdomain'});
3563: if ($env{'form.popup'}) {
3564: $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a></p>');
3565: } else {
1.367 golterma 3566: $r->print('<br />'.&Apache::lonhtmlcommon::actionbox(['<a href="javascript:backPage(document.userupdate,'."'$env{'form.prevphase'}','modify'".')">'
3567: .&mt('Modify this user: [_1]','<span class="LC_cusr_emph">'.$env{'form.ccuname'}.':'.$env{'form.ccdomain'}.' ('.$userinfo.')</span>').'</a>',
3568: '<a href="javascript:backPage(document.userupdate)">'.&mt('Create/Modify Another User').'</a>']));
1.233 raeburn 3569: }
1.220 raeburn 3570: }
3571: }
3572:
1.334 raeburn 3573: sub display_userinfo {
1.362 raeburn 3574: my ($r,$changed,$order,$canshow,$requestcourses,$usertools,$requestauthor,
3575: $userenv,$changedhash,$namechangedhash,$oldsetting,$oldsettingtext,
1.334 raeburn 3576: $newsetting,$newsettingtext) = @_;
3577: return unless (ref($order) eq 'ARRAY' &&
3578: ref($canshow) eq 'HASH' &&
3579: ref($requestcourses) eq 'ARRAY' &&
1.362 raeburn 3580: ref($requestauthor) eq 'ARRAY' &&
1.334 raeburn 3581: ref($usertools) eq 'ARRAY' &&
3582: ref($userenv) eq 'HASH' &&
3583: ref($changedhash) eq 'HASH' &&
3584: ref($oldsetting) eq 'HASH' &&
3585: ref($oldsettingtext) eq 'HASH' &&
3586: ref($newsetting) eq 'HASH' &&
3587: ref($newsettingtext) eq 'HASH');
3588: my %lt=&Apache::lonlocal::texthash(
1.372 raeburn 3589: 'ui' => 'User Information',
1.334 raeburn 3590: 'uic' => 'User Information Changed',
3591: 'firstname' => 'First Name',
3592: 'middlename' => 'Middle Name',
3593: 'lastname' => 'Last Name',
3594: 'generation' => 'Generation',
3595: 'id' => 'Student/Employee ID',
3596: 'permanentemail' => 'Permanent e-mail address',
1.378 raeburn 3597: 'portfolioquota' => 'Disk space allocated to portfolio files',
1.385 bisitz 3598: 'authorquota' => 'Disk space allocated to Authoring Space',
1.334 raeburn 3599: 'blog' => 'Blog Availability',
1.361 raeburn 3600: 'webdav' => 'WebDAV Availability',
1.334 raeburn 3601: 'aboutme' => 'Personal Information Page Availability',
3602: 'portfolio' => 'Portfolio Availability',
1.459 raeburn 3603: 'timezone' => 'Can set own Time Zone',
1.334 raeburn 3604: 'official' => 'Can Request Official Courses',
3605: 'unofficial' => 'Can Request Unofficial Courses',
3606: 'community' => 'Can Request Communities',
1.384 raeburn 3607: 'textbook' => 'Can Request Textbook Courses',
1.411 raeburn 3608: 'placement' => 'Can Request Placement Tests',
1.449 raeburn 3609: 'lti' => 'Can Request LTI Courses',
1.362 raeburn 3610: 'requestauthor' => 'Can Request Author Role',
1.334 raeburn 3611: 'inststatus' => "Affiliation",
3612: 'prvs' => 'Previous Value:',
3613: 'chto' => 'Changed To:'
3614: );
3615: if ($changed) {
1.372 raeburn 3616: $r->print('<h3>'.$lt{'uic'}.'</h3>'.
1.367 golterma 3617: &Apache::loncommon::start_data_table().
3618: &Apache::loncommon::start_data_table_header_row());
1.334 raeburn 3619: $r->print("<th> </th>\n");
1.367 golterma 3620: $r->print('<th><b>'.$lt{'prvs'}.'</b></th>');
3621: $r->print('<th><span class="LC_nobreak"><b>'.$lt{'chto'}.'</b></span></th>');
3622: $r->print(&Apache::loncommon::end_data_table_header_row());
3623: my @userinfo = ('firstname','middlename','lastname','generation','permanentemail','id');
3624:
1.334 raeburn 3625: foreach my $item (@userinfo) {
3626: my $value = $env{'form.c'.$item};
1.367 golterma 3627: #show changes only:
1.383 raeburn 3628: unless ($value eq $userenv->{$item}){
1.367 golterma 3629: $r->print(&Apache::loncommon::start_data_table_row());
3630: $r->print("<td>$lt{$item}</td>\n");
1.383 raeburn 3631: $r->print("<td>".$userenv->{$item}."</td>\n");
1.367 golterma 3632: $r->print("<td>$value </td>\n");
3633: $r->print(&Apache::loncommon::end_data_table_row());
1.334 raeburn 3634: }
3635: }
3636: foreach my $entry (@{$order}) {
1.383 raeburn 3637: if ($canshow->{$entry}) {
3638: if (($entry eq 'requestcourses') || ($entry eq 'reqcrsotherdom') || ($entry eq 'requestauthor')) {
3639: my @items;
3640: if ($entry eq 'requestauthor') {
3641: @items = ($entry);
3642: } else {
3643: @items = @{$requestcourses};
1.384 raeburn 3644: }
1.383 raeburn 3645: foreach my $item (@items) {
3646: if (($newsetting->{$item} ne $oldsetting->{$item}) ||
3647: ($newsettingtext->{$item} ne $oldsettingtext->{$item})) {
3648: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3649: $r->print("<td>$lt{$item}</td>\n");
3650: $r->print("<td>".$oldsetting->{$item});
3651: if ($oldsettingtext->{$item}) {
3652: if ($oldsetting->{$item}) {
3653: $r->print(' -- ');
3654: }
3655: $r->print($oldsettingtext->{$item});
3656: }
3657: $r->print("</td>\n");
3658: $r->print("<td>".$newsetting->{$item});
3659: if ($newsettingtext->{$item}) {
3660: if ($newsetting->{$item}) {
3661: $r->print(' -- ');
3662: }
3663: $r->print($newsettingtext->{$item});
3664: }
3665: $r->print("</td>\n");
3666: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.334 raeburn 3667: }
3668: }
3669: } elsif ($entry eq 'tools') {
3670: foreach my $item (@{$usertools}) {
1.383 raeburn 3671: if ($newsetting->{$item} ne $oldsetting->{$item}) {
3672: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3673: $r->print("<td>$lt{$item}</td>\n");
3674: $r->print("<td>".$oldsetting->{$item}.' '.$oldsettingtext->{$item}."</td>\n");
3675: $r->print("<td>".$newsetting->{$item}.' '.$newsettingtext->{$item}."</td>\n");
3676: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.334 raeburn 3677: }
3678: }
1.378 raeburn 3679: } elsif ($entry eq 'quota') {
3680: if ((ref($oldsetting->{$entry}) eq 'HASH') && (ref($oldsettingtext->{$entry}) eq 'HASH') &&
3681: (ref($newsetting->{$entry}) eq 'HASH') && (ref($newsettingtext->{$entry}) eq 'HASH')) {
3682: foreach my $name ('portfolio','author') {
1.383 raeburn 3683: if ($newsetting->{$entry}->{$name} ne $oldsetting->{$entry}->{$name}) {
3684: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3685: $r->print("<td>$lt{$name.$entry}</td>\n");
3686: $r->print("<td>".$oldsettingtext->{$entry}->{$name}."</td>\n");
3687: $r->print("<td>".$newsettingtext->{$entry}->{$name}."</td>\n");
3688: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.378 raeburn 3689: }
3690: }
3691: }
1.334 raeburn 3692: } else {
1.383 raeburn 3693: if ($newsetting->{$entry} ne $oldsetting->{$entry}) {
3694: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3695: $r->print("<td>$lt{$entry}</td>\n");
3696: $r->print("<td>".$oldsetting->{$entry}.' '.$oldsettingtext->{$entry}."</td>\n");
3697: $r->print("<td>".$newsetting->{$entry}.' '.$newsettingtext->{$entry}."</td>\n");
3698: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.334 raeburn 3699: }
3700: }
3701: }
3702: }
1.367 golterma 3703: $r->print(&Apache::loncommon::end_data_table().'<br />');
1.372 raeburn 3704: } else {
3705: $r->print('<h3>'.$lt{'ui'}.'</h3>'.
3706: '<p>'.&mt('No changes made to user information').'</p>');
1.334 raeburn 3707: }
3708: return;
3709: }
3710:
1.275 raeburn 3711: sub tool_changes {
3712: my ($context,$usertools,$oldaccess,$oldaccesstext,$userenv,$changeHash,
3713: $changed,$newaccess,$newaccesstext) = @_;
3714: if (!((ref($usertools) eq 'ARRAY') && (ref($oldaccess) eq 'HASH') &&
3715: (ref($oldaccesstext) eq 'HASH') && (ref($userenv) eq 'HASH') &&
3716: (ref($changeHash) eq 'HASH') && (ref($changed) eq 'HASH') &&
3717: (ref($newaccess) eq 'HASH') && (ref($newaccesstext) eq 'HASH'))) {
3718: return;
3719: }
1.383 raeburn 3720: my %reqdisplay = &requestchange_display();
1.300 raeburn 3721: if ($context eq 'reqcrsotherdom') {
1.309 raeburn 3722: my @options = ('approval','validate','autolimit');
1.306 raeburn 3723: my $optregex = join('|',@options);
1.300 raeburn 3724: my $cdom = $env{'request.role.domain'};
3725: foreach my $tool (@{$usertools}) {
1.383 raeburn 3726: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
1.314 raeburn 3727: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
1.300 raeburn 3728: $changeHash->{$context.'.'.$tool} = $userenv->{$context.'.'.$tool};
1.383 raeburn 3729: my ($newop,$limit);
1.314 raeburn 3730: if ($env{'form.'.$context.'_'.$tool}) {
3731: $newop = $env{'form.'.$context.'_'.$tool};
3732: if ($newop eq 'autolimit') {
1.383 raeburn 3733: $limit = $env{'form.'.$context.'_'.$tool.'_limit'};
1.314 raeburn 3734: $limit =~ s/\D+//g;
3735: $newop .= '='.$limit;
3736: }
3737: }
1.300 raeburn 3738: if ($userenv->{$context.'.'.$tool} eq '') {
1.314 raeburn 3739: if ($newop) {
3740: $changed->{$tool}=&tool_admin($tool,$cdom.':'.$newop,
1.300 raeburn 3741: $changeHash,$context);
3742: if ($changed->{$tool}) {
1.383 raeburn 3743: if ($newop =~ /^autolimit/) {
3744: if ($limit) {
3745: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3746: } else {
3747: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3748: }
3749: } else {
3750: $newaccesstext->{$tool} = $reqdisplay{$newop};
3751: }
1.300 raeburn 3752: } else {
3753: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
3754: }
3755: }
3756: } else {
3757: my @curr = split(',',$userenv->{$context.'.'.$tool});
3758: my @new;
3759: my $changedoms;
1.314 raeburn 3760: foreach my $req (@curr) {
3761: if ($req =~ /^\Q$cdom\E\:($optregex\=?\d*)$/) {
3762: my $oldop = $1;
1.383 raeburn 3763: if ($oldop =~ /^autolimit=(\d*)/) {
3764: my $limit = $1;
3765: if ($limit) {
3766: $oldaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3767: } else {
3768: $oldaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3769: }
3770: } else {
3771: $oldaccesstext->{$tool} = $reqdisplay{$oldop};
3772: }
1.314 raeburn 3773: if ($oldop ne $newop) {
3774: $changedoms = 1;
3775: foreach my $item (@curr) {
3776: my ($reqdom,$option) = split(':',$item);
3777: unless ($reqdom eq $cdom) {
3778: push(@new,$item);
3779: }
3780: }
3781: if ($newop) {
3782: push(@new,$cdom.':'.$newop);
1.300 raeburn 3783: }
1.314 raeburn 3784: @new = sort(@new);
1.300 raeburn 3785: }
1.314 raeburn 3786: last;
1.300 raeburn 3787: }
1.314 raeburn 3788: }
3789: if ((!$changedoms) && ($newop)) {
1.300 raeburn 3790: $changedoms = 1;
1.306 raeburn 3791: @new = sort(@curr,$cdom.':'.$newop);
1.300 raeburn 3792: }
3793: if ($changedoms) {
1.314 raeburn 3794: my $newdomstr;
1.300 raeburn 3795: if (@new) {
3796: $newdomstr = join(',',@new);
3797: }
3798: $changed->{$tool}=&tool_admin($tool,$newdomstr,$changeHash,
3799: $context);
3800: if ($changed->{$tool}) {
3801: if ($env{'form.'.$context.'_'.$tool}) {
1.306 raeburn 3802: if ($env{'form.'.$context.'_'.$tool} eq 'autolimit') {
1.314 raeburn 3803: my $limit = $env{'form.'.$context.'_'.$tool.'_limit'};
3804: $limit =~ s/\D+//g;
3805: if ($limit) {
1.383 raeburn 3806: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
1.314 raeburn 3807: } else {
1.383 raeburn 3808: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
1.306 raeburn 3809: }
1.314 raeburn 3810: } else {
1.306 raeburn 3811: $newaccesstext->{$tool} = $reqdisplay{$env{'form.'.$context.'_'.$tool}};
3812: }
1.300 raeburn 3813: } else {
1.383 raeburn 3814: $newaccesstext->{$tool} = &mt("availability set to 'off'");
1.300 raeburn 3815: }
3816: }
3817: }
3818: }
3819: }
3820: return;
3821: }
1.275 raeburn 3822: foreach my $tool (@{$usertools}) {
1.383 raeburn 3823: my ($newval,$limit,$envkey);
1.362 raeburn 3824: $envkey = $context.'.'.$tool;
1.306 raeburn 3825: if ($context eq 'requestcourses') {
3826: $newval = $env{'form.crsreq_'.$tool};
3827: if ($newval eq 'autolimit') {
1.383 raeburn 3828: $limit = $env{'form.crsreq_'.$tool.'_limit'};
3829: $limit =~ s/\D+//g;
3830: $newval .= '='.$limit;
1.306 raeburn 3831: }
1.362 raeburn 3832: } elsif ($context eq 'requestauthor') {
3833: $newval = $env{'form.'.$context};
3834: $envkey = $context;
1.314 raeburn 3835: } else {
1.306 raeburn 3836: $newval = $env{'form.'.$context.'_'.$tool};
3837: }
1.362 raeburn 3838: if ($userenv->{$envkey} ne '') {
1.275 raeburn 3839: $oldaccess->{$tool} = &mt('custom');
1.383 raeburn 3840: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3841: if ($userenv->{$envkey} =~ /^autolimit=(\d*)$/) {
3842: my $currlimit = $1;
3843: if ($currlimit eq '') {
3844: $oldaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3845: } else {
3846: $oldaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$currlimit);
3847: }
3848: } elsif ($userenv->{$envkey}) {
3849: $oldaccesstext->{$tool} = $reqdisplay{$userenv->{$envkey}};
3850: } else {
3851: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
3852: }
1.275 raeburn 3853: } else {
1.383 raeburn 3854: if ($userenv->{$envkey}) {
3855: $oldaccesstext->{$tool} = &mt("availability set to 'on'");
3856: } else {
3857: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
3858: }
1.275 raeburn 3859: }
1.362 raeburn 3860: $changeHash->{$envkey} = $userenv->{$envkey};
1.275 raeburn 3861: if ($env{'form.custom'.$tool} == 1) {
1.362 raeburn 3862: if ($newval ne $userenv->{$envkey}) {
1.306 raeburn 3863: $changed->{$tool} = &tool_admin($tool,$newval,$changeHash,
3864: $context);
1.275 raeburn 3865: if ($changed->{$tool}) {
3866: $newaccess->{$tool} = &mt('custom');
1.383 raeburn 3867: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3868: if ($newval =~ /^autolimit/) {
3869: if ($limit) {
3870: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3871: } else {
3872: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3873: }
3874: } elsif ($newval) {
3875: $newaccesstext->{$tool} = $reqdisplay{$newval};
3876: } else {
3877: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3878: }
1.275 raeburn 3879: } else {
1.383 raeburn 3880: if ($newval) {
3881: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3882: } else {
3883: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3884: }
1.275 raeburn 3885: }
3886: } else {
3887: $newaccess->{$tool} = $oldaccess->{$tool};
1.383 raeburn 3888: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3889: if ($newval =~ /^autolimit/) {
3890: if ($limit) {
3891: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3892: } else {
3893: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3894: }
3895: } elsif ($newval) {
3896: $newaccesstext->{$tool} = $reqdisplay{$newval};
3897: } else {
3898: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3899: }
1.275 raeburn 3900: } else {
1.383 raeburn 3901: if ($userenv->{$context.'.'.$tool}) {
3902: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3903: } else {
3904: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3905: }
1.275 raeburn 3906: }
3907: }
3908: } else {
3909: $newaccess->{$tool} = $oldaccess->{$tool};
3910: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
3911: }
3912: } else {
3913: $changed->{$tool} = &tool_admin($tool,'',$changeHash,$context);
3914: if ($changed->{$tool}) {
3915: $newaccess->{$tool} = &mt('default');
3916: } else {
3917: $newaccess->{$tool} = $oldaccess->{$tool};
1.383 raeburn 3918: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3919: if ($newval =~ /^autolimit/) {
3920: if ($limit) {
3921: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3922: } else {
3923: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3924: }
3925: } elsif ($newval) {
3926: $newaccesstext->{$tool} = $reqdisplay{$newval};
3927: } else {
3928: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3929: }
1.275 raeburn 3930: } else {
1.383 raeburn 3931: if ($userenv->{$context.'.'.$tool}) {
3932: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3933: } else {
3934: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3935: }
1.275 raeburn 3936: }
3937: }
3938: }
3939: } else {
3940: $oldaccess->{$tool} = &mt('default');
3941: if ($env{'form.custom'.$tool} == 1) {
1.306 raeburn 3942: $changed->{$tool} = &tool_admin($tool,$newval,$changeHash,
3943: $context);
1.275 raeburn 3944: if ($changed->{$tool}) {
3945: $newaccess->{$tool} = &mt('custom');
1.383 raeburn 3946: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3947: if ($newval =~ /^autolimit/) {
3948: if ($limit) {
3949: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3950: } else {
3951: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3952: }
3953: } elsif ($newval) {
3954: $newaccesstext->{$tool} = $reqdisplay{$newval};
3955: } else {
3956: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3957: }
1.275 raeburn 3958: } else {
1.383 raeburn 3959: if ($newval) {
3960: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3961: } else {
3962: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3963: }
1.275 raeburn 3964: }
3965: } else {
3966: $newaccess->{$tool} = $oldaccess->{$tool};
3967: }
3968: } else {
3969: $newaccess->{$tool} = $oldaccess->{$tool};
3970: }
3971: }
3972: }
3973: return;
3974: }
3975:
1.220 raeburn 3976: sub update_roles {
1.375 raeburn 3977: my ($r,$context,$showcredits) = @_;
1.4 www 3978: my $now=time;
1.225 raeburn 3979: my @rolechanges;
1.220 raeburn 3980: my %disallowed;
1.73 sakharuk 3981: $r->print('<h3>'.&mt('Modifying Roles').'</h3>');
1.404 raeburn 3982: foreach my $key (keys(%env)) {
1.135 raeburn 3983: next if (! $env{$key});
1.190 raeburn 3984: next if ($key eq 'form.action');
1.27 matthew 3985: # Revoke roles
1.135 raeburn 3986: if ($key=~/^form\.rev/) {
3987: if ($key=~/^form\.rev\:([^\_]+)\_([^\_\.]+)$/) {
1.64 www 3988: # Revoke standard role
1.170 albertel 3989: my ($scope,$role) = ($1,$2);
3990: my $result =
3991: &Apache::lonnet::revokerole($env{'form.ccdomain'},
3992: $env{'form.ccuname'},
1.239 raeburn 3993: $scope,$role,'','',$context);
1.367 golterma 3994: $r->print(&Apache::lonhtmlcommon::confirm_success(
1.369 bisitz 3995: &mt('Revoking [_1] in [_2]',
3996: &Apache::lonnet::plaintext($role),
1.372 raeburn 3997: &Apache::loncommon::show_role_extent($scope,$context,$role)),
1.369 bisitz 3998: $result ne "ok").'<br />');
3999: if ($result ne "ok") {
4000: $r->print(&mt('Error: [_1]',$result).'<br />');
4001: }
1.170 albertel 4002: if ($role eq 'st') {
1.202 raeburn 4003: my $result =
1.198 raeburn 4004: &Apache::lonuserutils::classlist_drop($scope,
4005: $env{'form.ccuname'},$env{'form.ccdomain'},
1.202 raeburn 4006: $now);
1.367 golterma 4007: $r->print(&Apache::lonhtmlcommon::confirm_success($result));
1.53 www 4008: }
1.225 raeburn 4009: if (!grep(/^\Q$role\E$/,@rolechanges)) {
4010: push(@rolechanges,$role);
4011: }
1.196 raeburn 4012: }
1.195 raeburn 4013: if ($key=~m{^form\.rev\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}s) {
1.64 www 4014: # Revoke custom role
1.369 bisitz 4015: my $result = &Apache::lonnet::revokecustomrole(
4016: $env{'form.ccdomain'},$env{'form.ccuname'},$1,$2,$3,$4,'','',$context);
1.367 golterma 4017: $r->print(&Apache::lonhtmlcommon::confirm_success(
1.369 bisitz 4018: &mt('Revoking custom role [_1] by [_2] in [_3]',
1.372 raeburn 4019: $4,$3.':'.$2,&Apache::loncommon::show_role_extent($1,$context,'cr')),
1.369 bisitz 4020: $result ne 'ok').'<br />');
4021: if ($result ne "ok") {
4022: $r->print(&mt('Error: [_1]',$result).'<br />');
4023: }
1.225 raeburn 4024: if (!grep(/^cr$/,@rolechanges)) {
4025: push(@rolechanges,'cr');
4026: }
1.64 www 4027: }
1.135 raeburn 4028: } elsif ($key=~/^form\.del/) {
4029: if ($key=~/^form\.del\:([^\_]+)\_([^\_\.]+)$/) {
1.116 raeburn 4030: # Delete standard role
1.170 albertel 4031: my ($scope,$role) = ($1,$2);
4032: my $result =
4033: &Apache::lonnet::assignrole($env{'form.ccdomain'},
4034: $env{'form.ccuname'},
1.239 raeburn 4035: $scope,$role,$now,0,1,'',
4036: $context);
1.367 golterma 4037: $r->print(&Apache::lonhtmlcommon::confirm_success(
4038: &mt('Deleting [_1] in [_2]',
1.369 bisitz 4039: &Apache::lonnet::plaintext($role),
1.372 raeburn 4040: &Apache::loncommon::show_role_extent($scope,$context,$role)),
1.369 bisitz 4041: $result ne 'ok').'<br />');
4042: if ($result ne "ok") {
4043: $r->print(&mt('Error: [_1]',$result).'<br />');
4044: }
1.367 golterma 4045:
1.170 albertel 4046: if ($role eq 'st') {
1.202 raeburn 4047: my $result =
1.198 raeburn 4048: &Apache::lonuserutils::classlist_drop($scope,
4049: $env{'form.ccuname'},$env{'form.ccdomain'},
1.202 raeburn 4050: $now);
1.369 bisitz 4051: $r->print(&Apache::lonhtmlcommon::confirm_success($result));
1.81 albertel 4052: }
1.225 raeburn 4053: if (!grep(/^\Q$role\E$/,@rolechanges)) {
4054: push(@rolechanges,$role);
4055: }
1.116 raeburn 4056: }
1.139 albertel 4057: if ($key=~m{^form\.del\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
1.116 raeburn 4058: my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
4059: # Delete custom role
1.369 bisitz 4060: my $result =
4061: &Apache::lonnet::assigncustomrole($env{'form.ccdomain'},
4062: $env{'form.ccuname'},$url,$rdom,$rnam,$rolename,$now,
4063: 0,1,$context);
4064: $r->print(&Apache::lonhtmlcommon::confirm_success(&mt('Deleting custom role [_1] by [_2] in [_3]',
1.372 raeburn 4065: $rolename,$rnam.':'.$rdom,&Apache::loncommon::show_role_extent($1,$context,'cr')),
1.369 bisitz 4066: $result ne "ok").'<br />');
4067: if ($result ne "ok") {
4068: $r->print(&mt('Error: [_1]',$result).'<br />');
4069: }
1.367 golterma 4070:
1.225 raeburn 4071: if (!grep(/^cr$/,@rolechanges)) {
4072: push(@rolechanges,'cr');
4073: }
1.116 raeburn 4074: }
1.135 raeburn 4075: } elsif ($key=~/^form\.ren/) {
1.101 albertel 4076: my $udom = $env{'form.ccdomain'};
4077: my $uname = $env{'form.ccuname'};
1.116 raeburn 4078: # Re-enable standard role
1.135 raeburn 4079: if ($key=~/^form\.ren\:([^\_]+)\_([^\_\.]+)$/) {
1.89 raeburn 4080: my $url = $1;
4081: my $role = $2;
4082: my $logmsg;
4083: my $output;
4084: if ($role eq 'st') {
1.141 albertel 4085: if ($url =~ m-^/($match_domain)/($match_courseid)/?(\w*)$-) {
1.374 raeburn 4086: my ($cdom,$cnum,$csec) = ($1,$2,$3);
1.375 raeburn 4087: my $credits;
4088: if ($showcredits) {
4089: my $defaultcredits =
4090: &Apache::lonuserutils::get_defaultcredits($cdom,$cnum);
4091: $credits = &get_user_credits($defaultcredits,$cdom,$cnum);
4092: }
4093: my $result = &Apache::loncommon::commit_studentrole(\$logmsg,$udom,$uname,$url,$role,$now,0,$cdom,$cnum,$csec,$context,$credits);
1.220 raeburn 4094: if (($result =~ /^error/) || ($result eq 'not_in_class') || ($result eq 'unknown_course') || ($result eq 'refused')) {
1.223 raeburn 4095: if ($result eq 'refused' && $logmsg) {
4096: $output = $logmsg;
4097: } else {
1.369 bisitz 4098: $output = &mt('Error: [_1]',$result)."\n";
1.223 raeburn 4099: }
1.89 raeburn 4100: } else {
1.372 raeburn 4101: $output = &Apache::lonhtmlcommon::confirm_success(&mt('Assigning [_1] in [_2] starting [_3]',
4102: &Apache::lonnet::plaintext($role),
4103: &Apache::loncommon::show_role_extent($url,$context,'st'),
4104: &Apache::lonlocal::locallocaltime($now))).'<br />'.$logmsg.'<br />';
1.89 raeburn 4105: }
4106: }
4107: } else {
1.101 albertel 4108: my $result=&Apache::lonnet::assignrole($env{'form.ccdomain'},
1.239 raeburn 4109: $env{'form.ccuname'},$url,$role,0,$now,'','',
4110: $context);
1.461 raeburn 4111: $output = &Apache::lonhtmlcommon::confirm_success(&mt('Re-enabling [_1] in [_2]',
4112: &Apache::lonnet::plaintext($role),
4113: &Apache::loncommon::show_role_extent($url,$context,$role)),$result ne "ok").'<br />';
1.369 bisitz 4114: if ($result ne "ok") {
4115: $output .= &mt('Error: [_1]',$result).'<br />';
4116: }
4117: }
1.89 raeburn 4118: $r->print($output);
1.225 raeburn 4119: if (!grep(/^\Q$role\E$/,@rolechanges)) {
4120: push(@rolechanges,$role);
4121: }
1.113 raeburn 4122: }
1.116 raeburn 4123: # Re-enable custom role
1.139 albertel 4124: if ($key=~m{^form\.ren\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
1.116 raeburn 4125: my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
4126: my $result = &Apache::lonnet::assigncustomrole(
4127: $env{'form.ccdomain'}, $env{'form.ccuname'},
1.240 raeburn 4128: $url,$rdom,$rnam,$rolename,0,$now,undef,$context);
1.369 bisitz 4129: $r->print(&Apache::lonhtmlcommon::confirm_success(
4130: &mt('Re-enabling custom role [_1] by [_2] in [_3]',
1.372 raeburn 4131: $rolename,$rnam.':'.$rdom,&Apache::loncommon::show_role_extent($1,$context,'cr')),
1.369 bisitz 4132: $result ne "ok").'<br />');
4133: if ($result ne "ok") {
4134: $r->print(&mt('Error: [_1]',$result).'<br />');
4135: }
1.225 raeburn 4136: if (!grep(/^cr$/,@rolechanges)) {
4137: push(@rolechanges,'cr');
4138: }
1.116 raeburn 4139: }
1.135 raeburn 4140: } elsif ($key=~/^form\.act/) {
1.101 albertel 4141: my $udom = $env{'form.ccdomain'};
4142: my $uname = $env{'form.ccuname'};
1.141 albertel 4143: if ($key=~/^form\.act\_($match_domain)\_($match_courseid)\_cr_cr_($match_domain)_($match_username)_([^\_]+)$/) {
1.65 www 4144: # Activate a custom role
1.83 albertel 4145: my ($one,$two,$three,$four,$five)=($1,$2,$3,$4,$5);
4146: my $url='/'.$one.'/'.$two;
4147: my $full=$one.'_'.$two.'_cr_cr_'.$three.'_'.$four.'_'.$five;
1.65 www 4148:
1.101 albertel 4149: my $start = ( $env{'form.start_'.$full} ?
4150: $env{'form.start_'.$full} :
1.88 raeburn 4151: $now );
1.101 albertel 4152: my $end = ( $env{'form.end_'.$full} ?
4153: $env{'form.end_'.$full} :
1.88 raeburn 4154: 0 );
4155:
4156: # split multiple sections
4157: my %sections = ();
1.461 raeburn 4158: my $num_sections = &build_roles($env{'form.sec_'.$full},\%sections,$five);
1.88 raeburn 4159: if ($num_sections == 0) {
1.240 raeburn 4160: $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$url,$three,$four,$five,$start,$end,$context));
1.88 raeburn 4161: } else {
1.114 albertel 4162: my %curr_groups =
1.117 raeburn 4163: &Apache::longroup::coursegroups($one,$two);
1.404 raeburn 4164: foreach my $sec (sort {$a cmp $b} keys(%sections)) {
1.113 raeburn 4165: if (($sec eq 'none') || ($sec eq 'all') ||
4166: exists($curr_groups{$sec})) {
4167: $disallowed{$sec} = $url;
4168: next;
4169: }
4170: my $securl = $url.'/'.$sec;
1.240 raeburn 4171: $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$securl,$three,$four,$five,$start,$end,$context));
1.88 raeburn 4172: }
4173: }
1.225 raeburn 4174: if (!grep(/^cr$/,@rolechanges)) {
4175: push(@rolechanges,'cr');
4176: }
1.142 raeburn 4177: } elsif ($key=~/^form\.act\_($match_domain)\_($match_name)\_([^\_]+)$/) {
1.27 matthew 4178: # Activate roles for sections with 3 id numbers
4179: # set start, end times, and the url for the class
1.83 albertel 4180: my ($one,$two,$three)=($1,$2,$3);
1.461 raeburn 4181: my $start = ( $env{'form.start_'.$one.'_'.$two.'_'.$three} ?
4182: $env{'form.start_'.$one.'_'.$two.'_'.$three} :
1.27 matthew 4183: $now );
1.461 raeburn 4184: my $end = ( $env{'form.end_'.$one.'_'.$two.'_'.$three} ?
1.101 albertel 4185: $env{'form.end_'.$one.'_'.$two.'_'.$three} :
1.27 matthew 4186: 0 );
1.83 albertel 4187: my $url='/'.$one.'/'.$two;
1.88 raeburn 4188: my $type = 'three';
4189: # split multiple sections
4190: my %sections = ();
1.101 albertel 4191: my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two.'_'.$three},\%sections,$three);
1.375 raeburn 4192: my $credits;
4193: if ($three eq 'st') {
1.461 raeburn 4194: if ($showcredits) {
1.375 raeburn 4195: my $defaultcredits =
4196: &Apache::lonuserutils::get_defaultcredits($one,$two);
4197: $credits = $env{'form.credits_'.$one.'_'.$two.'_'.$three};
4198: $credits =~ s/[^\d\.]//g;
4199: if ($credits eq $defaultcredits) {
4200: undef($credits);
4201: }
4202: }
4203: }
1.88 raeburn 4204: if ($num_sections == 0) {
1.375 raeburn 4205: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'',$context,$credits));
1.88 raeburn 4206: } else {
1.114 albertel 4207: my %curr_groups =
1.117 raeburn 4208: &Apache::longroup::coursegroups($one,$two);
1.88 raeburn 4209: my $emptysec = 0;
1.404 raeburn 4210: foreach my $sec (sort {$a cmp $b} keys(%sections)) {
1.88 raeburn 4211: $sec =~ s/\W//g;
1.113 raeburn 4212: if ($sec ne '') {
4213: if (($sec eq 'none') || ($sec eq 'all') ||
4214: exists($curr_groups{$sec})) {
4215: $disallowed{$sec} = $url;
4216: next;
4217: }
1.88 raeburn 4218: my $securl = $url.'/'.$sec;
1.375 raeburn 4219: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$three,$start,$end,$one,$two,$sec,$context,$credits));
1.88 raeburn 4220: } else {
4221: $emptysec = 1;
4222: }
4223: }
4224: if ($emptysec) {
1.375 raeburn 4225: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'',$context,$credits));
1.88 raeburn 4226: }
1.225 raeburn 4227: }
4228: if (!grep(/^\Q$three\E$/,@rolechanges)) {
4229: push(@rolechanges,$three);
4230: }
1.135 raeburn 4231: } elsif ($key=~/^form\.act\_([^\_]+)\_([^\_]+)$/) {
1.27 matthew 4232: # Activate roles for sections with two id numbers
4233: # set start, end times, and the url for the class
1.461 raeburn 4234: my $start = ( $env{'form.start_'.$1.'_'.$2} ?
4235: $env{'form.start_'.$1.'_'.$2} :
1.27 matthew 4236: $now );
1.461 raeburn 4237: my $end = ( $env{'form.end_'.$1.'_'.$2} ?
1.101 albertel 4238: $env{'form.end_'.$1.'_'.$2} :
1.27 matthew 4239: 0 );
1.225 raeburn 4240: my $one = $1;
4241: my $two = $2;
4242: my $url='/'.$one.'/';
1.88 raeburn 4243: # split multiple sections
4244: my %sections = ();
1.225 raeburn 4245: my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two},\%sections,$two);
1.88 raeburn 4246: if ($num_sections == 0) {
1.240 raeburn 4247: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,'',$context));
1.88 raeburn 4248: } else {
4249: my $emptysec = 0;
1.404 raeburn 4250: foreach my $sec (sort {$a cmp $b} keys(%sections)) {
1.88 raeburn 4251: if ($sec ne '') {
4252: my $securl = $url.'/'.$sec;
1.240 raeburn 4253: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$two,$start,$end,$one,undef,$sec,$context));
1.88 raeburn 4254: } else {
4255: $emptysec = 1;
4256: }
4257: }
4258: if ($emptysec) {
1.240 raeburn 4259: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,'',$context));
1.88 raeburn 4260: }
4261: }
1.225 raeburn 4262: if (!grep(/^\Q$two\E$/,@rolechanges)) {
4263: push(@rolechanges,$two);
4264: }
1.64 www 4265: } else {
1.190 raeburn 4266: $r->print('<p><span class="LC_error">'.&mt('ERROR').': '.&mt('Unknown command').' <tt>'.$key.'</tt></span></p><br />');
1.64 www 4267: }
1.113 raeburn 4268: foreach my $key (sort(keys(%disallowed))) {
1.274 bisitz 4269: $r->print('<p class="LC_warning">');
1.113 raeburn 4270: if (($key eq 'none') || ($key eq 'all')) {
1.274 bisitz 4271: $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 4272: } else {
1.274 bisitz 4273: $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 4274: }
1.274 bisitz 4275: $r->print('</p><p>'
4276: .&mt('Please [_1]go back[_2] and choose a different section name.'
4277: ,'<a href="javascript:history.go(-1)'
4278: ,'</a>')
4279: .'</p><br />'
4280: );
1.113 raeburn 4281: }
4282: }
1.101 albertel 4283: } # End of foreach (keys(%env))
1.75 www 4284: # Flush the course logs so reverse user roles immediately updated
1.349 raeburn 4285: $r->register_cleanup(\&Apache::lonnet::flushcourselogs);
1.225 raeburn 4286: if (@rolechanges == 0) {
1.372 raeburn 4287: $r->print('<p>'.&mt('No roles to modify').'</p>');
1.193 raeburn 4288: }
1.225 raeburn 4289: return @rolechanges;
1.220 raeburn 4290: }
4291:
1.375 raeburn 4292: sub get_user_credits {
4293: my ($uname,$udom,$defaultcredits,$cdom,$cnum) = @_;
4294: if ($cdom eq '' || $cnum eq '') {
4295: return unless ($env{'request.course.id'});
4296: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
4297: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
4298: }
4299: my $credits;
4300: my %currhash =
4301: &Apache::lonnet::get('classlist',[$uname.':'.$udom],$cdom,$cnum);
4302: if (keys(%currhash) > 0) {
4303: my @items = split(/:/,$currhash{$uname.':'.$udom});
4304: my $crdidx = &Apache::loncoursedata::CL_CREDITS() - 3;
4305: $credits = $items[$crdidx];
4306: $credits =~ s/[^\d\.]//g;
4307: }
4308: if ($credits eq $defaultcredits) {
4309: undef($credits);
4310: }
4311: return $credits;
4312: }
4313:
1.220 raeburn 4314: sub enroll_single_student {
1.375 raeburn 4315: my ($r,$uhome,$amode,$genpwd,$now,$newuser,$context,$crstype,
4316: $showcredits,$defaultcredits) = @_;
1.318 raeburn 4317: $r->print('<h3>');
4318: if ($crstype eq 'Community') {
4319: $r->print(&mt('Enrolling Member'));
4320: } else {
4321: $r->print(&mt('Enrolling Student'));
4322: }
4323: $r->print('</h3>');
1.220 raeburn 4324:
4325: # Remove non alphanumeric values from section
4326: $env{'form.sections'}=~s/\W//g;
4327:
1.375 raeburn 4328: my $credits;
4329: if (($showcredits) && ($env{'form.credits'} ne '')) {
4330: $credits = $env{'form.credits'};
4331: $credits =~ s/[^\d\.]//g;
4332: if ($credits ne '') {
4333: if ($credits eq $defaultcredits) {
4334: undef($credits);
4335: }
4336: }
4337: }
4338:
1.220 raeburn 4339: # Clean out any old student roles the user has in this class.
4340: &Apache::lonuserutils::modifystudent($env{'form.ccdomain'},
4341: $env{'form.ccuname'},$env{'request.course.id'},undef,$uhome);
4342: my ($startdate,$enddate) = &Apache::lonuserutils::get_dates_from_form();
4343: my $enroll_result =
4344: &Apache::lonnet::modify_student_enrollment($env{'form.ccdomain'},
4345: $env{'form.ccuname'},$env{'form.cid'},$env{'form.cfirstname'},
4346: $env{'form.cmiddlename'},$env{'form.clastname'},
4347: $env{'form.generation'},$env{'form.sections'},$enddate,
1.375 raeburn 4348: $startdate,'manual',undef,$env{'request.course.id'},'',$context,
4349: $credits);
1.220 raeburn 4350: if ($enroll_result =~ /^ok/) {
1.381 bisitz 4351: $r->print(&mt('[_1] enrolled','<b>'.$env{'form.ccuname'}.':'.$env{'form.ccdomain'}.'</b>'));
1.220 raeburn 4352: if ($env{'form.sections'} ne '') {
4353: $r->print(' '.&mt('in section [_1]',$env{'form.sections'}));
4354: }
4355: my ($showstart,$showend);
4356: if ($startdate <= $now) {
4357: $showstart = &mt('Access starts immediately');
4358: } else {
4359: $showstart = &mt('Access starts: ').&Apache::lonlocal::locallocaltime($startdate);
4360: }
4361: if ($enddate == 0) {
4362: $showend = &mt('ends: no ending date');
4363: } else {
4364: $showend = &mt('ends: ').&Apache::lonlocal::locallocaltime($enddate);
4365: }
4366: $r->print('.<br />'.$showstart.'; '.$showend);
4367: if ($startdate <= $now && !$newuser) {
1.386 bisitz 4368: $r->print('<p class="LC_info">');
1.318 raeburn 4369: if ($crstype eq 'Community') {
1.392 raeburn 4370: $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 4371: } else {
1.392 raeburn 4372: $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 4373: }
4374: $r->print('</p>');
1.220 raeburn 4375: }
4376: } else {
4377: $r->print(&mt('unable to enroll').": ".$enroll_result);
4378: }
4379: return;
1.188 raeburn 4380: }
4381:
1.204 raeburn 4382: sub get_defaultquota_text {
4383: my ($settingstatus) = @_;
4384: my $defquotatext;
4385: if ($settingstatus eq '') {
1.383 raeburn 4386: $defquotatext = &mt('default');
1.204 raeburn 4387: } else {
4388: my ($usertypes,$order) =
4389: &Apache::lonnet::retrieve_inst_usertypes($env{'form.ccdomain'});
4390: if ($usertypes->{$settingstatus} eq '') {
1.383 raeburn 4391: $defquotatext = &mt('default');
1.204 raeburn 4392: } else {
1.383 raeburn 4393: $defquotatext = &mt('default for [_1]',$usertypes->{$settingstatus});
1.204 raeburn 4394: }
4395: }
4396: return $defquotatext;
4397: }
4398:
1.188 raeburn 4399: sub update_result_form {
4400: my ($uhome) = @_;
4401: my $outcome =
1.367 golterma 4402: '<form name="userupdate" method="post" action="">'."\n";
1.160 raeburn 4403: foreach my $item ('srchby','srchin','srchtype','srchterm','srchdomain','ccuname','ccdomain') {
1.188 raeburn 4404: $outcome .= '<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n";
1.160 raeburn 4405: }
1.207 raeburn 4406: if ($env{'form.origname'} ne '') {
4407: $outcome .= '<input type="hidden" name="origname" value="'.$env{'form.origname'}.'" />'."\n";
4408: }
1.160 raeburn 4409: foreach my $item ('sortby','seluname','seludom') {
4410: if (exists($env{'form.'.$item})) {
1.188 raeburn 4411: $outcome .= '<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n";
1.160 raeburn 4412: }
4413: }
1.188 raeburn 4414: if ($uhome eq 'no_host') {
4415: $outcome .= '<input type="hidden" name="forcenewuser" value="1" />'."\n";
4416: }
4417: $outcome .= '<input type="hidden" name="phase" value="" />'."\n".
1.383 raeburn 4418: '<input type="hidden" name="currstate" value="" />'."\n".
4419: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n".
1.188 raeburn 4420: '</form>';
4421: return $outcome;
1.4 www 4422: }
4423:
1.149 raeburn 4424: sub quota_admin {
1.378 raeburn 4425: my ($setquota,$changeHash,$name) = @_;
1.149 raeburn 4426: my $quotachanged;
4427: if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
4428: # Current user has quota modification privileges
1.267 raeburn 4429: if (ref($changeHash) eq 'HASH') {
4430: $quotachanged = 1;
1.378 raeburn 4431: $changeHash->{$name.'quota'} = $setquota;
1.267 raeburn 4432: }
1.149 raeburn 4433: }
4434: return $quotachanged;
4435: }
4436:
1.267 raeburn 4437: sub tool_admin {
1.275 raeburn 4438: my ($tool,$settool,$changeHash,$context) = @_;
4439: my $canchange = 0;
1.279 raeburn 4440: if ($context eq 'requestcourses') {
1.275 raeburn 4441: if (&Apache::lonnet::allowed('ccc',$env{'form.ccdomain'})) {
4442: $canchange = 1;
4443: }
1.300 raeburn 4444: } elsif ($context eq 'reqcrsotherdom') {
4445: if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
4446: $canchange = 1;
4447: }
1.362 raeburn 4448: } elsif ($context eq 'requestauthor') {
4449: if (&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) {
4450: $canchange = 1;
4451: }
1.275 raeburn 4452: } elsif (&Apache::lonnet::allowed('mut',$env{'form.ccdomain'})) {
4453: # Current user has quota modification privileges
4454: $canchange = 1;
4455: }
1.267 raeburn 4456: my $toolchanged;
1.275 raeburn 4457: if ($canchange) {
1.267 raeburn 4458: if (ref($changeHash) eq 'HASH') {
4459: $toolchanged = 1;
1.362 raeburn 4460: if ($tool eq 'requestauthor') {
4461: $changeHash->{$context} = $settool;
4462: } else {
4463: $changeHash->{$context.'.'.$tool} = $settool;
4464: }
1.267 raeburn 4465: }
4466: }
4467: return $toolchanged;
4468: }
4469:
1.88 raeburn 4470: sub build_roles {
1.89 raeburn 4471: my ($sectionstr,$sections,$role) = @_;
1.88 raeburn 4472: my $num_sections = 0;
4473: if ($sectionstr=~ /,/) {
4474: my @secnums = split/,/,$sectionstr;
1.89 raeburn 4475: if ($role eq 'st') {
4476: $secnums[0] =~ s/\W//g;
4477: $$sections{$secnums[0]} = 1;
4478: $num_sections = 1;
4479: } else {
4480: foreach my $sec (@secnums) {
4481: $sec =~ ~s/\W//g;
1.150 banghart 4482: if (!($sec eq "")) {
1.89 raeburn 4483: if (exists($$sections{$sec})) {
4484: $$sections{$sec} ++;
4485: } else {
4486: $$sections{$sec} = 1;
4487: $num_sections ++;
4488: }
1.88 raeburn 4489: }
4490: }
4491: }
4492: } else {
4493: $sectionstr=~s/\W//g;
4494: unless ($sectionstr eq '') {
4495: $$sections{$sectionstr} = 1;
4496: $num_sections ++;
4497: }
4498: }
1.129 albertel 4499:
1.88 raeburn 4500: return $num_sections;
4501: }
4502:
1.58 www 4503: # ========================================================== Custom Role Editor
4504:
4505: sub custom_role_editor {
1.439 raeburn 4506: my ($r,$context,$brcrum,$prefix,$permission) = @_;
1.324 raeburn 4507: my $action = $env{'form.customroleaction'};
1.439 raeburn 4508: my ($rolename,$helpitem);
1.324 raeburn 4509: if ($action eq 'new') {
4510: $rolename=$env{'form.newrolename'};
4511: } else {
4512: $rolename=$env{'form.rolename'};
1.59 www 4513: }
4514:
1.324 raeburn 4515: my ($crstype,$context);
4516: if ($env{'request.course.id'}) {
4517: $crstype = &Apache::loncommon::course_type();
4518: $context = 'course';
1.439 raeburn 4519: $helpitem = 'Course_Editing_Custom_Roles';
1.324 raeburn 4520: } else {
4521: $context = 'domain';
1.414 raeburn 4522: $crstype = 'course';
1.439 raeburn 4523: $helpitem = 'Domain_Editing_Custom_Roles';
1.324 raeburn 4524: }
1.351 raeburn 4525:
4526: $rolename=~s/[^A-Za-z0-9]//gs;
4527: if (!$rolename || $env{'form.phase'} eq 'pickrole') {
1.439 raeburn 4528: &print_username_entry_form($r,$context,undef,undef,undef,$crstype,$brcrum,
4529: $permission);
1.351 raeburn 4530: return;
4531: }
4532:
1.414 raeburn 4533: my $formname = 'form1';
4534: my %privs=();
4535: my $body_top = '<h2>';
4536: # ------------------------------------------------------- Does this role exist?
1.59 www 4537: my ($rdummy,$roledef)=
4538: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
4539: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1.414 raeburn 4540: $body_top .= &mt('Existing Role').' "';
1.61 www 4541: # ------------------------------------------------- Get current role privileges
1.414 raeburn 4542: ($privs{'system'},$privs{'domain'},$privs{'course'})=split(/\_/,$roledef);
4543: if ($privs{'system'} =~ /bre\&S/) {
4544: if ($context eq 'domain') {
1.417 raeburn 4545: $crstype = 'Course';
1.414 raeburn 4546: } elsif ($crstype eq 'Community') {
4547: $privs{'system'} =~ s/bre\&S//;
4548: }
4549: } elsif ($context eq 'domain') {
4550: $crstype = 'Course';
1.324 raeburn 4551: }
1.59 www 4552: } else {
1.414 raeburn 4553: $body_top .= &mt('New Role').' "';
4554: $roledef='';
1.59 www 4555: }
1.153 banghart 4556: $body_top .= $rolename.'"</h2>';
1.414 raeburn 4557:
4558: # ------------------------------------------------------- What can be assigned?
4559: my %full=();
1.417 raeburn 4560: my %levels=(
1.414 raeburn 4561: course => {},
4562: domain => {},
4563: system => {},
4564: );
4565: my %levelscurrent=(
4566: course => {},
4567: domain => {},
4568: system => {},
4569: );
4570: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
1.160 raeburn 4571: my ($jsback,$elements) = &crumb_utilities();
1.414 raeburn 4572: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
1.417 raeburn 4573: my $head_script =
1.414 raeburn 4574: &Apache::lonuserutils::custom_roledefs_js($context,$crstype,$formname,
4575: \%full,\@templateroles,$jsback);
1.351 raeburn 4576: push (@{$brcrum},
1.414 raeburn 4577: {href => "javascript:backPage(document.$formname,'pickrole','')",
1.351 raeburn 4578: text => "Pick custom role",
4579: faq => 282,bug=>'Instructor Interface',},
1.414 raeburn 4580: {href => "javascript:backPage(document.$formname,'','')",
1.351 raeburn 4581: text => "Edit custom role",
4582: faq => 282,
4583: bug => 'Instructor Interface',
1.439 raeburn 4584: help => $helpitem}
1.351 raeburn 4585: );
4586: my $args = { bread_crumbs => $brcrum,
4587: bread_crumbs_component => 'User Management'};
4588: $r->print(&Apache::loncommon::start_page('Custom Role Editor',
4589: $head_script,$args).
4590: $body_top);
1.414 raeburn 4591: $r->print('<form name="'.$formname.'" method="post" action="">'."\n".
4592: &Apache::lonuserutils::custom_role_header($context,$crstype,
4593: \@templateroles,$prefix));
1.264 bisitz 4594:
1.61 www 4595: $r->print(<<ENDCCF);
4596: <input type="hidden" name="phase" value="set_custom_roles" />
4597: <input type="hidden" name="rolename" value="$rolename" />
4598: ENDCCF
1.414 raeburn 4599: $r->print(&Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
4600: \%levelscurrent,$prefix));
1.135 raeburn 4601: $r->print(&Apache::loncommon::end_data_table().
1.190 raeburn 4602: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'.
1.160 raeburn 4603: '<input type="hidden" name="startrolename" value="'.$env{'form.rolename'}.
1.417 raeburn 4604: '" />'."\n".'<input type="hidden" name="currstate" value="" />'."\n".
1.160 raeburn 4605: '<input type="reset" value="'.&mt("Reset").'" />'."\n".
1.351 raeburn 4606: '<input type="submit" value="'.&mt('Save').'" /></form>');
1.61 www 4607: }
1.414 raeburn 4608:
1.61 www 4609: # ---------------------------------------------------------- Call to definerole
4610: sub set_custom_role {
1.439 raeburn 4611: my ($r,$context,$brcrum,$prefix,$permission) = @_;
1.101 albertel 4612: my $rolename=$env{'form.rolename'};
1.63 www 4613: $rolename=~s/[^A-Za-z0-9]//gs;
1.150 banghart 4614: if (!$rolename) {
1.439 raeburn 4615: &custom_role_editor($r,$context,$brcrum,$prefix,$permission);
1.61 www 4616: return;
4617: }
1.160 raeburn 4618: my ($jsback,$elements) = &crumb_utilities();
1.301 bisitz 4619: my $jscript = '<script type="text/javascript">'
4620: .'// <![CDATA['."\n"
4621: .$jsback."\n"
4622: .'// ]]>'."\n"
4623: .'</script>'."\n";
1.439 raeburn 4624: my $helpitem = 'Course_Editing_Custom_Roles';
4625: if ($context eq 'domain') {
4626: $helpitem = 'Domain_Editing_Custom_Roles';
4627: }
1.352 raeburn 4628: push(@{$brcrum},
4629: {href => "javascript:backPage(document.customresult,'pickrole','')",
4630: text => "Pick custom role",
4631: faq => 282,
4632: bug => 'Instructor Interface',},
4633: {href => "javascript:backPage(document.customresult,'selected_custom_edit','')",
4634: text => "Edit custom role",
4635: faq => 282,
4636: bug => 'Instructor Interface',},
4637: {href => "javascript:backPage(document.customresult,'set_custom_roles','')",
4638: text => "Result",
4639: faq => 282,
4640: bug => 'Instructor Interface',
1.439 raeburn 4641: help => $helpitem,}
1.352 raeburn 4642: );
4643: my $args = { bread_crumbs => $brcrum,
1.414 raeburn 4644: bread_crumbs_component => 'User Management'};
1.351 raeburn 4645: $r->print(&Apache::loncommon::start_page('Save Custom Role',$jscript,$args));
1.160 raeburn 4646:
1.393 raeburn 4647: my $newrole;
1.61 www 4648: my ($rdummy,$roledef)=
1.110 albertel 4649: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
4650:
1.61 www 4651: # ------------------------------------------------------- Does this role exist?
1.188 raeburn 4652: $r->print('<h3>');
1.61 www 4653: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1.73 sakharuk 4654: $r->print(&mt('Existing Role').' "');
1.61 www 4655: } else {
1.73 sakharuk 4656: $r->print(&mt('New Role').' "');
1.61 www 4657: $roledef='';
1.393 raeburn 4658: $newrole = 1;
1.61 www 4659: }
1.188 raeburn 4660: $r->print($rolename.'"</h3>');
1.414 raeburn 4661: # ------------------------------------------------- Assign role and show result
1.61 www 4662:
1.387 bisitz 4663: my $errmsg;
1.414 raeburn 4664: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$prefix);
4665: # Assign role and return result
4666: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
4667: $newprivs{'c'});
1.387 bisitz 4668: if ($result ne 'ok') {
4669: $errmsg = ': '.$result;
4670: }
4671: my $message =
4672: &Apache::lonhtmlcommon::confirm_success(
4673: &mt('Defining Role').$errmsg, ($result eq 'ok' ? 0 : 1));
1.101 albertel 4674: if ($env{'request.course.id'}) {
4675: my $url='/'.$env{'request.course.id'};
1.63 www 4676: $url=~s/\_/\//g;
1.387 bisitz 4677: $result =
4678: &Apache::lonnet::assigncustomrole(
4679: $env{'user.domain'},$env{'user.name'},
4680: $url,
4681: $env{'user.domain'},$env{'user.name'},
4682: $rolename,undef,undef,undef,$context);
4683: if ($result ne 'ok') {
4684: $errmsg = ': '.$result;
4685: }
4686: $message .=
4687: '<br />'
4688: .&Apache::lonhtmlcommon::confirm_success(
4689: &mt('Assigning Role to Self').$errmsg, ($result eq 'ok' ? 0 : 1));
1.63 www 4690: }
1.380 bisitz 4691: $r->print(
1.387 bisitz 4692: &Apache::loncommon::confirmwrapper($message)
4693: .'<br />'
4694: .&Apache::lonhtmlcommon::actionbox([
4695: '<a href="javascript:backPage(document.customresult,'."'pickrole'".')">'
4696: .&mt('Create or edit another custom role')
4697: .'</a>'])
1.380 bisitz 4698: .'<form name="customresult" method="post" action="">'
1.387 bisitz 4699: .&Apache::lonhtmlcommon::echo_form_input([])
4700: .'</form>'
1.380 bisitz 4701: );
1.58 www 4702: }
4703:
1.2 www 4704: # ================================================================ Main Handler
4705: sub handler {
4706: my $r = shift;
4707: if ($r->header_only) {
1.68 www 4708: &Apache::loncommon::content_type($r,'text/html');
1.2 www 4709: $r->send_http_header;
4710: return OK;
4711: }
1.439 raeburn 4712: my ($context,$crstype,$cid,$cnum,$cdom,$allhelpitems);
4713:
1.190 raeburn 4714: if ($env{'request.course.id'}) {
4715: $context = 'course';
1.318 raeburn 4716: $crstype = &Apache::loncommon::course_type();
1.190 raeburn 4717: } elsif ($env{'request.role'} =~ /^au\./) {
1.206 raeburn 4718: $context = 'author';
1.190 raeburn 4719: } else {
4720: $context = 'domain';
4721: }
1.375 raeburn 4722:
1.439 raeburn 4723: my ($permission,$allowed) =
4724: &Apache::lonuserutils::get_permission($context,$crstype);
4725:
4726: if ($allowed) {
4727: my @allhelp;
4728: if ($context eq 'course') {
4729: $cid = $env{'request.course.id'};
4730: $cdom = $env{'course.'.$cid.'.domain'};
4731: $cnum = $env{'course.'.$cid.'.num'};
4732:
4733: if ($permission->{'cusr'}) {
4734: push(@allhelp,'Course_Create_Class_List');
4735: }
4736: if ($permission->{'view'} || $permission->{'cusr'}) {
4737: push(@allhelp,('Course_Change_Privileges','Course_View_Class_List'));
4738: }
4739: if ($permission->{'custom'}) {
4740: push(@allhelp,'Course_Editing_Custom_Roles');
4741: }
4742: if ($permission->{'cusr'}) {
4743: push(@allhelp,('Course_Add_Student','Course_Drop_Student'));
4744: }
4745: unless ($permission->{'cusr_section'}) {
4746: if (&Apache::lonnet::auto_run($cnum,$cdom) && (($permission->{'cusr'}) || ($permission->{'view'}))) {
4747: push(@allhelp,'Course_Automated_Enrollment');
4748: }
4749: if ($permission->{'selfenrolladmin'}) {
4750: push(@allhelp,'Course_Approve_Selfenroll');
4751: }
4752: }
4753: if ($permission->{'grp_manage'}) {
4754: push(@allhelp,'Course_Manage_Group');
4755: }
4756: if ($permission->{'view'} || $permission->{'cusr'}) {
4757: push(@allhelp,'Course_User_Logs');
4758: }
4759: } elsif ($context eq 'author') {
4760: push(@allhelp,('Author_Change_Privileges','Author_Create_Coauthor_List',
4761: 'Author_View_Coauthor_List','Author_User_Logs'));
4762: } else {
4763: if ($permission->{'cusr'}) {
4764: push(@allhelp,'Domain_Change_Privileges');
4765: if ($permission->{'activity'}) {
4766: push(@allhelp,'Domain_User_Access_Logs');
4767: }
4768: push(@allhelp,('Domain_Create_Users','Domain_View_Users_List'));
4769: if ($permission->{'custom'}) {
4770: push(@allhelp,'Domain_Editing_Custom_Roles');
4771: }
4772: push(@allhelp,('Domain_Role_Approvals','Domain_Username_Approvals','Domain_Change_Logs'));
4773: } elsif ($permission->{'view'}) {
4774: push(@allhelp,'Domain_View_Privileges');
4775: if ($permission->{'activity'}) {
4776: push(@allhelp,'Domain_User_Access_Logs');
4777: }
4778: push(@allhelp,('Domain_View_Users_List','Domain_Change_Logs'));
4779: }
4780: }
4781: if (@allhelp) {
4782: $allhelpitems = join(',',@allhelp);
4783: }
4784: }
4785:
1.190 raeburn 4786: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.233 raeburn 4787: ['action','state','callingform','roletype','showrole','bulkaction','popup','phase',
1.391 raeburn 4788: 'username','domain','srchterm','srchdomain','srchin','srchby','srchtype','queue']);
1.190 raeburn 4789: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.351 raeburn 4790: my $args;
4791: my $brcrum = [];
4792: my $bread_crumbs_component = 'User Management';
1.391 raeburn 4793: if (($env{'form.action'} ne 'dateselect') && ($env{'form.action'} ne 'displayuserreq')) {
1.351 raeburn 4794: $brcrum = [{href=>"/adm/createuser",
4795: text=>"User Management",
1.439 raeburn 4796: help=>$allhelpitems}
1.351 raeburn 4797: ];
1.202 raeburn 4798: }
1.190 raeburn 4799: if (!$allowed) {
1.358 raeburn 4800: if ($context eq 'course') {
4801: $r->internal_redirect('/adm/viewclasslist');
4802: return OK;
4803: }
1.190 raeburn 4804: $env{'user.error.msg'}=
4805: "/adm/createuser:cst:0:0:Cannot create/modify user data ".
4806: "or view user status.";
4807: return HTTP_NOT_ACCEPTABLE;
4808: }
4809:
4810: &Apache::loncommon::content_type($r,'text/html');
4811: $r->send_http_header;
4812:
1.375 raeburn 4813: my $showcredits;
4814: if ((($context eq 'course') && ($crstype eq 'Course')) ||
4815: ($context eq 'domain')) {
4816: my %domdefaults =
4817: &Apache::lonnet::get_domain_defaults($env{'request.role.domain'});
4818: if ($domdefaults{'officialcredits'} || $domdefaults{'unofficialcredits'}) {
4819: $showcredits = 1;
4820: }
4821: }
4822:
1.190 raeburn 4823: # Main switch on form.action and form.state, as appropriate
4824: if (! exists($env{'form.action'})) {
1.351 raeburn 4825: $args = {bread_crumbs => $brcrum,
4826: bread_crumbs_component => $bread_crumbs_component};
4827: $r->print(&header(undef,$args));
1.318 raeburn 4828: $r->print(&print_main_menu($permission,$context,$crstype));
1.190 raeburn 4829: } elsif ($env{'form.action'} eq 'upload' && $permission->{'cusr'}) {
1.439 raeburn 4830: my $helpitem = 'Course_Create_Class_List';
4831: if ($context eq 'author') {
4832: $helpitem = 'Author_Create_Coauthor_List';
4833: } elsif ($context eq 'domain') {
4834: $helpitem = 'Domain_Create_Users';
4835: }
1.351 raeburn 4836: push(@{$brcrum},
4837: { href => '/adm/createuser?action=upload&state=',
4838: text => 'Upload Users List',
1.439 raeburn 4839: help => $helpitem,
1.351 raeburn 4840: });
4841: $bread_crumbs_component = 'Upload Users List';
4842: $args = {bread_crumbs => $brcrum,
4843: bread_crumbs_component => $bread_crumbs_component};
4844: $r->print(&header(undef,$args));
1.190 raeburn 4845: $r->print('<form name="studentform" method="post" '.
4846: 'enctype="multipart/form-data" '.
4847: ' action="/adm/createuser">'."\n");
4848: if (! exists($env{'form.state'})) {
4849: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
4850: } elsif ($env{'form.state'} eq 'got_file') {
1.448 raeburn 4851: my $result =
4852: &Apache::lonuserutils::print_upload_manager_form($r,$context,
4853: $permission,
4854: $crstype,$showcredits);
4855: if ($result eq 'missingdata') {
4856: delete($env{'form.state'});
4857: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
4858: }
1.190 raeburn 4859: } elsif ($env{'form.state'} eq 'enrolling') {
4860: if ($env{'form.datatoken'}) {
1.448 raeburn 4861: my $result = &Apache::lonuserutils::upfile_drop_add($r,$context,
4862: $permission,
4863: $showcredits);
4864: if ($result eq 'missingdata') {
4865: delete($env{'form.state'});
4866: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
4867: } elsif ($result eq 'invalidhome') {
4868: $env{'form.state'} = 'got_file';
4869: delete($env{'form.lcserver'});
4870: my $result =
4871: &Apache::lonuserutils::print_upload_manager_form($r,$context,$permission,
4872: $crstype,$showcredits);
4873: if ($result eq 'missingdata') {
4874: delete($env{'form.state'});
4875: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
4876: }
4877: }
4878: } else {
4879: delete($env{'form.state'});
4880: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
1.190 raeburn 4881: }
4882: } else {
4883: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
4884: }
1.447 raeburn 4885: $r->print('</form>');
1.416 raeburn 4886: } elsif (((($env{'form.action'} eq 'singleuser') || ($env{'form.action'}
4887: eq 'singlestudent')) && ($permission->{'cusr'})) ||
1.418 raeburn 4888: (($env{'form.action'} eq 'singleuser') && ($permission->{'view'})) ||
1.416 raeburn 4889: (($env{'form.action'} eq 'accesslogs') && ($permission->{'activity'}))) {
1.190 raeburn 4890: my $phase = $env{'form.phase'};
4891: my @search = ('srchterm','srchby','srchin','srchtype','srchdomain');
1.192 albertel 4892: &Apache::loncreateuser::restore_prev_selections();
4893: my $srch;
4894: foreach my $item (@search) {
4895: $srch->{$item} = $env{'form.'.$item};
4896: }
1.207 raeburn 4897: if (($phase eq 'get_user_info') || ($phase eq 'userpicked') ||
1.416 raeburn 4898: ($phase eq 'createnewuser') || ($phase eq 'activity')) {
1.207 raeburn 4899: if ($env{'form.phase'} eq 'createnewuser') {
4900: my $response;
4901: if ($env{'form.srchterm'} !~ /^$match_username$/) {
1.366 bisitz 4902: my $response =
4903: '<span class="LC_warning">'
4904: .&mt('You must specify a valid username. Only the following are allowed:'
4905: .' letters numbers - . @')
4906: .'</span>';
1.221 raeburn 4907: $env{'form.phase'} = '';
1.375 raeburn 4908: &print_username_entry_form($r,$context,$response,$srch,undef,
1.439 raeburn 4909: $crstype,$brcrum,$permission);
1.207 raeburn 4910: } else {
4911: my $ccuname =&LONCAPA::clean_username($srch->{'srchterm'});
4912: my $ccdomain=&LONCAPA::clean_domain($srch->{'srchdomain'});
4913: &print_user_modification_page($r,$ccuname,$ccdomain,
1.221 raeburn 4914: $srch,$response,$context,
1.375 raeburn 4915: $permission,$crstype,$brcrum,
4916: $showcredits);
1.207 raeburn 4917: }
4918: } elsif ($env{'form.phase'} eq 'get_user_info') {
1.190 raeburn 4919: my ($currstate,$response,$forcenewuser,$results) =
1.221 raeburn 4920: &user_search_result($context,$srch);
1.190 raeburn 4921: if ($env{'form.currstate'} eq 'modify') {
4922: $currstate = $env{'form.currstate'};
4923: }
4924: if ($currstate eq 'select') {
4925: &print_user_selection_page($r,$response,$srch,$results,
1.351 raeburn 4926: \@search,$context,undef,$crstype,
4927: $brcrum);
1.416 raeburn 4928: } elsif (($currstate eq 'modify') || ($env{'form.action'} eq 'accesslogs')) {
4929: my ($ccuname,$ccdomain,$uhome);
1.190 raeburn 4930: if (($srch->{'srchby'} eq 'uname') &&
4931: ($srch->{'srchtype'} eq 'exact')) {
4932: $ccuname = $srch->{'srchterm'};
4933: $ccdomain= $srch->{'srchdomain'};
4934: } else {
4935: my @matchedunames = keys(%{$results});
4936: ($ccuname,$ccdomain) = split(/:/,$matchedunames[0]);
4937: }
4938: $ccuname =&LONCAPA::clean_username($ccuname);
4939: $ccdomain=&LONCAPA::clean_domain($ccdomain);
1.416 raeburn 4940: if ($env{'form.action'} eq 'accesslogs') {
4941: my $uhome;
4942: if (($ccuname ne '') && ($ccdomain ne '')) {
4943: $uhome = &Apache::lonnet::homeserver($ccuname,$ccdomain);
4944: }
4945: if (($uhome eq '') || ($uhome eq 'no_host')) {
4946: $env{'form.phase'} = '';
4947: undef($forcenewuser);
4948: #if ($response) {
4949: # unless ($response =~ m{\Q<br /><br />\E$}) {
4950: # $response .= '<br /><br />';
4951: # }
4952: #}
4953: &print_username_entry_form($r,$context,$response,$srch,
1.439 raeburn 4954: $forcenewuser,$crstype,$brcrum,
4955: $permission);
1.416 raeburn 4956: } else {
4957: &print_useraccesslogs_display($r,$ccuname,$ccdomain,$permission,$brcrum);
4958: }
4959: } else {
4960: if ($env{'form.forcenewuser'}) {
4961: $response = '';
4962: }
4963: &print_user_modification_page($r,$ccuname,$ccdomain,
4964: $srch,$response,$context,
4965: $permission,$crstype,$brcrum);
1.190 raeburn 4966: }
4967: } elsif ($currstate eq 'query') {
1.351 raeburn 4968: &print_user_query_page($r,'createuser',$brcrum);
1.190 raeburn 4969: } else {
1.229 raeburn 4970: $env{'form.phase'} = '';
1.207 raeburn 4971: &print_username_entry_form($r,$context,$response,$srch,
1.439 raeburn 4972: $forcenewuser,$crstype,$brcrum,
4973: $permission);
1.190 raeburn 4974: }
4975: } elsif ($env{'form.phase'} eq 'userpicked') {
4976: my $ccuname = &LONCAPA::clean_username($env{'form.seluname'});
4977: my $ccdomain = &LONCAPA::clean_domain($env{'form.seludom'});
1.416 raeburn 4978: if ($env{'form.action'} eq 'accesslogs') {
4979: &print_useraccesslogs_display($r,$ccuname,$ccdomain,$permission,$brcrum);
4980: } else {
4981: &print_user_modification_page($r,$ccuname,$ccdomain,$srch,'',
4982: $context,$permission,$crstype,
4983: $brcrum);
4984: }
4985: } elsif ($env{'form.action'} eq 'accesslogs') {
4986: my $ccuname = &LONCAPA::clean_username($env{'form.accessuname'});
4987: my $ccdomain = &LONCAPA::clean_domain($env{'form.accessudom'});
4988: &print_useraccesslogs_display($r,$ccuname,$ccdomain,$permission,$brcrum);
1.190 raeburn 4989: }
4990: } elsif ($env{'form.phase'} eq 'update_user_data') {
1.451 raeburn 4991: &update_user_data($r,$context,$crstype,$brcrum,$showcredits,$permission);
1.190 raeburn 4992: } else {
1.351 raeburn 4993: &print_username_entry_form($r,$context,undef,$srch,undef,$crstype,
1.439 raeburn 4994: $brcrum,$permission);
1.190 raeburn 4995: }
4996: } elsif ($env{'form.action'} eq 'custom' && $permission->{'custom'}) {
1.414 raeburn 4997: my $prefix;
1.190 raeburn 4998: if ($env{'form.phase'} eq 'set_custom_roles') {
1.439 raeburn 4999: &set_custom_role($r,$context,$brcrum,$prefix,$permission);
1.190 raeburn 5000: } else {
1.439 raeburn 5001: &custom_role_editor($r,$context,$brcrum,$prefix,$permission);
1.190 raeburn 5002: }
1.362 raeburn 5003: } elsif (($env{'form.action'} eq 'processauthorreq') &&
5004: ($permission->{'cusr'}) &&
5005: (&Apache::lonnet::allowed('cau',$env{'request.role.domain'}))) {
5006: push(@{$brcrum},
5007: {href => '/adm/createuser?action=processauthorreq',
1.385 bisitz 5008: text => 'Authoring Space requests',
1.362 raeburn 5009: help => 'Domain_Role_Approvals'});
5010: $bread_crumbs_component = 'Authoring requests';
5011: if ($env{'form.state'} eq 'done') {
5012: push(@{$brcrum},
5013: {href => '/adm/createuser?action=authorreqqueue',
5014: text => 'Result',
5015: help => 'Domain_Role_Approvals'});
5016: $bread_crumbs_component = 'Authoring request result';
5017: }
5018: $args = { bread_crumbs => $brcrum,
5019: bread_crumbs_component => $bread_crumbs_component};
1.391 raeburn 5020: my $js = &usernamerequest_javascript();
5021: $r->print(&header(&add_script($js),$args));
1.362 raeburn 5022: if (!exists($env{'form.state'})) {
5023: $r->print(&Apache::loncoursequeueadmin::display_queued_requests('requestauthor',
5024: $env{'request.role.domain'}));
5025: } elsif ($env{'form.state'} eq 'done') {
5026: $r->print('<h3>'.&mt('Authoring request processing').'</h3>'."\n");
5027: $r->print(&Apache::loncoursequeueadmin::update_request_queue('requestauthor',
5028: $env{'request.role.domain'}));
5029: }
1.391 raeburn 5030: } elsif (($env{'form.action'} eq 'processusernamereq') &&
5031: ($permission->{'cusr'}) &&
5032: (&Apache::lonnet::allowed('cau',$env{'request.role.domain'}))) {
5033: push(@{$brcrum},
5034: {href => '/adm/createuser?action=processusernamereq',
5035: text => 'LON-CAPA account requests',
5036: help => 'Domain_Username_Approvals'});
5037: $bread_crumbs_component = 'Account requests';
5038: if ($env{'form.state'} eq 'done') {
5039: push(@{$brcrum},
5040: {href => '/adm/createuser?action=usernamereqqueue',
5041: text => 'Result',
5042: help => 'Domain_Username_Approvals'});
5043: $bread_crumbs_component = 'LON-CAPA account request result';
5044: }
5045: $args = { bread_crumbs => $brcrum,
5046: bread_crumbs_component => $bread_crumbs_component};
5047: my $js = &usernamerequest_javascript();
5048: $r->print(&header(&add_script($js),$args));
5049: if (!exists($env{'form.state'})) {
5050: $r->print(&Apache::loncoursequeueadmin::display_queued_requests('requestusername',
5051: $env{'request.role.domain'}));
5052: } elsif ($env{'form.state'} eq 'done') {
5053: $r->print('<h3>'.&mt('LON-CAPA account request processing').'</h3>'."\n");
5054: $r->print(&Apache::loncoursequeueadmin::update_request_queue('requestusername',
5055: $env{'request.role.domain'}));
5056: }
5057: } elsif (($env{'form.action'} eq 'displayuserreq') &&
5058: ($permission->{'cusr'})) {
5059: my $dom = $env{'form.domain'};
5060: my $uname = $env{'form.username'};
5061: my $warning;
5062: if (($dom =~ /^$match_domain$/) && (&Apache::lonnet::domain($dom) ne '')) {
5063: if (($dom eq $env{'request.role.domain'}) && (&Apache::lonnet::allowed('ccc',$dom))) {
5064: if (($uname =~ /^$match_username$/) && ($env{'form.queue'} eq 'approval')) {
5065: my $uhome = &Apache::lonnet::homeserver($uname,$dom);
5066: if ($uhome eq 'no_host') {
5067: my $queue = $env{'form.queue'};
5068: my $reqkey = &escape($uname).'_'.$queue;
5069: my $namespace = 'usernamequeue';
5070: my $domconfig = &Apache::lonnet::get_domainconfiguser($dom);
5071: my %queued =
5072: &Apache::lonnet::get($namespace,[$reqkey],$dom,$domconfig);
5073: unless ($queued{$reqkey}) {
5074: $warning = &mt('No information was found for this LON-CAPA account request.');
5075: }
5076: } else {
5077: $warning = &mt('A LON-CAPA account already exists for the requested username and domain.');
5078: }
5079: } else {
5080: $warning = &mt('LON-CAPA account request status check is for an invalid username.');
5081: }
5082: } else {
5083: $warning = &mt('You do not have rights to view LON-CAPA account requests in the domain specified.');
5084: }
5085: } else {
5086: $warning = &mt('LON-CAPA account request status check is for an invalid domain.');
5087: }
5088: my $args = { only_body => 1 };
5089: $r->print(&header(undef,$args).
5090: '<h3>'.&mt('LON-CAPA Account Request Details').'</h3>');
5091: if ($warning ne '') {
5092: $r->print('<div class="LC_warning">'.$warning.'</div>');
5093: } else {
5094: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
5095: my $domconfiguser = &Apache::lonnet::get_domainconfiguser($dom);
5096: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
5097: if (ref($domconfig{'usercreation'}) eq 'HASH') {
5098: if (ref($domconfig{'usercreation'}{'cancreate'}) eq 'HASH') {
5099: if (ref($domconfig{'usercreation'}{'cancreate'}{'emailusername'}) eq 'HASH') {
5100: my %info =
5101: &Apache::lonnet::get('nohist_requestedusernames',[$uname],$dom,$domconfiguser);
5102: if (ref($info{$uname}) eq 'HASH') {
1.396 raeburn 5103: my $usertype = $info{$uname}{'inststatus'};
5104: unless ($usertype) {
5105: $usertype = 'default';
5106: }
1.442 raeburn 5107: my ($showstatus,$showemail,$pickstart);
5108: my $numextras = 0;
5109: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.443 raeburn 5110: if ((ref($types) eq 'ARRAY') && (@{$types} > 0)) {
5111: if (ref($usertypes) eq 'HASH') {
5112: if ($usertypes->{$usertype}) {
5113: $showstatus = $usertypes->{$usertype};
5114: } else {
5115: $showstatus = $othertitle;
5116: }
5117: if ($showstatus) {
5118: $numextras ++;
5119: }
1.442 raeburn 5120: }
5121: }
5122: if (($info{$uname}{'email'} ne '') && ($info{$uname}{'email'} ne $uname)) {
5123: $showemail = $info{$uname}{'email'};
5124: $numextras ++;
5125: }
1.396 raeburn 5126: if (ref($domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}) eq 'HASH') {
5127: if ((ref($infofields) eq 'ARRAY') && (ref($infotitles) eq 'HASH')) {
1.442 raeburn 5128: $pickstart = 1;
1.396 raeburn 5129: $r->print('<div>'.&Apache::lonhtmlcommon::start_pick_box());
1.442 raeburn 5130: my ($num,$count);
1.396 raeburn 5131: $count = scalar(keys(%{$domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}}));
1.442 raeburn 5132: $count += $numextras;
1.396 raeburn 5133: foreach my $field (@{$infofields}) {
5134: next unless ($domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}{$field});
5135: next unless ($infotitles->{$field});
5136: $r->print(&Apache::lonhtmlcommon::row_title($infotitles->{$field}).
5137: $info{$uname}{$field});
5138: $num ++;
1.442 raeburn 5139: unless ($count == $num) {
1.396 raeburn 5140: $r->print(&Apache::lonhtmlcommon::row_closure());
5141: }
5142: }
1.442 raeburn 5143: }
5144: }
5145: if ($numextras) {
5146: unless ($pickstart) {
5147: $r->print('<div>'.&Apache::lonhtmlcommon::start_pick_box());
5148: $pickstart = 1;
5149: }
5150: if ($showemail) {
5151: my $closure = '';
5152: unless ($showstatus) {
5153: $closure = 1;
1.391 raeburn 5154: }
1.442 raeburn 5155: $r->print(&Apache::lonhtmlcommon::row_title(&mt('E-mail address')).
5156: $showemail.
5157: &Apache::lonhtmlcommon::row_closure($closure));
1.391 raeburn 5158: }
1.442 raeburn 5159: if ($showstatus) {
5160: $r->print(&Apache::lonhtmlcommon::row_title(&mt('Status type[_1](self-reported)','<br />')).
5161: $showstatus.
5162: &Apache::lonhtmlcommon::row_closure(1));
5163: }
5164: }
5165: if ($pickstart) {
5166: $r->print(&Apache::lonhtmlcommon::end_pick_box().'</div>');
5167: } else {
5168: $r->print('<div>'.&mt('No information to display for this account request.').'</div>');
1.391 raeburn 5169: }
1.442 raeburn 5170: } else {
5171: $r->print('<div>'.&mt('No information available for this account request.').'</div>');
1.391 raeburn 5172: }
5173: }
5174: }
5175: }
5176: }
1.442 raeburn 5177: $r->print(&close_popup_form());
1.207 raeburn 5178: } elsif (($env{'form.action'} eq 'listusers') &&
5179: ($permission->{'view'} || $permission->{'cusr'})) {
1.439 raeburn 5180: my $helpitem = 'Course_View_Class_List';
5181: if ($context eq 'author') {
5182: $helpitem = 'Author_View_Coauthor_List';
5183: } elsif ($context eq 'domain') {
5184: $helpitem = 'Domain_View_Users_List';
5185: }
1.202 raeburn 5186: if ($env{'form.phase'} eq 'bulkchange') {
1.351 raeburn 5187: push(@{$brcrum},
5188: {href => '/adm/createuser?action=listusers',
5189: text => "List Users"},
5190: {href => "/adm/createuser",
5191: text => "Result",
1.439 raeburn 5192: help => $helpitem});
1.351 raeburn 5193: $bread_crumbs_component = 'Update Users';
5194: $args = {bread_crumbs => $brcrum,
5195: bread_crumbs_component => $bread_crumbs_component};
5196: $r->print(&header(undef,$args));
1.202 raeburn 5197: my $setting = $env{'form.roletype'};
5198: my $choice = $env{'form.bulkaction'};
5199: if ($permission->{'cusr'}) {
1.336 raeburn 5200: &Apache::lonuserutils::update_user_list($r,$context,$setting,$choice,$crstype);
1.221 raeburn 5201: } else {
5202: $r->print(&mt('You are not authorized to make bulk changes to user roles'));
1.223 raeburn 5203: $r->print('<p><a href="/adm/createuser?action=listusers">'.&mt('Display User Lists').'</a>');
1.202 raeburn 5204: }
5205: } else {
1.351 raeburn 5206: push(@{$brcrum},
5207: {href => '/adm/createuser?action=listusers',
5208: text => "List Users",
1.439 raeburn 5209: help => $helpitem});
1.351 raeburn 5210: $bread_crumbs_component = 'List Users';
5211: $args = {bread_crumbs => $brcrum,
5212: bread_crumbs_component => $bread_crumbs_component};
1.202 raeburn 5213: my ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles);
5214: my $formname = 'studentform';
1.364 raeburn 5215: my $hidecall = "hide_searching();";
1.321 raeburn 5216: if (($context eq 'domain') && (($env{'form.roletype'} eq 'course') ||
5217: ($env{'form.roletype'} eq 'community'))) {
5218: if ($env{'form.roletype'} eq 'course') {
5219: ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles) =
5220: &Apache::lonuserutils::courses_selector($env{'request.role.domain'},
5221: $formname);
5222: } elsif ($env{'form.roletype'} eq 'community') {
5223: $cb_jscript =
5224: &Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
5225: my %elements = (
5226: coursepick => 'radio',
5227: coursetotal => 'text',
5228: courselist => 'text',
5229: );
5230: $jscript = &Apache::lonhtmlcommon::set_form_elements(\%elements);
5231: }
1.364 raeburn 5232: $jscript .= &verify_user_display($context)."\n".
5233: &Apache::loncommon::check_uncheck_jscript();
1.202 raeburn 5234: my $js = &add_script($jscript).$cb_jscript;
5235: my $loadcode =
5236: &Apache::lonuserutils::course_selector_loadcode($formname);
5237: if ($loadcode ne '') {
1.364 raeburn 5238: $args->{add_entries} = {onload => "$loadcode;$hidecall"};
5239: } else {
5240: $args->{add_entries} = {onload => $hidecall};
1.202 raeburn 5241: }
1.351 raeburn 5242: $r->print(&header($js,$args));
1.191 raeburn 5243: } else {
1.364 raeburn 5244: $args->{add_entries} = {onload => $hidecall};
5245: $jscript = &verify_user_display($context).
5246: &Apache::loncommon::check_uncheck_jscript();
5247: $r->print(&header(&add_script($jscript),$args));
1.191 raeburn 5248: }
1.202 raeburn 5249: &Apache::lonuserutils::print_userlist($r,undef,$permission,$context,
1.375 raeburn 5250: $formname,$totcodes,$codetitles,$idlist,$idlist_titles,
5251: $showcredits);
1.191 raeburn 5252: }
1.213 raeburn 5253: } elsif ($env{'form.action'} eq 'drop' && $permission->{'cusr'}) {
1.318 raeburn 5254: my $brtext;
5255: if ($crstype eq 'Community') {
5256: $brtext = 'Drop Members';
5257: } else {
5258: $brtext = 'Drop Students';
5259: }
1.351 raeburn 5260: push(@{$brcrum},
5261: {href => '/adm/createuser?action=drop',
5262: text => $brtext,
5263: help => 'Course_Drop_Student'});
5264: if ($env{'form.state'} eq 'done') {
5265: push(@{$brcrum},
5266: {href=>'/adm/createuser?action=drop',
5267: text=>"Result"});
5268: }
5269: $bread_crumbs_component = $brtext;
5270: $args = {bread_crumbs => $brcrum,
5271: bread_crumbs_component => $bread_crumbs_component};
5272: $r->print(&header(undef,$args));
1.213 raeburn 5273: if (!exists($env{'form.state'})) {
1.318 raeburn 5274: &Apache::lonuserutils::print_drop_menu($r,$context,$permission,$crstype);
1.213 raeburn 5275: } elsif ($env{'form.state'} eq 'done') {
5276: &Apache::lonuserutils::update_user_list($r,$context,undef,
5277: $env{'form.action'});
5278: }
1.202 raeburn 5279: } elsif ($env{'form.action'} eq 'dateselect') {
5280: if ($permission->{'cusr'}) {
1.351 raeburn 5281: $r->print(&header(undef,{'no_nav_bar' => 1}).
1.375 raeburn 5282: &Apache::lonuserutils::date_section_selector($context,$permission,
5283: $crstype,$showcredits));
1.202 raeburn 5284: } else {
1.351 raeburn 5285: $r->print(&header(undef,{'no_nav_bar' => 1}).
5286: '<span class="LC_error">'.&mt('You do not have permission to modify dates or sections for users').'</span>');
1.202 raeburn 5287: }
1.237 raeburn 5288: } elsif ($env{'form.action'} eq 'selfenroll') {
1.398 raeburn 5289: if ($permission->{selfenrolladmin}) {
5290: my %currsettings = (
5291: selfenroll_types => $env{'course.'.$cid.'.internal.selfenroll_types'},
5292: selfenroll_registered => $env{'course.'.$cid.'.internal.selfenroll_registered'},
5293: selfenroll_section => $env{'course.'.$cid.'.internal.selfenroll_section'},
5294: selfenroll_notifylist => $env{'course.'.$cid.'.internal.selfenroll_notifylist'},
5295: selfenroll_approval => $env{'course.'.$cid.'.internal.selfenroll_approval'},
5296: selfenroll_limit => $env{'course.'.$cid.'.internal.selfenroll_limit'},
5297: selfenroll_cap => $env{'course.'.$cid.'.internal.selfenroll_cap'},
5298: selfenroll_start_date => $env{'course.'.$cid.'.internal.selfenroll_start_date'},
5299: selfenroll_end_date => $env{'course.'.$cid.'.internal.selfenroll_end_date'},
5300: selfenroll_start_access => $env{'course.'.$cid.'.internal.selfenroll_start_access'},
5301: selfenroll_end_access => $env{'course.'.$cid.'.internal.selfenroll_end_access'},
5302: default_enrollment_start_date => $env{'course.'.$cid.'.default_enrollment_start_date'},
5303: default_enrollment_end_date => $env{'course.'.$cid.'.default_enrollment_end_date'},
1.400 raeburn 5304: uniquecode => $env{'course.'.$cid.'.internal.uniquecode'},
1.398 raeburn 5305: );
5306: push(@{$brcrum},
5307: {href => '/adm/createuser?action=selfenroll',
5308: text => "Configure Self-enrollment",
5309: help => 'Course_Self_Enrollment'});
5310: if (!exists($env{'form.state'})) {
5311: $args = { bread_crumbs => $brcrum,
5312: bread_crumbs_component => 'Configure Self-enrollment'};
5313: $r->print(&header(undef,$args));
5314: $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n");
5315: &print_selfenroll_menu($r,'course',$cid,$cdom,$cnum,\%currsettings);
5316: } elsif ($env{'form.state'} eq 'done') {
5317: push (@{$brcrum},
5318: {href=>'/adm/createuser?action=selfenroll',
5319: text=>"Result"});
5320: $args = { bread_crumbs => $brcrum,
5321: bread_crumbs_component => 'Self-enrollment result'};
5322: $r->print(&header(undef,$args));
5323: $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n");
1.400 raeburn 5324: &update_selfenroll_config($r,$cid,$cdom,$cnum,$context,$crstype,\%currsettings);
1.398 raeburn 5325: }
5326: } else {
5327: $r->print(&header(undef,{'no_nav_bar' => 1}).
5328: '<span class="LC_error">'.&mt('You do not have permission to configure self-enrollment').'</span>');
1.237 raeburn 5329: }
1.277 raeburn 5330: } elsif ($env{'form.action'} eq 'selfenrollqueue') {
1.418 raeburn 5331: if ($permission->{selfenrolladmin}) {
1.351 raeburn 5332: push(@{$brcrum},
5333: {href => '/adm/createuser?action=selfenrollqueue',
1.418 raeburn 5334: text => 'Enrollment requests',
1.439 raeburn 5335: help => 'Course_Approve_Selfenroll'});
1.418 raeburn 5336: $bread_crumbs_component = 'Enrollment requests';
5337: if ($env{'form.state'} eq 'done') {
5338: push(@{$brcrum},
5339: {href => '/adm/createuser?action=selfenrollqueue',
5340: text => 'Result',
1.439 raeburn 5341: help => 'Course_Approve_Selfenroll'});
1.418 raeburn 5342: $bread_crumbs_component = 'Enrollment result';
5343: }
5344: $args = { bread_crumbs => $brcrum,
5345: bread_crumbs_component => $bread_crumbs_component};
5346: $r->print(&header(undef,$args));
5347: my $coursedesc = $env{'course.'.$cid.'.description'};
5348: if (!exists($env{'form.state'})) {
5349: $r->print('<h3>'.&mt('Pending enrollment requests').'</h3>'."\n");
5350: $r->print(&Apache::loncoursequeueadmin::display_queued_requests($context,
5351: $cdom,$cnum));
5352: } elsif ($env{'form.state'} eq 'done') {
5353: $r->print('<h3>'.&mt('Enrollment request processing').'</h3>'."\n");
5354: $r->print(&Apache::loncoursequeueadmin::update_request_queue($context,
1.430 raeburn 5355: $cdom,$cnum,$coursedesc));
1.418 raeburn 5356: }
5357: } else {
5358: $r->print(&header(undef,{'no_nav_bar' => 1}).
5359: '<span class="LC_error">'.&mt('You do not have permission to manage self-enrollment').'</span>');
1.351 raeburn 5360: }
1.418 raeburn 5361: } elsif ($env{'form.action'} eq 'changelogs') {
5362: if ($permission->{cusr} || $permission->{view}) {
5363: &print_userchangelogs_display($r,$context,$permission,$brcrum);
5364: } else {
5365: $r->print(&header(undef,{'no_nav_bar' => 1}).
5366: '<span class="LC_error">'.&mt('You do not have permission to view change logs').'</span>');
1.277 raeburn 5367: }
1.428 raeburn 5368: } elsif ($env{'form.action'} eq 'helpdesk') {
5369: if (($permission->{'owner'}) || ($permission->{'co-owner'})) {
5370: if ($env{'form.state'} eq 'process') {
5371: if ($permission->{'owner'}) {
5372: &update_helpdeskaccess($r,$permission,$brcrum);
5373: } else {
5374: &print_helpdeskaccess_display($r,$permission,$brcrum);
1.430 raeburn 5375: }
1.428 raeburn 5376: } else {
5377: &print_helpdeskaccess_display($r,$permission,$brcrum);
5378: }
5379: } else {
5380: $r->print(&header(undef,{'no_nav_bar' => 1}).
5381: '<span class="LC_error">'.&mt('You do not have permission to view helpdesk access').'</span>');
5382: }
1.190 raeburn 5383: } else {
1.351 raeburn 5384: $bread_crumbs_component = 'User Management';
5385: $args = { bread_crumbs => $brcrum,
5386: bread_crumbs_component => $bread_crumbs_component};
5387: $r->print(&header(undef,$args));
1.318 raeburn 5388: $r->print(&print_main_menu($permission,$context,$crstype));
1.190 raeburn 5389: }
1.351 raeburn 5390: $r->print(&Apache::loncommon::end_page());
1.190 raeburn 5391: return OK;
5392: }
5393:
5394: sub header {
1.351 raeburn 5395: my ($jscript,$args) = @_;
1.190 raeburn 5396: my $start_page;
1.351 raeburn 5397: if (ref($args) eq 'HASH') {
5398: $start_page=&Apache::loncommon::start_page('User Management',$jscript,$args);
1.190 raeburn 5399: } else {
1.351 raeburn 5400: $start_page=&Apache::loncommon::start_page('User Management',$jscript);
1.190 raeburn 5401: }
5402: return $start_page;
5403: }
1.2 www 5404:
1.191 raeburn 5405: sub add_script {
5406: my ($js) = @_;
1.301 bisitz 5407: return '<script type="text/javascript">'."\n"
5408: .'// <![CDATA['."\n"
5409: .$js."\n"
5410: .'// ]]>'."\n"
5411: .'</script>'."\n";
1.191 raeburn 5412: }
5413:
1.391 raeburn 5414: sub usernamerequest_javascript {
5415: my $js = <<ENDJS;
5416:
5417: function openusernamereqdisplay(dom,uname,queue) {
5418: var url = '/adm/createuser?action=displayuserreq';
5419: url += '&domain='+dom+'&username='+uname+'&queue='+queue;
5420: var title = 'Account_Request_Browser';
5421: var options = 'scrollbars=1,resizable=1,menubar=0';
5422: options += ',width=700,height=600';
5423: var stdeditbrowser = open(url,title,options,'1');
5424: stdeditbrowser.focus();
5425: return;
5426: }
5427:
5428: ENDJS
5429: }
5430:
5431: sub close_popup_form {
5432: my $close= &mt('Close Window');
5433: return << "END";
5434: <p><form name="displayreq" action="" method="post">
5435: <input type="button" name="closeme" value="$close" onclick="javascript:self.close();" />
5436: </form></p>
5437: END
5438: }
5439:
1.202 raeburn 5440: sub verify_user_display {
1.364 raeburn 5441: my ($context) = @_;
1.374 raeburn 5442: my %lt = &Apache::lonlocal::texthash (
5443: course => 'course(s): description, section(s), status',
5444: community => 'community(s): description, section(s), status',
5445: author => 'author',
5446: );
1.364 raeburn 5447: my $photos;
5448: if (($context eq 'course') && $env{'request.course.id'}) {
5449: $photos = $env{'course.'.$env{'request.course.id'}.'.internal.showphoto'};
5450: }
1.202 raeburn 5451: my $output = <<"END";
5452:
1.364 raeburn 5453: function hide_searching() {
5454: if (document.getElementById('searching')) {
5455: document.getElementById('searching').style.display = 'none';
5456: }
5457: return;
5458: }
5459:
1.202 raeburn 5460: function display_update() {
5461: document.studentform.action.value = 'listusers';
5462: document.studentform.phase.value = 'display';
5463: document.studentform.submit();
5464: }
5465:
1.364 raeburn 5466: function updateCols(caller) {
5467: var context = '$context';
5468: var photos = '$photos';
5469: if (caller == 'Status') {
1.374 raeburn 5470: if ((context == 'domain') &&
5471: ((document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'course') ||
5472: (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community'))) {
1.364 raeburn 5473: document.getElementById('showcolstatus').checked = false;
5474: document.getElementById('showcolstatus').disabled = 'disabled';
5475: document.getElementById('showcolstart').checked = false;
5476: document.getElementById('showcolend').checked = false;
1.374 raeburn 5477: } else {
5478: if (document.studentform.Status.options[document.studentform.Status.selectedIndex].value == 'Any') {
5479: document.getElementById('showcolstatus').checked = true;
5480: document.getElementById('showcolstatus').disabled = '';
5481: document.getElementById('showcolstart').checked = true;
5482: document.getElementById('showcolend').checked = true;
5483: } else {
5484: document.getElementById('showcolstatus').checked = false;
5485: document.getElementById('showcolstatus').disabled = 'disabled';
5486: document.getElementById('showcolstart').checked = false;
5487: document.getElementById('showcolend').checked = false;
5488: }
1.364 raeburn 5489: }
5490: }
5491: if (caller == 'output') {
5492: if (photos == 1) {
5493: if (document.getElementById('showcolphoto')) {
5494: var photoitem = document.getElementById('showcolphoto');
5495: if (document.studentform.output.options[document.studentform.output.selectedIndex].value == 'html') {
5496: photoitem.checked = true;
5497: photoitem.disabled = '';
5498: } else {
5499: photoitem.checked = false;
5500: photoitem.disabled = 'disabled';
5501: }
5502: }
5503: }
5504: }
5505: if (caller == 'showrole') {
1.371 raeburn 5506: if ((document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'Any') ||
5507: (document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'cr')) {
1.364 raeburn 5508: document.getElementById('showcolrole').checked = true;
5509: document.getElementById('showcolrole').disabled = '';
5510: } else {
5511: document.getElementById('showcolrole').checked = false;
5512: document.getElementById('showcolrole').disabled = 'disabled';
5513: }
1.374 raeburn 5514: if (context == 'domain') {
1.382 raeburn 5515: var quotausageshow = 0;
1.374 raeburn 5516: if ((document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'course') ||
5517: (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community')) {
5518: document.getElementById('showcolstatus').checked = false;
5519: document.getElementById('showcolstatus').disabled = 'disabled';
5520: document.getElementById('showcolstart').checked = false;
5521: document.getElementById('showcolend').checked = false;
5522: } else {
5523: if (document.studentform.Status.options[document.studentform.Status.selectedIndex].value == 'Any') {
5524: document.getElementById('showcolstatus').checked = true;
5525: document.getElementById('showcolstatus').disabled = '';
5526: document.getElementById('showcolstart').checked = true;
5527: document.getElementById('showcolend').checked = true;
5528: }
5529: }
5530: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'domain') {
5531: document.getElementById('showcolextent').disabled = 'disabled';
5532: document.getElementById('showcolextent').checked = 'false';
5533: document.getElementById('showextent').style.display='none';
5534: document.getElementById('showcoltextextent').innerHTML = '';
1.382 raeburn 5535: if ((document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'au') ||
5536: (document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'Any')) {
5537: if (document.getElementById('showcolauthorusage')) {
5538: document.getElementById('showcolauthorusage').disabled = '';
5539: }
5540: if (document.getElementById('showcolauthorquota')) {
5541: document.getElementById('showcolauthorquota').disabled = '';
5542: }
5543: quotausageshow = 1;
5544: }
1.374 raeburn 5545: } else {
5546: document.getElementById('showextent').style.display='block';
5547: document.getElementById('showextent').style.textAlign='left';
5548: document.getElementById('showextent').style.textFace='normal';
5549: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'author') {
5550: document.getElementById('showcolextent').disabled = '';
5551: document.getElementById('showcolextent').checked = 'true';
5552: document.getElementById('showcoltextextent').innerHTML="$lt{'author'}";
5553: } else {
5554: document.getElementById('showcolextent').disabled = '';
5555: document.getElementById('showcolextent').checked = 'true';
5556: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community') {
5557: document.getElementById('showcoltextextent').innerHTML="$lt{'community'}";
5558: } else {
5559: document.getElementById('showcoltextextent').innerHTML="$lt{'course'}";
5560: }
5561: }
5562: }
1.382 raeburn 5563: if (quotausageshow == 0) {
5564: if (document.getElementById('showcolauthorusage')) {
5565: document.getElementById('showcolauthorusage').checked = false;
5566: document.getElementById('showcolauthorusage').disabled = 'disabled';
5567: }
5568: if (document.getElementById('showcolauthorquota')) {
5569: document.getElementById('showcolauthorquota').checked = false;
5570: document.getElementById('showcolauthorquota').disabled = 'disabled';
5571: }
5572: }
1.374 raeburn 5573: }
1.364 raeburn 5574: }
5575: return;
5576: }
5577:
1.202 raeburn 5578: END
5579: return $output;
5580:
5581: }
5582:
1.190 raeburn 5583: ###############################################################
5584: ###############################################################
5585: # Menu Phase One
5586: sub print_main_menu {
1.318 raeburn 5587: my ($permission,$context,$crstype) = @_;
5588: my $linkcontext = $context;
5589: my $stuterm = lc(&Apache::lonnet::plaintext('st',$crstype));
5590: if (($context eq 'course') && ($crstype eq 'Community')) {
5591: $linkcontext = lc($crstype);
5592: $stuterm = 'Members';
5593: }
1.208 raeburn 5594: my %links = (
1.298 droeschl 5595: domain => {
5596: upload => 'Upload a File of Users',
5597: singleuser => 'Add/Modify a User',
5598: listusers => 'Manage Users',
5599: },
5600: author => {
5601: upload => 'Upload a File of Co-authors',
5602: singleuser => 'Add/Modify a Co-author',
5603: listusers => 'Manage Co-authors',
5604: },
5605: course => {
5606: upload => 'Upload a File of Course Users',
5607: singleuser => 'Add/Modify a Course User',
1.354 www 5608: listusers => 'List and Modify Multiple Course Users',
1.298 droeschl 5609: },
1.318 raeburn 5610: community => {
5611: upload => 'Upload a File of Community Users',
5612: singleuser => 'Add/Modify a Community User',
1.354 www 5613: listusers => 'List and Modify Multiple Community Users',
1.318 raeburn 5614: },
5615: );
5616: my %linktitles = (
5617: domain => {
5618: singleuser => 'Add a user to the domain, and/or a course or community in the domain.',
5619: listusers => 'Show and manage users in this domain.',
5620: },
5621: author => {
5622: singleuser => 'Add a user with a co- or assistant author role.',
5623: listusers => 'Show and manage co- or assistant authors.',
5624: },
5625: course => {
5626: singleuser => 'Add a user with a certain role to this course.',
5627: listusers => 'Show and manage users in this course.',
5628: },
5629: community => {
5630: singleuser => 'Add a user with a certain role to this community.',
5631: listusers => 'Show and manage users in this community.',
5632: },
1.298 droeschl 5633: );
1.418 raeburn 5634: if ($linkcontext eq 'domain') {
5635: unless ($permission->{'cusr'}) {
1.430 raeburn 5636: $links{'domain'}{'singleuser'} = 'View a User';
1.418 raeburn 5637: $linktitles{'domain'}{'singleuser'} = 'View information about a user in the domain';
5638: }
5639: } elsif ($linkcontext eq 'course') {
5640: unless ($permission->{'cusr'}) {
5641: $links{'course'}{'singleuser'} = 'View a Course User';
5642: $linktitles{'course'}{'singleuser'} = 'View information about a user in this course';
5643: $links{'course'}{'listusers'} = 'List Course Users';
5644: $linktitles{'course'}{'listusers'} = 'Show information about users in this course';
5645: }
5646: } elsif ($linkcontext eq 'community') {
5647: unless ($permission->{'cusr'}) {
5648: $links{'community'}{'singleuser'} = 'View a Community User';
5649: $linktitles{'community'}{'singleuser'} = 'View information about a user in this community';
5650: $links{'community'}{'listusers'} = 'List Community Users';
5651: $linktitles{'community'}{'listusers'} = 'Show information about users in this community';
5652: }
5653: }
1.298 droeschl 5654: my @menu = ( {categorytitle => 'Single Users',
5655: items =>
5656: [
5657: {
1.318 raeburn 5658: linktext => $links{$linkcontext}{'singleuser'},
1.298 droeschl 5659: icon => 'edit-redo.png',
5660: #help => 'Course_Change_Privileges',
5661: url => '/adm/createuser?action=singleuser',
1.418 raeburn 5662: permission => ($permission->{'view'} || $permission->{'cusr'}),
1.318 raeburn 5663: linktitle => $linktitles{$linkcontext}{'singleuser'},
1.298 droeschl 5664: },
5665: ]},
5666:
5667: {categorytitle => 'Multiple Users',
5668: items =>
5669: [
5670: {
1.318 raeburn 5671: linktext => $links{$linkcontext}{'upload'},
1.340 wenzelju 5672: icon => 'uplusr.png',
1.298 droeschl 5673: #help => 'Course_Create_Class_List',
5674: url => '/adm/createuser?action=upload',
5675: permission => $permission->{'cusr'},
5676: linktitle => 'Upload a CSV or a text file containing users.',
5677: },
5678: {
1.318 raeburn 5679: linktext => $links{$linkcontext}{'listusers'},
1.340 wenzelju 5680: icon => 'mngcu.png',
1.298 droeschl 5681: #help => 'Course_View_Class_List',
5682: url => '/adm/createuser?action=listusers',
5683: permission => ($permission->{'view'} || $permission->{'cusr'}),
1.318 raeburn 5684: linktitle => $linktitles{$linkcontext}{'listusers'},
1.298 droeschl 5685: },
5686:
5687: ]},
5688:
5689: {categorytitle => 'Administration',
5690: items => [ ]},
5691: );
1.415 raeburn 5692:
1.265 mielkec 5693: if ($context eq 'domain'){
1.416 raeburn 5694: push(@{ $menu[0]->{items} }, # Single Users
5695: {
5696: linktext => 'User Access Log',
1.417 raeburn 5697: icon => 'document-properties.png',
1.425 raeburn 5698: #help => 'Domain_User_Access_Logs',
1.416 raeburn 5699: url => '/adm/createuser?action=accesslogs',
5700: permission => $permission->{'activity'},
5701: linktitle => 'View user access log.',
5702: }
5703: );
1.298 droeschl 5704:
5705: push(@{ $menu[2]->{items} }, #Category: Administration
5706: {
5707: linktext => 'Custom Roles',
5708: icon => 'emblem-photos.png',
5709: #help => 'Course_Editing_Custom_Roles',
5710: url => '/adm/createuser?action=custom',
5711: permission => $permission->{'custom'},
5712: linktitle => 'Configure a custom role.',
5713: },
1.362 raeburn 5714: {
5715: linktext => 'Authoring Space Requests',
5716: icon => 'selfenrl-queue.png',
5717: #help => 'Domain_Role_Approvals',
5718: url => '/adm/createuser?action=processauthorreq',
5719: permission => $permission->{'cusr'},
5720: linktitle => 'Approve or reject author role requests',
5721: },
1.363 raeburn 5722: {
1.391 raeburn 5723: linktext => 'LON-CAPA Account Requests',
5724: icon => 'list-add.png',
5725: #help => 'Domain_Username_Approvals',
5726: url => '/adm/createuser?action=processusernamereq',
5727: permission => $permission->{'cusr'},
5728: linktitle => 'Approve or reject LON-CAPA account requests',
5729: },
5730: {
1.363 raeburn 5731: linktext => 'Change Log',
5732: icon => 'document-properties.png',
5733: #help => 'Course_User_Logs',
5734: url => '/adm/createuser?action=changelogs',
1.418 raeburn 5735: permission => ($permission->{'cusr'} || $permission->{'view'}),
1.363 raeburn 5736: linktitle => 'View change log.',
5737: },
1.298 droeschl 5738: );
5739:
1.265 mielkec 5740: }elsif ($context eq 'course'){
1.298 droeschl 5741: my ($cnum,$cdom) = &Apache::lonuserutils::get_course_identity();
1.318 raeburn 5742:
5743: my %linktext = (
5744: 'Course' => {
5745: single => 'Add/Modify a Student',
5746: drop => 'Drop Students',
5747: groups => 'Course Groups',
5748: },
5749: 'Community' => {
5750: single => 'Add/Modify a Member',
5751: drop => 'Drop Members',
5752: groups => 'Community Groups',
5753: },
5754: );
1.411 raeburn 5755: $linktext{'Placement'} = $linktext{'Course'};
1.318 raeburn 5756:
5757: my %linktitle = (
5758: 'Course' => {
5759: single => 'Add a user with the role of student to this course',
5760: drop => 'Remove a student from this course.',
5761: groups => 'Manage course groups',
5762: },
5763: 'Community' => {
5764: single => 'Add a user with the role of member to this community',
5765: drop => 'Remove a member from this community.',
5766: groups => 'Manage community groups',
5767: },
5768: );
5769:
1.411 raeburn 5770: $linktitle{'Placement'} = $linktitle{'Course'};
5771:
1.298 droeschl 5772: push(@{ $menu[0]->{items} }, #Category: Single Users
5773: {
1.318 raeburn 5774: linktext => $linktext{$crstype}{'single'},
1.298 droeschl 5775: #help => 'Course_Add_Student',
5776: icon => 'list-add.png',
5777: url => '/adm/createuser?action=singlestudent',
5778: permission => $permission->{'cusr'},
1.318 raeburn 5779: linktitle => $linktitle{$crstype}{'single'},
1.298 droeschl 5780: },
5781: );
5782:
5783: push(@{ $menu[1]->{items} }, #Category: Multiple Users
5784: {
1.318 raeburn 5785: linktext => $linktext{$crstype}{'drop'},
1.298 droeschl 5786: icon => 'edit-undo.png',
5787: #help => 'Course_Drop_Student',
5788: url => '/adm/createuser?action=drop',
5789: permission => $permission->{'cusr'},
1.318 raeburn 5790: linktitle => $linktitle{$crstype}{'drop'},
1.298 droeschl 5791: },
5792: );
5793: push(@{ $menu[2]->{items} }, #Category: Administration
1.428 raeburn 5794: {
5795: linktext => 'Helpdesk Access',
5796: icon => 'helpdesk-access.png',
5797: #help => 'Course_Helpdesk_Access',
5798: url => '/adm/createuser?action=helpdesk',
5799: permission => ($permission->{'owner'} || $permission->{'co-owner'}),
5800: linktitle => 'Helpdesk access options',
5801: },
5802: {
1.298 droeschl 5803: linktext => 'Custom Roles',
5804: icon => 'emblem-photos.png',
5805: #help => 'Course_Editing_Custom_Roles',
5806: url => '/adm/createuser?action=custom',
5807: permission => $permission->{'custom'},
5808: linktitle => 'Configure a custom role.',
5809: },
5810: {
1.318 raeburn 5811: linktext => $linktext{$crstype}{'groups'},
1.333 wenzelju 5812: icon => 'grps.png',
1.298 droeschl 5813: #help => 'Course_Manage_Group',
5814: url => '/adm/coursegroups?refpage=cusr',
5815: permission => $permission->{'grp_manage'},
1.318 raeburn 5816: linktitle => $linktitle{$crstype}{'groups'},
1.298 droeschl 5817: },
5818: {
1.328 wenzelju 5819: linktext => 'Change Log',
1.298 droeschl 5820: icon => 'document-properties.png',
5821: #help => 'Course_User_Logs',
5822: url => '/adm/createuser?action=changelogs',
1.418 raeburn 5823: permission => ($permission->{'view'} || $permission->{'cusr'}),
1.298 droeschl 5824: linktitle => 'View change log.',
5825: },
5826: );
1.277 raeburn 5827: if ($env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_approval'}) {
1.298 droeschl 5828: push(@{ $menu[2]->{items} },
1.398 raeburn 5829: {
1.298 droeschl 5830: linktext => 'Enrollment Requests',
5831: icon => 'selfenrl-queue.png',
5832: #help => 'Course_Approve_Selfenroll',
5833: url => '/adm/createuser?action=selfenrollqueue',
1.398 raeburn 5834: permission => $permission->{'selfenrolladmin'},
1.298 droeschl 5835: linktitle =>'Approve or reject enrollment requests.',
5836: },
5837: );
1.277 raeburn 5838: }
1.298 droeschl 5839:
1.265 mielkec 5840: if (!exists($permission->{'cusr_section'})){
1.320 raeburn 5841: if ($crstype ne 'Community') {
5842: push(@{ $menu[2]->{items} },
5843: {
5844: linktext => 'Automated Enrollment',
5845: icon => 'roles.png',
5846: #help => 'Course_Automated_Enrollment',
5847: permission => (&Apache::lonnet::auto_run($cnum,$cdom)
1.418 raeburn 5848: && (($permission->{'cusr'}) ||
5849: ($permission->{'view'}))),
1.320 raeburn 5850: url => '/adm/populate',
5851: linktitle => 'Automated enrollment manager.',
5852: }
5853: );
5854: }
5855: push(@{ $menu[2]->{items} },
1.298 droeschl 5856: {
5857: linktext => 'User Self-Enrollment',
1.342 wenzelju 5858: icon => 'self_enroll.png',
1.298 droeschl 5859: #help => 'Course_Self_Enrollment',
5860: url => '/adm/createuser?action=selfenroll',
1.398 raeburn 5861: permission => $permission->{'selfenrolladmin'},
1.317 bisitz 5862: linktitle => 'Configure user self-enrollment.',
1.298 droeschl 5863: },
5864: );
5865: }
1.363 raeburn 5866: } elsif ($context eq 'author') {
1.370 raeburn 5867: push(@{ $menu[2]->{items} }, #Category: Administration
1.363 raeburn 5868: {
5869: linktext => 'Change Log',
5870: icon => 'document-properties.png',
5871: #help => 'Course_User_Logs',
5872: url => '/adm/createuser?action=changelogs',
5873: permission => $permission->{'cusr'},
5874: linktitle => 'View change log.',
5875: },
1.370 raeburn 5876: );
1.363 raeburn 5877: }
5878: return Apache::lonhtmlcommon::generate_menu(@menu);
1.250 raeburn 5879: # { text => 'View Log-in History',
5880: # help => 'Course_User_Logins',
5881: # action => 'logins',
5882: # permission => $permission->{'cusr'},
5883: # });
1.190 raeburn 5884: }
5885:
1.189 albertel 5886: sub restore_prev_selections {
5887: my %saveable_parameters = ('srchby' => 'scalar',
5888: 'srchin' => 'scalar',
5889: 'srchtype' => 'scalar',
5890: );
5891: &Apache::loncommon::store_settings('user','user_picker',
5892: \%saveable_parameters);
5893: &Apache::loncommon::restore_settings('user','user_picker',
5894: \%saveable_parameters);
5895: }
5896:
1.237 raeburn 5897: sub print_selfenroll_menu {
1.418 raeburn 5898: my ($r,$context,$cid,$cdom,$cnum,$currsettings,$additional,$readonly) = @_;
1.322 raeburn 5899: my $crstype = &Apache::loncommon::course_type();
1.398 raeburn 5900: my $formname = 'selfenroll';
1.237 raeburn 5901: my $nolink = 1;
1.398 raeburn 5902: my ($row,$lt) = &Apache::lonuserutils::get_selfenroll_titles();
1.237 raeburn 5903: my $groupslist = &Apache::lonuserutils::get_groupslist();
5904: my $setsec_js =
5905: &Apache::lonuserutils::setsections_javascript($formname,$groupslist);
1.249 raeburn 5906: my %alerts = &Apache::lonlocal::texthash(
5907: acto => 'Activation of self-enrollment was selected for the following domain(s)',
5908: butn => 'but no user types have been checked.',
5909: wilf => "Please uncheck 'activate' or check at least one type.",
5910: );
1.418 raeburn 5911: my $disabled;
5912: if ($readonly) {
5913: $disabled = ' disabled="disabled"';
5914: }
1.405 damieng 5915: &js_escape(\%alerts);
1.249 raeburn 5916: my $selfenroll_js = <<"ENDSCRIPT";
5917: function update_types(caller,num) {
5918: var delidx = getIndexByName('selfenroll_delete');
5919: var actidx = getIndexByName('selfenroll_activate');
5920: if (caller == 'selfenroll_all') {
5921: var selall;
5922: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
5923: if (document.$formname.selfenroll_all[i].checked) {
5924: selall = document.$formname.selfenroll_all[i].value;
5925: }
5926: }
5927: if (selall == 1) {
5928: if (delidx != -1) {
5929: if (document.$formname.selfenroll_delete.length) {
5930: for (var j=0; j<document.$formname.selfenroll_delete.length; j++) {
5931: document.$formname.selfenroll_delete[j].checked = true;
5932: }
5933: } else {
5934: document.$formname.elements[delidx].checked = true;
5935: }
5936: }
5937: if (actidx != -1) {
5938: if (document.$formname.selfenroll_activate.length) {
5939: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
5940: document.$formname.selfenroll_activate[j].checked = false;
5941: }
5942: } else {
5943: document.$formname.elements[actidx].checked = false;
5944: }
5945: }
5946: document.$formname.selfenroll_newdom.selectedIndex = 0;
5947: }
5948: }
5949: if (caller == 'selfenroll_activate') {
5950: if (document.$formname.selfenroll_activate.length) {
5951: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
5952: if (document.$formname.selfenroll_activate[j].value == num) {
5953: if (document.$formname.selfenroll_activate[j].checked) {
5954: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
5955: if (document.$formname.selfenroll_all[i].value == '1') {
5956: document.$formname.selfenroll_all[i].checked = false;
5957: }
5958: if (document.$formname.selfenroll_all[i].value == '0') {
5959: document.$formname.selfenroll_all[i].checked = true;
5960: }
5961: }
5962: }
5963: }
5964: }
5965: } else {
5966: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
5967: if (document.$formname.selfenroll_all[i].value == '1') {
5968: document.$formname.selfenroll_all[i].checked = false;
5969: }
5970: if (document.$formname.selfenroll_all[i].value == '0') {
5971: document.$formname.selfenroll_all[i].checked = true;
5972: }
5973: }
5974: }
5975: }
5976: if (caller == 'selfenroll_delete') {
5977: if (document.$formname.selfenroll_delete.length) {
5978: for (var j=0; j<document.$formname.selfenroll_delete.length; j++) {
5979: if (document.$formname.selfenroll_delete[j].value == num) {
5980: if (document.$formname.selfenroll_delete[j].checked) {
5981: var delindex = getIndexByName('selfenroll_types_'+num);
5982: if (delindex != -1) {
5983: if (document.$formname.elements[delindex].length) {
5984: for (var k=0; k<document.$formname.elements[delindex].length; k++) {
5985: document.$formname.elements[delindex][k].checked = false;
5986: }
5987: } else {
5988: document.$formname.elements[delindex].checked = false;
5989: }
5990: }
5991: }
5992: }
5993: }
5994: } else {
5995: if (document.$formname.selfenroll_delete.checked) {
5996: var delindex = getIndexByName('selfenroll_types_'+num);
5997: if (delindex != -1) {
5998: if (document.$formname.elements[delindex].length) {
5999: for (var k=0; k<document.$formname.elements[delindex].length; k++) {
6000: document.$formname.elements[delindex][k].checked = false;
6001: }
6002: } else {
6003: document.$formname.elements[delindex].checked = false;
6004: }
6005: }
6006: }
6007: }
6008: }
6009: return;
6010: }
6011:
6012: function validate_types(form) {
6013: var needaction = new Array();
6014: var countfail = 0;
6015: var actidx = getIndexByName('selfenroll_activate');
6016: if (actidx != -1) {
6017: if (document.$formname.selfenroll_activate.length) {
6018: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
6019: var num = document.$formname.selfenroll_activate[j].value;
6020: if (document.$formname.selfenroll_activate[j].checked) {
6021: countfail = check_types(num,countfail,needaction)
6022: }
6023: }
6024: } else {
6025: if (document.$formname.selfenroll_activate.checked) {
1.398 raeburn 6026: var num = document.$formname.selfenroll_activate.value;
1.249 raeburn 6027: countfail = check_types(num,countfail,needaction)
6028: }
6029: }
6030: }
6031: if (countfail > 0) {
6032: var msg = "$alerts{'acto'}\\n";
6033: var loopend = needaction.length -1;
6034: if (loopend > 0) {
6035: for (var m=0; m<loopend; m++) {
6036: msg += needaction[m]+", ";
6037: }
6038: }
6039: msg += needaction[loopend]+"\\n$alerts{'butn'}\\n$alerts{'wilf'}";
6040: alert(msg);
6041: return;
6042: }
6043: setSections(form);
6044: }
6045:
6046: function check_types(num,countfail,needaction) {
1.441 raeburn 6047: var boxname = 'selfenroll_types_'+num;
6048: var typeidx = getIndexByName(boxname);
1.249 raeburn 6049: var count = 0;
6050: if (typeidx != -1) {
1.441 raeburn 6051: if (document.$formname.elements[boxname].length) {
6052: for (var k=0; k<document.$formname.elements[boxname].length; k++) {
6053: if (document.$formname.elements[boxname][k].checked) {
1.249 raeburn 6054: count ++;
6055: }
6056: }
6057: } else {
6058: if (document.$formname.elements[typeidx].checked) {
6059: count ++;
6060: }
6061: }
6062: if (count == 0) {
6063: var domidx = getIndexByName('selfenroll_dom_'+num);
6064: if (domidx != -1) {
6065: var domname = document.$formname.elements[domidx].value;
6066: needaction[countfail] = domname;
6067: countfail ++;
6068: }
6069: }
6070: }
6071: return countfail;
6072: }
6073:
1.398 raeburn 6074: function toggleNotify() {
6075: var selfenrollApproval = 0;
6076: if (document.$formname.selfenroll_approval.length) {
6077: for (var i=0; i<document.$formname.selfenroll_approval.length; i++) {
6078: if (document.$formname.selfenroll_approval[i].checked) {
6079: selfenrollApproval = document.$formname.selfenroll_approval[i].value;
6080: break;
6081: }
6082: }
6083: }
6084: if (document.getElementById('notified')) {
6085: if (selfenrollApproval == 0) {
6086: document.getElementById('notified').style.display='none';
6087: } else {
6088: document.getElementById('notified').style.display='block';
6089: }
6090: }
6091: return;
6092: }
6093:
1.249 raeburn 6094: function getIndexByName(item) {
6095: for (var i=0;i<document.$formname.elements.length;i++) {
6096: if (document.$formname.elements[i].name == item) {
6097: return i;
6098: }
6099: }
6100: return -1;
6101: }
6102: ENDSCRIPT
1.256 raeburn 6103:
1.237 raeburn 6104: my $output = '<script type="text/javascript">'."\n".
1.301 bisitz 6105: '// <![CDATA['."\n".
1.249 raeburn 6106: $setsec_js."\n".$selfenroll_js."\n".
1.301 bisitz 6107: '// ]]>'."\n".
1.237 raeburn 6108: '</script>'."\n".
1.256 raeburn 6109: '<h3>'.$lt->{'selfenroll'}.'</h3>'."\n";
1.400 raeburn 6110:
6111: my $visactions = &cat_visibility();
6112: my ($cathash,%cattype);
6113: my %domconfig = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom);
6114: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
6115: $cathash = $domconfig{'coursecategories'}{'cats'};
6116: $cattype{'auth'} = $domconfig{'coursecategories'}{'auth'};
6117: $cattype{'unauth'} = $domconfig{'coursecategories'}{'unauth'};
1.406 raeburn 6118: if ($cattype{'auth'} eq '') {
6119: $cattype{'auth'} = 'std';
6120: }
6121: if ($cattype{'unauth'} eq '') {
6122: $cattype{'unauth'} = 'std';
6123: }
1.400 raeburn 6124: } else {
6125: $cathash = {};
6126: $cattype{'auth'} = 'std';
6127: $cattype{'unauth'} = 'std';
6128: }
6129: if (($cattype{'auth'} eq 'none') && ($cattype{'unauth'} eq 'none')) {
6130: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
6131: '<br />'.
6132: '<br />'.$visactions->{'take'}.'<ul>'.
6133: '<li>'.$visactions->{'dc_chgconf'}.'</li>'.
6134: '</ul>');
6135: } elsif (($cattype{'auth'} !~ /^(std|domonly)$/) && ($cattype{'unauth'} !~ /^(std|domonly)$/)) {
6136: if ($currsettings->{'uniquecode'}) {
6137: $r->print('<span class="LC_info">'.$visactions->{'vis'}.'</span>');
6138: } else {
6139: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
6140: '<br />'.
6141: '<br />'.$visactions->{'take'}.'<ul>'.
6142: '<li>'.$visactions->{'dc_setcode'}.'</li>'.
6143: '</ul><br />');
6144: }
6145: } else {
6146: my ($visible,$cansetvis,$vismsgs) = &visible_in_stdcat($cdom,$cnum,\%domconfig);
6147: if (ref($visactions) eq 'HASH') {
6148: if ($visible) {
6149: $output .= '<p class="LC_info">'.$visactions->{'vis'}.'</p>';
6150: } else {
6151: $output .= '<p class="LC_warning">'.$visactions->{'miss'}.'</p>'
6152: .$visactions->{'yous'}.
6153: '<p>'.$visactions->{'gen'}.'<br />'.$visactions->{'coca'};
6154: if (ref($vismsgs) eq 'ARRAY') {
6155: $output .= '<br />'.$visactions->{'make'}.'<ul>';
6156: foreach my $item (@{$vismsgs}) {
6157: $output .= '<li>'.$visactions->{$item}.'</li>';
6158: }
6159: $output .= '</ul>';
1.256 raeburn 6160: }
1.400 raeburn 6161: $output .= '</p>';
1.256 raeburn 6162: }
6163: }
6164: }
1.398 raeburn 6165: my $actionhref = '/adm/createuser';
6166: if ($context eq 'domain') {
6167: $actionhref = '/adm/modifycourse';
6168: }
1.400 raeburn 6169:
6170: my %noedit;
6171: unless ($context eq 'domain') {
6172: %noedit = &get_noedit_fields($cdom,$cnum,$crstype,$row);
6173: }
1.398 raeburn 6174: $output .= '<form name="'.$formname.'" method="post" action="'.$actionhref.'">'."\n".
1.256 raeburn 6175: &Apache::lonhtmlcommon::start_pick_box();
1.237 raeburn 6176: if (ref($row) eq 'ARRAY') {
6177: foreach my $item (@{$row}) {
6178: my $title = $item;
6179: if (ref($lt) eq 'HASH') {
6180: $title = $lt->{$item};
6181: }
1.297 bisitz 6182: $output .= &Apache::lonhtmlcommon::row_title($title);
1.237 raeburn 6183: if ($item eq 'types') {
1.398 raeburn 6184: my $curr_types;
6185: if (ref($currsettings) eq 'HASH') {
6186: $curr_types = $currsettings->{'selfenroll_types'};
6187: }
1.400 raeburn 6188: if ($noedit{$item}) {
6189: if ($curr_types eq '*') {
6190: $output .= &mt('Any user in any domain');
6191: } else {
6192: my @entries = split(/;/,$curr_types);
6193: if (@entries > 0) {
6194: $output .= '<ul>';
6195: foreach my $entry (@entries) {
6196: my ($currdom,$typestr) = split(/:/,$entry);
6197: next if ($typestr eq '');
6198: my $domdesc = &Apache::lonnet::domain($currdom);
6199: my @currinsttypes = split(',',$typestr);
6200: my ($othertitle,$usertypes,$types) =
6201: &Apache::loncommon::sorted_inst_types($currdom);
6202: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
6203: $usertypes->{'any'} = &mt('any user');
6204: if (keys(%{$usertypes}) > 0) {
6205: $usertypes->{'other'} = &mt('other users');
6206: }
6207: my @longinsttypes = map { $usertypes->{$_}; } @currinsttypes;
6208: $output .= '<li>'.$domdesc.':'.join(', ',@longinsttypes).'</li>';
6209: }
6210: }
6211: $output .= '</ul>';
6212: } else {
6213: $output .= &mt('None');
6214: }
6215: }
6216: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6217: next;
6218: }
1.241 raeburn 6219: my $showdomdesc = 1;
6220: my $includeempty = 1;
6221: my $num = 0;
6222: $output .= &Apache::loncommon::start_data_table().
6223: &Apache::loncommon::start_data_table_row()
6224: .'<td colspan="2"><span class="LC_nobreak"><label>'
6225: .&mt('Any user in any domain:')
6226: .' <input type="radio" name="selfenroll_all" value="1" ';
6227: if ($curr_types eq '*') {
6228: $output .= ' checked="checked" ';
6229: }
1.249 raeburn 6230: $output .= 'onchange="javascript:update_types('.
1.418 raeburn 6231: "'selfenroll_all'".');"'.$disabled.' />'.&mt('Yes').'</label>'.
1.249 raeburn 6232: ' <input type="radio" name="selfenroll_all" value="0" ';
1.241 raeburn 6233: if ($curr_types ne '*') {
6234: $output .= ' checked="checked" ';
6235: }
1.249 raeburn 6236: $output .= ' onchange="javascript:update_types('.
1.418 raeburn 6237: "'selfenroll_all'".');"'.$disabled.' />'.&mt('No').'</label></td>'.
1.249 raeburn 6238: &Apache::loncommon::end_data_table_row().
6239: &Apache::loncommon::end_data_table().
6240: &mt('Or').'<br />'.
6241: &Apache::loncommon::start_data_table();
1.241 raeburn 6242: my %currdoms;
1.249 raeburn 6243: if ($curr_types eq '') {
1.241 raeburn 6244: $output .= &new_selfenroll_dom_row($cdom,'0');
6245: } elsif ($curr_types ne '*') {
6246: my @entries = split(/;/,$curr_types);
6247: if (@entries > 0) {
6248: foreach my $entry (@entries) {
6249: my ($currdom,$typestr) = split(/:/,$entry);
6250: $currdoms{$currdom} = 1;
6251: my $domdesc = &Apache::lonnet::domain($currdom);
1.249 raeburn 6252: my @currinsttypes = split(',',$typestr);
1.241 raeburn 6253: $output .= &Apache::loncommon::start_data_table_row()
6254: .'<td valign="top"><span class="LC_nobreak">'.&mt('Domain:').'<b>'
6255: .' '.$domdesc.' ('.$currdom.')'
6256: .'</b><input type="hidden" name="selfenroll_dom_'.$num
6257: .'" value="'.$currdom.'" /></span><br />'
6258: .'<span class="LC_nobreak"><label><input type="checkbox" '
1.418 raeburn 6259: .'name="selfenroll_delete" value="'.$num.'" onchange="javascript:update_types('."'selfenroll_delete','$num'".');"'.$disabled.' />'
1.241 raeburn 6260: .&mt('Delete').'</label></span></td>';
1.249 raeburn 6261: $output .= '<td valign="top"> '.&mt('User types:').'<br />'
1.418 raeburn 6262: .&selfenroll_inst_types($num,$currdom,\@currinsttypes,$readonly).'</td>'
1.241 raeburn 6263: .&Apache::loncommon::end_data_table_row();
6264: $num ++;
6265: }
6266: }
6267: }
1.249 raeburn 6268: my $add_domtitle = &mt('Users in additional domain:');
1.241 raeburn 6269: if ($curr_types eq '*') {
1.249 raeburn 6270: $add_domtitle = &mt('Users in specific domain:');
1.241 raeburn 6271: } elsif ($curr_types eq '') {
1.249 raeburn 6272: $add_domtitle = &mt('Users in other domain:');
1.241 raeburn 6273: }
1.446 raeburn 6274: my ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('enroll',$cdom);
1.241 raeburn 6275: $output .= &Apache::loncommon::start_data_table_row()
6276: .'<td colspan="2"><span class="LC_nobreak">'.$add_domtitle.'</span><br />'
6277: .&Apache::loncommon::select_dom_form('','selfenroll_newdom',
1.446 raeburn 6278: $includeempty,$showdomdesc,'',$trusted,$untrusted,$readonly)
1.241 raeburn 6279: .'<input type="hidden" name="selfenroll_types_total" value="'.$num.'" />'
6280: .'</td>'.&Apache::loncommon::end_data_table_row()
6281: .&Apache::loncommon::end_data_table();
1.237 raeburn 6282: } elsif ($item eq 'registered') {
6283: my ($regon,$regoff);
1.398 raeburn 6284: my $registered;
6285: if (ref($currsettings) eq 'HASH') {
6286: $registered = $currsettings->{'selfenroll_registered'};
6287: }
1.400 raeburn 6288: if ($noedit{$item}) {
6289: if ($registered) {
6290: $output .= &mt('Must be registered in course');
6291: } else {
6292: $output .= &mt('No requirement');
6293: }
6294: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6295: next;
6296: }
1.398 raeburn 6297: if ($registered) {
1.237 raeburn 6298: $regon = ' checked="checked" ';
1.419 raeburn 6299: $regoff = '';
1.237 raeburn 6300: } else {
1.419 raeburn 6301: $regon = '';
1.237 raeburn 6302: $regoff = ' checked="checked" ';
6303: }
6304: $output .= '<label>'.
1.419 raeburn 6305: '<input type="radio" name="selfenroll_registered" value="1"'.$regon.$disabled.' />'.
1.244 bisitz 6306: &mt('Yes').'</label> <label>'.
1.419 raeburn 6307: '<input type="radio" name="selfenroll_registered" value="0"'.$regoff.$disabled.' />'.
1.244 bisitz 6308: &mt('No').'</label>';
1.237 raeburn 6309: } elsif ($item eq 'enroll_dates') {
1.398 raeburn 6310: my ($starttime,$endtime);
6311: if (ref($currsettings) eq 'HASH') {
6312: $starttime = $currsettings->{'selfenroll_start_date'};
6313: $endtime = $currsettings->{'selfenroll_end_date'};
6314: if ($starttime eq '') {
6315: $starttime = $currsettings->{'default_enrollment_start_date'};
6316: }
6317: if ($endtime eq '') {
6318: $endtime = $currsettings->{'default_enrollment_end_date'};
6319: }
1.237 raeburn 6320: }
1.400 raeburn 6321: if ($noedit{$item}) {
6322: $output .= &mt('From: [_1], to: [_2]',&Apache::lonlocal::locallocaltime($starttime),
6323: &Apache::lonlocal::locallocaltime($endtime));
6324: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6325: next;
6326: }
1.237 raeburn 6327: my $startform =
6328: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_start_date',$starttime,
1.418 raeburn 6329: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
1.237 raeburn 6330: my $endform =
6331: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_end_date',$endtime,
1.418 raeburn 6332: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
1.237 raeburn 6333: $output .= &selfenroll_date_forms($startform,$endform);
6334: } elsif ($item eq 'access_dates') {
1.398 raeburn 6335: my ($starttime,$endtime);
6336: if (ref($currsettings) eq 'HASH') {
6337: $starttime = $currsettings->{'selfenroll_start_access'};
6338: $endtime = $currsettings->{'selfenroll_end_access'};
6339: if ($starttime eq '') {
6340: $starttime = $currsettings->{'default_enrollment_start_date'};
6341: }
6342: if ($endtime eq '') {
6343: $endtime = $currsettings->{'default_enrollment_end_date'};
6344: }
1.237 raeburn 6345: }
1.400 raeburn 6346: if ($noedit{$item}) {
6347: $output .= &mt('From: [_1], to: [_2]',&Apache::lonlocal::locallocaltime($starttime),
6348: &Apache::lonlocal::locallocaltime($endtime));
6349: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6350: next;
6351: }
1.237 raeburn 6352: my $startform =
6353: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_start_access',$starttime,
1.418 raeburn 6354: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
1.237 raeburn 6355: my $endform =
6356: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_end_access',$endtime,
1.418 raeburn 6357: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
1.237 raeburn 6358: $output .= &selfenroll_date_forms($startform,$endform);
6359: } elsif ($item eq 'section') {
1.398 raeburn 6360: my $currsec;
6361: if (ref($currsettings) eq 'HASH') {
6362: $currsec = $currsettings->{'selfenroll_section'};
6363: }
1.237 raeburn 6364: my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum);
6365: my $newsecval;
6366: if ($currsec ne 'none' && $currsec ne '') {
6367: if (!defined($sections_count{$currsec})) {
6368: $newsecval = $currsec;
6369: }
6370: }
1.400 raeburn 6371: if ($noedit{$item}) {
6372: if ($currsec ne '') {
6373: $output .= $currsec;
6374: } else {
6375: $output .= &mt('No specific section');
6376: }
6377: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6378: next;
6379: }
1.237 raeburn 6380: my $sections_select =
1.418 raeburn 6381: &Apache::lonuserutils::course_sections(\%sections_count,'st',$currsec,$disabled);
1.237 raeburn 6382: $output .= '<table class="LC_createuser">'."\n".
6383: '<tr class="LC_section_row">'."\n".
6384: '<td align="center">'.&mt('Existing sections')."\n".
6385: '<br />'.$sections_select.'</td><td align="center">'.
6386: &mt('New section').'<br />'."\n".
1.418 raeburn 6387: '<input type="text" name="newsec" size="15" value="'.$newsecval.'"'.$disabled.' />'."\n".
1.237 raeburn 6388: '<input type="hidden" name="sections" value="" />'."\n".
6389: '</td></tr></table>'."\n";
1.276 raeburn 6390: } elsif ($item eq 'approval') {
1.398 raeburn 6391: my ($currnotified,$currapproval,%appchecked);
6392: my %selfdescs = &Apache::lonuserutils::selfenroll_default_descs();
1.430 raeburn 6393: if (ref($currsettings) eq 'HASH') {
1.398 raeburn 6394: $currnotified = $currsettings->{'selfenroll_notifylist'};
6395: $currapproval = $currsettings->{'selfenroll_approval'};
6396: }
6397: if ($currapproval !~ /^[012]$/) {
6398: $currapproval = 0;
6399: }
1.400 raeburn 6400: if ($noedit{$item}) {
6401: $output .= $selfdescs{'approval'}{$currapproval}.
6402: '<br />'.&mt('(Set by Domain Coordinator)');
6403: next;
6404: }
1.398 raeburn 6405: $appchecked{$currapproval} = ' checked="checked"';
6406: for my $i (0..2) {
6407: $output .= '<label>'.
6408: '<input type="radio" name="selfenroll_approval" value="'.$i.'"'.
1.418 raeburn 6409: $appchecked{$i}.' onclick="toggleNotify();"'.$disabled.' />'.
6410: $selfdescs{'approval'}{$i}.'</label>'.(' 'x2);
1.276 raeburn 6411: }
6412: my %advhash = &Apache::lonnet::get_course_adv_roles($cid,1);
6413: my (@ccs,%notified);
1.322 raeburn 6414: my $ccrole = 'cc';
6415: if ($crstype eq 'Community') {
6416: $ccrole = 'co';
6417: }
6418: if ($advhash{$ccrole}) {
6419: @ccs = split(/,/,$advhash{$ccrole});
1.276 raeburn 6420: }
6421: if ($currnotified) {
6422: foreach my $current (split(/,/,$currnotified)) {
6423: $notified{$current} = 1;
6424: if (!grep(/^\Q$current\E$/,@ccs)) {
6425: push(@ccs,$current);
6426: }
6427: }
6428: }
6429: if (@ccs) {
1.398 raeburn 6430: my $style;
6431: unless ($currapproval) {
6432: $style = ' style="display: none;"';
6433: }
6434: $output .= '<br /><div id="notified"'.$style.'>'.
6435: &mt('Personnel to be notified when an enrollment request needs approval, or has been approved:').' '.
6436: &Apache::loncommon::start_data_table().
1.276 raeburn 6437: &Apache::loncommon::start_data_table_row();
6438: my $count = 0;
6439: my $numcols = 4;
6440: foreach my $cc (sort(@ccs)) {
6441: my $notifyon;
6442: my ($ccuname,$ccudom) = split(/:/,$cc);
6443: if ($notified{$cc}) {
6444: $notifyon = ' checked="checked" ';
6445: }
6446: if ($count && !$count%$numcols) {
6447: $output .= &Apache::loncommon::end_data_table_row().
6448: &Apache::loncommon::start_data_table_row()
6449: }
6450: $output .= '<td><span class="LC_nobreak"><label>'.
1.418 raeburn 6451: '<input type="checkbox" name="selfenroll_notify"'.$notifyon.' value="'.$cc.'"'.$disabled.' />'.
1.276 raeburn 6452: &Apache::loncommon::plainname($ccuname,$ccudom).
6453: '</label></span></td>';
1.343 raeburn 6454: $count ++;
1.276 raeburn 6455: }
6456: my $rem = $count%$numcols;
6457: if ($rem) {
6458: my $emptycols = $numcols - $rem;
6459: for (my $i=0; $i<$emptycols; $i++) {
6460: $output .= '<td> </td>';
6461: }
6462: }
6463: $output .= &Apache::loncommon::end_data_table_row().
1.398 raeburn 6464: &Apache::loncommon::end_data_table().
6465: '</div>';
1.276 raeburn 6466: }
6467: } elsif ($item eq 'limit') {
1.398 raeburn 6468: my ($crslimit,$selflimit,$nolimit,$currlim,$currcap);
6469: if (ref($currsettings) eq 'HASH') {
6470: $currlim = $currsettings->{'selfenroll_limit'};
6471: $currcap = $currsettings->{'selfenroll_cap'};
6472: }
1.400 raeburn 6473: if ($noedit{$item}) {
6474: if (($currlim eq 'allstudents') || ($currlim eq 'selfenrolled')) {
6475: if ($currlim eq 'allstudents') {
6476: $output .= &mt('Limit by total students');
6477: } elsif ($currlim eq 'selfenrolled') {
6478: $output .= &mt('Limit by total self-enrolled students');
6479: }
6480: $output .= ' '.&mt('Maximum: [_1]',$currcap).
6481: '<br />'.&mt('(Set by Domain Coordinator)');
6482: } else {
6483: $output .= &mt('No limit').'<br />'.&mt('(Set by Domain Coordinator)');
6484: }
6485: next;
6486: }
1.276 raeburn 6487: if ($currlim eq 'allstudents') {
6488: $crslimit = ' checked="checked" ';
6489: $selflimit = ' ';
6490: $nolimit = ' ';
6491: } elsif ($currlim eq 'selfenrolled') {
6492: $crslimit = ' ';
6493: $selflimit = ' checked="checked" ';
6494: $nolimit = ' ';
6495: } else {
6496: $crslimit = ' ';
6497: $selflimit = ' ';
1.398 raeburn 6498: $nolimit = ' checked="checked" ';
1.276 raeburn 6499: }
6500: $output .= '<table><tr><td><label>'.
1.418 raeburn 6501: '<input type="radio" name="selfenroll_limit" value="none"'.$nolimit.$disabled.'/>'.
1.276 raeburn 6502: &mt('No limit').'</label></td><td><label>'.
1.418 raeburn 6503: '<input type="radio" name="selfenroll_limit" value="allstudents"'.$crslimit.$disabled.'/>'.
1.276 raeburn 6504: &mt('Limit by total students').'</label></td><td><label>'.
1.418 raeburn 6505: '<input type="radio" name="selfenroll_limit" value="selfenrolled"'.$selflimit.$disabled.'/>'.
1.276 raeburn 6506: &mt('Limit by total self-enrolled students').
6507: '</td></tr><tr>'.
6508: '<td> </td><td colspan="2"><span class="LC_nobreak">'.
6509: (' 'x3).&mt('Maximum number allowed: ').
1.418 raeburn 6510: '<input type="text" name="selfenroll_cap" size = "5" value="'.$currcap.'"'.$disabled.' /></td></tr></table>';
1.237 raeburn 6511: }
6512: $output .= &Apache::lonhtmlcommon::row_closure(1);
6513: }
6514: }
1.418 raeburn 6515: $output .= &Apache::lonhtmlcommon::end_pick_box().'<br />';
6516: unless ($readonly) {
6517: $output .= '<input type="button" name="selfenrollconf" value="'
6518: .&mt('Save').'" onclick="validate_types(this.form);" />';
6519: }
6520: $output .= '<input type="hidden" name="action" value="selfenroll" />'
6521: .'<input type="hidden" name="state" value="done" />'."\n"
6522: .$additional.'</form>';
1.237 raeburn 6523: $r->print($output);
6524: return;
6525: }
6526:
1.400 raeburn 6527: sub get_noedit_fields {
6528: my ($cdom,$cnum,$crstype,$row) = @_;
6529: my %noedit;
6530: if (ref($row) eq 'ARRAY') {
6531: my %settings = &Apache::lonnet::get('environment',['internal.coursecode','internal.textbook',
6532: 'internal.selfenrollmgrdc',
6533: 'internal.selfenrollmgrcc'],$cdom,$cnum);
6534: my $type = &Apache::lonuserutils::get_extended_type($cdom,$cnum,$crstype,\%settings);
6535: my (%specific_managebydc,%specific_managebycc,%default_managebydc);
6536: map { $specific_managebydc{$_} = 1; } (split(/,/,$settings{'internal.selfenrollmgrdc'}));
6537: map { $specific_managebycc{$_} = 1; } (split(/,/,$settings{'internal.selfenrollmgrcc'}));
6538: my %domdefaults = &Apache::lonnet::get_domain_defaults($cdom);
6539: map { $default_managebydc{$_} = 1; } (split(/,/,$domdefaults{$type.'selfenrolladmdc'}));
6540:
6541: foreach my $item (@{$row}) {
6542: next if ($specific_managebycc{$item});
6543: if (($specific_managebydc{$item}) || ($default_managebydc{$item})) {
6544: $noedit{$item} = 1;
6545: }
6546: }
6547: }
6548: return %noedit;
6549: }
6550:
6551: sub visible_in_stdcat {
6552: my ($cdom,$cnum,$domconf) = @_;
6553: my ($cathash,%settable,@vismsgs,$cansetvis,$visible);
6554: unless (ref($domconf) eq 'HASH') {
6555: return ($visible,$cansetvis,\@vismsgs);
6556: }
6557: if (ref($domconf->{'coursecategories'}) eq 'HASH') {
6558: if ($domconf->{'coursecategories'}{'togglecats'} eq 'crs') {
1.256 raeburn 6559: $settable{'togglecats'} = 1;
6560: }
1.400 raeburn 6561: if ($domconf->{'coursecategories'}{'categorize'} eq 'crs') {
1.256 raeburn 6562: $settable{'categorize'} = 1;
6563: }
1.400 raeburn 6564: $cathash = $domconf->{'coursecategories'}{'cats'};
1.256 raeburn 6565: }
1.260 raeburn 6566: if ($settable{'togglecats'} && $settable{'categorize'}) {
1.256 raeburn 6567: $cansetvis = &mt('You are able to both assign a course category and choose to exclude this course from the catalog.');
6568: } elsif ($settable{'togglecats'}) {
6569: $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 6570: } elsif ($settable{'categorize'}) {
1.256 raeburn 6571: $cansetvis = &mt('You may assign a course category, but only a Domain Coordinator may choose to exclude this course from the catalog.');
6572: } else {
6573: $cansetvis = &mt('Only a Domain Coordinator may assign a course category or choose to exclude this course from the catalog.');
6574: }
6575:
6576: my %currsettings =
6577: &Apache::lonnet::get('environment',['hidefromcat','categories','internal.coursecode'],
6578: $cdom,$cnum);
1.400 raeburn 6579: $visible = 0;
1.256 raeburn 6580: if ($currsettings{'internal.coursecode'} ne '') {
1.400 raeburn 6581: if (ref($domconf->{'coursecategories'}) eq 'HASH') {
6582: $cathash = $domconf->{'coursecategories'}{'cats'};
1.256 raeburn 6583: if (ref($cathash) eq 'HASH') {
6584: if ($cathash->{'instcode::0'} eq '') {
6585: push(@vismsgs,'dc_addinst');
6586: } else {
6587: $visible = 1;
6588: }
6589: } else {
6590: $visible = 1;
6591: }
6592: } else {
6593: $visible = 1;
6594: }
6595: } else {
6596: if (ref($cathash) eq 'HASH') {
6597: if ($cathash->{'instcode::0'} ne '') {
6598: push(@vismsgs,'dc_instcode');
6599: }
6600: } else {
6601: push(@vismsgs,'dc_instcode');
6602: }
6603: }
6604: if ($currsettings{'categories'} ne '') {
6605: my $cathash;
1.400 raeburn 6606: if (ref($domconf->{'coursecategories'}) eq 'HASH') {
6607: $cathash = $domconf->{'coursecategories'}{'cats'};
1.256 raeburn 6608: if (ref($cathash) eq 'HASH') {
6609: if (keys(%{$cathash}) == 0) {
6610: push(@vismsgs,'dc_catalog');
6611: } elsif ((keys(%{$cathash}) == 1) && ($cathash->{'instcode::0'} ne '')) {
6612: push(@vismsgs,'dc_categories');
6613: } else {
6614: my @currcategories = split('&',$currsettings{'categories'});
6615: my $matched = 0;
6616: foreach my $cat (@currcategories) {
6617: if ($cathash->{$cat} ne '') {
6618: $visible = 1;
6619: $matched = 1;
6620: last;
6621: }
6622: }
6623: if (!$matched) {
1.260 raeburn 6624: if ($settable{'categorize'}) {
1.256 raeburn 6625: push(@vismsgs,'chgcat');
6626: } else {
6627: push(@vismsgs,'dc_chgcat');
6628: }
6629: }
6630: }
6631: }
6632: }
6633: } else {
6634: if (ref($cathash) eq 'HASH') {
6635: if ((keys(%{$cathash}) > 1) ||
6636: (keys(%{$cathash}) == 1) && ($cathash->{'instcode::0'} eq '')) {
1.260 raeburn 6637: if ($settable{'categorize'}) {
1.256 raeburn 6638: push(@vismsgs,'addcat');
6639: } else {
6640: push(@vismsgs,'dc_addcat');
6641: }
6642: }
6643: }
6644: }
6645: if ($currsettings{'hidefromcat'} eq 'yes') {
6646: $visible = 0;
6647: if ($settable{'togglecats'}) {
6648: unshift(@vismsgs,'unhide');
6649: } else {
6650: unshift(@vismsgs,'dc_unhide')
6651: }
6652: }
1.400 raeburn 6653: return ($visible,$cansetvis,\@vismsgs);
6654: }
6655:
6656: sub cat_visibility {
6657: my %visactions = &Apache::lonlocal::texthash(
6658: vis => 'This course/community currently appears in the Course/Community Catalog for this domain.',
6659: 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.',
6660: miss => 'This course/community does not currently appear in the Course/Community Catalog for this domain.',
6661: none => 'Display of a course catalog is disabled for this domain.',
6662: yous => 'You should remedy this if you plan to allow self-enrollment, otherwise students will have difficulty finding this course.',
6663: 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.',
6664: make => 'Make any changes to self-enrollment settings below, click "Save", then take action to include the course in the Catalog:',
6665: take => 'Take the following action to ensure the course appears in the Catalog:',
6666: dc_chgconf => 'Ask a domain coordinator to change the Catalog type for this domain.',
6667: dc_setcode => 'Ask a domain coordinator to assign a six character code to the course',
6668: dc_unhide => 'Ask a domain coordinator to change the "Exclude from course catalog" setting.',
6669: dc_addinst => 'Ask a domain coordinator to enable display the catalog of "Official courses (with institutional codes)".',
6670: dc_instcode => 'Ask a domain coordinator to assign an institutional code (if this is an official course).',
6671: dc_catalog => 'Ask a domain coordinator to enable or create at least one course category in the domain.',
6672: dc_categories => 'Ask a domain coordinator to create a hierarchy of categories and sub categories for courses in the domain.',
6673: 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',
6674: dc_addcat => 'Ask a domain coordinator to assign a category to the course.',
6675: );
6676: $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>"');
6677: $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>"');
6678: $visactions{'addcat'} = &mt('Use [_1]Categorize course[_2] to assign a category to the course.','"<a href="/adm/courseprefs?phase=display&actions=courseinfo">','</a>"');
6679: return \%visactions;
1.256 raeburn 6680: }
6681:
1.241 raeburn 6682: sub new_selfenroll_dom_row {
6683: my ($newdom,$num) = @_;
6684: my $domdesc = &Apache::lonnet::domain($newdom);
6685: my $output;
6686: if ($domdesc ne '') {
6687: $output .= &Apache::loncommon::start_data_table_row()
6688: .'<td valign="top"><span class="LC_nobreak">'.&mt('Domain:').' <b>'.$domdesc
6689: .' ('.$newdom.')</b><input type="hidden" name="selfenroll_dom_'.$num
1.249 raeburn 6690: .'" value="'.$newdom.'" /></span><br />'
6691: .'<span class="LC_nobreak"><label><input type="checkbox" '
6692: .'name="selfenroll_activate" value="'.$num.'" '
6693: .'onchange="javascript:update_types('
6694: ."'selfenroll_activate','$num'".');" />'
6695: .&mt('Activate').'</label></span></td>';
1.241 raeburn 6696: my @currinsttypes;
6697: $output .= '<td>'.&mt('User types:').'<br />'
6698: .&selfenroll_inst_types($num,$newdom,\@currinsttypes).'</td>'
6699: .&Apache::loncommon::end_data_table_row();
6700: }
6701: return $output;
6702: }
6703:
6704: sub selfenroll_inst_types {
1.418 raeburn 6705: my ($num,$currdom,$currinsttypes,$readonly) = @_;
1.241 raeburn 6706: my $output;
6707: my $numinrow = 4;
6708: my $count = 0;
6709: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($currdom);
1.247 raeburn 6710: my $othervalue = 'any';
1.418 raeburn 6711: my $disabled;
6712: if ($readonly) {
6713: $disabled = ' disabled="disabled"';
6714: }
1.241 raeburn 6715: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
1.251 raeburn 6716: if (keys(%{$usertypes}) > 0) {
1.247 raeburn 6717: $othervalue = 'other';
6718: }
1.241 raeburn 6719: $output .= '<table><tr>';
6720: foreach my $type (@{$types}) {
6721: if (($count > 0) && ($count%$numinrow == 0)) {
6722: $output .= '</tr><tr>';
6723: }
6724: if (defined($usertypes->{$type})) {
1.257 raeburn 6725: my $esc_type = &escape($type);
1.241 raeburn 6726: $output .= '<td><span class="LC_nobreak"><label><input type = "checkbox" value="'.
1.257 raeburn 6727: $esc_type.'" ';
1.241 raeburn 6728: if (ref($currinsttypes) eq 'ARRAY') {
6729: if (@{$currinsttypes} > 0) {
1.249 raeburn 6730: if (grep(/^any$/,@{$currinsttypes})) {
6731: $output .= 'checked="checked"';
1.257 raeburn 6732: } elsif (grep(/^\Q$esc_type\E$/,@{$currinsttypes})) {
1.241 raeburn 6733: $output .= 'checked="checked"';
6734: }
1.249 raeburn 6735: } else {
6736: $output .= 'checked="checked"';
1.241 raeburn 6737: }
6738: }
1.418 raeburn 6739: $output .= ' name="selfenroll_types_'.$num.'"'.$disabled.' />'.$usertypes->{$type}.'</label></span></td>';
1.241 raeburn 6740: }
6741: $count ++;
6742: }
6743: if (($count > 0) && ($count%$numinrow == 0)) {
6744: $output .= '</tr><tr>';
6745: }
1.249 raeburn 6746: $output .= '<td><span class="LC_nobreak"><label><input type = "checkbox" value="'.$othervalue.'"';
1.241 raeburn 6747: if (ref($currinsttypes) eq 'ARRAY') {
6748: if (@{$currinsttypes} > 0) {
1.249 raeburn 6749: if (grep(/^any$/,@{$currinsttypes})) {
6750: $output .= ' checked="checked"';
6751: } elsif ($othervalue eq 'other') {
6752: if (grep(/^\Q$othervalue\E$/,@{$currinsttypes})) {
6753: $output .= ' checked="checked"';
6754: }
1.241 raeburn 6755: }
1.249 raeburn 6756: } else {
6757: $output .= ' checked="checked"';
1.241 raeburn 6758: }
1.249 raeburn 6759: } else {
6760: $output .= ' checked="checked"';
1.241 raeburn 6761: }
1.418 raeburn 6762: $output .= ' name="selfenroll_types_'.$num.'"'.$disabled.' />'.$othertitle.'</label></span></td></tr></table>';
1.241 raeburn 6763: }
6764: return $output;
6765: }
6766:
1.237 raeburn 6767: sub selfenroll_date_forms {
6768: my ($startform,$endform) = @_;
6769: my $output .= &Apache::lonhtmlcommon::start_pick_box()."\n".
1.244 bisitz 6770: &Apache::lonhtmlcommon::row_title(&mt('Start date'),
1.237 raeburn 6771: 'LC_oddrow_value')."\n".
6772: $startform."\n".
6773: &Apache::lonhtmlcommon::row_closure(1).
1.244 bisitz 6774: &Apache::lonhtmlcommon::row_title(&mt('End date'),
1.237 raeburn 6775: 'LC_oddrow_value')."\n".
6776: $endform."\n".
6777: &Apache::lonhtmlcommon::row_closure(1).
6778: &Apache::lonhtmlcommon::end_pick_box();
6779: return $output;
6780: }
6781:
1.239 raeburn 6782: sub print_userchangelogs_display {
1.415 raeburn 6783: my ($r,$context,$permission,$brcrum) = @_;
1.363 raeburn 6784: my $formname = 'rolelog';
1.418 raeburn 6785: my ($username,$domain,$crstype,$viewablesec,%roleslog);
1.363 raeburn 6786: if ($context eq 'domain') {
6787: $domain = $env{'request.role.domain'};
6788: %roleslog=&Apache::lonnet::dump_dom('nohist_rolelog',$domain);
6789: } else {
6790: if ($context eq 'course') {
6791: $domain = $env{'course.'.$env{'request.course.id'}.'.domain'};
6792: $username = $env{'course.'.$env{'request.course.id'}.'.num'};
6793: $crstype = &Apache::loncommon::course_type();
1.418 raeburn 6794: $viewablesec = &Apache::lonuserutils::viewable_section($permission);
1.363 raeburn 6795: my %saveable_parameters = ('show' => 'scalar',);
6796: &Apache::loncommon::store_course_settings('roles_log',
6797: \%saveable_parameters);
6798: &Apache::loncommon::restore_course_settings('roles_log',
6799: \%saveable_parameters);
6800: } elsif ($context eq 'author') {
6801: $domain = $env{'user.domain'};
6802: if ($env{'request.role'} =~ m{^au\./\Q$domain\E/$}) {
6803: $username = $env{'user.name'};
6804: } else {
6805: undef($domain);
6806: }
6807: }
6808: if ($domain ne '' && $username ne '') {
6809: %roleslog=&Apache::lonnet::dump('nohist_rolelog',$domain,$username);
6810: }
6811: }
1.239 raeburn 6812: if ((keys(%roleslog))[0]=~/^error\:/) { undef(%roleslog); }
6813:
1.415 raeburn 6814: my $helpitem;
6815: if ($context eq 'course') {
6816: $helpitem = 'Course_User_Logs';
1.439 raeburn 6817: } elsif ($context eq 'domain') {
6818: $helpitem = 'Domain_Role_Logs';
6819: } elsif ($context eq 'author') {
6820: $helpitem = 'Author_User_Logs';
1.415 raeburn 6821: }
6822: push (@{$brcrum},
6823: {href => '/adm/createuser?action=changelogs',
6824: text => 'User Management Logs',
6825: help => $helpitem});
6826: my $bread_crumbs_component = 'User Changes';
6827: my $args = { bread_crumbs => $brcrum,
6828: bread_crumbs_component => $bread_crumbs_component};
6829:
6830: # Create navigation javascript
6831: my $jsnav = &userlogdisplay_js($formname);
6832:
6833: my $jscript = (<<ENDSCRIPT);
6834: <script type="text/javascript">
6835: // <![CDATA[
6836: $jsnav
6837: // ]]>
6838: </script>
6839: ENDSCRIPT
6840:
6841: # print page header
6842: $r->print(&header($jscript,$args));
6843:
1.239 raeburn 6844: # set defaults
6845: my $now = time();
6846: my $defstart = $now - (7*24*3600); #7 days ago
6847: my %defaults = (
6848: page => '1',
6849: show => '10',
6850: role => 'any',
6851: chgcontext => 'any',
6852: rolelog_start_date => $defstart,
6853: rolelog_end_date => $now,
6854: );
6855: my $more_records = 0;
6856:
6857: # set current
6858: my %curr;
6859: foreach my $item ('show','page','role','chgcontext') {
6860: $curr{$item} = $env{'form.'.$item};
6861: }
6862: my ($startdate,$enddate) =
6863: &Apache::lonuserutils::get_dates_from_form('rolelog_start_date','rolelog_end_date');
6864: $curr{'rolelog_start_date'} = $startdate;
6865: $curr{'rolelog_end_date'} = $enddate;
6866: foreach my $key (keys(%defaults)) {
6867: if ($curr{$key} eq '') {
6868: $curr{$key} = $defaults{$key};
6869: }
6870: }
1.248 raeburn 6871: my (%whodunit,%changed,$version);
6872: ($version) = ($r->dir_config('lonVersion') =~ /^([\d\.]+)\-/);
1.239 raeburn 6873: my ($minshown,$maxshown);
1.255 raeburn 6874: $minshown = 1;
1.239 raeburn 6875: my $count = 0;
1.415 raeburn 6876: if ($curr{'show'} =~ /\D/) {
6877: $curr{'page'} = 1;
6878: } else {
1.239 raeburn 6879: $maxshown = $curr{'page'} * $curr{'show'};
6880: if ($curr{'page'} > 1) {
6881: $minshown = 1 + ($curr{'page'} - 1) * $curr{'show'};
6882: }
6883: }
1.301 bisitz 6884:
1.327 raeburn 6885: # Form Header
6886: $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">'.
1.363 raeburn 6887: &role_display_filter($context,$formname,$domain,$username,\%curr,
6888: $version,$crstype));
1.327 raeburn 6889:
6890: my $showntableheader = 0;
6891:
6892: # Table Header
6893: my $tableheader =
6894: &Apache::loncommon::start_data_table_header_row()
6895: .'<th> </th>'
6896: .'<th>'.&mt('When').'</th>'
6897: .'<th>'.&mt('Who made the change').'</th>'
6898: .'<th>'.&mt('Changed User').'</th>'
1.363 raeburn 6899: .'<th>'.&mt('Role').'</th>';
6900:
6901: if ($context eq 'course') {
6902: $tableheader .= '<th>'.&mt('Section').'</th>';
6903: }
6904: $tableheader .=
6905: '<th>'.&mt('Context').'</th>'
1.327 raeburn 6906: .'<th>'.&mt('Start').'</th>'
6907: .'<th>'.&mt('End').'</th>'
6908: .&Apache::loncommon::end_data_table_header_row();
6909:
6910: # Display user change log data
1.239 raeburn 6911: foreach my $id (sort { $roleslog{$b}{'exe_time'}<=>$roleslog{$a}{'exe_time'} } (keys(%roleslog))) {
6912: next if (($roleslog{$id}{'exe_time'} < $curr{'rolelog_start_date'}) ||
6913: ($roleslog{$id}{'exe_time'} > $curr{'rolelog_end_date'}));
1.415 raeburn 6914: if ($curr{'show'} !~ /\D/) {
1.239 raeburn 6915: if ($count >= $curr{'page'} * $curr{'show'}) {
6916: $more_records = 1;
6917: last;
6918: }
6919: }
6920: if ($curr{'role'} ne 'any') {
6921: next if ($roleslog{$id}{'logentry'}{'role'} ne $curr{'role'});
6922: }
6923: if ($curr{'chgcontext'} ne 'any') {
6924: if ($curr{'chgcontext'} eq 'selfenroll') {
6925: next if (!$roleslog{$id}{'logentry'}{'selfenroll'});
6926: } else {
6927: next if ($roleslog{$id}{'logentry'}{'context'} ne $curr{'chgcontext'});
6928: }
6929: }
1.418 raeburn 6930: if (($context eq 'course') && ($viewablesec ne '')) {
1.430 raeburn 6931: next if ($roleslog{$id}{'logentry'}{'section'} ne $viewablesec);
1.418 raeburn 6932: }
1.239 raeburn 6933: $count ++;
6934: next if ($count < $minshown);
1.327 raeburn 6935: unless ($showntableheader) {
1.415 raeburn 6936: $r->print(&Apache::loncommon::start_data_table()
1.327 raeburn 6937: .$tableheader);
6938: $r->rflush();
6939: $showntableheader = 1;
6940: }
1.239 raeburn 6941: if ($whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}} eq '') {
6942: $whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}} =
6943: &Apache::loncommon::plainname($roleslog{$id}{'exe_uname'},$roleslog{$id}{'exe_udom'});
6944: }
6945: if ($changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}} eq '') {
6946: $changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}} =
6947: &Apache::loncommon::plainname($roleslog{$id}{'uname'},$roleslog{$id}{'udom'});
6948: }
6949: my $sec = $roleslog{$id}{'logentry'}{'section'};
6950: if ($sec eq '') {
6951: $sec = &mt('None');
6952: }
6953: my ($rolestart,$roleend);
6954: if ($roleslog{$id}{'delflag'}) {
6955: $rolestart = &mt('deleted');
6956: $roleend = &mt('deleted');
6957: } else {
6958: $rolestart = $roleslog{$id}{'logentry'}{'start'};
6959: $roleend = $roleslog{$id}{'logentry'}{'end'};
6960: if ($rolestart eq '' || $rolestart == 0) {
6961: $rolestart = &mt('No start date');
6962: } else {
6963: $rolestart = &Apache::lonlocal::locallocaltime($rolestart);
6964: }
6965: if ($roleend eq '' || $roleend == 0) {
6966: $roleend = &mt('No end date');
6967: } else {
6968: $roleend = &Apache::lonlocal::locallocaltime($roleend);
6969: }
6970: }
6971: my $chgcontext = $roleslog{$id}{'logentry'}{'context'};
6972: if ($roleslog{$id}{'logentry'}{'selfenroll'}) {
6973: $chgcontext = 'selfenroll';
6974: }
1.363 raeburn 6975: my %lt = &rolechg_contexts($context,$crstype);
1.239 raeburn 6976: if ($chgcontext ne '' && $lt{$chgcontext} ne '') {
6977: $chgcontext = $lt{$chgcontext};
6978: }
1.327 raeburn 6979: $r->print(
1.301 bisitz 6980: &Apache::loncommon::start_data_table_row()
6981: .'<td>'.$count.'</td>'
6982: .'<td>'.&Apache::lonlocal::locallocaltime($roleslog{$id}{'exe_time'}).'</td>'
6983: .'<td>'.$whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}}.'</td>'
6984: .'<td>'.$changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}}.'</td>'
1.363 raeburn 6985: .'<td>'.&Apache::lonnet::plaintext($roleslog{$id}{'logentry'}{'role'},$crstype).'</td>');
6986: if ($context eq 'course') {
6987: $r->print('<td>'.$sec.'</td>');
6988: }
6989: $r->print(
6990: '<td>'.$chgcontext.'</td>'
1.301 bisitz 6991: .'<td>'.$rolestart.'</td>'
6992: .'<td>'.$roleend.'</td>'
1.327 raeburn 6993: .&Apache::loncommon::end_data_table_row()."\n");
1.301 bisitz 6994: }
6995:
1.327 raeburn 6996: if ($showntableheader) { # Table footer, if content displayed above
1.415 raeburn 6997: $r->print(&Apache::loncommon::end_data_table().
6998: &userlogdisplay_navlinks(\%curr,$more_records));
1.327 raeburn 6999: } else { # No content displayed above
1.301 bisitz 7000: $r->print('<p class="LC_info">'
7001: .&mt('There are no records to display.')
7002: .'</p>'
7003: );
1.239 raeburn 7004: }
1.301 bisitz 7005:
1.327 raeburn 7006: # Form Footer
7007: $r->print(
7008: '<input type="hidden" name="page" value="'.$curr{'page'}.'" />'
7009: .'<input type="hidden" name="action" value="changelogs" />'
7010: .'</form>');
7011: return;
7012: }
1.301 bisitz 7013:
1.416 raeburn 7014: sub print_useraccesslogs_display {
7015: my ($r,$uname,$udom,$permission,$brcrum) = @_;
7016: my $formname = 'accesslog';
7017: my $form = 'document.accesslog';
7018:
7019: # set breadcrumbs
1.422 raeburn 7020: my %breadcrumb_text = &singleuser_breadcrumb('','domain',$udom);
1.431 raeburn 7021: my $prevphasestr;
7022: if ($env{'form.popup'}) {
7023: $brcrum = [];
7024: } else {
7025: push (@{$brcrum},
7026: {href => "javascript:backPage($form)",
7027: text => $breadcrumb_text{'search'}});
7028: my @prevphases;
7029: if ($env{'form.prevphases'}) {
7030: @prevphases = split(/,/,$env{'form.prevphases'});
7031: $prevphasestr = $env{'form.prevphases'};
7032: }
7033: if (($env{'form.phase'} eq 'userpicked') || (grep(/^userpicked$/,@prevphases))) {
7034: push(@{$brcrum},
7035: {href => "javascript:backPage($form,'get_user_info','select')",
7036: text => $breadcrumb_text{'userpicked'}});
7037: if ($env{'form.phase'} eq 'userpicked') {
7038: $prevphasestr = 'userpicked';
7039: }
1.416 raeburn 7040: }
7041: }
7042: push(@{$brcrum},
7043: {href => '/adm/createuser?action=accesslogs',
7044: text => 'User access logs',
1.424 raeburn 7045: help => 'Domain_User_Access_Logs'});
1.416 raeburn 7046: my $bread_crumbs_component = 'User Access Logs';
7047: my $args = { bread_crumbs => $brcrum,
7048: bread_crumbs_component => 'User Management'};
1.423 raeburn 7049: if ($env{'form.popup'}) {
7050: $args->{'no_nav_bar'} = 1;
1.431 raeburn 7051: $args->{'bread_crumbs_nomenu'} = 1;
1.423 raeburn 7052: }
1.416 raeburn 7053:
1.417 raeburn 7054: # set javascript
1.416 raeburn 7055: my ($jsback,$elements) = &crumb_utilities();
7056: my $jsnav = &userlogdisplay_js($formname);
7057:
7058: my $jscript = (<<ENDSCRIPT);
7059: <script type="text/javascript">
7060: // <![CDATA[
7061:
7062: $jsback
7063: $jsnav
7064:
7065: // ]]>
7066: </script>
7067:
7068: ENDSCRIPT
7069:
1.417 raeburn 7070: # print page header
1.416 raeburn 7071: $r->print(&header($jscript,$args));
7072:
7073: # early out unless log data can be displayed.
7074: unless ($permission->{'activity'}) {
7075: $r->print('<p class="LC_warning">'
7076: .&mt('You do not have rights to display user access logs.')
1.431 raeburn 7077: .'</p>');
7078: if ($env{'form.popup'}) {
7079: $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a></p>');
7080: } else {
7081: $r->print(&earlyout_accesslog_form($formname,$prevphasestr,$udom));
7082: }
1.416 raeburn 7083: return;
7084: }
7085:
7086: unless ($udom eq $env{'request.role.domain'}) {
7087: $r->print('<p class="LC_warning">'
7088: .&mt("User's domain must match role's domain")
7089: .'</p>'
7090: .&earlyout_accesslog_form($formname,$prevphasestr,$udom));
1.417 raeburn 7091: return;
1.416 raeburn 7092: }
7093:
7094: if (($uname eq '') || ($udom eq '')) {
7095: $r->print('<p class="LC_warning">'
7096: .&mt('Invalid username or domain')
7097: .'</p>'
7098: .&earlyout_accesslog_form($formname,$prevphasestr,$udom));
7099: return;
7100: }
7101:
1.437 raeburn 7102: if (&Apache::lonnet::privileged($uname,$udom,
7103: [$env{'request.role.domain'}],['dc','su'])) {
7104: unless (&Apache::lonnet::privileged($env{'user.name'},$env{'user.domain'},
7105: [$env{'request.role.domain'}],['dc','su'])) {
7106: $r->print('<p class="LC_warning">'
7107: .&mt('You need to be a privileged user to display user access logs for [_1]',
7108: &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),
7109: $uname,$udom))
7110: .'</p>');
7111: if ($env{'form.popup'}) {
7112: $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a></p>');
7113: } else {
7114: $r->print(&earlyout_accesslog_form($formname,$prevphasestr,$udom));
7115: }
7116: return;
7117: }
7118: }
7119:
1.416 raeburn 7120: # set defaults
7121: my $now = time();
7122: my $defstart = $now - (7*24*3600);
7123: my %defaults = (
7124: page => '1',
7125: show => '10',
7126: activity => 'any',
7127: accesslog_start_date => $defstart,
7128: accesslog_end_date => $now,
7129: );
7130: my $more_records = 0;
7131:
7132: # set current
7133: my %curr;
7134: foreach my $item ('show','page','activity') {
7135: $curr{$item} = $env{'form.'.$item};
7136: }
7137: my ($startdate,$enddate) =
7138: &Apache::lonuserutils::get_dates_from_form('accesslog_start_date','accesslog_end_date');
7139: $curr{'accesslog_start_date'} = $startdate;
7140: $curr{'accesslog_end_date'} = $enddate;
7141: foreach my $key (keys(%defaults)) {
7142: if ($curr{$key} eq '') {
7143: $curr{$key} = $defaults{$key};
7144: }
7145: }
7146: my ($minshown,$maxshown);
7147: $minshown = 1;
7148: my $count = 0;
7149: if ($curr{'show'} =~ /\D/) {
7150: $curr{'page'} = 1;
7151: } else {
7152: $maxshown = $curr{'page'} * $curr{'show'};
7153: if ($curr{'page'} > 1) {
7154: $minshown = 1 + ($curr{'page'} - 1) * $curr{'show'};
7155: }
7156: }
7157:
7158: # form header
7159: $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">'.
7160: &activity_display_filter($formname,\%curr));
7161:
7162: my $showntableheader = 0;
7163: my ($nav_script,$nav_links);
7164:
7165: # table header
1.453 raeburn 7166: my $heading = '<h3>'.
1.431 raeburn 7167: &mt('User access logs for: [_1]',
1.453 raeburn 7168: &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),$uname,$udom)).'</h3>';
7169: my $tableheader = $heading
1.431 raeburn 7170: .&Apache::loncommon::start_data_table_header_row()
1.416 raeburn 7171: .'<th> </th>'
7172: .'<th>'.&mt('When').'</th>'
7173: .'<th>'.&mt('HostID').'</th>'
7174: .'<th>'.&mt('Event').'</th>'
7175: .'<th>'.&mt('Other data').'</th>'
7176: .&Apache::loncommon::end_data_table_header_row();
7177:
7178: my %filters=(
7179: start => $curr{'accesslog_start_date'},
7180: end => $curr{'accesslog_end_date'},
7181: action => $curr{'activity'},
7182: );
7183:
7184: my $reply = &Apache::lonnet::userlog_query($uname,$udom,%filters);
7185: unless ( ($reply =~/^timeout/) || ($reply =~/^error/) ) {
7186: my (%courses,%missing);
7187: my @results = split(/\&/,$reply);
7188: foreach my $item (reverse(@results)) {
7189: my ($timestamp,$host,$event) = split(/:/,$item);
7190: next unless ($event =~ /^(Log|Role)/);
7191: if ($curr{'show'} !~ /\D/) {
7192: if ($count >= $curr{'page'} * $curr{'show'}) {
7193: $more_records = 1;
7194: last;
7195: }
7196: }
7197: $count ++;
7198: next if ($count < $minshown);
7199: unless ($showntableheader) {
7200: $r->print($nav_script
7201: .&Apache::loncommon::start_data_table()
7202: .$tableheader);
7203: $r->rflush();
7204: $showntableheader = 1;
7205: }
1.418 raeburn 7206: my ($shown,$extra);
1.437 raeburn 7207: my ($event,$data) = split(/\s+/,&unescape($event),2);
1.416 raeburn 7208: if ($event eq 'Role') {
7209: my ($rolecode,$extent) = split(/\./,$data,2);
7210: next if ($extent eq '');
7211: my ($crstype,$desc,$info);
1.418 raeburn 7212: if ($extent =~ m{^/($match_domain)/($match_courseid)(?:/(\w+)|)$}) {
7213: my ($cdom,$cnum,$sec) = ($1,$2,$3);
1.416 raeburn 7214: my $cid = $cdom.'_'.$cnum;
7215: if (exists($courses{$cid})) {
7216: $crstype = $courses{$cid}{'type'};
7217: $desc = $courses{$cid}{'description'};
7218: } elsif ($missing{$cid}) {
7219: $crstype = 'Course';
7220: $desc = 'Course/Community';
7221: } else {
7222: my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',$cnum,undef,undef,'.');
7223: if (ref($crsinfo{$cdom.'_'.$cnum}) eq 'HASH') {
7224: $courses{$cid} = $crsinfo{$cid};
7225: $crstype = $crsinfo{$cid}{'type'};
7226: $desc = $crsinfo{$cid}{'description'};
7227: } else {
7228: $missing{$cid} = 1;
7229: }
7230: }
7231: $extra = &mt($crstype).': <a href="/public/'.$cdom.'/'.$cnum.'/syllabus">'.$desc.'</a>';
1.418 raeburn 7232: if ($sec ne '') {
7233: $extra .= ' ('.&mt('Section: [_1]',$sec).')';
7234: }
1.416 raeburn 7235: } elsif ($extent =~ m{^/($match_domain)/($match_username|$)}) {
7236: my ($dom,$name) = ($1,$2);
7237: if ($rolecode eq 'au') {
7238: $extra = '';
7239: } elsif ($rolecode =~ /^(ca|aa)$/) {
1.417 raeburn 7240: $extra = &mt('Authoring Space: [_1]',$name.':'.$dom);
1.416 raeburn 7241: } elsif ($rolecode =~ /^(li|dg|dh|dc|sc)$/) {
7242: $extra = &mt('Domain: [_1]',$dom);
7243: }
7244: }
7245: my $rolename;
7246: if ($rolecode =~ m{^cr/($match_domain)/($match_username)/(\w+)}) {
7247: my $role = $3;
1.417 raeburn 7248: my $owner = "($2:$1)";
1.416 raeburn 7249: if ($2 eq $1.'-domainconfig') {
7250: $owner = '(ad hoc)';
1.417 raeburn 7251: }
1.416 raeburn 7252: $rolename = &mt('Custom role: [_1]',$role.' '.$owner);
7253: } else {
7254: $rolename = &Apache::lonnet::plaintext($rolecode,$crstype);
7255: }
7256: $shown = &mt('Role selection: [_1]',$rolename);
7257: } else {
7258: $shown = &mt($event);
1.437 raeburn 7259: if ($data =~ /^webdav/) {
7260: my ($path,$clientip) = split(/\s+/,$data,2);
7261: $path =~ s/^webdav//;
7262: if ($clientip ne '') {
7263: $extra = &mt('Client IP address: [_1]',$clientip);
7264: }
7265: if ($path ne '') {
7266: $shown .= ' '.&mt('(WebDAV access to [_1])',$path);
7267: }
7268: } elsif ($data ne '') {
7269: $extra = &mt('Client IP address: [_1]',$data);
1.416 raeburn 7270: }
7271: }
7272: $r->print(
7273: &Apache::loncommon::start_data_table_row()
7274: .'<td>'.$count.'</td>'
7275: .'<td>'.&Apache::lonlocal::locallocaltime($timestamp).'</td>'
7276: .'<td>'.$host.'</td>'
7277: .'<td>'.$shown.'</td>'
7278: .'<td>'.$extra.'</td>'
7279: .&Apache::loncommon::end_data_table_row()."\n");
7280: }
7281: }
7282:
7283: if ($showntableheader) { # Table footer, if content displayed above
7284: $r->print(&Apache::loncommon::end_data_table().
7285: &userlogdisplay_navlinks(\%curr,$more_records));
7286: } else { # No content displayed above
1.453 raeburn 7287: $r->print($heading.'<p class="LC_info">'
1.416 raeburn 7288: .&mt('There are no records to display.')
7289: .'</p>');
7290: }
7291:
1.423 raeburn 7292: if ($env{'form.popup'} == 1) {
7293: $r->print('<input type="hidden" name="popup" value="1" />'."\n");
7294: }
7295:
1.416 raeburn 7296: # Form Footer
7297: $r->print(
7298: '<input type="hidden" name="currstate" value="" />'
7299: .'<input type="hidden" name="accessuname" value="'.$uname.'" />'
7300: .'<input type="hidden" name="accessudom" value="'.$udom.'" />'
7301: .'<input type="hidden" name="page" value="'.$curr{'page'}.'" />'
7302: .'<input type="hidden" name="prevphases" value="'.$prevphasestr.'" />'
7303: .'<input type="hidden" name="phase" value="activity" />'
7304: .'<input type="hidden" name="action" value="accesslogs" />'
7305: .'<input type="hidden" name="srchdomain" value="'.$udom.'" />'
7306: .'<input type="hidden" name="srchby" value="'.$env{'form.srchby'}.'" />'
7307: .'<input type="hidden" name="srchtype" value="'.$env{'form.srchtype'}.'" />'
7308: .'<input type="hidden" name="srchterm" value="'.&HTML::Entities::encode($env{'form.srchterm'},'<>"&').'" />'
7309: .'<input type="hidden" name="srchin" value="'.$env{'form.srchin'}.'" />'
7310: .'</form>');
7311: return;
7312: }
7313:
7314: sub earlyout_accesslog_form {
7315: my ($formname,$prevphasestr,$udom) = @_;
7316: my $srchterm = &HTML::Entities::encode($env{'form.srchterm'},'<>"&');
7317: return <<"END";
7318: <form action="/adm/createuser" method="post" name="$formname">
7319: <input type="hidden" name="currstate" value="" />
7320: <input type="hidden" name="prevphases" value="$prevphasestr" />
7321: <input type="hidden" name="phase" value="activity" />
7322: <input type="hidden" name="action" value="accesslogs" />
7323: <input type="hidden" name="srchdomain" value="$udom" />
7324: <input type="hidden" name="srchby" value="$env{'form.srchby'}" />
7325: <input type="hidden" name="srchtype" value="$env{'form.srchtype'}" />
7326: <input type="hidden" name="srchterm" value="$srchterm" />
7327: <input type="hidden" name="srchin" value="$env{'form.srchin'}" />
7328: </form>
7329: END
7330: }
7331:
7332: sub activity_display_filter {
7333: my ($formname,$curr) = @_;
7334: my $nolink = 1;
7335: my $output = '<table><tr><td valign="top">'.
7336: '<span class="LC_nobreak"><b>'.&mt('Actions/page:').'</b></span><br />'.
7337: &Apache::lonmeta::selectbox('show',$curr->{'show'},undef,
7338: (&mt('all'),5,10,20,50,100,1000,10000)).
7339: '</td><td> </td>';
7340: my $startform =
7341: &Apache::lonhtmlcommon::date_setter($formname,'accesslog_start_date',
7342: $curr->{'accesslog_start_date'},undef,
7343: undef,undef,undef,undef,undef,undef,$nolink);
7344: my $endform =
7345: &Apache::lonhtmlcommon::date_setter($formname,'accesslog_end_date',
7346: $curr->{'accesslog_end_date'},undef,
7347: undef,undef,undef,undef,undef,undef,$nolink);
7348: my %lt = &Apache::lonlocal::texthash (
7349: activity => 'Activity',
7350: Role => 'Role selection',
7351: log => 'Log-in or Logout',
7352: );
7353: $output .= '<td valign="top"><b>'.&mt('Window during which actions occurred:').'</b><br />'.
7354: '<table><tr><td>'.&mt('After:').
7355: '</td><td>'.$startform.'</td></tr>'.
7356: '<tr><td>'.&mt('Before:').'</td>'.
7357: '<td>'.$endform.'</td></tr></table>'.
7358: '</td>'.
7359: '<td> </td>'.
7360: '<td valign="top"><b>'.&mt('Activities').'</b><br />'.
7361: '<select name="activity"><option value="any"';
7362: if ($curr->{'activity'} eq 'any') {
7363: $output .= ' selected="selected"';
7364: }
7365: $output .= '>'.&mt('Any').'</option>'."\n";
7366: foreach my $activity ('Role','log') {
7367: my $selstr = '';
7368: if ($activity eq $curr->{'activity'}) {
7369: $selstr = ' selected="selected"';
7370: }
7371: $output .= '<option value="'.$activity.'"'.$selstr.'>'.$lt{$activity}.'</option>';
7372: }
7373: $output .= '</select></td>'.
7374: '</tr></table>';
7375: # Update Display button
7376: $output .= '<p>'
7377: .'<input type="submit" value="'.&mt('Update Display').'" />'
1.431 raeburn 7378: .'</p><hr />';
1.416 raeburn 7379: return $output;
7380: }
7381:
1.415 raeburn 7382: sub userlogdisplay_js {
7383: my ($formname) = @_;
7384: return <<"ENDSCRIPT";
7385:
1.239 raeburn 7386: function chgPage(caller) {
7387: if (caller == 'previous') {
7388: document.$formname.page.value --;
7389: }
7390: if (caller == 'next') {
7391: document.$formname.page.value ++;
7392: }
1.327 raeburn 7393: document.$formname.submit();
1.239 raeburn 7394: return;
7395: }
7396: ENDSCRIPT
1.415 raeburn 7397: }
7398:
7399: sub userlogdisplay_navlinks {
7400: my ($curr,$more_records) = @_;
7401: return unless(ref($curr) eq 'HASH');
7402: # Navigation Buttons
7403: my $nav_links = '<p>';
7404: if (($curr->{'page'} > 1) || ($more_records)) {
7405: if (($curr->{'page'} > 1) && ($curr->{'show'} !~ /\D/)) {
7406: $nav_links .= '<input type="button"'
7407: .' onclick="javascript:chgPage('."'previous'".');"'
7408: .' value="'.&mt('Previous [_1] changes',$curr->{'show'})
7409: .'" /> ';
7410: }
7411: if ($more_records) {
7412: $nav_links .= '<input type="button"'
7413: .' onclick="javascript:chgPage('."'next'".');"'
7414: .' value="'.&mt('Next [_1] changes',$curr->{'show'})
7415: .'" />';
1.301 bisitz 7416: }
7417: }
1.415 raeburn 7418: $nav_links .= '</p>';
7419: return $nav_links;
1.239 raeburn 7420: }
7421:
7422: sub role_display_filter {
1.363 raeburn 7423: my ($context,$formname,$cdom,$cnum,$curr,$version,$crstype) = @_;
7424: my $lctype;
7425: if ($context eq 'course') {
7426: $lctype = lc($crstype);
7427: }
1.239 raeburn 7428: my $nolink = 1;
7429: my $output = '<table><tr><td valign="top">'.
1.301 bisitz 7430: '<span class="LC_nobreak"><b>'.&mt('Changes/page:').'</b></span><br />'.
1.239 raeburn 7431: &Apache::lonmeta::selectbox('show',$curr->{'show'},undef,
7432: (&mt('all'),5,10,20,50,100,1000,10000)).
7433: '</td><td> </td>';
7434: my $startform =
7435: &Apache::lonhtmlcommon::date_setter($formname,'rolelog_start_date',
7436: $curr->{'rolelog_start_date'},undef,
7437: undef,undef,undef,undef,undef,undef,$nolink);
7438: my $endform =
7439: &Apache::lonhtmlcommon::date_setter($formname,'rolelog_end_date',
7440: $curr->{'rolelog_end_date'},undef,
7441: undef,undef,undef,undef,undef,undef,$nolink);
1.363 raeburn 7442: my %lt = &rolechg_contexts($context,$crstype);
1.301 bisitz 7443: $output .= '<td valign="top"><b>'.&mt('Window during which changes occurred:').'</b><br />'.
7444: '<table><tr><td>'.&mt('After:').
7445: '</td><td>'.$startform.'</td></tr>'.
7446: '<tr><td>'.&mt('Before:').'</td>'.
7447: '<td>'.$endform.'</td></tr></table>'.
7448: '</td>'.
7449: '<td> </td>'.
1.239 raeburn 7450: '<td valign="top"><b>'.&mt('Role:').'</b><br />'.
7451: '<select name="role"><option value="any"';
7452: if ($curr->{'role'} eq 'any') {
7453: $output .= ' selected="selected"';
7454: }
7455: $output .= '>'.&mt('Any').'</option>'."\n";
1.363 raeburn 7456: my @roles = &Apache::lonuserutils::roles_by_context($context,1,$crstype);
1.239 raeburn 7457: foreach my $role (@roles) {
7458: my $plrole;
7459: if ($role eq 'cr') {
7460: $plrole = &mt('Custom Role');
7461: } else {
1.318 raeburn 7462: $plrole=&Apache::lonnet::plaintext($role,$crstype);
1.239 raeburn 7463: }
7464: my $selstr = '';
7465: if ($role eq $curr->{'role'}) {
7466: $selstr = ' selected="selected"';
7467: }
7468: $output .= ' <option value="'.$role.'"'.$selstr.'>'.$plrole.'</option>';
7469: }
1.301 bisitz 7470: $output .= '</select></td>'.
7471: '<td> </td>'.
7472: '<td valign="top"><b>'.
1.239 raeburn 7473: &mt('Context:').'</b><br /><select name="chgcontext">';
1.363 raeburn 7474: my @posscontexts;
7475: if ($context eq 'course') {
1.457 raeburn 7476: @posscontexts = ('any','automated','updatenow','createcourse','course','domain','selfenroll','requestcourses','chgtype');
1.363 raeburn 7477: } elsif ($context eq 'domain') {
7478: @posscontexts = ('any','domain','requestauthor','domconfig','server');
7479: } else {
7480: @posscontexts = ('any','author','domain');
1.457 raeburn 7481: }
1.363 raeburn 7482: foreach my $chgtype (@posscontexts) {
1.239 raeburn 7483: my $selstr = '';
7484: if ($curr->{'chgcontext'} eq $chgtype) {
1.301 bisitz 7485: $selstr = ' selected="selected"';
1.239 raeburn 7486: }
1.363 raeburn 7487: if ($context eq 'course') {
1.376 raeburn 7488: if (($chgtype eq 'automated') || ($chgtype eq 'updatenow')) {
1.363 raeburn 7489: next if (!&Apache::lonnet::auto_run($cnum,$cdom));
7490: }
1.239 raeburn 7491: }
7492: $output .= '<option value="'.$chgtype.'"'.$selstr.'>'.$lt{$chgtype}.'</option>'."\n";
1.248 raeburn 7493: }
1.303 bisitz 7494: $output .= '</select></td>'
7495: .'</tr></table>';
7496:
7497: # Update Display button
7498: $output .= '<p>'
7499: .'<input type="submit" value="'.&mt('Update Display').'" />'
7500: .'</p>';
7501:
7502: # Server version info
1.363 raeburn 7503: my $needsrev = '2.11.0';
7504: if ($context eq 'course') {
7505: $needsrev = '2.7.0';
7506: }
7507:
1.303 bisitz 7508: $output .= '<p class="LC_info">'
7509: .&mt('Only changes made from servers running LON-CAPA [_1] or later are displayed.'
1.363 raeburn 7510: ,$needsrev);
1.248 raeburn 7511: if ($version) {
1.303 bisitz 7512: $output .= ' '.&mt('This LON-CAPA server is version [_1]',$version);
7513: }
7514: $output .= '</p><hr />';
1.239 raeburn 7515: return $output;
7516: }
7517:
7518: sub rolechg_contexts {
1.363 raeburn 7519: my ($context,$crstype) = @_;
7520: my %lt;
7521: if ($context eq 'course') {
7522: %lt = &Apache::lonlocal::texthash (
1.239 raeburn 7523: any => 'Any',
1.376 raeburn 7524: automated => 'Automated Enrollment',
1.457 raeburn 7525: chgtype => 'Enrollment Type/Lock Change',
1.239 raeburn 7526: updatenow => 'Roster Update',
7527: createcourse => 'Course Creation',
7528: course => 'User Management in course',
7529: domain => 'User Management in domain',
1.313 raeburn 7530: selfenroll => 'Self-enrolled',
1.318 raeburn 7531: requestcourses => 'Course Request',
1.239 raeburn 7532: );
1.363 raeburn 7533: if ($crstype eq 'Community') {
7534: $lt{'createcourse'} = &mt('Community Creation');
7535: $lt{'course'} = &mt('User Management in community');
7536: $lt{'requestcourses'} = &mt('Community Request');
7537: }
7538: } elsif ($context eq 'domain') {
7539: %lt = &Apache::lonlocal::texthash (
7540: any => 'Any',
7541: domain => 'User Management in domain',
7542: requestauthor => 'Authoring Request',
7543: server => 'Command line script (DC role)',
7544: domconfig => 'Self-enrolled',
7545: );
7546: } else {
7547: %lt = &Apache::lonlocal::texthash (
7548: any => 'Any',
7549: domain => 'User Management in domain',
7550: author => 'User Management by author',
7551: );
7552: }
1.239 raeburn 7553: return %lt;
7554: }
7555:
1.428 raeburn 7556: sub print_helpdeskaccess_display {
7557: my ($r,$permission,$brcrum) = @_;
7558: my $formname = 'helpdeskaccess';
7559: my $helpitem = 'Course_Helpdesk_Access';
7560: push (@{$brcrum},
7561: {href => '/adm/createuser?action=helpdesk',
7562: text => 'Helpdesk Access',
7563: help => $helpitem});
7564: my $bread_crumbs_component = 'Helpdesk Staff Access';
7565: my $args = { bread_crumbs => $brcrum,
7566: bread_crumbs_component => $bread_crumbs_component};
7567:
7568: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
7569: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
7570: my $confname = $cdom.'-domainconfig';
7571: my $crstype = &Apache::loncommon::course_type();
7572:
1.434 raeburn 7573: my @accesstypes = ('all','dh','da','none');
1.428 raeburn 7574: my ($numstatustypes,@jsarray);
7575: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($cdom);
7576: if (ref($types) eq 'ARRAY') {
1.430 raeburn 7577: if (@{$types} > 0) {
1.428 raeburn 7578: $numstatustypes = scalar(@{$types});
7579: push(@accesstypes,'status');
7580: @jsarray = ('bystatus');
7581: }
7582: }
7583: my %customroles = &get_domain_customroles($cdom,$confname);
1.432 raeburn 7584: my %domhelpdesk = &Apache::lonnet::get_active_domroles($cdom,['dh','da']);
1.428 raeburn 7585: if (keys(%domhelpdesk)) {
7586: push(@accesstypes,('inc','exc'));
7587: push(@jsarray,('notinc','notexc'));
7588: }
7589: push(@jsarray,'privs');
7590: my $hiddenstr = join("','",@jsarray);
7591: my $rolestr = join("','",sort(keys(%customroles)));
7592:
7593: my $jscript;
7594: my (%settings,%overridden);
7595: if (keys(%customroles)) {
7596: &get_adhocrole_settings($env{'request.course.id'},\@accesstypes,
7597: $types,\%customroles,\%settings,\%overridden);
7598: my %jsfull=();
7599: my %jslevels= (
7600: course => {},
7601: domain => {},
7602: system => {},
7603: );
7604: my %jslevelscurrent=(
7605: course => {},
7606: domain => {},
7607: system => {},
7608: );
7609: my (%privs,%jsprivs);
7610: &Apache::lonuserutils::custom_role_privs(\%privs,\%jsfull,\%jslevels,\%jslevelscurrent);
7611: foreach my $priv (keys(%jsfull)) {
7612: if ($jslevels{'course'}{$priv}) {
7613: $jsprivs{$priv} = 1;
7614: }
7615: }
7616: my (%elements,%stored);
7617: foreach my $role (keys(%customroles)) {
7618: $elements{$role.'_access'} = 'radio';
7619: $elements{$role.'_incrs'} = 'radio';
7620: if ($numstatustypes) {
7621: $elements{$role.'_status'} = 'checkbox';
7622: }
7623: if (keys(%domhelpdesk) > 0) {
7624: $elements{$role.'_staff_inc'} = 'checkbox';
7625: $elements{$role.'_staff_exc'} = 'checkbox';
7626: }
1.430 raeburn 7627: $elements{$role.'_override'} = 'checkbox';
1.428 raeburn 7628: if (ref($settings{$role}) eq 'HASH') {
7629: if ($settings{$role}{'access'} ne '') {
7630: my $curraccess = $settings{$role}{'access'};
7631: $stored{$role.'_access'} = $curraccess;
7632: $stored{$role.'_incrs'} = 1;
7633: if ($curraccess eq 'status') {
7634: if (ref($settings{$role}{'status'}) eq 'ARRAY') {
7635: $stored{$role.'_status'} = $settings{$role}{'status'};
7636: }
7637: } elsif (($curraccess eq 'exc') || ($curraccess eq 'inc')) {
7638: if (ref($settings{$role}{$curraccess}) eq 'ARRAY') {
7639: $stored{$role.'_staff_'.$curraccess} = $settings{$role}{$curraccess};
7640: }
7641: }
7642: } else {
7643: $stored{$role.'_incrs'} = 0;
7644: }
7645: $stored{$role.'_override'} = [];
7646: if ($env{'course.'.$env{'request.course.id'}.'.internal.adhocpriv.'.$role}) {
7647: if (ref($settings{$role}{'off'}) eq 'ARRAY') {
7648: foreach my $priv (@{$settings{$role}{'off'}}) {
7649: push(@{$stored{$role.'_override'}},$priv);
7650: }
7651: }
7652: if (ref($settings{$role}{'on'}) eq 'ARRAY') {
7653: foreach my $priv (@{$settings{$role}{'on'}}) {
7654: unless (grep(/^$priv$/,@{$stored{$role.'_override'}})) {
7655: push(@{$stored{$role.'_override'}},$priv);
7656: }
7657: }
7658: }
7659: }
7660: } else {
7661: $stored{$role.'_incrs'} = 0;
7662: }
7663: }
7664: $jscript = &Apache::lonhtmlcommon::set_form_elements(\%elements,\%stored);
7665: }
7666:
7667: my $js = <<"ENDJS";
7668: <script type="text/javascript">
7669: // <![CDATA[
7670: $jscript;
7671:
7672: function switchRoleTab(caller,role) {
7673: if (document.getElementById(role+'_maindiv')) {
7674: if (caller.id != 'LC_current_minitab') {
7675: if (document.getElementById('LC_current_minitab')) {
7676: document.getElementById('LC_current_minitab').id=null;
7677: }
7678: var roledivs = Array('$rolestr');
7679: if (roledivs.length > 0) {
7680: for (var i=0; i<roledivs.length; i++) {
7681: if (document.getElementById(roledivs[i]+'_maindiv')) {
7682: document.getElementById(roledivs[i]+'_maindiv').style.display='none';
7683: }
7684: }
7685: }
7686: caller.id = 'LC_current_minitab';
7687: document.getElementById(role+'_maindiv').style.display='block';
7688: }
7689: }
7690: return false;
1.430 raeburn 7691: }
1.428 raeburn 7692:
7693: function helpdeskAccess(role) {
7694: var curraccess = null;
7695: if (document.$formname.elements[role+'_access'].length) {
7696: for (var i=0; i<document.$formname.elements[role+'_access'].length; i++) {
7697: if (document.$formname.elements[role+'_access'][i].checked) {
7698: curraccess = document.$formname.elements[role+'_access'][i].value;
7699: }
7700: }
7701: }
7702: var shown = Array();
7703: var hidden = Array();
7704: if (curraccess == 'none') {
1.430 raeburn 7705: hidden = Array ('$hiddenstr');
1.428 raeburn 7706: } else {
7707: if (curraccess == 'status') {
1.430 raeburn 7708: shown = Array ('bystatus','privs');
7709: hidden = Array ('notinc','notexc');
1.428 raeburn 7710: } else {
7711: if (curraccess == 'exc') {
7712: shown = Array ('notexc','privs');
7713: hidden = Array ('notinc','bystatus');
7714: }
7715: if (curraccess == 'inc') {
7716: shown = Array ('notinc','privs');
7717: hidden = Array ('notexc','bystatus');
7718: }
7719: if (curraccess == 'all') {
7720: shown = Array ('privs');
7721: hidden = Array ('notinc','notexc','bystatus');
7722: }
7723: }
7724: }
7725: if (hidden.length > 0) {
7726: for (var i=0; i<hidden.length; i++) {
7727: if (document.getElementById(role+'_'+hidden[i])) {
1.430 raeburn 7728: document.getElementById(role+'_'+hidden[i]).style.display = 'none';
1.428 raeburn 7729: }
7730: }
7731: }
7732: if (shown.length > 0) {
7733: for (var i=0; i<shown.length; i++) {
7734: if (document.getElementById(role+'_'+shown[i])) {
7735: if (shown[i] == 'privs') {
7736: document.getElementById(role+'_'+shown[i]).style.display = 'block';
7737: } else {
7738: document.getElementById(role+'_'+shown[i]).style.display = 'inline';
7739: }
7740: }
7741: }
7742: }
7743: return;
7744: }
7745:
7746: function toggleAccess(role) {
7747: if ((document.getElementById(role+'_setincrs')) &&
7748: (document.getElementById(role+'_setindom'))) {
7749: for (var i=0; i<document.$formname.elements[role+'_incrs'].length; i++) {
7750: if (document.$formname.elements[role+'_incrs'][i].checked) {
7751: if (document.$formname.elements[role+'_incrs'][i].value == 1) {
7752: document.getElementById(role+'_setindom').style.display = 'none';
1.430 raeburn 7753: document.getElementById(role+'_setincrs').style.display = 'block';
1.428 raeburn 7754: } else {
7755: document.getElementById(role+'_setincrs').style.display = 'none';
7756: document.getElementById(role+'_setindom').style.display = 'block';
7757: }
7758: break;
7759: }
7760: }
7761: }
7762: return;
7763: }
7764:
7765: // ]]>
7766: </script>
7767: ENDJS
7768:
7769: $args->{add_entries} = {onload => "javascript:setFormElements(document.$formname)"};
7770:
7771: # print page header
7772: $r->print(&header($js,$args));
7773: # print form header
7774: $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">');
7775:
7776: if (keys(%customroles)) {
7777: my %lt = &Apache::lonlocal::texthash(
7778: 'aco' => 'As course owner you may override the defaults set in the domain for role usage and/or privileges.',
7779: 'rou' => 'Role usage',
7780: 'whi' => 'Which helpdesk personnel may use this role?',
7781: 'udd' => 'Use domain default',
1.433 raeburn 7782: 'all' => 'All with domain helpdesk or helpdesk assistant role',
1.434 raeburn 7783: 'dh' => 'All with domain helpdesk role',
7784: 'da' => 'All with domain helpdesk assistant role',
1.428 raeburn 7785: 'none' => 'None',
7786: 'status' => 'Determined based on institutional status',
1.430 raeburn 7787: 'inc' => 'Include all, but exclude specific personnel',
1.428 raeburn 7788: 'exc' => 'Exclude all, but include specific personnel',
7789: 'hel' => 'Helpdesk',
7790: 'rpr' => 'Role privileges',
7791: );
7792: $lt{'tfh'} = &mt("Custom [_1]ad hoc[_2] course roles available for use by the domain's helpdesk are as follows",'<i>','</i>');
7793: my %domconfig = &Apache::lonnet::get_dom('configuration',['helpsettings'],$cdom);
7794: my (%domcurrent,%ordered,%description,%domusage,$disabled);
7795: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
7796: if (ref($domconfig{'helpsettings'}{'adhoc'}) eq 'HASH') {
7797: %domcurrent = %{$domconfig{'helpsettings'}{'adhoc'}};
7798: }
7799: }
7800: my $count = 0;
7801: foreach my $role (sort(keys(%customroles))) {
7802: my ($order,$desc,$access_in_dom);
7803: if (ref($domcurrent{$role}) eq 'HASH') {
7804: $order = $domcurrent{$role}{'order'};
7805: $desc = $domcurrent{$role}{'desc'};
7806: $access_in_dom = $domcurrent{$role}{'access'};
7807: }
7808: if ($order eq '') {
7809: $order = $count;
7810: }
7811: $ordered{$order} = $role;
7812: if ($desc ne '') {
7813: $description{$role} = $desc;
7814: } else {
7815: $description{$role}= $role;
7816: }
7817: $count++;
7818: }
7819: %domusage = &domain_adhoc_access(\%customroles,\%domcurrent,\@accesstypes,$usertypes,$othertitle);
7820: my @roles_by_num = ();
7821: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
7822: push(@roles_by_num,$ordered{$item});
1.430 raeburn 7823: }
1.429 raeburn 7824: $r->print('<p>'.$lt{'tfh'}.': <i>'.join('</i>, <i>',map { $description{$_}; } @roles_by_num).'</i>.');
1.428 raeburn 7825: if ($permission->{'owner'}) {
7826: $r->print('<br />'.$lt{'aco'}.'</p><p>');
7827: $r->print('<input type="hidden" name="state" value="process" />'.
7828: '<input type="submit" value="'.&mt('Save changes').'" />');
7829: } else {
7830: if ($env{'course.'.$env{'request.course.id'}.'.internal.courseowner'}) {
7831: my ($ownername,$ownerdom) = split(/:/,$env{'course.'.$env{'request.course.id'}.'.internal.courseowner'});
7832: $r->print('<br />'.&mt('The course owner -- [_1] -- can override the default access and/or privileges for these ad hoc roles.',
7833: &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($ownername,$ownerdom),$ownername,$ownerdom)));
7834: }
7835: $disabled = ' disabled="disabled"';
7836: }
7837: $r->print('</p>');
7838:
7839: $r->print('<div id="LC_minitab_header"><ul>');
7840: my $count = 0;
7841: my %visibility;
7842: foreach my $role (@roles_by_num) {
7843: my $id;
7844: if ($count == 0) {
7845: $id=' id="LC_current_minitab"';
1.430 raeburn 7846: $visibility{$role} = ' style="display:block"';
1.428 raeburn 7847: } else {
7848: $visibility{$role} = ' style="display:none"';
7849: }
7850: $count ++;
7851: $r->print('<li'.$id.'><a href="#" onclick="javascript:switchRoleTab(this.parentNode,'."'$role'".');">'.$description{$role}.'</a></li>');
7852: }
7853: $r->print('</ul></div>');
7854:
7855: foreach my $role (@roles_by_num) {
7856: my %usecheck = (
7857: all => ' checked="checked"',
7858: );
7859: my %displaydiv = (
7860: status => 'none',
7861: inc => 'none',
7862: exc => 'none',
7863: priv => 'block',
7864: );
7865: my (%selected,$overridden,$incrscheck,$indomcheck,$indomvis,$incrsvis);
1.430 raeburn 7866: if (ref($settings{$role}) eq 'HASH') {
1.428 raeburn 7867: if ($settings{$role}{'access'} ne '') {
7868: $indomvis = ' style="display:none"';
7869: $incrsvis = ' style="display:block"';
1.430 raeburn 7870: $incrscheck = ' checked="checked"';
1.428 raeburn 7871: if ($settings{$role}{'access'} ne 'all') {
7872: $usecheck{$settings{$role}{'access'}} = $usecheck{'all'};
7873: delete($usecheck{'all'});
7874: if ($settings{$role}{'access'} eq 'status') {
7875: my $access = 'status';
7876: $displaydiv{$access} = 'inline';
7877: if (ref($settings{$role}{$access}) eq 'ARRAY') {
7878: $selected{$access} = $settings{$role}{$access};
7879: }
7880: } elsif ($settings{$role}{'access'} =~ /^(inc|exc)$/) {
7881: my $access = $1;
7882: $displaydiv{$access} = 'inline';
7883: if (ref($settings{$role}{$access}) eq 'ARRAY') {
7884: $selected{$access} = $settings{$role}{$access};
7885: }
7886: } elsif ($settings{$role}{'access'} eq 'none') {
7887: $displaydiv{'priv'} = 'none';
7888: }
7889: }
7890: } else {
7891: $indomcheck = ' checked="checked"';
7892: $indomvis = ' style="display:block"';
7893: $incrsvis = ' style="display:none"';
7894: }
7895: } else {
7896: $indomcheck = ' checked="checked"';
1.430 raeburn 7897: $indomvis = ' style="display:block"';
1.428 raeburn 7898: $incrsvis = ' style="display:none"';
7899: }
7900: $r->print('<div class="LC_left_float" id="'.$role.'_maindiv"'.$visibility{$role}.'>'.
7901: '<fieldset><legend>'.$lt{'rou'}.'</legend>'.
7902: '<p>'.$lt{'whi'}.' <span class="LC_nobreak">'.
7903: '<label><input type="radio" name="'.$role.'_incrs" value="1"'.$incrscheck.' onclick="toggleAccess('."'$role'".');"'.$disabled.'>'.
7904: &mt('Set here in [_1]',lc($crstype)).'</label>'.
7905: '<span>'.(' 'x2).
7906: '<label><input type="radio" name="'.$role.'_incrs" value="0"'.$indomcheck.' onclick="toggleAccess('."'$role'".');"'.$disabled.'>'.
7907: $lt{'udd'}.'</label><span></p>'.
7908: '<div id="'.$role.'_setindom"'.$indomvis.'>'.
7909: '<span class="LC_cusr_emph">'.$domusage{$role}.'</span></div>'.
7910: '<div id="'.$role.'_setincrs"'.$incrsvis.'>');
7911: foreach my $access (@accesstypes) {
7912: $r->print('<p><label><input type="radio" name="'.$role.'_access" value="'.$access.'" '.$usecheck{$access}.
7913: ' onclick="helpdeskAccess('."'$role'".');"'.$disabled.' />'.$lt{$access}.'</label>');
7914: if ($access eq 'status') {
7915: $r->print('<div id="'.$role.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
7916: &Apache::lonuserutils::adhoc_status_types($cdom,undef,$role,$selected{$access},
7917: $othertitle,$usertypes,$types,$disabled).
7918: '</div>');
7919: } elsif (($access eq 'inc') && (keys(%domhelpdesk) > 0)) {
7920: $r->print('<div id="'.$role.'_notinc" style="display:'.$displaydiv{$access}.'">'.
7921: &Apache::lonuserutils::adhoc_staff($access,undef,$role,$selected{$access},
7922: \%domhelpdesk,$disabled).
7923: '</div>');
7924: } elsif (($access eq 'exc') && (keys(%domhelpdesk) > 0)) {
7925: $r->print('<div id="'.$role.'_notexc" style="display:'.$displaydiv{$access}.'">'.
7926: &Apache::lonuserutils::adhoc_staff($access,undef,$role,$selected{$access},
7927: \%domhelpdesk,$disabled).
7928: '</div>');
7929: }
7930: $r->print('</p>');
7931: }
7932: $r->print('</div></fieldset>');
7933: my %full=();
7934: my %levels= (
7935: course => {},
7936: domain => {},
7937: system => {},
7938: );
7939: my %levelscurrent=(
7940: course => {},
7941: domain => {},
7942: system => {},
7943: );
7944: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
7945: $r->print('<fieldset id="'.$role.'_privs" style="display:'.$displaydiv{'priv'}.'">'.
7946: '<legend>'.$lt{'rpr'}.'</legend>'.
7947: &role_priv_table($role,$permission,$crstype,\%full,\%levels,\%levelscurrent,$overridden{$role}).
7948: '</fieldset></div><div style="padding:0;clear:both;margin:0;border:0"></div>');
7949: }
1.429 raeburn 7950: if ($permission->{'owner'}) {
7951: $r->print('<p><input type="submit" value="'.&mt('Save changes').'" /></p>');
7952: }
1.428 raeburn 7953: } else {
7954: $r->print(&mt('Helpdesk roles have not yet been created in this domain.'));
7955: }
7956: # Form Footer
7957: $r->print('<input type="hidden" name="action" value="helpdesk" />'
7958: .'</form>');
7959: return;
7960: }
7961:
7962: sub domain_adhoc_access {
7963: my ($roles,$domcurrent,$accesstypes,$usertypes,$othertitle) = @_;
7964: my %domusage;
7965: return unless ((ref($roles) eq 'HASH') && (ref($domcurrent) eq 'HASH') && (ref($accesstypes) eq 'ARRAY'));
7966: foreach my $role (keys(%{$roles})) {
7967: if (ref($domcurrent->{$role}) eq 'HASH') {
7968: my $access = $domcurrent->{$role}{'access'};
7969: if (($access eq '') || (!grep(/^\Q$access\E$/,@{$accesstypes}))) {
7970: $access = 'all';
1.432 raeburn 7971: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role',&Apache::lonnet::plaintext('dh'),
7972: &Apache::lonnet::plaintext('da'));
1.428 raeburn 7973: } elsif ($access eq 'status') {
7974: if (ref($domcurrent->{$role}{$access}) eq 'ARRAY') {
7975: my @shown;
7976: foreach my $type (@{$domcurrent->{$role}{$access}}) {
7977: unless ($type eq 'default') {
7978: if ($usertypes->{$type}) {
7979: push(@shown,$usertypes->{$type});
7980: }
7981: }
7982: }
7983: if (grep(/^default$/,@{$domcurrent->{$role}{$access}})) {
7984: push(@shown,$othertitle);
7985: }
7986: if (@shown) {
7987: my $shownstatus = join(' '.&mt('or').' ',@shown);
1.432 raeburn 7988: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role, and institutional status: [_3]',
7989: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'),$shownstatus);
1.428 raeburn 7990: } else {
7991: $domusage{$role} = &mt('No one in the domain');
7992: }
7993: }
7994: } elsif ($access eq 'inc') {
7995: my @dominc = ();
7996: if (ref($domcurrent->{$role}{'inc'}) eq 'ARRAY') {
7997: foreach my $user (@{$domcurrent->{$role}{'inc'}}) {
7998: my ($uname,$udom) = split(/:/,$user);
7999: push(@dominc,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),$uname,$udom));
8000: }
8001: my $showninc = join(', ',@dominc);
8002: if ($showninc ne '') {
1.432 raeburn 8003: $domusage{$role} = &mt('Include any user in domain with active [_1] or [_2] role, except: [_3]',
8004: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'),$showninc);
1.428 raeburn 8005: } else {
1.432 raeburn 8006: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role',
8007: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'));
1.428 raeburn 8008: }
8009: }
8010: } elsif ($access eq 'exc') {
8011: my @domexc = ();
8012: if (ref($domcurrent->{$role}{'exc'}) eq 'ARRAY') {
8013: foreach my $user (@{$domcurrent->{$role}{'exc'}}) {
8014: my ($uname,$udom) = split(/:/,$user);
8015: push(@domexc,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),$uname,$udom));
8016: }
8017: }
8018: my $shownexc = join(', ',@domexc);
8019: if ($shownexc ne '') {
1.432 raeburn 8020: $domusage{$role} = &mt('Only the following in the domain with active [_1] or [_2] role: [_3]',
8021: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'),$shownexc);
1.428 raeburn 8022: } else {
8023: $domusage{$role} = &mt('No one in the domain');
8024: }
8025: } elsif ($access eq 'none') {
8026: $domusage{$role} = &mt('No one in the domain');
1.434 raeburn 8027: } elsif ($access eq 'dh') {
1.433 raeburn 8028: $domusage{$role} = &mt('Any user in domain with active [_1] role',&Apache::lonnet::plaintext('dh'));
1.434 raeburn 8029: } elsif ($access eq 'da') {
1.433 raeburn 8030: $domusage{$role} = &mt('Any user in domain with active [_1] role',&Apache::lonnet::plaintext('da'));
1.428 raeburn 8031: } elsif ($access eq 'all') {
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: } else {
1.432 raeburn 8036: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role',
8037: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'));
1.428 raeburn 8038: }
8039: }
8040: return %domusage;
8041: }
8042:
8043: sub get_domain_customroles {
8044: my ($cdom,$confname) = @_;
8045: my %existing=&Apache::lonnet::dump('roles',$cdom,$confname,'rolesdef_');
8046: my %customroles;
8047: foreach my $key (keys(%existing)) {
8048: if ($key=~/^rolesdef\_(\w+)$/) {
8049: my $rolename = $1;
8050: my %privs;
8051: ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
8052: $customroles{$rolename} = \%privs;
8053: }
8054: }
8055: return %customroles;
8056: }
8057:
8058: sub role_priv_table {
8059: my ($role,$permission,$crstype,$full,$levels,$levelscurrent,$overridden) = @_;
8060: return unless ((ref($full) eq 'HASH') && (ref($levels) eq 'HASH') &&
8061: (ref($levelscurrent) eq 'HASH'));
8062: my %lt=&Apache::lonlocal::texthash (
8063: 'crl' => 'Course Level Privilege',
8064: 'def' => 'Domain Defaults',
8065: 'ove' => 'Override in Course',
8066: 'ine' => 'In effect',
8067: 'dis' => 'Disabled',
8068: 'ena' => 'Enabled',
8069: );
8070: if ($crstype eq 'Community') {
8071: $lt{'ove'} = 'Override in Community',
8072: }
8073: my @status = ('Disabled','Enabled');
8074: my (%on,%off);
8075: if (ref($overridden) eq 'HASH') {
8076: if (ref($overridden->{'on'}) eq 'ARRAY') {
8077: map { $on{$_} = 1; } (@{$overridden->{'on'}});
8078: }
8079: if (ref($overridden->{'off'}) eq 'ARRAY') {
8080: map { $off{$_} = 1; } (@{$overridden->{'off'}});
8081: }
8082: }
8083: my $output=&Apache::loncommon::start_data_table().
8084: &Apache::loncommon::start_data_table_header_row().
8085: '<th>'.$lt{'crl'}.'</th><th>'.$lt{'def'}.'</th><th>'.$lt{'ove'}.
8086: '</th><th>'.$lt{'ine'}.'</th>'.
8087: &Apache::loncommon::end_data_table_header_row();
8088: foreach my $priv (sort(keys(%{$full}))) {
8089: next unless ($levels->{'course'}{$priv});
8090: my $privtext = &Apache::lonnet::plaintext($priv,$crstype);
8091: my ($default,$ineffect);
8092: if ($levelscurrent->{'course'}{$priv}) {
8093: $default = '<img src="/adm/lonIcons/navmap.correct.gif" alt="'.$lt{'ena'}.'" />';
8094: $ineffect = $default;
8095: }
8096: my ($customstatus,$checked);
8097: $output .= &Apache::loncommon::start_data_table_row().
8098: '<td>'.$privtext.'</td>'.
8099: '<td>'.$default.'</td><td>';
8100: if (($levelscurrent->{'course'}{$priv}) && ($off{$priv})) {
8101: if ($permission->{'owner'}) {
8102: $checked = ' checked="checked"';
8103: }
8104: $customstatus = '<img src="/adm/lonIcons/navmap.wrong.gif" alt="'.$lt{'dis'}.'" />';
1.430 raeburn 8105: $ineffect = $customstatus;
1.428 raeburn 8106: } elsif ((!$levelscurrent->{'course'}{$priv}) && ($on{$priv})) {
8107: if ($permission->{'owner'}) {
1.430 raeburn 8108: $checked = ' checked="checked"';
1.428 raeburn 8109: }
8110: $customstatus = '<img src="/adm/lonIcons/navmap.correct.gif" alt="'.$lt{'ena'}.'" />';
1.430 raeburn 8111: $ineffect = $customstatus;
1.428 raeburn 8112: }
8113: if ($permission->{'owner'}) {
8114: $output .= '<input type="checkbox" name="'.$role.'_override" value="'.$priv.'"'.$checked.' />';
8115: } else {
8116: $output .= $customstatus;
8117: }
8118: $output .= '</td><td>'.$ineffect.'</td>'.
8119: &Apache::loncommon::end_data_table_row();
8120: }
8121: $output .= &Apache::loncommon::end_data_table();
8122: return $output;
8123: }
8124:
8125: sub get_adhocrole_settings {
1.430 raeburn 8126: my ($cid,$accesstypes,$types,$customroles,$settings,$overridden) = @_;
1.428 raeburn 8127: return unless ((ref($accesstypes) eq 'ARRAY') && (ref($customroles) eq 'HASH') &&
8128: (ref($settings) eq 'HASH') && (ref($overridden) eq 'HASH'));
8129: foreach my $role (split(/,/,$env{'course.'.$cid.'.internal.adhocaccess'})) {
8130: my ($curraccess,$rest) = split(/=/,$env{'course.'.$cid.'.internal.adhoc.'.$role});
8131: if (($curraccess ne '') && (grep(/^\Q$curraccess\E$/,@{$accesstypes}))) {
8132: $settings->{$role}{'access'} = $curraccess;
8133: if (($curraccess eq 'status') && (ref($types) eq 'ARRAY')) {
8134: my @status = split(/,/,$rest);
8135: my @currstatus;
8136: foreach my $type (@status) {
8137: if ($type eq 'default') {
8138: push(@currstatus,$type);
8139: } elsif (grep(/^\Q$type\E$/,@{$types})) {
8140: push(@currstatus,$type);
8141: }
8142: }
8143: if (@currstatus) {
8144: $settings->{$role}{$curraccess} = \@currstatus;
8145: } elsif (($curraccess eq 'exc') || ($curraccess eq 'inc')) {
8146: my @personnel = split(/,/,$rest);
8147: $settings->{$role}{$curraccess} = \@personnel;
8148: }
8149: }
8150: }
8151: }
8152: foreach my $role (keys(%{$customroles})) {
8153: if ($env{'course.'.$cid.'.internal.adhocpriv.'.$role}) {
8154: my %currentprivs;
8155: if (ref($customroles->{$role}) eq 'HASH') {
8156: if (exists($customroles->{$role}{'course'})) {
8157: my %full=();
8158: my %levels= (
8159: course => {},
8160: domain => {},
8161: system => {},
8162: );
8163: my %levelscurrent=(
8164: course => {},
8165: domain => {},
8166: system => {},
8167: );
8168: &Apache::lonuserutils::custom_role_privs($customroles->{$role},\%full,\%levels,\%levelscurrent);
8169: %currentprivs = %{$levelscurrent{'course'}};
8170: }
8171: }
8172: foreach my $item (split(/,/,$env{'course.'.$cid.'.internal.adhocpriv.'.$role})) {
8173: next if ($item eq '');
8174: my ($rule,$rest) = split(/=/,$item);
8175: next unless (($rule eq 'off') || ($rule eq 'on'));
8176: foreach my $priv (split(/:/,$rest)) {
8177: if ($priv ne '') {
8178: if ($rule eq 'off') {
8179: push(@{$overridden->{$role}{'off'}},$priv);
8180: if ($currentprivs{$priv}) {
8181: push(@{$settings->{$role}{'off'}},$priv);
8182: }
8183: } else {
8184: push(@{$overridden->{$role}{'on'}},$priv);
8185: unless ($currentprivs{$priv}) {
8186: push(@{$settings->{$role}{'on'}},$priv);
8187: }
8188: }
8189: }
8190: }
8191: }
8192: }
8193: }
8194: return;
8195: }
8196:
8197: sub update_helpdeskaccess {
8198: my ($r,$permission,$brcrum) = @_;
8199: my $helpitem = 'Course_Helpdesk_Access';
8200: push (@{$brcrum},
8201: {href => '/adm/createuser?action=helpdesk',
8202: text => 'Helpdesk Access',
8203: help => $helpitem},
8204: {href => '/adm/createuser?action=helpdesk',
8205: text => 'Result',
8206: help => $helpitem}
8207: );
8208: my $bread_crumbs_component = 'Helpdesk Staff Access';
8209: my $args = { bread_crumbs => $brcrum,
8210: bread_crumbs_component => $bread_crumbs_component};
8211:
8212: # print page header
8213: $r->print(&header('',$args));
8214: unless ((ref($permission) eq 'HASH') && ($permission->{'owner'})) {
8215: $r->print('<p class="LC_error">'.&mt('You do not have permission to change helpdesk access.').'</p>');
8216: return;
8217: }
1.434 raeburn 8218: my @accesstypes = ('all','dh','da','none','status','inc','exc');
1.428 raeburn 8219: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
8220: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
8221: my $confname = $cdom.'-domainconfig';
8222: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($cdom);
8223: my $crstype = &Apache::loncommon::course_type();
8224: my %customroles = &get_domain_customroles($cdom,$confname);
8225: my (%settings,%overridden);
8226: &get_adhocrole_settings($env{'request.course.id'},\@accesstypes,
8227: $types,\%customroles,\%settings,\%overridden);
1.432 raeburn 8228: my %domhelpdesk = &Apache::lonnet::get_active_domroles($cdom,['dh','da']);
1.428 raeburn 8229: my (%changed,%storehash,@todelete);
8230:
8231: if (keys(%customroles)) {
8232: my (%newsettings,@incrs);
8233: foreach my $role (keys(%customroles)) {
8234: $newsettings{$role} = {
8235: access => '',
8236: status => '',
8237: exc => '',
8238: inc => '',
8239: on => '',
8240: off => '',
8241: };
8242: my %current;
8243: if (ref($settings{$role}) eq 'HASH') {
8244: %current = %{$settings{$role}};
8245: }
8246: if (ref($overridden{$role}) eq 'HASH') {
8247: $current{'overridden'} = $overridden{$role};
8248: }
8249: if ($env{'form.'.$role.'_incrs'}) {
8250: my $access = $env{'form.'.$role.'_access'};
8251: if (grep(/^\Q$access\E$/,@accesstypes)) {
8252: push(@incrs,$role);
8253: unless ($current{'access'} eq $access) {
8254: $changed{$role}{'access'} = 1;
1.430 raeburn 8255: $storehash{'internal.adhoc.'.$role} = $access;
1.428 raeburn 8256: }
8257: if ($access eq 'status') {
8258: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$role.'_status');
8259: my @stored;
8260: my @shownstatus;
8261: if (ref($types) eq 'ARRAY') {
8262: foreach my $type (sort(@statuses)) {
8263: if ($type eq 'default') {
8264: push(@stored,$type);
8265: } elsif (grep(/^\Q$type\E$/,@{$types})) {
8266: push(@stored,$type);
8267: push(@shownstatus,$usertypes->{$type});
8268: }
8269: }
8270: if (grep(/^default$/,@statuses)) {
8271: push(@shownstatus,$othertitle);
8272: }
8273: $storehash{'internal.adhoc.'.$role} .= '='.join(',',@stored);
8274: }
8275: $newsettings{$role}{'status'} = join(' '.&mt('or').' ',@shownstatus);
8276: if (ref($current{'status'}) eq 'ARRAY') {
8277: my @diffs = &Apache::loncommon::compare_arrays(\@stored,$current{'status'});
8278: if (@diffs) {
8279: $changed{$role}{'status'} = 1;
8280: }
8281: } elsif (@stored) {
8282: $changed{$role}{'status'} = 1;
8283: }
8284: } elsif (($access eq 'inc') || ($access eq 'exc')) {
8285: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$role.'_staff_'.$access);
8286: my @newspecstaff;
8287: my @stored;
8288: my @currstaff;
8289: foreach my $person (sort(@personnel)) {
8290: if ($domhelpdesk{$person}) {
1.430 raeburn 8291: push(@stored,$person);
1.428 raeburn 8292: }
8293: }
8294: if (ref($current{$access}) eq 'ARRAY') {
8295: my @diffs = &Apache::loncommon::compare_arrays(\@stored,$current{$access});
8296: if (@diffs) {
8297: $changed{$role}{$access} = 1;
8298: }
8299: } elsif (@stored) {
8300: $changed{$role}{$access} = 1;
8301: }
8302: $storehash{'internal.adhoc.'.$role} .= '='.join(',',@stored);
8303: foreach my $person (@stored) {
8304: my ($uname,$udom) = split(/:/,$person);
8305: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
8306: }
8307: $newsettings{$role}{$access} = join(', ',sort(@newspecstaff));
8308: }
8309: $newsettings{$role}{'access'} = $access;
8310: }
8311: } else {
8312: if (($current{'access'} ne '') && (grep(/^\Q$current{'access'}\E$/,@accesstypes))) {
8313: $changed{$role}{'access'} = 1;
8314: $newsettings{$role} = {};
8315: push(@todelete,'internal.adhoc.'.$role);
8316: }
8317: }
8318: if (($env{'form.'.$role.'_incrs'}) && ($env{'form.'.$role.'_access'} eq 'none')) {
8319: if (ref($current{'overridden'}) eq 'HASH') {
8320: push(@todelete,'internal.adhocpriv.'.$role);
8321: }
8322: } else {
8323: my %full=();
8324: my %levels= (
8325: course => {},
8326: domain => {},
8327: system => {},
8328: );
8329: my %levelscurrent=(
8330: course => {},
8331: domain => {},
8332: system => {},
8333: );
8334: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
8335: my (@updatedon,@updatedoff,@override);
8336: @override = &Apache::loncommon::get_env_multiple('form.'.$role.'_override');
1.430 raeburn 8337: if (@override) {
1.428 raeburn 8338: foreach my $priv (sort(keys(%full))) {
8339: next unless ($levels{'course'}{$priv});
8340: if (grep(/^\Q$priv\E$/,@override)) {
8341: if ($levelscurrent{'course'}{$priv}) {
8342: push(@updatedoff,$priv);
8343: } else {
8344: push(@updatedon,$priv);
8345: }
8346: }
8347: }
8348: }
8349: if (@updatedon) {
1.430 raeburn 8350: $newsettings{$role}{'on'} = join('</li><li>', map { &Apache::lonnet::plaintext($_,$crstype) } (@updatedon));
1.428 raeburn 8351: }
8352: if (@updatedoff) {
8353: $newsettings{$role}{'off'} = join('</li><li>', map { &Apache::lonnet::plaintext($_,$crstype) } (@updatedoff));
8354: }
8355: if (ref($current{'overridden'}) eq 'HASH') {
8356: if (ref($current{'overridden'}{'on'}) eq 'ARRAY') {
8357: if (@updatedon) {
8358: my @diffs = &Apache::loncommon::compare_arrays(\@updatedon,$current{'overridden'}{'on'});
8359: if (@diffs) {
8360: $changed{$role}{'on'} = 1;
8361: }
8362: } else {
8363: $changed{$role}{'on'} = 1;
8364: }
8365: } elsif (@updatedon) {
8366: $changed{$role}{'on'} = 1;
8367: }
8368: if (ref($current{'overridden'}{'off'}) eq 'ARRAY') {
8369: if (@updatedoff) {
8370: my @diffs = &Apache::loncommon::compare_arrays(\@updatedoff,$current{'overridden'}{'off'});
8371: if (@diffs) {
8372: $changed{$role}{'off'} = 1;
8373: }
8374: } else {
8375: $changed{$role}{'off'} = 1;
8376: }
8377: } elsif (@updatedoff) {
8378: $changed{$role}{'off'} = 1;
8379: }
8380: } else {
8381: if (@updatedon) {
8382: $changed{$role}{'on'} = 1;
8383: }
8384: if (@updatedoff) {
8385: $changed{$role}{'off'} = 1;
8386: }
8387: }
8388: if (ref($changed{$role}) eq 'HASH') {
8389: if (($changed{$role}{'on'} || $changed{$role}{'off'})) {
8390: my $newpriv;
8391: if (@updatedon) {
8392: $newpriv = 'on='.join(':',@updatedon);
8393: }
8394: if (@updatedoff) {
8395: $newpriv .= ($newpriv ? ',' : '' ).'off='.join(':',@updatedoff);
8396: }
8397: if ($newpriv eq '') {
8398: push(@todelete,'internal.adhocpriv.'.$role);
8399: } else {
8400: $storehash{'internal.adhocpriv.'.$role} = $newpriv;
8401: }
8402: }
8403: }
8404: }
8405: }
8406: if (@incrs) {
8407: $storehash{'internal.adhocaccess'} = join(',',@incrs);
8408: } elsif (@todelete) {
8409: push(@todelete,'internal.adhocaccess');
8410: }
8411: if (keys(%changed)) {
8412: my ($putres,$delres);
8413: if (keys(%storehash)) {
8414: $putres = &Apache::lonnet::put('environment',\%storehash,$cdom,$cnum);
8415: my %newenvhash;
8416: foreach my $key (keys(%storehash)) {
8417: $newenvhash{'course.'.$env{'request.course.id'}.'.'.$key} = $storehash{$key};
8418: }
8419: &Apache::lonnet::appenv(\%newenvhash);
8420: }
8421: if (@todelete) {
8422: $delres = &Apache::lonnet::del('environment',\@todelete,$cdom,$cnum);
8423: foreach my $key (@todelete) {
8424: &Apache::lonnet::delenv('course.'.$env{'request.course.id'}.'.'.$key);
8425: }
8426: }
8427: if (($putres eq 'ok') || ($delres eq 'ok')) {
8428: my %domconfig = &Apache::lonnet::get_dom('configuration',['helpsettings'],$cdom);
8429: my (%domcurrent,%ordered,%description,%domusage);
8430: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
8431: if (ref($domconfig{'helpsettings'}{'adhoc'}) eq 'HASH') {
8432: %domcurrent = %{$domconfig{'helpsettings'}{'adhoc'}};
8433: }
8434: }
8435: my $count = 0;
8436: foreach my $role (sort(keys(%customroles))) {
8437: my ($order,$desc);
8438: if (ref($domcurrent{$role}) eq 'HASH') {
8439: $order = $domcurrent{$role}{'order'};
8440: $desc = $domcurrent{$role}{'desc'};
8441: }
8442: if ($order eq '') {
8443: $order = $count;
8444: }
8445: $ordered{$order} = $role;
8446: if ($desc ne '') {
8447: $description{$role} = $desc;
8448: } else {
8449: $description{$role}= $role;
8450: }
8451: $count++;
8452: }
8453: my @roles_by_num = ();
8454: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
8455: push(@roles_by_num,$ordered{$item});
8456: }
8457: %domusage = &domain_adhoc_access(\%changed,\%domcurrent,\@accesstypes,$usertypes,$othertitle);
1.430 raeburn 8458: $r->print(&mt('Helpdesk access settings have been changed as follows').'<br />');
1.428 raeburn 8459: $r->print('<ul>');
8460: foreach my $role (@roles_by_num) {
8461: next unless (ref($changed{$role}) eq 'HASH');
8462: $r->print('<li>'.&mt('Ad hoc role').': <b>'.$description{$role}.'</b>'.
8463: '<ul>');
1.430 raeburn 8464: if ($changed{$role}{'access'} || $changed{$role}{'status'} || $changed{$role}{'inc'} || $changed{$role}{'exc'}) {
1.428 raeburn 8465: $r->print('<li>');
8466: if ($env{'form.'.$role.'_incrs'}) {
8467: if ($newsettings{$role}{'access'} eq 'all') {
8468: $r->print(&mt('All helpdesk staff can access '.lc($crstype).' with this role.'));
1.434 raeburn 8469: } elsif ($newsettings{$role}{'access'} eq 'dh') {
1.433 raeburn 8470: $r->print(&mt('Helpdesk staff can use this role if they have an active [_1] role',
8471: &Apache::lonnet::plaintext('dh')));
1.434 raeburn 8472: } elsif ($newsettings{$role}{'access'} eq 'da') {
1.433 raeburn 8473: $r->print(&mt('Helpdesk staff can use this role if they have an active [_1] role',
8474: &Apache::lonnet::plaintext('da')));
1.428 raeburn 8475: } elsif ($newsettings{$role}{'access'} eq 'none') {
8476: $r->print(&mt('No helpdesk staff can access '.lc($crstype).' with this role.'));
8477: } elsif ($newsettings{$role}{'access'} eq 'status') {
8478: if ($newsettings{$role}{'status'}) {
8479: my ($access,$rest) = split(/=/,$storehash{'internal.adhoc.'.$role});
1.430 raeburn 8480: if (split(/,/,$rest) > 1) {
1.428 raeburn 8481: $r->print(&mt('Helpdesk staff can use this role if their institutional type is one of: [_1].',
8482: $newsettings{$role}{'status'}));
8483: } else {
8484: $r->print(&mt('Helpdesk staff can use this role if their institutional type is: [_1].',
8485: $newsettings{$role}{'status'}));
8486: }
8487: } else {
8488: $r->print(&mt('No helpdesk staff can access '.lc($crstype).' with this role.'));
8489: }
8490: } elsif ($newsettings{$role}{'access'} eq 'exc') {
8491: if ($newsettings{$role}{'exc'}) {
8492: $r->print(&mt('Helpdesk staff who can use this role are as follows:').' '.$newsettings{$role}{'exc'}.'.');
8493: } else {
8494: $r->print(&mt('No helpdesk staff can access '.lc($crstype).' with this role.'));
8495: }
8496: } elsif ($newsettings{$role}{'access'} eq 'inc') {
8497: if ($newsettings{$role}{'inc'}) {
8498: $r->print(&mt('All helpdesk staff may use this role except the following:').' '.$newsettings{$role}{'inc'}.'.');
8499: } else {
8500: $r->print(&mt('All helpdesk staff may use this role.'));
8501: }
8502: }
8503: } else {
8504: $r->print(&mt('Default access set in the domain now applies.').'<br />'.
8505: '<span class="LC_cusr_emph">'.$domusage{$role}.'</span>');
8506: }
8507: $r->print('</li>');
8508: }
8509: unless ($newsettings{$role}{'access'} eq 'none') {
8510: if ($changed{$role}{'off'}) {
8511: if ($newsettings{$role}{'off'}) {
8512: $r->print('<li>'.&mt('Privileges which are available by default for this ad hoc role, but are disabled for this specific '.lc($crstype).':').
8513: '<ul><li>'.$newsettings{$role}{'off'}.'</li></ul></li>');
8514: } else {
1.430 raeburn 8515: $r->print('<li>'.&mt('All privileges available by default for this ad hoc role are enabled.').'</li>');
1.428 raeburn 8516: }
8517: }
1.430 raeburn 8518: if ($changed{$role}{'on'}) {
1.428 raeburn 8519: if ($newsettings{$role}{'on'}) {
8520: $r->print('<li>'.&mt('Privileges which are not available by default for this ad hoc role, but are enabled for this specific '.lc($crstype).':').
8521: '<ul><li>'.$newsettings{$role}{'on'}.'</li></ul></li>');
8522: } else {
1.430 raeburn 8523: $r->print('<li>'.&mt('None of the privileges unavailable by default for this ad hoc role are enabled.').'</li>');
1.428 raeburn 8524: }
8525: }
8526: }
8527: $r->print('</ul></li>');
8528: }
8529: $r->print('</ul>');
8530: }
8531: } else {
1.430 raeburn 8532: $r->print(&mt('No changes made to helpdesk access settings.'));
1.428 raeburn 8533: }
8534: }
8535: return;
8536: }
8537:
1.27 matthew 8538: #-------------------------------------------------- functions for &phase_two
1.160 raeburn 8539: sub user_search_result {
1.221 raeburn 8540: my ($context,$srch) = @_;
1.160 raeburn 8541: my %allhomes;
8542: my %inst_matches;
8543: my %srch_results;
1.181 raeburn 8544: my ($response,$currstate,$forcenewuser,$dirsrchres);
1.183 raeburn 8545: $srch->{'srchterm'} =~ s/\s+/ /g;
1.176 raeburn 8546: if ($srch->{'srchby'} !~ /^(uname|lastname|lastfirst)$/) {
1.160 raeburn 8547: $response = &mt('Invalid search.');
8548: }
8549: if ($srch->{'srchin'} !~ /^(crs|dom|alc|instd)$/) {
8550: $response = &mt('Invalid search.');
8551: }
1.177 raeburn 8552: if ($srch->{'srchtype'} !~ /^(exact|contains|begins)$/) {
1.160 raeburn 8553: $response = &mt('Invalid search.');
8554: }
8555: if ($srch->{'srchterm'} eq '') {
8556: $response = &mt('You must enter a search term.');
8557: }
1.183 raeburn 8558: if ($srch->{'srchterm'} =~ /^\s+$/) {
8559: $response = &mt('Your search term must contain more than just spaces.');
8560: }
1.160 raeburn 8561: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'instd')) {
8562: if (($srch->{'srchdomain'} eq '') ||
1.163 albertel 8563: ! (&Apache::lonnet::domain($srch->{'srchdomain'}))) {
1.160 raeburn 8564: $response = &mt('You must specify a valid domain when searching in a domain or institutional directory.')
8565: }
8566: }
8567: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs') ||
8568: ($srch->{'srchin'} eq 'alc')) {
1.176 raeburn 8569: if ($srch->{'srchby'} eq 'uname') {
1.243 raeburn 8570: my $unamecheck = $srch->{'srchterm'};
8571: if ($srch->{'srchtype'} eq 'contains') {
8572: if ($unamecheck !~ /^\w/) {
8573: $unamecheck = 'a'.$unamecheck;
8574: }
8575: }
8576: if ($unamecheck !~ /^$match_username$/) {
1.176 raeburn 8577: $response = &mt('You must specify a valid username. Only the following are allowed: letters numbers - . @');
8578: }
1.160 raeburn 8579: }
8580: }
1.180 raeburn 8581: if ($response ne '') {
1.413 raeburn 8582: $response = '<span class="LC_warning">'.$response.'</span><br />';
1.180 raeburn 8583: }
1.160 raeburn 8584: if ($srch->{'srchin'} eq 'instd') {
1.412 raeburn 8585: my $instd_chk = &instdirectorysrch_check($srch);
1.160 raeburn 8586: if ($instd_chk ne 'ok') {
1.412 raeburn 8587: my $domd_chk = &domdirectorysrch_check($srch);
1.413 raeburn 8588: $response .= '<span class="LC_warning">'.$instd_chk.'</span><br />';
1.412 raeburn 8589: if ($domd_chk eq 'ok') {
1.435 raeburn 8590: $response .= &mt('You may want to search in the LON-CAPA domain instead of in the institutional directory.');
1.412 raeburn 8591: }
1.415 raeburn 8592: $response .= '<br />';
1.412 raeburn 8593: }
8594: } else {
1.417 raeburn 8595: unless (($context eq 'requestcrs') && ($srch->{'srchtype'} eq 'exact')) {
1.412 raeburn 8596: my $domd_chk = &domdirectorysrch_check($srch);
1.438 raeburn 8597: if (($domd_chk ne 'ok') && ($env{'form.action'} ne 'accesslogs')) {
1.412 raeburn 8598: my $instd_chk = &instdirectorysrch_check($srch);
1.413 raeburn 8599: $response .= '<span class="LC_warning">'.$domd_chk.'</span><br />';
1.412 raeburn 8600: if ($instd_chk eq 'ok') {
1.435 raeburn 8601: $response .= &mt('You may want to search in the institutional directory instead of in the LON-CAPA domain.');
1.412 raeburn 8602: }
1.415 raeburn 8603: $response .= '<br />';
1.412 raeburn 8604: }
1.160 raeburn 8605: }
8606: }
8607: if ($response ne '') {
1.180 raeburn 8608: return ($currstate,$response);
1.160 raeburn 8609: }
8610: if ($srch->{'srchby'} eq 'uname') {
8611: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs')) {
8612: if ($env{'form.forcenew'}) {
8613: if ($srch->{'srchdomain'} ne $env{'request.role.domain'}) {
8614: my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
8615: if ($uhome eq 'no_host') {
8616: my $domdesc = &Apache::lonnet::domain($env{'request.role.domain'},'description');
1.180 raeburn 8617: my $showdom = &display_domain_info($env{'request.role.domain'});
8618: $response = &mt('New users can only be created in the domain to which your current role belongs - [_1].',$showdom);
1.160 raeburn 8619: } else {
1.179 raeburn 8620: $currstate = 'modify';
1.160 raeburn 8621: }
8622: } else {
1.179 raeburn 8623: $currstate = 'modify';
1.160 raeburn 8624: }
8625: } else {
8626: if ($srch->{'srchin'} eq 'dom') {
1.162 raeburn 8627: if ($srch->{'srchtype'} eq 'exact') {
8628: my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
8629: if ($uhome eq 'no_host') {
1.179 raeburn 8630: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8631: &build_search_response($context,$srch,%srch_results);
1.162 raeburn 8632: } else {
1.179 raeburn 8633: $currstate = 'modify';
1.416 raeburn 8634: if ($env{'form.action'} eq 'accesslogs') {
8635: $currstate = 'activity';
8636: }
1.310 raeburn 8637: my $uname = $srch->{'srchterm'};
8638: my $udom = $srch->{'srchdomain'};
8639: $srch_results{$uname.':'.$udom} =
8640: { &Apache::lonnet::get('environment',
8641: ['firstname',
8642: 'lastname',
8643: 'permanentemail'],
8644: $udom,$uname)
8645: };
1.162 raeburn 8646: }
8647: } else {
8648: %srch_results = &Apache::lonnet::usersearch($srch);
1.179 raeburn 8649: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8650: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 8651: }
8652: } else {
1.167 albertel 8653: my $courseusers = &get_courseusers();
1.162 raeburn 8654: if ($srch->{'srchtype'} eq 'exact') {
1.167 albertel 8655: if (exists($courseusers->{$srch->{'srchterm'}.':'.$srch->{'srchdomain'}})) {
1.179 raeburn 8656: $currstate = 'modify';
1.162 raeburn 8657: } else {
1.179 raeburn 8658: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8659: &build_search_response($context,$srch,%srch_results);
1.162 raeburn 8660: }
1.160 raeburn 8661: } else {
1.167 albertel 8662: foreach my $user (keys(%$courseusers)) {
1.162 raeburn 8663: my ($cuname,$cudomain) = split(/:/,$user);
8664: if ($cudomain eq $srch->{'srchdomain'}) {
1.177 raeburn 8665: my $matched = 0;
8666: if ($srch->{'srchtype'} eq 'begins') {
8667: if ($cuname =~ /^\Q$srch->{'srchterm'}\E/i) {
8668: $matched = 1;
8669: }
8670: } else {
8671: if ($cuname =~ /\Q$srch->{'srchterm'}\E/i) {
8672: $matched = 1;
8673: }
8674: }
8675: if ($matched) {
1.167 albertel 8676: $srch_results{$user} =
8677: {&Apache::lonnet::get('environment',
8678: ['firstname',
8679: 'lastname',
1.194 albertel 8680: 'permanentemail'],
8681: $cudomain,$cuname)};
1.162 raeburn 8682: }
8683: }
8684: }
1.179 raeburn 8685: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8686: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 8687: }
8688: }
8689: }
8690: } elsif ($srch->{'srchin'} eq 'alc') {
1.179 raeburn 8691: $currstate = 'query';
1.160 raeburn 8692: } elsif ($srch->{'srchin'} eq 'instd') {
1.181 raeburn 8693: ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
8694: if ($dirsrchres eq 'ok') {
8695: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8696: &build_search_response($context,$srch,%srch_results);
1.181 raeburn 8697: } else {
8698: my $showdom = &display_domain_info($srch->{'srchdomain'});
8699: $response = '<span class="LC_warning">'.
8700: &mt('Institutional directory search is not available in domain: [_1]',$showdom).
8701: '</span><br />'.
1.435 raeburn 8702: &mt('You may want to search in the LON-CAPA domain instead of in the institutional directory.').
1.415 raeburn 8703: '<br />';
1.181 raeburn 8704: }
1.160 raeburn 8705: }
8706: } else {
8707: if ($srch->{'srchin'} eq 'dom') {
8708: %srch_results = &Apache::lonnet::usersearch($srch);
1.179 raeburn 8709: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8710: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 8711: } elsif ($srch->{'srchin'} eq 'crs') {
1.167 albertel 8712: my $courseusers = &get_courseusers();
8713: foreach my $user (keys(%$courseusers)) {
1.160 raeburn 8714: my ($uname,$udom) = split(/:/,$user);
8715: my %names = &Apache::loncommon::getnames($uname,$udom);
8716: my %emails = &Apache::loncommon::getemails($uname,$udom);
8717: if ($srch->{'srchby'} eq 'lastname') {
8718: if ((($srch->{'srchtype'} eq 'exact') &&
8719: ($names{'lastname'} eq $srch->{'srchterm'})) ||
1.177 raeburn 8720: (($srch->{'srchtype'} eq 'begins') &&
8721: ($names{'lastname'} =~ /^\Q$srch->{'srchterm'}\E/i)) ||
1.160 raeburn 8722: (($srch->{'srchtype'} eq 'contains') &&
8723: ($names{'lastname'} =~ /\Q$srch->{'srchterm'}\E/i))) {
8724: $srch_results{$user} = {firstname => $names{'firstname'},
8725: lastname => $names{'lastname'},
8726: permanentemail => $emails{'permanentemail'},
8727: };
8728: }
8729: } elsif ($srch->{'srchby'} eq 'lastfirst') {
8730: my ($srchlast,$srchfirst) = split(/,/,$srch->{'srchterm'});
1.177 raeburn 8731: $srchlast =~ s/\s+$//;
8732: $srchfirst =~ s/^\s+//;
1.160 raeburn 8733: if ($srch->{'srchtype'} eq 'exact') {
8734: if (($names{'lastname'} eq $srchlast) &&
8735: ($names{'firstname'} eq $srchfirst)) {
8736: $srch_results{$user} = {firstname => $names{'firstname'},
8737: lastname => $names{'lastname'},
8738: permanentemail => $emails{'permanentemail'},
8739:
8740: };
8741: }
1.177 raeburn 8742: } elsif ($srch->{'srchtype'} eq 'begins') {
8743: if (($names{'lastname'} =~ /^\Q$srchlast\E/i) &&
8744: ($names{'firstname'} =~ /^\Q$srchfirst\E/i)) {
8745: $srch_results{$user} = {firstname => $names{'firstname'},
8746: lastname => $names{'lastname'},
8747: permanentemail => $emails{'permanentemail'},
8748: };
8749: }
8750: } else {
1.160 raeburn 8751: if (($names{'lastname'} =~ /\Q$srchlast\E/i) &&
8752: ($names{'firstname'} =~ /\Q$srchfirst\E/i)) {
8753: $srch_results{$user} = {firstname => $names{'firstname'},
8754: lastname => $names{'lastname'},
8755: permanentemail => $emails{'permanentemail'},
8756: };
8757: }
8758: }
8759: }
8760: }
1.179 raeburn 8761: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8762: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 8763: } elsif ($srch->{'srchin'} eq 'alc') {
1.179 raeburn 8764: $currstate = 'query';
1.160 raeburn 8765: } elsif ($srch->{'srchin'} eq 'instd') {
1.181 raeburn 8766: ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
8767: if ($dirsrchres eq 'ok') {
8768: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8769: &build_search_response($context,$srch,%srch_results);
1.181 raeburn 8770: } else {
1.412 raeburn 8771: my $showdom = &display_domain_info($srch->{'srchdomain'});
8772: $response = '<span class="LC_warning">'.
1.181 raeburn 8773: &mt('Institutional directory search is not available in domain: [_1]',$showdom).
8774: '</span><br />'.
1.435 raeburn 8775: &mt('You may want to search in the LON-CAPA domain instead of in the institutional directory.').
1.415 raeburn 8776: '<br />';
1.181 raeburn 8777: }
1.160 raeburn 8778: }
8779: }
1.179 raeburn 8780: return ($currstate,$response,$forcenewuser,\%srch_results);
1.160 raeburn 8781: }
8782:
1.412 raeburn 8783: sub domdirectorysrch_check {
8784: my ($srch) = @_;
8785: my $response;
8786: my %dom_inst_srch = &Apache::lonnet::get_dom('configuration',
8787: ['directorysrch'],$srch->{'srchdomain'});
8788: my $showdom = &display_domain_info($srch->{'srchdomain'});
8789: if (ref($dom_inst_srch{'directorysrch'}) eq 'HASH') {
8790: if ($dom_inst_srch{'directorysrch'}{'lcavailable'} eq '0') {
8791: return &mt('LON-CAPA directory search is not available in domain: [_1]',$showdom);
8792: }
8793: if ($dom_inst_srch{'directorysrch'}{'lclocalonly'}) {
8794: if ($env{'request.role.domain'} ne $srch->{'srchdomain'}) {
8795: return &mt('LON-CAPA directory search in domain: [_1] is only allowed for users with a current role in the domain.',$showdom);
8796: }
8797: }
8798: }
8799: return 'ok';
8800: }
8801:
8802: sub instdirectorysrch_check {
1.160 raeburn 8803: my ($srch) = @_;
8804: my $can_search = 0;
8805: my $response;
8806: my %dom_inst_srch = &Apache::lonnet::get_dom('configuration',
8807: ['directorysrch'],$srch->{'srchdomain'});
1.180 raeburn 8808: my $showdom = &display_domain_info($srch->{'srchdomain'});
1.160 raeburn 8809: if (ref($dom_inst_srch{'directorysrch'}) eq 'HASH') {
8810: if (!$dom_inst_srch{'directorysrch'}{'available'}) {
1.180 raeburn 8811: return &mt('Institutional directory search is not available in domain: [_1]',$showdom);
1.160 raeburn 8812: }
8813: if ($dom_inst_srch{'directorysrch'}{'localonly'}) {
8814: if ($env{'request.role.domain'} ne $srch->{'srchdomain'}) {
1.180 raeburn 8815: return &mt('Institutional directory search in domain: [_1] is only allowed for users with a current role in the domain.',$showdom);
1.160 raeburn 8816: }
8817: my @usertypes = split(/:/,$env{'environment.inststatus'});
8818: if (!@usertypes) {
8819: push(@usertypes,'default');
8820: }
8821: if (ref($dom_inst_srch{'directorysrch'}{'cansearch'}) eq 'ARRAY') {
8822: foreach my $type (@usertypes) {
8823: if (grep(/^\Q$type\E$/,@{$dom_inst_srch{'directorysrch'}{'cansearch'}})) {
8824: $can_search = 1;
8825: last;
8826: }
8827: }
8828: }
8829: if (!$can_search) {
8830: my ($insttypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($srch->{'srchdomain'});
8831: my @longtypes;
8832: foreach my $item (@usertypes) {
1.229 raeburn 8833: if (defined($insttypes->{$item})) {
8834: push (@longtypes,$insttypes->{$item});
8835: } elsif ($item eq 'default') {
8836: push (@longtypes,&mt('other'));
8837: }
1.160 raeburn 8838: }
8839: my $insttype_str = join(', ',@longtypes);
1.180 raeburn 8840: return &mt('Institutional directory search in domain: [_1] is not available to your user type: ',$showdom).$insttype_str;
1.229 raeburn 8841: }
1.160 raeburn 8842: } else {
8843: $can_search = 1;
8844: }
8845: } else {
1.180 raeburn 8846: return &mt('Institutional directory search has not been configured for domain: [_1]',$showdom);
1.160 raeburn 8847: }
8848: my %longtext = &Apache::lonlocal::texthash (
1.167 albertel 8849: uname => 'username',
1.160 raeburn 8850: lastfirst => 'last name, first name',
1.167 albertel 8851: lastname => 'last name',
1.172 raeburn 8852: contains => 'contains',
1.178 raeburn 8853: exact => 'as exact match to',
8854: begins => 'begins with',
1.160 raeburn 8855: );
8856: if ($can_search) {
8857: if (ref($dom_inst_srch{'directorysrch'}{'searchby'}) eq 'ARRAY') {
8858: if (!grep(/^\Q$srch->{'srchby'}\E$/,@{$dom_inst_srch{'directorysrch'}{'searchby'}})) {
1.180 raeburn 8859: return &mt('Institutional directory search in domain: [_1] is not available for searching by "[_2]"',$showdom,$longtext{$srch->{'srchby'}});
1.160 raeburn 8860: }
8861: } else {
1.180 raeburn 8862: return &mt('Institutional directory search in domain: [_1] is not available.', $showdom);
1.160 raeburn 8863: }
8864: }
8865: if ($can_search) {
1.178 raeburn 8866: if (ref($dom_inst_srch{'directorysrch'}{'searchtypes'}) eq 'ARRAY') {
8867: if (grep(/^\Q$srch->{'srchtype'}\E/,@{$dom_inst_srch{'directorysrch'}{'searchtypes'}})) {
8868: return 'ok';
8869: } else {
1.180 raeburn 8870: return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
1.178 raeburn 8871: }
8872: } else {
8873: if ((($dom_inst_srch{'directorysrch'}{'searchtypes'} eq 'specify') &&
8874: ($srch->{'srchtype'} eq 'exact' || $srch->{'srchtype'} eq 'contains')) ||
8875: ($dom_inst_srch{'directorysrch'}{'searchtypes'} eq $srch->{'srchtype'})) {
8876: return 'ok';
8877: } else {
1.180 raeburn 8878: return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
1.178 raeburn 8879: }
1.160 raeburn 8880: }
8881: }
8882: }
8883:
8884: sub get_courseusers {
8885: my %advhash;
1.167 albertel 8886: my $classlist = &Apache::loncoursedata::get_classlist();
1.160 raeburn 8887: my %coursepersonnel=&Apache::lonnet::get_course_adv_roles();
8888: foreach my $role (sort(keys(%coursepersonnel))) {
8889: foreach my $user (split(/\,/,$coursepersonnel{$role})) {
1.167 albertel 8890: if (!exists($classlist->{$user})) {
8891: $classlist->{$user} = [];
8892: }
1.160 raeburn 8893: }
8894: }
1.167 albertel 8895: return $classlist;
1.160 raeburn 8896: }
8897:
8898: sub build_search_response {
1.221 raeburn 8899: my ($context,$srch,%srch_results) = @_;
1.179 raeburn 8900: my ($currstate,$response,$forcenewuser);
1.160 raeburn 8901: my %names = (
1.330 bisitz 8902: 'uname' => 'username',
8903: 'lastname' => 'last name',
1.160 raeburn 8904: 'lastfirst' => 'last name, first name',
1.330 bisitz 8905: 'crs' => 'this course',
8906: 'dom' => 'LON-CAPA domain',
8907: 'instd' => 'the institutional directory for domain',
1.160 raeburn 8908: );
8909:
8910: my %single = (
1.180 raeburn 8911: begins => 'A match',
1.160 raeburn 8912: contains => 'A match',
1.180 raeburn 8913: exact => 'An exact match',
1.160 raeburn 8914: );
8915: my %nomatch = (
1.180 raeburn 8916: begins => 'No match',
1.160 raeburn 8917: contains => 'No match',
1.180 raeburn 8918: exact => 'No exact match',
1.160 raeburn 8919: );
8920: if (keys(%srch_results) > 1) {
1.179 raeburn 8921: $currstate = 'select';
1.160 raeburn 8922: } else {
8923: if (keys(%srch_results) == 1) {
1.416 raeburn 8924: if ($env{'form.action'} eq 'accesslogs') {
8925: $currstate = 'activity';
8926: } else {
8927: $currstate = 'modify';
8928: }
1.180 raeburn 8929: $response = &mt("$single{$srch->{'srchtype'}} was found for the $names{$srch->{'srchby'}} ([_1]) in $names{$srch->{'srchin'}}.",$srch->{'srchterm'});
8930: if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
1.330 bisitz 8931: $response .= ': '.&display_domain_info($srch->{'srchdomain'});
1.180 raeburn 8932: }
1.330 bisitz 8933: } else { # Search has nothing found. Prepare message to user.
8934: $response = '<span class="LC_warning">';
1.180 raeburn 8935: if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
1.330 bisitz 8936: $response .= &mt("$nomatch{$srch->{'srchtype'}} found for the $names{$srch->{'srchby'}} [_1] in $names{$srch->{'srchin'}}: [_2]",
8937: '<b>'.$srch->{'srchterm'}.'</b>',
8938: &display_domain_info($srch->{'srchdomain'}));
8939: } else {
8940: $response .= &mt("$nomatch{$srch->{'srchtype'}} found for the $names{$srch->{'srchby'}} [_1] in $names{$srch->{'srchin'}}.",
8941: '<b>'.$srch->{'srchterm'}.'</b>');
1.180 raeburn 8942: }
8943: $response .= '</span>';
1.330 bisitz 8944:
1.160 raeburn 8945: if ($srch->{'srchin'} ne 'alc') {
8946: $forcenewuser = 1;
8947: my $cansrchinst = 0;
1.438 raeburn 8948: if (($srch->{'srchdomain'}) && ($env{'form.action'} ne 'accesslogs')) {
1.160 raeburn 8949: my %domconfig = &Apache::lonnet::get_dom('configuration',['directorysrch'],$srch->{'srchdomain'});
8950: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
8951: if ($domconfig{'directorysrch'}{'available'}) {
8952: $cansrchinst = 1;
8953: }
8954: }
8955: }
1.180 raeburn 8956: if ((($srch->{'srchby'} eq 'lastfirst') ||
8957: ($srch->{'srchby'} eq 'lastname')) &&
8958: ($srch->{'srchin'} eq 'dom')) {
8959: if ($cansrchinst) {
8960: $response .= '<br />'.&mt('You may want to broaden your search to a search of the institutional directory for the domain.');
1.160 raeburn 8961: }
8962: }
1.180 raeburn 8963: if ($srch->{'srchin'} eq 'crs') {
8964: $response .= '<br />'.&mt('You may want to broaden your search to the selected LON-CAPA domain.');
8965: }
8966: }
1.305 raeburn 8967: my $createdom = $env{'request.role.domain'};
8968: if ($context eq 'requestcrs') {
8969: if ($env{'form.coursedom'} ne '') {
8970: $createdom = $env{'form.coursedom'};
8971: }
8972: }
1.416 raeburn 8973: unless (($env{'form.action'} eq 'accesslogs') || (($srch->{'srchby'} eq 'uname') && ($srch->{'srchin'} eq 'dom') &&
8974: ($srch->{'srchtype'} eq 'exact') && ($srch->{'srchdomain'} eq $createdom))) {
1.221 raeburn 8975: my $cancreate =
1.305 raeburn 8976: &Apache::lonuserutils::can_create_user($createdom,$context);
8977: my $targetdom = '<span class="LC_cusr_emph">'.$createdom.'</span>';
1.221 raeburn 8978: if ($cancreate) {
1.305 raeburn 8979: my $showdom = &display_domain_info($createdom);
1.266 bisitz 8980: $response .= '<br /><br />'
8981: .'<b>'.&mt('To add a new user:').'</b>'
1.305 raeburn 8982: .'<br />';
8983: if ($context eq 'requestcrs') {
8984: $response .= &mt("(You can only define new users in the new course's domain - [_1])",$targetdom);
8985: } else {
8986: $response .= &mt("(You can only create new users in your current role's domain - [_1])",$targetdom);
8987: }
8988: $response .='<ul><li>'
1.266 bisitz 8989: .&mt("Set 'Domain/institution to search' to: [_1]",'<span class="LC_cusr_emph">'.$showdom.'</span>')
8990: .'</li><li>'
8991: .&mt("Set 'Search criteria' to: [_1]username is ..... in selected LON-CAPA domain[_2]",'<span class="LC_cusr_emph">','</span>')
8992: .'</li><li>'
8993: .&mt('Provide the proposed username')
8994: .'</li><li>'
8995: .&mt("Click 'Search'")
8996: .'</li></ul><br />';
1.221 raeburn 8997: } else {
1.422 raeburn 8998: unless (($context eq 'domain') && ($env{'form.action'} eq 'singleuser')) {
8999: my $helplink = ' href="javascript:helpMenu('."'display'".')"';
9000: $response .= '<br /><br />';
9001: if ($context eq 'requestcrs') {
9002: $response .= &mt("You are not authorized to define new users in the new course's domain - [_1].",$targetdom);
9003: } else {
9004: $response .= &mt("You are not authorized to create new users in your current role's domain - [_1].",$targetdom);
9005: }
9006: $response .= '<br />'
9007: .&mt('Please contact the [_1]helpdesk[_2] if you need to create a new user.'
9008: ,' <a'.$helplink.'>'
9009: ,'</a>')
9010: .'<br />';
1.305 raeburn 9011: }
1.221 raeburn 9012: }
1.160 raeburn 9013: }
9014: }
9015: }
1.179 raeburn 9016: return ($currstate,$response,$forcenewuser);
1.160 raeburn 9017: }
9018:
1.180 raeburn 9019: sub display_domain_info {
9020: my ($dom) = @_;
9021: my $output = $dom;
9022: if ($dom ne '') {
9023: my $domdesc = &Apache::lonnet::domain($dom,'description');
9024: if ($domdesc ne '') {
9025: $output .= ' <span class="LC_cusr_emph">('.$domdesc.')</span>';
9026: }
9027: }
9028: return $output;
9029: }
9030:
1.160 raeburn 9031: sub crumb_utilities {
9032: my %elements = (
9033: crtuser => {
9034: srchterm => 'text',
1.172 raeburn 9035: srchin => 'selectbox',
1.160 raeburn 9036: srchby => 'selectbox',
9037: srchtype => 'selectbox',
9038: srchdomain => 'selectbox',
9039: },
1.207 raeburn 9040: crtusername => {
9041: srchterm => 'text',
9042: srchdomain => 'selectbox',
9043: },
1.160 raeburn 9044: docustom => {
9045: rolename => 'selectbox',
9046: newrolename => 'textbox',
9047: },
1.179 raeburn 9048: studentform => {
9049: srchterm => 'text',
9050: srchin => 'selectbox',
9051: srchby => 'selectbox',
9052: srchtype => 'selectbox',
9053: srchdomain => 'selectbox',
9054: },
1.160 raeburn 9055: );
9056:
9057: my $jsback .= qq|
9058: function backPage(formname,prevphase,prevstate) {
1.211 raeburn 9059: if (typeof prevphase == 'undefined') {
9060: formname.phase.value = '';
9061: }
9062: else {
9063: formname.phase.value = prevphase;
9064: }
9065: if (typeof prevstate == 'undefined') {
9066: formname.currstate.value = '';
9067: }
9068: else {
9069: formname.currstate.value = prevstate;
9070: }
1.160 raeburn 9071: formname.submit();
9072: }
9073: |;
9074: return ($jsback,\%elements);
9075: }
9076:
1.26 matthew 9077: sub course_level_table {
1.375 raeburn 9078: my ($inccourses,$showcredits,$defaultcredits) = @_;
9079: return unless (ref($inccourses) eq 'HASH');
1.26 matthew 9080: my $table = '';
1.62 www 9081: # Custom Roles?
9082:
1.190 raeburn 9083: my %customroles=&Apache::lonuserutils::my_custom_roles();
1.89 raeburn 9084: my %lt=&Apache::lonlocal::texthash(
9085: 'exs' => "Existing sections",
9086: 'new' => "Define new section",
9087: 'ssd' => "Set Start Date",
9088: 'sed' => "Set End Date",
1.131 raeburn 9089: 'crl' => "Course Level",
1.89 raeburn 9090: 'act' => "Activate",
9091: 'rol' => "Role",
9092: 'ext' => "Extent",
1.113 raeburn 9093: 'grs' => "Section",
1.375 raeburn 9094: 'crd' => "Credits",
1.89 raeburn 9095: 'sta' => "Start",
9096: 'end' => "End"
9097: );
1.62 www 9098:
1.375 raeburn 9099: foreach my $protectedcourse (sort(keys(%{$inccourses}))) {
1.135 raeburn 9100: my $thiscourse=$protectedcourse;
1.26 matthew 9101: $thiscourse=~s:_:/:g;
9102: my %coursedata=&Apache::lonnet::coursedescription($thiscourse);
1.365 raeburn 9103: my $isowner = &Apache::lonuserutils::is_courseowner($protectedcourse,$coursedata{'internal.courseowner'});
1.26 matthew 9104: my $area=$coursedata{'description'};
1.321 raeburn 9105: my $crstype=$coursedata{'type'};
1.135 raeburn 9106: if (!defined($area)) { $area=&mt('Unavailable course').': '.$protectedcourse; }
1.89 raeburn 9107: my ($domain,$cnum)=split(/\//,$thiscourse);
1.115 albertel 9108: my %sections_count;
1.101 albertel 9109: if (defined($env{'request.course.id'})) {
9110: if ($env{'request.course.id'} eq $domain.'_'.$cnum) {
1.115 albertel 9111: %sections_count =
9112: &Apache::loncommon::get_sections($domain,$cnum);
1.92 raeburn 9113: }
9114: }
1.321 raeburn 9115: my @roles = &Apache::lonuserutils::roles_by_context('course','',$crstype);
1.213 raeburn 9116: foreach my $role (@roles) {
1.321 raeburn 9117: my $plrole=&Apache::lonnet::plaintext($role,$crstype);
1.329 raeburn 9118: if ((&Apache::lonnet::allowed('c'.$role,$thiscourse)) ||
9119: ((($role eq 'cc') || ($role eq 'co')) && ($isowner))) {
1.221 raeburn 9120: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
1.375 raeburn 9121: $plrole,\%sections_count,\%lt,
1.402 raeburn 9122: $showcredits,$defaultcredits,$crstype);
1.221 raeburn 9123: } elsif ($env{'request.course.sec'} ne '') {
9124: if (&Apache::lonnet::allowed('c'.$role,$thiscourse.'/'.
9125: $env{'request.course.sec'})) {
9126: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
1.375 raeburn 9127: $plrole,\%sections_count,\%lt,
1.402 raeburn 9128: $showcredits,$defaultcredits,$crstype);
1.26 matthew 9129: }
9130: }
9131: }
1.221 raeburn 9132: if (&Apache::lonnet::allowed('ccr',$thiscourse)) {
1.324 raeburn 9133: foreach my $cust (sort(keys(%customroles))) {
9134: next if ($crstype eq 'Community' && $customroles{$cust} =~ /bre\&S/);
1.221 raeburn 9135: my $role = 'cr_cr_'.$env{'user.domain'}.'_'.$env{'user.name'}.'_'.$cust;
9136: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
1.402 raeburn 9137: $cust,\%sections_count,\%lt,
9138: $showcredits,$defaultcredits,$crstype);
1.221 raeburn 9139: }
1.62 www 9140: }
1.26 matthew 9141: }
9142: return '' if ($table eq ''); # return nothing if there is nothing
9143: # in the table
1.188 raeburn 9144: my $result;
9145: if (!$env{'request.course.id'}) {
9146: $result = '<h4>'.$lt{'crl'}.'</h4>'."\n";
9147: }
9148: $result .=
1.136 raeburn 9149: &Apache::loncommon::start_data_table().
9150: &Apache::loncommon::start_data_table_header_row().
1.375 raeburn 9151: '<th>'.$lt{'act'}.'</th><th>'.$lt{'rol'}.'</th>'."\n".
1.402 raeburn 9152: '<th>'.$lt{'ext'}.'</th><th>'."\n";
9153: if ($showcredits) {
9154: $result .= $lt{'crd'}.'</th>';
9155: }
9156: $result .=
1.375 raeburn 9157: '<th>'.$lt{'grs'}.'</th><th>'.$lt{'sta'}.'</th>'."\n".
9158: '<th>'.$lt{'end'}.'</th>'.
1.136 raeburn 9159: &Apache::loncommon::end_data_table_header_row().
9160: $table.
9161: &Apache::loncommon::end_data_table();
1.26 matthew 9162: return $result;
9163: }
1.88 raeburn 9164:
1.221 raeburn 9165: sub course_level_row {
1.375 raeburn 9166: my ($protectedcourse,$role,$area,$domain,$plrole,$sections_count,
1.402 raeburn 9167: $lt,$showcredits,$defaultcredits,$crstype) = @_;
1.375 raeburn 9168: my $creditem;
1.222 raeburn 9169: my $row = &Apache::loncommon::start_data_table_row().
9170: ' <td><input type="checkbox" name="act_'.
9171: $protectedcourse.'_'.$role.'" /></td>'."\n".
9172: ' <td>'.$plrole.'</td>'."\n".
9173: ' <td>'.$area.'<br />Domain: '.$domain.'</td>'."\n";
1.402 raeburn 9174: if (($showcredits) && ($role eq 'st') && ($crstype eq 'Course')) {
1.375 raeburn 9175: $row .=
9176: '<td><input type="text" name="credits_'.$protectedcourse.'_'.
9177: $role.'" size="3" value="'.$defaultcredits.'" /></td>';
9178: } else {
9179: $row .= '<td> </td>';
9180: }
1.322 raeburn 9181: if (($role eq 'cc') || ($role eq 'co')) {
1.222 raeburn 9182: $row .= '<td> </td>';
1.221 raeburn 9183: } elsif ($env{'request.course.sec'} ne '') {
1.222 raeburn 9184: $row .= ' <td><input type="hidden" value="'.
9185: $env{'request.course.sec'}.'" '.
9186: 'name="sec_'.$protectedcourse.'_'.$role.'" />'.
9187: $env{'request.course.sec'}.'</td>';
1.221 raeburn 9188: } else {
9189: if (ref($sections_count) eq 'HASH') {
9190: my $currsec =
9191: &Apache::lonuserutils::course_sections($sections_count,
9192: $protectedcourse.'_'.$role);
1.222 raeburn 9193: $row .= '<td><table class="LC_createuser">'."\n".
9194: '<tr class="LC_section_row">'."\n".
9195: ' <td valign="top">'.$lt->{'exs'}.'<br />'.
9196: $currsec.'</td>'."\n".
9197: ' <td> </td>'."\n".
9198: ' <td valign="top"> '.$lt->{'new'}.'<br />'.
1.221 raeburn 9199: '<input type="text" name="newsec_'.$protectedcourse.'_'.$role.
9200: '" value="" />'.
9201: '<input type="hidden" '.
9202: 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'."\n".
1.222 raeburn 9203: '</tr></table></td>'."\n";
1.221 raeburn 9204: } else {
1.222 raeburn 9205: $row .= '<td><input type="text" size="10" '.
1.375 raeburn 9206: 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'."\n";
1.221 raeburn 9207: }
9208: }
1.222 raeburn 9209: $row .= <<ENDTIMEENTRY;
9210: <td><input type="hidden" name="start_$protectedcourse\_$role" value="" />
1.221 raeburn 9211: <a href=
9212: "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 9213: <td><input type="hidden" name="end_$protectedcourse\_$role" value="" />
1.221 raeburn 9214: <a href=
9215: "javascript:pjump('date_end','End Date $plrole',document.cu.end_$protectedcourse\_$role.value,'end_$protectedcourse\_$role','cu.pres','dateset')">$lt->{'sed'}</a></td>
9216: ENDTIMEENTRY
1.222 raeburn 9217: $row .= &Apache::loncommon::end_data_table_row();
9218: return $row;
1.221 raeburn 9219: }
9220:
1.88 raeburn 9221: sub course_level_dc {
1.375 raeburn 9222: my ($dcdom,$showcredits) = @_;
1.190 raeburn 9223: my %customroles=&Apache::lonuserutils::my_custom_roles();
1.213 raeburn 9224: my @roles = &Apache::lonuserutils::roles_by_context('course');
1.88 raeburn 9225: my $hiddenitems = '<input type="hidden" name="dcdomain" value="'.$dcdom.'" />'.
9226: '<input type="hidden" name="origdom" value="'.$dcdom.'" />'.
1.133 raeburn 9227: '<input type="hidden" name="dccourse" value="" />';
1.355 www 9228: my $courseform=&Apache::loncommon::selectcourse_link
1.356 raeburn 9229: ('cu','dccourse','dcdomain','coursedesc',undef,undef,'Select','crstype');
1.375 raeburn 9230: my $credit_elem;
9231: if ($showcredits) {
9232: $credit_elem = 'credits';
9233: }
9234: my $cb_jscript = &Apache::loncommon::coursebrowser_javascript($dcdom,'currsec','cu','role','Course/Community Browser',$credit_elem);
1.88 raeburn 9235: my %lt=&Apache::lonlocal::texthash(
9236: 'rol' => "Role",
1.113 raeburn 9237: 'grs' => "Section",
1.88 raeburn 9238: 'exs' => "Existing sections",
9239: 'new' => "Define new section",
9240: 'sta' => "Start",
9241: 'end' => "End",
9242: 'ssd' => "Set Start Date",
1.355 www 9243: 'sed' => "Set End Date",
1.375 raeburn 9244: 'scc' => "Course/Community",
9245: 'crd' => "Credits",
1.88 raeburn 9246: );
1.323 raeburn 9247: my $header = '<h4>'.&mt('Course/Community Level').'</h4>'.
1.136 raeburn 9248: &Apache::loncommon::start_data_table().
9249: &Apache::loncommon::start_data_table_header_row().
1.375 raeburn 9250: '<th>'.$lt{'scc'}.'</th><th>'.$lt{'rol'}.'</th>'."\n".
1.397 bisitz 9251: '<th>'.$lt{'grs'}.'</th>'."\n";
9252: $header .= '<th>'.$lt{'crd'}.'</th>'."\n" if ($showcredits);
9253: $header .= '<th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'."\n".
1.136 raeburn 9254: &Apache::loncommon::end_data_table_header_row();
1.143 raeburn 9255: my $otheritems = &Apache::loncommon::start_data_table_row()."\n".
1.356 raeburn 9256: '<td><br /><span class="LC_nobreak"><input type="text" name="coursedesc" value="" onfocus="this.blur();opencrsbrowser('."'cu','dccourse','dcdomain','coursedesc','','','','crstype'".')" />'.
9257: $courseform.(' ' x4).'</span></td>'."\n".
1.389 bisitz 9258: '<td valign="top"><br /><select name="role">'."\n";
1.213 raeburn 9259: foreach my $role (@roles) {
1.135 raeburn 9260: my $plrole=&Apache::lonnet::plaintext($role);
1.389 bisitz 9261: $otheritems .= ' <option value="'.$role.'">'.$plrole.'</option>';
1.88 raeburn 9262: }
1.404 raeburn 9263: if ( keys(%customroles) > 0) {
9264: foreach my $cust (sort(keys(%customroles))) {
1.101 albertel 9265: my $custrole='cr_cr_'.$env{'user.domain'}.
1.135 raeburn 9266: '_'.$env{'user.name'}.'_'.$cust;
1.389 bisitz 9267: $otheritems .= ' <option value="'.$custrole.'">'.$cust.'</option>';
1.88 raeburn 9268: }
9269: }
9270: $otheritems .= '</select></td><td>'.
9271: '<table border="0" cellspacing="0" cellpadding="0">'.
9272: '<tr><td valign="top"><b>'.$lt{'exs'}.'</b><br /><select name="currsec">'.
1.389 bisitz 9273: ' <option value=""><--'.&mt('Pick course first').'</option></select></td>'.
1.88 raeburn 9274: '<td> </td>'.
9275: '<td valign="top"> <b>'.$lt{'new'}.'</b><br />'.
1.113 raeburn 9276: '<input type="text" name="newsec" value="" />'.
1.237 raeburn 9277: '<input type="hidden" name="section" value="" />'.
1.323 raeburn 9278: '<input type="hidden" name="groups" value="" />'.
9279: '<input type="hidden" name="crstype" value="" /></td>'.
1.375 raeburn 9280: '</tr></table></td>'."\n";
9281: if ($showcredits) {
9282: $otheritems .= '<td><br />'."\n".
1.397 bisitz 9283: '<input type="text" size="3" name="credits" value="" /></td>'."\n";
1.375 raeburn 9284: }
1.88 raeburn 9285: $otheritems .= <<ENDTIMEENTRY;
1.323 raeburn 9286: <td><br /><input type="hidden" name="start" value='' />
1.88 raeburn 9287: <a href=
9288: "javascript:pjump('date_start','Start Date',document.cu.start.value,'start','cu.pres','dateset')">$lt{'ssd'}</a></td>
1.323 raeburn 9289: <td><br /><input type="hidden" name="end" value='' />
1.88 raeburn 9290: <a href=
9291: "javascript:pjump('date_end','End Date',document.cu.end.value,'end','cu.pres','dateset')">$lt{'sed'}</a></td>
9292: ENDTIMEENTRY
1.136 raeburn 9293: $otheritems .= &Apache::loncommon::end_data_table_row().
9294: &Apache::loncommon::end_data_table()."\n";
1.88 raeburn 9295: return $cb_jscript.$header.$hiddenitems.$otheritems;
9296: }
9297:
1.237 raeburn 9298: sub update_selfenroll_config {
1.400 raeburn 9299: my ($r,$cid,$cdom,$cnum,$context,$crstype,$currsettings) = @_;
1.398 raeburn 9300: return unless (ref($currsettings) eq 'HASH');
9301: my ($row,$lt) = &Apache::lonuserutils::get_selfenroll_titles();
9302: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
1.237 raeburn 9303: my (%changes,%warning);
1.241 raeburn 9304: my $curr_types;
1.400 raeburn 9305: my %noedit;
9306: unless ($context eq 'domain') {
9307: %noedit = &get_noedit_fields($cdom,$cnum,$crstype,$row);
9308: }
1.237 raeburn 9309: if (ref($row) eq 'ARRAY') {
9310: foreach my $item (@{$row}) {
1.400 raeburn 9311: next if ($noedit{$item});
1.237 raeburn 9312: if ($item eq 'enroll_dates') {
9313: my (%currenrolldate,%newenrolldate);
9314: foreach my $type ('start','end') {
1.398 raeburn 9315: $currenrolldate{$type} = $currsettings->{'selfenroll_'.$type.'_date'};
1.237 raeburn 9316: $newenrolldate{$type} = &Apache::lonhtmlcommon::get_date_from_form('selfenroll_'.$type.'_date');
9317: if ($newenrolldate{$type} ne $currenrolldate{$type}) {
9318: $changes{'internal.selfenroll_'.$type.'_date'} = $newenrolldate{$type};
9319: }
9320: }
9321: } elsif ($item eq 'access_dates') {
9322: my (%currdate,%newdate);
9323: foreach my $type ('start','end') {
1.398 raeburn 9324: $currdate{$type} = $currsettings->{'selfenroll_'.$type.'_access'};
1.237 raeburn 9325: $newdate{$type} = &Apache::lonhtmlcommon::get_date_from_form('selfenroll_'.$type.'_access');
9326: if ($newdate{$type} ne $currdate{$type}) {
9327: $changes{'internal.selfenroll_'.$type.'_access'} = $newdate{$type};
9328: }
9329: }
1.241 raeburn 9330: } elsif ($item eq 'types') {
1.398 raeburn 9331: $curr_types = $currsettings->{'selfenroll_'.$item};
1.241 raeburn 9332: if ($env{'form.selfenroll_all'}) {
9333: if ($curr_types ne '*') {
9334: $changes{'internal.selfenroll_types'} = '*';
9335: } else {
9336: next;
9337: }
9338: } else {
1.249 raeburn 9339: my %currdoms;
1.241 raeburn 9340: my @entries = split(/;/,$curr_types);
9341: my @deletedoms = &Apache::loncommon::get_env_multiple('form.selfenroll_delete');
1.249 raeburn 9342: my @activations = &Apache::loncommon::get_env_multiple('form.selfenroll_activate');
1.241 raeburn 9343: my $newnum = 0;
1.249 raeburn 9344: my @latesttypes;
9345: foreach my $num (@activations) {
9346: my @types = &Apache::loncommon::get_env_multiple('form.selfenroll_types_'.$num);
9347: if (@types > 0) {
1.241 raeburn 9348: @types = sort(@types);
9349: my $typestr = join(',',@types);
1.249 raeburn 9350: my $typedom = $env{'form.selfenroll_dom_'.$num};
9351: $latesttypes[$newnum] = $typedom.':'.$typestr;
9352: $currdoms{$typedom} = 1;
1.241 raeburn 9353: $newnum ++;
9354: }
9355: }
1.338 raeburn 9356: for (my $j=0; $j<$env{'form.selfenroll_types_total'}; $j++) {
9357: if ((!grep(/^$j$/,@deletedoms)) && (!grep(/^$j$/,@activations))) {
1.249 raeburn 9358: my @types = &Apache::loncommon::get_env_multiple('form.selfenroll_types_'.$j);
9359: if (@types > 0) {
9360: @types = sort(@types);
9361: my $typestr = join(',',@types);
9362: my $typedom = $env{'form.selfenroll_dom_'.$j};
9363: $latesttypes[$newnum] = $typedom.':'.$typestr;
9364: $currdoms{$typedom} = 1;
9365: $newnum ++;
9366: }
9367: }
9368: }
9369: if ($env{'form.selfenroll_newdom'} ne '') {
9370: my $typedom = $env{'form.selfenroll_newdom'};
9371: if ((!defined($currdoms{$typedom})) &&
9372: (&Apache::lonnet::domain($typedom) ne '')) {
9373: my $typestr;
9374: my ($othertitle,$usertypes,$types) =
9375: &Apache::loncommon::sorted_inst_types($typedom);
9376: my $othervalue = 'any';
9377: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
9378: if (@{$types} > 0) {
1.257 raeburn 9379: my @esc_types = map { &escape($_); } @{$types};
1.249 raeburn 9380: $othervalue = 'other';
1.258 raeburn 9381: $typestr = join(',',(@esc_types,$othervalue));
1.249 raeburn 9382: }
9383: $typestr = $othervalue;
9384: } else {
9385: $typestr = $othervalue;
9386: }
9387: $latesttypes[$newnum] = $typedom.':'.$typestr;
9388: $newnum ++ ;
9389: }
9390: }
1.241 raeburn 9391: my $selfenroll_types = join(';',@latesttypes);
9392: if ($selfenroll_types ne $curr_types) {
9393: $changes{'internal.selfenroll_types'} = $selfenroll_types;
9394: }
9395: }
1.276 raeburn 9396: } elsif ($item eq 'limit') {
9397: my $newlimit = $env{'form.selfenroll_limit'};
9398: my $newcap = $env{'form.selfenroll_cap'};
9399: $newcap =~s/\s+//g;
1.398 raeburn 9400: my $currlimit = $currsettings->{'selfenroll_limit'};
1.276 raeburn 9401: $currlimit = 'none' if ($currlimit eq '');
1.398 raeburn 9402: my $currcap = $currsettings->{'selfenroll_cap'};
1.276 raeburn 9403: if ($newlimit ne $currlimit) {
9404: if ($newlimit ne 'none') {
9405: if ($newcap =~ /^\d+$/) {
9406: if ($newcap ne $currcap) {
9407: $changes{'internal.selfenroll_cap'} = $newcap;
9408: }
9409: $changes{'internal.selfenroll_limit'} = $newlimit;
9410: } else {
1.398 raeburn 9411: $warning{$item} = &mt('Maximum enrollment setting unchanged.').'<br />'.
9412: &mt('The value provided was invalid - it must be a positive integer if enrollment is being limited.');
1.276 raeburn 9413: }
9414: } elsif ($currcap ne '') {
9415: $changes{'internal.selfenroll_cap'} = '';
9416: $changes{'internal.selfenroll_limit'} = $newlimit;
9417: }
9418: } elsif ($currlimit ne 'none') {
9419: if ($newcap =~ /^\d+$/) {
9420: if ($newcap ne $currcap) {
9421: $changes{'internal.selfenroll_cap'} = $newcap;
9422: }
9423: } else {
1.398 raeburn 9424: $warning{$item} = &mt('Maximum enrollment setting unchanged.').'<br />'.
9425: &mt('The value provided was invalid - it must be a positive integer if enrollment is being limited.');
1.276 raeburn 9426: }
9427: }
9428: } elsif ($item eq 'approval') {
9429: my (@currnotified,@newnotified);
1.398 raeburn 9430: my $currapproval = $currsettings->{'selfenroll_approval'};
9431: my $currnotifylist = $currsettings->{'selfenroll_notifylist'};
1.276 raeburn 9432: if ($currnotifylist ne '') {
9433: @currnotified = split(/,/,$currnotifylist);
9434: @currnotified = sort(@currnotified);
9435: }
9436: my $newapproval = $env{'form.selfenroll_approval'};
9437: @newnotified = &Apache::loncommon::get_env_multiple('form.selfenroll_notify');
9438: @newnotified = sort(@newnotified);
9439: if ($newapproval ne $currapproval) {
9440: $changes{'internal.selfenroll_approval'} = $newapproval;
9441: if (!$newapproval) {
9442: if ($currnotifylist ne '') {
9443: $changes{'internal.selfenroll_notifylist'} = '';
9444: }
9445: } else {
9446: my @differences =
1.295 raeburn 9447: &Apache::loncommon::compare_arrays(\@currnotified,\@newnotified);
1.276 raeburn 9448: if (@differences > 0) {
9449: if (@newnotified > 0) {
9450: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
9451: } else {
9452: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
9453: }
9454: }
9455: }
9456: } else {
1.295 raeburn 9457: my @differences = &Apache::loncommon::compare_arrays(\@currnotified,\@newnotified);
1.276 raeburn 9458: if (@differences > 0) {
9459: if (@newnotified > 0) {
9460: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
9461: } else {
9462: $changes{'internal.selfenroll_notifylist'} = '';
9463: }
9464: }
9465: }
1.237 raeburn 9466: } else {
1.398 raeburn 9467: my $curr_val = $currsettings->{'selfenroll_'.$item};
1.237 raeburn 9468: my $newval = $env{'form.selfenroll_'.$item};
9469: if ($item eq 'section') {
9470: $newval = $env{'form.sections'};
1.241 raeburn 9471: if (defined($curr_groups{$newval})) {
1.237 raeburn 9472: $newval = $curr_val;
1.398 raeburn 9473: $warning{$item} = &mt('Section for self-enrolled users unchanged as the proposed section is a group').'<br />'.
9474: &mt('Group names and section names must be distinct');
1.237 raeburn 9475: } elsif ($newval eq 'all') {
9476: $newval = $curr_val;
1.274 bisitz 9477: $warning{$item} = &mt('Section for self-enrolled users unchanged, as "all" is a reserved section name.');
1.237 raeburn 9478: }
9479: if ($newval eq '') {
9480: $newval = 'none';
9481: }
9482: }
9483: if ($newval ne $curr_val) {
9484: $changes{'internal.selfenroll_'.$item} = $newval;
9485: }
1.241 raeburn 9486: }
1.237 raeburn 9487: }
9488: if (keys(%warning) > 0) {
9489: foreach my $item (@{$row}) {
9490: if (exists($warning{$item})) {
9491: $r->print($warning{$item}.'<br />');
9492: }
9493: }
9494: }
9495: if (keys(%changes) > 0) {
9496: my $putresult = &Apache::lonnet::put('environment',\%changes,$cdom,$cnum);
9497: if ($putresult eq 'ok') {
9498: if ((exists($changes{'internal.selfenroll_types'})) ||
9499: (exists($changes{'internal.selfenroll_start_date'})) ||
9500: (exists($changes{'internal.selfenroll_end_date'}))) {
9501: my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',
9502: $cnum,undef,undef,'Course');
9503: my $chome = &Apache::lonnet::homeserver($cnum,$cdom);
1.398 raeburn 9504: if (ref($crsinfo{$cid}) eq 'HASH') {
1.237 raeburn 9505: foreach my $item ('selfenroll_types','selfenroll_start_date','selfenroll_end_date') {
9506: if (exists($changes{'internal.'.$item})) {
1.398 raeburn 9507: $crsinfo{$cid}{$item} = $changes{'internal.'.$item};
1.237 raeburn 9508: }
9509: }
9510: my $crsputresult =
9511: &Apache::lonnet::courseidput($cdom,\%crsinfo,
9512: $chome,'notime');
9513: }
9514: }
9515: $r->print(&mt('The following changes were made to self-enrollment settings:').'<ul>');
9516: foreach my $item (@{$row}) {
9517: my $title = $item;
9518: if (ref($lt) eq 'HASH') {
9519: $title = $lt->{$item};
9520: }
9521: if ($item eq 'enroll_dates') {
9522: foreach my $type ('start','end') {
9523: if (exists($changes{'internal.selfenroll_'.$type.'_date'})) {
9524: my $newdate = &Apache::lonlocal::locallocaltime($changes{'internal.selfenroll_'.$type.'_date'});
1.244 bisitz 9525: $r->print('<li>'.&mt('[_1]: "[_2]" set to "[_3]".',
1.237 raeburn 9526: $title,$type,$newdate).'</li>');
9527: }
9528: }
9529: } elsif ($item eq 'access_dates') {
9530: foreach my $type ('start','end') {
9531: if (exists($changes{'internal.selfenroll_'.$type.'_access'})) {
9532: my $newdate = &Apache::lonlocal::locallocaltime($changes{'internal.selfenroll_'.$type.'_access'});
1.244 bisitz 9533: $r->print('<li>'.&mt('[_1]: "[_2]" set to "[_3]".',
1.237 raeburn 9534: $title,$type,$newdate).'</li>');
9535: }
9536: }
1.276 raeburn 9537: } elsif ($item eq 'limit') {
9538: if ((exists($changes{'internal.selfenroll_limit'})) ||
9539: (exists($changes{'internal.selfenroll_cap'}))) {
9540: my ($newval,$newcap);
9541: if ($changes{'internal.selfenroll_cap'} ne '') {
9542: $newcap = $changes{'internal.selfenroll_cap'}
9543: } else {
1.398 raeburn 9544: $newcap = $currsettings->{'selfenroll_cap'};
1.276 raeburn 9545: }
9546: if ($changes{'internal.selfenroll_limit'} eq 'none') {
9547: $newval = &mt('No limit');
9548: } elsif ($changes{'internal.selfenroll_limit'} eq
9549: 'allstudents') {
9550: $newval = &mt('New self-enrollment no longer allowed when total (all students) reaches [_1].',$newcap);
9551: } elsif ($changes{'internal.selfenroll_limit'} eq 'selfenrolled') {
9552: $newval = &mt('New self-enrollment no longer allowed when total number of self-enrolled students reaches [_1].',$newcap);
9553: } else {
1.398 raeburn 9554: my $currlimit = $currsettings->{'selfenroll_limit'};
1.276 raeburn 9555: if ($currlimit eq 'allstudents') {
9556: $newval = &mt('New self-enrollment no longer allowed when total (all students) reaches [_1].',$newcap);
9557: } elsif ($changes{'internal.selfenroll_limit'} eq 'selfenrolled') {
1.308 raeburn 9558: $newval = &mt('New self-enrollment no longer allowed when total number of self-enrolled students reaches [_1].',$newcap);
1.276 raeburn 9559: }
9560: }
9561: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval).'</li>'."\n");
9562: }
9563: } elsif ($item eq 'approval') {
9564: if ((exists($changes{'internal.selfenroll_approval'})) ||
9565: (exists($changes{'internal.selfenroll_notifylist'}))) {
1.398 raeburn 9566: my %selfdescs = &Apache::lonuserutils::selfenroll_default_descs();
1.276 raeburn 9567: my ($newval,$newnotify);
9568: if (exists($changes{'internal.selfenroll_notifylist'})) {
9569: $newnotify = $changes{'internal.selfenroll_notifylist'};
9570: } else {
1.398 raeburn 9571: $newnotify = $currsettings->{'selfenroll_notifylist'};
1.276 raeburn 9572: }
1.398 raeburn 9573: if (exists($changes{'internal.selfenroll_approval'})) {
9574: if ($changes{'internal.selfenroll_approval'} !~ /^[012]$/) {
9575: $changes{'internal.selfenroll_approval'} = '0';
9576: }
9577: $newval = $selfdescs{'approval'}{$changes{'internal.selfenroll_approval'}};
1.276 raeburn 9578: } else {
1.398 raeburn 9579: my $currapproval = $currsettings->{'selfenroll_approval'};
9580: if ($currapproval !~ /^[012]$/) {
9581: $currapproval = 0;
1.276 raeburn 9582: }
1.398 raeburn 9583: $newval = $selfdescs{'approval'}{$currapproval};
1.276 raeburn 9584: }
9585: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval));
9586: if ($newnotify) {
1.277 raeburn 9587: $r->print('<br />'.&mt('The following will be notified when an enrollment request needs approval, or has been approved: [_1].',$newnotify));
1.276 raeburn 9588: } else {
1.277 raeburn 9589: $r->print('<br />'.&mt('No notifications sent when an enrollment request needs approval, or has been approved.'));
1.276 raeburn 9590: }
9591: $r->print('</li>'."\n");
9592: }
1.237 raeburn 9593: } else {
9594: if (exists($changes{'internal.selfenroll_'.$item})) {
1.241 raeburn 9595: my $newval = $changes{'internal.selfenroll_'.$item};
9596: if ($item eq 'types') {
9597: if ($newval eq '') {
9598: $newval = &mt('None');
9599: } elsif ($newval eq '*') {
9600: $newval = &mt('Any user in any domain');
9601: }
1.245 raeburn 9602: } elsif ($item eq 'registered') {
9603: if ($newval eq '1') {
9604: $newval = &mt('Yes');
9605: } elsif ($newval eq '0') {
9606: $newval = &mt('No');
9607: }
1.241 raeburn 9608: }
1.244 bisitz 9609: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval).'</li>'."\n");
1.237 raeburn 9610: }
9611: }
9612: }
9613: $r->print('</ul>');
1.398 raeburn 9614: if ($env{'course.'.$cid.'.description'} ne '') {
9615: my %newenvhash;
9616: foreach my $key (keys(%changes)) {
9617: $newenvhash{'course.'.$cid.'.'.$key} = $changes{$key};
9618: }
9619: &Apache::lonnet::appenv(\%newenvhash);
1.237 raeburn 9620: }
9621: } else {
1.398 raeburn 9622: $r->print(&mt('An error occurred when saving changes to self-enrollment settings in this course.').'<br />'.
9623: &mt('The error was: [_1].',$putresult));
1.237 raeburn 9624: }
9625: } else {
1.249 raeburn 9626: $r->print(&mt('No changes were made to the existing self-enrollment settings in this course.'));
1.237 raeburn 9627: }
9628: } else {
1.249 raeburn 9629: $r->print(&mt('No changes were made to the existing self-enrollment settings in this course.'));
1.241 raeburn 9630: }
1.400 raeburn 9631: my $visactions = &cat_visibility();
9632: my ($cathash,%cattype);
9633: my %domconfig = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom);
9634: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
9635: $cathash = $domconfig{'coursecategories'}{'cats'};
9636: $cattype{'auth'} = $domconfig{'coursecategories'}{'auth'};
9637: $cattype{'unauth'} = $domconfig{'coursecategories'}{'unauth'};
9638: } else {
9639: $cathash = {};
9640: $cattype{'auth'} = 'std';
9641: $cattype{'unauth'} = 'std';
9642: }
9643: if (($cattype{'auth'} eq 'none') && ($cattype{'unauth'} eq 'none')) {
9644: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
9645: '<br />'.
9646: '<br />'.$visactions->{'take'}.'<ul>'.
9647: '<li>'.$visactions->{'dc_chgconf'}.'</li>'.
9648: '</ul>');
9649: } elsif (($cattype{'auth'} !~ /^(std|domonly)$/) && ($cattype{'unauth'} !~ /^(std|domonly)$/)) {
9650: if ($currsettings->{'uniquecode'}) {
9651: $r->print('<span class="LC_info">'.$visactions->{'vis'}.'</span>');
9652: } else {
1.366 bisitz 9653: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
1.400 raeburn 9654: '<br />'.
9655: '<br />'.$visactions->{'take'}.'<ul>'.
9656: '<li>'.$visactions->{'dc_setcode'}.'</li>'.
9657: '</ul><br />');
9658: }
9659: } else {
9660: my ($visible,$cansetvis,$vismsgs) = &visible_in_stdcat($cdom,$cnum,\%domconfig);
9661: if (ref($visactions) eq 'HASH') {
9662: if (!$visible) {
9663: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
9664: '<br />');
9665: if (ref($vismsgs) eq 'ARRAY') {
9666: $r->print('<br />'.$visactions->{'take'}.'<ul>');
9667: foreach my $item (@{$vismsgs}) {
9668: $r->print('<li>'.$visactions->{$item}.'</li>');
9669: }
9670: $r->print('</ul>');
1.256 raeburn 9671: }
1.400 raeburn 9672: $r->print($cansetvis);
1.256 raeburn 9673: }
9674: }
9675: }
1.237 raeburn 9676: return;
9677: }
9678:
1.27 matthew 9679: #---------------------------------------------- end functions for &phase_two
1.29 matthew 9680:
9681: #--------------------------------- functions for &phase_two and &phase_three
9682:
9683: #--------------------------end of functions for &phase_two and &phase_three
1.372 raeburn 9684:
1.1 www 9685: 1;
9686: __END__
1.2 www 9687:
9688:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>