Annotation of loncom/interface/loncreateuser.pm, revision 1.406.2.13
1.20 harris41 1: # The LearningOnline Network with CAPA
1.1 www 2: # Create a user
3: #
1.406.2.13! raeburn 4: # $Id: loncreateuser.pm,v 1.406.2.12 2017/01/30 18:37:34 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:
1.406.2.6 raeburn 163: if ((&Apache::lonnet::allowed('mut',$ccdomain)) ||
164: (&Apache::lonnet::allowed('udp',$ccdomain))) {
1.275 raeburn 165: $output .= &build_tools_display($ccuname,$ccdomain,'tools');
1.267 raeburn 166: }
1.378 raeburn 167:
168: my %titles = &Apache::lonlocal::texthash (
169: portfolio => "Disk space allocated to user's portfolio files",
1.385 bisitz 170: author => "Disk space allocated to user's Authoring Space (if role assigned)",
1.378 raeburn 171: );
172: foreach my $name ('portfolio','author') {
173: my ($currquota,$quotatype,$inststatus,$defquota) =
174: &Apache::loncommon::get_user_quota($ccuname,$ccdomain,$name);
175: if ($longinsttype eq '') {
176: if ($inststatus ne '') {
177: if ($usertypes->{$inststatus} ne '') {
178: $longinsttype = $usertypes->{$inststatus};
179: }
180: }
181: }
182: my ($showquota,$custom_on,$custom_off,$defaultinfo);
183: $custom_on = ' ';
184: $custom_off = ' checked="checked" ';
185: if ($quotatype eq 'custom') {
186: $custom_on = $custom_off;
187: $custom_off = ' ';
188: $showquota = $currquota;
189: if ($longinsttype eq '') {
190: $defaultinfo = &mt('For this user, the default quota would be [_1]'
1.383 raeburn 191: .' MB.',$defquota);
1.378 raeburn 192: } else {
193: $defaultinfo = &mt("For this user, the default quota would be [_1]".
1.383 raeburn 194: " MB, as determined by the user's institutional".
1.378 raeburn 195: " affiliation ([_2]).",$defquota,$longinsttype);
196: }
197: } else {
198: if ($longinsttype eq '') {
199: $defaultinfo = &mt('For this user, the default quota is [_1]'
1.383 raeburn 200: .' MB.',$defquota);
1.378 raeburn 201: } else {
202: $defaultinfo = &mt("For this user, the default quota of [_1]".
1.383 raeburn 203: " MB, is determined by the user's institutional".
1.378 raeburn 204: " affiliation ([_2]).",$defquota,$longinsttype);
205: }
206: }
207:
208: if (&Apache::lonnet::allowed('mpq',$ccdomain)) {
209: $output .= '<tr class="LC_info_row">'."\n".
210: ' <td>'.$titles{$name}.'</td>'."\n".
211: ' </tr>'."\n".
212: &Apache::loncommon::start_data_table_row()."\n".
1.390 bisitz 213: ' <td><span class="LC_nobreak">'.
214: &mt('Current quota: [_1] MB',$currquota).'</span> '.
1.378 raeburn 215: $defaultinfo.'</td>'."\n".
216: &Apache::loncommon::end_data_table_row()."\n".
217: &Apache::loncommon::start_data_table_row()."\n".
218: ' <td><span class="LC_nobreak">'.$lt{'chqu'}.
219: ': <label>'.
220: '<input type="radio" name="custom_'.$name.'quota" id="custom_'.$name.'quota_off" '.
1.379 raeburn 221: 'value="0" '.$custom_off.' onchange="javascript:quota_changes('."'custom','$name'".');"'.
1.390 bisitz 222: ' /><span class="LC_nobreak">'.
223: &mt('Default ([_1] MB)',$defquota).'</span></label> '.
1.378 raeburn 224: ' <label><input type="radio" name="custom_'.$name.'quota" id="custom_'.$name.'quota_on" '.
1.379 raeburn 225: 'value="1" '.$custom_on.' onchange="javascript:quota_changes('."'custom','$name'".');"'.
1.378 raeburn 226: ' />'.$lt{'cust'}.':</label> '.
1.379 raeburn 227: '<input type="text" name="'.$name.'quota" id="'.$name.'quota" size ="5" '.
228: 'value="'.$showquota.'" onfocus="javascript:quota_changes('."'quota','$name'".');"'.
1.390 bisitz 229: ' /> '.&mt('MB').'</span></td>'."\n".
1.378 raeburn 230: &Apache::loncommon::end_data_table_row()."\n";
231: }
232: }
1.267 raeburn 233: $output .= &Apache::loncommon::end_data_table();
1.134 raeburn 234: return $output;
235: }
236:
1.275 raeburn 237: sub build_tools_display {
238: my ($ccuname,$ccdomain,$context) = @_;
1.306 raeburn 239: my (@usertools,%userenv,$output,@options,%validations,%reqtitles,%reqdisplay,
1.332 raeburn 240: $colspan,$isadv,%domconfig);
1.275 raeburn 241: my %lt = &Apache::lonlocal::texthash (
242: 'blog' => "Personal User Blog",
243: 'aboutme' => "Personal Information Page",
1.385 bisitz 244: 'webdav' => "WebDAV access to Authoring Spaces (if SSL and author/co-author)",
1.275 raeburn 245: 'portfolio' => "Personal User Portfolio",
246: 'avai' => "Available",
247: 'cusa' => "availability",
248: 'chse' => "Change setting",
249: 'usde' => "Use default",
250: 'uscu' => "Use custom",
251: 'official' => 'Can request creation of official courses',
1.299 raeburn 252: 'unofficial' => 'Can request creation of unofficial courses',
253: 'community' => 'Can request creation of communities',
1.384 raeburn 254: 'textbook' => 'Can request creation of textbook courses',
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.384 raeburn 260: 'requestcourses.community','requestcourses.textbook');
261: @usertools = ('official','unofficial','community','textbook');
1.309 raeburn 262: @options =('norequest','approval','autolimit','validate');
1.306 raeburn 263: %validations = &Apache::lonnet::auto_courserequest_checks($ccdomain);
264: %reqtitles = &courserequest_titles();
265: %reqdisplay = &courserequest_display();
266: $colspan = ' colspan="2"';
1.332 raeburn 267: %domconfig =
268: &Apache::lonnet::get_dom('configuration',['requestcourses'],$ccdomain);
1.406.2.6 raeburn 269: $isadv = &Apache::lonnet::is_advanced_user($ccdomain,$ccuname);
1.362 raeburn 270: } elsif ($context eq 'requestauthor') {
271: %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
272: 'requestauthor');
273: @usertools = ('requestauthor');
274: @options =('norequest','approval','automatic');
275: %reqtitles = &requestauthor_titles();
276: %reqdisplay = &requestauthor_display();
277: $colspan = ' colspan="2"';
278: %domconfig =
279: &Apache::lonnet::get_dom('configuration',['requestauthor'],$ccdomain);
1.275 raeburn 280: } else {
281: %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
1.361 raeburn 282: 'tools.aboutme','tools.portfolio','tools.blog',
283: 'tools.webdav');
284: @usertools = ('aboutme','blog','webdav','portfolio');
1.275 raeburn 285: }
286: foreach my $item (@usertools) {
1.306 raeburn 287: my ($custom_access,$curr_access,$cust_on,$cust_off,$tool_on,$tool_off,
288: $currdisp,$custdisp,$custradio);
1.275 raeburn 289: $cust_off = 'checked="checked" ';
290: $tool_on = 'checked="checked" ';
291: $curr_access =
292: &Apache::lonnet::usertools_access($ccuname,$ccdomain,$item,undef,
293: $context);
1.362 raeburn 294: if ($context eq 'requestauthor') {
295: if ($userenv{$context} ne '') {
296: $cust_on = ' checked="checked" ';
297: $cust_off = '';
298: }
299: } elsif ($userenv{$context.'.'.$item} ne '') {
1.306 raeburn 300: $cust_on = ' checked="checked" ';
301: $cust_off = '';
302: }
303: if ($context eq 'requestcourses') {
304: if ($userenv{$context.'.'.$item} eq '') {
1.314 raeburn 305: $custom_access = &mt('Currently from default setting.');
1.306 raeburn 306: } else {
307: $custom_access = &mt('Currently from custom setting.');
1.275 raeburn 308: }
1.362 raeburn 309: } elsif ($context eq 'requestauthor') {
310: if ($userenv{$context} eq '') {
311: $custom_access = &mt('Currently from default setting.');
312: } else {
313: $custom_access = &mt('Currently from custom setting.');
314: }
1.275 raeburn 315: } else {
1.306 raeburn 316: if ($userenv{$context.'.'.$item} eq '') {
1.314 raeburn 317: $custom_access =
1.306 raeburn 318: &mt('Availability determined currently from default setting.');
319: if (!$curr_access) {
320: $tool_off = 'checked="checked" ';
321: $tool_on = '';
322: }
323: } else {
1.314 raeburn 324: $custom_access =
1.306 raeburn 325: &mt('Availability determined currently from custom setting.');
326: if ($userenv{$context.'.'.$item} == 0) {
327: $tool_off = 'checked="checked" ';
328: $tool_on = '';
329: }
1.275 raeburn 330: }
331: }
332: $output .= ' <tr class="LC_info_row">'."\n".
1.306 raeburn 333: ' <td'.$colspan.'>'.$lt{$item}.'</td>'."\n".
1.275 raeburn 334: ' </tr>'."\n".
1.306 raeburn 335: &Apache::loncommon::start_data_table_row()."\n";
1.362 raeburn 336: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.306 raeburn 337: my ($curroption,$currlimit);
1.362 raeburn 338: my $envkey = $context.'.'.$item;
339: if ($context eq 'requestauthor') {
340: $envkey = $context;
341: }
342: if ($userenv{$envkey} ne '') {
343: $curroption = $userenv{$envkey};
1.332 raeburn 344: } else {
345: my (@inststatuses);
1.362 raeburn 346: if ($context eq 'requestcourses') {
347: $curroption =
348: &Apache::loncoursequeueadmin::get_processtype('course',$ccuname,$ccdomain,
349: $isadv,$ccdomain,$item,
350: \@inststatuses,\%domconfig);
351: } else {
352: $curroption =
353: &Apache::loncoursequeueadmin::get_processtype('requestauthor',$ccuname,$ccdomain,
354: $isadv,$ccdomain,undef,
355: \@inststatuses,\%domconfig);
356: }
1.332 raeburn 357: }
1.306 raeburn 358: if (!$curroption) {
359: $curroption = 'norequest';
360: }
361: if ($curroption =~ /^autolimit=(\d*)$/) {
362: $currlimit = $1;
1.314 raeburn 363: if ($currlimit eq '') {
364: $currdisp = &mt('Yes, automatic creation');
365: } else {
366: $currdisp = &mt('Yes, up to [quant,_1,request]/user',$currlimit);
367: }
1.306 raeburn 368: } else {
369: $currdisp = $reqdisplay{$curroption};
370: }
371: $custdisp = '<table>';
372: foreach my $option (@options) {
373: my $val = $option;
374: if ($option eq 'norequest') {
375: $val = 0;
376: }
377: if ($option eq 'validate') {
378: my $canvalidate = 0;
379: if (ref($validations{$item}) eq 'HASH') {
380: if ($validations{$item}{'_custom_'}) {
381: $canvalidate = 1;
382: }
383: }
384: next if (!$canvalidate);
385: }
386: my $checked = '';
387: if ($option eq $curroption) {
388: $checked = ' checked="checked"';
389: } elsif ($option eq 'autolimit') {
390: if ($curroption =~ /^autolimit/) {
391: $checked = ' checked="checked"';
392: }
393: }
1.362 raeburn 394: my $name = 'crsreq_'.$item;
395: if ($context eq 'requestauthor') {
396: $name = $item;
397: }
1.306 raeburn 398: $custdisp .= '<tr><td><span class="LC_nobreak"><label>'.
1.362 raeburn 399: '<input type="radio" name="'.$name.'" '.
400: 'value="'.$val.'"'.$checked.' />'.
1.306 raeburn 401: $reqtitles{$option}.'</label> ';
402: if ($option eq 'autolimit') {
1.362 raeburn 403: $custdisp .= '<input type="text" name="'.$name.
404: '_limit" size="1" '.
1.314 raeburn 405: 'value="'.$currlimit.'" /></span><br />'.
406: $reqtitles{'unlimited'};
1.362 raeburn 407: } else {
408: $custdisp .= '</span>';
409: }
410: $custdisp .= '</td></tr>';
1.306 raeburn 411: }
412: $custdisp .= '</table>';
413: $custradio = '</span></td><td>'.&mt('Custom setting').'<br />'.$custdisp;
414: } else {
415: $currdisp = ($curr_access?&mt('Yes'):&mt('No'));
1.362 raeburn 416: my $name = $context.'_'.$item;
417: if ($context eq 'requestauthor') {
418: $name = $context;
419: }
1.306 raeburn 420: $custdisp = '<span class="LC_nobreak"><label>'.
1.362 raeburn 421: '<input type="radio" name="'.$name.'"'.
1.361 raeburn 422: ' value="1" '.$tool_on.'/>'.&mt('On').'</label> <label>'.
1.362 raeburn 423: '<input type="radio" name="'.$name.'" value="0" '.
1.306 raeburn 424: $tool_off.'/>'.&mt('Off').'</label></span>';
425: $custradio = (' 'x2).'--'.$lt{'cusa'}.': '.$custdisp.
426: '</span>';
427: }
428: $output .= ' <td'.$colspan.'>'.$custom_access.(' 'x4).
429: $lt{'avai'}.': '.$currdisp.'</td>'."\n".
1.406.2.6 raeburn 430: &Apache::loncommon::end_data_table_row()."\n";
431: unless (&Apache::lonnet::allowed('udp',$ccdomain)) {
432: $output .=
1.275 raeburn 433: &Apache::loncommon::start_data_table_row()."\n".
1.306 raeburn 434: ' <td style="vertical-align:top;"><span class="LC_nobreak">'.
435: $lt{'chse'}.': <label>'.
1.275 raeburn 436: '<input type="radio" name="custom'.$item.'" value="0" '.
1.306 raeburn 437: $cust_off.'/>'.$lt{'usde'}.'</label>'.(' ' x3).
438: '<label><input type="radio" name="custom'.$item.'" value="1" '.
439: $cust_on.'/>'.$lt{'uscu'}.'</label>'.$custradio.'</td>'.
1.275 raeburn 440: &Apache::loncommon::end_data_table_row()."\n";
1.406.2.6 raeburn 441: }
1.275 raeburn 442: }
443: return $output;
444: }
445:
1.300 raeburn 446: sub coursereq_externaluser {
447: my ($ccuname,$ccdomain,$cdom) = @_;
1.306 raeburn 448: my (@usertools,@options,%validations,%userenv,$output);
1.300 raeburn 449: my %lt = &Apache::lonlocal::texthash (
450: 'official' => 'Can request creation of official courses',
451: 'unofficial' => 'Can request creation of unofficial courses',
452: 'community' => 'Can request creation of communities',
1.384 raeburn 453: 'textbook' => 'Can request creation of textbook courses',
1.300 raeburn 454: );
455:
456: %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
457: 'reqcrsotherdom.official','reqcrsotherdom.unofficial',
1.384 raeburn 458: 'reqcrsotherdom.community','reqcrsotherdom.textbook');
459: @usertools = ('official','unofficial','community','textbook');
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.306 raeburn 534: sub courserequest_titles {
535: my %titles = &Apache::lonlocal::texthash (
536: official => 'Official',
537: unofficial => 'Unofficial',
538: community => 'Communities',
1.384 raeburn 539: textbook => 'Textbook',
1.306 raeburn 540: norequest => 'Not allowed',
1.309 raeburn 541: approval => 'Approval by Dom. Coord.',
1.306 raeburn 542: validate => 'With validation',
543: autolimit => 'Numerical limit',
1.314 raeburn 544: unlimited => '(blank for unlimited)',
1.306 raeburn 545: );
546: return %titles;
547: }
548:
549: sub courserequest_display {
550: my %titles = &Apache::lonlocal::texthash (
1.309 raeburn 551: approval => 'Yes, need approval',
1.306 raeburn 552: validate => 'Yes, with validation',
553: norequest => 'No',
554: );
555: return %titles;
556: }
557:
1.362 raeburn 558: sub requestauthor_titles {
559: my %titles = &Apache::lonlocal::texthash (
560: norequest => 'Not allowed',
561: approval => 'Approval by Dom. Coord.',
562: automatic => 'Automatic approval',
563: );
564: return %titles;
565:
566: }
567:
568: sub requestauthor_display {
569: my %titles = &Apache::lonlocal::texthash (
570: approval => 'Yes, need approval',
571: automatic => 'Yes, automatic approval',
572: norequest => 'No',
573: );
574: return %titles;
575: }
576:
1.383 raeburn 577: sub requestchange_display {
578: my %titles = &Apache::lonlocal::texthash (
579: approval => "availability set to 'on' (approval required)",
580: automatic => "availability set to 'on' (automatic approval)",
581: norequest => "availability set to 'off'",
582: );
583: return %titles;
584: }
585:
1.362 raeburn 586: sub curr_requestauthor {
587: my ($uname,$udom,$isadv,$inststatuses,$domconfig) = @_;
588: return unless ((ref($inststatuses) eq 'ARRAY') && (ref($domconfig) eq 'HASH'));
589: if ($uname eq '' || $udom eq '') {
590: $uname = $env{'user.name'};
591: $udom = $env{'user.domain'};
592: $isadv = $env{'user.adv'};
593: }
594: my (%userenv,%settings,$val);
595: my @options = ('automatic','approval');
596: %userenv =
597: &Apache::lonnet::userenvironment($udom,$uname,'requestauthor','inststatus');
598: if ($userenv{'requestauthor'}) {
599: $val = $userenv{'requestauthor'};
600: @{$inststatuses} = ('_custom_');
601: } else {
602: my %alltasks;
603: if (ref($domconfig->{'requestauthor'}) eq 'HASH') {
604: %settings = %{$domconfig->{'requestauthor'}};
605: if (($isadv) && ($settings{'_LC_adv'} ne '')) {
606: $val = $settings{'_LC_adv'};
607: @{$inststatuses} = ('_LC_adv_');
608: } else {
609: if ($userenv{'inststatus'} ne '') {
610: @{$inststatuses} = split(',',$userenv{'inststatus'});
611: } else {
612: @{$inststatuses} = ('default');
613: }
614: foreach my $status (@{$inststatuses}) {
615: if (exists($settings{$status})) {
616: my $value = $settings{$status};
617: next unless ($value);
618: unless (exists($alltasks{$value})) {
619: if (ref($alltasks{$value}) eq 'ARRAY') {
620: unless(grep(/^\Q$status\E$/,@{$alltasks{$value}})) {
621: push(@{$alltasks{$value}},$status);
622: }
623: } else {
624: @{$alltasks{$value}} = ($status);
625: }
626: }
627: }
628: }
629: foreach my $option (@options) {
630: if ($alltasks{$option}) {
631: $val = $option;
632: last;
633: }
634: }
635: }
636: }
637: }
638: return $val;
639: }
640:
1.2 www 641: # =================================================================== Phase one
1.1 www 642:
1.42 matthew 643: sub print_username_entry_form {
1.351 raeburn 644: my ($r,$context,$response,$srch,$forcenewuser,$crstype,$brcrum) = @_;
1.101 albertel 645: my $defdom=$env{'request.role.domain'};
1.160 raeburn 646: my $formtoset = 'crtuser';
647: if (exists($env{'form.startrolename'})) {
648: $formtoset = 'docustom';
649: $env{'form.rolename'} = $env{'form.startrolename'};
1.207 raeburn 650: } elsif ($env{'form.origform'} eq 'crtusername') {
651: $formtoset = $env{'form.origform'};
1.160 raeburn 652: }
653:
654: my ($jsback,$elements) = &crumb_utilities();
655:
656: my $jscript = &Apache::loncommon::studentbrowser_javascript()."\n".
1.165 albertel 657: '<script type="text/javascript">'."\n".
1.301 bisitz 658: '// <![CDATA['."\n".
659: &Apache::lonhtmlcommon::set_form_elements($elements->{$formtoset})."\n".
660: '// ]]>'."\n".
1.162 raeburn 661: '</script>'."\n";
1.160 raeburn 662:
1.324 raeburn 663: my %existingroles=&Apache::lonuserutils::my_custom_roles($crstype);
664: if (($env{'form.action'} eq 'custom') && (keys(%existingroles) > 0)
665: && (&Apache::lonnet::allowed('mcr','/'))) {
666: $jscript .= &customrole_javascript();
667: }
1.224 raeburn 668: my $helpitem = 'Course_Change_Privileges';
669: if ($env{'form.action'} eq 'custom') {
670: $helpitem = 'Course_Editing_Custom_Roles';
671: } elsif ($env{'form.action'} eq 'singlestudent') {
672: $helpitem = 'Course_Add_Student';
1.406.2.5 raeburn 673: } elsif ($env{'form.action'} eq 'accesslogs') {
674: $helpitem = 'Domain_User_Access_Logs';
1.224 raeburn 675: }
1.406.2.7 raeburn 676: my %breadcrumb_text = &singleuser_breadcrumb($crstype,$context,$defdom);
1.351 raeburn 677: if ($env{'form.action'} eq 'custom') {
678: push(@{$brcrum},
679: {href=>"javascript:backPage(document.crtuser)",
680: text=>"Pick custom role",
681: help => $helpitem,}
682: );
683: } else {
684: push (@{$brcrum},
685: {href => "javascript:backPage(document.crtuser)",
686: text => $breadcrumb_text{'search'},
687: help => $helpitem,
688: faq => 282,
689: bug => 'Instructor Interface',}
690: );
691: }
692: my %loaditems = (
693: 'onload' => "javascript:setFormElements(document.$formtoset)",
694: );
695: my $args = {bread_crumbs => $brcrum,
696: bread_crumbs_component => 'User Management',
697: add_entries => \%loaditems,};
698: $r->print(&Apache::loncommon::start_page('User Management',$jscript,$args));
699:
1.71 sakharuk 700: my %lt=&Apache::lonlocal::texthash(
1.229 raeburn 701: 'srst' => 'Search for a user and enroll as a student',
1.318 raeburn 702: 'srme' => 'Search for a user and enroll as a member',
1.229 raeburn 703: 'srad' => 'Search for a user and modify/add user information or roles',
1.406.2.7 raeburn 704: 'srvu' => 'Search for a user and view user information and roles',
1.406.2.5 raeburn 705: 'srva' => 'Search for a user and view access log information',
1.71 sakharuk 706: 'usr' => "Username",
707: 'dom' => "Domain",
1.324 raeburn 708: 'ecrp' => "Define or Edit Custom Role",
709: 'nr' => "role name",
1.282 schafran 710: 'cre' => "Next",
1.71 sakharuk 711: );
1.351 raeburn 712:
1.214 raeburn 713: if ($env{'form.action'} eq 'custom') {
1.190 raeburn 714: if (&Apache::lonnet::allowed('mcr','/')) {
1.324 raeburn 715: my $newroletext = &mt('Define new custom role:');
716: $r->print('<form action="/adm/createuser" method="post" name="docustom">'.
717: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'.
718: '<input type="hidden" name="phase" value="selected_custom_edit" />'.
719: '<h3>'.$lt{'ecrp'}.'</h3>'.
720: &Apache::loncommon::start_data_table().
721: &Apache::loncommon::start_data_table_row().
722: '<td>');
723: if (keys(%existingroles) > 0) {
724: $r->print('<br /><label><input type="radio" name="customroleaction" value="new" checked="checked" onclick="setCustomFields();" /><b>'.$newroletext.'</b></label>');
725: } else {
726: $r->print('<br /><input type="hidden" name="customroleaction" value="new" /><b>'.$newroletext.'</b>');
727: }
728: $r->print('</td><td align="center">'.$lt{'nr'}.'<br /><input type="text" size="15" name="newrolename" onfocus="setCustomAction('."'new'".');" /></td>'.
729: &Apache::loncommon::end_data_table_row());
730: if (keys(%existingroles) > 0) {
731: $r->print(&Apache::loncommon::start_data_table_row().'<td><br />'.
732: '<label><input type="radio" name="customroleaction" value="edit" onclick="setCustomFields();"/><b>'.
733: &mt('View/Modify existing role:').'</b></label></td>'.
734: '<td align="center"><br />'.
735: '<select name="rolename" onchange="setCustomAction('."'edit'".');">'.
1.326 raeburn 736: '<option value="" selected="selected">'.
1.324 raeburn 737: &mt('Select'));
738: foreach my $role (sort(keys(%existingroles))) {
1.326 raeburn 739: $r->print('<option value="'.$role.'">'.$role.'</option>');
1.324 raeburn 740: }
741: $r->print('</select>'.
742: '</td>'.
743: &Apache::loncommon::end_data_table_row());
744: }
745: $r->print(&Apache::loncommon::end_data_table().'<p>'.
746: '<input name="customeditor" type="submit" value="'.
747: $lt{'cre'}.'" /></p>'.
748: '</form>');
1.190 raeburn 749: }
1.213 raeburn 750: } else {
1.229 raeburn 751: my $actiontext = $lt{'srad'};
1.406.2.13! raeburn 752: my $fixeddom;
1.213 raeburn 753: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 754: if ($crstype eq 'Community') {
755: $actiontext = $lt{'srme'};
756: } else {
757: $actiontext = $lt{'srst'};
758: }
1.406.2.5 raeburn 759: } elsif ($env{'form.action'} eq 'accesslogs') {
760: $actiontext = $lt{'srva'};
1.406.2.13! raeburn 761: $fixeddom = 1;
1.406.2.7 raeburn 762: } elsif (($env{'form.action'} eq 'singleuser') &&
763: ($context eq 'domain') && (!&Apache::lonnet::allowed('mau',$defdom))) {
764: $actiontext = $lt{'srvu'};
1.213 raeburn 765: }
1.324 raeburn 766: $r->print("<h3>$actiontext</h3>");
1.213 raeburn 767: if ($env{'form.origform'} ne 'crtusername') {
1.406.2.5 raeburn 768: if ($response) {
769: $r->print("\n<div>$response</div>".
770: '<br clear="all" />');
771: }
1.213 raeburn 772: }
1.406.2.13! raeburn 773: $r->print(&entry_form($defdom,$srch,$forcenewuser,$context,$response,$crstype,$fixeddom));
1.107 www 774: }
1.110 albertel 775: }
776:
1.324 raeburn 777: sub customrole_javascript {
778: my $js = <<"END";
779: <script type="text/javascript">
780: // <![CDATA[
781:
782: function setCustomFields() {
783: if (document.docustom.customroleaction.length > 0) {
784: for (var i=0; i<document.docustom.customroleaction.length; i++) {
785: if (document.docustom.customroleaction[i].checked) {
786: if (document.docustom.customroleaction[i].value == 'new') {
787: document.docustom.rolename.selectedIndex = 0;
788: } else {
789: document.docustom.newrolename.value = '';
790: }
791: }
792: }
793: }
794: return;
795: }
796:
797: function setCustomAction(caller) {
798: if (document.docustom.customroleaction.length > 0) {
799: for (var i=0; i<document.docustom.customroleaction.length; i++) {
800: if (document.docustom.customroleaction[i].value == caller) {
801: document.docustom.customroleaction[i].checked = true;
802: }
803: }
804: }
805: setCustomFields();
806: return;
807: }
808:
809: // ]]>
810: </script>
811: END
812: return $js;
813: }
814:
1.160 raeburn 815: sub entry_form {
1.406.2.5 raeburn 816: my ($dom,$srch,$forcenewuser,$context,$responsemsg,$crstype,$fixeddom) = @_;
1.229 raeburn 817: my ($usertype,$inexact);
1.214 raeburn 818: if (ref($srch) eq 'HASH') {
819: if (($srch->{'srchin'} eq 'dom') &&
820: ($srch->{'srchby'} eq 'uname') &&
821: ($srch->{'srchtype'} eq 'exact') &&
822: ($srch->{'srchdomain'} ne '') &&
823: ($srch->{'srchterm'} ne '')) {
1.353 raeburn 824: my (%curr_rules,%got_rules);
1.214 raeburn 825: my ($rules,$ruleorder) =
826: &Apache::lonnet::inst_userrules($srch->{'srchdomain'},'username');
1.353 raeburn 827: $usertype = &Apache::lonuserutils::check_usertype($srch->{'srchdomain'},$srch->{'srchterm'},$rules,\%curr_rules,\%got_rules);
1.229 raeburn 828: } else {
829: $inexact = 1;
1.214 raeburn 830: }
1.207 raeburn 831: }
1.214 raeburn 832: my $cancreate =
833: &Apache::lonuserutils::can_create_user($dom,$context,$usertype);
1.406.2.3 raeburn 834: my ($userpicker,$cansearch) =
1.179 raeburn 835: &Apache::loncommon::user_picker($dom,$srch,$forcenewuser,
1.406.2.5 raeburn 836: 'document.crtuser',$cancreate,$usertype,$context,$fixeddom);
1.160 raeburn 837: my $srchbutton = &mt('Search');
1.229 raeburn 838: if ($env{'form.action'} eq 'singlestudent') {
839: $srchbutton = &mt('Search and Enroll');
1.406.2.5 raeburn 840: } elsif ($env{'form.action'} eq 'accesslogs') {
841: $srchbutton = &mt('Search');
1.229 raeburn 842: } elsif ($cancreate && $responsemsg ne '' && $inexact) {
843: $srchbutton = &mt('Search or Add New User');
844: }
1.406.2.3 raeburn 845: my $output;
846: if ($cansearch) {
847: $output = <<"ENDBLOCK";
1.160 raeburn 848: <form action="/adm/createuser" method="post" name="crtuser">
1.190 raeburn 849: <input type="hidden" name="action" value="$env{'form.action'}" />
1.160 raeburn 850: <input type="hidden" name="phase" value="get_user_info" />
851: $userpicker
1.179 raeburn 852: <input name="userrole" type="button" value="$srchbutton" onclick="javascript:validateEntry(document.crtuser)" />
1.160 raeburn 853: </form>
1.207 raeburn 854: ENDBLOCK
1.406.2.3 raeburn 855: } else {
856: $output = '<p>'.$userpicker.'</p>';
857: }
1.406.2.7 raeburn 858: if (($env{'form.phase'} eq '') && ($env{'form.action'} ne 'accesslogs') &&
859: (!(($env{'form.action'} eq 'singleuser') && ($context eq 'domain') &&
860: (!&Apache::lonnet::allowed('mau',$env{'request.role.domain'}))))) {
1.207 raeburn 861: my $defdom=$env{'request.role.domain'};
862: my $domform = &Apache::loncommon::select_dom_form($defdom,'srchdomain');
863: my %lt=&Apache::lonlocal::texthash(
1.229 raeburn 864: 'enro' => 'Enroll one student',
1.318 raeburn 865: 'enrm' => 'Enroll one member',
1.229 raeburn 866: 'admo' => 'Add/modify a single user',
867: 'crea' => 'create new user if required',
868: 'uskn' => "username is known",
1.207 raeburn 869: 'crnu' => 'Create a new user',
870: 'usr' => 'Username',
871: 'dom' => 'in domain',
1.229 raeburn 872: 'enrl' => 'Enroll',
873: 'cram' => 'Create/Modify user',
1.207 raeburn 874: );
1.229 raeburn 875: my $sellink=&Apache::loncommon::selectstudent_link('crtusername','srchterm','srchdomain');
876: my ($title,$buttontext,$showresponse);
1.318 raeburn 877: if ($env{'form.action'} eq 'singlestudent') {
878: if ($crstype eq 'Community') {
879: $title = $lt{'enrm'};
880: } else {
881: $title = $lt{'enro'};
882: }
1.229 raeburn 883: $buttontext = $lt{'enrl'};
884: } else {
885: $title = $lt{'admo'};
886: $buttontext = $lt{'cram'};
887: }
888: if ($cancreate) {
889: $title .= ' <span class="LC_cusr_subheading">('.$lt{'crea'}.')</span>';
890: } else {
891: $title .= ' <span class="LC_cusr_subheading">('.$lt{'uskn'}.')</span>';
892: }
893: if ($env{'form.origform'} eq 'crtusername') {
894: $showresponse = $responsemsg;
895: }
1.207 raeburn 896: $output .= <<"ENDDOCUMENT";
1.229 raeburn 897: <br />
1.207 raeburn 898: <form action="/adm/createuser" method="post" name="crtusername">
899: <input type="hidden" name="action" value="$env{'form.action'}" />
900: <input type="hidden" name="phase" value="createnewuser" />
901: <input type="hidden" name="srchtype" value="exact" />
1.233 raeburn 902: <input type="hidden" name="srchby" value="uname" />
1.207 raeburn 903: <input type="hidden" name="srchin" value="dom" />
904: <input type="hidden" name="forcenewuser" value="1" />
905: <input type="hidden" name="origform" value="crtusername" />
1.229 raeburn 906: <h3>$title</h3>
907: $showresponse
1.207 raeburn 908: <table>
909: <tr>
910: <td>$lt{'usr'}:</td>
911: <td><input type="text" size="15" name="srchterm" /></td>
912: <td> $lt{'dom'}:</td><td>$domform</td>
1.229 raeburn 913: <td> $sellink </td>
914: <td> <input name="userrole" type="submit" value="$buttontext" /></td>
1.207 raeburn 915: </tr>
916: </table>
917: </form>
1.160 raeburn 918: ENDDOCUMENT
1.207 raeburn 919: }
1.160 raeburn 920: return $output;
921: }
1.110 albertel 922:
923: sub user_modification_js {
1.113 raeburn 924: my ($pjump_def,$dc_setcourse_code,$nondc_setsection_code,$groupslist)=@_;
925:
1.110 albertel 926: return <<END;
927: <script type="text/javascript" language="Javascript">
1.301 bisitz 928: // <![CDATA[
1.314 raeburn 929:
1.110 albertel 930: $pjump_def
931: $dc_setcourse_code
932:
933: function dateset() {
934: eval("document.cu."+document.cu.pres_marker.value+
935: ".value=document.cu.pres_value.value");
1.359 www 936: modalWindow.close();
1.110 albertel 937: }
938:
1.113 raeburn 939: $nondc_setsection_code
1.301 bisitz 940: // ]]>
1.110 albertel 941: </script>
942: END
1.2 www 943: }
944:
945: # =================================================================== Phase two
1.160 raeburn 946: sub print_user_selection_page {
1.351 raeburn 947: my ($r,$response,$srch,$srch_results,$srcharray,$context,$opener_elements,$crstype,$brcrum) = @_;
1.160 raeburn 948: my @fields = ('username','domain','lastname','firstname','permanentemail');
949: my $sortby = $env{'form.sortby'};
950:
951: if (!grep(/^\Q$sortby\E$/,@fields)) {
952: $sortby = 'lastname';
953: }
954:
955: my ($jsback,$elements) = &crumb_utilities();
956:
957: my $jscript = (<<ENDSCRIPT);
958: <script type="text/javascript">
1.301 bisitz 959: // <![CDATA[
1.160 raeburn 960: function pickuser(uname,udom) {
961: document.usersrchform.seluname.value=uname;
962: document.usersrchform.seludom.value=udom;
963: document.usersrchform.phase.value="userpicked";
964: document.usersrchform.submit();
965: }
966:
967: $jsback
1.301 bisitz 968: // ]]>
1.160 raeburn 969: </script>
970: ENDSCRIPT
971:
972: my %lt=&Apache::lonlocal::texthash(
1.179 raeburn 973: 'usrch' => "User Search to add/modify roles",
974: 'stusrch' => "User Search to enroll student",
1.318 raeburn 975: 'memsrch' => "User Search to enroll member",
1.406.2.5 raeburn 976: 'srcva' => "Search for a user and view access log information",
1.406.2.7 raeburn 977: 'usrvu' => "User Search to view user roles",
1.179 raeburn 978: 'usel' => "Select a user to add/modify roles",
1.406.2.7 raeburn 979: 'suvr' => "Select a user to view roles",
1.318 raeburn 980: 'stusel' => "Select a user to enroll as a student",
981: 'memsel' => "Select a user to enroll as a member",
1.406.2.5 raeburn 982: 'vacsel' => "Select a user to view access log",
1.160 raeburn 983: 'username' => "username",
984: 'domain' => "domain",
985: 'lastname' => "last name",
986: 'firstname' => "first name",
987: 'permanentemail' => "permanent e-mail",
988: );
1.302 raeburn 989: if ($context eq 'requestcrs') {
990: $r->print('<div>');
991: } else {
1.406.2.7 raeburn 992: my %breadcrumb_text = &singleuser_breadcrumb($crstype,$context,$srch->{'srchdomain'});
1.351 raeburn 993: my $helpitem;
994: if ($env{'form.action'} eq 'singleuser') {
995: $helpitem = 'Course_Change_Privileges';
996: } elsif ($env{'form.action'} eq 'singlestudent') {
997: $helpitem = 'Course_Add_Student';
998: }
999: push (@{$brcrum},
1000: {href => "javascript:backPage(document.usersrchform,'','')",
1001: text => $breadcrumb_text{'search'},
1002: faq => 282,
1003: bug => 'Instructor Interface',},
1004: {href => "javascript:backPage(document.usersrchform,'get_user_info','select')",
1005: text => $breadcrumb_text{'userpicked'},
1006: faq => 282,
1007: bug => 'Instructor Interface',
1008: help => $helpitem}
1009: );
1010: $r->print(&Apache::loncommon::start_page('User Management',$jscript,{bread_crumbs => $brcrum}));
1.302 raeburn 1011: if ($env{'form.action'} eq 'singleuser') {
1.406.2.7 raeburn 1012: my $readonly;
1013: if (($context eq 'domain') && (!&Apache::lonnet::allowed('mau',$srch->{'srchdomain'}))) {
1014: $readonly = 1;
1015: $r->print("<b>$lt{'usrvu'}</b><br />");
1016: } else {
1017: $r->print("<b>$lt{'usrch'}</b><br />");
1018: }
1.318 raeburn 1019: $r->print(&entry_form($srch->{'srchdomain'},$srch,undef,$context,undef,$crstype));
1.406.2.7 raeburn 1020: if ($readonly) {
1021: $r->print('<h3>'.$lt{'suvr'}.'</h3>');
1022: } else {
1023: $r->print('<h3>'.$lt{'usel'}.'</h3>');
1024: }
1.302 raeburn 1025: } elsif ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1026: $r->print($jscript."<b>");
1027: if ($crstype eq 'Community') {
1028: $r->print($lt{'memsrch'});
1029: } else {
1030: $r->print($lt{'stusrch'});
1031: }
1032: $r->print("</b><br />");
1033: $r->print(&entry_form($srch->{'srchdomain'},$srch,undef,$context,undef,$crstype));
1034: $r->print('</form><h3>');
1035: if ($crstype eq 'Community') {
1036: $r->print($lt{'memsel'});
1037: } else {
1038: $r->print($lt{'stusel'});
1039: }
1040: $r->print('</h3>');
1.406.2.5 raeburn 1041: } elsif ($env{'form.action'} eq 'accesslogs') {
1042: $r->print("<b>$lt{'srcva'}</b><br />");
1043: $r->print(&entry_form($srch->{'srchdomain'},$srch,undef,'accesslogs',undef,undef,1));
1044: $r->print('<h3>'.$lt{'vacsel'}.'</h3>');
1.302 raeburn 1045: }
1.179 raeburn 1046: }
1.380 bisitz 1047: $r->print('<form name="usersrchform" method="post" action="">'.
1.160 raeburn 1048: &Apache::loncommon::start_data_table()."\n".
1049: &Apache::loncommon::start_data_table_header_row()."\n".
1050: ' <th> </th>'."\n");
1051: foreach my $field (@fields) {
1052: $r->print(' <th><a href="javascript:document.usersrchform.sortby.value='.
1053: "'".$field."'".';document.usersrchform.submit();">'.
1054: $lt{$field}.'</a></th>'."\n");
1055: }
1056: $r->print(&Apache::loncommon::end_data_table_header_row());
1057:
1058: my @sorted_users = sort {
1.167 albertel 1059: lc($srch_results->{$a}->{$sortby}) cmp lc($srch_results->{$b}->{$sortby})
1.160 raeburn 1060: ||
1.167 albertel 1061: lc($srch_results->{$a}->{lastname}) cmp lc($srch_results->{$b}->{lastname})
1.160 raeburn 1062: ||
1063: lc($srch_results->{$a}->{firstname}) cmp lc($srch_results->{$b}->{firstname})
1.167 albertel 1064: ||
1065: lc($a) cmp lc($b)
1.160 raeburn 1066: } (keys(%$srch_results));
1067:
1068: foreach my $user (@sorted_users) {
1069: my ($uname,$udom) = split(/:/,$user);
1.302 raeburn 1070: my $onclick;
1071: if ($context eq 'requestcrs') {
1.314 raeburn 1072: $onclick =
1.302 raeburn 1073: 'onclick="javascript:gochoose('."'$uname','$udom',".
1074: "'$srch_results->{$user}->{firstname}',".
1075: "'$srch_results->{$user}->{lastname}',".
1076: "'$srch_results->{$user}->{permanentemail}'".');"';
1077: } else {
1.314 raeburn 1078: $onclick =
1.302 raeburn 1079: ' onclick="javascript:pickuser('."'".$uname."'".','."'".$udom."'".');"';
1080: }
1.160 raeburn 1081: $r->print(&Apache::loncommon::start_data_table_row().
1.302 raeburn 1082: '<td><input type="button" name="seluser" value="'.&mt('Select').'" '.
1083: $onclick.' /></td>'.
1.160 raeburn 1084: '<td><tt>'.$uname.'</tt></td>'.
1085: '<td><tt>'.$udom.'</tt></td>');
1086: foreach my $field ('lastname','firstname','permanentemail') {
1087: $r->print('<td>'.$srch_results->{$user}->{$field}.'</td>');
1088: }
1089: $r->print(&Apache::loncommon::end_data_table_row());
1090: }
1091: $r->print(&Apache::loncommon::end_data_table().'<br /><br />');
1.179 raeburn 1092: if (ref($srcharray) eq 'ARRAY') {
1093: foreach my $item (@{$srcharray}) {
1094: $r->print('<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n");
1095: }
1096: }
1.160 raeburn 1097: $r->print(' <input type="hidden" name="sortby" value="'.$sortby.'" />'."\n".
1098: ' <input type="hidden" name="seluname" value="" />'."\n".
1099: ' <input type="hidden" name="seludom" value="" />'."\n".
1.179 raeburn 1100: ' <input type="hidden" name="currstate" value="select" />'."\n".
1.190 raeburn 1101: ' <input type="hidden" name="phase" value="get_user_info" />'."\n".
1.214 raeburn 1102: ' <input type="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n");
1.302 raeburn 1103: if ($context eq 'requestcrs') {
1104: $r->print($opener_elements.'</form></div>');
1105: } else {
1.351 raeburn 1106: $r->print($response.'</form>');
1.302 raeburn 1107: }
1.160 raeburn 1108: }
1109:
1110: sub print_user_query_page {
1.351 raeburn 1111: my ($r,$caller,$brcrum) = @_;
1.160 raeburn 1112: # FIXME - this is for a network-wide name search (similar to catalog search)
1113: # To use frames with similar behavior to catalog/portfolio search.
1114: # To be implemented.
1115: return;
1116: }
1117:
1.42 matthew 1118: sub print_user_modification_page {
1.375 raeburn 1119: my ($r,$ccuname,$ccdomain,$srch,$response,$context,$permission,$crstype,
1120: $brcrum,$showcredits) = @_;
1.185 raeburn 1121: if (($ccuname eq '') || ($ccdomain eq '')) {
1.215 raeburn 1122: my $usermsg = &mt('No username and/or domain provided.');
1123: $env{'form.phase'} = '';
1.351 raeburn 1124: &print_username_entry_form($r,$context,$usermsg,'','',$crstype,$brcrum);
1.58 www 1125: return;
1126: }
1.213 raeburn 1127: my ($form,$formname);
1128: if ($env{'form.action'} eq 'singlestudent') {
1129: $form = 'document.enrollstudent';
1130: $formname = 'enrollstudent';
1131: } else {
1132: $form = 'document.cu';
1133: $formname = 'cu';
1134: }
1.188 raeburn 1135: my %abv_auth = &auth_abbrev();
1.227 raeburn 1136: my (%rulematch,%inst_results,$newuser,%alerts,%curr_rules,%got_rules);
1.185 raeburn 1137: my $uhome=&Apache::lonnet::homeserver($ccuname,$ccdomain);
1138: if ($uhome eq 'no_host') {
1.215 raeburn 1139: my $usertype;
1140: my ($rules,$ruleorder) =
1141: &Apache::lonnet::inst_userrules($ccdomain,'username');
1142: $usertype =
1.353 raeburn 1143: &Apache::lonuserutils::check_usertype($ccdomain,$ccuname,$rules,
1.362 raeburn 1144: \%curr_rules,\%got_rules);
1.215 raeburn 1145: my $cancreate =
1146: &Apache::lonuserutils::can_create_user($ccdomain,$context,
1147: $usertype);
1148: if (!$cancreate) {
1.292 bisitz 1149: my $helplink = 'javascript:helpMenu('."'display'".')';
1.215 raeburn 1150: my %usertypetext = (
1151: official => 'institutional',
1152: unofficial => 'non-institutional',
1153: );
1154: my $response;
1155: if ($env{'form.origform'} eq 'crtusername') {
1.362 raeburn 1156: $response = '<span class="LC_warning">'.
1157: &mt('No match found for the username [_1] in LON-CAPA domain: [_2]',
1158: '<b>'.$ccuname.'</b>',$ccdomain).
1.215 raeburn 1159: '</span><br />';
1160: }
1.292 bisitz 1161: $response .= '<p class="LC_warning">'
1162: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
1.406.2.6 raeburn 1163: .' ';
1164: if ($context eq 'domain') {
1165: $response .= &mt('Please contact a [_1] for assistance.',
1166: &Apache::lonnet::plaintext('dc'));
1167: } else {
1168: $response .= &mt('Please contact the [_1]helpdesk[_2] for assistance.'
1169: ,'<a href="'.$helplink.'">','</a>');
1170: }
1171: $response .= '</p><br />';
1.215 raeburn 1172: $env{'form.phase'} = '';
1.351 raeburn 1173: &print_username_entry_form($r,$context,$response,undef,undef,$crstype,$brcrum);
1.215 raeburn 1174: return;
1175: }
1.188 raeburn 1176: $newuser = 1;
1.193 raeburn 1177: my $checkhash;
1178: my $checks = { 'username' => 1 };
1.196 raeburn 1179: $checkhash->{$ccuname.':'.$ccdomain} = { 'newuser' => $newuser };
1.193 raeburn 1180: &Apache::loncommon::user_rule_check($checkhash,$checks,
1.196 raeburn 1181: \%alerts,\%rulematch,\%inst_results,\%curr_rules,\%got_rules);
1182: if (ref($alerts{'username'}) eq 'HASH') {
1183: if (ref($alerts{'username'}{$ccdomain}) eq 'HASH') {
1184: my $domdesc =
1.193 raeburn 1185: &Apache::lonnet::domain($ccdomain,'description');
1.196 raeburn 1186: if ($alerts{'username'}{$ccdomain}{$ccuname}) {
1187: my $userchkmsg;
1188: if (ref($curr_rules{$ccdomain}) eq 'HASH') {
1189: $userchkmsg =
1190: &Apache::loncommon::instrule_disallow_msg('username',
1.193 raeburn 1191: $domdesc,1).
1192: &Apache::loncommon::user_rule_formats($ccdomain,
1193: $domdesc,$curr_rules{$ccdomain}{'username'},
1194: 'username');
1.196 raeburn 1195: }
1.215 raeburn 1196: $env{'form.phase'} = '';
1.351 raeburn 1197: &print_username_entry_form($r,$context,$userchkmsg,undef,undef,$crstype,$brcrum);
1.196 raeburn 1198: return;
1.215 raeburn 1199: }
1.193 raeburn 1200: }
1.185 raeburn 1201: }
1.187 raeburn 1202: } else {
1.188 raeburn 1203: $newuser = 0;
1.185 raeburn 1204: }
1.160 raeburn 1205: if ($response) {
1.215 raeburn 1206: $response = '<br />'.$response;
1.160 raeburn 1207: }
1.149 raeburn 1208:
1.52 matthew 1209: my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
1.88 raeburn 1210: my $dc_setcourse_code = '';
1.119 raeburn 1211: my $nondc_setsection_code = '';
1.112 albertel 1212: my %loaditem;
1.114 albertel 1213:
1.216 raeburn 1214: my $groupslist = &Apache::lonuserutils::get_groupslist();
1.88 raeburn 1215:
1.375 raeburn 1216: my $js = &validation_javascript($context,$ccdomain,$pjump_def,$crstype,
1.216 raeburn 1217: $groupslist,$newuser,$formname,\%loaditem);
1.406.2.7 raeburn 1218: my %breadcrumb_text = &singleuser_breadcrumb($crstype,$context,$ccdomain);
1.224 raeburn 1219: my $helpitem = 'Course_Change_Privileges';
1220: if ($env{'form.action'} eq 'singlestudent') {
1221: $helpitem = 'Course_Add_Student';
1222: }
1.351 raeburn 1223: push (@{$brcrum},
1224: {href => "javascript:backPage($form)",
1225: text => $breadcrumb_text{'search'},
1226: faq => 282,
1227: bug => 'Instructor Interface',});
1228: if ($env{'form.phase'} eq 'userpicked') {
1229: push(@{$brcrum},
1230: {href => "javascript:backPage($form,'get_user_info','select')",
1231: text => $breadcrumb_text{'userpicked'},
1232: faq => 282,
1233: bug => 'Instructor Interface',});
1234: }
1235: push(@{$brcrum},
1236: {href => "javascript:backPage($form,'$env{'form.phase'}','modify')",
1237: text => $breadcrumb_text{'modify'},
1238: faq => 282,
1239: bug => 'Instructor Interface',
1240: help => $helpitem});
1241: my $args = {'add_entries' => \%loaditem,
1242: 'bread_crumbs' => $brcrum,
1243: 'bread_crumbs_component' => 'User Management'};
1244: if ($env{'form.popup'}) {
1245: $args->{'no_nav_bar'} = 1;
1246: }
1247: my $start_page =
1248: &Apache::loncommon::start_page('User Management',$js,$args);
1.3 www 1249:
1.25 matthew 1250: my $forminfo =<<"ENDFORMINFO";
1.216 raeburn 1251: <form action="/adm/createuser" method="post" name="$formname">
1.190 raeburn 1252: <input type="hidden" name="phase" value="update_user_data" />
1.188 raeburn 1253: <input type="hidden" name="ccuname" value="$ccuname" />
1254: <input type="hidden" name="ccdomain" value="$ccdomain" />
1.157 albertel 1255: <input type="hidden" name="pres_value" value="" />
1256: <input type="hidden" name="pres_type" value="" />
1257: <input type="hidden" name="pres_marker" value="" />
1.25 matthew 1258: ENDFORMINFO
1.375 raeburn 1259: my (%inccourses,$roledom,$defaultcredits);
1.329 raeburn 1260: if ($context eq 'course') {
1261: $inccourses{$env{'request.course.id'}}=1;
1262: $roledom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1.375 raeburn 1263: if ($showcredits) {
1264: $defaultcredits = &Apache::lonuserutils::get_defaultcredits();
1265: }
1.329 raeburn 1266: } elsif ($context eq 'author') {
1267: $roledom = $env{'request.role.domain'};
1268: } elsif ($context eq 'domain') {
1269: foreach my $key (keys(%env)) {
1270: $roledom = $env{'request.role.domain'};
1271: if ($key=~/^user\.priv\.cm\.\/($roledom)\/($match_username)/) {
1272: $inccourses{$1.'_'.$2}=1;
1273: }
1274: }
1275: } else {
1276: foreach my $key (keys(%env)) {
1277: if ($key=~/^user\.priv\.cm\.\/($match_domain)\/($match_username)/) {
1278: $inccourses{$1.'_'.$2}=1;
1279: }
1.2 www 1280: }
1.24 matthew 1281: }
1.389 bisitz 1282: my $title = '';
1.216 raeburn 1283: if ($newuser) {
1.406.2.9 raeburn 1284: my ($portfolioform,$domroleform);
1.267 raeburn 1285: if ((&Apache::lonnet::allowed('mpq',$env{'request.role.domain'})) ||
1286: (&Apache::lonnet::allowed('mut',$env{'request.role.domain'}))) {
1287: # Current user has quota or user tools modification privileges
1.378 raeburn 1288: $portfolioform = '<br />'.&user_quotas($ccuname,$ccdomain);
1.134 raeburn 1289: }
1.383 raeburn 1290: if ((&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) &&
1291: ($ccdomain eq $env{'request.role.domain'})) {
1.362 raeburn 1292: $domroleform = '<br />'.&domainrole_req($ccuname,$ccdomain);
1293: }
1.227 raeburn 1294: &initialize_authen_forms($ccdomain,$formname);
1.188 raeburn 1295: my %lt=&Apache::lonlocal::texthash(
1296: 'lg' => 'Login Data',
1.190 raeburn 1297: 'hs' => "Home Server",
1.188 raeburn 1298: );
1.185 raeburn 1299: $r->print(<<ENDTITLE);
1.110 albertel 1300: $start_page
1.160 raeburn 1301: $response
1.25 matthew 1302: $forminfo
1.31 matthew 1303: <script type="text/javascript" language="Javascript">
1.301 bisitz 1304: // <![CDATA[
1.20 harris41 1305: $loginscript
1.301 bisitz 1306: // ]]>
1.31 matthew 1307: </script>
1.20 harris41 1308: <input type='hidden' name='makeuser' value='1' />
1.185 raeburn 1309: ENDTITLE
1.213 raeburn 1310: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1311: if ($crstype eq 'Community') {
1.389 bisitz 1312: $title = &mt('Create New User [_1] in domain [_2] as a member',
1313: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.318 raeburn 1314: } else {
1.389 bisitz 1315: $title = &mt('Create New User [_1] in domain [_2] as a student',
1316: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.318 raeburn 1317: }
1.389 bisitz 1318: } else {
1319: $title = &mt('Create New User [_1] in domain [_2]',
1320: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.213 raeburn 1321: }
1.389 bisitz 1322: $r->print('<h2>'.$title.'</h2>'."\n");
1323: $r->print('<div class="LC_left_float">');
1.393 raeburn 1324: $r->print(&personal_data_display($ccuname,$ccdomain,$newuser,$context,
1325: $inst_results{$ccuname.':'.$ccdomain}));
1326: # Option to disable student/employee ID conflict checking not offerred for new users.
1.187 raeburn 1327: my ($home_server_pick,$numlib) =
1328: &Apache::loncommon::home_server_form_item($ccdomain,'hserver',
1329: 'default','hide');
1330: if ($numlib > 1) {
1331: $r->print("
1.185 raeburn 1332: <br />
1.187 raeburn 1333: $lt{'hs'}: $home_server_pick
1334: <br />");
1335: } else {
1336: $r->print($home_server_pick);
1337: }
1.304 raeburn 1338: if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
1.362 raeburn 1339: $r->print('<br /><h3>'.
1340: &mt('User Can Request Creation of Courses/Communities in this Domain?').'</h3>'.
1.304 raeburn 1341: &Apache::loncommon::start_data_table().
1342: &build_tools_display($ccuname,$ccdomain,
1343: 'requestcourses').
1344: &Apache::loncommon::end_data_table());
1345: }
1.188 raeburn 1346: $r->print('</div>'."\n".'<div class="LC_left_float"><h3>'.
1347: $lt{'lg'}.'</h3>');
1.185 raeburn 1348: my ($fixedauth,$varauth,$authmsg);
1.193 raeburn 1349: if (ref($rulematch{$ccuname.':'.$ccdomain}) eq 'HASH') {
1350: my $matchedrule = $rulematch{$ccuname.':'.$ccdomain}{'username'};
1351: my ($rules,$ruleorder) =
1352: &Apache::lonnet::inst_userrules($ccdomain,'username');
1.185 raeburn 1353: if (ref($rules) eq 'HASH') {
1.193 raeburn 1354: if (ref($rules->{$matchedrule}) eq 'HASH') {
1355: my $authtype = $rules->{$matchedrule}{'authtype'};
1.185 raeburn 1356: if ($authtype !~ /^(krb4|krb5|int|fsys|loc)$/) {
1.190 raeburn 1357: $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1.275 raeburn 1358: } else {
1.193 raeburn 1359: my $authparm = $rules->{$matchedrule}{'authparm'};
1.273 raeburn 1360: $authmsg = $rules->{$matchedrule}{'authmsg'};
1.185 raeburn 1361: if ($authtype =~ /^krb(4|5)$/) {
1362: my $ver = $1;
1363: if ($authparm ne '') {
1364: $fixedauth = <<"KERB";
1365: <input type="hidden" name="login" value="krb" />
1366: <input type="hidden" name="krbver" value="$ver" />
1367: <input type="hidden" name="krbarg" value="$authparm" />
1368: KERB
1369: }
1370: } else {
1371: $fixedauth =
1372: '<input type="hidden" name="login" value="'.$authtype.'" />'."\n";
1.193 raeburn 1373: if ($rules->{$matchedrule}{'authparmfixed'}) {
1.185 raeburn 1374: $fixedauth .=
1375: '<input type="hidden" name="'.$authtype.'arg" value="'.$authparm.'" />'."\n";
1376: } else {
1.273 raeburn 1377: if ($authtype eq 'int') {
1378: $varauth = '<br />'.
1.301 bisitz 1379: &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 1380: } elsif ($authtype eq 'loc') {
1381: $varauth = '<br />'.
1382: &mt('[_1] Local Authentication with argument [_2]','','<input type="text" name="'.$authtype.'arg" value="" />')."\n";
1383: } else {
1384: $varauth =
1.185 raeburn 1385: '<input type="text" name="'.$authtype.'arg" value="" />'."\n";
1.273 raeburn 1386: }
1.185 raeburn 1387: }
1388: }
1389: }
1390: } else {
1.190 raeburn 1391: $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1.185 raeburn 1392: }
1393: }
1394: if ($authmsg) {
1395: $r->print(<<ENDAUTH);
1396: $fixedauth
1397: $authmsg
1398: $varauth
1399: ENDAUTH
1400: }
1401: } else {
1.190 raeburn 1402: $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1.187 raeburn 1403: }
1.406.2.9 raeburn 1404: $r->print($portfolioform.$domroleform);
1.215 raeburn 1405: if ($env{'form.action'} eq 'singlestudent') {
1406: $r->print(&date_sections_select($context,$newuser,$formname,
1.375 raeburn 1407: $permission,$crstype,$ccuname,
1408: $ccdomain,$showcredits));
1.215 raeburn 1409: }
1410: $r->print('</div><div class="LC_clear_float_footer"></div>');
1.216 raeburn 1411: } else { # user already exists
1.389 bisitz 1412: $r->print($start_page.$forminfo);
1.213 raeburn 1413: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1414: if ($crstype eq 'Community') {
1.389 bisitz 1415: $title = &mt('Enroll one member: [_1] in domain [_2]',
1416: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.318 raeburn 1417: } else {
1.389 bisitz 1418: $title = &mt('Enroll one student: [_1] in domain [_2]',
1419: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.318 raeburn 1420: }
1.213 raeburn 1421: } else {
1.406.2.6 raeburn 1422: if ($permission->{'cusr'}) {
1423: $title = &mt('Modify existing user: [_1] in domain [_2]',
1424: '"'.$ccuname.'"','"'.$ccdomain.'"');
1425: } else {
1426: $title = &mt('Existing user: [_1] in domain [_2]',
1.389 bisitz 1427: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.406.2.6 raeburn 1428: }
1.213 raeburn 1429: }
1.389 bisitz 1430: $r->print('<h2>'.$title.'</h2>'."\n");
1431: $r->print('<div class="LC_left_float">');
1.393 raeburn 1432: $r->print(&personal_data_display($ccuname,$ccdomain,$newuser,$context,
1433: $inst_results{$ccuname.':'.$ccdomain}));
1.406.2.6 raeburn 1434: if ((&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) ||
1435: (&Apache::lonnet::allowed('udp',$env{'request.role.domain'}))) {
1.362 raeburn 1436: $r->print('<br /><h3>'.&mt('User Can Request Creation of Courses/Communities in this Domain?').'</h3>'.
1.300 raeburn 1437: &Apache::loncommon::start_data_table());
1.314 raeburn 1438: if ($env{'request.role.domain'} eq $ccdomain) {
1.300 raeburn 1439: $r->print(&build_tools_display($ccuname,$ccdomain,'requestcourses'));
1440: } else {
1441: $r->print(&coursereq_externaluser($ccuname,$ccdomain,
1442: $env{'request.role.domain'}));
1443: }
1444: $r->print(&Apache::loncommon::end_data_table());
1.275 raeburn 1445: }
1.199 raeburn 1446: $r->print('</div>');
1.406.2.9 raeburn 1447: my @order = ('auth','quota','tools','requestauthor');
1.362 raeburn 1448: my %user_text;
1449: my ($isadv,$isauthor) =
1.406.2.6 raeburn 1450: &Apache::lonnet::is_advanced_user($ccdomain,$ccuname);
1.362 raeburn 1451: if ((!$isauthor) &&
1.406.2.6 raeburn 1452: ((&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) ||
1453: (&Apache::lonnet::allowed('udp',$env{'request.role.domain'}))) &&
1454: ($env{'request.role.domain'} eq $ccdomain)) {
1.362 raeburn 1455: $user_text{'requestauthor'} = &domainrole_req($ccuname,$ccdomain);
1456: }
1457: $user_text{'auth'} = &user_authentication($ccuname,$ccdomain,$formname);
1.267 raeburn 1458: if ((&Apache::lonnet::allowed('mpq',$ccdomain)) ||
1.406.2.6 raeburn 1459: (&Apache::lonnet::allowed('mut',$ccdomain)) ||
1460: (&Apache::lonnet::allowed('udp',$ccdomain))) {
1.188 raeburn 1461: # Current user has quota modification privileges
1.378 raeburn 1462: $user_text{'quota'} = &user_quotas($ccuname,$ccdomain);
1.267 raeburn 1463: }
1464: if (!&Apache::lonnet::allowed('mpq',$ccdomain)) {
1465: if (&Apache::lonnet::allowed('mpq',$env{'request.role.domain'})) {
1466: my %lt=&Apache::lonlocal::texthash(
1.385 bisitz 1467: 'dska' => "Disk quotas for user's portfolio and Authoring Space",
1468: 'youd' => "You do not have privileges to modify the portfolio and/or Authoring Space quotas for this user.",
1.267 raeburn 1469: 'ichr' => "If a change is required, contact a domain coordinator for the domain",
1470: );
1.362 raeburn 1471: $user_text{'quota'} = <<ENDNOPORTPRIV;
1.188 raeburn 1472: <h3>$lt{'dska'}</h3>
1473: $lt{'youd'} $lt{'ichr'}: $ccdomain
1474: ENDNOPORTPRIV
1.267 raeburn 1475: }
1476: }
1477: if (!&Apache::lonnet::allowed('mut',$ccdomain)) {
1478: if (&Apache::lonnet::allowed('mut',$env{'request.role.domain'})) {
1479: my %lt=&Apache::lonlocal::texthash(
1480: 'utav' => "User Tools Availability",
1.361 raeburn 1481: 'yodo' => "You do not have privileges to modify Portfolio, Blog, WebDAV, or Personal Information Page settings for this user.",
1.267 raeburn 1482: 'ifch' => "If a change is required, contact a domain coordinator for the domain",
1483: );
1.362 raeburn 1484: $user_text{'tools'} = <<ENDNOTOOLSPRIV;
1.267 raeburn 1485: <h3>$lt{'utav'}</h3>
1486: $lt{'yodo'} $lt{'ifch'}: $ccdomain
1487: ENDNOTOOLSPRIV
1488: }
1.188 raeburn 1489: }
1.362 raeburn 1490: my $gotdiv = 0;
1491: foreach my $item (@order) {
1492: if ($user_text{$item} ne '') {
1493: unless ($gotdiv) {
1494: $r->print('<div class="LC_left_float">');
1495: $gotdiv = 1;
1496: }
1497: $r->print('<br />'.$user_text{$item});
1498: }
1499: }
1500: if ($env{'form.action'} eq 'singlestudent') {
1501: unless ($gotdiv) {
1502: $r->print('<div class="LC_left_float">');
1.213 raeburn 1503: }
1.375 raeburn 1504: my $credits;
1505: if ($showcredits) {
1506: $credits = &get_user_credits($ccuname,$ccdomain,$defaultcredits);
1507: if ($credits eq '') {
1508: $credits = $defaultcredits;
1509: }
1510: }
1.374 raeburn 1511: $r->print(&date_sections_select($context,$newuser,$formname,
1.375 raeburn 1512: $permission,$crstype,$ccuname,
1513: $ccdomain,$showcredits));
1.374 raeburn 1514: }
1.362 raeburn 1515: if ($gotdiv) {
1516: $r->print('</div><div class="LC_clear_float_footer"></div>');
1.188 raeburn 1517: }
1.406.2.6 raeburn 1518: my $statuses;
1519: if (($context eq 'domain') && (&Apache::lonnet::allowed('udp',$ccdomain)) &&
1520: (!&Apache::lonnet::allowed('mau',$ccdomain))) {
1521: $statuses = ['active'];
1522: } elsif (($context eq 'course') && ((&Apache::lonnet::allowed('vcl',$env{'request.course.id'})) ||
1523: ($env{'request.course.sec'} &&
1524: &Apache::lonnet::allowed('vcl',$env{'request.course.id'}.'/'.$env{'request.course.sec'})))) {
1525: $statuses = ['active'];
1526: }
1.217 raeburn 1527: if ($env{'form.action'} ne 'singlestudent') {
1.329 raeburn 1528: &display_existing_roles($r,$ccuname,$ccdomain,\%inccourses,$context,
1.406.2.6 raeburn 1529: $roledom,$crstype,$showcredits,$statuses);
1.217 raeburn 1530: }
1.25 matthew 1531: } ## End of new user/old user logic
1.218 raeburn 1532: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1533: my $btntxt;
1534: if ($crstype eq 'Community') {
1535: $btntxt = &mt('Enroll Member');
1536: } else {
1537: $btntxt = &mt('Enroll Student');
1538: }
1539: $r->print('<br /><input type="button" value="'.$btntxt.'" onclick="setSections(this.form)" />'."\n");
1.406.2.6 raeburn 1540: } elsif ($permission->{'cusr'}) {
1.393 raeburn 1541: $r->print('<div class="LC_left_float">'.
1542: '<fieldset><legend>'.&mt('Add Roles').'</legend>');
1.218 raeburn 1543: my $addrolesdisplay = 0;
1544: if ($context eq 'domain' || $context eq 'author') {
1545: $addrolesdisplay = &new_coauthor_roles($r,$ccuname,$ccdomain);
1546: }
1547: if ($context eq 'domain') {
1.357 raeburn 1548: my $add_domainroles = &new_domain_roles($r,$ccdomain);
1.218 raeburn 1549: if (!$addrolesdisplay) {
1550: $addrolesdisplay = $add_domainroles;
1.2 www 1551: }
1.375 raeburn 1552: $r->print(&course_level_dc($env{'request.role.domain'},$showcredits));
1.393 raeburn 1553: $r->print('</fieldset></div><div class="LC_clear_float_footer"></div>'.
1554: '<br /><input type="button" value="'.&mt('Save').'" onclick="setCourse()" />'."\n");
1.218 raeburn 1555: } elsif ($context eq 'author') {
1556: if ($addrolesdisplay) {
1.393 raeburn 1557: $r->print('</fieldset></div><div class="LC_clear_float_footer"></div>'.
1558: '<br /><input type="button" value="'.&mt('Save').'"');
1.218 raeburn 1559: if ($newuser) {
1.301 bisitz 1560: $r->print(' onclick="auth_check()" \>'."\n");
1.218 raeburn 1561: } else {
1.301 bisitz 1562: $r->print('onclick="this.form.submit()" \>'."\n");
1.218 raeburn 1563: }
1.188 raeburn 1564: } else {
1.393 raeburn 1565: $r->print('</fieldset></div>'.
1566: '<div class="LC_clear_float_footer"></div>'.
1567: '<br /><a href="javascript:backPage(document.cu)">'.
1.218 raeburn 1568: &mt('Back to previous page').'</a>');
1.188 raeburn 1569: }
1570: } else {
1.375 raeburn 1571: $r->print(&course_level_table(\%inccourses,$showcredits,$defaultcredits));
1.393 raeburn 1572: $r->print('</fieldset></div><div class="LC_clear_float_footer"></div>'.
1573: '<br /><input type="button" value="'.&mt('Save').'" onclick="setSections(this.form)" />'."\n");
1.188 raeburn 1574: }
1.88 raeburn 1575: }
1.188 raeburn 1576: $r->print(&Apache::lonhtmlcommon::echo_form_input(['phase','userrole','ccdomain','prevphase','currstate','ccuname','ccdomain']));
1.179 raeburn 1577: $r->print('<input type="hidden" name="currstate" value="" />');
1.393 raeburn 1578: $r->print('<input type="hidden" name="prevphase" value="'.$env{'form.phase'}.'" /></form><br /><br />');
1.218 raeburn 1579: return;
1.2 www 1580: }
1.1 www 1581:
1.213 raeburn 1582: sub singleuser_breadcrumb {
1.406.2.7 raeburn 1583: my ($crstype,$context,$domain) = @_;
1.213 raeburn 1584: my %breadcrumb_text;
1585: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1586: if ($crstype eq 'Community') {
1587: $breadcrumb_text{'search'} = 'Enroll a member';
1588: } else {
1589: $breadcrumb_text{'search'} = 'Enroll a student';
1590: }
1.406.2.7 raeburn 1591: $breadcrumb_text{'userpicked'} = 'Select a user';
1592: $breadcrumb_text{'modify'} = 'Set section/dates';
1.406.2.5 raeburn 1593: } elsif ($env{'form.action'} eq 'accesslogs') {
1594: $breadcrumb_text{'search'} = 'View access logs for a user';
1.406.2.7 raeburn 1595: $breadcrumb_text{'userpicked'} = 'Select a user';
1596: $breadcrumb_text{'activity'} = 'Activity';
1597: } elsif (($env{'form.action'} eq 'singleuser') && ($context eq 'domain') &&
1598: (!&Apache::lonnet::allowed('mau',$domain))) {
1599: $breadcrumb_text{'search'} = "View user's roles";
1600: $breadcrumb_text{'userpicked'} = 'Select a user';
1601: $breadcrumb_text{'modify'} = 'User roles';
1.213 raeburn 1602: } else {
1.229 raeburn 1603: $breadcrumb_text{'search'} = 'Create/modify a user';
1.406.2.7 raeburn 1604: $breadcrumb_text{'userpicked'} = 'Select a user';
1605: $breadcrumb_text{'modify'} = 'Set user role';
1.213 raeburn 1606: }
1607: return %breadcrumb_text;
1608: }
1609:
1610: sub date_sections_select {
1.375 raeburn 1611: my ($context,$newuser,$formname,$permission,$crstype,$ccuname,$ccdomain,
1612: $showcredits) = @_;
1613: my $credits;
1614: if ($showcredits) {
1615: my $defaultcredits = &Apache::lonuserutils::get_defaultcredits();
1616: $credits = &get_user_credits($ccuname,$ccdomain,$defaultcredits);
1617: if ($credits eq '') {
1618: $credits = $defaultcredits;
1619: }
1620: }
1.213 raeburn 1621: my $cid = $env{'request.course.id'};
1622: my ($cnum,$cdom) = &Apache::lonuserutils::get_course_identity($cid);
1623: my $date_table = '<h3>'.&mt('Starting and Ending Dates').'</h3>'."\n".
1624: &Apache::lonuserutils::date_setting_table(undef,undef,$context,
1625: undef,$formname,$permission);
1626: my $rowtitle = 'Section';
1.375 raeburn 1627: my $secbox = '<h3>'.&mt('Section and Credits').'</h3>'."\n".
1.213 raeburn 1628: &Apache::lonuserutils::section_picker($cdom,$cnum,'st',$rowtitle,
1.375 raeburn 1629: $permission,$context,'',$crstype,
1630: $showcredits,$credits);
1.213 raeburn 1631: my $output = $date_table.$secbox;
1632: return $output;
1633: }
1634:
1.216 raeburn 1635: sub validation_javascript {
1.375 raeburn 1636: my ($context,$ccdomain,$pjump_def,$crstype,$groupslist,$newuser,$formname,
1.216 raeburn 1637: $loaditem) = @_;
1638: my $dc_setcourse_code = '';
1639: my $nondc_setsection_code = '';
1640: if ($context eq 'domain') {
1641: my $dcdom = $env{'request.role.domain'};
1642: $loaditem->{'onload'} = "document.cu.coursedesc.value='';";
1.227 raeburn 1643: $dc_setcourse_code =
1644: &Apache::lonuserutils::dc_setcourse_js('cu','singleuser',$context);
1.216 raeburn 1645: } else {
1.227 raeburn 1646: my $checkauth;
1647: if (($newuser) || (&Apache::lonnet::allowed('mau',$ccdomain))) {
1648: $checkauth = 1;
1649: }
1650: if ($context eq 'course') {
1651: $nondc_setsection_code =
1652: &Apache::lonuserutils::setsections_javascript($formname,$groupslist,
1.375 raeburn 1653: undef,$checkauth,
1654: $crstype);
1.227 raeburn 1655: }
1656: if ($checkauth) {
1657: $nondc_setsection_code .=
1658: &Apache::lonuserutils::verify_authen($formname,$context);
1659: }
1.216 raeburn 1660: }
1661: my $js = &user_modification_js($pjump_def,$dc_setcourse_code,
1662: $nondc_setsection_code,$groupslist);
1663: my ($jsback,$elements) = &crumb_utilities();
1664: $js .= "\n".
1.301 bisitz 1665: '<script type="text/javascript">'."\n".
1666: '// <![CDATA['."\n".
1667: $jsback."\n".
1668: '// ]]>'."\n".
1669: '</script>'."\n";
1.216 raeburn 1670: return $js;
1671: }
1672:
1.217 raeburn 1673: sub display_existing_roles {
1.375 raeburn 1674: my ($r,$ccuname,$ccdomain,$inccourses,$context,$roledom,$crstype,
1.406.2.6 raeburn 1675: $showcredits,$statuses) = @_;
1.329 raeburn 1676: my $now=time;
1.406.2.6 raeburn 1677: my $showall = 1;
1678: my ($showexpired,$showactive);
1679: if ((ref($statuses) eq 'ARRAY') && (@{$statuses} > 0)) {
1680: $showall = 0;
1681: if (grep(/^expired$/,@{$statuses})) {
1682: $showexpired = 1;
1683: }
1684: if (grep(/^active$/,@{$statuses})) {
1685: $showactive = 1;
1686: }
1687: if ($showexpired && $showactive) {
1688: $showall = 1;
1689: }
1690: }
1.329 raeburn 1691: my %lt=&Apache::lonlocal::texthash(
1.217 raeburn 1692: 'rer' => "Existing Roles",
1693: 'rev' => "Revoke",
1694: 'del' => "Delete",
1695: 'ren' => "Re-Enable",
1696: 'rol' => "Role",
1697: 'ext' => "Extent",
1.375 raeburn 1698: 'crd' => "Credits",
1.217 raeburn 1699: 'sta' => "Start",
1700: 'end' => "End",
1701: );
1.329 raeburn 1702: my (%rolesdump,%roletext,%sortrole,%roleclass,%rolepriv);
1703: if ($context eq 'course' || $context eq 'author') {
1704: my @roles = &Apache::lonuserutils::roles_by_context($context,1,$crstype);
1705: my %roleshash =
1706: &Apache::lonnet::get_my_roles($ccuname,$ccdomain,'userroles',
1707: ['active','previous','future'],\@roles,$roledom,1);
1708: foreach my $key (keys(%roleshash)) {
1709: my ($start,$end) = split(':',$roleshash{$key});
1710: next if ($start eq '-1' || $end eq '-1');
1711: my ($rnum,$rdom,$role,$sec) = split(':',$key);
1712: if ($context eq 'course') {
1713: next unless (($rnum eq $env{'course.'.$env{'request.course.id'}.'.num'})
1714: && ($rdom eq $env{'course.'.$env{'request.course.id'}.'.domain'}));
1715: } elsif ($context eq 'author') {
1716: next unless (($rnum eq $env{'user.name'}) && ($rdom eq $env{'request.role.domain'}));
1717: }
1718: my ($newkey,$newvalue,$newrole);
1719: $newkey = '/'.$rdom.'/'.$rnum;
1720: if ($sec ne '') {
1721: $newkey .= '/'.$sec;
1722: }
1723: $newvalue = $role;
1724: if ($role =~ /^cr/) {
1725: $newrole = 'cr';
1726: } else {
1727: $newrole = $role;
1728: }
1729: $newkey .= '_'.$newrole;
1730: if ($start ne '' && $end ne '') {
1731: $newvalue .= '_'.$end.'_'.$start;
1.335 raeburn 1732: } elsif ($end ne '') {
1733: $newvalue .= '_'.$end;
1.329 raeburn 1734: }
1735: $rolesdump{$newkey} = $newvalue;
1736: }
1737: } else {
1.360 raeburn 1738: %rolesdump=&Apache::lonnet::dump('roles',$ccdomain,$ccuname);
1.329 raeburn 1739: }
1740: # Build up table of user roles to allow revocation and re-enabling of roles.
1741: my ($tmp) = keys(%rolesdump);
1742: return if ($tmp =~ /^(con_lost|error)/i);
1743: foreach my $area (sort { my $a1=join('_',(split('_',$a))[1,0]);
1744: my $b1=join('_',(split('_',$b))[1,0]);
1745: return $a1 cmp $b1;
1746: } keys(%rolesdump)) {
1747: next if ($area =~ /^rolesdef/);
1748: my $envkey=$area;
1749: my $role = $rolesdump{$area};
1750: my $thisrole=$area;
1751: $area =~ s/\_\w\w$//;
1752: my ($role_code,$role_end_time,$role_start_time) =
1753: split(/_/,$role);
1.406.2.6 raeburn 1754: my $active=1;
1755: $active=0 if (($role_end_time) && ($now>$role_end_time));
1756: if ($active) {
1757: next unless($showall || $showactive);
1758: } else {
1759: next unless($showall || $showexpired);
1760: }
1.217 raeburn 1761: # Is this a custom role? Get role owner and title.
1.329 raeburn 1762: my ($croleudom,$croleuname,$croletitle)=
1763: ($role_code=~m{^cr/($match_domain)/($match_username)/(\w+)$});
1764: my $allowed=0;
1765: my $delallowed=0;
1766: my $sortkey=$role_code;
1767: my $class='Unknown';
1.375 raeburn 1768: my $credits='';
1.406.2.6 raeburn 1769: my $csec;
1.406.2.7 raeburn 1770: if ($area =~ m{^/($match_domain)/($match_courseid)}) {
1.329 raeburn 1771: $class='Course';
1772: my ($coursedom,$coursedir) = ($1,$2);
1773: my $cid = $1.'_'.$2;
1774: # $1.'_'.$2 is the course id (eg. 103_12345abcef103l3).
1.406.2.7 raeburn 1775: next if ($envkey =~ m{^/$match_domain/$match_courseid/[A-Za-z0-9]+_gr$});
1.329 raeburn 1776: my %coursedata=
1777: &Apache::lonnet::coursedescription($cid);
1778: if ($coursedir =~ /^$match_community$/) {
1779: $class='Community';
1780: }
1781: $sortkey.="\0$coursedom";
1782: my $carea;
1783: if (defined($coursedata{'description'})) {
1784: $carea=$coursedata{'description'}.
1785: '<br />'.&mt('Domain').': '.$coursedom.(' 'x8).
1786: &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$coursedir,$coursedom);
1787: $sortkey.="\0".$coursedata{'description'};
1788: } else {
1789: if ($class eq 'Community') {
1790: $carea=&mt('Unavailable community').': '.$area;
1791: $sortkey.="\0".&mt('Unavailable community').': '.$area;
1.217 raeburn 1792: } else {
1793: $carea=&mt('Unavailable course').': '.$area;
1794: $sortkey.="\0".&mt('Unavailable course').': '.$area;
1795: }
1.329 raeburn 1796: }
1797: $sortkey.="\0$coursedir";
1798: $inccourses->{$cid}=1;
1.375 raeburn 1799: if (($showcredits) && ($class eq 'Course') && ($role_code eq 'st')) {
1800: my $defaultcredits = $coursedata{'internal.defaultcredits'};
1801: $credits =
1802: &get_user_credits($ccuname,$ccdomain,$defaultcredits,
1803: $coursedom,$coursedir);
1804: if ($credits eq '') {
1805: $credits = $defaultcredits;
1806: }
1807: }
1.329 raeburn 1808: if ((&Apache::lonnet::allowed('c'.$role_code,$coursedom.'/'.$coursedir)) ||
1809: (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) {
1810: $allowed=1;
1811: }
1812: unless ($allowed) {
1.365 raeburn 1813: my $isowner = &Apache::lonuserutils::is_courseowner($cid,$coursedata{'internal.courseowner'});
1.329 raeburn 1814: if ($isowner) {
1815: if (($role_code eq 'co') && ($class eq 'Community')) {
1816: $allowed = 1;
1817: } elsif (($role_code eq 'cc') && ($class eq 'Course')) {
1818: $allowed = 1;
1819: }
1.217 raeburn 1820: }
1.329 raeburn 1821: }
1822: if ((&Apache::lonnet::allowed('dro',$coursedom)) ||
1823: (&Apache::lonnet::allowed('dro',$ccdomain))) {
1824: $delallowed=1;
1825: }
1.217 raeburn 1826: # - custom role. Needs more info, too
1.329 raeburn 1827: if ($croletitle) {
1828: if (&Apache::lonnet::allowed('ccr',$coursedom.'/'.$coursedir)) {
1829: $allowed=1;
1830: $thisrole.='.'.$role_code;
1.217 raeburn 1831: }
1.329 raeburn 1832: }
1.406.2.6 raeburn 1833: if ($area=~m{^/($match_domain/$match_courseid/(\w+))}) {
1834: $csec = $2;
1835: $carea.='<br />'.&mt('Section: [_1]',$csec);
1836: $sortkey.="\0$csec";
1.329 raeburn 1837: if (!$allowed) {
1.406.2.6 raeburn 1838: if ($env{'request.course.sec'} eq $csec) {
1839: if (&Apache::lonnet::allowed('c'.$role_code,$1)) {
1.329 raeburn 1840: $allowed = 1;
1.217 raeburn 1841: }
1842: }
1843: }
1.329 raeburn 1844: }
1845: $area=$carea;
1846: } else {
1847: $sortkey.="\0".$area;
1848: # Determine if current user is able to revoke privileges
1849: if ($area=~m{^/($match_domain)/}) {
1850: if ((&Apache::lonnet::allowed('c'.$role_code,$1)) ||
1851: (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) {
1852: $allowed=1;
1.217 raeburn 1853: }
1.329 raeburn 1854: if (((&Apache::lonnet::allowed('dro',$1)) ||
1855: (&Apache::lonnet::allowed('dro',$ccdomain))) &&
1856: ($role_code ne 'dc')) {
1857: $delallowed=1;
1.217 raeburn 1858: }
1.329 raeburn 1859: } else {
1860: if (&Apache::lonnet::allowed('c'.$role_code,'/')) {
1.217 raeburn 1861: $allowed=1;
1862: }
1863: }
1.363 raeburn 1864: if ($role_code eq 'ca' || $role_code eq 'au' || $role_code eq 'aa') {
1.377 raeburn 1865: $class='Authoring Space';
1.329 raeburn 1866: } elsif ($role_code eq 'su') {
1867: $class='System';
1.217 raeburn 1868: } else {
1.329 raeburn 1869: $class='Domain';
1.217 raeburn 1870: }
1.329 raeburn 1871: }
1872: if (($role_code eq 'ca') || ($role_code eq 'aa')) {
1873: $area=~m{/($match_domain)/($match_username)};
1874: if (&Apache::lonuserutils::authorpriv($2,$1)) {
1875: $allowed=1;
1.217 raeburn 1876: } else {
1.329 raeburn 1877: $allowed=0;
1.217 raeburn 1878: }
1.329 raeburn 1879: }
1880: my $row = '';
1.406.2.6 raeburn 1881: if ($showall) {
1882: $row.= '<td>';
1883: if (($active) && ($allowed)) {
1884: $row.= '<input type="checkbox" name="rev:'.$thisrole.'" />';
1.217 raeburn 1885: } else {
1.406.2.6 raeburn 1886: if ($active) {
1887: $row.=' ';
1888: } else {
1889: $row.=&mt('expired or revoked');
1890: }
1.217 raeburn 1891: }
1.406.2.6 raeburn 1892: $row.='</td><td>';
1893: if ($allowed && !$active) {
1894: $row.= '<input type="checkbox" name="ren:'.$thisrole.'" />';
1895: } else {
1896: $row.=' ';
1897: }
1898: $row.='</td><td>';
1899: if ($delallowed) {
1900: $row.= '<input type="checkbox" name="del:'.$thisrole.'" />';
1901: } else {
1902: $row.=' ';
1903: }
1904: $row.= '</td>';
1.329 raeburn 1905: }
1906: my $plaintext='';
1907: if (!$croletitle) {
1.375 raeburn 1908: $plaintext=&Apache::lonnet::plaintext($role_code,$class);
1909: if (($showcredits) && ($credits ne '')) {
1910: $plaintext .= '<br/ ><span class="LC_nobreak">'.
1911: '<span class="LC_fontsize_small">'.
1912: &mt('Credits: [_1]',$credits).
1913: '</span></span>';
1914: }
1.329 raeburn 1915: } else {
1916: $plaintext=
1.395 bisitz 1917: &mt('Custom role [_1][_2]defined by [_3]',
1.346 bisitz 1918: '"'.$croletitle.'"',
1919: '<br />',
1920: $croleuname.':'.$croleudom);
1.329 raeburn 1921: }
1.406.2.6 raeburn 1922: $row.= '<td>'.$plaintext.'</td>'.
1923: '<td>'.$area.'</td>'.
1924: '<td>'.($role_start_time?&Apache::lonlocal::locallocaltime($role_start_time)
1925: : ' ' ).'</td>'.
1926: '<td>'.($role_end_time ?&Apache::lonlocal::locallocaltime($role_end_time)
1927: : ' ' ).'</td>';
1.329 raeburn 1928: $sortrole{$sortkey}=$envkey;
1929: $roletext{$envkey}=$row;
1930: $roleclass{$envkey}=$class;
1.406.2.6 raeburn 1931: if ($allowed) {
1932: $rolepriv{$envkey}='edit';
1933: } else {
1934: if ($context eq 'domain') {
1.406.2.7 raeburn 1935: if ((&Apache::lonnet::allowed('vur',$ccdomain)) &&
1936: ($envkey=~m{^/$ccdomain/})) {
1.406.2.6 raeburn 1937: $rolepriv{$envkey}='view';
1938: }
1939: } elsif ($context eq 'course') {
1940: if ((&Apache::lonnet::allowed('vcl',$env{'request.course.id'})) ||
1941: ($env{'request.course.sec'} && ($env{'request.course.sec'} eq $csec) &&
1942: &Apache::lonnet::allowed('vcl',$env{'request.course.id'}.'/'.$env{'request.course.sec'}))) {
1943: $rolepriv{$envkey}='view';
1944: }
1945: }
1946: }
1.329 raeburn 1947: } # end of foreach (table building loop)
1948:
1949: my $rolesdisplay = 0;
1950: my %output = ();
1.377 raeburn 1951: foreach my $type ('Authoring Space','Course','Community','Domain','System','Unknown') {
1.329 raeburn 1952: $output{$type} = '';
1953: foreach my $which (sort {uc($a) cmp uc($b)} (keys(%sortrole))) {
1954: if ( ($roleclass{$sortrole{$which}} =~ /^\Q$type\E/ ) && ($rolepriv{$sortrole{$which}}) ) {
1955: $output{$type}.=
1956: &Apache::loncommon::start_data_table_row().
1957: $roletext{$sortrole{$which}}.
1958: &Apache::loncommon::end_data_table_row();
1.217 raeburn 1959: }
1.329 raeburn 1960: }
1961: unless($output{$type} eq '') {
1962: $output{$type} = '<tr class="LC_info_row">'.
1963: "<td align='center' colspan='7'>".&mt($type)."</td></tr>".
1964: $output{$type};
1965: $rolesdisplay = 1;
1966: }
1967: }
1968: if ($rolesdisplay == 1) {
1969: my $contextrole='';
1970: if ($env{'request.course.id'}) {
1971: if (&Apache::loncommon::course_type() eq 'Community') {
1972: $contextrole = &mt('Existing Roles in this Community');
1.290 bisitz 1973: } else {
1.329 raeburn 1974: $contextrole = &mt('Existing Roles in this Course');
1.290 bisitz 1975: }
1.329 raeburn 1976: } elsif ($env{'request.role'} =~ /^au\./) {
1.377 raeburn 1977: $contextrole = &mt('Existing Co-Author Roles in your Authoring Space');
1.329 raeburn 1978: } else {
1.406.2.6 raeburn 1979: if ($showall) {
1980: $contextrole = &mt('Existing Roles in this Domain');
1981: } elsif ($showactive) {
1982: $contextrole = &mt('Unexpired Roles in this Domain');
1983: } elsif ($showexpired) {
1984: $contextrole = &mt('Expired or Revoked Roles in this Domain');
1985: }
1.329 raeburn 1986: }
1.393 raeburn 1987: $r->print('<div class="LC_left_float">'.
1.375 raeburn 1988: '<fieldset><legend>'.$contextrole.'</legend>'.
1.217 raeburn 1989: &Apache::loncommon::start_data_table("LC_createuser").
1.406.2.6 raeburn 1990: &Apache::loncommon::start_data_table_header_row());
1991: if ($showall) {
1992: $r->print(
1993: '<th>'.$lt{'rev'}.'</th><th>'.$lt{'ren'}.'</th><th>'.$lt{'del'}.'</th>'
1994: );
1995: } elsif ($showexpired) {
1996: $r->print('<th>'.$lt{'rev'}.'</th>');
1997: }
1998: $r->print(
1999: '<th>'.$lt{'rol'}.'</th><th>'.$lt{'ext'}.'</th>'.
2000: '<th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'.
1.217 raeburn 2001: &Apache::loncommon::end_data_table_header_row());
1.377 raeburn 2002: foreach my $type ('Authoring Space','Course','Community','Domain','System','Unknown') {
1.329 raeburn 2003: if ($output{$type}) {
2004: $r->print($output{$type}."\n");
1.217 raeburn 2005: }
2006: }
1.375 raeburn 2007: $r->print(&Apache::loncommon::end_data_table().
2008: '</fieldset></div>');
1.329 raeburn 2009: }
1.217 raeburn 2010: return;
2011: }
2012:
1.218 raeburn 2013: sub new_coauthor_roles {
2014: my ($r,$ccuname,$ccdomain) = @_;
2015: my $addrolesdisplay = 0;
2016: #
2017: # Co-Author
2018: #
2019: if (&Apache::lonuserutils::authorpriv($env{'user.name'},
2020: $env{'request.role.domain'}) &&
2021: ($env{'user.name'} ne $ccuname || $env{'user.domain'} ne $ccdomain)) {
2022: # No sense in assigning co-author role to yourself
2023: $addrolesdisplay = 1;
2024: my $cuname=$env{'user.name'};
2025: my $cudom=$env{'request.role.domain'};
2026: my %lt=&Apache::lonlocal::texthash(
1.377 raeburn 2027: 'cs' => "Authoring Space",
1.218 raeburn 2028: 'act' => "Activate",
2029: 'rol' => "Role",
2030: 'ext' => "Extent",
2031: 'sta' => "Start",
2032: 'end' => "End",
2033: 'cau' => "Co-Author",
2034: 'caa' => "Assistant Co-Author",
2035: 'ssd' => "Set Start Date",
2036: 'sed' => "Set End Date"
2037: );
2038: $r->print('<h4>'.$lt{'cs'}.'</h4>'."\n".
2039: &Apache::loncommon::start_data_table()."\n".
2040: &Apache::loncommon::start_data_table_header_row()."\n".
2041: '<th>'.$lt{'act'}.'</th><th>'.$lt{'rol'}.'</th>'.
2042: '<th>'.$lt{'ext'}.'</th><th>'.$lt{'sta'}.'</th>'.
2043: '<th>'.$lt{'end'}.'</th>'."\n".
2044: &Apache::loncommon::end_data_table_header_row()."\n".
2045: &Apache::loncommon::start_data_table_row().'
2046: <td>
1.291 bisitz 2047: <input type="checkbox" name="act_'.$cudom.'_'.$cuname.'_ca" />
1.218 raeburn 2048: </td>
2049: <td>'.$lt{'cau'}.'</td>
2050: <td>'.$cudom.'_'.$cuname.'</td>
2051: <td><input type="hidden" name="start_'.$cudom.'_'.$cuname.'_ca" value="" />
2052: <a href=
2053: "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>
2054: <td><input type="hidden" name="end_'.$cudom.'_'.$cuname.'_ca" value="" />
2055: <a href=
2056: "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".
2057: &Apache::loncommon::end_data_table_row()."\n".
2058: &Apache::loncommon::start_data_table_row()."\n".
1.291 bisitz 2059: '<td><input type="checkbox" name="act_'.$cudom.'_'.$cuname.'_aa" /></td>
1.218 raeburn 2060: <td>'.$lt{'caa'}.'</td>
2061: <td>'.$cudom.'_'.$cuname.'</td>
2062: <td><input type="hidden" name="start_'.$cudom.'_'.$cuname.'_aa" value="" />
2063: <a href=
2064: "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>
2065: <td><input type="hidden" name="end_'.$cudom.'_'.$cuname.'_aa" value="" />
2066: <a href=
2067: "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".
2068: &Apache::loncommon::end_data_table_row()."\n".
2069: &Apache::loncommon::end_data_table());
2070: } elsif ($env{'request.role'} =~ /^au\./) {
2071: if (!(&Apache::lonuserutils::authorpriv($env{'user.name'},
2072: $env{'request.role.domain'}))) {
2073: $r->print('<span class="LC_error">'.
2074: &mt('You do not have privileges to assign co-author roles.').
2075: '</span>');
2076: } elsif (($env{'user.name'} eq $ccuname) &&
2077: ($env{'user.domain'} eq $ccdomain)) {
1.377 raeburn 2078: $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 2079: }
2080: }
2081: return $addrolesdisplay;;
2082: }
2083:
2084: sub new_domain_roles {
1.357 raeburn 2085: my ($r,$ccdomain) = @_;
1.218 raeburn 2086: my $addrolesdisplay = 0;
2087: #
2088: # Domain level
2089: #
2090: my $num_domain_level = 0;
2091: my $domaintext =
2092: '<h4>'.&mt('Domain Level').'</h4>'.
2093: &Apache::loncommon::start_data_table().
2094: &Apache::loncommon::start_data_table_header_row().
2095: '<th>'.&mt('Activate').'</th><th>'.&mt('Role').'</th><th>'.
2096: &mt('Extent').'</th>'.
2097: '<th>'.&mt('Start').'</th><th>'.&mt('End').'</th>'.
2098: &Apache::loncommon::end_data_table_header_row();
1.312 raeburn 2099: my @allroles = &Apache::lonuserutils::roles_by_context('domain');
1.218 raeburn 2100: foreach my $thisdomain (sort(&Apache::lonnet::all_domains())) {
1.312 raeburn 2101: foreach my $role (@allroles) {
2102: next if ($role eq 'ad');
1.357 raeburn 2103: next if (($role eq 'au') && ($ccdomain ne $thisdomain));
1.218 raeburn 2104: if (&Apache::lonnet::allowed('c'.$role,$thisdomain)) {
2105: my $plrole=&Apache::lonnet::plaintext($role);
2106: my %lt=&Apache::lonlocal::texthash(
2107: 'ssd' => "Set Start Date",
2108: 'sed' => "Set End Date"
2109: );
2110: $num_domain_level ++;
2111: $domaintext .=
2112: &Apache::loncommon::start_data_table_row().
1.291 bisitz 2113: '<td><input type="checkbox" name="act_'.$thisdomain.'_'.$role.'" /></td>
1.218 raeburn 2114: <td>'.$plrole.'</td>
2115: <td>'.$thisdomain.'</td>
2116: <td><input type="hidden" name="start_'.$thisdomain.'_'.$role.'" value="" />
2117: <a href=
2118: "javascript:pjump('."'date_start','Start Date $plrole',document.cu.start_$thisdomain\_$role.value,'start_$thisdomain\_$role','cu.pres','dateset'".')">'.$lt{'ssd'}.'</a></td>
2119: <td><input type="hidden" name="end_'.$thisdomain.'_'.$role.'" value="" />
2120: <a href=
2121: "javascript:pjump('."'date_end','End Date $plrole',document.cu.end_$thisdomain\_$role.value,'end_$thisdomain\_$role','cu.pres','dateset'".')">'.$lt{'sed'}.'</a></td>'.
2122: &Apache::loncommon::end_data_table_row();
2123: }
2124: }
2125: }
2126: $domaintext.= &Apache::loncommon::end_data_table();
2127: if ($num_domain_level > 0) {
2128: $r->print($domaintext);
2129: $addrolesdisplay = 1;
2130: }
2131: return $addrolesdisplay;
2132: }
2133:
1.188 raeburn 2134: sub user_authentication {
1.227 raeburn 2135: my ($ccuname,$ccdomain,$formname) = @_;
1.188 raeburn 2136: my $currentauth=&Apache::lonnet::queryauthenticate($ccuname,$ccdomain);
1.227 raeburn 2137: my $outcome;
1.406.2.6 raeburn 2138: my %lt=&Apache::lonlocal::texthash(
2139: 'err' => "ERROR",
2140: 'uuas' => "This user has an unrecognized authentication scheme",
2141: 'adcs' => "Please alert a domain coordinator of this situation",
2142: 'sldb' => "Please specify login data below",
2143: 'ld' => "Login Data"
2144: );
1.188 raeburn 2145: # Check for a bad authentication type
2146: if ($currentauth !~ /^(krb4|krb5|unix|internal|localauth):/) {
2147: # bad authentication scheme
2148: if (&Apache::lonnet::allowed('mau',$ccdomain)) {
1.227 raeburn 2149: &initialize_authen_forms($ccdomain,$formname);
2150:
1.190 raeburn 2151: my $choices = &Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc);
1.188 raeburn 2152: $outcome = <<ENDBADAUTH;
2153: <script type="text/javascript" language="Javascript">
1.301 bisitz 2154: // <![CDATA[
1.188 raeburn 2155: $loginscript
1.301 bisitz 2156: // ]]>
1.188 raeburn 2157: </script>
2158: <span class="LC_error">$lt{'err'}:
2159: $lt{'uuas'} ($currentauth). $lt{'sldb'}.</span>
2160: <h3>$lt{'ld'}</h3>
2161: $choices
2162: ENDBADAUTH
2163: } else {
2164: # This user is not allowed to modify the user's
2165: # authentication scheme, so just notify them of the problem
2166: $outcome = <<ENDBADAUTH;
2167: <span class="LC_error"> $lt{'err'}:
2168: $lt{'uuas'} ($currentauth). $lt{'adcs'}.
2169: </span>
2170: ENDBADAUTH
2171: }
2172: } else { # Authentication type is valid
1.227 raeburn 2173: &initialize_authen_forms($ccdomain,$formname,$currentauth,'modifyuser');
1.205 raeburn 2174: my ($authformcurrent,$can_modify,@authform_others) =
1.188 raeburn 2175: &modify_login_block($ccdomain,$currentauth);
2176: if (&Apache::lonnet::allowed('mau',$ccdomain)) {
2177: # Current user has login modification privileges
2178: $outcome =
2179: '<script type="text/javascript" language="Javascript">'."\n".
1.301 bisitz 2180: '// <![CDATA['."\n".
1.188 raeburn 2181: $loginscript."\n".
1.301 bisitz 2182: '// ]]>'."\n".
1.188 raeburn 2183: '</script>'."\n".
2184: '<h3>'.$lt{'ld'}.'</h3>'.
2185: &Apache::loncommon::start_data_table().
1.205 raeburn 2186: &Apache::loncommon::start_data_table_row().
1.188 raeburn 2187: '<td>'.$authformnop;
1.406.2.6 raeburn 2188: if (($can_modify) && (&Apache::lonnet::allowed('mau',$ccdomain))) {
1.188 raeburn 2189: $outcome .= '</td>'."\n".
2190: &Apache::loncommon::end_data_table_row().
2191: &Apache::loncommon::start_data_table_row().
2192: '<td>'.$authformcurrent.'</td>'.
2193: &Apache::loncommon::end_data_table_row()."\n";
2194: } else {
1.200 raeburn 2195: $outcome .= ' ('.$authformcurrent.')</td>'.
2196: &Apache::loncommon::end_data_table_row()."\n";
1.188 raeburn 2197: }
1.406.2.6 raeburn 2198: if (&Apache::lonnet::allowed('mau',$ccdomain)) {
2199: foreach my $item (@authform_others) {
2200: $outcome .= &Apache::loncommon::start_data_table_row().
2201: '<td>'.$item.'</td>'.
2202: &Apache::loncommon::end_data_table_row()."\n";
2203: }
1.188 raeburn 2204: }
1.205 raeburn 2205: $outcome .= &Apache::loncommon::end_data_table();
1.188 raeburn 2206: } else {
1.406.2.6 raeburn 2207: if (&Apache::lonnet::allowed('udp',$ccdomain)) {
2208: # Current user has rights to view domain preferences for user's domain
2209: my $result;
2210: if ($currentauth =~ /^krb(4|5):([^:]*)$/) {
2211: my ($krbver,$krbrealm) = ($1,$2);
2212: if ($krbrealm eq '') {
2213: $result = &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
2214: } else {
2215: $result = &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
1.406.2.9 raeburn 2216: $krbrealm,$krbver);
1.406.2.6 raeburn 2217: }
2218: } elsif ($currentauth =~ /^internal:/) {
2219: $result = &mt('Currently internally authenticated.');
2220: } elsif ($currentauth =~ /^localauth:/) {
2221: $result = &mt('Currently using local (institutional) authentication.');
2222: } elsif ($currentauth =~ /^unix:/) {
2223: $result = &mt('Currently Filesystem Authenticated.');
2224: }
2225: $outcome = '<h3>'.$lt{'ld'}.'</h3>'.
2226: &Apache::loncommon::start_data_table().
2227: &Apache::loncommon::start_data_table_row().
2228: '<td>'.$result.'</td>'.
2229: &Apache::loncommon::end_data_table_row()."\n".
2230: &Apache::loncommon::end_data_table();
2231: } elsif (&Apache::lonnet::allowed('mau',$env{'request.role.domain'})) {
1.188 raeburn 2232: my %lt=&Apache::lonlocal::texthash(
2233: 'ccld' => "Change Current Login Data",
2234: 'yodo' => "You do not have privileges to modify the authentication configuration for this user.",
2235: 'ifch' => "If a change is required, contact a domain coordinator for the domain",
2236: );
2237: $outcome .= <<ENDNOPRIV;
2238: <h3>$lt{'ccld'}</h3>
2239: $lt{'yodo'} $lt{'ifch'}: $ccdomain
1.235 raeburn 2240: <input type="hidden" name="login" value="nochange" />
1.188 raeburn 2241: ENDNOPRIV
2242: }
2243: }
2244: } ## End of "check for bad authentication type" logic
2245: return $outcome;
2246: }
2247:
1.187 raeburn 2248: sub modify_login_block {
2249: my ($dom,$currentauth) = @_;
2250: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
2251: my ($authnum,%can_assign) =
2252: &Apache::loncommon::get_assignable_auth($dom);
1.205 raeburn 2253: my ($authformcurrent,@authform_others,$show_override_msg);
1.187 raeburn 2254: if ($currentauth=~/^krb(4|5):/) {
2255: $authformcurrent=$authformkrb;
2256: if ($can_assign{'int'}) {
1.205 raeburn 2257: push(@authform_others,$authformint);
1.187 raeburn 2258: }
2259: if ($can_assign{'loc'}) {
1.205 raeburn 2260: push(@authform_others,$authformloc);
1.187 raeburn 2261: }
2262: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
2263: $show_override_msg = 1;
2264: }
2265: } elsif ($currentauth=~/^internal:/) {
2266: $authformcurrent=$authformint;
2267: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205 raeburn 2268: push(@authform_others,$authformkrb);
1.187 raeburn 2269: }
2270: if ($can_assign{'loc'}) {
1.205 raeburn 2271: push(@authform_others,$authformloc);
1.187 raeburn 2272: }
2273: if ($can_assign{'int'}) {
2274: $show_override_msg = 1;
2275: }
2276: } elsif ($currentauth=~/^unix:/) {
2277: $authformcurrent=$authformfsys;
2278: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205 raeburn 2279: push(@authform_others,$authformkrb);
1.187 raeburn 2280: }
2281: if ($can_assign{'int'}) {
1.205 raeburn 2282: push(@authform_others,$authformint);
1.187 raeburn 2283: }
2284: if ($can_assign{'loc'}) {
1.205 raeburn 2285: push(@authform_others,$authformloc);
1.187 raeburn 2286: }
2287: if ($can_assign{'fsys'}) {
2288: $show_override_msg = 1;
2289: }
2290: } elsif ($currentauth=~/^localauth:/) {
2291: $authformcurrent=$authformloc;
2292: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205 raeburn 2293: push(@authform_others,$authformkrb);
1.187 raeburn 2294: }
2295: if ($can_assign{'int'}) {
1.205 raeburn 2296: push(@authform_others,$authformint);
1.187 raeburn 2297: }
2298: if ($can_assign{'loc'}) {
2299: $show_override_msg = 1;
2300: }
2301: }
2302: if ($show_override_msg) {
1.205 raeburn 2303: $authformcurrent = '<table><tr><td colspan="3">'.$authformcurrent.
2304: '</td></tr>'."\n".
2305: '<tr><td> </td>'.
2306: '<td><b>'.&mt('Currently in use').'</b></td>'.
2307: '<td align="right"><span class="LC_cusr_emph">'.
1.187 raeburn 2308: &mt('will override current values').
1.205 raeburn 2309: '</span></td></tr></table>';
1.187 raeburn 2310: }
1.205 raeburn 2311: return ($authformcurrent,$show_override_msg,@authform_others);
1.187 raeburn 2312: }
2313:
1.188 raeburn 2314: sub personal_data_display {
1.391 raeburn 2315: my ($ccuname,$ccdomain,$newuser,$context,$inst_results,$rolesarray,
1.396 raeburn 2316: $now,$captchaform,$emailusername,$usertype) = @_;
1.388 bisitz 2317: my ($output,%userenv,%canmodify,%canmodify_status);
1.219 raeburn 2318: my @userinfo = ('firstname','middlename','lastname','generation',
2319: 'permanentemail','id');
1.252 raeburn 2320: my $rowcount = 0;
2321: my $editable = 0;
1.391 raeburn 2322: my %textboxsize = (
2323: firstname => '15',
2324: middlename => '15',
2325: lastname => '15',
2326: generation => '5',
2327: permanentemail => '25',
2328: id => '15',
2329: );
2330:
2331: my %lt=&Apache::lonlocal::texthash(
2332: 'pd' => "Personal Data",
2333: 'firstname' => "First Name",
2334: 'middlename' => "Middle Name",
2335: 'lastname' => "Last Name",
2336: 'generation' => "Generation",
2337: 'permanentemail' => "Permanent e-mail address",
2338: 'id' => "Student/Employee ID",
2339: 'lg' => "Login Data",
2340: 'inststatus' => "Affiliation",
2341: 'email' => 'E-mail address',
2342: 'valid' => 'Validation',
2343: );
2344:
2345: %canmodify_status =
1.286 raeburn 2346: &Apache::lonuserutils::can_modify_userinfo($context,$ccdomain,
2347: ['inststatus'],$rolesarray);
1.253 raeburn 2348: if (!$newuser) {
1.188 raeburn 2349: # Get the users information
2350: %userenv = &Apache::lonnet::get('environment',
2351: ['firstname','middlename','lastname','generation',
1.286 raeburn 2352: 'permanentemail','id','inststatus'],$ccdomain,$ccuname);
1.219 raeburn 2353: %canmodify =
2354: &Apache::lonuserutils::can_modify_userinfo($context,$ccdomain,
1.252 raeburn 2355: \@userinfo,$rolesarray);
1.257 raeburn 2356: } elsif ($context eq 'selfcreate') {
1.391 raeburn 2357: if ($newuser eq 'email') {
1.396 raeburn 2358: if (ref($emailusername) eq 'HASH') {
2359: if (ref($emailusername->{$usertype}) eq 'HASH') {
2360: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
2361: @userinfo = ();
2362: if ((ref($infofields) eq 'ARRAY') && (ref($infotitles) eq 'HASH')) {
2363: foreach my $field (@{$infofields}) {
2364: if ($emailusername->{$usertype}->{$field}) {
2365: push(@userinfo,$field);
2366: $canmodify{$field} = 1;
2367: unless ($textboxsize{$field}) {
2368: $textboxsize{$field} = 25;
2369: }
2370: unless ($lt{$field}) {
2371: $lt{$field} = $infotitles->{$field};
2372: }
2373: if ($emailusername->{$usertype}->{$field} eq 'required') {
2374: $lt{$field} .= '<b>*</b>';
2375: }
1.391 raeburn 2376: }
2377: }
2378: }
2379: }
2380: }
2381: } else {
2382: %canmodify = &selfcreate_canmodify($context,$ccdomain,\@userinfo,
2383: $inst_results,$rolesarray);
2384: }
1.188 raeburn 2385: }
1.391 raeburn 2386:
1.188 raeburn 2387: my $genhelp=&Apache::loncommon::help_open_topic('Generation');
2388: $output = '<h3>'.$lt{'pd'}.'</h3>'.
2389: &Apache::lonhtmlcommon::start_pick_box();
1.391 raeburn 2390: if (($context eq 'selfcreate') && ($newuser eq 'email')) {
1.396 raeburn 2391: $output .= &Apache::lonhtmlcommon::row_title($lt{'email'}.'<b>*</b>',undef,
1.391 raeburn 2392: 'LC_oddrow_value')."\n".
1.394 raeburn 2393: '<input type="text" name="uname" size="25" value="" autocomplete="off" />';
1.391 raeburn 2394: $rowcount ++;
2395: $output .= &Apache::lonhtmlcommon::row_closure(1);
1.406.2.1 raeburn 2396: my $upassone = '<input type="password" name="upass'.$now.'" size="20" autocomplete="off" />';
2397: my $upasstwo = '<input type="password" name="upasscheck'.$now.'" size="20" autocomplete="off" />';
1.396 raeburn 2398: $output .= &Apache::lonhtmlcommon::row_title(&mt('Password').'<b>*</b>',
1.391 raeburn 2399: 'LC_pick_box_title',
2400: 'LC_oddrow_value')."\n".
2401: $upassone."\n".
2402: &Apache::lonhtmlcommon::row_closure(1)."\n".
1.396 raeburn 2403: &Apache::lonhtmlcommon::row_title(&mt('Confirm password').'<b>*</b>',
1.391 raeburn 2404: 'LC_pick_box_title',
2405: 'LC_oddrow_value')."\n".
2406: $upasstwo.
2407: &Apache::lonhtmlcommon::row_closure()."\n";
2408: }
1.188 raeburn 2409: foreach my $item (@userinfo) {
2410: my $rowtitle = $lt{$item};
1.252 raeburn 2411: my $hiderow = 0;
1.188 raeburn 2412: if ($item eq 'generation') {
2413: $rowtitle = $genhelp.$rowtitle;
2414: }
1.252 raeburn 2415: my $row = &Apache::lonhtmlcommon::row_title($rowtitle,undef,'LC_oddrow_value')."\n";
1.188 raeburn 2416: if ($newuser) {
1.210 raeburn 2417: if (ref($inst_results) eq 'HASH') {
2418: if ($inst_results->{$item} ne '') {
1.252 raeburn 2419: $row .= '<input type="hidden" name="c'.$item.'" value="'.$inst_results->{$item}.'" />'.$inst_results->{$item};
1.210 raeburn 2420: } else {
1.252 raeburn 2421: if ($context eq 'selfcreate') {
1.391 raeburn 2422: if ($canmodify{$item}) {
1.394 raeburn 2423: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" autocomplete="off" />';
1.252 raeburn 2424: $editable ++;
2425: } else {
2426: $hiderow = 1;
2427: }
1.253 raeburn 2428: } else {
2429: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
1.252 raeburn 2430: }
1.210 raeburn 2431: }
1.188 raeburn 2432: } else {
1.252 raeburn 2433: if ($context eq 'selfcreate') {
1.401 raeburn 2434: if ($canmodify{$item}) {
2435: if ($newuser eq 'email') {
2436: $row .= '<input type="text" name="'.$item.'" size="'.$textboxsize{$item}.'" value="" autocomplete="off" />';
1.287 raeburn 2437: } else {
1.401 raeburn 2438: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" autocomplete="off" />';
1.287 raeburn 2439: }
1.401 raeburn 2440: $editable ++;
2441: } else {
2442: $hiderow = 1;
1.252 raeburn 2443: }
1.253 raeburn 2444: } else {
2445: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
1.252 raeburn 2446: }
1.188 raeburn 2447: }
2448: } else {
1.219 raeburn 2449: if ($canmodify{$item}) {
1.252 raeburn 2450: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="'.$userenv{$item}.'" />';
1.393 raeburn 2451: if (($item eq 'id') && (!$newuser)) {
2452: $row .= '<br />'.&Apache::lonuserutils::forceid_change($context);
2453: }
1.188 raeburn 2454: } else {
1.252 raeburn 2455: $row .= $userenv{$item};
1.188 raeburn 2456: }
2457: }
1.252 raeburn 2458: $row .= &Apache::lonhtmlcommon::row_closure(1);
2459: if (!$hiderow) {
2460: $output .= $row;
2461: $rowcount ++;
2462: }
1.188 raeburn 2463: }
1.286 raeburn 2464: if (($canmodify_status{'inststatus'}) || ($context ne 'selfcreate')) {
2465: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($ccdomain);
2466: if (ref($types) eq 'ARRAY') {
2467: if (@{$types} > 0) {
2468: my ($hiderow,$shown);
2469: if ($canmodify_status{'inststatus'}) {
2470: $shown = &pick_inst_statuses($userenv{'inststatus'},$usertypes,$types);
2471: } else {
2472: if ($userenv{'inststatus'} eq '') {
2473: $hiderow = 1;
1.334 raeburn 2474: } else {
2475: my @showitems;
2476: foreach my $item ( map { &unescape($_); } split(':',$userenv{'inststatus'})) {
2477: if (exists($usertypes->{$item})) {
2478: push(@showitems,$usertypes->{$item});
2479: } else {
2480: push(@showitems,$item);
2481: }
2482: }
2483: if (@showitems) {
2484: $shown = join(', ',@showitems);
2485: } else {
2486: $hiderow = 1;
2487: }
1.286 raeburn 2488: }
2489: }
2490: if (!$hiderow) {
1.389 bisitz 2491: my $row = &Apache::lonhtmlcommon::row_title(&mt('Affiliations'),undef,'LC_oddrow_value')."\n".
1.286 raeburn 2492: $shown.&Apache::lonhtmlcommon::row_closure(1);
2493: if ($context eq 'selfcreate') {
2494: $rowcount ++;
2495: }
2496: $output .= $row;
2497: }
2498: }
2499: }
2500: }
1.391 raeburn 2501: if (($context eq 'selfcreate') && ($newuser eq 'email')) {
2502: if ($captchaform) {
1.406.2.2 raeburn 2503: $output .= &Apache::lonhtmlcommon::row_title($lt{'valid'}.'*',
1.391 raeburn 2504: 'LC_pick_box_title')."\n".
2505: $captchaform."\n".'<br /><br />'.
2506: &Apache::lonhtmlcommon::row_closure(1);
2507: $rowcount ++;
2508: }
2509: my $submit_text = &mt('Create account');
2510: $output .= &Apache::lonhtmlcommon::row_title()."\n".
2511: '<br /><input type="submit" name="createaccount" value="'.
2512: $submit_text.'" />'.
1.396 raeburn 2513: '<input type="hidden" name="type" value="'.$usertype.'" />'.
1.391 raeburn 2514: &Apache::lonhtmlcommon::row_closure(1);
2515: }
1.188 raeburn 2516: $output .= &Apache::lonhtmlcommon::end_pick_box();
1.206 raeburn 2517: if (wantarray) {
1.252 raeburn 2518: if ($context eq 'selfcreate') {
2519: return($output,$rowcount,$editable);
2520: } else {
1.388 bisitz 2521: return $output;
1.252 raeburn 2522: }
1.206 raeburn 2523: } else {
2524: return $output;
2525: }
1.188 raeburn 2526: }
2527:
1.286 raeburn 2528: sub pick_inst_statuses {
2529: my ($curr,$usertypes,$types) = @_;
2530: my ($output,$rem,@currtypes);
2531: if ($curr ne '') {
2532: @currtypes = map { &unescape($_); } split(/:/,$curr);
2533: }
2534: my $numinrow = 2;
2535: if (ref($types) eq 'ARRAY') {
2536: $output = '<table>';
2537: my $lastcolspan;
2538: for (my $i=0; $i<@{$types}; $i++) {
2539: if (defined($usertypes->{$types->[$i]})) {
2540: my $rem = $i%($numinrow);
2541: if ($rem == 0) {
2542: if ($i<@{$types}-1) {
2543: if ($i > 0) {
2544: $output .= '</tr>';
2545: }
2546: $output .= '<tr>';
2547: }
2548: } elsif ($i==@{$types}-1) {
2549: my $colsleft = $numinrow - $rem;
2550: if ($colsleft > 1) {
2551: $lastcolspan = ' colspan="'.$colsleft.'"';
2552: }
2553: }
2554: my $check = ' ';
2555: if (grep(/^\Q$types->[$i]\E$/,@currtypes)) {
2556: $check = ' checked="checked" ';
2557: }
2558: $output .= '<td class="LC_left_item"'.$lastcolspan.'>'.
2559: '<span class="LC_nobreak"><label>'.
2560: '<input type="checkbox" name="inststatus" '.
2561: 'value="'.$types->[$i].'"'.$check.'/>'.
2562: $usertypes->{$types->[$i]}.'</label></span></td>';
2563: }
2564: }
2565: $output .= '</tr></table>';
2566: }
2567: return $output;
2568: }
2569:
1.257 raeburn 2570: sub selfcreate_canmodify {
2571: my ($context,$dom,$userinfo,$inst_results,$rolesarray) = @_;
2572: if (ref($inst_results) eq 'HASH') {
2573: my @inststatuses = &get_inststatuses($inst_results);
2574: if (@inststatuses == 0) {
2575: @inststatuses = ('default');
2576: }
2577: $rolesarray = \@inststatuses;
2578: }
2579: my %canmodify =
2580: &Apache::lonuserutils::can_modify_userinfo($context,$dom,$userinfo,
2581: $rolesarray);
2582: return %canmodify;
2583: }
2584:
1.252 raeburn 2585: sub get_inststatuses {
2586: my ($insthashref) = @_;
2587: my @inststatuses = ();
2588: if (ref($insthashref) eq 'HASH') {
2589: if (ref($insthashref->{'inststatus'}) eq 'ARRAY') {
2590: @inststatuses = @{$insthashref->{'inststatus'}};
2591: }
2592: }
2593: return @inststatuses;
2594: }
2595:
1.4 www 2596: # ================================================================= Phase Three
1.42 matthew 2597: sub update_user_data {
1.375 raeburn 2598: my ($r,$context,$crstype,$brcrum,$showcredits) = @_;
1.101 albertel 2599: my $uhome=&Apache::lonnet::homeserver($env{'form.ccuname'},
2600: $env{'form.ccdomain'});
1.27 matthew 2601: # Error messages
1.188 raeburn 2602: my $error = '<span class="LC_error">'.&mt('Error').': ';
1.193 raeburn 2603: my $end = '</span><br /><br />';
2604: my $rtnlink = '<a href="javascript:backPage(document.userupdate,'.
1.188 raeburn 2605: "'$env{'form.prevphase'}','modify')".'" />'.
1.219 raeburn 2606: &mt('Return to previous page').'</a>'.
2607: &Apache::loncommon::end_page();
2608: my $now = time;
1.40 www 2609: my $title;
1.101 albertel 2610: if (exists($env{'form.makeuser'})) {
1.40 www 2611: $title='Set Privileges for New User';
2612: } else {
2613: $title='Modify User Privileges';
2614: }
1.213 raeburn 2615: my $newuser = 0;
1.160 raeburn 2616: my ($jsback,$elements) = &crumb_utilities();
2617: my $jscript = '<script type="text/javascript">'."\n".
1.301 bisitz 2618: '// <![CDATA['."\n".
2619: $jsback."\n".
2620: '// ]]>'."\n".
2621: '</script>'."\n";
1.406.2.7 raeburn 2622: my %breadcrumb_text = &singleuser_breadcrumb($crstype,$context,$env{'form.ccdomain'});
1.351 raeburn 2623: push (@{$brcrum},
2624: {href => "javascript:backPage(document.userupdate)",
2625: text => $breadcrumb_text{'search'},
2626: faq => 282,
2627: bug => 'Instructor Interface',}
2628: );
2629: if ($env{'form.prevphase'} eq 'userpicked') {
2630: push(@{$brcrum},
2631: {href => "javascript:backPage(document.userupdate,'get_user_info','select')",
2632: text => $breadcrumb_text{'userpicked'},
2633: faq => 282,
2634: bug => 'Instructor Interface',});
1.233 raeburn 2635: }
1.224 raeburn 2636: my $helpitem = 'Course_Change_Privileges';
2637: if ($env{'form.action'} eq 'singlestudent') {
2638: $helpitem = 'Course_Add_Student';
2639: }
1.351 raeburn 2640: push(@{$brcrum},
2641: {href => "javascript:backPage(document.userupdate,'$env{'form.prevphase'}','modify')",
2642: text => $breadcrumb_text{'modify'},
2643: faq => 282,
2644: bug => 'Instructor Interface',},
2645: {href => "/adm/createuser",
2646: text => "Result",
2647: faq => 282,
2648: bug => 'Instructor Interface',
2649: help => $helpitem});
2650: my $args = {bread_crumbs => $brcrum,
2651: bread_crumbs_component => 'User Management'};
2652: if ($env{'form.popup'}) {
2653: $args->{'no_nav_bar'} = 1;
2654: }
2655: $r->print(&Apache::loncommon::start_page($title,$jscript,$args));
1.188 raeburn 2656: $r->print(&update_result_form($uhome));
1.27 matthew 2657: # Check Inputs
1.101 albertel 2658: if (! $env{'form.ccuname'} ) {
1.193 raeburn 2659: $r->print($error.&mt('No login name specified').'.'.$end.$rtnlink);
1.27 matthew 2660: return;
2661: }
1.138 albertel 2662: if ( $env{'form.ccuname'} ne
2663: &LONCAPA::clean_username($env{'form.ccuname'}) ) {
1.281 bisitz 2664: $r->print($error.&mt('Invalid login name.').' '.
2665: &mt('Only letters, numbers, periods, dashes, @, and underscores are valid.').
1.193 raeburn 2666: $end.$rtnlink);
1.27 matthew 2667: return;
2668: }
1.101 albertel 2669: if (! $env{'form.ccdomain'} ) {
1.193 raeburn 2670: $r->print($error.&mt('No domain specified').'.'.$end.$rtnlink);
1.27 matthew 2671: return;
2672: }
1.138 albertel 2673: if ( $env{'form.ccdomain'} ne
2674: &LONCAPA::clean_domain($env{'form.ccdomain'}) ) {
1.281 bisitz 2675: $r->print($error.&mt('Invalid domain name.').' '.
2676: &mt('Only letters, numbers, periods, dashes, and underscores are valid.').
1.193 raeburn 2677: $end.$rtnlink);
1.27 matthew 2678: return;
2679: }
1.219 raeburn 2680: if ($uhome eq 'no_host') {
2681: $newuser = 1;
2682: }
1.101 albertel 2683: if (! exists($env{'form.makeuser'})) {
1.29 matthew 2684: # Modifying an existing user, so check the validity of the name
2685: if ($uhome eq 'no_host') {
1.389 bisitz 2686: $r->print(
2687: $error
2688: .'<p class="LC_error">'
2689: .&mt('Unable to determine home server for [_1] in domain [_2].',
2690: '"'.$env{'form.ccuname'}.'"','"'.$env{'form.ccdomain'}.'"')
2691: .'</p>');
1.29 matthew 2692: return;
2693: }
2694: }
1.27 matthew 2695: # Determine authentication method and password for the user being modified
2696: my $amode='';
2697: my $genpwd='';
1.101 albertel 2698: if ($env{'form.login'} eq 'krb') {
1.41 albertel 2699: $amode='krb';
1.101 albertel 2700: $amode.=$env{'form.krbver'};
2701: $genpwd=$env{'form.krbarg'};
2702: } elsif ($env{'form.login'} eq 'int') {
1.27 matthew 2703: $amode='internal';
1.101 albertel 2704: $genpwd=$env{'form.intarg'};
2705: } elsif ($env{'form.login'} eq 'fsys') {
1.27 matthew 2706: $amode='unix';
1.101 albertel 2707: $genpwd=$env{'form.fsysarg'};
2708: } elsif ($env{'form.login'} eq 'loc') {
1.27 matthew 2709: $amode='localauth';
1.101 albertel 2710: $genpwd=$env{'form.locarg'};
1.27 matthew 2711: $genpwd=" " if (!$genpwd);
1.101 albertel 2712: } elsif (($env{'form.login'} eq 'nochange') ||
2713: ($env{'form.login'} eq '' )) {
1.34 matthew 2714: # There is no need to tell the user we did not change what they
2715: # did not ask us to change.
1.35 matthew 2716: # If they are creating a new user but have not specified login
2717: # information this will be caught below.
1.30 matthew 2718: } else {
1.367 golterma 2719: $r->print($error.&mt('Invalid login mode or password').$end.$rtnlink);
2720: return;
1.27 matthew 2721: }
1.164 albertel 2722:
1.188 raeburn 2723: $r->print('<h3>'.&mt('User [_1] in domain [_2]',
1.367 golterma 2724: $env{'form.ccuname'}.' ('.&Apache::loncommon::plainname($env{'form.ccuname'},
2725: $env{'form.ccdomain'}).')', $env{'form.ccdomain'}).'</h3>');
2726: my %prog_state = &Apache::lonhtmlcommon::Create_PrgWin($r,2);
1.344 bisitz 2727:
1.193 raeburn 2728: my (%alerts,%rulematch,%inst_results,%curr_rules);
1.334 raeburn 2729: my @userinfo = ('firstname','middlename','lastname','generation','permanentemail','id');
1.361 raeburn 2730: my @usertools = ('aboutme','blog','webdav','portfolio');
1.384 raeburn 2731: my @requestcourses = ('official','unofficial','community','textbook');
1.362 raeburn 2732: my @requestauthor = ('requestauthor');
1.286 raeburn 2733: my ($othertitle,$usertypes,$types) =
2734: &Apache::loncommon::sorted_inst_types($env{'form.ccdomain'});
1.334 raeburn 2735: my %canmodify_status =
2736: &Apache::lonuserutils::can_modify_userinfo($context,$env{'form.ccdomain'},
2737: ['inststatus']);
1.101 albertel 2738: if ($env{'form.makeuser'}) {
1.164 albertel 2739: $r->print('<h3>'.&mt('Creating new account.').'</h3>');
1.27 matthew 2740: # Check for the authentication mode and password
2741: if (! $amode || ! $genpwd) {
1.193 raeburn 2742: $r->print($error.&mt('Invalid login mode or password').$end.$rtnlink);
1.27 matthew 2743: return;
1.18 albertel 2744: }
1.29 matthew 2745: # Determine desired host
1.101 albertel 2746: my $desiredhost = $env{'form.hserver'};
1.29 matthew 2747: if (lc($desiredhost) eq 'default') {
2748: $desiredhost = undef;
2749: } else {
1.147 albertel 2750: my %home_servers =
2751: &Apache::lonnet::get_servers($env{'form.ccdomain'},'library');
1.29 matthew 2752: if (! exists($home_servers{$desiredhost})) {
1.193 raeburn 2753: $r->print($error.&mt('Invalid home server specified').$end.$rtnlink);
2754: return;
2755: }
2756: }
2757: # Check ID format
2758: my %checkhash;
2759: my %checks = ('id' => 1);
2760: %{$checkhash{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}}} = (
1.219 raeburn 2761: 'newuser' => $newuser,
1.196 raeburn 2762: 'id' => $env{'form.cid'},
1.193 raeburn 2763: );
1.196 raeburn 2764: if ($env{'form.cid'} ne '') {
2765: &Apache::loncommon::user_rule_check(\%checkhash,\%checks,\%alerts,
2766: \%rulematch,\%inst_results,\%curr_rules);
2767: if (ref($alerts{'id'}) eq 'HASH') {
2768: if (ref($alerts{'id'}{$env{'form.ccdomain'}}) eq 'HASH') {
2769: my $domdesc =
2770: &Apache::lonnet::domain($env{'form.ccdomain'},'description');
2771: if ($alerts{'id'}{$env{'form.ccdomain'}}{$env{'form.cid'}}) {
2772: my $userchkmsg;
2773: if (ref($curr_rules{$env{'form.ccdomain'}}) eq 'HASH') {
2774: $userchkmsg =
2775: &Apache::loncommon::instrule_disallow_msg('id',
2776: $domdesc,1).
2777: &Apache::loncommon::user_rule_formats($env{'form.ccdomain'},
2778: $domdesc,$curr_rules{$env{'form.ccdomain'}}{'id'},'id');
2779: }
2780: $r->print($error.&mt('Invalid ID format').$end.
2781: $userchkmsg.$rtnlink);
2782: return;
2783: }
2784: }
1.29 matthew 2785: }
2786: }
1.367 golterma 2787: &Apache::lonhtmlcommon::Increment_PrgWin($r, \%prog_state);
1.27 matthew 2788: # Call modifyuser
2789: my $result = &Apache::lonnet::modifyuser
1.193 raeburn 2790: ($env{'form.ccdomain'},$env{'form.ccuname'},$env{'form.cid'},
1.188 raeburn 2791: $amode,$genpwd,$env{'form.cfirstname'},
2792: $env{'form.cmiddlename'},$env{'form.clastname'},
2793: $env{'form.cgeneration'},undef,$desiredhost,
2794: $env{'form.cpermanentemail'});
1.77 www 2795: $r->print(&mt('Generating user').': '.$result);
1.219 raeburn 2796: $uhome = &Apache::lonnet::homeserver($env{'form.ccuname'},
1.101 albertel 2797: $env{'form.ccdomain'});
1.334 raeburn 2798: my (%changeHash,%newcustom,%changed,%changedinfo);
1.267 raeburn 2799: if ($uhome ne 'no_host') {
1.334 raeburn 2800: if ($context eq 'domain') {
1.378 raeburn 2801: foreach my $name ('portfolio','author') {
2802: if ($env{'form.custom_'.$name.'quota'} == 1) {
2803: if ($env{'form.'.$name.'quota'} eq '') {
2804: $newcustom{$name.'quota'} = 0;
2805: } else {
2806: $newcustom{$name.'quota'} = $env{'form.'.$name.'quota'};
2807: $newcustom{$name.'quota'} =~ s/[^\d\.]//g;
2808: }
2809: if ("a_admin($newcustom{$name.'quota'},\%changeHash,$name)) {
2810: $changed{$name.'quota'} = 1;
2811: }
1.334 raeburn 2812: }
2813: }
2814: foreach my $item (@usertools) {
2815: if ($env{'form.custom'.$item} == 1) {
2816: $newcustom{$item} = $env{'form.tools_'.$item};
2817: $changed{$item} = &tool_admin($item,$newcustom{$item},
2818: \%changeHash,'tools');
2819: }
1.267 raeburn 2820: }
1.334 raeburn 2821: foreach my $item (@requestcourses) {
1.341 raeburn 2822: if ($env{'form.custom'.$item} == 1) {
2823: $newcustom{$item} = $env{'form.crsreq_'.$item};
2824: if ($env{'form.crsreq_'.$item} eq 'autolimit') {
2825: $newcustom{$item} .= '=';
1.383 raeburn 2826: $env{'form.crsreq_'.$item.'_limit'} =~ s/\D+//g;
2827: if ($env{'form.crsreq_'.$item.'_limit'}) {
1.341 raeburn 2828: $newcustom{$item} .= $env{'form.crsreq_'.$item.'_limit'};
2829: }
1.334 raeburn 2830: }
1.341 raeburn 2831: $changed{$item} = &tool_admin($item,$newcustom{$item},
2832: \%changeHash,'requestcourses');
1.334 raeburn 2833: }
1.275 raeburn 2834: }
1.362 raeburn 2835: if ($env{'form.customrequestauthor'} == 1) {
2836: $newcustom{'requestauthor'} = $env{'form.requestauthor'};
2837: $changed{'requestauthor'} = &tool_admin('requestauthor',
2838: $newcustom{'requestauthor'},
2839: \%changeHash,'requestauthor');
2840: }
1.275 raeburn 2841: }
1.334 raeburn 2842: if ($canmodify_status{'inststatus'}) {
2843: if (exists($env{'form.inststatus'})) {
2844: my @inststatuses = &Apache::loncommon::get_env_multiple('form.inststatus');
2845: if (@inststatuses > 0) {
2846: $changeHash{'inststatus'} = join(',',@inststatuses);
2847: $changed{'inststatus'} = $changeHash{'inststatus'};
1.306 raeburn 2848: }
2849: }
1.232 raeburn 2850: }
1.334 raeburn 2851: if (keys(%changed)) {
2852: foreach my $item (@userinfo) {
2853: $changeHash{$item} = $env{'form.c'.$item};
1.286 raeburn 2854: }
1.267 raeburn 2855: my $chgresult =
2856: &Apache::lonnet::put('environment',\%changeHash,
2857: $env{'form.ccdomain'},$env{'form.ccuname'});
2858: }
1.232 raeburn 2859: }
1.219 raeburn 2860: $r->print('<br />'.&mt('Home server').': '.$uhome.' '.
2861: &Apache::lonnet::hostname($uhome));
1.101 albertel 2862: } elsif (($env{'form.login'} ne 'nochange') &&
2863: ($env{'form.login'} ne '' )) {
1.27 matthew 2864: # Modify user privileges
2865: if (! $amode || ! $genpwd) {
1.193 raeburn 2866: $r->print($error.'Invalid login mode or password'.$end.$rtnlink);
1.27 matthew 2867: return;
1.20 harris41 2868: }
1.395 bisitz 2869: # Only allow authentication modification if the person has authority
1.101 albertel 2870: if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'})) {
1.20 harris41 2871: $r->print('Modifying authentication: '.
1.31 matthew 2872: &Apache::lonnet::modifyuserauth(
1.101 albertel 2873: $env{'form.ccdomain'},$env{'form.ccuname'},
1.21 harris41 2874: $amode,$genpwd));
1.102 albertel 2875: $r->print('<br />'.&mt('Home server').': '.&Apache::lonnet::homeserver
1.101 albertel 2876: ($env{'form.ccuname'},$env{'form.ccdomain'}));
1.4 www 2877: } else {
1.27 matthew 2878: # Okay, this is a non-fatal error.
1.395 bisitz 2879: $r->print($error.&mt('You do not have the authority to modify this users authentication information.').$end);
1.27 matthew 2880: }
1.28 matthew 2881: }
1.344 bisitz 2882: $r->rflush(); # Finish display of header before time consuming actions start
1.367 golterma 2883: &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state);
1.28 matthew 2884: ##
1.375 raeburn 2885: my (@userroles,%userupdate,$cnum,$cdom,$defaultcredits,%namechanged);
1.213 raeburn 2886: if ($context eq 'course') {
1.375 raeburn 2887: ($cnum,$cdom) =
2888: &Apache::lonuserutils::get_course_identity();
1.318 raeburn 2889: $crstype = &Apache::loncommon::course_type($cdom.'_'.$cnum);
1.375 raeburn 2890: if ($showcredits) {
2891: $defaultcredits = &Apache::lonuserutils::get_defaultcredits($cdom,$cnum);
2892: }
1.213 raeburn 2893: }
1.101 albertel 2894: if (! $env{'form.makeuser'} ) {
1.28 matthew 2895: # Check for need to change
2896: my %userenv = &Apache::lonnet::get
1.134 raeburn 2897: ('environment',['firstname','middlename','lastname','generation',
1.378 raeburn 2898: 'id','permanentemail','portfolioquota','authorquota','inststatus',
2899: 'tools.aboutme','tools.blog','tools.webdav','tools.portfolio',
1.361 raeburn 2900: 'requestcourses.official','requestcourses.unofficial',
1.384 raeburn 2901: 'requestcourses.community','requestcourses.textbook',
2902: 'reqcrsotherdom.official','reqcrsotherdom.unofficial',
2903: 'reqcrsotherdom.community','reqcrsotherdom.textbook',
1.406.2.9 raeburn 2904: 'requestauthor'],
1.160 raeburn 2905: $env{'form.ccdomain'},$env{'form.ccuname'});
1.28 matthew 2906: my ($tmp) = keys(%userenv);
2907: if ($tmp =~ /^(con_lost|error)/i) {
2908: %userenv = ();
2909: }
1.206 raeburn 2910: my $no_forceid_alert;
2911: # Check to see if user information can be changed
2912: my %domconfig =
2913: &Apache::lonnet::get_dom('configuration',['usermodification'],
2914: $env{'form.ccdomain'});
1.213 raeburn 2915: my @statuses = ('active','future');
2916: my %roles = &Apache::lonnet::get_my_roles($env{'form.ccuname'},$env{'form.ccdomain'},'userroles',\@statuses,undef,$env{'request.role.domain'});
2917: my ($auname,$audom);
1.220 raeburn 2918: if ($context eq 'author') {
1.206 raeburn 2919: $auname = $env{'user.name'};
2920: $audom = $env{'user.domain'};
2921: }
2922: foreach my $item (keys(%roles)) {
1.220 raeburn 2923: my ($rolenum,$roledom,$role) = split(/:/,$item,-1);
1.206 raeburn 2924: if ($context eq 'course') {
2925: if ($cnum ne '' && $cdom ne '') {
2926: if ($rolenum eq $cnum && $roledom eq $cdom) {
2927: if (!grep(/^\Q$role\E$/,@userroles)) {
2928: push(@userroles,$role);
2929: }
2930: }
2931: }
2932: } elsif ($context eq 'author') {
2933: if ($rolenum eq $auname && $roledom eq $audom) {
2934: if (!grep(/^\Q$role\E$/,@userroles)) {
2935: push(@userroles,$role);
2936: }
2937: }
2938: }
2939: }
1.220 raeburn 2940: if ($env{'form.action'} eq 'singlestudent') {
2941: if (!grep(/^st$/,@userroles)) {
2942: push(@userroles,'st');
2943: }
2944: } else {
2945: # Check for course or co-author roles being activated or re-enabled
2946: if ($context eq 'author' || $context eq 'course') {
2947: foreach my $key (keys(%env)) {
2948: if ($context eq 'author') {
2949: if ($key=~/^form\.act_\Q$audom\E_\Q$auname\E_([^_]+)/) {
2950: if (!grep(/^\Q$1\E$/,@userroles)) {
2951: push(@userroles,$1);
2952: }
2953: } elsif ($key =~/^form\.ren\:\Q$audom\E\/\Q$auname\E_([^_]+)/) {
2954: if (!grep(/^\Q$1\E$/,@userroles)) {
2955: push(@userroles,$1);
2956: }
1.206 raeburn 2957: }
1.220 raeburn 2958: } elsif ($context eq 'course') {
2959: if ($key=~/^form\.act_\Q$cdom\E_\Q$cnum\E_([^_]+)/) {
2960: if (!grep(/^\Q$1\E$/,@userroles)) {
2961: push(@userroles,$1);
2962: }
2963: } elsif ($key =~/^form\.ren\:\Q$cdom\E\/\Q$cnum\E(\/?\w*)_([^_]+)/) {
2964: if (!grep(/^\Q$1\E$/,@userroles)) {
2965: push(@userroles,$1);
2966: }
1.206 raeburn 2967: }
2968: }
2969: }
2970: }
2971: }
2972: #Check to see if we can change personal data for the user
2973: my (@mod_disallowed,@longroles);
2974: foreach my $role (@userroles) {
2975: if ($role eq 'cr') {
2976: push(@longroles,'Custom');
2977: } else {
1.318 raeburn 2978: push(@longroles,&Apache::lonnet::plaintext($role,$crstype));
1.206 raeburn 2979: }
2980: }
1.219 raeburn 2981: my %canmodify = &Apache::lonuserutils::can_modify_userinfo($context,$env{'form.ccdomain'},\@userinfo,\@userroles);
2982: foreach my $item (@userinfo) {
1.28 matthew 2983: # Strip leading and trailing whitespace
1.203 raeburn 2984: $env{'form.c'.$item} =~ s/(\s+$|^\s+)//g;
1.219 raeburn 2985: if (!$canmodify{$item}) {
1.207 raeburn 2986: if (defined($env{'form.c'.$item})) {
2987: if ($env{'form.c'.$item} ne $userenv{$item}) {
2988: push(@mod_disallowed,$item);
2989: }
1.206 raeburn 2990: }
2991: $env{'form.c'.$item} = $userenv{$item};
2992: }
1.28 matthew 2993: }
1.259 bisitz 2994: # Check to see if we can change the Student/Employee ID
1.196 raeburn 2995: my $forceid = $env{'form.forceid'};
2996: my $recurseid = $env{'form.recurseid'};
2997: my (%alerts,%rulematch,%idinst_results,%curr_rules,%got_rules);
1.203 raeburn 2998: my %uidhash = &Apache::lonnet::idrget($env{'form.ccdomain'},
2999: $env{'form.ccuname'});
3000: if (($uidhash{$env{'form.ccuname'}}) &&
3001: ($uidhash{$env{'form.ccuname'}}!~/error\:/) &&
3002: (!$forceid)) {
3003: if ($env{'form.cid'} ne $uidhash{$env{'form.ccuname'}}) {
3004: $env{'form.cid'} = $userenv{'id'};
1.293 bisitz 3005: $no_forceid_alert = &mt('New student/employee ID does not match existing ID for this user.')
1.259 bisitz 3006: .'<br />'
3007: .&mt("Change is not permitted without checking the 'Force ID change' checkbox on the previous page.")
3008: .'<br />'."\n";
1.203 raeburn 3009: }
3010: }
3011: if ($env{'form.cid'} ne $userenv{'id'}) {
1.196 raeburn 3012: my $checkhash;
3013: my $checks = { 'id' => 1 };
3014: $checkhash->{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}} =
3015: { 'newuser' => $newuser,
3016: 'id' => $env{'form.cid'},
3017: };
3018: &Apache::loncommon::user_rule_check($checkhash,$checks,
3019: \%alerts,\%rulematch,\%idinst_results,\%curr_rules,\%got_rules);
3020: if (ref($alerts{'id'}) eq 'HASH') {
3021: if (ref($alerts{'id'}{$env{'form.ccdomain'}}) eq 'HASH') {
1.203 raeburn 3022: $env{'form.cid'} = $userenv{'id'};
1.196 raeburn 3023: }
3024: }
3025: }
1.378 raeburn 3026: my (%quotachanged,%oldquota,%newquota,%olddefquota,%newdefquota,
3027: $oldinststatus,$newinststatus,%oldisdefault,%newisdefault,%oldsettings,
1.339 raeburn 3028: %oldsettingstext,%newsettings,%newsettingstext,@disporder,
1.378 raeburn 3029: %oldsettingstatus,%newsettingstatus);
1.334 raeburn 3030: @disporder = ('inststatus');
3031: if ($env{'request.role.domain'} eq $env{'form.ccdomain'}) {
1.362 raeburn 3032: push(@disporder,'requestcourses','requestauthor');
1.334 raeburn 3033: } else {
3034: push(@disporder,'reqcrsotherdom');
3035: }
3036: push(@disporder,('quota','tools'));
1.338 raeburn 3037: $oldinststatus = $userenv{'inststatus'};
1.378 raeburn 3038: foreach my $name ('portfolio','author') {
3039: ($olddefquota{$name},$oldsettingstatus{$name}) =
3040: &Apache::loncommon::default_quota($env{'form.ccdomain'},$oldinststatus,$name);
3041: ($newdefquota{$name},$newsettingstatus{$name}) = ($olddefquota{$name},$oldsettingstatus{$name});
3042: }
1.334 raeburn 3043: my %canshow;
1.220 raeburn 3044: if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
1.334 raeburn 3045: $canshow{'quota'} = 1;
1.220 raeburn 3046: }
1.267 raeburn 3047: if (&Apache::lonnet::allowed('mut',$env{'form.ccdomain'})) {
1.334 raeburn 3048: $canshow{'tools'} = 1;
1.267 raeburn 3049: }
1.275 raeburn 3050: if (&Apache::lonnet::allowed('ccc',$env{'form.ccdomain'})) {
1.334 raeburn 3051: $canshow{'requestcourses'} = 1;
1.300 raeburn 3052: } elsif (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
1.334 raeburn 3053: $canshow{'reqcrsotherdom'} = 1;
1.275 raeburn 3054: }
1.286 raeburn 3055: if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'})) {
1.334 raeburn 3056: $canshow{'inststatus'} = 1;
1.286 raeburn 3057: }
1.362 raeburn 3058: if (&Apache::lonnet::allowed('cau',$env{'form.ccdomain'})) {
3059: $canshow{'requestauthor'} = 1;
3060: }
1.267 raeburn 3061: my (%changeHash,%changed);
1.286 raeburn 3062: if ($oldinststatus eq '') {
1.334 raeburn 3063: $oldsettings{'inststatus'} = $othertitle;
1.286 raeburn 3064: } else {
3065: if (ref($usertypes) eq 'HASH') {
1.334 raeburn 3066: $oldsettings{'inststatus'} = join(', ',map{ $usertypes->{ &unescape($_) }; } (split(/:/,$userenv{'inststatus'})));
1.286 raeburn 3067: } else {
1.334 raeburn 3068: $oldsettings{'inststatus'} = join(', ',map{ &unescape($_); } (split(/:/,$userenv{'inststatus'})));
1.286 raeburn 3069: }
3070: }
3071: $changeHash{'inststatus'} = $userenv{'inststatus'};
1.334 raeburn 3072: if ($canmodify_status{'inststatus'}) {
3073: $canshow{'inststatus'} = 1;
1.286 raeburn 3074: if (exists($env{'form.inststatus'})) {
3075: my @inststatuses = &Apache::loncommon::get_env_multiple('form.inststatus');
3076: if (@inststatuses > 0) {
3077: $newinststatus = join(':',map { &escape($_); } @inststatuses);
3078: $changeHash{'inststatus'} = $newinststatus;
3079: if ($newinststatus ne $oldinststatus) {
3080: $changed{'inststatus'} = $newinststatus;
1.378 raeburn 3081: foreach my $name ('portfolio','author') {
3082: ($newdefquota{$name},$newsettingstatus{$name}) =
3083: &Apache::loncommon::default_quota($env{'form.ccdomain'},$newinststatus,$name);
3084: }
1.286 raeburn 3085: }
3086: if (ref($usertypes) eq 'HASH') {
1.334 raeburn 3087: $newsettings{'inststatus'} = join(', ',map{ $usertypes->{$_}; } (@inststatuses));
1.286 raeburn 3088: } else {
1.337 raeburn 3089: $newsettings{'inststatus'} = join(', ',@inststatuses);
1.286 raeburn 3090: }
1.334 raeburn 3091: }
3092: } else {
3093: $newinststatus = '';
3094: $changeHash{'inststatus'} = $newinststatus;
3095: $newsettings{'inststatus'} = $othertitle;
3096: if ($newinststatus ne $oldinststatus) {
3097: $changed{'inststatus'} = $changeHash{'inststatus'};
1.378 raeburn 3098: foreach my $name ('portfolio','author') {
3099: ($newdefquota{$name},$newsettingstatus{$name}) =
3100: &Apache::loncommon::default_quota($env{'form.ccdomain'},$newinststatus,$name);
3101: }
1.286 raeburn 3102: }
3103: }
1.334 raeburn 3104: } elsif ($context ne 'selfcreate') {
3105: $canshow{'inststatus'} = 1;
1.337 raeburn 3106: $newsettings{'inststatus'} = $oldsettings{'inststatus'};
1.286 raeburn 3107: }
1.378 raeburn 3108: foreach my $name ('portfolio','author') {
3109: $changeHash{$name.'quota'} = $userenv{$name.'quota'};
3110: }
1.334 raeburn 3111: if ($context eq 'domain') {
1.378 raeburn 3112: foreach my $name ('portfolio','author') {
3113: if ($userenv{$name.'quota'} ne '') {
3114: $oldquota{$name} = $userenv{$name.'quota'};
3115: if ($env{'form.custom_'.$name.'quota'} == 1) {
3116: if ($env{'form.'.$name.'quota'} eq '') {
3117: $newquota{$name} = 0;
3118: } else {
3119: $newquota{$name} = $env{'form.'.$name.'quota'};
3120: $newquota{$name} =~ s/[^\d\.]//g;
3121: }
3122: if ($newquota{$name} != $oldquota{$name}) {
3123: if ("a_admin($newquota{$name},\%changeHash,$name)) {
3124: $changed{$name.'quota'} = 1;
3125: }
3126: }
1.334 raeburn 3127: } else {
1.378 raeburn 3128: if ("a_admin('',\%changeHash,$name)) {
3129: $changed{$name.'quota'} = 1;
3130: $newquota{$name} = $newdefquota{$name};
3131: $newisdefault{$name} = 1;
3132: }
1.334 raeburn 3133: }
1.149 raeburn 3134: } else {
1.378 raeburn 3135: $oldisdefault{$name} = 1;
3136: $oldquota{$name} = $olddefquota{$name};
3137: if ($env{'form.custom_'.$name.'quota'} == 1) {
3138: if ($env{'form.'.$name.'quota'} eq '') {
3139: $newquota{$name} = 0;
3140: } else {
3141: $newquota{$name} = $env{'form.'.$name.'quota'};
3142: $newquota{$name} =~ s/[^\d\.]//g;
3143: }
3144: if ("a_admin($newquota{$name},\%changeHash,$name)) {
3145: $changed{$name.'quota'} = 1;
3146: }
1.334 raeburn 3147: } else {
1.378 raeburn 3148: $newquota{$name} = $newdefquota{$name};
3149: $newisdefault{$name} = 1;
1.334 raeburn 3150: }
1.378 raeburn 3151: }
3152: if ($oldisdefault{$name}) {
3153: $oldsettingstext{'quota'}{$name} = &get_defaultquota_text($oldsettingstatus{$name});
1.383 raeburn 3154: } else {
3155: $oldsettingstext{'quota'}{$name} = &mt('custom quota: [_1] MB',$oldquota{$name});
1.378 raeburn 3156: }
3157: if ($newisdefault{$name}) {
3158: $newsettingstext{'quota'}{$name} = &get_defaultquota_text($newsettingstatus{$name});
1.383 raeburn 3159: } else {
3160: $newsettingstext{'quota'}{$name} = &mt('custom quota: [_1] MB',$newquota{$name});
1.134 raeburn 3161: }
3162: }
1.334 raeburn 3163: &tool_changes('tools',\@usertools,\%oldsettings,\%oldsettingstext,\%userenv,
3164: \%changeHash,\%changed,\%newsettings,\%newsettingstext);
3165: if ($env{'form.ccdomain'} eq $env{'request.role.domain'}) {
3166: &tool_changes('requestcourses',\@requestcourses,\%oldsettings,\%oldsettingstext,
3167: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
1.384 raeburn 3168: &tool_changes('requestauthor',\@requestauthor,\%oldsettings,\%oldsettingstext,
3169: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
1.149 raeburn 3170: } else {
1.334 raeburn 3171: &tool_changes('reqcrsotherdom',\@requestcourses,\%oldsettings,\%oldsettingstext,
3172: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
1.149 raeburn 3173: }
3174: }
1.334 raeburn 3175: foreach my $item (@userinfo) {
3176: if ($env{'form.c'.$item} ne $userenv{$item}) {
3177: $namechanged{$item} = 1;
3178: }
1.204 raeburn 3179: }
1.378 raeburn 3180: foreach my $name ('portfolio','author') {
1.390 bisitz 3181: $oldsettings{'quota'}{$name} = &mt('[_1] MB',$oldquota{$name});
3182: $newsettings{'quota'}{$name} = &mt('[_1] MB',$newquota{$name});
1.378 raeburn 3183: }
1.334 raeburn 3184: if ((keys(%namechanged) > 0) || (keys(%changed) > 0)) {
1.267 raeburn 3185: my ($chgresult,$namechgresult);
3186: if (keys(%changed) > 0) {
3187: $chgresult =
1.204 raeburn 3188: &Apache::lonnet::put('environment',\%changeHash,
3189: $env{'form.ccdomain'},$env{'form.ccuname'});
1.267 raeburn 3190: if ($chgresult eq 'ok') {
3191: if (($env{'user.name'} eq $env{'form.ccuname'}) &&
3192: ($env{'user.domain'} eq $env{'form.ccdomain'})) {
1.270 raeburn 3193: my %newenvhash;
3194: foreach my $key (keys(%changed)) {
1.299 raeburn 3195: if (($key eq 'official') || ($key eq 'unofficial')
1.403 raeburn 3196: || ($key eq 'community') || ($key eq 'textbook')) {
1.279 raeburn 3197: $newenvhash{'environment.requestcourses.'.$key} =
3198: $changeHash{'requestcourses.'.$key};
1.362 raeburn 3199: if ($changeHash{'requestcourses.'.$key}) {
1.332 raeburn 3200: $newenvhash{'environment.canrequest.'.$key} = 1;
1.279 raeburn 3201: } else {
3202: $newenvhash{'environment.canrequest.'.$key} =
3203: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
3204: $key,'reload','requestcourses');
3205: }
1.362 raeburn 3206: } elsif ($key eq 'requestauthor') {
3207: $newenvhash{'environment.'.$key} = $changeHash{$key};
3208: if ($changeHash{$key}) {
3209: $newenvhash{'environment.canrequest.author'} = 1;
3210: } else {
3211: $newenvhash{'environment.canrequest.author'} =
3212: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
3213: $key,'reload','requestauthor');
3214: }
1.275 raeburn 3215: } elsif ($key ne 'quota') {
1.270 raeburn 3216: $newenvhash{'environment.tools.'.$key} =
3217: $changeHash{'tools.'.$key};
1.279 raeburn 3218: if ($changeHash{'tools.'.$key} ne '') {
3219: $newenvhash{'environment.availabletools.'.$key} =
3220: $changeHash{'tools.'.$key};
3221: } else {
3222: $newenvhash{'environment.availabletools.'.$key} =
1.367 golterma 3223: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
3224: $key,'reload','tools');
1.279 raeburn 3225: }
1.270 raeburn 3226: }
3227: }
1.271 raeburn 3228: if (keys(%newenvhash)) {
3229: &Apache::lonnet::appenv(\%newenvhash);
3230: }
1.267 raeburn 3231: }
3232: }
1.204 raeburn 3233: }
1.334 raeburn 3234: if (keys(%namechanged) > 0) {
1.337 raeburn 3235: foreach my $field (@userinfo) {
3236: $changeHash{$field} = $env{'form.c'.$field};
3237: }
3238: # Make the change
1.204 raeburn 3239: $namechgresult =
3240: &Apache::lonnet::modifyuser($env{'form.ccdomain'},
3241: $env{'form.ccuname'},$changeHash{'id'},undef,undef,
3242: $changeHash{'firstname'},$changeHash{'middlename'},
3243: $changeHash{'lastname'},$changeHash{'generation'},
1.337 raeburn 3244: $changeHash{'id'},undef,$changeHash{'permanentemail'},undef,\@userinfo);
1.220 raeburn 3245: %userupdate = (
3246: lastname => $env{'form.clastname'},
3247: middlename => $env{'form.cmiddlename'},
3248: firstname => $env{'form.cfirstname'},
3249: generation => $env{'form.cgeneration'},
3250: id => $env{'form.cid'},
3251: );
1.204 raeburn 3252: }
1.334 raeburn 3253: if (((keys(%namechanged) > 0) && $namechgresult eq 'ok') ||
1.267 raeburn 3254: ((keys(%changed) > 0) && $chgresult eq 'ok')) {
1.28 matthew 3255: # Tell the user we changed the name
1.334 raeburn 3256: &display_userinfo($r,1,\@disporder,\%canshow,\@requestcourses,
1.362 raeburn 3257: \@usertools,\@requestauthor,\%userenv,\%changed,\%namechanged,
1.334 raeburn 3258: \%oldsettings, \%oldsettingstext,\%newsettings,
3259: \%newsettingstext);
1.203 raeburn 3260: if ($env{'form.cid'} ne $userenv{'id'}) {
3261: &Apache::lonnet::idput($env{'form.ccdomain'},
1.406.2.5 raeburn 3262: {$env{'form.ccuname'} => $env{'form.cid'}});
1.203 raeburn 3263: if (($recurseid) &&
3264: (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'}))) {
3265: my $idresult =
3266: &Apache::lonuserutils::propagate_id_change(
3267: $env{'form.ccuname'},$env{'form.ccdomain'},
3268: \%userupdate);
3269: $r->print('<br />'.$idresult.'<br />');
3270: }
1.196 raeburn 3271: }
1.149 raeburn 3272: if (($env{'form.ccdomain'} eq $env{'user.domain'}) &&
3273: ($env{'form.ccuname'} eq $env{'user.name'})) {
3274: my %newenvhash;
3275: foreach my $key (keys(%changeHash)) {
3276: $newenvhash{'environment.'.$key} = $changeHash{$key};
3277: }
1.238 raeburn 3278: &Apache::lonnet::appenv(\%newenvhash);
1.149 raeburn 3279: }
1.28 matthew 3280: } else { # error occurred
1.389 bisitz 3281: $r->print(
3282: '<p class="LC_error">'
3283: .&mt('Unable to successfully change environment for [_1] in domain [_2].',
3284: '"'.$env{'form.ccuname'}.'"',
3285: '"'.$env{'form.ccdomain'}.'"')
3286: .'</p>');
1.28 matthew 3287: }
1.334 raeburn 3288: } else { # End of if ($env ... ) logic
1.275 raeburn 3289: # They did not want to change the users name, quota, tool availability,
3290: # or ability to request creation of courses,
1.267 raeburn 3291: # but we can still tell them what the name and quota and availabilities are
1.334 raeburn 3292: &display_userinfo($r,undef,\@disporder,\%canshow,\@requestcourses,
1.362 raeburn 3293: \@usertools,\@requestauthor,\%userenv,\%changed,\%namechanged,\%oldsettings,
1.334 raeburn 3294: \%oldsettingstext,\%newsettings,\%newsettingstext);
1.28 matthew 3295: }
1.206 raeburn 3296: if (@mod_disallowed) {
3297: my ($rolestr,$contextname);
3298: if (@longroles > 0) {
3299: $rolestr = join(', ',@longroles);
3300: } else {
3301: $rolestr = &mt('No roles');
3302: }
3303: if ($context eq 'course') {
1.399 bisitz 3304: $contextname = 'course';
1.206 raeburn 3305: } elsif ($context eq 'author') {
1.399 bisitz 3306: $contextname = 'co-author';
1.206 raeburn 3307: }
3308: $r->print(&mt('The following fields were not updated: ').'<ul>');
3309: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
3310: foreach my $field (@mod_disallowed) {
3311: $r->print('<li>'.$fieldtitles{$field}.'</li>'."\n");
3312: }
1.207 raeburn 3313: $r->print('</ul>');
3314: if (@mod_disallowed == 1) {
1.399 bisitz 3315: $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 3316: } else {
1.399 bisitz 3317: $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 3318: }
1.292 bisitz 3319: my $helplink = 'javascript:helpMenu('."'display'".')';
3320: $r->print('<span class="LC_cusr_emph">'.$rolestr.'</span><br />'
3321: .&mt('Please contact your [_1]helpdesk[_2] for more information.'
3322: ,'<a href="'.$helplink.'">','</a>')
3323: .'<br />');
1.206 raeburn 3324: }
1.259 bisitz 3325: $r->print('<span class="LC_warning">'
3326: .$no_forceid_alert
3327: .&Apache::lonuserutils::print_namespacing_alerts($env{'form.ccdomain'},\%alerts,\%curr_rules)
3328: .'</span>');
1.4 www 3329: }
1.367 golterma 3330: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
1.220 raeburn 3331: if ($env{'form.action'} eq 'singlestudent') {
1.375 raeburn 3332: &enroll_single_student($r,$uhome,$amode,$genpwd,$now,$newuser,$context,
3333: $crstype,$showcredits,$defaultcredits);
1.386 bisitz 3334: my $linktext = ($crstype eq 'Community' ?
3335: &mt('Enroll Another Member') : &mt('Enroll Another Student'));
3336: $r->print(
3337: &Apache::lonhtmlcommon::actionbox([
3338: '<a href="javascript:backPage(document.userupdate)">'
3339: .($crstype eq 'Community' ?
3340: &mt('Enroll Another Member') : &mt('Enroll Another Student'))
3341: .'</a>']));
1.220 raeburn 3342: } else {
1.375 raeburn 3343: my @rolechanges = &update_roles($r,$context,$showcredits);
1.334 raeburn 3344: if (keys(%namechanged) > 0) {
1.220 raeburn 3345: if ($context eq 'course') {
3346: if (@userroles > 0) {
1.225 raeburn 3347: if ((@rolechanges == 0) ||
3348: (!(grep(/^st$/,@rolechanges)))) {
3349: if (grep(/^st$/,@userroles)) {
3350: my $classlistupdated =
3351: &Apache::lonuserutils::update_classlist($cdom,
1.220 raeburn 3352: $cnum,$env{'form.ccdomain'},
3353: $env{'form.ccuname'},\%userupdate);
1.225 raeburn 3354: }
1.220 raeburn 3355: }
3356: }
3357: }
3358: }
1.226 raeburn 3359: my $userinfo = &Apache::loncommon::plainname($env{'form.ccuname'},
1.233 raeburn 3360: $env{'form.ccdomain'});
3361: if ($env{'form.popup'}) {
3362: $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a></p>');
3363: } else {
1.367 golterma 3364: $r->print('<br />'.&Apache::lonhtmlcommon::actionbox(['<a href="javascript:backPage(document.userupdate,'."'$env{'form.prevphase'}','modify'".')">'
3365: .&mt('Modify this user: [_1]','<span class="LC_cusr_emph">'.$env{'form.ccuname'}.':'.$env{'form.ccdomain'}.' ('.$userinfo.')</span>').'</a>',
3366: '<a href="javascript:backPage(document.userupdate)">'.&mt('Create/Modify Another User').'</a>']));
1.233 raeburn 3367: }
1.220 raeburn 3368: }
3369: }
3370:
1.334 raeburn 3371: sub display_userinfo {
1.362 raeburn 3372: my ($r,$changed,$order,$canshow,$requestcourses,$usertools,$requestauthor,
3373: $userenv,$changedhash,$namechangedhash,$oldsetting,$oldsettingtext,
1.334 raeburn 3374: $newsetting,$newsettingtext) = @_;
3375: return unless (ref($order) eq 'ARRAY' &&
3376: ref($canshow) eq 'HASH' &&
3377: ref($requestcourses) eq 'ARRAY' &&
1.362 raeburn 3378: ref($requestauthor) eq 'ARRAY' &&
1.334 raeburn 3379: ref($usertools) eq 'ARRAY' &&
3380: ref($userenv) eq 'HASH' &&
3381: ref($changedhash) eq 'HASH' &&
3382: ref($oldsetting) eq 'HASH' &&
3383: ref($oldsettingtext) eq 'HASH' &&
3384: ref($newsetting) eq 'HASH' &&
3385: ref($newsettingtext) eq 'HASH');
3386: my %lt=&Apache::lonlocal::texthash(
1.372 raeburn 3387: 'ui' => 'User Information',
1.334 raeburn 3388: 'uic' => 'User Information Changed',
3389: 'firstname' => 'First Name',
3390: 'middlename' => 'Middle Name',
3391: 'lastname' => 'Last Name',
3392: 'generation' => 'Generation',
3393: 'id' => 'Student/Employee ID',
3394: 'permanentemail' => 'Permanent e-mail address',
1.378 raeburn 3395: 'portfolioquota' => 'Disk space allocated to portfolio files',
1.385 bisitz 3396: 'authorquota' => 'Disk space allocated to Authoring Space',
1.334 raeburn 3397: 'blog' => 'Blog Availability',
1.361 raeburn 3398: 'webdav' => 'WebDAV Availability',
1.334 raeburn 3399: 'aboutme' => 'Personal Information Page Availability',
3400: 'portfolio' => 'Portfolio Availability',
3401: 'official' => 'Can Request Official Courses',
3402: 'unofficial' => 'Can Request Unofficial Courses',
3403: 'community' => 'Can Request Communities',
1.384 raeburn 3404: 'textbook' => 'Can Request Textbook Courses',
1.362 raeburn 3405: 'requestauthor' => 'Can Request Author Role',
1.334 raeburn 3406: 'inststatus' => "Affiliation",
3407: 'prvs' => 'Previous Value:',
3408: 'chto' => 'Changed To:'
3409: );
3410: if ($changed) {
1.372 raeburn 3411: $r->print('<h3>'.$lt{'uic'}.'</h3>'.
1.367 golterma 3412: &Apache::loncommon::start_data_table().
3413: &Apache::loncommon::start_data_table_header_row());
1.334 raeburn 3414: $r->print("<th> </th>\n");
1.367 golterma 3415: $r->print('<th><b>'.$lt{'prvs'}.'</b></th>');
3416: $r->print('<th><span class="LC_nobreak"><b>'.$lt{'chto'}.'</b></span></th>');
3417: $r->print(&Apache::loncommon::end_data_table_header_row());
3418: my @userinfo = ('firstname','middlename','lastname','generation','permanentemail','id');
3419:
1.334 raeburn 3420: foreach my $item (@userinfo) {
3421: my $value = $env{'form.c'.$item};
1.367 golterma 3422: #show changes only:
1.383 raeburn 3423: unless ($value eq $userenv->{$item}){
1.367 golterma 3424: $r->print(&Apache::loncommon::start_data_table_row());
3425: $r->print("<td>$lt{$item}</td>\n");
1.383 raeburn 3426: $r->print("<td>".$userenv->{$item}."</td>\n");
1.367 golterma 3427: $r->print("<td>$value </td>\n");
3428: $r->print(&Apache::loncommon::end_data_table_row());
1.334 raeburn 3429: }
3430: }
3431: foreach my $entry (@{$order}) {
1.383 raeburn 3432: if ($canshow->{$entry}) {
3433: if (($entry eq 'requestcourses') || ($entry eq 'reqcrsotherdom') || ($entry eq 'requestauthor')) {
3434: my @items;
3435: if ($entry eq 'requestauthor') {
3436: @items = ($entry);
3437: } else {
3438: @items = @{$requestcourses};
1.384 raeburn 3439: }
1.383 raeburn 3440: foreach my $item (@items) {
3441: if (($newsetting->{$item} ne $oldsetting->{$item}) ||
3442: ($newsettingtext->{$item} ne $oldsettingtext->{$item})) {
3443: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3444: $r->print("<td>$lt{$item}</td>\n");
3445: $r->print("<td>".$oldsetting->{$item});
3446: if ($oldsettingtext->{$item}) {
3447: if ($oldsetting->{$item}) {
3448: $r->print(' -- ');
3449: }
3450: $r->print($oldsettingtext->{$item});
3451: }
3452: $r->print("</td>\n");
3453: $r->print("<td>".$newsetting->{$item});
3454: if ($newsettingtext->{$item}) {
3455: if ($newsetting->{$item}) {
3456: $r->print(' -- ');
3457: }
3458: $r->print($newsettingtext->{$item});
3459: }
3460: $r->print("</td>\n");
3461: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.334 raeburn 3462: }
3463: }
3464: } elsif ($entry eq 'tools') {
3465: foreach my $item (@{$usertools}) {
1.383 raeburn 3466: if ($newsetting->{$item} ne $oldsetting->{$item}) {
3467: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3468: $r->print("<td>$lt{$item}</td>\n");
3469: $r->print("<td>".$oldsetting->{$item}.' '.$oldsettingtext->{$item}."</td>\n");
3470: $r->print("<td>".$newsetting->{$item}.' '.$newsettingtext->{$item}."</td>\n");
3471: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.334 raeburn 3472: }
3473: }
1.378 raeburn 3474: } elsif ($entry eq 'quota') {
3475: if ((ref($oldsetting->{$entry}) eq 'HASH') && (ref($oldsettingtext->{$entry}) eq 'HASH') &&
3476: (ref($newsetting->{$entry}) eq 'HASH') && (ref($newsettingtext->{$entry}) eq 'HASH')) {
3477: foreach my $name ('portfolio','author') {
1.383 raeburn 3478: if ($newsetting->{$entry}->{$name} ne $oldsetting->{$entry}->{$name}) {
3479: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3480: $r->print("<td>$lt{$name.$entry}</td>\n");
3481: $r->print("<td>".$oldsettingtext->{$entry}->{$name}."</td>\n");
3482: $r->print("<td>".$newsettingtext->{$entry}->{$name}."</td>\n");
3483: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.378 raeburn 3484: }
3485: }
3486: }
1.334 raeburn 3487: } else {
1.383 raeburn 3488: if ($newsetting->{$entry} ne $oldsetting->{$entry}) {
3489: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3490: $r->print("<td>$lt{$entry}</td>\n");
3491: $r->print("<td>".$oldsetting->{$entry}.' '.$oldsettingtext->{$entry}."</td>\n");
3492: $r->print("<td>".$newsetting->{$entry}.' '.$newsettingtext->{$entry}."</td>\n");
3493: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.334 raeburn 3494: }
3495: }
3496: }
3497: }
1.367 golterma 3498: $r->print(&Apache::loncommon::end_data_table().'<br />');
1.372 raeburn 3499: } else {
3500: $r->print('<h3>'.$lt{'ui'}.'</h3>'.
3501: '<p>'.&mt('No changes made to user information').'</p>');
1.334 raeburn 3502: }
3503: return;
3504: }
3505:
1.275 raeburn 3506: sub tool_changes {
3507: my ($context,$usertools,$oldaccess,$oldaccesstext,$userenv,$changeHash,
3508: $changed,$newaccess,$newaccesstext) = @_;
3509: if (!((ref($usertools) eq 'ARRAY') && (ref($oldaccess) eq 'HASH') &&
3510: (ref($oldaccesstext) eq 'HASH') && (ref($userenv) eq 'HASH') &&
3511: (ref($changeHash) eq 'HASH') && (ref($changed) eq 'HASH') &&
3512: (ref($newaccess) eq 'HASH') && (ref($newaccesstext) eq 'HASH'))) {
3513: return;
3514: }
1.383 raeburn 3515: my %reqdisplay = &requestchange_display();
1.300 raeburn 3516: if ($context eq 'reqcrsotherdom') {
1.309 raeburn 3517: my @options = ('approval','validate','autolimit');
1.306 raeburn 3518: my $optregex = join('|',@options);
1.300 raeburn 3519: my $cdom = $env{'request.role.domain'};
3520: foreach my $tool (@{$usertools}) {
1.383 raeburn 3521: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
1.314 raeburn 3522: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
1.300 raeburn 3523: $changeHash->{$context.'.'.$tool} = $userenv->{$context.'.'.$tool};
1.383 raeburn 3524: my ($newop,$limit);
1.314 raeburn 3525: if ($env{'form.'.$context.'_'.$tool}) {
3526: $newop = $env{'form.'.$context.'_'.$tool};
3527: if ($newop eq 'autolimit') {
1.383 raeburn 3528: $limit = $env{'form.'.$context.'_'.$tool.'_limit'};
1.314 raeburn 3529: $limit =~ s/\D+//g;
3530: $newop .= '='.$limit;
3531: }
3532: }
1.300 raeburn 3533: if ($userenv->{$context.'.'.$tool} eq '') {
1.314 raeburn 3534: if ($newop) {
3535: $changed->{$tool}=&tool_admin($tool,$cdom.':'.$newop,
1.300 raeburn 3536: $changeHash,$context);
3537: if ($changed->{$tool}) {
1.383 raeburn 3538: if ($newop =~ /^autolimit/) {
3539: if ($limit) {
3540: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3541: } else {
3542: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3543: }
3544: } else {
3545: $newaccesstext->{$tool} = $reqdisplay{$newop};
3546: }
1.300 raeburn 3547: } else {
3548: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
3549: }
3550: }
3551: } else {
3552: my @curr = split(',',$userenv->{$context.'.'.$tool});
3553: my @new;
3554: my $changedoms;
1.314 raeburn 3555: foreach my $req (@curr) {
3556: if ($req =~ /^\Q$cdom\E\:($optregex\=?\d*)$/) {
3557: my $oldop = $1;
1.383 raeburn 3558: if ($oldop =~ /^autolimit=(\d*)/) {
3559: my $limit = $1;
3560: if ($limit) {
3561: $oldaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3562: } else {
3563: $oldaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3564: }
3565: } else {
3566: $oldaccesstext->{$tool} = $reqdisplay{$oldop};
3567: }
1.314 raeburn 3568: if ($oldop ne $newop) {
3569: $changedoms = 1;
3570: foreach my $item (@curr) {
3571: my ($reqdom,$option) = split(':',$item);
3572: unless ($reqdom eq $cdom) {
3573: push(@new,$item);
3574: }
3575: }
3576: if ($newop) {
3577: push(@new,$cdom.':'.$newop);
1.300 raeburn 3578: }
1.314 raeburn 3579: @new = sort(@new);
1.300 raeburn 3580: }
1.314 raeburn 3581: last;
1.300 raeburn 3582: }
1.314 raeburn 3583: }
3584: if ((!$changedoms) && ($newop)) {
1.300 raeburn 3585: $changedoms = 1;
1.306 raeburn 3586: @new = sort(@curr,$cdom.':'.$newop);
1.300 raeburn 3587: }
3588: if ($changedoms) {
1.314 raeburn 3589: my $newdomstr;
1.300 raeburn 3590: if (@new) {
3591: $newdomstr = join(',',@new);
3592: }
3593: $changed->{$tool}=&tool_admin($tool,$newdomstr,$changeHash,
3594: $context);
3595: if ($changed->{$tool}) {
3596: if ($env{'form.'.$context.'_'.$tool}) {
1.306 raeburn 3597: if ($env{'form.'.$context.'_'.$tool} eq 'autolimit') {
1.314 raeburn 3598: my $limit = $env{'form.'.$context.'_'.$tool.'_limit'};
3599: $limit =~ s/\D+//g;
3600: if ($limit) {
1.383 raeburn 3601: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
1.314 raeburn 3602: } else {
1.383 raeburn 3603: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
1.306 raeburn 3604: }
1.314 raeburn 3605: } else {
1.306 raeburn 3606: $newaccesstext->{$tool} = $reqdisplay{$env{'form.'.$context.'_'.$tool}};
3607: }
1.300 raeburn 3608: } else {
1.383 raeburn 3609: $newaccesstext->{$tool} = &mt("availability set to 'off'");
1.300 raeburn 3610: }
3611: }
3612: }
3613: }
3614: }
3615: return;
3616: }
1.275 raeburn 3617: foreach my $tool (@{$usertools}) {
1.383 raeburn 3618: my ($newval,$limit,$envkey);
1.362 raeburn 3619: $envkey = $context.'.'.$tool;
1.306 raeburn 3620: if ($context eq 'requestcourses') {
3621: $newval = $env{'form.crsreq_'.$tool};
3622: if ($newval eq 'autolimit') {
1.383 raeburn 3623: $limit = $env{'form.crsreq_'.$tool.'_limit'};
3624: $limit =~ s/\D+//g;
3625: $newval .= '='.$limit;
1.306 raeburn 3626: }
1.362 raeburn 3627: } elsif ($context eq 'requestauthor') {
3628: $newval = $env{'form.'.$context};
3629: $envkey = $context;
1.314 raeburn 3630: } else {
1.306 raeburn 3631: $newval = $env{'form.'.$context.'_'.$tool};
3632: }
1.362 raeburn 3633: if ($userenv->{$envkey} ne '') {
1.275 raeburn 3634: $oldaccess->{$tool} = &mt('custom');
1.383 raeburn 3635: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3636: if ($userenv->{$envkey} =~ /^autolimit=(\d*)$/) {
3637: my $currlimit = $1;
3638: if ($currlimit eq '') {
3639: $oldaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3640: } else {
3641: $oldaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$currlimit);
3642: }
3643: } elsif ($userenv->{$envkey}) {
3644: $oldaccesstext->{$tool} = $reqdisplay{$userenv->{$envkey}};
3645: } else {
3646: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
3647: }
1.275 raeburn 3648: } else {
1.383 raeburn 3649: if ($userenv->{$envkey}) {
3650: $oldaccesstext->{$tool} = &mt("availability set to 'on'");
3651: } else {
3652: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
3653: }
1.275 raeburn 3654: }
1.362 raeburn 3655: $changeHash->{$envkey} = $userenv->{$envkey};
1.275 raeburn 3656: if ($env{'form.custom'.$tool} == 1) {
1.362 raeburn 3657: if ($newval ne $userenv->{$envkey}) {
1.306 raeburn 3658: $changed->{$tool} = &tool_admin($tool,$newval,$changeHash,
3659: $context);
1.275 raeburn 3660: if ($changed->{$tool}) {
3661: $newaccess->{$tool} = &mt('custom');
1.383 raeburn 3662: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3663: if ($newval =~ /^autolimit/) {
3664: if ($limit) {
3665: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3666: } else {
3667: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3668: }
3669: } elsif ($newval) {
3670: $newaccesstext->{$tool} = $reqdisplay{$newval};
3671: } else {
3672: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3673: }
1.275 raeburn 3674: } else {
1.383 raeburn 3675: if ($newval) {
3676: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3677: } else {
3678: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3679: }
1.275 raeburn 3680: }
3681: } else {
3682: $newaccess->{$tool} = $oldaccess->{$tool};
1.383 raeburn 3683: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3684: if ($newval =~ /^autolimit/) {
3685: if ($limit) {
3686: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3687: } else {
3688: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3689: }
3690: } elsif ($newval) {
3691: $newaccesstext->{$tool} = $reqdisplay{$newval};
3692: } else {
3693: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3694: }
1.275 raeburn 3695: } else {
1.383 raeburn 3696: if ($userenv->{$context.'.'.$tool}) {
3697: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3698: } else {
3699: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3700: }
1.275 raeburn 3701: }
3702: }
3703: } else {
3704: $newaccess->{$tool} = $oldaccess->{$tool};
3705: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
3706: }
3707: } else {
3708: $changed->{$tool} = &tool_admin($tool,'',$changeHash,$context);
3709: if ($changed->{$tool}) {
3710: $newaccess->{$tool} = &mt('default');
3711: } else {
3712: $newaccess->{$tool} = $oldaccess->{$tool};
1.383 raeburn 3713: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3714: if ($newval =~ /^autolimit/) {
3715: if ($limit) {
3716: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3717: } else {
3718: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3719: }
3720: } elsif ($newval) {
3721: $newaccesstext->{$tool} = $reqdisplay{$newval};
3722: } else {
3723: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3724: }
1.275 raeburn 3725: } else {
1.383 raeburn 3726: if ($userenv->{$context.'.'.$tool}) {
3727: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3728: } else {
3729: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3730: }
1.275 raeburn 3731: }
3732: }
3733: }
3734: } else {
3735: $oldaccess->{$tool} = &mt('default');
3736: if ($env{'form.custom'.$tool} == 1) {
1.306 raeburn 3737: $changed->{$tool} = &tool_admin($tool,$newval,$changeHash,
3738: $context);
1.275 raeburn 3739: if ($changed->{$tool}) {
3740: $newaccess->{$tool} = &mt('custom');
1.383 raeburn 3741: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3742: if ($newval =~ /^autolimit/) {
3743: if ($limit) {
3744: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3745: } else {
3746: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3747: }
3748: } elsif ($newval) {
3749: $newaccesstext->{$tool} = $reqdisplay{$newval};
3750: } else {
3751: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3752: }
1.275 raeburn 3753: } else {
1.383 raeburn 3754: if ($newval) {
3755: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3756: } else {
3757: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3758: }
1.275 raeburn 3759: }
3760: } else {
3761: $newaccess->{$tool} = $oldaccess->{$tool};
3762: }
3763: } else {
3764: $newaccess->{$tool} = $oldaccess->{$tool};
3765: }
3766: }
3767: }
3768: return;
3769: }
3770:
1.220 raeburn 3771: sub update_roles {
1.375 raeburn 3772: my ($r,$context,$showcredits) = @_;
1.4 www 3773: my $now=time;
1.225 raeburn 3774: my @rolechanges;
1.220 raeburn 3775: my %disallowed;
1.73 sakharuk 3776: $r->print('<h3>'.&mt('Modifying Roles').'</h3>');
1.404 raeburn 3777: foreach my $key (keys(%env)) {
1.135 raeburn 3778: next if (! $env{$key});
1.190 raeburn 3779: next if ($key eq 'form.action');
1.27 matthew 3780: # Revoke roles
1.135 raeburn 3781: if ($key=~/^form\.rev/) {
3782: if ($key=~/^form\.rev\:([^\_]+)\_([^\_\.]+)$/) {
1.64 www 3783: # Revoke standard role
1.170 albertel 3784: my ($scope,$role) = ($1,$2);
3785: my $result =
3786: &Apache::lonnet::revokerole($env{'form.ccdomain'},
3787: $env{'form.ccuname'},
1.239 raeburn 3788: $scope,$role,'','',$context);
1.367 golterma 3789: $r->print(&Apache::lonhtmlcommon::confirm_success(
1.369 bisitz 3790: &mt('Revoking [_1] in [_2]',
3791: &Apache::lonnet::plaintext($role),
1.372 raeburn 3792: &Apache::loncommon::show_role_extent($scope,$context,$role)),
1.369 bisitz 3793: $result ne "ok").'<br />');
3794: if ($result ne "ok") {
3795: $r->print(&mt('Error: [_1]',$result).'<br />');
3796: }
1.170 albertel 3797: if ($role eq 'st') {
1.202 raeburn 3798: my $result =
1.198 raeburn 3799: &Apache::lonuserutils::classlist_drop($scope,
3800: $env{'form.ccuname'},$env{'form.ccdomain'},
1.202 raeburn 3801: $now);
1.367 golterma 3802: $r->print(&Apache::lonhtmlcommon::confirm_success($result));
1.53 www 3803: }
1.225 raeburn 3804: if (!grep(/^\Q$role\E$/,@rolechanges)) {
3805: push(@rolechanges,$role);
3806: }
1.196 raeburn 3807: }
1.195 raeburn 3808: if ($key=~m{^form\.rev\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}s) {
1.64 www 3809: # Revoke custom role
1.369 bisitz 3810: my $result = &Apache::lonnet::revokecustomrole(
3811: $env{'form.ccdomain'},$env{'form.ccuname'},$1,$2,$3,$4,'','',$context);
1.367 golterma 3812: $r->print(&Apache::lonhtmlcommon::confirm_success(
1.369 bisitz 3813: &mt('Revoking custom role [_1] by [_2] in [_3]',
1.372 raeburn 3814: $4,$3.':'.$2,&Apache::loncommon::show_role_extent($1,$context,'cr')),
1.369 bisitz 3815: $result ne 'ok').'<br />');
3816: if ($result ne "ok") {
3817: $r->print(&mt('Error: [_1]',$result).'<br />');
3818: }
1.225 raeburn 3819: if (!grep(/^cr$/,@rolechanges)) {
3820: push(@rolechanges,'cr');
3821: }
1.64 www 3822: }
1.135 raeburn 3823: } elsif ($key=~/^form\.del/) {
3824: if ($key=~/^form\.del\:([^\_]+)\_([^\_\.]+)$/) {
1.116 raeburn 3825: # Delete standard role
1.170 albertel 3826: my ($scope,$role) = ($1,$2);
3827: my $result =
3828: &Apache::lonnet::assignrole($env{'form.ccdomain'},
3829: $env{'form.ccuname'},
1.239 raeburn 3830: $scope,$role,$now,0,1,'',
3831: $context);
1.367 golterma 3832: $r->print(&Apache::lonhtmlcommon::confirm_success(
3833: &mt('Deleting [_1] in [_2]',
1.369 bisitz 3834: &Apache::lonnet::plaintext($role),
1.372 raeburn 3835: &Apache::loncommon::show_role_extent($scope,$context,$role)),
1.369 bisitz 3836: $result ne 'ok').'<br />');
3837: if ($result ne "ok") {
3838: $r->print(&mt('Error: [_1]',$result).'<br />');
3839: }
1.367 golterma 3840:
1.170 albertel 3841: if ($role eq 'st') {
1.202 raeburn 3842: my $result =
1.198 raeburn 3843: &Apache::lonuserutils::classlist_drop($scope,
3844: $env{'form.ccuname'},$env{'form.ccdomain'},
1.202 raeburn 3845: $now);
1.369 bisitz 3846: $r->print(&Apache::lonhtmlcommon::confirm_success($result));
1.81 albertel 3847: }
1.225 raeburn 3848: if (!grep(/^\Q$role\E$/,@rolechanges)) {
3849: push(@rolechanges,$role);
3850: }
1.116 raeburn 3851: }
1.139 albertel 3852: if ($key=~m{^form\.del\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
1.116 raeburn 3853: my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
3854: # Delete custom role
1.369 bisitz 3855: my $result =
3856: &Apache::lonnet::assigncustomrole($env{'form.ccdomain'},
3857: $env{'form.ccuname'},$url,$rdom,$rnam,$rolename,$now,
3858: 0,1,$context);
3859: $r->print(&Apache::lonhtmlcommon::confirm_success(&mt('Deleting custom role [_1] by [_2] in [_3]',
1.372 raeburn 3860: $rolename,$rnam.':'.$rdom,&Apache::loncommon::show_role_extent($1,$context,'cr')),
1.369 bisitz 3861: $result ne "ok").'<br />');
3862: if ($result ne "ok") {
3863: $r->print(&mt('Error: [_1]',$result).'<br />');
3864: }
1.367 golterma 3865:
1.225 raeburn 3866: if (!grep(/^cr$/,@rolechanges)) {
3867: push(@rolechanges,'cr');
3868: }
1.116 raeburn 3869: }
1.135 raeburn 3870: } elsif ($key=~/^form\.ren/) {
1.101 albertel 3871: my $udom = $env{'form.ccdomain'};
3872: my $uname = $env{'form.ccuname'};
1.116 raeburn 3873: # Re-enable standard role
1.135 raeburn 3874: if ($key=~/^form\.ren\:([^\_]+)\_([^\_\.]+)$/) {
1.89 raeburn 3875: my $url = $1;
3876: my $role = $2;
3877: my $logmsg;
3878: my $output;
3879: if ($role eq 'st') {
1.141 albertel 3880: if ($url =~ m-^/($match_domain)/($match_courseid)/?(\w*)$-) {
1.374 raeburn 3881: my ($cdom,$cnum,$csec) = ($1,$2,$3);
1.375 raeburn 3882: my $credits;
3883: if ($showcredits) {
3884: my $defaultcredits =
3885: &Apache::lonuserutils::get_defaultcredits($cdom,$cnum);
3886: $credits = &get_user_credits($defaultcredits,$cdom,$cnum);
3887: }
3888: my $result = &Apache::loncommon::commit_studentrole(\$logmsg,$udom,$uname,$url,$role,$now,0,$cdom,$cnum,$csec,$context,$credits);
1.220 raeburn 3889: if (($result =~ /^error/) || ($result eq 'not_in_class') || ($result eq 'unknown_course') || ($result eq 'refused')) {
1.223 raeburn 3890: if ($result eq 'refused' && $logmsg) {
3891: $output = $logmsg;
3892: } else {
1.369 bisitz 3893: $output = &mt('Error: [_1]',$result)."\n";
1.223 raeburn 3894: }
1.89 raeburn 3895: } else {
1.372 raeburn 3896: $output = &Apache::lonhtmlcommon::confirm_success(&mt('Assigning [_1] in [_2] starting [_3]',
3897: &Apache::lonnet::plaintext($role),
3898: &Apache::loncommon::show_role_extent($url,$context,'st'),
3899: &Apache::lonlocal::locallocaltime($now))).'<br />'.$logmsg.'<br />';
1.89 raeburn 3900: }
3901: }
3902: } else {
1.101 albertel 3903: my $result=&Apache::lonnet::assignrole($env{'form.ccdomain'},
1.239 raeburn 3904: $env{'form.ccuname'},$url,$role,0,$now,'','',
3905: $context);
1.367 golterma 3906: $output = &Apache::lonhtmlcommon::confirm_success(&mt('Re-enabling [_1] in [_2]',
1.372 raeburn 3907: &Apache::lonnet::plaintext($role),
3908: &Apache::loncommon::show_role_extent($url,$context,$role)),$result ne "ok").'<br />';
1.369 bisitz 3909: if ($result ne "ok") {
3910: $output .= &mt('Error: [_1]',$result).'<br />';
3911: }
3912: }
1.89 raeburn 3913: $r->print($output);
1.225 raeburn 3914: if (!grep(/^\Q$role\E$/,@rolechanges)) {
3915: push(@rolechanges,$role);
3916: }
1.113 raeburn 3917: }
1.116 raeburn 3918: # Re-enable custom role
1.139 albertel 3919: if ($key=~m{^form\.ren\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
1.116 raeburn 3920: my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
3921: my $result = &Apache::lonnet::assigncustomrole(
3922: $env{'form.ccdomain'}, $env{'form.ccuname'},
1.240 raeburn 3923: $url,$rdom,$rnam,$rolename,0,$now,undef,$context);
1.369 bisitz 3924: $r->print(&Apache::lonhtmlcommon::confirm_success(
3925: &mt('Re-enabling custom role [_1] by [_2] in [_3]',
1.372 raeburn 3926: $rolename,$rnam.':'.$rdom,&Apache::loncommon::show_role_extent($1,$context,'cr')),
1.369 bisitz 3927: $result ne "ok").'<br />');
3928: if ($result ne "ok") {
3929: $r->print(&mt('Error: [_1]',$result).'<br />');
3930: }
1.225 raeburn 3931: if (!grep(/^cr$/,@rolechanges)) {
3932: push(@rolechanges,'cr');
3933: }
1.116 raeburn 3934: }
1.135 raeburn 3935: } elsif ($key=~/^form\.act/) {
1.101 albertel 3936: my $udom = $env{'form.ccdomain'};
3937: my $uname = $env{'form.ccuname'};
1.141 albertel 3938: if ($key=~/^form\.act\_($match_domain)\_($match_courseid)\_cr_cr_($match_domain)_($match_username)_([^\_]+)$/) {
1.65 www 3939: # Activate a custom role
1.83 albertel 3940: my ($one,$two,$three,$four,$five)=($1,$2,$3,$4,$5);
3941: my $url='/'.$one.'/'.$two;
3942: my $full=$one.'_'.$two.'_cr_cr_'.$three.'_'.$four.'_'.$five;
1.65 www 3943:
1.101 albertel 3944: my $start = ( $env{'form.start_'.$full} ?
3945: $env{'form.start_'.$full} :
1.88 raeburn 3946: $now );
1.101 albertel 3947: my $end = ( $env{'form.end_'.$full} ?
3948: $env{'form.end_'.$full} :
1.88 raeburn 3949: 0 );
3950:
3951: # split multiple sections
3952: my %sections = ();
1.101 albertel 3953: my $num_sections = &build_roles($env{'form.sec_'.$full},\%sections,$5);
1.88 raeburn 3954: if ($num_sections == 0) {
1.240 raeburn 3955: $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$url,$three,$four,$five,$start,$end,$context));
1.88 raeburn 3956: } else {
1.114 albertel 3957: my %curr_groups =
1.117 raeburn 3958: &Apache::longroup::coursegroups($one,$two);
1.404 raeburn 3959: foreach my $sec (sort {$a cmp $b} keys(%sections)) {
1.113 raeburn 3960: if (($sec eq 'none') || ($sec eq 'all') ||
3961: exists($curr_groups{$sec})) {
3962: $disallowed{$sec} = $url;
3963: next;
3964: }
3965: my $securl = $url.'/'.$sec;
1.240 raeburn 3966: $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$securl,$three,$four,$five,$start,$end,$context));
1.88 raeburn 3967: }
3968: }
1.225 raeburn 3969: if (!grep(/^cr$/,@rolechanges)) {
3970: push(@rolechanges,'cr');
3971: }
1.142 raeburn 3972: } elsif ($key=~/^form\.act\_($match_domain)\_($match_name)\_([^\_]+)$/) {
1.27 matthew 3973: # Activate roles for sections with 3 id numbers
3974: # set start, end times, and the url for the class
1.83 albertel 3975: my ($one,$two,$three)=($1,$2,$3);
1.101 albertel 3976: my $start = ( $env{'form.start_'.$one.'_'.$two.'_'.$three} ?
3977: $env{'form.start_'.$one.'_'.$two.'_'.$three} :
1.27 matthew 3978: $now );
1.101 albertel 3979: my $end = ( $env{'form.end_'.$one.'_'.$two.'_'.$three} ?
3980: $env{'form.end_'.$one.'_'.$two.'_'.$three} :
1.27 matthew 3981: 0 );
1.83 albertel 3982: my $url='/'.$one.'/'.$two;
1.88 raeburn 3983: my $type = 'three';
3984: # split multiple sections
3985: my %sections = ();
1.101 albertel 3986: my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two.'_'.$three},\%sections,$three);
1.375 raeburn 3987: my $credits;
3988: if ($three eq 'st') {
3989: if ($showcredits) {
3990: my $defaultcredits =
3991: &Apache::lonuserutils::get_defaultcredits($one,$two);
3992: $credits = $env{'form.credits_'.$one.'_'.$two.'_'.$three};
3993: $credits =~ s/[^\d\.]//g;
3994: if ($credits eq $defaultcredits) {
3995: undef($credits);
3996: }
3997: }
3998: }
1.88 raeburn 3999: if ($num_sections == 0) {
1.375 raeburn 4000: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'',$context,$credits));
1.88 raeburn 4001: } else {
1.114 albertel 4002: my %curr_groups =
1.117 raeburn 4003: &Apache::longroup::coursegroups($one,$two);
1.88 raeburn 4004: my $emptysec = 0;
1.404 raeburn 4005: foreach my $sec (sort {$a cmp $b} keys(%sections)) {
1.88 raeburn 4006: $sec =~ s/\W//g;
1.113 raeburn 4007: if ($sec ne '') {
4008: if (($sec eq 'none') || ($sec eq 'all') ||
4009: exists($curr_groups{$sec})) {
4010: $disallowed{$sec} = $url;
4011: next;
4012: }
1.88 raeburn 4013: my $securl = $url.'/'.$sec;
1.375 raeburn 4014: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$three,$start,$end,$one,$two,$sec,$context,$credits));
1.88 raeburn 4015: } else {
4016: $emptysec = 1;
4017: }
4018: }
4019: if ($emptysec) {
1.375 raeburn 4020: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'',$context,$credits));
1.88 raeburn 4021: }
1.225 raeburn 4022: }
4023: if (!grep(/^\Q$three\E$/,@rolechanges)) {
4024: push(@rolechanges,$three);
4025: }
1.135 raeburn 4026: } elsif ($key=~/^form\.act\_([^\_]+)\_([^\_]+)$/) {
1.27 matthew 4027: # Activate roles for sections with two id numbers
4028: # set start, end times, and the url for the class
1.101 albertel 4029: my $start = ( $env{'form.start_'.$1.'_'.$2} ?
4030: $env{'form.start_'.$1.'_'.$2} :
1.27 matthew 4031: $now );
1.101 albertel 4032: my $end = ( $env{'form.end_'.$1.'_'.$2} ?
4033: $env{'form.end_'.$1.'_'.$2} :
1.27 matthew 4034: 0 );
1.225 raeburn 4035: my $one = $1;
4036: my $two = $2;
4037: my $url='/'.$one.'/';
1.88 raeburn 4038: # split multiple sections
4039: my %sections = ();
1.225 raeburn 4040: my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two},\%sections,$two);
1.88 raeburn 4041: if ($num_sections == 0) {
1.240 raeburn 4042: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,'',$context));
1.88 raeburn 4043: } else {
4044: my $emptysec = 0;
1.404 raeburn 4045: foreach my $sec (sort {$a cmp $b} keys(%sections)) {
1.88 raeburn 4046: if ($sec ne '') {
4047: my $securl = $url.'/'.$sec;
1.240 raeburn 4048: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$two,$start,$end,$one,undef,$sec,$context));
1.88 raeburn 4049: } else {
4050: $emptysec = 1;
4051: }
4052: }
4053: if ($emptysec) {
1.240 raeburn 4054: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,'',$context));
1.88 raeburn 4055: }
4056: }
1.225 raeburn 4057: if (!grep(/^\Q$two\E$/,@rolechanges)) {
4058: push(@rolechanges,$two);
4059: }
1.64 www 4060: } else {
1.190 raeburn 4061: $r->print('<p><span class="LC_error">'.&mt('ERROR').': '.&mt('Unknown command').' <tt>'.$key.'</tt></span></p><br />');
1.64 www 4062: }
1.113 raeburn 4063: foreach my $key (sort(keys(%disallowed))) {
1.274 bisitz 4064: $r->print('<p class="LC_warning">');
1.113 raeburn 4065: if (($key eq 'none') || ($key eq 'all')) {
1.274 bisitz 4066: $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 4067: } else {
1.274 bisitz 4068: $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 4069: }
1.274 bisitz 4070: $r->print('</p><p>'
4071: .&mt('Please [_1]go back[_2] and choose a different section name.'
4072: ,'<a href="javascript:history.go(-1)'
4073: ,'</a>')
4074: .'</p><br />'
4075: );
1.113 raeburn 4076: }
4077: }
1.101 albertel 4078: } # End of foreach (keys(%env))
1.75 www 4079: # Flush the course logs so reverse user roles immediately updated
1.349 raeburn 4080: $r->register_cleanup(\&Apache::lonnet::flushcourselogs);
1.225 raeburn 4081: if (@rolechanges == 0) {
1.372 raeburn 4082: $r->print('<p>'.&mt('No roles to modify').'</p>');
1.193 raeburn 4083: }
1.225 raeburn 4084: return @rolechanges;
1.220 raeburn 4085: }
4086:
1.375 raeburn 4087: sub get_user_credits {
4088: my ($uname,$udom,$defaultcredits,$cdom,$cnum) = @_;
4089: if ($cdom eq '' || $cnum eq '') {
4090: return unless ($env{'request.course.id'});
4091: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
4092: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
4093: }
4094: my $credits;
4095: my %currhash =
4096: &Apache::lonnet::get('classlist',[$uname.':'.$udom],$cdom,$cnum);
4097: if (keys(%currhash) > 0) {
4098: my @items = split(/:/,$currhash{$uname.':'.$udom});
4099: my $crdidx = &Apache::loncoursedata::CL_CREDITS() - 3;
4100: $credits = $items[$crdidx];
4101: $credits =~ s/[^\d\.]//g;
4102: }
4103: if ($credits eq $defaultcredits) {
4104: undef($credits);
4105: }
4106: return $credits;
4107: }
4108:
1.220 raeburn 4109: sub enroll_single_student {
1.375 raeburn 4110: my ($r,$uhome,$amode,$genpwd,$now,$newuser,$context,$crstype,
4111: $showcredits,$defaultcredits) = @_;
1.318 raeburn 4112: $r->print('<h3>');
4113: if ($crstype eq 'Community') {
4114: $r->print(&mt('Enrolling Member'));
4115: } else {
4116: $r->print(&mt('Enrolling Student'));
4117: }
4118: $r->print('</h3>');
1.220 raeburn 4119:
4120: # Remove non alphanumeric values from section
4121: $env{'form.sections'}=~s/\W//g;
4122:
1.375 raeburn 4123: my $credits;
4124: if (($showcredits) && ($env{'form.credits'} ne '')) {
4125: $credits = $env{'form.credits'};
4126: $credits =~ s/[^\d\.]//g;
4127: if ($credits ne '') {
4128: if ($credits eq $defaultcredits) {
4129: undef($credits);
4130: }
4131: }
4132: }
4133:
1.220 raeburn 4134: # Clean out any old student roles the user has in this class.
4135: &Apache::lonuserutils::modifystudent($env{'form.ccdomain'},
4136: $env{'form.ccuname'},$env{'request.course.id'},undef,$uhome);
4137: my ($startdate,$enddate) = &Apache::lonuserutils::get_dates_from_form();
4138: my $enroll_result =
4139: &Apache::lonnet::modify_student_enrollment($env{'form.ccdomain'},
4140: $env{'form.ccuname'},$env{'form.cid'},$env{'form.cfirstname'},
4141: $env{'form.cmiddlename'},$env{'form.clastname'},
4142: $env{'form.generation'},$env{'form.sections'},$enddate,
1.375 raeburn 4143: $startdate,'manual',undef,$env{'request.course.id'},'',$context,
4144: $credits);
1.220 raeburn 4145: if ($enroll_result =~ /^ok/) {
1.381 bisitz 4146: $r->print(&mt('[_1] enrolled','<b>'.$env{'form.ccuname'}.':'.$env{'form.ccdomain'}.'</b>'));
1.220 raeburn 4147: if ($env{'form.sections'} ne '') {
4148: $r->print(' '.&mt('in section [_1]',$env{'form.sections'}));
4149: }
4150: my ($showstart,$showend);
4151: if ($startdate <= $now) {
4152: $showstart = &mt('Access starts immediately');
4153: } else {
4154: $showstart = &mt('Access starts: ').&Apache::lonlocal::locallocaltime($startdate);
4155: }
4156: if ($enddate == 0) {
4157: $showend = &mt('ends: no ending date');
4158: } else {
4159: $showend = &mt('ends: ').&Apache::lonlocal::locallocaltime($enddate);
4160: }
4161: $r->print('.<br />'.$showstart.'; '.$showend);
4162: if ($startdate <= $now && !$newuser) {
1.386 bisitz 4163: $r->print('<p class="LC_info">');
1.318 raeburn 4164: if ($crstype eq 'Community') {
1.392 raeburn 4165: $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 4166: } else {
1.392 raeburn 4167: $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 4168: }
4169: $r->print('</p>');
1.220 raeburn 4170: }
4171: } else {
4172: $r->print(&mt('unable to enroll').": ".$enroll_result);
4173: }
4174: return;
1.188 raeburn 4175: }
4176:
1.204 raeburn 4177: sub get_defaultquota_text {
4178: my ($settingstatus) = @_;
4179: my $defquotatext;
4180: if ($settingstatus eq '') {
1.383 raeburn 4181: $defquotatext = &mt('default');
1.204 raeburn 4182: } else {
4183: my ($usertypes,$order) =
4184: &Apache::lonnet::retrieve_inst_usertypes($env{'form.ccdomain'});
4185: if ($usertypes->{$settingstatus} eq '') {
1.383 raeburn 4186: $defquotatext = &mt('default');
1.204 raeburn 4187: } else {
1.383 raeburn 4188: $defquotatext = &mt('default for [_1]',$usertypes->{$settingstatus});
1.204 raeburn 4189: }
4190: }
4191: return $defquotatext;
4192: }
4193:
1.188 raeburn 4194: sub update_result_form {
4195: my ($uhome) = @_;
4196: my $outcome =
1.367 golterma 4197: '<form name="userupdate" method="post" action="">'."\n";
1.160 raeburn 4198: foreach my $item ('srchby','srchin','srchtype','srchterm','srchdomain','ccuname','ccdomain') {
1.188 raeburn 4199: $outcome .= '<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n";
1.160 raeburn 4200: }
1.207 raeburn 4201: if ($env{'form.origname'} ne '') {
4202: $outcome .= '<input type="hidden" name="origname" value="'.$env{'form.origname'}.'" />'."\n";
4203: }
1.160 raeburn 4204: foreach my $item ('sortby','seluname','seludom') {
4205: if (exists($env{'form.'.$item})) {
1.188 raeburn 4206: $outcome .= '<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n";
1.160 raeburn 4207: }
4208: }
1.188 raeburn 4209: if ($uhome eq 'no_host') {
4210: $outcome .= '<input type="hidden" name="forcenewuser" value="1" />'."\n";
4211: }
4212: $outcome .= '<input type="hidden" name="phase" value="" />'."\n".
1.383 raeburn 4213: '<input type="hidden" name="currstate" value="" />'."\n".
4214: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n".
1.188 raeburn 4215: '</form>';
4216: return $outcome;
1.4 www 4217: }
4218:
1.149 raeburn 4219: sub quota_admin {
1.378 raeburn 4220: my ($setquota,$changeHash,$name) = @_;
1.149 raeburn 4221: my $quotachanged;
4222: if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
4223: # Current user has quota modification privileges
1.267 raeburn 4224: if (ref($changeHash) eq 'HASH') {
4225: $quotachanged = 1;
1.378 raeburn 4226: $changeHash->{$name.'quota'} = $setquota;
1.267 raeburn 4227: }
1.149 raeburn 4228: }
4229: return $quotachanged;
4230: }
4231:
1.267 raeburn 4232: sub tool_admin {
1.275 raeburn 4233: my ($tool,$settool,$changeHash,$context) = @_;
4234: my $canchange = 0;
1.279 raeburn 4235: if ($context eq 'requestcourses') {
1.275 raeburn 4236: if (&Apache::lonnet::allowed('ccc',$env{'form.ccdomain'})) {
4237: $canchange = 1;
4238: }
1.300 raeburn 4239: } elsif ($context eq 'reqcrsotherdom') {
4240: if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
4241: $canchange = 1;
4242: }
1.362 raeburn 4243: } elsif ($context eq 'requestauthor') {
4244: if (&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) {
4245: $canchange = 1;
4246: }
1.275 raeburn 4247: } elsif (&Apache::lonnet::allowed('mut',$env{'form.ccdomain'})) {
4248: # Current user has quota modification privileges
4249: $canchange = 1;
4250: }
1.267 raeburn 4251: my $toolchanged;
1.275 raeburn 4252: if ($canchange) {
1.267 raeburn 4253: if (ref($changeHash) eq 'HASH') {
4254: $toolchanged = 1;
1.362 raeburn 4255: if ($tool eq 'requestauthor') {
4256: $changeHash->{$context} = $settool;
4257: } else {
4258: $changeHash->{$context.'.'.$tool} = $settool;
4259: }
1.267 raeburn 4260: }
4261: }
4262: return $toolchanged;
4263: }
4264:
1.88 raeburn 4265: sub build_roles {
1.89 raeburn 4266: my ($sectionstr,$sections,$role) = @_;
1.88 raeburn 4267: my $num_sections = 0;
4268: if ($sectionstr=~ /,/) {
4269: my @secnums = split/,/,$sectionstr;
1.89 raeburn 4270: if ($role eq 'st') {
4271: $secnums[0] =~ s/\W//g;
4272: $$sections{$secnums[0]} = 1;
4273: $num_sections = 1;
4274: } else {
4275: foreach my $sec (@secnums) {
4276: $sec =~ ~s/\W//g;
1.150 banghart 4277: if (!($sec eq "")) {
1.89 raeburn 4278: if (exists($$sections{$sec})) {
4279: $$sections{$sec} ++;
4280: } else {
4281: $$sections{$sec} = 1;
4282: $num_sections ++;
4283: }
1.88 raeburn 4284: }
4285: }
4286: }
4287: } else {
4288: $sectionstr=~s/\W//g;
4289: unless ($sectionstr eq '') {
4290: $$sections{$sectionstr} = 1;
4291: $num_sections ++;
4292: }
4293: }
1.129 albertel 4294:
1.88 raeburn 4295: return $num_sections;
4296: }
4297:
1.58 www 4298: # ========================================================== Custom Role Editor
4299:
4300: sub custom_role_editor {
1.406.2.5 raeburn 4301: my ($r,$brcrum,$prefix) = @_;
1.324 raeburn 4302: my $action = $env{'form.customroleaction'};
4303: my $rolename;
4304: if ($action eq 'new') {
4305: $rolename=$env{'form.newrolename'};
4306: } else {
4307: $rolename=$env{'form.rolename'};
1.59 www 4308: }
4309:
1.324 raeburn 4310: my ($crstype,$context);
4311: if ($env{'request.course.id'}) {
4312: $crstype = &Apache::loncommon::course_type();
4313: $context = 'course';
4314: } else {
4315: $context = 'domain';
1.406.2.5 raeburn 4316: $crstype = 'course';
1.324 raeburn 4317: }
1.351 raeburn 4318:
4319: $rolename=~s/[^A-Za-z0-9]//gs;
4320: if (!$rolename || $env{'form.phase'} eq 'pickrole') {
4321: &print_username_entry_form($r,undef,undef,undef,undef,$crstype,$brcrum);
4322: return;
4323: }
4324:
1.406.2.5 raeburn 4325: my $formname = 'form1';
4326: my %privs=();
4327: my $body_top = '<h2>';
4328: # ------------------------------------------------------- Does this role exist?
1.59 www 4329: my ($rdummy,$roledef)=
4330: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
4331: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1.406.2.5 raeburn 4332: $body_top .= &mt('Existing Role').' "';
1.61 www 4333: # ------------------------------------------------- Get current role privileges
1.406.2.5 raeburn 4334: ($privs{'system'},$privs{'domain'},$privs{'course'})=split(/\_/,$roledef);
4335: if ($privs{'system'} =~ /bre\&S/) {
4336: if ($context eq 'domain') {
4337: $crstype = 'Course';
4338: } elsif ($crstype eq 'Community') {
4339: $privs{'system'} =~ s/bre\&S//;
4340: }
4341: } elsif ($context eq 'domain') {
4342: $crstype = 'Course';
1.324 raeburn 4343: }
1.59 www 4344: } else {
1.406.2.5 raeburn 4345: $body_top .= &mt('New Role').' "';
4346: $roledef='';
1.59 www 4347: }
1.153 banghart 4348: $body_top .= $rolename.'"</h2>';
1.406.2.5 raeburn 4349:
4350: # ------------------------------------------------------- What can be assigned?
4351: my %full=();
4352: my %levels=(
4353: course => {},
4354: domain => {},
4355: system => {},
4356: );
4357: my %levelscurrent=(
4358: course => {},
4359: domain => {},
4360: system => {},
4361: );
4362: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
1.160 raeburn 4363: my ($jsback,$elements) = &crumb_utilities();
1.406.2.5 raeburn 4364: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
4365: my $head_script =
4366: &Apache::lonuserutils::custom_roledefs_js($context,$crstype,$formname,
4367: \%full,\@templateroles,$jsback);
1.351 raeburn 4368: push (@{$brcrum},
1.406.2.5 raeburn 4369: {href => "javascript:backPage(document.$formname,'pickrole','')",
1.351 raeburn 4370: text => "Pick custom role",
4371: faq => 282,bug=>'Instructor Interface',},
1.406.2.5 raeburn 4372: {href => "javascript:backPage(document.$formname,'','')",
1.351 raeburn 4373: text => "Edit custom role",
4374: faq => 282,
4375: bug => 'Instructor Interface',
4376: help => 'Course_Editing_Custom_Roles'}
4377: );
4378: my $args = { bread_crumbs => $brcrum,
4379: bread_crumbs_component => 'User Management'};
4380: $r->print(&Apache::loncommon::start_page('Custom Role Editor',
4381: $head_script,$args).
4382: $body_top);
1.406.2.5 raeburn 4383: $r->print('<form name="'.$formname.'" method="post" action="">'."\n".
4384: &Apache::lonuserutils::custom_role_header($context,$crstype,
4385: \@templateroles,$prefix));
1.264 bisitz 4386:
1.61 www 4387: $r->print(<<ENDCCF);
4388: <input type="hidden" name="phase" value="set_custom_roles" />
4389: <input type="hidden" name="rolename" value="$rolename" />
4390: ENDCCF
1.406.2.5 raeburn 4391: $r->print(&Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
4392: \%levelscurrent,$prefix));
1.135 raeburn 4393: $r->print(&Apache::loncommon::end_data_table().
1.190 raeburn 4394: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'.
1.160 raeburn 4395: '<input type="hidden" name="startrolename" value="'.$env{'form.rolename'}.
1.406.2.5 raeburn 4396: '" />'."\n".'<input type="hidden" name="currstate" value="" />'."\n".
1.160 raeburn 4397: '<input type="reset" value="'.&mt("Reset").'" />'."\n".
1.351 raeburn 4398: '<input type="submit" value="'.&mt('Save').'" /></form>');
1.61 www 4399: }
1.406.2.5 raeburn 4400:
1.61 www 4401: # ---------------------------------------------------------- Call to definerole
4402: sub set_custom_role {
1.406.2.5 raeburn 4403: my ($r,$context,$brcrum,$prefix) = @_;
1.101 albertel 4404: my $rolename=$env{'form.rolename'};
1.63 www 4405: $rolename=~s/[^A-Za-z0-9]//gs;
1.150 banghart 4406: if (!$rolename) {
1.406.2.5 raeburn 4407: &custom_role_editor($r,$brcrum,$prefix);
1.61 www 4408: return;
4409: }
1.160 raeburn 4410: my ($jsback,$elements) = &crumb_utilities();
1.301 bisitz 4411: my $jscript = '<script type="text/javascript">'
4412: .'// <![CDATA['."\n"
4413: .$jsback."\n"
4414: .'// ]]>'."\n"
4415: .'</script>'."\n";
1.352 raeburn 4416: push(@{$brcrum},
4417: {href => "javascript:backPage(document.customresult,'pickrole','')",
4418: text => "Pick custom role",
4419: faq => 282,
4420: bug => 'Instructor Interface',},
4421: {href => "javascript:backPage(document.customresult,'selected_custom_edit','')",
4422: text => "Edit custom role",
4423: faq => 282,
4424: bug => 'Instructor Interface',},
4425: {href => "javascript:backPage(document.customresult,'set_custom_roles','')",
4426: text => "Result",
4427: faq => 282,
4428: bug => 'Instructor Interface',
4429: help => 'Course_Editing_Custom_Roles'},
4430: );
4431: my $args = { bread_crumbs => $brcrum,
1.406.2.5 raeburn 4432: bread_crumbs_component => 'User Management'};
1.351 raeburn 4433: $r->print(&Apache::loncommon::start_page('Save Custom Role',$jscript,$args));
1.160 raeburn 4434:
1.393 raeburn 4435: my $newrole;
1.61 www 4436: my ($rdummy,$roledef)=
1.110 albertel 4437: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
4438:
1.61 www 4439: # ------------------------------------------------------- Does this role exist?
1.188 raeburn 4440: $r->print('<h3>');
1.61 www 4441: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1.73 sakharuk 4442: $r->print(&mt('Existing Role').' "');
1.61 www 4443: } else {
1.73 sakharuk 4444: $r->print(&mt('New Role').' "');
1.61 www 4445: $roledef='';
1.393 raeburn 4446: $newrole = 1;
1.61 www 4447: }
1.188 raeburn 4448: $r->print($rolename.'"</h3>');
1.406.2.5 raeburn 4449: # ------------------------------------------------- Assign role and show result
1.61 www 4450:
1.387 bisitz 4451: my $errmsg;
1.406.2.5 raeburn 4452: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$prefix);
4453: # Assign role and return result
4454: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
4455: $newprivs{'c'});
1.387 bisitz 4456: if ($result ne 'ok') {
4457: $errmsg = ': '.$result;
4458: }
4459: my $message =
4460: &Apache::lonhtmlcommon::confirm_success(
4461: &mt('Defining Role').$errmsg, ($result eq 'ok' ? 0 : 1));
1.101 albertel 4462: if ($env{'request.course.id'}) {
4463: my $url='/'.$env{'request.course.id'};
1.63 www 4464: $url=~s/\_/\//g;
1.387 bisitz 4465: $result =
4466: &Apache::lonnet::assigncustomrole(
4467: $env{'user.domain'},$env{'user.name'},
4468: $url,
4469: $env{'user.domain'},$env{'user.name'},
4470: $rolename,undef,undef,undef,$context);
4471: if ($result ne 'ok') {
4472: $errmsg = ': '.$result;
4473: }
4474: $message .=
4475: '<br />'
4476: .&Apache::lonhtmlcommon::confirm_success(
4477: &mt('Assigning Role to Self').$errmsg, ($result eq 'ok' ? 0 : 1));
1.63 www 4478: }
1.380 bisitz 4479: $r->print(
1.387 bisitz 4480: &Apache::loncommon::confirmwrapper($message)
4481: .'<br />'
4482: .&Apache::lonhtmlcommon::actionbox([
4483: '<a href="javascript:backPage(document.customresult,'."'pickrole'".')">'
4484: .&mt('Create or edit another custom role')
4485: .'</a>'])
1.380 bisitz 4486: .'<form name="customresult" method="post" action="">'
1.387 bisitz 4487: .&Apache::lonhtmlcommon::echo_form_input([])
4488: .'</form>'
1.380 bisitz 4489: );
1.58 www 4490: }
4491:
1.2 www 4492: # ================================================================ Main Handler
4493: sub handler {
4494: my $r = shift;
4495: if ($r->header_only) {
1.68 www 4496: &Apache::loncommon::content_type($r,'text/html');
1.2 www 4497: $r->send_http_header;
4498: return OK;
4499: }
1.318 raeburn 4500: my ($context,$crstype);
1.190 raeburn 4501: if ($env{'request.course.id'}) {
4502: $context = 'course';
1.318 raeburn 4503: $crstype = &Apache::loncommon::course_type();
1.190 raeburn 4504: } elsif ($env{'request.role'} =~ /^au\./) {
1.206 raeburn 4505: $context = 'author';
1.190 raeburn 4506: } else {
4507: $context = 'domain';
4508: }
1.375 raeburn 4509:
1.190 raeburn 4510: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.233 raeburn 4511: ['action','state','callingform','roletype','showrole','bulkaction','popup','phase',
1.391 raeburn 4512: 'username','domain','srchterm','srchdomain','srchin','srchby','srchtype','queue']);
1.190 raeburn 4513: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.351 raeburn 4514: my $args;
4515: my $brcrum = [];
4516: my $bread_crumbs_component = 'User Management';
1.391 raeburn 4517: if (($env{'form.action'} ne 'dateselect') && ($env{'form.action'} ne 'displayuserreq')) {
1.351 raeburn 4518: $brcrum = [{href=>"/adm/createuser",
4519: text=>"User Management",
4520: 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'}
4521: ];
1.202 raeburn 4522: }
1.289 droeschl 4523: #SD Following files not added to help, because the corresponding .tex-files seem to
4524: #be missing: Course_Approve_Selfenroll,Course_User_Logs,
1.209 raeburn 4525: my ($permission,$allowed) =
1.318 raeburn 4526: &Apache::lonuserutils::get_permission($context,$crstype);
1.190 raeburn 4527: if (!$allowed) {
1.358 raeburn 4528: if ($context eq 'course') {
4529: $r->internal_redirect('/adm/viewclasslist');
4530: return OK;
4531: }
1.190 raeburn 4532: $env{'user.error.msg'}=
4533: "/adm/createuser:cst:0:0:Cannot create/modify user data ".
4534: "or view user status.";
4535: return HTTP_NOT_ACCEPTABLE;
4536: }
4537:
4538: &Apache::loncommon::content_type($r,'text/html');
4539: $r->send_http_header;
4540:
1.375 raeburn 4541: my $showcredits;
4542: if ((($context eq 'course') && ($crstype eq 'Course')) ||
4543: ($context eq 'domain')) {
4544: my %domdefaults =
4545: &Apache::lonnet::get_domain_defaults($env{'request.role.domain'});
4546: if ($domdefaults{'officialcredits'} || $domdefaults{'unofficialcredits'}) {
4547: $showcredits = 1;
4548: }
4549: }
4550:
1.190 raeburn 4551: # Main switch on form.action and form.state, as appropriate
4552: if (! exists($env{'form.action'})) {
1.351 raeburn 4553: $args = {bread_crumbs => $brcrum,
4554: bread_crumbs_component => $bread_crumbs_component};
4555: $r->print(&header(undef,$args));
1.318 raeburn 4556: $r->print(&print_main_menu($permission,$context,$crstype));
1.190 raeburn 4557: } elsif ($env{'form.action'} eq 'upload' && $permission->{'cusr'}) {
1.351 raeburn 4558: push(@{$brcrum},
4559: { href => '/adm/createuser?action=upload&state=',
4560: text => 'Upload Users List',
4561: help => 'Course_Create_Class_List',
4562: });
4563: $bread_crumbs_component = 'Upload Users List';
4564: $args = {bread_crumbs => $brcrum,
4565: bread_crumbs_component => $bread_crumbs_component};
4566: $r->print(&header(undef,$args));
1.190 raeburn 4567: $r->print('<form name="studentform" method="post" '.
4568: 'enctype="multipart/form-data" '.
4569: ' action="/adm/createuser">'."\n");
4570: if (! exists($env{'form.state'})) {
4571: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
4572: } elsif ($env{'form.state'} eq 'got_file') {
1.375 raeburn 4573: &Apache::lonuserutils::print_upload_manager_form($r,$context,$permission,
4574: $crstype,$showcredits);
1.190 raeburn 4575: } elsif ($env{'form.state'} eq 'enrolling') {
4576: if ($env{'form.datatoken'}) {
1.375 raeburn 4577: &Apache::lonuserutils::upfile_drop_add($r,$context,$permission,
4578: $showcredits);
1.190 raeburn 4579: }
4580: } else {
4581: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
4582: }
1.406.2.5 raeburn 4583: } elsif (((($env{'form.action'} eq 'singleuser') || ($env{'form.action'}
4584: eq 'singlestudent')) && ($permission->{'cusr'})) ||
1.406.2.6 raeburn 4585: (($env{'form.action'} eq 'singleuser') && ($permission->{'view'})) ||
1.406.2.5 raeburn 4586: (($env{'form.action'} eq 'accesslogs') && ($permission->{'activity'}))) {
1.190 raeburn 4587: my $phase = $env{'form.phase'};
4588: my @search = ('srchterm','srchby','srchin','srchtype','srchdomain');
1.192 albertel 4589: &Apache::loncreateuser::restore_prev_selections();
4590: my $srch;
4591: foreach my $item (@search) {
4592: $srch->{$item} = $env{'form.'.$item};
4593: }
1.207 raeburn 4594: if (($phase eq 'get_user_info') || ($phase eq 'userpicked') ||
1.406.2.5 raeburn 4595: ($phase eq 'createnewuser') || ($phase eq 'activity')) {
1.207 raeburn 4596: if ($env{'form.phase'} eq 'createnewuser') {
4597: my $response;
4598: if ($env{'form.srchterm'} !~ /^$match_username$/) {
1.366 bisitz 4599: my $response =
4600: '<span class="LC_warning">'
4601: .&mt('You must specify a valid username. Only the following are allowed:'
4602: .' letters numbers - . @')
4603: .'</span>';
1.221 raeburn 4604: $env{'form.phase'} = '';
1.375 raeburn 4605: &print_username_entry_form($r,$context,$response,$srch,undef,
4606: $crstype,$brcrum,$showcredits);
1.207 raeburn 4607: } else {
4608: my $ccuname =&LONCAPA::clean_username($srch->{'srchterm'});
4609: my $ccdomain=&LONCAPA::clean_domain($srch->{'srchdomain'});
4610: &print_user_modification_page($r,$ccuname,$ccdomain,
1.221 raeburn 4611: $srch,$response,$context,
1.375 raeburn 4612: $permission,$crstype,$brcrum,
4613: $showcredits);
1.207 raeburn 4614: }
4615: } elsif ($env{'form.phase'} eq 'get_user_info') {
1.190 raeburn 4616: my ($currstate,$response,$forcenewuser,$results) =
1.221 raeburn 4617: &user_search_result($context,$srch);
1.190 raeburn 4618: if ($env{'form.currstate'} eq 'modify') {
4619: $currstate = $env{'form.currstate'};
4620: }
4621: if ($currstate eq 'select') {
4622: &print_user_selection_page($r,$response,$srch,$results,
1.351 raeburn 4623: \@search,$context,undef,$crstype,
4624: $brcrum);
1.406.2.5 raeburn 4625: } elsif (($currstate eq 'modify') || ($env{'form.action'} eq 'accesslogs')) {
4626: my ($ccuname,$ccdomain,$uhome);
1.190 raeburn 4627: if (($srch->{'srchby'} eq 'uname') &&
4628: ($srch->{'srchtype'} eq 'exact')) {
4629: $ccuname = $srch->{'srchterm'};
4630: $ccdomain= $srch->{'srchdomain'};
4631: } else {
4632: my @matchedunames = keys(%{$results});
4633: ($ccuname,$ccdomain) = split(/:/,$matchedunames[0]);
4634: }
4635: $ccuname =&LONCAPA::clean_username($ccuname);
4636: $ccdomain=&LONCAPA::clean_domain($ccdomain);
1.406.2.5 raeburn 4637: if ($env{'form.action'} eq 'accesslogs') {
4638: my $uhome;
4639: if (($ccuname ne '') && ($ccdomain ne '')) {
4640: $uhome = &Apache::lonnet::homeserver($ccuname,$ccdomain);
4641: }
4642: if (($uhome eq '') || ($uhome eq 'no_host')) {
4643: $env{'form.phase'} = '';
4644: undef($forcenewuser);
4645: #if ($response) {
4646: # unless ($response =~ m{\Q<br /><br />\E$}) {
4647: # $response .= '<br /><br />';
4648: # }
4649: #}
4650: &print_username_entry_form($r,$context,$response,$srch,
4651: $forcenewuser,$crstype,$brcrum);
4652: } else {
4653: &print_useraccesslogs_display($r,$ccuname,$ccdomain,$permission,$brcrum);
4654: }
4655: } else {
4656: if ($env{'form.forcenewuser'}) {
4657: $response = '';
4658: }
4659: &print_user_modification_page($r,$ccuname,$ccdomain,
4660: $srch,$response,$context,
4661: $permission,$crstype,$brcrum);
1.190 raeburn 4662: }
4663: } elsif ($currstate eq 'query') {
1.351 raeburn 4664: &print_user_query_page($r,'createuser',$brcrum);
1.190 raeburn 4665: } else {
1.229 raeburn 4666: $env{'form.phase'} = '';
1.207 raeburn 4667: &print_username_entry_form($r,$context,$response,$srch,
1.351 raeburn 4668: $forcenewuser,$crstype,$brcrum);
1.190 raeburn 4669: }
4670: } elsif ($env{'form.phase'} eq 'userpicked') {
4671: my $ccuname = &LONCAPA::clean_username($env{'form.seluname'});
4672: my $ccdomain = &LONCAPA::clean_domain($env{'form.seludom'});
1.406.2.5 raeburn 4673: if ($env{'form.action'} eq 'accesslogs') {
4674: &print_useraccesslogs_display($r,$ccuname,$ccdomain,$permission,$brcrum);
4675: } else {
4676: &print_user_modification_page($r,$ccuname,$ccdomain,$srch,'',
4677: $context,$permission,$crstype,
4678: $brcrum);
4679: }
4680: } elsif ($env{'form.action'} eq 'accesslogs') {
4681: my $ccuname = &LONCAPA::clean_username($env{'form.accessuname'});
4682: my $ccdomain = &LONCAPA::clean_domain($env{'form.accessudom'});
4683: &print_useraccesslogs_display($r,$ccuname,$ccdomain,$permission,$brcrum);
1.190 raeburn 4684: }
4685: } elsif ($env{'form.phase'} eq 'update_user_data') {
1.375 raeburn 4686: &update_user_data($r,$context,$crstype,$brcrum,$showcredits);
1.190 raeburn 4687: } else {
1.351 raeburn 4688: &print_username_entry_form($r,$context,undef,$srch,undef,$crstype,
4689: $brcrum);
1.190 raeburn 4690: }
4691: } elsif ($env{'form.action'} eq 'custom' && $permission->{'custom'}) {
1.406.2.5 raeburn 4692: my $prefix;
1.190 raeburn 4693: if ($env{'form.phase'} eq 'set_custom_roles') {
1.406.2.5 raeburn 4694: &set_custom_role($r,$context,$brcrum,$prefix);
1.190 raeburn 4695: } else {
1.406.2.5 raeburn 4696: &custom_role_editor($r,$brcrum,$prefix);
1.190 raeburn 4697: }
1.362 raeburn 4698: } elsif (($env{'form.action'} eq 'processauthorreq') &&
4699: ($permission->{'cusr'}) &&
4700: (&Apache::lonnet::allowed('cau',$env{'request.role.domain'}))) {
4701: push(@{$brcrum},
4702: {href => '/adm/createuser?action=processauthorreq',
1.385 bisitz 4703: text => 'Authoring Space requests',
1.362 raeburn 4704: help => 'Domain_Role_Approvals'});
4705: $bread_crumbs_component = 'Authoring requests';
4706: if ($env{'form.state'} eq 'done') {
4707: push(@{$brcrum},
4708: {href => '/adm/createuser?action=authorreqqueue',
4709: text => 'Result',
4710: help => 'Domain_Role_Approvals'});
4711: $bread_crumbs_component = 'Authoring request result';
4712: }
4713: $args = { bread_crumbs => $brcrum,
4714: bread_crumbs_component => $bread_crumbs_component};
1.391 raeburn 4715: my $js = &usernamerequest_javascript();
4716: $r->print(&header(&add_script($js),$args));
1.362 raeburn 4717: if (!exists($env{'form.state'})) {
4718: $r->print(&Apache::loncoursequeueadmin::display_queued_requests('requestauthor',
4719: $env{'request.role.domain'}));
4720: } elsif ($env{'form.state'} eq 'done') {
4721: $r->print('<h3>'.&mt('Authoring request processing').'</h3>'."\n");
4722: $r->print(&Apache::loncoursequeueadmin::update_request_queue('requestauthor',
4723: $env{'request.role.domain'}));
4724: }
1.391 raeburn 4725: } elsif (($env{'form.action'} eq 'processusernamereq') &&
4726: ($permission->{'cusr'}) &&
4727: (&Apache::lonnet::allowed('cau',$env{'request.role.domain'}))) {
4728: push(@{$brcrum},
4729: {href => '/adm/createuser?action=processusernamereq',
4730: text => 'LON-CAPA account requests',
4731: help => 'Domain_Username_Approvals'});
4732: $bread_crumbs_component = 'Account requests';
4733: if ($env{'form.state'} eq 'done') {
4734: push(@{$brcrum},
4735: {href => '/adm/createuser?action=usernamereqqueue',
4736: text => 'Result',
4737: help => 'Domain_Username_Approvals'});
4738: $bread_crumbs_component = 'LON-CAPA account request result';
4739: }
4740: $args = { bread_crumbs => $brcrum,
4741: bread_crumbs_component => $bread_crumbs_component};
4742: my $js = &usernamerequest_javascript();
4743: $r->print(&header(&add_script($js),$args));
4744: if (!exists($env{'form.state'})) {
4745: $r->print(&Apache::loncoursequeueadmin::display_queued_requests('requestusername',
4746: $env{'request.role.domain'}));
4747: } elsif ($env{'form.state'} eq 'done') {
4748: $r->print('<h3>'.&mt('LON-CAPA account request processing').'</h3>'."\n");
4749: $r->print(&Apache::loncoursequeueadmin::update_request_queue('requestusername',
4750: $env{'request.role.domain'}));
4751: }
4752: } elsif (($env{'form.action'} eq 'displayuserreq') &&
4753: ($permission->{'cusr'})) {
4754: my $dom = $env{'form.domain'};
4755: my $uname = $env{'form.username'};
4756: my $warning;
4757: if (($dom =~ /^$match_domain$/) && (&Apache::lonnet::domain($dom) ne '')) {
4758: if (($dom eq $env{'request.role.domain'}) && (&Apache::lonnet::allowed('ccc',$dom))) {
4759: if (($uname =~ /^$match_username$/) && ($env{'form.queue'} eq 'approval')) {
4760: my $uhome = &Apache::lonnet::homeserver($uname,$dom);
4761: if ($uhome eq 'no_host') {
4762: my $queue = $env{'form.queue'};
4763: my $reqkey = &escape($uname).'_'.$queue;
4764: my $namespace = 'usernamequeue';
4765: my $domconfig = &Apache::lonnet::get_domainconfiguser($dom);
4766: my %queued =
4767: &Apache::lonnet::get($namespace,[$reqkey],$dom,$domconfig);
4768: unless ($queued{$reqkey}) {
4769: $warning = &mt('No information was found for this LON-CAPA account request.');
4770: }
4771: } else {
4772: $warning = &mt('A LON-CAPA account already exists for the requested username and domain.');
4773: }
4774: } else {
4775: $warning = &mt('LON-CAPA account request status check is for an invalid username.');
4776: }
4777: } else {
4778: $warning = &mt('You do not have rights to view LON-CAPA account requests in the domain specified.');
4779: }
4780: } else {
4781: $warning = &mt('LON-CAPA account request status check is for an invalid domain.');
4782: }
4783: my $args = { only_body => 1 };
4784: $r->print(&header(undef,$args).
4785: '<h3>'.&mt('LON-CAPA Account Request Details').'</h3>');
4786: if ($warning ne '') {
4787: $r->print('<div class="LC_warning">'.$warning.'</div>');
4788: } else {
4789: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
4790: my $domconfiguser = &Apache::lonnet::get_domainconfiguser($dom);
4791: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
4792: if (ref($domconfig{'usercreation'}) eq 'HASH') {
4793: if (ref($domconfig{'usercreation'}{'cancreate'}) eq 'HASH') {
4794: if (ref($domconfig{'usercreation'}{'cancreate'}{'emailusername'}) eq 'HASH') {
4795: my %info =
4796: &Apache::lonnet::get('nohist_requestedusernames',[$uname],$dom,$domconfiguser);
4797: if (ref($info{$uname}) eq 'HASH') {
1.396 raeburn 4798: my $usertype = $info{$uname}{'inststatus'};
4799: unless ($usertype) {
4800: $usertype = 'default';
4801: }
4802: if (ref($domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}) eq 'HASH') {
4803: if ((ref($infofields) eq 'ARRAY') && (ref($infotitles) eq 'HASH')) {
4804: $r->print('<div>'.&Apache::lonhtmlcommon::start_pick_box());
4805: my ($num,$count,$showstatus);
4806: $count = scalar(keys(%{$domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}}));
4807: unless ($usertype eq 'default') {
4808: my ($othertitle,$usertypes,$types) =
4809: &Apache::loncommon::sorted_inst_types($dom);
4810: if (ref($usertypes) eq 'HASH') {
4811: if ($usertypes->{$usertype}) {
4812: $showstatus = $usertypes->{$usertype};
4813: $count ++;
4814: }
4815: }
4816: }
4817: foreach my $field (@{$infofields}) {
4818: next unless ($domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}{$field});
4819: next unless ($infotitles->{$field});
4820: $r->print(&Apache::lonhtmlcommon::row_title($infotitles->{$field}).
4821: $info{$uname}{$field});
4822: $num ++;
4823: if ($count == $num) {
4824: $r->print(&Apache::lonhtmlcommon::row_closure(1));
4825: } else {
4826: $r->print(&Apache::lonhtmlcommon::row_closure());
4827: }
4828: }
4829: if ($showstatus) {
4830: $r->print(&Apache::lonhtmlcommon::row_title(&mt('Status type (self-reported)')).
4831: $showstatus.
4832: &Apache::lonhtmlcommon::row_closure(1));
1.391 raeburn 4833: }
1.396 raeburn 4834: $r->print(&Apache::lonhtmlcommon::end_pick_box().'</div>');
1.391 raeburn 4835: }
4836: }
4837: }
4838: }
4839: }
4840: }
4841: $r->print(&close_popup_form());
4842: }
1.207 raeburn 4843: } elsif (($env{'form.action'} eq 'listusers') &&
4844: ($permission->{'view'} || $permission->{'cusr'})) {
1.202 raeburn 4845: if ($env{'form.phase'} eq 'bulkchange') {
1.351 raeburn 4846: push(@{$brcrum},
4847: {href => '/adm/createuser?action=listusers',
4848: text => "List Users"},
4849: {href => "/adm/createuser",
4850: text => "Result",
4851: help => 'Course_View_Class_List'});
4852: $bread_crumbs_component = 'Update Users';
4853: $args = {bread_crumbs => $brcrum,
4854: bread_crumbs_component => $bread_crumbs_component};
4855: $r->print(&header(undef,$args));
1.202 raeburn 4856: my $setting = $env{'form.roletype'};
4857: my $choice = $env{'form.bulkaction'};
4858: if ($permission->{'cusr'}) {
1.336 raeburn 4859: &Apache::lonuserutils::update_user_list($r,$context,$setting,$choice,$crstype);
1.221 raeburn 4860: } else {
4861: $r->print(&mt('You are not authorized to make bulk changes to user roles'));
1.223 raeburn 4862: $r->print('<p><a href="/adm/createuser?action=listusers">'.&mt('Display User Lists').'</a>');
1.202 raeburn 4863: }
4864: } else {
1.351 raeburn 4865: push(@{$brcrum},
4866: {href => '/adm/createuser?action=listusers',
4867: text => "List Users",
4868: help => 'Course_View_Class_List'});
4869: $bread_crumbs_component = 'List Users';
4870: $args = {bread_crumbs => $brcrum,
4871: bread_crumbs_component => $bread_crumbs_component};
1.202 raeburn 4872: my ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles);
4873: my $formname = 'studentform';
1.364 raeburn 4874: my $hidecall = "hide_searching();";
1.321 raeburn 4875: if (($context eq 'domain') && (($env{'form.roletype'} eq 'course') ||
4876: ($env{'form.roletype'} eq 'community'))) {
4877: if ($env{'form.roletype'} eq 'course') {
4878: ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles) =
4879: &Apache::lonuserutils::courses_selector($env{'request.role.domain'},
4880: $formname);
4881: } elsif ($env{'form.roletype'} eq 'community') {
4882: $cb_jscript =
4883: &Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
4884: my %elements = (
4885: coursepick => 'radio',
4886: coursetotal => 'text',
4887: courselist => 'text',
4888: );
4889: $jscript = &Apache::lonhtmlcommon::set_form_elements(\%elements);
4890: }
1.364 raeburn 4891: $jscript .= &verify_user_display($context)."\n".
4892: &Apache::loncommon::check_uncheck_jscript();
1.202 raeburn 4893: my $js = &add_script($jscript).$cb_jscript;
4894: my $loadcode =
4895: &Apache::lonuserutils::course_selector_loadcode($formname);
4896: if ($loadcode ne '') {
1.364 raeburn 4897: $args->{add_entries} = {onload => "$loadcode;$hidecall"};
4898: } else {
4899: $args->{add_entries} = {onload => $hidecall};
1.202 raeburn 4900: }
1.351 raeburn 4901: $r->print(&header($js,$args));
1.191 raeburn 4902: } else {
1.364 raeburn 4903: $args->{add_entries} = {onload => $hidecall};
4904: $jscript = &verify_user_display($context).
4905: &Apache::loncommon::check_uncheck_jscript();
4906: $r->print(&header(&add_script($jscript),$args));
1.191 raeburn 4907: }
1.202 raeburn 4908: &Apache::lonuserutils::print_userlist($r,undef,$permission,$context,
1.375 raeburn 4909: $formname,$totcodes,$codetitles,$idlist,$idlist_titles,
4910: $showcredits);
1.191 raeburn 4911: }
1.213 raeburn 4912: } elsif ($env{'form.action'} eq 'drop' && $permission->{'cusr'}) {
1.318 raeburn 4913: my $brtext;
4914: if ($crstype eq 'Community') {
4915: $brtext = 'Drop Members';
4916: } else {
4917: $brtext = 'Drop Students';
4918: }
1.351 raeburn 4919: push(@{$brcrum},
4920: {href => '/adm/createuser?action=drop',
4921: text => $brtext,
4922: help => 'Course_Drop_Student'});
4923: if ($env{'form.state'} eq 'done') {
4924: push(@{$brcrum},
4925: {href=>'/adm/createuser?action=drop',
4926: text=>"Result"});
4927: }
4928: $bread_crumbs_component = $brtext;
4929: $args = {bread_crumbs => $brcrum,
4930: bread_crumbs_component => $bread_crumbs_component};
4931: $r->print(&header(undef,$args));
1.213 raeburn 4932: if (!exists($env{'form.state'})) {
1.318 raeburn 4933: &Apache::lonuserutils::print_drop_menu($r,$context,$permission,$crstype);
1.213 raeburn 4934: } elsif ($env{'form.state'} eq 'done') {
4935: &Apache::lonuserutils::update_user_list($r,$context,undef,
4936: $env{'form.action'});
4937: }
1.202 raeburn 4938: } elsif ($env{'form.action'} eq 'dateselect') {
4939: if ($permission->{'cusr'}) {
1.351 raeburn 4940: $r->print(&header(undef,{'no_nav_bar' => 1}).
1.375 raeburn 4941: &Apache::lonuserutils::date_section_selector($context,$permission,
4942: $crstype,$showcredits));
1.202 raeburn 4943: } else {
1.351 raeburn 4944: $r->print(&header(undef,{'no_nav_bar' => 1}).
4945: '<span class="LC_error">'.&mt('You do not have permission to modify dates or sections for users').'</span>');
1.202 raeburn 4946: }
1.237 raeburn 4947: } elsif ($env{'form.action'} eq 'selfenroll') {
1.398 raeburn 4948: if ($permission->{selfenrolladmin}) {
4949: my $cid = $env{'request.course.id'};
4950: my $cdom = $env{'course.'.$cid.'.domain'};
4951: my $cnum = $env{'course.'.$cid.'.num'};
4952: my %currsettings = (
4953: selfenroll_types => $env{'course.'.$cid.'.internal.selfenroll_types'},
4954: selfenroll_registered => $env{'course.'.$cid.'.internal.selfenroll_registered'},
4955: selfenroll_section => $env{'course.'.$cid.'.internal.selfenroll_section'},
4956: selfenroll_notifylist => $env{'course.'.$cid.'.internal.selfenroll_notifylist'},
4957: selfenroll_approval => $env{'course.'.$cid.'.internal.selfenroll_approval'},
4958: selfenroll_limit => $env{'course.'.$cid.'.internal.selfenroll_limit'},
4959: selfenroll_cap => $env{'course.'.$cid.'.internal.selfenroll_cap'},
4960: selfenroll_start_date => $env{'course.'.$cid.'.internal.selfenroll_start_date'},
4961: selfenroll_end_date => $env{'course.'.$cid.'.internal.selfenroll_end_date'},
4962: selfenroll_start_access => $env{'course.'.$cid.'.internal.selfenroll_start_access'},
4963: selfenroll_end_access => $env{'course.'.$cid.'.internal.selfenroll_end_access'},
4964: default_enrollment_start_date => $env{'course.'.$cid.'.default_enrollment_start_date'},
4965: default_enrollment_end_date => $env{'course.'.$cid.'.default_enrollment_end_date'},
1.400 raeburn 4966: uniquecode => $env{'course.'.$cid.'.internal.uniquecode'},
1.398 raeburn 4967: );
4968: push(@{$brcrum},
4969: {href => '/adm/createuser?action=selfenroll',
4970: text => "Configure Self-enrollment",
4971: help => 'Course_Self_Enrollment'});
4972: if (!exists($env{'form.state'})) {
4973: $args = { bread_crumbs => $brcrum,
4974: bread_crumbs_component => 'Configure Self-enrollment'};
4975: $r->print(&header(undef,$args));
4976: $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n");
4977: &print_selfenroll_menu($r,'course',$cid,$cdom,$cnum,\%currsettings);
4978: } elsif ($env{'form.state'} eq 'done') {
4979: push (@{$brcrum},
4980: {href=>'/adm/createuser?action=selfenroll',
4981: text=>"Result"});
4982: $args = { bread_crumbs => $brcrum,
4983: bread_crumbs_component => 'Self-enrollment result'};
4984: $r->print(&header(undef,$args));
4985: $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n");
1.400 raeburn 4986: &update_selfenroll_config($r,$cid,$cdom,$cnum,$context,$crstype,\%currsettings);
1.398 raeburn 4987: }
4988: } else {
4989: $r->print(&header(undef,{'no_nav_bar' => 1}).
4990: '<span class="LC_error">'.&mt('You do not have permission to configure self-enrollment').'</span>');
1.237 raeburn 4991: }
1.277 raeburn 4992: } elsif ($env{'form.action'} eq 'selfenrollqueue') {
1.406.2.6 raeburn 4993: if ($permission->{selfenrolladmin}) {
1.351 raeburn 4994: push(@{$brcrum},
4995: {href => '/adm/createuser?action=selfenrollqueue',
1.406.2.6 raeburn 4996: text => 'Enrollment requests',
1.351 raeburn 4997: help => 'Course_Self_Enrollment'});
1.406.2.6 raeburn 4998: $bread_crumbs_component = 'Enrollment requests';
4999: if ($env{'form.state'} eq 'done') {
5000: push(@{$brcrum},
5001: {href => '/adm/createuser?action=selfenrollqueue',
5002: text => 'Result',
5003: help => 'Course_Self_Enrollment'});
5004: $bread_crumbs_component = 'Enrollment result';
5005: }
5006: $args = { bread_crumbs => $brcrum,
5007: bread_crumbs_component => $bread_crumbs_component};
5008: $r->print(&header(undef,$args));
5009: my $cid = $env{'request.course.id'};
5010: my $cdom = $env{'course.'.$cid.'.domain'};
5011: my $cnum = $env{'course.'.$cid.'.num'};
5012: my $coursedesc = $env{'course.'.$cid.'.description'};
5013: if (!exists($env{'form.state'})) {
5014: $r->print('<h3>'.&mt('Pending enrollment requests').'</h3>'."\n");
5015: $r->print(&Apache::loncoursequeueadmin::display_queued_requests($context,
5016: $cdom,$cnum));
5017: } elsif ($env{'form.state'} eq 'done') {
5018: $r->print('<h3>'.&mt('Enrollment request processing').'</h3>'."\n");
5019: $r->print(&Apache::loncoursequeueadmin::update_request_queue($context,
5020: $cdom,$cnum,$coursedesc));
5021: }
5022: } else {
5023: $r->print(&header(undef,{'no_nav_bar' => 1}).
5024: '<span class="LC_error">'.&mt('You do not have permission to manage self-enrollment').'</span>');
1.277 raeburn 5025: }
1.239 raeburn 5026: } elsif ($env{'form.action'} eq 'changelogs') {
1.406.2.6 raeburn 5027: if ($permission->{cusr} || $permission->{view}) {
5028: &print_userchangelogs_display($r,$context,$permission,$brcrum);
5029: } else {
5030: $r->print(&header(undef,{'no_nav_bar' => 1}).
5031: '<span class="LC_error">'.&mt('You do not have permission to view change logs').'</span>');
5032: }
1.406.2.10 raeburn 5033: } elsif ($env{'form.action'} eq 'helpdesk') {
5034: if (($permission->{'owner'}) || ($permission->{'co-owner'})) {
5035: if ($env{'form.state'} eq 'process') {
5036: if ($permission->{'owner'}) {
5037: &update_helpdeskaccess($r,$permission,$brcrum);
5038: } else {
5039: &print_helpdeskaccess_display($r,$permission,$brcrum);
5040: }
5041: } else {
5042: &print_helpdeskaccess_display($r,$permission,$brcrum);
5043: }
5044: } else {
5045: $r->print(&header(undef,{'no_nav_bar' => 1}).
5046: '<span class="LC_error">'.&mt('You do not have permission to view helpdesk access').'</span>');
5047: }
1.190 raeburn 5048: } else {
1.351 raeburn 5049: $bread_crumbs_component = 'User Management';
5050: $args = { bread_crumbs => $brcrum,
5051: bread_crumbs_component => $bread_crumbs_component};
5052: $r->print(&header(undef,$args));
1.318 raeburn 5053: $r->print(&print_main_menu($permission,$context,$crstype));
1.190 raeburn 5054: }
1.351 raeburn 5055: $r->print(&Apache::loncommon::end_page());
1.190 raeburn 5056: return OK;
5057: }
5058:
5059: sub header {
1.351 raeburn 5060: my ($jscript,$args) = @_;
1.190 raeburn 5061: my $start_page;
1.351 raeburn 5062: if (ref($args) eq 'HASH') {
5063: $start_page=&Apache::loncommon::start_page('User Management',$jscript,$args);
1.190 raeburn 5064: } else {
1.351 raeburn 5065: $start_page=&Apache::loncommon::start_page('User Management',$jscript);
1.190 raeburn 5066: }
5067: return $start_page;
5068: }
1.2 www 5069:
1.191 raeburn 5070: sub add_script {
5071: my ($js) = @_;
1.301 bisitz 5072: return '<script type="text/javascript">'."\n"
5073: .'// <![CDATA['."\n"
5074: .$js."\n"
5075: .'// ]]>'."\n"
5076: .'</script>'."\n";
1.191 raeburn 5077: }
5078:
1.391 raeburn 5079: sub usernamerequest_javascript {
5080: my $js = <<ENDJS;
5081:
5082: function openusernamereqdisplay(dom,uname,queue) {
5083: var url = '/adm/createuser?action=displayuserreq';
5084: url += '&domain='+dom+'&username='+uname+'&queue='+queue;
5085: var title = 'Account_Request_Browser';
5086: var options = 'scrollbars=1,resizable=1,menubar=0';
5087: options += ',width=700,height=600';
5088: var stdeditbrowser = open(url,title,options,'1');
5089: stdeditbrowser.focus();
5090: return;
5091: }
5092:
5093: ENDJS
5094: }
5095:
5096: sub close_popup_form {
5097: my $close= &mt('Close Window');
5098: return << "END";
5099: <p><form name="displayreq" action="" method="post">
5100: <input type="button" name="closeme" value="$close" onclick="javascript:self.close();" />
5101: </form></p>
5102: END
5103: }
5104:
1.202 raeburn 5105: sub verify_user_display {
1.364 raeburn 5106: my ($context) = @_;
1.374 raeburn 5107: my %lt = &Apache::lonlocal::texthash (
5108: course => 'course(s): description, section(s), status',
5109: community => 'community(s): description, section(s), status',
5110: author => 'author',
5111: );
1.364 raeburn 5112: my $photos;
5113: if (($context eq 'course') && $env{'request.course.id'}) {
5114: $photos = $env{'course.'.$env{'request.course.id'}.'.internal.showphoto'};
5115: }
1.202 raeburn 5116: my $output = <<"END";
5117:
1.364 raeburn 5118: function hide_searching() {
5119: if (document.getElementById('searching')) {
5120: document.getElementById('searching').style.display = 'none';
5121: }
5122: return;
5123: }
5124:
1.202 raeburn 5125: function display_update() {
5126: document.studentform.action.value = 'listusers';
5127: document.studentform.phase.value = 'display';
5128: document.studentform.submit();
5129: }
5130:
1.364 raeburn 5131: function updateCols(caller) {
5132: var context = '$context';
5133: var photos = '$photos';
5134: if (caller == 'Status') {
1.374 raeburn 5135: if ((context == 'domain') &&
5136: ((document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'course') ||
5137: (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community'))) {
1.364 raeburn 5138: document.getElementById('showcolstatus').checked = false;
5139: document.getElementById('showcolstatus').disabled = 'disabled';
5140: document.getElementById('showcolstart').checked = false;
5141: document.getElementById('showcolend').checked = false;
1.374 raeburn 5142: } else {
5143: if (document.studentform.Status.options[document.studentform.Status.selectedIndex].value == 'Any') {
5144: document.getElementById('showcolstatus').checked = true;
5145: document.getElementById('showcolstatus').disabled = '';
5146: document.getElementById('showcolstart').checked = true;
5147: document.getElementById('showcolend').checked = true;
5148: } else {
5149: document.getElementById('showcolstatus').checked = false;
5150: document.getElementById('showcolstatus').disabled = 'disabled';
5151: document.getElementById('showcolstart').checked = false;
5152: document.getElementById('showcolend').checked = false;
5153: }
1.364 raeburn 5154: }
5155: }
5156: if (caller == 'output') {
5157: if (photos == 1) {
5158: if (document.getElementById('showcolphoto')) {
5159: var photoitem = document.getElementById('showcolphoto');
5160: if (document.studentform.output.options[document.studentform.output.selectedIndex].value == 'html') {
5161: photoitem.checked = true;
5162: photoitem.disabled = '';
5163: } else {
5164: photoitem.checked = false;
5165: photoitem.disabled = 'disabled';
5166: }
5167: }
5168: }
5169: }
5170: if (caller == 'showrole') {
1.371 raeburn 5171: if ((document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'Any') ||
5172: (document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'cr')) {
1.364 raeburn 5173: document.getElementById('showcolrole').checked = true;
5174: document.getElementById('showcolrole').disabled = '';
5175: } else {
5176: document.getElementById('showcolrole').checked = false;
5177: document.getElementById('showcolrole').disabled = 'disabled';
5178: }
1.374 raeburn 5179: if (context == 'domain') {
1.382 raeburn 5180: var quotausageshow = 0;
1.374 raeburn 5181: if ((document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'course') ||
5182: (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community')) {
5183: document.getElementById('showcolstatus').checked = false;
5184: document.getElementById('showcolstatus').disabled = 'disabled';
5185: document.getElementById('showcolstart').checked = false;
5186: document.getElementById('showcolend').checked = false;
5187: } else {
5188: if (document.studentform.Status.options[document.studentform.Status.selectedIndex].value == 'Any') {
5189: document.getElementById('showcolstatus').checked = true;
5190: document.getElementById('showcolstatus').disabled = '';
5191: document.getElementById('showcolstart').checked = true;
5192: document.getElementById('showcolend').checked = true;
5193: }
5194: }
5195: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'domain') {
5196: document.getElementById('showcolextent').disabled = 'disabled';
5197: document.getElementById('showcolextent').checked = 'false';
5198: document.getElementById('showextent').style.display='none';
5199: document.getElementById('showcoltextextent').innerHTML = '';
1.382 raeburn 5200: if ((document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'au') ||
5201: (document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'Any')) {
5202: if (document.getElementById('showcolauthorusage')) {
5203: document.getElementById('showcolauthorusage').disabled = '';
5204: }
5205: if (document.getElementById('showcolauthorquota')) {
5206: document.getElementById('showcolauthorquota').disabled = '';
5207: }
5208: quotausageshow = 1;
5209: }
1.374 raeburn 5210: } else {
5211: document.getElementById('showextent').style.display='block';
5212: document.getElementById('showextent').style.textAlign='left';
5213: document.getElementById('showextent').style.textFace='normal';
5214: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'author') {
5215: document.getElementById('showcolextent').disabled = '';
5216: document.getElementById('showcolextent').checked = 'true';
5217: document.getElementById('showcoltextextent').innerHTML="$lt{'author'}";
5218: } else {
5219: document.getElementById('showcolextent').disabled = '';
5220: document.getElementById('showcolextent').checked = 'true';
5221: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community') {
5222: document.getElementById('showcoltextextent').innerHTML="$lt{'community'}";
5223: } else {
5224: document.getElementById('showcoltextextent').innerHTML="$lt{'course'}";
5225: }
5226: }
5227: }
1.382 raeburn 5228: if (quotausageshow == 0) {
5229: if (document.getElementById('showcolauthorusage')) {
5230: document.getElementById('showcolauthorusage').checked = false;
5231: document.getElementById('showcolauthorusage').disabled = 'disabled';
5232: }
5233: if (document.getElementById('showcolauthorquota')) {
5234: document.getElementById('showcolauthorquota').checked = false;
5235: document.getElementById('showcolauthorquota').disabled = 'disabled';
5236: }
5237: }
1.374 raeburn 5238: }
1.364 raeburn 5239: }
5240: return;
5241: }
5242:
1.202 raeburn 5243: END
5244: return $output;
5245:
5246: }
5247:
1.190 raeburn 5248: ###############################################################
5249: ###############################################################
5250: # Menu Phase One
5251: sub print_main_menu {
1.318 raeburn 5252: my ($permission,$context,$crstype) = @_;
5253: my $linkcontext = $context;
5254: my $stuterm = lc(&Apache::lonnet::plaintext('st',$crstype));
5255: if (($context eq 'course') && ($crstype eq 'Community')) {
5256: $linkcontext = lc($crstype);
5257: $stuterm = 'Members';
5258: }
1.208 raeburn 5259: my %links = (
1.298 droeschl 5260: domain => {
5261: upload => 'Upload a File of Users',
5262: singleuser => 'Add/Modify a User',
5263: listusers => 'Manage Users',
5264: },
5265: author => {
5266: upload => 'Upload a File of Co-authors',
5267: singleuser => 'Add/Modify a Co-author',
5268: listusers => 'Manage Co-authors',
5269: },
5270: course => {
5271: upload => 'Upload a File of Course Users',
5272: singleuser => 'Add/Modify a Course User',
1.354 www 5273: listusers => 'List and Modify Multiple Course Users',
1.298 droeschl 5274: },
1.318 raeburn 5275: community => {
5276: upload => 'Upload a File of Community Users',
5277: singleuser => 'Add/Modify a Community User',
1.354 www 5278: listusers => 'List and Modify Multiple Community Users',
1.318 raeburn 5279: },
5280: );
5281: my %linktitles = (
5282: domain => {
5283: singleuser => 'Add a user to the domain, and/or a course or community in the domain.',
5284: listusers => 'Show and manage users in this domain.',
5285: },
5286: author => {
5287: singleuser => 'Add a user with a co- or assistant author role.',
5288: listusers => 'Show and manage co- or assistant authors.',
5289: },
5290: course => {
5291: singleuser => 'Add a user with a certain role to this course.',
5292: listusers => 'Show and manage users in this course.',
5293: },
5294: community => {
5295: singleuser => 'Add a user with a certain role to this community.',
5296: listusers => 'Show and manage users in this community.',
5297: },
1.298 droeschl 5298: );
1.406.2.6 raeburn 5299: if ($linkcontext eq 'domain') {
5300: unless ($permission->{'cusr'}) {
5301: $links{'domain'}{'singleuser'} = 'View a User';
5302: $linktitles{'domain'}{'singleuser'} = 'View information about a user in the domain';
5303: }
5304: } elsif ($linkcontext eq 'course') {
5305: unless ($permission->{'cusr'}) {
5306: $links{'course'}{'singleuser'} = 'View a Course User';
5307: $linktitles{'course'}{'singleuser'} = 'View information about a user in this course';
5308: $links{'course'}{'listusers'} = 'List Course Users';
5309: $linktitles{'course'}{'listusers'} = 'Show information about users in this course';
5310: }
5311: } elsif ($linkcontext eq 'community') {
5312: unless ($permission->{'cusr'}) {
5313: $links{'community'}{'singleuser'} = 'View a Community User';
5314: $linktitles{'community'}{'singleuser'} = 'View information about a user in this community';
5315: $links{'community'}{'listusers'} = 'List Community Users';
5316: $linktitles{'community'}{'listusers'} = 'Show information about users in this community';
5317: }
5318: }
1.298 droeschl 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',
1.406.2.6 raeburn 5327: permission => ($permission->{'view'} || $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.406.2.5 raeburn 5357:
1.265 mielkec 5358: if ($context eq 'domain'){
1.406.2.5 raeburn 5359: push(@{ $menu[0]->{items} }, # Single Users
5360: {
5361: linktext => 'User Access Log',
5362: icon => 'document-properties.png',
1.406.2.8 raeburn 5363: #help => 'Domain_User_Access_Logs',
1.406.2.5 raeburn 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',
1.406.2.6 raeburn 5400: permission => ($permission->{'cusr'} || $permission->{'view'}),
1.363 raeburn 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: );
5420:
5421: my %linktitle = (
5422: 'Course' => {
5423: single => 'Add a user with the role of student to this course',
5424: drop => 'Remove a student from this course.',
5425: groups => 'Manage course groups',
5426: },
5427: 'Community' => {
5428: single => 'Add a user with the role of member to this community',
5429: drop => 'Remove a member from this community.',
5430: groups => 'Manage community groups',
5431: },
5432: );
5433:
1.298 droeschl 5434: push(@{ $menu[0]->{items} }, #Category: Single Users
5435: {
1.318 raeburn 5436: linktext => $linktext{$crstype}{'single'},
1.298 droeschl 5437: #help => 'Course_Add_Student',
5438: icon => 'list-add.png',
5439: url => '/adm/createuser?action=singlestudent',
5440: permission => $permission->{'cusr'},
1.318 raeburn 5441: linktitle => $linktitle{$crstype}{'single'},
1.298 droeschl 5442: },
5443: );
5444:
5445: push(@{ $menu[1]->{items} }, #Category: Multiple Users
5446: {
1.318 raeburn 5447: linktext => $linktext{$crstype}{'drop'},
1.298 droeschl 5448: icon => 'edit-undo.png',
5449: #help => 'Course_Drop_Student',
5450: url => '/adm/createuser?action=drop',
5451: permission => $permission->{'cusr'},
1.318 raeburn 5452: linktitle => $linktitle{$crstype}{'drop'},
1.298 droeschl 5453: },
5454: );
5455: push(@{ $menu[2]->{items} }, #Category: Administration
1.406.2.11 raeburn 5456: {
5457: linktext => 'Helpdesk Access',
5458: icon => 'helpdesk-access.png',
5459: #help => 'Course_Helpdesk_Access',
5460: url => '/adm/createuser?action=helpdesk',
5461: permission => ($permission->{'owner'} || $permission->{'co-owner'}),
5462: linktitle => 'Helpdesk access options',
5463: },
5464: {
1.298 droeschl 5465: linktext => 'Custom Roles',
5466: icon => 'emblem-photos.png',
5467: #help => 'Course_Editing_Custom_Roles',
5468: url => '/adm/createuser?action=custom',
5469: permission => $permission->{'custom'},
5470: linktitle => 'Configure a custom role.',
5471: },
5472: {
1.318 raeburn 5473: linktext => $linktext{$crstype}{'groups'},
1.333 wenzelju 5474: icon => 'grps.png',
1.298 droeschl 5475: #help => 'Course_Manage_Group',
5476: url => '/adm/coursegroups?refpage=cusr',
5477: permission => $permission->{'grp_manage'},
1.318 raeburn 5478: linktitle => $linktitle{$crstype}{'groups'},
1.298 droeschl 5479: },
5480: {
1.328 wenzelju 5481: linktext => 'Change Log',
1.298 droeschl 5482: icon => 'document-properties.png',
5483: #help => 'Course_User_Logs',
5484: url => '/adm/createuser?action=changelogs',
1.406.2.6 raeburn 5485: permission => ($permission->{'view'} || $permission->{'cusr'}),
1.298 droeschl 5486: linktitle => 'View change log.',
5487: },
5488: );
1.277 raeburn 5489: if ($env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_approval'}) {
1.298 droeschl 5490: push(@{ $menu[2]->{items} },
1.398 raeburn 5491: {
1.298 droeschl 5492: linktext => 'Enrollment Requests',
5493: icon => 'selfenrl-queue.png',
5494: #help => 'Course_Approve_Selfenroll',
5495: url => '/adm/createuser?action=selfenrollqueue',
1.398 raeburn 5496: permission => $permission->{'selfenrolladmin'},
1.298 droeschl 5497: linktitle =>'Approve or reject enrollment requests.',
5498: },
5499: );
1.277 raeburn 5500: }
1.298 droeschl 5501:
1.265 mielkec 5502: if (!exists($permission->{'cusr_section'})){
1.320 raeburn 5503: if ($crstype ne 'Community') {
5504: push(@{ $menu[2]->{items} },
5505: {
5506: linktext => 'Automated Enrollment',
5507: icon => 'roles.png',
5508: #help => 'Course_Automated_Enrollment',
5509: permission => (&Apache::lonnet::auto_run($cnum,$cdom)
1.406.2.6 raeburn 5510: && (($permission->{'cusr'}) ||
5511: ($permission->{'view'}))),
1.320 raeburn 5512: url => '/adm/populate',
5513: linktitle => 'Automated enrollment manager.',
5514: }
5515: );
5516: }
5517: push(@{ $menu[2]->{items} },
1.298 droeschl 5518: {
5519: linktext => 'User Self-Enrollment',
1.342 wenzelju 5520: icon => 'self_enroll.png',
1.298 droeschl 5521: #help => 'Course_Self_Enrollment',
5522: url => '/adm/createuser?action=selfenroll',
1.398 raeburn 5523: permission => $permission->{'selfenrolladmin'},
1.317 bisitz 5524: linktitle => 'Configure user self-enrollment.',
1.298 droeschl 5525: },
5526: );
5527: }
1.363 raeburn 5528: } elsif ($context eq 'author') {
1.370 raeburn 5529: push(@{ $menu[2]->{items} }, #Category: Administration
1.363 raeburn 5530: {
5531: linktext => 'Change Log',
5532: icon => 'document-properties.png',
5533: #help => 'Course_User_Logs',
5534: url => '/adm/createuser?action=changelogs',
5535: permission => $permission->{'cusr'},
5536: linktitle => 'View change log.',
5537: },
1.370 raeburn 5538: );
1.363 raeburn 5539: }
5540: return Apache::lonhtmlcommon::generate_menu(@menu);
1.250 raeburn 5541: # { text => 'View Log-in History',
5542: # help => 'Course_User_Logins',
5543: # action => 'logins',
5544: # permission => $permission->{'cusr'},
5545: # });
1.190 raeburn 5546: }
5547:
1.189 albertel 5548: sub restore_prev_selections {
5549: my %saveable_parameters = ('srchby' => 'scalar',
5550: 'srchin' => 'scalar',
5551: 'srchtype' => 'scalar',
5552: );
5553: &Apache::loncommon::store_settings('user','user_picker',
5554: \%saveable_parameters);
5555: &Apache::loncommon::restore_settings('user','user_picker',
5556: \%saveable_parameters);
5557: }
5558:
1.237 raeburn 5559: sub print_selfenroll_menu {
1.406.2.6 raeburn 5560: my ($r,$context,$cid,$cdom,$cnum,$currsettings,$additional,$readonly) = @_;
1.322 raeburn 5561: my $crstype = &Apache::loncommon::course_type();
1.398 raeburn 5562: my $formname = 'selfenroll';
1.237 raeburn 5563: my $nolink = 1;
1.398 raeburn 5564: my ($row,$lt) = &Apache::lonuserutils::get_selfenroll_titles();
1.237 raeburn 5565: my $groupslist = &Apache::lonuserutils::get_groupslist();
5566: my $setsec_js =
5567: &Apache::lonuserutils::setsections_javascript($formname,$groupslist);
1.249 raeburn 5568: my %alerts = &Apache::lonlocal::texthash(
5569: acto => 'Activation of self-enrollment was selected for the following domain(s)',
5570: butn => 'but no user types have been checked.',
5571: wilf => "Please uncheck 'activate' or check at least one type.",
5572: );
1.406.2.6 raeburn 5573: my $disabled;
5574: if ($readonly) {
5575: $disabled = ' disabled="disabled"';
5576: }
1.405 damieng 5577: &js_escape(\%alerts);
1.249 raeburn 5578: my $selfenroll_js = <<"ENDSCRIPT";
5579: function update_types(caller,num) {
5580: var delidx = getIndexByName('selfenroll_delete');
5581: var actidx = getIndexByName('selfenroll_activate');
5582: if (caller == 'selfenroll_all') {
5583: var selall;
5584: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
5585: if (document.$formname.selfenroll_all[i].checked) {
5586: selall = document.$formname.selfenroll_all[i].value;
5587: }
5588: }
5589: if (selall == 1) {
5590: if (delidx != -1) {
5591: if (document.$formname.selfenroll_delete.length) {
5592: for (var j=0; j<document.$formname.selfenroll_delete.length; j++) {
5593: document.$formname.selfenroll_delete[j].checked = true;
5594: }
5595: } else {
5596: document.$formname.elements[delidx].checked = true;
5597: }
5598: }
5599: if (actidx != -1) {
5600: if (document.$formname.selfenroll_activate.length) {
5601: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
5602: document.$formname.selfenroll_activate[j].checked = false;
5603: }
5604: } else {
5605: document.$formname.elements[actidx].checked = false;
5606: }
5607: }
5608: document.$formname.selfenroll_newdom.selectedIndex = 0;
5609: }
5610: }
5611: if (caller == 'selfenroll_activate') {
5612: if (document.$formname.selfenroll_activate.length) {
5613: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
5614: if (document.$formname.selfenroll_activate[j].value == num) {
5615: if (document.$formname.selfenroll_activate[j].checked) {
5616: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
5617: if (document.$formname.selfenroll_all[i].value == '1') {
5618: document.$formname.selfenroll_all[i].checked = false;
5619: }
5620: if (document.$formname.selfenroll_all[i].value == '0') {
5621: document.$formname.selfenroll_all[i].checked = true;
5622: }
5623: }
5624: }
5625: }
5626: }
5627: } else {
5628: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
5629: if (document.$formname.selfenroll_all[i].value == '1') {
5630: document.$formname.selfenroll_all[i].checked = false;
5631: }
5632: if (document.$formname.selfenroll_all[i].value == '0') {
5633: document.$formname.selfenroll_all[i].checked = true;
5634: }
5635: }
5636: }
5637: }
5638: if (caller == 'selfenroll_delete') {
5639: if (document.$formname.selfenroll_delete.length) {
5640: for (var j=0; j<document.$formname.selfenroll_delete.length; j++) {
5641: if (document.$formname.selfenroll_delete[j].value == num) {
5642: if (document.$formname.selfenroll_delete[j].checked) {
5643: var delindex = getIndexByName('selfenroll_types_'+num);
5644: if (delindex != -1) {
5645: if (document.$formname.elements[delindex].length) {
5646: for (var k=0; k<document.$formname.elements[delindex].length; k++) {
5647: document.$formname.elements[delindex][k].checked = false;
5648: }
5649: } else {
5650: document.$formname.elements[delindex].checked = false;
5651: }
5652: }
5653: }
5654: }
5655: }
5656: } else {
5657: if (document.$formname.selfenroll_delete.checked) {
5658: var delindex = getIndexByName('selfenroll_types_'+num);
5659: if (delindex != -1) {
5660: if (document.$formname.elements[delindex].length) {
5661: for (var k=0; k<document.$formname.elements[delindex].length; k++) {
5662: document.$formname.elements[delindex][k].checked = false;
5663: }
5664: } else {
5665: document.$formname.elements[delindex].checked = false;
5666: }
5667: }
5668: }
5669: }
5670: }
5671: return;
5672: }
5673:
5674: function validate_types(form) {
5675: var needaction = new Array();
5676: var countfail = 0;
5677: var actidx = getIndexByName('selfenroll_activate');
5678: if (actidx != -1) {
5679: if (document.$formname.selfenroll_activate.length) {
5680: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
5681: var num = document.$formname.selfenroll_activate[j].value;
5682: if (document.$formname.selfenroll_activate[j].checked) {
5683: countfail = check_types(num,countfail,needaction)
5684: }
5685: }
5686: } else {
5687: if (document.$formname.selfenroll_activate.checked) {
1.398 raeburn 5688: var num = document.$formname.selfenroll_activate.value;
1.249 raeburn 5689: countfail = check_types(num,countfail,needaction)
5690: }
5691: }
5692: }
5693: if (countfail > 0) {
5694: var msg = "$alerts{'acto'}\\n";
5695: var loopend = needaction.length -1;
5696: if (loopend > 0) {
5697: for (var m=0; m<loopend; m++) {
5698: msg += needaction[m]+", ";
5699: }
5700: }
5701: msg += needaction[loopend]+"\\n$alerts{'butn'}\\n$alerts{'wilf'}";
5702: alert(msg);
5703: return;
5704: }
5705: setSections(form);
5706: }
5707:
5708: function check_types(num,countfail,needaction) {
5709: var typeidx = getIndexByName('selfenroll_types_'+num);
5710: var count = 0;
5711: if (typeidx != -1) {
5712: if (document.$formname.elements[typeidx].length) {
5713: for (var k=0; k<document.$formname.elements[typeidx].length; k++) {
5714: if (document.$formname.elements[typeidx][k].checked) {
5715: count ++;
5716: }
5717: }
5718: } else {
5719: if (document.$formname.elements[typeidx].checked) {
5720: count ++;
5721: }
5722: }
5723: if (count == 0) {
5724: var domidx = getIndexByName('selfenroll_dom_'+num);
5725: if (domidx != -1) {
5726: var domname = document.$formname.elements[domidx].value;
5727: needaction[countfail] = domname;
5728: countfail ++;
5729: }
5730: }
5731: }
5732: return countfail;
5733: }
5734:
1.398 raeburn 5735: function toggleNotify() {
5736: var selfenrollApproval = 0;
5737: if (document.$formname.selfenroll_approval.length) {
5738: for (var i=0; i<document.$formname.selfenroll_approval.length; i++) {
5739: if (document.$formname.selfenroll_approval[i].checked) {
5740: selfenrollApproval = document.$formname.selfenroll_approval[i].value;
5741: break;
5742: }
5743: }
5744: }
5745: if (document.getElementById('notified')) {
5746: if (selfenrollApproval == 0) {
5747: document.getElementById('notified').style.display='none';
5748: } else {
5749: document.getElementById('notified').style.display='block';
5750: }
5751: }
5752: return;
5753: }
5754:
1.249 raeburn 5755: function getIndexByName(item) {
5756: for (var i=0;i<document.$formname.elements.length;i++) {
5757: if (document.$formname.elements[i].name == item) {
5758: return i;
5759: }
5760: }
5761: return -1;
5762: }
5763: ENDSCRIPT
1.256 raeburn 5764:
1.237 raeburn 5765: my $output = '<script type="text/javascript">'."\n".
1.301 bisitz 5766: '// <![CDATA['."\n".
1.249 raeburn 5767: $setsec_js."\n".$selfenroll_js."\n".
1.301 bisitz 5768: '// ]]>'."\n".
1.237 raeburn 5769: '</script>'."\n".
1.256 raeburn 5770: '<h3>'.$lt->{'selfenroll'}.'</h3>'."\n";
1.400 raeburn 5771:
5772: my $visactions = &cat_visibility();
5773: my ($cathash,%cattype);
5774: my %domconfig = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom);
5775: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
5776: $cathash = $domconfig{'coursecategories'}{'cats'};
5777: $cattype{'auth'} = $domconfig{'coursecategories'}{'auth'};
5778: $cattype{'unauth'} = $domconfig{'coursecategories'}{'unauth'};
1.406 raeburn 5779: if ($cattype{'auth'} eq '') {
5780: $cattype{'auth'} = 'std';
5781: }
5782: if ($cattype{'unauth'} eq '') {
5783: $cattype{'unauth'} = 'std';
5784: }
1.400 raeburn 5785: } else {
5786: $cathash = {};
5787: $cattype{'auth'} = 'std';
5788: $cattype{'unauth'} = 'std';
5789: }
5790: if (($cattype{'auth'} eq 'none') && ($cattype{'unauth'} eq 'none')) {
5791: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
5792: '<br />'.
5793: '<br />'.$visactions->{'take'}.'<ul>'.
5794: '<li>'.$visactions->{'dc_chgconf'}.'</li>'.
5795: '</ul>');
5796: } elsif (($cattype{'auth'} !~ /^(std|domonly)$/) && ($cattype{'unauth'} !~ /^(std|domonly)$/)) {
5797: if ($currsettings->{'uniquecode'}) {
5798: $r->print('<span class="LC_info">'.$visactions->{'vis'}.'</span>');
5799: } else {
5800: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
5801: '<br />'.
5802: '<br />'.$visactions->{'take'}.'<ul>'.
5803: '<li>'.$visactions->{'dc_setcode'}.'</li>'.
5804: '</ul><br />');
5805: }
5806: } else {
5807: my ($visible,$cansetvis,$vismsgs) = &visible_in_stdcat($cdom,$cnum,\%domconfig);
5808: if (ref($visactions) eq 'HASH') {
5809: if ($visible) {
5810: $output .= '<p class="LC_info">'.$visactions->{'vis'}.'</p>';
5811: } else {
5812: $output .= '<p class="LC_warning">'.$visactions->{'miss'}.'</p>'
5813: .$visactions->{'yous'}.
5814: '<p>'.$visactions->{'gen'}.'<br />'.$visactions->{'coca'};
5815: if (ref($vismsgs) eq 'ARRAY') {
5816: $output .= '<br />'.$visactions->{'make'}.'<ul>';
5817: foreach my $item (@{$vismsgs}) {
5818: $output .= '<li>'.$visactions->{$item}.'</li>';
5819: }
5820: $output .= '</ul>';
1.256 raeburn 5821: }
1.400 raeburn 5822: $output .= '</p>';
1.256 raeburn 5823: }
5824: }
5825: }
1.398 raeburn 5826: my $actionhref = '/adm/createuser';
5827: if ($context eq 'domain') {
5828: $actionhref = '/adm/modifycourse';
5829: }
1.400 raeburn 5830:
5831: my %noedit;
5832: unless ($context eq 'domain') {
5833: %noedit = &get_noedit_fields($cdom,$cnum,$crstype,$row);
5834: }
1.398 raeburn 5835: $output .= '<form name="'.$formname.'" method="post" action="'.$actionhref.'">'."\n".
1.256 raeburn 5836: &Apache::lonhtmlcommon::start_pick_box();
1.237 raeburn 5837: if (ref($row) eq 'ARRAY') {
5838: foreach my $item (@{$row}) {
5839: my $title = $item;
5840: if (ref($lt) eq 'HASH') {
5841: $title = $lt->{$item};
5842: }
1.297 bisitz 5843: $output .= &Apache::lonhtmlcommon::row_title($title);
1.237 raeburn 5844: if ($item eq 'types') {
1.398 raeburn 5845: my $curr_types;
5846: if (ref($currsettings) eq 'HASH') {
5847: $curr_types = $currsettings->{'selfenroll_types'};
5848: }
1.400 raeburn 5849: if ($noedit{$item}) {
5850: if ($curr_types eq '*') {
5851: $output .= &mt('Any user in any domain');
5852: } else {
5853: my @entries = split(/;/,$curr_types);
5854: if (@entries > 0) {
5855: $output .= '<ul>';
5856: foreach my $entry (@entries) {
5857: my ($currdom,$typestr) = split(/:/,$entry);
5858: next if ($typestr eq '');
5859: my $domdesc = &Apache::lonnet::domain($currdom);
5860: my @currinsttypes = split(',',$typestr);
5861: my ($othertitle,$usertypes,$types) =
5862: &Apache::loncommon::sorted_inst_types($currdom);
5863: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
5864: $usertypes->{'any'} = &mt('any user');
5865: if (keys(%{$usertypes}) > 0) {
5866: $usertypes->{'other'} = &mt('other users');
5867: }
5868: my @longinsttypes = map { $usertypes->{$_}; } @currinsttypes;
5869: $output .= '<li>'.$domdesc.':'.join(', ',@longinsttypes).'</li>';
5870: }
5871: }
5872: $output .= '</ul>';
5873: } else {
5874: $output .= &mt('None');
5875: }
5876: }
5877: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
5878: next;
5879: }
1.241 raeburn 5880: my $showdomdesc = 1;
5881: my $includeempty = 1;
5882: my $num = 0;
5883: $output .= &Apache::loncommon::start_data_table().
5884: &Apache::loncommon::start_data_table_row()
5885: .'<td colspan="2"><span class="LC_nobreak"><label>'
5886: .&mt('Any user in any domain:')
5887: .' <input type="radio" name="selfenroll_all" value="1" ';
5888: if ($curr_types eq '*') {
5889: $output .= ' checked="checked" ';
5890: }
1.249 raeburn 5891: $output .= 'onchange="javascript:update_types('.
1.406.2.6 raeburn 5892: "'selfenroll_all'".');"'.$disabled.' />'.&mt('Yes').'</label>'.
1.249 raeburn 5893: ' <input type="radio" name="selfenroll_all" value="0" ';
1.241 raeburn 5894: if ($curr_types ne '*') {
5895: $output .= ' checked="checked" ';
5896: }
1.249 raeburn 5897: $output .= ' onchange="javascript:update_types('.
1.406.2.6 raeburn 5898: "'selfenroll_all'".');"'.$disabled.' />'.&mt('No').'</label></td>'.
1.249 raeburn 5899: &Apache::loncommon::end_data_table_row().
5900: &Apache::loncommon::end_data_table().
5901: &mt('Or').'<br />'.
5902: &Apache::loncommon::start_data_table();
1.241 raeburn 5903: my %currdoms;
1.249 raeburn 5904: if ($curr_types eq '') {
1.241 raeburn 5905: $output .= &new_selfenroll_dom_row($cdom,'0');
5906: } elsif ($curr_types ne '*') {
5907: my @entries = split(/;/,$curr_types);
5908: if (@entries > 0) {
5909: foreach my $entry (@entries) {
5910: my ($currdom,$typestr) = split(/:/,$entry);
5911: $currdoms{$currdom} = 1;
5912: my $domdesc = &Apache::lonnet::domain($currdom);
1.249 raeburn 5913: my @currinsttypes = split(',',$typestr);
1.241 raeburn 5914: $output .= &Apache::loncommon::start_data_table_row()
5915: .'<td valign="top"><span class="LC_nobreak">'.&mt('Domain:').'<b>'
5916: .' '.$domdesc.' ('.$currdom.')'
5917: .'</b><input type="hidden" name="selfenroll_dom_'.$num
5918: .'" value="'.$currdom.'" /></span><br />'
5919: .'<span class="LC_nobreak"><label><input type="checkbox" '
1.406.2.6 raeburn 5920: .'name="selfenroll_delete" value="'.$num.'" onchange="javascript:update_types('."'selfenroll_delete','$num'".');"'.$disabled.' />'
1.241 raeburn 5921: .&mt('Delete').'</label></span></td>';
1.249 raeburn 5922: $output .= '<td valign="top"> '.&mt('User types:').'<br />'
1.406.2.6 raeburn 5923: .&selfenroll_inst_types($num,$currdom,\@currinsttypes,$readonly).'</td>'
1.241 raeburn 5924: .&Apache::loncommon::end_data_table_row();
5925: $num ++;
5926: }
5927: }
5928: }
1.249 raeburn 5929: my $add_domtitle = &mt('Users in additional domain:');
1.241 raeburn 5930: if ($curr_types eq '*') {
1.249 raeburn 5931: $add_domtitle = &mt('Users in specific domain:');
1.241 raeburn 5932: } elsif ($curr_types eq '') {
1.249 raeburn 5933: $add_domtitle = &mt('Users in other domain:');
1.241 raeburn 5934: }
5935: $output .= &Apache::loncommon::start_data_table_row()
5936: .'<td colspan="2"><span class="LC_nobreak">'.$add_domtitle.'</span><br />'
5937: .&Apache::loncommon::select_dom_form('','selfenroll_newdom',
1.406.2.6 raeburn 5938: $includeempty,$showdomdesc,'','','',$readonly)
1.241 raeburn 5939: .'<input type="hidden" name="selfenroll_types_total" value="'.$num.'" />'
5940: .'</td>'.&Apache::loncommon::end_data_table_row()
5941: .&Apache::loncommon::end_data_table();
1.237 raeburn 5942: } elsif ($item eq 'registered') {
5943: my ($regon,$regoff);
1.398 raeburn 5944: my $registered;
5945: if (ref($currsettings) eq 'HASH') {
5946: $registered = $currsettings->{'selfenroll_registered'};
5947: }
1.400 raeburn 5948: if ($noedit{$item}) {
5949: if ($registered) {
5950: $output .= &mt('Must be registered in course');
5951: } else {
5952: $output .= &mt('No requirement');
5953: }
5954: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
5955: next;
5956: }
1.398 raeburn 5957: if ($registered) {
1.237 raeburn 5958: $regon = ' checked="checked" ';
1.406.2.6 raeburn 5959: $regoff = '';
1.237 raeburn 5960: } else {
1.406.2.6 raeburn 5961: $regon = '';
1.237 raeburn 5962: $regoff = ' checked="checked" ';
5963: }
5964: $output .= '<label>'.
1.406.2.6 raeburn 5965: '<input type="radio" name="selfenroll_registered" value="1"'.$regon.$disabled.' />'.
1.244 bisitz 5966: &mt('Yes').'</label> <label>'.
1.406.2.6 raeburn 5967: '<input type="radio" name="selfenroll_registered" value="0"'.$regoff.$disabled.' />'.
1.244 bisitz 5968: &mt('No').'</label>';
1.237 raeburn 5969: } elsif ($item eq 'enroll_dates') {
1.398 raeburn 5970: my ($starttime,$endtime);
5971: if (ref($currsettings) eq 'HASH') {
5972: $starttime = $currsettings->{'selfenroll_start_date'};
5973: $endtime = $currsettings->{'selfenroll_end_date'};
5974: if ($starttime eq '') {
5975: $starttime = $currsettings->{'default_enrollment_start_date'};
5976: }
5977: if ($endtime eq '') {
5978: $endtime = $currsettings->{'default_enrollment_end_date'};
5979: }
1.237 raeburn 5980: }
1.400 raeburn 5981: if ($noedit{$item}) {
5982: $output .= &mt('From: [_1], to: [_2]',&Apache::lonlocal::locallocaltime($starttime),
5983: &Apache::lonlocal::locallocaltime($endtime));
5984: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
5985: next;
5986: }
1.237 raeburn 5987: my $startform =
5988: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_start_date',$starttime,
1.406.2.6 raeburn 5989: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
1.237 raeburn 5990: my $endform =
5991: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_end_date',$endtime,
1.406.2.6 raeburn 5992: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
1.237 raeburn 5993: $output .= &selfenroll_date_forms($startform,$endform);
5994: } elsif ($item eq 'access_dates') {
1.398 raeburn 5995: my ($starttime,$endtime);
5996: if (ref($currsettings) eq 'HASH') {
5997: $starttime = $currsettings->{'selfenroll_start_access'};
5998: $endtime = $currsettings->{'selfenroll_end_access'};
5999: if ($starttime eq '') {
6000: $starttime = $currsettings->{'default_enrollment_start_date'};
6001: }
6002: if ($endtime eq '') {
6003: $endtime = $currsettings->{'default_enrollment_end_date'};
6004: }
1.237 raeburn 6005: }
1.400 raeburn 6006: if ($noedit{$item}) {
6007: $output .= &mt('From: [_1], to: [_2]',&Apache::lonlocal::locallocaltime($starttime),
6008: &Apache::lonlocal::locallocaltime($endtime));
6009: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6010: next;
6011: }
1.237 raeburn 6012: my $startform =
6013: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_start_access',$starttime,
1.406.2.6 raeburn 6014: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
1.237 raeburn 6015: my $endform =
6016: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_end_access',$endtime,
1.406.2.6 raeburn 6017: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
1.237 raeburn 6018: $output .= &selfenroll_date_forms($startform,$endform);
6019: } elsif ($item eq 'section') {
1.398 raeburn 6020: my $currsec;
6021: if (ref($currsettings) eq 'HASH') {
6022: $currsec = $currsettings->{'selfenroll_section'};
6023: }
1.237 raeburn 6024: my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum);
6025: my $newsecval;
6026: if ($currsec ne 'none' && $currsec ne '') {
6027: if (!defined($sections_count{$currsec})) {
6028: $newsecval = $currsec;
6029: }
6030: }
1.400 raeburn 6031: if ($noedit{$item}) {
6032: if ($currsec ne '') {
6033: $output .= $currsec;
6034: } else {
6035: $output .= &mt('No specific section');
6036: }
6037: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6038: next;
6039: }
1.237 raeburn 6040: my $sections_select =
1.406.2.6 raeburn 6041: &Apache::lonuserutils::course_sections(\%sections_count,'st',$currsec,$disabled);
1.237 raeburn 6042: $output .= '<table class="LC_createuser">'."\n".
6043: '<tr class="LC_section_row">'."\n".
6044: '<td align="center">'.&mt('Existing sections')."\n".
6045: '<br />'.$sections_select.'</td><td align="center">'.
6046: &mt('New section').'<br />'."\n".
1.406.2.6 raeburn 6047: '<input type="text" name="newsec" size="15" value="'.$newsecval.'"'.$disabled.' />'."\n".
1.237 raeburn 6048: '<input type="hidden" name="sections" value="" />'."\n".
6049: '</td></tr></table>'."\n";
1.276 raeburn 6050: } elsif ($item eq 'approval') {
1.398 raeburn 6051: my ($currnotified,$currapproval,%appchecked);
6052: my %selfdescs = &Apache::lonuserutils::selfenroll_default_descs();
1.406.2.6 raeburn 6053: if (ref($currsettings) eq 'HASH') {
1.398 raeburn 6054: $currnotified = $currsettings->{'selfenroll_notifylist'};
6055: $currapproval = $currsettings->{'selfenroll_approval'};
6056: }
6057: if ($currapproval !~ /^[012]$/) {
6058: $currapproval = 0;
6059: }
1.400 raeburn 6060: if ($noedit{$item}) {
6061: $output .= $selfdescs{'approval'}{$currapproval}.
6062: '<br />'.&mt('(Set by Domain Coordinator)');
6063: next;
6064: }
1.398 raeburn 6065: $appchecked{$currapproval} = ' checked="checked"';
6066: for my $i (0..2) {
6067: $output .= '<label>'.
6068: '<input type="radio" name="selfenroll_approval" value="'.$i.'"'.
1.406.2.6 raeburn 6069: $appchecked{$i}.' onclick="toggleNotify();"'.$disabled.' />'.
6070: $selfdescs{'approval'}{$i}.'</label>'.(' 'x2);
1.276 raeburn 6071: }
6072: my %advhash = &Apache::lonnet::get_course_adv_roles($cid,1);
6073: my (@ccs,%notified);
1.322 raeburn 6074: my $ccrole = 'cc';
6075: if ($crstype eq 'Community') {
6076: $ccrole = 'co';
6077: }
6078: if ($advhash{$ccrole}) {
6079: @ccs = split(/,/,$advhash{$ccrole});
1.276 raeburn 6080: }
6081: if ($currnotified) {
6082: foreach my $current (split(/,/,$currnotified)) {
6083: $notified{$current} = 1;
6084: if (!grep(/^\Q$current\E$/,@ccs)) {
6085: push(@ccs,$current);
6086: }
6087: }
6088: }
6089: if (@ccs) {
1.398 raeburn 6090: my $style;
6091: unless ($currapproval) {
6092: $style = ' style="display: none;"';
6093: }
6094: $output .= '<br /><div id="notified"'.$style.'>'.
6095: &mt('Personnel to be notified when an enrollment request needs approval, or has been approved:').' '.
6096: &Apache::loncommon::start_data_table().
1.276 raeburn 6097: &Apache::loncommon::start_data_table_row();
6098: my $count = 0;
6099: my $numcols = 4;
6100: foreach my $cc (sort(@ccs)) {
6101: my $notifyon;
6102: my ($ccuname,$ccudom) = split(/:/,$cc);
6103: if ($notified{$cc}) {
6104: $notifyon = ' checked="checked" ';
6105: }
6106: if ($count && !$count%$numcols) {
6107: $output .= &Apache::loncommon::end_data_table_row().
6108: &Apache::loncommon::start_data_table_row()
6109: }
6110: $output .= '<td><span class="LC_nobreak"><label>'.
1.406.2.6 raeburn 6111: '<input type="checkbox" name="selfenroll_notify"'.$notifyon.' value="'.$cc.'"'.$disabled.' />'.
1.276 raeburn 6112: &Apache::loncommon::plainname($ccuname,$ccudom).
6113: '</label></span></td>';
1.343 raeburn 6114: $count ++;
1.276 raeburn 6115: }
6116: my $rem = $count%$numcols;
6117: if ($rem) {
6118: my $emptycols = $numcols - $rem;
6119: for (my $i=0; $i<$emptycols; $i++) {
6120: $output .= '<td> </td>';
6121: }
6122: }
6123: $output .= &Apache::loncommon::end_data_table_row().
1.398 raeburn 6124: &Apache::loncommon::end_data_table().
6125: '</div>';
1.276 raeburn 6126: }
6127: } elsif ($item eq 'limit') {
1.398 raeburn 6128: my ($crslimit,$selflimit,$nolimit,$currlim,$currcap);
6129: if (ref($currsettings) eq 'HASH') {
6130: $currlim = $currsettings->{'selfenroll_limit'};
6131: $currcap = $currsettings->{'selfenroll_cap'};
6132: }
1.400 raeburn 6133: if ($noedit{$item}) {
6134: if (($currlim eq 'allstudents') || ($currlim eq 'selfenrolled')) {
6135: if ($currlim eq 'allstudents') {
6136: $output .= &mt('Limit by total students');
6137: } elsif ($currlim eq 'selfenrolled') {
6138: $output .= &mt('Limit by total self-enrolled students');
6139: }
6140: $output .= ' '.&mt('Maximum: [_1]',$currcap).
6141: '<br />'.&mt('(Set by Domain Coordinator)');
6142: } else {
6143: $output .= &mt('No limit').'<br />'.&mt('(Set by Domain Coordinator)');
6144: }
6145: next;
6146: }
1.276 raeburn 6147: if ($currlim eq 'allstudents') {
6148: $crslimit = ' checked="checked" ';
6149: $selflimit = ' ';
6150: $nolimit = ' ';
6151: } elsif ($currlim eq 'selfenrolled') {
6152: $crslimit = ' ';
6153: $selflimit = ' checked="checked" ';
6154: $nolimit = ' ';
6155: } else {
6156: $crslimit = ' ';
6157: $selflimit = ' ';
1.398 raeburn 6158: $nolimit = ' checked="checked" ';
1.276 raeburn 6159: }
6160: $output .= '<table><tr><td><label>'.
1.406.2.6 raeburn 6161: '<input type="radio" name="selfenroll_limit" value="none"'.$nolimit.$disabled.'/>'.
1.276 raeburn 6162: &mt('No limit').'</label></td><td><label>'.
1.406.2.6 raeburn 6163: '<input type="radio" name="selfenroll_limit" value="allstudents"'.$crslimit.$disabled.'/>'.
1.276 raeburn 6164: &mt('Limit by total students').'</label></td><td><label>'.
1.406.2.6 raeburn 6165: '<input type="radio" name="selfenroll_limit" value="selfenrolled"'.$selflimit.$disabled.'/>'.
1.276 raeburn 6166: &mt('Limit by total self-enrolled students').
6167: '</td></tr><tr>'.
6168: '<td> </td><td colspan="2"><span class="LC_nobreak">'.
6169: (' 'x3).&mt('Maximum number allowed: ').
1.406.2.6 raeburn 6170: '<input type="text" name="selfenroll_cap" size = "5" value="'.$currcap.'"'.$disabled.' /></td></tr></table>';
1.237 raeburn 6171: }
6172: $output .= &Apache::lonhtmlcommon::row_closure(1);
6173: }
6174: }
1.406.2.6 raeburn 6175: $output .= &Apache::lonhtmlcommon::end_pick_box().'<br />';
6176: unless ($readonly) {
6177: $output .= '<input type="button" name="selfenrollconf" value="'
6178: .&mt('Save').'" onclick="validate_types(this.form);" />';
6179: }
6180: $output .= '<input type="hidden" name="action" value="selfenroll" />'
1.406.2.11 raeburn 6181: .'<input type="hidden" name="state" value="done" />'."\n"
6182: .$additional.'</form>';
1.237 raeburn 6183: $r->print($output);
6184: return;
6185: }
6186:
1.400 raeburn 6187: sub get_noedit_fields {
6188: my ($cdom,$cnum,$crstype,$row) = @_;
6189: my %noedit;
6190: if (ref($row) eq 'ARRAY') {
6191: my %settings = &Apache::lonnet::get('environment',['internal.coursecode','internal.textbook',
6192: 'internal.selfenrollmgrdc',
6193: 'internal.selfenrollmgrcc'],$cdom,$cnum);
6194: my $type = &Apache::lonuserutils::get_extended_type($cdom,$cnum,$crstype,\%settings);
6195: my (%specific_managebydc,%specific_managebycc,%default_managebydc);
6196: map { $specific_managebydc{$_} = 1; } (split(/,/,$settings{'internal.selfenrollmgrdc'}));
6197: map { $specific_managebycc{$_} = 1; } (split(/,/,$settings{'internal.selfenrollmgrcc'}));
6198: my %domdefaults = &Apache::lonnet::get_domain_defaults($cdom);
6199: map { $default_managebydc{$_} = 1; } (split(/,/,$domdefaults{$type.'selfenrolladmdc'}));
6200:
6201: foreach my $item (@{$row}) {
6202: next if ($specific_managebycc{$item});
6203: if (($specific_managebydc{$item}) || ($default_managebydc{$item})) {
6204: $noedit{$item} = 1;
6205: }
6206: }
6207: }
6208: return %noedit;
6209: }
6210:
6211: sub visible_in_stdcat {
6212: my ($cdom,$cnum,$domconf) = @_;
6213: my ($cathash,%settable,@vismsgs,$cansetvis,$visible);
6214: unless (ref($domconf) eq 'HASH') {
6215: return ($visible,$cansetvis,\@vismsgs);
6216: }
6217: if (ref($domconf->{'coursecategories'}) eq 'HASH') {
6218: if ($domconf->{'coursecategories'}{'togglecats'} eq 'crs') {
1.256 raeburn 6219: $settable{'togglecats'} = 1;
6220: }
1.400 raeburn 6221: if ($domconf->{'coursecategories'}{'categorize'} eq 'crs') {
1.256 raeburn 6222: $settable{'categorize'} = 1;
6223: }
1.400 raeburn 6224: $cathash = $domconf->{'coursecategories'}{'cats'};
1.256 raeburn 6225: }
1.260 raeburn 6226: if ($settable{'togglecats'} && $settable{'categorize'}) {
1.256 raeburn 6227: $cansetvis = &mt('You are able to both assign a course category and choose to exclude this course from the catalog.');
6228: } elsif ($settable{'togglecats'}) {
6229: $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 6230: } elsif ($settable{'categorize'}) {
1.256 raeburn 6231: $cansetvis = &mt('You may assign a course category, but only a Domain Coordinator may choose to exclude this course from the catalog.');
6232: } else {
6233: $cansetvis = &mt('Only a Domain Coordinator may assign a course category or choose to exclude this course from the catalog.');
6234: }
6235:
6236: my %currsettings =
6237: &Apache::lonnet::get('environment',['hidefromcat','categories','internal.coursecode'],
6238: $cdom,$cnum);
1.400 raeburn 6239: $visible = 0;
1.256 raeburn 6240: if ($currsettings{'internal.coursecode'} ne '') {
1.400 raeburn 6241: if (ref($domconf->{'coursecategories'}) eq 'HASH') {
6242: $cathash = $domconf->{'coursecategories'}{'cats'};
1.256 raeburn 6243: if (ref($cathash) eq 'HASH') {
6244: if ($cathash->{'instcode::0'} eq '') {
6245: push(@vismsgs,'dc_addinst');
6246: } else {
6247: $visible = 1;
6248: }
6249: } else {
6250: $visible = 1;
6251: }
6252: } else {
6253: $visible = 1;
6254: }
6255: } else {
6256: if (ref($cathash) eq 'HASH') {
6257: if ($cathash->{'instcode::0'} ne '') {
6258: push(@vismsgs,'dc_instcode');
6259: }
6260: } else {
6261: push(@vismsgs,'dc_instcode');
6262: }
6263: }
6264: if ($currsettings{'categories'} ne '') {
6265: my $cathash;
1.400 raeburn 6266: if (ref($domconf->{'coursecategories'}) eq 'HASH') {
6267: $cathash = $domconf->{'coursecategories'}{'cats'};
1.256 raeburn 6268: if (ref($cathash) eq 'HASH') {
6269: if (keys(%{$cathash}) == 0) {
6270: push(@vismsgs,'dc_catalog');
6271: } elsif ((keys(%{$cathash}) == 1) && ($cathash->{'instcode::0'} ne '')) {
6272: push(@vismsgs,'dc_categories');
6273: } else {
6274: my @currcategories = split('&',$currsettings{'categories'});
6275: my $matched = 0;
6276: foreach my $cat (@currcategories) {
6277: if ($cathash->{$cat} ne '') {
6278: $visible = 1;
6279: $matched = 1;
6280: last;
6281: }
6282: }
6283: if (!$matched) {
1.260 raeburn 6284: if ($settable{'categorize'}) {
1.256 raeburn 6285: push(@vismsgs,'chgcat');
6286: } else {
6287: push(@vismsgs,'dc_chgcat');
6288: }
6289: }
6290: }
6291: }
6292: }
6293: } else {
6294: if (ref($cathash) eq 'HASH') {
6295: if ((keys(%{$cathash}) > 1) ||
6296: (keys(%{$cathash}) == 1) && ($cathash->{'instcode::0'} eq '')) {
1.260 raeburn 6297: if ($settable{'categorize'}) {
1.256 raeburn 6298: push(@vismsgs,'addcat');
6299: } else {
6300: push(@vismsgs,'dc_addcat');
6301: }
6302: }
6303: }
6304: }
6305: if ($currsettings{'hidefromcat'} eq 'yes') {
6306: $visible = 0;
6307: if ($settable{'togglecats'}) {
6308: unshift(@vismsgs,'unhide');
6309: } else {
6310: unshift(@vismsgs,'dc_unhide')
6311: }
6312: }
1.400 raeburn 6313: return ($visible,$cansetvis,\@vismsgs);
6314: }
6315:
6316: sub cat_visibility {
6317: my %visactions = &Apache::lonlocal::texthash(
6318: vis => 'This course/community currently appears in the Course/Community Catalog for this domain.',
6319: 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.',
6320: miss => 'This course/community does not currently appear in the Course/Community Catalog for this domain.',
6321: none => 'Display of a course catalog is disabled for this domain.',
6322: yous => 'You should remedy this if you plan to allow self-enrollment, otherwise students will have difficulty finding this course.',
6323: 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.',
6324: make => 'Make any changes to self-enrollment settings below, click "Save", then take action to include the course in the Catalog:',
6325: take => 'Take the following action to ensure the course appears in the Catalog:',
6326: dc_chgconf => 'Ask a domain coordinator to change the Catalog type for this domain.',
6327: dc_setcode => 'Ask a domain coordinator to assign a six character code to the course',
6328: dc_unhide => 'Ask a domain coordinator to change the "Exclude from course catalog" setting.',
6329: dc_addinst => 'Ask a domain coordinator to enable display the catalog of "Official courses (with institutional codes)".',
6330: dc_instcode => 'Ask a domain coordinator to assign an institutional code (if this is an official course).',
6331: dc_catalog => 'Ask a domain coordinator to enable or create at least one course category in the domain.',
6332: dc_categories => 'Ask a domain coordinator to create a hierarchy of categories and sub categories for courses in the domain.',
6333: 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',
6334: dc_addcat => 'Ask a domain coordinator to assign a category to the course.',
6335: );
6336: $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>"');
6337: $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>"');
6338: $visactions{'addcat'} = &mt('Use [_1]Categorize course[_2] to assign a category to the course.','"<a href="/adm/courseprefs?phase=display&actions=courseinfo">','</a>"');
6339: return \%visactions;
1.256 raeburn 6340: }
6341:
1.241 raeburn 6342: sub new_selfenroll_dom_row {
6343: my ($newdom,$num) = @_;
6344: my $domdesc = &Apache::lonnet::domain($newdom);
6345: my $output;
6346: if ($domdesc ne '') {
6347: $output .= &Apache::loncommon::start_data_table_row()
6348: .'<td valign="top"><span class="LC_nobreak">'.&mt('Domain:').' <b>'.$domdesc
6349: .' ('.$newdom.')</b><input type="hidden" name="selfenroll_dom_'.$num
1.249 raeburn 6350: .'" value="'.$newdom.'" /></span><br />'
6351: .'<span class="LC_nobreak"><label><input type="checkbox" '
6352: .'name="selfenroll_activate" value="'.$num.'" '
6353: .'onchange="javascript:update_types('
6354: ."'selfenroll_activate','$num'".');" />'
6355: .&mt('Activate').'</label></span></td>';
1.241 raeburn 6356: my @currinsttypes;
6357: $output .= '<td>'.&mt('User types:').'<br />'
6358: .&selfenroll_inst_types($num,$newdom,\@currinsttypes).'</td>'
6359: .&Apache::loncommon::end_data_table_row();
6360: }
6361: return $output;
6362: }
6363:
6364: sub selfenroll_inst_types {
1.406.2.6 raeburn 6365: my ($num,$currdom,$currinsttypes,$readonly) = @_;
1.241 raeburn 6366: my $output;
6367: my $numinrow = 4;
6368: my $count = 0;
6369: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($currdom);
1.247 raeburn 6370: my $othervalue = 'any';
1.406.2.6 raeburn 6371: my $disabled;
6372: if ($readonly) {
6373: $disabled = ' disabled="disabled"';
6374: }
1.241 raeburn 6375: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
1.251 raeburn 6376: if (keys(%{$usertypes}) > 0) {
1.247 raeburn 6377: $othervalue = 'other';
6378: }
1.241 raeburn 6379: $output .= '<table><tr>';
6380: foreach my $type (@{$types}) {
6381: if (($count > 0) && ($count%$numinrow == 0)) {
6382: $output .= '</tr><tr>';
6383: }
6384: if (defined($usertypes->{$type})) {
1.257 raeburn 6385: my $esc_type = &escape($type);
1.241 raeburn 6386: $output .= '<td><span class="LC_nobreak"><label><input type = "checkbox" value="'.
1.257 raeburn 6387: $esc_type.'" ';
1.241 raeburn 6388: if (ref($currinsttypes) eq 'ARRAY') {
6389: if (@{$currinsttypes} > 0) {
1.249 raeburn 6390: if (grep(/^any$/,@{$currinsttypes})) {
6391: $output .= 'checked="checked"';
1.257 raeburn 6392: } elsif (grep(/^\Q$esc_type\E$/,@{$currinsttypes})) {
1.241 raeburn 6393: $output .= 'checked="checked"';
6394: }
1.249 raeburn 6395: } else {
6396: $output .= 'checked="checked"';
1.241 raeburn 6397: }
6398: }
1.406.2.6 raeburn 6399: $output .= ' name="selfenroll_types_'.$num.'"'.$disabled.' />'.$usertypes->{$type}.'</label></span></td>';
1.241 raeburn 6400: }
6401: $count ++;
6402: }
6403: if (($count > 0) && ($count%$numinrow == 0)) {
6404: $output .= '</tr><tr>';
6405: }
1.249 raeburn 6406: $output .= '<td><span class="LC_nobreak"><label><input type = "checkbox" value="'.$othervalue.'"';
1.241 raeburn 6407: if (ref($currinsttypes) eq 'ARRAY') {
6408: if (@{$currinsttypes} > 0) {
1.249 raeburn 6409: if (grep(/^any$/,@{$currinsttypes})) {
6410: $output .= ' checked="checked"';
6411: } elsif ($othervalue eq 'other') {
6412: if (grep(/^\Q$othervalue\E$/,@{$currinsttypes})) {
6413: $output .= ' checked="checked"';
6414: }
1.241 raeburn 6415: }
1.249 raeburn 6416: } else {
6417: $output .= ' checked="checked"';
1.241 raeburn 6418: }
1.249 raeburn 6419: } else {
6420: $output .= ' checked="checked"';
1.241 raeburn 6421: }
1.406.2.6 raeburn 6422: $output .= ' name="selfenroll_types_'.$num.'"'.$disabled.' />'.$othertitle.'</label></span></td></tr></table>';
1.241 raeburn 6423: }
6424: return $output;
6425: }
6426:
1.237 raeburn 6427: sub selfenroll_date_forms {
6428: my ($startform,$endform) = @_;
6429: my $output .= &Apache::lonhtmlcommon::start_pick_box()."\n".
1.244 bisitz 6430: &Apache::lonhtmlcommon::row_title(&mt('Start date'),
1.237 raeburn 6431: 'LC_oddrow_value')."\n".
6432: $startform."\n".
6433: &Apache::lonhtmlcommon::row_closure(1).
1.244 bisitz 6434: &Apache::lonhtmlcommon::row_title(&mt('End date'),
1.237 raeburn 6435: 'LC_oddrow_value')."\n".
6436: $endform."\n".
6437: &Apache::lonhtmlcommon::row_closure(1).
6438: &Apache::lonhtmlcommon::end_pick_box();
6439: return $output;
6440: }
6441:
1.239 raeburn 6442: sub print_userchangelogs_display {
1.406.2.5 raeburn 6443: my ($r,$context,$permission,$brcrum) = @_;
1.363 raeburn 6444: my $formname = 'rolelog';
1.406.2.6 raeburn 6445: my ($username,$domain,$crstype,$viewablesec,%roleslog);
1.363 raeburn 6446: if ($context eq 'domain') {
6447: $domain = $env{'request.role.domain'};
6448: %roleslog=&Apache::lonnet::dump_dom('nohist_rolelog',$domain);
6449: } else {
6450: if ($context eq 'course') {
6451: $domain = $env{'course.'.$env{'request.course.id'}.'.domain'};
6452: $username = $env{'course.'.$env{'request.course.id'}.'.num'};
6453: $crstype = &Apache::loncommon::course_type();
1.406.2.6 raeburn 6454: $viewablesec = &Apache::lonuserutils::viewable_section($permission);
1.363 raeburn 6455: my %saveable_parameters = ('show' => 'scalar',);
6456: &Apache::loncommon::store_course_settings('roles_log',
6457: \%saveable_parameters);
6458: &Apache::loncommon::restore_course_settings('roles_log',
6459: \%saveable_parameters);
6460: } elsif ($context eq 'author') {
6461: $domain = $env{'user.domain'};
6462: if ($env{'request.role'} =~ m{^au\./\Q$domain\E/$}) {
6463: $username = $env{'user.name'};
6464: } else {
6465: undef($domain);
6466: }
6467: }
6468: if ($domain ne '' && $username ne '') {
6469: %roleslog=&Apache::lonnet::dump('nohist_rolelog',$domain,$username);
6470: }
6471: }
1.239 raeburn 6472: if ((keys(%roleslog))[0]=~/^error\:/) { undef(%roleslog); }
6473:
1.406.2.5 raeburn 6474: my $helpitem;
6475: if ($context eq 'course') {
6476: $helpitem = 'Course_User_Logs';
6477: }
6478: push (@{$brcrum},
6479: {href => '/adm/createuser?action=changelogs',
6480: text => 'User Management Logs',
6481: help => $helpitem});
6482: my $bread_crumbs_component = 'User Changes';
6483: my $args = { bread_crumbs => $brcrum,
6484: bread_crumbs_component => $bread_crumbs_component};
6485:
6486: # Create navigation javascript
6487: my $jsnav = &userlogdisplay_js($formname);
6488:
6489: my $jscript = (<<ENDSCRIPT);
6490: <script type="text/javascript">
6491: // <![CDATA[
6492: $jsnav
6493: // ]]>
6494: </script>
6495: ENDSCRIPT
6496:
6497: # print page header
6498: $r->print(&header($jscript,$args));
6499:
1.239 raeburn 6500: # set defaults
6501: my $now = time();
6502: my $defstart = $now - (7*24*3600); #7 days ago
6503: my %defaults = (
6504: page => '1',
6505: show => '10',
6506: role => 'any',
6507: chgcontext => 'any',
6508: rolelog_start_date => $defstart,
6509: rolelog_end_date => $now,
6510: );
6511: my $more_records = 0;
6512:
6513: # set current
6514: my %curr;
6515: foreach my $item ('show','page','role','chgcontext') {
6516: $curr{$item} = $env{'form.'.$item};
6517: }
6518: my ($startdate,$enddate) =
6519: &Apache::lonuserutils::get_dates_from_form('rolelog_start_date','rolelog_end_date');
6520: $curr{'rolelog_start_date'} = $startdate;
6521: $curr{'rolelog_end_date'} = $enddate;
6522: foreach my $key (keys(%defaults)) {
6523: if ($curr{$key} eq '') {
6524: $curr{$key} = $defaults{$key};
6525: }
6526: }
1.248 raeburn 6527: my (%whodunit,%changed,$version);
6528: ($version) = ($r->dir_config('lonVersion') =~ /^([\d\.]+)\-/);
1.239 raeburn 6529: my ($minshown,$maxshown);
1.255 raeburn 6530: $minshown = 1;
1.239 raeburn 6531: my $count = 0;
1.406.2.5 raeburn 6532: if ($curr{'show'} =~ /\D/) {
6533: $curr{'page'} = 1;
6534: } else {
1.239 raeburn 6535: $maxshown = $curr{'page'} * $curr{'show'};
6536: if ($curr{'page'} > 1) {
6537: $minshown = 1 + ($curr{'page'} - 1) * $curr{'show'};
6538: }
6539: }
1.301 bisitz 6540:
1.327 raeburn 6541: # Form Header
6542: $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">'.
1.363 raeburn 6543: &role_display_filter($context,$formname,$domain,$username,\%curr,
6544: $version,$crstype));
1.327 raeburn 6545:
6546: my $showntableheader = 0;
6547:
6548: # Table Header
6549: my $tableheader =
6550: &Apache::loncommon::start_data_table_header_row()
6551: .'<th> </th>'
6552: .'<th>'.&mt('When').'</th>'
6553: .'<th>'.&mt('Who made the change').'</th>'
6554: .'<th>'.&mt('Changed User').'</th>'
1.363 raeburn 6555: .'<th>'.&mt('Role').'</th>';
6556:
6557: if ($context eq 'course') {
6558: $tableheader .= '<th>'.&mt('Section').'</th>';
6559: }
6560: $tableheader .=
6561: '<th>'.&mt('Context').'</th>'
1.327 raeburn 6562: .'<th>'.&mt('Start').'</th>'
6563: .'<th>'.&mt('End').'</th>'
6564: .&Apache::loncommon::end_data_table_header_row();
6565:
6566: # Display user change log data
1.239 raeburn 6567: foreach my $id (sort { $roleslog{$b}{'exe_time'}<=>$roleslog{$a}{'exe_time'} } (keys(%roleslog))) {
6568: next if (($roleslog{$id}{'exe_time'} < $curr{'rolelog_start_date'}) ||
6569: ($roleslog{$id}{'exe_time'} > $curr{'rolelog_end_date'}));
1.406.2.5 raeburn 6570: if ($curr{'show'} !~ /\D/) {
1.239 raeburn 6571: if ($count >= $curr{'page'} * $curr{'show'}) {
6572: $more_records = 1;
6573: last;
6574: }
6575: }
6576: if ($curr{'role'} ne 'any') {
6577: next if ($roleslog{$id}{'logentry'}{'role'} ne $curr{'role'});
6578: }
6579: if ($curr{'chgcontext'} ne 'any') {
6580: if ($curr{'chgcontext'} eq 'selfenroll') {
6581: next if (!$roleslog{$id}{'logentry'}{'selfenroll'});
6582: } else {
6583: next if ($roleslog{$id}{'logentry'}{'context'} ne $curr{'chgcontext'});
6584: }
6585: }
1.406.2.6 raeburn 6586: if (($context eq 'course') && ($viewablesec ne '')) {
6587: next if ($roleslog{$id}{'logentry'}{'section'} ne $viewablesec);
6588: }
1.239 raeburn 6589: $count ++;
6590: next if ($count < $minshown);
1.327 raeburn 6591: unless ($showntableheader) {
1.406.2.5 raeburn 6592: $r->print(&Apache::loncommon::start_data_table()
1.327 raeburn 6593: .$tableheader);
6594: $r->rflush();
6595: $showntableheader = 1;
6596: }
1.239 raeburn 6597: if ($whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}} eq '') {
6598: $whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}} =
6599: &Apache::loncommon::plainname($roleslog{$id}{'exe_uname'},$roleslog{$id}{'exe_udom'});
6600: }
6601: if ($changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}} eq '') {
6602: $changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}} =
6603: &Apache::loncommon::plainname($roleslog{$id}{'uname'},$roleslog{$id}{'udom'});
6604: }
6605: my $sec = $roleslog{$id}{'logentry'}{'section'};
6606: if ($sec eq '') {
6607: $sec = &mt('None');
6608: }
6609: my ($rolestart,$roleend);
6610: if ($roleslog{$id}{'delflag'}) {
6611: $rolestart = &mt('deleted');
6612: $roleend = &mt('deleted');
6613: } else {
6614: $rolestart = $roleslog{$id}{'logentry'}{'start'};
6615: $roleend = $roleslog{$id}{'logentry'}{'end'};
6616: if ($rolestart eq '' || $rolestart == 0) {
6617: $rolestart = &mt('No start date');
6618: } else {
6619: $rolestart = &Apache::lonlocal::locallocaltime($rolestart);
6620: }
6621: if ($roleend eq '' || $roleend == 0) {
6622: $roleend = &mt('No end date');
6623: } else {
6624: $roleend = &Apache::lonlocal::locallocaltime($roleend);
6625: }
6626: }
6627: my $chgcontext = $roleslog{$id}{'logentry'}{'context'};
6628: if ($roleslog{$id}{'logentry'}{'selfenroll'}) {
6629: $chgcontext = 'selfenroll';
6630: }
1.363 raeburn 6631: my %lt = &rolechg_contexts($context,$crstype);
1.239 raeburn 6632: if ($chgcontext ne '' && $lt{$chgcontext} ne '') {
6633: $chgcontext = $lt{$chgcontext};
6634: }
1.327 raeburn 6635: $r->print(
1.301 bisitz 6636: &Apache::loncommon::start_data_table_row()
6637: .'<td>'.$count.'</td>'
6638: .'<td>'.&Apache::lonlocal::locallocaltime($roleslog{$id}{'exe_time'}).'</td>'
6639: .'<td>'.$whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}}.'</td>'
6640: .'<td>'.$changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}}.'</td>'
1.363 raeburn 6641: .'<td>'.&Apache::lonnet::plaintext($roleslog{$id}{'logentry'}{'role'},$crstype).'</td>');
6642: if ($context eq 'course') {
6643: $r->print('<td>'.$sec.'</td>');
6644: }
6645: $r->print(
6646: '<td>'.$chgcontext.'</td>'
1.301 bisitz 6647: .'<td>'.$rolestart.'</td>'
6648: .'<td>'.$roleend.'</td>'
1.327 raeburn 6649: .&Apache::loncommon::end_data_table_row()."\n");
1.301 bisitz 6650: }
6651:
1.327 raeburn 6652: if ($showntableheader) { # Table footer, if content displayed above
1.406.2.5 raeburn 6653: $r->print(&Apache::loncommon::end_data_table().
6654: &userlogdisplay_navlinks(\%curr,$more_records));
1.327 raeburn 6655: } else { # No content displayed above
1.301 bisitz 6656: $r->print('<p class="LC_info">'
6657: .&mt('There are no records to display.')
6658: .'</p>'
6659: );
1.239 raeburn 6660: }
1.301 bisitz 6661:
1.327 raeburn 6662: # Form Footer
6663: $r->print(
6664: '<input type="hidden" name="page" value="'.$curr{'page'}.'" />'
6665: .'<input type="hidden" name="action" value="changelogs" />'
6666: .'</form>');
6667: return;
6668: }
1.301 bisitz 6669:
1.406.2.5 raeburn 6670: sub print_useraccesslogs_display {
6671: my ($r,$uname,$udom,$permission,$brcrum) = @_;
6672: my $formname = 'accesslog';
6673: my $form = 'document.accesslog';
6674:
6675: # set breadcrumbs
1.406.2.7 raeburn 6676: my %breadcrumb_text = &singleuser_breadcrumb('','domain',$udom);
1.406.2.12 raeburn 6677: my $prevphasestr;
6678: if ($env{'form.popup'}) {
6679: $brcrum = [];
6680: } else {
6681: push (@{$brcrum},
6682: {href => "javascript:backPage($form)",
6683: text => $breadcrumb_text{'search'}});
6684: my @prevphases;
6685: if ($env{'form.prevphases'}) {
6686: @prevphases = split(/,/,$env{'form.prevphases'});
6687: $prevphasestr = $env{'form.prevphases'};
6688: }
6689: if (($env{'form.phase'} eq 'userpicked') || (grep(/^userpicked$/,@prevphases))) {
6690: push(@{$brcrum},
6691: {href => "javascript:backPage($form,'get_user_info','select')",
6692: text => $breadcrumb_text{'userpicked'}});
6693: if ($env{'form.phase'} eq 'userpicked') {
6694: $prevphasestr = 'userpicked';
6695: }
1.406.2.5 raeburn 6696: }
6697: }
6698: push(@{$brcrum},
6699: {href => '/adm/createuser?action=accesslogs',
6700: text => 'User access logs',
1.406.2.8 raeburn 6701: help => 'Domain_User_Access_Logs'});
1.406.2.5 raeburn 6702: my $bread_crumbs_component = 'User Access Logs';
6703: my $args = { bread_crumbs => $brcrum,
6704: bread_crumbs_component => 'User Management'};
1.406.2.8 raeburn 6705: if ($env{'form.popup'}) {
6706: $args->{'no_nav_bar'} = 1;
1.406.2.12 raeburn 6707: $args->{'bread_crumbs_nomenu'} = 1;
1.406.2.8 raeburn 6708: }
1.406.2.5 raeburn 6709:
6710: # set javascript
6711: my ($jsback,$elements) = &crumb_utilities();
6712: my $jsnav = &userlogdisplay_js($formname);
6713:
6714: my $jscript = (<<ENDSCRIPT);
1.239 raeburn 6715: <script type="text/javascript">
1.301 bisitz 6716: // <![CDATA[
1.406.2.5 raeburn 6717:
6718: $jsback
6719: $jsnav
6720:
6721: // ]]>
6722: </script>
6723:
6724: ENDSCRIPT
6725:
6726: # print page header
6727: $r->print(&header($jscript,$args));
6728:
6729: # early out unless log data can be displayed.
6730: unless ($permission->{'activity'}) {
6731: $r->print('<p class="LC_warning">'
6732: .&mt('You do not have rights to display user access logs.')
1.406.2.12 raeburn 6733: .'</p>');
6734: if ($env{'form.popup'}) {
6735: $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a></p>');
6736: } else {
6737: $r->print(&earlyout_accesslog_form($formname,$prevphasestr,$udom));
6738: }
1.406.2.5 raeburn 6739: return;
6740: }
6741:
6742: unless ($udom eq $env{'request.role.domain'}) {
6743: $r->print('<p class="LC_warning">'
6744: .&mt("User's domain must match role's domain")
6745: .'</p>'
6746: .&earlyout_accesslog_form($formname,$prevphasestr,$udom));
6747: return;
6748: }
6749:
6750: if (($uname eq '') || ($udom eq '')) {
6751: $r->print('<p class="LC_warning">'
6752: .&mt('Invalid username or domain')
6753: .'</p>'
6754: .&earlyout_accesslog_form($formname,$prevphasestr,$udom));
6755: return;
6756: }
6757:
1.406.2.13! raeburn 6758: if (&Apache::lonnet::privileged($uname,$udom,
! 6759: [$env{'request.role.domain'}],['dc','su'])) {
! 6760: unless (&Apache::lonnet::privileged($env{'user.name'},$env{'user.domain'},
! 6761: [$env{'request.role.domain'}],['dc','su'])) {
! 6762: $r->print('<p class="LC_warning">'
! 6763: .&mt('You need to be a privileged user to display user access logs for [_1]',
! 6764: &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),
! 6765: $uname,$udom))
! 6766: .'</p>');
! 6767: if ($env{'form.popup'}) {
! 6768: $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a></p>');
! 6769: } else {
! 6770: $r->print(&earlyout_accesslog_form($formname,$prevphasestr,$udom));
! 6771: }
! 6772: return;
! 6773: }
! 6774: }
! 6775:
1.406.2.5 raeburn 6776: # set defaults
6777: my $now = time();
6778: my $defstart = $now - (7*24*3600);
6779: my %defaults = (
6780: page => '1',
6781: show => '10',
6782: activity => 'any',
6783: accesslog_start_date => $defstart,
6784: accesslog_end_date => $now,
6785: );
6786: my $more_records = 0;
6787:
6788: # set current
6789: my %curr;
6790: foreach my $item ('show','page','activity') {
6791: $curr{$item} = $env{'form.'.$item};
6792: }
6793: my ($startdate,$enddate) =
6794: &Apache::lonuserutils::get_dates_from_form('accesslog_start_date','accesslog_end_date');
6795: $curr{'accesslog_start_date'} = $startdate;
6796: $curr{'accesslog_end_date'} = $enddate;
6797: foreach my $key (keys(%defaults)) {
6798: if ($curr{$key} eq '') {
6799: $curr{$key} = $defaults{$key};
6800: }
6801: }
6802: my ($minshown,$maxshown);
6803: $minshown = 1;
6804: my $count = 0;
6805: if ($curr{'show'} =~ /\D/) {
6806: $curr{'page'} = 1;
6807: } else {
6808: $maxshown = $curr{'page'} * $curr{'show'};
6809: if ($curr{'page'} > 1) {
6810: $minshown = 1 + ($curr{'page'} - 1) * $curr{'show'};
6811: }
6812: }
6813:
6814: # form header
6815: $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">'.
6816: &activity_display_filter($formname,\%curr));
6817:
6818: my $showntableheader = 0;
6819: my ($nav_script,$nav_links);
6820:
6821: # table header
1.406.2.12 raeburn 6822: my $tableheader = '<h3>'.
6823: &mt('User access logs for: [_1]',
6824: &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),$uname,$udom)).'</h3>'
6825: .&Apache::loncommon::start_data_table_header_row()
1.406.2.5 raeburn 6826: .'<th> </th>'
6827: .'<th>'.&mt('When').'</th>'
6828: .'<th>'.&mt('HostID').'</th>'
6829: .'<th>'.&mt('Event').'</th>'
6830: .'<th>'.&mt('Other data').'</th>'
6831: .&Apache::loncommon::end_data_table_header_row();
6832:
6833: my %filters=(
6834: start => $curr{'accesslog_start_date'},
6835: end => $curr{'accesslog_end_date'},
6836: action => $curr{'activity'},
6837: );
6838:
6839: my $reply = &Apache::lonnet::userlog_query($uname,$udom,%filters);
6840: unless ( ($reply =~/^timeout/) || ($reply =~/^error/) ) {
6841: my (%courses,%missing);
6842: my @results = split(/\&/,$reply);
6843: foreach my $item (reverse(@results)) {
6844: my ($timestamp,$host,$event) = split(/:/,$item);
6845: next unless ($event =~ /^(Log|Role)/);
6846: if ($curr{'show'} !~ /\D/) {
6847: if ($count >= $curr{'page'} * $curr{'show'}) {
6848: $more_records = 1;
6849: last;
6850: }
6851: }
6852: $count ++;
6853: next if ($count < $minshown);
6854: unless ($showntableheader) {
6855: $r->print($nav_script
6856: .&Apache::loncommon::start_data_table()
6857: .$tableheader);
6858: $r->rflush();
6859: $showntableheader = 1;
6860: }
1.406.2.6 raeburn 6861: my ($shown,$extra);
1.406.2.13! raeburn 6862: my ($event,$data) = split(/\s+/,&unescape($event),2);
1.406.2.5 raeburn 6863: if ($event eq 'Role') {
6864: my ($rolecode,$extent) = split(/\./,$data,2);
6865: next if ($extent eq '');
6866: my ($crstype,$desc,$info);
1.406.2.6 raeburn 6867: if ($extent =~ m{^/($match_domain)/($match_courseid)(?:/(\w+)|)$}) {
6868: my ($cdom,$cnum,$sec) = ($1,$2,$3);
1.406.2.5 raeburn 6869: my $cid = $cdom.'_'.$cnum;
6870: if (exists($courses{$cid})) {
6871: $crstype = $courses{$cid}{'type'};
6872: $desc = $courses{$cid}{'description'};
6873: } elsif ($missing{$cid}) {
6874: $crstype = 'Course';
6875: $desc = 'Course/Community';
6876: } else {
6877: my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',$cnum,undef,undef,'.');
6878: if (ref($crsinfo{$cdom.'_'.$cnum}) eq 'HASH') {
6879: $courses{$cid} = $crsinfo{$cid};
6880: $crstype = $crsinfo{$cid}{'type'};
6881: $desc = $crsinfo{$cid}{'description'};
6882: } else {
6883: $missing{$cid} = 1;
6884: }
6885: }
6886: $extra = &mt($crstype).': <a href="/public/'.$cdom.'/'.$cnum.'/syllabus">'.$desc.'</a>';
1.406.2.6 raeburn 6887: if ($sec ne '') {
6888: $extra .= ' ('.&mt('Section: [_1]',$sec).')';
6889: }
1.406.2.5 raeburn 6890: } elsif ($extent =~ m{^/($match_domain)/($match_username|$)}) {
6891: my ($dom,$name) = ($1,$2);
6892: if ($rolecode eq 'au') {
6893: $extra = '';
6894: } elsif ($rolecode =~ /^(ca|aa)$/) {
6895: $extra = &mt('Authoring Space: [_1]',$name.':'.$dom);
6896: } elsif ($rolecode =~ /^(li|dg|dh|dc|sc)$/) {
6897: $extra = &mt('Domain: [_1]',$dom);
6898: }
6899: }
6900: my $rolename;
6901: if ($rolecode =~ m{^cr/($match_domain)/($match_username)/(\w+)}) {
6902: my $role = $3;
6903: my $owner = "($2:$1)";
6904: if ($2 eq $1.'-domainconfig') {
6905: $owner = '(ad hoc)';
6906: }
6907: $rolename = &mt('Custom role: [_1]',$role.' '.$owner);
6908: } else {
6909: $rolename = &Apache::lonnet::plaintext($rolecode,$crstype);
6910: }
6911: $shown = &mt('Role selection: [_1]',$rolename);
6912: } else {
6913: $shown = &mt($event);
1.406.2.13! raeburn 6914: if ($data =~ /^webdav/) {
! 6915: my ($path,$clientip) = split(/\s+/,$data,2);
! 6916: $path =~ s/^webdav//;
! 6917: if ($clientip ne '') {
! 6918: $extra = &mt('Client IP address: [_1]',$clientip);
! 6919: }
! 6920: if ($path ne '') {
! 6921: $shown .= ' '.&mt('(WebDAV access to [_1])',$path);
! 6922: }
! 6923: } elsif ($data ne '') {
! 6924: $extra = &mt('Client IP address: [_1]',$data);
1.406.2.5 raeburn 6925: }
6926: }
6927: $r->print(
6928: &Apache::loncommon::start_data_table_row()
6929: .'<td>'.$count.'</td>'
6930: .'<td>'.&Apache::lonlocal::locallocaltime($timestamp).'</td>'
6931: .'<td>'.$host.'</td>'
6932: .'<td>'.$shown.'</td>'
6933: .'<td>'.$extra.'</td>'
6934: .&Apache::loncommon::end_data_table_row()."\n");
6935: }
6936: }
6937:
6938: if ($showntableheader) { # Table footer, if content displayed above
6939: $r->print(&Apache::loncommon::end_data_table().
6940: &userlogdisplay_navlinks(\%curr,$more_records));
6941: } else { # No content displayed above
6942: $r->print('<p class="LC_info">'
6943: .&mt('There are no records to display.')
6944: .'</p>');
6945: }
6946:
1.406.2.8 raeburn 6947: if ($env{'form.popup'} == 1) {
6948: $r->print('<input type="hidden" name="popup" value="1" />'."\n");
6949: }
6950:
1.406.2.5 raeburn 6951: # Form Footer
6952: $r->print(
6953: '<input type="hidden" name="currstate" value="" />'
6954: .'<input type="hidden" name="accessuname" value="'.$uname.'" />'
6955: .'<input type="hidden" name="accessudom" value="'.$udom.'" />'
6956: .'<input type="hidden" name="page" value="'.$curr{'page'}.'" />'
6957: .'<input type="hidden" name="prevphases" value="'.$prevphasestr.'" />'
6958: .'<input type="hidden" name="phase" value="activity" />'
6959: .'<input type="hidden" name="action" value="accesslogs" />'
6960: .'<input type="hidden" name="srchdomain" value="'.$udom.'" />'
6961: .'<input type="hidden" name="srchby" value="'.$env{'form.srchby'}.'" />'
6962: .'<input type="hidden" name="srchtype" value="'.$env{'form.srchtype'}.'" />'
6963: .'<input type="hidden" name="srchterm" value="'.&HTML::Entities::encode($env{'form.srchterm'},'<>"&').'" />'
6964: .'<input type="hidden" name="srchin" value="'.$env{'form.srchin'}.'" />'
6965: .'</form>');
6966: return;
6967: }
6968:
6969: sub earlyout_accesslog_form {
6970: my ($formname,$prevphasestr,$udom) = @_;
6971: my $srchterm = &HTML::Entities::encode($env{'form.srchterm'},'<>"&');
6972: return <<"END";
6973: <form action="/adm/createuser" method="post" name="$formname">
6974: <input type="hidden" name="currstate" value="" />
6975: <input type="hidden" name="prevphases" value="$prevphasestr" />
6976: <input type="hidden" name="phase" value="activity" />
6977: <input type="hidden" name="action" value="accesslogs" />
6978: <input type="hidden" name="srchdomain" value="$udom" />
6979: <input type="hidden" name="srchby" value="$env{'form.srchby'}" />
6980: <input type="hidden" name="srchtype" value="$env{'form.srchtype'}" />
6981: <input type="hidden" name="srchterm" value="$srchterm" />
6982: <input type="hidden" name="srchin" value="$env{'form.srchin'}" />
6983: </form>
6984: END
6985: }
6986:
6987: sub activity_display_filter {
6988: my ($formname,$curr) = @_;
6989: my $nolink = 1;
6990: my $output = '<table><tr><td valign="top">'.
6991: '<span class="LC_nobreak"><b>'.&mt('Actions/page:').'</b></span><br />'.
6992: &Apache::lonmeta::selectbox('show',$curr->{'show'},undef,
6993: (&mt('all'),5,10,20,50,100,1000,10000)).
6994: '</td><td> </td>';
6995: my $startform =
6996: &Apache::lonhtmlcommon::date_setter($formname,'accesslog_start_date',
6997: $curr->{'accesslog_start_date'},undef,
6998: undef,undef,undef,undef,undef,undef,$nolink);
6999: my $endform =
7000: &Apache::lonhtmlcommon::date_setter($formname,'accesslog_end_date',
7001: $curr->{'accesslog_end_date'},undef,
7002: undef,undef,undef,undef,undef,undef,$nolink);
7003: my %lt = &Apache::lonlocal::texthash (
7004: activity => 'Activity',
7005: Role => 'Role selection',
7006: log => 'Log-in or Logout',
7007: );
7008: $output .= '<td valign="top"><b>'.&mt('Window during which actions occurred:').'</b><br />'.
7009: '<table><tr><td>'.&mt('After:').
7010: '</td><td>'.$startform.'</td></tr>'.
7011: '<tr><td>'.&mt('Before:').'</td>'.
7012: '<td>'.$endform.'</td></tr></table>'.
7013: '</td>'.
7014: '<td> </td>'.
7015: '<td valign="top"><b>'.&mt('Activities').'</b><br />'.
7016: '<select name="activity"><option value="any"';
7017: if ($curr->{'activity'} eq 'any') {
7018: $output .= ' selected="selected"';
7019: }
7020: $output .= '>'.&mt('Any').'</option>'."\n";
7021: foreach my $activity ('Role','log') {
7022: my $selstr = '';
7023: if ($activity eq $curr->{'activity'}) {
7024: $selstr = ' selected="selected"';
7025: }
7026: $output .= '<option value="'.$activity.'"'.$selstr.'>'.$lt{$activity}.'</option>';
7027: }
7028: $output .= '</select></td>'.
7029: '</tr></table>';
7030: # Update Display button
7031: $output .= '<p>'
7032: .'<input type="submit" value="'.&mt('Update Display').'" />'
1.406.2.12 raeburn 7033: .'</p><hr />';
1.406.2.5 raeburn 7034: return $output;
7035: }
7036:
7037: sub userlogdisplay_js {
7038: my ($formname) = @_;
7039: return <<"ENDSCRIPT";
7040:
1.239 raeburn 7041: function chgPage(caller) {
7042: if (caller == 'previous') {
7043: document.$formname.page.value --;
7044: }
7045: if (caller == 'next') {
7046: document.$formname.page.value ++;
7047: }
1.327 raeburn 7048: document.$formname.submit();
1.239 raeburn 7049: return;
7050: }
7051: ENDSCRIPT
1.406.2.5 raeburn 7052: }
7053:
7054: sub userlogdisplay_navlinks {
7055: my ($curr,$more_records) = @_;
7056: return unless(ref($curr) eq 'HASH');
7057: # Navigation Buttons
7058: my $nav_links = '<p>';
7059: if (($curr->{'page'} > 1) || ($more_records)) {
7060: if (($curr->{'page'} > 1) && ($curr->{'show'} !~ /\D/)) {
7061: $nav_links .= '<input type="button"'
7062: .' onclick="javascript:chgPage('."'previous'".');"'
7063: .' value="'.&mt('Previous [_1] changes',$curr->{'show'})
7064: .'" /> ';
7065: }
7066: if ($more_records) {
7067: $nav_links .= '<input type="button"'
7068: .' onclick="javascript:chgPage('."'next'".');"'
7069: .' value="'.&mt('Next [_1] changes',$curr->{'show'})
7070: .'" />';
1.301 bisitz 7071: }
7072: }
1.406.2.5 raeburn 7073: $nav_links .= '</p>';
7074: return $nav_links;
1.239 raeburn 7075: }
7076:
7077: sub role_display_filter {
1.363 raeburn 7078: my ($context,$formname,$cdom,$cnum,$curr,$version,$crstype) = @_;
7079: my $lctype;
7080: if ($context eq 'course') {
7081: $lctype = lc($crstype);
7082: }
1.239 raeburn 7083: my $nolink = 1;
7084: my $output = '<table><tr><td valign="top">'.
1.301 bisitz 7085: '<span class="LC_nobreak"><b>'.&mt('Changes/page:').'</b></span><br />'.
1.239 raeburn 7086: &Apache::lonmeta::selectbox('show',$curr->{'show'},undef,
7087: (&mt('all'),5,10,20,50,100,1000,10000)).
7088: '</td><td> </td>';
7089: my $startform =
7090: &Apache::lonhtmlcommon::date_setter($formname,'rolelog_start_date',
7091: $curr->{'rolelog_start_date'},undef,
7092: undef,undef,undef,undef,undef,undef,$nolink);
7093: my $endform =
7094: &Apache::lonhtmlcommon::date_setter($formname,'rolelog_end_date',
7095: $curr->{'rolelog_end_date'},undef,
7096: undef,undef,undef,undef,undef,undef,$nolink);
1.363 raeburn 7097: my %lt = &rolechg_contexts($context,$crstype);
1.301 bisitz 7098: $output .= '<td valign="top"><b>'.&mt('Window during which changes occurred:').'</b><br />'.
7099: '<table><tr><td>'.&mt('After:').
7100: '</td><td>'.$startform.'</td></tr>'.
7101: '<tr><td>'.&mt('Before:').'</td>'.
7102: '<td>'.$endform.'</td></tr></table>'.
7103: '</td>'.
7104: '<td> </td>'.
1.239 raeburn 7105: '<td valign="top"><b>'.&mt('Role:').'</b><br />'.
7106: '<select name="role"><option value="any"';
7107: if ($curr->{'role'} eq 'any') {
7108: $output .= ' selected="selected"';
7109: }
7110: $output .= '>'.&mt('Any').'</option>'."\n";
1.363 raeburn 7111: my @roles = &Apache::lonuserutils::roles_by_context($context,1,$crstype);
1.239 raeburn 7112: foreach my $role (@roles) {
7113: my $plrole;
7114: if ($role eq 'cr') {
7115: $plrole = &mt('Custom Role');
7116: } else {
1.318 raeburn 7117: $plrole=&Apache::lonnet::plaintext($role,$crstype);
1.239 raeburn 7118: }
7119: my $selstr = '';
7120: if ($role eq $curr->{'role'}) {
7121: $selstr = ' selected="selected"';
7122: }
7123: $output .= ' <option value="'.$role.'"'.$selstr.'>'.$plrole.'</option>';
7124: }
1.301 bisitz 7125: $output .= '</select></td>'.
7126: '<td> </td>'.
7127: '<td valign="top"><b>'.
1.239 raeburn 7128: &mt('Context:').'</b><br /><select name="chgcontext">';
1.363 raeburn 7129: my @posscontexts;
7130: if ($context eq 'course') {
1.376 raeburn 7131: @posscontexts = ('any','automated','updatenow','createcourse','course','domain','selfenroll','requestcourses');
1.363 raeburn 7132: } elsif ($context eq 'domain') {
7133: @posscontexts = ('any','domain','requestauthor','domconfig','server');
7134: } else {
7135: @posscontexts = ('any','author','domain');
7136: }
7137: foreach my $chgtype (@posscontexts) {
1.239 raeburn 7138: my $selstr = '';
7139: if ($curr->{'chgcontext'} eq $chgtype) {
1.301 bisitz 7140: $selstr = ' selected="selected"';
1.239 raeburn 7141: }
1.363 raeburn 7142: if ($context eq 'course') {
1.376 raeburn 7143: if (($chgtype eq 'automated') || ($chgtype eq 'updatenow')) {
1.363 raeburn 7144: next if (!&Apache::lonnet::auto_run($cnum,$cdom));
7145: }
1.239 raeburn 7146: }
7147: $output .= '<option value="'.$chgtype.'"'.$selstr.'>'.$lt{$chgtype}.'</option>'."\n";
1.248 raeburn 7148: }
1.303 bisitz 7149: $output .= '</select></td>'
7150: .'</tr></table>';
7151:
7152: # Update Display button
7153: $output .= '<p>'
7154: .'<input type="submit" value="'.&mt('Update Display').'" />'
7155: .'</p>';
7156:
7157: # Server version info
1.363 raeburn 7158: my $needsrev = '2.11.0';
7159: if ($context eq 'course') {
7160: $needsrev = '2.7.0';
7161: }
7162:
1.303 bisitz 7163: $output .= '<p class="LC_info">'
7164: .&mt('Only changes made from servers running LON-CAPA [_1] or later are displayed.'
1.363 raeburn 7165: ,$needsrev);
1.248 raeburn 7166: if ($version) {
1.303 bisitz 7167: $output .= ' '.&mt('This LON-CAPA server is version [_1]',$version);
7168: }
7169: $output .= '</p><hr />';
1.239 raeburn 7170: return $output;
7171: }
7172:
7173: sub rolechg_contexts {
1.363 raeburn 7174: my ($context,$crstype) = @_;
7175: my %lt;
7176: if ($context eq 'course') {
7177: %lt = &Apache::lonlocal::texthash (
1.239 raeburn 7178: any => 'Any',
1.376 raeburn 7179: automated => 'Automated Enrollment',
1.239 raeburn 7180: updatenow => 'Roster Update',
7181: createcourse => 'Course Creation',
7182: course => 'User Management in course',
7183: domain => 'User Management in domain',
1.313 raeburn 7184: selfenroll => 'Self-enrolled',
1.318 raeburn 7185: requestcourses => 'Course Request',
1.239 raeburn 7186: );
1.363 raeburn 7187: if ($crstype eq 'Community') {
7188: $lt{'createcourse'} = &mt('Community Creation');
7189: $lt{'course'} = &mt('User Management in community');
7190: $lt{'requestcourses'} = &mt('Community Request');
7191: }
7192: } elsif ($context eq 'domain') {
7193: %lt = &Apache::lonlocal::texthash (
7194: any => 'Any',
7195: domain => 'User Management in domain',
7196: requestauthor => 'Authoring Request',
7197: server => 'Command line script (DC role)',
7198: domconfig => 'Self-enrolled',
7199: );
7200: } else {
7201: %lt = &Apache::lonlocal::texthash (
7202: any => 'Any',
7203: domain => 'User Management in domain',
7204: author => 'User Management by author',
7205: );
7206: }
1.239 raeburn 7207: return %lt;
7208: }
7209:
1.406.2.10 raeburn 7210: sub print_helpdeskaccess_display {
7211: my ($r,$permission,$brcrum) = @_;
7212: my $formname = 'helpdeskaccess';
7213: my $helpitem = 'Course_Helpdesk_Access';
7214: push (@{$brcrum},
7215: {href => '/adm/createuser?action=helpdesk',
7216: text => 'Helpdesk Access',
7217: help => $helpitem});
7218: my $bread_crumbs_component = 'Helpdesk Staff Access';
7219: my $args = { bread_crumbs => $brcrum,
7220: bread_crumbs_component => $bread_crumbs_component};
7221:
7222: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
7223: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
7224: my $confname = $cdom.'-domainconfig';
7225: my $crstype = &Apache::loncommon::course_type();
7226:
1.406.2.12 raeburn 7227: my @accesstypes = ('all','dh','da','none');
1.406.2.10 raeburn 7228: my ($numstatustypes,@jsarray);
7229: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($cdom);
7230: if (ref($types) eq 'ARRAY') {
7231: if (@{$types} > 0) {
7232: $numstatustypes = scalar(@{$types});
7233: push(@accesstypes,'status');
7234: @jsarray = ('bystatus');
7235: }
7236: }
7237: my %customroles = &get_domain_customroles($cdom,$confname);
1.406.2.12 raeburn 7238: my %domhelpdesk = &Apache::lonnet::get_active_domroles($cdom,['dh','da']);
1.406.2.10 raeburn 7239: if (keys(%domhelpdesk)) {
7240: push(@accesstypes,('inc','exc'));
7241: push(@jsarray,('notinc','notexc'));
7242: }
7243: push(@jsarray,'privs');
7244: my $hiddenstr = join("','",@jsarray);
7245: my $rolestr = join("','",sort(keys(%customroles)));
7246:
7247: my $jscript;
7248: my (%settings,%overridden);
7249: if (keys(%customroles)) {
7250: &get_adhocrole_settings($env{'request.course.id'},\@accesstypes,
7251: $types,\%customroles,\%settings,\%overridden);
7252: my %jsfull=();
7253: my %jslevels= (
7254: course => {},
7255: domain => {},
7256: system => {},
7257: );
7258: my %jslevelscurrent=(
7259: course => {},
7260: domain => {},
7261: system => {},
7262: );
7263: my (%privs,%jsprivs);
7264: &Apache::lonuserutils::custom_role_privs(\%privs,\%jsfull,\%jslevels,\%jslevelscurrent);
7265: foreach my $priv (keys(%jsfull)) {
7266: if ($jslevels{'course'}{$priv}) {
7267: $jsprivs{$priv} = 1;
7268: }
7269: }
7270: my (%elements,%stored);
7271: foreach my $role (keys(%customroles)) {
7272: $elements{$role.'_access'} = 'radio';
7273: $elements{$role.'_incrs'} = 'radio';
7274: if ($numstatustypes) {
7275: $elements{$role.'_status'} = 'checkbox';
7276: }
7277: if (keys(%domhelpdesk) > 0) {
7278: $elements{$role.'_staff_inc'} = 'checkbox';
7279: $elements{$role.'_staff_exc'} = 'checkbox';
7280: }
7281: $elements{$role.'_override'} = 'checkbox';
7282: if (ref($settings{$role}) eq 'HASH') {
7283: if ($settings{$role}{'access'} ne '') {
7284: my $curraccess = $settings{$role}{'access'};
7285: $stored{$role.'_access'} = $curraccess;
7286: $stored{$role.'_incrs'} = 1;
7287: if ($curraccess eq 'status') {
7288: if (ref($settings{$role}{'status'}) eq 'ARRAY') {
7289: $stored{$role.'_status'} = $settings{$role}{'status'};
7290: }
7291: } elsif (($curraccess eq 'exc') || ($curraccess eq 'inc')) {
7292: if (ref($settings{$role}{$curraccess}) eq 'ARRAY') {
7293: $stored{$role.'_staff_'.$curraccess} = $settings{$role}{$curraccess};
7294: }
7295: }
7296: } else {
7297: $stored{$role.'_incrs'} = 0;
7298: }
7299: $stored{$role.'_override'} = [];
7300: if ($env{'course.'.$env{'request.course.id'}.'.internal.adhocpriv.'.$role}) {
7301: if (ref($settings{$role}{'off'}) eq 'ARRAY') {
7302: foreach my $priv (@{$settings{$role}{'off'}}) {
7303: push(@{$stored{$role.'_override'}},$priv);
7304: }
7305: }
7306: if (ref($settings{$role}{'on'}) eq 'ARRAY') {
7307: foreach my $priv (@{$settings{$role}{'on'}}) {
7308: unless (grep(/^$priv$/,@{$stored{$role.'_override'}})) {
7309: push(@{$stored{$role.'_override'}},$priv);
7310: }
7311: }
7312: }
7313: }
7314: } else {
7315: $stored{$role.'_incrs'} = 0;
7316: }
7317: }
7318: $jscript = &Apache::lonhtmlcommon::set_form_elements(\%elements,\%stored);
7319: }
7320:
7321: my $js = <<"ENDJS";
7322: <script type="text/javascript">
7323: // <![CDATA[
7324: $jscript;
7325:
7326: function switchRoleTab(caller,role) {
7327: if (document.getElementById(role+'_maindiv')) {
7328: if (caller.id != 'LC_current_minitab') {
7329: if (document.getElementById('LC_current_minitab')) {
7330: document.getElementById('LC_current_minitab').id=null;
7331: }
7332: var roledivs = Array('$rolestr');
7333: if (roledivs.length > 0) {
7334: for (var i=0; i<roledivs.length; i++) {
7335: if (document.getElementById(roledivs[i]+'_maindiv')) {
7336: document.getElementById(roledivs[i]+'_maindiv').style.display='none';
7337: }
7338: }
7339: }
7340: caller.id = 'LC_current_minitab';
7341: document.getElementById(role+'_maindiv').style.display='block';
7342: }
7343: }
7344: return false;
7345: }
7346:
7347: function helpdeskAccess(role) {
7348: var curraccess = null;
7349: if (document.$formname.elements[role+'_access'].length) {
7350: for (var i=0; i<document.$formname.elements[role+'_access'].length; i++) {
7351: if (document.$formname.elements[role+'_access'][i].checked) {
7352: curraccess = document.$formname.elements[role+'_access'][i].value;
7353: }
7354: }
7355: }
7356: var shown = Array();
7357: var hidden = Array();
7358: if (curraccess == 'none') {
7359: hidden = Array ('$hiddenstr');
7360: } else {
7361: if (curraccess == 'status') {
7362: shown = Array ('bystatus','privs');
7363: hidden = Array ('notinc','notexc');
7364: } else {
7365: if (curraccess == 'exc') {
7366: shown = Array ('notexc','privs');
7367: hidden = Array ('notinc','bystatus');
7368: }
7369: if (curraccess == 'inc') {
7370: shown = Array ('notinc','privs');
7371: hidden = Array ('notexc','bystatus');
7372: }
7373: if (curraccess == 'all') {
7374: shown = Array ('privs');
7375: hidden = Array ('notinc','notexc','bystatus');
7376: }
7377: }
7378: }
7379: if (hidden.length > 0) {
7380: for (var i=0; i<hidden.length; i++) {
7381: if (document.getElementById(role+'_'+hidden[i])) {
7382: document.getElementById(role+'_'+hidden[i]).style.display = 'none';
7383: }
7384: }
7385: }
7386: if (shown.length > 0) {
7387: for (var i=0; i<shown.length; i++) {
7388: if (document.getElementById(role+'_'+shown[i])) {
7389: if (shown[i] == 'privs') {
7390: document.getElementById(role+'_'+shown[i]).style.display = 'block';
7391: } else {
7392: document.getElementById(role+'_'+shown[i]).style.display = 'inline';
7393: }
7394: }
7395: }
7396: }
7397: return;
7398: }
7399:
7400: function toggleAccess(role) {
7401: if ((document.getElementById(role+'_setincrs')) &&
7402: (document.getElementById(role+'_setindom'))) {
7403: for (var i=0; i<document.$formname.elements[role+'_incrs'].length; i++) {
7404: if (document.$formname.elements[role+'_incrs'][i].checked) {
7405: if (document.$formname.elements[role+'_incrs'][i].value == 1) {
7406: document.getElementById(role+'_setindom').style.display = 'none';
7407: document.getElementById(role+'_setincrs').style.display = 'block';
7408: } else {
7409: document.getElementById(role+'_setincrs').style.display = 'none';
7410: document.getElementById(role+'_setindom').style.display = 'block';
7411: }
7412: break;
7413: }
7414: }
7415: }
7416: return;
7417: }
7418:
7419: // ]]>
7420: </script>
7421: ENDJS
7422:
7423: $args->{add_entries} = {onload => "javascript:setFormElements(document.$formname)"};
7424:
7425: # print page header
7426: $r->print(&header($js,$args));
7427: # print form header
7428: $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">');
7429:
7430: if (keys(%customroles)) {
7431: my %lt = &Apache::lonlocal::texthash(
7432: 'aco' => 'As course owner you may override the defaults set in the domain for role usage and/or privileges.',
7433: 'rou' => 'Role usage',
7434: 'whi' => 'Which helpdesk personnel may use this role?',
7435: 'udd' => 'Use domain default',
1.406.2.12 raeburn 7436: 'all' => 'All with domain helpdesk or helpdesk assistant role',
7437: 'dh' => 'All with domain helpdesk role',
7438: 'da' => 'All with domain helpdesk assistant role',
1.406.2.10 raeburn 7439: 'none' => 'None',
7440: 'status' => 'Determined based on institutional status',
7441: 'inc' => 'Include all, but exclude specific personnel',
7442: 'exc' => 'Exclude all, but include specific personnel',
7443: 'hel' => 'Helpdesk',
7444: 'rpr' => 'Role privileges',
7445: );
7446: $lt{'tfh'} = &mt("Custom [_1]ad hoc[_2] course roles available for use by the domain's helpdesk are as follows",'<i>','</i>');
7447: my %domconfig = &Apache::lonnet::get_dom('configuration',['helpsettings'],$cdom);
7448: my (%domcurrent,%ordered,%description,%domusage,$disabled);
7449: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
7450: if (ref($domconfig{'helpsettings'}{'adhoc'}) eq 'HASH') {
7451: %domcurrent = %{$domconfig{'helpsettings'}{'adhoc'}};
7452: }
7453: }
7454: my $count = 0;
7455: foreach my $role (sort(keys(%customroles))) {
7456: my ($order,$desc,$access_in_dom);
7457: if (ref($domcurrent{$role}) eq 'HASH') {
7458: $order = $domcurrent{$role}{'order'};
7459: $desc = $domcurrent{$role}{'desc'};
7460: $access_in_dom = $domcurrent{$role}{'access'};
7461: }
7462: if ($order eq '') {
7463: $order = $count;
7464: }
7465: $ordered{$order} = $role;
7466: if ($desc ne '') {
7467: $description{$role} = $desc;
7468: } else {
7469: $description{$role}= $role;
7470: }
7471: $count++;
7472: }
7473: %domusage = &domain_adhoc_access(\%customroles,\%domcurrent,\@accesstypes,$usertypes,$othertitle);
7474: my @roles_by_num = ();
7475: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
7476: push(@roles_by_num,$ordered{$item});
7477: }
7478: $r->print('<p>'.$lt{'tfh'}.': <i>'.join('</i>, <i>',map { $description{$_}; } @roles_by_num).'</i>.');
7479: if ($permission->{'owner'}) {
7480: $r->print('<br />'.$lt{'aco'}.'</p><p>');
7481: $r->print('<input type="hidden" name="state" value="process" />'.
7482: '<input type="submit" value="'.&mt('Save changes').'" />');
7483: } else {
7484: if ($env{'course.'.$env{'request.course.id'}.'.internal.courseowner'}) {
7485: my ($ownername,$ownerdom) = split(/:/,$env{'course.'.$env{'request.course.id'}.'.internal.courseowner'});
7486: $r->print('<br />'.&mt('The course owner -- [_1] -- can override the default access and/or privileges for these ad hoc roles.',
7487: &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($ownername,$ownerdom),$ownername,$ownerdom)));
7488: }
7489: $disabled = ' disabled="disabled"';
7490: }
7491: $r->print('</p>');
7492:
7493: $r->print('<div id="LC_minitab_header"><ul>');
7494: my $count = 0;
7495: my %visibility;
7496: foreach my $role (@roles_by_num) {
7497: my $id;
7498: if ($count == 0) {
7499: $id=' id="LC_current_minitab"';
7500: $visibility{$role} = ' style="display:block"';
7501: } else {
7502: $visibility{$role} = ' style="display:none"';
7503: }
7504: $count ++;
7505: $r->print('<li'.$id.'><a href="#" onclick="javascript:switchRoleTab(this.parentNode,'."'$role'".');">'.$description{$role}.'</a></li>');
7506: }
7507: $r->print('</ul></div>');
7508:
7509: foreach my $role (@roles_by_num) {
7510: my %usecheck = (
7511: all => ' checked="checked"',
7512: );
7513: my %displaydiv = (
7514: status => 'none',
7515: inc => 'none',
7516: exc => 'none',
7517: priv => 'block',
7518: );
7519: my (%selected,$overridden,$incrscheck,$indomcheck,$indomvis,$incrsvis);
7520: if (ref($settings{$role}) eq 'HASH') {
7521: if ($settings{$role}{'access'} ne '') {
7522: $indomvis = ' style="display:none"';
7523: $incrsvis = ' style="display:block"';
7524: $incrscheck = ' checked="checked"';
7525: if ($settings{$role}{'access'} ne 'all') {
7526: $usecheck{$settings{$role}{'access'}} = $usecheck{'all'};
7527: delete($usecheck{'all'});
7528: if ($settings{$role}{'access'} eq 'status') {
7529: my $access = 'status';
7530: $displaydiv{$access} = 'inline';
7531: if (ref($settings{$role}{$access}) eq 'ARRAY') {
7532: $selected{$access} = $settings{$role}{$access};
7533: }
7534: } elsif ($settings{$role}{'access'} =~ /^(inc|exc)$/) {
7535: my $access = $1;
7536: $displaydiv{$access} = 'inline';
7537: if (ref($settings{$role}{$access}) eq 'ARRAY') {
7538: $selected{$access} = $settings{$role}{$access};
7539: }
7540: } elsif ($settings{$role}{'access'} eq 'none') {
7541: $displaydiv{'priv'} = 'none';
7542: }
7543: }
7544: } else {
7545: $indomcheck = ' checked="checked"';
7546: $indomvis = ' style="display:block"';
7547: $incrsvis = ' style="display:none"';
7548: }
7549: } else {
7550: $indomcheck = ' checked="checked"';
7551: $indomvis = ' style="display:block"';
7552: $incrsvis = ' style="display:none"';
7553: }
7554: $r->print('<div class="LC_left_float" id="'.$role.'_maindiv"'.$visibility{$role}.'>'.
7555: '<fieldset><legend>'.$lt{'rou'}.'</legend>'.
7556: '<p>'.$lt{'whi'}.' <span class="LC_nobreak">'.
7557: '<label><input type="radio" name="'.$role.'_incrs" value="1"'.$incrscheck.' onclick="toggleAccess('."'$role'".');"'.$disabled.'>'.
7558: &mt('Set here in [_1]',lc($crstype)).'</label>'.
7559: '<span>'.(' 'x2).
7560: '<label><input type="radio" name="'.$role.'_incrs" value="0"'.$indomcheck.' onclick="toggleAccess('."'$role'".');"'.$disabled.'>'.
7561: $lt{'udd'}.'</label><span></p>'.
7562: '<div id="'.$role.'_setindom"'.$indomvis.'>'.
7563: '<span class="LC_cusr_emph">'.$domusage{$role}.'</span></div>'.
7564: '<div id="'.$role.'_setincrs"'.$incrsvis.'>');
7565: foreach my $access (@accesstypes) {
7566: $r->print('<p><label><input type="radio" name="'.$role.'_access" value="'.$access.'" '.$usecheck{$access}.
7567: ' onclick="helpdeskAccess('."'$role'".');"'.$disabled.' />'.$lt{$access}.'</label>');
7568: if ($access eq 'status') {
7569: $r->print('<div id="'.$role.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
7570: &Apache::lonuserutils::adhoc_status_types($cdom,undef,$role,$selected{$access},
7571: $othertitle,$usertypes,$types,$disabled).
7572: '</div>');
7573: } elsif (($access eq 'inc') && (keys(%domhelpdesk) > 0)) {
7574: $r->print('<div id="'.$role.'_notinc" style="display:'.$displaydiv{$access}.'">'.
7575: &Apache::lonuserutils::adhoc_staff($access,undef,$role,$selected{$access},
7576: \%domhelpdesk,$disabled).
7577: '</div>');
7578: } elsif (($access eq 'exc') && (keys(%domhelpdesk) > 0)) {
7579: $r->print('<div id="'.$role.'_notexc" style="display:'.$displaydiv{$access}.'">'.
7580: &Apache::lonuserutils::adhoc_staff($access,undef,$role,$selected{$access},
7581: \%domhelpdesk,$disabled).
7582: '</div>');
7583: }
7584: $r->print('</p>');
7585: }
7586: $r->print('</div></fieldset>');
7587: my %full=();
7588: my %levels= (
7589: course => {},
7590: domain => {},
7591: system => {},
7592: );
7593: my %levelscurrent=(
7594: course => {},
7595: domain => {},
7596: system => {},
7597: );
7598: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
7599: $r->print('<fieldset id="'.$role.'_privs" style="display:'.$displaydiv{'priv'}.'">'.
7600: '<legend>'.$lt{'rpr'}.'</legend>'.
7601: &role_priv_table($role,$permission,$crstype,\%full,\%levels,\%levelscurrent,$overridden{$role}).
7602: '</fieldset></div><div style="padding:0;clear:both;margin:0;border:0"></div>');
7603: }
7604: if ($permission->{'owner'}) {
7605: $r->print('<p><input type="submit" value="'.&mt('Save changes').'" /></p>');
7606: }
7607: } else {
7608: $r->print(&mt('Helpdesk roles have not yet been created in this domain.'));
7609: }
7610: # Form Footer
7611: $r->print('<input type="hidden" name="action" value="helpdesk" />'
7612: .'</form>');
7613: return;
7614: }
7615:
7616: sub domain_adhoc_access {
7617: my ($roles,$domcurrent,$accesstypes,$usertypes,$othertitle) = @_;
7618: my %domusage;
7619: return unless ((ref($roles) eq 'HASH') && (ref($domcurrent) eq 'HASH') && (ref($accesstypes) eq 'ARRAY'));
7620: foreach my $role (keys(%{$roles})) {
7621: if (ref($domcurrent->{$role}) eq 'HASH') {
7622: my $access = $domcurrent->{$role}{'access'};
7623: if (($access eq '') || (!grep(/^\Q$access\E$/,@{$accesstypes}))) {
7624: $access = 'all';
1.406.2.12 raeburn 7625: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role',&Apache::lonnet::plaintext('dh'),
7626: &Apache::lonnet::plaintext('da'));
1.406.2.10 raeburn 7627: } elsif ($access eq 'status') {
7628: if (ref($domcurrent->{$role}{$access}) eq 'ARRAY') {
7629: my @shown;
7630: foreach my $type (@{$domcurrent->{$role}{$access}}) {
7631: unless ($type eq 'default') {
7632: if ($usertypes->{$type}) {
7633: push(@shown,$usertypes->{$type});
7634: }
7635: }
7636: }
7637: if (grep(/^default$/,@{$domcurrent->{$role}{$access}})) {
7638: push(@shown,$othertitle);
7639: }
7640: if (@shown) {
7641: my $shownstatus = join(' '.&mt('or').' ',@shown);
1.406.2.12 raeburn 7642: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role, and institutional status: [_3]',
7643: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'),$shownstatus);
1.406.2.10 raeburn 7644: } else {
7645: $domusage{$role} = &mt('No one in the domain');
7646: }
7647: }
7648: } elsif ($access eq 'inc') {
7649: my @dominc = ();
7650: if (ref($domcurrent->{$role}{'inc'}) eq 'ARRAY') {
7651: foreach my $user (@{$domcurrent->{$role}{'inc'}}) {
7652: my ($uname,$udom) = split(/:/,$user);
7653: push(@dominc,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),$uname,$udom));
7654: }
7655: my $showninc = join(', ',@dominc);
7656: if ($showninc ne '') {
1.406.2.12 raeburn 7657: $domusage{$role} = &mt('Include any user in domain with active [_1] or [_2] role, except: [_3]',
7658: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'),$showninc);
1.406.2.10 raeburn 7659: } else {
1.406.2.12 raeburn 7660: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role',
7661: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'));
1.406.2.10 raeburn 7662: }
7663: }
7664: } elsif ($access eq 'exc') {
7665: my @domexc = ();
7666: if (ref($domcurrent->{$role}{'exc'}) eq 'ARRAY') {
7667: foreach my $user (@{$domcurrent->{$role}{'exc'}}) {
7668: my ($uname,$udom) = split(/:/,$user);
7669: push(@domexc,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),$uname,$udom));
7670: }
7671: }
7672: my $shownexc = join(', ',@domexc);
7673: if ($shownexc ne '') {
1.406.2.12 raeburn 7674: $domusage{$role} = &mt('Only the following in the domain with active [_1] or [_2] role: [_3]',
7675: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'),$shownexc);
1.406.2.10 raeburn 7676: } else {
7677: $domusage{$role} = &mt('No one in the domain');
7678: }
7679: } elsif ($access eq 'none') {
7680: $domusage{$role} = &mt('No one in the domain');
1.406.2.12 raeburn 7681: } elsif ($access eq 'dh') {
1.406.2.10 raeburn 7682: $domusage{$role} = &mt('Any user in domain with active [_1] role',&Apache::lonnet::plaintext('dh'));
1.406.2.12 raeburn 7683: } elsif ($access eq 'da') {
7684: $domusage{$role} = &mt('Any user in domain with active [_1] role',&Apache::lonnet::plaintext('da'));
7685: } elsif ($access eq 'all') {
7686: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role',
7687: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'));
1.406.2.10 raeburn 7688: }
7689: } else {
1.406.2.12 raeburn 7690: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role',
7691: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'));
1.406.2.10 raeburn 7692: }
7693: }
7694: return %domusage;
7695: }
7696:
7697: sub get_domain_customroles {
7698: my ($cdom,$confname) = @_;
7699: my %existing=&Apache::lonnet::dump('roles',$cdom,$confname,'rolesdef_');
7700: my %customroles;
7701: foreach my $key (keys(%existing)) {
7702: if ($key=~/^rolesdef\_(\w+)$/) {
7703: my $rolename = $1;
7704: my %privs;
7705: ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
7706: $customroles{$rolename} = \%privs;
7707: }
7708: }
7709: return %customroles;
7710: }
7711:
7712: sub role_priv_table {
7713: my ($role,$permission,$crstype,$full,$levels,$levelscurrent,$overridden) = @_;
7714: return unless ((ref($full) eq 'HASH') && (ref($levels) eq 'HASH') &&
7715: (ref($levelscurrent) eq 'HASH'));
7716: my %lt=&Apache::lonlocal::texthash (
7717: 'crl' => 'Course Level Privilege',
7718: 'def' => 'Domain Defaults',
7719: 'ove' => 'Override in Course',
7720: 'ine' => 'In effect',
7721: 'dis' => 'Disabled',
7722: 'ena' => 'Enabled',
7723: );
7724: if ($crstype eq 'Community') {
7725: $lt{'ove'} = 'Override in Community',
7726: }
7727: my @status = ('Disabled','Enabled');
7728: my (%on,%off);
7729: if (ref($overridden) eq 'HASH') {
7730: if (ref($overridden->{'on'}) eq 'ARRAY') {
7731: map { $on{$_} = 1; } (@{$overridden->{'on'}});
7732: }
7733: if (ref($overridden->{'off'}) eq 'ARRAY') {
7734: map { $off{$_} = 1; } (@{$overridden->{'off'}});
7735: }
7736: }
7737: my $output=&Apache::loncommon::start_data_table().
7738: &Apache::loncommon::start_data_table_header_row().
7739: '<th>'.$lt{'crl'}.'</th><th>'.$lt{'def'}.'</th><th>'.$lt{'ove'}.
7740: '</th><th>'.$lt{'ine'}.'</th>'.
7741: &Apache::loncommon::end_data_table_header_row();
7742: foreach my $priv (sort(keys(%{$full}))) {
7743: next unless ($levels->{'course'}{$priv});
7744: my $privtext = &Apache::lonnet::plaintext($priv,$crstype);
7745: my ($default,$ineffect);
7746: if ($levelscurrent->{'course'}{$priv}) {
7747: $default = '<img src="/adm/lonIcons/navmap.correct.gif" alt="'.$lt{'ena'}.'" />';
7748: $ineffect = $default;
7749: }
7750: my ($customstatus,$checked);
7751: $output .= &Apache::loncommon::start_data_table_row().
7752: '<td>'.$privtext.'</td>'.
7753: '<td>'.$default.'</td><td>';
7754: if (($levelscurrent->{'course'}{$priv}) && ($off{$priv})) {
7755: if ($permission->{'owner'}) {
7756: $checked = ' checked="checked"';
7757: }
7758: $customstatus = '<img src="/adm/lonIcons/navmap.wrong.gif" alt="'.$lt{'dis'}.'" />';
7759: $ineffect = $customstatus;
7760: } elsif ((!$levelscurrent->{'course'}{$priv}) && ($on{$priv})) {
7761: if ($permission->{'owner'}) {
7762: $checked = ' checked="checked"';
7763: }
7764: $customstatus = '<img src="/adm/lonIcons/navmap.correct.gif" alt="'.$lt{'ena'}.'" />';
7765: $ineffect = $customstatus;
7766: }
7767: if ($permission->{'owner'}) {
7768: $output .= '<input type="checkbox" name="'.$role.'_override" value="'.$priv.'"'.$checked.' />';
7769: } else {
7770: $output .= $customstatus;
7771: }
7772: $output .= '</td><td>'.$ineffect.'</td>'.
7773: &Apache::loncommon::end_data_table_row();
7774: }
7775: $output .= &Apache::loncommon::end_data_table();
7776: return $output;
7777: }
7778:
7779: sub get_adhocrole_settings {
7780: my ($cid,$accesstypes,$types,$customroles,$settings,$overridden) = @_;
7781: return unless ((ref($accesstypes) eq 'ARRAY') && (ref($customroles) eq 'HASH') &&
7782: (ref($settings) eq 'HASH') && (ref($overridden) eq 'HASH'));
7783: foreach my $role (split(/,/,$env{'course.'.$cid.'.internal.adhocaccess'})) {
7784: my ($curraccess,$rest) = split(/=/,$env{'course.'.$cid.'.internal.adhoc.'.$role});
7785: if (($curraccess ne '') && (grep(/^\Q$curraccess\E$/,@{$accesstypes}))) {
7786: $settings->{$role}{'access'} = $curraccess;
7787: if (($curraccess eq 'status') && (ref($types) eq 'ARRAY')) {
7788: my @status = split(/,/,$rest);
7789: my @currstatus;
7790: foreach my $type (@status) {
7791: if ($type eq 'default') {
7792: push(@currstatus,$type);
7793: } elsif (grep(/^\Q$type\E$/,@{$types})) {
7794: push(@currstatus,$type);
7795: }
7796: }
7797: if (@currstatus) {
7798: $settings->{$role}{$curraccess} = \@currstatus;
7799: } elsif (($curraccess eq 'exc') || ($curraccess eq 'inc')) {
7800: my @personnel = split(/,/,$rest);
7801: $settings->{$role}{$curraccess} = \@personnel;
7802: }
7803: }
7804: }
7805: }
7806: foreach my $role (keys(%{$customroles})) {
7807: if ($env{'course.'.$cid.'.internal.adhocpriv.'.$role}) {
7808: my %currentprivs;
7809: if (ref($customroles->{$role}) eq 'HASH') {
7810: if (exists($customroles->{$role}{'course'})) {
7811: my %full=();
7812: my %levels= (
7813: course => {},
7814: domain => {},
7815: system => {},
7816: );
7817: my %levelscurrent=(
7818: course => {},
7819: domain => {},
7820: system => {},
7821: );
7822: &Apache::lonuserutils::custom_role_privs($customroles->{$role},\%full,\%levels,\%levelscurrent);
7823: %currentprivs = %{$levelscurrent{'course'}};
7824: }
7825: }
7826: foreach my $item (split(/,/,$env{'course.'.$cid.'.internal.adhocpriv.'.$role})) {
7827: next if ($item eq '');
7828: my ($rule,$rest) = split(/=/,$item);
7829: next unless (($rule eq 'off') || ($rule eq 'on'));
7830: foreach my $priv (split(/:/,$rest)) {
7831: if ($priv ne '') {
7832: if ($rule eq 'off') {
7833: push(@{$overridden->{$role}{'off'}},$priv);
7834: if ($currentprivs{$priv}) {
7835: push(@{$settings->{$role}{'off'}},$priv);
7836: }
7837: } else {
7838: push(@{$overridden->{$role}{'on'}},$priv);
7839: unless ($currentprivs{$priv}) {
7840: push(@{$settings->{$role}{'on'}},$priv);
7841: }
7842: }
7843: }
7844: }
7845: }
7846: }
7847: }
7848: return;
7849: }
7850:
7851: sub update_helpdeskaccess {
7852: my ($r,$permission,$brcrum) = @_;
7853: my $helpitem = 'Course_Helpdesk_Access';
7854: push (@{$brcrum},
7855: {href => '/adm/createuser?action=helpdesk',
7856: text => 'Helpdesk Access',
7857: help => $helpitem},
7858: {href => '/adm/createuser?action=helpdesk',
7859: text => 'Result',
7860: help => $helpitem}
7861: );
7862: my $bread_crumbs_component = 'Helpdesk Staff Access';
7863: my $args = { bread_crumbs => $brcrum,
7864: bread_crumbs_component => $bread_crumbs_component};
7865:
7866: # print page header
7867: $r->print(&header('',$args));
7868: unless ((ref($permission) eq 'HASH') && ($permission->{'owner'})) {
7869: $r->print('<p class="LC_error">'.&mt('You do not have permission to change helpdesk access.').'</p>');
7870: return;
7871: }
1.406.2.12 raeburn 7872: my @accesstypes = ('all','dh','da','none','status','inc','exc');
1.406.2.10 raeburn 7873: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
7874: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
7875: my $confname = $cdom.'-domainconfig';
7876: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($cdom);
7877: my $crstype = &Apache::loncommon::course_type();
7878: my %customroles = &get_domain_customroles($cdom,$confname);
7879: my (%settings,%overridden);
7880: &get_adhocrole_settings($env{'request.course.id'},\@accesstypes,
7881: $types,\%customroles,\%settings,\%overridden);
1.406.2.12 raeburn 7882: my %domhelpdesk = &Apache::lonnet::get_active_domroles($cdom,['dh','da']);
1.406.2.10 raeburn 7883: my (%changed,%storehash,@todelete);
7884:
7885: if (keys(%customroles)) {
7886: my (%newsettings,@incrs);
7887: foreach my $role (keys(%customroles)) {
7888: $newsettings{$role} = {
7889: access => '',
7890: status => '',
7891: exc => '',
7892: inc => '',
7893: on => '',
7894: off => '',
7895: };
7896: my %current;
7897: if (ref($settings{$role}) eq 'HASH') {
7898: %current = %{$settings{$role}};
7899: }
7900: if (ref($overridden{$role}) eq 'HASH') {
7901: $current{'overridden'} = $overridden{$role};
7902: }
7903: if ($env{'form.'.$role.'_incrs'}) {
7904: my $access = $env{'form.'.$role.'_access'};
7905: if (grep(/^\Q$access\E$/,@accesstypes)) {
7906: push(@incrs,$role);
7907: unless ($current{'access'} eq $access) {
7908: $changed{$role}{'access'} = 1;
7909: $storehash{'internal.adhoc.'.$role} = $access;
7910: }
7911: if ($access eq 'status') {
7912: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$role.'_status');
7913: my @stored;
7914: my @shownstatus;
7915: if (ref($types) eq 'ARRAY') {
7916: foreach my $type (sort(@statuses)) {
7917: if ($type eq 'default') {
7918: push(@stored,$type);
7919: } elsif (grep(/^\Q$type\E$/,@{$types})) {
7920: push(@stored,$type);
7921: push(@shownstatus,$usertypes->{$type});
7922: }
7923: }
7924: if (grep(/^default$/,@statuses)) {
7925: push(@shownstatus,$othertitle);
7926: }
7927: $storehash{'internal.adhoc.'.$role} .= '='.join(',',@stored);
7928: }
7929: $newsettings{$role}{'status'} = join(' '.&mt('or').' ',@shownstatus);
7930: if (ref($current{'status'}) eq 'ARRAY') {
7931: my @diffs = &Apache::loncommon::compare_arrays(\@stored,$current{'status'});
7932: if (@diffs) {
7933: $changed{$role}{'status'} = 1;
7934: }
7935: } elsif (@stored) {
7936: $changed{$role}{'status'} = 1;
7937: }
7938: } elsif (($access eq 'inc') || ($access eq 'exc')) {
7939: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$role.'_staff_'.$access);
7940: my @newspecstaff;
7941: my @stored;
7942: my @currstaff;
7943: foreach my $person (sort(@personnel)) {
7944: if ($domhelpdesk{$person}) {
7945: push(@stored,$person);
7946: }
7947: }
7948: if (ref($current{$access}) eq 'ARRAY') {
7949: my @diffs = &Apache::loncommon::compare_arrays(\@stored,$current{$access});
7950: if (@diffs) {
7951: $changed{$role}{$access} = 1;
7952: }
7953: } elsif (@stored) {
7954: $changed{$role}{$access} = 1;
7955: }
7956: $storehash{'internal.adhoc.'.$role} .= '='.join(',',@stored);
7957: foreach my $person (@stored) {
7958: my ($uname,$udom) = split(/:/,$person);
7959: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
7960: }
7961: $newsettings{$role}{$access} = join(', ',sort(@newspecstaff));
7962: }
7963: $newsettings{$role}{'access'} = $access;
7964: }
7965: } else {
7966: if (($current{'access'} ne '') && (grep(/^\Q$current{'access'}\E$/,@accesstypes))) {
7967: $changed{$role}{'access'} = 1;
7968: $newsettings{$role} = {};
7969: push(@todelete,'internal.adhoc.'.$role);
7970: }
7971: }
7972: if (($env{'form.'.$role.'_incrs'}) && ($env{'form.'.$role.'_access'} eq 'none')) {
7973: if (ref($current{'overridden'}) eq 'HASH') {
7974: push(@todelete,'internal.adhocpriv.'.$role);
7975: }
7976: } else {
7977: my %full=();
7978: my %levels= (
7979: course => {},
7980: domain => {},
7981: system => {},
7982: );
7983: my %levelscurrent=(
7984: course => {},
7985: domain => {},
7986: system => {},
7987: );
7988: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
7989: my (@updatedon,@updatedoff,@override);
7990: @override = &Apache::loncommon::get_env_multiple('form.'.$role.'_override');
7991: if (@override) {
7992: foreach my $priv (sort(keys(%full))) {
7993: next unless ($levels{'course'}{$priv});
7994: if (grep(/^\Q$priv\E$/,@override)) {
7995: if ($levelscurrent{'course'}{$priv}) {
7996: push(@updatedoff,$priv);
7997: } else {
7998: push(@updatedon,$priv);
7999: }
8000: }
8001: }
8002: }
8003: if (@updatedon) {
8004: $newsettings{$role}{'on'} = join('</li><li>', map { &Apache::lonnet::plaintext($_,$crstype) } (@updatedon));
8005: }
8006: if (@updatedoff) {
8007: $newsettings{$role}{'off'} = join('</li><li>', map { &Apache::lonnet::plaintext($_,$crstype) } (@updatedoff));
8008: }
8009: if (ref($current{'overridden'}) eq 'HASH') {
8010: if (ref($current{'overridden'}{'on'}) eq 'ARRAY') {
8011: if (@updatedon) {
8012: my @diffs = &Apache::loncommon::compare_arrays(\@updatedon,$current{'overridden'}{'on'});
8013: if (@diffs) {
8014: $changed{$role}{'on'} = 1;
8015: }
8016: } else {
8017: $changed{$role}{'on'} = 1;
8018: }
8019: } elsif (@updatedon) {
8020: $changed{$role}{'on'} = 1;
8021: }
8022: if (ref($current{'overridden'}{'off'}) eq 'ARRAY') {
8023: if (@updatedoff) {
8024: my @diffs = &Apache::loncommon::compare_arrays(\@updatedoff,$current{'overridden'}{'off'});
8025: if (@diffs) {
8026: $changed{$role}{'off'} = 1;
8027: }
8028: } else {
8029: $changed{$role}{'off'} = 1;
8030: }
8031: } elsif (@updatedoff) {
8032: $changed{$role}{'off'} = 1;
8033: }
8034: } else {
8035: if (@updatedon) {
8036: $changed{$role}{'on'} = 1;
8037: }
8038: if (@updatedoff) {
8039: $changed{$role}{'off'} = 1;
8040: }
8041: }
8042: if (ref($changed{$role}) eq 'HASH') {
8043: if (($changed{$role}{'on'} || $changed{$role}{'off'})) {
8044: my $newpriv;
8045: if (@updatedon) {
8046: $newpriv = 'on='.join(':',@updatedon);
8047: }
8048: if (@updatedoff) {
8049: $newpriv .= ($newpriv ? ',' : '' ).'off='.join(':',@updatedoff);
8050: }
8051: if ($newpriv eq '') {
8052: push(@todelete,'internal.adhocpriv.'.$role);
8053: } else {
8054: $storehash{'internal.adhocpriv.'.$role} = $newpriv;
8055: }
8056: }
8057: }
8058: }
8059: }
8060: if (@incrs) {
8061: $storehash{'internal.adhocaccess'} = join(',',@incrs);
8062: } elsif (@todelete) {
8063: push(@todelete,'internal.adhocaccess');
8064: }
8065: if (keys(%changed)) {
8066: my ($putres,$delres);
8067: if (keys(%storehash)) {
8068: $putres = &Apache::lonnet::put('environment',\%storehash,$cdom,$cnum);
8069: my %newenvhash;
8070: foreach my $key (keys(%storehash)) {
8071: $newenvhash{'course.'.$env{'request.course.id'}.'.'.$key} = $storehash{$key};
8072: }
8073: &Apache::lonnet::appenv(\%newenvhash);
8074: }
8075: if (@todelete) {
8076: $delres = &Apache::lonnet::del('environment',\@todelete,$cdom,$cnum);
8077: foreach my $key (@todelete) {
8078: &Apache::lonnet::delenv('course.'.$env{'request.course.id'}.'.'.$key);
8079: }
8080: }
8081: if (($putres eq 'ok') || ($delres eq 'ok')) {
8082: my %domconfig = &Apache::lonnet::get_dom('configuration',['helpsettings'],$cdom);
8083: my (%domcurrent,%ordered,%description,%domusage);
8084: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
8085: if (ref($domconfig{'helpsettings'}{'adhoc'}) eq 'HASH') {
8086: %domcurrent = %{$domconfig{'helpsettings'}{'adhoc'}};
8087: }
8088: }
8089: my $count = 0;
8090: foreach my $role (sort(keys(%customroles))) {
8091: my ($order,$desc);
8092: if (ref($domcurrent{$role}) eq 'HASH') {
8093: $order = $domcurrent{$role}{'order'};
8094: $desc = $domcurrent{$role}{'desc'};
8095: }
8096: if ($order eq '') {
8097: $order = $count;
8098: }
8099: $ordered{$order} = $role;
8100: if ($desc ne '') {
8101: $description{$role} = $desc;
8102: } else {
8103: $description{$role}= $role;
8104: }
8105: $count++;
8106: }
8107: my @roles_by_num = ();
8108: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
8109: push(@roles_by_num,$ordered{$item});
8110: }
8111: %domusage = &domain_adhoc_access(\%changed,\%domcurrent,\@accesstypes,$usertypes,$othertitle);
8112: $r->print(&mt('Helpdesk access settings have been changed as follows').'<br />');
8113: $r->print('<ul>');
8114: foreach my $role (@roles_by_num) {
8115: next unless (ref($changed{$role}) eq 'HASH');
8116: $r->print('<li>'.&mt('Ad hoc role').': <b>'.$description{$role}.'</b>'.
8117: '<ul>');
8118: if ($changed{$role}{'access'} || $changed{$role}{'status'} || $changed{$role}{'inc'} || $changed{$role}{'exc'}) {
8119: $r->print('<li>');
8120: if ($env{'form.'.$role.'_incrs'}) {
8121: if ($newsettings{$role}{'access'} eq 'all') {
8122: $r->print(&mt('All helpdesk staff can access '.lc($crstype).' with this role.'));
1.406.2.12 raeburn 8123: } elsif ($newsettings{$role}{'access'} eq 'dh') {
8124: $r->print(&mt('Helpdesk staff can use this role if they have an active [_1] role',
8125: &Apache::lonnet::plaintext('dh')));
8126: } elsif ($newsettings{$role}{'access'} eq 'da') {
8127: $r->print(&mt('Helpdesk staff can use this role if they have an active [_1] role',
8128: &Apache::lonnet::plaintext('da')));
1.406.2.10 raeburn 8129: } elsif ($newsettings{$role}{'access'} eq 'none') {
8130: $r->print(&mt('No helpdesk staff can access '.lc($crstype).' with this role.'));
8131: } elsif ($newsettings{$role}{'access'} eq 'status') {
8132: if ($newsettings{$role}{'status'}) {
8133: my ($access,$rest) = split(/=/,$storehash{'internal.adhoc.'.$role});
8134: if (split(/,/,$rest) > 1) {
8135: $r->print(&mt('Helpdesk staff can use this role if their institutional type is one of: [_1].',
8136: $newsettings{$role}{'status'}));
8137: } else {
8138: $r->print(&mt('Helpdesk staff can use this role if their institutional type is: [_1].',
8139: $newsettings{$role}{'status'}));
8140: }
8141: } else {
8142: $r->print(&mt('No helpdesk staff can access '.lc($crstype).' with this role.'));
8143: }
8144: } elsif ($newsettings{$role}{'access'} eq 'exc') {
8145: if ($newsettings{$role}{'exc'}) {
8146: $r->print(&mt('Helpdesk staff who can use this role are as follows:').' '.$newsettings{$role}{'exc'}.'.');
8147: } else {
8148: $r->print(&mt('No helpdesk staff can access '.lc($crstype).' with this role.'));
8149: }
8150: } elsif ($newsettings{$role}{'access'} eq 'inc') {
8151: if ($newsettings{$role}{'inc'}) {
8152: $r->print(&mt('All helpdesk staff may use this role except the following:').' '.$newsettings{$role}{'inc'}.'.');
8153: } else {
8154: $r->print(&mt('All helpdesk staff may use this role.'));
8155: }
8156: }
8157: } else {
8158: $r->print(&mt('Default access set in the domain now applies.').'<br />'.
8159: '<span class="LC_cusr_emph">'.$domusage{$role}.'</span>');
8160: }
8161: $r->print('</li>');
8162: }
8163: unless ($newsettings{$role}{'access'} eq 'none') {
8164: if ($changed{$role}{'off'}) {
8165: if ($newsettings{$role}{'off'}) {
8166: $r->print('<li>'.&mt('Privileges which are available by default for this ad hoc role, but are disabled for this specific '.lc($crstype).':').
8167: '<ul><li>'.$newsettings{$role}{'off'}.'</li></ul></li>');
8168: } else {
8169: $r->print('<li>'.&mt('All privileges available by default for this ad hoc role are enabled.').'</li>');
8170: }
8171: }
8172: if ($changed{$role}{'on'}) {
8173: if ($newsettings{$role}{'on'}) {
8174: $r->print('<li>'.&mt('Privileges which are not available by default for this ad hoc role, but are enabled for this specific '.lc($crstype).':').
8175: '<ul><li>'.$newsettings{$role}{'on'}.'</li></ul></li>');
8176: } else {
8177: $r->print('<li>'.&mt('None of the privileges unavailable by default for this ad hoc role are enabled.').'</li>');
8178: }
8179: }
8180: }
8181: $r->print('</ul></li>');
8182: }
8183: $r->print('</ul>');
8184: }
8185: } else {
8186: $r->print(&mt('No changes made to helpdesk access settings.'));
8187: }
8188: }
8189: return;
8190: }
8191:
1.27 matthew 8192: #-------------------------------------------------- functions for &phase_two
1.160 raeburn 8193: sub user_search_result {
1.221 raeburn 8194: my ($context,$srch) = @_;
1.160 raeburn 8195: my %allhomes;
8196: my %inst_matches;
8197: my %srch_results;
1.181 raeburn 8198: my ($response,$currstate,$forcenewuser,$dirsrchres);
1.183 raeburn 8199: $srch->{'srchterm'} =~ s/\s+/ /g;
1.176 raeburn 8200: if ($srch->{'srchby'} !~ /^(uname|lastname|lastfirst)$/) {
1.160 raeburn 8201: $response = &mt('Invalid search.');
8202: }
8203: if ($srch->{'srchin'} !~ /^(crs|dom|alc|instd)$/) {
8204: $response = &mt('Invalid search.');
8205: }
1.177 raeburn 8206: if ($srch->{'srchtype'} !~ /^(exact|contains|begins)$/) {
1.160 raeburn 8207: $response = &mt('Invalid search.');
8208: }
8209: if ($srch->{'srchterm'} eq '') {
8210: $response = &mt('You must enter a search term.');
8211: }
1.183 raeburn 8212: if ($srch->{'srchterm'} =~ /^\s+$/) {
8213: $response = &mt('Your search term must contain more than just spaces.');
8214: }
1.160 raeburn 8215: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'instd')) {
8216: if (($srch->{'srchdomain'} eq '') ||
1.163 albertel 8217: ! (&Apache::lonnet::domain($srch->{'srchdomain'}))) {
1.160 raeburn 8218: $response = &mt('You must specify a valid domain when searching in a domain or institutional directory.')
8219: }
8220: }
8221: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs') ||
8222: ($srch->{'srchin'} eq 'alc')) {
1.176 raeburn 8223: if ($srch->{'srchby'} eq 'uname') {
1.243 raeburn 8224: my $unamecheck = $srch->{'srchterm'};
8225: if ($srch->{'srchtype'} eq 'contains') {
8226: if ($unamecheck !~ /^\w/) {
8227: $unamecheck = 'a'.$unamecheck;
8228: }
8229: }
8230: if ($unamecheck !~ /^$match_username$/) {
1.176 raeburn 8231: $response = &mt('You must specify a valid username. Only the following are allowed: letters numbers - . @');
8232: }
1.160 raeburn 8233: }
8234: }
1.180 raeburn 8235: if ($response ne '') {
1.406.2.4 raeburn 8236: $response = '<span class="LC_warning">'.$response.'</span><br />';
1.180 raeburn 8237: }
1.160 raeburn 8238: if ($srch->{'srchin'} eq 'instd') {
1.406.2.3 raeburn 8239: my $instd_chk = &instdirectorysrch_check($srch);
1.160 raeburn 8240: if ($instd_chk ne 'ok') {
1.406.2.3 raeburn 8241: my $domd_chk = &domdirectorysrch_check($srch);
1.406.2.4 raeburn 8242: $response .= '<span class="LC_warning">'.$instd_chk.'</span><br />';
1.406.2.3 raeburn 8243: if ($domd_chk eq 'ok') {
1.406.2.4 raeburn 8244: $response .= &mt('You may want to search in the LON-CAPA domain instead of the institutional directory.');
1.406.2.3 raeburn 8245: }
1.406.2.5 raeburn 8246: $response .= '<br />';
1.406.2.3 raeburn 8247: }
8248: } else {
8249: unless (($context eq 'requestcrs') && ($srch->{'srchtype'} eq 'exact')) {
8250: my $domd_chk = &domdirectorysrch_check($srch);
8251: if ($domd_chk ne 'ok') {
8252: my $instd_chk = &instdirectorysrch_check($srch);
1.406.2.4 raeburn 8253: $response .= '<span class="LC_warning">'.$domd_chk.'</span><br />';
1.406.2.3 raeburn 8254: if ($instd_chk eq 'ok') {
1.406.2.4 raeburn 8255: $response .= &mt('You may want to search in the institutional directory instead of the LON-CAPA domain.');
1.406.2.3 raeburn 8256: }
1.406.2.5 raeburn 8257: $response .= '<br />';
1.406.2.3 raeburn 8258: }
1.160 raeburn 8259: }
8260: }
8261: if ($response ne '') {
1.180 raeburn 8262: return ($currstate,$response);
1.160 raeburn 8263: }
8264: if ($srch->{'srchby'} eq 'uname') {
8265: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs')) {
8266: if ($env{'form.forcenew'}) {
8267: if ($srch->{'srchdomain'} ne $env{'request.role.domain'}) {
8268: my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
8269: if ($uhome eq 'no_host') {
8270: my $domdesc = &Apache::lonnet::domain($env{'request.role.domain'},'description');
1.180 raeburn 8271: my $showdom = &display_domain_info($env{'request.role.domain'});
8272: $response = &mt('New users can only be created in the domain to which your current role belongs - [_1].',$showdom);
1.160 raeburn 8273: } else {
1.179 raeburn 8274: $currstate = 'modify';
1.160 raeburn 8275: }
8276: } else {
1.179 raeburn 8277: $currstate = 'modify';
1.160 raeburn 8278: }
8279: } else {
8280: if ($srch->{'srchin'} eq 'dom') {
1.162 raeburn 8281: if ($srch->{'srchtype'} eq 'exact') {
8282: my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
8283: if ($uhome eq 'no_host') {
1.179 raeburn 8284: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8285: &build_search_response($context,$srch,%srch_results);
1.162 raeburn 8286: } else {
1.179 raeburn 8287: $currstate = 'modify';
1.406.2.5 raeburn 8288: if ($env{'form.action'} eq 'accesslogs') {
8289: $currstate = 'activity';
8290: }
1.310 raeburn 8291: my $uname = $srch->{'srchterm'};
8292: my $udom = $srch->{'srchdomain'};
8293: $srch_results{$uname.':'.$udom} =
8294: { &Apache::lonnet::get('environment',
8295: ['firstname',
8296: 'lastname',
8297: 'permanentemail'],
8298: $udom,$uname)
8299: };
1.162 raeburn 8300: }
8301: } else {
8302: %srch_results = &Apache::lonnet::usersearch($srch);
1.179 raeburn 8303: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8304: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 8305: }
8306: } else {
1.167 albertel 8307: my $courseusers = &get_courseusers();
1.162 raeburn 8308: if ($srch->{'srchtype'} eq 'exact') {
1.167 albertel 8309: if (exists($courseusers->{$srch->{'srchterm'}.':'.$srch->{'srchdomain'}})) {
1.179 raeburn 8310: $currstate = 'modify';
1.162 raeburn 8311: } else {
1.179 raeburn 8312: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8313: &build_search_response($context,$srch,%srch_results);
1.162 raeburn 8314: }
1.160 raeburn 8315: } else {
1.167 albertel 8316: foreach my $user (keys(%$courseusers)) {
1.162 raeburn 8317: my ($cuname,$cudomain) = split(/:/,$user);
8318: if ($cudomain eq $srch->{'srchdomain'}) {
1.177 raeburn 8319: my $matched = 0;
8320: if ($srch->{'srchtype'} eq 'begins') {
8321: if ($cuname =~ /^\Q$srch->{'srchterm'}\E/i) {
8322: $matched = 1;
8323: }
8324: } else {
8325: if ($cuname =~ /\Q$srch->{'srchterm'}\E/i) {
8326: $matched = 1;
8327: }
8328: }
8329: if ($matched) {
1.167 albertel 8330: $srch_results{$user} =
8331: {&Apache::lonnet::get('environment',
8332: ['firstname',
8333: 'lastname',
1.194 albertel 8334: 'permanentemail'],
8335: $cudomain,$cuname)};
1.162 raeburn 8336: }
8337: }
8338: }
1.179 raeburn 8339: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8340: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 8341: }
8342: }
8343: }
8344: } elsif ($srch->{'srchin'} eq 'alc') {
1.179 raeburn 8345: $currstate = 'query';
1.160 raeburn 8346: } elsif ($srch->{'srchin'} eq 'instd') {
1.181 raeburn 8347: ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
8348: if ($dirsrchres eq 'ok') {
8349: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8350: &build_search_response($context,$srch,%srch_results);
1.181 raeburn 8351: } else {
8352: my $showdom = &display_domain_info($srch->{'srchdomain'});
8353: $response = '<span class="LC_warning">'.
8354: &mt('Institutional directory search is not available in domain: [_1]',$showdom).
8355: '</span><br />'.
8356: &mt('You may want to search in the LON-CAPA domain instead of the institutional directory.').
1.406.2.5 raeburn 8357: '<br />';
1.181 raeburn 8358: }
1.160 raeburn 8359: }
8360: } else {
8361: if ($srch->{'srchin'} eq 'dom') {
8362: %srch_results = &Apache::lonnet::usersearch($srch);
1.179 raeburn 8363: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8364: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 8365: } elsif ($srch->{'srchin'} eq 'crs') {
1.167 albertel 8366: my $courseusers = &get_courseusers();
8367: foreach my $user (keys(%$courseusers)) {
1.160 raeburn 8368: my ($uname,$udom) = split(/:/,$user);
8369: my %names = &Apache::loncommon::getnames($uname,$udom);
8370: my %emails = &Apache::loncommon::getemails($uname,$udom);
8371: if ($srch->{'srchby'} eq 'lastname') {
8372: if ((($srch->{'srchtype'} eq 'exact') &&
8373: ($names{'lastname'} eq $srch->{'srchterm'})) ||
1.177 raeburn 8374: (($srch->{'srchtype'} eq 'begins') &&
8375: ($names{'lastname'} =~ /^\Q$srch->{'srchterm'}\E/i)) ||
1.160 raeburn 8376: (($srch->{'srchtype'} eq 'contains') &&
8377: ($names{'lastname'} =~ /\Q$srch->{'srchterm'}\E/i))) {
8378: $srch_results{$user} = {firstname => $names{'firstname'},
8379: lastname => $names{'lastname'},
8380: permanentemail => $emails{'permanentemail'},
8381: };
8382: }
8383: } elsif ($srch->{'srchby'} eq 'lastfirst') {
8384: my ($srchlast,$srchfirst) = split(/,/,$srch->{'srchterm'});
1.177 raeburn 8385: $srchlast =~ s/\s+$//;
8386: $srchfirst =~ s/^\s+//;
1.160 raeburn 8387: if ($srch->{'srchtype'} eq 'exact') {
8388: if (($names{'lastname'} eq $srchlast) &&
8389: ($names{'firstname'} eq $srchfirst)) {
8390: $srch_results{$user} = {firstname => $names{'firstname'},
8391: lastname => $names{'lastname'},
8392: permanentemail => $emails{'permanentemail'},
8393:
8394: };
8395: }
1.177 raeburn 8396: } elsif ($srch->{'srchtype'} eq 'begins') {
8397: if (($names{'lastname'} =~ /^\Q$srchlast\E/i) &&
8398: ($names{'firstname'} =~ /^\Q$srchfirst\E/i)) {
8399: $srch_results{$user} = {firstname => $names{'firstname'},
8400: lastname => $names{'lastname'},
8401: permanentemail => $emails{'permanentemail'},
8402: };
8403: }
8404: } else {
1.160 raeburn 8405: if (($names{'lastname'} =~ /\Q$srchlast\E/i) &&
8406: ($names{'firstname'} =~ /\Q$srchfirst\E/i)) {
8407: $srch_results{$user} = {firstname => $names{'firstname'},
8408: lastname => $names{'lastname'},
8409: permanentemail => $emails{'permanentemail'},
8410: };
8411: }
8412: }
8413: }
8414: }
1.179 raeburn 8415: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8416: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 8417: } elsif ($srch->{'srchin'} eq 'alc') {
1.179 raeburn 8418: $currstate = 'query';
1.160 raeburn 8419: } elsif ($srch->{'srchin'} eq 'instd') {
1.181 raeburn 8420: ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
8421: if ($dirsrchres eq 'ok') {
8422: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8423: &build_search_response($context,$srch,%srch_results);
1.181 raeburn 8424: } else {
1.406.2.5 raeburn 8425: my $showdom = &display_domain_info($srch->{'srchdomain'});
8426: $response = '<span class="LC_warning">'.
1.181 raeburn 8427: &mt('Institutional directory search is not available in domain: [_1]',$showdom).
8428: '</span><br />'.
8429: &mt('You may want to search in the LON-CAPA domain instead of the institutional directory.').
1.406.2.5 raeburn 8430: '<br />';
1.181 raeburn 8431: }
1.160 raeburn 8432: }
8433: }
1.179 raeburn 8434: return ($currstate,$response,$forcenewuser,\%srch_results);
1.160 raeburn 8435: }
8436:
1.406.2.3 raeburn 8437: sub domdirectorysrch_check {
8438: my ($srch) = @_;
8439: my $response;
8440: my %dom_inst_srch = &Apache::lonnet::get_dom('configuration',
8441: ['directorysrch'],$srch->{'srchdomain'});
8442: my $showdom = &display_domain_info($srch->{'srchdomain'});
8443: if (ref($dom_inst_srch{'directorysrch'}) eq 'HASH') {
8444: if ($dom_inst_srch{'directorysrch'}{'lcavailable'} eq '0') {
8445: return &mt('LON-CAPA directory search is not available in domain: [_1]',$showdom);
8446: }
8447: if ($dom_inst_srch{'directorysrch'}{'lclocalonly'}) {
8448: if ($env{'request.role.domain'} ne $srch->{'srchdomain'}) {
8449: return &mt('LON-CAPA directory search in domain: [_1] is only allowed for users with a current role in the domain.',$showdom);
8450: }
8451: }
8452: }
8453: return 'ok';
8454: }
8455:
8456: sub instdirectorysrch_check {
1.160 raeburn 8457: my ($srch) = @_;
8458: my $can_search = 0;
8459: my $response;
8460: my %dom_inst_srch = &Apache::lonnet::get_dom('configuration',
8461: ['directorysrch'],$srch->{'srchdomain'});
1.180 raeburn 8462: my $showdom = &display_domain_info($srch->{'srchdomain'});
1.160 raeburn 8463: if (ref($dom_inst_srch{'directorysrch'}) eq 'HASH') {
8464: if (!$dom_inst_srch{'directorysrch'}{'available'}) {
1.180 raeburn 8465: return &mt('Institutional directory search is not available in domain: [_1]',$showdom);
1.160 raeburn 8466: }
8467: if ($dom_inst_srch{'directorysrch'}{'localonly'}) {
8468: if ($env{'request.role.domain'} ne $srch->{'srchdomain'}) {
1.180 raeburn 8469: return &mt('Institutional directory search in domain: [_1] is only allowed for users with a current role in the domain.',$showdom);
1.160 raeburn 8470: }
8471: my @usertypes = split(/:/,$env{'environment.inststatus'});
8472: if (!@usertypes) {
8473: push(@usertypes,'default');
8474: }
8475: if (ref($dom_inst_srch{'directorysrch'}{'cansearch'}) eq 'ARRAY') {
8476: foreach my $type (@usertypes) {
8477: if (grep(/^\Q$type\E$/,@{$dom_inst_srch{'directorysrch'}{'cansearch'}})) {
8478: $can_search = 1;
8479: last;
8480: }
8481: }
8482: }
8483: if (!$can_search) {
8484: my ($insttypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($srch->{'srchdomain'});
8485: my @longtypes;
8486: foreach my $item (@usertypes) {
1.229 raeburn 8487: if (defined($insttypes->{$item})) {
8488: push (@longtypes,$insttypes->{$item});
8489: } elsif ($item eq 'default') {
8490: push (@longtypes,&mt('other'));
8491: }
1.160 raeburn 8492: }
8493: my $insttype_str = join(', ',@longtypes);
1.180 raeburn 8494: return &mt('Institutional directory search in domain: [_1] is not available to your user type: ',$showdom).$insttype_str;
1.229 raeburn 8495: }
1.160 raeburn 8496: } else {
8497: $can_search = 1;
8498: }
8499: } else {
1.180 raeburn 8500: return &mt('Institutional directory search has not been configured for domain: [_1]',$showdom);
1.160 raeburn 8501: }
8502: my %longtext = &Apache::lonlocal::texthash (
1.167 albertel 8503: uname => 'username',
1.160 raeburn 8504: lastfirst => 'last name, first name',
1.167 albertel 8505: lastname => 'last name',
1.172 raeburn 8506: contains => 'contains',
1.178 raeburn 8507: exact => 'as exact match to',
8508: begins => 'begins with',
1.160 raeburn 8509: );
8510: if ($can_search) {
8511: if (ref($dom_inst_srch{'directorysrch'}{'searchby'}) eq 'ARRAY') {
8512: if (!grep(/^\Q$srch->{'srchby'}\E$/,@{$dom_inst_srch{'directorysrch'}{'searchby'}})) {
1.180 raeburn 8513: return &mt('Institutional directory search in domain: [_1] is not available for searching by "[_2]"',$showdom,$longtext{$srch->{'srchby'}});
1.160 raeburn 8514: }
8515: } else {
1.180 raeburn 8516: return &mt('Institutional directory search in domain: [_1] is not available.', $showdom);
1.160 raeburn 8517: }
8518: }
8519: if ($can_search) {
1.178 raeburn 8520: if (ref($dom_inst_srch{'directorysrch'}{'searchtypes'}) eq 'ARRAY') {
8521: if (grep(/^\Q$srch->{'srchtype'}\E/,@{$dom_inst_srch{'directorysrch'}{'searchtypes'}})) {
8522: return 'ok';
8523: } else {
1.180 raeburn 8524: return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
1.178 raeburn 8525: }
8526: } else {
8527: if ((($dom_inst_srch{'directorysrch'}{'searchtypes'} eq 'specify') &&
8528: ($srch->{'srchtype'} eq 'exact' || $srch->{'srchtype'} eq 'contains')) ||
8529: ($dom_inst_srch{'directorysrch'}{'searchtypes'} eq $srch->{'srchtype'})) {
8530: return 'ok';
8531: } else {
1.180 raeburn 8532: return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
1.178 raeburn 8533: }
1.160 raeburn 8534: }
8535: }
8536: }
8537:
8538: sub get_courseusers {
8539: my %advhash;
1.167 albertel 8540: my $classlist = &Apache::loncoursedata::get_classlist();
1.160 raeburn 8541: my %coursepersonnel=&Apache::lonnet::get_course_adv_roles();
8542: foreach my $role (sort(keys(%coursepersonnel))) {
8543: foreach my $user (split(/\,/,$coursepersonnel{$role})) {
1.167 albertel 8544: if (!exists($classlist->{$user})) {
8545: $classlist->{$user} = [];
8546: }
1.160 raeburn 8547: }
8548: }
1.167 albertel 8549: return $classlist;
1.160 raeburn 8550: }
8551:
8552: sub build_search_response {
1.221 raeburn 8553: my ($context,$srch,%srch_results) = @_;
1.179 raeburn 8554: my ($currstate,$response,$forcenewuser);
1.160 raeburn 8555: my %names = (
1.330 bisitz 8556: 'uname' => 'username',
8557: 'lastname' => 'last name',
1.160 raeburn 8558: 'lastfirst' => 'last name, first name',
1.330 bisitz 8559: 'crs' => 'this course',
8560: 'dom' => 'LON-CAPA domain',
8561: 'instd' => 'the institutional directory for domain',
1.160 raeburn 8562: );
8563:
8564: my %single = (
1.180 raeburn 8565: begins => 'A match',
1.160 raeburn 8566: contains => 'A match',
1.180 raeburn 8567: exact => 'An exact match',
1.160 raeburn 8568: );
8569: my %nomatch = (
1.180 raeburn 8570: begins => 'No match',
1.160 raeburn 8571: contains => 'No match',
1.180 raeburn 8572: exact => 'No exact match',
1.160 raeburn 8573: );
8574: if (keys(%srch_results) > 1) {
1.179 raeburn 8575: $currstate = 'select';
1.160 raeburn 8576: } else {
8577: if (keys(%srch_results) == 1) {
1.406.2.5 raeburn 8578: if ($env{'form.action'} eq 'accesslogs') {
8579: $currstate = 'activity';
8580: } else {
8581: $currstate = 'modify';
8582: }
1.180 raeburn 8583: $response = &mt("$single{$srch->{'srchtype'}} was found for the $names{$srch->{'srchby'}} ([_1]) in $names{$srch->{'srchin'}}.",$srch->{'srchterm'});
8584: if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
1.330 bisitz 8585: $response .= ': '.&display_domain_info($srch->{'srchdomain'});
1.180 raeburn 8586: }
1.330 bisitz 8587: } else { # Search has nothing found. Prepare message to user.
8588: $response = '<span class="LC_warning">';
1.180 raeburn 8589: if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
1.330 bisitz 8590: $response .= &mt("$nomatch{$srch->{'srchtype'}} found for the $names{$srch->{'srchby'}} [_1] in $names{$srch->{'srchin'}}: [_2]",
8591: '<b>'.$srch->{'srchterm'}.'</b>',
8592: &display_domain_info($srch->{'srchdomain'}));
8593: } else {
8594: $response .= &mt("$nomatch{$srch->{'srchtype'}} found for the $names{$srch->{'srchby'}} [_1] in $names{$srch->{'srchin'}}.",
8595: '<b>'.$srch->{'srchterm'}.'</b>');
1.180 raeburn 8596: }
8597: $response .= '</span>';
1.330 bisitz 8598:
1.160 raeburn 8599: if ($srch->{'srchin'} ne 'alc') {
8600: $forcenewuser = 1;
8601: my $cansrchinst = 0;
8602: if ($srch->{'srchdomain'}) {
8603: my %domconfig = &Apache::lonnet::get_dom('configuration',['directorysrch'],$srch->{'srchdomain'});
8604: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
8605: if ($domconfig{'directorysrch'}{'available'}) {
8606: $cansrchinst = 1;
8607: }
8608: }
8609: }
1.180 raeburn 8610: if ((($srch->{'srchby'} eq 'lastfirst') ||
8611: ($srch->{'srchby'} eq 'lastname')) &&
8612: ($srch->{'srchin'} eq 'dom')) {
8613: if ($cansrchinst) {
8614: $response .= '<br />'.&mt('You may want to broaden your search to a search of the institutional directory for the domain.');
1.160 raeburn 8615: }
8616: }
1.180 raeburn 8617: if ($srch->{'srchin'} eq 'crs') {
8618: $response .= '<br />'.&mt('You may want to broaden your search to the selected LON-CAPA domain.');
8619: }
8620: }
1.305 raeburn 8621: my $createdom = $env{'request.role.domain'};
8622: if ($context eq 'requestcrs') {
8623: if ($env{'form.coursedom'} ne '') {
8624: $createdom = $env{'form.coursedom'};
8625: }
8626: }
1.406.2.5 raeburn 8627: unless (($env{'form.action'} eq 'accesslogs') || (($srch->{'srchby'} eq 'uname') && ($srch->{'srchin'} eq 'dom') &&
8628: ($srch->{'srchtype'} eq 'exact') && ($srch->{'srchdomain'} eq $createdom))) {
1.221 raeburn 8629: my $cancreate =
1.305 raeburn 8630: &Apache::lonuserutils::can_create_user($createdom,$context);
8631: my $targetdom = '<span class="LC_cusr_emph">'.$createdom.'</span>';
1.221 raeburn 8632: if ($cancreate) {
1.305 raeburn 8633: my $showdom = &display_domain_info($createdom);
1.266 bisitz 8634: $response .= '<br /><br />'
8635: .'<b>'.&mt('To add a new user:').'</b>'
1.305 raeburn 8636: .'<br />';
8637: if ($context eq 'requestcrs') {
8638: $response .= &mt("(You can only define new users in the new course's domain - [_1])",$targetdom);
8639: } else {
8640: $response .= &mt("(You can only create new users in your current role's domain - [_1])",$targetdom);
8641: }
8642: $response .='<ul><li>'
1.266 bisitz 8643: .&mt("Set 'Domain/institution to search' to: [_1]",'<span class="LC_cusr_emph">'.$showdom.'</span>')
8644: .'</li><li>'
8645: .&mt("Set 'Search criteria' to: [_1]username is ..... in selected LON-CAPA domain[_2]",'<span class="LC_cusr_emph">','</span>')
8646: .'</li><li>'
8647: .&mt('Provide the proposed username')
8648: .'</li><li>'
8649: .&mt("Click 'Search'")
8650: .'</li></ul><br />';
1.221 raeburn 8651: } else {
1.406.2.7 raeburn 8652: unless (($context eq 'domain') && ($env{'form.action'} eq 'singleuser')) {
8653: my $helplink = ' href="javascript:helpMenu('."'display'".')"';
8654: $response .= '<br /><br />';
8655: if ($context eq 'requestcrs') {
8656: $response .= &mt("You are not authorized to define new users in the new course's domain - [_1].",$targetdom);
8657: } else {
8658: $response .= &mt("You are not authorized to create new users in your current role's domain - [_1].",$targetdom);
8659: }
8660: $response .= '<br />'
8661: .&mt('Please contact the [_1]helpdesk[_2] if you need to create a new user.'
8662: ,' <a'.$helplink.'>'
8663: ,'</a>')
8664: .'<br />';
1.305 raeburn 8665: }
1.221 raeburn 8666: }
1.160 raeburn 8667: }
8668: }
8669: }
1.179 raeburn 8670: return ($currstate,$response,$forcenewuser);
1.160 raeburn 8671: }
8672:
1.180 raeburn 8673: sub display_domain_info {
8674: my ($dom) = @_;
8675: my $output = $dom;
8676: if ($dom ne '') {
8677: my $domdesc = &Apache::lonnet::domain($dom,'description');
8678: if ($domdesc ne '') {
8679: $output .= ' <span class="LC_cusr_emph">('.$domdesc.')</span>';
8680: }
8681: }
8682: return $output;
8683: }
8684:
1.160 raeburn 8685: sub crumb_utilities {
8686: my %elements = (
8687: crtuser => {
8688: srchterm => 'text',
1.172 raeburn 8689: srchin => 'selectbox',
1.160 raeburn 8690: srchby => 'selectbox',
8691: srchtype => 'selectbox',
8692: srchdomain => 'selectbox',
8693: },
1.207 raeburn 8694: crtusername => {
8695: srchterm => 'text',
8696: srchdomain => 'selectbox',
8697: },
1.160 raeburn 8698: docustom => {
8699: rolename => 'selectbox',
8700: newrolename => 'textbox',
8701: },
1.179 raeburn 8702: studentform => {
8703: srchterm => 'text',
8704: srchin => 'selectbox',
8705: srchby => 'selectbox',
8706: srchtype => 'selectbox',
8707: srchdomain => 'selectbox',
8708: },
1.160 raeburn 8709: );
8710:
8711: my $jsback .= qq|
8712: function backPage(formname,prevphase,prevstate) {
1.211 raeburn 8713: if (typeof prevphase == 'undefined') {
8714: formname.phase.value = '';
8715: }
8716: else {
8717: formname.phase.value = prevphase;
8718: }
8719: if (typeof prevstate == 'undefined') {
8720: formname.currstate.value = '';
8721: }
8722: else {
8723: formname.currstate.value = prevstate;
8724: }
1.160 raeburn 8725: formname.submit();
8726: }
8727: |;
8728: return ($jsback,\%elements);
8729: }
8730:
1.26 matthew 8731: sub course_level_table {
1.375 raeburn 8732: my ($inccourses,$showcredits,$defaultcredits) = @_;
8733: return unless (ref($inccourses) eq 'HASH');
1.26 matthew 8734: my $table = '';
1.62 www 8735: # Custom Roles?
8736:
1.190 raeburn 8737: my %customroles=&Apache::lonuserutils::my_custom_roles();
1.89 raeburn 8738: my %lt=&Apache::lonlocal::texthash(
8739: 'exs' => "Existing sections",
8740: 'new' => "Define new section",
8741: 'ssd' => "Set Start Date",
8742: 'sed' => "Set End Date",
1.131 raeburn 8743: 'crl' => "Course Level",
1.89 raeburn 8744: 'act' => "Activate",
8745: 'rol' => "Role",
8746: 'ext' => "Extent",
1.113 raeburn 8747: 'grs' => "Section",
1.375 raeburn 8748: 'crd' => "Credits",
1.89 raeburn 8749: 'sta' => "Start",
8750: 'end' => "End"
8751: );
1.62 www 8752:
1.375 raeburn 8753: foreach my $protectedcourse (sort(keys(%{$inccourses}))) {
1.135 raeburn 8754: my $thiscourse=$protectedcourse;
1.26 matthew 8755: $thiscourse=~s:_:/:g;
8756: my %coursedata=&Apache::lonnet::coursedescription($thiscourse);
1.365 raeburn 8757: my $isowner = &Apache::lonuserutils::is_courseowner($protectedcourse,$coursedata{'internal.courseowner'});
1.26 matthew 8758: my $area=$coursedata{'description'};
1.321 raeburn 8759: my $crstype=$coursedata{'type'};
1.135 raeburn 8760: if (!defined($area)) { $area=&mt('Unavailable course').': '.$protectedcourse; }
1.89 raeburn 8761: my ($domain,$cnum)=split(/\//,$thiscourse);
1.115 albertel 8762: my %sections_count;
1.101 albertel 8763: if (defined($env{'request.course.id'})) {
8764: if ($env{'request.course.id'} eq $domain.'_'.$cnum) {
1.115 albertel 8765: %sections_count =
8766: &Apache::loncommon::get_sections($domain,$cnum);
1.92 raeburn 8767: }
8768: }
1.321 raeburn 8769: my @roles = &Apache::lonuserutils::roles_by_context('course','',$crstype);
1.213 raeburn 8770: foreach my $role (@roles) {
1.321 raeburn 8771: my $plrole=&Apache::lonnet::plaintext($role,$crstype);
1.329 raeburn 8772: if ((&Apache::lonnet::allowed('c'.$role,$thiscourse)) ||
8773: ((($role eq 'cc') || ($role eq 'co')) && ($isowner))) {
1.221 raeburn 8774: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
1.375 raeburn 8775: $plrole,\%sections_count,\%lt,
1.402 raeburn 8776: $showcredits,$defaultcredits,$crstype);
1.221 raeburn 8777: } elsif ($env{'request.course.sec'} ne '') {
8778: if (&Apache::lonnet::allowed('c'.$role,$thiscourse.'/'.
8779: $env{'request.course.sec'})) {
8780: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
1.375 raeburn 8781: $plrole,\%sections_count,\%lt,
1.402 raeburn 8782: $showcredits,$defaultcredits,$crstype);
1.26 matthew 8783: }
8784: }
8785: }
1.221 raeburn 8786: if (&Apache::lonnet::allowed('ccr',$thiscourse)) {
1.324 raeburn 8787: foreach my $cust (sort(keys(%customroles))) {
8788: next if ($crstype eq 'Community' && $customroles{$cust} =~ /bre\&S/);
1.221 raeburn 8789: my $role = 'cr_cr_'.$env{'user.domain'}.'_'.$env{'user.name'}.'_'.$cust;
8790: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
1.402 raeburn 8791: $cust,\%sections_count,\%lt,
8792: $showcredits,$defaultcredits,$crstype);
1.221 raeburn 8793: }
1.62 www 8794: }
1.26 matthew 8795: }
8796: return '' if ($table eq ''); # return nothing if there is nothing
8797: # in the table
1.188 raeburn 8798: my $result;
8799: if (!$env{'request.course.id'}) {
8800: $result = '<h4>'.$lt{'crl'}.'</h4>'."\n";
8801: }
8802: $result .=
1.136 raeburn 8803: &Apache::loncommon::start_data_table().
8804: &Apache::loncommon::start_data_table_header_row().
1.375 raeburn 8805: '<th>'.$lt{'act'}.'</th><th>'.$lt{'rol'}.'</th>'."\n".
1.402 raeburn 8806: '<th>'.$lt{'ext'}.'</th><th>'."\n";
8807: if ($showcredits) {
8808: $result .= $lt{'crd'}.'</th>';
8809: }
8810: $result .=
1.375 raeburn 8811: '<th>'.$lt{'grs'}.'</th><th>'.$lt{'sta'}.'</th>'."\n".
8812: '<th>'.$lt{'end'}.'</th>'.
1.136 raeburn 8813: &Apache::loncommon::end_data_table_header_row().
8814: $table.
8815: &Apache::loncommon::end_data_table();
1.26 matthew 8816: return $result;
8817: }
1.88 raeburn 8818:
1.221 raeburn 8819: sub course_level_row {
1.375 raeburn 8820: my ($protectedcourse,$role,$area,$domain,$plrole,$sections_count,
1.402 raeburn 8821: $lt,$showcredits,$defaultcredits,$crstype) = @_;
1.375 raeburn 8822: my $creditem;
1.222 raeburn 8823: my $row = &Apache::loncommon::start_data_table_row().
8824: ' <td><input type="checkbox" name="act_'.
8825: $protectedcourse.'_'.$role.'" /></td>'."\n".
8826: ' <td>'.$plrole.'</td>'."\n".
8827: ' <td>'.$area.'<br />Domain: '.$domain.'</td>'."\n";
1.402 raeburn 8828: if (($showcredits) && ($role eq 'st') && ($crstype eq 'Course')) {
1.375 raeburn 8829: $row .=
8830: '<td><input type="text" name="credits_'.$protectedcourse.'_'.
8831: $role.'" size="3" value="'.$defaultcredits.'" /></td>';
8832: } else {
8833: $row .= '<td> </td>';
8834: }
1.322 raeburn 8835: if (($role eq 'cc') || ($role eq 'co')) {
1.222 raeburn 8836: $row .= '<td> </td>';
1.221 raeburn 8837: } elsif ($env{'request.course.sec'} ne '') {
1.222 raeburn 8838: $row .= ' <td><input type="hidden" value="'.
8839: $env{'request.course.sec'}.'" '.
8840: 'name="sec_'.$protectedcourse.'_'.$role.'" />'.
8841: $env{'request.course.sec'}.'</td>';
1.221 raeburn 8842: } else {
8843: if (ref($sections_count) eq 'HASH') {
8844: my $currsec =
8845: &Apache::lonuserutils::course_sections($sections_count,
8846: $protectedcourse.'_'.$role);
1.222 raeburn 8847: $row .= '<td><table class="LC_createuser">'."\n".
8848: '<tr class="LC_section_row">'."\n".
8849: ' <td valign="top">'.$lt->{'exs'}.'<br />'.
8850: $currsec.'</td>'."\n".
8851: ' <td> </td>'."\n".
8852: ' <td valign="top"> '.$lt->{'new'}.'<br />'.
1.221 raeburn 8853: '<input type="text" name="newsec_'.$protectedcourse.'_'.$role.
8854: '" value="" />'.
8855: '<input type="hidden" '.
8856: 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'."\n".
1.222 raeburn 8857: '</tr></table></td>'."\n";
1.221 raeburn 8858: } else {
1.222 raeburn 8859: $row .= '<td><input type="text" size="10" '.
1.375 raeburn 8860: 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'."\n";
1.221 raeburn 8861: }
8862: }
1.222 raeburn 8863: $row .= <<ENDTIMEENTRY;
8864: <td><input type="hidden" name="start_$protectedcourse\_$role" value="" />
1.221 raeburn 8865: <a href=
8866: "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 8867: <td><input type="hidden" name="end_$protectedcourse\_$role" value="" />
1.221 raeburn 8868: <a href=
8869: "javascript:pjump('date_end','End Date $plrole',document.cu.end_$protectedcourse\_$role.value,'end_$protectedcourse\_$role','cu.pres','dateset')">$lt->{'sed'}</a></td>
8870: ENDTIMEENTRY
1.222 raeburn 8871: $row .= &Apache::loncommon::end_data_table_row();
8872: return $row;
1.221 raeburn 8873: }
8874:
1.88 raeburn 8875: sub course_level_dc {
1.375 raeburn 8876: my ($dcdom,$showcredits) = @_;
1.190 raeburn 8877: my %customroles=&Apache::lonuserutils::my_custom_roles();
1.213 raeburn 8878: my @roles = &Apache::lonuserutils::roles_by_context('course');
1.88 raeburn 8879: my $hiddenitems = '<input type="hidden" name="dcdomain" value="'.$dcdom.'" />'.
8880: '<input type="hidden" name="origdom" value="'.$dcdom.'" />'.
1.133 raeburn 8881: '<input type="hidden" name="dccourse" value="" />';
1.355 www 8882: my $courseform=&Apache::loncommon::selectcourse_link
1.356 raeburn 8883: ('cu','dccourse','dcdomain','coursedesc',undef,undef,'Select','crstype');
1.375 raeburn 8884: my $credit_elem;
8885: if ($showcredits) {
8886: $credit_elem = 'credits';
8887: }
8888: my $cb_jscript = &Apache::loncommon::coursebrowser_javascript($dcdom,'currsec','cu','role','Course/Community Browser',$credit_elem);
1.88 raeburn 8889: my %lt=&Apache::lonlocal::texthash(
8890: 'rol' => "Role",
1.113 raeburn 8891: 'grs' => "Section",
1.88 raeburn 8892: 'exs' => "Existing sections",
8893: 'new' => "Define new section",
8894: 'sta' => "Start",
8895: 'end' => "End",
8896: 'ssd' => "Set Start Date",
1.355 www 8897: 'sed' => "Set End Date",
1.375 raeburn 8898: 'scc' => "Course/Community",
8899: 'crd' => "Credits",
1.88 raeburn 8900: );
1.323 raeburn 8901: my $header = '<h4>'.&mt('Course/Community Level').'</h4>'.
1.136 raeburn 8902: &Apache::loncommon::start_data_table().
8903: &Apache::loncommon::start_data_table_header_row().
1.375 raeburn 8904: '<th>'.$lt{'scc'}.'</th><th>'.$lt{'rol'}.'</th>'."\n".
1.397 bisitz 8905: '<th>'.$lt{'grs'}.'</th>'."\n";
8906: $header .= '<th>'.$lt{'crd'}.'</th>'."\n" if ($showcredits);
8907: $header .= '<th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'."\n".
1.136 raeburn 8908: &Apache::loncommon::end_data_table_header_row();
1.143 raeburn 8909: my $otheritems = &Apache::loncommon::start_data_table_row()."\n".
1.356 raeburn 8910: '<td><br /><span class="LC_nobreak"><input type="text" name="coursedesc" value="" onfocus="this.blur();opencrsbrowser('."'cu','dccourse','dcdomain','coursedesc','','','','crstype'".')" />'.
8911: $courseform.(' ' x4).'</span></td>'."\n".
1.389 bisitz 8912: '<td valign="top"><br /><select name="role">'."\n";
1.213 raeburn 8913: foreach my $role (@roles) {
1.135 raeburn 8914: my $plrole=&Apache::lonnet::plaintext($role);
1.389 bisitz 8915: $otheritems .= ' <option value="'.$role.'">'.$plrole.'</option>';
1.88 raeburn 8916: }
1.404 raeburn 8917: if ( keys(%customroles) > 0) {
8918: foreach my $cust (sort(keys(%customroles))) {
1.101 albertel 8919: my $custrole='cr_cr_'.$env{'user.domain'}.
1.135 raeburn 8920: '_'.$env{'user.name'}.'_'.$cust;
1.389 bisitz 8921: $otheritems .= ' <option value="'.$custrole.'">'.$cust.'</option>';
1.88 raeburn 8922: }
8923: }
8924: $otheritems .= '</select></td><td>'.
8925: '<table border="0" cellspacing="0" cellpadding="0">'.
8926: '<tr><td valign="top"><b>'.$lt{'exs'}.'</b><br /><select name="currsec">'.
1.389 bisitz 8927: ' <option value=""><--'.&mt('Pick course first').'</option></select></td>'.
1.88 raeburn 8928: '<td> </td>'.
8929: '<td valign="top"> <b>'.$lt{'new'}.'</b><br />'.
1.113 raeburn 8930: '<input type="text" name="newsec" value="" />'.
1.237 raeburn 8931: '<input type="hidden" name="section" value="" />'.
1.323 raeburn 8932: '<input type="hidden" name="groups" value="" />'.
8933: '<input type="hidden" name="crstype" value="" /></td>'.
1.375 raeburn 8934: '</tr></table></td>'."\n";
8935: if ($showcredits) {
8936: $otheritems .= '<td><br />'."\n".
1.397 bisitz 8937: '<input type="text" size="3" name="credits" value="" /></td>'."\n";
1.375 raeburn 8938: }
1.88 raeburn 8939: $otheritems .= <<ENDTIMEENTRY;
1.323 raeburn 8940: <td><br /><input type="hidden" name="start" value='' />
1.88 raeburn 8941: <a href=
8942: "javascript:pjump('date_start','Start Date',document.cu.start.value,'start','cu.pres','dateset')">$lt{'ssd'}</a></td>
1.323 raeburn 8943: <td><br /><input type="hidden" name="end" value='' />
1.88 raeburn 8944: <a href=
8945: "javascript:pjump('date_end','End Date',document.cu.end.value,'end','cu.pres','dateset')">$lt{'sed'}</a></td>
8946: ENDTIMEENTRY
1.136 raeburn 8947: $otheritems .= &Apache::loncommon::end_data_table_row().
8948: &Apache::loncommon::end_data_table()."\n";
1.88 raeburn 8949: return $cb_jscript.$header.$hiddenitems.$otheritems;
8950: }
8951:
1.237 raeburn 8952: sub update_selfenroll_config {
1.400 raeburn 8953: my ($r,$cid,$cdom,$cnum,$context,$crstype,$currsettings) = @_;
1.398 raeburn 8954: return unless (ref($currsettings) eq 'HASH');
8955: my ($row,$lt) = &Apache::lonuserutils::get_selfenroll_titles();
8956: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
1.237 raeburn 8957: my (%changes,%warning);
1.241 raeburn 8958: my $curr_types;
1.400 raeburn 8959: my %noedit;
8960: unless ($context eq 'domain') {
8961: %noedit = &get_noedit_fields($cdom,$cnum,$crstype,$row);
8962: }
1.237 raeburn 8963: if (ref($row) eq 'ARRAY') {
8964: foreach my $item (@{$row}) {
1.400 raeburn 8965: next if ($noedit{$item});
1.237 raeburn 8966: if ($item eq 'enroll_dates') {
8967: my (%currenrolldate,%newenrolldate);
8968: foreach my $type ('start','end') {
1.398 raeburn 8969: $currenrolldate{$type} = $currsettings->{'selfenroll_'.$type.'_date'};
1.237 raeburn 8970: $newenrolldate{$type} = &Apache::lonhtmlcommon::get_date_from_form('selfenroll_'.$type.'_date');
8971: if ($newenrolldate{$type} ne $currenrolldate{$type}) {
8972: $changes{'internal.selfenroll_'.$type.'_date'} = $newenrolldate{$type};
8973: }
8974: }
8975: } elsif ($item eq 'access_dates') {
8976: my (%currdate,%newdate);
8977: foreach my $type ('start','end') {
1.398 raeburn 8978: $currdate{$type} = $currsettings->{'selfenroll_'.$type.'_access'};
1.237 raeburn 8979: $newdate{$type} = &Apache::lonhtmlcommon::get_date_from_form('selfenroll_'.$type.'_access');
8980: if ($newdate{$type} ne $currdate{$type}) {
8981: $changes{'internal.selfenroll_'.$type.'_access'} = $newdate{$type};
8982: }
8983: }
1.241 raeburn 8984: } elsif ($item eq 'types') {
1.398 raeburn 8985: $curr_types = $currsettings->{'selfenroll_'.$item};
1.241 raeburn 8986: if ($env{'form.selfenroll_all'}) {
8987: if ($curr_types ne '*') {
8988: $changes{'internal.selfenroll_types'} = '*';
8989: } else {
8990: next;
8991: }
8992: } else {
1.249 raeburn 8993: my %currdoms;
1.241 raeburn 8994: my @entries = split(/;/,$curr_types);
8995: my @deletedoms = &Apache::loncommon::get_env_multiple('form.selfenroll_delete');
1.249 raeburn 8996: my @activations = &Apache::loncommon::get_env_multiple('form.selfenroll_activate');
1.241 raeburn 8997: my $newnum = 0;
1.249 raeburn 8998: my @latesttypes;
8999: foreach my $num (@activations) {
9000: my @types = &Apache::loncommon::get_env_multiple('form.selfenroll_types_'.$num);
9001: if (@types > 0) {
1.241 raeburn 9002: @types = sort(@types);
9003: my $typestr = join(',',@types);
1.249 raeburn 9004: my $typedom = $env{'form.selfenroll_dom_'.$num};
9005: $latesttypes[$newnum] = $typedom.':'.$typestr;
9006: $currdoms{$typedom} = 1;
1.241 raeburn 9007: $newnum ++;
9008: }
9009: }
1.338 raeburn 9010: for (my $j=0; $j<$env{'form.selfenroll_types_total'}; $j++) {
9011: if ((!grep(/^$j$/,@deletedoms)) && (!grep(/^$j$/,@activations))) {
1.249 raeburn 9012: my @types = &Apache::loncommon::get_env_multiple('form.selfenroll_types_'.$j);
9013: if (@types > 0) {
9014: @types = sort(@types);
9015: my $typestr = join(',',@types);
9016: my $typedom = $env{'form.selfenroll_dom_'.$j};
9017: $latesttypes[$newnum] = $typedom.':'.$typestr;
9018: $currdoms{$typedom} = 1;
9019: $newnum ++;
9020: }
9021: }
9022: }
9023: if ($env{'form.selfenroll_newdom'} ne '') {
9024: my $typedom = $env{'form.selfenroll_newdom'};
9025: if ((!defined($currdoms{$typedom})) &&
9026: (&Apache::lonnet::domain($typedom) ne '')) {
9027: my $typestr;
9028: my ($othertitle,$usertypes,$types) =
9029: &Apache::loncommon::sorted_inst_types($typedom);
9030: my $othervalue = 'any';
9031: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
9032: if (@{$types} > 0) {
1.257 raeburn 9033: my @esc_types = map { &escape($_); } @{$types};
1.249 raeburn 9034: $othervalue = 'other';
1.258 raeburn 9035: $typestr = join(',',(@esc_types,$othervalue));
1.249 raeburn 9036: }
9037: $typestr = $othervalue;
9038: } else {
9039: $typestr = $othervalue;
9040: }
9041: $latesttypes[$newnum] = $typedom.':'.$typestr;
9042: $newnum ++ ;
9043: }
9044: }
1.241 raeburn 9045: my $selfenroll_types = join(';',@latesttypes);
9046: if ($selfenroll_types ne $curr_types) {
9047: $changes{'internal.selfenroll_types'} = $selfenroll_types;
9048: }
9049: }
1.276 raeburn 9050: } elsif ($item eq 'limit') {
9051: my $newlimit = $env{'form.selfenroll_limit'};
9052: my $newcap = $env{'form.selfenroll_cap'};
9053: $newcap =~s/\s+//g;
1.398 raeburn 9054: my $currlimit = $currsettings->{'selfenroll_limit'};
1.276 raeburn 9055: $currlimit = 'none' if ($currlimit eq '');
1.398 raeburn 9056: my $currcap = $currsettings->{'selfenroll_cap'};
1.276 raeburn 9057: if ($newlimit ne $currlimit) {
9058: if ($newlimit ne 'none') {
9059: if ($newcap =~ /^\d+$/) {
9060: if ($newcap ne $currcap) {
9061: $changes{'internal.selfenroll_cap'} = $newcap;
9062: }
9063: $changes{'internal.selfenroll_limit'} = $newlimit;
9064: } else {
1.398 raeburn 9065: $warning{$item} = &mt('Maximum enrollment setting unchanged.').'<br />'.
9066: &mt('The value provided was invalid - it must be a positive integer if enrollment is being limited.');
1.276 raeburn 9067: }
9068: } elsif ($currcap ne '') {
9069: $changes{'internal.selfenroll_cap'} = '';
9070: $changes{'internal.selfenroll_limit'} = $newlimit;
9071: }
9072: } elsif ($currlimit ne 'none') {
9073: if ($newcap =~ /^\d+$/) {
9074: if ($newcap ne $currcap) {
9075: $changes{'internal.selfenroll_cap'} = $newcap;
9076: }
9077: } else {
1.398 raeburn 9078: $warning{$item} = &mt('Maximum enrollment setting unchanged.').'<br />'.
9079: &mt('The value provided was invalid - it must be a positive integer if enrollment is being limited.');
1.276 raeburn 9080: }
9081: }
9082: } elsif ($item eq 'approval') {
9083: my (@currnotified,@newnotified);
1.398 raeburn 9084: my $currapproval = $currsettings->{'selfenroll_approval'};
9085: my $currnotifylist = $currsettings->{'selfenroll_notifylist'};
1.276 raeburn 9086: if ($currnotifylist ne '') {
9087: @currnotified = split(/,/,$currnotifylist);
9088: @currnotified = sort(@currnotified);
9089: }
9090: my $newapproval = $env{'form.selfenroll_approval'};
9091: @newnotified = &Apache::loncommon::get_env_multiple('form.selfenroll_notify');
9092: @newnotified = sort(@newnotified);
9093: if ($newapproval ne $currapproval) {
9094: $changes{'internal.selfenroll_approval'} = $newapproval;
9095: if (!$newapproval) {
9096: if ($currnotifylist ne '') {
9097: $changes{'internal.selfenroll_notifylist'} = '';
9098: }
9099: } else {
9100: my @differences =
1.295 raeburn 9101: &Apache::loncommon::compare_arrays(\@currnotified,\@newnotified);
1.276 raeburn 9102: if (@differences > 0) {
9103: if (@newnotified > 0) {
9104: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
9105: } else {
9106: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
9107: }
9108: }
9109: }
9110: } else {
1.295 raeburn 9111: my @differences = &Apache::loncommon::compare_arrays(\@currnotified,\@newnotified);
1.276 raeburn 9112: if (@differences > 0) {
9113: if (@newnotified > 0) {
9114: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
9115: } else {
9116: $changes{'internal.selfenroll_notifylist'} = '';
9117: }
9118: }
9119: }
1.237 raeburn 9120: } else {
1.398 raeburn 9121: my $curr_val = $currsettings->{'selfenroll_'.$item};
1.237 raeburn 9122: my $newval = $env{'form.selfenroll_'.$item};
9123: if ($item eq 'section') {
9124: $newval = $env{'form.sections'};
1.241 raeburn 9125: if (defined($curr_groups{$newval})) {
1.237 raeburn 9126: $newval = $curr_val;
1.398 raeburn 9127: $warning{$item} = &mt('Section for self-enrolled users unchanged as the proposed section is a group').'<br />'.
9128: &mt('Group names and section names must be distinct');
1.237 raeburn 9129: } elsif ($newval eq 'all') {
9130: $newval = $curr_val;
1.274 bisitz 9131: $warning{$item} = &mt('Section for self-enrolled users unchanged, as "all" is a reserved section name.');
1.237 raeburn 9132: }
9133: if ($newval eq '') {
9134: $newval = 'none';
9135: }
9136: }
9137: if ($newval ne $curr_val) {
9138: $changes{'internal.selfenroll_'.$item} = $newval;
9139: }
1.241 raeburn 9140: }
1.237 raeburn 9141: }
9142: if (keys(%warning) > 0) {
9143: foreach my $item (@{$row}) {
9144: if (exists($warning{$item})) {
9145: $r->print($warning{$item}.'<br />');
9146: }
9147: }
9148: }
9149: if (keys(%changes) > 0) {
9150: my $putresult = &Apache::lonnet::put('environment',\%changes,$cdom,$cnum);
9151: if ($putresult eq 'ok') {
9152: if ((exists($changes{'internal.selfenroll_types'})) ||
9153: (exists($changes{'internal.selfenroll_start_date'})) ||
9154: (exists($changes{'internal.selfenroll_end_date'}))) {
9155: my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',
9156: $cnum,undef,undef,'Course');
9157: my $chome = &Apache::lonnet::homeserver($cnum,$cdom);
1.398 raeburn 9158: if (ref($crsinfo{$cid}) eq 'HASH') {
1.237 raeburn 9159: foreach my $item ('selfenroll_types','selfenroll_start_date','selfenroll_end_date') {
9160: if (exists($changes{'internal.'.$item})) {
1.398 raeburn 9161: $crsinfo{$cid}{$item} = $changes{'internal.'.$item};
1.237 raeburn 9162: }
9163: }
9164: my $crsputresult =
9165: &Apache::lonnet::courseidput($cdom,\%crsinfo,
9166: $chome,'notime');
9167: }
9168: }
9169: $r->print(&mt('The following changes were made to self-enrollment settings:').'<ul>');
9170: foreach my $item (@{$row}) {
9171: my $title = $item;
9172: if (ref($lt) eq 'HASH') {
9173: $title = $lt->{$item};
9174: }
9175: if ($item eq 'enroll_dates') {
9176: foreach my $type ('start','end') {
9177: if (exists($changes{'internal.selfenroll_'.$type.'_date'})) {
9178: my $newdate = &Apache::lonlocal::locallocaltime($changes{'internal.selfenroll_'.$type.'_date'});
1.244 bisitz 9179: $r->print('<li>'.&mt('[_1]: "[_2]" set to "[_3]".',
1.237 raeburn 9180: $title,$type,$newdate).'</li>');
9181: }
9182: }
9183: } elsif ($item eq 'access_dates') {
9184: foreach my $type ('start','end') {
9185: if (exists($changes{'internal.selfenroll_'.$type.'_access'})) {
9186: my $newdate = &Apache::lonlocal::locallocaltime($changes{'internal.selfenroll_'.$type.'_access'});
1.244 bisitz 9187: $r->print('<li>'.&mt('[_1]: "[_2]" set to "[_3]".',
1.237 raeburn 9188: $title,$type,$newdate).'</li>');
9189: }
9190: }
1.276 raeburn 9191: } elsif ($item eq 'limit') {
9192: if ((exists($changes{'internal.selfenroll_limit'})) ||
9193: (exists($changes{'internal.selfenroll_cap'}))) {
9194: my ($newval,$newcap);
9195: if ($changes{'internal.selfenroll_cap'} ne '') {
9196: $newcap = $changes{'internal.selfenroll_cap'}
9197: } else {
1.398 raeburn 9198: $newcap = $currsettings->{'selfenroll_cap'};
1.276 raeburn 9199: }
9200: if ($changes{'internal.selfenroll_limit'} eq 'none') {
9201: $newval = &mt('No limit');
9202: } elsif ($changes{'internal.selfenroll_limit'} eq
9203: 'allstudents') {
9204: $newval = &mt('New self-enrollment no longer allowed when total (all students) reaches [_1].',$newcap);
9205: } elsif ($changes{'internal.selfenroll_limit'} eq 'selfenrolled') {
9206: $newval = &mt('New self-enrollment no longer allowed when total number of self-enrolled students reaches [_1].',$newcap);
9207: } else {
1.398 raeburn 9208: my $currlimit = $currsettings->{'selfenroll_limit'};
1.276 raeburn 9209: if ($currlimit eq 'allstudents') {
9210: $newval = &mt('New self-enrollment no longer allowed when total (all students) reaches [_1].',$newcap);
9211: } elsif ($changes{'internal.selfenroll_limit'} eq 'selfenrolled') {
1.308 raeburn 9212: $newval = &mt('New self-enrollment no longer allowed when total number of self-enrolled students reaches [_1].',$newcap);
1.276 raeburn 9213: }
9214: }
9215: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval).'</li>'."\n");
9216: }
9217: } elsif ($item eq 'approval') {
9218: if ((exists($changes{'internal.selfenroll_approval'})) ||
9219: (exists($changes{'internal.selfenroll_notifylist'}))) {
1.398 raeburn 9220: my %selfdescs = &Apache::lonuserutils::selfenroll_default_descs();
1.276 raeburn 9221: my ($newval,$newnotify);
9222: if (exists($changes{'internal.selfenroll_notifylist'})) {
9223: $newnotify = $changes{'internal.selfenroll_notifylist'};
9224: } else {
1.398 raeburn 9225: $newnotify = $currsettings->{'selfenroll_notifylist'};
1.276 raeburn 9226: }
1.398 raeburn 9227: if (exists($changes{'internal.selfenroll_approval'})) {
9228: if ($changes{'internal.selfenroll_approval'} !~ /^[012]$/) {
9229: $changes{'internal.selfenroll_approval'} = '0';
9230: }
9231: $newval = $selfdescs{'approval'}{$changes{'internal.selfenroll_approval'}};
1.276 raeburn 9232: } else {
1.398 raeburn 9233: my $currapproval = $currsettings->{'selfenroll_approval'};
9234: if ($currapproval !~ /^[012]$/) {
9235: $currapproval = 0;
1.276 raeburn 9236: }
1.398 raeburn 9237: $newval = $selfdescs{'approval'}{$currapproval};
1.276 raeburn 9238: }
9239: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval));
9240: if ($newnotify) {
1.277 raeburn 9241: $r->print('<br />'.&mt('The following will be notified when an enrollment request needs approval, or has been approved: [_1].',$newnotify));
1.276 raeburn 9242: } else {
1.277 raeburn 9243: $r->print('<br />'.&mt('No notifications sent when an enrollment request needs approval, or has been approved.'));
1.276 raeburn 9244: }
9245: $r->print('</li>'."\n");
9246: }
1.237 raeburn 9247: } else {
9248: if (exists($changes{'internal.selfenroll_'.$item})) {
1.241 raeburn 9249: my $newval = $changes{'internal.selfenroll_'.$item};
9250: if ($item eq 'types') {
9251: if ($newval eq '') {
9252: $newval = &mt('None');
9253: } elsif ($newval eq '*') {
9254: $newval = &mt('Any user in any domain');
9255: }
1.245 raeburn 9256: } elsif ($item eq 'registered') {
9257: if ($newval eq '1') {
9258: $newval = &mt('Yes');
9259: } elsif ($newval eq '0') {
9260: $newval = &mt('No');
9261: }
1.241 raeburn 9262: }
1.244 bisitz 9263: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval).'</li>'."\n");
1.237 raeburn 9264: }
9265: }
9266: }
9267: $r->print('</ul>');
1.398 raeburn 9268: if ($env{'course.'.$cid.'.description'} ne '') {
9269: my %newenvhash;
9270: foreach my $key (keys(%changes)) {
9271: $newenvhash{'course.'.$cid.'.'.$key} = $changes{$key};
9272: }
9273: &Apache::lonnet::appenv(\%newenvhash);
1.237 raeburn 9274: }
9275: } else {
1.398 raeburn 9276: $r->print(&mt('An error occurred when saving changes to self-enrollment settings in this course.').'<br />'.
9277: &mt('The error was: [_1].',$putresult));
1.237 raeburn 9278: }
9279: } else {
1.249 raeburn 9280: $r->print(&mt('No changes were made to the existing self-enrollment settings in this course.'));
1.237 raeburn 9281: }
9282: } else {
1.249 raeburn 9283: $r->print(&mt('No changes were made to the existing self-enrollment settings in this course.'));
1.241 raeburn 9284: }
1.400 raeburn 9285: my $visactions = &cat_visibility();
9286: my ($cathash,%cattype);
9287: my %domconfig = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom);
9288: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
9289: $cathash = $domconfig{'coursecategories'}{'cats'};
9290: $cattype{'auth'} = $domconfig{'coursecategories'}{'auth'};
9291: $cattype{'unauth'} = $domconfig{'coursecategories'}{'unauth'};
9292: } else {
9293: $cathash = {};
9294: $cattype{'auth'} = 'std';
9295: $cattype{'unauth'} = 'std';
9296: }
9297: if (($cattype{'auth'} eq 'none') && ($cattype{'unauth'} eq 'none')) {
9298: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
9299: '<br />'.
9300: '<br />'.$visactions->{'take'}.'<ul>'.
9301: '<li>'.$visactions->{'dc_chgconf'}.'</li>'.
9302: '</ul>');
9303: } elsif (($cattype{'auth'} !~ /^(std|domonly)$/) && ($cattype{'unauth'} !~ /^(std|domonly)$/)) {
9304: if ($currsettings->{'uniquecode'}) {
9305: $r->print('<span class="LC_info">'.$visactions->{'vis'}.'</span>');
9306: } else {
1.366 bisitz 9307: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
1.400 raeburn 9308: '<br />'.
9309: '<br />'.$visactions->{'take'}.'<ul>'.
9310: '<li>'.$visactions->{'dc_setcode'}.'</li>'.
9311: '</ul><br />');
9312: }
9313: } else {
9314: my ($visible,$cansetvis,$vismsgs) = &visible_in_stdcat($cdom,$cnum,\%domconfig);
9315: if (ref($visactions) eq 'HASH') {
9316: if (!$visible) {
9317: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
9318: '<br />');
9319: if (ref($vismsgs) eq 'ARRAY') {
9320: $r->print('<br />'.$visactions->{'take'}.'<ul>');
9321: foreach my $item (@{$vismsgs}) {
9322: $r->print('<li>'.$visactions->{$item}.'</li>');
9323: }
9324: $r->print('</ul>');
1.256 raeburn 9325: }
1.400 raeburn 9326: $r->print($cansetvis);
1.256 raeburn 9327: }
9328: }
9329: }
1.237 raeburn 9330: return;
9331: }
9332:
1.27 matthew 9333: #---------------------------------------------- end functions for &phase_two
1.29 matthew 9334:
9335: #--------------------------------- functions for &phase_two and &phase_three
9336:
9337: #--------------------------end of functions for &phase_two and &phase_three
1.372 raeburn 9338:
1.1 www 9339: 1;
9340: __END__
1.2 www 9341:
9342:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>