Annotation of loncom/interface/loncreateuser.pm, revision 1.464
1.20 harris41 1: # The LearningOnline Network with CAPA
1.1 www 2: # Create a user
3: #
1.464 ! raeburn 4: # $Id: loncreateuser.pm,v 1.463 2022/11/16 14:24:35 raeburn Exp $
1.22 albertel 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
1.20 harris41 28: ###
29:
1.1 www 30: package Apache::loncreateuser;
1.66 bowersj2 31:
32: =pod
33:
34: =head1 NAME
35:
1.263 jms 36: Apache::loncreateuser.pm
1.66 bowersj2 37:
38: =head1 SYNOPSIS
39:
1.263 jms 40: Handler to create users and custom roles
41:
42: Provides an Apache handler for creating users,
1.66 bowersj2 43: editing their login parameters, roles, and removing roles, and
44: also creating and assigning custom roles.
45:
46: =head1 OVERVIEW
47:
48: =head2 Custom Roles
49:
50: In LON-CAPA, roles are actually collections of privileges. "Teaching
51: Assistant", "Course Coordinator", and other such roles are really just
52: collection of privileges that are useful in many circumstances.
53:
1.324 raeburn 54: Custom roles can be defined by a Domain Coordinator, Course Coordinator
55: or Community Coordinator via the Manage User functionality.
56: The custom role editor screen will show all privileges which can be
57: assigned to users. For a complete list of privileges, please see
58: C</home/httpd/lonTabs/rolesplain.tab>.
1.66 bowersj2 59:
1.324 raeburn 60: Custom role definitions are stored in the C<roles.db> file of the creator
61: of the role.
1.66 bowersj2 62:
63: =cut
1.1 www 64:
65: use strict;
66: use Apache::Constants qw(:common :http);
67: use Apache::lonnet;
1.54 bowersj2 68: use Apache::loncommon;
1.68 www 69: use Apache::lonlocal;
1.117 raeburn 70: use Apache::longroup;
1.190 raeburn 71: use Apache::lonuserutils;
1.307 raeburn 72: use Apache::loncoursequeueadmin;
1.139 albertel 73: use LONCAPA qw(:DEFAULT :match);
1.456 raeburn 74: use HTML::Entities;
1.1 www 75:
1.20 harris41 76: my $loginscript; # piece of javascript used in two separate instances
77: my $authformnop;
78: my $authformkrb;
79: my $authformint;
80: my $authformfsys;
81: my $authformloc;
1.449 raeburn 82: my $authformlti;
1.20 harris41 83:
1.94 matthew 84: sub initialize_authen_forms {
1.227 raeburn 85: my ($dom,$formname,$curr_authtype,$mode) = @_;
86: my ($krbdef,$krbdefdom) = &Apache::loncommon::get_kerberos_defaults($dom);
87: my %param = ( formname => $formname,
1.187 raeburn 88: kerb_def_dom => $krbdefdom,
1.227 raeburn 89: kerb_def_auth => $krbdef,
1.187 raeburn 90: domain => $dom,
91: );
1.188 raeburn 92: my %abv_auth = &auth_abbrev();
1.449 raeburn 93: if ($curr_authtype =~ /^(krb4|krb5|internal|localauth|unix|lti):(.*)$/) {
1.188 raeburn 94: my $long_auth = $1;
1.227 raeburn 95: my $curr_autharg = $2;
1.188 raeburn 96: my %abv_auth = &auth_abbrev();
97: $param{'curr_authtype'} = $abv_auth{$long_auth};
98: if ($long_auth =~ /^krb(4|5)$/) {
99: $param{'curr_kerb_ver'} = $1;
1.227 raeburn 100: $param{'curr_autharg'} = $curr_autharg;
1.188 raeburn 101: }
1.205 raeburn 102: if ($mode eq 'modifyuser') {
103: $param{'mode'} = $mode;
104: }
1.187 raeburn 105: }
1.227 raeburn 106: $loginscript = &Apache::loncommon::authform_header(%param);
107: $authformkrb = &Apache::loncommon::authform_kerberos(%param);
1.31 matthew 108: $authformnop = &Apache::loncommon::authform_nochange(%param);
109: $authformint = &Apache::loncommon::authform_internal(%param);
110: $authformfsys = &Apache::loncommon::authform_filesystem(%param);
111: $authformloc = &Apache::loncommon::authform_local(%param);
1.449 raeburn 112: $authformlti = &Apache::loncommon::authform_lti(%param);
1.20 harris41 113: }
114:
1.188 raeburn 115: sub auth_abbrev {
116: my %abv_auth = (
1.368 raeburn 117: krb5 => 'krb',
118: krb4 => 'krb',
119: internal => 'int',
120: localauth => 'loc',
121: unix => 'fsys',
1.449 raeburn 122: lti => 'lti',
1.188 raeburn 123: );
124: return %abv_auth;
125: }
1.43 www 126:
1.134 raeburn 127: # ====================================================
128:
1.378 raeburn 129: sub user_quotas {
1.134 raeburn 130: my ($ccuname,$ccdomain) = @_;
131: my %lt = &Apache::lonlocal::texthash(
1.267 raeburn 132: 'usrt' => "User Tools",
133: 'cust' => "Custom quota",
134: 'chqu' => "Change quota",
1.134 raeburn 135: );
1.378 raeburn 136:
1.149 raeburn 137: my $quota_javascript = <<"END_SCRIPT";
138: <script type="text/javascript">
1.301 bisitz 139: // <![CDATA[
1.378 raeburn 140: function quota_changes(caller,context) {
141: var customoff = document.getElementById('custom_'+context+'quota_off');
142: var customon = document.getElementById('custom_'+context+'quota_on');
143: var number = document.getElementById(context+'quota');
1.149 raeburn 144: if (caller == "custom") {
1.378 raeburn 145: if (customoff) {
146: if (customoff.checked) {
147: number.value = "";
148: }
1.149 raeburn 149: }
150: }
151: if (caller == "quota") {
1.378 raeburn 152: if (customon) {
153: customon.checked = true;
154: }
1.149 raeburn 155: }
1.378 raeburn 156: return;
1.149 raeburn 157: }
1.301 bisitz 158: // ]]>
1.149 raeburn 159: </script>
160: END_SCRIPT
1.378 raeburn 161: my $longinsttype;
162: my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($ccdomain);
1.267 raeburn 163: my $output = $quota_javascript."\n".
164: '<h3>'.$lt{'usrt'}.'</h3>'."\n".
165: &Apache::loncommon::start_data_table();
166:
1.418 raeburn 167: if ((&Apache::lonnet::allowed('mut',$ccdomain)) ||
168: (&Apache::lonnet::allowed('udp',$ccdomain))) {
1.275 raeburn 169: $output .= &build_tools_display($ccuname,$ccdomain,'tools');
1.267 raeburn 170: }
1.378 raeburn 171:
172: my %titles = &Apache::lonlocal::texthash (
173: portfolio => "Disk space allocated to user's portfolio files",
1.385 bisitz 174: author => "Disk space allocated to user's Authoring Space (if role assigned)",
1.378 raeburn 175: );
176: foreach my $name ('portfolio','author') {
177: my ($currquota,$quotatype,$inststatus,$defquota) =
178: &Apache::loncommon::get_user_quota($ccuname,$ccdomain,$name);
179: if ($longinsttype eq '') {
180: if ($inststatus ne '') {
181: if ($usertypes->{$inststatus} ne '') {
182: $longinsttype = $usertypes->{$inststatus};
183: }
184: }
185: }
186: my ($showquota,$custom_on,$custom_off,$defaultinfo);
187: $custom_on = ' ';
188: $custom_off = ' checked="checked" ';
189: if ($quotatype eq 'custom') {
190: $custom_on = $custom_off;
191: $custom_off = ' ';
192: $showquota = $currquota;
193: if ($longinsttype eq '') {
194: $defaultinfo = &mt('For this user, the default quota would be [_1]'
1.383 raeburn 195: .' MB.',$defquota);
1.378 raeburn 196: } else {
197: $defaultinfo = &mt("For this user, the default quota would be [_1]".
1.383 raeburn 198: " MB, as determined by the user's institutional".
1.378 raeburn 199: " affiliation ([_2]).",$defquota,$longinsttype);
200: }
201: } else {
202: if ($longinsttype eq '') {
203: $defaultinfo = &mt('For this user, the default quota is [_1]'
1.383 raeburn 204: .' MB.',$defquota);
1.378 raeburn 205: } else {
206: $defaultinfo = &mt("For this user, the default quota of [_1]".
1.383 raeburn 207: " MB, is determined by the user's institutional".
1.378 raeburn 208: " affiliation ([_2]).",$defquota,$longinsttype);
209: }
210: }
211:
212: if (&Apache::lonnet::allowed('mpq',$ccdomain)) {
213: $output .= '<tr class="LC_info_row">'."\n".
214: ' <td>'.$titles{$name}.'</td>'."\n".
215: ' </tr>'."\n".
216: &Apache::loncommon::start_data_table_row()."\n".
1.390 bisitz 217: ' <td><span class="LC_nobreak">'.
218: &mt('Current quota: [_1] MB',$currquota).'</span> '.
1.378 raeburn 219: $defaultinfo.'</td>'."\n".
220: &Apache::loncommon::end_data_table_row()."\n".
221: &Apache::loncommon::start_data_table_row()."\n".
222: ' <td><span class="LC_nobreak">'.$lt{'chqu'}.
223: ': <label>'.
224: '<input type="radio" name="custom_'.$name.'quota" id="custom_'.$name.'quota_off" '.
1.379 raeburn 225: 'value="0" '.$custom_off.' onchange="javascript:quota_changes('."'custom','$name'".');"'.
1.390 bisitz 226: ' /><span class="LC_nobreak">'.
227: &mt('Default ([_1] MB)',$defquota).'</span></label> '.
1.378 raeburn 228: ' <label><input type="radio" name="custom_'.$name.'quota" id="custom_'.$name.'quota_on" '.
1.379 raeburn 229: 'value="1" '.$custom_on.' onchange="javascript:quota_changes('."'custom','$name'".');"'.
1.378 raeburn 230: ' />'.$lt{'cust'}.':</label> '.
1.379 raeburn 231: '<input type="text" name="'.$name.'quota" id="'.$name.'quota" size ="5" '.
232: 'value="'.$showquota.'" onfocus="javascript:quota_changes('."'quota','$name'".');"'.
1.390 bisitz 233: ' /> '.&mt('MB').'</span></td>'."\n".
1.378 raeburn 234: &Apache::loncommon::end_data_table_row()."\n";
235: }
236: }
1.267 raeburn 237: $output .= &Apache::loncommon::end_data_table();
1.134 raeburn 238: return $output;
239: }
240:
1.275 raeburn 241: sub build_tools_display {
242: my ($ccuname,$ccdomain,$context) = @_;
1.306 raeburn 243: my (@usertools,%userenv,$output,@options,%validations,%reqtitles,%reqdisplay,
1.332 raeburn 244: $colspan,$isadv,%domconfig);
1.275 raeburn 245: my %lt = &Apache::lonlocal::texthash (
246: 'blog' => "Personal User Blog",
247: 'aboutme' => "Personal Information Page",
1.385 bisitz 248: 'webdav' => "WebDAV access to Authoring Spaces (if SSL and author/co-author)",
1.275 raeburn 249: 'portfolio' => "Personal User Portfolio",
1.459 raeburn 250: 'timezone' => "Can set Time Zone",
1.275 raeburn 251: 'avai' => "Available",
252: 'cusa' => "availability",
253: 'chse' => "Change setting",
254: 'usde' => "Use default",
255: 'uscu' => "Use custom",
256: 'official' => 'Can request creation of official courses',
1.299 raeburn 257: 'unofficial' => 'Can request creation of unofficial courses',
258: 'community' => 'Can request creation of communities',
1.384 raeburn 259: 'textbook' => 'Can request creation of textbook courses',
1.411 raeburn 260: 'placement' => 'Can request creation of placement tests',
1.449 raeburn 261: 'lti' => 'Can request creation of LTI courses',
1.362 raeburn 262: 'requestauthor' => 'Can request author space',
1.275 raeburn 263: );
1.462 raeburn 264: $isadv = &Apache::lonnet::is_advanced_user($ccdomain,$ccuname);
1.279 raeburn 265: if ($context eq 'requestcourses') {
1.275 raeburn 266: %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
1.299 raeburn 267: 'requestcourses.official','requestcourses.unofficial',
1.411 raeburn 268: 'requestcourses.community','requestcourses.textbook',
1.449 raeburn 269: 'requestcourses.placement','requestcourses.lti');
270: @usertools = ('official','unofficial','community','textbook','placement','lti');
1.309 raeburn 271: @options =('norequest','approval','autolimit','validate');
1.306 raeburn 272: %validations = &Apache::lonnet::auto_courserequest_checks($ccdomain);
273: %reqtitles = &courserequest_titles();
274: %reqdisplay = &courserequest_display();
275: $colspan = ' colspan="2"';
1.332 raeburn 276: %domconfig =
277: &Apache::lonnet::get_dom('configuration',['requestcourses'],$ccdomain);
1.362 raeburn 278: } elsif ($context eq 'requestauthor') {
279: %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
280: 'requestauthor');
281: @usertools = ('requestauthor');
282: @options =('norequest','approval','automatic');
283: %reqtitles = &requestauthor_titles();
284: %reqdisplay = &requestauthor_display();
285: $colspan = ' colspan="2"';
286: %domconfig =
287: &Apache::lonnet::get_dom('configuration',['requestauthor'],$ccdomain);
1.275 raeburn 288: } else {
289: %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
1.361 raeburn 290: 'tools.aboutme','tools.portfolio','tools.blog',
1.459 raeburn 291: 'tools.webdav','tools.timezone');
292: @usertools = ('aboutme','blog','webdav','portfolio','timezone');
1.275 raeburn 293: }
294: foreach my $item (@usertools) {
1.306 raeburn 295: my ($custom_access,$curr_access,$cust_on,$cust_off,$tool_on,$tool_off,
296: $currdisp,$custdisp,$custradio);
1.275 raeburn 297: $cust_off = 'checked="checked" ';
298: $tool_on = 'checked="checked" ';
1.463 raeburn 299: $curr_access =
1.275 raeburn 300: &Apache::lonnet::usertools_access($ccuname,$ccdomain,$item,undef,
1.462 raeburn 301: $context,\%userenv,'',
302: {'is_adv' => $isadv});
1.362 raeburn 303: if ($context eq 'requestauthor') {
304: if ($userenv{$context} ne '') {
305: $cust_on = ' checked="checked" ';
306: $cust_off = '';
307: }
308: } elsif ($userenv{$context.'.'.$item} ne '') {
1.306 raeburn 309: $cust_on = ' checked="checked" ';
310: $cust_off = '';
311: }
312: if ($context eq 'requestcourses') {
313: if ($userenv{$context.'.'.$item} eq '') {
1.314 raeburn 314: $custom_access = &mt('Currently from default setting.');
1.306 raeburn 315: } else {
316: $custom_access = &mt('Currently from custom setting.');
1.275 raeburn 317: }
1.362 raeburn 318: } elsif ($context eq 'requestauthor') {
319: if ($userenv{$context} eq '') {
320: $custom_access = &mt('Currently from default setting.');
321: } else {
322: $custom_access = &mt('Currently from custom setting.');
323: }
1.275 raeburn 324: } else {
1.306 raeburn 325: if ($userenv{$context.'.'.$item} eq '') {
1.314 raeburn 326: $custom_access =
1.306 raeburn 327: &mt('Availability determined currently from default setting.');
328: if (!$curr_access) {
329: $tool_off = 'checked="checked" ';
330: $tool_on = '';
331: }
332: } else {
1.314 raeburn 333: $custom_access =
1.306 raeburn 334: &mt('Availability determined currently from custom setting.');
335: if ($userenv{$context.'.'.$item} == 0) {
336: $tool_off = 'checked="checked" ';
337: $tool_on = '';
338: }
1.275 raeburn 339: }
340: }
341: $output .= ' <tr class="LC_info_row">'."\n".
1.306 raeburn 342: ' <td'.$colspan.'>'.$lt{$item}.'</td>'."\n".
1.275 raeburn 343: ' </tr>'."\n".
1.306 raeburn 344: &Apache::loncommon::start_data_table_row()."\n";
1.418 raeburn 345:
1.362 raeburn 346: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.306 raeburn 347: my ($curroption,$currlimit);
1.362 raeburn 348: my $envkey = $context.'.'.$item;
349: if ($context eq 'requestauthor') {
350: $envkey = $context;
351: }
352: if ($userenv{$envkey} ne '') {
353: $curroption = $userenv{$envkey};
1.332 raeburn 354: } else {
355: my (@inststatuses);
1.362 raeburn 356: if ($context eq 'requestcourses') {
357: $curroption =
358: &Apache::loncoursequeueadmin::get_processtype('course',$ccuname,$ccdomain,
359: $isadv,$ccdomain,$item,
360: \@inststatuses,\%domconfig);
361: } else {
362: $curroption =
363: &Apache::loncoursequeueadmin::get_processtype('requestauthor',$ccuname,$ccdomain,
364: $isadv,$ccdomain,undef,
365: \@inststatuses,\%domconfig);
366: }
1.332 raeburn 367: }
1.306 raeburn 368: if (!$curroption) {
369: $curroption = 'norequest';
370: }
371: if ($curroption =~ /^autolimit=(\d*)$/) {
372: $currlimit = $1;
1.314 raeburn 373: if ($currlimit eq '') {
374: $currdisp = &mt('Yes, automatic creation');
375: } else {
376: $currdisp = &mt('Yes, up to [quant,_1,request]/user',$currlimit);
377: }
1.306 raeburn 378: } else {
379: $currdisp = $reqdisplay{$curroption};
380: }
381: $custdisp = '<table>';
382: foreach my $option (@options) {
383: my $val = $option;
384: if ($option eq 'norequest') {
385: $val = 0;
386: }
387: if ($option eq 'validate') {
388: my $canvalidate = 0;
389: if (ref($validations{$item}) eq 'HASH') {
390: if ($validations{$item}{'_custom_'}) {
391: $canvalidate = 1;
392: }
393: }
394: next if (!$canvalidate);
395: }
396: my $checked = '';
397: if ($option eq $curroption) {
398: $checked = ' checked="checked"';
399: } elsif ($option eq 'autolimit') {
400: if ($curroption =~ /^autolimit/) {
401: $checked = ' checked="checked"';
402: }
403: }
1.362 raeburn 404: my $name = 'crsreq_'.$item;
405: if ($context eq 'requestauthor') {
406: $name = $item;
407: }
1.306 raeburn 408: $custdisp .= '<tr><td><span class="LC_nobreak"><label>'.
1.362 raeburn 409: '<input type="radio" name="'.$name.'" '.
410: 'value="'.$val.'"'.$checked.' />'.
1.306 raeburn 411: $reqtitles{$option}.'</label> ';
412: if ($option eq 'autolimit') {
1.362 raeburn 413: $custdisp .= '<input type="text" name="'.$name.
414: '_limit" size="1" '.
1.314 raeburn 415: 'value="'.$currlimit.'" /></span><br />'.
416: $reqtitles{'unlimited'};
1.362 raeburn 417: } else {
418: $custdisp .= '</span>';
419: }
420: $custdisp .= '</td></tr>';
1.306 raeburn 421: }
422: $custdisp .= '</table>';
423: $custradio = '</span></td><td>'.&mt('Custom setting').'<br />'.$custdisp;
424: } else {
425: $currdisp = ($curr_access?&mt('Yes'):&mt('No'));
1.362 raeburn 426: my $name = $context.'_'.$item;
427: if ($context eq 'requestauthor') {
428: $name = $context;
429: }
1.306 raeburn 430: $custdisp = '<span class="LC_nobreak"><label>'.
1.362 raeburn 431: '<input type="radio" name="'.$name.'"'.
1.361 raeburn 432: ' value="1" '.$tool_on.'/>'.&mt('On').'</label> <label>'.
1.362 raeburn 433: '<input type="radio" name="'.$name.'" value="0" '.
1.306 raeburn 434: $tool_off.'/>'.&mt('Off').'</label></span>';
435: $custradio = (' 'x2).'--'.$lt{'cusa'}.': '.$custdisp.
436: '</span>';
437: }
438: $output .= ' <td'.$colspan.'>'.$custom_access.(' 'x4).
1.419 raeburn 439: $lt{'avai'}.': '.$currdisp.'</td>'."\n".
1.418 raeburn 440: &Apache::loncommon::end_data_table_row()."\n";
441: unless (&Apache::lonnet::allowed('udp',$ccdomain)) {
442: $output .=
1.275 raeburn 443: &Apache::loncommon::start_data_table_row()."\n".
1.306 raeburn 444: ' <td style="vertical-align:top;"><span class="LC_nobreak">'.
445: $lt{'chse'}.': <label>'.
1.275 raeburn 446: '<input type="radio" name="custom'.$item.'" value="0" '.
1.306 raeburn 447: $cust_off.'/>'.$lt{'usde'}.'</label>'.(' ' x3).
448: '<label><input type="radio" name="custom'.$item.'" value="1" '.
449: $cust_on.'/>'.$lt{'uscu'}.'</label>'.$custradio.'</td>'.
1.275 raeburn 450: &Apache::loncommon::end_data_table_row()."\n";
1.418 raeburn 451: }
1.275 raeburn 452: }
453: return $output;
454: }
455:
1.300 raeburn 456: sub coursereq_externaluser {
457: my ($ccuname,$ccdomain,$cdom) = @_;
1.306 raeburn 458: my (@usertools,@options,%validations,%userenv,$output);
1.300 raeburn 459: my %lt = &Apache::lonlocal::texthash (
460: 'official' => 'Can request creation of official courses',
461: 'unofficial' => 'Can request creation of unofficial courses',
462: 'community' => 'Can request creation of communities',
1.384 raeburn 463: 'textbook' => 'Can request creation of textbook courses',
1.411 raeburn 464: 'placement' => 'Can request creation of placement tests',
1.300 raeburn 465: );
466:
467: %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
468: 'reqcrsotherdom.official','reqcrsotherdom.unofficial',
1.411 raeburn 469: 'reqcrsotherdom.community','reqcrsotherdom.textbook',
470: 'reqcrsotherdom.placement');
471: @usertools = ('official','unofficial','community','textbook','placement');
1.309 raeburn 472: @options = ('approval','validate','autolimit');
1.306 raeburn 473: %validations = &Apache::lonnet::auto_courserequest_checks($cdom);
474: my $optregex = join('|',@options);
475: my %reqtitles = &courserequest_titles();
1.300 raeburn 476: foreach my $item (@usertools) {
1.306 raeburn 477: my ($curroption,$currlimit,$tooloff);
1.300 raeburn 478: if ($userenv{'reqcrsotherdom.'.$item} ne '') {
479: my @curr = split(',',$userenv{'reqcrsotherdom.'.$item});
1.314 raeburn 480: foreach my $req (@curr) {
481: if ($req =~ /^\Q$cdom\E\:($optregex)=?(\d*)$/) {
482: $curroption = $1;
483: $currlimit = $2;
484: last;
1.306 raeburn 485: }
486: }
1.314 raeburn 487: if (!$curroption) {
488: $curroption = 'norequest';
489: $tooloff = ' checked="checked"';
490: }
1.306 raeburn 491: } else {
492: $curroption = 'norequest';
493: $tooloff = ' checked="checked"';
494: }
495: $output.= &Apache::loncommon::start_data_table_row()."\n".
1.314 raeburn 496: ' <td><span class="LC_nobreak">'.$lt{$item}.': </span></td><td>'.
497: '<table><tr><td valign="top">'."\n".
1.306 raeburn 498: '<label><input type="radio" name="reqcrsotherdom_'.$item.
1.314 raeburn 499: '" value=""'.$tooloff.' />'.$reqtitles{'norequest'}.
500: '</label></td>';
1.306 raeburn 501: foreach my $option (@options) {
502: if ($option eq 'validate') {
503: my $canvalidate = 0;
504: if (ref($validations{$item}) eq 'HASH') {
505: if ($validations{$item}{'_external_'}) {
506: $canvalidate = 1;
507: }
508: }
509: next if (!$canvalidate);
510: }
511: my $checked = '';
512: if ($option eq $curroption) {
513: $checked = ' checked="checked"';
514: }
1.314 raeburn 515: $output .= '<td valign="top"><span class="LC_nobreak"><label>'.
1.306 raeburn 516: '<input type="radio" name="reqcrsotherdom_'.$item.
517: '" value="'.$option.'"'.$checked.' />'.
1.314 raeburn 518: $reqtitles{$option}.'</label>';
1.306 raeburn 519: if ($option eq 'autolimit') {
1.314 raeburn 520: $output .= ' <input type="text" name="reqcrsotherdom_'.
1.306 raeburn 521: $item.'_limit" size="1" '.
1.314 raeburn 522: 'value="'.$currlimit.'" /></span>'.
523: '<br />'.$reqtitles{'unlimited'};
524: } else {
525: $output .= '</span>';
1.300 raeburn 526: }
1.314 raeburn 527: $output .= '</td>';
1.300 raeburn 528: }
1.314 raeburn 529: $output .= '</td></tr></table></td>'."\n".
1.300 raeburn 530: &Apache::loncommon::end_data_table_row()."\n";
531: }
532: return $output;
533: }
534:
1.362 raeburn 535: sub domainrole_req {
536: my ($ccuname,$ccdomain) = @_;
537: return '<br /><h3>'.
538: &mt('User Can Request Assignment of Domain Roles?').
539: '</h3>'."\n".
540: &Apache::loncommon::start_data_table().
541: &build_tools_display($ccuname,$ccdomain,
542: 'requestauthor').
543: &Apache::loncommon::end_data_table();
544: }
545:
1.306 raeburn 546: sub courserequest_titles {
547: my %titles = &Apache::lonlocal::texthash (
548: official => 'Official',
549: unofficial => 'Unofficial',
550: community => 'Communities',
1.384 raeburn 551: textbook => 'Textbook',
1.411 raeburn 552: placement => 'Placement Tests',
1.449 raeburn 553: lti => 'LTI Provider',
1.306 raeburn 554: norequest => 'Not allowed',
1.309 raeburn 555: approval => 'Approval by Dom. Coord.',
1.306 raeburn 556: validate => 'With validation',
557: autolimit => 'Numerical limit',
1.314 raeburn 558: unlimited => '(blank for unlimited)',
1.306 raeburn 559: );
560: return %titles;
561: }
562:
563: sub courserequest_display {
564: my %titles = &Apache::lonlocal::texthash (
1.309 raeburn 565: approval => 'Yes, need approval',
1.306 raeburn 566: validate => 'Yes, with validation',
567: norequest => 'No',
568: );
569: return %titles;
570: }
571:
1.362 raeburn 572: sub requestauthor_titles {
573: my %titles = &Apache::lonlocal::texthash (
574: norequest => 'Not allowed',
575: approval => 'Approval by Dom. Coord.',
576: automatic => 'Automatic approval',
577: );
578: return %titles;
579:
580: }
581:
582: sub requestauthor_display {
583: my %titles = &Apache::lonlocal::texthash (
584: approval => 'Yes, need approval',
585: automatic => 'Yes, automatic approval',
586: norequest => 'No',
587: );
588: return %titles;
589: }
590:
1.383 raeburn 591: sub requestchange_display {
592: my %titles = &Apache::lonlocal::texthash (
593: approval => "availability set to 'on' (approval required)",
594: automatic => "availability set to 'on' (automatic approval)",
595: norequest => "availability set to 'off'",
596: );
597: return %titles;
598: }
599:
1.362 raeburn 600: sub curr_requestauthor {
601: my ($uname,$udom,$isadv,$inststatuses,$domconfig) = @_;
602: return unless ((ref($inststatuses) eq 'ARRAY') && (ref($domconfig) eq 'HASH'));
603: if ($uname eq '' || $udom eq '') {
604: $uname = $env{'user.name'};
605: $udom = $env{'user.domain'};
606: $isadv = $env{'user.adv'};
607: }
608: my (%userenv,%settings,$val);
609: my @options = ('automatic','approval');
610: %userenv =
611: &Apache::lonnet::userenvironment($udom,$uname,'requestauthor','inststatus');
612: if ($userenv{'requestauthor'}) {
613: $val = $userenv{'requestauthor'};
614: @{$inststatuses} = ('_custom_');
615: } else {
616: my %alltasks;
617: if (ref($domconfig->{'requestauthor'}) eq 'HASH') {
618: %settings = %{$domconfig->{'requestauthor'}};
619: if (($isadv) && ($settings{'_LC_adv'} ne '')) {
620: $val = $settings{'_LC_adv'};
621: @{$inststatuses} = ('_LC_adv_');
622: } else {
623: if ($userenv{'inststatus'} ne '') {
624: @{$inststatuses} = split(',',$userenv{'inststatus'});
625: } else {
626: @{$inststatuses} = ('default');
627: }
628: foreach my $status (@{$inststatuses}) {
629: if (exists($settings{$status})) {
630: my $value = $settings{$status};
631: next unless ($value);
632: unless (exists($alltasks{$value})) {
633: if (ref($alltasks{$value}) eq 'ARRAY') {
634: unless(grep(/^\Q$status\E$/,@{$alltasks{$value}})) {
635: push(@{$alltasks{$value}},$status);
636: }
637: } else {
638: @{$alltasks{$value}} = ($status);
639: }
640: }
641: }
642: }
643: foreach my $option (@options) {
644: if ($alltasks{$option}) {
645: $val = $option;
646: last;
647: }
648: }
649: }
650: }
651: }
652: return $val;
653: }
654:
1.2 www 655: # =================================================================== Phase one
1.1 www 656:
1.42 matthew 657: sub print_username_entry_form {
1.439 raeburn 658: my ($r,$context,$response,$srch,$forcenewuser,$crstype,$brcrum,
659: $permission) = @_;
1.101 albertel 660: my $defdom=$env{'request.role.domain'};
1.160 raeburn 661: my $formtoset = 'crtuser';
662: if (exists($env{'form.startrolename'})) {
663: $formtoset = 'docustom';
664: $env{'form.rolename'} = $env{'form.startrolename'};
1.207 raeburn 665: } elsif ($env{'form.origform'} eq 'crtusername') {
666: $formtoset = $env{'form.origform'};
1.160 raeburn 667: }
668:
669: my ($jsback,$elements) = &crumb_utilities();
670:
671: my $jscript = &Apache::loncommon::studentbrowser_javascript()."\n".
1.165 albertel 672: '<script type="text/javascript">'."\n".
1.301 bisitz 673: '// <![CDATA['."\n".
674: &Apache::lonhtmlcommon::set_form_elements($elements->{$formtoset})."\n".
675: '// ]]>'."\n".
1.162 raeburn 676: '</script>'."\n";
1.160 raeburn 677:
1.324 raeburn 678: my %existingroles=&Apache::lonuserutils::my_custom_roles($crstype);
679: if (($env{'form.action'} eq 'custom') && (keys(%existingroles) > 0)
680: && (&Apache::lonnet::allowed('mcr','/'))) {
681: $jscript .= &customrole_javascript();
682: }
1.224 raeburn 683: my $helpitem = 'Course_Change_Privileges';
684: if ($env{'form.action'} eq 'custom') {
1.439 raeburn 685: if ($context eq 'course') {
686: $helpitem = 'Course_Editing_Custom_Roles';
687: } elsif ($context eq 'domain') {
688: $helpitem = 'Domain_Editing_Custom_Roles';
689: }
1.224 raeburn 690: } elsif ($env{'form.action'} eq 'singlestudent') {
691: $helpitem = 'Course_Add_Student';
1.416 raeburn 692: } elsif ($env{'form.action'} eq 'accesslogs') {
693: $helpitem = 'Domain_User_Access_Logs';
1.439 raeburn 694: } elsif ($context eq 'author') {
695: $helpitem = 'Author_Change_Privileges';
696: } elsif ($context eq 'domain') {
697: if ($permission->{'cusr'}) {
698: $helpitem = 'Domain_Change_Privileges';
699: } elsif ($permission->{'view'}) {
700: $helpitem = 'Domain_View_Privileges';
701: } else {
702: undef($helpitem);
703: }
1.224 raeburn 704: }
1.422 raeburn 705: my %breadcrumb_text = &singleuser_breadcrumb($crstype,$context,$defdom);
1.351 raeburn 706: if ($env{'form.action'} eq 'custom') {
707: push(@{$brcrum},
708: {href=>"javascript:backPage(document.crtuser)",
709: text=>"Pick custom role",
710: help => $helpitem,}
711: );
712: } else {
713: push (@{$brcrum},
714: {href => "javascript:backPage(document.crtuser)",
715: text => $breadcrumb_text{'search'},
716: help => $helpitem,
717: faq => 282,
718: bug => 'Instructor Interface',}
719: );
720: }
721: my %loaditems = (
722: 'onload' => "javascript:setFormElements(document.$formtoset)",
723: );
724: my $args = {bread_crumbs => $brcrum,
725: bread_crumbs_component => 'User Management',
726: add_entries => \%loaditems,};
727: $r->print(&Apache::loncommon::start_page('User Management',$jscript,$args));
728:
1.71 sakharuk 729: my %lt=&Apache::lonlocal::texthash(
1.229 raeburn 730: 'srst' => 'Search for a user and enroll as a student',
1.318 raeburn 731: 'srme' => 'Search for a user and enroll as a member',
1.229 raeburn 732: 'srad' => 'Search for a user and modify/add user information or roles',
1.422 raeburn 733: 'srvu' => 'Search for a user and view user information and roles',
1.416 raeburn 734: 'srva' => 'Search for a user and view access log information',
1.71 sakharuk 735: 'usr' => "Username",
736: 'dom' => "Domain",
1.324 raeburn 737: 'ecrp' => "Define or Edit Custom Role",
738: 'nr' => "role name",
1.282 schafran 739: 'cre' => "Next",
1.71 sakharuk 740: );
1.351 raeburn 741:
1.214 raeburn 742: if ($env{'form.action'} eq 'custom') {
1.190 raeburn 743: if (&Apache::lonnet::allowed('mcr','/')) {
1.324 raeburn 744: my $newroletext = &mt('Define new custom role:');
745: $r->print('<form action="/adm/createuser" method="post" name="docustom">'.
746: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'.
747: '<input type="hidden" name="phase" value="selected_custom_edit" />'.
748: '<h3>'.$lt{'ecrp'}.'</h3>'.
749: &Apache::loncommon::start_data_table().
750: &Apache::loncommon::start_data_table_row().
751: '<td>');
752: if (keys(%existingroles) > 0) {
753: $r->print('<br /><label><input type="radio" name="customroleaction" value="new" checked="checked" onclick="setCustomFields();" /><b>'.$newroletext.'</b></label>');
754: } else {
755: $r->print('<br /><input type="hidden" name="customroleaction" value="new" /><b>'.$newroletext.'</b>');
756: }
757: $r->print('</td><td align="center">'.$lt{'nr'}.'<br /><input type="text" size="15" name="newrolename" onfocus="setCustomAction('."'new'".');" /></td>'.
758: &Apache::loncommon::end_data_table_row());
759: if (keys(%existingroles) > 0) {
760: $r->print(&Apache::loncommon::start_data_table_row().'<td><br />'.
761: '<label><input type="radio" name="customroleaction" value="edit" onclick="setCustomFields();"/><b>'.
762: &mt('View/Modify existing role:').'</b></label></td>'.
763: '<td align="center"><br />'.
764: '<select name="rolename" onchange="setCustomAction('."'edit'".');">'.
1.326 raeburn 765: '<option value="" selected="selected">'.
1.324 raeburn 766: &mt('Select'));
767: foreach my $role (sort(keys(%existingroles))) {
1.326 raeburn 768: $r->print('<option value="'.$role.'">'.$role.'</option>');
1.324 raeburn 769: }
770: $r->print('</select>'.
771: '</td>'.
772: &Apache::loncommon::end_data_table_row());
773: }
774: $r->print(&Apache::loncommon::end_data_table().'<p>'.
775: '<input name="customeditor" type="submit" value="'.
776: $lt{'cre'}.'" /></p>'.
777: '</form>');
1.190 raeburn 778: }
1.213 raeburn 779: } else {
1.229 raeburn 780: my $actiontext = $lt{'srad'};
1.436 raeburn 781: my $fixeddom;
1.213 raeburn 782: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 783: if ($crstype eq 'Community') {
784: $actiontext = $lt{'srme'};
785: } else {
786: $actiontext = $lt{'srst'};
787: }
1.416 raeburn 788: } elsif ($env{'form.action'} eq 'accesslogs') {
1.417 raeburn 789: $actiontext = $lt{'srva'};
1.436 raeburn 790: $fixeddom = 1;
1.422 raeburn 791: } elsif (($env{'form.action'} eq 'singleuser') &&
792: ($context eq 'domain') && (!&Apache::lonnet::allowed('mau',$defdom))) {
793: $actiontext = $lt{'srvu'};
1.439 raeburn 794: $fixeddom = 1;
1.213 raeburn 795: }
1.324 raeburn 796: $r->print("<h3>$actiontext</h3>");
1.213 raeburn 797: if ($env{'form.origform'} ne 'crtusername') {
1.415 raeburn 798: if ($response) {
799: $r->print("\n<div>$response</div>".
800: '<br clear="all" />');
801: }
1.213 raeburn 802: }
1.436 raeburn 803: $r->print(&entry_form($defdom,$srch,$forcenewuser,$context,$response,$crstype,$fixeddom));
1.107 www 804: }
1.110 albertel 805: }
806:
1.324 raeburn 807: sub customrole_javascript {
808: my $js = <<"END";
809: <script type="text/javascript">
810: // <![CDATA[
811:
812: function setCustomFields() {
813: if (document.docustom.customroleaction.length > 0) {
814: for (var i=0; i<document.docustom.customroleaction.length; i++) {
815: if (document.docustom.customroleaction[i].checked) {
816: if (document.docustom.customroleaction[i].value == 'new') {
817: document.docustom.rolename.selectedIndex = 0;
818: } else {
819: document.docustom.newrolename.value = '';
820: }
821: }
822: }
823: }
824: return;
825: }
826:
827: function setCustomAction(caller) {
828: if (document.docustom.customroleaction.length > 0) {
829: for (var i=0; i<document.docustom.customroleaction.length; i++) {
830: if (document.docustom.customroleaction[i].value == caller) {
831: document.docustom.customroleaction[i].checked = true;
832: }
833: }
834: }
835: setCustomFields();
836: return;
837: }
838:
839: // ]]>
840: </script>
841: END
842: return $js;
843: }
844:
1.160 raeburn 845: sub entry_form {
1.416 raeburn 846: my ($dom,$srch,$forcenewuser,$context,$responsemsg,$crstype,$fixeddom) = @_;
1.229 raeburn 847: my ($usertype,$inexact);
1.214 raeburn 848: if (ref($srch) eq 'HASH') {
849: if (($srch->{'srchin'} eq 'dom') &&
850: ($srch->{'srchby'} eq 'uname') &&
851: ($srch->{'srchtype'} eq 'exact') &&
852: ($srch->{'srchdomain'} ne '') &&
853: ($srch->{'srchterm'} ne '')) {
1.353 raeburn 854: my (%curr_rules,%got_rules);
1.214 raeburn 855: my ($rules,$ruleorder) =
856: &Apache::lonnet::inst_userrules($srch->{'srchdomain'},'username');
1.353 raeburn 857: $usertype = &Apache::lonuserutils::check_usertype($srch->{'srchdomain'},$srch->{'srchterm'},$rules,\%curr_rules,\%got_rules);
1.229 raeburn 858: } else {
859: $inexact = 1;
1.214 raeburn 860: }
1.207 raeburn 861: }
1.438 raeburn 862: my ($cancreate,$noinstd);
863: if ($env{'form.action'} eq 'accesslogs') {
864: $noinstd = 1;
865: } else {
866: $cancreate =
867: &Apache::lonuserutils::can_create_user($dom,$context,$usertype);
868: }
1.412 raeburn 869: my ($userpicker,$cansearch) =
1.179 raeburn 870: &Apache::loncommon::user_picker($dom,$srch,$forcenewuser,
1.438 raeburn 871: 'document.crtuser',$cancreate,$usertype,$context,$fixeddom,$noinstd);
1.160 raeburn 872: my $srchbutton = &mt('Search');
1.229 raeburn 873: if ($env{'form.action'} eq 'singlestudent') {
874: $srchbutton = &mt('Search and Enroll');
1.416 raeburn 875: } elsif ($env{'form.action'} eq 'accesslogs') {
876: $srchbutton = &mt('Search');
1.229 raeburn 877: } elsif ($cancreate && $responsemsg ne '' && $inexact) {
878: $srchbutton = &mt('Search or Add New User');
879: }
1.412 raeburn 880: my $output;
881: if ($cansearch) {
882: $output = <<"ENDBLOCK";
1.160 raeburn 883: <form action="/adm/createuser" method="post" name="crtuser">
1.190 raeburn 884: <input type="hidden" name="action" value="$env{'form.action'}" />
1.160 raeburn 885: <input type="hidden" name="phase" value="get_user_info" />
886: $userpicker
1.179 raeburn 887: <input name="userrole" type="button" value="$srchbutton" onclick="javascript:validateEntry(document.crtuser)" />
1.160 raeburn 888: </form>
1.207 raeburn 889: ENDBLOCK
1.412 raeburn 890: } else {
891: $output = '<p>'.$userpicker.'</p>';
892: }
1.422 raeburn 893: if (($env{'form.phase'} eq '') && ($env{'form.action'} ne 'accesslogs') &&
1.430 raeburn 894: (!(($env{'form.action'} eq 'singleuser') && ($context eq 'domain') &&
1.422 raeburn 895: (!&Apache::lonnet::allowed('mau',$env{'request.role.domain'}))))) {
1.207 raeburn 896: my $defdom=$env{'request.role.domain'};
1.446 raeburn 897: my ($trusted,$untrusted);
1.444 raeburn 898: if ($context eq 'course') {
1.446 raeburn 899: ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('enroll',$defdom);
1.444 raeburn 900: } elsif ($context eq 'author') {
1.446 raeburn 901: ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('othcoau',$defdom);
1.444 raeburn 902: } elsif ($context eq 'domain') {
1.446 raeburn 903: ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('domroles',$defdom);
1.444 raeburn 904: }
1.446 raeburn 905: my $domform = &Apache::loncommon::select_dom_form($defdom,'srchdomain',undef,undef,undef,$trusted,$untrusted);
1.207 raeburn 906: my %lt=&Apache::lonlocal::texthash(
1.229 raeburn 907: 'enro' => 'Enroll one student',
1.318 raeburn 908: 'enrm' => 'Enroll one member',
1.229 raeburn 909: 'admo' => 'Add/modify a single user',
910: 'crea' => 'create new user if required',
911: 'uskn' => "username is known",
1.207 raeburn 912: 'crnu' => 'Create a new user',
913: 'usr' => 'Username',
914: 'dom' => 'in domain',
1.229 raeburn 915: 'enrl' => 'Enroll',
916: 'cram' => 'Create/Modify user',
1.207 raeburn 917: );
1.229 raeburn 918: my $sellink=&Apache::loncommon::selectstudent_link('crtusername','srchterm','srchdomain');
919: my ($title,$buttontext,$showresponse);
1.318 raeburn 920: if ($env{'form.action'} eq 'singlestudent') {
921: if ($crstype eq 'Community') {
922: $title = $lt{'enrm'};
923: } else {
924: $title = $lt{'enro'};
925: }
1.229 raeburn 926: $buttontext = $lt{'enrl'};
927: } else {
928: $title = $lt{'admo'};
929: $buttontext = $lt{'cram'};
930: }
931: if ($cancreate) {
932: $title .= ' <span class="LC_cusr_subheading">('.$lt{'crea'}.')</span>';
933: } else {
934: $title .= ' <span class="LC_cusr_subheading">('.$lt{'uskn'}.')</span>';
935: }
936: if ($env{'form.origform'} eq 'crtusername') {
937: $showresponse = $responsemsg;
938: }
1.207 raeburn 939: $output .= <<"ENDDOCUMENT";
1.229 raeburn 940: <br />
1.207 raeburn 941: <form action="/adm/createuser" method="post" name="crtusername">
942: <input type="hidden" name="action" value="$env{'form.action'}" />
943: <input type="hidden" name="phase" value="createnewuser" />
944: <input type="hidden" name="srchtype" value="exact" />
1.233 raeburn 945: <input type="hidden" name="srchby" value="uname" />
1.207 raeburn 946: <input type="hidden" name="srchin" value="dom" />
947: <input type="hidden" name="forcenewuser" value="1" />
948: <input type="hidden" name="origform" value="crtusername" />
1.229 raeburn 949: <h3>$title</h3>
950: $showresponse
1.207 raeburn 951: <table>
952: <tr>
953: <td>$lt{'usr'}:</td>
954: <td><input type="text" size="15" name="srchterm" /></td>
955: <td> $lt{'dom'}:</td><td>$domform</td>
1.229 raeburn 956: <td> $sellink </td>
957: <td> <input name="userrole" type="submit" value="$buttontext" /></td>
1.207 raeburn 958: </tr>
959: </table>
960: </form>
1.160 raeburn 961: ENDDOCUMENT
1.207 raeburn 962: }
1.160 raeburn 963: return $output;
964: }
1.110 albertel 965:
966: sub user_modification_js {
1.113 raeburn 967: my ($pjump_def,$dc_setcourse_code,$nondc_setsection_code,$groupslist)=@_;
968:
1.110 albertel 969: return <<END;
970: <script type="text/javascript" language="Javascript">
1.301 bisitz 971: // <![CDATA[
1.314 raeburn 972:
1.110 albertel 973: $pjump_def
974: $dc_setcourse_code
975:
976: function dateset() {
977: eval("document.cu."+document.cu.pres_marker.value+
978: ".value=document.cu.pres_value.value");
1.359 www 979: modalWindow.close();
1.110 albertel 980: }
981:
1.113 raeburn 982: $nondc_setsection_code
1.301 bisitz 983: // ]]>
1.110 albertel 984: </script>
985: END
1.2 www 986: }
987:
988: # =================================================================== Phase two
1.160 raeburn 989: sub print_user_selection_page {
1.351 raeburn 990: my ($r,$response,$srch,$srch_results,$srcharray,$context,$opener_elements,$crstype,$brcrum) = @_;
1.160 raeburn 991: my @fields = ('username','domain','lastname','firstname','permanentemail');
992: my $sortby = $env{'form.sortby'};
993:
994: if (!grep(/^\Q$sortby\E$/,@fields)) {
995: $sortby = 'lastname';
996: }
997:
998: my ($jsback,$elements) = &crumb_utilities();
999:
1000: my $jscript = (<<ENDSCRIPT);
1001: <script type="text/javascript">
1.301 bisitz 1002: // <![CDATA[
1.160 raeburn 1003: function pickuser(uname,udom) {
1004: document.usersrchform.seluname.value=uname;
1005: document.usersrchform.seludom.value=udom;
1006: document.usersrchform.phase.value="userpicked";
1007: document.usersrchform.submit();
1008: }
1009:
1010: $jsback
1.301 bisitz 1011: // ]]>
1.160 raeburn 1012: </script>
1013: ENDSCRIPT
1014:
1015: my %lt=&Apache::lonlocal::texthash(
1.179 raeburn 1016: 'usrch' => "User Search to add/modify roles",
1017: 'stusrch' => "User Search to enroll student",
1.318 raeburn 1018: 'memsrch' => "User Search to enroll member",
1.416 raeburn 1019: 'srcva' => "Search for a user and view access log information",
1.422 raeburn 1020: 'usrvu' => "User Search to view user roles",
1.179 raeburn 1021: 'usel' => "Select a user to add/modify roles",
1.422 raeburn 1022: 'suvr' => "Select a user to view roles",
1.318 raeburn 1023: 'stusel' => "Select a user to enroll as a student",
1024: 'memsel' => "Select a user to enroll as a member",
1.416 raeburn 1025: 'vacsel' => "Select a user to view access log",
1.160 raeburn 1026: 'username' => "username",
1027: 'domain' => "domain",
1028: 'lastname' => "last name",
1029: 'firstname' => "first name",
1030: 'permanentemail' => "permanent e-mail",
1031: );
1.302 raeburn 1032: if ($context eq 'requestcrs') {
1033: $r->print('<div>');
1034: } else {
1.422 raeburn 1035: my %breadcrumb_text = &singleuser_breadcrumb($crstype,$context,$srch->{'srchdomain'});
1.351 raeburn 1036: my $helpitem;
1037: if ($env{'form.action'} eq 'singleuser') {
1038: $helpitem = 'Course_Change_Privileges';
1039: } elsif ($env{'form.action'} eq 'singlestudent') {
1040: $helpitem = 'Course_Add_Student';
1.439 raeburn 1041: } elsif ($context eq 'author') {
1042: $helpitem = 'Author_Change_Privileges';
1043: } elsif ($context eq 'domain') {
1044: $helpitem = 'Domain_Change_Privileges';
1.351 raeburn 1045: }
1046: push (@{$brcrum},
1047: {href => "javascript:backPage(document.usersrchform,'','')",
1048: text => $breadcrumb_text{'search'},
1049: faq => 282,
1050: bug => 'Instructor Interface',},
1051: {href => "javascript:backPage(document.usersrchform,'get_user_info','select')",
1052: text => $breadcrumb_text{'userpicked'},
1053: faq => 282,
1054: bug => 'Instructor Interface',
1055: help => $helpitem}
1056: );
1057: $r->print(&Apache::loncommon::start_page('User Management',$jscript,{bread_crumbs => $brcrum}));
1.302 raeburn 1058: if ($env{'form.action'} eq 'singleuser') {
1.422 raeburn 1059: my $readonly;
1060: if (($context eq 'domain') && (!&Apache::lonnet::allowed('mau',$srch->{'srchdomain'}))) {
1061: $readonly = 1;
1062: $r->print("<b>$lt{'usrvu'}</b><br />");
1063: } else {
1064: $r->print("<b>$lt{'usrch'}</b><br />");
1065: }
1.318 raeburn 1066: $r->print(&entry_form($srch->{'srchdomain'},$srch,undef,$context,undef,$crstype));
1.422 raeburn 1067: if ($readonly) {
1068: $r->print('<h3>'.$lt{'suvr'}.'</h3>');
1069: } else {
1070: $r->print('<h3>'.$lt{'usel'}.'</h3>');
1071: }
1.302 raeburn 1072: } elsif ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1073: $r->print($jscript."<b>");
1074: if ($crstype eq 'Community') {
1075: $r->print($lt{'memsrch'});
1076: } else {
1077: $r->print($lt{'stusrch'});
1078: }
1079: $r->print("</b><br />");
1080: $r->print(&entry_form($srch->{'srchdomain'},$srch,undef,$context,undef,$crstype));
1081: $r->print('</form><h3>');
1082: if ($crstype eq 'Community') {
1083: $r->print($lt{'memsel'});
1084: } else {
1085: $r->print($lt{'stusel'});
1086: }
1087: $r->print('</h3>');
1.416 raeburn 1088: } elsif ($env{'form.action'} eq 'accesslogs') {
1089: $r->print("<b>$lt{'srcva'}</b><br />");
1.438 raeburn 1090: $r->print(&entry_form($srch->{'srchdomain'},$srch,undef,$context,undef,undef,1));
1.416 raeburn 1091: $r->print('<h3>'.$lt{'vacsel'}.'</h3>');
1.302 raeburn 1092: }
1.179 raeburn 1093: }
1.380 bisitz 1094: $r->print('<form name="usersrchform" method="post" action="">'.
1.160 raeburn 1095: &Apache::loncommon::start_data_table()."\n".
1096: &Apache::loncommon::start_data_table_header_row()."\n".
1097: ' <th> </th>'."\n");
1098: foreach my $field (@fields) {
1099: $r->print(' <th><a href="javascript:document.usersrchform.sortby.value='.
1100: "'".$field."'".';document.usersrchform.submit();">'.
1101: $lt{$field}.'</a></th>'."\n");
1102: }
1103: $r->print(&Apache::loncommon::end_data_table_header_row());
1104:
1105: my @sorted_users = sort {
1.167 albertel 1106: lc($srch_results->{$a}->{$sortby}) cmp lc($srch_results->{$b}->{$sortby})
1.160 raeburn 1107: ||
1.167 albertel 1108: lc($srch_results->{$a}->{lastname}) cmp lc($srch_results->{$b}->{lastname})
1.160 raeburn 1109: ||
1110: lc($srch_results->{$a}->{firstname}) cmp lc($srch_results->{$b}->{firstname})
1.167 albertel 1111: ||
1112: lc($a) cmp lc($b)
1.160 raeburn 1113: } (keys(%$srch_results));
1114:
1115: foreach my $user (@sorted_users) {
1116: my ($uname,$udom) = split(/:/,$user);
1.302 raeburn 1117: my $onclick;
1118: if ($context eq 'requestcrs') {
1.314 raeburn 1119: $onclick =
1.302 raeburn 1120: 'onclick="javascript:gochoose('."'$uname','$udom',".
1121: "'$srch_results->{$user}->{firstname}',".
1122: "'$srch_results->{$user}->{lastname}',".
1123: "'$srch_results->{$user}->{permanentemail}'".');"';
1124: } else {
1.314 raeburn 1125: $onclick =
1.302 raeburn 1126: ' onclick="javascript:pickuser('."'".$uname."'".','."'".$udom."'".');"';
1127: }
1.160 raeburn 1128: $r->print(&Apache::loncommon::start_data_table_row().
1.302 raeburn 1129: '<td><input type="button" name="seluser" value="'.&mt('Select').'" '.
1130: $onclick.' /></td>'.
1.160 raeburn 1131: '<td><tt>'.$uname.'</tt></td>'.
1132: '<td><tt>'.$udom.'</tt></td>');
1133: foreach my $field ('lastname','firstname','permanentemail') {
1134: $r->print('<td>'.$srch_results->{$user}->{$field}.'</td>');
1135: }
1136: $r->print(&Apache::loncommon::end_data_table_row());
1137: }
1138: $r->print(&Apache::loncommon::end_data_table().'<br /><br />');
1.179 raeburn 1139: if (ref($srcharray) eq 'ARRAY') {
1140: foreach my $item (@{$srcharray}) {
1141: $r->print('<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n");
1142: }
1143: }
1.160 raeburn 1144: $r->print(' <input type="hidden" name="sortby" value="'.$sortby.'" />'."\n".
1145: ' <input type="hidden" name="seluname" value="" />'."\n".
1146: ' <input type="hidden" name="seludom" value="" />'."\n".
1.179 raeburn 1147: ' <input type="hidden" name="currstate" value="select" />'."\n".
1.190 raeburn 1148: ' <input type="hidden" name="phase" value="get_user_info" />'."\n".
1.214 raeburn 1149: ' <input type="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n");
1.302 raeburn 1150: if ($context eq 'requestcrs') {
1151: $r->print($opener_elements.'</form></div>');
1152: } else {
1.351 raeburn 1153: $r->print($response.'</form>');
1.302 raeburn 1154: }
1.160 raeburn 1155: }
1156:
1157: sub print_user_query_page {
1.351 raeburn 1158: my ($r,$caller,$brcrum) = @_;
1.160 raeburn 1159: # FIXME - this is for a network-wide name search (similar to catalog search)
1160: # To use frames with similar behavior to catalog/portfolio search.
1161: # To be implemented.
1162: return;
1163: }
1164:
1.42 matthew 1165: sub print_user_modification_page {
1.375 raeburn 1166: my ($r,$ccuname,$ccdomain,$srch,$response,$context,$permission,$crstype,
1167: $brcrum,$showcredits) = @_;
1.185 raeburn 1168: if (($ccuname eq '') || ($ccdomain eq '')) {
1.215 raeburn 1169: my $usermsg = &mt('No username and/or domain provided.');
1170: $env{'form.phase'} = '';
1.439 raeburn 1171: &print_username_entry_form($r,$context,$usermsg,'','',$crstype,$brcrum,
1172: $permission);
1.58 www 1173: return;
1174: }
1.213 raeburn 1175: my ($form,$formname);
1176: if ($env{'form.action'} eq 'singlestudent') {
1177: $form = 'document.enrollstudent';
1178: $formname = 'enrollstudent';
1179: } else {
1180: $form = 'document.cu';
1181: $formname = 'cu';
1182: }
1.188 raeburn 1183: my %abv_auth = &auth_abbrev();
1.227 raeburn 1184: my (%rulematch,%inst_results,$newuser,%alerts,%curr_rules,%got_rules);
1.185 raeburn 1185: my $uhome=&Apache::lonnet::homeserver($ccuname,$ccdomain);
1186: if ($uhome eq 'no_host') {
1.215 raeburn 1187: my $usertype;
1188: my ($rules,$ruleorder) =
1189: &Apache::lonnet::inst_userrules($ccdomain,'username');
1190: $usertype =
1.353 raeburn 1191: &Apache::lonuserutils::check_usertype($ccdomain,$ccuname,$rules,
1.362 raeburn 1192: \%curr_rules,\%got_rules);
1.215 raeburn 1193: my $cancreate =
1194: &Apache::lonuserutils::can_create_user($ccdomain,$context,
1195: $usertype);
1196: if (!$cancreate) {
1.292 bisitz 1197: my $helplink = 'javascript:helpMenu('."'display'".')';
1.215 raeburn 1198: my %usertypetext = (
1199: official => 'institutional',
1200: unofficial => 'non-institutional',
1201: );
1202: my $response;
1203: if ($env{'form.origform'} eq 'crtusername') {
1.362 raeburn 1204: $response = '<span class="LC_warning">'.
1205: &mt('No match found for the username [_1] in LON-CAPA domain: [_2]',
1206: '<b>'.$ccuname.'</b>',$ccdomain).
1.215 raeburn 1207: '</span><br />';
1208: }
1.292 bisitz 1209: $response .= '<p class="LC_warning">'
1210: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
1.418 raeburn 1211: .' ';
1212: if ($context eq 'domain') {
1213: $response .= &mt('Please contact a [_1] for assistance.',
1214: &Apache::lonnet::plaintext('dc'));
1215: } else {
1216: $response .= &mt('Please contact the [_1]helpdesk[_2] for assistance.'
1217: ,'<a href="'.$helplink.'">','</a>');
1218: }
1219: $response .= '</p><br />';
1.215 raeburn 1220: $env{'form.phase'} = '';
1.439 raeburn 1221: &print_username_entry_form($r,$context,$response,undef,undef,$crstype,$brcrum,
1222: $permission);
1.215 raeburn 1223: return;
1224: }
1.188 raeburn 1225: $newuser = 1;
1.193 raeburn 1226: my $checkhash;
1227: my $checks = { 'username' => 1 };
1.196 raeburn 1228: $checkhash->{$ccuname.':'.$ccdomain} = { 'newuser' => $newuser };
1.193 raeburn 1229: &Apache::loncommon::user_rule_check($checkhash,$checks,
1.196 raeburn 1230: \%alerts,\%rulematch,\%inst_results,\%curr_rules,\%got_rules);
1231: if (ref($alerts{'username'}) eq 'HASH') {
1232: if (ref($alerts{'username'}{$ccdomain}) eq 'HASH') {
1233: my $domdesc =
1.193 raeburn 1234: &Apache::lonnet::domain($ccdomain,'description');
1.196 raeburn 1235: if ($alerts{'username'}{$ccdomain}{$ccuname}) {
1236: my $userchkmsg;
1237: if (ref($curr_rules{$ccdomain}) eq 'HASH') {
1238: $userchkmsg =
1239: &Apache::loncommon::instrule_disallow_msg('username',
1.193 raeburn 1240: $domdesc,1).
1241: &Apache::loncommon::user_rule_formats($ccdomain,
1242: $domdesc,$curr_rules{$ccdomain}{'username'},
1243: 'username');
1.196 raeburn 1244: }
1.215 raeburn 1245: $env{'form.phase'} = '';
1.439 raeburn 1246: &print_username_entry_form($r,$context,$userchkmsg,undef,undef,$crstype,$brcrum,
1247: $permission);
1.196 raeburn 1248: return;
1.215 raeburn 1249: }
1.193 raeburn 1250: }
1.185 raeburn 1251: }
1.187 raeburn 1252: } else {
1.188 raeburn 1253: $newuser = 0;
1.185 raeburn 1254: }
1.160 raeburn 1255: if ($response) {
1.215 raeburn 1256: $response = '<br />'.$response;
1.160 raeburn 1257: }
1.149 raeburn 1258:
1.52 matthew 1259: my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
1.88 raeburn 1260: my $dc_setcourse_code = '';
1.119 raeburn 1261: my $nondc_setsection_code = '';
1.112 albertel 1262: my %loaditem;
1.114 albertel 1263:
1.216 raeburn 1264: my $groupslist = &Apache::lonuserutils::get_groupslist();
1.88 raeburn 1265:
1.375 raeburn 1266: my $js = &validation_javascript($context,$ccdomain,$pjump_def,$crstype,
1.216 raeburn 1267: $groupslist,$newuser,$formname,\%loaditem);
1.422 raeburn 1268: my %breadcrumb_text = &singleuser_breadcrumb($crstype,$context,$ccdomain);
1.224 raeburn 1269: my $helpitem = 'Course_Change_Privileges';
1270: if ($env{'form.action'} eq 'singlestudent') {
1271: $helpitem = 'Course_Add_Student';
1.439 raeburn 1272: } elsif ($context eq 'author') {
1273: $helpitem = 'Author_Change_Privileges';
1274: } elsif ($context eq 'domain') {
1275: $helpitem = 'Domain_Change_Privileges';
1.224 raeburn 1276: }
1.351 raeburn 1277: push (@{$brcrum},
1278: {href => "javascript:backPage($form)",
1279: text => $breadcrumb_text{'search'},
1280: faq => 282,
1281: bug => 'Instructor Interface',});
1282: if ($env{'form.phase'} eq 'userpicked') {
1283: push(@{$brcrum},
1284: {href => "javascript:backPage($form,'get_user_info','select')",
1285: text => $breadcrumb_text{'userpicked'},
1286: faq => 282,
1287: bug => 'Instructor Interface',});
1288: }
1289: push(@{$brcrum},
1290: {href => "javascript:backPage($form,'$env{'form.phase'}','modify')",
1291: text => $breadcrumb_text{'modify'},
1292: faq => 282,
1293: bug => 'Instructor Interface',
1294: help => $helpitem});
1295: my $args = {'add_entries' => \%loaditem,
1296: 'bread_crumbs' => $brcrum,
1297: 'bread_crumbs_component' => 'User Management'};
1298: if ($env{'form.popup'}) {
1299: $args->{'no_nav_bar'} = 1;
1300: }
1301: my $start_page =
1302: &Apache::loncommon::start_page('User Management',$js,$args);
1.3 www 1303:
1.25 matthew 1304: my $forminfo =<<"ENDFORMINFO";
1.216 raeburn 1305: <form action="/adm/createuser" method="post" name="$formname">
1.190 raeburn 1306: <input type="hidden" name="phase" value="update_user_data" />
1.188 raeburn 1307: <input type="hidden" name="ccuname" value="$ccuname" />
1308: <input type="hidden" name="ccdomain" value="$ccdomain" />
1.157 albertel 1309: <input type="hidden" name="pres_value" value="" />
1310: <input type="hidden" name="pres_type" value="" />
1311: <input type="hidden" name="pres_marker" value="" />
1.25 matthew 1312: ENDFORMINFO
1.375 raeburn 1313: my (%inccourses,$roledom,$defaultcredits);
1.329 raeburn 1314: if ($context eq 'course') {
1315: $inccourses{$env{'request.course.id'}}=1;
1316: $roledom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1.375 raeburn 1317: if ($showcredits) {
1318: $defaultcredits = &Apache::lonuserutils::get_defaultcredits();
1319: }
1.329 raeburn 1320: } elsif ($context eq 'author') {
1321: $roledom = $env{'request.role.domain'};
1322: } elsif ($context eq 'domain') {
1323: foreach my $key (keys(%env)) {
1324: $roledom = $env{'request.role.domain'};
1325: if ($key=~/^user\.priv\.cm\.\/($roledom)\/($match_username)/) {
1326: $inccourses{$1.'_'.$2}=1;
1327: }
1328: }
1329: } else {
1330: foreach my $key (keys(%env)) {
1331: if ($key=~/^user\.priv\.cm\.\/($match_domain)\/($match_username)/) {
1332: $inccourses{$1.'_'.$2}=1;
1333: }
1.2 www 1334: }
1.24 matthew 1335: }
1.389 bisitz 1336: my $title = '';
1.216 raeburn 1337: if ($newuser) {
1.427 raeburn 1338: my ($portfolioform,$domroleform);
1.267 raeburn 1339: if ((&Apache::lonnet::allowed('mpq',$env{'request.role.domain'})) ||
1340: (&Apache::lonnet::allowed('mut',$env{'request.role.domain'}))) {
1341: # Current user has quota or user tools modification privileges
1.378 raeburn 1342: $portfolioform = '<br />'.&user_quotas($ccuname,$ccdomain);
1.134 raeburn 1343: }
1.383 raeburn 1344: if ((&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) &&
1345: ($ccdomain eq $env{'request.role.domain'})) {
1.362 raeburn 1346: $domroleform = '<br />'.&domainrole_req($ccuname,$ccdomain);
1347: }
1.227 raeburn 1348: &initialize_authen_forms($ccdomain,$formname);
1.188 raeburn 1349: my %lt=&Apache::lonlocal::texthash(
1350: 'lg' => 'Login Data',
1.190 raeburn 1351: 'hs' => "Home Server",
1.188 raeburn 1352: );
1.185 raeburn 1353: $r->print(<<ENDTITLE);
1.110 albertel 1354: $start_page
1.160 raeburn 1355: $response
1.25 matthew 1356: $forminfo
1.31 matthew 1357: <script type="text/javascript" language="Javascript">
1.301 bisitz 1358: // <![CDATA[
1.20 harris41 1359: $loginscript
1.301 bisitz 1360: // ]]>
1.31 matthew 1361: </script>
1.20 harris41 1362: <input type='hidden' name='makeuser' value='1' />
1.185 raeburn 1363: ENDTITLE
1.213 raeburn 1364: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1365: if ($crstype eq 'Community') {
1.389 bisitz 1366: $title = &mt('Create New User [_1] in domain [_2] as a member',
1367: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.318 raeburn 1368: } else {
1.389 bisitz 1369: $title = &mt('Create New User [_1] in domain [_2] as a student',
1370: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.318 raeburn 1371: }
1.389 bisitz 1372: } else {
1373: $title = &mt('Create New User [_1] in domain [_2]',
1374: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.213 raeburn 1375: }
1.389 bisitz 1376: $r->print('<h2>'.$title.'</h2>'."\n");
1377: $r->print('<div class="LC_left_float">');
1.393 raeburn 1378: $r->print(&personal_data_display($ccuname,$ccdomain,$newuser,$context,
1379: $inst_results{$ccuname.':'.$ccdomain}));
1380: # Option to disable student/employee ID conflict checking not offerred for new users.
1.187 raeburn 1381: my ($home_server_pick,$numlib) =
1382: &Apache::loncommon::home_server_form_item($ccdomain,'hserver',
1383: 'default','hide');
1384: if ($numlib > 1) {
1385: $r->print("
1.185 raeburn 1386: <br />
1.187 raeburn 1387: $lt{'hs'}: $home_server_pick
1388: <br />");
1389: } else {
1390: $r->print($home_server_pick);
1391: }
1.304 raeburn 1392: if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
1.362 raeburn 1393: $r->print('<br /><h3>'.
1394: &mt('User Can Request Creation of Courses/Communities in this Domain?').'</h3>'.
1.304 raeburn 1395: &Apache::loncommon::start_data_table().
1396: &build_tools_display($ccuname,$ccdomain,
1397: 'requestcourses').
1398: &Apache::loncommon::end_data_table());
1399: }
1.188 raeburn 1400: $r->print('</div>'."\n".'<div class="LC_left_float"><h3>'.
1401: $lt{'lg'}.'</h3>');
1.185 raeburn 1402: my ($fixedauth,$varauth,$authmsg);
1.193 raeburn 1403: if (ref($rulematch{$ccuname.':'.$ccdomain}) eq 'HASH') {
1404: my $matchedrule = $rulematch{$ccuname.':'.$ccdomain}{'username'};
1405: my ($rules,$ruleorder) =
1406: &Apache::lonnet::inst_userrules($ccdomain,'username');
1.185 raeburn 1407: if (ref($rules) eq 'HASH') {
1.193 raeburn 1408: if (ref($rules->{$matchedrule}) eq 'HASH') {
1409: my $authtype = $rules->{$matchedrule}{'authtype'};
1.185 raeburn 1410: if ($authtype !~ /^(krb4|krb5|int|fsys|loc)$/) {
1.190 raeburn 1411: $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1.275 raeburn 1412: } else {
1.193 raeburn 1413: my $authparm = $rules->{$matchedrule}{'authparm'};
1.273 raeburn 1414: $authmsg = $rules->{$matchedrule}{'authmsg'};
1.185 raeburn 1415: if ($authtype =~ /^krb(4|5)$/) {
1416: my $ver = $1;
1417: if ($authparm ne '') {
1418: $fixedauth = <<"KERB";
1419: <input type="hidden" name="login" value="krb" />
1420: <input type="hidden" name="krbver" value="$ver" />
1421: <input type="hidden" name="krbarg" value="$authparm" />
1422: KERB
1423: }
1424: } else {
1425: $fixedauth =
1426: '<input type="hidden" name="login" value="'.$authtype.'" />'."\n";
1.193 raeburn 1427: if ($rules->{$matchedrule}{'authparmfixed'}) {
1.185 raeburn 1428: $fixedauth .=
1429: '<input type="hidden" name="'.$authtype.'arg" value="'.$authparm.'" />'."\n";
1430: } else {
1.273 raeburn 1431: if ($authtype eq 'int') {
1432: $varauth = '<br />'.
1.301 bisitz 1433: &mt('[_1] Internally authenticated (with initial password [_2])','','<input type="password" size="10" name="intarg" value="" />')."<label><input type=\"checkbox\" name=\"visible\" onclick='if (this.checked) { this.form.intarg.type=\"text\" } else { this.form.intarg.type=\"password\" }' />".&mt('Visible input').'</label>';
1.273 raeburn 1434: } elsif ($authtype eq 'loc') {
1435: $varauth = '<br />'.
1436: &mt('[_1] Local Authentication with argument [_2]','','<input type="text" name="'.$authtype.'arg" value="" />')."\n";
1437: } else {
1438: $varauth =
1.185 raeburn 1439: '<input type="text" name="'.$authtype.'arg" value="" />'."\n";
1.273 raeburn 1440: }
1.185 raeburn 1441: }
1442: }
1443: }
1444: } else {
1.190 raeburn 1445: $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1.185 raeburn 1446: }
1447: }
1448: if ($authmsg) {
1449: $r->print(<<ENDAUTH);
1450: $fixedauth
1451: $authmsg
1452: $varauth
1453: ENDAUTH
1454: }
1455: } else {
1.190 raeburn 1456: $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1.187 raeburn 1457: }
1.427 raeburn 1458: $r->print($portfolioform.$domroleform);
1.215 raeburn 1459: if ($env{'form.action'} eq 'singlestudent') {
1460: $r->print(&date_sections_select($context,$newuser,$formname,
1.375 raeburn 1461: $permission,$crstype,$ccuname,
1462: $ccdomain,$showcredits));
1.215 raeburn 1463: }
1464: $r->print('</div><div class="LC_clear_float_footer"></div>');
1.216 raeburn 1465: } else { # user already exists
1.389 bisitz 1466: $r->print($start_page.$forminfo);
1.213 raeburn 1467: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1468: if ($crstype eq 'Community') {
1.389 bisitz 1469: $title = &mt('Enroll one member: [_1] in domain [_2]',
1470: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.318 raeburn 1471: } else {
1.389 bisitz 1472: $title = &mt('Enroll one student: [_1] in domain [_2]',
1473: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.318 raeburn 1474: }
1.213 raeburn 1475: } else {
1.418 raeburn 1476: if ($permission->{'cusr'}) {
1477: $title = &mt('Modify existing user: [_1] in domain [_2]',
1478: '"'.$ccuname.'"','"'.$ccdomain.'"');
1479: } else {
1480: $title = &mt('Existing user: [_1] in domain [_2]',
1.389 bisitz 1481: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.418 raeburn 1482: }
1.213 raeburn 1483: }
1.389 bisitz 1484: $r->print('<h2>'.$title.'</h2>'."\n");
1485: $r->print('<div class="LC_left_float">');
1.393 raeburn 1486: $r->print(&personal_data_display($ccuname,$ccdomain,$newuser,$context,
1487: $inst_results{$ccuname.':'.$ccdomain}));
1.430 raeburn 1488: if ((&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) ||
1.418 raeburn 1489: (&Apache::lonnet::allowed('udp',$env{'request.role.domain'}))) {
1.450 raeburn 1490: $r->print('<br /><h3>'.&mt('User Can Request Creation of Courses/Communities in this Domain?').'</h3>'."\n");
1491: if (($env{'request.role.domain'} eq $ccdomain) ||
1492: (&Apache::lonnet::will_trust('reqcrs',$ccdomain,$env{'request.role.domain'}))) {
1493: $r->print(&Apache::loncommon::start_data_table());
1494: if ($env{'request.role.domain'} eq $ccdomain) {
1495: $r->print(&build_tools_display($ccuname,$ccdomain,'requestcourses'));
1496: } else {
1.444 raeburn 1497: $r->print(&coursereq_externaluser($ccuname,$ccdomain,
1498: $env{'request.role.domain'}));
1499: }
1.450 raeburn 1500: $r->print(&Apache::loncommon::end_data_table());
1501: } else {
1502: $r->print(&mt('Domain configuration for this domain prohibits course creation by users from domain: "[_1]"',
1503: &Apache::lonnet::domain($ccdomain,'description')));
1.300 raeburn 1504: }
1.275 raeburn 1505: }
1.199 raeburn 1506: $r->print('</div>');
1.427 raeburn 1507: my @order = ('auth','quota','tools','requestauthor');
1.362 raeburn 1508: my %user_text;
1509: my ($isadv,$isauthor) =
1.418 raeburn 1510: &Apache::lonnet::is_advanced_user($ccdomain,$ccuname);
1.362 raeburn 1511: if ((!$isauthor) &&
1.418 raeburn 1512: ((&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) ||
1513: (&Apache::lonnet::allowed('udp',$env{'request.role.domain'}))) &&
1.430 raeburn 1514: ($env{'request.role.domain'} eq $ccdomain)) {
1.362 raeburn 1515: $user_text{'requestauthor'} = &domainrole_req($ccuname,$ccdomain);
1516: }
1.451 raeburn 1517: $user_text{'auth'} = &user_authentication($ccuname,$ccdomain,$formname,$crstype,$permission);
1.267 raeburn 1518: if ((&Apache::lonnet::allowed('mpq',$ccdomain)) ||
1.418 raeburn 1519: (&Apache::lonnet::allowed('mut',$ccdomain)) ||
1520: (&Apache::lonnet::allowed('udp',$ccdomain))) {
1.188 raeburn 1521: # Current user has quota modification privileges
1.378 raeburn 1522: $user_text{'quota'} = &user_quotas($ccuname,$ccdomain);
1.267 raeburn 1523: }
1524: if (!&Apache::lonnet::allowed('mpq',$ccdomain)) {
1525: if (&Apache::lonnet::allowed('mpq',$env{'request.role.domain'})) {
1526: my %lt=&Apache::lonlocal::texthash(
1.385 bisitz 1527: 'dska' => "Disk quotas for user's portfolio and Authoring Space",
1528: 'youd' => "You do not have privileges to modify the portfolio and/or Authoring Space quotas for this user.",
1.267 raeburn 1529: 'ichr' => "If a change is required, contact a domain coordinator for the domain",
1530: );
1.362 raeburn 1531: $user_text{'quota'} = <<ENDNOPORTPRIV;
1.188 raeburn 1532: <h3>$lt{'dska'}</h3>
1533: $lt{'youd'} $lt{'ichr'}: $ccdomain
1534: ENDNOPORTPRIV
1.267 raeburn 1535: }
1536: }
1537: if (!&Apache::lonnet::allowed('mut',$ccdomain)) {
1538: if (&Apache::lonnet::allowed('mut',$env{'request.role.domain'})) {
1539: my %lt=&Apache::lonlocal::texthash(
1540: 'utav' => "User Tools Availability",
1.361 raeburn 1541: 'yodo' => "You do not have privileges to modify Portfolio, Blog, WebDAV, or Personal Information Page settings for this user.",
1.267 raeburn 1542: 'ifch' => "If a change is required, contact a domain coordinator for the domain",
1543: );
1.362 raeburn 1544: $user_text{'tools'} = <<ENDNOTOOLSPRIV;
1.267 raeburn 1545: <h3>$lt{'utav'}</h3>
1546: $lt{'yodo'} $lt{'ifch'}: $ccdomain
1547: ENDNOTOOLSPRIV
1548: }
1.188 raeburn 1549: }
1.362 raeburn 1550: my $gotdiv = 0;
1551: foreach my $item (@order) {
1552: if ($user_text{$item} ne '') {
1553: unless ($gotdiv) {
1554: $r->print('<div class="LC_left_float">');
1555: $gotdiv = 1;
1556: }
1557: $r->print('<br />'.$user_text{$item});
1558: }
1559: }
1560: if ($env{'form.action'} eq 'singlestudent') {
1561: unless ($gotdiv) {
1562: $r->print('<div class="LC_left_float">');
1.213 raeburn 1563: }
1.375 raeburn 1564: my $credits;
1565: if ($showcredits) {
1566: $credits = &get_user_credits($ccuname,$ccdomain,$defaultcredits);
1567: if ($credits eq '') {
1568: $credits = $defaultcredits;
1569: }
1570: }
1.374 raeburn 1571: $r->print(&date_sections_select($context,$newuser,$formname,
1.375 raeburn 1572: $permission,$crstype,$ccuname,
1573: $ccdomain,$showcredits));
1.374 raeburn 1574: }
1.362 raeburn 1575: if ($gotdiv) {
1576: $r->print('</div><div class="LC_clear_float_footer"></div>');
1.188 raeburn 1577: }
1.418 raeburn 1578: my $statuses;
1579: if (($context eq 'domain') && (&Apache::lonnet::allowed('udp',$ccdomain)) &&
1580: (!&Apache::lonnet::allowed('mau',$ccdomain))) {
1581: $statuses = ['active'];
1582: } elsif (($context eq 'course') && ((&Apache::lonnet::allowed('vcl',$env{'request.course.id'})) ||
1583: ($env{'request.course.sec'} &&
1584: &Apache::lonnet::allowed('vcl',$env{'request.course.id'}.'/'.$env{'request.course.sec'})))) {
1.430 raeburn 1585: $statuses = ['active'];
1.418 raeburn 1586: }
1.217 raeburn 1587: if ($env{'form.action'} ne 'singlestudent') {
1.329 raeburn 1588: &display_existing_roles($r,$ccuname,$ccdomain,\%inccourses,$context,
1.418 raeburn 1589: $roledom,$crstype,$showcredits,$statuses);
1.217 raeburn 1590: }
1.25 matthew 1591: } ## End of new user/old user logic
1.218 raeburn 1592: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1593: my $btntxt;
1594: if ($crstype eq 'Community') {
1595: $btntxt = &mt('Enroll Member');
1596: } else {
1597: $btntxt = &mt('Enroll Student');
1598: }
1599: $r->print('<br /><input type="button" value="'.$btntxt.'" onclick="setSections(this.form)" />'."\n");
1.418 raeburn 1600: } elsif ($permission->{'cusr'}) {
1.393 raeburn 1601: $r->print('<div class="LC_left_float">'.
1602: '<fieldset><legend>'.&mt('Add Roles').'</legend>');
1.218 raeburn 1603: my $addrolesdisplay = 0;
1604: if ($context eq 'domain' || $context eq 'author') {
1605: $addrolesdisplay = &new_coauthor_roles($r,$ccuname,$ccdomain);
1606: }
1607: if ($context eq 'domain') {
1.357 raeburn 1608: my $add_domainroles = &new_domain_roles($r,$ccdomain);
1.218 raeburn 1609: if (!$addrolesdisplay) {
1610: $addrolesdisplay = $add_domainroles;
1.2 www 1611: }
1.375 raeburn 1612: $r->print(&course_level_dc($env{'request.role.domain'},$showcredits));
1.393 raeburn 1613: $r->print('</fieldset></div><div class="LC_clear_float_footer"></div>'.
1614: '<br /><input type="button" value="'.&mt('Save').'" onclick="setCourse()" />'."\n");
1.218 raeburn 1615: } elsif ($context eq 'author') {
1616: if ($addrolesdisplay) {
1.393 raeburn 1617: $r->print('</fieldset></div><div class="LC_clear_float_footer"></div>'.
1618: '<br /><input type="button" value="'.&mt('Save').'"');
1.218 raeburn 1619: if ($newuser) {
1.301 bisitz 1620: $r->print(' onclick="auth_check()" \>'."\n");
1.218 raeburn 1621: } else {
1.461 raeburn 1622: $r->print(' onclick="this.form.submit()" \>'."\n");
1.218 raeburn 1623: }
1.188 raeburn 1624: } else {
1.393 raeburn 1625: $r->print('</fieldset></div>'.
1626: '<div class="LC_clear_float_footer"></div>'.
1627: '<br /><a href="javascript:backPage(document.cu)">'.
1.218 raeburn 1628: &mt('Back to previous page').'</a>');
1.188 raeburn 1629: }
1630: } else {
1.375 raeburn 1631: $r->print(&course_level_table(\%inccourses,$showcredits,$defaultcredits));
1.393 raeburn 1632: $r->print('</fieldset></div><div class="LC_clear_float_footer"></div>'.
1633: '<br /><input type="button" value="'.&mt('Save').'" onclick="setSections(this.form)" />'."\n");
1.188 raeburn 1634: }
1.88 raeburn 1635: }
1.188 raeburn 1636: $r->print(&Apache::lonhtmlcommon::echo_form_input(['phase','userrole','ccdomain','prevphase','currstate','ccuname','ccdomain']));
1.179 raeburn 1637: $r->print('<input type="hidden" name="currstate" value="" />');
1.393 raeburn 1638: $r->print('<input type="hidden" name="prevphase" value="'.$env{'form.phase'}.'" /></form><br /><br />');
1.218 raeburn 1639: return;
1.2 www 1640: }
1.1 www 1641:
1.213 raeburn 1642: sub singleuser_breadcrumb {
1.422 raeburn 1643: my ($crstype,$context,$domain) = @_;
1.213 raeburn 1644: my %breadcrumb_text;
1645: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1646: if ($crstype eq 'Community') {
1647: $breadcrumb_text{'search'} = 'Enroll a member';
1648: } else {
1649: $breadcrumb_text{'search'} = 'Enroll a student';
1650: }
1.422 raeburn 1651: $breadcrumb_text{'userpicked'} = 'Select a user';
1652: $breadcrumb_text{'modify'} = 'Set section/dates';
1.416 raeburn 1653: } elsif ($env{'form.action'} eq 'accesslogs') {
1654: $breadcrumb_text{'search'} = 'View access logs for a user';
1.422 raeburn 1655: $breadcrumb_text{'userpicked'} = 'Select a user';
1656: $breadcrumb_text{'activity'} = 'Activity';
1657: } elsif (($env{'form.action'} eq 'singleuser') && ($context eq 'domain') &&
1658: (!&Apache::lonnet::allowed('mau',$domain))) {
1659: $breadcrumb_text{'search'} = "View user's roles";
1660: $breadcrumb_text{'userpicked'} = 'Select a user';
1661: $breadcrumb_text{'modify'} = 'User roles';
1.213 raeburn 1662: } else {
1.229 raeburn 1663: $breadcrumb_text{'search'} = 'Create/modify a user';
1.422 raeburn 1664: $breadcrumb_text{'userpicked'} = 'Select a user';
1665: $breadcrumb_text{'modify'} = 'Set user role';
1.213 raeburn 1666: }
1667: return %breadcrumb_text;
1668: }
1669:
1670: sub date_sections_select {
1.375 raeburn 1671: my ($context,$newuser,$formname,$permission,$crstype,$ccuname,$ccdomain,
1672: $showcredits) = @_;
1673: my $credits;
1674: if ($showcredits) {
1675: my $defaultcredits = &Apache::lonuserutils::get_defaultcredits();
1676: $credits = &get_user_credits($ccuname,$ccdomain,$defaultcredits);
1677: if ($credits eq '') {
1678: $credits = $defaultcredits;
1679: }
1680: }
1.213 raeburn 1681: my $cid = $env{'request.course.id'};
1682: my ($cnum,$cdom) = &Apache::lonuserutils::get_course_identity($cid);
1683: my $date_table = '<h3>'.&mt('Starting and Ending Dates').'</h3>'."\n".
1684: &Apache::lonuserutils::date_setting_table(undef,undef,$context,
1685: undef,$formname,$permission);
1686: my $rowtitle = 'Section';
1.375 raeburn 1687: my $secbox = '<h3>'.&mt('Section and Credits').'</h3>'."\n".
1.213 raeburn 1688: &Apache::lonuserutils::section_picker($cdom,$cnum,'st',$rowtitle,
1.375 raeburn 1689: $permission,$context,'',$crstype,
1690: $showcredits,$credits);
1.213 raeburn 1691: my $output = $date_table.$secbox;
1692: return $output;
1693: }
1694:
1.216 raeburn 1695: sub validation_javascript {
1.375 raeburn 1696: my ($context,$ccdomain,$pjump_def,$crstype,$groupslist,$newuser,$formname,
1.216 raeburn 1697: $loaditem) = @_;
1698: my $dc_setcourse_code = '';
1699: my $nondc_setsection_code = '';
1700: if ($context eq 'domain') {
1701: my $dcdom = $env{'request.role.domain'};
1702: $loaditem->{'onload'} = "document.cu.coursedesc.value='';";
1.227 raeburn 1703: $dc_setcourse_code =
1704: &Apache::lonuserutils::dc_setcourse_js('cu','singleuser',$context);
1.216 raeburn 1705: } else {
1.227 raeburn 1706: my $checkauth;
1707: if (($newuser) || (&Apache::lonnet::allowed('mau',$ccdomain))) {
1708: $checkauth = 1;
1709: }
1710: if ($context eq 'course') {
1711: $nondc_setsection_code =
1712: &Apache::lonuserutils::setsections_javascript($formname,$groupslist,
1.375 raeburn 1713: undef,$checkauth,
1714: $crstype);
1.227 raeburn 1715: }
1716: if ($checkauth) {
1717: $nondc_setsection_code .=
1718: &Apache::lonuserutils::verify_authen($formname,$context);
1719: }
1.216 raeburn 1720: }
1721: my $js = &user_modification_js($pjump_def,$dc_setcourse_code,
1722: $nondc_setsection_code,$groupslist);
1723: my ($jsback,$elements) = &crumb_utilities();
1724: $js .= "\n".
1.301 bisitz 1725: '<script type="text/javascript">'."\n".
1726: '// <![CDATA['."\n".
1727: $jsback."\n".
1728: '// ]]>'."\n".
1729: '</script>'."\n";
1.216 raeburn 1730: return $js;
1731: }
1732:
1.217 raeburn 1733: sub display_existing_roles {
1.375 raeburn 1734: my ($r,$ccuname,$ccdomain,$inccourses,$context,$roledom,$crstype,
1.418 raeburn 1735: $showcredits,$statuses) = @_;
1.329 raeburn 1736: my $now=time;
1.418 raeburn 1737: my $showall = 1;
1738: my ($showexpired,$showactive);
1739: if ((ref($statuses) eq 'ARRAY') && (@{$statuses} > 0)) {
1740: $showall = 0;
1741: if (grep(/^expired$/,@{$statuses})) {
1742: $showexpired = 1;
1743: }
1744: if (grep(/^active$/,@{$statuses})) {
1745: $showactive = 1;
1746: }
1747: if ($showexpired && $showactive) {
1748: $showall = 1;
1749: }
1750: }
1.329 raeburn 1751: my %lt=&Apache::lonlocal::texthash(
1.217 raeburn 1752: 'rer' => "Existing Roles",
1753: 'rev' => "Revoke",
1754: 'del' => "Delete",
1755: 'ren' => "Re-Enable",
1756: 'rol' => "Role",
1757: 'ext' => "Extent",
1.375 raeburn 1758: 'crd' => "Credits",
1.217 raeburn 1759: 'sta' => "Start",
1760: 'end' => "End",
1761: );
1.329 raeburn 1762: my (%rolesdump,%roletext,%sortrole,%roleclass,%rolepriv);
1763: if ($context eq 'course' || $context eq 'author') {
1764: my @roles = &Apache::lonuserutils::roles_by_context($context,1,$crstype);
1765: my %roleshash =
1766: &Apache::lonnet::get_my_roles($ccuname,$ccdomain,'userroles',
1767: ['active','previous','future'],\@roles,$roledom,1);
1768: foreach my $key (keys(%roleshash)) {
1769: my ($start,$end) = split(':',$roleshash{$key});
1770: next if ($start eq '-1' || $end eq '-1');
1771: my ($rnum,$rdom,$role,$sec) = split(':',$key);
1772: if ($context eq 'course') {
1773: next unless (($rnum eq $env{'course.'.$env{'request.course.id'}.'.num'})
1774: && ($rdom eq $env{'course.'.$env{'request.course.id'}.'.domain'}));
1775: } elsif ($context eq 'author') {
1776: next unless (($rnum eq $env{'user.name'}) && ($rdom eq $env{'request.role.domain'}));
1777: }
1778: my ($newkey,$newvalue,$newrole);
1779: $newkey = '/'.$rdom.'/'.$rnum;
1780: if ($sec ne '') {
1781: $newkey .= '/'.$sec;
1782: }
1783: $newvalue = $role;
1784: if ($role =~ /^cr/) {
1785: $newrole = 'cr';
1786: } else {
1787: $newrole = $role;
1788: }
1789: $newkey .= '_'.$newrole;
1790: if ($start ne '' && $end ne '') {
1791: $newvalue .= '_'.$end.'_'.$start;
1.335 raeburn 1792: } elsif ($end ne '') {
1793: $newvalue .= '_'.$end;
1.329 raeburn 1794: }
1795: $rolesdump{$newkey} = $newvalue;
1796: }
1797: } else {
1.360 raeburn 1798: %rolesdump=&Apache::lonnet::dump('roles',$ccdomain,$ccuname);
1.329 raeburn 1799: }
1800: # Build up table of user roles to allow revocation and re-enabling of roles.
1801: my ($tmp) = keys(%rolesdump);
1802: return if ($tmp =~ /^(con_lost|error)/i);
1803: foreach my $area (sort { my $a1=join('_',(split('_',$a))[1,0]);
1804: my $b1=join('_',(split('_',$b))[1,0]);
1805: return $a1 cmp $b1;
1806: } keys(%rolesdump)) {
1807: next if ($area =~ /^rolesdef/);
1808: my $envkey=$area;
1809: my $role = $rolesdump{$area};
1810: my $thisrole=$area;
1811: $area =~ s/\_\w\w$//;
1812: my ($role_code,$role_end_time,$role_start_time) =
1813: split(/_/,$role);
1.418 raeburn 1814: my $active=1;
1815: $active=0 if (($role_end_time) && ($now>$role_end_time));
1816: if ($active) {
1817: next unless($showall || $showactive);
1818: } else {
1.430 raeburn 1819: next unless($showall || $showexpired);
1.418 raeburn 1820: }
1.217 raeburn 1821: # Is this a custom role? Get role owner and title.
1.329 raeburn 1822: my ($croleudom,$croleuname,$croletitle)=
1823: ($role_code=~m{^cr/($match_domain)/($match_username)/(\w+)$});
1824: my $allowed=0;
1825: my $delallowed=0;
1826: my $sortkey=$role_code;
1827: my $class='Unknown';
1.375 raeburn 1828: my $credits='';
1.418 raeburn 1829: my $csec;
1.421 raeburn 1830: if ($area =~ m{^/($match_domain)/($match_courseid)}) {
1.329 raeburn 1831: $class='Course';
1832: my ($coursedom,$coursedir) = ($1,$2);
1833: my $cid = $1.'_'.$2;
1834: # $1.'_'.$2 is the course id (eg. 103_12345abcef103l3).
1.421 raeburn 1835: next if ($envkey =~ m{^/$match_domain/$match_courseid/[A-Za-z0-9]+_gr$});
1.329 raeburn 1836: my %coursedata=
1837: &Apache::lonnet::coursedescription($cid);
1838: if ($coursedir =~ /^$match_community$/) {
1839: $class='Community';
1840: }
1841: $sortkey.="\0$coursedom";
1842: my $carea;
1843: if (defined($coursedata{'description'})) {
1844: $carea=$coursedata{'description'}.
1845: '<br />'.&mt('Domain').': '.$coursedom.(' 'x8).
1846: &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$coursedir,$coursedom);
1847: $sortkey.="\0".$coursedata{'description'};
1848: } else {
1849: if ($class eq 'Community') {
1850: $carea=&mt('Unavailable community').': '.$area;
1851: $sortkey.="\0".&mt('Unavailable community').': '.$area;
1.217 raeburn 1852: } else {
1853: $carea=&mt('Unavailable course').': '.$area;
1854: $sortkey.="\0".&mt('Unavailable course').': '.$area;
1855: }
1.329 raeburn 1856: }
1857: $sortkey.="\0$coursedir";
1858: $inccourses->{$cid}=1;
1.375 raeburn 1859: if (($showcredits) && ($class eq 'Course') && ($role_code eq 'st')) {
1860: my $defaultcredits = $coursedata{'internal.defaultcredits'};
1861: $credits =
1862: &get_user_credits($ccuname,$ccdomain,$defaultcredits,
1863: $coursedom,$coursedir);
1864: if ($credits eq '') {
1865: $credits = $defaultcredits;
1866: }
1867: }
1.329 raeburn 1868: if ((&Apache::lonnet::allowed('c'.$role_code,$coursedom.'/'.$coursedir)) ||
1869: (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) {
1870: $allowed=1;
1871: }
1872: unless ($allowed) {
1.365 raeburn 1873: my $isowner = &Apache::lonuserutils::is_courseowner($cid,$coursedata{'internal.courseowner'});
1.329 raeburn 1874: if ($isowner) {
1875: if (($role_code eq 'co') && ($class eq 'Community')) {
1876: $allowed = 1;
1877: } elsif (($role_code eq 'cc') && ($class eq 'Course')) {
1878: $allowed = 1;
1879: }
1.217 raeburn 1880: }
1.329 raeburn 1881: }
1882: if ((&Apache::lonnet::allowed('dro',$coursedom)) ||
1883: (&Apache::lonnet::allowed('dro',$ccdomain))) {
1884: $delallowed=1;
1885: }
1.217 raeburn 1886: # - custom role. Needs more info, too
1.329 raeburn 1887: if ($croletitle) {
1888: if (&Apache::lonnet::allowed('ccr',$coursedom.'/'.$coursedir)) {
1889: $allowed=1;
1890: $thisrole.='.'.$role_code;
1.217 raeburn 1891: }
1.329 raeburn 1892: }
1.418 raeburn 1893: if ($area=~m{^/($match_domain/$match_courseid/(\w+))}) {
1894: $csec = $2;
1895: $carea.='<br />'.&mt('Section: [_1]',$csec);
1896: $sortkey.="\0$csec";
1.329 raeburn 1897: if (!$allowed) {
1.418 raeburn 1898: if ($env{'request.course.sec'} eq $csec) {
1899: if (&Apache::lonnet::allowed('c'.$role_code,$1)) {
1.329 raeburn 1900: $allowed = 1;
1.217 raeburn 1901: }
1902: }
1903: }
1.329 raeburn 1904: }
1905: $area=$carea;
1906: } else {
1907: $sortkey.="\0".$area;
1908: # Determine if current user is able to revoke privileges
1909: if ($area=~m{^/($match_domain)/}) {
1910: if ((&Apache::lonnet::allowed('c'.$role_code,$1)) ||
1911: (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) {
1912: $allowed=1;
1.217 raeburn 1913: }
1.329 raeburn 1914: if (((&Apache::lonnet::allowed('dro',$1)) ||
1915: (&Apache::lonnet::allowed('dro',$ccdomain))) &&
1916: ($role_code ne 'dc')) {
1917: $delallowed=1;
1.217 raeburn 1918: }
1.329 raeburn 1919: } else {
1920: if (&Apache::lonnet::allowed('c'.$role_code,'/')) {
1.217 raeburn 1921: $allowed=1;
1922: }
1923: }
1.363 raeburn 1924: if ($role_code eq 'ca' || $role_code eq 'au' || $role_code eq 'aa') {
1.377 raeburn 1925: $class='Authoring Space';
1.329 raeburn 1926: } elsif ($role_code eq 'su') {
1927: $class='System';
1.217 raeburn 1928: } else {
1.329 raeburn 1929: $class='Domain';
1.217 raeburn 1930: }
1.329 raeburn 1931: }
1932: if (($role_code eq 'ca') || ($role_code eq 'aa')) {
1933: $area=~m{/($match_domain)/($match_username)};
1934: if (&Apache::lonuserutils::authorpriv($2,$1)) {
1935: $allowed=1;
1.217 raeburn 1936: } else {
1.329 raeburn 1937: $allowed=0;
1.217 raeburn 1938: }
1.329 raeburn 1939: }
1940: my $row = '';
1.418 raeburn 1941: if ($showall) {
1942: $row.= '<td>';
1943: if (($active) && ($allowed)) {
1944: $row.= '<input type="checkbox" name="rev:'.$thisrole.'" />';
1945: } else {
1946: if ($active) {
1947: $row.=' ';
1948: } else {
1949: $row.=&mt('expired or revoked');
1950: }
1951: }
1952: $row.='</td><td>';
1953: if ($allowed && !$active) {
1954: $row.= '<input type="checkbox" name="ren:'.$thisrole.'" />';
1955: } else {
1956: $row.=' ';
1957: }
1958: $row.='</td><td>';
1959: if ($delallowed) {
1960: $row.= '<input type="checkbox" name="del:'.$thisrole.'" />';
1.217 raeburn 1961: } else {
1.418 raeburn 1962: $row.=' ';
1.217 raeburn 1963: }
1.430 raeburn 1964: $row.= '</td>';
1.329 raeburn 1965: }
1966: my $plaintext='';
1967: if (!$croletitle) {
1.375 raeburn 1968: $plaintext=&Apache::lonnet::plaintext($role_code,$class);
1969: if (($showcredits) && ($credits ne '')) {
1970: $plaintext .= '<br/ ><span class="LC_nobreak">'.
1971: '<span class="LC_fontsize_small">'.
1972: &mt('Credits: [_1]',$credits).
1973: '</span></span>';
1974: }
1.329 raeburn 1975: } else {
1976: $plaintext=
1.395 bisitz 1977: &mt('Custom role [_1][_2]defined by [_3]',
1.346 bisitz 1978: '"'.$croletitle.'"',
1979: '<br />',
1980: $croleuname.':'.$croleudom);
1.329 raeburn 1981: }
1.418 raeburn 1982: $row.= '<td>'.$plaintext.'</td>'.
1983: '<td>'.$area.'</td>'.
1984: '<td>'.($role_start_time?&Apache::lonlocal::locallocaltime($role_start_time)
1985: : ' ' ).'</td>'.
1986: '<td>'.($role_end_time ?&Apache::lonlocal::locallocaltime($role_end_time)
1987: : ' ' ).'</td>';
1.329 raeburn 1988: $sortrole{$sortkey}=$envkey;
1989: $roletext{$envkey}=$row;
1990: $roleclass{$envkey}=$class;
1.418 raeburn 1991: if ($allowed) {
1992: $rolepriv{$envkey}='edit';
1993: } else {
1994: if ($context eq 'domain') {
1.420 raeburn 1995: if ((&Apache::lonnet::allowed('vur',$ccdomain)) &&
1.421 raeburn 1996: ($envkey=~m{^/$ccdomain/})) {
1.418 raeburn 1997: $rolepriv{$envkey}='view';
1998: }
1999: } elsif ($context eq 'course') {
2000: if ((&Apache::lonnet::allowed('vcl',$env{'request.course.id'})) ||
2001: ($env{'request.course.sec'} && ($env{'request.course.sec'} eq $csec) &&
2002: &Apache::lonnet::allowed('vcl',$env{'request.course.id'}.'/'.$env{'request.course.sec'}))) {
2003: $rolepriv{$envkey}='view';
2004: }
2005: }
2006: }
1.329 raeburn 2007: } # end of foreach (table building loop)
2008:
2009: my $rolesdisplay = 0;
2010: my %output = ();
1.377 raeburn 2011: foreach my $type ('Authoring Space','Course','Community','Domain','System','Unknown') {
1.329 raeburn 2012: $output{$type} = '';
2013: foreach my $which (sort {uc($a) cmp uc($b)} (keys(%sortrole))) {
2014: if ( ($roleclass{$sortrole{$which}} =~ /^\Q$type\E/ ) && ($rolepriv{$sortrole{$which}}) ) {
2015: $output{$type}.=
2016: &Apache::loncommon::start_data_table_row().
2017: $roletext{$sortrole{$which}}.
2018: &Apache::loncommon::end_data_table_row();
1.217 raeburn 2019: }
1.329 raeburn 2020: }
2021: unless($output{$type} eq '') {
2022: $output{$type} = '<tr class="LC_info_row">'.
2023: "<td align='center' colspan='7'>".&mt($type)."</td></tr>".
2024: $output{$type};
2025: $rolesdisplay = 1;
2026: }
2027: }
2028: if ($rolesdisplay == 1) {
2029: my $contextrole='';
2030: if ($env{'request.course.id'}) {
2031: if (&Apache::loncommon::course_type() eq 'Community') {
2032: $contextrole = &mt('Existing Roles in this Community');
1.290 bisitz 2033: } else {
1.329 raeburn 2034: $contextrole = &mt('Existing Roles in this Course');
1.290 bisitz 2035: }
1.329 raeburn 2036: } elsif ($env{'request.role'} =~ /^au\./) {
1.377 raeburn 2037: $contextrole = &mt('Existing Co-Author Roles in your Authoring Space');
1.329 raeburn 2038: } else {
1.418 raeburn 2039: if ($showall) {
2040: $contextrole = &mt('Existing Roles in this Domain');
2041: } elsif ($showactive) {
2042: $contextrole = &mt('Unexpired Roles in this Domain');
2043: } elsif ($showexpired) {
2044: $contextrole = &mt('Expired or Revoked Roles in this Domain');
2045: }
1.329 raeburn 2046: }
1.393 raeburn 2047: $r->print('<div class="LC_left_float">'.
1.375 raeburn 2048: '<fieldset><legend>'.$contextrole.'</legend>'.
1.217 raeburn 2049: &Apache::loncommon::start_data_table("LC_createuser").
1.418 raeburn 2050: &Apache::loncommon::start_data_table_header_row());
2051: if ($showall) {
2052: $r->print(
1.419 raeburn 2053: '<th>'.$lt{'rev'}.'</th><th>'.$lt{'ren'}.'</th><th>'.$lt{'del'}.'</th>'
1.418 raeburn 2054: );
2055: } elsif ($showexpired) {
2056: $r->print('<th>'.$lt{'rev'}.'</th>');
2057: }
2058: $r->print(
1.419 raeburn 2059: '<th>'.$lt{'rol'}.'</th><th>'.$lt{'ext'}.'</th>'.
2060: '<th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'.
1.217 raeburn 2061: &Apache::loncommon::end_data_table_header_row());
1.377 raeburn 2062: foreach my $type ('Authoring Space','Course','Community','Domain','System','Unknown') {
1.329 raeburn 2063: if ($output{$type}) {
2064: $r->print($output{$type}."\n");
1.217 raeburn 2065: }
2066: }
1.375 raeburn 2067: $r->print(&Apache::loncommon::end_data_table().
2068: '</fieldset></div>');
1.329 raeburn 2069: }
1.217 raeburn 2070: return;
2071: }
2072:
1.218 raeburn 2073: sub new_coauthor_roles {
2074: my ($r,$ccuname,$ccdomain) = @_;
2075: my $addrolesdisplay = 0;
2076: #
2077: # Co-Author
2078: #
2079: if (&Apache::lonuserutils::authorpriv($env{'user.name'},
2080: $env{'request.role.domain'}) &&
2081: ($env{'user.name'} ne $ccuname || $env{'user.domain'} ne $ccdomain)) {
2082: # No sense in assigning co-author role to yourself
2083: $addrolesdisplay = 1;
2084: my $cuname=$env{'user.name'};
2085: my $cudom=$env{'request.role.domain'};
2086: my %lt=&Apache::lonlocal::texthash(
1.377 raeburn 2087: 'cs' => "Authoring Space",
1.218 raeburn 2088: 'act' => "Activate",
2089: 'rol' => "Role",
2090: 'ext' => "Extent",
2091: 'sta' => "Start",
2092: 'end' => "End",
2093: 'cau' => "Co-Author",
2094: 'caa' => "Assistant Co-Author",
2095: 'ssd' => "Set Start Date",
2096: 'sed' => "Set End Date"
2097: );
2098: $r->print('<h4>'.$lt{'cs'}.'</h4>'."\n".
2099: &Apache::loncommon::start_data_table()."\n".
2100: &Apache::loncommon::start_data_table_header_row()."\n".
2101: '<th>'.$lt{'act'}.'</th><th>'.$lt{'rol'}.'</th>'.
2102: '<th>'.$lt{'ext'}.'</th><th>'.$lt{'sta'}.'</th>'.
2103: '<th>'.$lt{'end'}.'</th>'."\n".
2104: &Apache::loncommon::end_data_table_header_row()."\n".
2105: &Apache::loncommon::start_data_table_row().'
2106: <td>
1.291 bisitz 2107: <input type="checkbox" name="act_'.$cudom.'_'.$cuname.'_ca" />
1.218 raeburn 2108: </td>
2109: <td>'.$lt{'cau'}.'</td>
2110: <td>'.$cudom.'_'.$cuname.'</td>
2111: <td><input type="hidden" name="start_'.$cudom.'_'.$cuname.'_ca" value="" />
2112: <a href=
2113: "javascript:pjump('."'date_start','Start Date Co-Author',document.cu.start_$cudom\_$cuname\_ca.value,'start_$cudom\_$cuname\_ca','cu.pres','dateset'".')">'.$lt{'ssd'}.'</a></td>
2114: <td><input type="hidden" name="end_'.$cudom.'_'.$cuname.'_ca" value="" />
2115: <a href=
2116: "javascript:pjump('."'date_end','End Date Co-Author',document.cu.end_$cudom\_$cuname\_ca.value,'end_$cudom\_$cuname\_ca','cu.pres','dateset'".')">'.$lt{'sed'}.'</a></td>'."\n".
2117: &Apache::loncommon::end_data_table_row()."\n".
2118: &Apache::loncommon::start_data_table_row()."\n".
1.291 bisitz 2119: '<td><input type="checkbox" name="act_'.$cudom.'_'.$cuname.'_aa" /></td>
1.218 raeburn 2120: <td>'.$lt{'caa'}.'</td>
2121: <td>'.$cudom.'_'.$cuname.'</td>
2122: <td><input type="hidden" name="start_'.$cudom.'_'.$cuname.'_aa" value="" />
2123: <a href=
2124: "javascript:pjump('."'date_start','Start Date Assistant Co-Author',document.cu.start_$cudom\_$cuname\_aa.value,'start_$cudom\_$cuname\_aa','cu.pres','dateset'".')">'.$lt{'ssd'}.'</a></td>
2125: <td><input type="hidden" name="end_'.$cudom.'_'.$cuname.'_aa" value="" />
2126: <a href=
2127: "javascript:pjump('."'date_end','End Date Assistant Co-Author',document.cu.end_$cudom\_$cuname\_aa.value,'end_$cudom\_$cuname\_aa','cu.pres','dateset'".')">'.$lt{'sed'}.'</a></td>'."\n".
2128: &Apache::loncommon::end_data_table_row()."\n".
2129: &Apache::loncommon::end_data_table());
2130: } elsif ($env{'request.role'} =~ /^au\./) {
2131: if (!(&Apache::lonuserutils::authorpriv($env{'user.name'},
2132: $env{'request.role.domain'}))) {
2133: $r->print('<span class="LC_error">'.
2134: &mt('You do not have privileges to assign co-author roles.').
2135: '</span>');
2136: } elsif (($env{'user.name'} eq $ccuname) &&
2137: ($env{'user.domain'} eq $ccdomain)) {
1.377 raeburn 2138: $r->print(&mt('Assigning yourself a co-author or assistant co-author role in your own author area in Authoring Space is not permitted'));
1.218 raeburn 2139: }
2140: }
2141: return $addrolesdisplay;;
2142: }
2143:
2144: sub new_domain_roles {
1.357 raeburn 2145: my ($r,$ccdomain) = @_;
1.218 raeburn 2146: my $addrolesdisplay = 0;
2147: #
2148: # Domain level
2149: #
2150: my $num_domain_level = 0;
2151: my $domaintext =
2152: '<h4>'.&mt('Domain Level').'</h4>'.
2153: &Apache::loncommon::start_data_table().
2154: &Apache::loncommon::start_data_table_header_row().
2155: '<th>'.&mt('Activate').'</th><th>'.&mt('Role').'</th><th>'.
2156: &mt('Extent').'</th>'.
2157: '<th>'.&mt('Start').'</th><th>'.&mt('End').'</th>'.
2158: &Apache::loncommon::end_data_table_header_row();
1.312 raeburn 2159: my @allroles = &Apache::lonuserutils::roles_by_context('domain');
1.445 raeburn 2160: my $uprimary = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
2161: my $uintdom = &Apache::lonnet::internet_dom($uprimary);
1.218 raeburn 2162: foreach my $thisdomain (sort(&Apache::lonnet::all_domains())) {
1.312 raeburn 2163: foreach my $role (@allroles) {
2164: next if ($role eq 'ad');
1.357 raeburn 2165: next if (($role eq 'au') && ($ccdomain ne $thisdomain));
1.218 raeburn 2166: if (&Apache::lonnet::allowed('c'.$role,$thisdomain)) {
1.445 raeburn 2167: if ($role eq 'dc') {
2168: unless ($thisdomain eq $env{'request.role.domain'}) {
2169: my $domprim = &Apache::lonnet::domain($thisdomain,'primary');
2170: my $intdom = &Apache::lonnet::internet_dom($domprim);
2171: next unless ($uintdom eq $intdom);
2172: }
2173: }
1.218 raeburn 2174: my $plrole=&Apache::lonnet::plaintext($role);
2175: my %lt=&Apache::lonlocal::texthash(
2176: 'ssd' => "Set Start Date",
2177: 'sed' => "Set End Date"
2178: );
2179: $num_domain_level ++;
2180: $domaintext .=
2181: &Apache::loncommon::start_data_table_row().
1.291 bisitz 2182: '<td><input type="checkbox" name="act_'.$thisdomain.'_'.$role.'" /></td>
1.218 raeburn 2183: <td>'.$plrole.'</td>
2184: <td>'.$thisdomain.'</td>
2185: <td><input type="hidden" name="start_'.$thisdomain.'_'.$role.'" value="" />
2186: <a href=
2187: "javascript:pjump('."'date_start','Start Date $plrole',document.cu.start_$thisdomain\_$role.value,'start_$thisdomain\_$role','cu.pres','dateset'".')">'.$lt{'ssd'}.'</a></td>
2188: <td><input type="hidden" name="end_'.$thisdomain.'_'.$role.'" value="" />
2189: <a href=
2190: "javascript:pjump('."'date_end','End Date $plrole',document.cu.end_$thisdomain\_$role.value,'end_$thisdomain\_$role','cu.pres','dateset'".')">'.$lt{'sed'}.'</a></td>'.
2191: &Apache::loncommon::end_data_table_row();
2192: }
2193: }
2194: }
2195: $domaintext.= &Apache::loncommon::end_data_table();
2196: if ($num_domain_level > 0) {
2197: $r->print($domaintext);
2198: $addrolesdisplay = 1;
2199: }
2200: return $addrolesdisplay;
2201: }
2202:
1.188 raeburn 2203: sub user_authentication {
1.451 raeburn 2204: my ($ccuname,$ccdomain,$formname,$crstype,$permission) = @_;
1.188 raeburn 2205: my $currentauth=&Apache::lonnet::queryauthenticate($ccuname,$ccdomain);
1.227 raeburn 2206: my $outcome;
1.418 raeburn 2207: my %lt=&Apache::lonlocal::texthash(
2208: 'err' => "ERROR",
2209: 'uuas' => "This user has an unrecognized authentication scheme",
2210: 'adcs' => "Please alert a domain coordinator of this situation",
2211: 'sldb' => "Please specify login data below",
2212: 'ld' => "Login Data"
2213: );
1.188 raeburn 2214: # Check for a bad authentication type
1.449 raeburn 2215: if ($currentauth !~ /^(krb4|krb5|unix|internal|localauth|lti):/) {
1.188 raeburn 2216: # bad authentication scheme
2217: if (&Apache::lonnet::allowed('mau',$ccdomain)) {
1.227 raeburn 2218: &initialize_authen_forms($ccdomain,$formname);
2219:
1.190 raeburn 2220: my $choices = &Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc);
1.188 raeburn 2221: $outcome = <<ENDBADAUTH;
2222: <script type="text/javascript" language="Javascript">
1.301 bisitz 2223: // <![CDATA[
1.188 raeburn 2224: $loginscript
1.301 bisitz 2225: // ]]>
1.188 raeburn 2226: </script>
2227: <span class="LC_error">$lt{'err'}:
2228: $lt{'uuas'} ($currentauth). $lt{'sldb'}.</span>
2229: <h3>$lt{'ld'}</h3>
2230: $choices
2231: ENDBADAUTH
2232: } else {
2233: # This user is not allowed to modify the user's
2234: # authentication scheme, so just notify them of the problem
2235: $outcome = <<ENDBADAUTH;
2236: <span class="LC_error"> $lt{'err'}:
2237: $lt{'uuas'} ($currentauth). $lt{'adcs'}.
2238: </span>
2239: ENDBADAUTH
2240: }
2241: } else { # Authentication type is valid
1.418 raeburn 2242:
1.227 raeburn 2243: &initialize_authen_forms($ccdomain,$formname,$currentauth,'modifyuser');
1.205 raeburn 2244: my ($authformcurrent,$can_modify,@authform_others) =
1.188 raeburn 2245: &modify_login_block($ccdomain,$currentauth);
2246: if (&Apache::lonnet::allowed('mau',$ccdomain)) {
2247: # Current user has login modification privileges
2248: $outcome =
2249: '<script type="text/javascript" language="Javascript">'."\n".
1.301 bisitz 2250: '// <![CDATA['."\n".
1.188 raeburn 2251: $loginscript."\n".
1.301 bisitz 2252: '// ]]>'."\n".
1.188 raeburn 2253: '</script>'."\n".
2254: '<h3>'.$lt{'ld'}.'</h3>'.
2255: &Apache::loncommon::start_data_table().
1.205 raeburn 2256: &Apache::loncommon::start_data_table_row().
1.188 raeburn 2257: '<td>'.$authformnop;
1.418 raeburn 2258: if (($can_modify) && (&Apache::lonnet::allowed('mau',$ccdomain))) {
1.188 raeburn 2259: $outcome .= '</td>'."\n".
2260: &Apache::loncommon::end_data_table_row().
2261: &Apache::loncommon::start_data_table_row().
2262: '<td>'.$authformcurrent.'</td>'.
2263: &Apache::loncommon::end_data_table_row()."\n";
2264: } else {
1.200 raeburn 2265: $outcome .= ' ('.$authformcurrent.')</td>'.
2266: &Apache::loncommon::end_data_table_row()."\n";
1.188 raeburn 2267: }
1.418 raeburn 2268: if (&Apache::lonnet::allowed('mau',$ccdomain)) {
2269: foreach my $item (@authform_others) {
2270: $outcome .= &Apache::loncommon::start_data_table_row().
2271: '<td>'.$item.'</td>'.
2272: &Apache::loncommon::end_data_table_row()."\n";
2273: }
1.188 raeburn 2274: }
1.205 raeburn 2275: $outcome .= &Apache::loncommon::end_data_table();
1.188 raeburn 2276: } else {
1.451 raeburn 2277: if (($currentauth =~ /^internal:/) &&
2278: (&Apache::lonuserutils::can_change_internalpass($ccuname,$ccdomain,$crstype,$permission))) {
2279: $outcome = <<"ENDJS";
2280: <script type="text/javascript">
2281: // <![CDATA[
2282: function togglePwd(form) {
2283: if (form.newintpwd.length) {
2284: if (document.getElementById('LC_ownersetpwd')) {
2285: for (var i=0; i<form.newintpwd.length; i++) {
2286: if (form.newintpwd[i].checked) {
2287: if (form.newintpwd[i].value == 1) {
2288: document.getElementById('LC_ownersetpwd').style.display = 'inline-block';
2289: } else {
2290: document.getElementById('LC_ownersetpwd').style.display = 'none';
2291: }
2292: }
2293: }
2294: }
2295: }
2296: }
2297: // ]]>
2298: </script>
2299: ENDJS
2300:
2301: $outcome .= '<h3>'.$lt{'ld'}.'</h3>'.
2302: &Apache::loncommon::start_data_table().
2303: &Apache::loncommon::start_data_table_row().
2304: '<td>'.&mt('Internally authenticated').'<br />'.&mt("Change user's password?").
2305: '<label><input type="radio" name="newintpwd" value="0" checked="checked" onclick="togglePwd(this.form);" />'.
2306: &mt('No').'</label>'.(' 'x2).
2307: '<label><input type="radio" name="newintpwd" value="1" onclick="togglePwd(this.form);" />'.&mt('Yes').'</label>'.
2308: '<div id="LC_ownersetpwd" style="display:none">'.
2309: ' '.&mt('Password').' <input type="password" size="15" name="intarg" value="" />'.
2310: '<label><input type="checkbox" name="visible" onclick="if (this.checked) { this.form.intarg.type='."'text'".' } else { this.form.intarg.type='."'password'".' }" />'.&mt('Visible input').'</label></div></td>'.
2311: &Apache::loncommon::end_data_table_row().
2312: &Apache::loncommon::end_data_table();
2313: }
1.418 raeburn 2314: if (&Apache::lonnet::allowed('udp',$ccdomain)) {
2315: # Current user has rights to view domain preferences for user's domain
2316: my $result;
2317: if ($currentauth =~ /^krb(4|5):([^:]*)$/) {
2318: my ($krbver,$krbrealm) = ($1,$2);
2319: if ($krbrealm eq '') {
2320: $result = &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
2321: } else {
2322: $result = &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
1.426 raeburn 2323: $krbrealm,$krbver);
1.418 raeburn 2324: }
2325: } elsif ($currentauth =~ /^internal:/) {
2326: $result = &mt('Currently internally authenticated.');
2327: } elsif ($currentauth =~ /^localauth:/) {
2328: $result = &mt('Currently using local (institutional) authentication.');
2329: } elsif ($currentauth =~ /^unix:/) {
2330: $result = &mt('Currently Filesystem Authenticated.');
1.449 raeburn 2331: } elsif ($currentauth =~ /^lti:/) {
1.451 raeburn 2332: $result = &mt('Currently LTI authenticated.');
1.418 raeburn 2333: }
2334: $outcome = '<h3>'.$lt{'ld'}.'</h3>'.
2335: &Apache::loncommon::start_data_table().
2336: &Apache::loncommon::start_data_table_row().
2337: '<td>'.$result.'</td>'.
2338: &Apache::loncommon::end_data_table_row()."\n".
2339: &Apache::loncommon::end_data_table();
2340: } elsif (&Apache::lonnet::allowed('mau',$env{'request.role.domain'})) {
1.188 raeburn 2341: my %lt=&Apache::lonlocal::texthash(
2342: 'ccld' => "Change Current Login Data",
2343: 'yodo' => "You do not have privileges to modify the authentication configuration for this user.",
2344: 'ifch' => "If a change is required, contact a domain coordinator for the domain",
2345: );
2346: $outcome .= <<ENDNOPRIV;
2347: <h3>$lt{'ccld'}</h3>
2348: $lt{'yodo'} $lt{'ifch'}: $ccdomain
1.235 raeburn 2349: <input type="hidden" name="login" value="nochange" />
1.188 raeburn 2350: ENDNOPRIV
2351: }
2352: }
2353: } ## End of "check for bad authentication type" logic
2354: return $outcome;
2355: }
2356:
1.187 raeburn 2357: sub modify_login_block {
2358: my ($dom,$currentauth) = @_;
2359: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
2360: my ($authnum,%can_assign) =
2361: &Apache::loncommon::get_assignable_auth($dom);
1.205 raeburn 2362: my ($authformcurrent,@authform_others,$show_override_msg);
1.187 raeburn 2363: if ($currentauth=~/^krb(4|5):/) {
2364: $authformcurrent=$authformkrb;
2365: if ($can_assign{'int'}) {
1.205 raeburn 2366: push(@authform_others,$authformint);
1.187 raeburn 2367: }
2368: if ($can_assign{'loc'}) {
1.205 raeburn 2369: push(@authform_others,$authformloc);
1.187 raeburn 2370: }
1.449 raeburn 2371: if ($can_assign{'lti'}) {
2372: push(@authform_others,$authformlti);
2373: }
1.187 raeburn 2374: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
2375: $show_override_msg = 1;
2376: }
2377: } elsif ($currentauth=~/^internal:/) {
2378: $authformcurrent=$authformint;
2379: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205 raeburn 2380: push(@authform_others,$authformkrb);
1.187 raeburn 2381: }
2382: if ($can_assign{'loc'}) {
1.205 raeburn 2383: push(@authform_others,$authformloc);
1.187 raeburn 2384: }
1.449 raeburn 2385: if ($can_assign{'lti'}) {
2386: push(@authform_others,$authformlti);
2387: }
1.187 raeburn 2388: if ($can_assign{'int'}) {
2389: $show_override_msg = 1;
2390: }
2391: } elsif ($currentauth=~/^unix:/) {
2392: $authformcurrent=$authformfsys;
2393: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205 raeburn 2394: push(@authform_others,$authformkrb);
1.187 raeburn 2395: }
2396: if ($can_assign{'int'}) {
1.205 raeburn 2397: push(@authform_others,$authformint);
1.187 raeburn 2398: }
2399: if ($can_assign{'loc'}) {
1.205 raeburn 2400: push(@authform_others,$authformloc);
1.187 raeburn 2401: }
1.449 raeburn 2402: if ($can_assign{'lti'}) {
2403: push(@authform_others,$authformlti);
2404: }
1.187 raeburn 2405: if ($can_assign{'fsys'}) {
2406: $show_override_msg = 1;
2407: }
2408: } elsif ($currentauth=~/^localauth:/) {
2409: $authformcurrent=$authformloc;
2410: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205 raeburn 2411: push(@authform_others,$authformkrb);
1.187 raeburn 2412: }
2413: if ($can_assign{'int'}) {
1.205 raeburn 2414: push(@authform_others,$authformint);
1.187 raeburn 2415: }
1.449 raeburn 2416: if ($can_assign{'lti'}) {
2417: push(@authform_others,$authformlti);
2418: }
1.187 raeburn 2419: if ($can_assign{'loc'}) {
2420: $show_override_msg = 1;
2421: }
1.449 raeburn 2422: } elsif ($currentauth=~/^lti:/) {
2423: $authformcurrent=$authformlti;
2424: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
2425: push(@authform_others,$authformkrb);
2426: }
2427: if ($can_assign{'int'}) {
2428: push(@authform_others,$authformint);
2429: }
2430: if ($can_assign{'loc'}) {
2431: push(@authform_others,$authformloc);
2432: }
1.187 raeburn 2433: }
2434: if ($show_override_msg) {
1.205 raeburn 2435: $authformcurrent = '<table><tr><td colspan="3">'.$authformcurrent.
2436: '</td></tr>'."\n".
2437: '<tr><td> </td>'.
2438: '<td><b>'.&mt('Currently in use').'</b></td>'.
2439: '<td align="right"><span class="LC_cusr_emph">'.
1.187 raeburn 2440: &mt('will override current values').
1.205 raeburn 2441: '</span></td></tr></table>';
1.187 raeburn 2442: }
1.205 raeburn 2443: return ($authformcurrent,$show_override_msg,@authform_others);
1.187 raeburn 2444: }
2445:
1.188 raeburn 2446: sub personal_data_display {
1.456 raeburn 2447: my ($ccuname,$ccdomain,$newuser,$context,$inst_results,$rolesarray,$now,
2448: $captchaform,$emailusername,$usertype,$usernameset,$condition,$excluded,$showsubmit) = @_;
1.388 bisitz 2449: my ($output,%userenv,%canmodify,%canmodify_status);
1.219 raeburn 2450: my @userinfo = ('firstname','middlename','lastname','generation',
2451: 'permanentemail','id');
1.252 raeburn 2452: my $rowcount = 0;
2453: my $editable = 0;
1.391 raeburn 2454: my %textboxsize = (
2455: firstname => '15',
2456: middlename => '15',
2457: lastname => '15',
2458: generation => '5',
2459: permanentemail => '25',
2460: id => '15',
2461: );
2462:
2463: my %lt=&Apache::lonlocal::texthash(
2464: 'pd' => "Personal Data",
2465: 'firstname' => "First Name",
2466: 'middlename' => "Middle Name",
2467: 'lastname' => "Last Name",
2468: 'generation' => "Generation",
2469: 'permanentemail' => "Permanent e-mail address",
2470: 'id' => "Student/Employee ID",
2471: 'lg' => "Login Data",
2472: 'inststatus' => "Affiliation",
2473: 'email' => 'E-mail address',
2474: 'valid' => 'Validation',
1.442 raeburn 2475: 'username' => 'Username',
1.391 raeburn 2476: );
2477:
2478: %canmodify_status =
1.286 raeburn 2479: &Apache::lonuserutils::can_modify_userinfo($context,$ccdomain,
2480: ['inststatus'],$rolesarray);
1.253 raeburn 2481: if (!$newuser) {
1.188 raeburn 2482: # Get the users information
2483: %userenv = &Apache::lonnet::get('environment',
2484: ['firstname','middlename','lastname','generation',
1.286 raeburn 2485: 'permanentemail','id','inststatus'],$ccdomain,$ccuname);
1.219 raeburn 2486: %canmodify =
2487: &Apache::lonuserutils::can_modify_userinfo($context,$ccdomain,
1.252 raeburn 2488: \@userinfo,$rolesarray);
1.257 raeburn 2489: } elsif ($context eq 'selfcreate') {
1.391 raeburn 2490: if ($newuser eq 'email') {
1.396 raeburn 2491: if (ref($emailusername) eq 'HASH') {
2492: if (ref($emailusername->{$usertype}) eq 'HASH') {
2493: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
1.442 raeburn 2494: @userinfo = ();
1.396 raeburn 2495: if ((ref($infofields) eq 'ARRAY') && (ref($infotitles) eq 'HASH')) {
2496: foreach my $field (@{$infofields}) {
2497: if ($emailusername->{$usertype}->{$field}) {
2498: push(@userinfo,$field);
2499: $canmodify{$field} = 1;
2500: unless ($textboxsize{$field}) {
2501: $textboxsize{$field} = 25;
2502: }
2503: unless ($lt{$field}) {
2504: $lt{$field} = $infotitles->{$field};
2505: }
2506: if ($emailusername->{$usertype}->{$field} eq 'required') {
2507: $lt{$field} .= '<b>*</b>';
2508: }
1.391 raeburn 2509: }
2510: }
2511: }
2512: }
2513: }
2514: } else {
2515: %canmodify = &selfcreate_canmodify($context,$ccdomain,\@userinfo,
2516: $inst_results,$rolesarray);
2517: }
1.188 raeburn 2518: }
1.391 raeburn 2519:
1.188 raeburn 2520: my $genhelp=&Apache::loncommon::help_open_topic('Generation');
2521: $output = '<h3>'.$lt{'pd'}.'</h3>'.
2522: &Apache::lonhtmlcommon::start_pick_box();
1.391 raeburn 2523: if (($context eq 'selfcreate') && ($newuser eq 'email')) {
1.443 raeburn 2524: my $size = 25;
1.442 raeburn 2525: if ($condition) {
1.443 raeburn 2526: if ($condition =~ /^\@[^\@]+$/) {
2527: $size = 10;
1.442 raeburn 2528: } else {
2529: undef($condition);
2530: }
1.443 raeburn 2531: }
2532: if ($excluded) {
2533: unless ($excluded =~ /^\@[^\@]+$/) {
2534: undef($condition);
2535: }
1.442 raeburn 2536: }
1.396 raeburn 2537: $output .= &Apache::lonhtmlcommon::row_title($lt{'email'}.'<b>*</b>',undef,
1.391 raeburn 2538: 'LC_oddrow_value')."\n".
1.443 raeburn 2539: '<input type="text" name="uname" size="'.$size.'" value="" autocomplete="off" />';
2540: if ($condition) {
2541: $output .= $condition;
2542: } elsif ($excluded) {
2543: $output .= '<br /><span style="font-size: smaller">'.&mt('You must use an e-mail address that does not end with [_1]',
2544: $excluded).'</span>';
2545: }
2546: if ($usernameset eq 'first') {
2547: $output .= '<br /><span style="font-size: smaller">';
2548: if ($condition) {
2549: $output .= &mt('Your username in LON-CAPA will be the part of your e-mail address before [_1]',
2550: $condition);
2551: } else {
2552: $output .= &mt('Your username in LON-CAPA will be the part of your e-mail address before the @');
2553: }
2554: $output .= '</span>';
2555: }
1.391 raeburn 2556: $rowcount ++;
2557: $output .= &Apache::lonhtmlcommon::row_closure(1);
1.460 raeburn 2558: my $upassone = '<input type="password" name="upass'.$now.'" size="20" autocomplete="new-password" />';
2559: my $upasstwo = '<input type="password" name="upasscheck'.$now.'" size="20" autocomplete="new-password" />';
1.396 raeburn 2560: $output .= &Apache::lonhtmlcommon::row_title(&mt('Password').'<b>*</b>',
1.391 raeburn 2561: 'LC_pick_box_title',
2562: 'LC_oddrow_value')."\n".
2563: $upassone."\n".
2564: &Apache::lonhtmlcommon::row_closure(1)."\n".
1.396 raeburn 2565: &Apache::lonhtmlcommon::row_title(&mt('Confirm password').'<b>*</b>',
1.391 raeburn 2566: 'LC_pick_box_title',
2567: 'LC_oddrow_value')."\n".
2568: $upasstwo.
2569: &Apache::lonhtmlcommon::row_closure()."\n";
1.443 raeburn 2570: if ($usernameset eq 'free') {
2571: my $onclick = "toggleUsernameDisp(this,'selfcreateusername');";
1.442 raeburn 2572: $output .= &Apache::lonhtmlcommon::row_title($lt{'username'},undef,'LC_oddrow_value')."\n".
1.455 raeburn 2573: '<span class="LC_nobreak">'.&mt('Use e-mail address: ').
2574: '<label><input type="radio" name="emailused" value="1" checked="checked" onclick="'.$onclick.'" />'.
2575: &mt('Yes').'</label>'.(' 'x2).
2576: '<label><input type="radio" name="emailused" value="0" onclick="'.$onclick.'" />'.
2577: &mt('No').'</label></span>'."\n".
1.442 raeburn 2578: '<div id="selfcreateusername" style="display: none; font-size: smaller">'.
2579: '<br /><span class="LC_nobreak">'.&mt('Preferred username').
2580: ' <input type="text" name="username" value="" size="20" autocomplete="off"/>'.
2581: '</span></div>'."\n".&Apache::lonhtmlcommon::row_closure(1);
2582: $rowcount ++;
2583: }
1.391 raeburn 2584: }
1.188 raeburn 2585: foreach my $item (@userinfo) {
2586: my $rowtitle = $lt{$item};
1.252 raeburn 2587: my $hiderow = 0;
1.188 raeburn 2588: if ($item eq 'generation') {
2589: $rowtitle = $genhelp.$rowtitle;
2590: }
1.252 raeburn 2591: my $row = &Apache::lonhtmlcommon::row_title($rowtitle,undef,'LC_oddrow_value')."\n";
1.188 raeburn 2592: if ($newuser) {
1.210 raeburn 2593: if (ref($inst_results) eq 'HASH') {
2594: if ($inst_results->{$item} ne '') {
1.252 raeburn 2595: $row .= '<input type="hidden" name="c'.$item.'" value="'.$inst_results->{$item}.'" />'.$inst_results->{$item};
1.210 raeburn 2596: } else {
1.252 raeburn 2597: if ($context eq 'selfcreate') {
1.391 raeburn 2598: if ($canmodify{$item}) {
1.394 raeburn 2599: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" autocomplete="off" />';
1.252 raeburn 2600: $editable ++;
2601: } else {
2602: $hiderow = 1;
2603: }
1.253 raeburn 2604: } else {
2605: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
1.252 raeburn 2606: }
1.210 raeburn 2607: }
1.188 raeburn 2608: } else {
1.252 raeburn 2609: if ($context eq 'selfcreate') {
1.401 raeburn 2610: if ($canmodify{$item}) {
2611: if ($newuser eq 'email') {
2612: $row .= '<input type="text" name="'.$item.'" size="'.$textboxsize{$item}.'" value="" autocomplete="off" />';
1.287 raeburn 2613: } else {
1.401 raeburn 2614: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" autocomplete="off" />';
1.287 raeburn 2615: }
1.401 raeburn 2616: $editable ++;
2617: } else {
2618: $hiderow = 1;
1.252 raeburn 2619: }
1.253 raeburn 2620: } else {
2621: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
1.252 raeburn 2622: }
1.188 raeburn 2623: }
2624: } else {
1.219 raeburn 2625: if ($canmodify{$item}) {
1.252 raeburn 2626: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="'.$userenv{$item}.'" />';
1.393 raeburn 2627: if (($item eq 'id') && (!$newuser)) {
2628: $row .= '<br />'.&Apache::lonuserutils::forceid_change($context);
2629: }
1.188 raeburn 2630: } else {
1.252 raeburn 2631: $row .= $userenv{$item};
1.188 raeburn 2632: }
2633: }
1.252 raeburn 2634: $row .= &Apache::lonhtmlcommon::row_closure(1);
2635: if (!$hiderow) {
2636: $output .= $row;
2637: $rowcount ++;
2638: }
1.188 raeburn 2639: }
1.286 raeburn 2640: if (($canmodify_status{'inststatus'}) || ($context ne 'selfcreate')) {
2641: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($ccdomain);
2642: if (ref($types) eq 'ARRAY') {
2643: if (@{$types} > 0) {
2644: my ($hiderow,$shown);
2645: if ($canmodify_status{'inststatus'}) {
2646: $shown = &pick_inst_statuses($userenv{'inststatus'},$usertypes,$types);
2647: } else {
2648: if ($userenv{'inststatus'} eq '') {
2649: $hiderow = 1;
1.334 raeburn 2650: } else {
2651: my @showitems;
2652: foreach my $item ( map { &unescape($_); } split(':',$userenv{'inststatus'})) {
2653: if (exists($usertypes->{$item})) {
2654: push(@showitems,$usertypes->{$item});
2655: } else {
2656: push(@showitems,$item);
2657: }
2658: }
2659: if (@showitems) {
2660: $shown = join(', ',@showitems);
2661: } else {
2662: $hiderow = 1;
2663: }
1.286 raeburn 2664: }
2665: }
2666: if (!$hiderow) {
1.389 bisitz 2667: my $row = &Apache::lonhtmlcommon::row_title(&mt('Affiliations'),undef,'LC_oddrow_value')."\n".
1.286 raeburn 2668: $shown.&Apache::lonhtmlcommon::row_closure(1);
2669: if ($context eq 'selfcreate') {
2670: $rowcount ++;
2671: }
2672: $output .= $row;
2673: }
2674: }
2675: }
2676: }
1.391 raeburn 2677: if (($context eq 'selfcreate') && ($newuser eq 'email')) {
2678: if ($captchaform) {
1.410 raeburn 2679: $output .= &Apache::lonhtmlcommon::row_title($lt{'valid'}.'*',
2680: 'LC_pick_box_title')."\n".
1.456 raeburn 2681: $captchaform."\n".'<br /><br />'.
1.391 raeburn 2682: &Apache::lonhtmlcommon::row_closure(1);
2683: $rowcount ++;
2684: }
1.456 raeburn 2685: if ($showsubmit) {
2686: my $submit_text = &mt('Create account');
2687: $output .= &Apache::lonhtmlcommon::row_title()."\n".
2688: '<br /><input type="submit" name="createaccount" value="'.
2689: $submit_text.'" />';
2690: if ($usertype ne '') {
2691: $output .= '<input type="hidden" name="type" value="'.
2692: &HTML::Entities::encode($usertype,'\'<>"&').'" />';
2693: }
2694: $output .= &Apache::lonhtmlcommon::row_closure(1);
2695: }
1.391 raeburn 2696: }
1.188 raeburn 2697: $output .= &Apache::lonhtmlcommon::end_pick_box();
1.206 raeburn 2698: if (wantarray) {
1.252 raeburn 2699: if ($context eq 'selfcreate') {
2700: return($output,$rowcount,$editable);
2701: } else {
1.388 bisitz 2702: return $output;
1.252 raeburn 2703: }
1.206 raeburn 2704: } else {
2705: return $output;
2706: }
1.188 raeburn 2707: }
2708:
1.286 raeburn 2709: sub pick_inst_statuses {
2710: my ($curr,$usertypes,$types) = @_;
2711: my ($output,$rem,@currtypes);
2712: if ($curr ne '') {
2713: @currtypes = map { &unescape($_); } split(/:/,$curr);
2714: }
2715: my $numinrow = 2;
2716: if (ref($types) eq 'ARRAY') {
2717: $output = '<table>';
2718: my $lastcolspan;
2719: for (my $i=0; $i<@{$types}; $i++) {
2720: if (defined($usertypes->{$types->[$i]})) {
2721: my $rem = $i%($numinrow);
2722: if ($rem == 0) {
2723: if ($i<@{$types}-1) {
2724: if ($i > 0) {
2725: $output .= '</tr>';
2726: }
2727: $output .= '<tr>';
2728: }
2729: } elsif ($i==@{$types}-1) {
2730: my $colsleft = $numinrow - $rem;
2731: if ($colsleft > 1) {
2732: $lastcolspan = ' colspan="'.$colsleft.'"';
2733: }
2734: }
2735: my $check = ' ';
2736: if (grep(/^\Q$types->[$i]\E$/,@currtypes)) {
2737: $check = ' checked="checked" ';
2738: }
2739: $output .= '<td class="LC_left_item"'.$lastcolspan.'>'.
2740: '<span class="LC_nobreak"><label>'.
2741: '<input type="checkbox" name="inststatus" '.
2742: 'value="'.$types->[$i].'"'.$check.'/>'.
2743: $usertypes->{$types->[$i]}.'</label></span></td>';
2744: }
2745: }
2746: $output .= '</tr></table>';
2747: }
2748: return $output;
2749: }
2750:
1.257 raeburn 2751: sub selfcreate_canmodify {
2752: my ($context,$dom,$userinfo,$inst_results,$rolesarray) = @_;
2753: if (ref($inst_results) eq 'HASH') {
2754: my @inststatuses = &get_inststatuses($inst_results);
2755: if (@inststatuses == 0) {
2756: @inststatuses = ('default');
2757: }
2758: $rolesarray = \@inststatuses;
2759: }
2760: my %canmodify =
2761: &Apache::lonuserutils::can_modify_userinfo($context,$dom,$userinfo,
2762: $rolesarray);
2763: return %canmodify;
2764: }
2765:
1.252 raeburn 2766: sub get_inststatuses {
2767: my ($insthashref) = @_;
2768: my @inststatuses = ();
2769: if (ref($insthashref) eq 'HASH') {
2770: if (ref($insthashref->{'inststatus'}) eq 'ARRAY') {
2771: @inststatuses = @{$insthashref->{'inststatus'}};
2772: }
2773: }
2774: return @inststatuses;
2775: }
2776:
1.4 www 2777: # ================================================================= Phase Three
1.42 matthew 2778: sub update_user_data {
1.451 raeburn 2779: my ($r,$context,$crstype,$brcrum,$showcredits,$permission) = @_;
1.101 albertel 2780: my $uhome=&Apache::lonnet::homeserver($env{'form.ccuname'},
2781: $env{'form.ccdomain'});
1.27 matthew 2782: # Error messages
1.188 raeburn 2783: my $error = '<span class="LC_error">'.&mt('Error').': ';
1.193 raeburn 2784: my $end = '</span><br /><br />';
2785: my $rtnlink = '<a href="javascript:backPage(document.userupdate,'.
1.188 raeburn 2786: "'$env{'form.prevphase'}','modify')".'" />'.
1.219 raeburn 2787: &mt('Return to previous page').'</a>'.
2788: &Apache::loncommon::end_page();
2789: my $now = time;
1.40 www 2790: my $title;
1.101 albertel 2791: if (exists($env{'form.makeuser'})) {
1.40 www 2792: $title='Set Privileges for New User';
2793: } else {
2794: $title='Modify User Privileges';
2795: }
1.213 raeburn 2796: my $newuser = 0;
1.160 raeburn 2797: my ($jsback,$elements) = &crumb_utilities();
2798: my $jscript = '<script type="text/javascript">'."\n".
1.301 bisitz 2799: '// <![CDATA['."\n".
2800: $jsback."\n".
2801: '// ]]>'."\n".
2802: '</script>'."\n";
1.422 raeburn 2803: my %breadcrumb_text = &singleuser_breadcrumb($crstype,$context,$env{'form.ccdomain'});
1.351 raeburn 2804: push (@{$brcrum},
2805: {href => "javascript:backPage(document.userupdate)",
2806: text => $breadcrumb_text{'search'},
2807: faq => 282,
2808: bug => 'Instructor Interface',}
2809: );
2810: if ($env{'form.prevphase'} eq 'userpicked') {
2811: push(@{$brcrum},
2812: {href => "javascript:backPage(document.userupdate,'get_user_info','select')",
2813: text => $breadcrumb_text{'userpicked'},
2814: faq => 282,
2815: bug => 'Instructor Interface',});
1.233 raeburn 2816: }
1.224 raeburn 2817: my $helpitem = 'Course_Change_Privileges';
2818: if ($env{'form.action'} eq 'singlestudent') {
2819: $helpitem = 'Course_Add_Student';
1.439 raeburn 2820: } elsif ($context eq 'author') {
2821: $helpitem = 'Author_Change_Privileges';
2822: } elsif ($context eq 'domain') {
2823: $helpitem = 'Domain_Change_Privileges';
1.224 raeburn 2824: }
1.351 raeburn 2825: push(@{$brcrum},
2826: {href => "javascript:backPage(document.userupdate,'$env{'form.prevphase'}','modify')",
2827: text => $breadcrumb_text{'modify'},
2828: faq => 282,
2829: bug => 'Instructor Interface',},
2830: {href => "/adm/createuser",
2831: text => "Result",
2832: faq => 282,
2833: bug => 'Instructor Interface',
2834: help => $helpitem});
2835: my $args = {bread_crumbs => $brcrum,
2836: bread_crumbs_component => 'User Management'};
2837: if ($env{'form.popup'}) {
2838: $args->{'no_nav_bar'} = 1;
2839: }
2840: $r->print(&Apache::loncommon::start_page($title,$jscript,$args));
1.188 raeburn 2841: $r->print(&update_result_form($uhome));
1.27 matthew 2842: # Check Inputs
1.101 albertel 2843: if (! $env{'form.ccuname'} ) {
1.193 raeburn 2844: $r->print($error.&mt('No login name specified').'.'.$end.$rtnlink);
1.27 matthew 2845: return;
2846: }
1.138 albertel 2847: if ( $env{'form.ccuname'} ne
2848: &LONCAPA::clean_username($env{'form.ccuname'}) ) {
1.281 bisitz 2849: $r->print($error.&mt('Invalid login name.').' '.
2850: &mt('Only letters, numbers, periods, dashes, @, and underscores are valid.').
1.193 raeburn 2851: $end.$rtnlink);
1.27 matthew 2852: return;
2853: }
1.101 albertel 2854: if (! $env{'form.ccdomain'} ) {
1.193 raeburn 2855: $r->print($error.&mt('No domain specified').'.'.$end.$rtnlink);
1.27 matthew 2856: return;
2857: }
1.138 albertel 2858: if ( $env{'form.ccdomain'} ne
2859: &LONCAPA::clean_domain($env{'form.ccdomain'}) ) {
1.281 bisitz 2860: $r->print($error.&mt('Invalid domain name.').' '.
2861: &mt('Only letters, numbers, periods, dashes, and underscores are valid.').
1.193 raeburn 2862: $end.$rtnlink);
1.27 matthew 2863: return;
2864: }
1.219 raeburn 2865: if ($uhome eq 'no_host') {
2866: $newuser = 1;
2867: }
1.101 albertel 2868: if (! exists($env{'form.makeuser'})) {
1.29 matthew 2869: # Modifying an existing user, so check the validity of the name
2870: if ($uhome eq 'no_host') {
1.389 bisitz 2871: $r->print(
2872: $error
2873: .'<p class="LC_error">'
2874: .&mt('Unable to determine home server for [_1] in domain [_2].',
2875: '"'.$env{'form.ccuname'}.'"','"'.$env{'form.ccdomain'}.'"')
2876: .'</p>');
1.29 matthew 2877: return;
2878: }
2879: }
1.27 matthew 2880: # Determine authentication method and password for the user being modified
2881: my $amode='';
2882: my $genpwd='';
1.101 albertel 2883: if ($env{'form.login'} eq 'krb') {
1.41 albertel 2884: $amode='krb';
1.101 albertel 2885: $amode.=$env{'form.krbver'};
2886: $genpwd=$env{'form.krbarg'};
2887: } elsif ($env{'form.login'} eq 'int') {
1.27 matthew 2888: $amode='internal';
1.101 albertel 2889: $genpwd=$env{'form.intarg'};
2890: } elsif ($env{'form.login'} eq 'fsys') {
1.27 matthew 2891: $amode='unix';
1.101 albertel 2892: $genpwd=$env{'form.fsysarg'};
2893: } elsif ($env{'form.login'} eq 'loc') {
1.27 matthew 2894: $amode='localauth';
1.101 albertel 2895: $genpwd=$env{'form.locarg'};
1.27 matthew 2896: $genpwd=" " if (!$genpwd);
1.449 raeburn 2897: } elsif ($env{'form.login'} eq 'lti') {
2898: $amode='lti';
2899: $genpwd=" ";
1.101 albertel 2900: } elsif (($env{'form.login'} eq 'nochange') ||
2901: ($env{'form.login'} eq '' )) {
1.34 matthew 2902: # There is no need to tell the user we did not change what they
2903: # did not ask us to change.
1.35 matthew 2904: # If they are creating a new user but have not specified login
2905: # information this will be caught below.
1.30 matthew 2906: } else {
1.367 golterma 2907: $r->print($error.&mt('Invalid login mode or password').$end.$rtnlink);
2908: return;
1.27 matthew 2909: }
1.164 albertel 2910:
1.188 raeburn 2911: $r->print('<h3>'.&mt('User [_1] in domain [_2]',
1.367 golterma 2912: $env{'form.ccuname'}.' ('.&Apache::loncommon::plainname($env{'form.ccuname'},
2913: $env{'form.ccdomain'}).')', $env{'form.ccdomain'}).'</h3>');
2914: my %prog_state = &Apache::lonhtmlcommon::Create_PrgWin($r,2);
1.344 bisitz 2915:
1.193 raeburn 2916: my (%alerts,%rulematch,%inst_results,%curr_rules);
1.334 raeburn 2917: my @userinfo = ('firstname','middlename','lastname','generation','permanentemail','id');
1.459 raeburn 2918: my @usertools = ('aboutme','blog','webdav','portfolio','timezone');
1.449 raeburn 2919: my @requestcourses = ('official','unofficial','community','textbook','placement','lti');
1.362 raeburn 2920: my @requestauthor = ('requestauthor');
1.286 raeburn 2921: my ($othertitle,$usertypes,$types) =
2922: &Apache::loncommon::sorted_inst_types($env{'form.ccdomain'});
1.334 raeburn 2923: my %canmodify_status =
2924: &Apache::lonuserutils::can_modify_userinfo($context,$env{'form.ccdomain'},
2925: ['inststatus']);
1.101 albertel 2926: if ($env{'form.makeuser'}) {
1.164 albertel 2927: $r->print('<h3>'.&mt('Creating new account.').'</h3>');
1.27 matthew 2928: # Check for the authentication mode and password
2929: if (! $amode || ! $genpwd) {
1.193 raeburn 2930: $r->print($error.&mt('Invalid login mode or password').$end.$rtnlink);
1.27 matthew 2931: return;
1.18 albertel 2932: }
1.29 matthew 2933: # Determine desired host
1.101 albertel 2934: my $desiredhost = $env{'form.hserver'};
1.29 matthew 2935: if (lc($desiredhost) eq 'default') {
2936: $desiredhost = undef;
2937: } else {
1.147 albertel 2938: my %home_servers =
2939: &Apache::lonnet::get_servers($env{'form.ccdomain'},'library');
1.29 matthew 2940: if (! exists($home_servers{$desiredhost})) {
1.193 raeburn 2941: $r->print($error.&mt('Invalid home server specified').$end.$rtnlink);
2942: return;
2943: }
2944: }
2945: # Check ID format
2946: my %checkhash;
2947: my %checks = ('id' => 1);
2948: %{$checkhash{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}}} = (
1.219 raeburn 2949: 'newuser' => $newuser,
1.196 raeburn 2950: 'id' => $env{'form.cid'},
1.193 raeburn 2951: );
1.196 raeburn 2952: if ($env{'form.cid'} ne '') {
2953: &Apache::loncommon::user_rule_check(\%checkhash,\%checks,\%alerts,
2954: \%rulematch,\%inst_results,\%curr_rules);
2955: if (ref($alerts{'id'}) eq 'HASH') {
2956: if (ref($alerts{'id'}{$env{'form.ccdomain'}}) eq 'HASH') {
2957: my $domdesc =
2958: &Apache::lonnet::domain($env{'form.ccdomain'},'description');
2959: if ($alerts{'id'}{$env{'form.ccdomain'}}{$env{'form.cid'}}) {
2960: my $userchkmsg;
2961: if (ref($curr_rules{$env{'form.ccdomain'}}) eq 'HASH') {
2962: $userchkmsg =
2963: &Apache::loncommon::instrule_disallow_msg('id',
2964: $domdesc,1).
2965: &Apache::loncommon::user_rule_formats($env{'form.ccdomain'},
2966: $domdesc,$curr_rules{$env{'form.ccdomain'}}{'id'},'id');
2967: }
2968: $r->print($error.&mt('Invalid ID format').$end.
2969: $userchkmsg.$rtnlink);
2970: return;
2971: }
2972: }
1.29 matthew 2973: }
2974: }
1.367 golterma 2975: &Apache::lonhtmlcommon::Increment_PrgWin($r, \%prog_state);
1.27 matthew 2976: # Call modifyuser
2977: my $result = &Apache::lonnet::modifyuser
1.193 raeburn 2978: ($env{'form.ccdomain'},$env{'form.ccuname'},$env{'form.cid'},
1.188 raeburn 2979: $amode,$genpwd,$env{'form.cfirstname'},
2980: $env{'form.cmiddlename'},$env{'form.clastname'},
2981: $env{'form.cgeneration'},undef,$desiredhost,
2982: $env{'form.cpermanentemail'});
1.77 www 2983: $r->print(&mt('Generating user').': '.$result);
1.219 raeburn 2984: $uhome = &Apache::lonnet::homeserver($env{'form.ccuname'},
1.101 albertel 2985: $env{'form.ccdomain'});
1.334 raeburn 2986: my (%changeHash,%newcustom,%changed,%changedinfo);
1.267 raeburn 2987: if ($uhome ne 'no_host') {
1.334 raeburn 2988: if ($context eq 'domain') {
1.378 raeburn 2989: foreach my $name ('portfolio','author') {
2990: if ($env{'form.custom_'.$name.'quota'} == 1) {
2991: if ($env{'form.'.$name.'quota'} eq '') {
2992: $newcustom{$name.'quota'} = 0;
2993: } else {
2994: $newcustom{$name.'quota'} = $env{'form.'.$name.'quota'};
2995: $newcustom{$name.'quota'} =~ s/[^\d\.]//g;
2996: }
2997: if ("a_admin($newcustom{$name.'quota'},\%changeHash,$name)) {
2998: $changed{$name.'quota'} = 1;
2999: }
1.334 raeburn 3000: }
3001: }
3002: foreach my $item (@usertools) {
3003: if ($env{'form.custom'.$item} == 1) {
3004: $newcustom{$item} = $env{'form.tools_'.$item};
3005: $changed{$item} = &tool_admin($item,$newcustom{$item},
3006: \%changeHash,'tools');
3007: }
1.267 raeburn 3008: }
1.334 raeburn 3009: foreach my $item (@requestcourses) {
1.341 raeburn 3010: if ($env{'form.custom'.$item} == 1) {
3011: $newcustom{$item} = $env{'form.crsreq_'.$item};
3012: if ($env{'form.crsreq_'.$item} eq 'autolimit') {
3013: $newcustom{$item} .= '=';
1.383 raeburn 3014: $env{'form.crsreq_'.$item.'_limit'} =~ s/\D+//g;
3015: if ($env{'form.crsreq_'.$item.'_limit'}) {
1.341 raeburn 3016: $newcustom{$item} .= $env{'form.crsreq_'.$item.'_limit'};
3017: }
1.334 raeburn 3018: }
1.341 raeburn 3019: $changed{$item} = &tool_admin($item,$newcustom{$item},
3020: \%changeHash,'requestcourses');
1.334 raeburn 3021: }
1.275 raeburn 3022: }
1.362 raeburn 3023: if ($env{'form.customrequestauthor'} == 1) {
3024: $newcustom{'requestauthor'} = $env{'form.requestauthor'};
3025: $changed{'requestauthor'} = &tool_admin('requestauthor',
3026: $newcustom{'requestauthor'},
3027: \%changeHash,'requestauthor');
3028: }
1.275 raeburn 3029: }
1.334 raeburn 3030: if ($canmodify_status{'inststatus'}) {
3031: if (exists($env{'form.inststatus'})) {
3032: my @inststatuses = &Apache::loncommon::get_env_multiple('form.inststatus');
3033: if (@inststatuses > 0) {
3034: $changeHash{'inststatus'} = join(',',@inststatuses);
3035: $changed{'inststatus'} = $changeHash{'inststatus'};
1.306 raeburn 3036: }
3037: }
1.232 raeburn 3038: }
1.334 raeburn 3039: if (keys(%changed)) {
3040: foreach my $item (@userinfo) {
3041: $changeHash{$item} = $env{'form.c'.$item};
1.286 raeburn 3042: }
1.267 raeburn 3043: my $chgresult =
3044: &Apache::lonnet::put('environment',\%changeHash,
3045: $env{'form.ccdomain'},$env{'form.ccuname'});
3046: }
1.232 raeburn 3047: }
1.454 raeburn 3048: $r->print('<br />'.&mt('Home Server').': '.$uhome.' '.
1.219 raeburn 3049: &Apache::lonnet::hostname($uhome));
1.101 albertel 3050: } elsif (($env{'form.login'} ne 'nochange') &&
3051: ($env{'form.login'} ne '' )) {
1.27 matthew 3052: # Modify user privileges
3053: if (! $amode || ! $genpwd) {
1.193 raeburn 3054: $r->print($error.'Invalid login mode or password'.$end.$rtnlink);
1.27 matthew 3055: return;
1.20 harris41 3056: }
1.395 bisitz 3057: # Only allow authentication modification if the person has authority
1.101 albertel 3058: if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'})) {
1.20 harris41 3059: $r->print('Modifying authentication: '.
1.31 matthew 3060: &Apache::lonnet::modifyuserauth(
1.101 albertel 3061: $env{'form.ccdomain'},$env{'form.ccuname'},
1.21 harris41 3062: $amode,$genpwd));
1.454 raeburn 3063: $r->print('<br />'.&mt('Home Server').': '.&Apache::lonnet::homeserver
1.101 albertel 3064: ($env{'form.ccuname'},$env{'form.ccdomain'}));
1.4 www 3065: } else {
1.27 matthew 3066: # Okay, this is a non-fatal error.
1.452 raeburn 3067: $r->print($error.&mt('You do not have privileges to modify the authentication configuration for this user.').$end);
1.27 matthew 3068: }
1.451 raeburn 3069: } elsif (($env{'form.intarg'} ne '') &&
3070: (&Apache::lonnet::queryauthenticate($env{'form.ccuname'},$env{'form.ccdomain'}) =~ /^internal:/) &&
3071: (&Apache::lonuserutils::can_change_internalpass($env{'form.ccuname'},$env{'form.ccdomain'},$crstype,$permission))) {
3072: $r->print('Modifying authentication: '.
3073: &Apache::lonnet::modifyuserauth(
3074: $env{'form.ccdomain'},$env{'form.ccuname'},
3075: 'internal',$env{'form.intarg'}));
1.28 matthew 3076: }
1.344 bisitz 3077: $r->rflush(); # Finish display of header before time consuming actions start
1.367 golterma 3078: &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state);
1.28 matthew 3079: ##
1.375 raeburn 3080: my (@userroles,%userupdate,$cnum,$cdom,$defaultcredits,%namechanged);
1.213 raeburn 3081: if ($context eq 'course') {
1.375 raeburn 3082: ($cnum,$cdom) =
3083: &Apache::lonuserutils::get_course_identity();
1.318 raeburn 3084: $crstype = &Apache::loncommon::course_type($cdom.'_'.$cnum);
1.375 raeburn 3085: if ($showcredits) {
3086: $defaultcredits = &Apache::lonuserutils::get_defaultcredits($cdom,$cnum);
3087: }
1.213 raeburn 3088: }
1.101 albertel 3089: if (! $env{'form.makeuser'} ) {
1.28 matthew 3090: # Check for need to change
3091: my %userenv = &Apache::lonnet::get
1.134 raeburn 3092: ('environment',['firstname','middlename','lastname','generation',
1.378 raeburn 3093: 'id','permanentemail','portfolioquota','authorquota','inststatus',
1.459 raeburn 3094: 'tools.aboutme','tools.blog','tools.webdav',
3095: 'tools.portfolio','tools.timezone',
1.361 raeburn 3096: 'requestcourses.official','requestcourses.unofficial',
1.384 raeburn 3097: 'requestcourses.community','requestcourses.textbook',
1.458 raeburn 3098: 'requestcourses.lti','requestauthor',
1.384 raeburn 3099: 'reqcrsotherdom.official','reqcrsotherdom.unofficial',
3100: 'reqcrsotherdom.community','reqcrsotherdom.textbook',
1.458 raeburn 3101: 'reqcrsotherdom.placement'],
1.160 raeburn 3102: $env{'form.ccdomain'},$env{'form.ccuname'});
1.28 matthew 3103: my ($tmp) = keys(%userenv);
3104: if ($tmp =~ /^(con_lost|error)/i) {
3105: %userenv = ();
3106: }
1.206 raeburn 3107: my $no_forceid_alert;
3108: # Check to see if user information can be changed
3109: my %domconfig =
3110: &Apache::lonnet::get_dom('configuration',['usermodification'],
3111: $env{'form.ccdomain'});
1.213 raeburn 3112: my @statuses = ('active','future');
3113: my %roles = &Apache::lonnet::get_my_roles($env{'form.ccuname'},$env{'form.ccdomain'},'userroles',\@statuses,undef,$env{'request.role.domain'});
3114: my ($auname,$audom);
1.220 raeburn 3115: if ($context eq 'author') {
1.206 raeburn 3116: $auname = $env{'user.name'};
3117: $audom = $env{'user.domain'};
3118: }
3119: foreach my $item (keys(%roles)) {
1.220 raeburn 3120: my ($rolenum,$roledom,$role) = split(/:/,$item,-1);
1.206 raeburn 3121: if ($context eq 'course') {
3122: if ($cnum ne '' && $cdom ne '') {
3123: if ($rolenum eq $cnum && $roledom eq $cdom) {
3124: if (!grep(/^\Q$role\E$/,@userroles)) {
3125: push(@userroles,$role);
3126: }
3127: }
3128: }
3129: } elsif ($context eq 'author') {
3130: if ($rolenum eq $auname && $roledom eq $audom) {
1.461 raeburn 3131: if (!grep(/^\Q$role\E$/,@userroles)) {
1.206 raeburn 3132: push(@userroles,$role);
3133: }
3134: }
3135: }
3136: }
1.220 raeburn 3137: if ($env{'form.action'} eq 'singlestudent') {
3138: if (!grep(/^st$/,@userroles)) {
3139: push(@userroles,'st');
3140: }
3141: } else {
3142: # Check for course or co-author roles being activated or re-enabled
3143: if ($context eq 'author' || $context eq 'course') {
3144: foreach my $key (keys(%env)) {
3145: if ($context eq 'author') {
3146: if ($key=~/^form\.act_\Q$audom\E_\Q$auname\E_([^_]+)/) {
3147: if (!grep(/^\Q$1\E$/,@userroles)) {
3148: push(@userroles,$1);
3149: }
3150: } elsif ($key =~/^form\.ren\:\Q$audom\E\/\Q$auname\E_([^_]+)/) {
3151: if (!grep(/^\Q$1\E$/,@userroles)) {
3152: push(@userroles,$1);
3153: }
1.206 raeburn 3154: }
1.220 raeburn 3155: } elsif ($context eq 'course') {
3156: if ($key=~/^form\.act_\Q$cdom\E_\Q$cnum\E_([^_]+)/) {
3157: if (!grep(/^\Q$1\E$/,@userroles)) {
3158: push(@userroles,$1);
3159: }
3160: } elsif ($key =~/^form\.ren\:\Q$cdom\E\/\Q$cnum\E(\/?\w*)_([^_]+)/) {
3161: if (!grep(/^\Q$1\E$/,@userroles)) {
3162: push(@userroles,$1);
3163: }
1.206 raeburn 3164: }
3165: }
3166: }
3167: }
3168: }
3169: #Check to see if we can change personal data for the user
3170: my (@mod_disallowed,@longroles);
3171: foreach my $role (@userroles) {
3172: if ($role eq 'cr') {
3173: push(@longroles,'Custom');
3174: } else {
1.318 raeburn 3175: push(@longroles,&Apache::lonnet::plaintext($role,$crstype));
1.206 raeburn 3176: }
3177: }
1.219 raeburn 3178: my %canmodify = &Apache::lonuserutils::can_modify_userinfo($context,$env{'form.ccdomain'},\@userinfo,\@userroles);
3179: foreach my $item (@userinfo) {
1.28 matthew 3180: # Strip leading and trailing whitespace
1.203 raeburn 3181: $env{'form.c'.$item} =~ s/(\s+$|^\s+)//g;
1.219 raeburn 3182: if (!$canmodify{$item}) {
1.207 raeburn 3183: if (defined($env{'form.c'.$item})) {
3184: if ($env{'form.c'.$item} ne $userenv{$item}) {
3185: push(@mod_disallowed,$item);
3186: }
1.206 raeburn 3187: }
3188: $env{'form.c'.$item} = $userenv{$item};
3189: }
1.28 matthew 3190: }
1.259 bisitz 3191: # Check to see if we can change the Student/Employee ID
1.196 raeburn 3192: my $forceid = $env{'form.forceid'};
3193: my $recurseid = $env{'form.recurseid'};
3194: my (%alerts,%rulematch,%idinst_results,%curr_rules,%got_rules);
1.203 raeburn 3195: my %uidhash = &Apache::lonnet::idrget($env{'form.ccdomain'},
3196: $env{'form.ccuname'});
3197: if (($uidhash{$env{'form.ccuname'}}) &&
3198: ($uidhash{$env{'form.ccuname'}}!~/error\:/) &&
3199: (!$forceid)) {
3200: if ($env{'form.cid'} ne $uidhash{$env{'form.ccuname'}}) {
3201: $env{'form.cid'} = $userenv{'id'};
1.293 bisitz 3202: $no_forceid_alert = &mt('New student/employee ID does not match existing ID for this user.')
1.259 bisitz 3203: .'<br />'
3204: .&mt("Change is not permitted without checking the 'Force ID change' checkbox on the previous page.")
3205: .'<br />'."\n";
1.203 raeburn 3206: }
3207: }
3208: if ($env{'form.cid'} ne $userenv{'id'}) {
1.196 raeburn 3209: my $checkhash;
3210: my $checks = { 'id' => 1 };
3211: $checkhash->{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}} =
3212: { 'newuser' => $newuser,
3213: 'id' => $env{'form.cid'},
3214: };
3215: &Apache::loncommon::user_rule_check($checkhash,$checks,
3216: \%alerts,\%rulematch,\%idinst_results,\%curr_rules,\%got_rules);
3217: if (ref($alerts{'id'}) eq 'HASH') {
3218: if (ref($alerts{'id'}{$env{'form.ccdomain'}}) eq 'HASH') {
1.203 raeburn 3219: $env{'form.cid'} = $userenv{'id'};
1.196 raeburn 3220: }
3221: }
3222: }
1.378 raeburn 3223: my (%quotachanged,%oldquota,%newquota,%olddefquota,%newdefquota,
3224: $oldinststatus,$newinststatus,%oldisdefault,%newisdefault,%oldsettings,
1.339 raeburn 3225: %oldsettingstext,%newsettings,%newsettingstext,@disporder,
1.378 raeburn 3226: %oldsettingstatus,%newsettingstatus);
1.334 raeburn 3227: @disporder = ('inststatus');
3228: if ($env{'request.role.domain'} eq $env{'form.ccdomain'}) {
1.362 raeburn 3229: push(@disporder,'requestcourses','requestauthor');
1.334 raeburn 3230: } else {
3231: push(@disporder,'reqcrsotherdom');
3232: }
3233: push(@disporder,('quota','tools'));
1.338 raeburn 3234: $oldinststatus = $userenv{'inststatus'};
1.378 raeburn 3235: foreach my $name ('portfolio','author') {
3236: ($olddefquota{$name},$oldsettingstatus{$name}) =
3237: &Apache::loncommon::default_quota($env{'form.ccdomain'},$oldinststatus,$name);
3238: ($newdefquota{$name},$newsettingstatus{$name}) = ($olddefquota{$name},$oldsettingstatus{$name});
3239: }
1.334 raeburn 3240: my %canshow;
1.220 raeburn 3241: if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
1.334 raeburn 3242: $canshow{'quota'} = 1;
1.220 raeburn 3243: }
1.267 raeburn 3244: if (&Apache::lonnet::allowed('mut',$env{'form.ccdomain'})) {
1.334 raeburn 3245: $canshow{'tools'} = 1;
1.267 raeburn 3246: }
1.275 raeburn 3247: if (&Apache::lonnet::allowed('ccc',$env{'form.ccdomain'})) {
1.334 raeburn 3248: $canshow{'requestcourses'} = 1;
1.300 raeburn 3249: } elsif (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
1.334 raeburn 3250: $canshow{'reqcrsotherdom'} = 1;
1.275 raeburn 3251: }
1.286 raeburn 3252: if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'})) {
1.334 raeburn 3253: $canshow{'inststatus'} = 1;
1.286 raeburn 3254: }
1.362 raeburn 3255: if (&Apache::lonnet::allowed('cau',$env{'form.ccdomain'})) {
3256: $canshow{'requestauthor'} = 1;
3257: }
1.267 raeburn 3258: my (%changeHash,%changed);
1.286 raeburn 3259: if ($oldinststatus eq '') {
1.334 raeburn 3260: $oldsettings{'inststatus'} = $othertitle;
1.286 raeburn 3261: } else {
3262: if (ref($usertypes) eq 'HASH') {
1.334 raeburn 3263: $oldsettings{'inststatus'} = join(', ',map{ $usertypes->{ &unescape($_) }; } (split(/:/,$userenv{'inststatus'})));
1.286 raeburn 3264: } else {
1.334 raeburn 3265: $oldsettings{'inststatus'} = join(', ',map{ &unescape($_); } (split(/:/,$userenv{'inststatus'})));
1.286 raeburn 3266: }
3267: }
3268: $changeHash{'inststatus'} = $userenv{'inststatus'};
1.334 raeburn 3269: if ($canmodify_status{'inststatus'}) {
3270: $canshow{'inststatus'} = 1;
1.286 raeburn 3271: if (exists($env{'form.inststatus'})) {
3272: my @inststatuses = &Apache::loncommon::get_env_multiple('form.inststatus');
3273: if (@inststatuses > 0) {
3274: $newinststatus = join(':',map { &escape($_); } @inststatuses);
3275: $changeHash{'inststatus'} = $newinststatus;
3276: if ($newinststatus ne $oldinststatus) {
3277: $changed{'inststatus'} = $newinststatus;
1.378 raeburn 3278: foreach my $name ('portfolio','author') {
3279: ($newdefquota{$name},$newsettingstatus{$name}) =
3280: &Apache::loncommon::default_quota($env{'form.ccdomain'},$newinststatus,$name);
3281: }
1.286 raeburn 3282: }
3283: if (ref($usertypes) eq 'HASH') {
1.334 raeburn 3284: $newsettings{'inststatus'} = join(', ',map{ $usertypes->{$_}; } (@inststatuses));
1.286 raeburn 3285: } else {
1.337 raeburn 3286: $newsettings{'inststatus'} = join(', ',@inststatuses);
1.286 raeburn 3287: }
1.334 raeburn 3288: }
3289: } else {
3290: $newinststatus = '';
3291: $changeHash{'inststatus'} = $newinststatus;
3292: $newsettings{'inststatus'} = $othertitle;
3293: if ($newinststatus ne $oldinststatus) {
3294: $changed{'inststatus'} = $changeHash{'inststatus'};
1.378 raeburn 3295: foreach my $name ('portfolio','author') {
3296: ($newdefquota{$name},$newsettingstatus{$name}) =
3297: &Apache::loncommon::default_quota($env{'form.ccdomain'},$newinststatus,$name);
3298: }
1.286 raeburn 3299: }
3300: }
1.334 raeburn 3301: } elsif ($context ne 'selfcreate') {
3302: $canshow{'inststatus'} = 1;
1.337 raeburn 3303: $newsettings{'inststatus'} = $oldsettings{'inststatus'};
1.286 raeburn 3304: }
1.378 raeburn 3305: foreach my $name ('portfolio','author') {
3306: $changeHash{$name.'quota'} = $userenv{$name.'quota'};
3307: }
1.334 raeburn 3308: if ($context eq 'domain') {
1.378 raeburn 3309: foreach my $name ('portfolio','author') {
3310: if ($userenv{$name.'quota'} ne '') {
3311: $oldquota{$name} = $userenv{$name.'quota'};
3312: if ($env{'form.custom_'.$name.'quota'} == 1) {
3313: if ($env{'form.'.$name.'quota'} eq '') {
3314: $newquota{$name} = 0;
3315: } else {
3316: $newquota{$name} = $env{'form.'.$name.'quota'};
3317: $newquota{$name} =~ s/[^\d\.]//g;
3318: }
3319: if ($newquota{$name} != $oldquota{$name}) {
3320: if ("a_admin($newquota{$name},\%changeHash,$name)) {
3321: $changed{$name.'quota'} = 1;
3322: }
3323: }
1.334 raeburn 3324: } else {
1.378 raeburn 3325: if ("a_admin('',\%changeHash,$name)) {
3326: $changed{$name.'quota'} = 1;
3327: $newquota{$name} = $newdefquota{$name};
3328: $newisdefault{$name} = 1;
3329: }
1.334 raeburn 3330: }
1.149 raeburn 3331: } else {
1.378 raeburn 3332: $oldisdefault{$name} = 1;
3333: $oldquota{$name} = $olddefquota{$name};
3334: if ($env{'form.custom_'.$name.'quota'} == 1) {
3335: if ($env{'form.'.$name.'quota'} eq '') {
3336: $newquota{$name} = 0;
3337: } else {
3338: $newquota{$name} = $env{'form.'.$name.'quota'};
3339: $newquota{$name} =~ s/[^\d\.]//g;
3340: }
3341: if ("a_admin($newquota{$name},\%changeHash,$name)) {
3342: $changed{$name.'quota'} = 1;
3343: }
1.334 raeburn 3344: } else {
1.378 raeburn 3345: $newquota{$name} = $newdefquota{$name};
3346: $newisdefault{$name} = 1;
1.334 raeburn 3347: }
1.378 raeburn 3348: }
3349: if ($oldisdefault{$name}) {
3350: $oldsettingstext{'quota'}{$name} = &get_defaultquota_text($oldsettingstatus{$name});
1.383 raeburn 3351: } else {
3352: $oldsettingstext{'quota'}{$name} = &mt('custom quota: [_1] MB',$oldquota{$name});
1.378 raeburn 3353: }
3354: if ($newisdefault{$name}) {
3355: $newsettingstext{'quota'}{$name} = &get_defaultquota_text($newsettingstatus{$name});
1.383 raeburn 3356: } else {
3357: $newsettingstext{'quota'}{$name} = &mt('custom quota: [_1] MB',$newquota{$name});
1.134 raeburn 3358: }
3359: }
1.334 raeburn 3360: &tool_changes('tools',\@usertools,\%oldsettings,\%oldsettingstext,\%userenv,
3361: \%changeHash,\%changed,\%newsettings,\%newsettingstext);
3362: if ($env{'form.ccdomain'} eq $env{'request.role.domain'}) {
3363: &tool_changes('requestcourses',\@requestcourses,\%oldsettings,\%oldsettingstext,
3364: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
1.384 raeburn 3365: &tool_changes('requestauthor',\@requestauthor,\%oldsettings,\%oldsettingstext,
3366: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
1.149 raeburn 3367: } else {
1.334 raeburn 3368: &tool_changes('reqcrsotherdom',\@requestcourses,\%oldsettings,\%oldsettingstext,
3369: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
1.149 raeburn 3370: }
3371: }
1.334 raeburn 3372: foreach my $item (@userinfo) {
3373: if ($env{'form.c'.$item} ne $userenv{$item}) {
3374: $namechanged{$item} = 1;
3375: }
1.204 raeburn 3376: }
1.378 raeburn 3377: foreach my $name ('portfolio','author') {
1.390 bisitz 3378: $oldsettings{'quota'}{$name} = &mt('[_1] MB',$oldquota{$name});
3379: $newsettings{'quota'}{$name} = &mt('[_1] MB',$newquota{$name});
1.378 raeburn 3380: }
1.334 raeburn 3381: if ((keys(%namechanged) > 0) || (keys(%changed) > 0)) {
1.267 raeburn 3382: my ($chgresult,$namechgresult);
3383: if (keys(%changed) > 0) {
3384: $chgresult =
1.204 raeburn 3385: &Apache::lonnet::put('environment',\%changeHash,
3386: $env{'form.ccdomain'},$env{'form.ccuname'});
1.267 raeburn 3387: if ($chgresult eq 'ok') {
3388: if (($env{'user.name'} eq $env{'form.ccuname'}) &&
3389: ($env{'user.domain'} eq $env{'form.ccdomain'})) {
1.270 raeburn 3390: my %newenvhash;
3391: foreach my $key (keys(%changed)) {
1.411 raeburn 3392: if (($key eq 'official') || ($key eq 'unofficial') ||
3393: ($key eq 'community') || ($key eq 'textbook') ||
1.449 raeburn 3394: ($key eq 'placement') || ($key eq 'lti')) {
1.279 raeburn 3395: $newenvhash{'environment.requestcourses.'.$key} =
3396: $changeHash{'requestcourses.'.$key};
1.362 raeburn 3397: if ($changeHash{'requestcourses.'.$key}) {
1.332 raeburn 3398: $newenvhash{'environment.canrequest.'.$key} = 1;
1.279 raeburn 3399: } else {
3400: $newenvhash{'environment.canrequest.'.$key} =
3401: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
3402: $key,'reload','requestcourses');
3403: }
1.362 raeburn 3404: } elsif ($key eq 'requestauthor') {
3405: $newenvhash{'environment.'.$key} = $changeHash{$key};
3406: if ($changeHash{$key}) {
3407: $newenvhash{'environment.canrequest.author'} = 1;
3408: } else {
3409: $newenvhash{'environment.canrequest.author'} =
3410: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
3411: $key,'reload','requestauthor');
3412: }
1.275 raeburn 3413: } elsif ($key ne 'quota') {
1.270 raeburn 3414: $newenvhash{'environment.tools.'.$key} =
3415: $changeHash{'tools.'.$key};
1.279 raeburn 3416: if ($changeHash{'tools.'.$key} ne '') {
3417: $newenvhash{'environment.availabletools.'.$key} =
3418: $changeHash{'tools.'.$key};
3419: } else {
3420: $newenvhash{'environment.availabletools.'.$key} =
1.367 golterma 3421: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
3422: $key,'reload','tools');
1.279 raeburn 3423: }
1.270 raeburn 3424: }
3425: }
1.271 raeburn 3426: if (keys(%newenvhash)) {
3427: &Apache::lonnet::appenv(\%newenvhash);
3428: }
1.267 raeburn 3429: }
1.463 raeburn 3430: if ($changed{'aboutme'}) {
3431: &Apache::loncommon::devalidate_aboutme_cache($env{'form.ccuname'},
3432: $env{'form.ccdomain'});
3433: }
1.267 raeburn 3434: }
1.204 raeburn 3435: }
1.334 raeburn 3436: if (keys(%namechanged) > 0) {
1.337 raeburn 3437: foreach my $field (@userinfo) {
3438: $changeHash{$field} = $env{'form.c'.$field};
3439: }
3440: # Make the change
1.204 raeburn 3441: $namechgresult =
3442: &Apache::lonnet::modifyuser($env{'form.ccdomain'},
3443: $env{'form.ccuname'},$changeHash{'id'},undef,undef,
3444: $changeHash{'firstname'},$changeHash{'middlename'},
3445: $changeHash{'lastname'},$changeHash{'generation'},
1.337 raeburn 3446: $changeHash{'id'},undef,$changeHash{'permanentemail'},undef,\@userinfo);
1.220 raeburn 3447: %userupdate = (
3448: lastname => $env{'form.clastname'},
3449: middlename => $env{'form.cmiddlename'},
3450: firstname => $env{'form.cfirstname'},
3451: generation => $env{'form.cgeneration'},
3452: id => $env{'form.cid'},
3453: );
1.204 raeburn 3454: }
1.334 raeburn 3455: if (((keys(%namechanged) > 0) && $namechgresult eq 'ok') ||
1.267 raeburn 3456: ((keys(%changed) > 0) && $chgresult eq 'ok')) {
1.28 matthew 3457: # Tell the user we changed the name
1.334 raeburn 3458: &display_userinfo($r,1,\@disporder,\%canshow,\@requestcourses,
1.362 raeburn 3459: \@usertools,\@requestauthor,\%userenv,\%changed,\%namechanged,
1.334 raeburn 3460: \%oldsettings, \%oldsettingstext,\%newsettings,
3461: \%newsettingstext);
1.203 raeburn 3462: if ($env{'form.cid'} ne $userenv{'id'}) {
3463: &Apache::lonnet::idput($env{'form.ccdomain'},
1.407 raeburn 3464: {$env{'form.ccuname'} => $env{'form.cid'}},$uhome,'ids');
1.203 raeburn 3465: if (($recurseid) &&
3466: (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'}))) {
3467: my $idresult =
3468: &Apache::lonuserutils::propagate_id_change(
3469: $env{'form.ccuname'},$env{'form.ccdomain'},
3470: \%userupdate);
3471: $r->print('<br />'.$idresult.'<br />');
3472: }
1.196 raeburn 3473: }
1.149 raeburn 3474: if (($env{'form.ccdomain'} eq $env{'user.domain'}) &&
3475: ($env{'form.ccuname'} eq $env{'user.name'})) {
3476: my %newenvhash;
3477: foreach my $key (keys(%changeHash)) {
3478: $newenvhash{'environment.'.$key} = $changeHash{$key};
3479: }
1.238 raeburn 3480: &Apache::lonnet::appenv(\%newenvhash);
1.149 raeburn 3481: }
1.28 matthew 3482: } else { # error occurred
1.389 bisitz 3483: $r->print(
3484: '<p class="LC_error">'
3485: .&mt('Unable to successfully change environment for [_1] in domain [_2].',
3486: '"'.$env{'form.ccuname'}.'"',
3487: '"'.$env{'form.ccdomain'}.'"')
3488: .'</p>');
1.28 matthew 3489: }
1.334 raeburn 3490: } else { # End of if ($env ... ) logic
1.275 raeburn 3491: # They did not want to change the users name, quota, tool availability,
3492: # or ability to request creation of courses,
1.267 raeburn 3493: # but we can still tell them what the name and quota and availabilities are
1.334 raeburn 3494: &display_userinfo($r,undef,\@disporder,\%canshow,\@requestcourses,
1.362 raeburn 3495: \@usertools,\@requestauthor,\%userenv,\%changed,\%namechanged,\%oldsettings,
1.334 raeburn 3496: \%oldsettingstext,\%newsettings,\%newsettingstext);
1.28 matthew 3497: }
1.206 raeburn 3498: if (@mod_disallowed) {
3499: my ($rolestr,$contextname);
3500: if (@longroles > 0) {
3501: $rolestr = join(', ',@longroles);
3502: } else {
3503: $rolestr = &mt('No roles');
3504: }
3505: if ($context eq 'course') {
1.399 bisitz 3506: $contextname = 'course';
1.206 raeburn 3507: } elsif ($context eq 'author') {
1.399 bisitz 3508: $contextname = 'co-author';
1.206 raeburn 3509: }
3510: $r->print(&mt('The following fields were not updated: ').'<ul>');
3511: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
3512: foreach my $field (@mod_disallowed) {
3513: $r->print('<li>'.$fieldtitles{$field}.'</li>'."\n");
3514: }
1.207 raeburn 3515: $r->print('</ul>');
3516: if (@mod_disallowed == 1) {
1.399 bisitz 3517: $r->print(&mt("You do not have the authority to change this field given the user's current set of active/future $contextname roles:"));
1.207 raeburn 3518: } else {
1.399 bisitz 3519: $r->print(&mt("You do not have the authority to change these fields given the user's current set of active/future $contextname roles:"));
1.207 raeburn 3520: }
1.292 bisitz 3521: my $helplink = 'javascript:helpMenu('."'display'".')';
3522: $r->print('<span class="LC_cusr_emph">'.$rolestr.'</span><br />'
3523: .&mt('Please contact your [_1]helpdesk[_2] for more information.'
3524: ,'<a href="'.$helplink.'">','</a>')
3525: .'<br />');
1.206 raeburn 3526: }
1.259 bisitz 3527: $r->print('<span class="LC_warning">'
3528: .$no_forceid_alert
3529: .&Apache::lonuserutils::print_namespacing_alerts($env{'form.ccdomain'},\%alerts,\%curr_rules)
3530: .'</span>');
1.4 www 3531: }
1.367 golterma 3532: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
1.220 raeburn 3533: if ($env{'form.action'} eq 'singlestudent') {
1.375 raeburn 3534: &enroll_single_student($r,$uhome,$amode,$genpwd,$now,$newuser,$context,
3535: $crstype,$showcredits,$defaultcredits);
1.386 bisitz 3536: my $linktext = ($crstype eq 'Community' ?
3537: &mt('Enroll Another Member') : &mt('Enroll Another Student'));
3538: $r->print(
3539: &Apache::lonhtmlcommon::actionbox([
3540: '<a href="javascript:backPage(document.userupdate)">'
3541: .($crstype eq 'Community' ?
3542: &mt('Enroll Another Member') : &mt('Enroll Another Student'))
3543: .'</a>']));
1.220 raeburn 3544: } else {
1.375 raeburn 3545: my @rolechanges = &update_roles($r,$context,$showcredits);
1.334 raeburn 3546: if (keys(%namechanged) > 0) {
1.220 raeburn 3547: if ($context eq 'course') {
3548: if (@userroles > 0) {
1.225 raeburn 3549: if ((@rolechanges == 0) ||
3550: (!(grep(/^st$/,@rolechanges)))) {
3551: if (grep(/^st$/,@userroles)) {
3552: my $classlistupdated =
3553: &Apache::lonuserutils::update_classlist($cdom,
1.220 raeburn 3554: $cnum,$env{'form.ccdomain'},
3555: $env{'form.ccuname'},\%userupdate);
1.225 raeburn 3556: }
1.220 raeburn 3557: }
3558: }
3559: }
3560: }
1.226 raeburn 3561: my $userinfo = &Apache::loncommon::plainname($env{'form.ccuname'},
1.233 raeburn 3562: $env{'form.ccdomain'});
3563: if ($env{'form.popup'}) {
3564: $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a></p>');
3565: } else {
1.367 golterma 3566: $r->print('<br />'.&Apache::lonhtmlcommon::actionbox(['<a href="javascript:backPage(document.userupdate,'."'$env{'form.prevphase'}','modify'".')">'
3567: .&mt('Modify this user: [_1]','<span class="LC_cusr_emph">'.$env{'form.ccuname'}.':'.$env{'form.ccdomain'}.' ('.$userinfo.')</span>').'</a>',
3568: '<a href="javascript:backPage(document.userupdate)">'.&mt('Create/Modify Another User').'</a>']));
1.233 raeburn 3569: }
1.220 raeburn 3570: }
3571: }
3572:
1.334 raeburn 3573: sub display_userinfo {
1.362 raeburn 3574: my ($r,$changed,$order,$canshow,$requestcourses,$usertools,$requestauthor,
3575: $userenv,$changedhash,$namechangedhash,$oldsetting,$oldsettingtext,
1.334 raeburn 3576: $newsetting,$newsettingtext) = @_;
3577: return unless (ref($order) eq 'ARRAY' &&
3578: ref($canshow) eq 'HASH' &&
3579: ref($requestcourses) eq 'ARRAY' &&
1.362 raeburn 3580: ref($requestauthor) eq 'ARRAY' &&
1.334 raeburn 3581: ref($usertools) eq 'ARRAY' &&
3582: ref($userenv) eq 'HASH' &&
3583: ref($changedhash) eq 'HASH' &&
3584: ref($oldsetting) eq 'HASH' &&
3585: ref($oldsettingtext) eq 'HASH' &&
3586: ref($newsetting) eq 'HASH' &&
3587: ref($newsettingtext) eq 'HASH');
3588: my %lt=&Apache::lonlocal::texthash(
1.372 raeburn 3589: 'ui' => 'User Information',
1.334 raeburn 3590: 'uic' => 'User Information Changed',
3591: 'firstname' => 'First Name',
3592: 'middlename' => 'Middle Name',
3593: 'lastname' => 'Last Name',
3594: 'generation' => 'Generation',
3595: 'id' => 'Student/Employee ID',
3596: 'permanentemail' => 'Permanent e-mail address',
1.378 raeburn 3597: 'portfolioquota' => 'Disk space allocated to portfolio files',
1.385 bisitz 3598: 'authorquota' => 'Disk space allocated to Authoring Space',
1.334 raeburn 3599: 'blog' => 'Blog Availability',
1.361 raeburn 3600: 'webdav' => 'WebDAV Availability',
1.334 raeburn 3601: 'aboutme' => 'Personal Information Page Availability',
3602: 'portfolio' => 'Portfolio Availability',
1.459 raeburn 3603: 'timezone' => 'Can set own Time Zone',
1.334 raeburn 3604: 'official' => 'Can Request Official Courses',
3605: 'unofficial' => 'Can Request Unofficial Courses',
3606: 'community' => 'Can Request Communities',
1.384 raeburn 3607: 'textbook' => 'Can Request Textbook Courses',
1.411 raeburn 3608: 'placement' => 'Can Request Placement Tests',
1.449 raeburn 3609: 'lti' => 'Can Request LTI Courses',
1.362 raeburn 3610: 'requestauthor' => 'Can Request Author Role',
1.334 raeburn 3611: 'inststatus' => "Affiliation",
3612: 'prvs' => 'Previous Value:',
3613: 'chto' => 'Changed To:'
3614: );
3615: if ($changed) {
1.372 raeburn 3616: $r->print('<h3>'.$lt{'uic'}.'</h3>'.
1.367 golterma 3617: &Apache::loncommon::start_data_table().
3618: &Apache::loncommon::start_data_table_header_row());
1.334 raeburn 3619: $r->print("<th> </th>\n");
1.367 golterma 3620: $r->print('<th><b>'.$lt{'prvs'}.'</b></th>');
3621: $r->print('<th><span class="LC_nobreak"><b>'.$lt{'chto'}.'</b></span></th>');
3622: $r->print(&Apache::loncommon::end_data_table_header_row());
3623: my @userinfo = ('firstname','middlename','lastname','generation','permanentemail','id');
3624:
1.334 raeburn 3625: foreach my $item (@userinfo) {
3626: my $value = $env{'form.c'.$item};
1.367 golterma 3627: #show changes only:
1.383 raeburn 3628: unless ($value eq $userenv->{$item}){
1.367 golterma 3629: $r->print(&Apache::loncommon::start_data_table_row());
3630: $r->print("<td>$lt{$item}</td>\n");
1.383 raeburn 3631: $r->print("<td>".$userenv->{$item}."</td>\n");
1.367 golterma 3632: $r->print("<td>$value </td>\n");
3633: $r->print(&Apache::loncommon::end_data_table_row());
1.334 raeburn 3634: }
3635: }
3636: foreach my $entry (@{$order}) {
1.383 raeburn 3637: if ($canshow->{$entry}) {
3638: if (($entry eq 'requestcourses') || ($entry eq 'reqcrsotherdom') || ($entry eq 'requestauthor')) {
3639: my @items;
3640: if ($entry eq 'requestauthor') {
3641: @items = ($entry);
3642: } else {
3643: @items = @{$requestcourses};
1.384 raeburn 3644: }
1.383 raeburn 3645: foreach my $item (@items) {
3646: if (($newsetting->{$item} ne $oldsetting->{$item}) ||
3647: ($newsettingtext->{$item} ne $oldsettingtext->{$item})) {
3648: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3649: $r->print("<td>$lt{$item}</td>\n");
3650: $r->print("<td>".$oldsetting->{$item});
3651: if ($oldsettingtext->{$item}) {
3652: if ($oldsetting->{$item}) {
3653: $r->print(' -- ');
3654: }
3655: $r->print($oldsettingtext->{$item});
3656: }
3657: $r->print("</td>\n");
3658: $r->print("<td>".$newsetting->{$item});
3659: if ($newsettingtext->{$item}) {
3660: if ($newsetting->{$item}) {
3661: $r->print(' -- ');
3662: }
3663: $r->print($newsettingtext->{$item});
3664: }
3665: $r->print("</td>\n");
3666: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.334 raeburn 3667: }
3668: }
3669: } elsif ($entry eq 'tools') {
3670: foreach my $item (@{$usertools}) {
1.383 raeburn 3671: if ($newsetting->{$item} ne $oldsetting->{$item}) {
3672: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3673: $r->print("<td>$lt{$item}</td>\n");
3674: $r->print("<td>".$oldsetting->{$item}.' '.$oldsettingtext->{$item}."</td>\n");
3675: $r->print("<td>".$newsetting->{$item}.' '.$newsettingtext->{$item}."</td>\n");
3676: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.334 raeburn 3677: }
3678: }
1.378 raeburn 3679: } elsif ($entry eq 'quota') {
3680: if ((ref($oldsetting->{$entry}) eq 'HASH') && (ref($oldsettingtext->{$entry}) eq 'HASH') &&
3681: (ref($newsetting->{$entry}) eq 'HASH') && (ref($newsettingtext->{$entry}) eq 'HASH')) {
3682: foreach my $name ('portfolio','author') {
1.383 raeburn 3683: if ($newsetting->{$entry}->{$name} ne $oldsetting->{$entry}->{$name}) {
3684: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3685: $r->print("<td>$lt{$name.$entry}</td>\n");
3686: $r->print("<td>".$oldsettingtext->{$entry}->{$name}."</td>\n");
3687: $r->print("<td>".$newsettingtext->{$entry}->{$name}."</td>\n");
3688: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.378 raeburn 3689: }
3690: }
3691: }
1.334 raeburn 3692: } else {
1.383 raeburn 3693: if ($newsetting->{$entry} ne $oldsetting->{$entry}) {
3694: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3695: $r->print("<td>$lt{$entry}</td>\n");
3696: $r->print("<td>".$oldsetting->{$entry}.' '.$oldsettingtext->{$entry}."</td>\n");
3697: $r->print("<td>".$newsetting->{$entry}.' '.$newsettingtext->{$entry}."</td>\n");
3698: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.334 raeburn 3699: }
3700: }
3701: }
3702: }
1.367 golterma 3703: $r->print(&Apache::loncommon::end_data_table().'<br />');
1.372 raeburn 3704: } else {
3705: $r->print('<h3>'.$lt{'ui'}.'</h3>'.
3706: '<p>'.&mt('No changes made to user information').'</p>');
1.334 raeburn 3707: }
3708: return;
3709: }
3710:
1.275 raeburn 3711: sub tool_changes {
3712: my ($context,$usertools,$oldaccess,$oldaccesstext,$userenv,$changeHash,
3713: $changed,$newaccess,$newaccesstext) = @_;
3714: if (!((ref($usertools) eq 'ARRAY') && (ref($oldaccess) eq 'HASH') &&
3715: (ref($oldaccesstext) eq 'HASH') && (ref($userenv) eq 'HASH') &&
3716: (ref($changeHash) eq 'HASH') && (ref($changed) eq 'HASH') &&
3717: (ref($newaccess) eq 'HASH') && (ref($newaccesstext) eq 'HASH'))) {
3718: return;
3719: }
1.383 raeburn 3720: my %reqdisplay = &requestchange_display();
1.300 raeburn 3721: if ($context eq 'reqcrsotherdom') {
1.309 raeburn 3722: my @options = ('approval','validate','autolimit');
1.306 raeburn 3723: my $optregex = join('|',@options);
1.300 raeburn 3724: my $cdom = $env{'request.role.domain'};
3725: foreach my $tool (@{$usertools}) {
1.383 raeburn 3726: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
1.314 raeburn 3727: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
1.300 raeburn 3728: $changeHash->{$context.'.'.$tool} = $userenv->{$context.'.'.$tool};
1.383 raeburn 3729: my ($newop,$limit);
1.314 raeburn 3730: if ($env{'form.'.$context.'_'.$tool}) {
3731: $newop = $env{'form.'.$context.'_'.$tool};
3732: if ($newop eq 'autolimit') {
1.383 raeburn 3733: $limit = $env{'form.'.$context.'_'.$tool.'_limit'};
1.314 raeburn 3734: $limit =~ s/\D+//g;
3735: $newop .= '='.$limit;
3736: }
3737: }
1.300 raeburn 3738: if ($userenv->{$context.'.'.$tool} eq '') {
1.314 raeburn 3739: if ($newop) {
3740: $changed->{$tool}=&tool_admin($tool,$cdom.':'.$newop,
1.300 raeburn 3741: $changeHash,$context);
3742: if ($changed->{$tool}) {
1.383 raeburn 3743: if ($newop =~ /^autolimit/) {
3744: if ($limit) {
3745: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3746: } else {
3747: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3748: }
3749: } else {
3750: $newaccesstext->{$tool} = $reqdisplay{$newop};
3751: }
1.300 raeburn 3752: } else {
3753: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
3754: }
3755: }
3756: } else {
3757: my @curr = split(',',$userenv->{$context.'.'.$tool});
3758: my @new;
3759: my $changedoms;
1.314 raeburn 3760: foreach my $req (@curr) {
3761: if ($req =~ /^\Q$cdom\E\:($optregex\=?\d*)$/) {
3762: my $oldop = $1;
1.383 raeburn 3763: if ($oldop =~ /^autolimit=(\d*)/) {
3764: my $limit = $1;
3765: if ($limit) {
3766: $oldaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3767: } else {
3768: $oldaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3769: }
3770: } else {
3771: $oldaccesstext->{$tool} = $reqdisplay{$oldop};
3772: }
1.314 raeburn 3773: if ($oldop ne $newop) {
3774: $changedoms = 1;
3775: foreach my $item (@curr) {
3776: my ($reqdom,$option) = split(':',$item);
3777: unless ($reqdom eq $cdom) {
3778: push(@new,$item);
3779: }
3780: }
3781: if ($newop) {
3782: push(@new,$cdom.':'.$newop);
1.300 raeburn 3783: }
1.314 raeburn 3784: @new = sort(@new);
1.300 raeburn 3785: }
1.314 raeburn 3786: last;
1.300 raeburn 3787: }
1.314 raeburn 3788: }
3789: if ((!$changedoms) && ($newop)) {
1.300 raeburn 3790: $changedoms = 1;
1.306 raeburn 3791: @new = sort(@curr,$cdom.':'.$newop);
1.300 raeburn 3792: }
3793: if ($changedoms) {
1.314 raeburn 3794: my $newdomstr;
1.300 raeburn 3795: if (@new) {
3796: $newdomstr = join(',',@new);
3797: }
3798: $changed->{$tool}=&tool_admin($tool,$newdomstr,$changeHash,
3799: $context);
3800: if ($changed->{$tool}) {
3801: if ($env{'form.'.$context.'_'.$tool}) {
1.306 raeburn 3802: if ($env{'form.'.$context.'_'.$tool} eq 'autolimit') {
1.314 raeburn 3803: my $limit = $env{'form.'.$context.'_'.$tool.'_limit'};
3804: $limit =~ s/\D+//g;
3805: if ($limit) {
1.383 raeburn 3806: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
1.314 raeburn 3807: } else {
1.383 raeburn 3808: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
1.306 raeburn 3809: }
1.314 raeburn 3810: } else {
1.306 raeburn 3811: $newaccesstext->{$tool} = $reqdisplay{$env{'form.'.$context.'_'.$tool}};
3812: }
1.300 raeburn 3813: } else {
1.383 raeburn 3814: $newaccesstext->{$tool} = &mt("availability set to 'off'");
1.300 raeburn 3815: }
3816: }
3817: }
3818: }
3819: }
3820: return;
3821: }
1.275 raeburn 3822: foreach my $tool (@{$usertools}) {
1.383 raeburn 3823: my ($newval,$limit,$envkey);
1.362 raeburn 3824: $envkey = $context.'.'.$tool;
1.306 raeburn 3825: if ($context eq 'requestcourses') {
3826: $newval = $env{'form.crsreq_'.$tool};
3827: if ($newval eq 'autolimit') {
1.383 raeburn 3828: $limit = $env{'form.crsreq_'.$tool.'_limit'};
3829: $limit =~ s/\D+//g;
3830: $newval .= '='.$limit;
1.306 raeburn 3831: }
1.362 raeburn 3832: } elsif ($context eq 'requestauthor') {
3833: $newval = $env{'form.'.$context};
3834: $envkey = $context;
1.314 raeburn 3835: } else {
1.306 raeburn 3836: $newval = $env{'form.'.$context.'_'.$tool};
3837: }
1.362 raeburn 3838: if ($userenv->{$envkey} ne '') {
1.275 raeburn 3839: $oldaccess->{$tool} = &mt('custom');
1.383 raeburn 3840: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3841: if ($userenv->{$envkey} =~ /^autolimit=(\d*)$/) {
3842: my $currlimit = $1;
3843: if ($currlimit eq '') {
3844: $oldaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3845: } else {
3846: $oldaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$currlimit);
3847: }
3848: } elsif ($userenv->{$envkey}) {
3849: $oldaccesstext->{$tool} = $reqdisplay{$userenv->{$envkey}};
3850: } else {
3851: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
3852: }
1.275 raeburn 3853: } else {
1.383 raeburn 3854: if ($userenv->{$envkey}) {
3855: $oldaccesstext->{$tool} = &mt("availability set to 'on'");
3856: } else {
3857: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
3858: }
1.275 raeburn 3859: }
1.362 raeburn 3860: $changeHash->{$envkey} = $userenv->{$envkey};
1.275 raeburn 3861: if ($env{'form.custom'.$tool} == 1) {
1.362 raeburn 3862: if ($newval ne $userenv->{$envkey}) {
1.306 raeburn 3863: $changed->{$tool} = &tool_admin($tool,$newval,$changeHash,
3864: $context);
1.275 raeburn 3865: if ($changed->{$tool}) {
3866: $newaccess->{$tool} = &mt('custom');
1.383 raeburn 3867: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3868: if ($newval =~ /^autolimit/) {
3869: if ($limit) {
3870: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3871: } else {
3872: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3873: }
3874: } elsif ($newval) {
3875: $newaccesstext->{$tool} = $reqdisplay{$newval};
3876: } else {
3877: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3878: }
1.275 raeburn 3879: } else {
1.383 raeburn 3880: if ($newval) {
3881: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3882: } else {
3883: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3884: }
1.275 raeburn 3885: }
3886: } else {
3887: $newaccess->{$tool} = $oldaccess->{$tool};
1.383 raeburn 3888: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3889: if ($newval =~ /^autolimit/) {
3890: if ($limit) {
3891: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3892: } else {
3893: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3894: }
3895: } elsif ($newval) {
3896: $newaccesstext->{$tool} = $reqdisplay{$newval};
3897: } else {
3898: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3899: }
1.275 raeburn 3900: } else {
1.383 raeburn 3901: if ($userenv->{$context.'.'.$tool}) {
3902: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3903: } else {
3904: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3905: }
1.275 raeburn 3906: }
3907: }
3908: } else {
3909: $newaccess->{$tool} = $oldaccess->{$tool};
3910: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
3911: }
3912: } else {
3913: $changed->{$tool} = &tool_admin($tool,'',$changeHash,$context);
3914: if ($changed->{$tool}) {
3915: $newaccess->{$tool} = &mt('default');
3916: } else {
3917: $newaccess->{$tool} = $oldaccess->{$tool};
1.383 raeburn 3918: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3919: if ($newval =~ /^autolimit/) {
3920: if ($limit) {
3921: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3922: } else {
3923: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3924: }
3925: } elsif ($newval) {
3926: $newaccesstext->{$tool} = $reqdisplay{$newval};
3927: } else {
3928: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3929: }
1.275 raeburn 3930: } else {
1.383 raeburn 3931: if ($userenv->{$context.'.'.$tool}) {
3932: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3933: } else {
3934: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3935: }
1.275 raeburn 3936: }
3937: }
3938: }
3939: } else {
3940: $oldaccess->{$tool} = &mt('default');
3941: if ($env{'form.custom'.$tool} == 1) {
1.306 raeburn 3942: $changed->{$tool} = &tool_admin($tool,$newval,$changeHash,
3943: $context);
1.275 raeburn 3944: if ($changed->{$tool}) {
3945: $newaccess->{$tool} = &mt('custom');
1.383 raeburn 3946: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3947: if ($newval =~ /^autolimit/) {
3948: if ($limit) {
3949: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3950: } else {
3951: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3952: }
3953: } elsif ($newval) {
3954: $newaccesstext->{$tool} = $reqdisplay{$newval};
3955: } else {
3956: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3957: }
1.275 raeburn 3958: } else {
1.383 raeburn 3959: if ($newval) {
3960: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3961: } else {
3962: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3963: }
1.275 raeburn 3964: }
3965: } else {
3966: $newaccess->{$tool} = $oldaccess->{$tool};
3967: }
3968: } else {
3969: $newaccess->{$tool} = $oldaccess->{$tool};
3970: }
3971: }
3972: }
3973: return;
3974: }
3975:
1.220 raeburn 3976: sub update_roles {
1.375 raeburn 3977: my ($r,$context,$showcredits) = @_;
1.4 www 3978: my $now=time;
1.225 raeburn 3979: my @rolechanges;
1.220 raeburn 3980: my %disallowed;
1.73 sakharuk 3981: $r->print('<h3>'.&mt('Modifying Roles').'</h3>');
1.404 raeburn 3982: foreach my $key (keys(%env)) {
1.135 raeburn 3983: next if (! $env{$key});
1.190 raeburn 3984: next if ($key eq 'form.action');
1.27 matthew 3985: # Revoke roles
1.135 raeburn 3986: if ($key=~/^form\.rev/) {
3987: if ($key=~/^form\.rev\:([^\_]+)\_([^\_\.]+)$/) {
1.64 www 3988: # Revoke standard role
1.170 albertel 3989: my ($scope,$role) = ($1,$2);
3990: my $result =
3991: &Apache::lonnet::revokerole($env{'form.ccdomain'},
3992: $env{'form.ccuname'},
1.239 raeburn 3993: $scope,$role,'','',$context);
1.367 golterma 3994: $r->print(&Apache::lonhtmlcommon::confirm_success(
1.369 bisitz 3995: &mt('Revoking [_1] in [_2]',
3996: &Apache::lonnet::plaintext($role),
1.372 raeburn 3997: &Apache::loncommon::show_role_extent($scope,$context,$role)),
1.369 bisitz 3998: $result ne "ok").'<br />');
3999: if ($result ne "ok") {
4000: $r->print(&mt('Error: [_1]',$result).'<br />');
4001: }
1.170 albertel 4002: if ($role eq 'st') {
1.202 raeburn 4003: my $result =
1.198 raeburn 4004: &Apache::lonuserutils::classlist_drop($scope,
4005: $env{'form.ccuname'},$env{'form.ccdomain'},
1.202 raeburn 4006: $now);
1.367 golterma 4007: $r->print(&Apache::lonhtmlcommon::confirm_success($result));
1.53 www 4008: }
1.225 raeburn 4009: if (!grep(/^\Q$role\E$/,@rolechanges)) {
4010: push(@rolechanges,$role);
4011: }
1.196 raeburn 4012: }
1.195 raeburn 4013: if ($key=~m{^form\.rev\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}s) {
1.64 www 4014: # Revoke custom role
1.369 bisitz 4015: my $result = &Apache::lonnet::revokecustomrole(
4016: $env{'form.ccdomain'},$env{'form.ccuname'},$1,$2,$3,$4,'','',$context);
1.367 golterma 4017: $r->print(&Apache::lonhtmlcommon::confirm_success(
1.369 bisitz 4018: &mt('Revoking custom role [_1] by [_2] in [_3]',
1.372 raeburn 4019: $4,$3.':'.$2,&Apache::loncommon::show_role_extent($1,$context,'cr')),
1.369 bisitz 4020: $result ne 'ok').'<br />');
4021: if ($result ne "ok") {
4022: $r->print(&mt('Error: [_1]',$result).'<br />');
4023: }
1.225 raeburn 4024: if (!grep(/^cr$/,@rolechanges)) {
4025: push(@rolechanges,'cr');
4026: }
1.64 www 4027: }
1.135 raeburn 4028: } elsif ($key=~/^form\.del/) {
4029: if ($key=~/^form\.del\:([^\_]+)\_([^\_\.]+)$/) {
1.116 raeburn 4030: # Delete standard role
1.170 albertel 4031: my ($scope,$role) = ($1,$2);
4032: my $result =
4033: &Apache::lonnet::assignrole($env{'form.ccdomain'},
4034: $env{'form.ccuname'},
1.239 raeburn 4035: $scope,$role,$now,0,1,'',
4036: $context);
1.367 golterma 4037: $r->print(&Apache::lonhtmlcommon::confirm_success(
4038: &mt('Deleting [_1] in [_2]',
1.369 bisitz 4039: &Apache::lonnet::plaintext($role),
1.372 raeburn 4040: &Apache::loncommon::show_role_extent($scope,$context,$role)),
1.369 bisitz 4041: $result ne 'ok').'<br />');
4042: if ($result ne "ok") {
4043: $r->print(&mt('Error: [_1]',$result).'<br />');
4044: }
1.367 golterma 4045:
1.170 albertel 4046: if ($role eq 'st') {
1.202 raeburn 4047: my $result =
1.198 raeburn 4048: &Apache::lonuserutils::classlist_drop($scope,
4049: $env{'form.ccuname'},$env{'form.ccdomain'},
1.202 raeburn 4050: $now);
1.369 bisitz 4051: $r->print(&Apache::lonhtmlcommon::confirm_success($result));
1.81 albertel 4052: }
1.225 raeburn 4053: if (!grep(/^\Q$role\E$/,@rolechanges)) {
4054: push(@rolechanges,$role);
4055: }
1.116 raeburn 4056: }
1.139 albertel 4057: if ($key=~m{^form\.del\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
1.116 raeburn 4058: my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
4059: # Delete custom role
1.369 bisitz 4060: my $result =
4061: &Apache::lonnet::assigncustomrole($env{'form.ccdomain'},
4062: $env{'form.ccuname'},$url,$rdom,$rnam,$rolename,$now,
4063: 0,1,$context);
4064: $r->print(&Apache::lonhtmlcommon::confirm_success(&mt('Deleting custom role [_1] by [_2] in [_3]',
1.372 raeburn 4065: $rolename,$rnam.':'.$rdom,&Apache::loncommon::show_role_extent($1,$context,'cr')),
1.369 bisitz 4066: $result ne "ok").'<br />');
4067: if ($result ne "ok") {
4068: $r->print(&mt('Error: [_1]',$result).'<br />');
4069: }
1.367 golterma 4070:
1.225 raeburn 4071: if (!grep(/^cr$/,@rolechanges)) {
4072: push(@rolechanges,'cr');
4073: }
1.116 raeburn 4074: }
1.135 raeburn 4075: } elsif ($key=~/^form\.ren/) {
1.101 albertel 4076: my $udom = $env{'form.ccdomain'};
4077: my $uname = $env{'form.ccuname'};
1.116 raeburn 4078: # Re-enable standard role
1.135 raeburn 4079: if ($key=~/^form\.ren\:([^\_]+)\_([^\_\.]+)$/) {
1.89 raeburn 4080: my $url = $1;
4081: my $role = $2;
4082: my $logmsg;
4083: my $output;
4084: if ($role eq 'st') {
1.141 albertel 4085: if ($url =~ m-^/($match_domain)/($match_courseid)/?(\w*)$-) {
1.374 raeburn 4086: my ($cdom,$cnum,$csec) = ($1,$2,$3);
1.375 raeburn 4087: my $credits;
4088: if ($showcredits) {
4089: my $defaultcredits =
4090: &Apache::lonuserutils::get_defaultcredits($cdom,$cnum);
4091: $credits = &get_user_credits($defaultcredits,$cdom,$cnum);
4092: }
4093: my $result = &Apache::loncommon::commit_studentrole(\$logmsg,$udom,$uname,$url,$role,$now,0,$cdom,$cnum,$csec,$context,$credits);
1.220 raeburn 4094: if (($result =~ /^error/) || ($result eq 'not_in_class') || ($result eq 'unknown_course') || ($result eq 'refused')) {
1.223 raeburn 4095: if ($result eq 'refused' && $logmsg) {
4096: $output = $logmsg;
4097: } else {
1.369 bisitz 4098: $output = &mt('Error: [_1]',$result)."\n";
1.223 raeburn 4099: }
1.89 raeburn 4100: } else {
1.372 raeburn 4101: $output = &Apache::lonhtmlcommon::confirm_success(&mt('Assigning [_1] in [_2] starting [_3]',
4102: &Apache::lonnet::plaintext($role),
4103: &Apache::loncommon::show_role_extent($url,$context,'st'),
4104: &Apache::lonlocal::locallocaltime($now))).'<br />'.$logmsg.'<br />';
1.89 raeburn 4105: }
4106: }
4107: } else {
1.101 albertel 4108: my $result=&Apache::lonnet::assignrole($env{'form.ccdomain'},
1.239 raeburn 4109: $env{'form.ccuname'},$url,$role,0,$now,'','',
4110: $context);
1.461 raeburn 4111: $output = &Apache::lonhtmlcommon::confirm_success(&mt('Re-enabling [_1] in [_2]',
4112: &Apache::lonnet::plaintext($role),
4113: &Apache::loncommon::show_role_extent($url,$context,$role)),$result ne "ok").'<br />';
1.369 bisitz 4114: if ($result ne "ok") {
4115: $output .= &mt('Error: [_1]',$result).'<br />';
4116: }
4117: }
1.89 raeburn 4118: $r->print($output);
1.225 raeburn 4119: if (!grep(/^\Q$role\E$/,@rolechanges)) {
4120: push(@rolechanges,$role);
4121: }
1.113 raeburn 4122: }
1.116 raeburn 4123: # Re-enable custom role
1.139 albertel 4124: if ($key=~m{^form\.ren\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
1.116 raeburn 4125: my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
4126: my $result = &Apache::lonnet::assigncustomrole(
4127: $env{'form.ccdomain'}, $env{'form.ccuname'},
1.240 raeburn 4128: $url,$rdom,$rnam,$rolename,0,$now,undef,$context);
1.369 bisitz 4129: $r->print(&Apache::lonhtmlcommon::confirm_success(
4130: &mt('Re-enabling custom role [_1] by [_2] in [_3]',
1.372 raeburn 4131: $rolename,$rnam.':'.$rdom,&Apache::loncommon::show_role_extent($1,$context,'cr')),
1.369 bisitz 4132: $result ne "ok").'<br />');
4133: if ($result ne "ok") {
4134: $r->print(&mt('Error: [_1]',$result).'<br />');
4135: }
1.225 raeburn 4136: if (!grep(/^cr$/,@rolechanges)) {
4137: push(@rolechanges,'cr');
4138: }
1.116 raeburn 4139: }
1.135 raeburn 4140: } elsif ($key=~/^form\.act/) {
1.101 albertel 4141: my $udom = $env{'form.ccdomain'};
4142: my $uname = $env{'form.ccuname'};
1.141 albertel 4143: if ($key=~/^form\.act\_($match_domain)\_($match_courseid)\_cr_cr_($match_domain)_($match_username)_([^\_]+)$/) {
1.65 www 4144: # Activate a custom role
1.83 albertel 4145: my ($one,$two,$three,$four,$five)=($1,$2,$3,$4,$5);
4146: my $url='/'.$one.'/'.$two;
4147: my $full=$one.'_'.$two.'_cr_cr_'.$three.'_'.$four.'_'.$five;
1.65 www 4148:
1.101 albertel 4149: my $start = ( $env{'form.start_'.$full} ?
4150: $env{'form.start_'.$full} :
1.88 raeburn 4151: $now );
1.101 albertel 4152: my $end = ( $env{'form.end_'.$full} ?
4153: $env{'form.end_'.$full} :
1.88 raeburn 4154: 0 );
4155:
4156: # split multiple sections
4157: my %sections = ();
1.461 raeburn 4158: my $num_sections = &build_roles($env{'form.sec_'.$full},\%sections,$five);
1.88 raeburn 4159: if ($num_sections == 0) {
1.240 raeburn 4160: $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$url,$three,$four,$five,$start,$end,$context));
1.88 raeburn 4161: } else {
1.114 albertel 4162: my %curr_groups =
1.117 raeburn 4163: &Apache::longroup::coursegroups($one,$two);
1.404 raeburn 4164: foreach my $sec (sort {$a cmp $b} keys(%sections)) {
1.113 raeburn 4165: if (($sec eq 'none') || ($sec eq 'all') ||
4166: exists($curr_groups{$sec})) {
4167: $disallowed{$sec} = $url;
4168: next;
4169: }
4170: my $securl = $url.'/'.$sec;
1.240 raeburn 4171: $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$securl,$three,$four,$five,$start,$end,$context));
1.88 raeburn 4172: }
4173: }
1.225 raeburn 4174: if (!grep(/^cr$/,@rolechanges)) {
4175: push(@rolechanges,'cr');
4176: }
1.142 raeburn 4177: } elsif ($key=~/^form\.act\_($match_domain)\_($match_name)\_([^\_]+)$/) {
1.27 matthew 4178: # Activate roles for sections with 3 id numbers
4179: # set start, end times, and the url for the class
1.83 albertel 4180: my ($one,$two,$three)=($1,$2,$3);
1.461 raeburn 4181: my $start = ( $env{'form.start_'.$one.'_'.$two.'_'.$three} ?
4182: $env{'form.start_'.$one.'_'.$two.'_'.$three} :
1.27 matthew 4183: $now );
1.461 raeburn 4184: my $end = ( $env{'form.end_'.$one.'_'.$two.'_'.$three} ?
1.101 albertel 4185: $env{'form.end_'.$one.'_'.$two.'_'.$three} :
1.27 matthew 4186: 0 );
1.83 albertel 4187: my $url='/'.$one.'/'.$two;
1.88 raeburn 4188: my $type = 'three';
4189: # split multiple sections
4190: my %sections = ();
1.101 albertel 4191: my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two.'_'.$three},\%sections,$three);
1.375 raeburn 4192: my $credits;
4193: if ($three eq 'st') {
1.461 raeburn 4194: if ($showcredits) {
1.375 raeburn 4195: my $defaultcredits =
4196: &Apache::lonuserutils::get_defaultcredits($one,$two);
4197: $credits = $env{'form.credits_'.$one.'_'.$two.'_'.$three};
4198: $credits =~ s/[^\d\.]//g;
4199: if ($credits eq $defaultcredits) {
4200: undef($credits);
4201: }
4202: }
4203: }
1.88 raeburn 4204: if ($num_sections == 0) {
1.375 raeburn 4205: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'',$context,$credits));
1.88 raeburn 4206: } else {
1.114 albertel 4207: my %curr_groups =
1.117 raeburn 4208: &Apache::longroup::coursegroups($one,$two);
1.88 raeburn 4209: my $emptysec = 0;
1.404 raeburn 4210: foreach my $sec (sort {$a cmp $b} keys(%sections)) {
1.88 raeburn 4211: $sec =~ s/\W//g;
1.113 raeburn 4212: if ($sec ne '') {
4213: if (($sec eq 'none') || ($sec eq 'all') ||
4214: exists($curr_groups{$sec})) {
4215: $disallowed{$sec} = $url;
4216: next;
4217: }
1.88 raeburn 4218: my $securl = $url.'/'.$sec;
1.375 raeburn 4219: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$three,$start,$end,$one,$two,$sec,$context,$credits));
1.88 raeburn 4220: } else {
4221: $emptysec = 1;
4222: }
4223: }
4224: if ($emptysec) {
1.375 raeburn 4225: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'',$context,$credits));
1.88 raeburn 4226: }
1.225 raeburn 4227: }
4228: if (!grep(/^\Q$three\E$/,@rolechanges)) {
4229: push(@rolechanges,$three);
4230: }
1.135 raeburn 4231: } elsif ($key=~/^form\.act\_([^\_]+)\_([^\_]+)$/) {
1.27 matthew 4232: # Activate roles for sections with two id numbers
4233: # set start, end times, and the url for the class
1.461 raeburn 4234: my $start = ( $env{'form.start_'.$1.'_'.$2} ?
4235: $env{'form.start_'.$1.'_'.$2} :
1.27 matthew 4236: $now );
1.461 raeburn 4237: my $end = ( $env{'form.end_'.$1.'_'.$2} ?
1.101 albertel 4238: $env{'form.end_'.$1.'_'.$2} :
1.27 matthew 4239: 0 );
1.225 raeburn 4240: my $one = $1;
4241: my $two = $2;
4242: my $url='/'.$one.'/';
1.88 raeburn 4243: # split multiple sections
4244: my %sections = ();
1.225 raeburn 4245: my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two},\%sections,$two);
1.88 raeburn 4246: if ($num_sections == 0) {
1.240 raeburn 4247: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,'',$context));
1.88 raeburn 4248: } else {
4249: my $emptysec = 0;
1.404 raeburn 4250: foreach my $sec (sort {$a cmp $b} keys(%sections)) {
1.88 raeburn 4251: if ($sec ne '') {
4252: my $securl = $url.'/'.$sec;
1.240 raeburn 4253: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$two,$start,$end,$one,undef,$sec,$context));
1.88 raeburn 4254: } else {
4255: $emptysec = 1;
4256: }
4257: }
4258: if ($emptysec) {
1.240 raeburn 4259: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,'',$context));
1.88 raeburn 4260: }
4261: }
1.225 raeburn 4262: if (!grep(/^\Q$two\E$/,@rolechanges)) {
4263: push(@rolechanges,$two);
4264: }
1.64 www 4265: } else {
1.190 raeburn 4266: $r->print('<p><span class="LC_error">'.&mt('ERROR').': '.&mt('Unknown command').' <tt>'.$key.'</tt></span></p><br />');
1.64 www 4267: }
1.113 raeburn 4268: foreach my $key (sort(keys(%disallowed))) {
1.274 bisitz 4269: $r->print('<p class="LC_warning">');
1.113 raeburn 4270: if (($key eq 'none') || ($key eq 'all')) {
1.274 bisitz 4271: $r->print(&mt('[_1] may not be used as the name for a section, as it is a reserved word.','<tt>'.$key.'</tt>'));
1.113 raeburn 4272: } else {
1.274 bisitz 4273: $r->print(&mt('[_1] may not be used as the name for a section, as it is the name of a course group.','<tt>'.$key.'</tt>'));
1.113 raeburn 4274: }
1.274 bisitz 4275: $r->print('</p><p>'
4276: .&mt('Please [_1]go back[_2] and choose a different section name.'
4277: ,'<a href="javascript:history.go(-1)'
4278: ,'</a>')
4279: .'</p><br />'
4280: );
1.113 raeburn 4281: }
4282: }
1.101 albertel 4283: } # End of foreach (keys(%env))
1.75 www 4284: # Flush the course logs so reverse user roles immediately updated
1.349 raeburn 4285: $r->register_cleanup(\&Apache::lonnet::flushcourselogs);
1.225 raeburn 4286: if (@rolechanges == 0) {
1.372 raeburn 4287: $r->print('<p>'.&mt('No roles to modify').'</p>');
1.193 raeburn 4288: }
1.225 raeburn 4289: return @rolechanges;
1.220 raeburn 4290: }
4291:
1.375 raeburn 4292: sub get_user_credits {
4293: my ($uname,$udom,$defaultcredits,$cdom,$cnum) = @_;
4294: if ($cdom eq '' || $cnum eq '') {
4295: return unless ($env{'request.course.id'});
4296: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
4297: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
4298: }
4299: my $credits;
4300: my %currhash =
4301: &Apache::lonnet::get('classlist',[$uname.':'.$udom],$cdom,$cnum);
4302: if (keys(%currhash) > 0) {
4303: my @items = split(/:/,$currhash{$uname.':'.$udom});
4304: my $crdidx = &Apache::loncoursedata::CL_CREDITS() - 3;
4305: $credits = $items[$crdidx];
4306: $credits =~ s/[^\d\.]//g;
4307: }
4308: if ($credits eq $defaultcredits) {
4309: undef($credits);
4310: }
4311: return $credits;
4312: }
4313:
1.220 raeburn 4314: sub enroll_single_student {
1.375 raeburn 4315: my ($r,$uhome,$amode,$genpwd,$now,$newuser,$context,$crstype,
4316: $showcredits,$defaultcredits) = @_;
1.318 raeburn 4317: $r->print('<h3>');
4318: if ($crstype eq 'Community') {
4319: $r->print(&mt('Enrolling Member'));
4320: } else {
4321: $r->print(&mt('Enrolling Student'));
4322: }
4323: $r->print('</h3>');
1.220 raeburn 4324:
4325: # Remove non alphanumeric values from section
4326: $env{'form.sections'}=~s/\W//g;
4327:
1.375 raeburn 4328: my $credits;
4329: if (($showcredits) && ($env{'form.credits'} ne '')) {
4330: $credits = $env{'form.credits'};
4331: $credits =~ s/[^\d\.]//g;
4332: if ($credits ne '') {
4333: if ($credits eq $defaultcredits) {
4334: undef($credits);
4335: }
4336: }
4337: }
4338:
1.220 raeburn 4339: # Clean out any old student roles the user has in this class.
4340: &Apache::lonuserutils::modifystudent($env{'form.ccdomain'},
4341: $env{'form.ccuname'},$env{'request.course.id'},undef,$uhome);
4342: my ($startdate,$enddate) = &Apache::lonuserutils::get_dates_from_form();
4343: my $enroll_result =
4344: &Apache::lonnet::modify_student_enrollment($env{'form.ccdomain'},
4345: $env{'form.ccuname'},$env{'form.cid'},$env{'form.cfirstname'},
4346: $env{'form.cmiddlename'},$env{'form.clastname'},
4347: $env{'form.generation'},$env{'form.sections'},$enddate,
1.375 raeburn 4348: $startdate,'manual',undef,$env{'request.course.id'},'',$context,
4349: $credits);
1.220 raeburn 4350: if ($enroll_result =~ /^ok/) {
1.381 bisitz 4351: $r->print(&mt('[_1] enrolled','<b>'.$env{'form.ccuname'}.':'.$env{'form.ccdomain'}.'</b>'));
1.220 raeburn 4352: if ($env{'form.sections'} ne '') {
4353: $r->print(' '.&mt('in section [_1]',$env{'form.sections'}));
4354: }
4355: my ($showstart,$showend);
4356: if ($startdate <= $now) {
4357: $showstart = &mt('Access starts immediately');
4358: } else {
4359: $showstart = &mt('Access starts: ').&Apache::lonlocal::locallocaltime($startdate);
4360: }
4361: if ($enddate == 0) {
4362: $showend = &mt('ends: no ending date');
4363: } else {
4364: $showend = &mt('ends: ').&Apache::lonlocal::locallocaltime($enddate);
4365: }
4366: $r->print('.<br />'.$showstart.'; '.$showend);
4367: if ($startdate <= $now && !$newuser) {
1.386 bisitz 4368: $r->print('<p class="LC_info">');
1.318 raeburn 4369: if ($crstype eq 'Community') {
1.392 raeburn 4370: $r->print(&mt('If the member is currently logged-in to LON-CAPA, the new role can be displayed by using the "Check for changes" link on the Roles/Courses page.'));
1.318 raeburn 4371: } else {
1.392 raeburn 4372: $r->print(&mt('If the student is currently logged-in to LON-CAPA, the new role can be displayed by using the "Check for changes" link on the Roles/Courses page.'));
1.318 raeburn 4373: }
4374: $r->print('</p>');
1.220 raeburn 4375: }
4376: } else {
4377: $r->print(&mt('unable to enroll').": ".$enroll_result);
4378: }
4379: return;
1.188 raeburn 4380: }
4381:
1.204 raeburn 4382: sub get_defaultquota_text {
4383: my ($settingstatus) = @_;
4384: my $defquotatext;
4385: if ($settingstatus eq '') {
1.383 raeburn 4386: $defquotatext = &mt('default');
1.204 raeburn 4387: } else {
4388: my ($usertypes,$order) =
4389: &Apache::lonnet::retrieve_inst_usertypes($env{'form.ccdomain'});
4390: if ($usertypes->{$settingstatus} eq '') {
1.383 raeburn 4391: $defquotatext = &mt('default');
1.204 raeburn 4392: } else {
1.383 raeburn 4393: $defquotatext = &mt('default for [_1]',$usertypes->{$settingstatus});
1.204 raeburn 4394: }
4395: }
4396: return $defquotatext;
4397: }
4398:
1.188 raeburn 4399: sub update_result_form {
4400: my ($uhome) = @_;
4401: my $outcome =
1.367 golterma 4402: '<form name="userupdate" method="post" action="">'."\n";
1.160 raeburn 4403: foreach my $item ('srchby','srchin','srchtype','srchterm','srchdomain','ccuname','ccdomain') {
1.188 raeburn 4404: $outcome .= '<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n";
1.160 raeburn 4405: }
1.207 raeburn 4406: if ($env{'form.origname'} ne '') {
4407: $outcome .= '<input type="hidden" name="origname" value="'.$env{'form.origname'}.'" />'."\n";
4408: }
1.160 raeburn 4409: foreach my $item ('sortby','seluname','seludom') {
4410: if (exists($env{'form.'.$item})) {
1.188 raeburn 4411: $outcome .= '<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n";
1.160 raeburn 4412: }
4413: }
1.188 raeburn 4414: if ($uhome eq 'no_host') {
4415: $outcome .= '<input type="hidden" name="forcenewuser" value="1" />'."\n";
4416: }
4417: $outcome .= '<input type="hidden" name="phase" value="" />'."\n".
1.383 raeburn 4418: '<input type="hidden" name="currstate" value="" />'."\n".
4419: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n".
1.188 raeburn 4420: '</form>';
4421: return $outcome;
1.4 www 4422: }
4423:
1.149 raeburn 4424: sub quota_admin {
1.378 raeburn 4425: my ($setquota,$changeHash,$name) = @_;
1.149 raeburn 4426: my $quotachanged;
4427: if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
4428: # Current user has quota modification privileges
1.267 raeburn 4429: if (ref($changeHash) eq 'HASH') {
4430: $quotachanged = 1;
1.378 raeburn 4431: $changeHash->{$name.'quota'} = $setquota;
1.267 raeburn 4432: }
1.149 raeburn 4433: }
4434: return $quotachanged;
4435: }
4436:
1.267 raeburn 4437: sub tool_admin {
1.275 raeburn 4438: my ($tool,$settool,$changeHash,$context) = @_;
4439: my $canchange = 0;
1.279 raeburn 4440: if ($context eq 'requestcourses') {
1.275 raeburn 4441: if (&Apache::lonnet::allowed('ccc',$env{'form.ccdomain'})) {
4442: $canchange = 1;
4443: }
1.300 raeburn 4444: } elsif ($context eq 'reqcrsotherdom') {
4445: if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
4446: $canchange = 1;
4447: }
1.362 raeburn 4448: } elsif ($context eq 'requestauthor') {
4449: if (&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) {
4450: $canchange = 1;
4451: }
1.275 raeburn 4452: } elsif (&Apache::lonnet::allowed('mut',$env{'form.ccdomain'})) {
4453: # Current user has quota modification privileges
4454: $canchange = 1;
4455: }
1.267 raeburn 4456: my $toolchanged;
1.275 raeburn 4457: if ($canchange) {
1.267 raeburn 4458: if (ref($changeHash) eq 'HASH') {
4459: $toolchanged = 1;
1.362 raeburn 4460: if ($tool eq 'requestauthor') {
4461: $changeHash->{$context} = $settool;
4462: } else {
4463: $changeHash->{$context.'.'.$tool} = $settool;
4464: }
1.267 raeburn 4465: }
4466: }
4467: return $toolchanged;
4468: }
4469:
1.88 raeburn 4470: sub build_roles {
1.89 raeburn 4471: my ($sectionstr,$sections,$role) = @_;
1.88 raeburn 4472: my $num_sections = 0;
4473: if ($sectionstr=~ /,/) {
4474: my @secnums = split/,/,$sectionstr;
1.89 raeburn 4475: if ($role eq 'st') {
4476: $secnums[0] =~ s/\W//g;
4477: $$sections{$secnums[0]} = 1;
4478: $num_sections = 1;
4479: } else {
4480: foreach my $sec (@secnums) {
4481: $sec =~ ~s/\W//g;
1.150 banghart 4482: if (!($sec eq "")) {
1.89 raeburn 4483: if (exists($$sections{$sec})) {
4484: $$sections{$sec} ++;
4485: } else {
4486: $$sections{$sec} = 1;
4487: $num_sections ++;
4488: }
1.88 raeburn 4489: }
4490: }
4491: }
4492: } else {
4493: $sectionstr=~s/\W//g;
4494: unless ($sectionstr eq '') {
4495: $$sections{$sectionstr} = 1;
4496: $num_sections ++;
4497: }
4498: }
1.129 albertel 4499:
1.88 raeburn 4500: return $num_sections;
4501: }
4502:
1.58 www 4503: # ========================================================== Custom Role Editor
4504:
4505: sub custom_role_editor {
1.439 raeburn 4506: my ($r,$context,$brcrum,$prefix,$permission) = @_;
1.324 raeburn 4507: my $action = $env{'form.customroleaction'};
1.439 raeburn 4508: my ($rolename,$helpitem);
1.324 raeburn 4509: if ($action eq 'new') {
4510: $rolename=$env{'form.newrolename'};
4511: } else {
4512: $rolename=$env{'form.rolename'};
1.59 www 4513: }
4514:
1.324 raeburn 4515: my ($crstype,$context);
4516: if ($env{'request.course.id'}) {
4517: $crstype = &Apache::loncommon::course_type();
4518: $context = 'course';
1.439 raeburn 4519: $helpitem = 'Course_Editing_Custom_Roles';
1.324 raeburn 4520: } else {
4521: $context = 'domain';
1.414 raeburn 4522: $crstype = 'course';
1.439 raeburn 4523: $helpitem = 'Domain_Editing_Custom_Roles';
1.324 raeburn 4524: }
1.351 raeburn 4525:
4526: $rolename=~s/[^A-Za-z0-9]//gs;
4527: if (!$rolename || $env{'form.phase'} eq 'pickrole') {
1.439 raeburn 4528: &print_username_entry_form($r,$context,undef,undef,undef,$crstype,$brcrum,
4529: $permission);
1.351 raeburn 4530: return;
4531: }
4532:
1.414 raeburn 4533: my $formname = 'form1';
4534: my %privs=();
4535: my $body_top = '<h2>';
4536: # ------------------------------------------------------- Does this role exist?
1.59 www 4537: my ($rdummy,$roledef)=
4538: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
4539: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1.414 raeburn 4540: $body_top .= &mt('Existing Role').' "';
1.61 www 4541: # ------------------------------------------------- Get current role privileges
1.414 raeburn 4542: ($privs{'system'},$privs{'domain'},$privs{'course'})=split(/\_/,$roledef);
4543: if ($privs{'system'} =~ /bre\&S/) {
4544: if ($context eq 'domain') {
1.417 raeburn 4545: $crstype = 'Course';
1.414 raeburn 4546: } elsif ($crstype eq 'Community') {
4547: $privs{'system'} =~ s/bre\&S//;
4548: }
4549: } elsif ($context eq 'domain') {
4550: $crstype = 'Course';
1.324 raeburn 4551: }
1.59 www 4552: } else {
1.414 raeburn 4553: $body_top .= &mt('New Role').' "';
4554: $roledef='';
1.59 www 4555: }
1.153 banghart 4556: $body_top .= $rolename.'"</h2>';
1.414 raeburn 4557:
4558: # ------------------------------------------------------- What can be assigned?
4559: my %full=();
1.417 raeburn 4560: my %levels=(
1.414 raeburn 4561: course => {},
4562: domain => {},
4563: system => {},
4564: );
4565: my %levelscurrent=(
4566: course => {},
4567: domain => {},
4568: system => {},
4569: );
4570: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
1.160 raeburn 4571: my ($jsback,$elements) = &crumb_utilities();
1.414 raeburn 4572: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
1.417 raeburn 4573: my $head_script =
1.414 raeburn 4574: &Apache::lonuserutils::custom_roledefs_js($context,$crstype,$formname,
4575: \%full,\@templateroles,$jsback);
1.351 raeburn 4576: push (@{$brcrum},
1.414 raeburn 4577: {href => "javascript:backPage(document.$formname,'pickrole','')",
1.351 raeburn 4578: text => "Pick custom role",
4579: faq => 282,bug=>'Instructor Interface',},
1.414 raeburn 4580: {href => "javascript:backPage(document.$formname,'','')",
1.351 raeburn 4581: text => "Edit custom role",
4582: faq => 282,
4583: bug => 'Instructor Interface',
1.439 raeburn 4584: help => $helpitem}
1.351 raeburn 4585: );
4586: my $args = { bread_crumbs => $brcrum,
4587: bread_crumbs_component => 'User Management'};
4588: $r->print(&Apache::loncommon::start_page('Custom Role Editor',
4589: $head_script,$args).
4590: $body_top);
1.414 raeburn 4591: $r->print('<form name="'.$formname.'" method="post" action="">'."\n".
4592: &Apache::lonuserutils::custom_role_header($context,$crstype,
4593: \@templateroles,$prefix));
1.264 bisitz 4594:
1.61 www 4595: $r->print(<<ENDCCF);
4596: <input type="hidden" name="phase" value="set_custom_roles" />
4597: <input type="hidden" name="rolename" value="$rolename" />
4598: ENDCCF
1.414 raeburn 4599: $r->print(&Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
4600: \%levelscurrent,$prefix));
1.135 raeburn 4601: $r->print(&Apache::loncommon::end_data_table().
1.190 raeburn 4602: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'.
1.160 raeburn 4603: '<input type="hidden" name="startrolename" value="'.$env{'form.rolename'}.
1.417 raeburn 4604: '" />'."\n".'<input type="hidden" name="currstate" value="" />'."\n".
1.160 raeburn 4605: '<input type="reset" value="'.&mt("Reset").'" />'."\n".
1.351 raeburn 4606: '<input type="submit" value="'.&mt('Save').'" /></form>');
1.61 www 4607: }
1.414 raeburn 4608:
1.61 www 4609: # ---------------------------------------------------------- Call to definerole
4610: sub set_custom_role {
1.439 raeburn 4611: my ($r,$context,$brcrum,$prefix,$permission) = @_;
1.101 albertel 4612: my $rolename=$env{'form.rolename'};
1.63 www 4613: $rolename=~s/[^A-Za-z0-9]//gs;
1.150 banghart 4614: if (!$rolename) {
1.439 raeburn 4615: &custom_role_editor($r,$context,$brcrum,$prefix,$permission);
1.61 www 4616: return;
4617: }
1.160 raeburn 4618: my ($jsback,$elements) = &crumb_utilities();
1.301 bisitz 4619: my $jscript = '<script type="text/javascript">'
4620: .'// <![CDATA['."\n"
4621: .$jsback."\n"
4622: .'// ]]>'."\n"
4623: .'</script>'."\n";
1.439 raeburn 4624: my $helpitem = 'Course_Editing_Custom_Roles';
4625: if ($context eq 'domain') {
4626: $helpitem = 'Domain_Editing_Custom_Roles';
4627: }
1.352 raeburn 4628: push(@{$brcrum},
4629: {href => "javascript:backPage(document.customresult,'pickrole','')",
4630: text => "Pick custom role",
4631: faq => 282,
4632: bug => 'Instructor Interface',},
4633: {href => "javascript:backPage(document.customresult,'selected_custom_edit','')",
4634: text => "Edit custom role",
4635: faq => 282,
4636: bug => 'Instructor Interface',},
4637: {href => "javascript:backPage(document.customresult,'set_custom_roles','')",
4638: text => "Result",
4639: faq => 282,
4640: bug => 'Instructor Interface',
1.439 raeburn 4641: help => $helpitem,}
1.352 raeburn 4642: );
4643: my $args = { bread_crumbs => $brcrum,
1.414 raeburn 4644: bread_crumbs_component => 'User Management'};
1.351 raeburn 4645: $r->print(&Apache::loncommon::start_page('Save Custom Role',$jscript,$args));
1.160 raeburn 4646:
1.393 raeburn 4647: my $newrole;
1.61 www 4648: my ($rdummy,$roledef)=
1.110 albertel 4649: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
4650:
1.61 www 4651: # ------------------------------------------------------- Does this role exist?
1.188 raeburn 4652: $r->print('<h3>');
1.61 www 4653: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1.73 sakharuk 4654: $r->print(&mt('Existing Role').' "');
1.61 www 4655: } else {
1.73 sakharuk 4656: $r->print(&mt('New Role').' "');
1.61 www 4657: $roledef='';
1.393 raeburn 4658: $newrole = 1;
1.61 www 4659: }
1.188 raeburn 4660: $r->print($rolename.'"</h3>');
1.414 raeburn 4661: # ------------------------------------------------- Assign role and show result
1.61 www 4662:
1.387 bisitz 4663: my $errmsg;
1.414 raeburn 4664: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$prefix);
4665: # Assign role and return result
4666: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
4667: $newprivs{'c'});
1.387 bisitz 4668: if ($result ne 'ok') {
4669: $errmsg = ': '.$result;
4670: }
4671: my $message =
4672: &Apache::lonhtmlcommon::confirm_success(
4673: &mt('Defining Role').$errmsg, ($result eq 'ok' ? 0 : 1));
1.101 albertel 4674: if ($env{'request.course.id'}) {
4675: my $url='/'.$env{'request.course.id'};
1.63 www 4676: $url=~s/\_/\//g;
1.387 bisitz 4677: $result =
4678: &Apache::lonnet::assigncustomrole(
4679: $env{'user.domain'},$env{'user.name'},
4680: $url,
4681: $env{'user.domain'},$env{'user.name'},
4682: $rolename,undef,undef,undef,$context);
4683: if ($result ne 'ok') {
4684: $errmsg = ': '.$result;
4685: }
4686: $message .=
4687: '<br />'
4688: .&Apache::lonhtmlcommon::confirm_success(
4689: &mt('Assigning Role to Self').$errmsg, ($result eq 'ok' ? 0 : 1));
1.63 www 4690: }
1.380 bisitz 4691: $r->print(
1.387 bisitz 4692: &Apache::loncommon::confirmwrapper($message)
4693: .'<br />'
4694: .&Apache::lonhtmlcommon::actionbox([
4695: '<a href="javascript:backPage(document.customresult,'."'pickrole'".')">'
4696: .&mt('Create or edit another custom role')
4697: .'</a>'])
1.380 bisitz 4698: .'<form name="customresult" method="post" action="">'
1.387 bisitz 4699: .&Apache::lonhtmlcommon::echo_form_input([])
4700: .'</form>'
1.380 bisitz 4701: );
1.58 www 4702: }
4703:
1.2 www 4704: # ================================================================ Main Handler
4705: sub handler {
4706: my $r = shift;
4707: if ($r->header_only) {
1.68 www 4708: &Apache::loncommon::content_type($r,'text/html');
1.2 www 4709: $r->send_http_header;
4710: return OK;
4711: }
1.439 raeburn 4712: my ($context,$crstype,$cid,$cnum,$cdom,$allhelpitems);
4713:
1.190 raeburn 4714: if ($env{'request.course.id'}) {
4715: $context = 'course';
1.318 raeburn 4716: $crstype = &Apache::loncommon::course_type();
1.190 raeburn 4717: } elsif ($env{'request.role'} =~ /^au\./) {
1.206 raeburn 4718: $context = 'author';
1.190 raeburn 4719: } else {
4720: $context = 'domain';
4721: }
1.375 raeburn 4722:
1.439 raeburn 4723: my ($permission,$allowed) =
4724: &Apache::lonuserutils::get_permission($context,$crstype);
4725:
4726: if ($allowed) {
4727: my @allhelp;
4728: if ($context eq 'course') {
4729: $cid = $env{'request.course.id'};
4730: $cdom = $env{'course.'.$cid.'.domain'};
4731: $cnum = $env{'course.'.$cid.'.num'};
4732:
4733: if ($permission->{'cusr'}) {
4734: push(@allhelp,'Course_Create_Class_List');
4735: }
4736: if ($permission->{'view'} || $permission->{'cusr'}) {
4737: push(@allhelp,('Course_Change_Privileges','Course_View_Class_List'));
4738: }
4739: if ($permission->{'custom'}) {
4740: push(@allhelp,'Course_Editing_Custom_Roles');
4741: }
4742: if ($permission->{'cusr'}) {
4743: push(@allhelp,('Course_Add_Student','Course_Drop_Student'));
4744: }
4745: unless ($permission->{'cusr_section'}) {
4746: if (&Apache::lonnet::auto_run($cnum,$cdom) && (($permission->{'cusr'}) || ($permission->{'view'}))) {
4747: push(@allhelp,'Course_Automated_Enrollment');
4748: }
4749: if ($permission->{'selfenrolladmin'}) {
4750: push(@allhelp,'Course_Approve_Selfenroll');
4751: }
4752: }
4753: if ($permission->{'grp_manage'}) {
4754: push(@allhelp,'Course_Manage_Group');
4755: }
4756: if ($permission->{'view'} || $permission->{'cusr'}) {
4757: push(@allhelp,'Course_User_Logs');
4758: }
4759: } elsif ($context eq 'author') {
4760: push(@allhelp,('Author_Change_Privileges','Author_Create_Coauthor_List',
4761: 'Author_View_Coauthor_List','Author_User_Logs'));
4762: } else {
4763: if ($permission->{'cusr'}) {
4764: push(@allhelp,'Domain_Change_Privileges');
4765: if ($permission->{'activity'}) {
4766: push(@allhelp,'Domain_User_Access_Logs');
4767: }
4768: push(@allhelp,('Domain_Create_Users','Domain_View_Users_List'));
4769: if ($permission->{'custom'}) {
4770: push(@allhelp,'Domain_Editing_Custom_Roles');
4771: }
4772: push(@allhelp,('Domain_Role_Approvals','Domain_Username_Approvals','Domain_Change_Logs'));
4773: } elsif ($permission->{'view'}) {
4774: push(@allhelp,'Domain_View_Privileges');
4775: if ($permission->{'activity'}) {
4776: push(@allhelp,'Domain_User_Access_Logs');
4777: }
4778: push(@allhelp,('Domain_View_Users_List','Domain_Change_Logs'));
4779: }
4780: }
4781: if (@allhelp) {
4782: $allhelpitems = join(',',@allhelp);
4783: }
4784: }
4785:
1.190 raeburn 4786: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.233 raeburn 4787: ['action','state','callingform','roletype','showrole','bulkaction','popup','phase',
1.391 raeburn 4788: 'username','domain','srchterm','srchdomain','srchin','srchby','srchtype','queue']);
1.190 raeburn 4789: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.351 raeburn 4790: my $args;
4791: my $brcrum = [];
4792: my $bread_crumbs_component = 'User Management';
1.391 raeburn 4793: if (($env{'form.action'} ne 'dateselect') && ($env{'form.action'} ne 'displayuserreq')) {
1.351 raeburn 4794: $brcrum = [{href=>"/adm/createuser",
4795: text=>"User Management",
1.439 raeburn 4796: help=>$allhelpitems}
1.351 raeburn 4797: ];
1.202 raeburn 4798: }
1.190 raeburn 4799: if (!$allowed) {
1.358 raeburn 4800: if ($context eq 'course') {
4801: $r->internal_redirect('/adm/viewclasslist');
4802: return OK;
4803: }
1.190 raeburn 4804: $env{'user.error.msg'}=
4805: "/adm/createuser:cst:0:0:Cannot create/modify user data ".
4806: "or view user status.";
4807: return HTTP_NOT_ACCEPTABLE;
4808: }
4809:
4810: &Apache::loncommon::content_type($r,'text/html');
4811: $r->send_http_header;
4812:
1.375 raeburn 4813: my $showcredits;
4814: if ((($context eq 'course') && ($crstype eq 'Course')) ||
4815: ($context eq 'domain')) {
4816: my %domdefaults =
4817: &Apache::lonnet::get_domain_defaults($env{'request.role.domain'});
4818: if ($domdefaults{'officialcredits'} || $domdefaults{'unofficialcredits'}) {
4819: $showcredits = 1;
4820: }
4821: }
4822:
1.190 raeburn 4823: # Main switch on form.action and form.state, as appropriate
4824: if (! exists($env{'form.action'})) {
1.351 raeburn 4825: $args = {bread_crumbs => $brcrum,
4826: bread_crumbs_component => $bread_crumbs_component};
4827: $r->print(&header(undef,$args));
1.318 raeburn 4828: $r->print(&print_main_menu($permission,$context,$crstype));
1.190 raeburn 4829: } elsif ($env{'form.action'} eq 'upload' && $permission->{'cusr'}) {
1.439 raeburn 4830: my $helpitem = 'Course_Create_Class_List';
4831: if ($context eq 'author') {
4832: $helpitem = 'Author_Create_Coauthor_List';
4833: } elsif ($context eq 'domain') {
4834: $helpitem = 'Domain_Create_Users';
4835: }
1.351 raeburn 4836: push(@{$brcrum},
4837: { href => '/adm/createuser?action=upload&state=',
4838: text => 'Upload Users List',
1.439 raeburn 4839: help => $helpitem,
1.351 raeburn 4840: });
4841: $bread_crumbs_component = 'Upload Users List';
4842: $args = {bread_crumbs => $brcrum,
4843: bread_crumbs_component => $bread_crumbs_component};
4844: $r->print(&header(undef,$args));
1.190 raeburn 4845: $r->print('<form name="studentform" method="post" '.
4846: 'enctype="multipart/form-data" '.
4847: ' action="/adm/createuser">'."\n");
4848: if (! exists($env{'form.state'})) {
4849: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
4850: } elsif ($env{'form.state'} eq 'got_file') {
1.448 raeburn 4851: my $result =
4852: &Apache::lonuserutils::print_upload_manager_form($r,$context,
4853: $permission,
4854: $crstype,$showcredits);
4855: if ($result eq 'missingdata') {
4856: delete($env{'form.state'});
4857: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
4858: }
1.190 raeburn 4859: } elsif ($env{'form.state'} eq 'enrolling') {
4860: if ($env{'form.datatoken'}) {
1.448 raeburn 4861: my $result = &Apache::lonuserutils::upfile_drop_add($r,$context,
4862: $permission,
4863: $showcredits);
4864: if ($result eq 'missingdata') {
4865: delete($env{'form.state'});
4866: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
4867: } elsif ($result eq 'invalidhome') {
4868: $env{'form.state'} = 'got_file';
4869: delete($env{'form.lcserver'});
4870: my $result =
4871: &Apache::lonuserutils::print_upload_manager_form($r,$context,$permission,
4872: $crstype,$showcredits);
4873: if ($result eq 'missingdata') {
4874: delete($env{'form.state'});
4875: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
4876: }
4877: }
4878: } else {
4879: delete($env{'form.state'});
4880: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
1.190 raeburn 4881: }
4882: } else {
4883: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
4884: }
1.447 raeburn 4885: $r->print('</form>');
1.416 raeburn 4886: } elsif (((($env{'form.action'} eq 'singleuser') || ($env{'form.action'}
4887: eq 'singlestudent')) && ($permission->{'cusr'})) ||
1.418 raeburn 4888: (($env{'form.action'} eq 'singleuser') && ($permission->{'view'})) ||
1.416 raeburn 4889: (($env{'form.action'} eq 'accesslogs') && ($permission->{'activity'}))) {
1.190 raeburn 4890: my $phase = $env{'form.phase'};
4891: my @search = ('srchterm','srchby','srchin','srchtype','srchdomain');
1.192 albertel 4892: &Apache::loncreateuser::restore_prev_selections();
4893: my $srch;
4894: foreach my $item (@search) {
4895: $srch->{$item} = $env{'form.'.$item};
4896: }
1.207 raeburn 4897: if (($phase eq 'get_user_info') || ($phase eq 'userpicked') ||
1.416 raeburn 4898: ($phase eq 'createnewuser') || ($phase eq 'activity')) {
1.207 raeburn 4899: if ($env{'form.phase'} eq 'createnewuser') {
4900: my $response;
4901: if ($env{'form.srchterm'} !~ /^$match_username$/) {
1.366 bisitz 4902: my $response =
4903: '<span class="LC_warning">'
4904: .&mt('You must specify a valid username. Only the following are allowed:'
4905: .' letters numbers - . @')
4906: .'</span>';
1.221 raeburn 4907: $env{'form.phase'} = '';
1.375 raeburn 4908: &print_username_entry_form($r,$context,$response,$srch,undef,
1.439 raeburn 4909: $crstype,$brcrum,$permission);
1.207 raeburn 4910: } else {
4911: my $ccuname =&LONCAPA::clean_username($srch->{'srchterm'});
4912: my $ccdomain=&LONCAPA::clean_domain($srch->{'srchdomain'});
4913: &print_user_modification_page($r,$ccuname,$ccdomain,
1.221 raeburn 4914: $srch,$response,$context,
1.375 raeburn 4915: $permission,$crstype,$brcrum,
4916: $showcredits);
1.207 raeburn 4917: }
4918: } elsif ($env{'form.phase'} eq 'get_user_info') {
1.190 raeburn 4919: my ($currstate,$response,$forcenewuser,$results) =
1.221 raeburn 4920: &user_search_result($context,$srch);
1.190 raeburn 4921: if ($env{'form.currstate'} eq 'modify') {
4922: $currstate = $env{'form.currstate'};
4923: }
4924: if ($currstate eq 'select') {
4925: &print_user_selection_page($r,$response,$srch,$results,
1.351 raeburn 4926: \@search,$context,undef,$crstype,
4927: $brcrum);
1.416 raeburn 4928: } elsif (($currstate eq 'modify') || ($env{'form.action'} eq 'accesslogs')) {
4929: my ($ccuname,$ccdomain,$uhome);
1.190 raeburn 4930: if (($srch->{'srchby'} eq 'uname') &&
4931: ($srch->{'srchtype'} eq 'exact')) {
4932: $ccuname = $srch->{'srchterm'};
4933: $ccdomain= $srch->{'srchdomain'};
4934: } else {
4935: my @matchedunames = keys(%{$results});
4936: ($ccuname,$ccdomain) = split(/:/,$matchedunames[0]);
4937: }
4938: $ccuname =&LONCAPA::clean_username($ccuname);
4939: $ccdomain=&LONCAPA::clean_domain($ccdomain);
1.416 raeburn 4940: if ($env{'form.action'} eq 'accesslogs') {
4941: my $uhome;
4942: if (($ccuname ne '') && ($ccdomain ne '')) {
4943: $uhome = &Apache::lonnet::homeserver($ccuname,$ccdomain);
4944: }
4945: if (($uhome eq '') || ($uhome eq 'no_host')) {
4946: $env{'form.phase'} = '';
4947: undef($forcenewuser);
4948: #if ($response) {
4949: # unless ($response =~ m{\Q<br /><br />\E$}) {
4950: # $response .= '<br /><br />';
4951: # }
4952: #}
4953: &print_username_entry_form($r,$context,$response,$srch,
1.439 raeburn 4954: $forcenewuser,$crstype,$brcrum,
4955: $permission);
1.416 raeburn 4956: } else {
4957: &print_useraccesslogs_display($r,$ccuname,$ccdomain,$permission,$brcrum);
4958: }
4959: } else {
4960: if ($env{'form.forcenewuser'}) {
4961: $response = '';
4962: }
4963: &print_user_modification_page($r,$ccuname,$ccdomain,
4964: $srch,$response,$context,
4965: $permission,$crstype,$brcrum);
1.190 raeburn 4966: }
4967: } elsif ($currstate eq 'query') {
1.351 raeburn 4968: &print_user_query_page($r,'createuser',$brcrum);
1.190 raeburn 4969: } else {
1.229 raeburn 4970: $env{'form.phase'} = '';
1.207 raeburn 4971: &print_username_entry_form($r,$context,$response,$srch,
1.439 raeburn 4972: $forcenewuser,$crstype,$brcrum,
4973: $permission);
1.190 raeburn 4974: }
4975: } elsif ($env{'form.phase'} eq 'userpicked') {
4976: my $ccuname = &LONCAPA::clean_username($env{'form.seluname'});
4977: my $ccdomain = &LONCAPA::clean_domain($env{'form.seludom'});
1.416 raeburn 4978: if ($env{'form.action'} eq 'accesslogs') {
4979: &print_useraccesslogs_display($r,$ccuname,$ccdomain,$permission,$brcrum);
4980: } else {
4981: &print_user_modification_page($r,$ccuname,$ccdomain,$srch,'',
4982: $context,$permission,$crstype,
4983: $brcrum);
4984: }
4985: } elsif ($env{'form.action'} eq 'accesslogs') {
4986: my $ccuname = &LONCAPA::clean_username($env{'form.accessuname'});
4987: my $ccdomain = &LONCAPA::clean_domain($env{'form.accessudom'});
4988: &print_useraccesslogs_display($r,$ccuname,$ccdomain,$permission,$brcrum);
1.190 raeburn 4989: }
4990: } elsif ($env{'form.phase'} eq 'update_user_data') {
1.451 raeburn 4991: &update_user_data($r,$context,$crstype,$brcrum,$showcredits,$permission);
1.190 raeburn 4992: } else {
1.351 raeburn 4993: &print_username_entry_form($r,$context,undef,$srch,undef,$crstype,
1.439 raeburn 4994: $brcrum,$permission);
1.190 raeburn 4995: }
4996: } elsif ($env{'form.action'} eq 'custom' && $permission->{'custom'}) {
1.414 raeburn 4997: my $prefix;
1.190 raeburn 4998: if ($env{'form.phase'} eq 'set_custom_roles') {
1.439 raeburn 4999: &set_custom_role($r,$context,$brcrum,$prefix,$permission);
1.190 raeburn 5000: } else {
1.439 raeburn 5001: &custom_role_editor($r,$context,$brcrum,$prefix,$permission);
1.190 raeburn 5002: }
1.362 raeburn 5003: } elsif (($env{'form.action'} eq 'processauthorreq') &&
5004: ($permission->{'cusr'}) &&
5005: (&Apache::lonnet::allowed('cau',$env{'request.role.domain'}))) {
5006: push(@{$brcrum},
5007: {href => '/adm/createuser?action=processauthorreq',
1.385 bisitz 5008: text => 'Authoring Space requests',
1.362 raeburn 5009: help => 'Domain_Role_Approvals'});
5010: $bread_crumbs_component = 'Authoring requests';
5011: if ($env{'form.state'} eq 'done') {
5012: push(@{$brcrum},
5013: {href => '/adm/createuser?action=authorreqqueue',
5014: text => 'Result',
5015: help => 'Domain_Role_Approvals'});
5016: $bread_crumbs_component = 'Authoring request result';
5017: }
5018: $args = { bread_crumbs => $brcrum,
5019: bread_crumbs_component => $bread_crumbs_component};
1.391 raeburn 5020: my $js = &usernamerequest_javascript();
5021: $r->print(&header(&add_script($js),$args));
1.362 raeburn 5022: if (!exists($env{'form.state'})) {
5023: $r->print(&Apache::loncoursequeueadmin::display_queued_requests('requestauthor',
5024: $env{'request.role.domain'}));
5025: } elsif ($env{'form.state'} eq 'done') {
5026: $r->print('<h3>'.&mt('Authoring request processing').'</h3>'."\n");
5027: $r->print(&Apache::loncoursequeueadmin::update_request_queue('requestauthor',
5028: $env{'request.role.domain'}));
5029: }
1.391 raeburn 5030: } elsif (($env{'form.action'} eq 'processusernamereq') &&
5031: ($permission->{'cusr'}) &&
5032: (&Apache::lonnet::allowed('cau',$env{'request.role.domain'}))) {
5033: push(@{$brcrum},
5034: {href => '/adm/createuser?action=processusernamereq',
5035: text => 'LON-CAPA account requests',
5036: help => 'Domain_Username_Approvals'});
5037: $bread_crumbs_component = 'Account requests';
5038: if ($env{'form.state'} eq 'done') {
5039: push(@{$brcrum},
5040: {href => '/adm/createuser?action=usernamereqqueue',
5041: text => 'Result',
5042: help => 'Domain_Username_Approvals'});
5043: $bread_crumbs_component = 'LON-CAPA account request result';
5044: }
5045: $args = { bread_crumbs => $brcrum,
5046: bread_crumbs_component => $bread_crumbs_component};
5047: my $js = &usernamerequest_javascript();
5048: $r->print(&header(&add_script($js),$args));
5049: if (!exists($env{'form.state'})) {
5050: $r->print(&Apache::loncoursequeueadmin::display_queued_requests('requestusername',
5051: $env{'request.role.domain'}));
5052: } elsif ($env{'form.state'} eq 'done') {
5053: $r->print('<h3>'.&mt('LON-CAPA account request processing').'</h3>'."\n");
5054: $r->print(&Apache::loncoursequeueadmin::update_request_queue('requestusername',
5055: $env{'request.role.domain'}));
5056: }
5057: } elsif (($env{'form.action'} eq 'displayuserreq') &&
5058: ($permission->{'cusr'})) {
5059: my $dom = $env{'form.domain'};
5060: my $uname = $env{'form.username'};
5061: my $warning;
5062: if (($dom =~ /^$match_domain$/) && (&Apache::lonnet::domain($dom) ne '')) {
5063: if (($dom eq $env{'request.role.domain'}) && (&Apache::lonnet::allowed('ccc',$dom))) {
5064: if (($uname =~ /^$match_username$/) && ($env{'form.queue'} eq 'approval')) {
5065: my $uhome = &Apache::lonnet::homeserver($uname,$dom);
5066: if ($uhome eq 'no_host') {
5067: my $queue = $env{'form.queue'};
5068: my $reqkey = &escape($uname).'_'.$queue;
5069: my $namespace = 'usernamequeue';
5070: my $domconfig = &Apache::lonnet::get_domainconfiguser($dom);
5071: my %queued =
5072: &Apache::lonnet::get($namespace,[$reqkey],$dom,$domconfig);
5073: unless ($queued{$reqkey}) {
5074: $warning = &mt('No information was found for this LON-CAPA account request.');
5075: }
5076: } else {
5077: $warning = &mt('A LON-CAPA account already exists for the requested username and domain.');
5078: }
5079: } else {
5080: $warning = &mt('LON-CAPA account request status check is for an invalid username.');
5081: }
5082: } else {
5083: $warning = &mt('You do not have rights to view LON-CAPA account requests in the domain specified.');
5084: }
5085: } else {
5086: $warning = &mt('LON-CAPA account request status check is for an invalid domain.');
5087: }
5088: my $args = { only_body => 1 };
5089: $r->print(&header(undef,$args).
5090: '<h3>'.&mt('LON-CAPA Account Request Details').'</h3>');
5091: if ($warning ne '') {
5092: $r->print('<div class="LC_warning">'.$warning.'</div>');
5093: } else {
5094: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
5095: my $domconfiguser = &Apache::lonnet::get_domainconfiguser($dom);
5096: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
5097: if (ref($domconfig{'usercreation'}) eq 'HASH') {
5098: if (ref($domconfig{'usercreation'}{'cancreate'}) eq 'HASH') {
5099: if (ref($domconfig{'usercreation'}{'cancreate'}{'emailusername'}) eq 'HASH') {
5100: my %info =
5101: &Apache::lonnet::get('nohist_requestedusernames',[$uname],$dom,$domconfiguser);
5102: if (ref($info{$uname}) eq 'HASH') {
1.396 raeburn 5103: my $usertype = $info{$uname}{'inststatus'};
5104: unless ($usertype) {
5105: $usertype = 'default';
5106: }
1.442 raeburn 5107: my ($showstatus,$showemail,$pickstart);
5108: my $numextras = 0;
5109: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.443 raeburn 5110: if ((ref($types) eq 'ARRAY') && (@{$types} > 0)) {
5111: if (ref($usertypes) eq 'HASH') {
5112: if ($usertypes->{$usertype}) {
5113: $showstatus = $usertypes->{$usertype};
5114: } else {
5115: $showstatus = $othertitle;
5116: }
5117: if ($showstatus) {
5118: $numextras ++;
5119: }
1.442 raeburn 5120: }
5121: }
5122: if (($info{$uname}{'email'} ne '') && ($info{$uname}{'email'} ne $uname)) {
5123: $showemail = $info{$uname}{'email'};
5124: $numextras ++;
5125: }
1.396 raeburn 5126: if (ref($domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}) eq 'HASH') {
5127: if ((ref($infofields) eq 'ARRAY') && (ref($infotitles) eq 'HASH')) {
1.442 raeburn 5128: $pickstart = 1;
1.396 raeburn 5129: $r->print('<div>'.&Apache::lonhtmlcommon::start_pick_box());
1.442 raeburn 5130: my ($num,$count);
1.396 raeburn 5131: $count = scalar(keys(%{$domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}}));
1.442 raeburn 5132: $count += $numextras;
1.396 raeburn 5133: foreach my $field (@{$infofields}) {
5134: next unless ($domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}{$field});
5135: next unless ($infotitles->{$field});
5136: $r->print(&Apache::lonhtmlcommon::row_title($infotitles->{$field}).
5137: $info{$uname}{$field});
5138: $num ++;
1.442 raeburn 5139: unless ($count == $num) {
1.396 raeburn 5140: $r->print(&Apache::lonhtmlcommon::row_closure());
5141: }
5142: }
1.442 raeburn 5143: }
5144: }
5145: if ($numextras) {
5146: unless ($pickstart) {
5147: $r->print('<div>'.&Apache::lonhtmlcommon::start_pick_box());
5148: $pickstart = 1;
5149: }
5150: if ($showemail) {
5151: my $closure = '';
5152: unless ($showstatus) {
5153: $closure = 1;
1.391 raeburn 5154: }
1.442 raeburn 5155: $r->print(&Apache::lonhtmlcommon::row_title(&mt('E-mail address')).
5156: $showemail.
5157: &Apache::lonhtmlcommon::row_closure($closure));
1.391 raeburn 5158: }
1.442 raeburn 5159: if ($showstatus) {
5160: $r->print(&Apache::lonhtmlcommon::row_title(&mt('Status type[_1](self-reported)','<br />')).
5161: $showstatus.
5162: &Apache::lonhtmlcommon::row_closure(1));
5163: }
5164: }
5165: if ($pickstart) {
5166: $r->print(&Apache::lonhtmlcommon::end_pick_box().'</div>');
5167: } else {
5168: $r->print('<div>'.&mt('No information to display for this account request.').'</div>');
1.391 raeburn 5169: }
1.442 raeburn 5170: } else {
5171: $r->print('<div>'.&mt('No information available for this account request.').'</div>');
1.391 raeburn 5172: }
5173: }
5174: }
5175: }
5176: }
1.442 raeburn 5177: $r->print(&close_popup_form());
1.207 raeburn 5178: } elsif (($env{'form.action'} eq 'listusers') &&
5179: ($permission->{'view'} || $permission->{'cusr'})) {
1.439 raeburn 5180: my $helpitem = 'Course_View_Class_List';
5181: if ($context eq 'author') {
5182: $helpitem = 'Author_View_Coauthor_List';
5183: } elsif ($context eq 'domain') {
5184: $helpitem = 'Domain_View_Users_List';
5185: }
1.202 raeburn 5186: if ($env{'form.phase'} eq 'bulkchange') {
1.351 raeburn 5187: push(@{$brcrum},
5188: {href => '/adm/createuser?action=listusers',
5189: text => "List Users"},
5190: {href => "/adm/createuser",
5191: text => "Result",
1.439 raeburn 5192: help => $helpitem});
1.351 raeburn 5193: $bread_crumbs_component = 'Update Users';
5194: $args = {bread_crumbs => $brcrum,
5195: bread_crumbs_component => $bread_crumbs_component};
5196: $r->print(&header(undef,$args));
1.202 raeburn 5197: my $setting = $env{'form.roletype'};
5198: my $choice = $env{'form.bulkaction'};
5199: if ($permission->{'cusr'}) {
1.336 raeburn 5200: &Apache::lonuserutils::update_user_list($r,$context,$setting,$choice,$crstype);
1.221 raeburn 5201: } else {
5202: $r->print(&mt('You are not authorized to make bulk changes to user roles'));
1.223 raeburn 5203: $r->print('<p><a href="/adm/createuser?action=listusers">'.&mt('Display User Lists').'</a>');
1.202 raeburn 5204: }
5205: } else {
1.351 raeburn 5206: push(@{$brcrum},
5207: {href => '/adm/createuser?action=listusers',
5208: text => "List Users",
1.439 raeburn 5209: help => $helpitem});
1.351 raeburn 5210: $bread_crumbs_component = 'List Users';
5211: $args = {bread_crumbs => $brcrum,
5212: bread_crumbs_component => $bread_crumbs_component};
1.202 raeburn 5213: my ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles);
5214: my $formname = 'studentform';
1.364 raeburn 5215: my $hidecall = "hide_searching();";
1.321 raeburn 5216: if (($context eq 'domain') && (($env{'form.roletype'} eq 'course') ||
5217: ($env{'form.roletype'} eq 'community'))) {
5218: if ($env{'form.roletype'} eq 'course') {
5219: ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles) =
5220: &Apache::lonuserutils::courses_selector($env{'request.role.domain'},
5221: $formname);
5222: } elsif ($env{'form.roletype'} eq 'community') {
5223: $cb_jscript =
5224: &Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
5225: my %elements = (
5226: coursepick => 'radio',
5227: coursetotal => 'text',
5228: courselist => 'text',
5229: );
5230: $jscript = &Apache::lonhtmlcommon::set_form_elements(\%elements);
5231: }
1.364 raeburn 5232: $jscript .= &verify_user_display($context)."\n".
5233: &Apache::loncommon::check_uncheck_jscript();
1.202 raeburn 5234: my $js = &add_script($jscript).$cb_jscript;
5235: my $loadcode =
5236: &Apache::lonuserutils::course_selector_loadcode($formname);
5237: if ($loadcode ne '') {
1.364 raeburn 5238: $args->{add_entries} = {onload => "$loadcode;$hidecall"};
5239: } else {
5240: $args->{add_entries} = {onload => $hidecall};
1.202 raeburn 5241: }
1.351 raeburn 5242: $r->print(&header($js,$args));
1.191 raeburn 5243: } else {
1.364 raeburn 5244: $args->{add_entries} = {onload => $hidecall};
5245: $jscript = &verify_user_display($context).
5246: &Apache::loncommon::check_uncheck_jscript();
5247: $r->print(&header(&add_script($jscript),$args));
1.191 raeburn 5248: }
1.202 raeburn 5249: &Apache::lonuserutils::print_userlist($r,undef,$permission,$context,
1.375 raeburn 5250: $formname,$totcodes,$codetitles,$idlist,$idlist_titles,
5251: $showcredits);
1.191 raeburn 5252: }
1.213 raeburn 5253: } elsif ($env{'form.action'} eq 'drop' && $permission->{'cusr'}) {
1.318 raeburn 5254: my $brtext;
5255: if ($crstype eq 'Community') {
5256: $brtext = 'Drop Members';
5257: } else {
5258: $brtext = 'Drop Students';
5259: }
1.351 raeburn 5260: push(@{$brcrum},
5261: {href => '/adm/createuser?action=drop',
5262: text => $brtext,
5263: help => 'Course_Drop_Student'});
5264: if ($env{'form.state'} eq 'done') {
5265: push(@{$brcrum},
5266: {href=>'/adm/createuser?action=drop',
5267: text=>"Result"});
5268: }
5269: $bread_crumbs_component = $brtext;
5270: $args = {bread_crumbs => $brcrum,
5271: bread_crumbs_component => $bread_crumbs_component};
5272: $r->print(&header(undef,$args));
1.213 raeburn 5273: if (!exists($env{'form.state'})) {
1.318 raeburn 5274: &Apache::lonuserutils::print_drop_menu($r,$context,$permission,$crstype);
1.213 raeburn 5275: } elsif ($env{'form.state'} eq 'done') {
5276: &Apache::lonuserutils::update_user_list($r,$context,undef,
5277: $env{'form.action'});
5278: }
1.202 raeburn 5279: } elsif ($env{'form.action'} eq 'dateselect') {
5280: if ($permission->{'cusr'}) {
1.351 raeburn 5281: $r->print(&header(undef,{'no_nav_bar' => 1}).
1.375 raeburn 5282: &Apache::lonuserutils::date_section_selector($context,$permission,
5283: $crstype,$showcredits));
1.202 raeburn 5284: } else {
1.351 raeburn 5285: $r->print(&header(undef,{'no_nav_bar' => 1}).
5286: '<span class="LC_error">'.&mt('You do not have permission to modify dates or sections for users').'</span>');
1.202 raeburn 5287: }
1.237 raeburn 5288: } elsif ($env{'form.action'} eq 'selfenroll') {
1.398 raeburn 5289: if ($permission->{selfenrolladmin}) {
5290: my %currsettings = (
5291: selfenroll_types => $env{'course.'.$cid.'.internal.selfenroll_types'},
5292: selfenroll_registered => $env{'course.'.$cid.'.internal.selfenroll_registered'},
5293: selfenroll_section => $env{'course.'.$cid.'.internal.selfenroll_section'},
5294: selfenroll_notifylist => $env{'course.'.$cid.'.internal.selfenroll_notifylist'},
5295: selfenroll_approval => $env{'course.'.$cid.'.internal.selfenroll_approval'},
5296: selfenroll_limit => $env{'course.'.$cid.'.internal.selfenroll_limit'},
5297: selfenroll_cap => $env{'course.'.$cid.'.internal.selfenroll_cap'},
5298: selfenroll_start_date => $env{'course.'.$cid.'.internal.selfenroll_start_date'},
5299: selfenroll_end_date => $env{'course.'.$cid.'.internal.selfenroll_end_date'},
5300: selfenroll_start_access => $env{'course.'.$cid.'.internal.selfenroll_start_access'},
5301: selfenroll_end_access => $env{'course.'.$cid.'.internal.selfenroll_end_access'},
5302: default_enrollment_start_date => $env{'course.'.$cid.'.default_enrollment_start_date'},
5303: default_enrollment_end_date => $env{'course.'.$cid.'.default_enrollment_end_date'},
1.400 raeburn 5304: uniquecode => $env{'course.'.$cid.'.internal.uniquecode'},
1.398 raeburn 5305: );
5306: push(@{$brcrum},
5307: {href => '/adm/createuser?action=selfenroll',
5308: text => "Configure Self-enrollment",
5309: help => 'Course_Self_Enrollment'});
5310: if (!exists($env{'form.state'})) {
5311: $args = { bread_crumbs => $brcrum,
5312: bread_crumbs_component => 'Configure Self-enrollment'};
5313: $r->print(&header(undef,$args));
5314: $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n");
5315: &print_selfenroll_menu($r,'course',$cid,$cdom,$cnum,\%currsettings);
5316: } elsif ($env{'form.state'} eq 'done') {
5317: push (@{$brcrum},
5318: {href=>'/adm/createuser?action=selfenroll',
5319: text=>"Result"});
5320: $args = { bread_crumbs => $brcrum,
5321: bread_crumbs_component => 'Self-enrollment result'};
5322: $r->print(&header(undef,$args));
5323: $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n");
1.400 raeburn 5324: &update_selfenroll_config($r,$cid,$cdom,$cnum,$context,$crstype,\%currsettings);
1.398 raeburn 5325: }
5326: } else {
5327: $r->print(&header(undef,{'no_nav_bar' => 1}).
5328: '<span class="LC_error">'.&mt('You do not have permission to configure self-enrollment').'</span>');
1.237 raeburn 5329: }
1.277 raeburn 5330: } elsif ($env{'form.action'} eq 'selfenrollqueue') {
1.418 raeburn 5331: if ($permission->{selfenrolladmin}) {
1.351 raeburn 5332: push(@{$brcrum},
5333: {href => '/adm/createuser?action=selfenrollqueue',
1.418 raeburn 5334: text => 'Enrollment requests',
1.439 raeburn 5335: help => 'Course_Approve_Selfenroll'});
1.418 raeburn 5336: $bread_crumbs_component = 'Enrollment requests';
5337: if ($env{'form.state'} eq 'done') {
5338: push(@{$brcrum},
5339: {href => '/adm/createuser?action=selfenrollqueue',
5340: text => 'Result',
1.439 raeburn 5341: help => 'Course_Approve_Selfenroll'});
1.418 raeburn 5342: $bread_crumbs_component = 'Enrollment result';
5343: }
5344: $args = { bread_crumbs => $brcrum,
5345: bread_crumbs_component => $bread_crumbs_component};
5346: $r->print(&header(undef,$args));
5347: my $coursedesc = $env{'course.'.$cid.'.description'};
5348: if (!exists($env{'form.state'})) {
5349: $r->print('<h3>'.&mt('Pending enrollment requests').'</h3>'."\n");
5350: $r->print(&Apache::loncoursequeueadmin::display_queued_requests($context,
5351: $cdom,$cnum));
5352: } elsif ($env{'form.state'} eq 'done') {
5353: $r->print('<h3>'.&mt('Enrollment request processing').'</h3>'."\n");
5354: $r->print(&Apache::loncoursequeueadmin::update_request_queue($context,
1.430 raeburn 5355: $cdom,$cnum,$coursedesc));
1.418 raeburn 5356: }
5357: } else {
5358: $r->print(&header(undef,{'no_nav_bar' => 1}).
5359: '<span class="LC_error">'.&mt('You do not have permission to manage self-enrollment').'</span>');
1.351 raeburn 5360: }
1.418 raeburn 5361: } elsif ($env{'form.action'} eq 'changelogs') {
5362: if ($permission->{cusr} || $permission->{view}) {
5363: &print_userchangelogs_display($r,$context,$permission,$brcrum);
5364: } else {
5365: $r->print(&header(undef,{'no_nav_bar' => 1}).
5366: '<span class="LC_error">'.&mt('You do not have permission to view change logs').'</span>');
1.277 raeburn 5367: }
1.428 raeburn 5368: } elsif ($env{'form.action'} eq 'helpdesk') {
1.464 ! raeburn 5369: if (($permission->{'owner'} || $permission->{'co-owner'}) &&
! 5370: ($permission->{'cusr'} || $permission->{'view'})) {
1.428 raeburn 5371: if ($env{'form.state'} eq 'process') {
5372: if ($permission->{'owner'}) {
5373: &update_helpdeskaccess($r,$permission,$brcrum);
5374: } else {
5375: &print_helpdeskaccess_display($r,$permission,$brcrum);
1.430 raeburn 5376: }
1.428 raeburn 5377: } else {
5378: &print_helpdeskaccess_display($r,$permission,$brcrum);
5379: }
5380: } else {
5381: $r->print(&header(undef,{'no_nav_bar' => 1}).
5382: '<span class="LC_error">'.&mt('You do not have permission to view helpdesk access').'</span>');
5383: }
1.190 raeburn 5384: } else {
1.351 raeburn 5385: $bread_crumbs_component = 'User Management';
5386: $args = { bread_crumbs => $brcrum,
5387: bread_crumbs_component => $bread_crumbs_component};
5388: $r->print(&header(undef,$args));
1.318 raeburn 5389: $r->print(&print_main_menu($permission,$context,$crstype));
1.190 raeburn 5390: }
1.351 raeburn 5391: $r->print(&Apache::loncommon::end_page());
1.190 raeburn 5392: return OK;
5393: }
5394:
5395: sub header {
1.351 raeburn 5396: my ($jscript,$args) = @_;
1.190 raeburn 5397: my $start_page;
1.351 raeburn 5398: if (ref($args) eq 'HASH') {
5399: $start_page=&Apache::loncommon::start_page('User Management',$jscript,$args);
1.190 raeburn 5400: } else {
1.351 raeburn 5401: $start_page=&Apache::loncommon::start_page('User Management',$jscript);
1.190 raeburn 5402: }
5403: return $start_page;
5404: }
1.2 www 5405:
1.191 raeburn 5406: sub add_script {
5407: my ($js) = @_;
1.301 bisitz 5408: return '<script type="text/javascript">'."\n"
5409: .'// <![CDATA['."\n"
5410: .$js."\n"
5411: .'// ]]>'."\n"
5412: .'</script>'."\n";
1.191 raeburn 5413: }
5414:
1.391 raeburn 5415: sub usernamerequest_javascript {
5416: my $js = <<ENDJS;
5417:
5418: function openusernamereqdisplay(dom,uname,queue) {
5419: var url = '/adm/createuser?action=displayuserreq';
5420: url += '&domain='+dom+'&username='+uname+'&queue='+queue;
5421: var title = 'Account_Request_Browser';
5422: var options = 'scrollbars=1,resizable=1,menubar=0';
5423: options += ',width=700,height=600';
5424: var stdeditbrowser = open(url,title,options,'1');
5425: stdeditbrowser.focus();
5426: return;
5427: }
5428:
5429: ENDJS
5430: }
5431:
5432: sub close_popup_form {
5433: my $close= &mt('Close Window');
5434: return << "END";
5435: <p><form name="displayreq" action="" method="post">
5436: <input type="button" name="closeme" value="$close" onclick="javascript:self.close();" />
5437: </form></p>
5438: END
5439: }
5440:
1.202 raeburn 5441: sub verify_user_display {
1.364 raeburn 5442: my ($context) = @_;
1.374 raeburn 5443: my %lt = &Apache::lonlocal::texthash (
5444: course => 'course(s): description, section(s), status',
5445: community => 'community(s): description, section(s), status',
5446: author => 'author',
5447: );
1.364 raeburn 5448: my $photos;
5449: if (($context eq 'course') && $env{'request.course.id'}) {
5450: $photos = $env{'course.'.$env{'request.course.id'}.'.internal.showphoto'};
5451: }
1.202 raeburn 5452: my $output = <<"END";
5453:
1.364 raeburn 5454: function hide_searching() {
5455: if (document.getElementById('searching')) {
5456: document.getElementById('searching').style.display = 'none';
5457: }
5458: return;
5459: }
5460:
1.202 raeburn 5461: function display_update() {
5462: document.studentform.action.value = 'listusers';
5463: document.studentform.phase.value = 'display';
5464: document.studentform.submit();
5465: }
5466:
1.364 raeburn 5467: function updateCols(caller) {
5468: var context = '$context';
5469: var photos = '$photos';
5470: if (caller == 'Status') {
1.374 raeburn 5471: if ((context == 'domain') &&
5472: ((document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'course') ||
5473: (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community'))) {
1.364 raeburn 5474: document.getElementById('showcolstatus').checked = false;
5475: document.getElementById('showcolstatus').disabled = 'disabled';
5476: document.getElementById('showcolstart').checked = false;
5477: document.getElementById('showcolend').checked = false;
1.374 raeburn 5478: } else {
5479: if (document.studentform.Status.options[document.studentform.Status.selectedIndex].value == 'Any') {
5480: document.getElementById('showcolstatus').checked = true;
5481: document.getElementById('showcolstatus').disabled = '';
5482: document.getElementById('showcolstart').checked = true;
5483: document.getElementById('showcolend').checked = true;
5484: } else {
5485: document.getElementById('showcolstatus').checked = false;
5486: document.getElementById('showcolstatus').disabled = 'disabled';
5487: document.getElementById('showcolstart').checked = false;
5488: document.getElementById('showcolend').checked = false;
5489: }
1.364 raeburn 5490: }
5491: }
5492: if (caller == 'output') {
5493: if (photos == 1) {
5494: if (document.getElementById('showcolphoto')) {
5495: var photoitem = document.getElementById('showcolphoto');
5496: if (document.studentform.output.options[document.studentform.output.selectedIndex].value == 'html') {
5497: photoitem.checked = true;
5498: photoitem.disabled = '';
5499: } else {
5500: photoitem.checked = false;
5501: photoitem.disabled = 'disabled';
5502: }
5503: }
5504: }
5505: }
5506: if (caller == 'showrole') {
1.371 raeburn 5507: if ((document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'Any') ||
5508: (document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'cr')) {
1.364 raeburn 5509: document.getElementById('showcolrole').checked = true;
5510: document.getElementById('showcolrole').disabled = '';
5511: } else {
5512: document.getElementById('showcolrole').checked = false;
5513: document.getElementById('showcolrole').disabled = 'disabled';
5514: }
1.374 raeburn 5515: if (context == 'domain') {
1.382 raeburn 5516: var quotausageshow = 0;
1.374 raeburn 5517: if ((document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'course') ||
5518: (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community')) {
5519: document.getElementById('showcolstatus').checked = false;
5520: document.getElementById('showcolstatus').disabled = 'disabled';
5521: document.getElementById('showcolstart').checked = false;
5522: document.getElementById('showcolend').checked = false;
5523: } else {
5524: if (document.studentform.Status.options[document.studentform.Status.selectedIndex].value == 'Any') {
5525: document.getElementById('showcolstatus').checked = true;
5526: document.getElementById('showcolstatus').disabled = '';
5527: document.getElementById('showcolstart').checked = true;
5528: document.getElementById('showcolend').checked = true;
5529: }
5530: }
5531: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'domain') {
5532: document.getElementById('showcolextent').disabled = 'disabled';
5533: document.getElementById('showcolextent').checked = 'false';
5534: document.getElementById('showextent').style.display='none';
5535: document.getElementById('showcoltextextent').innerHTML = '';
1.382 raeburn 5536: if ((document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'au') ||
5537: (document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'Any')) {
5538: if (document.getElementById('showcolauthorusage')) {
5539: document.getElementById('showcolauthorusage').disabled = '';
5540: }
5541: if (document.getElementById('showcolauthorquota')) {
5542: document.getElementById('showcolauthorquota').disabled = '';
5543: }
5544: quotausageshow = 1;
5545: }
1.374 raeburn 5546: } else {
5547: document.getElementById('showextent').style.display='block';
5548: document.getElementById('showextent').style.textAlign='left';
5549: document.getElementById('showextent').style.textFace='normal';
5550: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'author') {
5551: document.getElementById('showcolextent').disabled = '';
5552: document.getElementById('showcolextent').checked = 'true';
5553: document.getElementById('showcoltextextent').innerHTML="$lt{'author'}";
5554: } else {
5555: document.getElementById('showcolextent').disabled = '';
5556: document.getElementById('showcolextent').checked = 'true';
5557: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community') {
5558: document.getElementById('showcoltextextent').innerHTML="$lt{'community'}";
5559: } else {
5560: document.getElementById('showcoltextextent').innerHTML="$lt{'course'}";
5561: }
5562: }
5563: }
1.382 raeburn 5564: if (quotausageshow == 0) {
5565: if (document.getElementById('showcolauthorusage')) {
5566: document.getElementById('showcolauthorusage').checked = false;
5567: document.getElementById('showcolauthorusage').disabled = 'disabled';
5568: }
5569: if (document.getElementById('showcolauthorquota')) {
5570: document.getElementById('showcolauthorquota').checked = false;
5571: document.getElementById('showcolauthorquota').disabled = 'disabled';
5572: }
5573: }
1.374 raeburn 5574: }
1.364 raeburn 5575: }
5576: return;
5577: }
5578:
1.202 raeburn 5579: END
5580: return $output;
5581:
5582: }
5583:
1.190 raeburn 5584: ###############################################################
5585: ###############################################################
5586: # Menu Phase One
5587: sub print_main_menu {
1.318 raeburn 5588: my ($permission,$context,$crstype) = @_;
5589: my $linkcontext = $context;
5590: my $stuterm = lc(&Apache::lonnet::plaintext('st',$crstype));
5591: if (($context eq 'course') && ($crstype eq 'Community')) {
5592: $linkcontext = lc($crstype);
5593: $stuterm = 'Members';
5594: }
1.208 raeburn 5595: my %links = (
1.298 droeschl 5596: domain => {
5597: upload => 'Upload a File of Users',
5598: singleuser => 'Add/Modify a User',
5599: listusers => 'Manage Users',
5600: },
5601: author => {
5602: upload => 'Upload a File of Co-authors',
5603: singleuser => 'Add/Modify a Co-author',
5604: listusers => 'Manage Co-authors',
5605: },
5606: course => {
5607: upload => 'Upload a File of Course Users',
5608: singleuser => 'Add/Modify a Course User',
1.354 www 5609: listusers => 'List and Modify Multiple Course Users',
1.298 droeschl 5610: },
1.318 raeburn 5611: community => {
5612: upload => 'Upload a File of Community Users',
5613: singleuser => 'Add/Modify a Community User',
1.354 www 5614: listusers => 'List and Modify Multiple Community Users',
1.318 raeburn 5615: },
5616: );
5617: my %linktitles = (
5618: domain => {
5619: singleuser => 'Add a user to the domain, and/or a course or community in the domain.',
5620: listusers => 'Show and manage users in this domain.',
5621: },
5622: author => {
5623: singleuser => 'Add a user with a co- or assistant author role.',
5624: listusers => 'Show and manage co- or assistant authors.',
5625: },
5626: course => {
5627: singleuser => 'Add a user with a certain role to this course.',
5628: listusers => 'Show and manage users in this course.',
5629: },
5630: community => {
5631: singleuser => 'Add a user with a certain role to this community.',
5632: listusers => 'Show and manage users in this community.',
5633: },
1.298 droeschl 5634: );
1.418 raeburn 5635: if ($linkcontext eq 'domain') {
5636: unless ($permission->{'cusr'}) {
1.430 raeburn 5637: $links{'domain'}{'singleuser'} = 'View a User';
1.418 raeburn 5638: $linktitles{'domain'}{'singleuser'} = 'View information about a user in the domain';
5639: }
5640: } elsif ($linkcontext eq 'course') {
5641: unless ($permission->{'cusr'}) {
5642: $links{'course'}{'singleuser'} = 'View a Course User';
5643: $linktitles{'course'}{'singleuser'} = 'View information about a user in this course';
5644: $links{'course'}{'listusers'} = 'List Course Users';
5645: $linktitles{'course'}{'listusers'} = 'Show information about users in this course';
5646: }
5647: } elsif ($linkcontext eq 'community') {
5648: unless ($permission->{'cusr'}) {
5649: $links{'community'}{'singleuser'} = 'View a Community User';
5650: $linktitles{'community'}{'singleuser'} = 'View information about a user in this community';
5651: $links{'community'}{'listusers'} = 'List Community Users';
5652: $linktitles{'community'}{'listusers'} = 'Show information about users in this community';
5653: }
5654: }
1.298 droeschl 5655: my @menu = ( {categorytitle => 'Single Users',
5656: items =>
5657: [
5658: {
1.318 raeburn 5659: linktext => $links{$linkcontext}{'singleuser'},
1.298 droeschl 5660: icon => 'edit-redo.png',
5661: #help => 'Course_Change_Privileges',
5662: url => '/adm/createuser?action=singleuser',
1.418 raeburn 5663: permission => ($permission->{'view'} || $permission->{'cusr'}),
1.318 raeburn 5664: linktitle => $linktitles{$linkcontext}{'singleuser'},
1.298 droeschl 5665: },
5666: ]},
5667:
5668: {categorytitle => 'Multiple Users',
5669: items =>
5670: [
5671: {
1.318 raeburn 5672: linktext => $links{$linkcontext}{'upload'},
1.340 wenzelju 5673: icon => 'uplusr.png',
1.298 droeschl 5674: #help => 'Course_Create_Class_List',
5675: url => '/adm/createuser?action=upload',
5676: permission => $permission->{'cusr'},
5677: linktitle => 'Upload a CSV or a text file containing users.',
5678: },
5679: {
1.318 raeburn 5680: linktext => $links{$linkcontext}{'listusers'},
1.340 wenzelju 5681: icon => 'mngcu.png',
1.298 droeschl 5682: #help => 'Course_View_Class_List',
5683: url => '/adm/createuser?action=listusers',
5684: permission => ($permission->{'view'} || $permission->{'cusr'}),
1.318 raeburn 5685: linktitle => $linktitles{$linkcontext}{'listusers'},
1.298 droeschl 5686: },
5687:
5688: ]},
5689:
5690: {categorytitle => 'Administration',
5691: items => [ ]},
5692: );
1.415 raeburn 5693:
1.265 mielkec 5694: if ($context eq 'domain'){
1.416 raeburn 5695: push(@{ $menu[0]->{items} }, # Single Users
5696: {
5697: linktext => 'User Access Log',
1.417 raeburn 5698: icon => 'document-properties.png',
1.425 raeburn 5699: #help => 'Domain_User_Access_Logs',
1.416 raeburn 5700: url => '/adm/createuser?action=accesslogs',
5701: permission => $permission->{'activity'},
5702: linktitle => 'View user access log.',
5703: }
5704: );
1.298 droeschl 5705:
5706: push(@{ $menu[2]->{items} }, #Category: Administration
5707: {
5708: linktext => 'Custom Roles',
5709: icon => 'emblem-photos.png',
5710: #help => 'Course_Editing_Custom_Roles',
5711: url => '/adm/createuser?action=custom',
5712: permission => $permission->{'custom'},
5713: linktitle => 'Configure a custom role.',
5714: },
1.362 raeburn 5715: {
5716: linktext => 'Authoring Space Requests',
5717: icon => 'selfenrl-queue.png',
5718: #help => 'Domain_Role_Approvals',
5719: url => '/adm/createuser?action=processauthorreq',
5720: permission => $permission->{'cusr'},
5721: linktitle => 'Approve or reject author role requests',
5722: },
1.363 raeburn 5723: {
1.391 raeburn 5724: linktext => 'LON-CAPA Account Requests',
5725: icon => 'list-add.png',
5726: #help => 'Domain_Username_Approvals',
5727: url => '/adm/createuser?action=processusernamereq',
5728: permission => $permission->{'cusr'},
5729: linktitle => 'Approve or reject LON-CAPA account requests',
5730: },
5731: {
1.363 raeburn 5732: linktext => 'Change Log',
5733: icon => 'document-properties.png',
5734: #help => 'Course_User_Logs',
5735: url => '/adm/createuser?action=changelogs',
1.418 raeburn 5736: permission => ($permission->{'cusr'} || $permission->{'view'}),
1.363 raeburn 5737: linktitle => 'View change log.',
5738: },
1.298 droeschl 5739: );
5740:
1.265 mielkec 5741: }elsif ($context eq 'course'){
1.298 droeschl 5742: my ($cnum,$cdom) = &Apache::lonuserutils::get_course_identity();
1.318 raeburn 5743:
5744: my %linktext = (
5745: 'Course' => {
5746: single => 'Add/Modify a Student',
5747: drop => 'Drop Students',
5748: groups => 'Course Groups',
5749: },
5750: 'Community' => {
5751: single => 'Add/Modify a Member',
5752: drop => 'Drop Members',
5753: groups => 'Community Groups',
5754: },
5755: );
1.411 raeburn 5756: $linktext{'Placement'} = $linktext{'Course'};
1.318 raeburn 5757:
5758: my %linktitle = (
5759: 'Course' => {
5760: single => 'Add a user with the role of student to this course',
5761: drop => 'Remove a student from this course.',
5762: groups => 'Manage course groups',
5763: },
5764: 'Community' => {
5765: single => 'Add a user with the role of member to this community',
5766: drop => 'Remove a member from this community.',
5767: groups => 'Manage community groups',
5768: },
5769: );
5770:
1.411 raeburn 5771: $linktitle{'Placement'} = $linktitle{'Course'};
5772:
1.298 droeschl 5773: push(@{ $menu[0]->{items} }, #Category: Single Users
5774: {
1.318 raeburn 5775: linktext => $linktext{$crstype}{'single'},
1.298 droeschl 5776: #help => 'Course_Add_Student',
5777: icon => 'list-add.png',
5778: url => '/adm/createuser?action=singlestudent',
5779: permission => $permission->{'cusr'},
1.318 raeburn 5780: linktitle => $linktitle{$crstype}{'single'},
1.298 droeschl 5781: },
5782: );
5783:
5784: push(@{ $menu[1]->{items} }, #Category: Multiple Users
5785: {
1.318 raeburn 5786: linktext => $linktext{$crstype}{'drop'},
1.298 droeschl 5787: icon => 'edit-undo.png',
5788: #help => 'Course_Drop_Student',
5789: url => '/adm/createuser?action=drop',
5790: permission => $permission->{'cusr'},
1.318 raeburn 5791: linktitle => $linktitle{$crstype}{'drop'},
1.298 droeschl 5792: },
5793: );
5794: push(@{ $menu[2]->{items} }, #Category: Administration
1.428 raeburn 5795: {
5796: linktext => 'Helpdesk Access',
5797: icon => 'helpdesk-access.png',
5798: #help => 'Course_Helpdesk_Access',
5799: url => '/adm/createuser?action=helpdesk',
1.464 ! raeburn 5800: permission => (($permission->{'owner'} || $permission->{'co-owner'}) &&
! 5801: ($permission->{'view'} || $permission->{'cusr'})),
1.428 raeburn 5802: linktitle => 'Helpdesk access options',
5803: },
5804: {
1.298 droeschl 5805: linktext => 'Custom Roles',
5806: icon => 'emblem-photos.png',
5807: #help => 'Course_Editing_Custom_Roles',
5808: url => '/adm/createuser?action=custom',
5809: permission => $permission->{'custom'},
5810: linktitle => 'Configure a custom role.',
5811: },
5812: {
1.318 raeburn 5813: linktext => $linktext{$crstype}{'groups'},
1.333 wenzelju 5814: icon => 'grps.png',
1.298 droeschl 5815: #help => 'Course_Manage_Group',
5816: url => '/adm/coursegroups?refpage=cusr',
5817: permission => $permission->{'grp_manage'},
1.318 raeburn 5818: linktitle => $linktitle{$crstype}{'groups'},
1.298 droeschl 5819: },
5820: {
1.328 wenzelju 5821: linktext => 'Change Log',
1.298 droeschl 5822: icon => 'document-properties.png',
5823: #help => 'Course_User_Logs',
5824: url => '/adm/createuser?action=changelogs',
1.418 raeburn 5825: permission => ($permission->{'view'} || $permission->{'cusr'}),
1.298 droeschl 5826: linktitle => 'View change log.',
5827: },
5828: );
1.277 raeburn 5829: if ($env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_approval'}) {
1.298 droeschl 5830: push(@{ $menu[2]->{items} },
1.398 raeburn 5831: {
1.298 droeschl 5832: linktext => 'Enrollment Requests',
5833: icon => 'selfenrl-queue.png',
5834: #help => 'Course_Approve_Selfenroll',
5835: url => '/adm/createuser?action=selfenrollqueue',
1.398 raeburn 5836: permission => $permission->{'selfenrolladmin'},
1.298 droeschl 5837: linktitle =>'Approve or reject enrollment requests.',
5838: },
5839: );
1.277 raeburn 5840: }
1.298 droeschl 5841:
1.265 mielkec 5842: if (!exists($permission->{'cusr_section'})){
1.320 raeburn 5843: if ($crstype ne 'Community') {
5844: push(@{ $menu[2]->{items} },
5845: {
5846: linktext => 'Automated Enrollment',
5847: icon => 'roles.png',
5848: #help => 'Course_Automated_Enrollment',
5849: permission => (&Apache::lonnet::auto_run($cnum,$cdom)
1.418 raeburn 5850: && (($permission->{'cusr'}) ||
5851: ($permission->{'view'}))),
1.320 raeburn 5852: url => '/adm/populate',
5853: linktitle => 'Automated enrollment manager.',
5854: }
5855: );
5856: }
5857: push(@{ $menu[2]->{items} },
1.298 droeschl 5858: {
5859: linktext => 'User Self-Enrollment',
1.342 wenzelju 5860: icon => 'self_enroll.png',
1.298 droeschl 5861: #help => 'Course_Self_Enrollment',
5862: url => '/adm/createuser?action=selfenroll',
1.398 raeburn 5863: permission => $permission->{'selfenrolladmin'},
1.317 bisitz 5864: linktitle => 'Configure user self-enrollment.',
1.298 droeschl 5865: },
5866: );
5867: }
1.363 raeburn 5868: } elsif ($context eq 'author') {
1.370 raeburn 5869: push(@{ $menu[2]->{items} }, #Category: Administration
1.363 raeburn 5870: {
5871: linktext => 'Change Log',
5872: icon => 'document-properties.png',
5873: #help => 'Course_User_Logs',
5874: url => '/adm/createuser?action=changelogs',
5875: permission => $permission->{'cusr'},
5876: linktitle => 'View change log.',
5877: },
1.370 raeburn 5878: );
1.363 raeburn 5879: }
5880: return Apache::lonhtmlcommon::generate_menu(@menu);
1.250 raeburn 5881: # { text => 'View Log-in History',
5882: # help => 'Course_User_Logins',
5883: # action => 'logins',
5884: # permission => $permission->{'cusr'},
5885: # });
1.190 raeburn 5886: }
5887:
1.189 albertel 5888: sub restore_prev_selections {
5889: my %saveable_parameters = ('srchby' => 'scalar',
5890: 'srchin' => 'scalar',
5891: 'srchtype' => 'scalar',
5892: );
5893: &Apache::loncommon::store_settings('user','user_picker',
5894: \%saveable_parameters);
5895: &Apache::loncommon::restore_settings('user','user_picker',
5896: \%saveable_parameters);
5897: }
5898:
1.237 raeburn 5899: sub print_selfenroll_menu {
1.418 raeburn 5900: my ($r,$context,$cid,$cdom,$cnum,$currsettings,$additional,$readonly) = @_;
1.322 raeburn 5901: my $crstype = &Apache::loncommon::course_type();
1.398 raeburn 5902: my $formname = 'selfenroll';
1.237 raeburn 5903: my $nolink = 1;
1.398 raeburn 5904: my ($row,$lt) = &Apache::lonuserutils::get_selfenroll_titles();
1.237 raeburn 5905: my $groupslist = &Apache::lonuserutils::get_groupslist();
5906: my $setsec_js =
5907: &Apache::lonuserutils::setsections_javascript($formname,$groupslist);
1.249 raeburn 5908: my %alerts = &Apache::lonlocal::texthash(
5909: acto => 'Activation of self-enrollment was selected for the following domain(s)',
5910: butn => 'but no user types have been checked.',
5911: wilf => "Please uncheck 'activate' or check at least one type.",
5912: );
1.418 raeburn 5913: my $disabled;
5914: if ($readonly) {
5915: $disabled = ' disabled="disabled"';
5916: }
1.405 damieng 5917: &js_escape(\%alerts);
1.249 raeburn 5918: my $selfenroll_js = <<"ENDSCRIPT";
5919: function update_types(caller,num) {
5920: var delidx = getIndexByName('selfenroll_delete');
5921: var actidx = getIndexByName('selfenroll_activate');
5922: if (caller == 'selfenroll_all') {
5923: var selall;
5924: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
5925: if (document.$formname.selfenroll_all[i].checked) {
5926: selall = document.$formname.selfenroll_all[i].value;
5927: }
5928: }
5929: if (selall == 1) {
5930: if (delidx != -1) {
5931: if (document.$formname.selfenroll_delete.length) {
5932: for (var j=0; j<document.$formname.selfenroll_delete.length; j++) {
5933: document.$formname.selfenroll_delete[j].checked = true;
5934: }
5935: } else {
5936: document.$formname.elements[delidx].checked = true;
5937: }
5938: }
5939: if (actidx != -1) {
5940: if (document.$formname.selfenroll_activate.length) {
5941: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
5942: document.$formname.selfenroll_activate[j].checked = false;
5943: }
5944: } else {
5945: document.$formname.elements[actidx].checked = false;
5946: }
5947: }
5948: document.$formname.selfenroll_newdom.selectedIndex = 0;
5949: }
5950: }
5951: if (caller == 'selfenroll_activate') {
5952: if (document.$formname.selfenroll_activate.length) {
5953: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
5954: if (document.$formname.selfenroll_activate[j].value == num) {
5955: if (document.$formname.selfenroll_activate[j].checked) {
5956: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
5957: if (document.$formname.selfenroll_all[i].value == '1') {
5958: document.$formname.selfenroll_all[i].checked = false;
5959: }
5960: if (document.$formname.selfenroll_all[i].value == '0') {
5961: document.$formname.selfenroll_all[i].checked = true;
5962: }
5963: }
5964: }
5965: }
5966: }
5967: } else {
5968: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
5969: if (document.$formname.selfenroll_all[i].value == '1') {
5970: document.$formname.selfenroll_all[i].checked = false;
5971: }
5972: if (document.$formname.selfenroll_all[i].value == '0') {
5973: document.$formname.selfenroll_all[i].checked = true;
5974: }
5975: }
5976: }
5977: }
5978: if (caller == 'selfenroll_delete') {
5979: if (document.$formname.selfenroll_delete.length) {
5980: for (var j=0; j<document.$formname.selfenroll_delete.length; j++) {
5981: if (document.$formname.selfenroll_delete[j].value == num) {
5982: if (document.$formname.selfenroll_delete[j].checked) {
5983: var delindex = getIndexByName('selfenroll_types_'+num);
5984: if (delindex != -1) {
5985: if (document.$formname.elements[delindex].length) {
5986: for (var k=0; k<document.$formname.elements[delindex].length; k++) {
5987: document.$formname.elements[delindex][k].checked = false;
5988: }
5989: } else {
5990: document.$formname.elements[delindex].checked = false;
5991: }
5992: }
5993: }
5994: }
5995: }
5996: } else {
5997: if (document.$formname.selfenroll_delete.checked) {
5998: var delindex = getIndexByName('selfenroll_types_'+num);
5999: if (delindex != -1) {
6000: if (document.$formname.elements[delindex].length) {
6001: for (var k=0; k<document.$formname.elements[delindex].length; k++) {
6002: document.$formname.elements[delindex][k].checked = false;
6003: }
6004: } else {
6005: document.$formname.elements[delindex].checked = false;
6006: }
6007: }
6008: }
6009: }
6010: }
6011: return;
6012: }
6013:
6014: function validate_types(form) {
6015: var needaction = new Array();
6016: var countfail = 0;
6017: var actidx = getIndexByName('selfenroll_activate');
6018: if (actidx != -1) {
6019: if (document.$formname.selfenroll_activate.length) {
6020: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
6021: var num = document.$formname.selfenroll_activate[j].value;
6022: if (document.$formname.selfenroll_activate[j].checked) {
6023: countfail = check_types(num,countfail,needaction)
6024: }
6025: }
6026: } else {
6027: if (document.$formname.selfenroll_activate.checked) {
1.398 raeburn 6028: var num = document.$formname.selfenroll_activate.value;
1.249 raeburn 6029: countfail = check_types(num,countfail,needaction)
6030: }
6031: }
6032: }
6033: if (countfail > 0) {
6034: var msg = "$alerts{'acto'}\\n";
6035: var loopend = needaction.length -1;
6036: if (loopend > 0) {
6037: for (var m=0; m<loopend; m++) {
6038: msg += needaction[m]+", ";
6039: }
6040: }
6041: msg += needaction[loopend]+"\\n$alerts{'butn'}\\n$alerts{'wilf'}";
6042: alert(msg);
6043: return;
6044: }
6045: setSections(form);
6046: }
6047:
6048: function check_types(num,countfail,needaction) {
1.441 raeburn 6049: var boxname = 'selfenroll_types_'+num;
6050: var typeidx = getIndexByName(boxname);
1.249 raeburn 6051: var count = 0;
6052: if (typeidx != -1) {
1.441 raeburn 6053: if (document.$formname.elements[boxname].length) {
6054: for (var k=0; k<document.$formname.elements[boxname].length; k++) {
6055: if (document.$formname.elements[boxname][k].checked) {
1.249 raeburn 6056: count ++;
6057: }
6058: }
6059: } else {
6060: if (document.$formname.elements[typeidx].checked) {
6061: count ++;
6062: }
6063: }
6064: if (count == 0) {
6065: var domidx = getIndexByName('selfenroll_dom_'+num);
6066: if (domidx != -1) {
6067: var domname = document.$formname.elements[domidx].value;
6068: needaction[countfail] = domname;
6069: countfail ++;
6070: }
6071: }
6072: }
6073: return countfail;
6074: }
6075:
1.398 raeburn 6076: function toggleNotify() {
6077: var selfenrollApproval = 0;
6078: if (document.$formname.selfenroll_approval.length) {
6079: for (var i=0; i<document.$formname.selfenroll_approval.length; i++) {
6080: if (document.$formname.selfenroll_approval[i].checked) {
6081: selfenrollApproval = document.$formname.selfenroll_approval[i].value;
6082: break;
6083: }
6084: }
6085: }
6086: if (document.getElementById('notified')) {
6087: if (selfenrollApproval == 0) {
6088: document.getElementById('notified').style.display='none';
6089: } else {
6090: document.getElementById('notified').style.display='block';
6091: }
6092: }
6093: return;
6094: }
6095:
1.249 raeburn 6096: function getIndexByName(item) {
6097: for (var i=0;i<document.$formname.elements.length;i++) {
6098: if (document.$formname.elements[i].name == item) {
6099: return i;
6100: }
6101: }
6102: return -1;
6103: }
6104: ENDSCRIPT
1.256 raeburn 6105:
1.237 raeburn 6106: my $output = '<script type="text/javascript">'."\n".
1.301 bisitz 6107: '// <![CDATA['."\n".
1.249 raeburn 6108: $setsec_js."\n".$selfenroll_js."\n".
1.301 bisitz 6109: '// ]]>'."\n".
1.237 raeburn 6110: '</script>'."\n".
1.256 raeburn 6111: '<h3>'.$lt->{'selfenroll'}.'</h3>'."\n";
1.400 raeburn 6112:
6113: my $visactions = &cat_visibility();
6114: my ($cathash,%cattype);
6115: my %domconfig = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom);
6116: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
6117: $cathash = $domconfig{'coursecategories'}{'cats'};
6118: $cattype{'auth'} = $domconfig{'coursecategories'}{'auth'};
6119: $cattype{'unauth'} = $domconfig{'coursecategories'}{'unauth'};
1.406 raeburn 6120: if ($cattype{'auth'} eq '') {
6121: $cattype{'auth'} = 'std';
6122: }
6123: if ($cattype{'unauth'} eq '') {
6124: $cattype{'unauth'} = 'std';
6125: }
1.400 raeburn 6126: } else {
6127: $cathash = {};
6128: $cattype{'auth'} = 'std';
6129: $cattype{'unauth'} = 'std';
6130: }
6131: if (($cattype{'auth'} eq 'none') && ($cattype{'unauth'} eq 'none')) {
6132: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
6133: '<br />'.
6134: '<br />'.$visactions->{'take'}.'<ul>'.
6135: '<li>'.$visactions->{'dc_chgconf'}.'</li>'.
6136: '</ul>');
6137: } elsif (($cattype{'auth'} !~ /^(std|domonly)$/) && ($cattype{'unauth'} !~ /^(std|domonly)$/)) {
6138: if ($currsettings->{'uniquecode'}) {
6139: $r->print('<span class="LC_info">'.$visactions->{'vis'}.'</span>');
6140: } else {
6141: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
6142: '<br />'.
6143: '<br />'.$visactions->{'take'}.'<ul>'.
6144: '<li>'.$visactions->{'dc_setcode'}.'</li>'.
6145: '</ul><br />');
6146: }
6147: } else {
6148: my ($visible,$cansetvis,$vismsgs) = &visible_in_stdcat($cdom,$cnum,\%domconfig);
6149: if (ref($visactions) eq 'HASH') {
6150: if ($visible) {
6151: $output .= '<p class="LC_info">'.$visactions->{'vis'}.'</p>';
6152: } else {
6153: $output .= '<p class="LC_warning">'.$visactions->{'miss'}.'</p>'
6154: .$visactions->{'yous'}.
6155: '<p>'.$visactions->{'gen'}.'<br />'.$visactions->{'coca'};
6156: if (ref($vismsgs) eq 'ARRAY') {
6157: $output .= '<br />'.$visactions->{'make'}.'<ul>';
6158: foreach my $item (@{$vismsgs}) {
6159: $output .= '<li>'.$visactions->{$item}.'</li>';
6160: }
6161: $output .= '</ul>';
1.256 raeburn 6162: }
1.400 raeburn 6163: $output .= '</p>';
1.256 raeburn 6164: }
6165: }
6166: }
1.398 raeburn 6167: my $actionhref = '/adm/createuser';
6168: if ($context eq 'domain') {
6169: $actionhref = '/adm/modifycourse';
6170: }
1.400 raeburn 6171:
6172: my %noedit;
6173: unless ($context eq 'domain') {
6174: %noedit = &get_noedit_fields($cdom,$cnum,$crstype,$row);
6175: }
1.398 raeburn 6176: $output .= '<form name="'.$formname.'" method="post" action="'.$actionhref.'">'."\n".
1.256 raeburn 6177: &Apache::lonhtmlcommon::start_pick_box();
1.237 raeburn 6178: if (ref($row) eq 'ARRAY') {
6179: foreach my $item (@{$row}) {
6180: my $title = $item;
6181: if (ref($lt) eq 'HASH') {
6182: $title = $lt->{$item};
6183: }
1.297 bisitz 6184: $output .= &Apache::lonhtmlcommon::row_title($title);
1.237 raeburn 6185: if ($item eq 'types') {
1.398 raeburn 6186: my $curr_types;
6187: if (ref($currsettings) eq 'HASH') {
6188: $curr_types = $currsettings->{'selfenroll_types'};
6189: }
1.400 raeburn 6190: if ($noedit{$item}) {
6191: if ($curr_types eq '*') {
6192: $output .= &mt('Any user in any domain');
6193: } else {
6194: my @entries = split(/;/,$curr_types);
6195: if (@entries > 0) {
6196: $output .= '<ul>';
6197: foreach my $entry (@entries) {
6198: my ($currdom,$typestr) = split(/:/,$entry);
6199: next if ($typestr eq '');
6200: my $domdesc = &Apache::lonnet::domain($currdom);
6201: my @currinsttypes = split(',',$typestr);
6202: my ($othertitle,$usertypes,$types) =
6203: &Apache::loncommon::sorted_inst_types($currdom);
6204: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
6205: $usertypes->{'any'} = &mt('any user');
6206: if (keys(%{$usertypes}) > 0) {
6207: $usertypes->{'other'} = &mt('other users');
6208: }
6209: my @longinsttypes = map { $usertypes->{$_}; } @currinsttypes;
6210: $output .= '<li>'.$domdesc.':'.join(', ',@longinsttypes).'</li>';
6211: }
6212: }
6213: $output .= '</ul>';
6214: } else {
6215: $output .= &mt('None');
6216: }
6217: }
6218: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6219: next;
6220: }
1.241 raeburn 6221: my $showdomdesc = 1;
6222: my $includeempty = 1;
6223: my $num = 0;
6224: $output .= &Apache::loncommon::start_data_table().
6225: &Apache::loncommon::start_data_table_row()
6226: .'<td colspan="2"><span class="LC_nobreak"><label>'
6227: .&mt('Any user in any domain:')
6228: .' <input type="radio" name="selfenroll_all" value="1" ';
6229: if ($curr_types eq '*') {
6230: $output .= ' checked="checked" ';
6231: }
1.249 raeburn 6232: $output .= 'onchange="javascript:update_types('.
1.418 raeburn 6233: "'selfenroll_all'".');"'.$disabled.' />'.&mt('Yes').'</label>'.
1.249 raeburn 6234: ' <input type="radio" name="selfenroll_all" value="0" ';
1.241 raeburn 6235: if ($curr_types ne '*') {
6236: $output .= ' checked="checked" ';
6237: }
1.249 raeburn 6238: $output .= ' onchange="javascript:update_types('.
1.418 raeburn 6239: "'selfenroll_all'".');"'.$disabled.' />'.&mt('No').'</label></td>'.
1.249 raeburn 6240: &Apache::loncommon::end_data_table_row().
6241: &Apache::loncommon::end_data_table().
6242: &mt('Or').'<br />'.
6243: &Apache::loncommon::start_data_table();
1.241 raeburn 6244: my %currdoms;
1.249 raeburn 6245: if ($curr_types eq '') {
1.241 raeburn 6246: $output .= &new_selfenroll_dom_row($cdom,'0');
6247: } elsif ($curr_types ne '*') {
6248: my @entries = split(/;/,$curr_types);
6249: if (@entries > 0) {
6250: foreach my $entry (@entries) {
6251: my ($currdom,$typestr) = split(/:/,$entry);
6252: $currdoms{$currdom} = 1;
6253: my $domdesc = &Apache::lonnet::domain($currdom);
1.249 raeburn 6254: my @currinsttypes = split(',',$typestr);
1.241 raeburn 6255: $output .= &Apache::loncommon::start_data_table_row()
6256: .'<td valign="top"><span class="LC_nobreak">'.&mt('Domain:').'<b>'
6257: .' '.$domdesc.' ('.$currdom.')'
6258: .'</b><input type="hidden" name="selfenroll_dom_'.$num
6259: .'" value="'.$currdom.'" /></span><br />'
6260: .'<span class="LC_nobreak"><label><input type="checkbox" '
1.418 raeburn 6261: .'name="selfenroll_delete" value="'.$num.'" onchange="javascript:update_types('."'selfenroll_delete','$num'".');"'.$disabled.' />'
1.241 raeburn 6262: .&mt('Delete').'</label></span></td>';
1.249 raeburn 6263: $output .= '<td valign="top"> '.&mt('User types:').'<br />'
1.418 raeburn 6264: .&selfenroll_inst_types($num,$currdom,\@currinsttypes,$readonly).'</td>'
1.241 raeburn 6265: .&Apache::loncommon::end_data_table_row();
6266: $num ++;
6267: }
6268: }
6269: }
1.249 raeburn 6270: my $add_domtitle = &mt('Users in additional domain:');
1.241 raeburn 6271: if ($curr_types eq '*') {
1.249 raeburn 6272: $add_domtitle = &mt('Users in specific domain:');
1.241 raeburn 6273: } elsif ($curr_types eq '') {
1.249 raeburn 6274: $add_domtitle = &mt('Users in other domain:');
1.241 raeburn 6275: }
1.446 raeburn 6276: my ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('enroll',$cdom);
1.241 raeburn 6277: $output .= &Apache::loncommon::start_data_table_row()
6278: .'<td colspan="2"><span class="LC_nobreak">'.$add_domtitle.'</span><br />'
6279: .&Apache::loncommon::select_dom_form('','selfenroll_newdom',
1.446 raeburn 6280: $includeempty,$showdomdesc,'',$trusted,$untrusted,$readonly)
1.241 raeburn 6281: .'<input type="hidden" name="selfenroll_types_total" value="'.$num.'" />'
6282: .'</td>'.&Apache::loncommon::end_data_table_row()
6283: .&Apache::loncommon::end_data_table();
1.237 raeburn 6284: } elsif ($item eq 'registered') {
6285: my ($regon,$regoff);
1.398 raeburn 6286: my $registered;
6287: if (ref($currsettings) eq 'HASH') {
6288: $registered = $currsettings->{'selfenroll_registered'};
6289: }
1.400 raeburn 6290: if ($noedit{$item}) {
6291: if ($registered) {
6292: $output .= &mt('Must be registered in course');
6293: } else {
6294: $output .= &mt('No requirement');
6295: }
6296: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6297: next;
6298: }
1.398 raeburn 6299: if ($registered) {
1.237 raeburn 6300: $regon = ' checked="checked" ';
1.419 raeburn 6301: $regoff = '';
1.237 raeburn 6302: } else {
1.419 raeburn 6303: $regon = '';
1.237 raeburn 6304: $regoff = ' checked="checked" ';
6305: }
6306: $output .= '<label>'.
1.419 raeburn 6307: '<input type="radio" name="selfenroll_registered" value="1"'.$regon.$disabled.' />'.
1.244 bisitz 6308: &mt('Yes').'</label> <label>'.
1.419 raeburn 6309: '<input type="radio" name="selfenroll_registered" value="0"'.$regoff.$disabled.' />'.
1.244 bisitz 6310: &mt('No').'</label>';
1.237 raeburn 6311: } elsif ($item eq 'enroll_dates') {
1.398 raeburn 6312: my ($starttime,$endtime);
6313: if (ref($currsettings) eq 'HASH') {
6314: $starttime = $currsettings->{'selfenroll_start_date'};
6315: $endtime = $currsettings->{'selfenroll_end_date'};
6316: if ($starttime eq '') {
6317: $starttime = $currsettings->{'default_enrollment_start_date'};
6318: }
6319: if ($endtime eq '') {
6320: $endtime = $currsettings->{'default_enrollment_end_date'};
6321: }
1.237 raeburn 6322: }
1.400 raeburn 6323: if ($noedit{$item}) {
6324: $output .= &mt('From: [_1], to: [_2]',&Apache::lonlocal::locallocaltime($starttime),
6325: &Apache::lonlocal::locallocaltime($endtime));
6326: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6327: next;
6328: }
1.237 raeburn 6329: my $startform =
6330: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_start_date',$starttime,
1.418 raeburn 6331: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
1.237 raeburn 6332: my $endform =
6333: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_end_date',$endtime,
1.418 raeburn 6334: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
1.237 raeburn 6335: $output .= &selfenroll_date_forms($startform,$endform);
6336: } elsif ($item eq 'access_dates') {
1.398 raeburn 6337: my ($starttime,$endtime);
6338: if (ref($currsettings) eq 'HASH') {
6339: $starttime = $currsettings->{'selfenroll_start_access'};
6340: $endtime = $currsettings->{'selfenroll_end_access'};
6341: if ($starttime eq '') {
6342: $starttime = $currsettings->{'default_enrollment_start_date'};
6343: }
6344: if ($endtime eq '') {
6345: $endtime = $currsettings->{'default_enrollment_end_date'};
6346: }
1.237 raeburn 6347: }
1.400 raeburn 6348: if ($noedit{$item}) {
6349: $output .= &mt('From: [_1], to: [_2]',&Apache::lonlocal::locallocaltime($starttime),
6350: &Apache::lonlocal::locallocaltime($endtime));
6351: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6352: next;
6353: }
1.237 raeburn 6354: my $startform =
6355: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_start_access',$starttime,
1.418 raeburn 6356: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
1.237 raeburn 6357: my $endform =
6358: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_end_access',$endtime,
1.418 raeburn 6359: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
1.237 raeburn 6360: $output .= &selfenroll_date_forms($startform,$endform);
6361: } elsif ($item eq 'section') {
1.398 raeburn 6362: my $currsec;
6363: if (ref($currsettings) eq 'HASH') {
6364: $currsec = $currsettings->{'selfenroll_section'};
6365: }
1.237 raeburn 6366: my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum);
6367: my $newsecval;
6368: if ($currsec ne 'none' && $currsec ne '') {
6369: if (!defined($sections_count{$currsec})) {
6370: $newsecval = $currsec;
6371: }
6372: }
1.400 raeburn 6373: if ($noedit{$item}) {
6374: if ($currsec ne '') {
6375: $output .= $currsec;
6376: } else {
6377: $output .= &mt('No specific section');
6378: }
6379: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6380: next;
6381: }
1.237 raeburn 6382: my $sections_select =
1.418 raeburn 6383: &Apache::lonuserutils::course_sections(\%sections_count,'st',$currsec,$disabled);
1.237 raeburn 6384: $output .= '<table class="LC_createuser">'."\n".
6385: '<tr class="LC_section_row">'."\n".
6386: '<td align="center">'.&mt('Existing sections')."\n".
6387: '<br />'.$sections_select.'</td><td align="center">'.
6388: &mt('New section').'<br />'."\n".
1.418 raeburn 6389: '<input type="text" name="newsec" size="15" value="'.$newsecval.'"'.$disabled.' />'."\n".
1.237 raeburn 6390: '<input type="hidden" name="sections" value="" />'."\n".
6391: '</td></tr></table>'."\n";
1.276 raeburn 6392: } elsif ($item eq 'approval') {
1.398 raeburn 6393: my ($currnotified,$currapproval,%appchecked);
6394: my %selfdescs = &Apache::lonuserutils::selfenroll_default_descs();
1.430 raeburn 6395: if (ref($currsettings) eq 'HASH') {
1.398 raeburn 6396: $currnotified = $currsettings->{'selfenroll_notifylist'};
6397: $currapproval = $currsettings->{'selfenroll_approval'};
6398: }
6399: if ($currapproval !~ /^[012]$/) {
6400: $currapproval = 0;
6401: }
1.400 raeburn 6402: if ($noedit{$item}) {
6403: $output .= $selfdescs{'approval'}{$currapproval}.
6404: '<br />'.&mt('(Set by Domain Coordinator)');
6405: next;
6406: }
1.398 raeburn 6407: $appchecked{$currapproval} = ' checked="checked"';
6408: for my $i (0..2) {
6409: $output .= '<label>'.
6410: '<input type="radio" name="selfenroll_approval" value="'.$i.'"'.
1.418 raeburn 6411: $appchecked{$i}.' onclick="toggleNotify();"'.$disabled.' />'.
6412: $selfdescs{'approval'}{$i}.'</label>'.(' 'x2);
1.276 raeburn 6413: }
6414: my %advhash = &Apache::lonnet::get_course_adv_roles($cid,1);
6415: my (@ccs,%notified);
1.322 raeburn 6416: my $ccrole = 'cc';
6417: if ($crstype eq 'Community') {
6418: $ccrole = 'co';
6419: }
6420: if ($advhash{$ccrole}) {
6421: @ccs = split(/,/,$advhash{$ccrole});
1.276 raeburn 6422: }
6423: if ($currnotified) {
6424: foreach my $current (split(/,/,$currnotified)) {
6425: $notified{$current} = 1;
6426: if (!grep(/^\Q$current\E$/,@ccs)) {
6427: push(@ccs,$current);
6428: }
6429: }
6430: }
6431: if (@ccs) {
1.398 raeburn 6432: my $style;
6433: unless ($currapproval) {
6434: $style = ' style="display: none;"';
6435: }
6436: $output .= '<br /><div id="notified"'.$style.'>'.
6437: &mt('Personnel to be notified when an enrollment request needs approval, or has been approved:').' '.
6438: &Apache::loncommon::start_data_table().
1.276 raeburn 6439: &Apache::loncommon::start_data_table_row();
6440: my $count = 0;
6441: my $numcols = 4;
6442: foreach my $cc (sort(@ccs)) {
6443: my $notifyon;
6444: my ($ccuname,$ccudom) = split(/:/,$cc);
6445: if ($notified{$cc}) {
6446: $notifyon = ' checked="checked" ';
6447: }
6448: if ($count && !$count%$numcols) {
6449: $output .= &Apache::loncommon::end_data_table_row().
6450: &Apache::loncommon::start_data_table_row()
6451: }
6452: $output .= '<td><span class="LC_nobreak"><label>'.
1.418 raeburn 6453: '<input type="checkbox" name="selfenroll_notify"'.$notifyon.' value="'.$cc.'"'.$disabled.' />'.
1.276 raeburn 6454: &Apache::loncommon::plainname($ccuname,$ccudom).
6455: '</label></span></td>';
1.343 raeburn 6456: $count ++;
1.276 raeburn 6457: }
6458: my $rem = $count%$numcols;
6459: if ($rem) {
6460: my $emptycols = $numcols - $rem;
6461: for (my $i=0; $i<$emptycols; $i++) {
6462: $output .= '<td> </td>';
6463: }
6464: }
6465: $output .= &Apache::loncommon::end_data_table_row().
1.398 raeburn 6466: &Apache::loncommon::end_data_table().
6467: '</div>';
1.276 raeburn 6468: }
6469: } elsif ($item eq 'limit') {
1.398 raeburn 6470: my ($crslimit,$selflimit,$nolimit,$currlim,$currcap);
6471: if (ref($currsettings) eq 'HASH') {
6472: $currlim = $currsettings->{'selfenroll_limit'};
6473: $currcap = $currsettings->{'selfenroll_cap'};
6474: }
1.400 raeburn 6475: if ($noedit{$item}) {
6476: if (($currlim eq 'allstudents') || ($currlim eq 'selfenrolled')) {
6477: if ($currlim eq 'allstudents') {
6478: $output .= &mt('Limit by total students');
6479: } elsif ($currlim eq 'selfenrolled') {
6480: $output .= &mt('Limit by total self-enrolled students');
6481: }
6482: $output .= ' '.&mt('Maximum: [_1]',$currcap).
6483: '<br />'.&mt('(Set by Domain Coordinator)');
6484: } else {
6485: $output .= &mt('No limit').'<br />'.&mt('(Set by Domain Coordinator)');
6486: }
6487: next;
6488: }
1.276 raeburn 6489: if ($currlim eq 'allstudents') {
6490: $crslimit = ' checked="checked" ';
6491: $selflimit = ' ';
6492: $nolimit = ' ';
6493: } elsif ($currlim eq 'selfenrolled') {
6494: $crslimit = ' ';
6495: $selflimit = ' checked="checked" ';
6496: $nolimit = ' ';
6497: } else {
6498: $crslimit = ' ';
6499: $selflimit = ' ';
1.398 raeburn 6500: $nolimit = ' checked="checked" ';
1.276 raeburn 6501: }
6502: $output .= '<table><tr><td><label>'.
1.418 raeburn 6503: '<input type="radio" name="selfenroll_limit" value="none"'.$nolimit.$disabled.'/>'.
1.276 raeburn 6504: &mt('No limit').'</label></td><td><label>'.
1.418 raeburn 6505: '<input type="radio" name="selfenroll_limit" value="allstudents"'.$crslimit.$disabled.'/>'.
1.276 raeburn 6506: &mt('Limit by total students').'</label></td><td><label>'.
1.418 raeburn 6507: '<input type="radio" name="selfenroll_limit" value="selfenrolled"'.$selflimit.$disabled.'/>'.
1.276 raeburn 6508: &mt('Limit by total self-enrolled students').
6509: '</td></tr><tr>'.
6510: '<td> </td><td colspan="2"><span class="LC_nobreak">'.
6511: (' 'x3).&mt('Maximum number allowed: ').
1.418 raeburn 6512: '<input type="text" name="selfenroll_cap" size = "5" value="'.$currcap.'"'.$disabled.' /></td></tr></table>';
1.237 raeburn 6513: }
6514: $output .= &Apache::lonhtmlcommon::row_closure(1);
6515: }
6516: }
1.418 raeburn 6517: $output .= &Apache::lonhtmlcommon::end_pick_box().'<br />';
6518: unless ($readonly) {
6519: $output .= '<input type="button" name="selfenrollconf" value="'
6520: .&mt('Save').'" onclick="validate_types(this.form);" />';
6521: }
6522: $output .= '<input type="hidden" name="action" value="selfenroll" />'
6523: .'<input type="hidden" name="state" value="done" />'."\n"
6524: .$additional.'</form>';
1.237 raeburn 6525: $r->print($output);
6526: return;
6527: }
6528:
1.400 raeburn 6529: sub get_noedit_fields {
6530: my ($cdom,$cnum,$crstype,$row) = @_;
6531: my %noedit;
6532: if (ref($row) eq 'ARRAY') {
6533: my %settings = &Apache::lonnet::get('environment',['internal.coursecode','internal.textbook',
6534: 'internal.selfenrollmgrdc',
6535: 'internal.selfenrollmgrcc'],$cdom,$cnum);
6536: my $type = &Apache::lonuserutils::get_extended_type($cdom,$cnum,$crstype,\%settings);
6537: my (%specific_managebydc,%specific_managebycc,%default_managebydc);
6538: map { $specific_managebydc{$_} = 1; } (split(/,/,$settings{'internal.selfenrollmgrdc'}));
6539: map { $specific_managebycc{$_} = 1; } (split(/,/,$settings{'internal.selfenrollmgrcc'}));
6540: my %domdefaults = &Apache::lonnet::get_domain_defaults($cdom);
6541: map { $default_managebydc{$_} = 1; } (split(/,/,$domdefaults{$type.'selfenrolladmdc'}));
6542:
6543: foreach my $item (@{$row}) {
6544: next if ($specific_managebycc{$item});
6545: if (($specific_managebydc{$item}) || ($default_managebydc{$item})) {
6546: $noedit{$item} = 1;
6547: }
6548: }
6549: }
6550: return %noedit;
6551: }
6552:
6553: sub visible_in_stdcat {
6554: my ($cdom,$cnum,$domconf) = @_;
6555: my ($cathash,%settable,@vismsgs,$cansetvis,$visible);
6556: unless (ref($domconf) eq 'HASH') {
6557: return ($visible,$cansetvis,\@vismsgs);
6558: }
6559: if (ref($domconf->{'coursecategories'}) eq 'HASH') {
6560: if ($domconf->{'coursecategories'}{'togglecats'} eq 'crs') {
1.256 raeburn 6561: $settable{'togglecats'} = 1;
6562: }
1.400 raeburn 6563: if ($domconf->{'coursecategories'}{'categorize'} eq 'crs') {
1.256 raeburn 6564: $settable{'categorize'} = 1;
6565: }
1.400 raeburn 6566: $cathash = $domconf->{'coursecategories'}{'cats'};
1.256 raeburn 6567: }
1.260 raeburn 6568: if ($settable{'togglecats'} && $settable{'categorize'}) {
1.256 raeburn 6569: $cansetvis = &mt('You are able to both assign a course category and choose to exclude this course from the catalog.');
6570: } elsif ($settable{'togglecats'}) {
6571: $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 6572: } elsif ($settable{'categorize'}) {
1.256 raeburn 6573: $cansetvis = &mt('You may assign a course category, but only a Domain Coordinator may choose to exclude this course from the catalog.');
6574: } else {
6575: $cansetvis = &mt('Only a Domain Coordinator may assign a course category or choose to exclude this course from the catalog.');
6576: }
6577:
6578: my %currsettings =
6579: &Apache::lonnet::get('environment',['hidefromcat','categories','internal.coursecode'],
6580: $cdom,$cnum);
1.400 raeburn 6581: $visible = 0;
1.256 raeburn 6582: if ($currsettings{'internal.coursecode'} ne '') {
1.400 raeburn 6583: if (ref($domconf->{'coursecategories'}) eq 'HASH') {
6584: $cathash = $domconf->{'coursecategories'}{'cats'};
1.256 raeburn 6585: if (ref($cathash) eq 'HASH') {
6586: if ($cathash->{'instcode::0'} eq '') {
6587: push(@vismsgs,'dc_addinst');
6588: } else {
6589: $visible = 1;
6590: }
6591: } else {
6592: $visible = 1;
6593: }
6594: } else {
6595: $visible = 1;
6596: }
6597: } else {
6598: if (ref($cathash) eq 'HASH') {
6599: if ($cathash->{'instcode::0'} ne '') {
6600: push(@vismsgs,'dc_instcode');
6601: }
6602: } else {
6603: push(@vismsgs,'dc_instcode');
6604: }
6605: }
6606: if ($currsettings{'categories'} ne '') {
6607: my $cathash;
1.400 raeburn 6608: if (ref($domconf->{'coursecategories'}) eq 'HASH') {
6609: $cathash = $domconf->{'coursecategories'}{'cats'};
1.256 raeburn 6610: if (ref($cathash) eq 'HASH') {
6611: if (keys(%{$cathash}) == 0) {
6612: push(@vismsgs,'dc_catalog');
6613: } elsif ((keys(%{$cathash}) == 1) && ($cathash->{'instcode::0'} ne '')) {
6614: push(@vismsgs,'dc_categories');
6615: } else {
6616: my @currcategories = split('&',$currsettings{'categories'});
6617: my $matched = 0;
6618: foreach my $cat (@currcategories) {
6619: if ($cathash->{$cat} ne '') {
6620: $visible = 1;
6621: $matched = 1;
6622: last;
6623: }
6624: }
6625: if (!$matched) {
1.260 raeburn 6626: if ($settable{'categorize'}) {
1.256 raeburn 6627: push(@vismsgs,'chgcat');
6628: } else {
6629: push(@vismsgs,'dc_chgcat');
6630: }
6631: }
6632: }
6633: }
6634: }
6635: } else {
6636: if (ref($cathash) eq 'HASH') {
6637: if ((keys(%{$cathash}) > 1) ||
6638: (keys(%{$cathash}) == 1) && ($cathash->{'instcode::0'} eq '')) {
1.260 raeburn 6639: if ($settable{'categorize'}) {
1.256 raeburn 6640: push(@vismsgs,'addcat');
6641: } else {
6642: push(@vismsgs,'dc_addcat');
6643: }
6644: }
6645: }
6646: }
6647: if ($currsettings{'hidefromcat'} eq 'yes') {
6648: $visible = 0;
6649: if ($settable{'togglecats'}) {
6650: unshift(@vismsgs,'unhide');
6651: } else {
6652: unshift(@vismsgs,'dc_unhide')
6653: }
6654: }
1.400 raeburn 6655: return ($visible,$cansetvis,\@vismsgs);
6656: }
6657:
6658: sub cat_visibility {
6659: my %visactions = &Apache::lonlocal::texthash(
6660: vis => 'This course/community currently appears in the Course/Community Catalog for this domain.',
6661: 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.',
6662: miss => 'This course/community does not currently appear in the Course/Community Catalog for this domain.',
6663: none => 'Display of a course catalog is disabled for this domain.',
6664: yous => 'You should remedy this if you plan to allow self-enrollment, otherwise students will have difficulty finding this course.',
6665: 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.',
6666: make => 'Make any changes to self-enrollment settings below, click "Save", then take action to include the course in the Catalog:',
6667: take => 'Take the following action to ensure the course appears in the Catalog:',
6668: dc_chgconf => 'Ask a domain coordinator to change the Catalog type for this domain.',
6669: dc_setcode => 'Ask a domain coordinator to assign a six character code to the course',
6670: dc_unhide => 'Ask a domain coordinator to change the "Exclude from course catalog" setting.',
6671: dc_addinst => 'Ask a domain coordinator to enable display the catalog of "Official courses (with institutional codes)".',
6672: dc_instcode => 'Ask a domain coordinator to assign an institutional code (if this is an official course).',
6673: dc_catalog => 'Ask a domain coordinator to enable or create at least one course category in the domain.',
6674: dc_categories => 'Ask a domain coordinator to create a hierarchy of categories and sub categories for courses in the domain.',
6675: 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',
6676: dc_addcat => 'Ask a domain coordinator to assign a category to the course.',
6677: );
6678: $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>"');
6679: $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>"');
6680: $visactions{'addcat'} = &mt('Use [_1]Categorize course[_2] to assign a category to the course.','"<a href="/adm/courseprefs?phase=display&actions=courseinfo">','</a>"');
6681: return \%visactions;
1.256 raeburn 6682: }
6683:
1.241 raeburn 6684: sub new_selfenroll_dom_row {
6685: my ($newdom,$num) = @_;
6686: my $domdesc = &Apache::lonnet::domain($newdom);
6687: my $output;
6688: if ($domdesc ne '') {
6689: $output .= &Apache::loncommon::start_data_table_row()
6690: .'<td valign="top"><span class="LC_nobreak">'.&mt('Domain:').' <b>'.$domdesc
6691: .' ('.$newdom.')</b><input type="hidden" name="selfenroll_dom_'.$num
1.249 raeburn 6692: .'" value="'.$newdom.'" /></span><br />'
6693: .'<span class="LC_nobreak"><label><input type="checkbox" '
6694: .'name="selfenroll_activate" value="'.$num.'" '
6695: .'onchange="javascript:update_types('
6696: ."'selfenroll_activate','$num'".');" />'
6697: .&mt('Activate').'</label></span></td>';
1.241 raeburn 6698: my @currinsttypes;
6699: $output .= '<td>'.&mt('User types:').'<br />'
6700: .&selfenroll_inst_types($num,$newdom,\@currinsttypes).'</td>'
6701: .&Apache::loncommon::end_data_table_row();
6702: }
6703: return $output;
6704: }
6705:
6706: sub selfenroll_inst_types {
1.418 raeburn 6707: my ($num,$currdom,$currinsttypes,$readonly) = @_;
1.241 raeburn 6708: my $output;
6709: my $numinrow = 4;
6710: my $count = 0;
6711: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($currdom);
1.247 raeburn 6712: my $othervalue = 'any';
1.418 raeburn 6713: my $disabled;
6714: if ($readonly) {
6715: $disabled = ' disabled="disabled"';
6716: }
1.241 raeburn 6717: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
1.251 raeburn 6718: if (keys(%{$usertypes}) > 0) {
1.247 raeburn 6719: $othervalue = 'other';
6720: }
1.241 raeburn 6721: $output .= '<table><tr>';
6722: foreach my $type (@{$types}) {
6723: if (($count > 0) && ($count%$numinrow == 0)) {
6724: $output .= '</tr><tr>';
6725: }
6726: if (defined($usertypes->{$type})) {
1.257 raeburn 6727: my $esc_type = &escape($type);
1.241 raeburn 6728: $output .= '<td><span class="LC_nobreak"><label><input type = "checkbox" value="'.
1.257 raeburn 6729: $esc_type.'" ';
1.241 raeburn 6730: if (ref($currinsttypes) eq 'ARRAY') {
6731: if (@{$currinsttypes} > 0) {
1.249 raeburn 6732: if (grep(/^any$/,@{$currinsttypes})) {
6733: $output .= 'checked="checked"';
1.257 raeburn 6734: } elsif (grep(/^\Q$esc_type\E$/,@{$currinsttypes})) {
1.241 raeburn 6735: $output .= 'checked="checked"';
6736: }
1.249 raeburn 6737: } else {
6738: $output .= 'checked="checked"';
1.241 raeburn 6739: }
6740: }
1.418 raeburn 6741: $output .= ' name="selfenroll_types_'.$num.'"'.$disabled.' />'.$usertypes->{$type}.'</label></span></td>';
1.241 raeburn 6742: }
6743: $count ++;
6744: }
6745: if (($count > 0) && ($count%$numinrow == 0)) {
6746: $output .= '</tr><tr>';
6747: }
1.249 raeburn 6748: $output .= '<td><span class="LC_nobreak"><label><input type = "checkbox" value="'.$othervalue.'"';
1.241 raeburn 6749: if (ref($currinsttypes) eq 'ARRAY') {
6750: if (@{$currinsttypes} > 0) {
1.249 raeburn 6751: if (grep(/^any$/,@{$currinsttypes})) {
6752: $output .= ' checked="checked"';
6753: } elsif ($othervalue eq 'other') {
6754: if (grep(/^\Q$othervalue\E$/,@{$currinsttypes})) {
6755: $output .= ' checked="checked"';
6756: }
1.241 raeburn 6757: }
1.249 raeburn 6758: } else {
6759: $output .= ' checked="checked"';
1.241 raeburn 6760: }
1.249 raeburn 6761: } else {
6762: $output .= ' checked="checked"';
1.241 raeburn 6763: }
1.418 raeburn 6764: $output .= ' name="selfenroll_types_'.$num.'"'.$disabled.' />'.$othertitle.'</label></span></td></tr></table>';
1.241 raeburn 6765: }
6766: return $output;
6767: }
6768:
1.237 raeburn 6769: sub selfenroll_date_forms {
6770: my ($startform,$endform) = @_;
6771: my $output .= &Apache::lonhtmlcommon::start_pick_box()."\n".
1.244 bisitz 6772: &Apache::lonhtmlcommon::row_title(&mt('Start date'),
1.237 raeburn 6773: 'LC_oddrow_value')."\n".
6774: $startform."\n".
6775: &Apache::lonhtmlcommon::row_closure(1).
1.244 bisitz 6776: &Apache::lonhtmlcommon::row_title(&mt('End date'),
1.237 raeburn 6777: 'LC_oddrow_value')."\n".
6778: $endform."\n".
6779: &Apache::lonhtmlcommon::row_closure(1).
6780: &Apache::lonhtmlcommon::end_pick_box();
6781: return $output;
6782: }
6783:
1.239 raeburn 6784: sub print_userchangelogs_display {
1.415 raeburn 6785: my ($r,$context,$permission,$brcrum) = @_;
1.363 raeburn 6786: my $formname = 'rolelog';
1.418 raeburn 6787: my ($username,$domain,$crstype,$viewablesec,%roleslog);
1.363 raeburn 6788: if ($context eq 'domain') {
6789: $domain = $env{'request.role.domain'};
6790: %roleslog=&Apache::lonnet::dump_dom('nohist_rolelog',$domain);
6791: } else {
6792: if ($context eq 'course') {
6793: $domain = $env{'course.'.$env{'request.course.id'}.'.domain'};
6794: $username = $env{'course.'.$env{'request.course.id'}.'.num'};
6795: $crstype = &Apache::loncommon::course_type();
1.418 raeburn 6796: $viewablesec = &Apache::lonuserutils::viewable_section($permission);
1.363 raeburn 6797: my %saveable_parameters = ('show' => 'scalar',);
6798: &Apache::loncommon::store_course_settings('roles_log',
6799: \%saveable_parameters);
6800: &Apache::loncommon::restore_course_settings('roles_log',
6801: \%saveable_parameters);
6802: } elsif ($context eq 'author') {
6803: $domain = $env{'user.domain'};
6804: if ($env{'request.role'} =~ m{^au\./\Q$domain\E/$}) {
6805: $username = $env{'user.name'};
6806: } else {
6807: undef($domain);
6808: }
6809: }
6810: if ($domain ne '' && $username ne '') {
6811: %roleslog=&Apache::lonnet::dump('nohist_rolelog',$domain,$username);
6812: }
6813: }
1.239 raeburn 6814: if ((keys(%roleslog))[0]=~/^error\:/) { undef(%roleslog); }
6815:
1.415 raeburn 6816: my $helpitem;
6817: if ($context eq 'course') {
6818: $helpitem = 'Course_User_Logs';
1.439 raeburn 6819: } elsif ($context eq 'domain') {
6820: $helpitem = 'Domain_Role_Logs';
6821: } elsif ($context eq 'author') {
6822: $helpitem = 'Author_User_Logs';
1.415 raeburn 6823: }
6824: push (@{$brcrum},
6825: {href => '/adm/createuser?action=changelogs',
6826: text => 'User Management Logs',
6827: help => $helpitem});
6828: my $bread_crumbs_component = 'User Changes';
6829: my $args = { bread_crumbs => $brcrum,
6830: bread_crumbs_component => $bread_crumbs_component};
6831:
6832: # Create navigation javascript
6833: my $jsnav = &userlogdisplay_js($formname);
6834:
6835: my $jscript = (<<ENDSCRIPT);
6836: <script type="text/javascript">
6837: // <![CDATA[
6838: $jsnav
6839: // ]]>
6840: </script>
6841: ENDSCRIPT
6842:
6843: # print page header
6844: $r->print(&header($jscript,$args));
6845:
1.239 raeburn 6846: # set defaults
6847: my $now = time();
6848: my $defstart = $now - (7*24*3600); #7 days ago
6849: my %defaults = (
6850: page => '1',
6851: show => '10',
6852: role => 'any',
6853: chgcontext => 'any',
6854: rolelog_start_date => $defstart,
6855: rolelog_end_date => $now,
6856: );
6857: my $more_records = 0;
6858:
6859: # set current
6860: my %curr;
6861: foreach my $item ('show','page','role','chgcontext') {
6862: $curr{$item} = $env{'form.'.$item};
6863: }
6864: my ($startdate,$enddate) =
6865: &Apache::lonuserutils::get_dates_from_form('rolelog_start_date','rolelog_end_date');
6866: $curr{'rolelog_start_date'} = $startdate;
6867: $curr{'rolelog_end_date'} = $enddate;
6868: foreach my $key (keys(%defaults)) {
6869: if ($curr{$key} eq '') {
6870: $curr{$key} = $defaults{$key};
6871: }
6872: }
1.248 raeburn 6873: my (%whodunit,%changed,$version);
6874: ($version) = ($r->dir_config('lonVersion') =~ /^([\d\.]+)\-/);
1.239 raeburn 6875: my ($minshown,$maxshown);
1.255 raeburn 6876: $minshown = 1;
1.239 raeburn 6877: my $count = 0;
1.415 raeburn 6878: if ($curr{'show'} =~ /\D/) {
6879: $curr{'page'} = 1;
6880: } else {
1.239 raeburn 6881: $maxshown = $curr{'page'} * $curr{'show'};
6882: if ($curr{'page'} > 1) {
6883: $minshown = 1 + ($curr{'page'} - 1) * $curr{'show'};
6884: }
6885: }
1.301 bisitz 6886:
1.327 raeburn 6887: # Form Header
6888: $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">'.
1.363 raeburn 6889: &role_display_filter($context,$formname,$domain,$username,\%curr,
6890: $version,$crstype));
1.327 raeburn 6891:
6892: my $showntableheader = 0;
6893:
6894: # Table Header
6895: my $tableheader =
6896: &Apache::loncommon::start_data_table_header_row()
6897: .'<th> </th>'
6898: .'<th>'.&mt('When').'</th>'
6899: .'<th>'.&mt('Who made the change').'</th>'
6900: .'<th>'.&mt('Changed User').'</th>'
1.363 raeburn 6901: .'<th>'.&mt('Role').'</th>';
6902:
6903: if ($context eq 'course') {
6904: $tableheader .= '<th>'.&mt('Section').'</th>';
6905: }
6906: $tableheader .=
6907: '<th>'.&mt('Context').'</th>'
1.327 raeburn 6908: .'<th>'.&mt('Start').'</th>'
6909: .'<th>'.&mt('End').'</th>'
6910: .&Apache::loncommon::end_data_table_header_row();
6911:
6912: # Display user change log data
1.239 raeburn 6913: foreach my $id (sort { $roleslog{$b}{'exe_time'}<=>$roleslog{$a}{'exe_time'} } (keys(%roleslog))) {
6914: next if (($roleslog{$id}{'exe_time'} < $curr{'rolelog_start_date'}) ||
6915: ($roleslog{$id}{'exe_time'} > $curr{'rolelog_end_date'}));
1.415 raeburn 6916: if ($curr{'show'} !~ /\D/) {
1.239 raeburn 6917: if ($count >= $curr{'page'} * $curr{'show'}) {
6918: $more_records = 1;
6919: last;
6920: }
6921: }
6922: if ($curr{'role'} ne 'any') {
6923: next if ($roleslog{$id}{'logentry'}{'role'} ne $curr{'role'});
6924: }
6925: if ($curr{'chgcontext'} ne 'any') {
6926: if ($curr{'chgcontext'} eq 'selfenroll') {
6927: next if (!$roleslog{$id}{'logentry'}{'selfenroll'});
6928: } else {
6929: next if ($roleslog{$id}{'logentry'}{'context'} ne $curr{'chgcontext'});
6930: }
6931: }
1.418 raeburn 6932: if (($context eq 'course') && ($viewablesec ne '')) {
1.430 raeburn 6933: next if ($roleslog{$id}{'logentry'}{'section'} ne $viewablesec);
1.418 raeburn 6934: }
1.239 raeburn 6935: $count ++;
6936: next if ($count < $minshown);
1.327 raeburn 6937: unless ($showntableheader) {
1.415 raeburn 6938: $r->print(&Apache::loncommon::start_data_table()
1.327 raeburn 6939: .$tableheader);
6940: $r->rflush();
6941: $showntableheader = 1;
6942: }
1.239 raeburn 6943: if ($whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}} eq '') {
6944: $whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}} =
6945: &Apache::loncommon::plainname($roleslog{$id}{'exe_uname'},$roleslog{$id}{'exe_udom'});
6946: }
6947: if ($changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}} eq '') {
6948: $changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}} =
6949: &Apache::loncommon::plainname($roleslog{$id}{'uname'},$roleslog{$id}{'udom'});
6950: }
6951: my $sec = $roleslog{$id}{'logentry'}{'section'};
6952: if ($sec eq '') {
6953: $sec = &mt('None');
6954: }
6955: my ($rolestart,$roleend);
6956: if ($roleslog{$id}{'delflag'}) {
6957: $rolestart = &mt('deleted');
6958: $roleend = &mt('deleted');
6959: } else {
6960: $rolestart = $roleslog{$id}{'logentry'}{'start'};
6961: $roleend = $roleslog{$id}{'logentry'}{'end'};
6962: if ($rolestart eq '' || $rolestart == 0) {
6963: $rolestart = &mt('No start date');
6964: } else {
6965: $rolestart = &Apache::lonlocal::locallocaltime($rolestart);
6966: }
6967: if ($roleend eq '' || $roleend == 0) {
6968: $roleend = &mt('No end date');
6969: } else {
6970: $roleend = &Apache::lonlocal::locallocaltime($roleend);
6971: }
6972: }
6973: my $chgcontext = $roleslog{$id}{'logentry'}{'context'};
6974: if ($roleslog{$id}{'logentry'}{'selfenroll'}) {
6975: $chgcontext = 'selfenroll';
6976: }
1.363 raeburn 6977: my %lt = &rolechg_contexts($context,$crstype);
1.239 raeburn 6978: if ($chgcontext ne '' && $lt{$chgcontext} ne '') {
6979: $chgcontext = $lt{$chgcontext};
6980: }
1.327 raeburn 6981: $r->print(
1.301 bisitz 6982: &Apache::loncommon::start_data_table_row()
6983: .'<td>'.$count.'</td>'
6984: .'<td>'.&Apache::lonlocal::locallocaltime($roleslog{$id}{'exe_time'}).'</td>'
6985: .'<td>'.$whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}}.'</td>'
6986: .'<td>'.$changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}}.'</td>'
1.363 raeburn 6987: .'<td>'.&Apache::lonnet::plaintext($roleslog{$id}{'logentry'}{'role'},$crstype).'</td>');
6988: if ($context eq 'course') {
6989: $r->print('<td>'.$sec.'</td>');
6990: }
6991: $r->print(
6992: '<td>'.$chgcontext.'</td>'
1.301 bisitz 6993: .'<td>'.$rolestart.'</td>'
6994: .'<td>'.$roleend.'</td>'
1.327 raeburn 6995: .&Apache::loncommon::end_data_table_row()."\n");
1.301 bisitz 6996: }
6997:
1.327 raeburn 6998: if ($showntableheader) { # Table footer, if content displayed above
1.415 raeburn 6999: $r->print(&Apache::loncommon::end_data_table().
7000: &userlogdisplay_navlinks(\%curr,$more_records));
1.327 raeburn 7001: } else { # No content displayed above
1.301 bisitz 7002: $r->print('<p class="LC_info">'
7003: .&mt('There are no records to display.')
7004: .'</p>'
7005: );
1.239 raeburn 7006: }
1.301 bisitz 7007:
1.327 raeburn 7008: # Form Footer
7009: $r->print(
7010: '<input type="hidden" name="page" value="'.$curr{'page'}.'" />'
7011: .'<input type="hidden" name="action" value="changelogs" />'
7012: .'</form>');
7013: return;
7014: }
1.301 bisitz 7015:
1.416 raeburn 7016: sub print_useraccesslogs_display {
7017: my ($r,$uname,$udom,$permission,$brcrum) = @_;
7018: my $formname = 'accesslog';
7019: my $form = 'document.accesslog';
7020:
7021: # set breadcrumbs
1.422 raeburn 7022: my %breadcrumb_text = &singleuser_breadcrumb('','domain',$udom);
1.431 raeburn 7023: my $prevphasestr;
7024: if ($env{'form.popup'}) {
7025: $brcrum = [];
7026: } else {
7027: push (@{$brcrum},
7028: {href => "javascript:backPage($form)",
7029: text => $breadcrumb_text{'search'}});
7030: my @prevphases;
7031: if ($env{'form.prevphases'}) {
7032: @prevphases = split(/,/,$env{'form.prevphases'});
7033: $prevphasestr = $env{'form.prevphases'};
7034: }
7035: if (($env{'form.phase'} eq 'userpicked') || (grep(/^userpicked$/,@prevphases))) {
7036: push(@{$brcrum},
7037: {href => "javascript:backPage($form,'get_user_info','select')",
7038: text => $breadcrumb_text{'userpicked'}});
7039: if ($env{'form.phase'} eq 'userpicked') {
7040: $prevphasestr = 'userpicked';
7041: }
1.416 raeburn 7042: }
7043: }
7044: push(@{$brcrum},
7045: {href => '/adm/createuser?action=accesslogs',
7046: text => 'User access logs',
1.424 raeburn 7047: help => 'Domain_User_Access_Logs'});
1.416 raeburn 7048: my $bread_crumbs_component = 'User Access Logs';
7049: my $args = { bread_crumbs => $brcrum,
7050: bread_crumbs_component => 'User Management'};
1.423 raeburn 7051: if ($env{'form.popup'}) {
7052: $args->{'no_nav_bar'} = 1;
1.431 raeburn 7053: $args->{'bread_crumbs_nomenu'} = 1;
1.423 raeburn 7054: }
1.416 raeburn 7055:
1.417 raeburn 7056: # set javascript
1.416 raeburn 7057: my ($jsback,$elements) = &crumb_utilities();
7058: my $jsnav = &userlogdisplay_js($formname);
7059:
7060: my $jscript = (<<ENDSCRIPT);
7061: <script type="text/javascript">
7062: // <![CDATA[
7063:
7064: $jsback
7065: $jsnav
7066:
7067: // ]]>
7068: </script>
7069:
7070: ENDSCRIPT
7071:
1.417 raeburn 7072: # print page header
1.416 raeburn 7073: $r->print(&header($jscript,$args));
7074:
7075: # early out unless log data can be displayed.
7076: unless ($permission->{'activity'}) {
7077: $r->print('<p class="LC_warning">'
7078: .&mt('You do not have rights to display user access logs.')
1.431 raeburn 7079: .'</p>');
7080: if ($env{'form.popup'}) {
7081: $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a></p>');
7082: } else {
7083: $r->print(&earlyout_accesslog_form($formname,$prevphasestr,$udom));
7084: }
1.416 raeburn 7085: return;
7086: }
7087:
7088: unless ($udom eq $env{'request.role.domain'}) {
7089: $r->print('<p class="LC_warning">'
7090: .&mt("User's domain must match role's domain")
7091: .'</p>'
7092: .&earlyout_accesslog_form($formname,$prevphasestr,$udom));
1.417 raeburn 7093: return;
1.416 raeburn 7094: }
7095:
7096: if (($uname eq '') || ($udom eq '')) {
7097: $r->print('<p class="LC_warning">'
7098: .&mt('Invalid username or domain')
7099: .'</p>'
7100: .&earlyout_accesslog_form($formname,$prevphasestr,$udom));
7101: return;
7102: }
7103:
1.437 raeburn 7104: if (&Apache::lonnet::privileged($uname,$udom,
7105: [$env{'request.role.domain'}],['dc','su'])) {
7106: unless (&Apache::lonnet::privileged($env{'user.name'},$env{'user.domain'},
7107: [$env{'request.role.domain'}],['dc','su'])) {
7108: $r->print('<p class="LC_warning">'
7109: .&mt('You need to be a privileged user to display user access logs for [_1]',
7110: &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),
7111: $uname,$udom))
7112: .'</p>');
7113: if ($env{'form.popup'}) {
7114: $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a></p>');
7115: } else {
7116: $r->print(&earlyout_accesslog_form($formname,$prevphasestr,$udom));
7117: }
7118: return;
7119: }
7120: }
7121:
1.416 raeburn 7122: # set defaults
7123: my $now = time();
7124: my $defstart = $now - (7*24*3600);
7125: my %defaults = (
7126: page => '1',
7127: show => '10',
7128: activity => 'any',
7129: accesslog_start_date => $defstart,
7130: accesslog_end_date => $now,
7131: );
7132: my $more_records = 0;
7133:
7134: # set current
7135: my %curr;
7136: foreach my $item ('show','page','activity') {
7137: $curr{$item} = $env{'form.'.$item};
7138: }
7139: my ($startdate,$enddate) =
7140: &Apache::lonuserutils::get_dates_from_form('accesslog_start_date','accesslog_end_date');
7141: $curr{'accesslog_start_date'} = $startdate;
7142: $curr{'accesslog_end_date'} = $enddate;
7143: foreach my $key (keys(%defaults)) {
7144: if ($curr{$key} eq '') {
7145: $curr{$key} = $defaults{$key};
7146: }
7147: }
7148: my ($minshown,$maxshown);
7149: $minshown = 1;
7150: my $count = 0;
7151: if ($curr{'show'} =~ /\D/) {
7152: $curr{'page'} = 1;
7153: } else {
7154: $maxshown = $curr{'page'} * $curr{'show'};
7155: if ($curr{'page'} > 1) {
7156: $minshown = 1 + ($curr{'page'} - 1) * $curr{'show'};
7157: }
7158: }
7159:
7160: # form header
7161: $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">'.
7162: &activity_display_filter($formname,\%curr));
7163:
7164: my $showntableheader = 0;
7165: my ($nav_script,$nav_links);
7166:
7167: # table header
1.453 raeburn 7168: my $heading = '<h3>'.
1.431 raeburn 7169: &mt('User access logs for: [_1]',
1.453 raeburn 7170: &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),$uname,$udom)).'</h3>';
7171: my $tableheader = $heading
1.431 raeburn 7172: .&Apache::loncommon::start_data_table_header_row()
1.416 raeburn 7173: .'<th> </th>'
7174: .'<th>'.&mt('When').'</th>'
7175: .'<th>'.&mt('HostID').'</th>'
7176: .'<th>'.&mt('Event').'</th>'
7177: .'<th>'.&mt('Other data').'</th>'
7178: .&Apache::loncommon::end_data_table_header_row();
7179:
7180: my %filters=(
7181: start => $curr{'accesslog_start_date'},
7182: end => $curr{'accesslog_end_date'},
7183: action => $curr{'activity'},
7184: );
7185:
7186: my $reply = &Apache::lonnet::userlog_query($uname,$udom,%filters);
7187: unless ( ($reply =~/^timeout/) || ($reply =~/^error/) ) {
7188: my (%courses,%missing);
7189: my @results = split(/\&/,$reply);
7190: foreach my $item (reverse(@results)) {
7191: my ($timestamp,$host,$event) = split(/:/,$item);
7192: next unless ($event =~ /^(Log|Role)/);
7193: if ($curr{'show'} !~ /\D/) {
7194: if ($count >= $curr{'page'} * $curr{'show'}) {
7195: $more_records = 1;
7196: last;
7197: }
7198: }
7199: $count ++;
7200: next if ($count < $minshown);
7201: unless ($showntableheader) {
7202: $r->print($nav_script
7203: .&Apache::loncommon::start_data_table()
7204: .$tableheader);
7205: $r->rflush();
7206: $showntableheader = 1;
7207: }
1.418 raeburn 7208: my ($shown,$extra);
1.437 raeburn 7209: my ($event,$data) = split(/\s+/,&unescape($event),2);
1.416 raeburn 7210: if ($event eq 'Role') {
7211: my ($rolecode,$extent) = split(/\./,$data,2);
7212: next if ($extent eq '');
7213: my ($crstype,$desc,$info);
1.418 raeburn 7214: if ($extent =~ m{^/($match_domain)/($match_courseid)(?:/(\w+)|)$}) {
7215: my ($cdom,$cnum,$sec) = ($1,$2,$3);
1.416 raeburn 7216: my $cid = $cdom.'_'.$cnum;
7217: if (exists($courses{$cid})) {
7218: $crstype = $courses{$cid}{'type'};
7219: $desc = $courses{$cid}{'description'};
7220: } elsif ($missing{$cid}) {
7221: $crstype = 'Course';
7222: $desc = 'Course/Community';
7223: } else {
7224: my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',$cnum,undef,undef,'.');
7225: if (ref($crsinfo{$cdom.'_'.$cnum}) eq 'HASH') {
7226: $courses{$cid} = $crsinfo{$cid};
7227: $crstype = $crsinfo{$cid}{'type'};
7228: $desc = $crsinfo{$cid}{'description'};
7229: } else {
7230: $missing{$cid} = 1;
7231: }
7232: }
7233: $extra = &mt($crstype).': <a href="/public/'.$cdom.'/'.$cnum.'/syllabus">'.$desc.'</a>';
1.418 raeburn 7234: if ($sec ne '') {
7235: $extra .= ' ('.&mt('Section: [_1]',$sec).')';
7236: }
1.416 raeburn 7237: } elsif ($extent =~ m{^/($match_domain)/($match_username|$)}) {
7238: my ($dom,$name) = ($1,$2);
7239: if ($rolecode eq 'au') {
7240: $extra = '';
7241: } elsif ($rolecode =~ /^(ca|aa)$/) {
1.417 raeburn 7242: $extra = &mt('Authoring Space: [_1]',$name.':'.$dom);
1.416 raeburn 7243: } elsif ($rolecode =~ /^(li|dg|dh|dc|sc)$/) {
7244: $extra = &mt('Domain: [_1]',$dom);
7245: }
7246: }
7247: my $rolename;
7248: if ($rolecode =~ m{^cr/($match_domain)/($match_username)/(\w+)}) {
7249: my $role = $3;
1.417 raeburn 7250: my $owner = "($2:$1)";
1.416 raeburn 7251: if ($2 eq $1.'-domainconfig') {
7252: $owner = '(ad hoc)';
1.417 raeburn 7253: }
1.416 raeburn 7254: $rolename = &mt('Custom role: [_1]',$role.' '.$owner);
7255: } else {
7256: $rolename = &Apache::lonnet::plaintext($rolecode,$crstype);
7257: }
7258: $shown = &mt('Role selection: [_1]',$rolename);
7259: } else {
7260: $shown = &mt($event);
1.437 raeburn 7261: if ($data =~ /^webdav/) {
7262: my ($path,$clientip) = split(/\s+/,$data,2);
7263: $path =~ s/^webdav//;
7264: if ($clientip ne '') {
7265: $extra = &mt('Client IP address: [_1]',$clientip);
7266: }
7267: if ($path ne '') {
7268: $shown .= ' '.&mt('(WebDAV access to [_1])',$path);
7269: }
7270: } elsif ($data ne '') {
7271: $extra = &mt('Client IP address: [_1]',$data);
1.416 raeburn 7272: }
7273: }
7274: $r->print(
7275: &Apache::loncommon::start_data_table_row()
7276: .'<td>'.$count.'</td>'
7277: .'<td>'.&Apache::lonlocal::locallocaltime($timestamp).'</td>'
7278: .'<td>'.$host.'</td>'
7279: .'<td>'.$shown.'</td>'
7280: .'<td>'.$extra.'</td>'
7281: .&Apache::loncommon::end_data_table_row()."\n");
7282: }
7283: }
7284:
7285: if ($showntableheader) { # Table footer, if content displayed above
7286: $r->print(&Apache::loncommon::end_data_table().
7287: &userlogdisplay_navlinks(\%curr,$more_records));
7288: } else { # No content displayed above
1.453 raeburn 7289: $r->print($heading.'<p class="LC_info">'
1.416 raeburn 7290: .&mt('There are no records to display.')
7291: .'</p>');
7292: }
7293:
1.423 raeburn 7294: if ($env{'form.popup'} == 1) {
7295: $r->print('<input type="hidden" name="popup" value="1" />'."\n");
7296: }
7297:
1.416 raeburn 7298: # Form Footer
7299: $r->print(
7300: '<input type="hidden" name="currstate" value="" />'
7301: .'<input type="hidden" name="accessuname" value="'.$uname.'" />'
7302: .'<input type="hidden" name="accessudom" value="'.$udom.'" />'
7303: .'<input type="hidden" name="page" value="'.$curr{'page'}.'" />'
7304: .'<input type="hidden" name="prevphases" value="'.$prevphasestr.'" />'
7305: .'<input type="hidden" name="phase" value="activity" />'
7306: .'<input type="hidden" name="action" value="accesslogs" />'
7307: .'<input type="hidden" name="srchdomain" value="'.$udom.'" />'
7308: .'<input type="hidden" name="srchby" value="'.$env{'form.srchby'}.'" />'
7309: .'<input type="hidden" name="srchtype" value="'.$env{'form.srchtype'}.'" />'
7310: .'<input type="hidden" name="srchterm" value="'.&HTML::Entities::encode($env{'form.srchterm'},'<>"&').'" />'
7311: .'<input type="hidden" name="srchin" value="'.$env{'form.srchin'}.'" />'
7312: .'</form>');
7313: return;
7314: }
7315:
7316: sub earlyout_accesslog_form {
7317: my ($formname,$prevphasestr,$udom) = @_;
7318: my $srchterm = &HTML::Entities::encode($env{'form.srchterm'},'<>"&');
7319: return <<"END";
7320: <form action="/adm/createuser" method="post" name="$formname">
7321: <input type="hidden" name="currstate" value="" />
7322: <input type="hidden" name="prevphases" value="$prevphasestr" />
7323: <input type="hidden" name="phase" value="activity" />
7324: <input type="hidden" name="action" value="accesslogs" />
7325: <input type="hidden" name="srchdomain" value="$udom" />
7326: <input type="hidden" name="srchby" value="$env{'form.srchby'}" />
7327: <input type="hidden" name="srchtype" value="$env{'form.srchtype'}" />
7328: <input type="hidden" name="srchterm" value="$srchterm" />
7329: <input type="hidden" name="srchin" value="$env{'form.srchin'}" />
7330: </form>
7331: END
7332: }
7333:
7334: sub activity_display_filter {
7335: my ($formname,$curr) = @_;
7336: my $nolink = 1;
7337: my $output = '<table><tr><td valign="top">'.
7338: '<span class="LC_nobreak"><b>'.&mt('Actions/page:').'</b></span><br />'.
7339: &Apache::lonmeta::selectbox('show',$curr->{'show'},undef,
7340: (&mt('all'),5,10,20,50,100,1000,10000)).
7341: '</td><td> </td>';
7342: my $startform =
7343: &Apache::lonhtmlcommon::date_setter($formname,'accesslog_start_date',
7344: $curr->{'accesslog_start_date'},undef,
7345: undef,undef,undef,undef,undef,undef,$nolink);
7346: my $endform =
7347: &Apache::lonhtmlcommon::date_setter($formname,'accesslog_end_date',
7348: $curr->{'accesslog_end_date'},undef,
7349: undef,undef,undef,undef,undef,undef,$nolink);
7350: my %lt = &Apache::lonlocal::texthash (
7351: activity => 'Activity',
7352: Role => 'Role selection',
7353: log => 'Log-in or Logout',
7354: );
7355: $output .= '<td valign="top"><b>'.&mt('Window during which actions occurred:').'</b><br />'.
7356: '<table><tr><td>'.&mt('After:').
7357: '</td><td>'.$startform.'</td></tr>'.
7358: '<tr><td>'.&mt('Before:').'</td>'.
7359: '<td>'.$endform.'</td></tr></table>'.
7360: '</td>'.
7361: '<td> </td>'.
7362: '<td valign="top"><b>'.&mt('Activities').'</b><br />'.
7363: '<select name="activity"><option value="any"';
7364: if ($curr->{'activity'} eq 'any') {
7365: $output .= ' selected="selected"';
7366: }
7367: $output .= '>'.&mt('Any').'</option>'."\n";
7368: foreach my $activity ('Role','log') {
7369: my $selstr = '';
7370: if ($activity eq $curr->{'activity'}) {
7371: $selstr = ' selected="selected"';
7372: }
7373: $output .= '<option value="'.$activity.'"'.$selstr.'>'.$lt{$activity}.'</option>';
7374: }
7375: $output .= '</select></td>'.
7376: '</tr></table>';
7377: # Update Display button
7378: $output .= '<p>'
7379: .'<input type="submit" value="'.&mt('Update Display').'" />'
1.431 raeburn 7380: .'</p><hr />';
1.416 raeburn 7381: return $output;
7382: }
7383:
1.415 raeburn 7384: sub userlogdisplay_js {
7385: my ($formname) = @_;
7386: return <<"ENDSCRIPT";
7387:
1.239 raeburn 7388: function chgPage(caller) {
7389: if (caller == 'previous') {
7390: document.$formname.page.value --;
7391: }
7392: if (caller == 'next') {
7393: document.$formname.page.value ++;
7394: }
1.327 raeburn 7395: document.$formname.submit();
1.239 raeburn 7396: return;
7397: }
7398: ENDSCRIPT
1.415 raeburn 7399: }
7400:
7401: sub userlogdisplay_navlinks {
7402: my ($curr,$more_records) = @_;
7403: return unless(ref($curr) eq 'HASH');
7404: # Navigation Buttons
7405: my $nav_links = '<p>';
7406: if (($curr->{'page'} > 1) || ($more_records)) {
7407: if (($curr->{'page'} > 1) && ($curr->{'show'} !~ /\D/)) {
7408: $nav_links .= '<input type="button"'
7409: .' onclick="javascript:chgPage('."'previous'".');"'
7410: .' value="'.&mt('Previous [_1] changes',$curr->{'show'})
7411: .'" /> ';
7412: }
7413: if ($more_records) {
7414: $nav_links .= '<input type="button"'
7415: .' onclick="javascript:chgPage('."'next'".');"'
7416: .' value="'.&mt('Next [_1] changes',$curr->{'show'})
7417: .'" />';
1.301 bisitz 7418: }
7419: }
1.415 raeburn 7420: $nav_links .= '</p>';
7421: return $nav_links;
1.239 raeburn 7422: }
7423:
7424: sub role_display_filter {
1.363 raeburn 7425: my ($context,$formname,$cdom,$cnum,$curr,$version,$crstype) = @_;
7426: my $lctype;
7427: if ($context eq 'course') {
7428: $lctype = lc($crstype);
7429: }
1.239 raeburn 7430: my $nolink = 1;
7431: my $output = '<table><tr><td valign="top">'.
1.301 bisitz 7432: '<span class="LC_nobreak"><b>'.&mt('Changes/page:').'</b></span><br />'.
1.239 raeburn 7433: &Apache::lonmeta::selectbox('show',$curr->{'show'},undef,
7434: (&mt('all'),5,10,20,50,100,1000,10000)).
7435: '</td><td> </td>';
7436: my $startform =
7437: &Apache::lonhtmlcommon::date_setter($formname,'rolelog_start_date',
7438: $curr->{'rolelog_start_date'},undef,
7439: undef,undef,undef,undef,undef,undef,$nolink);
7440: my $endform =
7441: &Apache::lonhtmlcommon::date_setter($formname,'rolelog_end_date',
7442: $curr->{'rolelog_end_date'},undef,
7443: undef,undef,undef,undef,undef,undef,$nolink);
1.363 raeburn 7444: my %lt = &rolechg_contexts($context,$crstype);
1.301 bisitz 7445: $output .= '<td valign="top"><b>'.&mt('Window during which changes occurred:').'</b><br />'.
7446: '<table><tr><td>'.&mt('After:').
7447: '</td><td>'.$startform.'</td></tr>'.
7448: '<tr><td>'.&mt('Before:').'</td>'.
7449: '<td>'.$endform.'</td></tr></table>'.
7450: '</td>'.
7451: '<td> </td>'.
1.239 raeburn 7452: '<td valign="top"><b>'.&mt('Role:').'</b><br />'.
7453: '<select name="role"><option value="any"';
7454: if ($curr->{'role'} eq 'any') {
7455: $output .= ' selected="selected"';
7456: }
7457: $output .= '>'.&mt('Any').'</option>'."\n";
1.363 raeburn 7458: my @roles = &Apache::lonuserutils::roles_by_context($context,1,$crstype);
1.239 raeburn 7459: foreach my $role (@roles) {
7460: my $plrole;
7461: if ($role eq 'cr') {
7462: $plrole = &mt('Custom Role');
7463: } else {
1.318 raeburn 7464: $plrole=&Apache::lonnet::plaintext($role,$crstype);
1.239 raeburn 7465: }
7466: my $selstr = '';
7467: if ($role eq $curr->{'role'}) {
7468: $selstr = ' selected="selected"';
7469: }
7470: $output .= ' <option value="'.$role.'"'.$selstr.'>'.$plrole.'</option>';
7471: }
1.301 bisitz 7472: $output .= '</select></td>'.
7473: '<td> </td>'.
7474: '<td valign="top"><b>'.
1.239 raeburn 7475: &mt('Context:').'</b><br /><select name="chgcontext">';
1.363 raeburn 7476: my @posscontexts;
7477: if ($context eq 'course') {
1.457 raeburn 7478: @posscontexts = ('any','automated','updatenow','createcourse','course','domain','selfenroll','requestcourses','chgtype');
1.363 raeburn 7479: } elsif ($context eq 'domain') {
7480: @posscontexts = ('any','domain','requestauthor','domconfig','server');
7481: } else {
7482: @posscontexts = ('any','author','domain');
1.457 raeburn 7483: }
1.363 raeburn 7484: foreach my $chgtype (@posscontexts) {
1.239 raeburn 7485: my $selstr = '';
7486: if ($curr->{'chgcontext'} eq $chgtype) {
1.301 bisitz 7487: $selstr = ' selected="selected"';
1.239 raeburn 7488: }
1.363 raeburn 7489: if ($context eq 'course') {
1.376 raeburn 7490: if (($chgtype eq 'automated') || ($chgtype eq 'updatenow')) {
1.363 raeburn 7491: next if (!&Apache::lonnet::auto_run($cnum,$cdom));
7492: }
1.239 raeburn 7493: }
7494: $output .= '<option value="'.$chgtype.'"'.$selstr.'>'.$lt{$chgtype}.'</option>'."\n";
1.248 raeburn 7495: }
1.303 bisitz 7496: $output .= '</select></td>'
7497: .'</tr></table>';
7498:
7499: # Update Display button
7500: $output .= '<p>'
7501: .'<input type="submit" value="'.&mt('Update Display').'" />'
7502: .'</p>';
7503:
7504: # Server version info
1.363 raeburn 7505: my $needsrev = '2.11.0';
7506: if ($context eq 'course') {
7507: $needsrev = '2.7.0';
7508: }
7509:
1.303 bisitz 7510: $output .= '<p class="LC_info">'
7511: .&mt('Only changes made from servers running LON-CAPA [_1] or later are displayed.'
1.363 raeburn 7512: ,$needsrev);
1.248 raeburn 7513: if ($version) {
1.303 bisitz 7514: $output .= ' '.&mt('This LON-CAPA server is version [_1]',$version);
7515: }
7516: $output .= '</p><hr />';
1.239 raeburn 7517: return $output;
7518: }
7519:
7520: sub rolechg_contexts {
1.363 raeburn 7521: my ($context,$crstype) = @_;
7522: my %lt;
7523: if ($context eq 'course') {
7524: %lt = &Apache::lonlocal::texthash (
1.239 raeburn 7525: any => 'Any',
1.376 raeburn 7526: automated => 'Automated Enrollment',
1.457 raeburn 7527: chgtype => 'Enrollment Type/Lock Change',
1.239 raeburn 7528: updatenow => 'Roster Update',
7529: createcourse => 'Course Creation',
7530: course => 'User Management in course',
7531: domain => 'User Management in domain',
1.313 raeburn 7532: selfenroll => 'Self-enrolled',
1.318 raeburn 7533: requestcourses => 'Course Request',
1.239 raeburn 7534: );
1.363 raeburn 7535: if ($crstype eq 'Community') {
7536: $lt{'createcourse'} = &mt('Community Creation');
7537: $lt{'course'} = &mt('User Management in community');
7538: $lt{'requestcourses'} = &mt('Community Request');
7539: }
7540: } elsif ($context eq 'domain') {
7541: %lt = &Apache::lonlocal::texthash (
7542: any => 'Any',
7543: domain => 'User Management in domain',
7544: requestauthor => 'Authoring Request',
7545: server => 'Command line script (DC role)',
7546: domconfig => 'Self-enrolled',
7547: );
7548: } else {
7549: %lt = &Apache::lonlocal::texthash (
7550: any => 'Any',
7551: domain => 'User Management in domain',
7552: author => 'User Management by author',
7553: );
7554: }
1.239 raeburn 7555: return %lt;
7556: }
7557:
1.428 raeburn 7558: sub print_helpdeskaccess_display {
7559: my ($r,$permission,$brcrum) = @_;
7560: my $formname = 'helpdeskaccess';
7561: my $helpitem = 'Course_Helpdesk_Access';
7562: push (@{$brcrum},
7563: {href => '/adm/createuser?action=helpdesk',
7564: text => 'Helpdesk Access',
7565: help => $helpitem});
7566: my $bread_crumbs_component = 'Helpdesk Staff Access';
7567: my $args = { bread_crumbs => $brcrum,
7568: bread_crumbs_component => $bread_crumbs_component};
7569:
7570: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
7571: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
7572: my $confname = $cdom.'-domainconfig';
7573: my $crstype = &Apache::loncommon::course_type();
7574:
1.434 raeburn 7575: my @accesstypes = ('all','dh','da','none');
1.428 raeburn 7576: my ($numstatustypes,@jsarray);
7577: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($cdom);
7578: if (ref($types) eq 'ARRAY') {
1.430 raeburn 7579: if (@{$types} > 0) {
1.428 raeburn 7580: $numstatustypes = scalar(@{$types});
7581: push(@accesstypes,'status');
7582: @jsarray = ('bystatus');
7583: }
7584: }
7585: my %customroles = &get_domain_customroles($cdom,$confname);
1.432 raeburn 7586: my %domhelpdesk = &Apache::lonnet::get_active_domroles($cdom,['dh','da']);
1.428 raeburn 7587: if (keys(%domhelpdesk)) {
7588: push(@accesstypes,('inc','exc'));
7589: push(@jsarray,('notinc','notexc'));
7590: }
7591: push(@jsarray,'privs');
7592: my $hiddenstr = join("','",@jsarray);
7593: my $rolestr = join("','",sort(keys(%customroles)));
7594:
7595: my $jscript;
7596: my (%settings,%overridden);
7597: if (keys(%customroles)) {
7598: &get_adhocrole_settings($env{'request.course.id'},\@accesstypes,
7599: $types,\%customroles,\%settings,\%overridden);
7600: my %jsfull=();
7601: my %jslevels= (
7602: course => {},
7603: domain => {},
7604: system => {},
7605: );
7606: my %jslevelscurrent=(
7607: course => {},
7608: domain => {},
7609: system => {},
7610: );
7611: my (%privs,%jsprivs);
7612: &Apache::lonuserutils::custom_role_privs(\%privs,\%jsfull,\%jslevels,\%jslevelscurrent);
7613: foreach my $priv (keys(%jsfull)) {
7614: if ($jslevels{'course'}{$priv}) {
7615: $jsprivs{$priv} = 1;
7616: }
7617: }
7618: my (%elements,%stored);
7619: foreach my $role (keys(%customroles)) {
7620: $elements{$role.'_access'} = 'radio';
7621: $elements{$role.'_incrs'} = 'radio';
7622: if ($numstatustypes) {
7623: $elements{$role.'_status'} = 'checkbox';
7624: }
7625: if (keys(%domhelpdesk) > 0) {
7626: $elements{$role.'_staff_inc'} = 'checkbox';
7627: $elements{$role.'_staff_exc'} = 'checkbox';
7628: }
1.430 raeburn 7629: $elements{$role.'_override'} = 'checkbox';
1.428 raeburn 7630: if (ref($settings{$role}) eq 'HASH') {
7631: if ($settings{$role}{'access'} ne '') {
7632: my $curraccess = $settings{$role}{'access'};
7633: $stored{$role.'_access'} = $curraccess;
7634: $stored{$role.'_incrs'} = 1;
7635: if ($curraccess eq 'status') {
7636: if (ref($settings{$role}{'status'}) eq 'ARRAY') {
7637: $stored{$role.'_status'} = $settings{$role}{'status'};
7638: }
7639: } elsif (($curraccess eq 'exc') || ($curraccess eq 'inc')) {
7640: if (ref($settings{$role}{$curraccess}) eq 'ARRAY') {
7641: $stored{$role.'_staff_'.$curraccess} = $settings{$role}{$curraccess};
7642: }
7643: }
7644: } else {
7645: $stored{$role.'_incrs'} = 0;
7646: }
7647: $stored{$role.'_override'} = [];
7648: if ($env{'course.'.$env{'request.course.id'}.'.internal.adhocpriv.'.$role}) {
7649: if (ref($settings{$role}{'off'}) eq 'ARRAY') {
7650: foreach my $priv (@{$settings{$role}{'off'}}) {
7651: push(@{$stored{$role.'_override'}},$priv);
7652: }
7653: }
7654: if (ref($settings{$role}{'on'}) eq 'ARRAY') {
7655: foreach my $priv (@{$settings{$role}{'on'}}) {
7656: unless (grep(/^$priv$/,@{$stored{$role.'_override'}})) {
7657: push(@{$stored{$role.'_override'}},$priv);
7658: }
7659: }
7660: }
7661: }
7662: } else {
7663: $stored{$role.'_incrs'} = 0;
7664: }
7665: }
7666: $jscript = &Apache::lonhtmlcommon::set_form_elements(\%elements,\%stored);
7667: }
7668:
7669: my $js = <<"ENDJS";
7670: <script type="text/javascript">
7671: // <![CDATA[
7672: $jscript;
7673:
7674: function switchRoleTab(caller,role) {
7675: if (document.getElementById(role+'_maindiv')) {
7676: if (caller.id != 'LC_current_minitab') {
7677: if (document.getElementById('LC_current_minitab')) {
7678: document.getElementById('LC_current_minitab').id=null;
7679: }
7680: var roledivs = Array('$rolestr');
7681: if (roledivs.length > 0) {
7682: for (var i=0; i<roledivs.length; i++) {
7683: if (document.getElementById(roledivs[i]+'_maindiv')) {
7684: document.getElementById(roledivs[i]+'_maindiv').style.display='none';
7685: }
7686: }
7687: }
7688: caller.id = 'LC_current_minitab';
7689: document.getElementById(role+'_maindiv').style.display='block';
7690: }
7691: }
7692: return false;
1.430 raeburn 7693: }
1.428 raeburn 7694:
7695: function helpdeskAccess(role) {
7696: var curraccess = null;
7697: if (document.$formname.elements[role+'_access'].length) {
7698: for (var i=0; i<document.$formname.elements[role+'_access'].length; i++) {
7699: if (document.$formname.elements[role+'_access'][i].checked) {
7700: curraccess = document.$formname.elements[role+'_access'][i].value;
7701: }
7702: }
7703: }
7704: var shown = Array();
7705: var hidden = Array();
7706: if (curraccess == 'none') {
1.430 raeburn 7707: hidden = Array ('$hiddenstr');
1.428 raeburn 7708: } else {
7709: if (curraccess == 'status') {
1.430 raeburn 7710: shown = Array ('bystatus','privs');
7711: hidden = Array ('notinc','notexc');
1.428 raeburn 7712: } else {
7713: if (curraccess == 'exc') {
7714: shown = Array ('notexc','privs');
7715: hidden = Array ('notinc','bystatus');
7716: }
7717: if (curraccess == 'inc') {
7718: shown = Array ('notinc','privs');
7719: hidden = Array ('notexc','bystatus');
7720: }
7721: if (curraccess == 'all') {
7722: shown = Array ('privs');
7723: hidden = Array ('notinc','notexc','bystatus');
7724: }
7725: }
7726: }
7727: if (hidden.length > 0) {
7728: for (var i=0; i<hidden.length; i++) {
7729: if (document.getElementById(role+'_'+hidden[i])) {
1.430 raeburn 7730: document.getElementById(role+'_'+hidden[i]).style.display = 'none';
1.428 raeburn 7731: }
7732: }
7733: }
7734: if (shown.length > 0) {
7735: for (var i=0; i<shown.length; i++) {
7736: if (document.getElementById(role+'_'+shown[i])) {
7737: if (shown[i] == 'privs') {
7738: document.getElementById(role+'_'+shown[i]).style.display = 'block';
7739: } else {
7740: document.getElementById(role+'_'+shown[i]).style.display = 'inline';
7741: }
7742: }
7743: }
7744: }
7745: return;
7746: }
7747:
7748: function toggleAccess(role) {
7749: if ((document.getElementById(role+'_setincrs')) &&
7750: (document.getElementById(role+'_setindom'))) {
7751: for (var i=0; i<document.$formname.elements[role+'_incrs'].length; i++) {
7752: if (document.$formname.elements[role+'_incrs'][i].checked) {
7753: if (document.$formname.elements[role+'_incrs'][i].value == 1) {
7754: document.getElementById(role+'_setindom').style.display = 'none';
1.430 raeburn 7755: document.getElementById(role+'_setincrs').style.display = 'block';
1.428 raeburn 7756: } else {
7757: document.getElementById(role+'_setincrs').style.display = 'none';
7758: document.getElementById(role+'_setindom').style.display = 'block';
7759: }
7760: break;
7761: }
7762: }
7763: }
7764: return;
7765: }
7766:
7767: // ]]>
7768: </script>
7769: ENDJS
7770:
7771: $args->{add_entries} = {onload => "javascript:setFormElements(document.$formname)"};
7772:
7773: # print page header
7774: $r->print(&header($js,$args));
7775: # print form header
7776: $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">');
7777:
7778: if (keys(%customroles)) {
7779: my %lt = &Apache::lonlocal::texthash(
7780: 'aco' => 'As course owner you may override the defaults set in the domain for role usage and/or privileges.',
7781: 'rou' => 'Role usage',
7782: 'whi' => 'Which helpdesk personnel may use this role?',
7783: 'udd' => 'Use domain default',
1.433 raeburn 7784: 'all' => 'All with domain helpdesk or helpdesk assistant role',
1.434 raeburn 7785: 'dh' => 'All with domain helpdesk role',
7786: 'da' => 'All with domain helpdesk assistant role',
1.428 raeburn 7787: 'none' => 'None',
7788: 'status' => 'Determined based on institutional status',
1.430 raeburn 7789: 'inc' => 'Include all, but exclude specific personnel',
1.428 raeburn 7790: 'exc' => 'Exclude all, but include specific personnel',
7791: 'hel' => 'Helpdesk',
7792: 'rpr' => 'Role privileges',
7793: );
7794: $lt{'tfh'} = &mt("Custom [_1]ad hoc[_2] course roles available for use by the domain's helpdesk are as follows",'<i>','</i>');
7795: my %domconfig = &Apache::lonnet::get_dom('configuration',['helpsettings'],$cdom);
7796: my (%domcurrent,%ordered,%description,%domusage,$disabled);
7797: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
7798: if (ref($domconfig{'helpsettings'}{'adhoc'}) eq 'HASH') {
7799: %domcurrent = %{$domconfig{'helpsettings'}{'adhoc'}};
7800: }
7801: }
7802: my $count = 0;
7803: foreach my $role (sort(keys(%customroles))) {
7804: my ($order,$desc,$access_in_dom);
7805: if (ref($domcurrent{$role}) eq 'HASH') {
7806: $order = $domcurrent{$role}{'order'};
7807: $desc = $domcurrent{$role}{'desc'};
7808: $access_in_dom = $domcurrent{$role}{'access'};
7809: }
7810: if ($order eq '') {
7811: $order = $count;
7812: }
7813: $ordered{$order} = $role;
7814: if ($desc ne '') {
7815: $description{$role} = $desc;
7816: } else {
7817: $description{$role}= $role;
7818: }
7819: $count++;
7820: }
7821: %domusage = &domain_adhoc_access(\%customroles,\%domcurrent,\@accesstypes,$usertypes,$othertitle);
7822: my @roles_by_num = ();
7823: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
7824: push(@roles_by_num,$ordered{$item});
1.430 raeburn 7825: }
1.429 raeburn 7826: $r->print('<p>'.$lt{'tfh'}.': <i>'.join('</i>, <i>',map { $description{$_}; } @roles_by_num).'</i>.');
1.428 raeburn 7827: if ($permission->{'owner'}) {
7828: $r->print('<br />'.$lt{'aco'}.'</p><p>');
7829: $r->print('<input type="hidden" name="state" value="process" />'.
7830: '<input type="submit" value="'.&mt('Save changes').'" />');
7831: } else {
7832: if ($env{'course.'.$env{'request.course.id'}.'.internal.courseowner'}) {
7833: my ($ownername,$ownerdom) = split(/:/,$env{'course.'.$env{'request.course.id'}.'.internal.courseowner'});
7834: $r->print('<br />'.&mt('The course owner -- [_1] -- can override the default access and/or privileges for these ad hoc roles.',
7835: &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($ownername,$ownerdom),$ownername,$ownerdom)));
7836: }
7837: $disabled = ' disabled="disabled"';
7838: }
7839: $r->print('</p>');
7840:
7841: $r->print('<div id="LC_minitab_header"><ul>');
7842: my $count = 0;
7843: my %visibility;
7844: foreach my $role (@roles_by_num) {
7845: my $id;
7846: if ($count == 0) {
7847: $id=' id="LC_current_minitab"';
1.430 raeburn 7848: $visibility{$role} = ' style="display:block"';
1.428 raeburn 7849: } else {
7850: $visibility{$role} = ' style="display:none"';
7851: }
7852: $count ++;
7853: $r->print('<li'.$id.'><a href="#" onclick="javascript:switchRoleTab(this.parentNode,'."'$role'".');">'.$description{$role}.'</a></li>');
7854: }
7855: $r->print('</ul></div>');
7856:
7857: foreach my $role (@roles_by_num) {
7858: my %usecheck = (
7859: all => ' checked="checked"',
7860: );
7861: my %displaydiv = (
7862: status => 'none',
7863: inc => 'none',
7864: exc => 'none',
7865: priv => 'block',
7866: );
7867: my (%selected,$overridden,$incrscheck,$indomcheck,$indomvis,$incrsvis);
1.430 raeburn 7868: if (ref($settings{$role}) eq 'HASH') {
1.428 raeburn 7869: if ($settings{$role}{'access'} ne '') {
7870: $indomvis = ' style="display:none"';
7871: $incrsvis = ' style="display:block"';
1.430 raeburn 7872: $incrscheck = ' checked="checked"';
1.428 raeburn 7873: if ($settings{$role}{'access'} ne 'all') {
7874: $usecheck{$settings{$role}{'access'}} = $usecheck{'all'};
7875: delete($usecheck{'all'});
7876: if ($settings{$role}{'access'} eq 'status') {
7877: my $access = 'status';
7878: $displaydiv{$access} = 'inline';
7879: if (ref($settings{$role}{$access}) eq 'ARRAY') {
7880: $selected{$access} = $settings{$role}{$access};
7881: }
7882: } elsif ($settings{$role}{'access'} =~ /^(inc|exc)$/) {
7883: my $access = $1;
7884: $displaydiv{$access} = 'inline';
7885: if (ref($settings{$role}{$access}) eq 'ARRAY') {
7886: $selected{$access} = $settings{$role}{$access};
7887: }
7888: } elsif ($settings{$role}{'access'} eq 'none') {
7889: $displaydiv{'priv'} = 'none';
7890: }
7891: }
7892: } else {
7893: $indomcheck = ' checked="checked"';
7894: $indomvis = ' style="display:block"';
7895: $incrsvis = ' style="display:none"';
7896: }
7897: } else {
7898: $indomcheck = ' checked="checked"';
1.430 raeburn 7899: $indomvis = ' style="display:block"';
1.428 raeburn 7900: $incrsvis = ' style="display:none"';
7901: }
7902: $r->print('<div class="LC_left_float" id="'.$role.'_maindiv"'.$visibility{$role}.'>'.
7903: '<fieldset><legend>'.$lt{'rou'}.'</legend>'.
7904: '<p>'.$lt{'whi'}.' <span class="LC_nobreak">'.
7905: '<label><input type="radio" name="'.$role.'_incrs" value="1"'.$incrscheck.' onclick="toggleAccess('."'$role'".');"'.$disabled.'>'.
7906: &mt('Set here in [_1]',lc($crstype)).'</label>'.
7907: '<span>'.(' 'x2).
7908: '<label><input type="radio" name="'.$role.'_incrs" value="0"'.$indomcheck.' onclick="toggleAccess('."'$role'".');"'.$disabled.'>'.
7909: $lt{'udd'}.'</label><span></p>'.
7910: '<div id="'.$role.'_setindom"'.$indomvis.'>'.
7911: '<span class="LC_cusr_emph">'.$domusage{$role}.'</span></div>'.
7912: '<div id="'.$role.'_setincrs"'.$incrsvis.'>');
7913: foreach my $access (@accesstypes) {
7914: $r->print('<p><label><input type="radio" name="'.$role.'_access" value="'.$access.'" '.$usecheck{$access}.
7915: ' onclick="helpdeskAccess('."'$role'".');"'.$disabled.' />'.$lt{$access}.'</label>');
7916: if ($access eq 'status') {
7917: $r->print('<div id="'.$role.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
7918: &Apache::lonuserutils::adhoc_status_types($cdom,undef,$role,$selected{$access},
7919: $othertitle,$usertypes,$types,$disabled).
7920: '</div>');
7921: } elsif (($access eq 'inc') && (keys(%domhelpdesk) > 0)) {
7922: $r->print('<div id="'.$role.'_notinc" style="display:'.$displaydiv{$access}.'">'.
7923: &Apache::lonuserutils::adhoc_staff($access,undef,$role,$selected{$access},
7924: \%domhelpdesk,$disabled).
7925: '</div>');
7926: } elsif (($access eq 'exc') && (keys(%domhelpdesk) > 0)) {
7927: $r->print('<div id="'.$role.'_notexc" style="display:'.$displaydiv{$access}.'">'.
7928: &Apache::lonuserutils::adhoc_staff($access,undef,$role,$selected{$access},
7929: \%domhelpdesk,$disabled).
7930: '</div>');
7931: }
7932: $r->print('</p>');
7933: }
7934: $r->print('</div></fieldset>');
7935: my %full=();
7936: my %levels= (
7937: course => {},
7938: domain => {},
7939: system => {},
7940: );
7941: my %levelscurrent=(
7942: course => {},
7943: domain => {},
7944: system => {},
7945: );
7946: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
7947: $r->print('<fieldset id="'.$role.'_privs" style="display:'.$displaydiv{'priv'}.'">'.
7948: '<legend>'.$lt{'rpr'}.'</legend>'.
7949: &role_priv_table($role,$permission,$crstype,\%full,\%levels,\%levelscurrent,$overridden{$role}).
7950: '</fieldset></div><div style="padding:0;clear:both;margin:0;border:0"></div>');
7951: }
1.429 raeburn 7952: if ($permission->{'owner'}) {
7953: $r->print('<p><input type="submit" value="'.&mt('Save changes').'" /></p>');
7954: }
1.428 raeburn 7955: } else {
7956: $r->print(&mt('Helpdesk roles have not yet been created in this domain.'));
7957: }
7958: # Form Footer
7959: $r->print('<input type="hidden" name="action" value="helpdesk" />'
7960: .'</form>');
7961: return;
7962: }
7963:
7964: sub domain_adhoc_access {
7965: my ($roles,$domcurrent,$accesstypes,$usertypes,$othertitle) = @_;
7966: my %domusage;
7967: return unless ((ref($roles) eq 'HASH') && (ref($domcurrent) eq 'HASH') && (ref($accesstypes) eq 'ARRAY'));
7968: foreach my $role (keys(%{$roles})) {
7969: if (ref($domcurrent->{$role}) eq 'HASH') {
7970: my $access = $domcurrent->{$role}{'access'};
7971: if (($access eq '') || (!grep(/^\Q$access\E$/,@{$accesstypes}))) {
7972: $access = 'all';
1.432 raeburn 7973: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role',&Apache::lonnet::plaintext('dh'),
7974: &Apache::lonnet::plaintext('da'));
1.428 raeburn 7975: } elsif ($access eq 'status') {
7976: if (ref($domcurrent->{$role}{$access}) eq 'ARRAY') {
7977: my @shown;
7978: foreach my $type (@{$domcurrent->{$role}{$access}}) {
7979: unless ($type eq 'default') {
7980: if ($usertypes->{$type}) {
7981: push(@shown,$usertypes->{$type});
7982: }
7983: }
7984: }
7985: if (grep(/^default$/,@{$domcurrent->{$role}{$access}})) {
7986: push(@shown,$othertitle);
7987: }
7988: if (@shown) {
7989: my $shownstatus = join(' '.&mt('or').' ',@shown);
1.432 raeburn 7990: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role, and institutional status: [_3]',
7991: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'),$shownstatus);
1.428 raeburn 7992: } else {
7993: $domusage{$role} = &mt('No one in the domain');
7994: }
7995: }
7996: } elsif ($access eq 'inc') {
7997: my @dominc = ();
7998: if (ref($domcurrent->{$role}{'inc'}) eq 'ARRAY') {
7999: foreach my $user (@{$domcurrent->{$role}{'inc'}}) {
8000: my ($uname,$udom) = split(/:/,$user);
8001: push(@dominc,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),$uname,$udom));
8002: }
8003: my $showninc = join(', ',@dominc);
8004: if ($showninc ne '') {
1.432 raeburn 8005: $domusage{$role} = &mt('Include any user in domain with active [_1] or [_2] role, except: [_3]',
8006: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'),$showninc);
1.428 raeburn 8007: } else {
1.432 raeburn 8008: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role',
8009: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'));
1.428 raeburn 8010: }
8011: }
8012: } elsif ($access eq 'exc') {
8013: my @domexc = ();
8014: if (ref($domcurrent->{$role}{'exc'}) eq 'ARRAY') {
8015: foreach my $user (@{$domcurrent->{$role}{'exc'}}) {
8016: my ($uname,$udom) = split(/:/,$user);
8017: push(@domexc,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),$uname,$udom));
8018: }
8019: }
8020: my $shownexc = join(', ',@domexc);
8021: if ($shownexc ne '') {
1.432 raeburn 8022: $domusage{$role} = &mt('Only the following in the domain with active [_1] or [_2] role: [_3]',
8023: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'),$shownexc);
1.428 raeburn 8024: } else {
8025: $domusage{$role} = &mt('No one in the domain');
8026: }
8027: } elsif ($access eq 'none') {
8028: $domusage{$role} = &mt('No one in the domain');
1.434 raeburn 8029: } elsif ($access eq 'dh') {
1.433 raeburn 8030: $domusage{$role} = &mt('Any user in domain with active [_1] role',&Apache::lonnet::plaintext('dh'));
1.434 raeburn 8031: } elsif ($access eq 'da') {
1.433 raeburn 8032: $domusage{$role} = &mt('Any user in domain with active [_1] role',&Apache::lonnet::plaintext('da'));
1.428 raeburn 8033: } elsif ($access eq 'all') {
1.432 raeburn 8034: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role',
8035: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'));
1.428 raeburn 8036: }
8037: } else {
1.432 raeburn 8038: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role',
8039: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'));
1.428 raeburn 8040: }
8041: }
8042: return %domusage;
8043: }
8044:
8045: sub get_domain_customroles {
8046: my ($cdom,$confname) = @_;
8047: my %existing=&Apache::lonnet::dump('roles',$cdom,$confname,'rolesdef_');
8048: my %customroles;
8049: foreach my $key (keys(%existing)) {
8050: if ($key=~/^rolesdef\_(\w+)$/) {
8051: my $rolename = $1;
8052: my %privs;
8053: ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
8054: $customroles{$rolename} = \%privs;
8055: }
8056: }
8057: return %customroles;
8058: }
8059:
8060: sub role_priv_table {
8061: my ($role,$permission,$crstype,$full,$levels,$levelscurrent,$overridden) = @_;
8062: return unless ((ref($full) eq 'HASH') && (ref($levels) eq 'HASH') &&
8063: (ref($levelscurrent) eq 'HASH'));
8064: my %lt=&Apache::lonlocal::texthash (
8065: 'crl' => 'Course Level Privilege',
8066: 'def' => 'Domain Defaults',
8067: 'ove' => 'Override in Course',
8068: 'ine' => 'In effect',
8069: 'dis' => 'Disabled',
8070: 'ena' => 'Enabled',
8071: );
8072: if ($crstype eq 'Community') {
8073: $lt{'ove'} = 'Override in Community',
8074: }
8075: my @status = ('Disabled','Enabled');
8076: my (%on,%off);
8077: if (ref($overridden) eq 'HASH') {
8078: if (ref($overridden->{'on'}) eq 'ARRAY') {
8079: map { $on{$_} = 1; } (@{$overridden->{'on'}});
8080: }
8081: if (ref($overridden->{'off'}) eq 'ARRAY') {
8082: map { $off{$_} = 1; } (@{$overridden->{'off'}});
8083: }
8084: }
8085: my $output=&Apache::loncommon::start_data_table().
8086: &Apache::loncommon::start_data_table_header_row().
8087: '<th>'.$lt{'crl'}.'</th><th>'.$lt{'def'}.'</th><th>'.$lt{'ove'}.
8088: '</th><th>'.$lt{'ine'}.'</th>'.
8089: &Apache::loncommon::end_data_table_header_row();
8090: foreach my $priv (sort(keys(%{$full}))) {
8091: next unless ($levels->{'course'}{$priv});
8092: my $privtext = &Apache::lonnet::plaintext($priv,$crstype);
8093: my ($default,$ineffect);
8094: if ($levelscurrent->{'course'}{$priv}) {
8095: $default = '<img src="/adm/lonIcons/navmap.correct.gif" alt="'.$lt{'ena'}.'" />';
8096: $ineffect = $default;
8097: }
8098: my ($customstatus,$checked);
8099: $output .= &Apache::loncommon::start_data_table_row().
8100: '<td>'.$privtext.'</td>'.
8101: '<td>'.$default.'</td><td>';
8102: if (($levelscurrent->{'course'}{$priv}) && ($off{$priv})) {
8103: if ($permission->{'owner'}) {
8104: $checked = ' checked="checked"';
8105: }
8106: $customstatus = '<img src="/adm/lonIcons/navmap.wrong.gif" alt="'.$lt{'dis'}.'" />';
1.430 raeburn 8107: $ineffect = $customstatus;
1.428 raeburn 8108: } elsif ((!$levelscurrent->{'course'}{$priv}) && ($on{$priv})) {
8109: if ($permission->{'owner'}) {
1.430 raeburn 8110: $checked = ' checked="checked"';
1.428 raeburn 8111: }
8112: $customstatus = '<img src="/adm/lonIcons/navmap.correct.gif" alt="'.$lt{'ena'}.'" />';
1.430 raeburn 8113: $ineffect = $customstatus;
1.428 raeburn 8114: }
8115: if ($permission->{'owner'}) {
8116: $output .= '<input type="checkbox" name="'.$role.'_override" value="'.$priv.'"'.$checked.' />';
8117: } else {
8118: $output .= $customstatus;
8119: }
8120: $output .= '</td><td>'.$ineffect.'</td>'.
8121: &Apache::loncommon::end_data_table_row();
8122: }
8123: $output .= &Apache::loncommon::end_data_table();
8124: return $output;
8125: }
8126:
8127: sub get_adhocrole_settings {
1.430 raeburn 8128: my ($cid,$accesstypes,$types,$customroles,$settings,$overridden) = @_;
1.428 raeburn 8129: return unless ((ref($accesstypes) eq 'ARRAY') && (ref($customroles) eq 'HASH') &&
8130: (ref($settings) eq 'HASH') && (ref($overridden) eq 'HASH'));
8131: foreach my $role (split(/,/,$env{'course.'.$cid.'.internal.adhocaccess'})) {
8132: my ($curraccess,$rest) = split(/=/,$env{'course.'.$cid.'.internal.adhoc.'.$role});
8133: if (($curraccess ne '') && (grep(/^\Q$curraccess\E$/,@{$accesstypes}))) {
8134: $settings->{$role}{'access'} = $curraccess;
8135: if (($curraccess eq 'status') && (ref($types) eq 'ARRAY')) {
8136: my @status = split(/,/,$rest);
8137: my @currstatus;
8138: foreach my $type (@status) {
8139: if ($type eq 'default') {
8140: push(@currstatus,$type);
8141: } elsif (grep(/^\Q$type\E$/,@{$types})) {
8142: push(@currstatus,$type);
8143: }
8144: }
8145: if (@currstatus) {
8146: $settings->{$role}{$curraccess} = \@currstatus;
8147: } elsif (($curraccess eq 'exc') || ($curraccess eq 'inc')) {
8148: my @personnel = split(/,/,$rest);
8149: $settings->{$role}{$curraccess} = \@personnel;
8150: }
8151: }
8152: }
8153: }
8154: foreach my $role (keys(%{$customroles})) {
8155: if ($env{'course.'.$cid.'.internal.adhocpriv.'.$role}) {
8156: my %currentprivs;
8157: if (ref($customroles->{$role}) eq 'HASH') {
8158: if (exists($customroles->{$role}{'course'})) {
8159: my %full=();
8160: my %levels= (
8161: course => {},
8162: domain => {},
8163: system => {},
8164: );
8165: my %levelscurrent=(
8166: course => {},
8167: domain => {},
8168: system => {},
8169: );
8170: &Apache::lonuserutils::custom_role_privs($customroles->{$role},\%full,\%levels,\%levelscurrent);
8171: %currentprivs = %{$levelscurrent{'course'}};
8172: }
8173: }
8174: foreach my $item (split(/,/,$env{'course.'.$cid.'.internal.adhocpriv.'.$role})) {
8175: next if ($item eq '');
8176: my ($rule,$rest) = split(/=/,$item);
8177: next unless (($rule eq 'off') || ($rule eq 'on'));
8178: foreach my $priv (split(/:/,$rest)) {
8179: if ($priv ne '') {
8180: if ($rule eq 'off') {
8181: push(@{$overridden->{$role}{'off'}},$priv);
8182: if ($currentprivs{$priv}) {
8183: push(@{$settings->{$role}{'off'}},$priv);
8184: }
8185: } else {
8186: push(@{$overridden->{$role}{'on'}},$priv);
8187: unless ($currentprivs{$priv}) {
8188: push(@{$settings->{$role}{'on'}},$priv);
8189: }
8190: }
8191: }
8192: }
8193: }
8194: }
8195: }
8196: return;
8197: }
8198:
8199: sub update_helpdeskaccess {
8200: my ($r,$permission,$brcrum) = @_;
8201: my $helpitem = 'Course_Helpdesk_Access';
8202: push (@{$brcrum},
8203: {href => '/adm/createuser?action=helpdesk',
8204: text => 'Helpdesk Access',
8205: help => $helpitem},
8206: {href => '/adm/createuser?action=helpdesk',
8207: text => 'Result',
8208: help => $helpitem}
8209: );
8210: my $bread_crumbs_component = 'Helpdesk Staff Access';
8211: my $args = { bread_crumbs => $brcrum,
8212: bread_crumbs_component => $bread_crumbs_component};
8213:
8214: # print page header
8215: $r->print(&header('',$args));
8216: unless ((ref($permission) eq 'HASH') && ($permission->{'owner'})) {
8217: $r->print('<p class="LC_error">'.&mt('You do not have permission to change helpdesk access.').'</p>');
8218: return;
8219: }
1.434 raeburn 8220: my @accesstypes = ('all','dh','da','none','status','inc','exc');
1.428 raeburn 8221: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
8222: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
8223: my $confname = $cdom.'-domainconfig';
8224: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($cdom);
8225: my $crstype = &Apache::loncommon::course_type();
8226: my %customroles = &get_domain_customroles($cdom,$confname);
8227: my (%settings,%overridden);
8228: &get_adhocrole_settings($env{'request.course.id'},\@accesstypes,
8229: $types,\%customroles,\%settings,\%overridden);
1.432 raeburn 8230: my %domhelpdesk = &Apache::lonnet::get_active_domroles($cdom,['dh','da']);
1.428 raeburn 8231: my (%changed,%storehash,@todelete);
8232:
8233: if (keys(%customroles)) {
8234: my (%newsettings,@incrs);
8235: foreach my $role (keys(%customroles)) {
8236: $newsettings{$role} = {
8237: access => '',
8238: status => '',
8239: exc => '',
8240: inc => '',
8241: on => '',
8242: off => '',
8243: };
8244: my %current;
8245: if (ref($settings{$role}) eq 'HASH') {
8246: %current = %{$settings{$role}};
8247: }
8248: if (ref($overridden{$role}) eq 'HASH') {
8249: $current{'overridden'} = $overridden{$role};
8250: }
8251: if ($env{'form.'.$role.'_incrs'}) {
8252: my $access = $env{'form.'.$role.'_access'};
8253: if (grep(/^\Q$access\E$/,@accesstypes)) {
8254: push(@incrs,$role);
8255: unless ($current{'access'} eq $access) {
8256: $changed{$role}{'access'} = 1;
1.430 raeburn 8257: $storehash{'internal.adhoc.'.$role} = $access;
1.428 raeburn 8258: }
8259: if ($access eq 'status') {
8260: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$role.'_status');
8261: my @stored;
8262: my @shownstatus;
8263: if (ref($types) eq 'ARRAY') {
8264: foreach my $type (sort(@statuses)) {
8265: if ($type eq 'default') {
8266: push(@stored,$type);
8267: } elsif (grep(/^\Q$type\E$/,@{$types})) {
8268: push(@stored,$type);
8269: push(@shownstatus,$usertypes->{$type});
8270: }
8271: }
8272: if (grep(/^default$/,@statuses)) {
8273: push(@shownstatus,$othertitle);
8274: }
8275: $storehash{'internal.adhoc.'.$role} .= '='.join(',',@stored);
8276: }
8277: $newsettings{$role}{'status'} = join(' '.&mt('or').' ',@shownstatus);
8278: if (ref($current{'status'}) eq 'ARRAY') {
8279: my @diffs = &Apache::loncommon::compare_arrays(\@stored,$current{'status'});
8280: if (@diffs) {
8281: $changed{$role}{'status'} = 1;
8282: }
8283: } elsif (@stored) {
8284: $changed{$role}{'status'} = 1;
8285: }
8286: } elsif (($access eq 'inc') || ($access eq 'exc')) {
8287: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$role.'_staff_'.$access);
8288: my @newspecstaff;
8289: my @stored;
8290: my @currstaff;
8291: foreach my $person (sort(@personnel)) {
8292: if ($domhelpdesk{$person}) {
1.430 raeburn 8293: push(@stored,$person);
1.428 raeburn 8294: }
8295: }
8296: if (ref($current{$access}) eq 'ARRAY') {
8297: my @diffs = &Apache::loncommon::compare_arrays(\@stored,$current{$access});
8298: if (@diffs) {
8299: $changed{$role}{$access} = 1;
8300: }
8301: } elsif (@stored) {
8302: $changed{$role}{$access} = 1;
8303: }
8304: $storehash{'internal.adhoc.'.$role} .= '='.join(',',@stored);
8305: foreach my $person (@stored) {
8306: my ($uname,$udom) = split(/:/,$person);
8307: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
8308: }
8309: $newsettings{$role}{$access} = join(', ',sort(@newspecstaff));
8310: }
8311: $newsettings{$role}{'access'} = $access;
8312: }
8313: } else {
8314: if (($current{'access'} ne '') && (grep(/^\Q$current{'access'}\E$/,@accesstypes))) {
8315: $changed{$role}{'access'} = 1;
8316: $newsettings{$role} = {};
8317: push(@todelete,'internal.adhoc.'.$role);
8318: }
8319: }
8320: if (($env{'form.'.$role.'_incrs'}) && ($env{'form.'.$role.'_access'} eq 'none')) {
8321: if (ref($current{'overridden'}) eq 'HASH') {
8322: push(@todelete,'internal.adhocpriv.'.$role);
8323: }
8324: } else {
8325: my %full=();
8326: my %levels= (
8327: course => {},
8328: domain => {},
8329: system => {},
8330: );
8331: my %levelscurrent=(
8332: course => {},
8333: domain => {},
8334: system => {},
8335: );
8336: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
8337: my (@updatedon,@updatedoff,@override);
8338: @override = &Apache::loncommon::get_env_multiple('form.'.$role.'_override');
1.430 raeburn 8339: if (@override) {
1.428 raeburn 8340: foreach my $priv (sort(keys(%full))) {
8341: next unless ($levels{'course'}{$priv});
8342: if (grep(/^\Q$priv\E$/,@override)) {
8343: if ($levelscurrent{'course'}{$priv}) {
8344: push(@updatedoff,$priv);
8345: } else {
8346: push(@updatedon,$priv);
8347: }
8348: }
8349: }
8350: }
8351: if (@updatedon) {
1.430 raeburn 8352: $newsettings{$role}{'on'} = join('</li><li>', map { &Apache::lonnet::plaintext($_,$crstype) } (@updatedon));
1.428 raeburn 8353: }
8354: if (@updatedoff) {
8355: $newsettings{$role}{'off'} = join('</li><li>', map { &Apache::lonnet::plaintext($_,$crstype) } (@updatedoff));
8356: }
8357: if (ref($current{'overridden'}) eq 'HASH') {
8358: if (ref($current{'overridden'}{'on'}) eq 'ARRAY') {
8359: if (@updatedon) {
8360: my @diffs = &Apache::loncommon::compare_arrays(\@updatedon,$current{'overridden'}{'on'});
8361: if (@diffs) {
8362: $changed{$role}{'on'} = 1;
8363: }
8364: } else {
8365: $changed{$role}{'on'} = 1;
8366: }
8367: } elsif (@updatedon) {
8368: $changed{$role}{'on'} = 1;
8369: }
8370: if (ref($current{'overridden'}{'off'}) eq 'ARRAY') {
8371: if (@updatedoff) {
8372: my @diffs = &Apache::loncommon::compare_arrays(\@updatedoff,$current{'overridden'}{'off'});
8373: if (@diffs) {
8374: $changed{$role}{'off'} = 1;
8375: }
8376: } else {
8377: $changed{$role}{'off'} = 1;
8378: }
8379: } elsif (@updatedoff) {
8380: $changed{$role}{'off'} = 1;
8381: }
8382: } else {
8383: if (@updatedon) {
8384: $changed{$role}{'on'} = 1;
8385: }
8386: if (@updatedoff) {
8387: $changed{$role}{'off'} = 1;
8388: }
8389: }
8390: if (ref($changed{$role}) eq 'HASH') {
8391: if (($changed{$role}{'on'} || $changed{$role}{'off'})) {
8392: my $newpriv;
8393: if (@updatedon) {
8394: $newpriv = 'on='.join(':',@updatedon);
8395: }
8396: if (@updatedoff) {
8397: $newpriv .= ($newpriv ? ',' : '' ).'off='.join(':',@updatedoff);
8398: }
8399: if ($newpriv eq '') {
8400: push(@todelete,'internal.adhocpriv.'.$role);
8401: } else {
8402: $storehash{'internal.adhocpriv.'.$role} = $newpriv;
8403: }
8404: }
8405: }
8406: }
8407: }
8408: if (@incrs) {
8409: $storehash{'internal.adhocaccess'} = join(',',@incrs);
8410: } elsif (@todelete) {
8411: push(@todelete,'internal.adhocaccess');
8412: }
8413: if (keys(%changed)) {
8414: my ($putres,$delres);
8415: if (keys(%storehash)) {
8416: $putres = &Apache::lonnet::put('environment',\%storehash,$cdom,$cnum);
8417: my %newenvhash;
8418: foreach my $key (keys(%storehash)) {
8419: $newenvhash{'course.'.$env{'request.course.id'}.'.'.$key} = $storehash{$key};
8420: }
8421: &Apache::lonnet::appenv(\%newenvhash);
8422: }
8423: if (@todelete) {
8424: $delres = &Apache::lonnet::del('environment',\@todelete,$cdom,$cnum);
8425: foreach my $key (@todelete) {
8426: &Apache::lonnet::delenv('course.'.$env{'request.course.id'}.'.'.$key);
8427: }
8428: }
8429: if (($putres eq 'ok') || ($delres eq 'ok')) {
8430: my %domconfig = &Apache::lonnet::get_dom('configuration',['helpsettings'],$cdom);
8431: my (%domcurrent,%ordered,%description,%domusage);
8432: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
8433: if (ref($domconfig{'helpsettings'}{'adhoc'}) eq 'HASH') {
8434: %domcurrent = %{$domconfig{'helpsettings'}{'adhoc'}};
8435: }
8436: }
8437: my $count = 0;
8438: foreach my $role (sort(keys(%customroles))) {
8439: my ($order,$desc);
8440: if (ref($domcurrent{$role}) eq 'HASH') {
8441: $order = $domcurrent{$role}{'order'};
8442: $desc = $domcurrent{$role}{'desc'};
8443: }
8444: if ($order eq '') {
8445: $order = $count;
8446: }
8447: $ordered{$order} = $role;
8448: if ($desc ne '') {
8449: $description{$role} = $desc;
8450: } else {
8451: $description{$role}= $role;
8452: }
8453: $count++;
8454: }
8455: my @roles_by_num = ();
8456: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
8457: push(@roles_by_num,$ordered{$item});
8458: }
8459: %domusage = &domain_adhoc_access(\%changed,\%domcurrent,\@accesstypes,$usertypes,$othertitle);
1.430 raeburn 8460: $r->print(&mt('Helpdesk access settings have been changed as follows').'<br />');
1.428 raeburn 8461: $r->print('<ul>');
8462: foreach my $role (@roles_by_num) {
8463: next unless (ref($changed{$role}) eq 'HASH');
8464: $r->print('<li>'.&mt('Ad hoc role').': <b>'.$description{$role}.'</b>'.
8465: '<ul>');
1.430 raeburn 8466: if ($changed{$role}{'access'} || $changed{$role}{'status'} || $changed{$role}{'inc'} || $changed{$role}{'exc'}) {
1.428 raeburn 8467: $r->print('<li>');
8468: if ($env{'form.'.$role.'_incrs'}) {
8469: if ($newsettings{$role}{'access'} eq 'all') {
8470: $r->print(&mt('All helpdesk staff can access '.lc($crstype).' with this role.'));
1.434 raeburn 8471: } elsif ($newsettings{$role}{'access'} eq 'dh') {
1.433 raeburn 8472: $r->print(&mt('Helpdesk staff can use this role if they have an active [_1] role',
8473: &Apache::lonnet::plaintext('dh')));
1.434 raeburn 8474: } elsif ($newsettings{$role}{'access'} eq 'da') {
1.433 raeburn 8475: $r->print(&mt('Helpdesk staff can use this role if they have an active [_1] role',
8476: &Apache::lonnet::plaintext('da')));
1.428 raeburn 8477: } elsif ($newsettings{$role}{'access'} eq 'none') {
8478: $r->print(&mt('No helpdesk staff can access '.lc($crstype).' with this role.'));
8479: } elsif ($newsettings{$role}{'access'} eq 'status') {
8480: if ($newsettings{$role}{'status'}) {
8481: my ($access,$rest) = split(/=/,$storehash{'internal.adhoc.'.$role});
1.430 raeburn 8482: if (split(/,/,$rest) > 1) {
1.428 raeburn 8483: $r->print(&mt('Helpdesk staff can use this role if their institutional type is one of: [_1].',
8484: $newsettings{$role}{'status'}));
8485: } else {
8486: $r->print(&mt('Helpdesk staff can use this role if their institutional type is: [_1].',
8487: $newsettings{$role}{'status'}));
8488: }
8489: } else {
8490: $r->print(&mt('No helpdesk staff can access '.lc($crstype).' with this role.'));
8491: }
8492: } elsif ($newsettings{$role}{'access'} eq 'exc') {
8493: if ($newsettings{$role}{'exc'}) {
8494: $r->print(&mt('Helpdesk staff who can use this role are as follows:').' '.$newsettings{$role}{'exc'}.'.');
8495: } else {
8496: $r->print(&mt('No helpdesk staff can access '.lc($crstype).' with this role.'));
8497: }
8498: } elsif ($newsettings{$role}{'access'} eq 'inc') {
8499: if ($newsettings{$role}{'inc'}) {
8500: $r->print(&mt('All helpdesk staff may use this role except the following:').' '.$newsettings{$role}{'inc'}.'.');
8501: } else {
8502: $r->print(&mt('All helpdesk staff may use this role.'));
8503: }
8504: }
8505: } else {
8506: $r->print(&mt('Default access set in the domain now applies.').'<br />'.
8507: '<span class="LC_cusr_emph">'.$domusage{$role}.'</span>');
8508: }
8509: $r->print('</li>');
8510: }
8511: unless ($newsettings{$role}{'access'} eq 'none') {
8512: if ($changed{$role}{'off'}) {
8513: if ($newsettings{$role}{'off'}) {
8514: $r->print('<li>'.&mt('Privileges which are available by default for this ad hoc role, but are disabled for this specific '.lc($crstype).':').
8515: '<ul><li>'.$newsettings{$role}{'off'}.'</li></ul></li>');
8516: } else {
1.430 raeburn 8517: $r->print('<li>'.&mt('All privileges available by default for this ad hoc role are enabled.').'</li>');
1.428 raeburn 8518: }
8519: }
1.430 raeburn 8520: if ($changed{$role}{'on'}) {
1.428 raeburn 8521: if ($newsettings{$role}{'on'}) {
8522: $r->print('<li>'.&mt('Privileges which are not available by default for this ad hoc role, but are enabled for this specific '.lc($crstype).':').
8523: '<ul><li>'.$newsettings{$role}{'on'}.'</li></ul></li>');
8524: } else {
1.430 raeburn 8525: $r->print('<li>'.&mt('None of the privileges unavailable by default for this ad hoc role are enabled.').'</li>');
1.428 raeburn 8526: }
8527: }
8528: }
8529: $r->print('</ul></li>');
8530: }
8531: $r->print('</ul>');
8532: }
8533: } else {
1.430 raeburn 8534: $r->print(&mt('No changes made to helpdesk access settings.'));
1.428 raeburn 8535: }
8536: }
8537: return;
8538: }
8539:
1.27 matthew 8540: #-------------------------------------------------- functions for &phase_two
1.160 raeburn 8541: sub user_search_result {
1.221 raeburn 8542: my ($context,$srch) = @_;
1.160 raeburn 8543: my %allhomes;
8544: my %inst_matches;
8545: my %srch_results;
1.181 raeburn 8546: my ($response,$currstate,$forcenewuser,$dirsrchres);
1.183 raeburn 8547: $srch->{'srchterm'} =~ s/\s+/ /g;
1.176 raeburn 8548: if ($srch->{'srchby'} !~ /^(uname|lastname|lastfirst)$/) {
1.160 raeburn 8549: $response = &mt('Invalid search.');
8550: }
8551: if ($srch->{'srchin'} !~ /^(crs|dom|alc|instd)$/) {
8552: $response = &mt('Invalid search.');
8553: }
1.177 raeburn 8554: if ($srch->{'srchtype'} !~ /^(exact|contains|begins)$/) {
1.160 raeburn 8555: $response = &mt('Invalid search.');
8556: }
8557: if ($srch->{'srchterm'} eq '') {
8558: $response = &mt('You must enter a search term.');
8559: }
1.183 raeburn 8560: if ($srch->{'srchterm'} =~ /^\s+$/) {
8561: $response = &mt('Your search term must contain more than just spaces.');
8562: }
1.160 raeburn 8563: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'instd')) {
8564: if (($srch->{'srchdomain'} eq '') ||
1.163 albertel 8565: ! (&Apache::lonnet::domain($srch->{'srchdomain'}))) {
1.160 raeburn 8566: $response = &mt('You must specify a valid domain when searching in a domain or institutional directory.')
8567: }
8568: }
8569: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs') ||
8570: ($srch->{'srchin'} eq 'alc')) {
1.176 raeburn 8571: if ($srch->{'srchby'} eq 'uname') {
1.243 raeburn 8572: my $unamecheck = $srch->{'srchterm'};
8573: if ($srch->{'srchtype'} eq 'contains') {
8574: if ($unamecheck !~ /^\w/) {
8575: $unamecheck = 'a'.$unamecheck;
8576: }
8577: }
8578: if ($unamecheck !~ /^$match_username$/) {
1.176 raeburn 8579: $response = &mt('You must specify a valid username. Only the following are allowed: letters numbers - . @');
8580: }
1.160 raeburn 8581: }
8582: }
1.180 raeburn 8583: if ($response ne '') {
1.413 raeburn 8584: $response = '<span class="LC_warning">'.$response.'</span><br />';
1.180 raeburn 8585: }
1.160 raeburn 8586: if ($srch->{'srchin'} eq 'instd') {
1.412 raeburn 8587: my $instd_chk = &instdirectorysrch_check($srch);
1.160 raeburn 8588: if ($instd_chk ne 'ok') {
1.412 raeburn 8589: my $domd_chk = &domdirectorysrch_check($srch);
1.413 raeburn 8590: $response .= '<span class="LC_warning">'.$instd_chk.'</span><br />';
1.412 raeburn 8591: if ($domd_chk eq 'ok') {
1.435 raeburn 8592: $response .= &mt('You may want to search in the LON-CAPA domain instead of in the institutional directory.');
1.412 raeburn 8593: }
1.415 raeburn 8594: $response .= '<br />';
1.412 raeburn 8595: }
8596: } else {
1.417 raeburn 8597: unless (($context eq 'requestcrs') && ($srch->{'srchtype'} eq 'exact')) {
1.412 raeburn 8598: my $domd_chk = &domdirectorysrch_check($srch);
1.438 raeburn 8599: if (($domd_chk ne 'ok') && ($env{'form.action'} ne 'accesslogs')) {
1.412 raeburn 8600: my $instd_chk = &instdirectorysrch_check($srch);
1.413 raeburn 8601: $response .= '<span class="LC_warning">'.$domd_chk.'</span><br />';
1.412 raeburn 8602: if ($instd_chk eq 'ok') {
1.435 raeburn 8603: $response .= &mt('You may want to search in the institutional directory instead of in the LON-CAPA domain.');
1.412 raeburn 8604: }
1.415 raeburn 8605: $response .= '<br />';
1.412 raeburn 8606: }
1.160 raeburn 8607: }
8608: }
8609: if ($response ne '') {
1.180 raeburn 8610: return ($currstate,$response);
1.160 raeburn 8611: }
8612: if ($srch->{'srchby'} eq 'uname') {
8613: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs')) {
8614: if ($env{'form.forcenew'}) {
8615: if ($srch->{'srchdomain'} ne $env{'request.role.domain'}) {
8616: my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
8617: if ($uhome eq 'no_host') {
8618: my $domdesc = &Apache::lonnet::domain($env{'request.role.domain'},'description');
1.180 raeburn 8619: my $showdom = &display_domain_info($env{'request.role.domain'});
8620: $response = &mt('New users can only be created in the domain to which your current role belongs - [_1].',$showdom);
1.160 raeburn 8621: } else {
1.179 raeburn 8622: $currstate = 'modify';
1.160 raeburn 8623: }
8624: } else {
1.179 raeburn 8625: $currstate = 'modify';
1.160 raeburn 8626: }
8627: } else {
8628: if ($srch->{'srchin'} eq 'dom') {
1.162 raeburn 8629: if ($srch->{'srchtype'} eq 'exact') {
8630: my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
8631: if ($uhome eq 'no_host') {
1.179 raeburn 8632: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8633: &build_search_response($context,$srch,%srch_results);
1.162 raeburn 8634: } else {
1.179 raeburn 8635: $currstate = 'modify';
1.416 raeburn 8636: if ($env{'form.action'} eq 'accesslogs') {
8637: $currstate = 'activity';
8638: }
1.310 raeburn 8639: my $uname = $srch->{'srchterm'};
8640: my $udom = $srch->{'srchdomain'};
8641: $srch_results{$uname.':'.$udom} =
8642: { &Apache::lonnet::get('environment',
8643: ['firstname',
8644: 'lastname',
8645: 'permanentemail'],
8646: $udom,$uname)
8647: };
1.162 raeburn 8648: }
8649: } else {
8650: %srch_results = &Apache::lonnet::usersearch($srch);
1.179 raeburn 8651: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8652: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 8653: }
8654: } else {
1.167 albertel 8655: my $courseusers = &get_courseusers();
1.162 raeburn 8656: if ($srch->{'srchtype'} eq 'exact') {
1.167 albertel 8657: if (exists($courseusers->{$srch->{'srchterm'}.':'.$srch->{'srchdomain'}})) {
1.179 raeburn 8658: $currstate = 'modify';
1.162 raeburn 8659: } else {
1.179 raeburn 8660: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8661: &build_search_response($context,$srch,%srch_results);
1.162 raeburn 8662: }
1.160 raeburn 8663: } else {
1.167 albertel 8664: foreach my $user (keys(%$courseusers)) {
1.162 raeburn 8665: my ($cuname,$cudomain) = split(/:/,$user);
8666: if ($cudomain eq $srch->{'srchdomain'}) {
1.177 raeburn 8667: my $matched = 0;
8668: if ($srch->{'srchtype'} eq 'begins') {
8669: if ($cuname =~ /^\Q$srch->{'srchterm'}\E/i) {
8670: $matched = 1;
8671: }
8672: } else {
8673: if ($cuname =~ /\Q$srch->{'srchterm'}\E/i) {
8674: $matched = 1;
8675: }
8676: }
8677: if ($matched) {
1.167 albertel 8678: $srch_results{$user} =
8679: {&Apache::lonnet::get('environment',
8680: ['firstname',
8681: 'lastname',
1.194 albertel 8682: 'permanentemail'],
8683: $cudomain,$cuname)};
1.162 raeburn 8684: }
8685: }
8686: }
1.179 raeburn 8687: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8688: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 8689: }
8690: }
8691: }
8692: } elsif ($srch->{'srchin'} eq 'alc') {
1.179 raeburn 8693: $currstate = 'query';
1.160 raeburn 8694: } elsif ($srch->{'srchin'} eq 'instd') {
1.181 raeburn 8695: ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
8696: if ($dirsrchres eq 'ok') {
8697: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8698: &build_search_response($context,$srch,%srch_results);
1.181 raeburn 8699: } else {
8700: my $showdom = &display_domain_info($srch->{'srchdomain'});
8701: $response = '<span class="LC_warning">'.
8702: &mt('Institutional directory search is not available in domain: [_1]',$showdom).
8703: '</span><br />'.
1.435 raeburn 8704: &mt('You may want to search in the LON-CAPA domain instead of in the institutional directory.').
1.415 raeburn 8705: '<br />';
1.181 raeburn 8706: }
1.160 raeburn 8707: }
8708: } else {
8709: if ($srch->{'srchin'} eq 'dom') {
8710: %srch_results = &Apache::lonnet::usersearch($srch);
1.179 raeburn 8711: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8712: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 8713: } elsif ($srch->{'srchin'} eq 'crs') {
1.167 albertel 8714: my $courseusers = &get_courseusers();
8715: foreach my $user (keys(%$courseusers)) {
1.160 raeburn 8716: my ($uname,$udom) = split(/:/,$user);
8717: my %names = &Apache::loncommon::getnames($uname,$udom);
8718: my %emails = &Apache::loncommon::getemails($uname,$udom);
8719: if ($srch->{'srchby'} eq 'lastname') {
8720: if ((($srch->{'srchtype'} eq 'exact') &&
8721: ($names{'lastname'} eq $srch->{'srchterm'})) ||
1.177 raeburn 8722: (($srch->{'srchtype'} eq 'begins') &&
8723: ($names{'lastname'} =~ /^\Q$srch->{'srchterm'}\E/i)) ||
1.160 raeburn 8724: (($srch->{'srchtype'} eq 'contains') &&
8725: ($names{'lastname'} =~ /\Q$srch->{'srchterm'}\E/i))) {
8726: $srch_results{$user} = {firstname => $names{'firstname'},
8727: lastname => $names{'lastname'},
8728: permanentemail => $emails{'permanentemail'},
8729: };
8730: }
8731: } elsif ($srch->{'srchby'} eq 'lastfirst') {
8732: my ($srchlast,$srchfirst) = split(/,/,$srch->{'srchterm'});
1.177 raeburn 8733: $srchlast =~ s/\s+$//;
8734: $srchfirst =~ s/^\s+//;
1.160 raeburn 8735: if ($srch->{'srchtype'} eq 'exact') {
8736: if (($names{'lastname'} eq $srchlast) &&
8737: ($names{'firstname'} eq $srchfirst)) {
8738: $srch_results{$user} = {firstname => $names{'firstname'},
8739: lastname => $names{'lastname'},
8740: permanentemail => $emails{'permanentemail'},
8741:
8742: };
8743: }
1.177 raeburn 8744: } elsif ($srch->{'srchtype'} eq 'begins') {
8745: if (($names{'lastname'} =~ /^\Q$srchlast\E/i) &&
8746: ($names{'firstname'} =~ /^\Q$srchfirst\E/i)) {
8747: $srch_results{$user} = {firstname => $names{'firstname'},
8748: lastname => $names{'lastname'},
8749: permanentemail => $emails{'permanentemail'},
8750: };
8751: }
8752: } else {
1.160 raeburn 8753: if (($names{'lastname'} =~ /\Q$srchlast\E/i) &&
8754: ($names{'firstname'} =~ /\Q$srchfirst\E/i)) {
8755: $srch_results{$user} = {firstname => $names{'firstname'},
8756: lastname => $names{'lastname'},
8757: permanentemail => $emails{'permanentemail'},
8758: };
8759: }
8760: }
8761: }
8762: }
1.179 raeburn 8763: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8764: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 8765: } elsif ($srch->{'srchin'} eq 'alc') {
1.179 raeburn 8766: $currstate = 'query';
1.160 raeburn 8767: } elsif ($srch->{'srchin'} eq 'instd') {
1.181 raeburn 8768: ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
8769: if ($dirsrchres eq 'ok') {
8770: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8771: &build_search_response($context,$srch,%srch_results);
1.181 raeburn 8772: } else {
1.412 raeburn 8773: my $showdom = &display_domain_info($srch->{'srchdomain'});
8774: $response = '<span class="LC_warning">'.
1.181 raeburn 8775: &mt('Institutional directory search is not available in domain: [_1]',$showdom).
8776: '</span><br />'.
1.435 raeburn 8777: &mt('You may want to search in the LON-CAPA domain instead of in the institutional directory.').
1.415 raeburn 8778: '<br />';
1.181 raeburn 8779: }
1.160 raeburn 8780: }
8781: }
1.179 raeburn 8782: return ($currstate,$response,$forcenewuser,\%srch_results);
1.160 raeburn 8783: }
8784:
1.412 raeburn 8785: sub domdirectorysrch_check {
8786: my ($srch) = @_;
8787: my $response;
8788: my %dom_inst_srch = &Apache::lonnet::get_dom('configuration',
8789: ['directorysrch'],$srch->{'srchdomain'});
8790: my $showdom = &display_domain_info($srch->{'srchdomain'});
8791: if (ref($dom_inst_srch{'directorysrch'}) eq 'HASH') {
8792: if ($dom_inst_srch{'directorysrch'}{'lcavailable'} eq '0') {
8793: return &mt('LON-CAPA directory search is not available in domain: [_1]',$showdom);
8794: }
8795: if ($dom_inst_srch{'directorysrch'}{'lclocalonly'}) {
8796: if ($env{'request.role.domain'} ne $srch->{'srchdomain'}) {
8797: return &mt('LON-CAPA directory search in domain: [_1] is only allowed for users with a current role in the domain.',$showdom);
8798: }
8799: }
8800: }
8801: return 'ok';
8802: }
8803:
8804: sub instdirectorysrch_check {
1.160 raeburn 8805: my ($srch) = @_;
8806: my $can_search = 0;
8807: my $response;
8808: my %dom_inst_srch = &Apache::lonnet::get_dom('configuration',
8809: ['directorysrch'],$srch->{'srchdomain'});
1.180 raeburn 8810: my $showdom = &display_domain_info($srch->{'srchdomain'});
1.160 raeburn 8811: if (ref($dom_inst_srch{'directorysrch'}) eq 'HASH') {
8812: if (!$dom_inst_srch{'directorysrch'}{'available'}) {
1.180 raeburn 8813: return &mt('Institutional directory search is not available in domain: [_1]',$showdom);
1.160 raeburn 8814: }
8815: if ($dom_inst_srch{'directorysrch'}{'localonly'}) {
8816: if ($env{'request.role.domain'} ne $srch->{'srchdomain'}) {
1.180 raeburn 8817: return &mt('Institutional directory search in domain: [_1] is only allowed for users with a current role in the domain.',$showdom);
1.160 raeburn 8818: }
8819: my @usertypes = split(/:/,$env{'environment.inststatus'});
8820: if (!@usertypes) {
8821: push(@usertypes,'default');
8822: }
8823: if (ref($dom_inst_srch{'directorysrch'}{'cansearch'}) eq 'ARRAY') {
8824: foreach my $type (@usertypes) {
8825: if (grep(/^\Q$type\E$/,@{$dom_inst_srch{'directorysrch'}{'cansearch'}})) {
8826: $can_search = 1;
8827: last;
8828: }
8829: }
8830: }
8831: if (!$can_search) {
8832: my ($insttypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($srch->{'srchdomain'});
8833: my @longtypes;
8834: foreach my $item (@usertypes) {
1.229 raeburn 8835: if (defined($insttypes->{$item})) {
8836: push (@longtypes,$insttypes->{$item});
8837: } elsif ($item eq 'default') {
8838: push (@longtypes,&mt('other'));
8839: }
1.160 raeburn 8840: }
8841: my $insttype_str = join(', ',@longtypes);
1.180 raeburn 8842: return &mt('Institutional directory search in domain: [_1] is not available to your user type: ',$showdom).$insttype_str;
1.229 raeburn 8843: }
1.160 raeburn 8844: } else {
8845: $can_search = 1;
8846: }
8847: } else {
1.180 raeburn 8848: return &mt('Institutional directory search has not been configured for domain: [_1]',$showdom);
1.160 raeburn 8849: }
8850: my %longtext = &Apache::lonlocal::texthash (
1.167 albertel 8851: uname => 'username',
1.160 raeburn 8852: lastfirst => 'last name, first name',
1.167 albertel 8853: lastname => 'last name',
1.172 raeburn 8854: contains => 'contains',
1.178 raeburn 8855: exact => 'as exact match to',
8856: begins => 'begins with',
1.160 raeburn 8857: );
8858: if ($can_search) {
8859: if (ref($dom_inst_srch{'directorysrch'}{'searchby'}) eq 'ARRAY') {
8860: if (!grep(/^\Q$srch->{'srchby'}\E$/,@{$dom_inst_srch{'directorysrch'}{'searchby'}})) {
1.180 raeburn 8861: return &mt('Institutional directory search in domain: [_1] is not available for searching by "[_2]"',$showdom,$longtext{$srch->{'srchby'}});
1.160 raeburn 8862: }
8863: } else {
1.180 raeburn 8864: return &mt('Institutional directory search in domain: [_1] is not available.', $showdom);
1.160 raeburn 8865: }
8866: }
8867: if ($can_search) {
1.178 raeburn 8868: if (ref($dom_inst_srch{'directorysrch'}{'searchtypes'}) eq 'ARRAY') {
8869: if (grep(/^\Q$srch->{'srchtype'}\E/,@{$dom_inst_srch{'directorysrch'}{'searchtypes'}})) {
8870: return 'ok';
8871: } else {
1.180 raeburn 8872: return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
1.178 raeburn 8873: }
8874: } else {
8875: if ((($dom_inst_srch{'directorysrch'}{'searchtypes'} eq 'specify') &&
8876: ($srch->{'srchtype'} eq 'exact' || $srch->{'srchtype'} eq 'contains')) ||
8877: ($dom_inst_srch{'directorysrch'}{'searchtypes'} eq $srch->{'srchtype'})) {
8878: return 'ok';
8879: } else {
1.180 raeburn 8880: return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
1.178 raeburn 8881: }
1.160 raeburn 8882: }
8883: }
8884: }
8885:
8886: sub get_courseusers {
8887: my %advhash;
1.167 albertel 8888: my $classlist = &Apache::loncoursedata::get_classlist();
1.160 raeburn 8889: my %coursepersonnel=&Apache::lonnet::get_course_adv_roles();
8890: foreach my $role (sort(keys(%coursepersonnel))) {
8891: foreach my $user (split(/\,/,$coursepersonnel{$role})) {
1.167 albertel 8892: if (!exists($classlist->{$user})) {
8893: $classlist->{$user} = [];
8894: }
1.160 raeburn 8895: }
8896: }
1.167 albertel 8897: return $classlist;
1.160 raeburn 8898: }
8899:
8900: sub build_search_response {
1.221 raeburn 8901: my ($context,$srch,%srch_results) = @_;
1.179 raeburn 8902: my ($currstate,$response,$forcenewuser);
1.160 raeburn 8903: my %names = (
1.330 bisitz 8904: 'uname' => 'username',
8905: 'lastname' => 'last name',
1.160 raeburn 8906: 'lastfirst' => 'last name, first name',
1.330 bisitz 8907: 'crs' => 'this course',
8908: 'dom' => 'LON-CAPA domain',
8909: 'instd' => 'the institutional directory for domain',
1.160 raeburn 8910: );
8911:
8912: my %single = (
1.180 raeburn 8913: begins => 'A match',
1.160 raeburn 8914: contains => 'A match',
1.180 raeburn 8915: exact => 'An exact match',
1.160 raeburn 8916: );
8917: my %nomatch = (
1.180 raeburn 8918: begins => 'No match',
1.160 raeburn 8919: contains => 'No match',
1.180 raeburn 8920: exact => 'No exact match',
1.160 raeburn 8921: );
8922: if (keys(%srch_results) > 1) {
1.179 raeburn 8923: $currstate = 'select';
1.160 raeburn 8924: } else {
8925: if (keys(%srch_results) == 1) {
1.416 raeburn 8926: if ($env{'form.action'} eq 'accesslogs') {
8927: $currstate = 'activity';
8928: } else {
8929: $currstate = 'modify';
8930: }
1.180 raeburn 8931: $response = &mt("$single{$srch->{'srchtype'}} was found for the $names{$srch->{'srchby'}} ([_1]) in $names{$srch->{'srchin'}}.",$srch->{'srchterm'});
8932: if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
1.330 bisitz 8933: $response .= ': '.&display_domain_info($srch->{'srchdomain'});
1.180 raeburn 8934: }
1.330 bisitz 8935: } else { # Search has nothing found. Prepare message to user.
8936: $response = '<span class="LC_warning">';
1.180 raeburn 8937: if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
1.330 bisitz 8938: $response .= &mt("$nomatch{$srch->{'srchtype'}} found for the $names{$srch->{'srchby'}} [_1] in $names{$srch->{'srchin'}}: [_2]",
8939: '<b>'.$srch->{'srchterm'}.'</b>',
8940: &display_domain_info($srch->{'srchdomain'}));
8941: } else {
8942: $response .= &mt("$nomatch{$srch->{'srchtype'}} found for the $names{$srch->{'srchby'}} [_1] in $names{$srch->{'srchin'}}.",
8943: '<b>'.$srch->{'srchterm'}.'</b>');
1.180 raeburn 8944: }
8945: $response .= '</span>';
1.330 bisitz 8946:
1.160 raeburn 8947: if ($srch->{'srchin'} ne 'alc') {
8948: $forcenewuser = 1;
8949: my $cansrchinst = 0;
1.438 raeburn 8950: if (($srch->{'srchdomain'}) && ($env{'form.action'} ne 'accesslogs')) {
1.160 raeburn 8951: my %domconfig = &Apache::lonnet::get_dom('configuration',['directorysrch'],$srch->{'srchdomain'});
8952: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
8953: if ($domconfig{'directorysrch'}{'available'}) {
8954: $cansrchinst = 1;
8955: }
8956: }
8957: }
1.180 raeburn 8958: if ((($srch->{'srchby'} eq 'lastfirst') ||
8959: ($srch->{'srchby'} eq 'lastname')) &&
8960: ($srch->{'srchin'} eq 'dom')) {
8961: if ($cansrchinst) {
8962: $response .= '<br />'.&mt('You may want to broaden your search to a search of the institutional directory for the domain.');
1.160 raeburn 8963: }
8964: }
1.180 raeburn 8965: if ($srch->{'srchin'} eq 'crs') {
8966: $response .= '<br />'.&mt('You may want to broaden your search to the selected LON-CAPA domain.');
8967: }
8968: }
1.305 raeburn 8969: my $createdom = $env{'request.role.domain'};
8970: if ($context eq 'requestcrs') {
8971: if ($env{'form.coursedom'} ne '') {
8972: $createdom = $env{'form.coursedom'};
8973: }
8974: }
1.416 raeburn 8975: unless (($env{'form.action'} eq 'accesslogs') || (($srch->{'srchby'} eq 'uname') && ($srch->{'srchin'} eq 'dom') &&
8976: ($srch->{'srchtype'} eq 'exact') && ($srch->{'srchdomain'} eq $createdom))) {
1.221 raeburn 8977: my $cancreate =
1.305 raeburn 8978: &Apache::lonuserutils::can_create_user($createdom,$context);
8979: my $targetdom = '<span class="LC_cusr_emph">'.$createdom.'</span>';
1.221 raeburn 8980: if ($cancreate) {
1.305 raeburn 8981: my $showdom = &display_domain_info($createdom);
1.266 bisitz 8982: $response .= '<br /><br />'
8983: .'<b>'.&mt('To add a new user:').'</b>'
1.305 raeburn 8984: .'<br />';
8985: if ($context eq 'requestcrs') {
8986: $response .= &mt("(You can only define new users in the new course's domain - [_1])",$targetdom);
8987: } else {
8988: $response .= &mt("(You can only create new users in your current role's domain - [_1])",$targetdom);
8989: }
8990: $response .='<ul><li>'
1.266 bisitz 8991: .&mt("Set 'Domain/institution to search' to: [_1]",'<span class="LC_cusr_emph">'.$showdom.'</span>')
8992: .'</li><li>'
8993: .&mt("Set 'Search criteria' to: [_1]username is ..... in selected LON-CAPA domain[_2]",'<span class="LC_cusr_emph">','</span>')
8994: .'</li><li>'
8995: .&mt('Provide the proposed username')
8996: .'</li><li>'
8997: .&mt("Click 'Search'")
8998: .'</li></ul><br />';
1.221 raeburn 8999: } else {
1.422 raeburn 9000: unless (($context eq 'domain') && ($env{'form.action'} eq 'singleuser')) {
9001: my $helplink = ' href="javascript:helpMenu('."'display'".')"';
9002: $response .= '<br /><br />';
9003: if ($context eq 'requestcrs') {
9004: $response .= &mt("You are not authorized to define new users in the new course's domain - [_1].",$targetdom);
9005: } else {
9006: $response .= &mt("You are not authorized to create new users in your current role's domain - [_1].",$targetdom);
9007: }
9008: $response .= '<br />'
9009: .&mt('Please contact the [_1]helpdesk[_2] if you need to create a new user.'
9010: ,' <a'.$helplink.'>'
9011: ,'</a>')
9012: .'<br />';
1.305 raeburn 9013: }
1.221 raeburn 9014: }
1.160 raeburn 9015: }
9016: }
9017: }
1.179 raeburn 9018: return ($currstate,$response,$forcenewuser);
1.160 raeburn 9019: }
9020:
1.180 raeburn 9021: sub display_domain_info {
9022: my ($dom) = @_;
9023: my $output = $dom;
9024: if ($dom ne '') {
9025: my $domdesc = &Apache::lonnet::domain($dom,'description');
9026: if ($domdesc ne '') {
9027: $output .= ' <span class="LC_cusr_emph">('.$domdesc.')</span>';
9028: }
9029: }
9030: return $output;
9031: }
9032:
1.160 raeburn 9033: sub crumb_utilities {
9034: my %elements = (
9035: crtuser => {
9036: srchterm => 'text',
1.172 raeburn 9037: srchin => 'selectbox',
1.160 raeburn 9038: srchby => 'selectbox',
9039: srchtype => 'selectbox',
9040: srchdomain => 'selectbox',
9041: },
1.207 raeburn 9042: crtusername => {
9043: srchterm => 'text',
9044: srchdomain => 'selectbox',
9045: },
1.160 raeburn 9046: docustom => {
9047: rolename => 'selectbox',
9048: newrolename => 'textbox',
9049: },
1.179 raeburn 9050: studentform => {
9051: srchterm => 'text',
9052: srchin => 'selectbox',
9053: srchby => 'selectbox',
9054: srchtype => 'selectbox',
9055: srchdomain => 'selectbox',
9056: },
1.160 raeburn 9057: );
9058:
9059: my $jsback .= qq|
9060: function backPage(formname,prevphase,prevstate) {
1.211 raeburn 9061: if (typeof prevphase == 'undefined') {
9062: formname.phase.value = '';
9063: }
9064: else {
9065: formname.phase.value = prevphase;
9066: }
9067: if (typeof prevstate == 'undefined') {
9068: formname.currstate.value = '';
9069: }
9070: else {
9071: formname.currstate.value = prevstate;
9072: }
1.160 raeburn 9073: formname.submit();
9074: }
9075: |;
9076: return ($jsback,\%elements);
9077: }
9078:
1.26 matthew 9079: sub course_level_table {
1.375 raeburn 9080: my ($inccourses,$showcredits,$defaultcredits) = @_;
9081: return unless (ref($inccourses) eq 'HASH');
1.26 matthew 9082: my $table = '';
1.62 www 9083: # Custom Roles?
9084:
1.190 raeburn 9085: my %customroles=&Apache::lonuserutils::my_custom_roles();
1.89 raeburn 9086: my %lt=&Apache::lonlocal::texthash(
9087: 'exs' => "Existing sections",
9088: 'new' => "Define new section",
9089: 'ssd' => "Set Start Date",
9090: 'sed' => "Set End Date",
1.131 raeburn 9091: 'crl' => "Course Level",
1.89 raeburn 9092: 'act' => "Activate",
9093: 'rol' => "Role",
9094: 'ext' => "Extent",
1.113 raeburn 9095: 'grs' => "Section",
1.375 raeburn 9096: 'crd' => "Credits",
1.89 raeburn 9097: 'sta' => "Start",
9098: 'end' => "End"
9099: );
1.62 www 9100:
1.375 raeburn 9101: foreach my $protectedcourse (sort(keys(%{$inccourses}))) {
1.135 raeburn 9102: my $thiscourse=$protectedcourse;
1.26 matthew 9103: $thiscourse=~s:_:/:g;
9104: my %coursedata=&Apache::lonnet::coursedescription($thiscourse);
1.365 raeburn 9105: my $isowner = &Apache::lonuserutils::is_courseowner($protectedcourse,$coursedata{'internal.courseowner'});
1.26 matthew 9106: my $area=$coursedata{'description'};
1.321 raeburn 9107: my $crstype=$coursedata{'type'};
1.135 raeburn 9108: if (!defined($area)) { $area=&mt('Unavailable course').': '.$protectedcourse; }
1.89 raeburn 9109: my ($domain,$cnum)=split(/\//,$thiscourse);
1.115 albertel 9110: my %sections_count;
1.101 albertel 9111: if (defined($env{'request.course.id'})) {
9112: if ($env{'request.course.id'} eq $domain.'_'.$cnum) {
1.115 albertel 9113: %sections_count =
9114: &Apache::loncommon::get_sections($domain,$cnum);
1.92 raeburn 9115: }
9116: }
1.321 raeburn 9117: my @roles = &Apache::lonuserutils::roles_by_context('course','',$crstype);
1.213 raeburn 9118: foreach my $role (@roles) {
1.321 raeburn 9119: my $plrole=&Apache::lonnet::plaintext($role,$crstype);
1.329 raeburn 9120: if ((&Apache::lonnet::allowed('c'.$role,$thiscourse)) ||
9121: ((($role eq 'cc') || ($role eq 'co')) && ($isowner))) {
1.221 raeburn 9122: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
1.375 raeburn 9123: $plrole,\%sections_count,\%lt,
1.402 raeburn 9124: $showcredits,$defaultcredits,$crstype);
1.221 raeburn 9125: } elsif ($env{'request.course.sec'} ne '') {
9126: if (&Apache::lonnet::allowed('c'.$role,$thiscourse.'/'.
9127: $env{'request.course.sec'})) {
9128: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
1.375 raeburn 9129: $plrole,\%sections_count,\%lt,
1.402 raeburn 9130: $showcredits,$defaultcredits,$crstype);
1.26 matthew 9131: }
9132: }
9133: }
1.221 raeburn 9134: if (&Apache::lonnet::allowed('ccr',$thiscourse)) {
1.324 raeburn 9135: foreach my $cust (sort(keys(%customroles))) {
9136: next if ($crstype eq 'Community' && $customroles{$cust} =~ /bre\&S/);
1.221 raeburn 9137: my $role = 'cr_cr_'.$env{'user.domain'}.'_'.$env{'user.name'}.'_'.$cust;
9138: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
1.402 raeburn 9139: $cust,\%sections_count,\%lt,
9140: $showcredits,$defaultcredits,$crstype);
1.221 raeburn 9141: }
1.62 www 9142: }
1.26 matthew 9143: }
9144: return '' if ($table eq ''); # return nothing if there is nothing
9145: # in the table
1.188 raeburn 9146: my $result;
9147: if (!$env{'request.course.id'}) {
9148: $result = '<h4>'.$lt{'crl'}.'</h4>'."\n";
9149: }
9150: $result .=
1.136 raeburn 9151: &Apache::loncommon::start_data_table().
9152: &Apache::loncommon::start_data_table_header_row().
1.375 raeburn 9153: '<th>'.$lt{'act'}.'</th><th>'.$lt{'rol'}.'</th>'."\n".
1.402 raeburn 9154: '<th>'.$lt{'ext'}.'</th><th>'."\n";
9155: if ($showcredits) {
9156: $result .= $lt{'crd'}.'</th>';
9157: }
9158: $result .=
1.375 raeburn 9159: '<th>'.$lt{'grs'}.'</th><th>'.$lt{'sta'}.'</th>'."\n".
9160: '<th>'.$lt{'end'}.'</th>'.
1.136 raeburn 9161: &Apache::loncommon::end_data_table_header_row().
9162: $table.
9163: &Apache::loncommon::end_data_table();
1.26 matthew 9164: return $result;
9165: }
1.88 raeburn 9166:
1.221 raeburn 9167: sub course_level_row {
1.375 raeburn 9168: my ($protectedcourse,$role,$area,$domain,$plrole,$sections_count,
1.402 raeburn 9169: $lt,$showcredits,$defaultcredits,$crstype) = @_;
1.375 raeburn 9170: my $creditem;
1.222 raeburn 9171: my $row = &Apache::loncommon::start_data_table_row().
9172: ' <td><input type="checkbox" name="act_'.
9173: $protectedcourse.'_'.$role.'" /></td>'."\n".
9174: ' <td>'.$plrole.'</td>'."\n".
9175: ' <td>'.$area.'<br />Domain: '.$domain.'</td>'."\n";
1.402 raeburn 9176: if (($showcredits) && ($role eq 'st') && ($crstype eq 'Course')) {
1.375 raeburn 9177: $row .=
9178: '<td><input type="text" name="credits_'.$protectedcourse.'_'.
9179: $role.'" size="3" value="'.$defaultcredits.'" /></td>';
9180: } else {
9181: $row .= '<td> </td>';
9182: }
1.322 raeburn 9183: if (($role eq 'cc') || ($role eq 'co')) {
1.222 raeburn 9184: $row .= '<td> </td>';
1.221 raeburn 9185: } elsif ($env{'request.course.sec'} ne '') {
1.222 raeburn 9186: $row .= ' <td><input type="hidden" value="'.
9187: $env{'request.course.sec'}.'" '.
9188: 'name="sec_'.$protectedcourse.'_'.$role.'" />'.
9189: $env{'request.course.sec'}.'</td>';
1.221 raeburn 9190: } else {
9191: if (ref($sections_count) eq 'HASH') {
9192: my $currsec =
9193: &Apache::lonuserutils::course_sections($sections_count,
9194: $protectedcourse.'_'.$role);
1.222 raeburn 9195: $row .= '<td><table class="LC_createuser">'."\n".
9196: '<tr class="LC_section_row">'."\n".
9197: ' <td valign="top">'.$lt->{'exs'}.'<br />'.
9198: $currsec.'</td>'."\n".
9199: ' <td> </td>'."\n".
9200: ' <td valign="top"> '.$lt->{'new'}.'<br />'.
1.221 raeburn 9201: '<input type="text" name="newsec_'.$protectedcourse.'_'.$role.
9202: '" value="" />'.
9203: '<input type="hidden" '.
9204: 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'."\n".
1.222 raeburn 9205: '</tr></table></td>'."\n";
1.221 raeburn 9206: } else {
1.222 raeburn 9207: $row .= '<td><input type="text" size="10" '.
1.375 raeburn 9208: 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'."\n";
1.221 raeburn 9209: }
9210: }
1.222 raeburn 9211: $row .= <<ENDTIMEENTRY;
9212: <td><input type="hidden" name="start_$protectedcourse\_$role" value="" />
1.221 raeburn 9213: <a href=
9214: "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 9215: <td><input type="hidden" name="end_$protectedcourse\_$role" value="" />
1.221 raeburn 9216: <a href=
9217: "javascript:pjump('date_end','End Date $plrole',document.cu.end_$protectedcourse\_$role.value,'end_$protectedcourse\_$role','cu.pres','dateset')">$lt->{'sed'}</a></td>
9218: ENDTIMEENTRY
1.222 raeburn 9219: $row .= &Apache::loncommon::end_data_table_row();
9220: return $row;
1.221 raeburn 9221: }
9222:
1.88 raeburn 9223: sub course_level_dc {
1.375 raeburn 9224: my ($dcdom,$showcredits) = @_;
1.190 raeburn 9225: my %customroles=&Apache::lonuserutils::my_custom_roles();
1.213 raeburn 9226: my @roles = &Apache::lonuserutils::roles_by_context('course');
1.88 raeburn 9227: my $hiddenitems = '<input type="hidden" name="dcdomain" value="'.$dcdom.'" />'.
9228: '<input type="hidden" name="origdom" value="'.$dcdom.'" />'.
1.133 raeburn 9229: '<input type="hidden" name="dccourse" value="" />';
1.355 www 9230: my $courseform=&Apache::loncommon::selectcourse_link
1.356 raeburn 9231: ('cu','dccourse','dcdomain','coursedesc',undef,undef,'Select','crstype');
1.375 raeburn 9232: my $credit_elem;
9233: if ($showcredits) {
9234: $credit_elem = 'credits';
9235: }
9236: my $cb_jscript = &Apache::loncommon::coursebrowser_javascript($dcdom,'currsec','cu','role','Course/Community Browser',$credit_elem);
1.88 raeburn 9237: my %lt=&Apache::lonlocal::texthash(
9238: 'rol' => "Role",
1.113 raeburn 9239: 'grs' => "Section",
1.88 raeburn 9240: 'exs' => "Existing sections",
9241: 'new' => "Define new section",
9242: 'sta' => "Start",
9243: 'end' => "End",
9244: 'ssd' => "Set Start Date",
1.355 www 9245: 'sed' => "Set End Date",
1.375 raeburn 9246: 'scc' => "Course/Community",
9247: 'crd' => "Credits",
1.88 raeburn 9248: );
1.323 raeburn 9249: my $header = '<h4>'.&mt('Course/Community Level').'</h4>'.
1.136 raeburn 9250: &Apache::loncommon::start_data_table().
9251: &Apache::loncommon::start_data_table_header_row().
1.375 raeburn 9252: '<th>'.$lt{'scc'}.'</th><th>'.$lt{'rol'}.'</th>'."\n".
1.397 bisitz 9253: '<th>'.$lt{'grs'}.'</th>'."\n";
9254: $header .= '<th>'.$lt{'crd'}.'</th>'."\n" if ($showcredits);
9255: $header .= '<th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'."\n".
1.136 raeburn 9256: &Apache::loncommon::end_data_table_header_row();
1.143 raeburn 9257: my $otheritems = &Apache::loncommon::start_data_table_row()."\n".
1.356 raeburn 9258: '<td><br /><span class="LC_nobreak"><input type="text" name="coursedesc" value="" onfocus="this.blur();opencrsbrowser('."'cu','dccourse','dcdomain','coursedesc','','','','crstype'".')" />'.
9259: $courseform.(' ' x4).'</span></td>'."\n".
1.389 bisitz 9260: '<td valign="top"><br /><select name="role">'."\n";
1.213 raeburn 9261: foreach my $role (@roles) {
1.135 raeburn 9262: my $plrole=&Apache::lonnet::plaintext($role);
1.389 bisitz 9263: $otheritems .= ' <option value="'.$role.'">'.$plrole.'</option>';
1.88 raeburn 9264: }
1.404 raeburn 9265: if ( keys(%customroles) > 0) {
9266: foreach my $cust (sort(keys(%customroles))) {
1.101 albertel 9267: my $custrole='cr_cr_'.$env{'user.domain'}.
1.135 raeburn 9268: '_'.$env{'user.name'}.'_'.$cust;
1.389 bisitz 9269: $otheritems .= ' <option value="'.$custrole.'">'.$cust.'</option>';
1.88 raeburn 9270: }
9271: }
9272: $otheritems .= '</select></td><td>'.
9273: '<table border="0" cellspacing="0" cellpadding="0">'.
9274: '<tr><td valign="top"><b>'.$lt{'exs'}.'</b><br /><select name="currsec">'.
1.389 bisitz 9275: ' <option value=""><--'.&mt('Pick course first').'</option></select></td>'.
1.88 raeburn 9276: '<td> </td>'.
9277: '<td valign="top"> <b>'.$lt{'new'}.'</b><br />'.
1.113 raeburn 9278: '<input type="text" name="newsec" value="" />'.
1.237 raeburn 9279: '<input type="hidden" name="section" value="" />'.
1.323 raeburn 9280: '<input type="hidden" name="groups" value="" />'.
9281: '<input type="hidden" name="crstype" value="" /></td>'.
1.375 raeburn 9282: '</tr></table></td>'."\n";
9283: if ($showcredits) {
9284: $otheritems .= '<td><br />'."\n".
1.397 bisitz 9285: '<input type="text" size="3" name="credits" value="" /></td>'."\n";
1.375 raeburn 9286: }
1.88 raeburn 9287: $otheritems .= <<ENDTIMEENTRY;
1.323 raeburn 9288: <td><br /><input type="hidden" name="start" value='' />
1.88 raeburn 9289: <a href=
9290: "javascript:pjump('date_start','Start Date',document.cu.start.value,'start','cu.pres','dateset')">$lt{'ssd'}</a></td>
1.323 raeburn 9291: <td><br /><input type="hidden" name="end" value='' />
1.88 raeburn 9292: <a href=
9293: "javascript:pjump('date_end','End Date',document.cu.end.value,'end','cu.pres','dateset')">$lt{'sed'}</a></td>
9294: ENDTIMEENTRY
1.136 raeburn 9295: $otheritems .= &Apache::loncommon::end_data_table_row().
9296: &Apache::loncommon::end_data_table()."\n";
1.88 raeburn 9297: return $cb_jscript.$header.$hiddenitems.$otheritems;
9298: }
9299:
1.237 raeburn 9300: sub update_selfenroll_config {
1.400 raeburn 9301: my ($r,$cid,$cdom,$cnum,$context,$crstype,$currsettings) = @_;
1.398 raeburn 9302: return unless (ref($currsettings) eq 'HASH');
9303: my ($row,$lt) = &Apache::lonuserutils::get_selfenroll_titles();
9304: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
1.237 raeburn 9305: my (%changes,%warning);
1.241 raeburn 9306: my $curr_types;
1.400 raeburn 9307: my %noedit;
9308: unless ($context eq 'domain') {
9309: %noedit = &get_noedit_fields($cdom,$cnum,$crstype,$row);
9310: }
1.237 raeburn 9311: if (ref($row) eq 'ARRAY') {
9312: foreach my $item (@{$row}) {
1.400 raeburn 9313: next if ($noedit{$item});
1.237 raeburn 9314: if ($item eq 'enroll_dates') {
9315: my (%currenrolldate,%newenrolldate);
9316: foreach my $type ('start','end') {
1.398 raeburn 9317: $currenrolldate{$type} = $currsettings->{'selfenroll_'.$type.'_date'};
1.237 raeburn 9318: $newenrolldate{$type} = &Apache::lonhtmlcommon::get_date_from_form('selfenroll_'.$type.'_date');
9319: if ($newenrolldate{$type} ne $currenrolldate{$type}) {
9320: $changes{'internal.selfenroll_'.$type.'_date'} = $newenrolldate{$type};
9321: }
9322: }
9323: } elsif ($item eq 'access_dates') {
9324: my (%currdate,%newdate);
9325: foreach my $type ('start','end') {
1.398 raeburn 9326: $currdate{$type} = $currsettings->{'selfenroll_'.$type.'_access'};
1.237 raeburn 9327: $newdate{$type} = &Apache::lonhtmlcommon::get_date_from_form('selfenroll_'.$type.'_access');
9328: if ($newdate{$type} ne $currdate{$type}) {
9329: $changes{'internal.selfenroll_'.$type.'_access'} = $newdate{$type};
9330: }
9331: }
1.241 raeburn 9332: } elsif ($item eq 'types') {
1.398 raeburn 9333: $curr_types = $currsettings->{'selfenroll_'.$item};
1.241 raeburn 9334: if ($env{'form.selfenroll_all'}) {
9335: if ($curr_types ne '*') {
9336: $changes{'internal.selfenroll_types'} = '*';
9337: } else {
9338: next;
9339: }
9340: } else {
1.249 raeburn 9341: my %currdoms;
1.241 raeburn 9342: my @entries = split(/;/,$curr_types);
9343: my @deletedoms = &Apache::loncommon::get_env_multiple('form.selfenroll_delete');
1.249 raeburn 9344: my @activations = &Apache::loncommon::get_env_multiple('form.selfenroll_activate');
1.241 raeburn 9345: my $newnum = 0;
1.249 raeburn 9346: my @latesttypes;
9347: foreach my $num (@activations) {
9348: my @types = &Apache::loncommon::get_env_multiple('form.selfenroll_types_'.$num);
9349: if (@types > 0) {
1.241 raeburn 9350: @types = sort(@types);
9351: my $typestr = join(',',@types);
1.249 raeburn 9352: my $typedom = $env{'form.selfenroll_dom_'.$num};
9353: $latesttypes[$newnum] = $typedom.':'.$typestr;
9354: $currdoms{$typedom} = 1;
1.241 raeburn 9355: $newnum ++;
9356: }
9357: }
1.338 raeburn 9358: for (my $j=0; $j<$env{'form.selfenroll_types_total'}; $j++) {
9359: if ((!grep(/^$j$/,@deletedoms)) && (!grep(/^$j$/,@activations))) {
1.249 raeburn 9360: my @types = &Apache::loncommon::get_env_multiple('form.selfenroll_types_'.$j);
9361: if (@types > 0) {
9362: @types = sort(@types);
9363: my $typestr = join(',',@types);
9364: my $typedom = $env{'form.selfenroll_dom_'.$j};
9365: $latesttypes[$newnum] = $typedom.':'.$typestr;
9366: $currdoms{$typedom} = 1;
9367: $newnum ++;
9368: }
9369: }
9370: }
9371: if ($env{'form.selfenroll_newdom'} ne '') {
9372: my $typedom = $env{'form.selfenroll_newdom'};
9373: if ((!defined($currdoms{$typedom})) &&
9374: (&Apache::lonnet::domain($typedom) ne '')) {
9375: my $typestr;
9376: my ($othertitle,$usertypes,$types) =
9377: &Apache::loncommon::sorted_inst_types($typedom);
9378: my $othervalue = 'any';
9379: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
9380: if (@{$types} > 0) {
1.257 raeburn 9381: my @esc_types = map { &escape($_); } @{$types};
1.249 raeburn 9382: $othervalue = 'other';
1.258 raeburn 9383: $typestr = join(',',(@esc_types,$othervalue));
1.249 raeburn 9384: }
9385: $typestr = $othervalue;
9386: } else {
9387: $typestr = $othervalue;
9388: }
9389: $latesttypes[$newnum] = $typedom.':'.$typestr;
9390: $newnum ++ ;
9391: }
9392: }
1.241 raeburn 9393: my $selfenroll_types = join(';',@latesttypes);
9394: if ($selfenroll_types ne $curr_types) {
9395: $changes{'internal.selfenroll_types'} = $selfenroll_types;
9396: }
9397: }
1.276 raeburn 9398: } elsif ($item eq 'limit') {
9399: my $newlimit = $env{'form.selfenroll_limit'};
9400: my $newcap = $env{'form.selfenroll_cap'};
9401: $newcap =~s/\s+//g;
1.398 raeburn 9402: my $currlimit = $currsettings->{'selfenroll_limit'};
1.276 raeburn 9403: $currlimit = 'none' if ($currlimit eq '');
1.398 raeburn 9404: my $currcap = $currsettings->{'selfenroll_cap'};
1.276 raeburn 9405: if ($newlimit ne $currlimit) {
9406: if ($newlimit ne 'none') {
9407: if ($newcap =~ /^\d+$/) {
9408: if ($newcap ne $currcap) {
9409: $changes{'internal.selfenroll_cap'} = $newcap;
9410: }
9411: $changes{'internal.selfenroll_limit'} = $newlimit;
9412: } else {
1.398 raeburn 9413: $warning{$item} = &mt('Maximum enrollment setting unchanged.').'<br />'.
9414: &mt('The value provided was invalid - it must be a positive integer if enrollment is being limited.');
1.276 raeburn 9415: }
9416: } elsif ($currcap ne '') {
9417: $changes{'internal.selfenroll_cap'} = '';
9418: $changes{'internal.selfenroll_limit'} = $newlimit;
9419: }
9420: } elsif ($currlimit ne 'none') {
9421: if ($newcap =~ /^\d+$/) {
9422: if ($newcap ne $currcap) {
9423: $changes{'internal.selfenroll_cap'} = $newcap;
9424: }
9425: } else {
1.398 raeburn 9426: $warning{$item} = &mt('Maximum enrollment setting unchanged.').'<br />'.
9427: &mt('The value provided was invalid - it must be a positive integer if enrollment is being limited.');
1.276 raeburn 9428: }
9429: }
9430: } elsif ($item eq 'approval') {
9431: my (@currnotified,@newnotified);
1.398 raeburn 9432: my $currapproval = $currsettings->{'selfenroll_approval'};
9433: my $currnotifylist = $currsettings->{'selfenroll_notifylist'};
1.276 raeburn 9434: if ($currnotifylist ne '') {
9435: @currnotified = split(/,/,$currnotifylist);
9436: @currnotified = sort(@currnotified);
9437: }
9438: my $newapproval = $env{'form.selfenroll_approval'};
9439: @newnotified = &Apache::loncommon::get_env_multiple('form.selfenroll_notify');
9440: @newnotified = sort(@newnotified);
9441: if ($newapproval ne $currapproval) {
9442: $changes{'internal.selfenroll_approval'} = $newapproval;
9443: if (!$newapproval) {
9444: if ($currnotifylist ne '') {
9445: $changes{'internal.selfenroll_notifylist'} = '';
9446: }
9447: } else {
9448: my @differences =
1.295 raeburn 9449: &Apache::loncommon::compare_arrays(\@currnotified,\@newnotified);
1.276 raeburn 9450: if (@differences > 0) {
9451: if (@newnotified > 0) {
9452: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
9453: } else {
9454: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
9455: }
9456: }
9457: }
9458: } else {
1.295 raeburn 9459: my @differences = &Apache::loncommon::compare_arrays(\@currnotified,\@newnotified);
1.276 raeburn 9460: if (@differences > 0) {
9461: if (@newnotified > 0) {
9462: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
9463: } else {
9464: $changes{'internal.selfenroll_notifylist'} = '';
9465: }
9466: }
9467: }
1.237 raeburn 9468: } else {
1.398 raeburn 9469: my $curr_val = $currsettings->{'selfenroll_'.$item};
1.237 raeburn 9470: my $newval = $env{'form.selfenroll_'.$item};
9471: if ($item eq 'section') {
9472: $newval = $env{'form.sections'};
1.241 raeburn 9473: if (defined($curr_groups{$newval})) {
1.237 raeburn 9474: $newval = $curr_val;
1.398 raeburn 9475: $warning{$item} = &mt('Section for self-enrolled users unchanged as the proposed section is a group').'<br />'.
9476: &mt('Group names and section names must be distinct');
1.237 raeburn 9477: } elsif ($newval eq 'all') {
9478: $newval = $curr_val;
1.274 bisitz 9479: $warning{$item} = &mt('Section for self-enrolled users unchanged, as "all" is a reserved section name.');
1.237 raeburn 9480: }
9481: if ($newval eq '') {
9482: $newval = 'none';
9483: }
9484: }
9485: if ($newval ne $curr_val) {
9486: $changes{'internal.selfenroll_'.$item} = $newval;
9487: }
1.241 raeburn 9488: }
1.237 raeburn 9489: }
9490: if (keys(%warning) > 0) {
9491: foreach my $item (@{$row}) {
9492: if (exists($warning{$item})) {
9493: $r->print($warning{$item}.'<br />');
9494: }
9495: }
9496: }
9497: if (keys(%changes) > 0) {
9498: my $putresult = &Apache::lonnet::put('environment',\%changes,$cdom,$cnum);
9499: if ($putresult eq 'ok') {
9500: if ((exists($changes{'internal.selfenroll_types'})) ||
9501: (exists($changes{'internal.selfenroll_start_date'})) ||
9502: (exists($changes{'internal.selfenroll_end_date'}))) {
9503: my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',
9504: $cnum,undef,undef,'Course');
9505: my $chome = &Apache::lonnet::homeserver($cnum,$cdom);
1.398 raeburn 9506: if (ref($crsinfo{$cid}) eq 'HASH') {
1.237 raeburn 9507: foreach my $item ('selfenroll_types','selfenroll_start_date','selfenroll_end_date') {
9508: if (exists($changes{'internal.'.$item})) {
1.398 raeburn 9509: $crsinfo{$cid}{$item} = $changes{'internal.'.$item};
1.237 raeburn 9510: }
9511: }
9512: my $crsputresult =
9513: &Apache::lonnet::courseidput($cdom,\%crsinfo,
9514: $chome,'notime');
9515: }
9516: }
9517: $r->print(&mt('The following changes were made to self-enrollment settings:').'<ul>');
9518: foreach my $item (@{$row}) {
9519: my $title = $item;
9520: if (ref($lt) eq 'HASH') {
9521: $title = $lt->{$item};
9522: }
9523: if ($item eq 'enroll_dates') {
9524: foreach my $type ('start','end') {
9525: if (exists($changes{'internal.selfenroll_'.$type.'_date'})) {
9526: my $newdate = &Apache::lonlocal::locallocaltime($changes{'internal.selfenroll_'.$type.'_date'});
1.244 bisitz 9527: $r->print('<li>'.&mt('[_1]: "[_2]" set to "[_3]".',
1.237 raeburn 9528: $title,$type,$newdate).'</li>');
9529: }
9530: }
9531: } elsif ($item eq 'access_dates') {
9532: foreach my $type ('start','end') {
9533: if (exists($changes{'internal.selfenroll_'.$type.'_access'})) {
9534: my $newdate = &Apache::lonlocal::locallocaltime($changes{'internal.selfenroll_'.$type.'_access'});
1.244 bisitz 9535: $r->print('<li>'.&mt('[_1]: "[_2]" set to "[_3]".',
1.237 raeburn 9536: $title,$type,$newdate).'</li>');
9537: }
9538: }
1.276 raeburn 9539: } elsif ($item eq 'limit') {
9540: if ((exists($changes{'internal.selfenroll_limit'})) ||
9541: (exists($changes{'internal.selfenroll_cap'}))) {
9542: my ($newval,$newcap);
9543: if ($changes{'internal.selfenroll_cap'} ne '') {
9544: $newcap = $changes{'internal.selfenroll_cap'}
9545: } else {
1.398 raeburn 9546: $newcap = $currsettings->{'selfenroll_cap'};
1.276 raeburn 9547: }
9548: if ($changes{'internal.selfenroll_limit'} eq 'none') {
9549: $newval = &mt('No limit');
9550: } elsif ($changes{'internal.selfenroll_limit'} eq
9551: 'allstudents') {
9552: $newval = &mt('New self-enrollment no longer allowed when total (all students) reaches [_1].',$newcap);
9553: } elsif ($changes{'internal.selfenroll_limit'} eq 'selfenrolled') {
9554: $newval = &mt('New self-enrollment no longer allowed when total number of self-enrolled students reaches [_1].',$newcap);
9555: } else {
1.398 raeburn 9556: my $currlimit = $currsettings->{'selfenroll_limit'};
1.276 raeburn 9557: if ($currlimit eq 'allstudents') {
9558: $newval = &mt('New self-enrollment no longer allowed when total (all students) reaches [_1].',$newcap);
9559: } elsif ($changes{'internal.selfenroll_limit'} eq 'selfenrolled') {
1.308 raeburn 9560: $newval = &mt('New self-enrollment no longer allowed when total number of self-enrolled students reaches [_1].',$newcap);
1.276 raeburn 9561: }
9562: }
9563: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval).'</li>'."\n");
9564: }
9565: } elsif ($item eq 'approval') {
9566: if ((exists($changes{'internal.selfenroll_approval'})) ||
9567: (exists($changes{'internal.selfenroll_notifylist'}))) {
1.398 raeburn 9568: my %selfdescs = &Apache::lonuserutils::selfenroll_default_descs();
1.276 raeburn 9569: my ($newval,$newnotify);
9570: if (exists($changes{'internal.selfenroll_notifylist'})) {
9571: $newnotify = $changes{'internal.selfenroll_notifylist'};
9572: } else {
1.398 raeburn 9573: $newnotify = $currsettings->{'selfenroll_notifylist'};
1.276 raeburn 9574: }
1.398 raeburn 9575: if (exists($changes{'internal.selfenroll_approval'})) {
9576: if ($changes{'internal.selfenroll_approval'} !~ /^[012]$/) {
9577: $changes{'internal.selfenroll_approval'} = '0';
9578: }
9579: $newval = $selfdescs{'approval'}{$changes{'internal.selfenroll_approval'}};
1.276 raeburn 9580: } else {
1.398 raeburn 9581: my $currapproval = $currsettings->{'selfenroll_approval'};
9582: if ($currapproval !~ /^[012]$/) {
9583: $currapproval = 0;
1.276 raeburn 9584: }
1.398 raeburn 9585: $newval = $selfdescs{'approval'}{$currapproval};
1.276 raeburn 9586: }
9587: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval));
9588: if ($newnotify) {
1.277 raeburn 9589: $r->print('<br />'.&mt('The following will be notified when an enrollment request needs approval, or has been approved: [_1].',$newnotify));
1.276 raeburn 9590: } else {
1.277 raeburn 9591: $r->print('<br />'.&mt('No notifications sent when an enrollment request needs approval, or has been approved.'));
1.276 raeburn 9592: }
9593: $r->print('</li>'."\n");
9594: }
1.237 raeburn 9595: } else {
9596: if (exists($changes{'internal.selfenroll_'.$item})) {
1.241 raeburn 9597: my $newval = $changes{'internal.selfenroll_'.$item};
9598: if ($item eq 'types') {
9599: if ($newval eq '') {
9600: $newval = &mt('None');
9601: } elsif ($newval eq '*') {
9602: $newval = &mt('Any user in any domain');
9603: }
1.245 raeburn 9604: } elsif ($item eq 'registered') {
9605: if ($newval eq '1') {
9606: $newval = &mt('Yes');
9607: } elsif ($newval eq '0') {
9608: $newval = &mt('No');
9609: }
1.241 raeburn 9610: }
1.244 bisitz 9611: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval).'</li>'."\n");
1.237 raeburn 9612: }
9613: }
9614: }
9615: $r->print('</ul>');
1.398 raeburn 9616: if ($env{'course.'.$cid.'.description'} ne '') {
9617: my %newenvhash;
9618: foreach my $key (keys(%changes)) {
9619: $newenvhash{'course.'.$cid.'.'.$key} = $changes{$key};
9620: }
9621: &Apache::lonnet::appenv(\%newenvhash);
1.237 raeburn 9622: }
9623: } else {
1.398 raeburn 9624: $r->print(&mt('An error occurred when saving changes to self-enrollment settings in this course.').'<br />'.
9625: &mt('The error was: [_1].',$putresult));
1.237 raeburn 9626: }
9627: } else {
1.249 raeburn 9628: $r->print(&mt('No changes were made to the existing self-enrollment settings in this course.'));
1.237 raeburn 9629: }
9630: } else {
1.249 raeburn 9631: $r->print(&mt('No changes were made to the existing self-enrollment settings in this course.'));
1.241 raeburn 9632: }
1.400 raeburn 9633: my $visactions = &cat_visibility();
9634: my ($cathash,%cattype);
9635: my %domconfig = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom);
9636: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
9637: $cathash = $domconfig{'coursecategories'}{'cats'};
9638: $cattype{'auth'} = $domconfig{'coursecategories'}{'auth'};
9639: $cattype{'unauth'} = $domconfig{'coursecategories'}{'unauth'};
9640: } else {
9641: $cathash = {};
9642: $cattype{'auth'} = 'std';
9643: $cattype{'unauth'} = 'std';
9644: }
9645: if (($cattype{'auth'} eq 'none') && ($cattype{'unauth'} eq 'none')) {
9646: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
9647: '<br />'.
9648: '<br />'.$visactions->{'take'}.'<ul>'.
9649: '<li>'.$visactions->{'dc_chgconf'}.'</li>'.
9650: '</ul>');
9651: } elsif (($cattype{'auth'} !~ /^(std|domonly)$/) && ($cattype{'unauth'} !~ /^(std|domonly)$/)) {
9652: if ($currsettings->{'uniquecode'}) {
9653: $r->print('<span class="LC_info">'.$visactions->{'vis'}.'</span>');
9654: } else {
1.366 bisitz 9655: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
1.400 raeburn 9656: '<br />'.
9657: '<br />'.$visactions->{'take'}.'<ul>'.
9658: '<li>'.$visactions->{'dc_setcode'}.'</li>'.
9659: '</ul><br />');
9660: }
9661: } else {
9662: my ($visible,$cansetvis,$vismsgs) = &visible_in_stdcat($cdom,$cnum,\%domconfig);
9663: if (ref($visactions) eq 'HASH') {
9664: if (!$visible) {
9665: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
9666: '<br />');
9667: if (ref($vismsgs) eq 'ARRAY') {
9668: $r->print('<br />'.$visactions->{'take'}.'<ul>');
9669: foreach my $item (@{$vismsgs}) {
9670: $r->print('<li>'.$visactions->{$item}.'</li>');
9671: }
9672: $r->print('</ul>');
1.256 raeburn 9673: }
1.400 raeburn 9674: $r->print($cansetvis);
1.256 raeburn 9675: }
9676: }
9677: }
1.237 raeburn 9678: return;
9679: }
9680:
1.27 matthew 9681: #---------------------------------------------- end functions for &phase_two
1.29 matthew 9682:
9683: #--------------------------------- functions for &phase_two and &phase_three
9684:
9685: #--------------------------end of functions for &phase_two and &phase_three
1.372 raeburn 9686:
1.1 www 9687: 1;
9688: __END__
1.2 www 9689:
9690:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>