Annotation of loncom/interface/loncreateuser.pm, revision 1.469
1.20 harris41 1: # The LearningOnline Network with CAPA
1.1 www 2: # Create a user
3: #
1.469 ! raeburn 4: # $Id: loncreateuser.pm,v 1.468 2023/06/20 14:03:52 raeburn Exp $
1.22 albertel 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
1.20 harris41 28: ###
29:
1.1 www 30: package Apache::loncreateuser;
1.66 bowersj2 31:
32: =pod
33:
34: =head1 NAME
35:
1.263 jms 36: Apache::loncreateuser.pm
1.66 bowersj2 37:
38: =head1 SYNOPSIS
39:
1.263 jms 40: Handler to create users and custom roles
41:
42: Provides an Apache handler for creating users,
1.66 bowersj2 43: editing their login parameters, roles, and removing roles, and
44: also creating and assigning custom roles.
45:
46: =head1 OVERVIEW
47:
48: =head2 Custom Roles
49:
50: In LON-CAPA, roles are actually collections of privileges. "Teaching
51: Assistant", "Course Coordinator", and other such roles are really just
52: collection of privileges that are useful in many circumstances.
53:
1.324 raeburn 54: Custom roles can be defined by a Domain Coordinator, Course Coordinator
55: or Community Coordinator via the Manage User functionality.
56: The custom role editor screen will show all privileges which can be
57: assigned to users. For a complete list of privileges, please see
58: C</home/httpd/lonTabs/rolesplain.tab>.
1.66 bowersj2 59:
1.324 raeburn 60: Custom role definitions are stored in the C<roles.db> file of the creator
61: of the role.
1.66 bowersj2 62:
63: =cut
1.1 www 64:
65: use strict;
66: use Apache::Constants qw(:common :http);
67: use Apache::lonnet;
1.54 bowersj2 68: use Apache::loncommon;
1.68 www 69: use Apache::lonlocal;
1.117 raeburn 70: use Apache::longroup;
1.190 raeburn 71: use Apache::lonuserutils;
1.307 raeburn 72: use Apache::loncoursequeueadmin;
1.139 albertel 73: use LONCAPA qw(:DEFAULT :match);
1.456 raeburn 74: use HTML::Entities;
1.1 www 75:
1.20 harris41 76: my $loginscript; # piece of javascript used in two separate instances
77: my $authformnop;
78: my $authformkrb;
79: my $authformint;
80: my $authformfsys;
81: my $authformloc;
1.449 raeburn 82: my $authformlti;
1.20 harris41 83:
1.94 matthew 84: sub initialize_authen_forms {
1.227 raeburn 85: my ($dom,$formname,$curr_authtype,$mode) = @_;
86: my ($krbdef,$krbdefdom) = &Apache::loncommon::get_kerberos_defaults($dom);
87: my %param = ( formname => $formname,
1.187 raeburn 88: kerb_def_dom => $krbdefdom,
1.227 raeburn 89: kerb_def_auth => $krbdef,
1.187 raeburn 90: domain => $dom,
91: );
1.188 raeburn 92: my %abv_auth = &auth_abbrev();
1.449 raeburn 93: if ($curr_authtype =~ /^(krb4|krb5|internal|localauth|unix|lti):(.*)$/) {
1.188 raeburn 94: my $long_auth = $1;
1.227 raeburn 95: my $curr_autharg = $2;
1.188 raeburn 96: my %abv_auth = &auth_abbrev();
97: $param{'curr_authtype'} = $abv_auth{$long_auth};
98: if ($long_auth =~ /^krb(4|5)$/) {
99: $param{'curr_kerb_ver'} = $1;
1.227 raeburn 100: $param{'curr_autharg'} = $curr_autharg;
1.188 raeburn 101: }
1.205 raeburn 102: if ($mode eq 'modifyuser') {
103: $param{'mode'} = $mode;
104: }
1.187 raeburn 105: }
1.227 raeburn 106: $loginscript = &Apache::loncommon::authform_header(%param);
107: $authformkrb = &Apache::loncommon::authform_kerberos(%param);
1.31 matthew 108: $authformnop = &Apache::loncommon::authform_nochange(%param);
109: $authformint = &Apache::loncommon::authform_internal(%param);
110: $authformfsys = &Apache::loncommon::authform_filesystem(%param);
111: $authformloc = &Apache::loncommon::authform_local(%param);
1.449 raeburn 112: $authformlti = &Apache::loncommon::authform_lti(%param);
1.20 harris41 113: }
114:
1.188 raeburn 115: sub auth_abbrev {
116: my %abv_auth = (
1.368 raeburn 117: krb5 => 'krb',
118: krb4 => 'krb',
119: internal => 'int',
120: localauth => 'loc',
121: unix => 'fsys',
1.449 raeburn 122: lti => 'lti',
1.188 raeburn 123: );
124: return %abv_auth;
125: }
1.43 www 126:
1.134 raeburn 127: # ====================================================
128:
1.378 raeburn 129: sub user_quotas {
1.134 raeburn 130: my ($ccuname,$ccdomain) = @_;
131: my %lt = &Apache::lonlocal::texthash(
1.267 raeburn 132: 'usrt' => "User Tools",
133: 'cust' => "Custom quota",
134: 'chqu' => "Change quota",
1.134 raeburn 135: );
1.378 raeburn 136:
1.149 raeburn 137: my $quota_javascript = <<"END_SCRIPT";
138: <script type="text/javascript">
1.301 bisitz 139: // <![CDATA[
1.378 raeburn 140: function quota_changes(caller,context) {
141: var customoff = document.getElementById('custom_'+context+'quota_off');
142: var customon = document.getElementById('custom_'+context+'quota_on');
143: var number = document.getElementById(context+'quota');
1.149 raeburn 144: if (caller == "custom") {
1.378 raeburn 145: if (customoff) {
146: if (customoff.checked) {
147: number.value = "";
148: }
1.149 raeburn 149: }
150: }
151: if (caller == "quota") {
1.378 raeburn 152: if (customon) {
153: customon.checked = true;
154: }
1.149 raeburn 155: }
1.378 raeburn 156: return;
1.149 raeburn 157: }
1.301 bisitz 158: // ]]>
1.149 raeburn 159: </script>
160: END_SCRIPT
1.378 raeburn 161: my $longinsttype;
162: my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($ccdomain);
1.267 raeburn 163: my $output = $quota_javascript."\n".
164: '<h3>'.$lt{'usrt'}.'</h3>'."\n".
165: &Apache::loncommon::start_data_table();
166:
1.418 raeburn 167: if ((&Apache::lonnet::allowed('mut',$ccdomain)) ||
168: (&Apache::lonnet::allowed('udp',$ccdomain))) {
1.275 raeburn 169: $output .= &build_tools_display($ccuname,$ccdomain,'tools');
1.267 raeburn 170: }
1.378 raeburn 171:
172: my %titles = &Apache::lonlocal::texthash (
173: portfolio => "Disk space allocated to user's portfolio files",
1.385 bisitz 174: author => "Disk space allocated to user's Authoring Space (if role assigned)",
1.378 raeburn 175: );
176: foreach my $name ('portfolio','author') {
177: my ($currquota,$quotatype,$inststatus,$defquota) =
178: &Apache::loncommon::get_user_quota($ccuname,$ccdomain,$name);
179: if ($longinsttype eq '') {
180: if ($inststatus ne '') {
181: if ($usertypes->{$inststatus} ne '') {
182: $longinsttype = $usertypes->{$inststatus};
183: }
184: }
185: }
186: my ($showquota,$custom_on,$custom_off,$defaultinfo);
187: $custom_on = ' ';
188: $custom_off = ' checked="checked" ';
189: if ($quotatype eq 'custom') {
190: $custom_on = $custom_off;
191: $custom_off = ' ';
192: $showquota = $currquota;
193: if ($longinsttype eq '') {
194: $defaultinfo = &mt('For this user, the default quota would be [_1]'
1.383 raeburn 195: .' MB.',$defquota);
1.378 raeburn 196: } else {
197: $defaultinfo = &mt("For this user, the default quota would be [_1]".
1.383 raeburn 198: " MB, as determined by the user's institutional".
1.378 raeburn 199: " affiliation ([_2]).",$defquota,$longinsttype);
200: }
201: } else {
202: if ($longinsttype eq '') {
203: $defaultinfo = &mt('For this user, the default quota is [_1]'
1.383 raeburn 204: .' MB.',$defquota);
1.378 raeburn 205: } else {
206: $defaultinfo = &mt("For this user, the default quota of [_1]".
1.383 raeburn 207: " MB, is determined by the user's institutional".
1.378 raeburn 208: " affiliation ([_2]).",$defquota,$longinsttype);
209: }
210: }
211:
212: if (&Apache::lonnet::allowed('mpq',$ccdomain)) {
213: $output .= '<tr class="LC_info_row">'."\n".
214: ' <td>'.$titles{$name}.'</td>'."\n".
215: ' </tr>'."\n".
216: &Apache::loncommon::start_data_table_row()."\n".
1.390 bisitz 217: ' <td><span class="LC_nobreak">'.
218: &mt('Current quota: [_1] MB',$currquota).'</span> '.
1.378 raeburn 219: $defaultinfo.'</td>'."\n".
220: &Apache::loncommon::end_data_table_row()."\n".
221: &Apache::loncommon::start_data_table_row()."\n".
222: ' <td><span class="LC_nobreak">'.$lt{'chqu'}.
223: ': <label>'.
224: '<input type="radio" name="custom_'.$name.'quota" id="custom_'.$name.'quota_off" '.
1.379 raeburn 225: 'value="0" '.$custom_off.' onchange="javascript:quota_changes('."'custom','$name'".');"'.
1.390 bisitz 226: ' /><span class="LC_nobreak">'.
227: &mt('Default ([_1] MB)',$defquota).'</span></label> '.
1.378 raeburn 228: ' <label><input type="radio" name="custom_'.$name.'quota" id="custom_'.$name.'quota_on" '.
1.379 raeburn 229: 'value="1" '.$custom_on.' onchange="javascript:quota_changes('."'custom','$name'".');"'.
1.378 raeburn 230: ' />'.$lt{'cust'}.':</label> '.
1.379 raeburn 231: '<input type="text" name="'.$name.'quota" id="'.$name.'quota" size ="5" '.
232: 'value="'.$showquota.'" onfocus="javascript:quota_changes('."'quota','$name'".');"'.
1.390 bisitz 233: ' /> '.&mt('MB').'</span></td>'."\n".
1.378 raeburn 234: &Apache::loncommon::end_data_table_row()."\n";
235: }
236: }
1.267 raeburn 237: $output .= &Apache::loncommon::end_data_table();
1.134 raeburn 238: return $output;
239: }
240:
1.275 raeburn 241: sub build_tools_display {
242: my ($ccuname,$ccdomain,$context) = @_;
1.306 raeburn 243: my (@usertools,%userenv,$output,@options,%validations,%reqtitles,%reqdisplay,
1.332 raeburn 244: $colspan,$isadv,%domconfig);
1.275 raeburn 245: my %lt = &Apache::lonlocal::texthash (
246: 'blog' => "Personal User Blog",
247: 'aboutme' => "Personal Information Page",
1.385 bisitz 248: 'webdav' => "WebDAV access to Authoring Spaces (if SSL and author/co-author)",
1.275 raeburn 249: 'portfolio' => "Personal User Portfolio",
1.459 raeburn 250: 'timezone' => "Can set Time Zone",
1.275 raeburn 251: 'avai' => "Available",
252: 'cusa' => "availability",
253: 'chse' => "Change setting",
254: 'usde' => "Use default",
255: 'uscu' => "Use custom",
256: 'official' => 'Can request creation of official courses',
1.299 raeburn 257: 'unofficial' => 'Can request creation of unofficial courses',
258: 'community' => 'Can request creation of communities',
1.384 raeburn 259: 'textbook' => 'Can request creation of textbook courses',
1.411 raeburn 260: 'placement' => 'Can request creation of placement tests',
1.449 raeburn 261: 'lti' => 'Can request creation of LTI courses',
1.362 raeburn 262: 'requestauthor' => 'Can request author space',
1.275 raeburn 263: );
1.462 raeburn 264: $isadv = &Apache::lonnet::is_advanced_user($ccdomain,$ccuname);
1.279 raeburn 265: if ($context eq 'requestcourses') {
1.275 raeburn 266: %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
1.299 raeburn 267: 'requestcourses.official','requestcourses.unofficial',
1.411 raeburn 268: 'requestcourses.community','requestcourses.textbook',
1.449 raeburn 269: 'requestcourses.placement','requestcourses.lti');
270: @usertools = ('official','unofficial','community','textbook','placement','lti');
1.309 raeburn 271: @options =('norequest','approval','autolimit','validate');
1.306 raeburn 272: %validations = &Apache::lonnet::auto_courserequest_checks($ccdomain);
273: %reqtitles = &courserequest_titles();
274: %reqdisplay = &courserequest_display();
275: $colspan = ' colspan="2"';
1.332 raeburn 276: %domconfig =
277: &Apache::lonnet::get_dom('configuration',['requestcourses'],$ccdomain);
1.362 raeburn 278: } elsif ($context eq 'requestauthor') {
279: %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
280: 'requestauthor');
281: @usertools = ('requestauthor');
282: @options =('norequest','approval','automatic');
283: %reqtitles = &requestauthor_titles();
284: %reqdisplay = &requestauthor_display();
285: $colspan = ' colspan="2"';
286: %domconfig =
287: &Apache::lonnet::get_dom('configuration',['requestauthor'],$ccdomain);
1.275 raeburn 288: } else {
289: %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
1.361 raeburn 290: 'tools.aboutme','tools.portfolio','tools.blog',
1.459 raeburn 291: 'tools.webdav','tools.timezone');
292: @usertools = ('aboutme','blog','webdav','portfolio','timezone');
1.275 raeburn 293: }
294: foreach my $item (@usertools) {
1.306 raeburn 295: my ($custom_access,$curr_access,$cust_on,$cust_off,$tool_on,$tool_off,
296: $currdisp,$custdisp,$custradio);
1.275 raeburn 297: $cust_off = 'checked="checked" ';
298: $tool_on = 'checked="checked" ';
1.463 raeburn 299: $curr_access =
1.275 raeburn 300: &Apache::lonnet::usertools_access($ccuname,$ccdomain,$item,undef,
1.462 raeburn 301: $context,\%userenv,'',
302: {'is_adv' => $isadv});
1.362 raeburn 303: if ($context eq 'requestauthor') {
304: if ($userenv{$context} ne '') {
305: $cust_on = ' checked="checked" ';
306: $cust_off = '';
307: }
308: } elsif ($userenv{$context.'.'.$item} ne '') {
1.306 raeburn 309: $cust_on = ' checked="checked" ';
310: $cust_off = '';
311: }
312: if ($context eq 'requestcourses') {
313: if ($userenv{$context.'.'.$item} eq '') {
1.314 raeburn 314: $custom_access = &mt('Currently from default setting.');
1.306 raeburn 315: } else {
316: $custom_access = &mt('Currently from custom setting.');
1.275 raeburn 317: }
1.362 raeburn 318: } elsif ($context eq 'requestauthor') {
319: if ($userenv{$context} eq '') {
320: $custom_access = &mt('Currently from default setting.');
321: } else {
322: $custom_access = &mt('Currently from custom setting.');
323: }
1.275 raeburn 324: } else {
1.306 raeburn 325: if ($userenv{$context.'.'.$item} eq '') {
1.314 raeburn 326: $custom_access =
1.306 raeburn 327: &mt('Availability determined currently from default setting.');
328: if (!$curr_access) {
329: $tool_off = 'checked="checked" ';
330: $tool_on = '';
331: }
332: } else {
1.314 raeburn 333: $custom_access =
1.306 raeburn 334: &mt('Availability determined currently from custom setting.');
335: if ($userenv{$context.'.'.$item} == 0) {
336: $tool_off = 'checked="checked" ';
337: $tool_on = '';
338: }
1.275 raeburn 339: }
340: }
341: $output .= ' <tr class="LC_info_row">'."\n".
1.306 raeburn 342: ' <td'.$colspan.'>'.$lt{$item}.'</td>'."\n".
1.275 raeburn 343: ' </tr>'."\n".
1.306 raeburn 344: &Apache::loncommon::start_data_table_row()."\n";
1.418 raeburn 345:
1.362 raeburn 346: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.306 raeburn 347: my ($curroption,$currlimit);
1.362 raeburn 348: my $envkey = $context.'.'.$item;
349: if ($context eq 'requestauthor') {
350: $envkey = $context;
351: }
352: if ($userenv{$envkey} ne '') {
353: $curroption = $userenv{$envkey};
1.332 raeburn 354: } else {
355: my (@inststatuses);
1.362 raeburn 356: if ($context eq 'requestcourses') {
357: $curroption =
358: &Apache::loncoursequeueadmin::get_processtype('course',$ccuname,$ccdomain,
359: $isadv,$ccdomain,$item,
360: \@inststatuses,\%domconfig);
361: } else {
362: $curroption =
363: &Apache::loncoursequeueadmin::get_processtype('requestauthor',$ccuname,$ccdomain,
364: $isadv,$ccdomain,undef,
365: \@inststatuses,\%domconfig);
366: }
1.332 raeburn 367: }
1.306 raeburn 368: if (!$curroption) {
369: $curroption = 'norequest';
370: }
371: if ($curroption =~ /^autolimit=(\d*)$/) {
372: $currlimit = $1;
1.314 raeburn 373: if ($currlimit eq '') {
374: $currdisp = &mt('Yes, automatic creation');
375: } else {
376: $currdisp = &mt('Yes, up to [quant,_1,request]/user',$currlimit);
377: }
1.306 raeburn 378: } else {
379: $currdisp = $reqdisplay{$curroption};
380: }
381: $custdisp = '<table>';
382: foreach my $option (@options) {
383: my $val = $option;
384: if ($option eq 'norequest') {
385: $val = 0;
386: }
387: if ($option eq 'validate') {
388: my $canvalidate = 0;
389: if (ref($validations{$item}) eq 'HASH') {
390: if ($validations{$item}{'_custom_'}) {
391: $canvalidate = 1;
392: }
393: }
394: next if (!$canvalidate);
395: }
396: my $checked = '';
397: if ($option eq $curroption) {
398: $checked = ' checked="checked"';
399: } elsif ($option eq 'autolimit') {
400: if ($curroption =~ /^autolimit/) {
401: $checked = ' checked="checked"';
402: }
403: }
1.362 raeburn 404: my $name = 'crsreq_'.$item;
405: if ($context eq 'requestauthor') {
406: $name = $item;
407: }
1.306 raeburn 408: $custdisp .= '<tr><td><span class="LC_nobreak"><label>'.
1.362 raeburn 409: '<input type="radio" name="'.$name.'" '.
410: 'value="'.$val.'"'.$checked.' />'.
1.306 raeburn 411: $reqtitles{$option}.'</label> ';
412: if ($option eq 'autolimit') {
1.362 raeburn 413: $custdisp .= '<input type="text" name="'.$name.
414: '_limit" size="1" '.
1.314 raeburn 415: 'value="'.$currlimit.'" /></span><br />'.
416: $reqtitles{'unlimited'};
1.362 raeburn 417: } else {
418: $custdisp .= '</span>';
419: }
420: $custdisp .= '</td></tr>';
1.306 raeburn 421: }
422: $custdisp .= '</table>';
423: $custradio = '</span></td><td>'.&mt('Custom setting').'<br />'.$custdisp;
424: } else {
425: $currdisp = ($curr_access?&mt('Yes'):&mt('No'));
1.362 raeburn 426: my $name = $context.'_'.$item;
427: if ($context eq 'requestauthor') {
428: $name = $context;
429: }
1.306 raeburn 430: $custdisp = '<span class="LC_nobreak"><label>'.
1.362 raeburn 431: '<input type="radio" name="'.$name.'"'.
1.361 raeburn 432: ' value="1" '.$tool_on.'/>'.&mt('On').'</label> <label>'.
1.362 raeburn 433: '<input type="radio" name="'.$name.'" value="0" '.
1.306 raeburn 434: $tool_off.'/>'.&mt('Off').'</label></span>';
435: $custradio = (' 'x2).'--'.$lt{'cusa'}.': '.$custdisp.
436: '</span>';
437: }
438: $output .= ' <td'.$colspan.'>'.$custom_access.(' 'x4).
1.419 raeburn 439: $lt{'avai'}.': '.$currdisp.'</td>'."\n".
1.418 raeburn 440: &Apache::loncommon::end_data_table_row()."\n";
441: unless (&Apache::lonnet::allowed('udp',$ccdomain)) {
442: $output .=
1.275 raeburn 443: &Apache::loncommon::start_data_table_row()."\n".
1.306 raeburn 444: ' <td style="vertical-align:top;"><span class="LC_nobreak">'.
445: $lt{'chse'}.': <label>'.
1.275 raeburn 446: '<input type="radio" name="custom'.$item.'" value="0" '.
1.306 raeburn 447: $cust_off.'/>'.$lt{'usde'}.'</label>'.(' ' x3).
448: '<label><input type="radio" name="custom'.$item.'" value="1" '.
449: $cust_on.'/>'.$lt{'uscu'}.'</label>'.$custradio.'</td>'.
1.275 raeburn 450: &Apache::loncommon::end_data_table_row()."\n";
1.418 raeburn 451: }
1.275 raeburn 452: }
453: return $output;
454: }
455:
1.300 raeburn 456: sub coursereq_externaluser {
457: my ($ccuname,$ccdomain,$cdom) = @_;
1.306 raeburn 458: my (@usertools,@options,%validations,%userenv,$output);
1.300 raeburn 459: my %lt = &Apache::lonlocal::texthash (
460: 'official' => 'Can request creation of official courses',
461: 'unofficial' => 'Can request creation of unofficial courses',
462: 'community' => 'Can request creation of communities',
1.384 raeburn 463: 'textbook' => 'Can request creation of textbook courses',
1.411 raeburn 464: 'placement' => 'Can request creation of placement tests',
1.300 raeburn 465: );
466:
467: %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
468: 'reqcrsotherdom.official','reqcrsotherdom.unofficial',
1.411 raeburn 469: 'reqcrsotherdom.community','reqcrsotherdom.textbook',
470: 'reqcrsotherdom.placement');
471: @usertools = ('official','unofficial','community','textbook','placement');
1.309 raeburn 472: @options = ('approval','validate','autolimit');
1.306 raeburn 473: %validations = &Apache::lonnet::auto_courserequest_checks($cdom);
474: my $optregex = join('|',@options);
475: my %reqtitles = &courserequest_titles();
1.300 raeburn 476: foreach my $item (@usertools) {
1.306 raeburn 477: my ($curroption,$currlimit,$tooloff);
1.300 raeburn 478: if ($userenv{'reqcrsotherdom.'.$item} ne '') {
479: my @curr = split(',',$userenv{'reqcrsotherdom.'.$item});
1.314 raeburn 480: foreach my $req (@curr) {
481: if ($req =~ /^\Q$cdom\E\:($optregex)=?(\d*)$/) {
482: $curroption = $1;
483: $currlimit = $2;
484: last;
1.306 raeburn 485: }
486: }
1.314 raeburn 487: if (!$curroption) {
488: $curroption = 'norequest';
489: $tooloff = ' checked="checked"';
490: }
1.306 raeburn 491: } else {
492: $curroption = 'norequest';
493: $tooloff = ' checked="checked"';
494: }
495: $output.= &Apache::loncommon::start_data_table_row()."\n".
1.314 raeburn 496: ' <td><span class="LC_nobreak">'.$lt{$item}.': </span></td><td>'.
497: '<table><tr><td valign="top">'."\n".
1.306 raeburn 498: '<label><input type="radio" name="reqcrsotherdom_'.$item.
1.314 raeburn 499: '" value=""'.$tooloff.' />'.$reqtitles{'norequest'}.
500: '</label></td>';
1.306 raeburn 501: foreach my $option (@options) {
502: if ($option eq 'validate') {
503: my $canvalidate = 0;
504: if (ref($validations{$item}) eq 'HASH') {
505: if ($validations{$item}{'_external_'}) {
506: $canvalidate = 1;
507: }
508: }
509: next if (!$canvalidate);
510: }
511: my $checked = '';
512: if ($option eq $curroption) {
513: $checked = ' checked="checked"';
514: }
1.314 raeburn 515: $output .= '<td valign="top"><span class="LC_nobreak"><label>'.
1.306 raeburn 516: '<input type="radio" name="reqcrsotherdom_'.$item.
517: '" value="'.$option.'"'.$checked.' />'.
1.314 raeburn 518: $reqtitles{$option}.'</label>';
1.306 raeburn 519: if ($option eq 'autolimit') {
1.314 raeburn 520: $output .= ' <input type="text" name="reqcrsotherdom_'.
1.306 raeburn 521: $item.'_limit" size="1" '.
1.314 raeburn 522: 'value="'.$currlimit.'" /></span>'.
523: '<br />'.$reqtitles{'unlimited'};
524: } else {
525: $output .= '</span>';
1.300 raeburn 526: }
1.314 raeburn 527: $output .= '</td>';
1.300 raeburn 528: }
1.314 raeburn 529: $output .= '</td></tr></table></td>'."\n".
1.300 raeburn 530: &Apache::loncommon::end_data_table_row()."\n";
531: }
532: return $output;
533: }
534:
1.362 raeburn 535: sub domainrole_req {
536: my ($ccuname,$ccdomain) = @_;
537: return '<br /><h3>'.
538: &mt('User Can Request Assignment of Domain Roles?').
539: '</h3>'."\n".
540: &Apache::loncommon::start_data_table().
541: &build_tools_display($ccuname,$ccdomain,
542: 'requestauthor').
543: &Apache::loncommon::end_data_table();
544: }
545:
1.306 raeburn 546: sub courserequest_titles {
547: my %titles = &Apache::lonlocal::texthash (
548: official => 'Official',
549: unofficial => 'Unofficial',
550: community => 'Communities',
1.384 raeburn 551: textbook => 'Textbook',
1.411 raeburn 552: placement => 'Placement Tests',
1.449 raeburn 553: lti => 'LTI Provider',
1.306 raeburn 554: norequest => 'Not allowed',
1.309 raeburn 555: approval => 'Approval by Dom. Coord.',
1.306 raeburn 556: validate => 'With validation',
557: autolimit => 'Numerical limit',
1.314 raeburn 558: unlimited => '(blank for unlimited)',
1.306 raeburn 559: );
560: return %titles;
561: }
562:
563: sub courserequest_display {
564: my %titles = &Apache::lonlocal::texthash (
1.309 raeburn 565: approval => 'Yes, need approval',
1.306 raeburn 566: validate => 'Yes, with validation',
567: norequest => 'No',
568: );
569: return %titles;
570: }
571:
1.362 raeburn 572: sub requestauthor_titles {
573: my %titles = &Apache::lonlocal::texthash (
574: norequest => 'Not allowed',
575: approval => 'Approval by Dom. Coord.',
576: automatic => 'Automatic approval',
577: );
578: return %titles;
579:
580: }
581:
582: sub requestauthor_display {
583: my %titles = &Apache::lonlocal::texthash (
584: approval => 'Yes, need approval',
585: automatic => 'Yes, automatic approval',
586: norequest => 'No',
587: );
588: return %titles;
589: }
590:
1.383 raeburn 591: sub requestchange_display {
592: my %titles = &Apache::lonlocal::texthash (
593: approval => "availability set to 'on' (approval required)",
594: automatic => "availability set to 'on' (automatic approval)",
595: norequest => "availability set to 'off'",
596: );
597: return %titles;
598: }
599:
1.362 raeburn 600: sub curr_requestauthor {
601: my ($uname,$udom,$isadv,$inststatuses,$domconfig) = @_;
602: return unless ((ref($inststatuses) eq 'ARRAY') && (ref($domconfig) eq 'HASH'));
603: if ($uname eq '' || $udom eq '') {
604: $uname = $env{'user.name'};
605: $udom = $env{'user.domain'};
606: $isadv = $env{'user.adv'};
607: }
608: my (%userenv,%settings,$val);
609: my @options = ('automatic','approval');
610: %userenv =
611: &Apache::lonnet::userenvironment($udom,$uname,'requestauthor','inststatus');
612: if ($userenv{'requestauthor'}) {
613: $val = $userenv{'requestauthor'};
614: @{$inststatuses} = ('_custom_');
615: } else {
616: my %alltasks;
617: if (ref($domconfig->{'requestauthor'}) eq 'HASH') {
618: %settings = %{$domconfig->{'requestauthor'}};
619: if (($isadv) && ($settings{'_LC_adv'} ne '')) {
620: $val = $settings{'_LC_adv'};
621: @{$inststatuses} = ('_LC_adv_');
622: } else {
623: if ($userenv{'inststatus'} ne '') {
624: @{$inststatuses} = split(',',$userenv{'inststatus'});
625: } else {
626: @{$inststatuses} = ('default');
627: }
628: foreach my $status (@{$inststatuses}) {
629: if (exists($settings{$status})) {
630: my $value = $settings{$status};
631: next unless ($value);
632: unless (exists($alltasks{$value})) {
633: if (ref($alltasks{$value}) eq 'ARRAY') {
634: unless(grep(/^\Q$status\E$/,@{$alltasks{$value}})) {
635: push(@{$alltasks{$value}},$status);
636: }
637: } else {
638: @{$alltasks{$value}} = ($status);
639: }
640: }
641: }
642: }
643: foreach my $option (@options) {
644: if ($alltasks{$option}) {
645: $val = $option;
646: last;
647: }
648: }
649: }
650: }
651: }
652: return $val;
653: }
654:
1.2 www 655: # =================================================================== Phase one
1.1 www 656:
1.42 matthew 657: sub print_username_entry_form {
1.439 raeburn 658: my ($r,$context,$response,$srch,$forcenewuser,$crstype,$brcrum,
659: $permission) = @_;
1.101 albertel 660: my $defdom=$env{'request.role.domain'};
1.160 raeburn 661: my $formtoset = 'crtuser';
662: if (exists($env{'form.startrolename'})) {
663: $formtoset = 'docustom';
664: $env{'form.rolename'} = $env{'form.startrolename'};
1.207 raeburn 665: } elsif ($env{'form.origform'} eq 'crtusername') {
666: $formtoset = $env{'form.origform'};
1.160 raeburn 667: }
668:
669: my ($jsback,$elements) = &crumb_utilities();
670:
671: my $jscript = &Apache::loncommon::studentbrowser_javascript()."\n".
1.165 albertel 672: '<script type="text/javascript">'."\n".
1.301 bisitz 673: '// <![CDATA['."\n".
674: &Apache::lonhtmlcommon::set_form_elements($elements->{$formtoset})."\n".
675: '// ]]>'."\n".
1.162 raeburn 676: '</script>'."\n";
1.160 raeburn 677:
1.324 raeburn 678: my %existingroles=&Apache::lonuserutils::my_custom_roles($crstype);
679: if (($env{'form.action'} eq 'custom') && (keys(%existingroles) > 0)
680: && (&Apache::lonnet::allowed('mcr','/'))) {
681: $jscript .= &customrole_javascript();
682: }
1.224 raeburn 683: my $helpitem = 'Course_Change_Privileges';
684: if ($env{'form.action'} eq 'custom') {
1.439 raeburn 685: if ($context eq 'course') {
686: $helpitem = 'Course_Editing_Custom_Roles';
687: } elsif ($context eq 'domain') {
688: $helpitem = 'Domain_Editing_Custom_Roles';
689: }
1.224 raeburn 690: } elsif ($env{'form.action'} eq 'singlestudent') {
691: $helpitem = 'Course_Add_Student';
1.416 raeburn 692: } elsif ($env{'form.action'} eq 'accesslogs') {
693: $helpitem = 'Domain_User_Access_Logs';
1.439 raeburn 694: } elsif ($context eq 'author') {
695: $helpitem = 'Author_Change_Privileges';
696: } elsif ($context eq 'domain') {
697: if ($permission->{'cusr'}) {
698: $helpitem = 'Domain_Change_Privileges';
699: } elsif ($permission->{'view'}) {
700: $helpitem = 'Domain_View_Privileges';
701: } else {
702: undef($helpitem);
703: }
1.224 raeburn 704: }
1.422 raeburn 705: my %breadcrumb_text = &singleuser_breadcrumb($crstype,$context,$defdom);
1.351 raeburn 706: if ($env{'form.action'} eq 'custom') {
707: push(@{$brcrum},
708: {href=>"javascript:backPage(document.crtuser)",
709: text=>"Pick custom role",
710: help => $helpitem,}
711: );
712: } else {
713: push (@{$brcrum},
714: {href => "javascript:backPage(document.crtuser)",
715: text => $breadcrumb_text{'search'},
716: help => $helpitem,
717: faq => 282,
718: bug => 'Instructor Interface',}
719: );
720: }
721: my %loaditems = (
722: 'onload' => "javascript:setFormElements(document.$formtoset)",
723: );
724: my $args = {bread_crumbs => $brcrum,
725: bread_crumbs_component => 'User Management',
726: add_entries => \%loaditems,};
727: $r->print(&Apache::loncommon::start_page('User Management',$jscript,$args));
728:
1.71 sakharuk 729: my %lt=&Apache::lonlocal::texthash(
1.229 raeburn 730: 'srst' => 'Search for a user and enroll as a student',
1.318 raeburn 731: 'srme' => 'Search for a user and enroll as a member',
1.229 raeburn 732: 'srad' => 'Search for a user and modify/add user information or roles',
1.422 raeburn 733: 'srvu' => 'Search for a user and view user information and roles',
1.416 raeburn 734: 'srva' => 'Search for a user and view access log information',
1.71 sakharuk 735: 'usr' => "Username",
736: 'dom' => "Domain",
1.324 raeburn 737: 'ecrp' => "Define or Edit Custom Role",
738: 'nr' => "role name",
1.282 schafran 739: 'cre' => "Next",
1.71 sakharuk 740: );
1.351 raeburn 741:
1.214 raeburn 742: if ($env{'form.action'} eq 'custom') {
1.190 raeburn 743: if (&Apache::lonnet::allowed('mcr','/')) {
1.324 raeburn 744: my $newroletext = &mt('Define new custom role:');
745: $r->print('<form action="/adm/createuser" method="post" name="docustom">'.
746: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'.
747: '<input type="hidden" name="phase" value="selected_custom_edit" />'.
748: '<h3>'.$lt{'ecrp'}.'</h3>'.
749: &Apache::loncommon::start_data_table().
750: &Apache::loncommon::start_data_table_row().
751: '<td>');
752: if (keys(%existingroles) > 0) {
753: $r->print('<br /><label><input type="radio" name="customroleaction" value="new" checked="checked" onclick="setCustomFields();" /><b>'.$newroletext.'</b></label>');
754: } else {
755: $r->print('<br /><input type="hidden" name="customroleaction" value="new" /><b>'.$newroletext.'</b>');
756: }
757: $r->print('</td><td align="center">'.$lt{'nr'}.'<br /><input type="text" size="15" name="newrolename" onfocus="setCustomAction('."'new'".');" /></td>'.
758: &Apache::loncommon::end_data_table_row());
759: if (keys(%existingroles) > 0) {
760: $r->print(&Apache::loncommon::start_data_table_row().'<td><br />'.
761: '<label><input type="radio" name="customroleaction" value="edit" onclick="setCustomFields();"/><b>'.
762: &mt('View/Modify existing role:').'</b></label></td>'.
763: '<td align="center"><br />'.
764: '<select name="rolename" onchange="setCustomAction('."'edit'".');">'.
1.326 raeburn 765: '<option value="" selected="selected">'.
1.324 raeburn 766: &mt('Select'));
767: foreach my $role (sort(keys(%existingroles))) {
1.326 raeburn 768: $r->print('<option value="'.$role.'">'.$role.'</option>');
1.324 raeburn 769: }
770: $r->print('</select>'.
771: '</td>'.
772: &Apache::loncommon::end_data_table_row());
773: }
774: $r->print(&Apache::loncommon::end_data_table().'<p>'.
775: '<input name="customeditor" type="submit" value="'.
776: $lt{'cre'}.'" /></p>'.
777: '</form>');
1.190 raeburn 778: }
1.213 raeburn 779: } else {
1.229 raeburn 780: my $actiontext = $lt{'srad'};
1.436 raeburn 781: my $fixeddom;
1.213 raeburn 782: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 783: if ($crstype eq 'Community') {
784: $actiontext = $lt{'srme'};
785: } else {
786: $actiontext = $lt{'srst'};
787: }
1.416 raeburn 788: } elsif ($env{'form.action'} eq 'accesslogs') {
1.417 raeburn 789: $actiontext = $lt{'srva'};
1.436 raeburn 790: $fixeddom = 1;
1.422 raeburn 791: } elsif (($env{'form.action'} eq 'singleuser') &&
792: ($context eq 'domain') && (!&Apache::lonnet::allowed('mau',$defdom))) {
793: $actiontext = $lt{'srvu'};
1.439 raeburn 794: $fixeddom = 1;
1.213 raeburn 795: }
1.324 raeburn 796: $r->print("<h3>$actiontext</h3>");
1.213 raeburn 797: if ($env{'form.origform'} ne 'crtusername') {
1.415 raeburn 798: if ($response) {
799: $r->print("\n<div>$response</div>".
800: '<br clear="all" />');
801: }
1.213 raeburn 802: }
1.436 raeburn 803: $r->print(&entry_form($defdom,$srch,$forcenewuser,$context,$response,$crstype,$fixeddom));
1.107 www 804: }
1.110 albertel 805: }
806:
1.324 raeburn 807: sub customrole_javascript {
808: my $js = <<"END";
809: <script type="text/javascript">
810: // <![CDATA[
811:
812: function setCustomFields() {
813: if (document.docustom.customroleaction.length > 0) {
814: for (var i=0; i<document.docustom.customroleaction.length; i++) {
815: if (document.docustom.customroleaction[i].checked) {
816: if (document.docustom.customroleaction[i].value == 'new') {
817: document.docustom.rolename.selectedIndex = 0;
818: } else {
819: document.docustom.newrolename.value = '';
820: }
821: }
822: }
823: }
824: return;
825: }
826:
827: function setCustomAction(caller) {
828: if (document.docustom.customroleaction.length > 0) {
829: for (var i=0; i<document.docustom.customroleaction.length; i++) {
830: if (document.docustom.customroleaction[i].value == caller) {
831: document.docustom.customroleaction[i].checked = true;
832: }
833: }
834: }
835: setCustomFields();
836: return;
837: }
838:
839: // ]]>
840: </script>
841: END
842: return $js;
843: }
844:
1.160 raeburn 845: sub entry_form {
1.416 raeburn 846: my ($dom,$srch,$forcenewuser,$context,$responsemsg,$crstype,$fixeddom) = @_;
1.229 raeburn 847: my ($usertype,$inexact);
1.214 raeburn 848: if (ref($srch) eq 'HASH') {
849: if (($srch->{'srchin'} eq 'dom') &&
850: ($srch->{'srchby'} eq 'uname') &&
851: ($srch->{'srchtype'} eq 'exact') &&
852: ($srch->{'srchdomain'} ne '') &&
853: ($srch->{'srchterm'} ne '')) {
1.353 raeburn 854: my (%curr_rules,%got_rules);
1.214 raeburn 855: my ($rules,$ruleorder) =
856: &Apache::lonnet::inst_userrules($srch->{'srchdomain'},'username');
1.353 raeburn 857: $usertype = &Apache::lonuserutils::check_usertype($srch->{'srchdomain'},$srch->{'srchterm'},$rules,\%curr_rules,\%got_rules);
1.229 raeburn 858: } else {
859: $inexact = 1;
1.214 raeburn 860: }
1.207 raeburn 861: }
1.438 raeburn 862: my ($cancreate,$noinstd);
863: if ($env{'form.action'} eq 'accesslogs') {
864: $noinstd = 1;
865: } else {
866: $cancreate =
867: &Apache::lonuserutils::can_create_user($dom,$context,$usertype);
868: }
1.412 raeburn 869: my ($userpicker,$cansearch) =
1.179 raeburn 870: &Apache::loncommon::user_picker($dom,$srch,$forcenewuser,
1.438 raeburn 871: 'document.crtuser',$cancreate,$usertype,$context,$fixeddom,$noinstd);
1.160 raeburn 872: my $srchbutton = &mt('Search');
1.229 raeburn 873: if ($env{'form.action'} eq 'singlestudent') {
874: $srchbutton = &mt('Search and Enroll');
1.416 raeburn 875: } elsif ($env{'form.action'} eq 'accesslogs') {
876: $srchbutton = &mt('Search');
1.229 raeburn 877: } elsif ($cancreate && $responsemsg ne '' && $inexact) {
878: $srchbutton = &mt('Search or Add New User');
879: }
1.412 raeburn 880: my $output;
881: if ($cansearch) {
882: $output = <<"ENDBLOCK";
1.160 raeburn 883: <form action="/adm/createuser" method="post" name="crtuser">
1.190 raeburn 884: <input type="hidden" name="action" value="$env{'form.action'}" />
1.160 raeburn 885: <input type="hidden" name="phase" value="get_user_info" />
886: $userpicker
1.179 raeburn 887: <input name="userrole" type="button" value="$srchbutton" onclick="javascript:validateEntry(document.crtuser)" />
1.160 raeburn 888: </form>
1.207 raeburn 889: ENDBLOCK
1.412 raeburn 890: } else {
891: $output = '<p>'.$userpicker.'</p>';
892: }
1.422 raeburn 893: if (($env{'form.phase'} eq '') && ($env{'form.action'} ne 'accesslogs') &&
1.430 raeburn 894: (!(($env{'form.action'} eq 'singleuser') && ($context eq 'domain') &&
1.422 raeburn 895: (!&Apache::lonnet::allowed('mau',$env{'request.role.domain'}))))) {
1.207 raeburn 896: my $defdom=$env{'request.role.domain'};
1.446 raeburn 897: my ($trusted,$untrusted);
1.444 raeburn 898: if ($context eq 'course') {
1.446 raeburn 899: ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('enroll',$defdom);
1.444 raeburn 900: } elsif ($context eq 'author') {
1.446 raeburn 901: ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('othcoau',$defdom);
1.444 raeburn 902: } elsif ($context eq 'domain') {
1.446 raeburn 903: ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('domroles',$defdom);
1.444 raeburn 904: }
1.446 raeburn 905: my $domform = &Apache::loncommon::select_dom_form($defdom,'srchdomain',undef,undef,undef,$trusted,$untrusted);
1.207 raeburn 906: my %lt=&Apache::lonlocal::texthash(
1.229 raeburn 907: 'enro' => 'Enroll one student',
1.318 raeburn 908: 'enrm' => 'Enroll one member',
1.229 raeburn 909: 'admo' => 'Add/modify a single user',
910: 'crea' => 'create new user if required',
911: 'uskn' => "username is known",
1.207 raeburn 912: 'crnu' => 'Create a new user',
913: 'usr' => 'Username',
914: 'dom' => 'in domain',
1.229 raeburn 915: 'enrl' => 'Enroll',
916: 'cram' => 'Create/Modify user',
1.207 raeburn 917: );
1.229 raeburn 918: my $sellink=&Apache::loncommon::selectstudent_link('crtusername','srchterm','srchdomain');
919: my ($title,$buttontext,$showresponse);
1.318 raeburn 920: if ($env{'form.action'} eq 'singlestudent') {
921: if ($crstype eq 'Community') {
922: $title = $lt{'enrm'};
923: } else {
924: $title = $lt{'enro'};
925: }
1.229 raeburn 926: $buttontext = $lt{'enrl'};
927: } else {
928: $title = $lt{'admo'};
929: $buttontext = $lt{'cram'};
930: }
931: if ($cancreate) {
932: $title .= ' <span class="LC_cusr_subheading">('.$lt{'crea'}.')</span>';
933: } else {
934: $title .= ' <span class="LC_cusr_subheading">('.$lt{'uskn'}.')</span>';
935: }
936: if ($env{'form.origform'} eq 'crtusername') {
937: $showresponse = $responsemsg;
938: }
1.207 raeburn 939: $output .= <<"ENDDOCUMENT";
1.229 raeburn 940: <br />
1.207 raeburn 941: <form action="/adm/createuser" method="post" name="crtusername">
942: <input type="hidden" name="action" value="$env{'form.action'}" />
943: <input type="hidden" name="phase" value="createnewuser" />
944: <input type="hidden" name="srchtype" value="exact" />
1.233 raeburn 945: <input type="hidden" name="srchby" value="uname" />
1.207 raeburn 946: <input type="hidden" name="srchin" value="dom" />
947: <input type="hidden" name="forcenewuser" value="1" />
948: <input type="hidden" name="origform" value="crtusername" />
1.229 raeburn 949: <h3>$title</h3>
950: $showresponse
1.207 raeburn 951: <table>
952: <tr>
953: <td>$lt{'usr'}:</td>
954: <td><input type="text" size="15" name="srchterm" /></td>
955: <td> $lt{'dom'}:</td><td>$domform</td>
1.229 raeburn 956: <td> $sellink </td>
957: <td> <input name="userrole" type="submit" value="$buttontext" /></td>
1.207 raeburn 958: </tr>
959: </table>
960: </form>
1.160 raeburn 961: ENDDOCUMENT
1.207 raeburn 962: }
1.160 raeburn 963: return $output;
964: }
1.110 albertel 965:
966: sub user_modification_js {
1.113 raeburn 967: my ($pjump_def,$dc_setcourse_code,$nondc_setsection_code,$groupslist)=@_;
968:
1.110 albertel 969: return <<END;
970: <script type="text/javascript" language="Javascript">
1.301 bisitz 971: // <![CDATA[
1.314 raeburn 972:
1.110 albertel 973: $pjump_def
974: $dc_setcourse_code
975:
976: function dateset() {
977: eval("document.cu."+document.cu.pres_marker.value+
978: ".value=document.cu.pres_value.value");
1.359 www 979: modalWindow.close();
1.110 albertel 980: }
981:
1.113 raeburn 982: $nondc_setsection_code
1.301 bisitz 983: // ]]>
1.110 albertel 984: </script>
985: END
1.2 www 986: }
987:
988: # =================================================================== Phase two
1.160 raeburn 989: sub print_user_selection_page {
1.351 raeburn 990: my ($r,$response,$srch,$srch_results,$srcharray,$context,$opener_elements,$crstype,$brcrum) = @_;
1.160 raeburn 991: my @fields = ('username','domain','lastname','firstname','permanentemail');
992: my $sortby = $env{'form.sortby'};
993:
994: if (!grep(/^\Q$sortby\E$/,@fields)) {
995: $sortby = 'lastname';
996: }
997:
998: my ($jsback,$elements) = &crumb_utilities();
999:
1000: my $jscript = (<<ENDSCRIPT);
1001: <script type="text/javascript">
1.301 bisitz 1002: // <![CDATA[
1.160 raeburn 1003: function pickuser(uname,udom) {
1004: document.usersrchform.seluname.value=uname;
1005: document.usersrchform.seludom.value=udom;
1006: document.usersrchform.phase.value="userpicked";
1007: document.usersrchform.submit();
1008: }
1009:
1010: $jsback
1.301 bisitz 1011: // ]]>
1.160 raeburn 1012: </script>
1013: ENDSCRIPT
1014:
1015: my %lt=&Apache::lonlocal::texthash(
1.179 raeburn 1016: 'usrch' => "User Search to add/modify roles",
1017: 'stusrch' => "User Search to enroll student",
1.318 raeburn 1018: 'memsrch' => "User Search to enroll member",
1.416 raeburn 1019: 'srcva' => "Search for a user and view access log information",
1.422 raeburn 1020: 'usrvu' => "User Search to view user roles",
1.179 raeburn 1021: 'usel' => "Select a user to add/modify roles",
1.422 raeburn 1022: 'suvr' => "Select a user to view roles",
1.318 raeburn 1023: 'stusel' => "Select a user to enroll as a student",
1024: 'memsel' => "Select a user to enroll as a member",
1.416 raeburn 1025: 'vacsel' => "Select a user to view access log",
1.160 raeburn 1026: 'username' => "username",
1027: 'domain' => "domain",
1028: 'lastname' => "last name",
1029: 'firstname' => "first name",
1030: 'permanentemail' => "permanent e-mail",
1031: );
1.302 raeburn 1032: if ($context eq 'requestcrs') {
1033: $r->print('<div>');
1034: } else {
1.422 raeburn 1035: my %breadcrumb_text = &singleuser_breadcrumb($crstype,$context,$srch->{'srchdomain'});
1.351 raeburn 1036: my $helpitem;
1037: if ($env{'form.action'} eq 'singleuser') {
1038: $helpitem = 'Course_Change_Privileges';
1039: } elsif ($env{'form.action'} eq 'singlestudent') {
1040: $helpitem = 'Course_Add_Student';
1.439 raeburn 1041: } elsif ($context eq 'author') {
1042: $helpitem = 'Author_Change_Privileges';
1043: } elsif ($context eq 'domain') {
1044: $helpitem = 'Domain_Change_Privileges';
1.351 raeburn 1045: }
1046: push (@{$brcrum},
1047: {href => "javascript:backPage(document.usersrchform,'','')",
1048: text => $breadcrumb_text{'search'},
1049: faq => 282,
1050: bug => 'Instructor Interface',},
1051: {href => "javascript:backPage(document.usersrchform,'get_user_info','select')",
1052: text => $breadcrumb_text{'userpicked'},
1053: faq => 282,
1054: bug => 'Instructor Interface',
1055: help => $helpitem}
1056: );
1057: $r->print(&Apache::loncommon::start_page('User Management',$jscript,{bread_crumbs => $brcrum}));
1.302 raeburn 1058: if ($env{'form.action'} eq 'singleuser') {
1.422 raeburn 1059: my $readonly;
1060: if (($context eq 'domain') && (!&Apache::lonnet::allowed('mau',$srch->{'srchdomain'}))) {
1061: $readonly = 1;
1062: $r->print("<b>$lt{'usrvu'}</b><br />");
1063: } else {
1064: $r->print("<b>$lt{'usrch'}</b><br />");
1065: }
1.318 raeburn 1066: $r->print(&entry_form($srch->{'srchdomain'},$srch,undef,$context,undef,$crstype));
1.422 raeburn 1067: if ($readonly) {
1068: $r->print('<h3>'.$lt{'suvr'}.'</h3>');
1069: } else {
1070: $r->print('<h3>'.$lt{'usel'}.'</h3>');
1071: }
1.302 raeburn 1072: } elsif ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1073: $r->print($jscript."<b>");
1074: if ($crstype eq 'Community') {
1075: $r->print($lt{'memsrch'});
1076: } else {
1077: $r->print($lt{'stusrch'});
1078: }
1079: $r->print("</b><br />");
1080: $r->print(&entry_form($srch->{'srchdomain'},$srch,undef,$context,undef,$crstype));
1081: $r->print('</form><h3>');
1082: if ($crstype eq 'Community') {
1083: $r->print($lt{'memsel'});
1084: } else {
1085: $r->print($lt{'stusel'});
1086: }
1087: $r->print('</h3>');
1.416 raeburn 1088: } elsif ($env{'form.action'} eq 'accesslogs') {
1089: $r->print("<b>$lt{'srcva'}</b><br />");
1.438 raeburn 1090: $r->print(&entry_form($srch->{'srchdomain'},$srch,undef,$context,undef,undef,1));
1.416 raeburn 1091: $r->print('<h3>'.$lt{'vacsel'}.'</h3>');
1.302 raeburn 1092: }
1.179 raeburn 1093: }
1.380 bisitz 1094: $r->print('<form name="usersrchform" method="post" action="">'.
1.160 raeburn 1095: &Apache::loncommon::start_data_table()."\n".
1096: &Apache::loncommon::start_data_table_header_row()."\n".
1097: ' <th> </th>'."\n");
1098: foreach my $field (@fields) {
1099: $r->print(' <th><a href="javascript:document.usersrchform.sortby.value='.
1100: "'".$field."'".';document.usersrchform.submit();">'.
1101: $lt{$field}.'</a></th>'."\n");
1102: }
1103: $r->print(&Apache::loncommon::end_data_table_header_row());
1104:
1105: my @sorted_users = sort {
1.167 albertel 1106: lc($srch_results->{$a}->{$sortby}) cmp lc($srch_results->{$b}->{$sortby})
1.160 raeburn 1107: ||
1.167 albertel 1108: lc($srch_results->{$a}->{lastname}) cmp lc($srch_results->{$b}->{lastname})
1.160 raeburn 1109: ||
1110: lc($srch_results->{$a}->{firstname}) cmp lc($srch_results->{$b}->{firstname})
1.167 albertel 1111: ||
1112: lc($a) cmp lc($b)
1.160 raeburn 1113: } (keys(%$srch_results));
1114:
1115: foreach my $user (@sorted_users) {
1116: my ($uname,$udom) = split(/:/,$user);
1.302 raeburn 1117: my $onclick;
1118: if ($context eq 'requestcrs') {
1.314 raeburn 1119: $onclick =
1.302 raeburn 1120: 'onclick="javascript:gochoose('."'$uname','$udom',".
1121: "'$srch_results->{$user}->{firstname}',".
1122: "'$srch_results->{$user}->{lastname}',".
1123: "'$srch_results->{$user}->{permanentemail}'".');"';
1124: } else {
1.314 raeburn 1125: $onclick =
1.302 raeburn 1126: ' onclick="javascript:pickuser('."'".$uname."'".','."'".$udom."'".');"';
1127: }
1.160 raeburn 1128: $r->print(&Apache::loncommon::start_data_table_row().
1.302 raeburn 1129: '<td><input type="button" name="seluser" value="'.&mt('Select').'" '.
1130: $onclick.' /></td>'.
1.160 raeburn 1131: '<td><tt>'.$uname.'</tt></td>'.
1132: '<td><tt>'.$udom.'</tt></td>');
1133: foreach my $field ('lastname','firstname','permanentemail') {
1134: $r->print('<td>'.$srch_results->{$user}->{$field}.'</td>');
1135: }
1136: $r->print(&Apache::loncommon::end_data_table_row());
1137: }
1138: $r->print(&Apache::loncommon::end_data_table().'<br /><br />');
1.179 raeburn 1139: if (ref($srcharray) eq 'ARRAY') {
1140: foreach my $item (@{$srcharray}) {
1141: $r->print('<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n");
1142: }
1143: }
1.160 raeburn 1144: $r->print(' <input type="hidden" name="sortby" value="'.$sortby.'" />'."\n".
1145: ' <input type="hidden" name="seluname" value="" />'."\n".
1146: ' <input type="hidden" name="seludom" value="" />'."\n".
1.179 raeburn 1147: ' <input type="hidden" name="currstate" value="select" />'."\n".
1.190 raeburn 1148: ' <input type="hidden" name="phase" value="get_user_info" />'."\n".
1.214 raeburn 1149: ' <input type="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n");
1.302 raeburn 1150: if ($context eq 'requestcrs') {
1151: $r->print($opener_elements.'</form></div>');
1152: } else {
1.351 raeburn 1153: $r->print($response.'</form>');
1.302 raeburn 1154: }
1.160 raeburn 1155: }
1156:
1157: sub print_user_query_page {
1.351 raeburn 1158: my ($r,$caller,$brcrum) = @_;
1.160 raeburn 1159: # FIXME - this is for a network-wide name search (similar to catalog search)
1160: # To use frames with similar behavior to catalog/portfolio search.
1161: # To be implemented.
1162: return;
1163: }
1164:
1.42 matthew 1165: sub print_user_modification_page {
1.375 raeburn 1166: my ($r,$ccuname,$ccdomain,$srch,$response,$context,$permission,$crstype,
1167: $brcrum,$showcredits) = @_;
1.185 raeburn 1168: if (($ccuname eq '') || ($ccdomain eq '')) {
1.215 raeburn 1169: my $usermsg = &mt('No username and/or domain provided.');
1170: $env{'form.phase'} = '';
1.439 raeburn 1171: &print_username_entry_form($r,$context,$usermsg,'','',$crstype,$brcrum,
1172: $permission);
1.58 www 1173: return;
1174: }
1.213 raeburn 1175: my ($form,$formname);
1176: if ($env{'form.action'} eq 'singlestudent') {
1177: $form = 'document.enrollstudent';
1178: $formname = 'enrollstudent';
1179: } else {
1180: $form = 'document.cu';
1181: $formname = 'cu';
1182: }
1.188 raeburn 1183: my %abv_auth = &auth_abbrev();
1.227 raeburn 1184: my (%rulematch,%inst_results,$newuser,%alerts,%curr_rules,%got_rules);
1.185 raeburn 1185: my $uhome=&Apache::lonnet::homeserver($ccuname,$ccdomain);
1186: if ($uhome eq 'no_host') {
1.215 raeburn 1187: my $usertype;
1188: my ($rules,$ruleorder) =
1189: &Apache::lonnet::inst_userrules($ccdomain,'username');
1190: $usertype =
1.353 raeburn 1191: &Apache::lonuserutils::check_usertype($ccdomain,$ccuname,$rules,
1.362 raeburn 1192: \%curr_rules,\%got_rules);
1.215 raeburn 1193: my $cancreate =
1194: &Apache::lonuserutils::can_create_user($ccdomain,$context,
1195: $usertype);
1196: if (!$cancreate) {
1.292 bisitz 1197: my $helplink = 'javascript:helpMenu('."'display'".')';
1.215 raeburn 1198: my %usertypetext = (
1199: official => 'institutional',
1200: unofficial => 'non-institutional',
1201: );
1202: my $response;
1203: if ($env{'form.origform'} eq 'crtusername') {
1.362 raeburn 1204: $response = '<span class="LC_warning">'.
1205: &mt('No match found for the username [_1] in LON-CAPA domain: [_2]',
1206: '<b>'.$ccuname.'</b>',$ccdomain).
1.215 raeburn 1207: '</span><br />';
1208: }
1.292 bisitz 1209: $response .= '<p class="LC_warning">'
1210: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
1.418 raeburn 1211: .' ';
1212: if ($context eq 'domain') {
1213: $response .= &mt('Please contact a [_1] for assistance.',
1214: &Apache::lonnet::plaintext('dc'));
1215: } else {
1216: $response .= &mt('Please contact the [_1]helpdesk[_2] for assistance.'
1217: ,'<a href="'.$helplink.'">','</a>');
1218: }
1219: $response .= '</p><br />';
1.215 raeburn 1220: $env{'form.phase'} = '';
1.439 raeburn 1221: &print_username_entry_form($r,$context,$response,undef,undef,$crstype,$brcrum,
1222: $permission);
1.215 raeburn 1223: return;
1224: }
1.188 raeburn 1225: $newuser = 1;
1.193 raeburn 1226: my $checkhash;
1227: my $checks = { 'username' => 1 };
1.196 raeburn 1228: $checkhash->{$ccuname.':'.$ccdomain} = { 'newuser' => $newuser };
1.193 raeburn 1229: &Apache::loncommon::user_rule_check($checkhash,$checks,
1.196 raeburn 1230: \%alerts,\%rulematch,\%inst_results,\%curr_rules,\%got_rules);
1231: if (ref($alerts{'username'}) eq 'HASH') {
1232: if (ref($alerts{'username'}{$ccdomain}) eq 'HASH') {
1233: my $domdesc =
1.193 raeburn 1234: &Apache::lonnet::domain($ccdomain,'description');
1.196 raeburn 1235: if ($alerts{'username'}{$ccdomain}{$ccuname}) {
1236: my $userchkmsg;
1237: if (ref($curr_rules{$ccdomain}) eq 'HASH') {
1238: $userchkmsg =
1239: &Apache::loncommon::instrule_disallow_msg('username',
1.193 raeburn 1240: $domdesc,1).
1241: &Apache::loncommon::user_rule_formats($ccdomain,
1242: $domdesc,$curr_rules{$ccdomain}{'username'},
1243: 'username');
1.196 raeburn 1244: }
1.215 raeburn 1245: $env{'form.phase'} = '';
1.439 raeburn 1246: &print_username_entry_form($r,$context,$userchkmsg,undef,undef,$crstype,$brcrum,
1247: $permission);
1.196 raeburn 1248: return;
1.215 raeburn 1249: }
1.193 raeburn 1250: }
1.185 raeburn 1251: }
1.187 raeburn 1252: } else {
1.188 raeburn 1253: $newuser = 0;
1.185 raeburn 1254: }
1.160 raeburn 1255: if ($response) {
1.215 raeburn 1256: $response = '<br />'.$response;
1.160 raeburn 1257: }
1.149 raeburn 1258:
1.52 matthew 1259: my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
1.88 raeburn 1260: my $dc_setcourse_code = '';
1.119 raeburn 1261: my $nondc_setsection_code = '';
1.112 albertel 1262: my %loaditem;
1.114 albertel 1263:
1.216 raeburn 1264: my $groupslist = &Apache::lonuserutils::get_groupslist();
1.88 raeburn 1265:
1.375 raeburn 1266: my $js = &validation_javascript($context,$ccdomain,$pjump_def,$crstype,
1.216 raeburn 1267: $groupslist,$newuser,$formname,\%loaditem);
1.422 raeburn 1268: my %breadcrumb_text = &singleuser_breadcrumb($crstype,$context,$ccdomain);
1.224 raeburn 1269: my $helpitem = 'Course_Change_Privileges';
1270: if ($env{'form.action'} eq 'singlestudent') {
1271: $helpitem = 'Course_Add_Student';
1.439 raeburn 1272: } elsif ($context eq 'author') {
1273: $helpitem = 'Author_Change_Privileges';
1274: } elsif ($context eq 'domain') {
1275: $helpitem = 'Domain_Change_Privileges';
1.224 raeburn 1276: }
1.351 raeburn 1277: push (@{$brcrum},
1278: {href => "javascript:backPage($form)",
1279: text => $breadcrumb_text{'search'},
1280: faq => 282,
1281: bug => 'Instructor Interface',});
1282: if ($env{'form.phase'} eq 'userpicked') {
1283: push(@{$brcrum},
1284: {href => "javascript:backPage($form,'get_user_info','select')",
1285: text => $breadcrumb_text{'userpicked'},
1286: faq => 282,
1287: bug => 'Instructor Interface',});
1288: }
1289: push(@{$brcrum},
1290: {href => "javascript:backPage($form,'$env{'form.phase'}','modify')",
1291: text => $breadcrumb_text{'modify'},
1292: faq => 282,
1293: bug => 'Instructor Interface',
1294: help => $helpitem});
1295: my $args = {'add_entries' => \%loaditem,
1296: 'bread_crumbs' => $brcrum,
1297: 'bread_crumbs_component' => 'User Management'};
1298: if ($env{'form.popup'}) {
1299: $args->{'no_nav_bar'} = 1;
1300: }
1301: my $start_page =
1302: &Apache::loncommon::start_page('User Management',$js,$args);
1.3 www 1303:
1.25 matthew 1304: my $forminfo =<<"ENDFORMINFO";
1.216 raeburn 1305: <form action="/adm/createuser" method="post" name="$formname">
1.190 raeburn 1306: <input type="hidden" name="phase" value="update_user_data" />
1.188 raeburn 1307: <input type="hidden" name="ccuname" value="$ccuname" />
1308: <input type="hidden" name="ccdomain" value="$ccdomain" />
1.157 albertel 1309: <input type="hidden" name="pres_value" value="" />
1310: <input type="hidden" name="pres_type" value="" />
1311: <input type="hidden" name="pres_marker" value="" />
1.25 matthew 1312: ENDFORMINFO
1.375 raeburn 1313: my (%inccourses,$roledom,$defaultcredits);
1.329 raeburn 1314: if ($context eq 'course') {
1315: $inccourses{$env{'request.course.id'}}=1;
1316: $roledom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1.375 raeburn 1317: if ($showcredits) {
1318: $defaultcredits = &Apache::lonuserutils::get_defaultcredits();
1319: }
1.329 raeburn 1320: } elsif ($context eq 'author') {
1321: $roledom = $env{'request.role.domain'};
1322: } elsif ($context eq 'domain') {
1323: foreach my $key (keys(%env)) {
1324: $roledom = $env{'request.role.domain'};
1325: if ($key=~/^user\.priv\.cm\.\/($roledom)\/($match_username)/) {
1326: $inccourses{$1.'_'.$2}=1;
1327: }
1328: }
1329: } else {
1330: foreach my $key (keys(%env)) {
1331: if ($key=~/^user\.priv\.cm\.\/($match_domain)\/($match_username)/) {
1332: $inccourses{$1.'_'.$2}=1;
1333: }
1.2 www 1334: }
1.24 matthew 1335: }
1.389 bisitz 1336: my $title = '';
1.216 raeburn 1337: if ($newuser) {
1.427 raeburn 1338: my ($portfolioform,$domroleform);
1.267 raeburn 1339: if ((&Apache::lonnet::allowed('mpq',$env{'request.role.domain'})) ||
1340: (&Apache::lonnet::allowed('mut',$env{'request.role.domain'}))) {
1341: # Current user has quota or user tools modification privileges
1.378 raeburn 1342: $portfolioform = '<br />'.&user_quotas($ccuname,$ccdomain);
1.134 raeburn 1343: }
1.383 raeburn 1344: if ((&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) &&
1345: ($ccdomain eq $env{'request.role.domain'})) {
1.362 raeburn 1346: $domroleform = '<br />'.&domainrole_req($ccuname,$ccdomain);
1347: }
1.227 raeburn 1348: &initialize_authen_forms($ccdomain,$formname);
1.188 raeburn 1349: my %lt=&Apache::lonlocal::texthash(
1350: 'lg' => 'Login Data',
1.190 raeburn 1351: 'hs' => "Home Server",
1.188 raeburn 1352: );
1.185 raeburn 1353: $r->print(<<ENDTITLE);
1.110 albertel 1354: $start_page
1.160 raeburn 1355: $response
1.25 matthew 1356: $forminfo
1.31 matthew 1357: <script type="text/javascript" language="Javascript">
1.301 bisitz 1358: // <![CDATA[
1.20 harris41 1359: $loginscript
1.301 bisitz 1360: // ]]>
1.31 matthew 1361: </script>
1.20 harris41 1362: <input type='hidden' name='makeuser' value='1' />
1.185 raeburn 1363: ENDTITLE
1.213 raeburn 1364: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1365: if ($crstype eq 'Community') {
1.389 bisitz 1366: $title = &mt('Create New User [_1] in domain [_2] as a member',
1367: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.318 raeburn 1368: } else {
1.389 bisitz 1369: $title = &mt('Create New User [_1] in domain [_2] as a student',
1370: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.318 raeburn 1371: }
1.389 bisitz 1372: } else {
1373: $title = &mt('Create New User [_1] in domain [_2]',
1374: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.213 raeburn 1375: }
1.389 bisitz 1376: $r->print('<h2>'.$title.'</h2>'."\n");
1377: $r->print('<div class="LC_left_float">');
1.393 raeburn 1378: $r->print(&personal_data_display($ccuname,$ccdomain,$newuser,$context,
1379: $inst_results{$ccuname.':'.$ccdomain}));
1380: # Option to disable student/employee ID conflict checking not offerred for new users.
1.187 raeburn 1381: my ($home_server_pick,$numlib) =
1382: &Apache::loncommon::home_server_form_item($ccdomain,'hserver',
1383: 'default','hide');
1384: if ($numlib > 1) {
1385: $r->print("
1.185 raeburn 1386: <br />
1.187 raeburn 1387: $lt{'hs'}: $home_server_pick
1388: <br />");
1389: } else {
1390: $r->print($home_server_pick);
1391: }
1.304 raeburn 1392: if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
1.362 raeburn 1393: $r->print('<br /><h3>'.
1394: &mt('User Can Request Creation of Courses/Communities in this Domain?').'</h3>'.
1.304 raeburn 1395: &Apache::loncommon::start_data_table().
1396: &build_tools_display($ccuname,$ccdomain,
1397: 'requestcourses').
1398: &Apache::loncommon::end_data_table());
1399: }
1.188 raeburn 1400: $r->print('</div>'."\n".'<div class="LC_left_float"><h3>'.
1401: $lt{'lg'}.'</h3>');
1.185 raeburn 1402: my ($fixedauth,$varauth,$authmsg);
1.193 raeburn 1403: if (ref($rulematch{$ccuname.':'.$ccdomain}) eq 'HASH') {
1404: my $matchedrule = $rulematch{$ccuname.':'.$ccdomain}{'username'};
1405: my ($rules,$ruleorder) =
1406: &Apache::lonnet::inst_userrules($ccdomain,'username');
1.185 raeburn 1407: if (ref($rules) eq 'HASH') {
1.193 raeburn 1408: if (ref($rules->{$matchedrule}) eq 'HASH') {
1409: my $authtype = $rules->{$matchedrule}{'authtype'};
1.185 raeburn 1410: if ($authtype !~ /^(krb4|krb5|int|fsys|loc)$/) {
1.190 raeburn 1411: $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1.275 raeburn 1412: } else {
1.193 raeburn 1413: my $authparm = $rules->{$matchedrule}{'authparm'};
1.273 raeburn 1414: $authmsg = $rules->{$matchedrule}{'authmsg'};
1.185 raeburn 1415: if ($authtype =~ /^krb(4|5)$/) {
1416: my $ver = $1;
1417: if ($authparm ne '') {
1418: $fixedauth = <<"KERB";
1419: <input type="hidden" name="login" value="krb" />
1420: <input type="hidden" name="krbver" value="$ver" />
1421: <input type="hidden" name="krbarg" value="$authparm" />
1422: KERB
1423: }
1424: } else {
1425: $fixedauth =
1426: '<input type="hidden" name="login" value="'.$authtype.'" />'."\n";
1.193 raeburn 1427: if ($rules->{$matchedrule}{'authparmfixed'}) {
1.185 raeburn 1428: $fixedauth .=
1429: '<input type="hidden" name="'.$authtype.'arg" value="'.$authparm.'" />'."\n";
1430: } else {
1.273 raeburn 1431: if ($authtype eq 'int') {
1432: $varauth = '<br />'.
1.301 bisitz 1433: &mt('[_1] Internally authenticated (with initial password [_2])','','<input type="password" size="10" name="intarg" value="" />')."<label><input type=\"checkbox\" name=\"visible\" onclick='if (this.checked) { this.form.intarg.type=\"text\" } else { this.form.intarg.type=\"password\" }' />".&mt('Visible input').'</label>';
1.273 raeburn 1434: } elsif ($authtype eq 'loc') {
1435: $varauth = '<br />'.
1436: &mt('[_1] Local Authentication with argument [_2]','','<input type="text" name="'.$authtype.'arg" value="" />')."\n";
1437: } else {
1438: $varauth =
1.185 raeburn 1439: '<input type="text" name="'.$authtype.'arg" value="" />'."\n";
1.273 raeburn 1440: }
1.185 raeburn 1441: }
1442: }
1443: }
1444: } else {
1.190 raeburn 1445: $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1.185 raeburn 1446: }
1447: }
1448: if ($authmsg) {
1449: $r->print(<<ENDAUTH);
1450: $fixedauth
1451: $authmsg
1452: $varauth
1453: ENDAUTH
1454: }
1455: } else {
1.190 raeburn 1456: $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1.187 raeburn 1457: }
1.427 raeburn 1458: $r->print($portfolioform.$domroleform);
1.215 raeburn 1459: if ($env{'form.action'} eq 'singlestudent') {
1460: $r->print(&date_sections_select($context,$newuser,$formname,
1.375 raeburn 1461: $permission,$crstype,$ccuname,
1462: $ccdomain,$showcredits));
1.215 raeburn 1463: }
1464: $r->print('</div><div class="LC_clear_float_footer"></div>');
1.216 raeburn 1465: } else { # user already exists
1.389 bisitz 1466: $r->print($start_page.$forminfo);
1.213 raeburn 1467: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1468: if ($crstype eq 'Community') {
1.389 bisitz 1469: $title = &mt('Enroll one member: [_1] in domain [_2]',
1470: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.318 raeburn 1471: } else {
1.389 bisitz 1472: $title = &mt('Enroll one student: [_1] in domain [_2]',
1473: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.318 raeburn 1474: }
1.213 raeburn 1475: } else {
1.418 raeburn 1476: if ($permission->{'cusr'}) {
1477: $title = &mt('Modify existing user: [_1] in domain [_2]',
1478: '"'.$ccuname.'"','"'.$ccdomain.'"');
1479: } else {
1480: $title = &mt('Existing user: [_1] in domain [_2]',
1.389 bisitz 1481: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.418 raeburn 1482: }
1.213 raeburn 1483: }
1.389 bisitz 1484: $r->print('<h2>'.$title.'</h2>'."\n");
1485: $r->print('<div class="LC_left_float">');
1.393 raeburn 1486: $r->print(&personal_data_display($ccuname,$ccdomain,$newuser,$context,
1487: $inst_results{$ccuname.':'.$ccdomain}));
1.430 raeburn 1488: if ((&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) ||
1.418 raeburn 1489: (&Apache::lonnet::allowed('udp',$env{'request.role.domain'}))) {
1.450 raeburn 1490: $r->print('<br /><h3>'.&mt('User Can Request Creation of Courses/Communities in this Domain?').'</h3>'."\n");
1491: if (($env{'request.role.domain'} eq $ccdomain) ||
1492: (&Apache::lonnet::will_trust('reqcrs',$ccdomain,$env{'request.role.domain'}))) {
1493: $r->print(&Apache::loncommon::start_data_table());
1494: if ($env{'request.role.domain'} eq $ccdomain) {
1495: $r->print(&build_tools_display($ccuname,$ccdomain,'requestcourses'));
1496: } else {
1.444 raeburn 1497: $r->print(&coursereq_externaluser($ccuname,$ccdomain,
1498: $env{'request.role.domain'}));
1499: }
1.450 raeburn 1500: $r->print(&Apache::loncommon::end_data_table());
1501: } else {
1502: $r->print(&mt('Domain configuration for this domain prohibits course creation by users from domain: "[_1]"',
1503: &Apache::lonnet::domain($ccdomain,'description')));
1.300 raeburn 1504: }
1.275 raeburn 1505: }
1.199 raeburn 1506: $r->print('</div>');
1.427 raeburn 1507: my @order = ('auth','quota','tools','requestauthor');
1.362 raeburn 1508: my %user_text;
1509: my ($isadv,$isauthor) =
1.418 raeburn 1510: &Apache::lonnet::is_advanced_user($ccdomain,$ccuname);
1.362 raeburn 1511: if ((!$isauthor) &&
1.418 raeburn 1512: ((&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) ||
1513: (&Apache::lonnet::allowed('udp',$env{'request.role.domain'}))) &&
1.430 raeburn 1514: ($env{'request.role.domain'} eq $ccdomain)) {
1.362 raeburn 1515: $user_text{'requestauthor'} = &domainrole_req($ccuname,$ccdomain);
1516: }
1.451 raeburn 1517: $user_text{'auth'} = &user_authentication($ccuname,$ccdomain,$formname,$crstype,$permission);
1.267 raeburn 1518: if ((&Apache::lonnet::allowed('mpq',$ccdomain)) ||
1.418 raeburn 1519: (&Apache::lonnet::allowed('mut',$ccdomain)) ||
1520: (&Apache::lonnet::allowed('udp',$ccdomain))) {
1.188 raeburn 1521: # Current user has quota modification privileges
1.378 raeburn 1522: $user_text{'quota'} = &user_quotas($ccuname,$ccdomain);
1.267 raeburn 1523: }
1524: if (!&Apache::lonnet::allowed('mpq',$ccdomain)) {
1525: if (&Apache::lonnet::allowed('mpq',$env{'request.role.domain'})) {
1526: my %lt=&Apache::lonlocal::texthash(
1.385 bisitz 1527: 'dska' => "Disk quotas for user's portfolio and Authoring Space",
1528: 'youd' => "You do not have privileges to modify the portfolio and/or Authoring Space quotas for this user.",
1.267 raeburn 1529: 'ichr' => "If a change is required, contact a domain coordinator for the domain",
1530: );
1.362 raeburn 1531: $user_text{'quota'} = <<ENDNOPORTPRIV;
1.188 raeburn 1532: <h3>$lt{'dska'}</h3>
1533: $lt{'youd'} $lt{'ichr'}: $ccdomain
1534: ENDNOPORTPRIV
1.267 raeburn 1535: }
1536: }
1537: if (!&Apache::lonnet::allowed('mut',$ccdomain)) {
1538: if (&Apache::lonnet::allowed('mut',$env{'request.role.domain'})) {
1539: my %lt=&Apache::lonlocal::texthash(
1540: 'utav' => "User Tools Availability",
1.361 raeburn 1541: 'yodo' => "You do not have privileges to modify Portfolio, Blog, WebDAV, or Personal Information Page settings for this user.",
1.267 raeburn 1542: 'ifch' => "If a change is required, contact a domain coordinator for the domain",
1543: );
1.362 raeburn 1544: $user_text{'tools'} = <<ENDNOTOOLSPRIV;
1.267 raeburn 1545: <h3>$lt{'utav'}</h3>
1546: $lt{'yodo'} $lt{'ifch'}: $ccdomain
1547: ENDNOTOOLSPRIV
1548: }
1.188 raeburn 1549: }
1.362 raeburn 1550: my $gotdiv = 0;
1551: foreach my $item (@order) {
1552: if ($user_text{$item} ne '') {
1553: unless ($gotdiv) {
1554: $r->print('<div class="LC_left_float">');
1555: $gotdiv = 1;
1556: }
1557: $r->print('<br />'.$user_text{$item});
1558: }
1559: }
1560: if ($env{'form.action'} eq 'singlestudent') {
1561: unless ($gotdiv) {
1562: $r->print('<div class="LC_left_float">');
1.213 raeburn 1563: }
1.375 raeburn 1564: my $credits;
1565: if ($showcredits) {
1566: $credits = &get_user_credits($ccuname,$ccdomain,$defaultcredits);
1567: if ($credits eq '') {
1568: $credits = $defaultcredits;
1569: }
1570: }
1.374 raeburn 1571: $r->print(&date_sections_select($context,$newuser,$formname,
1.375 raeburn 1572: $permission,$crstype,$ccuname,
1573: $ccdomain,$showcredits));
1.374 raeburn 1574: }
1.362 raeburn 1575: if ($gotdiv) {
1576: $r->print('</div><div class="LC_clear_float_footer"></div>');
1.188 raeburn 1577: }
1.418 raeburn 1578: my $statuses;
1579: if (($context eq 'domain') && (&Apache::lonnet::allowed('udp',$ccdomain)) &&
1580: (!&Apache::lonnet::allowed('mau',$ccdomain))) {
1581: $statuses = ['active'];
1582: } elsif (($context eq 'course') && ((&Apache::lonnet::allowed('vcl',$env{'request.course.id'})) ||
1583: ($env{'request.course.sec'} &&
1584: &Apache::lonnet::allowed('vcl',$env{'request.course.id'}.'/'.$env{'request.course.sec'})))) {
1.430 raeburn 1585: $statuses = ['active'];
1.418 raeburn 1586: }
1.217 raeburn 1587: if ($env{'form.action'} ne 'singlestudent') {
1.329 raeburn 1588: &display_existing_roles($r,$ccuname,$ccdomain,\%inccourses,$context,
1.418 raeburn 1589: $roledom,$crstype,$showcredits,$statuses);
1.217 raeburn 1590: }
1.25 matthew 1591: } ## End of new user/old user logic
1.218 raeburn 1592: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1593: my $btntxt;
1594: if ($crstype eq 'Community') {
1595: $btntxt = &mt('Enroll Member');
1596: } else {
1597: $btntxt = &mt('Enroll Student');
1598: }
1599: $r->print('<br /><input type="button" value="'.$btntxt.'" onclick="setSections(this.form)" />'."\n");
1.418 raeburn 1600: } elsif ($permission->{'cusr'}) {
1.393 raeburn 1601: $r->print('<div class="LC_left_float">'.
1602: '<fieldset><legend>'.&mt('Add Roles').'</legend>');
1.218 raeburn 1603: my $addrolesdisplay = 0;
1604: if ($context eq 'domain' || $context eq 'author') {
1605: $addrolesdisplay = &new_coauthor_roles($r,$ccuname,$ccdomain);
1606: }
1607: if ($context eq 'domain') {
1.357 raeburn 1608: my $add_domainroles = &new_domain_roles($r,$ccdomain);
1.218 raeburn 1609: if (!$addrolesdisplay) {
1610: $addrolesdisplay = $add_domainroles;
1.2 www 1611: }
1.375 raeburn 1612: $r->print(&course_level_dc($env{'request.role.domain'},$showcredits));
1.393 raeburn 1613: $r->print('</fieldset></div><div class="LC_clear_float_footer"></div>'.
1614: '<br /><input type="button" value="'.&mt('Save').'" onclick="setCourse()" />'."\n");
1.218 raeburn 1615: } elsif ($context eq 'author') {
1616: if ($addrolesdisplay) {
1.393 raeburn 1617: $r->print('</fieldset></div><div class="LC_clear_float_footer"></div>'.
1618: '<br /><input type="button" value="'.&mt('Save').'"');
1.218 raeburn 1619: if ($newuser) {
1.301 bisitz 1620: $r->print(' onclick="auth_check()" \>'."\n");
1.218 raeburn 1621: } else {
1.461 raeburn 1622: $r->print(' onclick="this.form.submit()" \>'."\n");
1.218 raeburn 1623: }
1.188 raeburn 1624: } else {
1.393 raeburn 1625: $r->print('</fieldset></div>'.
1626: '<div class="LC_clear_float_footer"></div>'.
1627: '<br /><a href="javascript:backPage(document.cu)">'.
1.218 raeburn 1628: &mt('Back to previous page').'</a>');
1.188 raeburn 1629: }
1630: } else {
1.375 raeburn 1631: $r->print(&course_level_table(\%inccourses,$showcredits,$defaultcredits));
1.393 raeburn 1632: $r->print('</fieldset></div><div class="LC_clear_float_footer"></div>'.
1633: '<br /><input type="button" value="'.&mt('Save').'" onclick="setSections(this.form)" />'."\n");
1.188 raeburn 1634: }
1.88 raeburn 1635: }
1.188 raeburn 1636: $r->print(&Apache::lonhtmlcommon::echo_form_input(['phase','userrole','ccdomain','prevphase','currstate','ccuname','ccdomain']));
1.179 raeburn 1637: $r->print('<input type="hidden" name="currstate" value="" />');
1.393 raeburn 1638: $r->print('<input type="hidden" name="prevphase" value="'.$env{'form.phase'}.'" /></form><br /><br />');
1.218 raeburn 1639: return;
1.2 www 1640: }
1.1 www 1641:
1.213 raeburn 1642: sub singleuser_breadcrumb {
1.422 raeburn 1643: my ($crstype,$context,$domain) = @_;
1.213 raeburn 1644: my %breadcrumb_text;
1645: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1646: if ($crstype eq 'Community') {
1647: $breadcrumb_text{'search'} = 'Enroll a member';
1648: } else {
1649: $breadcrumb_text{'search'} = 'Enroll a student';
1650: }
1.422 raeburn 1651: $breadcrumb_text{'userpicked'} = 'Select a user';
1652: $breadcrumb_text{'modify'} = 'Set section/dates';
1.416 raeburn 1653: } elsif ($env{'form.action'} eq 'accesslogs') {
1654: $breadcrumb_text{'search'} = 'View access logs for a user';
1.422 raeburn 1655: $breadcrumb_text{'userpicked'} = 'Select a user';
1656: $breadcrumb_text{'activity'} = 'Activity';
1657: } elsif (($env{'form.action'} eq 'singleuser') && ($context eq 'domain') &&
1658: (!&Apache::lonnet::allowed('mau',$domain))) {
1659: $breadcrumb_text{'search'} = "View user's roles";
1660: $breadcrumb_text{'userpicked'} = 'Select a user';
1661: $breadcrumb_text{'modify'} = 'User roles';
1.213 raeburn 1662: } else {
1.229 raeburn 1663: $breadcrumb_text{'search'} = 'Create/modify a user';
1.422 raeburn 1664: $breadcrumb_text{'userpicked'} = 'Select a user';
1665: $breadcrumb_text{'modify'} = 'Set user role';
1.213 raeburn 1666: }
1667: return %breadcrumb_text;
1668: }
1669:
1670: sub date_sections_select {
1.375 raeburn 1671: my ($context,$newuser,$formname,$permission,$crstype,$ccuname,$ccdomain,
1672: $showcredits) = @_;
1673: my $credits;
1674: if ($showcredits) {
1675: my $defaultcredits = &Apache::lonuserutils::get_defaultcredits();
1676: $credits = &get_user_credits($ccuname,$ccdomain,$defaultcredits);
1677: if ($credits eq '') {
1678: $credits = $defaultcredits;
1679: }
1680: }
1.213 raeburn 1681: my $cid = $env{'request.course.id'};
1682: my ($cnum,$cdom) = &Apache::lonuserutils::get_course_identity($cid);
1683: my $date_table = '<h3>'.&mt('Starting and Ending Dates').'</h3>'."\n".
1684: &Apache::lonuserutils::date_setting_table(undef,undef,$context,
1685: undef,$formname,$permission);
1686: my $rowtitle = 'Section';
1.375 raeburn 1687: my $secbox = '<h3>'.&mt('Section and Credits').'</h3>'."\n".
1.213 raeburn 1688: &Apache::lonuserutils::section_picker($cdom,$cnum,'st',$rowtitle,
1.375 raeburn 1689: $permission,$context,'',$crstype,
1690: $showcredits,$credits);
1.213 raeburn 1691: my $output = $date_table.$secbox;
1692: return $output;
1693: }
1694:
1.216 raeburn 1695: sub validation_javascript {
1.375 raeburn 1696: my ($context,$ccdomain,$pjump_def,$crstype,$groupslist,$newuser,$formname,
1.216 raeburn 1697: $loaditem) = @_;
1698: my $dc_setcourse_code = '';
1699: my $nondc_setsection_code = '';
1700: if ($context eq 'domain') {
1701: my $dcdom = $env{'request.role.domain'};
1702: $loaditem->{'onload'} = "document.cu.coursedesc.value='';";
1.227 raeburn 1703: $dc_setcourse_code =
1704: &Apache::lonuserutils::dc_setcourse_js('cu','singleuser',$context);
1.216 raeburn 1705: } else {
1.227 raeburn 1706: my $checkauth;
1707: if (($newuser) || (&Apache::lonnet::allowed('mau',$ccdomain))) {
1708: $checkauth = 1;
1709: }
1710: if ($context eq 'course') {
1711: $nondc_setsection_code =
1712: &Apache::lonuserutils::setsections_javascript($formname,$groupslist,
1.375 raeburn 1713: undef,$checkauth,
1714: $crstype);
1.227 raeburn 1715: }
1716: if ($checkauth) {
1717: $nondc_setsection_code .=
1718: &Apache::lonuserutils::verify_authen($formname,$context);
1719: }
1.216 raeburn 1720: }
1721: my $js = &user_modification_js($pjump_def,$dc_setcourse_code,
1722: $nondc_setsection_code,$groupslist);
1723: my ($jsback,$elements) = &crumb_utilities();
1724: $js .= "\n".
1.301 bisitz 1725: '<script type="text/javascript">'."\n".
1726: '// <![CDATA['."\n".
1727: $jsback."\n".
1728: '// ]]>'."\n".
1729: '</script>'."\n";
1.216 raeburn 1730: return $js;
1731: }
1732:
1.217 raeburn 1733: sub display_existing_roles {
1.375 raeburn 1734: my ($r,$ccuname,$ccdomain,$inccourses,$context,$roledom,$crstype,
1.418 raeburn 1735: $showcredits,$statuses) = @_;
1.329 raeburn 1736: my $now=time;
1.418 raeburn 1737: my $showall = 1;
1738: my ($showexpired,$showactive);
1739: if ((ref($statuses) eq 'ARRAY') && (@{$statuses} > 0)) {
1740: $showall = 0;
1741: if (grep(/^expired$/,@{$statuses})) {
1742: $showexpired = 1;
1743: }
1744: if (grep(/^active$/,@{$statuses})) {
1745: $showactive = 1;
1746: }
1747: if ($showexpired && $showactive) {
1748: $showall = 1;
1749: }
1750: }
1.329 raeburn 1751: my %lt=&Apache::lonlocal::texthash(
1.217 raeburn 1752: 'rer' => "Existing Roles",
1753: 'rev' => "Revoke",
1754: 'del' => "Delete",
1755: 'ren' => "Re-Enable",
1756: 'rol' => "Role",
1757: 'ext' => "Extent",
1.375 raeburn 1758: 'crd' => "Credits",
1.217 raeburn 1759: 'sta' => "Start",
1760: 'end' => "End",
1761: );
1.329 raeburn 1762: my (%rolesdump,%roletext,%sortrole,%roleclass,%rolepriv);
1763: if ($context eq 'course' || $context eq 'author') {
1764: my @roles = &Apache::lonuserutils::roles_by_context($context,1,$crstype);
1765: my %roleshash =
1766: &Apache::lonnet::get_my_roles($ccuname,$ccdomain,'userroles',
1767: ['active','previous','future'],\@roles,$roledom,1);
1768: foreach my $key (keys(%roleshash)) {
1769: my ($start,$end) = split(':',$roleshash{$key});
1770: next if ($start eq '-1' || $end eq '-1');
1771: my ($rnum,$rdom,$role,$sec) = split(':',$key);
1772: if ($context eq 'course') {
1773: next unless (($rnum eq $env{'course.'.$env{'request.course.id'}.'.num'})
1774: && ($rdom eq $env{'course.'.$env{'request.course.id'}.'.domain'}));
1775: } elsif ($context eq 'author') {
1776: next unless (($rnum eq $env{'user.name'}) && ($rdom eq $env{'request.role.domain'}));
1777: }
1778: my ($newkey,$newvalue,$newrole);
1779: $newkey = '/'.$rdom.'/'.$rnum;
1780: if ($sec ne '') {
1781: $newkey .= '/'.$sec;
1782: }
1783: $newvalue = $role;
1784: if ($role =~ /^cr/) {
1785: $newrole = 'cr';
1786: } else {
1787: $newrole = $role;
1788: }
1789: $newkey .= '_'.$newrole;
1790: if ($start ne '' && $end ne '') {
1791: $newvalue .= '_'.$end.'_'.$start;
1.335 raeburn 1792: } elsif ($end ne '') {
1793: $newvalue .= '_'.$end;
1.329 raeburn 1794: }
1795: $rolesdump{$newkey} = $newvalue;
1796: }
1797: } else {
1.360 raeburn 1798: %rolesdump=&Apache::lonnet::dump('roles',$ccdomain,$ccuname);
1.329 raeburn 1799: }
1800: # Build up table of user roles to allow revocation and re-enabling of roles.
1801: my ($tmp) = keys(%rolesdump);
1802: return if ($tmp =~ /^(con_lost|error)/i);
1803: foreach my $area (sort { my $a1=join('_',(split('_',$a))[1,0]);
1804: my $b1=join('_',(split('_',$b))[1,0]);
1805: return $a1 cmp $b1;
1806: } keys(%rolesdump)) {
1807: next if ($area =~ /^rolesdef/);
1808: my $envkey=$area;
1809: my $role = $rolesdump{$area};
1810: my $thisrole=$area;
1811: $area =~ s/\_\w\w$//;
1812: my ($role_code,$role_end_time,$role_start_time) =
1813: split(/_/,$role);
1.418 raeburn 1814: my $active=1;
1815: $active=0 if (($role_end_time) && ($now>$role_end_time));
1816: if ($active) {
1817: next unless($showall || $showactive);
1818: } else {
1.430 raeburn 1819: next unless($showall || $showexpired);
1.418 raeburn 1820: }
1.217 raeburn 1821: # Is this a custom role? Get role owner and title.
1.329 raeburn 1822: my ($croleudom,$croleuname,$croletitle)=
1823: ($role_code=~m{^cr/($match_domain)/($match_username)/(\w+)$});
1824: my $allowed=0;
1825: my $delallowed=0;
1826: my $sortkey=$role_code;
1827: my $class='Unknown';
1.375 raeburn 1828: my $credits='';
1.418 raeburn 1829: my $csec;
1.421 raeburn 1830: if ($area =~ m{^/($match_domain)/($match_courseid)}) {
1.329 raeburn 1831: $class='Course';
1832: my ($coursedom,$coursedir) = ($1,$2);
1833: my $cid = $1.'_'.$2;
1834: # $1.'_'.$2 is the course id (eg. 103_12345abcef103l3).
1.421 raeburn 1835: next if ($envkey =~ m{^/$match_domain/$match_courseid/[A-Za-z0-9]+_gr$});
1.329 raeburn 1836: my %coursedata=
1837: &Apache::lonnet::coursedescription($cid);
1838: if ($coursedir =~ /^$match_community$/) {
1839: $class='Community';
1840: }
1841: $sortkey.="\0$coursedom";
1842: my $carea;
1843: if (defined($coursedata{'description'})) {
1844: $carea=$coursedata{'description'}.
1845: '<br />'.&mt('Domain').': '.$coursedom.(' 'x8).
1846: &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$coursedir,$coursedom);
1847: $sortkey.="\0".$coursedata{'description'};
1848: } else {
1849: if ($class eq 'Community') {
1850: $carea=&mt('Unavailable community').': '.$area;
1851: $sortkey.="\0".&mt('Unavailable community').': '.$area;
1.217 raeburn 1852: } else {
1853: $carea=&mt('Unavailable course').': '.$area;
1854: $sortkey.="\0".&mt('Unavailable course').': '.$area;
1855: }
1.329 raeburn 1856: }
1857: $sortkey.="\0$coursedir";
1858: $inccourses->{$cid}=1;
1.375 raeburn 1859: if (($showcredits) && ($class eq 'Course') && ($role_code eq 'st')) {
1860: my $defaultcredits = $coursedata{'internal.defaultcredits'};
1861: $credits =
1862: &get_user_credits($ccuname,$ccdomain,$defaultcredits,
1863: $coursedom,$coursedir);
1864: if ($credits eq '') {
1865: $credits = $defaultcredits;
1866: }
1867: }
1.329 raeburn 1868: if ((&Apache::lonnet::allowed('c'.$role_code,$coursedom.'/'.$coursedir)) ||
1869: (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) {
1870: $allowed=1;
1871: }
1872: unless ($allowed) {
1.365 raeburn 1873: my $isowner = &Apache::lonuserutils::is_courseowner($cid,$coursedata{'internal.courseowner'});
1.329 raeburn 1874: if ($isowner) {
1875: if (($role_code eq 'co') && ($class eq 'Community')) {
1876: $allowed = 1;
1877: } elsif (($role_code eq 'cc') && ($class eq 'Course')) {
1878: $allowed = 1;
1879: }
1.217 raeburn 1880: }
1.329 raeburn 1881: }
1882: if ((&Apache::lonnet::allowed('dro',$coursedom)) ||
1883: (&Apache::lonnet::allowed('dro',$ccdomain))) {
1884: $delallowed=1;
1885: }
1.217 raeburn 1886: # - custom role. Needs more info, too
1.329 raeburn 1887: if ($croletitle) {
1888: if (&Apache::lonnet::allowed('ccr',$coursedom.'/'.$coursedir)) {
1889: $allowed=1;
1890: $thisrole.='.'.$role_code;
1.217 raeburn 1891: }
1.329 raeburn 1892: }
1.418 raeburn 1893: if ($area=~m{^/($match_domain/$match_courseid/(\w+))}) {
1894: $csec = $2;
1895: $carea.='<br />'.&mt('Section: [_1]',$csec);
1896: $sortkey.="\0$csec";
1.329 raeburn 1897: if (!$allowed) {
1.418 raeburn 1898: if ($env{'request.course.sec'} eq $csec) {
1899: if (&Apache::lonnet::allowed('c'.$role_code,$1)) {
1.329 raeburn 1900: $allowed = 1;
1.217 raeburn 1901: }
1902: }
1903: }
1.329 raeburn 1904: }
1905: $area=$carea;
1906: } else {
1907: $sortkey.="\0".$area;
1908: # Determine if current user is able to revoke privileges
1909: if ($area=~m{^/($match_domain)/}) {
1910: if ((&Apache::lonnet::allowed('c'.$role_code,$1)) ||
1911: (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) {
1912: $allowed=1;
1.217 raeburn 1913: }
1.329 raeburn 1914: if (((&Apache::lonnet::allowed('dro',$1)) ||
1915: (&Apache::lonnet::allowed('dro',$ccdomain))) &&
1916: ($role_code ne 'dc')) {
1917: $delallowed=1;
1.217 raeburn 1918: }
1.329 raeburn 1919: } else {
1920: if (&Apache::lonnet::allowed('c'.$role_code,'/')) {
1.217 raeburn 1921: $allowed=1;
1922: }
1923: }
1.363 raeburn 1924: if ($role_code eq 'ca' || $role_code eq 'au' || $role_code eq 'aa') {
1.377 raeburn 1925: $class='Authoring Space';
1.329 raeburn 1926: } elsif ($role_code eq 'su') {
1927: $class='System';
1.217 raeburn 1928: } else {
1.329 raeburn 1929: $class='Domain';
1.217 raeburn 1930: }
1.329 raeburn 1931: }
1932: if (($role_code eq 'ca') || ($role_code eq 'aa')) {
1933: $area=~m{/($match_domain)/($match_username)};
1934: if (&Apache::lonuserutils::authorpriv($2,$1)) {
1935: $allowed=1;
1.217 raeburn 1936: } else {
1.329 raeburn 1937: $allowed=0;
1.217 raeburn 1938: }
1.329 raeburn 1939: }
1940: my $row = '';
1.418 raeburn 1941: if ($showall) {
1942: $row.= '<td>';
1943: if (($active) && ($allowed)) {
1944: $row.= '<input type="checkbox" name="rev:'.$thisrole.'" />';
1945: } else {
1946: if ($active) {
1947: $row.=' ';
1948: } else {
1949: $row.=&mt('expired or revoked');
1950: }
1951: }
1952: $row.='</td><td>';
1953: if ($allowed && !$active) {
1954: $row.= '<input type="checkbox" name="ren:'.$thisrole.'" />';
1955: } else {
1956: $row.=' ';
1957: }
1958: $row.='</td><td>';
1959: if ($delallowed) {
1960: $row.= '<input type="checkbox" name="del:'.$thisrole.'" />';
1.217 raeburn 1961: } else {
1.418 raeburn 1962: $row.=' ';
1.217 raeburn 1963: }
1.430 raeburn 1964: $row.= '</td>';
1.329 raeburn 1965: }
1966: my $plaintext='';
1967: if (!$croletitle) {
1.375 raeburn 1968: $plaintext=&Apache::lonnet::plaintext($role_code,$class);
1969: if (($showcredits) && ($credits ne '')) {
1970: $plaintext .= '<br/ ><span class="LC_nobreak">'.
1971: '<span class="LC_fontsize_small">'.
1972: &mt('Credits: [_1]',$credits).
1973: '</span></span>';
1974: }
1.329 raeburn 1975: } else {
1976: $plaintext=
1.395 bisitz 1977: &mt('Custom role [_1][_2]defined by [_3]',
1.346 bisitz 1978: '"'.$croletitle.'"',
1979: '<br />',
1980: $croleuname.':'.$croleudom);
1.329 raeburn 1981: }
1.418 raeburn 1982: $row.= '<td>'.$plaintext.'</td>'.
1983: '<td>'.$area.'</td>'.
1984: '<td>'.($role_start_time?&Apache::lonlocal::locallocaltime($role_start_time)
1985: : ' ' ).'</td>'.
1986: '<td>'.($role_end_time ?&Apache::lonlocal::locallocaltime($role_end_time)
1987: : ' ' ).'</td>';
1.329 raeburn 1988: $sortrole{$sortkey}=$envkey;
1989: $roletext{$envkey}=$row;
1990: $roleclass{$envkey}=$class;
1.418 raeburn 1991: if ($allowed) {
1992: $rolepriv{$envkey}='edit';
1993: } else {
1994: if ($context eq 'domain') {
1.420 raeburn 1995: if ((&Apache::lonnet::allowed('vur',$ccdomain)) &&
1.421 raeburn 1996: ($envkey=~m{^/$ccdomain/})) {
1.418 raeburn 1997: $rolepriv{$envkey}='view';
1998: }
1999: } elsif ($context eq 'course') {
2000: if ((&Apache::lonnet::allowed('vcl',$env{'request.course.id'})) ||
2001: ($env{'request.course.sec'} && ($env{'request.course.sec'} eq $csec) &&
2002: &Apache::lonnet::allowed('vcl',$env{'request.course.id'}.'/'.$env{'request.course.sec'}))) {
2003: $rolepriv{$envkey}='view';
2004: }
2005: }
2006: }
1.329 raeburn 2007: } # end of foreach (table building loop)
2008:
2009: my $rolesdisplay = 0;
2010: my %output = ();
1.377 raeburn 2011: foreach my $type ('Authoring Space','Course','Community','Domain','System','Unknown') {
1.329 raeburn 2012: $output{$type} = '';
2013: foreach my $which (sort {uc($a) cmp uc($b)} (keys(%sortrole))) {
2014: if ( ($roleclass{$sortrole{$which}} =~ /^\Q$type\E/ ) && ($rolepriv{$sortrole{$which}}) ) {
2015: $output{$type}.=
2016: &Apache::loncommon::start_data_table_row().
2017: $roletext{$sortrole{$which}}.
2018: &Apache::loncommon::end_data_table_row();
1.217 raeburn 2019: }
1.329 raeburn 2020: }
2021: unless($output{$type} eq '') {
2022: $output{$type} = '<tr class="LC_info_row">'.
2023: "<td align='center' colspan='7'>".&mt($type)."</td></tr>".
2024: $output{$type};
2025: $rolesdisplay = 1;
2026: }
2027: }
2028: if ($rolesdisplay == 1) {
2029: my $contextrole='';
2030: if ($env{'request.course.id'}) {
2031: if (&Apache::loncommon::course_type() eq 'Community') {
2032: $contextrole = &mt('Existing Roles in this Community');
1.290 bisitz 2033: } else {
1.329 raeburn 2034: $contextrole = &mt('Existing Roles in this Course');
1.290 bisitz 2035: }
1.329 raeburn 2036: } elsif ($env{'request.role'} =~ /^au\./) {
1.377 raeburn 2037: $contextrole = &mt('Existing Co-Author Roles in your Authoring Space');
1.329 raeburn 2038: } else {
1.418 raeburn 2039: if ($showall) {
2040: $contextrole = &mt('Existing Roles in this Domain');
2041: } elsif ($showactive) {
2042: $contextrole = &mt('Unexpired Roles in this Domain');
2043: } elsif ($showexpired) {
2044: $contextrole = &mt('Expired or Revoked Roles in this Domain');
2045: }
1.329 raeburn 2046: }
1.393 raeburn 2047: $r->print('<div class="LC_left_float">'.
1.375 raeburn 2048: '<fieldset><legend>'.$contextrole.'</legend>'.
1.217 raeburn 2049: &Apache::loncommon::start_data_table("LC_createuser").
1.418 raeburn 2050: &Apache::loncommon::start_data_table_header_row());
2051: if ($showall) {
2052: $r->print(
1.419 raeburn 2053: '<th>'.$lt{'rev'}.'</th><th>'.$lt{'ren'}.'</th><th>'.$lt{'del'}.'</th>'
1.418 raeburn 2054: );
2055: } elsif ($showexpired) {
2056: $r->print('<th>'.$lt{'rev'}.'</th>');
2057: }
2058: $r->print(
1.419 raeburn 2059: '<th>'.$lt{'rol'}.'</th><th>'.$lt{'ext'}.'</th>'.
2060: '<th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'.
1.217 raeburn 2061: &Apache::loncommon::end_data_table_header_row());
1.377 raeburn 2062: foreach my $type ('Authoring Space','Course','Community','Domain','System','Unknown') {
1.329 raeburn 2063: if ($output{$type}) {
2064: $r->print($output{$type}."\n");
1.217 raeburn 2065: }
2066: }
1.375 raeburn 2067: $r->print(&Apache::loncommon::end_data_table().
2068: '</fieldset></div>');
1.329 raeburn 2069: }
1.217 raeburn 2070: return;
2071: }
2072:
1.218 raeburn 2073: sub new_coauthor_roles {
2074: my ($r,$ccuname,$ccdomain) = @_;
2075: my $addrolesdisplay = 0;
2076: #
2077: # Co-Author
2078: #
2079: if (&Apache::lonuserutils::authorpriv($env{'user.name'},
2080: $env{'request.role.domain'}) &&
2081: ($env{'user.name'} ne $ccuname || $env{'user.domain'} ne $ccdomain)) {
2082: # No sense in assigning co-author role to yourself
2083: $addrolesdisplay = 1;
2084: my $cuname=$env{'user.name'};
2085: my $cudom=$env{'request.role.domain'};
2086: my %lt=&Apache::lonlocal::texthash(
1.377 raeburn 2087: 'cs' => "Authoring Space",
1.218 raeburn 2088: 'act' => "Activate",
2089: 'rol' => "Role",
2090: 'ext' => "Extent",
2091: 'sta' => "Start",
2092: 'end' => "End",
2093: 'cau' => "Co-Author",
2094: 'caa' => "Assistant Co-Author",
2095: 'ssd' => "Set Start Date",
2096: 'sed' => "Set End Date"
2097: );
2098: $r->print('<h4>'.$lt{'cs'}.'</h4>'."\n".
2099: &Apache::loncommon::start_data_table()."\n".
2100: &Apache::loncommon::start_data_table_header_row()."\n".
2101: '<th>'.$lt{'act'}.'</th><th>'.$lt{'rol'}.'</th>'.
2102: '<th>'.$lt{'ext'}.'</th><th>'.$lt{'sta'}.'</th>'.
2103: '<th>'.$lt{'end'}.'</th>'."\n".
2104: &Apache::loncommon::end_data_table_header_row()."\n".
2105: &Apache::loncommon::start_data_table_row().'
2106: <td>
1.291 bisitz 2107: <input type="checkbox" name="act_'.$cudom.'_'.$cuname.'_ca" />
1.218 raeburn 2108: </td>
2109: <td>'.$lt{'cau'}.'</td>
2110: <td>'.$cudom.'_'.$cuname.'</td>
2111: <td><input type="hidden" name="start_'.$cudom.'_'.$cuname.'_ca" value="" />
2112: <a href=
2113: "javascript:pjump('."'date_start','Start Date Co-Author',document.cu.start_$cudom\_$cuname\_ca.value,'start_$cudom\_$cuname\_ca','cu.pres','dateset'".')">'.$lt{'ssd'}.'</a></td>
2114: <td><input type="hidden" name="end_'.$cudom.'_'.$cuname.'_ca" value="" />
2115: <a href=
2116: "javascript:pjump('."'date_end','End Date Co-Author',document.cu.end_$cudom\_$cuname\_ca.value,'end_$cudom\_$cuname\_ca','cu.pres','dateset'".')">'.$lt{'sed'}.'</a></td>'."\n".
2117: &Apache::loncommon::end_data_table_row()."\n".
2118: &Apache::loncommon::start_data_table_row()."\n".
1.291 bisitz 2119: '<td><input type="checkbox" name="act_'.$cudom.'_'.$cuname.'_aa" /></td>
1.218 raeburn 2120: <td>'.$lt{'caa'}.'</td>
2121: <td>'.$cudom.'_'.$cuname.'</td>
2122: <td><input type="hidden" name="start_'.$cudom.'_'.$cuname.'_aa" value="" />
2123: <a href=
2124: "javascript:pjump('."'date_start','Start Date Assistant Co-Author',document.cu.start_$cudom\_$cuname\_aa.value,'start_$cudom\_$cuname\_aa','cu.pres','dateset'".')">'.$lt{'ssd'}.'</a></td>
2125: <td><input type="hidden" name="end_'.$cudom.'_'.$cuname.'_aa" value="" />
2126: <a href=
2127: "javascript:pjump('."'date_end','End Date Assistant Co-Author',document.cu.end_$cudom\_$cuname\_aa.value,'end_$cudom\_$cuname\_aa','cu.pres','dateset'".')">'.$lt{'sed'}.'</a></td>'."\n".
2128: &Apache::loncommon::end_data_table_row()."\n".
2129: &Apache::loncommon::end_data_table());
2130: } elsif ($env{'request.role'} =~ /^au\./) {
2131: if (!(&Apache::lonuserutils::authorpriv($env{'user.name'},
2132: $env{'request.role.domain'}))) {
2133: $r->print('<span class="LC_error">'.
2134: &mt('You do not have privileges to assign co-author roles.').
2135: '</span>');
2136: } elsif (($env{'user.name'} eq $ccuname) &&
2137: ($env{'user.domain'} eq $ccdomain)) {
1.377 raeburn 2138: $r->print(&mt('Assigning yourself a co-author or assistant co-author role in your own author area in Authoring Space is not permitted'));
1.218 raeburn 2139: }
2140: }
2141: return $addrolesdisplay;;
2142: }
2143:
2144: sub new_domain_roles {
1.357 raeburn 2145: my ($r,$ccdomain) = @_;
1.218 raeburn 2146: my $addrolesdisplay = 0;
2147: #
2148: # Domain level
2149: #
2150: my $num_domain_level = 0;
2151: my $domaintext =
2152: '<h4>'.&mt('Domain Level').'</h4>'.
2153: &Apache::loncommon::start_data_table().
2154: &Apache::loncommon::start_data_table_header_row().
2155: '<th>'.&mt('Activate').'</th><th>'.&mt('Role').'</th><th>'.
2156: &mt('Extent').'</th>'.
2157: '<th>'.&mt('Start').'</th><th>'.&mt('End').'</th>'.
2158: &Apache::loncommon::end_data_table_header_row();
1.312 raeburn 2159: my @allroles = &Apache::lonuserutils::roles_by_context('domain');
1.445 raeburn 2160: my $uprimary = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
2161: my $uintdom = &Apache::lonnet::internet_dom($uprimary);
1.218 raeburn 2162: foreach my $thisdomain (sort(&Apache::lonnet::all_domains())) {
1.312 raeburn 2163: foreach my $role (@allroles) {
2164: next if ($role eq 'ad');
1.357 raeburn 2165: next if (($role eq 'au') && ($ccdomain ne $thisdomain));
1.218 raeburn 2166: if (&Apache::lonnet::allowed('c'.$role,$thisdomain)) {
1.445 raeburn 2167: if ($role eq 'dc') {
2168: unless ($thisdomain eq $env{'request.role.domain'}) {
2169: my $domprim = &Apache::lonnet::domain($thisdomain,'primary');
2170: my $intdom = &Apache::lonnet::internet_dom($domprim);
2171: next unless ($uintdom eq $intdom);
2172: }
2173: }
1.218 raeburn 2174: my $plrole=&Apache::lonnet::plaintext($role);
2175: my %lt=&Apache::lonlocal::texthash(
2176: 'ssd' => "Set Start Date",
2177: 'sed' => "Set End Date"
2178: );
2179: $num_domain_level ++;
2180: $domaintext .=
2181: &Apache::loncommon::start_data_table_row().
1.291 bisitz 2182: '<td><input type="checkbox" name="act_'.$thisdomain.'_'.$role.'" /></td>
1.218 raeburn 2183: <td>'.$plrole.'</td>
2184: <td>'.$thisdomain.'</td>
2185: <td><input type="hidden" name="start_'.$thisdomain.'_'.$role.'" value="" />
2186: <a href=
2187: "javascript:pjump('."'date_start','Start Date $plrole',document.cu.start_$thisdomain\_$role.value,'start_$thisdomain\_$role','cu.pres','dateset'".')">'.$lt{'ssd'}.'</a></td>
2188: <td><input type="hidden" name="end_'.$thisdomain.'_'.$role.'" value="" />
2189: <a href=
2190: "javascript:pjump('."'date_end','End Date $plrole',document.cu.end_$thisdomain\_$role.value,'end_$thisdomain\_$role','cu.pres','dateset'".')">'.$lt{'sed'}.'</a></td>'.
2191: &Apache::loncommon::end_data_table_row();
2192: }
2193: }
2194: }
2195: $domaintext.= &Apache::loncommon::end_data_table();
2196: if ($num_domain_level > 0) {
2197: $r->print($domaintext);
2198: $addrolesdisplay = 1;
2199: }
2200: return $addrolesdisplay;
2201: }
2202:
1.188 raeburn 2203: sub user_authentication {
1.451 raeburn 2204: my ($ccuname,$ccdomain,$formname,$crstype,$permission) = @_;
1.188 raeburn 2205: my $currentauth=&Apache::lonnet::queryauthenticate($ccuname,$ccdomain);
1.227 raeburn 2206: my $outcome;
1.418 raeburn 2207: my %lt=&Apache::lonlocal::texthash(
2208: 'err' => "ERROR",
2209: 'uuas' => "This user has an unrecognized authentication scheme",
2210: 'adcs' => "Please alert a domain coordinator of this situation",
2211: 'sldb' => "Please specify login data below",
2212: 'ld' => "Login Data"
2213: );
1.188 raeburn 2214: # Check for a bad authentication type
1.449 raeburn 2215: if ($currentauth !~ /^(krb4|krb5|unix|internal|localauth|lti):/) {
1.188 raeburn 2216: # bad authentication scheme
2217: if (&Apache::lonnet::allowed('mau',$ccdomain)) {
1.227 raeburn 2218: &initialize_authen_forms($ccdomain,$formname);
2219:
1.190 raeburn 2220: my $choices = &Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc);
1.188 raeburn 2221: $outcome = <<ENDBADAUTH;
2222: <script type="text/javascript" language="Javascript">
1.301 bisitz 2223: // <![CDATA[
1.188 raeburn 2224: $loginscript
1.301 bisitz 2225: // ]]>
1.188 raeburn 2226: </script>
2227: <span class="LC_error">$lt{'err'}:
2228: $lt{'uuas'} ($currentauth). $lt{'sldb'}.</span>
2229: <h3>$lt{'ld'}</h3>
2230: $choices
2231: ENDBADAUTH
2232: } else {
2233: # This user is not allowed to modify the user's
2234: # authentication scheme, so just notify them of the problem
2235: $outcome = <<ENDBADAUTH;
2236: <span class="LC_error"> $lt{'err'}:
2237: $lt{'uuas'} ($currentauth). $lt{'adcs'}.
2238: </span>
2239: ENDBADAUTH
2240: }
2241: } else { # Authentication type is valid
1.418 raeburn 2242:
1.227 raeburn 2243: &initialize_authen_forms($ccdomain,$formname,$currentauth,'modifyuser');
1.205 raeburn 2244: my ($authformcurrent,$can_modify,@authform_others) =
1.188 raeburn 2245: &modify_login_block($ccdomain,$currentauth);
2246: if (&Apache::lonnet::allowed('mau',$ccdomain)) {
2247: # Current user has login modification privileges
2248: $outcome =
2249: '<script type="text/javascript" language="Javascript">'."\n".
1.301 bisitz 2250: '// <![CDATA['."\n".
1.188 raeburn 2251: $loginscript."\n".
1.301 bisitz 2252: '// ]]>'."\n".
1.188 raeburn 2253: '</script>'."\n".
2254: '<h3>'.$lt{'ld'}.'</h3>'.
2255: &Apache::loncommon::start_data_table().
1.205 raeburn 2256: &Apache::loncommon::start_data_table_row().
1.188 raeburn 2257: '<td>'.$authformnop;
1.418 raeburn 2258: if (($can_modify) && (&Apache::lonnet::allowed('mau',$ccdomain))) {
1.188 raeburn 2259: $outcome .= '</td>'."\n".
2260: &Apache::loncommon::end_data_table_row().
2261: &Apache::loncommon::start_data_table_row().
2262: '<td>'.$authformcurrent.'</td>'.
2263: &Apache::loncommon::end_data_table_row()."\n";
2264: } else {
1.200 raeburn 2265: $outcome .= ' ('.$authformcurrent.')</td>'.
2266: &Apache::loncommon::end_data_table_row()."\n";
1.188 raeburn 2267: }
1.418 raeburn 2268: if (&Apache::lonnet::allowed('mau',$ccdomain)) {
2269: foreach my $item (@authform_others) {
2270: $outcome .= &Apache::loncommon::start_data_table_row().
2271: '<td>'.$item.'</td>'.
2272: &Apache::loncommon::end_data_table_row()."\n";
2273: }
1.188 raeburn 2274: }
1.205 raeburn 2275: $outcome .= &Apache::loncommon::end_data_table();
1.188 raeburn 2276: } else {
1.451 raeburn 2277: if (($currentauth =~ /^internal:/) &&
2278: (&Apache::lonuserutils::can_change_internalpass($ccuname,$ccdomain,$crstype,$permission))) {
2279: $outcome = <<"ENDJS";
2280: <script type="text/javascript">
2281: // <![CDATA[
2282: function togglePwd(form) {
2283: if (form.newintpwd.length) {
2284: if (document.getElementById('LC_ownersetpwd')) {
2285: for (var i=0; i<form.newintpwd.length; i++) {
2286: if (form.newintpwd[i].checked) {
2287: if (form.newintpwd[i].value == 1) {
2288: document.getElementById('LC_ownersetpwd').style.display = 'inline-block';
2289: } else {
2290: document.getElementById('LC_ownersetpwd').style.display = 'none';
2291: }
2292: }
2293: }
2294: }
2295: }
2296: }
2297: // ]]>
2298: </script>
2299: ENDJS
2300:
2301: $outcome .= '<h3>'.$lt{'ld'}.'</h3>'.
2302: &Apache::loncommon::start_data_table().
2303: &Apache::loncommon::start_data_table_row().
2304: '<td>'.&mt('Internally authenticated').'<br />'.&mt("Change user's password?").
2305: '<label><input type="radio" name="newintpwd" value="0" checked="checked" onclick="togglePwd(this.form);" />'.
2306: &mt('No').'</label>'.(' 'x2).
2307: '<label><input type="radio" name="newintpwd" value="1" onclick="togglePwd(this.form);" />'.&mt('Yes').'</label>'.
2308: '<div id="LC_ownersetpwd" style="display:none">'.
2309: ' '.&mt('Password').' <input type="password" size="15" name="intarg" value="" />'.
2310: '<label><input type="checkbox" name="visible" onclick="if (this.checked) { this.form.intarg.type='."'text'".' } else { this.form.intarg.type='."'password'".' }" />'.&mt('Visible input').'</label></div></td>'.
2311: &Apache::loncommon::end_data_table_row().
2312: &Apache::loncommon::end_data_table();
2313: }
1.418 raeburn 2314: if (&Apache::lonnet::allowed('udp',$ccdomain)) {
2315: # Current user has rights to view domain preferences for user's domain
2316: my $result;
2317: if ($currentauth =~ /^krb(4|5):([^:]*)$/) {
2318: my ($krbver,$krbrealm) = ($1,$2);
2319: if ($krbrealm eq '') {
2320: $result = &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
2321: } else {
2322: $result = &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
1.426 raeburn 2323: $krbrealm,$krbver);
1.418 raeburn 2324: }
2325: } elsif ($currentauth =~ /^internal:/) {
2326: $result = &mt('Currently internally authenticated.');
2327: } elsif ($currentauth =~ /^localauth:/) {
2328: $result = &mt('Currently using local (institutional) authentication.');
2329: } elsif ($currentauth =~ /^unix:/) {
2330: $result = &mt('Currently Filesystem Authenticated.');
1.449 raeburn 2331: } elsif ($currentauth =~ /^lti:/) {
1.451 raeburn 2332: $result = &mt('Currently LTI authenticated.');
1.418 raeburn 2333: }
2334: $outcome = '<h3>'.$lt{'ld'}.'</h3>'.
2335: &Apache::loncommon::start_data_table().
2336: &Apache::loncommon::start_data_table_row().
2337: '<td>'.$result.'</td>'.
2338: &Apache::loncommon::end_data_table_row()."\n".
2339: &Apache::loncommon::end_data_table();
2340: } elsif (&Apache::lonnet::allowed('mau',$env{'request.role.domain'})) {
1.188 raeburn 2341: my %lt=&Apache::lonlocal::texthash(
2342: 'ccld' => "Change Current Login Data",
2343: 'yodo' => "You do not have privileges to modify the authentication configuration for this user.",
2344: 'ifch' => "If a change is required, contact a domain coordinator for the domain",
2345: );
2346: $outcome .= <<ENDNOPRIV;
2347: <h3>$lt{'ccld'}</h3>
2348: $lt{'yodo'} $lt{'ifch'}: $ccdomain
1.235 raeburn 2349: <input type="hidden" name="login" value="nochange" />
1.188 raeburn 2350: ENDNOPRIV
2351: }
2352: }
2353: } ## End of "check for bad authentication type" logic
2354: return $outcome;
2355: }
2356:
1.187 raeburn 2357: sub modify_login_block {
2358: my ($dom,$currentauth) = @_;
2359: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
2360: my ($authnum,%can_assign) =
2361: &Apache::loncommon::get_assignable_auth($dom);
1.205 raeburn 2362: my ($authformcurrent,@authform_others,$show_override_msg);
1.187 raeburn 2363: if ($currentauth=~/^krb(4|5):/) {
2364: $authformcurrent=$authformkrb;
2365: if ($can_assign{'int'}) {
1.205 raeburn 2366: push(@authform_others,$authformint);
1.187 raeburn 2367: }
2368: if ($can_assign{'loc'}) {
1.205 raeburn 2369: push(@authform_others,$authformloc);
1.187 raeburn 2370: }
1.449 raeburn 2371: if ($can_assign{'lti'}) {
2372: push(@authform_others,$authformlti);
2373: }
1.187 raeburn 2374: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
2375: $show_override_msg = 1;
2376: }
2377: } elsif ($currentauth=~/^internal:/) {
2378: $authformcurrent=$authformint;
2379: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205 raeburn 2380: push(@authform_others,$authformkrb);
1.187 raeburn 2381: }
2382: if ($can_assign{'loc'}) {
1.205 raeburn 2383: push(@authform_others,$authformloc);
1.187 raeburn 2384: }
1.449 raeburn 2385: if ($can_assign{'lti'}) {
2386: push(@authform_others,$authformlti);
2387: }
1.187 raeburn 2388: if ($can_assign{'int'}) {
2389: $show_override_msg = 1;
2390: }
2391: } elsif ($currentauth=~/^unix:/) {
2392: $authformcurrent=$authformfsys;
2393: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205 raeburn 2394: push(@authform_others,$authformkrb);
1.187 raeburn 2395: }
2396: if ($can_assign{'int'}) {
1.205 raeburn 2397: push(@authform_others,$authformint);
1.187 raeburn 2398: }
2399: if ($can_assign{'loc'}) {
1.205 raeburn 2400: push(@authform_others,$authformloc);
1.187 raeburn 2401: }
1.449 raeburn 2402: if ($can_assign{'lti'}) {
2403: push(@authform_others,$authformlti);
2404: }
1.187 raeburn 2405: if ($can_assign{'fsys'}) {
2406: $show_override_msg = 1;
2407: }
2408: } elsif ($currentauth=~/^localauth:/) {
2409: $authformcurrent=$authformloc;
2410: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205 raeburn 2411: push(@authform_others,$authformkrb);
1.187 raeburn 2412: }
2413: if ($can_assign{'int'}) {
1.205 raeburn 2414: push(@authform_others,$authformint);
1.187 raeburn 2415: }
1.449 raeburn 2416: if ($can_assign{'lti'}) {
2417: push(@authform_others,$authformlti);
2418: }
1.187 raeburn 2419: if ($can_assign{'loc'}) {
2420: $show_override_msg = 1;
2421: }
1.449 raeburn 2422: } elsif ($currentauth=~/^lti:/) {
2423: $authformcurrent=$authformlti;
2424: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
2425: push(@authform_others,$authformkrb);
2426: }
2427: if ($can_assign{'int'}) {
2428: push(@authform_others,$authformint);
2429: }
2430: if ($can_assign{'loc'}) {
2431: push(@authform_others,$authformloc);
2432: }
1.187 raeburn 2433: }
2434: if ($show_override_msg) {
1.205 raeburn 2435: $authformcurrent = '<table><tr><td colspan="3">'.$authformcurrent.
2436: '</td></tr>'."\n".
2437: '<tr><td> </td>'.
2438: '<td><b>'.&mt('Currently in use').'</b></td>'.
2439: '<td align="right"><span class="LC_cusr_emph">'.
1.187 raeburn 2440: &mt('will override current values').
1.205 raeburn 2441: '</span></td></tr></table>';
1.187 raeburn 2442: }
1.205 raeburn 2443: return ($authformcurrent,$show_override_msg,@authform_others);
1.187 raeburn 2444: }
2445:
1.188 raeburn 2446: sub personal_data_display {
1.456 raeburn 2447: my ($ccuname,$ccdomain,$newuser,$context,$inst_results,$rolesarray,$now,
2448: $captchaform,$emailusername,$usertype,$usernameset,$condition,$excluded,$showsubmit) = @_;
1.388 bisitz 2449: my ($output,%userenv,%canmodify,%canmodify_status);
1.219 raeburn 2450: my @userinfo = ('firstname','middlename','lastname','generation',
2451: 'permanentemail','id');
1.252 raeburn 2452: my $rowcount = 0;
2453: my $editable = 0;
1.391 raeburn 2454: my %textboxsize = (
2455: firstname => '15',
2456: middlename => '15',
2457: lastname => '15',
2458: generation => '5',
2459: permanentemail => '25',
2460: id => '15',
2461: );
2462:
2463: my %lt=&Apache::lonlocal::texthash(
2464: 'pd' => "Personal Data",
2465: 'firstname' => "First Name",
2466: 'middlename' => "Middle Name",
2467: 'lastname' => "Last Name",
2468: 'generation' => "Generation",
2469: 'permanentemail' => "Permanent e-mail address",
2470: 'id' => "Student/Employee ID",
2471: 'lg' => "Login Data",
2472: 'inststatus' => "Affiliation",
2473: 'email' => 'E-mail address',
2474: 'valid' => 'Validation',
1.442 raeburn 2475: 'username' => 'Username',
1.391 raeburn 2476: );
2477:
2478: %canmodify_status =
1.286 raeburn 2479: &Apache::lonuserutils::can_modify_userinfo($context,$ccdomain,
2480: ['inststatus'],$rolesarray);
1.253 raeburn 2481: if (!$newuser) {
1.188 raeburn 2482: # Get the users information
2483: %userenv = &Apache::lonnet::get('environment',
2484: ['firstname','middlename','lastname','generation',
1.286 raeburn 2485: 'permanentemail','id','inststatus'],$ccdomain,$ccuname);
1.219 raeburn 2486: %canmodify =
2487: &Apache::lonuserutils::can_modify_userinfo($context,$ccdomain,
1.252 raeburn 2488: \@userinfo,$rolesarray);
1.257 raeburn 2489: } elsif ($context eq 'selfcreate') {
1.391 raeburn 2490: if ($newuser eq 'email') {
1.396 raeburn 2491: if (ref($emailusername) eq 'HASH') {
2492: if (ref($emailusername->{$usertype}) eq 'HASH') {
2493: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
1.442 raeburn 2494: @userinfo = ();
1.396 raeburn 2495: if ((ref($infofields) eq 'ARRAY') && (ref($infotitles) eq 'HASH')) {
2496: foreach my $field (@{$infofields}) {
2497: if ($emailusername->{$usertype}->{$field}) {
2498: push(@userinfo,$field);
2499: $canmodify{$field} = 1;
2500: unless ($textboxsize{$field}) {
2501: $textboxsize{$field} = 25;
2502: }
2503: unless ($lt{$field}) {
2504: $lt{$field} = $infotitles->{$field};
2505: }
2506: if ($emailusername->{$usertype}->{$field} eq 'required') {
2507: $lt{$field} .= '<b>*</b>';
2508: }
1.391 raeburn 2509: }
2510: }
2511: }
2512: }
2513: }
2514: } else {
2515: %canmodify = &selfcreate_canmodify($context,$ccdomain,\@userinfo,
2516: $inst_results,$rolesarray);
2517: }
1.188 raeburn 2518: }
1.391 raeburn 2519:
1.188 raeburn 2520: my $genhelp=&Apache::loncommon::help_open_topic('Generation');
2521: $output = '<h3>'.$lt{'pd'}.'</h3>'.
2522: &Apache::lonhtmlcommon::start_pick_box();
1.391 raeburn 2523: if (($context eq 'selfcreate') && ($newuser eq 'email')) {
1.443 raeburn 2524: my $size = 25;
1.442 raeburn 2525: if ($condition) {
1.443 raeburn 2526: if ($condition =~ /^\@[^\@]+$/) {
2527: $size = 10;
1.442 raeburn 2528: } else {
2529: undef($condition);
2530: }
1.443 raeburn 2531: }
2532: if ($excluded) {
2533: unless ($excluded =~ /^\@[^\@]+$/) {
2534: undef($condition);
2535: }
1.442 raeburn 2536: }
1.396 raeburn 2537: $output .= &Apache::lonhtmlcommon::row_title($lt{'email'}.'<b>*</b>',undef,
1.391 raeburn 2538: 'LC_oddrow_value')."\n".
1.443 raeburn 2539: '<input type="text" name="uname" size="'.$size.'" value="" autocomplete="off" />';
2540: if ($condition) {
2541: $output .= $condition;
2542: } elsif ($excluded) {
2543: $output .= '<br /><span style="font-size: smaller">'.&mt('You must use an e-mail address that does not end with [_1]',
2544: $excluded).'</span>';
2545: }
2546: if ($usernameset eq 'first') {
2547: $output .= '<br /><span style="font-size: smaller">';
2548: if ($condition) {
2549: $output .= &mt('Your username in LON-CAPA will be the part of your e-mail address before [_1]',
2550: $condition);
2551: } else {
2552: $output .= &mt('Your username in LON-CAPA will be the part of your e-mail address before the @');
2553: }
2554: $output .= '</span>';
2555: }
1.391 raeburn 2556: $rowcount ++;
2557: $output .= &Apache::lonhtmlcommon::row_closure(1);
1.460 raeburn 2558: my $upassone = '<input type="password" name="upass'.$now.'" size="20" autocomplete="new-password" />';
2559: my $upasstwo = '<input type="password" name="upasscheck'.$now.'" size="20" autocomplete="new-password" />';
1.396 raeburn 2560: $output .= &Apache::lonhtmlcommon::row_title(&mt('Password').'<b>*</b>',
1.391 raeburn 2561: 'LC_pick_box_title',
2562: 'LC_oddrow_value')."\n".
2563: $upassone."\n".
2564: &Apache::lonhtmlcommon::row_closure(1)."\n".
1.396 raeburn 2565: &Apache::lonhtmlcommon::row_title(&mt('Confirm password').'<b>*</b>',
1.391 raeburn 2566: 'LC_pick_box_title',
2567: 'LC_oddrow_value')."\n".
2568: $upasstwo.
2569: &Apache::lonhtmlcommon::row_closure()."\n";
1.443 raeburn 2570: if ($usernameset eq 'free') {
2571: my $onclick = "toggleUsernameDisp(this,'selfcreateusername');";
1.442 raeburn 2572: $output .= &Apache::lonhtmlcommon::row_title($lt{'username'},undef,'LC_oddrow_value')."\n".
1.455 raeburn 2573: '<span class="LC_nobreak">'.&mt('Use e-mail address: ').
2574: '<label><input type="radio" name="emailused" value="1" checked="checked" onclick="'.$onclick.'" />'.
2575: &mt('Yes').'</label>'.(' 'x2).
2576: '<label><input type="radio" name="emailused" value="0" onclick="'.$onclick.'" />'.
2577: &mt('No').'</label></span>'."\n".
1.442 raeburn 2578: '<div id="selfcreateusername" style="display: none; font-size: smaller">'.
2579: '<br /><span class="LC_nobreak">'.&mt('Preferred username').
2580: ' <input type="text" name="username" value="" size="20" autocomplete="off"/>'.
2581: '</span></div>'."\n".&Apache::lonhtmlcommon::row_closure(1);
2582: $rowcount ++;
2583: }
1.391 raeburn 2584: }
1.188 raeburn 2585: foreach my $item (@userinfo) {
2586: my $rowtitle = $lt{$item};
1.252 raeburn 2587: my $hiderow = 0;
1.188 raeburn 2588: if ($item eq 'generation') {
2589: $rowtitle = $genhelp.$rowtitle;
2590: }
1.252 raeburn 2591: my $row = &Apache::lonhtmlcommon::row_title($rowtitle,undef,'LC_oddrow_value')."\n";
1.188 raeburn 2592: if ($newuser) {
1.210 raeburn 2593: if (ref($inst_results) eq 'HASH') {
2594: if ($inst_results->{$item} ne '') {
1.252 raeburn 2595: $row .= '<input type="hidden" name="c'.$item.'" value="'.$inst_results->{$item}.'" />'.$inst_results->{$item};
1.210 raeburn 2596: } else {
1.252 raeburn 2597: if ($context eq 'selfcreate') {
1.391 raeburn 2598: if ($canmodify{$item}) {
1.394 raeburn 2599: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" autocomplete="off" />';
1.252 raeburn 2600: $editable ++;
2601: } else {
2602: $hiderow = 1;
2603: }
1.253 raeburn 2604: } else {
2605: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
1.252 raeburn 2606: }
1.210 raeburn 2607: }
1.188 raeburn 2608: } else {
1.252 raeburn 2609: if ($context eq 'selfcreate') {
1.401 raeburn 2610: if ($canmodify{$item}) {
2611: if ($newuser eq 'email') {
2612: $row .= '<input type="text" name="'.$item.'" size="'.$textboxsize{$item}.'" value="" autocomplete="off" />';
1.287 raeburn 2613: } else {
1.401 raeburn 2614: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" autocomplete="off" />';
1.287 raeburn 2615: }
1.401 raeburn 2616: $editable ++;
2617: } else {
2618: $hiderow = 1;
1.252 raeburn 2619: }
1.253 raeburn 2620: } else {
2621: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
1.252 raeburn 2622: }
1.188 raeburn 2623: }
2624: } else {
1.219 raeburn 2625: if ($canmodify{$item}) {
1.252 raeburn 2626: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="'.$userenv{$item}.'" />';
1.393 raeburn 2627: if (($item eq 'id') && (!$newuser)) {
2628: $row .= '<br />'.&Apache::lonuserutils::forceid_change($context);
2629: }
1.188 raeburn 2630: } else {
1.252 raeburn 2631: $row .= $userenv{$item};
1.188 raeburn 2632: }
2633: }
1.252 raeburn 2634: $row .= &Apache::lonhtmlcommon::row_closure(1);
2635: if (!$hiderow) {
2636: $output .= $row;
2637: $rowcount ++;
2638: }
1.188 raeburn 2639: }
1.286 raeburn 2640: if (($canmodify_status{'inststatus'}) || ($context ne 'selfcreate')) {
2641: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($ccdomain);
2642: if (ref($types) eq 'ARRAY') {
2643: if (@{$types} > 0) {
2644: my ($hiderow,$shown);
2645: if ($canmodify_status{'inststatus'}) {
2646: $shown = &pick_inst_statuses($userenv{'inststatus'},$usertypes,$types);
2647: } else {
2648: if ($userenv{'inststatus'} eq '') {
2649: $hiderow = 1;
1.334 raeburn 2650: } else {
2651: my @showitems;
2652: foreach my $item ( map { &unescape($_); } split(':',$userenv{'inststatus'})) {
2653: if (exists($usertypes->{$item})) {
2654: push(@showitems,$usertypes->{$item});
2655: } else {
2656: push(@showitems,$item);
2657: }
2658: }
2659: if (@showitems) {
2660: $shown = join(', ',@showitems);
2661: } else {
2662: $hiderow = 1;
2663: }
1.286 raeburn 2664: }
2665: }
2666: if (!$hiderow) {
1.389 bisitz 2667: my $row = &Apache::lonhtmlcommon::row_title(&mt('Affiliations'),undef,'LC_oddrow_value')."\n".
1.286 raeburn 2668: $shown.&Apache::lonhtmlcommon::row_closure(1);
2669: if ($context eq 'selfcreate') {
2670: $rowcount ++;
2671: }
2672: $output .= $row;
2673: }
2674: }
2675: }
2676: }
1.391 raeburn 2677: if (($context eq 'selfcreate') && ($newuser eq 'email')) {
2678: if ($captchaform) {
1.410 raeburn 2679: $output .= &Apache::lonhtmlcommon::row_title($lt{'valid'}.'*',
2680: 'LC_pick_box_title')."\n".
1.456 raeburn 2681: $captchaform."\n".'<br /><br />'.
1.391 raeburn 2682: &Apache::lonhtmlcommon::row_closure(1);
2683: $rowcount ++;
2684: }
1.456 raeburn 2685: if ($showsubmit) {
2686: my $submit_text = &mt('Create account');
2687: $output .= &Apache::lonhtmlcommon::row_title()."\n".
2688: '<br /><input type="submit" name="createaccount" value="'.
2689: $submit_text.'" />';
2690: if ($usertype ne '') {
2691: $output .= '<input type="hidden" name="type" value="'.
2692: &HTML::Entities::encode($usertype,'\'<>"&').'" />';
2693: }
2694: $output .= &Apache::lonhtmlcommon::row_closure(1);
2695: }
1.391 raeburn 2696: }
1.188 raeburn 2697: $output .= &Apache::lonhtmlcommon::end_pick_box();
1.206 raeburn 2698: if (wantarray) {
1.252 raeburn 2699: if ($context eq 'selfcreate') {
2700: return($output,$rowcount,$editable);
2701: } else {
1.388 bisitz 2702: return $output;
1.252 raeburn 2703: }
1.206 raeburn 2704: } else {
2705: return $output;
2706: }
1.188 raeburn 2707: }
2708:
1.286 raeburn 2709: sub pick_inst_statuses {
2710: my ($curr,$usertypes,$types) = @_;
2711: my ($output,$rem,@currtypes);
2712: if ($curr ne '') {
2713: @currtypes = map { &unescape($_); } split(/:/,$curr);
2714: }
2715: my $numinrow = 2;
2716: if (ref($types) eq 'ARRAY') {
2717: $output = '<table>';
2718: my $lastcolspan;
2719: for (my $i=0; $i<@{$types}; $i++) {
2720: if (defined($usertypes->{$types->[$i]})) {
2721: my $rem = $i%($numinrow);
2722: if ($rem == 0) {
2723: if ($i<@{$types}-1) {
2724: if ($i > 0) {
2725: $output .= '</tr>';
2726: }
2727: $output .= '<tr>';
2728: }
2729: } elsif ($i==@{$types}-1) {
2730: my $colsleft = $numinrow - $rem;
2731: if ($colsleft > 1) {
2732: $lastcolspan = ' colspan="'.$colsleft.'"';
2733: }
2734: }
2735: my $check = ' ';
2736: if (grep(/^\Q$types->[$i]\E$/,@currtypes)) {
2737: $check = ' checked="checked" ';
2738: }
2739: $output .= '<td class="LC_left_item"'.$lastcolspan.'>'.
2740: '<span class="LC_nobreak"><label>'.
2741: '<input type="checkbox" name="inststatus" '.
2742: 'value="'.$types->[$i].'"'.$check.'/>'.
2743: $usertypes->{$types->[$i]}.'</label></span></td>';
2744: }
2745: }
2746: $output .= '</tr></table>';
2747: }
2748: return $output;
2749: }
2750:
1.257 raeburn 2751: sub selfcreate_canmodify {
2752: my ($context,$dom,$userinfo,$inst_results,$rolesarray) = @_;
2753: if (ref($inst_results) eq 'HASH') {
2754: my @inststatuses = &get_inststatuses($inst_results);
2755: if (@inststatuses == 0) {
2756: @inststatuses = ('default');
2757: }
2758: $rolesarray = \@inststatuses;
2759: }
2760: my %canmodify =
2761: &Apache::lonuserutils::can_modify_userinfo($context,$dom,$userinfo,
2762: $rolesarray);
2763: return %canmodify;
2764: }
2765:
1.252 raeburn 2766: sub get_inststatuses {
2767: my ($insthashref) = @_;
2768: my @inststatuses = ();
2769: if (ref($insthashref) eq 'HASH') {
2770: if (ref($insthashref->{'inststatus'}) eq 'ARRAY') {
2771: @inststatuses = @{$insthashref->{'inststatus'}};
2772: }
2773: }
2774: return @inststatuses;
2775: }
2776:
1.4 www 2777: # ================================================================= Phase Three
1.42 matthew 2778: sub update_user_data {
1.451 raeburn 2779: my ($r,$context,$crstype,$brcrum,$showcredits,$permission) = @_;
1.101 albertel 2780: my $uhome=&Apache::lonnet::homeserver($env{'form.ccuname'},
2781: $env{'form.ccdomain'});
1.27 matthew 2782: # Error messages
1.188 raeburn 2783: my $error = '<span class="LC_error">'.&mt('Error').': ';
1.193 raeburn 2784: my $end = '</span><br /><br />';
2785: my $rtnlink = '<a href="javascript:backPage(document.userupdate,'.
1.188 raeburn 2786: "'$env{'form.prevphase'}','modify')".'" />'.
1.219 raeburn 2787: &mt('Return to previous page').'</a>'.
2788: &Apache::loncommon::end_page();
2789: my $now = time;
1.40 www 2790: my $title;
1.101 albertel 2791: if (exists($env{'form.makeuser'})) {
1.40 www 2792: $title='Set Privileges for New User';
2793: } else {
2794: $title='Modify User Privileges';
2795: }
1.213 raeburn 2796: my $newuser = 0;
1.160 raeburn 2797: my ($jsback,$elements) = &crumb_utilities();
2798: my $jscript = '<script type="text/javascript">'."\n".
1.301 bisitz 2799: '// <![CDATA['."\n".
2800: $jsback."\n".
2801: '// ]]>'."\n".
2802: '</script>'."\n";
1.422 raeburn 2803: my %breadcrumb_text = &singleuser_breadcrumb($crstype,$context,$env{'form.ccdomain'});
1.351 raeburn 2804: push (@{$brcrum},
2805: {href => "javascript:backPage(document.userupdate)",
2806: text => $breadcrumb_text{'search'},
2807: faq => 282,
2808: bug => 'Instructor Interface',}
2809: );
2810: if ($env{'form.prevphase'} eq 'userpicked') {
2811: push(@{$brcrum},
2812: {href => "javascript:backPage(document.userupdate,'get_user_info','select')",
2813: text => $breadcrumb_text{'userpicked'},
2814: faq => 282,
2815: bug => 'Instructor Interface',});
1.233 raeburn 2816: }
1.224 raeburn 2817: my $helpitem = 'Course_Change_Privileges';
2818: if ($env{'form.action'} eq 'singlestudent') {
2819: $helpitem = 'Course_Add_Student';
1.439 raeburn 2820: } elsif ($context eq 'author') {
2821: $helpitem = 'Author_Change_Privileges';
2822: } elsif ($context eq 'domain') {
2823: $helpitem = 'Domain_Change_Privileges';
1.224 raeburn 2824: }
1.351 raeburn 2825: push(@{$brcrum},
2826: {href => "javascript:backPage(document.userupdate,'$env{'form.prevphase'}','modify')",
2827: text => $breadcrumb_text{'modify'},
2828: faq => 282,
2829: bug => 'Instructor Interface',},
2830: {href => "/adm/createuser",
2831: text => "Result",
2832: faq => 282,
2833: bug => 'Instructor Interface',
2834: help => $helpitem});
2835: my $args = {bread_crumbs => $brcrum,
2836: bread_crumbs_component => 'User Management'};
2837: if ($env{'form.popup'}) {
2838: $args->{'no_nav_bar'} = 1;
2839: }
2840: $r->print(&Apache::loncommon::start_page($title,$jscript,$args));
1.188 raeburn 2841: $r->print(&update_result_form($uhome));
1.27 matthew 2842: # Check Inputs
1.101 albertel 2843: if (! $env{'form.ccuname'} ) {
1.193 raeburn 2844: $r->print($error.&mt('No login name specified').'.'.$end.$rtnlink);
1.27 matthew 2845: return;
2846: }
1.138 albertel 2847: if ( $env{'form.ccuname'} ne
2848: &LONCAPA::clean_username($env{'form.ccuname'}) ) {
1.281 bisitz 2849: $r->print($error.&mt('Invalid login name.').' '.
2850: &mt('Only letters, numbers, periods, dashes, @, and underscores are valid.').
1.193 raeburn 2851: $end.$rtnlink);
1.27 matthew 2852: return;
2853: }
1.101 albertel 2854: if (! $env{'form.ccdomain'} ) {
1.193 raeburn 2855: $r->print($error.&mt('No domain specified').'.'.$end.$rtnlink);
1.27 matthew 2856: return;
2857: }
1.138 albertel 2858: if ( $env{'form.ccdomain'} ne
2859: &LONCAPA::clean_domain($env{'form.ccdomain'}) ) {
1.281 bisitz 2860: $r->print($error.&mt('Invalid domain name.').' '.
2861: &mt('Only letters, numbers, periods, dashes, and underscores are valid.').
1.193 raeburn 2862: $end.$rtnlink);
1.27 matthew 2863: return;
2864: }
1.219 raeburn 2865: if ($uhome eq 'no_host') {
2866: $newuser = 1;
2867: }
1.101 albertel 2868: if (! exists($env{'form.makeuser'})) {
1.29 matthew 2869: # Modifying an existing user, so check the validity of the name
2870: if ($uhome eq 'no_host') {
1.389 bisitz 2871: $r->print(
2872: $error
2873: .'<p class="LC_error">'
2874: .&mt('Unable to determine home server for [_1] in domain [_2].',
2875: '"'.$env{'form.ccuname'}.'"','"'.$env{'form.ccdomain'}.'"')
2876: .'</p>');
1.29 matthew 2877: return;
2878: }
2879: }
1.27 matthew 2880: # Determine authentication method and password for the user being modified
2881: my $amode='';
2882: my $genpwd='';
1.101 albertel 2883: if ($env{'form.login'} eq 'krb') {
1.41 albertel 2884: $amode='krb';
1.101 albertel 2885: $amode.=$env{'form.krbver'};
2886: $genpwd=$env{'form.krbarg'};
2887: } elsif ($env{'form.login'} eq 'int') {
1.27 matthew 2888: $amode='internal';
1.101 albertel 2889: $genpwd=$env{'form.intarg'};
2890: } elsif ($env{'form.login'} eq 'fsys') {
1.27 matthew 2891: $amode='unix';
1.101 albertel 2892: $genpwd=$env{'form.fsysarg'};
2893: } elsif ($env{'form.login'} eq 'loc') {
1.27 matthew 2894: $amode='localauth';
1.101 albertel 2895: $genpwd=$env{'form.locarg'};
1.27 matthew 2896: $genpwd=" " if (!$genpwd);
1.449 raeburn 2897: } elsif ($env{'form.login'} eq 'lti') {
2898: $amode='lti';
2899: $genpwd=" ";
1.101 albertel 2900: } elsif (($env{'form.login'} eq 'nochange') ||
2901: ($env{'form.login'} eq '' )) {
1.34 matthew 2902: # There is no need to tell the user we did not change what they
2903: # did not ask us to change.
1.35 matthew 2904: # If they are creating a new user but have not specified login
2905: # information this will be caught below.
1.30 matthew 2906: } else {
1.367 golterma 2907: $r->print($error.&mt('Invalid login mode or password').$end.$rtnlink);
2908: return;
1.27 matthew 2909: }
1.164 albertel 2910:
1.188 raeburn 2911: $r->print('<h3>'.&mt('User [_1] in domain [_2]',
1.367 golterma 2912: $env{'form.ccuname'}.' ('.&Apache::loncommon::plainname($env{'form.ccuname'},
2913: $env{'form.ccdomain'}).')', $env{'form.ccdomain'}).'</h3>');
2914: my %prog_state = &Apache::lonhtmlcommon::Create_PrgWin($r,2);
1.344 bisitz 2915:
1.193 raeburn 2916: my (%alerts,%rulematch,%inst_results,%curr_rules);
1.334 raeburn 2917: my @userinfo = ('firstname','middlename','lastname','generation','permanentemail','id');
1.459 raeburn 2918: my @usertools = ('aboutme','blog','webdav','portfolio','timezone');
1.449 raeburn 2919: my @requestcourses = ('official','unofficial','community','textbook','placement','lti');
1.362 raeburn 2920: my @requestauthor = ('requestauthor');
1.286 raeburn 2921: my ($othertitle,$usertypes,$types) =
2922: &Apache::loncommon::sorted_inst_types($env{'form.ccdomain'});
1.334 raeburn 2923: my %canmodify_status =
2924: &Apache::lonuserutils::can_modify_userinfo($context,$env{'form.ccdomain'},
2925: ['inststatus']);
1.101 albertel 2926: if ($env{'form.makeuser'}) {
1.164 albertel 2927: $r->print('<h3>'.&mt('Creating new account.').'</h3>');
1.27 matthew 2928: # Check for the authentication mode and password
2929: if (! $amode || ! $genpwd) {
1.193 raeburn 2930: $r->print($error.&mt('Invalid login mode or password').$end.$rtnlink);
1.27 matthew 2931: return;
1.18 albertel 2932: }
1.29 matthew 2933: # Determine desired host
1.101 albertel 2934: my $desiredhost = $env{'form.hserver'};
1.29 matthew 2935: if (lc($desiredhost) eq 'default') {
2936: $desiredhost = undef;
2937: } else {
1.147 albertel 2938: my %home_servers =
2939: &Apache::lonnet::get_servers($env{'form.ccdomain'},'library');
1.29 matthew 2940: if (! exists($home_servers{$desiredhost})) {
1.193 raeburn 2941: $r->print($error.&mt('Invalid home server specified').$end.$rtnlink);
2942: return;
2943: }
2944: }
2945: # Check ID format
2946: my %checkhash;
2947: my %checks = ('id' => 1);
2948: %{$checkhash{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}}} = (
1.219 raeburn 2949: 'newuser' => $newuser,
1.196 raeburn 2950: 'id' => $env{'form.cid'},
1.193 raeburn 2951: );
1.196 raeburn 2952: if ($env{'form.cid'} ne '') {
2953: &Apache::loncommon::user_rule_check(\%checkhash,\%checks,\%alerts,
2954: \%rulematch,\%inst_results,\%curr_rules);
2955: if (ref($alerts{'id'}) eq 'HASH') {
2956: if (ref($alerts{'id'}{$env{'form.ccdomain'}}) eq 'HASH') {
2957: my $domdesc =
2958: &Apache::lonnet::domain($env{'form.ccdomain'},'description');
2959: if ($alerts{'id'}{$env{'form.ccdomain'}}{$env{'form.cid'}}) {
2960: my $userchkmsg;
2961: if (ref($curr_rules{$env{'form.ccdomain'}}) eq 'HASH') {
2962: $userchkmsg =
2963: &Apache::loncommon::instrule_disallow_msg('id',
2964: $domdesc,1).
2965: &Apache::loncommon::user_rule_formats($env{'form.ccdomain'},
2966: $domdesc,$curr_rules{$env{'form.ccdomain'}}{'id'},'id');
2967: }
2968: $r->print($error.&mt('Invalid ID format').$end.
2969: $userchkmsg.$rtnlink);
2970: return;
2971: }
2972: }
1.29 matthew 2973: }
2974: }
1.367 golterma 2975: &Apache::lonhtmlcommon::Increment_PrgWin($r, \%prog_state);
1.27 matthew 2976: # Call modifyuser
2977: my $result = &Apache::lonnet::modifyuser
1.193 raeburn 2978: ($env{'form.ccdomain'},$env{'form.ccuname'},$env{'form.cid'},
1.188 raeburn 2979: $amode,$genpwd,$env{'form.cfirstname'},
2980: $env{'form.cmiddlename'},$env{'form.clastname'},
2981: $env{'form.cgeneration'},undef,$desiredhost,
2982: $env{'form.cpermanentemail'});
1.77 www 2983: $r->print(&mt('Generating user').': '.$result);
1.219 raeburn 2984: $uhome = &Apache::lonnet::homeserver($env{'form.ccuname'},
1.101 albertel 2985: $env{'form.ccdomain'});
1.334 raeburn 2986: my (%changeHash,%newcustom,%changed,%changedinfo);
1.267 raeburn 2987: if ($uhome ne 'no_host') {
1.334 raeburn 2988: if ($context eq 'domain') {
1.378 raeburn 2989: foreach my $name ('portfolio','author') {
2990: if ($env{'form.custom_'.$name.'quota'} == 1) {
2991: if ($env{'form.'.$name.'quota'} eq '') {
2992: $newcustom{$name.'quota'} = 0;
2993: } else {
2994: $newcustom{$name.'quota'} = $env{'form.'.$name.'quota'};
2995: $newcustom{$name.'quota'} =~ s/[^\d\.]//g;
2996: }
2997: if ("a_admin($newcustom{$name.'quota'},\%changeHash,$name)) {
2998: $changed{$name.'quota'} = 1;
2999: }
1.334 raeburn 3000: }
3001: }
3002: foreach my $item (@usertools) {
3003: if ($env{'form.custom'.$item} == 1) {
3004: $newcustom{$item} = $env{'form.tools_'.$item};
3005: $changed{$item} = &tool_admin($item,$newcustom{$item},
3006: \%changeHash,'tools');
3007: }
1.267 raeburn 3008: }
1.334 raeburn 3009: foreach my $item (@requestcourses) {
1.341 raeburn 3010: if ($env{'form.custom'.$item} == 1) {
3011: $newcustom{$item} = $env{'form.crsreq_'.$item};
3012: if ($env{'form.crsreq_'.$item} eq 'autolimit') {
3013: $newcustom{$item} .= '=';
1.383 raeburn 3014: $env{'form.crsreq_'.$item.'_limit'} =~ s/\D+//g;
3015: if ($env{'form.crsreq_'.$item.'_limit'}) {
1.341 raeburn 3016: $newcustom{$item} .= $env{'form.crsreq_'.$item.'_limit'};
3017: }
1.334 raeburn 3018: }
1.341 raeburn 3019: $changed{$item} = &tool_admin($item,$newcustom{$item},
3020: \%changeHash,'requestcourses');
1.334 raeburn 3021: }
1.275 raeburn 3022: }
1.362 raeburn 3023: if ($env{'form.customrequestauthor'} == 1) {
3024: $newcustom{'requestauthor'} = $env{'form.requestauthor'};
3025: $changed{'requestauthor'} = &tool_admin('requestauthor',
3026: $newcustom{'requestauthor'},
3027: \%changeHash,'requestauthor');
3028: }
1.275 raeburn 3029: }
1.334 raeburn 3030: if ($canmodify_status{'inststatus'}) {
3031: if (exists($env{'form.inststatus'})) {
3032: my @inststatuses = &Apache::loncommon::get_env_multiple('form.inststatus');
3033: if (@inststatuses > 0) {
3034: $changeHash{'inststatus'} = join(',',@inststatuses);
3035: $changed{'inststatus'} = $changeHash{'inststatus'};
1.306 raeburn 3036: }
3037: }
1.232 raeburn 3038: }
1.334 raeburn 3039: if (keys(%changed)) {
3040: foreach my $item (@userinfo) {
3041: $changeHash{$item} = $env{'form.c'.$item};
1.286 raeburn 3042: }
1.267 raeburn 3043: my $chgresult =
3044: &Apache::lonnet::put('environment',\%changeHash,
3045: $env{'form.ccdomain'},$env{'form.ccuname'});
3046: }
1.232 raeburn 3047: }
1.454 raeburn 3048: $r->print('<br />'.&mt('Home Server').': '.$uhome.' '.
1.219 raeburn 3049: &Apache::lonnet::hostname($uhome));
1.101 albertel 3050: } elsif (($env{'form.login'} ne 'nochange') &&
3051: ($env{'form.login'} ne '' )) {
1.27 matthew 3052: # Modify user privileges
3053: if (! $amode || ! $genpwd) {
1.193 raeburn 3054: $r->print($error.'Invalid login mode or password'.$end.$rtnlink);
1.27 matthew 3055: return;
1.20 harris41 3056: }
1.395 bisitz 3057: # Only allow authentication modification if the person has authority
1.101 albertel 3058: if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'})) {
1.20 harris41 3059: $r->print('Modifying authentication: '.
1.31 matthew 3060: &Apache::lonnet::modifyuserauth(
1.101 albertel 3061: $env{'form.ccdomain'},$env{'form.ccuname'},
1.21 harris41 3062: $amode,$genpwd));
1.454 raeburn 3063: $r->print('<br />'.&mt('Home Server').': '.&Apache::lonnet::homeserver
1.101 albertel 3064: ($env{'form.ccuname'},$env{'form.ccdomain'}));
1.4 www 3065: } else {
1.27 matthew 3066: # Okay, this is a non-fatal error.
1.452 raeburn 3067: $r->print($error.&mt('You do not have privileges to modify the authentication configuration for this user.').$end);
1.27 matthew 3068: }
1.451 raeburn 3069: } elsif (($env{'form.intarg'} ne '') &&
3070: (&Apache::lonnet::queryauthenticate($env{'form.ccuname'},$env{'form.ccdomain'}) =~ /^internal:/) &&
3071: (&Apache::lonuserutils::can_change_internalpass($env{'form.ccuname'},$env{'form.ccdomain'},$crstype,$permission))) {
3072: $r->print('Modifying authentication: '.
3073: &Apache::lonnet::modifyuserauth(
3074: $env{'form.ccdomain'},$env{'form.ccuname'},
3075: 'internal',$env{'form.intarg'}));
1.28 matthew 3076: }
1.344 bisitz 3077: $r->rflush(); # Finish display of header before time consuming actions start
1.367 golterma 3078: &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state);
1.28 matthew 3079: ##
1.375 raeburn 3080: my (@userroles,%userupdate,$cnum,$cdom,$defaultcredits,%namechanged);
1.213 raeburn 3081: if ($context eq 'course') {
1.375 raeburn 3082: ($cnum,$cdom) =
3083: &Apache::lonuserutils::get_course_identity();
1.318 raeburn 3084: $crstype = &Apache::loncommon::course_type($cdom.'_'.$cnum);
1.375 raeburn 3085: if ($showcredits) {
3086: $defaultcredits = &Apache::lonuserutils::get_defaultcredits($cdom,$cnum);
3087: }
1.213 raeburn 3088: }
1.101 albertel 3089: if (! $env{'form.makeuser'} ) {
1.28 matthew 3090: # Check for need to change
3091: my %userenv = &Apache::lonnet::get
1.134 raeburn 3092: ('environment',['firstname','middlename','lastname','generation',
1.378 raeburn 3093: 'id','permanentemail','portfolioquota','authorquota','inststatus',
1.459 raeburn 3094: 'tools.aboutme','tools.blog','tools.webdav',
3095: 'tools.portfolio','tools.timezone',
1.361 raeburn 3096: 'requestcourses.official','requestcourses.unofficial',
1.384 raeburn 3097: 'requestcourses.community','requestcourses.textbook',
1.458 raeburn 3098: 'requestcourses.lti','requestauthor',
1.384 raeburn 3099: 'reqcrsotherdom.official','reqcrsotherdom.unofficial',
3100: 'reqcrsotherdom.community','reqcrsotherdom.textbook',
1.458 raeburn 3101: 'reqcrsotherdom.placement'],
1.160 raeburn 3102: $env{'form.ccdomain'},$env{'form.ccuname'});
1.28 matthew 3103: my ($tmp) = keys(%userenv);
3104: if ($tmp =~ /^(con_lost|error)/i) {
3105: %userenv = ();
3106: }
1.206 raeburn 3107: my $no_forceid_alert;
3108: # Check to see if user information can be changed
3109: my %domconfig =
3110: &Apache::lonnet::get_dom('configuration',['usermodification'],
3111: $env{'form.ccdomain'});
1.213 raeburn 3112: my @statuses = ('active','future');
3113: my %roles = &Apache::lonnet::get_my_roles($env{'form.ccuname'},$env{'form.ccdomain'},'userroles',\@statuses,undef,$env{'request.role.domain'});
3114: my ($auname,$audom);
1.220 raeburn 3115: if ($context eq 'author') {
1.206 raeburn 3116: $auname = $env{'user.name'};
3117: $audom = $env{'user.domain'};
3118: }
3119: foreach my $item (keys(%roles)) {
1.220 raeburn 3120: my ($rolenum,$roledom,$role) = split(/:/,$item,-1);
1.206 raeburn 3121: if ($context eq 'course') {
3122: if ($cnum ne '' && $cdom ne '') {
3123: if ($rolenum eq $cnum && $roledom eq $cdom) {
3124: if (!grep(/^\Q$role\E$/,@userroles)) {
3125: push(@userroles,$role);
3126: }
3127: }
3128: }
3129: } elsif ($context eq 'author') {
3130: if ($rolenum eq $auname && $roledom eq $audom) {
1.461 raeburn 3131: if (!grep(/^\Q$role\E$/,@userroles)) {
1.206 raeburn 3132: push(@userroles,$role);
3133: }
3134: }
3135: }
3136: }
1.220 raeburn 3137: if ($env{'form.action'} eq 'singlestudent') {
3138: if (!grep(/^st$/,@userroles)) {
3139: push(@userroles,'st');
3140: }
3141: } else {
3142: # Check for course or co-author roles being activated or re-enabled
3143: if ($context eq 'author' || $context eq 'course') {
3144: foreach my $key (keys(%env)) {
3145: if ($context eq 'author') {
3146: if ($key=~/^form\.act_\Q$audom\E_\Q$auname\E_([^_]+)/) {
3147: if (!grep(/^\Q$1\E$/,@userroles)) {
3148: push(@userroles,$1);
3149: }
3150: } elsif ($key =~/^form\.ren\:\Q$audom\E\/\Q$auname\E_([^_]+)/) {
3151: if (!grep(/^\Q$1\E$/,@userroles)) {
3152: push(@userroles,$1);
3153: }
1.206 raeburn 3154: }
1.220 raeburn 3155: } elsif ($context eq 'course') {
3156: if ($key=~/^form\.act_\Q$cdom\E_\Q$cnum\E_([^_]+)/) {
3157: if (!grep(/^\Q$1\E$/,@userroles)) {
3158: push(@userroles,$1);
3159: }
3160: } elsif ($key =~/^form\.ren\:\Q$cdom\E\/\Q$cnum\E(\/?\w*)_([^_]+)/) {
3161: if (!grep(/^\Q$1\E$/,@userroles)) {
3162: push(@userroles,$1);
3163: }
1.206 raeburn 3164: }
3165: }
3166: }
3167: }
3168: }
3169: #Check to see if we can change personal data for the user
3170: my (@mod_disallowed,@longroles);
3171: foreach my $role (@userroles) {
3172: if ($role eq 'cr') {
3173: push(@longroles,'Custom');
3174: } else {
1.318 raeburn 3175: push(@longroles,&Apache::lonnet::plaintext($role,$crstype));
1.206 raeburn 3176: }
3177: }
1.219 raeburn 3178: my %canmodify = &Apache::lonuserutils::can_modify_userinfo($context,$env{'form.ccdomain'},\@userinfo,\@userroles);
3179: foreach my $item (@userinfo) {
1.28 matthew 3180: # Strip leading and trailing whitespace
1.203 raeburn 3181: $env{'form.c'.$item} =~ s/(\s+$|^\s+)//g;
1.219 raeburn 3182: if (!$canmodify{$item}) {
1.207 raeburn 3183: if (defined($env{'form.c'.$item})) {
3184: if ($env{'form.c'.$item} ne $userenv{$item}) {
3185: push(@mod_disallowed,$item);
3186: }
1.206 raeburn 3187: }
3188: $env{'form.c'.$item} = $userenv{$item};
3189: }
1.28 matthew 3190: }
1.259 bisitz 3191: # Check to see if we can change the Student/Employee ID
1.196 raeburn 3192: my $forceid = $env{'form.forceid'};
3193: my $recurseid = $env{'form.recurseid'};
3194: my (%alerts,%rulematch,%idinst_results,%curr_rules,%got_rules);
1.203 raeburn 3195: my %uidhash = &Apache::lonnet::idrget($env{'form.ccdomain'},
3196: $env{'form.ccuname'});
3197: if (($uidhash{$env{'form.ccuname'}}) &&
3198: ($uidhash{$env{'form.ccuname'}}!~/error\:/) &&
3199: (!$forceid)) {
3200: if ($env{'form.cid'} ne $uidhash{$env{'form.ccuname'}}) {
3201: $env{'form.cid'} = $userenv{'id'};
1.293 bisitz 3202: $no_forceid_alert = &mt('New student/employee ID does not match existing ID for this user.')
1.259 bisitz 3203: .'<br />'
3204: .&mt("Change is not permitted without checking the 'Force ID change' checkbox on the previous page.")
3205: .'<br />'."\n";
1.203 raeburn 3206: }
3207: }
3208: if ($env{'form.cid'} ne $userenv{'id'}) {
1.196 raeburn 3209: my $checkhash;
3210: my $checks = { 'id' => 1 };
3211: $checkhash->{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}} =
3212: { 'newuser' => $newuser,
3213: 'id' => $env{'form.cid'},
3214: };
3215: &Apache::loncommon::user_rule_check($checkhash,$checks,
3216: \%alerts,\%rulematch,\%idinst_results,\%curr_rules,\%got_rules);
3217: if (ref($alerts{'id'}) eq 'HASH') {
3218: if (ref($alerts{'id'}{$env{'form.ccdomain'}}) eq 'HASH') {
1.203 raeburn 3219: $env{'form.cid'} = $userenv{'id'};
1.196 raeburn 3220: }
3221: }
3222: }
1.378 raeburn 3223: my (%quotachanged,%oldquota,%newquota,%olddefquota,%newdefquota,
3224: $oldinststatus,$newinststatus,%oldisdefault,%newisdefault,%oldsettings,
1.339 raeburn 3225: %oldsettingstext,%newsettings,%newsettingstext,@disporder,
1.378 raeburn 3226: %oldsettingstatus,%newsettingstatus);
1.334 raeburn 3227: @disporder = ('inststatus');
3228: if ($env{'request.role.domain'} eq $env{'form.ccdomain'}) {
1.362 raeburn 3229: push(@disporder,'requestcourses','requestauthor');
1.334 raeburn 3230: } else {
3231: push(@disporder,'reqcrsotherdom');
3232: }
3233: push(@disporder,('quota','tools'));
1.338 raeburn 3234: $oldinststatus = $userenv{'inststatus'};
1.378 raeburn 3235: foreach my $name ('portfolio','author') {
3236: ($olddefquota{$name},$oldsettingstatus{$name}) =
3237: &Apache::loncommon::default_quota($env{'form.ccdomain'},$oldinststatus,$name);
3238: ($newdefquota{$name},$newsettingstatus{$name}) = ($olddefquota{$name},$oldsettingstatus{$name});
3239: }
1.334 raeburn 3240: my %canshow;
1.220 raeburn 3241: if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
1.334 raeburn 3242: $canshow{'quota'} = 1;
1.220 raeburn 3243: }
1.267 raeburn 3244: if (&Apache::lonnet::allowed('mut',$env{'form.ccdomain'})) {
1.334 raeburn 3245: $canshow{'tools'} = 1;
1.267 raeburn 3246: }
1.275 raeburn 3247: if (&Apache::lonnet::allowed('ccc',$env{'form.ccdomain'})) {
1.334 raeburn 3248: $canshow{'requestcourses'} = 1;
1.300 raeburn 3249: } elsif (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
1.334 raeburn 3250: $canshow{'reqcrsotherdom'} = 1;
1.275 raeburn 3251: }
1.286 raeburn 3252: if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'})) {
1.334 raeburn 3253: $canshow{'inststatus'} = 1;
1.286 raeburn 3254: }
1.362 raeburn 3255: if (&Apache::lonnet::allowed('cau',$env{'form.ccdomain'})) {
3256: $canshow{'requestauthor'} = 1;
3257: }
1.267 raeburn 3258: my (%changeHash,%changed);
1.286 raeburn 3259: if ($oldinststatus eq '') {
1.334 raeburn 3260: $oldsettings{'inststatus'} = $othertitle;
1.286 raeburn 3261: } else {
3262: if (ref($usertypes) eq 'HASH') {
1.334 raeburn 3263: $oldsettings{'inststatus'} = join(', ',map{ $usertypes->{ &unescape($_) }; } (split(/:/,$userenv{'inststatus'})));
1.286 raeburn 3264: } else {
1.334 raeburn 3265: $oldsettings{'inststatus'} = join(', ',map{ &unescape($_); } (split(/:/,$userenv{'inststatus'})));
1.286 raeburn 3266: }
3267: }
3268: $changeHash{'inststatus'} = $userenv{'inststatus'};
1.334 raeburn 3269: if ($canmodify_status{'inststatus'}) {
3270: $canshow{'inststatus'} = 1;
1.286 raeburn 3271: if (exists($env{'form.inststatus'})) {
3272: my @inststatuses = &Apache::loncommon::get_env_multiple('form.inststatus');
3273: if (@inststatuses > 0) {
3274: $newinststatus = join(':',map { &escape($_); } @inststatuses);
3275: $changeHash{'inststatus'} = $newinststatus;
3276: if ($newinststatus ne $oldinststatus) {
3277: $changed{'inststatus'} = $newinststatus;
1.378 raeburn 3278: foreach my $name ('portfolio','author') {
3279: ($newdefquota{$name},$newsettingstatus{$name}) =
3280: &Apache::loncommon::default_quota($env{'form.ccdomain'},$newinststatus,$name);
3281: }
1.286 raeburn 3282: }
3283: if (ref($usertypes) eq 'HASH') {
1.334 raeburn 3284: $newsettings{'inststatus'} = join(', ',map{ $usertypes->{$_}; } (@inststatuses));
1.286 raeburn 3285: } else {
1.337 raeburn 3286: $newsettings{'inststatus'} = join(', ',@inststatuses);
1.286 raeburn 3287: }
1.334 raeburn 3288: }
3289: } else {
3290: $newinststatus = '';
3291: $changeHash{'inststatus'} = $newinststatus;
3292: $newsettings{'inststatus'} = $othertitle;
3293: if ($newinststatus ne $oldinststatus) {
3294: $changed{'inststatus'} = $changeHash{'inststatus'};
1.378 raeburn 3295: foreach my $name ('portfolio','author') {
3296: ($newdefquota{$name},$newsettingstatus{$name}) =
3297: &Apache::loncommon::default_quota($env{'form.ccdomain'},$newinststatus,$name);
3298: }
1.286 raeburn 3299: }
3300: }
1.334 raeburn 3301: } elsif ($context ne 'selfcreate') {
3302: $canshow{'inststatus'} = 1;
1.337 raeburn 3303: $newsettings{'inststatus'} = $oldsettings{'inststatus'};
1.286 raeburn 3304: }
1.378 raeburn 3305: foreach my $name ('portfolio','author') {
3306: $changeHash{$name.'quota'} = $userenv{$name.'quota'};
3307: }
1.334 raeburn 3308: if ($context eq 'domain') {
1.378 raeburn 3309: foreach my $name ('portfolio','author') {
3310: if ($userenv{$name.'quota'} ne '') {
3311: $oldquota{$name} = $userenv{$name.'quota'};
3312: if ($env{'form.custom_'.$name.'quota'} == 1) {
3313: if ($env{'form.'.$name.'quota'} eq '') {
3314: $newquota{$name} = 0;
3315: } else {
3316: $newquota{$name} = $env{'form.'.$name.'quota'};
3317: $newquota{$name} =~ s/[^\d\.]//g;
3318: }
3319: if ($newquota{$name} != $oldquota{$name}) {
3320: if ("a_admin($newquota{$name},\%changeHash,$name)) {
3321: $changed{$name.'quota'} = 1;
3322: }
3323: }
1.334 raeburn 3324: } else {
1.378 raeburn 3325: if ("a_admin('',\%changeHash,$name)) {
3326: $changed{$name.'quota'} = 1;
3327: $newquota{$name} = $newdefquota{$name};
3328: $newisdefault{$name} = 1;
3329: }
1.334 raeburn 3330: }
1.149 raeburn 3331: } else {
1.378 raeburn 3332: $oldisdefault{$name} = 1;
3333: $oldquota{$name} = $olddefquota{$name};
3334: if ($env{'form.custom_'.$name.'quota'} == 1) {
3335: if ($env{'form.'.$name.'quota'} eq '') {
3336: $newquota{$name} = 0;
3337: } else {
3338: $newquota{$name} = $env{'form.'.$name.'quota'};
3339: $newquota{$name} =~ s/[^\d\.]//g;
3340: }
3341: if ("a_admin($newquota{$name},\%changeHash,$name)) {
3342: $changed{$name.'quota'} = 1;
3343: }
1.334 raeburn 3344: } else {
1.378 raeburn 3345: $newquota{$name} = $newdefquota{$name};
3346: $newisdefault{$name} = 1;
1.334 raeburn 3347: }
1.378 raeburn 3348: }
3349: if ($oldisdefault{$name}) {
3350: $oldsettingstext{'quota'}{$name} = &get_defaultquota_text($oldsettingstatus{$name});
1.383 raeburn 3351: } else {
3352: $oldsettingstext{'quota'}{$name} = &mt('custom quota: [_1] MB',$oldquota{$name});
1.378 raeburn 3353: }
3354: if ($newisdefault{$name}) {
3355: $newsettingstext{'quota'}{$name} = &get_defaultquota_text($newsettingstatus{$name});
1.383 raeburn 3356: } else {
3357: $newsettingstext{'quota'}{$name} = &mt('custom quota: [_1] MB',$newquota{$name});
1.134 raeburn 3358: }
3359: }
1.334 raeburn 3360: &tool_changes('tools',\@usertools,\%oldsettings,\%oldsettingstext,\%userenv,
3361: \%changeHash,\%changed,\%newsettings,\%newsettingstext);
3362: if ($env{'form.ccdomain'} eq $env{'request.role.domain'}) {
3363: &tool_changes('requestcourses',\@requestcourses,\%oldsettings,\%oldsettingstext,
3364: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
1.384 raeburn 3365: &tool_changes('requestauthor',\@requestauthor,\%oldsettings,\%oldsettingstext,
3366: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
1.149 raeburn 3367: } else {
1.334 raeburn 3368: &tool_changes('reqcrsotherdom',\@requestcourses,\%oldsettings,\%oldsettingstext,
3369: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
1.149 raeburn 3370: }
3371: }
1.334 raeburn 3372: foreach my $item (@userinfo) {
3373: if ($env{'form.c'.$item} ne $userenv{$item}) {
3374: $namechanged{$item} = 1;
3375: }
1.204 raeburn 3376: }
1.378 raeburn 3377: foreach my $name ('portfolio','author') {
1.390 bisitz 3378: $oldsettings{'quota'}{$name} = &mt('[_1] MB',$oldquota{$name});
3379: $newsettings{'quota'}{$name} = &mt('[_1] MB',$newquota{$name});
1.378 raeburn 3380: }
1.334 raeburn 3381: if ((keys(%namechanged) > 0) || (keys(%changed) > 0)) {
1.267 raeburn 3382: my ($chgresult,$namechgresult);
3383: if (keys(%changed) > 0) {
3384: $chgresult =
1.204 raeburn 3385: &Apache::lonnet::put('environment',\%changeHash,
3386: $env{'form.ccdomain'},$env{'form.ccuname'});
1.267 raeburn 3387: if ($chgresult eq 'ok') {
3388: if (($env{'user.name'} eq $env{'form.ccuname'}) &&
3389: ($env{'user.domain'} eq $env{'form.ccdomain'})) {
1.270 raeburn 3390: my %newenvhash;
3391: foreach my $key (keys(%changed)) {
1.411 raeburn 3392: if (($key eq 'official') || ($key eq 'unofficial') ||
3393: ($key eq 'community') || ($key eq 'textbook') ||
1.449 raeburn 3394: ($key eq 'placement') || ($key eq 'lti')) {
1.279 raeburn 3395: $newenvhash{'environment.requestcourses.'.$key} =
3396: $changeHash{'requestcourses.'.$key};
1.362 raeburn 3397: if ($changeHash{'requestcourses.'.$key}) {
1.332 raeburn 3398: $newenvhash{'environment.canrequest.'.$key} = 1;
1.279 raeburn 3399: } else {
3400: $newenvhash{'environment.canrequest.'.$key} =
3401: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
3402: $key,'reload','requestcourses');
3403: }
1.362 raeburn 3404: } elsif ($key eq 'requestauthor') {
3405: $newenvhash{'environment.'.$key} = $changeHash{$key};
3406: if ($changeHash{$key}) {
3407: $newenvhash{'environment.canrequest.author'} = 1;
3408: } else {
3409: $newenvhash{'environment.canrequest.author'} =
3410: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
3411: $key,'reload','requestauthor');
3412: }
1.275 raeburn 3413: } elsif ($key ne 'quota') {
1.270 raeburn 3414: $newenvhash{'environment.tools.'.$key} =
3415: $changeHash{'tools.'.$key};
1.279 raeburn 3416: if ($changeHash{'tools.'.$key} ne '') {
3417: $newenvhash{'environment.availabletools.'.$key} =
3418: $changeHash{'tools.'.$key};
3419: } else {
3420: $newenvhash{'environment.availabletools.'.$key} =
1.367 golterma 3421: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
3422: $key,'reload','tools');
1.279 raeburn 3423: }
1.270 raeburn 3424: }
3425: }
1.271 raeburn 3426: if (keys(%newenvhash)) {
3427: &Apache::lonnet::appenv(\%newenvhash);
3428: }
1.267 raeburn 3429: }
1.463 raeburn 3430: if ($changed{'aboutme'}) {
3431: &Apache::loncommon::devalidate_aboutme_cache($env{'form.ccuname'},
3432: $env{'form.ccdomain'});
3433: }
1.267 raeburn 3434: }
1.204 raeburn 3435: }
1.334 raeburn 3436: if (keys(%namechanged) > 0) {
1.337 raeburn 3437: foreach my $field (@userinfo) {
3438: $changeHash{$field} = $env{'form.c'.$field};
3439: }
3440: # Make the change
1.204 raeburn 3441: $namechgresult =
3442: &Apache::lonnet::modifyuser($env{'form.ccdomain'},
3443: $env{'form.ccuname'},$changeHash{'id'},undef,undef,
3444: $changeHash{'firstname'},$changeHash{'middlename'},
3445: $changeHash{'lastname'},$changeHash{'generation'},
1.337 raeburn 3446: $changeHash{'id'},undef,$changeHash{'permanentemail'},undef,\@userinfo);
1.220 raeburn 3447: %userupdate = (
3448: lastname => $env{'form.clastname'},
3449: middlename => $env{'form.cmiddlename'},
3450: firstname => $env{'form.cfirstname'},
3451: generation => $env{'form.cgeneration'},
3452: id => $env{'form.cid'},
3453: );
1.204 raeburn 3454: }
1.334 raeburn 3455: if (((keys(%namechanged) > 0) && $namechgresult eq 'ok') ||
1.267 raeburn 3456: ((keys(%changed) > 0) && $chgresult eq 'ok')) {
1.28 matthew 3457: # Tell the user we changed the name
1.334 raeburn 3458: &display_userinfo($r,1,\@disporder,\%canshow,\@requestcourses,
1.362 raeburn 3459: \@usertools,\@requestauthor,\%userenv,\%changed,\%namechanged,
1.334 raeburn 3460: \%oldsettings, \%oldsettingstext,\%newsettings,
3461: \%newsettingstext);
1.203 raeburn 3462: if ($env{'form.cid'} ne $userenv{'id'}) {
3463: &Apache::lonnet::idput($env{'form.ccdomain'},
1.407 raeburn 3464: {$env{'form.ccuname'} => $env{'form.cid'}},$uhome,'ids');
1.203 raeburn 3465: if (($recurseid) &&
3466: (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'}))) {
3467: my $idresult =
3468: &Apache::lonuserutils::propagate_id_change(
3469: $env{'form.ccuname'},$env{'form.ccdomain'},
3470: \%userupdate);
3471: $r->print('<br />'.$idresult.'<br />');
3472: }
1.196 raeburn 3473: }
1.149 raeburn 3474: if (($env{'form.ccdomain'} eq $env{'user.domain'}) &&
3475: ($env{'form.ccuname'} eq $env{'user.name'})) {
3476: my %newenvhash;
3477: foreach my $key (keys(%changeHash)) {
3478: $newenvhash{'environment.'.$key} = $changeHash{$key};
3479: }
1.238 raeburn 3480: &Apache::lonnet::appenv(\%newenvhash);
1.149 raeburn 3481: }
1.28 matthew 3482: } else { # error occurred
1.389 bisitz 3483: $r->print(
3484: '<p class="LC_error">'
3485: .&mt('Unable to successfully change environment for [_1] in domain [_2].',
3486: '"'.$env{'form.ccuname'}.'"',
3487: '"'.$env{'form.ccdomain'}.'"')
3488: .'</p>');
1.28 matthew 3489: }
1.334 raeburn 3490: } else { # End of if ($env ... ) logic
1.275 raeburn 3491: # They did not want to change the users name, quota, tool availability,
3492: # or ability to request creation of courses,
1.267 raeburn 3493: # but we can still tell them what the name and quota and availabilities are
1.334 raeburn 3494: &display_userinfo($r,undef,\@disporder,\%canshow,\@requestcourses,
1.362 raeburn 3495: \@usertools,\@requestauthor,\%userenv,\%changed,\%namechanged,\%oldsettings,
1.334 raeburn 3496: \%oldsettingstext,\%newsettings,\%newsettingstext);
1.28 matthew 3497: }
1.206 raeburn 3498: if (@mod_disallowed) {
3499: my ($rolestr,$contextname);
3500: if (@longroles > 0) {
3501: $rolestr = join(', ',@longroles);
3502: } else {
3503: $rolestr = &mt('No roles');
3504: }
3505: if ($context eq 'course') {
1.399 bisitz 3506: $contextname = 'course';
1.206 raeburn 3507: } elsif ($context eq 'author') {
1.399 bisitz 3508: $contextname = 'co-author';
1.206 raeburn 3509: }
3510: $r->print(&mt('The following fields were not updated: ').'<ul>');
3511: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
3512: foreach my $field (@mod_disallowed) {
3513: $r->print('<li>'.$fieldtitles{$field}.'</li>'."\n");
3514: }
1.207 raeburn 3515: $r->print('</ul>');
3516: if (@mod_disallowed == 1) {
1.399 bisitz 3517: $r->print(&mt("You do not have the authority to change this field given the user's current set of active/future $contextname roles:"));
1.207 raeburn 3518: } else {
1.399 bisitz 3519: $r->print(&mt("You do not have the authority to change these fields given the user's current set of active/future $contextname roles:"));
1.207 raeburn 3520: }
1.292 bisitz 3521: my $helplink = 'javascript:helpMenu('."'display'".')';
3522: $r->print('<span class="LC_cusr_emph">'.$rolestr.'</span><br />'
3523: .&mt('Please contact your [_1]helpdesk[_2] for more information.'
3524: ,'<a href="'.$helplink.'">','</a>')
3525: .'<br />');
1.206 raeburn 3526: }
1.259 bisitz 3527: $r->print('<span class="LC_warning">'
3528: .$no_forceid_alert
3529: .&Apache::lonuserutils::print_namespacing_alerts($env{'form.ccdomain'},\%alerts,\%curr_rules)
3530: .'</span>');
1.4 www 3531: }
1.367 golterma 3532: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
1.220 raeburn 3533: if ($env{'form.action'} eq 'singlestudent') {
1.375 raeburn 3534: &enroll_single_student($r,$uhome,$amode,$genpwd,$now,$newuser,$context,
3535: $crstype,$showcredits,$defaultcredits);
1.386 bisitz 3536: my $linktext = ($crstype eq 'Community' ?
3537: &mt('Enroll Another Member') : &mt('Enroll Another Student'));
3538: $r->print(
3539: &Apache::lonhtmlcommon::actionbox([
3540: '<a href="javascript:backPage(document.userupdate)">'
3541: .($crstype eq 'Community' ?
3542: &mt('Enroll Another Member') : &mt('Enroll Another Student'))
3543: .'</a>']));
1.220 raeburn 3544: } else {
1.375 raeburn 3545: my @rolechanges = &update_roles($r,$context,$showcredits);
1.334 raeburn 3546: if (keys(%namechanged) > 0) {
1.220 raeburn 3547: if ($context eq 'course') {
3548: if (@userroles > 0) {
1.225 raeburn 3549: if ((@rolechanges == 0) ||
3550: (!(grep(/^st$/,@rolechanges)))) {
3551: if (grep(/^st$/,@userroles)) {
3552: my $classlistupdated =
3553: &Apache::lonuserutils::update_classlist($cdom,
1.220 raeburn 3554: $cnum,$env{'form.ccdomain'},
3555: $env{'form.ccuname'},\%userupdate);
1.225 raeburn 3556: }
1.220 raeburn 3557: }
3558: }
3559: }
3560: }
1.226 raeburn 3561: my $userinfo = &Apache::loncommon::plainname($env{'form.ccuname'},
1.233 raeburn 3562: $env{'form.ccdomain'});
3563: if ($env{'form.popup'}) {
3564: $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a></p>');
3565: } else {
1.367 golterma 3566: $r->print('<br />'.&Apache::lonhtmlcommon::actionbox(['<a href="javascript:backPage(document.userupdate,'."'$env{'form.prevphase'}','modify'".')">'
3567: .&mt('Modify this user: [_1]','<span class="LC_cusr_emph">'.$env{'form.ccuname'}.':'.$env{'form.ccdomain'}.' ('.$userinfo.')</span>').'</a>',
3568: '<a href="javascript:backPage(document.userupdate)">'.&mt('Create/Modify Another User').'</a>']));
1.233 raeburn 3569: }
1.220 raeburn 3570: }
3571: }
3572:
1.334 raeburn 3573: sub display_userinfo {
1.362 raeburn 3574: my ($r,$changed,$order,$canshow,$requestcourses,$usertools,$requestauthor,
3575: $userenv,$changedhash,$namechangedhash,$oldsetting,$oldsettingtext,
1.334 raeburn 3576: $newsetting,$newsettingtext) = @_;
3577: return unless (ref($order) eq 'ARRAY' &&
3578: ref($canshow) eq 'HASH' &&
3579: ref($requestcourses) eq 'ARRAY' &&
1.362 raeburn 3580: ref($requestauthor) eq 'ARRAY' &&
1.334 raeburn 3581: ref($usertools) eq 'ARRAY' &&
3582: ref($userenv) eq 'HASH' &&
3583: ref($changedhash) eq 'HASH' &&
3584: ref($oldsetting) eq 'HASH' &&
3585: ref($oldsettingtext) eq 'HASH' &&
3586: ref($newsetting) eq 'HASH' &&
3587: ref($newsettingtext) eq 'HASH');
3588: my %lt=&Apache::lonlocal::texthash(
1.372 raeburn 3589: 'ui' => 'User Information',
1.334 raeburn 3590: 'uic' => 'User Information Changed',
3591: 'firstname' => 'First Name',
3592: 'middlename' => 'Middle Name',
3593: 'lastname' => 'Last Name',
3594: 'generation' => 'Generation',
3595: 'id' => 'Student/Employee ID',
3596: 'permanentemail' => 'Permanent e-mail address',
1.378 raeburn 3597: 'portfolioquota' => 'Disk space allocated to portfolio files',
1.385 bisitz 3598: 'authorquota' => 'Disk space allocated to Authoring Space',
1.334 raeburn 3599: 'blog' => 'Blog Availability',
1.361 raeburn 3600: 'webdav' => 'WebDAV Availability',
1.334 raeburn 3601: 'aboutme' => 'Personal Information Page Availability',
3602: 'portfolio' => 'Portfolio Availability',
1.459 raeburn 3603: 'timezone' => 'Can set own Time Zone',
1.334 raeburn 3604: 'official' => 'Can Request Official Courses',
3605: 'unofficial' => 'Can Request Unofficial Courses',
3606: 'community' => 'Can Request Communities',
1.384 raeburn 3607: 'textbook' => 'Can Request Textbook Courses',
1.411 raeburn 3608: 'placement' => 'Can Request Placement Tests',
1.449 raeburn 3609: 'lti' => 'Can Request LTI Courses',
1.362 raeburn 3610: 'requestauthor' => 'Can Request Author Role',
1.334 raeburn 3611: 'inststatus' => "Affiliation",
3612: 'prvs' => 'Previous Value:',
3613: 'chto' => 'Changed To:'
3614: );
3615: if ($changed) {
1.372 raeburn 3616: $r->print('<h3>'.$lt{'uic'}.'</h3>'.
1.367 golterma 3617: &Apache::loncommon::start_data_table().
3618: &Apache::loncommon::start_data_table_header_row());
1.334 raeburn 3619: $r->print("<th> </th>\n");
1.367 golterma 3620: $r->print('<th><b>'.$lt{'prvs'}.'</b></th>');
3621: $r->print('<th><span class="LC_nobreak"><b>'.$lt{'chto'}.'</b></span></th>');
3622: $r->print(&Apache::loncommon::end_data_table_header_row());
3623: my @userinfo = ('firstname','middlename','lastname','generation','permanentemail','id');
3624:
1.334 raeburn 3625: foreach my $item (@userinfo) {
3626: my $value = $env{'form.c'.$item};
1.367 golterma 3627: #show changes only:
1.383 raeburn 3628: unless ($value eq $userenv->{$item}){
1.367 golterma 3629: $r->print(&Apache::loncommon::start_data_table_row());
3630: $r->print("<td>$lt{$item}</td>\n");
1.383 raeburn 3631: $r->print("<td>".$userenv->{$item}."</td>\n");
1.367 golterma 3632: $r->print("<td>$value </td>\n");
3633: $r->print(&Apache::loncommon::end_data_table_row());
1.334 raeburn 3634: }
3635: }
3636: foreach my $entry (@{$order}) {
1.383 raeburn 3637: if ($canshow->{$entry}) {
3638: if (($entry eq 'requestcourses') || ($entry eq 'reqcrsotherdom') || ($entry eq 'requestauthor')) {
3639: my @items;
3640: if ($entry eq 'requestauthor') {
3641: @items = ($entry);
3642: } else {
3643: @items = @{$requestcourses};
1.384 raeburn 3644: }
1.383 raeburn 3645: foreach my $item (@items) {
3646: if (($newsetting->{$item} ne $oldsetting->{$item}) ||
3647: ($newsettingtext->{$item} ne $oldsettingtext->{$item})) {
3648: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3649: $r->print("<td>$lt{$item}</td>\n");
3650: $r->print("<td>".$oldsetting->{$item});
3651: if ($oldsettingtext->{$item}) {
3652: if ($oldsetting->{$item}) {
3653: $r->print(' -- ');
3654: }
3655: $r->print($oldsettingtext->{$item});
3656: }
3657: $r->print("</td>\n");
3658: $r->print("<td>".$newsetting->{$item});
3659: if ($newsettingtext->{$item}) {
3660: if ($newsetting->{$item}) {
3661: $r->print(' -- ');
3662: }
3663: $r->print($newsettingtext->{$item});
3664: }
3665: $r->print("</td>\n");
3666: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.334 raeburn 3667: }
3668: }
3669: } elsif ($entry eq 'tools') {
3670: foreach my $item (@{$usertools}) {
1.383 raeburn 3671: if ($newsetting->{$item} ne $oldsetting->{$item}) {
3672: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3673: $r->print("<td>$lt{$item}</td>\n");
3674: $r->print("<td>".$oldsetting->{$item}.' '.$oldsettingtext->{$item}."</td>\n");
3675: $r->print("<td>".$newsetting->{$item}.' '.$newsettingtext->{$item}."</td>\n");
3676: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.334 raeburn 3677: }
3678: }
1.378 raeburn 3679: } elsif ($entry eq 'quota') {
3680: if ((ref($oldsetting->{$entry}) eq 'HASH') && (ref($oldsettingtext->{$entry}) eq 'HASH') &&
3681: (ref($newsetting->{$entry}) eq 'HASH') && (ref($newsettingtext->{$entry}) eq 'HASH')) {
3682: foreach my $name ('portfolio','author') {
1.383 raeburn 3683: if ($newsetting->{$entry}->{$name} ne $oldsetting->{$entry}->{$name}) {
3684: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3685: $r->print("<td>$lt{$name.$entry}</td>\n");
3686: $r->print("<td>".$oldsettingtext->{$entry}->{$name}."</td>\n");
3687: $r->print("<td>".$newsettingtext->{$entry}->{$name}."</td>\n");
3688: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.378 raeburn 3689: }
3690: }
3691: }
1.334 raeburn 3692: } else {
1.383 raeburn 3693: if ($newsetting->{$entry} ne $oldsetting->{$entry}) {
3694: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3695: $r->print("<td>$lt{$entry}</td>\n");
3696: $r->print("<td>".$oldsetting->{$entry}.' '.$oldsettingtext->{$entry}."</td>\n");
3697: $r->print("<td>".$newsetting->{$entry}.' '.$newsettingtext->{$entry}."</td>\n");
3698: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.334 raeburn 3699: }
3700: }
3701: }
3702: }
1.367 golterma 3703: $r->print(&Apache::loncommon::end_data_table().'<br />');
1.372 raeburn 3704: } else {
3705: $r->print('<h3>'.$lt{'ui'}.'</h3>'.
3706: '<p>'.&mt('No changes made to user information').'</p>');
1.334 raeburn 3707: }
3708: return;
3709: }
3710:
1.275 raeburn 3711: sub tool_changes {
3712: my ($context,$usertools,$oldaccess,$oldaccesstext,$userenv,$changeHash,
3713: $changed,$newaccess,$newaccesstext) = @_;
3714: if (!((ref($usertools) eq 'ARRAY') && (ref($oldaccess) eq 'HASH') &&
3715: (ref($oldaccesstext) eq 'HASH') && (ref($userenv) eq 'HASH') &&
3716: (ref($changeHash) eq 'HASH') && (ref($changed) eq 'HASH') &&
3717: (ref($newaccess) eq 'HASH') && (ref($newaccesstext) eq 'HASH'))) {
3718: return;
3719: }
1.383 raeburn 3720: my %reqdisplay = &requestchange_display();
1.300 raeburn 3721: if ($context eq 'reqcrsotherdom') {
1.309 raeburn 3722: my @options = ('approval','validate','autolimit');
1.306 raeburn 3723: my $optregex = join('|',@options);
1.300 raeburn 3724: my $cdom = $env{'request.role.domain'};
3725: foreach my $tool (@{$usertools}) {
1.383 raeburn 3726: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
1.314 raeburn 3727: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
1.300 raeburn 3728: $changeHash->{$context.'.'.$tool} = $userenv->{$context.'.'.$tool};
1.383 raeburn 3729: my ($newop,$limit);
1.314 raeburn 3730: if ($env{'form.'.$context.'_'.$tool}) {
3731: $newop = $env{'form.'.$context.'_'.$tool};
3732: if ($newop eq 'autolimit') {
1.383 raeburn 3733: $limit = $env{'form.'.$context.'_'.$tool.'_limit'};
1.314 raeburn 3734: $limit =~ s/\D+//g;
3735: $newop .= '='.$limit;
3736: }
3737: }
1.300 raeburn 3738: if ($userenv->{$context.'.'.$tool} eq '') {
1.314 raeburn 3739: if ($newop) {
3740: $changed->{$tool}=&tool_admin($tool,$cdom.':'.$newop,
1.300 raeburn 3741: $changeHash,$context);
3742: if ($changed->{$tool}) {
1.383 raeburn 3743: if ($newop =~ /^autolimit/) {
3744: if ($limit) {
3745: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3746: } else {
3747: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3748: }
3749: } else {
3750: $newaccesstext->{$tool} = $reqdisplay{$newop};
3751: }
1.300 raeburn 3752: } else {
3753: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
3754: }
3755: }
3756: } else {
3757: my @curr = split(',',$userenv->{$context.'.'.$tool});
3758: my @new;
3759: my $changedoms;
1.314 raeburn 3760: foreach my $req (@curr) {
3761: if ($req =~ /^\Q$cdom\E\:($optregex\=?\d*)$/) {
3762: my $oldop = $1;
1.383 raeburn 3763: if ($oldop =~ /^autolimit=(\d*)/) {
3764: my $limit = $1;
3765: if ($limit) {
3766: $oldaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3767: } else {
3768: $oldaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3769: }
3770: } else {
3771: $oldaccesstext->{$tool} = $reqdisplay{$oldop};
3772: }
1.314 raeburn 3773: if ($oldop ne $newop) {
3774: $changedoms = 1;
3775: foreach my $item (@curr) {
3776: my ($reqdom,$option) = split(':',$item);
3777: unless ($reqdom eq $cdom) {
3778: push(@new,$item);
3779: }
3780: }
3781: if ($newop) {
3782: push(@new,$cdom.':'.$newop);
1.300 raeburn 3783: }
1.314 raeburn 3784: @new = sort(@new);
1.300 raeburn 3785: }
1.314 raeburn 3786: last;
1.300 raeburn 3787: }
1.314 raeburn 3788: }
3789: if ((!$changedoms) && ($newop)) {
1.300 raeburn 3790: $changedoms = 1;
1.306 raeburn 3791: @new = sort(@curr,$cdom.':'.$newop);
1.300 raeburn 3792: }
3793: if ($changedoms) {
1.314 raeburn 3794: my $newdomstr;
1.300 raeburn 3795: if (@new) {
3796: $newdomstr = join(',',@new);
3797: }
3798: $changed->{$tool}=&tool_admin($tool,$newdomstr,$changeHash,
3799: $context);
3800: if ($changed->{$tool}) {
3801: if ($env{'form.'.$context.'_'.$tool}) {
1.306 raeburn 3802: if ($env{'form.'.$context.'_'.$tool} eq 'autolimit') {
1.314 raeburn 3803: my $limit = $env{'form.'.$context.'_'.$tool.'_limit'};
3804: $limit =~ s/\D+//g;
3805: if ($limit) {
1.383 raeburn 3806: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
1.314 raeburn 3807: } else {
1.383 raeburn 3808: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
1.306 raeburn 3809: }
1.314 raeburn 3810: } else {
1.306 raeburn 3811: $newaccesstext->{$tool} = $reqdisplay{$env{'form.'.$context.'_'.$tool}};
3812: }
1.300 raeburn 3813: } else {
1.383 raeburn 3814: $newaccesstext->{$tool} = &mt("availability set to 'off'");
1.300 raeburn 3815: }
3816: }
3817: }
3818: }
3819: }
3820: return;
3821: }
1.275 raeburn 3822: foreach my $tool (@{$usertools}) {
1.383 raeburn 3823: my ($newval,$limit,$envkey);
1.362 raeburn 3824: $envkey = $context.'.'.$tool;
1.306 raeburn 3825: if ($context eq 'requestcourses') {
3826: $newval = $env{'form.crsreq_'.$tool};
3827: if ($newval eq 'autolimit') {
1.383 raeburn 3828: $limit = $env{'form.crsreq_'.$tool.'_limit'};
3829: $limit =~ s/\D+//g;
3830: $newval .= '='.$limit;
1.306 raeburn 3831: }
1.362 raeburn 3832: } elsif ($context eq 'requestauthor') {
3833: $newval = $env{'form.'.$context};
3834: $envkey = $context;
1.314 raeburn 3835: } else {
1.306 raeburn 3836: $newval = $env{'form.'.$context.'_'.$tool};
3837: }
1.362 raeburn 3838: if ($userenv->{$envkey} ne '') {
1.275 raeburn 3839: $oldaccess->{$tool} = &mt('custom');
1.383 raeburn 3840: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3841: if ($userenv->{$envkey} =~ /^autolimit=(\d*)$/) {
3842: my $currlimit = $1;
3843: if ($currlimit eq '') {
3844: $oldaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3845: } else {
3846: $oldaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$currlimit);
3847: }
3848: } elsif ($userenv->{$envkey}) {
3849: $oldaccesstext->{$tool} = $reqdisplay{$userenv->{$envkey}};
3850: } else {
3851: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
3852: }
1.275 raeburn 3853: } else {
1.383 raeburn 3854: if ($userenv->{$envkey}) {
3855: $oldaccesstext->{$tool} = &mt("availability set to 'on'");
3856: } else {
3857: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
3858: }
1.275 raeburn 3859: }
1.362 raeburn 3860: $changeHash->{$envkey} = $userenv->{$envkey};
1.275 raeburn 3861: if ($env{'form.custom'.$tool} == 1) {
1.362 raeburn 3862: if ($newval ne $userenv->{$envkey}) {
1.306 raeburn 3863: $changed->{$tool} = &tool_admin($tool,$newval,$changeHash,
3864: $context);
1.275 raeburn 3865: if ($changed->{$tool}) {
3866: $newaccess->{$tool} = &mt('custom');
1.383 raeburn 3867: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3868: if ($newval =~ /^autolimit/) {
3869: if ($limit) {
3870: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3871: } else {
3872: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3873: }
3874: } elsif ($newval) {
3875: $newaccesstext->{$tool} = $reqdisplay{$newval};
3876: } else {
3877: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3878: }
1.275 raeburn 3879: } else {
1.383 raeburn 3880: if ($newval) {
3881: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3882: } else {
3883: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3884: }
1.275 raeburn 3885: }
3886: } else {
3887: $newaccess->{$tool} = $oldaccess->{$tool};
1.383 raeburn 3888: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3889: if ($newval =~ /^autolimit/) {
3890: if ($limit) {
3891: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3892: } else {
3893: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3894: }
3895: } elsif ($newval) {
3896: $newaccesstext->{$tool} = $reqdisplay{$newval};
3897: } else {
3898: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3899: }
1.275 raeburn 3900: } else {
1.383 raeburn 3901: if ($userenv->{$context.'.'.$tool}) {
3902: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3903: } else {
3904: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3905: }
1.275 raeburn 3906: }
3907: }
3908: } else {
3909: $newaccess->{$tool} = $oldaccess->{$tool};
3910: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
3911: }
3912: } else {
3913: $changed->{$tool} = &tool_admin($tool,'',$changeHash,$context);
3914: if ($changed->{$tool}) {
3915: $newaccess->{$tool} = &mt('default');
3916: } else {
3917: $newaccess->{$tool} = $oldaccess->{$tool};
1.383 raeburn 3918: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3919: if ($newval =~ /^autolimit/) {
3920: if ($limit) {
3921: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3922: } else {
3923: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3924: }
3925: } elsif ($newval) {
3926: $newaccesstext->{$tool} = $reqdisplay{$newval};
3927: } else {
3928: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3929: }
1.275 raeburn 3930: } else {
1.383 raeburn 3931: if ($userenv->{$context.'.'.$tool}) {
3932: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3933: } else {
3934: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3935: }
1.275 raeburn 3936: }
3937: }
3938: }
3939: } else {
3940: $oldaccess->{$tool} = &mt('default');
3941: if ($env{'form.custom'.$tool} == 1) {
1.306 raeburn 3942: $changed->{$tool} = &tool_admin($tool,$newval,$changeHash,
3943: $context);
1.275 raeburn 3944: if ($changed->{$tool}) {
3945: $newaccess->{$tool} = &mt('custom');
1.383 raeburn 3946: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3947: if ($newval =~ /^autolimit/) {
3948: if ($limit) {
3949: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3950: } else {
3951: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3952: }
3953: } elsif ($newval) {
3954: $newaccesstext->{$tool} = $reqdisplay{$newval};
3955: } else {
3956: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3957: }
1.275 raeburn 3958: } else {
1.383 raeburn 3959: if ($newval) {
3960: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3961: } else {
3962: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3963: }
1.275 raeburn 3964: }
3965: } else {
3966: $newaccess->{$tool} = $oldaccess->{$tool};
3967: }
3968: } else {
3969: $newaccess->{$tool} = $oldaccess->{$tool};
3970: }
3971: }
3972: }
3973: return;
3974: }
3975:
1.220 raeburn 3976: sub update_roles {
1.375 raeburn 3977: my ($r,$context,$showcredits) = @_;
1.4 www 3978: my $now=time;
1.225 raeburn 3979: my @rolechanges;
1.465 raeburn 3980: my (%disallowed,%got_role_approvals,%got_instdoms,%process_by,%instdoms,
1.466 raeburn 3981: %pending,%reject,%notifydc,%status,%unauthorized,%currqueued);
1.465 raeburn 3982: $got_role_approvals{$context} = '';
3983: $process_by{$context} = {};
3984: my @domroles = &Apache::lonuserutils::domain_roles();
3985: my @cstrroles = &Apache::lonuserutils::construction_space_roles();
3986: my @courseroles = &Apache::lonuserutils::roles_by_context('course',1);
1.73 sakharuk 3987: $r->print('<h3>'.&mt('Modifying Roles').'</h3>');
1.404 raeburn 3988: foreach my $key (keys(%env)) {
1.135 raeburn 3989: next if (! $env{$key});
1.190 raeburn 3990: next if ($key eq 'form.action');
1.27 matthew 3991: # Revoke roles
1.135 raeburn 3992: if ($key=~/^form\.rev/) {
3993: if ($key=~/^form\.rev\:([^\_]+)\_([^\_\.]+)$/) {
1.64 www 3994: # Revoke standard role
1.170 albertel 3995: my ($scope,$role) = ($1,$2);
3996: my $result =
3997: &Apache::lonnet::revokerole($env{'form.ccdomain'},
3998: $env{'form.ccuname'},
1.239 raeburn 3999: $scope,$role,'','',$context);
1.367 golterma 4000: $r->print(&Apache::lonhtmlcommon::confirm_success(
1.369 bisitz 4001: &mt('Revoking [_1] in [_2]',
4002: &Apache::lonnet::plaintext($role),
1.372 raeburn 4003: &Apache::loncommon::show_role_extent($scope,$context,$role)),
1.369 bisitz 4004: $result ne "ok").'<br />');
4005: if ($result ne "ok") {
4006: $r->print(&mt('Error: [_1]',$result).'<br />');
4007: }
1.170 albertel 4008: if ($role eq 'st') {
1.202 raeburn 4009: my $result =
1.198 raeburn 4010: &Apache::lonuserutils::classlist_drop($scope,
4011: $env{'form.ccuname'},$env{'form.ccdomain'},
1.202 raeburn 4012: $now);
1.367 golterma 4013: $r->print(&Apache::lonhtmlcommon::confirm_success($result));
1.53 www 4014: }
1.225 raeburn 4015: if (!grep(/^\Q$role\E$/,@rolechanges)) {
4016: push(@rolechanges,$role);
4017: }
1.196 raeburn 4018: }
1.195 raeburn 4019: if ($key=~m{^form\.rev\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}s) {
1.64 www 4020: # Revoke custom role
1.369 bisitz 4021: my $result = &Apache::lonnet::revokecustomrole(
4022: $env{'form.ccdomain'},$env{'form.ccuname'},$1,$2,$3,$4,'','',$context);
1.367 golterma 4023: $r->print(&Apache::lonhtmlcommon::confirm_success(
1.369 bisitz 4024: &mt('Revoking custom role [_1] by [_2] in [_3]',
1.372 raeburn 4025: $4,$3.':'.$2,&Apache::loncommon::show_role_extent($1,$context,'cr')),
1.369 bisitz 4026: $result ne 'ok').'<br />');
4027: if ($result ne "ok") {
4028: $r->print(&mt('Error: [_1]',$result).'<br />');
4029: }
1.225 raeburn 4030: if (!grep(/^cr$/,@rolechanges)) {
4031: push(@rolechanges,'cr');
4032: }
1.64 www 4033: }
1.135 raeburn 4034: } elsif ($key=~/^form\.del/) {
4035: if ($key=~/^form\.del\:([^\_]+)\_([^\_\.]+)$/) {
1.116 raeburn 4036: # Delete standard role
1.170 albertel 4037: my ($scope,$role) = ($1,$2);
4038: my $result =
4039: &Apache::lonnet::assignrole($env{'form.ccdomain'},
4040: $env{'form.ccuname'},
1.239 raeburn 4041: $scope,$role,$now,0,1,'',
4042: $context);
1.367 golterma 4043: $r->print(&Apache::lonhtmlcommon::confirm_success(
4044: &mt('Deleting [_1] in [_2]',
1.369 bisitz 4045: &Apache::lonnet::plaintext($role),
1.372 raeburn 4046: &Apache::loncommon::show_role_extent($scope,$context,$role)),
1.369 bisitz 4047: $result ne 'ok').'<br />');
4048: if ($result ne "ok") {
4049: $r->print(&mt('Error: [_1]',$result).'<br />');
4050: }
1.367 golterma 4051:
1.170 albertel 4052: if ($role eq 'st') {
1.202 raeburn 4053: my $result =
1.198 raeburn 4054: &Apache::lonuserutils::classlist_drop($scope,
4055: $env{'form.ccuname'},$env{'form.ccdomain'},
1.202 raeburn 4056: $now);
1.369 bisitz 4057: $r->print(&Apache::lonhtmlcommon::confirm_success($result));
1.81 albertel 4058: }
1.225 raeburn 4059: if (!grep(/^\Q$role\E$/,@rolechanges)) {
4060: push(@rolechanges,$role);
4061: }
1.116 raeburn 4062: }
1.139 albertel 4063: if ($key=~m{^form\.del\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
1.116 raeburn 4064: my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
4065: # Delete custom role
1.369 bisitz 4066: my $result =
4067: &Apache::lonnet::assigncustomrole($env{'form.ccdomain'},
4068: $env{'form.ccuname'},$url,$rdom,$rnam,$rolename,$now,
4069: 0,1,$context);
4070: $r->print(&Apache::lonhtmlcommon::confirm_success(&mt('Deleting custom role [_1] by [_2] in [_3]',
1.372 raeburn 4071: $rolename,$rnam.':'.$rdom,&Apache::loncommon::show_role_extent($1,$context,'cr')),
1.369 bisitz 4072: $result ne "ok").'<br />');
4073: if ($result ne "ok") {
4074: $r->print(&mt('Error: [_1]',$result).'<br />');
4075: }
1.367 golterma 4076:
1.225 raeburn 4077: if (!grep(/^cr$/,@rolechanges)) {
4078: push(@rolechanges,'cr');
4079: }
1.116 raeburn 4080: }
1.135 raeburn 4081: } elsif ($key=~/^form\.ren/) {
1.101 albertel 4082: my $udom = $env{'form.ccdomain'};
4083: my $uname = $env{'form.ccuname'};
1.116 raeburn 4084: # Re-enable standard role
1.135 raeburn 4085: if ($key=~/^form\.ren\:([^\_]+)\_([^\_\.]+)$/) {
1.89 raeburn 4086: my $url = $1;
4087: my $role = $2;
1.465 raeburn 4088: my $id = $url.'_'.$role;
1.89 raeburn 4089: my $logmsg;
4090: my $output;
4091: if ($role eq 'st') {
1.141 albertel 4092: if ($url =~ m-^/($match_domain)/($match_courseid)/?(\w*)$-) {
1.374 raeburn 4093: my ($cdom,$cnum,$csec) = ($1,$2,$3);
1.375 raeburn 4094: my $credits;
4095: if ($showcredits) {
1.465 raeburn 4096: my $defaultcredits =
1.375 raeburn 4097: &Apache::lonuserutils::get_defaultcredits($cdom,$cnum);
4098: $credits = &get_user_credits($defaultcredits,$cdom,$cnum);
4099: }
1.465 raeburn 4100: unless ($udom eq $cdom) {
4101: next if (&Apache::lonuserutils::restricted_dom($context,$id,$udom,
4102: $uname,$role,$now,0,$cdom,$cnum,$csec,$credits,
4103: \%process_by,\%instdoms,\%got_role_approvals,
1.466 raeburn 4104: \%got_instdoms,\%reject,\%pending,\%notifydc,
4105: \%status,\%unauthorized,\%currqueued));
1.465 raeburn 4106: }
1.375 raeburn 4107: my $result = &Apache::loncommon::commit_studentrole(\$logmsg,$udom,$uname,$url,$role,$now,0,$cdom,$cnum,$csec,$context,$credits);
1.220 raeburn 4108: if (($result =~ /^error/) || ($result eq 'not_in_class') || ($result eq 'unknown_course') || ($result eq 'refused')) {
1.223 raeburn 4109: if ($result eq 'refused' && $logmsg) {
4110: $output = $logmsg;
4111: } else {
1.369 bisitz 4112: $output = &mt('Error: [_1]',$result)."\n";
1.223 raeburn 4113: }
1.89 raeburn 4114: } else {
1.372 raeburn 4115: $output = &Apache::lonhtmlcommon::confirm_success(&mt('Assigning [_1] in [_2] starting [_3]',
4116: &Apache::lonnet::plaintext($role),
4117: &Apache::loncommon::show_role_extent($url,$context,'st'),
4118: &Apache::lonlocal::locallocaltime($now))).'<br />'.$logmsg.'<br />';
1.89 raeburn 4119: }
4120: }
4121: } else {
1.465 raeburn 4122: my ($cdom,$cnum,$csec);
4123: if (grep(/^\Q$role\E$/,@cstrroles)) {
4124: ($cdom,$cnum) = ($url =~ m{^/($match_domain)/($match_username)$});
4125: } elsif (grep(/^\Q$role\E$/,@domroles)) {
4126: ($cdom) = ($url =~ m{^/($match_domain)/$});
4127: } elsif ($url =~ m-^/($match_domain)/($match_courseid)/?(\w*)$-) {
4128: ($cdom,$cnum,$csec) = ($1,$2,$3);
4129: }
4130: if ($cdom ne '') {
4131: unless ($udom eq $cdom) {
4132: next if (&Apache::lonuserutils::restricted_dom($context,$id,$udom,
4133: $uname,$role,$now,0,$cdom,$cnum,$csec,'',\%process_by,
4134: \%instdoms,\%got_role_approvals,\%got_instdoms,\%reject,
1.466 raeburn 4135: \%pending,\%notifydc,\%status,\%unauthorized,\%currqueued));
1.465 raeburn 4136: }
4137: }
1.101 albertel 4138: my $result=&Apache::lonnet::assignrole($env{'form.ccdomain'},
1.239 raeburn 4139: $env{'form.ccuname'},$url,$role,0,$now,'','',
4140: $context);
1.461 raeburn 4141: $output = &Apache::lonhtmlcommon::confirm_success(&mt('Re-enabling [_1] in [_2]',
4142: &Apache::lonnet::plaintext($role),
4143: &Apache::loncommon::show_role_extent($url,$context,$role)),$result ne "ok").'<br />';
1.369 bisitz 4144: if ($result ne "ok") {
4145: $output .= &mt('Error: [_1]',$result).'<br />';
4146: }
4147: }
1.89 raeburn 4148: $r->print($output);
1.225 raeburn 4149: if (!grep(/^\Q$role\E$/,@rolechanges)) {
4150: push(@rolechanges,$role);
4151: }
1.113 raeburn 4152: }
1.116 raeburn 4153: # Re-enable custom role
1.139 albertel 4154: if ($key=~m{^form\.ren\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
1.116 raeburn 4155: my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
1.465 raeburn 4156: my $id = $url.'_cr'."/$rdom/$rnam/$rolename";
4157: my $role = "cr/$rdom/$rnam/$rolename";
4158: if ($url =~ m-^/($match_domain)/($match_courseid)/?(\w*)$-) {
4159: my ($cdom,$cnum,$csec) = ($1,$2,$3);
4160: unless ($udom eq $cdom) {
4161: next if (&Apache::lonuserutils::restricted_dom($context,$id,$udom,
4162: $uname,$role,$now,0,$cdom,$cnum,$csec,'',\%process_by,
4163: \%instdoms,\%got_role_approvals,\%got_instdoms,\%reject,
1.466 raeburn 4164: \%pending,\%notifydc,\%status,\%unauthorized,\%currqueued));
1.465 raeburn 4165: }
4166: }
1.116 raeburn 4167: my $result = &Apache::lonnet::assigncustomrole(
4168: $env{'form.ccdomain'}, $env{'form.ccuname'},
1.240 raeburn 4169: $url,$rdom,$rnam,$rolename,0,$now,undef,$context);
1.369 bisitz 4170: $r->print(&Apache::lonhtmlcommon::confirm_success(
4171: &mt('Re-enabling custom role [_1] by [_2] in [_3]',
1.372 raeburn 4172: $rolename,$rnam.':'.$rdom,&Apache::loncommon::show_role_extent($1,$context,'cr')),
1.369 bisitz 4173: $result ne "ok").'<br />');
4174: if ($result ne "ok") {
4175: $r->print(&mt('Error: [_1]',$result).'<br />');
4176: }
1.225 raeburn 4177: if (!grep(/^cr$/,@rolechanges)) {
4178: push(@rolechanges,'cr');
4179: }
1.116 raeburn 4180: }
1.135 raeburn 4181: } elsif ($key=~/^form\.act/) {
1.101 albertel 4182: my $udom = $env{'form.ccdomain'};
4183: my $uname = $env{'form.ccuname'};
1.141 albertel 4184: if ($key=~/^form\.act\_($match_domain)\_($match_courseid)\_cr_cr_($match_domain)_($match_username)_([^\_]+)$/) {
1.65 www 4185: # Activate a custom role
1.83 albertel 4186: my ($one,$two,$three,$four,$five)=($1,$2,$3,$4,$5);
4187: my $url='/'.$one.'/'.$two;
1.465 raeburn 4188: my $id = $url.'_cr/'."$three/$four/$five";
4189: my $role = "cr/$three/$four/$five";
1.83 albertel 4190: my $full=$one.'_'.$two.'_cr_cr_'.$three.'_'.$four.'_'.$five;
1.65 www 4191:
1.101 albertel 4192: my $start = ( $env{'form.start_'.$full} ?
4193: $env{'form.start_'.$full} :
1.88 raeburn 4194: $now );
1.101 albertel 4195: my $end = ( $env{'form.end_'.$full} ?
4196: $env{'form.end_'.$full} :
1.88 raeburn 4197: 0 );
1.465 raeburn 4198:
1.88 raeburn 4199: # split multiple sections
4200: my %sections = ();
1.461 raeburn 4201: my $num_sections = &build_roles($env{'form.sec_'.$full},\%sections,$five);
1.88 raeburn 4202: if ($num_sections == 0) {
1.465 raeburn 4203: unless ($udom eq $one) {
4204: next if (&Apache::lonuserutils::restricted_dom($context,$id,$udom,
4205: $uname,$role,$start,$end,$one,$two,'','',\%process_by,
4206: \%instdoms,\%got_role_approvals,\%got_instdoms,\%reject,
1.466 raeburn 4207: \%pending,\%notifydc,\%status,\%unauthorized,\%currqueued));
1.465 raeburn 4208: }
1.240 raeburn 4209: $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$url,$three,$four,$five,$start,$end,$context));
1.88 raeburn 4210: } else {
1.114 albertel 4211: my %curr_groups =
1.117 raeburn 4212: &Apache::longroup::coursegroups($one,$two);
1.465 raeburn 4213: my ($restricted,$numchanges);
1.404 raeburn 4214: foreach my $sec (sort {$a cmp $b} keys(%sections)) {
1.113 raeburn 4215: if (($sec eq 'none') || ($sec eq 'all') ||
4216: exists($curr_groups{$sec})) {
4217: $disallowed{$sec} = $url;
4218: next;
4219: }
4220: my $securl = $url.'/'.$sec;
1.465 raeburn 4221: my $secid = $securl.'_cr'."/$three/$four/$five";
4222: undef($restricted);
4223: unless ($udom eq $one) {
4224: next if (&Apache::lonuserutils::restricted_dom($context,$secid,$udom,
4225: $uname,$role,$start,$end,$one,$two,$sec,'',\%process_by,
4226: \%instdoms,\%got_role_approvals,\%got_instdoms,\%reject,
1.466 raeburn 4227: \%pending,\%notifydc,\%status,\%unauthorized,\%currqueued));
1.465 raeburn 4228: }
4229: $numchanges ++;
1.240 raeburn 4230: $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$securl,$three,$four,$five,$start,$end,$context));
1.88 raeburn 4231: }
1.465 raeburn 4232: next unless ($numchanges);
1.88 raeburn 4233: }
1.225 raeburn 4234: if (!grep(/^cr$/,@rolechanges)) {
4235: push(@rolechanges,'cr');
4236: }
1.142 raeburn 4237: } elsif ($key=~/^form\.act\_($match_domain)\_($match_name)\_([^\_]+)$/) {
1.27 matthew 4238: # Activate roles for sections with 3 id numbers
4239: # set start, end times, and the url for the class
1.83 albertel 4240: my ($one,$two,$three)=($1,$2,$3);
1.461 raeburn 4241: my $start = ( $env{'form.start_'.$one.'_'.$two.'_'.$three} ?
4242: $env{'form.start_'.$one.'_'.$two.'_'.$three} :
1.27 matthew 4243: $now );
1.461 raeburn 4244: my $end = ( $env{'form.end_'.$one.'_'.$two.'_'.$three} ?
1.101 albertel 4245: $env{'form.end_'.$one.'_'.$two.'_'.$three} :
1.27 matthew 4246: 0 );
1.83 albertel 4247: my $url='/'.$one.'/'.$two;
1.465 raeburn 4248: my $id = $url.'_'.$three;
1.88 raeburn 4249: # split multiple sections
4250: my %sections = ();
1.101 albertel 4251: my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two.'_'.$three},\%sections,$three);
1.465 raeburn 4252: my ($credits,$numchanges);
1.375 raeburn 4253: if ($three eq 'st') {
1.461 raeburn 4254: if ($showcredits) {
1.375 raeburn 4255: my $defaultcredits =
4256: &Apache::lonuserutils::get_defaultcredits($one,$two);
4257: $credits = $env{'form.credits_'.$one.'_'.$two.'_'.$three};
4258: $credits =~ s/[^\d\.]//g;
4259: if ($credits eq $defaultcredits) {
4260: undef($credits);
4261: }
4262: }
4263: }
1.88 raeburn 4264: if ($num_sections == 0) {
1.465 raeburn 4265: unless ($udom eq $one) {
4266: next if (&Apache::lonuserutils::restricted_dom($context,$id,$udom,
4267: $uname,$three,$start,$end,$one,$two,'',$credits,\%process_by,
4268: \%instdoms,\%got_role_approvals,\%got_instdoms,\%reject,
1.466 raeburn 4269: \%pending,\%notifydc,\%status,\%unauthorized,\%currqueued));
1.465 raeburn 4270: }
4271: $numchanges ++;
1.375 raeburn 4272: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'',$context,$credits));
1.88 raeburn 4273: } else {
1.114 albertel 4274: my %curr_groups =
1.117 raeburn 4275: &Apache::longroup::coursegroups($one,$two);
1.88 raeburn 4276: my $emptysec = 0;
1.465 raeburn 4277: my $restricted;
1.404 raeburn 4278: foreach my $sec (sort {$a cmp $b} keys(%sections)) {
1.88 raeburn 4279: $sec =~ s/\W//g;
1.113 raeburn 4280: if ($sec ne '') {
4281: if (($sec eq 'none') || ($sec eq 'all') ||
4282: exists($curr_groups{$sec})) {
4283: $disallowed{$sec} = $url;
4284: next;
4285: }
1.88 raeburn 4286: my $securl = $url.'/'.$sec;
1.465 raeburn 4287: my $secid = $securl.'_'.$three;
4288: unless ($udom eq $one) {
4289: undef($restricted);
4290: $restricted = &Apache::lonuserutils::restricted_dom($context,$secid,$udom,
4291: $uname,$three,$start,$end,$one,$two,$sec,$credits,\%process_by,
4292: \%instdoms,\%got_role_approvals,\%got_instdoms,\%reject,
1.466 raeburn 4293: \%pending,\%notifydc,\%status,\%unauthorized,\%currqueued);
1.465 raeburn 4294: next if ($restricted);
4295: }
4296: $numchanges ++;
1.375 raeburn 4297: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$three,$start,$end,$one,$two,$sec,$context,$credits));
1.88 raeburn 4298: } else {
4299: $emptysec = 1;
4300: }
4301: }
4302: if ($emptysec) {
1.465 raeburn 4303: unless ($udom eq $one) {
4304: undef($restricted);
4305: $restricted = &Apache::lonuserutils::restricted_dom($context,$id,$udom,
4306: $uname,$three,$start,$end,$one,$two,'',$credits,\%process_by,
4307: \%instdoms,\%got_role_approvals,\%got_instdoms,\%reject,
1.466 raeburn 4308: \%pending,\%notifydc,\%status,\%unauthorized,\%currqueued);
1.465 raeburn 4309: next if ($restricted);
4310: }
4311: $numchanges ++;
1.375 raeburn 4312: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'',$context,$credits));
1.88 raeburn 4313: }
1.465 raeburn 4314: next unless ($numchanges);
1.225 raeburn 4315: }
4316: if (!grep(/^\Q$three\E$/,@rolechanges)) {
4317: push(@rolechanges,$three);
4318: }
1.135 raeburn 4319: } elsif ($key=~/^form\.act\_([^\_]+)\_([^\_]+)$/) {
1.27 matthew 4320: # Activate roles for sections with two id numbers
4321: # set start, end times, and the url for the class
1.461 raeburn 4322: my $start = ( $env{'form.start_'.$1.'_'.$2} ?
4323: $env{'form.start_'.$1.'_'.$2} :
1.27 matthew 4324: $now );
1.461 raeburn 4325: my $end = ( $env{'form.end_'.$1.'_'.$2} ?
1.101 albertel 4326: $env{'form.end_'.$1.'_'.$2} :
1.27 matthew 4327: 0 );
1.225 raeburn 4328: my $one = $1;
4329: my $two = $2;
4330: my $url='/'.$one.'/';
1.465 raeburn 4331: my $id = $url.'_'.$two;
1.468 raeburn 4332: my ($cdom,$cnum) = split(/\//,$one);
1.88 raeburn 4333: # split multiple sections
4334: my %sections = ();
1.465 raeburn 4335: my ($restricted,$numchanges);
1.225 raeburn 4336: my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two},\%sections,$two);
1.88 raeburn 4337: if ($num_sections == 0) {
1.465 raeburn 4338: unless ($udom eq $one) {
4339: $restricted = &Apache::lonuserutils::restricted_dom($context,$id,$udom,
1.468 raeburn 4340: $uname,$two,$start,$end,$cdom,$cnum,'','',\%process_by,
1.465 raeburn 4341: \%instdoms,\%got_role_approvals,\%got_instdoms,\%reject,
1.466 raeburn 4342: \%pending,\%notifydc,\%status,\%unauthorized,\%currqueued);
1.465 raeburn 4343: next if ($restricted);
4344: }
4345: $numchanges ++;
1.240 raeburn 4346: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,'',$context));
1.88 raeburn 4347: } else {
4348: my $emptysec = 0;
1.404 raeburn 4349: foreach my $sec (sort {$a cmp $b} keys(%sections)) {
1.88 raeburn 4350: if ($sec ne '') {
4351: my $securl = $url.'/'.$sec;
1.465 raeburn 4352: my $secid = $securl.'_'.$two;
4353: unless ($udom eq $one) {
4354: undef($restricted);
4355: $restricted = &Apache::lonuserutils::restricted_dom($context,$secid,$udom,
1.468 raeburn 4356: $uname,$two,$start,$end,$cdom,$cnum,$sec,'',\%process_by,
1.465 raeburn 4357: \%instdoms,\%got_role_approvals,\%got_instdoms,\%reject,
1.466 raeburn 4358: \%pending,\%notifydc,\%status,\%unauthorized,\%currqueued);
1.465 raeburn 4359: next if ($restricted);
4360: }
4361: $numchanges ++;
1.240 raeburn 4362: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$two,$start,$end,$one,undef,$sec,$context));
1.88 raeburn 4363: } else {
4364: $emptysec = 1;
4365: }
4366: }
4367: if ($emptysec) {
1.465 raeburn 4368: unless ($udom eq $one) {
4369: undef($restricted);
4370: $restricted = &Apache::lonuserutils::restricted_dom($context,$id,$udom,
1.468 raeburn 4371: $uname,$two,$start,$end,$cdom,$cnum,'','',\%process_by,
1.465 raeburn 4372: \%instdoms,\%got_role_approvals,\%got_instdoms,\%reject,
1.466 raeburn 4373: \%pending,\%notifydc,\%status,\%unauthorized,\%currqueued);
1.465 raeburn 4374: next if ($restricted);
4375: }
4376: $numchanges ++;
1.240 raeburn 4377: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,'',$context));
1.88 raeburn 4378: }
1.465 raeburn 4379: next unless ($numchanges);
1.88 raeburn 4380: }
1.225 raeburn 4381: if (!grep(/^\Q$two\E$/,@rolechanges)) {
4382: push(@rolechanges,$two);
4383: }
1.64 www 4384: } else {
1.190 raeburn 4385: $r->print('<p><span class="LC_error">'.&mt('ERROR').': '.&mt('Unknown command').' <tt>'.$key.'</tt></span></p><br />');
1.64 www 4386: }
1.113 raeburn 4387: foreach my $key (sort(keys(%disallowed))) {
1.274 bisitz 4388: $r->print('<p class="LC_warning">');
1.113 raeburn 4389: if (($key eq 'none') || ($key eq 'all')) {
1.274 bisitz 4390: $r->print(&mt('[_1] may not be used as the name for a section, as it is a reserved word.','<tt>'.$key.'</tt>'));
1.113 raeburn 4391: } else {
1.274 bisitz 4392: $r->print(&mt('[_1] may not be used as the name for a section, as it is the name of a course group.','<tt>'.$key.'</tt>'));
1.113 raeburn 4393: }
1.274 bisitz 4394: $r->print('</p><p>'
4395: .&mt('Please [_1]go back[_2] and choose a different section name.'
4396: ,'<a href="javascript:history.go(-1)'
4397: ,'</a>')
4398: .'</p><br />'
4399: );
1.113 raeburn 4400: }
4401: }
1.101 albertel 4402: } # End of foreach (keys(%env))
1.466 raeburn 4403: if ((keys(%reject)) || (keys(%unauthorized))) {
4404: $r->print(&Apache::lonuserutils::print_roles_rejected($context,\%reject,\%unauthorized));
1.465 raeburn 4405: }
1.466 raeburn 4406: if ((keys(%pending)) || (keys(%currqueued))) {
4407: $r->print(&Apache::lonuserutils::print_roles_queued($context,\%pending,\%notifydc,\%currqueued));
1.465 raeburn 4408: }
1.75 www 4409: # Flush the course logs so reverse user roles immediately updated
1.349 raeburn 4410: $r->register_cleanup(\&Apache::lonnet::flushcourselogs);
1.225 raeburn 4411: if (@rolechanges == 0) {
1.372 raeburn 4412: $r->print('<p>'.&mt('No roles to modify').'</p>');
1.193 raeburn 4413: }
1.225 raeburn 4414: return @rolechanges;
1.220 raeburn 4415: }
4416:
1.375 raeburn 4417: sub get_user_credits {
4418: my ($uname,$udom,$defaultcredits,$cdom,$cnum) = @_;
4419: if ($cdom eq '' || $cnum eq '') {
4420: return unless ($env{'request.course.id'});
4421: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
4422: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
4423: }
4424: my $credits;
4425: my %currhash =
4426: &Apache::lonnet::get('classlist',[$uname.':'.$udom],$cdom,$cnum);
4427: if (keys(%currhash) > 0) {
4428: my @items = split(/:/,$currhash{$uname.':'.$udom});
4429: my $crdidx = &Apache::loncoursedata::CL_CREDITS() - 3;
4430: $credits = $items[$crdidx];
4431: $credits =~ s/[^\d\.]//g;
4432: }
4433: if ($credits eq $defaultcredits) {
4434: undef($credits);
4435: }
4436: return $credits;
4437: }
4438:
1.220 raeburn 4439: sub enroll_single_student {
1.375 raeburn 4440: my ($r,$uhome,$amode,$genpwd,$now,$newuser,$context,$crstype,
4441: $showcredits,$defaultcredits) = @_;
1.318 raeburn 4442: $r->print('<h3>');
4443: if ($crstype eq 'Community') {
4444: $r->print(&mt('Enrolling Member'));
4445: } else {
4446: $r->print(&mt('Enrolling Student'));
4447: }
4448: $r->print('</h3>');
1.220 raeburn 4449:
4450: # Remove non alphanumeric values from section
4451: $env{'form.sections'}=~s/\W//g;
4452:
1.375 raeburn 4453: my $credits;
4454: if (($showcredits) && ($env{'form.credits'} ne '')) {
4455: $credits = $env{'form.credits'};
4456: $credits =~ s/[^\d\.]//g;
4457: if ($credits ne '') {
4458: if ($credits eq $defaultcredits) {
4459: undef($credits);
4460: }
4461: }
4462: }
1.465 raeburn 4463: my ($startdate,$enddate) = &Apache::lonuserutils::get_dates_from_form();
1.466 raeburn 4464: my (%got_role_approvals,%got_instdoms,%process_by,%instdoms,%pending,%reject,%notifydc,
4465: %status,%unauthorized,%currqueued);
1.465 raeburn 4466: unless ($env{'form.ccdomain'} eq $env{'course.'.$env{'request.course.id'}.'.domain'}) {
4467: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
4468: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
4469: my $csec = $env{'form.sections'};
4470: my $id = "/$cdom/$cnum";
4471: if ($csec ne '') {
4472: $id .= "/$csec";
4473: }
4474: $id .= '_st';
4475: if (&Apache::lonuserutils::restricted_dom($context,$id,$env{'form.ccdomain'},$env{'form.ccuname'},
4476: 'st',$startdate,$enddate,$cdom,$cnum,$csec,$credits,
4477: \%process_by,\%instdoms,\%got_role_approvals,\%got_instdoms,
1.466 raeburn 4478: \%reject,\%pending,\%notifydc,\%status,\%unauthorized,\%currqueued)) {
4479: if ((keys(%reject)) || (keys(%unauthorized))) {
4480: $r->print(&Apache::lonuserutils::print_roles_rejected($context,\%reject,\%unauthorized));
1.465 raeburn 4481: }
1.466 raeburn 4482: if ((keys(%pending)) || (keys(%currqueued))) {
4483: $r->print(&Apache::lonuserutils::print_roles_queued($context,\%pending,\%notifydc,\%currqueued));
1.465 raeburn 4484: }
4485: return;
4486: }
4487: }
1.375 raeburn 4488:
1.220 raeburn 4489: # Clean out any old student roles the user has in this class.
4490: &Apache::lonuserutils::modifystudent($env{'form.ccdomain'},
4491: $env{'form.ccuname'},$env{'request.course.id'},undef,$uhome);
4492: my $enroll_result =
4493: &Apache::lonnet::modify_student_enrollment($env{'form.ccdomain'},
4494: $env{'form.ccuname'},$env{'form.cid'},$env{'form.cfirstname'},
4495: $env{'form.cmiddlename'},$env{'form.clastname'},
4496: $env{'form.generation'},$env{'form.sections'},$enddate,
1.375 raeburn 4497: $startdate,'manual',undef,$env{'request.course.id'},'',$context,
4498: $credits);
1.220 raeburn 4499: if ($enroll_result =~ /^ok/) {
1.381 bisitz 4500: $r->print(&mt('[_1] enrolled','<b>'.$env{'form.ccuname'}.':'.$env{'form.ccdomain'}.'</b>'));
1.220 raeburn 4501: if ($env{'form.sections'} ne '') {
4502: $r->print(' '.&mt('in section [_1]',$env{'form.sections'}));
4503: }
4504: my ($showstart,$showend);
4505: if ($startdate <= $now) {
4506: $showstart = &mt('Access starts immediately');
4507: } else {
4508: $showstart = &mt('Access starts: ').&Apache::lonlocal::locallocaltime($startdate);
4509: }
4510: if ($enddate == 0) {
4511: $showend = &mt('ends: no ending date');
4512: } else {
4513: $showend = &mt('ends: ').&Apache::lonlocal::locallocaltime($enddate);
4514: }
4515: $r->print('.<br />'.$showstart.'; '.$showend);
4516: if ($startdate <= $now && !$newuser) {
1.386 bisitz 4517: $r->print('<p class="LC_info">');
1.318 raeburn 4518: if ($crstype eq 'Community') {
1.392 raeburn 4519: $r->print(&mt('If the member is currently logged-in to LON-CAPA, the new role can be displayed by using the "Check for changes" link on the Roles/Courses page.'));
1.318 raeburn 4520: } else {
1.392 raeburn 4521: $r->print(&mt('If the student is currently logged-in to LON-CAPA, the new role can be displayed by using the "Check for changes" link on the Roles/Courses page.'));
1.318 raeburn 4522: }
4523: $r->print('</p>');
1.220 raeburn 4524: }
4525: } else {
4526: $r->print(&mt('unable to enroll').": ".$enroll_result);
4527: }
4528: return;
1.188 raeburn 4529: }
4530:
1.204 raeburn 4531: sub get_defaultquota_text {
4532: my ($settingstatus) = @_;
4533: my $defquotatext;
4534: if ($settingstatus eq '') {
1.383 raeburn 4535: $defquotatext = &mt('default');
1.204 raeburn 4536: } else {
4537: my ($usertypes,$order) =
4538: &Apache::lonnet::retrieve_inst_usertypes($env{'form.ccdomain'});
4539: if ($usertypes->{$settingstatus} eq '') {
1.383 raeburn 4540: $defquotatext = &mt('default');
1.204 raeburn 4541: } else {
1.383 raeburn 4542: $defquotatext = &mt('default for [_1]',$usertypes->{$settingstatus});
1.204 raeburn 4543: }
4544: }
4545: return $defquotatext;
4546: }
4547:
1.188 raeburn 4548: sub update_result_form {
4549: my ($uhome) = @_;
4550: my $outcome =
1.367 golterma 4551: '<form name="userupdate" method="post" action="">'."\n";
1.160 raeburn 4552: foreach my $item ('srchby','srchin','srchtype','srchterm','srchdomain','ccuname','ccdomain') {
1.188 raeburn 4553: $outcome .= '<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n";
1.160 raeburn 4554: }
1.207 raeburn 4555: if ($env{'form.origname'} ne '') {
4556: $outcome .= '<input type="hidden" name="origname" value="'.$env{'form.origname'}.'" />'."\n";
4557: }
1.160 raeburn 4558: foreach my $item ('sortby','seluname','seludom') {
4559: if (exists($env{'form.'.$item})) {
1.188 raeburn 4560: $outcome .= '<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n";
1.160 raeburn 4561: }
4562: }
1.188 raeburn 4563: if ($uhome eq 'no_host') {
4564: $outcome .= '<input type="hidden" name="forcenewuser" value="1" />'."\n";
4565: }
4566: $outcome .= '<input type="hidden" name="phase" value="" />'."\n".
1.383 raeburn 4567: '<input type="hidden" name="currstate" value="" />'."\n".
4568: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n".
1.188 raeburn 4569: '</form>';
4570: return $outcome;
1.4 www 4571: }
4572:
1.149 raeburn 4573: sub quota_admin {
1.378 raeburn 4574: my ($setquota,$changeHash,$name) = @_;
1.149 raeburn 4575: my $quotachanged;
4576: if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
4577: # Current user has quota modification privileges
1.267 raeburn 4578: if (ref($changeHash) eq 'HASH') {
4579: $quotachanged = 1;
1.378 raeburn 4580: $changeHash->{$name.'quota'} = $setquota;
1.267 raeburn 4581: }
1.149 raeburn 4582: }
4583: return $quotachanged;
4584: }
4585:
1.267 raeburn 4586: sub tool_admin {
1.275 raeburn 4587: my ($tool,$settool,$changeHash,$context) = @_;
4588: my $canchange = 0;
1.279 raeburn 4589: if ($context eq 'requestcourses') {
1.275 raeburn 4590: if (&Apache::lonnet::allowed('ccc',$env{'form.ccdomain'})) {
4591: $canchange = 1;
4592: }
1.300 raeburn 4593: } elsif ($context eq 'reqcrsotherdom') {
4594: if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
4595: $canchange = 1;
4596: }
1.362 raeburn 4597: } elsif ($context eq 'requestauthor') {
4598: if (&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) {
4599: $canchange = 1;
4600: }
1.275 raeburn 4601: } elsif (&Apache::lonnet::allowed('mut',$env{'form.ccdomain'})) {
4602: # Current user has quota modification privileges
4603: $canchange = 1;
4604: }
1.267 raeburn 4605: my $toolchanged;
1.275 raeburn 4606: if ($canchange) {
1.267 raeburn 4607: if (ref($changeHash) eq 'HASH') {
4608: $toolchanged = 1;
1.362 raeburn 4609: if ($tool eq 'requestauthor') {
4610: $changeHash->{$context} = $settool;
4611: } else {
4612: $changeHash->{$context.'.'.$tool} = $settool;
4613: }
1.267 raeburn 4614: }
4615: }
4616: return $toolchanged;
4617: }
4618:
1.88 raeburn 4619: sub build_roles {
1.89 raeburn 4620: my ($sectionstr,$sections,$role) = @_;
1.88 raeburn 4621: my $num_sections = 0;
4622: if ($sectionstr=~ /,/) {
4623: my @secnums = split/,/,$sectionstr;
1.89 raeburn 4624: if ($role eq 'st') {
4625: $secnums[0] =~ s/\W//g;
4626: $$sections{$secnums[0]} = 1;
4627: $num_sections = 1;
4628: } else {
4629: foreach my $sec (@secnums) {
4630: $sec =~ ~s/\W//g;
1.150 banghart 4631: if (!($sec eq "")) {
1.89 raeburn 4632: if (exists($$sections{$sec})) {
4633: $$sections{$sec} ++;
4634: } else {
4635: $$sections{$sec} = 1;
4636: $num_sections ++;
4637: }
1.88 raeburn 4638: }
4639: }
4640: }
4641: } else {
4642: $sectionstr=~s/\W//g;
4643: unless ($sectionstr eq '') {
4644: $$sections{$sectionstr} = 1;
4645: $num_sections ++;
4646: }
4647: }
1.129 albertel 4648:
1.88 raeburn 4649: return $num_sections;
4650: }
4651:
1.58 www 4652: # ========================================================== Custom Role Editor
4653:
4654: sub custom_role_editor {
1.439 raeburn 4655: my ($r,$context,$brcrum,$prefix,$permission) = @_;
1.324 raeburn 4656: my $action = $env{'form.customroleaction'};
1.439 raeburn 4657: my ($rolename,$helpitem);
1.324 raeburn 4658: if ($action eq 'new') {
4659: $rolename=$env{'form.newrolename'};
4660: } else {
4661: $rolename=$env{'form.rolename'};
1.59 www 4662: }
4663:
1.324 raeburn 4664: my ($crstype,$context);
4665: if ($env{'request.course.id'}) {
4666: $crstype = &Apache::loncommon::course_type();
4667: $context = 'course';
1.439 raeburn 4668: $helpitem = 'Course_Editing_Custom_Roles';
1.324 raeburn 4669: } else {
4670: $context = 'domain';
1.414 raeburn 4671: $crstype = 'course';
1.439 raeburn 4672: $helpitem = 'Domain_Editing_Custom_Roles';
1.324 raeburn 4673: }
1.351 raeburn 4674:
4675: $rolename=~s/[^A-Za-z0-9]//gs;
4676: if (!$rolename || $env{'form.phase'} eq 'pickrole') {
1.439 raeburn 4677: &print_username_entry_form($r,$context,undef,undef,undef,$crstype,$brcrum,
4678: $permission);
1.351 raeburn 4679: return;
4680: }
4681:
1.414 raeburn 4682: my $formname = 'form1';
4683: my %privs=();
4684: my $body_top = '<h2>';
4685: # ------------------------------------------------------- Does this role exist?
1.59 www 4686: my ($rdummy,$roledef)=
4687: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
4688: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1.414 raeburn 4689: $body_top .= &mt('Existing Role').' "';
1.61 www 4690: # ------------------------------------------------- Get current role privileges
1.414 raeburn 4691: ($privs{'system'},$privs{'domain'},$privs{'course'})=split(/\_/,$roledef);
4692: if ($privs{'system'} =~ /bre\&S/) {
4693: if ($context eq 'domain') {
1.417 raeburn 4694: $crstype = 'Course';
1.414 raeburn 4695: } elsif ($crstype eq 'Community') {
4696: $privs{'system'} =~ s/bre\&S//;
4697: }
4698: } elsif ($context eq 'domain') {
4699: $crstype = 'Course';
1.324 raeburn 4700: }
1.59 www 4701: } else {
1.414 raeburn 4702: $body_top .= &mt('New Role').' "';
4703: $roledef='';
1.59 www 4704: }
1.153 banghart 4705: $body_top .= $rolename.'"</h2>';
1.414 raeburn 4706:
4707: # ------------------------------------------------------- What can be assigned?
4708: my %full=();
1.417 raeburn 4709: my %levels=(
1.414 raeburn 4710: course => {},
4711: domain => {},
4712: system => {},
4713: );
4714: my %levelscurrent=(
4715: course => {},
4716: domain => {},
4717: system => {},
4718: );
4719: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
1.160 raeburn 4720: my ($jsback,$elements) = &crumb_utilities();
1.414 raeburn 4721: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
1.417 raeburn 4722: my $head_script =
1.414 raeburn 4723: &Apache::lonuserutils::custom_roledefs_js($context,$crstype,$formname,
4724: \%full,\@templateroles,$jsback);
1.351 raeburn 4725: push (@{$brcrum},
1.414 raeburn 4726: {href => "javascript:backPage(document.$formname,'pickrole','')",
1.351 raeburn 4727: text => "Pick custom role",
4728: faq => 282,bug=>'Instructor Interface',},
1.414 raeburn 4729: {href => "javascript:backPage(document.$formname,'','')",
1.351 raeburn 4730: text => "Edit custom role",
4731: faq => 282,
4732: bug => 'Instructor Interface',
1.439 raeburn 4733: help => $helpitem}
1.351 raeburn 4734: );
4735: my $args = { bread_crumbs => $brcrum,
4736: bread_crumbs_component => 'User Management'};
4737: $r->print(&Apache::loncommon::start_page('Custom Role Editor',
4738: $head_script,$args).
4739: $body_top);
1.414 raeburn 4740: $r->print('<form name="'.$formname.'" method="post" action="">'."\n".
4741: &Apache::lonuserutils::custom_role_header($context,$crstype,
4742: \@templateroles,$prefix));
1.264 bisitz 4743:
1.61 www 4744: $r->print(<<ENDCCF);
4745: <input type="hidden" name="phase" value="set_custom_roles" />
4746: <input type="hidden" name="rolename" value="$rolename" />
4747: ENDCCF
1.414 raeburn 4748: $r->print(&Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
4749: \%levelscurrent,$prefix));
1.135 raeburn 4750: $r->print(&Apache::loncommon::end_data_table().
1.190 raeburn 4751: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'.
1.160 raeburn 4752: '<input type="hidden" name="startrolename" value="'.$env{'form.rolename'}.
1.417 raeburn 4753: '" />'."\n".'<input type="hidden" name="currstate" value="" />'."\n".
1.160 raeburn 4754: '<input type="reset" value="'.&mt("Reset").'" />'."\n".
1.351 raeburn 4755: '<input type="submit" value="'.&mt('Save').'" /></form>');
1.61 www 4756: }
1.414 raeburn 4757:
1.61 www 4758: # ---------------------------------------------------------- Call to definerole
4759: sub set_custom_role {
1.439 raeburn 4760: my ($r,$context,$brcrum,$prefix,$permission) = @_;
1.101 albertel 4761: my $rolename=$env{'form.rolename'};
1.63 www 4762: $rolename=~s/[^A-Za-z0-9]//gs;
1.150 banghart 4763: if (!$rolename) {
1.439 raeburn 4764: &custom_role_editor($r,$context,$brcrum,$prefix,$permission);
1.61 www 4765: return;
4766: }
1.160 raeburn 4767: my ($jsback,$elements) = &crumb_utilities();
1.301 bisitz 4768: my $jscript = '<script type="text/javascript">'
4769: .'// <![CDATA['."\n"
4770: .$jsback."\n"
4771: .'// ]]>'."\n"
4772: .'</script>'."\n";
1.439 raeburn 4773: my $helpitem = 'Course_Editing_Custom_Roles';
4774: if ($context eq 'domain') {
4775: $helpitem = 'Domain_Editing_Custom_Roles';
4776: }
1.352 raeburn 4777: push(@{$brcrum},
4778: {href => "javascript:backPage(document.customresult,'pickrole','')",
4779: text => "Pick custom role",
4780: faq => 282,
4781: bug => 'Instructor Interface',},
4782: {href => "javascript:backPage(document.customresult,'selected_custom_edit','')",
4783: text => "Edit custom role",
4784: faq => 282,
4785: bug => 'Instructor Interface',},
4786: {href => "javascript:backPage(document.customresult,'set_custom_roles','')",
4787: text => "Result",
4788: faq => 282,
4789: bug => 'Instructor Interface',
1.439 raeburn 4790: help => $helpitem,}
1.352 raeburn 4791: );
4792: my $args = { bread_crumbs => $brcrum,
1.414 raeburn 4793: bread_crumbs_component => 'User Management'};
1.351 raeburn 4794: $r->print(&Apache::loncommon::start_page('Save Custom Role',$jscript,$args));
1.160 raeburn 4795:
1.393 raeburn 4796: my $newrole;
1.61 www 4797: my ($rdummy,$roledef)=
1.110 albertel 4798: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
4799:
1.61 www 4800: # ------------------------------------------------------- Does this role exist?
1.188 raeburn 4801: $r->print('<h3>');
1.61 www 4802: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1.73 sakharuk 4803: $r->print(&mt('Existing Role').' "');
1.61 www 4804: } else {
1.73 sakharuk 4805: $r->print(&mt('New Role').' "');
1.61 www 4806: $roledef='';
1.393 raeburn 4807: $newrole = 1;
1.61 www 4808: }
1.188 raeburn 4809: $r->print($rolename.'"</h3>');
1.414 raeburn 4810: # ------------------------------------------------- Assign role and show result
1.61 www 4811:
1.387 bisitz 4812: my $errmsg;
1.414 raeburn 4813: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$prefix);
4814: # Assign role and return result
4815: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
4816: $newprivs{'c'});
1.387 bisitz 4817: if ($result ne 'ok') {
4818: $errmsg = ': '.$result;
4819: }
4820: my $message =
4821: &Apache::lonhtmlcommon::confirm_success(
4822: &mt('Defining Role').$errmsg, ($result eq 'ok' ? 0 : 1));
1.101 albertel 4823: if ($env{'request.course.id'}) {
4824: my $url='/'.$env{'request.course.id'};
1.63 www 4825: $url=~s/\_/\//g;
1.387 bisitz 4826: $result =
4827: &Apache::lonnet::assigncustomrole(
4828: $env{'user.domain'},$env{'user.name'},
4829: $url,
4830: $env{'user.domain'},$env{'user.name'},
4831: $rolename,undef,undef,undef,$context);
4832: if ($result ne 'ok') {
4833: $errmsg = ': '.$result;
4834: }
4835: $message .=
4836: '<br />'
4837: .&Apache::lonhtmlcommon::confirm_success(
4838: &mt('Assigning Role to Self').$errmsg, ($result eq 'ok' ? 0 : 1));
1.63 www 4839: }
1.380 bisitz 4840: $r->print(
1.387 bisitz 4841: &Apache::loncommon::confirmwrapper($message)
4842: .'<br />'
4843: .&Apache::lonhtmlcommon::actionbox([
4844: '<a href="javascript:backPage(document.customresult,'."'pickrole'".')">'
4845: .&mt('Create or edit another custom role')
4846: .'</a>'])
1.380 bisitz 4847: .'<form name="customresult" method="post" action="">'
1.387 bisitz 4848: .&Apache::lonhtmlcommon::echo_form_input([])
4849: .'</form>'
1.380 bisitz 4850: );
1.58 www 4851: }
4852:
1.465 raeburn 4853: sub show_role_requests {
4854: my ($caller,$dom) = @_;
4855: my $showrolereqs;
4856: my %domconfig = &Apache::lonnet::get_dom('configuration',['privacy'],$dom);
4857: if (ref($domconfig{'privacy'}) eq 'HASH') {
4858: if (ref($domconfig{'privacy'}{'approval'}) eq 'HASH') {
4859: my %approvalconf = %{$domconfig{'privacy'}{'approval'}};
4860: foreach my $key ('instdom','extdom') {
4861: if (ref($approvalconf{$key}) eq 'HASH') {
4862: if (keys(%{$approvalconf{$key}})) {
4863: foreach my $context ('domain','author','course','community') {
4864: if ($approvalconf{$key}{$context} eq $caller) {
4865: $showrolereqs = 1;
4866: last if ($showrolereqs);
4867: }
4868: }
4869: }
4870: }
4871: last if ($showrolereqs);
4872: }
4873: }
4874: }
4875: return $showrolereqs;
4876: }
4877:
1.2 www 4878: # ================================================================ Main Handler
4879: sub handler {
4880: my $r = shift;
4881: if ($r->header_only) {
1.68 www 4882: &Apache::loncommon::content_type($r,'text/html');
1.2 www 4883: $r->send_http_header;
4884: return OK;
4885: }
1.439 raeburn 4886: my ($context,$crstype,$cid,$cnum,$cdom,$allhelpitems);
4887:
1.190 raeburn 4888: if ($env{'request.course.id'}) {
4889: $context = 'course';
1.318 raeburn 4890: $crstype = &Apache::loncommon::course_type();
1.190 raeburn 4891: } elsif ($env{'request.role'} =~ /^au\./) {
1.206 raeburn 4892: $context = 'author';
1.190 raeburn 4893: } else {
4894: $context = 'domain';
4895: }
1.375 raeburn 4896:
1.439 raeburn 4897: my ($permission,$allowed) =
4898: &Apache::lonuserutils::get_permission($context,$crstype);
4899:
4900: if ($allowed) {
4901: my @allhelp;
4902: if ($context eq 'course') {
4903: $cid = $env{'request.course.id'};
4904: $cdom = $env{'course.'.$cid.'.domain'};
4905: $cnum = $env{'course.'.$cid.'.num'};
4906:
4907: if ($permission->{'cusr'}) {
4908: push(@allhelp,'Course_Create_Class_List');
4909: }
4910: if ($permission->{'view'} || $permission->{'cusr'}) {
4911: push(@allhelp,('Course_Change_Privileges','Course_View_Class_List'));
4912: }
4913: if ($permission->{'custom'}) {
4914: push(@allhelp,'Course_Editing_Custom_Roles');
4915: }
4916: if ($permission->{'cusr'}) {
4917: push(@allhelp,('Course_Add_Student','Course_Drop_Student'));
4918: }
4919: unless ($permission->{'cusr_section'}) {
4920: if (&Apache::lonnet::auto_run($cnum,$cdom) && (($permission->{'cusr'}) || ($permission->{'view'}))) {
4921: push(@allhelp,'Course_Automated_Enrollment');
4922: }
1.469 ! raeburn 4923: if (($permission->{'selfenrolladmin'}) || ($permission->{'selfenrollview'})) {
1.439 raeburn 4924: push(@allhelp,'Course_Approve_Selfenroll');
4925: }
4926: }
4927: if ($permission->{'grp_manage'}) {
4928: push(@allhelp,'Course_Manage_Group');
4929: }
4930: if ($permission->{'view'} || $permission->{'cusr'}) {
4931: push(@allhelp,'Course_User_Logs');
4932: }
4933: } elsif ($context eq 'author') {
4934: push(@allhelp,('Author_Change_Privileges','Author_Create_Coauthor_List',
4935: 'Author_View_Coauthor_List','Author_User_Logs'));
4936: } else {
4937: if ($permission->{'cusr'}) {
4938: push(@allhelp,'Domain_Change_Privileges');
4939: if ($permission->{'activity'}) {
4940: push(@allhelp,'Domain_User_Access_Logs');
4941: }
4942: push(@allhelp,('Domain_Create_Users','Domain_View_Users_List'));
4943: if ($permission->{'custom'}) {
4944: push(@allhelp,'Domain_Editing_Custom_Roles');
4945: }
4946: push(@allhelp,('Domain_Role_Approvals','Domain_Username_Approvals','Domain_Change_Logs'));
4947: } elsif ($permission->{'view'}) {
4948: push(@allhelp,'Domain_View_Privileges');
4949: if ($permission->{'activity'}) {
4950: push(@allhelp,'Domain_User_Access_Logs');
4951: }
4952: push(@allhelp,('Domain_View_Users_List','Domain_Change_Logs'));
4953: }
4954: }
4955: if (@allhelp) {
4956: $allhelpitems = join(',',@allhelp);
4957: }
4958: }
4959:
1.190 raeburn 4960: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.233 raeburn 4961: ['action','state','callingform','roletype','showrole','bulkaction','popup','phase',
1.391 raeburn 4962: 'username','domain','srchterm','srchdomain','srchin','srchby','srchtype','queue']);
1.190 raeburn 4963: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.351 raeburn 4964: my $args;
4965: my $brcrum = [];
4966: my $bread_crumbs_component = 'User Management';
1.391 raeburn 4967: if (($env{'form.action'} ne 'dateselect') && ($env{'form.action'} ne 'displayuserreq')) {
1.351 raeburn 4968: $brcrum = [{href=>"/adm/createuser",
4969: text=>"User Management",
1.439 raeburn 4970: help=>$allhelpitems}
1.351 raeburn 4971: ];
1.202 raeburn 4972: }
1.190 raeburn 4973: if (!$allowed) {
1.358 raeburn 4974: if ($context eq 'course') {
4975: $r->internal_redirect('/adm/viewclasslist');
4976: return OK;
4977: }
1.190 raeburn 4978: $env{'user.error.msg'}=
4979: "/adm/createuser:cst:0:0:Cannot create/modify user data ".
4980: "or view user status.";
4981: return HTTP_NOT_ACCEPTABLE;
4982: }
4983:
4984: &Apache::loncommon::content_type($r,'text/html');
4985: $r->send_http_header;
4986:
1.375 raeburn 4987: my $showcredits;
4988: if ((($context eq 'course') && ($crstype eq 'Course')) ||
4989: ($context eq 'domain')) {
4990: my %domdefaults =
4991: &Apache::lonnet::get_domain_defaults($env{'request.role.domain'});
4992: if ($domdefaults{'officialcredits'} || $domdefaults{'unofficialcredits'}) {
4993: $showcredits = 1;
4994: }
4995: }
4996:
1.190 raeburn 4997: # Main switch on form.action and form.state, as appropriate
4998: if (! exists($env{'form.action'})) {
1.351 raeburn 4999: $args = {bread_crumbs => $brcrum,
5000: bread_crumbs_component => $bread_crumbs_component};
5001: $r->print(&header(undef,$args));
1.318 raeburn 5002: $r->print(&print_main_menu($permission,$context,$crstype));
1.190 raeburn 5003: } elsif ($env{'form.action'} eq 'upload' && $permission->{'cusr'}) {
1.439 raeburn 5004: my $helpitem = 'Course_Create_Class_List';
5005: if ($context eq 'author') {
5006: $helpitem = 'Author_Create_Coauthor_List';
5007: } elsif ($context eq 'domain') {
5008: $helpitem = 'Domain_Create_Users';
5009: }
1.351 raeburn 5010: push(@{$brcrum},
5011: { href => '/adm/createuser?action=upload&state=',
5012: text => 'Upload Users List',
1.439 raeburn 5013: help => $helpitem,
1.351 raeburn 5014: });
5015: $bread_crumbs_component = 'Upload Users List';
5016: $args = {bread_crumbs => $brcrum,
5017: bread_crumbs_component => $bread_crumbs_component};
5018: $r->print(&header(undef,$args));
1.190 raeburn 5019: $r->print('<form name="studentform" method="post" '.
5020: 'enctype="multipart/form-data" '.
5021: ' action="/adm/createuser">'."\n");
5022: if (! exists($env{'form.state'})) {
5023: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
5024: } elsif ($env{'form.state'} eq 'got_file') {
1.448 raeburn 5025: my $result =
5026: &Apache::lonuserutils::print_upload_manager_form($r,$context,
5027: $permission,
5028: $crstype,$showcredits);
5029: if ($result eq 'missingdata') {
5030: delete($env{'form.state'});
5031: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
5032: }
1.190 raeburn 5033: } elsif ($env{'form.state'} eq 'enrolling') {
5034: if ($env{'form.datatoken'}) {
1.448 raeburn 5035: my $result = &Apache::lonuserutils::upfile_drop_add($r,$context,
5036: $permission,
5037: $showcredits);
5038: if ($result eq 'missingdata') {
5039: delete($env{'form.state'});
5040: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
5041: } elsif ($result eq 'invalidhome') {
5042: $env{'form.state'} = 'got_file';
5043: delete($env{'form.lcserver'});
5044: my $result =
5045: &Apache::lonuserutils::print_upload_manager_form($r,$context,$permission,
5046: $crstype,$showcredits);
5047: if ($result eq 'missingdata') {
5048: delete($env{'form.state'});
5049: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
5050: }
5051: }
5052: } else {
5053: delete($env{'form.state'});
5054: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
1.190 raeburn 5055: }
5056: } else {
5057: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
5058: }
1.447 raeburn 5059: $r->print('</form>');
1.416 raeburn 5060: } elsif (((($env{'form.action'} eq 'singleuser') || ($env{'form.action'}
5061: eq 'singlestudent')) && ($permission->{'cusr'})) ||
1.418 raeburn 5062: (($env{'form.action'} eq 'singleuser') && ($permission->{'view'})) ||
1.416 raeburn 5063: (($env{'form.action'} eq 'accesslogs') && ($permission->{'activity'}))) {
1.190 raeburn 5064: my $phase = $env{'form.phase'};
5065: my @search = ('srchterm','srchby','srchin','srchtype','srchdomain');
1.192 albertel 5066: &Apache::loncreateuser::restore_prev_selections();
5067: my $srch;
5068: foreach my $item (@search) {
5069: $srch->{$item} = $env{'form.'.$item};
5070: }
1.207 raeburn 5071: if (($phase eq 'get_user_info') || ($phase eq 'userpicked') ||
1.416 raeburn 5072: ($phase eq 'createnewuser') || ($phase eq 'activity')) {
1.207 raeburn 5073: if ($env{'form.phase'} eq 'createnewuser') {
5074: my $response;
5075: if ($env{'form.srchterm'} !~ /^$match_username$/) {
1.366 bisitz 5076: my $response =
5077: '<span class="LC_warning">'
5078: .&mt('You must specify a valid username. Only the following are allowed:'
5079: .' letters numbers - . @')
5080: .'</span>';
1.221 raeburn 5081: $env{'form.phase'} = '';
1.375 raeburn 5082: &print_username_entry_form($r,$context,$response,$srch,undef,
1.439 raeburn 5083: $crstype,$brcrum,$permission);
1.207 raeburn 5084: } else {
5085: my $ccuname =&LONCAPA::clean_username($srch->{'srchterm'});
5086: my $ccdomain=&LONCAPA::clean_domain($srch->{'srchdomain'});
5087: &print_user_modification_page($r,$ccuname,$ccdomain,
1.221 raeburn 5088: $srch,$response,$context,
1.375 raeburn 5089: $permission,$crstype,$brcrum,
5090: $showcredits);
1.207 raeburn 5091: }
5092: } elsif ($env{'form.phase'} eq 'get_user_info') {
1.190 raeburn 5093: my ($currstate,$response,$forcenewuser,$results) =
1.221 raeburn 5094: &user_search_result($context,$srch);
1.190 raeburn 5095: if ($env{'form.currstate'} eq 'modify') {
5096: $currstate = $env{'form.currstate'};
5097: }
5098: if ($currstate eq 'select') {
5099: &print_user_selection_page($r,$response,$srch,$results,
1.351 raeburn 5100: \@search,$context,undef,$crstype,
5101: $brcrum);
1.416 raeburn 5102: } elsif (($currstate eq 'modify') || ($env{'form.action'} eq 'accesslogs')) {
5103: my ($ccuname,$ccdomain,$uhome);
1.190 raeburn 5104: if (($srch->{'srchby'} eq 'uname') &&
5105: ($srch->{'srchtype'} eq 'exact')) {
5106: $ccuname = $srch->{'srchterm'};
5107: $ccdomain= $srch->{'srchdomain'};
5108: } else {
5109: my @matchedunames = keys(%{$results});
5110: ($ccuname,$ccdomain) = split(/:/,$matchedunames[0]);
5111: }
5112: $ccuname =&LONCAPA::clean_username($ccuname);
5113: $ccdomain=&LONCAPA::clean_domain($ccdomain);
1.416 raeburn 5114: if ($env{'form.action'} eq 'accesslogs') {
5115: my $uhome;
5116: if (($ccuname ne '') && ($ccdomain ne '')) {
5117: $uhome = &Apache::lonnet::homeserver($ccuname,$ccdomain);
5118: }
5119: if (($uhome eq '') || ($uhome eq 'no_host')) {
5120: $env{'form.phase'} = '';
5121: undef($forcenewuser);
5122: #if ($response) {
5123: # unless ($response =~ m{\Q<br /><br />\E$}) {
5124: # $response .= '<br /><br />';
5125: # }
5126: #}
5127: &print_username_entry_form($r,$context,$response,$srch,
1.439 raeburn 5128: $forcenewuser,$crstype,$brcrum,
5129: $permission);
1.416 raeburn 5130: } else {
5131: &print_useraccesslogs_display($r,$ccuname,$ccdomain,$permission,$brcrum);
5132: }
5133: } else {
5134: if ($env{'form.forcenewuser'}) {
5135: $response = '';
5136: }
5137: &print_user_modification_page($r,$ccuname,$ccdomain,
5138: $srch,$response,$context,
5139: $permission,$crstype,$brcrum);
1.190 raeburn 5140: }
5141: } elsif ($currstate eq 'query') {
1.351 raeburn 5142: &print_user_query_page($r,'createuser',$brcrum);
1.190 raeburn 5143: } else {
1.229 raeburn 5144: $env{'form.phase'} = '';
1.207 raeburn 5145: &print_username_entry_form($r,$context,$response,$srch,
1.439 raeburn 5146: $forcenewuser,$crstype,$brcrum,
5147: $permission);
1.190 raeburn 5148: }
5149: } elsif ($env{'form.phase'} eq 'userpicked') {
5150: my $ccuname = &LONCAPA::clean_username($env{'form.seluname'});
5151: my $ccdomain = &LONCAPA::clean_domain($env{'form.seludom'});
1.416 raeburn 5152: if ($env{'form.action'} eq 'accesslogs') {
5153: &print_useraccesslogs_display($r,$ccuname,$ccdomain,$permission,$brcrum);
5154: } else {
5155: &print_user_modification_page($r,$ccuname,$ccdomain,$srch,'',
5156: $context,$permission,$crstype,
5157: $brcrum);
5158: }
5159: } elsif ($env{'form.action'} eq 'accesslogs') {
5160: my $ccuname = &LONCAPA::clean_username($env{'form.accessuname'});
5161: my $ccdomain = &LONCAPA::clean_domain($env{'form.accessudom'});
5162: &print_useraccesslogs_display($r,$ccuname,$ccdomain,$permission,$brcrum);
1.190 raeburn 5163: }
5164: } elsif ($env{'form.phase'} eq 'update_user_data') {
1.451 raeburn 5165: &update_user_data($r,$context,$crstype,$brcrum,$showcredits,$permission);
1.190 raeburn 5166: } else {
1.351 raeburn 5167: &print_username_entry_form($r,$context,undef,$srch,undef,$crstype,
1.439 raeburn 5168: $brcrum,$permission);
1.190 raeburn 5169: }
5170: } elsif ($env{'form.action'} eq 'custom' && $permission->{'custom'}) {
1.414 raeburn 5171: my $prefix;
1.190 raeburn 5172: if ($env{'form.phase'} eq 'set_custom_roles') {
1.439 raeburn 5173: &set_custom_role($r,$context,$brcrum,$prefix,$permission);
1.190 raeburn 5174: } else {
1.439 raeburn 5175: &custom_role_editor($r,$context,$brcrum,$prefix,$permission);
1.190 raeburn 5176: }
1.362 raeburn 5177: } elsif (($env{'form.action'} eq 'processauthorreq') &&
5178: ($permission->{'cusr'}) &&
5179: (&Apache::lonnet::allowed('cau',$env{'request.role.domain'}))) {
5180: push(@{$brcrum},
5181: {href => '/adm/createuser?action=processauthorreq',
1.385 bisitz 5182: text => 'Authoring Space requests',
1.362 raeburn 5183: help => 'Domain_Role_Approvals'});
5184: $bread_crumbs_component = 'Authoring requests';
5185: if ($env{'form.state'} eq 'done') {
5186: push(@{$brcrum},
5187: {href => '/adm/createuser?action=authorreqqueue',
5188: text => 'Result',
5189: help => 'Domain_Role_Approvals'});
5190: $bread_crumbs_component = 'Authoring request result';
5191: }
5192: $args = { bread_crumbs => $brcrum,
5193: bread_crumbs_component => $bread_crumbs_component};
1.391 raeburn 5194: my $js = &usernamerequest_javascript();
5195: $r->print(&header(&add_script($js),$args));
1.362 raeburn 5196: if (!exists($env{'form.state'})) {
5197: $r->print(&Apache::loncoursequeueadmin::display_queued_requests('requestauthor',
5198: $env{'request.role.domain'}));
5199: } elsif ($env{'form.state'} eq 'done') {
5200: $r->print('<h3>'.&mt('Authoring request processing').'</h3>'."\n");
5201: $r->print(&Apache::loncoursequeueadmin::update_request_queue('requestauthor',
5202: $env{'request.role.domain'}));
5203: }
1.391 raeburn 5204: } elsif (($env{'form.action'} eq 'processusernamereq') &&
5205: ($permission->{'cusr'}) &&
5206: (&Apache::lonnet::allowed('cau',$env{'request.role.domain'}))) {
5207: push(@{$brcrum},
5208: {href => '/adm/createuser?action=processusernamereq',
5209: text => 'LON-CAPA account requests',
5210: help => 'Domain_Username_Approvals'});
5211: $bread_crumbs_component = 'Account requests';
5212: if ($env{'form.state'} eq 'done') {
5213: push(@{$brcrum},
5214: {href => '/adm/createuser?action=usernamereqqueue',
5215: text => 'Result',
5216: help => 'Domain_Username_Approvals'});
5217: $bread_crumbs_component = 'LON-CAPA account request result';
5218: }
5219: $args = { bread_crumbs => $brcrum,
5220: bread_crumbs_component => $bread_crumbs_component};
5221: my $js = &usernamerequest_javascript();
5222: $r->print(&header(&add_script($js),$args));
5223: if (!exists($env{'form.state'})) {
5224: $r->print(&Apache::loncoursequeueadmin::display_queued_requests('requestusername',
5225: $env{'request.role.domain'}));
5226: } elsif ($env{'form.state'} eq 'done') {
5227: $r->print('<h3>'.&mt('LON-CAPA account request processing').'</h3>'."\n");
5228: $r->print(&Apache::loncoursequeueadmin::update_request_queue('requestusername',
5229: $env{'request.role.domain'}));
5230: }
5231: } elsif (($env{'form.action'} eq 'displayuserreq') &&
5232: ($permission->{'cusr'})) {
5233: my $dom = $env{'form.domain'};
5234: my $uname = $env{'form.username'};
5235: my $warning;
5236: if (($dom =~ /^$match_domain$/) && (&Apache::lonnet::domain($dom) ne '')) {
5237: if (($dom eq $env{'request.role.domain'}) && (&Apache::lonnet::allowed('ccc',$dom))) {
5238: if (($uname =~ /^$match_username$/) && ($env{'form.queue'} eq 'approval')) {
5239: my $uhome = &Apache::lonnet::homeserver($uname,$dom);
5240: if ($uhome eq 'no_host') {
5241: my $queue = $env{'form.queue'};
5242: my $reqkey = &escape($uname).'_'.$queue;
5243: my $namespace = 'usernamequeue';
5244: my $domconfig = &Apache::lonnet::get_domainconfiguser($dom);
5245: my %queued =
5246: &Apache::lonnet::get($namespace,[$reqkey],$dom,$domconfig);
5247: unless ($queued{$reqkey}) {
5248: $warning = &mt('No information was found for this LON-CAPA account request.');
5249: }
5250: } else {
5251: $warning = &mt('A LON-CAPA account already exists for the requested username and domain.');
5252: }
5253: } else {
5254: $warning = &mt('LON-CAPA account request status check is for an invalid username.');
5255: }
5256: } else {
5257: $warning = &mt('You do not have rights to view LON-CAPA account requests in the domain specified.');
5258: }
5259: } else {
5260: $warning = &mt('LON-CAPA account request status check is for an invalid domain.');
5261: }
5262: my $args = { only_body => 1 };
5263: $r->print(&header(undef,$args).
5264: '<h3>'.&mt('LON-CAPA Account Request Details').'</h3>');
5265: if ($warning ne '') {
5266: $r->print('<div class="LC_warning">'.$warning.'</div>');
5267: } else {
5268: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
5269: my $domconfiguser = &Apache::lonnet::get_domainconfiguser($dom);
5270: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
5271: if (ref($domconfig{'usercreation'}) eq 'HASH') {
5272: if (ref($domconfig{'usercreation'}{'cancreate'}) eq 'HASH') {
5273: if (ref($domconfig{'usercreation'}{'cancreate'}{'emailusername'}) eq 'HASH') {
5274: my %info =
5275: &Apache::lonnet::get('nohist_requestedusernames',[$uname],$dom,$domconfiguser);
5276: if (ref($info{$uname}) eq 'HASH') {
1.396 raeburn 5277: my $usertype = $info{$uname}{'inststatus'};
5278: unless ($usertype) {
5279: $usertype = 'default';
5280: }
1.442 raeburn 5281: my ($showstatus,$showemail,$pickstart);
5282: my $numextras = 0;
5283: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.443 raeburn 5284: if ((ref($types) eq 'ARRAY') && (@{$types} > 0)) {
5285: if (ref($usertypes) eq 'HASH') {
5286: if ($usertypes->{$usertype}) {
5287: $showstatus = $usertypes->{$usertype};
5288: } else {
5289: $showstatus = $othertitle;
5290: }
5291: if ($showstatus) {
5292: $numextras ++;
5293: }
1.442 raeburn 5294: }
5295: }
5296: if (($info{$uname}{'email'} ne '') && ($info{$uname}{'email'} ne $uname)) {
5297: $showemail = $info{$uname}{'email'};
5298: $numextras ++;
5299: }
1.396 raeburn 5300: if (ref($domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}) eq 'HASH') {
5301: if ((ref($infofields) eq 'ARRAY') && (ref($infotitles) eq 'HASH')) {
1.442 raeburn 5302: $pickstart = 1;
1.396 raeburn 5303: $r->print('<div>'.&Apache::lonhtmlcommon::start_pick_box());
1.442 raeburn 5304: my ($num,$count);
1.396 raeburn 5305: $count = scalar(keys(%{$domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}}));
1.442 raeburn 5306: $count += $numextras;
1.396 raeburn 5307: foreach my $field (@{$infofields}) {
5308: next unless ($domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}{$field});
5309: next unless ($infotitles->{$field});
5310: $r->print(&Apache::lonhtmlcommon::row_title($infotitles->{$field}).
5311: $info{$uname}{$field});
5312: $num ++;
1.442 raeburn 5313: unless ($count == $num) {
1.396 raeburn 5314: $r->print(&Apache::lonhtmlcommon::row_closure());
5315: }
5316: }
1.442 raeburn 5317: }
5318: }
5319: if ($numextras) {
5320: unless ($pickstart) {
5321: $r->print('<div>'.&Apache::lonhtmlcommon::start_pick_box());
5322: $pickstart = 1;
5323: }
5324: if ($showemail) {
5325: my $closure = '';
5326: unless ($showstatus) {
5327: $closure = 1;
1.391 raeburn 5328: }
1.442 raeburn 5329: $r->print(&Apache::lonhtmlcommon::row_title(&mt('E-mail address')).
5330: $showemail.
5331: &Apache::lonhtmlcommon::row_closure($closure));
1.391 raeburn 5332: }
1.442 raeburn 5333: if ($showstatus) {
5334: $r->print(&Apache::lonhtmlcommon::row_title(&mt('Status type[_1](self-reported)','<br />')).
5335: $showstatus.
5336: &Apache::lonhtmlcommon::row_closure(1));
5337: }
5338: }
5339: if ($pickstart) {
5340: $r->print(&Apache::lonhtmlcommon::end_pick_box().'</div>');
5341: } else {
5342: $r->print('<div>'.&mt('No information to display for this account request.').'</div>');
1.391 raeburn 5343: }
1.442 raeburn 5344: } else {
5345: $r->print('<div>'.&mt('No information available for this account request.').'</div>');
1.391 raeburn 5346: }
5347: }
5348: }
5349: }
5350: }
1.442 raeburn 5351: $r->print(&close_popup_form());
1.207 raeburn 5352: } elsif (($env{'form.action'} eq 'listusers') &&
5353: ($permission->{'view'} || $permission->{'cusr'})) {
1.439 raeburn 5354: my $helpitem = 'Course_View_Class_List';
5355: if ($context eq 'author') {
5356: $helpitem = 'Author_View_Coauthor_List';
5357: } elsif ($context eq 'domain') {
5358: $helpitem = 'Domain_View_Users_List';
5359: }
1.202 raeburn 5360: if ($env{'form.phase'} eq 'bulkchange') {
1.351 raeburn 5361: push(@{$brcrum},
5362: {href => '/adm/createuser?action=listusers',
5363: text => "List Users"},
5364: {href => "/adm/createuser",
5365: text => "Result",
1.439 raeburn 5366: help => $helpitem});
1.351 raeburn 5367: $bread_crumbs_component = 'Update Users';
5368: $args = {bread_crumbs => $brcrum,
5369: bread_crumbs_component => $bread_crumbs_component};
5370: $r->print(&header(undef,$args));
1.202 raeburn 5371: my $setting = $env{'form.roletype'};
5372: my $choice = $env{'form.bulkaction'};
5373: if ($permission->{'cusr'}) {
1.336 raeburn 5374: &Apache::lonuserutils::update_user_list($r,$context,$setting,$choice,$crstype);
1.221 raeburn 5375: } else {
5376: $r->print(&mt('You are not authorized to make bulk changes to user roles'));
1.223 raeburn 5377: $r->print('<p><a href="/adm/createuser?action=listusers">'.&mt('Display User Lists').'</a>');
1.202 raeburn 5378: }
5379: } else {
1.351 raeburn 5380: push(@{$brcrum},
5381: {href => '/adm/createuser?action=listusers',
5382: text => "List Users",
1.439 raeburn 5383: help => $helpitem});
1.351 raeburn 5384: $bread_crumbs_component = 'List Users';
5385: $args = {bread_crumbs => $brcrum,
5386: bread_crumbs_component => $bread_crumbs_component};
1.202 raeburn 5387: my ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles);
5388: my $formname = 'studentform';
1.364 raeburn 5389: my $hidecall = "hide_searching();";
1.321 raeburn 5390: if (($context eq 'domain') && (($env{'form.roletype'} eq 'course') ||
5391: ($env{'form.roletype'} eq 'community'))) {
5392: if ($env{'form.roletype'} eq 'course') {
5393: ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles) =
5394: &Apache::lonuserutils::courses_selector($env{'request.role.domain'},
5395: $formname);
5396: } elsif ($env{'form.roletype'} eq 'community') {
5397: $cb_jscript =
5398: &Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
5399: my %elements = (
5400: coursepick => 'radio',
5401: coursetotal => 'text',
5402: courselist => 'text',
5403: );
5404: $jscript = &Apache::lonhtmlcommon::set_form_elements(\%elements);
5405: }
1.364 raeburn 5406: $jscript .= &verify_user_display($context)."\n".
5407: &Apache::loncommon::check_uncheck_jscript();
1.202 raeburn 5408: my $js = &add_script($jscript).$cb_jscript;
5409: my $loadcode =
5410: &Apache::lonuserutils::course_selector_loadcode($formname);
5411: if ($loadcode ne '') {
1.364 raeburn 5412: $args->{add_entries} = {onload => "$loadcode;$hidecall"};
5413: } else {
5414: $args->{add_entries} = {onload => $hidecall};
1.202 raeburn 5415: }
1.351 raeburn 5416: $r->print(&header($js,$args));
1.191 raeburn 5417: } else {
1.364 raeburn 5418: $args->{add_entries} = {onload => $hidecall};
5419: $jscript = &verify_user_display($context).
5420: &Apache::loncommon::check_uncheck_jscript();
5421: $r->print(&header(&add_script($jscript),$args));
1.191 raeburn 5422: }
1.202 raeburn 5423: &Apache::lonuserutils::print_userlist($r,undef,$permission,$context,
1.375 raeburn 5424: $formname,$totcodes,$codetitles,$idlist,$idlist_titles,
5425: $showcredits);
1.191 raeburn 5426: }
1.213 raeburn 5427: } elsif ($env{'form.action'} eq 'drop' && $permission->{'cusr'}) {
1.318 raeburn 5428: my $brtext;
5429: if ($crstype eq 'Community') {
5430: $brtext = 'Drop Members';
5431: } else {
5432: $brtext = 'Drop Students';
5433: }
1.351 raeburn 5434: push(@{$brcrum},
5435: {href => '/adm/createuser?action=drop',
5436: text => $brtext,
5437: help => 'Course_Drop_Student'});
5438: if ($env{'form.state'} eq 'done') {
5439: push(@{$brcrum},
5440: {href=>'/adm/createuser?action=drop',
5441: text=>"Result"});
5442: }
5443: $bread_crumbs_component = $brtext;
5444: $args = {bread_crumbs => $brcrum,
5445: bread_crumbs_component => $bread_crumbs_component};
5446: $r->print(&header(undef,$args));
1.213 raeburn 5447: if (!exists($env{'form.state'})) {
1.318 raeburn 5448: &Apache::lonuserutils::print_drop_menu($r,$context,$permission,$crstype);
1.213 raeburn 5449: } elsif ($env{'form.state'} eq 'done') {
5450: &Apache::lonuserutils::update_user_list($r,$context,undef,
5451: $env{'form.action'});
5452: }
1.202 raeburn 5453: } elsif ($env{'form.action'} eq 'dateselect') {
5454: if ($permission->{'cusr'}) {
1.351 raeburn 5455: $r->print(&header(undef,{'no_nav_bar' => 1}).
1.375 raeburn 5456: &Apache::lonuserutils::date_section_selector($context,$permission,
5457: $crstype,$showcredits));
1.202 raeburn 5458: } else {
1.351 raeburn 5459: $r->print(&header(undef,{'no_nav_bar' => 1}).
5460: '<span class="LC_error">'.&mt('You do not have permission to modify dates or sections for users').'</span>');
1.202 raeburn 5461: }
1.237 raeburn 5462: } elsif ($env{'form.action'} eq 'selfenroll') {
1.469 ! raeburn 5463: my %currsettings;
! 5464: if ($permission->{selfenrolladmin} || $permission->{selfenrollview}) {
! 5465: %currsettings = (
1.398 raeburn 5466: selfenroll_types => $env{'course.'.$cid.'.internal.selfenroll_types'},
5467: selfenroll_registered => $env{'course.'.$cid.'.internal.selfenroll_registered'},
5468: selfenroll_section => $env{'course.'.$cid.'.internal.selfenroll_section'},
5469: selfenroll_notifylist => $env{'course.'.$cid.'.internal.selfenroll_notifylist'},
5470: selfenroll_approval => $env{'course.'.$cid.'.internal.selfenroll_approval'},
5471: selfenroll_limit => $env{'course.'.$cid.'.internal.selfenroll_limit'},
5472: selfenroll_cap => $env{'course.'.$cid.'.internal.selfenroll_cap'},
5473: selfenroll_start_date => $env{'course.'.$cid.'.internal.selfenroll_start_date'},
5474: selfenroll_end_date => $env{'course.'.$cid.'.internal.selfenroll_end_date'},
5475: selfenroll_start_access => $env{'course.'.$cid.'.internal.selfenroll_start_access'},
5476: selfenroll_end_access => $env{'course.'.$cid.'.internal.selfenroll_end_access'},
5477: default_enrollment_start_date => $env{'course.'.$cid.'.default_enrollment_start_date'},
5478: default_enrollment_end_date => $env{'course.'.$cid.'.default_enrollment_end_date'},
1.400 raeburn 5479: uniquecode => $env{'course.'.$cid.'.internal.uniquecode'},
1.398 raeburn 5480: );
1.469 ! raeburn 5481: }
! 5482: if ($permission->{selfenrolladmin}) {
1.398 raeburn 5483: push(@{$brcrum},
5484: {href => '/adm/createuser?action=selfenroll',
5485: text => "Configure Self-enrollment",
5486: help => 'Course_Self_Enrollment'});
5487: if (!exists($env{'form.state'})) {
5488: $args = { bread_crumbs => $brcrum,
5489: bread_crumbs_component => 'Configure Self-enrollment'};
5490: $r->print(&header(undef,$args));
5491: $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n");
5492: &print_selfenroll_menu($r,'course',$cid,$cdom,$cnum,\%currsettings);
5493: } elsif ($env{'form.state'} eq 'done') {
5494: push (@{$brcrum},
5495: {href=>'/adm/createuser?action=selfenroll',
5496: text=>"Result"});
5497: $args = { bread_crumbs => $brcrum,
5498: bread_crumbs_component => 'Self-enrollment result'};
5499: $r->print(&header(undef,$args));
5500: $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n");
1.400 raeburn 5501: &update_selfenroll_config($r,$cid,$cdom,$cnum,$context,$crstype,\%currsettings);
1.398 raeburn 5502: }
1.469 ! raeburn 5503: } elsif ($permission->{selfenrollview}) {
! 5504: push(@{$brcrum},
! 5505: {href => '/adm/createuser?action=selfenroll',
! 5506: text => "View Self-enrollment configuration",
! 5507: help => 'Course_Self_Enrollment'});
! 5508: $args = { bread_crumbs => $brcrum,
! 5509: bread_crumbs_component => 'Self-enrollment Settings'};
! 5510: $r->print(&header(undef,$args));
! 5511: $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n");
! 5512: &print_selfenroll_menu($r,'course',$cid,$cdom,$cnum,\%currsettings,'',1);
1.398 raeburn 5513: } else {
5514: $r->print(&header(undef,{'no_nav_bar' => 1}).
5515: '<span class="LC_error">'.&mt('You do not have permission to configure self-enrollment').'</span>');
1.237 raeburn 5516: }
1.277 raeburn 5517: } elsif ($env{'form.action'} eq 'selfenrollqueue') {
1.418 raeburn 5518: if ($permission->{selfenrolladmin}) {
1.351 raeburn 5519: push(@{$brcrum},
5520: {href => '/adm/createuser?action=selfenrollqueue',
1.418 raeburn 5521: text => 'Enrollment requests',
1.439 raeburn 5522: help => 'Course_Approve_Selfenroll'});
1.418 raeburn 5523: $bread_crumbs_component = 'Enrollment requests';
5524: if ($env{'form.state'} eq 'done') {
5525: push(@{$brcrum},
5526: {href => '/adm/createuser?action=selfenrollqueue',
5527: text => 'Result',
1.439 raeburn 5528: help => 'Course_Approve_Selfenroll'});
1.418 raeburn 5529: $bread_crumbs_component = 'Enrollment result';
5530: }
5531: $args = { bread_crumbs => $brcrum,
5532: bread_crumbs_component => $bread_crumbs_component};
5533: $r->print(&header(undef,$args));
5534: my $coursedesc = $env{'course.'.$cid.'.description'};
5535: if (!exists($env{'form.state'})) {
5536: $r->print('<h3>'.&mt('Pending enrollment requests').'</h3>'."\n");
5537: $r->print(&Apache::loncoursequeueadmin::display_queued_requests($context,
5538: $cdom,$cnum));
5539: } elsif ($env{'form.state'} eq 'done') {
5540: $r->print('<h3>'.&mt('Enrollment request processing').'</h3>'."\n");
5541: $r->print(&Apache::loncoursequeueadmin::update_request_queue($context,
1.430 raeburn 5542: $cdom,$cnum,$coursedesc));
1.418 raeburn 5543: }
5544: } else {
5545: $r->print(&header(undef,{'no_nav_bar' => 1}).
5546: '<span class="LC_error">'.&mt('You do not have permission to manage self-enrollment').'</span>');
1.351 raeburn 5547: }
1.418 raeburn 5548: } elsif ($env{'form.action'} eq 'changelogs') {
5549: if ($permission->{cusr} || $permission->{view}) {
5550: &print_userchangelogs_display($r,$context,$permission,$brcrum);
5551: } else {
5552: $r->print(&header(undef,{'no_nav_bar' => 1}).
5553: '<span class="LC_error">'.&mt('You do not have permission to view change logs').'</span>');
1.277 raeburn 5554: }
1.428 raeburn 5555: } elsif ($env{'form.action'} eq 'helpdesk') {
1.464 raeburn 5556: if (($permission->{'owner'} || $permission->{'co-owner'}) &&
5557: ($permission->{'cusr'} || $permission->{'view'})) {
1.428 raeburn 5558: if ($env{'form.state'} eq 'process') {
5559: if ($permission->{'owner'}) {
5560: &update_helpdeskaccess($r,$permission,$brcrum);
5561: } else {
5562: &print_helpdeskaccess_display($r,$permission,$brcrum);
1.430 raeburn 5563: }
1.428 raeburn 5564: } else {
5565: &print_helpdeskaccess_display($r,$permission,$brcrum);
5566: }
5567: } else {
5568: $r->print(&header(undef,{'no_nav_bar' => 1}).
5569: '<span class="LC_error">'.&mt('You do not have permission to view helpdesk access').'</span>');
5570: }
1.465 raeburn 5571: } elsif ($env{'form.action'} eq 'rolerequests') {
5572: if ($permission->{cusr} || $permission->{view}) {
5573: &print_queued_roles($r,$context,$permission,$brcrum);
5574: }
5575: } elsif ($env{'form.action'} eq 'queuedroles') {
5576: if (($permission->{cusr}) && ($context eq 'domain')) {
5577: if (&show_role_requests($context,$env{'request.role.domain'})) {
5578: if ($env{'form.state'} eq 'done') {
5579: &process_pendingroles($r,$context,$permission,$brcrum);
5580: } else {
5581: &print_pendingroles($r,$context,$permission,$brcrum);
5582: }
5583: } else {
5584: $r->print(&header(undef,{'no_nav_bar' => 1}).
5585: '<span class="LC_info">'.&mt('Domain coordinator approval of requests from other domains for assignment of roles to users from this domain not in use.').'</span>');
5586: }
5587: } else {
5588: $r->print(&header(undef,{'no_nav_bar' => 1}).
5589: '<span class="LC_error">'.&mt('You do not have permission to view queued requests from other domains for assignment of roles to users from this domain.').'</span>');
5590: }
1.190 raeburn 5591: } else {
1.351 raeburn 5592: $bread_crumbs_component = 'User Management';
5593: $args = { bread_crumbs => $brcrum,
5594: bread_crumbs_component => $bread_crumbs_component};
5595: $r->print(&header(undef,$args));
1.318 raeburn 5596: $r->print(&print_main_menu($permission,$context,$crstype));
1.190 raeburn 5597: }
1.351 raeburn 5598: $r->print(&Apache::loncommon::end_page());
1.190 raeburn 5599: return OK;
5600: }
5601:
5602: sub header {
1.351 raeburn 5603: my ($jscript,$args) = @_;
1.190 raeburn 5604: my $start_page;
1.351 raeburn 5605: if (ref($args) eq 'HASH') {
5606: $start_page=&Apache::loncommon::start_page('User Management',$jscript,$args);
1.190 raeburn 5607: } else {
1.351 raeburn 5608: $start_page=&Apache::loncommon::start_page('User Management',$jscript);
1.190 raeburn 5609: }
5610: return $start_page;
5611: }
1.2 www 5612:
1.191 raeburn 5613: sub add_script {
5614: my ($js) = @_;
1.301 bisitz 5615: return '<script type="text/javascript">'."\n"
5616: .'// <![CDATA['."\n"
5617: .$js."\n"
5618: .'// ]]>'."\n"
5619: .'</script>'."\n";
1.191 raeburn 5620: }
5621:
1.391 raeburn 5622: sub usernamerequest_javascript {
5623: my $js = <<ENDJS;
5624:
5625: function openusernamereqdisplay(dom,uname,queue) {
5626: var url = '/adm/createuser?action=displayuserreq';
5627: url += '&domain='+dom+'&username='+uname+'&queue='+queue;
5628: var title = 'Account_Request_Browser';
5629: var options = 'scrollbars=1,resizable=1,menubar=0';
5630: options += ',width=700,height=600';
5631: var stdeditbrowser = open(url,title,options,'1');
5632: stdeditbrowser.focus();
5633: return;
5634: }
5635:
5636: ENDJS
5637: }
5638:
5639: sub close_popup_form {
5640: my $close= &mt('Close Window');
5641: return << "END";
5642: <p><form name="displayreq" action="" method="post">
5643: <input type="button" name="closeme" value="$close" onclick="javascript:self.close();" />
5644: </form></p>
5645: END
5646: }
5647:
1.202 raeburn 5648: sub verify_user_display {
1.364 raeburn 5649: my ($context) = @_;
1.374 raeburn 5650: my %lt = &Apache::lonlocal::texthash (
5651: course => 'course(s): description, section(s), status',
5652: community => 'community(s): description, section(s), status',
5653: author => 'author',
5654: );
1.364 raeburn 5655: my $photos;
5656: if (($context eq 'course') && $env{'request.course.id'}) {
5657: $photos = $env{'course.'.$env{'request.course.id'}.'.internal.showphoto'};
5658: }
1.202 raeburn 5659: my $output = <<"END";
5660:
1.364 raeburn 5661: function hide_searching() {
5662: if (document.getElementById('searching')) {
5663: document.getElementById('searching').style.display = 'none';
5664: }
5665: return;
5666: }
5667:
1.202 raeburn 5668: function display_update() {
5669: document.studentform.action.value = 'listusers';
5670: document.studentform.phase.value = 'display';
5671: document.studentform.submit();
5672: }
5673:
1.364 raeburn 5674: function updateCols(caller) {
5675: var context = '$context';
5676: var photos = '$photos';
5677: if (caller == 'Status') {
1.374 raeburn 5678: if ((context == 'domain') &&
5679: ((document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'course') ||
5680: (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community'))) {
1.364 raeburn 5681: document.getElementById('showcolstatus').checked = false;
5682: document.getElementById('showcolstatus').disabled = 'disabled';
5683: document.getElementById('showcolstart').checked = false;
5684: document.getElementById('showcolend').checked = false;
1.374 raeburn 5685: } else {
5686: if (document.studentform.Status.options[document.studentform.Status.selectedIndex].value == 'Any') {
5687: document.getElementById('showcolstatus').checked = true;
5688: document.getElementById('showcolstatus').disabled = '';
5689: document.getElementById('showcolstart').checked = true;
5690: document.getElementById('showcolend').checked = true;
5691: } else {
5692: document.getElementById('showcolstatus').checked = false;
5693: document.getElementById('showcolstatus').disabled = 'disabled';
5694: document.getElementById('showcolstart').checked = false;
5695: document.getElementById('showcolend').checked = false;
5696: }
1.364 raeburn 5697: }
5698: }
5699: if (caller == 'output') {
5700: if (photos == 1) {
5701: if (document.getElementById('showcolphoto')) {
5702: var photoitem = document.getElementById('showcolphoto');
5703: if (document.studentform.output.options[document.studentform.output.selectedIndex].value == 'html') {
5704: photoitem.checked = true;
5705: photoitem.disabled = '';
5706: } else {
5707: photoitem.checked = false;
5708: photoitem.disabled = 'disabled';
5709: }
5710: }
5711: }
5712: }
5713: if (caller == 'showrole') {
1.371 raeburn 5714: if ((document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'Any') ||
5715: (document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'cr')) {
1.364 raeburn 5716: document.getElementById('showcolrole').checked = true;
5717: document.getElementById('showcolrole').disabled = '';
5718: } else {
5719: document.getElementById('showcolrole').checked = false;
5720: document.getElementById('showcolrole').disabled = 'disabled';
5721: }
1.374 raeburn 5722: if (context == 'domain') {
1.382 raeburn 5723: var quotausageshow = 0;
1.374 raeburn 5724: if ((document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'course') ||
5725: (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community')) {
5726: document.getElementById('showcolstatus').checked = false;
5727: document.getElementById('showcolstatus').disabled = 'disabled';
5728: document.getElementById('showcolstart').checked = false;
5729: document.getElementById('showcolend').checked = false;
5730: } else {
5731: if (document.studentform.Status.options[document.studentform.Status.selectedIndex].value == 'Any') {
5732: document.getElementById('showcolstatus').checked = true;
5733: document.getElementById('showcolstatus').disabled = '';
5734: document.getElementById('showcolstart').checked = true;
5735: document.getElementById('showcolend').checked = true;
5736: }
5737: }
5738: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'domain') {
5739: document.getElementById('showcolextent').disabled = 'disabled';
5740: document.getElementById('showcolextent').checked = 'false';
5741: document.getElementById('showextent').style.display='none';
5742: document.getElementById('showcoltextextent').innerHTML = '';
1.382 raeburn 5743: if ((document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'au') ||
5744: (document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'Any')) {
5745: if (document.getElementById('showcolauthorusage')) {
5746: document.getElementById('showcolauthorusage').disabled = '';
5747: }
5748: if (document.getElementById('showcolauthorquota')) {
5749: document.getElementById('showcolauthorquota').disabled = '';
5750: }
5751: quotausageshow = 1;
5752: }
1.374 raeburn 5753: } else {
5754: document.getElementById('showextent').style.display='block';
5755: document.getElementById('showextent').style.textAlign='left';
5756: document.getElementById('showextent').style.textFace='normal';
5757: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'author') {
5758: document.getElementById('showcolextent').disabled = '';
5759: document.getElementById('showcolextent').checked = 'true';
5760: document.getElementById('showcoltextextent').innerHTML="$lt{'author'}";
5761: } else {
5762: document.getElementById('showcolextent').disabled = '';
5763: document.getElementById('showcolextent').checked = 'true';
5764: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community') {
5765: document.getElementById('showcoltextextent').innerHTML="$lt{'community'}";
5766: } else {
5767: document.getElementById('showcoltextextent').innerHTML="$lt{'course'}";
5768: }
5769: }
5770: }
1.382 raeburn 5771: if (quotausageshow == 0) {
5772: if (document.getElementById('showcolauthorusage')) {
5773: document.getElementById('showcolauthorusage').checked = false;
5774: document.getElementById('showcolauthorusage').disabled = 'disabled';
5775: }
5776: if (document.getElementById('showcolauthorquota')) {
5777: document.getElementById('showcolauthorquota').checked = false;
5778: document.getElementById('showcolauthorquota').disabled = 'disabled';
5779: }
5780: }
1.374 raeburn 5781: }
1.364 raeburn 5782: }
5783: return;
5784: }
5785:
1.202 raeburn 5786: END
5787: return $output;
5788:
5789: }
5790:
1.190 raeburn 5791: ###############################################################
5792: ###############################################################
5793: # Menu Phase One
5794: sub print_main_menu {
1.318 raeburn 5795: my ($permission,$context,$crstype) = @_;
5796: my $linkcontext = $context;
5797: my $stuterm = lc(&Apache::lonnet::plaintext('st',$crstype));
5798: if (($context eq 'course') && ($crstype eq 'Community')) {
5799: $linkcontext = lc($crstype);
5800: $stuterm = 'Members';
5801: }
1.208 raeburn 5802: my %links = (
1.298 droeschl 5803: domain => {
5804: upload => 'Upload a File of Users',
5805: singleuser => 'Add/Modify a User',
5806: listusers => 'Manage Users',
5807: },
5808: author => {
5809: upload => 'Upload a File of Co-authors',
5810: singleuser => 'Add/Modify a Co-author',
5811: listusers => 'Manage Co-authors',
5812: },
5813: course => {
5814: upload => 'Upload a File of Course Users',
5815: singleuser => 'Add/Modify a Course User',
1.354 www 5816: listusers => 'List and Modify Multiple Course Users',
1.298 droeschl 5817: },
1.318 raeburn 5818: community => {
5819: upload => 'Upload a File of Community Users',
5820: singleuser => 'Add/Modify a Community User',
1.354 www 5821: listusers => 'List and Modify Multiple Community Users',
1.318 raeburn 5822: },
5823: );
5824: my %linktitles = (
5825: domain => {
5826: singleuser => 'Add a user to the domain, and/or a course or community in the domain.',
5827: listusers => 'Show and manage users in this domain.',
5828: },
5829: author => {
5830: singleuser => 'Add a user with a co- or assistant author role.',
5831: listusers => 'Show and manage co- or assistant authors.',
5832: },
5833: course => {
5834: singleuser => 'Add a user with a certain role to this course.',
5835: listusers => 'Show and manage users in this course.',
5836: },
5837: community => {
5838: singleuser => 'Add a user with a certain role to this community.',
5839: listusers => 'Show and manage users in this community.',
5840: },
1.298 droeschl 5841: );
1.465 raeburn 5842:
1.418 raeburn 5843: if ($linkcontext eq 'domain') {
5844: unless ($permission->{'cusr'}) {
1.430 raeburn 5845: $links{'domain'}{'singleuser'} = 'View a User';
1.418 raeburn 5846: $linktitles{'domain'}{'singleuser'} = 'View information about a user in the domain';
5847: }
5848: } elsif ($linkcontext eq 'course') {
5849: unless ($permission->{'cusr'}) {
5850: $links{'course'}{'singleuser'} = 'View a Course User';
5851: $linktitles{'course'}{'singleuser'} = 'View information about a user in this course';
5852: $links{'course'}{'listusers'} = 'List Course Users';
5853: $linktitles{'course'}{'listusers'} = 'Show information about users in this course';
5854: }
5855: } elsif ($linkcontext eq 'community') {
5856: unless ($permission->{'cusr'}) {
5857: $links{'community'}{'singleuser'} = 'View a Community User';
5858: $linktitles{'community'}{'singleuser'} = 'View information about a user in this community';
5859: $links{'community'}{'listusers'} = 'List Community Users';
5860: $linktitles{'community'}{'listusers'} = 'Show information about users in this community';
5861: }
5862: }
1.298 droeschl 5863: my @menu = ( {categorytitle => 'Single Users',
5864: items =>
5865: [
5866: {
1.318 raeburn 5867: linktext => $links{$linkcontext}{'singleuser'},
1.298 droeschl 5868: icon => 'edit-redo.png',
5869: #help => 'Course_Change_Privileges',
5870: url => '/adm/createuser?action=singleuser',
1.418 raeburn 5871: permission => ($permission->{'view'} || $permission->{'cusr'}),
1.318 raeburn 5872: linktitle => $linktitles{$linkcontext}{'singleuser'},
1.298 droeschl 5873: },
5874: ]},
5875:
5876: {categorytitle => 'Multiple Users',
5877: items =>
5878: [
5879: {
1.318 raeburn 5880: linktext => $links{$linkcontext}{'upload'},
1.340 wenzelju 5881: icon => 'uplusr.png',
1.298 droeschl 5882: #help => 'Course_Create_Class_List',
5883: url => '/adm/createuser?action=upload',
5884: permission => $permission->{'cusr'},
5885: linktitle => 'Upload a CSV or a text file containing users.',
5886: },
5887: {
1.318 raeburn 5888: linktext => $links{$linkcontext}{'listusers'},
1.340 wenzelju 5889: icon => 'mngcu.png',
1.298 droeschl 5890: #help => 'Course_View_Class_List',
5891: url => '/adm/createuser?action=listusers',
5892: permission => ($permission->{'view'} || $permission->{'cusr'}),
1.318 raeburn 5893: linktitle => $linktitles{$linkcontext}{'listusers'},
1.298 droeschl 5894: },
5895:
5896: ]},
5897:
5898: {categorytitle => 'Administration',
5899: items => [ ]},
5900: );
1.415 raeburn 5901:
1.265 mielkec 5902: if ($context eq 'domain'){
1.416 raeburn 5903: push(@{ $menu[0]->{items} }, # Single Users
5904: {
5905: linktext => 'User Access Log',
1.417 raeburn 5906: icon => 'document-properties.png',
1.425 raeburn 5907: #help => 'Domain_User_Access_Logs',
1.416 raeburn 5908: url => '/adm/createuser?action=accesslogs',
5909: permission => $permission->{'activity'},
5910: linktitle => 'View user access log.',
5911: }
5912: );
1.298 droeschl 5913:
5914: push(@{ $menu[2]->{items} }, #Category: Administration
5915: {
5916: linktext => 'Custom Roles',
5917: icon => 'emblem-photos.png',
5918: #help => 'Course_Editing_Custom_Roles',
5919: url => '/adm/createuser?action=custom',
5920: permission => $permission->{'custom'},
5921: linktitle => 'Configure a custom role.',
5922: },
1.362 raeburn 5923: {
5924: linktext => 'Authoring Space Requests',
5925: icon => 'selfenrl-queue.png',
5926: #help => 'Domain_Role_Approvals',
5927: url => '/adm/createuser?action=processauthorreq',
5928: permission => $permission->{'cusr'},
5929: linktitle => 'Approve or reject author role requests',
5930: },
1.363 raeburn 5931: {
1.391 raeburn 5932: linktext => 'LON-CAPA Account Requests',
5933: icon => 'list-add.png',
5934: #help => 'Domain_Username_Approvals',
5935: url => '/adm/createuser?action=processusernamereq',
5936: permission => $permission->{'cusr'},
5937: linktitle => 'Approve or reject LON-CAPA account requests',
5938: },
5939: {
1.363 raeburn 5940: linktext => 'Change Log',
5941: icon => 'document-properties.png',
5942: #help => 'Course_User_Logs',
5943: url => '/adm/createuser?action=changelogs',
1.418 raeburn 5944: permission => ($permission->{'cusr'} || $permission->{'view'}),
1.363 raeburn 5945: linktitle => 'View change log.',
5946: },
1.298 droeschl 5947: );
5948:
1.265 mielkec 5949: }elsif ($context eq 'course'){
1.298 droeschl 5950: my ($cnum,$cdom) = &Apache::lonuserutils::get_course_identity();
1.318 raeburn 5951:
5952: my %linktext = (
5953: 'Course' => {
5954: single => 'Add/Modify a Student',
5955: drop => 'Drop Students',
5956: groups => 'Course Groups',
5957: },
5958: 'Community' => {
5959: single => 'Add/Modify a Member',
5960: drop => 'Drop Members',
5961: groups => 'Community Groups',
5962: },
5963: );
1.411 raeburn 5964: $linktext{'Placement'} = $linktext{'Course'};
1.318 raeburn 5965:
5966: my %linktitle = (
5967: 'Course' => {
5968: single => 'Add a user with the role of student to this course',
5969: drop => 'Remove a student from this course.',
5970: groups => 'Manage course groups',
5971: },
5972: 'Community' => {
5973: single => 'Add a user with the role of member to this community',
5974: drop => 'Remove a member from this community.',
5975: groups => 'Manage community groups',
5976: },
5977: );
5978:
1.411 raeburn 5979: $linktitle{'Placement'} = $linktitle{'Course'};
5980:
1.298 droeschl 5981: push(@{ $menu[0]->{items} }, #Category: Single Users
5982: {
1.318 raeburn 5983: linktext => $linktext{$crstype}{'single'},
1.298 droeschl 5984: #help => 'Course_Add_Student',
5985: icon => 'list-add.png',
5986: url => '/adm/createuser?action=singlestudent',
5987: permission => $permission->{'cusr'},
1.318 raeburn 5988: linktitle => $linktitle{$crstype}{'single'},
1.298 droeschl 5989: },
5990: );
5991:
5992: push(@{ $menu[1]->{items} }, #Category: Multiple Users
5993: {
1.318 raeburn 5994: linktext => $linktext{$crstype}{'drop'},
1.298 droeschl 5995: icon => 'edit-undo.png',
5996: #help => 'Course_Drop_Student',
5997: url => '/adm/createuser?action=drop',
5998: permission => $permission->{'cusr'},
1.318 raeburn 5999: linktitle => $linktitle{$crstype}{'drop'},
1.298 droeschl 6000: },
6001: );
6002: push(@{ $menu[2]->{items} }, #Category: Administration
1.428 raeburn 6003: {
6004: linktext => 'Helpdesk Access',
6005: icon => 'helpdesk-access.png',
6006: #help => 'Course_Helpdesk_Access',
6007: url => '/adm/createuser?action=helpdesk',
1.464 raeburn 6008: permission => (($permission->{'owner'} || $permission->{'co-owner'}) &&
6009: ($permission->{'view'} || $permission->{'cusr'})),
1.428 raeburn 6010: linktitle => 'Helpdesk access options',
6011: },
6012: {
1.298 droeschl 6013: linktext => 'Custom Roles',
6014: icon => 'emblem-photos.png',
6015: #help => 'Course_Editing_Custom_Roles',
6016: url => '/adm/createuser?action=custom',
6017: permission => $permission->{'custom'},
6018: linktitle => 'Configure a custom role.',
6019: },
6020: {
1.318 raeburn 6021: linktext => $linktext{$crstype}{'groups'},
1.333 wenzelju 6022: icon => 'grps.png',
1.298 droeschl 6023: #help => 'Course_Manage_Group',
6024: url => '/adm/coursegroups?refpage=cusr',
6025: permission => $permission->{'grp_manage'},
1.318 raeburn 6026: linktitle => $linktitle{$crstype}{'groups'},
1.298 droeschl 6027: },
6028: {
1.328 wenzelju 6029: linktext => 'Change Log',
1.298 droeschl 6030: icon => 'document-properties.png',
6031: #help => 'Course_User_Logs',
6032: url => '/adm/createuser?action=changelogs',
1.418 raeburn 6033: permission => ($permission->{'view'} || $permission->{'cusr'}),
1.298 droeschl 6034: linktitle => 'View change log.',
6035: },
6036: );
1.277 raeburn 6037: if ($env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_approval'}) {
1.298 droeschl 6038: push(@{ $menu[2]->{items} },
1.398 raeburn 6039: {
1.298 droeschl 6040: linktext => 'Enrollment Requests',
6041: icon => 'selfenrl-queue.png',
6042: #help => 'Course_Approve_Selfenroll',
6043: url => '/adm/createuser?action=selfenrollqueue',
1.469 ! raeburn 6044: permission => $permission->{'selfenrolladmin'} || $permission->{'selfenrollview'},
1.298 droeschl 6045: linktitle =>'Approve or reject enrollment requests.',
6046: },
6047: );
1.277 raeburn 6048: }
1.298 droeschl 6049:
1.265 mielkec 6050: if (!exists($permission->{'cusr_section'})){
1.320 raeburn 6051: if ($crstype ne 'Community') {
6052: push(@{ $menu[2]->{items} },
6053: {
6054: linktext => 'Automated Enrollment',
6055: icon => 'roles.png',
6056: #help => 'Course_Automated_Enrollment',
6057: permission => (&Apache::lonnet::auto_run($cnum,$cdom)
1.418 raeburn 6058: && (($permission->{'cusr'}) ||
6059: ($permission->{'view'}))),
1.320 raeburn 6060: url => '/adm/populate',
6061: linktitle => 'Automated enrollment manager.',
6062: }
6063: );
6064: }
6065: push(@{ $menu[2]->{items} },
1.298 droeschl 6066: {
6067: linktext => 'User Self-Enrollment',
1.342 wenzelju 6068: icon => 'self_enroll.png',
1.298 droeschl 6069: #help => 'Course_Self_Enrollment',
6070: url => '/adm/createuser?action=selfenroll',
1.469 ! raeburn 6071: permission => $permission->{'selfenrolladmin'} || $permission->{'selfenrollview'},
1.317 bisitz 6072: linktitle => 'Configure user self-enrollment.',
1.298 droeschl 6073: },
6074: );
6075: }
1.363 raeburn 6076: } elsif ($context eq 'author') {
1.370 raeburn 6077: push(@{ $menu[2]->{items} }, #Category: Administration
1.363 raeburn 6078: {
6079: linktext => 'Change Log',
6080: icon => 'document-properties.png',
6081: #help => 'Course_User_Logs',
6082: url => '/adm/createuser?action=changelogs',
6083: permission => $permission->{'cusr'},
6084: linktitle => 'View change log.',
6085: },
1.370 raeburn 6086: );
1.363 raeburn 6087: }
1.465 raeburn 6088: push(@{ $menu[2]->{items} },
6089: {
6090: linktext => 'Role Requests (other domains)',
6091: icon => 'edit-find.png',
6092: #help => 'Role_Requests',
6093: url => '/adm/createuser?action=rolerequests',
6094: permission => $permission->{'cusr'},
6095: linktitle => 'Role requests for users in other domains',
6096: },
6097: );
6098: if (&show_role_requests($context,$env{'request.role.domain'})) {
6099: push(@{ $menu[2]->{items} },
6100: {
6101: linktext => 'Queued Role Assignments (this domain)',
6102: icon => 'edit-find.png',
6103: #help => 'Role_Approvals',
6104: url => '/adm/createuser?action=queuedroles',
6105: permission => $permission->{'cusr'},
6106: linktitle => "Role requests for this domain's users",
6107: },
6108: );
6109: }
1.363 raeburn 6110: return Apache::lonhtmlcommon::generate_menu(@menu);
1.250 raeburn 6111: # { text => 'View Log-in History',
6112: # help => 'Course_User_Logins',
6113: # action => 'logins',
6114: # permission => $permission->{'cusr'},
6115: # });
1.190 raeburn 6116: }
6117:
1.189 albertel 6118: sub restore_prev_selections {
6119: my %saveable_parameters = ('srchby' => 'scalar',
6120: 'srchin' => 'scalar',
6121: 'srchtype' => 'scalar',
6122: );
6123: &Apache::loncommon::store_settings('user','user_picker',
6124: \%saveable_parameters);
6125: &Apache::loncommon::restore_settings('user','user_picker',
6126: \%saveable_parameters);
6127: }
6128:
1.237 raeburn 6129: sub print_selfenroll_menu {
1.418 raeburn 6130: my ($r,$context,$cid,$cdom,$cnum,$currsettings,$additional,$readonly) = @_;
1.322 raeburn 6131: my $crstype = &Apache::loncommon::course_type();
1.398 raeburn 6132: my $formname = 'selfenroll';
1.237 raeburn 6133: my $nolink = 1;
1.398 raeburn 6134: my ($row,$lt) = &Apache::lonuserutils::get_selfenroll_titles();
1.237 raeburn 6135: my $groupslist = &Apache::lonuserutils::get_groupslist();
6136: my $setsec_js =
6137: &Apache::lonuserutils::setsections_javascript($formname,$groupslist);
1.249 raeburn 6138: my %alerts = &Apache::lonlocal::texthash(
6139: acto => 'Activation of self-enrollment was selected for the following domain(s)',
6140: butn => 'but no user types have been checked.',
6141: wilf => "Please uncheck 'activate' or check at least one type.",
6142: );
1.418 raeburn 6143: my $disabled;
6144: if ($readonly) {
6145: $disabled = ' disabled="disabled"';
6146: }
1.405 damieng 6147: &js_escape(\%alerts);
1.249 raeburn 6148: my $selfenroll_js = <<"ENDSCRIPT";
6149: function update_types(caller,num) {
6150: var delidx = getIndexByName('selfenroll_delete');
6151: var actidx = getIndexByName('selfenroll_activate');
6152: if (caller == 'selfenroll_all') {
6153: var selall;
6154: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
6155: if (document.$formname.selfenroll_all[i].checked) {
6156: selall = document.$formname.selfenroll_all[i].value;
6157: }
6158: }
6159: if (selall == 1) {
6160: if (delidx != -1) {
6161: if (document.$formname.selfenroll_delete.length) {
6162: for (var j=0; j<document.$formname.selfenroll_delete.length; j++) {
6163: document.$formname.selfenroll_delete[j].checked = true;
6164: }
6165: } else {
6166: document.$formname.elements[delidx].checked = true;
6167: }
6168: }
6169: if (actidx != -1) {
6170: if (document.$formname.selfenroll_activate.length) {
6171: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
6172: document.$formname.selfenroll_activate[j].checked = false;
6173: }
6174: } else {
6175: document.$formname.elements[actidx].checked = false;
6176: }
6177: }
6178: document.$formname.selfenroll_newdom.selectedIndex = 0;
6179: }
6180: }
6181: if (caller == 'selfenroll_activate') {
6182: if (document.$formname.selfenroll_activate.length) {
6183: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
6184: if (document.$formname.selfenroll_activate[j].value == num) {
6185: if (document.$formname.selfenroll_activate[j].checked) {
6186: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
6187: if (document.$formname.selfenroll_all[i].value == '1') {
6188: document.$formname.selfenroll_all[i].checked = false;
6189: }
6190: if (document.$formname.selfenroll_all[i].value == '0') {
6191: document.$formname.selfenroll_all[i].checked = true;
6192: }
6193: }
6194: }
6195: }
6196: }
6197: } else {
6198: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
6199: if (document.$formname.selfenroll_all[i].value == '1') {
6200: document.$formname.selfenroll_all[i].checked = false;
6201: }
6202: if (document.$formname.selfenroll_all[i].value == '0') {
6203: document.$formname.selfenroll_all[i].checked = true;
6204: }
6205: }
6206: }
6207: }
6208: if (caller == 'selfenroll_delete') {
6209: if (document.$formname.selfenroll_delete.length) {
6210: for (var j=0; j<document.$formname.selfenroll_delete.length; j++) {
6211: if (document.$formname.selfenroll_delete[j].value == num) {
6212: if (document.$formname.selfenroll_delete[j].checked) {
6213: var delindex = getIndexByName('selfenroll_types_'+num);
6214: if (delindex != -1) {
6215: if (document.$formname.elements[delindex].length) {
6216: for (var k=0; k<document.$formname.elements[delindex].length; k++) {
6217: document.$formname.elements[delindex][k].checked = false;
6218: }
6219: } else {
6220: document.$formname.elements[delindex].checked = false;
6221: }
6222: }
6223: }
6224: }
6225: }
6226: } else {
6227: if (document.$formname.selfenroll_delete.checked) {
6228: var delindex = getIndexByName('selfenroll_types_'+num);
6229: if (delindex != -1) {
6230: if (document.$formname.elements[delindex].length) {
6231: for (var k=0; k<document.$formname.elements[delindex].length; k++) {
6232: document.$formname.elements[delindex][k].checked = false;
6233: }
6234: } else {
6235: document.$formname.elements[delindex].checked = false;
6236: }
6237: }
6238: }
6239: }
6240: }
6241: return;
6242: }
6243:
6244: function validate_types(form) {
6245: var needaction = new Array();
6246: var countfail = 0;
6247: var actidx = getIndexByName('selfenroll_activate');
6248: if (actidx != -1) {
6249: if (document.$formname.selfenroll_activate.length) {
6250: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
6251: var num = document.$formname.selfenroll_activate[j].value;
6252: if (document.$formname.selfenroll_activate[j].checked) {
6253: countfail = check_types(num,countfail,needaction)
6254: }
6255: }
6256: } else {
6257: if (document.$formname.selfenroll_activate.checked) {
1.398 raeburn 6258: var num = document.$formname.selfenroll_activate.value;
1.249 raeburn 6259: countfail = check_types(num,countfail,needaction)
6260: }
6261: }
6262: }
6263: if (countfail > 0) {
6264: var msg = "$alerts{'acto'}\\n";
6265: var loopend = needaction.length -1;
6266: if (loopend > 0) {
6267: for (var m=0; m<loopend; m++) {
6268: msg += needaction[m]+", ";
6269: }
6270: }
6271: msg += needaction[loopend]+"\\n$alerts{'butn'}\\n$alerts{'wilf'}";
6272: alert(msg);
6273: return;
6274: }
6275: setSections(form);
6276: }
6277:
6278: function check_types(num,countfail,needaction) {
1.441 raeburn 6279: var boxname = 'selfenroll_types_'+num;
6280: var typeidx = getIndexByName(boxname);
1.249 raeburn 6281: var count = 0;
6282: if (typeidx != -1) {
1.441 raeburn 6283: if (document.$formname.elements[boxname].length) {
6284: for (var k=0; k<document.$formname.elements[boxname].length; k++) {
6285: if (document.$formname.elements[boxname][k].checked) {
1.249 raeburn 6286: count ++;
6287: }
6288: }
6289: } else {
6290: if (document.$formname.elements[typeidx].checked) {
6291: count ++;
6292: }
6293: }
6294: if (count == 0) {
6295: var domidx = getIndexByName('selfenroll_dom_'+num);
6296: if (domidx != -1) {
6297: var domname = document.$formname.elements[domidx].value;
6298: needaction[countfail] = domname;
6299: countfail ++;
6300: }
6301: }
6302: }
6303: return countfail;
6304: }
6305:
1.398 raeburn 6306: function toggleNotify() {
6307: var selfenrollApproval = 0;
6308: if (document.$formname.selfenroll_approval.length) {
6309: for (var i=0; i<document.$formname.selfenroll_approval.length; i++) {
6310: if (document.$formname.selfenroll_approval[i].checked) {
6311: selfenrollApproval = document.$formname.selfenroll_approval[i].value;
6312: break;
6313: }
6314: }
6315: }
6316: if (document.getElementById('notified')) {
6317: if (selfenrollApproval == 0) {
6318: document.getElementById('notified').style.display='none';
6319: } else {
6320: document.getElementById('notified').style.display='block';
6321: }
6322: }
6323: return;
6324: }
6325:
1.249 raeburn 6326: function getIndexByName(item) {
6327: for (var i=0;i<document.$formname.elements.length;i++) {
6328: if (document.$formname.elements[i].name == item) {
6329: return i;
6330: }
6331: }
6332: return -1;
6333: }
6334: ENDSCRIPT
1.256 raeburn 6335:
1.237 raeburn 6336: my $output = '<script type="text/javascript">'."\n".
1.301 bisitz 6337: '// <![CDATA['."\n".
1.249 raeburn 6338: $setsec_js."\n".$selfenroll_js."\n".
1.301 bisitz 6339: '// ]]>'."\n".
1.237 raeburn 6340: '</script>'."\n".
1.256 raeburn 6341: '<h3>'.$lt->{'selfenroll'}.'</h3>'."\n";
1.469 ! raeburn 6342: my $visactions = &cat_visibility($cdom);
1.400 raeburn 6343: my ($cathash,%cattype);
6344: my %domconfig = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom);
6345: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
6346: $cathash = $domconfig{'coursecategories'}{'cats'};
6347: $cattype{'auth'} = $domconfig{'coursecategories'}{'auth'};
6348: $cattype{'unauth'} = $domconfig{'coursecategories'}{'unauth'};
1.406 raeburn 6349: if ($cattype{'auth'} eq '') {
6350: $cattype{'auth'} = 'std';
6351: }
6352: if ($cattype{'unauth'} eq '') {
6353: $cattype{'unauth'} = 'std';
6354: }
1.400 raeburn 6355: } else {
6356: $cathash = {};
6357: $cattype{'auth'} = 'std';
6358: $cattype{'unauth'} = 'std';
6359: }
6360: if (($cattype{'auth'} eq 'none') && ($cattype{'unauth'} eq 'none')) {
6361: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
6362: '<br />'.
6363: '<br />'.$visactions->{'take'}.'<ul>'.
6364: '<li>'.$visactions->{'dc_chgconf'}.'</li>'.
6365: '</ul>');
6366: } elsif (($cattype{'auth'} !~ /^(std|domonly)$/) && ($cattype{'unauth'} !~ /^(std|domonly)$/)) {
6367: if ($currsettings->{'uniquecode'}) {
6368: $r->print('<span class="LC_info">'.$visactions->{'vis'}.'</span>');
6369: } else {
6370: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
6371: '<br />'.
6372: '<br />'.$visactions->{'take'}.'<ul>'.
6373: '<li>'.$visactions->{'dc_setcode'}.'</li>'.
6374: '</ul><br />');
6375: }
6376: } else {
6377: my ($visible,$cansetvis,$vismsgs) = &visible_in_stdcat($cdom,$cnum,\%domconfig);
6378: if (ref($visactions) eq 'HASH') {
6379: if ($visible) {
6380: $output .= '<p class="LC_info">'.$visactions->{'vis'}.'</p>';
6381: } else {
6382: $output .= '<p class="LC_warning">'.$visactions->{'miss'}.'</p>'
6383: .$visactions->{'yous'}.
6384: '<p>'.$visactions->{'gen'}.'<br />'.$visactions->{'coca'};
6385: if (ref($vismsgs) eq 'ARRAY') {
6386: $output .= '<br />'.$visactions->{'make'}.'<ul>';
6387: foreach my $item (@{$vismsgs}) {
6388: $output .= '<li>'.$visactions->{$item}.'</li>';
6389: }
6390: $output .= '</ul>';
1.256 raeburn 6391: }
1.400 raeburn 6392: $output .= '</p>';
1.256 raeburn 6393: }
6394: }
6395: }
1.398 raeburn 6396: my $actionhref = '/adm/createuser';
6397: if ($context eq 'domain') {
6398: $actionhref = '/adm/modifycourse';
6399: }
1.400 raeburn 6400:
6401: my %noedit;
6402: unless ($context eq 'domain') {
6403: %noedit = &get_noedit_fields($cdom,$cnum,$crstype,$row);
6404: }
1.398 raeburn 6405: $output .= '<form name="'.$formname.'" method="post" action="'.$actionhref.'">'."\n".
1.256 raeburn 6406: &Apache::lonhtmlcommon::start_pick_box();
1.237 raeburn 6407: if (ref($row) eq 'ARRAY') {
6408: foreach my $item (@{$row}) {
6409: my $title = $item;
6410: if (ref($lt) eq 'HASH') {
6411: $title = $lt->{$item};
6412: }
1.297 bisitz 6413: $output .= &Apache::lonhtmlcommon::row_title($title);
1.237 raeburn 6414: if ($item eq 'types') {
1.398 raeburn 6415: my $curr_types;
6416: if (ref($currsettings) eq 'HASH') {
6417: $curr_types = $currsettings->{'selfenroll_types'};
6418: }
1.400 raeburn 6419: if ($noedit{$item}) {
6420: if ($curr_types eq '*') {
6421: $output .= &mt('Any user in any domain');
6422: } else {
6423: my @entries = split(/;/,$curr_types);
6424: if (@entries > 0) {
6425: $output .= '<ul>';
6426: foreach my $entry (@entries) {
6427: my ($currdom,$typestr) = split(/:/,$entry);
6428: next if ($typestr eq '');
6429: my $domdesc = &Apache::lonnet::domain($currdom);
6430: my @currinsttypes = split(',',$typestr);
6431: my ($othertitle,$usertypes,$types) =
6432: &Apache::loncommon::sorted_inst_types($currdom);
6433: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
6434: $usertypes->{'any'} = &mt('any user');
6435: if (keys(%{$usertypes}) > 0) {
6436: $usertypes->{'other'} = &mt('other users');
6437: }
6438: my @longinsttypes = map { $usertypes->{$_}; } @currinsttypes;
6439: $output .= '<li>'.$domdesc.':'.join(', ',@longinsttypes).'</li>';
6440: }
6441: }
6442: $output .= '</ul>';
6443: } else {
6444: $output .= &mt('None');
6445: }
6446: }
6447: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6448: next;
6449: }
1.241 raeburn 6450: my $showdomdesc = 1;
6451: my $includeempty = 1;
6452: my $num = 0;
6453: $output .= &Apache::loncommon::start_data_table().
6454: &Apache::loncommon::start_data_table_row()
6455: .'<td colspan="2"><span class="LC_nobreak"><label>'
6456: .&mt('Any user in any domain:')
6457: .' <input type="radio" name="selfenroll_all" value="1" ';
6458: if ($curr_types eq '*') {
6459: $output .= ' checked="checked" ';
6460: }
1.249 raeburn 6461: $output .= 'onchange="javascript:update_types('.
1.418 raeburn 6462: "'selfenroll_all'".');"'.$disabled.' />'.&mt('Yes').'</label>'.
1.249 raeburn 6463: ' <input type="radio" name="selfenroll_all" value="0" ';
1.241 raeburn 6464: if ($curr_types ne '*') {
6465: $output .= ' checked="checked" ';
6466: }
1.249 raeburn 6467: $output .= ' onchange="javascript:update_types('.
1.418 raeburn 6468: "'selfenroll_all'".');"'.$disabled.' />'.&mt('No').'</label></td>'.
1.249 raeburn 6469: &Apache::loncommon::end_data_table_row().
6470: &Apache::loncommon::end_data_table().
6471: &mt('Or').'<br />'.
6472: &Apache::loncommon::start_data_table();
1.241 raeburn 6473: my %currdoms;
1.249 raeburn 6474: if ($curr_types eq '') {
1.241 raeburn 6475: $output .= &new_selfenroll_dom_row($cdom,'0');
6476: } elsif ($curr_types ne '*') {
6477: my @entries = split(/;/,$curr_types);
6478: if (@entries > 0) {
6479: foreach my $entry (@entries) {
6480: my ($currdom,$typestr) = split(/:/,$entry);
6481: $currdoms{$currdom} = 1;
6482: my $domdesc = &Apache::lonnet::domain($currdom);
1.249 raeburn 6483: my @currinsttypes = split(',',$typestr);
1.241 raeburn 6484: $output .= &Apache::loncommon::start_data_table_row()
6485: .'<td valign="top"><span class="LC_nobreak">'.&mt('Domain:').'<b>'
6486: .' '.$domdesc.' ('.$currdom.')'
6487: .'</b><input type="hidden" name="selfenroll_dom_'.$num
6488: .'" value="'.$currdom.'" /></span><br />'
6489: .'<span class="LC_nobreak"><label><input type="checkbox" '
1.418 raeburn 6490: .'name="selfenroll_delete" value="'.$num.'" onchange="javascript:update_types('."'selfenroll_delete','$num'".');"'.$disabled.' />'
1.241 raeburn 6491: .&mt('Delete').'</label></span></td>';
1.249 raeburn 6492: $output .= '<td valign="top"> '.&mt('User types:').'<br />'
1.418 raeburn 6493: .&selfenroll_inst_types($num,$currdom,\@currinsttypes,$readonly).'</td>'
1.241 raeburn 6494: .&Apache::loncommon::end_data_table_row();
6495: $num ++;
6496: }
6497: }
6498: }
1.249 raeburn 6499: my $add_domtitle = &mt('Users in additional domain:');
1.241 raeburn 6500: if ($curr_types eq '*') {
1.249 raeburn 6501: $add_domtitle = &mt('Users in specific domain:');
1.241 raeburn 6502: } elsif ($curr_types eq '') {
1.249 raeburn 6503: $add_domtitle = &mt('Users in other domain:');
1.241 raeburn 6504: }
1.446 raeburn 6505: my ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('enroll',$cdom);
1.241 raeburn 6506: $output .= &Apache::loncommon::start_data_table_row()
6507: .'<td colspan="2"><span class="LC_nobreak">'.$add_domtitle.'</span><br />'
6508: .&Apache::loncommon::select_dom_form('','selfenroll_newdom',
1.446 raeburn 6509: $includeempty,$showdomdesc,'',$trusted,$untrusted,$readonly)
1.241 raeburn 6510: .'<input type="hidden" name="selfenroll_types_total" value="'.$num.'" />'
6511: .'</td>'.&Apache::loncommon::end_data_table_row()
6512: .&Apache::loncommon::end_data_table();
1.237 raeburn 6513: } elsif ($item eq 'registered') {
6514: my ($regon,$regoff);
1.398 raeburn 6515: my $registered;
6516: if (ref($currsettings) eq 'HASH') {
6517: $registered = $currsettings->{'selfenroll_registered'};
6518: }
1.400 raeburn 6519: if ($noedit{$item}) {
6520: if ($registered) {
6521: $output .= &mt('Must be registered in course');
6522: } else {
6523: $output .= &mt('No requirement');
6524: }
6525: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6526: next;
6527: }
1.398 raeburn 6528: if ($registered) {
1.237 raeburn 6529: $regon = ' checked="checked" ';
1.419 raeburn 6530: $regoff = '';
1.237 raeburn 6531: } else {
1.419 raeburn 6532: $regon = '';
1.237 raeburn 6533: $regoff = ' checked="checked" ';
6534: }
6535: $output .= '<label>'.
1.419 raeburn 6536: '<input type="radio" name="selfenroll_registered" value="1"'.$regon.$disabled.' />'.
1.244 bisitz 6537: &mt('Yes').'</label> <label>'.
1.419 raeburn 6538: '<input type="radio" name="selfenroll_registered" value="0"'.$regoff.$disabled.' />'.
1.244 bisitz 6539: &mt('No').'</label>';
1.237 raeburn 6540: } elsif ($item eq 'enroll_dates') {
1.398 raeburn 6541: my ($starttime,$endtime);
6542: if (ref($currsettings) eq 'HASH') {
6543: $starttime = $currsettings->{'selfenroll_start_date'};
6544: $endtime = $currsettings->{'selfenroll_end_date'};
6545: if ($starttime eq '') {
6546: $starttime = $currsettings->{'default_enrollment_start_date'};
6547: }
6548: if ($endtime eq '') {
6549: $endtime = $currsettings->{'default_enrollment_end_date'};
6550: }
1.237 raeburn 6551: }
1.400 raeburn 6552: if ($noedit{$item}) {
6553: $output .= &mt('From: [_1], to: [_2]',&Apache::lonlocal::locallocaltime($starttime),
6554: &Apache::lonlocal::locallocaltime($endtime));
6555: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6556: next;
6557: }
1.237 raeburn 6558: my $startform =
6559: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_start_date',$starttime,
1.418 raeburn 6560: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
1.237 raeburn 6561: my $endform =
6562: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_end_date',$endtime,
1.418 raeburn 6563: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
1.237 raeburn 6564: $output .= &selfenroll_date_forms($startform,$endform);
6565: } elsif ($item eq 'access_dates') {
1.398 raeburn 6566: my ($starttime,$endtime);
6567: if (ref($currsettings) eq 'HASH') {
6568: $starttime = $currsettings->{'selfenroll_start_access'};
6569: $endtime = $currsettings->{'selfenroll_end_access'};
6570: if ($starttime eq '') {
6571: $starttime = $currsettings->{'default_enrollment_start_date'};
6572: }
6573: if ($endtime eq '') {
6574: $endtime = $currsettings->{'default_enrollment_end_date'};
6575: }
1.237 raeburn 6576: }
1.400 raeburn 6577: if ($noedit{$item}) {
6578: $output .= &mt('From: [_1], to: [_2]',&Apache::lonlocal::locallocaltime($starttime),
6579: &Apache::lonlocal::locallocaltime($endtime));
6580: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6581: next;
6582: }
1.237 raeburn 6583: my $startform =
6584: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_start_access',$starttime,
1.418 raeburn 6585: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
1.237 raeburn 6586: my $endform =
6587: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_end_access',$endtime,
1.418 raeburn 6588: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
1.237 raeburn 6589: $output .= &selfenroll_date_forms($startform,$endform);
6590: } elsif ($item eq 'section') {
1.398 raeburn 6591: my $currsec;
6592: if (ref($currsettings) eq 'HASH') {
6593: $currsec = $currsettings->{'selfenroll_section'};
6594: }
1.237 raeburn 6595: my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum);
6596: my $newsecval;
6597: if ($currsec ne 'none' && $currsec ne '') {
6598: if (!defined($sections_count{$currsec})) {
6599: $newsecval = $currsec;
6600: }
6601: }
1.400 raeburn 6602: if ($noedit{$item}) {
6603: if ($currsec ne '') {
6604: $output .= $currsec;
6605: } else {
6606: $output .= &mt('No specific section');
6607: }
6608: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6609: next;
6610: }
1.237 raeburn 6611: my $sections_select =
1.418 raeburn 6612: &Apache::lonuserutils::course_sections(\%sections_count,'st',$currsec,$disabled);
1.237 raeburn 6613: $output .= '<table class="LC_createuser">'."\n".
6614: '<tr class="LC_section_row">'."\n".
6615: '<td align="center">'.&mt('Existing sections')."\n".
6616: '<br />'.$sections_select.'</td><td align="center">'.
6617: &mt('New section').'<br />'."\n".
1.418 raeburn 6618: '<input type="text" name="newsec" size="15" value="'.$newsecval.'"'.$disabled.' />'."\n".
1.237 raeburn 6619: '<input type="hidden" name="sections" value="" />'."\n".
6620: '</td></tr></table>'."\n";
1.276 raeburn 6621: } elsif ($item eq 'approval') {
1.398 raeburn 6622: my ($currnotified,$currapproval,%appchecked);
6623: my %selfdescs = &Apache::lonuserutils::selfenroll_default_descs();
1.430 raeburn 6624: if (ref($currsettings) eq 'HASH') {
1.398 raeburn 6625: $currnotified = $currsettings->{'selfenroll_notifylist'};
6626: $currapproval = $currsettings->{'selfenroll_approval'};
6627: }
6628: if ($currapproval !~ /^[012]$/) {
6629: $currapproval = 0;
6630: }
1.400 raeburn 6631: if ($noedit{$item}) {
6632: $output .= $selfdescs{'approval'}{$currapproval}.
6633: '<br />'.&mt('(Set by Domain Coordinator)');
6634: next;
6635: }
1.398 raeburn 6636: $appchecked{$currapproval} = ' checked="checked"';
6637: for my $i (0..2) {
6638: $output .= '<label>'.
6639: '<input type="radio" name="selfenroll_approval" value="'.$i.'"'.
1.418 raeburn 6640: $appchecked{$i}.' onclick="toggleNotify();"'.$disabled.' />'.
6641: $selfdescs{'approval'}{$i}.'</label>'.(' 'x2);
1.276 raeburn 6642: }
6643: my %advhash = &Apache::lonnet::get_course_adv_roles($cid,1);
6644: my (@ccs,%notified);
1.322 raeburn 6645: my $ccrole = 'cc';
6646: if ($crstype eq 'Community') {
6647: $ccrole = 'co';
6648: }
6649: if ($advhash{$ccrole}) {
6650: @ccs = split(/,/,$advhash{$ccrole});
1.276 raeburn 6651: }
6652: if ($currnotified) {
6653: foreach my $current (split(/,/,$currnotified)) {
6654: $notified{$current} = 1;
6655: if (!grep(/^\Q$current\E$/,@ccs)) {
6656: push(@ccs,$current);
6657: }
6658: }
6659: }
6660: if (@ccs) {
1.398 raeburn 6661: my $style;
6662: unless ($currapproval) {
6663: $style = ' style="display: none;"';
6664: }
6665: $output .= '<br /><div id="notified"'.$style.'>'.
6666: &mt('Personnel to be notified when an enrollment request needs approval, or has been approved:').' '.
6667: &Apache::loncommon::start_data_table().
1.276 raeburn 6668: &Apache::loncommon::start_data_table_row();
6669: my $count = 0;
6670: my $numcols = 4;
6671: foreach my $cc (sort(@ccs)) {
6672: my $notifyon;
6673: my ($ccuname,$ccudom) = split(/:/,$cc);
6674: if ($notified{$cc}) {
6675: $notifyon = ' checked="checked" ';
6676: }
6677: if ($count && !$count%$numcols) {
6678: $output .= &Apache::loncommon::end_data_table_row().
6679: &Apache::loncommon::start_data_table_row()
6680: }
6681: $output .= '<td><span class="LC_nobreak"><label>'.
1.418 raeburn 6682: '<input type="checkbox" name="selfenroll_notify"'.$notifyon.' value="'.$cc.'"'.$disabled.' />'.
1.276 raeburn 6683: &Apache::loncommon::plainname($ccuname,$ccudom).
6684: '</label></span></td>';
1.343 raeburn 6685: $count ++;
1.276 raeburn 6686: }
6687: my $rem = $count%$numcols;
6688: if ($rem) {
6689: my $emptycols = $numcols - $rem;
6690: for (my $i=0; $i<$emptycols; $i++) {
6691: $output .= '<td> </td>';
6692: }
6693: }
6694: $output .= &Apache::loncommon::end_data_table_row().
1.398 raeburn 6695: &Apache::loncommon::end_data_table().
6696: '</div>';
1.276 raeburn 6697: }
6698: } elsif ($item eq 'limit') {
1.398 raeburn 6699: my ($crslimit,$selflimit,$nolimit,$currlim,$currcap);
6700: if (ref($currsettings) eq 'HASH') {
6701: $currlim = $currsettings->{'selfenroll_limit'};
6702: $currcap = $currsettings->{'selfenroll_cap'};
6703: }
1.400 raeburn 6704: if ($noedit{$item}) {
6705: if (($currlim eq 'allstudents') || ($currlim eq 'selfenrolled')) {
6706: if ($currlim eq 'allstudents') {
6707: $output .= &mt('Limit by total students');
6708: } elsif ($currlim eq 'selfenrolled') {
6709: $output .= &mt('Limit by total self-enrolled students');
6710: }
6711: $output .= ' '.&mt('Maximum: [_1]',$currcap).
6712: '<br />'.&mt('(Set by Domain Coordinator)');
6713: } else {
6714: $output .= &mt('No limit').'<br />'.&mt('(Set by Domain Coordinator)');
6715: }
6716: next;
6717: }
1.276 raeburn 6718: if ($currlim eq 'allstudents') {
6719: $crslimit = ' checked="checked" ';
6720: $selflimit = ' ';
6721: $nolimit = ' ';
6722: } elsif ($currlim eq 'selfenrolled') {
6723: $crslimit = ' ';
6724: $selflimit = ' checked="checked" ';
6725: $nolimit = ' ';
6726: } else {
6727: $crslimit = ' ';
6728: $selflimit = ' ';
1.398 raeburn 6729: $nolimit = ' checked="checked" ';
1.276 raeburn 6730: }
6731: $output .= '<table><tr><td><label>'.
1.418 raeburn 6732: '<input type="radio" name="selfenroll_limit" value="none"'.$nolimit.$disabled.'/>'.
1.276 raeburn 6733: &mt('No limit').'</label></td><td><label>'.
1.418 raeburn 6734: '<input type="radio" name="selfenroll_limit" value="allstudents"'.$crslimit.$disabled.'/>'.
1.276 raeburn 6735: &mt('Limit by total students').'</label></td><td><label>'.
1.418 raeburn 6736: '<input type="radio" name="selfenroll_limit" value="selfenrolled"'.$selflimit.$disabled.'/>'.
1.276 raeburn 6737: &mt('Limit by total self-enrolled students').
6738: '</td></tr><tr>'.
6739: '<td> </td><td colspan="2"><span class="LC_nobreak">'.
6740: (' 'x3).&mt('Maximum number allowed: ').
1.418 raeburn 6741: '<input type="text" name="selfenroll_cap" size = "5" value="'.$currcap.'"'.$disabled.' /></td></tr></table>';
1.237 raeburn 6742: }
6743: $output .= &Apache::lonhtmlcommon::row_closure(1);
6744: }
6745: }
1.418 raeburn 6746: $output .= &Apache::lonhtmlcommon::end_pick_box().'<br />';
6747: unless ($readonly) {
6748: $output .= '<input type="button" name="selfenrollconf" value="'
6749: .&mt('Save').'" onclick="validate_types(this.form);" />';
6750: }
6751: $output .= '<input type="hidden" name="action" value="selfenroll" />'
6752: .'<input type="hidden" name="state" value="done" />'."\n"
6753: .$additional.'</form>';
1.237 raeburn 6754: $r->print($output);
6755: return;
6756: }
6757:
1.400 raeburn 6758: sub get_noedit_fields {
6759: my ($cdom,$cnum,$crstype,$row) = @_;
6760: my %noedit;
6761: if (ref($row) eq 'ARRAY') {
6762: my %settings = &Apache::lonnet::get('environment',['internal.coursecode','internal.textbook',
6763: 'internal.selfenrollmgrdc',
6764: 'internal.selfenrollmgrcc'],$cdom,$cnum);
6765: my $type = &Apache::lonuserutils::get_extended_type($cdom,$cnum,$crstype,\%settings);
6766: my (%specific_managebydc,%specific_managebycc,%default_managebydc);
6767: map { $specific_managebydc{$_} = 1; } (split(/,/,$settings{'internal.selfenrollmgrdc'}));
6768: map { $specific_managebycc{$_} = 1; } (split(/,/,$settings{'internal.selfenrollmgrcc'}));
6769: my %domdefaults = &Apache::lonnet::get_domain_defaults($cdom);
6770: map { $default_managebydc{$_} = 1; } (split(/,/,$domdefaults{$type.'selfenrolladmdc'}));
6771:
6772: foreach my $item (@{$row}) {
6773: next if ($specific_managebycc{$item});
6774: if (($specific_managebydc{$item}) || ($default_managebydc{$item})) {
6775: $noedit{$item} = 1;
6776: }
6777: }
6778: }
6779: return %noedit;
6780: }
6781:
6782: sub visible_in_stdcat {
6783: my ($cdom,$cnum,$domconf) = @_;
6784: my ($cathash,%settable,@vismsgs,$cansetvis,$visible);
6785: unless (ref($domconf) eq 'HASH') {
6786: return ($visible,$cansetvis,\@vismsgs);
6787: }
6788: if (ref($domconf->{'coursecategories'}) eq 'HASH') {
6789: if ($domconf->{'coursecategories'}{'togglecats'} eq 'crs') {
1.256 raeburn 6790: $settable{'togglecats'} = 1;
6791: }
1.400 raeburn 6792: if ($domconf->{'coursecategories'}{'categorize'} eq 'crs') {
1.256 raeburn 6793: $settable{'categorize'} = 1;
6794: }
1.400 raeburn 6795: $cathash = $domconf->{'coursecategories'}{'cats'};
1.256 raeburn 6796: }
1.260 raeburn 6797: if ($settable{'togglecats'} && $settable{'categorize'}) {
1.256 raeburn 6798: $cansetvis = &mt('You are able to both assign a course category and choose to exclude this course from the catalog.');
6799: } elsif ($settable{'togglecats'}) {
6800: $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 6801: } elsif ($settable{'categorize'}) {
1.256 raeburn 6802: $cansetvis = &mt('You may assign a course category, but only a Domain Coordinator may choose to exclude this course from the catalog.');
6803: } else {
6804: $cansetvis = &mt('Only a Domain Coordinator may assign a course category or choose to exclude this course from the catalog.');
6805: }
6806:
6807: my %currsettings =
6808: &Apache::lonnet::get('environment',['hidefromcat','categories','internal.coursecode'],
6809: $cdom,$cnum);
1.400 raeburn 6810: $visible = 0;
1.256 raeburn 6811: if ($currsettings{'internal.coursecode'} ne '') {
1.400 raeburn 6812: if (ref($domconf->{'coursecategories'}) eq 'HASH') {
6813: $cathash = $domconf->{'coursecategories'}{'cats'};
1.256 raeburn 6814: if (ref($cathash) eq 'HASH') {
6815: if ($cathash->{'instcode::0'} eq '') {
6816: push(@vismsgs,'dc_addinst');
6817: } else {
6818: $visible = 1;
6819: }
6820: } else {
6821: $visible = 1;
6822: }
6823: } else {
6824: $visible = 1;
6825: }
6826: } else {
6827: if (ref($cathash) eq 'HASH') {
6828: if ($cathash->{'instcode::0'} ne '') {
6829: push(@vismsgs,'dc_instcode');
6830: }
6831: } else {
6832: push(@vismsgs,'dc_instcode');
6833: }
6834: }
6835: if ($currsettings{'categories'} ne '') {
6836: my $cathash;
1.400 raeburn 6837: if (ref($domconf->{'coursecategories'}) eq 'HASH') {
6838: $cathash = $domconf->{'coursecategories'}{'cats'};
1.256 raeburn 6839: if (ref($cathash) eq 'HASH') {
6840: if (keys(%{$cathash}) == 0) {
6841: push(@vismsgs,'dc_catalog');
6842: } elsif ((keys(%{$cathash}) == 1) && ($cathash->{'instcode::0'} ne '')) {
6843: push(@vismsgs,'dc_categories');
6844: } else {
6845: my @currcategories = split('&',$currsettings{'categories'});
6846: my $matched = 0;
6847: foreach my $cat (@currcategories) {
6848: if ($cathash->{$cat} ne '') {
6849: $visible = 1;
6850: $matched = 1;
6851: last;
6852: }
6853: }
6854: if (!$matched) {
1.260 raeburn 6855: if ($settable{'categorize'}) {
1.256 raeburn 6856: push(@vismsgs,'chgcat');
6857: } else {
6858: push(@vismsgs,'dc_chgcat');
6859: }
6860: }
6861: }
6862: }
6863: }
6864: } else {
6865: if (ref($cathash) eq 'HASH') {
6866: if ((keys(%{$cathash}) > 1) ||
6867: (keys(%{$cathash}) == 1) && ($cathash->{'instcode::0'} eq '')) {
1.260 raeburn 6868: if ($settable{'categorize'}) {
1.256 raeburn 6869: push(@vismsgs,'addcat');
6870: } else {
6871: push(@vismsgs,'dc_addcat');
6872: }
6873: }
6874: }
6875: }
6876: if ($currsettings{'hidefromcat'} eq 'yes') {
6877: $visible = 0;
6878: if ($settable{'togglecats'}) {
6879: unshift(@vismsgs,'unhide');
6880: } else {
6881: unshift(@vismsgs,'dc_unhide')
6882: }
6883: }
1.400 raeburn 6884: return ($visible,$cansetvis,\@vismsgs);
6885: }
6886:
6887: sub cat_visibility {
1.469 ! raeburn 6888: my ($cdom) = @_;
1.400 raeburn 6889: my %visactions = &Apache::lonlocal::texthash(
6890: vis => 'This course/community currently appears in the Course/Community Catalog for this domain.',
6891: 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.',
6892: miss => 'This course/community does not currently appear in the Course/Community Catalog for this domain.',
6893: none => 'Display of a course catalog is disabled for this domain.',
6894: yous => 'You should remedy this if you plan to allow self-enrollment, otherwise students will have difficulty finding this course.',
6895: 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.',
6896: make => 'Make any changes to self-enrollment settings below, click "Save", then take action to include the course in the Catalog:',
6897: take => 'Take the following action to ensure the course appears in the Catalog:',
6898: dc_chgconf => 'Ask a domain coordinator to change the Catalog type for this domain.',
6899: dc_setcode => 'Ask a domain coordinator to assign a six character code to the course',
6900: dc_unhide => 'Ask a domain coordinator to change the "Exclude from course catalog" setting.',
1.469 ! raeburn 6901: dc_addinst => 'Ask a domain coordinator to enable catalog display of "Official courses (with institutional codes)".',
1.400 raeburn 6902: dc_instcode => 'Ask a domain coordinator to assign an institutional code (if this is an official course).',
6903: dc_catalog => 'Ask a domain coordinator to enable or create at least one course category in the domain.',
6904: dc_categories => 'Ask a domain coordinator to create a hierarchy of categories and sub categories for courses in the domain.',
6905: 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',
6906: dc_addcat => 'Ask a domain coordinator to assign a category to the course.',
6907: );
1.469 ! raeburn 6908: if ($env{'request.role'} eq "dc./$cdom/") {
! 6909: $visactions{'dc_chgconf'} = &mt('Use: "Main menu" [_1] "Set domain configuration" [_1] "Cataloging of courses/communities" to change the Catalog type for this domain.','»');
! 6910: $visactions{'dc_setcode'} = &mt('Use: "Main menu" [_1] "Set domain configuration" [_1] "Cataloging of courses/communities" to assign a six character code to the course.','»');
! 6911: $visactions{'dc_unhide'} = &mt('Use: "Main menu" [_1] "Set domain configuration" [_1] "Cataloging of courses/communities" to change the "Exclude from course catalog" setting.','»');
! 6912: $visactions{'dc_addinst'} = &mt('Use: "Main menu" [_1] "Set domain configuration" [_1] "Cataloging of courses/communities" to enable catalog display of "Official courses (with institutional codes)".','»');
! 6913: $visactions{'dc_instcode'} = &mt('Use: "Main menu" [_1] "View or modify a course or community" [_1] "View/Modify course owner, institutional code ... " to assign an institutional code (if this is an official course).','»');
! 6914: $visactions{'dc_catalog'} = &mt('Use: "Main menu" [_1] "Set domain configuration" [_1] "Cataloging of courses/communities" to enable or create at least one course category in the domain.','»');
! 6915: $visactions{'dc_categories'} = &mt('Use: "Main menu" [_1] "Set domain configuration" [_1] "Cataloging of courses/communities" to create a hierarchy of categories and sub categories for courses in the domain.','»');
! 6916: $visactions{'dc_chgcat'} = &mt('Use: "Main menu" [_1] "View or modify a course or community" [_1] "View/Modify catalog settings for course" to change the category assigned to the course, as the one currently assigned is no longer used in the domain.','»');
! 6917: $visactions{'dc_addcat'} = &mt('Use: "Main menu" [_1] "View or modify a course or community" [_1] "View/Modify catalog settings for course" to assign a category to the course.','»');
! 6918: }
1.400 raeburn 6919: $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>"');
6920: $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>"');
6921: $visactions{'addcat'} = &mt('Use [_1]Categorize course[_2] to assign a category to the course.','"<a href="/adm/courseprefs?phase=display&actions=courseinfo">','</a>"');
6922: return \%visactions;
1.256 raeburn 6923: }
6924:
1.241 raeburn 6925: sub new_selfenroll_dom_row {
6926: my ($newdom,$num) = @_;
6927: my $domdesc = &Apache::lonnet::domain($newdom);
6928: my $output;
6929: if ($domdesc ne '') {
6930: $output .= &Apache::loncommon::start_data_table_row()
6931: .'<td valign="top"><span class="LC_nobreak">'.&mt('Domain:').' <b>'.$domdesc
6932: .' ('.$newdom.')</b><input type="hidden" name="selfenroll_dom_'.$num
1.249 raeburn 6933: .'" value="'.$newdom.'" /></span><br />'
6934: .'<span class="LC_nobreak"><label><input type="checkbox" '
6935: .'name="selfenroll_activate" value="'.$num.'" '
6936: .'onchange="javascript:update_types('
6937: ."'selfenroll_activate','$num'".');" />'
6938: .&mt('Activate').'</label></span></td>';
1.241 raeburn 6939: my @currinsttypes;
6940: $output .= '<td>'.&mt('User types:').'<br />'
6941: .&selfenroll_inst_types($num,$newdom,\@currinsttypes).'</td>'
6942: .&Apache::loncommon::end_data_table_row();
6943: }
6944: return $output;
6945: }
6946:
6947: sub selfenroll_inst_types {
1.418 raeburn 6948: my ($num,$currdom,$currinsttypes,$readonly) = @_;
1.241 raeburn 6949: my $output;
6950: my $numinrow = 4;
6951: my $count = 0;
6952: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($currdom);
1.247 raeburn 6953: my $othervalue = 'any';
1.418 raeburn 6954: my $disabled;
6955: if ($readonly) {
6956: $disabled = ' disabled="disabled"';
6957: }
1.241 raeburn 6958: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
1.251 raeburn 6959: if (keys(%{$usertypes}) > 0) {
1.247 raeburn 6960: $othervalue = 'other';
6961: }
1.241 raeburn 6962: $output .= '<table><tr>';
6963: foreach my $type (@{$types}) {
6964: if (($count > 0) && ($count%$numinrow == 0)) {
6965: $output .= '</tr><tr>';
6966: }
6967: if (defined($usertypes->{$type})) {
1.257 raeburn 6968: my $esc_type = &escape($type);
1.241 raeburn 6969: $output .= '<td><span class="LC_nobreak"><label><input type = "checkbox" value="'.
1.257 raeburn 6970: $esc_type.'" ';
1.241 raeburn 6971: if (ref($currinsttypes) eq 'ARRAY') {
6972: if (@{$currinsttypes} > 0) {
1.249 raeburn 6973: if (grep(/^any$/,@{$currinsttypes})) {
6974: $output .= 'checked="checked"';
1.257 raeburn 6975: } elsif (grep(/^\Q$esc_type\E$/,@{$currinsttypes})) {
1.241 raeburn 6976: $output .= 'checked="checked"';
6977: }
1.249 raeburn 6978: } else {
6979: $output .= 'checked="checked"';
1.241 raeburn 6980: }
6981: }
1.418 raeburn 6982: $output .= ' name="selfenroll_types_'.$num.'"'.$disabled.' />'.$usertypes->{$type}.'</label></span></td>';
1.241 raeburn 6983: }
6984: $count ++;
6985: }
6986: if (($count > 0) && ($count%$numinrow == 0)) {
6987: $output .= '</tr><tr>';
6988: }
1.249 raeburn 6989: $output .= '<td><span class="LC_nobreak"><label><input type = "checkbox" value="'.$othervalue.'"';
1.241 raeburn 6990: if (ref($currinsttypes) eq 'ARRAY') {
6991: if (@{$currinsttypes} > 0) {
1.249 raeburn 6992: if (grep(/^any$/,@{$currinsttypes})) {
6993: $output .= ' checked="checked"';
6994: } elsif ($othervalue eq 'other') {
6995: if (grep(/^\Q$othervalue\E$/,@{$currinsttypes})) {
6996: $output .= ' checked="checked"';
6997: }
1.241 raeburn 6998: }
1.249 raeburn 6999: } else {
7000: $output .= ' checked="checked"';
1.241 raeburn 7001: }
1.249 raeburn 7002: } else {
7003: $output .= ' checked="checked"';
1.241 raeburn 7004: }
1.418 raeburn 7005: $output .= ' name="selfenroll_types_'.$num.'"'.$disabled.' />'.$othertitle.'</label></span></td></tr></table>';
1.241 raeburn 7006: }
7007: return $output;
7008: }
7009:
1.237 raeburn 7010: sub selfenroll_date_forms {
7011: my ($startform,$endform) = @_;
7012: my $output .= &Apache::lonhtmlcommon::start_pick_box()."\n".
1.244 bisitz 7013: &Apache::lonhtmlcommon::row_title(&mt('Start date'),
1.237 raeburn 7014: 'LC_oddrow_value')."\n".
7015: $startform."\n".
7016: &Apache::lonhtmlcommon::row_closure(1).
1.244 bisitz 7017: &Apache::lonhtmlcommon::row_title(&mt('End date'),
1.237 raeburn 7018: 'LC_oddrow_value')."\n".
7019: $endform."\n".
7020: &Apache::lonhtmlcommon::row_closure(1).
7021: &Apache::lonhtmlcommon::end_pick_box();
7022: return $output;
7023: }
7024:
1.239 raeburn 7025: sub print_userchangelogs_display {
1.415 raeburn 7026: my ($r,$context,$permission,$brcrum) = @_;
1.363 raeburn 7027: my $formname = 'rolelog';
1.418 raeburn 7028: my ($username,$domain,$crstype,$viewablesec,%roleslog);
1.363 raeburn 7029: if ($context eq 'domain') {
7030: $domain = $env{'request.role.domain'};
7031: %roleslog=&Apache::lonnet::dump_dom('nohist_rolelog',$domain);
7032: } else {
7033: if ($context eq 'course') {
7034: $domain = $env{'course.'.$env{'request.course.id'}.'.domain'};
7035: $username = $env{'course.'.$env{'request.course.id'}.'.num'};
7036: $crstype = &Apache::loncommon::course_type();
1.418 raeburn 7037: $viewablesec = &Apache::lonuserutils::viewable_section($permission);
1.363 raeburn 7038: my %saveable_parameters = ('show' => 'scalar',);
7039: &Apache::loncommon::store_course_settings('roles_log',
7040: \%saveable_parameters);
7041: &Apache::loncommon::restore_course_settings('roles_log',
7042: \%saveable_parameters);
7043: } elsif ($context eq 'author') {
7044: $domain = $env{'user.domain'};
7045: if ($env{'request.role'} =~ m{^au\./\Q$domain\E/$}) {
7046: $username = $env{'user.name'};
7047: } else {
7048: undef($domain);
7049: }
7050: }
7051: if ($domain ne '' && $username ne '') {
7052: %roleslog=&Apache::lonnet::dump('nohist_rolelog',$domain,$username);
7053: }
7054: }
1.239 raeburn 7055: if ((keys(%roleslog))[0]=~/^error\:/) { undef(%roleslog); }
7056:
1.415 raeburn 7057: my $helpitem;
7058: if ($context eq 'course') {
7059: $helpitem = 'Course_User_Logs';
1.439 raeburn 7060: } elsif ($context eq 'domain') {
7061: $helpitem = 'Domain_Role_Logs';
7062: } elsif ($context eq 'author') {
7063: $helpitem = 'Author_User_Logs';
1.415 raeburn 7064: }
7065: push (@{$brcrum},
7066: {href => '/adm/createuser?action=changelogs',
7067: text => 'User Management Logs',
7068: help => $helpitem});
7069: my $bread_crumbs_component = 'User Changes';
7070: my $args = { bread_crumbs => $brcrum,
7071: bread_crumbs_component => $bread_crumbs_component};
7072:
7073: # Create navigation javascript
7074: my $jsnav = &userlogdisplay_js($formname);
7075:
7076: my $jscript = (<<ENDSCRIPT);
7077: <script type="text/javascript">
7078: // <![CDATA[
7079: $jsnav
7080: // ]]>
7081: </script>
7082: ENDSCRIPT
7083:
7084: # print page header
7085: $r->print(&header($jscript,$args));
7086:
1.239 raeburn 7087: # set defaults
7088: my $now = time();
7089: my $defstart = $now - (7*24*3600); #7 days ago
7090: my %defaults = (
7091: page => '1',
7092: show => '10',
7093: role => 'any',
7094: chgcontext => 'any',
7095: rolelog_start_date => $defstart,
7096: rolelog_end_date => $now,
1.468 raeburn 7097: approvals => 'any',
1.239 raeburn 7098: );
7099: my $more_records = 0;
7100:
7101: # set current
7102: my %curr;
1.468 raeburn 7103: foreach my $item ('show','page','role','chgcontext','approvals') {
1.239 raeburn 7104: $curr{$item} = $env{'form.'.$item};
7105: }
7106: my ($startdate,$enddate) =
7107: &Apache::lonuserutils::get_dates_from_form('rolelog_start_date','rolelog_end_date');
7108: $curr{'rolelog_start_date'} = $startdate;
7109: $curr{'rolelog_end_date'} = $enddate;
7110: foreach my $key (keys(%defaults)) {
7111: if ($curr{$key} eq '') {
7112: $curr{$key} = $defaults{$key};
7113: }
7114: }
1.248 raeburn 7115: my (%whodunit,%changed,$version);
7116: ($version) = ($r->dir_config('lonVersion') =~ /^([\d\.]+)\-/);
1.239 raeburn 7117: my ($minshown,$maxshown);
1.255 raeburn 7118: $minshown = 1;
1.239 raeburn 7119: my $count = 0;
1.415 raeburn 7120: if ($curr{'show'} =~ /\D/) {
7121: $curr{'page'} = 1;
7122: } else {
1.239 raeburn 7123: $maxshown = $curr{'page'} * $curr{'show'};
7124: if ($curr{'page'} > 1) {
7125: $minshown = 1 + ($curr{'page'} - 1) * $curr{'show'};
7126: }
7127: }
1.301 bisitz 7128:
1.327 raeburn 7129: # Form Header
7130: $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">'.
1.363 raeburn 7131: &role_display_filter($context,$formname,$domain,$username,\%curr,
7132: $version,$crstype));
1.327 raeburn 7133:
7134: my $showntableheader = 0;
7135:
7136: # Table Header
7137: my $tableheader =
7138: &Apache::loncommon::start_data_table_header_row()
7139: .'<th> </th>'
7140: .'<th>'.&mt('When').'</th>'
7141: .'<th>'.&mt('Who made the change').'</th>'
7142: .'<th>'.&mt('Changed User').'</th>'
1.363 raeburn 7143: .'<th>'.&mt('Role').'</th>';
7144:
7145: if ($context eq 'course') {
7146: $tableheader .= '<th>'.&mt('Section').'</th>';
7147: }
7148: $tableheader .=
7149: '<th>'.&mt('Context').'</th>'
1.327 raeburn 7150: .'<th>'.&mt('Start').'</th>'
7151: .'<th>'.&mt('End').'</th>'
7152: .&Apache::loncommon::end_data_table_header_row();
7153:
7154: # Display user change log data
1.239 raeburn 7155: foreach my $id (sort { $roleslog{$b}{'exe_time'}<=>$roleslog{$a}{'exe_time'} } (keys(%roleslog))) {
7156: next if (($roleslog{$id}{'exe_time'} < $curr{'rolelog_start_date'}) ||
7157: ($roleslog{$id}{'exe_time'} > $curr{'rolelog_end_date'}));
1.415 raeburn 7158: if ($curr{'show'} !~ /\D/) {
1.239 raeburn 7159: if ($count >= $curr{'page'} * $curr{'show'}) {
7160: $more_records = 1;
7161: last;
7162: }
7163: }
7164: if ($curr{'role'} ne 'any') {
7165: next if ($roleslog{$id}{'logentry'}{'role'} ne $curr{'role'});
7166: }
7167: if ($curr{'chgcontext'} ne 'any') {
7168: if ($curr{'chgcontext'} eq 'selfenroll') {
7169: next if (!$roleslog{$id}{'logentry'}{'selfenroll'});
7170: } else {
7171: next if ($roleslog{$id}{'logentry'}{'context'} ne $curr{'chgcontext'});
7172: }
7173: }
1.418 raeburn 7174: if (($context eq 'course') && ($viewablesec ne '')) {
1.430 raeburn 7175: next if ($roleslog{$id}{'logentry'}{'section'} ne $viewablesec);
1.418 raeburn 7176: }
1.468 raeburn 7177: if ($curr{'approvals'} eq 'none') {
7178: next if ($roleslog{$id}{'logentry'}{'approval'});
7179: } elsif ($curr{'approvals'} ne 'any') {
7180: next if ($roleslog{$id}{'logentry'}{'approval'} ne $curr{'approvals'});
7181: }
1.239 raeburn 7182: $count ++;
7183: next if ($count < $minshown);
1.327 raeburn 7184: unless ($showntableheader) {
1.415 raeburn 7185: $r->print(&Apache::loncommon::start_data_table()
1.327 raeburn 7186: .$tableheader);
7187: $r->rflush();
7188: $showntableheader = 1;
7189: }
1.239 raeburn 7190: if ($whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}} eq '') {
7191: $whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}} =
7192: &Apache::loncommon::plainname($roleslog{$id}{'exe_uname'},$roleslog{$id}{'exe_udom'});
7193: }
7194: if ($changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}} eq '') {
7195: $changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}} =
7196: &Apache::loncommon::plainname($roleslog{$id}{'uname'},$roleslog{$id}{'udom'});
7197: }
7198: my $sec = $roleslog{$id}{'logentry'}{'section'};
7199: if ($sec eq '') {
7200: $sec = &mt('None');
7201: }
7202: my ($rolestart,$roleend);
7203: if ($roleslog{$id}{'delflag'}) {
7204: $rolestart = &mt('deleted');
7205: $roleend = &mt('deleted');
7206: } else {
7207: $rolestart = $roleslog{$id}{'logentry'}{'start'};
7208: $roleend = $roleslog{$id}{'logentry'}{'end'};
7209: if ($rolestart eq '' || $rolestart == 0) {
7210: $rolestart = &mt('No start date');
7211: } else {
7212: $rolestart = &Apache::lonlocal::locallocaltime($rolestart);
7213: }
7214: if ($roleend eq '' || $roleend == 0) {
7215: $roleend = &mt('No end date');
7216: } else {
7217: $roleend = &Apache::lonlocal::locallocaltime($roleend);
7218: }
7219: }
7220: my $chgcontext = $roleslog{$id}{'logentry'}{'context'};
7221: if ($roleslog{$id}{'logentry'}{'selfenroll'}) {
7222: $chgcontext = 'selfenroll';
7223: }
1.363 raeburn 7224: my %lt = &rolechg_contexts($context,$crstype);
1.239 raeburn 7225: if ($chgcontext ne '' && $lt{$chgcontext} ne '') {
7226: $chgcontext = $lt{$chgcontext};
7227: }
1.468 raeburn 7228: my ($showreqby,%reqby);
7229: if (($roleslog{$id}{'logentry'}{'approval'}) &&
7230: ($roleslog{$id}{'logentry'}{'requester'})) {
7231: if ($reqby{$roleslog{$id}{'logentry'}{'requester'}} eq '') {
7232: my ($requname,$requdom) = split(/:/,$roleslog{$id}{'logentry'}{'requester'});
7233: $reqby{$roleslog{$id}{'logentry'}{'requester'}} =
7234: &Apache::loncommon::plainname($requname,$requdom);
7235: }
7236: $showreqby = &mt('Requester').': <span class="LC_nobreak">'.$reqby{$roleslog{$id}{'logentry'}{'requester'}}.'</span><br />';
7237: if ($roleslog{$id}{'logentry'}{'approval'} eq 'domain') {
7238: $showreqby .= &mt('Adjudicator').': <span class="LC_nobreak">'.
7239: $whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}}.
7240: '</span>';
7241: } else {
7242: $showreqby .= '<span class="LC_nobreak">'.&mt('User approved').'</span>';
7243: }
7244: } else {
7245: $showreqby = $whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}};
7246: }
1.327 raeburn 7247: $r->print(
1.301 bisitz 7248: &Apache::loncommon::start_data_table_row()
7249: .'<td>'.$count.'</td>'
7250: .'<td>'.&Apache::lonlocal::locallocaltime($roleslog{$id}{'exe_time'}).'</td>'
1.468 raeburn 7251: .'<td>'.$showreqby.'</td>'
1.301 bisitz 7252: .'<td>'.$changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}}.'</td>'
1.363 raeburn 7253: .'<td>'.&Apache::lonnet::plaintext($roleslog{$id}{'logentry'}{'role'},$crstype).'</td>');
7254: if ($context eq 'course') {
7255: $r->print('<td>'.$sec.'</td>');
7256: }
7257: $r->print(
7258: '<td>'.$chgcontext.'</td>'
1.301 bisitz 7259: .'<td>'.$rolestart.'</td>'
7260: .'<td>'.$roleend.'</td>'
1.327 raeburn 7261: .&Apache::loncommon::end_data_table_row()."\n");
1.301 bisitz 7262: }
7263:
1.327 raeburn 7264: if ($showntableheader) { # Table footer, if content displayed above
1.415 raeburn 7265: $r->print(&Apache::loncommon::end_data_table().
7266: &userlogdisplay_navlinks(\%curr,$more_records));
1.327 raeburn 7267: } else { # No content displayed above
1.301 bisitz 7268: $r->print('<p class="LC_info">'
7269: .&mt('There are no records to display.')
7270: .'</p>'
7271: );
1.239 raeburn 7272: }
1.301 bisitz 7273:
1.327 raeburn 7274: # Form Footer
7275: $r->print(
7276: '<input type="hidden" name="page" value="'.$curr{'page'}.'" />'
7277: .'<input type="hidden" name="action" value="changelogs" />'
7278: .'</form>');
7279: return;
7280: }
1.301 bisitz 7281:
1.416 raeburn 7282: sub print_useraccesslogs_display {
7283: my ($r,$uname,$udom,$permission,$brcrum) = @_;
7284: my $formname = 'accesslog';
7285: my $form = 'document.accesslog';
7286:
7287: # set breadcrumbs
1.422 raeburn 7288: my %breadcrumb_text = &singleuser_breadcrumb('','domain',$udom);
1.431 raeburn 7289: my $prevphasestr;
7290: if ($env{'form.popup'}) {
7291: $brcrum = [];
7292: } else {
7293: push (@{$brcrum},
7294: {href => "javascript:backPage($form)",
7295: text => $breadcrumb_text{'search'}});
7296: my @prevphases;
7297: if ($env{'form.prevphases'}) {
7298: @prevphases = split(/,/,$env{'form.prevphases'});
7299: $prevphasestr = $env{'form.prevphases'};
7300: }
7301: if (($env{'form.phase'} eq 'userpicked') || (grep(/^userpicked$/,@prevphases))) {
7302: push(@{$brcrum},
7303: {href => "javascript:backPage($form,'get_user_info','select')",
7304: text => $breadcrumb_text{'userpicked'}});
7305: if ($env{'form.phase'} eq 'userpicked') {
7306: $prevphasestr = 'userpicked';
7307: }
1.416 raeburn 7308: }
7309: }
7310: push(@{$brcrum},
7311: {href => '/adm/createuser?action=accesslogs',
7312: text => 'User access logs',
1.424 raeburn 7313: help => 'Domain_User_Access_Logs'});
1.416 raeburn 7314: my $bread_crumbs_component = 'User Access Logs';
7315: my $args = { bread_crumbs => $brcrum,
7316: bread_crumbs_component => 'User Management'};
1.423 raeburn 7317: if ($env{'form.popup'}) {
7318: $args->{'no_nav_bar'} = 1;
1.431 raeburn 7319: $args->{'bread_crumbs_nomenu'} = 1;
1.423 raeburn 7320: }
1.416 raeburn 7321:
1.417 raeburn 7322: # set javascript
1.416 raeburn 7323: my ($jsback,$elements) = &crumb_utilities();
7324: my $jsnav = &userlogdisplay_js($formname);
7325:
7326: my $jscript = (<<ENDSCRIPT);
7327: <script type="text/javascript">
7328: // <![CDATA[
7329:
7330: $jsback
7331: $jsnav
7332:
7333: // ]]>
7334: </script>
7335:
7336: ENDSCRIPT
7337:
1.417 raeburn 7338: # print page header
1.416 raeburn 7339: $r->print(&header($jscript,$args));
7340:
7341: # early out unless log data can be displayed.
7342: unless ($permission->{'activity'}) {
7343: $r->print('<p class="LC_warning">'
7344: .&mt('You do not have rights to display user access logs.')
1.431 raeburn 7345: .'</p>');
7346: if ($env{'form.popup'}) {
7347: $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a></p>');
7348: } else {
7349: $r->print(&earlyout_accesslog_form($formname,$prevphasestr,$udom));
7350: }
1.416 raeburn 7351: return;
7352: }
7353:
7354: unless ($udom eq $env{'request.role.domain'}) {
7355: $r->print('<p class="LC_warning">'
7356: .&mt("User's domain must match role's domain")
7357: .'</p>'
7358: .&earlyout_accesslog_form($formname,$prevphasestr,$udom));
1.417 raeburn 7359: return;
1.416 raeburn 7360: }
7361:
7362: if (($uname eq '') || ($udom eq '')) {
7363: $r->print('<p class="LC_warning">'
7364: .&mt('Invalid username or domain')
7365: .'</p>'
7366: .&earlyout_accesslog_form($formname,$prevphasestr,$udom));
7367: return;
7368: }
7369:
1.437 raeburn 7370: if (&Apache::lonnet::privileged($uname,$udom,
7371: [$env{'request.role.domain'}],['dc','su'])) {
7372: unless (&Apache::lonnet::privileged($env{'user.name'},$env{'user.domain'},
7373: [$env{'request.role.domain'}],['dc','su'])) {
7374: $r->print('<p class="LC_warning">'
7375: .&mt('You need to be a privileged user to display user access logs for [_1]',
7376: &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),
7377: $uname,$udom))
7378: .'</p>');
7379: if ($env{'form.popup'}) {
7380: $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a></p>');
7381: } else {
7382: $r->print(&earlyout_accesslog_form($formname,$prevphasestr,$udom));
7383: }
7384: return;
7385: }
7386: }
7387:
1.416 raeburn 7388: # set defaults
7389: my $now = time();
7390: my $defstart = $now - (7*24*3600);
7391: my %defaults = (
7392: page => '1',
7393: show => '10',
7394: activity => 'any',
7395: accesslog_start_date => $defstart,
7396: accesslog_end_date => $now,
7397: );
7398: my $more_records = 0;
7399:
7400: # set current
7401: my %curr;
7402: foreach my $item ('show','page','activity') {
7403: $curr{$item} = $env{'form.'.$item};
7404: }
7405: my ($startdate,$enddate) =
7406: &Apache::lonuserutils::get_dates_from_form('accesslog_start_date','accesslog_end_date');
7407: $curr{'accesslog_start_date'} = $startdate;
7408: $curr{'accesslog_end_date'} = $enddate;
7409: foreach my $key (keys(%defaults)) {
7410: if ($curr{$key} eq '') {
7411: $curr{$key} = $defaults{$key};
7412: }
7413: }
7414: my ($minshown,$maxshown);
7415: $minshown = 1;
7416: my $count = 0;
7417: if ($curr{'show'} =~ /\D/) {
7418: $curr{'page'} = 1;
7419: } else {
7420: $maxshown = $curr{'page'} * $curr{'show'};
7421: if ($curr{'page'} > 1) {
7422: $minshown = 1 + ($curr{'page'} - 1) * $curr{'show'};
7423: }
7424: }
7425:
7426: # form header
7427: $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">'.
7428: &activity_display_filter($formname,\%curr));
7429:
7430: my $showntableheader = 0;
7431: my ($nav_script,$nav_links);
7432:
7433: # table header
1.453 raeburn 7434: my $heading = '<h3>'.
1.431 raeburn 7435: &mt('User access logs for: [_1]',
1.453 raeburn 7436: &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),$uname,$udom)).'</h3>';
7437: my $tableheader = $heading
1.431 raeburn 7438: .&Apache::loncommon::start_data_table_header_row()
1.416 raeburn 7439: .'<th> </th>'
7440: .'<th>'.&mt('When').'</th>'
7441: .'<th>'.&mt('HostID').'</th>'
7442: .'<th>'.&mt('Event').'</th>'
7443: .'<th>'.&mt('Other data').'</th>'
7444: .&Apache::loncommon::end_data_table_header_row();
7445:
7446: my %filters=(
7447: start => $curr{'accesslog_start_date'},
7448: end => $curr{'accesslog_end_date'},
7449: action => $curr{'activity'},
7450: );
7451:
7452: my $reply = &Apache::lonnet::userlog_query($uname,$udom,%filters);
7453: unless ( ($reply =~/^timeout/) || ($reply =~/^error/) ) {
7454: my (%courses,%missing);
7455: my @results = split(/\&/,$reply);
7456: foreach my $item (reverse(@results)) {
7457: my ($timestamp,$host,$event) = split(/:/,$item);
7458: next unless ($event =~ /^(Log|Role)/);
7459: if ($curr{'show'} !~ /\D/) {
7460: if ($count >= $curr{'page'} * $curr{'show'}) {
7461: $more_records = 1;
7462: last;
7463: }
7464: }
7465: $count ++;
7466: next if ($count < $minshown);
7467: unless ($showntableheader) {
7468: $r->print($nav_script
7469: .&Apache::loncommon::start_data_table()
7470: .$tableheader);
7471: $r->rflush();
7472: $showntableheader = 1;
7473: }
1.418 raeburn 7474: my ($shown,$extra);
1.437 raeburn 7475: my ($event,$data) = split(/\s+/,&unescape($event),2);
1.416 raeburn 7476: if ($event eq 'Role') {
7477: my ($rolecode,$extent) = split(/\./,$data,2);
7478: next if ($extent eq '');
7479: my ($crstype,$desc,$info);
1.418 raeburn 7480: if ($extent =~ m{^/($match_domain)/($match_courseid)(?:/(\w+)|)$}) {
7481: my ($cdom,$cnum,$sec) = ($1,$2,$3);
1.416 raeburn 7482: my $cid = $cdom.'_'.$cnum;
7483: if (exists($courses{$cid})) {
7484: $crstype = $courses{$cid}{'type'};
7485: $desc = $courses{$cid}{'description'};
7486: } elsif ($missing{$cid}) {
7487: $crstype = 'Course';
7488: $desc = 'Course/Community';
7489: } else {
7490: my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',$cnum,undef,undef,'.');
7491: if (ref($crsinfo{$cdom.'_'.$cnum}) eq 'HASH') {
7492: $courses{$cid} = $crsinfo{$cid};
7493: $crstype = $crsinfo{$cid}{'type'};
7494: $desc = $crsinfo{$cid}{'description'};
7495: } else {
7496: $missing{$cid} = 1;
7497: }
7498: }
7499: $extra = &mt($crstype).': <a href="/public/'.$cdom.'/'.$cnum.'/syllabus">'.$desc.'</a>';
1.418 raeburn 7500: if ($sec ne '') {
7501: $extra .= ' ('.&mt('Section: [_1]',$sec).')';
7502: }
1.416 raeburn 7503: } elsif ($extent =~ m{^/($match_domain)/($match_username|$)}) {
7504: my ($dom,$name) = ($1,$2);
7505: if ($rolecode eq 'au') {
7506: $extra = '';
7507: } elsif ($rolecode =~ /^(ca|aa)$/) {
1.417 raeburn 7508: $extra = &mt('Authoring Space: [_1]',$name.':'.$dom);
1.416 raeburn 7509: } elsif ($rolecode =~ /^(li|dg|dh|dc|sc)$/) {
7510: $extra = &mt('Domain: [_1]',$dom);
7511: }
7512: }
7513: my $rolename;
7514: if ($rolecode =~ m{^cr/($match_domain)/($match_username)/(\w+)}) {
7515: my $role = $3;
1.417 raeburn 7516: my $owner = "($2:$1)";
1.416 raeburn 7517: if ($2 eq $1.'-domainconfig') {
7518: $owner = '(ad hoc)';
1.417 raeburn 7519: }
1.416 raeburn 7520: $rolename = &mt('Custom role: [_1]',$role.' '.$owner);
7521: } else {
7522: $rolename = &Apache::lonnet::plaintext($rolecode,$crstype);
7523: }
7524: $shown = &mt('Role selection: [_1]',$rolename);
7525: } else {
7526: $shown = &mt($event);
1.437 raeburn 7527: if ($data =~ /^webdav/) {
7528: my ($path,$clientip) = split(/\s+/,$data,2);
7529: $path =~ s/^webdav//;
7530: if ($clientip ne '') {
7531: $extra = &mt('Client IP address: [_1]',$clientip);
7532: }
7533: if ($path ne '') {
7534: $shown .= ' '.&mt('(WebDAV access to [_1])',$path);
7535: }
7536: } elsif ($data ne '') {
7537: $extra = &mt('Client IP address: [_1]',$data);
1.416 raeburn 7538: }
7539: }
7540: $r->print(
7541: &Apache::loncommon::start_data_table_row()
7542: .'<td>'.$count.'</td>'
7543: .'<td>'.&Apache::lonlocal::locallocaltime($timestamp).'</td>'
7544: .'<td>'.$host.'</td>'
7545: .'<td>'.$shown.'</td>'
7546: .'<td>'.$extra.'</td>'
7547: .&Apache::loncommon::end_data_table_row()."\n");
7548: }
7549: }
7550:
7551: if ($showntableheader) { # Table footer, if content displayed above
7552: $r->print(&Apache::loncommon::end_data_table().
7553: &userlogdisplay_navlinks(\%curr,$more_records));
7554: } else { # No content displayed above
1.453 raeburn 7555: $r->print($heading.'<p class="LC_info">'
1.416 raeburn 7556: .&mt('There are no records to display.')
7557: .'</p>');
7558: }
7559:
1.423 raeburn 7560: if ($env{'form.popup'} == 1) {
7561: $r->print('<input type="hidden" name="popup" value="1" />'."\n");
7562: }
7563:
1.416 raeburn 7564: # Form Footer
7565: $r->print(
7566: '<input type="hidden" name="currstate" value="" />'
7567: .'<input type="hidden" name="accessuname" value="'.$uname.'" />'
7568: .'<input type="hidden" name="accessudom" value="'.$udom.'" />'
7569: .'<input type="hidden" name="page" value="'.$curr{'page'}.'" />'
7570: .'<input type="hidden" name="prevphases" value="'.$prevphasestr.'" />'
7571: .'<input type="hidden" name="phase" value="activity" />'
7572: .'<input type="hidden" name="action" value="accesslogs" />'
7573: .'<input type="hidden" name="srchdomain" value="'.$udom.'" />'
7574: .'<input type="hidden" name="srchby" value="'.$env{'form.srchby'}.'" />'
7575: .'<input type="hidden" name="srchtype" value="'.$env{'form.srchtype'}.'" />'
7576: .'<input type="hidden" name="srchterm" value="'.&HTML::Entities::encode($env{'form.srchterm'},'<>"&').'" />'
7577: .'<input type="hidden" name="srchin" value="'.$env{'form.srchin'}.'" />'
7578: .'</form>');
7579: return;
7580: }
7581:
7582: sub earlyout_accesslog_form {
7583: my ($formname,$prevphasestr,$udom) = @_;
7584: my $srchterm = &HTML::Entities::encode($env{'form.srchterm'},'<>"&');
7585: return <<"END";
7586: <form action="/adm/createuser" method="post" name="$formname">
7587: <input type="hidden" name="currstate" value="" />
7588: <input type="hidden" name="prevphases" value="$prevphasestr" />
7589: <input type="hidden" name="phase" value="activity" />
7590: <input type="hidden" name="action" value="accesslogs" />
7591: <input type="hidden" name="srchdomain" value="$udom" />
7592: <input type="hidden" name="srchby" value="$env{'form.srchby'}" />
7593: <input type="hidden" name="srchtype" value="$env{'form.srchtype'}" />
7594: <input type="hidden" name="srchterm" value="$srchterm" />
7595: <input type="hidden" name="srchin" value="$env{'form.srchin'}" />
7596: </form>
7597: END
7598: }
7599:
7600: sub activity_display_filter {
7601: my ($formname,$curr) = @_;
7602: my $nolink = 1;
7603: my $output = '<table><tr><td valign="top">'.
7604: '<span class="LC_nobreak"><b>'.&mt('Actions/page:').'</b></span><br />'.
1.467 raeburn 7605: &Apache::lonmeta::selectbox('show',$curr->{'show'},'',undef,
1.416 raeburn 7606: (&mt('all'),5,10,20,50,100,1000,10000)).
7607: '</td><td> </td>';
7608: my $startform =
7609: &Apache::lonhtmlcommon::date_setter($formname,'accesslog_start_date',
7610: $curr->{'accesslog_start_date'},undef,
7611: undef,undef,undef,undef,undef,undef,$nolink);
7612: my $endform =
7613: &Apache::lonhtmlcommon::date_setter($formname,'accesslog_end_date',
7614: $curr->{'accesslog_end_date'},undef,
7615: undef,undef,undef,undef,undef,undef,$nolink);
7616: my %lt = &Apache::lonlocal::texthash (
7617: activity => 'Activity',
7618: Role => 'Role selection',
7619: log => 'Log-in or Logout',
7620: );
7621: $output .= '<td valign="top"><b>'.&mt('Window during which actions occurred:').'</b><br />'.
7622: '<table><tr><td>'.&mt('After:').
7623: '</td><td>'.$startform.'</td></tr>'.
7624: '<tr><td>'.&mt('Before:').'</td>'.
7625: '<td>'.$endform.'</td></tr></table>'.
7626: '</td>'.
7627: '<td> </td>'.
7628: '<td valign="top"><b>'.&mt('Activities').'</b><br />'.
7629: '<select name="activity"><option value="any"';
7630: if ($curr->{'activity'} eq 'any') {
7631: $output .= ' selected="selected"';
7632: }
7633: $output .= '>'.&mt('Any').'</option>'."\n";
7634: foreach my $activity ('Role','log') {
7635: my $selstr = '';
7636: if ($activity eq $curr->{'activity'}) {
7637: $selstr = ' selected="selected"';
7638: }
7639: $output .= '<option value="'.$activity.'"'.$selstr.'>'.$lt{$activity}.'</option>';
7640: }
7641: $output .= '</select></td>'.
7642: '</tr></table>';
7643: # Update Display button
7644: $output .= '<p>'
7645: .'<input type="submit" value="'.&mt('Update Display').'" />'
1.431 raeburn 7646: .'</p><hr />';
1.416 raeburn 7647: return $output;
7648: }
7649:
1.415 raeburn 7650: sub userlogdisplay_js {
7651: my ($formname) = @_;
7652: return <<"ENDSCRIPT";
7653:
1.239 raeburn 7654: function chgPage(caller) {
7655: if (caller == 'previous') {
7656: document.$formname.page.value --;
7657: }
7658: if (caller == 'next') {
7659: document.$formname.page.value ++;
7660: }
1.327 raeburn 7661: document.$formname.submit();
1.239 raeburn 7662: return;
7663: }
7664: ENDSCRIPT
1.415 raeburn 7665: }
7666:
7667: sub userlogdisplay_navlinks {
7668: my ($curr,$more_records) = @_;
7669: return unless(ref($curr) eq 'HASH');
7670: # Navigation Buttons
7671: my $nav_links = '<p>';
7672: if (($curr->{'page'} > 1) || ($more_records)) {
7673: if (($curr->{'page'} > 1) && ($curr->{'show'} !~ /\D/)) {
7674: $nav_links .= '<input type="button"'
7675: .' onclick="javascript:chgPage('."'previous'".');"'
7676: .' value="'.&mt('Previous [_1] changes',$curr->{'show'})
7677: .'" /> ';
7678: }
7679: if ($more_records) {
7680: $nav_links .= '<input type="button"'
7681: .' onclick="javascript:chgPage('."'next'".');"'
7682: .' value="'.&mt('Next [_1] changes',$curr->{'show'})
7683: .'" />';
1.301 bisitz 7684: }
7685: }
1.415 raeburn 7686: $nav_links .= '</p>';
7687: return $nav_links;
1.239 raeburn 7688: }
7689:
7690: sub role_display_filter {
1.363 raeburn 7691: my ($context,$formname,$cdom,$cnum,$curr,$version,$crstype) = @_;
1.239 raeburn 7692: my $nolink = 1;
7693: my $output = '<table><tr><td valign="top">'.
1.301 bisitz 7694: '<span class="LC_nobreak"><b>'.&mt('Changes/page:').'</b></span><br />'.
1.467 raeburn 7695: &Apache::lonmeta::selectbox('show',$curr->{'show'},'',undef,
1.239 raeburn 7696: (&mt('all'),5,10,20,50,100,1000,10000)).
7697: '</td><td> </td>';
7698: my $startform =
7699: &Apache::lonhtmlcommon::date_setter($formname,'rolelog_start_date',
7700: $curr->{'rolelog_start_date'},undef,
7701: undef,undef,undef,undef,undef,undef,$nolink);
7702: my $endform =
7703: &Apache::lonhtmlcommon::date_setter($formname,'rolelog_end_date',
7704: $curr->{'rolelog_end_date'},undef,
7705: undef,undef,undef,undef,undef,undef,$nolink);
1.363 raeburn 7706: my %lt = &rolechg_contexts($context,$crstype);
1.301 bisitz 7707: $output .= '<td valign="top"><b>'.&mt('Window during which changes occurred:').'</b><br />'.
7708: '<table><tr><td>'.&mt('After:').
7709: '</td><td>'.$startform.'</td></tr>'.
7710: '<tr><td>'.&mt('Before:').'</td>'.
7711: '<td>'.$endform.'</td></tr></table>'.
7712: '</td>'.
7713: '<td> </td>'.
1.239 raeburn 7714: '<td valign="top"><b>'.&mt('Role:').'</b><br />'.
7715: '<select name="role"><option value="any"';
7716: if ($curr->{'role'} eq 'any') {
7717: $output .= ' selected="selected"';
7718: }
1.466 raeburn 7719: $output .= '>'.&mt('Any').'</option>'."\n";
1.363 raeburn 7720: my @roles = &Apache::lonuserutils::roles_by_context($context,1,$crstype);
1.239 raeburn 7721: foreach my $role (@roles) {
7722: my $plrole;
7723: if ($role eq 'cr') {
7724: $plrole = &mt('Custom Role');
7725: } else {
1.318 raeburn 7726: $plrole=&Apache::lonnet::plaintext($role,$crstype);
1.239 raeburn 7727: }
7728: my $selstr = '';
7729: if ($role eq $curr->{'role'}) {
7730: $selstr = ' selected="selected"';
7731: }
7732: $output .= ' <option value="'.$role.'"'.$selstr.'>'.$plrole.'</option>';
7733: }
1.301 bisitz 7734: $output .= '</select></td>'.
7735: '<td> </td>'.
7736: '<td valign="top"><b>'.
1.239 raeburn 7737: &mt('Context:').'</b><br /><select name="chgcontext">';
1.363 raeburn 7738: my @posscontexts;
7739: if ($context eq 'course') {
1.468 raeburn 7740: @posscontexts = ('any','automated','updatenow','createcourse','course','domain','selfenroll','requestcourses','chgtype','ltienroll');
1.363 raeburn 7741: } elsif ($context eq 'domain') {
7742: @posscontexts = ('any','domain','requestauthor','domconfig','server');
7743: } else {
7744: @posscontexts = ('any','author','domain');
1.457 raeburn 7745: }
1.363 raeburn 7746: foreach my $chgtype (@posscontexts) {
1.239 raeburn 7747: my $selstr = '';
7748: if ($curr->{'chgcontext'} eq $chgtype) {
1.301 bisitz 7749: $selstr = ' selected="selected"';
1.239 raeburn 7750: }
1.363 raeburn 7751: if ($context eq 'course') {
1.376 raeburn 7752: if (($chgtype eq 'automated') || ($chgtype eq 'updatenow')) {
1.363 raeburn 7753: next if (!&Apache::lonnet::auto_run($cnum,$cdom));
7754: }
1.239 raeburn 7755: }
7756: $output .= '<option value="'.$chgtype.'"'.$selstr.'>'.$lt{$chgtype}.'</option>'."\n";
1.248 raeburn 7757: }
1.468 raeburn 7758: my @possapprovals = ('any','none','domain','user');
7759: my %apptxt = &approval_types();
7760: $output .= '</select></td>'.
7761: '<td> </td>'.
7762: '<td valign="top"><b>'.
7763: &mt('Approvals:').'</b><br /><select name="approvals">';
7764: foreach my $approval (@possapprovals) {
7765: my $selstr = '';
7766: if ($curr->{'approvals'} eq $approval) {
7767: $selstr = ' selected="selected"';
7768: }
7769: $output .= '<option value="'.$approval.'"'.$selstr.'>'.$apptxt{$approval}.'</option>';
7770: }
7771: $output .= '</select></td></tr></table>';
1.303 bisitz 7772:
7773: # Update Display button
7774: $output .= '<p>'
7775: .'<input type="submit" value="'.&mt('Update Display').'" />'
7776: .'</p>';
7777:
7778: # Server version info
1.363 raeburn 7779: my $needsrev = '2.11.0';
7780: if ($context eq 'course') {
7781: $needsrev = '2.7.0';
7782: }
7783:
1.303 bisitz 7784: $output .= '<p class="LC_info">'
7785: .&mt('Only changes made from servers running LON-CAPA [_1] or later are displayed.'
1.363 raeburn 7786: ,$needsrev);
1.248 raeburn 7787: if ($version) {
1.303 bisitz 7788: $output .= ' '.&mt('This LON-CAPA server is version [_1]',$version);
7789: }
7790: $output .= '</p><hr />';
1.239 raeburn 7791: return $output;
7792: }
7793:
7794: sub rolechg_contexts {
1.363 raeburn 7795: my ($context,$crstype) = @_;
7796: my %lt;
7797: if ($context eq 'course') {
7798: %lt = &Apache::lonlocal::texthash (
1.239 raeburn 7799: any => 'Any',
1.376 raeburn 7800: automated => 'Automated Enrollment',
1.457 raeburn 7801: chgtype => 'Enrollment Type/Lock Change',
1.239 raeburn 7802: updatenow => 'Roster Update',
7803: createcourse => 'Course Creation',
7804: course => 'User Management in course',
7805: domain => 'User Management in domain',
1.313 raeburn 7806: selfenroll => 'Self-enrolled',
1.318 raeburn 7807: requestcourses => 'Course Request',
1.468 raeburn 7808: ltienroll => 'Enrollment via LTI',
1.239 raeburn 7809: );
1.363 raeburn 7810: if ($crstype eq 'Community') {
7811: $lt{'createcourse'} = &mt('Community Creation');
7812: $lt{'course'} = &mt('User Management in community');
7813: $lt{'requestcourses'} = &mt('Community Request');
7814: }
7815: } elsif ($context eq 'domain') {
7816: %lt = &Apache::lonlocal::texthash (
7817: any => 'Any',
7818: domain => 'User Management in domain',
7819: requestauthor => 'Authoring Request',
7820: server => 'Command line script (DC role)',
7821: domconfig => 'Self-enrolled',
7822: );
7823: } else {
7824: %lt = &Apache::lonlocal::texthash (
7825: any => 'Any',
7826: domain => 'User Management in domain',
7827: author => 'User Management by author',
7828: );
7829: }
1.239 raeburn 7830: return %lt;
7831: }
7832:
1.468 raeburn 7833: sub approval_types {
7834: return &Apache::lonlocal::texthash (
7835: any => 'Any',
7836: none => 'No approval needed',
7837: user => 'Role recipient approval',
7838: domain => 'Domain coordinator approval',
7839: );
7840: }
7841:
1.428 raeburn 7842: sub print_helpdeskaccess_display {
7843: my ($r,$permission,$brcrum) = @_;
7844: my $formname = 'helpdeskaccess';
7845: my $helpitem = 'Course_Helpdesk_Access';
7846: push (@{$brcrum},
7847: {href => '/adm/createuser?action=helpdesk',
7848: text => 'Helpdesk Access',
7849: help => $helpitem});
7850: my $bread_crumbs_component = 'Helpdesk Staff Access';
7851: my $args = { bread_crumbs => $brcrum,
7852: bread_crumbs_component => $bread_crumbs_component};
7853:
7854: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
7855: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
7856: my $confname = $cdom.'-domainconfig';
7857: my $crstype = &Apache::loncommon::course_type();
7858:
1.434 raeburn 7859: my @accesstypes = ('all','dh','da','none');
1.428 raeburn 7860: my ($numstatustypes,@jsarray);
7861: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($cdom);
7862: if (ref($types) eq 'ARRAY') {
1.430 raeburn 7863: if (@{$types} > 0) {
1.428 raeburn 7864: $numstatustypes = scalar(@{$types});
7865: push(@accesstypes,'status');
7866: @jsarray = ('bystatus');
7867: }
7868: }
7869: my %customroles = &get_domain_customroles($cdom,$confname);
1.432 raeburn 7870: my %domhelpdesk = &Apache::lonnet::get_active_domroles($cdom,['dh','da']);
1.428 raeburn 7871: if (keys(%domhelpdesk)) {
7872: push(@accesstypes,('inc','exc'));
7873: push(@jsarray,('notinc','notexc'));
7874: }
7875: push(@jsarray,'privs');
7876: my $hiddenstr = join("','",@jsarray);
7877: my $rolestr = join("','",sort(keys(%customroles)));
7878:
7879: my $jscript;
7880: my (%settings,%overridden);
7881: if (keys(%customroles)) {
7882: &get_adhocrole_settings($env{'request.course.id'},\@accesstypes,
7883: $types,\%customroles,\%settings,\%overridden);
7884: my %jsfull=();
7885: my %jslevels= (
7886: course => {},
7887: domain => {},
7888: system => {},
7889: );
7890: my %jslevelscurrent=(
7891: course => {},
7892: domain => {},
7893: system => {},
7894: );
7895: my (%privs,%jsprivs);
7896: &Apache::lonuserutils::custom_role_privs(\%privs,\%jsfull,\%jslevels,\%jslevelscurrent);
7897: foreach my $priv (keys(%jsfull)) {
7898: if ($jslevels{'course'}{$priv}) {
7899: $jsprivs{$priv} = 1;
7900: }
7901: }
7902: my (%elements,%stored);
7903: foreach my $role (keys(%customroles)) {
7904: $elements{$role.'_access'} = 'radio';
7905: $elements{$role.'_incrs'} = 'radio';
7906: if ($numstatustypes) {
7907: $elements{$role.'_status'} = 'checkbox';
7908: }
7909: if (keys(%domhelpdesk) > 0) {
7910: $elements{$role.'_staff_inc'} = 'checkbox';
7911: $elements{$role.'_staff_exc'} = 'checkbox';
7912: }
1.430 raeburn 7913: $elements{$role.'_override'} = 'checkbox';
1.428 raeburn 7914: if (ref($settings{$role}) eq 'HASH') {
7915: if ($settings{$role}{'access'} ne '') {
7916: my $curraccess = $settings{$role}{'access'};
7917: $stored{$role.'_access'} = $curraccess;
7918: $stored{$role.'_incrs'} = 1;
7919: if ($curraccess eq 'status') {
7920: if (ref($settings{$role}{'status'}) eq 'ARRAY') {
7921: $stored{$role.'_status'} = $settings{$role}{'status'};
7922: }
7923: } elsif (($curraccess eq 'exc') || ($curraccess eq 'inc')) {
7924: if (ref($settings{$role}{$curraccess}) eq 'ARRAY') {
7925: $stored{$role.'_staff_'.$curraccess} = $settings{$role}{$curraccess};
7926: }
7927: }
7928: } else {
7929: $stored{$role.'_incrs'} = 0;
7930: }
7931: $stored{$role.'_override'} = [];
7932: if ($env{'course.'.$env{'request.course.id'}.'.internal.adhocpriv.'.$role}) {
7933: if (ref($settings{$role}{'off'}) eq 'ARRAY') {
7934: foreach my $priv (@{$settings{$role}{'off'}}) {
7935: push(@{$stored{$role.'_override'}},$priv);
7936: }
7937: }
7938: if (ref($settings{$role}{'on'}) eq 'ARRAY') {
7939: foreach my $priv (@{$settings{$role}{'on'}}) {
7940: unless (grep(/^$priv$/,@{$stored{$role.'_override'}})) {
7941: push(@{$stored{$role.'_override'}},$priv);
7942: }
7943: }
7944: }
7945: }
7946: } else {
7947: $stored{$role.'_incrs'} = 0;
7948: }
7949: }
7950: $jscript = &Apache::lonhtmlcommon::set_form_elements(\%elements,\%stored);
7951: }
7952:
7953: my $js = <<"ENDJS";
7954: <script type="text/javascript">
7955: // <![CDATA[
7956: $jscript;
7957:
7958: function switchRoleTab(caller,role) {
7959: if (document.getElementById(role+'_maindiv')) {
7960: if (caller.id != 'LC_current_minitab') {
7961: if (document.getElementById('LC_current_minitab')) {
7962: document.getElementById('LC_current_minitab').id=null;
7963: }
7964: var roledivs = Array('$rolestr');
7965: if (roledivs.length > 0) {
7966: for (var i=0; i<roledivs.length; i++) {
7967: if (document.getElementById(roledivs[i]+'_maindiv')) {
7968: document.getElementById(roledivs[i]+'_maindiv').style.display='none';
7969: }
7970: }
7971: }
7972: caller.id = 'LC_current_minitab';
7973: document.getElementById(role+'_maindiv').style.display='block';
7974: }
7975: }
7976: return false;
1.430 raeburn 7977: }
1.428 raeburn 7978:
7979: function helpdeskAccess(role) {
7980: var curraccess = null;
7981: if (document.$formname.elements[role+'_access'].length) {
7982: for (var i=0; i<document.$formname.elements[role+'_access'].length; i++) {
7983: if (document.$formname.elements[role+'_access'][i].checked) {
7984: curraccess = document.$formname.elements[role+'_access'][i].value;
7985: }
7986: }
7987: }
7988: var shown = Array();
7989: var hidden = Array();
7990: if (curraccess == 'none') {
1.430 raeburn 7991: hidden = Array ('$hiddenstr');
1.428 raeburn 7992: } else {
7993: if (curraccess == 'status') {
1.430 raeburn 7994: shown = Array ('bystatus','privs');
7995: hidden = Array ('notinc','notexc');
1.428 raeburn 7996: } else {
7997: if (curraccess == 'exc') {
7998: shown = Array ('notexc','privs');
7999: hidden = Array ('notinc','bystatus');
8000: }
8001: if (curraccess == 'inc') {
8002: shown = Array ('notinc','privs');
8003: hidden = Array ('notexc','bystatus');
8004: }
8005: if (curraccess == 'all') {
8006: shown = Array ('privs');
8007: hidden = Array ('notinc','notexc','bystatus');
8008: }
8009: }
8010: }
8011: if (hidden.length > 0) {
8012: for (var i=0; i<hidden.length; i++) {
8013: if (document.getElementById(role+'_'+hidden[i])) {
1.430 raeburn 8014: document.getElementById(role+'_'+hidden[i]).style.display = 'none';
1.428 raeburn 8015: }
8016: }
8017: }
8018: if (shown.length > 0) {
8019: for (var i=0; i<shown.length; i++) {
8020: if (document.getElementById(role+'_'+shown[i])) {
8021: if (shown[i] == 'privs') {
8022: document.getElementById(role+'_'+shown[i]).style.display = 'block';
8023: } else {
8024: document.getElementById(role+'_'+shown[i]).style.display = 'inline';
8025: }
8026: }
8027: }
8028: }
8029: return;
8030: }
8031:
8032: function toggleAccess(role) {
8033: if ((document.getElementById(role+'_setincrs')) &&
8034: (document.getElementById(role+'_setindom'))) {
8035: for (var i=0; i<document.$formname.elements[role+'_incrs'].length; i++) {
8036: if (document.$formname.elements[role+'_incrs'][i].checked) {
8037: if (document.$formname.elements[role+'_incrs'][i].value == 1) {
8038: document.getElementById(role+'_setindom').style.display = 'none';
1.430 raeburn 8039: document.getElementById(role+'_setincrs').style.display = 'block';
1.428 raeburn 8040: } else {
8041: document.getElementById(role+'_setincrs').style.display = 'none';
8042: document.getElementById(role+'_setindom').style.display = 'block';
8043: }
8044: break;
8045: }
8046: }
8047: }
8048: return;
8049: }
8050:
8051: // ]]>
8052: </script>
8053: ENDJS
8054:
8055: $args->{add_entries} = {onload => "javascript:setFormElements(document.$formname)"};
8056:
8057: # print page header
8058: $r->print(&header($js,$args));
8059: # print form header
8060: $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">');
8061:
8062: if (keys(%customroles)) {
8063: my %lt = &Apache::lonlocal::texthash(
8064: 'aco' => 'As course owner you may override the defaults set in the domain for role usage and/or privileges.',
8065: 'rou' => 'Role usage',
8066: 'whi' => 'Which helpdesk personnel may use this role?',
8067: 'udd' => 'Use domain default',
1.433 raeburn 8068: 'all' => 'All with domain helpdesk or helpdesk assistant role',
1.434 raeburn 8069: 'dh' => 'All with domain helpdesk role',
8070: 'da' => 'All with domain helpdesk assistant role',
1.428 raeburn 8071: 'none' => 'None',
8072: 'status' => 'Determined based on institutional status',
1.430 raeburn 8073: 'inc' => 'Include all, but exclude specific personnel',
1.428 raeburn 8074: 'exc' => 'Exclude all, but include specific personnel',
8075: 'hel' => 'Helpdesk',
8076: 'rpr' => 'Role privileges',
8077: );
8078: $lt{'tfh'} = &mt("Custom [_1]ad hoc[_2] course roles available for use by the domain's helpdesk are as follows",'<i>','</i>');
8079: my %domconfig = &Apache::lonnet::get_dom('configuration',['helpsettings'],$cdom);
8080: my (%domcurrent,%ordered,%description,%domusage,$disabled);
8081: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
8082: if (ref($domconfig{'helpsettings'}{'adhoc'}) eq 'HASH') {
8083: %domcurrent = %{$domconfig{'helpsettings'}{'adhoc'}};
8084: }
8085: }
8086: my $count = 0;
8087: foreach my $role (sort(keys(%customroles))) {
8088: my ($order,$desc,$access_in_dom);
8089: if (ref($domcurrent{$role}) eq 'HASH') {
8090: $order = $domcurrent{$role}{'order'};
8091: $desc = $domcurrent{$role}{'desc'};
8092: $access_in_dom = $domcurrent{$role}{'access'};
8093: }
8094: if ($order eq '') {
8095: $order = $count;
8096: }
8097: $ordered{$order} = $role;
8098: if ($desc ne '') {
8099: $description{$role} = $desc;
8100: } else {
8101: $description{$role}= $role;
8102: }
8103: $count++;
8104: }
8105: %domusage = &domain_adhoc_access(\%customroles,\%domcurrent,\@accesstypes,$usertypes,$othertitle);
8106: my @roles_by_num = ();
8107: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
8108: push(@roles_by_num,$ordered{$item});
1.430 raeburn 8109: }
1.429 raeburn 8110: $r->print('<p>'.$lt{'tfh'}.': <i>'.join('</i>, <i>',map { $description{$_}; } @roles_by_num).'</i>.');
1.428 raeburn 8111: if ($permission->{'owner'}) {
8112: $r->print('<br />'.$lt{'aco'}.'</p><p>');
8113: $r->print('<input type="hidden" name="state" value="process" />'.
8114: '<input type="submit" value="'.&mt('Save changes').'" />');
8115: } else {
8116: if ($env{'course.'.$env{'request.course.id'}.'.internal.courseowner'}) {
8117: my ($ownername,$ownerdom) = split(/:/,$env{'course.'.$env{'request.course.id'}.'.internal.courseowner'});
8118: $r->print('<br />'.&mt('The course owner -- [_1] -- can override the default access and/or privileges for these ad hoc roles.',
8119: &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($ownername,$ownerdom),$ownername,$ownerdom)));
8120: }
8121: $disabled = ' disabled="disabled"';
8122: }
8123: $r->print('</p>');
8124:
8125: $r->print('<div id="LC_minitab_header"><ul>');
8126: my $count = 0;
8127: my %visibility;
8128: foreach my $role (@roles_by_num) {
8129: my $id;
8130: if ($count == 0) {
8131: $id=' id="LC_current_minitab"';
1.430 raeburn 8132: $visibility{$role} = ' style="display:block"';
1.428 raeburn 8133: } else {
8134: $visibility{$role} = ' style="display:none"';
8135: }
8136: $count ++;
8137: $r->print('<li'.$id.'><a href="#" onclick="javascript:switchRoleTab(this.parentNode,'."'$role'".');">'.$description{$role}.'</a></li>');
8138: }
8139: $r->print('</ul></div>');
8140:
8141: foreach my $role (@roles_by_num) {
8142: my %usecheck = (
8143: all => ' checked="checked"',
8144: );
8145: my %displaydiv = (
8146: status => 'none',
8147: inc => 'none',
8148: exc => 'none',
8149: priv => 'block',
8150: );
8151: my (%selected,$overridden,$incrscheck,$indomcheck,$indomvis,$incrsvis);
1.430 raeburn 8152: if (ref($settings{$role}) eq 'HASH') {
1.428 raeburn 8153: if ($settings{$role}{'access'} ne '') {
8154: $indomvis = ' style="display:none"';
8155: $incrsvis = ' style="display:block"';
1.430 raeburn 8156: $incrscheck = ' checked="checked"';
1.428 raeburn 8157: if ($settings{$role}{'access'} ne 'all') {
8158: $usecheck{$settings{$role}{'access'}} = $usecheck{'all'};
8159: delete($usecheck{'all'});
8160: if ($settings{$role}{'access'} eq 'status') {
8161: my $access = 'status';
8162: $displaydiv{$access} = 'inline';
8163: if (ref($settings{$role}{$access}) eq 'ARRAY') {
8164: $selected{$access} = $settings{$role}{$access};
8165: }
8166: } elsif ($settings{$role}{'access'} =~ /^(inc|exc)$/) {
8167: my $access = $1;
8168: $displaydiv{$access} = 'inline';
8169: if (ref($settings{$role}{$access}) eq 'ARRAY') {
8170: $selected{$access} = $settings{$role}{$access};
8171: }
8172: } elsif ($settings{$role}{'access'} eq 'none') {
8173: $displaydiv{'priv'} = 'none';
8174: }
8175: }
8176: } else {
8177: $indomcheck = ' checked="checked"';
8178: $indomvis = ' style="display:block"';
8179: $incrsvis = ' style="display:none"';
8180: }
8181: } else {
8182: $indomcheck = ' checked="checked"';
1.430 raeburn 8183: $indomvis = ' style="display:block"';
1.428 raeburn 8184: $incrsvis = ' style="display:none"';
8185: }
8186: $r->print('<div class="LC_left_float" id="'.$role.'_maindiv"'.$visibility{$role}.'>'.
8187: '<fieldset><legend>'.$lt{'rou'}.'</legend>'.
8188: '<p>'.$lt{'whi'}.' <span class="LC_nobreak">'.
8189: '<label><input type="radio" name="'.$role.'_incrs" value="1"'.$incrscheck.' onclick="toggleAccess('."'$role'".');"'.$disabled.'>'.
8190: &mt('Set here in [_1]',lc($crstype)).'</label>'.
8191: '<span>'.(' 'x2).
8192: '<label><input type="radio" name="'.$role.'_incrs" value="0"'.$indomcheck.' onclick="toggleAccess('."'$role'".');"'.$disabled.'>'.
8193: $lt{'udd'}.'</label><span></p>'.
8194: '<div id="'.$role.'_setindom"'.$indomvis.'>'.
8195: '<span class="LC_cusr_emph">'.$domusage{$role}.'</span></div>'.
8196: '<div id="'.$role.'_setincrs"'.$incrsvis.'>');
8197: foreach my $access (@accesstypes) {
8198: $r->print('<p><label><input type="radio" name="'.$role.'_access" value="'.$access.'" '.$usecheck{$access}.
8199: ' onclick="helpdeskAccess('."'$role'".');"'.$disabled.' />'.$lt{$access}.'</label>');
8200: if ($access eq 'status') {
8201: $r->print('<div id="'.$role.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
8202: &Apache::lonuserutils::adhoc_status_types($cdom,undef,$role,$selected{$access},
8203: $othertitle,$usertypes,$types,$disabled).
8204: '</div>');
8205: } elsif (($access eq 'inc') && (keys(%domhelpdesk) > 0)) {
8206: $r->print('<div id="'.$role.'_notinc" style="display:'.$displaydiv{$access}.'">'.
8207: &Apache::lonuserutils::adhoc_staff($access,undef,$role,$selected{$access},
8208: \%domhelpdesk,$disabled).
8209: '</div>');
8210: } elsif (($access eq 'exc') && (keys(%domhelpdesk) > 0)) {
8211: $r->print('<div id="'.$role.'_notexc" style="display:'.$displaydiv{$access}.'">'.
8212: &Apache::lonuserutils::adhoc_staff($access,undef,$role,$selected{$access},
8213: \%domhelpdesk,$disabled).
8214: '</div>');
8215: }
8216: $r->print('</p>');
8217: }
8218: $r->print('</div></fieldset>');
8219: my %full=();
8220: my %levels= (
8221: course => {},
8222: domain => {},
8223: system => {},
8224: );
8225: my %levelscurrent=(
8226: course => {},
8227: domain => {},
8228: system => {},
8229: );
8230: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
8231: $r->print('<fieldset id="'.$role.'_privs" style="display:'.$displaydiv{'priv'}.'">'.
8232: '<legend>'.$lt{'rpr'}.'</legend>'.
8233: &role_priv_table($role,$permission,$crstype,\%full,\%levels,\%levelscurrent,$overridden{$role}).
8234: '</fieldset></div><div style="padding:0;clear:both;margin:0;border:0"></div>');
8235: }
1.429 raeburn 8236: if ($permission->{'owner'}) {
8237: $r->print('<p><input type="submit" value="'.&mt('Save changes').'" /></p>');
8238: }
1.428 raeburn 8239: } else {
8240: $r->print(&mt('Helpdesk roles have not yet been created in this domain.'));
8241: }
8242: # Form Footer
8243: $r->print('<input type="hidden" name="action" value="helpdesk" />'
8244: .'</form>');
8245: return;
8246: }
8247:
1.465 raeburn 8248: sub print_queued_roles {
8249: my ($r,$context,$permission,$brcrum) = @_;
8250: push (@{$brcrum},
8251: {href => '/adm/createuser?action=rolerequests',
8252: text => 'Role Requests (other domains)',
8253: help => ''});
8254: my $bread_crumbs_component = 'Role Requests';
8255: my $args = { bread_crumbs => $brcrum,
8256: bread_crumbs_component => $bread_crumbs_component};
8257: # print page header
8258: $r->print(&header('',$args));
8259: my ($dom,$cnum);
8260: $dom = $env{'request.role.domain'};
8261: if ($context eq 'course') {
8262: if ($env{'request.course.id'}) {
8263: if (&Apache::loncommon::course_type() eq 'Community') {
8264: $context = 'community';
8265: }
8266: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
8267: }
8268: } elsif ($context eq 'author') {
8269: $cnum = $env{'user.name'};
8270: }
8271: $r->print(&Apache::loncoursequeueadmin::display_queued_requests('othdomqueue',$dom,$cnum,$context));
8272: return;
8273: }
8274:
8275: sub print_pendingroles {
8276: my ($r,$context,$permission,$brcrum) = @_;
8277: push (@{$brcrum},
8278: {href => '/adm/createuser?action=queuedroles',
8279: text => 'Queued Role Assignments (users in this domain)',
8280: help => ''});
8281: my $bread_crumbs_component = 'Queued Role Assignments';
8282: my $args = { bread_crumbs => $brcrum,
8283: bread_crumbs_component => $bread_crumbs_component};
8284: # print page header
8285: $r->print(&header('',$args));
8286: $r->print(&Apache::loncoursequeueadmin::display_queued_requests('othdomaction',$env{'request.role.domain'},'','domain'));
8287: return;
8288: }
8289:
8290: sub process_pendingroles {
8291: my ($r,$context,$permission,$brcrum) = @_;
8292: push (@{$brcrum},
8293: {href => '/adm/createuser?action=queuedroles',
8294: text => 'Queued Role Assignments (users in this domain)',
8295: help => ''},
8296: {href => '/adm/createuser?action=processrolereq',
8297: text => 'Process Queue',
8298: help => ''});
8299: my $bread_crumbs_component = 'Queued Role Assignments';
8300: my $args = { bread_crumbs => $brcrum,
8301: bread_crumbs_component => $bread_crumbs_component};
8302: # print page header
8303: $r->print(&header('',$args));
8304: $r->print(&Apache::loncoursequeueadmin::update_request_queue('othdombydc',
8305: $env{'request.role.domain'}));
8306: return;
8307: }
8308:
1.428 raeburn 8309: sub domain_adhoc_access {
8310: my ($roles,$domcurrent,$accesstypes,$usertypes,$othertitle) = @_;
8311: my %domusage;
8312: return unless ((ref($roles) eq 'HASH') && (ref($domcurrent) eq 'HASH') && (ref($accesstypes) eq 'ARRAY'));
8313: foreach my $role (keys(%{$roles})) {
8314: if (ref($domcurrent->{$role}) eq 'HASH') {
8315: my $access = $domcurrent->{$role}{'access'};
8316: if (($access eq '') || (!grep(/^\Q$access\E$/,@{$accesstypes}))) {
8317: $access = 'all';
1.432 raeburn 8318: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role',&Apache::lonnet::plaintext('dh'),
8319: &Apache::lonnet::plaintext('da'));
1.428 raeburn 8320: } elsif ($access eq 'status') {
8321: if (ref($domcurrent->{$role}{$access}) eq 'ARRAY') {
8322: my @shown;
8323: foreach my $type (@{$domcurrent->{$role}{$access}}) {
8324: unless ($type eq 'default') {
8325: if ($usertypes->{$type}) {
8326: push(@shown,$usertypes->{$type});
8327: }
8328: }
8329: }
8330: if (grep(/^default$/,@{$domcurrent->{$role}{$access}})) {
8331: push(@shown,$othertitle);
8332: }
8333: if (@shown) {
8334: my $shownstatus = join(' '.&mt('or').' ',@shown);
1.432 raeburn 8335: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role, and institutional status: [_3]',
8336: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'),$shownstatus);
1.428 raeburn 8337: } else {
8338: $domusage{$role} = &mt('No one in the domain');
8339: }
8340: }
8341: } elsif ($access eq 'inc') {
8342: my @dominc = ();
8343: if (ref($domcurrent->{$role}{'inc'}) eq 'ARRAY') {
8344: foreach my $user (@{$domcurrent->{$role}{'inc'}}) {
8345: my ($uname,$udom) = split(/:/,$user);
8346: push(@dominc,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),$uname,$udom));
8347: }
8348: my $showninc = join(', ',@dominc);
8349: if ($showninc ne '') {
1.432 raeburn 8350: $domusage{$role} = &mt('Include any user in domain with active [_1] or [_2] role, except: [_3]',
8351: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'),$showninc);
1.428 raeburn 8352: } else {
1.432 raeburn 8353: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role',
8354: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'));
1.428 raeburn 8355: }
8356: }
8357: } elsif ($access eq 'exc') {
8358: my @domexc = ();
8359: if (ref($domcurrent->{$role}{'exc'}) eq 'ARRAY') {
8360: foreach my $user (@{$domcurrent->{$role}{'exc'}}) {
8361: my ($uname,$udom) = split(/:/,$user);
8362: push(@domexc,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),$uname,$udom));
8363: }
8364: }
8365: my $shownexc = join(', ',@domexc);
8366: if ($shownexc ne '') {
1.432 raeburn 8367: $domusage{$role} = &mt('Only the following in the domain with active [_1] or [_2] role: [_3]',
8368: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'),$shownexc);
1.428 raeburn 8369: } else {
8370: $domusage{$role} = &mt('No one in the domain');
8371: }
8372: } elsif ($access eq 'none') {
8373: $domusage{$role} = &mt('No one in the domain');
1.434 raeburn 8374: } elsif ($access eq 'dh') {
1.433 raeburn 8375: $domusage{$role} = &mt('Any user in domain with active [_1] role',&Apache::lonnet::plaintext('dh'));
1.434 raeburn 8376: } elsif ($access eq 'da') {
1.433 raeburn 8377: $domusage{$role} = &mt('Any user in domain with active [_1] role',&Apache::lonnet::plaintext('da'));
1.428 raeburn 8378: } elsif ($access eq 'all') {
1.432 raeburn 8379: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role',
8380: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'));
1.428 raeburn 8381: }
8382: } else {
1.432 raeburn 8383: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role',
8384: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'));
1.428 raeburn 8385: }
8386: }
8387: return %domusage;
8388: }
8389:
8390: sub get_domain_customroles {
8391: my ($cdom,$confname) = @_;
8392: my %existing=&Apache::lonnet::dump('roles',$cdom,$confname,'rolesdef_');
8393: my %customroles;
8394: foreach my $key (keys(%existing)) {
8395: if ($key=~/^rolesdef\_(\w+)$/) {
8396: my $rolename = $1;
8397: my %privs;
8398: ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
8399: $customroles{$rolename} = \%privs;
8400: }
8401: }
8402: return %customroles;
8403: }
8404:
8405: sub role_priv_table {
8406: my ($role,$permission,$crstype,$full,$levels,$levelscurrent,$overridden) = @_;
8407: return unless ((ref($full) eq 'HASH') && (ref($levels) eq 'HASH') &&
8408: (ref($levelscurrent) eq 'HASH'));
8409: my %lt=&Apache::lonlocal::texthash (
8410: 'crl' => 'Course Level Privilege',
8411: 'def' => 'Domain Defaults',
8412: 'ove' => 'Override in Course',
8413: 'ine' => 'In effect',
8414: 'dis' => 'Disabled',
8415: 'ena' => 'Enabled',
8416: );
8417: if ($crstype eq 'Community') {
8418: $lt{'ove'} = 'Override in Community',
8419: }
8420: my @status = ('Disabled','Enabled');
8421: my (%on,%off);
8422: if (ref($overridden) eq 'HASH') {
8423: if (ref($overridden->{'on'}) eq 'ARRAY') {
8424: map { $on{$_} = 1; } (@{$overridden->{'on'}});
8425: }
8426: if (ref($overridden->{'off'}) eq 'ARRAY') {
8427: map { $off{$_} = 1; } (@{$overridden->{'off'}});
8428: }
8429: }
8430: my $output=&Apache::loncommon::start_data_table().
8431: &Apache::loncommon::start_data_table_header_row().
8432: '<th>'.$lt{'crl'}.'</th><th>'.$lt{'def'}.'</th><th>'.$lt{'ove'}.
8433: '</th><th>'.$lt{'ine'}.'</th>'.
8434: &Apache::loncommon::end_data_table_header_row();
8435: foreach my $priv (sort(keys(%{$full}))) {
8436: next unless ($levels->{'course'}{$priv});
8437: my $privtext = &Apache::lonnet::plaintext($priv,$crstype);
8438: my ($default,$ineffect);
8439: if ($levelscurrent->{'course'}{$priv}) {
8440: $default = '<img src="/adm/lonIcons/navmap.correct.gif" alt="'.$lt{'ena'}.'" />';
8441: $ineffect = $default;
8442: }
8443: my ($customstatus,$checked);
8444: $output .= &Apache::loncommon::start_data_table_row().
8445: '<td>'.$privtext.'</td>'.
8446: '<td>'.$default.'</td><td>';
8447: if (($levelscurrent->{'course'}{$priv}) && ($off{$priv})) {
8448: if ($permission->{'owner'}) {
8449: $checked = ' checked="checked"';
8450: }
8451: $customstatus = '<img src="/adm/lonIcons/navmap.wrong.gif" alt="'.$lt{'dis'}.'" />';
1.430 raeburn 8452: $ineffect = $customstatus;
1.428 raeburn 8453: } elsif ((!$levelscurrent->{'course'}{$priv}) && ($on{$priv})) {
8454: if ($permission->{'owner'}) {
1.430 raeburn 8455: $checked = ' checked="checked"';
1.428 raeburn 8456: }
8457: $customstatus = '<img src="/adm/lonIcons/navmap.correct.gif" alt="'.$lt{'ena'}.'" />';
1.430 raeburn 8458: $ineffect = $customstatus;
1.428 raeburn 8459: }
8460: if ($permission->{'owner'}) {
8461: $output .= '<input type="checkbox" name="'.$role.'_override" value="'.$priv.'"'.$checked.' />';
8462: } else {
8463: $output .= $customstatus;
8464: }
8465: $output .= '</td><td>'.$ineffect.'</td>'.
8466: &Apache::loncommon::end_data_table_row();
8467: }
8468: $output .= &Apache::loncommon::end_data_table();
8469: return $output;
8470: }
8471:
8472: sub get_adhocrole_settings {
1.430 raeburn 8473: my ($cid,$accesstypes,$types,$customroles,$settings,$overridden) = @_;
1.428 raeburn 8474: return unless ((ref($accesstypes) eq 'ARRAY') && (ref($customroles) eq 'HASH') &&
8475: (ref($settings) eq 'HASH') && (ref($overridden) eq 'HASH'));
8476: foreach my $role (split(/,/,$env{'course.'.$cid.'.internal.adhocaccess'})) {
8477: my ($curraccess,$rest) = split(/=/,$env{'course.'.$cid.'.internal.adhoc.'.$role});
8478: if (($curraccess ne '') && (grep(/^\Q$curraccess\E$/,@{$accesstypes}))) {
8479: $settings->{$role}{'access'} = $curraccess;
8480: if (($curraccess eq 'status') && (ref($types) eq 'ARRAY')) {
8481: my @status = split(/,/,$rest);
8482: my @currstatus;
8483: foreach my $type (@status) {
8484: if ($type eq 'default') {
8485: push(@currstatus,$type);
8486: } elsif (grep(/^\Q$type\E$/,@{$types})) {
8487: push(@currstatus,$type);
8488: }
8489: }
8490: if (@currstatus) {
8491: $settings->{$role}{$curraccess} = \@currstatus;
8492: } elsif (($curraccess eq 'exc') || ($curraccess eq 'inc')) {
8493: my @personnel = split(/,/,$rest);
8494: $settings->{$role}{$curraccess} = \@personnel;
8495: }
8496: }
8497: }
8498: }
8499: foreach my $role (keys(%{$customroles})) {
8500: if ($env{'course.'.$cid.'.internal.adhocpriv.'.$role}) {
8501: my %currentprivs;
8502: if (ref($customroles->{$role}) eq 'HASH') {
8503: if (exists($customroles->{$role}{'course'})) {
8504: my %full=();
8505: my %levels= (
8506: course => {},
8507: domain => {},
8508: system => {},
8509: );
8510: my %levelscurrent=(
8511: course => {},
8512: domain => {},
8513: system => {},
8514: );
8515: &Apache::lonuserutils::custom_role_privs($customroles->{$role},\%full,\%levels,\%levelscurrent);
8516: %currentprivs = %{$levelscurrent{'course'}};
8517: }
8518: }
8519: foreach my $item (split(/,/,$env{'course.'.$cid.'.internal.adhocpriv.'.$role})) {
8520: next if ($item eq '');
8521: my ($rule,$rest) = split(/=/,$item);
8522: next unless (($rule eq 'off') || ($rule eq 'on'));
8523: foreach my $priv (split(/:/,$rest)) {
8524: if ($priv ne '') {
8525: if ($rule eq 'off') {
8526: push(@{$overridden->{$role}{'off'}},$priv);
8527: if ($currentprivs{$priv}) {
8528: push(@{$settings->{$role}{'off'}},$priv);
8529: }
8530: } else {
8531: push(@{$overridden->{$role}{'on'}},$priv);
8532: unless ($currentprivs{$priv}) {
8533: push(@{$settings->{$role}{'on'}},$priv);
8534: }
8535: }
8536: }
8537: }
8538: }
8539: }
8540: }
8541: return;
8542: }
8543:
8544: sub update_helpdeskaccess {
8545: my ($r,$permission,$brcrum) = @_;
8546: my $helpitem = 'Course_Helpdesk_Access';
8547: push (@{$brcrum},
8548: {href => '/adm/createuser?action=helpdesk',
8549: text => 'Helpdesk Access',
8550: help => $helpitem},
8551: {href => '/adm/createuser?action=helpdesk',
8552: text => 'Result',
8553: help => $helpitem}
8554: );
8555: my $bread_crumbs_component = 'Helpdesk Staff Access';
8556: my $args = { bread_crumbs => $brcrum,
8557: bread_crumbs_component => $bread_crumbs_component};
8558:
8559: # print page header
8560: $r->print(&header('',$args));
8561: unless ((ref($permission) eq 'HASH') && ($permission->{'owner'})) {
8562: $r->print('<p class="LC_error">'.&mt('You do not have permission to change helpdesk access.').'</p>');
8563: return;
8564: }
1.434 raeburn 8565: my @accesstypes = ('all','dh','da','none','status','inc','exc');
1.428 raeburn 8566: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
8567: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
8568: my $confname = $cdom.'-domainconfig';
8569: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($cdom);
8570: my $crstype = &Apache::loncommon::course_type();
8571: my %customroles = &get_domain_customroles($cdom,$confname);
8572: my (%settings,%overridden);
8573: &get_adhocrole_settings($env{'request.course.id'},\@accesstypes,
8574: $types,\%customroles,\%settings,\%overridden);
1.432 raeburn 8575: my %domhelpdesk = &Apache::lonnet::get_active_domroles($cdom,['dh','da']);
1.428 raeburn 8576: my (%changed,%storehash,@todelete);
8577:
8578: if (keys(%customroles)) {
8579: my (%newsettings,@incrs);
8580: foreach my $role (keys(%customroles)) {
8581: $newsettings{$role} = {
8582: access => '',
8583: status => '',
8584: exc => '',
8585: inc => '',
8586: on => '',
8587: off => '',
8588: };
8589: my %current;
8590: if (ref($settings{$role}) eq 'HASH') {
8591: %current = %{$settings{$role}};
8592: }
8593: if (ref($overridden{$role}) eq 'HASH') {
8594: $current{'overridden'} = $overridden{$role};
8595: }
8596: if ($env{'form.'.$role.'_incrs'}) {
8597: my $access = $env{'form.'.$role.'_access'};
8598: if (grep(/^\Q$access\E$/,@accesstypes)) {
8599: push(@incrs,$role);
8600: unless ($current{'access'} eq $access) {
8601: $changed{$role}{'access'} = 1;
1.430 raeburn 8602: $storehash{'internal.adhoc.'.$role} = $access;
1.428 raeburn 8603: }
8604: if ($access eq 'status') {
8605: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$role.'_status');
8606: my @stored;
8607: my @shownstatus;
8608: if (ref($types) eq 'ARRAY') {
8609: foreach my $type (sort(@statuses)) {
8610: if ($type eq 'default') {
8611: push(@stored,$type);
8612: } elsif (grep(/^\Q$type\E$/,@{$types})) {
8613: push(@stored,$type);
8614: push(@shownstatus,$usertypes->{$type});
8615: }
8616: }
8617: if (grep(/^default$/,@statuses)) {
8618: push(@shownstatus,$othertitle);
8619: }
8620: $storehash{'internal.adhoc.'.$role} .= '='.join(',',@stored);
8621: }
8622: $newsettings{$role}{'status'} = join(' '.&mt('or').' ',@shownstatus);
8623: if (ref($current{'status'}) eq 'ARRAY') {
8624: my @diffs = &Apache::loncommon::compare_arrays(\@stored,$current{'status'});
8625: if (@diffs) {
8626: $changed{$role}{'status'} = 1;
8627: }
8628: } elsif (@stored) {
8629: $changed{$role}{'status'} = 1;
8630: }
8631: } elsif (($access eq 'inc') || ($access eq 'exc')) {
8632: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$role.'_staff_'.$access);
8633: my @newspecstaff;
8634: my @stored;
8635: my @currstaff;
8636: foreach my $person (sort(@personnel)) {
8637: if ($domhelpdesk{$person}) {
1.430 raeburn 8638: push(@stored,$person);
1.428 raeburn 8639: }
8640: }
8641: if (ref($current{$access}) eq 'ARRAY') {
8642: my @diffs = &Apache::loncommon::compare_arrays(\@stored,$current{$access});
8643: if (@diffs) {
8644: $changed{$role}{$access} = 1;
8645: }
8646: } elsif (@stored) {
8647: $changed{$role}{$access} = 1;
8648: }
8649: $storehash{'internal.adhoc.'.$role} .= '='.join(',',@stored);
8650: foreach my $person (@stored) {
8651: my ($uname,$udom) = split(/:/,$person);
8652: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
8653: }
8654: $newsettings{$role}{$access} = join(', ',sort(@newspecstaff));
8655: }
8656: $newsettings{$role}{'access'} = $access;
8657: }
8658: } else {
8659: if (($current{'access'} ne '') && (grep(/^\Q$current{'access'}\E$/,@accesstypes))) {
8660: $changed{$role}{'access'} = 1;
8661: $newsettings{$role} = {};
8662: push(@todelete,'internal.adhoc.'.$role);
8663: }
8664: }
8665: if (($env{'form.'.$role.'_incrs'}) && ($env{'form.'.$role.'_access'} eq 'none')) {
8666: if (ref($current{'overridden'}) eq 'HASH') {
8667: push(@todelete,'internal.adhocpriv.'.$role);
8668: }
8669: } else {
8670: my %full=();
8671: my %levels= (
8672: course => {},
8673: domain => {},
8674: system => {},
8675: );
8676: my %levelscurrent=(
8677: course => {},
8678: domain => {},
8679: system => {},
8680: );
8681: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
8682: my (@updatedon,@updatedoff,@override);
8683: @override = &Apache::loncommon::get_env_multiple('form.'.$role.'_override');
1.430 raeburn 8684: if (@override) {
1.428 raeburn 8685: foreach my $priv (sort(keys(%full))) {
8686: next unless ($levels{'course'}{$priv});
8687: if (grep(/^\Q$priv\E$/,@override)) {
8688: if ($levelscurrent{'course'}{$priv}) {
8689: push(@updatedoff,$priv);
8690: } else {
8691: push(@updatedon,$priv);
8692: }
8693: }
8694: }
8695: }
8696: if (@updatedon) {
1.430 raeburn 8697: $newsettings{$role}{'on'} = join('</li><li>', map { &Apache::lonnet::plaintext($_,$crstype) } (@updatedon));
1.428 raeburn 8698: }
8699: if (@updatedoff) {
8700: $newsettings{$role}{'off'} = join('</li><li>', map { &Apache::lonnet::plaintext($_,$crstype) } (@updatedoff));
8701: }
8702: if (ref($current{'overridden'}) eq 'HASH') {
8703: if (ref($current{'overridden'}{'on'}) eq 'ARRAY') {
8704: if (@updatedon) {
8705: my @diffs = &Apache::loncommon::compare_arrays(\@updatedon,$current{'overridden'}{'on'});
8706: if (@diffs) {
8707: $changed{$role}{'on'} = 1;
8708: }
8709: } else {
8710: $changed{$role}{'on'} = 1;
8711: }
8712: } elsif (@updatedon) {
8713: $changed{$role}{'on'} = 1;
8714: }
8715: if (ref($current{'overridden'}{'off'}) eq 'ARRAY') {
8716: if (@updatedoff) {
8717: my @diffs = &Apache::loncommon::compare_arrays(\@updatedoff,$current{'overridden'}{'off'});
8718: if (@diffs) {
8719: $changed{$role}{'off'} = 1;
8720: }
8721: } else {
8722: $changed{$role}{'off'} = 1;
8723: }
8724: } elsif (@updatedoff) {
8725: $changed{$role}{'off'} = 1;
8726: }
8727: } else {
8728: if (@updatedon) {
8729: $changed{$role}{'on'} = 1;
8730: }
8731: if (@updatedoff) {
8732: $changed{$role}{'off'} = 1;
8733: }
8734: }
8735: if (ref($changed{$role}) eq 'HASH') {
8736: if (($changed{$role}{'on'} || $changed{$role}{'off'})) {
8737: my $newpriv;
8738: if (@updatedon) {
8739: $newpriv = 'on='.join(':',@updatedon);
8740: }
8741: if (@updatedoff) {
8742: $newpriv .= ($newpriv ? ',' : '' ).'off='.join(':',@updatedoff);
8743: }
8744: if ($newpriv eq '') {
8745: push(@todelete,'internal.adhocpriv.'.$role);
8746: } else {
8747: $storehash{'internal.adhocpriv.'.$role} = $newpriv;
8748: }
8749: }
8750: }
8751: }
8752: }
8753: if (@incrs) {
8754: $storehash{'internal.adhocaccess'} = join(',',@incrs);
8755: } elsif (@todelete) {
8756: push(@todelete,'internal.adhocaccess');
8757: }
8758: if (keys(%changed)) {
8759: my ($putres,$delres);
8760: if (keys(%storehash)) {
8761: $putres = &Apache::lonnet::put('environment',\%storehash,$cdom,$cnum);
8762: my %newenvhash;
8763: foreach my $key (keys(%storehash)) {
8764: $newenvhash{'course.'.$env{'request.course.id'}.'.'.$key} = $storehash{$key};
8765: }
8766: &Apache::lonnet::appenv(\%newenvhash);
8767: }
8768: if (@todelete) {
8769: $delres = &Apache::lonnet::del('environment',\@todelete,$cdom,$cnum);
8770: foreach my $key (@todelete) {
8771: &Apache::lonnet::delenv('course.'.$env{'request.course.id'}.'.'.$key);
8772: }
8773: }
8774: if (($putres eq 'ok') || ($delres eq 'ok')) {
8775: my %domconfig = &Apache::lonnet::get_dom('configuration',['helpsettings'],$cdom);
8776: my (%domcurrent,%ordered,%description,%domusage);
8777: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
8778: if (ref($domconfig{'helpsettings'}{'adhoc'}) eq 'HASH') {
8779: %domcurrent = %{$domconfig{'helpsettings'}{'adhoc'}};
8780: }
8781: }
8782: my $count = 0;
8783: foreach my $role (sort(keys(%customroles))) {
8784: my ($order,$desc);
8785: if (ref($domcurrent{$role}) eq 'HASH') {
8786: $order = $domcurrent{$role}{'order'};
8787: $desc = $domcurrent{$role}{'desc'};
8788: }
8789: if ($order eq '') {
8790: $order = $count;
8791: }
8792: $ordered{$order} = $role;
8793: if ($desc ne '') {
8794: $description{$role} = $desc;
8795: } else {
8796: $description{$role}= $role;
8797: }
8798: $count++;
8799: }
8800: my @roles_by_num = ();
8801: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
8802: push(@roles_by_num,$ordered{$item});
8803: }
8804: %domusage = &domain_adhoc_access(\%changed,\%domcurrent,\@accesstypes,$usertypes,$othertitle);
1.430 raeburn 8805: $r->print(&mt('Helpdesk access settings have been changed as follows').'<br />');
1.428 raeburn 8806: $r->print('<ul>');
8807: foreach my $role (@roles_by_num) {
8808: next unless (ref($changed{$role}) eq 'HASH');
8809: $r->print('<li>'.&mt('Ad hoc role').': <b>'.$description{$role}.'</b>'.
8810: '<ul>');
1.430 raeburn 8811: if ($changed{$role}{'access'} || $changed{$role}{'status'} || $changed{$role}{'inc'} || $changed{$role}{'exc'}) {
1.428 raeburn 8812: $r->print('<li>');
8813: if ($env{'form.'.$role.'_incrs'}) {
8814: if ($newsettings{$role}{'access'} eq 'all') {
8815: $r->print(&mt('All helpdesk staff can access '.lc($crstype).' with this role.'));
1.434 raeburn 8816: } elsif ($newsettings{$role}{'access'} eq 'dh') {
1.433 raeburn 8817: $r->print(&mt('Helpdesk staff can use this role if they have an active [_1] role',
8818: &Apache::lonnet::plaintext('dh')));
1.434 raeburn 8819: } elsif ($newsettings{$role}{'access'} eq 'da') {
1.433 raeburn 8820: $r->print(&mt('Helpdesk staff can use this role if they have an active [_1] role',
8821: &Apache::lonnet::plaintext('da')));
1.428 raeburn 8822: } elsif ($newsettings{$role}{'access'} eq 'none') {
8823: $r->print(&mt('No helpdesk staff can access '.lc($crstype).' with this role.'));
8824: } elsif ($newsettings{$role}{'access'} eq 'status') {
8825: if ($newsettings{$role}{'status'}) {
8826: my ($access,$rest) = split(/=/,$storehash{'internal.adhoc.'.$role});
1.430 raeburn 8827: if (split(/,/,$rest) > 1) {
1.428 raeburn 8828: $r->print(&mt('Helpdesk staff can use this role if their institutional type is one of: [_1].',
8829: $newsettings{$role}{'status'}));
8830: } else {
8831: $r->print(&mt('Helpdesk staff can use this role if their institutional type is: [_1].',
8832: $newsettings{$role}{'status'}));
8833: }
8834: } else {
8835: $r->print(&mt('No helpdesk staff can access '.lc($crstype).' with this role.'));
8836: }
8837: } elsif ($newsettings{$role}{'access'} eq 'exc') {
8838: if ($newsettings{$role}{'exc'}) {
8839: $r->print(&mt('Helpdesk staff who can use this role are as follows:').' '.$newsettings{$role}{'exc'}.'.');
8840: } else {
8841: $r->print(&mt('No helpdesk staff can access '.lc($crstype).' with this role.'));
8842: }
8843: } elsif ($newsettings{$role}{'access'} eq 'inc') {
8844: if ($newsettings{$role}{'inc'}) {
8845: $r->print(&mt('All helpdesk staff may use this role except the following:').' '.$newsettings{$role}{'inc'}.'.');
8846: } else {
8847: $r->print(&mt('All helpdesk staff may use this role.'));
8848: }
8849: }
8850: } else {
8851: $r->print(&mt('Default access set in the domain now applies.').'<br />'.
8852: '<span class="LC_cusr_emph">'.$domusage{$role}.'</span>');
8853: }
8854: $r->print('</li>');
8855: }
8856: unless ($newsettings{$role}{'access'} eq 'none') {
8857: if ($changed{$role}{'off'}) {
8858: if ($newsettings{$role}{'off'}) {
8859: $r->print('<li>'.&mt('Privileges which are available by default for this ad hoc role, but are disabled for this specific '.lc($crstype).':').
8860: '<ul><li>'.$newsettings{$role}{'off'}.'</li></ul></li>');
8861: } else {
1.430 raeburn 8862: $r->print('<li>'.&mt('All privileges available by default for this ad hoc role are enabled.').'</li>');
1.428 raeburn 8863: }
8864: }
1.430 raeburn 8865: if ($changed{$role}{'on'}) {
1.428 raeburn 8866: if ($newsettings{$role}{'on'}) {
8867: $r->print('<li>'.&mt('Privileges which are not available by default for this ad hoc role, but are enabled for this specific '.lc($crstype).':').
8868: '<ul><li>'.$newsettings{$role}{'on'}.'</li></ul></li>');
8869: } else {
1.430 raeburn 8870: $r->print('<li>'.&mt('None of the privileges unavailable by default for this ad hoc role are enabled.').'</li>');
1.428 raeburn 8871: }
8872: }
8873: }
8874: $r->print('</ul></li>');
8875: }
8876: $r->print('</ul>');
8877: }
8878: } else {
1.430 raeburn 8879: $r->print(&mt('No changes made to helpdesk access settings.'));
1.428 raeburn 8880: }
8881: }
8882: return;
8883: }
8884:
1.27 matthew 8885: #-------------------------------------------------- functions for &phase_two
1.160 raeburn 8886: sub user_search_result {
1.221 raeburn 8887: my ($context,$srch) = @_;
1.160 raeburn 8888: my %allhomes;
8889: my %inst_matches;
8890: my %srch_results;
1.181 raeburn 8891: my ($response,$currstate,$forcenewuser,$dirsrchres);
1.183 raeburn 8892: $srch->{'srchterm'} =~ s/\s+/ /g;
1.176 raeburn 8893: if ($srch->{'srchby'} !~ /^(uname|lastname|lastfirst)$/) {
1.160 raeburn 8894: $response = &mt('Invalid search.');
8895: }
8896: if ($srch->{'srchin'} !~ /^(crs|dom|alc|instd)$/) {
8897: $response = &mt('Invalid search.');
8898: }
1.177 raeburn 8899: if ($srch->{'srchtype'} !~ /^(exact|contains|begins)$/) {
1.160 raeburn 8900: $response = &mt('Invalid search.');
8901: }
8902: if ($srch->{'srchterm'} eq '') {
8903: $response = &mt('You must enter a search term.');
8904: }
1.183 raeburn 8905: if ($srch->{'srchterm'} =~ /^\s+$/) {
8906: $response = &mt('Your search term must contain more than just spaces.');
8907: }
1.160 raeburn 8908: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'instd')) {
8909: if (($srch->{'srchdomain'} eq '') ||
1.163 albertel 8910: ! (&Apache::lonnet::domain($srch->{'srchdomain'}))) {
1.160 raeburn 8911: $response = &mt('You must specify a valid domain when searching in a domain or institutional directory.')
8912: }
8913: }
8914: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs') ||
8915: ($srch->{'srchin'} eq 'alc')) {
1.176 raeburn 8916: if ($srch->{'srchby'} eq 'uname') {
1.243 raeburn 8917: my $unamecheck = $srch->{'srchterm'};
8918: if ($srch->{'srchtype'} eq 'contains') {
8919: if ($unamecheck !~ /^\w/) {
8920: $unamecheck = 'a'.$unamecheck;
8921: }
8922: }
8923: if ($unamecheck !~ /^$match_username$/) {
1.176 raeburn 8924: $response = &mt('You must specify a valid username. Only the following are allowed: letters numbers - . @');
8925: }
1.160 raeburn 8926: }
8927: }
1.180 raeburn 8928: if ($response ne '') {
1.413 raeburn 8929: $response = '<span class="LC_warning">'.$response.'</span><br />';
1.180 raeburn 8930: }
1.160 raeburn 8931: if ($srch->{'srchin'} eq 'instd') {
1.412 raeburn 8932: my $instd_chk = &instdirectorysrch_check($srch);
1.160 raeburn 8933: if ($instd_chk ne 'ok') {
1.412 raeburn 8934: my $domd_chk = &domdirectorysrch_check($srch);
1.413 raeburn 8935: $response .= '<span class="LC_warning">'.$instd_chk.'</span><br />';
1.412 raeburn 8936: if ($domd_chk eq 'ok') {
1.435 raeburn 8937: $response .= &mt('You may want to search in the LON-CAPA domain instead of in the institutional directory.');
1.412 raeburn 8938: }
1.415 raeburn 8939: $response .= '<br />';
1.412 raeburn 8940: }
8941: } else {
1.417 raeburn 8942: unless (($context eq 'requestcrs') && ($srch->{'srchtype'} eq 'exact')) {
1.412 raeburn 8943: my $domd_chk = &domdirectorysrch_check($srch);
1.438 raeburn 8944: if (($domd_chk ne 'ok') && ($env{'form.action'} ne 'accesslogs')) {
1.412 raeburn 8945: my $instd_chk = &instdirectorysrch_check($srch);
1.413 raeburn 8946: $response .= '<span class="LC_warning">'.$domd_chk.'</span><br />';
1.412 raeburn 8947: if ($instd_chk eq 'ok') {
1.435 raeburn 8948: $response .= &mt('You may want to search in the institutional directory instead of in the LON-CAPA domain.');
1.412 raeburn 8949: }
1.415 raeburn 8950: $response .= '<br />';
1.412 raeburn 8951: }
1.160 raeburn 8952: }
8953: }
8954: if ($response ne '') {
1.180 raeburn 8955: return ($currstate,$response);
1.160 raeburn 8956: }
8957: if ($srch->{'srchby'} eq 'uname') {
8958: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs')) {
8959: if ($env{'form.forcenew'}) {
8960: if ($srch->{'srchdomain'} ne $env{'request.role.domain'}) {
8961: my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
8962: if ($uhome eq 'no_host') {
8963: my $domdesc = &Apache::lonnet::domain($env{'request.role.domain'},'description');
1.180 raeburn 8964: my $showdom = &display_domain_info($env{'request.role.domain'});
8965: $response = &mt('New users can only be created in the domain to which your current role belongs - [_1].',$showdom);
1.160 raeburn 8966: } else {
1.179 raeburn 8967: $currstate = 'modify';
1.160 raeburn 8968: }
8969: } else {
1.179 raeburn 8970: $currstate = 'modify';
1.160 raeburn 8971: }
8972: } else {
8973: if ($srch->{'srchin'} eq 'dom') {
1.162 raeburn 8974: if ($srch->{'srchtype'} eq 'exact') {
8975: my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
8976: if ($uhome eq 'no_host') {
1.179 raeburn 8977: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8978: &build_search_response($context,$srch,%srch_results);
1.162 raeburn 8979: } else {
1.179 raeburn 8980: $currstate = 'modify';
1.416 raeburn 8981: if ($env{'form.action'} eq 'accesslogs') {
8982: $currstate = 'activity';
8983: }
1.310 raeburn 8984: my $uname = $srch->{'srchterm'};
8985: my $udom = $srch->{'srchdomain'};
8986: $srch_results{$uname.':'.$udom} =
8987: { &Apache::lonnet::get('environment',
8988: ['firstname',
8989: 'lastname',
8990: 'permanentemail'],
8991: $udom,$uname)
8992: };
1.162 raeburn 8993: }
8994: } else {
8995: %srch_results = &Apache::lonnet::usersearch($srch);
1.179 raeburn 8996: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8997: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 8998: }
8999: } else {
1.167 albertel 9000: my $courseusers = &get_courseusers();
1.162 raeburn 9001: if ($srch->{'srchtype'} eq 'exact') {
1.167 albertel 9002: if (exists($courseusers->{$srch->{'srchterm'}.':'.$srch->{'srchdomain'}})) {
1.179 raeburn 9003: $currstate = 'modify';
1.162 raeburn 9004: } else {
1.179 raeburn 9005: ($currstate,$response,$forcenewuser) =
1.221 raeburn 9006: &build_search_response($context,$srch,%srch_results);
1.162 raeburn 9007: }
1.160 raeburn 9008: } else {
1.167 albertel 9009: foreach my $user (keys(%$courseusers)) {
1.162 raeburn 9010: my ($cuname,$cudomain) = split(/:/,$user);
9011: if ($cudomain eq $srch->{'srchdomain'}) {
1.177 raeburn 9012: my $matched = 0;
9013: if ($srch->{'srchtype'} eq 'begins') {
9014: if ($cuname =~ /^\Q$srch->{'srchterm'}\E/i) {
9015: $matched = 1;
9016: }
9017: } else {
9018: if ($cuname =~ /\Q$srch->{'srchterm'}\E/i) {
9019: $matched = 1;
9020: }
9021: }
9022: if ($matched) {
1.167 albertel 9023: $srch_results{$user} =
9024: {&Apache::lonnet::get('environment',
9025: ['firstname',
9026: 'lastname',
1.194 albertel 9027: 'permanentemail'],
9028: $cudomain,$cuname)};
1.162 raeburn 9029: }
9030: }
9031: }
1.179 raeburn 9032: ($currstate,$response,$forcenewuser) =
1.221 raeburn 9033: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 9034: }
9035: }
9036: }
9037: } elsif ($srch->{'srchin'} eq 'alc') {
1.179 raeburn 9038: $currstate = 'query';
1.160 raeburn 9039: } elsif ($srch->{'srchin'} eq 'instd') {
1.181 raeburn 9040: ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
9041: if ($dirsrchres eq 'ok') {
9042: ($currstate,$response,$forcenewuser) =
1.221 raeburn 9043: &build_search_response($context,$srch,%srch_results);
1.181 raeburn 9044: } else {
9045: my $showdom = &display_domain_info($srch->{'srchdomain'});
9046: $response = '<span class="LC_warning">'.
9047: &mt('Institutional directory search is not available in domain: [_1]',$showdom).
9048: '</span><br />'.
1.435 raeburn 9049: &mt('You may want to search in the LON-CAPA domain instead of in the institutional directory.').
1.415 raeburn 9050: '<br />';
1.181 raeburn 9051: }
1.160 raeburn 9052: }
9053: } else {
9054: if ($srch->{'srchin'} eq 'dom') {
9055: %srch_results = &Apache::lonnet::usersearch($srch);
1.179 raeburn 9056: ($currstate,$response,$forcenewuser) =
1.221 raeburn 9057: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 9058: } elsif ($srch->{'srchin'} eq 'crs') {
1.167 albertel 9059: my $courseusers = &get_courseusers();
9060: foreach my $user (keys(%$courseusers)) {
1.160 raeburn 9061: my ($uname,$udom) = split(/:/,$user);
9062: my %names = &Apache::loncommon::getnames($uname,$udom);
9063: my %emails = &Apache::loncommon::getemails($uname,$udom);
9064: if ($srch->{'srchby'} eq 'lastname') {
9065: if ((($srch->{'srchtype'} eq 'exact') &&
9066: ($names{'lastname'} eq $srch->{'srchterm'})) ||
1.177 raeburn 9067: (($srch->{'srchtype'} eq 'begins') &&
9068: ($names{'lastname'} =~ /^\Q$srch->{'srchterm'}\E/i)) ||
1.160 raeburn 9069: (($srch->{'srchtype'} eq 'contains') &&
9070: ($names{'lastname'} =~ /\Q$srch->{'srchterm'}\E/i))) {
9071: $srch_results{$user} = {firstname => $names{'firstname'},
9072: lastname => $names{'lastname'},
9073: permanentemail => $emails{'permanentemail'},
9074: };
9075: }
9076: } elsif ($srch->{'srchby'} eq 'lastfirst') {
9077: my ($srchlast,$srchfirst) = split(/,/,$srch->{'srchterm'});
1.177 raeburn 9078: $srchlast =~ s/\s+$//;
9079: $srchfirst =~ s/^\s+//;
1.160 raeburn 9080: if ($srch->{'srchtype'} eq 'exact') {
9081: if (($names{'lastname'} eq $srchlast) &&
9082: ($names{'firstname'} eq $srchfirst)) {
9083: $srch_results{$user} = {firstname => $names{'firstname'},
9084: lastname => $names{'lastname'},
9085: permanentemail => $emails{'permanentemail'},
9086:
9087: };
9088: }
1.177 raeburn 9089: } elsif ($srch->{'srchtype'} eq 'begins') {
9090: if (($names{'lastname'} =~ /^\Q$srchlast\E/i) &&
9091: ($names{'firstname'} =~ /^\Q$srchfirst\E/i)) {
9092: $srch_results{$user} = {firstname => $names{'firstname'},
9093: lastname => $names{'lastname'},
9094: permanentemail => $emails{'permanentemail'},
9095: };
9096: }
9097: } else {
1.160 raeburn 9098: if (($names{'lastname'} =~ /\Q$srchlast\E/i) &&
9099: ($names{'firstname'} =~ /\Q$srchfirst\E/i)) {
9100: $srch_results{$user} = {firstname => $names{'firstname'},
9101: lastname => $names{'lastname'},
9102: permanentemail => $emails{'permanentemail'},
9103: };
9104: }
9105: }
9106: }
9107: }
1.179 raeburn 9108: ($currstate,$response,$forcenewuser) =
1.221 raeburn 9109: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 9110: } elsif ($srch->{'srchin'} eq 'alc') {
1.179 raeburn 9111: $currstate = 'query';
1.160 raeburn 9112: } elsif ($srch->{'srchin'} eq 'instd') {
1.181 raeburn 9113: ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
9114: if ($dirsrchres eq 'ok') {
9115: ($currstate,$response,$forcenewuser) =
1.221 raeburn 9116: &build_search_response($context,$srch,%srch_results);
1.181 raeburn 9117: } else {
1.412 raeburn 9118: my $showdom = &display_domain_info($srch->{'srchdomain'});
9119: $response = '<span class="LC_warning">'.
1.181 raeburn 9120: &mt('Institutional directory search is not available in domain: [_1]',$showdom).
9121: '</span><br />'.
1.435 raeburn 9122: &mt('You may want to search in the LON-CAPA domain instead of in the institutional directory.').
1.415 raeburn 9123: '<br />';
1.181 raeburn 9124: }
1.160 raeburn 9125: }
9126: }
1.179 raeburn 9127: return ($currstate,$response,$forcenewuser,\%srch_results);
1.160 raeburn 9128: }
9129:
1.412 raeburn 9130: sub domdirectorysrch_check {
9131: my ($srch) = @_;
9132: my $response;
9133: my %dom_inst_srch = &Apache::lonnet::get_dom('configuration',
9134: ['directorysrch'],$srch->{'srchdomain'});
9135: my $showdom = &display_domain_info($srch->{'srchdomain'});
9136: if (ref($dom_inst_srch{'directorysrch'}) eq 'HASH') {
9137: if ($dom_inst_srch{'directorysrch'}{'lcavailable'} eq '0') {
9138: return &mt('LON-CAPA directory search is not available in domain: [_1]',$showdom);
9139: }
9140: if ($dom_inst_srch{'directorysrch'}{'lclocalonly'}) {
9141: if ($env{'request.role.domain'} ne $srch->{'srchdomain'}) {
9142: return &mt('LON-CAPA directory search in domain: [_1] is only allowed for users with a current role in the domain.',$showdom);
9143: }
9144: }
9145: }
9146: return 'ok';
9147: }
9148:
9149: sub instdirectorysrch_check {
1.160 raeburn 9150: my ($srch) = @_;
9151: my $can_search = 0;
9152: my $response;
9153: my %dom_inst_srch = &Apache::lonnet::get_dom('configuration',
9154: ['directorysrch'],$srch->{'srchdomain'});
1.180 raeburn 9155: my $showdom = &display_domain_info($srch->{'srchdomain'});
1.160 raeburn 9156: if (ref($dom_inst_srch{'directorysrch'}) eq 'HASH') {
9157: if (!$dom_inst_srch{'directorysrch'}{'available'}) {
1.180 raeburn 9158: return &mt('Institutional directory search is not available in domain: [_1]',$showdom);
1.160 raeburn 9159: }
9160: if ($dom_inst_srch{'directorysrch'}{'localonly'}) {
9161: if ($env{'request.role.domain'} ne $srch->{'srchdomain'}) {
1.180 raeburn 9162: return &mt('Institutional directory search in domain: [_1] is only allowed for users with a current role in the domain.',$showdom);
1.160 raeburn 9163: }
9164: my @usertypes = split(/:/,$env{'environment.inststatus'});
9165: if (!@usertypes) {
9166: push(@usertypes,'default');
9167: }
9168: if (ref($dom_inst_srch{'directorysrch'}{'cansearch'}) eq 'ARRAY') {
9169: foreach my $type (@usertypes) {
9170: if (grep(/^\Q$type\E$/,@{$dom_inst_srch{'directorysrch'}{'cansearch'}})) {
9171: $can_search = 1;
9172: last;
9173: }
9174: }
9175: }
9176: if (!$can_search) {
9177: my ($insttypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($srch->{'srchdomain'});
9178: my @longtypes;
9179: foreach my $item (@usertypes) {
1.229 raeburn 9180: if (defined($insttypes->{$item})) {
9181: push (@longtypes,$insttypes->{$item});
9182: } elsif ($item eq 'default') {
9183: push (@longtypes,&mt('other'));
9184: }
1.160 raeburn 9185: }
9186: my $insttype_str = join(', ',@longtypes);
1.180 raeburn 9187: return &mt('Institutional directory search in domain: [_1] is not available to your user type: ',$showdom).$insttype_str;
1.229 raeburn 9188: }
1.160 raeburn 9189: } else {
9190: $can_search = 1;
9191: }
9192: } else {
1.180 raeburn 9193: return &mt('Institutional directory search has not been configured for domain: [_1]',$showdom);
1.160 raeburn 9194: }
9195: my %longtext = &Apache::lonlocal::texthash (
1.167 albertel 9196: uname => 'username',
1.160 raeburn 9197: lastfirst => 'last name, first name',
1.167 albertel 9198: lastname => 'last name',
1.172 raeburn 9199: contains => 'contains',
1.178 raeburn 9200: exact => 'as exact match to',
9201: begins => 'begins with',
1.160 raeburn 9202: );
9203: if ($can_search) {
9204: if (ref($dom_inst_srch{'directorysrch'}{'searchby'}) eq 'ARRAY') {
9205: if (!grep(/^\Q$srch->{'srchby'}\E$/,@{$dom_inst_srch{'directorysrch'}{'searchby'}})) {
1.180 raeburn 9206: return &mt('Institutional directory search in domain: [_1] is not available for searching by "[_2]"',$showdom,$longtext{$srch->{'srchby'}});
1.160 raeburn 9207: }
9208: } else {
1.180 raeburn 9209: return &mt('Institutional directory search in domain: [_1] is not available.', $showdom);
1.160 raeburn 9210: }
9211: }
9212: if ($can_search) {
1.178 raeburn 9213: if (ref($dom_inst_srch{'directorysrch'}{'searchtypes'}) eq 'ARRAY') {
9214: if (grep(/^\Q$srch->{'srchtype'}\E/,@{$dom_inst_srch{'directorysrch'}{'searchtypes'}})) {
9215: return 'ok';
9216: } else {
1.180 raeburn 9217: return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
1.178 raeburn 9218: }
9219: } else {
9220: if ((($dom_inst_srch{'directorysrch'}{'searchtypes'} eq 'specify') &&
9221: ($srch->{'srchtype'} eq 'exact' || $srch->{'srchtype'} eq 'contains')) ||
9222: ($dom_inst_srch{'directorysrch'}{'searchtypes'} eq $srch->{'srchtype'})) {
9223: return 'ok';
9224: } else {
1.180 raeburn 9225: return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
1.178 raeburn 9226: }
1.160 raeburn 9227: }
9228: }
9229: }
9230:
9231: sub get_courseusers {
9232: my %advhash;
1.167 albertel 9233: my $classlist = &Apache::loncoursedata::get_classlist();
1.160 raeburn 9234: my %coursepersonnel=&Apache::lonnet::get_course_adv_roles();
9235: foreach my $role (sort(keys(%coursepersonnel))) {
9236: foreach my $user (split(/\,/,$coursepersonnel{$role})) {
1.167 albertel 9237: if (!exists($classlist->{$user})) {
9238: $classlist->{$user} = [];
9239: }
1.160 raeburn 9240: }
9241: }
1.167 albertel 9242: return $classlist;
1.160 raeburn 9243: }
9244:
9245: sub build_search_response {
1.221 raeburn 9246: my ($context,$srch,%srch_results) = @_;
1.179 raeburn 9247: my ($currstate,$response,$forcenewuser);
1.160 raeburn 9248: my %names = (
1.330 bisitz 9249: 'uname' => 'username',
9250: 'lastname' => 'last name',
1.160 raeburn 9251: 'lastfirst' => 'last name, first name',
1.330 bisitz 9252: 'crs' => 'this course',
9253: 'dom' => 'LON-CAPA domain',
9254: 'instd' => 'the institutional directory for domain',
1.160 raeburn 9255: );
9256:
9257: my %single = (
1.180 raeburn 9258: begins => 'A match',
1.160 raeburn 9259: contains => 'A match',
1.180 raeburn 9260: exact => 'An exact match',
1.160 raeburn 9261: );
9262: my %nomatch = (
1.180 raeburn 9263: begins => 'No match',
1.160 raeburn 9264: contains => 'No match',
1.180 raeburn 9265: exact => 'No exact match',
1.160 raeburn 9266: );
9267: if (keys(%srch_results) > 1) {
1.179 raeburn 9268: $currstate = 'select';
1.160 raeburn 9269: } else {
9270: if (keys(%srch_results) == 1) {
1.416 raeburn 9271: if ($env{'form.action'} eq 'accesslogs') {
9272: $currstate = 'activity';
9273: } else {
9274: $currstate = 'modify';
9275: }
1.180 raeburn 9276: $response = &mt("$single{$srch->{'srchtype'}} was found for the $names{$srch->{'srchby'}} ([_1]) in $names{$srch->{'srchin'}}.",$srch->{'srchterm'});
9277: if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
1.330 bisitz 9278: $response .= ': '.&display_domain_info($srch->{'srchdomain'});
1.180 raeburn 9279: }
1.330 bisitz 9280: } else { # Search has nothing found. Prepare message to user.
9281: $response = '<span class="LC_warning">';
1.180 raeburn 9282: if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
1.330 bisitz 9283: $response .= &mt("$nomatch{$srch->{'srchtype'}} found for the $names{$srch->{'srchby'}} [_1] in $names{$srch->{'srchin'}}: [_2]",
9284: '<b>'.$srch->{'srchterm'}.'</b>',
9285: &display_domain_info($srch->{'srchdomain'}));
9286: } else {
9287: $response .= &mt("$nomatch{$srch->{'srchtype'}} found for the $names{$srch->{'srchby'}} [_1] in $names{$srch->{'srchin'}}.",
9288: '<b>'.$srch->{'srchterm'}.'</b>');
1.180 raeburn 9289: }
9290: $response .= '</span>';
1.330 bisitz 9291:
1.160 raeburn 9292: if ($srch->{'srchin'} ne 'alc') {
9293: $forcenewuser = 1;
9294: my $cansrchinst = 0;
1.438 raeburn 9295: if (($srch->{'srchdomain'}) && ($env{'form.action'} ne 'accesslogs')) {
1.160 raeburn 9296: my %domconfig = &Apache::lonnet::get_dom('configuration',['directorysrch'],$srch->{'srchdomain'});
9297: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
9298: if ($domconfig{'directorysrch'}{'available'}) {
9299: $cansrchinst = 1;
9300: }
9301: }
9302: }
1.180 raeburn 9303: if ((($srch->{'srchby'} eq 'lastfirst') ||
9304: ($srch->{'srchby'} eq 'lastname')) &&
9305: ($srch->{'srchin'} eq 'dom')) {
9306: if ($cansrchinst) {
9307: $response .= '<br />'.&mt('You may want to broaden your search to a search of the institutional directory for the domain.');
1.160 raeburn 9308: }
9309: }
1.180 raeburn 9310: if ($srch->{'srchin'} eq 'crs') {
9311: $response .= '<br />'.&mt('You may want to broaden your search to the selected LON-CAPA domain.');
9312: }
9313: }
1.305 raeburn 9314: my $createdom = $env{'request.role.domain'};
9315: if ($context eq 'requestcrs') {
9316: if ($env{'form.coursedom'} ne '') {
9317: $createdom = $env{'form.coursedom'};
9318: }
9319: }
1.416 raeburn 9320: unless (($env{'form.action'} eq 'accesslogs') || (($srch->{'srchby'} eq 'uname') && ($srch->{'srchin'} eq 'dom') &&
9321: ($srch->{'srchtype'} eq 'exact') && ($srch->{'srchdomain'} eq $createdom))) {
1.221 raeburn 9322: my $cancreate =
1.305 raeburn 9323: &Apache::lonuserutils::can_create_user($createdom,$context);
9324: my $targetdom = '<span class="LC_cusr_emph">'.$createdom.'</span>';
1.221 raeburn 9325: if ($cancreate) {
1.305 raeburn 9326: my $showdom = &display_domain_info($createdom);
1.266 bisitz 9327: $response .= '<br /><br />'
9328: .'<b>'.&mt('To add a new user:').'</b>'
1.305 raeburn 9329: .'<br />';
9330: if ($context eq 'requestcrs') {
9331: $response .= &mt("(You can only define new users in the new course's domain - [_1])",$targetdom);
9332: } else {
9333: $response .= &mt("(You can only create new users in your current role's domain - [_1])",$targetdom);
9334: }
9335: $response .='<ul><li>'
1.266 bisitz 9336: .&mt("Set 'Domain/institution to search' to: [_1]",'<span class="LC_cusr_emph">'.$showdom.'</span>')
9337: .'</li><li>'
9338: .&mt("Set 'Search criteria' to: [_1]username is ..... in selected LON-CAPA domain[_2]",'<span class="LC_cusr_emph">','</span>')
9339: .'</li><li>'
9340: .&mt('Provide the proposed username')
9341: .'</li><li>'
9342: .&mt("Click 'Search'")
9343: .'</li></ul><br />';
1.221 raeburn 9344: } else {
1.422 raeburn 9345: unless (($context eq 'domain') && ($env{'form.action'} eq 'singleuser')) {
9346: my $helplink = ' href="javascript:helpMenu('."'display'".')"';
9347: $response .= '<br /><br />';
9348: if ($context eq 'requestcrs') {
9349: $response .= &mt("You are not authorized to define new users in the new course's domain - [_1].",$targetdom);
9350: } else {
9351: $response .= &mt("You are not authorized to create new users in your current role's domain - [_1].",$targetdom);
9352: }
9353: $response .= '<br />'
9354: .&mt('Please contact the [_1]helpdesk[_2] if you need to create a new user.'
9355: ,' <a'.$helplink.'>'
9356: ,'</a>')
9357: .'<br />';
1.305 raeburn 9358: }
1.221 raeburn 9359: }
1.160 raeburn 9360: }
9361: }
9362: }
1.179 raeburn 9363: return ($currstate,$response,$forcenewuser);
1.160 raeburn 9364: }
9365:
1.180 raeburn 9366: sub display_domain_info {
9367: my ($dom) = @_;
9368: my $output = $dom;
9369: if ($dom ne '') {
9370: my $domdesc = &Apache::lonnet::domain($dom,'description');
9371: if ($domdesc ne '') {
9372: $output .= ' <span class="LC_cusr_emph">('.$domdesc.')</span>';
9373: }
9374: }
9375: return $output;
9376: }
9377:
1.160 raeburn 9378: sub crumb_utilities {
9379: my %elements = (
9380: crtuser => {
9381: srchterm => 'text',
1.172 raeburn 9382: srchin => 'selectbox',
1.160 raeburn 9383: srchby => 'selectbox',
9384: srchtype => 'selectbox',
9385: srchdomain => 'selectbox',
9386: },
1.207 raeburn 9387: crtusername => {
9388: srchterm => 'text',
9389: srchdomain => 'selectbox',
9390: },
1.160 raeburn 9391: docustom => {
9392: rolename => 'selectbox',
9393: newrolename => 'textbox',
9394: },
1.179 raeburn 9395: studentform => {
9396: srchterm => 'text',
9397: srchin => 'selectbox',
9398: srchby => 'selectbox',
9399: srchtype => 'selectbox',
9400: srchdomain => 'selectbox',
9401: },
1.160 raeburn 9402: );
9403:
9404: my $jsback .= qq|
9405: function backPage(formname,prevphase,prevstate) {
1.211 raeburn 9406: if (typeof prevphase == 'undefined') {
9407: formname.phase.value = '';
9408: }
9409: else {
9410: formname.phase.value = prevphase;
9411: }
9412: if (typeof prevstate == 'undefined') {
9413: formname.currstate.value = '';
9414: }
9415: else {
9416: formname.currstate.value = prevstate;
9417: }
1.160 raeburn 9418: formname.submit();
9419: }
9420: |;
9421: return ($jsback,\%elements);
9422: }
9423:
1.26 matthew 9424: sub course_level_table {
1.375 raeburn 9425: my ($inccourses,$showcredits,$defaultcredits) = @_;
9426: return unless (ref($inccourses) eq 'HASH');
1.26 matthew 9427: my $table = '';
1.62 www 9428: # Custom Roles?
9429:
1.190 raeburn 9430: my %customroles=&Apache::lonuserutils::my_custom_roles();
1.89 raeburn 9431: my %lt=&Apache::lonlocal::texthash(
9432: 'exs' => "Existing sections",
9433: 'new' => "Define new section",
9434: 'ssd' => "Set Start Date",
9435: 'sed' => "Set End Date",
1.131 raeburn 9436: 'crl' => "Course Level",
1.89 raeburn 9437: 'act' => "Activate",
9438: 'rol' => "Role",
9439: 'ext' => "Extent",
1.113 raeburn 9440: 'grs' => "Section",
1.375 raeburn 9441: 'crd' => "Credits",
1.89 raeburn 9442: 'sta' => "Start",
9443: 'end' => "End"
9444: );
1.62 www 9445:
1.375 raeburn 9446: foreach my $protectedcourse (sort(keys(%{$inccourses}))) {
1.135 raeburn 9447: my $thiscourse=$protectedcourse;
1.26 matthew 9448: $thiscourse=~s:_:/:g;
9449: my %coursedata=&Apache::lonnet::coursedescription($thiscourse);
1.365 raeburn 9450: my $isowner = &Apache::lonuserutils::is_courseowner($protectedcourse,$coursedata{'internal.courseowner'});
1.26 matthew 9451: my $area=$coursedata{'description'};
1.321 raeburn 9452: my $crstype=$coursedata{'type'};
1.135 raeburn 9453: if (!defined($area)) { $area=&mt('Unavailable course').': '.$protectedcourse; }
1.89 raeburn 9454: my ($domain,$cnum)=split(/\//,$thiscourse);
1.115 albertel 9455: my %sections_count;
1.101 albertel 9456: if (defined($env{'request.course.id'})) {
9457: if ($env{'request.course.id'} eq $domain.'_'.$cnum) {
1.115 albertel 9458: %sections_count =
9459: &Apache::loncommon::get_sections($domain,$cnum);
1.92 raeburn 9460: }
9461: }
1.321 raeburn 9462: my @roles = &Apache::lonuserutils::roles_by_context('course','',$crstype);
1.213 raeburn 9463: foreach my $role (@roles) {
1.321 raeburn 9464: my $plrole=&Apache::lonnet::plaintext($role,$crstype);
1.329 raeburn 9465: if ((&Apache::lonnet::allowed('c'.$role,$thiscourse)) ||
9466: ((($role eq 'cc') || ($role eq 'co')) && ($isowner))) {
1.221 raeburn 9467: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
1.375 raeburn 9468: $plrole,\%sections_count,\%lt,
1.402 raeburn 9469: $showcredits,$defaultcredits,$crstype);
1.221 raeburn 9470: } elsif ($env{'request.course.sec'} ne '') {
9471: if (&Apache::lonnet::allowed('c'.$role,$thiscourse.'/'.
9472: $env{'request.course.sec'})) {
9473: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
1.375 raeburn 9474: $plrole,\%sections_count,\%lt,
1.402 raeburn 9475: $showcredits,$defaultcredits,$crstype);
1.26 matthew 9476: }
9477: }
9478: }
1.221 raeburn 9479: if (&Apache::lonnet::allowed('ccr',$thiscourse)) {
1.324 raeburn 9480: foreach my $cust (sort(keys(%customroles))) {
9481: next if ($crstype eq 'Community' && $customroles{$cust} =~ /bre\&S/);
1.221 raeburn 9482: my $role = 'cr_cr_'.$env{'user.domain'}.'_'.$env{'user.name'}.'_'.$cust;
9483: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
1.402 raeburn 9484: $cust,\%sections_count,\%lt,
9485: $showcredits,$defaultcredits,$crstype);
1.221 raeburn 9486: }
1.62 www 9487: }
1.26 matthew 9488: }
9489: return '' if ($table eq ''); # return nothing if there is nothing
9490: # in the table
1.188 raeburn 9491: my $result;
9492: if (!$env{'request.course.id'}) {
9493: $result = '<h4>'.$lt{'crl'}.'</h4>'."\n";
9494: }
9495: $result .=
1.136 raeburn 9496: &Apache::loncommon::start_data_table().
9497: &Apache::loncommon::start_data_table_header_row().
1.375 raeburn 9498: '<th>'.$lt{'act'}.'</th><th>'.$lt{'rol'}.'</th>'."\n".
1.402 raeburn 9499: '<th>'.$lt{'ext'}.'</th><th>'."\n";
9500: if ($showcredits) {
9501: $result .= $lt{'crd'}.'</th>';
9502: }
9503: $result .=
1.375 raeburn 9504: '<th>'.$lt{'grs'}.'</th><th>'.$lt{'sta'}.'</th>'."\n".
9505: '<th>'.$lt{'end'}.'</th>'.
1.136 raeburn 9506: &Apache::loncommon::end_data_table_header_row().
9507: $table.
9508: &Apache::loncommon::end_data_table();
1.26 matthew 9509: return $result;
9510: }
1.88 raeburn 9511:
1.221 raeburn 9512: sub course_level_row {
1.375 raeburn 9513: my ($protectedcourse,$role,$area,$domain,$plrole,$sections_count,
1.402 raeburn 9514: $lt,$showcredits,$defaultcredits,$crstype) = @_;
1.375 raeburn 9515: my $creditem;
1.222 raeburn 9516: my $row = &Apache::loncommon::start_data_table_row().
9517: ' <td><input type="checkbox" name="act_'.
9518: $protectedcourse.'_'.$role.'" /></td>'."\n".
9519: ' <td>'.$plrole.'</td>'."\n".
9520: ' <td>'.$area.'<br />Domain: '.$domain.'</td>'."\n";
1.402 raeburn 9521: if (($showcredits) && ($role eq 'st') && ($crstype eq 'Course')) {
1.375 raeburn 9522: $row .=
9523: '<td><input type="text" name="credits_'.$protectedcourse.'_'.
9524: $role.'" size="3" value="'.$defaultcredits.'" /></td>';
9525: } else {
9526: $row .= '<td> </td>';
9527: }
1.322 raeburn 9528: if (($role eq 'cc') || ($role eq 'co')) {
1.222 raeburn 9529: $row .= '<td> </td>';
1.221 raeburn 9530: } elsif ($env{'request.course.sec'} ne '') {
1.222 raeburn 9531: $row .= ' <td><input type="hidden" value="'.
9532: $env{'request.course.sec'}.'" '.
9533: 'name="sec_'.$protectedcourse.'_'.$role.'" />'.
9534: $env{'request.course.sec'}.'</td>';
1.221 raeburn 9535: } else {
9536: if (ref($sections_count) eq 'HASH') {
9537: my $currsec =
9538: &Apache::lonuserutils::course_sections($sections_count,
9539: $protectedcourse.'_'.$role);
1.222 raeburn 9540: $row .= '<td><table class="LC_createuser">'."\n".
9541: '<tr class="LC_section_row">'."\n".
9542: ' <td valign="top">'.$lt->{'exs'}.'<br />'.
9543: $currsec.'</td>'."\n".
9544: ' <td> </td>'."\n".
9545: ' <td valign="top"> '.$lt->{'new'}.'<br />'.
1.221 raeburn 9546: '<input type="text" name="newsec_'.$protectedcourse.'_'.$role.
9547: '" value="" />'.
9548: '<input type="hidden" '.
9549: 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'."\n".
1.222 raeburn 9550: '</tr></table></td>'."\n";
1.221 raeburn 9551: } else {
1.222 raeburn 9552: $row .= '<td><input type="text" size="10" '.
1.375 raeburn 9553: 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'."\n";
1.221 raeburn 9554: }
9555: }
1.222 raeburn 9556: $row .= <<ENDTIMEENTRY;
9557: <td><input type="hidden" name="start_$protectedcourse\_$role" value="" />
1.221 raeburn 9558: <a href=
9559: "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 9560: <td><input type="hidden" name="end_$protectedcourse\_$role" value="" />
1.221 raeburn 9561: <a href=
9562: "javascript:pjump('date_end','End Date $plrole',document.cu.end_$protectedcourse\_$role.value,'end_$protectedcourse\_$role','cu.pres','dateset')">$lt->{'sed'}</a></td>
9563: ENDTIMEENTRY
1.222 raeburn 9564: $row .= &Apache::loncommon::end_data_table_row();
9565: return $row;
1.221 raeburn 9566: }
9567:
1.88 raeburn 9568: sub course_level_dc {
1.375 raeburn 9569: my ($dcdom,$showcredits) = @_;
1.190 raeburn 9570: my %customroles=&Apache::lonuserutils::my_custom_roles();
1.213 raeburn 9571: my @roles = &Apache::lonuserutils::roles_by_context('course');
1.88 raeburn 9572: my $hiddenitems = '<input type="hidden" name="dcdomain" value="'.$dcdom.'" />'.
9573: '<input type="hidden" name="origdom" value="'.$dcdom.'" />'.
1.133 raeburn 9574: '<input type="hidden" name="dccourse" value="" />';
1.355 www 9575: my $courseform=&Apache::loncommon::selectcourse_link
1.356 raeburn 9576: ('cu','dccourse','dcdomain','coursedesc',undef,undef,'Select','crstype');
1.375 raeburn 9577: my $credit_elem;
9578: if ($showcredits) {
9579: $credit_elem = 'credits';
9580: }
9581: my $cb_jscript = &Apache::loncommon::coursebrowser_javascript($dcdom,'currsec','cu','role','Course/Community Browser',$credit_elem);
1.88 raeburn 9582: my %lt=&Apache::lonlocal::texthash(
9583: 'rol' => "Role",
1.113 raeburn 9584: 'grs' => "Section",
1.88 raeburn 9585: 'exs' => "Existing sections",
9586: 'new' => "Define new section",
9587: 'sta' => "Start",
9588: 'end' => "End",
9589: 'ssd' => "Set Start Date",
1.355 www 9590: 'sed' => "Set End Date",
1.375 raeburn 9591: 'scc' => "Course/Community",
9592: 'crd' => "Credits",
1.88 raeburn 9593: );
1.323 raeburn 9594: my $header = '<h4>'.&mt('Course/Community Level').'</h4>'.
1.136 raeburn 9595: &Apache::loncommon::start_data_table().
9596: &Apache::loncommon::start_data_table_header_row().
1.375 raeburn 9597: '<th>'.$lt{'scc'}.'</th><th>'.$lt{'rol'}.'</th>'."\n".
1.397 bisitz 9598: '<th>'.$lt{'grs'}.'</th>'."\n";
9599: $header .= '<th>'.$lt{'crd'}.'</th>'."\n" if ($showcredits);
9600: $header .= '<th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'."\n".
1.136 raeburn 9601: &Apache::loncommon::end_data_table_header_row();
1.143 raeburn 9602: my $otheritems = &Apache::loncommon::start_data_table_row()."\n".
1.356 raeburn 9603: '<td><br /><span class="LC_nobreak"><input type="text" name="coursedesc" value="" onfocus="this.blur();opencrsbrowser('."'cu','dccourse','dcdomain','coursedesc','','','','crstype'".')" />'.
9604: $courseform.(' ' x4).'</span></td>'."\n".
1.389 bisitz 9605: '<td valign="top"><br /><select name="role">'."\n";
1.213 raeburn 9606: foreach my $role (@roles) {
1.135 raeburn 9607: my $plrole=&Apache::lonnet::plaintext($role);
1.389 bisitz 9608: $otheritems .= ' <option value="'.$role.'">'.$plrole.'</option>';
1.88 raeburn 9609: }
1.404 raeburn 9610: if ( keys(%customroles) > 0) {
9611: foreach my $cust (sort(keys(%customroles))) {
1.101 albertel 9612: my $custrole='cr_cr_'.$env{'user.domain'}.
1.135 raeburn 9613: '_'.$env{'user.name'}.'_'.$cust;
1.389 bisitz 9614: $otheritems .= ' <option value="'.$custrole.'">'.$cust.'</option>';
1.88 raeburn 9615: }
9616: }
9617: $otheritems .= '</select></td><td>'.
9618: '<table border="0" cellspacing="0" cellpadding="0">'.
9619: '<tr><td valign="top"><b>'.$lt{'exs'}.'</b><br /><select name="currsec">'.
1.389 bisitz 9620: ' <option value=""><--'.&mt('Pick course first').'</option></select></td>'.
1.88 raeburn 9621: '<td> </td>'.
9622: '<td valign="top"> <b>'.$lt{'new'}.'</b><br />'.
1.113 raeburn 9623: '<input type="text" name="newsec" value="" />'.
1.237 raeburn 9624: '<input type="hidden" name="section" value="" />'.
1.323 raeburn 9625: '<input type="hidden" name="groups" value="" />'.
9626: '<input type="hidden" name="crstype" value="" /></td>'.
1.375 raeburn 9627: '</tr></table></td>'."\n";
9628: if ($showcredits) {
9629: $otheritems .= '<td><br />'."\n".
1.397 bisitz 9630: '<input type="text" size="3" name="credits" value="" /></td>'."\n";
1.375 raeburn 9631: }
1.88 raeburn 9632: $otheritems .= <<ENDTIMEENTRY;
1.323 raeburn 9633: <td><br /><input type="hidden" name="start" value='' />
1.88 raeburn 9634: <a href=
9635: "javascript:pjump('date_start','Start Date',document.cu.start.value,'start','cu.pres','dateset')">$lt{'ssd'}</a></td>
1.323 raeburn 9636: <td><br /><input type="hidden" name="end" value='' />
1.88 raeburn 9637: <a href=
9638: "javascript:pjump('date_end','End Date',document.cu.end.value,'end','cu.pres','dateset')">$lt{'sed'}</a></td>
9639: ENDTIMEENTRY
1.136 raeburn 9640: $otheritems .= &Apache::loncommon::end_data_table_row().
9641: &Apache::loncommon::end_data_table()."\n";
1.88 raeburn 9642: return $cb_jscript.$header.$hiddenitems.$otheritems;
9643: }
9644:
1.237 raeburn 9645: sub update_selfenroll_config {
1.400 raeburn 9646: my ($r,$cid,$cdom,$cnum,$context,$crstype,$currsettings) = @_;
1.398 raeburn 9647: return unless (ref($currsettings) eq 'HASH');
9648: my ($row,$lt) = &Apache::lonuserutils::get_selfenroll_titles();
9649: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
1.237 raeburn 9650: my (%changes,%warning);
1.241 raeburn 9651: my $curr_types;
1.400 raeburn 9652: my %noedit;
9653: unless ($context eq 'domain') {
9654: %noedit = &get_noedit_fields($cdom,$cnum,$crstype,$row);
9655: }
1.237 raeburn 9656: if (ref($row) eq 'ARRAY') {
9657: foreach my $item (@{$row}) {
1.400 raeburn 9658: next if ($noedit{$item});
1.237 raeburn 9659: if ($item eq 'enroll_dates') {
9660: my (%currenrolldate,%newenrolldate);
9661: foreach my $type ('start','end') {
1.398 raeburn 9662: $currenrolldate{$type} = $currsettings->{'selfenroll_'.$type.'_date'};
1.237 raeburn 9663: $newenrolldate{$type} = &Apache::lonhtmlcommon::get_date_from_form('selfenroll_'.$type.'_date');
9664: if ($newenrolldate{$type} ne $currenrolldate{$type}) {
9665: $changes{'internal.selfenroll_'.$type.'_date'} = $newenrolldate{$type};
9666: }
9667: }
9668: } elsif ($item eq 'access_dates') {
9669: my (%currdate,%newdate);
9670: foreach my $type ('start','end') {
1.398 raeburn 9671: $currdate{$type} = $currsettings->{'selfenroll_'.$type.'_access'};
1.237 raeburn 9672: $newdate{$type} = &Apache::lonhtmlcommon::get_date_from_form('selfenroll_'.$type.'_access');
9673: if ($newdate{$type} ne $currdate{$type}) {
9674: $changes{'internal.selfenroll_'.$type.'_access'} = $newdate{$type};
9675: }
9676: }
1.241 raeburn 9677: } elsif ($item eq 'types') {
1.398 raeburn 9678: $curr_types = $currsettings->{'selfenroll_'.$item};
1.241 raeburn 9679: if ($env{'form.selfenroll_all'}) {
9680: if ($curr_types ne '*') {
9681: $changes{'internal.selfenroll_types'} = '*';
9682: } else {
9683: next;
9684: }
9685: } else {
1.249 raeburn 9686: my %currdoms;
1.241 raeburn 9687: my @entries = split(/;/,$curr_types);
9688: my @deletedoms = &Apache::loncommon::get_env_multiple('form.selfenroll_delete');
1.249 raeburn 9689: my @activations = &Apache::loncommon::get_env_multiple('form.selfenroll_activate');
1.241 raeburn 9690: my $newnum = 0;
1.249 raeburn 9691: my @latesttypes;
9692: foreach my $num (@activations) {
9693: my @types = &Apache::loncommon::get_env_multiple('form.selfenroll_types_'.$num);
9694: if (@types > 0) {
1.241 raeburn 9695: @types = sort(@types);
9696: my $typestr = join(',',@types);
1.249 raeburn 9697: my $typedom = $env{'form.selfenroll_dom_'.$num};
9698: $latesttypes[$newnum] = $typedom.':'.$typestr;
9699: $currdoms{$typedom} = 1;
1.241 raeburn 9700: $newnum ++;
9701: }
9702: }
1.338 raeburn 9703: for (my $j=0; $j<$env{'form.selfenroll_types_total'}; $j++) {
9704: if ((!grep(/^$j$/,@deletedoms)) && (!grep(/^$j$/,@activations))) {
1.249 raeburn 9705: my @types = &Apache::loncommon::get_env_multiple('form.selfenroll_types_'.$j);
9706: if (@types > 0) {
9707: @types = sort(@types);
9708: my $typestr = join(',',@types);
9709: my $typedom = $env{'form.selfenroll_dom_'.$j};
9710: $latesttypes[$newnum] = $typedom.':'.$typestr;
9711: $currdoms{$typedom} = 1;
9712: $newnum ++;
9713: }
9714: }
9715: }
9716: if ($env{'form.selfenroll_newdom'} ne '') {
9717: my $typedom = $env{'form.selfenroll_newdom'};
9718: if ((!defined($currdoms{$typedom})) &&
9719: (&Apache::lonnet::domain($typedom) ne '')) {
9720: my $typestr;
9721: my ($othertitle,$usertypes,$types) =
9722: &Apache::loncommon::sorted_inst_types($typedom);
9723: my $othervalue = 'any';
9724: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
9725: if (@{$types} > 0) {
1.257 raeburn 9726: my @esc_types = map { &escape($_); } @{$types};
1.249 raeburn 9727: $othervalue = 'other';
1.258 raeburn 9728: $typestr = join(',',(@esc_types,$othervalue));
1.249 raeburn 9729: }
9730: $typestr = $othervalue;
9731: } else {
9732: $typestr = $othervalue;
9733: }
9734: $latesttypes[$newnum] = $typedom.':'.$typestr;
9735: $newnum ++ ;
9736: }
9737: }
1.241 raeburn 9738: my $selfenroll_types = join(';',@latesttypes);
9739: if ($selfenroll_types ne $curr_types) {
9740: $changes{'internal.selfenroll_types'} = $selfenroll_types;
9741: }
9742: }
1.276 raeburn 9743: } elsif ($item eq 'limit') {
9744: my $newlimit = $env{'form.selfenroll_limit'};
9745: my $newcap = $env{'form.selfenroll_cap'};
9746: $newcap =~s/\s+//g;
1.398 raeburn 9747: my $currlimit = $currsettings->{'selfenroll_limit'};
1.276 raeburn 9748: $currlimit = 'none' if ($currlimit eq '');
1.398 raeburn 9749: my $currcap = $currsettings->{'selfenroll_cap'};
1.276 raeburn 9750: if ($newlimit ne $currlimit) {
9751: if ($newlimit ne 'none') {
9752: if ($newcap =~ /^\d+$/) {
9753: if ($newcap ne $currcap) {
9754: $changes{'internal.selfenroll_cap'} = $newcap;
9755: }
9756: $changes{'internal.selfenroll_limit'} = $newlimit;
9757: } else {
1.398 raeburn 9758: $warning{$item} = &mt('Maximum enrollment setting unchanged.').'<br />'.
9759: &mt('The value provided was invalid - it must be a positive integer if enrollment is being limited.');
1.276 raeburn 9760: }
9761: } elsif ($currcap ne '') {
9762: $changes{'internal.selfenroll_cap'} = '';
9763: $changes{'internal.selfenroll_limit'} = $newlimit;
9764: }
9765: } elsif ($currlimit ne 'none') {
9766: if ($newcap =~ /^\d+$/) {
9767: if ($newcap ne $currcap) {
9768: $changes{'internal.selfenroll_cap'} = $newcap;
9769: }
9770: } else {
1.398 raeburn 9771: $warning{$item} = &mt('Maximum enrollment setting unchanged.').'<br />'.
9772: &mt('The value provided was invalid - it must be a positive integer if enrollment is being limited.');
1.276 raeburn 9773: }
9774: }
9775: } elsif ($item eq 'approval') {
9776: my (@currnotified,@newnotified);
1.398 raeburn 9777: my $currapproval = $currsettings->{'selfenroll_approval'};
9778: my $currnotifylist = $currsettings->{'selfenroll_notifylist'};
1.276 raeburn 9779: if ($currnotifylist ne '') {
9780: @currnotified = split(/,/,$currnotifylist);
9781: @currnotified = sort(@currnotified);
9782: }
9783: my $newapproval = $env{'form.selfenroll_approval'};
9784: @newnotified = &Apache::loncommon::get_env_multiple('form.selfenroll_notify');
9785: @newnotified = sort(@newnotified);
9786: if ($newapproval ne $currapproval) {
9787: $changes{'internal.selfenroll_approval'} = $newapproval;
9788: if (!$newapproval) {
9789: if ($currnotifylist ne '') {
9790: $changes{'internal.selfenroll_notifylist'} = '';
9791: }
9792: } else {
9793: my @differences =
1.295 raeburn 9794: &Apache::loncommon::compare_arrays(\@currnotified,\@newnotified);
1.276 raeburn 9795: if (@differences > 0) {
9796: if (@newnotified > 0) {
9797: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
9798: } else {
9799: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
9800: }
9801: }
9802: }
9803: } else {
1.295 raeburn 9804: my @differences = &Apache::loncommon::compare_arrays(\@currnotified,\@newnotified);
1.276 raeburn 9805: if (@differences > 0) {
9806: if (@newnotified > 0) {
9807: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
9808: } else {
9809: $changes{'internal.selfenroll_notifylist'} = '';
9810: }
9811: }
9812: }
1.237 raeburn 9813: } else {
1.398 raeburn 9814: my $curr_val = $currsettings->{'selfenroll_'.$item};
1.237 raeburn 9815: my $newval = $env{'form.selfenroll_'.$item};
9816: if ($item eq 'section') {
9817: $newval = $env{'form.sections'};
1.241 raeburn 9818: if (defined($curr_groups{$newval})) {
1.237 raeburn 9819: $newval = $curr_val;
1.398 raeburn 9820: $warning{$item} = &mt('Section for self-enrolled users unchanged as the proposed section is a group').'<br />'.
9821: &mt('Group names and section names must be distinct');
1.237 raeburn 9822: } elsif ($newval eq 'all') {
9823: $newval = $curr_val;
1.274 bisitz 9824: $warning{$item} = &mt('Section for self-enrolled users unchanged, as "all" is a reserved section name.');
1.237 raeburn 9825: }
9826: if ($newval eq '') {
9827: $newval = 'none';
9828: }
9829: }
9830: if ($newval ne $curr_val) {
9831: $changes{'internal.selfenroll_'.$item} = $newval;
9832: }
1.241 raeburn 9833: }
1.237 raeburn 9834: }
9835: if (keys(%warning) > 0) {
9836: foreach my $item (@{$row}) {
9837: if (exists($warning{$item})) {
9838: $r->print($warning{$item}.'<br />');
9839: }
9840: }
9841: }
9842: if (keys(%changes) > 0) {
9843: my $putresult = &Apache::lonnet::put('environment',\%changes,$cdom,$cnum);
9844: if ($putresult eq 'ok') {
9845: if ((exists($changes{'internal.selfenroll_types'})) ||
9846: (exists($changes{'internal.selfenroll_start_date'})) ||
9847: (exists($changes{'internal.selfenroll_end_date'}))) {
9848: my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',
9849: $cnum,undef,undef,'Course');
9850: my $chome = &Apache::lonnet::homeserver($cnum,$cdom);
1.398 raeburn 9851: if (ref($crsinfo{$cid}) eq 'HASH') {
1.237 raeburn 9852: foreach my $item ('selfenroll_types','selfenroll_start_date','selfenroll_end_date') {
9853: if (exists($changes{'internal.'.$item})) {
1.398 raeburn 9854: $crsinfo{$cid}{$item} = $changes{'internal.'.$item};
1.237 raeburn 9855: }
9856: }
9857: my $crsputresult =
9858: &Apache::lonnet::courseidput($cdom,\%crsinfo,
9859: $chome,'notime');
9860: }
9861: }
9862: $r->print(&mt('The following changes were made to self-enrollment settings:').'<ul>');
9863: foreach my $item (@{$row}) {
9864: my $title = $item;
9865: if (ref($lt) eq 'HASH') {
9866: $title = $lt->{$item};
9867: }
9868: if ($item eq 'enroll_dates') {
9869: foreach my $type ('start','end') {
9870: if (exists($changes{'internal.selfenroll_'.$type.'_date'})) {
9871: my $newdate = &Apache::lonlocal::locallocaltime($changes{'internal.selfenroll_'.$type.'_date'});
1.244 bisitz 9872: $r->print('<li>'.&mt('[_1]: "[_2]" set to "[_3]".',
1.237 raeburn 9873: $title,$type,$newdate).'</li>');
9874: }
9875: }
9876: } elsif ($item eq 'access_dates') {
9877: foreach my $type ('start','end') {
9878: if (exists($changes{'internal.selfenroll_'.$type.'_access'})) {
9879: my $newdate = &Apache::lonlocal::locallocaltime($changes{'internal.selfenroll_'.$type.'_access'});
1.244 bisitz 9880: $r->print('<li>'.&mt('[_1]: "[_2]" set to "[_3]".',
1.237 raeburn 9881: $title,$type,$newdate).'</li>');
9882: }
9883: }
1.276 raeburn 9884: } elsif ($item eq 'limit') {
9885: if ((exists($changes{'internal.selfenroll_limit'})) ||
9886: (exists($changes{'internal.selfenroll_cap'}))) {
9887: my ($newval,$newcap);
9888: if ($changes{'internal.selfenroll_cap'} ne '') {
9889: $newcap = $changes{'internal.selfenroll_cap'}
9890: } else {
1.398 raeburn 9891: $newcap = $currsettings->{'selfenroll_cap'};
1.276 raeburn 9892: }
9893: if ($changes{'internal.selfenroll_limit'} eq 'none') {
9894: $newval = &mt('No limit');
9895: } elsif ($changes{'internal.selfenroll_limit'} eq
9896: 'allstudents') {
9897: $newval = &mt('New self-enrollment no longer allowed when total (all students) reaches [_1].',$newcap);
9898: } elsif ($changes{'internal.selfenroll_limit'} eq 'selfenrolled') {
9899: $newval = &mt('New self-enrollment no longer allowed when total number of self-enrolled students reaches [_1].',$newcap);
9900: } else {
1.398 raeburn 9901: my $currlimit = $currsettings->{'selfenroll_limit'};
1.276 raeburn 9902: if ($currlimit eq 'allstudents') {
9903: $newval = &mt('New self-enrollment no longer allowed when total (all students) reaches [_1].',$newcap);
9904: } elsif ($changes{'internal.selfenroll_limit'} eq 'selfenrolled') {
1.308 raeburn 9905: $newval = &mt('New self-enrollment no longer allowed when total number of self-enrolled students reaches [_1].',$newcap);
1.276 raeburn 9906: }
9907: }
9908: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval).'</li>'."\n");
9909: }
9910: } elsif ($item eq 'approval') {
9911: if ((exists($changes{'internal.selfenroll_approval'})) ||
9912: (exists($changes{'internal.selfenroll_notifylist'}))) {
1.398 raeburn 9913: my %selfdescs = &Apache::lonuserutils::selfenroll_default_descs();
1.276 raeburn 9914: my ($newval,$newnotify);
9915: if (exists($changes{'internal.selfenroll_notifylist'})) {
9916: $newnotify = $changes{'internal.selfenroll_notifylist'};
9917: } else {
1.398 raeburn 9918: $newnotify = $currsettings->{'selfenroll_notifylist'};
1.276 raeburn 9919: }
1.398 raeburn 9920: if (exists($changes{'internal.selfenroll_approval'})) {
9921: if ($changes{'internal.selfenroll_approval'} !~ /^[012]$/) {
9922: $changes{'internal.selfenroll_approval'} = '0';
9923: }
9924: $newval = $selfdescs{'approval'}{$changes{'internal.selfenroll_approval'}};
1.276 raeburn 9925: } else {
1.398 raeburn 9926: my $currapproval = $currsettings->{'selfenroll_approval'};
9927: if ($currapproval !~ /^[012]$/) {
9928: $currapproval = 0;
1.276 raeburn 9929: }
1.398 raeburn 9930: $newval = $selfdescs{'approval'}{$currapproval};
1.276 raeburn 9931: }
9932: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval));
9933: if ($newnotify) {
1.277 raeburn 9934: $r->print('<br />'.&mt('The following will be notified when an enrollment request needs approval, or has been approved: [_1].',$newnotify));
1.276 raeburn 9935: } else {
1.277 raeburn 9936: $r->print('<br />'.&mt('No notifications sent when an enrollment request needs approval, or has been approved.'));
1.276 raeburn 9937: }
9938: $r->print('</li>'."\n");
9939: }
1.237 raeburn 9940: } else {
9941: if (exists($changes{'internal.selfenroll_'.$item})) {
1.241 raeburn 9942: my $newval = $changes{'internal.selfenroll_'.$item};
9943: if ($item eq 'types') {
9944: if ($newval eq '') {
9945: $newval = &mt('None');
9946: } elsif ($newval eq '*') {
9947: $newval = &mt('Any user in any domain');
9948: }
1.245 raeburn 9949: } elsif ($item eq 'registered') {
9950: if ($newval eq '1') {
9951: $newval = &mt('Yes');
9952: } elsif ($newval eq '0') {
9953: $newval = &mt('No');
9954: }
1.241 raeburn 9955: }
1.244 bisitz 9956: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval).'</li>'."\n");
1.237 raeburn 9957: }
9958: }
9959: }
9960: $r->print('</ul>');
1.398 raeburn 9961: if ($env{'course.'.$cid.'.description'} ne '') {
9962: my %newenvhash;
9963: foreach my $key (keys(%changes)) {
9964: $newenvhash{'course.'.$cid.'.'.$key} = $changes{$key};
9965: }
9966: &Apache::lonnet::appenv(\%newenvhash);
1.237 raeburn 9967: }
9968: } else {
1.398 raeburn 9969: $r->print(&mt('An error occurred when saving changes to self-enrollment settings in this course.').'<br />'.
9970: &mt('The error was: [_1].',$putresult));
1.237 raeburn 9971: }
9972: } else {
1.249 raeburn 9973: $r->print(&mt('No changes were made to the existing self-enrollment settings in this course.'));
1.237 raeburn 9974: }
9975: } else {
1.249 raeburn 9976: $r->print(&mt('No changes were made to the existing self-enrollment settings in this course.'));
1.241 raeburn 9977: }
1.469 ! raeburn 9978: my $visactions = &cat_visibility($cdom);
1.400 raeburn 9979: my ($cathash,%cattype);
9980: my %domconfig = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom);
9981: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
9982: $cathash = $domconfig{'coursecategories'}{'cats'};
9983: $cattype{'auth'} = $domconfig{'coursecategories'}{'auth'};
9984: $cattype{'unauth'} = $domconfig{'coursecategories'}{'unauth'};
9985: } else {
9986: $cathash = {};
9987: $cattype{'auth'} = 'std';
9988: $cattype{'unauth'} = 'std';
9989: }
9990: if (($cattype{'auth'} eq 'none') && ($cattype{'unauth'} eq 'none')) {
9991: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
9992: '<br />'.
9993: '<br />'.$visactions->{'take'}.'<ul>'.
9994: '<li>'.$visactions->{'dc_chgconf'}.'</li>'.
9995: '</ul>');
9996: } elsif (($cattype{'auth'} !~ /^(std|domonly)$/) && ($cattype{'unauth'} !~ /^(std|domonly)$/)) {
9997: if ($currsettings->{'uniquecode'}) {
9998: $r->print('<span class="LC_info">'.$visactions->{'vis'}.'</span>');
9999: } else {
1.366 bisitz 10000: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
1.400 raeburn 10001: '<br />'.
10002: '<br />'.$visactions->{'take'}.'<ul>'.
10003: '<li>'.$visactions->{'dc_setcode'}.'</li>'.
10004: '</ul><br />');
10005: }
10006: } else {
10007: my ($visible,$cansetvis,$vismsgs) = &visible_in_stdcat($cdom,$cnum,\%domconfig);
10008: if (ref($visactions) eq 'HASH') {
10009: if (!$visible) {
10010: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
10011: '<br />');
10012: if (ref($vismsgs) eq 'ARRAY') {
10013: $r->print('<br />'.$visactions->{'take'}.'<ul>');
10014: foreach my $item (@{$vismsgs}) {
10015: $r->print('<li>'.$visactions->{$item}.'</li>');
10016: }
10017: $r->print('</ul>');
1.256 raeburn 10018: }
1.400 raeburn 10019: $r->print($cansetvis);
1.256 raeburn 10020: }
10021: }
10022: }
1.237 raeburn 10023: return;
10024: }
10025:
1.27 matthew 10026: #---------------------------------------------- end functions for &phase_two
1.29 matthew 10027:
10028: #--------------------------------- functions for &phase_two and &phase_three
10029:
10030: #--------------------------end of functions for &phase_two and &phase_three
1.372 raeburn 10031:
1.1 www 10032: 1;
10033: __END__
1.2 www 10034:
10035:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>