Annotation of loncom/interface/loncreateuser.pm, revision 1.406.2.15
1.20 harris41 1: # The LearningOnline Network with CAPA
1.1 www 2: # Create a user
3: #
1.406.2.15! raeburn 4: # $Id: loncreateuser.pm,v 1.406.2.14 2017/04/02 12:40:18 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.396 raeburn 2348: $now,$captchaform,$emailusername,$usertype) = @_;
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',
2375: );
2376:
2377: %canmodify_status =
1.286 raeburn 2378: &Apache::lonuserutils::can_modify_userinfo($context,$ccdomain,
2379: ['inststatus'],$rolesarray);
1.253 raeburn 2380: if (!$newuser) {
1.188 raeburn 2381: # Get the users information
2382: %userenv = &Apache::lonnet::get('environment',
2383: ['firstname','middlename','lastname','generation',
1.286 raeburn 2384: 'permanentemail','id','inststatus'],$ccdomain,$ccuname);
1.219 raeburn 2385: %canmodify =
2386: &Apache::lonuserutils::can_modify_userinfo($context,$ccdomain,
1.252 raeburn 2387: \@userinfo,$rolesarray);
1.257 raeburn 2388: } elsif ($context eq 'selfcreate') {
1.391 raeburn 2389: if ($newuser eq 'email') {
1.396 raeburn 2390: if (ref($emailusername) eq 'HASH') {
2391: if (ref($emailusername->{$usertype}) eq 'HASH') {
2392: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
2393: @userinfo = ();
2394: if ((ref($infofields) eq 'ARRAY') && (ref($infotitles) eq 'HASH')) {
2395: foreach my $field (@{$infofields}) {
2396: if ($emailusername->{$usertype}->{$field}) {
2397: push(@userinfo,$field);
2398: $canmodify{$field} = 1;
2399: unless ($textboxsize{$field}) {
2400: $textboxsize{$field} = 25;
2401: }
2402: unless ($lt{$field}) {
2403: $lt{$field} = $infotitles->{$field};
2404: }
2405: if ($emailusername->{$usertype}->{$field} eq 'required') {
2406: $lt{$field} .= '<b>*</b>';
2407: }
1.391 raeburn 2408: }
2409: }
2410: }
2411: }
2412: }
2413: } else {
2414: %canmodify = &selfcreate_canmodify($context,$ccdomain,\@userinfo,
2415: $inst_results,$rolesarray);
2416: }
1.188 raeburn 2417: }
1.391 raeburn 2418:
1.188 raeburn 2419: my $genhelp=&Apache::loncommon::help_open_topic('Generation');
2420: $output = '<h3>'.$lt{'pd'}.'</h3>'.
2421: &Apache::lonhtmlcommon::start_pick_box();
1.391 raeburn 2422: if (($context eq 'selfcreate') && ($newuser eq 'email')) {
1.396 raeburn 2423: $output .= &Apache::lonhtmlcommon::row_title($lt{'email'}.'<b>*</b>',undef,
1.391 raeburn 2424: 'LC_oddrow_value')."\n".
1.394 raeburn 2425: '<input type="text" name="uname" size="25" value="" autocomplete="off" />';
1.391 raeburn 2426: $rowcount ++;
2427: $output .= &Apache::lonhtmlcommon::row_closure(1);
1.406.2.1 raeburn 2428: my $upassone = '<input type="password" name="upass'.$now.'" size="20" autocomplete="off" />';
2429: my $upasstwo = '<input type="password" name="upasscheck'.$now.'" size="20" autocomplete="off" />';
1.396 raeburn 2430: $output .= &Apache::lonhtmlcommon::row_title(&mt('Password').'<b>*</b>',
1.391 raeburn 2431: 'LC_pick_box_title',
2432: 'LC_oddrow_value')."\n".
2433: $upassone."\n".
2434: &Apache::lonhtmlcommon::row_closure(1)."\n".
1.396 raeburn 2435: &Apache::lonhtmlcommon::row_title(&mt('Confirm password').'<b>*</b>',
1.391 raeburn 2436: 'LC_pick_box_title',
2437: 'LC_oddrow_value')."\n".
2438: $upasstwo.
2439: &Apache::lonhtmlcommon::row_closure()."\n";
2440: }
1.188 raeburn 2441: foreach my $item (@userinfo) {
2442: my $rowtitle = $lt{$item};
1.252 raeburn 2443: my $hiderow = 0;
1.188 raeburn 2444: if ($item eq 'generation') {
2445: $rowtitle = $genhelp.$rowtitle;
2446: }
1.252 raeburn 2447: my $row = &Apache::lonhtmlcommon::row_title($rowtitle,undef,'LC_oddrow_value')."\n";
1.188 raeburn 2448: if ($newuser) {
1.210 raeburn 2449: if (ref($inst_results) eq 'HASH') {
2450: if ($inst_results->{$item} ne '') {
1.252 raeburn 2451: $row .= '<input type="hidden" name="c'.$item.'" value="'.$inst_results->{$item}.'" />'.$inst_results->{$item};
1.210 raeburn 2452: } else {
1.252 raeburn 2453: if ($context eq 'selfcreate') {
1.391 raeburn 2454: if ($canmodify{$item}) {
1.394 raeburn 2455: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" autocomplete="off" />';
1.252 raeburn 2456: $editable ++;
2457: } else {
2458: $hiderow = 1;
2459: }
1.253 raeburn 2460: } else {
2461: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
1.252 raeburn 2462: }
1.210 raeburn 2463: }
1.188 raeburn 2464: } else {
1.252 raeburn 2465: if ($context eq 'selfcreate') {
1.401 raeburn 2466: if ($canmodify{$item}) {
2467: if ($newuser eq 'email') {
2468: $row .= '<input type="text" name="'.$item.'" size="'.$textboxsize{$item}.'" value="" autocomplete="off" />';
1.287 raeburn 2469: } else {
1.401 raeburn 2470: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" autocomplete="off" />';
1.287 raeburn 2471: }
1.401 raeburn 2472: $editable ++;
2473: } else {
2474: $hiderow = 1;
1.252 raeburn 2475: }
1.253 raeburn 2476: } else {
2477: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
1.252 raeburn 2478: }
1.188 raeburn 2479: }
2480: } else {
1.219 raeburn 2481: if ($canmodify{$item}) {
1.252 raeburn 2482: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="'.$userenv{$item}.'" />';
1.393 raeburn 2483: if (($item eq 'id') && (!$newuser)) {
2484: $row .= '<br />'.&Apache::lonuserutils::forceid_change($context);
2485: }
1.188 raeburn 2486: } else {
1.252 raeburn 2487: $row .= $userenv{$item};
1.188 raeburn 2488: }
2489: }
1.252 raeburn 2490: $row .= &Apache::lonhtmlcommon::row_closure(1);
2491: if (!$hiderow) {
2492: $output .= $row;
2493: $rowcount ++;
2494: }
1.188 raeburn 2495: }
1.286 raeburn 2496: if (($canmodify_status{'inststatus'}) || ($context ne 'selfcreate')) {
2497: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($ccdomain);
2498: if (ref($types) eq 'ARRAY') {
2499: if (@{$types} > 0) {
2500: my ($hiderow,$shown);
2501: if ($canmodify_status{'inststatus'}) {
2502: $shown = &pick_inst_statuses($userenv{'inststatus'},$usertypes,$types);
2503: } else {
2504: if ($userenv{'inststatus'} eq '') {
2505: $hiderow = 1;
1.334 raeburn 2506: } else {
2507: my @showitems;
2508: foreach my $item ( map { &unescape($_); } split(':',$userenv{'inststatus'})) {
2509: if (exists($usertypes->{$item})) {
2510: push(@showitems,$usertypes->{$item});
2511: } else {
2512: push(@showitems,$item);
2513: }
2514: }
2515: if (@showitems) {
2516: $shown = join(', ',@showitems);
2517: } else {
2518: $hiderow = 1;
2519: }
1.286 raeburn 2520: }
2521: }
2522: if (!$hiderow) {
1.389 bisitz 2523: my $row = &Apache::lonhtmlcommon::row_title(&mt('Affiliations'),undef,'LC_oddrow_value')."\n".
1.286 raeburn 2524: $shown.&Apache::lonhtmlcommon::row_closure(1);
2525: if ($context eq 'selfcreate') {
2526: $rowcount ++;
2527: }
2528: $output .= $row;
2529: }
2530: }
2531: }
2532: }
1.391 raeburn 2533: if (($context eq 'selfcreate') && ($newuser eq 'email')) {
2534: if ($captchaform) {
1.406.2.2 raeburn 2535: $output .= &Apache::lonhtmlcommon::row_title($lt{'valid'}.'*',
1.391 raeburn 2536: 'LC_pick_box_title')."\n".
2537: $captchaform."\n".'<br /><br />'.
2538: &Apache::lonhtmlcommon::row_closure(1);
2539: $rowcount ++;
2540: }
2541: my $submit_text = &mt('Create account');
2542: $output .= &Apache::lonhtmlcommon::row_title()."\n".
2543: '<br /><input type="submit" name="createaccount" value="'.
2544: $submit_text.'" />'.
1.396 raeburn 2545: '<input type="hidden" name="type" value="'.$usertype.'" />'.
1.391 raeburn 2546: &Apache::lonhtmlcommon::row_closure(1);
2547: }
1.188 raeburn 2548: $output .= &Apache::lonhtmlcommon::end_pick_box();
1.206 raeburn 2549: if (wantarray) {
1.252 raeburn 2550: if ($context eq 'selfcreate') {
2551: return($output,$rowcount,$editable);
2552: } else {
1.388 bisitz 2553: return $output;
1.252 raeburn 2554: }
1.206 raeburn 2555: } else {
2556: return $output;
2557: }
1.188 raeburn 2558: }
2559:
1.286 raeburn 2560: sub pick_inst_statuses {
2561: my ($curr,$usertypes,$types) = @_;
2562: my ($output,$rem,@currtypes);
2563: if ($curr ne '') {
2564: @currtypes = map { &unescape($_); } split(/:/,$curr);
2565: }
2566: my $numinrow = 2;
2567: if (ref($types) eq 'ARRAY') {
2568: $output = '<table>';
2569: my $lastcolspan;
2570: for (my $i=0; $i<@{$types}; $i++) {
2571: if (defined($usertypes->{$types->[$i]})) {
2572: my $rem = $i%($numinrow);
2573: if ($rem == 0) {
2574: if ($i<@{$types}-1) {
2575: if ($i > 0) {
2576: $output .= '</tr>';
2577: }
2578: $output .= '<tr>';
2579: }
2580: } elsif ($i==@{$types}-1) {
2581: my $colsleft = $numinrow - $rem;
2582: if ($colsleft > 1) {
2583: $lastcolspan = ' colspan="'.$colsleft.'"';
2584: }
2585: }
2586: my $check = ' ';
2587: if (grep(/^\Q$types->[$i]\E$/,@currtypes)) {
2588: $check = ' checked="checked" ';
2589: }
2590: $output .= '<td class="LC_left_item"'.$lastcolspan.'>'.
2591: '<span class="LC_nobreak"><label>'.
2592: '<input type="checkbox" name="inststatus" '.
2593: 'value="'.$types->[$i].'"'.$check.'/>'.
2594: $usertypes->{$types->[$i]}.'</label></span></td>';
2595: }
2596: }
2597: $output .= '</tr></table>';
2598: }
2599: return $output;
2600: }
2601:
1.257 raeburn 2602: sub selfcreate_canmodify {
2603: my ($context,$dom,$userinfo,$inst_results,$rolesarray) = @_;
2604: if (ref($inst_results) eq 'HASH') {
2605: my @inststatuses = &get_inststatuses($inst_results);
2606: if (@inststatuses == 0) {
2607: @inststatuses = ('default');
2608: }
2609: $rolesarray = \@inststatuses;
2610: }
2611: my %canmodify =
2612: &Apache::lonuserutils::can_modify_userinfo($context,$dom,$userinfo,
2613: $rolesarray);
2614: return %canmodify;
2615: }
2616:
1.252 raeburn 2617: sub get_inststatuses {
2618: my ($insthashref) = @_;
2619: my @inststatuses = ();
2620: if (ref($insthashref) eq 'HASH') {
2621: if (ref($insthashref->{'inststatus'}) eq 'ARRAY') {
2622: @inststatuses = @{$insthashref->{'inststatus'}};
2623: }
2624: }
2625: return @inststatuses;
2626: }
2627:
1.4 www 2628: # ================================================================= Phase Three
1.42 matthew 2629: sub update_user_data {
1.375 raeburn 2630: my ($r,$context,$crstype,$brcrum,$showcredits) = @_;
1.101 albertel 2631: my $uhome=&Apache::lonnet::homeserver($env{'form.ccuname'},
2632: $env{'form.ccdomain'});
1.27 matthew 2633: # Error messages
1.188 raeburn 2634: my $error = '<span class="LC_error">'.&mt('Error').': ';
1.193 raeburn 2635: my $end = '</span><br /><br />';
2636: my $rtnlink = '<a href="javascript:backPage(document.userupdate,'.
1.188 raeburn 2637: "'$env{'form.prevphase'}','modify')".'" />'.
1.219 raeburn 2638: &mt('Return to previous page').'</a>'.
2639: &Apache::loncommon::end_page();
2640: my $now = time;
1.40 www 2641: my $title;
1.101 albertel 2642: if (exists($env{'form.makeuser'})) {
1.40 www 2643: $title='Set Privileges for New User';
2644: } else {
2645: $title='Modify User Privileges';
2646: }
1.213 raeburn 2647: my $newuser = 0;
1.160 raeburn 2648: my ($jsback,$elements) = &crumb_utilities();
2649: my $jscript = '<script type="text/javascript">'."\n".
1.301 bisitz 2650: '// <![CDATA['."\n".
2651: $jsback."\n".
2652: '// ]]>'."\n".
2653: '</script>'."\n";
1.406.2.7 raeburn 2654: my %breadcrumb_text = &singleuser_breadcrumb($crstype,$context,$env{'form.ccdomain'});
1.351 raeburn 2655: push (@{$brcrum},
2656: {href => "javascript:backPage(document.userupdate)",
2657: text => $breadcrumb_text{'search'},
2658: faq => 282,
2659: bug => 'Instructor Interface',}
2660: );
2661: if ($env{'form.prevphase'} eq 'userpicked') {
2662: push(@{$brcrum},
2663: {href => "javascript:backPage(document.userupdate,'get_user_info','select')",
2664: text => $breadcrumb_text{'userpicked'},
2665: faq => 282,
2666: bug => 'Instructor Interface',});
1.233 raeburn 2667: }
1.224 raeburn 2668: my $helpitem = 'Course_Change_Privileges';
2669: if ($env{'form.action'} eq 'singlestudent') {
2670: $helpitem = 'Course_Add_Student';
1.406.2.14 raeburn 2671: } elsif ($context eq 'author') {
2672: $helpitem = 'Author_Change_Privileges';
2673: } elsif ($context eq 'domain') {
2674: $helpitem = 'Domain_Change_Privileges';
1.224 raeburn 2675: }
1.351 raeburn 2676: push(@{$brcrum},
2677: {href => "javascript:backPage(document.userupdate,'$env{'form.prevphase'}','modify')",
2678: text => $breadcrumb_text{'modify'},
2679: faq => 282,
2680: bug => 'Instructor Interface',},
2681: {href => "/adm/createuser",
2682: text => "Result",
2683: faq => 282,
2684: bug => 'Instructor Interface',
2685: help => $helpitem});
2686: my $args = {bread_crumbs => $brcrum,
2687: bread_crumbs_component => 'User Management'};
2688: if ($env{'form.popup'}) {
2689: $args->{'no_nav_bar'} = 1;
2690: }
2691: $r->print(&Apache::loncommon::start_page($title,$jscript,$args));
1.188 raeburn 2692: $r->print(&update_result_form($uhome));
1.27 matthew 2693: # Check Inputs
1.101 albertel 2694: if (! $env{'form.ccuname'} ) {
1.193 raeburn 2695: $r->print($error.&mt('No login name specified').'.'.$end.$rtnlink);
1.27 matthew 2696: return;
2697: }
1.138 albertel 2698: if ( $env{'form.ccuname'} ne
2699: &LONCAPA::clean_username($env{'form.ccuname'}) ) {
1.281 bisitz 2700: $r->print($error.&mt('Invalid login name.').' '.
2701: &mt('Only letters, numbers, periods, dashes, @, and underscores are valid.').
1.193 raeburn 2702: $end.$rtnlink);
1.27 matthew 2703: return;
2704: }
1.101 albertel 2705: if (! $env{'form.ccdomain'} ) {
1.193 raeburn 2706: $r->print($error.&mt('No domain specified').'.'.$end.$rtnlink);
1.27 matthew 2707: return;
2708: }
1.138 albertel 2709: if ( $env{'form.ccdomain'} ne
2710: &LONCAPA::clean_domain($env{'form.ccdomain'}) ) {
1.281 bisitz 2711: $r->print($error.&mt('Invalid domain name.').' '.
2712: &mt('Only letters, numbers, periods, dashes, and underscores are valid.').
1.193 raeburn 2713: $end.$rtnlink);
1.27 matthew 2714: return;
2715: }
1.219 raeburn 2716: if ($uhome eq 'no_host') {
2717: $newuser = 1;
2718: }
1.101 albertel 2719: if (! exists($env{'form.makeuser'})) {
1.29 matthew 2720: # Modifying an existing user, so check the validity of the name
2721: if ($uhome eq 'no_host') {
1.389 bisitz 2722: $r->print(
2723: $error
2724: .'<p class="LC_error">'
2725: .&mt('Unable to determine home server for [_1] in domain [_2].',
2726: '"'.$env{'form.ccuname'}.'"','"'.$env{'form.ccdomain'}.'"')
2727: .'</p>');
1.29 matthew 2728: return;
2729: }
2730: }
1.27 matthew 2731: # Determine authentication method and password for the user being modified
2732: my $amode='';
2733: my $genpwd='';
1.101 albertel 2734: if ($env{'form.login'} eq 'krb') {
1.41 albertel 2735: $amode='krb';
1.101 albertel 2736: $amode.=$env{'form.krbver'};
2737: $genpwd=$env{'form.krbarg'};
2738: } elsif ($env{'form.login'} eq 'int') {
1.27 matthew 2739: $amode='internal';
1.101 albertel 2740: $genpwd=$env{'form.intarg'};
2741: } elsif ($env{'form.login'} eq 'fsys') {
1.27 matthew 2742: $amode='unix';
1.101 albertel 2743: $genpwd=$env{'form.fsysarg'};
2744: } elsif ($env{'form.login'} eq 'loc') {
1.27 matthew 2745: $amode='localauth';
1.101 albertel 2746: $genpwd=$env{'form.locarg'};
1.27 matthew 2747: $genpwd=" " if (!$genpwd);
1.101 albertel 2748: } elsif (($env{'form.login'} eq 'nochange') ||
2749: ($env{'form.login'} eq '' )) {
1.34 matthew 2750: # There is no need to tell the user we did not change what they
2751: # did not ask us to change.
1.35 matthew 2752: # If they are creating a new user but have not specified login
2753: # information this will be caught below.
1.30 matthew 2754: } else {
1.367 golterma 2755: $r->print($error.&mt('Invalid login mode or password').$end.$rtnlink);
2756: return;
1.27 matthew 2757: }
1.164 albertel 2758:
1.188 raeburn 2759: $r->print('<h3>'.&mt('User [_1] in domain [_2]',
1.367 golterma 2760: $env{'form.ccuname'}.' ('.&Apache::loncommon::plainname($env{'form.ccuname'},
2761: $env{'form.ccdomain'}).')', $env{'form.ccdomain'}).'</h3>');
2762: my %prog_state = &Apache::lonhtmlcommon::Create_PrgWin($r,2);
1.344 bisitz 2763:
1.193 raeburn 2764: my (%alerts,%rulematch,%inst_results,%curr_rules);
1.334 raeburn 2765: my @userinfo = ('firstname','middlename','lastname','generation','permanentemail','id');
1.361 raeburn 2766: my @usertools = ('aboutme','blog','webdav','portfolio');
1.384 raeburn 2767: my @requestcourses = ('official','unofficial','community','textbook');
1.362 raeburn 2768: my @requestauthor = ('requestauthor');
1.286 raeburn 2769: my ($othertitle,$usertypes,$types) =
2770: &Apache::loncommon::sorted_inst_types($env{'form.ccdomain'});
1.334 raeburn 2771: my %canmodify_status =
2772: &Apache::lonuserutils::can_modify_userinfo($context,$env{'form.ccdomain'},
2773: ['inststatus']);
1.101 albertel 2774: if ($env{'form.makeuser'}) {
1.164 albertel 2775: $r->print('<h3>'.&mt('Creating new account.').'</h3>');
1.27 matthew 2776: # Check for the authentication mode and password
2777: if (! $amode || ! $genpwd) {
1.193 raeburn 2778: $r->print($error.&mt('Invalid login mode or password').$end.$rtnlink);
1.27 matthew 2779: return;
1.18 albertel 2780: }
1.29 matthew 2781: # Determine desired host
1.101 albertel 2782: my $desiredhost = $env{'form.hserver'};
1.29 matthew 2783: if (lc($desiredhost) eq 'default') {
2784: $desiredhost = undef;
2785: } else {
1.147 albertel 2786: my %home_servers =
2787: &Apache::lonnet::get_servers($env{'form.ccdomain'},'library');
1.29 matthew 2788: if (! exists($home_servers{$desiredhost})) {
1.193 raeburn 2789: $r->print($error.&mt('Invalid home server specified').$end.$rtnlink);
2790: return;
2791: }
2792: }
2793: # Check ID format
2794: my %checkhash;
2795: my %checks = ('id' => 1);
2796: %{$checkhash{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}}} = (
1.219 raeburn 2797: 'newuser' => $newuser,
1.196 raeburn 2798: 'id' => $env{'form.cid'},
1.193 raeburn 2799: );
1.196 raeburn 2800: if ($env{'form.cid'} ne '') {
2801: &Apache::loncommon::user_rule_check(\%checkhash,\%checks,\%alerts,
2802: \%rulematch,\%inst_results,\%curr_rules);
2803: if (ref($alerts{'id'}) eq 'HASH') {
2804: if (ref($alerts{'id'}{$env{'form.ccdomain'}}) eq 'HASH') {
2805: my $domdesc =
2806: &Apache::lonnet::domain($env{'form.ccdomain'},'description');
2807: if ($alerts{'id'}{$env{'form.ccdomain'}}{$env{'form.cid'}}) {
2808: my $userchkmsg;
2809: if (ref($curr_rules{$env{'form.ccdomain'}}) eq 'HASH') {
2810: $userchkmsg =
2811: &Apache::loncommon::instrule_disallow_msg('id',
2812: $domdesc,1).
2813: &Apache::loncommon::user_rule_formats($env{'form.ccdomain'},
2814: $domdesc,$curr_rules{$env{'form.ccdomain'}}{'id'},'id');
2815: }
2816: $r->print($error.&mt('Invalid ID format').$end.
2817: $userchkmsg.$rtnlink);
2818: return;
2819: }
2820: }
1.29 matthew 2821: }
2822: }
1.367 golterma 2823: &Apache::lonhtmlcommon::Increment_PrgWin($r, \%prog_state);
1.27 matthew 2824: # Call modifyuser
2825: my $result = &Apache::lonnet::modifyuser
1.193 raeburn 2826: ($env{'form.ccdomain'},$env{'form.ccuname'},$env{'form.cid'},
1.188 raeburn 2827: $amode,$genpwd,$env{'form.cfirstname'},
2828: $env{'form.cmiddlename'},$env{'form.clastname'},
2829: $env{'form.cgeneration'},undef,$desiredhost,
2830: $env{'form.cpermanentemail'});
1.77 www 2831: $r->print(&mt('Generating user').': '.$result);
1.219 raeburn 2832: $uhome = &Apache::lonnet::homeserver($env{'form.ccuname'},
1.101 albertel 2833: $env{'form.ccdomain'});
1.334 raeburn 2834: my (%changeHash,%newcustom,%changed,%changedinfo);
1.267 raeburn 2835: if ($uhome ne 'no_host') {
1.334 raeburn 2836: if ($context eq 'domain') {
1.378 raeburn 2837: foreach my $name ('portfolio','author') {
2838: if ($env{'form.custom_'.$name.'quota'} == 1) {
2839: if ($env{'form.'.$name.'quota'} eq '') {
2840: $newcustom{$name.'quota'} = 0;
2841: } else {
2842: $newcustom{$name.'quota'} = $env{'form.'.$name.'quota'};
2843: $newcustom{$name.'quota'} =~ s/[^\d\.]//g;
2844: }
2845: if ("a_admin($newcustom{$name.'quota'},\%changeHash,$name)) {
2846: $changed{$name.'quota'} = 1;
2847: }
1.334 raeburn 2848: }
2849: }
2850: foreach my $item (@usertools) {
2851: if ($env{'form.custom'.$item} == 1) {
2852: $newcustom{$item} = $env{'form.tools_'.$item};
2853: $changed{$item} = &tool_admin($item,$newcustom{$item},
2854: \%changeHash,'tools');
2855: }
1.267 raeburn 2856: }
1.334 raeburn 2857: foreach my $item (@requestcourses) {
1.341 raeburn 2858: if ($env{'form.custom'.$item} == 1) {
2859: $newcustom{$item} = $env{'form.crsreq_'.$item};
2860: if ($env{'form.crsreq_'.$item} eq 'autolimit') {
2861: $newcustom{$item} .= '=';
1.383 raeburn 2862: $env{'form.crsreq_'.$item.'_limit'} =~ s/\D+//g;
2863: if ($env{'form.crsreq_'.$item.'_limit'}) {
1.341 raeburn 2864: $newcustom{$item} .= $env{'form.crsreq_'.$item.'_limit'};
2865: }
1.334 raeburn 2866: }
1.341 raeburn 2867: $changed{$item} = &tool_admin($item,$newcustom{$item},
2868: \%changeHash,'requestcourses');
1.334 raeburn 2869: }
1.275 raeburn 2870: }
1.362 raeburn 2871: if ($env{'form.customrequestauthor'} == 1) {
2872: $newcustom{'requestauthor'} = $env{'form.requestauthor'};
2873: $changed{'requestauthor'} = &tool_admin('requestauthor',
2874: $newcustom{'requestauthor'},
2875: \%changeHash,'requestauthor');
2876: }
1.275 raeburn 2877: }
1.334 raeburn 2878: if ($canmodify_status{'inststatus'}) {
2879: if (exists($env{'form.inststatus'})) {
2880: my @inststatuses = &Apache::loncommon::get_env_multiple('form.inststatus');
2881: if (@inststatuses > 0) {
2882: $changeHash{'inststatus'} = join(',',@inststatuses);
2883: $changed{'inststatus'} = $changeHash{'inststatus'};
1.306 raeburn 2884: }
2885: }
1.232 raeburn 2886: }
1.334 raeburn 2887: if (keys(%changed)) {
2888: foreach my $item (@userinfo) {
2889: $changeHash{$item} = $env{'form.c'.$item};
1.286 raeburn 2890: }
1.267 raeburn 2891: my $chgresult =
2892: &Apache::lonnet::put('environment',\%changeHash,
2893: $env{'form.ccdomain'},$env{'form.ccuname'});
2894: }
1.232 raeburn 2895: }
1.219 raeburn 2896: $r->print('<br />'.&mt('Home server').': '.$uhome.' '.
2897: &Apache::lonnet::hostname($uhome));
1.101 albertel 2898: } elsif (($env{'form.login'} ne 'nochange') &&
2899: ($env{'form.login'} ne '' )) {
1.27 matthew 2900: # Modify user privileges
2901: if (! $amode || ! $genpwd) {
1.193 raeburn 2902: $r->print($error.'Invalid login mode or password'.$end.$rtnlink);
1.27 matthew 2903: return;
1.20 harris41 2904: }
1.395 bisitz 2905: # Only allow authentication modification if the person has authority
1.101 albertel 2906: if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'})) {
1.20 harris41 2907: $r->print('Modifying authentication: '.
1.31 matthew 2908: &Apache::lonnet::modifyuserauth(
1.101 albertel 2909: $env{'form.ccdomain'},$env{'form.ccuname'},
1.21 harris41 2910: $amode,$genpwd));
1.102 albertel 2911: $r->print('<br />'.&mt('Home server').': '.&Apache::lonnet::homeserver
1.101 albertel 2912: ($env{'form.ccuname'},$env{'form.ccdomain'}));
1.4 www 2913: } else {
1.27 matthew 2914: # Okay, this is a non-fatal error.
1.395 bisitz 2915: $r->print($error.&mt('You do not have the authority to modify this users authentication information.').$end);
1.27 matthew 2916: }
1.28 matthew 2917: }
1.344 bisitz 2918: $r->rflush(); # Finish display of header before time consuming actions start
1.367 golterma 2919: &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state);
1.28 matthew 2920: ##
1.375 raeburn 2921: my (@userroles,%userupdate,$cnum,$cdom,$defaultcredits,%namechanged);
1.213 raeburn 2922: if ($context eq 'course') {
1.375 raeburn 2923: ($cnum,$cdom) =
2924: &Apache::lonuserutils::get_course_identity();
1.318 raeburn 2925: $crstype = &Apache::loncommon::course_type($cdom.'_'.$cnum);
1.375 raeburn 2926: if ($showcredits) {
2927: $defaultcredits = &Apache::lonuserutils::get_defaultcredits($cdom,$cnum);
2928: }
1.213 raeburn 2929: }
1.101 albertel 2930: if (! $env{'form.makeuser'} ) {
1.28 matthew 2931: # Check for need to change
2932: my %userenv = &Apache::lonnet::get
1.134 raeburn 2933: ('environment',['firstname','middlename','lastname','generation',
1.378 raeburn 2934: 'id','permanentemail','portfolioquota','authorquota','inststatus',
2935: 'tools.aboutme','tools.blog','tools.webdav','tools.portfolio',
1.361 raeburn 2936: 'requestcourses.official','requestcourses.unofficial',
1.384 raeburn 2937: 'requestcourses.community','requestcourses.textbook',
2938: 'reqcrsotherdom.official','reqcrsotherdom.unofficial',
2939: 'reqcrsotherdom.community','reqcrsotherdom.textbook',
1.406.2.9 raeburn 2940: 'requestauthor'],
1.160 raeburn 2941: $env{'form.ccdomain'},$env{'form.ccuname'});
1.28 matthew 2942: my ($tmp) = keys(%userenv);
2943: if ($tmp =~ /^(con_lost|error)/i) {
2944: %userenv = ();
2945: }
1.206 raeburn 2946: my $no_forceid_alert;
2947: # Check to see if user information can be changed
2948: my %domconfig =
2949: &Apache::lonnet::get_dom('configuration',['usermodification'],
2950: $env{'form.ccdomain'});
1.213 raeburn 2951: my @statuses = ('active','future');
2952: my %roles = &Apache::lonnet::get_my_roles($env{'form.ccuname'},$env{'form.ccdomain'},'userroles',\@statuses,undef,$env{'request.role.domain'});
2953: my ($auname,$audom);
1.220 raeburn 2954: if ($context eq 'author') {
1.206 raeburn 2955: $auname = $env{'user.name'};
2956: $audom = $env{'user.domain'};
2957: }
2958: foreach my $item (keys(%roles)) {
1.220 raeburn 2959: my ($rolenum,$roledom,$role) = split(/:/,$item,-1);
1.206 raeburn 2960: if ($context eq 'course') {
2961: if ($cnum ne '' && $cdom ne '') {
2962: if ($rolenum eq $cnum && $roledom eq $cdom) {
2963: if (!grep(/^\Q$role\E$/,@userroles)) {
2964: push(@userroles,$role);
2965: }
2966: }
2967: }
2968: } elsif ($context eq 'author') {
2969: if ($rolenum eq $auname && $roledom eq $audom) {
2970: if (!grep(/^\Q$role\E$/,@userroles)) {
2971: push(@userroles,$role);
2972: }
2973: }
2974: }
2975: }
1.220 raeburn 2976: if ($env{'form.action'} eq 'singlestudent') {
2977: if (!grep(/^st$/,@userroles)) {
2978: push(@userroles,'st');
2979: }
2980: } else {
2981: # Check for course or co-author roles being activated or re-enabled
2982: if ($context eq 'author' || $context eq 'course') {
2983: foreach my $key (keys(%env)) {
2984: if ($context eq 'author') {
2985: if ($key=~/^form\.act_\Q$audom\E_\Q$auname\E_([^_]+)/) {
2986: if (!grep(/^\Q$1\E$/,@userroles)) {
2987: push(@userroles,$1);
2988: }
2989: } elsif ($key =~/^form\.ren\:\Q$audom\E\/\Q$auname\E_([^_]+)/) {
2990: if (!grep(/^\Q$1\E$/,@userroles)) {
2991: push(@userroles,$1);
2992: }
1.206 raeburn 2993: }
1.220 raeburn 2994: } elsif ($context eq 'course') {
2995: if ($key=~/^form\.act_\Q$cdom\E_\Q$cnum\E_([^_]+)/) {
2996: if (!grep(/^\Q$1\E$/,@userroles)) {
2997: push(@userroles,$1);
2998: }
2999: } elsif ($key =~/^form\.ren\:\Q$cdom\E\/\Q$cnum\E(\/?\w*)_([^_]+)/) {
3000: if (!grep(/^\Q$1\E$/,@userroles)) {
3001: push(@userroles,$1);
3002: }
1.206 raeburn 3003: }
3004: }
3005: }
3006: }
3007: }
3008: #Check to see if we can change personal data for the user
3009: my (@mod_disallowed,@longroles);
3010: foreach my $role (@userroles) {
3011: if ($role eq 'cr') {
3012: push(@longroles,'Custom');
3013: } else {
1.318 raeburn 3014: push(@longroles,&Apache::lonnet::plaintext($role,$crstype));
1.206 raeburn 3015: }
3016: }
1.219 raeburn 3017: my %canmodify = &Apache::lonuserutils::can_modify_userinfo($context,$env{'form.ccdomain'},\@userinfo,\@userroles);
3018: foreach my $item (@userinfo) {
1.28 matthew 3019: # Strip leading and trailing whitespace
1.203 raeburn 3020: $env{'form.c'.$item} =~ s/(\s+$|^\s+)//g;
1.219 raeburn 3021: if (!$canmodify{$item}) {
1.207 raeburn 3022: if (defined($env{'form.c'.$item})) {
3023: if ($env{'form.c'.$item} ne $userenv{$item}) {
3024: push(@mod_disallowed,$item);
3025: }
1.206 raeburn 3026: }
3027: $env{'form.c'.$item} = $userenv{$item};
3028: }
1.28 matthew 3029: }
1.259 bisitz 3030: # Check to see if we can change the Student/Employee ID
1.196 raeburn 3031: my $forceid = $env{'form.forceid'};
3032: my $recurseid = $env{'form.recurseid'};
3033: my (%alerts,%rulematch,%idinst_results,%curr_rules,%got_rules);
1.203 raeburn 3034: my %uidhash = &Apache::lonnet::idrget($env{'form.ccdomain'},
3035: $env{'form.ccuname'});
3036: if (($uidhash{$env{'form.ccuname'}}) &&
3037: ($uidhash{$env{'form.ccuname'}}!~/error\:/) &&
3038: (!$forceid)) {
3039: if ($env{'form.cid'} ne $uidhash{$env{'form.ccuname'}}) {
3040: $env{'form.cid'} = $userenv{'id'};
1.293 bisitz 3041: $no_forceid_alert = &mt('New student/employee ID does not match existing ID for this user.')
1.259 bisitz 3042: .'<br />'
3043: .&mt("Change is not permitted without checking the 'Force ID change' checkbox on the previous page.")
3044: .'<br />'."\n";
1.203 raeburn 3045: }
3046: }
3047: if ($env{'form.cid'} ne $userenv{'id'}) {
1.196 raeburn 3048: my $checkhash;
3049: my $checks = { 'id' => 1 };
3050: $checkhash->{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}} =
3051: { 'newuser' => $newuser,
3052: 'id' => $env{'form.cid'},
3053: };
3054: &Apache::loncommon::user_rule_check($checkhash,$checks,
3055: \%alerts,\%rulematch,\%idinst_results,\%curr_rules,\%got_rules);
3056: if (ref($alerts{'id'}) eq 'HASH') {
3057: if (ref($alerts{'id'}{$env{'form.ccdomain'}}) eq 'HASH') {
1.203 raeburn 3058: $env{'form.cid'} = $userenv{'id'};
1.196 raeburn 3059: }
3060: }
3061: }
1.378 raeburn 3062: my (%quotachanged,%oldquota,%newquota,%olddefquota,%newdefquota,
3063: $oldinststatus,$newinststatus,%oldisdefault,%newisdefault,%oldsettings,
1.339 raeburn 3064: %oldsettingstext,%newsettings,%newsettingstext,@disporder,
1.378 raeburn 3065: %oldsettingstatus,%newsettingstatus);
1.334 raeburn 3066: @disporder = ('inststatus');
3067: if ($env{'request.role.domain'} eq $env{'form.ccdomain'}) {
1.362 raeburn 3068: push(@disporder,'requestcourses','requestauthor');
1.334 raeburn 3069: } else {
3070: push(@disporder,'reqcrsotherdom');
3071: }
3072: push(@disporder,('quota','tools'));
1.338 raeburn 3073: $oldinststatus = $userenv{'inststatus'};
1.378 raeburn 3074: foreach my $name ('portfolio','author') {
3075: ($olddefquota{$name},$oldsettingstatus{$name}) =
3076: &Apache::loncommon::default_quota($env{'form.ccdomain'},$oldinststatus,$name);
3077: ($newdefquota{$name},$newsettingstatus{$name}) = ($olddefquota{$name},$oldsettingstatus{$name});
3078: }
1.334 raeburn 3079: my %canshow;
1.220 raeburn 3080: if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
1.334 raeburn 3081: $canshow{'quota'} = 1;
1.220 raeburn 3082: }
1.267 raeburn 3083: if (&Apache::lonnet::allowed('mut',$env{'form.ccdomain'})) {
1.334 raeburn 3084: $canshow{'tools'} = 1;
1.267 raeburn 3085: }
1.275 raeburn 3086: if (&Apache::lonnet::allowed('ccc',$env{'form.ccdomain'})) {
1.334 raeburn 3087: $canshow{'requestcourses'} = 1;
1.300 raeburn 3088: } elsif (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
1.334 raeburn 3089: $canshow{'reqcrsotherdom'} = 1;
1.275 raeburn 3090: }
1.286 raeburn 3091: if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'})) {
1.334 raeburn 3092: $canshow{'inststatus'} = 1;
1.286 raeburn 3093: }
1.362 raeburn 3094: if (&Apache::lonnet::allowed('cau',$env{'form.ccdomain'})) {
3095: $canshow{'requestauthor'} = 1;
3096: }
1.267 raeburn 3097: my (%changeHash,%changed);
1.286 raeburn 3098: if ($oldinststatus eq '') {
1.334 raeburn 3099: $oldsettings{'inststatus'} = $othertitle;
1.286 raeburn 3100: } else {
3101: if (ref($usertypes) eq 'HASH') {
1.334 raeburn 3102: $oldsettings{'inststatus'} = join(', ',map{ $usertypes->{ &unescape($_) }; } (split(/:/,$userenv{'inststatus'})));
1.286 raeburn 3103: } else {
1.334 raeburn 3104: $oldsettings{'inststatus'} = join(', ',map{ &unescape($_); } (split(/:/,$userenv{'inststatus'})));
1.286 raeburn 3105: }
3106: }
3107: $changeHash{'inststatus'} = $userenv{'inststatus'};
1.334 raeburn 3108: if ($canmodify_status{'inststatus'}) {
3109: $canshow{'inststatus'} = 1;
1.286 raeburn 3110: if (exists($env{'form.inststatus'})) {
3111: my @inststatuses = &Apache::loncommon::get_env_multiple('form.inststatus');
3112: if (@inststatuses > 0) {
3113: $newinststatus = join(':',map { &escape($_); } @inststatuses);
3114: $changeHash{'inststatus'} = $newinststatus;
3115: if ($newinststatus ne $oldinststatus) {
3116: $changed{'inststatus'} = $newinststatus;
1.378 raeburn 3117: foreach my $name ('portfolio','author') {
3118: ($newdefquota{$name},$newsettingstatus{$name}) =
3119: &Apache::loncommon::default_quota($env{'form.ccdomain'},$newinststatus,$name);
3120: }
1.286 raeburn 3121: }
3122: if (ref($usertypes) eq 'HASH') {
1.334 raeburn 3123: $newsettings{'inststatus'} = join(', ',map{ $usertypes->{$_}; } (@inststatuses));
1.286 raeburn 3124: } else {
1.337 raeburn 3125: $newsettings{'inststatus'} = join(', ',@inststatuses);
1.286 raeburn 3126: }
1.334 raeburn 3127: }
3128: } else {
3129: $newinststatus = '';
3130: $changeHash{'inststatus'} = $newinststatus;
3131: $newsettings{'inststatus'} = $othertitle;
3132: if ($newinststatus ne $oldinststatus) {
3133: $changed{'inststatus'} = $changeHash{'inststatus'};
1.378 raeburn 3134: foreach my $name ('portfolio','author') {
3135: ($newdefquota{$name},$newsettingstatus{$name}) =
3136: &Apache::loncommon::default_quota($env{'form.ccdomain'},$newinststatus,$name);
3137: }
1.286 raeburn 3138: }
3139: }
1.334 raeburn 3140: } elsif ($context ne 'selfcreate') {
3141: $canshow{'inststatus'} = 1;
1.337 raeburn 3142: $newsettings{'inststatus'} = $oldsettings{'inststatus'};
1.286 raeburn 3143: }
1.378 raeburn 3144: foreach my $name ('portfolio','author') {
3145: $changeHash{$name.'quota'} = $userenv{$name.'quota'};
3146: }
1.334 raeburn 3147: if ($context eq 'domain') {
1.378 raeburn 3148: foreach my $name ('portfolio','author') {
3149: if ($userenv{$name.'quota'} ne '') {
3150: $oldquota{$name} = $userenv{$name.'quota'};
3151: if ($env{'form.custom_'.$name.'quota'} == 1) {
3152: if ($env{'form.'.$name.'quota'} eq '') {
3153: $newquota{$name} = 0;
3154: } else {
3155: $newquota{$name} = $env{'form.'.$name.'quota'};
3156: $newquota{$name} =~ s/[^\d\.]//g;
3157: }
3158: if ($newquota{$name} != $oldquota{$name}) {
3159: if ("a_admin($newquota{$name},\%changeHash,$name)) {
3160: $changed{$name.'quota'} = 1;
3161: }
3162: }
1.334 raeburn 3163: } else {
1.378 raeburn 3164: if ("a_admin('',\%changeHash,$name)) {
3165: $changed{$name.'quota'} = 1;
3166: $newquota{$name} = $newdefquota{$name};
3167: $newisdefault{$name} = 1;
3168: }
1.334 raeburn 3169: }
1.149 raeburn 3170: } else {
1.378 raeburn 3171: $oldisdefault{$name} = 1;
3172: $oldquota{$name} = $olddefquota{$name};
3173: if ($env{'form.custom_'.$name.'quota'} == 1) {
3174: if ($env{'form.'.$name.'quota'} eq '') {
3175: $newquota{$name} = 0;
3176: } else {
3177: $newquota{$name} = $env{'form.'.$name.'quota'};
3178: $newquota{$name} =~ s/[^\d\.]//g;
3179: }
3180: if ("a_admin($newquota{$name},\%changeHash,$name)) {
3181: $changed{$name.'quota'} = 1;
3182: }
1.334 raeburn 3183: } else {
1.378 raeburn 3184: $newquota{$name} = $newdefquota{$name};
3185: $newisdefault{$name} = 1;
1.334 raeburn 3186: }
1.378 raeburn 3187: }
3188: if ($oldisdefault{$name}) {
3189: $oldsettingstext{'quota'}{$name} = &get_defaultquota_text($oldsettingstatus{$name});
1.383 raeburn 3190: } else {
3191: $oldsettingstext{'quota'}{$name} = &mt('custom quota: [_1] MB',$oldquota{$name});
1.378 raeburn 3192: }
3193: if ($newisdefault{$name}) {
3194: $newsettingstext{'quota'}{$name} = &get_defaultquota_text($newsettingstatus{$name});
1.383 raeburn 3195: } else {
3196: $newsettingstext{'quota'}{$name} = &mt('custom quota: [_1] MB',$newquota{$name});
1.134 raeburn 3197: }
3198: }
1.334 raeburn 3199: &tool_changes('tools',\@usertools,\%oldsettings,\%oldsettingstext,\%userenv,
3200: \%changeHash,\%changed,\%newsettings,\%newsettingstext);
3201: if ($env{'form.ccdomain'} eq $env{'request.role.domain'}) {
3202: &tool_changes('requestcourses',\@requestcourses,\%oldsettings,\%oldsettingstext,
3203: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
1.384 raeburn 3204: &tool_changes('requestauthor',\@requestauthor,\%oldsettings,\%oldsettingstext,
3205: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
1.149 raeburn 3206: } else {
1.334 raeburn 3207: &tool_changes('reqcrsotherdom',\@requestcourses,\%oldsettings,\%oldsettingstext,
3208: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
1.149 raeburn 3209: }
3210: }
1.334 raeburn 3211: foreach my $item (@userinfo) {
3212: if ($env{'form.c'.$item} ne $userenv{$item}) {
3213: $namechanged{$item} = 1;
3214: }
1.204 raeburn 3215: }
1.378 raeburn 3216: foreach my $name ('portfolio','author') {
1.390 bisitz 3217: $oldsettings{'quota'}{$name} = &mt('[_1] MB',$oldquota{$name});
3218: $newsettings{'quota'}{$name} = &mt('[_1] MB',$newquota{$name});
1.378 raeburn 3219: }
1.334 raeburn 3220: if ((keys(%namechanged) > 0) || (keys(%changed) > 0)) {
1.267 raeburn 3221: my ($chgresult,$namechgresult);
3222: if (keys(%changed) > 0) {
3223: $chgresult =
1.204 raeburn 3224: &Apache::lonnet::put('environment',\%changeHash,
3225: $env{'form.ccdomain'},$env{'form.ccuname'});
1.267 raeburn 3226: if ($chgresult eq 'ok') {
3227: if (($env{'user.name'} eq $env{'form.ccuname'}) &&
3228: ($env{'user.domain'} eq $env{'form.ccdomain'})) {
1.270 raeburn 3229: my %newenvhash;
3230: foreach my $key (keys(%changed)) {
1.299 raeburn 3231: if (($key eq 'official') || ($key eq 'unofficial')
1.403 raeburn 3232: || ($key eq 'community') || ($key eq 'textbook')) {
1.279 raeburn 3233: $newenvhash{'environment.requestcourses.'.$key} =
3234: $changeHash{'requestcourses.'.$key};
1.362 raeburn 3235: if ($changeHash{'requestcourses.'.$key}) {
1.332 raeburn 3236: $newenvhash{'environment.canrequest.'.$key} = 1;
1.279 raeburn 3237: } else {
3238: $newenvhash{'environment.canrequest.'.$key} =
3239: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
3240: $key,'reload','requestcourses');
3241: }
1.362 raeburn 3242: } elsif ($key eq 'requestauthor') {
3243: $newenvhash{'environment.'.$key} = $changeHash{$key};
3244: if ($changeHash{$key}) {
3245: $newenvhash{'environment.canrequest.author'} = 1;
3246: } else {
3247: $newenvhash{'environment.canrequest.author'} =
3248: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
3249: $key,'reload','requestauthor');
3250: }
1.275 raeburn 3251: } elsif ($key ne 'quota') {
1.270 raeburn 3252: $newenvhash{'environment.tools.'.$key} =
3253: $changeHash{'tools.'.$key};
1.279 raeburn 3254: if ($changeHash{'tools.'.$key} ne '') {
3255: $newenvhash{'environment.availabletools.'.$key} =
3256: $changeHash{'tools.'.$key};
3257: } else {
3258: $newenvhash{'environment.availabletools.'.$key} =
1.367 golterma 3259: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
3260: $key,'reload','tools');
1.279 raeburn 3261: }
1.270 raeburn 3262: }
3263: }
1.271 raeburn 3264: if (keys(%newenvhash)) {
3265: &Apache::lonnet::appenv(\%newenvhash);
3266: }
1.267 raeburn 3267: }
3268: }
1.204 raeburn 3269: }
1.334 raeburn 3270: if (keys(%namechanged) > 0) {
1.337 raeburn 3271: foreach my $field (@userinfo) {
3272: $changeHash{$field} = $env{'form.c'.$field};
3273: }
3274: # Make the change
1.204 raeburn 3275: $namechgresult =
3276: &Apache::lonnet::modifyuser($env{'form.ccdomain'},
3277: $env{'form.ccuname'},$changeHash{'id'},undef,undef,
3278: $changeHash{'firstname'},$changeHash{'middlename'},
3279: $changeHash{'lastname'},$changeHash{'generation'},
1.337 raeburn 3280: $changeHash{'id'},undef,$changeHash{'permanentemail'},undef,\@userinfo);
1.220 raeburn 3281: %userupdate = (
3282: lastname => $env{'form.clastname'},
3283: middlename => $env{'form.cmiddlename'},
3284: firstname => $env{'form.cfirstname'},
3285: generation => $env{'form.cgeneration'},
3286: id => $env{'form.cid'},
3287: );
1.204 raeburn 3288: }
1.334 raeburn 3289: if (((keys(%namechanged) > 0) && $namechgresult eq 'ok') ||
1.267 raeburn 3290: ((keys(%changed) > 0) && $chgresult eq 'ok')) {
1.28 matthew 3291: # Tell the user we changed the name
1.334 raeburn 3292: &display_userinfo($r,1,\@disporder,\%canshow,\@requestcourses,
1.362 raeburn 3293: \@usertools,\@requestauthor,\%userenv,\%changed,\%namechanged,
1.334 raeburn 3294: \%oldsettings, \%oldsettingstext,\%newsettings,
3295: \%newsettingstext);
1.203 raeburn 3296: if ($env{'form.cid'} ne $userenv{'id'}) {
3297: &Apache::lonnet::idput($env{'form.ccdomain'},
1.406.2.5 raeburn 3298: {$env{'form.ccuname'} => $env{'form.cid'}});
1.203 raeburn 3299: if (($recurseid) &&
3300: (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'}))) {
3301: my $idresult =
3302: &Apache::lonuserutils::propagate_id_change(
3303: $env{'form.ccuname'},$env{'form.ccdomain'},
3304: \%userupdate);
3305: $r->print('<br />'.$idresult.'<br />');
3306: }
1.196 raeburn 3307: }
1.149 raeburn 3308: if (($env{'form.ccdomain'} eq $env{'user.domain'}) &&
3309: ($env{'form.ccuname'} eq $env{'user.name'})) {
3310: my %newenvhash;
3311: foreach my $key (keys(%changeHash)) {
3312: $newenvhash{'environment.'.$key} = $changeHash{$key};
3313: }
1.238 raeburn 3314: &Apache::lonnet::appenv(\%newenvhash);
1.149 raeburn 3315: }
1.28 matthew 3316: } else { # error occurred
1.389 bisitz 3317: $r->print(
3318: '<p class="LC_error">'
3319: .&mt('Unable to successfully change environment for [_1] in domain [_2].',
3320: '"'.$env{'form.ccuname'}.'"',
3321: '"'.$env{'form.ccdomain'}.'"')
3322: .'</p>');
1.28 matthew 3323: }
1.334 raeburn 3324: } else { # End of if ($env ... ) logic
1.275 raeburn 3325: # They did not want to change the users name, quota, tool availability,
3326: # or ability to request creation of courses,
1.267 raeburn 3327: # but we can still tell them what the name and quota and availabilities are
1.334 raeburn 3328: &display_userinfo($r,undef,\@disporder,\%canshow,\@requestcourses,
1.362 raeburn 3329: \@usertools,\@requestauthor,\%userenv,\%changed,\%namechanged,\%oldsettings,
1.334 raeburn 3330: \%oldsettingstext,\%newsettings,\%newsettingstext);
1.28 matthew 3331: }
1.206 raeburn 3332: if (@mod_disallowed) {
3333: my ($rolestr,$contextname);
3334: if (@longroles > 0) {
3335: $rolestr = join(', ',@longroles);
3336: } else {
3337: $rolestr = &mt('No roles');
3338: }
3339: if ($context eq 'course') {
1.399 bisitz 3340: $contextname = 'course';
1.206 raeburn 3341: } elsif ($context eq 'author') {
1.399 bisitz 3342: $contextname = 'co-author';
1.206 raeburn 3343: }
3344: $r->print(&mt('The following fields were not updated: ').'<ul>');
3345: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
3346: foreach my $field (@mod_disallowed) {
3347: $r->print('<li>'.$fieldtitles{$field}.'</li>'."\n");
3348: }
1.207 raeburn 3349: $r->print('</ul>');
3350: if (@mod_disallowed == 1) {
1.399 bisitz 3351: $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 3352: } else {
1.399 bisitz 3353: $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 3354: }
1.292 bisitz 3355: my $helplink = 'javascript:helpMenu('."'display'".')';
3356: $r->print('<span class="LC_cusr_emph">'.$rolestr.'</span><br />'
3357: .&mt('Please contact your [_1]helpdesk[_2] for more information.'
3358: ,'<a href="'.$helplink.'">','</a>')
3359: .'<br />');
1.206 raeburn 3360: }
1.259 bisitz 3361: $r->print('<span class="LC_warning">'
3362: .$no_forceid_alert
3363: .&Apache::lonuserutils::print_namespacing_alerts($env{'form.ccdomain'},\%alerts,\%curr_rules)
3364: .'</span>');
1.4 www 3365: }
1.367 golterma 3366: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
1.220 raeburn 3367: if ($env{'form.action'} eq 'singlestudent') {
1.375 raeburn 3368: &enroll_single_student($r,$uhome,$amode,$genpwd,$now,$newuser,$context,
3369: $crstype,$showcredits,$defaultcredits);
1.386 bisitz 3370: my $linktext = ($crstype eq 'Community' ?
3371: &mt('Enroll Another Member') : &mt('Enroll Another Student'));
3372: $r->print(
3373: &Apache::lonhtmlcommon::actionbox([
3374: '<a href="javascript:backPage(document.userupdate)">'
3375: .($crstype eq 'Community' ?
3376: &mt('Enroll Another Member') : &mt('Enroll Another Student'))
3377: .'</a>']));
1.220 raeburn 3378: } else {
1.375 raeburn 3379: my @rolechanges = &update_roles($r,$context,$showcredits);
1.334 raeburn 3380: if (keys(%namechanged) > 0) {
1.220 raeburn 3381: if ($context eq 'course') {
3382: if (@userroles > 0) {
1.225 raeburn 3383: if ((@rolechanges == 0) ||
3384: (!(grep(/^st$/,@rolechanges)))) {
3385: if (grep(/^st$/,@userroles)) {
3386: my $classlistupdated =
3387: &Apache::lonuserutils::update_classlist($cdom,
1.220 raeburn 3388: $cnum,$env{'form.ccdomain'},
3389: $env{'form.ccuname'},\%userupdate);
1.225 raeburn 3390: }
1.220 raeburn 3391: }
3392: }
3393: }
3394: }
1.226 raeburn 3395: my $userinfo = &Apache::loncommon::plainname($env{'form.ccuname'},
1.233 raeburn 3396: $env{'form.ccdomain'});
3397: if ($env{'form.popup'}) {
3398: $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a></p>');
3399: } else {
1.367 golterma 3400: $r->print('<br />'.&Apache::lonhtmlcommon::actionbox(['<a href="javascript:backPage(document.userupdate,'."'$env{'form.prevphase'}','modify'".')">'
3401: .&mt('Modify this user: [_1]','<span class="LC_cusr_emph">'.$env{'form.ccuname'}.':'.$env{'form.ccdomain'}.' ('.$userinfo.')</span>').'</a>',
3402: '<a href="javascript:backPage(document.userupdate)">'.&mt('Create/Modify Another User').'</a>']));
1.233 raeburn 3403: }
1.220 raeburn 3404: }
3405: }
3406:
1.334 raeburn 3407: sub display_userinfo {
1.362 raeburn 3408: my ($r,$changed,$order,$canshow,$requestcourses,$usertools,$requestauthor,
3409: $userenv,$changedhash,$namechangedhash,$oldsetting,$oldsettingtext,
1.334 raeburn 3410: $newsetting,$newsettingtext) = @_;
3411: return unless (ref($order) eq 'ARRAY' &&
3412: ref($canshow) eq 'HASH' &&
3413: ref($requestcourses) eq 'ARRAY' &&
1.362 raeburn 3414: ref($requestauthor) eq 'ARRAY' &&
1.334 raeburn 3415: ref($usertools) eq 'ARRAY' &&
3416: ref($userenv) eq 'HASH' &&
3417: ref($changedhash) eq 'HASH' &&
3418: ref($oldsetting) eq 'HASH' &&
3419: ref($oldsettingtext) eq 'HASH' &&
3420: ref($newsetting) eq 'HASH' &&
3421: ref($newsettingtext) eq 'HASH');
3422: my %lt=&Apache::lonlocal::texthash(
1.372 raeburn 3423: 'ui' => 'User Information',
1.334 raeburn 3424: 'uic' => 'User Information Changed',
3425: 'firstname' => 'First Name',
3426: 'middlename' => 'Middle Name',
3427: 'lastname' => 'Last Name',
3428: 'generation' => 'Generation',
3429: 'id' => 'Student/Employee ID',
3430: 'permanentemail' => 'Permanent e-mail address',
1.378 raeburn 3431: 'portfolioquota' => 'Disk space allocated to portfolio files',
1.385 bisitz 3432: 'authorquota' => 'Disk space allocated to Authoring Space',
1.334 raeburn 3433: 'blog' => 'Blog Availability',
1.361 raeburn 3434: 'webdav' => 'WebDAV Availability',
1.334 raeburn 3435: 'aboutme' => 'Personal Information Page Availability',
3436: 'portfolio' => 'Portfolio Availability',
3437: 'official' => 'Can Request Official Courses',
3438: 'unofficial' => 'Can Request Unofficial Courses',
3439: 'community' => 'Can Request Communities',
1.384 raeburn 3440: 'textbook' => 'Can Request Textbook Courses',
1.362 raeburn 3441: 'requestauthor' => 'Can Request Author Role',
1.334 raeburn 3442: 'inststatus' => "Affiliation",
3443: 'prvs' => 'Previous Value:',
3444: 'chto' => 'Changed To:'
3445: );
3446: if ($changed) {
1.372 raeburn 3447: $r->print('<h3>'.$lt{'uic'}.'</h3>'.
1.367 golterma 3448: &Apache::loncommon::start_data_table().
3449: &Apache::loncommon::start_data_table_header_row());
1.334 raeburn 3450: $r->print("<th> </th>\n");
1.367 golterma 3451: $r->print('<th><b>'.$lt{'prvs'}.'</b></th>');
3452: $r->print('<th><span class="LC_nobreak"><b>'.$lt{'chto'}.'</b></span></th>');
3453: $r->print(&Apache::loncommon::end_data_table_header_row());
3454: my @userinfo = ('firstname','middlename','lastname','generation','permanentemail','id');
3455:
1.334 raeburn 3456: foreach my $item (@userinfo) {
3457: my $value = $env{'form.c'.$item};
1.367 golterma 3458: #show changes only:
1.383 raeburn 3459: unless ($value eq $userenv->{$item}){
1.367 golterma 3460: $r->print(&Apache::loncommon::start_data_table_row());
3461: $r->print("<td>$lt{$item}</td>\n");
1.383 raeburn 3462: $r->print("<td>".$userenv->{$item}."</td>\n");
1.367 golterma 3463: $r->print("<td>$value </td>\n");
3464: $r->print(&Apache::loncommon::end_data_table_row());
1.334 raeburn 3465: }
3466: }
3467: foreach my $entry (@{$order}) {
1.383 raeburn 3468: if ($canshow->{$entry}) {
3469: if (($entry eq 'requestcourses') || ($entry eq 'reqcrsotherdom') || ($entry eq 'requestauthor')) {
3470: my @items;
3471: if ($entry eq 'requestauthor') {
3472: @items = ($entry);
3473: } else {
3474: @items = @{$requestcourses};
1.384 raeburn 3475: }
1.383 raeburn 3476: foreach my $item (@items) {
3477: if (($newsetting->{$item} ne $oldsetting->{$item}) ||
3478: ($newsettingtext->{$item} ne $oldsettingtext->{$item})) {
3479: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3480: $r->print("<td>$lt{$item}</td>\n");
3481: $r->print("<td>".$oldsetting->{$item});
3482: if ($oldsettingtext->{$item}) {
3483: if ($oldsetting->{$item}) {
3484: $r->print(' -- ');
3485: }
3486: $r->print($oldsettingtext->{$item});
3487: }
3488: $r->print("</td>\n");
3489: $r->print("<td>".$newsetting->{$item});
3490: if ($newsettingtext->{$item}) {
3491: if ($newsetting->{$item}) {
3492: $r->print(' -- ');
3493: }
3494: $r->print($newsettingtext->{$item});
3495: }
3496: $r->print("</td>\n");
3497: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.334 raeburn 3498: }
3499: }
3500: } elsif ($entry eq 'tools') {
3501: foreach my $item (@{$usertools}) {
1.383 raeburn 3502: if ($newsetting->{$item} ne $oldsetting->{$item}) {
3503: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3504: $r->print("<td>$lt{$item}</td>\n");
3505: $r->print("<td>".$oldsetting->{$item}.' '.$oldsettingtext->{$item}."</td>\n");
3506: $r->print("<td>".$newsetting->{$item}.' '.$newsettingtext->{$item}."</td>\n");
3507: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.334 raeburn 3508: }
3509: }
1.378 raeburn 3510: } elsif ($entry eq 'quota') {
3511: if ((ref($oldsetting->{$entry}) eq 'HASH') && (ref($oldsettingtext->{$entry}) eq 'HASH') &&
3512: (ref($newsetting->{$entry}) eq 'HASH') && (ref($newsettingtext->{$entry}) eq 'HASH')) {
3513: foreach my $name ('portfolio','author') {
1.383 raeburn 3514: if ($newsetting->{$entry}->{$name} ne $oldsetting->{$entry}->{$name}) {
3515: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3516: $r->print("<td>$lt{$name.$entry}</td>\n");
3517: $r->print("<td>".$oldsettingtext->{$entry}->{$name}."</td>\n");
3518: $r->print("<td>".$newsettingtext->{$entry}->{$name}."</td>\n");
3519: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.378 raeburn 3520: }
3521: }
3522: }
1.334 raeburn 3523: } else {
1.383 raeburn 3524: if ($newsetting->{$entry} ne $oldsetting->{$entry}) {
3525: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3526: $r->print("<td>$lt{$entry}</td>\n");
3527: $r->print("<td>".$oldsetting->{$entry}.' '.$oldsettingtext->{$entry}."</td>\n");
3528: $r->print("<td>".$newsetting->{$entry}.' '.$newsettingtext->{$entry}."</td>\n");
3529: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.334 raeburn 3530: }
3531: }
3532: }
3533: }
1.367 golterma 3534: $r->print(&Apache::loncommon::end_data_table().'<br />');
1.372 raeburn 3535: } else {
3536: $r->print('<h3>'.$lt{'ui'}.'</h3>'.
3537: '<p>'.&mt('No changes made to user information').'</p>');
1.334 raeburn 3538: }
3539: return;
3540: }
3541:
1.275 raeburn 3542: sub tool_changes {
3543: my ($context,$usertools,$oldaccess,$oldaccesstext,$userenv,$changeHash,
3544: $changed,$newaccess,$newaccesstext) = @_;
3545: if (!((ref($usertools) eq 'ARRAY') && (ref($oldaccess) eq 'HASH') &&
3546: (ref($oldaccesstext) eq 'HASH') && (ref($userenv) eq 'HASH') &&
3547: (ref($changeHash) eq 'HASH') && (ref($changed) eq 'HASH') &&
3548: (ref($newaccess) eq 'HASH') && (ref($newaccesstext) eq 'HASH'))) {
3549: return;
3550: }
1.383 raeburn 3551: my %reqdisplay = &requestchange_display();
1.300 raeburn 3552: if ($context eq 'reqcrsotherdom') {
1.309 raeburn 3553: my @options = ('approval','validate','autolimit');
1.306 raeburn 3554: my $optregex = join('|',@options);
1.300 raeburn 3555: my $cdom = $env{'request.role.domain'};
3556: foreach my $tool (@{$usertools}) {
1.383 raeburn 3557: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
1.314 raeburn 3558: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
1.300 raeburn 3559: $changeHash->{$context.'.'.$tool} = $userenv->{$context.'.'.$tool};
1.383 raeburn 3560: my ($newop,$limit);
1.314 raeburn 3561: if ($env{'form.'.$context.'_'.$tool}) {
3562: $newop = $env{'form.'.$context.'_'.$tool};
3563: if ($newop eq 'autolimit') {
1.383 raeburn 3564: $limit = $env{'form.'.$context.'_'.$tool.'_limit'};
1.314 raeburn 3565: $limit =~ s/\D+//g;
3566: $newop .= '='.$limit;
3567: }
3568: }
1.300 raeburn 3569: if ($userenv->{$context.'.'.$tool} eq '') {
1.314 raeburn 3570: if ($newop) {
3571: $changed->{$tool}=&tool_admin($tool,$cdom.':'.$newop,
1.300 raeburn 3572: $changeHash,$context);
3573: if ($changed->{$tool}) {
1.383 raeburn 3574: if ($newop =~ /^autolimit/) {
3575: if ($limit) {
3576: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3577: } else {
3578: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3579: }
3580: } else {
3581: $newaccesstext->{$tool} = $reqdisplay{$newop};
3582: }
1.300 raeburn 3583: } else {
3584: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
3585: }
3586: }
3587: } else {
3588: my @curr = split(',',$userenv->{$context.'.'.$tool});
3589: my @new;
3590: my $changedoms;
1.314 raeburn 3591: foreach my $req (@curr) {
3592: if ($req =~ /^\Q$cdom\E\:($optregex\=?\d*)$/) {
3593: my $oldop = $1;
1.383 raeburn 3594: if ($oldop =~ /^autolimit=(\d*)/) {
3595: my $limit = $1;
3596: if ($limit) {
3597: $oldaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3598: } else {
3599: $oldaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3600: }
3601: } else {
3602: $oldaccesstext->{$tool} = $reqdisplay{$oldop};
3603: }
1.314 raeburn 3604: if ($oldop ne $newop) {
3605: $changedoms = 1;
3606: foreach my $item (@curr) {
3607: my ($reqdom,$option) = split(':',$item);
3608: unless ($reqdom eq $cdom) {
3609: push(@new,$item);
3610: }
3611: }
3612: if ($newop) {
3613: push(@new,$cdom.':'.$newop);
1.300 raeburn 3614: }
1.314 raeburn 3615: @new = sort(@new);
1.300 raeburn 3616: }
1.314 raeburn 3617: last;
1.300 raeburn 3618: }
1.314 raeburn 3619: }
3620: if ((!$changedoms) && ($newop)) {
1.300 raeburn 3621: $changedoms = 1;
1.306 raeburn 3622: @new = sort(@curr,$cdom.':'.$newop);
1.300 raeburn 3623: }
3624: if ($changedoms) {
1.314 raeburn 3625: my $newdomstr;
1.300 raeburn 3626: if (@new) {
3627: $newdomstr = join(',',@new);
3628: }
3629: $changed->{$tool}=&tool_admin($tool,$newdomstr,$changeHash,
3630: $context);
3631: if ($changed->{$tool}) {
3632: if ($env{'form.'.$context.'_'.$tool}) {
1.306 raeburn 3633: if ($env{'form.'.$context.'_'.$tool} eq 'autolimit') {
1.314 raeburn 3634: my $limit = $env{'form.'.$context.'_'.$tool.'_limit'};
3635: $limit =~ s/\D+//g;
3636: if ($limit) {
1.383 raeburn 3637: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
1.314 raeburn 3638: } else {
1.383 raeburn 3639: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
1.306 raeburn 3640: }
1.314 raeburn 3641: } else {
1.306 raeburn 3642: $newaccesstext->{$tool} = $reqdisplay{$env{'form.'.$context.'_'.$tool}};
3643: }
1.300 raeburn 3644: } else {
1.383 raeburn 3645: $newaccesstext->{$tool} = &mt("availability set to 'off'");
1.300 raeburn 3646: }
3647: }
3648: }
3649: }
3650: }
3651: return;
3652: }
1.275 raeburn 3653: foreach my $tool (@{$usertools}) {
1.383 raeburn 3654: my ($newval,$limit,$envkey);
1.362 raeburn 3655: $envkey = $context.'.'.$tool;
1.306 raeburn 3656: if ($context eq 'requestcourses') {
3657: $newval = $env{'form.crsreq_'.$tool};
3658: if ($newval eq 'autolimit') {
1.383 raeburn 3659: $limit = $env{'form.crsreq_'.$tool.'_limit'};
3660: $limit =~ s/\D+//g;
3661: $newval .= '='.$limit;
1.306 raeburn 3662: }
1.362 raeburn 3663: } elsif ($context eq 'requestauthor') {
3664: $newval = $env{'form.'.$context};
3665: $envkey = $context;
1.314 raeburn 3666: } else {
1.306 raeburn 3667: $newval = $env{'form.'.$context.'_'.$tool};
3668: }
1.362 raeburn 3669: if ($userenv->{$envkey} ne '') {
1.275 raeburn 3670: $oldaccess->{$tool} = &mt('custom');
1.383 raeburn 3671: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3672: if ($userenv->{$envkey} =~ /^autolimit=(\d*)$/) {
3673: my $currlimit = $1;
3674: if ($currlimit eq '') {
3675: $oldaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3676: } else {
3677: $oldaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$currlimit);
3678: }
3679: } elsif ($userenv->{$envkey}) {
3680: $oldaccesstext->{$tool} = $reqdisplay{$userenv->{$envkey}};
3681: } else {
3682: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
3683: }
1.275 raeburn 3684: } else {
1.383 raeburn 3685: if ($userenv->{$envkey}) {
3686: $oldaccesstext->{$tool} = &mt("availability set to 'on'");
3687: } else {
3688: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
3689: }
1.275 raeburn 3690: }
1.362 raeburn 3691: $changeHash->{$envkey} = $userenv->{$envkey};
1.275 raeburn 3692: if ($env{'form.custom'.$tool} == 1) {
1.362 raeburn 3693: if ($newval ne $userenv->{$envkey}) {
1.306 raeburn 3694: $changed->{$tool} = &tool_admin($tool,$newval,$changeHash,
3695: $context);
1.275 raeburn 3696: if ($changed->{$tool}) {
3697: $newaccess->{$tool} = &mt('custom');
1.383 raeburn 3698: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3699: if ($newval =~ /^autolimit/) {
3700: if ($limit) {
3701: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3702: } else {
3703: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3704: }
3705: } elsif ($newval) {
3706: $newaccesstext->{$tool} = $reqdisplay{$newval};
3707: } else {
3708: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3709: }
1.275 raeburn 3710: } else {
1.383 raeburn 3711: if ($newval) {
3712: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3713: } else {
3714: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3715: }
1.275 raeburn 3716: }
3717: } else {
3718: $newaccess->{$tool} = $oldaccess->{$tool};
1.383 raeburn 3719: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3720: if ($newval =~ /^autolimit/) {
3721: if ($limit) {
3722: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3723: } else {
3724: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3725: }
3726: } elsif ($newval) {
3727: $newaccesstext->{$tool} = $reqdisplay{$newval};
3728: } else {
3729: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3730: }
1.275 raeburn 3731: } else {
1.383 raeburn 3732: if ($userenv->{$context.'.'.$tool}) {
3733: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3734: } else {
3735: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3736: }
1.275 raeburn 3737: }
3738: }
3739: } else {
3740: $newaccess->{$tool} = $oldaccess->{$tool};
3741: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
3742: }
3743: } else {
3744: $changed->{$tool} = &tool_admin($tool,'',$changeHash,$context);
3745: if ($changed->{$tool}) {
3746: $newaccess->{$tool} = &mt('default');
3747: } else {
3748: $newaccess->{$tool} = $oldaccess->{$tool};
1.383 raeburn 3749: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3750: if ($newval =~ /^autolimit/) {
3751: if ($limit) {
3752: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3753: } else {
3754: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3755: }
3756: } elsif ($newval) {
3757: $newaccesstext->{$tool} = $reqdisplay{$newval};
3758: } else {
3759: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3760: }
1.275 raeburn 3761: } else {
1.383 raeburn 3762: if ($userenv->{$context.'.'.$tool}) {
3763: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3764: } else {
3765: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3766: }
1.275 raeburn 3767: }
3768: }
3769: }
3770: } else {
3771: $oldaccess->{$tool} = &mt('default');
3772: if ($env{'form.custom'.$tool} == 1) {
1.306 raeburn 3773: $changed->{$tool} = &tool_admin($tool,$newval,$changeHash,
3774: $context);
1.275 raeburn 3775: if ($changed->{$tool}) {
3776: $newaccess->{$tool} = &mt('custom');
1.383 raeburn 3777: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3778: if ($newval =~ /^autolimit/) {
3779: if ($limit) {
3780: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3781: } else {
3782: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3783: }
3784: } elsif ($newval) {
3785: $newaccesstext->{$tool} = $reqdisplay{$newval};
3786: } else {
3787: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3788: }
1.275 raeburn 3789: } else {
1.383 raeburn 3790: if ($newval) {
3791: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3792: } else {
3793: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3794: }
1.275 raeburn 3795: }
3796: } else {
3797: $newaccess->{$tool} = $oldaccess->{$tool};
3798: }
3799: } else {
3800: $newaccess->{$tool} = $oldaccess->{$tool};
3801: }
3802: }
3803: }
3804: return;
3805: }
3806:
1.220 raeburn 3807: sub update_roles {
1.375 raeburn 3808: my ($r,$context,$showcredits) = @_;
1.4 www 3809: my $now=time;
1.225 raeburn 3810: my @rolechanges;
1.220 raeburn 3811: my %disallowed;
1.73 sakharuk 3812: $r->print('<h3>'.&mt('Modifying Roles').'</h3>');
1.404 raeburn 3813: foreach my $key (keys(%env)) {
1.135 raeburn 3814: next if (! $env{$key});
1.190 raeburn 3815: next if ($key eq 'form.action');
1.27 matthew 3816: # Revoke roles
1.135 raeburn 3817: if ($key=~/^form\.rev/) {
3818: if ($key=~/^form\.rev\:([^\_]+)\_([^\_\.]+)$/) {
1.64 www 3819: # Revoke standard role
1.170 albertel 3820: my ($scope,$role) = ($1,$2);
3821: my $result =
3822: &Apache::lonnet::revokerole($env{'form.ccdomain'},
3823: $env{'form.ccuname'},
1.239 raeburn 3824: $scope,$role,'','',$context);
1.367 golterma 3825: $r->print(&Apache::lonhtmlcommon::confirm_success(
1.369 bisitz 3826: &mt('Revoking [_1] in [_2]',
3827: &Apache::lonnet::plaintext($role),
1.372 raeburn 3828: &Apache::loncommon::show_role_extent($scope,$context,$role)),
1.369 bisitz 3829: $result ne "ok").'<br />');
3830: if ($result ne "ok") {
3831: $r->print(&mt('Error: [_1]',$result).'<br />');
3832: }
1.170 albertel 3833: if ($role eq 'st') {
1.202 raeburn 3834: my $result =
1.198 raeburn 3835: &Apache::lonuserutils::classlist_drop($scope,
3836: $env{'form.ccuname'},$env{'form.ccdomain'},
1.202 raeburn 3837: $now);
1.367 golterma 3838: $r->print(&Apache::lonhtmlcommon::confirm_success($result));
1.53 www 3839: }
1.225 raeburn 3840: if (!grep(/^\Q$role\E$/,@rolechanges)) {
3841: push(@rolechanges,$role);
3842: }
1.196 raeburn 3843: }
1.195 raeburn 3844: if ($key=~m{^form\.rev\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}s) {
1.64 www 3845: # Revoke custom role
1.369 bisitz 3846: my $result = &Apache::lonnet::revokecustomrole(
3847: $env{'form.ccdomain'},$env{'form.ccuname'},$1,$2,$3,$4,'','',$context);
1.367 golterma 3848: $r->print(&Apache::lonhtmlcommon::confirm_success(
1.369 bisitz 3849: &mt('Revoking custom role [_1] by [_2] in [_3]',
1.372 raeburn 3850: $4,$3.':'.$2,&Apache::loncommon::show_role_extent($1,$context,'cr')),
1.369 bisitz 3851: $result ne 'ok').'<br />');
3852: if ($result ne "ok") {
3853: $r->print(&mt('Error: [_1]',$result).'<br />');
3854: }
1.225 raeburn 3855: if (!grep(/^cr$/,@rolechanges)) {
3856: push(@rolechanges,'cr');
3857: }
1.64 www 3858: }
1.135 raeburn 3859: } elsif ($key=~/^form\.del/) {
3860: if ($key=~/^form\.del\:([^\_]+)\_([^\_\.]+)$/) {
1.116 raeburn 3861: # Delete standard role
1.170 albertel 3862: my ($scope,$role) = ($1,$2);
3863: my $result =
3864: &Apache::lonnet::assignrole($env{'form.ccdomain'},
3865: $env{'form.ccuname'},
1.239 raeburn 3866: $scope,$role,$now,0,1,'',
3867: $context);
1.367 golterma 3868: $r->print(&Apache::lonhtmlcommon::confirm_success(
3869: &mt('Deleting [_1] in [_2]',
1.369 bisitz 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.367 golterma 3876:
1.170 albertel 3877: if ($role eq 'st') {
1.202 raeburn 3878: my $result =
1.198 raeburn 3879: &Apache::lonuserutils::classlist_drop($scope,
3880: $env{'form.ccuname'},$env{'form.ccdomain'},
1.202 raeburn 3881: $now);
1.369 bisitz 3882: $r->print(&Apache::lonhtmlcommon::confirm_success($result));
1.81 albertel 3883: }
1.225 raeburn 3884: if (!grep(/^\Q$role\E$/,@rolechanges)) {
3885: push(@rolechanges,$role);
3886: }
1.116 raeburn 3887: }
1.139 albertel 3888: if ($key=~m{^form\.del\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
1.116 raeburn 3889: my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
3890: # Delete custom role
1.369 bisitz 3891: my $result =
3892: &Apache::lonnet::assigncustomrole($env{'form.ccdomain'},
3893: $env{'form.ccuname'},$url,$rdom,$rnam,$rolename,$now,
3894: 0,1,$context);
3895: $r->print(&Apache::lonhtmlcommon::confirm_success(&mt('Deleting custom role [_1] by [_2] in [_3]',
1.372 raeburn 3896: $rolename,$rnam.':'.$rdom,&Apache::loncommon::show_role_extent($1,$context,'cr')),
1.369 bisitz 3897: $result ne "ok").'<br />');
3898: if ($result ne "ok") {
3899: $r->print(&mt('Error: [_1]',$result).'<br />');
3900: }
1.367 golterma 3901:
1.225 raeburn 3902: if (!grep(/^cr$/,@rolechanges)) {
3903: push(@rolechanges,'cr');
3904: }
1.116 raeburn 3905: }
1.135 raeburn 3906: } elsif ($key=~/^form\.ren/) {
1.101 albertel 3907: my $udom = $env{'form.ccdomain'};
3908: my $uname = $env{'form.ccuname'};
1.116 raeburn 3909: # Re-enable standard role
1.135 raeburn 3910: if ($key=~/^form\.ren\:([^\_]+)\_([^\_\.]+)$/) {
1.89 raeburn 3911: my $url = $1;
3912: my $role = $2;
3913: my $logmsg;
3914: my $output;
3915: if ($role eq 'st') {
1.141 albertel 3916: if ($url =~ m-^/($match_domain)/($match_courseid)/?(\w*)$-) {
1.374 raeburn 3917: my ($cdom,$cnum,$csec) = ($1,$2,$3);
1.375 raeburn 3918: my $credits;
3919: if ($showcredits) {
3920: my $defaultcredits =
3921: &Apache::lonuserutils::get_defaultcredits($cdom,$cnum);
3922: $credits = &get_user_credits($defaultcredits,$cdom,$cnum);
3923: }
3924: my $result = &Apache::loncommon::commit_studentrole(\$logmsg,$udom,$uname,$url,$role,$now,0,$cdom,$cnum,$csec,$context,$credits);
1.220 raeburn 3925: if (($result =~ /^error/) || ($result eq 'not_in_class') || ($result eq 'unknown_course') || ($result eq 'refused')) {
1.223 raeburn 3926: if ($result eq 'refused' && $logmsg) {
3927: $output = $logmsg;
3928: } else {
1.369 bisitz 3929: $output = &mt('Error: [_1]',$result)."\n";
1.223 raeburn 3930: }
1.89 raeburn 3931: } else {
1.372 raeburn 3932: $output = &Apache::lonhtmlcommon::confirm_success(&mt('Assigning [_1] in [_2] starting [_3]',
3933: &Apache::lonnet::plaintext($role),
3934: &Apache::loncommon::show_role_extent($url,$context,'st'),
3935: &Apache::lonlocal::locallocaltime($now))).'<br />'.$logmsg.'<br />';
1.89 raeburn 3936: }
3937: }
3938: } else {
1.101 albertel 3939: my $result=&Apache::lonnet::assignrole($env{'form.ccdomain'},
1.239 raeburn 3940: $env{'form.ccuname'},$url,$role,0,$now,'','',
3941: $context);
1.367 golterma 3942: $output = &Apache::lonhtmlcommon::confirm_success(&mt('Re-enabling [_1] in [_2]',
1.372 raeburn 3943: &Apache::lonnet::plaintext($role),
3944: &Apache::loncommon::show_role_extent($url,$context,$role)),$result ne "ok").'<br />';
1.369 bisitz 3945: if ($result ne "ok") {
3946: $output .= &mt('Error: [_1]',$result).'<br />';
3947: }
3948: }
1.89 raeburn 3949: $r->print($output);
1.225 raeburn 3950: if (!grep(/^\Q$role\E$/,@rolechanges)) {
3951: push(@rolechanges,$role);
3952: }
1.113 raeburn 3953: }
1.116 raeburn 3954: # Re-enable custom role
1.139 albertel 3955: if ($key=~m{^form\.ren\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
1.116 raeburn 3956: my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
3957: my $result = &Apache::lonnet::assigncustomrole(
3958: $env{'form.ccdomain'}, $env{'form.ccuname'},
1.240 raeburn 3959: $url,$rdom,$rnam,$rolename,0,$now,undef,$context);
1.369 bisitz 3960: $r->print(&Apache::lonhtmlcommon::confirm_success(
3961: &mt('Re-enabling custom role [_1] by [_2] in [_3]',
1.372 raeburn 3962: $rolename,$rnam.':'.$rdom,&Apache::loncommon::show_role_extent($1,$context,'cr')),
1.369 bisitz 3963: $result ne "ok").'<br />');
3964: if ($result ne "ok") {
3965: $r->print(&mt('Error: [_1]',$result).'<br />');
3966: }
1.225 raeburn 3967: if (!grep(/^cr$/,@rolechanges)) {
3968: push(@rolechanges,'cr');
3969: }
1.116 raeburn 3970: }
1.135 raeburn 3971: } elsif ($key=~/^form\.act/) {
1.101 albertel 3972: my $udom = $env{'form.ccdomain'};
3973: my $uname = $env{'form.ccuname'};
1.141 albertel 3974: if ($key=~/^form\.act\_($match_domain)\_($match_courseid)\_cr_cr_($match_domain)_($match_username)_([^\_]+)$/) {
1.65 www 3975: # Activate a custom role
1.83 albertel 3976: my ($one,$two,$three,$four,$five)=($1,$2,$3,$4,$5);
3977: my $url='/'.$one.'/'.$two;
3978: my $full=$one.'_'.$two.'_cr_cr_'.$three.'_'.$four.'_'.$five;
1.65 www 3979:
1.101 albertel 3980: my $start = ( $env{'form.start_'.$full} ?
3981: $env{'form.start_'.$full} :
1.88 raeburn 3982: $now );
1.101 albertel 3983: my $end = ( $env{'form.end_'.$full} ?
3984: $env{'form.end_'.$full} :
1.88 raeburn 3985: 0 );
3986:
3987: # split multiple sections
3988: my %sections = ();
1.101 albertel 3989: my $num_sections = &build_roles($env{'form.sec_'.$full},\%sections,$5);
1.88 raeburn 3990: if ($num_sections == 0) {
1.240 raeburn 3991: $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$url,$three,$four,$five,$start,$end,$context));
1.88 raeburn 3992: } else {
1.114 albertel 3993: my %curr_groups =
1.117 raeburn 3994: &Apache::longroup::coursegroups($one,$two);
1.404 raeburn 3995: foreach my $sec (sort {$a cmp $b} keys(%sections)) {
1.113 raeburn 3996: if (($sec eq 'none') || ($sec eq 'all') ||
3997: exists($curr_groups{$sec})) {
3998: $disallowed{$sec} = $url;
3999: next;
4000: }
4001: my $securl = $url.'/'.$sec;
1.240 raeburn 4002: $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$securl,$three,$four,$five,$start,$end,$context));
1.88 raeburn 4003: }
4004: }
1.225 raeburn 4005: if (!grep(/^cr$/,@rolechanges)) {
4006: push(@rolechanges,'cr');
4007: }
1.142 raeburn 4008: } elsif ($key=~/^form\.act\_($match_domain)\_($match_name)\_([^\_]+)$/) {
1.27 matthew 4009: # Activate roles for sections with 3 id numbers
4010: # set start, end times, and the url for the class
1.83 albertel 4011: my ($one,$two,$three)=($1,$2,$3);
1.101 albertel 4012: my $start = ( $env{'form.start_'.$one.'_'.$two.'_'.$three} ?
4013: $env{'form.start_'.$one.'_'.$two.'_'.$three} :
1.27 matthew 4014: $now );
1.101 albertel 4015: my $end = ( $env{'form.end_'.$one.'_'.$two.'_'.$three} ?
4016: $env{'form.end_'.$one.'_'.$two.'_'.$three} :
1.27 matthew 4017: 0 );
1.83 albertel 4018: my $url='/'.$one.'/'.$two;
1.88 raeburn 4019: my $type = 'three';
4020: # split multiple sections
4021: my %sections = ();
1.101 albertel 4022: my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two.'_'.$three},\%sections,$three);
1.375 raeburn 4023: my $credits;
4024: if ($three eq 'st') {
4025: if ($showcredits) {
4026: my $defaultcredits =
4027: &Apache::lonuserutils::get_defaultcredits($one,$two);
4028: $credits = $env{'form.credits_'.$one.'_'.$two.'_'.$three};
4029: $credits =~ s/[^\d\.]//g;
4030: if ($credits eq $defaultcredits) {
4031: undef($credits);
4032: }
4033: }
4034: }
1.88 raeburn 4035: if ($num_sections == 0) {
1.375 raeburn 4036: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'',$context,$credits));
1.88 raeburn 4037: } else {
1.114 albertel 4038: my %curr_groups =
1.117 raeburn 4039: &Apache::longroup::coursegroups($one,$two);
1.88 raeburn 4040: my $emptysec = 0;
1.404 raeburn 4041: foreach my $sec (sort {$a cmp $b} keys(%sections)) {
1.88 raeburn 4042: $sec =~ s/\W//g;
1.113 raeburn 4043: if ($sec ne '') {
4044: if (($sec eq 'none') || ($sec eq 'all') ||
4045: exists($curr_groups{$sec})) {
4046: $disallowed{$sec} = $url;
4047: next;
4048: }
1.88 raeburn 4049: my $securl = $url.'/'.$sec;
1.375 raeburn 4050: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$three,$start,$end,$one,$two,$sec,$context,$credits));
1.88 raeburn 4051: } else {
4052: $emptysec = 1;
4053: }
4054: }
4055: if ($emptysec) {
1.375 raeburn 4056: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'',$context,$credits));
1.88 raeburn 4057: }
1.225 raeburn 4058: }
4059: if (!grep(/^\Q$three\E$/,@rolechanges)) {
4060: push(@rolechanges,$three);
4061: }
1.135 raeburn 4062: } elsif ($key=~/^form\.act\_([^\_]+)\_([^\_]+)$/) {
1.27 matthew 4063: # Activate roles for sections with two id numbers
4064: # set start, end times, and the url for the class
1.101 albertel 4065: my $start = ( $env{'form.start_'.$1.'_'.$2} ?
4066: $env{'form.start_'.$1.'_'.$2} :
1.27 matthew 4067: $now );
1.101 albertel 4068: my $end = ( $env{'form.end_'.$1.'_'.$2} ?
4069: $env{'form.end_'.$1.'_'.$2} :
1.27 matthew 4070: 0 );
1.225 raeburn 4071: my $one = $1;
4072: my $two = $2;
4073: my $url='/'.$one.'/';
1.88 raeburn 4074: # split multiple sections
4075: my %sections = ();
1.225 raeburn 4076: my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two},\%sections,$two);
1.88 raeburn 4077: if ($num_sections == 0) {
1.240 raeburn 4078: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,'',$context));
1.88 raeburn 4079: } else {
4080: my $emptysec = 0;
1.404 raeburn 4081: foreach my $sec (sort {$a cmp $b} keys(%sections)) {
1.88 raeburn 4082: if ($sec ne '') {
4083: my $securl = $url.'/'.$sec;
1.240 raeburn 4084: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$two,$start,$end,$one,undef,$sec,$context));
1.88 raeburn 4085: } else {
4086: $emptysec = 1;
4087: }
4088: }
4089: if ($emptysec) {
1.240 raeburn 4090: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,'',$context));
1.88 raeburn 4091: }
4092: }
1.225 raeburn 4093: if (!grep(/^\Q$two\E$/,@rolechanges)) {
4094: push(@rolechanges,$two);
4095: }
1.64 www 4096: } else {
1.190 raeburn 4097: $r->print('<p><span class="LC_error">'.&mt('ERROR').': '.&mt('Unknown command').' <tt>'.$key.'</tt></span></p><br />');
1.64 www 4098: }
1.113 raeburn 4099: foreach my $key (sort(keys(%disallowed))) {
1.274 bisitz 4100: $r->print('<p class="LC_warning">');
1.113 raeburn 4101: if (($key eq 'none') || ($key eq 'all')) {
1.274 bisitz 4102: $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 4103: } else {
1.274 bisitz 4104: $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 4105: }
1.274 bisitz 4106: $r->print('</p><p>'
4107: .&mt('Please [_1]go back[_2] and choose a different section name.'
4108: ,'<a href="javascript:history.go(-1)'
4109: ,'</a>')
4110: .'</p><br />'
4111: );
1.113 raeburn 4112: }
4113: }
1.101 albertel 4114: } # End of foreach (keys(%env))
1.75 www 4115: # Flush the course logs so reverse user roles immediately updated
1.349 raeburn 4116: $r->register_cleanup(\&Apache::lonnet::flushcourselogs);
1.225 raeburn 4117: if (@rolechanges == 0) {
1.372 raeburn 4118: $r->print('<p>'.&mt('No roles to modify').'</p>');
1.193 raeburn 4119: }
1.225 raeburn 4120: return @rolechanges;
1.220 raeburn 4121: }
4122:
1.375 raeburn 4123: sub get_user_credits {
4124: my ($uname,$udom,$defaultcredits,$cdom,$cnum) = @_;
4125: if ($cdom eq '' || $cnum eq '') {
4126: return unless ($env{'request.course.id'});
4127: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
4128: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
4129: }
4130: my $credits;
4131: my %currhash =
4132: &Apache::lonnet::get('classlist',[$uname.':'.$udom],$cdom,$cnum);
4133: if (keys(%currhash) > 0) {
4134: my @items = split(/:/,$currhash{$uname.':'.$udom});
4135: my $crdidx = &Apache::loncoursedata::CL_CREDITS() - 3;
4136: $credits = $items[$crdidx];
4137: $credits =~ s/[^\d\.]//g;
4138: }
4139: if ($credits eq $defaultcredits) {
4140: undef($credits);
4141: }
4142: return $credits;
4143: }
4144:
1.220 raeburn 4145: sub enroll_single_student {
1.375 raeburn 4146: my ($r,$uhome,$amode,$genpwd,$now,$newuser,$context,$crstype,
4147: $showcredits,$defaultcredits) = @_;
1.318 raeburn 4148: $r->print('<h3>');
4149: if ($crstype eq 'Community') {
4150: $r->print(&mt('Enrolling Member'));
4151: } else {
4152: $r->print(&mt('Enrolling Student'));
4153: }
4154: $r->print('</h3>');
1.220 raeburn 4155:
4156: # Remove non alphanumeric values from section
4157: $env{'form.sections'}=~s/\W//g;
4158:
1.375 raeburn 4159: my $credits;
4160: if (($showcredits) && ($env{'form.credits'} ne '')) {
4161: $credits = $env{'form.credits'};
4162: $credits =~ s/[^\d\.]//g;
4163: if ($credits ne '') {
4164: if ($credits eq $defaultcredits) {
4165: undef($credits);
4166: }
4167: }
4168: }
4169:
1.220 raeburn 4170: # Clean out any old student roles the user has in this class.
4171: &Apache::lonuserutils::modifystudent($env{'form.ccdomain'},
4172: $env{'form.ccuname'},$env{'request.course.id'},undef,$uhome);
4173: my ($startdate,$enddate) = &Apache::lonuserutils::get_dates_from_form();
4174: my $enroll_result =
4175: &Apache::lonnet::modify_student_enrollment($env{'form.ccdomain'},
4176: $env{'form.ccuname'},$env{'form.cid'},$env{'form.cfirstname'},
4177: $env{'form.cmiddlename'},$env{'form.clastname'},
4178: $env{'form.generation'},$env{'form.sections'},$enddate,
1.375 raeburn 4179: $startdate,'manual',undef,$env{'request.course.id'},'',$context,
4180: $credits);
1.220 raeburn 4181: if ($enroll_result =~ /^ok/) {
1.381 bisitz 4182: $r->print(&mt('[_1] enrolled','<b>'.$env{'form.ccuname'}.':'.$env{'form.ccdomain'}.'</b>'));
1.220 raeburn 4183: if ($env{'form.sections'} ne '') {
4184: $r->print(' '.&mt('in section [_1]',$env{'form.sections'}));
4185: }
4186: my ($showstart,$showend);
4187: if ($startdate <= $now) {
4188: $showstart = &mt('Access starts immediately');
4189: } else {
4190: $showstart = &mt('Access starts: ').&Apache::lonlocal::locallocaltime($startdate);
4191: }
4192: if ($enddate == 0) {
4193: $showend = &mt('ends: no ending date');
4194: } else {
4195: $showend = &mt('ends: ').&Apache::lonlocal::locallocaltime($enddate);
4196: }
4197: $r->print('.<br />'.$showstart.'; '.$showend);
4198: if ($startdate <= $now && !$newuser) {
1.386 bisitz 4199: $r->print('<p class="LC_info">');
1.318 raeburn 4200: if ($crstype eq 'Community') {
1.392 raeburn 4201: $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 4202: } else {
1.392 raeburn 4203: $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 4204: }
4205: $r->print('</p>');
1.220 raeburn 4206: }
4207: } else {
4208: $r->print(&mt('unable to enroll').": ".$enroll_result);
4209: }
4210: return;
1.188 raeburn 4211: }
4212:
1.204 raeburn 4213: sub get_defaultquota_text {
4214: my ($settingstatus) = @_;
4215: my $defquotatext;
4216: if ($settingstatus eq '') {
1.383 raeburn 4217: $defquotatext = &mt('default');
1.204 raeburn 4218: } else {
4219: my ($usertypes,$order) =
4220: &Apache::lonnet::retrieve_inst_usertypes($env{'form.ccdomain'});
4221: if ($usertypes->{$settingstatus} eq '') {
1.383 raeburn 4222: $defquotatext = &mt('default');
1.204 raeburn 4223: } else {
1.383 raeburn 4224: $defquotatext = &mt('default for [_1]',$usertypes->{$settingstatus});
1.204 raeburn 4225: }
4226: }
4227: return $defquotatext;
4228: }
4229:
1.188 raeburn 4230: sub update_result_form {
4231: my ($uhome) = @_;
4232: my $outcome =
1.367 golterma 4233: '<form name="userupdate" method="post" action="">'."\n";
1.160 raeburn 4234: foreach my $item ('srchby','srchin','srchtype','srchterm','srchdomain','ccuname','ccdomain') {
1.188 raeburn 4235: $outcome .= '<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n";
1.160 raeburn 4236: }
1.207 raeburn 4237: if ($env{'form.origname'} ne '') {
4238: $outcome .= '<input type="hidden" name="origname" value="'.$env{'form.origname'}.'" />'."\n";
4239: }
1.160 raeburn 4240: foreach my $item ('sortby','seluname','seludom') {
4241: if (exists($env{'form.'.$item})) {
1.188 raeburn 4242: $outcome .= '<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n";
1.160 raeburn 4243: }
4244: }
1.188 raeburn 4245: if ($uhome eq 'no_host') {
4246: $outcome .= '<input type="hidden" name="forcenewuser" value="1" />'."\n";
4247: }
4248: $outcome .= '<input type="hidden" name="phase" value="" />'."\n".
1.383 raeburn 4249: '<input type="hidden" name="currstate" value="" />'."\n".
4250: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n".
1.188 raeburn 4251: '</form>';
4252: return $outcome;
1.4 www 4253: }
4254:
1.149 raeburn 4255: sub quota_admin {
1.378 raeburn 4256: my ($setquota,$changeHash,$name) = @_;
1.149 raeburn 4257: my $quotachanged;
4258: if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
4259: # Current user has quota modification privileges
1.267 raeburn 4260: if (ref($changeHash) eq 'HASH') {
4261: $quotachanged = 1;
1.378 raeburn 4262: $changeHash->{$name.'quota'} = $setquota;
1.267 raeburn 4263: }
1.149 raeburn 4264: }
4265: return $quotachanged;
4266: }
4267:
1.267 raeburn 4268: sub tool_admin {
1.275 raeburn 4269: my ($tool,$settool,$changeHash,$context) = @_;
4270: my $canchange = 0;
1.279 raeburn 4271: if ($context eq 'requestcourses') {
1.275 raeburn 4272: if (&Apache::lonnet::allowed('ccc',$env{'form.ccdomain'})) {
4273: $canchange = 1;
4274: }
1.300 raeburn 4275: } elsif ($context eq 'reqcrsotherdom') {
4276: if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
4277: $canchange = 1;
4278: }
1.362 raeburn 4279: } elsif ($context eq 'requestauthor') {
4280: if (&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) {
4281: $canchange = 1;
4282: }
1.275 raeburn 4283: } elsif (&Apache::lonnet::allowed('mut',$env{'form.ccdomain'})) {
4284: # Current user has quota modification privileges
4285: $canchange = 1;
4286: }
1.267 raeburn 4287: my $toolchanged;
1.275 raeburn 4288: if ($canchange) {
1.267 raeburn 4289: if (ref($changeHash) eq 'HASH') {
4290: $toolchanged = 1;
1.362 raeburn 4291: if ($tool eq 'requestauthor') {
4292: $changeHash->{$context} = $settool;
4293: } else {
4294: $changeHash->{$context.'.'.$tool} = $settool;
4295: }
1.267 raeburn 4296: }
4297: }
4298: return $toolchanged;
4299: }
4300:
1.88 raeburn 4301: sub build_roles {
1.89 raeburn 4302: my ($sectionstr,$sections,$role) = @_;
1.88 raeburn 4303: my $num_sections = 0;
4304: if ($sectionstr=~ /,/) {
4305: my @secnums = split/,/,$sectionstr;
1.89 raeburn 4306: if ($role eq 'st') {
4307: $secnums[0] =~ s/\W//g;
4308: $$sections{$secnums[0]} = 1;
4309: $num_sections = 1;
4310: } else {
4311: foreach my $sec (@secnums) {
4312: $sec =~ ~s/\W//g;
1.150 banghart 4313: if (!($sec eq "")) {
1.89 raeburn 4314: if (exists($$sections{$sec})) {
4315: $$sections{$sec} ++;
4316: } else {
4317: $$sections{$sec} = 1;
4318: $num_sections ++;
4319: }
1.88 raeburn 4320: }
4321: }
4322: }
4323: } else {
4324: $sectionstr=~s/\W//g;
4325: unless ($sectionstr eq '') {
4326: $$sections{$sectionstr} = 1;
4327: $num_sections ++;
4328: }
4329: }
1.129 albertel 4330:
1.88 raeburn 4331: return $num_sections;
4332: }
4333:
1.58 www 4334: # ========================================================== Custom Role Editor
4335:
4336: sub custom_role_editor {
1.406.2.14 raeburn 4337: my ($r,$context,$brcrum,$prefix,$permission) = @_;
1.324 raeburn 4338: my $action = $env{'form.customroleaction'};
1.406.2.14 raeburn 4339: my ($rolename,$helpitem);
1.324 raeburn 4340: if ($action eq 'new') {
4341: $rolename=$env{'form.newrolename'};
4342: } else {
4343: $rolename=$env{'form.rolename'};
1.59 www 4344: }
4345:
1.324 raeburn 4346: my ($crstype,$context);
4347: if ($env{'request.course.id'}) {
4348: $crstype = &Apache::loncommon::course_type();
4349: $context = 'course';
1.406.2.14 raeburn 4350: $helpitem = 'Course_Editing_Custom_Roles';
1.324 raeburn 4351: } else {
4352: $context = 'domain';
1.406.2.5 raeburn 4353: $crstype = 'course';
1.406.2.14 raeburn 4354: $helpitem = 'Domain_Editing_Custom_Roles';
1.324 raeburn 4355: }
1.351 raeburn 4356:
4357: $rolename=~s/[^A-Za-z0-9]//gs;
4358: if (!$rolename || $env{'form.phase'} eq 'pickrole') {
1.406.2.14 raeburn 4359: &print_username_entry_form($r,$context,undef,undef,undef,$crstype,$brcrum,
4360: $permission);
1.351 raeburn 4361: return;
4362: }
4363:
1.406.2.5 raeburn 4364: my $formname = 'form1';
4365: my %privs=();
4366: my $body_top = '<h2>';
4367: # ------------------------------------------------------- Does this role exist?
1.59 www 4368: my ($rdummy,$roledef)=
4369: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
4370: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1.406.2.5 raeburn 4371: $body_top .= &mt('Existing Role').' "';
1.61 www 4372: # ------------------------------------------------- Get current role privileges
1.406.2.5 raeburn 4373: ($privs{'system'},$privs{'domain'},$privs{'course'})=split(/\_/,$roledef);
4374: if ($privs{'system'} =~ /bre\&S/) {
4375: if ($context eq 'domain') {
4376: $crstype = 'Course';
4377: } elsif ($crstype eq 'Community') {
4378: $privs{'system'} =~ s/bre\&S//;
4379: }
4380: } elsif ($context eq 'domain') {
4381: $crstype = 'Course';
1.324 raeburn 4382: }
1.59 www 4383: } else {
1.406.2.5 raeburn 4384: $body_top .= &mt('New Role').' "';
4385: $roledef='';
1.59 www 4386: }
1.153 banghart 4387: $body_top .= $rolename.'"</h2>';
1.406.2.5 raeburn 4388:
4389: # ------------------------------------------------------- What can be assigned?
4390: my %full=();
4391: my %levels=(
4392: course => {},
4393: domain => {},
4394: system => {},
4395: );
4396: my %levelscurrent=(
4397: course => {},
4398: domain => {},
4399: system => {},
4400: );
4401: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
1.160 raeburn 4402: my ($jsback,$elements) = &crumb_utilities();
1.406.2.5 raeburn 4403: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
4404: my $head_script =
4405: &Apache::lonuserutils::custom_roledefs_js($context,$crstype,$formname,
4406: \%full,\@templateroles,$jsback);
1.351 raeburn 4407: push (@{$brcrum},
1.406.2.5 raeburn 4408: {href => "javascript:backPage(document.$formname,'pickrole','')",
1.351 raeburn 4409: text => "Pick custom role",
4410: faq => 282,bug=>'Instructor Interface',},
1.406.2.5 raeburn 4411: {href => "javascript:backPage(document.$formname,'','')",
1.351 raeburn 4412: text => "Edit custom role",
4413: faq => 282,
4414: bug => 'Instructor Interface',
1.406.2.14 raeburn 4415: help => $helpitem}
1.351 raeburn 4416: );
4417: my $args = { bread_crumbs => $brcrum,
4418: bread_crumbs_component => 'User Management'};
4419: $r->print(&Apache::loncommon::start_page('Custom Role Editor',
4420: $head_script,$args).
4421: $body_top);
1.406.2.5 raeburn 4422: $r->print('<form name="'.$formname.'" method="post" action="">'."\n".
4423: &Apache::lonuserutils::custom_role_header($context,$crstype,
4424: \@templateroles,$prefix));
1.264 bisitz 4425:
1.61 www 4426: $r->print(<<ENDCCF);
4427: <input type="hidden" name="phase" value="set_custom_roles" />
4428: <input type="hidden" name="rolename" value="$rolename" />
4429: ENDCCF
1.406.2.5 raeburn 4430: $r->print(&Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
4431: \%levelscurrent,$prefix));
1.135 raeburn 4432: $r->print(&Apache::loncommon::end_data_table().
1.190 raeburn 4433: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'.
1.160 raeburn 4434: '<input type="hidden" name="startrolename" value="'.$env{'form.rolename'}.
1.406.2.5 raeburn 4435: '" />'."\n".'<input type="hidden" name="currstate" value="" />'."\n".
1.160 raeburn 4436: '<input type="reset" value="'.&mt("Reset").'" />'."\n".
1.351 raeburn 4437: '<input type="submit" value="'.&mt('Save').'" /></form>');
1.61 www 4438: }
1.406.2.5 raeburn 4439:
1.61 www 4440: # ---------------------------------------------------------- Call to definerole
4441: sub set_custom_role {
1.406.2.14 raeburn 4442: my ($r,$context,$brcrum,$prefix,$permission) = @_;
1.101 albertel 4443: my $rolename=$env{'form.rolename'};
1.63 www 4444: $rolename=~s/[^A-Za-z0-9]//gs;
1.150 banghart 4445: if (!$rolename) {
1.406.2.14 raeburn 4446: &custom_role_editor($r,$context,$brcrum,$prefix,$permission);
1.61 www 4447: return;
4448: }
1.160 raeburn 4449: my ($jsback,$elements) = &crumb_utilities();
1.301 bisitz 4450: my $jscript = '<script type="text/javascript">'
4451: .'// <![CDATA['."\n"
4452: .$jsback."\n"
4453: .'// ]]>'."\n"
4454: .'</script>'."\n";
1.406.2.14 raeburn 4455: my $helpitem = 'Course_Editing_Custom_Roles';
4456: if ($context eq 'domain') {
4457: $helpitem = 'Domain_Editing_Custom_Roles';
4458: }
1.352 raeburn 4459: push(@{$brcrum},
4460: {href => "javascript:backPage(document.customresult,'pickrole','')",
4461: text => "Pick custom role",
4462: faq => 282,
4463: bug => 'Instructor Interface',},
4464: {href => "javascript:backPage(document.customresult,'selected_custom_edit','')",
4465: text => "Edit custom role",
4466: faq => 282,
4467: bug => 'Instructor Interface',},
4468: {href => "javascript:backPage(document.customresult,'set_custom_roles','')",
4469: text => "Result",
4470: faq => 282,
4471: bug => 'Instructor Interface',
1.406.2.14 raeburn 4472: help => $helpitem,}
1.352 raeburn 4473: );
4474: my $args = { bread_crumbs => $brcrum,
1.406.2.5 raeburn 4475: bread_crumbs_component => 'User Management'};
1.351 raeburn 4476: $r->print(&Apache::loncommon::start_page('Save Custom Role',$jscript,$args));
1.160 raeburn 4477:
1.393 raeburn 4478: my $newrole;
1.61 www 4479: my ($rdummy,$roledef)=
1.110 albertel 4480: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
4481:
1.61 www 4482: # ------------------------------------------------------- Does this role exist?
1.188 raeburn 4483: $r->print('<h3>');
1.61 www 4484: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1.73 sakharuk 4485: $r->print(&mt('Existing Role').' "');
1.61 www 4486: } else {
1.73 sakharuk 4487: $r->print(&mt('New Role').' "');
1.61 www 4488: $roledef='';
1.393 raeburn 4489: $newrole = 1;
1.61 www 4490: }
1.188 raeburn 4491: $r->print($rolename.'"</h3>');
1.406.2.5 raeburn 4492: # ------------------------------------------------- Assign role and show result
1.61 www 4493:
1.387 bisitz 4494: my $errmsg;
1.406.2.5 raeburn 4495: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$prefix);
4496: # Assign role and return result
4497: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
4498: $newprivs{'c'});
1.387 bisitz 4499: if ($result ne 'ok') {
4500: $errmsg = ': '.$result;
4501: }
4502: my $message =
4503: &Apache::lonhtmlcommon::confirm_success(
4504: &mt('Defining Role').$errmsg, ($result eq 'ok' ? 0 : 1));
1.101 albertel 4505: if ($env{'request.course.id'}) {
4506: my $url='/'.$env{'request.course.id'};
1.63 www 4507: $url=~s/\_/\//g;
1.387 bisitz 4508: $result =
4509: &Apache::lonnet::assigncustomrole(
4510: $env{'user.domain'},$env{'user.name'},
4511: $url,
4512: $env{'user.domain'},$env{'user.name'},
4513: $rolename,undef,undef,undef,$context);
4514: if ($result ne 'ok') {
4515: $errmsg = ': '.$result;
4516: }
4517: $message .=
4518: '<br />'
4519: .&Apache::lonhtmlcommon::confirm_success(
4520: &mt('Assigning Role to Self').$errmsg, ($result eq 'ok' ? 0 : 1));
1.63 www 4521: }
1.380 bisitz 4522: $r->print(
1.387 bisitz 4523: &Apache::loncommon::confirmwrapper($message)
4524: .'<br />'
4525: .&Apache::lonhtmlcommon::actionbox([
4526: '<a href="javascript:backPage(document.customresult,'."'pickrole'".')">'
4527: .&mt('Create or edit another custom role')
4528: .'</a>'])
1.380 bisitz 4529: .'<form name="customresult" method="post" action="">'
1.387 bisitz 4530: .&Apache::lonhtmlcommon::echo_form_input([])
4531: .'</form>'
1.380 bisitz 4532: );
1.58 www 4533: }
4534:
1.2 www 4535: # ================================================================ Main Handler
4536: sub handler {
4537: my $r = shift;
4538: if ($r->header_only) {
1.68 www 4539: &Apache::loncommon::content_type($r,'text/html');
1.2 www 4540: $r->send_http_header;
4541: return OK;
4542: }
1.406.2.14 raeburn 4543: my ($context,$crstype,$cid,$cnum,$cdom,$allhelpitems);
4544:
1.190 raeburn 4545: if ($env{'request.course.id'}) {
4546: $context = 'course';
1.318 raeburn 4547: $crstype = &Apache::loncommon::course_type();
1.190 raeburn 4548: } elsif ($env{'request.role'} =~ /^au\./) {
1.206 raeburn 4549: $context = 'author';
1.190 raeburn 4550: } else {
4551: $context = 'domain';
4552: }
1.375 raeburn 4553:
1.406.2.14 raeburn 4554: my ($permission,$allowed) =
4555: &Apache::lonuserutils::get_permission($context,$crstype);
4556:
4557: if ($allowed) {
4558: my @allhelp;
4559: if ($context eq 'course') {
4560: $cid = $env{'request.course.id'};
4561: $cdom = $env{'course.'.$cid.'.domain'};
4562: $cnum = $env{'course.'.$cid.'.num'};
4563:
4564: if ($permission->{'cusr'}) {
4565: push(@allhelp,'Course_Create_Class_List');
4566: }
4567: if ($permission->{'view'} || $permission->{'cusr'}) {
4568: push(@allhelp,('Course_Change_Privileges','Course_View_Class_List'));
4569: }
4570: if ($permission->{'custom'}) {
4571: push(@allhelp,'Course_Editing_Custom_Roles');
4572: }
4573: if ($permission->{'cusr'}) {
4574: push(@allhelp,('Course_Add_Student','Course_Drop_Student'));
4575: }
4576: unless ($permission->{'cusr_section'}) {
4577: if (&Apache::lonnet::auto_run($cnum,$cdom) && (($permission->{'cusr'}) || ($permission->{'view'}))) {
4578: push(@allhelp,'Course_Automated_Enrollment');
4579: }
4580: if ($permission->{'selfenrolladmin'}) {
4581: push(@allhelp,'Course_Approve_Selfenroll');
4582: }
4583: }
4584: if ($permission->{'grp_manage'}) {
4585: push(@allhelp,'Course_Manage_Group');
4586: }
4587: if ($permission->{'view'} || $permission->{'cusr'}) {
4588: push(@allhelp,'Course_User_Logs');
4589: }
4590: } elsif ($context eq 'author') {
4591: push(@allhelp,('Author_Change_Privileges','Author_Create_Coauthor_List',
4592: 'Author_View_Coauthor_List','Author_User_Logs'));
4593: } else {
4594: if ($permission->{'cusr'}) {
4595: push(@allhelp,'Domain_Change_Privileges');
4596: if ($permission->{'activity'}) {
4597: push(@allhelp,'Domain_User_Access_Logs');
4598: }
4599: push(@allhelp,('Domain_Create_Users','Domain_View_Users_List'));
4600: if ($permission->{'custom'}) {
4601: push(@allhelp,'Domain_Editing_Custom_Roles');
4602: }
4603: push(@allhelp,('Domain_Role_Approvals','Domain_Username_Approvals','Domain_Change_Logs'));
4604: } elsif ($permission->{'view'}) {
4605: push(@allhelp,'Domain_View_Privileges');
4606: if ($permission->{'activity'}) {
4607: push(@allhelp,'Domain_User_Access_Logs');
4608: }
4609: push(@allhelp,('Domain_View_Users_List','Domain_Change_Logs'));
4610: }
4611: }
4612: if (@allhelp) {
4613: $allhelpitems = join(',',@allhelp);
4614: }
4615: }
4616:
1.190 raeburn 4617: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.233 raeburn 4618: ['action','state','callingform','roletype','showrole','bulkaction','popup','phase',
1.391 raeburn 4619: 'username','domain','srchterm','srchdomain','srchin','srchby','srchtype','queue']);
1.190 raeburn 4620: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.351 raeburn 4621: my $args;
4622: my $brcrum = [];
4623: my $bread_crumbs_component = 'User Management';
1.391 raeburn 4624: if (($env{'form.action'} ne 'dateselect') && ($env{'form.action'} ne 'displayuserreq')) {
1.351 raeburn 4625: $brcrum = [{href=>"/adm/createuser",
4626: text=>"User Management",
1.406.2.14 raeburn 4627: help=>$allhelpitems}
1.351 raeburn 4628: ];
1.202 raeburn 4629: }
1.190 raeburn 4630: if (!$allowed) {
1.358 raeburn 4631: if ($context eq 'course') {
4632: $r->internal_redirect('/adm/viewclasslist');
4633: return OK;
4634: }
1.190 raeburn 4635: $env{'user.error.msg'}=
4636: "/adm/createuser:cst:0:0:Cannot create/modify user data ".
4637: "or view user status.";
4638: return HTTP_NOT_ACCEPTABLE;
4639: }
4640:
4641: &Apache::loncommon::content_type($r,'text/html');
4642: $r->send_http_header;
4643:
1.375 raeburn 4644: my $showcredits;
4645: if ((($context eq 'course') && ($crstype eq 'Course')) ||
4646: ($context eq 'domain')) {
4647: my %domdefaults =
4648: &Apache::lonnet::get_domain_defaults($env{'request.role.domain'});
4649: if ($domdefaults{'officialcredits'} || $domdefaults{'unofficialcredits'}) {
4650: $showcredits = 1;
4651: }
4652: }
4653:
1.190 raeburn 4654: # Main switch on form.action and form.state, as appropriate
4655: if (! exists($env{'form.action'})) {
1.351 raeburn 4656: $args = {bread_crumbs => $brcrum,
4657: bread_crumbs_component => $bread_crumbs_component};
4658: $r->print(&header(undef,$args));
1.318 raeburn 4659: $r->print(&print_main_menu($permission,$context,$crstype));
1.190 raeburn 4660: } elsif ($env{'form.action'} eq 'upload' && $permission->{'cusr'}) {
1.406.2.14 raeburn 4661: my $helpitem = 'Course_Create_Class_List';
4662: if ($context eq 'author') {
4663: $helpitem = 'Author_Create_Coauthor_List';
4664: } elsif ($context eq 'domain') {
4665: $helpitem = 'Domain_Create_Users';
4666: }
1.351 raeburn 4667: push(@{$brcrum},
4668: { href => '/adm/createuser?action=upload&state=',
4669: text => 'Upload Users List',
1.406.2.14 raeburn 4670: help => $helpitem,
1.351 raeburn 4671: });
4672: $bread_crumbs_component = 'Upload Users List';
4673: $args = {bread_crumbs => $brcrum,
4674: bread_crumbs_component => $bread_crumbs_component};
4675: $r->print(&header(undef,$args));
1.190 raeburn 4676: $r->print('<form name="studentform" method="post" '.
4677: 'enctype="multipart/form-data" '.
4678: ' action="/adm/createuser">'."\n");
4679: if (! exists($env{'form.state'})) {
4680: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
4681: } elsif ($env{'form.state'} eq 'got_file') {
1.406.2.15! raeburn 4682: my $result =
! 4683: &Apache::lonuserutils::print_upload_manager_form($r,$context,
! 4684: $permission,
! 4685: $crstype,$showcredits);
! 4686: if ($result eq 'missingdata') {
! 4687: delete($env{'form.state'});
! 4688: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
! 4689: }
1.190 raeburn 4690: } elsif ($env{'form.state'} eq 'enrolling') {
4691: if ($env{'form.datatoken'}) {
1.406.2.15! raeburn 4692: my $result = &Apache::lonuserutils::upfile_drop_add($r,$context,
! 4693: $permission,
! 4694: $showcredits);
! 4695: if ($result eq 'missingdata') {
! 4696: delete($env{'form.state'});
! 4697: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
! 4698: } elsif ($result eq 'invalidhome') {
! 4699: $env{'form.state'} = 'got_file';
! 4700: delete($env{'form.lcserver'});
! 4701: my $result =
! 4702: &Apache::lonuserutils::print_upload_manager_form($r,$context,$permission,
! 4703: $crstype,$showcredits);
! 4704: if ($result eq 'missingdata') {
! 4705: delete($env{'form.state'});
! 4706: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
! 4707: }
! 4708: }
! 4709: } else {
! 4710: delete($env{'form.state'});
! 4711: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
1.190 raeburn 4712: }
4713: } else {
4714: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
4715: }
1.406.2.15! raeburn 4716: $r->print('</form>');
1.406.2.5 raeburn 4717: } elsif (((($env{'form.action'} eq 'singleuser') || ($env{'form.action'}
4718: eq 'singlestudent')) && ($permission->{'cusr'})) ||
1.406.2.6 raeburn 4719: (($env{'form.action'} eq 'singleuser') && ($permission->{'view'})) ||
1.406.2.5 raeburn 4720: (($env{'form.action'} eq 'accesslogs') && ($permission->{'activity'}))) {
1.190 raeburn 4721: my $phase = $env{'form.phase'};
4722: my @search = ('srchterm','srchby','srchin','srchtype','srchdomain');
1.192 albertel 4723: &Apache::loncreateuser::restore_prev_selections();
4724: my $srch;
4725: foreach my $item (@search) {
4726: $srch->{$item} = $env{'form.'.$item};
4727: }
1.207 raeburn 4728: if (($phase eq 'get_user_info') || ($phase eq 'userpicked') ||
1.406.2.5 raeburn 4729: ($phase eq 'createnewuser') || ($phase eq 'activity')) {
1.207 raeburn 4730: if ($env{'form.phase'} eq 'createnewuser') {
4731: my $response;
4732: if ($env{'form.srchterm'} !~ /^$match_username$/) {
1.366 bisitz 4733: my $response =
4734: '<span class="LC_warning">'
4735: .&mt('You must specify a valid username. Only the following are allowed:'
4736: .' letters numbers - . @')
4737: .'</span>';
1.221 raeburn 4738: $env{'form.phase'} = '';
1.375 raeburn 4739: &print_username_entry_form($r,$context,$response,$srch,undef,
1.406.2.14 raeburn 4740: $crstype,$brcrum,$permission);
1.207 raeburn 4741: } else {
4742: my $ccuname =&LONCAPA::clean_username($srch->{'srchterm'});
4743: my $ccdomain=&LONCAPA::clean_domain($srch->{'srchdomain'});
4744: &print_user_modification_page($r,$ccuname,$ccdomain,
1.221 raeburn 4745: $srch,$response,$context,
1.375 raeburn 4746: $permission,$crstype,$brcrum,
4747: $showcredits);
1.207 raeburn 4748: }
4749: } elsif ($env{'form.phase'} eq 'get_user_info') {
1.190 raeburn 4750: my ($currstate,$response,$forcenewuser,$results) =
1.221 raeburn 4751: &user_search_result($context,$srch);
1.190 raeburn 4752: if ($env{'form.currstate'} eq 'modify') {
4753: $currstate = $env{'form.currstate'};
4754: }
4755: if ($currstate eq 'select') {
4756: &print_user_selection_page($r,$response,$srch,$results,
1.351 raeburn 4757: \@search,$context,undef,$crstype,
4758: $brcrum);
1.406.2.5 raeburn 4759: } elsif (($currstate eq 'modify') || ($env{'form.action'} eq 'accesslogs')) {
4760: my ($ccuname,$ccdomain,$uhome);
1.190 raeburn 4761: if (($srch->{'srchby'} eq 'uname') &&
4762: ($srch->{'srchtype'} eq 'exact')) {
4763: $ccuname = $srch->{'srchterm'};
4764: $ccdomain= $srch->{'srchdomain'};
4765: } else {
4766: my @matchedunames = keys(%{$results});
4767: ($ccuname,$ccdomain) = split(/:/,$matchedunames[0]);
4768: }
4769: $ccuname =&LONCAPA::clean_username($ccuname);
4770: $ccdomain=&LONCAPA::clean_domain($ccdomain);
1.406.2.5 raeburn 4771: if ($env{'form.action'} eq 'accesslogs') {
4772: my $uhome;
4773: if (($ccuname ne '') && ($ccdomain ne '')) {
4774: $uhome = &Apache::lonnet::homeserver($ccuname,$ccdomain);
4775: }
4776: if (($uhome eq '') || ($uhome eq 'no_host')) {
4777: $env{'form.phase'} = '';
4778: undef($forcenewuser);
4779: #if ($response) {
4780: # unless ($response =~ m{\Q<br /><br />\E$}) {
4781: # $response .= '<br /><br />';
4782: # }
4783: #}
4784: &print_username_entry_form($r,$context,$response,$srch,
1.406.2.14 raeburn 4785: $forcenewuser,$crstype,$brcrum,
4786: $permission);
1.406.2.5 raeburn 4787: } else {
4788: &print_useraccesslogs_display($r,$ccuname,$ccdomain,$permission,$brcrum);
4789: }
4790: } else {
4791: if ($env{'form.forcenewuser'}) {
4792: $response = '';
4793: }
4794: &print_user_modification_page($r,$ccuname,$ccdomain,
4795: $srch,$response,$context,
4796: $permission,$crstype,$brcrum);
1.190 raeburn 4797: }
4798: } elsif ($currstate eq 'query') {
1.351 raeburn 4799: &print_user_query_page($r,'createuser',$brcrum);
1.190 raeburn 4800: } else {
1.229 raeburn 4801: $env{'form.phase'} = '';
1.207 raeburn 4802: &print_username_entry_form($r,$context,$response,$srch,
1.406.2.14 raeburn 4803: $forcenewuser,$crstype,$brcrum,
4804: $permission);
1.190 raeburn 4805: }
4806: } elsif ($env{'form.phase'} eq 'userpicked') {
4807: my $ccuname = &LONCAPA::clean_username($env{'form.seluname'});
4808: my $ccdomain = &LONCAPA::clean_domain($env{'form.seludom'});
1.406.2.5 raeburn 4809: if ($env{'form.action'} eq 'accesslogs') {
4810: &print_useraccesslogs_display($r,$ccuname,$ccdomain,$permission,$brcrum);
4811: } else {
4812: &print_user_modification_page($r,$ccuname,$ccdomain,$srch,'',
4813: $context,$permission,$crstype,
4814: $brcrum);
4815: }
4816: } elsif ($env{'form.action'} eq 'accesslogs') {
4817: my $ccuname = &LONCAPA::clean_username($env{'form.accessuname'});
4818: my $ccdomain = &LONCAPA::clean_domain($env{'form.accessudom'});
4819: &print_useraccesslogs_display($r,$ccuname,$ccdomain,$permission,$brcrum);
1.190 raeburn 4820: }
4821: } elsif ($env{'form.phase'} eq 'update_user_data') {
1.375 raeburn 4822: &update_user_data($r,$context,$crstype,$brcrum,$showcredits);
1.190 raeburn 4823: } else {
1.351 raeburn 4824: &print_username_entry_form($r,$context,undef,$srch,undef,$crstype,
1.406.2.14 raeburn 4825: $brcrum,$permission);
1.190 raeburn 4826: }
4827: } elsif ($env{'form.action'} eq 'custom' && $permission->{'custom'}) {
1.406.2.5 raeburn 4828: my $prefix;
1.190 raeburn 4829: if ($env{'form.phase'} eq 'set_custom_roles') {
1.406.2.14 raeburn 4830: &set_custom_role($r,$context,$brcrum,$prefix,$permission);
1.190 raeburn 4831: } else {
1.406.2.14 raeburn 4832: &custom_role_editor($r,$context,$brcrum,$prefix,$permission);
1.190 raeburn 4833: }
1.362 raeburn 4834: } elsif (($env{'form.action'} eq 'processauthorreq') &&
4835: ($permission->{'cusr'}) &&
4836: (&Apache::lonnet::allowed('cau',$env{'request.role.domain'}))) {
4837: push(@{$brcrum},
4838: {href => '/adm/createuser?action=processauthorreq',
1.385 bisitz 4839: text => 'Authoring Space requests',
1.362 raeburn 4840: help => 'Domain_Role_Approvals'});
4841: $bread_crumbs_component = 'Authoring requests';
4842: if ($env{'form.state'} eq 'done') {
4843: push(@{$brcrum},
4844: {href => '/adm/createuser?action=authorreqqueue',
4845: text => 'Result',
4846: help => 'Domain_Role_Approvals'});
4847: $bread_crumbs_component = 'Authoring request result';
4848: }
4849: $args = { bread_crumbs => $brcrum,
4850: bread_crumbs_component => $bread_crumbs_component};
1.391 raeburn 4851: my $js = &usernamerequest_javascript();
4852: $r->print(&header(&add_script($js),$args));
1.362 raeburn 4853: if (!exists($env{'form.state'})) {
4854: $r->print(&Apache::loncoursequeueadmin::display_queued_requests('requestauthor',
4855: $env{'request.role.domain'}));
4856: } elsif ($env{'form.state'} eq 'done') {
4857: $r->print('<h3>'.&mt('Authoring request processing').'</h3>'."\n");
4858: $r->print(&Apache::loncoursequeueadmin::update_request_queue('requestauthor',
4859: $env{'request.role.domain'}));
4860: }
1.391 raeburn 4861: } elsif (($env{'form.action'} eq 'processusernamereq') &&
4862: ($permission->{'cusr'}) &&
4863: (&Apache::lonnet::allowed('cau',$env{'request.role.domain'}))) {
4864: push(@{$brcrum},
4865: {href => '/adm/createuser?action=processusernamereq',
4866: text => 'LON-CAPA account requests',
4867: help => 'Domain_Username_Approvals'});
4868: $bread_crumbs_component = 'Account requests';
4869: if ($env{'form.state'} eq 'done') {
4870: push(@{$brcrum},
4871: {href => '/adm/createuser?action=usernamereqqueue',
4872: text => 'Result',
4873: help => 'Domain_Username_Approvals'});
4874: $bread_crumbs_component = 'LON-CAPA account request result';
4875: }
4876: $args = { bread_crumbs => $brcrum,
4877: bread_crumbs_component => $bread_crumbs_component};
4878: my $js = &usernamerequest_javascript();
4879: $r->print(&header(&add_script($js),$args));
4880: if (!exists($env{'form.state'})) {
4881: $r->print(&Apache::loncoursequeueadmin::display_queued_requests('requestusername',
4882: $env{'request.role.domain'}));
4883: } elsif ($env{'form.state'} eq 'done') {
4884: $r->print('<h3>'.&mt('LON-CAPA account request processing').'</h3>'."\n");
4885: $r->print(&Apache::loncoursequeueadmin::update_request_queue('requestusername',
4886: $env{'request.role.domain'}));
4887: }
4888: } elsif (($env{'form.action'} eq 'displayuserreq') &&
4889: ($permission->{'cusr'})) {
4890: my $dom = $env{'form.domain'};
4891: my $uname = $env{'form.username'};
4892: my $warning;
4893: if (($dom =~ /^$match_domain$/) && (&Apache::lonnet::domain($dom) ne '')) {
4894: if (($dom eq $env{'request.role.domain'}) && (&Apache::lonnet::allowed('ccc',$dom))) {
4895: if (($uname =~ /^$match_username$/) && ($env{'form.queue'} eq 'approval')) {
4896: my $uhome = &Apache::lonnet::homeserver($uname,$dom);
4897: if ($uhome eq 'no_host') {
4898: my $queue = $env{'form.queue'};
4899: my $reqkey = &escape($uname).'_'.$queue;
4900: my $namespace = 'usernamequeue';
4901: my $domconfig = &Apache::lonnet::get_domainconfiguser($dom);
4902: my %queued =
4903: &Apache::lonnet::get($namespace,[$reqkey],$dom,$domconfig);
4904: unless ($queued{$reqkey}) {
4905: $warning = &mt('No information was found for this LON-CAPA account request.');
4906: }
4907: } else {
4908: $warning = &mt('A LON-CAPA account already exists for the requested username and domain.');
4909: }
4910: } else {
4911: $warning = &mt('LON-CAPA account request status check is for an invalid username.');
4912: }
4913: } else {
4914: $warning = &mt('You do not have rights to view LON-CAPA account requests in the domain specified.');
4915: }
4916: } else {
4917: $warning = &mt('LON-CAPA account request status check is for an invalid domain.');
4918: }
4919: my $args = { only_body => 1 };
4920: $r->print(&header(undef,$args).
4921: '<h3>'.&mt('LON-CAPA Account Request Details').'</h3>');
4922: if ($warning ne '') {
4923: $r->print('<div class="LC_warning">'.$warning.'</div>');
4924: } else {
4925: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
4926: my $domconfiguser = &Apache::lonnet::get_domainconfiguser($dom);
4927: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
4928: if (ref($domconfig{'usercreation'}) eq 'HASH') {
4929: if (ref($domconfig{'usercreation'}{'cancreate'}) eq 'HASH') {
4930: if (ref($domconfig{'usercreation'}{'cancreate'}{'emailusername'}) eq 'HASH') {
4931: my %info =
4932: &Apache::lonnet::get('nohist_requestedusernames',[$uname],$dom,$domconfiguser);
4933: if (ref($info{$uname}) eq 'HASH') {
1.396 raeburn 4934: my $usertype = $info{$uname}{'inststatus'};
4935: unless ($usertype) {
4936: $usertype = 'default';
4937: }
4938: if (ref($domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}) eq 'HASH') {
4939: if ((ref($infofields) eq 'ARRAY') && (ref($infotitles) eq 'HASH')) {
4940: $r->print('<div>'.&Apache::lonhtmlcommon::start_pick_box());
4941: my ($num,$count,$showstatus);
4942: $count = scalar(keys(%{$domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}}));
4943: unless ($usertype eq 'default') {
4944: my ($othertitle,$usertypes,$types) =
4945: &Apache::loncommon::sorted_inst_types($dom);
4946: if (ref($usertypes) eq 'HASH') {
4947: if ($usertypes->{$usertype}) {
4948: $showstatus = $usertypes->{$usertype};
4949: $count ++;
4950: }
4951: }
4952: }
4953: foreach my $field (@{$infofields}) {
4954: next unless ($domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}{$field});
4955: next unless ($infotitles->{$field});
4956: $r->print(&Apache::lonhtmlcommon::row_title($infotitles->{$field}).
4957: $info{$uname}{$field});
4958: $num ++;
4959: if ($count == $num) {
4960: $r->print(&Apache::lonhtmlcommon::row_closure(1));
4961: } else {
4962: $r->print(&Apache::lonhtmlcommon::row_closure());
4963: }
4964: }
4965: if ($showstatus) {
4966: $r->print(&Apache::lonhtmlcommon::row_title(&mt('Status type (self-reported)')).
4967: $showstatus.
4968: &Apache::lonhtmlcommon::row_closure(1));
1.391 raeburn 4969: }
1.396 raeburn 4970: $r->print(&Apache::lonhtmlcommon::end_pick_box().'</div>');
1.391 raeburn 4971: }
4972: }
4973: }
4974: }
4975: }
4976: }
4977: $r->print(&close_popup_form());
4978: }
1.207 raeburn 4979: } elsif (($env{'form.action'} eq 'listusers') &&
4980: ($permission->{'view'} || $permission->{'cusr'})) {
1.406.2.14 raeburn 4981: my $helpitem = 'Course_View_Class_List';
4982: if ($context eq 'author') {
4983: $helpitem = 'Author_View_Coauthor_List';
4984: } elsif ($context eq 'domain') {
4985: $helpitem = 'Domain_View_Users_List';
4986: }
1.202 raeburn 4987: if ($env{'form.phase'} eq 'bulkchange') {
1.351 raeburn 4988: push(@{$brcrum},
4989: {href => '/adm/createuser?action=listusers',
4990: text => "List Users"},
4991: {href => "/adm/createuser",
4992: text => "Result",
1.406.2.14 raeburn 4993: help => $helpitem});
1.351 raeburn 4994: $bread_crumbs_component = 'Update Users';
4995: $args = {bread_crumbs => $brcrum,
4996: bread_crumbs_component => $bread_crumbs_component};
4997: $r->print(&header(undef,$args));
1.202 raeburn 4998: my $setting = $env{'form.roletype'};
4999: my $choice = $env{'form.bulkaction'};
5000: if ($permission->{'cusr'}) {
1.336 raeburn 5001: &Apache::lonuserutils::update_user_list($r,$context,$setting,$choice,$crstype);
1.221 raeburn 5002: } else {
5003: $r->print(&mt('You are not authorized to make bulk changes to user roles'));
1.223 raeburn 5004: $r->print('<p><a href="/adm/createuser?action=listusers">'.&mt('Display User Lists').'</a>');
1.202 raeburn 5005: }
5006: } else {
1.351 raeburn 5007: push(@{$brcrum},
5008: {href => '/adm/createuser?action=listusers',
5009: text => "List Users",
1.406.2.14 raeburn 5010: help => $helpitem});
1.351 raeburn 5011: $bread_crumbs_component = 'List Users';
5012: $args = {bread_crumbs => $brcrum,
5013: bread_crumbs_component => $bread_crumbs_component};
1.202 raeburn 5014: my ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles);
5015: my $formname = 'studentform';
1.364 raeburn 5016: my $hidecall = "hide_searching();";
1.321 raeburn 5017: if (($context eq 'domain') && (($env{'form.roletype'} eq 'course') ||
5018: ($env{'form.roletype'} eq 'community'))) {
5019: if ($env{'form.roletype'} eq 'course') {
5020: ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles) =
5021: &Apache::lonuserutils::courses_selector($env{'request.role.domain'},
5022: $formname);
5023: } elsif ($env{'form.roletype'} eq 'community') {
5024: $cb_jscript =
5025: &Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
5026: my %elements = (
5027: coursepick => 'radio',
5028: coursetotal => 'text',
5029: courselist => 'text',
5030: );
5031: $jscript = &Apache::lonhtmlcommon::set_form_elements(\%elements);
5032: }
1.364 raeburn 5033: $jscript .= &verify_user_display($context)."\n".
5034: &Apache::loncommon::check_uncheck_jscript();
1.202 raeburn 5035: my $js = &add_script($jscript).$cb_jscript;
5036: my $loadcode =
5037: &Apache::lonuserutils::course_selector_loadcode($formname);
5038: if ($loadcode ne '') {
1.364 raeburn 5039: $args->{add_entries} = {onload => "$loadcode;$hidecall"};
5040: } else {
5041: $args->{add_entries} = {onload => $hidecall};
1.202 raeburn 5042: }
1.351 raeburn 5043: $r->print(&header($js,$args));
1.191 raeburn 5044: } else {
1.364 raeburn 5045: $args->{add_entries} = {onload => $hidecall};
5046: $jscript = &verify_user_display($context).
5047: &Apache::loncommon::check_uncheck_jscript();
5048: $r->print(&header(&add_script($jscript),$args));
1.191 raeburn 5049: }
1.202 raeburn 5050: &Apache::lonuserutils::print_userlist($r,undef,$permission,$context,
1.375 raeburn 5051: $formname,$totcodes,$codetitles,$idlist,$idlist_titles,
5052: $showcredits);
1.191 raeburn 5053: }
1.213 raeburn 5054: } elsif ($env{'form.action'} eq 'drop' && $permission->{'cusr'}) {
1.318 raeburn 5055: my $brtext;
5056: if ($crstype eq 'Community') {
5057: $brtext = 'Drop Members';
5058: } else {
5059: $brtext = 'Drop Students';
5060: }
1.351 raeburn 5061: push(@{$brcrum},
5062: {href => '/adm/createuser?action=drop',
5063: text => $brtext,
5064: help => 'Course_Drop_Student'});
5065: if ($env{'form.state'} eq 'done') {
5066: push(@{$brcrum},
5067: {href=>'/adm/createuser?action=drop',
5068: text=>"Result"});
5069: }
5070: $bread_crumbs_component = $brtext;
5071: $args = {bread_crumbs => $brcrum,
5072: bread_crumbs_component => $bread_crumbs_component};
5073: $r->print(&header(undef,$args));
1.213 raeburn 5074: if (!exists($env{'form.state'})) {
1.318 raeburn 5075: &Apache::lonuserutils::print_drop_menu($r,$context,$permission,$crstype);
1.213 raeburn 5076: } elsif ($env{'form.state'} eq 'done') {
5077: &Apache::lonuserutils::update_user_list($r,$context,undef,
5078: $env{'form.action'});
5079: }
1.202 raeburn 5080: } elsif ($env{'form.action'} eq 'dateselect') {
5081: if ($permission->{'cusr'}) {
1.351 raeburn 5082: $r->print(&header(undef,{'no_nav_bar' => 1}).
1.375 raeburn 5083: &Apache::lonuserutils::date_section_selector($context,$permission,
5084: $crstype,$showcredits));
1.202 raeburn 5085: } else {
1.351 raeburn 5086: $r->print(&header(undef,{'no_nav_bar' => 1}).
5087: '<span class="LC_error">'.&mt('You do not have permission to modify dates or sections for users').'</span>');
1.202 raeburn 5088: }
1.237 raeburn 5089: } elsif ($env{'form.action'} eq 'selfenroll') {
1.398 raeburn 5090: if ($permission->{selfenrolladmin}) {
5091: my %currsettings = (
5092: selfenroll_types => $env{'course.'.$cid.'.internal.selfenroll_types'},
5093: selfenroll_registered => $env{'course.'.$cid.'.internal.selfenroll_registered'},
5094: selfenroll_section => $env{'course.'.$cid.'.internal.selfenroll_section'},
5095: selfenroll_notifylist => $env{'course.'.$cid.'.internal.selfenroll_notifylist'},
5096: selfenroll_approval => $env{'course.'.$cid.'.internal.selfenroll_approval'},
5097: selfenroll_limit => $env{'course.'.$cid.'.internal.selfenroll_limit'},
5098: selfenroll_cap => $env{'course.'.$cid.'.internal.selfenroll_cap'},
5099: selfenroll_start_date => $env{'course.'.$cid.'.internal.selfenroll_start_date'},
5100: selfenroll_end_date => $env{'course.'.$cid.'.internal.selfenroll_end_date'},
5101: selfenroll_start_access => $env{'course.'.$cid.'.internal.selfenroll_start_access'},
5102: selfenroll_end_access => $env{'course.'.$cid.'.internal.selfenroll_end_access'},
5103: default_enrollment_start_date => $env{'course.'.$cid.'.default_enrollment_start_date'},
5104: default_enrollment_end_date => $env{'course.'.$cid.'.default_enrollment_end_date'},
1.400 raeburn 5105: uniquecode => $env{'course.'.$cid.'.internal.uniquecode'},
1.398 raeburn 5106: );
5107: push(@{$brcrum},
5108: {href => '/adm/createuser?action=selfenroll',
5109: text => "Configure Self-enrollment",
5110: help => 'Course_Self_Enrollment'});
5111: if (!exists($env{'form.state'})) {
5112: $args = { bread_crumbs => $brcrum,
5113: bread_crumbs_component => 'Configure Self-enrollment'};
5114: $r->print(&header(undef,$args));
5115: $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n");
5116: &print_selfenroll_menu($r,'course',$cid,$cdom,$cnum,\%currsettings);
5117: } elsif ($env{'form.state'} eq 'done') {
5118: push (@{$brcrum},
5119: {href=>'/adm/createuser?action=selfenroll',
5120: text=>"Result"});
5121: $args = { bread_crumbs => $brcrum,
5122: bread_crumbs_component => 'Self-enrollment result'};
5123: $r->print(&header(undef,$args));
5124: $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n");
1.400 raeburn 5125: &update_selfenroll_config($r,$cid,$cdom,$cnum,$context,$crstype,\%currsettings);
1.398 raeburn 5126: }
5127: } else {
5128: $r->print(&header(undef,{'no_nav_bar' => 1}).
5129: '<span class="LC_error">'.&mt('You do not have permission to configure self-enrollment').'</span>');
1.237 raeburn 5130: }
1.277 raeburn 5131: } elsif ($env{'form.action'} eq 'selfenrollqueue') {
1.406.2.6 raeburn 5132: if ($permission->{selfenrolladmin}) {
1.351 raeburn 5133: push(@{$brcrum},
5134: {href => '/adm/createuser?action=selfenrollqueue',
1.406.2.6 raeburn 5135: text => 'Enrollment requests',
1.406.2.14 raeburn 5136: help => 'Course_Approve_Selfenroll'});
1.406.2.6 raeburn 5137: $bread_crumbs_component = 'Enrollment requests';
5138: if ($env{'form.state'} eq 'done') {
5139: push(@{$brcrum},
5140: {href => '/adm/createuser?action=selfenrollqueue',
5141: text => 'Result',
1.406.2.14 raeburn 5142: help => 'Course_Approve_Selfenroll'});
1.406.2.6 raeburn 5143: $bread_crumbs_component = 'Enrollment result';
5144: }
5145: $args = { bread_crumbs => $brcrum,
5146: bread_crumbs_component => $bread_crumbs_component};
5147: $r->print(&header(undef,$args));
5148: my $coursedesc = $env{'course.'.$cid.'.description'};
5149: if (!exists($env{'form.state'})) {
5150: $r->print('<h3>'.&mt('Pending enrollment requests').'</h3>'."\n");
5151: $r->print(&Apache::loncoursequeueadmin::display_queued_requests($context,
5152: $cdom,$cnum));
5153: } elsif ($env{'form.state'} eq 'done') {
5154: $r->print('<h3>'.&mt('Enrollment request processing').'</h3>'."\n");
5155: $r->print(&Apache::loncoursequeueadmin::update_request_queue($context,
5156: $cdom,$cnum,$coursedesc));
5157: }
5158: } else {
5159: $r->print(&header(undef,{'no_nav_bar' => 1}).
5160: '<span class="LC_error">'.&mt('You do not have permission to manage self-enrollment').'</span>');
1.277 raeburn 5161: }
1.239 raeburn 5162: } elsif ($env{'form.action'} eq 'changelogs') {
1.406.2.6 raeburn 5163: if ($permission->{cusr} || $permission->{view}) {
5164: &print_userchangelogs_display($r,$context,$permission,$brcrum);
5165: } else {
5166: $r->print(&header(undef,{'no_nav_bar' => 1}).
5167: '<span class="LC_error">'.&mt('You do not have permission to view change logs').'</span>');
5168: }
1.406.2.10 raeburn 5169: } elsif ($env{'form.action'} eq 'helpdesk') {
5170: if (($permission->{'owner'}) || ($permission->{'co-owner'})) {
5171: if ($env{'form.state'} eq 'process') {
5172: if ($permission->{'owner'}) {
5173: &update_helpdeskaccess($r,$permission,$brcrum);
5174: } else {
5175: &print_helpdeskaccess_display($r,$permission,$brcrum);
5176: }
5177: } else {
5178: &print_helpdeskaccess_display($r,$permission,$brcrum);
5179: }
5180: } else {
5181: $r->print(&header(undef,{'no_nav_bar' => 1}).
5182: '<span class="LC_error">'.&mt('You do not have permission to view helpdesk access').'</span>');
5183: }
1.190 raeburn 5184: } else {
1.351 raeburn 5185: $bread_crumbs_component = 'User Management';
5186: $args = { bread_crumbs => $brcrum,
5187: bread_crumbs_component => $bread_crumbs_component};
5188: $r->print(&header(undef,$args));
1.318 raeburn 5189: $r->print(&print_main_menu($permission,$context,$crstype));
1.190 raeburn 5190: }
1.351 raeburn 5191: $r->print(&Apache::loncommon::end_page());
1.190 raeburn 5192: return OK;
5193: }
5194:
5195: sub header {
1.351 raeburn 5196: my ($jscript,$args) = @_;
1.190 raeburn 5197: my $start_page;
1.351 raeburn 5198: if (ref($args) eq 'HASH') {
5199: $start_page=&Apache::loncommon::start_page('User Management',$jscript,$args);
1.190 raeburn 5200: } else {
1.351 raeburn 5201: $start_page=&Apache::loncommon::start_page('User Management',$jscript);
1.190 raeburn 5202: }
5203: return $start_page;
5204: }
1.2 www 5205:
1.191 raeburn 5206: sub add_script {
5207: my ($js) = @_;
1.301 bisitz 5208: return '<script type="text/javascript">'."\n"
5209: .'// <![CDATA['."\n"
5210: .$js."\n"
5211: .'// ]]>'."\n"
5212: .'</script>'."\n";
1.191 raeburn 5213: }
5214:
1.391 raeburn 5215: sub usernamerequest_javascript {
5216: my $js = <<ENDJS;
5217:
5218: function openusernamereqdisplay(dom,uname,queue) {
5219: var url = '/adm/createuser?action=displayuserreq';
5220: url += '&domain='+dom+'&username='+uname+'&queue='+queue;
5221: var title = 'Account_Request_Browser';
5222: var options = 'scrollbars=1,resizable=1,menubar=0';
5223: options += ',width=700,height=600';
5224: var stdeditbrowser = open(url,title,options,'1');
5225: stdeditbrowser.focus();
5226: return;
5227: }
5228:
5229: ENDJS
5230: }
5231:
5232: sub close_popup_form {
5233: my $close= &mt('Close Window');
5234: return << "END";
5235: <p><form name="displayreq" action="" method="post">
5236: <input type="button" name="closeme" value="$close" onclick="javascript:self.close();" />
5237: </form></p>
5238: END
5239: }
5240:
1.202 raeburn 5241: sub verify_user_display {
1.364 raeburn 5242: my ($context) = @_;
1.374 raeburn 5243: my %lt = &Apache::lonlocal::texthash (
5244: course => 'course(s): description, section(s), status',
5245: community => 'community(s): description, section(s), status',
5246: author => 'author',
5247: );
1.364 raeburn 5248: my $photos;
5249: if (($context eq 'course') && $env{'request.course.id'}) {
5250: $photos = $env{'course.'.$env{'request.course.id'}.'.internal.showphoto'};
5251: }
1.202 raeburn 5252: my $output = <<"END";
5253:
1.364 raeburn 5254: function hide_searching() {
5255: if (document.getElementById('searching')) {
5256: document.getElementById('searching').style.display = 'none';
5257: }
5258: return;
5259: }
5260:
1.202 raeburn 5261: function display_update() {
5262: document.studentform.action.value = 'listusers';
5263: document.studentform.phase.value = 'display';
5264: document.studentform.submit();
5265: }
5266:
1.364 raeburn 5267: function updateCols(caller) {
5268: var context = '$context';
5269: var photos = '$photos';
5270: if (caller == 'Status') {
1.374 raeburn 5271: if ((context == 'domain') &&
5272: ((document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'course') ||
5273: (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community'))) {
1.364 raeburn 5274: document.getElementById('showcolstatus').checked = false;
5275: document.getElementById('showcolstatus').disabled = 'disabled';
5276: document.getElementById('showcolstart').checked = false;
5277: document.getElementById('showcolend').checked = false;
1.374 raeburn 5278: } else {
5279: if (document.studentform.Status.options[document.studentform.Status.selectedIndex].value == 'Any') {
5280: document.getElementById('showcolstatus').checked = true;
5281: document.getElementById('showcolstatus').disabled = '';
5282: document.getElementById('showcolstart').checked = true;
5283: document.getElementById('showcolend').checked = true;
5284: } else {
5285: document.getElementById('showcolstatus').checked = false;
5286: document.getElementById('showcolstatus').disabled = 'disabled';
5287: document.getElementById('showcolstart').checked = false;
5288: document.getElementById('showcolend').checked = false;
5289: }
1.364 raeburn 5290: }
5291: }
5292: if (caller == 'output') {
5293: if (photos == 1) {
5294: if (document.getElementById('showcolphoto')) {
5295: var photoitem = document.getElementById('showcolphoto');
5296: if (document.studentform.output.options[document.studentform.output.selectedIndex].value == 'html') {
5297: photoitem.checked = true;
5298: photoitem.disabled = '';
5299: } else {
5300: photoitem.checked = false;
5301: photoitem.disabled = 'disabled';
5302: }
5303: }
5304: }
5305: }
5306: if (caller == 'showrole') {
1.371 raeburn 5307: if ((document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'Any') ||
5308: (document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'cr')) {
1.364 raeburn 5309: document.getElementById('showcolrole').checked = true;
5310: document.getElementById('showcolrole').disabled = '';
5311: } else {
5312: document.getElementById('showcolrole').checked = false;
5313: document.getElementById('showcolrole').disabled = 'disabled';
5314: }
1.374 raeburn 5315: if (context == 'domain') {
1.382 raeburn 5316: var quotausageshow = 0;
1.374 raeburn 5317: if ((document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'course') ||
5318: (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community')) {
5319: document.getElementById('showcolstatus').checked = false;
5320: document.getElementById('showcolstatus').disabled = 'disabled';
5321: document.getElementById('showcolstart').checked = false;
5322: document.getElementById('showcolend').checked = false;
5323: } else {
5324: if (document.studentform.Status.options[document.studentform.Status.selectedIndex].value == 'Any') {
5325: document.getElementById('showcolstatus').checked = true;
5326: document.getElementById('showcolstatus').disabled = '';
5327: document.getElementById('showcolstart').checked = true;
5328: document.getElementById('showcolend').checked = true;
5329: }
5330: }
5331: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'domain') {
5332: document.getElementById('showcolextent').disabled = 'disabled';
5333: document.getElementById('showcolextent').checked = 'false';
5334: document.getElementById('showextent').style.display='none';
5335: document.getElementById('showcoltextextent').innerHTML = '';
1.382 raeburn 5336: if ((document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'au') ||
5337: (document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'Any')) {
5338: if (document.getElementById('showcolauthorusage')) {
5339: document.getElementById('showcolauthorusage').disabled = '';
5340: }
5341: if (document.getElementById('showcolauthorquota')) {
5342: document.getElementById('showcolauthorquota').disabled = '';
5343: }
5344: quotausageshow = 1;
5345: }
1.374 raeburn 5346: } else {
5347: document.getElementById('showextent').style.display='block';
5348: document.getElementById('showextent').style.textAlign='left';
5349: document.getElementById('showextent').style.textFace='normal';
5350: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'author') {
5351: document.getElementById('showcolextent').disabled = '';
5352: document.getElementById('showcolextent').checked = 'true';
5353: document.getElementById('showcoltextextent').innerHTML="$lt{'author'}";
5354: } else {
5355: document.getElementById('showcolextent').disabled = '';
5356: document.getElementById('showcolextent').checked = 'true';
5357: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community') {
5358: document.getElementById('showcoltextextent').innerHTML="$lt{'community'}";
5359: } else {
5360: document.getElementById('showcoltextextent').innerHTML="$lt{'course'}";
5361: }
5362: }
5363: }
1.382 raeburn 5364: if (quotausageshow == 0) {
5365: if (document.getElementById('showcolauthorusage')) {
5366: document.getElementById('showcolauthorusage').checked = false;
5367: document.getElementById('showcolauthorusage').disabled = 'disabled';
5368: }
5369: if (document.getElementById('showcolauthorquota')) {
5370: document.getElementById('showcolauthorquota').checked = false;
5371: document.getElementById('showcolauthorquota').disabled = 'disabled';
5372: }
5373: }
1.374 raeburn 5374: }
1.364 raeburn 5375: }
5376: return;
5377: }
5378:
1.202 raeburn 5379: END
5380: return $output;
5381:
5382: }
5383:
1.190 raeburn 5384: ###############################################################
5385: ###############################################################
5386: # Menu Phase One
5387: sub print_main_menu {
1.318 raeburn 5388: my ($permission,$context,$crstype) = @_;
5389: my $linkcontext = $context;
5390: my $stuterm = lc(&Apache::lonnet::plaintext('st',$crstype));
5391: if (($context eq 'course') && ($crstype eq 'Community')) {
5392: $linkcontext = lc($crstype);
5393: $stuterm = 'Members';
5394: }
1.208 raeburn 5395: my %links = (
1.298 droeschl 5396: domain => {
5397: upload => 'Upload a File of Users',
5398: singleuser => 'Add/Modify a User',
5399: listusers => 'Manage Users',
5400: },
5401: author => {
5402: upload => 'Upload a File of Co-authors',
5403: singleuser => 'Add/Modify a Co-author',
5404: listusers => 'Manage Co-authors',
5405: },
5406: course => {
5407: upload => 'Upload a File of Course Users',
5408: singleuser => 'Add/Modify a Course User',
1.354 www 5409: listusers => 'List and Modify Multiple Course Users',
1.298 droeschl 5410: },
1.318 raeburn 5411: community => {
5412: upload => 'Upload a File of Community Users',
5413: singleuser => 'Add/Modify a Community User',
1.354 www 5414: listusers => 'List and Modify Multiple Community Users',
1.318 raeburn 5415: },
5416: );
5417: my %linktitles = (
5418: domain => {
5419: singleuser => 'Add a user to the domain, and/or a course or community in the domain.',
5420: listusers => 'Show and manage users in this domain.',
5421: },
5422: author => {
5423: singleuser => 'Add a user with a co- or assistant author role.',
5424: listusers => 'Show and manage co- or assistant authors.',
5425: },
5426: course => {
5427: singleuser => 'Add a user with a certain role to this course.',
5428: listusers => 'Show and manage users in this course.',
5429: },
5430: community => {
5431: singleuser => 'Add a user with a certain role to this community.',
5432: listusers => 'Show and manage users in this community.',
5433: },
1.298 droeschl 5434: );
1.406.2.6 raeburn 5435: if ($linkcontext eq 'domain') {
5436: unless ($permission->{'cusr'}) {
5437: $links{'domain'}{'singleuser'} = 'View a User';
5438: $linktitles{'domain'}{'singleuser'} = 'View information about a user in the domain';
5439: }
5440: } elsif ($linkcontext eq 'course') {
5441: unless ($permission->{'cusr'}) {
5442: $links{'course'}{'singleuser'} = 'View a Course User';
5443: $linktitles{'course'}{'singleuser'} = 'View information about a user in this course';
5444: $links{'course'}{'listusers'} = 'List Course Users';
5445: $linktitles{'course'}{'listusers'} = 'Show information about users in this course';
5446: }
5447: } elsif ($linkcontext eq 'community') {
5448: unless ($permission->{'cusr'}) {
5449: $links{'community'}{'singleuser'} = 'View a Community User';
5450: $linktitles{'community'}{'singleuser'} = 'View information about a user in this community';
5451: $links{'community'}{'listusers'} = 'List Community Users';
5452: $linktitles{'community'}{'listusers'} = 'Show information about users in this community';
5453: }
5454: }
1.298 droeschl 5455: my @menu = ( {categorytitle => 'Single Users',
5456: items =>
5457: [
5458: {
1.318 raeburn 5459: linktext => $links{$linkcontext}{'singleuser'},
1.298 droeschl 5460: icon => 'edit-redo.png',
5461: #help => 'Course_Change_Privileges',
5462: url => '/adm/createuser?action=singleuser',
1.406.2.6 raeburn 5463: permission => ($permission->{'view'} || $permission->{'cusr'}),
1.318 raeburn 5464: linktitle => $linktitles{$linkcontext}{'singleuser'},
1.298 droeschl 5465: },
5466: ]},
5467:
5468: {categorytitle => 'Multiple Users',
5469: items =>
5470: [
5471: {
1.318 raeburn 5472: linktext => $links{$linkcontext}{'upload'},
1.340 wenzelju 5473: icon => 'uplusr.png',
1.298 droeschl 5474: #help => 'Course_Create_Class_List',
5475: url => '/adm/createuser?action=upload',
5476: permission => $permission->{'cusr'},
5477: linktitle => 'Upload a CSV or a text file containing users.',
5478: },
5479: {
1.318 raeburn 5480: linktext => $links{$linkcontext}{'listusers'},
1.340 wenzelju 5481: icon => 'mngcu.png',
1.298 droeschl 5482: #help => 'Course_View_Class_List',
5483: url => '/adm/createuser?action=listusers',
5484: permission => ($permission->{'view'} || $permission->{'cusr'}),
1.318 raeburn 5485: linktitle => $linktitles{$linkcontext}{'listusers'},
1.298 droeschl 5486: },
5487:
5488: ]},
5489:
5490: {categorytitle => 'Administration',
5491: items => [ ]},
5492: );
1.406.2.5 raeburn 5493:
1.265 mielkec 5494: if ($context eq 'domain'){
1.406.2.5 raeburn 5495: push(@{ $menu[0]->{items} }, # Single Users
5496: {
5497: linktext => 'User Access Log',
5498: icon => 'document-properties.png',
1.406.2.8 raeburn 5499: #help => 'Domain_User_Access_Logs',
1.406.2.5 raeburn 5500: url => '/adm/createuser?action=accesslogs',
5501: permission => $permission->{'activity'},
5502: linktitle => 'View user access log.',
5503: }
5504: );
1.298 droeschl 5505:
5506: push(@{ $menu[2]->{items} }, #Category: Administration
5507: {
5508: linktext => 'Custom Roles',
5509: icon => 'emblem-photos.png',
5510: #help => 'Course_Editing_Custom_Roles',
5511: url => '/adm/createuser?action=custom',
5512: permission => $permission->{'custom'},
5513: linktitle => 'Configure a custom role.',
5514: },
1.362 raeburn 5515: {
5516: linktext => 'Authoring Space Requests',
5517: icon => 'selfenrl-queue.png',
5518: #help => 'Domain_Role_Approvals',
5519: url => '/adm/createuser?action=processauthorreq',
5520: permission => $permission->{'cusr'},
5521: linktitle => 'Approve or reject author role requests',
5522: },
1.363 raeburn 5523: {
1.391 raeburn 5524: linktext => 'LON-CAPA Account Requests',
5525: icon => 'list-add.png',
5526: #help => 'Domain_Username_Approvals',
5527: url => '/adm/createuser?action=processusernamereq',
5528: permission => $permission->{'cusr'},
5529: linktitle => 'Approve or reject LON-CAPA account requests',
5530: },
5531: {
1.363 raeburn 5532: linktext => 'Change Log',
5533: icon => 'document-properties.png',
5534: #help => 'Course_User_Logs',
5535: url => '/adm/createuser?action=changelogs',
1.406.2.6 raeburn 5536: permission => ($permission->{'cusr'} || $permission->{'view'}),
1.363 raeburn 5537: linktitle => 'View change log.',
5538: },
1.298 droeschl 5539: );
5540:
1.265 mielkec 5541: }elsif ($context eq 'course'){
1.298 droeschl 5542: my ($cnum,$cdom) = &Apache::lonuserutils::get_course_identity();
1.318 raeburn 5543:
5544: my %linktext = (
5545: 'Course' => {
5546: single => 'Add/Modify a Student',
5547: drop => 'Drop Students',
5548: groups => 'Course Groups',
5549: },
5550: 'Community' => {
5551: single => 'Add/Modify a Member',
5552: drop => 'Drop Members',
5553: groups => 'Community Groups',
5554: },
5555: );
5556:
5557: my %linktitle = (
5558: 'Course' => {
5559: single => 'Add a user with the role of student to this course',
5560: drop => 'Remove a student from this course.',
5561: groups => 'Manage course groups',
5562: },
5563: 'Community' => {
5564: single => 'Add a user with the role of member to this community',
5565: drop => 'Remove a member from this community.',
5566: groups => 'Manage community groups',
5567: },
5568: );
5569:
1.298 droeschl 5570: push(@{ $menu[0]->{items} }, #Category: Single Users
5571: {
1.318 raeburn 5572: linktext => $linktext{$crstype}{'single'},
1.298 droeschl 5573: #help => 'Course_Add_Student',
5574: icon => 'list-add.png',
5575: url => '/adm/createuser?action=singlestudent',
5576: permission => $permission->{'cusr'},
1.318 raeburn 5577: linktitle => $linktitle{$crstype}{'single'},
1.298 droeschl 5578: },
5579: );
5580:
5581: push(@{ $menu[1]->{items} }, #Category: Multiple Users
5582: {
1.318 raeburn 5583: linktext => $linktext{$crstype}{'drop'},
1.298 droeschl 5584: icon => 'edit-undo.png',
5585: #help => 'Course_Drop_Student',
5586: url => '/adm/createuser?action=drop',
5587: permission => $permission->{'cusr'},
1.318 raeburn 5588: linktitle => $linktitle{$crstype}{'drop'},
1.298 droeschl 5589: },
5590: );
5591: push(@{ $menu[2]->{items} }, #Category: Administration
1.406.2.11 raeburn 5592: {
5593: linktext => 'Helpdesk Access',
5594: icon => 'helpdesk-access.png',
5595: #help => 'Course_Helpdesk_Access',
5596: url => '/adm/createuser?action=helpdesk',
5597: permission => ($permission->{'owner'} || $permission->{'co-owner'}),
5598: linktitle => 'Helpdesk access options',
5599: },
5600: {
1.298 droeschl 5601: linktext => 'Custom Roles',
5602: icon => 'emblem-photos.png',
5603: #help => 'Course_Editing_Custom_Roles',
5604: url => '/adm/createuser?action=custom',
5605: permission => $permission->{'custom'},
5606: linktitle => 'Configure a custom role.',
5607: },
5608: {
1.318 raeburn 5609: linktext => $linktext{$crstype}{'groups'},
1.333 wenzelju 5610: icon => 'grps.png',
1.298 droeschl 5611: #help => 'Course_Manage_Group',
5612: url => '/adm/coursegroups?refpage=cusr',
5613: permission => $permission->{'grp_manage'},
1.318 raeburn 5614: linktitle => $linktitle{$crstype}{'groups'},
1.298 droeschl 5615: },
5616: {
1.328 wenzelju 5617: linktext => 'Change Log',
1.298 droeschl 5618: icon => 'document-properties.png',
5619: #help => 'Course_User_Logs',
5620: url => '/adm/createuser?action=changelogs',
1.406.2.6 raeburn 5621: permission => ($permission->{'view'} || $permission->{'cusr'}),
1.298 droeschl 5622: linktitle => 'View change log.',
5623: },
5624: );
1.277 raeburn 5625: if ($env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_approval'}) {
1.298 droeschl 5626: push(@{ $menu[2]->{items} },
1.398 raeburn 5627: {
1.298 droeschl 5628: linktext => 'Enrollment Requests',
5629: icon => 'selfenrl-queue.png',
5630: #help => 'Course_Approve_Selfenroll',
5631: url => '/adm/createuser?action=selfenrollqueue',
1.398 raeburn 5632: permission => $permission->{'selfenrolladmin'},
1.298 droeschl 5633: linktitle =>'Approve or reject enrollment requests.',
5634: },
5635: );
1.277 raeburn 5636: }
1.298 droeschl 5637:
1.265 mielkec 5638: if (!exists($permission->{'cusr_section'})){
1.320 raeburn 5639: if ($crstype ne 'Community') {
5640: push(@{ $menu[2]->{items} },
5641: {
5642: linktext => 'Automated Enrollment',
5643: icon => 'roles.png',
5644: #help => 'Course_Automated_Enrollment',
5645: permission => (&Apache::lonnet::auto_run($cnum,$cdom)
1.406.2.6 raeburn 5646: && (($permission->{'cusr'}) ||
5647: ($permission->{'view'}))),
1.320 raeburn 5648: url => '/adm/populate',
5649: linktitle => 'Automated enrollment manager.',
5650: }
5651: );
5652: }
5653: push(@{ $menu[2]->{items} },
1.298 droeschl 5654: {
5655: linktext => 'User Self-Enrollment',
1.342 wenzelju 5656: icon => 'self_enroll.png',
1.298 droeschl 5657: #help => 'Course_Self_Enrollment',
5658: url => '/adm/createuser?action=selfenroll',
1.398 raeburn 5659: permission => $permission->{'selfenrolladmin'},
1.317 bisitz 5660: linktitle => 'Configure user self-enrollment.',
1.298 droeschl 5661: },
5662: );
5663: }
1.363 raeburn 5664: } elsif ($context eq 'author') {
1.370 raeburn 5665: push(@{ $menu[2]->{items} }, #Category: Administration
1.363 raeburn 5666: {
5667: linktext => 'Change Log',
5668: icon => 'document-properties.png',
5669: #help => 'Course_User_Logs',
5670: url => '/adm/createuser?action=changelogs',
5671: permission => $permission->{'cusr'},
5672: linktitle => 'View change log.',
5673: },
1.370 raeburn 5674: );
1.363 raeburn 5675: }
5676: return Apache::lonhtmlcommon::generate_menu(@menu);
1.250 raeburn 5677: # { text => 'View Log-in History',
5678: # help => 'Course_User_Logins',
5679: # action => 'logins',
5680: # permission => $permission->{'cusr'},
5681: # });
1.190 raeburn 5682: }
5683:
1.189 albertel 5684: sub restore_prev_selections {
5685: my %saveable_parameters = ('srchby' => 'scalar',
5686: 'srchin' => 'scalar',
5687: 'srchtype' => 'scalar',
5688: );
5689: &Apache::loncommon::store_settings('user','user_picker',
5690: \%saveable_parameters);
5691: &Apache::loncommon::restore_settings('user','user_picker',
5692: \%saveable_parameters);
5693: }
5694:
1.237 raeburn 5695: sub print_selfenroll_menu {
1.406.2.6 raeburn 5696: my ($r,$context,$cid,$cdom,$cnum,$currsettings,$additional,$readonly) = @_;
1.322 raeburn 5697: my $crstype = &Apache::loncommon::course_type();
1.398 raeburn 5698: my $formname = 'selfenroll';
1.237 raeburn 5699: my $nolink = 1;
1.398 raeburn 5700: my ($row,$lt) = &Apache::lonuserutils::get_selfenroll_titles();
1.237 raeburn 5701: my $groupslist = &Apache::lonuserutils::get_groupslist();
5702: my $setsec_js =
5703: &Apache::lonuserutils::setsections_javascript($formname,$groupslist);
1.249 raeburn 5704: my %alerts = &Apache::lonlocal::texthash(
5705: acto => 'Activation of self-enrollment was selected for the following domain(s)',
5706: butn => 'but no user types have been checked.',
5707: wilf => "Please uncheck 'activate' or check at least one type.",
5708: );
1.406.2.6 raeburn 5709: my $disabled;
5710: if ($readonly) {
5711: $disabled = ' disabled="disabled"';
5712: }
1.405 damieng 5713: &js_escape(\%alerts);
1.249 raeburn 5714: my $selfenroll_js = <<"ENDSCRIPT";
5715: function update_types(caller,num) {
5716: var delidx = getIndexByName('selfenroll_delete');
5717: var actidx = getIndexByName('selfenroll_activate');
5718: if (caller == 'selfenroll_all') {
5719: var selall;
5720: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
5721: if (document.$formname.selfenroll_all[i].checked) {
5722: selall = document.$formname.selfenroll_all[i].value;
5723: }
5724: }
5725: if (selall == 1) {
5726: if (delidx != -1) {
5727: if (document.$formname.selfenroll_delete.length) {
5728: for (var j=0; j<document.$formname.selfenroll_delete.length; j++) {
5729: document.$formname.selfenroll_delete[j].checked = true;
5730: }
5731: } else {
5732: document.$formname.elements[delidx].checked = true;
5733: }
5734: }
5735: if (actidx != -1) {
5736: if (document.$formname.selfenroll_activate.length) {
5737: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
5738: document.$formname.selfenroll_activate[j].checked = false;
5739: }
5740: } else {
5741: document.$formname.elements[actidx].checked = false;
5742: }
5743: }
5744: document.$formname.selfenroll_newdom.selectedIndex = 0;
5745: }
5746: }
5747: if (caller == 'selfenroll_activate') {
5748: if (document.$formname.selfenroll_activate.length) {
5749: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
5750: if (document.$formname.selfenroll_activate[j].value == num) {
5751: if (document.$formname.selfenroll_activate[j].checked) {
5752: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
5753: if (document.$formname.selfenroll_all[i].value == '1') {
5754: document.$formname.selfenroll_all[i].checked = false;
5755: }
5756: if (document.$formname.selfenroll_all[i].value == '0') {
5757: document.$formname.selfenroll_all[i].checked = true;
5758: }
5759: }
5760: }
5761: }
5762: }
5763: } else {
5764: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
5765: if (document.$formname.selfenroll_all[i].value == '1') {
5766: document.$formname.selfenroll_all[i].checked = false;
5767: }
5768: if (document.$formname.selfenroll_all[i].value == '0') {
5769: document.$formname.selfenroll_all[i].checked = true;
5770: }
5771: }
5772: }
5773: }
5774: if (caller == 'selfenroll_delete') {
5775: if (document.$formname.selfenroll_delete.length) {
5776: for (var j=0; j<document.$formname.selfenroll_delete.length; j++) {
5777: if (document.$formname.selfenroll_delete[j].value == num) {
5778: if (document.$formname.selfenroll_delete[j].checked) {
5779: var delindex = getIndexByName('selfenroll_types_'+num);
5780: if (delindex != -1) {
5781: if (document.$formname.elements[delindex].length) {
5782: for (var k=0; k<document.$formname.elements[delindex].length; k++) {
5783: document.$formname.elements[delindex][k].checked = false;
5784: }
5785: } else {
5786: document.$formname.elements[delindex].checked = false;
5787: }
5788: }
5789: }
5790: }
5791: }
5792: } else {
5793: if (document.$formname.selfenroll_delete.checked) {
5794: var delindex = getIndexByName('selfenroll_types_'+num);
5795: if (delindex != -1) {
5796: if (document.$formname.elements[delindex].length) {
5797: for (var k=0; k<document.$formname.elements[delindex].length; k++) {
5798: document.$formname.elements[delindex][k].checked = false;
5799: }
5800: } else {
5801: document.$formname.elements[delindex].checked = false;
5802: }
5803: }
5804: }
5805: }
5806: }
5807: return;
5808: }
5809:
5810: function validate_types(form) {
5811: var needaction = new Array();
5812: var countfail = 0;
5813: var actidx = getIndexByName('selfenroll_activate');
5814: if (actidx != -1) {
5815: if (document.$formname.selfenroll_activate.length) {
5816: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
5817: var num = document.$formname.selfenroll_activate[j].value;
5818: if (document.$formname.selfenroll_activate[j].checked) {
5819: countfail = check_types(num,countfail,needaction)
5820: }
5821: }
5822: } else {
5823: if (document.$formname.selfenroll_activate.checked) {
1.398 raeburn 5824: var num = document.$formname.selfenroll_activate.value;
1.249 raeburn 5825: countfail = check_types(num,countfail,needaction)
5826: }
5827: }
5828: }
5829: if (countfail > 0) {
5830: var msg = "$alerts{'acto'}\\n";
5831: var loopend = needaction.length -1;
5832: if (loopend > 0) {
5833: for (var m=0; m<loopend; m++) {
5834: msg += needaction[m]+", ";
5835: }
5836: }
5837: msg += needaction[loopend]+"\\n$alerts{'butn'}\\n$alerts{'wilf'}";
5838: alert(msg);
5839: return;
5840: }
5841: setSections(form);
5842: }
5843:
5844: function check_types(num,countfail,needaction) {
1.406.2.15! raeburn 5845: var boxname = 'selfenroll_types_'+num;
! 5846: var typeidx = getIndexByName(boxname);
1.249 raeburn 5847: var count = 0;
5848: if (typeidx != -1) {
1.406.2.15! raeburn 5849: if (document.$formname.elements[boxname].length) {
! 5850: for (var k=0; k<document.$formname.elements[boxname].length; k++) {
! 5851: if (document.$formname.elements[boxname][k].checked) {
1.249 raeburn 5852: count ++;
5853: }
5854: }
5855: } else {
5856: if (document.$formname.elements[typeidx].checked) {
5857: count ++;
5858: }
5859: }
5860: if (count == 0) {
5861: var domidx = getIndexByName('selfenroll_dom_'+num);
5862: if (domidx != -1) {
5863: var domname = document.$formname.elements[domidx].value;
5864: needaction[countfail] = domname;
5865: countfail ++;
5866: }
5867: }
5868: }
5869: return countfail;
5870: }
5871:
1.398 raeburn 5872: function toggleNotify() {
5873: var selfenrollApproval = 0;
5874: if (document.$formname.selfenroll_approval.length) {
5875: for (var i=0; i<document.$formname.selfenroll_approval.length; i++) {
5876: if (document.$formname.selfenroll_approval[i].checked) {
5877: selfenrollApproval = document.$formname.selfenroll_approval[i].value;
5878: break;
5879: }
5880: }
5881: }
5882: if (document.getElementById('notified')) {
5883: if (selfenrollApproval == 0) {
5884: document.getElementById('notified').style.display='none';
5885: } else {
5886: document.getElementById('notified').style.display='block';
5887: }
5888: }
5889: return;
5890: }
5891:
1.249 raeburn 5892: function getIndexByName(item) {
5893: for (var i=0;i<document.$formname.elements.length;i++) {
5894: if (document.$formname.elements[i].name == item) {
5895: return i;
5896: }
5897: }
5898: return -1;
5899: }
5900: ENDSCRIPT
1.256 raeburn 5901:
1.237 raeburn 5902: my $output = '<script type="text/javascript">'."\n".
1.301 bisitz 5903: '// <![CDATA['."\n".
1.249 raeburn 5904: $setsec_js."\n".$selfenroll_js."\n".
1.301 bisitz 5905: '// ]]>'."\n".
1.237 raeburn 5906: '</script>'."\n".
1.256 raeburn 5907: '<h3>'.$lt->{'selfenroll'}.'</h3>'."\n";
1.400 raeburn 5908:
5909: my $visactions = &cat_visibility();
5910: my ($cathash,%cattype);
5911: my %domconfig = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom);
5912: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
5913: $cathash = $domconfig{'coursecategories'}{'cats'};
5914: $cattype{'auth'} = $domconfig{'coursecategories'}{'auth'};
5915: $cattype{'unauth'} = $domconfig{'coursecategories'}{'unauth'};
1.406 raeburn 5916: if ($cattype{'auth'} eq '') {
5917: $cattype{'auth'} = 'std';
5918: }
5919: if ($cattype{'unauth'} eq '') {
5920: $cattype{'unauth'} = 'std';
5921: }
1.400 raeburn 5922: } else {
5923: $cathash = {};
5924: $cattype{'auth'} = 'std';
5925: $cattype{'unauth'} = 'std';
5926: }
5927: if (($cattype{'auth'} eq 'none') && ($cattype{'unauth'} eq 'none')) {
5928: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
5929: '<br />'.
5930: '<br />'.$visactions->{'take'}.'<ul>'.
5931: '<li>'.$visactions->{'dc_chgconf'}.'</li>'.
5932: '</ul>');
5933: } elsif (($cattype{'auth'} !~ /^(std|domonly)$/) && ($cattype{'unauth'} !~ /^(std|domonly)$/)) {
5934: if ($currsettings->{'uniquecode'}) {
5935: $r->print('<span class="LC_info">'.$visactions->{'vis'}.'</span>');
5936: } else {
5937: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
5938: '<br />'.
5939: '<br />'.$visactions->{'take'}.'<ul>'.
5940: '<li>'.$visactions->{'dc_setcode'}.'</li>'.
5941: '</ul><br />');
5942: }
5943: } else {
5944: my ($visible,$cansetvis,$vismsgs) = &visible_in_stdcat($cdom,$cnum,\%domconfig);
5945: if (ref($visactions) eq 'HASH') {
5946: if ($visible) {
5947: $output .= '<p class="LC_info">'.$visactions->{'vis'}.'</p>';
5948: } else {
5949: $output .= '<p class="LC_warning">'.$visactions->{'miss'}.'</p>'
5950: .$visactions->{'yous'}.
5951: '<p>'.$visactions->{'gen'}.'<br />'.$visactions->{'coca'};
5952: if (ref($vismsgs) eq 'ARRAY') {
5953: $output .= '<br />'.$visactions->{'make'}.'<ul>';
5954: foreach my $item (@{$vismsgs}) {
5955: $output .= '<li>'.$visactions->{$item}.'</li>';
5956: }
5957: $output .= '</ul>';
1.256 raeburn 5958: }
1.400 raeburn 5959: $output .= '</p>';
1.256 raeburn 5960: }
5961: }
5962: }
1.398 raeburn 5963: my $actionhref = '/adm/createuser';
5964: if ($context eq 'domain') {
5965: $actionhref = '/adm/modifycourse';
5966: }
1.400 raeburn 5967:
5968: my %noedit;
5969: unless ($context eq 'domain') {
5970: %noedit = &get_noedit_fields($cdom,$cnum,$crstype,$row);
5971: }
1.398 raeburn 5972: $output .= '<form name="'.$formname.'" method="post" action="'.$actionhref.'">'."\n".
1.256 raeburn 5973: &Apache::lonhtmlcommon::start_pick_box();
1.237 raeburn 5974: if (ref($row) eq 'ARRAY') {
5975: foreach my $item (@{$row}) {
5976: my $title = $item;
5977: if (ref($lt) eq 'HASH') {
5978: $title = $lt->{$item};
5979: }
1.297 bisitz 5980: $output .= &Apache::lonhtmlcommon::row_title($title);
1.237 raeburn 5981: if ($item eq 'types') {
1.398 raeburn 5982: my $curr_types;
5983: if (ref($currsettings) eq 'HASH') {
5984: $curr_types = $currsettings->{'selfenroll_types'};
5985: }
1.400 raeburn 5986: if ($noedit{$item}) {
5987: if ($curr_types eq '*') {
5988: $output .= &mt('Any user in any domain');
5989: } else {
5990: my @entries = split(/;/,$curr_types);
5991: if (@entries > 0) {
5992: $output .= '<ul>';
5993: foreach my $entry (@entries) {
5994: my ($currdom,$typestr) = split(/:/,$entry);
5995: next if ($typestr eq '');
5996: my $domdesc = &Apache::lonnet::domain($currdom);
5997: my @currinsttypes = split(',',$typestr);
5998: my ($othertitle,$usertypes,$types) =
5999: &Apache::loncommon::sorted_inst_types($currdom);
6000: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
6001: $usertypes->{'any'} = &mt('any user');
6002: if (keys(%{$usertypes}) > 0) {
6003: $usertypes->{'other'} = &mt('other users');
6004: }
6005: my @longinsttypes = map { $usertypes->{$_}; } @currinsttypes;
6006: $output .= '<li>'.$domdesc.':'.join(', ',@longinsttypes).'</li>';
6007: }
6008: }
6009: $output .= '</ul>';
6010: } else {
6011: $output .= &mt('None');
6012: }
6013: }
6014: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6015: next;
6016: }
1.241 raeburn 6017: my $showdomdesc = 1;
6018: my $includeempty = 1;
6019: my $num = 0;
6020: $output .= &Apache::loncommon::start_data_table().
6021: &Apache::loncommon::start_data_table_row()
6022: .'<td colspan="2"><span class="LC_nobreak"><label>'
6023: .&mt('Any user in any domain:')
6024: .' <input type="radio" name="selfenroll_all" value="1" ';
6025: if ($curr_types eq '*') {
6026: $output .= ' checked="checked" ';
6027: }
1.249 raeburn 6028: $output .= 'onchange="javascript:update_types('.
1.406.2.6 raeburn 6029: "'selfenroll_all'".');"'.$disabled.' />'.&mt('Yes').'</label>'.
1.249 raeburn 6030: ' <input type="radio" name="selfenroll_all" value="0" ';
1.241 raeburn 6031: if ($curr_types ne '*') {
6032: $output .= ' checked="checked" ';
6033: }
1.249 raeburn 6034: $output .= ' onchange="javascript:update_types('.
1.406.2.6 raeburn 6035: "'selfenroll_all'".');"'.$disabled.' />'.&mt('No').'</label></td>'.
1.249 raeburn 6036: &Apache::loncommon::end_data_table_row().
6037: &Apache::loncommon::end_data_table().
6038: &mt('Or').'<br />'.
6039: &Apache::loncommon::start_data_table();
1.241 raeburn 6040: my %currdoms;
1.249 raeburn 6041: if ($curr_types eq '') {
1.241 raeburn 6042: $output .= &new_selfenroll_dom_row($cdom,'0');
6043: } elsif ($curr_types ne '*') {
6044: my @entries = split(/;/,$curr_types);
6045: if (@entries > 0) {
6046: foreach my $entry (@entries) {
6047: my ($currdom,$typestr) = split(/:/,$entry);
6048: $currdoms{$currdom} = 1;
6049: my $domdesc = &Apache::lonnet::domain($currdom);
1.249 raeburn 6050: my @currinsttypes = split(',',$typestr);
1.241 raeburn 6051: $output .= &Apache::loncommon::start_data_table_row()
6052: .'<td valign="top"><span class="LC_nobreak">'.&mt('Domain:').'<b>'
6053: .' '.$domdesc.' ('.$currdom.')'
6054: .'</b><input type="hidden" name="selfenroll_dom_'.$num
6055: .'" value="'.$currdom.'" /></span><br />'
6056: .'<span class="LC_nobreak"><label><input type="checkbox" '
1.406.2.6 raeburn 6057: .'name="selfenroll_delete" value="'.$num.'" onchange="javascript:update_types('."'selfenroll_delete','$num'".');"'.$disabled.' />'
1.241 raeburn 6058: .&mt('Delete').'</label></span></td>';
1.249 raeburn 6059: $output .= '<td valign="top"> '.&mt('User types:').'<br />'
1.406.2.6 raeburn 6060: .&selfenroll_inst_types($num,$currdom,\@currinsttypes,$readonly).'</td>'
1.241 raeburn 6061: .&Apache::loncommon::end_data_table_row();
6062: $num ++;
6063: }
6064: }
6065: }
1.249 raeburn 6066: my $add_domtitle = &mt('Users in additional domain:');
1.241 raeburn 6067: if ($curr_types eq '*') {
1.249 raeburn 6068: $add_domtitle = &mt('Users in specific domain:');
1.241 raeburn 6069: } elsif ($curr_types eq '') {
1.249 raeburn 6070: $add_domtitle = &mt('Users in other domain:');
1.241 raeburn 6071: }
6072: $output .= &Apache::loncommon::start_data_table_row()
6073: .'<td colspan="2"><span class="LC_nobreak">'.$add_domtitle.'</span><br />'
6074: .&Apache::loncommon::select_dom_form('','selfenroll_newdom',
1.406.2.6 raeburn 6075: $includeempty,$showdomdesc,'','','',$readonly)
1.241 raeburn 6076: .'<input type="hidden" name="selfenroll_types_total" value="'.$num.'" />'
6077: .'</td>'.&Apache::loncommon::end_data_table_row()
6078: .&Apache::loncommon::end_data_table();
1.237 raeburn 6079: } elsif ($item eq 'registered') {
6080: my ($regon,$regoff);
1.398 raeburn 6081: my $registered;
6082: if (ref($currsettings) eq 'HASH') {
6083: $registered = $currsettings->{'selfenroll_registered'};
6084: }
1.400 raeburn 6085: if ($noedit{$item}) {
6086: if ($registered) {
6087: $output .= &mt('Must be registered in course');
6088: } else {
6089: $output .= &mt('No requirement');
6090: }
6091: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6092: next;
6093: }
1.398 raeburn 6094: if ($registered) {
1.237 raeburn 6095: $regon = ' checked="checked" ';
1.406.2.6 raeburn 6096: $regoff = '';
1.237 raeburn 6097: } else {
1.406.2.6 raeburn 6098: $regon = '';
1.237 raeburn 6099: $regoff = ' checked="checked" ';
6100: }
6101: $output .= '<label>'.
1.406.2.6 raeburn 6102: '<input type="radio" name="selfenroll_registered" value="1"'.$regon.$disabled.' />'.
1.244 bisitz 6103: &mt('Yes').'</label> <label>'.
1.406.2.6 raeburn 6104: '<input type="radio" name="selfenroll_registered" value="0"'.$regoff.$disabled.' />'.
1.244 bisitz 6105: &mt('No').'</label>';
1.237 raeburn 6106: } elsif ($item eq 'enroll_dates') {
1.398 raeburn 6107: my ($starttime,$endtime);
6108: if (ref($currsettings) eq 'HASH') {
6109: $starttime = $currsettings->{'selfenroll_start_date'};
6110: $endtime = $currsettings->{'selfenroll_end_date'};
6111: if ($starttime eq '') {
6112: $starttime = $currsettings->{'default_enrollment_start_date'};
6113: }
6114: if ($endtime eq '') {
6115: $endtime = $currsettings->{'default_enrollment_end_date'};
6116: }
1.237 raeburn 6117: }
1.400 raeburn 6118: if ($noedit{$item}) {
6119: $output .= &mt('From: [_1], to: [_2]',&Apache::lonlocal::locallocaltime($starttime),
6120: &Apache::lonlocal::locallocaltime($endtime));
6121: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6122: next;
6123: }
1.237 raeburn 6124: my $startform =
6125: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_start_date',$starttime,
1.406.2.6 raeburn 6126: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
1.237 raeburn 6127: my $endform =
6128: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_end_date',$endtime,
1.406.2.6 raeburn 6129: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
1.237 raeburn 6130: $output .= &selfenroll_date_forms($startform,$endform);
6131: } elsif ($item eq 'access_dates') {
1.398 raeburn 6132: my ($starttime,$endtime);
6133: if (ref($currsettings) eq 'HASH') {
6134: $starttime = $currsettings->{'selfenroll_start_access'};
6135: $endtime = $currsettings->{'selfenroll_end_access'};
6136: if ($starttime eq '') {
6137: $starttime = $currsettings->{'default_enrollment_start_date'};
6138: }
6139: if ($endtime eq '') {
6140: $endtime = $currsettings->{'default_enrollment_end_date'};
6141: }
1.237 raeburn 6142: }
1.400 raeburn 6143: if ($noedit{$item}) {
6144: $output .= &mt('From: [_1], to: [_2]',&Apache::lonlocal::locallocaltime($starttime),
6145: &Apache::lonlocal::locallocaltime($endtime));
6146: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6147: next;
6148: }
1.237 raeburn 6149: my $startform =
6150: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_start_access',$starttime,
1.406.2.6 raeburn 6151: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
1.237 raeburn 6152: my $endform =
6153: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_end_access',$endtime,
1.406.2.6 raeburn 6154: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
1.237 raeburn 6155: $output .= &selfenroll_date_forms($startform,$endform);
6156: } elsif ($item eq 'section') {
1.398 raeburn 6157: my $currsec;
6158: if (ref($currsettings) eq 'HASH') {
6159: $currsec = $currsettings->{'selfenroll_section'};
6160: }
1.237 raeburn 6161: my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum);
6162: my $newsecval;
6163: if ($currsec ne 'none' && $currsec ne '') {
6164: if (!defined($sections_count{$currsec})) {
6165: $newsecval = $currsec;
6166: }
6167: }
1.400 raeburn 6168: if ($noedit{$item}) {
6169: if ($currsec ne '') {
6170: $output .= $currsec;
6171: } else {
6172: $output .= &mt('No specific section');
6173: }
6174: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6175: next;
6176: }
1.237 raeburn 6177: my $sections_select =
1.406.2.6 raeburn 6178: &Apache::lonuserutils::course_sections(\%sections_count,'st',$currsec,$disabled);
1.237 raeburn 6179: $output .= '<table class="LC_createuser">'."\n".
6180: '<tr class="LC_section_row">'."\n".
6181: '<td align="center">'.&mt('Existing sections')."\n".
6182: '<br />'.$sections_select.'</td><td align="center">'.
6183: &mt('New section').'<br />'."\n".
1.406.2.6 raeburn 6184: '<input type="text" name="newsec" size="15" value="'.$newsecval.'"'.$disabled.' />'."\n".
1.237 raeburn 6185: '<input type="hidden" name="sections" value="" />'."\n".
6186: '</td></tr></table>'."\n";
1.276 raeburn 6187: } elsif ($item eq 'approval') {
1.398 raeburn 6188: my ($currnotified,$currapproval,%appchecked);
6189: my %selfdescs = &Apache::lonuserutils::selfenroll_default_descs();
1.406.2.6 raeburn 6190: if (ref($currsettings) eq 'HASH') {
1.398 raeburn 6191: $currnotified = $currsettings->{'selfenroll_notifylist'};
6192: $currapproval = $currsettings->{'selfenroll_approval'};
6193: }
6194: if ($currapproval !~ /^[012]$/) {
6195: $currapproval = 0;
6196: }
1.400 raeburn 6197: if ($noedit{$item}) {
6198: $output .= $selfdescs{'approval'}{$currapproval}.
6199: '<br />'.&mt('(Set by Domain Coordinator)');
6200: next;
6201: }
1.398 raeburn 6202: $appchecked{$currapproval} = ' checked="checked"';
6203: for my $i (0..2) {
6204: $output .= '<label>'.
6205: '<input type="radio" name="selfenroll_approval" value="'.$i.'"'.
1.406.2.6 raeburn 6206: $appchecked{$i}.' onclick="toggleNotify();"'.$disabled.' />'.
6207: $selfdescs{'approval'}{$i}.'</label>'.(' 'x2);
1.276 raeburn 6208: }
6209: my %advhash = &Apache::lonnet::get_course_adv_roles($cid,1);
6210: my (@ccs,%notified);
1.322 raeburn 6211: my $ccrole = 'cc';
6212: if ($crstype eq 'Community') {
6213: $ccrole = 'co';
6214: }
6215: if ($advhash{$ccrole}) {
6216: @ccs = split(/,/,$advhash{$ccrole});
1.276 raeburn 6217: }
6218: if ($currnotified) {
6219: foreach my $current (split(/,/,$currnotified)) {
6220: $notified{$current} = 1;
6221: if (!grep(/^\Q$current\E$/,@ccs)) {
6222: push(@ccs,$current);
6223: }
6224: }
6225: }
6226: if (@ccs) {
1.398 raeburn 6227: my $style;
6228: unless ($currapproval) {
6229: $style = ' style="display: none;"';
6230: }
6231: $output .= '<br /><div id="notified"'.$style.'>'.
6232: &mt('Personnel to be notified when an enrollment request needs approval, or has been approved:').' '.
6233: &Apache::loncommon::start_data_table().
1.276 raeburn 6234: &Apache::loncommon::start_data_table_row();
6235: my $count = 0;
6236: my $numcols = 4;
6237: foreach my $cc (sort(@ccs)) {
6238: my $notifyon;
6239: my ($ccuname,$ccudom) = split(/:/,$cc);
6240: if ($notified{$cc}) {
6241: $notifyon = ' checked="checked" ';
6242: }
6243: if ($count && !$count%$numcols) {
6244: $output .= &Apache::loncommon::end_data_table_row().
6245: &Apache::loncommon::start_data_table_row()
6246: }
6247: $output .= '<td><span class="LC_nobreak"><label>'.
1.406.2.6 raeburn 6248: '<input type="checkbox" name="selfenroll_notify"'.$notifyon.' value="'.$cc.'"'.$disabled.' />'.
1.276 raeburn 6249: &Apache::loncommon::plainname($ccuname,$ccudom).
6250: '</label></span></td>';
1.343 raeburn 6251: $count ++;
1.276 raeburn 6252: }
6253: my $rem = $count%$numcols;
6254: if ($rem) {
6255: my $emptycols = $numcols - $rem;
6256: for (my $i=0; $i<$emptycols; $i++) {
6257: $output .= '<td> </td>';
6258: }
6259: }
6260: $output .= &Apache::loncommon::end_data_table_row().
1.398 raeburn 6261: &Apache::loncommon::end_data_table().
6262: '</div>';
1.276 raeburn 6263: }
6264: } elsif ($item eq 'limit') {
1.398 raeburn 6265: my ($crslimit,$selflimit,$nolimit,$currlim,$currcap);
6266: if (ref($currsettings) eq 'HASH') {
6267: $currlim = $currsettings->{'selfenroll_limit'};
6268: $currcap = $currsettings->{'selfenroll_cap'};
6269: }
1.400 raeburn 6270: if ($noedit{$item}) {
6271: if (($currlim eq 'allstudents') || ($currlim eq 'selfenrolled')) {
6272: if ($currlim eq 'allstudents') {
6273: $output .= &mt('Limit by total students');
6274: } elsif ($currlim eq 'selfenrolled') {
6275: $output .= &mt('Limit by total self-enrolled students');
6276: }
6277: $output .= ' '.&mt('Maximum: [_1]',$currcap).
6278: '<br />'.&mt('(Set by Domain Coordinator)');
6279: } else {
6280: $output .= &mt('No limit').'<br />'.&mt('(Set by Domain Coordinator)');
6281: }
6282: next;
6283: }
1.276 raeburn 6284: if ($currlim eq 'allstudents') {
6285: $crslimit = ' checked="checked" ';
6286: $selflimit = ' ';
6287: $nolimit = ' ';
6288: } elsif ($currlim eq 'selfenrolled') {
6289: $crslimit = ' ';
6290: $selflimit = ' checked="checked" ';
6291: $nolimit = ' ';
6292: } else {
6293: $crslimit = ' ';
6294: $selflimit = ' ';
1.398 raeburn 6295: $nolimit = ' checked="checked" ';
1.276 raeburn 6296: }
6297: $output .= '<table><tr><td><label>'.
1.406.2.6 raeburn 6298: '<input type="radio" name="selfenroll_limit" value="none"'.$nolimit.$disabled.'/>'.
1.276 raeburn 6299: &mt('No limit').'</label></td><td><label>'.
1.406.2.6 raeburn 6300: '<input type="radio" name="selfenroll_limit" value="allstudents"'.$crslimit.$disabled.'/>'.
1.276 raeburn 6301: &mt('Limit by total students').'</label></td><td><label>'.
1.406.2.6 raeburn 6302: '<input type="radio" name="selfenroll_limit" value="selfenrolled"'.$selflimit.$disabled.'/>'.
1.276 raeburn 6303: &mt('Limit by total self-enrolled students').
6304: '</td></tr><tr>'.
6305: '<td> </td><td colspan="2"><span class="LC_nobreak">'.
6306: (' 'x3).&mt('Maximum number allowed: ').
1.406.2.6 raeburn 6307: '<input type="text" name="selfenroll_cap" size = "5" value="'.$currcap.'"'.$disabled.' /></td></tr></table>';
1.237 raeburn 6308: }
6309: $output .= &Apache::lonhtmlcommon::row_closure(1);
6310: }
6311: }
1.406.2.6 raeburn 6312: $output .= &Apache::lonhtmlcommon::end_pick_box().'<br />';
6313: unless ($readonly) {
6314: $output .= '<input type="button" name="selfenrollconf" value="'
6315: .&mt('Save').'" onclick="validate_types(this.form);" />';
6316: }
6317: $output .= '<input type="hidden" name="action" value="selfenroll" />'
1.406.2.11 raeburn 6318: .'<input type="hidden" name="state" value="done" />'."\n"
6319: .$additional.'</form>';
1.237 raeburn 6320: $r->print($output);
6321: return;
6322: }
6323:
1.400 raeburn 6324: sub get_noedit_fields {
6325: my ($cdom,$cnum,$crstype,$row) = @_;
6326: my %noedit;
6327: if (ref($row) eq 'ARRAY') {
6328: my %settings = &Apache::lonnet::get('environment',['internal.coursecode','internal.textbook',
6329: 'internal.selfenrollmgrdc',
6330: 'internal.selfenrollmgrcc'],$cdom,$cnum);
6331: my $type = &Apache::lonuserutils::get_extended_type($cdom,$cnum,$crstype,\%settings);
6332: my (%specific_managebydc,%specific_managebycc,%default_managebydc);
6333: map { $specific_managebydc{$_} = 1; } (split(/,/,$settings{'internal.selfenrollmgrdc'}));
6334: map { $specific_managebycc{$_} = 1; } (split(/,/,$settings{'internal.selfenrollmgrcc'}));
6335: my %domdefaults = &Apache::lonnet::get_domain_defaults($cdom);
6336: map { $default_managebydc{$_} = 1; } (split(/,/,$domdefaults{$type.'selfenrolladmdc'}));
6337:
6338: foreach my $item (@{$row}) {
6339: next if ($specific_managebycc{$item});
6340: if (($specific_managebydc{$item}) || ($default_managebydc{$item})) {
6341: $noedit{$item} = 1;
6342: }
6343: }
6344: }
6345: return %noedit;
6346: }
6347:
6348: sub visible_in_stdcat {
6349: my ($cdom,$cnum,$domconf) = @_;
6350: my ($cathash,%settable,@vismsgs,$cansetvis,$visible);
6351: unless (ref($domconf) eq 'HASH') {
6352: return ($visible,$cansetvis,\@vismsgs);
6353: }
6354: if (ref($domconf->{'coursecategories'}) eq 'HASH') {
6355: if ($domconf->{'coursecategories'}{'togglecats'} eq 'crs') {
1.256 raeburn 6356: $settable{'togglecats'} = 1;
6357: }
1.400 raeburn 6358: if ($domconf->{'coursecategories'}{'categorize'} eq 'crs') {
1.256 raeburn 6359: $settable{'categorize'} = 1;
6360: }
1.400 raeburn 6361: $cathash = $domconf->{'coursecategories'}{'cats'};
1.256 raeburn 6362: }
1.260 raeburn 6363: if ($settable{'togglecats'} && $settable{'categorize'}) {
1.256 raeburn 6364: $cansetvis = &mt('You are able to both assign a course category and choose to exclude this course from the catalog.');
6365: } elsif ($settable{'togglecats'}) {
6366: $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 6367: } elsif ($settable{'categorize'}) {
1.256 raeburn 6368: $cansetvis = &mt('You may assign a course category, but only a Domain Coordinator may choose to exclude this course from the catalog.');
6369: } else {
6370: $cansetvis = &mt('Only a Domain Coordinator may assign a course category or choose to exclude this course from the catalog.');
6371: }
6372:
6373: my %currsettings =
6374: &Apache::lonnet::get('environment',['hidefromcat','categories','internal.coursecode'],
6375: $cdom,$cnum);
1.400 raeburn 6376: $visible = 0;
1.256 raeburn 6377: if ($currsettings{'internal.coursecode'} ne '') {
1.400 raeburn 6378: if (ref($domconf->{'coursecategories'}) eq 'HASH') {
6379: $cathash = $domconf->{'coursecategories'}{'cats'};
1.256 raeburn 6380: if (ref($cathash) eq 'HASH') {
6381: if ($cathash->{'instcode::0'} eq '') {
6382: push(@vismsgs,'dc_addinst');
6383: } else {
6384: $visible = 1;
6385: }
6386: } else {
6387: $visible = 1;
6388: }
6389: } else {
6390: $visible = 1;
6391: }
6392: } else {
6393: if (ref($cathash) eq 'HASH') {
6394: if ($cathash->{'instcode::0'} ne '') {
6395: push(@vismsgs,'dc_instcode');
6396: }
6397: } else {
6398: push(@vismsgs,'dc_instcode');
6399: }
6400: }
6401: if ($currsettings{'categories'} ne '') {
6402: my $cathash;
1.400 raeburn 6403: if (ref($domconf->{'coursecategories'}) eq 'HASH') {
6404: $cathash = $domconf->{'coursecategories'}{'cats'};
1.256 raeburn 6405: if (ref($cathash) eq 'HASH') {
6406: if (keys(%{$cathash}) == 0) {
6407: push(@vismsgs,'dc_catalog');
6408: } elsif ((keys(%{$cathash}) == 1) && ($cathash->{'instcode::0'} ne '')) {
6409: push(@vismsgs,'dc_categories');
6410: } else {
6411: my @currcategories = split('&',$currsettings{'categories'});
6412: my $matched = 0;
6413: foreach my $cat (@currcategories) {
6414: if ($cathash->{$cat} ne '') {
6415: $visible = 1;
6416: $matched = 1;
6417: last;
6418: }
6419: }
6420: if (!$matched) {
1.260 raeburn 6421: if ($settable{'categorize'}) {
1.256 raeburn 6422: push(@vismsgs,'chgcat');
6423: } else {
6424: push(@vismsgs,'dc_chgcat');
6425: }
6426: }
6427: }
6428: }
6429: }
6430: } else {
6431: if (ref($cathash) eq 'HASH') {
6432: if ((keys(%{$cathash}) > 1) ||
6433: (keys(%{$cathash}) == 1) && ($cathash->{'instcode::0'} eq '')) {
1.260 raeburn 6434: if ($settable{'categorize'}) {
1.256 raeburn 6435: push(@vismsgs,'addcat');
6436: } else {
6437: push(@vismsgs,'dc_addcat');
6438: }
6439: }
6440: }
6441: }
6442: if ($currsettings{'hidefromcat'} eq 'yes') {
6443: $visible = 0;
6444: if ($settable{'togglecats'}) {
6445: unshift(@vismsgs,'unhide');
6446: } else {
6447: unshift(@vismsgs,'dc_unhide')
6448: }
6449: }
1.400 raeburn 6450: return ($visible,$cansetvis,\@vismsgs);
6451: }
6452:
6453: sub cat_visibility {
6454: my %visactions = &Apache::lonlocal::texthash(
6455: vis => 'This course/community currently appears in the Course/Community Catalog for this domain.',
6456: 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.',
6457: miss => 'This course/community does not currently appear in the Course/Community Catalog for this domain.',
6458: none => 'Display of a course catalog is disabled for this domain.',
6459: yous => 'You should remedy this if you plan to allow self-enrollment, otherwise students will have difficulty finding this course.',
6460: 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.',
6461: make => 'Make any changes to self-enrollment settings below, click "Save", then take action to include the course in the Catalog:',
6462: take => 'Take the following action to ensure the course appears in the Catalog:',
6463: dc_chgconf => 'Ask a domain coordinator to change the Catalog type for this domain.',
6464: dc_setcode => 'Ask a domain coordinator to assign a six character code to the course',
6465: dc_unhide => 'Ask a domain coordinator to change the "Exclude from course catalog" setting.',
6466: dc_addinst => 'Ask a domain coordinator to enable display the catalog of "Official courses (with institutional codes)".',
6467: dc_instcode => 'Ask a domain coordinator to assign an institutional code (if this is an official course).',
6468: dc_catalog => 'Ask a domain coordinator to enable or create at least one course category in the domain.',
6469: dc_categories => 'Ask a domain coordinator to create a hierarchy of categories and sub categories for courses in the domain.',
6470: 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',
6471: dc_addcat => 'Ask a domain coordinator to assign a category to the course.',
6472: );
6473: $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>"');
6474: $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>"');
6475: $visactions{'addcat'} = &mt('Use [_1]Categorize course[_2] to assign a category to the course.','"<a href="/adm/courseprefs?phase=display&actions=courseinfo">','</a>"');
6476: return \%visactions;
1.256 raeburn 6477: }
6478:
1.241 raeburn 6479: sub new_selfenroll_dom_row {
6480: my ($newdom,$num) = @_;
6481: my $domdesc = &Apache::lonnet::domain($newdom);
6482: my $output;
6483: if ($domdesc ne '') {
6484: $output .= &Apache::loncommon::start_data_table_row()
6485: .'<td valign="top"><span class="LC_nobreak">'.&mt('Domain:').' <b>'.$domdesc
6486: .' ('.$newdom.')</b><input type="hidden" name="selfenroll_dom_'.$num
1.249 raeburn 6487: .'" value="'.$newdom.'" /></span><br />'
6488: .'<span class="LC_nobreak"><label><input type="checkbox" '
6489: .'name="selfenroll_activate" value="'.$num.'" '
6490: .'onchange="javascript:update_types('
6491: ."'selfenroll_activate','$num'".');" />'
6492: .&mt('Activate').'</label></span></td>';
1.241 raeburn 6493: my @currinsttypes;
6494: $output .= '<td>'.&mt('User types:').'<br />'
6495: .&selfenroll_inst_types($num,$newdom,\@currinsttypes).'</td>'
6496: .&Apache::loncommon::end_data_table_row();
6497: }
6498: return $output;
6499: }
6500:
6501: sub selfenroll_inst_types {
1.406.2.6 raeburn 6502: my ($num,$currdom,$currinsttypes,$readonly) = @_;
1.241 raeburn 6503: my $output;
6504: my $numinrow = 4;
6505: my $count = 0;
6506: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($currdom);
1.247 raeburn 6507: my $othervalue = 'any';
1.406.2.6 raeburn 6508: my $disabled;
6509: if ($readonly) {
6510: $disabled = ' disabled="disabled"';
6511: }
1.241 raeburn 6512: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
1.251 raeburn 6513: if (keys(%{$usertypes}) > 0) {
1.247 raeburn 6514: $othervalue = 'other';
6515: }
1.241 raeburn 6516: $output .= '<table><tr>';
6517: foreach my $type (@{$types}) {
6518: if (($count > 0) && ($count%$numinrow == 0)) {
6519: $output .= '</tr><tr>';
6520: }
6521: if (defined($usertypes->{$type})) {
1.257 raeburn 6522: my $esc_type = &escape($type);
1.241 raeburn 6523: $output .= '<td><span class="LC_nobreak"><label><input type = "checkbox" value="'.
1.257 raeburn 6524: $esc_type.'" ';
1.241 raeburn 6525: if (ref($currinsttypes) eq 'ARRAY') {
6526: if (@{$currinsttypes} > 0) {
1.249 raeburn 6527: if (grep(/^any$/,@{$currinsttypes})) {
6528: $output .= 'checked="checked"';
1.257 raeburn 6529: } elsif (grep(/^\Q$esc_type\E$/,@{$currinsttypes})) {
1.241 raeburn 6530: $output .= 'checked="checked"';
6531: }
1.249 raeburn 6532: } else {
6533: $output .= 'checked="checked"';
1.241 raeburn 6534: }
6535: }
1.406.2.6 raeburn 6536: $output .= ' name="selfenroll_types_'.$num.'"'.$disabled.' />'.$usertypes->{$type}.'</label></span></td>';
1.241 raeburn 6537: }
6538: $count ++;
6539: }
6540: if (($count > 0) && ($count%$numinrow == 0)) {
6541: $output .= '</tr><tr>';
6542: }
1.249 raeburn 6543: $output .= '<td><span class="LC_nobreak"><label><input type = "checkbox" value="'.$othervalue.'"';
1.241 raeburn 6544: if (ref($currinsttypes) eq 'ARRAY') {
6545: if (@{$currinsttypes} > 0) {
1.249 raeburn 6546: if (grep(/^any$/,@{$currinsttypes})) {
6547: $output .= ' checked="checked"';
6548: } elsif ($othervalue eq 'other') {
6549: if (grep(/^\Q$othervalue\E$/,@{$currinsttypes})) {
6550: $output .= ' checked="checked"';
6551: }
1.241 raeburn 6552: }
1.249 raeburn 6553: } else {
6554: $output .= ' checked="checked"';
1.241 raeburn 6555: }
1.249 raeburn 6556: } else {
6557: $output .= ' checked="checked"';
1.241 raeburn 6558: }
1.406.2.6 raeburn 6559: $output .= ' name="selfenroll_types_'.$num.'"'.$disabled.' />'.$othertitle.'</label></span></td></tr></table>';
1.241 raeburn 6560: }
6561: return $output;
6562: }
6563:
1.237 raeburn 6564: sub selfenroll_date_forms {
6565: my ($startform,$endform) = @_;
6566: my $output .= &Apache::lonhtmlcommon::start_pick_box()."\n".
1.244 bisitz 6567: &Apache::lonhtmlcommon::row_title(&mt('Start date'),
1.237 raeburn 6568: 'LC_oddrow_value')."\n".
6569: $startform."\n".
6570: &Apache::lonhtmlcommon::row_closure(1).
1.244 bisitz 6571: &Apache::lonhtmlcommon::row_title(&mt('End date'),
1.237 raeburn 6572: 'LC_oddrow_value')."\n".
6573: $endform."\n".
6574: &Apache::lonhtmlcommon::row_closure(1).
6575: &Apache::lonhtmlcommon::end_pick_box();
6576: return $output;
6577: }
6578:
1.239 raeburn 6579: sub print_userchangelogs_display {
1.406.2.5 raeburn 6580: my ($r,$context,$permission,$brcrum) = @_;
1.363 raeburn 6581: my $formname = 'rolelog';
1.406.2.6 raeburn 6582: my ($username,$domain,$crstype,$viewablesec,%roleslog);
1.363 raeburn 6583: if ($context eq 'domain') {
6584: $domain = $env{'request.role.domain'};
6585: %roleslog=&Apache::lonnet::dump_dom('nohist_rolelog',$domain);
6586: } else {
6587: if ($context eq 'course') {
6588: $domain = $env{'course.'.$env{'request.course.id'}.'.domain'};
6589: $username = $env{'course.'.$env{'request.course.id'}.'.num'};
6590: $crstype = &Apache::loncommon::course_type();
1.406.2.6 raeburn 6591: $viewablesec = &Apache::lonuserutils::viewable_section($permission);
1.363 raeburn 6592: my %saveable_parameters = ('show' => 'scalar',);
6593: &Apache::loncommon::store_course_settings('roles_log',
6594: \%saveable_parameters);
6595: &Apache::loncommon::restore_course_settings('roles_log',
6596: \%saveable_parameters);
6597: } elsif ($context eq 'author') {
6598: $domain = $env{'user.domain'};
6599: if ($env{'request.role'} =~ m{^au\./\Q$domain\E/$}) {
6600: $username = $env{'user.name'};
6601: } else {
6602: undef($domain);
6603: }
6604: }
6605: if ($domain ne '' && $username ne '') {
6606: %roleslog=&Apache::lonnet::dump('nohist_rolelog',$domain,$username);
6607: }
6608: }
1.239 raeburn 6609: if ((keys(%roleslog))[0]=~/^error\:/) { undef(%roleslog); }
6610:
1.406.2.5 raeburn 6611: my $helpitem;
6612: if ($context eq 'course') {
6613: $helpitem = 'Course_User_Logs';
1.406.2.14 raeburn 6614: } elsif ($context eq 'domain') {
6615: $helpitem = 'Domain_Role_Logs';
6616: } elsif ($context eq 'author') {
6617: $helpitem = 'Author_User_Logs';
1.406.2.5 raeburn 6618: }
6619: push (@{$brcrum},
6620: {href => '/adm/createuser?action=changelogs',
6621: text => 'User Management Logs',
6622: help => $helpitem});
6623: my $bread_crumbs_component = 'User Changes';
6624: my $args = { bread_crumbs => $brcrum,
6625: bread_crumbs_component => $bread_crumbs_component};
6626:
6627: # Create navigation javascript
6628: my $jsnav = &userlogdisplay_js($formname);
6629:
6630: my $jscript = (<<ENDSCRIPT);
6631: <script type="text/javascript">
6632: // <![CDATA[
6633: $jsnav
6634: // ]]>
6635: </script>
6636: ENDSCRIPT
6637:
6638: # print page header
6639: $r->print(&header($jscript,$args));
6640:
1.239 raeburn 6641: # set defaults
6642: my $now = time();
6643: my $defstart = $now - (7*24*3600); #7 days ago
6644: my %defaults = (
6645: page => '1',
6646: show => '10',
6647: role => 'any',
6648: chgcontext => 'any',
6649: rolelog_start_date => $defstart,
6650: rolelog_end_date => $now,
6651: );
6652: my $more_records = 0;
6653:
6654: # set current
6655: my %curr;
6656: foreach my $item ('show','page','role','chgcontext') {
6657: $curr{$item} = $env{'form.'.$item};
6658: }
6659: my ($startdate,$enddate) =
6660: &Apache::lonuserutils::get_dates_from_form('rolelog_start_date','rolelog_end_date');
6661: $curr{'rolelog_start_date'} = $startdate;
6662: $curr{'rolelog_end_date'} = $enddate;
6663: foreach my $key (keys(%defaults)) {
6664: if ($curr{$key} eq '') {
6665: $curr{$key} = $defaults{$key};
6666: }
6667: }
1.248 raeburn 6668: my (%whodunit,%changed,$version);
6669: ($version) = ($r->dir_config('lonVersion') =~ /^([\d\.]+)\-/);
1.239 raeburn 6670: my ($minshown,$maxshown);
1.255 raeburn 6671: $minshown = 1;
1.239 raeburn 6672: my $count = 0;
1.406.2.5 raeburn 6673: if ($curr{'show'} =~ /\D/) {
6674: $curr{'page'} = 1;
6675: } else {
1.239 raeburn 6676: $maxshown = $curr{'page'} * $curr{'show'};
6677: if ($curr{'page'} > 1) {
6678: $minshown = 1 + ($curr{'page'} - 1) * $curr{'show'};
6679: }
6680: }
1.301 bisitz 6681:
1.327 raeburn 6682: # Form Header
6683: $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">'.
1.363 raeburn 6684: &role_display_filter($context,$formname,$domain,$username,\%curr,
6685: $version,$crstype));
1.327 raeburn 6686:
6687: my $showntableheader = 0;
6688:
6689: # Table Header
6690: my $tableheader =
6691: &Apache::loncommon::start_data_table_header_row()
6692: .'<th> </th>'
6693: .'<th>'.&mt('When').'</th>'
6694: .'<th>'.&mt('Who made the change').'</th>'
6695: .'<th>'.&mt('Changed User').'</th>'
1.363 raeburn 6696: .'<th>'.&mt('Role').'</th>';
6697:
6698: if ($context eq 'course') {
6699: $tableheader .= '<th>'.&mt('Section').'</th>';
6700: }
6701: $tableheader .=
6702: '<th>'.&mt('Context').'</th>'
1.327 raeburn 6703: .'<th>'.&mt('Start').'</th>'
6704: .'<th>'.&mt('End').'</th>'
6705: .&Apache::loncommon::end_data_table_header_row();
6706:
6707: # Display user change log data
1.239 raeburn 6708: foreach my $id (sort { $roleslog{$b}{'exe_time'}<=>$roleslog{$a}{'exe_time'} } (keys(%roleslog))) {
6709: next if (($roleslog{$id}{'exe_time'} < $curr{'rolelog_start_date'}) ||
6710: ($roleslog{$id}{'exe_time'} > $curr{'rolelog_end_date'}));
1.406.2.5 raeburn 6711: if ($curr{'show'} !~ /\D/) {
1.239 raeburn 6712: if ($count >= $curr{'page'} * $curr{'show'}) {
6713: $more_records = 1;
6714: last;
6715: }
6716: }
6717: if ($curr{'role'} ne 'any') {
6718: next if ($roleslog{$id}{'logentry'}{'role'} ne $curr{'role'});
6719: }
6720: if ($curr{'chgcontext'} ne 'any') {
6721: if ($curr{'chgcontext'} eq 'selfenroll') {
6722: next if (!$roleslog{$id}{'logentry'}{'selfenroll'});
6723: } else {
6724: next if ($roleslog{$id}{'logentry'}{'context'} ne $curr{'chgcontext'});
6725: }
6726: }
1.406.2.6 raeburn 6727: if (($context eq 'course') && ($viewablesec ne '')) {
6728: next if ($roleslog{$id}{'logentry'}{'section'} ne $viewablesec);
6729: }
1.239 raeburn 6730: $count ++;
6731: next if ($count < $minshown);
1.327 raeburn 6732: unless ($showntableheader) {
1.406.2.5 raeburn 6733: $r->print(&Apache::loncommon::start_data_table()
1.327 raeburn 6734: .$tableheader);
6735: $r->rflush();
6736: $showntableheader = 1;
6737: }
1.239 raeburn 6738: if ($whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}} eq '') {
6739: $whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}} =
6740: &Apache::loncommon::plainname($roleslog{$id}{'exe_uname'},$roleslog{$id}{'exe_udom'});
6741: }
6742: if ($changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}} eq '') {
6743: $changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}} =
6744: &Apache::loncommon::plainname($roleslog{$id}{'uname'},$roleslog{$id}{'udom'});
6745: }
6746: my $sec = $roleslog{$id}{'logentry'}{'section'};
6747: if ($sec eq '') {
6748: $sec = &mt('None');
6749: }
6750: my ($rolestart,$roleend);
6751: if ($roleslog{$id}{'delflag'}) {
6752: $rolestart = &mt('deleted');
6753: $roleend = &mt('deleted');
6754: } else {
6755: $rolestart = $roleslog{$id}{'logentry'}{'start'};
6756: $roleend = $roleslog{$id}{'logentry'}{'end'};
6757: if ($rolestart eq '' || $rolestart == 0) {
6758: $rolestart = &mt('No start date');
6759: } else {
6760: $rolestart = &Apache::lonlocal::locallocaltime($rolestart);
6761: }
6762: if ($roleend eq '' || $roleend == 0) {
6763: $roleend = &mt('No end date');
6764: } else {
6765: $roleend = &Apache::lonlocal::locallocaltime($roleend);
6766: }
6767: }
6768: my $chgcontext = $roleslog{$id}{'logentry'}{'context'};
6769: if ($roleslog{$id}{'logentry'}{'selfenroll'}) {
6770: $chgcontext = 'selfenroll';
6771: }
1.363 raeburn 6772: my %lt = &rolechg_contexts($context,$crstype);
1.239 raeburn 6773: if ($chgcontext ne '' && $lt{$chgcontext} ne '') {
6774: $chgcontext = $lt{$chgcontext};
6775: }
1.327 raeburn 6776: $r->print(
1.301 bisitz 6777: &Apache::loncommon::start_data_table_row()
6778: .'<td>'.$count.'</td>'
6779: .'<td>'.&Apache::lonlocal::locallocaltime($roleslog{$id}{'exe_time'}).'</td>'
6780: .'<td>'.$whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}}.'</td>'
6781: .'<td>'.$changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}}.'</td>'
1.363 raeburn 6782: .'<td>'.&Apache::lonnet::plaintext($roleslog{$id}{'logentry'}{'role'},$crstype).'</td>');
6783: if ($context eq 'course') {
6784: $r->print('<td>'.$sec.'</td>');
6785: }
6786: $r->print(
6787: '<td>'.$chgcontext.'</td>'
1.301 bisitz 6788: .'<td>'.$rolestart.'</td>'
6789: .'<td>'.$roleend.'</td>'
1.327 raeburn 6790: .&Apache::loncommon::end_data_table_row()."\n");
1.301 bisitz 6791: }
6792:
1.327 raeburn 6793: if ($showntableheader) { # Table footer, if content displayed above
1.406.2.5 raeburn 6794: $r->print(&Apache::loncommon::end_data_table().
6795: &userlogdisplay_navlinks(\%curr,$more_records));
1.327 raeburn 6796: } else { # No content displayed above
1.301 bisitz 6797: $r->print('<p class="LC_info">'
6798: .&mt('There are no records to display.')
6799: .'</p>'
6800: );
1.239 raeburn 6801: }
1.301 bisitz 6802:
1.327 raeburn 6803: # Form Footer
6804: $r->print(
6805: '<input type="hidden" name="page" value="'.$curr{'page'}.'" />'
6806: .'<input type="hidden" name="action" value="changelogs" />'
6807: .'</form>');
6808: return;
6809: }
1.301 bisitz 6810:
1.406.2.5 raeburn 6811: sub print_useraccesslogs_display {
6812: my ($r,$uname,$udom,$permission,$brcrum) = @_;
6813: my $formname = 'accesslog';
6814: my $form = 'document.accesslog';
6815:
6816: # set breadcrumbs
1.406.2.7 raeburn 6817: my %breadcrumb_text = &singleuser_breadcrumb('','domain',$udom);
1.406.2.12 raeburn 6818: my $prevphasestr;
6819: if ($env{'form.popup'}) {
6820: $brcrum = [];
6821: } else {
6822: push (@{$brcrum},
6823: {href => "javascript:backPage($form)",
6824: text => $breadcrumb_text{'search'}});
6825: my @prevphases;
6826: if ($env{'form.prevphases'}) {
6827: @prevphases = split(/,/,$env{'form.prevphases'});
6828: $prevphasestr = $env{'form.prevphases'};
6829: }
6830: if (($env{'form.phase'} eq 'userpicked') || (grep(/^userpicked$/,@prevphases))) {
6831: push(@{$brcrum},
6832: {href => "javascript:backPage($form,'get_user_info','select')",
6833: text => $breadcrumb_text{'userpicked'}});
6834: if ($env{'form.phase'} eq 'userpicked') {
6835: $prevphasestr = 'userpicked';
6836: }
1.406.2.5 raeburn 6837: }
6838: }
6839: push(@{$brcrum},
6840: {href => '/adm/createuser?action=accesslogs',
6841: text => 'User access logs',
1.406.2.8 raeburn 6842: help => 'Domain_User_Access_Logs'});
1.406.2.5 raeburn 6843: my $bread_crumbs_component = 'User Access Logs';
6844: my $args = { bread_crumbs => $brcrum,
6845: bread_crumbs_component => 'User Management'};
1.406.2.8 raeburn 6846: if ($env{'form.popup'}) {
6847: $args->{'no_nav_bar'} = 1;
1.406.2.12 raeburn 6848: $args->{'bread_crumbs_nomenu'} = 1;
1.406.2.8 raeburn 6849: }
1.406.2.5 raeburn 6850:
6851: # set javascript
6852: my ($jsback,$elements) = &crumb_utilities();
6853: my $jsnav = &userlogdisplay_js($formname);
6854:
6855: my $jscript = (<<ENDSCRIPT);
1.239 raeburn 6856: <script type="text/javascript">
1.301 bisitz 6857: // <![CDATA[
1.406.2.5 raeburn 6858:
6859: $jsback
6860: $jsnav
6861:
6862: // ]]>
6863: </script>
6864:
6865: ENDSCRIPT
6866:
6867: # print page header
6868: $r->print(&header($jscript,$args));
6869:
6870: # early out unless log data can be displayed.
6871: unless ($permission->{'activity'}) {
6872: $r->print('<p class="LC_warning">'
6873: .&mt('You do not have rights to display user access logs.')
1.406.2.12 raeburn 6874: .'</p>');
6875: if ($env{'form.popup'}) {
6876: $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a></p>');
6877: } else {
6878: $r->print(&earlyout_accesslog_form($formname,$prevphasestr,$udom));
6879: }
1.406.2.5 raeburn 6880: return;
6881: }
6882:
6883: unless ($udom eq $env{'request.role.domain'}) {
6884: $r->print('<p class="LC_warning">'
6885: .&mt("User's domain must match role's domain")
6886: .'</p>'
6887: .&earlyout_accesslog_form($formname,$prevphasestr,$udom));
6888: return;
6889: }
6890:
6891: if (($uname eq '') || ($udom eq '')) {
6892: $r->print('<p class="LC_warning">'
6893: .&mt('Invalid username or domain')
6894: .'</p>'
6895: .&earlyout_accesslog_form($formname,$prevphasestr,$udom));
6896: return;
6897: }
6898:
1.406.2.13 raeburn 6899: if (&Apache::lonnet::privileged($uname,$udom,
6900: [$env{'request.role.domain'}],['dc','su'])) {
6901: unless (&Apache::lonnet::privileged($env{'user.name'},$env{'user.domain'},
6902: [$env{'request.role.domain'}],['dc','su'])) {
6903: $r->print('<p class="LC_warning">'
6904: .&mt('You need to be a privileged user to display user access logs for [_1]',
6905: &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),
6906: $uname,$udom))
6907: .'</p>');
6908: if ($env{'form.popup'}) {
6909: $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a></p>');
6910: } else {
6911: $r->print(&earlyout_accesslog_form($formname,$prevphasestr,$udom));
6912: }
6913: return;
6914: }
6915: }
6916:
1.406.2.5 raeburn 6917: # set defaults
6918: my $now = time();
6919: my $defstart = $now - (7*24*3600);
6920: my %defaults = (
6921: page => '1',
6922: show => '10',
6923: activity => 'any',
6924: accesslog_start_date => $defstart,
6925: accesslog_end_date => $now,
6926: );
6927: my $more_records = 0;
6928:
6929: # set current
6930: my %curr;
6931: foreach my $item ('show','page','activity') {
6932: $curr{$item} = $env{'form.'.$item};
6933: }
6934: my ($startdate,$enddate) =
6935: &Apache::lonuserutils::get_dates_from_form('accesslog_start_date','accesslog_end_date');
6936: $curr{'accesslog_start_date'} = $startdate;
6937: $curr{'accesslog_end_date'} = $enddate;
6938: foreach my $key (keys(%defaults)) {
6939: if ($curr{$key} eq '') {
6940: $curr{$key} = $defaults{$key};
6941: }
6942: }
6943: my ($minshown,$maxshown);
6944: $minshown = 1;
6945: my $count = 0;
6946: if ($curr{'show'} =~ /\D/) {
6947: $curr{'page'} = 1;
6948: } else {
6949: $maxshown = $curr{'page'} * $curr{'show'};
6950: if ($curr{'page'} > 1) {
6951: $minshown = 1 + ($curr{'page'} - 1) * $curr{'show'};
6952: }
6953: }
6954:
6955: # form header
6956: $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">'.
6957: &activity_display_filter($formname,\%curr));
6958:
6959: my $showntableheader = 0;
6960: my ($nav_script,$nav_links);
6961:
6962: # table header
1.406.2.12 raeburn 6963: my $tableheader = '<h3>'.
6964: &mt('User access logs for: [_1]',
6965: &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),$uname,$udom)).'</h3>'
6966: .&Apache::loncommon::start_data_table_header_row()
1.406.2.5 raeburn 6967: .'<th> </th>'
6968: .'<th>'.&mt('When').'</th>'
6969: .'<th>'.&mt('HostID').'</th>'
6970: .'<th>'.&mt('Event').'</th>'
6971: .'<th>'.&mt('Other data').'</th>'
6972: .&Apache::loncommon::end_data_table_header_row();
6973:
6974: my %filters=(
6975: start => $curr{'accesslog_start_date'},
6976: end => $curr{'accesslog_end_date'},
6977: action => $curr{'activity'},
6978: );
6979:
6980: my $reply = &Apache::lonnet::userlog_query($uname,$udom,%filters);
6981: unless ( ($reply =~/^timeout/) || ($reply =~/^error/) ) {
6982: my (%courses,%missing);
6983: my @results = split(/\&/,$reply);
6984: foreach my $item (reverse(@results)) {
6985: my ($timestamp,$host,$event) = split(/:/,$item);
6986: next unless ($event =~ /^(Log|Role)/);
6987: if ($curr{'show'} !~ /\D/) {
6988: if ($count >= $curr{'page'} * $curr{'show'}) {
6989: $more_records = 1;
6990: last;
6991: }
6992: }
6993: $count ++;
6994: next if ($count < $minshown);
6995: unless ($showntableheader) {
6996: $r->print($nav_script
6997: .&Apache::loncommon::start_data_table()
6998: .$tableheader);
6999: $r->rflush();
7000: $showntableheader = 1;
7001: }
1.406.2.6 raeburn 7002: my ($shown,$extra);
1.406.2.13 raeburn 7003: my ($event,$data) = split(/\s+/,&unescape($event),2);
1.406.2.5 raeburn 7004: if ($event eq 'Role') {
7005: my ($rolecode,$extent) = split(/\./,$data,2);
7006: next if ($extent eq '');
7007: my ($crstype,$desc,$info);
1.406.2.6 raeburn 7008: if ($extent =~ m{^/($match_domain)/($match_courseid)(?:/(\w+)|)$}) {
7009: my ($cdom,$cnum,$sec) = ($1,$2,$3);
1.406.2.5 raeburn 7010: my $cid = $cdom.'_'.$cnum;
7011: if (exists($courses{$cid})) {
7012: $crstype = $courses{$cid}{'type'};
7013: $desc = $courses{$cid}{'description'};
7014: } elsif ($missing{$cid}) {
7015: $crstype = 'Course';
7016: $desc = 'Course/Community';
7017: } else {
7018: my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',$cnum,undef,undef,'.');
7019: if (ref($crsinfo{$cdom.'_'.$cnum}) eq 'HASH') {
7020: $courses{$cid} = $crsinfo{$cid};
7021: $crstype = $crsinfo{$cid}{'type'};
7022: $desc = $crsinfo{$cid}{'description'};
7023: } else {
7024: $missing{$cid} = 1;
7025: }
7026: }
7027: $extra = &mt($crstype).': <a href="/public/'.$cdom.'/'.$cnum.'/syllabus">'.$desc.'</a>';
1.406.2.6 raeburn 7028: if ($sec ne '') {
7029: $extra .= ' ('.&mt('Section: [_1]',$sec).')';
7030: }
1.406.2.5 raeburn 7031: } elsif ($extent =~ m{^/($match_domain)/($match_username|$)}) {
7032: my ($dom,$name) = ($1,$2);
7033: if ($rolecode eq 'au') {
7034: $extra = '';
7035: } elsif ($rolecode =~ /^(ca|aa)$/) {
7036: $extra = &mt('Authoring Space: [_1]',$name.':'.$dom);
7037: } elsif ($rolecode =~ /^(li|dg|dh|dc|sc)$/) {
7038: $extra = &mt('Domain: [_1]',$dom);
7039: }
7040: }
7041: my $rolename;
7042: if ($rolecode =~ m{^cr/($match_domain)/($match_username)/(\w+)}) {
7043: my $role = $3;
7044: my $owner = "($2:$1)";
7045: if ($2 eq $1.'-domainconfig') {
7046: $owner = '(ad hoc)';
7047: }
7048: $rolename = &mt('Custom role: [_1]',$role.' '.$owner);
7049: } else {
7050: $rolename = &Apache::lonnet::plaintext($rolecode,$crstype);
7051: }
7052: $shown = &mt('Role selection: [_1]',$rolename);
7053: } else {
7054: $shown = &mt($event);
1.406.2.13 raeburn 7055: if ($data =~ /^webdav/) {
7056: my ($path,$clientip) = split(/\s+/,$data,2);
7057: $path =~ s/^webdav//;
7058: if ($clientip ne '') {
7059: $extra = &mt('Client IP address: [_1]',$clientip);
7060: }
7061: if ($path ne '') {
7062: $shown .= ' '.&mt('(WebDAV access to [_1])',$path);
7063: }
7064: } elsif ($data ne '') {
7065: $extra = &mt('Client IP address: [_1]',$data);
1.406.2.5 raeburn 7066: }
7067: }
7068: $r->print(
7069: &Apache::loncommon::start_data_table_row()
7070: .'<td>'.$count.'</td>'
7071: .'<td>'.&Apache::lonlocal::locallocaltime($timestamp).'</td>'
7072: .'<td>'.$host.'</td>'
7073: .'<td>'.$shown.'</td>'
7074: .'<td>'.$extra.'</td>'
7075: .&Apache::loncommon::end_data_table_row()."\n");
7076: }
7077: }
7078:
7079: if ($showntableheader) { # Table footer, if content displayed above
7080: $r->print(&Apache::loncommon::end_data_table().
7081: &userlogdisplay_navlinks(\%curr,$more_records));
7082: } else { # No content displayed above
7083: $r->print('<p class="LC_info">'
7084: .&mt('There are no records to display.')
7085: .'</p>');
7086: }
7087:
1.406.2.8 raeburn 7088: if ($env{'form.popup'} == 1) {
7089: $r->print('<input type="hidden" name="popup" value="1" />'."\n");
7090: }
7091:
1.406.2.5 raeburn 7092: # Form Footer
7093: $r->print(
7094: '<input type="hidden" name="currstate" value="" />'
7095: .'<input type="hidden" name="accessuname" value="'.$uname.'" />'
7096: .'<input type="hidden" name="accessudom" value="'.$udom.'" />'
7097: .'<input type="hidden" name="page" value="'.$curr{'page'}.'" />'
7098: .'<input type="hidden" name="prevphases" value="'.$prevphasestr.'" />'
7099: .'<input type="hidden" name="phase" value="activity" />'
7100: .'<input type="hidden" name="action" value="accesslogs" />'
7101: .'<input type="hidden" name="srchdomain" value="'.$udom.'" />'
7102: .'<input type="hidden" name="srchby" value="'.$env{'form.srchby'}.'" />'
7103: .'<input type="hidden" name="srchtype" value="'.$env{'form.srchtype'}.'" />'
7104: .'<input type="hidden" name="srchterm" value="'.&HTML::Entities::encode($env{'form.srchterm'},'<>"&').'" />'
7105: .'<input type="hidden" name="srchin" value="'.$env{'form.srchin'}.'" />'
7106: .'</form>');
7107: return;
7108: }
7109:
7110: sub earlyout_accesslog_form {
7111: my ($formname,$prevphasestr,$udom) = @_;
7112: my $srchterm = &HTML::Entities::encode($env{'form.srchterm'},'<>"&');
7113: return <<"END";
7114: <form action="/adm/createuser" method="post" name="$formname">
7115: <input type="hidden" name="currstate" value="" />
7116: <input type="hidden" name="prevphases" value="$prevphasestr" />
7117: <input type="hidden" name="phase" value="activity" />
7118: <input type="hidden" name="action" value="accesslogs" />
7119: <input type="hidden" name="srchdomain" value="$udom" />
7120: <input type="hidden" name="srchby" value="$env{'form.srchby'}" />
7121: <input type="hidden" name="srchtype" value="$env{'form.srchtype'}" />
7122: <input type="hidden" name="srchterm" value="$srchterm" />
7123: <input type="hidden" name="srchin" value="$env{'form.srchin'}" />
7124: </form>
7125: END
7126: }
7127:
7128: sub activity_display_filter {
7129: my ($formname,$curr) = @_;
7130: my $nolink = 1;
7131: my $output = '<table><tr><td valign="top">'.
7132: '<span class="LC_nobreak"><b>'.&mt('Actions/page:').'</b></span><br />'.
7133: &Apache::lonmeta::selectbox('show',$curr->{'show'},undef,
7134: (&mt('all'),5,10,20,50,100,1000,10000)).
7135: '</td><td> </td>';
7136: my $startform =
7137: &Apache::lonhtmlcommon::date_setter($formname,'accesslog_start_date',
7138: $curr->{'accesslog_start_date'},undef,
7139: undef,undef,undef,undef,undef,undef,$nolink);
7140: my $endform =
7141: &Apache::lonhtmlcommon::date_setter($formname,'accesslog_end_date',
7142: $curr->{'accesslog_end_date'},undef,
7143: undef,undef,undef,undef,undef,undef,$nolink);
7144: my %lt = &Apache::lonlocal::texthash (
7145: activity => 'Activity',
7146: Role => 'Role selection',
7147: log => 'Log-in or Logout',
7148: );
7149: $output .= '<td valign="top"><b>'.&mt('Window during which actions occurred:').'</b><br />'.
7150: '<table><tr><td>'.&mt('After:').
7151: '</td><td>'.$startform.'</td></tr>'.
7152: '<tr><td>'.&mt('Before:').'</td>'.
7153: '<td>'.$endform.'</td></tr></table>'.
7154: '</td>'.
7155: '<td> </td>'.
7156: '<td valign="top"><b>'.&mt('Activities').'</b><br />'.
7157: '<select name="activity"><option value="any"';
7158: if ($curr->{'activity'} eq 'any') {
7159: $output .= ' selected="selected"';
7160: }
7161: $output .= '>'.&mt('Any').'</option>'."\n";
7162: foreach my $activity ('Role','log') {
7163: my $selstr = '';
7164: if ($activity eq $curr->{'activity'}) {
7165: $selstr = ' selected="selected"';
7166: }
7167: $output .= '<option value="'.$activity.'"'.$selstr.'>'.$lt{$activity}.'</option>';
7168: }
7169: $output .= '</select></td>'.
7170: '</tr></table>';
7171: # Update Display button
7172: $output .= '<p>'
7173: .'<input type="submit" value="'.&mt('Update Display').'" />'
1.406.2.12 raeburn 7174: .'</p><hr />';
1.406.2.5 raeburn 7175: return $output;
7176: }
7177:
7178: sub userlogdisplay_js {
7179: my ($formname) = @_;
7180: return <<"ENDSCRIPT";
7181:
1.239 raeburn 7182: function chgPage(caller) {
7183: if (caller == 'previous') {
7184: document.$formname.page.value --;
7185: }
7186: if (caller == 'next') {
7187: document.$formname.page.value ++;
7188: }
1.327 raeburn 7189: document.$formname.submit();
1.239 raeburn 7190: return;
7191: }
7192: ENDSCRIPT
1.406.2.5 raeburn 7193: }
7194:
7195: sub userlogdisplay_navlinks {
7196: my ($curr,$more_records) = @_;
7197: return unless(ref($curr) eq 'HASH');
7198: # Navigation Buttons
7199: my $nav_links = '<p>';
7200: if (($curr->{'page'} > 1) || ($more_records)) {
7201: if (($curr->{'page'} > 1) && ($curr->{'show'} !~ /\D/)) {
7202: $nav_links .= '<input type="button"'
7203: .' onclick="javascript:chgPage('."'previous'".');"'
7204: .' value="'.&mt('Previous [_1] changes',$curr->{'show'})
7205: .'" /> ';
7206: }
7207: if ($more_records) {
7208: $nav_links .= '<input type="button"'
7209: .' onclick="javascript:chgPage('."'next'".');"'
7210: .' value="'.&mt('Next [_1] changes',$curr->{'show'})
7211: .'" />';
1.301 bisitz 7212: }
7213: }
1.406.2.5 raeburn 7214: $nav_links .= '</p>';
7215: return $nav_links;
1.239 raeburn 7216: }
7217:
7218: sub role_display_filter {
1.363 raeburn 7219: my ($context,$formname,$cdom,$cnum,$curr,$version,$crstype) = @_;
7220: my $lctype;
7221: if ($context eq 'course') {
7222: $lctype = lc($crstype);
7223: }
1.239 raeburn 7224: my $nolink = 1;
7225: my $output = '<table><tr><td valign="top">'.
1.301 bisitz 7226: '<span class="LC_nobreak"><b>'.&mt('Changes/page:').'</b></span><br />'.
1.239 raeburn 7227: &Apache::lonmeta::selectbox('show',$curr->{'show'},undef,
7228: (&mt('all'),5,10,20,50,100,1000,10000)).
7229: '</td><td> </td>';
7230: my $startform =
7231: &Apache::lonhtmlcommon::date_setter($formname,'rolelog_start_date',
7232: $curr->{'rolelog_start_date'},undef,
7233: undef,undef,undef,undef,undef,undef,$nolink);
7234: my $endform =
7235: &Apache::lonhtmlcommon::date_setter($formname,'rolelog_end_date',
7236: $curr->{'rolelog_end_date'},undef,
7237: undef,undef,undef,undef,undef,undef,$nolink);
1.363 raeburn 7238: my %lt = &rolechg_contexts($context,$crstype);
1.301 bisitz 7239: $output .= '<td valign="top"><b>'.&mt('Window during which changes occurred:').'</b><br />'.
7240: '<table><tr><td>'.&mt('After:').
7241: '</td><td>'.$startform.'</td></tr>'.
7242: '<tr><td>'.&mt('Before:').'</td>'.
7243: '<td>'.$endform.'</td></tr></table>'.
7244: '</td>'.
7245: '<td> </td>'.
1.239 raeburn 7246: '<td valign="top"><b>'.&mt('Role:').'</b><br />'.
7247: '<select name="role"><option value="any"';
7248: if ($curr->{'role'} eq 'any') {
7249: $output .= ' selected="selected"';
7250: }
7251: $output .= '>'.&mt('Any').'</option>'."\n";
1.363 raeburn 7252: my @roles = &Apache::lonuserutils::roles_by_context($context,1,$crstype);
1.239 raeburn 7253: foreach my $role (@roles) {
7254: my $plrole;
7255: if ($role eq 'cr') {
7256: $plrole = &mt('Custom Role');
7257: } else {
1.318 raeburn 7258: $plrole=&Apache::lonnet::plaintext($role,$crstype);
1.239 raeburn 7259: }
7260: my $selstr = '';
7261: if ($role eq $curr->{'role'}) {
7262: $selstr = ' selected="selected"';
7263: }
7264: $output .= ' <option value="'.$role.'"'.$selstr.'>'.$plrole.'</option>';
7265: }
1.301 bisitz 7266: $output .= '</select></td>'.
7267: '<td> </td>'.
7268: '<td valign="top"><b>'.
1.239 raeburn 7269: &mt('Context:').'</b><br /><select name="chgcontext">';
1.363 raeburn 7270: my @posscontexts;
7271: if ($context eq 'course') {
1.376 raeburn 7272: @posscontexts = ('any','automated','updatenow','createcourse','course','domain','selfenroll','requestcourses');
1.363 raeburn 7273: } elsif ($context eq 'domain') {
7274: @posscontexts = ('any','domain','requestauthor','domconfig','server');
7275: } else {
7276: @posscontexts = ('any','author','domain');
7277: }
7278: foreach my $chgtype (@posscontexts) {
1.239 raeburn 7279: my $selstr = '';
7280: if ($curr->{'chgcontext'} eq $chgtype) {
1.301 bisitz 7281: $selstr = ' selected="selected"';
1.239 raeburn 7282: }
1.363 raeburn 7283: if ($context eq 'course') {
1.376 raeburn 7284: if (($chgtype eq 'automated') || ($chgtype eq 'updatenow')) {
1.363 raeburn 7285: next if (!&Apache::lonnet::auto_run($cnum,$cdom));
7286: }
1.239 raeburn 7287: }
7288: $output .= '<option value="'.$chgtype.'"'.$selstr.'>'.$lt{$chgtype}.'</option>'."\n";
1.248 raeburn 7289: }
1.303 bisitz 7290: $output .= '</select></td>'
7291: .'</tr></table>';
7292:
7293: # Update Display button
7294: $output .= '<p>'
7295: .'<input type="submit" value="'.&mt('Update Display').'" />'
7296: .'</p>';
7297:
7298: # Server version info
1.363 raeburn 7299: my $needsrev = '2.11.0';
7300: if ($context eq 'course') {
7301: $needsrev = '2.7.0';
7302: }
7303:
1.303 bisitz 7304: $output .= '<p class="LC_info">'
7305: .&mt('Only changes made from servers running LON-CAPA [_1] or later are displayed.'
1.363 raeburn 7306: ,$needsrev);
1.248 raeburn 7307: if ($version) {
1.303 bisitz 7308: $output .= ' '.&mt('This LON-CAPA server is version [_1]',$version);
7309: }
7310: $output .= '</p><hr />';
1.239 raeburn 7311: return $output;
7312: }
7313:
7314: sub rolechg_contexts {
1.363 raeburn 7315: my ($context,$crstype) = @_;
7316: my %lt;
7317: if ($context eq 'course') {
7318: %lt = &Apache::lonlocal::texthash (
1.239 raeburn 7319: any => 'Any',
1.376 raeburn 7320: automated => 'Automated Enrollment',
1.239 raeburn 7321: updatenow => 'Roster Update',
7322: createcourse => 'Course Creation',
7323: course => 'User Management in course',
7324: domain => 'User Management in domain',
1.313 raeburn 7325: selfenroll => 'Self-enrolled',
1.318 raeburn 7326: requestcourses => 'Course Request',
1.239 raeburn 7327: );
1.363 raeburn 7328: if ($crstype eq 'Community') {
7329: $lt{'createcourse'} = &mt('Community Creation');
7330: $lt{'course'} = &mt('User Management in community');
7331: $lt{'requestcourses'} = &mt('Community Request');
7332: }
7333: } elsif ($context eq 'domain') {
7334: %lt = &Apache::lonlocal::texthash (
7335: any => 'Any',
7336: domain => 'User Management in domain',
7337: requestauthor => 'Authoring Request',
7338: server => 'Command line script (DC role)',
7339: domconfig => 'Self-enrolled',
7340: );
7341: } else {
7342: %lt = &Apache::lonlocal::texthash (
7343: any => 'Any',
7344: domain => 'User Management in domain',
7345: author => 'User Management by author',
7346: );
7347: }
1.239 raeburn 7348: return %lt;
7349: }
7350:
1.406.2.10 raeburn 7351: sub print_helpdeskaccess_display {
7352: my ($r,$permission,$brcrum) = @_;
7353: my $formname = 'helpdeskaccess';
7354: my $helpitem = 'Course_Helpdesk_Access';
7355: push (@{$brcrum},
7356: {href => '/adm/createuser?action=helpdesk',
7357: text => 'Helpdesk Access',
7358: help => $helpitem});
7359: my $bread_crumbs_component = 'Helpdesk Staff Access';
7360: my $args = { bread_crumbs => $brcrum,
7361: bread_crumbs_component => $bread_crumbs_component};
7362:
7363: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
7364: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
7365: my $confname = $cdom.'-domainconfig';
7366: my $crstype = &Apache::loncommon::course_type();
7367:
1.406.2.12 raeburn 7368: my @accesstypes = ('all','dh','da','none');
1.406.2.10 raeburn 7369: my ($numstatustypes,@jsarray);
7370: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($cdom);
7371: if (ref($types) eq 'ARRAY') {
7372: if (@{$types} > 0) {
7373: $numstatustypes = scalar(@{$types});
7374: push(@accesstypes,'status');
7375: @jsarray = ('bystatus');
7376: }
7377: }
7378: my %customroles = &get_domain_customroles($cdom,$confname);
1.406.2.12 raeburn 7379: my %domhelpdesk = &Apache::lonnet::get_active_domroles($cdom,['dh','da']);
1.406.2.10 raeburn 7380: if (keys(%domhelpdesk)) {
7381: push(@accesstypes,('inc','exc'));
7382: push(@jsarray,('notinc','notexc'));
7383: }
7384: push(@jsarray,'privs');
7385: my $hiddenstr = join("','",@jsarray);
7386: my $rolestr = join("','",sort(keys(%customroles)));
7387:
7388: my $jscript;
7389: my (%settings,%overridden);
7390: if (keys(%customroles)) {
7391: &get_adhocrole_settings($env{'request.course.id'},\@accesstypes,
7392: $types,\%customroles,\%settings,\%overridden);
7393: my %jsfull=();
7394: my %jslevels= (
7395: course => {},
7396: domain => {},
7397: system => {},
7398: );
7399: my %jslevelscurrent=(
7400: course => {},
7401: domain => {},
7402: system => {},
7403: );
7404: my (%privs,%jsprivs);
7405: &Apache::lonuserutils::custom_role_privs(\%privs,\%jsfull,\%jslevels,\%jslevelscurrent);
7406: foreach my $priv (keys(%jsfull)) {
7407: if ($jslevels{'course'}{$priv}) {
7408: $jsprivs{$priv} = 1;
7409: }
7410: }
7411: my (%elements,%stored);
7412: foreach my $role (keys(%customroles)) {
7413: $elements{$role.'_access'} = 'radio';
7414: $elements{$role.'_incrs'} = 'radio';
7415: if ($numstatustypes) {
7416: $elements{$role.'_status'} = 'checkbox';
7417: }
7418: if (keys(%domhelpdesk) > 0) {
7419: $elements{$role.'_staff_inc'} = 'checkbox';
7420: $elements{$role.'_staff_exc'} = 'checkbox';
7421: }
7422: $elements{$role.'_override'} = 'checkbox';
7423: if (ref($settings{$role}) eq 'HASH') {
7424: if ($settings{$role}{'access'} ne '') {
7425: my $curraccess = $settings{$role}{'access'};
7426: $stored{$role.'_access'} = $curraccess;
7427: $stored{$role.'_incrs'} = 1;
7428: if ($curraccess eq 'status') {
7429: if (ref($settings{$role}{'status'}) eq 'ARRAY') {
7430: $stored{$role.'_status'} = $settings{$role}{'status'};
7431: }
7432: } elsif (($curraccess eq 'exc') || ($curraccess eq 'inc')) {
7433: if (ref($settings{$role}{$curraccess}) eq 'ARRAY') {
7434: $stored{$role.'_staff_'.$curraccess} = $settings{$role}{$curraccess};
7435: }
7436: }
7437: } else {
7438: $stored{$role.'_incrs'} = 0;
7439: }
7440: $stored{$role.'_override'} = [];
7441: if ($env{'course.'.$env{'request.course.id'}.'.internal.adhocpriv.'.$role}) {
7442: if (ref($settings{$role}{'off'}) eq 'ARRAY') {
7443: foreach my $priv (@{$settings{$role}{'off'}}) {
7444: push(@{$stored{$role.'_override'}},$priv);
7445: }
7446: }
7447: if (ref($settings{$role}{'on'}) eq 'ARRAY') {
7448: foreach my $priv (@{$settings{$role}{'on'}}) {
7449: unless (grep(/^$priv$/,@{$stored{$role.'_override'}})) {
7450: push(@{$stored{$role.'_override'}},$priv);
7451: }
7452: }
7453: }
7454: }
7455: } else {
7456: $stored{$role.'_incrs'} = 0;
7457: }
7458: }
7459: $jscript = &Apache::lonhtmlcommon::set_form_elements(\%elements,\%stored);
7460: }
7461:
7462: my $js = <<"ENDJS";
7463: <script type="text/javascript">
7464: // <![CDATA[
7465: $jscript;
7466:
7467: function switchRoleTab(caller,role) {
7468: if (document.getElementById(role+'_maindiv')) {
7469: if (caller.id != 'LC_current_minitab') {
7470: if (document.getElementById('LC_current_minitab')) {
7471: document.getElementById('LC_current_minitab').id=null;
7472: }
7473: var roledivs = Array('$rolestr');
7474: if (roledivs.length > 0) {
7475: for (var i=0; i<roledivs.length; i++) {
7476: if (document.getElementById(roledivs[i]+'_maindiv')) {
7477: document.getElementById(roledivs[i]+'_maindiv').style.display='none';
7478: }
7479: }
7480: }
7481: caller.id = 'LC_current_minitab';
7482: document.getElementById(role+'_maindiv').style.display='block';
7483: }
7484: }
7485: return false;
7486: }
7487:
7488: function helpdeskAccess(role) {
7489: var curraccess = null;
7490: if (document.$formname.elements[role+'_access'].length) {
7491: for (var i=0; i<document.$formname.elements[role+'_access'].length; i++) {
7492: if (document.$formname.elements[role+'_access'][i].checked) {
7493: curraccess = document.$formname.elements[role+'_access'][i].value;
7494: }
7495: }
7496: }
7497: var shown = Array();
7498: var hidden = Array();
7499: if (curraccess == 'none') {
7500: hidden = Array ('$hiddenstr');
7501: } else {
7502: if (curraccess == 'status') {
7503: shown = Array ('bystatus','privs');
7504: hidden = Array ('notinc','notexc');
7505: } else {
7506: if (curraccess == 'exc') {
7507: shown = Array ('notexc','privs');
7508: hidden = Array ('notinc','bystatus');
7509: }
7510: if (curraccess == 'inc') {
7511: shown = Array ('notinc','privs');
7512: hidden = Array ('notexc','bystatus');
7513: }
7514: if (curraccess == 'all') {
7515: shown = Array ('privs');
7516: hidden = Array ('notinc','notexc','bystatus');
7517: }
7518: }
7519: }
7520: if (hidden.length > 0) {
7521: for (var i=0; i<hidden.length; i++) {
7522: if (document.getElementById(role+'_'+hidden[i])) {
7523: document.getElementById(role+'_'+hidden[i]).style.display = 'none';
7524: }
7525: }
7526: }
7527: if (shown.length > 0) {
7528: for (var i=0; i<shown.length; i++) {
7529: if (document.getElementById(role+'_'+shown[i])) {
7530: if (shown[i] == 'privs') {
7531: document.getElementById(role+'_'+shown[i]).style.display = 'block';
7532: } else {
7533: document.getElementById(role+'_'+shown[i]).style.display = 'inline';
7534: }
7535: }
7536: }
7537: }
7538: return;
7539: }
7540:
7541: function toggleAccess(role) {
7542: if ((document.getElementById(role+'_setincrs')) &&
7543: (document.getElementById(role+'_setindom'))) {
7544: for (var i=0; i<document.$formname.elements[role+'_incrs'].length; i++) {
7545: if (document.$formname.elements[role+'_incrs'][i].checked) {
7546: if (document.$formname.elements[role+'_incrs'][i].value == 1) {
7547: document.getElementById(role+'_setindom').style.display = 'none';
7548: document.getElementById(role+'_setincrs').style.display = 'block';
7549: } else {
7550: document.getElementById(role+'_setincrs').style.display = 'none';
7551: document.getElementById(role+'_setindom').style.display = 'block';
7552: }
7553: break;
7554: }
7555: }
7556: }
7557: return;
7558: }
7559:
7560: // ]]>
7561: </script>
7562: ENDJS
7563:
7564: $args->{add_entries} = {onload => "javascript:setFormElements(document.$formname)"};
7565:
7566: # print page header
7567: $r->print(&header($js,$args));
7568: # print form header
7569: $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">');
7570:
7571: if (keys(%customroles)) {
7572: my %lt = &Apache::lonlocal::texthash(
7573: 'aco' => 'As course owner you may override the defaults set in the domain for role usage and/or privileges.',
7574: 'rou' => 'Role usage',
7575: 'whi' => 'Which helpdesk personnel may use this role?',
7576: 'udd' => 'Use domain default',
1.406.2.12 raeburn 7577: 'all' => 'All with domain helpdesk or helpdesk assistant role',
7578: 'dh' => 'All with domain helpdesk role',
7579: 'da' => 'All with domain helpdesk assistant role',
1.406.2.10 raeburn 7580: 'none' => 'None',
7581: 'status' => 'Determined based on institutional status',
7582: 'inc' => 'Include all, but exclude specific personnel',
7583: 'exc' => 'Exclude all, but include specific personnel',
7584: 'hel' => 'Helpdesk',
7585: 'rpr' => 'Role privileges',
7586: );
7587: $lt{'tfh'} = &mt("Custom [_1]ad hoc[_2] course roles available for use by the domain's helpdesk are as follows",'<i>','</i>');
7588: my %domconfig = &Apache::lonnet::get_dom('configuration',['helpsettings'],$cdom);
7589: my (%domcurrent,%ordered,%description,%domusage,$disabled);
7590: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
7591: if (ref($domconfig{'helpsettings'}{'adhoc'}) eq 'HASH') {
7592: %domcurrent = %{$domconfig{'helpsettings'}{'adhoc'}};
7593: }
7594: }
7595: my $count = 0;
7596: foreach my $role (sort(keys(%customroles))) {
7597: my ($order,$desc,$access_in_dom);
7598: if (ref($domcurrent{$role}) eq 'HASH') {
7599: $order = $domcurrent{$role}{'order'};
7600: $desc = $domcurrent{$role}{'desc'};
7601: $access_in_dom = $domcurrent{$role}{'access'};
7602: }
7603: if ($order eq '') {
7604: $order = $count;
7605: }
7606: $ordered{$order} = $role;
7607: if ($desc ne '') {
7608: $description{$role} = $desc;
7609: } else {
7610: $description{$role}= $role;
7611: }
7612: $count++;
7613: }
7614: %domusage = &domain_adhoc_access(\%customroles,\%domcurrent,\@accesstypes,$usertypes,$othertitle);
7615: my @roles_by_num = ();
7616: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
7617: push(@roles_by_num,$ordered{$item});
7618: }
7619: $r->print('<p>'.$lt{'tfh'}.': <i>'.join('</i>, <i>',map { $description{$_}; } @roles_by_num).'</i>.');
7620: if ($permission->{'owner'}) {
7621: $r->print('<br />'.$lt{'aco'}.'</p><p>');
7622: $r->print('<input type="hidden" name="state" value="process" />'.
7623: '<input type="submit" value="'.&mt('Save changes').'" />');
7624: } else {
7625: if ($env{'course.'.$env{'request.course.id'}.'.internal.courseowner'}) {
7626: my ($ownername,$ownerdom) = split(/:/,$env{'course.'.$env{'request.course.id'}.'.internal.courseowner'});
7627: $r->print('<br />'.&mt('The course owner -- [_1] -- can override the default access and/or privileges for these ad hoc roles.',
7628: &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($ownername,$ownerdom),$ownername,$ownerdom)));
7629: }
7630: $disabled = ' disabled="disabled"';
7631: }
7632: $r->print('</p>');
7633:
7634: $r->print('<div id="LC_minitab_header"><ul>');
7635: my $count = 0;
7636: my %visibility;
7637: foreach my $role (@roles_by_num) {
7638: my $id;
7639: if ($count == 0) {
7640: $id=' id="LC_current_minitab"';
7641: $visibility{$role} = ' style="display:block"';
7642: } else {
7643: $visibility{$role} = ' style="display:none"';
7644: }
7645: $count ++;
7646: $r->print('<li'.$id.'><a href="#" onclick="javascript:switchRoleTab(this.parentNode,'."'$role'".');">'.$description{$role}.'</a></li>');
7647: }
7648: $r->print('</ul></div>');
7649:
7650: foreach my $role (@roles_by_num) {
7651: my %usecheck = (
7652: all => ' checked="checked"',
7653: );
7654: my %displaydiv = (
7655: status => 'none',
7656: inc => 'none',
7657: exc => 'none',
7658: priv => 'block',
7659: );
7660: my (%selected,$overridden,$incrscheck,$indomcheck,$indomvis,$incrsvis);
7661: if (ref($settings{$role}) eq 'HASH') {
7662: if ($settings{$role}{'access'} ne '') {
7663: $indomvis = ' style="display:none"';
7664: $incrsvis = ' style="display:block"';
7665: $incrscheck = ' checked="checked"';
7666: if ($settings{$role}{'access'} ne 'all') {
7667: $usecheck{$settings{$role}{'access'}} = $usecheck{'all'};
7668: delete($usecheck{'all'});
7669: if ($settings{$role}{'access'} eq 'status') {
7670: my $access = 'status';
7671: $displaydiv{$access} = 'inline';
7672: if (ref($settings{$role}{$access}) eq 'ARRAY') {
7673: $selected{$access} = $settings{$role}{$access};
7674: }
7675: } elsif ($settings{$role}{'access'} =~ /^(inc|exc)$/) {
7676: my $access = $1;
7677: $displaydiv{$access} = 'inline';
7678: if (ref($settings{$role}{$access}) eq 'ARRAY') {
7679: $selected{$access} = $settings{$role}{$access};
7680: }
7681: } elsif ($settings{$role}{'access'} eq 'none') {
7682: $displaydiv{'priv'} = 'none';
7683: }
7684: }
7685: } else {
7686: $indomcheck = ' checked="checked"';
7687: $indomvis = ' style="display:block"';
7688: $incrsvis = ' style="display:none"';
7689: }
7690: } else {
7691: $indomcheck = ' checked="checked"';
7692: $indomvis = ' style="display:block"';
7693: $incrsvis = ' style="display:none"';
7694: }
7695: $r->print('<div class="LC_left_float" id="'.$role.'_maindiv"'.$visibility{$role}.'>'.
7696: '<fieldset><legend>'.$lt{'rou'}.'</legend>'.
7697: '<p>'.$lt{'whi'}.' <span class="LC_nobreak">'.
7698: '<label><input type="radio" name="'.$role.'_incrs" value="1"'.$incrscheck.' onclick="toggleAccess('."'$role'".');"'.$disabled.'>'.
7699: &mt('Set here in [_1]',lc($crstype)).'</label>'.
7700: '<span>'.(' 'x2).
7701: '<label><input type="radio" name="'.$role.'_incrs" value="0"'.$indomcheck.' onclick="toggleAccess('."'$role'".');"'.$disabled.'>'.
7702: $lt{'udd'}.'</label><span></p>'.
7703: '<div id="'.$role.'_setindom"'.$indomvis.'>'.
7704: '<span class="LC_cusr_emph">'.$domusage{$role}.'</span></div>'.
7705: '<div id="'.$role.'_setincrs"'.$incrsvis.'>');
7706: foreach my $access (@accesstypes) {
7707: $r->print('<p><label><input type="radio" name="'.$role.'_access" value="'.$access.'" '.$usecheck{$access}.
7708: ' onclick="helpdeskAccess('."'$role'".');"'.$disabled.' />'.$lt{$access}.'</label>');
7709: if ($access eq 'status') {
7710: $r->print('<div id="'.$role.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
7711: &Apache::lonuserutils::adhoc_status_types($cdom,undef,$role,$selected{$access},
7712: $othertitle,$usertypes,$types,$disabled).
7713: '</div>');
7714: } elsif (($access eq 'inc') && (keys(%domhelpdesk) > 0)) {
7715: $r->print('<div id="'.$role.'_notinc" style="display:'.$displaydiv{$access}.'">'.
7716: &Apache::lonuserutils::adhoc_staff($access,undef,$role,$selected{$access},
7717: \%domhelpdesk,$disabled).
7718: '</div>');
7719: } elsif (($access eq 'exc') && (keys(%domhelpdesk) > 0)) {
7720: $r->print('<div id="'.$role.'_notexc" style="display:'.$displaydiv{$access}.'">'.
7721: &Apache::lonuserutils::adhoc_staff($access,undef,$role,$selected{$access},
7722: \%domhelpdesk,$disabled).
7723: '</div>');
7724: }
7725: $r->print('</p>');
7726: }
7727: $r->print('</div></fieldset>');
7728: my %full=();
7729: my %levels= (
7730: course => {},
7731: domain => {},
7732: system => {},
7733: );
7734: my %levelscurrent=(
7735: course => {},
7736: domain => {},
7737: system => {},
7738: );
7739: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
7740: $r->print('<fieldset id="'.$role.'_privs" style="display:'.$displaydiv{'priv'}.'">'.
7741: '<legend>'.$lt{'rpr'}.'</legend>'.
7742: &role_priv_table($role,$permission,$crstype,\%full,\%levels,\%levelscurrent,$overridden{$role}).
7743: '</fieldset></div><div style="padding:0;clear:both;margin:0;border:0"></div>');
7744: }
7745: if ($permission->{'owner'}) {
7746: $r->print('<p><input type="submit" value="'.&mt('Save changes').'" /></p>');
7747: }
7748: } else {
7749: $r->print(&mt('Helpdesk roles have not yet been created in this domain.'));
7750: }
7751: # Form Footer
7752: $r->print('<input type="hidden" name="action" value="helpdesk" />'
7753: .'</form>');
7754: return;
7755: }
7756:
7757: sub domain_adhoc_access {
7758: my ($roles,$domcurrent,$accesstypes,$usertypes,$othertitle) = @_;
7759: my %domusage;
7760: return unless ((ref($roles) eq 'HASH') && (ref($domcurrent) eq 'HASH') && (ref($accesstypes) eq 'ARRAY'));
7761: foreach my $role (keys(%{$roles})) {
7762: if (ref($domcurrent->{$role}) eq 'HASH') {
7763: my $access = $domcurrent->{$role}{'access'};
7764: if (($access eq '') || (!grep(/^\Q$access\E$/,@{$accesstypes}))) {
7765: $access = 'all';
1.406.2.12 raeburn 7766: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role',&Apache::lonnet::plaintext('dh'),
7767: &Apache::lonnet::plaintext('da'));
1.406.2.10 raeburn 7768: } elsif ($access eq 'status') {
7769: if (ref($domcurrent->{$role}{$access}) eq 'ARRAY') {
7770: my @shown;
7771: foreach my $type (@{$domcurrent->{$role}{$access}}) {
7772: unless ($type eq 'default') {
7773: if ($usertypes->{$type}) {
7774: push(@shown,$usertypes->{$type});
7775: }
7776: }
7777: }
7778: if (grep(/^default$/,@{$domcurrent->{$role}{$access}})) {
7779: push(@shown,$othertitle);
7780: }
7781: if (@shown) {
7782: my $shownstatus = join(' '.&mt('or').' ',@shown);
1.406.2.12 raeburn 7783: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role, and institutional status: [_3]',
7784: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'),$shownstatus);
1.406.2.10 raeburn 7785: } else {
7786: $domusage{$role} = &mt('No one in the domain');
7787: }
7788: }
7789: } elsif ($access eq 'inc') {
7790: my @dominc = ();
7791: if (ref($domcurrent->{$role}{'inc'}) eq 'ARRAY') {
7792: foreach my $user (@{$domcurrent->{$role}{'inc'}}) {
7793: my ($uname,$udom) = split(/:/,$user);
7794: push(@dominc,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),$uname,$udom));
7795: }
7796: my $showninc = join(', ',@dominc);
7797: if ($showninc ne '') {
1.406.2.12 raeburn 7798: $domusage{$role} = &mt('Include any user in domain with active [_1] or [_2] role, except: [_3]',
7799: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'),$showninc);
1.406.2.10 raeburn 7800: } else {
1.406.2.12 raeburn 7801: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role',
7802: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'));
1.406.2.10 raeburn 7803: }
7804: }
7805: } elsif ($access eq 'exc') {
7806: my @domexc = ();
7807: if (ref($domcurrent->{$role}{'exc'}) eq 'ARRAY') {
7808: foreach my $user (@{$domcurrent->{$role}{'exc'}}) {
7809: my ($uname,$udom) = split(/:/,$user);
7810: push(@domexc,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),$uname,$udom));
7811: }
7812: }
7813: my $shownexc = join(', ',@domexc);
7814: if ($shownexc ne '') {
1.406.2.12 raeburn 7815: $domusage{$role} = &mt('Only the following in the domain with active [_1] or [_2] role: [_3]',
7816: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'),$shownexc);
1.406.2.10 raeburn 7817: } else {
7818: $domusage{$role} = &mt('No one in the domain');
7819: }
7820: } elsif ($access eq 'none') {
7821: $domusage{$role} = &mt('No one in the domain');
1.406.2.12 raeburn 7822: } elsif ($access eq 'dh') {
1.406.2.10 raeburn 7823: $domusage{$role} = &mt('Any user in domain with active [_1] role',&Apache::lonnet::plaintext('dh'));
1.406.2.12 raeburn 7824: } elsif ($access eq 'da') {
7825: $domusage{$role} = &mt('Any user in domain with active [_1] role',&Apache::lonnet::plaintext('da'));
7826: } elsif ($access eq 'all') {
7827: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role',
7828: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'));
1.406.2.10 raeburn 7829: }
7830: } else {
1.406.2.12 raeburn 7831: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role',
7832: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'));
1.406.2.10 raeburn 7833: }
7834: }
7835: return %domusage;
7836: }
7837:
7838: sub get_domain_customroles {
7839: my ($cdom,$confname) = @_;
7840: my %existing=&Apache::lonnet::dump('roles',$cdom,$confname,'rolesdef_');
7841: my %customroles;
7842: foreach my $key (keys(%existing)) {
7843: if ($key=~/^rolesdef\_(\w+)$/) {
7844: my $rolename = $1;
7845: my %privs;
7846: ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
7847: $customroles{$rolename} = \%privs;
7848: }
7849: }
7850: return %customroles;
7851: }
7852:
7853: sub role_priv_table {
7854: my ($role,$permission,$crstype,$full,$levels,$levelscurrent,$overridden) = @_;
7855: return unless ((ref($full) eq 'HASH') && (ref($levels) eq 'HASH') &&
7856: (ref($levelscurrent) eq 'HASH'));
7857: my %lt=&Apache::lonlocal::texthash (
7858: 'crl' => 'Course Level Privilege',
7859: 'def' => 'Domain Defaults',
7860: 'ove' => 'Override in Course',
7861: 'ine' => 'In effect',
7862: 'dis' => 'Disabled',
7863: 'ena' => 'Enabled',
7864: );
7865: if ($crstype eq 'Community') {
7866: $lt{'ove'} = 'Override in Community',
7867: }
7868: my @status = ('Disabled','Enabled');
7869: my (%on,%off);
7870: if (ref($overridden) eq 'HASH') {
7871: if (ref($overridden->{'on'}) eq 'ARRAY') {
7872: map { $on{$_} = 1; } (@{$overridden->{'on'}});
7873: }
7874: if (ref($overridden->{'off'}) eq 'ARRAY') {
7875: map { $off{$_} = 1; } (@{$overridden->{'off'}});
7876: }
7877: }
7878: my $output=&Apache::loncommon::start_data_table().
7879: &Apache::loncommon::start_data_table_header_row().
7880: '<th>'.$lt{'crl'}.'</th><th>'.$lt{'def'}.'</th><th>'.$lt{'ove'}.
7881: '</th><th>'.$lt{'ine'}.'</th>'.
7882: &Apache::loncommon::end_data_table_header_row();
7883: foreach my $priv (sort(keys(%{$full}))) {
7884: next unless ($levels->{'course'}{$priv});
7885: my $privtext = &Apache::lonnet::plaintext($priv,$crstype);
7886: my ($default,$ineffect);
7887: if ($levelscurrent->{'course'}{$priv}) {
7888: $default = '<img src="/adm/lonIcons/navmap.correct.gif" alt="'.$lt{'ena'}.'" />';
7889: $ineffect = $default;
7890: }
7891: my ($customstatus,$checked);
7892: $output .= &Apache::loncommon::start_data_table_row().
7893: '<td>'.$privtext.'</td>'.
7894: '<td>'.$default.'</td><td>';
7895: if (($levelscurrent->{'course'}{$priv}) && ($off{$priv})) {
7896: if ($permission->{'owner'}) {
7897: $checked = ' checked="checked"';
7898: }
7899: $customstatus = '<img src="/adm/lonIcons/navmap.wrong.gif" alt="'.$lt{'dis'}.'" />';
7900: $ineffect = $customstatus;
7901: } elsif ((!$levelscurrent->{'course'}{$priv}) && ($on{$priv})) {
7902: if ($permission->{'owner'}) {
7903: $checked = ' checked="checked"';
7904: }
7905: $customstatus = '<img src="/adm/lonIcons/navmap.correct.gif" alt="'.$lt{'ena'}.'" />';
7906: $ineffect = $customstatus;
7907: }
7908: if ($permission->{'owner'}) {
7909: $output .= '<input type="checkbox" name="'.$role.'_override" value="'.$priv.'"'.$checked.' />';
7910: } else {
7911: $output .= $customstatus;
7912: }
7913: $output .= '</td><td>'.$ineffect.'</td>'.
7914: &Apache::loncommon::end_data_table_row();
7915: }
7916: $output .= &Apache::loncommon::end_data_table();
7917: return $output;
7918: }
7919:
7920: sub get_adhocrole_settings {
7921: my ($cid,$accesstypes,$types,$customroles,$settings,$overridden) = @_;
7922: return unless ((ref($accesstypes) eq 'ARRAY') && (ref($customroles) eq 'HASH') &&
7923: (ref($settings) eq 'HASH') && (ref($overridden) eq 'HASH'));
7924: foreach my $role (split(/,/,$env{'course.'.$cid.'.internal.adhocaccess'})) {
7925: my ($curraccess,$rest) = split(/=/,$env{'course.'.$cid.'.internal.adhoc.'.$role});
7926: if (($curraccess ne '') && (grep(/^\Q$curraccess\E$/,@{$accesstypes}))) {
7927: $settings->{$role}{'access'} = $curraccess;
7928: if (($curraccess eq 'status') && (ref($types) eq 'ARRAY')) {
7929: my @status = split(/,/,$rest);
7930: my @currstatus;
7931: foreach my $type (@status) {
7932: if ($type eq 'default') {
7933: push(@currstatus,$type);
7934: } elsif (grep(/^\Q$type\E$/,@{$types})) {
7935: push(@currstatus,$type);
7936: }
7937: }
7938: if (@currstatus) {
7939: $settings->{$role}{$curraccess} = \@currstatus;
7940: } elsif (($curraccess eq 'exc') || ($curraccess eq 'inc')) {
7941: my @personnel = split(/,/,$rest);
7942: $settings->{$role}{$curraccess} = \@personnel;
7943: }
7944: }
7945: }
7946: }
7947: foreach my $role (keys(%{$customroles})) {
7948: if ($env{'course.'.$cid.'.internal.adhocpriv.'.$role}) {
7949: my %currentprivs;
7950: if (ref($customroles->{$role}) eq 'HASH') {
7951: if (exists($customroles->{$role}{'course'})) {
7952: my %full=();
7953: my %levels= (
7954: course => {},
7955: domain => {},
7956: system => {},
7957: );
7958: my %levelscurrent=(
7959: course => {},
7960: domain => {},
7961: system => {},
7962: );
7963: &Apache::lonuserutils::custom_role_privs($customroles->{$role},\%full,\%levels,\%levelscurrent);
7964: %currentprivs = %{$levelscurrent{'course'}};
7965: }
7966: }
7967: foreach my $item (split(/,/,$env{'course.'.$cid.'.internal.adhocpriv.'.$role})) {
7968: next if ($item eq '');
7969: my ($rule,$rest) = split(/=/,$item);
7970: next unless (($rule eq 'off') || ($rule eq 'on'));
7971: foreach my $priv (split(/:/,$rest)) {
7972: if ($priv ne '') {
7973: if ($rule eq 'off') {
7974: push(@{$overridden->{$role}{'off'}},$priv);
7975: if ($currentprivs{$priv}) {
7976: push(@{$settings->{$role}{'off'}},$priv);
7977: }
7978: } else {
7979: push(@{$overridden->{$role}{'on'}},$priv);
7980: unless ($currentprivs{$priv}) {
7981: push(@{$settings->{$role}{'on'}},$priv);
7982: }
7983: }
7984: }
7985: }
7986: }
7987: }
7988: }
7989: return;
7990: }
7991:
7992: sub update_helpdeskaccess {
7993: my ($r,$permission,$brcrum) = @_;
7994: my $helpitem = 'Course_Helpdesk_Access';
7995: push (@{$brcrum},
7996: {href => '/adm/createuser?action=helpdesk',
7997: text => 'Helpdesk Access',
7998: help => $helpitem},
7999: {href => '/adm/createuser?action=helpdesk',
8000: text => 'Result',
8001: help => $helpitem}
8002: );
8003: my $bread_crumbs_component = 'Helpdesk Staff Access';
8004: my $args = { bread_crumbs => $brcrum,
8005: bread_crumbs_component => $bread_crumbs_component};
8006:
8007: # print page header
8008: $r->print(&header('',$args));
8009: unless ((ref($permission) eq 'HASH') && ($permission->{'owner'})) {
8010: $r->print('<p class="LC_error">'.&mt('You do not have permission to change helpdesk access.').'</p>');
8011: return;
8012: }
1.406.2.12 raeburn 8013: my @accesstypes = ('all','dh','da','none','status','inc','exc');
1.406.2.10 raeburn 8014: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
8015: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
8016: my $confname = $cdom.'-domainconfig';
8017: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($cdom);
8018: my $crstype = &Apache::loncommon::course_type();
8019: my %customroles = &get_domain_customroles($cdom,$confname);
8020: my (%settings,%overridden);
8021: &get_adhocrole_settings($env{'request.course.id'},\@accesstypes,
8022: $types,\%customroles,\%settings,\%overridden);
1.406.2.12 raeburn 8023: my %domhelpdesk = &Apache::lonnet::get_active_domroles($cdom,['dh','da']);
1.406.2.10 raeburn 8024: my (%changed,%storehash,@todelete);
8025:
8026: if (keys(%customroles)) {
8027: my (%newsettings,@incrs);
8028: foreach my $role (keys(%customroles)) {
8029: $newsettings{$role} = {
8030: access => '',
8031: status => '',
8032: exc => '',
8033: inc => '',
8034: on => '',
8035: off => '',
8036: };
8037: my %current;
8038: if (ref($settings{$role}) eq 'HASH') {
8039: %current = %{$settings{$role}};
8040: }
8041: if (ref($overridden{$role}) eq 'HASH') {
8042: $current{'overridden'} = $overridden{$role};
8043: }
8044: if ($env{'form.'.$role.'_incrs'}) {
8045: my $access = $env{'form.'.$role.'_access'};
8046: if (grep(/^\Q$access\E$/,@accesstypes)) {
8047: push(@incrs,$role);
8048: unless ($current{'access'} eq $access) {
8049: $changed{$role}{'access'} = 1;
8050: $storehash{'internal.adhoc.'.$role} = $access;
8051: }
8052: if ($access eq 'status') {
8053: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$role.'_status');
8054: my @stored;
8055: my @shownstatus;
8056: if (ref($types) eq 'ARRAY') {
8057: foreach my $type (sort(@statuses)) {
8058: if ($type eq 'default') {
8059: push(@stored,$type);
8060: } elsif (grep(/^\Q$type\E$/,@{$types})) {
8061: push(@stored,$type);
8062: push(@shownstatus,$usertypes->{$type});
8063: }
8064: }
8065: if (grep(/^default$/,@statuses)) {
8066: push(@shownstatus,$othertitle);
8067: }
8068: $storehash{'internal.adhoc.'.$role} .= '='.join(',',@stored);
8069: }
8070: $newsettings{$role}{'status'} = join(' '.&mt('or').' ',@shownstatus);
8071: if (ref($current{'status'}) eq 'ARRAY') {
8072: my @diffs = &Apache::loncommon::compare_arrays(\@stored,$current{'status'});
8073: if (@diffs) {
8074: $changed{$role}{'status'} = 1;
8075: }
8076: } elsif (@stored) {
8077: $changed{$role}{'status'} = 1;
8078: }
8079: } elsif (($access eq 'inc') || ($access eq 'exc')) {
8080: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$role.'_staff_'.$access);
8081: my @newspecstaff;
8082: my @stored;
8083: my @currstaff;
8084: foreach my $person (sort(@personnel)) {
8085: if ($domhelpdesk{$person}) {
8086: push(@stored,$person);
8087: }
8088: }
8089: if (ref($current{$access}) eq 'ARRAY') {
8090: my @diffs = &Apache::loncommon::compare_arrays(\@stored,$current{$access});
8091: if (@diffs) {
8092: $changed{$role}{$access} = 1;
8093: }
8094: } elsif (@stored) {
8095: $changed{$role}{$access} = 1;
8096: }
8097: $storehash{'internal.adhoc.'.$role} .= '='.join(',',@stored);
8098: foreach my $person (@stored) {
8099: my ($uname,$udom) = split(/:/,$person);
8100: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
8101: }
8102: $newsettings{$role}{$access} = join(', ',sort(@newspecstaff));
8103: }
8104: $newsettings{$role}{'access'} = $access;
8105: }
8106: } else {
8107: if (($current{'access'} ne '') && (grep(/^\Q$current{'access'}\E$/,@accesstypes))) {
8108: $changed{$role}{'access'} = 1;
8109: $newsettings{$role} = {};
8110: push(@todelete,'internal.adhoc.'.$role);
8111: }
8112: }
8113: if (($env{'form.'.$role.'_incrs'}) && ($env{'form.'.$role.'_access'} eq 'none')) {
8114: if (ref($current{'overridden'}) eq 'HASH') {
8115: push(@todelete,'internal.adhocpriv.'.$role);
8116: }
8117: } else {
8118: my %full=();
8119: my %levels= (
8120: course => {},
8121: domain => {},
8122: system => {},
8123: );
8124: my %levelscurrent=(
8125: course => {},
8126: domain => {},
8127: system => {},
8128: );
8129: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
8130: my (@updatedon,@updatedoff,@override);
8131: @override = &Apache::loncommon::get_env_multiple('form.'.$role.'_override');
8132: if (@override) {
8133: foreach my $priv (sort(keys(%full))) {
8134: next unless ($levels{'course'}{$priv});
8135: if (grep(/^\Q$priv\E$/,@override)) {
8136: if ($levelscurrent{'course'}{$priv}) {
8137: push(@updatedoff,$priv);
8138: } else {
8139: push(@updatedon,$priv);
8140: }
8141: }
8142: }
8143: }
8144: if (@updatedon) {
8145: $newsettings{$role}{'on'} = join('</li><li>', map { &Apache::lonnet::plaintext($_,$crstype) } (@updatedon));
8146: }
8147: if (@updatedoff) {
8148: $newsettings{$role}{'off'} = join('</li><li>', map { &Apache::lonnet::plaintext($_,$crstype) } (@updatedoff));
8149: }
8150: if (ref($current{'overridden'}) eq 'HASH') {
8151: if (ref($current{'overridden'}{'on'}) eq 'ARRAY') {
8152: if (@updatedon) {
8153: my @diffs = &Apache::loncommon::compare_arrays(\@updatedon,$current{'overridden'}{'on'});
8154: if (@diffs) {
8155: $changed{$role}{'on'} = 1;
8156: }
8157: } else {
8158: $changed{$role}{'on'} = 1;
8159: }
8160: } elsif (@updatedon) {
8161: $changed{$role}{'on'} = 1;
8162: }
8163: if (ref($current{'overridden'}{'off'}) eq 'ARRAY') {
8164: if (@updatedoff) {
8165: my @diffs = &Apache::loncommon::compare_arrays(\@updatedoff,$current{'overridden'}{'off'});
8166: if (@diffs) {
8167: $changed{$role}{'off'} = 1;
8168: }
8169: } else {
8170: $changed{$role}{'off'} = 1;
8171: }
8172: } elsif (@updatedoff) {
8173: $changed{$role}{'off'} = 1;
8174: }
8175: } else {
8176: if (@updatedon) {
8177: $changed{$role}{'on'} = 1;
8178: }
8179: if (@updatedoff) {
8180: $changed{$role}{'off'} = 1;
8181: }
8182: }
8183: if (ref($changed{$role}) eq 'HASH') {
8184: if (($changed{$role}{'on'} || $changed{$role}{'off'})) {
8185: my $newpriv;
8186: if (@updatedon) {
8187: $newpriv = 'on='.join(':',@updatedon);
8188: }
8189: if (@updatedoff) {
8190: $newpriv .= ($newpriv ? ',' : '' ).'off='.join(':',@updatedoff);
8191: }
8192: if ($newpriv eq '') {
8193: push(@todelete,'internal.adhocpriv.'.$role);
8194: } else {
8195: $storehash{'internal.adhocpriv.'.$role} = $newpriv;
8196: }
8197: }
8198: }
8199: }
8200: }
8201: if (@incrs) {
8202: $storehash{'internal.adhocaccess'} = join(',',@incrs);
8203: } elsif (@todelete) {
8204: push(@todelete,'internal.adhocaccess');
8205: }
8206: if (keys(%changed)) {
8207: my ($putres,$delres);
8208: if (keys(%storehash)) {
8209: $putres = &Apache::lonnet::put('environment',\%storehash,$cdom,$cnum);
8210: my %newenvhash;
8211: foreach my $key (keys(%storehash)) {
8212: $newenvhash{'course.'.$env{'request.course.id'}.'.'.$key} = $storehash{$key};
8213: }
8214: &Apache::lonnet::appenv(\%newenvhash);
8215: }
8216: if (@todelete) {
8217: $delres = &Apache::lonnet::del('environment',\@todelete,$cdom,$cnum);
8218: foreach my $key (@todelete) {
8219: &Apache::lonnet::delenv('course.'.$env{'request.course.id'}.'.'.$key);
8220: }
8221: }
8222: if (($putres eq 'ok') || ($delres eq 'ok')) {
8223: my %domconfig = &Apache::lonnet::get_dom('configuration',['helpsettings'],$cdom);
8224: my (%domcurrent,%ordered,%description,%domusage);
8225: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
8226: if (ref($domconfig{'helpsettings'}{'adhoc'}) eq 'HASH') {
8227: %domcurrent = %{$domconfig{'helpsettings'}{'adhoc'}};
8228: }
8229: }
8230: my $count = 0;
8231: foreach my $role (sort(keys(%customroles))) {
8232: my ($order,$desc);
8233: if (ref($domcurrent{$role}) eq 'HASH') {
8234: $order = $domcurrent{$role}{'order'};
8235: $desc = $domcurrent{$role}{'desc'};
8236: }
8237: if ($order eq '') {
8238: $order = $count;
8239: }
8240: $ordered{$order} = $role;
8241: if ($desc ne '') {
8242: $description{$role} = $desc;
8243: } else {
8244: $description{$role}= $role;
8245: }
8246: $count++;
8247: }
8248: my @roles_by_num = ();
8249: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
8250: push(@roles_by_num,$ordered{$item});
8251: }
8252: %domusage = &domain_adhoc_access(\%changed,\%domcurrent,\@accesstypes,$usertypes,$othertitle);
8253: $r->print(&mt('Helpdesk access settings have been changed as follows').'<br />');
8254: $r->print('<ul>');
8255: foreach my $role (@roles_by_num) {
8256: next unless (ref($changed{$role}) eq 'HASH');
8257: $r->print('<li>'.&mt('Ad hoc role').': <b>'.$description{$role}.'</b>'.
8258: '<ul>');
8259: if ($changed{$role}{'access'} || $changed{$role}{'status'} || $changed{$role}{'inc'} || $changed{$role}{'exc'}) {
8260: $r->print('<li>');
8261: if ($env{'form.'.$role.'_incrs'}) {
8262: if ($newsettings{$role}{'access'} eq 'all') {
8263: $r->print(&mt('All helpdesk staff can access '.lc($crstype).' with this role.'));
1.406.2.12 raeburn 8264: } elsif ($newsettings{$role}{'access'} eq 'dh') {
8265: $r->print(&mt('Helpdesk staff can use this role if they have an active [_1] role',
8266: &Apache::lonnet::plaintext('dh')));
8267: } elsif ($newsettings{$role}{'access'} eq 'da') {
8268: $r->print(&mt('Helpdesk staff can use this role if they have an active [_1] role',
8269: &Apache::lonnet::plaintext('da')));
1.406.2.10 raeburn 8270: } elsif ($newsettings{$role}{'access'} eq 'none') {
8271: $r->print(&mt('No helpdesk staff can access '.lc($crstype).' with this role.'));
8272: } elsif ($newsettings{$role}{'access'} eq 'status') {
8273: if ($newsettings{$role}{'status'}) {
8274: my ($access,$rest) = split(/=/,$storehash{'internal.adhoc.'.$role});
8275: if (split(/,/,$rest) > 1) {
8276: $r->print(&mt('Helpdesk staff can use this role if their institutional type is one of: [_1].',
8277: $newsettings{$role}{'status'}));
8278: } else {
8279: $r->print(&mt('Helpdesk staff can use this role if their institutional type is: [_1].',
8280: $newsettings{$role}{'status'}));
8281: }
8282: } else {
8283: $r->print(&mt('No helpdesk staff can access '.lc($crstype).' with this role.'));
8284: }
8285: } elsif ($newsettings{$role}{'access'} eq 'exc') {
8286: if ($newsettings{$role}{'exc'}) {
8287: $r->print(&mt('Helpdesk staff who can use this role are as follows:').' '.$newsettings{$role}{'exc'}.'.');
8288: } else {
8289: $r->print(&mt('No helpdesk staff can access '.lc($crstype).' with this role.'));
8290: }
8291: } elsif ($newsettings{$role}{'access'} eq 'inc') {
8292: if ($newsettings{$role}{'inc'}) {
8293: $r->print(&mt('All helpdesk staff may use this role except the following:').' '.$newsettings{$role}{'inc'}.'.');
8294: } else {
8295: $r->print(&mt('All helpdesk staff may use this role.'));
8296: }
8297: }
8298: } else {
8299: $r->print(&mt('Default access set in the domain now applies.').'<br />'.
8300: '<span class="LC_cusr_emph">'.$domusage{$role}.'</span>');
8301: }
8302: $r->print('</li>');
8303: }
8304: unless ($newsettings{$role}{'access'} eq 'none') {
8305: if ($changed{$role}{'off'}) {
8306: if ($newsettings{$role}{'off'}) {
8307: $r->print('<li>'.&mt('Privileges which are available by default for this ad hoc role, but are disabled for this specific '.lc($crstype).':').
8308: '<ul><li>'.$newsettings{$role}{'off'}.'</li></ul></li>');
8309: } else {
8310: $r->print('<li>'.&mt('All privileges available by default for this ad hoc role are enabled.').'</li>');
8311: }
8312: }
8313: if ($changed{$role}{'on'}) {
8314: if ($newsettings{$role}{'on'}) {
8315: $r->print('<li>'.&mt('Privileges which are not available by default for this ad hoc role, but are enabled for this specific '.lc($crstype).':').
8316: '<ul><li>'.$newsettings{$role}{'on'}.'</li></ul></li>');
8317: } else {
8318: $r->print('<li>'.&mt('None of the privileges unavailable by default for this ad hoc role are enabled.').'</li>');
8319: }
8320: }
8321: }
8322: $r->print('</ul></li>');
8323: }
8324: $r->print('</ul>');
8325: }
8326: } else {
8327: $r->print(&mt('No changes made to helpdesk access settings.'));
8328: }
8329: }
8330: return;
8331: }
8332:
1.27 matthew 8333: #-------------------------------------------------- functions for &phase_two
1.160 raeburn 8334: sub user_search_result {
1.221 raeburn 8335: my ($context,$srch) = @_;
1.160 raeburn 8336: my %allhomes;
8337: my %inst_matches;
8338: my %srch_results;
1.181 raeburn 8339: my ($response,$currstate,$forcenewuser,$dirsrchres);
1.183 raeburn 8340: $srch->{'srchterm'} =~ s/\s+/ /g;
1.176 raeburn 8341: if ($srch->{'srchby'} !~ /^(uname|lastname|lastfirst)$/) {
1.160 raeburn 8342: $response = &mt('Invalid search.');
8343: }
8344: if ($srch->{'srchin'} !~ /^(crs|dom|alc|instd)$/) {
8345: $response = &mt('Invalid search.');
8346: }
1.177 raeburn 8347: if ($srch->{'srchtype'} !~ /^(exact|contains|begins)$/) {
1.160 raeburn 8348: $response = &mt('Invalid search.');
8349: }
8350: if ($srch->{'srchterm'} eq '') {
8351: $response = &mt('You must enter a search term.');
8352: }
1.183 raeburn 8353: if ($srch->{'srchterm'} =~ /^\s+$/) {
8354: $response = &mt('Your search term must contain more than just spaces.');
8355: }
1.160 raeburn 8356: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'instd')) {
8357: if (($srch->{'srchdomain'} eq '') ||
1.163 albertel 8358: ! (&Apache::lonnet::domain($srch->{'srchdomain'}))) {
1.160 raeburn 8359: $response = &mt('You must specify a valid domain when searching in a domain or institutional directory.')
8360: }
8361: }
8362: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs') ||
8363: ($srch->{'srchin'} eq 'alc')) {
1.176 raeburn 8364: if ($srch->{'srchby'} eq 'uname') {
1.243 raeburn 8365: my $unamecheck = $srch->{'srchterm'};
8366: if ($srch->{'srchtype'} eq 'contains') {
8367: if ($unamecheck !~ /^\w/) {
8368: $unamecheck = 'a'.$unamecheck;
8369: }
8370: }
8371: if ($unamecheck !~ /^$match_username$/) {
1.176 raeburn 8372: $response = &mt('You must specify a valid username. Only the following are allowed: letters numbers - . @');
8373: }
1.160 raeburn 8374: }
8375: }
1.180 raeburn 8376: if ($response ne '') {
1.406.2.4 raeburn 8377: $response = '<span class="LC_warning">'.$response.'</span><br />';
1.180 raeburn 8378: }
1.160 raeburn 8379: if ($srch->{'srchin'} eq 'instd') {
1.406.2.3 raeburn 8380: my $instd_chk = &instdirectorysrch_check($srch);
1.160 raeburn 8381: if ($instd_chk ne 'ok') {
1.406.2.3 raeburn 8382: my $domd_chk = &domdirectorysrch_check($srch);
1.406.2.4 raeburn 8383: $response .= '<span class="LC_warning">'.$instd_chk.'</span><br />';
1.406.2.3 raeburn 8384: if ($domd_chk eq 'ok') {
1.406.2.4 raeburn 8385: $response .= &mt('You may want to search in the LON-CAPA domain instead of the institutional directory.');
1.406.2.3 raeburn 8386: }
1.406.2.5 raeburn 8387: $response .= '<br />';
1.406.2.3 raeburn 8388: }
8389: } else {
8390: unless (($context eq 'requestcrs') && ($srch->{'srchtype'} eq 'exact')) {
8391: my $domd_chk = &domdirectorysrch_check($srch);
1.406.2.14 raeburn 8392: if (($domd_chk ne 'ok') && ($env{'form.action'} ne 'accesslogs')) {
1.406.2.3 raeburn 8393: my $instd_chk = &instdirectorysrch_check($srch);
1.406.2.4 raeburn 8394: $response .= '<span class="LC_warning">'.$domd_chk.'</span><br />';
1.406.2.3 raeburn 8395: if ($instd_chk eq 'ok') {
1.406.2.4 raeburn 8396: $response .= &mt('You may want to search in the institutional directory instead of the LON-CAPA domain.');
1.406.2.3 raeburn 8397: }
1.406.2.5 raeburn 8398: $response .= '<br />';
1.406.2.3 raeburn 8399: }
1.160 raeburn 8400: }
8401: }
8402: if ($response ne '') {
1.180 raeburn 8403: return ($currstate,$response);
1.160 raeburn 8404: }
8405: if ($srch->{'srchby'} eq 'uname') {
8406: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs')) {
8407: if ($env{'form.forcenew'}) {
8408: if ($srch->{'srchdomain'} ne $env{'request.role.domain'}) {
8409: my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
8410: if ($uhome eq 'no_host') {
8411: my $domdesc = &Apache::lonnet::domain($env{'request.role.domain'},'description');
1.180 raeburn 8412: my $showdom = &display_domain_info($env{'request.role.domain'});
8413: $response = &mt('New users can only be created in the domain to which your current role belongs - [_1].',$showdom);
1.160 raeburn 8414: } else {
1.179 raeburn 8415: $currstate = 'modify';
1.160 raeburn 8416: }
8417: } else {
1.179 raeburn 8418: $currstate = 'modify';
1.160 raeburn 8419: }
8420: } else {
8421: if ($srch->{'srchin'} eq 'dom') {
1.162 raeburn 8422: if ($srch->{'srchtype'} eq 'exact') {
8423: my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
8424: if ($uhome eq 'no_host') {
1.179 raeburn 8425: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8426: &build_search_response($context,$srch,%srch_results);
1.162 raeburn 8427: } else {
1.179 raeburn 8428: $currstate = 'modify';
1.406.2.5 raeburn 8429: if ($env{'form.action'} eq 'accesslogs') {
8430: $currstate = 'activity';
8431: }
1.310 raeburn 8432: my $uname = $srch->{'srchterm'};
8433: my $udom = $srch->{'srchdomain'};
8434: $srch_results{$uname.':'.$udom} =
8435: { &Apache::lonnet::get('environment',
8436: ['firstname',
8437: 'lastname',
8438: 'permanentemail'],
8439: $udom,$uname)
8440: };
1.162 raeburn 8441: }
8442: } else {
8443: %srch_results = &Apache::lonnet::usersearch($srch);
1.179 raeburn 8444: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8445: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 8446: }
8447: } else {
1.167 albertel 8448: my $courseusers = &get_courseusers();
1.162 raeburn 8449: if ($srch->{'srchtype'} eq 'exact') {
1.167 albertel 8450: if (exists($courseusers->{$srch->{'srchterm'}.':'.$srch->{'srchdomain'}})) {
1.179 raeburn 8451: $currstate = 'modify';
1.162 raeburn 8452: } else {
1.179 raeburn 8453: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8454: &build_search_response($context,$srch,%srch_results);
1.162 raeburn 8455: }
1.160 raeburn 8456: } else {
1.167 albertel 8457: foreach my $user (keys(%$courseusers)) {
1.162 raeburn 8458: my ($cuname,$cudomain) = split(/:/,$user);
8459: if ($cudomain eq $srch->{'srchdomain'}) {
1.177 raeburn 8460: my $matched = 0;
8461: if ($srch->{'srchtype'} eq 'begins') {
8462: if ($cuname =~ /^\Q$srch->{'srchterm'}\E/i) {
8463: $matched = 1;
8464: }
8465: } else {
8466: if ($cuname =~ /\Q$srch->{'srchterm'}\E/i) {
8467: $matched = 1;
8468: }
8469: }
8470: if ($matched) {
1.167 albertel 8471: $srch_results{$user} =
8472: {&Apache::lonnet::get('environment',
8473: ['firstname',
8474: 'lastname',
1.194 albertel 8475: 'permanentemail'],
8476: $cudomain,$cuname)};
1.162 raeburn 8477: }
8478: }
8479: }
1.179 raeburn 8480: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8481: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 8482: }
8483: }
8484: }
8485: } elsif ($srch->{'srchin'} eq 'alc') {
1.179 raeburn 8486: $currstate = 'query';
1.160 raeburn 8487: } elsif ($srch->{'srchin'} eq 'instd') {
1.181 raeburn 8488: ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
8489: if ($dirsrchres eq 'ok') {
8490: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8491: &build_search_response($context,$srch,%srch_results);
1.181 raeburn 8492: } else {
8493: my $showdom = &display_domain_info($srch->{'srchdomain'});
8494: $response = '<span class="LC_warning">'.
8495: &mt('Institutional directory search is not available in domain: [_1]',$showdom).
8496: '</span><br />'.
8497: &mt('You may want to search in the LON-CAPA domain instead of the institutional directory.').
1.406.2.5 raeburn 8498: '<br />';
1.181 raeburn 8499: }
1.160 raeburn 8500: }
8501: } else {
8502: if ($srch->{'srchin'} eq 'dom') {
8503: %srch_results = &Apache::lonnet::usersearch($srch);
1.179 raeburn 8504: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8505: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 8506: } elsif ($srch->{'srchin'} eq 'crs') {
1.167 albertel 8507: my $courseusers = &get_courseusers();
8508: foreach my $user (keys(%$courseusers)) {
1.160 raeburn 8509: my ($uname,$udom) = split(/:/,$user);
8510: my %names = &Apache::loncommon::getnames($uname,$udom);
8511: my %emails = &Apache::loncommon::getemails($uname,$udom);
8512: if ($srch->{'srchby'} eq 'lastname') {
8513: if ((($srch->{'srchtype'} eq 'exact') &&
8514: ($names{'lastname'} eq $srch->{'srchterm'})) ||
1.177 raeburn 8515: (($srch->{'srchtype'} eq 'begins') &&
8516: ($names{'lastname'} =~ /^\Q$srch->{'srchterm'}\E/i)) ||
1.160 raeburn 8517: (($srch->{'srchtype'} eq 'contains') &&
8518: ($names{'lastname'} =~ /\Q$srch->{'srchterm'}\E/i))) {
8519: $srch_results{$user} = {firstname => $names{'firstname'},
8520: lastname => $names{'lastname'},
8521: permanentemail => $emails{'permanentemail'},
8522: };
8523: }
8524: } elsif ($srch->{'srchby'} eq 'lastfirst') {
8525: my ($srchlast,$srchfirst) = split(/,/,$srch->{'srchterm'});
1.177 raeburn 8526: $srchlast =~ s/\s+$//;
8527: $srchfirst =~ s/^\s+//;
1.160 raeburn 8528: if ($srch->{'srchtype'} eq 'exact') {
8529: if (($names{'lastname'} eq $srchlast) &&
8530: ($names{'firstname'} eq $srchfirst)) {
8531: $srch_results{$user} = {firstname => $names{'firstname'},
8532: lastname => $names{'lastname'},
8533: permanentemail => $emails{'permanentemail'},
8534:
8535: };
8536: }
1.177 raeburn 8537: } elsif ($srch->{'srchtype'} eq 'begins') {
8538: if (($names{'lastname'} =~ /^\Q$srchlast\E/i) &&
8539: ($names{'firstname'} =~ /^\Q$srchfirst\E/i)) {
8540: $srch_results{$user} = {firstname => $names{'firstname'},
8541: lastname => $names{'lastname'},
8542: permanentemail => $emails{'permanentemail'},
8543: };
8544: }
8545: } else {
1.160 raeburn 8546: if (($names{'lastname'} =~ /\Q$srchlast\E/i) &&
8547: ($names{'firstname'} =~ /\Q$srchfirst\E/i)) {
8548: $srch_results{$user} = {firstname => $names{'firstname'},
8549: lastname => $names{'lastname'},
8550: permanentemail => $emails{'permanentemail'},
8551: };
8552: }
8553: }
8554: }
8555: }
1.179 raeburn 8556: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8557: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 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 {
1.406.2.5 raeburn 8566: my $showdom = &display_domain_info($srch->{'srchdomain'});
8567: $response = '<span class="LC_warning">'.
1.181 raeburn 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: }
1.179 raeburn 8575: return ($currstate,$response,$forcenewuser,\%srch_results);
1.160 raeburn 8576: }
8577:
1.406.2.3 raeburn 8578: sub domdirectorysrch_check {
8579: my ($srch) = @_;
8580: my $response;
8581: my %dom_inst_srch = &Apache::lonnet::get_dom('configuration',
8582: ['directorysrch'],$srch->{'srchdomain'});
8583: my $showdom = &display_domain_info($srch->{'srchdomain'});
8584: if (ref($dom_inst_srch{'directorysrch'}) eq 'HASH') {
8585: if ($dom_inst_srch{'directorysrch'}{'lcavailable'} eq '0') {
8586: return &mt('LON-CAPA directory search is not available in domain: [_1]',$showdom);
8587: }
8588: if ($dom_inst_srch{'directorysrch'}{'lclocalonly'}) {
8589: if ($env{'request.role.domain'} ne $srch->{'srchdomain'}) {
8590: return &mt('LON-CAPA directory search in domain: [_1] is only allowed for users with a current role in the domain.',$showdom);
8591: }
8592: }
8593: }
8594: return 'ok';
8595: }
8596:
8597: sub instdirectorysrch_check {
1.160 raeburn 8598: my ($srch) = @_;
8599: my $can_search = 0;
8600: my $response;
8601: my %dom_inst_srch = &Apache::lonnet::get_dom('configuration',
8602: ['directorysrch'],$srch->{'srchdomain'});
1.180 raeburn 8603: my $showdom = &display_domain_info($srch->{'srchdomain'});
1.160 raeburn 8604: if (ref($dom_inst_srch{'directorysrch'}) eq 'HASH') {
8605: if (!$dom_inst_srch{'directorysrch'}{'available'}) {
1.180 raeburn 8606: return &mt('Institutional directory search is not available in domain: [_1]',$showdom);
1.160 raeburn 8607: }
8608: if ($dom_inst_srch{'directorysrch'}{'localonly'}) {
8609: if ($env{'request.role.domain'} ne $srch->{'srchdomain'}) {
1.180 raeburn 8610: return &mt('Institutional directory search in domain: [_1] is only allowed for users with a current role in the domain.',$showdom);
1.160 raeburn 8611: }
8612: my @usertypes = split(/:/,$env{'environment.inststatus'});
8613: if (!@usertypes) {
8614: push(@usertypes,'default');
8615: }
8616: if (ref($dom_inst_srch{'directorysrch'}{'cansearch'}) eq 'ARRAY') {
8617: foreach my $type (@usertypes) {
8618: if (grep(/^\Q$type\E$/,@{$dom_inst_srch{'directorysrch'}{'cansearch'}})) {
8619: $can_search = 1;
8620: last;
8621: }
8622: }
8623: }
8624: if (!$can_search) {
8625: my ($insttypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($srch->{'srchdomain'});
8626: my @longtypes;
8627: foreach my $item (@usertypes) {
1.229 raeburn 8628: if (defined($insttypes->{$item})) {
8629: push (@longtypes,$insttypes->{$item});
8630: } elsif ($item eq 'default') {
8631: push (@longtypes,&mt('other'));
8632: }
1.160 raeburn 8633: }
8634: my $insttype_str = join(', ',@longtypes);
1.180 raeburn 8635: return &mt('Institutional directory search in domain: [_1] is not available to your user type: ',$showdom).$insttype_str;
1.229 raeburn 8636: }
1.160 raeburn 8637: } else {
8638: $can_search = 1;
8639: }
8640: } else {
1.180 raeburn 8641: return &mt('Institutional directory search has not been configured for domain: [_1]',$showdom);
1.160 raeburn 8642: }
8643: my %longtext = &Apache::lonlocal::texthash (
1.167 albertel 8644: uname => 'username',
1.160 raeburn 8645: lastfirst => 'last name, first name',
1.167 albertel 8646: lastname => 'last name',
1.172 raeburn 8647: contains => 'contains',
1.178 raeburn 8648: exact => 'as exact match to',
8649: begins => 'begins with',
1.160 raeburn 8650: );
8651: if ($can_search) {
8652: if (ref($dom_inst_srch{'directorysrch'}{'searchby'}) eq 'ARRAY') {
8653: if (!grep(/^\Q$srch->{'srchby'}\E$/,@{$dom_inst_srch{'directorysrch'}{'searchby'}})) {
1.180 raeburn 8654: return &mt('Institutional directory search in domain: [_1] is not available for searching by "[_2]"',$showdom,$longtext{$srch->{'srchby'}});
1.160 raeburn 8655: }
8656: } else {
1.180 raeburn 8657: return &mt('Institutional directory search in domain: [_1] is not available.', $showdom);
1.160 raeburn 8658: }
8659: }
8660: if ($can_search) {
1.178 raeburn 8661: if (ref($dom_inst_srch{'directorysrch'}{'searchtypes'}) eq 'ARRAY') {
8662: if (grep(/^\Q$srch->{'srchtype'}\E/,@{$dom_inst_srch{'directorysrch'}{'searchtypes'}})) {
8663: return 'ok';
8664: } else {
1.180 raeburn 8665: return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
1.178 raeburn 8666: }
8667: } else {
8668: if ((($dom_inst_srch{'directorysrch'}{'searchtypes'} eq 'specify') &&
8669: ($srch->{'srchtype'} eq 'exact' || $srch->{'srchtype'} eq 'contains')) ||
8670: ($dom_inst_srch{'directorysrch'}{'searchtypes'} eq $srch->{'srchtype'})) {
8671: return 'ok';
8672: } else {
1.180 raeburn 8673: return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
1.178 raeburn 8674: }
1.160 raeburn 8675: }
8676: }
8677: }
8678:
8679: sub get_courseusers {
8680: my %advhash;
1.167 albertel 8681: my $classlist = &Apache::loncoursedata::get_classlist();
1.160 raeburn 8682: my %coursepersonnel=&Apache::lonnet::get_course_adv_roles();
8683: foreach my $role (sort(keys(%coursepersonnel))) {
8684: foreach my $user (split(/\,/,$coursepersonnel{$role})) {
1.167 albertel 8685: if (!exists($classlist->{$user})) {
8686: $classlist->{$user} = [];
8687: }
1.160 raeburn 8688: }
8689: }
1.167 albertel 8690: return $classlist;
1.160 raeburn 8691: }
8692:
8693: sub build_search_response {
1.221 raeburn 8694: my ($context,$srch,%srch_results) = @_;
1.179 raeburn 8695: my ($currstate,$response,$forcenewuser);
1.160 raeburn 8696: my %names = (
1.330 bisitz 8697: 'uname' => 'username',
8698: 'lastname' => 'last name',
1.160 raeburn 8699: 'lastfirst' => 'last name, first name',
1.330 bisitz 8700: 'crs' => 'this course',
8701: 'dom' => 'LON-CAPA domain',
8702: 'instd' => 'the institutional directory for domain',
1.160 raeburn 8703: );
8704:
8705: my %single = (
1.180 raeburn 8706: begins => 'A match',
1.160 raeburn 8707: contains => 'A match',
1.180 raeburn 8708: exact => 'An exact match',
1.160 raeburn 8709: );
8710: my %nomatch = (
1.180 raeburn 8711: begins => 'No match',
1.160 raeburn 8712: contains => 'No match',
1.180 raeburn 8713: exact => 'No exact match',
1.160 raeburn 8714: );
8715: if (keys(%srch_results) > 1) {
1.179 raeburn 8716: $currstate = 'select';
1.160 raeburn 8717: } else {
8718: if (keys(%srch_results) == 1) {
1.406.2.5 raeburn 8719: if ($env{'form.action'} eq 'accesslogs') {
8720: $currstate = 'activity';
8721: } else {
8722: $currstate = 'modify';
8723: }
1.180 raeburn 8724: $response = &mt("$single{$srch->{'srchtype'}} was found for the $names{$srch->{'srchby'}} ([_1]) in $names{$srch->{'srchin'}}.",$srch->{'srchterm'});
8725: if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
1.330 bisitz 8726: $response .= ': '.&display_domain_info($srch->{'srchdomain'});
1.180 raeburn 8727: }
1.330 bisitz 8728: } else { # Search has nothing found. Prepare message to user.
8729: $response = '<span class="LC_warning">';
1.180 raeburn 8730: if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
1.330 bisitz 8731: $response .= &mt("$nomatch{$srch->{'srchtype'}} found for the $names{$srch->{'srchby'}} [_1] in $names{$srch->{'srchin'}}: [_2]",
8732: '<b>'.$srch->{'srchterm'}.'</b>',
8733: &display_domain_info($srch->{'srchdomain'}));
8734: } else {
8735: $response .= &mt("$nomatch{$srch->{'srchtype'}} found for the $names{$srch->{'srchby'}} [_1] in $names{$srch->{'srchin'}}.",
8736: '<b>'.$srch->{'srchterm'}.'</b>');
1.180 raeburn 8737: }
8738: $response .= '</span>';
1.330 bisitz 8739:
1.160 raeburn 8740: if ($srch->{'srchin'} ne 'alc') {
8741: $forcenewuser = 1;
8742: my $cansrchinst = 0;
1.406.2.14 raeburn 8743: if (($srch->{'srchdomain'}) && ($env{'form.action'} ne 'accesslogs')) {
1.160 raeburn 8744: my %domconfig = &Apache::lonnet::get_dom('configuration',['directorysrch'],$srch->{'srchdomain'});
8745: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
8746: if ($domconfig{'directorysrch'}{'available'}) {
8747: $cansrchinst = 1;
8748: }
8749: }
8750: }
1.180 raeburn 8751: if ((($srch->{'srchby'} eq 'lastfirst') ||
8752: ($srch->{'srchby'} eq 'lastname')) &&
8753: ($srch->{'srchin'} eq 'dom')) {
8754: if ($cansrchinst) {
8755: $response .= '<br />'.&mt('You may want to broaden your search to a search of the institutional directory for the domain.');
1.160 raeburn 8756: }
8757: }
1.180 raeburn 8758: if ($srch->{'srchin'} eq 'crs') {
8759: $response .= '<br />'.&mt('You may want to broaden your search to the selected LON-CAPA domain.');
8760: }
8761: }
1.305 raeburn 8762: my $createdom = $env{'request.role.domain'};
8763: if ($context eq 'requestcrs') {
8764: if ($env{'form.coursedom'} ne '') {
8765: $createdom = $env{'form.coursedom'};
8766: }
8767: }
1.406.2.5 raeburn 8768: unless (($env{'form.action'} eq 'accesslogs') || (($srch->{'srchby'} eq 'uname') && ($srch->{'srchin'} eq 'dom') &&
8769: ($srch->{'srchtype'} eq 'exact') && ($srch->{'srchdomain'} eq $createdom))) {
1.221 raeburn 8770: my $cancreate =
1.305 raeburn 8771: &Apache::lonuserutils::can_create_user($createdom,$context);
8772: my $targetdom = '<span class="LC_cusr_emph">'.$createdom.'</span>';
1.221 raeburn 8773: if ($cancreate) {
1.305 raeburn 8774: my $showdom = &display_domain_info($createdom);
1.266 bisitz 8775: $response .= '<br /><br />'
8776: .'<b>'.&mt('To add a new user:').'</b>'
1.305 raeburn 8777: .'<br />';
8778: if ($context eq 'requestcrs') {
8779: $response .= &mt("(You can only define new users in the new course's domain - [_1])",$targetdom);
8780: } else {
8781: $response .= &mt("(You can only create new users in your current role's domain - [_1])",$targetdom);
8782: }
8783: $response .='<ul><li>'
1.266 bisitz 8784: .&mt("Set 'Domain/institution to search' to: [_1]",'<span class="LC_cusr_emph">'.$showdom.'</span>')
8785: .'</li><li>'
8786: .&mt("Set 'Search criteria' to: [_1]username is ..... in selected LON-CAPA domain[_2]",'<span class="LC_cusr_emph">','</span>')
8787: .'</li><li>'
8788: .&mt('Provide the proposed username')
8789: .'</li><li>'
8790: .&mt("Click 'Search'")
8791: .'</li></ul><br />';
1.221 raeburn 8792: } else {
1.406.2.7 raeburn 8793: unless (($context eq 'domain') && ($env{'form.action'} eq 'singleuser')) {
8794: my $helplink = ' href="javascript:helpMenu('."'display'".')"';
8795: $response .= '<br /><br />';
8796: if ($context eq 'requestcrs') {
8797: $response .= &mt("You are not authorized to define new users in the new course's domain - [_1].",$targetdom);
8798: } else {
8799: $response .= &mt("You are not authorized to create new users in your current role's domain - [_1].",$targetdom);
8800: }
8801: $response .= '<br />'
8802: .&mt('Please contact the [_1]helpdesk[_2] if you need to create a new user.'
8803: ,' <a'.$helplink.'>'
8804: ,'</a>')
8805: .'<br />';
1.305 raeburn 8806: }
1.221 raeburn 8807: }
1.160 raeburn 8808: }
8809: }
8810: }
1.179 raeburn 8811: return ($currstate,$response,$forcenewuser);
1.160 raeburn 8812: }
8813:
1.180 raeburn 8814: sub display_domain_info {
8815: my ($dom) = @_;
8816: my $output = $dom;
8817: if ($dom ne '') {
8818: my $domdesc = &Apache::lonnet::domain($dom,'description');
8819: if ($domdesc ne '') {
8820: $output .= ' <span class="LC_cusr_emph">('.$domdesc.')</span>';
8821: }
8822: }
8823: return $output;
8824: }
8825:
1.160 raeburn 8826: sub crumb_utilities {
8827: my %elements = (
8828: crtuser => {
8829: srchterm => 'text',
1.172 raeburn 8830: srchin => 'selectbox',
1.160 raeburn 8831: srchby => 'selectbox',
8832: srchtype => 'selectbox',
8833: srchdomain => 'selectbox',
8834: },
1.207 raeburn 8835: crtusername => {
8836: srchterm => 'text',
8837: srchdomain => 'selectbox',
8838: },
1.160 raeburn 8839: docustom => {
8840: rolename => 'selectbox',
8841: newrolename => 'textbox',
8842: },
1.179 raeburn 8843: studentform => {
8844: srchterm => 'text',
8845: srchin => 'selectbox',
8846: srchby => 'selectbox',
8847: srchtype => 'selectbox',
8848: srchdomain => 'selectbox',
8849: },
1.160 raeburn 8850: );
8851:
8852: my $jsback .= qq|
8853: function backPage(formname,prevphase,prevstate) {
1.211 raeburn 8854: if (typeof prevphase == 'undefined') {
8855: formname.phase.value = '';
8856: }
8857: else {
8858: formname.phase.value = prevphase;
8859: }
8860: if (typeof prevstate == 'undefined') {
8861: formname.currstate.value = '';
8862: }
8863: else {
8864: formname.currstate.value = prevstate;
8865: }
1.160 raeburn 8866: formname.submit();
8867: }
8868: |;
8869: return ($jsback,\%elements);
8870: }
8871:
1.26 matthew 8872: sub course_level_table {
1.375 raeburn 8873: my ($inccourses,$showcredits,$defaultcredits) = @_;
8874: return unless (ref($inccourses) eq 'HASH');
1.26 matthew 8875: my $table = '';
1.62 www 8876: # Custom Roles?
8877:
1.190 raeburn 8878: my %customroles=&Apache::lonuserutils::my_custom_roles();
1.89 raeburn 8879: my %lt=&Apache::lonlocal::texthash(
8880: 'exs' => "Existing sections",
8881: 'new' => "Define new section",
8882: 'ssd' => "Set Start Date",
8883: 'sed' => "Set End Date",
1.131 raeburn 8884: 'crl' => "Course Level",
1.89 raeburn 8885: 'act' => "Activate",
8886: 'rol' => "Role",
8887: 'ext' => "Extent",
1.113 raeburn 8888: 'grs' => "Section",
1.375 raeburn 8889: 'crd' => "Credits",
1.89 raeburn 8890: 'sta' => "Start",
8891: 'end' => "End"
8892: );
1.62 www 8893:
1.375 raeburn 8894: foreach my $protectedcourse (sort(keys(%{$inccourses}))) {
1.135 raeburn 8895: my $thiscourse=$protectedcourse;
1.26 matthew 8896: $thiscourse=~s:_:/:g;
8897: my %coursedata=&Apache::lonnet::coursedescription($thiscourse);
1.365 raeburn 8898: my $isowner = &Apache::lonuserutils::is_courseowner($protectedcourse,$coursedata{'internal.courseowner'});
1.26 matthew 8899: my $area=$coursedata{'description'};
1.321 raeburn 8900: my $crstype=$coursedata{'type'};
1.135 raeburn 8901: if (!defined($area)) { $area=&mt('Unavailable course').': '.$protectedcourse; }
1.89 raeburn 8902: my ($domain,$cnum)=split(/\//,$thiscourse);
1.115 albertel 8903: my %sections_count;
1.101 albertel 8904: if (defined($env{'request.course.id'})) {
8905: if ($env{'request.course.id'} eq $domain.'_'.$cnum) {
1.115 albertel 8906: %sections_count =
8907: &Apache::loncommon::get_sections($domain,$cnum);
1.92 raeburn 8908: }
8909: }
1.321 raeburn 8910: my @roles = &Apache::lonuserutils::roles_by_context('course','',$crstype);
1.213 raeburn 8911: foreach my $role (@roles) {
1.321 raeburn 8912: my $plrole=&Apache::lonnet::plaintext($role,$crstype);
1.329 raeburn 8913: if ((&Apache::lonnet::allowed('c'.$role,$thiscourse)) ||
8914: ((($role eq 'cc') || ($role eq 'co')) && ($isowner))) {
1.221 raeburn 8915: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
1.375 raeburn 8916: $plrole,\%sections_count,\%lt,
1.402 raeburn 8917: $showcredits,$defaultcredits,$crstype);
1.221 raeburn 8918: } elsif ($env{'request.course.sec'} ne '') {
8919: if (&Apache::lonnet::allowed('c'.$role,$thiscourse.'/'.
8920: $env{'request.course.sec'})) {
8921: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
1.375 raeburn 8922: $plrole,\%sections_count,\%lt,
1.402 raeburn 8923: $showcredits,$defaultcredits,$crstype);
1.26 matthew 8924: }
8925: }
8926: }
1.221 raeburn 8927: if (&Apache::lonnet::allowed('ccr',$thiscourse)) {
1.324 raeburn 8928: foreach my $cust (sort(keys(%customroles))) {
8929: next if ($crstype eq 'Community' && $customroles{$cust} =~ /bre\&S/);
1.221 raeburn 8930: my $role = 'cr_cr_'.$env{'user.domain'}.'_'.$env{'user.name'}.'_'.$cust;
8931: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
1.402 raeburn 8932: $cust,\%sections_count,\%lt,
8933: $showcredits,$defaultcredits,$crstype);
1.221 raeburn 8934: }
1.62 www 8935: }
1.26 matthew 8936: }
8937: return '' if ($table eq ''); # return nothing if there is nothing
8938: # in the table
1.188 raeburn 8939: my $result;
8940: if (!$env{'request.course.id'}) {
8941: $result = '<h4>'.$lt{'crl'}.'</h4>'."\n";
8942: }
8943: $result .=
1.136 raeburn 8944: &Apache::loncommon::start_data_table().
8945: &Apache::loncommon::start_data_table_header_row().
1.375 raeburn 8946: '<th>'.$lt{'act'}.'</th><th>'.$lt{'rol'}.'</th>'."\n".
1.402 raeburn 8947: '<th>'.$lt{'ext'}.'</th><th>'."\n";
8948: if ($showcredits) {
8949: $result .= $lt{'crd'}.'</th>';
8950: }
8951: $result .=
1.375 raeburn 8952: '<th>'.$lt{'grs'}.'</th><th>'.$lt{'sta'}.'</th>'."\n".
8953: '<th>'.$lt{'end'}.'</th>'.
1.136 raeburn 8954: &Apache::loncommon::end_data_table_header_row().
8955: $table.
8956: &Apache::loncommon::end_data_table();
1.26 matthew 8957: return $result;
8958: }
1.88 raeburn 8959:
1.221 raeburn 8960: sub course_level_row {
1.375 raeburn 8961: my ($protectedcourse,$role,$area,$domain,$plrole,$sections_count,
1.402 raeburn 8962: $lt,$showcredits,$defaultcredits,$crstype) = @_;
1.375 raeburn 8963: my $creditem;
1.222 raeburn 8964: my $row = &Apache::loncommon::start_data_table_row().
8965: ' <td><input type="checkbox" name="act_'.
8966: $protectedcourse.'_'.$role.'" /></td>'."\n".
8967: ' <td>'.$plrole.'</td>'."\n".
8968: ' <td>'.$area.'<br />Domain: '.$domain.'</td>'."\n";
1.402 raeburn 8969: if (($showcredits) && ($role eq 'st') && ($crstype eq 'Course')) {
1.375 raeburn 8970: $row .=
8971: '<td><input type="text" name="credits_'.$protectedcourse.'_'.
8972: $role.'" size="3" value="'.$defaultcredits.'" /></td>';
8973: } else {
8974: $row .= '<td> </td>';
8975: }
1.322 raeburn 8976: if (($role eq 'cc') || ($role eq 'co')) {
1.222 raeburn 8977: $row .= '<td> </td>';
1.221 raeburn 8978: } elsif ($env{'request.course.sec'} ne '') {
1.222 raeburn 8979: $row .= ' <td><input type="hidden" value="'.
8980: $env{'request.course.sec'}.'" '.
8981: 'name="sec_'.$protectedcourse.'_'.$role.'" />'.
8982: $env{'request.course.sec'}.'</td>';
1.221 raeburn 8983: } else {
8984: if (ref($sections_count) eq 'HASH') {
8985: my $currsec =
8986: &Apache::lonuserutils::course_sections($sections_count,
8987: $protectedcourse.'_'.$role);
1.222 raeburn 8988: $row .= '<td><table class="LC_createuser">'."\n".
8989: '<tr class="LC_section_row">'."\n".
8990: ' <td valign="top">'.$lt->{'exs'}.'<br />'.
8991: $currsec.'</td>'."\n".
8992: ' <td> </td>'."\n".
8993: ' <td valign="top"> '.$lt->{'new'}.'<br />'.
1.221 raeburn 8994: '<input type="text" name="newsec_'.$protectedcourse.'_'.$role.
8995: '" value="" />'.
8996: '<input type="hidden" '.
8997: 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'."\n".
1.222 raeburn 8998: '</tr></table></td>'."\n";
1.221 raeburn 8999: } else {
1.222 raeburn 9000: $row .= '<td><input type="text" size="10" '.
1.375 raeburn 9001: 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'."\n";
1.221 raeburn 9002: }
9003: }
1.222 raeburn 9004: $row .= <<ENDTIMEENTRY;
9005: <td><input type="hidden" name="start_$protectedcourse\_$role" value="" />
1.221 raeburn 9006: <a href=
9007: "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 9008: <td><input type="hidden" name="end_$protectedcourse\_$role" value="" />
1.221 raeburn 9009: <a href=
9010: "javascript:pjump('date_end','End Date $plrole',document.cu.end_$protectedcourse\_$role.value,'end_$protectedcourse\_$role','cu.pres','dateset')">$lt->{'sed'}</a></td>
9011: ENDTIMEENTRY
1.222 raeburn 9012: $row .= &Apache::loncommon::end_data_table_row();
9013: return $row;
1.221 raeburn 9014: }
9015:
1.88 raeburn 9016: sub course_level_dc {
1.375 raeburn 9017: my ($dcdom,$showcredits) = @_;
1.190 raeburn 9018: my %customroles=&Apache::lonuserutils::my_custom_roles();
1.213 raeburn 9019: my @roles = &Apache::lonuserutils::roles_by_context('course');
1.88 raeburn 9020: my $hiddenitems = '<input type="hidden" name="dcdomain" value="'.$dcdom.'" />'.
9021: '<input type="hidden" name="origdom" value="'.$dcdom.'" />'.
1.133 raeburn 9022: '<input type="hidden" name="dccourse" value="" />';
1.355 www 9023: my $courseform=&Apache::loncommon::selectcourse_link
1.356 raeburn 9024: ('cu','dccourse','dcdomain','coursedesc',undef,undef,'Select','crstype');
1.375 raeburn 9025: my $credit_elem;
9026: if ($showcredits) {
9027: $credit_elem = 'credits';
9028: }
9029: my $cb_jscript = &Apache::loncommon::coursebrowser_javascript($dcdom,'currsec','cu','role','Course/Community Browser',$credit_elem);
1.88 raeburn 9030: my %lt=&Apache::lonlocal::texthash(
9031: 'rol' => "Role",
1.113 raeburn 9032: 'grs' => "Section",
1.88 raeburn 9033: 'exs' => "Existing sections",
9034: 'new' => "Define new section",
9035: 'sta' => "Start",
9036: 'end' => "End",
9037: 'ssd' => "Set Start Date",
1.355 www 9038: 'sed' => "Set End Date",
1.375 raeburn 9039: 'scc' => "Course/Community",
9040: 'crd' => "Credits",
1.88 raeburn 9041: );
1.323 raeburn 9042: my $header = '<h4>'.&mt('Course/Community Level').'</h4>'.
1.136 raeburn 9043: &Apache::loncommon::start_data_table().
9044: &Apache::loncommon::start_data_table_header_row().
1.375 raeburn 9045: '<th>'.$lt{'scc'}.'</th><th>'.$lt{'rol'}.'</th>'."\n".
1.397 bisitz 9046: '<th>'.$lt{'grs'}.'</th>'."\n";
9047: $header .= '<th>'.$lt{'crd'}.'</th>'."\n" if ($showcredits);
9048: $header .= '<th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'."\n".
1.136 raeburn 9049: &Apache::loncommon::end_data_table_header_row();
1.143 raeburn 9050: my $otheritems = &Apache::loncommon::start_data_table_row()."\n".
1.356 raeburn 9051: '<td><br /><span class="LC_nobreak"><input type="text" name="coursedesc" value="" onfocus="this.blur();opencrsbrowser('."'cu','dccourse','dcdomain','coursedesc','','','','crstype'".')" />'.
9052: $courseform.(' ' x4).'</span></td>'."\n".
1.389 bisitz 9053: '<td valign="top"><br /><select name="role">'."\n";
1.213 raeburn 9054: foreach my $role (@roles) {
1.135 raeburn 9055: my $plrole=&Apache::lonnet::plaintext($role);
1.389 bisitz 9056: $otheritems .= ' <option value="'.$role.'">'.$plrole.'</option>';
1.88 raeburn 9057: }
1.404 raeburn 9058: if ( keys(%customroles) > 0) {
9059: foreach my $cust (sort(keys(%customroles))) {
1.101 albertel 9060: my $custrole='cr_cr_'.$env{'user.domain'}.
1.135 raeburn 9061: '_'.$env{'user.name'}.'_'.$cust;
1.389 bisitz 9062: $otheritems .= ' <option value="'.$custrole.'">'.$cust.'</option>';
1.88 raeburn 9063: }
9064: }
9065: $otheritems .= '</select></td><td>'.
9066: '<table border="0" cellspacing="0" cellpadding="0">'.
9067: '<tr><td valign="top"><b>'.$lt{'exs'}.'</b><br /><select name="currsec">'.
1.389 bisitz 9068: ' <option value=""><--'.&mt('Pick course first').'</option></select></td>'.
1.88 raeburn 9069: '<td> </td>'.
9070: '<td valign="top"> <b>'.$lt{'new'}.'</b><br />'.
1.113 raeburn 9071: '<input type="text" name="newsec" value="" />'.
1.237 raeburn 9072: '<input type="hidden" name="section" value="" />'.
1.323 raeburn 9073: '<input type="hidden" name="groups" value="" />'.
9074: '<input type="hidden" name="crstype" value="" /></td>'.
1.375 raeburn 9075: '</tr></table></td>'."\n";
9076: if ($showcredits) {
9077: $otheritems .= '<td><br />'."\n".
1.397 bisitz 9078: '<input type="text" size="3" name="credits" value="" /></td>'."\n";
1.375 raeburn 9079: }
1.88 raeburn 9080: $otheritems .= <<ENDTIMEENTRY;
1.323 raeburn 9081: <td><br /><input type="hidden" name="start" value='' />
1.88 raeburn 9082: <a href=
9083: "javascript:pjump('date_start','Start Date',document.cu.start.value,'start','cu.pres','dateset')">$lt{'ssd'}</a></td>
1.323 raeburn 9084: <td><br /><input type="hidden" name="end" value='' />
1.88 raeburn 9085: <a href=
9086: "javascript:pjump('date_end','End Date',document.cu.end.value,'end','cu.pres','dateset')">$lt{'sed'}</a></td>
9087: ENDTIMEENTRY
1.136 raeburn 9088: $otheritems .= &Apache::loncommon::end_data_table_row().
9089: &Apache::loncommon::end_data_table()."\n";
1.88 raeburn 9090: return $cb_jscript.$header.$hiddenitems.$otheritems;
9091: }
9092:
1.237 raeburn 9093: sub update_selfenroll_config {
1.400 raeburn 9094: my ($r,$cid,$cdom,$cnum,$context,$crstype,$currsettings) = @_;
1.398 raeburn 9095: return unless (ref($currsettings) eq 'HASH');
9096: my ($row,$lt) = &Apache::lonuserutils::get_selfenroll_titles();
9097: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
1.237 raeburn 9098: my (%changes,%warning);
1.241 raeburn 9099: my $curr_types;
1.400 raeburn 9100: my %noedit;
9101: unless ($context eq 'domain') {
9102: %noedit = &get_noedit_fields($cdom,$cnum,$crstype,$row);
9103: }
1.237 raeburn 9104: if (ref($row) eq 'ARRAY') {
9105: foreach my $item (@{$row}) {
1.400 raeburn 9106: next if ($noedit{$item});
1.237 raeburn 9107: if ($item eq 'enroll_dates') {
9108: my (%currenrolldate,%newenrolldate);
9109: foreach my $type ('start','end') {
1.398 raeburn 9110: $currenrolldate{$type} = $currsettings->{'selfenroll_'.$type.'_date'};
1.237 raeburn 9111: $newenrolldate{$type} = &Apache::lonhtmlcommon::get_date_from_form('selfenroll_'.$type.'_date');
9112: if ($newenrolldate{$type} ne $currenrolldate{$type}) {
9113: $changes{'internal.selfenroll_'.$type.'_date'} = $newenrolldate{$type};
9114: }
9115: }
9116: } elsif ($item eq 'access_dates') {
9117: my (%currdate,%newdate);
9118: foreach my $type ('start','end') {
1.398 raeburn 9119: $currdate{$type} = $currsettings->{'selfenroll_'.$type.'_access'};
1.237 raeburn 9120: $newdate{$type} = &Apache::lonhtmlcommon::get_date_from_form('selfenroll_'.$type.'_access');
9121: if ($newdate{$type} ne $currdate{$type}) {
9122: $changes{'internal.selfenroll_'.$type.'_access'} = $newdate{$type};
9123: }
9124: }
1.241 raeburn 9125: } elsif ($item eq 'types') {
1.398 raeburn 9126: $curr_types = $currsettings->{'selfenroll_'.$item};
1.241 raeburn 9127: if ($env{'form.selfenroll_all'}) {
9128: if ($curr_types ne '*') {
9129: $changes{'internal.selfenroll_types'} = '*';
9130: } else {
9131: next;
9132: }
9133: } else {
1.249 raeburn 9134: my %currdoms;
1.241 raeburn 9135: my @entries = split(/;/,$curr_types);
9136: my @deletedoms = &Apache::loncommon::get_env_multiple('form.selfenroll_delete');
1.249 raeburn 9137: my @activations = &Apache::loncommon::get_env_multiple('form.selfenroll_activate');
1.241 raeburn 9138: my $newnum = 0;
1.249 raeburn 9139: my @latesttypes;
9140: foreach my $num (@activations) {
9141: my @types = &Apache::loncommon::get_env_multiple('form.selfenroll_types_'.$num);
9142: if (@types > 0) {
1.241 raeburn 9143: @types = sort(@types);
9144: my $typestr = join(',',@types);
1.249 raeburn 9145: my $typedom = $env{'form.selfenroll_dom_'.$num};
9146: $latesttypes[$newnum] = $typedom.':'.$typestr;
9147: $currdoms{$typedom} = 1;
1.241 raeburn 9148: $newnum ++;
9149: }
9150: }
1.338 raeburn 9151: for (my $j=0; $j<$env{'form.selfenroll_types_total'}; $j++) {
9152: if ((!grep(/^$j$/,@deletedoms)) && (!grep(/^$j$/,@activations))) {
1.249 raeburn 9153: my @types = &Apache::loncommon::get_env_multiple('form.selfenroll_types_'.$j);
9154: if (@types > 0) {
9155: @types = sort(@types);
9156: my $typestr = join(',',@types);
9157: my $typedom = $env{'form.selfenroll_dom_'.$j};
9158: $latesttypes[$newnum] = $typedom.':'.$typestr;
9159: $currdoms{$typedom} = 1;
9160: $newnum ++;
9161: }
9162: }
9163: }
9164: if ($env{'form.selfenroll_newdom'} ne '') {
9165: my $typedom = $env{'form.selfenroll_newdom'};
9166: if ((!defined($currdoms{$typedom})) &&
9167: (&Apache::lonnet::domain($typedom) ne '')) {
9168: my $typestr;
9169: my ($othertitle,$usertypes,$types) =
9170: &Apache::loncommon::sorted_inst_types($typedom);
9171: my $othervalue = 'any';
9172: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
9173: if (@{$types} > 0) {
1.257 raeburn 9174: my @esc_types = map { &escape($_); } @{$types};
1.249 raeburn 9175: $othervalue = 'other';
1.258 raeburn 9176: $typestr = join(',',(@esc_types,$othervalue));
1.249 raeburn 9177: }
9178: $typestr = $othervalue;
9179: } else {
9180: $typestr = $othervalue;
9181: }
9182: $latesttypes[$newnum] = $typedom.':'.$typestr;
9183: $newnum ++ ;
9184: }
9185: }
1.241 raeburn 9186: my $selfenroll_types = join(';',@latesttypes);
9187: if ($selfenroll_types ne $curr_types) {
9188: $changes{'internal.selfenroll_types'} = $selfenroll_types;
9189: }
9190: }
1.276 raeburn 9191: } elsif ($item eq 'limit') {
9192: my $newlimit = $env{'form.selfenroll_limit'};
9193: my $newcap = $env{'form.selfenroll_cap'};
9194: $newcap =~s/\s+//g;
1.398 raeburn 9195: my $currlimit = $currsettings->{'selfenroll_limit'};
1.276 raeburn 9196: $currlimit = 'none' if ($currlimit eq '');
1.398 raeburn 9197: my $currcap = $currsettings->{'selfenroll_cap'};
1.276 raeburn 9198: if ($newlimit ne $currlimit) {
9199: if ($newlimit ne 'none') {
9200: if ($newcap =~ /^\d+$/) {
9201: if ($newcap ne $currcap) {
9202: $changes{'internal.selfenroll_cap'} = $newcap;
9203: }
9204: $changes{'internal.selfenroll_limit'} = $newlimit;
9205: } else {
1.398 raeburn 9206: $warning{$item} = &mt('Maximum enrollment setting unchanged.').'<br />'.
9207: &mt('The value provided was invalid - it must be a positive integer if enrollment is being limited.');
1.276 raeburn 9208: }
9209: } elsif ($currcap ne '') {
9210: $changes{'internal.selfenroll_cap'} = '';
9211: $changes{'internal.selfenroll_limit'} = $newlimit;
9212: }
9213: } elsif ($currlimit ne 'none') {
9214: if ($newcap =~ /^\d+$/) {
9215: if ($newcap ne $currcap) {
9216: $changes{'internal.selfenroll_cap'} = $newcap;
9217: }
9218: } else {
1.398 raeburn 9219: $warning{$item} = &mt('Maximum enrollment setting unchanged.').'<br />'.
9220: &mt('The value provided was invalid - it must be a positive integer if enrollment is being limited.');
1.276 raeburn 9221: }
9222: }
9223: } elsif ($item eq 'approval') {
9224: my (@currnotified,@newnotified);
1.398 raeburn 9225: my $currapproval = $currsettings->{'selfenroll_approval'};
9226: my $currnotifylist = $currsettings->{'selfenroll_notifylist'};
1.276 raeburn 9227: if ($currnotifylist ne '') {
9228: @currnotified = split(/,/,$currnotifylist);
9229: @currnotified = sort(@currnotified);
9230: }
9231: my $newapproval = $env{'form.selfenroll_approval'};
9232: @newnotified = &Apache::loncommon::get_env_multiple('form.selfenroll_notify');
9233: @newnotified = sort(@newnotified);
9234: if ($newapproval ne $currapproval) {
9235: $changes{'internal.selfenroll_approval'} = $newapproval;
9236: if (!$newapproval) {
9237: if ($currnotifylist ne '') {
9238: $changes{'internal.selfenroll_notifylist'} = '';
9239: }
9240: } else {
9241: my @differences =
1.295 raeburn 9242: &Apache::loncommon::compare_arrays(\@currnotified,\@newnotified);
1.276 raeburn 9243: if (@differences > 0) {
9244: if (@newnotified > 0) {
9245: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
9246: } else {
9247: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
9248: }
9249: }
9250: }
9251: } else {
1.295 raeburn 9252: my @differences = &Apache::loncommon::compare_arrays(\@currnotified,\@newnotified);
1.276 raeburn 9253: if (@differences > 0) {
9254: if (@newnotified > 0) {
9255: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
9256: } else {
9257: $changes{'internal.selfenroll_notifylist'} = '';
9258: }
9259: }
9260: }
1.237 raeburn 9261: } else {
1.398 raeburn 9262: my $curr_val = $currsettings->{'selfenroll_'.$item};
1.237 raeburn 9263: my $newval = $env{'form.selfenroll_'.$item};
9264: if ($item eq 'section') {
9265: $newval = $env{'form.sections'};
1.241 raeburn 9266: if (defined($curr_groups{$newval})) {
1.237 raeburn 9267: $newval = $curr_val;
1.398 raeburn 9268: $warning{$item} = &mt('Section for self-enrolled users unchanged as the proposed section is a group').'<br />'.
9269: &mt('Group names and section names must be distinct');
1.237 raeburn 9270: } elsif ($newval eq 'all') {
9271: $newval = $curr_val;
1.274 bisitz 9272: $warning{$item} = &mt('Section for self-enrolled users unchanged, as "all" is a reserved section name.');
1.237 raeburn 9273: }
9274: if ($newval eq '') {
9275: $newval = 'none';
9276: }
9277: }
9278: if ($newval ne $curr_val) {
9279: $changes{'internal.selfenroll_'.$item} = $newval;
9280: }
1.241 raeburn 9281: }
1.237 raeburn 9282: }
9283: if (keys(%warning) > 0) {
9284: foreach my $item (@{$row}) {
9285: if (exists($warning{$item})) {
9286: $r->print($warning{$item}.'<br />');
9287: }
9288: }
9289: }
9290: if (keys(%changes) > 0) {
9291: my $putresult = &Apache::lonnet::put('environment',\%changes,$cdom,$cnum);
9292: if ($putresult eq 'ok') {
9293: if ((exists($changes{'internal.selfenroll_types'})) ||
9294: (exists($changes{'internal.selfenroll_start_date'})) ||
9295: (exists($changes{'internal.selfenroll_end_date'}))) {
9296: my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',
9297: $cnum,undef,undef,'Course');
9298: my $chome = &Apache::lonnet::homeserver($cnum,$cdom);
1.398 raeburn 9299: if (ref($crsinfo{$cid}) eq 'HASH') {
1.237 raeburn 9300: foreach my $item ('selfenroll_types','selfenroll_start_date','selfenroll_end_date') {
9301: if (exists($changes{'internal.'.$item})) {
1.398 raeburn 9302: $crsinfo{$cid}{$item} = $changes{'internal.'.$item};
1.237 raeburn 9303: }
9304: }
9305: my $crsputresult =
9306: &Apache::lonnet::courseidput($cdom,\%crsinfo,
9307: $chome,'notime');
9308: }
9309: }
9310: $r->print(&mt('The following changes were made to self-enrollment settings:').'<ul>');
9311: foreach my $item (@{$row}) {
9312: my $title = $item;
9313: if (ref($lt) eq 'HASH') {
9314: $title = $lt->{$item};
9315: }
9316: if ($item eq 'enroll_dates') {
9317: foreach my $type ('start','end') {
9318: if (exists($changes{'internal.selfenroll_'.$type.'_date'})) {
9319: my $newdate = &Apache::lonlocal::locallocaltime($changes{'internal.selfenroll_'.$type.'_date'});
1.244 bisitz 9320: $r->print('<li>'.&mt('[_1]: "[_2]" set to "[_3]".',
1.237 raeburn 9321: $title,$type,$newdate).'</li>');
9322: }
9323: }
9324: } elsif ($item eq 'access_dates') {
9325: foreach my $type ('start','end') {
9326: if (exists($changes{'internal.selfenroll_'.$type.'_access'})) {
9327: my $newdate = &Apache::lonlocal::locallocaltime($changes{'internal.selfenroll_'.$type.'_access'});
1.244 bisitz 9328: $r->print('<li>'.&mt('[_1]: "[_2]" set to "[_3]".',
1.237 raeburn 9329: $title,$type,$newdate).'</li>');
9330: }
9331: }
1.276 raeburn 9332: } elsif ($item eq 'limit') {
9333: if ((exists($changes{'internal.selfenroll_limit'})) ||
9334: (exists($changes{'internal.selfenroll_cap'}))) {
9335: my ($newval,$newcap);
9336: if ($changes{'internal.selfenroll_cap'} ne '') {
9337: $newcap = $changes{'internal.selfenroll_cap'}
9338: } else {
1.398 raeburn 9339: $newcap = $currsettings->{'selfenroll_cap'};
1.276 raeburn 9340: }
9341: if ($changes{'internal.selfenroll_limit'} eq 'none') {
9342: $newval = &mt('No limit');
9343: } elsif ($changes{'internal.selfenroll_limit'} eq
9344: 'allstudents') {
9345: $newval = &mt('New self-enrollment no longer allowed when total (all students) reaches [_1].',$newcap);
9346: } elsif ($changes{'internal.selfenroll_limit'} eq 'selfenrolled') {
9347: $newval = &mt('New self-enrollment no longer allowed when total number of self-enrolled students reaches [_1].',$newcap);
9348: } else {
1.398 raeburn 9349: my $currlimit = $currsettings->{'selfenroll_limit'};
1.276 raeburn 9350: if ($currlimit eq 'allstudents') {
9351: $newval = &mt('New self-enrollment no longer allowed when total (all students) reaches [_1].',$newcap);
9352: } elsif ($changes{'internal.selfenroll_limit'} eq 'selfenrolled') {
1.308 raeburn 9353: $newval = &mt('New self-enrollment no longer allowed when total number of self-enrolled students reaches [_1].',$newcap);
1.276 raeburn 9354: }
9355: }
9356: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval).'</li>'."\n");
9357: }
9358: } elsif ($item eq 'approval') {
9359: if ((exists($changes{'internal.selfenroll_approval'})) ||
9360: (exists($changes{'internal.selfenroll_notifylist'}))) {
1.398 raeburn 9361: my %selfdescs = &Apache::lonuserutils::selfenroll_default_descs();
1.276 raeburn 9362: my ($newval,$newnotify);
9363: if (exists($changes{'internal.selfenroll_notifylist'})) {
9364: $newnotify = $changes{'internal.selfenroll_notifylist'};
9365: } else {
1.398 raeburn 9366: $newnotify = $currsettings->{'selfenroll_notifylist'};
1.276 raeburn 9367: }
1.398 raeburn 9368: if (exists($changes{'internal.selfenroll_approval'})) {
9369: if ($changes{'internal.selfenroll_approval'} !~ /^[012]$/) {
9370: $changes{'internal.selfenroll_approval'} = '0';
9371: }
9372: $newval = $selfdescs{'approval'}{$changes{'internal.selfenroll_approval'}};
1.276 raeburn 9373: } else {
1.398 raeburn 9374: my $currapproval = $currsettings->{'selfenroll_approval'};
9375: if ($currapproval !~ /^[012]$/) {
9376: $currapproval = 0;
1.276 raeburn 9377: }
1.398 raeburn 9378: $newval = $selfdescs{'approval'}{$currapproval};
1.276 raeburn 9379: }
9380: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval));
9381: if ($newnotify) {
1.277 raeburn 9382: $r->print('<br />'.&mt('The following will be notified when an enrollment request needs approval, or has been approved: [_1].',$newnotify));
1.276 raeburn 9383: } else {
1.277 raeburn 9384: $r->print('<br />'.&mt('No notifications sent when an enrollment request needs approval, or has been approved.'));
1.276 raeburn 9385: }
9386: $r->print('</li>'."\n");
9387: }
1.237 raeburn 9388: } else {
9389: if (exists($changes{'internal.selfenroll_'.$item})) {
1.241 raeburn 9390: my $newval = $changes{'internal.selfenroll_'.$item};
9391: if ($item eq 'types') {
9392: if ($newval eq '') {
9393: $newval = &mt('None');
9394: } elsif ($newval eq '*') {
9395: $newval = &mt('Any user in any domain');
9396: }
1.245 raeburn 9397: } elsif ($item eq 'registered') {
9398: if ($newval eq '1') {
9399: $newval = &mt('Yes');
9400: } elsif ($newval eq '0') {
9401: $newval = &mt('No');
9402: }
1.241 raeburn 9403: }
1.244 bisitz 9404: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval).'</li>'."\n");
1.237 raeburn 9405: }
9406: }
9407: }
9408: $r->print('</ul>');
1.398 raeburn 9409: if ($env{'course.'.$cid.'.description'} ne '') {
9410: my %newenvhash;
9411: foreach my $key (keys(%changes)) {
9412: $newenvhash{'course.'.$cid.'.'.$key} = $changes{$key};
9413: }
9414: &Apache::lonnet::appenv(\%newenvhash);
1.237 raeburn 9415: }
9416: } else {
1.398 raeburn 9417: $r->print(&mt('An error occurred when saving changes to self-enrollment settings in this course.').'<br />'.
9418: &mt('The error was: [_1].',$putresult));
1.237 raeburn 9419: }
9420: } else {
1.249 raeburn 9421: $r->print(&mt('No changes were made to the existing self-enrollment settings in this course.'));
1.237 raeburn 9422: }
9423: } else {
1.249 raeburn 9424: $r->print(&mt('No changes were made to the existing self-enrollment settings in this course.'));
1.241 raeburn 9425: }
1.400 raeburn 9426: my $visactions = &cat_visibility();
9427: my ($cathash,%cattype);
9428: my %domconfig = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom);
9429: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
9430: $cathash = $domconfig{'coursecategories'}{'cats'};
9431: $cattype{'auth'} = $domconfig{'coursecategories'}{'auth'};
9432: $cattype{'unauth'} = $domconfig{'coursecategories'}{'unauth'};
9433: } else {
9434: $cathash = {};
9435: $cattype{'auth'} = 'std';
9436: $cattype{'unauth'} = 'std';
9437: }
9438: if (($cattype{'auth'} eq 'none') && ($cattype{'unauth'} eq 'none')) {
9439: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
9440: '<br />'.
9441: '<br />'.$visactions->{'take'}.'<ul>'.
9442: '<li>'.$visactions->{'dc_chgconf'}.'</li>'.
9443: '</ul>');
9444: } elsif (($cattype{'auth'} !~ /^(std|domonly)$/) && ($cattype{'unauth'} !~ /^(std|domonly)$/)) {
9445: if ($currsettings->{'uniquecode'}) {
9446: $r->print('<span class="LC_info">'.$visactions->{'vis'}.'</span>');
9447: } else {
1.366 bisitz 9448: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
1.400 raeburn 9449: '<br />'.
9450: '<br />'.$visactions->{'take'}.'<ul>'.
9451: '<li>'.$visactions->{'dc_setcode'}.'</li>'.
9452: '</ul><br />');
9453: }
9454: } else {
9455: my ($visible,$cansetvis,$vismsgs) = &visible_in_stdcat($cdom,$cnum,\%domconfig);
9456: if (ref($visactions) eq 'HASH') {
9457: if (!$visible) {
9458: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
9459: '<br />');
9460: if (ref($vismsgs) eq 'ARRAY') {
9461: $r->print('<br />'.$visactions->{'take'}.'<ul>');
9462: foreach my $item (@{$vismsgs}) {
9463: $r->print('<li>'.$visactions->{$item}.'</li>');
9464: }
9465: $r->print('</ul>');
1.256 raeburn 9466: }
1.400 raeburn 9467: $r->print($cansetvis);
1.256 raeburn 9468: }
9469: }
9470: }
1.237 raeburn 9471: return;
9472: }
9473:
1.27 matthew 9474: #---------------------------------------------- end functions for &phase_two
1.29 matthew 9475:
9476: #--------------------------------- functions for &phase_two and &phase_three
9477:
9478: #--------------------------end of functions for &phase_two and &phase_three
1.372 raeburn 9479:
1.1 www 9480: 1;
9481: __END__
1.2 www 9482:
9483:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>