Annotation of loncom/interface/loncreateuser.pm, revision 1.416
1.20 harris41 1: # The LearningOnline Network with CAPA
1.1 www 2: # Create a user
3: #
1.416 ! raeburn 4: # $Id: loncreateuser.pm,v 1.415 2016/10/10 02:53:02 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.1 www 74:
1.20 harris41 75: my $loginscript; # piece of javascript used in two separate instances
76: my $authformnop;
77: my $authformkrb;
78: my $authformint;
79: my $authformfsys;
80: my $authformloc;
81:
1.94 matthew 82: sub initialize_authen_forms {
1.227 raeburn 83: my ($dom,$formname,$curr_authtype,$mode) = @_;
84: my ($krbdef,$krbdefdom) = &Apache::loncommon::get_kerberos_defaults($dom);
85: my %param = ( formname => $formname,
1.187 raeburn 86: kerb_def_dom => $krbdefdom,
1.227 raeburn 87: kerb_def_auth => $krbdef,
1.187 raeburn 88: domain => $dom,
89: );
1.188 raeburn 90: my %abv_auth = &auth_abbrev();
1.227 raeburn 91: if ($curr_authtype =~ /^(krb4|krb5|internal|localauth|unix):(.*)$/) {
1.188 raeburn 92: my $long_auth = $1;
1.227 raeburn 93: my $curr_autharg = $2;
1.188 raeburn 94: my %abv_auth = &auth_abbrev();
95: $param{'curr_authtype'} = $abv_auth{$long_auth};
96: if ($long_auth =~ /^krb(4|5)$/) {
97: $param{'curr_kerb_ver'} = $1;
1.227 raeburn 98: $param{'curr_autharg'} = $curr_autharg;
1.188 raeburn 99: }
1.205 raeburn 100: if ($mode eq 'modifyuser') {
101: $param{'mode'} = $mode;
102: }
1.187 raeburn 103: }
1.227 raeburn 104: $loginscript = &Apache::loncommon::authform_header(%param);
105: $authformkrb = &Apache::loncommon::authform_kerberos(%param);
1.31 matthew 106: $authformnop = &Apache::loncommon::authform_nochange(%param);
107: $authformint = &Apache::loncommon::authform_internal(%param);
108: $authformfsys = &Apache::loncommon::authform_filesystem(%param);
109: $authformloc = &Apache::loncommon::authform_local(%param);
1.20 harris41 110: }
111:
1.188 raeburn 112: sub auth_abbrev {
113: my %abv_auth = (
1.368 raeburn 114: krb5 => 'krb',
115: krb4 => 'krb',
116: internal => 'int',
117: localauth => 'loc',
118: unix => 'fsys',
1.188 raeburn 119: );
120: return %abv_auth;
121: }
1.43 www 122:
1.134 raeburn 123: # ====================================================
124:
1.378 raeburn 125: sub user_quotas {
1.134 raeburn 126: my ($ccuname,$ccdomain) = @_;
127: my %lt = &Apache::lonlocal::texthash(
1.267 raeburn 128: 'usrt' => "User Tools",
129: 'cust' => "Custom quota",
130: 'chqu' => "Change quota",
1.134 raeburn 131: );
1.378 raeburn 132:
1.149 raeburn 133: my $quota_javascript = <<"END_SCRIPT";
134: <script type="text/javascript">
1.301 bisitz 135: // <![CDATA[
1.378 raeburn 136: function quota_changes(caller,context) {
137: var customoff = document.getElementById('custom_'+context+'quota_off');
138: var customon = document.getElementById('custom_'+context+'quota_on');
139: var number = document.getElementById(context+'quota');
1.149 raeburn 140: if (caller == "custom") {
1.378 raeburn 141: if (customoff) {
142: if (customoff.checked) {
143: number.value = "";
144: }
1.149 raeburn 145: }
146: }
147: if (caller == "quota") {
1.378 raeburn 148: if (customon) {
149: customon.checked = true;
150: }
1.149 raeburn 151: }
1.378 raeburn 152: return;
1.149 raeburn 153: }
1.301 bisitz 154: // ]]>
1.149 raeburn 155: </script>
156: END_SCRIPT
1.378 raeburn 157: my $longinsttype;
158: my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($ccdomain);
1.267 raeburn 159: my $output = $quota_javascript."\n".
160: '<h3>'.$lt{'usrt'}.'</h3>'."\n".
161: &Apache::loncommon::start_data_table();
162:
163: if (&Apache::lonnet::allowed('mut',$ccdomain)) {
1.275 raeburn 164: $output .= &build_tools_display($ccuname,$ccdomain,'tools');
1.267 raeburn 165: }
1.378 raeburn 166:
167: my %titles = &Apache::lonlocal::texthash (
168: portfolio => "Disk space allocated to user's portfolio files",
1.385 bisitz 169: author => "Disk space allocated to user's Authoring Space (if role assigned)",
1.378 raeburn 170: );
171: foreach my $name ('portfolio','author') {
172: my ($currquota,$quotatype,$inststatus,$defquota) =
173: &Apache::loncommon::get_user_quota($ccuname,$ccdomain,$name);
174: if ($longinsttype eq '') {
175: if ($inststatus ne '') {
176: if ($usertypes->{$inststatus} ne '') {
177: $longinsttype = $usertypes->{$inststatus};
178: }
179: }
180: }
181: my ($showquota,$custom_on,$custom_off,$defaultinfo);
182: $custom_on = ' ';
183: $custom_off = ' checked="checked" ';
184: if ($quotatype eq 'custom') {
185: $custom_on = $custom_off;
186: $custom_off = ' ';
187: $showquota = $currquota;
188: if ($longinsttype eq '') {
189: $defaultinfo = &mt('For this user, the default quota would be [_1]'
1.383 raeburn 190: .' MB.',$defquota);
1.378 raeburn 191: } else {
192: $defaultinfo = &mt("For this user, the default quota would be [_1]".
1.383 raeburn 193: " MB, as determined by the user's institutional".
1.378 raeburn 194: " affiliation ([_2]).",$defquota,$longinsttype);
195: }
196: } else {
197: if ($longinsttype eq '') {
198: $defaultinfo = &mt('For this user, the default quota is [_1]'
1.383 raeburn 199: .' MB.',$defquota);
1.378 raeburn 200: } else {
201: $defaultinfo = &mt("For this user, the default quota of [_1]".
1.383 raeburn 202: " MB, is determined by the user's institutional".
1.378 raeburn 203: " affiliation ([_2]).",$defquota,$longinsttype);
204: }
205: }
206:
207: if (&Apache::lonnet::allowed('mpq',$ccdomain)) {
208: $output .= '<tr class="LC_info_row">'."\n".
209: ' <td>'.$titles{$name}.'</td>'."\n".
210: ' </tr>'."\n".
211: &Apache::loncommon::start_data_table_row()."\n".
1.390 bisitz 212: ' <td><span class="LC_nobreak">'.
213: &mt('Current quota: [_1] MB',$currquota).'</span> '.
1.378 raeburn 214: $defaultinfo.'</td>'."\n".
215: &Apache::loncommon::end_data_table_row()."\n".
216: &Apache::loncommon::start_data_table_row()."\n".
217: ' <td><span class="LC_nobreak">'.$lt{'chqu'}.
218: ': <label>'.
219: '<input type="radio" name="custom_'.$name.'quota" id="custom_'.$name.'quota_off" '.
1.379 raeburn 220: 'value="0" '.$custom_off.' onchange="javascript:quota_changes('."'custom','$name'".');"'.
1.390 bisitz 221: ' /><span class="LC_nobreak">'.
222: &mt('Default ([_1] MB)',$defquota).'</span></label> '.
1.378 raeburn 223: ' <label><input type="radio" name="custom_'.$name.'quota" id="custom_'.$name.'quota_on" '.
1.379 raeburn 224: 'value="1" '.$custom_on.' onchange="javascript:quota_changes('."'custom','$name'".');"'.
1.378 raeburn 225: ' />'.$lt{'cust'}.':</label> '.
1.379 raeburn 226: '<input type="text" name="'.$name.'quota" id="'.$name.'quota" size ="5" '.
227: 'value="'.$showquota.'" onfocus="javascript:quota_changes('."'quota','$name'".');"'.
1.390 bisitz 228: ' /> '.&mt('MB').'</span></td>'."\n".
1.378 raeburn 229: &Apache::loncommon::end_data_table_row()."\n";
230: }
231: }
1.267 raeburn 232: $output .= &Apache::loncommon::end_data_table();
1.134 raeburn 233: return $output;
234: }
235:
1.275 raeburn 236: sub build_tools_display {
237: my ($ccuname,$ccdomain,$context) = @_;
1.306 raeburn 238: my (@usertools,%userenv,$output,@options,%validations,%reqtitles,%reqdisplay,
1.332 raeburn 239: $colspan,$isadv,%domconfig);
1.275 raeburn 240: my %lt = &Apache::lonlocal::texthash (
241: 'blog' => "Personal User Blog",
242: 'aboutme' => "Personal Information Page",
1.385 bisitz 243: 'webdav' => "WebDAV access to Authoring Spaces (if SSL and author/co-author)",
1.275 raeburn 244: 'portfolio' => "Personal User Portfolio",
245: 'avai' => "Available",
246: 'cusa' => "availability",
247: 'chse' => "Change setting",
248: 'usde' => "Use default",
249: 'uscu' => "Use custom",
250: 'official' => 'Can request creation of official courses',
1.299 raeburn 251: 'unofficial' => 'Can request creation of unofficial courses',
252: 'community' => 'Can request creation of communities',
1.384 raeburn 253: 'textbook' => 'Can request creation of textbook courses',
1.411 raeburn 254: 'placement' => 'Can request creation of placement tests',
1.362 raeburn 255: 'requestauthor' => 'Can request author space',
1.275 raeburn 256: );
1.279 raeburn 257: if ($context eq 'requestcourses') {
1.275 raeburn 258: %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
1.299 raeburn 259: 'requestcourses.official','requestcourses.unofficial',
1.411 raeburn 260: 'requestcourses.community','requestcourses.textbook',
261: 'requestcourses.placement');
262: @usertools = ('official','unofficial','community','textbook','placement');
1.309 raeburn 263: @options =('norequest','approval','autolimit','validate');
1.306 raeburn 264: %validations = &Apache::lonnet::auto_courserequest_checks($ccdomain);
265: %reqtitles = &courserequest_titles();
266: %reqdisplay = &courserequest_display();
267: $colspan = ' colspan="2"';
1.332 raeburn 268: %domconfig =
269: &Apache::lonnet::get_dom('configuration',['requestcourses'],$ccdomain);
270: $isadv = &Apache::lonnet::is_advanced_user($ccuname,$ccdomain);
1.362 raeburn 271: } elsif ($context eq 'requestauthor') {
272: %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
273: 'requestauthor');
274: @usertools = ('requestauthor');
275: @options =('norequest','approval','automatic');
276: %reqtitles = &requestauthor_titles();
277: %reqdisplay = &requestauthor_display();
278: $colspan = ' colspan="2"';
279: %domconfig =
280: &Apache::lonnet::get_dom('configuration',['requestauthor'],$ccdomain);
1.275 raeburn 281: } else {
282: %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
1.361 raeburn 283: 'tools.aboutme','tools.portfolio','tools.blog',
284: 'tools.webdav');
285: @usertools = ('aboutme','blog','webdav','portfolio');
1.275 raeburn 286: }
287: foreach my $item (@usertools) {
1.306 raeburn 288: my ($custom_access,$curr_access,$cust_on,$cust_off,$tool_on,$tool_off,
289: $currdisp,$custdisp,$custradio);
1.275 raeburn 290: $cust_off = 'checked="checked" ';
291: $tool_on = 'checked="checked" ';
292: $curr_access =
293: &Apache::lonnet::usertools_access($ccuname,$ccdomain,$item,undef,
294: $context);
1.362 raeburn 295: if ($context eq 'requestauthor') {
296: if ($userenv{$context} ne '') {
297: $cust_on = ' checked="checked" ';
298: $cust_off = '';
299: }
300: } elsif ($userenv{$context.'.'.$item} ne '') {
1.306 raeburn 301: $cust_on = ' checked="checked" ';
302: $cust_off = '';
303: }
304: if ($context eq 'requestcourses') {
305: if ($userenv{$context.'.'.$item} eq '') {
1.314 raeburn 306: $custom_access = &mt('Currently from default setting.');
1.306 raeburn 307: } else {
308: $custom_access = &mt('Currently from custom setting.');
1.275 raeburn 309: }
1.362 raeburn 310: } elsif ($context eq 'requestauthor') {
311: if ($userenv{$context} eq '') {
312: $custom_access = &mt('Currently from default setting.');
313: } else {
314: $custom_access = &mt('Currently from custom setting.');
315: }
1.275 raeburn 316: } else {
1.306 raeburn 317: if ($userenv{$context.'.'.$item} eq '') {
1.314 raeburn 318: $custom_access =
1.306 raeburn 319: &mt('Availability determined currently from default setting.');
320: if (!$curr_access) {
321: $tool_off = 'checked="checked" ';
322: $tool_on = '';
323: }
324: } else {
1.314 raeburn 325: $custom_access =
1.306 raeburn 326: &mt('Availability determined currently from custom setting.');
327: if ($userenv{$context.'.'.$item} == 0) {
328: $tool_off = 'checked="checked" ';
329: $tool_on = '';
330: }
1.275 raeburn 331: }
332: }
333: $output .= ' <tr class="LC_info_row">'."\n".
1.306 raeburn 334: ' <td'.$colspan.'>'.$lt{$item}.'</td>'."\n".
1.275 raeburn 335: ' </tr>'."\n".
1.306 raeburn 336: &Apache::loncommon::start_data_table_row()."\n";
1.362 raeburn 337: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.306 raeburn 338: my ($curroption,$currlimit);
1.362 raeburn 339: my $envkey = $context.'.'.$item;
340: if ($context eq 'requestauthor') {
341: $envkey = $context;
342: }
343: if ($userenv{$envkey} ne '') {
344: $curroption = $userenv{$envkey};
1.332 raeburn 345: } else {
346: my (@inststatuses);
1.362 raeburn 347: if ($context eq 'requestcourses') {
348: $curroption =
349: &Apache::loncoursequeueadmin::get_processtype('course',$ccuname,$ccdomain,
350: $isadv,$ccdomain,$item,
351: \@inststatuses,\%domconfig);
352: } else {
353: $curroption =
354: &Apache::loncoursequeueadmin::get_processtype('requestauthor',$ccuname,$ccdomain,
355: $isadv,$ccdomain,undef,
356: \@inststatuses,\%domconfig);
357: }
1.332 raeburn 358: }
1.306 raeburn 359: if (!$curroption) {
360: $curroption = 'norequest';
361: }
362: if ($curroption =~ /^autolimit=(\d*)$/) {
363: $currlimit = $1;
1.314 raeburn 364: if ($currlimit eq '') {
365: $currdisp = &mt('Yes, automatic creation');
366: } else {
367: $currdisp = &mt('Yes, up to [quant,_1,request]/user',$currlimit);
368: }
1.306 raeburn 369: } else {
370: $currdisp = $reqdisplay{$curroption};
371: }
372: $custdisp = '<table>';
373: foreach my $option (@options) {
374: my $val = $option;
375: if ($option eq 'norequest') {
376: $val = 0;
377: }
378: if ($option eq 'validate') {
379: my $canvalidate = 0;
380: if (ref($validations{$item}) eq 'HASH') {
381: if ($validations{$item}{'_custom_'}) {
382: $canvalidate = 1;
383: }
384: }
385: next if (!$canvalidate);
386: }
387: my $checked = '';
388: if ($option eq $curroption) {
389: $checked = ' checked="checked"';
390: } elsif ($option eq 'autolimit') {
391: if ($curroption =~ /^autolimit/) {
392: $checked = ' checked="checked"';
393: }
394: }
1.362 raeburn 395: my $name = 'crsreq_'.$item;
396: if ($context eq 'requestauthor') {
397: $name = $item;
398: }
1.306 raeburn 399: $custdisp .= '<tr><td><span class="LC_nobreak"><label>'.
1.362 raeburn 400: '<input type="radio" name="'.$name.'" '.
401: 'value="'.$val.'"'.$checked.' />'.
1.306 raeburn 402: $reqtitles{$option}.'</label> ';
403: if ($option eq 'autolimit') {
1.362 raeburn 404: $custdisp .= '<input type="text" name="'.$name.
405: '_limit" size="1" '.
1.314 raeburn 406: 'value="'.$currlimit.'" /></span><br />'.
407: $reqtitles{'unlimited'};
1.362 raeburn 408: } else {
409: $custdisp .= '</span>';
410: }
411: $custdisp .= '</td></tr>';
1.306 raeburn 412: }
413: $custdisp .= '</table>';
414: $custradio = '</span></td><td>'.&mt('Custom setting').'<br />'.$custdisp;
415: } else {
416: $currdisp = ($curr_access?&mt('Yes'):&mt('No'));
1.362 raeburn 417: my $name = $context.'_'.$item;
418: if ($context eq 'requestauthor') {
419: $name = $context;
420: }
1.306 raeburn 421: $custdisp = '<span class="LC_nobreak"><label>'.
1.362 raeburn 422: '<input type="radio" name="'.$name.'"'.
1.361 raeburn 423: ' value="1" '.$tool_on.'/>'.&mt('On').'</label> <label>'.
1.362 raeburn 424: '<input type="radio" name="'.$name.'" value="0" '.
1.306 raeburn 425: $tool_off.'/>'.&mt('Off').'</label></span>';
426: $custradio = (' 'x2).'--'.$lt{'cusa'}.': '.$custdisp.
427: '</span>';
428: }
429: $output .= ' <td'.$colspan.'>'.$custom_access.(' 'x4).
430: $lt{'avai'}.': '.$currdisp.'</td>'."\n".
1.275 raeburn 431: &Apache::loncommon::end_data_table_row()."\n".
432: &Apache::loncommon::start_data_table_row()."\n".
1.306 raeburn 433: ' <td style="vertical-align:top;"><span class="LC_nobreak">'.
434: $lt{'chse'}.': <label>'.
1.275 raeburn 435: '<input type="radio" name="custom'.$item.'" value="0" '.
1.306 raeburn 436: $cust_off.'/>'.$lt{'usde'}.'</label>'.(' ' x3).
437: '<label><input type="radio" name="custom'.$item.'" value="1" '.
438: $cust_on.'/>'.$lt{'uscu'}.'</label>'.$custradio.'</td>'.
1.275 raeburn 439: &Apache::loncommon::end_data_table_row()."\n";
440: }
441: return $output;
442: }
443:
1.300 raeburn 444: sub coursereq_externaluser {
445: my ($ccuname,$ccdomain,$cdom) = @_;
1.306 raeburn 446: my (@usertools,@options,%validations,%userenv,$output);
1.300 raeburn 447: my %lt = &Apache::lonlocal::texthash (
448: 'official' => 'Can request creation of official courses',
449: 'unofficial' => 'Can request creation of unofficial courses',
450: 'community' => 'Can request creation of communities',
1.384 raeburn 451: 'textbook' => 'Can request creation of textbook courses',
1.411 raeburn 452: 'placement' => 'Can request creation of placement tests',
1.300 raeburn 453: );
454:
455: %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
456: 'reqcrsotherdom.official','reqcrsotherdom.unofficial',
1.411 raeburn 457: 'reqcrsotherdom.community','reqcrsotherdom.textbook',
458: 'reqcrsotherdom.placement');
459: @usertools = ('official','unofficial','community','textbook','placement');
1.309 raeburn 460: @options = ('approval','validate','autolimit');
1.306 raeburn 461: %validations = &Apache::lonnet::auto_courserequest_checks($cdom);
462: my $optregex = join('|',@options);
463: my %reqtitles = &courserequest_titles();
1.300 raeburn 464: foreach my $item (@usertools) {
1.306 raeburn 465: my ($curroption,$currlimit,$tooloff);
1.300 raeburn 466: if ($userenv{'reqcrsotherdom.'.$item} ne '') {
467: my @curr = split(',',$userenv{'reqcrsotherdom.'.$item});
1.314 raeburn 468: foreach my $req (@curr) {
469: if ($req =~ /^\Q$cdom\E\:($optregex)=?(\d*)$/) {
470: $curroption = $1;
471: $currlimit = $2;
472: last;
1.306 raeburn 473: }
474: }
1.314 raeburn 475: if (!$curroption) {
476: $curroption = 'norequest';
477: $tooloff = ' checked="checked"';
478: }
1.306 raeburn 479: } else {
480: $curroption = 'norequest';
481: $tooloff = ' checked="checked"';
482: }
483: $output.= &Apache::loncommon::start_data_table_row()."\n".
1.314 raeburn 484: ' <td><span class="LC_nobreak">'.$lt{$item}.': </span></td><td>'.
485: '<table><tr><td valign="top">'."\n".
1.306 raeburn 486: '<label><input type="radio" name="reqcrsotherdom_'.$item.
1.314 raeburn 487: '" value=""'.$tooloff.' />'.$reqtitles{'norequest'}.
488: '</label></td>';
1.306 raeburn 489: foreach my $option (@options) {
490: if ($option eq 'validate') {
491: my $canvalidate = 0;
492: if (ref($validations{$item}) eq 'HASH') {
493: if ($validations{$item}{'_external_'}) {
494: $canvalidate = 1;
495: }
496: }
497: next if (!$canvalidate);
498: }
499: my $checked = '';
500: if ($option eq $curroption) {
501: $checked = ' checked="checked"';
502: }
1.314 raeburn 503: $output .= '<td valign="top"><span class="LC_nobreak"><label>'.
1.306 raeburn 504: '<input type="radio" name="reqcrsotherdom_'.$item.
505: '" value="'.$option.'"'.$checked.' />'.
1.314 raeburn 506: $reqtitles{$option}.'</label>';
1.306 raeburn 507: if ($option eq 'autolimit') {
1.314 raeburn 508: $output .= ' <input type="text" name="reqcrsotherdom_'.
1.306 raeburn 509: $item.'_limit" size="1" '.
1.314 raeburn 510: 'value="'.$currlimit.'" /></span>'.
511: '<br />'.$reqtitles{'unlimited'};
512: } else {
513: $output .= '</span>';
1.300 raeburn 514: }
1.314 raeburn 515: $output .= '</td>';
1.300 raeburn 516: }
1.314 raeburn 517: $output .= '</td></tr></table></td>'."\n".
1.300 raeburn 518: &Apache::loncommon::end_data_table_row()."\n";
519: }
520: return $output;
521: }
522:
1.362 raeburn 523: sub domainrole_req {
524: my ($ccuname,$ccdomain) = @_;
525: return '<br /><h3>'.
526: &mt('User Can Request Assignment of Domain Roles?').
527: '</h3>'."\n".
528: &Apache::loncommon::start_data_table().
529: &build_tools_display($ccuname,$ccdomain,
530: 'requestauthor').
531: &Apache::loncommon::end_data_table();
532: }
533:
1.414 raeburn 534: sub domadhocroles {
535: my ($ccuname,$ccdomain) = @_;
536: my $confname = &Apache::lonnet::get_domainconfiguser($env{'request.role.domain'});
537: my %existing=&Apache::lonnet::dump('roles',$env{'request.role.domain'},
538: $confname,'rolesdef_');
539: my $output;
540: if (keys(%existing) > 0) {
541: my @current;
542: my $curradhoc = 'adhocroles.'.$env{'request.role.domain'};
543: my %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,$curradhoc);
544: if ($userenv{$curradhoc}) {
545: @current = split(/,/,$userenv{$curradhoc});
546: }
547: my %customroles;
548: foreach my $key (keys(%existing)) {
549: if ($key=~/^rolesdef\_(\w+)$/) {
550: my $rolename = $1;
551: my %privs;
552: ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
553: $customroles{$rolename} = \%privs;
554: }
555: }
556: $output = '<br /><h3>'.
557: &mt('Ad Hoc Course Roles Selectable via Helpdesk Role').
558: '</h3>'."\n".
559: &Apache::loncommon::start_data_table().
560: &Apache::loncommon::start_data_table_header_row().
561: '<th>'.&mt('Action').'</th><th>'.&mt('Role').'</th>'.
562: '<th>'.&mt('Privileges in Course').'<th>'.
563: &Apache::loncommon::end_data_table_header_row();
564: foreach my $key (sort(keys(%customroles))) {
565: $output .= &Apache::loncommon::start_data_table_row();
566: if (grep(/^\Q$key\E$/,@current)) {
567: $output .= '<td><label>'.
568: '<input type="checkbox" name="adhocroledel" value="'.$key.'" />'.
569: &mt('Delete').'</label>'.
570: '</td>';
571: } else {
572: $output .= '<td><label>'.
573: '<input type="checkbox" name="adhocroleadd" value="'.$key.'" />'.
574: &mt('Add').'</label>'.
575: '</td>';
576: }
577: $output .= '<td>'.$key.'</td><td>';
578: foreach my $level ('course','domain','system') {
579: if ($customroles{$key}{$level}) {
580: my $suffix;
581: if (($level eq 'domain') || ($level eq 'system')) {
582: $suffix = ' ('.&mt($level).')';
583: }
584: my @privs = split(/:/,$customroles{$key}{$level});
585: foreach my $item (@privs) {
586: next if ($item eq '');
587: my ($priv,$cond) = split(/\&/,$item);
588: $output .= &Apache::lonnet::plaintext($priv,'Course').$suffix.'<br />';
589: }
590: }
591: }
592: $output .= '</td>'.
593: &Apache::loncommon::end_data_table_row();
594: }
595: $output .= &Apache::loncommon::end_data_table();
596: }
597: return $output;
598: }
599:
1.306 raeburn 600: sub courserequest_titles {
601: my %titles = &Apache::lonlocal::texthash (
602: official => 'Official',
603: unofficial => 'Unofficial',
604: community => 'Communities',
1.384 raeburn 605: textbook => 'Textbook',
1.411 raeburn 606: placement => 'Placement Tests',
1.306 raeburn 607: norequest => 'Not allowed',
1.309 raeburn 608: approval => 'Approval by Dom. Coord.',
1.306 raeburn 609: validate => 'With validation',
610: autolimit => 'Numerical limit',
1.314 raeburn 611: unlimited => '(blank for unlimited)',
1.306 raeburn 612: );
613: return %titles;
614: }
615:
616: sub courserequest_display {
617: my %titles = &Apache::lonlocal::texthash (
1.309 raeburn 618: approval => 'Yes, need approval',
1.306 raeburn 619: validate => 'Yes, with validation',
620: norequest => 'No',
621: );
622: return %titles;
623: }
624:
1.362 raeburn 625: sub requestauthor_titles {
626: my %titles = &Apache::lonlocal::texthash (
627: norequest => 'Not allowed',
628: approval => 'Approval by Dom. Coord.',
629: automatic => 'Automatic approval',
630: );
631: return %titles;
632:
633: }
634:
635: sub requestauthor_display {
636: my %titles = &Apache::lonlocal::texthash (
637: approval => 'Yes, need approval',
638: automatic => 'Yes, automatic approval',
639: norequest => 'No',
640: );
641: return %titles;
642: }
643:
1.383 raeburn 644: sub requestchange_display {
645: my %titles = &Apache::lonlocal::texthash (
646: approval => "availability set to 'on' (approval required)",
647: automatic => "availability set to 'on' (automatic approval)",
648: norequest => "availability set to 'off'",
649: );
650: return %titles;
651: }
652:
1.362 raeburn 653: sub curr_requestauthor {
654: my ($uname,$udom,$isadv,$inststatuses,$domconfig) = @_;
655: return unless ((ref($inststatuses) eq 'ARRAY') && (ref($domconfig) eq 'HASH'));
656: if ($uname eq '' || $udom eq '') {
657: $uname = $env{'user.name'};
658: $udom = $env{'user.domain'};
659: $isadv = $env{'user.adv'};
660: }
661: my (%userenv,%settings,$val);
662: my @options = ('automatic','approval');
663: %userenv =
664: &Apache::lonnet::userenvironment($udom,$uname,'requestauthor','inststatus');
665: if ($userenv{'requestauthor'}) {
666: $val = $userenv{'requestauthor'};
667: @{$inststatuses} = ('_custom_');
668: } else {
669: my %alltasks;
670: if (ref($domconfig->{'requestauthor'}) eq 'HASH') {
671: %settings = %{$domconfig->{'requestauthor'}};
672: if (($isadv) && ($settings{'_LC_adv'} ne '')) {
673: $val = $settings{'_LC_adv'};
674: @{$inststatuses} = ('_LC_adv_');
675: } else {
676: if ($userenv{'inststatus'} ne '') {
677: @{$inststatuses} = split(',',$userenv{'inststatus'});
678: } else {
679: @{$inststatuses} = ('default');
680: }
681: foreach my $status (@{$inststatuses}) {
682: if (exists($settings{$status})) {
683: my $value = $settings{$status};
684: next unless ($value);
685: unless (exists($alltasks{$value})) {
686: if (ref($alltasks{$value}) eq 'ARRAY') {
687: unless(grep(/^\Q$status\E$/,@{$alltasks{$value}})) {
688: push(@{$alltasks{$value}},$status);
689: }
690: } else {
691: @{$alltasks{$value}} = ($status);
692: }
693: }
694: }
695: }
696: foreach my $option (@options) {
697: if ($alltasks{$option}) {
698: $val = $option;
699: last;
700: }
701: }
702: }
703: }
704: }
705: return $val;
706: }
707:
1.2 www 708: # =================================================================== Phase one
1.1 www 709:
1.42 matthew 710: sub print_username_entry_form {
1.351 raeburn 711: my ($r,$context,$response,$srch,$forcenewuser,$crstype,$brcrum) = @_;
1.101 albertel 712: my $defdom=$env{'request.role.domain'};
1.160 raeburn 713: my $formtoset = 'crtuser';
714: if (exists($env{'form.startrolename'})) {
715: $formtoset = 'docustom';
716: $env{'form.rolename'} = $env{'form.startrolename'};
1.207 raeburn 717: } elsif ($env{'form.origform'} eq 'crtusername') {
718: $formtoset = $env{'form.origform'};
1.160 raeburn 719: }
720:
721: my ($jsback,$elements) = &crumb_utilities();
722:
723: my $jscript = &Apache::loncommon::studentbrowser_javascript()."\n".
1.165 albertel 724: '<script type="text/javascript">'."\n".
1.301 bisitz 725: '// <![CDATA['."\n".
726: &Apache::lonhtmlcommon::set_form_elements($elements->{$formtoset})."\n".
727: '// ]]>'."\n".
1.162 raeburn 728: '</script>'."\n";
1.160 raeburn 729:
1.324 raeburn 730: my %existingroles=&Apache::lonuserutils::my_custom_roles($crstype);
731: if (($env{'form.action'} eq 'custom') && (keys(%existingroles) > 0)
732: && (&Apache::lonnet::allowed('mcr','/'))) {
733: $jscript .= &customrole_javascript();
734: }
1.224 raeburn 735: my $helpitem = 'Course_Change_Privileges';
736: if ($env{'form.action'} eq 'custom') {
737: $helpitem = 'Course_Editing_Custom_Roles';
738: } elsif ($env{'form.action'} eq 'singlestudent') {
739: $helpitem = 'Course_Add_Student';
1.416 ! raeburn 740: } elsif ($env{'form.action'} eq 'accesslogs') {
! 741: $helpitem = 'Domain_User_Access_Logs';
1.224 raeburn 742: }
1.351 raeburn 743: my %breadcrumb_text = &singleuser_breadcrumb($crstype);
744: if ($env{'form.action'} eq 'custom') {
745: push(@{$brcrum},
746: {href=>"javascript:backPage(document.crtuser)",
747: text=>"Pick custom role",
748: help => $helpitem,}
749: );
750: } else {
751: push (@{$brcrum},
752: {href => "javascript:backPage(document.crtuser)",
753: text => $breadcrumb_text{'search'},
754: help => $helpitem,
755: faq => 282,
756: bug => 'Instructor Interface',}
757: );
758: }
759: my %loaditems = (
760: 'onload' => "javascript:setFormElements(document.$formtoset)",
761: );
762: my $args = {bread_crumbs => $brcrum,
763: bread_crumbs_component => 'User Management',
764: add_entries => \%loaditems,};
765: $r->print(&Apache::loncommon::start_page('User Management',$jscript,$args));
766:
1.71 sakharuk 767: my %lt=&Apache::lonlocal::texthash(
1.229 raeburn 768: 'srst' => 'Search for a user and enroll as a student',
1.318 raeburn 769: 'srme' => 'Search for a user and enroll as a member',
1.229 raeburn 770: 'srad' => 'Search for a user and modify/add user information or roles',
1.416 ! raeburn 771: 'srva' => 'Search for a user and view access log information',
1.71 sakharuk 772: 'usr' => "Username",
773: 'dom' => "Domain",
1.324 raeburn 774: 'ecrp' => "Define or Edit Custom Role",
775: 'nr' => "role name",
1.282 schafran 776: 'cre' => "Next",
1.71 sakharuk 777: );
1.351 raeburn 778:
1.214 raeburn 779: if ($env{'form.action'} eq 'custom') {
1.190 raeburn 780: if (&Apache::lonnet::allowed('mcr','/')) {
1.324 raeburn 781: my $newroletext = &mt('Define new custom role:');
782: $r->print('<form action="/adm/createuser" method="post" name="docustom">'.
783: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'.
784: '<input type="hidden" name="phase" value="selected_custom_edit" />'.
785: '<h3>'.$lt{'ecrp'}.'</h3>'.
786: &Apache::loncommon::start_data_table().
787: &Apache::loncommon::start_data_table_row().
788: '<td>');
789: if (keys(%existingroles) > 0) {
790: $r->print('<br /><label><input type="radio" name="customroleaction" value="new" checked="checked" onclick="setCustomFields();" /><b>'.$newroletext.'</b></label>');
791: } else {
792: $r->print('<br /><input type="hidden" name="customroleaction" value="new" /><b>'.$newroletext.'</b>');
793: }
794: $r->print('</td><td align="center">'.$lt{'nr'}.'<br /><input type="text" size="15" name="newrolename" onfocus="setCustomAction('."'new'".');" /></td>'.
795: &Apache::loncommon::end_data_table_row());
796: if (keys(%existingroles) > 0) {
797: $r->print(&Apache::loncommon::start_data_table_row().'<td><br />'.
798: '<label><input type="radio" name="customroleaction" value="edit" onclick="setCustomFields();"/><b>'.
799: &mt('View/Modify existing role:').'</b></label></td>'.
800: '<td align="center"><br />'.
801: '<select name="rolename" onchange="setCustomAction('."'edit'".');">'.
1.326 raeburn 802: '<option value="" selected="selected">'.
1.324 raeburn 803: &mt('Select'));
804: foreach my $role (sort(keys(%existingroles))) {
1.326 raeburn 805: $r->print('<option value="'.$role.'">'.$role.'</option>');
1.324 raeburn 806: }
807: $r->print('</select>'.
808: '</td>'.
809: &Apache::loncommon::end_data_table_row());
810: }
811: $r->print(&Apache::loncommon::end_data_table().'<p>'.
812: '<input name="customeditor" type="submit" value="'.
813: $lt{'cre'}.'" /></p>'.
814: '</form>');
1.190 raeburn 815: }
1.213 raeburn 816: } else {
1.229 raeburn 817: my $actiontext = $lt{'srad'};
1.213 raeburn 818: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 819: if ($crstype eq 'Community') {
820: $actiontext = $lt{'srme'};
821: } else {
822: $actiontext = $lt{'srst'};
823: }
1.416 ! raeburn 824: } elsif ($env{'form.action'} eq 'accesslogs') {
! 825: $actiontext = $lt{'srva'};
1.213 raeburn 826: }
1.324 raeburn 827: $r->print("<h3>$actiontext</h3>");
1.213 raeburn 828: if ($env{'form.origform'} ne 'crtusername') {
1.415 raeburn 829: if ($response) {
830: $r->print("\n<div>$response</div>".
831: '<br clear="all" />');
832: }
1.213 raeburn 833: }
1.416 ! raeburn 834: $r->print(&entry_form($defdom,$srch,$forcenewuser,$context,$response,$crstype,1));
1.107 www 835: }
1.110 albertel 836: }
837:
1.324 raeburn 838: sub customrole_javascript {
839: my $js = <<"END";
840: <script type="text/javascript">
841: // <![CDATA[
842:
843: function setCustomFields() {
844: if (document.docustom.customroleaction.length > 0) {
845: for (var i=0; i<document.docustom.customroleaction.length; i++) {
846: if (document.docustom.customroleaction[i].checked) {
847: if (document.docustom.customroleaction[i].value == 'new') {
848: document.docustom.rolename.selectedIndex = 0;
849: } else {
850: document.docustom.newrolename.value = '';
851: }
852: }
853: }
854: }
855: return;
856: }
857:
858: function setCustomAction(caller) {
859: if (document.docustom.customroleaction.length > 0) {
860: for (var i=0; i<document.docustom.customroleaction.length; i++) {
861: if (document.docustom.customroleaction[i].value == caller) {
862: document.docustom.customroleaction[i].checked = true;
863: }
864: }
865: }
866: setCustomFields();
867: return;
868: }
869:
870: // ]]>
871: </script>
872: END
873: return $js;
874: }
875:
1.160 raeburn 876: sub entry_form {
1.416 ! raeburn 877: my ($dom,$srch,$forcenewuser,$context,$responsemsg,$crstype,$fixeddom) = @_;
1.229 raeburn 878: my ($usertype,$inexact);
1.214 raeburn 879: if (ref($srch) eq 'HASH') {
880: if (($srch->{'srchin'} eq 'dom') &&
881: ($srch->{'srchby'} eq 'uname') &&
882: ($srch->{'srchtype'} eq 'exact') &&
883: ($srch->{'srchdomain'} ne '') &&
884: ($srch->{'srchterm'} ne '')) {
1.353 raeburn 885: my (%curr_rules,%got_rules);
1.214 raeburn 886: my ($rules,$ruleorder) =
887: &Apache::lonnet::inst_userrules($srch->{'srchdomain'},'username');
1.353 raeburn 888: $usertype = &Apache::lonuserutils::check_usertype($srch->{'srchdomain'},$srch->{'srchterm'},$rules,\%curr_rules,\%got_rules);
1.229 raeburn 889: } else {
890: $inexact = 1;
1.214 raeburn 891: }
1.207 raeburn 892: }
1.214 raeburn 893: my $cancreate =
894: &Apache::lonuserutils::can_create_user($dom,$context,$usertype);
1.412 raeburn 895: my ($userpicker,$cansearch) =
1.179 raeburn 896: &Apache::loncommon::user_picker($dom,$srch,$forcenewuser,
1.416 ! raeburn 897: 'document.crtuser',$cancreate,$usertype,$context,$fixeddom);
1.160 raeburn 898: my $srchbutton = &mt('Search');
1.229 raeburn 899: if ($env{'form.action'} eq 'singlestudent') {
900: $srchbutton = &mt('Search and Enroll');
1.416 ! raeburn 901: } elsif ($env{'form.action'} eq 'accesslogs') {
! 902: $srchbutton = &mt('Search');
1.229 raeburn 903: } elsif ($cancreate && $responsemsg ne '' && $inexact) {
904: $srchbutton = &mt('Search or Add New User');
905: }
1.412 raeburn 906: my $output;
907: if ($cansearch) {
908: $output = <<"ENDBLOCK";
1.160 raeburn 909: <form action="/adm/createuser" method="post" name="crtuser">
1.190 raeburn 910: <input type="hidden" name="action" value="$env{'form.action'}" />
1.160 raeburn 911: <input type="hidden" name="phase" value="get_user_info" />
912: $userpicker
1.179 raeburn 913: <input name="userrole" type="button" value="$srchbutton" onclick="javascript:validateEntry(document.crtuser)" />
1.160 raeburn 914: </form>
1.207 raeburn 915: ENDBLOCK
1.412 raeburn 916: } else {
917: $output = '<p>'.$userpicker.'</p>';
918: }
1.416 ! raeburn 919: if (($env{'form.phase'} eq '') && ($env{'form.action'} ne 'accesslogs')) {
1.207 raeburn 920: my $defdom=$env{'request.role.domain'};
921: my $domform = &Apache::loncommon::select_dom_form($defdom,'srchdomain');
922: my %lt=&Apache::lonlocal::texthash(
1.229 raeburn 923: 'enro' => 'Enroll one student',
1.318 raeburn 924: 'enrm' => 'Enroll one member',
1.229 raeburn 925: 'admo' => 'Add/modify a single user',
926: 'crea' => 'create new user if required',
927: 'uskn' => "username is known",
1.207 raeburn 928: 'crnu' => 'Create a new user',
929: 'usr' => 'Username',
930: 'dom' => 'in domain',
1.229 raeburn 931: 'enrl' => 'Enroll',
932: 'cram' => 'Create/Modify user',
1.207 raeburn 933: );
1.229 raeburn 934: my $sellink=&Apache::loncommon::selectstudent_link('crtusername','srchterm','srchdomain');
935: my ($title,$buttontext,$showresponse);
1.318 raeburn 936: if ($env{'form.action'} eq 'singlestudent') {
937: if ($crstype eq 'Community') {
938: $title = $lt{'enrm'};
939: } else {
940: $title = $lt{'enro'};
941: }
1.229 raeburn 942: $buttontext = $lt{'enrl'};
943: } else {
944: $title = $lt{'admo'};
945: $buttontext = $lt{'cram'};
946: }
947: if ($cancreate) {
948: $title .= ' <span class="LC_cusr_subheading">('.$lt{'crea'}.')</span>';
949: } else {
950: $title .= ' <span class="LC_cusr_subheading">('.$lt{'uskn'}.')</span>';
951: }
952: if ($env{'form.origform'} eq 'crtusername') {
953: $showresponse = $responsemsg;
954: }
1.207 raeburn 955: $output .= <<"ENDDOCUMENT";
1.229 raeburn 956: <br />
1.207 raeburn 957: <form action="/adm/createuser" method="post" name="crtusername">
958: <input type="hidden" name="action" value="$env{'form.action'}" />
959: <input type="hidden" name="phase" value="createnewuser" />
960: <input type="hidden" name="srchtype" value="exact" />
1.233 raeburn 961: <input type="hidden" name="srchby" value="uname" />
1.207 raeburn 962: <input type="hidden" name="srchin" value="dom" />
963: <input type="hidden" name="forcenewuser" value="1" />
964: <input type="hidden" name="origform" value="crtusername" />
1.229 raeburn 965: <h3>$title</h3>
966: $showresponse
1.207 raeburn 967: <table>
968: <tr>
969: <td>$lt{'usr'}:</td>
970: <td><input type="text" size="15" name="srchterm" /></td>
971: <td> $lt{'dom'}:</td><td>$domform</td>
1.229 raeburn 972: <td> $sellink </td>
973: <td> <input name="userrole" type="submit" value="$buttontext" /></td>
1.207 raeburn 974: </tr>
975: </table>
976: </form>
1.160 raeburn 977: ENDDOCUMENT
1.207 raeburn 978: }
1.160 raeburn 979: return $output;
980: }
1.110 albertel 981:
982: sub user_modification_js {
1.113 raeburn 983: my ($pjump_def,$dc_setcourse_code,$nondc_setsection_code,$groupslist)=@_;
984:
1.110 albertel 985: return <<END;
986: <script type="text/javascript" language="Javascript">
1.301 bisitz 987: // <![CDATA[
1.314 raeburn 988:
1.110 albertel 989: $pjump_def
990: $dc_setcourse_code
991:
992: function dateset() {
993: eval("document.cu."+document.cu.pres_marker.value+
994: ".value=document.cu.pres_value.value");
1.359 www 995: modalWindow.close();
1.110 albertel 996: }
997:
1.113 raeburn 998: $nondc_setsection_code
1.301 bisitz 999: // ]]>
1.110 albertel 1000: </script>
1001: END
1.2 www 1002: }
1003:
1004: # =================================================================== Phase two
1.160 raeburn 1005: sub print_user_selection_page {
1.351 raeburn 1006: my ($r,$response,$srch,$srch_results,$srcharray,$context,$opener_elements,$crstype,$brcrum) = @_;
1.160 raeburn 1007: my @fields = ('username','domain','lastname','firstname','permanentemail');
1008: my $sortby = $env{'form.sortby'};
1009:
1010: if (!grep(/^\Q$sortby\E$/,@fields)) {
1011: $sortby = 'lastname';
1012: }
1013:
1014: my ($jsback,$elements) = &crumb_utilities();
1015:
1016: my $jscript = (<<ENDSCRIPT);
1017: <script type="text/javascript">
1.301 bisitz 1018: // <![CDATA[
1.160 raeburn 1019: function pickuser(uname,udom) {
1020: document.usersrchform.seluname.value=uname;
1021: document.usersrchform.seludom.value=udom;
1022: document.usersrchform.phase.value="userpicked";
1023: document.usersrchform.submit();
1024: }
1025:
1026: $jsback
1.301 bisitz 1027: // ]]>
1.160 raeburn 1028: </script>
1029: ENDSCRIPT
1030:
1031: my %lt=&Apache::lonlocal::texthash(
1.179 raeburn 1032: 'usrch' => "User Search to add/modify roles",
1033: 'stusrch' => "User Search to enroll student",
1.318 raeburn 1034: 'memsrch' => "User Search to enroll member",
1.416 ! raeburn 1035: 'srcva' => "Search for a user and view access log information",
1.179 raeburn 1036: 'usel' => "Select a user to add/modify roles",
1.318 raeburn 1037: 'stusel' => "Select a user to enroll as a student",
1038: 'memsel' => "Select a user to enroll as a member",
1.416 ! raeburn 1039: 'vacsel' => "Select a user to view access log",
1.160 raeburn 1040: 'username' => "username",
1041: 'domain' => "domain",
1042: 'lastname' => "last name",
1043: 'firstname' => "first name",
1044: 'permanentemail' => "permanent e-mail",
1045: );
1.302 raeburn 1046: if ($context eq 'requestcrs') {
1047: $r->print('<div>');
1048: } else {
1.318 raeburn 1049: my %breadcrumb_text = &singleuser_breadcrumb($crstype);
1.351 raeburn 1050: my $helpitem;
1051: if ($env{'form.action'} eq 'singleuser') {
1052: $helpitem = 'Course_Change_Privileges';
1053: } elsif ($env{'form.action'} eq 'singlestudent') {
1054: $helpitem = 'Course_Add_Student';
1055: }
1056: push (@{$brcrum},
1057: {href => "javascript:backPage(document.usersrchform,'','')",
1058: text => $breadcrumb_text{'search'},
1059: faq => 282,
1060: bug => 'Instructor Interface',},
1061: {href => "javascript:backPage(document.usersrchform,'get_user_info','select')",
1062: text => $breadcrumb_text{'userpicked'},
1063: faq => 282,
1064: bug => 'Instructor Interface',
1065: help => $helpitem}
1066: );
1067: $r->print(&Apache::loncommon::start_page('User Management',$jscript,{bread_crumbs => $brcrum}));
1.302 raeburn 1068: if ($env{'form.action'} eq 'singleuser') {
1069: $r->print("<b>$lt{'usrch'}</b><br />");
1.318 raeburn 1070: $r->print(&entry_form($srch->{'srchdomain'},$srch,undef,$context,undef,$crstype));
1.302 raeburn 1071: $r->print('<h3>'.$lt{'usel'}.'</h3>');
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 />");
! 1090: $r->print(&entry_form($srch->{'srchdomain'},$srch,undef,'accesslogs',undef,undef,1));
! 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.351 raeburn 1171: &print_username_entry_form($r,$context,$usermsg,'','',$crstype,$brcrum);
1.58 www 1172: return;
1173: }
1.213 raeburn 1174: my ($form,$formname);
1175: if ($env{'form.action'} eq 'singlestudent') {
1176: $form = 'document.enrollstudent';
1177: $formname = 'enrollstudent';
1178: } else {
1179: $form = 'document.cu';
1180: $formname = 'cu';
1181: }
1.188 raeburn 1182: my %abv_auth = &auth_abbrev();
1.227 raeburn 1183: my (%rulematch,%inst_results,$newuser,%alerts,%curr_rules,%got_rules);
1.185 raeburn 1184: my $uhome=&Apache::lonnet::homeserver($ccuname,$ccdomain);
1185: if ($uhome eq 'no_host') {
1.215 raeburn 1186: my $usertype;
1187: my ($rules,$ruleorder) =
1188: &Apache::lonnet::inst_userrules($ccdomain,'username');
1189: $usertype =
1.353 raeburn 1190: &Apache::lonuserutils::check_usertype($ccdomain,$ccuname,$rules,
1.362 raeburn 1191: \%curr_rules,\%got_rules);
1.215 raeburn 1192: my $cancreate =
1193: &Apache::lonuserutils::can_create_user($ccdomain,$context,
1194: $usertype);
1195: if (!$cancreate) {
1.292 bisitz 1196: my $helplink = 'javascript:helpMenu('."'display'".')';
1.215 raeburn 1197: my %usertypetext = (
1198: official => 'institutional',
1199: unofficial => 'non-institutional',
1200: );
1201: my $response;
1202: if ($env{'form.origform'} eq 'crtusername') {
1.362 raeburn 1203: $response = '<span class="LC_warning">'.
1204: &mt('No match found for the username [_1] in LON-CAPA domain: [_2]',
1205: '<b>'.$ccuname.'</b>',$ccdomain).
1.215 raeburn 1206: '</span><br />';
1207: }
1.292 bisitz 1208: $response .= '<p class="LC_warning">'
1209: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
1210: .' '
1211: .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
1212: ,'<a href="'.$helplink.'">','</a>')
1213: .'</p><br />';
1.215 raeburn 1214: $env{'form.phase'} = '';
1.351 raeburn 1215: &print_username_entry_form($r,$context,$response,undef,undef,$crstype,$brcrum);
1.215 raeburn 1216: return;
1217: }
1.188 raeburn 1218: $newuser = 1;
1.193 raeburn 1219: my $checkhash;
1220: my $checks = { 'username' => 1 };
1.196 raeburn 1221: $checkhash->{$ccuname.':'.$ccdomain} = { 'newuser' => $newuser };
1.193 raeburn 1222: &Apache::loncommon::user_rule_check($checkhash,$checks,
1.196 raeburn 1223: \%alerts,\%rulematch,\%inst_results,\%curr_rules,\%got_rules);
1224: if (ref($alerts{'username'}) eq 'HASH') {
1225: if (ref($alerts{'username'}{$ccdomain}) eq 'HASH') {
1226: my $domdesc =
1.193 raeburn 1227: &Apache::lonnet::domain($ccdomain,'description');
1.196 raeburn 1228: if ($alerts{'username'}{$ccdomain}{$ccuname}) {
1229: my $userchkmsg;
1230: if (ref($curr_rules{$ccdomain}) eq 'HASH') {
1231: $userchkmsg =
1232: &Apache::loncommon::instrule_disallow_msg('username',
1.193 raeburn 1233: $domdesc,1).
1234: &Apache::loncommon::user_rule_formats($ccdomain,
1235: $domdesc,$curr_rules{$ccdomain}{'username'},
1236: 'username');
1.196 raeburn 1237: }
1.215 raeburn 1238: $env{'form.phase'} = '';
1.351 raeburn 1239: &print_username_entry_form($r,$context,$userchkmsg,undef,undef,$crstype,$brcrum);
1.196 raeburn 1240: return;
1.215 raeburn 1241: }
1.193 raeburn 1242: }
1.185 raeburn 1243: }
1.187 raeburn 1244: } else {
1.188 raeburn 1245: $newuser = 0;
1.185 raeburn 1246: }
1.160 raeburn 1247: if ($response) {
1.215 raeburn 1248: $response = '<br />'.$response;
1.160 raeburn 1249: }
1.149 raeburn 1250:
1.52 matthew 1251: my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
1.88 raeburn 1252: my $dc_setcourse_code = '';
1.119 raeburn 1253: my $nondc_setsection_code = '';
1.112 albertel 1254: my %loaditem;
1.114 albertel 1255:
1.216 raeburn 1256: my $groupslist = &Apache::lonuserutils::get_groupslist();
1.88 raeburn 1257:
1.375 raeburn 1258: my $js = &validation_javascript($context,$ccdomain,$pjump_def,$crstype,
1.216 raeburn 1259: $groupslist,$newuser,$formname,\%loaditem);
1.318 raeburn 1260: my %breadcrumb_text = &singleuser_breadcrumb($crstype);
1.224 raeburn 1261: my $helpitem = 'Course_Change_Privileges';
1262: if ($env{'form.action'} eq 'singlestudent') {
1263: $helpitem = 'Course_Add_Student';
1264: }
1.351 raeburn 1265: push (@{$brcrum},
1266: {href => "javascript:backPage($form)",
1267: text => $breadcrumb_text{'search'},
1268: faq => 282,
1269: bug => 'Instructor Interface',});
1270: if ($env{'form.phase'} eq 'userpicked') {
1271: push(@{$brcrum},
1272: {href => "javascript:backPage($form,'get_user_info','select')",
1273: text => $breadcrumb_text{'userpicked'},
1274: faq => 282,
1275: bug => 'Instructor Interface',});
1276: }
1277: push(@{$brcrum},
1278: {href => "javascript:backPage($form,'$env{'form.phase'}','modify')",
1279: text => $breadcrumb_text{'modify'},
1280: faq => 282,
1281: bug => 'Instructor Interface',
1282: help => $helpitem});
1283: my $args = {'add_entries' => \%loaditem,
1284: 'bread_crumbs' => $brcrum,
1285: 'bread_crumbs_component' => 'User Management'};
1286: if ($env{'form.popup'}) {
1287: $args->{'no_nav_bar'} = 1;
1288: }
1289: my $start_page =
1290: &Apache::loncommon::start_page('User Management',$js,$args);
1.3 www 1291:
1.25 matthew 1292: my $forminfo =<<"ENDFORMINFO";
1.216 raeburn 1293: <form action="/adm/createuser" method="post" name="$formname">
1.190 raeburn 1294: <input type="hidden" name="phase" value="update_user_data" />
1.188 raeburn 1295: <input type="hidden" name="ccuname" value="$ccuname" />
1296: <input type="hidden" name="ccdomain" value="$ccdomain" />
1.157 albertel 1297: <input type="hidden" name="pres_value" value="" />
1298: <input type="hidden" name="pres_type" value="" />
1299: <input type="hidden" name="pres_marker" value="" />
1.25 matthew 1300: ENDFORMINFO
1.375 raeburn 1301: my (%inccourses,$roledom,$defaultcredits);
1.329 raeburn 1302: if ($context eq 'course') {
1303: $inccourses{$env{'request.course.id'}}=1;
1304: $roledom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1.375 raeburn 1305: if ($showcredits) {
1306: $defaultcredits = &Apache::lonuserutils::get_defaultcredits();
1307: }
1.329 raeburn 1308: } elsif ($context eq 'author') {
1309: $roledom = $env{'request.role.domain'};
1310: } elsif ($context eq 'domain') {
1311: foreach my $key (keys(%env)) {
1312: $roledom = $env{'request.role.domain'};
1313: if ($key=~/^user\.priv\.cm\.\/($roledom)\/($match_username)/) {
1314: $inccourses{$1.'_'.$2}=1;
1315: }
1316: }
1317: } else {
1318: foreach my $key (keys(%env)) {
1319: if ($key=~/^user\.priv\.cm\.\/($match_domain)\/($match_username)/) {
1320: $inccourses{$1.'_'.$2}=1;
1321: }
1.2 www 1322: }
1.24 matthew 1323: }
1.389 bisitz 1324: my $title = '';
1.216 raeburn 1325: if ($newuser) {
1.414 raeburn 1326: my ($portfolioform,$domroleform,$adhocroleform);
1.267 raeburn 1327: if ((&Apache::lonnet::allowed('mpq',$env{'request.role.domain'})) ||
1328: (&Apache::lonnet::allowed('mut',$env{'request.role.domain'}))) {
1329: # Current user has quota or user tools modification privileges
1.378 raeburn 1330: $portfolioform = '<br />'.&user_quotas($ccuname,$ccdomain);
1.134 raeburn 1331: }
1.383 raeburn 1332: if ((&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) &&
1333: ($ccdomain eq $env{'request.role.domain'})) {
1.362 raeburn 1334: $domroleform = '<br />'.&domainrole_req($ccuname,$ccdomain);
1335: }
1.414 raeburn 1336: if (&Apache::lonnet::allowed('cdh',$env{'request.role.domain'})) {
1337: $adhocroleform = &domadhocroles($ccuname,$ccdomain);
1338: if ($adhocroleform) {
1339: $adhocroleform = '<br />'.$adhocroleform;
1340: }
1341: }
1.227 raeburn 1342: &initialize_authen_forms($ccdomain,$formname);
1.188 raeburn 1343: my %lt=&Apache::lonlocal::texthash(
1344: 'lg' => 'Login Data',
1.190 raeburn 1345: 'hs' => "Home Server",
1.188 raeburn 1346: );
1.185 raeburn 1347: $r->print(<<ENDTITLE);
1.110 albertel 1348: $start_page
1.160 raeburn 1349: $response
1.25 matthew 1350: $forminfo
1.31 matthew 1351: <script type="text/javascript" language="Javascript">
1.301 bisitz 1352: // <![CDATA[
1.20 harris41 1353: $loginscript
1.301 bisitz 1354: // ]]>
1.31 matthew 1355: </script>
1.20 harris41 1356: <input type='hidden' name='makeuser' value='1' />
1.185 raeburn 1357: ENDTITLE
1.213 raeburn 1358: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1359: if ($crstype eq 'Community') {
1.389 bisitz 1360: $title = &mt('Create New User [_1] in domain [_2] as a member',
1361: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.318 raeburn 1362: } else {
1.389 bisitz 1363: $title = &mt('Create New User [_1] in domain [_2] as a student',
1364: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.318 raeburn 1365: }
1.389 bisitz 1366: } else {
1367: $title = &mt('Create New User [_1] in domain [_2]',
1368: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.213 raeburn 1369: }
1.389 bisitz 1370: $r->print('<h2>'.$title.'</h2>'."\n");
1371: $r->print('<div class="LC_left_float">');
1.393 raeburn 1372: $r->print(&personal_data_display($ccuname,$ccdomain,$newuser,$context,
1373: $inst_results{$ccuname.':'.$ccdomain}));
1374: # Option to disable student/employee ID conflict checking not offerred for new users.
1.187 raeburn 1375: my ($home_server_pick,$numlib) =
1376: &Apache::loncommon::home_server_form_item($ccdomain,'hserver',
1377: 'default','hide');
1378: if ($numlib > 1) {
1379: $r->print("
1.185 raeburn 1380: <br />
1.187 raeburn 1381: $lt{'hs'}: $home_server_pick
1382: <br />");
1383: } else {
1384: $r->print($home_server_pick);
1385: }
1.304 raeburn 1386: if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
1.362 raeburn 1387: $r->print('<br /><h3>'.
1388: &mt('User Can Request Creation of Courses/Communities in this Domain?').'</h3>'.
1.304 raeburn 1389: &Apache::loncommon::start_data_table().
1390: &build_tools_display($ccuname,$ccdomain,
1391: 'requestcourses').
1392: &Apache::loncommon::end_data_table());
1393: }
1.188 raeburn 1394: $r->print('</div>'."\n".'<div class="LC_left_float"><h3>'.
1395: $lt{'lg'}.'</h3>');
1.185 raeburn 1396: my ($fixedauth,$varauth,$authmsg);
1.193 raeburn 1397: if (ref($rulematch{$ccuname.':'.$ccdomain}) eq 'HASH') {
1398: my $matchedrule = $rulematch{$ccuname.':'.$ccdomain}{'username'};
1399: my ($rules,$ruleorder) =
1400: &Apache::lonnet::inst_userrules($ccdomain,'username');
1.185 raeburn 1401: if (ref($rules) eq 'HASH') {
1.193 raeburn 1402: if (ref($rules->{$matchedrule}) eq 'HASH') {
1403: my $authtype = $rules->{$matchedrule}{'authtype'};
1.185 raeburn 1404: if ($authtype !~ /^(krb4|krb5|int|fsys|loc)$/) {
1.190 raeburn 1405: $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1.275 raeburn 1406: } else {
1.193 raeburn 1407: my $authparm = $rules->{$matchedrule}{'authparm'};
1.273 raeburn 1408: $authmsg = $rules->{$matchedrule}{'authmsg'};
1.185 raeburn 1409: if ($authtype =~ /^krb(4|5)$/) {
1410: my $ver = $1;
1411: if ($authparm ne '') {
1412: $fixedauth = <<"KERB";
1413: <input type="hidden" name="login" value="krb" />
1414: <input type="hidden" name="krbver" value="$ver" />
1415: <input type="hidden" name="krbarg" value="$authparm" />
1416: KERB
1417: }
1418: } else {
1419: $fixedauth =
1420: '<input type="hidden" name="login" value="'.$authtype.'" />'."\n";
1.193 raeburn 1421: if ($rules->{$matchedrule}{'authparmfixed'}) {
1.185 raeburn 1422: $fixedauth .=
1423: '<input type="hidden" name="'.$authtype.'arg" value="'.$authparm.'" />'."\n";
1424: } else {
1.273 raeburn 1425: if ($authtype eq 'int') {
1426: $varauth = '<br />'.
1.301 bisitz 1427: &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 1428: } elsif ($authtype eq 'loc') {
1429: $varauth = '<br />'.
1430: &mt('[_1] Local Authentication with argument [_2]','','<input type="text" name="'.$authtype.'arg" value="" />')."\n";
1431: } else {
1432: $varauth =
1.185 raeburn 1433: '<input type="text" name="'.$authtype.'arg" value="" />'."\n";
1.273 raeburn 1434: }
1.185 raeburn 1435: }
1436: }
1437: }
1438: } else {
1.190 raeburn 1439: $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1.185 raeburn 1440: }
1441: }
1442: if ($authmsg) {
1443: $r->print(<<ENDAUTH);
1444: $fixedauth
1445: $authmsg
1446: $varauth
1447: ENDAUTH
1448: }
1449: } else {
1.190 raeburn 1450: $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1.187 raeburn 1451: }
1.414 raeburn 1452: $r->print($portfolioform.$domroleform.$adhocroleform);
1.215 raeburn 1453: if ($env{'form.action'} eq 'singlestudent') {
1454: $r->print(&date_sections_select($context,$newuser,$formname,
1.375 raeburn 1455: $permission,$crstype,$ccuname,
1456: $ccdomain,$showcredits));
1.215 raeburn 1457: }
1458: $r->print('</div><div class="LC_clear_float_footer"></div>');
1.216 raeburn 1459: } else { # user already exists
1.389 bisitz 1460: $r->print($start_page.$forminfo);
1.213 raeburn 1461: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1462: if ($crstype eq 'Community') {
1.389 bisitz 1463: $title = &mt('Enroll one member: [_1] in domain [_2]',
1464: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.318 raeburn 1465: } else {
1.389 bisitz 1466: $title = &mt('Enroll one student: [_1] in domain [_2]',
1467: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.318 raeburn 1468: }
1.213 raeburn 1469: } else {
1.389 bisitz 1470: $title = &mt('Modify existing user: [_1] in domain [_2]',
1471: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.213 raeburn 1472: }
1.389 bisitz 1473: $r->print('<h2>'.$title.'</h2>'."\n");
1474: $r->print('<div class="LC_left_float">');
1.393 raeburn 1475: $r->print(&personal_data_display($ccuname,$ccdomain,$newuser,$context,
1476: $inst_results{$ccuname.':'.$ccdomain}));
1.275 raeburn 1477: if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
1.362 raeburn 1478: $r->print('<br /><h3>'.&mt('User Can Request Creation of Courses/Communities in this Domain?').'</h3>'.
1.300 raeburn 1479: &Apache::loncommon::start_data_table());
1.314 raeburn 1480: if ($env{'request.role.domain'} eq $ccdomain) {
1.300 raeburn 1481: $r->print(&build_tools_display($ccuname,$ccdomain,'requestcourses'));
1482: } else {
1483: $r->print(&coursereq_externaluser($ccuname,$ccdomain,
1484: $env{'request.role.domain'}));
1485: }
1486: $r->print(&Apache::loncommon::end_data_table());
1.275 raeburn 1487: }
1.199 raeburn 1488: $r->print('</div>');
1.414 raeburn 1489: my @order = ('auth','quota','tools','requestauthor','adhocroles');
1.362 raeburn 1490: my %user_text;
1491: my ($isadv,$isauthor) =
1492: &Apache::lonnet::is_advanced_user($ccuname,$ccdomain);
1493: if ((!$isauthor) &&
1.383 raeburn 1494: (&Apache::lonnet::allowed('cau',$env{'request.role.domain'}))
1495: && ($env{'request.role.domain'} eq $ccdomain)) {
1.362 raeburn 1496: $user_text{'requestauthor'} = &domainrole_req($ccuname,$ccdomain);
1497: }
1.414 raeburn 1498: if (&Apache::lonnet::allowed('cdh',$env{'request.role.domain'})) {
1499: $user_text{'adhocroles'} = &domadhocroles($ccuname,$ccdomain);
1500: }
1.362 raeburn 1501: $user_text{'auth'} = &user_authentication($ccuname,$ccdomain,$formname);
1.267 raeburn 1502: if ((&Apache::lonnet::allowed('mpq',$ccdomain)) ||
1503: (&Apache::lonnet::allowed('mut',$ccdomain))) {
1.188 raeburn 1504: # Current user has quota modification privileges
1.378 raeburn 1505: $user_text{'quota'} = &user_quotas($ccuname,$ccdomain);
1.267 raeburn 1506: }
1507: if (!&Apache::lonnet::allowed('mpq',$ccdomain)) {
1508: if (&Apache::lonnet::allowed('mpq',$env{'request.role.domain'})) {
1509: my %lt=&Apache::lonlocal::texthash(
1.385 bisitz 1510: 'dska' => "Disk quotas for user's portfolio and Authoring Space",
1511: 'youd' => "You do not have privileges to modify the portfolio and/or Authoring Space quotas for this user.",
1.267 raeburn 1512: 'ichr' => "If a change is required, contact a domain coordinator for the domain",
1513: );
1.362 raeburn 1514: $user_text{'quota'} = <<ENDNOPORTPRIV;
1.188 raeburn 1515: <h3>$lt{'dska'}</h3>
1516: $lt{'youd'} $lt{'ichr'}: $ccdomain
1517: ENDNOPORTPRIV
1.267 raeburn 1518: }
1519: }
1520: if (!&Apache::lonnet::allowed('mut',$ccdomain)) {
1521: if (&Apache::lonnet::allowed('mut',$env{'request.role.domain'})) {
1522: my %lt=&Apache::lonlocal::texthash(
1523: 'utav' => "User Tools Availability",
1.361 raeburn 1524: 'yodo' => "You do not have privileges to modify Portfolio, Blog, WebDAV, or Personal Information Page settings for this user.",
1.267 raeburn 1525: 'ifch' => "If a change is required, contact a domain coordinator for the domain",
1526: );
1.362 raeburn 1527: $user_text{'tools'} = <<ENDNOTOOLSPRIV;
1.267 raeburn 1528: <h3>$lt{'utav'}</h3>
1529: $lt{'yodo'} $lt{'ifch'}: $ccdomain
1530: ENDNOTOOLSPRIV
1531: }
1.188 raeburn 1532: }
1.362 raeburn 1533: my $gotdiv = 0;
1534: foreach my $item (@order) {
1535: if ($user_text{$item} ne '') {
1536: unless ($gotdiv) {
1537: $r->print('<div class="LC_left_float">');
1538: $gotdiv = 1;
1539: }
1540: $r->print('<br />'.$user_text{$item});
1541: }
1542: }
1543: if ($env{'form.action'} eq 'singlestudent') {
1544: unless ($gotdiv) {
1545: $r->print('<div class="LC_left_float">');
1.213 raeburn 1546: }
1.375 raeburn 1547: my $credits;
1548: if ($showcredits) {
1549: $credits = &get_user_credits($ccuname,$ccdomain,$defaultcredits);
1550: if ($credits eq '') {
1551: $credits = $defaultcredits;
1552: }
1553: }
1.374 raeburn 1554: $r->print(&date_sections_select($context,$newuser,$formname,
1.375 raeburn 1555: $permission,$crstype,$ccuname,
1556: $ccdomain,$showcredits));
1.374 raeburn 1557: }
1.362 raeburn 1558: if ($gotdiv) {
1559: $r->print('</div><div class="LC_clear_float_footer"></div>');
1.188 raeburn 1560: }
1.217 raeburn 1561: if ($env{'form.action'} ne 'singlestudent') {
1.329 raeburn 1562: &display_existing_roles($r,$ccuname,$ccdomain,\%inccourses,$context,
1563: $roledom,$crstype);
1.217 raeburn 1564: }
1.25 matthew 1565: } ## End of new user/old user logic
1.218 raeburn 1566: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1567: my $btntxt;
1568: if ($crstype eq 'Community') {
1569: $btntxt = &mt('Enroll Member');
1570: } else {
1571: $btntxt = &mt('Enroll Student');
1572: }
1573: $r->print('<br /><input type="button" value="'.$btntxt.'" onclick="setSections(this.form)" />'."\n");
1.218 raeburn 1574: } else {
1.393 raeburn 1575: $r->print('<div class="LC_left_float">'.
1576: '<fieldset><legend>'.&mt('Add Roles').'</legend>');
1.218 raeburn 1577: my $addrolesdisplay = 0;
1578: if ($context eq 'domain' || $context eq 'author') {
1579: $addrolesdisplay = &new_coauthor_roles($r,$ccuname,$ccdomain);
1580: }
1581: if ($context eq 'domain') {
1.357 raeburn 1582: my $add_domainroles = &new_domain_roles($r,$ccdomain);
1.218 raeburn 1583: if (!$addrolesdisplay) {
1584: $addrolesdisplay = $add_domainroles;
1.2 www 1585: }
1.375 raeburn 1586: $r->print(&course_level_dc($env{'request.role.domain'},$showcredits));
1.393 raeburn 1587: $r->print('</fieldset></div><div class="LC_clear_float_footer"></div>'.
1588: '<br /><input type="button" value="'.&mt('Save').'" onclick="setCourse()" />'."\n");
1.218 raeburn 1589: } elsif ($context eq 'author') {
1590: if ($addrolesdisplay) {
1.393 raeburn 1591: $r->print('</fieldset></div><div class="LC_clear_float_footer"></div>'.
1592: '<br /><input type="button" value="'.&mt('Save').'"');
1.218 raeburn 1593: if ($newuser) {
1.301 bisitz 1594: $r->print(' onclick="auth_check()" \>'."\n");
1.218 raeburn 1595: } else {
1.301 bisitz 1596: $r->print('onclick="this.form.submit()" \>'."\n");
1.218 raeburn 1597: }
1.188 raeburn 1598: } else {
1.393 raeburn 1599: $r->print('</fieldset></div>'.
1600: '<div class="LC_clear_float_footer"></div>'.
1601: '<br /><a href="javascript:backPage(document.cu)">'.
1.218 raeburn 1602: &mt('Back to previous page').'</a>');
1.188 raeburn 1603: }
1604: } else {
1.375 raeburn 1605: $r->print(&course_level_table(\%inccourses,$showcredits,$defaultcredits));
1.393 raeburn 1606: $r->print('</fieldset></div><div class="LC_clear_float_footer"></div>'.
1607: '<br /><input type="button" value="'.&mt('Save').'" onclick="setSections(this.form)" />'."\n");
1.188 raeburn 1608: }
1.88 raeburn 1609: }
1.188 raeburn 1610: $r->print(&Apache::lonhtmlcommon::echo_form_input(['phase','userrole','ccdomain','prevphase','currstate','ccuname','ccdomain']));
1.179 raeburn 1611: $r->print('<input type="hidden" name="currstate" value="" />');
1.393 raeburn 1612: $r->print('<input type="hidden" name="prevphase" value="'.$env{'form.phase'}.'" /></form><br /><br />');
1.218 raeburn 1613: return;
1.2 www 1614: }
1.1 www 1615:
1.213 raeburn 1616: sub singleuser_breadcrumb {
1.318 raeburn 1617: my ($crstype) = @_;
1.213 raeburn 1618: my %breadcrumb_text;
1619: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1620: if ($crstype eq 'Community') {
1621: $breadcrumb_text{'search'} = 'Enroll a member';
1622: } else {
1623: $breadcrumb_text{'search'} = 'Enroll a student';
1624: }
1.213 raeburn 1625: $breadcrumb_text{'userpicked'} = 'Select a user',
1626: $breadcrumb_text{'modify'} = 'Set section/dates',
1.416 ! raeburn 1627: } elsif ($env{'form.action'} eq 'accesslogs') {
! 1628: $breadcrumb_text{'search'} = 'View access logs for a user';
! 1629: $breadcrumb_text{'userpicked'} = 'Select a user',
! 1630: $breadcrumb_text{'activity'} = 'Activity',
1.213 raeburn 1631: } else {
1.229 raeburn 1632: $breadcrumb_text{'search'} = 'Create/modify a user';
1.213 raeburn 1633: $breadcrumb_text{'userpicked'} = 'Select a user',
1634: $breadcrumb_text{'modify'} = 'Set user role',
1635: }
1636: return %breadcrumb_text;
1637: }
1638:
1639: sub date_sections_select {
1.375 raeburn 1640: my ($context,$newuser,$formname,$permission,$crstype,$ccuname,$ccdomain,
1641: $showcredits) = @_;
1642: my $credits;
1643: if ($showcredits) {
1644: my $defaultcredits = &Apache::lonuserutils::get_defaultcredits();
1645: $credits = &get_user_credits($ccuname,$ccdomain,$defaultcredits);
1646: if ($credits eq '') {
1647: $credits = $defaultcredits;
1648: }
1649: }
1.213 raeburn 1650: my $cid = $env{'request.course.id'};
1651: my ($cnum,$cdom) = &Apache::lonuserutils::get_course_identity($cid);
1652: my $date_table = '<h3>'.&mt('Starting and Ending Dates').'</h3>'."\n".
1653: &Apache::lonuserutils::date_setting_table(undef,undef,$context,
1654: undef,$formname,$permission);
1655: my $rowtitle = 'Section';
1.375 raeburn 1656: my $secbox = '<h3>'.&mt('Section and Credits').'</h3>'."\n".
1.213 raeburn 1657: &Apache::lonuserutils::section_picker($cdom,$cnum,'st',$rowtitle,
1.375 raeburn 1658: $permission,$context,'',$crstype,
1659: $showcredits,$credits);
1.213 raeburn 1660: my $output = $date_table.$secbox;
1661: return $output;
1662: }
1663:
1.216 raeburn 1664: sub validation_javascript {
1.375 raeburn 1665: my ($context,$ccdomain,$pjump_def,$crstype,$groupslist,$newuser,$formname,
1.216 raeburn 1666: $loaditem) = @_;
1667: my $dc_setcourse_code = '';
1668: my $nondc_setsection_code = '';
1669: if ($context eq 'domain') {
1670: my $dcdom = $env{'request.role.domain'};
1671: $loaditem->{'onload'} = "document.cu.coursedesc.value='';";
1.227 raeburn 1672: $dc_setcourse_code =
1673: &Apache::lonuserutils::dc_setcourse_js('cu','singleuser',$context);
1.216 raeburn 1674: } else {
1.227 raeburn 1675: my $checkauth;
1676: if (($newuser) || (&Apache::lonnet::allowed('mau',$ccdomain))) {
1677: $checkauth = 1;
1678: }
1679: if ($context eq 'course') {
1680: $nondc_setsection_code =
1681: &Apache::lonuserutils::setsections_javascript($formname,$groupslist,
1.375 raeburn 1682: undef,$checkauth,
1683: $crstype);
1.227 raeburn 1684: }
1685: if ($checkauth) {
1686: $nondc_setsection_code .=
1687: &Apache::lonuserutils::verify_authen($formname,$context);
1688: }
1.216 raeburn 1689: }
1690: my $js = &user_modification_js($pjump_def,$dc_setcourse_code,
1691: $nondc_setsection_code,$groupslist);
1692: my ($jsback,$elements) = &crumb_utilities();
1693: $js .= "\n".
1.301 bisitz 1694: '<script type="text/javascript">'."\n".
1695: '// <![CDATA['."\n".
1696: $jsback."\n".
1697: '// ]]>'."\n".
1698: '</script>'."\n";
1.216 raeburn 1699: return $js;
1700: }
1701:
1.217 raeburn 1702: sub display_existing_roles {
1.375 raeburn 1703: my ($r,$ccuname,$ccdomain,$inccourses,$context,$roledom,$crstype,
1704: $showcredits) = @_;
1.329 raeburn 1705: my $now=time;
1706: my %lt=&Apache::lonlocal::texthash(
1.217 raeburn 1707: 'rer' => "Existing Roles",
1708: 'rev' => "Revoke",
1709: 'del' => "Delete",
1710: 'ren' => "Re-Enable",
1711: 'rol' => "Role",
1712: 'ext' => "Extent",
1.375 raeburn 1713: 'crd' => "Credits",
1.217 raeburn 1714: 'sta' => "Start",
1715: 'end' => "End",
1716: );
1.329 raeburn 1717: my (%rolesdump,%roletext,%sortrole,%roleclass,%rolepriv);
1718: if ($context eq 'course' || $context eq 'author') {
1719: my @roles = &Apache::lonuserutils::roles_by_context($context,1,$crstype);
1720: my %roleshash =
1721: &Apache::lonnet::get_my_roles($ccuname,$ccdomain,'userroles',
1722: ['active','previous','future'],\@roles,$roledom,1);
1723: foreach my $key (keys(%roleshash)) {
1724: my ($start,$end) = split(':',$roleshash{$key});
1725: next if ($start eq '-1' || $end eq '-1');
1726: my ($rnum,$rdom,$role,$sec) = split(':',$key);
1727: if ($context eq 'course') {
1728: next unless (($rnum eq $env{'course.'.$env{'request.course.id'}.'.num'})
1729: && ($rdom eq $env{'course.'.$env{'request.course.id'}.'.domain'}));
1730: } elsif ($context eq 'author') {
1731: next unless (($rnum eq $env{'user.name'}) && ($rdom eq $env{'request.role.domain'}));
1732: }
1733: my ($newkey,$newvalue,$newrole);
1734: $newkey = '/'.$rdom.'/'.$rnum;
1735: if ($sec ne '') {
1736: $newkey .= '/'.$sec;
1737: }
1738: $newvalue = $role;
1739: if ($role =~ /^cr/) {
1740: $newrole = 'cr';
1741: } else {
1742: $newrole = $role;
1743: }
1744: $newkey .= '_'.$newrole;
1745: if ($start ne '' && $end ne '') {
1746: $newvalue .= '_'.$end.'_'.$start;
1.335 raeburn 1747: } elsif ($end ne '') {
1748: $newvalue .= '_'.$end;
1.329 raeburn 1749: }
1750: $rolesdump{$newkey} = $newvalue;
1751: }
1752: } else {
1.360 raeburn 1753: %rolesdump=&Apache::lonnet::dump('roles',$ccdomain,$ccuname);
1.329 raeburn 1754: }
1755: # Build up table of user roles to allow revocation and re-enabling of roles.
1756: my ($tmp) = keys(%rolesdump);
1757: return if ($tmp =~ /^(con_lost|error)/i);
1758: foreach my $area (sort { my $a1=join('_',(split('_',$a))[1,0]);
1759: my $b1=join('_',(split('_',$b))[1,0]);
1760: return $a1 cmp $b1;
1761: } keys(%rolesdump)) {
1762: next if ($area =~ /^rolesdef/);
1763: my $envkey=$area;
1764: my $role = $rolesdump{$area};
1765: my $thisrole=$area;
1766: $area =~ s/\_\w\w$//;
1767: my ($role_code,$role_end_time,$role_start_time) =
1768: split(/_/,$role);
1.217 raeburn 1769: # Is this a custom role? Get role owner and title.
1.329 raeburn 1770: my ($croleudom,$croleuname,$croletitle)=
1771: ($role_code=~m{^cr/($match_domain)/($match_username)/(\w+)$});
1772: my $allowed=0;
1773: my $delallowed=0;
1774: my $sortkey=$role_code;
1775: my $class='Unknown';
1.375 raeburn 1776: my $credits='';
1.329 raeburn 1777: if ($area =~ m{^/($match_domain)/($match_courseid)} ) {
1778: $class='Course';
1779: my ($coursedom,$coursedir) = ($1,$2);
1780: my $cid = $1.'_'.$2;
1781: # $1.'_'.$2 is the course id (eg. 103_12345abcef103l3).
1782: my %coursedata=
1783: &Apache::lonnet::coursedescription($cid);
1784: if ($coursedir =~ /^$match_community$/) {
1785: $class='Community';
1786: }
1787: $sortkey.="\0$coursedom";
1788: my $carea;
1789: if (defined($coursedata{'description'})) {
1790: $carea=$coursedata{'description'}.
1791: '<br />'.&mt('Domain').': '.$coursedom.(' 'x8).
1792: &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$coursedir,$coursedom);
1793: $sortkey.="\0".$coursedata{'description'};
1794: } else {
1795: if ($class eq 'Community') {
1796: $carea=&mt('Unavailable community').': '.$area;
1797: $sortkey.="\0".&mt('Unavailable community').': '.$area;
1.217 raeburn 1798: } else {
1799: $carea=&mt('Unavailable course').': '.$area;
1800: $sortkey.="\0".&mt('Unavailable course').': '.$area;
1801: }
1.329 raeburn 1802: }
1803: $sortkey.="\0$coursedir";
1804: $inccourses->{$cid}=1;
1.375 raeburn 1805: if (($showcredits) && ($class eq 'Course') && ($role_code eq 'st')) {
1806: my $defaultcredits = $coursedata{'internal.defaultcredits'};
1807: $credits =
1808: &get_user_credits($ccuname,$ccdomain,$defaultcredits,
1809: $coursedom,$coursedir);
1810: if ($credits eq '') {
1811: $credits = $defaultcredits;
1812: }
1813: }
1.329 raeburn 1814: if ((&Apache::lonnet::allowed('c'.$role_code,$coursedom.'/'.$coursedir)) ||
1815: (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) {
1816: $allowed=1;
1817: }
1818: unless ($allowed) {
1.365 raeburn 1819: my $isowner = &Apache::lonuserutils::is_courseowner($cid,$coursedata{'internal.courseowner'});
1.329 raeburn 1820: if ($isowner) {
1821: if (($role_code eq 'co') && ($class eq 'Community')) {
1822: $allowed = 1;
1823: } elsif (($role_code eq 'cc') && ($class eq 'Course')) {
1824: $allowed = 1;
1825: }
1.217 raeburn 1826: }
1.329 raeburn 1827: }
1828: if ((&Apache::lonnet::allowed('dro',$coursedom)) ||
1829: (&Apache::lonnet::allowed('dro',$ccdomain))) {
1830: $delallowed=1;
1831: }
1.217 raeburn 1832: # - custom role. Needs more info, too
1.329 raeburn 1833: if ($croletitle) {
1834: if (&Apache::lonnet::allowed('ccr',$coursedom.'/'.$coursedir)) {
1835: $allowed=1;
1836: $thisrole.='.'.$role_code;
1.217 raeburn 1837: }
1.329 raeburn 1838: }
1839: if ($area=~m{^/($match_domain)/($match_courseid)/(\w+)}) {
1.373 bisitz 1840: $carea.='<br />'.&mt('Section: [_1]',$3);
1.329 raeburn 1841: $sortkey.="\0$3";
1842: if (!$allowed) {
1843: if ($env{'request.course.sec'} eq $3) {
1844: if (&Apache::lonnet::allowed('c'.$role_code,$1.'/'.$2.'/'.$3)) {
1845: $allowed = 1;
1.217 raeburn 1846: }
1847: }
1848: }
1.329 raeburn 1849: }
1850: $area=$carea;
1851: } else {
1852: $sortkey.="\0".$area;
1853: # Determine if current user is able to revoke privileges
1854: if ($area=~m{^/($match_domain)/}) {
1855: if ((&Apache::lonnet::allowed('c'.$role_code,$1)) ||
1856: (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) {
1857: $allowed=1;
1.217 raeburn 1858: }
1.329 raeburn 1859: if (((&Apache::lonnet::allowed('dro',$1)) ||
1860: (&Apache::lonnet::allowed('dro',$ccdomain))) &&
1861: ($role_code ne 'dc')) {
1862: $delallowed=1;
1.217 raeburn 1863: }
1.329 raeburn 1864: } else {
1865: if (&Apache::lonnet::allowed('c'.$role_code,'/')) {
1.217 raeburn 1866: $allowed=1;
1867: }
1868: }
1.363 raeburn 1869: if ($role_code eq 'ca' || $role_code eq 'au' || $role_code eq 'aa') {
1.377 raeburn 1870: $class='Authoring Space';
1.329 raeburn 1871: } elsif ($role_code eq 'su') {
1872: $class='System';
1.217 raeburn 1873: } else {
1.329 raeburn 1874: $class='Domain';
1.217 raeburn 1875: }
1.329 raeburn 1876: }
1877: if (($role_code eq 'ca') || ($role_code eq 'aa')) {
1878: $area=~m{/($match_domain)/($match_username)};
1879: if (&Apache::lonuserutils::authorpriv($2,$1)) {
1880: $allowed=1;
1.217 raeburn 1881: } else {
1.329 raeburn 1882: $allowed=0;
1.217 raeburn 1883: }
1.329 raeburn 1884: }
1885: my $row = '';
1886: $row.= '<td>';
1887: my $active=1;
1888: $active=0 if (($role_end_time) && ($now>$role_end_time));
1889: if (($active) && ($allowed)) {
1890: $row.= '<input type="checkbox" name="rev:'.$thisrole.'" />';
1891: } else {
1892: if ($active) {
1893: $row.=' ';
1.217 raeburn 1894: } else {
1.329 raeburn 1895: $row.=&mt('expired or revoked');
1.217 raeburn 1896: }
1.329 raeburn 1897: }
1898: $row.='</td><td>';
1899: if ($allowed && !$active) {
1900: $row.= '<input type="checkbox" name="ren:'.$thisrole.'" />';
1901: } else {
1902: $row.=' ';
1903: }
1904: $row.='</td><td>';
1905: if ($delallowed) {
1906: $row.= '<input type="checkbox" name="del:'.$thisrole.'" />';
1907: } else {
1908: $row.=' ';
1909: }
1910: my $plaintext='';
1911: if (!$croletitle) {
1.375 raeburn 1912: $plaintext=&Apache::lonnet::plaintext($role_code,$class);
1913: if (($showcredits) && ($credits ne '')) {
1914: $plaintext .= '<br/ ><span class="LC_nobreak">'.
1915: '<span class="LC_fontsize_small">'.
1916: &mt('Credits: [_1]',$credits).
1917: '</span></span>';
1918: }
1.329 raeburn 1919: } else {
1920: $plaintext=
1.395 bisitz 1921: &mt('Custom role [_1][_2]defined by [_3]',
1.346 bisitz 1922: '"'.$croletitle.'"',
1923: '<br />',
1924: $croleuname.':'.$croleudom);
1.329 raeburn 1925: }
1926: $row.= '</td><td>'.$plaintext.
1927: '</td><td>'.$area.
1928: '</td><td>'.($role_start_time?&Apache::lonlocal::locallocaltime($role_start_time)
1929: : ' ' ).
1930: '</td><td>'.($role_end_time ?&Apache::lonlocal::locallocaltime($role_end_time)
1931: : ' ' )
1932: ."</td>";
1933: $sortrole{$sortkey}=$envkey;
1934: $roletext{$envkey}=$row;
1935: $roleclass{$envkey}=$class;
1936: $rolepriv{$envkey}=$allowed;
1937: } # end of foreach (table building loop)
1938:
1939: my $rolesdisplay = 0;
1940: my %output = ();
1.377 raeburn 1941: foreach my $type ('Authoring Space','Course','Community','Domain','System','Unknown') {
1.329 raeburn 1942: $output{$type} = '';
1943: foreach my $which (sort {uc($a) cmp uc($b)} (keys(%sortrole))) {
1944: if ( ($roleclass{$sortrole{$which}} =~ /^\Q$type\E/ ) && ($rolepriv{$sortrole{$which}}) ) {
1945: $output{$type}.=
1946: &Apache::loncommon::start_data_table_row().
1947: $roletext{$sortrole{$which}}.
1948: &Apache::loncommon::end_data_table_row();
1.217 raeburn 1949: }
1.329 raeburn 1950: }
1951: unless($output{$type} eq '') {
1952: $output{$type} = '<tr class="LC_info_row">'.
1953: "<td align='center' colspan='7'>".&mt($type)."</td></tr>".
1954: $output{$type};
1955: $rolesdisplay = 1;
1956: }
1957: }
1958: if ($rolesdisplay == 1) {
1959: my $contextrole='';
1960: if ($env{'request.course.id'}) {
1961: if (&Apache::loncommon::course_type() eq 'Community') {
1962: $contextrole = &mt('Existing Roles in this Community');
1.290 bisitz 1963: } else {
1.329 raeburn 1964: $contextrole = &mt('Existing Roles in this Course');
1.290 bisitz 1965: }
1.329 raeburn 1966: } elsif ($env{'request.role'} =~ /^au\./) {
1.377 raeburn 1967: $contextrole = &mt('Existing Co-Author Roles in your Authoring Space');
1.329 raeburn 1968: } else {
1969: $contextrole = &mt('Existing Roles in this Domain');
1970: }
1.393 raeburn 1971: $r->print('<div class="LC_left_float">'.
1.375 raeburn 1972: '<fieldset><legend>'.$contextrole.'</legend>'.
1.217 raeburn 1973: &Apache::loncommon::start_data_table("LC_createuser").
1974: &Apache::loncommon::start_data_table_header_row().
1975: '<th>'.$lt{'rev'}.'</th><th>'.$lt{'ren'}.'</th><th>'.$lt{'del'}.
1976: '</th><th>'.$lt{'rol'}.'</th><th>'.$lt{'ext'}.
1977: '</th><th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'.
1978: &Apache::loncommon::end_data_table_header_row());
1.377 raeburn 1979: foreach my $type ('Authoring Space','Course','Community','Domain','System','Unknown') {
1.329 raeburn 1980: if ($output{$type}) {
1981: $r->print($output{$type}."\n");
1.217 raeburn 1982: }
1983: }
1.375 raeburn 1984: $r->print(&Apache::loncommon::end_data_table().
1985: '</fieldset></div>');
1.329 raeburn 1986: }
1.217 raeburn 1987: return;
1988: }
1989:
1.218 raeburn 1990: sub new_coauthor_roles {
1991: my ($r,$ccuname,$ccdomain) = @_;
1992: my $addrolesdisplay = 0;
1993: #
1994: # Co-Author
1995: #
1996: if (&Apache::lonuserutils::authorpriv($env{'user.name'},
1997: $env{'request.role.domain'}) &&
1998: ($env{'user.name'} ne $ccuname || $env{'user.domain'} ne $ccdomain)) {
1999: # No sense in assigning co-author role to yourself
2000: $addrolesdisplay = 1;
2001: my $cuname=$env{'user.name'};
2002: my $cudom=$env{'request.role.domain'};
2003: my %lt=&Apache::lonlocal::texthash(
1.377 raeburn 2004: 'cs' => "Authoring Space",
1.218 raeburn 2005: 'act' => "Activate",
2006: 'rol' => "Role",
2007: 'ext' => "Extent",
2008: 'sta' => "Start",
2009: 'end' => "End",
2010: 'cau' => "Co-Author",
2011: 'caa' => "Assistant Co-Author",
2012: 'ssd' => "Set Start Date",
2013: 'sed' => "Set End Date"
2014: );
2015: $r->print('<h4>'.$lt{'cs'}.'</h4>'."\n".
2016: &Apache::loncommon::start_data_table()."\n".
2017: &Apache::loncommon::start_data_table_header_row()."\n".
2018: '<th>'.$lt{'act'}.'</th><th>'.$lt{'rol'}.'</th>'.
2019: '<th>'.$lt{'ext'}.'</th><th>'.$lt{'sta'}.'</th>'.
2020: '<th>'.$lt{'end'}.'</th>'."\n".
2021: &Apache::loncommon::end_data_table_header_row()."\n".
2022: &Apache::loncommon::start_data_table_row().'
2023: <td>
1.291 bisitz 2024: <input type="checkbox" name="act_'.$cudom.'_'.$cuname.'_ca" />
1.218 raeburn 2025: </td>
2026: <td>'.$lt{'cau'}.'</td>
2027: <td>'.$cudom.'_'.$cuname.'</td>
2028: <td><input type="hidden" name="start_'.$cudom.'_'.$cuname.'_ca" value="" />
2029: <a href=
2030: "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>
2031: <td><input type="hidden" name="end_'.$cudom.'_'.$cuname.'_ca" value="" />
2032: <a href=
2033: "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".
2034: &Apache::loncommon::end_data_table_row()."\n".
2035: &Apache::loncommon::start_data_table_row()."\n".
1.291 bisitz 2036: '<td><input type="checkbox" name="act_'.$cudom.'_'.$cuname.'_aa" /></td>
1.218 raeburn 2037: <td>'.$lt{'caa'}.'</td>
2038: <td>'.$cudom.'_'.$cuname.'</td>
2039: <td><input type="hidden" name="start_'.$cudom.'_'.$cuname.'_aa" value="" />
2040: <a href=
2041: "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>
2042: <td><input type="hidden" name="end_'.$cudom.'_'.$cuname.'_aa" value="" />
2043: <a href=
2044: "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".
2045: &Apache::loncommon::end_data_table_row()."\n".
2046: &Apache::loncommon::end_data_table());
2047: } elsif ($env{'request.role'} =~ /^au\./) {
2048: if (!(&Apache::lonuserutils::authorpriv($env{'user.name'},
2049: $env{'request.role.domain'}))) {
2050: $r->print('<span class="LC_error">'.
2051: &mt('You do not have privileges to assign co-author roles.').
2052: '</span>');
2053: } elsif (($env{'user.name'} eq $ccuname) &&
2054: ($env{'user.domain'} eq $ccdomain)) {
1.377 raeburn 2055: $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 2056: }
2057: }
2058: return $addrolesdisplay;;
2059: }
2060:
2061: sub new_domain_roles {
1.357 raeburn 2062: my ($r,$ccdomain) = @_;
1.218 raeburn 2063: my $addrolesdisplay = 0;
2064: #
2065: # Domain level
2066: #
2067: my $num_domain_level = 0;
2068: my $domaintext =
2069: '<h4>'.&mt('Domain Level').'</h4>'.
2070: &Apache::loncommon::start_data_table().
2071: &Apache::loncommon::start_data_table_header_row().
2072: '<th>'.&mt('Activate').'</th><th>'.&mt('Role').'</th><th>'.
2073: &mt('Extent').'</th>'.
2074: '<th>'.&mt('Start').'</th><th>'.&mt('End').'</th>'.
2075: &Apache::loncommon::end_data_table_header_row();
1.312 raeburn 2076: my @allroles = &Apache::lonuserutils::roles_by_context('domain');
1.218 raeburn 2077: foreach my $thisdomain (sort(&Apache::lonnet::all_domains())) {
1.312 raeburn 2078: foreach my $role (@allroles) {
2079: next if ($role eq 'ad');
1.357 raeburn 2080: next if (($role eq 'au') && ($ccdomain ne $thisdomain));
1.218 raeburn 2081: if (&Apache::lonnet::allowed('c'.$role,$thisdomain)) {
2082: my $plrole=&Apache::lonnet::plaintext($role);
2083: my %lt=&Apache::lonlocal::texthash(
2084: 'ssd' => "Set Start Date",
2085: 'sed' => "Set End Date"
2086: );
2087: $num_domain_level ++;
2088: $domaintext .=
2089: &Apache::loncommon::start_data_table_row().
1.291 bisitz 2090: '<td><input type="checkbox" name="act_'.$thisdomain.'_'.$role.'" /></td>
1.218 raeburn 2091: <td>'.$plrole.'</td>
2092: <td>'.$thisdomain.'</td>
2093: <td><input type="hidden" name="start_'.$thisdomain.'_'.$role.'" value="" />
2094: <a href=
2095: "javascript:pjump('."'date_start','Start Date $plrole',document.cu.start_$thisdomain\_$role.value,'start_$thisdomain\_$role','cu.pres','dateset'".')">'.$lt{'ssd'}.'</a></td>
2096: <td><input type="hidden" name="end_'.$thisdomain.'_'.$role.'" value="" />
2097: <a href=
2098: "javascript:pjump('."'date_end','End Date $plrole',document.cu.end_$thisdomain\_$role.value,'end_$thisdomain\_$role','cu.pres','dateset'".')">'.$lt{'sed'}.'</a></td>'.
2099: &Apache::loncommon::end_data_table_row();
2100: }
2101: }
2102: }
2103: $domaintext.= &Apache::loncommon::end_data_table();
2104: if ($num_domain_level > 0) {
2105: $r->print($domaintext);
2106: $addrolesdisplay = 1;
2107: }
2108: return $addrolesdisplay;
2109: }
2110:
1.188 raeburn 2111: sub user_authentication {
1.227 raeburn 2112: my ($ccuname,$ccdomain,$formname) = @_;
1.188 raeburn 2113: my $currentauth=&Apache::lonnet::queryauthenticate($ccuname,$ccdomain);
1.227 raeburn 2114: my $outcome;
1.188 raeburn 2115: # Check for a bad authentication type
2116: if ($currentauth !~ /^(krb4|krb5|unix|internal|localauth):/) {
2117: # bad authentication scheme
2118: my %lt=&Apache::lonlocal::texthash(
2119: 'err' => "ERROR",
2120: 'uuas' => "This user has an unrecognized authentication scheme",
2121: 'adcs' => "Please alert a domain coordinator of this situation",
2122: 'sldb' => "Please specify login data below",
2123: 'ld' => "Login Data"
2124: );
2125: if (&Apache::lonnet::allowed('mau',$ccdomain)) {
1.227 raeburn 2126: &initialize_authen_forms($ccdomain,$formname);
2127:
1.190 raeburn 2128: my $choices = &Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc);
1.188 raeburn 2129: $outcome = <<ENDBADAUTH;
2130: <script type="text/javascript" language="Javascript">
1.301 bisitz 2131: // <![CDATA[
1.188 raeburn 2132: $loginscript
1.301 bisitz 2133: // ]]>
1.188 raeburn 2134: </script>
2135: <span class="LC_error">$lt{'err'}:
2136: $lt{'uuas'} ($currentauth). $lt{'sldb'}.</span>
2137: <h3>$lt{'ld'}</h3>
2138: $choices
2139: ENDBADAUTH
2140: } else {
2141: # This user is not allowed to modify the user's
2142: # authentication scheme, so just notify them of the problem
2143: $outcome = <<ENDBADAUTH;
2144: <span class="LC_error"> $lt{'err'}:
2145: $lt{'uuas'} ($currentauth). $lt{'adcs'}.
2146: </span>
2147: ENDBADAUTH
2148: }
2149: } else { # Authentication type is valid
1.227 raeburn 2150: &initialize_authen_forms($ccdomain,$formname,$currentauth,'modifyuser');
1.205 raeburn 2151: my ($authformcurrent,$can_modify,@authform_others) =
1.188 raeburn 2152: &modify_login_block($ccdomain,$currentauth);
2153: if (&Apache::lonnet::allowed('mau',$ccdomain)) {
2154: # Current user has login modification privileges
2155: my %lt=&Apache::lonlocal::texthash (
2156: 'ld' => "Login Data",
2157: 'ccld' => "Change Current Login Data",
2158: 'enld' => "Enter New Login Data"
2159: );
2160: $outcome =
2161: '<script type="text/javascript" language="Javascript">'."\n".
1.301 bisitz 2162: '// <![CDATA['."\n".
1.188 raeburn 2163: $loginscript."\n".
1.301 bisitz 2164: '// ]]>'."\n".
1.188 raeburn 2165: '</script>'."\n".
2166: '<h3>'.$lt{'ld'}.'</h3>'.
2167: &Apache::loncommon::start_data_table().
1.205 raeburn 2168: &Apache::loncommon::start_data_table_row().
1.188 raeburn 2169: '<td>'.$authformnop;
2170: if ($can_modify) {
2171: $outcome .= '</td>'."\n".
2172: &Apache::loncommon::end_data_table_row().
2173: &Apache::loncommon::start_data_table_row().
2174: '<td>'.$authformcurrent.'</td>'.
2175: &Apache::loncommon::end_data_table_row()."\n";
2176: } else {
1.200 raeburn 2177: $outcome .= ' ('.$authformcurrent.')</td>'.
2178: &Apache::loncommon::end_data_table_row()."\n";
1.188 raeburn 2179: }
1.205 raeburn 2180: foreach my $item (@authform_others) {
2181: $outcome .= &Apache::loncommon::start_data_table_row().
2182: '<td>'.$item.'</td>'.
2183: &Apache::loncommon::end_data_table_row()."\n";
1.188 raeburn 2184: }
1.205 raeburn 2185: $outcome .= &Apache::loncommon::end_data_table();
1.188 raeburn 2186: } else {
2187: if (&Apache::lonnet::allowed('mau',$env{'request.role.domain'})) {
2188: my %lt=&Apache::lonlocal::texthash(
2189: 'ccld' => "Change Current Login Data",
2190: 'yodo' => "You do not have privileges to modify the authentication configuration for this user.",
2191: 'ifch' => "If a change is required, contact a domain coordinator for the domain",
2192: );
2193: $outcome .= <<ENDNOPRIV;
2194: <h3>$lt{'ccld'}</h3>
2195: $lt{'yodo'} $lt{'ifch'}: $ccdomain
1.235 raeburn 2196: <input type="hidden" name="login" value="nochange" />
1.188 raeburn 2197: ENDNOPRIV
2198: }
2199: }
2200: } ## End of "check for bad authentication type" logic
2201: return $outcome;
2202: }
2203:
1.187 raeburn 2204: sub modify_login_block {
2205: my ($dom,$currentauth) = @_;
2206: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
2207: my ($authnum,%can_assign) =
2208: &Apache::loncommon::get_assignable_auth($dom);
1.205 raeburn 2209: my ($authformcurrent,@authform_others,$show_override_msg);
1.187 raeburn 2210: if ($currentauth=~/^krb(4|5):/) {
2211: $authformcurrent=$authformkrb;
2212: if ($can_assign{'int'}) {
1.205 raeburn 2213: push(@authform_others,$authformint);
1.187 raeburn 2214: }
2215: if ($can_assign{'loc'}) {
1.205 raeburn 2216: push(@authform_others,$authformloc);
1.187 raeburn 2217: }
2218: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
2219: $show_override_msg = 1;
2220: }
2221: } elsif ($currentauth=~/^internal:/) {
2222: $authformcurrent=$authformint;
2223: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205 raeburn 2224: push(@authform_others,$authformkrb);
1.187 raeburn 2225: }
2226: if ($can_assign{'loc'}) {
1.205 raeburn 2227: push(@authform_others,$authformloc);
1.187 raeburn 2228: }
2229: if ($can_assign{'int'}) {
2230: $show_override_msg = 1;
2231: }
2232: } elsif ($currentauth=~/^unix:/) {
2233: $authformcurrent=$authformfsys;
2234: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205 raeburn 2235: push(@authform_others,$authformkrb);
1.187 raeburn 2236: }
2237: if ($can_assign{'int'}) {
1.205 raeburn 2238: push(@authform_others,$authformint);
1.187 raeburn 2239: }
2240: if ($can_assign{'loc'}) {
1.205 raeburn 2241: push(@authform_others,$authformloc);
1.187 raeburn 2242: }
2243: if ($can_assign{'fsys'}) {
2244: $show_override_msg = 1;
2245: }
2246: } elsif ($currentauth=~/^localauth:/) {
2247: $authformcurrent=$authformloc;
2248: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205 raeburn 2249: push(@authform_others,$authformkrb);
1.187 raeburn 2250: }
2251: if ($can_assign{'int'}) {
1.205 raeburn 2252: push(@authform_others,$authformint);
1.187 raeburn 2253: }
2254: if ($can_assign{'loc'}) {
2255: $show_override_msg = 1;
2256: }
2257: }
2258: if ($show_override_msg) {
1.205 raeburn 2259: $authformcurrent = '<table><tr><td colspan="3">'.$authformcurrent.
2260: '</td></tr>'."\n".
2261: '<tr><td> </td>'.
2262: '<td><b>'.&mt('Currently in use').'</b></td>'.
2263: '<td align="right"><span class="LC_cusr_emph">'.
1.187 raeburn 2264: &mt('will override current values').
1.205 raeburn 2265: '</span></td></tr></table>';
1.187 raeburn 2266: }
1.205 raeburn 2267: return ($authformcurrent,$show_override_msg,@authform_others);
1.187 raeburn 2268: }
2269:
1.188 raeburn 2270: sub personal_data_display {
1.391 raeburn 2271: my ($ccuname,$ccdomain,$newuser,$context,$inst_results,$rolesarray,
1.410 raeburn 2272: $now,$captchaform,$emailusername,$usertype) = @_;
1.388 bisitz 2273: my ($output,%userenv,%canmodify,%canmodify_status);
1.219 raeburn 2274: my @userinfo = ('firstname','middlename','lastname','generation',
2275: 'permanentemail','id');
1.252 raeburn 2276: my $rowcount = 0;
2277: my $editable = 0;
1.391 raeburn 2278: my %textboxsize = (
2279: firstname => '15',
2280: middlename => '15',
2281: lastname => '15',
2282: generation => '5',
2283: permanentemail => '25',
2284: id => '15',
2285: );
2286:
2287: my %lt=&Apache::lonlocal::texthash(
2288: 'pd' => "Personal Data",
2289: 'firstname' => "First Name",
2290: 'middlename' => "Middle Name",
2291: 'lastname' => "Last Name",
2292: 'generation' => "Generation",
2293: 'permanentemail' => "Permanent e-mail address",
2294: 'id' => "Student/Employee ID",
2295: 'lg' => "Login Data",
2296: 'inststatus' => "Affiliation",
2297: 'email' => 'E-mail address',
2298: 'valid' => 'Validation',
2299: );
2300:
2301: %canmodify_status =
1.286 raeburn 2302: &Apache::lonuserutils::can_modify_userinfo($context,$ccdomain,
2303: ['inststatus'],$rolesarray);
1.253 raeburn 2304: if (!$newuser) {
1.188 raeburn 2305: # Get the users information
2306: %userenv = &Apache::lonnet::get('environment',
2307: ['firstname','middlename','lastname','generation',
1.286 raeburn 2308: 'permanentemail','id','inststatus'],$ccdomain,$ccuname);
1.219 raeburn 2309: %canmodify =
2310: &Apache::lonuserutils::can_modify_userinfo($context,$ccdomain,
1.252 raeburn 2311: \@userinfo,$rolesarray);
1.257 raeburn 2312: } elsif ($context eq 'selfcreate') {
1.391 raeburn 2313: if ($newuser eq 'email') {
1.396 raeburn 2314: if (ref($emailusername) eq 'HASH') {
2315: if (ref($emailusername->{$usertype}) eq 'HASH') {
2316: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
2317: @userinfo = ();
2318: if ((ref($infofields) eq 'ARRAY') && (ref($infotitles) eq 'HASH')) {
2319: foreach my $field (@{$infofields}) {
2320: if ($emailusername->{$usertype}->{$field}) {
2321: push(@userinfo,$field);
2322: $canmodify{$field} = 1;
2323: unless ($textboxsize{$field}) {
2324: $textboxsize{$field} = 25;
2325: }
2326: unless ($lt{$field}) {
2327: $lt{$field} = $infotitles->{$field};
2328: }
2329: if ($emailusername->{$usertype}->{$field} eq 'required') {
2330: $lt{$field} .= '<b>*</b>';
2331: }
1.391 raeburn 2332: }
2333: }
2334: }
2335: }
2336: }
2337: } else {
2338: %canmodify = &selfcreate_canmodify($context,$ccdomain,\@userinfo,
2339: $inst_results,$rolesarray);
2340: }
1.188 raeburn 2341: }
1.391 raeburn 2342:
1.188 raeburn 2343: my $genhelp=&Apache::loncommon::help_open_topic('Generation');
2344: $output = '<h3>'.$lt{'pd'}.'</h3>'.
2345: &Apache::lonhtmlcommon::start_pick_box();
1.391 raeburn 2346: if (($context eq 'selfcreate') && ($newuser eq 'email')) {
1.396 raeburn 2347: $output .= &Apache::lonhtmlcommon::row_title($lt{'email'}.'<b>*</b>',undef,
1.391 raeburn 2348: 'LC_oddrow_value')."\n".
1.394 raeburn 2349: '<input type="text" name="uname" size="25" value="" autocomplete="off" />';
1.391 raeburn 2350: $rowcount ++;
2351: $output .= &Apache::lonhtmlcommon::row_closure(1);
1.408 raeburn 2352: my $upassone = '<input type="password" name="upass'.$now.'" size="20" autocomplete="off" />';
2353: my $upasstwo = '<input type="password" name="upasscheck'.$now.'" size="20" autocomplete="off" />';
1.396 raeburn 2354: $output .= &Apache::lonhtmlcommon::row_title(&mt('Password').'<b>*</b>',
1.391 raeburn 2355: 'LC_pick_box_title',
2356: 'LC_oddrow_value')."\n".
2357: $upassone."\n".
2358: &Apache::lonhtmlcommon::row_closure(1)."\n".
1.396 raeburn 2359: &Apache::lonhtmlcommon::row_title(&mt('Confirm password').'<b>*</b>',
1.391 raeburn 2360: 'LC_pick_box_title',
2361: 'LC_oddrow_value')."\n".
2362: $upasstwo.
2363: &Apache::lonhtmlcommon::row_closure()."\n";
2364: }
1.188 raeburn 2365: foreach my $item (@userinfo) {
2366: my $rowtitle = $lt{$item};
1.252 raeburn 2367: my $hiderow = 0;
1.188 raeburn 2368: if ($item eq 'generation') {
2369: $rowtitle = $genhelp.$rowtitle;
2370: }
1.252 raeburn 2371: my $row = &Apache::lonhtmlcommon::row_title($rowtitle,undef,'LC_oddrow_value')."\n";
1.188 raeburn 2372: if ($newuser) {
1.210 raeburn 2373: if (ref($inst_results) eq 'HASH') {
2374: if ($inst_results->{$item} ne '') {
1.252 raeburn 2375: $row .= '<input type="hidden" name="c'.$item.'" value="'.$inst_results->{$item}.'" />'.$inst_results->{$item};
1.210 raeburn 2376: } else {
1.252 raeburn 2377: if ($context eq 'selfcreate') {
1.391 raeburn 2378: if ($canmodify{$item}) {
1.394 raeburn 2379: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" autocomplete="off" />';
1.252 raeburn 2380: $editable ++;
2381: } else {
2382: $hiderow = 1;
2383: }
1.253 raeburn 2384: } else {
2385: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
1.252 raeburn 2386: }
1.210 raeburn 2387: }
1.188 raeburn 2388: } else {
1.252 raeburn 2389: if ($context eq 'selfcreate') {
1.401 raeburn 2390: if ($canmodify{$item}) {
2391: if ($newuser eq 'email') {
2392: $row .= '<input type="text" name="'.$item.'" size="'.$textboxsize{$item}.'" value="" autocomplete="off" />';
1.287 raeburn 2393: } else {
1.401 raeburn 2394: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" autocomplete="off" />';
1.287 raeburn 2395: }
1.401 raeburn 2396: $editable ++;
2397: } else {
2398: $hiderow = 1;
1.252 raeburn 2399: }
1.253 raeburn 2400: } else {
2401: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
1.252 raeburn 2402: }
1.188 raeburn 2403: }
2404: } else {
1.219 raeburn 2405: if ($canmodify{$item}) {
1.252 raeburn 2406: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="'.$userenv{$item}.'" />';
1.393 raeburn 2407: if (($item eq 'id') && (!$newuser)) {
2408: $row .= '<br />'.&Apache::lonuserutils::forceid_change($context);
2409: }
1.188 raeburn 2410: } else {
1.252 raeburn 2411: $row .= $userenv{$item};
1.188 raeburn 2412: }
2413: }
1.252 raeburn 2414: $row .= &Apache::lonhtmlcommon::row_closure(1);
2415: if (!$hiderow) {
2416: $output .= $row;
2417: $rowcount ++;
2418: }
1.188 raeburn 2419: }
1.286 raeburn 2420: if (($canmodify_status{'inststatus'}) || ($context ne 'selfcreate')) {
2421: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($ccdomain);
2422: if (ref($types) eq 'ARRAY') {
2423: if (@{$types} > 0) {
2424: my ($hiderow,$shown);
2425: if ($canmodify_status{'inststatus'}) {
2426: $shown = &pick_inst_statuses($userenv{'inststatus'},$usertypes,$types);
2427: } else {
2428: if ($userenv{'inststatus'} eq '') {
2429: $hiderow = 1;
1.334 raeburn 2430: } else {
2431: my @showitems;
2432: foreach my $item ( map { &unescape($_); } split(':',$userenv{'inststatus'})) {
2433: if (exists($usertypes->{$item})) {
2434: push(@showitems,$usertypes->{$item});
2435: } else {
2436: push(@showitems,$item);
2437: }
2438: }
2439: if (@showitems) {
2440: $shown = join(', ',@showitems);
2441: } else {
2442: $hiderow = 1;
2443: }
1.286 raeburn 2444: }
2445: }
2446: if (!$hiderow) {
1.389 bisitz 2447: my $row = &Apache::lonhtmlcommon::row_title(&mt('Affiliations'),undef,'LC_oddrow_value')."\n".
1.286 raeburn 2448: $shown.&Apache::lonhtmlcommon::row_closure(1);
2449: if ($context eq 'selfcreate') {
2450: $rowcount ++;
2451: }
2452: $output .= $row;
2453: }
2454: }
2455: }
2456: }
1.391 raeburn 2457: if (($context eq 'selfcreate') && ($newuser eq 'email')) {
2458: if ($captchaform) {
1.410 raeburn 2459: $output .= &Apache::lonhtmlcommon::row_title($lt{'valid'}.'*',
2460: 'LC_pick_box_title')."\n".
2461: $captchaform."\n".'<br /><br />'.
1.391 raeburn 2462: &Apache::lonhtmlcommon::row_closure(1);
2463: $rowcount ++;
2464: }
2465: my $submit_text = &mt('Create account');
2466: $output .= &Apache::lonhtmlcommon::row_title()."\n".
2467: '<br /><input type="submit" name="createaccount" value="'.
2468: $submit_text.'" />'.
1.396 raeburn 2469: '<input type="hidden" name="type" value="'.$usertype.'" />'.
1.391 raeburn 2470: &Apache::lonhtmlcommon::row_closure(1);
2471: }
1.188 raeburn 2472: $output .= &Apache::lonhtmlcommon::end_pick_box();
1.206 raeburn 2473: if (wantarray) {
1.252 raeburn 2474: if ($context eq 'selfcreate') {
2475: return($output,$rowcount,$editable);
2476: } else {
1.388 bisitz 2477: return $output;
1.252 raeburn 2478: }
1.206 raeburn 2479: } else {
2480: return $output;
2481: }
1.188 raeburn 2482: }
2483:
1.286 raeburn 2484: sub pick_inst_statuses {
2485: my ($curr,$usertypes,$types) = @_;
2486: my ($output,$rem,@currtypes);
2487: if ($curr ne '') {
2488: @currtypes = map { &unescape($_); } split(/:/,$curr);
2489: }
2490: my $numinrow = 2;
2491: if (ref($types) eq 'ARRAY') {
2492: $output = '<table>';
2493: my $lastcolspan;
2494: for (my $i=0; $i<@{$types}; $i++) {
2495: if (defined($usertypes->{$types->[$i]})) {
2496: my $rem = $i%($numinrow);
2497: if ($rem == 0) {
2498: if ($i<@{$types}-1) {
2499: if ($i > 0) {
2500: $output .= '</tr>';
2501: }
2502: $output .= '<tr>';
2503: }
2504: } elsif ($i==@{$types}-1) {
2505: my $colsleft = $numinrow - $rem;
2506: if ($colsleft > 1) {
2507: $lastcolspan = ' colspan="'.$colsleft.'"';
2508: }
2509: }
2510: my $check = ' ';
2511: if (grep(/^\Q$types->[$i]\E$/,@currtypes)) {
2512: $check = ' checked="checked" ';
2513: }
2514: $output .= '<td class="LC_left_item"'.$lastcolspan.'>'.
2515: '<span class="LC_nobreak"><label>'.
2516: '<input type="checkbox" name="inststatus" '.
2517: 'value="'.$types->[$i].'"'.$check.'/>'.
2518: $usertypes->{$types->[$i]}.'</label></span></td>';
2519: }
2520: }
2521: $output .= '</tr></table>';
2522: }
2523: return $output;
2524: }
2525:
1.257 raeburn 2526: sub selfcreate_canmodify {
2527: my ($context,$dom,$userinfo,$inst_results,$rolesarray) = @_;
2528: if (ref($inst_results) eq 'HASH') {
2529: my @inststatuses = &get_inststatuses($inst_results);
2530: if (@inststatuses == 0) {
2531: @inststatuses = ('default');
2532: }
2533: $rolesarray = \@inststatuses;
2534: }
2535: my %canmodify =
2536: &Apache::lonuserutils::can_modify_userinfo($context,$dom,$userinfo,
2537: $rolesarray);
2538: return %canmodify;
2539: }
2540:
1.252 raeburn 2541: sub get_inststatuses {
2542: my ($insthashref) = @_;
2543: my @inststatuses = ();
2544: if (ref($insthashref) eq 'HASH') {
2545: if (ref($insthashref->{'inststatus'}) eq 'ARRAY') {
2546: @inststatuses = @{$insthashref->{'inststatus'}};
2547: }
2548: }
2549: return @inststatuses;
2550: }
2551:
1.4 www 2552: # ================================================================= Phase Three
1.42 matthew 2553: sub update_user_data {
1.375 raeburn 2554: my ($r,$context,$crstype,$brcrum,$showcredits) = @_;
1.101 albertel 2555: my $uhome=&Apache::lonnet::homeserver($env{'form.ccuname'},
2556: $env{'form.ccdomain'});
1.27 matthew 2557: # Error messages
1.188 raeburn 2558: my $error = '<span class="LC_error">'.&mt('Error').': ';
1.193 raeburn 2559: my $end = '</span><br /><br />';
2560: my $rtnlink = '<a href="javascript:backPage(document.userupdate,'.
1.188 raeburn 2561: "'$env{'form.prevphase'}','modify')".'" />'.
1.219 raeburn 2562: &mt('Return to previous page').'</a>'.
2563: &Apache::loncommon::end_page();
2564: my $now = time;
1.40 www 2565: my $title;
1.101 albertel 2566: if (exists($env{'form.makeuser'})) {
1.40 www 2567: $title='Set Privileges for New User';
2568: } else {
2569: $title='Modify User Privileges';
2570: }
1.213 raeburn 2571: my $newuser = 0;
1.160 raeburn 2572: my ($jsback,$elements) = &crumb_utilities();
2573: my $jscript = '<script type="text/javascript">'."\n".
1.301 bisitz 2574: '// <![CDATA['."\n".
2575: $jsback."\n".
2576: '// ]]>'."\n".
2577: '</script>'."\n";
1.318 raeburn 2578: my %breadcrumb_text = &singleuser_breadcrumb($crstype);
1.351 raeburn 2579: push (@{$brcrum},
2580: {href => "javascript:backPage(document.userupdate)",
2581: text => $breadcrumb_text{'search'},
2582: faq => 282,
2583: bug => 'Instructor Interface',}
2584: );
2585: if ($env{'form.prevphase'} eq 'userpicked') {
2586: push(@{$brcrum},
2587: {href => "javascript:backPage(document.userupdate,'get_user_info','select')",
2588: text => $breadcrumb_text{'userpicked'},
2589: faq => 282,
2590: bug => 'Instructor Interface',});
1.233 raeburn 2591: }
1.224 raeburn 2592: my $helpitem = 'Course_Change_Privileges';
2593: if ($env{'form.action'} eq 'singlestudent') {
2594: $helpitem = 'Course_Add_Student';
2595: }
1.351 raeburn 2596: push(@{$brcrum},
2597: {href => "javascript:backPage(document.userupdate,'$env{'form.prevphase'}','modify')",
2598: text => $breadcrumb_text{'modify'},
2599: faq => 282,
2600: bug => 'Instructor Interface',},
2601: {href => "/adm/createuser",
2602: text => "Result",
2603: faq => 282,
2604: bug => 'Instructor Interface',
2605: help => $helpitem});
2606: my $args = {bread_crumbs => $brcrum,
2607: bread_crumbs_component => 'User Management'};
2608: if ($env{'form.popup'}) {
2609: $args->{'no_nav_bar'} = 1;
2610: }
2611: $r->print(&Apache::loncommon::start_page($title,$jscript,$args));
1.188 raeburn 2612: $r->print(&update_result_form($uhome));
1.27 matthew 2613: # Check Inputs
1.101 albertel 2614: if (! $env{'form.ccuname'} ) {
1.193 raeburn 2615: $r->print($error.&mt('No login name specified').'.'.$end.$rtnlink);
1.27 matthew 2616: return;
2617: }
1.138 albertel 2618: if ( $env{'form.ccuname'} ne
2619: &LONCAPA::clean_username($env{'form.ccuname'}) ) {
1.281 bisitz 2620: $r->print($error.&mt('Invalid login name.').' '.
2621: &mt('Only letters, numbers, periods, dashes, @, and underscores are valid.').
1.193 raeburn 2622: $end.$rtnlink);
1.27 matthew 2623: return;
2624: }
1.101 albertel 2625: if (! $env{'form.ccdomain'} ) {
1.193 raeburn 2626: $r->print($error.&mt('No domain specified').'.'.$end.$rtnlink);
1.27 matthew 2627: return;
2628: }
1.138 albertel 2629: if ( $env{'form.ccdomain'} ne
2630: &LONCAPA::clean_domain($env{'form.ccdomain'}) ) {
1.281 bisitz 2631: $r->print($error.&mt('Invalid domain name.').' '.
2632: &mt('Only letters, numbers, periods, dashes, and underscores are valid.').
1.193 raeburn 2633: $end.$rtnlink);
1.27 matthew 2634: return;
2635: }
1.219 raeburn 2636: if ($uhome eq 'no_host') {
2637: $newuser = 1;
2638: }
1.101 albertel 2639: if (! exists($env{'form.makeuser'})) {
1.29 matthew 2640: # Modifying an existing user, so check the validity of the name
2641: if ($uhome eq 'no_host') {
1.389 bisitz 2642: $r->print(
2643: $error
2644: .'<p class="LC_error">'
2645: .&mt('Unable to determine home server for [_1] in domain [_2].',
2646: '"'.$env{'form.ccuname'}.'"','"'.$env{'form.ccdomain'}.'"')
2647: .'</p>');
1.29 matthew 2648: return;
2649: }
2650: }
1.27 matthew 2651: # Determine authentication method and password for the user being modified
2652: my $amode='';
2653: my $genpwd='';
1.101 albertel 2654: if ($env{'form.login'} eq 'krb') {
1.41 albertel 2655: $amode='krb';
1.101 albertel 2656: $amode.=$env{'form.krbver'};
2657: $genpwd=$env{'form.krbarg'};
2658: } elsif ($env{'form.login'} eq 'int') {
1.27 matthew 2659: $amode='internal';
1.101 albertel 2660: $genpwd=$env{'form.intarg'};
2661: } elsif ($env{'form.login'} eq 'fsys') {
1.27 matthew 2662: $amode='unix';
1.101 albertel 2663: $genpwd=$env{'form.fsysarg'};
2664: } elsif ($env{'form.login'} eq 'loc') {
1.27 matthew 2665: $amode='localauth';
1.101 albertel 2666: $genpwd=$env{'form.locarg'};
1.27 matthew 2667: $genpwd=" " if (!$genpwd);
1.101 albertel 2668: } elsif (($env{'form.login'} eq 'nochange') ||
2669: ($env{'form.login'} eq '' )) {
1.34 matthew 2670: # There is no need to tell the user we did not change what they
2671: # did not ask us to change.
1.35 matthew 2672: # If they are creating a new user but have not specified login
2673: # information this will be caught below.
1.30 matthew 2674: } else {
1.367 golterma 2675: $r->print($error.&mt('Invalid login mode or password').$end.$rtnlink);
2676: return;
1.27 matthew 2677: }
1.164 albertel 2678:
1.188 raeburn 2679: $r->print('<h3>'.&mt('User [_1] in domain [_2]',
1.367 golterma 2680: $env{'form.ccuname'}.' ('.&Apache::loncommon::plainname($env{'form.ccuname'},
2681: $env{'form.ccdomain'}).')', $env{'form.ccdomain'}).'</h3>');
2682: my %prog_state = &Apache::lonhtmlcommon::Create_PrgWin($r,2);
1.344 bisitz 2683:
1.193 raeburn 2684: my (%alerts,%rulematch,%inst_results,%curr_rules);
1.334 raeburn 2685: my @userinfo = ('firstname','middlename','lastname','generation','permanentemail','id');
1.361 raeburn 2686: my @usertools = ('aboutme','blog','webdav','portfolio');
1.411 raeburn 2687: my @requestcourses = ('official','unofficial','community','textbook','placement');
1.362 raeburn 2688: my @requestauthor = ('requestauthor');
1.286 raeburn 2689: my ($othertitle,$usertypes,$types) =
2690: &Apache::loncommon::sorted_inst_types($env{'form.ccdomain'});
1.334 raeburn 2691: my %canmodify_status =
2692: &Apache::lonuserutils::can_modify_userinfo($context,$env{'form.ccdomain'},
2693: ['inststatus']);
1.101 albertel 2694: if ($env{'form.makeuser'}) {
1.164 albertel 2695: $r->print('<h3>'.&mt('Creating new account.').'</h3>');
1.27 matthew 2696: # Check for the authentication mode and password
2697: if (! $amode || ! $genpwd) {
1.193 raeburn 2698: $r->print($error.&mt('Invalid login mode or password').$end.$rtnlink);
1.27 matthew 2699: return;
1.18 albertel 2700: }
1.29 matthew 2701: # Determine desired host
1.101 albertel 2702: my $desiredhost = $env{'form.hserver'};
1.29 matthew 2703: if (lc($desiredhost) eq 'default') {
2704: $desiredhost = undef;
2705: } else {
1.147 albertel 2706: my %home_servers =
2707: &Apache::lonnet::get_servers($env{'form.ccdomain'},'library');
1.29 matthew 2708: if (! exists($home_servers{$desiredhost})) {
1.193 raeburn 2709: $r->print($error.&mt('Invalid home server specified').$end.$rtnlink);
2710: return;
2711: }
2712: }
2713: # Check ID format
2714: my %checkhash;
2715: my %checks = ('id' => 1);
2716: %{$checkhash{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}}} = (
1.219 raeburn 2717: 'newuser' => $newuser,
1.196 raeburn 2718: 'id' => $env{'form.cid'},
1.193 raeburn 2719: );
1.196 raeburn 2720: if ($env{'form.cid'} ne '') {
2721: &Apache::loncommon::user_rule_check(\%checkhash,\%checks,\%alerts,
2722: \%rulematch,\%inst_results,\%curr_rules);
2723: if (ref($alerts{'id'}) eq 'HASH') {
2724: if (ref($alerts{'id'}{$env{'form.ccdomain'}}) eq 'HASH') {
2725: my $domdesc =
2726: &Apache::lonnet::domain($env{'form.ccdomain'},'description');
2727: if ($alerts{'id'}{$env{'form.ccdomain'}}{$env{'form.cid'}}) {
2728: my $userchkmsg;
2729: if (ref($curr_rules{$env{'form.ccdomain'}}) eq 'HASH') {
2730: $userchkmsg =
2731: &Apache::loncommon::instrule_disallow_msg('id',
2732: $domdesc,1).
2733: &Apache::loncommon::user_rule_formats($env{'form.ccdomain'},
2734: $domdesc,$curr_rules{$env{'form.ccdomain'}}{'id'},'id');
2735: }
2736: $r->print($error.&mt('Invalid ID format').$end.
2737: $userchkmsg.$rtnlink);
2738: return;
2739: }
2740: }
1.29 matthew 2741: }
2742: }
1.367 golterma 2743: &Apache::lonhtmlcommon::Increment_PrgWin($r, \%prog_state);
1.27 matthew 2744: # Call modifyuser
2745: my $result = &Apache::lonnet::modifyuser
1.193 raeburn 2746: ($env{'form.ccdomain'},$env{'form.ccuname'},$env{'form.cid'},
1.188 raeburn 2747: $amode,$genpwd,$env{'form.cfirstname'},
2748: $env{'form.cmiddlename'},$env{'form.clastname'},
2749: $env{'form.cgeneration'},undef,$desiredhost,
2750: $env{'form.cpermanentemail'});
1.77 www 2751: $r->print(&mt('Generating user').': '.$result);
1.219 raeburn 2752: $uhome = &Apache::lonnet::homeserver($env{'form.ccuname'},
1.101 albertel 2753: $env{'form.ccdomain'});
1.334 raeburn 2754: my (%changeHash,%newcustom,%changed,%changedinfo);
1.267 raeburn 2755: if ($uhome ne 'no_host') {
1.334 raeburn 2756: if ($context eq 'domain') {
1.378 raeburn 2757: foreach my $name ('portfolio','author') {
2758: if ($env{'form.custom_'.$name.'quota'} == 1) {
2759: if ($env{'form.'.$name.'quota'} eq '') {
2760: $newcustom{$name.'quota'} = 0;
2761: } else {
2762: $newcustom{$name.'quota'} = $env{'form.'.$name.'quota'};
2763: $newcustom{$name.'quota'} =~ s/[^\d\.]//g;
2764: }
2765: if ("a_admin($newcustom{$name.'quota'},\%changeHash,$name)) {
2766: $changed{$name.'quota'} = 1;
2767: }
1.334 raeburn 2768: }
2769: }
2770: foreach my $item (@usertools) {
2771: if ($env{'form.custom'.$item} == 1) {
2772: $newcustom{$item} = $env{'form.tools_'.$item};
2773: $changed{$item} = &tool_admin($item,$newcustom{$item},
2774: \%changeHash,'tools');
2775: }
1.267 raeburn 2776: }
1.334 raeburn 2777: foreach my $item (@requestcourses) {
1.341 raeburn 2778: if ($env{'form.custom'.$item} == 1) {
2779: $newcustom{$item} = $env{'form.crsreq_'.$item};
2780: if ($env{'form.crsreq_'.$item} eq 'autolimit') {
2781: $newcustom{$item} .= '=';
1.383 raeburn 2782: $env{'form.crsreq_'.$item.'_limit'} =~ s/\D+//g;
2783: if ($env{'form.crsreq_'.$item.'_limit'}) {
1.341 raeburn 2784: $newcustom{$item} .= $env{'form.crsreq_'.$item.'_limit'};
2785: }
1.334 raeburn 2786: }
1.341 raeburn 2787: $changed{$item} = &tool_admin($item,$newcustom{$item},
2788: \%changeHash,'requestcourses');
1.334 raeburn 2789: }
1.275 raeburn 2790: }
1.362 raeburn 2791: if ($env{'form.customrequestauthor'} == 1) {
2792: $newcustom{'requestauthor'} = $env{'form.requestauthor'};
2793: $changed{'requestauthor'} = &tool_admin('requestauthor',
2794: $newcustom{'requestauthor'},
2795: \%changeHash,'requestauthor');
2796: }
1.414 raeburn 2797: if (&Apache::lonnet::allowed('cdh',$env{'request.role.domain'})) {
2798: my @adds = &Apache::loncommon::get_env_multiple('form.adhocroleadd');
2799: if (&adhocrole_changes(\%changeHash)) {
2800: $changed{'adhocroles.'.$env{'request.role.domain'}} = $changeHash{'adhocroles.'.$env{'request.role.domain'}};
2801: }
2802: }
1.275 raeburn 2803: }
1.334 raeburn 2804: if ($canmodify_status{'inststatus'}) {
2805: if (exists($env{'form.inststatus'})) {
2806: my @inststatuses = &Apache::loncommon::get_env_multiple('form.inststatus');
2807: if (@inststatuses > 0) {
2808: $changeHash{'inststatus'} = join(',',@inststatuses);
2809: $changed{'inststatus'} = $changeHash{'inststatus'};
1.306 raeburn 2810: }
2811: }
1.232 raeburn 2812: }
1.334 raeburn 2813: if (keys(%changed)) {
2814: foreach my $item (@userinfo) {
2815: $changeHash{$item} = $env{'form.c'.$item};
1.286 raeburn 2816: }
1.267 raeburn 2817: my $chgresult =
2818: &Apache::lonnet::put('environment',\%changeHash,
2819: $env{'form.ccdomain'},$env{'form.ccuname'});
2820: }
1.232 raeburn 2821: }
1.219 raeburn 2822: $r->print('<br />'.&mt('Home server').': '.$uhome.' '.
2823: &Apache::lonnet::hostname($uhome));
1.101 albertel 2824: } elsif (($env{'form.login'} ne 'nochange') &&
2825: ($env{'form.login'} ne '' )) {
1.27 matthew 2826: # Modify user privileges
2827: if (! $amode || ! $genpwd) {
1.193 raeburn 2828: $r->print($error.'Invalid login mode or password'.$end.$rtnlink);
1.27 matthew 2829: return;
1.20 harris41 2830: }
1.395 bisitz 2831: # Only allow authentication modification if the person has authority
1.101 albertel 2832: if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'})) {
1.20 harris41 2833: $r->print('Modifying authentication: '.
1.31 matthew 2834: &Apache::lonnet::modifyuserauth(
1.101 albertel 2835: $env{'form.ccdomain'},$env{'form.ccuname'},
1.21 harris41 2836: $amode,$genpwd));
1.102 albertel 2837: $r->print('<br />'.&mt('Home server').': '.&Apache::lonnet::homeserver
1.101 albertel 2838: ($env{'form.ccuname'},$env{'form.ccdomain'}));
1.4 www 2839: } else {
1.27 matthew 2840: # Okay, this is a non-fatal error.
1.395 bisitz 2841: $r->print($error.&mt('You do not have the authority to modify this users authentication information.').$end);
1.27 matthew 2842: }
1.28 matthew 2843: }
1.344 bisitz 2844: $r->rflush(); # Finish display of header before time consuming actions start
1.367 golterma 2845: &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state);
1.28 matthew 2846: ##
1.375 raeburn 2847: my (@userroles,%userupdate,$cnum,$cdom,$defaultcredits,%namechanged);
1.213 raeburn 2848: if ($context eq 'course') {
1.375 raeburn 2849: ($cnum,$cdom) =
2850: &Apache::lonuserutils::get_course_identity();
1.318 raeburn 2851: $crstype = &Apache::loncommon::course_type($cdom.'_'.$cnum);
1.375 raeburn 2852: if ($showcredits) {
2853: $defaultcredits = &Apache::lonuserutils::get_defaultcredits($cdom,$cnum);
2854: }
1.213 raeburn 2855: }
1.101 albertel 2856: if (! $env{'form.makeuser'} ) {
1.28 matthew 2857: # Check for need to change
2858: my %userenv = &Apache::lonnet::get
1.134 raeburn 2859: ('environment',['firstname','middlename','lastname','generation',
1.378 raeburn 2860: 'id','permanentemail','portfolioquota','authorquota','inststatus',
2861: 'tools.aboutme','tools.blog','tools.webdav','tools.portfolio',
1.361 raeburn 2862: 'requestcourses.official','requestcourses.unofficial',
1.384 raeburn 2863: 'requestcourses.community','requestcourses.textbook',
2864: 'reqcrsotherdom.official','reqcrsotherdom.unofficial',
2865: 'reqcrsotherdom.community','reqcrsotherdom.textbook',
1.414 raeburn 2866: 'reqcrsotherdom.placement','requestauthor',
2867: 'adhocroles.'.$env{'request.role.domain'}],
1.160 raeburn 2868: $env{'form.ccdomain'},$env{'form.ccuname'});
1.28 matthew 2869: my ($tmp) = keys(%userenv);
2870: if ($tmp =~ /^(con_lost|error)/i) {
2871: %userenv = ();
2872: }
1.206 raeburn 2873: my $no_forceid_alert;
2874: # Check to see if user information can be changed
2875: my %domconfig =
2876: &Apache::lonnet::get_dom('configuration',['usermodification'],
2877: $env{'form.ccdomain'});
1.213 raeburn 2878: my @statuses = ('active','future');
2879: my %roles = &Apache::lonnet::get_my_roles($env{'form.ccuname'},$env{'form.ccdomain'},'userroles',\@statuses,undef,$env{'request.role.domain'});
2880: my ($auname,$audom);
1.220 raeburn 2881: if ($context eq 'author') {
1.206 raeburn 2882: $auname = $env{'user.name'};
2883: $audom = $env{'user.domain'};
2884: }
2885: foreach my $item (keys(%roles)) {
1.220 raeburn 2886: my ($rolenum,$roledom,$role) = split(/:/,$item,-1);
1.206 raeburn 2887: if ($context eq 'course') {
2888: if ($cnum ne '' && $cdom ne '') {
2889: if ($rolenum eq $cnum && $roledom eq $cdom) {
2890: if (!grep(/^\Q$role\E$/,@userroles)) {
2891: push(@userroles,$role);
2892: }
2893: }
2894: }
2895: } elsif ($context eq 'author') {
2896: if ($rolenum eq $auname && $roledom eq $audom) {
2897: if (!grep(/^\Q$role\E$/,@userroles)) {
2898: push(@userroles,$role);
2899: }
2900: }
2901: }
2902: }
1.220 raeburn 2903: if ($env{'form.action'} eq 'singlestudent') {
2904: if (!grep(/^st$/,@userroles)) {
2905: push(@userroles,'st');
2906: }
2907: } else {
2908: # Check for course or co-author roles being activated or re-enabled
2909: if ($context eq 'author' || $context eq 'course') {
2910: foreach my $key (keys(%env)) {
2911: if ($context eq 'author') {
2912: if ($key=~/^form\.act_\Q$audom\E_\Q$auname\E_([^_]+)/) {
2913: if (!grep(/^\Q$1\E$/,@userroles)) {
2914: push(@userroles,$1);
2915: }
2916: } elsif ($key =~/^form\.ren\:\Q$audom\E\/\Q$auname\E_([^_]+)/) {
2917: if (!grep(/^\Q$1\E$/,@userroles)) {
2918: push(@userroles,$1);
2919: }
1.206 raeburn 2920: }
1.220 raeburn 2921: } elsif ($context eq 'course') {
2922: if ($key=~/^form\.act_\Q$cdom\E_\Q$cnum\E_([^_]+)/) {
2923: if (!grep(/^\Q$1\E$/,@userroles)) {
2924: push(@userroles,$1);
2925: }
2926: } elsif ($key =~/^form\.ren\:\Q$cdom\E\/\Q$cnum\E(\/?\w*)_([^_]+)/) {
2927: if (!grep(/^\Q$1\E$/,@userroles)) {
2928: push(@userroles,$1);
2929: }
1.206 raeburn 2930: }
2931: }
2932: }
2933: }
2934: }
2935: #Check to see if we can change personal data for the user
2936: my (@mod_disallowed,@longroles);
2937: foreach my $role (@userroles) {
2938: if ($role eq 'cr') {
2939: push(@longroles,'Custom');
2940: } else {
1.318 raeburn 2941: push(@longroles,&Apache::lonnet::plaintext($role,$crstype));
1.206 raeburn 2942: }
2943: }
1.219 raeburn 2944: my %canmodify = &Apache::lonuserutils::can_modify_userinfo($context,$env{'form.ccdomain'},\@userinfo,\@userroles);
2945: foreach my $item (@userinfo) {
1.28 matthew 2946: # Strip leading and trailing whitespace
1.203 raeburn 2947: $env{'form.c'.$item} =~ s/(\s+$|^\s+)//g;
1.219 raeburn 2948: if (!$canmodify{$item}) {
1.207 raeburn 2949: if (defined($env{'form.c'.$item})) {
2950: if ($env{'form.c'.$item} ne $userenv{$item}) {
2951: push(@mod_disallowed,$item);
2952: }
1.206 raeburn 2953: }
2954: $env{'form.c'.$item} = $userenv{$item};
2955: }
1.28 matthew 2956: }
1.259 bisitz 2957: # Check to see if we can change the Student/Employee ID
1.196 raeburn 2958: my $forceid = $env{'form.forceid'};
2959: my $recurseid = $env{'form.recurseid'};
2960: my (%alerts,%rulematch,%idinst_results,%curr_rules,%got_rules);
1.203 raeburn 2961: my %uidhash = &Apache::lonnet::idrget($env{'form.ccdomain'},
2962: $env{'form.ccuname'});
2963: if (($uidhash{$env{'form.ccuname'}}) &&
2964: ($uidhash{$env{'form.ccuname'}}!~/error\:/) &&
2965: (!$forceid)) {
2966: if ($env{'form.cid'} ne $uidhash{$env{'form.ccuname'}}) {
2967: $env{'form.cid'} = $userenv{'id'};
1.293 bisitz 2968: $no_forceid_alert = &mt('New student/employee ID does not match existing ID for this user.')
1.259 bisitz 2969: .'<br />'
2970: .&mt("Change is not permitted without checking the 'Force ID change' checkbox on the previous page.")
2971: .'<br />'."\n";
1.203 raeburn 2972: }
2973: }
2974: if ($env{'form.cid'} ne $userenv{'id'}) {
1.196 raeburn 2975: my $checkhash;
2976: my $checks = { 'id' => 1 };
2977: $checkhash->{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}} =
2978: { 'newuser' => $newuser,
2979: 'id' => $env{'form.cid'},
2980: };
2981: &Apache::loncommon::user_rule_check($checkhash,$checks,
2982: \%alerts,\%rulematch,\%idinst_results,\%curr_rules,\%got_rules);
2983: if (ref($alerts{'id'}) eq 'HASH') {
2984: if (ref($alerts{'id'}{$env{'form.ccdomain'}}) eq 'HASH') {
1.203 raeburn 2985: $env{'form.cid'} = $userenv{'id'};
1.196 raeburn 2986: }
2987: }
2988: }
1.378 raeburn 2989: my (%quotachanged,%oldquota,%newquota,%olddefquota,%newdefquota,
2990: $oldinststatus,$newinststatus,%oldisdefault,%newisdefault,%oldsettings,
1.339 raeburn 2991: %oldsettingstext,%newsettings,%newsettingstext,@disporder,
1.378 raeburn 2992: %oldsettingstatus,%newsettingstatus);
1.334 raeburn 2993: @disporder = ('inststatus');
2994: if ($env{'request.role.domain'} eq $env{'form.ccdomain'}) {
1.362 raeburn 2995: push(@disporder,'requestcourses','requestauthor');
1.334 raeburn 2996: } else {
2997: push(@disporder,'reqcrsotherdom');
2998: }
2999: push(@disporder,('quota','tools'));
1.338 raeburn 3000: $oldinststatus = $userenv{'inststatus'};
1.378 raeburn 3001: foreach my $name ('portfolio','author') {
3002: ($olddefquota{$name},$oldsettingstatus{$name}) =
3003: &Apache::loncommon::default_quota($env{'form.ccdomain'},$oldinststatus,$name);
3004: ($newdefquota{$name},$newsettingstatus{$name}) = ($olddefquota{$name},$oldsettingstatus{$name});
3005: }
1.414 raeburn 3006: push(@disporder,'adhocroles');
1.334 raeburn 3007: my %canshow;
1.220 raeburn 3008: if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
1.334 raeburn 3009: $canshow{'quota'} = 1;
1.220 raeburn 3010: }
1.267 raeburn 3011: if (&Apache::lonnet::allowed('mut',$env{'form.ccdomain'})) {
1.334 raeburn 3012: $canshow{'tools'} = 1;
1.267 raeburn 3013: }
1.275 raeburn 3014: if (&Apache::lonnet::allowed('ccc',$env{'form.ccdomain'})) {
1.334 raeburn 3015: $canshow{'requestcourses'} = 1;
1.300 raeburn 3016: } elsif (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
1.334 raeburn 3017: $canshow{'reqcrsotherdom'} = 1;
1.275 raeburn 3018: }
1.286 raeburn 3019: if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'})) {
1.334 raeburn 3020: $canshow{'inststatus'} = 1;
1.286 raeburn 3021: }
1.362 raeburn 3022: if (&Apache::lonnet::allowed('cau',$env{'form.ccdomain'})) {
3023: $canshow{'requestauthor'} = 1;
3024: }
1.414 raeburn 3025: if (&Apache::lonnet::allowed('cdh',$env{'request.role.domain'})) {
3026: $canshow{'adhocroles'} = 1;
3027: }
1.267 raeburn 3028: my (%changeHash,%changed);
1.286 raeburn 3029: if ($oldinststatus eq '') {
1.334 raeburn 3030: $oldsettings{'inststatus'} = $othertitle;
1.286 raeburn 3031: } else {
3032: if (ref($usertypes) eq 'HASH') {
1.334 raeburn 3033: $oldsettings{'inststatus'} = join(', ',map{ $usertypes->{ &unescape($_) }; } (split(/:/,$userenv{'inststatus'})));
1.286 raeburn 3034: } else {
1.334 raeburn 3035: $oldsettings{'inststatus'} = join(', ',map{ &unescape($_); } (split(/:/,$userenv{'inststatus'})));
1.286 raeburn 3036: }
3037: }
3038: $changeHash{'inststatus'} = $userenv{'inststatus'};
1.334 raeburn 3039: if ($canmodify_status{'inststatus'}) {
3040: $canshow{'inststatus'} = 1;
1.286 raeburn 3041: if (exists($env{'form.inststatus'})) {
3042: my @inststatuses = &Apache::loncommon::get_env_multiple('form.inststatus');
3043: if (@inststatuses > 0) {
3044: $newinststatus = join(':',map { &escape($_); } @inststatuses);
3045: $changeHash{'inststatus'} = $newinststatus;
3046: if ($newinststatus ne $oldinststatus) {
3047: $changed{'inststatus'} = $newinststatus;
1.378 raeburn 3048: foreach my $name ('portfolio','author') {
3049: ($newdefquota{$name},$newsettingstatus{$name}) =
3050: &Apache::loncommon::default_quota($env{'form.ccdomain'},$newinststatus,$name);
3051: }
1.286 raeburn 3052: }
3053: if (ref($usertypes) eq 'HASH') {
1.334 raeburn 3054: $newsettings{'inststatus'} = join(', ',map{ $usertypes->{$_}; } (@inststatuses));
1.286 raeburn 3055: } else {
1.337 raeburn 3056: $newsettings{'inststatus'} = join(', ',@inststatuses);
1.286 raeburn 3057: }
1.334 raeburn 3058: }
3059: } else {
3060: $newinststatus = '';
3061: $changeHash{'inststatus'} = $newinststatus;
3062: $newsettings{'inststatus'} = $othertitle;
3063: if ($newinststatus ne $oldinststatus) {
3064: $changed{'inststatus'} = $changeHash{'inststatus'};
1.378 raeburn 3065: foreach my $name ('portfolio','author') {
3066: ($newdefquota{$name},$newsettingstatus{$name}) =
3067: &Apache::loncommon::default_quota($env{'form.ccdomain'},$newinststatus,$name);
3068: }
1.286 raeburn 3069: }
3070: }
1.334 raeburn 3071: } elsif ($context ne 'selfcreate') {
3072: $canshow{'inststatus'} = 1;
1.337 raeburn 3073: $newsettings{'inststatus'} = $oldsettings{'inststatus'};
1.286 raeburn 3074: }
1.378 raeburn 3075: foreach my $name ('portfolio','author') {
3076: $changeHash{$name.'quota'} = $userenv{$name.'quota'};
3077: }
1.334 raeburn 3078: if ($context eq 'domain') {
1.378 raeburn 3079: foreach my $name ('portfolio','author') {
3080: if ($userenv{$name.'quota'} ne '') {
3081: $oldquota{$name} = $userenv{$name.'quota'};
3082: if ($env{'form.custom_'.$name.'quota'} == 1) {
3083: if ($env{'form.'.$name.'quota'} eq '') {
3084: $newquota{$name} = 0;
3085: } else {
3086: $newquota{$name} = $env{'form.'.$name.'quota'};
3087: $newquota{$name} =~ s/[^\d\.]//g;
3088: }
3089: if ($newquota{$name} != $oldquota{$name}) {
3090: if ("a_admin($newquota{$name},\%changeHash,$name)) {
3091: $changed{$name.'quota'} = 1;
3092: }
3093: }
1.334 raeburn 3094: } else {
1.378 raeburn 3095: if ("a_admin('',\%changeHash,$name)) {
3096: $changed{$name.'quota'} = 1;
3097: $newquota{$name} = $newdefquota{$name};
3098: $newisdefault{$name} = 1;
3099: }
1.334 raeburn 3100: }
1.149 raeburn 3101: } else {
1.378 raeburn 3102: $oldisdefault{$name} = 1;
3103: $oldquota{$name} = $olddefquota{$name};
3104: if ($env{'form.custom_'.$name.'quota'} == 1) {
3105: if ($env{'form.'.$name.'quota'} eq '') {
3106: $newquota{$name} = 0;
3107: } else {
3108: $newquota{$name} = $env{'form.'.$name.'quota'};
3109: $newquota{$name} =~ s/[^\d\.]//g;
3110: }
3111: if ("a_admin($newquota{$name},\%changeHash,$name)) {
3112: $changed{$name.'quota'} = 1;
3113: }
1.334 raeburn 3114: } else {
1.378 raeburn 3115: $newquota{$name} = $newdefquota{$name};
3116: $newisdefault{$name} = 1;
1.334 raeburn 3117: }
1.378 raeburn 3118: }
3119: if ($oldisdefault{$name}) {
3120: $oldsettingstext{'quota'}{$name} = &get_defaultquota_text($oldsettingstatus{$name});
1.383 raeburn 3121: } else {
3122: $oldsettingstext{'quota'}{$name} = &mt('custom quota: [_1] MB',$oldquota{$name});
1.378 raeburn 3123: }
3124: if ($newisdefault{$name}) {
3125: $newsettingstext{'quota'}{$name} = &get_defaultquota_text($newsettingstatus{$name});
1.383 raeburn 3126: } else {
3127: $newsettingstext{'quota'}{$name} = &mt('custom quota: [_1] MB',$newquota{$name});
1.134 raeburn 3128: }
3129: }
1.334 raeburn 3130: &tool_changes('tools',\@usertools,\%oldsettings,\%oldsettingstext,\%userenv,
3131: \%changeHash,\%changed,\%newsettings,\%newsettingstext);
3132: if ($env{'form.ccdomain'} eq $env{'request.role.domain'}) {
3133: &tool_changes('requestcourses',\@requestcourses,\%oldsettings,\%oldsettingstext,
3134: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
1.384 raeburn 3135: &tool_changes('requestauthor',\@requestauthor,\%oldsettings,\%oldsettingstext,
3136: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
1.149 raeburn 3137: } else {
1.334 raeburn 3138: &tool_changes('reqcrsotherdom',\@requestcourses,\%oldsettings,\%oldsettingstext,
3139: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
1.149 raeburn 3140: }
1.414 raeburn 3141: if ($userenv{'adhocroles.'.$env{'request.role.domain'}}) {
3142: $changeHash{'adhocroles.'.$env{'request.role.domain'}} = $userenv{'adhocroles.'.$env{'request.role.domain'}};
3143: }
3144: if (&adhocrole_changes(\%changeHash,\%userenv)) {
3145: $changed{'adhocroles'} = 1;
3146: $oldsettings{'adhocroles'} = $userenv{'adhocroles.'.$env{'request.role.domain'}};
3147: $newsettings{'adhocroles'} = $changeHash{'adhocroles.'.$env{'request.role.domain'}};
3148: }
1.149 raeburn 3149: }
1.334 raeburn 3150: foreach my $item (@userinfo) {
3151: if ($env{'form.c'.$item} ne $userenv{$item}) {
3152: $namechanged{$item} = 1;
3153: }
1.204 raeburn 3154: }
1.378 raeburn 3155: foreach my $name ('portfolio','author') {
1.390 bisitz 3156: $oldsettings{'quota'}{$name} = &mt('[_1] MB',$oldquota{$name});
3157: $newsettings{'quota'}{$name} = &mt('[_1] MB',$newquota{$name});
1.378 raeburn 3158: }
1.334 raeburn 3159: if ((keys(%namechanged) > 0) || (keys(%changed) > 0)) {
1.267 raeburn 3160: my ($chgresult,$namechgresult);
3161: if (keys(%changed) > 0) {
3162: $chgresult =
1.204 raeburn 3163: &Apache::lonnet::put('environment',\%changeHash,
3164: $env{'form.ccdomain'},$env{'form.ccuname'});
1.267 raeburn 3165: if ($chgresult eq 'ok') {
3166: if (($env{'user.name'} eq $env{'form.ccuname'}) &&
3167: ($env{'user.domain'} eq $env{'form.ccdomain'})) {
1.270 raeburn 3168: my %newenvhash;
3169: foreach my $key (keys(%changed)) {
1.411 raeburn 3170: if (($key eq 'official') || ($key eq 'unofficial') ||
3171: ($key eq 'community') || ($key eq 'textbook') ||
3172: ($key eq 'placement')) {
1.279 raeburn 3173: $newenvhash{'environment.requestcourses.'.$key} =
3174: $changeHash{'requestcourses.'.$key};
1.362 raeburn 3175: if ($changeHash{'requestcourses.'.$key}) {
1.332 raeburn 3176: $newenvhash{'environment.canrequest.'.$key} = 1;
1.279 raeburn 3177: } else {
3178: $newenvhash{'environment.canrequest.'.$key} =
3179: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
3180: $key,'reload','requestcourses');
3181: }
1.362 raeburn 3182: } elsif ($key eq 'requestauthor') {
3183: $newenvhash{'environment.'.$key} = $changeHash{$key};
3184: if ($changeHash{$key}) {
3185: $newenvhash{'environment.canrequest.author'} = 1;
3186: } else {
3187: $newenvhash{'environment.canrequest.author'} =
3188: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
3189: $key,'reload','requestauthor');
3190: }
1.414 raeburn 3191: } elsif ($key eq 'adhocroles') {
3192: $newenvhash{'adhocroles.'.$env{'request.role.domain'}} =
3193: $changeHash{'adhocroles.'.$env{'request.role.domain'}};
1.275 raeburn 3194: } elsif ($key ne 'quota') {
1.270 raeburn 3195: $newenvhash{'environment.tools.'.$key} =
3196: $changeHash{'tools.'.$key};
1.279 raeburn 3197: if ($changeHash{'tools.'.$key} ne '') {
3198: $newenvhash{'environment.availabletools.'.$key} =
3199: $changeHash{'tools.'.$key};
3200: } else {
3201: $newenvhash{'environment.availabletools.'.$key} =
1.367 golterma 3202: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
3203: $key,'reload','tools');
1.279 raeburn 3204: }
1.270 raeburn 3205: }
3206: }
1.271 raeburn 3207: if (keys(%newenvhash)) {
3208: &Apache::lonnet::appenv(\%newenvhash);
3209: }
1.267 raeburn 3210: }
3211: }
1.204 raeburn 3212: }
1.334 raeburn 3213: if (keys(%namechanged) > 0) {
1.337 raeburn 3214: foreach my $field (@userinfo) {
3215: $changeHash{$field} = $env{'form.c'.$field};
3216: }
3217: # Make the change
1.204 raeburn 3218: $namechgresult =
3219: &Apache::lonnet::modifyuser($env{'form.ccdomain'},
3220: $env{'form.ccuname'},$changeHash{'id'},undef,undef,
3221: $changeHash{'firstname'},$changeHash{'middlename'},
3222: $changeHash{'lastname'},$changeHash{'generation'},
1.337 raeburn 3223: $changeHash{'id'},undef,$changeHash{'permanentemail'},undef,\@userinfo);
1.220 raeburn 3224: %userupdate = (
3225: lastname => $env{'form.clastname'},
3226: middlename => $env{'form.cmiddlename'},
3227: firstname => $env{'form.cfirstname'},
3228: generation => $env{'form.cgeneration'},
3229: id => $env{'form.cid'},
3230: );
1.204 raeburn 3231: }
1.334 raeburn 3232: if (((keys(%namechanged) > 0) && $namechgresult eq 'ok') ||
1.267 raeburn 3233: ((keys(%changed) > 0) && $chgresult eq 'ok')) {
1.28 matthew 3234: # Tell the user we changed the name
1.334 raeburn 3235: &display_userinfo($r,1,\@disporder,\%canshow,\@requestcourses,
1.362 raeburn 3236: \@usertools,\@requestauthor,\%userenv,\%changed,\%namechanged,
1.334 raeburn 3237: \%oldsettings, \%oldsettingstext,\%newsettings,
3238: \%newsettingstext);
1.203 raeburn 3239: if ($env{'form.cid'} ne $userenv{'id'}) {
3240: &Apache::lonnet::idput($env{'form.ccdomain'},
1.407 raeburn 3241: {$env{'form.ccuname'} => $env{'form.cid'}},$uhome,'ids');
1.203 raeburn 3242: if (($recurseid) &&
3243: (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'}))) {
3244: my $idresult =
3245: &Apache::lonuserutils::propagate_id_change(
3246: $env{'form.ccuname'},$env{'form.ccdomain'},
3247: \%userupdate);
3248: $r->print('<br />'.$idresult.'<br />');
3249: }
1.196 raeburn 3250: }
1.149 raeburn 3251: if (($env{'form.ccdomain'} eq $env{'user.domain'}) &&
3252: ($env{'form.ccuname'} eq $env{'user.name'})) {
3253: my %newenvhash;
3254: foreach my $key (keys(%changeHash)) {
3255: $newenvhash{'environment.'.$key} = $changeHash{$key};
3256: }
1.238 raeburn 3257: &Apache::lonnet::appenv(\%newenvhash);
1.149 raeburn 3258: }
1.28 matthew 3259: } else { # error occurred
1.389 bisitz 3260: $r->print(
3261: '<p class="LC_error">'
3262: .&mt('Unable to successfully change environment for [_1] in domain [_2].',
3263: '"'.$env{'form.ccuname'}.'"',
3264: '"'.$env{'form.ccdomain'}.'"')
3265: .'</p>');
1.28 matthew 3266: }
1.334 raeburn 3267: } else { # End of if ($env ... ) logic
1.275 raeburn 3268: # They did not want to change the users name, quota, tool availability,
3269: # or ability to request creation of courses,
1.267 raeburn 3270: # but we can still tell them what the name and quota and availabilities are
1.334 raeburn 3271: &display_userinfo($r,undef,\@disporder,\%canshow,\@requestcourses,
1.362 raeburn 3272: \@usertools,\@requestauthor,\%userenv,\%changed,\%namechanged,\%oldsettings,
1.334 raeburn 3273: \%oldsettingstext,\%newsettings,\%newsettingstext);
1.28 matthew 3274: }
1.206 raeburn 3275: if (@mod_disallowed) {
3276: my ($rolestr,$contextname);
3277: if (@longroles > 0) {
3278: $rolestr = join(', ',@longroles);
3279: } else {
3280: $rolestr = &mt('No roles');
3281: }
3282: if ($context eq 'course') {
1.399 bisitz 3283: $contextname = 'course';
1.206 raeburn 3284: } elsif ($context eq 'author') {
1.399 bisitz 3285: $contextname = 'co-author';
1.206 raeburn 3286: }
3287: $r->print(&mt('The following fields were not updated: ').'<ul>');
3288: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
3289: foreach my $field (@mod_disallowed) {
3290: $r->print('<li>'.$fieldtitles{$field}.'</li>'."\n");
3291: }
1.207 raeburn 3292: $r->print('</ul>');
3293: if (@mod_disallowed == 1) {
1.399 bisitz 3294: $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 3295: } else {
1.399 bisitz 3296: $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 3297: }
1.292 bisitz 3298: my $helplink = 'javascript:helpMenu('."'display'".')';
3299: $r->print('<span class="LC_cusr_emph">'.$rolestr.'</span><br />'
3300: .&mt('Please contact your [_1]helpdesk[_2] for more information.'
3301: ,'<a href="'.$helplink.'">','</a>')
3302: .'<br />');
1.206 raeburn 3303: }
1.259 bisitz 3304: $r->print('<span class="LC_warning">'
3305: .$no_forceid_alert
3306: .&Apache::lonuserutils::print_namespacing_alerts($env{'form.ccdomain'},\%alerts,\%curr_rules)
3307: .'</span>');
1.4 www 3308: }
1.367 golterma 3309: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
1.220 raeburn 3310: if ($env{'form.action'} eq 'singlestudent') {
1.375 raeburn 3311: &enroll_single_student($r,$uhome,$amode,$genpwd,$now,$newuser,$context,
3312: $crstype,$showcredits,$defaultcredits);
1.386 bisitz 3313: my $linktext = ($crstype eq 'Community' ?
3314: &mt('Enroll Another Member') : &mt('Enroll Another Student'));
3315: $r->print(
3316: &Apache::lonhtmlcommon::actionbox([
3317: '<a href="javascript:backPage(document.userupdate)">'
3318: .($crstype eq 'Community' ?
3319: &mt('Enroll Another Member') : &mt('Enroll Another Student'))
3320: .'</a>']));
1.220 raeburn 3321: } else {
1.375 raeburn 3322: my @rolechanges = &update_roles($r,$context,$showcredits);
1.334 raeburn 3323: if (keys(%namechanged) > 0) {
1.220 raeburn 3324: if ($context eq 'course') {
3325: if (@userroles > 0) {
1.225 raeburn 3326: if ((@rolechanges == 0) ||
3327: (!(grep(/^st$/,@rolechanges)))) {
3328: if (grep(/^st$/,@userroles)) {
3329: my $classlistupdated =
3330: &Apache::lonuserutils::update_classlist($cdom,
1.220 raeburn 3331: $cnum,$env{'form.ccdomain'},
3332: $env{'form.ccuname'},\%userupdate);
1.225 raeburn 3333: }
1.220 raeburn 3334: }
3335: }
3336: }
3337: }
1.226 raeburn 3338: my $userinfo = &Apache::loncommon::plainname($env{'form.ccuname'},
1.233 raeburn 3339: $env{'form.ccdomain'});
3340: if ($env{'form.popup'}) {
3341: $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a></p>');
3342: } else {
1.367 golterma 3343: $r->print('<br />'.&Apache::lonhtmlcommon::actionbox(['<a href="javascript:backPage(document.userupdate,'."'$env{'form.prevphase'}','modify'".')">'
3344: .&mt('Modify this user: [_1]','<span class="LC_cusr_emph">'.$env{'form.ccuname'}.':'.$env{'form.ccdomain'}.' ('.$userinfo.')</span>').'</a>',
3345: '<a href="javascript:backPage(document.userupdate)">'.&mt('Create/Modify Another User').'</a>']));
1.233 raeburn 3346: }
1.220 raeburn 3347: }
3348: }
3349:
1.334 raeburn 3350: sub display_userinfo {
1.362 raeburn 3351: my ($r,$changed,$order,$canshow,$requestcourses,$usertools,$requestauthor,
3352: $userenv,$changedhash,$namechangedhash,$oldsetting,$oldsettingtext,
1.334 raeburn 3353: $newsetting,$newsettingtext) = @_;
3354: return unless (ref($order) eq 'ARRAY' &&
3355: ref($canshow) eq 'HASH' &&
3356: ref($requestcourses) eq 'ARRAY' &&
1.362 raeburn 3357: ref($requestauthor) eq 'ARRAY' &&
1.334 raeburn 3358: ref($usertools) eq 'ARRAY' &&
3359: ref($userenv) eq 'HASH' &&
3360: ref($changedhash) eq 'HASH' &&
3361: ref($oldsetting) eq 'HASH' &&
3362: ref($oldsettingtext) eq 'HASH' &&
3363: ref($newsetting) eq 'HASH' &&
3364: ref($newsettingtext) eq 'HASH');
3365: my %lt=&Apache::lonlocal::texthash(
1.372 raeburn 3366: 'ui' => 'User Information',
1.334 raeburn 3367: 'uic' => 'User Information Changed',
3368: 'firstname' => 'First Name',
3369: 'middlename' => 'Middle Name',
3370: 'lastname' => 'Last Name',
3371: 'generation' => 'Generation',
3372: 'id' => 'Student/Employee ID',
3373: 'permanentemail' => 'Permanent e-mail address',
1.378 raeburn 3374: 'portfolioquota' => 'Disk space allocated to portfolio files',
1.385 bisitz 3375: 'authorquota' => 'Disk space allocated to Authoring Space',
1.334 raeburn 3376: 'blog' => 'Blog Availability',
1.361 raeburn 3377: 'webdav' => 'WebDAV Availability',
1.334 raeburn 3378: 'aboutme' => 'Personal Information Page Availability',
3379: 'portfolio' => 'Portfolio Availability',
3380: 'official' => 'Can Request Official Courses',
3381: 'unofficial' => 'Can Request Unofficial Courses',
3382: 'community' => 'Can Request Communities',
1.384 raeburn 3383: 'textbook' => 'Can Request Textbook Courses',
1.411 raeburn 3384: 'placement' => 'Can Request Placement Tests',
1.362 raeburn 3385: 'requestauthor' => 'Can Request Author Role',
1.414 raeburn 3386: 'adhocroles' => 'Ad Hoc Roles Selectable via Helpdesk Role',
1.334 raeburn 3387: 'inststatus' => "Affiliation",
3388: 'prvs' => 'Previous Value:',
3389: 'chto' => 'Changed To:'
3390: );
3391: if ($changed) {
1.372 raeburn 3392: $r->print('<h3>'.$lt{'uic'}.'</h3>'.
1.367 golterma 3393: &Apache::loncommon::start_data_table().
3394: &Apache::loncommon::start_data_table_header_row());
1.334 raeburn 3395: $r->print("<th> </th>\n");
1.367 golterma 3396: $r->print('<th><b>'.$lt{'prvs'}.'</b></th>');
3397: $r->print('<th><span class="LC_nobreak"><b>'.$lt{'chto'}.'</b></span></th>');
3398: $r->print(&Apache::loncommon::end_data_table_header_row());
3399: my @userinfo = ('firstname','middlename','lastname','generation','permanentemail','id');
3400:
1.334 raeburn 3401: foreach my $item (@userinfo) {
3402: my $value = $env{'form.c'.$item};
1.367 golterma 3403: #show changes only:
1.383 raeburn 3404: unless ($value eq $userenv->{$item}){
1.367 golterma 3405: $r->print(&Apache::loncommon::start_data_table_row());
3406: $r->print("<td>$lt{$item}</td>\n");
1.383 raeburn 3407: $r->print("<td>".$userenv->{$item}."</td>\n");
1.367 golterma 3408: $r->print("<td>$value </td>\n");
3409: $r->print(&Apache::loncommon::end_data_table_row());
1.334 raeburn 3410: }
3411: }
3412: foreach my $entry (@{$order}) {
1.383 raeburn 3413: if ($canshow->{$entry}) {
3414: if (($entry eq 'requestcourses') || ($entry eq 'reqcrsotherdom') || ($entry eq 'requestauthor')) {
3415: my @items;
3416: if ($entry eq 'requestauthor') {
3417: @items = ($entry);
3418: } else {
3419: @items = @{$requestcourses};
1.384 raeburn 3420: }
1.383 raeburn 3421: foreach my $item (@items) {
3422: if (($newsetting->{$item} ne $oldsetting->{$item}) ||
3423: ($newsettingtext->{$item} ne $oldsettingtext->{$item})) {
3424: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3425: $r->print("<td>$lt{$item}</td>\n");
3426: $r->print("<td>".$oldsetting->{$item});
3427: if ($oldsettingtext->{$item}) {
3428: if ($oldsetting->{$item}) {
3429: $r->print(' -- ');
3430: }
3431: $r->print($oldsettingtext->{$item});
3432: }
3433: $r->print("</td>\n");
3434: $r->print("<td>".$newsetting->{$item});
3435: if ($newsettingtext->{$item}) {
3436: if ($newsetting->{$item}) {
3437: $r->print(' -- ');
3438: }
3439: $r->print($newsettingtext->{$item});
3440: }
3441: $r->print("</td>\n");
3442: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.334 raeburn 3443: }
3444: }
3445: } elsif ($entry eq 'tools') {
3446: foreach my $item (@{$usertools}) {
1.383 raeburn 3447: if ($newsetting->{$item} ne $oldsetting->{$item}) {
3448: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3449: $r->print("<td>$lt{$item}</td>\n");
3450: $r->print("<td>".$oldsetting->{$item}.' '.$oldsettingtext->{$item}."</td>\n");
3451: $r->print("<td>".$newsetting->{$item}.' '.$newsettingtext->{$item}."</td>\n");
3452: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.334 raeburn 3453: }
3454: }
1.378 raeburn 3455: } elsif ($entry eq 'quota') {
3456: if ((ref($oldsetting->{$entry}) eq 'HASH') && (ref($oldsettingtext->{$entry}) eq 'HASH') &&
3457: (ref($newsetting->{$entry}) eq 'HASH') && (ref($newsettingtext->{$entry}) eq 'HASH')) {
3458: foreach my $name ('portfolio','author') {
1.383 raeburn 3459: if ($newsetting->{$entry}->{$name} ne $oldsetting->{$entry}->{$name}) {
3460: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3461: $r->print("<td>$lt{$name.$entry}</td>\n");
3462: $r->print("<td>".$oldsettingtext->{$entry}->{$name}."</td>\n");
3463: $r->print("<td>".$newsettingtext->{$entry}->{$name}."</td>\n");
3464: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.378 raeburn 3465: }
3466: }
3467: }
1.334 raeburn 3468: } else {
1.383 raeburn 3469: if ($newsetting->{$entry} ne $oldsetting->{$entry}) {
3470: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3471: $r->print("<td>$lt{$entry}</td>\n");
3472: $r->print("<td>".$oldsetting->{$entry}.' '.$oldsettingtext->{$entry}."</td>\n");
3473: $r->print("<td>".$newsetting->{$entry}.' '.$newsettingtext->{$entry}."</td>\n");
3474: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.334 raeburn 3475: }
3476: }
3477: }
3478: }
1.367 golterma 3479: $r->print(&Apache::loncommon::end_data_table().'<br />');
1.372 raeburn 3480: } else {
3481: $r->print('<h3>'.$lt{'ui'}.'</h3>'.
3482: '<p>'.&mt('No changes made to user information').'</p>');
1.334 raeburn 3483: }
3484: return;
3485: }
3486:
1.275 raeburn 3487: sub tool_changes {
3488: my ($context,$usertools,$oldaccess,$oldaccesstext,$userenv,$changeHash,
3489: $changed,$newaccess,$newaccesstext) = @_;
3490: if (!((ref($usertools) eq 'ARRAY') && (ref($oldaccess) eq 'HASH') &&
3491: (ref($oldaccesstext) eq 'HASH') && (ref($userenv) eq 'HASH') &&
3492: (ref($changeHash) eq 'HASH') && (ref($changed) eq 'HASH') &&
3493: (ref($newaccess) eq 'HASH') && (ref($newaccesstext) eq 'HASH'))) {
3494: return;
3495: }
1.383 raeburn 3496: my %reqdisplay = &requestchange_display();
1.300 raeburn 3497: if ($context eq 'reqcrsotherdom') {
1.309 raeburn 3498: my @options = ('approval','validate','autolimit');
1.306 raeburn 3499: my $optregex = join('|',@options);
1.300 raeburn 3500: my $cdom = $env{'request.role.domain'};
3501: foreach my $tool (@{$usertools}) {
1.383 raeburn 3502: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
1.314 raeburn 3503: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
1.300 raeburn 3504: $changeHash->{$context.'.'.$tool} = $userenv->{$context.'.'.$tool};
1.383 raeburn 3505: my ($newop,$limit);
1.314 raeburn 3506: if ($env{'form.'.$context.'_'.$tool}) {
3507: $newop = $env{'form.'.$context.'_'.$tool};
3508: if ($newop eq 'autolimit') {
1.383 raeburn 3509: $limit = $env{'form.'.$context.'_'.$tool.'_limit'};
1.314 raeburn 3510: $limit =~ s/\D+//g;
3511: $newop .= '='.$limit;
3512: }
3513: }
1.300 raeburn 3514: if ($userenv->{$context.'.'.$tool} eq '') {
1.314 raeburn 3515: if ($newop) {
3516: $changed->{$tool}=&tool_admin($tool,$cdom.':'.$newop,
1.300 raeburn 3517: $changeHash,$context);
3518: if ($changed->{$tool}) {
1.383 raeburn 3519: if ($newop =~ /^autolimit/) {
3520: if ($limit) {
3521: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3522: } else {
3523: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3524: }
3525: } else {
3526: $newaccesstext->{$tool} = $reqdisplay{$newop};
3527: }
1.300 raeburn 3528: } else {
3529: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
3530: }
3531: }
3532: } else {
3533: my @curr = split(',',$userenv->{$context.'.'.$tool});
3534: my @new;
3535: my $changedoms;
1.314 raeburn 3536: foreach my $req (@curr) {
3537: if ($req =~ /^\Q$cdom\E\:($optregex\=?\d*)$/) {
3538: my $oldop = $1;
1.383 raeburn 3539: if ($oldop =~ /^autolimit=(\d*)/) {
3540: my $limit = $1;
3541: if ($limit) {
3542: $oldaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3543: } else {
3544: $oldaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3545: }
3546: } else {
3547: $oldaccesstext->{$tool} = $reqdisplay{$oldop};
3548: }
1.314 raeburn 3549: if ($oldop ne $newop) {
3550: $changedoms = 1;
3551: foreach my $item (@curr) {
3552: my ($reqdom,$option) = split(':',$item);
3553: unless ($reqdom eq $cdom) {
3554: push(@new,$item);
3555: }
3556: }
3557: if ($newop) {
3558: push(@new,$cdom.':'.$newop);
1.300 raeburn 3559: }
1.314 raeburn 3560: @new = sort(@new);
1.300 raeburn 3561: }
1.314 raeburn 3562: last;
1.300 raeburn 3563: }
1.314 raeburn 3564: }
3565: if ((!$changedoms) && ($newop)) {
1.300 raeburn 3566: $changedoms = 1;
1.306 raeburn 3567: @new = sort(@curr,$cdom.':'.$newop);
1.300 raeburn 3568: }
3569: if ($changedoms) {
1.314 raeburn 3570: my $newdomstr;
1.300 raeburn 3571: if (@new) {
3572: $newdomstr = join(',',@new);
3573: }
3574: $changed->{$tool}=&tool_admin($tool,$newdomstr,$changeHash,
3575: $context);
3576: if ($changed->{$tool}) {
3577: if ($env{'form.'.$context.'_'.$tool}) {
1.306 raeburn 3578: if ($env{'form.'.$context.'_'.$tool} eq 'autolimit') {
1.314 raeburn 3579: my $limit = $env{'form.'.$context.'_'.$tool.'_limit'};
3580: $limit =~ s/\D+//g;
3581: if ($limit) {
1.383 raeburn 3582: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
1.314 raeburn 3583: } else {
1.383 raeburn 3584: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
1.306 raeburn 3585: }
1.314 raeburn 3586: } else {
1.306 raeburn 3587: $newaccesstext->{$tool} = $reqdisplay{$env{'form.'.$context.'_'.$tool}};
3588: }
1.300 raeburn 3589: } else {
1.383 raeburn 3590: $newaccesstext->{$tool} = &mt("availability set to 'off'");
1.300 raeburn 3591: }
3592: }
3593: }
3594: }
3595: }
3596: return;
3597: }
1.275 raeburn 3598: foreach my $tool (@{$usertools}) {
1.383 raeburn 3599: my ($newval,$limit,$envkey);
1.362 raeburn 3600: $envkey = $context.'.'.$tool;
1.306 raeburn 3601: if ($context eq 'requestcourses') {
3602: $newval = $env{'form.crsreq_'.$tool};
3603: if ($newval eq 'autolimit') {
1.383 raeburn 3604: $limit = $env{'form.crsreq_'.$tool.'_limit'};
3605: $limit =~ s/\D+//g;
3606: $newval .= '='.$limit;
1.306 raeburn 3607: }
1.362 raeburn 3608: } elsif ($context eq 'requestauthor') {
3609: $newval = $env{'form.'.$context};
3610: $envkey = $context;
1.314 raeburn 3611: } else {
1.306 raeburn 3612: $newval = $env{'form.'.$context.'_'.$tool};
3613: }
1.362 raeburn 3614: if ($userenv->{$envkey} ne '') {
1.275 raeburn 3615: $oldaccess->{$tool} = &mt('custom');
1.383 raeburn 3616: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3617: if ($userenv->{$envkey} =~ /^autolimit=(\d*)$/) {
3618: my $currlimit = $1;
3619: if ($currlimit eq '') {
3620: $oldaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3621: } else {
3622: $oldaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$currlimit);
3623: }
3624: } elsif ($userenv->{$envkey}) {
3625: $oldaccesstext->{$tool} = $reqdisplay{$userenv->{$envkey}};
3626: } else {
3627: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
3628: }
1.275 raeburn 3629: } else {
1.383 raeburn 3630: if ($userenv->{$envkey}) {
3631: $oldaccesstext->{$tool} = &mt("availability set to 'on'");
3632: } else {
3633: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
3634: }
1.275 raeburn 3635: }
1.362 raeburn 3636: $changeHash->{$envkey} = $userenv->{$envkey};
1.275 raeburn 3637: if ($env{'form.custom'.$tool} == 1) {
1.362 raeburn 3638: if ($newval ne $userenv->{$envkey}) {
1.306 raeburn 3639: $changed->{$tool} = &tool_admin($tool,$newval,$changeHash,
3640: $context);
1.275 raeburn 3641: if ($changed->{$tool}) {
3642: $newaccess->{$tool} = &mt('custom');
1.383 raeburn 3643: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3644: if ($newval =~ /^autolimit/) {
3645: if ($limit) {
3646: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3647: } else {
3648: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3649: }
3650: } elsif ($newval) {
3651: $newaccesstext->{$tool} = $reqdisplay{$newval};
3652: } else {
3653: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3654: }
1.275 raeburn 3655: } else {
1.383 raeburn 3656: if ($newval) {
3657: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3658: } else {
3659: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3660: }
1.275 raeburn 3661: }
3662: } else {
3663: $newaccess->{$tool} = $oldaccess->{$tool};
1.383 raeburn 3664: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3665: if ($newval =~ /^autolimit/) {
3666: if ($limit) {
3667: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3668: } else {
3669: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3670: }
3671: } elsif ($newval) {
3672: $newaccesstext->{$tool} = $reqdisplay{$newval};
3673: } else {
3674: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3675: }
1.275 raeburn 3676: } else {
1.383 raeburn 3677: if ($userenv->{$context.'.'.$tool}) {
3678: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3679: } else {
3680: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3681: }
1.275 raeburn 3682: }
3683: }
3684: } else {
3685: $newaccess->{$tool} = $oldaccess->{$tool};
3686: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
3687: }
3688: } else {
3689: $changed->{$tool} = &tool_admin($tool,'',$changeHash,$context);
3690: if ($changed->{$tool}) {
3691: $newaccess->{$tool} = &mt('default');
3692: } else {
3693: $newaccess->{$tool} = $oldaccess->{$tool};
1.383 raeburn 3694: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3695: if ($newval =~ /^autolimit/) {
3696: if ($limit) {
3697: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3698: } else {
3699: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3700: }
3701: } elsif ($newval) {
3702: $newaccesstext->{$tool} = $reqdisplay{$newval};
3703: } else {
3704: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3705: }
1.275 raeburn 3706: } else {
1.383 raeburn 3707: if ($userenv->{$context.'.'.$tool}) {
3708: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3709: } else {
3710: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3711: }
1.275 raeburn 3712: }
3713: }
3714: }
3715: } else {
3716: $oldaccess->{$tool} = &mt('default');
3717: if ($env{'form.custom'.$tool} == 1) {
1.306 raeburn 3718: $changed->{$tool} = &tool_admin($tool,$newval,$changeHash,
3719: $context);
1.275 raeburn 3720: if ($changed->{$tool}) {
3721: $newaccess->{$tool} = &mt('custom');
1.383 raeburn 3722: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3723: if ($newval =~ /^autolimit/) {
3724: if ($limit) {
3725: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3726: } else {
3727: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3728: }
3729: } elsif ($newval) {
3730: $newaccesstext->{$tool} = $reqdisplay{$newval};
3731: } else {
3732: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3733: }
1.275 raeburn 3734: } else {
1.383 raeburn 3735: if ($newval) {
3736: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3737: } else {
3738: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3739: }
1.275 raeburn 3740: }
3741: } else {
3742: $newaccess->{$tool} = $oldaccess->{$tool};
3743: }
3744: } else {
3745: $newaccess->{$tool} = $oldaccess->{$tool};
3746: }
3747: }
3748: }
3749: return;
3750: }
3751:
1.414 raeburn 3752: sub adhocrole_changes {
3753: my ($changehashref,$userenv) = @_;
3754: my @adds = &Apache::loncommon::get_env_multiple('form.adhocroleadd');
3755: my @dels = &Apache::loncommon::get_env_multiple('form.adhocroledel');
3756: my (@saved,@added,@alladhoc,$changed);
3757: my $adhoc_key = 'adhocroles.'.$env{'request.role.domain'};
3758: if (!$env{'form.makeuser'}) {
3759: if (ref($userenv) eq 'HASH') {
3760: my @current;
3761: if ($userenv->{$adhoc_key}) {
3762: @current = split(/,/,$userenv->{$adhoc_key});
3763: if (@dels) {
3764: foreach my $curr (@current) {
3765: next if ($curr eq '');
3766: unless (grep(/\Q$curr\E$/,@dels)) {
3767: push(@saved,$curr);
3768: }
3769: }
3770: $changed = 1;
3771: } else {
3772: @saved = @current;
3773: }
3774: }
3775: }
3776: }
3777: if (@adds) {
3778: my $confname = &Apache::lonnet::get_domainconfiguser($env{'request.role.domain'});
3779: my %existing=&Apache::lonnet::dump('roles',$env{'request.role.domain'},
3780: $confname,'rolesdef_');
3781: foreach my $poss (@adds) {
3782: if (exists($existing{'rolesdef_'.$poss})) {
3783: push(@added,$poss);
3784: $changed = 1;
3785: }
3786: }
3787: }
3788: if (@added) {
3789: if (@saved) {
3790: foreach my $add (@added) {
3791: unless (grep(/^\Q$add\E$/,@saved)) {
3792: push(@alladhoc,$add);
3793: }
3794: }
3795: } else {
3796: push(@alladhoc,@added);
3797: }
3798: }
3799: if (@saved) {
3800: push(@alladhoc,@saved);
3801: }
3802: if (@alladhoc) {
3803: my $adhocstr = join(',',sort(@alladhoc));
3804: $changehashref->{$adhoc_key} = $adhocstr;
3805: } elsif (@dels) {
3806: &Apache::lonnet::del('environment',[$adhoc_key],$env{'form.ccdomain'},$env{'form.ccuname'});
3807: delete($changehashref->{$adhoc_key});
3808: if (($env{'form.ccdomain'} eq $env{'user.domain'}) &&
3809: ($env{'form.ccuname'} eq $env{'user.name'})) {
3810: &Apache::lonnet::delenv($adhoc_key);
3811: }
3812: }
3813: return $changed;
3814: }
3815:
1.220 raeburn 3816: sub update_roles {
1.375 raeburn 3817: my ($r,$context,$showcredits) = @_;
1.4 www 3818: my $now=time;
1.225 raeburn 3819: my @rolechanges;
1.220 raeburn 3820: my %disallowed;
1.73 sakharuk 3821: $r->print('<h3>'.&mt('Modifying Roles').'</h3>');
1.404 raeburn 3822: foreach my $key (keys(%env)) {
1.135 raeburn 3823: next if (! $env{$key});
1.190 raeburn 3824: next if ($key eq 'form.action');
1.27 matthew 3825: # Revoke roles
1.135 raeburn 3826: if ($key=~/^form\.rev/) {
3827: if ($key=~/^form\.rev\:([^\_]+)\_([^\_\.]+)$/) {
1.64 www 3828: # Revoke standard role
1.170 albertel 3829: my ($scope,$role) = ($1,$2);
3830: my $result =
3831: &Apache::lonnet::revokerole($env{'form.ccdomain'},
3832: $env{'form.ccuname'},
1.239 raeburn 3833: $scope,$role,'','',$context);
1.367 golterma 3834: $r->print(&Apache::lonhtmlcommon::confirm_success(
1.369 bisitz 3835: &mt('Revoking [_1] in [_2]',
3836: &Apache::lonnet::plaintext($role),
1.372 raeburn 3837: &Apache::loncommon::show_role_extent($scope,$context,$role)),
1.369 bisitz 3838: $result ne "ok").'<br />');
3839: if ($result ne "ok") {
3840: $r->print(&mt('Error: [_1]',$result).'<br />');
3841: }
1.170 albertel 3842: if ($role eq 'st') {
1.202 raeburn 3843: my $result =
1.198 raeburn 3844: &Apache::lonuserutils::classlist_drop($scope,
3845: $env{'form.ccuname'},$env{'form.ccdomain'},
1.202 raeburn 3846: $now);
1.367 golterma 3847: $r->print(&Apache::lonhtmlcommon::confirm_success($result));
1.53 www 3848: }
1.225 raeburn 3849: if (!grep(/^\Q$role\E$/,@rolechanges)) {
3850: push(@rolechanges,$role);
3851: }
1.196 raeburn 3852: }
1.195 raeburn 3853: if ($key=~m{^form\.rev\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}s) {
1.64 www 3854: # Revoke custom role
1.369 bisitz 3855: my $result = &Apache::lonnet::revokecustomrole(
3856: $env{'form.ccdomain'},$env{'form.ccuname'},$1,$2,$3,$4,'','',$context);
1.367 golterma 3857: $r->print(&Apache::lonhtmlcommon::confirm_success(
1.369 bisitz 3858: &mt('Revoking custom role [_1] by [_2] in [_3]',
1.372 raeburn 3859: $4,$3.':'.$2,&Apache::loncommon::show_role_extent($1,$context,'cr')),
1.369 bisitz 3860: $result ne 'ok').'<br />');
3861: if ($result ne "ok") {
3862: $r->print(&mt('Error: [_1]',$result).'<br />');
3863: }
1.225 raeburn 3864: if (!grep(/^cr$/,@rolechanges)) {
3865: push(@rolechanges,'cr');
3866: }
1.64 www 3867: }
1.135 raeburn 3868: } elsif ($key=~/^form\.del/) {
3869: if ($key=~/^form\.del\:([^\_]+)\_([^\_\.]+)$/) {
1.116 raeburn 3870: # Delete standard role
1.170 albertel 3871: my ($scope,$role) = ($1,$2);
3872: my $result =
3873: &Apache::lonnet::assignrole($env{'form.ccdomain'},
3874: $env{'form.ccuname'},
1.239 raeburn 3875: $scope,$role,$now,0,1,'',
3876: $context);
1.367 golterma 3877: $r->print(&Apache::lonhtmlcommon::confirm_success(
3878: &mt('Deleting [_1] in [_2]',
1.369 bisitz 3879: &Apache::lonnet::plaintext($role),
1.372 raeburn 3880: &Apache::loncommon::show_role_extent($scope,$context,$role)),
1.369 bisitz 3881: $result ne 'ok').'<br />');
3882: if ($result ne "ok") {
3883: $r->print(&mt('Error: [_1]',$result).'<br />');
3884: }
1.367 golterma 3885:
1.170 albertel 3886: if ($role eq 'st') {
1.202 raeburn 3887: my $result =
1.198 raeburn 3888: &Apache::lonuserutils::classlist_drop($scope,
3889: $env{'form.ccuname'},$env{'form.ccdomain'},
1.202 raeburn 3890: $now);
1.369 bisitz 3891: $r->print(&Apache::lonhtmlcommon::confirm_success($result));
1.81 albertel 3892: }
1.225 raeburn 3893: if (!grep(/^\Q$role\E$/,@rolechanges)) {
3894: push(@rolechanges,$role);
3895: }
1.116 raeburn 3896: }
1.139 albertel 3897: if ($key=~m{^form\.del\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
1.116 raeburn 3898: my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
3899: # Delete custom role
1.369 bisitz 3900: my $result =
3901: &Apache::lonnet::assigncustomrole($env{'form.ccdomain'},
3902: $env{'form.ccuname'},$url,$rdom,$rnam,$rolename,$now,
3903: 0,1,$context);
3904: $r->print(&Apache::lonhtmlcommon::confirm_success(&mt('Deleting custom role [_1] by [_2] in [_3]',
1.372 raeburn 3905: $rolename,$rnam.':'.$rdom,&Apache::loncommon::show_role_extent($1,$context,'cr')),
1.369 bisitz 3906: $result ne "ok").'<br />');
3907: if ($result ne "ok") {
3908: $r->print(&mt('Error: [_1]',$result).'<br />');
3909: }
1.367 golterma 3910:
1.225 raeburn 3911: if (!grep(/^cr$/,@rolechanges)) {
3912: push(@rolechanges,'cr');
3913: }
1.116 raeburn 3914: }
1.135 raeburn 3915: } elsif ($key=~/^form\.ren/) {
1.101 albertel 3916: my $udom = $env{'form.ccdomain'};
3917: my $uname = $env{'form.ccuname'};
1.116 raeburn 3918: # Re-enable standard role
1.135 raeburn 3919: if ($key=~/^form\.ren\:([^\_]+)\_([^\_\.]+)$/) {
1.89 raeburn 3920: my $url = $1;
3921: my $role = $2;
3922: my $logmsg;
3923: my $output;
3924: if ($role eq 'st') {
1.141 albertel 3925: if ($url =~ m-^/($match_domain)/($match_courseid)/?(\w*)$-) {
1.374 raeburn 3926: my ($cdom,$cnum,$csec) = ($1,$2,$3);
1.375 raeburn 3927: my $credits;
3928: if ($showcredits) {
3929: my $defaultcredits =
3930: &Apache::lonuserutils::get_defaultcredits($cdom,$cnum);
3931: $credits = &get_user_credits($defaultcredits,$cdom,$cnum);
3932: }
3933: my $result = &Apache::loncommon::commit_studentrole(\$logmsg,$udom,$uname,$url,$role,$now,0,$cdom,$cnum,$csec,$context,$credits);
1.220 raeburn 3934: if (($result =~ /^error/) || ($result eq 'not_in_class') || ($result eq 'unknown_course') || ($result eq 'refused')) {
1.223 raeburn 3935: if ($result eq 'refused' && $logmsg) {
3936: $output = $logmsg;
3937: } else {
1.369 bisitz 3938: $output = &mt('Error: [_1]',$result)."\n";
1.223 raeburn 3939: }
1.89 raeburn 3940: } else {
1.372 raeburn 3941: $output = &Apache::lonhtmlcommon::confirm_success(&mt('Assigning [_1] in [_2] starting [_3]',
3942: &Apache::lonnet::plaintext($role),
3943: &Apache::loncommon::show_role_extent($url,$context,'st'),
3944: &Apache::lonlocal::locallocaltime($now))).'<br />'.$logmsg.'<br />';
1.89 raeburn 3945: }
3946: }
3947: } else {
1.101 albertel 3948: my $result=&Apache::lonnet::assignrole($env{'form.ccdomain'},
1.239 raeburn 3949: $env{'form.ccuname'},$url,$role,0,$now,'','',
3950: $context);
1.367 golterma 3951: $output = &Apache::lonhtmlcommon::confirm_success(&mt('Re-enabling [_1] in [_2]',
1.372 raeburn 3952: &Apache::lonnet::plaintext($role),
3953: &Apache::loncommon::show_role_extent($url,$context,$role)),$result ne "ok").'<br />';
1.369 bisitz 3954: if ($result ne "ok") {
3955: $output .= &mt('Error: [_1]',$result).'<br />';
3956: }
3957: }
1.89 raeburn 3958: $r->print($output);
1.225 raeburn 3959: if (!grep(/^\Q$role\E$/,@rolechanges)) {
3960: push(@rolechanges,$role);
3961: }
1.113 raeburn 3962: }
1.116 raeburn 3963: # Re-enable custom role
1.139 albertel 3964: if ($key=~m{^form\.ren\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
1.116 raeburn 3965: my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
3966: my $result = &Apache::lonnet::assigncustomrole(
3967: $env{'form.ccdomain'}, $env{'form.ccuname'},
1.240 raeburn 3968: $url,$rdom,$rnam,$rolename,0,$now,undef,$context);
1.369 bisitz 3969: $r->print(&Apache::lonhtmlcommon::confirm_success(
3970: &mt('Re-enabling custom role [_1] by [_2] in [_3]',
1.372 raeburn 3971: $rolename,$rnam.':'.$rdom,&Apache::loncommon::show_role_extent($1,$context,'cr')),
1.369 bisitz 3972: $result ne "ok").'<br />');
3973: if ($result ne "ok") {
3974: $r->print(&mt('Error: [_1]',$result).'<br />');
3975: }
1.225 raeburn 3976: if (!grep(/^cr$/,@rolechanges)) {
3977: push(@rolechanges,'cr');
3978: }
1.116 raeburn 3979: }
1.135 raeburn 3980: } elsif ($key=~/^form\.act/) {
1.101 albertel 3981: my $udom = $env{'form.ccdomain'};
3982: my $uname = $env{'form.ccuname'};
1.141 albertel 3983: if ($key=~/^form\.act\_($match_domain)\_($match_courseid)\_cr_cr_($match_domain)_($match_username)_([^\_]+)$/) {
1.65 www 3984: # Activate a custom role
1.83 albertel 3985: my ($one,$two,$three,$four,$five)=($1,$2,$3,$4,$5);
3986: my $url='/'.$one.'/'.$two;
3987: my $full=$one.'_'.$two.'_cr_cr_'.$three.'_'.$four.'_'.$five;
1.65 www 3988:
1.101 albertel 3989: my $start = ( $env{'form.start_'.$full} ?
3990: $env{'form.start_'.$full} :
1.88 raeburn 3991: $now );
1.101 albertel 3992: my $end = ( $env{'form.end_'.$full} ?
3993: $env{'form.end_'.$full} :
1.88 raeburn 3994: 0 );
3995:
3996: # split multiple sections
3997: my %sections = ();
1.101 albertel 3998: my $num_sections = &build_roles($env{'form.sec_'.$full},\%sections,$5);
1.88 raeburn 3999: if ($num_sections == 0) {
1.240 raeburn 4000: $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$url,$three,$four,$five,$start,$end,$context));
1.88 raeburn 4001: } else {
1.114 albertel 4002: my %curr_groups =
1.117 raeburn 4003: &Apache::longroup::coursegroups($one,$two);
1.404 raeburn 4004: foreach my $sec (sort {$a cmp $b} keys(%sections)) {
1.113 raeburn 4005: if (($sec eq 'none') || ($sec eq 'all') ||
4006: exists($curr_groups{$sec})) {
4007: $disallowed{$sec} = $url;
4008: next;
4009: }
4010: my $securl = $url.'/'.$sec;
1.240 raeburn 4011: $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$securl,$three,$four,$five,$start,$end,$context));
1.88 raeburn 4012: }
4013: }
1.225 raeburn 4014: if (!grep(/^cr$/,@rolechanges)) {
4015: push(@rolechanges,'cr');
4016: }
1.142 raeburn 4017: } elsif ($key=~/^form\.act\_($match_domain)\_($match_name)\_([^\_]+)$/) {
1.27 matthew 4018: # Activate roles for sections with 3 id numbers
4019: # set start, end times, and the url for the class
1.83 albertel 4020: my ($one,$two,$three)=($1,$2,$3);
1.101 albertel 4021: my $start = ( $env{'form.start_'.$one.'_'.$two.'_'.$three} ?
4022: $env{'form.start_'.$one.'_'.$two.'_'.$three} :
1.27 matthew 4023: $now );
1.101 albertel 4024: my $end = ( $env{'form.end_'.$one.'_'.$two.'_'.$three} ?
4025: $env{'form.end_'.$one.'_'.$two.'_'.$three} :
1.27 matthew 4026: 0 );
1.83 albertel 4027: my $url='/'.$one.'/'.$two;
1.88 raeburn 4028: my $type = 'three';
4029: # split multiple sections
4030: my %sections = ();
1.101 albertel 4031: my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two.'_'.$three},\%sections,$three);
1.375 raeburn 4032: my $credits;
4033: if ($three eq 'st') {
4034: if ($showcredits) {
4035: my $defaultcredits =
4036: &Apache::lonuserutils::get_defaultcredits($one,$two);
4037: $credits = $env{'form.credits_'.$one.'_'.$two.'_'.$three};
4038: $credits =~ s/[^\d\.]//g;
4039: if ($credits eq $defaultcredits) {
4040: undef($credits);
4041: }
4042: }
4043: }
1.88 raeburn 4044: if ($num_sections == 0) {
1.375 raeburn 4045: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'',$context,$credits));
1.88 raeburn 4046: } else {
1.114 albertel 4047: my %curr_groups =
1.117 raeburn 4048: &Apache::longroup::coursegroups($one,$two);
1.88 raeburn 4049: my $emptysec = 0;
1.404 raeburn 4050: foreach my $sec (sort {$a cmp $b} keys(%sections)) {
1.88 raeburn 4051: $sec =~ s/\W//g;
1.113 raeburn 4052: if ($sec ne '') {
4053: if (($sec eq 'none') || ($sec eq 'all') ||
4054: exists($curr_groups{$sec})) {
4055: $disallowed{$sec} = $url;
4056: next;
4057: }
1.88 raeburn 4058: my $securl = $url.'/'.$sec;
1.375 raeburn 4059: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$three,$start,$end,$one,$two,$sec,$context,$credits));
1.88 raeburn 4060: } else {
4061: $emptysec = 1;
4062: }
4063: }
4064: if ($emptysec) {
1.375 raeburn 4065: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'',$context,$credits));
1.88 raeburn 4066: }
1.225 raeburn 4067: }
4068: if (!grep(/^\Q$three\E$/,@rolechanges)) {
4069: push(@rolechanges,$three);
4070: }
1.135 raeburn 4071: } elsif ($key=~/^form\.act\_([^\_]+)\_([^\_]+)$/) {
1.27 matthew 4072: # Activate roles for sections with two id numbers
4073: # set start, end times, and the url for the class
1.101 albertel 4074: my $start = ( $env{'form.start_'.$1.'_'.$2} ?
4075: $env{'form.start_'.$1.'_'.$2} :
1.27 matthew 4076: $now );
1.101 albertel 4077: my $end = ( $env{'form.end_'.$1.'_'.$2} ?
4078: $env{'form.end_'.$1.'_'.$2} :
1.27 matthew 4079: 0 );
1.225 raeburn 4080: my $one = $1;
4081: my $two = $2;
4082: my $url='/'.$one.'/';
1.88 raeburn 4083: # split multiple sections
4084: my %sections = ();
1.225 raeburn 4085: my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two},\%sections,$two);
1.88 raeburn 4086: if ($num_sections == 0) {
1.240 raeburn 4087: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,'',$context));
1.88 raeburn 4088: } else {
4089: my $emptysec = 0;
1.404 raeburn 4090: foreach my $sec (sort {$a cmp $b} keys(%sections)) {
1.88 raeburn 4091: if ($sec ne '') {
4092: my $securl = $url.'/'.$sec;
1.240 raeburn 4093: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$two,$start,$end,$one,undef,$sec,$context));
1.88 raeburn 4094: } else {
4095: $emptysec = 1;
4096: }
4097: }
4098: if ($emptysec) {
1.240 raeburn 4099: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,'',$context));
1.88 raeburn 4100: }
4101: }
1.225 raeburn 4102: if (!grep(/^\Q$two\E$/,@rolechanges)) {
4103: push(@rolechanges,$two);
4104: }
1.64 www 4105: } else {
1.190 raeburn 4106: $r->print('<p><span class="LC_error">'.&mt('ERROR').': '.&mt('Unknown command').' <tt>'.$key.'</tt></span></p><br />');
1.64 www 4107: }
1.113 raeburn 4108: foreach my $key (sort(keys(%disallowed))) {
1.274 bisitz 4109: $r->print('<p class="LC_warning">');
1.113 raeburn 4110: if (($key eq 'none') || ($key eq 'all')) {
1.274 bisitz 4111: $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 4112: } else {
1.274 bisitz 4113: $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 4114: }
1.274 bisitz 4115: $r->print('</p><p>'
4116: .&mt('Please [_1]go back[_2] and choose a different section name.'
4117: ,'<a href="javascript:history.go(-1)'
4118: ,'</a>')
4119: .'</p><br />'
4120: );
1.113 raeburn 4121: }
4122: }
1.101 albertel 4123: } # End of foreach (keys(%env))
1.75 www 4124: # Flush the course logs so reverse user roles immediately updated
1.349 raeburn 4125: $r->register_cleanup(\&Apache::lonnet::flushcourselogs);
1.225 raeburn 4126: if (@rolechanges == 0) {
1.372 raeburn 4127: $r->print('<p>'.&mt('No roles to modify').'</p>');
1.193 raeburn 4128: }
1.225 raeburn 4129: return @rolechanges;
1.220 raeburn 4130: }
4131:
1.375 raeburn 4132: sub get_user_credits {
4133: my ($uname,$udom,$defaultcredits,$cdom,$cnum) = @_;
4134: if ($cdom eq '' || $cnum eq '') {
4135: return unless ($env{'request.course.id'});
4136: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
4137: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
4138: }
4139: my $credits;
4140: my %currhash =
4141: &Apache::lonnet::get('classlist',[$uname.':'.$udom],$cdom,$cnum);
4142: if (keys(%currhash) > 0) {
4143: my @items = split(/:/,$currhash{$uname.':'.$udom});
4144: my $crdidx = &Apache::loncoursedata::CL_CREDITS() - 3;
4145: $credits = $items[$crdidx];
4146: $credits =~ s/[^\d\.]//g;
4147: }
4148: if ($credits eq $defaultcredits) {
4149: undef($credits);
4150: }
4151: return $credits;
4152: }
4153:
1.220 raeburn 4154: sub enroll_single_student {
1.375 raeburn 4155: my ($r,$uhome,$amode,$genpwd,$now,$newuser,$context,$crstype,
4156: $showcredits,$defaultcredits) = @_;
1.318 raeburn 4157: $r->print('<h3>');
4158: if ($crstype eq 'Community') {
4159: $r->print(&mt('Enrolling Member'));
4160: } else {
4161: $r->print(&mt('Enrolling Student'));
4162: }
4163: $r->print('</h3>');
1.220 raeburn 4164:
4165: # Remove non alphanumeric values from section
4166: $env{'form.sections'}=~s/\W//g;
4167:
1.375 raeburn 4168: my $credits;
4169: if (($showcredits) && ($env{'form.credits'} ne '')) {
4170: $credits = $env{'form.credits'};
4171: $credits =~ s/[^\d\.]//g;
4172: if ($credits ne '') {
4173: if ($credits eq $defaultcredits) {
4174: undef($credits);
4175: }
4176: }
4177: }
4178:
1.220 raeburn 4179: # Clean out any old student roles the user has in this class.
4180: &Apache::lonuserutils::modifystudent($env{'form.ccdomain'},
4181: $env{'form.ccuname'},$env{'request.course.id'},undef,$uhome);
4182: my ($startdate,$enddate) = &Apache::lonuserutils::get_dates_from_form();
4183: my $enroll_result =
4184: &Apache::lonnet::modify_student_enrollment($env{'form.ccdomain'},
4185: $env{'form.ccuname'},$env{'form.cid'},$env{'form.cfirstname'},
4186: $env{'form.cmiddlename'},$env{'form.clastname'},
4187: $env{'form.generation'},$env{'form.sections'},$enddate,
1.375 raeburn 4188: $startdate,'manual',undef,$env{'request.course.id'},'',$context,
4189: $credits);
1.220 raeburn 4190: if ($enroll_result =~ /^ok/) {
1.381 bisitz 4191: $r->print(&mt('[_1] enrolled','<b>'.$env{'form.ccuname'}.':'.$env{'form.ccdomain'}.'</b>'));
1.220 raeburn 4192: if ($env{'form.sections'} ne '') {
4193: $r->print(' '.&mt('in section [_1]',$env{'form.sections'}));
4194: }
4195: my ($showstart,$showend);
4196: if ($startdate <= $now) {
4197: $showstart = &mt('Access starts immediately');
4198: } else {
4199: $showstart = &mt('Access starts: ').&Apache::lonlocal::locallocaltime($startdate);
4200: }
4201: if ($enddate == 0) {
4202: $showend = &mt('ends: no ending date');
4203: } else {
4204: $showend = &mt('ends: ').&Apache::lonlocal::locallocaltime($enddate);
4205: }
4206: $r->print('.<br />'.$showstart.'; '.$showend);
4207: if ($startdate <= $now && !$newuser) {
1.386 bisitz 4208: $r->print('<p class="LC_info">');
1.318 raeburn 4209: if ($crstype eq 'Community') {
1.392 raeburn 4210: $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 4211: } else {
1.392 raeburn 4212: $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 4213: }
4214: $r->print('</p>');
1.220 raeburn 4215: }
4216: } else {
4217: $r->print(&mt('unable to enroll').": ".$enroll_result);
4218: }
4219: return;
1.188 raeburn 4220: }
4221:
1.204 raeburn 4222: sub get_defaultquota_text {
4223: my ($settingstatus) = @_;
4224: my $defquotatext;
4225: if ($settingstatus eq '') {
1.383 raeburn 4226: $defquotatext = &mt('default');
1.204 raeburn 4227: } else {
4228: my ($usertypes,$order) =
4229: &Apache::lonnet::retrieve_inst_usertypes($env{'form.ccdomain'});
4230: if ($usertypes->{$settingstatus} eq '') {
1.383 raeburn 4231: $defquotatext = &mt('default');
1.204 raeburn 4232: } else {
1.383 raeburn 4233: $defquotatext = &mt('default for [_1]',$usertypes->{$settingstatus});
1.204 raeburn 4234: }
4235: }
4236: return $defquotatext;
4237: }
4238:
1.188 raeburn 4239: sub update_result_form {
4240: my ($uhome) = @_;
4241: my $outcome =
1.367 golterma 4242: '<form name="userupdate" method="post" action="">'."\n";
1.160 raeburn 4243: foreach my $item ('srchby','srchin','srchtype','srchterm','srchdomain','ccuname','ccdomain') {
1.188 raeburn 4244: $outcome .= '<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n";
1.160 raeburn 4245: }
1.207 raeburn 4246: if ($env{'form.origname'} ne '') {
4247: $outcome .= '<input type="hidden" name="origname" value="'.$env{'form.origname'}.'" />'."\n";
4248: }
1.160 raeburn 4249: foreach my $item ('sortby','seluname','seludom') {
4250: if (exists($env{'form.'.$item})) {
1.188 raeburn 4251: $outcome .= '<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n";
1.160 raeburn 4252: }
4253: }
1.188 raeburn 4254: if ($uhome eq 'no_host') {
4255: $outcome .= '<input type="hidden" name="forcenewuser" value="1" />'."\n";
4256: }
4257: $outcome .= '<input type="hidden" name="phase" value="" />'."\n".
1.383 raeburn 4258: '<input type="hidden" name="currstate" value="" />'."\n".
4259: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n".
1.188 raeburn 4260: '</form>';
4261: return $outcome;
1.4 www 4262: }
4263:
1.149 raeburn 4264: sub quota_admin {
1.378 raeburn 4265: my ($setquota,$changeHash,$name) = @_;
1.149 raeburn 4266: my $quotachanged;
4267: if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
4268: # Current user has quota modification privileges
1.267 raeburn 4269: if (ref($changeHash) eq 'HASH') {
4270: $quotachanged = 1;
1.378 raeburn 4271: $changeHash->{$name.'quota'} = $setquota;
1.267 raeburn 4272: }
1.149 raeburn 4273: }
4274: return $quotachanged;
4275: }
4276:
1.267 raeburn 4277: sub tool_admin {
1.275 raeburn 4278: my ($tool,$settool,$changeHash,$context) = @_;
4279: my $canchange = 0;
1.279 raeburn 4280: if ($context eq 'requestcourses') {
1.275 raeburn 4281: if (&Apache::lonnet::allowed('ccc',$env{'form.ccdomain'})) {
4282: $canchange = 1;
4283: }
1.300 raeburn 4284: } elsif ($context eq 'reqcrsotherdom') {
4285: if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
4286: $canchange = 1;
4287: }
1.362 raeburn 4288: } elsif ($context eq 'requestauthor') {
4289: if (&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) {
4290: $canchange = 1;
4291: }
1.275 raeburn 4292: } elsif (&Apache::lonnet::allowed('mut',$env{'form.ccdomain'})) {
4293: # Current user has quota modification privileges
4294: $canchange = 1;
4295: }
1.267 raeburn 4296: my $toolchanged;
1.275 raeburn 4297: if ($canchange) {
1.267 raeburn 4298: if (ref($changeHash) eq 'HASH') {
4299: $toolchanged = 1;
1.362 raeburn 4300: if ($tool eq 'requestauthor') {
4301: $changeHash->{$context} = $settool;
4302: } else {
4303: $changeHash->{$context.'.'.$tool} = $settool;
4304: }
1.267 raeburn 4305: }
4306: }
4307: return $toolchanged;
4308: }
4309:
1.88 raeburn 4310: sub build_roles {
1.89 raeburn 4311: my ($sectionstr,$sections,$role) = @_;
1.88 raeburn 4312: my $num_sections = 0;
4313: if ($sectionstr=~ /,/) {
4314: my @secnums = split/,/,$sectionstr;
1.89 raeburn 4315: if ($role eq 'st') {
4316: $secnums[0] =~ s/\W//g;
4317: $$sections{$secnums[0]} = 1;
4318: $num_sections = 1;
4319: } else {
4320: foreach my $sec (@secnums) {
4321: $sec =~ ~s/\W//g;
1.150 banghart 4322: if (!($sec eq "")) {
1.89 raeburn 4323: if (exists($$sections{$sec})) {
4324: $$sections{$sec} ++;
4325: } else {
4326: $$sections{$sec} = 1;
4327: $num_sections ++;
4328: }
1.88 raeburn 4329: }
4330: }
4331: }
4332: } else {
4333: $sectionstr=~s/\W//g;
4334: unless ($sectionstr eq '') {
4335: $$sections{$sectionstr} = 1;
4336: $num_sections ++;
4337: }
4338: }
1.129 albertel 4339:
1.88 raeburn 4340: return $num_sections;
4341: }
4342:
1.58 www 4343: # ========================================================== Custom Role Editor
4344:
4345: sub custom_role_editor {
1.414 raeburn 4346: my ($r,$brcrum,$prefix) = @_;
1.324 raeburn 4347: my $action = $env{'form.customroleaction'};
4348: my $rolename;
4349: if ($action eq 'new') {
4350: $rolename=$env{'form.newrolename'};
4351: } else {
4352: $rolename=$env{'form.rolename'};
1.59 www 4353: }
4354:
1.324 raeburn 4355: my ($crstype,$context);
4356: if ($env{'request.course.id'}) {
4357: $crstype = &Apache::loncommon::course_type();
4358: $context = 'course';
4359: } else {
4360: $context = 'domain';
1.414 raeburn 4361: $crstype = 'course';
1.324 raeburn 4362: }
1.351 raeburn 4363:
4364: $rolename=~s/[^A-Za-z0-9]//gs;
4365: if (!$rolename || $env{'form.phase'} eq 'pickrole') {
4366: &print_username_entry_form($r,undef,undef,undef,undef,$crstype,$brcrum);
4367: return;
4368: }
4369:
1.414 raeburn 4370: my $formname = 'form1';
4371: my %privs=();
4372: my $body_top = '<h2>';
4373: # ------------------------------------------------------- Does this role exist?
1.59 www 4374: my ($rdummy,$roledef)=
4375: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
4376: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1.414 raeburn 4377: $body_top .= &mt('Existing Role').' "';
1.61 www 4378: # ------------------------------------------------- Get current role privileges
1.414 raeburn 4379: ($privs{'system'},$privs{'domain'},$privs{'course'})=split(/\_/,$roledef);
4380: if ($privs{'system'} =~ /bre\&S/) {
4381: if ($context eq 'domain') {
4382: $crstype = 'Course';
4383: } elsif ($crstype eq 'Community') {
4384: $privs{'system'} =~ s/bre\&S//;
4385: }
4386: } elsif ($context eq 'domain') {
4387: $crstype = 'Course';
1.324 raeburn 4388: }
1.59 www 4389: } else {
1.414 raeburn 4390: $body_top .= &mt('New Role').' "';
4391: $roledef='';
1.59 www 4392: }
1.153 banghart 4393: $body_top .= $rolename.'"</h2>';
1.414 raeburn 4394:
4395: # ------------------------------------------------------- What can be assigned?
4396: my %full=();
4397: my %levels=(
4398: course => {},
4399: domain => {},
4400: system => {},
4401: );
4402: my %levelscurrent=(
4403: course => {},
4404: domain => {},
4405: system => {},
4406: );
4407: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
1.160 raeburn 4408: my ($jsback,$elements) = &crumb_utilities();
1.414 raeburn 4409: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
4410: my $head_script =
4411: &Apache::lonuserutils::custom_roledefs_js($context,$crstype,$formname,
4412: \%full,\@templateroles,$jsback);
1.351 raeburn 4413: push (@{$brcrum},
1.414 raeburn 4414: {href => "javascript:backPage(document.$formname,'pickrole','')",
1.351 raeburn 4415: text => "Pick custom role",
4416: faq => 282,bug=>'Instructor Interface',},
1.414 raeburn 4417: {href => "javascript:backPage(document.$formname,'','')",
1.351 raeburn 4418: text => "Edit custom role",
4419: faq => 282,
4420: bug => 'Instructor Interface',
4421: help => 'Course_Editing_Custom_Roles'}
4422: );
4423: my $args = { bread_crumbs => $brcrum,
4424: bread_crumbs_component => 'User Management'};
4425:
4426: $r->print(&Apache::loncommon::start_page('Custom Role Editor',
4427: $head_script,$args).
4428: $body_top);
1.414 raeburn 4429: $r->print('<form name="'.$formname.'" method="post" action="">'."\n".
4430: &Apache::lonuserutils::custom_role_header($context,$crstype,
4431: \@templateroles,$prefix));
1.264 bisitz 4432:
1.61 www 4433: $r->print(<<ENDCCF);
4434: <input type="hidden" name="phase" value="set_custom_roles" />
4435: <input type="hidden" name="rolename" value="$rolename" />
4436: ENDCCF
1.414 raeburn 4437: $r->print(&Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
4438: \%levelscurrent,$prefix));
1.135 raeburn 4439: $r->print(&Apache::loncommon::end_data_table().
1.190 raeburn 4440: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'.
1.160 raeburn 4441: '<input type="hidden" name="startrolename" value="'.$env{'form.rolename'}.
1.179 raeburn 4442: '" />'."\n".'<input type="hidden" name="currstate" value="" />'."\n".
1.160 raeburn 4443: '<input type="reset" value="'.&mt("Reset").'" />'."\n".
1.351 raeburn 4444: '<input type="submit" value="'.&mt('Save').'" /></form>');
1.61 www 4445: }
1.414 raeburn 4446:
1.61 www 4447: # ---------------------------------------------------------- Call to definerole
4448: sub set_custom_role {
1.414 raeburn 4449: my ($r,$context,$brcrum,$prefix) = @_;
1.101 albertel 4450: my $rolename=$env{'form.rolename'};
1.63 www 4451: $rolename=~s/[^A-Za-z0-9]//gs;
1.150 banghart 4452: if (!$rolename) {
1.414 raeburn 4453: &custom_role_editor($r,$brcrum,$prefix);
1.61 www 4454: return;
4455: }
1.160 raeburn 4456: my ($jsback,$elements) = &crumb_utilities();
1.301 bisitz 4457: my $jscript = '<script type="text/javascript">'
4458: .'// <![CDATA['."\n"
4459: .$jsback."\n"
4460: .'// ]]>'."\n"
4461: .'</script>'."\n";
1.352 raeburn 4462: push(@{$brcrum},
4463: {href => "javascript:backPage(document.customresult,'pickrole','')",
4464: text => "Pick custom role",
4465: faq => 282,
4466: bug => 'Instructor Interface',},
4467: {href => "javascript:backPage(document.customresult,'selected_custom_edit','')",
4468: text => "Edit custom role",
4469: faq => 282,
4470: bug => 'Instructor Interface',},
4471: {href => "javascript:backPage(document.customresult,'set_custom_roles','')",
4472: text => "Result",
4473: faq => 282,
4474: bug => 'Instructor Interface',
4475: help => 'Course_Editing_Custom_Roles'},
4476: );
4477: my $args = { bread_crumbs => $brcrum,
1.414 raeburn 4478: bread_crumbs_component => 'User Management'};
1.351 raeburn 4479: $r->print(&Apache::loncommon::start_page('Save Custom Role',$jscript,$args));
1.160 raeburn 4480:
1.393 raeburn 4481: my $newrole;
1.61 www 4482: my ($rdummy,$roledef)=
1.110 albertel 4483: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
4484:
1.61 www 4485: # ------------------------------------------------------- Does this role exist?
1.188 raeburn 4486: $r->print('<h3>');
1.61 www 4487: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1.73 sakharuk 4488: $r->print(&mt('Existing Role').' "');
1.61 www 4489: } else {
1.73 sakharuk 4490: $r->print(&mt('New Role').' "');
1.61 www 4491: $roledef='';
1.393 raeburn 4492: $newrole = 1;
1.61 www 4493: }
1.188 raeburn 4494: $r->print($rolename.'"</h3>');
1.414 raeburn 4495: # ------------------------------------------------- Assign role and show result
1.61 www 4496:
1.387 bisitz 4497: my $errmsg;
1.414 raeburn 4498: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$prefix);
4499: # Assign role and return result
4500: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
4501: $newprivs{'c'});
1.387 bisitz 4502: if ($result ne 'ok') {
4503: $errmsg = ': '.$result;
4504: }
4505: my $message =
4506: &Apache::lonhtmlcommon::confirm_success(
4507: &mt('Defining Role').$errmsg, ($result eq 'ok' ? 0 : 1));
1.101 albertel 4508: if ($env{'request.course.id'}) {
4509: my $url='/'.$env{'request.course.id'};
1.63 www 4510: $url=~s/\_/\//g;
1.387 bisitz 4511: $result =
4512: &Apache::lonnet::assigncustomrole(
4513: $env{'user.domain'},$env{'user.name'},
4514: $url,
4515: $env{'user.domain'},$env{'user.name'},
4516: $rolename,undef,undef,undef,$context);
4517: if ($result ne 'ok') {
4518: $errmsg = ': '.$result;
4519: }
4520: $message .=
4521: '<br />'
4522: .&Apache::lonhtmlcommon::confirm_success(
4523: &mt('Assigning Role to Self').$errmsg, ($result eq 'ok' ? 0 : 1));
1.63 www 4524: }
1.380 bisitz 4525: $r->print(
1.387 bisitz 4526: &Apache::loncommon::confirmwrapper($message)
4527: .'<br />'
4528: .&Apache::lonhtmlcommon::actionbox([
4529: '<a href="javascript:backPage(document.customresult,'."'pickrole'".')">'
4530: .&mt('Create or edit another custom role')
4531: .'</a>'])
1.380 bisitz 4532: .'<form name="customresult" method="post" action="">'
1.387 bisitz 4533: .&Apache::lonhtmlcommon::echo_form_input([])
4534: .'</form>'
1.380 bisitz 4535: );
1.58 www 4536: }
4537:
1.2 www 4538: # ================================================================ Main Handler
4539: sub handler {
4540: my $r = shift;
4541: if ($r->header_only) {
1.68 www 4542: &Apache::loncommon::content_type($r,'text/html');
1.2 www 4543: $r->send_http_header;
4544: return OK;
4545: }
1.318 raeburn 4546: my ($context,$crstype);
1.190 raeburn 4547: if ($env{'request.course.id'}) {
4548: $context = 'course';
1.318 raeburn 4549: $crstype = &Apache::loncommon::course_type();
1.190 raeburn 4550: } elsif ($env{'request.role'} =~ /^au\./) {
1.206 raeburn 4551: $context = 'author';
1.190 raeburn 4552: } else {
4553: $context = 'domain';
4554: }
1.375 raeburn 4555:
1.190 raeburn 4556: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.233 raeburn 4557: ['action','state','callingform','roletype','showrole','bulkaction','popup','phase',
1.391 raeburn 4558: 'username','domain','srchterm','srchdomain','srchin','srchby','srchtype','queue']);
1.190 raeburn 4559: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.351 raeburn 4560: my $args;
4561: my $brcrum = [];
4562: my $bread_crumbs_component = 'User Management';
1.391 raeburn 4563: if (($env{'form.action'} ne 'dateselect') && ($env{'form.action'} ne 'displayuserreq')) {
1.351 raeburn 4564: $brcrum = [{href=>"/adm/createuser",
4565: text=>"User Management",
4566: help=>'Course_Create_Class_List,Course_Change_Privileges,Course_View_Class_List,Course_Editing_Custom_Roles,Course_Add_Student,Course_Drop_Student,Course_Automated_Enrollment,Course_Self_Enrollment,Course_Manage_Group'}
4567: ];
1.202 raeburn 4568: }
1.289 droeschl 4569: #SD Following files not added to help, because the corresponding .tex-files seem to
4570: #be missing: Course_Approve_Selfenroll,Course_User_Logs,
1.209 raeburn 4571: my ($permission,$allowed) =
1.318 raeburn 4572: &Apache::lonuserutils::get_permission($context,$crstype);
1.190 raeburn 4573: if (!$allowed) {
1.358 raeburn 4574: if ($context eq 'course') {
4575: $r->internal_redirect('/adm/viewclasslist');
4576: return OK;
4577: }
1.190 raeburn 4578: $env{'user.error.msg'}=
4579: "/adm/createuser:cst:0:0:Cannot create/modify user data ".
4580: "or view user status.";
4581: return HTTP_NOT_ACCEPTABLE;
4582: }
4583:
4584: &Apache::loncommon::content_type($r,'text/html');
4585: $r->send_http_header;
4586:
1.375 raeburn 4587: my $showcredits;
4588: if ((($context eq 'course') && ($crstype eq 'Course')) ||
4589: ($context eq 'domain')) {
4590: my %domdefaults =
4591: &Apache::lonnet::get_domain_defaults($env{'request.role.domain'});
4592: if ($domdefaults{'officialcredits'} || $domdefaults{'unofficialcredits'}) {
4593: $showcredits = 1;
4594: }
4595: }
4596:
1.190 raeburn 4597: # Main switch on form.action and form.state, as appropriate
4598: if (! exists($env{'form.action'})) {
1.351 raeburn 4599: $args = {bread_crumbs => $brcrum,
4600: bread_crumbs_component => $bread_crumbs_component};
4601: $r->print(&header(undef,$args));
1.318 raeburn 4602: $r->print(&print_main_menu($permission,$context,$crstype));
1.190 raeburn 4603: } elsif ($env{'form.action'} eq 'upload' && $permission->{'cusr'}) {
1.351 raeburn 4604: push(@{$brcrum},
4605: { href => '/adm/createuser?action=upload&state=',
4606: text => 'Upload Users List',
4607: help => 'Course_Create_Class_List',
4608: });
4609: $bread_crumbs_component = 'Upload Users List';
4610: $args = {bread_crumbs => $brcrum,
4611: bread_crumbs_component => $bread_crumbs_component};
4612: $r->print(&header(undef,$args));
1.190 raeburn 4613: $r->print('<form name="studentform" method="post" '.
4614: 'enctype="multipart/form-data" '.
4615: ' action="/adm/createuser">'."\n");
4616: if (! exists($env{'form.state'})) {
4617: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
4618: } elsif ($env{'form.state'} eq 'got_file') {
1.375 raeburn 4619: &Apache::lonuserutils::print_upload_manager_form($r,$context,$permission,
4620: $crstype,$showcredits);
1.190 raeburn 4621: } elsif ($env{'form.state'} eq 'enrolling') {
4622: if ($env{'form.datatoken'}) {
1.375 raeburn 4623: &Apache::lonuserutils::upfile_drop_add($r,$context,$permission,
4624: $showcredits);
1.190 raeburn 4625: }
4626: } else {
4627: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
4628: }
1.416 ! raeburn 4629: } elsif (((($env{'form.action'} eq 'singleuser') || ($env{'form.action'}
! 4630: eq 'singlestudent')) && ($permission->{'cusr'})) ||
! 4631: (($env{'form.action'} eq 'accesslogs') && ($permission->{'activity'}))) {
1.190 raeburn 4632: my $phase = $env{'form.phase'};
4633: my @search = ('srchterm','srchby','srchin','srchtype','srchdomain');
1.192 albertel 4634: &Apache::loncreateuser::restore_prev_selections();
4635: my $srch;
4636: foreach my $item (@search) {
4637: $srch->{$item} = $env{'form.'.$item};
4638: }
1.207 raeburn 4639: if (($phase eq 'get_user_info') || ($phase eq 'userpicked') ||
1.416 ! raeburn 4640: ($phase eq 'createnewuser') || ($phase eq 'activity')) {
1.207 raeburn 4641: if ($env{'form.phase'} eq 'createnewuser') {
4642: my $response;
4643: if ($env{'form.srchterm'} !~ /^$match_username$/) {
1.366 bisitz 4644: my $response =
4645: '<span class="LC_warning">'
4646: .&mt('You must specify a valid username. Only the following are allowed:'
4647: .' letters numbers - . @')
4648: .'</span>';
1.221 raeburn 4649: $env{'form.phase'} = '';
1.375 raeburn 4650: &print_username_entry_form($r,$context,$response,$srch,undef,
4651: $crstype,$brcrum,$showcredits);
1.207 raeburn 4652: } else {
4653: my $ccuname =&LONCAPA::clean_username($srch->{'srchterm'});
4654: my $ccdomain=&LONCAPA::clean_domain($srch->{'srchdomain'});
4655: &print_user_modification_page($r,$ccuname,$ccdomain,
1.221 raeburn 4656: $srch,$response,$context,
1.375 raeburn 4657: $permission,$crstype,$brcrum,
4658: $showcredits);
1.207 raeburn 4659: }
4660: } elsif ($env{'form.phase'} eq 'get_user_info') {
1.190 raeburn 4661: my ($currstate,$response,$forcenewuser,$results) =
1.221 raeburn 4662: &user_search_result($context,$srch);
1.190 raeburn 4663: if ($env{'form.currstate'} eq 'modify') {
4664: $currstate = $env{'form.currstate'};
4665: }
4666: if ($currstate eq 'select') {
4667: &print_user_selection_page($r,$response,$srch,$results,
1.351 raeburn 4668: \@search,$context,undef,$crstype,
4669: $brcrum);
1.416 ! raeburn 4670: } elsif (($currstate eq 'modify') || ($env{'form.action'} eq 'accesslogs')) {
! 4671: my ($ccuname,$ccdomain,$uhome);
1.190 raeburn 4672: if (($srch->{'srchby'} eq 'uname') &&
4673: ($srch->{'srchtype'} eq 'exact')) {
4674: $ccuname = $srch->{'srchterm'};
4675: $ccdomain= $srch->{'srchdomain'};
4676: } else {
4677: my @matchedunames = keys(%{$results});
4678: ($ccuname,$ccdomain) = split(/:/,$matchedunames[0]);
4679: }
4680: $ccuname =&LONCAPA::clean_username($ccuname);
4681: $ccdomain=&LONCAPA::clean_domain($ccdomain);
1.416 ! raeburn 4682: if ($env{'form.action'} eq 'accesslogs') {
! 4683: my $uhome;
! 4684: if (($ccuname ne '') && ($ccdomain ne '')) {
! 4685: $uhome = &Apache::lonnet::homeserver($ccuname,$ccdomain);
! 4686: }
! 4687: if (($uhome eq '') || ($uhome eq 'no_host')) {
! 4688: $env{'form.phase'} = '';
! 4689: undef($forcenewuser);
! 4690: #if ($response) {
! 4691: # unless ($response =~ m{\Q<br /><br />\E$}) {
! 4692: # $response .= '<br /><br />';
! 4693: # }
! 4694: #}
! 4695: &print_username_entry_form($r,$context,$response,$srch,
! 4696: $forcenewuser,$crstype,$brcrum);
! 4697: } else {
! 4698: &print_useraccesslogs_display($r,$ccuname,$ccdomain,$permission,$brcrum);
! 4699: }
! 4700: } else {
! 4701: if ($env{'form.forcenewuser'}) {
! 4702: $response = '';
! 4703: }
! 4704: &print_user_modification_page($r,$ccuname,$ccdomain,
! 4705: $srch,$response,$context,
! 4706: $permission,$crstype,$brcrum);
1.190 raeburn 4707: }
4708: } elsif ($currstate eq 'query') {
1.351 raeburn 4709: &print_user_query_page($r,'createuser',$brcrum);
1.190 raeburn 4710: } else {
1.229 raeburn 4711: $env{'form.phase'} = '';
1.207 raeburn 4712: &print_username_entry_form($r,$context,$response,$srch,
1.351 raeburn 4713: $forcenewuser,$crstype,$brcrum);
1.190 raeburn 4714: }
4715: } elsif ($env{'form.phase'} eq 'userpicked') {
4716: my $ccuname = &LONCAPA::clean_username($env{'form.seluname'});
4717: my $ccdomain = &LONCAPA::clean_domain($env{'form.seludom'});
1.416 ! raeburn 4718: if ($env{'form.action'} eq 'accesslogs') {
! 4719: &print_useraccesslogs_display($r,$ccuname,$ccdomain,$permission,$brcrum);
! 4720: } else {
! 4721: &print_user_modification_page($r,$ccuname,$ccdomain,$srch,'',
! 4722: $context,$permission,$crstype,
! 4723: $brcrum);
! 4724: }
! 4725: } elsif ($env{'form.action'} eq 'accesslogs') {
! 4726: my $ccuname = &LONCAPA::clean_username($env{'form.accessuname'});
! 4727: my $ccdomain = &LONCAPA::clean_domain($env{'form.accessudom'});
! 4728: &print_useraccesslogs_display($r,$ccuname,$ccdomain,$permission,$brcrum);
1.190 raeburn 4729: }
4730: } elsif ($env{'form.phase'} eq 'update_user_data') {
1.375 raeburn 4731: &update_user_data($r,$context,$crstype,$brcrum,$showcredits);
1.190 raeburn 4732: } else {
1.351 raeburn 4733: &print_username_entry_form($r,$context,undef,$srch,undef,$crstype,
4734: $brcrum);
1.190 raeburn 4735: }
4736: } elsif ($env{'form.action'} eq 'custom' && $permission->{'custom'}) {
1.414 raeburn 4737: my $prefix;
1.190 raeburn 4738: if ($env{'form.phase'} eq 'set_custom_roles') {
1.414 raeburn 4739: &set_custom_role($r,$context,$brcrum,$prefix);
1.190 raeburn 4740: } else {
1.414 raeburn 4741: &custom_role_editor($r,$brcrum,$prefix);
1.190 raeburn 4742: }
1.362 raeburn 4743: } elsif (($env{'form.action'} eq 'processauthorreq') &&
4744: ($permission->{'cusr'}) &&
4745: (&Apache::lonnet::allowed('cau',$env{'request.role.domain'}))) {
4746: push(@{$brcrum},
4747: {href => '/adm/createuser?action=processauthorreq',
1.385 bisitz 4748: text => 'Authoring Space requests',
1.362 raeburn 4749: help => 'Domain_Role_Approvals'});
4750: $bread_crumbs_component = 'Authoring requests';
4751: if ($env{'form.state'} eq 'done') {
4752: push(@{$brcrum},
4753: {href => '/adm/createuser?action=authorreqqueue',
4754: text => 'Result',
4755: help => 'Domain_Role_Approvals'});
4756: $bread_crumbs_component = 'Authoring request result';
4757: }
4758: $args = { bread_crumbs => $brcrum,
4759: bread_crumbs_component => $bread_crumbs_component};
1.391 raeburn 4760: my $js = &usernamerequest_javascript();
4761: $r->print(&header(&add_script($js),$args));
1.362 raeburn 4762: if (!exists($env{'form.state'})) {
4763: $r->print(&Apache::loncoursequeueadmin::display_queued_requests('requestauthor',
4764: $env{'request.role.domain'}));
4765: } elsif ($env{'form.state'} eq 'done') {
4766: $r->print('<h3>'.&mt('Authoring request processing').'</h3>'."\n");
4767: $r->print(&Apache::loncoursequeueadmin::update_request_queue('requestauthor',
4768: $env{'request.role.domain'}));
4769: }
1.391 raeburn 4770: } elsif (($env{'form.action'} eq 'processusernamereq') &&
4771: ($permission->{'cusr'}) &&
4772: (&Apache::lonnet::allowed('cau',$env{'request.role.domain'}))) {
4773: push(@{$brcrum},
4774: {href => '/adm/createuser?action=processusernamereq',
4775: text => 'LON-CAPA account requests',
4776: help => 'Domain_Username_Approvals'});
4777: $bread_crumbs_component = 'Account requests';
4778: if ($env{'form.state'} eq 'done') {
4779: push(@{$brcrum},
4780: {href => '/adm/createuser?action=usernamereqqueue',
4781: text => 'Result',
4782: help => 'Domain_Username_Approvals'});
4783: $bread_crumbs_component = 'LON-CAPA account request result';
4784: }
4785: $args = { bread_crumbs => $brcrum,
4786: bread_crumbs_component => $bread_crumbs_component};
4787: my $js = &usernamerequest_javascript();
4788: $r->print(&header(&add_script($js),$args));
4789: if (!exists($env{'form.state'})) {
4790: $r->print(&Apache::loncoursequeueadmin::display_queued_requests('requestusername',
4791: $env{'request.role.domain'}));
4792: } elsif ($env{'form.state'} eq 'done') {
4793: $r->print('<h3>'.&mt('LON-CAPA account request processing').'</h3>'."\n");
4794: $r->print(&Apache::loncoursequeueadmin::update_request_queue('requestusername',
4795: $env{'request.role.domain'}));
4796: }
4797: } elsif (($env{'form.action'} eq 'displayuserreq') &&
4798: ($permission->{'cusr'})) {
4799: my $dom = $env{'form.domain'};
4800: my $uname = $env{'form.username'};
4801: my $warning;
4802: if (($dom =~ /^$match_domain$/) && (&Apache::lonnet::domain($dom) ne '')) {
4803: if (($dom eq $env{'request.role.domain'}) && (&Apache::lonnet::allowed('ccc',$dom))) {
4804: if (($uname =~ /^$match_username$/) && ($env{'form.queue'} eq 'approval')) {
4805: my $uhome = &Apache::lonnet::homeserver($uname,$dom);
4806: if ($uhome eq 'no_host') {
4807: my $queue = $env{'form.queue'};
4808: my $reqkey = &escape($uname).'_'.$queue;
4809: my $namespace = 'usernamequeue';
4810: my $domconfig = &Apache::lonnet::get_domainconfiguser($dom);
4811: my %queued =
4812: &Apache::lonnet::get($namespace,[$reqkey],$dom,$domconfig);
4813: unless ($queued{$reqkey}) {
4814: $warning = &mt('No information was found for this LON-CAPA account request.');
4815: }
4816: } else {
4817: $warning = &mt('A LON-CAPA account already exists for the requested username and domain.');
4818: }
4819: } else {
4820: $warning = &mt('LON-CAPA account request status check is for an invalid username.');
4821: }
4822: } else {
4823: $warning = &mt('You do not have rights to view LON-CAPA account requests in the domain specified.');
4824: }
4825: } else {
4826: $warning = &mt('LON-CAPA account request status check is for an invalid domain.');
4827: }
4828: my $args = { only_body => 1 };
4829: $r->print(&header(undef,$args).
4830: '<h3>'.&mt('LON-CAPA Account Request Details').'</h3>');
4831: if ($warning ne '') {
4832: $r->print('<div class="LC_warning">'.$warning.'</div>');
4833: } else {
4834: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
4835: my $domconfiguser = &Apache::lonnet::get_domainconfiguser($dom);
4836: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
4837: if (ref($domconfig{'usercreation'}) eq 'HASH') {
4838: if (ref($domconfig{'usercreation'}{'cancreate'}) eq 'HASH') {
4839: if (ref($domconfig{'usercreation'}{'cancreate'}{'emailusername'}) eq 'HASH') {
4840: my %info =
4841: &Apache::lonnet::get('nohist_requestedusernames',[$uname],$dom,$domconfiguser);
4842: if (ref($info{$uname}) eq 'HASH') {
1.396 raeburn 4843: my $usertype = $info{$uname}{'inststatus'};
4844: unless ($usertype) {
4845: $usertype = 'default';
4846: }
4847: if (ref($domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}) eq 'HASH') {
4848: if ((ref($infofields) eq 'ARRAY') && (ref($infotitles) eq 'HASH')) {
4849: $r->print('<div>'.&Apache::lonhtmlcommon::start_pick_box());
4850: my ($num,$count,$showstatus);
4851: $count = scalar(keys(%{$domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}}));
4852: unless ($usertype eq 'default') {
4853: my ($othertitle,$usertypes,$types) =
4854: &Apache::loncommon::sorted_inst_types($dom);
4855: if (ref($usertypes) eq 'HASH') {
4856: if ($usertypes->{$usertype}) {
4857: $showstatus = $usertypes->{$usertype};
4858: $count ++;
4859: }
4860: }
4861: }
4862: foreach my $field (@{$infofields}) {
4863: next unless ($domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}{$field});
4864: next unless ($infotitles->{$field});
4865: $r->print(&Apache::lonhtmlcommon::row_title($infotitles->{$field}).
4866: $info{$uname}{$field});
4867: $num ++;
4868: if ($count == $num) {
4869: $r->print(&Apache::lonhtmlcommon::row_closure(1));
4870: } else {
4871: $r->print(&Apache::lonhtmlcommon::row_closure());
4872: }
4873: }
4874: if ($showstatus) {
4875: $r->print(&Apache::lonhtmlcommon::row_title(&mt('Status type (self-reported)')).
4876: $showstatus.
4877: &Apache::lonhtmlcommon::row_closure(1));
1.391 raeburn 4878: }
1.396 raeburn 4879: $r->print(&Apache::lonhtmlcommon::end_pick_box().'</div>');
1.391 raeburn 4880: }
4881: }
4882: }
4883: }
4884: }
4885: }
4886: $r->print(&close_popup_form());
4887: }
1.207 raeburn 4888: } elsif (($env{'form.action'} eq 'listusers') &&
4889: ($permission->{'view'} || $permission->{'cusr'})) {
1.202 raeburn 4890: if ($env{'form.phase'} eq 'bulkchange') {
1.351 raeburn 4891: push(@{$brcrum},
4892: {href => '/adm/createuser?action=listusers',
4893: text => "List Users"},
4894: {href => "/adm/createuser",
4895: text => "Result",
4896: help => 'Course_View_Class_List'});
4897: $bread_crumbs_component = 'Update Users';
4898: $args = {bread_crumbs => $brcrum,
4899: bread_crumbs_component => $bread_crumbs_component};
4900: $r->print(&header(undef,$args));
1.202 raeburn 4901: my $setting = $env{'form.roletype'};
4902: my $choice = $env{'form.bulkaction'};
4903: if ($permission->{'cusr'}) {
1.336 raeburn 4904: &Apache::lonuserutils::update_user_list($r,$context,$setting,$choice,$crstype);
1.221 raeburn 4905: } else {
4906: $r->print(&mt('You are not authorized to make bulk changes to user roles'));
1.223 raeburn 4907: $r->print('<p><a href="/adm/createuser?action=listusers">'.&mt('Display User Lists').'</a>');
1.202 raeburn 4908: }
4909: } else {
1.351 raeburn 4910: push(@{$brcrum},
4911: {href => '/adm/createuser?action=listusers',
4912: text => "List Users",
4913: help => 'Course_View_Class_List'});
4914: $bread_crumbs_component = 'List Users';
4915: $args = {bread_crumbs => $brcrum,
4916: bread_crumbs_component => $bread_crumbs_component};
1.202 raeburn 4917: my ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles);
4918: my $formname = 'studentform';
1.364 raeburn 4919: my $hidecall = "hide_searching();";
1.321 raeburn 4920: if (($context eq 'domain') && (($env{'form.roletype'} eq 'course') ||
4921: ($env{'form.roletype'} eq 'community'))) {
4922: if ($env{'form.roletype'} eq 'course') {
4923: ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles) =
4924: &Apache::lonuserutils::courses_selector($env{'request.role.domain'},
4925: $formname);
4926: } elsif ($env{'form.roletype'} eq 'community') {
4927: $cb_jscript =
4928: &Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
4929: my %elements = (
4930: coursepick => 'radio',
4931: coursetotal => 'text',
4932: courselist => 'text',
4933: );
4934: $jscript = &Apache::lonhtmlcommon::set_form_elements(\%elements);
4935: }
1.364 raeburn 4936: $jscript .= &verify_user_display($context)."\n".
4937: &Apache::loncommon::check_uncheck_jscript();
1.202 raeburn 4938: my $js = &add_script($jscript).$cb_jscript;
4939: my $loadcode =
4940: &Apache::lonuserutils::course_selector_loadcode($formname);
4941: if ($loadcode ne '') {
1.364 raeburn 4942: $args->{add_entries} = {onload => "$loadcode;$hidecall"};
4943: } else {
4944: $args->{add_entries} = {onload => $hidecall};
1.202 raeburn 4945: }
1.351 raeburn 4946: $r->print(&header($js,$args));
1.191 raeburn 4947: } else {
1.364 raeburn 4948: $args->{add_entries} = {onload => $hidecall};
4949: $jscript = &verify_user_display($context).
4950: &Apache::loncommon::check_uncheck_jscript();
4951: $r->print(&header(&add_script($jscript),$args));
1.191 raeburn 4952: }
1.202 raeburn 4953: &Apache::lonuserutils::print_userlist($r,undef,$permission,$context,
1.375 raeburn 4954: $formname,$totcodes,$codetitles,$idlist,$idlist_titles,
4955: $showcredits);
1.191 raeburn 4956: }
1.213 raeburn 4957: } elsif ($env{'form.action'} eq 'drop' && $permission->{'cusr'}) {
1.318 raeburn 4958: my $brtext;
4959: if ($crstype eq 'Community') {
4960: $brtext = 'Drop Members';
4961: } else {
4962: $brtext = 'Drop Students';
4963: }
1.351 raeburn 4964: push(@{$brcrum},
4965: {href => '/adm/createuser?action=drop',
4966: text => $brtext,
4967: help => 'Course_Drop_Student'});
4968: if ($env{'form.state'} eq 'done') {
4969: push(@{$brcrum},
4970: {href=>'/adm/createuser?action=drop',
4971: text=>"Result"});
4972: }
4973: $bread_crumbs_component = $brtext;
4974: $args = {bread_crumbs => $brcrum,
4975: bread_crumbs_component => $bread_crumbs_component};
4976: $r->print(&header(undef,$args));
1.213 raeburn 4977: if (!exists($env{'form.state'})) {
1.318 raeburn 4978: &Apache::lonuserutils::print_drop_menu($r,$context,$permission,$crstype);
1.213 raeburn 4979: } elsif ($env{'form.state'} eq 'done') {
4980: &Apache::lonuserutils::update_user_list($r,$context,undef,
4981: $env{'form.action'});
4982: }
1.202 raeburn 4983: } elsif ($env{'form.action'} eq 'dateselect') {
4984: if ($permission->{'cusr'}) {
1.351 raeburn 4985: $r->print(&header(undef,{'no_nav_bar' => 1}).
1.375 raeburn 4986: &Apache::lonuserutils::date_section_selector($context,$permission,
4987: $crstype,$showcredits));
1.202 raeburn 4988: } else {
1.351 raeburn 4989: $r->print(&header(undef,{'no_nav_bar' => 1}).
4990: '<span class="LC_error">'.&mt('You do not have permission to modify dates or sections for users').'</span>');
1.202 raeburn 4991: }
1.237 raeburn 4992: } elsif ($env{'form.action'} eq 'selfenroll') {
1.398 raeburn 4993: if ($permission->{selfenrolladmin}) {
4994: my $cid = $env{'request.course.id'};
4995: my $cdom = $env{'course.'.$cid.'.domain'};
4996: my $cnum = $env{'course.'.$cid.'.num'};
4997: my %currsettings = (
4998: selfenroll_types => $env{'course.'.$cid.'.internal.selfenroll_types'},
4999: selfenroll_registered => $env{'course.'.$cid.'.internal.selfenroll_registered'},
5000: selfenroll_section => $env{'course.'.$cid.'.internal.selfenroll_section'},
5001: selfenroll_notifylist => $env{'course.'.$cid.'.internal.selfenroll_notifylist'},
5002: selfenroll_approval => $env{'course.'.$cid.'.internal.selfenroll_approval'},
5003: selfenroll_limit => $env{'course.'.$cid.'.internal.selfenroll_limit'},
5004: selfenroll_cap => $env{'course.'.$cid.'.internal.selfenroll_cap'},
5005: selfenroll_start_date => $env{'course.'.$cid.'.internal.selfenroll_start_date'},
5006: selfenroll_end_date => $env{'course.'.$cid.'.internal.selfenroll_end_date'},
5007: selfenroll_start_access => $env{'course.'.$cid.'.internal.selfenroll_start_access'},
5008: selfenroll_end_access => $env{'course.'.$cid.'.internal.selfenroll_end_access'},
5009: default_enrollment_start_date => $env{'course.'.$cid.'.default_enrollment_start_date'},
5010: default_enrollment_end_date => $env{'course.'.$cid.'.default_enrollment_end_date'},
1.400 raeburn 5011: uniquecode => $env{'course.'.$cid.'.internal.uniquecode'},
1.398 raeburn 5012: );
5013: push(@{$brcrum},
5014: {href => '/adm/createuser?action=selfenroll',
5015: text => "Configure Self-enrollment",
5016: help => 'Course_Self_Enrollment'});
5017: if (!exists($env{'form.state'})) {
5018: $args = { bread_crumbs => $brcrum,
5019: bread_crumbs_component => 'Configure Self-enrollment'};
5020: $r->print(&header(undef,$args));
5021: $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n");
5022: &print_selfenroll_menu($r,'course',$cid,$cdom,$cnum,\%currsettings);
5023: } elsif ($env{'form.state'} eq 'done') {
5024: push (@{$brcrum},
5025: {href=>'/adm/createuser?action=selfenroll',
5026: text=>"Result"});
5027: $args = { bread_crumbs => $brcrum,
5028: bread_crumbs_component => 'Self-enrollment result'};
5029: $r->print(&header(undef,$args));
5030: $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n");
1.400 raeburn 5031: &update_selfenroll_config($r,$cid,$cdom,$cnum,$context,$crstype,\%currsettings);
1.398 raeburn 5032: }
5033: } else {
5034: $r->print(&header(undef,{'no_nav_bar' => 1}).
5035: '<span class="LC_error">'.&mt('You do not have permission to configure self-enrollment').'</span>');
1.237 raeburn 5036: }
1.277 raeburn 5037: } elsif ($env{'form.action'} eq 'selfenrollqueue') {
1.351 raeburn 5038: push(@{$brcrum},
5039: {href => '/adm/createuser?action=selfenrollqueue',
5040: text => 'Enrollment requests',
5041: help => 'Course_Self_Enrollment'});
5042: $bread_crumbs_component = 'Enrollment requests';
5043: if ($env{'form.state'} eq 'done') {
5044: push(@{$brcrum},
5045: {href => '/adm/createuser?action=selfenrollqueue',
5046: text => 'Result',
5047: help => 'Course_Self_Enrollment'});
5048: $bread_crumbs_component = 'Enrollment result';
5049: }
5050: $args = { bread_crumbs => $brcrum,
5051: bread_crumbs_component => $bread_crumbs_component};
5052: $r->print(&header(undef,$args));
1.277 raeburn 5053: my $cid = $env{'request.course.id'};
5054: my $cdom = $env{'course.'.$cid.'.domain'};
5055: my $cnum = $env{'course.'.$cid.'.num'};
1.307 raeburn 5056: my $coursedesc = $env{'course.'.$cid.'.description'};
1.277 raeburn 5057: if (!exists($env{'form.state'})) {
5058: $r->print('<h3>'.&mt('Pending enrollment requests').'</h3>'."\n");
1.307 raeburn 5059: $r->print(&Apache::loncoursequeueadmin::display_queued_requests($context,
5060: $cdom,$cnum));
1.277 raeburn 5061: } elsif ($env{'form.state'} eq 'done') {
5062: $r->print('<h3>'.&mt('Enrollment request processing').'</h3>'."\n");
1.307 raeburn 5063: $r->print(&Apache::loncoursequeueadmin::update_request_queue($context,
5064: $cdom,$cnum,$coursedesc));
1.277 raeburn 5065: }
1.239 raeburn 5066: } elsif ($env{'form.action'} eq 'changelogs') {
1.415 raeburn 5067: &print_userchangelogs_display($r,$context,$permission,$brcrum);
1.190 raeburn 5068: } else {
1.351 raeburn 5069: $bread_crumbs_component = 'User Management';
5070: $args = { bread_crumbs => $brcrum,
5071: bread_crumbs_component => $bread_crumbs_component};
5072: $r->print(&header(undef,$args));
1.318 raeburn 5073: $r->print(&print_main_menu($permission,$context,$crstype));
1.190 raeburn 5074: }
1.351 raeburn 5075: $r->print(&Apache::loncommon::end_page());
1.190 raeburn 5076: return OK;
5077: }
5078:
5079: sub header {
1.351 raeburn 5080: my ($jscript,$args) = @_;
1.190 raeburn 5081: my $start_page;
1.351 raeburn 5082: if (ref($args) eq 'HASH') {
5083: $start_page=&Apache::loncommon::start_page('User Management',$jscript,$args);
1.190 raeburn 5084: } else {
1.351 raeburn 5085: $start_page=&Apache::loncommon::start_page('User Management',$jscript);
1.190 raeburn 5086: }
5087: return $start_page;
5088: }
1.2 www 5089:
1.191 raeburn 5090: sub add_script {
5091: my ($js) = @_;
1.301 bisitz 5092: return '<script type="text/javascript">'."\n"
5093: .'// <![CDATA['."\n"
5094: .$js."\n"
5095: .'// ]]>'."\n"
5096: .'</script>'."\n";
1.191 raeburn 5097: }
5098:
1.391 raeburn 5099: sub usernamerequest_javascript {
5100: my $js = <<ENDJS;
5101:
5102: function openusernamereqdisplay(dom,uname,queue) {
5103: var url = '/adm/createuser?action=displayuserreq';
5104: url += '&domain='+dom+'&username='+uname+'&queue='+queue;
5105: var title = 'Account_Request_Browser';
5106: var options = 'scrollbars=1,resizable=1,menubar=0';
5107: options += ',width=700,height=600';
5108: var stdeditbrowser = open(url,title,options,'1');
5109: stdeditbrowser.focus();
5110: return;
5111: }
5112:
5113: ENDJS
5114: }
5115:
5116: sub close_popup_form {
5117: my $close= &mt('Close Window');
5118: return << "END";
5119: <p><form name="displayreq" action="" method="post">
5120: <input type="button" name="closeme" value="$close" onclick="javascript:self.close();" />
5121: </form></p>
5122: END
5123: }
5124:
1.202 raeburn 5125: sub verify_user_display {
1.364 raeburn 5126: my ($context) = @_;
1.374 raeburn 5127: my %lt = &Apache::lonlocal::texthash (
5128: course => 'course(s): description, section(s), status',
5129: community => 'community(s): description, section(s), status',
5130: author => 'author',
5131: );
1.364 raeburn 5132: my $photos;
5133: if (($context eq 'course') && $env{'request.course.id'}) {
5134: $photos = $env{'course.'.$env{'request.course.id'}.'.internal.showphoto'};
5135: }
1.202 raeburn 5136: my $output = <<"END";
5137:
1.364 raeburn 5138: function hide_searching() {
5139: if (document.getElementById('searching')) {
5140: document.getElementById('searching').style.display = 'none';
5141: }
5142: return;
5143: }
5144:
1.202 raeburn 5145: function display_update() {
5146: document.studentform.action.value = 'listusers';
5147: document.studentform.phase.value = 'display';
5148: document.studentform.submit();
5149: }
5150:
1.364 raeburn 5151: function updateCols(caller) {
5152: var context = '$context';
5153: var photos = '$photos';
5154: if (caller == 'Status') {
1.374 raeburn 5155: if ((context == 'domain') &&
5156: ((document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'course') ||
5157: (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community'))) {
1.364 raeburn 5158: document.getElementById('showcolstatus').checked = false;
5159: document.getElementById('showcolstatus').disabled = 'disabled';
5160: document.getElementById('showcolstart').checked = false;
5161: document.getElementById('showcolend').checked = false;
1.374 raeburn 5162: } else {
5163: if (document.studentform.Status.options[document.studentform.Status.selectedIndex].value == 'Any') {
5164: document.getElementById('showcolstatus').checked = true;
5165: document.getElementById('showcolstatus').disabled = '';
5166: document.getElementById('showcolstart').checked = true;
5167: document.getElementById('showcolend').checked = true;
5168: } else {
5169: document.getElementById('showcolstatus').checked = false;
5170: document.getElementById('showcolstatus').disabled = 'disabled';
5171: document.getElementById('showcolstart').checked = false;
5172: document.getElementById('showcolend').checked = false;
5173: }
1.364 raeburn 5174: }
5175: }
5176: if (caller == 'output') {
5177: if (photos == 1) {
5178: if (document.getElementById('showcolphoto')) {
5179: var photoitem = document.getElementById('showcolphoto');
5180: if (document.studentform.output.options[document.studentform.output.selectedIndex].value == 'html') {
5181: photoitem.checked = true;
5182: photoitem.disabled = '';
5183: } else {
5184: photoitem.checked = false;
5185: photoitem.disabled = 'disabled';
5186: }
5187: }
5188: }
5189: }
5190: if (caller == 'showrole') {
1.371 raeburn 5191: if ((document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'Any') ||
5192: (document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'cr')) {
1.364 raeburn 5193: document.getElementById('showcolrole').checked = true;
5194: document.getElementById('showcolrole').disabled = '';
5195: } else {
5196: document.getElementById('showcolrole').checked = false;
5197: document.getElementById('showcolrole').disabled = 'disabled';
5198: }
1.374 raeburn 5199: if (context == 'domain') {
1.382 raeburn 5200: var quotausageshow = 0;
1.374 raeburn 5201: if ((document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'course') ||
5202: (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community')) {
5203: document.getElementById('showcolstatus').checked = false;
5204: document.getElementById('showcolstatus').disabled = 'disabled';
5205: document.getElementById('showcolstart').checked = false;
5206: document.getElementById('showcolend').checked = false;
5207: } else {
5208: if (document.studentform.Status.options[document.studentform.Status.selectedIndex].value == 'Any') {
5209: document.getElementById('showcolstatus').checked = true;
5210: document.getElementById('showcolstatus').disabled = '';
5211: document.getElementById('showcolstart').checked = true;
5212: document.getElementById('showcolend').checked = true;
5213: }
5214: }
5215: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'domain') {
5216: document.getElementById('showcolextent').disabled = 'disabled';
5217: document.getElementById('showcolextent').checked = 'false';
5218: document.getElementById('showextent').style.display='none';
5219: document.getElementById('showcoltextextent').innerHTML = '';
1.382 raeburn 5220: if ((document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'au') ||
5221: (document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'Any')) {
5222: if (document.getElementById('showcolauthorusage')) {
5223: document.getElementById('showcolauthorusage').disabled = '';
5224: }
5225: if (document.getElementById('showcolauthorquota')) {
5226: document.getElementById('showcolauthorquota').disabled = '';
5227: }
5228: quotausageshow = 1;
5229: }
1.374 raeburn 5230: } else {
5231: document.getElementById('showextent').style.display='block';
5232: document.getElementById('showextent').style.textAlign='left';
5233: document.getElementById('showextent').style.textFace='normal';
5234: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'author') {
5235: document.getElementById('showcolextent').disabled = '';
5236: document.getElementById('showcolextent').checked = 'true';
5237: document.getElementById('showcoltextextent').innerHTML="$lt{'author'}";
5238: } else {
5239: document.getElementById('showcolextent').disabled = '';
5240: document.getElementById('showcolextent').checked = 'true';
5241: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community') {
5242: document.getElementById('showcoltextextent').innerHTML="$lt{'community'}";
5243: } else {
5244: document.getElementById('showcoltextextent').innerHTML="$lt{'course'}";
5245: }
5246: }
5247: }
1.382 raeburn 5248: if (quotausageshow == 0) {
5249: if (document.getElementById('showcolauthorusage')) {
5250: document.getElementById('showcolauthorusage').checked = false;
5251: document.getElementById('showcolauthorusage').disabled = 'disabled';
5252: }
5253: if (document.getElementById('showcolauthorquota')) {
5254: document.getElementById('showcolauthorquota').checked = false;
5255: document.getElementById('showcolauthorquota').disabled = 'disabled';
5256: }
5257: }
1.374 raeburn 5258: }
1.364 raeburn 5259: }
5260: return;
5261: }
5262:
1.202 raeburn 5263: END
5264: return $output;
5265:
5266: }
5267:
1.190 raeburn 5268: ###############################################################
5269: ###############################################################
5270: # Menu Phase One
5271: sub print_main_menu {
1.318 raeburn 5272: my ($permission,$context,$crstype) = @_;
5273: my $linkcontext = $context;
5274: my $stuterm = lc(&Apache::lonnet::plaintext('st',$crstype));
5275: if (($context eq 'course') && ($crstype eq 'Community')) {
5276: $linkcontext = lc($crstype);
5277: $stuterm = 'Members';
5278: }
1.208 raeburn 5279: my %links = (
1.298 droeschl 5280: domain => {
5281: upload => 'Upload a File of Users',
5282: singleuser => 'Add/Modify a User',
5283: listusers => 'Manage Users',
5284: },
5285: author => {
5286: upload => 'Upload a File of Co-authors',
5287: singleuser => 'Add/Modify a Co-author',
5288: listusers => 'Manage Co-authors',
5289: },
5290: course => {
5291: upload => 'Upload a File of Course Users',
5292: singleuser => 'Add/Modify a Course User',
1.354 www 5293: listusers => 'List and Modify Multiple Course Users',
1.298 droeschl 5294: },
1.318 raeburn 5295: community => {
5296: upload => 'Upload a File of Community Users',
5297: singleuser => 'Add/Modify a Community User',
1.354 www 5298: listusers => 'List and Modify Multiple Community Users',
1.318 raeburn 5299: },
5300: );
5301: my %linktitles = (
5302: domain => {
5303: singleuser => 'Add a user to the domain, and/or a course or community in the domain.',
5304: listusers => 'Show and manage users in this domain.',
5305: },
5306: author => {
5307: singleuser => 'Add a user with a co- or assistant author role.',
5308: listusers => 'Show and manage co- or assistant authors.',
5309: },
5310: course => {
5311: singleuser => 'Add a user with a certain role to this course.',
5312: listusers => 'Show and manage users in this course.',
5313: },
5314: community => {
5315: singleuser => 'Add a user with a certain role to this community.',
5316: listusers => 'Show and manage users in this community.',
5317: },
1.298 droeschl 5318: );
5319: my @menu = ( {categorytitle => 'Single Users',
5320: items =>
5321: [
5322: {
1.318 raeburn 5323: linktext => $links{$linkcontext}{'singleuser'},
1.298 droeschl 5324: icon => 'edit-redo.png',
5325: #help => 'Course_Change_Privileges',
5326: url => '/adm/createuser?action=singleuser',
5327: permission => $permission->{'cusr'},
1.318 raeburn 5328: linktitle => $linktitles{$linkcontext}{'singleuser'},
1.298 droeschl 5329: },
5330: ]},
5331:
5332: {categorytitle => 'Multiple Users',
5333: items =>
5334: [
5335: {
1.318 raeburn 5336: linktext => $links{$linkcontext}{'upload'},
1.340 wenzelju 5337: icon => 'uplusr.png',
1.298 droeschl 5338: #help => 'Course_Create_Class_List',
5339: url => '/adm/createuser?action=upload',
5340: permission => $permission->{'cusr'},
5341: linktitle => 'Upload a CSV or a text file containing users.',
5342: },
5343: {
1.318 raeburn 5344: linktext => $links{$linkcontext}{'listusers'},
1.340 wenzelju 5345: icon => 'mngcu.png',
1.298 droeschl 5346: #help => 'Course_View_Class_List',
5347: url => '/adm/createuser?action=listusers',
5348: permission => ($permission->{'view'} || $permission->{'cusr'}),
1.318 raeburn 5349: linktitle => $linktitles{$linkcontext}{'listusers'},
1.298 droeschl 5350: },
5351:
5352: ]},
5353:
5354: {categorytitle => 'Administration',
5355: items => [ ]},
5356: );
1.415 raeburn 5357:
1.265 mielkec 5358: if ($context eq 'domain'){
1.416 ! raeburn 5359: push(@{ $menu[0]->{items} }, # Single Users
! 5360: {
! 5361: linktext => 'User Access Log',
! 5362: icon => 'document-properties.png',
! 5363: #help => 'User_Access_Logs',
! 5364: url => '/adm/createuser?action=accesslogs',
! 5365: permission => $permission->{'activity'},
! 5366: linktitle => 'View user access log.',
! 5367: }
! 5368: );
1.298 droeschl 5369:
5370: push(@{ $menu[2]->{items} }, #Category: Administration
5371: {
5372: linktext => 'Custom Roles',
5373: icon => 'emblem-photos.png',
5374: #help => 'Course_Editing_Custom_Roles',
5375: url => '/adm/createuser?action=custom',
5376: permission => $permission->{'custom'},
5377: linktitle => 'Configure a custom role.',
5378: },
1.362 raeburn 5379: {
5380: linktext => 'Authoring Space Requests',
5381: icon => 'selfenrl-queue.png',
5382: #help => 'Domain_Role_Approvals',
5383: url => '/adm/createuser?action=processauthorreq',
5384: permission => $permission->{'cusr'},
5385: linktitle => 'Approve or reject author role requests',
5386: },
1.363 raeburn 5387: {
1.391 raeburn 5388: linktext => 'LON-CAPA Account Requests',
5389: icon => 'list-add.png',
5390: #help => 'Domain_Username_Approvals',
5391: url => '/adm/createuser?action=processusernamereq',
5392: permission => $permission->{'cusr'},
5393: linktitle => 'Approve or reject LON-CAPA account requests',
5394: },
5395: {
1.363 raeburn 5396: linktext => 'Change Log',
5397: icon => 'document-properties.png',
5398: #help => 'Course_User_Logs',
5399: url => '/adm/createuser?action=changelogs',
5400: permission => $permission->{'cusr'},
5401: linktitle => 'View change log.',
5402: },
1.298 droeschl 5403: );
5404:
1.265 mielkec 5405: }elsif ($context eq 'course'){
1.298 droeschl 5406: my ($cnum,$cdom) = &Apache::lonuserutils::get_course_identity();
1.318 raeburn 5407:
5408: my %linktext = (
5409: 'Course' => {
5410: single => 'Add/Modify a Student',
5411: drop => 'Drop Students',
5412: groups => 'Course Groups',
5413: },
5414: 'Community' => {
5415: single => 'Add/Modify a Member',
5416: drop => 'Drop Members',
5417: groups => 'Community Groups',
5418: },
5419: );
1.411 raeburn 5420: $linktext{'Placement'} = $linktext{'Course'};
1.318 raeburn 5421:
5422: my %linktitle = (
5423: 'Course' => {
5424: single => 'Add a user with the role of student to this course',
5425: drop => 'Remove a student from this course.',
5426: groups => 'Manage course groups',
5427: },
5428: 'Community' => {
5429: single => 'Add a user with the role of member to this community',
5430: drop => 'Remove a member from this community.',
5431: groups => 'Manage community groups',
5432: },
5433: );
5434:
1.411 raeburn 5435: $linktitle{'Placement'} = $linktitle{'Course'};
5436:
1.298 droeschl 5437: push(@{ $menu[0]->{items} }, #Category: Single Users
5438: {
1.318 raeburn 5439: linktext => $linktext{$crstype}{'single'},
1.298 droeschl 5440: #help => 'Course_Add_Student',
5441: icon => 'list-add.png',
5442: url => '/adm/createuser?action=singlestudent',
5443: permission => $permission->{'cusr'},
1.318 raeburn 5444: linktitle => $linktitle{$crstype}{'single'},
1.298 droeschl 5445: },
5446: );
5447:
5448: push(@{ $menu[1]->{items} }, #Category: Multiple Users
5449: {
1.318 raeburn 5450: linktext => $linktext{$crstype}{'drop'},
1.298 droeschl 5451: icon => 'edit-undo.png',
5452: #help => 'Course_Drop_Student',
5453: url => '/adm/createuser?action=drop',
5454: permission => $permission->{'cusr'},
1.318 raeburn 5455: linktitle => $linktitle{$crstype}{'drop'},
1.298 droeschl 5456: },
5457: );
5458: push(@{ $menu[2]->{items} }, #Category: Administration
5459: {
5460: linktext => 'Custom Roles',
5461: icon => 'emblem-photos.png',
5462: #help => 'Course_Editing_Custom_Roles',
5463: url => '/adm/createuser?action=custom',
5464: permission => $permission->{'custom'},
5465: linktitle => 'Configure a custom role.',
5466: },
5467: {
1.318 raeburn 5468: linktext => $linktext{$crstype}{'groups'},
1.333 wenzelju 5469: icon => 'grps.png',
1.298 droeschl 5470: #help => 'Course_Manage_Group',
5471: url => '/adm/coursegroups?refpage=cusr',
5472: permission => $permission->{'grp_manage'},
1.318 raeburn 5473: linktitle => $linktitle{$crstype}{'groups'},
1.298 droeschl 5474: },
5475: {
1.328 wenzelju 5476: linktext => 'Change Log',
1.298 droeschl 5477: icon => 'document-properties.png',
5478: #help => 'Course_User_Logs',
5479: url => '/adm/createuser?action=changelogs',
5480: permission => $permission->{'cusr'},
5481: linktitle => 'View change log.',
5482: },
5483: );
1.277 raeburn 5484: if ($env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_approval'}) {
1.298 droeschl 5485: push(@{ $menu[2]->{items} },
1.398 raeburn 5486: {
1.298 droeschl 5487: linktext => 'Enrollment Requests',
5488: icon => 'selfenrl-queue.png',
5489: #help => 'Course_Approve_Selfenroll',
5490: url => '/adm/createuser?action=selfenrollqueue',
1.398 raeburn 5491: permission => $permission->{'selfenrolladmin'},
1.298 droeschl 5492: linktitle =>'Approve or reject enrollment requests.',
5493: },
5494: );
1.277 raeburn 5495: }
1.298 droeschl 5496:
1.265 mielkec 5497: if (!exists($permission->{'cusr_section'})){
1.320 raeburn 5498: if ($crstype ne 'Community') {
5499: push(@{ $menu[2]->{items} },
5500: {
5501: linktext => 'Automated Enrollment',
5502: icon => 'roles.png',
5503: #help => 'Course_Automated_Enrollment',
5504: permission => (&Apache::lonnet::auto_run($cnum,$cdom)
5505: && $permission->{'cusr'}),
5506: url => '/adm/populate',
5507: linktitle => 'Automated enrollment manager.',
5508: }
5509: );
5510: }
5511: push(@{ $menu[2]->{items} },
1.298 droeschl 5512: {
5513: linktext => 'User Self-Enrollment',
1.342 wenzelju 5514: icon => 'self_enroll.png',
1.298 droeschl 5515: #help => 'Course_Self_Enrollment',
5516: url => '/adm/createuser?action=selfenroll',
1.398 raeburn 5517: permission => $permission->{'selfenrolladmin'},
1.317 bisitz 5518: linktitle => 'Configure user self-enrollment.',
1.298 droeschl 5519: },
5520: );
5521: }
1.363 raeburn 5522: } elsif ($context eq 'author') {
1.370 raeburn 5523: push(@{ $menu[2]->{items} }, #Category: Administration
1.363 raeburn 5524: {
5525: linktext => 'Change Log',
5526: icon => 'document-properties.png',
5527: #help => 'Course_User_Logs',
5528: url => '/adm/createuser?action=changelogs',
5529: permission => $permission->{'cusr'},
5530: linktitle => 'View change log.',
5531: },
1.370 raeburn 5532: );
1.363 raeburn 5533: }
5534: return Apache::lonhtmlcommon::generate_menu(@menu);
1.250 raeburn 5535: # { text => 'View Log-in History',
5536: # help => 'Course_User_Logins',
5537: # action => 'logins',
5538: # permission => $permission->{'cusr'},
5539: # });
1.190 raeburn 5540: }
5541:
1.189 albertel 5542: sub restore_prev_selections {
5543: my %saveable_parameters = ('srchby' => 'scalar',
5544: 'srchin' => 'scalar',
5545: 'srchtype' => 'scalar',
5546: );
5547: &Apache::loncommon::store_settings('user','user_picker',
5548: \%saveable_parameters);
5549: &Apache::loncommon::restore_settings('user','user_picker',
5550: \%saveable_parameters);
5551: }
5552:
1.237 raeburn 5553: sub print_selfenroll_menu {
1.398 raeburn 5554: my ($r,$context,$cid,$cdom,$cnum,$currsettings,$additional) = @_;
1.322 raeburn 5555: my $crstype = &Apache::loncommon::course_type();
1.398 raeburn 5556: my $formname = 'selfenroll';
1.237 raeburn 5557: my $nolink = 1;
1.398 raeburn 5558: my ($row,$lt) = &Apache::lonuserutils::get_selfenroll_titles();
1.237 raeburn 5559: my $groupslist = &Apache::lonuserutils::get_groupslist();
5560: my $setsec_js =
5561: &Apache::lonuserutils::setsections_javascript($formname,$groupslist);
1.249 raeburn 5562: my %alerts = &Apache::lonlocal::texthash(
5563: acto => 'Activation of self-enrollment was selected for the following domain(s)',
5564: butn => 'but no user types have been checked.',
5565: wilf => "Please uncheck 'activate' or check at least one type.",
5566: );
1.405 damieng 5567: &js_escape(\%alerts);
1.249 raeburn 5568: my $selfenroll_js = <<"ENDSCRIPT";
5569: function update_types(caller,num) {
5570: var delidx = getIndexByName('selfenroll_delete');
5571: var actidx = getIndexByName('selfenroll_activate');
5572: if (caller == 'selfenroll_all') {
5573: var selall;
5574: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
5575: if (document.$formname.selfenroll_all[i].checked) {
5576: selall = document.$formname.selfenroll_all[i].value;
5577: }
5578: }
5579: if (selall == 1) {
5580: if (delidx != -1) {
5581: if (document.$formname.selfenroll_delete.length) {
5582: for (var j=0; j<document.$formname.selfenroll_delete.length; j++) {
5583: document.$formname.selfenroll_delete[j].checked = true;
5584: }
5585: } else {
5586: document.$formname.elements[delidx].checked = true;
5587: }
5588: }
5589: if (actidx != -1) {
5590: if (document.$formname.selfenroll_activate.length) {
5591: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
5592: document.$formname.selfenroll_activate[j].checked = false;
5593: }
5594: } else {
5595: document.$formname.elements[actidx].checked = false;
5596: }
5597: }
5598: document.$formname.selfenroll_newdom.selectedIndex = 0;
5599: }
5600: }
5601: if (caller == 'selfenroll_activate') {
5602: if (document.$formname.selfenroll_activate.length) {
5603: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
5604: if (document.$formname.selfenroll_activate[j].value == num) {
5605: if (document.$formname.selfenroll_activate[j].checked) {
5606: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
5607: if (document.$formname.selfenroll_all[i].value == '1') {
5608: document.$formname.selfenroll_all[i].checked = false;
5609: }
5610: if (document.$formname.selfenroll_all[i].value == '0') {
5611: document.$formname.selfenroll_all[i].checked = true;
5612: }
5613: }
5614: }
5615: }
5616: }
5617: } else {
5618: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
5619: if (document.$formname.selfenroll_all[i].value == '1') {
5620: document.$formname.selfenroll_all[i].checked = false;
5621: }
5622: if (document.$formname.selfenroll_all[i].value == '0') {
5623: document.$formname.selfenroll_all[i].checked = true;
5624: }
5625: }
5626: }
5627: }
5628: if (caller == 'selfenroll_delete') {
5629: if (document.$formname.selfenroll_delete.length) {
5630: for (var j=0; j<document.$formname.selfenroll_delete.length; j++) {
5631: if (document.$formname.selfenroll_delete[j].value == num) {
5632: if (document.$formname.selfenroll_delete[j].checked) {
5633: var delindex = getIndexByName('selfenroll_types_'+num);
5634: if (delindex != -1) {
5635: if (document.$formname.elements[delindex].length) {
5636: for (var k=0; k<document.$formname.elements[delindex].length; k++) {
5637: document.$formname.elements[delindex][k].checked = false;
5638: }
5639: } else {
5640: document.$formname.elements[delindex].checked = false;
5641: }
5642: }
5643: }
5644: }
5645: }
5646: } else {
5647: if (document.$formname.selfenroll_delete.checked) {
5648: var delindex = getIndexByName('selfenroll_types_'+num);
5649: if (delindex != -1) {
5650: if (document.$formname.elements[delindex].length) {
5651: for (var k=0; k<document.$formname.elements[delindex].length; k++) {
5652: document.$formname.elements[delindex][k].checked = false;
5653: }
5654: } else {
5655: document.$formname.elements[delindex].checked = false;
5656: }
5657: }
5658: }
5659: }
5660: }
5661: return;
5662: }
5663:
5664: function validate_types(form) {
5665: var needaction = new Array();
5666: var countfail = 0;
5667: var actidx = getIndexByName('selfenroll_activate');
5668: if (actidx != -1) {
5669: if (document.$formname.selfenroll_activate.length) {
5670: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
5671: var num = document.$formname.selfenroll_activate[j].value;
5672: if (document.$formname.selfenroll_activate[j].checked) {
5673: countfail = check_types(num,countfail,needaction)
5674: }
5675: }
5676: } else {
5677: if (document.$formname.selfenroll_activate.checked) {
1.398 raeburn 5678: var num = document.$formname.selfenroll_activate.value;
1.249 raeburn 5679: countfail = check_types(num,countfail,needaction)
5680: }
5681: }
5682: }
5683: if (countfail > 0) {
5684: var msg = "$alerts{'acto'}\\n";
5685: var loopend = needaction.length -1;
5686: if (loopend > 0) {
5687: for (var m=0; m<loopend; m++) {
5688: msg += needaction[m]+", ";
5689: }
5690: }
5691: msg += needaction[loopend]+"\\n$alerts{'butn'}\\n$alerts{'wilf'}";
5692: alert(msg);
5693: return;
5694: }
5695: setSections(form);
5696: }
5697:
5698: function check_types(num,countfail,needaction) {
5699: var typeidx = getIndexByName('selfenroll_types_'+num);
5700: var count = 0;
5701: if (typeidx != -1) {
5702: if (document.$formname.elements[typeidx].length) {
5703: for (var k=0; k<document.$formname.elements[typeidx].length; k++) {
5704: if (document.$formname.elements[typeidx][k].checked) {
5705: count ++;
5706: }
5707: }
5708: } else {
5709: if (document.$formname.elements[typeidx].checked) {
5710: count ++;
5711: }
5712: }
5713: if (count == 0) {
5714: var domidx = getIndexByName('selfenroll_dom_'+num);
5715: if (domidx != -1) {
5716: var domname = document.$formname.elements[domidx].value;
5717: needaction[countfail] = domname;
5718: countfail ++;
5719: }
5720: }
5721: }
5722: return countfail;
5723: }
5724:
1.398 raeburn 5725: function toggleNotify() {
5726: var selfenrollApproval = 0;
5727: if (document.$formname.selfenroll_approval.length) {
5728: for (var i=0; i<document.$formname.selfenroll_approval.length; i++) {
5729: if (document.$formname.selfenroll_approval[i].checked) {
5730: selfenrollApproval = document.$formname.selfenroll_approval[i].value;
5731: break;
5732: }
5733: }
5734: }
5735: if (document.getElementById('notified')) {
5736: if (selfenrollApproval == 0) {
5737: document.getElementById('notified').style.display='none';
5738: } else {
5739: document.getElementById('notified').style.display='block';
5740: }
5741: }
5742: return;
5743: }
5744:
1.249 raeburn 5745: function getIndexByName(item) {
5746: for (var i=0;i<document.$formname.elements.length;i++) {
5747: if (document.$formname.elements[i].name == item) {
5748: return i;
5749: }
5750: }
5751: return -1;
5752: }
5753: ENDSCRIPT
1.256 raeburn 5754:
1.237 raeburn 5755: my $output = '<script type="text/javascript">'."\n".
1.301 bisitz 5756: '// <![CDATA['."\n".
1.249 raeburn 5757: $setsec_js."\n".$selfenroll_js."\n".
1.301 bisitz 5758: '// ]]>'."\n".
1.237 raeburn 5759: '</script>'."\n".
1.256 raeburn 5760: '<h3>'.$lt->{'selfenroll'}.'</h3>'."\n";
1.400 raeburn 5761:
5762: my $visactions = &cat_visibility();
5763: my ($cathash,%cattype);
5764: my %domconfig = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom);
5765: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
5766: $cathash = $domconfig{'coursecategories'}{'cats'};
5767: $cattype{'auth'} = $domconfig{'coursecategories'}{'auth'};
5768: $cattype{'unauth'} = $domconfig{'coursecategories'}{'unauth'};
1.406 raeburn 5769: if ($cattype{'auth'} eq '') {
5770: $cattype{'auth'} = 'std';
5771: }
5772: if ($cattype{'unauth'} eq '') {
5773: $cattype{'unauth'} = 'std';
5774: }
1.400 raeburn 5775: } else {
5776: $cathash = {};
5777: $cattype{'auth'} = 'std';
5778: $cattype{'unauth'} = 'std';
5779: }
5780: if (($cattype{'auth'} eq 'none') && ($cattype{'unauth'} eq 'none')) {
5781: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
5782: '<br />'.
5783: '<br />'.$visactions->{'take'}.'<ul>'.
5784: '<li>'.$visactions->{'dc_chgconf'}.'</li>'.
5785: '</ul>');
5786: } elsif (($cattype{'auth'} !~ /^(std|domonly)$/) && ($cattype{'unauth'} !~ /^(std|domonly)$/)) {
5787: if ($currsettings->{'uniquecode'}) {
5788: $r->print('<span class="LC_info">'.$visactions->{'vis'}.'</span>');
5789: } else {
5790: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
5791: '<br />'.
5792: '<br />'.$visactions->{'take'}.'<ul>'.
5793: '<li>'.$visactions->{'dc_setcode'}.'</li>'.
5794: '</ul><br />');
5795: }
5796: } else {
5797: my ($visible,$cansetvis,$vismsgs) = &visible_in_stdcat($cdom,$cnum,\%domconfig);
5798: if (ref($visactions) eq 'HASH') {
5799: if ($visible) {
5800: $output .= '<p class="LC_info">'.$visactions->{'vis'}.'</p>';
5801: } else {
5802: $output .= '<p class="LC_warning">'.$visactions->{'miss'}.'</p>'
5803: .$visactions->{'yous'}.
5804: '<p>'.$visactions->{'gen'}.'<br />'.$visactions->{'coca'};
5805: if (ref($vismsgs) eq 'ARRAY') {
5806: $output .= '<br />'.$visactions->{'make'}.'<ul>';
5807: foreach my $item (@{$vismsgs}) {
5808: $output .= '<li>'.$visactions->{$item}.'</li>';
5809: }
5810: $output .= '</ul>';
1.256 raeburn 5811: }
1.400 raeburn 5812: $output .= '</p>';
1.256 raeburn 5813: }
5814: }
5815: }
1.398 raeburn 5816: my $actionhref = '/adm/createuser';
5817: if ($context eq 'domain') {
5818: $actionhref = '/adm/modifycourse';
5819: }
1.400 raeburn 5820:
5821: my %noedit;
5822: unless ($context eq 'domain') {
5823: %noedit = &get_noedit_fields($cdom,$cnum,$crstype,$row);
5824: }
1.398 raeburn 5825: $output .= '<form name="'.$formname.'" method="post" action="'.$actionhref.'">'."\n".
1.256 raeburn 5826: &Apache::lonhtmlcommon::start_pick_box();
1.237 raeburn 5827: if (ref($row) eq 'ARRAY') {
5828: foreach my $item (@{$row}) {
5829: my $title = $item;
5830: if (ref($lt) eq 'HASH') {
5831: $title = $lt->{$item};
5832: }
1.297 bisitz 5833: $output .= &Apache::lonhtmlcommon::row_title($title);
1.237 raeburn 5834: if ($item eq 'types') {
1.398 raeburn 5835: my $curr_types;
5836: if (ref($currsettings) eq 'HASH') {
5837: $curr_types = $currsettings->{'selfenroll_types'};
5838: }
1.400 raeburn 5839: if ($noedit{$item}) {
5840: if ($curr_types eq '*') {
5841: $output .= &mt('Any user in any domain');
5842: } else {
5843: my @entries = split(/;/,$curr_types);
5844: if (@entries > 0) {
5845: $output .= '<ul>';
5846: foreach my $entry (@entries) {
5847: my ($currdom,$typestr) = split(/:/,$entry);
5848: next if ($typestr eq '');
5849: my $domdesc = &Apache::lonnet::domain($currdom);
5850: my @currinsttypes = split(',',$typestr);
5851: my ($othertitle,$usertypes,$types) =
5852: &Apache::loncommon::sorted_inst_types($currdom);
5853: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
5854: $usertypes->{'any'} = &mt('any user');
5855: if (keys(%{$usertypes}) > 0) {
5856: $usertypes->{'other'} = &mt('other users');
5857: }
5858: my @longinsttypes = map { $usertypes->{$_}; } @currinsttypes;
5859: $output .= '<li>'.$domdesc.':'.join(', ',@longinsttypes).'</li>';
5860: }
5861: }
5862: $output .= '</ul>';
5863: } else {
5864: $output .= &mt('None');
5865: }
5866: }
5867: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
5868: next;
5869: }
1.241 raeburn 5870: my $showdomdesc = 1;
5871: my $includeempty = 1;
5872: my $num = 0;
5873: $output .= &Apache::loncommon::start_data_table().
5874: &Apache::loncommon::start_data_table_row()
5875: .'<td colspan="2"><span class="LC_nobreak"><label>'
5876: .&mt('Any user in any domain:')
5877: .' <input type="radio" name="selfenroll_all" value="1" ';
5878: if ($curr_types eq '*') {
5879: $output .= ' checked="checked" ';
5880: }
1.249 raeburn 5881: $output .= 'onchange="javascript:update_types('.
5882: "'selfenroll_all'".');" />'.&mt('Yes').'</label>'.
5883: ' <input type="radio" name="selfenroll_all" value="0" ';
1.241 raeburn 5884: if ($curr_types ne '*') {
5885: $output .= ' checked="checked" ';
5886: }
1.249 raeburn 5887: $output .= ' onchange="javascript:update_types('.
5888: "'selfenroll_all'".');"/>'.&mt('No').'</label></td>'.
5889: &Apache::loncommon::end_data_table_row().
5890: &Apache::loncommon::end_data_table().
5891: &mt('Or').'<br />'.
5892: &Apache::loncommon::start_data_table();
1.241 raeburn 5893: my %currdoms;
1.249 raeburn 5894: if ($curr_types eq '') {
1.241 raeburn 5895: $output .= &new_selfenroll_dom_row($cdom,'0');
5896: } elsif ($curr_types ne '*') {
5897: my @entries = split(/;/,$curr_types);
5898: if (@entries > 0) {
5899: foreach my $entry (@entries) {
5900: my ($currdom,$typestr) = split(/:/,$entry);
5901: $currdoms{$currdom} = 1;
5902: my $domdesc = &Apache::lonnet::domain($currdom);
1.249 raeburn 5903: my @currinsttypes = split(',',$typestr);
1.241 raeburn 5904: $output .= &Apache::loncommon::start_data_table_row()
5905: .'<td valign="top"><span class="LC_nobreak">'.&mt('Domain:').'<b>'
5906: .' '.$domdesc.' ('.$currdom.')'
5907: .'</b><input type="hidden" name="selfenroll_dom_'.$num
5908: .'" value="'.$currdom.'" /></span><br />'
5909: .'<span class="LC_nobreak"><label><input type="checkbox" '
1.249 raeburn 5910: .'name="selfenroll_delete" value="'.$num.'" onchange="javascript:update_types('."'selfenroll_delete','$num'".');" />'
1.241 raeburn 5911: .&mt('Delete').'</label></span></td>';
1.249 raeburn 5912: $output .= '<td valign="top"> '.&mt('User types:').'<br />'
1.241 raeburn 5913: .&selfenroll_inst_types($num,$currdom,\@currinsttypes).'</td>'
5914: .&Apache::loncommon::end_data_table_row();
5915: $num ++;
5916: }
5917: }
5918: }
1.249 raeburn 5919: my $add_domtitle = &mt('Users in additional domain:');
1.241 raeburn 5920: if ($curr_types eq '*') {
1.249 raeburn 5921: $add_domtitle = &mt('Users in specific domain:');
1.241 raeburn 5922: } elsif ($curr_types eq '') {
1.249 raeburn 5923: $add_domtitle = &mt('Users in other domain:');
1.241 raeburn 5924: }
5925: $output .= &Apache::loncommon::start_data_table_row()
5926: .'<td colspan="2"><span class="LC_nobreak">'.$add_domtitle.'</span><br />'
5927: .&Apache::loncommon::select_dom_form('','selfenroll_newdom',
5928: $includeempty,$showdomdesc)
5929: .'<input type="hidden" name="selfenroll_types_total" value="'.$num.'" />'
5930: .'</td>'.&Apache::loncommon::end_data_table_row()
5931: .&Apache::loncommon::end_data_table();
1.237 raeburn 5932: } elsif ($item eq 'registered') {
5933: my ($regon,$regoff);
1.398 raeburn 5934: my $registered;
5935: if (ref($currsettings) eq 'HASH') {
5936: $registered = $currsettings->{'selfenroll_registered'};
5937: }
1.400 raeburn 5938: if ($noedit{$item}) {
5939: if ($registered) {
5940: $output .= &mt('Must be registered in course');
5941: } else {
5942: $output .= &mt('No requirement');
5943: }
5944: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
5945: next;
5946: }
1.398 raeburn 5947: if ($registered) {
1.237 raeburn 5948: $regon = ' checked="checked" ';
5949: $regoff = ' ';
5950: } else {
5951: $regon = ' ';
5952: $regoff = ' checked="checked" ';
5953: }
5954: $output .= '<label>'.
1.245 raeburn 5955: '<input type="radio" name="selfenroll_registered" value="1"'.$regon.'/>'.
1.244 bisitz 5956: &mt('Yes').'</label> <label>'.
1.245 raeburn 5957: '<input type="radio" name="selfenroll_registered" value="0"'.$regoff.'/>'.
1.244 bisitz 5958: &mt('No').'</label>';
1.237 raeburn 5959: } elsif ($item eq 'enroll_dates') {
1.398 raeburn 5960: my ($starttime,$endtime);
5961: if (ref($currsettings) eq 'HASH') {
5962: $starttime = $currsettings->{'selfenroll_start_date'};
5963: $endtime = $currsettings->{'selfenroll_end_date'};
5964: if ($starttime eq '') {
5965: $starttime = $currsettings->{'default_enrollment_start_date'};
5966: }
5967: if ($endtime eq '') {
5968: $endtime = $currsettings->{'default_enrollment_end_date'};
5969: }
1.237 raeburn 5970: }
1.400 raeburn 5971: if ($noedit{$item}) {
5972: $output .= &mt('From: [_1], to: [_2]',&Apache::lonlocal::locallocaltime($starttime),
5973: &Apache::lonlocal::locallocaltime($endtime));
5974: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
5975: next;
5976: }
1.237 raeburn 5977: my $startform =
5978: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_start_date',$starttime,
5979: undef,undef,undef,undef,undef,undef,undef,$nolink);
5980: my $endform =
5981: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_end_date',$endtime,
5982: undef,undef,undef,undef,undef,undef,undef,$nolink);
5983: $output .= &selfenroll_date_forms($startform,$endform);
5984: } elsif ($item eq 'access_dates') {
1.398 raeburn 5985: my ($starttime,$endtime);
5986: if (ref($currsettings) eq 'HASH') {
5987: $starttime = $currsettings->{'selfenroll_start_access'};
5988: $endtime = $currsettings->{'selfenroll_end_access'};
5989: if ($starttime eq '') {
5990: $starttime = $currsettings->{'default_enrollment_start_date'};
5991: }
5992: if ($endtime eq '') {
5993: $endtime = $currsettings->{'default_enrollment_end_date'};
5994: }
1.237 raeburn 5995: }
1.400 raeburn 5996: if ($noedit{$item}) {
5997: $output .= &mt('From: [_1], to: [_2]',&Apache::lonlocal::locallocaltime($starttime),
5998: &Apache::lonlocal::locallocaltime($endtime));
5999: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6000: next;
6001: }
1.237 raeburn 6002: my $startform =
6003: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_start_access',$starttime,
6004: undef,undef,undef,undef,undef,undef,undef,$nolink);
6005: my $endform =
6006: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_end_access',$endtime,
6007: undef,undef,undef,undef,undef,undef,undef,$nolink);
6008: $output .= &selfenroll_date_forms($startform,$endform);
6009: } elsif ($item eq 'section') {
1.398 raeburn 6010: my $currsec;
6011: if (ref($currsettings) eq 'HASH') {
6012: $currsec = $currsettings->{'selfenroll_section'};
6013: }
1.237 raeburn 6014: my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum);
6015: my $newsecval;
6016: if ($currsec ne 'none' && $currsec ne '') {
6017: if (!defined($sections_count{$currsec})) {
6018: $newsecval = $currsec;
6019: }
6020: }
1.400 raeburn 6021: if ($noedit{$item}) {
6022: if ($currsec ne '') {
6023: $output .= $currsec;
6024: } else {
6025: $output .= &mt('No specific section');
6026: }
6027: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6028: next;
6029: }
1.237 raeburn 6030: my $sections_select =
6031: &Apache::lonuserutils::course_sections(\%sections_count,'st',$currsec);
6032: $output .= '<table class="LC_createuser">'."\n".
6033: '<tr class="LC_section_row">'."\n".
6034: '<td align="center">'.&mt('Existing sections')."\n".
6035: '<br />'.$sections_select.'</td><td align="center">'.
6036: &mt('New section').'<br />'."\n".
6037: '<input type="text" name="newsec" size="15" value="'.$newsecval.'" />'."\n".
6038: '<input type="hidden" name="sections" value="" />'."\n".
6039: '</td></tr></table>'."\n";
1.276 raeburn 6040: } elsif ($item eq 'approval') {
1.398 raeburn 6041: my ($currnotified,$currapproval,%appchecked);
6042: my %selfdescs = &Apache::lonuserutils::selfenroll_default_descs();
6043: if (ref($currsettings) eq 'HASH') {
6044: $currnotified = $currsettings->{'selfenroll_notifylist'};
6045: $currapproval = $currsettings->{'selfenroll_approval'};
6046: }
6047: if ($currapproval !~ /^[012]$/) {
6048: $currapproval = 0;
6049: }
1.400 raeburn 6050: if ($noedit{$item}) {
6051: $output .= $selfdescs{'approval'}{$currapproval}.
6052: '<br />'.&mt('(Set by Domain Coordinator)');
6053: next;
6054: }
1.398 raeburn 6055: $appchecked{$currapproval} = ' checked="checked"';
6056: for my $i (0..2) {
6057: $output .= '<label>'.
6058: '<input type="radio" name="selfenroll_approval" value="'.$i.'"'.
6059: $appchecked{$i}.' onclick="toggleNotify();" />'.$selfdescs{'approval'}{$i}.
6060: '</label>'.(' 'x2);
1.276 raeburn 6061: }
6062: my %advhash = &Apache::lonnet::get_course_adv_roles($cid,1);
6063: my (@ccs,%notified);
1.322 raeburn 6064: my $ccrole = 'cc';
6065: if ($crstype eq 'Community') {
6066: $ccrole = 'co';
6067: }
6068: if ($advhash{$ccrole}) {
6069: @ccs = split(/,/,$advhash{$ccrole});
1.276 raeburn 6070: }
6071: if ($currnotified) {
6072: foreach my $current (split(/,/,$currnotified)) {
6073: $notified{$current} = 1;
6074: if (!grep(/^\Q$current\E$/,@ccs)) {
6075: push(@ccs,$current);
6076: }
6077: }
6078: }
6079: if (@ccs) {
1.398 raeburn 6080: my $style;
6081: unless ($currapproval) {
6082: $style = ' style="display: none;"';
6083: }
6084: $output .= '<br /><div id="notified"'.$style.'>'.
6085: &mt('Personnel to be notified when an enrollment request needs approval, or has been approved:').' '.
6086: &Apache::loncommon::start_data_table().
1.276 raeburn 6087: &Apache::loncommon::start_data_table_row();
6088: my $count = 0;
6089: my $numcols = 4;
6090: foreach my $cc (sort(@ccs)) {
6091: my $notifyon;
6092: my ($ccuname,$ccudom) = split(/:/,$cc);
6093: if ($notified{$cc}) {
6094: $notifyon = ' checked="checked" ';
6095: }
6096: if ($count && !$count%$numcols) {
6097: $output .= &Apache::loncommon::end_data_table_row().
6098: &Apache::loncommon::start_data_table_row()
6099: }
6100: $output .= '<td><span class="LC_nobreak"><label>'.
6101: '<input type="checkbox" name="selfenroll_notify"'.$notifyon.' value="'.$cc.'" />'.
6102: &Apache::loncommon::plainname($ccuname,$ccudom).
6103: '</label></span></td>';
1.343 raeburn 6104: $count ++;
1.276 raeburn 6105: }
6106: my $rem = $count%$numcols;
6107: if ($rem) {
6108: my $emptycols = $numcols - $rem;
6109: for (my $i=0; $i<$emptycols; $i++) {
6110: $output .= '<td> </td>';
6111: }
6112: }
6113: $output .= &Apache::loncommon::end_data_table_row().
1.398 raeburn 6114: &Apache::loncommon::end_data_table().
6115: '</div>';
1.276 raeburn 6116: }
6117: } elsif ($item eq 'limit') {
1.398 raeburn 6118: my ($crslimit,$selflimit,$nolimit,$currlim,$currcap);
6119: if (ref($currsettings) eq 'HASH') {
6120: $currlim = $currsettings->{'selfenroll_limit'};
6121: $currcap = $currsettings->{'selfenroll_cap'};
6122: }
1.400 raeburn 6123: if ($noedit{$item}) {
6124: if (($currlim eq 'allstudents') || ($currlim eq 'selfenrolled')) {
6125: if ($currlim eq 'allstudents') {
6126: $output .= &mt('Limit by total students');
6127: } elsif ($currlim eq 'selfenrolled') {
6128: $output .= &mt('Limit by total self-enrolled students');
6129: }
6130: $output .= ' '.&mt('Maximum: [_1]',$currcap).
6131: '<br />'.&mt('(Set by Domain Coordinator)');
6132: } else {
6133: $output .= &mt('No limit').'<br />'.&mt('(Set by Domain Coordinator)');
6134: }
6135: next;
6136: }
1.276 raeburn 6137: if ($currlim eq 'allstudents') {
6138: $crslimit = ' checked="checked" ';
6139: $selflimit = ' ';
6140: $nolimit = ' ';
6141: } elsif ($currlim eq 'selfenrolled') {
6142: $crslimit = ' ';
6143: $selflimit = ' checked="checked" ';
6144: $nolimit = ' ';
6145: } else {
6146: $crslimit = ' ';
6147: $selflimit = ' ';
1.398 raeburn 6148: $nolimit = ' checked="checked" ';
1.276 raeburn 6149: }
6150: $output .= '<table><tr><td><label>'.
1.278 raeburn 6151: '<input type="radio" name="selfenroll_limit" value="none"'.$nolimit.'/>'.
1.276 raeburn 6152: &mt('No limit').'</label></td><td><label>'.
6153: '<input type="radio" name="selfenroll_limit" value="allstudents"'.$crslimit.'/>'.
6154: &mt('Limit by total students').'</label></td><td><label>'.
6155: '<input type="radio" name="selfenroll_limit" value="selfenrolled"'.$selflimit.'/>'.
6156: &mt('Limit by total self-enrolled students').
6157: '</td></tr><tr>'.
6158: '<td> </td><td colspan="2"><span class="LC_nobreak">'.
6159: (' 'x3).&mt('Maximum number allowed: ').
6160: '<input type="text" name="selfenroll_cap" size = "5" value="'.$currcap.'" /></td></tr></table>';
1.237 raeburn 6161: }
6162: $output .= &Apache::lonhtmlcommon::row_closure(1);
6163: }
6164: }
6165: $output .= &Apache::lonhtmlcommon::end_pick_box().
1.241 raeburn 6166: '<br /><input type="button" name="selfenrollconf" value="'
1.282 schafran 6167: .&mt('Save').'" onclick="validate_types(this.form);" />'
1.400 raeburn 6168: .'<input type="hidden" name="action" value="selfenroll" />'
6169: .'<input type="hidden" name="state" value="done" />'."\n".
1.398 raeburn 6170: $additional.'</form>';
1.237 raeburn 6171: $r->print($output);
6172: return;
6173: }
6174:
1.400 raeburn 6175: sub get_noedit_fields {
6176: my ($cdom,$cnum,$crstype,$row) = @_;
6177: my %noedit;
6178: if (ref($row) eq 'ARRAY') {
6179: my %settings = &Apache::lonnet::get('environment',['internal.coursecode','internal.textbook',
6180: 'internal.selfenrollmgrdc',
6181: 'internal.selfenrollmgrcc'],$cdom,$cnum);
6182: my $type = &Apache::lonuserutils::get_extended_type($cdom,$cnum,$crstype,\%settings);
6183: my (%specific_managebydc,%specific_managebycc,%default_managebydc);
6184: map { $specific_managebydc{$_} = 1; } (split(/,/,$settings{'internal.selfenrollmgrdc'}));
6185: map { $specific_managebycc{$_} = 1; } (split(/,/,$settings{'internal.selfenrollmgrcc'}));
6186: my %domdefaults = &Apache::lonnet::get_domain_defaults($cdom);
6187: map { $default_managebydc{$_} = 1; } (split(/,/,$domdefaults{$type.'selfenrolladmdc'}));
6188:
6189: foreach my $item (@{$row}) {
6190: next if ($specific_managebycc{$item});
6191: if (($specific_managebydc{$item}) || ($default_managebydc{$item})) {
6192: $noedit{$item} = 1;
6193: }
6194: }
6195: }
6196: return %noedit;
6197: }
6198:
6199: sub visible_in_stdcat {
6200: my ($cdom,$cnum,$domconf) = @_;
6201: my ($cathash,%settable,@vismsgs,$cansetvis,$visible);
6202: unless (ref($domconf) eq 'HASH') {
6203: return ($visible,$cansetvis,\@vismsgs);
6204: }
6205: if (ref($domconf->{'coursecategories'}) eq 'HASH') {
6206: if ($domconf->{'coursecategories'}{'togglecats'} eq 'crs') {
1.256 raeburn 6207: $settable{'togglecats'} = 1;
6208: }
1.400 raeburn 6209: if ($domconf->{'coursecategories'}{'categorize'} eq 'crs') {
1.256 raeburn 6210: $settable{'categorize'} = 1;
6211: }
1.400 raeburn 6212: $cathash = $domconf->{'coursecategories'}{'cats'};
1.256 raeburn 6213: }
1.260 raeburn 6214: if ($settable{'togglecats'} && $settable{'categorize'}) {
1.256 raeburn 6215: $cansetvis = &mt('You are able to both assign a course category and choose to exclude this course from the catalog.');
6216: } elsif ($settable{'togglecats'}) {
6217: $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 6218: } elsif ($settable{'categorize'}) {
1.256 raeburn 6219: $cansetvis = &mt('You may assign a course category, but only a Domain Coordinator may choose to exclude this course from the catalog.');
6220: } else {
6221: $cansetvis = &mt('Only a Domain Coordinator may assign a course category or choose to exclude this course from the catalog.');
6222: }
6223:
6224: my %currsettings =
6225: &Apache::lonnet::get('environment',['hidefromcat','categories','internal.coursecode'],
6226: $cdom,$cnum);
1.400 raeburn 6227: $visible = 0;
1.256 raeburn 6228: if ($currsettings{'internal.coursecode'} ne '') {
1.400 raeburn 6229: if (ref($domconf->{'coursecategories'}) eq 'HASH') {
6230: $cathash = $domconf->{'coursecategories'}{'cats'};
1.256 raeburn 6231: if (ref($cathash) eq 'HASH') {
6232: if ($cathash->{'instcode::0'} eq '') {
6233: push(@vismsgs,'dc_addinst');
6234: } else {
6235: $visible = 1;
6236: }
6237: } else {
6238: $visible = 1;
6239: }
6240: } else {
6241: $visible = 1;
6242: }
6243: } else {
6244: if (ref($cathash) eq 'HASH') {
6245: if ($cathash->{'instcode::0'} ne '') {
6246: push(@vismsgs,'dc_instcode');
6247: }
6248: } else {
6249: push(@vismsgs,'dc_instcode');
6250: }
6251: }
6252: if ($currsettings{'categories'} ne '') {
6253: my $cathash;
1.400 raeburn 6254: if (ref($domconf->{'coursecategories'}) eq 'HASH') {
6255: $cathash = $domconf->{'coursecategories'}{'cats'};
1.256 raeburn 6256: if (ref($cathash) eq 'HASH') {
6257: if (keys(%{$cathash}) == 0) {
6258: push(@vismsgs,'dc_catalog');
6259: } elsif ((keys(%{$cathash}) == 1) && ($cathash->{'instcode::0'} ne '')) {
6260: push(@vismsgs,'dc_categories');
6261: } else {
6262: my @currcategories = split('&',$currsettings{'categories'});
6263: my $matched = 0;
6264: foreach my $cat (@currcategories) {
6265: if ($cathash->{$cat} ne '') {
6266: $visible = 1;
6267: $matched = 1;
6268: last;
6269: }
6270: }
6271: if (!$matched) {
1.260 raeburn 6272: if ($settable{'categorize'}) {
1.256 raeburn 6273: push(@vismsgs,'chgcat');
6274: } else {
6275: push(@vismsgs,'dc_chgcat');
6276: }
6277: }
6278: }
6279: }
6280: }
6281: } else {
6282: if (ref($cathash) eq 'HASH') {
6283: if ((keys(%{$cathash}) > 1) ||
6284: (keys(%{$cathash}) == 1) && ($cathash->{'instcode::0'} eq '')) {
1.260 raeburn 6285: if ($settable{'categorize'}) {
1.256 raeburn 6286: push(@vismsgs,'addcat');
6287: } else {
6288: push(@vismsgs,'dc_addcat');
6289: }
6290: }
6291: }
6292: }
6293: if ($currsettings{'hidefromcat'} eq 'yes') {
6294: $visible = 0;
6295: if ($settable{'togglecats'}) {
6296: unshift(@vismsgs,'unhide');
6297: } else {
6298: unshift(@vismsgs,'dc_unhide')
6299: }
6300: }
1.400 raeburn 6301: return ($visible,$cansetvis,\@vismsgs);
6302: }
6303:
6304: sub cat_visibility {
6305: my %visactions = &Apache::lonlocal::texthash(
6306: vis => 'This course/community currently appears in the Course/Community Catalog for this domain.',
6307: 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.',
6308: miss => 'This course/community does not currently appear in the Course/Community Catalog for this domain.',
6309: none => 'Display of a course catalog is disabled for this domain.',
6310: yous => 'You should remedy this if you plan to allow self-enrollment, otherwise students will have difficulty finding this course.',
6311: 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.',
6312: make => 'Make any changes to self-enrollment settings below, click "Save", then take action to include the course in the Catalog:',
6313: take => 'Take the following action to ensure the course appears in the Catalog:',
6314: dc_chgconf => 'Ask a domain coordinator to change the Catalog type for this domain.',
6315: dc_setcode => 'Ask a domain coordinator to assign a six character code to the course',
6316: dc_unhide => 'Ask a domain coordinator to change the "Exclude from course catalog" setting.',
6317: dc_addinst => 'Ask a domain coordinator to enable display the catalog of "Official courses (with institutional codes)".',
6318: dc_instcode => 'Ask a domain coordinator to assign an institutional code (if this is an official course).',
6319: dc_catalog => 'Ask a domain coordinator to enable or create at least one course category in the domain.',
6320: dc_categories => 'Ask a domain coordinator to create a hierarchy of categories and sub categories for courses in the domain.',
6321: 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',
6322: dc_addcat => 'Ask a domain coordinator to assign a category to the course.',
6323: );
6324: $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>"');
6325: $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>"');
6326: $visactions{'addcat'} = &mt('Use [_1]Categorize course[_2] to assign a category to the course.','"<a href="/adm/courseprefs?phase=display&actions=courseinfo">','</a>"');
6327: return \%visactions;
1.256 raeburn 6328: }
6329:
1.241 raeburn 6330: sub new_selfenroll_dom_row {
6331: my ($newdom,$num) = @_;
6332: my $domdesc = &Apache::lonnet::domain($newdom);
6333: my $output;
6334: if ($domdesc ne '') {
6335: $output .= &Apache::loncommon::start_data_table_row()
6336: .'<td valign="top"><span class="LC_nobreak">'.&mt('Domain:').' <b>'.$domdesc
6337: .' ('.$newdom.')</b><input type="hidden" name="selfenroll_dom_'.$num
1.249 raeburn 6338: .'" value="'.$newdom.'" /></span><br />'
6339: .'<span class="LC_nobreak"><label><input type="checkbox" '
6340: .'name="selfenroll_activate" value="'.$num.'" '
6341: .'onchange="javascript:update_types('
6342: ."'selfenroll_activate','$num'".');" />'
6343: .&mt('Activate').'</label></span></td>';
1.241 raeburn 6344: my @currinsttypes;
6345: $output .= '<td>'.&mt('User types:').'<br />'
6346: .&selfenroll_inst_types($num,$newdom,\@currinsttypes).'</td>'
6347: .&Apache::loncommon::end_data_table_row();
6348: }
6349: return $output;
6350: }
6351:
6352: sub selfenroll_inst_types {
6353: my ($num,$currdom,$currinsttypes) = @_;
6354: my $output;
6355: my $numinrow = 4;
6356: my $count = 0;
6357: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($currdom);
1.247 raeburn 6358: my $othervalue = 'any';
1.241 raeburn 6359: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
1.251 raeburn 6360: if (keys(%{$usertypes}) > 0) {
1.247 raeburn 6361: $othervalue = 'other';
6362: }
1.241 raeburn 6363: $output .= '<table><tr>';
6364: foreach my $type (@{$types}) {
6365: if (($count > 0) && ($count%$numinrow == 0)) {
6366: $output .= '</tr><tr>';
6367: }
6368: if (defined($usertypes->{$type})) {
1.257 raeburn 6369: my $esc_type = &escape($type);
1.241 raeburn 6370: $output .= '<td><span class="LC_nobreak"><label><input type = "checkbox" value="'.
1.257 raeburn 6371: $esc_type.'" ';
1.241 raeburn 6372: if (ref($currinsttypes) eq 'ARRAY') {
6373: if (@{$currinsttypes} > 0) {
1.249 raeburn 6374: if (grep(/^any$/,@{$currinsttypes})) {
6375: $output .= 'checked="checked"';
1.257 raeburn 6376: } elsif (grep(/^\Q$esc_type\E$/,@{$currinsttypes})) {
1.241 raeburn 6377: $output .= 'checked="checked"';
6378: }
1.249 raeburn 6379: } else {
6380: $output .= 'checked="checked"';
1.241 raeburn 6381: }
6382: }
6383: $output .= ' name="selfenroll_types_'.$num.'" />'.$usertypes->{$type}.'</label></span></td>';
6384: }
6385: $count ++;
6386: }
6387: if (($count > 0) && ($count%$numinrow == 0)) {
6388: $output .= '</tr><tr>';
6389: }
1.249 raeburn 6390: $output .= '<td><span class="LC_nobreak"><label><input type = "checkbox" value="'.$othervalue.'"';
1.241 raeburn 6391: if (ref($currinsttypes) eq 'ARRAY') {
6392: if (@{$currinsttypes} > 0) {
1.249 raeburn 6393: if (grep(/^any$/,@{$currinsttypes})) {
6394: $output .= ' checked="checked"';
6395: } elsif ($othervalue eq 'other') {
6396: if (grep(/^\Q$othervalue\E$/,@{$currinsttypes})) {
6397: $output .= ' checked="checked"';
6398: }
1.241 raeburn 6399: }
1.249 raeburn 6400: } else {
6401: $output .= ' checked="checked"';
1.241 raeburn 6402: }
1.249 raeburn 6403: } else {
6404: $output .= ' checked="checked"';
1.241 raeburn 6405: }
6406: $output .= ' name="selfenroll_types_'.$num.'" />'.$othertitle.'</label></span></td></tr></table>';
6407: }
6408: return $output;
6409: }
6410:
1.237 raeburn 6411: sub selfenroll_date_forms {
6412: my ($startform,$endform) = @_;
6413: my $output .= &Apache::lonhtmlcommon::start_pick_box()."\n".
1.244 bisitz 6414: &Apache::lonhtmlcommon::row_title(&mt('Start date'),
1.237 raeburn 6415: 'LC_oddrow_value')."\n".
6416: $startform."\n".
6417: &Apache::lonhtmlcommon::row_closure(1).
1.244 bisitz 6418: &Apache::lonhtmlcommon::row_title(&mt('End date'),
1.237 raeburn 6419: 'LC_oddrow_value')."\n".
6420: $endform."\n".
6421: &Apache::lonhtmlcommon::row_closure(1).
6422: &Apache::lonhtmlcommon::end_pick_box();
6423: return $output;
6424: }
6425:
1.239 raeburn 6426: sub print_userchangelogs_display {
1.415 raeburn 6427: my ($r,$context,$permission,$brcrum) = @_;
1.363 raeburn 6428: my $formname = 'rolelog';
6429: my ($username,$domain,$crstype,%roleslog);
6430: if ($context eq 'domain') {
6431: $domain = $env{'request.role.domain'};
6432: %roleslog=&Apache::lonnet::dump_dom('nohist_rolelog',$domain);
6433: } else {
6434: if ($context eq 'course') {
6435: $domain = $env{'course.'.$env{'request.course.id'}.'.domain'};
6436: $username = $env{'course.'.$env{'request.course.id'}.'.num'};
6437: $crstype = &Apache::loncommon::course_type();
6438: my %saveable_parameters = ('show' => 'scalar',);
6439: &Apache::loncommon::store_course_settings('roles_log',
6440: \%saveable_parameters);
6441: &Apache::loncommon::restore_course_settings('roles_log',
6442: \%saveable_parameters);
6443: } elsif ($context eq 'author') {
6444: $domain = $env{'user.domain'};
6445: if ($env{'request.role'} =~ m{^au\./\Q$domain\E/$}) {
6446: $username = $env{'user.name'};
6447: } else {
6448: undef($domain);
6449: }
6450: }
6451: if ($domain ne '' && $username ne '') {
6452: %roleslog=&Apache::lonnet::dump('nohist_rolelog',$domain,$username);
6453: }
6454: }
1.239 raeburn 6455: if ((keys(%roleslog))[0]=~/^error\:/) { undef(%roleslog); }
6456:
1.415 raeburn 6457: my $helpitem;
6458: if ($context eq 'course') {
6459: $helpitem = 'Course_User_Logs';
6460: }
6461: push (@{$brcrum},
6462: {href => '/adm/createuser?action=changelogs',
6463: text => 'User Management Logs',
6464: help => $helpitem});
6465: my $bread_crumbs_component = 'User Changes';
6466: my $args = { bread_crumbs => $brcrum,
6467: bread_crumbs_component => $bread_crumbs_component};
6468:
6469: # Create navigation javascript
6470: my $jsnav = &userlogdisplay_js($formname);
6471:
6472: my $jscript = (<<ENDSCRIPT);
6473: <script type="text/javascript">
6474: // <![CDATA[
6475: $jsnav
6476: // ]]>
6477: </script>
6478: ENDSCRIPT
6479:
6480: # print page header
6481: $r->print(&header($jscript,$args));
6482:
1.239 raeburn 6483: # set defaults
6484: my $now = time();
6485: my $defstart = $now - (7*24*3600); #7 days ago
6486: my %defaults = (
6487: page => '1',
6488: show => '10',
6489: role => 'any',
6490: chgcontext => 'any',
6491: rolelog_start_date => $defstart,
6492: rolelog_end_date => $now,
6493: );
6494: my $more_records = 0;
6495:
6496: # set current
6497: my %curr;
6498: foreach my $item ('show','page','role','chgcontext') {
6499: $curr{$item} = $env{'form.'.$item};
6500: }
6501: my ($startdate,$enddate) =
6502: &Apache::lonuserutils::get_dates_from_form('rolelog_start_date','rolelog_end_date');
6503: $curr{'rolelog_start_date'} = $startdate;
6504: $curr{'rolelog_end_date'} = $enddate;
6505: foreach my $key (keys(%defaults)) {
6506: if ($curr{$key} eq '') {
6507: $curr{$key} = $defaults{$key};
6508: }
6509: }
1.248 raeburn 6510: my (%whodunit,%changed,$version);
6511: ($version) = ($r->dir_config('lonVersion') =~ /^([\d\.]+)\-/);
1.239 raeburn 6512: my ($minshown,$maxshown);
1.255 raeburn 6513: $minshown = 1;
1.239 raeburn 6514: my $count = 0;
1.415 raeburn 6515: if ($curr{'show'} =~ /\D/) {
6516: $curr{'page'} = 1;
6517: } else {
1.239 raeburn 6518: $maxshown = $curr{'page'} * $curr{'show'};
6519: if ($curr{'page'} > 1) {
6520: $minshown = 1 + ($curr{'page'} - 1) * $curr{'show'};
6521: }
6522: }
1.301 bisitz 6523:
1.327 raeburn 6524: # Form Header
6525: $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">'.
1.363 raeburn 6526: &role_display_filter($context,$formname,$domain,$username,\%curr,
6527: $version,$crstype));
1.327 raeburn 6528:
6529: my $showntableheader = 0;
6530:
6531: # Table Header
6532: my $tableheader =
6533: &Apache::loncommon::start_data_table_header_row()
6534: .'<th> </th>'
6535: .'<th>'.&mt('When').'</th>'
6536: .'<th>'.&mt('Who made the change').'</th>'
6537: .'<th>'.&mt('Changed User').'</th>'
1.363 raeburn 6538: .'<th>'.&mt('Role').'</th>';
6539:
6540: if ($context eq 'course') {
6541: $tableheader .= '<th>'.&mt('Section').'</th>';
6542: }
6543: $tableheader .=
6544: '<th>'.&mt('Context').'</th>'
1.327 raeburn 6545: .'<th>'.&mt('Start').'</th>'
6546: .'<th>'.&mt('End').'</th>'
6547: .&Apache::loncommon::end_data_table_header_row();
6548:
6549: # Display user change log data
1.239 raeburn 6550: foreach my $id (sort { $roleslog{$b}{'exe_time'}<=>$roleslog{$a}{'exe_time'} } (keys(%roleslog))) {
6551: next if (($roleslog{$id}{'exe_time'} < $curr{'rolelog_start_date'}) ||
6552: ($roleslog{$id}{'exe_time'} > $curr{'rolelog_end_date'}));
1.415 raeburn 6553: if ($curr{'show'} !~ /\D/) {
1.239 raeburn 6554: if ($count >= $curr{'page'} * $curr{'show'}) {
6555: $more_records = 1;
6556: last;
6557: }
6558: }
6559: if ($curr{'role'} ne 'any') {
6560: next if ($roleslog{$id}{'logentry'}{'role'} ne $curr{'role'});
6561: }
6562: if ($curr{'chgcontext'} ne 'any') {
6563: if ($curr{'chgcontext'} eq 'selfenroll') {
6564: next if (!$roleslog{$id}{'logentry'}{'selfenroll'});
6565: } else {
6566: next if ($roleslog{$id}{'logentry'}{'context'} ne $curr{'chgcontext'});
6567: }
6568: }
6569: $count ++;
6570: next if ($count < $minshown);
1.327 raeburn 6571: unless ($showntableheader) {
1.415 raeburn 6572: $r->print(&Apache::loncommon::start_data_table()
1.327 raeburn 6573: .$tableheader);
6574: $r->rflush();
6575: $showntableheader = 1;
6576: }
1.239 raeburn 6577: if ($whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}} eq '') {
6578: $whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}} =
6579: &Apache::loncommon::plainname($roleslog{$id}{'exe_uname'},$roleslog{$id}{'exe_udom'});
6580: }
6581: if ($changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}} eq '') {
6582: $changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}} =
6583: &Apache::loncommon::plainname($roleslog{$id}{'uname'},$roleslog{$id}{'udom'});
6584: }
6585: my $sec = $roleslog{$id}{'logentry'}{'section'};
6586: if ($sec eq '') {
6587: $sec = &mt('None');
6588: }
6589: my ($rolestart,$roleend);
6590: if ($roleslog{$id}{'delflag'}) {
6591: $rolestart = &mt('deleted');
6592: $roleend = &mt('deleted');
6593: } else {
6594: $rolestart = $roleslog{$id}{'logentry'}{'start'};
6595: $roleend = $roleslog{$id}{'logentry'}{'end'};
6596: if ($rolestart eq '' || $rolestart == 0) {
6597: $rolestart = &mt('No start date');
6598: } else {
6599: $rolestart = &Apache::lonlocal::locallocaltime($rolestart);
6600: }
6601: if ($roleend eq '' || $roleend == 0) {
6602: $roleend = &mt('No end date');
6603: } else {
6604: $roleend = &Apache::lonlocal::locallocaltime($roleend);
6605: }
6606: }
6607: my $chgcontext = $roleslog{$id}{'logentry'}{'context'};
6608: if ($roleslog{$id}{'logentry'}{'selfenroll'}) {
6609: $chgcontext = 'selfenroll';
6610: }
1.363 raeburn 6611: my %lt = &rolechg_contexts($context,$crstype);
1.239 raeburn 6612: if ($chgcontext ne '' && $lt{$chgcontext} ne '') {
6613: $chgcontext = $lt{$chgcontext};
6614: }
1.327 raeburn 6615: $r->print(
1.301 bisitz 6616: &Apache::loncommon::start_data_table_row()
6617: .'<td>'.$count.'</td>'
6618: .'<td>'.&Apache::lonlocal::locallocaltime($roleslog{$id}{'exe_time'}).'</td>'
6619: .'<td>'.$whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}}.'</td>'
6620: .'<td>'.$changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}}.'</td>'
1.363 raeburn 6621: .'<td>'.&Apache::lonnet::plaintext($roleslog{$id}{'logentry'}{'role'},$crstype).'</td>');
6622: if ($context eq 'course') {
6623: $r->print('<td>'.$sec.'</td>');
6624: }
6625: $r->print(
6626: '<td>'.$chgcontext.'</td>'
1.301 bisitz 6627: .'<td>'.$rolestart.'</td>'
6628: .'<td>'.$roleend.'</td>'
1.327 raeburn 6629: .&Apache::loncommon::end_data_table_row()."\n");
1.301 bisitz 6630: }
6631:
1.327 raeburn 6632: if ($showntableheader) { # Table footer, if content displayed above
1.415 raeburn 6633: $r->print(&Apache::loncommon::end_data_table().
6634: &userlogdisplay_navlinks(\%curr,$more_records));
1.327 raeburn 6635: } else { # No content displayed above
1.301 bisitz 6636: $r->print('<p class="LC_info">'
6637: .&mt('There are no records to display.')
6638: .'</p>'
6639: );
1.239 raeburn 6640: }
1.301 bisitz 6641:
1.327 raeburn 6642: # Form Footer
6643: $r->print(
6644: '<input type="hidden" name="page" value="'.$curr{'page'}.'" />'
6645: .'<input type="hidden" name="action" value="changelogs" />'
6646: .'</form>');
6647: return;
6648: }
1.301 bisitz 6649:
1.416 ! raeburn 6650: sub print_useraccesslogs_display {
! 6651: my ($r,$uname,$udom,$permission,$brcrum) = @_;
! 6652: my $formname = 'accesslog';
! 6653: my $form = 'document.accesslog';
! 6654:
! 6655: # set breadcrumbs
! 6656: my %breadcrumb_text = &singleuser_breadcrumb();
! 6657: push (@{$brcrum},
! 6658: {href => "javascript:backPage($form)",
! 6659: text => $breadcrumb_text{'search'}});
! 6660: my (@prevphases,$prevphasestr);
! 6661: if ($env{'form.prevphases'}) {
! 6662: @prevphases = split(/,/,$env{'form.prevphases'});
! 6663: $prevphasestr = $env{'form.prevphases'};
! 6664: }
! 6665: if (($env{'form.phase'} eq 'userpicked') || (grep(/^userpicked$/,@prevphases))) {
! 6666: push(@{$brcrum},
! 6667: {href => "javascript:backPage($form,'get_user_info','select')",
! 6668: text => $breadcrumb_text{'userpicked'}});
! 6669: if ($env{'form.phase'} eq 'userpicked') {
! 6670: $prevphasestr = 'userpicked';
! 6671: }
! 6672: }
! 6673: push(@{$brcrum},
! 6674: {href => '/adm/createuser?action=accesslogs',
! 6675: text => 'User access logs',
! 6676: help => 'User_Access_Logs'});
! 6677: my $bread_crumbs_component = 'User Access Logs';
! 6678: my $args = { bread_crumbs => $brcrum,
! 6679: bread_crumbs_component => 'User Management'};
! 6680:
! 6681: # set javascript
! 6682: my ($jsback,$elements) = &crumb_utilities();
! 6683: my $jsnav = &userlogdisplay_js($formname);
! 6684:
! 6685: my $jscript = (<<ENDSCRIPT);
! 6686: <script type="text/javascript">
! 6687: // <![CDATA[
! 6688:
! 6689: $jsback
! 6690: $jsnav
! 6691:
! 6692: // ]]>
! 6693: </script>
! 6694:
! 6695: ENDSCRIPT
! 6696:
! 6697: # print page header
! 6698: $r->print(&header($jscript,$args));
! 6699:
! 6700: # early out unless log data can be displayed.
! 6701: unless ($permission->{'activity'}) {
! 6702: $r->print('<p class="LC_warning">'
! 6703: .&mt('You do not have rights to display user access logs.')
! 6704: .'</p>'
! 6705: .&earlyout_accesslog_form($formname,$prevphasestr,$udom));
! 6706: return;
! 6707: }
! 6708:
! 6709: unless ($udom eq $env{'request.role.domain'}) {
! 6710: $r->print('<p class="LC_warning">'
! 6711: .&mt("User's domain must match role's domain")
! 6712: .'</p>'
! 6713: .&earlyout_accesslog_form($formname,$prevphasestr,$udom));
! 6714: return;
! 6715: }
! 6716:
! 6717: if (($uname eq '') || ($udom eq '')) {
! 6718: $r->print('<p class="LC_warning">'
! 6719: .&mt('Invalid username or domain')
! 6720: .'</p>'
! 6721: .&earlyout_accesslog_form($formname,$prevphasestr,$udom));
! 6722: return;
! 6723: }
! 6724:
! 6725: # set defaults
! 6726: my $now = time();
! 6727: my $defstart = $now - (7*24*3600);
! 6728: my %defaults = (
! 6729: page => '1',
! 6730: show => '10',
! 6731: activity => 'any',
! 6732: accesslog_start_date => $defstart,
! 6733: accesslog_end_date => $now,
! 6734: );
! 6735: my $more_records = 0;
! 6736:
! 6737: # set current
! 6738: my %curr;
! 6739: foreach my $item ('show','page','activity') {
! 6740: $curr{$item} = $env{'form.'.$item};
! 6741: }
! 6742: my ($startdate,$enddate) =
! 6743: &Apache::lonuserutils::get_dates_from_form('accesslog_start_date','accesslog_end_date');
! 6744: $curr{'accesslog_start_date'} = $startdate;
! 6745: $curr{'accesslog_end_date'} = $enddate;
! 6746: foreach my $key (keys(%defaults)) {
! 6747: if ($curr{$key} eq '') {
! 6748: $curr{$key} = $defaults{$key};
! 6749: }
! 6750: }
! 6751: my ($minshown,$maxshown);
! 6752: $minshown = 1;
! 6753: my $count = 0;
! 6754: if ($curr{'show'} =~ /\D/) {
! 6755: $curr{'page'} = 1;
! 6756: } else {
! 6757: $maxshown = $curr{'page'} * $curr{'show'};
! 6758: if ($curr{'page'} > 1) {
! 6759: $minshown = 1 + ($curr{'page'} - 1) * $curr{'show'};
! 6760: }
! 6761: }
! 6762:
! 6763: # form header
! 6764: $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">'.
! 6765: &activity_display_filter($formname,\%curr));
! 6766:
! 6767: my $showntableheader = 0;
! 6768: my ($nav_script,$nav_links);
! 6769:
! 6770: # table header
! 6771: my $tableheader =
! 6772: &Apache::loncommon::start_data_table_header_row()
! 6773: .'<th> </th>'
! 6774: .'<th>'.&mt('When').'</th>'
! 6775: .'<th>'.&mt('HostID').'</th>'
! 6776: .'<th>'.&mt('Event').'</th>'
! 6777: .'<th>'.&mt('Other data').'</th>'
! 6778: .&Apache::loncommon::end_data_table_header_row();
! 6779:
! 6780: my %filters=(
! 6781: start => $curr{'accesslog_start_date'},
! 6782: end => $curr{'accesslog_end_date'},
! 6783: action => $curr{'activity'},
! 6784: );
! 6785:
! 6786: my $reply = &Apache::lonnet::userlog_query($uname,$udom,%filters);
! 6787: unless ( ($reply =~/^timeout/) || ($reply =~/^error/) ) {
! 6788: my (%courses,%missing);
! 6789: my @results = split(/\&/,$reply);
! 6790: foreach my $item (reverse(@results)) {
! 6791: my ($timestamp,$host,$event) = split(/:/,$item);
! 6792: next unless ($event =~ /^(Log|Role)/);
! 6793: if ($curr{'show'} !~ /\D/) {
! 6794: if ($count >= $curr{'page'} * $curr{'show'}) {
! 6795: $more_records = 1;
! 6796: last;
! 6797: }
! 6798: }
! 6799: $count ++;
! 6800: next if ($count < $minshown);
! 6801: unless ($showntableheader) {
! 6802: $r->print($nav_script
! 6803: .&Apache::loncommon::start_data_table()
! 6804: .$tableheader);
! 6805: $r->rflush();
! 6806: $showntableheader = 1;
! 6807: }
! 6808: my ($shown,$extra,);
! 6809: my ($event,$data) = split(/\s+/,&unescape($event));
! 6810: if ($event eq 'Role') {
! 6811: my ($rolecode,$extent) = split(/\./,$data,2);
! 6812: next if ($extent eq '');
! 6813: my ($crstype,$desc,$info);
! 6814: if ($extent =~ m{^/($match_domain)/($match_courseid)$}) {
! 6815: my ($cdom,$cnum) = ($1,$2);
! 6816: my $cid = $cdom.'_'.$cnum;
! 6817: if (exists($courses{$cid})) {
! 6818: $crstype = $courses{$cid}{'type'};
! 6819: $desc = $courses{$cid}{'description'};
! 6820: } elsif ($missing{$cid}) {
! 6821: $crstype = 'Course';
! 6822: $desc = 'Course/Community';
! 6823: } else {
! 6824: my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',$cnum,undef,undef,'.');
! 6825: if (ref($crsinfo{$cdom.'_'.$cnum}) eq 'HASH') {
! 6826: $courses{$cid} = $crsinfo{$cid};
! 6827: $crstype = $crsinfo{$cid}{'type'};
! 6828: $desc = $crsinfo{$cid}{'description'};
! 6829: } else {
! 6830: $missing{$cid} = 1;
! 6831: }
! 6832: }
! 6833: $extra = &mt($crstype).': <a href="/public/'.$cdom.'/'.$cnum.'/syllabus">'.$desc.'</a>';
! 6834: } elsif ($extent =~ m{^/($match_domain)/($match_username|$)}) {
! 6835: my ($dom,$name) = ($1,$2);
! 6836: if ($rolecode eq 'au') {
! 6837: $extra = '';
! 6838: } elsif ($rolecode =~ /^(ca|aa)$/) {
! 6839: $extra = &mt('Authoring Space: [_1]',$name.':'.$dom);
! 6840: } elsif ($rolecode =~ /^(li|dg|dh|dc|sc)$/) {
! 6841: $extra = &mt('Domain: [_1]',$dom);
! 6842: }
! 6843: }
! 6844: my $rolename;
! 6845: if ($rolecode =~ m{^cr/($match_domain)/($match_username)/(\w+)}) {
! 6846: my $role = $3;
! 6847: my $owner = "($2:$1)";
! 6848: if ($2 eq $1.'-domainconfig') {
! 6849: $owner = '(ad hoc)';
! 6850: }
! 6851: $rolename = &mt('Custom role: [_1]',$role.' '.$owner);
! 6852: } else {
! 6853: $rolename = &Apache::lonnet::plaintext($rolecode,$crstype);
! 6854: }
! 6855: $shown = &mt('Role selection: [_1]',$rolename);
! 6856: } else {
! 6857: $shown = &mt($event);
! 6858: if ($data ne '') {
! 6859: $extra = &mt('Client IP address: [_1]',$data);
! 6860: }
! 6861: }
! 6862: $r->print(
! 6863: &Apache::loncommon::start_data_table_row()
! 6864: .'<td>'.$count.'</td>'
! 6865: .'<td>'.&Apache::lonlocal::locallocaltime($timestamp).'</td>'
! 6866: .'<td>'.$host.'</td>'
! 6867: .'<td>'.$shown.'</td>'
! 6868: .'<td>'.$extra.'</td>'
! 6869: .&Apache::loncommon::end_data_table_row()."\n");
! 6870: }
! 6871: }
! 6872:
! 6873: if ($showntableheader) { # Table footer, if content displayed above
! 6874: $r->print(&Apache::loncommon::end_data_table().
! 6875: &userlogdisplay_navlinks(\%curr,$more_records));
! 6876: } else { # No content displayed above
! 6877: $r->print('<p class="LC_info">'
! 6878: .&mt('There are no records to display.')
! 6879: .'</p>');
! 6880: }
! 6881:
! 6882: # Form Footer
! 6883: $r->print(
! 6884: '<input type="hidden" name="currstate" value="" />'
! 6885: .'<input type="hidden" name="accessuname" value="'.$uname.'" />'
! 6886: .'<input type="hidden" name="accessudom" value="'.$udom.'" />'
! 6887: .'<input type="hidden" name="page" value="'.$curr{'page'}.'" />'
! 6888: .'<input type="hidden" name="prevphases" value="'.$prevphasestr.'" />'
! 6889: .'<input type="hidden" name="phase" value="activity" />'
! 6890: .'<input type="hidden" name="action" value="accesslogs" />'
! 6891: .'<input type="hidden" name="srchdomain" value="'.$udom.'" />'
! 6892: .'<input type="hidden" name="srchby" value="'.$env{'form.srchby'}.'" />'
! 6893: .'<input type="hidden" name="srchtype" value="'.$env{'form.srchtype'}.'" />'
! 6894: .'<input type="hidden" name="srchterm" value="'.&HTML::Entities::encode($env{'form.srchterm'},'<>"&').'" />'
! 6895: .'<input type="hidden" name="srchin" value="'.$env{'form.srchin'}.'" />'
! 6896: .'</form>');
! 6897: return;
! 6898: }
! 6899:
! 6900: sub earlyout_accesslog_form {
! 6901: my ($formname,$prevphasestr,$udom) = @_;
! 6902: my $srchterm = &HTML::Entities::encode($env{'form.srchterm'},'<>"&');
! 6903: return <<"END";
! 6904: <form action="/adm/createuser" method="post" name="$formname">
! 6905: <input type="hidden" name="currstate" value="" />
! 6906: <input type="hidden" name="prevphases" value="$prevphasestr" />
! 6907: <input type="hidden" name="phase" value="activity" />
! 6908: <input type="hidden" name="action" value="accesslogs" />
! 6909: <input type="hidden" name="srchdomain" value="$udom" />
! 6910: <input type="hidden" name="srchby" value="$env{'form.srchby'}" />
! 6911: <input type="hidden" name="srchtype" value="$env{'form.srchtype'}" />
! 6912: <input type="hidden" name="srchterm" value="$srchterm" />
! 6913: <input type="hidden" name="srchin" value="$env{'form.srchin'}" />
! 6914: </form>
! 6915: END
! 6916: }
! 6917:
! 6918: sub activity_display_filter {
! 6919: my ($formname,$curr) = @_;
! 6920: my $nolink = 1;
! 6921: my $output = '<table><tr><td valign="top">'.
! 6922: '<span class="LC_nobreak"><b>'.&mt('Actions/page:').'</b></span><br />'.
! 6923: &Apache::lonmeta::selectbox('show',$curr->{'show'},undef,
! 6924: (&mt('all'),5,10,20,50,100,1000,10000)).
! 6925: '</td><td> </td>';
! 6926: my $startform =
! 6927: &Apache::lonhtmlcommon::date_setter($formname,'accesslog_start_date',
! 6928: $curr->{'accesslog_start_date'},undef,
! 6929: undef,undef,undef,undef,undef,undef,$nolink);
! 6930: my $endform =
! 6931: &Apache::lonhtmlcommon::date_setter($formname,'accesslog_end_date',
! 6932: $curr->{'accesslog_end_date'},undef,
! 6933: undef,undef,undef,undef,undef,undef,$nolink);
! 6934: my %lt = &Apache::lonlocal::texthash (
! 6935: activity => 'Activity',
! 6936: Role => 'Role selection',
! 6937: log => 'Log-in or Logout',
! 6938: );
! 6939: $output .= '<td valign="top"><b>'.&mt('Window during which actions occurred:').'</b><br />'.
! 6940: '<table><tr><td>'.&mt('After:').
! 6941: '</td><td>'.$startform.'</td></tr>'.
! 6942: '<tr><td>'.&mt('Before:').'</td>'.
! 6943: '<td>'.$endform.'</td></tr></table>'.
! 6944: '</td>'.
! 6945: '<td> </td>'.
! 6946: '<td valign="top"><b>'.&mt('Activities').'</b><br />'.
! 6947: '<select name="activity"><option value="any"';
! 6948: if ($curr->{'activity'} eq 'any') {
! 6949: $output .= ' selected="selected"';
! 6950: }
! 6951: $output .= '>'.&mt('Any').'</option>'."\n";
! 6952: foreach my $activity ('Role','log') {
! 6953: my $selstr = '';
! 6954: if ($activity eq $curr->{'activity'}) {
! 6955: $selstr = ' selected="selected"';
! 6956: }
! 6957: $output .= '<option value="'.$activity.'"'.$selstr.'>'.$lt{$activity}.'</option>';
! 6958: }
! 6959: $output .= '</select></td>'.
! 6960: '</tr></table>';
! 6961: # Update Display button
! 6962: $output .= '<p>'
! 6963: .'<input type="submit" value="'.&mt('Update Display').'" />'
! 6964: .'</p>';
! 6965: return $output;
! 6966: }
! 6967:
1.415 raeburn 6968: sub userlogdisplay_js {
6969: my ($formname) = @_;
6970: return <<"ENDSCRIPT";
6971:
1.239 raeburn 6972: function chgPage(caller) {
6973: if (caller == 'previous') {
6974: document.$formname.page.value --;
6975: }
6976: if (caller == 'next') {
6977: document.$formname.page.value ++;
6978: }
1.327 raeburn 6979: document.$formname.submit();
1.239 raeburn 6980: return;
6981: }
6982: ENDSCRIPT
1.415 raeburn 6983: }
6984:
6985: sub userlogdisplay_navlinks {
6986: my ($curr,$more_records) = @_;
6987: return unless(ref($curr) eq 'HASH');
6988: # Navigation Buttons
6989: my $nav_links = '<p>';
6990: if (($curr->{'page'} > 1) || ($more_records)) {
6991: if (($curr->{'page'} > 1) && ($curr->{'show'} !~ /\D/)) {
6992: $nav_links .= '<input type="button"'
6993: .' onclick="javascript:chgPage('."'previous'".');"'
6994: .' value="'.&mt('Previous [_1] changes',$curr->{'show'})
6995: .'" /> ';
6996: }
6997: if ($more_records) {
6998: $nav_links .= '<input type="button"'
6999: .' onclick="javascript:chgPage('."'next'".');"'
7000: .' value="'.&mt('Next [_1] changes',$curr->{'show'})
7001: .'" />';
1.301 bisitz 7002: }
7003: }
1.415 raeburn 7004: $nav_links .= '</p>';
7005: return $nav_links;
1.239 raeburn 7006: }
7007:
7008: sub role_display_filter {
1.363 raeburn 7009: my ($context,$formname,$cdom,$cnum,$curr,$version,$crstype) = @_;
7010: my $lctype;
7011: if ($context eq 'course') {
7012: $lctype = lc($crstype);
7013: }
1.239 raeburn 7014: my $nolink = 1;
7015: my $output = '<table><tr><td valign="top">'.
1.301 bisitz 7016: '<span class="LC_nobreak"><b>'.&mt('Changes/page:').'</b></span><br />'.
1.239 raeburn 7017: &Apache::lonmeta::selectbox('show',$curr->{'show'},undef,
7018: (&mt('all'),5,10,20,50,100,1000,10000)).
7019: '</td><td> </td>';
7020: my $startform =
7021: &Apache::lonhtmlcommon::date_setter($formname,'rolelog_start_date',
7022: $curr->{'rolelog_start_date'},undef,
7023: undef,undef,undef,undef,undef,undef,$nolink);
7024: my $endform =
7025: &Apache::lonhtmlcommon::date_setter($formname,'rolelog_end_date',
7026: $curr->{'rolelog_end_date'},undef,
7027: undef,undef,undef,undef,undef,undef,$nolink);
1.363 raeburn 7028: my %lt = &rolechg_contexts($context,$crstype);
1.301 bisitz 7029: $output .= '<td valign="top"><b>'.&mt('Window during which changes occurred:').'</b><br />'.
7030: '<table><tr><td>'.&mt('After:').
7031: '</td><td>'.$startform.'</td></tr>'.
7032: '<tr><td>'.&mt('Before:').'</td>'.
7033: '<td>'.$endform.'</td></tr></table>'.
7034: '</td>'.
7035: '<td> </td>'.
1.239 raeburn 7036: '<td valign="top"><b>'.&mt('Role:').'</b><br />'.
7037: '<select name="role"><option value="any"';
7038: if ($curr->{'role'} eq 'any') {
7039: $output .= ' selected="selected"';
7040: }
7041: $output .= '>'.&mt('Any').'</option>'."\n";
1.363 raeburn 7042: my @roles = &Apache::lonuserutils::roles_by_context($context,1,$crstype);
1.239 raeburn 7043: foreach my $role (@roles) {
7044: my $plrole;
7045: if ($role eq 'cr') {
7046: $plrole = &mt('Custom Role');
7047: } else {
1.318 raeburn 7048: $plrole=&Apache::lonnet::plaintext($role,$crstype);
1.239 raeburn 7049: }
7050: my $selstr = '';
7051: if ($role eq $curr->{'role'}) {
7052: $selstr = ' selected="selected"';
7053: }
7054: $output .= ' <option value="'.$role.'"'.$selstr.'>'.$plrole.'</option>';
7055: }
1.301 bisitz 7056: $output .= '</select></td>'.
7057: '<td> </td>'.
7058: '<td valign="top"><b>'.
1.239 raeburn 7059: &mt('Context:').'</b><br /><select name="chgcontext">';
1.363 raeburn 7060: my @posscontexts;
7061: if ($context eq 'course') {
1.376 raeburn 7062: @posscontexts = ('any','automated','updatenow','createcourse','course','domain','selfenroll','requestcourses');
1.363 raeburn 7063: } elsif ($context eq 'domain') {
7064: @posscontexts = ('any','domain','requestauthor','domconfig','server');
7065: } else {
7066: @posscontexts = ('any','author','domain');
7067: }
7068: foreach my $chgtype (@posscontexts) {
1.239 raeburn 7069: my $selstr = '';
7070: if ($curr->{'chgcontext'} eq $chgtype) {
1.301 bisitz 7071: $selstr = ' selected="selected"';
1.239 raeburn 7072: }
1.363 raeburn 7073: if ($context eq 'course') {
1.376 raeburn 7074: if (($chgtype eq 'automated') || ($chgtype eq 'updatenow')) {
1.363 raeburn 7075: next if (!&Apache::lonnet::auto_run($cnum,$cdom));
7076: }
1.239 raeburn 7077: }
7078: $output .= '<option value="'.$chgtype.'"'.$selstr.'>'.$lt{$chgtype}.'</option>'."\n";
1.248 raeburn 7079: }
1.303 bisitz 7080: $output .= '</select></td>'
7081: .'</tr></table>';
7082:
7083: # Update Display button
7084: $output .= '<p>'
7085: .'<input type="submit" value="'.&mt('Update Display').'" />'
7086: .'</p>';
7087:
7088: # Server version info
1.363 raeburn 7089: my $needsrev = '2.11.0';
7090: if ($context eq 'course') {
7091: $needsrev = '2.7.0';
7092: }
7093:
1.303 bisitz 7094: $output .= '<p class="LC_info">'
7095: .&mt('Only changes made from servers running LON-CAPA [_1] or later are displayed.'
1.363 raeburn 7096: ,$needsrev);
1.248 raeburn 7097: if ($version) {
1.303 bisitz 7098: $output .= ' '.&mt('This LON-CAPA server is version [_1]',$version);
7099: }
7100: $output .= '</p><hr />';
1.239 raeburn 7101: return $output;
7102: }
7103:
7104: sub rolechg_contexts {
1.363 raeburn 7105: my ($context,$crstype) = @_;
7106: my %lt;
7107: if ($context eq 'course') {
7108: %lt = &Apache::lonlocal::texthash (
1.239 raeburn 7109: any => 'Any',
1.376 raeburn 7110: automated => 'Automated Enrollment',
1.239 raeburn 7111: updatenow => 'Roster Update',
7112: createcourse => 'Course Creation',
7113: course => 'User Management in course',
7114: domain => 'User Management in domain',
1.313 raeburn 7115: selfenroll => 'Self-enrolled',
1.318 raeburn 7116: requestcourses => 'Course Request',
1.239 raeburn 7117: );
1.363 raeburn 7118: if ($crstype eq 'Community') {
7119: $lt{'createcourse'} = &mt('Community Creation');
7120: $lt{'course'} = &mt('User Management in community');
7121: $lt{'requestcourses'} = &mt('Community Request');
7122: }
7123: } elsif ($context eq 'domain') {
7124: %lt = &Apache::lonlocal::texthash (
7125: any => 'Any',
7126: domain => 'User Management in domain',
7127: requestauthor => 'Authoring Request',
7128: server => 'Command line script (DC role)',
7129: domconfig => 'Self-enrolled',
7130: );
7131: } else {
7132: %lt = &Apache::lonlocal::texthash (
7133: any => 'Any',
7134: domain => 'User Management in domain',
7135: author => 'User Management by author',
7136: );
7137: }
1.239 raeburn 7138: return %lt;
7139: }
7140:
1.27 matthew 7141: #-------------------------------------------------- functions for &phase_two
1.160 raeburn 7142: sub user_search_result {
1.221 raeburn 7143: my ($context,$srch) = @_;
1.160 raeburn 7144: my %allhomes;
7145: my %inst_matches;
7146: my %srch_results;
1.181 raeburn 7147: my ($response,$currstate,$forcenewuser,$dirsrchres);
1.183 raeburn 7148: $srch->{'srchterm'} =~ s/\s+/ /g;
1.176 raeburn 7149: if ($srch->{'srchby'} !~ /^(uname|lastname|lastfirst)$/) {
1.160 raeburn 7150: $response = &mt('Invalid search.');
7151: }
7152: if ($srch->{'srchin'} !~ /^(crs|dom|alc|instd)$/) {
7153: $response = &mt('Invalid search.');
7154: }
1.177 raeburn 7155: if ($srch->{'srchtype'} !~ /^(exact|contains|begins)$/) {
1.160 raeburn 7156: $response = &mt('Invalid search.');
7157: }
7158: if ($srch->{'srchterm'} eq '') {
7159: $response = &mt('You must enter a search term.');
7160: }
1.183 raeburn 7161: if ($srch->{'srchterm'} =~ /^\s+$/) {
7162: $response = &mt('Your search term must contain more than just spaces.');
7163: }
1.160 raeburn 7164: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'instd')) {
7165: if (($srch->{'srchdomain'} eq '') ||
1.163 albertel 7166: ! (&Apache::lonnet::domain($srch->{'srchdomain'}))) {
1.160 raeburn 7167: $response = &mt('You must specify a valid domain when searching in a domain or institutional directory.')
7168: }
7169: }
7170: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs') ||
7171: ($srch->{'srchin'} eq 'alc')) {
1.176 raeburn 7172: if ($srch->{'srchby'} eq 'uname') {
1.243 raeburn 7173: my $unamecheck = $srch->{'srchterm'};
7174: if ($srch->{'srchtype'} eq 'contains') {
7175: if ($unamecheck !~ /^\w/) {
7176: $unamecheck = 'a'.$unamecheck;
7177: }
7178: }
7179: if ($unamecheck !~ /^$match_username$/) {
1.176 raeburn 7180: $response = &mt('You must specify a valid username. Only the following are allowed: letters numbers - . @');
7181: }
1.160 raeburn 7182: }
7183: }
1.180 raeburn 7184: if ($response ne '') {
1.413 raeburn 7185: $response = '<span class="LC_warning">'.$response.'</span><br />';
1.180 raeburn 7186: }
1.160 raeburn 7187: if ($srch->{'srchin'} eq 'instd') {
1.412 raeburn 7188: my $instd_chk = &instdirectorysrch_check($srch);
1.160 raeburn 7189: if ($instd_chk ne 'ok') {
1.412 raeburn 7190: my $domd_chk = &domdirectorysrch_check($srch);
1.413 raeburn 7191: $response .= '<span class="LC_warning">'.$instd_chk.'</span><br />';
1.412 raeburn 7192: if ($domd_chk eq 'ok') {
1.413 raeburn 7193: $response .= &mt('You may want to search in the LON-CAPA domain instead of the institutional directory.');
1.412 raeburn 7194: }
1.415 raeburn 7195: $response .= '<br />';
1.412 raeburn 7196: }
7197: } else {
7198: unless (($context eq 'requestcrs') && ($srch->{'srchtype'} eq 'exact')) {
7199: my $domd_chk = &domdirectorysrch_check($srch);
7200: if ($domd_chk ne 'ok') {
7201: my $instd_chk = &instdirectorysrch_check($srch);
1.413 raeburn 7202: $response .= '<span class="LC_warning">'.$domd_chk.'</span><br />';
1.412 raeburn 7203: if ($instd_chk eq 'ok') {
1.413 raeburn 7204: $response .= &mt('You may want to search in the institutional directory instead of the LON-CAPA domain.');
1.412 raeburn 7205: }
1.415 raeburn 7206: $response .= '<br />';
1.412 raeburn 7207: }
1.160 raeburn 7208: }
7209: }
7210: if ($response ne '') {
1.180 raeburn 7211: return ($currstate,$response);
1.160 raeburn 7212: }
7213: if ($srch->{'srchby'} eq 'uname') {
7214: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs')) {
7215: if ($env{'form.forcenew'}) {
7216: if ($srch->{'srchdomain'} ne $env{'request.role.domain'}) {
7217: my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
7218: if ($uhome eq 'no_host') {
7219: my $domdesc = &Apache::lonnet::domain($env{'request.role.domain'},'description');
1.180 raeburn 7220: my $showdom = &display_domain_info($env{'request.role.domain'});
7221: $response = &mt('New users can only be created in the domain to which your current role belongs - [_1].',$showdom);
1.160 raeburn 7222: } else {
1.179 raeburn 7223: $currstate = 'modify';
1.160 raeburn 7224: }
7225: } else {
1.179 raeburn 7226: $currstate = 'modify';
1.160 raeburn 7227: }
7228: } else {
7229: if ($srch->{'srchin'} eq 'dom') {
1.162 raeburn 7230: if ($srch->{'srchtype'} eq 'exact') {
7231: my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
7232: if ($uhome eq 'no_host') {
1.179 raeburn 7233: ($currstate,$response,$forcenewuser) =
1.221 raeburn 7234: &build_search_response($context,$srch,%srch_results);
1.162 raeburn 7235: } else {
1.179 raeburn 7236: $currstate = 'modify';
1.416 ! raeburn 7237: if ($env{'form.action'} eq 'accesslogs') {
! 7238: $currstate = 'activity';
! 7239: }
1.310 raeburn 7240: my $uname = $srch->{'srchterm'};
7241: my $udom = $srch->{'srchdomain'};
7242: $srch_results{$uname.':'.$udom} =
7243: { &Apache::lonnet::get('environment',
7244: ['firstname',
7245: 'lastname',
7246: 'permanentemail'],
7247: $udom,$uname)
7248: };
1.162 raeburn 7249: }
7250: } else {
7251: %srch_results = &Apache::lonnet::usersearch($srch);
1.179 raeburn 7252: ($currstate,$response,$forcenewuser) =
1.221 raeburn 7253: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 7254: }
7255: } else {
1.167 albertel 7256: my $courseusers = &get_courseusers();
1.162 raeburn 7257: if ($srch->{'srchtype'} eq 'exact') {
1.167 albertel 7258: if (exists($courseusers->{$srch->{'srchterm'}.':'.$srch->{'srchdomain'}})) {
1.179 raeburn 7259: $currstate = 'modify';
1.162 raeburn 7260: } else {
1.179 raeburn 7261: ($currstate,$response,$forcenewuser) =
1.221 raeburn 7262: &build_search_response($context,$srch,%srch_results);
1.162 raeburn 7263: }
1.160 raeburn 7264: } else {
1.167 albertel 7265: foreach my $user (keys(%$courseusers)) {
1.162 raeburn 7266: my ($cuname,$cudomain) = split(/:/,$user);
7267: if ($cudomain eq $srch->{'srchdomain'}) {
1.177 raeburn 7268: my $matched = 0;
7269: if ($srch->{'srchtype'} eq 'begins') {
7270: if ($cuname =~ /^\Q$srch->{'srchterm'}\E/i) {
7271: $matched = 1;
7272: }
7273: } else {
7274: if ($cuname =~ /\Q$srch->{'srchterm'}\E/i) {
7275: $matched = 1;
7276: }
7277: }
7278: if ($matched) {
1.167 albertel 7279: $srch_results{$user} =
7280: {&Apache::lonnet::get('environment',
7281: ['firstname',
7282: 'lastname',
1.194 albertel 7283: 'permanentemail'],
7284: $cudomain,$cuname)};
1.162 raeburn 7285: }
7286: }
7287: }
1.179 raeburn 7288: ($currstate,$response,$forcenewuser) =
1.221 raeburn 7289: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 7290: }
7291: }
7292: }
7293: } elsif ($srch->{'srchin'} eq 'alc') {
1.179 raeburn 7294: $currstate = 'query';
1.160 raeburn 7295: } elsif ($srch->{'srchin'} eq 'instd') {
1.181 raeburn 7296: ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
7297: if ($dirsrchres eq 'ok') {
7298: ($currstate,$response,$forcenewuser) =
1.221 raeburn 7299: &build_search_response($context,$srch,%srch_results);
1.181 raeburn 7300: } else {
7301: my $showdom = &display_domain_info($srch->{'srchdomain'});
7302: $response = '<span class="LC_warning">'.
7303: &mt('Institutional directory search is not available in domain: [_1]',$showdom).
7304: '</span><br />'.
7305: &mt('You may want to search in the LON-CAPA domain instead of the institutional directory.').
1.415 raeburn 7306: '<br />';
1.181 raeburn 7307: }
1.160 raeburn 7308: }
7309: } else {
7310: if ($srch->{'srchin'} eq 'dom') {
7311: %srch_results = &Apache::lonnet::usersearch($srch);
1.179 raeburn 7312: ($currstate,$response,$forcenewuser) =
1.221 raeburn 7313: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 7314: } elsif ($srch->{'srchin'} eq 'crs') {
1.167 albertel 7315: my $courseusers = &get_courseusers();
7316: foreach my $user (keys(%$courseusers)) {
1.160 raeburn 7317: my ($uname,$udom) = split(/:/,$user);
7318: my %names = &Apache::loncommon::getnames($uname,$udom);
7319: my %emails = &Apache::loncommon::getemails($uname,$udom);
7320: if ($srch->{'srchby'} eq 'lastname') {
7321: if ((($srch->{'srchtype'} eq 'exact') &&
7322: ($names{'lastname'} eq $srch->{'srchterm'})) ||
1.177 raeburn 7323: (($srch->{'srchtype'} eq 'begins') &&
7324: ($names{'lastname'} =~ /^\Q$srch->{'srchterm'}\E/i)) ||
1.160 raeburn 7325: (($srch->{'srchtype'} eq 'contains') &&
7326: ($names{'lastname'} =~ /\Q$srch->{'srchterm'}\E/i))) {
7327: $srch_results{$user} = {firstname => $names{'firstname'},
7328: lastname => $names{'lastname'},
7329: permanentemail => $emails{'permanentemail'},
7330: };
7331: }
7332: } elsif ($srch->{'srchby'} eq 'lastfirst') {
7333: my ($srchlast,$srchfirst) = split(/,/,$srch->{'srchterm'});
1.177 raeburn 7334: $srchlast =~ s/\s+$//;
7335: $srchfirst =~ s/^\s+//;
1.160 raeburn 7336: if ($srch->{'srchtype'} eq 'exact') {
7337: if (($names{'lastname'} eq $srchlast) &&
7338: ($names{'firstname'} eq $srchfirst)) {
7339: $srch_results{$user} = {firstname => $names{'firstname'},
7340: lastname => $names{'lastname'},
7341: permanentemail => $emails{'permanentemail'},
7342:
7343: };
7344: }
1.177 raeburn 7345: } elsif ($srch->{'srchtype'} eq 'begins') {
7346: if (($names{'lastname'} =~ /^\Q$srchlast\E/i) &&
7347: ($names{'firstname'} =~ /^\Q$srchfirst\E/i)) {
7348: $srch_results{$user} = {firstname => $names{'firstname'},
7349: lastname => $names{'lastname'},
7350: permanentemail => $emails{'permanentemail'},
7351: };
7352: }
7353: } else {
1.160 raeburn 7354: if (($names{'lastname'} =~ /\Q$srchlast\E/i) &&
7355: ($names{'firstname'} =~ /\Q$srchfirst\E/i)) {
7356: $srch_results{$user} = {firstname => $names{'firstname'},
7357: lastname => $names{'lastname'},
7358: permanentemail => $emails{'permanentemail'},
7359: };
7360: }
7361: }
7362: }
7363: }
1.179 raeburn 7364: ($currstate,$response,$forcenewuser) =
1.221 raeburn 7365: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 7366: } elsif ($srch->{'srchin'} eq 'alc') {
1.179 raeburn 7367: $currstate = 'query';
1.160 raeburn 7368: } elsif ($srch->{'srchin'} eq 'instd') {
1.181 raeburn 7369: ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
7370: if ($dirsrchres eq 'ok') {
7371: ($currstate,$response,$forcenewuser) =
1.221 raeburn 7372: &build_search_response($context,$srch,%srch_results);
1.181 raeburn 7373: } else {
1.412 raeburn 7374: my $showdom = &display_domain_info($srch->{'srchdomain'});
7375: $response = '<span class="LC_warning">'.
1.181 raeburn 7376: &mt('Institutional directory search is not available in domain: [_1]',$showdom).
7377: '</span><br />'.
7378: &mt('You may want to search in the LON-CAPA domain instead of the institutional directory.').
1.415 raeburn 7379: '<br />';
1.181 raeburn 7380: }
1.160 raeburn 7381: }
7382: }
1.179 raeburn 7383: return ($currstate,$response,$forcenewuser,\%srch_results);
1.160 raeburn 7384: }
7385:
1.412 raeburn 7386: sub domdirectorysrch_check {
7387: my ($srch) = @_;
7388: my $response;
7389: my %dom_inst_srch = &Apache::lonnet::get_dom('configuration',
7390: ['directorysrch'],$srch->{'srchdomain'});
7391: my $showdom = &display_domain_info($srch->{'srchdomain'});
7392: if (ref($dom_inst_srch{'directorysrch'}) eq 'HASH') {
7393: if ($dom_inst_srch{'directorysrch'}{'lcavailable'} eq '0') {
7394: return &mt('LON-CAPA directory search is not available in domain: [_1]',$showdom);
7395: }
7396: if ($dom_inst_srch{'directorysrch'}{'lclocalonly'}) {
7397: if ($env{'request.role.domain'} ne $srch->{'srchdomain'}) {
7398: return &mt('LON-CAPA directory search in domain: [_1] is only allowed for users with a current role in the domain.',$showdom);
7399: }
7400: }
7401: }
7402: return 'ok';
7403: }
7404:
7405: sub instdirectorysrch_check {
1.160 raeburn 7406: my ($srch) = @_;
7407: my $can_search = 0;
7408: my $response;
7409: my %dom_inst_srch = &Apache::lonnet::get_dom('configuration',
7410: ['directorysrch'],$srch->{'srchdomain'});
1.180 raeburn 7411: my $showdom = &display_domain_info($srch->{'srchdomain'});
1.160 raeburn 7412: if (ref($dom_inst_srch{'directorysrch'}) eq 'HASH') {
7413: if (!$dom_inst_srch{'directorysrch'}{'available'}) {
1.180 raeburn 7414: return &mt('Institutional directory search is not available in domain: [_1]',$showdom);
1.160 raeburn 7415: }
7416: if ($dom_inst_srch{'directorysrch'}{'localonly'}) {
7417: if ($env{'request.role.domain'} ne $srch->{'srchdomain'}) {
1.180 raeburn 7418: return &mt('Institutional directory search in domain: [_1] is only allowed for users with a current role in the domain.',$showdom);
1.160 raeburn 7419: }
7420: my @usertypes = split(/:/,$env{'environment.inststatus'});
7421: if (!@usertypes) {
7422: push(@usertypes,'default');
7423: }
7424: if (ref($dom_inst_srch{'directorysrch'}{'cansearch'}) eq 'ARRAY') {
7425: foreach my $type (@usertypes) {
7426: if (grep(/^\Q$type\E$/,@{$dom_inst_srch{'directorysrch'}{'cansearch'}})) {
7427: $can_search = 1;
7428: last;
7429: }
7430: }
7431: }
7432: if (!$can_search) {
7433: my ($insttypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($srch->{'srchdomain'});
7434: my @longtypes;
7435: foreach my $item (@usertypes) {
1.229 raeburn 7436: if (defined($insttypes->{$item})) {
7437: push (@longtypes,$insttypes->{$item});
7438: } elsif ($item eq 'default') {
7439: push (@longtypes,&mt('other'));
7440: }
1.160 raeburn 7441: }
7442: my $insttype_str = join(', ',@longtypes);
1.180 raeburn 7443: return &mt('Institutional directory search in domain: [_1] is not available to your user type: ',$showdom).$insttype_str;
1.229 raeburn 7444: }
1.160 raeburn 7445: } else {
7446: $can_search = 1;
7447: }
7448: } else {
1.180 raeburn 7449: return &mt('Institutional directory search has not been configured for domain: [_1]',$showdom);
1.160 raeburn 7450: }
7451: my %longtext = &Apache::lonlocal::texthash (
1.167 albertel 7452: uname => 'username',
1.160 raeburn 7453: lastfirst => 'last name, first name',
1.167 albertel 7454: lastname => 'last name',
1.172 raeburn 7455: contains => 'contains',
1.178 raeburn 7456: exact => 'as exact match to',
7457: begins => 'begins with',
1.160 raeburn 7458: );
7459: if ($can_search) {
7460: if (ref($dom_inst_srch{'directorysrch'}{'searchby'}) eq 'ARRAY') {
7461: if (!grep(/^\Q$srch->{'srchby'}\E$/,@{$dom_inst_srch{'directorysrch'}{'searchby'}})) {
1.180 raeburn 7462: return &mt('Institutional directory search in domain: [_1] is not available for searching by "[_2]"',$showdom,$longtext{$srch->{'srchby'}});
1.160 raeburn 7463: }
7464: } else {
1.180 raeburn 7465: return &mt('Institutional directory search in domain: [_1] is not available.', $showdom);
1.160 raeburn 7466: }
7467: }
7468: if ($can_search) {
1.178 raeburn 7469: if (ref($dom_inst_srch{'directorysrch'}{'searchtypes'}) eq 'ARRAY') {
7470: if (grep(/^\Q$srch->{'srchtype'}\E/,@{$dom_inst_srch{'directorysrch'}{'searchtypes'}})) {
7471: return 'ok';
7472: } else {
1.180 raeburn 7473: return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
1.178 raeburn 7474: }
7475: } else {
7476: if ((($dom_inst_srch{'directorysrch'}{'searchtypes'} eq 'specify') &&
7477: ($srch->{'srchtype'} eq 'exact' || $srch->{'srchtype'} eq 'contains')) ||
7478: ($dom_inst_srch{'directorysrch'}{'searchtypes'} eq $srch->{'srchtype'})) {
7479: return 'ok';
7480: } else {
1.180 raeburn 7481: return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
1.178 raeburn 7482: }
1.160 raeburn 7483: }
7484: }
7485: }
7486:
7487: sub get_courseusers {
7488: my %advhash;
1.167 albertel 7489: my $classlist = &Apache::loncoursedata::get_classlist();
1.160 raeburn 7490: my %coursepersonnel=&Apache::lonnet::get_course_adv_roles();
7491: foreach my $role (sort(keys(%coursepersonnel))) {
7492: foreach my $user (split(/\,/,$coursepersonnel{$role})) {
1.167 albertel 7493: if (!exists($classlist->{$user})) {
7494: $classlist->{$user} = [];
7495: }
1.160 raeburn 7496: }
7497: }
1.167 albertel 7498: return $classlist;
1.160 raeburn 7499: }
7500:
7501: sub build_search_response {
1.221 raeburn 7502: my ($context,$srch,%srch_results) = @_;
1.179 raeburn 7503: my ($currstate,$response,$forcenewuser);
1.160 raeburn 7504: my %names = (
1.330 bisitz 7505: 'uname' => 'username',
7506: 'lastname' => 'last name',
1.160 raeburn 7507: 'lastfirst' => 'last name, first name',
1.330 bisitz 7508: 'crs' => 'this course',
7509: 'dom' => 'LON-CAPA domain',
7510: 'instd' => 'the institutional directory for domain',
1.160 raeburn 7511: );
7512:
7513: my %single = (
1.180 raeburn 7514: begins => 'A match',
1.160 raeburn 7515: contains => 'A match',
1.180 raeburn 7516: exact => 'An exact match',
1.160 raeburn 7517: );
7518: my %nomatch = (
1.180 raeburn 7519: begins => 'No match',
1.160 raeburn 7520: contains => 'No match',
1.180 raeburn 7521: exact => 'No exact match',
1.160 raeburn 7522: );
7523: if (keys(%srch_results) > 1) {
1.179 raeburn 7524: $currstate = 'select';
1.160 raeburn 7525: } else {
7526: if (keys(%srch_results) == 1) {
1.416 ! raeburn 7527: if ($env{'form.action'} eq 'accesslogs') {
! 7528: $currstate = 'activity';
! 7529: } else {
! 7530: $currstate = 'modify';
! 7531: }
1.180 raeburn 7532: $response = &mt("$single{$srch->{'srchtype'}} was found for the $names{$srch->{'srchby'}} ([_1]) in $names{$srch->{'srchin'}}.",$srch->{'srchterm'});
7533: if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
1.330 bisitz 7534: $response .= ': '.&display_domain_info($srch->{'srchdomain'});
1.180 raeburn 7535: }
1.330 bisitz 7536: } else { # Search has nothing found. Prepare message to user.
7537: $response = '<span class="LC_warning">';
1.180 raeburn 7538: if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
1.330 bisitz 7539: $response .= &mt("$nomatch{$srch->{'srchtype'}} found for the $names{$srch->{'srchby'}} [_1] in $names{$srch->{'srchin'}}: [_2]",
7540: '<b>'.$srch->{'srchterm'}.'</b>',
7541: &display_domain_info($srch->{'srchdomain'}));
7542: } else {
7543: $response .= &mt("$nomatch{$srch->{'srchtype'}} found for the $names{$srch->{'srchby'}} [_1] in $names{$srch->{'srchin'}}.",
7544: '<b>'.$srch->{'srchterm'}.'</b>');
1.180 raeburn 7545: }
7546: $response .= '</span>';
1.330 bisitz 7547:
1.160 raeburn 7548: if ($srch->{'srchin'} ne 'alc') {
7549: $forcenewuser = 1;
7550: my $cansrchinst = 0;
7551: if ($srch->{'srchdomain'}) {
7552: my %domconfig = &Apache::lonnet::get_dom('configuration',['directorysrch'],$srch->{'srchdomain'});
7553: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
7554: if ($domconfig{'directorysrch'}{'available'}) {
7555: $cansrchinst = 1;
7556: }
7557: }
7558: }
1.180 raeburn 7559: if ((($srch->{'srchby'} eq 'lastfirst') ||
7560: ($srch->{'srchby'} eq 'lastname')) &&
7561: ($srch->{'srchin'} eq 'dom')) {
7562: if ($cansrchinst) {
7563: $response .= '<br />'.&mt('You may want to broaden your search to a search of the institutional directory for the domain.');
1.160 raeburn 7564: }
7565: }
1.180 raeburn 7566: if ($srch->{'srchin'} eq 'crs') {
7567: $response .= '<br />'.&mt('You may want to broaden your search to the selected LON-CAPA domain.');
7568: }
7569: }
1.305 raeburn 7570: my $createdom = $env{'request.role.domain'};
7571: if ($context eq 'requestcrs') {
7572: if ($env{'form.coursedom'} ne '') {
7573: $createdom = $env{'form.coursedom'};
7574: }
7575: }
1.416 ! raeburn 7576: unless (($env{'form.action'} eq 'accesslogs') || (($srch->{'srchby'} eq 'uname') && ($srch->{'srchin'} eq 'dom') &&
! 7577: ($srch->{'srchtype'} eq 'exact') && ($srch->{'srchdomain'} eq $createdom))) {
1.221 raeburn 7578: my $cancreate =
1.305 raeburn 7579: &Apache::lonuserutils::can_create_user($createdom,$context);
7580: my $targetdom = '<span class="LC_cusr_emph">'.$createdom.'</span>';
1.221 raeburn 7581: if ($cancreate) {
1.305 raeburn 7582: my $showdom = &display_domain_info($createdom);
1.266 bisitz 7583: $response .= '<br /><br />'
7584: .'<b>'.&mt('To add a new user:').'</b>'
1.305 raeburn 7585: .'<br />';
7586: if ($context eq 'requestcrs') {
7587: $response .= &mt("(You can only define new users in the new course's domain - [_1])",$targetdom);
7588: } else {
7589: $response .= &mt("(You can only create new users in your current role's domain - [_1])",$targetdom);
7590: }
7591: $response .='<ul><li>'
1.266 bisitz 7592: .&mt("Set 'Domain/institution to search' to: [_1]",'<span class="LC_cusr_emph">'.$showdom.'</span>')
7593: .'</li><li>'
7594: .&mt("Set 'Search criteria' to: [_1]username is ..... in selected LON-CAPA domain[_2]",'<span class="LC_cusr_emph">','</span>')
7595: .'</li><li>'
7596: .&mt('Provide the proposed username')
7597: .'</li><li>'
7598: .&mt("Click 'Search'")
7599: .'</li></ul><br />';
1.221 raeburn 7600: } else {
7601: my $helplink = ' href="javascript:helpMenu('."'display'".')"';
1.305 raeburn 7602: $response .= '<br /><br />';
7603: if ($context eq 'requestcrs') {
1.314 raeburn 7604: $response .= &mt("You are not authorized to define new users in the new course's domain - [_1].",$targetdom);
1.305 raeburn 7605: } else {
7606: $response .= &mt("You are not authorized to create new users in your current role's domain - [_1].",$targetdom);
7607: }
7608: $response .= '<br />'
7609: .&mt('Please contact the [_1]helpdesk[_2] if you need to create a new user.'
1.266 bisitz 7610: ,' <a'.$helplink.'>'
7611: ,'</a>')
1.415 raeburn 7612: .'<br />';
1.221 raeburn 7613: }
1.160 raeburn 7614: }
7615: }
7616: }
1.179 raeburn 7617: return ($currstate,$response,$forcenewuser);
1.160 raeburn 7618: }
7619:
1.180 raeburn 7620: sub display_domain_info {
7621: my ($dom) = @_;
7622: my $output = $dom;
7623: if ($dom ne '') {
7624: my $domdesc = &Apache::lonnet::domain($dom,'description');
7625: if ($domdesc ne '') {
7626: $output .= ' <span class="LC_cusr_emph">('.$domdesc.')</span>';
7627: }
7628: }
7629: return $output;
7630: }
7631:
1.160 raeburn 7632: sub crumb_utilities {
7633: my %elements = (
7634: crtuser => {
7635: srchterm => 'text',
1.172 raeburn 7636: srchin => 'selectbox',
1.160 raeburn 7637: srchby => 'selectbox',
7638: srchtype => 'selectbox',
7639: srchdomain => 'selectbox',
7640: },
1.207 raeburn 7641: crtusername => {
7642: srchterm => 'text',
7643: srchdomain => 'selectbox',
7644: },
1.160 raeburn 7645: docustom => {
7646: rolename => 'selectbox',
7647: newrolename => 'textbox',
7648: },
1.179 raeburn 7649: studentform => {
7650: srchterm => 'text',
7651: srchin => 'selectbox',
7652: srchby => 'selectbox',
7653: srchtype => 'selectbox',
7654: srchdomain => 'selectbox',
7655: },
1.160 raeburn 7656: );
7657:
7658: my $jsback .= qq|
7659: function backPage(formname,prevphase,prevstate) {
1.211 raeburn 7660: if (typeof prevphase == 'undefined') {
7661: formname.phase.value = '';
7662: }
7663: else {
7664: formname.phase.value = prevphase;
7665: }
7666: if (typeof prevstate == 'undefined') {
7667: formname.currstate.value = '';
7668: }
7669: else {
7670: formname.currstate.value = prevstate;
7671: }
1.160 raeburn 7672: formname.submit();
7673: }
7674: |;
7675: return ($jsback,\%elements);
7676: }
7677:
1.26 matthew 7678: sub course_level_table {
1.375 raeburn 7679: my ($inccourses,$showcredits,$defaultcredits) = @_;
7680: return unless (ref($inccourses) eq 'HASH');
1.26 matthew 7681: my $table = '';
1.62 www 7682: # Custom Roles?
7683:
1.190 raeburn 7684: my %customroles=&Apache::lonuserutils::my_custom_roles();
1.89 raeburn 7685: my %lt=&Apache::lonlocal::texthash(
7686: 'exs' => "Existing sections",
7687: 'new' => "Define new section",
7688: 'ssd' => "Set Start Date",
7689: 'sed' => "Set End Date",
1.131 raeburn 7690: 'crl' => "Course Level",
1.89 raeburn 7691: 'act' => "Activate",
7692: 'rol' => "Role",
7693: 'ext' => "Extent",
1.113 raeburn 7694: 'grs' => "Section",
1.375 raeburn 7695: 'crd' => "Credits",
1.89 raeburn 7696: 'sta' => "Start",
7697: 'end' => "End"
7698: );
1.62 www 7699:
1.375 raeburn 7700: foreach my $protectedcourse (sort(keys(%{$inccourses}))) {
1.135 raeburn 7701: my $thiscourse=$protectedcourse;
1.26 matthew 7702: $thiscourse=~s:_:/:g;
7703: my %coursedata=&Apache::lonnet::coursedescription($thiscourse);
1.365 raeburn 7704: my $isowner = &Apache::lonuserutils::is_courseowner($protectedcourse,$coursedata{'internal.courseowner'});
1.26 matthew 7705: my $area=$coursedata{'description'};
1.321 raeburn 7706: my $crstype=$coursedata{'type'};
1.135 raeburn 7707: if (!defined($area)) { $area=&mt('Unavailable course').': '.$protectedcourse; }
1.89 raeburn 7708: my ($domain,$cnum)=split(/\//,$thiscourse);
1.115 albertel 7709: my %sections_count;
1.101 albertel 7710: if (defined($env{'request.course.id'})) {
7711: if ($env{'request.course.id'} eq $domain.'_'.$cnum) {
1.115 albertel 7712: %sections_count =
7713: &Apache::loncommon::get_sections($domain,$cnum);
1.92 raeburn 7714: }
7715: }
1.321 raeburn 7716: my @roles = &Apache::lonuserutils::roles_by_context('course','',$crstype);
1.213 raeburn 7717: foreach my $role (@roles) {
1.321 raeburn 7718: my $plrole=&Apache::lonnet::plaintext($role,$crstype);
1.329 raeburn 7719: if ((&Apache::lonnet::allowed('c'.$role,$thiscourse)) ||
7720: ((($role eq 'cc') || ($role eq 'co')) && ($isowner))) {
1.221 raeburn 7721: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
1.375 raeburn 7722: $plrole,\%sections_count,\%lt,
1.402 raeburn 7723: $showcredits,$defaultcredits,$crstype);
1.221 raeburn 7724: } elsif ($env{'request.course.sec'} ne '') {
7725: if (&Apache::lonnet::allowed('c'.$role,$thiscourse.'/'.
7726: $env{'request.course.sec'})) {
7727: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
1.375 raeburn 7728: $plrole,\%sections_count,\%lt,
1.402 raeburn 7729: $showcredits,$defaultcredits,$crstype);
1.26 matthew 7730: }
7731: }
7732: }
1.221 raeburn 7733: if (&Apache::lonnet::allowed('ccr',$thiscourse)) {
1.324 raeburn 7734: foreach my $cust (sort(keys(%customroles))) {
7735: next if ($crstype eq 'Community' && $customroles{$cust} =~ /bre\&S/);
1.221 raeburn 7736: my $role = 'cr_cr_'.$env{'user.domain'}.'_'.$env{'user.name'}.'_'.$cust;
7737: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
1.402 raeburn 7738: $cust,\%sections_count,\%lt,
7739: $showcredits,$defaultcredits,$crstype);
1.221 raeburn 7740: }
1.62 www 7741: }
1.26 matthew 7742: }
7743: return '' if ($table eq ''); # return nothing if there is nothing
7744: # in the table
1.188 raeburn 7745: my $result;
7746: if (!$env{'request.course.id'}) {
7747: $result = '<h4>'.$lt{'crl'}.'</h4>'."\n";
7748: }
7749: $result .=
1.136 raeburn 7750: &Apache::loncommon::start_data_table().
7751: &Apache::loncommon::start_data_table_header_row().
1.375 raeburn 7752: '<th>'.$lt{'act'}.'</th><th>'.$lt{'rol'}.'</th>'."\n".
1.402 raeburn 7753: '<th>'.$lt{'ext'}.'</th><th>'."\n";
7754: if ($showcredits) {
7755: $result .= $lt{'crd'}.'</th>';
7756: }
7757: $result .=
1.375 raeburn 7758: '<th>'.$lt{'grs'}.'</th><th>'.$lt{'sta'}.'</th>'."\n".
7759: '<th>'.$lt{'end'}.'</th>'.
1.136 raeburn 7760: &Apache::loncommon::end_data_table_header_row().
7761: $table.
7762: &Apache::loncommon::end_data_table();
1.26 matthew 7763: return $result;
7764: }
1.88 raeburn 7765:
1.221 raeburn 7766: sub course_level_row {
1.375 raeburn 7767: my ($protectedcourse,$role,$area,$domain,$plrole,$sections_count,
1.402 raeburn 7768: $lt,$showcredits,$defaultcredits,$crstype) = @_;
1.375 raeburn 7769: my $creditem;
1.222 raeburn 7770: my $row = &Apache::loncommon::start_data_table_row().
7771: ' <td><input type="checkbox" name="act_'.
7772: $protectedcourse.'_'.$role.'" /></td>'."\n".
7773: ' <td>'.$plrole.'</td>'."\n".
7774: ' <td>'.$area.'<br />Domain: '.$domain.'</td>'."\n";
1.402 raeburn 7775: if (($showcredits) && ($role eq 'st') && ($crstype eq 'Course')) {
1.375 raeburn 7776: $row .=
7777: '<td><input type="text" name="credits_'.$protectedcourse.'_'.
7778: $role.'" size="3" value="'.$defaultcredits.'" /></td>';
7779: } else {
7780: $row .= '<td> </td>';
7781: }
1.322 raeburn 7782: if (($role eq 'cc') || ($role eq 'co')) {
1.222 raeburn 7783: $row .= '<td> </td>';
1.221 raeburn 7784: } elsif ($env{'request.course.sec'} ne '') {
1.222 raeburn 7785: $row .= ' <td><input type="hidden" value="'.
7786: $env{'request.course.sec'}.'" '.
7787: 'name="sec_'.$protectedcourse.'_'.$role.'" />'.
7788: $env{'request.course.sec'}.'</td>';
1.221 raeburn 7789: } else {
7790: if (ref($sections_count) eq 'HASH') {
7791: my $currsec =
7792: &Apache::lonuserutils::course_sections($sections_count,
7793: $protectedcourse.'_'.$role);
1.222 raeburn 7794: $row .= '<td><table class="LC_createuser">'."\n".
7795: '<tr class="LC_section_row">'."\n".
7796: ' <td valign="top">'.$lt->{'exs'}.'<br />'.
7797: $currsec.'</td>'."\n".
7798: ' <td> </td>'."\n".
7799: ' <td valign="top"> '.$lt->{'new'}.'<br />'.
1.221 raeburn 7800: '<input type="text" name="newsec_'.$protectedcourse.'_'.$role.
7801: '" value="" />'.
7802: '<input type="hidden" '.
7803: 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'."\n".
1.222 raeburn 7804: '</tr></table></td>'."\n";
1.221 raeburn 7805: } else {
1.222 raeburn 7806: $row .= '<td><input type="text" size="10" '.
1.375 raeburn 7807: 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'."\n";
1.221 raeburn 7808: }
7809: }
1.222 raeburn 7810: $row .= <<ENDTIMEENTRY;
7811: <td><input type="hidden" name="start_$protectedcourse\_$role" value="" />
1.221 raeburn 7812: <a href=
7813: "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 7814: <td><input type="hidden" name="end_$protectedcourse\_$role" value="" />
1.221 raeburn 7815: <a href=
7816: "javascript:pjump('date_end','End Date $plrole',document.cu.end_$protectedcourse\_$role.value,'end_$protectedcourse\_$role','cu.pres','dateset')">$lt->{'sed'}</a></td>
7817: ENDTIMEENTRY
1.222 raeburn 7818: $row .= &Apache::loncommon::end_data_table_row();
7819: return $row;
1.221 raeburn 7820: }
7821:
1.88 raeburn 7822: sub course_level_dc {
1.375 raeburn 7823: my ($dcdom,$showcredits) = @_;
1.190 raeburn 7824: my %customroles=&Apache::lonuserutils::my_custom_roles();
1.213 raeburn 7825: my @roles = &Apache::lonuserutils::roles_by_context('course');
1.88 raeburn 7826: my $hiddenitems = '<input type="hidden" name="dcdomain" value="'.$dcdom.'" />'.
7827: '<input type="hidden" name="origdom" value="'.$dcdom.'" />'.
1.133 raeburn 7828: '<input type="hidden" name="dccourse" value="" />';
1.355 www 7829: my $courseform=&Apache::loncommon::selectcourse_link
1.356 raeburn 7830: ('cu','dccourse','dcdomain','coursedesc',undef,undef,'Select','crstype');
1.375 raeburn 7831: my $credit_elem;
7832: if ($showcredits) {
7833: $credit_elem = 'credits';
7834: }
7835: my $cb_jscript = &Apache::loncommon::coursebrowser_javascript($dcdom,'currsec','cu','role','Course/Community Browser',$credit_elem);
1.88 raeburn 7836: my %lt=&Apache::lonlocal::texthash(
7837: 'rol' => "Role",
1.113 raeburn 7838: 'grs' => "Section",
1.88 raeburn 7839: 'exs' => "Existing sections",
7840: 'new' => "Define new section",
7841: 'sta' => "Start",
7842: 'end' => "End",
7843: 'ssd' => "Set Start Date",
1.355 www 7844: 'sed' => "Set End Date",
1.375 raeburn 7845: 'scc' => "Course/Community",
7846: 'crd' => "Credits",
1.88 raeburn 7847: );
1.323 raeburn 7848: my $header = '<h4>'.&mt('Course/Community Level').'</h4>'.
1.136 raeburn 7849: &Apache::loncommon::start_data_table().
7850: &Apache::loncommon::start_data_table_header_row().
1.375 raeburn 7851: '<th>'.$lt{'scc'}.'</th><th>'.$lt{'rol'}.'</th>'."\n".
1.397 bisitz 7852: '<th>'.$lt{'grs'}.'</th>'."\n";
7853: $header .= '<th>'.$lt{'crd'}.'</th>'."\n" if ($showcredits);
7854: $header .= '<th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'."\n".
1.136 raeburn 7855: &Apache::loncommon::end_data_table_header_row();
1.143 raeburn 7856: my $otheritems = &Apache::loncommon::start_data_table_row()."\n".
1.356 raeburn 7857: '<td><br /><span class="LC_nobreak"><input type="text" name="coursedesc" value="" onfocus="this.blur();opencrsbrowser('."'cu','dccourse','dcdomain','coursedesc','','','','crstype'".')" />'.
7858: $courseform.(' ' x4).'</span></td>'."\n".
1.389 bisitz 7859: '<td valign="top"><br /><select name="role">'."\n";
1.213 raeburn 7860: foreach my $role (@roles) {
1.135 raeburn 7861: my $plrole=&Apache::lonnet::plaintext($role);
1.389 bisitz 7862: $otheritems .= ' <option value="'.$role.'">'.$plrole.'</option>';
1.88 raeburn 7863: }
1.404 raeburn 7864: if ( keys(%customroles) > 0) {
7865: foreach my $cust (sort(keys(%customroles))) {
1.101 albertel 7866: my $custrole='cr_cr_'.$env{'user.domain'}.
1.135 raeburn 7867: '_'.$env{'user.name'}.'_'.$cust;
1.389 bisitz 7868: $otheritems .= ' <option value="'.$custrole.'">'.$cust.'</option>';
1.88 raeburn 7869: }
7870: }
7871: $otheritems .= '</select></td><td>'.
7872: '<table border="0" cellspacing="0" cellpadding="0">'.
7873: '<tr><td valign="top"><b>'.$lt{'exs'}.'</b><br /><select name="currsec">'.
1.389 bisitz 7874: ' <option value=""><--'.&mt('Pick course first').'</option></select></td>'.
1.88 raeburn 7875: '<td> </td>'.
7876: '<td valign="top"> <b>'.$lt{'new'}.'</b><br />'.
1.113 raeburn 7877: '<input type="text" name="newsec" value="" />'.
1.237 raeburn 7878: '<input type="hidden" name="section" value="" />'.
1.323 raeburn 7879: '<input type="hidden" name="groups" value="" />'.
7880: '<input type="hidden" name="crstype" value="" /></td>'.
1.375 raeburn 7881: '</tr></table></td>'."\n";
7882: if ($showcredits) {
7883: $otheritems .= '<td><br />'."\n".
1.397 bisitz 7884: '<input type="text" size="3" name="credits" value="" /></td>'."\n";
1.375 raeburn 7885: }
1.88 raeburn 7886: $otheritems .= <<ENDTIMEENTRY;
1.323 raeburn 7887: <td><br /><input type="hidden" name="start" value='' />
1.88 raeburn 7888: <a href=
7889: "javascript:pjump('date_start','Start Date',document.cu.start.value,'start','cu.pres','dateset')">$lt{'ssd'}</a></td>
1.323 raeburn 7890: <td><br /><input type="hidden" name="end" value='' />
1.88 raeburn 7891: <a href=
7892: "javascript:pjump('date_end','End Date',document.cu.end.value,'end','cu.pres','dateset')">$lt{'sed'}</a></td>
7893: ENDTIMEENTRY
1.136 raeburn 7894: $otheritems .= &Apache::loncommon::end_data_table_row().
7895: &Apache::loncommon::end_data_table()."\n";
1.88 raeburn 7896: return $cb_jscript.$header.$hiddenitems.$otheritems;
7897: }
7898:
1.237 raeburn 7899: sub update_selfenroll_config {
1.400 raeburn 7900: my ($r,$cid,$cdom,$cnum,$context,$crstype,$currsettings) = @_;
1.398 raeburn 7901: return unless (ref($currsettings) eq 'HASH');
7902: my ($row,$lt) = &Apache::lonuserutils::get_selfenroll_titles();
7903: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
1.237 raeburn 7904: my (%changes,%warning);
1.241 raeburn 7905: my $curr_types;
1.400 raeburn 7906: my %noedit;
7907: unless ($context eq 'domain') {
7908: %noedit = &get_noedit_fields($cdom,$cnum,$crstype,$row);
7909: }
1.237 raeburn 7910: if (ref($row) eq 'ARRAY') {
7911: foreach my $item (@{$row}) {
1.400 raeburn 7912: next if ($noedit{$item});
1.237 raeburn 7913: if ($item eq 'enroll_dates') {
7914: my (%currenrolldate,%newenrolldate);
7915: foreach my $type ('start','end') {
1.398 raeburn 7916: $currenrolldate{$type} = $currsettings->{'selfenroll_'.$type.'_date'};
1.237 raeburn 7917: $newenrolldate{$type} = &Apache::lonhtmlcommon::get_date_from_form('selfenroll_'.$type.'_date');
7918: if ($newenrolldate{$type} ne $currenrolldate{$type}) {
7919: $changes{'internal.selfenroll_'.$type.'_date'} = $newenrolldate{$type};
7920: }
7921: }
7922: } elsif ($item eq 'access_dates') {
7923: my (%currdate,%newdate);
7924: foreach my $type ('start','end') {
1.398 raeburn 7925: $currdate{$type} = $currsettings->{'selfenroll_'.$type.'_access'};
1.237 raeburn 7926: $newdate{$type} = &Apache::lonhtmlcommon::get_date_from_form('selfenroll_'.$type.'_access');
7927: if ($newdate{$type} ne $currdate{$type}) {
7928: $changes{'internal.selfenroll_'.$type.'_access'} = $newdate{$type};
7929: }
7930: }
1.241 raeburn 7931: } elsif ($item eq 'types') {
1.398 raeburn 7932: $curr_types = $currsettings->{'selfenroll_'.$item};
1.241 raeburn 7933: if ($env{'form.selfenroll_all'}) {
7934: if ($curr_types ne '*') {
7935: $changes{'internal.selfenroll_types'} = '*';
7936: } else {
7937: next;
7938: }
7939: } else {
1.249 raeburn 7940: my %currdoms;
1.241 raeburn 7941: my @entries = split(/;/,$curr_types);
7942: my @deletedoms = &Apache::loncommon::get_env_multiple('form.selfenroll_delete');
1.249 raeburn 7943: my @activations = &Apache::loncommon::get_env_multiple('form.selfenroll_activate');
1.241 raeburn 7944: my $newnum = 0;
1.249 raeburn 7945: my @latesttypes;
7946: foreach my $num (@activations) {
7947: my @types = &Apache::loncommon::get_env_multiple('form.selfenroll_types_'.$num);
7948: if (@types > 0) {
1.241 raeburn 7949: @types = sort(@types);
7950: my $typestr = join(',',@types);
1.249 raeburn 7951: my $typedom = $env{'form.selfenroll_dom_'.$num};
7952: $latesttypes[$newnum] = $typedom.':'.$typestr;
7953: $currdoms{$typedom} = 1;
1.241 raeburn 7954: $newnum ++;
7955: }
7956: }
1.338 raeburn 7957: for (my $j=0; $j<$env{'form.selfenroll_types_total'}; $j++) {
7958: if ((!grep(/^$j$/,@deletedoms)) && (!grep(/^$j$/,@activations))) {
1.249 raeburn 7959: my @types = &Apache::loncommon::get_env_multiple('form.selfenroll_types_'.$j);
7960: if (@types > 0) {
7961: @types = sort(@types);
7962: my $typestr = join(',',@types);
7963: my $typedom = $env{'form.selfenroll_dom_'.$j};
7964: $latesttypes[$newnum] = $typedom.':'.$typestr;
7965: $currdoms{$typedom} = 1;
7966: $newnum ++;
7967: }
7968: }
7969: }
7970: if ($env{'form.selfenroll_newdom'} ne '') {
7971: my $typedom = $env{'form.selfenroll_newdom'};
7972: if ((!defined($currdoms{$typedom})) &&
7973: (&Apache::lonnet::domain($typedom) ne '')) {
7974: my $typestr;
7975: my ($othertitle,$usertypes,$types) =
7976: &Apache::loncommon::sorted_inst_types($typedom);
7977: my $othervalue = 'any';
7978: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
7979: if (@{$types} > 0) {
1.257 raeburn 7980: my @esc_types = map { &escape($_); } @{$types};
1.249 raeburn 7981: $othervalue = 'other';
1.258 raeburn 7982: $typestr = join(',',(@esc_types,$othervalue));
1.249 raeburn 7983: }
7984: $typestr = $othervalue;
7985: } else {
7986: $typestr = $othervalue;
7987: }
7988: $latesttypes[$newnum] = $typedom.':'.$typestr;
7989: $newnum ++ ;
7990: }
7991: }
1.241 raeburn 7992: my $selfenroll_types = join(';',@latesttypes);
7993: if ($selfenroll_types ne $curr_types) {
7994: $changes{'internal.selfenroll_types'} = $selfenroll_types;
7995: }
7996: }
1.276 raeburn 7997: } elsif ($item eq 'limit') {
7998: my $newlimit = $env{'form.selfenroll_limit'};
7999: my $newcap = $env{'form.selfenroll_cap'};
8000: $newcap =~s/\s+//g;
1.398 raeburn 8001: my $currlimit = $currsettings->{'selfenroll_limit'};
1.276 raeburn 8002: $currlimit = 'none' if ($currlimit eq '');
1.398 raeburn 8003: my $currcap = $currsettings->{'selfenroll_cap'};
1.276 raeburn 8004: if ($newlimit ne $currlimit) {
8005: if ($newlimit ne 'none') {
8006: if ($newcap =~ /^\d+$/) {
8007: if ($newcap ne $currcap) {
8008: $changes{'internal.selfenroll_cap'} = $newcap;
8009: }
8010: $changes{'internal.selfenroll_limit'} = $newlimit;
8011: } else {
1.398 raeburn 8012: $warning{$item} = &mt('Maximum enrollment setting unchanged.').'<br />'.
8013: &mt('The value provided was invalid - it must be a positive integer if enrollment is being limited.');
1.276 raeburn 8014: }
8015: } elsif ($currcap ne '') {
8016: $changes{'internal.selfenroll_cap'} = '';
8017: $changes{'internal.selfenroll_limit'} = $newlimit;
8018: }
8019: } elsif ($currlimit ne 'none') {
8020: if ($newcap =~ /^\d+$/) {
8021: if ($newcap ne $currcap) {
8022: $changes{'internal.selfenroll_cap'} = $newcap;
8023: }
8024: } else {
1.398 raeburn 8025: $warning{$item} = &mt('Maximum enrollment setting unchanged.').'<br />'.
8026: &mt('The value provided was invalid - it must be a positive integer if enrollment is being limited.');
1.276 raeburn 8027: }
8028: }
8029: } elsif ($item eq 'approval') {
8030: my (@currnotified,@newnotified);
1.398 raeburn 8031: my $currapproval = $currsettings->{'selfenroll_approval'};
8032: my $currnotifylist = $currsettings->{'selfenroll_notifylist'};
1.276 raeburn 8033: if ($currnotifylist ne '') {
8034: @currnotified = split(/,/,$currnotifylist);
8035: @currnotified = sort(@currnotified);
8036: }
8037: my $newapproval = $env{'form.selfenroll_approval'};
8038: @newnotified = &Apache::loncommon::get_env_multiple('form.selfenroll_notify');
8039: @newnotified = sort(@newnotified);
8040: if ($newapproval ne $currapproval) {
8041: $changes{'internal.selfenroll_approval'} = $newapproval;
8042: if (!$newapproval) {
8043: if ($currnotifylist ne '') {
8044: $changes{'internal.selfenroll_notifylist'} = '';
8045: }
8046: } else {
8047: my @differences =
1.295 raeburn 8048: &Apache::loncommon::compare_arrays(\@currnotified,\@newnotified);
1.276 raeburn 8049: if (@differences > 0) {
8050: if (@newnotified > 0) {
8051: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
8052: } else {
8053: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
8054: }
8055: }
8056: }
8057: } else {
1.295 raeburn 8058: my @differences = &Apache::loncommon::compare_arrays(\@currnotified,\@newnotified);
1.276 raeburn 8059: if (@differences > 0) {
8060: if (@newnotified > 0) {
8061: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
8062: } else {
8063: $changes{'internal.selfenroll_notifylist'} = '';
8064: }
8065: }
8066: }
1.237 raeburn 8067: } else {
1.398 raeburn 8068: my $curr_val = $currsettings->{'selfenroll_'.$item};
1.237 raeburn 8069: my $newval = $env{'form.selfenroll_'.$item};
8070: if ($item eq 'section') {
8071: $newval = $env{'form.sections'};
1.241 raeburn 8072: if (defined($curr_groups{$newval})) {
1.237 raeburn 8073: $newval = $curr_val;
1.398 raeburn 8074: $warning{$item} = &mt('Section for self-enrolled users unchanged as the proposed section is a group').'<br />'.
8075: &mt('Group names and section names must be distinct');
1.237 raeburn 8076: } elsif ($newval eq 'all') {
8077: $newval = $curr_val;
1.274 bisitz 8078: $warning{$item} = &mt('Section for self-enrolled users unchanged, as "all" is a reserved section name.');
1.237 raeburn 8079: }
8080: if ($newval eq '') {
8081: $newval = 'none';
8082: }
8083: }
8084: if ($newval ne $curr_val) {
8085: $changes{'internal.selfenroll_'.$item} = $newval;
8086: }
1.241 raeburn 8087: }
1.237 raeburn 8088: }
8089: if (keys(%warning) > 0) {
8090: foreach my $item (@{$row}) {
8091: if (exists($warning{$item})) {
8092: $r->print($warning{$item}.'<br />');
8093: }
8094: }
8095: }
8096: if (keys(%changes) > 0) {
8097: my $putresult = &Apache::lonnet::put('environment',\%changes,$cdom,$cnum);
8098: if ($putresult eq 'ok') {
8099: if ((exists($changes{'internal.selfenroll_types'})) ||
8100: (exists($changes{'internal.selfenroll_start_date'})) ||
8101: (exists($changes{'internal.selfenroll_end_date'}))) {
8102: my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',
8103: $cnum,undef,undef,'Course');
8104: my $chome = &Apache::lonnet::homeserver($cnum,$cdom);
1.398 raeburn 8105: if (ref($crsinfo{$cid}) eq 'HASH') {
1.237 raeburn 8106: foreach my $item ('selfenroll_types','selfenroll_start_date','selfenroll_end_date') {
8107: if (exists($changes{'internal.'.$item})) {
1.398 raeburn 8108: $crsinfo{$cid}{$item} = $changes{'internal.'.$item};
1.237 raeburn 8109: }
8110: }
8111: my $crsputresult =
8112: &Apache::lonnet::courseidput($cdom,\%crsinfo,
8113: $chome,'notime');
8114: }
8115: }
8116: $r->print(&mt('The following changes were made to self-enrollment settings:').'<ul>');
8117: foreach my $item (@{$row}) {
8118: my $title = $item;
8119: if (ref($lt) eq 'HASH') {
8120: $title = $lt->{$item};
8121: }
8122: if ($item eq 'enroll_dates') {
8123: foreach my $type ('start','end') {
8124: if (exists($changes{'internal.selfenroll_'.$type.'_date'})) {
8125: my $newdate = &Apache::lonlocal::locallocaltime($changes{'internal.selfenroll_'.$type.'_date'});
1.244 bisitz 8126: $r->print('<li>'.&mt('[_1]: "[_2]" set to "[_3]".',
1.237 raeburn 8127: $title,$type,$newdate).'</li>');
8128: }
8129: }
8130: } elsif ($item eq 'access_dates') {
8131: foreach my $type ('start','end') {
8132: if (exists($changes{'internal.selfenroll_'.$type.'_access'})) {
8133: my $newdate = &Apache::lonlocal::locallocaltime($changes{'internal.selfenroll_'.$type.'_access'});
1.244 bisitz 8134: $r->print('<li>'.&mt('[_1]: "[_2]" set to "[_3]".',
1.237 raeburn 8135: $title,$type,$newdate).'</li>');
8136: }
8137: }
1.276 raeburn 8138: } elsif ($item eq 'limit') {
8139: if ((exists($changes{'internal.selfenroll_limit'})) ||
8140: (exists($changes{'internal.selfenroll_cap'}))) {
8141: my ($newval,$newcap);
8142: if ($changes{'internal.selfenroll_cap'} ne '') {
8143: $newcap = $changes{'internal.selfenroll_cap'}
8144: } else {
1.398 raeburn 8145: $newcap = $currsettings->{'selfenroll_cap'};
1.276 raeburn 8146: }
8147: if ($changes{'internal.selfenroll_limit'} eq 'none') {
8148: $newval = &mt('No limit');
8149: } elsif ($changes{'internal.selfenroll_limit'} eq
8150: 'allstudents') {
8151: $newval = &mt('New self-enrollment no longer allowed when total (all students) reaches [_1].',$newcap);
8152: } elsif ($changes{'internal.selfenroll_limit'} eq 'selfenrolled') {
8153: $newval = &mt('New self-enrollment no longer allowed when total number of self-enrolled students reaches [_1].',$newcap);
8154: } else {
1.398 raeburn 8155: my $currlimit = $currsettings->{'selfenroll_limit'};
1.276 raeburn 8156: if ($currlimit eq 'allstudents') {
8157: $newval = &mt('New self-enrollment no longer allowed when total (all students) reaches [_1].',$newcap);
8158: } elsif ($changes{'internal.selfenroll_limit'} eq 'selfenrolled') {
1.308 raeburn 8159: $newval = &mt('New self-enrollment no longer allowed when total number of self-enrolled students reaches [_1].',$newcap);
1.276 raeburn 8160: }
8161: }
8162: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval).'</li>'."\n");
8163: }
8164: } elsif ($item eq 'approval') {
8165: if ((exists($changes{'internal.selfenroll_approval'})) ||
8166: (exists($changes{'internal.selfenroll_notifylist'}))) {
1.398 raeburn 8167: my %selfdescs = &Apache::lonuserutils::selfenroll_default_descs();
1.276 raeburn 8168: my ($newval,$newnotify);
8169: if (exists($changes{'internal.selfenroll_notifylist'})) {
8170: $newnotify = $changes{'internal.selfenroll_notifylist'};
8171: } else {
1.398 raeburn 8172: $newnotify = $currsettings->{'selfenroll_notifylist'};
1.276 raeburn 8173: }
1.398 raeburn 8174: if (exists($changes{'internal.selfenroll_approval'})) {
8175: if ($changes{'internal.selfenroll_approval'} !~ /^[012]$/) {
8176: $changes{'internal.selfenroll_approval'} = '0';
8177: }
8178: $newval = $selfdescs{'approval'}{$changes{'internal.selfenroll_approval'}};
1.276 raeburn 8179: } else {
1.398 raeburn 8180: my $currapproval = $currsettings->{'selfenroll_approval'};
8181: if ($currapproval !~ /^[012]$/) {
8182: $currapproval = 0;
1.276 raeburn 8183: }
1.398 raeburn 8184: $newval = $selfdescs{'approval'}{$currapproval};
1.276 raeburn 8185: }
8186: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval));
8187: if ($newnotify) {
1.277 raeburn 8188: $r->print('<br />'.&mt('The following will be notified when an enrollment request needs approval, or has been approved: [_1].',$newnotify));
1.276 raeburn 8189: } else {
1.277 raeburn 8190: $r->print('<br />'.&mt('No notifications sent when an enrollment request needs approval, or has been approved.'));
1.276 raeburn 8191: }
8192: $r->print('</li>'."\n");
8193: }
1.237 raeburn 8194: } else {
8195: if (exists($changes{'internal.selfenroll_'.$item})) {
1.241 raeburn 8196: my $newval = $changes{'internal.selfenroll_'.$item};
8197: if ($item eq 'types') {
8198: if ($newval eq '') {
8199: $newval = &mt('None');
8200: } elsif ($newval eq '*') {
8201: $newval = &mt('Any user in any domain');
8202: }
1.245 raeburn 8203: } elsif ($item eq 'registered') {
8204: if ($newval eq '1') {
8205: $newval = &mt('Yes');
8206: } elsif ($newval eq '0') {
8207: $newval = &mt('No');
8208: }
1.241 raeburn 8209: }
1.244 bisitz 8210: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval).'</li>'."\n");
1.237 raeburn 8211: }
8212: }
8213: }
8214: $r->print('</ul>');
1.398 raeburn 8215: if ($env{'course.'.$cid.'.description'} ne '') {
8216: my %newenvhash;
8217: foreach my $key (keys(%changes)) {
8218: $newenvhash{'course.'.$cid.'.'.$key} = $changes{$key};
8219: }
8220: &Apache::lonnet::appenv(\%newenvhash);
1.237 raeburn 8221: }
8222: } else {
1.398 raeburn 8223: $r->print(&mt('An error occurred when saving changes to self-enrollment settings in this course.').'<br />'.
8224: &mt('The error was: [_1].',$putresult));
1.237 raeburn 8225: }
8226: } else {
1.249 raeburn 8227: $r->print(&mt('No changes were made to the existing self-enrollment settings in this course.'));
1.237 raeburn 8228: }
8229: } else {
1.249 raeburn 8230: $r->print(&mt('No changes were made to the existing self-enrollment settings in this course.'));
1.241 raeburn 8231: }
1.400 raeburn 8232: my $visactions = &cat_visibility();
8233: my ($cathash,%cattype);
8234: my %domconfig = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom);
8235: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
8236: $cathash = $domconfig{'coursecategories'}{'cats'};
8237: $cattype{'auth'} = $domconfig{'coursecategories'}{'auth'};
8238: $cattype{'unauth'} = $domconfig{'coursecategories'}{'unauth'};
8239: } else {
8240: $cathash = {};
8241: $cattype{'auth'} = 'std';
8242: $cattype{'unauth'} = 'std';
8243: }
8244: if (($cattype{'auth'} eq 'none') && ($cattype{'unauth'} eq 'none')) {
8245: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
8246: '<br />'.
8247: '<br />'.$visactions->{'take'}.'<ul>'.
8248: '<li>'.$visactions->{'dc_chgconf'}.'</li>'.
8249: '</ul>');
8250: } elsif (($cattype{'auth'} !~ /^(std|domonly)$/) && ($cattype{'unauth'} !~ /^(std|domonly)$/)) {
8251: if ($currsettings->{'uniquecode'}) {
8252: $r->print('<span class="LC_info">'.$visactions->{'vis'}.'</span>');
8253: } else {
1.366 bisitz 8254: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
1.400 raeburn 8255: '<br />'.
8256: '<br />'.$visactions->{'take'}.'<ul>'.
8257: '<li>'.$visactions->{'dc_setcode'}.'</li>'.
8258: '</ul><br />');
8259: }
8260: } else {
8261: my ($visible,$cansetvis,$vismsgs) = &visible_in_stdcat($cdom,$cnum,\%domconfig);
8262: if (ref($visactions) eq 'HASH') {
8263: if (!$visible) {
8264: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
8265: '<br />');
8266: if (ref($vismsgs) eq 'ARRAY') {
8267: $r->print('<br />'.$visactions->{'take'}.'<ul>');
8268: foreach my $item (@{$vismsgs}) {
8269: $r->print('<li>'.$visactions->{$item}.'</li>');
8270: }
8271: $r->print('</ul>');
1.256 raeburn 8272: }
1.400 raeburn 8273: $r->print($cansetvis);
1.256 raeburn 8274: }
8275: }
8276: }
1.237 raeburn 8277: return;
8278: }
8279:
1.27 matthew 8280: #---------------------------------------------- end functions for &phase_two
1.29 matthew 8281:
8282: #--------------------------------- functions for &phase_two and &phase_three
8283:
8284: #--------------------------end of functions for &phase_two and &phase_three
1.372 raeburn 8285:
1.1 www 8286: 1;
8287: __END__
1.2 www 8288:
8289:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>