Annotation of loncom/interface/loncreateuser.pm, revision 1.406.2.16
1.20 harris41 1: # The LearningOnline Network with CAPA
1.1 www 2: # Create a user
3: #
1.406.2.16! raeburn 4: # $Id: loncreateuser.pm,v 1.406.2.15 2018/09/14 14:57:52 raeburn Exp $
1.22 albertel 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
1.20 harris41 28: ###
29:
1.1 www 30: package Apache::loncreateuser;
1.66 bowersj2 31:
32: =pod
33:
34: =head1 NAME
35:
1.263 jms 36: Apache::loncreateuser.pm
1.66 bowersj2 37:
38: =head1 SYNOPSIS
39:
1.263 jms 40: Handler to create users and custom roles
41:
42: Provides an Apache handler for creating users,
1.66 bowersj2 43: editing their login parameters, roles, and removing roles, and
44: also creating and assigning custom roles.
45:
46: =head1 OVERVIEW
47:
48: =head2 Custom Roles
49:
50: In LON-CAPA, roles are actually collections of privileges. "Teaching
51: Assistant", "Course Coordinator", and other such roles are really just
52: collection of privileges that are useful in many circumstances.
53:
1.324 raeburn 54: Custom roles can be defined by a Domain Coordinator, Course Coordinator
55: or Community Coordinator via the Manage User functionality.
56: The custom role editor screen will show all privileges which can be
57: assigned to users. For a complete list of privileges, please see
58: C</home/httpd/lonTabs/rolesplain.tab>.
1.66 bowersj2 59:
1.324 raeburn 60: Custom role definitions are stored in the C<roles.db> file of the creator
61: of the role.
1.66 bowersj2 62:
63: =cut
1.1 www 64:
65: use strict;
66: use Apache::Constants qw(:common :http);
67: use Apache::lonnet;
1.54 bowersj2 68: use Apache::loncommon;
1.68 www 69: use Apache::lonlocal;
1.117 raeburn 70: use Apache::longroup;
1.190 raeburn 71: use Apache::lonuserutils;
1.307 raeburn 72: use Apache::loncoursequeueadmin;
1.139 albertel 73: use LONCAPA qw(:DEFAULT :match);
1.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.406.2.14 raeburn 644: my ($r,$context,$response,$srch,$forcenewuser,$crstype,$brcrum,
645: $permission) = @_;
1.101 albertel 646: my $defdom=$env{'request.role.domain'};
1.160 raeburn 647: my $formtoset = 'crtuser';
648: if (exists($env{'form.startrolename'})) {
649: $formtoset = 'docustom';
650: $env{'form.rolename'} = $env{'form.startrolename'};
1.207 raeburn 651: } elsif ($env{'form.origform'} eq 'crtusername') {
652: $formtoset = $env{'form.origform'};
1.160 raeburn 653: }
654:
655: my ($jsback,$elements) = &crumb_utilities();
656:
657: my $jscript = &Apache::loncommon::studentbrowser_javascript()."\n".
1.165 albertel 658: '<script type="text/javascript">'."\n".
1.301 bisitz 659: '// <![CDATA['."\n".
660: &Apache::lonhtmlcommon::set_form_elements($elements->{$formtoset})."\n".
661: '// ]]>'."\n".
1.162 raeburn 662: '</script>'."\n";
1.160 raeburn 663:
1.324 raeburn 664: my %existingroles=&Apache::lonuserutils::my_custom_roles($crstype);
665: if (($env{'form.action'} eq 'custom') && (keys(%existingroles) > 0)
666: && (&Apache::lonnet::allowed('mcr','/'))) {
667: $jscript .= &customrole_javascript();
668: }
1.224 raeburn 669: my $helpitem = 'Course_Change_Privileges';
670: if ($env{'form.action'} eq 'custom') {
1.406.2.14 raeburn 671: if ($context eq 'course') {
672: $helpitem = 'Course_Editing_Custom_Roles';
673: } elsif ($context eq 'domain') {
674: $helpitem = 'Domain_Editing_Custom_Roles';
675: }
1.224 raeburn 676: } elsif ($env{'form.action'} eq 'singlestudent') {
677: $helpitem = 'Course_Add_Student';
1.406.2.5 raeburn 678: } elsif ($env{'form.action'} eq 'accesslogs') {
679: $helpitem = 'Domain_User_Access_Logs';
1.406.2.14 raeburn 680: } elsif ($context eq 'author') {
681: $helpitem = 'Author_Change_Privileges';
682: } elsif ($context eq 'domain') {
683: if ($permission->{'cusr'}) {
684: $helpitem = 'Domain_Change_Privileges';
685: } elsif ($permission->{'view'}) {
686: $helpitem = 'Domain_View_Privileges';
687: } else {
688: undef($helpitem);
689: }
1.224 raeburn 690: }
1.406.2.7 raeburn 691: my %breadcrumb_text = &singleuser_breadcrumb($crstype,$context,$defdom);
1.351 raeburn 692: if ($env{'form.action'} eq 'custom') {
693: push(@{$brcrum},
694: {href=>"javascript:backPage(document.crtuser)",
695: text=>"Pick custom role",
696: help => $helpitem,}
697: );
698: } else {
699: push (@{$brcrum},
700: {href => "javascript:backPage(document.crtuser)",
701: text => $breadcrumb_text{'search'},
702: help => $helpitem,
703: faq => 282,
704: bug => 'Instructor Interface',}
705: );
706: }
707: my %loaditems = (
708: 'onload' => "javascript:setFormElements(document.$formtoset)",
709: );
710: my $args = {bread_crumbs => $brcrum,
711: bread_crumbs_component => 'User Management',
712: add_entries => \%loaditems,};
713: $r->print(&Apache::loncommon::start_page('User Management',$jscript,$args));
714:
1.71 sakharuk 715: my %lt=&Apache::lonlocal::texthash(
1.229 raeburn 716: 'srst' => 'Search for a user and enroll as a student',
1.318 raeburn 717: 'srme' => 'Search for a user and enroll as a member',
1.229 raeburn 718: 'srad' => 'Search for a user and modify/add user information or roles',
1.406.2.7 raeburn 719: 'srvu' => 'Search for a user and view user information and roles',
1.406.2.5 raeburn 720: 'srva' => 'Search for a user and view access log information',
1.71 sakharuk 721: 'usr' => "Username",
722: 'dom' => "Domain",
1.324 raeburn 723: 'ecrp' => "Define or Edit Custom Role",
724: 'nr' => "role name",
1.282 schafran 725: 'cre' => "Next",
1.71 sakharuk 726: );
1.351 raeburn 727:
1.214 raeburn 728: if ($env{'form.action'} eq 'custom') {
1.190 raeburn 729: if (&Apache::lonnet::allowed('mcr','/')) {
1.324 raeburn 730: my $newroletext = &mt('Define new custom role:');
731: $r->print('<form action="/adm/createuser" method="post" name="docustom">'.
732: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'.
733: '<input type="hidden" name="phase" value="selected_custom_edit" />'.
734: '<h3>'.$lt{'ecrp'}.'</h3>'.
735: &Apache::loncommon::start_data_table().
736: &Apache::loncommon::start_data_table_row().
737: '<td>');
738: if (keys(%existingroles) > 0) {
739: $r->print('<br /><label><input type="radio" name="customroleaction" value="new" checked="checked" onclick="setCustomFields();" /><b>'.$newroletext.'</b></label>');
740: } else {
741: $r->print('<br /><input type="hidden" name="customroleaction" value="new" /><b>'.$newroletext.'</b>');
742: }
743: $r->print('</td><td align="center">'.$lt{'nr'}.'<br /><input type="text" size="15" name="newrolename" onfocus="setCustomAction('."'new'".');" /></td>'.
744: &Apache::loncommon::end_data_table_row());
745: if (keys(%existingroles) > 0) {
746: $r->print(&Apache::loncommon::start_data_table_row().'<td><br />'.
747: '<label><input type="radio" name="customroleaction" value="edit" onclick="setCustomFields();"/><b>'.
748: &mt('View/Modify existing role:').'</b></label></td>'.
749: '<td align="center"><br />'.
750: '<select name="rolename" onchange="setCustomAction('."'edit'".');">'.
1.326 raeburn 751: '<option value="" selected="selected">'.
1.324 raeburn 752: &mt('Select'));
753: foreach my $role (sort(keys(%existingroles))) {
1.326 raeburn 754: $r->print('<option value="'.$role.'">'.$role.'</option>');
1.324 raeburn 755: }
756: $r->print('</select>'.
757: '</td>'.
758: &Apache::loncommon::end_data_table_row());
759: }
760: $r->print(&Apache::loncommon::end_data_table().'<p>'.
761: '<input name="customeditor" type="submit" value="'.
762: $lt{'cre'}.'" /></p>'.
763: '</form>');
1.190 raeburn 764: }
1.213 raeburn 765: } else {
1.229 raeburn 766: my $actiontext = $lt{'srad'};
1.406.2.13 raeburn 767: my $fixeddom;
1.213 raeburn 768: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 769: if ($crstype eq 'Community') {
770: $actiontext = $lt{'srme'};
771: } else {
772: $actiontext = $lt{'srst'};
773: }
1.406.2.5 raeburn 774: } elsif ($env{'form.action'} eq 'accesslogs') {
775: $actiontext = $lt{'srva'};
1.406.2.13 raeburn 776: $fixeddom = 1;
1.406.2.7 raeburn 777: } elsif (($env{'form.action'} eq 'singleuser') &&
778: ($context eq 'domain') && (!&Apache::lonnet::allowed('mau',$defdom))) {
779: $actiontext = $lt{'srvu'};
1.406.2.14 raeburn 780: $fixeddom = 1;
1.213 raeburn 781: }
1.324 raeburn 782: $r->print("<h3>$actiontext</h3>");
1.213 raeburn 783: if ($env{'form.origform'} ne 'crtusername') {
1.406.2.5 raeburn 784: if ($response) {
785: $r->print("\n<div>$response</div>".
786: '<br clear="all" />');
787: }
1.213 raeburn 788: }
1.406.2.13 raeburn 789: $r->print(&entry_form($defdom,$srch,$forcenewuser,$context,$response,$crstype,$fixeddom));
1.107 www 790: }
1.110 albertel 791: }
792:
1.324 raeburn 793: sub customrole_javascript {
794: my $js = <<"END";
795: <script type="text/javascript">
796: // <![CDATA[
797:
798: function setCustomFields() {
799: if (document.docustom.customroleaction.length > 0) {
800: for (var i=0; i<document.docustom.customroleaction.length; i++) {
801: if (document.docustom.customroleaction[i].checked) {
802: if (document.docustom.customroleaction[i].value == 'new') {
803: document.docustom.rolename.selectedIndex = 0;
804: } else {
805: document.docustom.newrolename.value = '';
806: }
807: }
808: }
809: }
810: return;
811: }
812:
813: function setCustomAction(caller) {
814: if (document.docustom.customroleaction.length > 0) {
815: for (var i=0; i<document.docustom.customroleaction.length; i++) {
816: if (document.docustom.customroleaction[i].value == caller) {
817: document.docustom.customroleaction[i].checked = true;
818: }
819: }
820: }
821: setCustomFields();
822: return;
823: }
824:
825: // ]]>
826: </script>
827: END
828: return $js;
829: }
830:
1.160 raeburn 831: sub entry_form {
1.406.2.5 raeburn 832: my ($dom,$srch,$forcenewuser,$context,$responsemsg,$crstype,$fixeddom) = @_;
1.229 raeburn 833: my ($usertype,$inexact);
1.214 raeburn 834: if (ref($srch) eq 'HASH') {
835: if (($srch->{'srchin'} eq 'dom') &&
836: ($srch->{'srchby'} eq 'uname') &&
837: ($srch->{'srchtype'} eq 'exact') &&
838: ($srch->{'srchdomain'} ne '') &&
839: ($srch->{'srchterm'} ne '')) {
1.353 raeburn 840: my (%curr_rules,%got_rules);
1.214 raeburn 841: my ($rules,$ruleorder) =
842: &Apache::lonnet::inst_userrules($srch->{'srchdomain'},'username');
1.353 raeburn 843: $usertype = &Apache::lonuserutils::check_usertype($srch->{'srchdomain'},$srch->{'srchterm'},$rules,\%curr_rules,\%got_rules);
1.229 raeburn 844: } else {
845: $inexact = 1;
1.214 raeburn 846: }
1.207 raeburn 847: }
1.406.2.14 raeburn 848: my ($cancreate,$noinstd);
849: if ($env{'form.action'} eq 'accesslogs') {
850: $noinstd = 1;
851: } else {
852: $cancreate =
853: &Apache::lonuserutils::can_create_user($dom,$context,$usertype);
854: }
1.406.2.3 raeburn 855: my ($userpicker,$cansearch) =
1.179 raeburn 856: &Apache::loncommon::user_picker($dom,$srch,$forcenewuser,
1.406.2.14 raeburn 857: 'document.crtuser',$cancreate,$usertype,$context,$fixeddom,$noinstd);
1.160 raeburn 858: my $srchbutton = &mt('Search');
1.229 raeburn 859: if ($env{'form.action'} eq 'singlestudent') {
860: $srchbutton = &mt('Search and Enroll');
1.406.2.5 raeburn 861: } elsif ($env{'form.action'} eq 'accesslogs') {
862: $srchbutton = &mt('Search');
1.229 raeburn 863: } elsif ($cancreate && $responsemsg ne '' && $inexact) {
864: $srchbutton = &mt('Search or Add New User');
865: }
1.406.2.3 raeburn 866: my $output;
867: if ($cansearch) {
868: $output = <<"ENDBLOCK";
1.160 raeburn 869: <form action="/adm/createuser" method="post" name="crtuser">
1.190 raeburn 870: <input type="hidden" name="action" value="$env{'form.action'}" />
1.160 raeburn 871: <input type="hidden" name="phase" value="get_user_info" />
872: $userpicker
1.179 raeburn 873: <input name="userrole" type="button" value="$srchbutton" onclick="javascript:validateEntry(document.crtuser)" />
1.160 raeburn 874: </form>
1.207 raeburn 875: ENDBLOCK
1.406.2.3 raeburn 876: } else {
877: $output = '<p>'.$userpicker.'</p>';
878: }
1.406.2.7 raeburn 879: if (($env{'form.phase'} eq '') && ($env{'form.action'} ne 'accesslogs') &&
880: (!(($env{'form.action'} eq 'singleuser') && ($context eq 'domain') &&
881: (!&Apache::lonnet::allowed('mau',$env{'request.role.domain'}))))) {
1.207 raeburn 882: my $defdom=$env{'request.role.domain'};
883: my $domform = &Apache::loncommon::select_dom_form($defdom,'srchdomain');
884: my %lt=&Apache::lonlocal::texthash(
1.229 raeburn 885: 'enro' => 'Enroll one student',
1.318 raeburn 886: 'enrm' => 'Enroll one member',
1.229 raeburn 887: 'admo' => 'Add/modify a single user',
888: 'crea' => 'create new user if required',
889: 'uskn' => "username is known",
1.207 raeburn 890: 'crnu' => 'Create a new user',
891: 'usr' => 'Username',
892: 'dom' => 'in domain',
1.229 raeburn 893: 'enrl' => 'Enroll',
894: 'cram' => 'Create/Modify user',
1.207 raeburn 895: );
1.229 raeburn 896: my $sellink=&Apache::loncommon::selectstudent_link('crtusername','srchterm','srchdomain');
897: my ($title,$buttontext,$showresponse);
1.318 raeburn 898: if ($env{'form.action'} eq 'singlestudent') {
899: if ($crstype eq 'Community') {
900: $title = $lt{'enrm'};
901: } else {
902: $title = $lt{'enro'};
903: }
1.229 raeburn 904: $buttontext = $lt{'enrl'};
905: } else {
906: $title = $lt{'admo'};
907: $buttontext = $lt{'cram'};
908: }
909: if ($cancreate) {
910: $title .= ' <span class="LC_cusr_subheading">('.$lt{'crea'}.')</span>';
911: } else {
912: $title .= ' <span class="LC_cusr_subheading">('.$lt{'uskn'}.')</span>';
913: }
914: if ($env{'form.origform'} eq 'crtusername') {
915: $showresponse = $responsemsg;
916: }
1.207 raeburn 917: $output .= <<"ENDDOCUMENT";
1.229 raeburn 918: <br />
1.207 raeburn 919: <form action="/adm/createuser" method="post" name="crtusername">
920: <input type="hidden" name="action" value="$env{'form.action'}" />
921: <input type="hidden" name="phase" value="createnewuser" />
922: <input type="hidden" name="srchtype" value="exact" />
1.233 raeburn 923: <input type="hidden" name="srchby" value="uname" />
1.207 raeburn 924: <input type="hidden" name="srchin" value="dom" />
925: <input type="hidden" name="forcenewuser" value="1" />
926: <input type="hidden" name="origform" value="crtusername" />
1.229 raeburn 927: <h3>$title</h3>
928: $showresponse
1.207 raeburn 929: <table>
930: <tr>
931: <td>$lt{'usr'}:</td>
932: <td><input type="text" size="15" name="srchterm" /></td>
933: <td> $lt{'dom'}:</td><td>$domform</td>
1.229 raeburn 934: <td> $sellink </td>
935: <td> <input name="userrole" type="submit" value="$buttontext" /></td>
1.207 raeburn 936: </tr>
937: </table>
938: </form>
1.160 raeburn 939: ENDDOCUMENT
1.207 raeburn 940: }
1.160 raeburn 941: return $output;
942: }
1.110 albertel 943:
944: sub user_modification_js {
1.113 raeburn 945: my ($pjump_def,$dc_setcourse_code,$nondc_setsection_code,$groupslist)=@_;
946:
1.110 albertel 947: return <<END;
948: <script type="text/javascript" language="Javascript">
1.301 bisitz 949: // <![CDATA[
1.314 raeburn 950:
1.110 albertel 951: $pjump_def
952: $dc_setcourse_code
953:
954: function dateset() {
955: eval("document.cu."+document.cu.pres_marker.value+
956: ".value=document.cu.pres_value.value");
1.359 www 957: modalWindow.close();
1.110 albertel 958: }
959:
1.113 raeburn 960: $nondc_setsection_code
1.301 bisitz 961: // ]]>
1.110 albertel 962: </script>
963: END
1.2 www 964: }
965:
966: # =================================================================== Phase two
1.160 raeburn 967: sub print_user_selection_page {
1.351 raeburn 968: my ($r,$response,$srch,$srch_results,$srcharray,$context,$opener_elements,$crstype,$brcrum) = @_;
1.160 raeburn 969: my @fields = ('username','domain','lastname','firstname','permanentemail');
970: my $sortby = $env{'form.sortby'};
971:
972: if (!grep(/^\Q$sortby\E$/,@fields)) {
973: $sortby = 'lastname';
974: }
975:
976: my ($jsback,$elements) = &crumb_utilities();
977:
978: my $jscript = (<<ENDSCRIPT);
979: <script type="text/javascript">
1.301 bisitz 980: // <![CDATA[
1.160 raeburn 981: function pickuser(uname,udom) {
982: document.usersrchform.seluname.value=uname;
983: document.usersrchform.seludom.value=udom;
984: document.usersrchform.phase.value="userpicked";
985: document.usersrchform.submit();
986: }
987:
988: $jsback
1.301 bisitz 989: // ]]>
1.160 raeburn 990: </script>
991: ENDSCRIPT
992:
993: my %lt=&Apache::lonlocal::texthash(
1.179 raeburn 994: 'usrch' => "User Search to add/modify roles",
995: 'stusrch' => "User Search to enroll student",
1.318 raeburn 996: 'memsrch' => "User Search to enroll member",
1.406.2.5 raeburn 997: 'srcva' => "Search for a user and view access log information",
1.406.2.7 raeburn 998: 'usrvu' => "User Search to view user roles",
1.179 raeburn 999: 'usel' => "Select a user to add/modify roles",
1.406.2.7 raeburn 1000: 'suvr' => "Select a user to view roles",
1.318 raeburn 1001: 'stusel' => "Select a user to enroll as a student",
1002: 'memsel' => "Select a user to enroll as a member",
1.406.2.5 raeburn 1003: 'vacsel' => "Select a user to view access log",
1.160 raeburn 1004: 'username' => "username",
1005: 'domain' => "domain",
1006: 'lastname' => "last name",
1007: 'firstname' => "first name",
1008: 'permanentemail' => "permanent e-mail",
1009: );
1.302 raeburn 1010: if ($context eq 'requestcrs') {
1011: $r->print('<div>');
1012: } else {
1.406.2.7 raeburn 1013: my %breadcrumb_text = &singleuser_breadcrumb($crstype,$context,$srch->{'srchdomain'});
1.351 raeburn 1014: my $helpitem;
1015: if ($env{'form.action'} eq 'singleuser') {
1016: $helpitem = 'Course_Change_Privileges';
1017: } elsif ($env{'form.action'} eq 'singlestudent') {
1018: $helpitem = 'Course_Add_Student';
1.406.2.14 raeburn 1019: } elsif ($context eq 'author') {
1020: $helpitem = 'Author_Change_Privileges';
1021: } elsif ($context eq 'domain') {
1022: $helpitem = 'Domain_Change_Privileges';
1.351 raeburn 1023: }
1024: push (@{$brcrum},
1025: {href => "javascript:backPage(document.usersrchform,'','')",
1026: text => $breadcrumb_text{'search'},
1027: faq => 282,
1028: bug => 'Instructor Interface',},
1029: {href => "javascript:backPage(document.usersrchform,'get_user_info','select')",
1030: text => $breadcrumb_text{'userpicked'},
1031: faq => 282,
1032: bug => 'Instructor Interface',
1033: help => $helpitem}
1034: );
1035: $r->print(&Apache::loncommon::start_page('User Management',$jscript,{bread_crumbs => $brcrum}));
1.302 raeburn 1036: if ($env{'form.action'} eq 'singleuser') {
1.406.2.7 raeburn 1037: my $readonly;
1038: if (($context eq 'domain') && (!&Apache::lonnet::allowed('mau',$srch->{'srchdomain'}))) {
1039: $readonly = 1;
1040: $r->print("<b>$lt{'usrvu'}</b><br />");
1041: } else {
1042: $r->print("<b>$lt{'usrch'}</b><br />");
1043: }
1.318 raeburn 1044: $r->print(&entry_form($srch->{'srchdomain'},$srch,undef,$context,undef,$crstype));
1.406.2.7 raeburn 1045: if ($readonly) {
1046: $r->print('<h3>'.$lt{'suvr'}.'</h3>');
1047: } else {
1048: $r->print('<h3>'.$lt{'usel'}.'</h3>');
1049: }
1.302 raeburn 1050: } elsif ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1051: $r->print($jscript."<b>");
1052: if ($crstype eq 'Community') {
1053: $r->print($lt{'memsrch'});
1054: } else {
1055: $r->print($lt{'stusrch'});
1056: }
1057: $r->print("</b><br />");
1058: $r->print(&entry_form($srch->{'srchdomain'},$srch,undef,$context,undef,$crstype));
1059: $r->print('</form><h3>');
1060: if ($crstype eq 'Community') {
1061: $r->print($lt{'memsel'});
1062: } else {
1063: $r->print($lt{'stusel'});
1064: }
1065: $r->print('</h3>');
1.406.2.5 raeburn 1066: } elsif ($env{'form.action'} eq 'accesslogs') {
1067: $r->print("<b>$lt{'srcva'}</b><br />");
1.406.2.14 raeburn 1068: $r->print(&entry_form($srch->{'srchdomain'},$srch,undef,$context,undef,undef,1));
1.406.2.5 raeburn 1069: $r->print('<h3>'.$lt{'vacsel'}.'</h3>');
1.302 raeburn 1070: }
1.179 raeburn 1071: }
1.380 bisitz 1072: $r->print('<form name="usersrchform" method="post" action="">'.
1.160 raeburn 1073: &Apache::loncommon::start_data_table()."\n".
1074: &Apache::loncommon::start_data_table_header_row()."\n".
1075: ' <th> </th>'."\n");
1076: foreach my $field (@fields) {
1077: $r->print(' <th><a href="javascript:document.usersrchform.sortby.value='.
1078: "'".$field."'".';document.usersrchform.submit();">'.
1079: $lt{$field}.'</a></th>'."\n");
1080: }
1081: $r->print(&Apache::loncommon::end_data_table_header_row());
1082:
1083: my @sorted_users = sort {
1.167 albertel 1084: lc($srch_results->{$a}->{$sortby}) cmp lc($srch_results->{$b}->{$sortby})
1.160 raeburn 1085: ||
1.167 albertel 1086: lc($srch_results->{$a}->{lastname}) cmp lc($srch_results->{$b}->{lastname})
1.160 raeburn 1087: ||
1088: lc($srch_results->{$a}->{firstname}) cmp lc($srch_results->{$b}->{firstname})
1.167 albertel 1089: ||
1090: lc($a) cmp lc($b)
1.160 raeburn 1091: } (keys(%$srch_results));
1092:
1093: foreach my $user (@sorted_users) {
1094: my ($uname,$udom) = split(/:/,$user);
1.302 raeburn 1095: my $onclick;
1096: if ($context eq 'requestcrs') {
1.314 raeburn 1097: $onclick =
1.302 raeburn 1098: 'onclick="javascript:gochoose('."'$uname','$udom',".
1099: "'$srch_results->{$user}->{firstname}',".
1100: "'$srch_results->{$user}->{lastname}',".
1101: "'$srch_results->{$user}->{permanentemail}'".');"';
1102: } else {
1.314 raeburn 1103: $onclick =
1.302 raeburn 1104: ' onclick="javascript:pickuser('."'".$uname."'".','."'".$udom."'".');"';
1105: }
1.160 raeburn 1106: $r->print(&Apache::loncommon::start_data_table_row().
1.302 raeburn 1107: '<td><input type="button" name="seluser" value="'.&mt('Select').'" '.
1108: $onclick.' /></td>'.
1.160 raeburn 1109: '<td><tt>'.$uname.'</tt></td>'.
1110: '<td><tt>'.$udom.'</tt></td>');
1111: foreach my $field ('lastname','firstname','permanentemail') {
1112: $r->print('<td>'.$srch_results->{$user}->{$field}.'</td>');
1113: }
1114: $r->print(&Apache::loncommon::end_data_table_row());
1115: }
1116: $r->print(&Apache::loncommon::end_data_table().'<br /><br />');
1.179 raeburn 1117: if (ref($srcharray) eq 'ARRAY') {
1118: foreach my $item (@{$srcharray}) {
1119: $r->print('<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n");
1120: }
1121: }
1.160 raeburn 1122: $r->print(' <input type="hidden" name="sortby" value="'.$sortby.'" />'."\n".
1123: ' <input type="hidden" name="seluname" value="" />'."\n".
1124: ' <input type="hidden" name="seludom" value="" />'."\n".
1.179 raeburn 1125: ' <input type="hidden" name="currstate" value="select" />'."\n".
1.190 raeburn 1126: ' <input type="hidden" name="phase" value="get_user_info" />'."\n".
1.214 raeburn 1127: ' <input type="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n");
1.302 raeburn 1128: if ($context eq 'requestcrs') {
1129: $r->print($opener_elements.'</form></div>');
1130: } else {
1.351 raeburn 1131: $r->print($response.'</form>');
1.302 raeburn 1132: }
1.160 raeburn 1133: }
1134:
1135: sub print_user_query_page {
1.351 raeburn 1136: my ($r,$caller,$brcrum) = @_;
1.160 raeburn 1137: # FIXME - this is for a network-wide name search (similar to catalog search)
1138: # To use frames with similar behavior to catalog/portfolio search.
1139: # To be implemented.
1140: return;
1141: }
1142:
1.42 matthew 1143: sub print_user_modification_page {
1.375 raeburn 1144: my ($r,$ccuname,$ccdomain,$srch,$response,$context,$permission,$crstype,
1145: $brcrum,$showcredits) = @_;
1.185 raeburn 1146: if (($ccuname eq '') || ($ccdomain eq '')) {
1.215 raeburn 1147: my $usermsg = &mt('No username and/or domain provided.');
1148: $env{'form.phase'} = '';
1.406.2.14 raeburn 1149: &print_username_entry_form($r,$context,$usermsg,'','',$crstype,$brcrum,
1150: $permission);
1.58 www 1151: return;
1152: }
1.213 raeburn 1153: my ($form,$formname);
1154: if ($env{'form.action'} eq 'singlestudent') {
1155: $form = 'document.enrollstudent';
1156: $formname = 'enrollstudent';
1157: } else {
1158: $form = 'document.cu';
1159: $formname = 'cu';
1160: }
1.188 raeburn 1161: my %abv_auth = &auth_abbrev();
1.227 raeburn 1162: my (%rulematch,%inst_results,$newuser,%alerts,%curr_rules,%got_rules);
1.185 raeburn 1163: my $uhome=&Apache::lonnet::homeserver($ccuname,$ccdomain);
1164: if ($uhome eq 'no_host') {
1.215 raeburn 1165: my $usertype;
1166: my ($rules,$ruleorder) =
1167: &Apache::lonnet::inst_userrules($ccdomain,'username');
1168: $usertype =
1.353 raeburn 1169: &Apache::lonuserutils::check_usertype($ccdomain,$ccuname,$rules,
1.362 raeburn 1170: \%curr_rules,\%got_rules);
1.215 raeburn 1171: my $cancreate =
1172: &Apache::lonuserutils::can_create_user($ccdomain,$context,
1173: $usertype);
1174: if (!$cancreate) {
1.292 bisitz 1175: my $helplink = 'javascript:helpMenu('."'display'".')';
1.215 raeburn 1176: my %usertypetext = (
1177: official => 'institutional',
1178: unofficial => 'non-institutional',
1179: );
1180: my $response;
1181: if ($env{'form.origform'} eq 'crtusername') {
1.362 raeburn 1182: $response = '<span class="LC_warning">'.
1183: &mt('No match found for the username [_1] in LON-CAPA domain: [_2]',
1184: '<b>'.$ccuname.'</b>',$ccdomain).
1.215 raeburn 1185: '</span><br />';
1186: }
1.292 bisitz 1187: $response .= '<p class="LC_warning">'
1188: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
1.406.2.6 raeburn 1189: .' ';
1190: if ($context eq 'domain') {
1191: $response .= &mt('Please contact a [_1] for assistance.',
1192: &Apache::lonnet::plaintext('dc'));
1193: } else {
1194: $response .= &mt('Please contact the [_1]helpdesk[_2] for assistance.'
1195: ,'<a href="'.$helplink.'">','</a>');
1196: }
1197: $response .= '</p><br />';
1.215 raeburn 1198: $env{'form.phase'} = '';
1.406.2.14 raeburn 1199: &print_username_entry_form($r,$context,$response,undef,undef,$crstype,$brcrum,
1200: $permission);
1.215 raeburn 1201: return;
1202: }
1.188 raeburn 1203: $newuser = 1;
1.193 raeburn 1204: my $checkhash;
1205: my $checks = { 'username' => 1 };
1.196 raeburn 1206: $checkhash->{$ccuname.':'.$ccdomain} = { 'newuser' => $newuser };
1.193 raeburn 1207: &Apache::loncommon::user_rule_check($checkhash,$checks,
1.196 raeburn 1208: \%alerts,\%rulematch,\%inst_results,\%curr_rules,\%got_rules);
1209: if (ref($alerts{'username'}) eq 'HASH') {
1210: if (ref($alerts{'username'}{$ccdomain}) eq 'HASH') {
1211: my $domdesc =
1.193 raeburn 1212: &Apache::lonnet::domain($ccdomain,'description');
1.196 raeburn 1213: if ($alerts{'username'}{$ccdomain}{$ccuname}) {
1214: my $userchkmsg;
1215: if (ref($curr_rules{$ccdomain}) eq 'HASH') {
1216: $userchkmsg =
1217: &Apache::loncommon::instrule_disallow_msg('username',
1.193 raeburn 1218: $domdesc,1).
1219: &Apache::loncommon::user_rule_formats($ccdomain,
1220: $domdesc,$curr_rules{$ccdomain}{'username'},
1221: 'username');
1.196 raeburn 1222: }
1.215 raeburn 1223: $env{'form.phase'} = '';
1.406.2.14 raeburn 1224: &print_username_entry_form($r,$context,$userchkmsg,undef,undef,$crstype,$brcrum,
1225: $permission);
1.196 raeburn 1226: return;
1.215 raeburn 1227: }
1.193 raeburn 1228: }
1.185 raeburn 1229: }
1.187 raeburn 1230: } else {
1.188 raeburn 1231: $newuser = 0;
1.185 raeburn 1232: }
1.160 raeburn 1233: if ($response) {
1.215 raeburn 1234: $response = '<br />'.$response;
1.160 raeburn 1235: }
1.149 raeburn 1236:
1.52 matthew 1237: my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
1.88 raeburn 1238: my $dc_setcourse_code = '';
1.119 raeburn 1239: my $nondc_setsection_code = '';
1.112 albertel 1240: my %loaditem;
1.114 albertel 1241:
1.216 raeburn 1242: my $groupslist = &Apache::lonuserutils::get_groupslist();
1.88 raeburn 1243:
1.375 raeburn 1244: my $js = &validation_javascript($context,$ccdomain,$pjump_def,$crstype,
1.216 raeburn 1245: $groupslist,$newuser,$formname,\%loaditem);
1.406.2.7 raeburn 1246: my %breadcrumb_text = &singleuser_breadcrumb($crstype,$context,$ccdomain);
1.224 raeburn 1247: my $helpitem = 'Course_Change_Privileges';
1248: if ($env{'form.action'} eq 'singlestudent') {
1249: $helpitem = 'Course_Add_Student';
1.406.2.14 raeburn 1250: } elsif ($context eq 'author') {
1251: $helpitem = 'Author_Change_Privileges';
1252: } elsif ($context eq 'domain') {
1253: $helpitem = 'Domain_Change_Privileges';
1.224 raeburn 1254: }
1.351 raeburn 1255: push (@{$brcrum},
1256: {href => "javascript:backPage($form)",
1257: text => $breadcrumb_text{'search'},
1258: faq => 282,
1259: bug => 'Instructor Interface',});
1260: if ($env{'form.phase'} eq 'userpicked') {
1261: push(@{$brcrum},
1262: {href => "javascript:backPage($form,'get_user_info','select')",
1263: text => $breadcrumb_text{'userpicked'},
1264: faq => 282,
1265: bug => 'Instructor Interface',});
1266: }
1267: push(@{$brcrum},
1268: {href => "javascript:backPage($form,'$env{'form.phase'}','modify')",
1269: text => $breadcrumb_text{'modify'},
1270: faq => 282,
1271: bug => 'Instructor Interface',
1272: help => $helpitem});
1273: my $args = {'add_entries' => \%loaditem,
1274: 'bread_crumbs' => $brcrum,
1275: 'bread_crumbs_component' => 'User Management'};
1276: if ($env{'form.popup'}) {
1277: $args->{'no_nav_bar'} = 1;
1278: }
1279: my $start_page =
1280: &Apache::loncommon::start_page('User Management',$js,$args);
1.3 www 1281:
1.25 matthew 1282: my $forminfo =<<"ENDFORMINFO";
1.216 raeburn 1283: <form action="/adm/createuser" method="post" name="$formname">
1.190 raeburn 1284: <input type="hidden" name="phase" value="update_user_data" />
1.188 raeburn 1285: <input type="hidden" name="ccuname" value="$ccuname" />
1286: <input type="hidden" name="ccdomain" value="$ccdomain" />
1.157 albertel 1287: <input type="hidden" name="pres_value" value="" />
1288: <input type="hidden" name="pres_type" value="" />
1289: <input type="hidden" name="pres_marker" value="" />
1.25 matthew 1290: ENDFORMINFO
1.375 raeburn 1291: my (%inccourses,$roledom,$defaultcredits);
1.329 raeburn 1292: if ($context eq 'course') {
1293: $inccourses{$env{'request.course.id'}}=1;
1294: $roledom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1.375 raeburn 1295: if ($showcredits) {
1296: $defaultcredits = &Apache::lonuserutils::get_defaultcredits();
1297: }
1.329 raeburn 1298: } elsif ($context eq 'author') {
1299: $roledom = $env{'request.role.domain'};
1300: } elsif ($context eq 'domain') {
1301: foreach my $key (keys(%env)) {
1302: $roledom = $env{'request.role.domain'};
1303: if ($key=~/^user\.priv\.cm\.\/($roledom)\/($match_username)/) {
1304: $inccourses{$1.'_'.$2}=1;
1305: }
1306: }
1307: } else {
1308: foreach my $key (keys(%env)) {
1309: if ($key=~/^user\.priv\.cm\.\/($match_domain)\/($match_username)/) {
1310: $inccourses{$1.'_'.$2}=1;
1311: }
1.2 www 1312: }
1.24 matthew 1313: }
1.389 bisitz 1314: my $title = '';
1.216 raeburn 1315: if ($newuser) {
1.406.2.9 raeburn 1316: my ($portfolioform,$domroleform);
1.267 raeburn 1317: if ((&Apache::lonnet::allowed('mpq',$env{'request.role.domain'})) ||
1318: (&Apache::lonnet::allowed('mut',$env{'request.role.domain'}))) {
1319: # Current user has quota or user tools modification privileges
1.378 raeburn 1320: $portfolioform = '<br />'.&user_quotas($ccuname,$ccdomain);
1.134 raeburn 1321: }
1.383 raeburn 1322: if ((&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) &&
1323: ($ccdomain eq $env{'request.role.domain'})) {
1.362 raeburn 1324: $domroleform = '<br />'.&domainrole_req($ccuname,$ccdomain);
1325: }
1.227 raeburn 1326: &initialize_authen_forms($ccdomain,$formname);
1.188 raeburn 1327: my %lt=&Apache::lonlocal::texthash(
1328: 'lg' => 'Login Data',
1.190 raeburn 1329: 'hs' => "Home Server",
1.188 raeburn 1330: );
1.185 raeburn 1331: $r->print(<<ENDTITLE);
1.110 albertel 1332: $start_page
1.160 raeburn 1333: $response
1.25 matthew 1334: $forminfo
1.31 matthew 1335: <script type="text/javascript" language="Javascript">
1.301 bisitz 1336: // <![CDATA[
1.20 harris41 1337: $loginscript
1.301 bisitz 1338: // ]]>
1.31 matthew 1339: </script>
1.20 harris41 1340: <input type='hidden' name='makeuser' value='1' />
1.185 raeburn 1341: ENDTITLE
1.213 raeburn 1342: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1343: if ($crstype eq 'Community') {
1.389 bisitz 1344: $title = &mt('Create New User [_1] in domain [_2] as a member',
1345: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.318 raeburn 1346: } else {
1.389 bisitz 1347: $title = &mt('Create New User [_1] in domain [_2] as a student',
1348: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.318 raeburn 1349: }
1.389 bisitz 1350: } else {
1351: $title = &mt('Create New User [_1] in domain [_2]',
1352: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.213 raeburn 1353: }
1.389 bisitz 1354: $r->print('<h2>'.$title.'</h2>'."\n");
1355: $r->print('<div class="LC_left_float">');
1.393 raeburn 1356: $r->print(&personal_data_display($ccuname,$ccdomain,$newuser,$context,
1357: $inst_results{$ccuname.':'.$ccdomain}));
1358: # Option to disable student/employee ID conflict checking not offerred for new users.
1.187 raeburn 1359: my ($home_server_pick,$numlib) =
1360: &Apache::loncommon::home_server_form_item($ccdomain,'hserver',
1361: 'default','hide');
1362: if ($numlib > 1) {
1363: $r->print("
1.185 raeburn 1364: <br />
1.187 raeburn 1365: $lt{'hs'}: $home_server_pick
1366: <br />");
1367: } else {
1368: $r->print($home_server_pick);
1369: }
1.304 raeburn 1370: if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
1.362 raeburn 1371: $r->print('<br /><h3>'.
1372: &mt('User Can Request Creation of Courses/Communities in this Domain?').'</h3>'.
1.304 raeburn 1373: &Apache::loncommon::start_data_table().
1374: &build_tools_display($ccuname,$ccdomain,
1375: 'requestcourses').
1376: &Apache::loncommon::end_data_table());
1377: }
1.188 raeburn 1378: $r->print('</div>'."\n".'<div class="LC_left_float"><h3>'.
1379: $lt{'lg'}.'</h3>');
1.185 raeburn 1380: my ($fixedauth,$varauth,$authmsg);
1.193 raeburn 1381: if (ref($rulematch{$ccuname.':'.$ccdomain}) eq 'HASH') {
1382: my $matchedrule = $rulematch{$ccuname.':'.$ccdomain}{'username'};
1383: my ($rules,$ruleorder) =
1384: &Apache::lonnet::inst_userrules($ccdomain,'username');
1.185 raeburn 1385: if (ref($rules) eq 'HASH') {
1.193 raeburn 1386: if (ref($rules->{$matchedrule}) eq 'HASH') {
1387: my $authtype = $rules->{$matchedrule}{'authtype'};
1.185 raeburn 1388: if ($authtype !~ /^(krb4|krb5|int|fsys|loc)$/) {
1.190 raeburn 1389: $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1.275 raeburn 1390: } else {
1.193 raeburn 1391: my $authparm = $rules->{$matchedrule}{'authparm'};
1.273 raeburn 1392: $authmsg = $rules->{$matchedrule}{'authmsg'};
1.185 raeburn 1393: if ($authtype =~ /^krb(4|5)$/) {
1394: my $ver = $1;
1395: if ($authparm ne '') {
1396: $fixedauth = <<"KERB";
1397: <input type="hidden" name="login" value="krb" />
1398: <input type="hidden" name="krbver" value="$ver" />
1399: <input type="hidden" name="krbarg" value="$authparm" />
1400: KERB
1401: }
1402: } else {
1403: $fixedauth =
1404: '<input type="hidden" name="login" value="'.$authtype.'" />'."\n";
1.193 raeburn 1405: if ($rules->{$matchedrule}{'authparmfixed'}) {
1.185 raeburn 1406: $fixedauth .=
1407: '<input type="hidden" name="'.$authtype.'arg" value="'.$authparm.'" />'."\n";
1408: } else {
1.273 raeburn 1409: if ($authtype eq 'int') {
1410: $varauth = '<br />'.
1.301 bisitz 1411: &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 1412: } elsif ($authtype eq 'loc') {
1413: $varauth = '<br />'.
1414: &mt('[_1] Local Authentication with argument [_2]','','<input type="text" name="'.$authtype.'arg" value="" />')."\n";
1415: } else {
1416: $varauth =
1.185 raeburn 1417: '<input type="text" name="'.$authtype.'arg" value="" />'."\n";
1.273 raeburn 1418: }
1.185 raeburn 1419: }
1420: }
1421: }
1422: } else {
1.190 raeburn 1423: $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1.185 raeburn 1424: }
1425: }
1426: if ($authmsg) {
1427: $r->print(<<ENDAUTH);
1428: $fixedauth
1429: $authmsg
1430: $varauth
1431: ENDAUTH
1432: }
1433: } else {
1.190 raeburn 1434: $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1.187 raeburn 1435: }
1.406.2.9 raeburn 1436: $r->print($portfolioform.$domroleform);
1.215 raeburn 1437: if ($env{'form.action'} eq 'singlestudent') {
1438: $r->print(&date_sections_select($context,$newuser,$formname,
1.375 raeburn 1439: $permission,$crstype,$ccuname,
1440: $ccdomain,$showcredits));
1.215 raeburn 1441: }
1442: $r->print('</div><div class="LC_clear_float_footer"></div>');
1.216 raeburn 1443: } else { # user already exists
1.389 bisitz 1444: $r->print($start_page.$forminfo);
1.213 raeburn 1445: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1446: if ($crstype eq 'Community') {
1.389 bisitz 1447: $title = &mt('Enroll one member: [_1] in domain [_2]',
1448: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.318 raeburn 1449: } else {
1.389 bisitz 1450: $title = &mt('Enroll one student: [_1] in domain [_2]',
1451: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.318 raeburn 1452: }
1.213 raeburn 1453: } else {
1.406.2.6 raeburn 1454: if ($permission->{'cusr'}) {
1455: $title = &mt('Modify existing user: [_1] in domain [_2]',
1456: '"'.$ccuname.'"','"'.$ccdomain.'"');
1457: } else {
1458: $title = &mt('Existing user: [_1] in domain [_2]',
1.389 bisitz 1459: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.406.2.6 raeburn 1460: }
1.213 raeburn 1461: }
1.389 bisitz 1462: $r->print('<h2>'.$title.'</h2>'."\n");
1463: $r->print('<div class="LC_left_float">');
1.393 raeburn 1464: $r->print(&personal_data_display($ccuname,$ccdomain,$newuser,$context,
1465: $inst_results{$ccuname.':'.$ccdomain}));
1.406.2.6 raeburn 1466: if ((&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) ||
1467: (&Apache::lonnet::allowed('udp',$env{'request.role.domain'}))) {
1.362 raeburn 1468: $r->print('<br /><h3>'.&mt('User Can Request Creation of Courses/Communities in this Domain?').'</h3>'.
1.300 raeburn 1469: &Apache::loncommon::start_data_table());
1.314 raeburn 1470: if ($env{'request.role.domain'} eq $ccdomain) {
1.300 raeburn 1471: $r->print(&build_tools_display($ccuname,$ccdomain,'requestcourses'));
1472: } else {
1473: $r->print(&coursereq_externaluser($ccuname,$ccdomain,
1474: $env{'request.role.domain'}));
1475: }
1476: $r->print(&Apache::loncommon::end_data_table());
1.275 raeburn 1477: }
1.199 raeburn 1478: $r->print('</div>');
1.406.2.9 raeburn 1479: my @order = ('auth','quota','tools','requestauthor');
1.362 raeburn 1480: my %user_text;
1481: my ($isadv,$isauthor) =
1.406.2.6 raeburn 1482: &Apache::lonnet::is_advanced_user($ccdomain,$ccuname);
1.362 raeburn 1483: if ((!$isauthor) &&
1.406.2.6 raeburn 1484: ((&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) ||
1485: (&Apache::lonnet::allowed('udp',$env{'request.role.domain'}))) &&
1486: ($env{'request.role.domain'} eq $ccdomain)) {
1.362 raeburn 1487: $user_text{'requestauthor'} = &domainrole_req($ccuname,$ccdomain);
1488: }
1489: $user_text{'auth'} = &user_authentication($ccuname,$ccdomain,$formname);
1.267 raeburn 1490: if ((&Apache::lonnet::allowed('mpq',$ccdomain)) ||
1.406.2.6 raeburn 1491: (&Apache::lonnet::allowed('mut',$ccdomain)) ||
1492: (&Apache::lonnet::allowed('udp',$ccdomain))) {
1.188 raeburn 1493: # Current user has quota modification privileges
1.378 raeburn 1494: $user_text{'quota'} = &user_quotas($ccuname,$ccdomain);
1.267 raeburn 1495: }
1496: if (!&Apache::lonnet::allowed('mpq',$ccdomain)) {
1497: if (&Apache::lonnet::allowed('mpq',$env{'request.role.domain'})) {
1498: my %lt=&Apache::lonlocal::texthash(
1.385 bisitz 1499: 'dska' => "Disk quotas for user's portfolio and Authoring Space",
1500: 'youd' => "You do not have privileges to modify the portfolio and/or Authoring Space quotas for this user.",
1.267 raeburn 1501: 'ichr' => "If a change is required, contact a domain coordinator for the domain",
1502: );
1.362 raeburn 1503: $user_text{'quota'} = <<ENDNOPORTPRIV;
1.188 raeburn 1504: <h3>$lt{'dska'}</h3>
1505: $lt{'youd'} $lt{'ichr'}: $ccdomain
1506: ENDNOPORTPRIV
1.267 raeburn 1507: }
1508: }
1509: if (!&Apache::lonnet::allowed('mut',$ccdomain)) {
1510: if (&Apache::lonnet::allowed('mut',$env{'request.role.domain'})) {
1511: my %lt=&Apache::lonlocal::texthash(
1512: 'utav' => "User Tools Availability",
1.361 raeburn 1513: 'yodo' => "You do not have privileges to modify Portfolio, Blog, WebDAV, or Personal Information Page settings for this user.",
1.267 raeburn 1514: 'ifch' => "If a change is required, contact a domain coordinator for the domain",
1515: );
1.362 raeburn 1516: $user_text{'tools'} = <<ENDNOTOOLSPRIV;
1.267 raeburn 1517: <h3>$lt{'utav'}</h3>
1518: $lt{'yodo'} $lt{'ifch'}: $ccdomain
1519: ENDNOTOOLSPRIV
1520: }
1.188 raeburn 1521: }
1.362 raeburn 1522: my $gotdiv = 0;
1523: foreach my $item (@order) {
1524: if ($user_text{$item} ne '') {
1525: unless ($gotdiv) {
1526: $r->print('<div class="LC_left_float">');
1527: $gotdiv = 1;
1528: }
1529: $r->print('<br />'.$user_text{$item});
1530: }
1531: }
1532: if ($env{'form.action'} eq 'singlestudent') {
1533: unless ($gotdiv) {
1534: $r->print('<div class="LC_left_float">');
1.213 raeburn 1535: }
1.375 raeburn 1536: my $credits;
1537: if ($showcredits) {
1538: $credits = &get_user_credits($ccuname,$ccdomain,$defaultcredits);
1539: if ($credits eq '') {
1540: $credits = $defaultcredits;
1541: }
1542: }
1.374 raeburn 1543: $r->print(&date_sections_select($context,$newuser,$formname,
1.375 raeburn 1544: $permission,$crstype,$ccuname,
1545: $ccdomain,$showcredits));
1.374 raeburn 1546: }
1.362 raeburn 1547: if ($gotdiv) {
1548: $r->print('</div><div class="LC_clear_float_footer"></div>');
1.188 raeburn 1549: }
1.406.2.6 raeburn 1550: my $statuses;
1551: if (($context eq 'domain') && (&Apache::lonnet::allowed('udp',$ccdomain)) &&
1552: (!&Apache::lonnet::allowed('mau',$ccdomain))) {
1553: $statuses = ['active'];
1554: } elsif (($context eq 'course') && ((&Apache::lonnet::allowed('vcl',$env{'request.course.id'})) ||
1555: ($env{'request.course.sec'} &&
1556: &Apache::lonnet::allowed('vcl',$env{'request.course.id'}.'/'.$env{'request.course.sec'})))) {
1557: $statuses = ['active'];
1558: }
1.217 raeburn 1559: if ($env{'form.action'} ne 'singlestudent') {
1.329 raeburn 1560: &display_existing_roles($r,$ccuname,$ccdomain,\%inccourses,$context,
1.406.2.6 raeburn 1561: $roledom,$crstype,$showcredits,$statuses);
1.217 raeburn 1562: }
1.25 matthew 1563: } ## End of new user/old user logic
1.218 raeburn 1564: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1565: my $btntxt;
1566: if ($crstype eq 'Community') {
1567: $btntxt = &mt('Enroll Member');
1568: } else {
1569: $btntxt = &mt('Enroll Student');
1570: }
1571: $r->print('<br /><input type="button" value="'.$btntxt.'" onclick="setSections(this.form)" />'."\n");
1.406.2.6 raeburn 1572: } elsif ($permission->{'cusr'}) {
1.393 raeburn 1573: $r->print('<div class="LC_left_float">'.
1574: '<fieldset><legend>'.&mt('Add Roles').'</legend>');
1.218 raeburn 1575: my $addrolesdisplay = 0;
1576: if ($context eq 'domain' || $context eq 'author') {
1577: $addrolesdisplay = &new_coauthor_roles($r,$ccuname,$ccdomain);
1578: }
1579: if ($context eq 'domain') {
1.357 raeburn 1580: my $add_domainroles = &new_domain_roles($r,$ccdomain);
1.218 raeburn 1581: if (!$addrolesdisplay) {
1582: $addrolesdisplay = $add_domainroles;
1.2 www 1583: }
1.375 raeburn 1584: $r->print(&course_level_dc($env{'request.role.domain'},$showcredits));
1.393 raeburn 1585: $r->print('</fieldset></div><div class="LC_clear_float_footer"></div>'.
1586: '<br /><input type="button" value="'.&mt('Save').'" onclick="setCourse()" />'."\n");
1.218 raeburn 1587: } elsif ($context eq 'author') {
1588: if ($addrolesdisplay) {
1.393 raeburn 1589: $r->print('</fieldset></div><div class="LC_clear_float_footer"></div>'.
1590: '<br /><input type="button" value="'.&mt('Save').'"');
1.218 raeburn 1591: if ($newuser) {
1.301 bisitz 1592: $r->print(' onclick="auth_check()" \>'."\n");
1.218 raeburn 1593: } else {
1.301 bisitz 1594: $r->print('onclick="this.form.submit()" \>'."\n");
1.218 raeburn 1595: }
1.188 raeburn 1596: } else {
1.393 raeburn 1597: $r->print('</fieldset></div>'.
1598: '<div class="LC_clear_float_footer"></div>'.
1599: '<br /><a href="javascript:backPage(document.cu)">'.
1.218 raeburn 1600: &mt('Back to previous page').'</a>');
1.188 raeburn 1601: }
1602: } else {
1.375 raeburn 1603: $r->print(&course_level_table(\%inccourses,$showcredits,$defaultcredits));
1.393 raeburn 1604: $r->print('</fieldset></div><div class="LC_clear_float_footer"></div>'.
1605: '<br /><input type="button" value="'.&mt('Save').'" onclick="setSections(this.form)" />'."\n");
1.188 raeburn 1606: }
1.88 raeburn 1607: }
1.188 raeburn 1608: $r->print(&Apache::lonhtmlcommon::echo_form_input(['phase','userrole','ccdomain','prevphase','currstate','ccuname','ccdomain']));
1.179 raeburn 1609: $r->print('<input type="hidden" name="currstate" value="" />');
1.393 raeburn 1610: $r->print('<input type="hidden" name="prevphase" value="'.$env{'form.phase'}.'" /></form><br /><br />');
1.218 raeburn 1611: return;
1.2 www 1612: }
1.1 www 1613:
1.213 raeburn 1614: sub singleuser_breadcrumb {
1.406.2.7 raeburn 1615: my ($crstype,$context,$domain) = @_;
1.213 raeburn 1616: my %breadcrumb_text;
1617: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1618: if ($crstype eq 'Community') {
1619: $breadcrumb_text{'search'} = 'Enroll a member';
1620: } else {
1621: $breadcrumb_text{'search'} = 'Enroll a student';
1622: }
1.406.2.7 raeburn 1623: $breadcrumb_text{'userpicked'} = 'Select a user';
1624: $breadcrumb_text{'modify'} = 'Set section/dates';
1.406.2.5 raeburn 1625: } elsif ($env{'form.action'} eq 'accesslogs') {
1626: $breadcrumb_text{'search'} = 'View access logs for a user';
1.406.2.7 raeburn 1627: $breadcrumb_text{'userpicked'} = 'Select a user';
1628: $breadcrumb_text{'activity'} = 'Activity';
1629: } elsif (($env{'form.action'} eq 'singleuser') && ($context eq 'domain') &&
1630: (!&Apache::lonnet::allowed('mau',$domain))) {
1631: $breadcrumb_text{'search'} = "View user's roles";
1632: $breadcrumb_text{'userpicked'} = 'Select a user';
1633: $breadcrumb_text{'modify'} = 'User roles';
1.213 raeburn 1634: } else {
1.229 raeburn 1635: $breadcrumb_text{'search'} = 'Create/modify a user';
1.406.2.7 raeburn 1636: $breadcrumb_text{'userpicked'} = 'Select a user';
1637: $breadcrumb_text{'modify'} = 'Set user role';
1.213 raeburn 1638: }
1639: return %breadcrumb_text;
1640: }
1641:
1642: sub date_sections_select {
1.375 raeburn 1643: my ($context,$newuser,$formname,$permission,$crstype,$ccuname,$ccdomain,
1644: $showcredits) = @_;
1645: my $credits;
1646: if ($showcredits) {
1647: my $defaultcredits = &Apache::lonuserutils::get_defaultcredits();
1648: $credits = &get_user_credits($ccuname,$ccdomain,$defaultcredits);
1649: if ($credits eq '') {
1650: $credits = $defaultcredits;
1651: }
1652: }
1.213 raeburn 1653: my $cid = $env{'request.course.id'};
1654: my ($cnum,$cdom) = &Apache::lonuserutils::get_course_identity($cid);
1655: my $date_table = '<h3>'.&mt('Starting and Ending Dates').'</h3>'."\n".
1656: &Apache::lonuserutils::date_setting_table(undef,undef,$context,
1657: undef,$formname,$permission);
1658: my $rowtitle = 'Section';
1.375 raeburn 1659: my $secbox = '<h3>'.&mt('Section and Credits').'</h3>'."\n".
1.213 raeburn 1660: &Apache::lonuserutils::section_picker($cdom,$cnum,'st',$rowtitle,
1.375 raeburn 1661: $permission,$context,'',$crstype,
1662: $showcredits,$credits);
1.213 raeburn 1663: my $output = $date_table.$secbox;
1664: return $output;
1665: }
1666:
1.216 raeburn 1667: sub validation_javascript {
1.375 raeburn 1668: my ($context,$ccdomain,$pjump_def,$crstype,$groupslist,$newuser,$formname,
1.216 raeburn 1669: $loaditem) = @_;
1670: my $dc_setcourse_code = '';
1671: my $nondc_setsection_code = '';
1672: if ($context eq 'domain') {
1673: my $dcdom = $env{'request.role.domain'};
1674: $loaditem->{'onload'} = "document.cu.coursedesc.value='';";
1.227 raeburn 1675: $dc_setcourse_code =
1676: &Apache::lonuserutils::dc_setcourse_js('cu','singleuser',$context);
1.216 raeburn 1677: } else {
1.227 raeburn 1678: my $checkauth;
1679: if (($newuser) || (&Apache::lonnet::allowed('mau',$ccdomain))) {
1680: $checkauth = 1;
1681: }
1682: if ($context eq 'course') {
1683: $nondc_setsection_code =
1684: &Apache::lonuserutils::setsections_javascript($formname,$groupslist,
1.375 raeburn 1685: undef,$checkauth,
1686: $crstype);
1.227 raeburn 1687: }
1688: if ($checkauth) {
1689: $nondc_setsection_code .=
1690: &Apache::lonuserutils::verify_authen($formname,$context);
1691: }
1.216 raeburn 1692: }
1693: my $js = &user_modification_js($pjump_def,$dc_setcourse_code,
1694: $nondc_setsection_code,$groupslist);
1695: my ($jsback,$elements) = &crumb_utilities();
1696: $js .= "\n".
1.301 bisitz 1697: '<script type="text/javascript">'."\n".
1698: '// <![CDATA['."\n".
1699: $jsback."\n".
1700: '// ]]>'."\n".
1701: '</script>'."\n";
1.216 raeburn 1702: return $js;
1703: }
1704:
1.217 raeburn 1705: sub display_existing_roles {
1.375 raeburn 1706: my ($r,$ccuname,$ccdomain,$inccourses,$context,$roledom,$crstype,
1.406.2.6 raeburn 1707: $showcredits,$statuses) = @_;
1.329 raeburn 1708: my $now=time;
1.406.2.6 raeburn 1709: my $showall = 1;
1710: my ($showexpired,$showactive);
1711: if ((ref($statuses) eq 'ARRAY') && (@{$statuses} > 0)) {
1712: $showall = 0;
1713: if (grep(/^expired$/,@{$statuses})) {
1714: $showexpired = 1;
1715: }
1716: if (grep(/^active$/,@{$statuses})) {
1717: $showactive = 1;
1718: }
1719: if ($showexpired && $showactive) {
1720: $showall = 1;
1721: }
1722: }
1.329 raeburn 1723: my %lt=&Apache::lonlocal::texthash(
1.217 raeburn 1724: 'rer' => "Existing Roles",
1725: 'rev' => "Revoke",
1726: 'del' => "Delete",
1727: 'ren' => "Re-Enable",
1728: 'rol' => "Role",
1729: 'ext' => "Extent",
1.375 raeburn 1730: 'crd' => "Credits",
1.217 raeburn 1731: 'sta' => "Start",
1732: 'end' => "End",
1733: );
1.329 raeburn 1734: my (%rolesdump,%roletext,%sortrole,%roleclass,%rolepriv);
1735: if ($context eq 'course' || $context eq 'author') {
1736: my @roles = &Apache::lonuserutils::roles_by_context($context,1,$crstype);
1737: my %roleshash =
1738: &Apache::lonnet::get_my_roles($ccuname,$ccdomain,'userroles',
1739: ['active','previous','future'],\@roles,$roledom,1);
1740: foreach my $key (keys(%roleshash)) {
1741: my ($start,$end) = split(':',$roleshash{$key});
1742: next if ($start eq '-1' || $end eq '-1');
1743: my ($rnum,$rdom,$role,$sec) = split(':',$key);
1744: if ($context eq 'course') {
1745: next unless (($rnum eq $env{'course.'.$env{'request.course.id'}.'.num'})
1746: && ($rdom eq $env{'course.'.$env{'request.course.id'}.'.domain'}));
1747: } elsif ($context eq 'author') {
1748: next unless (($rnum eq $env{'user.name'}) && ($rdom eq $env{'request.role.domain'}));
1749: }
1750: my ($newkey,$newvalue,$newrole);
1751: $newkey = '/'.$rdom.'/'.$rnum;
1752: if ($sec ne '') {
1753: $newkey .= '/'.$sec;
1754: }
1755: $newvalue = $role;
1756: if ($role =~ /^cr/) {
1757: $newrole = 'cr';
1758: } else {
1759: $newrole = $role;
1760: }
1761: $newkey .= '_'.$newrole;
1762: if ($start ne '' && $end ne '') {
1763: $newvalue .= '_'.$end.'_'.$start;
1.335 raeburn 1764: } elsif ($end ne '') {
1765: $newvalue .= '_'.$end;
1.329 raeburn 1766: }
1767: $rolesdump{$newkey} = $newvalue;
1768: }
1769: } else {
1.360 raeburn 1770: %rolesdump=&Apache::lonnet::dump('roles',$ccdomain,$ccuname);
1.329 raeburn 1771: }
1772: # Build up table of user roles to allow revocation and re-enabling of roles.
1773: my ($tmp) = keys(%rolesdump);
1774: return if ($tmp =~ /^(con_lost|error)/i);
1775: foreach my $area (sort { my $a1=join('_',(split('_',$a))[1,0]);
1776: my $b1=join('_',(split('_',$b))[1,0]);
1777: return $a1 cmp $b1;
1778: } keys(%rolesdump)) {
1779: next if ($area =~ /^rolesdef/);
1780: my $envkey=$area;
1781: my $role = $rolesdump{$area};
1782: my $thisrole=$area;
1783: $area =~ s/\_\w\w$//;
1784: my ($role_code,$role_end_time,$role_start_time) =
1785: split(/_/,$role);
1.406.2.6 raeburn 1786: my $active=1;
1787: $active=0 if (($role_end_time) && ($now>$role_end_time));
1788: if ($active) {
1789: next unless($showall || $showactive);
1790: } else {
1791: next unless($showall || $showexpired);
1792: }
1.217 raeburn 1793: # Is this a custom role? Get role owner and title.
1.329 raeburn 1794: my ($croleudom,$croleuname,$croletitle)=
1795: ($role_code=~m{^cr/($match_domain)/($match_username)/(\w+)$});
1796: my $allowed=0;
1797: my $delallowed=0;
1798: my $sortkey=$role_code;
1799: my $class='Unknown';
1.375 raeburn 1800: my $credits='';
1.406.2.6 raeburn 1801: my $csec;
1.406.2.7 raeburn 1802: if ($area =~ m{^/($match_domain)/($match_courseid)}) {
1.329 raeburn 1803: $class='Course';
1804: my ($coursedom,$coursedir) = ($1,$2);
1805: my $cid = $1.'_'.$2;
1806: # $1.'_'.$2 is the course id (eg. 103_12345abcef103l3).
1.406.2.7 raeburn 1807: next if ($envkey =~ m{^/$match_domain/$match_courseid/[A-Za-z0-9]+_gr$});
1.329 raeburn 1808: my %coursedata=
1809: &Apache::lonnet::coursedescription($cid);
1810: if ($coursedir =~ /^$match_community$/) {
1811: $class='Community';
1812: }
1813: $sortkey.="\0$coursedom";
1814: my $carea;
1815: if (defined($coursedata{'description'})) {
1816: $carea=$coursedata{'description'}.
1817: '<br />'.&mt('Domain').': '.$coursedom.(' 'x8).
1818: &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$coursedir,$coursedom);
1819: $sortkey.="\0".$coursedata{'description'};
1820: } else {
1821: if ($class eq 'Community') {
1822: $carea=&mt('Unavailable community').': '.$area;
1823: $sortkey.="\0".&mt('Unavailable community').': '.$area;
1.217 raeburn 1824: } else {
1825: $carea=&mt('Unavailable course').': '.$area;
1826: $sortkey.="\0".&mt('Unavailable course').': '.$area;
1827: }
1.329 raeburn 1828: }
1829: $sortkey.="\0$coursedir";
1830: $inccourses->{$cid}=1;
1.375 raeburn 1831: if (($showcredits) && ($class eq 'Course') && ($role_code eq 'st')) {
1832: my $defaultcredits = $coursedata{'internal.defaultcredits'};
1833: $credits =
1834: &get_user_credits($ccuname,$ccdomain,$defaultcredits,
1835: $coursedom,$coursedir);
1836: if ($credits eq '') {
1837: $credits = $defaultcredits;
1838: }
1839: }
1.329 raeburn 1840: if ((&Apache::lonnet::allowed('c'.$role_code,$coursedom.'/'.$coursedir)) ||
1841: (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) {
1842: $allowed=1;
1843: }
1844: unless ($allowed) {
1.365 raeburn 1845: my $isowner = &Apache::lonuserutils::is_courseowner($cid,$coursedata{'internal.courseowner'});
1.329 raeburn 1846: if ($isowner) {
1847: if (($role_code eq 'co') && ($class eq 'Community')) {
1848: $allowed = 1;
1849: } elsif (($role_code eq 'cc') && ($class eq 'Course')) {
1850: $allowed = 1;
1851: }
1.217 raeburn 1852: }
1.329 raeburn 1853: }
1854: if ((&Apache::lonnet::allowed('dro',$coursedom)) ||
1855: (&Apache::lonnet::allowed('dro',$ccdomain))) {
1856: $delallowed=1;
1857: }
1.217 raeburn 1858: # - custom role. Needs more info, too
1.329 raeburn 1859: if ($croletitle) {
1860: if (&Apache::lonnet::allowed('ccr',$coursedom.'/'.$coursedir)) {
1861: $allowed=1;
1862: $thisrole.='.'.$role_code;
1.217 raeburn 1863: }
1.329 raeburn 1864: }
1.406.2.6 raeburn 1865: if ($area=~m{^/($match_domain/$match_courseid/(\w+))}) {
1866: $csec = $2;
1867: $carea.='<br />'.&mt('Section: [_1]',$csec);
1868: $sortkey.="\0$csec";
1.329 raeburn 1869: if (!$allowed) {
1.406.2.6 raeburn 1870: if ($env{'request.course.sec'} eq $csec) {
1871: if (&Apache::lonnet::allowed('c'.$role_code,$1)) {
1.329 raeburn 1872: $allowed = 1;
1.217 raeburn 1873: }
1874: }
1875: }
1.329 raeburn 1876: }
1877: $area=$carea;
1878: } else {
1879: $sortkey.="\0".$area;
1880: # Determine if current user is able to revoke privileges
1881: if ($area=~m{^/($match_domain)/}) {
1882: if ((&Apache::lonnet::allowed('c'.$role_code,$1)) ||
1883: (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) {
1884: $allowed=1;
1.217 raeburn 1885: }
1.329 raeburn 1886: if (((&Apache::lonnet::allowed('dro',$1)) ||
1887: (&Apache::lonnet::allowed('dro',$ccdomain))) &&
1888: ($role_code ne 'dc')) {
1889: $delallowed=1;
1.217 raeburn 1890: }
1.329 raeburn 1891: } else {
1892: if (&Apache::lonnet::allowed('c'.$role_code,'/')) {
1.217 raeburn 1893: $allowed=1;
1894: }
1895: }
1.363 raeburn 1896: if ($role_code eq 'ca' || $role_code eq 'au' || $role_code eq 'aa') {
1.377 raeburn 1897: $class='Authoring Space';
1.329 raeburn 1898: } elsif ($role_code eq 'su') {
1899: $class='System';
1.217 raeburn 1900: } else {
1.329 raeburn 1901: $class='Domain';
1.217 raeburn 1902: }
1.329 raeburn 1903: }
1904: if (($role_code eq 'ca') || ($role_code eq 'aa')) {
1905: $area=~m{/($match_domain)/($match_username)};
1906: if (&Apache::lonuserutils::authorpriv($2,$1)) {
1907: $allowed=1;
1.217 raeburn 1908: } else {
1.329 raeburn 1909: $allowed=0;
1.217 raeburn 1910: }
1.329 raeburn 1911: }
1912: my $row = '';
1.406.2.6 raeburn 1913: if ($showall) {
1914: $row.= '<td>';
1915: if (($active) && ($allowed)) {
1916: $row.= '<input type="checkbox" name="rev:'.$thisrole.'" />';
1.217 raeburn 1917: } else {
1.406.2.6 raeburn 1918: if ($active) {
1919: $row.=' ';
1920: } else {
1921: $row.=&mt('expired or revoked');
1922: }
1.217 raeburn 1923: }
1.406.2.6 raeburn 1924: $row.='</td><td>';
1925: if ($allowed && !$active) {
1926: $row.= '<input type="checkbox" name="ren:'.$thisrole.'" />';
1927: } else {
1928: $row.=' ';
1929: }
1930: $row.='</td><td>';
1931: if ($delallowed) {
1932: $row.= '<input type="checkbox" name="del:'.$thisrole.'" />';
1933: } else {
1934: $row.=' ';
1935: }
1936: $row.= '</td>';
1.329 raeburn 1937: }
1938: my $plaintext='';
1939: if (!$croletitle) {
1.375 raeburn 1940: $plaintext=&Apache::lonnet::plaintext($role_code,$class);
1941: if (($showcredits) && ($credits ne '')) {
1942: $plaintext .= '<br/ ><span class="LC_nobreak">'.
1943: '<span class="LC_fontsize_small">'.
1944: &mt('Credits: [_1]',$credits).
1945: '</span></span>';
1946: }
1.329 raeburn 1947: } else {
1948: $plaintext=
1.395 bisitz 1949: &mt('Custom role [_1][_2]defined by [_3]',
1.346 bisitz 1950: '"'.$croletitle.'"',
1951: '<br />',
1952: $croleuname.':'.$croleudom);
1.329 raeburn 1953: }
1.406.2.6 raeburn 1954: $row.= '<td>'.$plaintext.'</td>'.
1955: '<td>'.$area.'</td>'.
1956: '<td>'.($role_start_time?&Apache::lonlocal::locallocaltime($role_start_time)
1957: : ' ' ).'</td>'.
1958: '<td>'.($role_end_time ?&Apache::lonlocal::locallocaltime($role_end_time)
1959: : ' ' ).'</td>';
1.329 raeburn 1960: $sortrole{$sortkey}=$envkey;
1961: $roletext{$envkey}=$row;
1962: $roleclass{$envkey}=$class;
1.406.2.6 raeburn 1963: if ($allowed) {
1964: $rolepriv{$envkey}='edit';
1965: } else {
1966: if ($context eq 'domain') {
1.406.2.7 raeburn 1967: if ((&Apache::lonnet::allowed('vur',$ccdomain)) &&
1968: ($envkey=~m{^/$ccdomain/})) {
1.406.2.6 raeburn 1969: $rolepriv{$envkey}='view';
1970: }
1971: } elsif ($context eq 'course') {
1972: if ((&Apache::lonnet::allowed('vcl',$env{'request.course.id'})) ||
1973: ($env{'request.course.sec'} && ($env{'request.course.sec'} eq $csec) &&
1974: &Apache::lonnet::allowed('vcl',$env{'request.course.id'}.'/'.$env{'request.course.sec'}))) {
1975: $rolepriv{$envkey}='view';
1976: }
1977: }
1978: }
1.329 raeburn 1979: } # end of foreach (table building loop)
1980:
1981: my $rolesdisplay = 0;
1982: my %output = ();
1.377 raeburn 1983: foreach my $type ('Authoring Space','Course','Community','Domain','System','Unknown') {
1.329 raeburn 1984: $output{$type} = '';
1985: foreach my $which (sort {uc($a) cmp uc($b)} (keys(%sortrole))) {
1986: if ( ($roleclass{$sortrole{$which}} =~ /^\Q$type\E/ ) && ($rolepriv{$sortrole{$which}}) ) {
1987: $output{$type}.=
1988: &Apache::loncommon::start_data_table_row().
1989: $roletext{$sortrole{$which}}.
1990: &Apache::loncommon::end_data_table_row();
1.217 raeburn 1991: }
1.329 raeburn 1992: }
1993: unless($output{$type} eq '') {
1994: $output{$type} = '<tr class="LC_info_row">'.
1995: "<td align='center' colspan='7'>".&mt($type)."</td></tr>".
1996: $output{$type};
1997: $rolesdisplay = 1;
1998: }
1999: }
2000: if ($rolesdisplay == 1) {
2001: my $contextrole='';
2002: if ($env{'request.course.id'}) {
2003: if (&Apache::loncommon::course_type() eq 'Community') {
2004: $contextrole = &mt('Existing Roles in this Community');
1.290 bisitz 2005: } else {
1.329 raeburn 2006: $contextrole = &mt('Existing Roles in this Course');
1.290 bisitz 2007: }
1.329 raeburn 2008: } elsif ($env{'request.role'} =~ /^au\./) {
1.377 raeburn 2009: $contextrole = &mt('Existing Co-Author Roles in your Authoring Space');
1.329 raeburn 2010: } else {
1.406.2.6 raeburn 2011: if ($showall) {
2012: $contextrole = &mt('Existing Roles in this Domain');
2013: } elsif ($showactive) {
2014: $contextrole = &mt('Unexpired Roles in this Domain');
2015: } elsif ($showexpired) {
2016: $contextrole = &mt('Expired or Revoked Roles in this Domain');
2017: }
1.329 raeburn 2018: }
1.393 raeburn 2019: $r->print('<div class="LC_left_float">'.
1.375 raeburn 2020: '<fieldset><legend>'.$contextrole.'</legend>'.
1.217 raeburn 2021: &Apache::loncommon::start_data_table("LC_createuser").
1.406.2.6 raeburn 2022: &Apache::loncommon::start_data_table_header_row());
2023: if ($showall) {
2024: $r->print(
2025: '<th>'.$lt{'rev'}.'</th><th>'.$lt{'ren'}.'</th><th>'.$lt{'del'}.'</th>'
2026: );
2027: } elsif ($showexpired) {
2028: $r->print('<th>'.$lt{'rev'}.'</th>');
2029: }
2030: $r->print(
2031: '<th>'.$lt{'rol'}.'</th><th>'.$lt{'ext'}.'</th>'.
2032: '<th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'.
1.217 raeburn 2033: &Apache::loncommon::end_data_table_header_row());
1.377 raeburn 2034: foreach my $type ('Authoring Space','Course','Community','Domain','System','Unknown') {
1.329 raeburn 2035: if ($output{$type}) {
2036: $r->print($output{$type}."\n");
1.217 raeburn 2037: }
2038: }
1.375 raeburn 2039: $r->print(&Apache::loncommon::end_data_table().
2040: '</fieldset></div>');
1.329 raeburn 2041: }
1.217 raeburn 2042: return;
2043: }
2044:
1.218 raeburn 2045: sub new_coauthor_roles {
2046: my ($r,$ccuname,$ccdomain) = @_;
2047: my $addrolesdisplay = 0;
2048: #
2049: # Co-Author
2050: #
2051: if (&Apache::lonuserutils::authorpriv($env{'user.name'},
2052: $env{'request.role.domain'}) &&
2053: ($env{'user.name'} ne $ccuname || $env{'user.domain'} ne $ccdomain)) {
2054: # No sense in assigning co-author role to yourself
2055: $addrolesdisplay = 1;
2056: my $cuname=$env{'user.name'};
2057: my $cudom=$env{'request.role.domain'};
2058: my %lt=&Apache::lonlocal::texthash(
1.377 raeburn 2059: 'cs' => "Authoring Space",
1.218 raeburn 2060: 'act' => "Activate",
2061: 'rol' => "Role",
2062: 'ext' => "Extent",
2063: 'sta' => "Start",
2064: 'end' => "End",
2065: 'cau' => "Co-Author",
2066: 'caa' => "Assistant Co-Author",
2067: 'ssd' => "Set Start Date",
2068: 'sed' => "Set End Date"
2069: );
2070: $r->print('<h4>'.$lt{'cs'}.'</h4>'."\n".
2071: &Apache::loncommon::start_data_table()."\n".
2072: &Apache::loncommon::start_data_table_header_row()."\n".
2073: '<th>'.$lt{'act'}.'</th><th>'.$lt{'rol'}.'</th>'.
2074: '<th>'.$lt{'ext'}.'</th><th>'.$lt{'sta'}.'</th>'.
2075: '<th>'.$lt{'end'}.'</th>'."\n".
2076: &Apache::loncommon::end_data_table_header_row()."\n".
2077: &Apache::loncommon::start_data_table_row().'
2078: <td>
1.291 bisitz 2079: <input type="checkbox" name="act_'.$cudom.'_'.$cuname.'_ca" />
1.218 raeburn 2080: </td>
2081: <td>'.$lt{'cau'}.'</td>
2082: <td>'.$cudom.'_'.$cuname.'</td>
2083: <td><input type="hidden" name="start_'.$cudom.'_'.$cuname.'_ca" value="" />
2084: <a href=
2085: "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>
2086: <td><input type="hidden" name="end_'.$cudom.'_'.$cuname.'_ca" value="" />
2087: <a href=
2088: "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".
2089: &Apache::loncommon::end_data_table_row()."\n".
2090: &Apache::loncommon::start_data_table_row()."\n".
1.291 bisitz 2091: '<td><input type="checkbox" name="act_'.$cudom.'_'.$cuname.'_aa" /></td>
1.218 raeburn 2092: <td>'.$lt{'caa'}.'</td>
2093: <td>'.$cudom.'_'.$cuname.'</td>
2094: <td><input type="hidden" name="start_'.$cudom.'_'.$cuname.'_aa" value="" />
2095: <a href=
2096: "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>
2097: <td><input type="hidden" name="end_'.$cudom.'_'.$cuname.'_aa" value="" />
2098: <a href=
2099: "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".
2100: &Apache::loncommon::end_data_table_row()."\n".
2101: &Apache::loncommon::end_data_table());
2102: } elsif ($env{'request.role'} =~ /^au\./) {
2103: if (!(&Apache::lonuserutils::authorpriv($env{'user.name'},
2104: $env{'request.role.domain'}))) {
2105: $r->print('<span class="LC_error">'.
2106: &mt('You do not have privileges to assign co-author roles.').
2107: '</span>');
2108: } elsif (($env{'user.name'} eq $ccuname) &&
2109: ($env{'user.domain'} eq $ccdomain)) {
1.377 raeburn 2110: $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 2111: }
2112: }
2113: return $addrolesdisplay;;
2114: }
2115:
2116: sub new_domain_roles {
1.357 raeburn 2117: my ($r,$ccdomain) = @_;
1.218 raeburn 2118: my $addrolesdisplay = 0;
2119: #
2120: # Domain level
2121: #
2122: my $num_domain_level = 0;
2123: my $domaintext =
2124: '<h4>'.&mt('Domain Level').'</h4>'.
2125: &Apache::loncommon::start_data_table().
2126: &Apache::loncommon::start_data_table_header_row().
2127: '<th>'.&mt('Activate').'</th><th>'.&mt('Role').'</th><th>'.
2128: &mt('Extent').'</th>'.
2129: '<th>'.&mt('Start').'</th><th>'.&mt('End').'</th>'.
2130: &Apache::loncommon::end_data_table_header_row();
1.312 raeburn 2131: my @allroles = &Apache::lonuserutils::roles_by_context('domain');
1.218 raeburn 2132: foreach my $thisdomain (sort(&Apache::lonnet::all_domains())) {
1.312 raeburn 2133: foreach my $role (@allroles) {
2134: next if ($role eq 'ad');
1.357 raeburn 2135: next if (($role eq 'au') && ($ccdomain ne $thisdomain));
1.218 raeburn 2136: if (&Apache::lonnet::allowed('c'.$role,$thisdomain)) {
2137: my $plrole=&Apache::lonnet::plaintext($role);
2138: my %lt=&Apache::lonlocal::texthash(
2139: 'ssd' => "Set Start Date",
2140: 'sed' => "Set End Date"
2141: );
2142: $num_domain_level ++;
2143: $domaintext .=
2144: &Apache::loncommon::start_data_table_row().
1.291 bisitz 2145: '<td><input type="checkbox" name="act_'.$thisdomain.'_'.$role.'" /></td>
1.218 raeburn 2146: <td>'.$plrole.'</td>
2147: <td>'.$thisdomain.'</td>
2148: <td><input type="hidden" name="start_'.$thisdomain.'_'.$role.'" value="" />
2149: <a href=
2150: "javascript:pjump('."'date_start','Start Date $plrole',document.cu.start_$thisdomain\_$role.value,'start_$thisdomain\_$role','cu.pres','dateset'".')">'.$lt{'ssd'}.'</a></td>
2151: <td><input type="hidden" name="end_'.$thisdomain.'_'.$role.'" value="" />
2152: <a href=
2153: "javascript:pjump('."'date_end','End Date $plrole',document.cu.end_$thisdomain\_$role.value,'end_$thisdomain\_$role','cu.pres','dateset'".')">'.$lt{'sed'}.'</a></td>'.
2154: &Apache::loncommon::end_data_table_row();
2155: }
2156: }
2157: }
2158: $domaintext.= &Apache::loncommon::end_data_table();
2159: if ($num_domain_level > 0) {
2160: $r->print($domaintext);
2161: $addrolesdisplay = 1;
2162: }
2163: return $addrolesdisplay;
2164: }
2165:
1.188 raeburn 2166: sub user_authentication {
1.227 raeburn 2167: my ($ccuname,$ccdomain,$formname) = @_;
1.188 raeburn 2168: my $currentauth=&Apache::lonnet::queryauthenticate($ccuname,$ccdomain);
1.227 raeburn 2169: my $outcome;
1.406.2.6 raeburn 2170: my %lt=&Apache::lonlocal::texthash(
2171: 'err' => "ERROR",
2172: 'uuas' => "This user has an unrecognized authentication scheme",
2173: 'adcs' => "Please alert a domain coordinator of this situation",
2174: 'sldb' => "Please specify login data below",
2175: 'ld' => "Login Data"
2176: );
1.188 raeburn 2177: # Check for a bad authentication type
2178: if ($currentauth !~ /^(krb4|krb5|unix|internal|localauth):/) {
2179: # bad authentication scheme
2180: if (&Apache::lonnet::allowed('mau',$ccdomain)) {
1.227 raeburn 2181: &initialize_authen_forms($ccdomain,$formname);
2182:
1.190 raeburn 2183: my $choices = &Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc);
1.188 raeburn 2184: $outcome = <<ENDBADAUTH;
2185: <script type="text/javascript" language="Javascript">
1.301 bisitz 2186: // <![CDATA[
1.188 raeburn 2187: $loginscript
1.301 bisitz 2188: // ]]>
1.188 raeburn 2189: </script>
2190: <span class="LC_error">$lt{'err'}:
2191: $lt{'uuas'} ($currentauth). $lt{'sldb'}.</span>
2192: <h3>$lt{'ld'}</h3>
2193: $choices
2194: ENDBADAUTH
2195: } else {
2196: # This user is not allowed to modify the user's
2197: # authentication scheme, so just notify them of the problem
2198: $outcome = <<ENDBADAUTH;
2199: <span class="LC_error"> $lt{'err'}:
2200: $lt{'uuas'} ($currentauth). $lt{'adcs'}.
2201: </span>
2202: ENDBADAUTH
2203: }
2204: } else { # Authentication type is valid
1.227 raeburn 2205: &initialize_authen_forms($ccdomain,$formname,$currentauth,'modifyuser');
1.205 raeburn 2206: my ($authformcurrent,$can_modify,@authform_others) =
1.188 raeburn 2207: &modify_login_block($ccdomain,$currentauth);
2208: if (&Apache::lonnet::allowed('mau',$ccdomain)) {
2209: # Current user has login modification privileges
2210: $outcome =
2211: '<script type="text/javascript" language="Javascript">'."\n".
1.301 bisitz 2212: '// <![CDATA['."\n".
1.188 raeburn 2213: $loginscript."\n".
1.301 bisitz 2214: '// ]]>'."\n".
1.188 raeburn 2215: '</script>'."\n".
2216: '<h3>'.$lt{'ld'}.'</h3>'.
2217: &Apache::loncommon::start_data_table().
1.205 raeburn 2218: &Apache::loncommon::start_data_table_row().
1.188 raeburn 2219: '<td>'.$authformnop;
1.406.2.6 raeburn 2220: if (($can_modify) && (&Apache::lonnet::allowed('mau',$ccdomain))) {
1.188 raeburn 2221: $outcome .= '</td>'."\n".
2222: &Apache::loncommon::end_data_table_row().
2223: &Apache::loncommon::start_data_table_row().
2224: '<td>'.$authformcurrent.'</td>'.
2225: &Apache::loncommon::end_data_table_row()."\n";
2226: } else {
1.200 raeburn 2227: $outcome .= ' ('.$authformcurrent.')</td>'.
2228: &Apache::loncommon::end_data_table_row()."\n";
1.188 raeburn 2229: }
1.406.2.6 raeburn 2230: if (&Apache::lonnet::allowed('mau',$ccdomain)) {
2231: foreach my $item (@authform_others) {
2232: $outcome .= &Apache::loncommon::start_data_table_row().
2233: '<td>'.$item.'</td>'.
2234: &Apache::loncommon::end_data_table_row()."\n";
2235: }
1.188 raeburn 2236: }
1.205 raeburn 2237: $outcome .= &Apache::loncommon::end_data_table();
1.188 raeburn 2238: } else {
1.406.2.6 raeburn 2239: if (&Apache::lonnet::allowed('udp',$ccdomain)) {
2240: # Current user has rights to view domain preferences for user's domain
2241: my $result;
2242: if ($currentauth =~ /^krb(4|5):([^:]*)$/) {
2243: my ($krbver,$krbrealm) = ($1,$2);
2244: if ($krbrealm eq '') {
2245: $result = &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
2246: } else {
2247: $result = &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
1.406.2.9 raeburn 2248: $krbrealm,$krbver);
1.406.2.6 raeburn 2249: }
2250: } elsif ($currentauth =~ /^internal:/) {
2251: $result = &mt('Currently internally authenticated.');
2252: } elsif ($currentauth =~ /^localauth:/) {
2253: $result = &mt('Currently using local (institutional) authentication.');
2254: } elsif ($currentauth =~ /^unix:/) {
2255: $result = &mt('Currently Filesystem Authenticated.');
2256: }
2257: $outcome = '<h3>'.$lt{'ld'}.'</h3>'.
2258: &Apache::loncommon::start_data_table().
2259: &Apache::loncommon::start_data_table_row().
2260: '<td>'.$result.'</td>'.
2261: &Apache::loncommon::end_data_table_row()."\n".
2262: &Apache::loncommon::end_data_table();
2263: } elsif (&Apache::lonnet::allowed('mau',$env{'request.role.domain'})) {
1.188 raeburn 2264: my %lt=&Apache::lonlocal::texthash(
2265: 'ccld' => "Change Current Login Data",
2266: 'yodo' => "You do not have privileges to modify the authentication configuration for this user.",
2267: 'ifch' => "If a change is required, contact a domain coordinator for the domain",
2268: );
2269: $outcome .= <<ENDNOPRIV;
2270: <h3>$lt{'ccld'}</h3>
2271: $lt{'yodo'} $lt{'ifch'}: $ccdomain
1.235 raeburn 2272: <input type="hidden" name="login" value="nochange" />
1.188 raeburn 2273: ENDNOPRIV
2274: }
2275: }
2276: } ## End of "check for bad authentication type" logic
2277: return $outcome;
2278: }
2279:
1.187 raeburn 2280: sub modify_login_block {
2281: my ($dom,$currentauth) = @_;
2282: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
2283: my ($authnum,%can_assign) =
2284: &Apache::loncommon::get_assignable_auth($dom);
1.205 raeburn 2285: my ($authformcurrent,@authform_others,$show_override_msg);
1.187 raeburn 2286: if ($currentauth=~/^krb(4|5):/) {
2287: $authformcurrent=$authformkrb;
2288: if ($can_assign{'int'}) {
1.205 raeburn 2289: push(@authform_others,$authformint);
1.187 raeburn 2290: }
2291: if ($can_assign{'loc'}) {
1.205 raeburn 2292: push(@authform_others,$authformloc);
1.187 raeburn 2293: }
2294: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
2295: $show_override_msg = 1;
2296: }
2297: } elsif ($currentauth=~/^internal:/) {
2298: $authformcurrent=$authformint;
2299: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205 raeburn 2300: push(@authform_others,$authformkrb);
1.187 raeburn 2301: }
2302: if ($can_assign{'loc'}) {
1.205 raeburn 2303: push(@authform_others,$authformloc);
1.187 raeburn 2304: }
2305: if ($can_assign{'int'}) {
2306: $show_override_msg = 1;
2307: }
2308: } elsif ($currentauth=~/^unix:/) {
2309: $authformcurrent=$authformfsys;
2310: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205 raeburn 2311: push(@authform_others,$authformkrb);
1.187 raeburn 2312: }
2313: if ($can_assign{'int'}) {
1.205 raeburn 2314: push(@authform_others,$authformint);
1.187 raeburn 2315: }
2316: if ($can_assign{'loc'}) {
1.205 raeburn 2317: push(@authform_others,$authformloc);
1.187 raeburn 2318: }
2319: if ($can_assign{'fsys'}) {
2320: $show_override_msg = 1;
2321: }
2322: } elsif ($currentauth=~/^localauth:/) {
2323: $authformcurrent=$authformloc;
2324: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205 raeburn 2325: push(@authform_others,$authformkrb);
1.187 raeburn 2326: }
2327: if ($can_assign{'int'}) {
1.205 raeburn 2328: push(@authform_others,$authformint);
1.187 raeburn 2329: }
2330: if ($can_assign{'loc'}) {
2331: $show_override_msg = 1;
2332: }
2333: }
2334: if ($show_override_msg) {
1.205 raeburn 2335: $authformcurrent = '<table><tr><td colspan="3">'.$authformcurrent.
2336: '</td></tr>'."\n".
2337: '<tr><td> </td>'.
2338: '<td><b>'.&mt('Currently in use').'</b></td>'.
2339: '<td align="right"><span class="LC_cusr_emph">'.
1.187 raeburn 2340: &mt('will override current values').
1.205 raeburn 2341: '</span></td></tr></table>';
1.187 raeburn 2342: }
1.205 raeburn 2343: return ($authformcurrent,$show_override_msg,@authform_others);
1.187 raeburn 2344: }
2345:
1.188 raeburn 2346: sub personal_data_display {
1.391 raeburn 2347: my ($ccuname,$ccdomain,$newuser,$context,$inst_results,$rolesarray,
1.406.2.16! raeburn 2348: $now,$captchaform,$emailusername,$usertype,$usernameset,$condition,$excluded) = @_;
1.388 bisitz 2349: my ($output,%userenv,%canmodify,%canmodify_status);
1.219 raeburn 2350: my @userinfo = ('firstname','middlename','lastname','generation',
2351: 'permanentemail','id');
1.252 raeburn 2352: my $rowcount = 0;
2353: my $editable = 0;
1.391 raeburn 2354: my %textboxsize = (
2355: firstname => '15',
2356: middlename => '15',
2357: lastname => '15',
2358: generation => '5',
2359: permanentemail => '25',
2360: id => '15',
2361: );
2362:
2363: my %lt=&Apache::lonlocal::texthash(
2364: 'pd' => "Personal Data",
2365: 'firstname' => "First Name",
2366: 'middlename' => "Middle Name",
2367: 'lastname' => "Last Name",
2368: 'generation' => "Generation",
2369: 'permanentemail' => "Permanent e-mail address",
2370: 'id' => "Student/Employee ID",
2371: 'lg' => "Login Data",
2372: 'inststatus' => "Affiliation",
2373: 'email' => 'E-mail address',
2374: 'valid' => 'Validation',
1.406.2.16! raeburn 2375: 'username' => 'Username',
1.391 raeburn 2376: );
2377:
2378: %canmodify_status =
1.286 raeburn 2379: &Apache::lonuserutils::can_modify_userinfo($context,$ccdomain,
2380: ['inststatus'],$rolesarray);
1.253 raeburn 2381: if (!$newuser) {
1.188 raeburn 2382: # Get the users information
2383: %userenv = &Apache::lonnet::get('environment',
2384: ['firstname','middlename','lastname','generation',
1.286 raeburn 2385: 'permanentemail','id','inststatus'],$ccdomain,$ccuname);
1.219 raeburn 2386: %canmodify =
2387: &Apache::lonuserutils::can_modify_userinfo($context,$ccdomain,
1.252 raeburn 2388: \@userinfo,$rolesarray);
1.257 raeburn 2389: } elsif ($context eq 'selfcreate') {
1.391 raeburn 2390: if ($newuser eq 'email') {
1.396 raeburn 2391: if (ref($emailusername) eq 'HASH') {
2392: if (ref($emailusername->{$usertype}) eq 'HASH') {
2393: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
1.406.2.16! raeburn 2394: @userinfo = ();
1.396 raeburn 2395: if ((ref($infofields) eq 'ARRAY') && (ref($infotitles) eq 'HASH')) {
2396: foreach my $field (@{$infofields}) {
2397: if ($emailusername->{$usertype}->{$field}) {
2398: push(@userinfo,$field);
2399: $canmodify{$field} = 1;
2400: unless ($textboxsize{$field}) {
2401: $textboxsize{$field} = 25;
2402: }
2403: unless ($lt{$field}) {
2404: $lt{$field} = $infotitles->{$field};
2405: }
2406: if ($emailusername->{$usertype}->{$field} eq 'required') {
2407: $lt{$field} .= '<b>*</b>';
2408: }
1.391 raeburn 2409: }
2410: }
2411: }
2412: }
2413: }
2414: } else {
2415: %canmodify = &selfcreate_canmodify($context,$ccdomain,\@userinfo,
2416: $inst_results,$rolesarray);
2417: }
1.188 raeburn 2418: }
1.391 raeburn 2419:
1.188 raeburn 2420: my $genhelp=&Apache::loncommon::help_open_topic('Generation');
2421: $output = '<h3>'.$lt{'pd'}.'</h3>'.
2422: &Apache::lonhtmlcommon::start_pick_box();
1.391 raeburn 2423: if (($context eq 'selfcreate') && ($newuser eq 'email')) {
1.406.2.16! raeburn 2424: my $size = 25;
! 2425: if ($condition) {
! 2426: if ($condition =~ /^\@[^\@]+$/) {
! 2427: $size = 10;
! 2428: } else {
! 2429: undef($condition);
! 2430: }
! 2431: }
! 2432: if ($excluded) {
! 2433: unless ($excluded =~ /^\@[^\@]+$/) {
! 2434: undef($condition);
! 2435: }
! 2436: }
1.396 raeburn 2437: $output .= &Apache::lonhtmlcommon::row_title($lt{'email'}.'<b>*</b>',undef,
1.391 raeburn 2438: 'LC_oddrow_value')."\n".
1.406.2.16! raeburn 2439: '<input type="text" name="uname" size="'.$size.'" value="" autocomplete="off" />';
! 2440: if ($condition) {
! 2441: $output .= $condition;
! 2442: } elsif ($excluded) {
! 2443: $output .= '<br /><span style="font-size: smaller">'.&mt('You must use an e-mail address that does not end with [_1]',
! 2444: $excluded).'</span>';
! 2445: }
! 2446: if ($usernameset eq 'first') {
! 2447: $output .= '<br /><span style="font-size: smaller">';
! 2448: if ($condition) {
! 2449: $output .= &mt('Your username in LON-CAPA will be the part of your e-mail address before [_1]',
! 2450: $condition);
! 2451: } else {
! 2452: $output .= &mt('Your username in LON-CAPA will be the part of your e-mail address before the @');
! 2453: }
! 2454: $output .= '</span>';
! 2455: }
1.391 raeburn 2456: $rowcount ++;
2457: $output .= &Apache::lonhtmlcommon::row_closure(1);
1.406.2.1 raeburn 2458: my $upassone = '<input type="password" name="upass'.$now.'" size="20" autocomplete="off" />';
2459: my $upasstwo = '<input type="password" name="upasscheck'.$now.'" size="20" autocomplete="off" />';
1.396 raeburn 2460: $output .= &Apache::lonhtmlcommon::row_title(&mt('Password').'<b>*</b>',
1.391 raeburn 2461: 'LC_pick_box_title',
2462: 'LC_oddrow_value')."\n".
2463: $upassone."\n".
2464: &Apache::lonhtmlcommon::row_closure(1)."\n".
1.396 raeburn 2465: &Apache::lonhtmlcommon::row_title(&mt('Confirm password').'<b>*</b>',
1.391 raeburn 2466: 'LC_pick_box_title',
2467: 'LC_oddrow_value')."\n".
2468: $upasstwo.
2469: &Apache::lonhtmlcommon::row_closure()."\n";
1.406.2.16! raeburn 2470: if ($usernameset eq 'free') {
! 2471: my $onclick = "toggleUsernameDisp(this,'selfcreateusername');";
! 2472: $output .= &Apache::lonhtmlcommon::row_title($lt{'username'},undef,'LC_oddrow_value')."\n".
! 2473: &mt('Use e-mail address: ').
! 2474: '<label><input type="radio" name="emailused" value="1" checked="checked" onclick="'.$onclick.'" />'.&mt('Yes').'</label>'."\n".
! 2475: (' 'x2).
! 2476: '<label><input type="radio" name="emailused" value="0" onclick="'.$onclick.'" />'.&mt('No').'</label>'."\n".
! 2477: '<div id="selfcreateusername" style="display: none; font-size: smaller">'.
! 2478: '<br /><span class="LC_nobreak">'.&mt('Preferred username').
! 2479: ' <input type="text" name="username" value="" size="20" autocomplete="off"/>'.
! 2480: '</span></div>'."\n".&Apache::lonhtmlcommon::row_closure(1);
! 2481: $rowcount ++;
! 2482: }
1.391 raeburn 2483: }
1.188 raeburn 2484: foreach my $item (@userinfo) {
2485: my $rowtitle = $lt{$item};
1.252 raeburn 2486: my $hiderow = 0;
1.188 raeburn 2487: if ($item eq 'generation') {
2488: $rowtitle = $genhelp.$rowtitle;
2489: }
1.252 raeburn 2490: my $row = &Apache::lonhtmlcommon::row_title($rowtitle,undef,'LC_oddrow_value')."\n";
1.188 raeburn 2491: if ($newuser) {
1.210 raeburn 2492: if (ref($inst_results) eq 'HASH') {
2493: if ($inst_results->{$item} ne '') {
1.252 raeburn 2494: $row .= '<input type="hidden" name="c'.$item.'" value="'.$inst_results->{$item}.'" />'.$inst_results->{$item};
1.210 raeburn 2495: } else {
1.252 raeburn 2496: if ($context eq 'selfcreate') {
1.391 raeburn 2497: if ($canmodify{$item}) {
1.394 raeburn 2498: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" autocomplete="off" />';
1.252 raeburn 2499: $editable ++;
2500: } else {
2501: $hiderow = 1;
2502: }
1.253 raeburn 2503: } else {
2504: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
1.252 raeburn 2505: }
1.210 raeburn 2506: }
1.188 raeburn 2507: } else {
1.252 raeburn 2508: if ($context eq 'selfcreate') {
1.401 raeburn 2509: if ($canmodify{$item}) {
2510: if ($newuser eq 'email') {
2511: $row .= '<input type="text" name="'.$item.'" size="'.$textboxsize{$item}.'" value="" autocomplete="off" />';
1.287 raeburn 2512: } else {
1.401 raeburn 2513: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" autocomplete="off" />';
1.287 raeburn 2514: }
1.401 raeburn 2515: $editable ++;
2516: } else {
2517: $hiderow = 1;
1.252 raeburn 2518: }
1.253 raeburn 2519: } else {
2520: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
1.252 raeburn 2521: }
1.188 raeburn 2522: }
2523: } else {
1.219 raeburn 2524: if ($canmodify{$item}) {
1.252 raeburn 2525: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="'.$userenv{$item}.'" />';
1.393 raeburn 2526: if (($item eq 'id') && (!$newuser)) {
2527: $row .= '<br />'.&Apache::lonuserutils::forceid_change($context);
2528: }
1.188 raeburn 2529: } else {
1.252 raeburn 2530: $row .= $userenv{$item};
1.188 raeburn 2531: }
2532: }
1.252 raeburn 2533: $row .= &Apache::lonhtmlcommon::row_closure(1);
2534: if (!$hiderow) {
2535: $output .= $row;
2536: $rowcount ++;
2537: }
1.188 raeburn 2538: }
1.286 raeburn 2539: if (($canmodify_status{'inststatus'}) || ($context ne 'selfcreate')) {
2540: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($ccdomain);
2541: if (ref($types) eq 'ARRAY') {
2542: if (@{$types} > 0) {
2543: my ($hiderow,$shown);
2544: if ($canmodify_status{'inststatus'}) {
2545: $shown = &pick_inst_statuses($userenv{'inststatus'},$usertypes,$types);
2546: } else {
2547: if ($userenv{'inststatus'} eq '') {
2548: $hiderow = 1;
1.334 raeburn 2549: } else {
2550: my @showitems;
2551: foreach my $item ( map { &unescape($_); } split(':',$userenv{'inststatus'})) {
2552: if (exists($usertypes->{$item})) {
2553: push(@showitems,$usertypes->{$item});
2554: } else {
2555: push(@showitems,$item);
2556: }
2557: }
2558: if (@showitems) {
2559: $shown = join(', ',@showitems);
2560: } else {
2561: $hiderow = 1;
2562: }
1.286 raeburn 2563: }
2564: }
2565: if (!$hiderow) {
1.389 bisitz 2566: my $row = &Apache::lonhtmlcommon::row_title(&mt('Affiliations'),undef,'LC_oddrow_value')."\n".
1.286 raeburn 2567: $shown.&Apache::lonhtmlcommon::row_closure(1);
2568: if ($context eq 'selfcreate') {
2569: $rowcount ++;
2570: }
2571: $output .= $row;
2572: }
2573: }
2574: }
2575: }
1.391 raeburn 2576: if (($context eq 'selfcreate') && ($newuser eq 'email')) {
2577: if ($captchaform) {
1.406.2.2 raeburn 2578: $output .= &Apache::lonhtmlcommon::row_title($lt{'valid'}.'*',
1.391 raeburn 2579: 'LC_pick_box_title')."\n".
2580: $captchaform."\n".'<br /><br />'.
2581: &Apache::lonhtmlcommon::row_closure(1);
2582: $rowcount ++;
2583: }
2584: my $submit_text = &mt('Create account');
2585: $output .= &Apache::lonhtmlcommon::row_title()."\n".
2586: '<br /><input type="submit" name="createaccount" value="'.
2587: $submit_text.'" />'.
1.396 raeburn 2588: '<input type="hidden" name="type" value="'.$usertype.'" />'.
1.391 raeburn 2589: &Apache::lonhtmlcommon::row_closure(1);
2590: }
1.188 raeburn 2591: $output .= &Apache::lonhtmlcommon::end_pick_box();
1.206 raeburn 2592: if (wantarray) {
1.252 raeburn 2593: if ($context eq 'selfcreate') {
2594: return($output,$rowcount,$editable);
2595: } else {
1.388 bisitz 2596: return $output;
1.252 raeburn 2597: }
1.206 raeburn 2598: } else {
2599: return $output;
2600: }
1.188 raeburn 2601: }
2602:
1.286 raeburn 2603: sub pick_inst_statuses {
2604: my ($curr,$usertypes,$types) = @_;
2605: my ($output,$rem,@currtypes);
2606: if ($curr ne '') {
2607: @currtypes = map { &unescape($_); } split(/:/,$curr);
2608: }
2609: my $numinrow = 2;
2610: if (ref($types) eq 'ARRAY') {
2611: $output = '<table>';
2612: my $lastcolspan;
2613: for (my $i=0; $i<@{$types}; $i++) {
2614: if (defined($usertypes->{$types->[$i]})) {
2615: my $rem = $i%($numinrow);
2616: if ($rem == 0) {
2617: if ($i<@{$types}-1) {
2618: if ($i > 0) {
2619: $output .= '</tr>';
2620: }
2621: $output .= '<tr>';
2622: }
2623: } elsif ($i==@{$types}-1) {
2624: my $colsleft = $numinrow - $rem;
2625: if ($colsleft > 1) {
2626: $lastcolspan = ' colspan="'.$colsleft.'"';
2627: }
2628: }
2629: my $check = ' ';
2630: if (grep(/^\Q$types->[$i]\E$/,@currtypes)) {
2631: $check = ' checked="checked" ';
2632: }
2633: $output .= '<td class="LC_left_item"'.$lastcolspan.'>'.
2634: '<span class="LC_nobreak"><label>'.
2635: '<input type="checkbox" name="inststatus" '.
2636: 'value="'.$types->[$i].'"'.$check.'/>'.
2637: $usertypes->{$types->[$i]}.'</label></span></td>';
2638: }
2639: }
2640: $output .= '</tr></table>';
2641: }
2642: return $output;
2643: }
2644:
1.257 raeburn 2645: sub selfcreate_canmodify {
2646: my ($context,$dom,$userinfo,$inst_results,$rolesarray) = @_;
2647: if (ref($inst_results) eq 'HASH') {
2648: my @inststatuses = &get_inststatuses($inst_results);
2649: if (@inststatuses == 0) {
2650: @inststatuses = ('default');
2651: }
2652: $rolesarray = \@inststatuses;
2653: }
2654: my %canmodify =
2655: &Apache::lonuserutils::can_modify_userinfo($context,$dom,$userinfo,
2656: $rolesarray);
2657: return %canmodify;
2658: }
2659:
1.252 raeburn 2660: sub get_inststatuses {
2661: my ($insthashref) = @_;
2662: my @inststatuses = ();
2663: if (ref($insthashref) eq 'HASH') {
2664: if (ref($insthashref->{'inststatus'}) eq 'ARRAY') {
2665: @inststatuses = @{$insthashref->{'inststatus'}};
2666: }
2667: }
2668: return @inststatuses;
2669: }
2670:
1.4 www 2671: # ================================================================= Phase Three
1.42 matthew 2672: sub update_user_data {
1.375 raeburn 2673: my ($r,$context,$crstype,$brcrum,$showcredits) = @_;
1.101 albertel 2674: my $uhome=&Apache::lonnet::homeserver($env{'form.ccuname'},
2675: $env{'form.ccdomain'});
1.27 matthew 2676: # Error messages
1.188 raeburn 2677: my $error = '<span class="LC_error">'.&mt('Error').': ';
1.193 raeburn 2678: my $end = '</span><br /><br />';
2679: my $rtnlink = '<a href="javascript:backPage(document.userupdate,'.
1.188 raeburn 2680: "'$env{'form.prevphase'}','modify')".'" />'.
1.219 raeburn 2681: &mt('Return to previous page').'</a>'.
2682: &Apache::loncommon::end_page();
2683: my $now = time;
1.40 www 2684: my $title;
1.101 albertel 2685: if (exists($env{'form.makeuser'})) {
1.40 www 2686: $title='Set Privileges for New User';
2687: } else {
2688: $title='Modify User Privileges';
2689: }
1.213 raeburn 2690: my $newuser = 0;
1.160 raeburn 2691: my ($jsback,$elements) = &crumb_utilities();
2692: my $jscript = '<script type="text/javascript">'."\n".
1.301 bisitz 2693: '// <![CDATA['."\n".
2694: $jsback."\n".
2695: '// ]]>'."\n".
2696: '</script>'."\n";
1.406.2.7 raeburn 2697: my %breadcrumb_text = &singleuser_breadcrumb($crstype,$context,$env{'form.ccdomain'});
1.351 raeburn 2698: push (@{$brcrum},
2699: {href => "javascript:backPage(document.userupdate)",
2700: text => $breadcrumb_text{'search'},
2701: faq => 282,
2702: bug => 'Instructor Interface',}
2703: );
2704: if ($env{'form.prevphase'} eq 'userpicked') {
2705: push(@{$brcrum},
2706: {href => "javascript:backPage(document.userupdate,'get_user_info','select')",
2707: text => $breadcrumb_text{'userpicked'},
2708: faq => 282,
2709: bug => 'Instructor Interface',});
1.233 raeburn 2710: }
1.224 raeburn 2711: my $helpitem = 'Course_Change_Privileges';
2712: if ($env{'form.action'} eq 'singlestudent') {
2713: $helpitem = 'Course_Add_Student';
1.406.2.14 raeburn 2714: } elsif ($context eq 'author') {
2715: $helpitem = 'Author_Change_Privileges';
2716: } elsif ($context eq 'domain') {
2717: $helpitem = 'Domain_Change_Privileges';
1.224 raeburn 2718: }
1.351 raeburn 2719: push(@{$brcrum},
2720: {href => "javascript:backPage(document.userupdate,'$env{'form.prevphase'}','modify')",
2721: text => $breadcrumb_text{'modify'},
2722: faq => 282,
2723: bug => 'Instructor Interface',},
2724: {href => "/adm/createuser",
2725: text => "Result",
2726: faq => 282,
2727: bug => 'Instructor Interface',
2728: help => $helpitem});
2729: my $args = {bread_crumbs => $brcrum,
2730: bread_crumbs_component => 'User Management'};
2731: if ($env{'form.popup'}) {
2732: $args->{'no_nav_bar'} = 1;
2733: }
2734: $r->print(&Apache::loncommon::start_page($title,$jscript,$args));
1.188 raeburn 2735: $r->print(&update_result_form($uhome));
1.27 matthew 2736: # Check Inputs
1.101 albertel 2737: if (! $env{'form.ccuname'} ) {
1.193 raeburn 2738: $r->print($error.&mt('No login name specified').'.'.$end.$rtnlink);
1.27 matthew 2739: return;
2740: }
1.138 albertel 2741: if ( $env{'form.ccuname'} ne
2742: &LONCAPA::clean_username($env{'form.ccuname'}) ) {
1.281 bisitz 2743: $r->print($error.&mt('Invalid login name.').' '.
2744: &mt('Only letters, numbers, periods, dashes, @, and underscores are valid.').
1.193 raeburn 2745: $end.$rtnlink);
1.27 matthew 2746: return;
2747: }
1.101 albertel 2748: if (! $env{'form.ccdomain'} ) {
1.193 raeburn 2749: $r->print($error.&mt('No domain specified').'.'.$end.$rtnlink);
1.27 matthew 2750: return;
2751: }
1.138 albertel 2752: if ( $env{'form.ccdomain'} ne
2753: &LONCAPA::clean_domain($env{'form.ccdomain'}) ) {
1.281 bisitz 2754: $r->print($error.&mt('Invalid domain name.').' '.
2755: &mt('Only letters, numbers, periods, dashes, and underscores are valid.').
1.193 raeburn 2756: $end.$rtnlink);
1.27 matthew 2757: return;
2758: }
1.219 raeburn 2759: if ($uhome eq 'no_host') {
2760: $newuser = 1;
2761: }
1.101 albertel 2762: if (! exists($env{'form.makeuser'})) {
1.29 matthew 2763: # Modifying an existing user, so check the validity of the name
2764: if ($uhome eq 'no_host') {
1.389 bisitz 2765: $r->print(
2766: $error
2767: .'<p class="LC_error">'
2768: .&mt('Unable to determine home server for [_1] in domain [_2].',
2769: '"'.$env{'form.ccuname'}.'"','"'.$env{'form.ccdomain'}.'"')
2770: .'</p>');
1.29 matthew 2771: return;
2772: }
2773: }
1.27 matthew 2774: # Determine authentication method and password for the user being modified
2775: my $amode='';
2776: my $genpwd='';
1.101 albertel 2777: if ($env{'form.login'} eq 'krb') {
1.41 albertel 2778: $amode='krb';
1.101 albertel 2779: $amode.=$env{'form.krbver'};
2780: $genpwd=$env{'form.krbarg'};
2781: } elsif ($env{'form.login'} eq 'int') {
1.27 matthew 2782: $amode='internal';
1.101 albertel 2783: $genpwd=$env{'form.intarg'};
2784: } elsif ($env{'form.login'} eq 'fsys') {
1.27 matthew 2785: $amode='unix';
1.101 albertel 2786: $genpwd=$env{'form.fsysarg'};
2787: } elsif ($env{'form.login'} eq 'loc') {
1.27 matthew 2788: $amode='localauth';
1.101 albertel 2789: $genpwd=$env{'form.locarg'};
1.27 matthew 2790: $genpwd=" " if (!$genpwd);
1.101 albertel 2791: } elsif (($env{'form.login'} eq 'nochange') ||
2792: ($env{'form.login'} eq '' )) {
1.34 matthew 2793: # There is no need to tell the user we did not change what they
2794: # did not ask us to change.
1.35 matthew 2795: # If they are creating a new user but have not specified login
2796: # information this will be caught below.
1.30 matthew 2797: } else {
1.367 golterma 2798: $r->print($error.&mt('Invalid login mode or password').$end.$rtnlink);
2799: return;
1.27 matthew 2800: }
1.164 albertel 2801:
1.188 raeburn 2802: $r->print('<h3>'.&mt('User [_1] in domain [_2]',
1.367 golterma 2803: $env{'form.ccuname'}.' ('.&Apache::loncommon::plainname($env{'form.ccuname'},
2804: $env{'form.ccdomain'}).')', $env{'form.ccdomain'}).'</h3>');
2805: my %prog_state = &Apache::lonhtmlcommon::Create_PrgWin($r,2);
1.344 bisitz 2806:
1.193 raeburn 2807: my (%alerts,%rulematch,%inst_results,%curr_rules);
1.334 raeburn 2808: my @userinfo = ('firstname','middlename','lastname','generation','permanentemail','id');
1.361 raeburn 2809: my @usertools = ('aboutme','blog','webdav','portfolio');
1.384 raeburn 2810: my @requestcourses = ('official','unofficial','community','textbook');
1.362 raeburn 2811: my @requestauthor = ('requestauthor');
1.286 raeburn 2812: my ($othertitle,$usertypes,$types) =
2813: &Apache::loncommon::sorted_inst_types($env{'form.ccdomain'});
1.334 raeburn 2814: my %canmodify_status =
2815: &Apache::lonuserutils::can_modify_userinfo($context,$env{'form.ccdomain'},
2816: ['inststatus']);
1.101 albertel 2817: if ($env{'form.makeuser'}) {
1.164 albertel 2818: $r->print('<h3>'.&mt('Creating new account.').'</h3>');
1.27 matthew 2819: # Check for the authentication mode and password
2820: if (! $amode || ! $genpwd) {
1.193 raeburn 2821: $r->print($error.&mt('Invalid login mode or password').$end.$rtnlink);
1.27 matthew 2822: return;
1.18 albertel 2823: }
1.29 matthew 2824: # Determine desired host
1.101 albertel 2825: my $desiredhost = $env{'form.hserver'};
1.29 matthew 2826: if (lc($desiredhost) eq 'default') {
2827: $desiredhost = undef;
2828: } else {
1.147 albertel 2829: my %home_servers =
2830: &Apache::lonnet::get_servers($env{'form.ccdomain'},'library');
1.29 matthew 2831: if (! exists($home_servers{$desiredhost})) {
1.193 raeburn 2832: $r->print($error.&mt('Invalid home server specified').$end.$rtnlink);
2833: return;
2834: }
2835: }
2836: # Check ID format
2837: my %checkhash;
2838: my %checks = ('id' => 1);
2839: %{$checkhash{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}}} = (
1.219 raeburn 2840: 'newuser' => $newuser,
1.196 raeburn 2841: 'id' => $env{'form.cid'},
1.193 raeburn 2842: );
1.196 raeburn 2843: if ($env{'form.cid'} ne '') {
2844: &Apache::loncommon::user_rule_check(\%checkhash,\%checks,\%alerts,
2845: \%rulematch,\%inst_results,\%curr_rules);
2846: if (ref($alerts{'id'}) eq 'HASH') {
2847: if (ref($alerts{'id'}{$env{'form.ccdomain'}}) eq 'HASH') {
2848: my $domdesc =
2849: &Apache::lonnet::domain($env{'form.ccdomain'},'description');
2850: if ($alerts{'id'}{$env{'form.ccdomain'}}{$env{'form.cid'}}) {
2851: my $userchkmsg;
2852: if (ref($curr_rules{$env{'form.ccdomain'}}) eq 'HASH') {
2853: $userchkmsg =
2854: &Apache::loncommon::instrule_disallow_msg('id',
2855: $domdesc,1).
2856: &Apache::loncommon::user_rule_formats($env{'form.ccdomain'},
2857: $domdesc,$curr_rules{$env{'form.ccdomain'}}{'id'},'id');
2858: }
2859: $r->print($error.&mt('Invalid ID format').$end.
2860: $userchkmsg.$rtnlink);
2861: return;
2862: }
2863: }
1.29 matthew 2864: }
2865: }
1.367 golterma 2866: &Apache::lonhtmlcommon::Increment_PrgWin($r, \%prog_state);
1.27 matthew 2867: # Call modifyuser
2868: my $result = &Apache::lonnet::modifyuser
1.193 raeburn 2869: ($env{'form.ccdomain'},$env{'form.ccuname'},$env{'form.cid'},
1.188 raeburn 2870: $amode,$genpwd,$env{'form.cfirstname'},
2871: $env{'form.cmiddlename'},$env{'form.clastname'},
2872: $env{'form.cgeneration'},undef,$desiredhost,
2873: $env{'form.cpermanentemail'});
1.77 www 2874: $r->print(&mt('Generating user').': '.$result);
1.219 raeburn 2875: $uhome = &Apache::lonnet::homeserver($env{'form.ccuname'},
1.101 albertel 2876: $env{'form.ccdomain'});
1.334 raeburn 2877: my (%changeHash,%newcustom,%changed,%changedinfo);
1.267 raeburn 2878: if ($uhome ne 'no_host') {
1.334 raeburn 2879: if ($context eq 'domain') {
1.378 raeburn 2880: foreach my $name ('portfolio','author') {
2881: if ($env{'form.custom_'.$name.'quota'} == 1) {
2882: if ($env{'form.'.$name.'quota'} eq '') {
2883: $newcustom{$name.'quota'} = 0;
2884: } else {
2885: $newcustom{$name.'quota'} = $env{'form.'.$name.'quota'};
2886: $newcustom{$name.'quota'} =~ s/[^\d\.]//g;
2887: }
2888: if ("a_admin($newcustom{$name.'quota'},\%changeHash,$name)) {
2889: $changed{$name.'quota'} = 1;
2890: }
1.334 raeburn 2891: }
2892: }
2893: foreach my $item (@usertools) {
2894: if ($env{'form.custom'.$item} == 1) {
2895: $newcustom{$item} = $env{'form.tools_'.$item};
2896: $changed{$item} = &tool_admin($item,$newcustom{$item},
2897: \%changeHash,'tools');
2898: }
1.267 raeburn 2899: }
1.334 raeburn 2900: foreach my $item (@requestcourses) {
1.341 raeburn 2901: if ($env{'form.custom'.$item} == 1) {
2902: $newcustom{$item} = $env{'form.crsreq_'.$item};
2903: if ($env{'form.crsreq_'.$item} eq 'autolimit') {
2904: $newcustom{$item} .= '=';
1.383 raeburn 2905: $env{'form.crsreq_'.$item.'_limit'} =~ s/\D+//g;
2906: if ($env{'form.crsreq_'.$item.'_limit'}) {
1.341 raeburn 2907: $newcustom{$item} .= $env{'form.crsreq_'.$item.'_limit'};
2908: }
1.334 raeburn 2909: }
1.341 raeburn 2910: $changed{$item} = &tool_admin($item,$newcustom{$item},
2911: \%changeHash,'requestcourses');
1.334 raeburn 2912: }
1.275 raeburn 2913: }
1.362 raeburn 2914: if ($env{'form.customrequestauthor'} == 1) {
2915: $newcustom{'requestauthor'} = $env{'form.requestauthor'};
2916: $changed{'requestauthor'} = &tool_admin('requestauthor',
2917: $newcustom{'requestauthor'},
2918: \%changeHash,'requestauthor');
2919: }
1.275 raeburn 2920: }
1.334 raeburn 2921: if ($canmodify_status{'inststatus'}) {
2922: if (exists($env{'form.inststatus'})) {
2923: my @inststatuses = &Apache::loncommon::get_env_multiple('form.inststatus');
2924: if (@inststatuses > 0) {
2925: $changeHash{'inststatus'} = join(',',@inststatuses);
2926: $changed{'inststatus'} = $changeHash{'inststatus'};
1.306 raeburn 2927: }
2928: }
1.232 raeburn 2929: }
1.334 raeburn 2930: if (keys(%changed)) {
2931: foreach my $item (@userinfo) {
2932: $changeHash{$item} = $env{'form.c'.$item};
1.286 raeburn 2933: }
1.267 raeburn 2934: my $chgresult =
2935: &Apache::lonnet::put('environment',\%changeHash,
2936: $env{'form.ccdomain'},$env{'form.ccuname'});
2937: }
1.232 raeburn 2938: }
1.219 raeburn 2939: $r->print('<br />'.&mt('Home server').': '.$uhome.' '.
2940: &Apache::lonnet::hostname($uhome));
1.101 albertel 2941: } elsif (($env{'form.login'} ne 'nochange') &&
2942: ($env{'form.login'} ne '' )) {
1.27 matthew 2943: # Modify user privileges
2944: if (! $amode || ! $genpwd) {
1.193 raeburn 2945: $r->print($error.'Invalid login mode or password'.$end.$rtnlink);
1.27 matthew 2946: return;
1.20 harris41 2947: }
1.395 bisitz 2948: # Only allow authentication modification if the person has authority
1.101 albertel 2949: if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'})) {
1.20 harris41 2950: $r->print('Modifying authentication: '.
1.31 matthew 2951: &Apache::lonnet::modifyuserauth(
1.101 albertel 2952: $env{'form.ccdomain'},$env{'form.ccuname'},
1.21 harris41 2953: $amode,$genpwd));
1.102 albertel 2954: $r->print('<br />'.&mt('Home server').': '.&Apache::lonnet::homeserver
1.101 albertel 2955: ($env{'form.ccuname'},$env{'form.ccdomain'}));
1.4 www 2956: } else {
1.27 matthew 2957: # Okay, this is a non-fatal error.
1.395 bisitz 2958: $r->print($error.&mt('You do not have the authority to modify this users authentication information.').$end);
1.27 matthew 2959: }
1.28 matthew 2960: }
1.344 bisitz 2961: $r->rflush(); # Finish display of header before time consuming actions start
1.367 golterma 2962: &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state);
1.28 matthew 2963: ##
1.375 raeburn 2964: my (@userroles,%userupdate,$cnum,$cdom,$defaultcredits,%namechanged);
1.213 raeburn 2965: if ($context eq 'course') {
1.375 raeburn 2966: ($cnum,$cdom) =
2967: &Apache::lonuserutils::get_course_identity();
1.318 raeburn 2968: $crstype = &Apache::loncommon::course_type($cdom.'_'.$cnum);
1.375 raeburn 2969: if ($showcredits) {
2970: $defaultcredits = &Apache::lonuserutils::get_defaultcredits($cdom,$cnum);
2971: }
1.213 raeburn 2972: }
1.101 albertel 2973: if (! $env{'form.makeuser'} ) {
1.28 matthew 2974: # Check for need to change
2975: my %userenv = &Apache::lonnet::get
1.134 raeburn 2976: ('environment',['firstname','middlename','lastname','generation',
1.378 raeburn 2977: 'id','permanentemail','portfolioquota','authorquota','inststatus',
2978: 'tools.aboutme','tools.blog','tools.webdav','tools.portfolio',
1.361 raeburn 2979: 'requestcourses.official','requestcourses.unofficial',
1.384 raeburn 2980: 'requestcourses.community','requestcourses.textbook',
2981: 'reqcrsotherdom.official','reqcrsotherdom.unofficial',
2982: 'reqcrsotherdom.community','reqcrsotherdom.textbook',
1.406.2.9 raeburn 2983: 'requestauthor'],
1.160 raeburn 2984: $env{'form.ccdomain'},$env{'form.ccuname'});
1.28 matthew 2985: my ($tmp) = keys(%userenv);
2986: if ($tmp =~ /^(con_lost|error)/i) {
2987: %userenv = ();
2988: }
1.206 raeburn 2989: my $no_forceid_alert;
2990: # Check to see if user information can be changed
2991: my %domconfig =
2992: &Apache::lonnet::get_dom('configuration',['usermodification'],
2993: $env{'form.ccdomain'});
1.213 raeburn 2994: my @statuses = ('active','future');
2995: my %roles = &Apache::lonnet::get_my_roles($env{'form.ccuname'},$env{'form.ccdomain'},'userroles',\@statuses,undef,$env{'request.role.domain'});
2996: my ($auname,$audom);
1.220 raeburn 2997: if ($context eq 'author') {
1.206 raeburn 2998: $auname = $env{'user.name'};
2999: $audom = $env{'user.domain'};
3000: }
3001: foreach my $item (keys(%roles)) {
1.220 raeburn 3002: my ($rolenum,$roledom,$role) = split(/:/,$item,-1);
1.206 raeburn 3003: if ($context eq 'course') {
3004: if ($cnum ne '' && $cdom ne '') {
3005: if ($rolenum eq $cnum && $roledom eq $cdom) {
3006: if (!grep(/^\Q$role\E$/,@userroles)) {
3007: push(@userroles,$role);
3008: }
3009: }
3010: }
3011: } elsif ($context eq 'author') {
3012: if ($rolenum eq $auname && $roledom eq $audom) {
3013: if (!grep(/^\Q$role\E$/,@userroles)) {
3014: push(@userroles,$role);
3015: }
3016: }
3017: }
3018: }
1.220 raeburn 3019: if ($env{'form.action'} eq 'singlestudent') {
3020: if (!grep(/^st$/,@userroles)) {
3021: push(@userroles,'st');
3022: }
3023: } else {
3024: # Check for course or co-author roles being activated or re-enabled
3025: if ($context eq 'author' || $context eq 'course') {
3026: foreach my $key (keys(%env)) {
3027: if ($context eq 'author') {
3028: if ($key=~/^form\.act_\Q$audom\E_\Q$auname\E_([^_]+)/) {
3029: if (!grep(/^\Q$1\E$/,@userroles)) {
3030: push(@userroles,$1);
3031: }
3032: } elsif ($key =~/^form\.ren\:\Q$audom\E\/\Q$auname\E_([^_]+)/) {
3033: if (!grep(/^\Q$1\E$/,@userroles)) {
3034: push(@userroles,$1);
3035: }
1.206 raeburn 3036: }
1.220 raeburn 3037: } elsif ($context eq 'course') {
3038: if ($key=~/^form\.act_\Q$cdom\E_\Q$cnum\E_([^_]+)/) {
3039: if (!grep(/^\Q$1\E$/,@userroles)) {
3040: push(@userroles,$1);
3041: }
3042: } elsif ($key =~/^form\.ren\:\Q$cdom\E\/\Q$cnum\E(\/?\w*)_([^_]+)/) {
3043: if (!grep(/^\Q$1\E$/,@userroles)) {
3044: push(@userroles,$1);
3045: }
1.206 raeburn 3046: }
3047: }
3048: }
3049: }
3050: }
3051: #Check to see if we can change personal data for the user
3052: my (@mod_disallowed,@longroles);
3053: foreach my $role (@userroles) {
3054: if ($role eq 'cr') {
3055: push(@longroles,'Custom');
3056: } else {
1.318 raeburn 3057: push(@longroles,&Apache::lonnet::plaintext($role,$crstype));
1.206 raeburn 3058: }
3059: }
1.219 raeburn 3060: my %canmodify = &Apache::lonuserutils::can_modify_userinfo($context,$env{'form.ccdomain'},\@userinfo,\@userroles);
3061: foreach my $item (@userinfo) {
1.28 matthew 3062: # Strip leading and trailing whitespace
1.203 raeburn 3063: $env{'form.c'.$item} =~ s/(\s+$|^\s+)//g;
1.219 raeburn 3064: if (!$canmodify{$item}) {
1.207 raeburn 3065: if (defined($env{'form.c'.$item})) {
3066: if ($env{'form.c'.$item} ne $userenv{$item}) {
3067: push(@mod_disallowed,$item);
3068: }
1.206 raeburn 3069: }
3070: $env{'form.c'.$item} = $userenv{$item};
3071: }
1.28 matthew 3072: }
1.259 bisitz 3073: # Check to see if we can change the Student/Employee ID
1.196 raeburn 3074: my $forceid = $env{'form.forceid'};
3075: my $recurseid = $env{'form.recurseid'};
3076: my (%alerts,%rulematch,%idinst_results,%curr_rules,%got_rules);
1.203 raeburn 3077: my %uidhash = &Apache::lonnet::idrget($env{'form.ccdomain'},
3078: $env{'form.ccuname'});
3079: if (($uidhash{$env{'form.ccuname'}}) &&
3080: ($uidhash{$env{'form.ccuname'}}!~/error\:/) &&
3081: (!$forceid)) {
3082: if ($env{'form.cid'} ne $uidhash{$env{'form.ccuname'}}) {
3083: $env{'form.cid'} = $userenv{'id'};
1.293 bisitz 3084: $no_forceid_alert = &mt('New student/employee ID does not match existing ID for this user.')
1.259 bisitz 3085: .'<br />'
3086: .&mt("Change is not permitted without checking the 'Force ID change' checkbox on the previous page.")
3087: .'<br />'."\n";
1.203 raeburn 3088: }
3089: }
3090: if ($env{'form.cid'} ne $userenv{'id'}) {
1.196 raeburn 3091: my $checkhash;
3092: my $checks = { 'id' => 1 };
3093: $checkhash->{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}} =
3094: { 'newuser' => $newuser,
3095: 'id' => $env{'form.cid'},
3096: };
3097: &Apache::loncommon::user_rule_check($checkhash,$checks,
3098: \%alerts,\%rulematch,\%idinst_results,\%curr_rules,\%got_rules);
3099: if (ref($alerts{'id'}) eq 'HASH') {
3100: if (ref($alerts{'id'}{$env{'form.ccdomain'}}) eq 'HASH') {
1.203 raeburn 3101: $env{'form.cid'} = $userenv{'id'};
1.196 raeburn 3102: }
3103: }
3104: }
1.378 raeburn 3105: my (%quotachanged,%oldquota,%newquota,%olddefquota,%newdefquota,
3106: $oldinststatus,$newinststatus,%oldisdefault,%newisdefault,%oldsettings,
1.339 raeburn 3107: %oldsettingstext,%newsettings,%newsettingstext,@disporder,
1.378 raeburn 3108: %oldsettingstatus,%newsettingstatus);
1.334 raeburn 3109: @disporder = ('inststatus');
3110: if ($env{'request.role.domain'} eq $env{'form.ccdomain'}) {
1.362 raeburn 3111: push(@disporder,'requestcourses','requestauthor');
1.334 raeburn 3112: } else {
3113: push(@disporder,'reqcrsotherdom');
3114: }
3115: push(@disporder,('quota','tools'));
1.338 raeburn 3116: $oldinststatus = $userenv{'inststatus'};
1.378 raeburn 3117: foreach my $name ('portfolio','author') {
3118: ($olddefquota{$name},$oldsettingstatus{$name}) =
3119: &Apache::loncommon::default_quota($env{'form.ccdomain'},$oldinststatus,$name);
3120: ($newdefquota{$name},$newsettingstatus{$name}) = ($olddefquota{$name},$oldsettingstatus{$name});
3121: }
1.334 raeburn 3122: my %canshow;
1.220 raeburn 3123: if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
1.334 raeburn 3124: $canshow{'quota'} = 1;
1.220 raeburn 3125: }
1.267 raeburn 3126: if (&Apache::lonnet::allowed('mut',$env{'form.ccdomain'})) {
1.334 raeburn 3127: $canshow{'tools'} = 1;
1.267 raeburn 3128: }
1.275 raeburn 3129: if (&Apache::lonnet::allowed('ccc',$env{'form.ccdomain'})) {
1.334 raeburn 3130: $canshow{'requestcourses'} = 1;
1.300 raeburn 3131: } elsif (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
1.334 raeburn 3132: $canshow{'reqcrsotherdom'} = 1;
1.275 raeburn 3133: }
1.286 raeburn 3134: if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'})) {
1.334 raeburn 3135: $canshow{'inststatus'} = 1;
1.286 raeburn 3136: }
1.362 raeburn 3137: if (&Apache::lonnet::allowed('cau',$env{'form.ccdomain'})) {
3138: $canshow{'requestauthor'} = 1;
3139: }
1.267 raeburn 3140: my (%changeHash,%changed);
1.286 raeburn 3141: if ($oldinststatus eq '') {
1.334 raeburn 3142: $oldsettings{'inststatus'} = $othertitle;
1.286 raeburn 3143: } else {
3144: if (ref($usertypes) eq 'HASH') {
1.334 raeburn 3145: $oldsettings{'inststatus'} = join(', ',map{ $usertypes->{ &unescape($_) }; } (split(/:/,$userenv{'inststatus'})));
1.286 raeburn 3146: } else {
1.334 raeburn 3147: $oldsettings{'inststatus'} = join(', ',map{ &unescape($_); } (split(/:/,$userenv{'inststatus'})));
1.286 raeburn 3148: }
3149: }
3150: $changeHash{'inststatus'} = $userenv{'inststatus'};
1.334 raeburn 3151: if ($canmodify_status{'inststatus'}) {
3152: $canshow{'inststatus'} = 1;
1.286 raeburn 3153: if (exists($env{'form.inststatus'})) {
3154: my @inststatuses = &Apache::loncommon::get_env_multiple('form.inststatus');
3155: if (@inststatuses > 0) {
3156: $newinststatus = join(':',map { &escape($_); } @inststatuses);
3157: $changeHash{'inststatus'} = $newinststatus;
3158: if ($newinststatus ne $oldinststatus) {
3159: $changed{'inststatus'} = $newinststatus;
1.378 raeburn 3160: foreach my $name ('portfolio','author') {
3161: ($newdefquota{$name},$newsettingstatus{$name}) =
3162: &Apache::loncommon::default_quota($env{'form.ccdomain'},$newinststatus,$name);
3163: }
1.286 raeburn 3164: }
3165: if (ref($usertypes) eq 'HASH') {
1.334 raeburn 3166: $newsettings{'inststatus'} = join(', ',map{ $usertypes->{$_}; } (@inststatuses));
1.286 raeburn 3167: } else {
1.337 raeburn 3168: $newsettings{'inststatus'} = join(', ',@inststatuses);
1.286 raeburn 3169: }
1.334 raeburn 3170: }
3171: } else {
3172: $newinststatus = '';
3173: $changeHash{'inststatus'} = $newinststatus;
3174: $newsettings{'inststatus'} = $othertitle;
3175: if ($newinststatus ne $oldinststatus) {
3176: $changed{'inststatus'} = $changeHash{'inststatus'};
1.378 raeburn 3177: foreach my $name ('portfolio','author') {
3178: ($newdefquota{$name},$newsettingstatus{$name}) =
3179: &Apache::loncommon::default_quota($env{'form.ccdomain'},$newinststatus,$name);
3180: }
1.286 raeburn 3181: }
3182: }
1.334 raeburn 3183: } elsif ($context ne 'selfcreate') {
3184: $canshow{'inststatus'} = 1;
1.337 raeburn 3185: $newsettings{'inststatus'} = $oldsettings{'inststatus'};
1.286 raeburn 3186: }
1.378 raeburn 3187: foreach my $name ('portfolio','author') {
3188: $changeHash{$name.'quota'} = $userenv{$name.'quota'};
3189: }
1.334 raeburn 3190: if ($context eq 'domain') {
1.378 raeburn 3191: foreach my $name ('portfolio','author') {
3192: if ($userenv{$name.'quota'} ne '') {
3193: $oldquota{$name} = $userenv{$name.'quota'};
3194: if ($env{'form.custom_'.$name.'quota'} == 1) {
3195: if ($env{'form.'.$name.'quota'} eq '') {
3196: $newquota{$name} = 0;
3197: } else {
3198: $newquota{$name} = $env{'form.'.$name.'quota'};
3199: $newquota{$name} =~ s/[^\d\.]//g;
3200: }
3201: if ($newquota{$name} != $oldquota{$name}) {
3202: if ("a_admin($newquota{$name},\%changeHash,$name)) {
3203: $changed{$name.'quota'} = 1;
3204: }
3205: }
1.334 raeburn 3206: } else {
1.378 raeburn 3207: if ("a_admin('',\%changeHash,$name)) {
3208: $changed{$name.'quota'} = 1;
3209: $newquota{$name} = $newdefquota{$name};
3210: $newisdefault{$name} = 1;
3211: }
1.334 raeburn 3212: }
1.149 raeburn 3213: } else {
1.378 raeburn 3214: $oldisdefault{$name} = 1;
3215: $oldquota{$name} = $olddefquota{$name};
3216: if ($env{'form.custom_'.$name.'quota'} == 1) {
3217: if ($env{'form.'.$name.'quota'} eq '') {
3218: $newquota{$name} = 0;
3219: } else {
3220: $newquota{$name} = $env{'form.'.$name.'quota'};
3221: $newquota{$name} =~ s/[^\d\.]//g;
3222: }
3223: if ("a_admin($newquota{$name},\%changeHash,$name)) {
3224: $changed{$name.'quota'} = 1;
3225: }
1.334 raeburn 3226: } else {
1.378 raeburn 3227: $newquota{$name} = $newdefquota{$name};
3228: $newisdefault{$name} = 1;
1.334 raeburn 3229: }
1.378 raeburn 3230: }
3231: if ($oldisdefault{$name}) {
3232: $oldsettingstext{'quota'}{$name} = &get_defaultquota_text($oldsettingstatus{$name});
1.383 raeburn 3233: } else {
3234: $oldsettingstext{'quota'}{$name} = &mt('custom quota: [_1] MB',$oldquota{$name});
1.378 raeburn 3235: }
3236: if ($newisdefault{$name}) {
3237: $newsettingstext{'quota'}{$name} = &get_defaultquota_text($newsettingstatus{$name});
1.383 raeburn 3238: } else {
3239: $newsettingstext{'quota'}{$name} = &mt('custom quota: [_1] MB',$newquota{$name});
1.134 raeburn 3240: }
3241: }
1.334 raeburn 3242: &tool_changes('tools',\@usertools,\%oldsettings,\%oldsettingstext,\%userenv,
3243: \%changeHash,\%changed,\%newsettings,\%newsettingstext);
3244: if ($env{'form.ccdomain'} eq $env{'request.role.domain'}) {
3245: &tool_changes('requestcourses',\@requestcourses,\%oldsettings,\%oldsettingstext,
3246: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
1.384 raeburn 3247: &tool_changes('requestauthor',\@requestauthor,\%oldsettings,\%oldsettingstext,
3248: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
1.149 raeburn 3249: } else {
1.334 raeburn 3250: &tool_changes('reqcrsotherdom',\@requestcourses,\%oldsettings,\%oldsettingstext,
3251: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
1.149 raeburn 3252: }
3253: }
1.334 raeburn 3254: foreach my $item (@userinfo) {
3255: if ($env{'form.c'.$item} ne $userenv{$item}) {
3256: $namechanged{$item} = 1;
3257: }
1.204 raeburn 3258: }
1.378 raeburn 3259: foreach my $name ('portfolio','author') {
1.390 bisitz 3260: $oldsettings{'quota'}{$name} = &mt('[_1] MB',$oldquota{$name});
3261: $newsettings{'quota'}{$name} = &mt('[_1] MB',$newquota{$name});
1.378 raeburn 3262: }
1.334 raeburn 3263: if ((keys(%namechanged) > 0) || (keys(%changed) > 0)) {
1.267 raeburn 3264: my ($chgresult,$namechgresult);
3265: if (keys(%changed) > 0) {
3266: $chgresult =
1.204 raeburn 3267: &Apache::lonnet::put('environment',\%changeHash,
3268: $env{'form.ccdomain'},$env{'form.ccuname'});
1.267 raeburn 3269: if ($chgresult eq 'ok') {
3270: if (($env{'user.name'} eq $env{'form.ccuname'}) &&
3271: ($env{'user.domain'} eq $env{'form.ccdomain'})) {
1.270 raeburn 3272: my %newenvhash;
3273: foreach my $key (keys(%changed)) {
1.299 raeburn 3274: if (($key eq 'official') || ($key eq 'unofficial')
1.403 raeburn 3275: || ($key eq 'community') || ($key eq 'textbook')) {
1.279 raeburn 3276: $newenvhash{'environment.requestcourses.'.$key} =
3277: $changeHash{'requestcourses.'.$key};
1.362 raeburn 3278: if ($changeHash{'requestcourses.'.$key}) {
1.332 raeburn 3279: $newenvhash{'environment.canrequest.'.$key} = 1;
1.279 raeburn 3280: } else {
3281: $newenvhash{'environment.canrequest.'.$key} =
3282: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
3283: $key,'reload','requestcourses');
3284: }
1.362 raeburn 3285: } elsif ($key eq 'requestauthor') {
3286: $newenvhash{'environment.'.$key} = $changeHash{$key};
3287: if ($changeHash{$key}) {
3288: $newenvhash{'environment.canrequest.author'} = 1;
3289: } else {
3290: $newenvhash{'environment.canrequest.author'} =
3291: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
3292: $key,'reload','requestauthor');
3293: }
1.275 raeburn 3294: } elsif ($key ne 'quota') {
1.270 raeburn 3295: $newenvhash{'environment.tools.'.$key} =
3296: $changeHash{'tools.'.$key};
1.279 raeburn 3297: if ($changeHash{'tools.'.$key} ne '') {
3298: $newenvhash{'environment.availabletools.'.$key} =
3299: $changeHash{'tools.'.$key};
3300: } else {
3301: $newenvhash{'environment.availabletools.'.$key} =
1.367 golterma 3302: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
3303: $key,'reload','tools');
1.279 raeburn 3304: }
1.270 raeburn 3305: }
3306: }
1.271 raeburn 3307: if (keys(%newenvhash)) {
3308: &Apache::lonnet::appenv(\%newenvhash);
3309: }
1.267 raeburn 3310: }
3311: }
1.204 raeburn 3312: }
1.334 raeburn 3313: if (keys(%namechanged) > 0) {
1.337 raeburn 3314: foreach my $field (@userinfo) {
3315: $changeHash{$field} = $env{'form.c'.$field};
3316: }
3317: # Make the change
1.204 raeburn 3318: $namechgresult =
3319: &Apache::lonnet::modifyuser($env{'form.ccdomain'},
3320: $env{'form.ccuname'},$changeHash{'id'},undef,undef,
3321: $changeHash{'firstname'},$changeHash{'middlename'},
3322: $changeHash{'lastname'},$changeHash{'generation'},
1.337 raeburn 3323: $changeHash{'id'},undef,$changeHash{'permanentemail'},undef,\@userinfo);
1.220 raeburn 3324: %userupdate = (
3325: lastname => $env{'form.clastname'},
3326: middlename => $env{'form.cmiddlename'},
3327: firstname => $env{'form.cfirstname'},
3328: generation => $env{'form.cgeneration'},
3329: id => $env{'form.cid'},
3330: );
1.204 raeburn 3331: }
1.334 raeburn 3332: if (((keys(%namechanged) > 0) && $namechgresult eq 'ok') ||
1.267 raeburn 3333: ((keys(%changed) > 0) && $chgresult eq 'ok')) {
1.28 matthew 3334: # Tell the user we changed the name
1.334 raeburn 3335: &display_userinfo($r,1,\@disporder,\%canshow,\@requestcourses,
1.362 raeburn 3336: \@usertools,\@requestauthor,\%userenv,\%changed,\%namechanged,
1.334 raeburn 3337: \%oldsettings, \%oldsettingstext,\%newsettings,
3338: \%newsettingstext);
1.203 raeburn 3339: if ($env{'form.cid'} ne $userenv{'id'}) {
3340: &Apache::lonnet::idput($env{'form.ccdomain'},
1.406.2.5 raeburn 3341: {$env{'form.ccuname'} => $env{'form.cid'}});
1.203 raeburn 3342: if (($recurseid) &&
3343: (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'}))) {
3344: my $idresult =
3345: &Apache::lonuserutils::propagate_id_change(
3346: $env{'form.ccuname'},$env{'form.ccdomain'},
3347: \%userupdate);
3348: $r->print('<br />'.$idresult.'<br />');
3349: }
1.196 raeburn 3350: }
1.149 raeburn 3351: if (($env{'form.ccdomain'} eq $env{'user.domain'}) &&
3352: ($env{'form.ccuname'} eq $env{'user.name'})) {
3353: my %newenvhash;
3354: foreach my $key (keys(%changeHash)) {
3355: $newenvhash{'environment.'.$key} = $changeHash{$key};
3356: }
1.238 raeburn 3357: &Apache::lonnet::appenv(\%newenvhash);
1.149 raeburn 3358: }
1.28 matthew 3359: } else { # error occurred
1.389 bisitz 3360: $r->print(
3361: '<p class="LC_error">'
3362: .&mt('Unable to successfully change environment for [_1] in domain [_2].',
3363: '"'.$env{'form.ccuname'}.'"',
3364: '"'.$env{'form.ccdomain'}.'"')
3365: .'</p>');
1.28 matthew 3366: }
1.334 raeburn 3367: } else { # End of if ($env ... ) logic
1.275 raeburn 3368: # They did not want to change the users name, quota, tool availability,
3369: # or ability to request creation of courses,
1.267 raeburn 3370: # but we can still tell them what the name and quota and availabilities are
1.334 raeburn 3371: &display_userinfo($r,undef,\@disporder,\%canshow,\@requestcourses,
1.362 raeburn 3372: \@usertools,\@requestauthor,\%userenv,\%changed,\%namechanged,\%oldsettings,
1.334 raeburn 3373: \%oldsettingstext,\%newsettings,\%newsettingstext);
1.28 matthew 3374: }
1.206 raeburn 3375: if (@mod_disallowed) {
3376: my ($rolestr,$contextname);
3377: if (@longroles > 0) {
3378: $rolestr = join(', ',@longroles);
3379: } else {
3380: $rolestr = &mt('No roles');
3381: }
3382: if ($context eq 'course') {
1.399 bisitz 3383: $contextname = 'course';
1.206 raeburn 3384: } elsif ($context eq 'author') {
1.399 bisitz 3385: $contextname = 'co-author';
1.206 raeburn 3386: }
3387: $r->print(&mt('The following fields were not updated: ').'<ul>');
3388: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
3389: foreach my $field (@mod_disallowed) {
3390: $r->print('<li>'.$fieldtitles{$field}.'</li>'."\n");
3391: }
1.207 raeburn 3392: $r->print('</ul>');
3393: if (@mod_disallowed == 1) {
1.399 bisitz 3394: $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 3395: } else {
1.399 bisitz 3396: $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 3397: }
1.292 bisitz 3398: my $helplink = 'javascript:helpMenu('."'display'".')';
3399: $r->print('<span class="LC_cusr_emph">'.$rolestr.'</span><br />'
3400: .&mt('Please contact your [_1]helpdesk[_2] for more information.'
3401: ,'<a href="'.$helplink.'">','</a>')
3402: .'<br />');
1.206 raeburn 3403: }
1.259 bisitz 3404: $r->print('<span class="LC_warning">'
3405: .$no_forceid_alert
3406: .&Apache::lonuserutils::print_namespacing_alerts($env{'form.ccdomain'},\%alerts,\%curr_rules)
3407: .'</span>');
1.4 www 3408: }
1.367 golterma 3409: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
1.220 raeburn 3410: if ($env{'form.action'} eq 'singlestudent') {
1.375 raeburn 3411: &enroll_single_student($r,$uhome,$amode,$genpwd,$now,$newuser,$context,
3412: $crstype,$showcredits,$defaultcredits);
1.386 bisitz 3413: my $linktext = ($crstype eq 'Community' ?
3414: &mt('Enroll Another Member') : &mt('Enroll Another Student'));
3415: $r->print(
3416: &Apache::lonhtmlcommon::actionbox([
3417: '<a href="javascript:backPage(document.userupdate)">'
3418: .($crstype eq 'Community' ?
3419: &mt('Enroll Another Member') : &mt('Enroll Another Student'))
3420: .'</a>']));
1.220 raeburn 3421: } else {
1.375 raeburn 3422: my @rolechanges = &update_roles($r,$context,$showcredits);
1.334 raeburn 3423: if (keys(%namechanged) > 0) {
1.220 raeburn 3424: if ($context eq 'course') {
3425: if (@userroles > 0) {
1.225 raeburn 3426: if ((@rolechanges == 0) ||
3427: (!(grep(/^st$/,@rolechanges)))) {
3428: if (grep(/^st$/,@userroles)) {
3429: my $classlistupdated =
3430: &Apache::lonuserutils::update_classlist($cdom,
1.220 raeburn 3431: $cnum,$env{'form.ccdomain'},
3432: $env{'form.ccuname'},\%userupdate);
1.225 raeburn 3433: }
1.220 raeburn 3434: }
3435: }
3436: }
3437: }
1.226 raeburn 3438: my $userinfo = &Apache::loncommon::plainname($env{'form.ccuname'},
1.233 raeburn 3439: $env{'form.ccdomain'});
3440: if ($env{'form.popup'}) {
3441: $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a></p>');
3442: } else {
1.367 golterma 3443: $r->print('<br />'.&Apache::lonhtmlcommon::actionbox(['<a href="javascript:backPage(document.userupdate,'."'$env{'form.prevphase'}','modify'".')">'
3444: .&mt('Modify this user: [_1]','<span class="LC_cusr_emph">'.$env{'form.ccuname'}.':'.$env{'form.ccdomain'}.' ('.$userinfo.')</span>').'</a>',
3445: '<a href="javascript:backPage(document.userupdate)">'.&mt('Create/Modify Another User').'</a>']));
1.233 raeburn 3446: }
1.220 raeburn 3447: }
3448: }
3449:
1.334 raeburn 3450: sub display_userinfo {
1.362 raeburn 3451: my ($r,$changed,$order,$canshow,$requestcourses,$usertools,$requestauthor,
3452: $userenv,$changedhash,$namechangedhash,$oldsetting,$oldsettingtext,
1.334 raeburn 3453: $newsetting,$newsettingtext) = @_;
3454: return unless (ref($order) eq 'ARRAY' &&
3455: ref($canshow) eq 'HASH' &&
3456: ref($requestcourses) eq 'ARRAY' &&
1.362 raeburn 3457: ref($requestauthor) eq 'ARRAY' &&
1.334 raeburn 3458: ref($usertools) eq 'ARRAY' &&
3459: ref($userenv) eq 'HASH' &&
3460: ref($changedhash) eq 'HASH' &&
3461: ref($oldsetting) eq 'HASH' &&
3462: ref($oldsettingtext) eq 'HASH' &&
3463: ref($newsetting) eq 'HASH' &&
3464: ref($newsettingtext) eq 'HASH');
3465: my %lt=&Apache::lonlocal::texthash(
1.372 raeburn 3466: 'ui' => 'User Information',
1.334 raeburn 3467: 'uic' => 'User Information Changed',
3468: 'firstname' => 'First Name',
3469: 'middlename' => 'Middle Name',
3470: 'lastname' => 'Last Name',
3471: 'generation' => 'Generation',
3472: 'id' => 'Student/Employee ID',
3473: 'permanentemail' => 'Permanent e-mail address',
1.378 raeburn 3474: 'portfolioquota' => 'Disk space allocated to portfolio files',
1.385 bisitz 3475: 'authorquota' => 'Disk space allocated to Authoring Space',
1.334 raeburn 3476: 'blog' => 'Blog Availability',
1.361 raeburn 3477: 'webdav' => 'WebDAV Availability',
1.334 raeburn 3478: 'aboutme' => 'Personal Information Page Availability',
3479: 'portfolio' => 'Portfolio Availability',
3480: 'official' => 'Can Request Official Courses',
3481: 'unofficial' => 'Can Request Unofficial Courses',
3482: 'community' => 'Can Request Communities',
1.384 raeburn 3483: 'textbook' => 'Can Request Textbook Courses',
1.362 raeburn 3484: 'requestauthor' => 'Can Request Author Role',
1.334 raeburn 3485: 'inststatus' => "Affiliation",
3486: 'prvs' => 'Previous Value:',
3487: 'chto' => 'Changed To:'
3488: );
3489: if ($changed) {
1.372 raeburn 3490: $r->print('<h3>'.$lt{'uic'}.'</h3>'.
1.367 golterma 3491: &Apache::loncommon::start_data_table().
3492: &Apache::loncommon::start_data_table_header_row());
1.334 raeburn 3493: $r->print("<th> </th>\n");
1.367 golterma 3494: $r->print('<th><b>'.$lt{'prvs'}.'</b></th>');
3495: $r->print('<th><span class="LC_nobreak"><b>'.$lt{'chto'}.'</b></span></th>');
3496: $r->print(&Apache::loncommon::end_data_table_header_row());
3497: my @userinfo = ('firstname','middlename','lastname','generation','permanentemail','id');
3498:
1.334 raeburn 3499: foreach my $item (@userinfo) {
3500: my $value = $env{'form.c'.$item};
1.367 golterma 3501: #show changes only:
1.383 raeburn 3502: unless ($value eq $userenv->{$item}){
1.367 golterma 3503: $r->print(&Apache::loncommon::start_data_table_row());
3504: $r->print("<td>$lt{$item}</td>\n");
1.383 raeburn 3505: $r->print("<td>".$userenv->{$item}."</td>\n");
1.367 golterma 3506: $r->print("<td>$value </td>\n");
3507: $r->print(&Apache::loncommon::end_data_table_row());
1.334 raeburn 3508: }
3509: }
3510: foreach my $entry (@{$order}) {
1.383 raeburn 3511: if ($canshow->{$entry}) {
3512: if (($entry eq 'requestcourses') || ($entry eq 'reqcrsotherdom') || ($entry eq 'requestauthor')) {
3513: my @items;
3514: if ($entry eq 'requestauthor') {
3515: @items = ($entry);
3516: } else {
3517: @items = @{$requestcourses};
1.384 raeburn 3518: }
1.383 raeburn 3519: foreach my $item (@items) {
3520: if (($newsetting->{$item} ne $oldsetting->{$item}) ||
3521: ($newsettingtext->{$item} ne $oldsettingtext->{$item})) {
3522: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3523: $r->print("<td>$lt{$item}</td>\n");
3524: $r->print("<td>".$oldsetting->{$item});
3525: if ($oldsettingtext->{$item}) {
3526: if ($oldsetting->{$item}) {
3527: $r->print(' -- ');
3528: }
3529: $r->print($oldsettingtext->{$item});
3530: }
3531: $r->print("</td>\n");
3532: $r->print("<td>".$newsetting->{$item});
3533: if ($newsettingtext->{$item}) {
3534: if ($newsetting->{$item}) {
3535: $r->print(' -- ');
3536: }
3537: $r->print($newsettingtext->{$item});
3538: }
3539: $r->print("</td>\n");
3540: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.334 raeburn 3541: }
3542: }
3543: } elsif ($entry eq 'tools') {
3544: foreach my $item (@{$usertools}) {
1.383 raeburn 3545: if ($newsetting->{$item} ne $oldsetting->{$item}) {
3546: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3547: $r->print("<td>$lt{$item}</td>\n");
3548: $r->print("<td>".$oldsetting->{$item}.' '.$oldsettingtext->{$item}."</td>\n");
3549: $r->print("<td>".$newsetting->{$item}.' '.$newsettingtext->{$item}."</td>\n");
3550: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.334 raeburn 3551: }
3552: }
1.378 raeburn 3553: } elsif ($entry eq 'quota') {
3554: if ((ref($oldsetting->{$entry}) eq 'HASH') && (ref($oldsettingtext->{$entry}) eq 'HASH') &&
3555: (ref($newsetting->{$entry}) eq 'HASH') && (ref($newsettingtext->{$entry}) eq 'HASH')) {
3556: foreach my $name ('portfolio','author') {
1.383 raeburn 3557: if ($newsetting->{$entry}->{$name} ne $oldsetting->{$entry}->{$name}) {
3558: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3559: $r->print("<td>$lt{$name.$entry}</td>\n");
3560: $r->print("<td>".$oldsettingtext->{$entry}->{$name}."</td>\n");
3561: $r->print("<td>".$newsettingtext->{$entry}->{$name}."</td>\n");
3562: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.378 raeburn 3563: }
3564: }
3565: }
1.334 raeburn 3566: } else {
1.383 raeburn 3567: if ($newsetting->{$entry} ne $oldsetting->{$entry}) {
3568: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3569: $r->print("<td>$lt{$entry}</td>\n");
3570: $r->print("<td>".$oldsetting->{$entry}.' '.$oldsettingtext->{$entry}."</td>\n");
3571: $r->print("<td>".$newsetting->{$entry}.' '.$newsettingtext->{$entry}."</td>\n");
3572: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.334 raeburn 3573: }
3574: }
3575: }
3576: }
1.367 golterma 3577: $r->print(&Apache::loncommon::end_data_table().'<br />');
1.372 raeburn 3578: } else {
3579: $r->print('<h3>'.$lt{'ui'}.'</h3>'.
3580: '<p>'.&mt('No changes made to user information').'</p>');
1.334 raeburn 3581: }
3582: return;
3583: }
3584:
1.275 raeburn 3585: sub tool_changes {
3586: my ($context,$usertools,$oldaccess,$oldaccesstext,$userenv,$changeHash,
3587: $changed,$newaccess,$newaccesstext) = @_;
3588: if (!((ref($usertools) eq 'ARRAY') && (ref($oldaccess) eq 'HASH') &&
3589: (ref($oldaccesstext) eq 'HASH') && (ref($userenv) eq 'HASH') &&
3590: (ref($changeHash) eq 'HASH') && (ref($changed) eq 'HASH') &&
3591: (ref($newaccess) eq 'HASH') && (ref($newaccesstext) eq 'HASH'))) {
3592: return;
3593: }
1.383 raeburn 3594: my %reqdisplay = &requestchange_display();
1.300 raeburn 3595: if ($context eq 'reqcrsotherdom') {
1.309 raeburn 3596: my @options = ('approval','validate','autolimit');
1.306 raeburn 3597: my $optregex = join('|',@options);
1.300 raeburn 3598: my $cdom = $env{'request.role.domain'};
3599: foreach my $tool (@{$usertools}) {
1.383 raeburn 3600: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
1.314 raeburn 3601: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
1.300 raeburn 3602: $changeHash->{$context.'.'.$tool} = $userenv->{$context.'.'.$tool};
1.383 raeburn 3603: my ($newop,$limit);
1.314 raeburn 3604: if ($env{'form.'.$context.'_'.$tool}) {
3605: $newop = $env{'form.'.$context.'_'.$tool};
3606: if ($newop eq 'autolimit') {
1.383 raeburn 3607: $limit = $env{'form.'.$context.'_'.$tool.'_limit'};
1.314 raeburn 3608: $limit =~ s/\D+//g;
3609: $newop .= '='.$limit;
3610: }
3611: }
1.300 raeburn 3612: if ($userenv->{$context.'.'.$tool} eq '') {
1.314 raeburn 3613: if ($newop) {
3614: $changed->{$tool}=&tool_admin($tool,$cdom.':'.$newop,
1.300 raeburn 3615: $changeHash,$context);
3616: if ($changed->{$tool}) {
1.383 raeburn 3617: if ($newop =~ /^autolimit/) {
3618: if ($limit) {
3619: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3620: } else {
3621: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3622: }
3623: } else {
3624: $newaccesstext->{$tool} = $reqdisplay{$newop};
3625: }
1.300 raeburn 3626: } else {
3627: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
3628: }
3629: }
3630: } else {
3631: my @curr = split(',',$userenv->{$context.'.'.$tool});
3632: my @new;
3633: my $changedoms;
1.314 raeburn 3634: foreach my $req (@curr) {
3635: if ($req =~ /^\Q$cdom\E\:($optregex\=?\d*)$/) {
3636: my $oldop = $1;
1.383 raeburn 3637: if ($oldop =~ /^autolimit=(\d*)/) {
3638: my $limit = $1;
3639: if ($limit) {
3640: $oldaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3641: } else {
3642: $oldaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3643: }
3644: } else {
3645: $oldaccesstext->{$tool} = $reqdisplay{$oldop};
3646: }
1.314 raeburn 3647: if ($oldop ne $newop) {
3648: $changedoms = 1;
3649: foreach my $item (@curr) {
3650: my ($reqdom,$option) = split(':',$item);
3651: unless ($reqdom eq $cdom) {
3652: push(@new,$item);
3653: }
3654: }
3655: if ($newop) {
3656: push(@new,$cdom.':'.$newop);
1.300 raeburn 3657: }
1.314 raeburn 3658: @new = sort(@new);
1.300 raeburn 3659: }
1.314 raeburn 3660: last;
1.300 raeburn 3661: }
1.314 raeburn 3662: }
3663: if ((!$changedoms) && ($newop)) {
1.300 raeburn 3664: $changedoms = 1;
1.306 raeburn 3665: @new = sort(@curr,$cdom.':'.$newop);
1.300 raeburn 3666: }
3667: if ($changedoms) {
1.314 raeburn 3668: my $newdomstr;
1.300 raeburn 3669: if (@new) {
3670: $newdomstr = join(',',@new);
3671: }
3672: $changed->{$tool}=&tool_admin($tool,$newdomstr,$changeHash,
3673: $context);
3674: if ($changed->{$tool}) {
3675: if ($env{'form.'.$context.'_'.$tool}) {
1.306 raeburn 3676: if ($env{'form.'.$context.'_'.$tool} eq 'autolimit') {
1.314 raeburn 3677: my $limit = $env{'form.'.$context.'_'.$tool.'_limit'};
3678: $limit =~ s/\D+//g;
3679: if ($limit) {
1.383 raeburn 3680: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
1.314 raeburn 3681: } else {
1.383 raeburn 3682: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
1.306 raeburn 3683: }
1.314 raeburn 3684: } else {
1.306 raeburn 3685: $newaccesstext->{$tool} = $reqdisplay{$env{'form.'.$context.'_'.$tool}};
3686: }
1.300 raeburn 3687: } else {
1.383 raeburn 3688: $newaccesstext->{$tool} = &mt("availability set to 'off'");
1.300 raeburn 3689: }
3690: }
3691: }
3692: }
3693: }
3694: return;
3695: }
1.275 raeburn 3696: foreach my $tool (@{$usertools}) {
1.383 raeburn 3697: my ($newval,$limit,$envkey);
1.362 raeburn 3698: $envkey = $context.'.'.$tool;
1.306 raeburn 3699: if ($context eq 'requestcourses') {
3700: $newval = $env{'form.crsreq_'.$tool};
3701: if ($newval eq 'autolimit') {
1.383 raeburn 3702: $limit = $env{'form.crsreq_'.$tool.'_limit'};
3703: $limit =~ s/\D+//g;
3704: $newval .= '='.$limit;
1.306 raeburn 3705: }
1.362 raeburn 3706: } elsif ($context eq 'requestauthor') {
3707: $newval = $env{'form.'.$context};
3708: $envkey = $context;
1.314 raeburn 3709: } else {
1.306 raeburn 3710: $newval = $env{'form.'.$context.'_'.$tool};
3711: }
1.362 raeburn 3712: if ($userenv->{$envkey} ne '') {
1.275 raeburn 3713: $oldaccess->{$tool} = &mt('custom');
1.383 raeburn 3714: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3715: if ($userenv->{$envkey} =~ /^autolimit=(\d*)$/) {
3716: my $currlimit = $1;
3717: if ($currlimit eq '') {
3718: $oldaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3719: } else {
3720: $oldaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$currlimit);
3721: }
3722: } elsif ($userenv->{$envkey}) {
3723: $oldaccesstext->{$tool} = $reqdisplay{$userenv->{$envkey}};
3724: } else {
3725: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
3726: }
1.275 raeburn 3727: } else {
1.383 raeburn 3728: if ($userenv->{$envkey}) {
3729: $oldaccesstext->{$tool} = &mt("availability set to 'on'");
3730: } else {
3731: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
3732: }
1.275 raeburn 3733: }
1.362 raeburn 3734: $changeHash->{$envkey} = $userenv->{$envkey};
1.275 raeburn 3735: if ($env{'form.custom'.$tool} == 1) {
1.362 raeburn 3736: if ($newval ne $userenv->{$envkey}) {
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};
1.383 raeburn 3762: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3763: if ($newval =~ /^autolimit/) {
3764: if ($limit) {
3765: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3766: } else {
3767: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3768: }
3769: } elsif ($newval) {
3770: $newaccesstext->{$tool} = $reqdisplay{$newval};
3771: } else {
3772: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3773: }
1.275 raeburn 3774: } else {
1.383 raeburn 3775: if ($userenv->{$context.'.'.$tool}) {
3776: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3777: } else {
3778: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3779: }
1.275 raeburn 3780: }
3781: }
3782: } else {
3783: $newaccess->{$tool} = $oldaccess->{$tool};
3784: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
3785: }
3786: } else {
3787: $changed->{$tool} = &tool_admin($tool,'',$changeHash,$context);
3788: if ($changed->{$tool}) {
3789: $newaccess->{$tool} = &mt('default');
3790: } else {
3791: $newaccess->{$tool} = $oldaccess->{$tool};
1.383 raeburn 3792: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3793: if ($newval =~ /^autolimit/) {
3794: if ($limit) {
3795: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3796: } else {
3797: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3798: }
3799: } elsif ($newval) {
3800: $newaccesstext->{$tool} = $reqdisplay{$newval};
3801: } else {
3802: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3803: }
1.275 raeburn 3804: } else {
1.383 raeburn 3805: if ($userenv->{$context.'.'.$tool}) {
3806: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3807: } else {
3808: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3809: }
1.275 raeburn 3810: }
3811: }
3812: }
3813: } else {
3814: $oldaccess->{$tool} = &mt('default');
3815: if ($env{'form.custom'.$tool} == 1) {
1.306 raeburn 3816: $changed->{$tool} = &tool_admin($tool,$newval,$changeHash,
3817: $context);
1.275 raeburn 3818: if ($changed->{$tool}) {
3819: $newaccess->{$tool} = &mt('custom');
1.383 raeburn 3820: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3821: if ($newval =~ /^autolimit/) {
3822: if ($limit) {
3823: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3824: } else {
3825: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3826: }
3827: } elsif ($newval) {
3828: $newaccesstext->{$tool} = $reqdisplay{$newval};
3829: } else {
3830: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3831: }
1.275 raeburn 3832: } else {
1.383 raeburn 3833: if ($newval) {
3834: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3835: } else {
3836: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3837: }
1.275 raeburn 3838: }
3839: } else {
3840: $newaccess->{$tool} = $oldaccess->{$tool};
3841: }
3842: } else {
3843: $newaccess->{$tool} = $oldaccess->{$tool};
3844: }
3845: }
3846: }
3847: return;
3848: }
3849:
1.220 raeburn 3850: sub update_roles {
1.375 raeburn 3851: my ($r,$context,$showcredits) = @_;
1.4 www 3852: my $now=time;
1.225 raeburn 3853: my @rolechanges;
1.220 raeburn 3854: my %disallowed;
1.73 sakharuk 3855: $r->print('<h3>'.&mt('Modifying Roles').'</h3>');
1.404 raeburn 3856: foreach my $key (keys(%env)) {
1.135 raeburn 3857: next if (! $env{$key});
1.190 raeburn 3858: next if ($key eq 'form.action');
1.27 matthew 3859: # Revoke roles
1.135 raeburn 3860: if ($key=~/^form\.rev/) {
3861: if ($key=~/^form\.rev\:([^\_]+)\_([^\_\.]+)$/) {
1.64 www 3862: # Revoke standard role
1.170 albertel 3863: my ($scope,$role) = ($1,$2);
3864: my $result =
3865: &Apache::lonnet::revokerole($env{'form.ccdomain'},
3866: $env{'form.ccuname'},
1.239 raeburn 3867: $scope,$role,'','',$context);
1.367 golterma 3868: $r->print(&Apache::lonhtmlcommon::confirm_success(
1.369 bisitz 3869: &mt('Revoking [_1] in [_2]',
3870: &Apache::lonnet::plaintext($role),
1.372 raeburn 3871: &Apache::loncommon::show_role_extent($scope,$context,$role)),
1.369 bisitz 3872: $result ne "ok").'<br />');
3873: if ($result ne "ok") {
3874: $r->print(&mt('Error: [_1]',$result).'<br />');
3875: }
1.170 albertel 3876: if ($role eq 'st') {
1.202 raeburn 3877: my $result =
1.198 raeburn 3878: &Apache::lonuserutils::classlist_drop($scope,
3879: $env{'form.ccuname'},$env{'form.ccdomain'},
1.202 raeburn 3880: $now);
1.367 golterma 3881: $r->print(&Apache::lonhtmlcommon::confirm_success($result));
1.53 www 3882: }
1.225 raeburn 3883: if (!grep(/^\Q$role\E$/,@rolechanges)) {
3884: push(@rolechanges,$role);
3885: }
1.196 raeburn 3886: }
1.195 raeburn 3887: if ($key=~m{^form\.rev\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}s) {
1.64 www 3888: # Revoke custom role
1.369 bisitz 3889: my $result = &Apache::lonnet::revokecustomrole(
3890: $env{'form.ccdomain'},$env{'form.ccuname'},$1,$2,$3,$4,'','',$context);
1.367 golterma 3891: $r->print(&Apache::lonhtmlcommon::confirm_success(
1.369 bisitz 3892: &mt('Revoking custom role [_1] by [_2] in [_3]',
1.372 raeburn 3893: $4,$3.':'.$2,&Apache::loncommon::show_role_extent($1,$context,'cr')),
1.369 bisitz 3894: $result ne 'ok').'<br />');
3895: if ($result ne "ok") {
3896: $r->print(&mt('Error: [_1]',$result).'<br />');
3897: }
1.225 raeburn 3898: if (!grep(/^cr$/,@rolechanges)) {
3899: push(@rolechanges,'cr');
3900: }
1.64 www 3901: }
1.135 raeburn 3902: } elsif ($key=~/^form\.del/) {
3903: if ($key=~/^form\.del\:([^\_]+)\_([^\_\.]+)$/) {
1.116 raeburn 3904: # Delete standard role
1.170 albertel 3905: my ($scope,$role) = ($1,$2);
3906: my $result =
3907: &Apache::lonnet::assignrole($env{'form.ccdomain'},
3908: $env{'form.ccuname'},
1.239 raeburn 3909: $scope,$role,$now,0,1,'',
3910: $context);
1.367 golterma 3911: $r->print(&Apache::lonhtmlcommon::confirm_success(
3912: &mt('Deleting [_1] in [_2]',
1.369 bisitz 3913: &Apache::lonnet::plaintext($role),
1.372 raeburn 3914: &Apache::loncommon::show_role_extent($scope,$context,$role)),
1.369 bisitz 3915: $result ne 'ok').'<br />');
3916: if ($result ne "ok") {
3917: $r->print(&mt('Error: [_1]',$result).'<br />');
3918: }
1.367 golterma 3919:
1.170 albertel 3920: if ($role eq 'st') {
1.202 raeburn 3921: my $result =
1.198 raeburn 3922: &Apache::lonuserutils::classlist_drop($scope,
3923: $env{'form.ccuname'},$env{'form.ccdomain'},
1.202 raeburn 3924: $now);
1.369 bisitz 3925: $r->print(&Apache::lonhtmlcommon::confirm_success($result));
1.81 albertel 3926: }
1.225 raeburn 3927: if (!grep(/^\Q$role\E$/,@rolechanges)) {
3928: push(@rolechanges,$role);
3929: }
1.116 raeburn 3930: }
1.139 albertel 3931: if ($key=~m{^form\.del\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
1.116 raeburn 3932: my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
3933: # Delete custom role
1.369 bisitz 3934: my $result =
3935: &Apache::lonnet::assigncustomrole($env{'form.ccdomain'},
3936: $env{'form.ccuname'},$url,$rdom,$rnam,$rolename,$now,
3937: 0,1,$context);
3938: $r->print(&Apache::lonhtmlcommon::confirm_success(&mt('Deleting custom role [_1] by [_2] in [_3]',
1.372 raeburn 3939: $rolename,$rnam.':'.$rdom,&Apache::loncommon::show_role_extent($1,$context,'cr')),
1.369 bisitz 3940: $result ne "ok").'<br />');
3941: if ($result ne "ok") {
3942: $r->print(&mt('Error: [_1]',$result).'<br />');
3943: }
1.367 golterma 3944:
1.225 raeburn 3945: if (!grep(/^cr$/,@rolechanges)) {
3946: push(@rolechanges,'cr');
3947: }
1.116 raeburn 3948: }
1.135 raeburn 3949: } elsif ($key=~/^form\.ren/) {
1.101 albertel 3950: my $udom = $env{'form.ccdomain'};
3951: my $uname = $env{'form.ccuname'};
1.116 raeburn 3952: # Re-enable standard role
1.135 raeburn 3953: if ($key=~/^form\.ren\:([^\_]+)\_([^\_\.]+)$/) {
1.89 raeburn 3954: my $url = $1;
3955: my $role = $2;
3956: my $logmsg;
3957: my $output;
3958: if ($role eq 'st') {
1.141 albertel 3959: if ($url =~ m-^/($match_domain)/($match_courseid)/?(\w*)$-) {
1.374 raeburn 3960: my ($cdom,$cnum,$csec) = ($1,$2,$3);
1.375 raeburn 3961: my $credits;
3962: if ($showcredits) {
3963: my $defaultcredits =
3964: &Apache::lonuserutils::get_defaultcredits($cdom,$cnum);
3965: $credits = &get_user_credits($defaultcredits,$cdom,$cnum);
3966: }
3967: my $result = &Apache::loncommon::commit_studentrole(\$logmsg,$udom,$uname,$url,$role,$now,0,$cdom,$cnum,$csec,$context,$credits);
1.220 raeburn 3968: if (($result =~ /^error/) || ($result eq 'not_in_class') || ($result eq 'unknown_course') || ($result eq 'refused')) {
1.223 raeburn 3969: if ($result eq 'refused' && $logmsg) {
3970: $output = $logmsg;
3971: } else {
1.369 bisitz 3972: $output = &mt('Error: [_1]',$result)."\n";
1.223 raeburn 3973: }
1.89 raeburn 3974: } else {
1.372 raeburn 3975: $output = &Apache::lonhtmlcommon::confirm_success(&mt('Assigning [_1] in [_2] starting [_3]',
3976: &Apache::lonnet::plaintext($role),
3977: &Apache::loncommon::show_role_extent($url,$context,'st'),
3978: &Apache::lonlocal::locallocaltime($now))).'<br />'.$logmsg.'<br />';
1.89 raeburn 3979: }
3980: }
3981: } else {
1.101 albertel 3982: my $result=&Apache::lonnet::assignrole($env{'form.ccdomain'},
1.239 raeburn 3983: $env{'form.ccuname'},$url,$role,0,$now,'','',
3984: $context);
1.367 golterma 3985: $output = &Apache::lonhtmlcommon::confirm_success(&mt('Re-enabling [_1] in [_2]',
1.372 raeburn 3986: &Apache::lonnet::plaintext($role),
3987: &Apache::loncommon::show_role_extent($url,$context,$role)),$result ne "ok").'<br />';
1.369 bisitz 3988: if ($result ne "ok") {
3989: $output .= &mt('Error: [_1]',$result).'<br />';
3990: }
3991: }
1.89 raeburn 3992: $r->print($output);
1.225 raeburn 3993: if (!grep(/^\Q$role\E$/,@rolechanges)) {
3994: push(@rolechanges,$role);
3995: }
1.113 raeburn 3996: }
1.116 raeburn 3997: # Re-enable custom role
1.139 albertel 3998: if ($key=~m{^form\.ren\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
1.116 raeburn 3999: my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
4000: my $result = &Apache::lonnet::assigncustomrole(
4001: $env{'form.ccdomain'}, $env{'form.ccuname'},
1.240 raeburn 4002: $url,$rdom,$rnam,$rolename,0,$now,undef,$context);
1.369 bisitz 4003: $r->print(&Apache::lonhtmlcommon::confirm_success(
4004: &mt('Re-enabling custom role [_1] by [_2] in [_3]',
1.372 raeburn 4005: $rolename,$rnam.':'.$rdom,&Apache::loncommon::show_role_extent($1,$context,'cr')),
1.369 bisitz 4006: $result ne "ok").'<br />');
4007: if ($result ne "ok") {
4008: $r->print(&mt('Error: [_1]',$result).'<br />');
4009: }
1.225 raeburn 4010: if (!grep(/^cr$/,@rolechanges)) {
4011: push(@rolechanges,'cr');
4012: }
1.116 raeburn 4013: }
1.135 raeburn 4014: } elsif ($key=~/^form\.act/) {
1.101 albertel 4015: my $udom = $env{'form.ccdomain'};
4016: my $uname = $env{'form.ccuname'};
1.141 albertel 4017: if ($key=~/^form\.act\_($match_domain)\_($match_courseid)\_cr_cr_($match_domain)_($match_username)_([^\_]+)$/) {
1.65 www 4018: # Activate a custom role
1.83 albertel 4019: my ($one,$two,$three,$four,$five)=($1,$2,$3,$4,$5);
4020: my $url='/'.$one.'/'.$two;
4021: my $full=$one.'_'.$two.'_cr_cr_'.$three.'_'.$four.'_'.$five;
1.65 www 4022:
1.101 albertel 4023: my $start = ( $env{'form.start_'.$full} ?
4024: $env{'form.start_'.$full} :
1.88 raeburn 4025: $now );
1.101 albertel 4026: my $end = ( $env{'form.end_'.$full} ?
4027: $env{'form.end_'.$full} :
1.88 raeburn 4028: 0 );
4029:
4030: # split multiple sections
4031: my %sections = ();
1.101 albertel 4032: my $num_sections = &build_roles($env{'form.sec_'.$full},\%sections,$5);
1.88 raeburn 4033: if ($num_sections == 0) {
1.240 raeburn 4034: $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$url,$three,$four,$five,$start,$end,$context));
1.88 raeburn 4035: } else {
1.114 albertel 4036: my %curr_groups =
1.117 raeburn 4037: &Apache::longroup::coursegroups($one,$two);
1.404 raeburn 4038: foreach my $sec (sort {$a cmp $b} keys(%sections)) {
1.113 raeburn 4039: if (($sec eq 'none') || ($sec eq 'all') ||
4040: exists($curr_groups{$sec})) {
4041: $disallowed{$sec} = $url;
4042: next;
4043: }
4044: my $securl = $url.'/'.$sec;
1.240 raeburn 4045: $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$securl,$three,$four,$five,$start,$end,$context));
1.88 raeburn 4046: }
4047: }
1.225 raeburn 4048: if (!grep(/^cr$/,@rolechanges)) {
4049: push(@rolechanges,'cr');
4050: }
1.142 raeburn 4051: } elsif ($key=~/^form\.act\_($match_domain)\_($match_name)\_([^\_]+)$/) {
1.27 matthew 4052: # Activate roles for sections with 3 id numbers
4053: # set start, end times, and the url for the class
1.83 albertel 4054: my ($one,$two,$three)=($1,$2,$3);
1.101 albertel 4055: my $start = ( $env{'form.start_'.$one.'_'.$two.'_'.$three} ?
4056: $env{'form.start_'.$one.'_'.$two.'_'.$three} :
1.27 matthew 4057: $now );
1.101 albertel 4058: my $end = ( $env{'form.end_'.$one.'_'.$two.'_'.$three} ?
4059: $env{'form.end_'.$one.'_'.$two.'_'.$three} :
1.27 matthew 4060: 0 );
1.83 albertel 4061: my $url='/'.$one.'/'.$two;
1.88 raeburn 4062: my $type = 'three';
4063: # split multiple sections
4064: my %sections = ();
1.101 albertel 4065: my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two.'_'.$three},\%sections,$three);
1.375 raeburn 4066: my $credits;
4067: if ($three eq 'st') {
4068: if ($showcredits) {
4069: my $defaultcredits =
4070: &Apache::lonuserutils::get_defaultcredits($one,$two);
4071: $credits = $env{'form.credits_'.$one.'_'.$two.'_'.$three};
4072: $credits =~ s/[^\d\.]//g;
4073: if ($credits eq $defaultcredits) {
4074: undef($credits);
4075: }
4076: }
4077: }
1.88 raeburn 4078: if ($num_sections == 0) {
1.375 raeburn 4079: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'',$context,$credits));
1.88 raeburn 4080: } else {
1.114 albertel 4081: my %curr_groups =
1.117 raeburn 4082: &Apache::longroup::coursegroups($one,$two);
1.88 raeburn 4083: my $emptysec = 0;
1.404 raeburn 4084: foreach my $sec (sort {$a cmp $b} keys(%sections)) {
1.88 raeburn 4085: $sec =~ s/\W//g;
1.113 raeburn 4086: if ($sec ne '') {
4087: if (($sec eq 'none') || ($sec eq 'all') ||
4088: exists($curr_groups{$sec})) {
4089: $disallowed{$sec} = $url;
4090: next;
4091: }
1.88 raeburn 4092: my $securl = $url.'/'.$sec;
1.375 raeburn 4093: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$three,$start,$end,$one,$two,$sec,$context,$credits));
1.88 raeburn 4094: } else {
4095: $emptysec = 1;
4096: }
4097: }
4098: if ($emptysec) {
1.375 raeburn 4099: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'',$context,$credits));
1.88 raeburn 4100: }
1.225 raeburn 4101: }
4102: if (!grep(/^\Q$three\E$/,@rolechanges)) {
4103: push(@rolechanges,$three);
4104: }
1.135 raeburn 4105: } elsif ($key=~/^form\.act\_([^\_]+)\_([^\_]+)$/) {
1.27 matthew 4106: # Activate roles for sections with two id numbers
4107: # set start, end times, and the url for the class
1.101 albertel 4108: my $start = ( $env{'form.start_'.$1.'_'.$2} ?
4109: $env{'form.start_'.$1.'_'.$2} :
1.27 matthew 4110: $now );
1.101 albertel 4111: my $end = ( $env{'form.end_'.$1.'_'.$2} ?
4112: $env{'form.end_'.$1.'_'.$2} :
1.27 matthew 4113: 0 );
1.225 raeburn 4114: my $one = $1;
4115: my $two = $2;
4116: my $url='/'.$one.'/';
1.88 raeburn 4117: # split multiple sections
4118: my %sections = ();
1.225 raeburn 4119: my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two},\%sections,$two);
1.88 raeburn 4120: if ($num_sections == 0) {
1.240 raeburn 4121: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,'',$context));
1.88 raeburn 4122: } else {
4123: my $emptysec = 0;
1.404 raeburn 4124: foreach my $sec (sort {$a cmp $b} keys(%sections)) {
1.88 raeburn 4125: if ($sec ne '') {
4126: my $securl = $url.'/'.$sec;
1.240 raeburn 4127: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$two,$start,$end,$one,undef,$sec,$context));
1.88 raeburn 4128: } else {
4129: $emptysec = 1;
4130: }
4131: }
4132: if ($emptysec) {
1.240 raeburn 4133: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,'',$context));
1.88 raeburn 4134: }
4135: }
1.225 raeburn 4136: if (!grep(/^\Q$two\E$/,@rolechanges)) {
4137: push(@rolechanges,$two);
4138: }
1.64 www 4139: } else {
1.190 raeburn 4140: $r->print('<p><span class="LC_error">'.&mt('ERROR').': '.&mt('Unknown command').' <tt>'.$key.'</tt></span></p><br />');
1.64 www 4141: }
1.113 raeburn 4142: foreach my $key (sort(keys(%disallowed))) {
1.274 bisitz 4143: $r->print('<p class="LC_warning">');
1.113 raeburn 4144: if (($key eq 'none') || ($key eq 'all')) {
1.274 bisitz 4145: $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 4146: } else {
1.274 bisitz 4147: $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 4148: }
1.274 bisitz 4149: $r->print('</p><p>'
4150: .&mt('Please [_1]go back[_2] and choose a different section name.'
4151: ,'<a href="javascript:history.go(-1)'
4152: ,'</a>')
4153: .'</p><br />'
4154: );
1.113 raeburn 4155: }
4156: }
1.101 albertel 4157: } # End of foreach (keys(%env))
1.75 www 4158: # Flush the course logs so reverse user roles immediately updated
1.349 raeburn 4159: $r->register_cleanup(\&Apache::lonnet::flushcourselogs);
1.225 raeburn 4160: if (@rolechanges == 0) {
1.372 raeburn 4161: $r->print('<p>'.&mt('No roles to modify').'</p>');
1.193 raeburn 4162: }
1.225 raeburn 4163: return @rolechanges;
1.220 raeburn 4164: }
4165:
1.375 raeburn 4166: sub get_user_credits {
4167: my ($uname,$udom,$defaultcredits,$cdom,$cnum) = @_;
4168: if ($cdom eq '' || $cnum eq '') {
4169: return unless ($env{'request.course.id'});
4170: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
4171: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
4172: }
4173: my $credits;
4174: my %currhash =
4175: &Apache::lonnet::get('classlist',[$uname.':'.$udom],$cdom,$cnum);
4176: if (keys(%currhash) > 0) {
4177: my @items = split(/:/,$currhash{$uname.':'.$udom});
4178: my $crdidx = &Apache::loncoursedata::CL_CREDITS() - 3;
4179: $credits = $items[$crdidx];
4180: $credits =~ s/[^\d\.]//g;
4181: }
4182: if ($credits eq $defaultcredits) {
4183: undef($credits);
4184: }
4185: return $credits;
4186: }
4187:
1.220 raeburn 4188: sub enroll_single_student {
1.375 raeburn 4189: my ($r,$uhome,$amode,$genpwd,$now,$newuser,$context,$crstype,
4190: $showcredits,$defaultcredits) = @_;
1.318 raeburn 4191: $r->print('<h3>');
4192: if ($crstype eq 'Community') {
4193: $r->print(&mt('Enrolling Member'));
4194: } else {
4195: $r->print(&mt('Enrolling Student'));
4196: }
4197: $r->print('</h3>');
1.220 raeburn 4198:
4199: # Remove non alphanumeric values from section
4200: $env{'form.sections'}=~s/\W//g;
4201:
1.375 raeburn 4202: my $credits;
4203: if (($showcredits) && ($env{'form.credits'} ne '')) {
4204: $credits = $env{'form.credits'};
4205: $credits =~ s/[^\d\.]//g;
4206: if ($credits ne '') {
4207: if ($credits eq $defaultcredits) {
4208: undef($credits);
4209: }
4210: }
4211: }
4212:
1.220 raeburn 4213: # Clean out any old student roles the user has in this class.
4214: &Apache::lonuserutils::modifystudent($env{'form.ccdomain'},
4215: $env{'form.ccuname'},$env{'request.course.id'},undef,$uhome);
4216: my ($startdate,$enddate) = &Apache::lonuserutils::get_dates_from_form();
4217: my $enroll_result =
4218: &Apache::lonnet::modify_student_enrollment($env{'form.ccdomain'},
4219: $env{'form.ccuname'},$env{'form.cid'},$env{'form.cfirstname'},
4220: $env{'form.cmiddlename'},$env{'form.clastname'},
4221: $env{'form.generation'},$env{'form.sections'},$enddate,
1.375 raeburn 4222: $startdate,'manual',undef,$env{'request.course.id'},'',$context,
4223: $credits);
1.220 raeburn 4224: if ($enroll_result =~ /^ok/) {
1.381 bisitz 4225: $r->print(&mt('[_1] enrolled','<b>'.$env{'form.ccuname'}.':'.$env{'form.ccdomain'}.'</b>'));
1.220 raeburn 4226: if ($env{'form.sections'} ne '') {
4227: $r->print(' '.&mt('in section [_1]',$env{'form.sections'}));
4228: }
4229: my ($showstart,$showend);
4230: if ($startdate <= $now) {
4231: $showstart = &mt('Access starts immediately');
4232: } else {
4233: $showstart = &mt('Access starts: ').&Apache::lonlocal::locallocaltime($startdate);
4234: }
4235: if ($enddate == 0) {
4236: $showend = &mt('ends: no ending date');
4237: } else {
4238: $showend = &mt('ends: ').&Apache::lonlocal::locallocaltime($enddate);
4239: }
4240: $r->print('.<br />'.$showstart.'; '.$showend);
4241: if ($startdate <= $now && !$newuser) {
1.386 bisitz 4242: $r->print('<p class="LC_info">');
1.318 raeburn 4243: if ($crstype eq 'Community') {
1.392 raeburn 4244: $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 4245: } else {
1.392 raeburn 4246: $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 4247: }
4248: $r->print('</p>');
1.220 raeburn 4249: }
4250: } else {
4251: $r->print(&mt('unable to enroll').": ".$enroll_result);
4252: }
4253: return;
1.188 raeburn 4254: }
4255:
1.204 raeburn 4256: sub get_defaultquota_text {
4257: my ($settingstatus) = @_;
4258: my $defquotatext;
4259: if ($settingstatus eq '') {
1.383 raeburn 4260: $defquotatext = &mt('default');
1.204 raeburn 4261: } else {
4262: my ($usertypes,$order) =
4263: &Apache::lonnet::retrieve_inst_usertypes($env{'form.ccdomain'});
4264: if ($usertypes->{$settingstatus} eq '') {
1.383 raeburn 4265: $defquotatext = &mt('default');
1.204 raeburn 4266: } else {
1.383 raeburn 4267: $defquotatext = &mt('default for [_1]',$usertypes->{$settingstatus});
1.204 raeburn 4268: }
4269: }
4270: return $defquotatext;
4271: }
4272:
1.188 raeburn 4273: sub update_result_form {
4274: my ($uhome) = @_;
4275: my $outcome =
1.367 golterma 4276: '<form name="userupdate" method="post" action="">'."\n";
1.160 raeburn 4277: foreach my $item ('srchby','srchin','srchtype','srchterm','srchdomain','ccuname','ccdomain') {
1.188 raeburn 4278: $outcome .= '<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n";
1.160 raeburn 4279: }
1.207 raeburn 4280: if ($env{'form.origname'} ne '') {
4281: $outcome .= '<input type="hidden" name="origname" value="'.$env{'form.origname'}.'" />'."\n";
4282: }
1.160 raeburn 4283: foreach my $item ('sortby','seluname','seludom') {
4284: if (exists($env{'form.'.$item})) {
1.188 raeburn 4285: $outcome .= '<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n";
1.160 raeburn 4286: }
4287: }
1.188 raeburn 4288: if ($uhome eq 'no_host') {
4289: $outcome .= '<input type="hidden" name="forcenewuser" value="1" />'."\n";
4290: }
4291: $outcome .= '<input type="hidden" name="phase" value="" />'."\n".
1.383 raeburn 4292: '<input type="hidden" name="currstate" value="" />'."\n".
4293: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n".
1.188 raeburn 4294: '</form>';
4295: return $outcome;
1.4 www 4296: }
4297:
1.149 raeburn 4298: sub quota_admin {
1.378 raeburn 4299: my ($setquota,$changeHash,$name) = @_;
1.149 raeburn 4300: my $quotachanged;
4301: if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
4302: # Current user has quota modification privileges
1.267 raeburn 4303: if (ref($changeHash) eq 'HASH') {
4304: $quotachanged = 1;
1.378 raeburn 4305: $changeHash->{$name.'quota'} = $setquota;
1.267 raeburn 4306: }
1.149 raeburn 4307: }
4308: return $quotachanged;
4309: }
4310:
1.267 raeburn 4311: sub tool_admin {
1.275 raeburn 4312: my ($tool,$settool,$changeHash,$context) = @_;
4313: my $canchange = 0;
1.279 raeburn 4314: if ($context eq 'requestcourses') {
1.275 raeburn 4315: if (&Apache::lonnet::allowed('ccc',$env{'form.ccdomain'})) {
4316: $canchange = 1;
4317: }
1.300 raeburn 4318: } elsif ($context eq 'reqcrsotherdom') {
4319: if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
4320: $canchange = 1;
4321: }
1.362 raeburn 4322: } elsif ($context eq 'requestauthor') {
4323: if (&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) {
4324: $canchange = 1;
4325: }
1.275 raeburn 4326: } elsif (&Apache::lonnet::allowed('mut',$env{'form.ccdomain'})) {
4327: # Current user has quota modification privileges
4328: $canchange = 1;
4329: }
1.267 raeburn 4330: my $toolchanged;
1.275 raeburn 4331: if ($canchange) {
1.267 raeburn 4332: if (ref($changeHash) eq 'HASH') {
4333: $toolchanged = 1;
1.362 raeburn 4334: if ($tool eq 'requestauthor') {
4335: $changeHash->{$context} = $settool;
4336: } else {
4337: $changeHash->{$context.'.'.$tool} = $settool;
4338: }
1.267 raeburn 4339: }
4340: }
4341: return $toolchanged;
4342: }
4343:
1.88 raeburn 4344: sub build_roles {
1.89 raeburn 4345: my ($sectionstr,$sections,$role) = @_;
1.88 raeburn 4346: my $num_sections = 0;
4347: if ($sectionstr=~ /,/) {
4348: my @secnums = split/,/,$sectionstr;
1.89 raeburn 4349: if ($role eq 'st') {
4350: $secnums[0] =~ s/\W//g;
4351: $$sections{$secnums[0]} = 1;
4352: $num_sections = 1;
4353: } else {
4354: foreach my $sec (@secnums) {
4355: $sec =~ ~s/\W//g;
1.150 banghart 4356: if (!($sec eq "")) {
1.89 raeburn 4357: if (exists($$sections{$sec})) {
4358: $$sections{$sec} ++;
4359: } else {
4360: $$sections{$sec} = 1;
4361: $num_sections ++;
4362: }
1.88 raeburn 4363: }
4364: }
4365: }
4366: } else {
4367: $sectionstr=~s/\W//g;
4368: unless ($sectionstr eq '') {
4369: $$sections{$sectionstr} = 1;
4370: $num_sections ++;
4371: }
4372: }
1.129 albertel 4373:
1.88 raeburn 4374: return $num_sections;
4375: }
4376:
1.58 www 4377: # ========================================================== Custom Role Editor
4378:
4379: sub custom_role_editor {
1.406.2.14 raeburn 4380: my ($r,$context,$brcrum,$prefix,$permission) = @_;
1.324 raeburn 4381: my $action = $env{'form.customroleaction'};
1.406.2.14 raeburn 4382: my ($rolename,$helpitem);
1.324 raeburn 4383: if ($action eq 'new') {
4384: $rolename=$env{'form.newrolename'};
4385: } else {
4386: $rolename=$env{'form.rolename'};
1.59 www 4387: }
4388:
1.324 raeburn 4389: my ($crstype,$context);
4390: if ($env{'request.course.id'}) {
4391: $crstype = &Apache::loncommon::course_type();
4392: $context = 'course';
1.406.2.14 raeburn 4393: $helpitem = 'Course_Editing_Custom_Roles';
1.324 raeburn 4394: } else {
4395: $context = 'domain';
1.406.2.5 raeburn 4396: $crstype = 'course';
1.406.2.14 raeburn 4397: $helpitem = 'Domain_Editing_Custom_Roles';
1.324 raeburn 4398: }
1.351 raeburn 4399:
4400: $rolename=~s/[^A-Za-z0-9]//gs;
4401: if (!$rolename || $env{'form.phase'} eq 'pickrole') {
1.406.2.14 raeburn 4402: &print_username_entry_form($r,$context,undef,undef,undef,$crstype,$brcrum,
4403: $permission);
1.351 raeburn 4404: return;
4405: }
4406:
1.406.2.5 raeburn 4407: my $formname = 'form1';
4408: my %privs=();
4409: my $body_top = '<h2>';
4410: # ------------------------------------------------------- Does this role exist?
1.59 www 4411: my ($rdummy,$roledef)=
4412: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
4413: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1.406.2.5 raeburn 4414: $body_top .= &mt('Existing Role').' "';
1.61 www 4415: # ------------------------------------------------- Get current role privileges
1.406.2.5 raeburn 4416: ($privs{'system'},$privs{'domain'},$privs{'course'})=split(/\_/,$roledef);
4417: if ($privs{'system'} =~ /bre\&S/) {
4418: if ($context eq 'domain') {
4419: $crstype = 'Course';
4420: } elsif ($crstype eq 'Community') {
4421: $privs{'system'} =~ s/bre\&S//;
4422: }
4423: } elsif ($context eq 'domain') {
4424: $crstype = 'Course';
1.324 raeburn 4425: }
1.59 www 4426: } else {
1.406.2.5 raeburn 4427: $body_top .= &mt('New Role').' "';
4428: $roledef='';
1.59 www 4429: }
1.153 banghart 4430: $body_top .= $rolename.'"</h2>';
1.406.2.5 raeburn 4431:
4432: # ------------------------------------------------------- What can be assigned?
4433: my %full=();
4434: my %levels=(
4435: course => {},
4436: domain => {},
4437: system => {},
4438: );
4439: my %levelscurrent=(
4440: course => {},
4441: domain => {},
4442: system => {},
4443: );
4444: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
1.160 raeburn 4445: my ($jsback,$elements) = &crumb_utilities();
1.406.2.5 raeburn 4446: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
4447: my $head_script =
4448: &Apache::lonuserutils::custom_roledefs_js($context,$crstype,$formname,
4449: \%full,\@templateroles,$jsback);
1.351 raeburn 4450: push (@{$brcrum},
1.406.2.5 raeburn 4451: {href => "javascript:backPage(document.$formname,'pickrole','')",
1.351 raeburn 4452: text => "Pick custom role",
4453: faq => 282,bug=>'Instructor Interface',},
1.406.2.5 raeburn 4454: {href => "javascript:backPage(document.$formname,'','')",
1.351 raeburn 4455: text => "Edit custom role",
4456: faq => 282,
4457: bug => 'Instructor Interface',
1.406.2.14 raeburn 4458: help => $helpitem}
1.351 raeburn 4459: );
4460: my $args = { bread_crumbs => $brcrum,
4461: bread_crumbs_component => 'User Management'};
4462: $r->print(&Apache::loncommon::start_page('Custom Role Editor',
4463: $head_script,$args).
4464: $body_top);
1.406.2.5 raeburn 4465: $r->print('<form name="'.$formname.'" method="post" action="">'."\n".
4466: &Apache::lonuserutils::custom_role_header($context,$crstype,
4467: \@templateroles,$prefix));
1.264 bisitz 4468:
1.61 www 4469: $r->print(<<ENDCCF);
4470: <input type="hidden" name="phase" value="set_custom_roles" />
4471: <input type="hidden" name="rolename" value="$rolename" />
4472: ENDCCF
1.406.2.5 raeburn 4473: $r->print(&Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
4474: \%levelscurrent,$prefix));
1.135 raeburn 4475: $r->print(&Apache::loncommon::end_data_table().
1.190 raeburn 4476: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'.
1.160 raeburn 4477: '<input type="hidden" name="startrolename" value="'.$env{'form.rolename'}.
1.406.2.5 raeburn 4478: '" />'."\n".'<input type="hidden" name="currstate" value="" />'."\n".
1.160 raeburn 4479: '<input type="reset" value="'.&mt("Reset").'" />'."\n".
1.351 raeburn 4480: '<input type="submit" value="'.&mt('Save').'" /></form>');
1.61 www 4481: }
1.406.2.5 raeburn 4482:
1.61 www 4483: # ---------------------------------------------------------- Call to definerole
4484: sub set_custom_role {
1.406.2.14 raeburn 4485: my ($r,$context,$brcrum,$prefix,$permission) = @_;
1.101 albertel 4486: my $rolename=$env{'form.rolename'};
1.63 www 4487: $rolename=~s/[^A-Za-z0-9]//gs;
1.150 banghart 4488: if (!$rolename) {
1.406.2.14 raeburn 4489: &custom_role_editor($r,$context,$brcrum,$prefix,$permission);
1.61 www 4490: return;
4491: }
1.160 raeburn 4492: my ($jsback,$elements) = &crumb_utilities();
1.301 bisitz 4493: my $jscript = '<script type="text/javascript">'
4494: .'// <![CDATA['."\n"
4495: .$jsback."\n"
4496: .'// ]]>'."\n"
4497: .'</script>'."\n";
1.406.2.14 raeburn 4498: my $helpitem = 'Course_Editing_Custom_Roles';
4499: if ($context eq 'domain') {
4500: $helpitem = 'Domain_Editing_Custom_Roles';
4501: }
1.352 raeburn 4502: push(@{$brcrum},
4503: {href => "javascript:backPage(document.customresult,'pickrole','')",
4504: text => "Pick custom role",
4505: faq => 282,
4506: bug => 'Instructor Interface',},
4507: {href => "javascript:backPage(document.customresult,'selected_custom_edit','')",
4508: text => "Edit custom role",
4509: faq => 282,
4510: bug => 'Instructor Interface',},
4511: {href => "javascript:backPage(document.customresult,'set_custom_roles','')",
4512: text => "Result",
4513: faq => 282,
4514: bug => 'Instructor Interface',
1.406.2.14 raeburn 4515: help => $helpitem,}
1.352 raeburn 4516: );
4517: my $args = { bread_crumbs => $brcrum,
1.406.2.5 raeburn 4518: bread_crumbs_component => 'User Management'};
1.351 raeburn 4519: $r->print(&Apache::loncommon::start_page('Save Custom Role',$jscript,$args));
1.160 raeburn 4520:
1.393 raeburn 4521: my $newrole;
1.61 www 4522: my ($rdummy,$roledef)=
1.110 albertel 4523: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
4524:
1.61 www 4525: # ------------------------------------------------------- Does this role exist?
1.188 raeburn 4526: $r->print('<h3>');
1.61 www 4527: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1.73 sakharuk 4528: $r->print(&mt('Existing Role').' "');
1.61 www 4529: } else {
1.73 sakharuk 4530: $r->print(&mt('New Role').' "');
1.61 www 4531: $roledef='';
1.393 raeburn 4532: $newrole = 1;
1.61 www 4533: }
1.188 raeburn 4534: $r->print($rolename.'"</h3>');
1.406.2.5 raeburn 4535: # ------------------------------------------------- Assign role and show result
1.61 www 4536:
1.387 bisitz 4537: my $errmsg;
1.406.2.5 raeburn 4538: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$prefix);
4539: # Assign role and return result
4540: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
4541: $newprivs{'c'});
1.387 bisitz 4542: if ($result ne 'ok') {
4543: $errmsg = ': '.$result;
4544: }
4545: my $message =
4546: &Apache::lonhtmlcommon::confirm_success(
4547: &mt('Defining Role').$errmsg, ($result eq 'ok' ? 0 : 1));
1.101 albertel 4548: if ($env{'request.course.id'}) {
4549: my $url='/'.$env{'request.course.id'};
1.63 www 4550: $url=~s/\_/\//g;
1.387 bisitz 4551: $result =
4552: &Apache::lonnet::assigncustomrole(
4553: $env{'user.domain'},$env{'user.name'},
4554: $url,
4555: $env{'user.domain'},$env{'user.name'},
4556: $rolename,undef,undef,undef,$context);
4557: if ($result ne 'ok') {
4558: $errmsg = ': '.$result;
4559: }
4560: $message .=
4561: '<br />'
4562: .&Apache::lonhtmlcommon::confirm_success(
4563: &mt('Assigning Role to Self').$errmsg, ($result eq 'ok' ? 0 : 1));
1.63 www 4564: }
1.380 bisitz 4565: $r->print(
1.387 bisitz 4566: &Apache::loncommon::confirmwrapper($message)
4567: .'<br />'
4568: .&Apache::lonhtmlcommon::actionbox([
4569: '<a href="javascript:backPage(document.customresult,'."'pickrole'".')">'
4570: .&mt('Create or edit another custom role')
4571: .'</a>'])
1.380 bisitz 4572: .'<form name="customresult" method="post" action="">'
1.387 bisitz 4573: .&Apache::lonhtmlcommon::echo_form_input([])
4574: .'</form>'
1.380 bisitz 4575: );
1.58 www 4576: }
4577:
1.2 www 4578: # ================================================================ Main Handler
4579: sub handler {
4580: my $r = shift;
4581: if ($r->header_only) {
1.68 www 4582: &Apache::loncommon::content_type($r,'text/html');
1.2 www 4583: $r->send_http_header;
4584: return OK;
4585: }
1.406.2.14 raeburn 4586: my ($context,$crstype,$cid,$cnum,$cdom,$allhelpitems);
4587:
1.190 raeburn 4588: if ($env{'request.course.id'}) {
4589: $context = 'course';
1.318 raeburn 4590: $crstype = &Apache::loncommon::course_type();
1.190 raeburn 4591: } elsif ($env{'request.role'} =~ /^au\./) {
1.206 raeburn 4592: $context = 'author';
1.190 raeburn 4593: } else {
4594: $context = 'domain';
4595: }
1.375 raeburn 4596:
1.406.2.14 raeburn 4597: my ($permission,$allowed) =
4598: &Apache::lonuserutils::get_permission($context,$crstype);
4599:
4600: if ($allowed) {
4601: my @allhelp;
4602: if ($context eq 'course') {
4603: $cid = $env{'request.course.id'};
4604: $cdom = $env{'course.'.$cid.'.domain'};
4605: $cnum = $env{'course.'.$cid.'.num'};
4606:
4607: if ($permission->{'cusr'}) {
4608: push(@allhelp,'Course_Create_Class_List');
4609: }
4610: if ($permission->{'view'} || $permission->{'cusr'}) {
4611: push(@allhelp,('Course_Change_Privileges','Course_View_Class_List'));
4612: }
4613: if ($permission->{'custom'}) {
4614: push(@allhelp,'Course_Editing_Custom_Roles');
4615: }
4616: if ($permission->{'cusr'}) {
4617: push(@allhelp,('Course_Add_Student','Course_Drop_Student'));
4618: }
4619: unless ($permission->{'cusr_section'}) {
4620: if (&Apache::lonnet::auto_run($cnum,$cdom) && (($permission->{'cusr'}) || ($permission->{'view'}))) {
4621: push(@allhelp,'Course_Automated_Enrollment');
4622: }
4623: if ($permission->{'selfenrolladmin'}) {
4624: push(@allhelp,'Course_Approve_Selfenroll');
4625: }
4626: }
4627: if ($permission->{'grp_manage'}) {
4628: push(@allhelp,'Course_Manage_Group');
4629: }
4630: if ($permission->{'view'} || $permission->{'cusr'}) {
4631: push(@allhelp,'Course_User_Logs');
4632: }
4633: } elsif ($context eq 'author') {
4634: push(@allhelp,('Author_Change_Privileges','Author_Create_Coauthor_List',
4635: 'Author_View_Coauthor_List','Author_User_Logs'));
4636: } else {
4637: if ($permission->{'cusr'}) {
4638: push(@allhelp,'Domain_Change_Privileges');
4639: if ($permission->{'activity'}) {
4640: push(@allhelp,'Domain_User_Access_Logs');
4641: }
4642: push(@allhelp,('Domain_Create_Users','Domain_View_Users_List'));
4643: if ($permission->{'custom'}) {
4644: push(@allhelp,'Domain_Editing_Custom_Roles');
4645: }
4646: push(@allhelp,('Domain_Role_Approvals','Domain_Username_Approvals','Domain_Change_Logs'));
4647: } elsif ($permission->{'view'}) {
4648: push(@allhelp,'Domain_View_Privileges');
4649: if ($permission->{'activity'}) {
4650: push(@allhelp,'Domain_User_Access_Logs');
4651: }
4652: push(@allhelp,('Domain_View_Users_List','Domain_Change_Logs'));
4653: }
4654: }
4655: if (@allhelp) {
4656: $allhelpitems = join(',',@allhelp);
4657: }
4658: }
4659:
1.190 raeburn 4660: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.233 raeburn 4661: ['action','state','callingform','roletype','showrole','bulkaction','popup','phase',
1.391 raeburn 4662: 'username','domain','srchterm','srchdomain','srchin','srchby','srchtype','queue']);
1.190 raeburn 4663: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.351 raeburn 4664: my $args;
4665: my $brcrum = [];
4666: my $bread_crumbs_component = 'User Management';
1.391 raeburn 4667: if (($env{'form.action'} ne 'dateselect') && ($env{'form.action'} ne 'displayuserreq')) {
1.351 raeburn 4668: $brcrum = [{href=>"/adm/createuser",
4669: text=>"User Management",
1.406.2.14 raeburn 4670: help=>$allhelpitems}
1.351 raeburn 4671: ];
1.202 raeburn 4672: }
1.190 raeburn 4673: if (!$allowed) {
1.358 raeburn 4674: if ($context eq 'course') {
4675: $r->internal_redirect('/adm/viewclasslist');
4676: return OK;
4677: }
1.190 raeburn 4678: $env{'user.error.msg'}=
4679: "/adm/createuser:cst:0:0:Cannot create/modify user data ".
4680: "or view user status.";
4681: return HTTP_NOT_ACCEPTABLE;
4682: }
4683:
4684: &Apache::loncommon::content_type($r,'text/html');
4685: $r->send_http_header;
4686:
1.375 raeburn 4687: my $showcredits;
4688: if ((($context eq 'course') && ($crstype eq 'Course')) ||
4689: ($context eq 'domain')) {
4690: my %domdefaults =
4691: &Apache::lonnet::get_domain_defaults($env{'request.role.domain'});
4692: if ($domdefaults{'officialcredits'} || $domdefaults{'unofficialcredits'}) {
4693: $showcredits = 1;
4694: }
4695: }
4696:
1.190 raeburn 4697: # Main switch on form.action and form.state, as appropriate
4698: if (! exists($env{'form.action'})) {
1.351 raeburn 4699: $args = {bread_crumbs => $brcrum,
4700: bread_crumbs_component => $bread_crumbs_component};
4701: $r->print(&header(undef,$args));
1.318 raeburn 4702: $r->print(&print_main_menu($permission,$context,$crstype));
1.190 raeburn 4703: } elsif ($env{'form.action'} eq 'upload' && $permission->{'cusr'}) {
1.406.2.14 raeburn 4704: my $helpitem = 'Course_Create_Class_List';
4705: if ($context eq 'author') {
4706: $helpitem = 'Author_Create_Coauthor_List';
4707: } elsif ($context eq 'domain') {
4708: $helpitem = 'Domain_Create_Users';
4709: }
1.351 raeburn 4710: push(@{$brcrum},
4711: { href => '/adm/createuser?action=upload&state=',
4712: text => 'Upload Users List',
1.406.2.14 raeburn 4713: help => $helpitem,
1.351 raeburn 4714: });
4715: $bread_crumbs_component = 'Upload Users List';
4716: $args = {bread_crumbs => $brcrum,
4717: bread_crumbs_component => $bread_crumbs_component};
4718: $r->print(&header(undef,$args));
1.190 raeburn 4719: $r->print('<form name="studentform" method="post" '.
4720: 'enctype="multipart/form-data" '.
4721: ' action="/adm/createuser">'."\n");
4722: if (! exists($env{'form.state'})) {
4723: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
4724: } elsif ($env{'form.state'} eq 'got_file') {
1.406.2.15 raeburn 4725: my $result =
4726: &Apache::lonuserutils::print_upload_manager_form($r,$context,
4727: $permission,
4728: $crstype,$showcredits);
4729: if ($result eq 'missingdata') {
4730: delete($env{'form.state'});
4731: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
4732: }
1.190 raeburn 4733: } elsif ($env{'form.state'} eq 'enrolling') {
4734: if ($env{'form.datatoken'}) {
1.406.2.15 raeburn 4735: my $result = &Apache::lonuserutils::upfile_drop_add($r,$context,
4736: $permission,
4737: $showcredits);
4738: if ($result eq 'missingdata') {
4739: delete($env{'form.state'});
4740: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
4741: } elsif ($result eq 'invalidhome') {
4742: $env{'form.state'} = 'got_file';
4743: delete($env{'form.lcserver'});
4744: my $result =
4745: &Apache::lonuserutils::print_upload_manager_form($r,$context,$permission,
4746: $crstype,$showcredits);
4747: if ($result eq 'missingdata') {
4748: delete($env{'form.state'});
4749: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
4750: }
4751: }
4752: } else {
4753: delete($env{'form.state'});
4754: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
1.190 raeburn 4755: }
4756: } else {
4757: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
4758: }
1.406.2.15 raeburn 4759: $r->print('</form>');
1.406.2.5 raeburn 4760: } elsif (((($env{'form.action'} eq 'singleuser') || ($env{'form.action'}
4761: eq 'singlestudent')) && ($permission->{'cusr'})) ||
1.406.2.6 raeburn 4762: (($env{'form.action'} eq 'singleuser') && ($permission->{'view'})) ||
1.406.2.5 raeburn 4763: (($env{'form.action'} eq 'accesslogs') && ($permission->{'activity'}))) {
1.190 raeburn 4764: my $phase = $env{'form.phase'};
4765: my @search = ('srchterm','srchby','srchin','srchtype','srchdomain');
1.192 albertel 4766: &Apache::loncreateuser::restore_prev_selections();
4767: my $srch;
4768: foreach my $item (@search) {
4769: $srch->{$item} = $env{'form.'.$item};
4770: }
1.207 raeburn 4771: if (($phase eq 'get_user_info') || ($phase eq 'userpicked') ||
1.406.2.5 raeburn 4772: ($phase eq 'createnewuser') || ($phase eq 'activity')) {
1.207 raeburn 4773: if ($env{'form.phase'} eq 'createnewuser') {
4774: my $response;
4775: if ($env{'form.srchterm'} !~ /^$match_username$/) {
1.366 bisitz 4776: my $response =
4777: '<span class="LC_warning">'
4778: .&mt('You must specify a valid username. Only the following are allowed:'
4779: .' letters numbers - . @')
4780: .'</span>';
1.221 raeburn 4781: $env{'form.phase'} = '';
1.375 raeburn 4782: &print_username_entry_form($r,$context,$response,$srch,undef,
1.406.2.14 raeburn 4783: $crstype,$brcrum,$permission);
1.207 raeburn 4784: } else {
4785: my $ccuname =&LONCAPA::clean_username($srch->{'srchterm'});
4786: my $ccdomain=&LONCAPA::clean_domain($srch->{'srchdomain'});
4787: &print_user_modification_page($r,$ccuname,$ccdomain,
1.221 raeburn 4788: $srch,$response,$context,
1.375 raeburn 4789: $permission,$crstype,$brcrum,
4790: $showcredits);
1.207 raeburn 4791: }
4792: } elsif ($env{'form.phase'} eq 'get_user_info') {
1.190 raeburn 4793: my ($currstate,$response,$forcenewuser,$results) =
1.221 raeburn 4794: &user_search_result($context,$srch);
1.190 raeburn 4795: if ($env{'form.currstate'} eq 'modify') {
4796: $currstate = $env{'form.currstate'};
4797: }
4798: if ($currstate eq 'select') {
4799: &print_user_selection_page($r,$response,$srch,$results,
1.351 raeburn 4800: \@search,$context,undef,$crstype,
4801: $brcrum);
1.406.2.5 raeburn 4802: } elsif (($currstate eq 'modify') || ($env{'form.action'} eq 'accesslogs')) {
4803: my ($ccuname,$ccdomain,$uhome);
1.190 raeburn 4804: if (($srch->{'srchby'} eq 'uname') &&
4805: ($srch->{'srchtype'} eq 'exact')) {
4806: $ccuname = $srch->{'srchterm'};
4807: $ccdomain= $srch->{'srchdomain'};
4808: } else {
4809: my @matchedunames = keys(%{$results});
4810: ($ccuname,$ccdomain) = split(/:/,$matchedunames[0]);
4811: }
4812: $ccuname =&LONCAPA::clean_username($ccuname);
4813: $ccdomain=&LONCAPA::clean_domain($ccdomain);
1.406.2.5 raeburn 4814: if ($env{'form.action'} eq 'accesslogs') {
4815: my $uhome;
4816: if (($ccuname ne '') && ($ccdomain ne '')) {
4817: $uhome = &Apache::lonnet::homeserver($ccuname,$ccdomain);
4818: }
4819: if (($uhome eq '') || ($uhome eq 'no_host')) {
4820: $env{'form.phase'} = '';
4821: undef($forcenewuser);
4822: #if ($response) {
4823: # unless ($response =~ m{\Q<br /><br />\E$}) {
4824: # $response .= '<br /><br />';
4825: # }
4826: #}
4827: &print_username_entry_form($r,$context,$response,$srch,
1.406.2.14 raeburn 4828: $forcenewuser,$crstype,$brcrum,
4829: $permission);
1.406.2.5 raeburn 4830: } else {
4831: &print_useraccesslogs_display($r,$ccuname,$ccdomain,$permission,$brcrum);
4832: }
4833: } else {
4834: if ($env{'form.forcenewuser'}) {
4835: $response = '';
4836: }
4837: &print_user_modification_page($r,$ccuname,$ccdomain,
4838: $srch,$response,$context,
4839: $permission,$crstype,$brcrum);
1.190 raeburn 4840: }
4841: } elsif ($currstate eq 'query') {
1.351 raeburn 4842: &print_user_query_page($r,'createuser',$brcrum);
1.190 raeburn 4843: } else {
1.229 raeburn 4844: $env{'form.phase'} = '';
1.207 raeburn 4845: &print_username_entry_form($r,$context,$response,$srch,
1.406.2.14 raeburn 4846: $forcenewuser,$crstype,$brcrum,
4847: $permission);
1.190 raeburn 4848: }
4849: } elsif ($env{'form.phase'} eq 'userpicked') {
4850: my $ccuname = &LONCAPA::clean_username($env{'form.seluname'});
4851: my $ccdomain = &LONCAPA::clean_domain($env{'form.seludom'});
1.406.2.5 raeburn 4852: if ($env{'form.action'} eq 'accesslogs') {
4853: &print_useraccesslogs_display($r,$ccuname,$ccdomain,$permission,$brcrum);
4854: } else {
4855: &print_user_modification_page($r,$ccuname,$ccdomain,$srch,'',
4856: $context,$permission,$crstype,
4857: $brcrum);
4858: }
4859: } elsif ($env{'form.action'} eq 'accesslogs') {
4860: my $ccuname = &LONCAPA::clean_username($env{'form.accessuname'});
4861: my $ccdomain = &LONCAPA::clean_domain($env{'form.accessudom'});
4862: &print_useraccesslogs_display($r,$ccuname,$ccdomain,$permission,$brcrum);
1.190 raeburn 4863: }
4864: } elsif ($env{'form.phase'} eq 'update_user_data') {
1.375 raeburn 4865: &update_user_data($r,$context,$crstype,$brcrum,$showcredits);
1.190 raeburn 4866: } else {
1.351 raeburn 4867: &print_username_entry_form($r,$context,undef,$srch,undef,$crstype,
1.406.2.14 raeburn 4868: $brcrum,$permission);
1.190 raeburn 4869: }
4870: } elsif ($env{'form.action'} eq 'custom' && $permission->{'custom'}) {
1.406.2.5 raeburn 4871: my $prefix;
1.190 raeburn 4872: if ($env{'form.phase'} eq 'set_custom_roles') {
1.406.2.14 raeburn 4873: &set_custom_role($r,$context,$brcrum,$prefix,$permission);
1.190 raeburn 4874: } else {
1.406.2.14 raeburn 4875: &custom_role_editor($r,$context,$brcrum,$prefix,$permission);
1.190 raeburn 4876: }
1.362 raeburn 4877: } elsif (($env{'form.action'} eq 'processauthorreq') &&
4878: ($permission->{'cusr'}) &&
4879: (&Apache::lonnet::allowed('cau',$env{'request.role.domain'}))) {
4880: push(@{$brcrum},
4881: {href => '/adm/createuser?action=processauthorreq',
1.385 bisitz 4882: text => 'Authoring Space requests',
1.362 raeburn 4883: help => 'Domain_Role_Approvals'});
4884: $bread_crumbs_component = 'Authoring requests';
4885: if ($env{'form.state'} eq 'done') {
4886: push(@{$brcrum},
4887: {href => '/adm/createuser?action=authorreqqueue',
4888: text => 'Result',
4889: help => 'Domain_Role_Approvals'});
4890: $bread_crumbs_component = 'Authoring request result';
4891: }
4892: $args = { bread_crumbs => $brcrum,
4893: bread_crumbs_component => $bread_crumbs_component};
1.391 raeburn 4894: my $js = &usernamerequest_javascript();
4895: $r->print(&header(&add_script($js),$args));
1.362 raeburn 4896: if (!exists($env{'form.state'})) {
4897: $r->print(&Apache::loncoursequeueadmin::display_queued_requests('requestauthor',
4898: $env{'request.role.domain'}));
4899: } elsif ($env{'form.state'} eq 'done') {
4900: $r->print('<h3>'.&mt('Authoring request processing').'</h3>'."\n");
4901: $r->print(&Apache::loncoursequeueadmin::update_request_queue('requestauthor',
4902: $env{'request.role.domain'}));
4903: }
1.391 raeburn 4904: } elsif (($env{'form.action'} eq 'processusernamereq') &&
4905: ($permission->{'cusr'}) &&
4906: (&Apache::lonnet::allowed('cau',$env{'request.role.domain'}))) {
4907: push(@{$brcrum},
4908: {href => '/adm/createuser?action=processusernamereq',
4909: text => 'LON-CAPA account requests',
4910: help => 'Domain_Username_Approvals'});
4911: $bread_crumbs_component = 'Account requests';
4912: if ($env{'form.state'} eq 'done') {
4913: push(@{$brcrum},
4914: {href => '/adm/createuser?action=usernamereqqueue',
4915: text => 'Result',
4916: help => 'Domain_Username_Approvals'});
4917: $bread_crumbs_component = 'LON-CAPA account request result';
4918: }
4919: $args = { bread_crumbs => $brcrum,
4920: bread_crumbs_component => $bread_crumbs_component};
4921: my $js = &usernamerequest_javascript();
4922: $r->print(&header(&add_script($js),$args));
4923: if (!exists($env{'form.state'})) {
4924: $r->print(&Apache::loncoursequeueadmin::display_queued_requests('requestusername',
4925: $env{'request.role.domain'}));
4926: } elsif ($env{'form.state'} eq 'done') {
4927: $r->print('<h3>'.&mt('LON-CAPA account request processing').'</h3>'."\n");
4928: $r->print(&Apache::loncoursequeueadmin::update_request_queue('requestusername',
4929: $env{'request.role.domain'}));
4930: }
4931: } elsif (($env{'form.action'} eq 'displayuserreq') &&
4932: ($permission->{'cusr'})) {
4933: my $dom = $env{'form.domain'};
4934: my $uname = $env{'form.username'};
4935: my $warning;
4936: if (($dom =~ /^$match_domain$/) && (&Apache::lonnet::domain($dom) ne '')) {
4937: if (($dom eq $env{'request.role.domain'}) && (&Apache::lonnet::allowed('ccc',$dom))) {
4938: if (($uname =~ /^$match_username$/) && ($env{'form.queue'} eq 'approval')) {
4939: my $uhome = &Apache::lonnet::homeserver($uname,$dom);
4940: if ($uhome eq 'no_host') {
4941: my $queue = $env{'form.queue'};
4942: my $reqkey = &escape($uname).'_'.$queue;
4943: my $namespace = 'usernamequeue';
4944: my $domconfig = &Apache::lonnet::get_domainconfiguser($dom);
4945: my %queued =
4946: &Apache::lonnet::get($namespace,[$reqkey],$dom,$domconfig);
4947: unless ($queued{$reqkey}) {
4948: $warning = &mt('No information was found for this LON-CAPA account request.');
4949: }
4950: } else {
4951: $warning = &mt('A LON-CAPA account already exists for the requested username and domain.');
4952: }
4953: } else {
4954: $warning = &mt('LON-CAPA account request status check is for an invalid username.');
4955: }
4956: } else {
4957: $warning = &mt('You do not have rights to view LON-CAPA account requests in the domain specified.');
4958: }
4959: } else {
4960: $warning = &mt('LON-CAPA account request status check is for an invalid domain.');
4961: }
4962: my $args = { only_body => 1 };
4963: $r->print(&header(undef,$args).
4964: '<h3>'.&mt('LON-CAPA Account Request Details').'</h3>');
4965: if ($warning ne '') {
4966: $r->print('<div class="LC_warning">'.$warning.'</div>');
4967: } else {
4968: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
4969: my $domconfiguser = &Apache::lonnet::get_domainconfiguser($dom);
4970: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
4971: if (ref($domconfig{'usercreation'}) eq 'HASH') {
4972: if (ref($domconfig{'usercreation'}{'cancreate'}) eq 'HASH') {
4973: if (ref($domconfig{'usercreation'}{'cancreate'}{'emailusername'}) eq 'HASH') {
4974: my %info =
4975: &Apache::lonnet::get('nohist_requestedusernames',[$uname],$dom,$domconfiguser);
4976: if (ref($info{$uname}) eq 'HASH') {
1.396 raeburn 4977: my $usertype = $info{$uname}{'inststatus'};
4978: unless ($usertype) {
4979: $usertype = 'default';
4980: }
1.406.2.16! raeburn 4981: my ($showstatus,$showemail,$pickstart);
! 4982: my $numextras = 0;
! 4983: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
! 4984: if ((ref($types) eq 'ARRAY') && (@{$types} > 0)) {
! 4985: if (ref($usertypes) eq 'HASH') {
! 4986: if ($usertypes->{$usertype}) {
! 4987: $showstatus = $usertypes->{$usertype};
! 4988: } else {
! 4989: $showstatus = $othertitle;
! 4990: }
! 4991: if ($showstatus) {
! 4992: $numextras ++;
! 4993: }
! 4994: }
! 4995: }
! 4996: if (($info{$uname}{'email'} ne '') && ($info{$uname}{'email'} ne $uname)) {
! 4997: $showemail = $info{$uname}{'email'};
! 4998: $numextras ++;
! 4999: }
1.396 raeburn 5000: if (ref($domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}) eq 'HASH') {
5001: if ((ref($infofields) eq 'ARRAY') && (ref($infotitles) eq 'HASH')) {
1.406.2.16! raeburn 5002: $pickstart = 1;
1.396 raeburn 5003: $r->print('<div>'.&Apache::lonhtmlcommon::start_pick_box());
1.406.2.16! raeburn 5004: my ($num,$count);
1.396 raeburn 5005: $count = scalar(keys(%{$domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}}));
1.406.2.16! raeburn 5006: $count += $numextras;
1.396 raeburn 5007: foreach my $field (@{$infofields}) {
5008: next unless ($domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}{$field});
5009: next unless ($infotitles->{$field});
5010: $r->print(&Apache::lonhtmlcommon::row_title($infotitles->{$field}).
5011: $info{$uname}{$field});
5012: $num ++;
1.406.2.16! raeburn 5013: unless ($count == $num) {
1.396 raeburn 5014: $r->print(&Apache::lonhtmlcommon::row_closure());
5015: }
5016: }
1.406.2.16! raeburn 5017: }
! 5018: }
! 5019: if ($numextras) {
! 5020: unless ($pickstart) {
! 5021: $r->print('<div>'.&Apache::lonhtmlcommon::start_pick_box());
! 5022: $pickstart = 1;
! 5023: }
! 5024: if ($showemail) {
! 5025: my $closure = '';
! 5026: unless ($showstatus) {
! 5027: $closure = 1;
1.391 raeburn 5028: }
1.406.2.16! raeburn 5029: $r->print(&Apache::lonhtmlcommon::row_title(&mt('E-mail address')).
! 5030: $showemail.
! 5031: &Apache::lonhtmlcommon::row_closure($closure));
! 5032: }
! 5033: if ($showstatus) {
! 5034: $r->print(&Apache::lonhtmlcommon::row_title(&mt('Status type[_1](self-reported)','<br />')).
! 5035: $showstatus.
! 5036: &Apache::lonhtmlcommon::row_closure(1));
1.391 raeburn 5037: }
5038: }
1.406.2.16! raeburn 5039: if ($pickstart) {
! 5040: $r->print(&Apache::lonhtmlcommon::end_pick_box().'</div>');
! 5041: } else {
! 5042: $r->print('<div>'.&mt('No information to display for this account request.').'</div>');
! 5043: }
! 5044: } else {
! 5045: $r->print('<div>'.&mt('No information available for this account request.').'</div>');
1.391 raeburn 5046: }
5047: }
5048: }
5049: }
5050: }
1.406.2.16! raeburn 5051: $r->print(&close_popup_form());
1.207 raeburn 5052: } elsif (($env{'form.action'} eq 'listusers') &&
5053: ($permission->{'view'} || $permission->{'cusr'})) {
1.406.2.14 raeburn 5054: my $helpitem = 'Course_View_Class_List';
5055: if ($context eq 'author') {
5056: $helpitem = 'Author_View_Coauthor_List';
5057: } elsif ($context eq 'domain') {
5058: $helpitem = 'Domain_View_Users_List';
5059: }
1.202 raeburn 5060: if ($env{'form.phase'} eq 'bulkchange') {
1.351 raeburn 5061: push(@{$brcrum},
5062: {href => '/adm/createuser?action=listusers',
5063: text => "List Users"},
5064: {href => "/adm/createuser",
5065: text => "Result",
1.406.2.14 raeburn 5066: help => $helpitem});
1.351 raeburn 5067: $bread_crumbs_component = 'Update Users';
5068: $args = {bread_crumbs => $brcrum,
5069: bread_crumbs_component => $bread_crumbs_component};
5070: $r->print(&header(undef,$args));
1.202 raeburn 5071: my $setting = $env{'form.roletype'};
5072: my $choice = $env{'form.bulkaction'};
5073: if ($permission->{'cusr'}) {
1.336 raeburn 5074: &Apache::lonuserutils::update_user_list($r,$context,$setting,$choice,$crstype);
1.221 raeburn 5075: } else {
5076: $r->print(&mt('You are not authorized to make bulk changes to user roles'));
1.223 raeburn 5077: $r->print('<p><a href="/adm/createuser?action=listusers">'.&mt('Display User Lists').'</a>');
1.202 raeburn 5078: }
5079: } else {
1.351 raeburn 5080: push(@{$brcrum},
5081: {href => '/adm/createuser?action=listusers',
5082: text => "List Users",
1.406.2.14 raeburn 5083: help => $helpitem});
1.351 raeburn 5084: $bread_crumbs_component = 'List Users';
5085: $args = {bread_crumbs => $brcrum,
5086: bread_crumbs_component => $bread_crumbs_component};
1.202 raeburn 5087: my ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles);
5088: my $formname = 'studentform';
1.364 raeburn 5089: my $hidecall = "hide_searching();";
1.321 raeburn 5090: if (($context eq 'domain') && (($env{'form.roletype'} eq 'course') ||
5091: ($env{'form.roletype'} eq 'community'))) {
5092: if ($env{'form.roletype'} eq 'course') {
5093: ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles) =
5094: &Apache::lonuserutils::courses_selector($env{'request.role.domain'},
5095: $formname);
5096: } elsif ($env{'form.roletype'} eq 'community') {
5097: $cb_jscript =
5098: &Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
5099: my %elements = (
5100: coursepick => 'radio',
5101: coursetotal => 'text',
5102: courselist => 'text',
5103: );
5104: $jscript = &Apache::lonhtmlcommon::set_form_elements(\%elements);
5105: }
1.364 raeburn 5106: $jscript .= &verify_user_display($context)."\n".
5107: &Apache::loncommon::check_uncheck_jscript();
1.202 raeburn 5108: my $js = &add_script($jscript).$cb_jscript;
5109: my $loadcode =
5110: &Apache::lonuserutils::course_selector_loadcode($formname);
5111: if ($loadcode ne '') {
1.364 raeburn 5112: $args->{add_entries} = {onload => "$loadcode;$hidecall"};
5113: } else {
5114: $args->{add_entries} = {onload => $hidecall};
1.202 raeburn 5115: }
1.351 raeburn 5116: $r->print(&header($js,$args));
1.191 raeburn 5117: } else {
1.364 raeburn 5118: $args->{add_entries} = {onload => $hidecall};
5119: $jscript = &verify_user_display($context).
5120: &Apache::loncommon::check_uncheck_jscript();
5121: $r->print(&header(&add_script($jscript),$args));
1.191 raeburn 5122: }
1.202 raeburn 5123: &Apache::lonuserutils::print_userlist($r,undef,$permission,$context,
1.375 raeburn 5124: $formname,$totcodes,$codetitles,$idlist,$idlist_titles,
5125: $showcredits);
1.191 raeburn 5126: }
1.213 raeburn 5127: } elsif ($env{'form.action'} eq 'drop' && $permission->{'cusr'}) {
1.318 raeburn 5128: my $brtext;
5129: if ($crstype eq 'Community') {
5130: $brtext = 'Drop Members';
5131: } else {
5132: $brtext = 'Drop Students';
5133: }
1.351 raeburn 5134: push(@{$brcrum},
5135: {href => '/adm/createuser?action=drop',
5136: text => $brtext,
5137: help => 'Course_Drop_Student'});
5138: if ($env{'form.state'} eq 'done') {
5139: push(@{$brcrum},
5140: {href=>'/adm/createuser?action=drop',
5141: text=>"Result"});
5142: }
5143: $bread_crumbs_component = $brtext;
5144: $args = {bread_crumbs => $brcrum,
5145: bread_crumbs_component => $bread_crumbs_component};
5146: $r->print(&header(undef,$args));
1.213 raeburn 5147: if (!exists($env{'form.state'})) {
1.318 raeburn 5148: &Apache::lonuserutils::print_drop_menu($r,$context,$permission,$crstype);
1.213 raeburn 5149: } elsif ($env{'form.state'} eq 'done') {
5150: &Apache::lonuserutils::update_user_list($r,$context,undef,
5151: $env{'form.action'});
5152: }
1.202 raeburn 5153: } elsif ($env{'form.action'} eq 'dateselect') {
5154: if ($permission->{'cusr'}) {
1.351 raeburn 5155: $r->print(&header(undef,{'no_nav_bar' => 1}).
1.375 raeburn 5156: &Apache::lonuserutils::date_section_selector($context,$permission,
5157: $crstype,$showcredits));
1.202 raeburn 5158: } else {
1.351 raeburn 5159: $r->print(&header(undef,{'no_nav_bar' => 1}).
5160: '<span class="LC_error">'.&mt('You do not have permission to modify dates or sections for users').'</span>');
1.202 raeburn 5161: }
1.237 raeburn 5162: } elsif ($env{'form.action'} eq 'selfenroll') {
1.398 raeburn 5163: if ($permission->{selfenrolladmin}) {
5164: my %currsettings = (
5165: selfenroll_types => $env{'course.'.$cid.'.internal.selfenroll_types'},
5166: selfenroll_registered => $env{'course.'.$cid.'.internal.selfenroll_registered'},
5167: selfenroll_section => $env{'course.'.$cid.'.internal.selfenroll_section'},
5168: selfenroll_notifylist => $env{'course.'.$cid.'.internal.selfenroll_notifylist'},
5169: selfenroll_approval => $env{'course.'.$cid.'.internal.selfenroll_approval'},
5170: selfenroll_limit => $env{'course.'.$cid.'.internal.selfenroll_limit'},
5171: selfenroll_cap => $env{'course.'.$cid.'.internal.selfenroll_cap'},
5172: selfenroll_start_date => $env{'course.'.$cid.'.internal.selfenroll_start_date'},
5173: selfenroll_end_date => $env{'course.'.$cid.'.internal.selfenroll_end_date'},
5174: selfenroll_start_access => $env{'course.'.$cid.'.internal.selfenroll_start_access'},
5175: selfenroll_end_access => $env{'course.'.$cid.'.internal.selfenroll_end_access'},
5176: default_enrollment_start_date => $env{'course.'.$cid.'.default_enrollment_start_date'},
5177: default_enrollment_end_date => $env{'course.'.$cid.'.default_enrollment_end_date'},
1.400 raeburn 5178: uniquecode => $env{'course.'.$cid.'.internal.uniquecode'},
1.398 raeburn 5179: );
5180: push(@{$brcrum},
5181: {href => '/adm/createuser?action=selfenroll',
5182: text => "Configure Self-enrollment",
5183: help => 'Course_Self_Enrollment'});
5184: if (!exists($env{'form.state'})) {
5185: $args = { bread_crumbs => $brcrum,
5186: bread_crumbs_component => 'Configure Self-enrollment'};
5187: $r->print(&header(undef,$args));
5188: $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n");
5189: &print_selfenroll_menu($r,'course',$cid,$cdom,$cnum,\%currsettings);
5190: } elsif ($env{'form.state'} eq 'done') {
5191: push (@{$brcrum},
5192: {href=>'/adm/createuser?action=selfenroll',
5193: text=>"Result"});
5194: $args = { bread_crumbs => $brcrum,
5195: bread_crumbs_component => 'Self-enrollment result'};
5196: $r->print(&header(undef,$args));
5197: $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n");
1.400 raeburn 5198: &update_selfenroll_config($r,$cid,$cdom,$cnum,$context,$crstype,\%currsettings);
1.398 raeburn 5199: }
5200: } else {
5201: $r->print(&header(undef,{'no_nav_bar' => 1}).
5202: '<span class="LC_error">'.&mt('You do not have permission to configure self-enrollment').'</span>');
1.237 raeburn 5203: }
1.277 raeburn 5204: } elsif ($env{'form.action'} eq 'selfenrollqueue') {
1.406.2.6 raeburn 5205: if ($permission->{selfenrolladmin}) {
1.351 raeburn 5206: push(@{$brcrum},
5207: {href => '/adm/createuser?action=selfenrollqueue',
1.406.2.6 raeburn 5208: text => 'Enrollment requests',
1.406.2.14 raeburn 5209: help => 'Course_Approve_Selfenroll'});
1.406.2.6 raeburn 5210: $bread_crumbs_component = 'Enrollment requests';
5211: if ($env{'form.state'} eq 'done') {
5212: push(@{$brcrum},
5213: {href => '/adm/createuser?action=selfenrollqueue',
5214: text => 'Result',
1.406.2.14 raeburn 5215: help => 'Course_Approve_Selfenroll'});
1.406.2.6 raeburn 5216: $bread_crumbs_component = 'Enrollment result';
5217: }
5218: $args = { bread_crumbs => $brcrum,
5219: bread_crumbs_component => $bread_crumbs_component};
5220: $r->print(&header(undef,$args));
5221: my $coursedesc = $env{'course.'.$cid.'.description'};
5222: if (!exists($env{'form.state'})) {
5223: $r->print('<h3>'.&mt('Pending enrollment requests').'</h3>'."\n");
5224: $r->print(&Apache::loncoursequeueadmin::display_queued_requests($context,
5225: $cdom,$cnum));
5226: } elsif ($env{'form.state'} eq 'done') {
5227: $r->print('<h3>'.&mt('Enrollment request processing').'</h3>'."\n");
5228: $r->print(&Apache::loncoursequeueadmin::update_request_queue($context,
5229: $cdom,$cnum,$coursedesc));
5230: }
5231: } else {
5232: $r->print(&header(undef,{'no_nav_bar' => 1}).
5233: '<span class="LC_error">'.&mt('You do not have permission to manage self-enrollment').'</span>');
1.277 raeburn 5234: }
1.239 raeburn 5235: } elsif ($env{'form.action'} eq 'changelogs') {
1.406.2.6 raeburn 5236: if ($permission->{cusr} || $permission->{view}) {
5237: &print_userchangelogs_display($r,$context,$permission,$brcrum);
5238: } else {
5239: $r->print(&header(undef,{'no_nav_bar' => 1}).
5240: '<span class="LC_error">'.&mt('You do not have permission to view change logs').'</span>');
5241: }
1.406.2.10 raeburn 5242: } elsif ($env{'form.action'} eq 'helpdesk') {
5243: if (($permission->{'owner'}) || ($permission->{'co-owner'})) {
5244: if ($env{'form.state'} eq 'process') {
5245: if ($permission->{'owner'}) {
5246: &update_helpdeskaccess($r,$permission,$brcrum);
5247: } else {
5248: &print_helpdeskaccess_display($r,$permission,$brcrum);
5249: }
5250: } else {
5251: &print_helpdeskaccess_display($r,$permission,$brcrum);
5252: }
5253: } else {
5254: $r->print(&header(undef,{'no_nav_bar' => 1}).
5255: '<span class="LC_error">'.&mt('You do not have permission to view helpdesk access').'</span>');
5256: }
1.190 raeburn 5257: } else {
1.351 raeburn 5258: $bread_crumbs_component = 'User Management';
5259: $args = { bread_crumbs => $brcrum,
5260: bread_crumbs_component => $bread_crumbs_component};
5261: $r->print(&header(undef,$args));
1.318 raeburn 5262: $r->print(&print_main_menu($permission,$context,$crstype));
1.190 raeburn 5263: }
1.351 raeburn 5264: $r->print(&Apache::loncommon::end_page());
1.190 raeburn 5265: return OK;
5266: }
5267:
5268: sub header {
1.351 raeburn 5269: my ($jscript,$args) = @_;
1.190 raeburn 5270: my $start_page;
1.351 raeburn 5271: if (ref($args) eq 'HASH') {
5272: $start_page=&Apache::loncommon::start_page('User Management',$jscript,$args);
1.190 raeburn 5273: } else {
1.351 raeburn 5274: $start_page=&Apache::loncommon::start_page('User Management',$jscript);
1.190 raeburn 5275: }
5276: return $start_page;
5277: }
1.2 www 5278:
1.191 raeburn 5279: sub add_script {
5280: my ($js) = @_;
1.301 bisitz 5281: return '<script type="text/javascript">'."\n"
5282: .'// <![CDATA['."\n"
5283: .$js."\n"
5284: .'// ]]>'."\n"
5285: .'</script>'."\n";
1.191 raeburn 5286: }
5287:
1.391 raeburn 5288: sub usernamerequest_javascript {
5289: my $js = <<ENDJS;
5290:
5291: function openusernamereqdisplay(dom,uname,queue) {
5292: var url = '/adm/createuser?action=displayuserreq';
5293: url += '&domain='+dom+'&username='+uname+'&queue='+queue;
5294: var title = 'Account_Request_Browser';
5295: var options = 'scrollbars=1,resizable=1,menubar=0';
5296: options += ',width=700,height=600';
5297: var stdeditbrowser = open(url,title,options,'1');
5298: stdeditbrowser.focus();
5299: return;
5300: }
5301:
5302: ENDJS
5303: }
5304:
5305: sub close_popup_form {
5306: my $close= &mt('Close Window');
5307: return << "END";
5308: <p><form name="displayreq" action="" method="post">
5309: <input type="button" name="closeme" value="$close" onclick="javascript:self.close();" />
5310: </form></p>
5311: END
5312: }
5313:
1.202 raeburn 5314: sub verify_user_display {
1.364 raeburn 5315: my ($context) = @_;
1.374 raeburn 5316: my %lt = &Apache::lonlocal::texthash (
5317: course => 'course(s): description, section(s), status',
5318: community => 'community(s): description, section(s), status',
5319: author => 'author',
5320: );
1.364 raeburn 5321: my $photos;
5322: if (($context eq 'course') && $env{'request.course.id'}) {
5323: $photos = $env{'course.'.$env{'request.course.id'}.'.internal.showphoto'};
5324: }
1.202 raeburn 5325: my $output = <<"END";
5326:
1.364 raeburn 5327: function hide_searching() {
5328: if (document.getElementById('searching')) {
5329: document.getElementById('searching').style.display = 'none';
5330: }
5331: return;
5332: }
5333:
1.202 raeburn 5334: function display_update() {
5335: document.studentform.action.value = 'listusers';
5336: document.studentform.phase.value = 'display';
5337: document.studentform.submit();
5338: }
5339:
1.364 raeburn 5340: function updateCols(caller) {
5341: var context = '$context';
5342: var photos = '$photos';
5343: if (caller == 'Status') {
1.374 raeburn 5344: if ((context == 'domain') &&
5345: ((document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'course') ||
5346: (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community'))) {
1.364 raeburn 5347: document.getElementById('showcolstatus').checked = false;
5348: document.getElementById('showcolstatus').disabled = 'disabled';
5349: document.getElementById('showcolstart').checked = false;
5350: document.getElementById('showcolend').checked = false;
1.374 raeburn 5351: } else {
5352: if (document.studentform.Status.options[document.studentform.Status.selectedIndex].value == 'Any') {
5353: document.getElementById('showcolstatus').checked = true;
5354: document.getElementById('showcolstatus').disabled = '';
5355: document.getElementById('showcolstart').checked = true;
5356: document.getElementById('showcolend').checked = true;
5357: } else {
5358: document.getElementById('showcolstatus').checked = false;
5359: document.getElementById('showcolstatus').disabled = 'disabled';
5360: document.getElementById('showcolstart').checked = false;
5361: document.getElementById('showcolend').checked = false;
5362: }
1.364 raeburn 5363: }
5364: }
5365: if (caller == 'output') {
5366: if (photos == 1) {
5367: if (document.getElementById('showcolphoto')) {
5368: var photoitem = document.getElementById('showcolphoto');
5369: if (document.studentform.output.options[document.studentform.output.selectedIndex].value == 'html') {
5370: photoitem.checked = true;
5371: photoitem.disabled = '';
5372: } else {
5373: photoitem.checked = false;
5374: photoitem.disabled = 'disabled';
5375: }
5376: }
5377: }
5378: }
5379: if (caller == 'showrole') {
1.371 raeburn 5380: if ((document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'Any') ||
5381: (document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'cr')) {
1.364 raeburn 5382: document.getElementById('showcolrole').checked = true;
5383: document.getElementById('showcolrole').disabled = '';
5384: } else {
5385: document.getElementById('showcolrole').checked = false;
5386: document.getElementById('showcolrole').disabled = 'disabled';
5387: }
1.374 raeburn 5388: if (context == 'domain') {
1.382 raeburn 5389: var quotausageshow = 0;
1.374 raeburn 5390: if ((document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'course') ||
5391: (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community')) {
5392: document.getElementById('showcolstatus').checked = false;
5393: document.getElementById('showcolstatus').disabled = 'disabled';
5394: document.getElementById('showcolstart').checked = false;
5395: document.getElementById('showcolend').checked = false;
5396: } else {
5397: if (document.studentform.Status.options[document.studentform.Status.selectedIndex].value == 'Any') {
5398: document.getElementById('showcolstatus').checked = true;
5399: document.getElementById('showcolstatus').disabled = '';
5400: document.getElementById('showcolstart').checked = true;
5401: document.getElementById('showcolend').checked = true;
5402: }
5403: }
5404: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'domain') {
5405: document.getElementById('showcolextent').disabled = 'disabled';
5406: document.getElementById('showcolextent').checked = 'false';
5407: document.getElementById('showextent').style.display='none';
5408: document.getElementById('showcoltextextent').innerHTML = '';
1.382 raeburn 5409: if ((document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'au') ||
5410: (document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'Any')) {
5411: if (document.getElementById('showcolauthorusage')) {
5412: document.getElementById('showcolauthorusage').disabled = '';
5413: }
5414: if (document.getElementById('showcolauthorquota')) {
5415: document.getElementById('showcolauthorquota').disabled = '';
5416: }
5417: quotausageshow = 1;
5418: }
1.374 raeburn 5419: } else {
5420: document.getElementById('showextent').style.display='block';
5421: document.getElementById('showextent').style.textAlign='left';
5422: document.getElementById('showextent').style.textFace='normal';
5423: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'author') {
5424: document.getElementById('showcolextent').disabled = '';
5425: document.getElementById('showcolextent').checked = 'true';
5426: document.getElementById('showcoltextextent').innerHTML="$lt{'author'}";
5427: } else {
5428: document.getElementById('showcolextent').disabled = '';
5429: document.getElementById('showcolextent').checked = 'true';
5430: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community') {
5431: document.getElementById('showcoltextextent').innerHTML="$lt{'community'}";
5432: } else {
5433: document.getElementById('showcoltextextent').innerHTML="$lt{'course'}";
5434: }
5435: }
5436: }
1.382 raeburn 5437: if (quotausageshow == 0) {
5438: if (document.getElementById('showcolauthorusage')) {
5439: document.getElementById('showcolauthorusage').checked = false;
5440: document.getElementById('showcolauthorusage').disabled = 'disabled';
5441: }
5442: if (document.getElementById('showcolauthorquota')) {
5443: document.getElementById('showcolauthorquota').checked = false;
5444: document.getElementById('showcolauthorquota').disabled = 'disabled';
5445: }
5446: }
1.374 raeburn 5447: }
1.364 raeburn 5448: }
5449: return;
5450: }
5451:
1.202 raeburn 5452: END
5453: return $output;
5454:
5455: }
5456:
1.190 raeburn 5457: ###############################################################
5458: ###############################################################
5459: # Menu Phase One
5460: sub print_main_menu {
1.318 raeburn 5461: my ($permission,$context,$crstype) = @_;
5462: my $linkcontext = $context;
5463: my $stuterm = lc(&Apache::lonnet::plaintext('st',$crstype));
5464: if (($context eq 'course') && ($crstype eq 'Community')) {
5465: $linkcontext = lc($crstype);
5466: $stuterm = 'Members';
5467: }
1.208 raeburn 5468: my %links = (
1.298 droeschl 5469: domain => {
5470: upload => 'Upload a File of Users',
5471: singleuser => 'Add/Modify a User',
5472: listusers => 'Manage Users',
5473: },
5474: author => {
5475: upload => 'Upload a File of Co-authors',
5476: singleuser => 'Add/Modify a Co-author',
5477: listusers => 'Manage Co-authors',
5478: },
5479: course => {
5480: upload => 'Upload a File of Course Users',
5481: singleuser => 'Add/Modify a Course User',
1.354 www 5482: listusers => 'List and Modify Multiple Course Users',
1.298 droeschl 5483: },
1.318 raeburn 5484: community => {
5485: upload => 'Upload a File of Community Users',
5486: singleuser => 'Add/Modify a Community User',
1.354 www 5487: listusers => 'List and Modify Multiple Community Users',
1.318 raeburn 5488: },
5489: );
5490: my %linktitles = (
5491: domain => {
5492: singleuser => 'Add a user to the domain, and/or a course or community in the domain.',
5493: listusers => 'Show and manage users in this domain.',
5494: },
5495: author => {
5496: singleuser => 'Add a user with a co- or assistant author role.',
5497: listusers => 'Show and manage co- or assistant authors.',
5498: },
5499: course => {
5500: singleuser => 'Add a user with a certain role to this course.',
5501: listusers => 'Show and manage users in this course.',
5502: },
5503: community => {
5504: singleuser => 'Add a user with a certain role to this community.',
5505: listusers => 'Show and manage users in this community.',
5506: },
1.298 droeschl 5507: );
1.406.2.6 raeburn 5508: if ($linkcontext eq 'domain') {
5509: unless ($permission->{'cusr'}) {
5510: $links{'domain'}{'singleuser'} = 'View a User';
5511: $linktitles{'domain'}{'singleuser'} = 'View information about a user in the domain';
5512: }
5513: } elsif ($linkcontext eq 'course') {
5514: unless ($permission->{'cusr'}) {
5515: $links{'course'}{'singleuser'} = 'View a Course User';
5516: $linktitles{'course'}{'singleuser'} = 'View information about a user in this course';
5517: $links{'course'}{'listusers'} = 'List Course Users';
5518: $linktitles{'course'}{'listusers'} = 'Show information about users in this course';
5519: }
5520: } elsif ($linkcontext eq 'community') {
5521: unless ($permission->{'cusr'}) {
5522: $links{'community'}{'singleuser'} = 'View a Community User';
5523: $linktitles{'community'}{'singleuser'} = 'View information about a user in this community';
5524: $links{'community'}{'listusers'} = 'List Community Users';
5525: $linktitles{'community'}{'listusers'} = 'Show information about users in this community';
5526: }
5527: }
1.298 droeschl 5528: my @menu = ( {categorytitle => 'Single Users',
5529: items =>
5530: [
5531: {
1.318 raeburn 5532: linktext => $links{$linkcontext}{'singleuser'},
1.298 droeschl 5533: icon => 'edit-redo.png',
5534: #help => 'Course_Change_Privileges',
5535: url => '/adm/createuser?action=singleuser',
1.406.2.6 raeburn 5536: permission => ($permission->{'view'} || $permission->{'cusr'}),
1.318 raeburn 5537: linktitle => $linktitles{$linkcontext}{'singleuser'},
1.298 droeschl 5538: },
5539: ]},
5540:
5541: {categorytitle => 'Multiple Users',
5542: items =>
5543: [
5544: {
1.318 raeburn 5545: linktext => $links{$linkcontext}{'upload'},
1.340 wenzelju 5546: icon => 'uplusr.png',
1.298 droeschl 5547: #help => 'Course_Create_Class_List',
5548: url => '/adm/createuser?action=upload',
5549: permission => $permission->{'cusr'},
5550: linktitle => 'Upload a CSV or a text file containing users.',
5551: },
5552: {
1.318 raeburn 5553: linktext => $links{$linkcontext}{'listusers'},
1.340 wenzelju 5554: icon => 'mngcu.png',
1.298 droeschl 5555: #help => 'Course_View_Class_List',
5556: url => '/adm/createuser?action=listusers',
5557: permission => ($permission->{'view'} || $permission->{'cusr'}),
1.318 raeburn 5558: linktitle => $linktitles{$linkcontext}{'listusers'},
1.298 droeschl 5559: },
5560:
5561: ]},
5562:
5563: {categorytitle => 'Administration',
5564: items => [ ]},
5565: );
1.406.2.5 raeburn 5566:
1.265 mielkec 5567: if ($context eq 'domain'){
1.406.2.5 raeburn 5568: push(@{ $menu[0]->{items} }, # Single Users
5569: {
5570: linktext => 'User Access Log',
5571: icon => 'document-properties.png',
1.406.2.8 raeburn 5572: #help => 'Domain_User_Access_Logs',
1.406.2.5 raeburn 5573: url => '/adm/createuser?action=accesslogs',
5574: permission => $permission->{'activity'},
5575: linktitle => 'View user access log.',
5576: }
5577: );
1.298 droeschl 5578:
5579: push(@{ $menu[2]->{items} }, #Category: Administration
5580: {
5581: linktext => 'Custom Roles',
5582: icon => 'emblem-photos.png',
5583: #help => 'Course_Editing_Custom_Roles',
5584: url => '/adm/createuser?action=custom',
5585: permission => $permission->{'custom'},
5586: linktitle => 'Configure a custom role.',
5587: },
1.362 raeburn 5588: {
5589: linktext => 'Authoring Space Requests',
5590: icon => 'selfenrl-queue.png',
5591: #help => 'Domain_Role_Approvals',
5592: url => '/adm/createuser?action=processauthorreq',
5593: permission => $permission->{'cusr'},
5594: linktitle => 'Approve or reject author role requests',
5595: },
1.363 raeburn 5596: {
1.391 raeburn 5597: linktext => 'LON-CAPA Account Requests',
5598: icon => 'list-add.png',
5599: #help => 'Domain_Username_Approvals',
5600: url => '/adm/createuser?action=processusernamereq',
5601: permission => $permission->{'cusr'},
5602: linktitle => 'Approve or reject LON-CAPA account requests',
5603: },
5604: {
1.363 raeburn 5605: linktext => 'Change Log',
5606: icon => 'document-properties.png',
5607: #help => 'Course_User_Logs',
5608: url => '/adm/createuser?action=changelogs',
1.406.2.6 raeburn 5609: permission => ($permission->{'cusr'} || $permission->{'view'}),
1.363 raeburn 5610: linktitle => 'View change log.',
5611: },
1.298 droeschl 5612: );
5613:
1.265 mielkec 5614: }elsif ($context eq 'course'){
1.298 droeschl 5615: my ($cnum,$cdom) = &Apache::lonuserutils::get_course_identity();
1.318 raeburn 5616:
5617: my %linktext = (
5618: 'Course' => {
5619: single => 'Add/Modify a Student',
5620: drop => 'Drop Students',
5621: groups => 'Course Groups',
5622: },
5623: 'Community' => {
5624: single => 'Add/Modify a Member',
5625: drop => 'Drop Members',
5626: groups => 'Community Groups',
5627: },
5628: );
5629:
5630: my %linktitle = (
5631: 'Course' => {
5632: single => 'Add a user with the role of student to this course',
5633: drop => 'Remove a student from this course.',
5634: groups => 'Manage course groups',
5635: },
5636: 'Community' => {
5637: single => 'Add a user with the role of member to this community',
5638: drop => 'Remove a member from this community.',
5639: groups => 'Manage community groups',
5640: },
5641: );
5642:
1.298 droeschl 5643: push(@{ $menu[0]->{items} }, #Category: Single Users
5644: {
1.318 raeburn 5645: linktext => $linktext{$crstype}{'single'},
1.298 droeschl 5646: #help => 'Course_Add_Student',
5647: icon => 'list-add.png',
5648: url => '/adm/createuser?action=singlestudent',
5649: permission => $permission->{'cusr'},
1.318 raeburn 5650: linktitle => $linktitle{$crstype}{'single'},
1.298 droeschl 5651: },
5652: );
5653:
5654: push(@{ $menu[1]->{items} }, #Category: Multiple Users
5655: {
1.318 raeburn 5656: linktext => $linktext{$crstype}{'drop'},
1.298 droeschl 5657: icon => 'edit-undo.png',
5658: #help => 'Course_Drop_Student',
5659: url => '/adm/createuser?action=drop',
5660: permission => $permission->{'cusr'},
1.318 raeburn 5661: linktitle => $linktitle{$crstype}{'drop'},
1.298 droeschl 5662: },
5663: );
5664: push(@{ $menu[2]->{items} }, #Category: Administration
1.406.2.11 raeburn 5665: {
5666: linktext => 'Helpdesk Access',
5667: icon => 'helpdesk-access.png',
5668: #help => 'Course_Helpdesk_Access',
5669: url => '/adm/createuser?action=helpdesk',
5670: permission => ($permission->{'owner'} || $permission->{'co-owner'}),
5671: linktitle => 'Helpdesk access options',
5672: },
5673: {
1.298 droeschl 5674: linktext => 'Custom Roles',
5675: icon => 'emblem-photos.png',
5676: #help => 'Course_Editing_Custom_Roles',
5677: url => '/adm/createuser?action=custom',
5678: permission => $permission->{'custom'},
5679: linktitle => 'Configure a custom role.',
5680: },
5681: {
1.318 raeburn 5682: linktext => $linktext{$crstype}{'groups'},
1.333 wenzelju 5683: icon => 'grps.png',
1.298 droeschl 5684: #help => 'Course_Manage_Group',
5685: url => '/adm/coursegroups?refpage=cusr',
5686: permission => $permission->{'grp_manage'},
1.318 raeburn 5687: linktitle => $linktitle{$crstype}{'groups'},
1.298 droeschl 5688: },
5689: {
1.328 wenzelju 5690: linktext => 'Change Log',
1.298 droeschl 5691: icon => 'document-properties.png',
5692: #help => 'Course_User_Logs',
5693: url => '/adm/createuser?action=changelogs',
1.406.2.6 raeburn 5694: permission => ($permission->{'view'} || $permission->{'cusr'}),
1.298 droeschl 5695: linktitle => 'View change log.',
5696: },
5697: );
1.277 raeburn 5698: if ($env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_approval'}) {
1.298 droeschl 5699: push(@{ $menu[2]->{items} },
1.398 raeburn 5700: {
1.298 droeschl 5701: linktext => 'Enrollment Requests',
5702: icon => 'selfenrl-queue.png',
5703: #help => 'Course_Approve_Selfenroll',
5704: url => '/adm/createuser?action=selfenrollqueue',
1.398 raeburn 5705: permission => $permission->{'selfenrolladmin'},
1.298 droeschl 5706: linktitle =>'Approve or reject enrollment requests.',
5707: },
5708: );
1.277 raeburn 5709: }
1.298 droeschl 5710:
1.265 mielkec 5711: if (!exists($permission->{'cusr_section'})){
1.320 raeburn 5712: if ($crstype ne 'Community') {
5713: push(@{ $menu[2]->{items} },
5714: {
5715: linktext => 'Automated Enrollment',
5716: icon => 'roles.png',
5717: #help => 'Course_Automated_Enrollment',
5718: permission => (&Apache::lonnet::auto_run($cnum,$cdom)
1.406.2.6 raeburn 5719: && (($permission->{'cusr'}) ||
5720: ($permission->{'view'}))),
1.320 raeburn 5721: url => '/adm/populate',
5722: linktitle => 'Automated enrollment manager.',
5723: }
5724: );
5725: }
5726: push(@{ $menu[2]->{items} },
1.298 droeschl 5727: {
5728: linktext => 'User Self-Enrollment',
1.342 wenzelju 5729: icon => 'self_enroll.png',
1.298 droeschl 5730: #help => 'Course_Self_Enrollment',
5731: url => '/adm/createuser?action=selfenroll',
1.398 raeburn 5732: permission => $permission->{'selfenrolladmin'},
1.317 bisitz 5733: linktitle => 'Configure user self-enrollment.',
1.298 droeschl 5734: },
5735: );
5736: }
1.363 raeburn 5737: } elsif ($context eq 'author') {
1.370 raeburn 5738: push(@{ $menu[2]->{items} }, #Category: Administration
1.363 raeburn 5739: {
5740: linktext => 'Change Log',
5741: icon => 'document-properties.png',
5742: #help => 'Course_User_Logs',
5743: url => '/adm/createuser?action=changelogs',
5744: permission => $permission->{'cusr'},
5745: linktitle => 'View change log.',
5746: },
1.370 raeburn 5747: );
1.363 raeburn 5748: }
5749: return Apache::lonhtmlcommon::generate_menu(@menu);
1.250 raeburn 5750: # { text => 'View Log-in History',
5751: # help => 'Course_User_Logins',
5752: # action => 'logins',
5753: # permission => $permission->{'cusr'},
5754: # });
1.190 raeburn 5755: }
5756:
1.189 albertel 5757: sub restore_prev_selections {
5758: my %saveable_parameters = ('srchby' => 'scalar',
5759: 'srchin' => 'scalar',
5760: 'srchtype' => 'scalar',
5761: );
5762: &Apache::loncommon::store_settings('user','user_picker',
5763: \%saveable_parameters);
5764: &Apache::loncommon::restore_settings('user','user_picker',
5765: \%saveable_parameters);
5766: }
5767:
1.237 raeburn 5768: sub print_selfenroll_menu {
1.406.2.6 raeburn 5769: my ($r,$context,$cid,$cdom,$cnum,$currsettings,$additional,$readonly) = @_;
1.322 raeburn 5770: my $crstype = &Apache::loncommon::course_type();
1.398 raeburn 5771: my $formname = 'selfenroll';
1.237 raeburn 5772: my $nolink = 1;
1.398 raeburn 5773: my ($row,$lt) = &Apache::lonuserutils::get_selfenroll_titles();
1.237 raeburn 5774: my $groupslist = &Apache::lonuserutils::get_groupslist();
5775: my $setsec_js =
5776: &Apache::lonuserutils::setsections_javascript($formname,$groupslist);
1.249 raeburn 5777: my %alerts = &Apache::lonlocal::texthash(
5778: acto => 'Activation of self-enrollment was selected for the following domain(s)',
5779: butn => 'but no user types have been checked.',
5780: wilf => "Please uncheck 'activate' or check at least one type.",
5781: );
1.406.2.6 raeburn 5782: my $disabled;
5783: if ($readonly) {
5784: $disabled = ' disabled="disabled"';
5785: }
1.405 damieng 5786: &js_escape(\%alerts);
1.249 raeburn 5787: my $selfenroll_js = <<"ENDSCRIPT";
5788: function update_types(caller,num) {
5789: var delidx = getIndexByName('selfenroll_delete');
5790: var actidx = getIndexByName('selfenroll_activate');
5791: if (caller == 'selfenroll_all') {
5792: var selall;
5793: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
5794: if (document.$formname.selfenroll_all[i].checked) {
5795: selall = document.$formname.selfenroll_all[i].value;
5796: }
5797: }
5798: if (selall == 1) {
5799: if (delidx != -1) {
5800: if (document.$formname.selfenroll_delete.length) {
5801: for (var j=0; j<document.$formname.selfenroll_delete.length; j++) {
5802: document.$formname.selfenroll_delete[j].checked = true;
5803: }
5804: } else {
5805: document.$formname.elements[delidx].checked = true;
5806: }
5807: }
5808: if (actidx != -1) {
5809: if (document.$formname.selfenroll_activate.length) {
5810: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
5811: document.$formname.selfenroll_activate[j].checked = false;
5812: }
5813: } else {
5814: document.$formname.elements[actidx].checked = false;
5815: }
5816: }
5817: document.$formname.selfenroll_newdom.selectedIndex = 0;
5818: }
5819: }
5820: if (caller == 'selfenroll_activate') {
5821: if (document.$formname.selfenroll_activate.length) {
5822: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
5823: if (document.$formname.selfenroll_activate[j].value == num) {
5824: if (document.$formname.selfenroll_activate[j].checked) {
5825: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
5826: if (document.$formname.selfenroll_all[i].value == '1') {
5827: document.$formname.selfenroll_all[i].checked = false;
5828: }
5829: if (document.$formname.selfenroll_all[i].value == '0') {
5830: document.$formname.selfenroll_all[i].checked = true;
5831: }
5832: }
5833: }
5834: }
5835: }
5836: } else {
5837: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
5838: if (document.$formname.selfenroll_all[i].value == '1') {
5839: document.$formname.selfenroll_all[i].checked = false;
5840: }
5841: if (document.$formname.selfenroll_all[i].value == '0') {
5842: document.$formname.selfenroll_all[i].checked = true;
5843: }
5844: }
5845: }
5846: }
5847: if (caller == 'selfenroll_delete') {
5848: if (document.$formname.selfenroll_delete.length) {
5849: for (var j=0; j<document.$formname.selfenroll_delete.length; j++) {
5850: if (document.$formname.selfenroll_delete[j].value == num) {
5851: if (document.$formname.selfenroll_delete[j].checked) {
5852: var delindex = getIndexByName('selfenroll_types_'+num);
5853: if (delindex != -1) {
5854: if (document.$formname.elements[delindex].length) {
5855: for (var k=0; k<document.$formname.elements[delindex].length; k++) {
5856: document.$formname.elements[delindex][k].checked = false;
5857: }
5858: } else {
5859: document.$formname.elements[delindex].checked = false;
5860: }
5861: }
5862: }
5863: }
5864: }
5865: } else {
5866: if (document.$formname.selfenroll_delete.checked) {
5867: var delindex = getIndexByName('selfenroll_types_'+num);
5868: if (delindex != -1) {
5869: if (document.$formname.elements[delindex].length) {
5870: for (var k=0; k<document.$formname.elements[delindex].length; k++) {
5871: document.$formname.elements[delindex][k].checked = false;
5872: }
5873: } else {
5874: document.$formname.elements[delindex].checked = false;
5875: }
5876: }
5877: }
5878: }
5879: }
5880: return;
5881: }
5882:
5883: function validate_types(form) {
5884: var needaction = new Array();
5885: var countfail = 0;
5886: var actidx = getIndexByName('selfenroll_activate');
5887: if (actidx != -1) {
5888: if (document.$formname.selfenroll_activate.length) {
5889: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
5890: var num = document.$formname.selfenroll_activate[j].value;
5891: if (document.$formname.selfenroll_activate[j].checked) {
5892: countfail = check_types(num,countfail,needaction)
5893: }
5894: }
5895: } else {
5896: if (document.$formname.selfenroll_activate.checked) {
1.398 raeburn 5897: var num = document.$formname.selfenroll_activate.value;
1.249 raeburn 5898: countfail = check_types(num,countfail,needaction)
5899: }
5900: }
5901: }
5902: if (countfail > 0) {
5903: var msg = "$alerts{'acto'}\\n";
5904: var loopend = needaction.length -1;
5905: if (loopend > 0) {
5906: for (var m=0; m<loopend; m++) {
5907: msg += needaction[m]+", ";
5908: }
5909: }
5910: msg += needaction[loopend]+"\\n$alerts{'butn'}\\n$alerts{'wilf'}";
5911: alert(msg);
5912: return;
5913: }
5914: setSections(form);
5915: }
5916:
5917: function check_types(num,countfail,needaction) {
1.406.2.15 raeburn 5918: var boxname = 'selfenroll_types_'+num;
5919: var typeidx = getIndexByName(boxname);
1.249 raeburn 5920: var count = 0;
5921: if (typeidx != -1) {
1.406.2.15 raeburn 5922: if (document.$formname.elements[boxname].length) {
5923: for (var k=0; k<document.$formname.elements[boxname].length; k++) {
5924: if (document.$formname.elements[boxname][k].checked) {
1.249 raeburn 5925: count ++;
5926: }
5927: }
5928: } else {
5929: if (document.$formname.elements[typeidx].checked) {
5930: count ++;
5931: }
5932: }
5933: if (count == 0) {
5934: var domidx = getIndexByName('selfenroll_dom_'+num);
5935: if (domidx != -1) {
5936: var domname = document.$formname.elements[domidx].value;
5937: needaction[countfail] = domname;
5938: countfail ++;
5939: }
5940: }
5941: }
5942: return countfail;
5943: }
5944:
1.398 raeburn 5945: function toggleNotify() {
5946: var selfenrollApproval = 0;
5947: if (document.$formname.selfenroll_approval.length) {
5948: for (var i=0; i<document.$formname.selfenroll_approval.length; i++) {
5949: if (document.$formname.selfenroll_approval[i].checked) {
5950: selfenrollApproval = document.$formname.selfenroll_approval[i].value;
5951: break;
5952: }
5953: }
5954: }
5955: if (document.getElementById('notified')) {
5956: if (selfenrollApproval == 0) {
5957: document.getElementById('notified').style.display='none';
5958: } else {
5959: document.getElementById('notified').style.display='block';
5960: }
5961: }
5962: return;
5963: }
5964:
1.249 raeburn 5965: function getIndexByName(item) {
5966: for (var i=0;i<document.$formname.elements.length;i++) {
5967: if (document.$formname.elements[i].name == item) {
5968: return i;
5969: }
5970: }
5971: return -1;
5972: }
5973: ENDSCRIPT
1.256 raeburn 5974:
1.237 raeburn 5975: my $output = '<script type="text/javascript">'."\n".
1.301 bisitz 5976: '// <![CDATA['."\n".
1.249 raeburn 5977: $setsec_js."\n".$selfenroll_js."\n".
1.301 bisitz 5978: '// ]]>'."\n".
1.237 raeburn 5979: '</script>'."\n".
1.256 raeburn 5980: '<h3>'.$lt->{'selfenroll'}.'</h3>'."\n";
1.400 raeburn 5981:
5982: my $visactions = &cat_visibility();
5983: my ($cathash,%cattype);
5984: my %domconfig = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom);
5985: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
5986: $cathash = $domconfig{'coursecategories'}{'cats'};
5987: $cattype{'auth'} = $domconfig{'coursecategories'}{'auth'};
5988: $cattype{'unauth'} = $domconfig{'coursecategories'}{'unauth'};
1.406 raeburn 5989: if ($cattype{'auth'} eq '') {
5990: $cattype{'auth'} = 'std';
5991: }
5992: if ($cattype{'unauth'} eq '') {
5993: $cattype{'unauth'} = 'std';
5994: }
1.400 raeburn 5995: } else {
5996: $cathash = {};
5997: $cattype{'auth'} = 'std';
5998: $cattype{'unauth'} = 'std';
5999: }
6000: if (($cattype{'auth'} eq 'none') && ($cattype{'unauth'} eq 'none')) {
6001: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
6002: '<br />'.
6003: '<br />'.$visactions->{'take'}.'<ul>'.
6004: '<li>'.$visactions->{'dc_chgconf'}.'</li>'.
6005: '</ul>');
6006: } elsif (($cattype{'auth'} !~ /^(std|domonly)$/) && ($cattype{'unauth'} !~ /^(std|domonly)$/)) {
6007: if ($currsettings->{'uniquecode'}) {
6008: $r->print('<span class="LC_info">'.$visactions->{'vis'}.'</span>');
6009: } else {
6010: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
6011: '<br />'.
6012: '<br />'.$visactions->{'take'}.'<ul>'.
6013: '<li>'.$visactions->{'dc_setcode'}.'</li>'.
6014: '</ul><br />');
6015: }
6016: } else {
6017: my ($visible,$cansetvis,$vismsgs) = &visible_in_stdcat($cdom,$cnum,\%domconfig);
6018: if (ref($visactions) eq 'HASH') {
6019: if ($visible) {
6020: $output .= '<p class="LC_info">'.$visactions->{'vis'}.'</p>';
6021: } else {
6022: $output .= '<p class="LC_warning">'.$visactions->{'miss'}.'</p>'
6023: .$visactions->{'yous'}.
6024: '<p>'.$visactions->{'gen'}.'<br />'.$visactions->{'coca'};
6025: if (ref($vismsgs) eq 'ARRAY') {
6026: $output .= '<br />'.$visactions->{'make'}.'<ul>';
6027: foreach my $item (@{$vismsgs}) {
6028: $output .= '<li>'.$visactions->{$item}.'</li>';
6029: }
6030: $output .= '</ul>';
1.256 raeburn 6031: }
1.400 raeburn 6032: $output .= '</p>';
1.256 raeburn 6033: }
6034: }
6035: }
1.398 raeburn 6036: my $actionhref = '/adm/createuser';
6037: if ($context eq 'domain') {
6038: $actionhref = '/adm/modifycourse';
6039: }
1.400 raeburn 6040:
6041: my %noedit;
6042: unless ($context eq 'domain') {
6043: %noedit = &get_noedit_fields($cdom,$cnum,$crstype,$row);
6044: }
1.398 raeburn 6045: $output .= '<form name="'.$formname.'" method="post" action="'.$actionhref.'">'."\n".
1.256 raeburn 6046: &Apache::lonhtmlcommon::start_pick_box();
1.237 raeburn 6047: if (ref($row) eq 'ARRAY') {
6048: foreach my $item (@{$row}) {
6049: my $title = $item;
6050: if (ref($lt) eq 'HASH') {
6051: $title = $lt->{$item};
6052: }
1.297 bisitz 6053: $output .= &Apache::lonhtmlcommon::row_title($title);
1.237 raeburn 6054: if ($item eq 'types') {
1.398 raeburn 6055: my $curr_types;
6056: if (ref($currsettings) eq 'HASH') {
6057: $curr_types = $currsettings->{'selfenroll_types'};
6058: }
1.400 raeburn 6059: if ($noedit{$item}) {
6060: if ($curr_types eq '*') {
6061: $output .= &mt('Any user in any domain');
6062: } else {
6063: my @entries = split(/;/,$curr_types);
6064: if (@entries > 0) {
6065: $output .= '<ul>';
6066: foreach my $entry (@entries) {
6067: my ($currdom,$typestr) = split(/:/,$entry);
6068: next if ($typestr eq '');
6069: my $domdesc = &Apache::lonnet::domain($currdom);
6070: my @currinsttypes = split(',',$typestr);
6071: my ($othertitle,$usertypes,$types) =
6072: &Apache::loncommon::sorted_inst_types($currdom);
6073: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
6074: $usertypes->{'any'} = &mt('any user');
6075: if (keys(%{$usertypes}) > 0) {
6076: $usertypes->{'other'} = &mt('other users');
6077: }
6078: my @longinsttypes = map { $usertypes->{$_}; } @currinsttypes;
6079: $output .= '<li>'.$domdesc.':'.join(', ',@longinsttypes).'</li>';
6080: }
6081: }
6082: $output .= '</ul>';
6083: } else {
6084: $output .= &mt('None');
6085: }
6086: }
6087: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6088: next;
6089: }
1.241 raeburn 6090: my $showdomdesc = 1;
6091: my $includeempty = 1;
6092: my $num = 0;
6093: $output .= &Apache::loncommon::start_data_table().
6094: &Apache::loncommon::start_data_table_row()
6095: .'<td colspan="2"><span class="LC_nobreak"><label>'
6096: .&mt('Any user in any domain:')
6097: .' <input type="radio" name="selfenroll_all" value="1" ';
6098: if ($curr_types eq '*') {
6099: $output .= ' checked="checked" ';
6100: }
1.249 raeburn 6101: $output .= 'onchange="javascript:update_types('.
1.406.2.6 raeburn 6102: "'selfenroll_all'".');"'.$disabled.' />'.&mt('Yes').'</label>'.
1.249 raeburn 6103: ' <input type="radio" name="selfenroll_all" value="0" ';
1.241 raeburn 6104: if ($curr_types ne '*') {
6105: $output .= ' checked="checked" ';
6106: }
1.249 raeburn 6107: $output .= ' onchange="javascript:update_types('.
1.406.2.6 raeburn 6108: "'selfenroll_all'".');"'.$disabled.' />'.&mt('No').'</label></td>'.
1.249 raeburn 6109: &Apache::loncommon::end_data_table_row().
6110: &Apache::loncommon::end_data_table().
6111: &mt('Or').'<br />'.
6112: &Apache::loncommon::start_data_table();
1.241 raeburn 6113: my %currdoms;
1.249 raeburn 6114: if ($curr_types eq '') {
1.241 raeburn 6115: $output .= &new_selfenroll_dom_row($cdom,'0');
6116: } elsif ($curr_types ne '*') {
6117: my @entries = split(/;/,$curr_types);
6118: if (@entries > 0) {
6119: foreach my $entry (@entries) {
6120: my ($currdom,$typestr) = split(/:/,$entry);
6121: $currdoms{$currdom} = 1;
6122: my $domdesc = &Apache::lonnet::domain($currdom);
1.249 raeburn 6123: my @currinsttypes = split(',',$typestr);
1.241 raeburn 6124: $output .= &Apache::loncommon::start_data_table_row()
6125: .'<td valign="top"><span class="LC_nobreak">'.&mt('Domain:').'<b>'
6126: .' '.$domdesc.' ('.$currdom.')'
6127: .'</b><input type="hidden" name="selfenroll_dom_'.$num
6128: .'" value="'.$currdom.'" /></span><br />'
6129: .'<span class="LC_nobreak"><label><input type="checkbox" '
1.406.2.6 raeburn 6130: .'name="selfenroll_delete" value="'.$num.'" onchange="javascript:update_types('."'selfenroll_delete','$num'".');"'.$disabled.' />'
1.241 raeburn 6131: .&mt('Delete').'</label></span></td>';
1.249 raeburn 6132: $output .= '<td valign="top"> '.&mt('User types:').'<br />'
1.406.2.6 raeburn 6133: .&selfenroll_inst_types($num,$currdom,\@currinsttypes,$readonly).'</td>'
1.241 raeburn 6134: .&Apache::loncommon::end_data_table_row();
6135: $num ++;
6136: }
6137: }
6138: }
1.249 raeburn 6139: my $add_domtitle = &mt('Users in additional domain:');
1.241 raeburn 6140: if ($curr_types eq '*') {
1.249 raeburn 6141: $add_domtitle = &mt('Users in specific domain:');
1.241 raeburn 6142: } elsif ($curr_types eq '') {
1.249 raeburn 6143: $add_domtitle = &mt('Users in other domain:');
1.241 raeburn 6144: }
6145: $output .= &Apache::loncommon::start_data_table_row()
6146: .'<td colspan="2"><span class="LC_nobreak">'.$add_domtitle.'</span><br />'
6147: .&Apache::loncommon::select_dom_form('','selfenroll_newdom',
1.406.2.6 raeburn 6148: $includeempty,$showdomdesc,'','','',$readonly)
1.241 raeburn 6149: .'<input type="hidden" name="selfenroll_types_total" value="'.$num.'" />'
6150: .'</td>'.&Apache::loncommon::end_data_table_row()
6151: .&Apache::loncommon::end_data_table();
1.237 raeburn 6152: } elsif ($item eq 'registered') {
6153: my ($regon,$regoff);
1.398 raeburn 6154: my $registered;
6155: if (ref($currsettings) eq 'HASH') {
6156: $registered = $currsettings->{'selfenroll_registered'};
6157: }
1.400 raeburn 6158: if ($noedit{$item}) {
6159: if ($registered) {
6160: $output .= &mt('Must be registered in course');
6161: } else {
6162: $output .= &mt('No requirement');
6163: }
6164: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6165: next;
6166: }
1.398 raeburn 6167: if ($registered) {
1.237 raeburn 6168: $regon = ' checked="checked" ';
1.406.2.6 raeburn 6169: $regoff = '';
1.237 raeburn 6170: } else {
1.406.2.6 raeburn 6171: $regon = '';
1.237 raeburn 6172: $regoff = ' checked="checked" ';
6173: }
6174: $output .= '<label>'.
1.406.2.6 raeburn 6175: '<input type="radio" name="selfenroll_registered" value="1"'.$regon.$disabled.' />'.
1.244 bisitz 6176: &mt('Yes').'</label> <label>'.
1.406.2.6 raeburn 6177: '<input type="radio" name="selfenroll_registered" value="0"'.$regoff.$disabled.' />'.
1.244 bisitz 6178: &mt('No').'</label>';
1.237 raeburn 6179: } elsif ($item eq 'enroll_dates') {
1.398 raeburn 6180: my ($starttime,$endtime);
6181: if (ref($currsettings) eq 'HASH') {
6182: $starttime = $currsettings->{'selfenroll_start_date'};
6183: $endtime = $currsettings->{'selfenroll_end_date'};
6184: if ($starttime eq '') {
6185: $starttime = $currsettings->{'default_enrollment_start_date'};
6186: }
6187: if ($endtime eq '') {
6188: $endtime = $currsettings->{'default_enrollment_end_date'};
6189: }
1.237 raeburn 6190: }
1.400 raeburn 6191: if ($noedit{$item}) {
6192: $output .= &mt('From: [_1], to: [_2]',&Apache::lonlocal::locallocaltime($starttime),
6193: &Apache::lonlocal::locallocaltime($endtime));
6194: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6195: next;
6196: }
1.237 raeburn 6197: my $startform =
6198: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_start_date',$starttime,
1.406.2.6 raeburn 6199: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
1.237 raeburn 6200: my $endform =
6201: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_end_date',$endtime,
1.406.2.6 raeburn 6202: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
1.237 raeburn 6203: $output .= &selfenroll_date_forms($startform,$endform);
6204: } elsif ($item eq 'access_dates') {
1.398 raeburn 6205: my ($starttime,$endtime);
6206: if (ref($currsettings) eq 'HASH') {
6207: $starttime = $currsettings->{'selfenroll_start_access'};
6208: $endtime = $currsettings->{'selfenroll_end_access'};
6209: if ($starttime eq '') {
6210: $starttime = $currsettings->{'default_enrollment_start_date'};
6211: }
6212: if ($endtime eq '') {
6213: $endtime = $currsettings->{'default_enrollment_end_date'};
6214: }
1.237 raeburn 6215: }
1.400 raeburn 6216: if ($noedit{$item}) {
6217: $output .= &mt('From: [_1], to: [_2]',&Apache::lonlocal::locallocaltime($starttime),
6218: &Apache::lonlocal::locallocaltime($endtime));
6219: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6220: next;
6221: }
1.237 raeburn 6222: my $startform =
6223: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_start_access',$starttime,
1.406.2.6 raeburn 6224: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
1.237 raeburn 6225: my $endform =
6226: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_end_access',$endtime,
1.406.2.6 raeburn 6227: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
1.237 raeburn 6228: $output .= &selfenroll_date_forms($startform,$endform);
6229: } elsif ($item eq 'section') {
1.398 raeburn 6230: my $currsec;
6231: if (ref($currsettings) eq 'HASH') {
6232: $currsec = $currsettings->{'selfenroll_section'};
6233: }
1.237 raeburn 6234: my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum);
6235: my $newsecval;
6236: if ($currsec ne 'none' && $currsec ne '') {
6237: if (!defined($sections_count{$currsec})) {
6238: $newsecval = $currsec;
6239: }
6240: }
1.400 raeburn 6241: if ($noedit{$item}) {
6242: if ($currsec ne '') {
6243: $output .= $currsec;
6244: } else {
6245: $output .= &mt('No specific section');
6246: }
6247: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6248: next;
6249: }
1.237 raeburn 6250: my $sections_select =
1.406.2.6 raeburn 6251: &Apache::lonuserutils::course_sections(\%sections_count,'st',$currsec,$disabled);
1.237 raeburn 6252: $output .= '<table class="LC_createuser">'."\n".
6253: '<tr class="LC_section_row">'."\n".
6254: '<td align="center">'.&mt('Existing sections')."\n".
6255: '<br />'.$sections_select.'</td><td align="center">'.
6256: &mt('New section').'<br />'."\n".
1.406.2.6 raeburn 6257: '<input type="text" name="newsec" size="15" value="'.$newsecval.'"'.$disabled.' />'."\n".
1.237 raeburn 6258: '<input type="hidden" name="sections" value="" />'."\n".
6259: '</td></tr></table>'."\n";
1.276 raeburn 6260: } elsif ($item eq 'approval') {
1.398 raeburn 6261: my ($currnotified,$currapproval,%appchecked);
6262: my %selfdescs = &Apache::lonuserutils::selfenroll_default_descs();
1.406.2.6 raeburn 6263: if (ref($currsettings) eq 'HASH') {
1.398 raeburn 6264: $currnotified = $currsettings->{'selfenroll_notifylist'};
6265: $currapproval = $currsettings->{'selfenroll_approval'};
6266: }
6267: if ($currapproval !~ /^[012]$/) {
6268: $currapproval = 0;
6269: }
1.400 raeburn 6270: if ($noedit{$item}) {
6271: $output .= $selfdescs{'approval'}{$currapproval}.
6272: '<br />'.&mt('(Set by Domain Coordinator)');
6273: next;
6274: }
1.398 raeburn 6275: $appchecked{$currapproval} = ' checked="checked"';
6276: for my $i (0..2) {
6277: $output .= '<label>'.
6278: '<input type="radio" name="selfenroll_approval" value="'.$i.'"'.
1.406.2.6 raeburn 6279: $appchecked{$i}.' onclick="toggleNotify();"'.$disabled.' />'.
6280: $selfdescs{'approval'}{$i}.'</label>'.(' 'x2);
1.276 raeburn 6281: }
6282: my %advhash = &Apache::lonnet::get_course_adv_roles($cid,1);
6283: my (@ccs,%notified);
1.322 raeburn 6284: my $ccrole = 'cc';
6285: if ($crstype eq 'Community') {
6286: $ccrole = 'co';
6287: }
6288: if ($advhash{$ccrole}) {
6289: @ccs = split(/,/,$advhash{$ccrole});
1.276 raeburn 6290: }
6291: if ($currnotified) {
6292: foreach my $current (split(/,/,$currnotified)) {
6293: $notified{$current} = 1;
6294: if (!grep(/^\Q$current\E$/,@ccs)) {
6295: push(@ccs,$current);
6296: }
6297: }
6298: }
6299: if (@ccs) {
1.398 raeburn 6300: my $style;
6301: unless ($currapproval) {
6302: $style = ' style="display: none;"';
6303: }
6304: $output .= '<br /><div id="notified"'.$style.'>'.
6305: &mt('Personnel to be notified when an enrollment request needs approval, or has been approved:').' '.
6306: &Apache::loncommon::start_data_table().
1.276 raeburn 6307: &Apache::loncommon::start_data_table_row();
6308: my $count = 0;
6309: my $numcols = 4;
6310: foreach my $cc (sort(@ccs)) {
6311: my $notifyon;
6312: my ($ccuname,$ccudom) = split(/:/,$cc);
6313: if ($notified{$cc}) {
6314: $notifyon = ' checked="checked" ';
6315: }
6316: if ($count && !$count%$numcols) {
6317: $output .= &Apache::loncommon::end_data_table_row().
6318: &Apache::loncommon::start_data_table_row()
6319: }
6320: $output .= '<td><span class="LC_nobreak"><label>'.
1.406.2.6 raeburn 6321: '<input type="checkbox" name="selfenroll_notify"'.$notifyon.' value="'.$cc.'"'.$disabled.' />'.
1.276 raeburn 6322: &Apache::loncommon::plainname($ccuname,$ccudom).
6323: '</label></span></td>';
1.343 raeburn 6324: $count ++;
1.276 raeburn 6325: }
6326: my $rem = $count%$numcols;
6327: if ($rem) {
6328: my $emptycols = $numcols - $rem;
6329: for (my $i=0; $i<$emptycols; $i++) {
6330: $output .= '<td> </td>';
6331: }
6332: }
6333: $output .= &Apache::loncommon::end_data_table_row().
1.398 raeburn 6334: &Apache::loncommon::end_data_table().
6335: '</div>';
1.276 raeburn 6336: }
6337: } elsif ($item eq 'limit') {
1.398 raeburn 6338: my ($crslimit,$selflimit,$nolimit,$currlim,$currcap);
6339: if (ref($currsettings) eq 'HASH') {
6340: $currlim = $currsettings->{'selfenroll_limit'};
6341: $currcap = $currsettings->{'selfenroll_cap'};
6342: }
1.400 raeburn 6343: if ($noedit{$item}) {
6344: if (($currlim eq 'allstudents') || ($currlim eq 'selfenrolled')) {
6345: if ($currlim eq 'allstudents') {
6346: $output .= &mt('Limit by total students');
6347: } elsif ($currlim eq 'selfenrolled') {
6348: $output .= &mt('Limit by total self-enrolled students');
6349: }
6350: $output .= ' '.&mt('Maximum: [_1]',$currcap).
6351: '<br />'.&mt('(Set by Domain Coordinator)');
6352: } else {
6353: $output .= &mt('No limit').'<br />'.&mt('(Set by Domain Coordinator)');
6354: }
6355: next;
6356: }
1.276 raeburn 6357: if ($currlim eq 'allstudents') {
6358: $crslimit = ' checked="checked" ';
6359: $selflimit = ' ';
6360: $nolimit = ' ';
6361: } elsif ($currlim eq 'selfenrolled') {
6362: $crslimit = ' ';
6363: $selflimit = ' checked="checked" ';
6364: $nolimit = ' ';
6365: } else {
6366: $crslimit = ' ';
6367: $selflimit = ' ';
1.398 raeburn 6368: $nolimit = ' checked="checked" ';
1.276 raeburn 6369: }
6370: $output .= '<table><tr><td><label>'.
1.406.2.6 raeburn 6371: '<input type="radio" name="selfenroll_limit" value="none"'.$nolimit.$disabled.'/>'.
1.276 raeburn 6372: &mt('No limit').'</label></td><td><label>'.
1.406.2.6 raeburn 6373: '<input type="radio" name="selfenroll_limit" value="allstudents"'.$crslimit.$disabled.'/>'.
1.276 raeburn 6374: &mt('Limit by total students').'</label></td><td><label>'.
1.406.2.6 raeburn 6375: '<input type="radio" name="selfenroll_limit" value="selfenrolled"'.$selflimit.$disabled.'/>'.
1.276 raeburn 6376: &mt('Limit by total self-enrolled students').
6377: '</td></tr><tr>'.
6378: '<td> </td><td colspan="2"><span class="LC_nobreak">'.
6379: (' 'x3).&mt('Maximum number allowed: ').
1.406.2.6 raeburn 6380: '<input type="text" name="selfenroll_cap" size = "5" value="'.$currcap.'"'.$disabled.' /></td></tr></table>';
1.237 raeburn 6381: }
6382: $output .= &Apache::lonhtmlcommon::row_closure(1);
6383: }
6384: }
1.406.2.6 raeburn 6385: $output .= &Apache::lonhtmlcommon::end_pick_box().'<br />';
6386: unless ($readonly) {
6387: $output .= '<input type="button" name="selfenrollconf" value="'
6388: .&mt('Save').'" onclick="validate_types(this.form);" />';
6389: }
6390: $output .= '<input type="hidden" name="action" value="selfenroll" />'
1.406.2.11 raeburn 6391: .'<input type="hidden" name="state" value="done" />'."\n"
6392: .$additional.'</form>';
1.237 raeburn 6393: $r->print($output);
6394: return;
6395: }
6396:
1.400 raeburn 6397: sub get_noedit_fields {
6398: my ($cdom,$cnum,$crstype,$row) = @_;
6399: my %noedit;
6400: if (ref($row) eq 'ARRAY') {
6401: my %settings = &Apache::lonnet::get('environment',['internal.coursecode','internal.textbook',
6402: 'internal.selfenrollmgrdc',
6403: 'internal.selfenrollmgrcc'],$cdom,$cnum);
6404: my $type = &Apache::lonuserutils::get_extended_type($cdom,$cnum,$crstype,\%settings);
6405: my (%specific_managebydc,%specific_managebycc,%default_managebydc);
6406: map { $specific_managebydc{$_} = 1; } (split(/,/,$settings{'internal.selfenrollmgrdc'}));
6407: map { $specific_managebycc{$_} = 1; } (split(/,/,$settings{'internal.selfenrollmgrcc'}));
6408: my %domdefaults = &Apache::lonnet::get_domain_defaults($cdom);
6409: map { $default_managebydc{$_} = 1; } (split(/,/,$domdefaults{$type.'selfenrolladmdc'}));
6410:
6411: foreach my $item (@{$row}) {
6412: next if ($specific_managebycc{$item});
6413: if (($specific_managebydc{$item}) || ($default_managebydc{$item})) {
6414: $noedit{$item} = 1;
6415: }
6416: }
6417: }
6418: return %noedit;
6419: }
6420:
6421: sub visible_in_stdcat {
6422: my ($cdom,$cnum,$domconf) = @_;
6423: my ($cathash,%settable,@vismsgs,$cansetvis,$visible);
6424: unless (ref($domconf) eq 'HASH') {
6425: return ($visible,$cansetvis,\@vismsgs);
6426: }
6427: if (ref($domconf->{'coursecategories'}) eq 'HASH') {
6428: if ($domconf->{'coursecategories'}{'togglecats'} eq 'crs') {
1.256 raeburn 6429: $settable{'togglecats'} = 1;
6430: }
1.400 raeburn 6431: if ($domconf->{'coursecategories'}{'categorize'} eq 'crs') {
1.256 raeburn 6432: $settable{'categorize'} = 1;
6433: }
1.400 raeburn 6434: $cathash = $domconf->{'coursecategories'}{'cats'};
1.256 raeburn 6435: }
1.260 raeburn 6436: if ($settable{'togglecats'} && $settable{'categorize'}) {
1.256 raeburn 6437: $cansetvis = &mt('You are able to both assign a course category and choose to exclude this course from the catalog.');
6438: } elsif ($settable{'togglecats'}) {
6439: $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 6440: } elsif ($settable{'categorize'}) {
1.256 raeburn 6441: $cansetvis = &mt('You may assign a course category, but only a Domain Coordinator may choose to exclude this course from the catalog.');
6442: } else {
6443: $cansetvis = &mt('Only a Domain Coordinator may assign a course category or choose to exclude this course from the catalog.');
6444: }
6445:
6446: my %currsettings =
6447: &Apache::lonnet::get('environment',['hidefromcat','categories','internal.coursecode'],
6448: $cdom,$cnum);
1.400 raeburn 6449: $visible = 0;
1.256 raeburn 6450: if ($currsettings{'internal.coursecode'} ne '') {
1.400 raeburn 6451: if (ref($domconf->{'coursecategories'}) eq 'HASH') {
6452: $cathash = $domconf->{'coursecategories'}{'cats'};
1.256 raeburn 6453: if (ref($cathash) eq 'HASH') {
6454: if ($cathash->{'instcode::0'} eq '') {
6455: push(@vismsgs,'dc_addinst');
6456: } else {
6457: $visible = 1;
6458: }
6459: } else {
6460: $visible = 1;
6461: }
6462: } else {
6463: $visible = 1;
6464: }
6465: } else {
6466: if (ref($cathash) eq 'HASH') {
6467: if ($cathash->{'instcode::0'} ne '') {
6468: push(@vismsgs,'dc_instcode');
6469: }
6470: } else {
6471: push(@vismsgs,'dc_instcode');
6472: }
6473: }
6474: if ($currsettings{'categories'} ne '') {
6475: my $cathash;
1.400 raeburn 6476: if (ref($domconf->{'coursecategories'}) eq 'HASH') {
6477: $cathash = $domconf->{'coursecategories'}{'cats'};
1.256 raeburn 6478: if (ref($cathash) eq 'HASH') {
6479: if (keys(%{$cathash}) == 0) {
6480: push(@vismsgs,'dc_catalog');
6481: } elsif ((keys(%{$cathash}) == 1) && ($cathash->{'instcode::0'} ne '')) {
6482: push(@vismsgs,'dc_categories');
6483: } else {
6484: my @currcategories = split('&',$currsettings{'categories'});
6485: my $matched = 0;
6486: foreach my $cat (@currcategories) {
6487: if ($cathash->{$cat} ne '') {
6488: $visible = 1;
6489: $matched = 1;
6490: last;
6491: }
6492: }
6493: if (!$matched) {
1.260 raeburn 6494: if ($settable{'categorize'}) {
1.256 raeburn 6495: push(@vismsgs,'chgcat');
6496: } else {
6497: push(@vismsgs,'dc_chgcat');
6498: }
6499: }
6500: }
6501: }
6502: }
6503: } else {
6504: if (ref($cathash) eq 'HASH') {
6505: if ((keys(%{$cathash}) > 1) ||
6506: (keys(%{$cathash}) == 1) && ($cathash->{'instcode::0'} eq '')) {
1.260 raeburn 6507: if ($settable{'categorize'}) {
1.256 raeburn 6508: push(@vismsgs,'addcat');
6509: } else {
6510: push(@vismsgs,'dc_addcat');
6511: }
6512: }
6513: }
6514: }
6515: if ($currsettings{'hidefromcat'} eq 'yes') {
6516: $visible = 0;
6517: if ($settable{'togglecats'}) {
6518: unshift(@vismsgs,'unhide');
6519: } else {
6520: unshift(@vismsgs,'dc_unhide')
6521: }
6522: }
1.400 raeburn 6523: return ($visible,$cansetvis,\@vismsgs);
6524: }
6525:
6526: sub cat_visibility {
6527: my %visactions = &Apache::lonlocal::texthash(
6528: vis => 'This course/community currently appears in the Course/Community Catalog for this domain.',
6529: 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.',
6530: miss => 'This course/community does not currently appear in the Course/Community Catalog for this domain.',
6531: none => 'Display of a course catalog is disabled for this domain.',
6532: yous => 'You should remedy this if you plan to allow self-enrollment, otherwise students will have difficulty finding this course.',
6533: 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.',
6534: make => 'Make any changes to self-enrollment settings below, click "Save", then take action to include the course in the Catalog:',
6535: take => 'Take the following action to ensure the course appears in the Catalog:',
6536: dc_chgconf => 'Ask a domain coordinator to change the Catalog type for this domain.',
6537: dc_setcode => 'Ask a domain coordinator to assign a six character code to the course',
6538: dc_unhide => 'Ask a domain coordinator to change the "Exclude from course catalog" setting.',
6539: dc_addinst => 'Ask a domain coordinator to enable display the catalog of "Official courses (with institutional codes)".',
6540: dc_instcode => 'Ask a domain coordinator to assign an institutional code (if this is an official course).',
6541: dc_catalog => 'Ask a domain coordinator to enable or create at least one course category in the domain.',
6542: dc_categories => 'Ask a domain coordinator to create a hierarchy of categories and sub categories for courses in the domain.',
6543: 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',
6544: dc_addcat => 'Ask a domain coordinator to assign a category to the course.',
6545: );
6546: $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>"');
6547: $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>"');
6548: $visactions{'addcat'} = &mt('Use [_1]Categorize course[_2] to assign a category to the course.','"<a href="/adm/courseprefs?phase=display&actions=courseinfo">','</a>"');
6549: return \%visactions;
1.256 raeburn 6550: }
6551:
1.241 raeburn 6552: sub new_selfenroll_dom_row {
6553: my ($newdom,$num) = @_;
6554: my $domdesc = &Apache::lonnet::domain($newdom);
6555: my $output;
6556: if ($domdesc ne '') {
6557: $output .= &Apache::loncommon::start_data_table_row()
6558: .'<td valign="top"><span class="LC_nobreak">'.&mt('Domain:').' <b>'.$domdesc
6559: .' ('.$newdom.')</b><input type="hidden" name="selfenroll_dom_'.$num
1.249 raeburn 6560: .'" value="'.$newdom.'" /></span><br />'
6561: .'<span class="LC_nobreak"><label><input type="checkbox" '
6562: .'name="selfenroll_activate" value="'.$num.'" '
6563: .'onchange="javascript:update_types('
6564: ."'selfenroll_activate','$num'".');" />'
6565: .&mt('Activate').'</label></span></td>';
1.241 raeburn 6566: my @currinsttypes;
6567: $output .= '<td>'.&mt('User types:').'<br />'
6568: .&selfenroll_inst_types($num,$newdom,\@currinsttypes).'</td>'
6569: .&Apache::loncommon::end_data_table_row();
6570: }
6571: return $output;
6572: }
6573:
6574: sub selfenroll_inst_types {
1.406.2.6 raeburn 6575: my ($num,$currdom,$currinsttypes,$readonly) = @_;
1.241 raeburn 6576: my $output;
6577: my $numinrow = 4;
6578: my $count = 0;
6579: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($currdom);
1.247 raeburn 6580: my $othervalue = 'any';
1.406.2.6 raeburn 6581: my $disabled;
6582: if ($readonly) {
6583: $disabled = ' disabled="disabled"';
6584: }
1.241 raeburn 6585: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
1.251 raeburn 6586: if (keys(%{$usertypes}) > 0) {
1.247 raeburn 6587: $othervalue = 'other';
6588: }
1.241 raeburn 6589: $output .= '<table><tr>';
6590: foreach my $type (@{$types}) {
6591: if (($count > 0) && ($count%$numinrow == 0)) {
6592: $output .= '</tr><tr>';
6593: }
6594: if (defined($usertypes->{$type})) {
1.257 raeburn 6595: my $esc_type = &escape($type);
1.241 raeburn 6596: $output .= '<td><span class="LC_nobreak"><label><input type = "checkbox" value="'.
1.257 raeburn 6597: $esc_type.'" ';
1.241 raeburn 6598: if (ref($currinsttypes) eq 'ARRAY') {
6599: if (@{$currinsttypes} > 0) {
1.249 raeburn 6600: if (grep(/^any$/,@{$currinsttypes})) {
6601: $output .= 'checked="checked"';
1.257 raeburn 6602: } elsif (grep(/^\Q$esc_type\E$/,@{$currinsttypes})) {
1.241 raeburn 6603: $output .= 'checked="checked"';
6604: }
1.249 raeburn 6605: } else {
6606: $output .= 'checked="checked"';
1.241 raeburn 6607: }
6608: }
1.406.2.6 raeburn 6609: $output .= ' name="selfenroll_types_'.$num.'"'.$disabled.' />'.$usertypes->{$type}.'</label></span></td>';
1.241 raeburn 6610: }
6611: $count ++;
6612: }
6613: if (($count > 0) && ($count%$numinrow == 0)) {
6614: $output .= '</tr><tr>';
6615: }
1.249 raeburn 6616: $output .= '<td><span class="LC_nobreak"><label><input type = "checkbox" value="'.$othervalue.'"';
1.241 raeburn 6617: if (ref($currinsttypes) eq 'ARRAY') {
6618: if (@{$currinsttypes} > 0) {
1.249 raeburn 6619: if (grep(/^any$/,@{$currinsttypes})) {
6620: $output .= ' checked="checked"';
6621: } elsif ($othervalue eq 'other') {
6622: if (grep(/^\Q$othervalue\E$/,@{$currinsttypes})) {
6623: $output .= ' checked="checked"';
6624: }
1.241 raeburn 6625: }
1.249 raeburn 6626: } else {
6627: $output .= ' checked="checked"';
1.241 raeburn 6628: }
1.249 raeburn 6629: } else {
6630: $output .= ' checked="checked"';
1.241 raeburn 6631: }
1.406.2.6 raeburn 6632: $output .= ' name="selfenroll_types_'.$num.'"'.$disabled.' />'.$othertitle.'</label></span></td></tr></table>';
1.241 raeburn 6633: }
6634: return $output;
6635: }
6636:
1.237 raeburn 6637: sub selfenroll_date_forms {
6638: my ($startform,$endform) = @_;
6639: my $output .= &Apache::lonhtmlcommon::start_pick_box()."\n".
1.244 bisitz 6640: &Apache::lonhtmlcommon::row_title(&mt('Start date'),
1.237 raeburn 6641: 'LC_oddrow_value')."\n".
6642: $startform."\n".
6643: &Apache::lonhtmlcommon::row_closure(1).
1.244 bisitz 6644: &Apache::lonhtmlcommon::row_title(&mt('End date'),
1.237 raeburn 6645: 'LC_oddrow_value')."\n".
6646: $endform."\n".
6647: &Apache::lonhtmlcommon::row_closure(1).
6648: &Apache::lonhtmlcommon::end_pick_box();
6649: return $output;
6650: }
6651:
1.239 raeburn 6652: sub print_userchangelogs_display {
1.406.2.5 raeburn 6653: my ($r,$context,$permission,$brcrum) = @_;
1.363 raeburn 6654: my $formname = 'rolelog';
1.406.2.6 raeburn 6655: my ($username,$domain,$crstype,$viewablesec,%roleslog);
1.363 raeburn 6656: if ($context eq 'domain') {
6657: $domain = $env{'request.role.domain'};
6658: %roleslog=&Apache::lonnet::dump_dom('nohist_rolelog',$domain);
6659: } else {
6660: if ($context eq 'course') {
6661: $domain = $env{'course.'.$env{'request.course.id'}.'.domain'};
6662: $username = $env{'course.'.$env{'request.course.id'}.'.num'};
6663: $crstype = &Apache::loncommon::course_type();
1.406.2.6 raeburn 6664: $viewablesec = &Apache::lonuserutils::viewable_section($permission);
1.363 raeburn 6665: my %saveable_parameters = ('show' => 'scalar',);
6666: &Apache::loncommon::store_course_settings('roles_log',
6667: \%saveable_parameters);
6668: &Apache::loncommon::restore_course_settings('roles_log',
6669: \%saveable_parameters);
6670: } elsif ($context eq 'author') {
6671: $domain = $env{'user.domain'};
6672: if ($env{'request.role'} =~ m{^au\./\Q$domain\E/$}) {
6673: $username = $env{'user.name'};
6674: } else {
6675: undef($domain);
6676: }
6677: }
6678: if ($domain ne '' && $username ne '') {
6679: %roleslog=&Apache::lonnet::dump('nohist_rolelog',$domain,$username);
6680: }
6681: }
1.239 raeburn 6682: if ((keys(%roleslog))[0]=~/^error\:/) { undef(%roleslog); }
6683:
1.406.2.5 raeburn 6684: my $helpitem;
6685: if ($context eq 'course') {
6686: $helpitem = 'Course_User_Logs';
1.406.2.14 raeburn 6687: } elsif ($context eq 'domain') {
6688: $helpitem = 'Domain_Role_Logs';
6689: } elsif ($context eq 'author') {
6690: $helpitem = 'Author_User_Logs';
1.406.2.5 raeburn 6691: }
6692: push (@{$brcrum},
6693: {href => '/adm/createuser?action=changelogs',
6694: text => 'User Management Logs',
6695: help => $helpitem});
6696: my $bread_crumbs_component = 'User Changes';
6697: my $args = { bread_crumbs => $brcrum,
6698: bread_crumbs_component => $bread_crumbs_component};
6699:
6700: # Create navigation javascript
6701: my $jsnav = &userlogdisplay_js($formname);
6702:
6703: my $jscript = (<<ENDSCRIPT);
6704: <script type="text/javascript">
6705: // <![CDATA[
6706: $jsnav
6707: // ]]>
6708: </script>
6709: ENDSCRIPT
6710:
6711: # print page header
6712: $r->print(&header($jscript,$args));
6713:
1.239 raeburn 6714: # set defaults
6715: my $now = time();
6716: my $defstart = $now - (7*24*3600); #7 days ago
6717: my %defaults = (
6718: page => '1',
6719: show => '10',
6720: role => 'any',
6721: chgcontext => 'any',
6722: rolelog_start_date => $defstart,
6723: rolelog_end_date => $now,
6724: );
6725: my $more_records = 0;
6726:
6727: # set current
6728: my %curr;
6729: foreach my $item ('show','page','role','chgcontext') {
6730: $curr{$item} = $env{'form.'.$item};
6731: }
6732: my ($startdate,$enddate) =
6733: &Apache::lonuserutils::get_dates_from_form('rolelog_start_date','rolelog_end_date');
6734: $curr{'rolelog_start_date'} = $startdate;
6735: $curr{'rolelog_end_date'} = $enddate;
6736: foreach my $key (keys(%defaults)) {
6737: if ($curr{$key} eq '') {
6738: $curr{$key} = $defaults{$key};
6739: }
6740: }
1.248 raeburn 6741: my (%whodunit,%changed,$version);
6742: ($version) = ($r->dir_config('lonVersion') =~ /^([\d\.]+)\-/);
1.239 raeburn 6743: my ($minshown,$maxshown);
1.255 raeburn 6744: $minshown = 1;
1.239 raeburn 6745: my $count = 0;
1.406.2.5 raeburn 6746: if ($curr{'show'} =~ /\D/) {
6747: $curr{'page'} = 1;
6748: } else {
1.239 raeburn 6749: $maxshown = $curr{'page'} * $curr{'show'};
6750: if ($curr{'page'} > 1) {
6751: $minshown = 1 + ($curr{'page'} - 1) * $curr{'show'};
6752: }
6753: }
1.301 bisitz 6754:
1.327 raeburn 6755: # Form Header
6756: $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">'.
1.363 raeburn 6757: &role_display_filter($context,$formname,$domain,$username,\%curr,
6758: $version,$crstype));
1.327 raeburn 6759:
6760: my $showntableheader = 0;
6761:
6762: # Table Header
6763: my $tableheader =
6764: &Apache::loncommon::start_data_table_header_row()
6765: .'<th> </th>'
6766: .'<th>'.&mt('When').'</th>'
6767: .'<th>'.&mt('Who made the change').'</th>'
6768: .'<th>'.&mt('Changed User').'</th>'
1.363 raeburn 6769: .'<th>'.&mt('Role').'</th>';
6770:
6771: if ($context eq 'course') {
6772: $tableheader .= '<th>'.&mt('Section').'</th>';
6773: }
6774: $tableheader .=
6775: '<th>'.&mt('Context').'</th>'
1.327 raeburn 6776: .'<th>'.&mt('Start').'</th>'
6777: .'<th>'.&mt('End').'</th>'
6778: .&Apache::loncommon::end_data_table_header_row();
6779:
6780: # Display user change log data
1.239 raeburn 6781: foreach my $id (sort { $roleslog{$b}{'exe_time'}<=>$roleslog{$a}{'exe_time'} } (keys(%roleslog))) {
6782: next if (($roleslog{$id}{'exe_time'} < $curr{'rolelog_start_date'}) ||
6783: ($roleslog{$id}{'exe_time'} > $curr{'rolelog_end_date'}));
1.406.2.5 raeburn 6784: if ($curr{'show'} !~ /\D/) {
1.239 raeburn 6785: if ($count >= $curr{'page'} * $curr{'show'}) {
6786: $more_records = 1;
6787: last;
6788: }
6789: }
6790: if ($curr{'role'} ne 'any') {
6791: next if ($roleslog{$id}{'logentry'}{'role'} ne $curr{'role'});
6792: }
6793: if ($curr{'chgcontext'} ne 'any') {
6794: if ($curr{'chgcontext'} eq 'selfenroll') {
6795: next if (!$roleslog{$id}{'logentry'}{'selfenroll'});
6796: } else {
6797: next if ($roleslog{$id}{'logentry'}{'context'} ne $curr{'chgcontext'});
6798: }
6799: }
1.406.2.6 raeburn 6800: if (($context eq 'course') && ($viewablesec ne '')) {
6801: next if ($roleslog{$id}{'logentry'}{'section'} ne $viewablesec);
6802: }
1.239 raeburn 6803: $count ++;
6804: next if ($count < $minshown);
1.327 raeburn 6805: unless ($showntableheader) {
1.406.2.5 raeburn 6806: $r->print(&Apache::loncommon::start_data_table()
1.327 raeburn 6807: .$tableheader);
6808: $r->rflush();
6809: $showntableheader = 1;
6810: }
1.239 raeburn 6811: if ($whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}} eq '') {
6812: $whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}} =
6813: &Apache::loncommon::plainname($roleslog{$id}{'exe_uname'},$roleslog{$id}{'exe_udom'});
6814: }
6815: if ($changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}} eq '') {
6816: $changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}} =
6817: &Apache::loncommon::plainname($roleslog{$id}{'uname'},$roleslog{$id}{'udom'});
6818: }
6819: my $sec = $roleslog{$id}{'logentry'}{'section'};
6820: if ($sec eq '') {
6821: $sec = &mt('None');
6822: }
6823: my ($rolestart,$roleend);
6824: if ($roleslog{$id}{'delflag'}) {
6825: $rolestart = &mt('deleted');
6826: $roleend = &mt('deleted');
6827: } else {
6828: $rolestart = $roleslog{$id}{'logentry'}{'start'};
6829: $roleend = $roleslog{$id}{'logentry'}{'end'};
6830: if ($rolestart eq '' || $rolestart == 0) {
6831: $rolestart = &mt('No start date');
6832: } else {
6833: $rolestart = &Apache::lonlocal::locallocaltime($rolestart);
6834: }
6835: if ($roleend eq '' || $roleend == 0) {
6836: $roleend = &mt('No end date');
6837: } else {
6838: $roleend = &Apache::lonlocal::locallocaltime($roleend);
6839: }
6840: }
6841: my $chgcontext = $roleslog{$id}{'logentry'}{'context'};
6842: if ($roleslog{$id}{'logentry'}{'selfenroll'}) {
6843: $chgcontext = 'selfenroll';
6844: }
1.363 raeburn 6845: my %lt = &rolechg_contexts($context,$crstype);
1.239 raeburn 6846: if ($chgcontext ne '' && $lt{$chgcontext} ne '') {
6847: $chgcontext = $lt{$chgcontext};
6848: }
1.327 raeburn 6849: $r->print(
1.301 bisitz 6850: &Apache::loncommon::start_data_table_row()
6851: .'<td>'.$count.'</td>'
6852: .'<td>'.&Apache::lonlocal::locallocaltime($roleslog{$id}{'exe_time'}).'</td>'
6853: .'<td>'.$whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}}.'</td>'
6854: .'<td>'.$changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}}.'</td>'
1.363 raeburn 6855: .'<td>'.&Apache::lonnet::plaintext($roleslog{$id}{'logentry'}{'role'},$crstype).'</td>');
6856: if ($context eq 'course') {
6857: $r->print('<td>'.$sec.'</td>');
6858: }
6859: $r->print(
6860: '<td>'.$chgcontext.'</td>'
1.301 bisitz 6861: .'<td>'.$rolestart.'</td>'
6862: .'<td>'.$roleend.'</td>'
1.327 raeburn 6863: .&Apache::loncommon::end_data_table_row()."\n");
1.301 bisitz 6864: }
6865:
1.327 raeburn 6866: if ($showntableheader) { # Table footer, if content displayed above
1.406.2.5 raeburn 6867: $r->print(&Apache::loncommon::end_data_table().
6868: &userlogdisplay_navlinks(\%curr,$more_records));
1.327 raeburn 6869: } else { # No content displayed above
1.301 bisitz 6870: $r->print('<p class="LC_info">'
6871: .&mt('There are no records to display.')
6872: .'</p>'
6873: );
1.239 raeburn 6874: }
1.301 bisitz 6875:
1.327 raeburn 6876: # Form Footer
6877: $r->print(
6878: '<input type="hidden" name="page" value="'.$curr{'page'}.'" />'
6879: .'<input type="hidden" name="action" value="changelogs" />'
6880: .'</form>');
6881: return;
6882: }
1.301 bisitz 6883:
1.406.2.5 raeburn 6884: sub print_useraccesslogs_display {
6885: my ($r,$uname,$udom,$permission,$brcrum) = @_;
6886: my $formname = 'accesslog';
6887: my $form = 'document.accesslog';
6888:
6889: # set breadcrumbs
1.406.2.7 raeburn 6890: my %breadcrumb_text = &singleuser_breadcrumb('','domain',$udom);
1.406.2.12 raeburn 6891: my $prevphasestr;
6892: if ($env{'form.popup'}) {
6893: $brcrum = [];
6894: } else {
6895: push (@{$brcrum},
6896: {href => "javascript:backPage($form)",
6897: text => $breadcrumb_text{'search'}});
6898: my @prevphases;
6899: if ($env{'form.prevphases'}) {
6900: @prevphases = split(/,/,$env{'form.prevphases'});
6901: $prevphasestr = $env{'form.prevphases'};
6902: }
6903: if (($env{'form.phase'} eq 'userpicked') || (grep(/^userpicked$/,@prevphases))) {
6904: push(@{$brcrum},
6905: {href => "javascript:backPage($form,'get_user_info','select')",
6906: text => $breadcrumb_text{'userpicked'}});
6907: if ($env{'form.phase'} eq 'userpicked') {
6908: $prevphasestr = 'userpicked';
6909: }
1.406.2.5 raeburn 6910: }
6911: }
6912: push(@{$brcrum},
6913: {href => '/adm/createuser?action=accesslogs',
6914: text => 'User access logs',
1.406.2.8 raeburn 6915: help => 'Domain_User_Access_Logs'});
1.406.2.5 raeburn 6916: my $bread_crumbs_component = 'User Access Logs';
6917: my $args = { bread_crumbs => $brcrum,
6918: bread_crumbs_component => 'User Management'};
1.406.2.8 raeburn 6919: if ($env{'form.popup'}) {
6920: $args->{'no_nav_bar'} = 1;
1.406.2.12 raeburn 6921: $args->{'bread_crumbs_nomenu'} = 1;
1.406.2.8 raeburn 6922: }
1.406.2.5 raeburn 6923:
6924: # set javascript
6925: my ($jsback,$elements) = &crumb_utilities();
6926: my $jsnav = &userlogdisplay_js($formname);
6927:
6928: my $jscript = (<<ENDSCRIPT);
1.239 raeburn 6929: <script type="text/javascript">
1.301 bisitz 6930: // <![CDATA[
1.406.2.5 raeburn 6931:
6932: $jsback
6933: $jsnav
6934:
6935: // ]]>
6936: </script>
6937:
6938: ENDSCRIPT
6939:
6940: # print page header
6941: $r->print(&header($jscript,$args));
6942:
6943: # early out unless log data can be displayed.
6944: unless ($permission->{'activity'}) {
6945: $r->print('<p class="LC_warning">'
6946: .&mt('You do not have rights to display user access logs.')
1.406.2.12 raeburn 6947: .'</p>');
6948: if ($env{'form.popup'}) {
6949: $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a></p>');
6950: } else {
6951: $r->print(&earlyout_accesslog_form($formname,$prevphasestr,$udom));
6952: }
1.406.2.5 raeburn 6953: return;
6954: }
6955:
6956: unless ($udom eq $env{'request.role.domain'}) {
6957: $r->print('<p class="LC_warning">'
6958: .&mt("User's domain must match role's domain")
6959: .'</p>'
6960: .&earlyout_accesslog_form($formname,$prevphasestr,$udom));
6961: return;
6962: }
6963:
6964: if (($uname eq '') || ($udom eq '')) {
6965: $r->print('<p class="LC_warning">'
6966: .&mt('Invalid username or domain')
6967: .'</p>'
6968: .&earlyout_accesslog_form($formname,$prevphasestr,$udom));
6969: return;
6970: }
6971:
1.406.2.13 raeburn 6972: if (&Apache::lonnet::privileged($uname,$udom,
6973: [$env{'request.role.domain'}],['dc','su'])) {
6974: unless (&Apache::lonnet::privileged($env{'user.name'},$env{'user.domain'},
6975: [$env{'request.role.domain'}],['dc','su'])) {
6976: $r->print('<p class="LC_warning">'
6977: .&mt('You need to be a privileged user to display user access logs for [_1]',
6978: &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),
6979: $uname,$udom))
6980: .'</p>');
6981: if ($env{'form.popup'}) {
6982: $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a></p>');
6983: } else {
6984: $r->print(&earlyout_accesslog_form($formname,$prevphasestr,$udom));
6985: }
6986: return;
6987: }
6988: }
6989:
1.406.2.5 raeburn 6990: # set defaults
6991: my $now = time();
6992: my $defstart = $now - (7*24*3600);
6993: my %defaults = (
6994: page => '1',
6995: show => '10',
6996: activity => 'any',
6997: accesslog_start_date => $defstart,
6998: accesslog_end_date => $now,
6999: );
7000: my $more_records = 0;
7001:
7002: # set current
7003: my %curr;
7004: foreach my $item ('show','page','activity') {
7005: $curr{$item} = $env{'form.'.$item};
7006: }
7007: my ($startdate,$enddate) =
7008: &Apache::lonuserutils::get_dates_from_form('accesslog_start_date','accesslog_end_date');
7009: $curr{'accesslog_start_date'} = $startdate;
7010: $curr{'accesslog_end_date'} = $enddate;
7011: foreach my $key (keys(%defaults)) {
7012: if ($curr{$key} eq '') {
7013: $curr{$key} = $defaults{$key};
7014: }
7015: }
7016: my ($minshown,$maxshown);
7017: $minshown = 1;
7018: my $count = 0;
7019: if ($curr{'show'} =~ /\D/) {
7020: $curr{'page'} = 1;
7021: } else {
7022: $maxshown = $curr{'page'} * $curr{'show'};
7023: if ($curr{'page'} > 1) {
7024: $minshown = 1 + ($curr{'page'} - 1) * $curr{'show'};
7025: }
7026: }
7027:
7028: # form header
7029: $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">'.
7030: &activity_display_filter($formname,\%curr));
7031:
7032: my $showntableheader = 0;
7033: my ($nav_script,$nav_links);
7034:
7035: # table header
1.406.2.12 raeburn 7036: my $tableheader = '<h3>'.
7037: &mt('User access logs for: [_1]',
7038: &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),$uname,$udom)).'</h3>'
7039: .&Apache::loncommon::start_data_table_header_row()
1.406.2.5 raeburn 7040: .'<th> </th>'
7041: .'<th>'.&mt('When').'</th>'
7042: .'<th>'.&mt('HostID').'</th>'
7043: .'<th>'.&mt('Event').'</th>'
7044: .'<th>'.&mt('Other data').'</th>'
7045: .&Apache::loncommon::end_data_table_header_row();
7046:
7047: my %filters=(
7048: start => $curr{'accesslog_start_date'},
7049: end => $curr{'accesslog_end_date'},
7050: action => $curr{'activity'},
7051: );
7052:
7053: my $reply = &Apache::lonnet::userlog_query($uname,$udom,%filters);
7054: unless ( ($reply =~/^timeout/) || ($reply =~/^error/) ) {
7055: my (%courses,%missing);
7056: my @results = split(/\&/,$reply);
7057: foreach my $item (reverse(@results)) {
7058: my ($timestamp,$host,$event) = split(/:/,$item);
7059: next unless ($event =~ /^(Log|Role)/);
7060: if ($curr{'show'} !~ /\D/) {
7061: if ($count >= $curr{'page'} * $curr{'show'}) {
7062: $more_records = 1;
7063: last;
7064: }
7065: }
7066: $count ++;
7067: next if ($count < $minshown);
7068: unless ($showntableheader) {
7069: $r->print($nav_script
7070: .&Apache::loncommon::start_data_table()
7071: .$tableheader);
7072: $r->rflush();
7073: $showntableheader = 1;
7074: }
1.406.2.6 raeburn 7075: my ($shown,$extra);
1.406.2.13 raeburn 7076: my ($event,$data) = split(/\s+/,&unescape($event),2);
1.406.2.5 raeburn 7077: if ($event eq 'Role') {
7078: my ($rolecode,$extent) = split(/\./,$data,2);
7079: next if ($extent eq '');
7080: my ($crstype,$desc,$info);
1.406.2.6 raeburn 7081: if ($extent =~ m{^/($match_domain)/($match_courseid)(?:/(\w+)|)$}) {
7082: my ($cdom,$cnum,$sec) = ($1,$2,$3);
1.406.2.5 raeburn 7083: my $cid = $cdom.'_'.$cnum;
7084: if (exists($courses{$cid})) {
7085: $crstype = $courses{$cid}{'type'};
7086: $desc = $courses{$cid}{'description'};
7087: } elsif ($missing{$cid}) {
7088: $crstype = 'Course';
7089: $desc = 'Course/Community';
7090: } else {
7091: my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',$cnum,undef,undef,'.');
7092: if (ref($crsinfo{$cdom.'_'.$cnum}) eq 'HASH') {
7093: $courses{$cid} = $crsinfo{$cid};
7094: $crstype = $crsinfo{$cid}{'type'};
7095: $desc = $crsinfo{$cid}{'description'};
7096: } else {
7097: $missing{$cid} = 1;
7098: }
7099: }
7100: $extra = &mt($crstype).': <a href="/public/'.$cdom.'/'.$cnum.'/syllabus">'.$desc.'</a>';
1.406.2.6 raeburn 7101: if ($sec ne '') {
7102: $extra .= ' ('.&mt('Section: [_1]',$sec).')';
7103: }
1.406.2.5 raeburn 7104: } elsif ($extent =~ m{^/($match_domain)/($match_username|$)}) {
7105: my ($dom,$name) = ($1,$2);
7106: if ($rolecode eq 'au') {
7107: $extra = '';
7108: } elsif ($rolecode =~ /^(ca|aa)$/) {
7109: $extra = &mt('Authoring Space: [_1]',$name.':'.$dom);
7110: } elsif ($rolecode =~ /^(li|dg|dh|dc|sc)$/) {
7111: $extra = &mt('Domain: [_1]',$dom);
7112: }
7113: }
7114: my $rolename;
7115: if ($rolecode =~ m{^cr/($match_domain)/($match_username)/(\w+)}) {
7116: my $role = $3;
7117: my $owner = "($2:$1)";
7118: if ($2 eq $1.'-domainconfig') {
7119: $owner = '(ad hoc)';
7120: }
7121: $rolename = &mt('Custom role: [_1]',$role.' '.$owner);
7122: } else {
7123: $rolename = &Apache::lonnet::plaintext($rolecode,$crstype);
7124: }
7125: $shown = &mt('Role selection: [_1]',$rolename);
7126: } else {
7127: $shown = &mt($event);
1.406.2.13 raeburn 7128: if ($data =~ /^webdav/) {
7129: my ($path,$clientip) = split(/\s+/,$data,2);
7130: $path =~ s/^webdav//;
7131: if ($clientip ne '') {
7132: $extra = &mt('Client IP address: [_1]',$clientip);
7133: }
7134: if ($path ne '') {
7135: $shown .= ' '.&mt('(WebDAV access to [_1])',$path);
7136: }
7137: } elsif ($data ne '') {
7138: $extra = &mt('Client IP address: [_1]',$data);
1.406.2.5 raeburn 7139: }
7140: }
7141: $r->print(
7142: &Apache::loncommon::start_data_table_row()
7143: .'<td>'.$count.'</td>'
7144: .'<td>'.&Apache::lonlocal::locallocaltime($timestamp).'</td>'
7145: .'<td>'.$host.'</td>'
7146: .'<td>'.$shown.'</td>'
7147: .'<td>'.$extra.'</td>'
7148: .&Apache::loncommon::end_data_table_row()."\n");
7149: }
7150: }
7151:
7152: if ($showntableheader) { # Table footer, if content displayed above
7153: $r->print(&Apache::loncommon::end_data_table().
7154: &userlogdisplay_navlinks(\%curr,$more_records));
7155: } else { # No content displayed above
7156: $r->print('<p class="LC_info">'
7157: .&mt('There are no records to display.')
7158: .'</p>');
7159: }
7160:
1.406.2.8 raeburn 7161: if ($env{'form.popup'} == 1) {
7162: $r->print('<input type="hidden" name="popup" value="1" />'."\n");
7163: }
7164:
1.406.2.5 raeburn 7165: # Form Footer
7166: $r->print(
7167: '<input type="hidden" name="currstate" value="" />'
7168: .'<input type="hidden" name="accessuname" value="'.$uname.'" />'
7169: .'<input type="hidden" name="accessudom" value="'.$udom.'" />'
7170: .'<input type="hidden" name="page" value="'.$curr{'page'}.'" />'
7171: .'<input type="hidden" name="prevphases" value="'.$prevphasestr.'" />'
7172: .'<input type="hidden" name="phase" value="activity" />'
7173: .'<input type="hidden" name="action" value="accesslogs" />'
7174: .'<input type="hidden" name="srchdomain" value="'.$udom.'" />'
7175: .'<input type="hidden" name="srchby" value="'.$env{'form.srchby'}.'" />'
7176: .'<input type="hidden" name="srchtype" value="'.$env{'form.srchtype'}.'" />'
7177: .'<input type="hidden" name="srchterm" value="'.&HTML::Entities::encode($env{'form.srchterm'},'<>"&').'" />'
7178: .'<input type="hidden" name="srchin" value="'.$env{'form.srchin'}.'" />'
7179: .'</form>');
7180: return;
7181: }
7182:
7183: sub earlyout_accesslog_form {
7184: my ($formname,$prevphasestr,$udom) = @_;
7185: my $srchterm = &HTML::Entities::encode($env{'form.srchterm'},'<>"&');
7186: return <<"END";
7187: <form action="/adm/createuser" method="post" name="$formname">
7188: <input type="hidden" name="currstate" value="" />
7189: <input type="hidden" name="prevphases" value="$prevphasestr" />
7190: <input type="hidden" name="phase" value="activity" />
7191: <input type="hidden" name="action" value="accesslogs" />
7192: <input type="hidden" name="srchdomain" value="$udom" />
7193: <input type="hidden" name="srchby" value="$env{'form.srchby'}" />
7194: <input type="hidden" name="srchtype" value="$env{'form.srchtype'}" />
7195: <input type="hidden" name="srchterm" value="$srchterm" />
7196: <input type="hidden" name="srchin" value="$env{'form.srchin'}" />
7197: </form>
7198: END
7199: }
7200:
7201: sub activity_display_filter {
7202: my ($formname,$curr) = @_;
7203: my $nolink = 1;
7204: my $output = '<table><tr><td valign="top">'.
7205: '<span class="LC_nobreak"><b>'.&mt('Actions/page:').'</b></span><br />'.
7206: &Apache::lonmeta::selectbox('show',$curr->{'show'},undef,
7207: (&mt('all'),5,10,20,50,100,1000,10000)).
7208: '</td><td> </td>';
7209: my $startform =
7210: &Apache::lonhtmlcommon::date_setter($formname,'accesslog_start_date',
7211: $curr->{'accesslog_start_date'},undef,
7212: undef,undef,undef,undef,undef,undef,$nolink);
7213: my $endform =
7214: &Apache::lonhtmlcommon::date_setter($formname,'accesslog_end_date',
7215: $curr->{'accesslog_end_date'},undef,
7216: undef,undef,undef,undef,undef,undef,$nolink);
7217: my %lt = &Apache::lonlocal::texthash (
7218: activity => 'Activity',
7219: Role => 'Role selection',
7220: log => 'Log-in or Logout',
7221: );
7222: $output .= '<td valign="top"><b>'.&mt('Window during which actions occurred:').'</b><br />'.
7223: '<table><tr><td>'.&mt('After:').
7224: '</td><td>'.$startform.'</td></tr>'.
7225: '<tr><td>'.&mt('Before:').'</td>'.
7226: '<td>'.$endform.'</td></tr></table>'.
7227: '</td>'.
7228: '<td> </td>'.
7229: '<td valign="top"><b>'.&mt('Activities').'</b><br />'.
7230: '<select name="activity"><option value="any"';
7231: if ($curr->{'activity'} eq 'any') {
7232: $output .= ' selected="selected"';
7233: }
7234: $output .= '>'.&mt('Any').'</option>'."\n";
7235: foreach my $activity ('Role','log') {
7236: my $selstr = '';
7237: if ($activity eq $curr->{'activity'}) {
7238: $selstr = ' selected="selected"';
7239: }
7240: $output .= '<option value="'.$activity.'"'.$selstr.'>'.$lt{$activity}.'</option>';
7241: }
7242: $output .= '</select></td>'.
7243: '</tr></table>';
7244: # Update Display button
7245: $output .= '<p>'
7246: .'<input type="submit" value="'.&mt('Update Display').'" />'
1.406.2.12 raeburn 7247: .'</p><hr />';
1.406.2.5 raeburn 7248: return $output;
7249: }
7250:
7251: sub userlogdisplay_js {
7252: my ($formname) = @_;
7253: return <<"ENDSCRIPT";
7254:
1.239 raeburn 7255: function chgPage(caller) {
7256: if (caller == 'previous') {
7257: document.$formname.page.value --;
7258: }
7259: if (caller == 'next') {
7260: document.$formname.page.value ++;
7261: }
1.327 raeburn 7262: document.$formname.submit();
1.239 raeburn 7263: return;
7264: }
7265: ENDSCRIPT
1.406.2.5 raeburn 7266: }
7267:
7268: sub userlogdisplay_navlinks {
7269: my ($curr,$more_records) = @_;
7270: return unless(ref($curr) eq 'HASH');
7271: # Navigation Buttons
7272: my $nav_links = '<p>';
7273: if (($curr->{'page'} > 1) || ($more_records)) {
7274: if (($curr->{'page'} > 1) && ($curr->{'show'} !~ /\D/)) {
7275: $nav_links .= '<input type="button"'
7276: .' onclick="javascript:chgPage('."'previous'".');"'
7277: .' value="'.&mt('Previous [_1] changes',$curr->{'show'})
7278: .'" /> ';
7279: }
7280: if ($more_records) {
7281: $nav_links .= '<input type="button"'
7282: .' onclick="javascript:chgPage('."'next'".');"'
7283: .' value="'.&mt('Next [_1] changes',$curr->{'show'})
7284: .'" />';
1.301 bisitz 7285: }
7286: }
1.406.2.5 raeburn 7287: $nav_links .= '</p>';
7288: return $nav_links;
1.239 raeburn 7289: }
7290:
7291: sub role_display_filter {
1.363 raeburn 7292: my ($context,$formname,$cdom,$cnum,$curr,$version,$crstype) = @_;
7293: my $lctype;
7294: if ($context eq 'course') {
7295: $lctype = lc($crstype);
7296: }
1.239 raeburn 7297: my $nolink = 1;
7298: my $output = '<table><tr><td valign="top">'.
1.301 bisitz 7299: '<span class="LC_nobreak"><b>'.&mt('Changes/page:').'</b></span><br />'.
1.239 raeburn 7300: &Apache::lonmeta::selectbox('show',$curr->{'show'},undef,
7301: (&mt('all'),5,10,20,50,100,1000,10000)).
7302: '</td><td> </td>';
7303: my $startform =
7304: &Apache::lonhtmlcommon::date_setter($formname,'rolelog_start_date',
7305: $curr->{'rolelog_start_date'},undef,
7306: undef,undef,undef,undef,undef,undef,$nolink);
7307: my $endform =
7308: &Apache::lonhtmlcommon::date_setter($formname,'rolelog_end_date',
7309: $curr->{'rolelog_end_date'},undef,
7310: undef,undef,undef,undef,undef,undef,$nolink);
1.363 raeburn 7311: my %lt = &rolechg_contexts($context,$crstype);
1.301 bisitz 7312: $output .= '<td valign="top"><b>'.&mt('Window during which changes occurred:').'</b><br />'.
7313: '<table><tr><td>'.&mt('After:').
7314: '</td><td>'.$startform.'</td></tr>'.
7315: '<tr><td>'.&mt('Before:').'</td>'.
7316: '<td>'.$endform.'</td></tr></table>'.
7317: '</td>'.
7318: '<td> </td>'.
1.239 raeburn 7319: '<td valign="top"><b>'.&mt('Role:').'</b><br />'.
7320: '<select name="role"><option value="any"';
7321: if ($curr->{'role'} eq 'any') {
7322: $output .= ' selected="selected"';
7323: }
7324: $output .= '>'.&mt('Any').'</option>'."\n";
1.363 raeburn 7325: my @roles = &Apache::lonuserutils::roles_by_context($context,1,$crstype);
1.239 raeburn 7326: foreach my $role (@roles) {
7327: my $plrole;
7328: if ($role eq 'cr') {
7329: $plrole = &mt('Custom Role');
7330: } else {
1.318 raeburn 7331: $plrole=&Apache::lonnet::plaintext($role,$crstype);
1.239 raeburn 7332: }
7333: my $selstr = '';
7334: if ($role eq $curr->{'role'}) {
7335: $selstr = ' selected="selected"';
7336: }
7337: $output .= ' <option value="'.$role.'"'.$selstr.'>'.$plrole.'</option>';
7338: }
1.301 bisitz 7339: $output .= '</select></td>'.
7340: '<td> </td>'.
7341: '<td valign="top"><b>'.
1.239 raeburn 7342: &mt('Context:').'</b><br /><select name="chgcontext">';
1.363 raeburn 7343: my @posscontexts;
7344: if ($context eq 'course') {
1.376 raeburn 7345: @posscontexts = ('any','automated','updatenow','createcourse','course','domain','selfenroll','requestcourses');
1.363 raeburn 7346: } elsif ($context eq 'domain') {
7347: @posscontexts = ('any','domain','requestauthor','domconfig','server');
7348: } else {
7349: @posscontexts = ('any','author','domain');
7350: }
7351: foreach my $chgtype (@posscontexts) {
1.239 raeburn 7352: my $selstr = '';
7353: if ($curr->{'chgcontext'} eq $chgtype) {
1.301 bisitz 7354: $selstr = ' selected="selected"';
1.239 raeburn 7355: }
1.363 raeburn 7356: if ($context eq 'course') {
1.376 raeburn 7357: if (($chgtype eq 'automated') || ($chgtype eq 'updatenow')) {
1.363 raeburn 7358: next if (!&Apache::lonnet::auto_run($cnum,$cdom));
7359: }
1.239 raeburn 7360: }
7361: $output .= '<option value="'.$chgtype.'"'.$selstr.'>'.$lt{$chgtype}.'</option>'."\n";
1.248 raeburn 7362: }
1.303 bisitz 7363: $output .= '</select></td>'
7364: .'</tr></table>';
7365:
7366: # Update Display button
7367: $output .= '<p>'
7368: .'<input type="submit" value="'.&mt('Update Display').'" />'
7369: .'</p>';
7370:
7371: # Server version info
1.363 raeburn 7372: my $needsrev = '2.11.0';
7373: if ($context eq 'course') {
7374: $needsrev = '2.7.0';
7375: }
7376:
1.303 bisitz 7377: $output .= '<p class="LC_info">'
7378: .&mt('Only changes made from servers running LON-CAPA [_1] or later are displayed.'
1.363 raeburn 7379: ,$needsrev);
1.248 raeburn 7380: if ($version) {
1.303 bisitz 7381: $output .= ' '.&mt('This LON-CAPA server is version [_1]',$version);
7382: }
7383: $output .= '</p><hr />';
1.239 raeburn 7384: return $output;
7385: }
7386:
7387: sub rolechg_contexts {
1.363 raeburn 7388: my ($context,$crstype) = @_;
7389: my %lt;
7390: if ($context eq 'course') {
7391: %lt = &Apache::lonlocal::texthash (
1.239 raeburn 7392: any => 'Any',
1.376 raeburn 7393: automated => 'Automated Enrollment',
1.239 raeburn 7394: updatenow => 'Roster Update',
7395: createcourse => 'Course Creation',
7396: course => 'User Management in course',
7397: domain => 'User Management in domain',
1.313 raeburn 7398: selfenroll => 'Self-enrolled',
1.318 raeburn 7399: requestcourses => 'Course Request',
1.239 raeburn 7400: );
1.363 raeburn 7401: if ($crstype eq 'Community') {
7402: $lt{'createcourse'} = &mt('Community Creation');
7403: $lt{'course'} = &mt('User Management in community');
7404: $lt{'requestcourses'} = &mt('Community Request');
7405: }
7406: } elsif ($context eq 'domain') {
7407: %lt = &Apache::lonlocal::texthash (
7408: any => 'Any',
7409: domain => 'User Management in domain',
7410: requestauthor => 'Authoring Request',
7411: server => 'Command line script (DC role)',
7412: domconfig => 'Self-enrolled',
7413: );
7414: } else {
7415: %lt = &Apache::lonlocal::texthash (
7416: any => 'Any',
7417: domain => 'User Management in domain',
7418: author => 'User Management by author',
7419: );
7420: }
1.239 raeburn 7421: return %lt;
7422: }
7423:
1.406.2.10 raeburn 7424: sub print_helpdeskaccess_display {
7425: my ($r,$permission,$brcrum) = @_;
7426: my $formname = 'helpdeskaccess';
7427: my $helpitem = 'Course_Helpdesk_Access';
7428: push (@{$brcrum},
7429: {href => '/adm/createuser?action=helpdesk',
7430: text => 'Helpdesk Access',
7431: help => $helpitem});
7432: my $bread_crumbs_component = 'Helpdesk Staff Access';
7433: my $args = { bread_crumbs => $brcrum,
7434: bread_crumbs_component => $bread_crumbs_component};
7435:
7436: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
7437: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
7438: my $confname = $cdom.'-domainconfig';
7439: my $crstype = &Apache::loncommon::course_type();
7440:
1.406.2.12 raeburn 7441: my @accesstypes = ('all','dh','da','none');
1.406.2.10 raeburn 7442: my ($numstatustypes,@jsarray);
7443: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($cdom);
7444: if (ref($types) eq 'ARRAY') {
7445: if (@{$types} > 0) {
7446: $numstatustypes = scalar(@{$types});
7447: push(@accesstypes,'status');
7448: @jsarray = ('bystatus');
7449: }
7450: }
7451: my %customroles = &get_domain_customroles($cdom,$confname);
1.406.2.12 raeburn 7452: my %domhelpdesk = &Apache::lonnet::get_active_domroles($cdom,['dh','da']);
1.406.2.10 raeburn 7453: if (keys(%domhelpdesk)) {
7454: push(@accesstypes,('inc','exc'));
7455: push(@jsarray,('notinc','notexc'));
7456: }
7457: push(@jsarray,'privs');
7458: my $hiddenstr = join("','",@jsarray);
7459: my $rolestr = join("','",sort(keys(%customroles)));
7460:
7461: my $jscript;
7462: my (%settings,%overridden);
7463: if (keys(%customroles)) {
7464: &get_adhocrole_settings($env{'request.course.id'},\@accesstypes,
7465: $types,\%customroles,\%settings,\%overridden);
7466: my %jsfull=();
7467: my %jslevels= (
7468: course => {},
7469: domain => {},
7470: system => {},
7471: );
7472: my %jslevelscurrent=(
7473: course => {},
7474: domain => {},
7475: system => {},
7476: );
7477: my (%privs,%jsprivs);
7478: &Apache::lonuserutils::custom_role_privs(\%privs,\%jsfull,\%jslevels,\%jslevelscurrent);
7479: foreach my $priv (keys(%jsfull)) {
7480: if ($jslevels{'course'}{$priv}) {
7481: $jsprivs{$priv} = 1;
7482: }
7483: }
7484: my (%elements,%stored);
7485: foreach my $role (keys(%customroles)) {
7486: $elements{$role.'_access'} = 'radio';
7487: $elements{$role.'_incrs'} = 'radio';
7488: if ($numstatustypes) {
7489: $elements{$role.'_status'} = 'checkbox';
7490: }
7491: if (keys(%domhelpdesk) > 0) {
7492: $elements{$role.'_staff_inc'} = 'checkbox';
7493: $elements{$role.'_staff_exc'} = 'checkbox';
7494: }
7495: $elements{$role.'_override'} = 'checkbox';
7496: if (ref($settings{$role}) eq 'HASH') {
7497: if ($settings{$role}{'access'} ne '') {
7498: my $curraccess = $settings{$role}{'access'};
7499: $stored{$role.'_access'} = $curraccess;
7500: $stored{$role.'_incrs'} = 1;
7501: if ($curraccess eq 'status') {
7502: if (ref($settings{$role}{'status'}) eq 'ARRAY') {
7503: $stored{$role.'_status'} = $settings{$role}{'status'};
7504: }
7505: } elsif (($curraccess eq 'exc') || ($curraccess eq 'inc')) {
7506: if (ref($settings{$role}{$curraccess}) eq 'ARRAY') {
7507: $stored{$role.'_staff_'.$curraccess} = $settings{$role}{$curraccess};
7508: }
7509: }
7510: } else {
7511: $stored{$role.'_incrs'} = 0;
7512: }
7513: $stored{$role.'_override'} = [];
7514: if ($env{'course.'.$env{'request.course.id'}.'.internal.adhocpriv.'.$role}) {
7515: if (ref($settings{$role}{'off'}) eq 'ARRAY') {
7516: foreach my $priv (@{$settings{$role}{'off'}}) {
7517: push(@{$stored{$role.'_override'}},$priv);
7518: }
7519: }
7520: if (ref($settings{$role}{'on'}) eq 'ARRAY') {
7521: foreach my $priv (@{$settings{$role}{'on'}}) {
7522: unless (grep(/^$priv$/,@{$stored{$role.'_override'}})) {
7523: push(@{$stored{$role.'_override'}},$priv);
7524: }
7525: }
7526: }
7527: }
7528: } else {
7529: $stored{$role.'_incrs'} = 0;
7530: }
7531: }
7532: $jscript = &Apache::lonhtmlcommon::set_form_elements(\%elements,\%stored);
7533: }
7534:
7535: my $js = <<"ENDJS";
7536: <script type="text/javascript">
7537: // <![CDATA[
7538: $jscript;
7539:
7540: function switchRoleTab(caller,role) {
7541: if (document.getElementById(role+'_maindiv')) {
7542: if (caller.id != 'LC_current_minitab') {
7543: if (document.getElementById('LC_current_minitab')) {
7544: document.getElementById('LC_current_minitab').id=null;
7545: }
7546: var roledivs = Array('$rolestr');
7547: if (roledivs.length > 0) {
7548: for (var i=0; i<roledivs.length; i++) {
7549: if (document.getElementById(roledivs[i]+'_maindiv')) {
7550: document.getElementById(roledivs[i]+'_maindiv').style.display='none';
7551: }
7552: }
7553: }
7554: caller.id = 'LC_current_minitab';
7555: document.getElementById(role+'_maindiv').style.display='block';
7556: }
7557: }
7558: return false;
7559: }
7560:
7561: function helpdeskAccess(role) {
7562: var curraccess = null;
7563: if (document.$formname.elements[role+'_access'].length) {
7564: for (var i=0; i<document.$formname.elements[role+'_access'].length; i++) {
7565: if (document.$formname.elements[role+'_access'][i].checked) {
7566: curraccess = document.$formname.elements[role+'_access'][i].value;
7567: }
7568: }
7569: }
7570: var shown = Array();
7571: var hidden = Array();
7572: if (curraccess == 'none') {
7573: hidden = Array ('$hiddenstr');
7574: } else {
7575: if (curraccess == 'status') {
7576: shown = Array ('bystatus','privs');
7577: hidden = Array ('notinc','notexc');
7578: } else {
7579: if (curraccess == 'exc') {
7580: shown = Array ('notexc','privs');
7581: hidden = Array ('notinc','bystatus');
7582: }
7583: if (curraccess == 'inc') {
7584: shown = Array ('notinc','privs');
7585: hidden = Array ('notexc','bystatus');
7586: }
7587: if (curraccess == 'all') {
7588: shown = Array ('privs');
7589: hidden = Array ('notinc','notexc','bystatus');
7590: }
7591: }
7592: }
7593: if (hidden.length > 0) {
7594: for (var i=0; i<hidden.length; i++) {
7595: if (document.getElementById(role+'_'+hidden[i])) {
7596: document.getElementById(role+'_'+hidden[i]).style.display = 'none';
7597: }
7598: }
7599: }
7600: if (shown.length > 0) {
7601: for (var i=0; i<shown.length; i++) {
7602: if (document.getElementById(role+'_'+shown[i])) {
7603: if (shown[i] == 'privs') {
7604: document.getElementById(role+'_'+shown[i]).style.display = 'block';
7605: } else {
7606: document.getElementById(role+'_'+shown[i]).style.display = 'inline';
7607: }
7608: }
7609: }
7610: }
7611: return;
7612: }
7613:
7614: function toggleAccess(role) {
7615: if ((document.getElementById(role+'_setincrs')) &&
7616: (document.getElementById(role+'_setindom'))) {
7617: for (var i=0; i<document.$formname.elements[role+'_incrs'].length; i++) {
7618: if (document.$formname.elements[role+'_incrs'][i].checked) {
7619: if (document.$formname.elements[role+'_incrs'][i].value == 1) {
7620: document.getElementById(role+'_setindom').style.display = 'none';
7621: document.getElementById(role+'_setincrs').style.display = 'block';
7622: } else {
7623: document.getElementById(role+'_setincrs').style.display = 'none';
7624: document.getElementById(role+'_setindom').style.display = 'block';
7625: }
7626: break;
7627: }
7628: }
7629: }
7630: return;
7631: }
7632:
7633: // ]]>
7634: </script>
7635: ENDJS
7636:
7637: $args->{add_entries} = {onload => "javascript:setFormElements(document.$formname)"};
7638:
7639: # print page header
7640: $r->print(&header($js,$args));
7641: # print form header
7642: $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">');
7643:
7644: if (keys(%customroles)) {
7645: my %lt = &Apache::lonlocal::texthash(
7646: 'aco' => 'As course owner you may override the defaults set in the domain for role usage and/or privileges.',
7647: 'rou' => 'Role usage',
7648: 'whi' => 'Which helpdesk personnel may use this role?',
7649: 'udd' => 'Use domain default',
1.406.2.12 raeburn 7650: 'all' => 'All with domain helpdesk or helpdesk assistant role',
7651: 'dh' => 'All with domain helpdesk role',
7652: 'da' => 'All with domain helpdesk assistant role',
1.406.2.10 raeburn 7653: 'none' => 'None',
7654: 'status' => 'Determined based on institutional status',
7655: 'inc' => 'Include all, but exclude specific personnel',
7656: 'exc' => 'Exclude all, but include specific personnel',
7657: 'hel' => 'Helpdesk',
7658: 'rpr' => 'Role privileges',
7659: );
7660: $lt{'tfh'} = &mt("Custom [_1]ad hoc[_2] course roles available for use by the domain's helpdesk are as follows",'<i>','</i>');
7661: my %domconfig = &Apache::lonnet::get_dom('configuration',['helpsettings'],$cdom);
7662: my (%domcurrent,%ordered,%description,%domusage,$disabled);
7663: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
7664: if (ref($domconfig{'helpsettings'}{'adhoc'}) eq 'HASH') {
7665: %domcurrent = %{$domconfig{'helpsettings'}{'adhoc'}};
7666: }
7667: }
7668: my $count = 0;
7669: foreach my $role (sort(keys(%customroles))) {
7670: my ($order,$desc,$access_in_dom);
7671: if (ref($domcurrent{$role}) eq 'HASH') {
7672: $order = $domcurrent{$role}{'order'};
7673: $desc = $domcurrent{$role}{'desc'};
7674: $access_in_dom = $domcurrent{$role}{'access'};
7675: }
7676: if ($order eq '') {
7677: $order = $count;
7678: }
7679: $ordered{$order} = $role;
7680: if ($desc ne '') {
7681: $description{$role} = $desc;
7682: } else {
7683: $description{$role}= $role;
7684: }
7685: $count++;
7686: }
7687: %domusage = &domain_adhoc_access(\%customroles,\%domcurrent,\@accesstypes,$usertypes,$othertitle);
7688: my @roles_by_num = ();
7689: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
7690: push(@roles_by_num,$ordered{$item});
7691: }
7692: $r->print('<p>'.$lt{'tfh'}.': <i>'.join('</i>, <i>',map { $description{$_}; } @roles_by_num).'</i>.');
7693: if ($permission->{'owner'}) {
7694: $r->print('<br />'.$lt{'aco'}.'</p><p>');
7695: $r->print('<input type="hidden" name="state" value="process" />'.
7696: '<input type="submit" value="'.&mt('Save changes').'" />');
7697: } else {
7698: if ($env{'course.'.$env{'request.course.id'}.'.internal.courseowner'}) {
7699: my ($ownername,$ownerdom) = split(/:/,$env{'course.'.$env{'request.course.id'}.'.internal.courseowner'});
7700: $r->print('<br />'.&mt('The course owner -- [_1] -- can override the default access and/or privileges for these ad hoc roles.',
7701: &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($ownername,$ownerdom),$ownername,$ownerdom)));
7702: }
7703: $disabled = ' disabled="disabled"';
7704: }
7705: $r->print('</p>');
7706:
7707: $r->print('<div id="LC_minitab_header"><ul>');
7708: my $count = 0;
7709: my %visibility;
7710: foreach my $role (@roles_by_num) {
7711: my $id;
7712: if ($count == 0) {
7713: $id=' id="LC_current_minitab"';
7714: $visibility{$role} = ' style="display:block"';
7715: } else {
7716: $visibility{$role} = ' style="display:none"';
7717: }
7718: $count ++;
7719: $r->print('<li'.$id.'><a href="#" onclick="javascript:switchRoleTab(this.parentNode,'."'$role'".');">'.$description{$role}.'</a></li>');
7720: }
7721: $r->print('</ul></div>');
7722:
7723: foreach my $role (@roles_by_num) {
7724: my %usecheck = (
7725: all => ' checked="checked"',
7726: );
7727: my %displaydiv = (
7728: status => 'none',
7729: inc => 'none',
7730: exc => 'none',
7731: priv => 'block',
7732: );
7733: my (%selected,$overridden,$incrscheck,$indomcheck,$indomvis,$incrsvis);
7734: if (ref($settings{$role}) eq 'HASH') {
7735: if ($settings{$role}{'access'} ne '') {
7736: $indomvis = ' style="display:none"';
7737: $incrsvis = ' style="display:block"';
7738: $incrscheck = ' checked="checked"';
7739: if ($settings{$role}{'access'} ne 'all') {
7740: $usecheck{$settings{$role}{'access'}} = $usecheck{'all'};
7741: delete($usecheck{'all'});
7742: if ($settings{$role}{'access'} eq 'status') {
7743: my $access = 'status';
7744: $displaydiv{$access} = 'inline';
7745: if (ref($settings{$role}{$access}) eq 'ARRAY') {
7746: $selected{$access} = $settings{$role}{$access};
7747: }
7748: } elsif ($settings{$role}{'access'} =~ /^(inc|exc)$/) {
7749: my $access = $1;
7750: $displaydiv{$access} = 'inline';
7751: if (ref($settings{$role}{$access}) eq 'ARRAY') {
7752: $selected{$access} = $settings{$role}{$access};
7753: }
7754: } elsif ($settings{$role}{'access'} eq 'none') {
7755: $displaydiv{'priv'} = 'none';
7756: }
7757: }
7758: } else {
7759: $indomcheck = ' checked="checked"';
7760: $indomvis = ' style="display:block"';
7761: $incrsvis = ' style="display:none"';
7762: }
7763: } else {
7764: $indomcheck = ' checked="checked"';
7765: $indomvis = ' style="display:block"';
7766: $incrsvis = ' style="display:none"';
7767: }
7768: $r->print('<div class="LC_left_float" id="'.$role.'_maindiv"'.$visibility{$role}.'>'.
7769: '<fieldset><legend>'.$lt{'rou'}.'</legend>'.
7770: '<p>'.$lt{'whi'}.' <span class="LC_nobreak">'.
7771: '<label><input type="radio" name="'.$role.'_incrs" value="1"'.$incrscheck.' onclick="toggleAccess('."'$role'".');"'.$disabled.'>'.
7772: &mt('Set here in [_1]',lc($crstype)).'</label>'.
7773: '<span>'.(' 'x2).
7774: '<label><input type="radio" name="'.$role.'_incrs" value="0"'.$indomcheck.' onclick="toggleAccess('."'$role'".');"'.$disabled.'>'.
7775: $lt{'udd'}.'</label><span></p>'.
7776: '<div id="'.$role.'_setindom"'.$indomvis.'>'.
7777: '<span class="LC_cusr_emph">'.$domusage{$role}.'</span></div>'.
7778: '<div id="'.$role.'_setincrs"'.$incrsvis.'>');
7779: foreach my $access (@accesstypes) {
7780: $r->print('<p><label><input type="radio" name="'.$role.'_access" value="'.$access.'" '.$usecheck{$access}.
7781: ' onclick="helpdeskAccess('."'$role'".');"'.$disabled.' />'.$lt{$access}.'</label>');
7782: if ($access eq 'status') {
7783: $r->print('<div id="'.$role.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
7784: &Apache::lonuserutils::adhoc_status_types($cdom,undef,$role,$selected{$access},
7785: $othertitle,$usertypes,$types,$disabled).
7786: '</div>');
7787: } elsif (($access eq 'inc') && (keys(%domhelpdesk) > 0)) {
7788: $r->print('<div id="'.$role.'_notinc" style="display:'.$displaydiv{$access}.'">'.
7789: &Apache::lonuserutils::adhoc_staff($access,undef,$role,$selected{$access},
7790: \%domhelpdesk,$disabled).
7791: '</div>');
7792: } elsif (($access eq 'exc') && (keys(%domhelpdesk) > 0)) {
7793: $r->print('<div id="'.$role.'_notexc" style="display:'.$displaydiv{$access}.'">'.
7794: &Apache::lonuserutils::adhoc_staff($access,undef,$role,$selected{$access},
7795: \%domhelpdesk,$disabled).
7796: '</div>');
7797: }
7798: $r->print('</p>');
7799: }
7800: $r->print('</div></fieldset>');
7801: my %full=();
7802: my %levels= (
7803: course => {},
7804: domain => {},
7805: system => {},
7806: );
7807: my %levelscurrent=(
7808: course => {},
7809: domain => {},
7810: system => {},
7811: );
7812: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
7813: $r->print('<fieldset id="'.$role.'_privs" style="display:'.$displaydiv{'priv'}.'">'.
7814: '<legend>'.$lt{'rpr'}.'</legend>'.
7815: &role_priv_table($role,$permission,$crstype,\%full,\%levels,\%levelscurrent,$overridden{$role}).
7816: '</fieldset></div><div style="padding:0;clear:both;margin:0;border:0"></div>');
7817: }
7818: if ($permission->{'owner'}) {
7819: $r->print('<p><input type="submit" value="'.&mt('Save changes').'" /></p>');
7820: }
7821: } else {
7822: $r->print(&mt('Helpdesk roles have not yet been created in this domain.'));
7823: }
7824: # Form Footer
7825: $r->print('<input type="hidden" name="action" value="helpdesk" />'
7826: .'</form>');
7827: return;
7828: }
7829:
7830: sub domain_adhoc_access {
7831: my ($roles,$domcurrent,$accesstypes,$usertypes,$othertitle) = @_;
7832: my %domusage;
7833: return unless ((ref($roles) eq 'HASH') && (ref($domcurrent) eq 'HASH') && (ref($accesstypes) eq 'ARRAY'));
7834: foreach my $role (keys(%{$roles})) {
7835: if (ref($domcurrent->{$role}) eq 'HASH') {
7836: my $access = $domcurrent->{$role}{'access'};
7837: if (($access eq '') || (!grep(/^\Q$access\E$/,@{$accesstypes}))) {
7838: $access = 'all';
1.406.2.12 raeburn 7839: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role',&Apache::lonnet::plaintext('dh'),
7840: &Apache::lonnet::plaintext('da'));
1.406.2.10 raeburn 7841: } elsif ($access eq 'status') {
7842: if (ref($domcurrent->{$role}{$access}) eq 'ARRAY') {
7843: my @shown;
7844: foreach my $type (@{$domcurrent->{$role}{$access}}) {
7845: unless ($type eq 'default') {
7846: if ($usertypes->{$type}) {
7847: push(@shown,$usertypes->{$type});
7848: }
7849: }
7850: }
7851: if (grep(/^default$/,@{$domcurrent->{$role}{$access}})) {
7852: push(@shown,$othertitle);
7853: }
7854: if (@shown) {
7855: my $shownstatus = join(' '.&mt('or').' ',@shown);
1.406.2.12 raeburn 7856: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role, and institutional status: [_3]',
7857: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'),$shownstatus);
1.406.2.10 raeburn 7858: } else {
7859: $domusage{$role} = &mt('No one in the domain');
7860: }
7861: }
7862: } elsif ($access eq 'inc') {
7863: my @dominc = ();
7864: if (ref($domcurrent->{$role}{'inc'}) eq 'ARRAY') {
7865: foreach my $user (@{$domcurrent->{$role}{'inc'}}) {
7866: my ($uname,$udom) = split(/:/,$user);
7867: push(@dominc,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),$uname,$udom));
7868: }
7869: my $showninc = join(', ',@dominc);
7870: if ($showninc ne '') {
1.406.2.12 raeburn 7871: $domusage{$role} = &mt('Include any user in domain with active [_1] or [_2] role, except: [_3]',
7872: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'),$showninc);
1.406.2.10 raeburn 7873: } else {
1.406.2.12 raeburn 7874: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role',
7875: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'));
1.406.2.10 raeburn 7876: }
7877: }
7878: } elsif ($access eq 'exc') {
7879: my @domexc = ();
7880: if (ref($domcurrent->{$role}{'exc'}) eq 'ARRAY') {
7881: foreach my $user (@{$domcurrent->{$role}{'exc'}}) {
7882: my ($uname,$udom) = split(/:/,$user);
7883: push(@domexc,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),$uname,$udom));
7884: }
7885: }
7886: my $shownexc = join(', ',@domexc);
7887: if ($shownexc ne '') {
1.406.2.12 raeburn 7888: $domusage{$role} = &mt('Only the following in the domain with active [_1] or [_2] role: [_3]',
7889: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'),$shownexc);
1.406.2.10 raeburn 7890: } else {
7891: $domusage{$role} = &mt('No one in the domain');
7892: }
7893: } elsif ($access eq 'none') {
7894: $domusage{$role} = &mt('No one in the domain');
1.406.2.12 raeburn 7895: } elsif ($access eq 'dh') {
1.406.2.10 raeburn 7896: $domusage{$role} = &mt('Any user in domain with active [_1] role',&Apache::lonnet::plaintext('dh'));
1.406.2.12 raeburn 7897: } elsif ($access eq 'da') {
7898: $domusage{$role} = &mt('Any user in domain with active [_1] role',&Apache::lonnet::plaintext('da'));
7899: } elsif ($access eq 'all') {
7900: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role',
7901: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'));
1.406.2.10 raeburn 7902: }
7903: } else {
1.406.2.12 raeburn 7904: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role',
7905: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'));
1.406.2.10 raeburn 7906: }
7907: }
7908: return %domusage;
7909: }
7910:
7911: sub get_domain_customroles {
7912: my ($cdom,$confname) = @_;
7913: my %existing=&Apache::lonnet::dump('roles',$cdom,$confname,'rolesdef_');
7914: my %customroles;
7915: foreach my $key (keys(%existing)) {
7916: if ($key=~/^rolesdef\_(\w+)$/) {
7917: my $rolename = $1;
7918: my %privs;
7919: ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
7920: $customroles{$rolename} = \%privs;
7921: }
7922: }
7923: return %customroles;
7924: }
7925:
7926: sub role_priv_table {
7927: my ($role,$permission,$crstype,$full,$levels,$levelscurrent,$overridden) = @_;
7928: return unless ((ref($full) eq 'HASH') && (ref($levels) eq 'HASH') &&
7929: (ref($levelscurrent) eq 'HASH'));
7930: my %lt=&Apache::lonlocal::texthash (
7931: 'crl' => 'Course Level Privilege',
7932: 'def' => 'Domain Defaults',
7933: 'ove' => 'Override in Course',
7934: 'ine' => 'In effect',
7935: 'dis' => 'Disabled',
7936: 'ena' => 'Enabled',
7937: );
7938: if ($crstype eq 'Community') {
7939: $lt{'ove'} = 'Override in Community',
7940: }
7941: my @status = ('Disabled','Enabled');
7942: my (%on,%off);
7943: if (ref($overridden) eq 'HASH') {
7944: if (ref($overridden->{'on'}) eq 'ARRAY') {
7945: map { $on{$_} = 1; } (@{$overridden->{'on'}});
7946: }
7947: if (ref($overridden->{'off'}) eq 'ARRAY') {
7948: map { $off{$_} = 1; } (@{$overridden->{'off'}});
7949: }
7950: }
7951: my $output=&Apache::loncommon::start_data_table().
7952: &Apache::loncommon::start_data_table_header_row().
7953: '<th>'.$lt{'crl'}.'</th><th>'.$lt{'def'}.'</th><th>'.$lt{'ove'}.
7954: '</th><th>'.$lt{'ine'}.'</th>'.
7955: &Apache::loncommon::end_data_table_header_row();
7956: foreach my $priv (sort(keys(%{$full}))) {
7957: next unless ($levels->{'course'}{$priv});
7958: my $privtext = &Apache::lonnet::plaintext($priv,$crstype);
7959: my ($default,$ineffect);
7960: if ($levelscurrent->{'course'}{$priv}) {
7961: $default = '<img src="/adm/lonIcons/navmap.correct.gif" alt="'.$lt{'ena'}.'" />';
7962: $ineffect = $default;
7963: }
7964: my ($customstatus,$checked);
7965: $output .= &Apache::loncommon::start_data_table_row().
7966: '<td>'.$privtext.'</td>'.
7967: '<td>'.$default.'</td><td>';
7968: if (($levelscurrent->{'course'}{$priv}) && ($off{$priv})) {
7969: if ($permission->{'owner'}) {
7970: $checked = ' checked="checked"';
7971: }
7972: $customstatus = '<img src="/adm/lonIcons/navmap.wrong.gif" alt="'.$lt{'dis'}.'" />';
7973: $ineffect = $customstatus;
7974: } elsif ((!$levelscurrent->{'course'}{$priv}) && ($on{$priv})) {
7975: if ($permission->{'owner'}) {
7976: $checked = ' checked="checked"';
7977: }
7978: $customstatus = '<img src="/adm/lonIcons/navmap.correct.gif" alt="'.$lt{'ena'}.'" />';
7979: $ineffect = $customstatus;
7980: }
7981: if ($permission->{'owner'}) {
7982: $output .= '<input type="checkbox" name="'.$role.'_override" value="'.$priv.'"'.$checked.' />';
7983: } else {
7984: $output .= $customstatus;
7985: }
7986: $output .= '</td><td>'.$ineffect.'</td>'.
7987: &Apache::loncommon::end_data_table_row();
7988: }
7989: $output .= &Apache::loncommon::end_data_table();
7990: return $output;
7991: }
7992:
7993: sub get_adhocrole_settings {
7994: my ($cid,$accesstypes,$types,$customroles,$settings,$overridden) = @_;
7995: return unless ((ref($accesstypes) eq 'ARRAY') && (ref($customroles) eq 'HASH') &&
7996: (ref($settings) eq 'HASH') && (ref($overridden) eq 'HASH'));
7997: foreach my $role (split(/,/,$env{'course.'.$cid.'.internal.adhocaccess'})) {
7998: my ($curraccess,$rest) = split(/=/,$env{'course.'.$cid.'.internal.adhoc.'.$role});
7999: if (($curraccess ne '') && (grep(/^\Q$curraccess\E$/,@{$accesstypes}))) {
8000: $settings->{$role}{'access'} = $curraccess;
8001: if (($curraccess eq 'status') && (ref($types) eq 'ARRAY')) {
8002: my @status = split(/,/,$rest);
8003: my @currstatus;
8004: foreach my $type (@status) {
8005: if ($type eq 'default') {
8006: push(@currstatus,$type);
8007: } elsif (grep(/^\Q$type\E$/,@{$types})) {
8008: push(@currstatus,$type);
8009: }
8010: }
8011: if (@currstatus) {
8012: $settings->{$role}{$curraccess} = \@currstatus;
8013: } elsif (($curraccess eq 'exc') || ($curraccess eq 'inc')) {
8014: my @personnel = split(/,/,$rest);
8015: $settings->{$role}{$curraccess} = \@personnel;
8016: }
8017: }
8018: }
8019: }
8020: foreach my $role (keys(%{$customroles})) {
8021: if ($env{'course.'.$cid.'.internal.adhocpriv.'.$role}) {
8022: my %currentprivs;
8023: if (ref($customroles->{$role}) eq 'HASH') {
8024: if (exists($customroles->{$role}{'course'})) {
8025: my %full=();
8026: my %levels= (
8027: course => {},
8028: domain => {},
8029: system => {},
8030: );
8031: my %levelscurrent=(
8032: course => {},
8033: domain => {},
8034: system => {},
8035: );
8036: &Apache::lonuserutils::custom_role_privs($customroles->{$role},\%full,\%levels,\%levelscurrent);
8037: %currentprivs = %{$levelscurrent{'course'}};
8038: }
8039: }
8040: foreach my $item (split(/,/,$env{'course.'.$cid.'.internal.adhocpriv.'.$role})) {
8041: next if ($item eq '');
8042: my ($rule,$rest) = split(/=/,$item);
8043: next unless (($rule eq 'off') || ($rule eq 'on'));
8044: foreach my $priv (split(/:/,$rest)) {
8045: if ($priv ne '') {
8046: if ($rule eq 'off') {
8047: push(@{$overridden->{$role}{'off'}},$priv);
8048: if ($currentprivs{$priv}) {
8049: push(@{$settings->{$role}{'off'}},$priv);
8050: }
8051: } else {
8052: push(@{$overridden->{$role}{'on'}},$priv);
8053: unless ($currentprivs{$priv}) {
8054: push(@{$settings->{$role}{'on'}},$priv);
8055: }
8056: }
8057: }
8058: }
8059: }
8060: }
8061: }
8062: return;
8063: }
8064:
8065: sub update_helpdeskaccess {
8066: my ($r,$permission,$brcrum) = @_;
8067: my $helpitem = 'Course_Helpdesk_Access';
8068: push (@{$brcrum},
8069: {href => '/adm/createuser?action=helpdesk',
8070: text => 'Helpdesk Access',
8071: help => $helpitem},
8072: {href => '/adm/createuser?action=helpdesk',
8073: text => 'Result',
8074: help => $helpitem}
8075: );
8076: my $bread_crumbs_component = 'Helpdesk Staff Access';
8077: my $args = { bread_crumbs => $brcrum,
8078: bread_crumbs_component => $bread_crumbs_component};
8079:
8080: # print page header
8081: $r->print(&header('',$args));
8082: unless ((ref($permission) eq 'HASH') && ($permission->{'owner'})) {
8083: $r->print('<p class="LC_error">'.&mt('You do not have permission to change helpdesk access.').'</p>');
8084: return;
8085: }
1.406.2.12 raeburn 8086: my @accesstypes = ('all','dh','da','none','status','inc','exc');
1.406.2.10 raeburn 8087: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
8088: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
8089: my $confname = $cdom.'-domainconfig';
8090: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($cdom);
8091: my $crstype = &Apache::loncommon::course_type();
8092: my %customroles = &get_domain_customroles($cdom,$confname);
8093: my (%settings,%overridden);
8094: &get_adhocrole_settings($env{'request.course.id'},\@accesstypes,
8095: $types,\%customroles,\%settings,\%overridden);
1.406.2.12 raeburn 8096: my %domhelpdesk = &Apache::lonnet::get_active_domroles($cdom,['dh','da']);
1.406.2.10 raeburn 8097: my (%changed,%storehash,@todelete);
8098:
8099: if (keys(%customroles)) {
8100: my (%newsettings,@incrs);
8101: foreach my $role (keys(%customroles)) {
8102: $newsettings{$role} = {
8103: access => '',
8104: status => '',
8105: exc => '',
8106: inc => '',
8107: on => '',
8108: off => '',
8109: };
8110: my %current;
8111: if (ref($settings{$role}) eq 'HASH') {
8112: %current = %{$settings{$role}};
8113: }
8114: if (ref($overridden{$role}) eq 'HASH') {
8115: $current{'overridden'} = $overridden{$role};
8116: }
8117: if ($env{'form.'.$role.'_incrs'}) {
8118: my $access = $env{'form.'.$role.'_access'};
8119: if (grep(/^\Q$access\E$/,@accesstypes)) {
8120: push(@incrs,$role);
8121: unless ($current{'access'} eq $access) {
8122: $changed{$role}{'access'} = 1;
8123: $storehash{'internal.adhoc.'.$role} = $access;
8124: }
8125: if ($access eq 'status') {
8126: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$role.'_status');
8127: my @stored;
8128: my @shownstatus;
8129: if (ref($types) eq 'ARRAY') {
8130: foreach my $type (sort(@statuses)) {
8131: if ($type eq 'default') {
8132: push(@stored,$type);
8133: } elsif (grep(/^\Q$type\E$/,@{$types})) {
8134: push(@stored,$type);
8135: push(@shownstatus,$usertypes->{$type});
8136: }
8137: }
8138: if (grep(/^default$/,@statuses)) {
8139: push(@shownstatus,$othertitle);
8140: }
8141: $storehash{'internal.adhoc.'.$role} .= '='.join(',',@stored);
8142: }
8143: $newsettings{$role}{'status'} = join(' '.&mt('or').' ',@shownstatus);
8144: if (ref($current{'status'}) eq 'ARRAY') {
8145: my @diffs = &Apache::loncommon::compare_arrays(\@stored,$current{'status'});
8146: if (@diffs) {
8147: $changed{$role}{'status'} = 1;
8148: }
8149: } elsif (@stored) {
8150: $changed{$role}{'status'} = 1;
8151: }
8152: } elsif (($access eq 'inc') || ($access eq 'exc')) {
8153: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$role.'_staff_'.$access);
8154: my @newspecstaff;
8155: my @stored;
8156: my @currstaff;
8157: foreach my $person (sort(@personnel)) {
8158: if ($domhelpdesk{$person}) {
8159: push(@stored,$person);
8160: }
8161: }
8162: if (ref($current{$access}) eq 'ARRAY') {
8163: my @diffs = &Apache::loncommon::compare_arrays(\@stored,$current{$access});
8164: if (@diffs) {
8165: $changed{$role}{$access} = 1;
8166: }
8167: } elsif (@stored) {
8168: $changed{$role}{$access} = 1;
8169: }
8170: $storehash{'internal.adhoc.'.$role} .= '='.join(',',@stored);
8171: foreach my $person (@stored) {
8172: my ($uname,$udom) = split(/:/,$person);
8173: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
8174: }
8175: $newsettings{$role}{$access} = join(', ',sort(@newspecstaff));
8176: }
8177: $newsettings{$role}{'access'} = $access;
8178: }
8179: } else {
8180: if (($current{'access'} ne '') && (grep(/^\Q$current{'access'}\E$/,@accesstypes))) {
8181: $changed{$role}{'access'} = 1;
8182: $newsettings{$role} = {};
8183: push(@todelete,'internal.adhoc.'.$role);
8184: }
8185: }
8186: if (($env{'form.'.$role.'_incrs'}) && ($env{'form.'.$role.'_access'} eq 'none')) {
8187: if (ref($current{'overridden'}) eq 'HASH') {
8188: push(@todelete,'internal.adhocpriv.'.$role);
8189: }
8190: } else {
8191: my %full=();
8192: my %levels= (
8193: course => {},
8194: domain => {},
8195: system => {},
8196: );
8197: my %levelscurrent=(
8198: course => {},
8199: domain => {},
8200: system => {},
8201: );
8202: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
8203: my (@updatedon,@updatedoff,@override);
8204: @override = &Apache::loncommon::get_env_multiple('form.'.$role.'_override');
8205: if (@override) {
8206: foreach my $priv (sort(keys(%full))) {
8207: next unless ($levels{'course'}{$priv});
8208: if (grep(/^\Q$priv\E$/,@override)) {
8209: if ($levelscurrent{'course'}{$priv}) {
8210: push(@updatedoff,$priv);
8211: } else {
8212: push(@updatedon,$priv);
8213: }
8214: }
8215: }
8216: }
8217: if (@updatedon) {
8218: $newsettings{$role}{'on'} = join('</li><li>', map { &Apache::lonnet::plaintext($_,$crstype) } (@updatedon));
8219: }
8220: if (@updatedoff) {
8221: $newsettings{$role}{'off'} = join('</li><li>', map { &Apache::lonnet::plaintext($_,$crstype) } (@updatedoff));
8222: }
8223: if (ref($current{'overridden'}) eq 'HASH') {
8224: if (ref($current{'overridden'}{'on'}) eq 'ARRAY') {
8225: if (@updatedon) {
8226: my @diffs = &Apache::loncommon::compare_arrays(\@updatedon,$current{'overridden'}{'on'});
8227: if (@diffs) {
8228: $changed{$role}{'on'} = 1;
8229: }
8230: } else {
8231: $changed{$role}{'on'} = 1;
8232: }
8233: } elsif (@updatedon) {
8234: $changed{$role}{'on'} = 1;
8235: }
8236: if (ref($current{'overridden'}{'off'}) eq 'ARRAY') {
8237: if (@updatedoff) {
8238: my @diffs = &Apache::loncommon::compare_arrays(\@updatedoff,$current{'overridden'}{'off'});
8239: if (@diffs) {
8240: $changed{$role}{'off'} = 1;
8241: }
8242: } else {
8243: $changed{$role}{'off'} = 1;
8244: }
8245: } elsif (@updatedoff) {
8246: $changed{$role}{'off'} = 1;
8247: }
8248: } else {
8249: if (@updatedon) {
8250: $changed{$role}{'on'} = 1;
8251: }
8252: if (@updatedoff) {
8253: $changed{$role}{'off'} = 1;
8254: }
8255: }
8256: if (ref($changed{$role}) eq 'HASH') {
8257: if (($changed{$role}{'on'} || $changed{$role}{'off'})) {
8258: my $newpriv;
8259: if (@updatedon) {
8260: $newpriv = 'on='.join(':',@updatedon);
8261: }
8262: if (@updatedoff) {
8263: $newpriv .= ($newpriv ? ',' : '' ).'off='.join(':',@updatedoff);
8264: }
8265: if ($newpriv eq '') {
8266: push(@todelete,'internal.adhocpriv.'.$role);
8267: } else {
8268: $storehash{'internal.adhocpriv.'.$role} = $newpriv;
8269: }
8270: }
8271: }
8272: }
8273: }
8274: if (@incrs) {
8275: $storehash{'internal.adhocaccess'} = join(',',@incrs);
8276: } elsif (@todelete) {
8277: push(@todelete,'internal.adhocaccess');
8278: }
8279: if (keys(%changed)) {
8280: my ($putres,$delres);
8281: if (keys(%storehash)) {
8282: $putres = &Apache::lonnet::put('environment',\%storehash,$cdom,$cnum);
8283: my %newenvhash;
8284: foreach my $key (keys(%storehash)) {
8285: $newenvhash{'course.'.$env{'request.course.id'}.'.'.$key} = $storehash{$key};
8286: }
8287: &Apache::lonnet::appenv(\%newenvhash);
8288: }
8289: if (@todelete) {
8290: $delres = &Apache::lonnet::del('environment',\@todelete,$cdom,$cnum);
8291: foreach my $key (@todelete) {
8292: &Apache::lonnet::delenv('course.'.$env{'request.course.id'}.'.'.$key);
8293: }
8294: }
8295: if (($putres eq 'ok') || ($delres eq 'ok')) {
8296: my %domconfig = &Apache::lonnet::get_dom('configuration',['helpsettings'],$cdom);
8297: my (%domcurrent,%ordered,%description,%domusage);
8298: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
8299: if (ref($domconfig{'helpsettings'}{'adhoc'}) eq 'HASH') {
8300: %domcurrent = %{$domconfig{'helpsettings'}{'adhoc'}};
8301: }
8302: }
8303: my $count = 0;
8304: foreach my $role (sort(keys(%customroles))) {
8305: my ($order,$desc);
8306: if (ref($domcurrent{$role}) eq 'HASH') {
8307: $order = $domcurrent{$role}{'order'};
8308: $desc = $domcurrent{$role}{'desc'};
8309: }
8310: if ($order eq '') {
8311: $order = $count;
8312: }
8313: $ordered{$order} = $role;
8314: if ($desc ne '') {
8315: $description{$role} = $desc;
8316: } else {
8317: $description{$role}= $role;
8318: }
8319: $count++;
8320: }
8321: my @roles_by_num = ();
8322: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
8323: push(@roles_by_num,$ordered{$item});
8324: }
8325: %domusage = &domain_adhoc_access(\%changed,\%domcurrent,\@accesstypes,$usertypes,$othertitle);
8326: $r->print(&mt('Helpdesk access settings have been changed as follows').'<br />');
8327: $r->print('<ul>');
8328: foreach my $role (@roles_by_num) {
8329: next unless (ref($changed{$role}) eq 'HASH');
8330: $r->print('<li>'.&mt('Ad hoc role').': <b>'.$description{$role}.'</b>'.
8331: '<ul>');
8332: if ($changed{$role}{'access'} || $changed{$role}{'status'} || $changed{$role}{'inc'} || $changed{$role}{'exc'}) {
8333: $r->print('<li>');
8334: if ($env{'form.'.$role.'_incrs'}) {
8335: if ($newsettings{$role}{'access'} eq 'all') {
8336: $r->print(&mt('All helpdesk staff can access '.lc($crstype).' with this role.'));
1.406.2.12 raeburn 8337: } elsif ($newsettings{$role}{'access'} eq 'dh') {
8338: $r->print(&mt('Helpdesk staff can use this role if they have an active [_1] role',
8339: &Apache::lonnet::plaintext('dh')));
8340: } elsif ($newsettings{$role}{'access'} eq 'da') {
8341: $r->print(&mt('Helpdesk staff can use this role if they have an active [_1] role',
8342: &Apache::lonnet::plaintext('da')));
1.406.2.10 raeburn 8343: } elsif ($newsettings{$role}{'access'} eq 'none') {
8344: $r->print(&mt('No helpdesk staff can access '.lc($crstype).' with this role.'));
8345: } elsif ($newsettings{$role}{'access'} eq 'status') {
8346: if ($newsettings{$role}{'status'}) {
8347: my ($access,$rest) = split(/=/,$storehash{'internal.adhoc.'.$role});
8348: if (split(/,/,$rest) > 1) {
8349: $r->print(&mt('Helpdesk staff can use this role if their institutional type is one of: [_1].',
8350: $newsettings{$role}{'status'}));
8351: } else {
8352: $r->print(&mt('Helpdesk staff can use this role if their institutional type is: [_1].',
8353: $newsettings{$role}{'status'}));
8354: }
8355: } else {
8356: $r->print(&mt('No helpdesk staff can access '.lc($crstype).' with this role.'));
8357: }
8358: } elsif ($newsettings{$role}{'access'} eq 'exc') {
8359: if ($newsettings{$role}{'exc'}) {
8360: $r->print(&mt('Helpdesk staff who can use this role are as follows:').' '.$newsettings{$role}{'exc'}.'.');
8361: } else {
8362: $r->print(&mt('No helpdesk staff can access '.lc($crstype).' with this role.'));
8363: }
8364: } elsif ($newsettings{$role}{'access'} eq 'inc') {
8365: if ($newsettings{$role}{'inc'}) {
8366: $r->print(&mt('All helpdesk staff may use this role except the following:').' '.$newsettings{$role}{'inc'}.'.');
8367: } else {
8368: $r->print(&mt('All helpdesk staff may use this role.'));
8369: }
8370: }
8371: } else {
8372: $r->print(&mt('Default access set in the domain now applies.').'<br />'.
8373: '<span class="LC_cusr_emph">'.$domusage{$role}.'</span>');
8374: }
8375: $r->print('</li>');
8376: }
8377: unless ($newsettings{$role}{'access'} eq 'none') {
8378: if ($changed{$role}{'off'}) {
8379: if ($newsettings{$role}{'off'}) {
8380: $r->print('<li>'.&mt('Privileges which are available by default for this ad hoc role, but are disabled for this specific '.lc($crstype).':').
8381: '<ul><li>'.$newsettings{$role}{'off'}.'</li></ul></li>');
8382: } else {
8383: $r->print('<li>'.&mt('All privileges available by default for this ad hoc role are enabled.').'</li>');
8384: }
8385: }
8386: if ($changed{$role}{'on'}) {
8387: if ($newsettings{$role}{'on'}) {
8388: $r->print('<li>'.&mt('Privileges which are not available by default for this ad hoc role, but are enabled for this specific '.lc($crstype).':').
8389: '<ul><li>'.$newsettings{$role}{'on'}.'</li></ul></li>');
8390: } else {
8391: $r->print('<li>'.&mt('None of the privileges unavailable by default for this ad hoc role are enabled.').'</li>');
8392: }
8393: }
8394: }
8395: $r->print('</ul></li>');
8396: }
8397: $r->print('</ul>');
8398: }
8399: } else {
8400: $r->print(&mt('No changes made to helpdesk access settings.'));
8401: }
8402: }
8403: return;
8404: }
8405:
1.27 matthew 8406: #-------------------------------------------------- functions for &phase_two
1.160 raeburn 8407: sub user_search_result {
1.221 raeburn 8408: my ($context,$srch) = @_;
1.160 raeburn 8409: my %allhomes;
8410: my %inst_matches;
8411: my %srch_results;
1.181 raeburn 8412: my ($response,$currstate,$forcenewuser,$dirsrchres);
1.183 raeburn 8413: $srch->{'srchterm'} =~ s/\s+/ /g;
1.176 raeburn 8414: if ($srch->{'srchby'} !~ /^(uname|lastname|lastfirst)$/) {
1.160 raeburn 8415: $response = &mt('Invalid search.');
8416: }
8417: if ($srch->{'srchin'} !~ /^(crs|dom|alc|instd)$/) {
8418: $response = &mt('Invalid search.');
8419: }
1.177 raeburn 8420: if ($srch->{'srchtype'} !~ /^(exact|contains|begins)$/) {
1.160 raeburn 8421: $response = &mt('Invalid search.');
8422: }
8423: if ($srch->{'srchterm'} eq '') {
8424: $response = &mt('You must enter a search term.');
8425: }
1.183 raeburn 8426: if ($srch->{'srchterm'} =~ /^\s+$/) {
8427: $response = &mt('Your search term must contain more than just spaces.');
8428: }
1.160 raeburn 8429: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'instd')) {
8430: if (($srch->{'srchdomain'} eq '') ||
1.163 albertel 8431: ! (&Apache::lonnet::domain($srch->{'srchdomain'}))) {
1.160 raeburn 8432: $response = &mt('You must specify a valid domain when searching in a domain or institutional directory.')
8433: }
8434: }
8435: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs') ||
8436: ($srch->{'srchin'} eq 'alc')) {
1.176 raeburn 8437: if ($srch->{'srchby'} eq 'uname') {
1.243 raeburn 8438: my $unamecheck = $srch->{'srchterm'};
8439: if ($srch->{'srchtype'} eq 'contains') {
8440: if ($unamecheck !~ /^\w/) {
8441: $unamecheck = 'a'.$unamecheck;
8442: }
8443: }
8444: if ($unamecheck !~ /^$match_username$/) {
1.176 raeburn 8445: $response = &mt('You must specify a valid username. Only the following are allowed: letters numbers - . @');
8446: }
1.160 raeburn 8447: }
8448: }
1.180 raeburn 8449: if ($response ne '') {
1.406.2.4 raeburn 8450: $response = '<span class="LC_warning">'.$response.'</span><br />';
1.180 raeburn 8451: }
1.160 raeburn 8452: if ($srch->{'srchin'} eq 'instd') {
1.406.2.3 raeburn 8453: my $instd_chk = &instdirectorysrch_check($srch);
1.160 raeburn 8454: if ($instd_chk ne 'ok') {
1.406.2.3 raeburn 8455: my $domd_chk = &domdirectorysrch_check($srch);
1.406.2.4 raeburn 8456: $response .= '<span class="LC_warning">'.$instd_chk.'</span><br />';
1.406.2.3 raeburn 8457: if ($domd_chk eq 'ok') {
1.406.2.4 raeburn 8458: $response .= &mt('You may want to search in the LON-CAPA domain instead of the institutional directory.');
1.406.2.3 raeburn 8459: }
1.406.2.5 raeburn 8460: $response .= '<br />';
1.406.2.3 raeburn 8461: }
8462: } else {
8463: unless (($context eq 'requestcrs') && ($srch->{'srchtype'} eq 'exact')) {
8464: my $domd_chk = &domdirectorysrch_check($srch);
1.406.2.14 raeburn 8465: if (($domd_chk ne 'ok') && ($env{'form.action'} ne 'accesslogs')) {
1.406.2.3 raeburn 8466: my $instd_chk = &instdirectorysrch_check($srch);
1.406.2.4 raeburn 8467: $response .= '<span class="LC_warning">'.$domd_chk.'</span><br />';
1.406.2.3 raeburn 8468: if ($instd_chk eq 'ok') {
1.406.2.4 raeburn 8469: $response .= &mt('You may want to search in the institutional directory instead of the LON-CAPA domain.');
1.406.2.3 raeburn 8470: }
1.406.2.5 raeburn 8471: $response .= '<br />';
1.406.2.3 raeburn 8472: }
1.160 raeburn 8473: }
8474: }
8475: if ($response ne '') {
1.180 raeburn 8476: return ($currstate,$response);
1.160 raeburn 8477: }
8478: if ($srch->{'srchby'} eq 'uname') {
8479: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs')) {
8480: if ($env{'form.forcenew'}) {
8481: if ($srch->{'srchdomain'} ne $env{'request.role.domain'}) {
8482: my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
8483: if ($uhome eq 'no_host') {
8484: my $domdesc = &Apache::lonnet::domain($env{'request.role.domain'},'description');
1.180 raeburn 8485: my $showdom = &display_domain_info($env{'request.role.domain'});
8486: $response = &mt('New users can only be created in the domain to which your current role belongs - [_1].',$showdom);
1.160 raeburn 8487: } else {
1.179 raeburn 8488: $currstate = 'modify';
1.160 raeburn 8489: }
8490: } else {
1.179 raeburn 8491: $currstate = 'modify';
1.160 raeburn 8492: }
8493: } else {
8494: if ($srch->{'srchin'} eq 'dom') {
1.162 raeburn 8495: if ($srch->{'srchtype'} eq 'exact') {
8496: my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
8497: if ($uhome eq 'no_host') {
1.179 raeburn 8498: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8499: &build_search_response($context,$srch,%srch_results);
1.162 raeburn 8500: } else {
1.179 raeburn 8501: $currstate = 'modify';
1.406.2.5 raeburn 8502: if ($env{'form.action'} eq 'accesslogs') {
8503: $currstate = 'activity';
8504: }
1.310 raeburn 8505: my $uname = $srch->{'srchterm'};
8506: my $udom = $srch->{'srchdomain'};
8507: $srch_results{$uname.':'.$udom} =
8508: { &Apache::lonnet::get('environment',
8509: ['firstname',
8510: 'lastname',
8511: 'permanentemail'],
8512: $udom,$uname)
8513: };
1.162 raeburn 8514: }
8515: } else {
8516: %srch_results = &Apache::lonnet::usersearch($srch);
1.179 raeburn 8517: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8518: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 8519: }
8520: } else {
1.167 albertel 8521: my $courseusers = &get_courseusers();
1.162 raeburn 8522: if ($srch->{'srchtype'} eq 'exact') {
1.167 albertel 8523: if (exists($courseusers->{$srch->{'srchterm'}.':'.$srch->{'srchdomain'}})) {
1.179 raeburn 8524: $currstate = 'modify';
1.162 raeburn 8525: } else {
1.179 raeburn 8526: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8527: &build_search_response($context,$srch,%srch_results);
1.162 raeburn 8528: }
1.160 raeburn 8529: } else {
1.167 albertel 8530: foreach my $user (keys(%$courseusers)) {
1.162 raeburn 8531: my ($cuname,$cudomain) = split(/:/,$user);
8532: if ($cudomain eq $srch->{'srchdomain'}) {
1.177 raeburn 8533: my $matched = 0;
8534: if ($srch->{'srchtype'} eq 'begins') {
8535: if ($cuname =~ /^\Q$srch->{'srchterm'}\E/i) {
8536: $matched = 1;
8537: }
8538: } else {
8539: if ($cuname =~ /\Q$srch->{'srchterm'}\E/i) {
8540: $matched = 1;
8541: }
8542: }
8543: if ($matched) {
1.167 albertel 8544: $srch_results{$user} =
8545: {&Apache::lonnet::get('environment',
8546: ['firstname',
8547: 'lastname',
1.194 albertel 8548: 'permanentemail'],
8549: $cudomain,$cuname)};
1.162 raeburn 8550: }
8551: }
8552: }
1.179 raeburn 8553: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8554: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 8555: }
8556: }
8557: }
8558: } elsif ($srch->{'srchin'} eq 'alc') {
1.179 raeburn 8559: $currstate = 'query';
1.160 raeburn 8560: } elsif ($srch->{'srchin'} eq 'instd') {
1.181 raeburn 8561: ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
8562: if ($dirsrchres eq 'ok') {
8563: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8564: &build_search_response($context,$srch,%srch_results);
1.181 raeburn 8565: } else {
8566: my $showdom = &display_domain_info($srch->{'srchdomain'});
8567: $response = '<span class="LC_warning">'.
8568: &mt('Institutional directory search is not available in domain: [_1]',$showdom).
8569: '</span><br />'.
8570: &mt('You may want to search in the LON-CAPA domain instead of the institutional directory.').
1.406.2.5 raeburn 8571: '<br />';
1.181 raeburn 8572: }
1.160 raeburn 8573: }
8574: } else {
8575: if ($srch->{'srchin'} eq 'dom') {
8576: %srch_results = &Apache::lonnet::usersearch($srch);
1.179 raeburn 8577: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8578: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 8579: } elsif ($srch->{'srchin'} eq 'crs') {
1.167 albertel 8580: my $courseusers = &get_courseusers();
8581: foreach my $user (keys(%$courseusers)) {
1.160 raeburn 8582: my ($uname,$udom) = split(/:/,$user);
8583: my %names = &Apache::loncommon::getnames($uname,$udom);
8584: my %emails = &Apache::loncommon::getemails($uname,$udom);
8585: if ($srch->{'srchby'} eq 'lastname') {
8586: if ((($srch->{'srchtype'} eq 'exact') &&
8587: ($names{'lastname'} eq $srch->{'srchterm'})) ||
1.177 raeburn 8588: (($srch->{'srchtype'} eq 'begins') &&
8589: ($names{'lastname'} =~ /^\Q$srch->{'srchterm'}\E/i)) ||
1.160 raeburn 8590: (($srch->{'srchtype'} eq 'contains') &&
8591: ($names{'lastname'} =~ /\Q$srch->{'srchterm'}\E/i))) {
8592: $srch_results{$user} = {firstname => $names{'firstname'},
8593: lastname => $names{'lastname'},
8594: permanentemail => $emails{'permanentemail'},
8595: };
8596: }
8597: } elsif ($srch->{'srchby'} eq 'lastfirst') {
8598: my ($srchlast,$srchfirst) = split(/,/,$srch->{'srchterm'});
1.177 raeburn 8599: $srchlast =~ s/\s+$//;
8600: $srchfirst =~ s/^\s+//;
1.160 raeburn 8601: if ($srch->{'srchtype'} eq 'exact') {
8602: if (($names{'lastname'} eq $srchlast) &&
8603: ($names{'firstname'} eq $srchfirst)) {
8604: $srch_results{$user} = {firstname => $names{'firstname'},
8605: lastname => $names{'lastname'},
8606: permanentemail => $emails{'permanentemail'},
8607:
8608: };
8609: }
1.177 raeburn 8610: } elsif ($srch->{'srchtype'} eq 'begins') {
8611: if (($names{'lastname'} =~ /^\Q$srchlast\E/i) &&
8612: ($names{'firstname'} =~ /^\Q$srchfirst\E/i)) {
8613: $srch_results{$user} = {firstname => $names{'firstname'},
8614: lastname => $names{'lastname'},
8615: permanentemail => $emails{'permanentemail'},
8616: };
8617: }
8618: } else {
1.160 raeburn 8619: if (($names{'lastname'} =~ /\Q$srchlast\E/i) &&
8620: ($names{'firstname'} =~ /\Q$srchfirst\E/i)) {
8621: $srch_results{$user} = {firstname => $names{'firstname'},
8622: lastname => $names{'lastname'},
8623: permanentemail => $emails{'permanentemail'},
8624: };
8625: }
8626: }
8627: }
8628: }
1.179 raeburn 8629: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8630: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 8631: } elsif ($srch->{'srchin'} eq 'alc') {
1.179 raeburn 8632: $currstate = 'query';
1.160 raeburn 8633: } elsif ($srch->{'srchin'} eq 'instd') {
1.181 raeburn 8634: ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
8635: if ($dirsrchres eq 'ok') {
8636: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8637: &build_search_response($context,$srch,%srch_results);
1.181 raeburn 8638: } else {
1.406.2.5 raeburn 8639: my $showdom = &display_domain_info($srch->{'srchdomain'});
8640: $response = '<span class="LC_warning">'.
1.181 raeburn 8641: &mt('Institutional directory search is not available in domain: [_1]',$showdom).
8642: '</span><br />'.
8643: &mt('You may want to search in the LON-CAPA domain instead of the institutional directory.').
1.406.2.5 raeburn 8644: '<br />';
1.181 raeburn 8645: }
1.160 raeburn 8646: }
8647: }
1.179 raeburn 8648: return ($currstate,$response,$forcenewuser,\%srch_results);
1.160 raeburn 8649: }
8650:
1.406.2.3 raeburn 8651: sub domdirectorysrch_check {
8652: my ($srch) = @_;
8653: my $response;
8654: my %dom_inst_srch = &Apache::lonnet::get_dom('configuration',
8655: ['directorysrch'],$srch->{'srchdomain'});
8656: my $showdom = &display_domain_info($srch->{'srchdomain'});
8657: if (ref($dom_inst_srch{'directorysrch'}) eq 'HASH') {
8658: if ($dom_inst_srch{'directorysrch'}{'lcavailable'} eq '0') {
8659: return &mt('LON-CAPA directory search is not available in domain: [_1]',$showdom);
8660: }
8661: if ($dom_inst_srch{'directorysrch'}{'lclocalonly'}) {
8662: if ($env{'request.role.domain'} ne $srch->{'srchdomain'}) {
8663: return &mt('LON-CAPA directory search in domain: [_1] is only allowed for users with a current role in the domain.',$showdom);
8664: }
8665: }
8666: }
8667: return 'ok';
8668: }
8669:
8670: sub instdirectorysrch_check {
1.160 raeburn 8671: my ($srch) = @_;
8672: my $can_search = 0;
8673: my $response;
8674: my %dom_inst_srch = &Apache::lonnet::get_dom('configuration',
8675: ['directorysrch'],$srch->{'srchdomain'});
1.180 raeburn 8676: my $showdom = &display_domain_info($srch->{'srchdomain'});
1.160 raeburn 8677: if (ref($dom_inst_srch{'directorysrch'}) eq 'HASH') {
8678: if (!$dom_inst_srch{'directorysrch'}{'available'}) {
1.180 raeburn 8679: return &mt('Institutional directory search is not available in domain: [_1]',$showdom);
1.160 raeburn 8680: }
8681: if ($dom_inst_srch{'directorysrch'}{'localonly'}) {
8682: if ($env{'request.role.domain'} ne $srch->{'srchdomain'}) {
1.180 raeburn 8683: return &mt('Institutional directory search in domain: [_1] is only allowed for users with a current role in the domain.',$showdom);
1.160 raeburn 8684: }
8685: my @usertypes = split(/:/,$env{'environment.inststatus'});
8686: if (!@usertypes) {
8687: push(@usertypes,'default');
8688: }
8689: if (ref($dom_inst_srch{'directorysrch'}{'cansearch'}) eq 'ARRAY') {
8690: foreach my $type (@usertypes) {
8691: if (grep(/^\Q$type\E$/,@{$dom_inst_srch{'directorysrch'}{'cansearch'}})) {
8692: $can_search = 1;
8693: last;
8694: }
8695: }
8696: }
8697: if (!$can_search) {
8698: my ($insttypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($srch->{'srchdomain'});
8699: my @longtypes;
8700: foreach my $item (@usertypes) {
1.229 raeburn 8701: if (defined($insttypes->{$item})) {
8702: push (@longtypes,$insttypes->{$item});
8703: } elsif ($item eq 'default') {
8704: push (@longtypes,&mt('other'));
8705: }
1.160 raeburn 8706: }
8707: my $insttype_str = join(', ',@longtypes);
1.180 raeburn 8708: return &mt('Institutional directory search in domain: [_1] is not available to your user type: ',$showdom).$insttype_str;
1.229 raeburn 8709: }
1.160 raeburn 8710: } else {
8711: $can_search = 1;
8712: }
8713: } else {
1.180 raeburn 8714: return &mt('Institutional directory search has not been configured for domain: [_1]',$showdom);
1.160 raeburn 8715: }
8716: my %longtext = &Apache::lonlocal::texthash (
1.167 albertel 8717: uname => 'username',
1.160 raeburn 8718: lastfirst => 'last name, first name',
1.167 albertel 8719: lastname => 'last name',
1.172 raeburn 8720: contains => 'contains',
1.178 raeburn 8721: exact => 'as exact match to',
8722: begins => 'begins with',
1.160 raeburn 8723: );
8724: if ($can_search) {
8725: if (ref($dom_inst_srch{'directorysrch'}{'searchby'}) eq 'ARRAY') {
8726: if (!grep(/^\Q$srch->{'srchby'}\E$/,@{$dom_inst_srch{'directorysrch'}{'searchby'}})) {
1.180 raeburn 8727: return &mt('Institutional directory search in domain: [_1] is not available for searching by "[_2]"',$showdom,$longtext{$srch->{'srchby'}});
1.160 raeburn 8728: }
8729: } else {
1.180 raeburn 8730: return &mt('Institutional directory search in domain: [_1] is not available.', $showdom);
1.160 raeburn 8731: }
8732: }
8733: if ($can_search) {
1.178 raeburn 8734: if (ref($dom_inst_srch{'directorysrch'}{'searchtypes'}) eq 'ARRAY') {
8735: if (grep(/^\Q$srch->{'srchtype'}\E/,@{$dom_inst_srch{'directorysrch'}{'searchtypes'}})) {
8736: return 'ok';
8737: } else {
1.180 raeburn 8738: return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
1.178 raeburn 8739: }
8740: } else {
8741: if ((($dom_inst_srch{'directorysrch'}{'searchtypes'} eq 'specify') &&
8742: ($srch->{'srchtype'} eq 'exact' || $srch->{'srchtype'} eq 'contains')) ||
8743: ($dom_inst_srch{'directorysrch'}{'searchtypes'} eq $srch->{'srchtype'})) {
8744: return 'ok';
8745: } else {
1.180 raeburn 8746: return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
1.178 raeburn 8747: }
1.160 raeburn 8748: }
8749: }
8750: }
8751:
8752: sub get_courseusers {
8753: my %advhash;
1.167 albertel 8754: my $classlist = &Apache::loncoursedata::get_classlist();
1.160 raeburn 8755: my %coursepersonnel=&Apache::lonnet::get_course_adv_roles();
8756: foreach my $role (sort(keys(%coursepersonnel))) {
8757: foreach my $user (split(/\,/,$coursepersonnel{$role})) {
1.167 albertel 8758: if (!exists($classlist->{$user})) {
8759: $classlist->{$user} = [];
8760: }
1.160 raeburn 8761: }
8762: }
1.167 albertel 8763: return $classlist;
1.160 raeburn 8764: }
8765:
8766: sub build_search_response {
1.221 raeburn 8767: my ($context,$srch,%srch_results) = @_;
1.179 raeburn 8768: my ($currstate,$response,$forcenewuser);
1.160 raeburn 8769: my %names = (
1.330 bisitz 8770: 'uname' => 'username',
8771: 'lastname' => 'last name',
1.160 raeburn 8772: 'lastfirst' => 'last name, first name',
1.330 bisitz 8773: 'crs' => 'this course',
8774: 'dom' => 'LON-CAPA domain',
8775: 'instd' => 'the institutional directory for domain',
1.160 raeburn 8776: );
8777:
8778: my %single = (
1.180 raeburn 8779: begins => 'A match',
1.160 raeburn 8780: contains => 'A match',
1.180 raeburn 8781: exact => 'An exact match',
1.160 raeburn 8782: );
8783: my %nomatch = (
1.180 raeburn 8784: begins => 'No match',
1.160 raeburn 8785: contains => 'No match',
1.180 raeburn 8786: exact => 'No exact match',
1.160 raeburn 8787: );
8788: if (keys(%srch_results) > 1) {
1.179 raeburn 8789: $currstate = 'select';
1.160 raeburn 8790: } else {
8791: if (keys(%srch_results) == 1) {
1.406.2.5 raeburn 8792: if ($env{'form.action'} eq 'accesslogs') {
8793: $currstate = 'activity';
8794: } else {
8795: $currstate = 'modify';
8796: }
1.180 raeburn 8797: $response = &mt("$single{$srch->{'srchtype'}} was found for the $names{$srch->{'srchby'}} ([_1]) in $names{$srch->{'srchin'}}.",$srch->{'srchterm'});
8798: if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
1.330 bisitz 8799: $response .= ': '.&display_domain_info($srch->{'srchdomain'});
1.180 raeburn 8800: }
1.330 bisitz 8801: } else { # Search has nothing found. Prepare message to user.
8802: $response = '<span class="LC_warning">';
1.180 raeburn 8803: if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
1.330 bisitz 8804: $response .= &mt("$nomatch{$srch->{'srchtype'}} found for the $names{$srch->{'srchby'}} [_1] in $names{$srch->{'srchin'}}: [_2]",
8805: '<b>'.$srch->{'srchterm'}.'</b>',
8806: &display_domain_info($srch->{'srchdomain'}));
8807: } else {
8808: $response .= &mt("$nomatch{$srch->{'srchtype'}} found for the $names{$srch->{'srchby'}} [_1] in $names{$srch->{'srchin'}}.",
8809: '<b>'.$srch->{'srchterm'}.'</b>');
1.180 raeburn 8810: }
8811: $response .= '</span>';
1.330 bisitz 8812:
1.160 raeburn 8813: if ($srch->{'srchin'} ne 'alc') {
8814: $forcenewuser = 1;
8815: my $cansrchinst = 0;
1.406.2.14 raeburn 8816: if (($srch->{'srchdomain'}) && ($env{'form.action'} ne 'accesslogs')) {
1.160 raeburn 8817: my %domconfig = &Apache::lonnet::get_dom('configuration',['directorysrch'],$srch->{'srchdomain'});
8818: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
8819: if ($domconfig{'directorysrch'}{'available'}) {
8820: $cansrchinst = 1;
8821: }
8822: }
8823: }
1.180 raeburn 8824: if ((($srch->{'srchby'} eq 'lastfirst') ||
8825: ($srch->{'srchby'} eq 'lastname')) &&
8826: ($srch->{'srchin'} eq 'dom')) {
8827: if ($cansrchinst) {
8828: $response .= '<br />'.&mt('You may want to broaden your search to a search of the institutional directory for the domain.');
1.160 raeburn 8829: }
8830: }
1.180 raeburn 8831: if ($srch->{'srchin'} eq 'crs') {
8832: $response .= '<br />'.&mt('You may want to broaden your search to the selected LON-CAPA domain.');
8833: }
8834: }
1.305 raeburn 8835: my $createdom = $env{'request.role.domain'};
8836: if ($context eq 'requestcrs') {
8837: if ($env{'form.coursedom'} ne '') {
8838: $createdom = $env{'form.coursedom'};
8839: }
8840: }
1.406.2.5 raeburn 8841: unless (($env{'form.action'} eq 'accesslogs') || (($srch->{'srchby'} eq 'uname') && ($srch->{'srchin'} eq 'dom') &&
8842: ($srch->{'srchtype'} eq 'exact') && ($srch->{'srchdomain'} eq $createdom))) {
1.221 raeburn 8843: my $cancreate =
1.305 raeburn 8844: &Apache::lonuserutils::can_create_user($createdom,$context);
8845: my $targetdom = '<span class="LC_cusr_emph">'.$createdom.'</span>';
1.221 raeburn 8846: if ($cancreate) {
1.305 raeburn 8847: my $showdom = &display_domain_info($createdom);
1.266 bisitz 8848: $response .= '<br /><br />'
8849: .'<b>'.&mt('To add a new user:').'</b>'
1.305 raeburn 8850: .'<br />';
8851: if ($context eq 'requestcrs') {
8852: $response .= &mt("(You can only define new users in the new course's domain - [_1])",$targetdom);
8853: } else {
8854: $response .= &mt("(You can only create new users in your current role's domain - [_1])",$targetdom);
8855: }
8856: $response .='<ul><li>'
1.266 bisitz 8857: .&mt("Set 'Domain/institution to search' to: [_1]",'<span class="LC_cusr_emph">'.$showdom.'</span>')
8858: .'</li><li>'
8859: .&mt("Set 'Search criteria' to: [_1]username is ..... in selected LON-CAPA domain[_2]",'<span class="LC_cusr_emph">','</span>')
8860: .'</li><li>'
8861: .&mt('Provide the proposed username')
8862: .'</li><li>'
8863: .&mt("Click 'Search'")
8864: .'</li></ul><br />';
1.221 raeburn 8865: } else {
1.406.2.7 raeburn 8866: unless (($context eq 'domain') && ($env{'form.action'} eq 'singleuser')) {
8867: my $helplink = ' href="javascript:helpMenu('."'display'".')"';
8868: $response .= '<br /><br />';
8869: if ($context eq 'requestcrs') {
8870: $response .= &mt("You are not authorized to define new users in the new course's domain - [_1].",$targetdom);
8871: } else {
8872: $response .= &mt("You are not authorized to create new users in your current role's domain - [_1].",$targetdom);
8873: }
8874: $response .= '<br />'
8875: .&mt('Please contact the [_1]helpdesk[_2] if you need to create a new user.'
8876: ,' <a'.$helplink.'>'
8877: ,'</a>')
8878: .'<br />';
1.305 raeburn 8879: }
1.221 raeburn 8880: }
1.160 raeburn 8881: }
8882: }
8883: }
1.179 raeburn 8884: return ($currstate,$response,$forcenewuser);
1.160 raeburn 8885: }
8886:
1.180 raeburn 8887: sub display_domain_info {
8888: my ($dom) = @_;
8889: my $output = $dom;
8890: if ($dom ne '') {
8891: my $domdesc = &Apache::lonnet::domain($dom,'description');
8892: if ($domdesc ne '') {
8893: $output .= ' <span class="LC_cusr_emph">('.$domdesc.')</span>';
8894: }
8895: }
8896: return $output;
8897: }
8898:
1.160 raeburn 8899: sub crumb_utilities {
8900: my %elements = (
8901: crtuser => {
8902: srchterm => 'text',
1.172 raeburn 8903: srchin => 'selectbox',
1.160 raeburn 8904: srchby => 'selectbox',
8905: srchtype => 'selectbox',
8906: srchdomain => 'selectbox',
8907: },
1.207 raeburn 8908: crtusername => {
8909: srchterm => 'text',
8910: srchdomain => 'selectbox',
8911: },
1.160 raeburn 8912: docustom => {
8913: rolename => 'selectbox',
8914: newrolename => 'textbox',
8915: },
1.179 raeburn 8916: studentform => {
8917: srchterm => 'text',
8918: srchin => 'selectbox',
8919: srchby => 'selectbox',
8920: srchtype => 'selectbox',
8921: srchdomain => 'selectbox',
8922: },
1.160 raeburn 8923: );
8924:
8925: my $jsback .= qq|
8926: function backPage(formname,prevphase,prevstate) {
1.211 raeburn 8927: if (typeof prevphase == 'undefined') {
8928: formname.phase.value = '';
8929: }
8930: else {
8931: formname.phase.value = prevphase;
8932: }
8933: if (typeof prevstate == 'undefined') {
8934: formname.currstate.value = '';
8935: }
8936: else {
8937: formname.currstate.value = prevstate;
8938: }
1.160 raeburn 8939: formname.submit();
8940: }
8941: |;
8942: return ($jsback,\%elements);
8943: }
8944:
1.26 matthew 8945: sub course_level_table {
1.375 raeburn 8946: my ($inccourses,$showcredits,$defaultcredits) = @_;
8947: return unless (ref($inccourses) eq 'HASH');
1.26 matthew 8948: my $table = '';
1.62 www 8949: # Custom Roles?
8950:
1.190 raeburn 8951: my %customroles=&Apache::lonuserutils::my_custom_roles();
1.89 raeburn 8952: my %lt=&Apache::lonlocal::texthash(
8953: 'exs' => "Existing sections",
8954: 'new' => "Define new section",
8955: 'ssd' => "Set Start Date",
8956: 'sed' => "Set End Date",
1.131 raeburn 8957: 'crl' => "Course Level",
1.89 raeburn 8958: 'act' => "Activate",
8959: 'rol' => "Role",
8960: 'ext' => "Extent",
1.113 raeburn 8961: 'grs' => "Section",
1.375 raeburn 8962: 'crd' => "Credits",
1.89 raeburn 8963: 'sta' => "Start",
8964: 'end' => "End"
8965: );
1.62 www 8966:
1.375 raeburn 8967: foreach my $protectedcourse (sort(keys(%{$inccourses}))) {
1.135 raeburn 8968: my $thiscourse=$protectedcourse;
1.26 matthew 8969: $thiscourse=~s:_:/:g;
8970: my %coursedata=&Apache::lonnet::coursedescription($thiscourse);
1.365 raeburn 8971: my $isowner = &Apache::lonuserutils::is_courseowner($protectedcourse,$coursedata{'internal.courseowner'});
1.26 matthew 8972: my $area=$coursedata{'description'};
1.321 raeburn 8973: my $crstype=$coursedata{'type'};
1.135 raeburn 8974: if (!defined($area)) { $area=&mt('Unavailable course').': '.$protectedcourse; }
1.89 raeburn 8975: my ($domain,$cnum)=split(/\//,$thiscourse);
1.115 albertel 8976: my %sections_count;
1.101 albertel 8977: if (defined($env{'request.course.id'})) {
8978: if ($env{'request.course.id'} eq $domain.'_'.$cnum) {
1.115 albertel 8979: %sections_count =
8980: &Apache::loncommon::get_sections($domain,$cnum);
1.92 raeburn 8981: }
8982: }
1.321 raeburn 8983: my @roles = &Apache::lonuserutils::roles_by_context('course','',$crstype);
1.213 raeburn 8984: foreach my $role (@roles) {
1.321 raeburn 8985: my $plrole=&Apache::lonnet::plaintext($role,$crstype);
1.329 raeburn 8986: if ((&Apache::lonnet::allowed('c'.$role,$thiscourse)) ||
8987: ((($role eq 'cc') || ($role eq 'co')) && ($isowner))) {
1.221 raeburn 8988: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
1.375 raeburn 8989: $plrole,\%sections_count,\%lt,
1.402 raeburn 8990: $showcredits,$defaultcredits,$crstype);
1.221 raeburn 8991: } elsif ($env{'request.course.sec'} ne '') {
8992: if (&Apache::lonnet::allowed('c'.$role,$thiscourse.'/'.
8993: $env{'request.course.sec'})) {
8994: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
1.375 raeburn 8995: $plrole,\%sections_count,\%lt,
1.402 raeburn 8996: $showcredits,$defaultcredits,$crstype);
1.26 matthew 8997: }
8998: }
8999: }
1.221 raeburn 9000: if (&Apache::lonnet::allowed('ccr',$thiscourse)) {
1.324 raeburn 9001: foreach my $cust (sort(keys(%customroles))) {
9002: next if ($crstype eq 'Community' && $customroles{$cust} =~ /bre\&S/);
1.221 raeburn 9003: my $role = 'cr_cr_'.$env{'user.domain'}.'_'.$env{'user.name'}.'_'.$cust;
9004: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
1.402 raeburn 9005: $cust,\%sections_count,\%lt,
9006: $showcredits,$defaultcredits,$crstype);
1.221 raeburn 9007: }
1.62 www 9008: }
1.26 matthew 9009: }
9010: return '' if ($table eq ''); # return nothing if there is nothing
9011: # in the table
1.188 raeburn 9012: my $result;
9013: if (!$env{'request.course.id'}) {
9014: $result = '<h4>'.$lt{'crl'}.'</h4>'."\n";
9015: }
9016: $result .=
1.136 raeburn 9017: &Apache::loncommon::start_data_table().
9018: &Apache::loncommon::start_data_table_header_row().
1.375 raeburn 9019: '<th>'.$lt{'act'}.'</th><th>'.$lt{'rol'}.'</th>'."\n".
1.402 raeburn 9020: '<th>'.$lt{'ext'}.'</th><th>'."\n";
9021: if ($showcredits) {
9022: $result .= $lt{'crd'}.'</th>';
9023: }
9024: $result .=
1.375 raeburn 9025: '<th>'.$lt{'grs'}.'</th><th>'.$lt{'sta'}.'</th>'."\n".
9026: '<th>'.$lt{'end'}.'</th>'.
1.136 raeburn 9027: &Apache::loncommon::end_data_table_header_row().
9028: $table.
9029: &Apache::loncommon::end_data_table();
1.26 matthew 9030: return $result;
9031: }
1.88 raeburn 9032:
1.221 raeburn 9033: sub course_level_row {
1.375 raeburn 9034: my ($protectedcourse,$role,$area,$domain,$plrole,$sections_count,
1.402 raeburn 9035: $lt,$showcredits,$defaultcredits,$crstype) = @_;
1.375 raeburn 9036: my $creditem;
1.222 raeburn 9037: my $row = &Apache::loncommon::start_data_table_row().
9038: ' <td><input type="checkbox" name="act_'.
9039: $protectedcourse.'_'.$role.'" /></td>'."\n".
9040: ' <td>'.$plrole.'</td>'."\n".
9041: ' <td>'.$area.'<br />Domain: '.$domain.'</td>'."\n";
1.402 raeburn 9042: if (($showcredits) && ($role eq 'st') && ($crstype eq 'Course')) {
1.375 raeburn 9043: $row .=
9044: '<td><input type="text" name="credits_'.$protectedcourse.'_'.
9045: $role.'" size="3" value="'.$defaultcredits.'" /></td>';
9046: } else {
9047: $row .= '<td> </td>';
9048: }
1.322 raeburn 9049: if (($role eq 'cc') || ($role eq 'co')) {
1.222 raeburn 9050: $row .= '<td> </td>';
1.221 raeburn 9051: } elsif ($env{'request.course.sec'} ne '') {
1.222 raeburn 9052: $row .= ' <td><input type="hidden" value="'.
9053: $env{'request.course.sec'}.'" '.
9054: 'name="sec_'.$protectedcourse.'_'.$role.'" />'.
9055: $env{'request.course.sec'}.'</td>';
1.221 raeburn 9056: } else {
9057: if (ref($sections_count) eq 'HASH') {
9058: my $currsec =
9059: &Apache::lonuserutils::course_sections($sections_count,
9060: $protectedcourse.'_'.$role);
1.222 raeburn 9061: $row .= '<td><table class="LC_createuser">'."\n".
9062: '<tr class="LC_section_row">'."\n".
9063: ' <td valign="top">'.$lt->{'exs'}.'<br />'.
9064: $currsec.'</td>'."\n".
9065: ' <td> </td>'."\n".
9066: ' <td valign="top"> '.$lt->{'new'}.'<br />'.
1.221 raeburn 9067: '<input type="text" name="newsec_'.$protectedcourse.'_'.$role.
9068: '" value="" />'.
9069: '<input type="hidden" '.
9070: 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'."\n".
1.222 raeburn 9071: '</tr></table></td>'."\n";
1.221 raeburn 9072: } else {
1.222 raeburn 9073: $row .= '<td><input type="text" size="10" '.
1.375 raeburn 9074: 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'."\n";
1.221 raeburn 9075: }
9076: }
1.222 raeburn 9077: $row .= <<ENDTIMEENTRY;
9078: <td><input type="hidden" name="start_$protectedcourse\_$role" value="" />
1.221 raeburn 9079: <a href=
9080: "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 9081: <td><input type="hidden" name="end_$protectedcourse\_$role" value="" />
1.221 raeburn 9082: <a href=
9083: "javascript:pjump('date_end','End Date $plrole',document.cu.end_$protectedcourse\_$role.value,'end_$protectedcourse\_$role','cu.pres','dateset')">$lt->{'sed'}</a></td>
9084: ENDTIMEENTRY
1.222 raeburn 9085: $row .= &Apache::loncommon::end_data_table_row();
9086: return $row;
1.221 raeburn 9087: }
9088:
1.88 raeburn 9089: sub course_level_dc {
1.375 raeburn 9090: my ($dcdom,$showcredits) = @_;
1.190 raeburn 9091: my %customroles=&Apache::lonuserutils::my_custom_roles();
1.213 raeburn 9092: my @roles = &Apache::lonuserutils::roles_by_context('course');
1.88 raeburn 9093: my $hiddenitems = '<input type="hidden" name="dcdomain" value="'.$dcdom.'" />'.
9094: '<input type="hidden" name="origdom" value="'.$dcdom.'" />'.
1.133 raeburn 9095: '<input type="hidden" name="dccourse" value="" />';
1.355 www 9096: my $courseform=&Apache::loncommon::selectcourse_link
1.356 raeburn 9097: ('cu','dccourse','dcdomain','coursedesc',undef,undef,'Select','crstype');
1.375 raeburn 9098: my $credit_elem;
9099: if ($showcredits) {
9100: $credit_elem = 'credits';
9101: }
9102: my $cb_jscript = &Apache::loncommon::coursebrowser_javascript($dcdom,'currsec','cu','role','Course/Community Browser',$credit_elem);
1.88 raeburn 9103: my %lt=&Apache::lonlocal::texthash(
9104: 'rol' => "Role",
1.113 raeburn 9105: 'grs' => "Section",
1.88 raeburn 9106: 'exs' => "Existing sections",
9107: 'new' => "Define new section",
9108: 'sta' => "Start",
9109: 'end' => "End",
9110: 'ssd' => "Set Start Date",
1.355 www 9111: 'sed' => "Set End Date",
1.375 raeburn 9112: 'scc' => "Course/Community",
9113: 'crd' => "Credits",
1.88 raeburn 9114: );
1.323 raeburn 9115: my $header = '<h4>'.&mt('Course/Community Level').'</h4>'.
1.136 raeburn 9116: &Apache::loncommon::start_data_table().
9117: &Apache::loncommon::start_data_table_header_row().
1.375 raeburn 9118: '<th>'.$lt{'scc'}.'</th><th>'.$lt{'rol'}.'</th>'."\n".
1.397 bisitz 9119: '<th>'.$lt{'grs'}.'</th>'."\n";
9120: $header .= '<th>'.$lt{'crd'}.'</th>'."\n" if ($showcredits);
9121: $header .= '<th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'."\n".
1.136 raeburn 9122: &Apache::loncommon::end_data_table_header_row();
1.143 raeburn 9123: my $otheritems = &Apache::loncommon::start_data_table_row()."\n".
1.356 raeburn 9124: '<td><br /><span class="LC_nobreak"><input type="text" name="coursedesc" value="" onfocus="this.blur();opencrsbrowser('."'cu','dccourse','dcdomain','coursedesc','','','','crstype'".')" />'.
9125: $courseform.(' ' x4).'</span></td>'."\n".
1.389 bisitz 9126: '<td valign="top"><br /><select name="role">'."\n";
1.213 raeburn 9127: foreach my $role (@roles) {
1.135 raeburn 9128: my $plrole=&Apache::lonnet::plaintext($role);
1.389 bisitz 9129: $otheritems .= ' <option value="'.$role.'">'.$plrole.'</option>';
1.88 raeburn 9130: }
1.404 raeburn 9131: if ( keys(%customroles) > 0) {
9132: foreach my $cust (sort(keys(%customroles))) {
1.101 albertel 9133: my $custrole='cr_cr_'.$env{'user.domain'}.
1.135 raeburn 9134: '_'.$env{'user.name'}.'_'.$cust;
1.389 bisitz 9135: $otheritems .= ' <option value="'.$custrole.'">'.$cust.'</option>';
1.88 raeburn 9136: }
9137: }
9138: $otheritems .= '</select></td><td>'.
9139: '<table border="0" cellspacing="0" cellpadding="0">'.
9140: '<tr><td valign="top"><b>'.$lt{'exs'}.'</b><br /><select name="currsec">'.
1.389 bisitz 9141: ' <option value=""><--'.&mt('Pick course first').'</option></select></td>'.
1.88 raeburn 9142: '<td> </td>'.
9143: '<td valign="top"> <b>'.$lt{'new'}.'</b><br />'.
1.113 raeburn 9144: '<input type="text" name="newsec" value="" />'.
1.237 raeburn 9145: '<input type="hidden" name="section" value="" />'.
1.323 raeburn 9146: '<input type="hidden" name="groups" value="" />'.
9147: '<input type="hidden" name="crstype" value="" /></td>'.
1.375 raeburn 9148: '</tr></table></td>'."\n";
9149: if ($showcredits) {
9150: $otheritems .= '<td><br />'."\n".
1.397 bisitz 9151: '<input type="text" size="3" name="credits" value="" /></td>'."\n";
1.375 raeburn 9152: }
1.88 raeburn 9153: $otheritems .= <<ENDTIMEENTRY;
1.323 raeburn 9154: <td><br /><input type="hidden" name="start" value='' />
1.88 raeburn 9155: <a href=
9156: "javascript:pjump('date_start','Start Date',document.cu.start.value,'start','cu.pres','dateset')">$lt{'ssd'}</a></td>
1.323 raeburn 9157: <td><br /><input type="hidden" name="end" value='' />
1.88 raeburn 9158: <a href=
9159: "javascript:pjump('date_end','End Date',document.cu.end.value,'end','cu.pres','dateset')">$lt{'sed'}</a></td>
9160: ENDTIMEENTRY
1.136 raeburn 9161: $otheritems .= &Apache::loncommon::end_data_table_row().
9162: &Apache::loncommon::end_data_table()."\n";
1.88 raeburn 9163: return $cb_jscript.$header.$hiddenitems.$otheritems;
9164: }
9165:
1.237 raeburn 9166: sub update_selfenroll_config {
1.400 raeburn 9167: my ($r,$cid,$cdom,$cnum,$context,$crstype,$currsettings) = @_;
1.398 raeburn 9168: return unless (ref($currsettings) eq 'HASH');
9169: my ($row,$lt) = &Apache::lonuserutils::get_selfenroll_titles();
9170: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
1.237 raeburn 9171: my (%changes,%warning);
1.241 raeburn 9172: my $curr_types;
1.400 raeburn 9173: my %noedit;
9174: unless ($context eq 'domain') {
9175: %noedit = &get_noedit_fields($cdom,$cnum,$crstype,$row);
9176: }
1.237 raeburn 9177: if (ref($row) eq 'ARRAY') {
9178: foreach my $item (@{$row}) {
1.400 raeburn 9179: next if ($noedit{$item});
1.237 raeburn 9180: if ($item eq 'enroll_dates') {
9181: my (%currenrolldate,%newenrolldate);
9182: foreach my $type ('start','end') {
1.398 raeburn 9183: $currenrolldate{$type} = $currsettings->{'selfenroll_'.$type.'_date'};
1.237 raeburn 9184: $newenrolldate{$type} = &Apache::lonhtmlcommon::get_date_from_form('selfenroll_'.$type.'_date');
9185: if ($newenrolldate{$type} ne $currenrolldate{$type}) {
9186: $changes{'internal.selfenroll_'.$type.'_date'} = $newenrolldate{$type};
9187: }
9188: }
9189: } elsif ($item eq 'access_dates') {
9190: my (%currdate,%newdate);
9191: foreach my $type ('start','end') {
1.398 raeburn 9192: $currdate{$type} = $currsettings->{'selfenroll_'.$type.'_access'};
1.237 raeburn 9193: $newdate{$type} = &Apache::lonhtmlcommon::get_date_from_form('selfenroll_'.$type.'_access');
9194: if ($newdate{$type} ne $currdate{$type}) {
9195: $changes{'internal.selfenroll_'.$type.'_access'} = $newdate{$type};
9196: }
9197: }
1.241 raeburn 9198: } elsif ($item eq 'types') {
1.398 raeburn 9199: $curr_types = $currsettings->{'selfenroll_'.$item};
1.241 raeburn 9200: if ($env{'form.selfenroll_all'}) {
9201: if ($curr_types ne '*') {
9202: $changes{'internal.selfenroll_types'} = '*';
9203: } else {
9204: next;
9205: }
9206: } else {
1.249 raeburn 9207: my %currdoms;
1.241 raeburn 9208: my @entries = split(/;/,$curr_types);
9209: my @deletedoms = &Apache::loncommon::get_env_multiple('form.selfenroll_delete');
1.249 raeburn 9210: my @activations = &Apache::loncommon::get_env_multiple('form.selfenroll_activate');
1.241 raeburn 9211: my $newnum = 0;
1.249 raeburn 9212: my @latesttypes;
9213: foreach my $num (@activations) {
9214: my @types = &Apache::loncommon::get_env_multiple('form.selfenroll_types_'.$num);
9215: if (@types > 0) {
1.241 raeburn 9216: @types = sort(@types);
9217: my $typestr = join(',',@types);
1.249 raeburn 9218: my $typedom = $env{'form.selfenroll_dom_'.$num};
9219: $latesttypes[$newnum] = $typedom.':'.$typestr;
9220: $currdoms{$typedom} = 1;
1.241 raeburn 9221: $newnum ++;
9222: }
9223: }
1.338 raeburn 9224: for (my $j=0; $j<$env{'form.selfenroll_types_total'}; $j++) {
9225: if ((!grep(/^$j$/,@deletedoms)) && (!grep(/^$j$/,@activations))) {
1.249 raeburn 9226: my @types = &Apache::loncommon::get_env_multiple('form.selfenroll_types_'.$j);
9227: if (@types > 0) {
9228: @types = sort(@types);
9229: my $typestr = join(',',@types);
9230: my $typedom = $env{'form.selfenroll_dom_'.$j};
9231: $latesttypes[$newnum] = $typedom.':'.$typestr;
9232: $currdoms{$typedom} = 1;
9233: $newnum ++;
9234: }
9235: }
9236: }
9237: if ($env{'form.selfenroll_newdom'} ne '') {
9238: my $typedom = $env{'form.selfenroll_newdom'};
9239: if ((!defined($currdoms{$typedom})) &&
9240: (&Apache::lonnet::domain($typedom) ne '')) {
9241: my $typestr;
9242: my ($othertitle,$usertypes,$types) =
9243: &Apache::loncommon::sorted_inst_types($typedom);
9244: my $othervalue = 'any';
9245: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
9246: if (@{$types} > 0) {
1.257 raeburn 9247: my @esc_types = map { &escape($_); } @{$types};
1.249 raeburn 9248: $othervalue = 'other';
1.258 raeburn 9249: $typestr = join(',',(@esc_types,$othervalue));
1.249 raeburn 9250: }
9251: $typestr = $othervalue;
9252: } else {
9253: $typestr = $othervalue;
9254: }
9255: $latesttypes[$newnum] = $typedom.':'.$typestr;
9256: $newnum ++ ;
9257: }
9258: }
1.241 raeburn 9259: my $selfenroll_types = join(';',@latesttypes);
9260: if ($selfenroll_types ne $curr_types) {
9261: $changes{'internal.selfenroll_types'} = $selfenroll_types;
9262: }
9263: }
1.276 raeburn 9264: } elsif ($item eq 'limit') {
9265: my $newlimit = $env{'form.selfenroll_limit'};
9266: my $newcap = $env{'form.selfenroll_cap'};
9267: $newcap =~s/\s+//g;
1.398 raeburn 9268: my $currlimit = $currsettings->{'selfenroll_limit'};
1.276 raeburn 9269: $currlimit = 'none' if ($currlimit eq '');
1.398 raeburn 9270: my $currcap = $currsettings->{'selfenroll_cap'};
1.276 raeburn 9271: if ($newlimit ne $currlimit) {
9272: if ($newlimit ne 'none') {
9273: if ($newcap =~ /^\d+$/) {
9274: if ($newcap ne $currcap) {
9275: $changes{'internal.selfenroll_cap'} = $newcap;
9276: }
9277: $changes{'internal.selfenroll_limit'} = $newlimit;
9278: } else {
1.398 raeburn 9279: $warning{$item} = &mt('Maximum enrollment setting unchanged.').'<br />'.
9280: &mt('The value provided was invalid - it must be a positive integer if enrollment is being limited.');
1.276 raeburn 9281: }
9282: } elsif ($currcap ne '') {
9283: $changes{'internal.selfenroll_cap'} = '';
9284: $changes{'internal.selfenroll_limit'} = $newlimit;
9285: }
9286: } elsif ($currlimit ne 'none') {
9287: if ($newcap =~ /^\d+$/) {
9288: if ($newcap ne $currcap) {
9289: $changes{'internal.selfenroll_cap'} = $newcap;
9290: }
9291: } else {
1.398 raeburn 9292: $warning{$item} = &mt('Maximum enrollment setting unchanged.').'<br />'.
9293: &mt('The value provided was invalid - it must be a positive integer if enrollment is being limited.');
1.276 raeburn 9294: }
9295: }
9296: } elsif ($item eq 'approval') {
9297: my (@currnotified,@newnotified);
1.398 raeburn 9298: my $currapproval = $currsettings->{'selfenroll_approval'};
9299: my $currnotifylist = $currsettings->{'selfenroll_notifylist'};
1.276 raeburn 9300: if ($currnotifylist ne '') {
9301: @currnotified = split(/,/,$currnotifylist);
9302: @currnotified = sort(@currnotified);
9303: }
9304: my $newapproval = $env{'form.selfenroll_approval'};
9305: @newnotified = &Apache::loncommon::get_env_multiple('form.selfenroll_notify');
9306: @newnotified = sort(@newnotified);
9307: if ($newapproval ne $currapproval) {
9308: $changes{'internal.selfenroll_approval'} = $newapproval;
9309: if (!$newapproval) {
9310: if ($currnotifylist ne '') {
9311: $changes{'internal.selfenroll_notifylist'} = '';
9312: }
9313: } else {
9314: my @differences =
1.295 raeburn 9315: &Apache::loncommon::compare_arrays(\@currnotified,\@newnotified);
1.276 raeburn 9316: if (@differences > 0) {
9317: if (@newnotified > 0) {
9318: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
9319: } else {
9320: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
9321: }
9322: }
9323: }
9324: } else {
1.295 raeburn 9325: my @differences = &Apache::loncommon::compare_arrays(\@currnotified,\@newnotified);
1.276 raeburn 9326: if (@differences > 0) {
9327: if (@newnotified > 0) {
9328: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
9329: } else {
9330: $changes{'internal.selfenroll_notifylist'} = '';
9331: }
9332: }
9333: }
1.237 raeburn 9334: } else {
1.398 raeburn 9335: my $curr_val = $currsettings->{'selfenroll_'.$item};
1.237 raeburn 9336: my $newval = $env{'form.selfenroll_'.$item};
9337: if ($item eq 'section') {
9338: $newval = $env{'form.sections'};
1.241 raeburn 9339: if (defined($curr_groups{$newval})) {
1.237 raeburn 9340: $newval = $curr_val;
1.398 raeburn 9341: $warning{$item} = &mt('Section for self-enrolled users unchanged as the proposed section is a group').'<br />'.
9342: &mt('Group names and section names must be distinct');
1.237 raeburn 9343: } elsif ($newval eq 'all') {
9344: $newval = $curr_val;
1.274 bisitz 9345: $warning{$item} = &mt('Section for self-enrolled users unchanged, as "all" is a reserved section name.');
1.237 raeburn 9346: }
9347: if ($newval eq '') {
9348: $newval = 'none';
9349: }
9350: }
9351: if ($newval ne $curr_val) {
9352: $changes{'internal.selfenroll_'.$item} = $newval;
9353: }
1.241 raeburn 9354: }
1.237 raeburn 9355: }
9356: if (keys(%warning) > 0) {
9357: foreach my $item (@{$row}) {
9358: if (exists($warning{$item})) {
9359: $r->print($warning{$item}.'<br />');
9360: }
9361: }
9362: }
9363: if (keys(%changes) > 0) {
9364: my $putresult = &Apache::lonnet::put('environment',\%changes,$cdom,$cnum);
9365: if ($putresult eq 'ok') {
9366: if ((exists($changes{'internal.selfenroll_types'})) ||
9367: (exists($changes{'internal.selfenroll_start_date'})) ||
9368: (exists($changes{'internal.selfenroll_end_date'}))) {
9369: my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',
9370: $cnum,undef,undef,'Course');
9371: my $chome = &Apache::lonnet::homeserver($cnum,$cdom);
1.398 raeburn 9372: if (ref($crsinfo{$cid}) eq 'HASH') {
1.237 raeburn 9373: foreach my $item ('selfenroll_types','selfenroll_start_date','selfenroll_end_date') {
9374: if (exists($changes{'internal.'.$item})) {
1.398 raeburn 9375: $crsinfo{$cid}{$item} = $changes{'internal.'.$item};
1.237 raeburn 9376: }
9377: }
9378: my $crsputresult =
9379: &Apache::lonnet::courseidput($cdom,\%crsinfo,
9380: $chome,'notime');
9381: }
9382: }
9383: $r->print(&mt('The following changes were made to self-enrollment settings:').'<ul>');
9384: foreach my $item (@{$row}) {
9385: my $title = $item;
9386: if (ref($lt) eq 'HASH') {
9387: $title = $lt->{$item};
9388: }
9389: if ($item eq 'enroll_dates') {
9390: foreach my $type ('start','end') {
9391: if (exists($changes{'internal.selfenroll_'.$type.'_date'})) {
9392: my $newdate = &Apache::lonlocal::locallocaltime($changes{'internal.selfenroll_'.$type.'_date'});
1.244 bisitz 9393: $r->print('<li>'.&mt('[_1]: "[_2]" set to "[_3]".',
1.237 raeburn 9394: $title,$type,$newdate).'</li>');
9395: }
9396: }
9397: } elsif ($item eq 'access_dates') {
9398: foreach my $type ('start','end') {
9399: if (exists($changes{'internal.selfenroll_'.$type.'_access'})) {
9400: my $newdate = &Apache::lonlocal::locallocaltime($changes{'internal.selfenroll_'.$type.'_access'});
1.244 bisitz 9401: $r->print('<li>'.&mt('[_1]: "[_2]" set to "[_3]".',
1.237 raeburn 9402: $title,$type,$newdate).'</li>');
9403: }
9404: }
1.276 raeburn 9405: } elsif ($item eq 'limit') {
9406: if ((exists($changes{'internal.selfenroll_limit'})) ||
9407: (exists($changes{'internal.selfenroll_cap'}))) {
9408: my ($newval,$newcap);
9409: if ($changes{'internal.selfenroll_cap'} ne '') {
9410: $newcap = $changes{'internal.selfenroll_cap'}
9411: } else {
1.398 raeburn 9412: $newcap = $currsettings->{'selfenroll_cap'};
1.276 raeburn 9413: }
9414: if ($changes{'internal.selfenroll_limit'} eq 'none') {
9415: $newval = &mt('No limit');
9416: } elsif ($changes{'internal.selfenroll_limit'} eq
9417: 'allstudents') {
9418: $newval = &mt('New self-enrollment no longer allowed when total (all students) reaches [_1].',$newcap);
9419: } elsif ($changes{'internal.selfenroll_limit'} eq 'selfenrolled') {
9420: $newval = &mt('New self-enrollment no longer allowed when total number of self-enrolled students reaches [_1].',$newcap);
9421: } else {
1.398 raeburn 9422: my $currlimit = $currsettings->{'selfenroll_limit'};
1.276 raeburn 9423: if ($currlimit eq 'allstudents') {
9424: $newval = &mt('New self-enrollment no longer allowed when total (all students) reaches [_1].',$newcap);
9425: } elsif ($changes{'internal.selfenroll_limit'} eq 'selfenrolled') {
1.308 raeburn 9426: $newval = &mt('New self-enrollment no longer allowed when total number of self-enrolled students reaches [_1].',$newcap);
1.276 raeburn 9427: }
9428: }
9429: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval).'</li>'."\n");
9430: }
9431: } elsif ($item eq 'approval') {
9432: if ((exists($changes{'internal.selfenroll_approval'})) ||
9433: (exists($changes{'internal.selfenroll_notifylist'}))) {
1.398 raeburn 9434: my %selfdescs = &Apache::lonuserutils::selfenroll_default_descs();
1.276 raeburn 9435: my ($newval,$newnotify);
9436: if (exists($changes{'internal.selfenroll_notifylist'})) {
9437: $newnotify = $changes{'internal.selfenroll_notifylist'};
9438: } else {
1.398 raeburn 9439: $newnotify = $currsettings->{'selfenroll_notifylist'};
1.276 raeburn 9440: }
1.398 raeburn 9441: if (exists($changes{'internal.selfenroll_approval'})) {
9442: if ($changes{'internal.selfenroll_approval'} !~ /^[012]$/) {
9443: $changes{'internal.selfenroll_approval'} = '0';
9444: }
9445: $newval = $selfdescs{'approval'}{$changes{'internal.selfenroll_approval'}};
1.276 raeburn 9446: } else {
1.398 raeburn 9447: my $currapproval = $currsettings->{'selfenroll_approval'};
9448: if ($currapproval !~ /^[012]$/) {
9449: $currapproval = 0;
1.276 raeburn 9450: }
1.398 raeburn 9451: $newval = $selfdescs{'approval'}{$currapproval};
1.276 raeburn 9452: }
9453: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval));
9454: if ($newnotify) {
1.277 raeburn 9455: $r->print('<br />'.&mt('The following will be notified when an enrollment request needs approval, or has been approved: [_1].',$newnotify));
1.276 raeburn 9456: } else {
1.277 raeburn 9457: $r->print('<br />'.&mt('No notifications sent when an enrollment request needs approval, or has been approved.'));
1.276 raeburn 9458: }
9459: $r->print('</li>'."\n");
9460: }
1.237 raeburn 9461: } else {
9462: if (exists($changes{'internal.selfenroll_'.$item})) {
1.241 raeburn 9463: my $newval = $changes{'internal.selfenroll_'.$item};
9464: if ($item eq 'types') {
9465: if ($newval eq '') {
9466: $newval = &mt('None');
9467: } elsif ($newval eq '*') {
9468: $newval = &mt('Any user in any domain');
9469: }
1.245 raeburn 9470: } elsif ($item eq 'registered') {
9471: if ($newval eq '1') {
9472: $newval = &mt('Yes');
9473: } elsif ($newval eq '0') {
9474: $newval = &mt('No');
9475: }
1.241 raeburn 9476: }
1.244 bisitz 9477: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval).'</li>'."\n");
1.237 raeburn 9478: }
9479: }
9480: }
9481: $r->print('</ul>');
1.398 raeburn 9482: if ($env{'course.'.$cid.'.description'} ne '') {
9483: my %newenvhash;
9484: foreach my $key (keys(%changes)) {
9485: $newenvhash{'course.'.$cid.'.'.$key} = $changes{$key};
9486: }
9487: &Apache::lonnet::appenv(\%newenvhash);
1.237 raeburn 9488: }
9489: } else {
1.398 raeburn 9490: $r->print(&mt('An error occurred when saving changes to self-enrollment settings in this course.').'<br />'.
9491: &mt('The error was: [_1].',$putresult));
1.237 raeburn 9492: }
9493: } else {
1.249 raeburn 9494: $r->print(&mt('No changes were made to the existing self-enrollment settings in this course.'));
1.237 raeburn 9495: }
9496: } else {
1.249 raeburn 9497: $r->print(&mt('No changes were made to the existing self-enrollment settings in this course.'));
1.241 raeburn 9498: }
1.400 raeburn 9499: my $visactions = &cat_visibility();
9500: my ($cathash,%cattype);
9501: my %domconfig = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom);
9502: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
9503: $cathash = $domconfig{'coursecategories'}{'cats'};
9504: $cattype{'auth'} = $domconfig{'coursecategories'}{'auth'};
9505: $cattype{'unauth'} = $domconfig{'coursecategories'}{'unauth'};
9506: } else {
9507: $cathash = {};
9508: $cattype{'auth'} = 'std';
9509: $cattype{'unauth'} = 'std';
9510: }
9511: if (($cattype{'auth'} eq 'none') && ($cattype{'unauth'} eq 'none')) {
9512: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
9513: '<br />'.
9514: '<br />'.$visactions->{'take'}.'<ul>'.
9515: '<li>'.$visactions->{'dc_chgconf'}.'</li>'.
9516: '</ul>');
9517: } elsif (($cattype{'auth'} !~ /^(std|domonly)$/) && ($cattype{'unauth'} !~ /^(std|domonly)$/)) {
9518: if ($currsettings->{'uniquecode'}) {
9519: $r->print('<span class="LC_info">'.$visactions->{'vis'}.'</span>');
9520: } else {
1.366 bisitz 9521: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
1.400 raeburn 9522: '<br />'.
9523: '<br />'.$visactions->{'take'}.'<ul>'.
9524: '<li>'.$visactions->{'dc_setcode'}.'</li>'.
9525: '</ul><br />');
9526: }
9527: } else {
9528: my ($visible,$cansetvis,$vismsgs) = &visible_in_stdcat($cdom,$cnum,\%domconfig);
9529: if (ref($visactions) eq 'HASH') {
9530: if (!$visible) {
9531: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
9532: '<br />');
9533: if (ref($vismsgs) eq 'ARRAY') {
9534: $r->print('<br />'.$visactions->{'take'}.'<ul>');
9535: foreach my $item (@{$vismsgs}) {
9536: $r->print('<li>'.$visactions->{$item}.'</li>');
9537: }
9538: $r->print('</ul>');
1.256 raeburn 9539: }
1.400 raeburn 9540: $r->print($cansetvis);
1.256 raeburn 9541: }
9542: }
9543: }
1.237 raeburn 9544: return;
9545: }
9546:
1.27 matthew 9547: #---------------------------------------------- end functions for &phase_two
1.29 matthew 9548:
9549: #--------------------------------- functions for &phase_two and &phase_three
9550:
9551: #--------------------------end of functions for &phase_two and &phase_three
1.372 raeburn 9552:
1.1 www 9553: 1;
9554: __END__
1.2 www 9555:
9556:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>