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