Annotation of loncom/interface/loncreateuser.pm, revision 1.406.2.18
1.20 harris41 1: # The LearningOnline Network with CAPA
1.1 www 2: # Create a user
3: #
1.406.2.18! raeburn 4: # $Id: loncreateuser.pm,v 1.406.2.17 2019/08/27 14:45:04 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: }
1.406.2.17 raeburn 1489: $user_text{'auth'} = &user_authentication($ccuname,$ccdomain,$formname,$crstype,$permission);
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.406.2.17 raeburn 2167: my ($ccuname,$ccdomain,$formname,$crstype,$permission) = @_;
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.17 raeburn 2239: if (($currentauth =~ /^internal:/) &&
2240: (&Apache::lonuserutils::can_change_internalpass($ccuname,$ccdomain,$crstype,$permission))) {
2241: $outcome = <<"ENDJS";
2242: <script type="text/javascript">
2243: // <![CDATA[
2244: function togglePwd(form) {
2245: if (form.newintpwd.length) {
2246: if (document.getElementById('LC_ownersetpwd')) {
2247: for (var i=0; i<form.newintpwd.length; i++) {
2248: if (form.newintpwd[i].checked) {
2249: if (form.newintpwd[i].value == 1) {
2250: document.getElementById('LC_ownersetpwd').style.display = 'inline-block';
2251: } else {
2252: document.getElementById('LC_ownersetpwd').style.display = 'none';
2253: }
2254: }
2255: }
2256: }
2257: }
2258: }
2259: // ]]>
2260: </script>
2261: ENDJS
2262:
2263: $outcome .= '<h3>'.$lt{'ld'}.'</h3>'.
2264: &Apache::loncommon::start_data_table().
2265: &Apache::loncommon::start_data_table_row().
2266: '<td>'.&mt('Internally authenticated').'<br />'.&mt("Change user's password?").
2267: '<label><input type="radio" name="newintpwd" value="0" checked="checked" onclick="togglePwd(this.form);" />'.
2268: &mt('No').'</label>'.(' 'x2).
2269: '<label><input type="radio" name="newintpwd" value="1" onclick="togglePwd(this.form);" />'.&mt('Yes').'</label>'.
2270: '<div id="LC_ownersetpwd" style="display:none">'.
2271: ' '.&mt('Password').' <input type="password" size="15" name="intarg" value="" />'.
2272: '<label><input type="checkbox" name="visible" onclick="if (this.checked) { this.form.intarg.type='."'text'".' } else { this.form.intarg.type='."'password'".' }" />'.&mt('Visible input').'</label></div></td>'.
2273: &Apache::loncommon::end_data_table_row().
2274: &Apache::loncommon::end_data_table();
2275: }
1.406.2.6 raeburn 2276: if (&Apache::lonnet::allowed('udp',$ccdomain)) {
2277: # Current user has rights to view domain preferences for user's domain
2278: my $result;
2279: if ($currentauth =~ /^krb(4|5):([^:]*)$/) {
2280: my ($krbver,$krbrealm) = ($1,$2);
2281: if ($krbrealm eq '') {
2282: $result = &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
2283: } else {
2284: $result = &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
1.406.2.9 raeburn 2285: $krbrealm,$krbver);
1.406.2.6 raeburn 2286: }
2287: } elsif ($currentauth =~ /^internal:/) {
2288: $result = &mt('Currently internally authenticated.');
2289: } elsif ($currentauth =~ /^localauth:/) {
2290: $result = &mt('Currently using local (institutional) authentication.');
2291: } elsif ($currentauth =~ /^unix:/) {
2292: $result = &mt('Currently Filesystem Authenticated.');
2293: }
2294: $outcome = '<h3>'.$lt{'ld'}.'</h3>'.
2295: &Apache::loncommon::start_data_table().
2296: &Apache::loncommon::start_data_table_row().
2297: '<td>'.$result.'</td>'.
2298: &Apache::loncommon::end_data_table_row()."\n".
2299: &Apache::loncommon::end_data_table();
2300: } elsif (&Apache::lonnet::allowed('mau',$env{'request.role.domain'})) {
1.188 raeburn 2301: my %lt=&Apache::lonlocal::texthash(
2302: 'ccld' => "Change Current Login Data",
2303: 'yodo' => "You do not have privileges to modify the authentication configuration for this user.",
2304: 'ifch' => "If a change is required, contact a domain coordinator for the domain",
2305: );
2306: $outcome .= <<ENDNOPRIV;
2307: <h3>$lt{'ccld'}</h3>
2308: $lt{'yodo'} $lt{'ifch'}: $ccdomain
1.235 raeburn 2309: <input type="hidden" name="login" value="nochange" />
1.188 raeburn 2310: ENDNOPRIV
2311: }
2312: }
2313: } ## End of "check for bad authentication type" logic
2314: return $outcome;
2315: }
2316:
1.187 raeburn 2317: sub modify_login_block {
2318: my ($dom,$currentauth) = @_;
2319: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
2320: my ($authnum,%can_assign) =
2321: &Apache::loncommon::get_assignable_auth($dom);
1.205 raeburn 2322: my ($authformcurrent,@authform_others,$show_override_msg);
1.187 raeburn 2323: if ($currentauth=~/^krb(4|5):/) {
2324: $authformcurrent=$authformkrb;
2325: if ($can_assign{'int'}) {
1.205 raeburn 2326: push(@authform_others,$authformint);
1.187 raeburn 2327: }
2328: if ($can_assign{'loc'}) {
1.205 raeburn 2329: push(@authform_others,$authformloc);
1.187 raeburn 2330: }
2331: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
2332: $show_override_msg = 1;
2333: }
2334: } elsif ($currentauth=~/^internal:/) {
2335: $authformcurrent=$authformint;
2336: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205 raeburn 2337: push(@authform_others,$authformkrb);
1.187 raeburn 2338: }
2339: if ($can_assign{'loc'}) {
1.205 raeburn 2340: push(@authform_others,$authformloc);
1.187 raeburn 2341: }
2342: if ($can_assign{'int'}) {
2343: $show_override_msg = 1;
2344: }
2345: } elsif ($currentauth=~/^unix:/) {
2346: $authformcurrent=$authformfsys;
2347: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205 raeburn 2348: push(@authform_others,$authformkrb);
1.187 raeburn 2349: }
2350: if ($can_assign{'int'}) {
1.205 raeburn 2351: push(@authform_others,$authformint);
1.187 raeburn 2352: }
2353: if ($can_assign{'loc'}) {
1.205 raeburn 2354: push(@authform_others,$authformloc);
1.187 raeburn 2355: }
2356: if ($can_assign{'fsys'}) {
2357: $show_override_msg = 1;
2358: }
2359: } elsif ($currentauth=~/^localauth:/) {
2360: $authformcurrent=$authformloc;
2361: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205 raeburn 2362: push(@authform_others,$authformkrb);
1.187 raeburn 2363: }
2364: if ($can_assign{'int'}) {
1.205 raeburn 2365: push(@authform_others,$authformint);
1.187 raeburn 2366: }
2367: if ($can_assign{'loc'}) {
2368: $show_override_msg = 1;
2369: }
2370: }
2371: if ($show_override_msg) {
1.205 raeburn 2372: $authformcurrent = '<table><tr><td colspan="3">'.$authformcurrent.
2373: '</td></tr>'."\n".
2374: '<tr><td> </td>'.
2375: '<td><b>'.&mt('Currently in use').'</b></td>'.
2376: '<td align="right"><span class="LC_cusr_emph">'.
1.187 raeburn 2377: &mt('will override current values').
1.205 raeburn 2378: '</span></td></tr></table>';
1.187 raeburn 2379: }
1.205 raeburn 2380: return ($authformcurrent,$show_override_msg,@authform_others);
1.187 raeburn 2381: }
2382:
1.188 raeburn 2383: sub personal_data_display {
1.391 raeburn 2384: my ($ccuname,$ccdomain,$newuser,$context,$inst_results,$rolesarray,
1.406.2.16 raeburn 2385: $now,$captchaform,$emailusername,$usertype,$usernameset,$condition,$excluded) = @_;
1.388 bisitz 2386: my ($output,%userenv,%canmodify,%canmodify_status);
1.219 raeburn 2387: my @userinfo = ('firstname','middlename','lastname','generation',
2388: 'permanentemail','id');
1.252 raeburn 2389: my $rowcount = 0;
2390: my $editable = 0;
1.391 raeburn 2391: my %textboxsize = (
2392: firstname => '15',
2393: middlename => '15',
2394: lastname => '15',
2395: generation => '5',
2396: permanentemail => '25',
2397: id => '15',
2398: );
2399:
2400: my %lt=&Apache::lonlocal::texthash(
2401: 'pd' => "Personal Data",
2402: 'firstname' => "First Name",
2403: 'middlename' => "Middle Name",
2404: 'lastname' => "Last Name",
2405: 'generation' => "Generation",
2406: 'permanentemail' => "Permanent e-mail address",
2407: 'id' => "Student/Employee ID",
2408: 'lg' => "Login Data",
2409: 'inststatus' => "Affiliation",
2410: 'email' => 'E-mail address',
2411: 'valid' => 'Validation',
1.406.2.16 raeburn 2412: 'username' => 'Username',
1.391 raeburn 2413: );
2414:
2415: %canmodify_status =
1.286 raeburn 2416: &Apache::lonuserutils::can_modify_userinfo($context,$ccdomain,
2417: ['inststatus'],$rolesarray);
1.253 raeburn 2418: if (!$newuser) {
1.188 raeburn 2419: # Get the users information
2420: %userenv = &Apache::lonnet::get('environment',
2421: ['firstname','middlename','lastname','generation',
1.286 raeburn 2422: 'permanentemail','id','inststatus'],$ccdomain,$ccuname);
1.219 raeburn 2423: %canmodify =
2424: &Apache::lonuserutils::can_modify_userinfo($context,$ccdomain,
1.252 raeburn 2425: \@userinfo,$rolesarray);
1.257 raeburn 2426: } elsif ($context eq 'selfcreate') {
1.391 raeburn 2427: if ($newuser eq 'email') {
1.396 raeburn 2428: if (ref($emailusername) eq 'HASH') {
2429: if (ref($emailusername->{$usertype}) eq 'HASH') {
2430: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
1.406.2.16 raeburn 2431: @userinfo = ();
1.396 raeburn 2432: if ((ref($infofields) eq 'ARRAY') && (ref($infotitles) eq 'HASH')) {
2433: foreach my $field (@{$infofields}) {
2434: if ($emailusername->{$usertype}->{$field}) {
2435: push(@userinfo,$field);
2436: $canmodify{$field} = 1;
2437: unless ($textboxsize{$field}) {
2438: $textboxsize{$field} = 25;
2439: }
2440: unless ($lt{$field}) {
2441: $lt{$field} = $infotitles->{$field};
2442: }
2443: if ($emailusername->{$usertype}->{$field} eq 'required') {
2444: $lt{$field} .= '<b>*</b>';
2445: }
1.391 raeburn 2446: }
2447: }
2448: }
2449: }
2450: }
2451: } else {
2452: %canmodify = &selfcreate_canmodify($context,$ccdomain,\@userinfo,
2453: $inst_results,$rolesarray);
2454: }
1.188 raeburn 2455: }
1.391 raeburn 2456:
1.188 raeburn 2457: my $genhelp=&Apache::loncommon::help_open_topic('Generation');
2458: $output = '<h3>'.$lt{'pd'}.'</h3>'.
2459: &Apache::lonhtmlcommon::start_pick_box();
1.391 raeburn 2460: if (($context eq 'selfcreate') && ($newuser eq 'email')) {
1.406.2.16 raeburn 2461: my $size = 25;
2462: if ($condition) {
2463: if ($condition =~ /^\@[^\@]+$/) {
2464: $size = 10;
2465: } else {
2466: undef($condition);
2467: }
2468: }
2469: if ($excluded) {
2470: unless ($excluded =~ /^\@[^\@]+$/) {
2471: undef($condition);
2472: }
2473: }
1.396 raeburn 2474: $output .= &Apache::lonhtmlcommon::row_title($lt{'email'}.'<b>*</b>',undef,
1.391 raeburn 2475: 'LC_oddrow_value')."\n".
1.406.2.16 raeburn 2476: '<input type="text" name="uname" size="'.$size.'" value="" autocomplete="off" />';
2477: if ($condition) {
2478: $output .= $condition;
2479: } elsif ($excluded) {
2480: $output .= '<br /><span style="font-size: smaller">'.&mt('You must use an e-mail address that does not end with [_1]',
2481: $excluded).'</span>';
2482: }
2483: if ($usernameset eq 'first') {
2484: $output .= '<br /><span style="font-size: smaller">';
2485: if ($condition) {
2486: $output .= &mt('Your username in LON-CAPA will be the part of your e-mail address before [_1]',
2487: $condition);
2488: } else {
2489: $output .= &mt('Your username in LON-CAPA will be the part of your e-mail address before the @');
2490: }
2491: $output .= '</span>';
2492: }
1.391 raeburn 2493: $rowcount ++;
2494: $output .= &Apache::lonhtmlcommon::row_closure(1);
1.406.2.1 raeburn 2495: my $upassone = '<input type="password" name="upass'.$now.'" size="20" autocomplete="off" />';
2496: my $upasstwo = '<input type="password" name="upasscheck'.$now.'" size="20" autocomplete="off" />';
1.396 raeburn 2497: $output .= &Apache::lonhtmlcommon::row_title(&mt('Password').'<b>*</b>',
1.391 raeburn 2498: 'LC_pick_box_title',
2499: 'LC_oddrow_value')."\n".
2500: $upassone."\n".
2501: &Apache::lonhtmlcommon::row_closure(1)."\n".
1.396 raeburn 2502: &Apache::lonhtmlcommon::row_title(&mt('Confirm password').'<b>*</b>',
1.391 raeburn 2503: 'LC_pick_box_title',
2504: 'LC_oddrow_value')."\n".
2505: $upasstwo.
2506: &Apache::lonhtmlcommon::row_closure()."\n";
1.406.2.16 raeburn 2507: if ($usernameset eq 'free') {
2508: my $onclick = "toggleUsernameDisp(this,'selfcreateusername');";
2509: $output .= &Apache::lonhtmlcommon::row_title($lt{'username'},undef,'LC_oddrow_value')."\n".
2510: &mt('Use e-mail address: ').
2511: '<label><input type="radio" name="emailused" value="1" checked="checked" onclick="'.$onclick.'" />'.&mt('Yes').'</label>'."\n".
2512: (' 'x2).
2513: '<label><input type="radio" name="emailused" value="0" onclick="'.$onclick.'" />'.&mt('No').'</label>'."\n".
2514: '<div id="selfcreateusername" style="display: none; font-size: smaller">'.
2515: '<br /><span class="LC_nobreak">'.&mt('Preferred username').
2516: ' <input type="text" name="username" value="" size="20" autocomplete="off"/>'.
2517: '</span></div>'."\n".&Apache::lonhtmlcommon::row_closure(1);
2518: $rowcount ++;
2519: }
1.391 raeburn 2520: }
1.188 raeburn 2521: foreach my $item (@userinfo) {
2522: my $rowtitle = $lt{$item};
1.252 raeburn 2523: my $hiderow = 0;
1.188 raeburn 2524: if ($item eq 'generation') {
2525: $rowtitle = $genhelp.$rowtitle;
2526: }
1.252 raeburn 2527: my $row = &Apache::lonhtmlcommon::row_title($rowtitle,undef,'LC_oddrow_value')."\n";
1.188 raeburn 2528: if ($newuser) {
1.210 raeburn 2529: if (ref($inst_results) eq 'HASH') {
2530: if ($inst_results->{$item} ne '') {
1.252 raeburn 2531: $row .= '<input type="hidden" name="c'.$item.'" value="'.$inst_results->{$item}.'" />'.$inst_results->{$item};
1.210 raeburn 2532: } else {
1.252 raeburn 2533: if ($context eq 'selfcreate') {
1.391 raeburn 2534: if ($canmodify{$item}) {
1.394 raeburn 2535: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" autocomplete="off" />';
1.252 raeburn 2536: $editable ++;
2537: } else {
2538: $hiderow = 1;
2539: }
1.253 raeburn 2540: } else {
2541: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
1.252 raeburn 2542: }
1.210 raeburn 2543: }
1.188 raeburn 2544: } else {
1.252 raeburn 2545: if ($context eq 'selfcreate') {
1.401 raeburn 2546: if ($canmodify{$item}) {
2547: if ($newuser eq 'email') {
2548: $row .= '<input type="text" name="'.$item.'" size="'.$textboxsize{$item}.'" value="" autocomplete="off" />';
1.287 raeburn 2549: } else {
1.401 raeburn 2550: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" autocomplete="off" />';
1.287 raeburn 2551: }
1.401 raeburn 2552: $editable ++;
2553: } else {
2554: $hiderow = 1;
1.252 raeburn 2555: }
1.253 raeburn 2556: } else {
2557: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
1.252 raeburn 2558: }
1.188 raeburn 2559: }
2560: } else {
1.219 raeburn 2561: if ($canmodify{$item}) {
1.252 raeburn 2562: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="'.$userenv{$item}.'" />';
1.393 raeburn 2563: if (($item eq 'id') && (!$newuser)) {
2564: $row .= '<br />'.&Apache::lonuserutils::forceid_change($context);
2565: }
1.188 raeburn 2566: } else {
1.252 raeburn 2567: $row .= $userenv{$item};
1.188 raeburn 2568: }
2569: }
1.252 raeburn 2570: $row .= &Apache::lonhtmlcommon::row_closure(1);
2571: if (!$hiderow) {
2572: $output .= $row;
2573: $rowcount ++;
2574: }
1.188 raeburn 2575: }
1.286 raeburn 2576: if (($canmodify_status{'inststatus'}) || ($context ne 'selfcreate')) {
2577: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($ccdomain);
2578: if (ref($types) eq 'ARRAY') {
2579: if (@{$types} > 0) {
2580: my ($hiderow,$shown);
2581: if ($canmodify_status{'inststatus'}) {
2582: $shown = &pick_inst_statuses($userenv{'inststatus'},$usertypes,$types);
2583: } else {
2584: if ($userenv{'inststatus'} eq '') {
2585: $hiderow = 1;
1.334 raeburn 2586: } else {
2587: my @showitems;
2588: foreach my $item ( map { &unescape($_); } split(':',$userenv{'inststatus'})) {
2589: if (exists($usertypes->{$item})) {
2590: push(@showitems,$usertypes->{$item});
2591: } else {
2592: push(@showitems,$item);
2593: }
2594: }
2595: if (@showitems) {
2596: $shown = join(', ',@showitems);
2597: } else {
2598: $hiderow = 1;
2599: }
1.286 raeburn 2600: }
2601: }
2602: if (!$hiderow) {
1.389 bisitz 2603: my $row = &Apache::lonhtmlcommon::row_title(&mt('Affiliations'),undef,'LC_oddrow_value')."\n".
1.286 raeburn 2604: $shown.&Apache::lonhtmlcommon::row_closure(1);
2605: if ($context eq 'selfcreate') {
2606: $rowcount ++;
2607: }
2608: $output .= $row;
2609: }
2610: }
2611: }
2612: }
1.391 raeburn 2613: if (($context eq 'selfcreate') && ($newuser eq 'email')) {
2614: if ($captchaform) {
1.406.2.2 raeburn 2615: $output .= &Apache::lonhtmlcommon::row_title($lt{'valid'}.'*',
1.391 raeburn 2616: 'LC_pick_box_title')."\n".
2617: $captchaform."\n".'<br /><br />'.
2618: &Apache::lonhtmlcommon::row_closure(1);
2619: $rowcount ++;
2620: }
2621: my $submit_text = &mt('Create account');
2622: $output .= &Apache::lonhtmlcommon::row_title()."\n".
2623: '<br /><input type="submit" name="createaccount" value="'.
2624: $submit_text.'" />'.
1.396 raeburn 2625: '<input type="hidden" name="type" value="'.$usertype.'" />'.
1.391 raeburn 2626: &Apache::lonhtmlcommon::row_closure(1);
2627: }
1.188 raeburn 2628: $output .= &Apache::lonhtmlcommon::end_pick_box();
1.206 raeburn 2629: if (wantarray) {
1.252 raeburn 2630: if ($context eq 'selfcreate') {
2631: return($output,$rowcount,$editable);
2632: } else {
1.388 bisitz 2633: return $output;
1.252 raeburn 2634: }
1.206 raeburn 2635: } else {
2636: return $output;
2637: }
1.188 raeburn 2638: }
2639:
1.286 raeburn 2640: sub pick_inst_statuses {
2641: my ($curr,$usertypes,$types) = @_;
2642: my ($output,$rem,@currtypes);
2643: if ($curr ne '') {
2644: @currtypes = map { &unescape($_); } split(/:/,$curr);
2645: }
2646: my $numinrow = 2;
2647: if (ref($types) eq 'ARRAY') {
2648: $output = '<table>';
2649: my $lastcolspan;
2650: for (my $i=0; $i<@{$types}; $i++) {
2651: if (defined($usertypes->{$types->[$i]})) {
2652: my $rem = $i%($numinrow);
2653: if ($rem == 0) {
2654: if ($i<@{$types}-1) {
2655: if ($i > 0) {
2656: $output .= '</tr>';
2657: }
2658: $output .= '<tr>';
2659: }
2660: } elsif ($i==@{$types}-1) {
2661: my $colsleft = $numinrow - $rem;
2662: if ($colsleft > 1) {
2663: $lastcolspan = ' colspan="'.$colsleft.'"';
2664: }
2665: }
2666: my $check = ' ';
2667: if (grep(/^\Q$types->[$i]\E$/,@currtypes)) {
2668: $check = ' checked="checked" ';
2669: }
2670: $output .= '<td class="LC_left_item"'.$lastcolspan.'>'.
2671: '<span class="LC_nobreak"><label>'.
2672: '<input type="checkbox" name="inststatus" '.
2673: 'value="'.$types->[$i].'"'.$check.'/>'.
2674: $usertypes->{$types->[$i]}.'</label></span></td>';
2675: }
2676: }
2677: $output .= '</tr></table>';
2678: }
2679: return $output;
2680: }
2681:
1.257 raeburn 2682: sub selfcreate_canmodify {
2683: my ($context,$dom,$userinfo,$inst_results,$rolesarray) = @_;
2684: if (ref($inst_results) eq 'HASH') {
2685: my @inststatuses = &get_inststatuses($inst_results);
2686: if (@inststatuses == 0) {
2687: @inststatuses = ('default');
2688: }
2689: $rolesarray = \@inststatuses;
2690: }
2691: my %canmodify =
2692: &Apache::lonuserutils::can_modify_userinfo($context,$dom,$userinfo,
2693: $rolesarray);
2694: return %canmodify;
2695: }
2696:
1.252 raeburn 2697: sub get_inststatuses {
2698: my ($insthashref) = @_;
2699: my @inststatuses = ();
2700: if (ref($insthashref) eq 'HASH') {
2701: if (ref($insthashref->{'inststatus'}) eq 'ARRAY') {
2702: @inststatuses = @{$insthashref->{'inststatus'}};
2703: }
2704: }
2705: return @inststatuses;
2706: }
2707:
1.4 www 2708: # ================================================================= Phase Three
1.42 matthew 2709: sub update_user_data {
1.406.2.17 raeburn 2710: my ($r,$context,$crstype,$brcrum,$showcredits,$permission) = @_;
1.101 albertel 2711: my $uhome=&Apache::lonnet::homeserver($env{'form.ccuname'},
2712: $env{'form.ccdomain'});
1.27 matthew 2713: # Error messages
1.188 raeburn 2714: my $error = '<span class="LC_error">'.&mt('Error').': ';
1.193 raeburn 2715: my $end = '</span><br /><br />';
2716: my $rtnlink = '<a href="javascript:backPage(document.userupdate,'.
1.188 raeburn 2717: "'$env{'form.prevphase'}','modify')".'" />'.
1.219 raeburn 2718: &mt('Return to previous page').'</a>'.
2719: &Apache::loncommon::end_page();
2720: my $now = time;
1.40 www 2721: my $title;
1.101 albertel 2722: if (exists($env{'form.makeuser'})) {
1.40 www 2723: $title='Set Privileges for New User';
2724: } else {
2725: $title='Modify User Privileges';
2726: }
1.213 raeburn 2727: my $newuser = 0;
1.160 raeburn 2728: my ($jsback,$elements) = &crumb_utilities();
2729: my $jscript = '<script type="text/javascript">'."\n".
1.301 bisitz 2730: '// <![CDATA['."\n".
2731: $jsback."\n".
2732: '// ]]>'."\n".
2733: '</script>'."\n";
1.406.2.7 raeburn 2734: my %breadcrumb_text = &singleuser_breadcrumb($crstype,$context,$env{'form.ccdomain'});
1.351 raeburn 2735: push (@{$brcrum},
2736: {href => "javascript:backPage(document.userupdate)",
2737: text => $breadcrumb_text{'search'},
2738: faq => 282,
2739: bug => 'Instructor Interface',}
2740: );
2741: if ($env{'form.prevphase'} eq 'userpicked') {
2742: push(@{$brcrum},
2743: {href => "javascript:backPage(document.userupdate,'get_user_info','select')",
2744: text => $breadcrumb_text{'userpicked'},
2745: faq => 282,
2746: bug => 'Instructor Interface',});
1.233 raeburn 2747: }
1.224 raeburn 2748: my $helpitem = 'Course_Change_Privileges';
2749: if ($env{'form.action'} eq 'singlestudent') {
2750: $helpitem = 'Course_Add_Student';
1.406.2.14 raeburn 2751: } elsif ($context eq 'author') {
2752: $helpitem = 'Author_Change_Privileges';
2753: } elsif ($context eq 'domain') {
2754: $helpitem = 'Domain_Change_Privileges';
1.224 raeburn 2755: }
1.351 raeburn 2756: push(@{$brcrum},
2757: {href => "javascript:backPage(document.userupdate,'$env{'form.prevphase'}','modify')",
2758: text => $breadcrumb_text{'modify'},
2759: faq => 282,
2760: bug => 'Instructor Interface',},
2761: {href => "/adm/createuser",
2762: text => "Result",
2763: faq => 282,
2764: bug => 'Instructor Interface',
2765: help => $helpitem});
2766: my $args = {bread_crumbs => $brcrum,
2767: bread_crumbs_component => 'User Management'};
2768: if ($env{'form.popup'}) {
2769: $args->{'no_nav_bar'} = 1;
2770: }
2771: $r->print(&Apache::loncommon::start_page($title,$jscript,$args));
1.188 raeburn 2772: $r->print(&update_result_form($uhome));
1.27 matthew 2773: # Check Inputs
1.101 albertel 2774: if (! $env{'form.ccuname'} ) {
1.193 raeburn 2775: $r->print($error.&mt('No login name specified').'.'.$end.$rtnlink);
1.27 matthew 2776: return;
2777: }
1.138 albertel 2778: if ( $env{'form.ccuname'} ne
2779: &LONCAPA::clean_username($env{'form.ccuname'}) ) {
1.281 bisitz 2780: $r->print($error.&mt('Invalid login name.').' '.
2781: &mt('Only letters, numbers, periods, dashes, @, and underscores are valid.').
1.193 raeburn 2782: $end.$rtnlink);
1.27 matthew 2783: return;
2784: }
1.101 albertel 2785: if (! $env{'form.ccdomain'} ) {
1.193 raeburn 2786: $r->print($error.&mt('No domain specified').'.'.$end.$rtnlink);
1.27 matthew 2787: return;
2788: }
1.138 albertel 2789: if ( $env{'form.ccdomain'} ne
2790: &LONCAPA::clean_domain($env{'form.ccdomain'}) ) {
1.281 bisitz 2791: $r->print($error.&mt('Invalid domain name.').' '.
2792: &mt('Only letters, numbers, periods, dashes, and underscores are valid.').
1.193 raeburn 2793: $end.$rtnlink);
1.27 matthew 2794: return;
2795: }
1.219 raeburn 2796: if ($uhome eq 'no_host') {
2797: $newuser = 1;
2798: }
1.101 albertel 2799: if (! exists($env{'form.makeuser'})) {
1.29 matthew 2800: # Modifying an existing user, so check the validity of the name
2801: if ($uhome eq 'no_host') {
1.389 bisitz 2802: $r->print(
2803: $error
2804: .'<p class="LC_error">'
2805: .&mt('Unable to determine home server for [_1] in domain [_2].',
2806: '"'.$env{'form.ccuname'}.'"','"'.$env{'form.ccdomain'}.'"')
2807: .'</p>');
1.29 matthew 2808: return;
2809: }
2810: }
1.27 matthew 2811: # Determine authentication method and password for the user being modified
2812: my $amode='';
2813: my $genpwd='';
1.101 albertel 2814: if ($env{'form.login'} eq 'krb') {
1.41 albertel 2815: $amode='krb';
1.101 albertel 2816: $amode.=$env{'form.krbver'};
2817: $genpwd=$env{'form.krbarg'};
2818: } elsif ($env{'form.login'} eq 'int') {
1.27 matthew 2819: $amode='internal';
1.101 albertel 2820: $genpwd=$env{'form.intarg'};
2821: } elsif ($env{'form.login'} eq 'fsys') {
1.27 matthew 2822: $amode='unix';
1.101 albertel 2823: $genpwd=$env{'form.fsysarg'};
2824: } elsif ($env{'form.login'} eq 'loc') {
1.27 matthew 2825: $amode='localauth';
1.101 albertel 2826: $genpwd=$env{'form.locarg'};
1.27 matthew 2827: $genpwd=" " if (!$genpwd);
1.101 albertel 2828: } elsif (($env{'form.login'} eq 'nochange') ||
2829: ($env{'form.login'} eq '' )) {
1.34 matthew 2830: # There is no need to tell the user we did not change what they
2831: # did not ask us to change.
1.35 matthew 2832: # If they are creating a new user but have not specified login
2833: # information this will be caught below.
1.30 matthew 2834: } else {
1.367 golterma 2835: $r->print($error.&mt('Invalid login mode or password').$end.$rtnlink);
2836: return;
1.27 matthew 2837: }
1.164 albertel 2838:
1.188 raeburn 2839: $r->print('<h3>'.&mt('User [_1] in domain [_2]',
1.367 golterma 2840: $env{'form.ccuname'}.' ('.&Apache::loncommon::plainname($env{'form.ccuname'},
2841: $env{'form.ccdomain'}).')', $env{'form.ccdomain'}).'</h3>');
2842: my %prog_state = &Apache::lonhtmlcommon::Create_PrgWin($r,2);
1.344 bisitz 2843:
1.193 raeburn 2844: my (%alerts,%rulematch,%inst_results,%curr_rules);
1.334 raeburn 2845: my @userinfo = ('firstname','middlename','lastname','generation','permanentemail','id');
1.361 raeburn 2846: my @usertools = ('aboutme','blog','webdav','portfolio');
1.384 raeburn 2847: my @requestcourses = ('official','unofficial','community','textbook');
1.362 raeburn 2848: my @requestauthor = ('requestauthor');
1.286 raeburn 2849: my ($othertitle,$usertypes,$types) =
2850: &Apache::loncommon::sorted_inst_types($env{'form.ccdomain'});
1.334 raeburn 2851: my %canmodify_status =
2852: &Apache::lonuserutils::can_modify_userinfo($context,$env{'form.ccdomain'},
2853: ['inststatus']);
1.101 albertel 2854: if ($env{'form.makeuser'}) {
1.164 albertel 2855: $r->print('<h3>'.&mt('Creating new account.').'</h3>');
1.27 matthew 2856: # Check for the authentication mode and password
2857: if (! $amode || ! $genpwd) {
1.193 raeburn 2858: $r->print($error.&mt('Invalid login mode or password').$end.$rtnlink);
1.27 matthew 2859: return;
1.18 albertel 2860: }
1.29 matthew 2861: # Determine desired host
1.101 albertel 2862: my $desiredhost = $env{'form.hserver'};
1.29 matthew 2863: if (lc($desiredhost) eq 'default') {
2864: $desiredhost = undef;
2865: } else {
1.147 albertel 2866: my %home_servers =
2867: &Apache::lonnet::get_servers($env{'form.ccdomain'},'library');
1.29 matthew 2868: if (! exists($home_servers{$desiredhost})) {
1.193 raeburn 2869: $r->print($error.&mt('Invalid home server specified').$end.$rtnlink);
2870: return;
2871: }
2872: }
2873: # Check ID format
2874: my %checkhash;
2875: my %checks = ('id' => 1);
2876: %{$checkhash{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}}} = (
1.219 raeburn 2877: 'newuser' => $newuser,
1.196 raeburn 2878: 'id' => $env{'form.cid'},
1.193 raeburn 2879: );
1.196 raeburn 2880: if ($env{'form.cid'} ne '') {
2881: &Apache::loncommon::user_rule_check(\%checkhash,\%checks,\%alerts,
2882: \%rulematch,\%inst_results,\%curr_rules);
2883: if (ref($alerts{'id'}) eq 'HASH') {
2884: if (ref($alerts{'id'}{$env{'form.ccdomain'}}) eq 'HASH') {
2885: my $domdesc =
2886: &Apache::lonnet::domain($env{'form.ccdomain'},'description');
2887: if ($alerts{'id'}{$env{'form.ccdomain'}}{$env{'form.cid'}}) {
2888: my $userchkmsg;
2889: if (ref($curr_rules{$env{'form.ccdomain'}}) eq 'HASH') {
2890: $userchkmsg =
2891: &Apache::loncommon::instrule_disallow_msg('id',
2892: $domdesc,1).
2893: &Apache::loncommon::user_rule_formats($env{'form.ccdomain'},
2894: $domdesc,$curr_rules{$env{'form.ccdomain'}}{'id'},'id');
2895: }
2896: $r->print($error.&mt('Invalid ID format').$end.
2897: $userchkmsg.$rtnlink);
2898: return;
2899: }
2900: }
1.29 matthew 2901: }
2902: }
1.367 golterma 2903: &Apache::lonhtmlcommon::Increment_PrgWin($r, \%prog_state);
1.27 matthew 2904: # Call modifyuser
2905: my $result = &Apache::lonnet::modifyuser
1.193 raeburn 2906: ($env{'form.ccdomain'},$env{'form.ccuname'},$env{'form.cid'},
1.188 raeburn 2907: $amode,$genpwd,$env{'form.cfirstname'},
2908: $env{'form.cmiddlename'},$env{'form.clastname'},
2909: $env{'form.cgeneration'},undef,$desiredhost,
2910: $env{'form.cpermanentemail'});
1.77 www 2911: $r->print(&mt('Generating user').': '.$result);
1.219 raeburn 2912: $uhome = &Apache::lonnet::homeserver($env{'form.ccuname'},
1.101 albertel 2913: $env{'form.ccdomain'});
1.334 raeburn 2914: my (%changeHash,%newcustom,%changed,%changedinfo);
1.267 raeburn 2915: if ($uhome ne 'no_host') {
1.334 raeburn 2916: if ($context eq 'domain') {
1.378 raeburn 2917: foreach my $name ('portfolio','author') {
2918: if ($env{'form.custom_'.$name.'quota'} == 1) {
2919: if ($env{'form.'.$name.'quota'} eq '') {
2920: $newcustom{$name.'quota'} = 0;
2921: } else {
2922: $newcustom{$name.'quota'} = $env{'form.'.$name.'quota'};
2923: $newcustom{$name.'quota'} =~ s/[^\d\.]//g;
2924: }
2925: if ("a_admin($newcustom{$name.'quota'},\%changeHash,$name)) {
2926: $changed{$name.'quota'} = 1;
2927: }
1.334 raeburn 2928: }
2929: }
2930: foreach my $item (@usertools) {
2931: if ($env{'form.custom'.$item} == 1) {
2932: $newcustom{$item} = $env{'form.tools_'.$item};
2933: $changed{$item} = &tool_admin($item,$newcustom{$item},
2934: \%changeHash,'tools');
2935: }
1.267 raeburn 2936: }
1.334 raeburn 2937: foreach my $item (@requestcourses) {
1.341 raeburn 2938: if ($env{'form.custom'.$item} == 1) {
2939: $newcustom{$item} = $env{'form.crsreq_'.$item};
2940: if ($env{'form.crsreq_'.$item} eq 'autolimit') {
2941: $newcustom{$item} .= '=';
1.383 raeburn 2942: $env{'form.crsreq_'.$item.'_limit'} =~ s/\D+//g;
2943: if ($env{'form.crsreq_'.$item.'_limit'}) {
1.341 raeburn 2944: $newcustom{$item} .= $env{'form.crsreq_'.$item.'_limit'};
2945: }
1.334 raeburn 2946: }
1.341 raeburn 2947: $changed{$item} = &tool_admin($item,$newcustom{$item},
2948: \%changeHash,'requestcourses');
1.334 raeburn 2949: }
1.275 raeburn 2950: }
1.362 raeburn 2951: if ($env{'form.customrequestauthor'} == 1) {
2952: $newcustom{'requestauthor'} = $env{'form.requestauthor'};
2953: $changed{'requestauthor'} = &tool_admin('requestauthor',
2954: $newcustom{'requestauthor'},
2955: \%changeHash,'requestauthor');
2956: }
1.275 raeburn 2957: }
1.334 raeburn 2958: if ($canmodify_status{'inststatus'}) {
2959: if (exists($env{'form.inststatus'})) {
2960: my @inststatuses = &Apache::loncommon::get_env_multiple('form.inststatus');
2961: if (@inststatuses > 0) {
2962: $changeHash{'inststatus'} = join(',',@inststatuses);
2963: $changed{'inststatus'} = $changeHash{'inststatus'};
1.306 raeburn 2964: }
2965: }
1.232 raeburn 2966: }
1.334 raeburn 2967: if (keys(%changed)) {
2968: foreach my $item (@userinfo) {
2969: $changeHash{$item} = $env{'form.c'.$item};
1.286 raeburn 2970: }
1.267 raeburn 2971: my $chgresult =
2972: &Apache::lonnet::put('environment',\%changeHash,
2973: $env{'form.ccdomain'},$env{'form.ccuname'});
2974: }
1.232 raeburn 2975: }
1.219 raeburn 2976: $r->print('<br />'.&mt('Home server').': '.$uhome.' '.
2977: &Apache::lonnet::hostname($uhome));
1.101 albertel 2978: } elsif (($env{'form.login'} ne 'nochange') &&
2979: ($env{'form.login'} ne '' )) {
1.27 matthew 2980: # Modify user privileges
2981: if (! $amode || ! $genpwd) {
1.193 raeburn 2982: $r->print($error.'Invalid login mode or password'.$end.$rtnlink);
1.27 matthew 2983: return;
1.20 harris41 2984: }
1.395 bisitz 2985: # Only allow authentication modification if the person has authority
1.101 albertel 2986: if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'})) {
1.20 harris41 2987: $r->print('Modifying authentication: '.
1.31 matthew 2988: &Apache::lonnet::modifyuserauth(
1.101 albertel 2989: $env{'form.ccdomain'},$env{'form.ccuname'},
1.21 harris41 2990: $amode,$genpwd));
1.102 albertel 2991: $r->print('<br />'.&mt('Home server').': '.&Apache::lonnet::homeserver
1.101 albertel 2992: ($env{'form.ccuname'},$env{'form.ccdomain'}));
1.4 www 2993: } else {
1.27 matthew 2994: # Okay, this is a non-fatal error.
1.406.2.17 raeburn 2995: $r->print($error.&mt('You do not have privileges to modify the authentication configuration for this user.').$end);
1.27 matthew 2996: }
1.406.2.17 raeburn 2997: } elsif (($env{'form.intarg'} ne '') &&
2998: (&Apache::lonnet::queryauthenticate($env{'form.ccuname'},$env{'form.ccdomain'}) =~ /^internal:/) &&
2999: (&Apache::lonuserutils::can_change_internalpass($env{'form.ccuname'},$env{'form.ccdomain'},$crstype,$permission))) {
3000: $r->print('Modifying authentication: '.
3001: &Apache::lonnet::modifyuserauth(
3002: $env{'form.ccdomain'},$env{'form.ccuname'},
3003: 'internal',$env{'form.intarg'}));
1.28 matthew 3004: }
1.344 bisitz 3005: $r->rflush(); # Finish display of header before time consuming actions start
1.367 golterma 3006: &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state);
1.28 matthew 3007: ##
1.375 raeburn 3008: my (@userroles,%userupdate,$cnum,$cdom,$defaultcredits,%namechanged);
1.213 raeburn 3009: if ($context eq 'course') {
1.375 raeburn 3010: ($cnum,$cdom) =
3011: &Apache::lonuserutils::get_course_identity();
1.318 raeburn 3012: $crstype = &Apache::loncommon::course_type($cdom.'_'.$cnum);
1.375 raeburn 3013: if ($showcredits) {
3014: $defaultcredits = &Apache::lonuserutils::get_defaultcredits($cdom,$cnum);
3015: }
1.213 raeburn 3016: }
1.101 albertel 3017: if (! $env{'form.makeuser'} ) {
1.28 matthew 3018: # Check for need to change
3019: my %userenv = &Apache::lonnet::get
1.134 raeburn 3020: ('environment',['firstname','middlename','lastname','generation',
1.378 raeburn 3021: 'id','permanentemail','portfolioquota','authorquota','inststatus',
3022: 'tools.aboutme','tools.blog','tools.webdav','tools.portfolio',
1.361 raeburn 3023: 'requestcourses.official','requestcourses.unofficial',
1.384 raeburn 3024: 'requestcourses.community','requestcourses.textbook',
3025: 'reqcrsotherdom.official','reqcrsotherdom.unofficial',
3026: 'reqcrsotherdom.community','reqcrsotherdom.textbook',
1.406.2.9 raeburn 3027: 'requestauthor'],
1.160 raeburn 3028: $env{'form.ccdomain'},$env{'form.ccuname'});
1.28 matthew 3029: my ($tmp) = keys(%userenv);
3030: if ($tmp =~ /^(con_lost|error)/i) {
3031: %userenv = ();
3032: }
1.206 raeburn 3033: my $no_forceid_alert;
3034: # Check to see if user information can be changed
3035: my %domconfig =
3036: &Apache::lonnet::get_dom('configuration',['usermodification'],
3037: $env{'form.ccdomain'});
1.213 raeburn 3038: my @statuses = ('active','future');
3039: my %roles = &Apache::lonnet::get_my_roles($env{'form.ccuname'},$env{'form.ccdomain'},'userroles',\@statuses,undef,$env{'request.role.domain'});
3040: my ($auname,$audom);
1.220 raeburn 3041: if ($context eq 'author') {
1.206 raeburn 3042: $auname = $env{'user.name'};
3043: $audom = $env{'user.domain'};
3044: }
3045: foreach my $item (keys(%roles)) {
1.220 raeburn 3046: my ($rolenum,$roledom,$role) = split(/:/,$item,-1);
1.206 raeburn 3047: if ($context eq 'course') {
3048: if ($cnum ne '' && $cdom ne '') {
3049: if ($rolenum eq $cnum && $roledom eq $cdom) {
3050: if (!grep(/^\Q$role\E$/,@userroles)) {
3051: push(@userroles,$role);
3052: }
3053: }
3054: }
3055: } elsif ($context eq 'author') {
3056: if ($rolenum eq $auname && $roledom eq $audom) {
3057: if (!grep(/^\Q$role\E$/,@userroles)) {
3058: push(@userroles,$role);
3059: }
3060: }
3061: }
3062: }
1.220 raeburn 3063: if ($env{'form.action'} eq 'singlestudent') {
3064: if (!grep(/^st$/,@userroles)) {
3065: push(@userroles,'st');
3066: }
3067: } else {
3068: # Check for course or co-author roles being activated or re-enabled
3069: if ($context eq 'author' || $context eq 'course') {
3070: foreach my $key (keys(%env)) {
3071: if ($context eq 'author') {
3072: if ($key=~/^form\.act_\Q$audom\E_\Q$auname\E_([^_]+)/) {
3073: if (!grep(/^\Q$1\E$/,@userroles)) {
3074: push(@userroles,$1);
3075: }
3076: } elsif ($key =~/^form\.ren\:\Q$audom\E\/\Q$auname\E_([^_]+)/) {
3077: if (!grep(/^\Q$1\E$/,@userroles)) {
3078: push(@userroles,$1);
3079: }
1.206 raeburn 3080: }
1.220 raeburn 3081: } elsif ($context eq 'course') {
3082: if ($key=~/^form\.act_\Q$cdom\E_\Q$cnum\E_([^_]+)/) {
3083: if (!grep(/^\Q$1\E$/,@userroles)) {
3084: push(@userroles,$1);
3085: }
3086: } elsif ($key =~/^form\.ren\:\Q$cdom\E\/\Q$cnum\E(\/?\w*)_([^_]+)/) {
3087: if (!grep(/^\Q$1\E$/,@userroles)) {
3088: push(@userroles,$1);
3089: }
1.206 raeburn 3090: }
3091: }
3092: }
3093: }
3094: }
3095: #Check to see if we can change personal data for the user
3096: my (@mod_disallowed,@longroles);
3097: foreach my $role (@userroles) {
3098: if ($role eq 'cr') {
3099: push(@longroles,'Custom');
3100: } else {
1.318 raeburn 3101: push(@longroles,&Apache::lonnet::plaintext($role,$crstype));
1.206 raeburn 3102: }
3103: }
1.219 raeburn 3104: my %canmodify = &Apache::lonuserutils::can_modify_userinfo($context,$env{'form.ccdomain'},\@userinfo,\@userroles);
3105: foreach my $item (@userinfo) {
1.28 matthew 3106: # Strip leading and trailing whitespace
1.203 raeburn 3107: $env{'form.c'.$item} =~ s/(\s+$|^\s+)//g;
1.219 raeburn 3108: if (!$canmodify{$item}) {
1.207 raeburn 3109: if (defined($env{'form.c'.$item})) {
3110: if ($env{'form.c'.$item} ne $userenv{$item}) {
3111: push(@mod_disallowed,$item);
3112: }
1.206 raeburn 3113: }
3114: $env{'form.c'.$item} = $userenv{$item};
3115: }
1.28 matthew 3116: }
1.259 bisitz 3117: # Check to see if we can change the Student/Employee ID
1.196 raeburn 3118: my $forceid = $env{'form.forceid'};
3119: my $recurseid = $env{'form.recurseid'};
3120: my (%alerts,%rulematch,%idinst_results,%curr_rules,%got_rules);
1.203 raeburn 3121: my %uidhash = &Apache::lonnet::idrget($env{'form.ccdomain'},
3122: $env{'form.ccuname'});
3123: if (($uidhash{$env{'form.ccuname'}}) &&
3124: ($uidhash{$env{'form.ccuname'}}!~/error\:/) &&
3125: (!$forceid)) {
3126: if ($env{'form.cid'} ne $uidhash{$env{'form.ccuname'}}) {
3127: $env{'form.cid'} = $userenv{'id'};
1.293 bisitz 3128: $no_forceid_alert = &mt('New student/employee ID does not match existing ID for this user.')
1.259 bisitz 3129: .'<br />'
3130: .&mt("Change is not permitted without checking the 'Force ID change' checkbox on the previous page.")
3131: .'<br />'."\n";
1.203 raeburn 3132: }
3133: }
3134: if ($env{'form.cid'} ne $userenv{'id'}) {
1.196 raeburn 3135: my $checkhash;
3136: my $checks = { 'id' => 1 };
3137: $checkhash->{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}} =
3138: { 'newuser' => $newuser,
3139: 'id' => $env{'form.cid'},
3140: };
3141: &Apache::loncommon::user_rule_check($checkhash,$checks,
3142: \%alerts,\%rulematch,\%idinst_results,\%curr_rules,\%got_rules);
3143: if (ref($alerts{'id'}) eq 'HASH') {
3144: if (ref($alerts{'id'}{$env{'form.ccdomain'}}) eq 'HASH') {
1.203 raeburn 3145: $env{'form.cid'} = $userenv{'id'};
1.196 raeburn 3146: }
3147: }
3148: }
1.378 raeburn 3149: my (%quotachanged,%oldquota,%newquota,%olddefquota,%newdefquota,
3150: $oldinststatus,$newinststatus,%oldisdefault,%newisdefault,%oldsettings,
1.339 raeburn 3151: %oldsettingstext,%newsettings,%newsettingstext,@disporder,
1.378 raeburn 3152: %oldsettingstatus,%newsettingstatus);
1.334 raeburn 3153: @disporder = ('inststatus');
3154: if ($env{'request.role.domain'} eq $env{'form.ccdomain'}) {
1.362 raeburn 3155: push(@disporder,'requestcourses','requestauthor');
1.334 raeburn 3156: } else {
3157: push(@disporder,'reqcrsotherdom');
3158: }
3159: push(@disporder,('quota','tools'));
1.338 raeburn 3160: $oldinststatus = $userenv{'inststatus'};
1.378 raeburn 3161: foreach my $name ('portfolio','author') {
3162: ($olddefquota{$name},$oldsettingstatus{$name}) =
3163: &Apache::loncommon::default_quota($env{'form.ccdomain'},$oldinststatus,$name);
3164: ($newdefquota{$name},$newsettingstatus{$name}) = ($olddefquota{$name},$oldsettingstatus{$name});
3165: }
1.334 raeburn 3166: my %canshow;
1.220 raeburn 3167: if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
1.334 raeburn 3168: $canshow{'quota'} = 1;
1.220 raeburn 3169: }
1.267 raeburn 3170: if (&Apache::lonnet::allowed('mut',$env{'form.ccdomain'})) {
1.334 raeburn 3171: $canshow{'tools'} = 1;
1.267 raeburn 3172: }
1.275 raeburn 3173: if (&Apache::lonnet::allowed('ccc',$env{'form.ccdomain'})) {
1.334 raeburn 3174: $canshow{'requestcourses'} = 1;
1.300 raeburn 3175: } elsif (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
1.334 raeburn 3176: $canshow{'reqcrsotherdom'} = 1;
1.275 raeburn 3177: }
1.286 raeburn 3178: if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'})) {
1.334 raeburn 3179: $canshow{'inststatus'} = 1;
1.286 raeburn 3180: }
1.362 raeburn 3181: if (&Apache::lonnet::allowed('cau',$env{'form.ccdomain'})) {
3182: $canshow{'requestauthor'} = 1;
3183: }
1.267 raeburn 3184: my (%changeHash,%changed);
1.286 raeburn 3185: if ($oldinststatus eq '') {
1.334 raeburn 3186: $oldsettings{'inststatus'} = $othertitle;
1.286 raeburn 3187: } else {
3188: if (ref($usertypes) eq 'HASH') {
1.334 raeburn 3189: $oldsettings{'inststatus'} = join(', ',map{ $usertypes->{ &unescape($_) }; } (split(/:/,$userenv{'inststatus'})));
1.286 raeburn 3190: } else {
1.334 raeburn 3191: $oldsettings{'inststatus'} = join(', ',map{ &unescape($_); } (split(/:/,$userenv{'inststatus'})));
1.286 raeburn 3192: }
3193: }
3194: $changeHash{'inststatus'} = $userenv{'inststatus'};
1.334 raeburn 3195: if ($canmodify_status{'inststatus'}) {
3196: $canshow{'inststatus'} = 1;
1.286 raeburn 3197: if (exists($env{'form.inststatus'})) {
3198: my @inststatuses = &Apache::loncommon::get_env_multiple('form.inststatus');
3199: if (@inststatuses > 0) {
3200: $newinststatus = join(':',map { &escape($_); } @inststatuses);
3201: $changeHash{'inststatus'} = $newinststatus;
3202: if ($newinststatus ne $oldinststatus) {
3203: $changed{'inststatus'} = $newinststatus;
1.378 raeburn 3204: foreach my $name ('portfolio','author') {
3205: ($newdefquota{$name},$newsettingstatus{$name}) =
3206: &Apache::loncommon::default_quota($env{'form.ccdomain'},$newinststatus,$name);
3207: }
1.286 raeburn 3208: }
3209: if (ref($usertypes) eq 'HASH') {
1.334 raeburn 3210: $newsettings{'inststatus'} = join(', ',map{ $usertypes->{$_}; } (@inststatuses));
1.286 raeburn 3211: } else {
1.337 raeburn 3212: $newsettings{'inststatus'} = join(', ',@inststatuses);
1.286 raeburn 3213: }
1.334 raeburn 3214: }
3215: } else {
3216: $newinststatus = '';
3217: $changeHash{'inststatus'} = $newinststatus;
3218: $newsettings{'inststatus'} = $othertitle;
3219: if ($newinststatus ne $oldinststatus) {
3220: $changed{'inststatus'} = $changeHash{'inststatus'};
1.378 raeburn 3221: foreach my $name ('portfolio','author') {
3222: ($newdefquota{$name},$newsettingstatus{$name}) =
3223: &Apache::loncommon::default_quota($env{'form.ccdomain'},$newinststatus,$name);
3224: }
1.286 raeburn 3225: }
3226: }
1.334 raeburn 3227: } elsif ($context ne 'selfcreate') {
3228: $canshow{'inststatus'} = 1;
1.337 raeburn 3229: $newsettings{'inststatus'} = $oldsettings{'inststatus'};
1.286 raeburn 3230: }
1.378 raeburn 3231: foreach my $name ('portfolio','author') {
3232: $changeHash{$name.'quota'} = $userenv{$name.'quota'};
3233: }
1.334 raeburn 3234: if ($context eq 'domain') {
1.378 raeburn 3235: foreach my $name ('portfolio','author') {
3236: if ($userenv{$name.'quota'} ne '') {
3237: $oldquota{$name} = $userenv{$name.'quota'};
3238: if ($env{'form.custom_'.$name.'quota'} == 1) {
3239: if ($env{'form.'.$name.'quota'} eq '') {
3240: $newquota{$name} = 0;
3241: } else {
3242: $newquota{$name} = $env{'form.'.$name.'quota'};
3243: $newquota{$name} =~ s/[^\d\.]//g;
3244: }
3245: if ($newquota{$name} != $oldquota{$name}) {
3246: if ("a_admin($newquota{$name},\%changeHash,$name)) {
3247: $changed{$name.'quota'} = 1;
3248: }
3249: }
1.334 raeburn 3250: } else {
1.378 raeburn 3251: if ("a_admin('',\%changeHash,$name)) {
3252: $changed{$name.'quota'} = 1;
3253: $newquota{$name} = $newdefquota{$name};
3254: $newisdefault{$name} = 1;
3255: }
1.334 raeburn 3256: }
1.149 raeburn 3257: } else {
1.378 raeburn 3258: $oldisdefault{$name} = 1;
3259: $oldquota{$name} = $olddefquota{$name};
3260: if ($env{'form.custom_'.$name.'quota'} == 1) {
3261: if ($env{'form.'.$name.'quota'} eq '') {
3262: $newquota{$name} = 0;
3263: } else {
3264: $newquota{$name} = $env{'form.'.$name.'quota'};
3265: $newquota{$name} =~ s/[^\d\.]//g;
3266: }
3267: if ("a_admin($newquota{$name},\%changeHash,$name)) {
3268: $changed{$name.'quota'} = 1;
3269: }
1.334 raeburn 3270: } else {
1.378 raeburn 3271: $newquota{$name} = $newdefquota{$name};
3272: $newisdefault{$name} = 1;
1.334 raeburn 3273: }
1.378 raeburn 3274: }
3275: if ($oldisdefault{$name}) {
3276: $oldsettingstext{'quota'}{$name} = &get_defaultquota_text($oldsettingstatus{$name});
1.383 raeburn 3277: } else {
3278: $oldsettingstext{'quota'}{$name} = &mt('custom quota: [_1] MB',$oldquota{$name});
1.378 raeburn 3279: }
3280: if ($newisdefault{$name}) {
3281: $newsettingstext{'quota'}{$name} = &get_defaultquota_text($newsettingstatus{$name});
1.383 raeburn 3282: } else {
3283: $newsettingstext{'quota'}{$name} = &mt('custom quota: [_1] MB',$newquota{$name});
1.134 raeburn 3284: }
3285: }
1.334 raeburn 3286: &tool_changes('tools',\@usertools,\%oldsettings,\%oldsettingstext,\%userenv,
3287: \%changeHash,\%changed,\%newsettings,\%newsettingstext);
3288: if ($env{'form.ccdomain'} eq $env{'request.role.domain'}) {
3289: &tool_changes('requestcourses',\@requestcourses,\%oldsettings,\%oldsettingstext,
3290: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
1.384 raeburn 3291: &tool_changes('requestauthor',\@requestauthor,\%oldsettings,\%oldsettingstext,
3292: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
1.149 raeburn 3293: } else {
1.334 raeburn 3294: &tool_changes('reqcrsotherdom',\@requestcourses,\%oldsettings,\%oldsettingstext,
3295: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
1.149 raeburn 3296: }
3297: }
1.334 raeburn 3298: foreach my $item (@userinfo) {
3299: if ($env{'form.c'.$item} ne $userenv{$item}) {
3300: $namechanged{$item} = 1;
3301: }
1.204 raeburn 3302: }
1.378 raeburn 3303: foreach my $name ('portfolio','author') {
1.390 bisitz 3304: $oldsettings{'quota'}{$name} = &mt('[_1] MB',$oldquota{$name});
3305: $newsettings{'quota'}{$name} = &mt('[_1] MB',$newquota{$name});
1.378 raeburn 3306: }
1.334 raeburn 3307: if ((keys(%namechanged) > 0) || (keys(%changed) > 0)) {
1.267 raeburn 3308: my ($chgresult,$namechgresult);
3309: if (keys(%changed) > 0) {
3310: $chgresult =
1.204 raeburn 3311: &Apache::lonnet::put('environment',\%changeHash,
3312: $env{'form.ccdomain'},$env{'form.ccuname'});
1.267 raeburn 3313: if ($chgresult eq 'ok') {
3314: if (($env{'user.name'} eq $env{'form.ccuname'}) &&
3315: ($env{'user.domain'} eq $env{'form.ccdomain'})) {
1.270 raeburn 3316: my %newenvhash;
3317: foreach my $key (keys(%changed)) {
1.299 raeburn 3318: if (($key eq 'official') || ($key eq 'unofficial')
1.403 raeburn 3319: || ($key eq 'community') || ($key eq 'textbook')) {
1.279 raeburn 3320: $newenvhash{'environment.requestcourses.'.$key} =
3321: $changeHash{'requestcourses.'.$key};
1.362 raeburn 3322: if ($changeHash{'requestcourses.'.$key}) {
1.332 raeburn 3323: $newenvhash{'environment.canrequest.'.$key} = 1;
1.279 raeburn 3324: } else {
3325: $newenvhash{'environment.canrequest.'.$key} =
3326: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
3327: $key,'reload','requestcourses');
3328: }
1.362 raeburn 3329: } elsif ($key eq 'requestauthor') {
3330: $newenvhash{'environment.'.$key} = $changeHash{$key};
3331: if ($changeHash{$key}) {
3332: $newenvhash{'environment.canrequest.author'} = 1;
3333: } else {
3334: $newenvhash{'environment.canrequest.author'} =
3335: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
3336: $key,'reload','requestauthor');
3337: }
1.275 raeburn 3338: } elsif ($key ne 'quota') {
1.270 raeburn 3339: $newenvhash{'environment.tools.'.$key} =
3340: $changeHash{'tools.'.$key};
1.279 raeburn 3341: if ($changeHash{'tools.'.$key} ne '') {
3342: $newenvhash{'environment.availabletools.'.$key} =
3343: $changeHash{'tools.'.$key};
3344: } else {
3345: $newenvhash{'environment.availabletools.'.$key} =
1.367 golterma 3346: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
3347: $key,'reload','tools');
1.279 raeburn 3348: }
1.270 raeburn 3349: }
3350: }
1.271 raeburn 3351: if (keys(%newenvhash)) {
3352: &Apache::lonnet::appenv(\%newenvhash);
3353: }
1.267 raeburn 3354: }
3355: }
1.204 raeburn 3356: }
1.334 raeburn 3357: if (keys(%namechanged) > 0) {
1.337 raeburn 3358: foreach my $field (@userinfo) {
3359: $changeHash{$field} = $env{'form.c'.$field};
3360: }
3361: # Make the change
1.204 raeburn 3362: $namechgresult =
3363: &Apache::lonnet::modifyuser($env{'form.ccdomain'},
3364: $env{'form.ccuname'},$changeHash{'id'},undef,undef,
3365: $changeHash{'firstname'},$changeHash{'middlename'},
3366: $changeHash{'lastname'},$changeHash{'generation'},
1.337 raeburn 3367: $changeHash{'id'},undef,$changeHash{'permanentemail'},undef,\@userinfo);
1.220 raeburn 3368: %userupdate = (
3369: lastname => $env{'form.clastname'},
3370: middlename => $env{'form.cmiddlename'},
3371: firstname => $env{'form.cfirstname'},
3372: generation => $env{'form.cgeneration'},
3373: id => $env{'form.cid'},
3374: );
1.204 raeburn 3375: }
1.334 raeburn 3376: if (((keys(%namechanged) > 0) && $namechgresult eq 'ok') ||
1.267 raeburn 3377: ((keys(%changed) > 0) && $chgresult eq 'ok')) {
1.28 matthew 3378: # Tell the user we changed the name
1.334 raeburn 3379: &display_userinfo($r,1,\@disporder,\%canshow,\@requestcourses,
1.362 raeburn 3380: \@usertools,\@requestauthor,\%userenv,\%changed,\%namechanged,
1.334 raeburn 3381: \%oldsettings, \%oldsettingstext,\%newsettings,
3382: \%newsettingstext);
1.203 raeburn 3383: if ($env{'form.cid'} ne $userenv{'id'}) {
3384: &Apache::lonnet::idput($env{'form.ccdomain'},
1.406.2.5 raeburn 3385: {$env{'form.ccuname'} => $env{'form.cid'}});
1.203 raeburn 3386: if (($recurseid) &&
3387: (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'}))) {
3388: my $idresult =
3389: &Apache::lonuserutils::propagate_id_change(
3390: $env{'form.ccuname'},$env{'form.ccdomain'},
3391: \%userupdate);
3392: $r->print('<br />'.$idresult.'<br />');
3393: }
1.196 raeburn 3394: }
1.149 raeburn 3395: if (($env{'form.ccdomain'} eq $env{'user.domain'}) &&
3396: ($env{'form.ccuname'} eq $env{'user.name'})) {
3397: my %newenvhash;
3398: foreach my $key (keys(%changeHash)) {
3399: $newenvhash{'environment.'.$key} = $changeHash{$key};
3400: }
1.238 raeburn 3401: &Apache::lonnet::appenv(\%newenvhash);
1.149 raeburn 3402: }
1.28 matthew 3403: } else { # error occurred
1.389 bisitz 3404: $r->print(
3405: '<p class="LC_error">'
3406: .&mt('Unable to successfully change environment for [_1] in domain [_2].',
3407: '"'.$env{'form.ccuname'}.'"',
3408: '"'.$env{'form.ccdomain'}.'"')
3409: .'</p>');
1.28 matthew 3410: }
1.334 raeburn 3411: } else { # End of if ($env ... ) logic
1.275 raeburn 3412: # They did not want to change the users name, quota, tool availability,
3413: # or ability to request creation of courses,
1.267 raeburn 3414: # but we can still tell them what the name and quota and availabilities are
1.334 raeburn 3415: &display_userinfo($r,undef,\@disporder,\%canshow,\@requestcourses,
1.362 raeburn 3416: \@usertools,\@requestauthor,\%userenv,\%changed,\%namechanged,\%oldsettings,
1.334 raeburn 3417: \%oldsettingstext,\%newsettings,\%newsettingstext);
1.28 matthew 3418: }
1.206 raeburn 3419: if (@mod_disallowed) {
3420: my ($rolestr,$contextname);
3421: if (@longroles > 0) {
3422: $rolestr = join(', ',@longroles);
3423: } else {
3424: $rolestr = &mt('No roles');
3425: }
3426: if ($context eq 'course') {
1.399 bisitz 3427: $contextname = 'course';
1.206 raeburn 3428: } elsif ($context eq 'author') {
1.399 bisitz 3429: $contextname = 'co-author';
1.206 raeburn 3430: }
3431: $r->print(&mt('The following fields were not updated: ').'<ul>');
3432: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
3433: foreach my $field (@mod_disallowed) {
3434: $r->print('<li>'.$fieldtitles{$field}.'</li>'."\n");
3435: }
1.207 raeburn 3436: $r->print('</ul>');
3437: if (@mod_disallowed == 1) {
1.399 bisitz 3438: $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 3439: } else {
1.399 bisitz 3440: $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 3441: }
1.292 bisitz 3442: my $helplink = 'javascript:helpMenu('."'display'".')';
3443: $r->print('<span class="LC_cusr_emph">'.$rolestr.'</span><br />'
3444: .&mt('Please contact your [_1]helpdesk[_2] for more information.'
3445: ,'<a href="'.$helplink.'">','</a>')
3446: .'<br />');
1.206 raeburn 3447: }
1.259 bisitz 3448: $r->print('<span class="LC_warning">'
3449: .$no_forceid_alert
3450: .&Apache::lonuserutils::print_namespacing_alerts($env{'form.ccdomain'},\%alerts,\%curr_rules)
3451: .'</span>');
1.4 www 3452: }
1.367 golterma 3453: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
1.220 raeburn 3454: if ($env{'form.action'} eq 'singlestudent') {
1.375 raeburn 3455: &enroll_single_student($r,$uhome,$amode,$genpwd,$now,$newuser,$context,
3456: $crstype,$showcredits,$defaultcredits);
1.386 bisitz 3457: my $linktext = ($crstype eq 'Community' ?
3458: &mt('Enroll Another Member') : &mt('Enroll Another Student'));
3459: $r->print(
3460: &Apache::lonhtmlcommon::actionbox([
3461: '<a href="javascript:backPage(document.userupdate)">'
3462: .($crstype eq 'Community' ?
3463: &mt('Enroll Another Member') : &mt('Enroll Another Student'))
3464: .'</a>']));
1.220 raeburn 3465: } else {
1.375 raeburn 3466: my @rolechanges = &update_roles($r,$context,$showcredits);
1.334 raeburn 3467: if (keys(%namechanged) > 0) {
1.220 raeburn 3468: if ($context eq 'course') {
3469: if (@userroles > 0) {
1.225 raeburn 3470: if ((@rolechanges == 0) ||
3471: (!(grep(/^st$/,@rolechanges)))) {
3472: if (grep(/^st$/,@userroles)) {
3473: my $classlistupdated =
3474: &Apache::lonuserutils::update_classlist($cdom,
1.220 raeburn 3475: $cnum,$env{'form.ccdomain'},
3476: $env{'form.ccuname'},\%userupdate);
1.225 raeburn 3477: }
1.220 raeburn 3478: }
3479: }
3480: }
3481: }
1.226 raeburn 3482: my $userinfo = &Apache::loncommon::plainname($env{'form.ccuname'},
1.233 raeburn 3483: $env{'form.ccdomain'});
3484: if ($env{'form.popup'}) {
3485: $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a></p>');
3486: } else {
1.367 golterma 3487: $r->print('<br />'.&Apache::lonhtmlcommon::actionbox(['<a href="javascript:backPage(document.userupdate,'."'$env{'form.prevphase'}','modify'".')">'
3488: .&mt('Modify this user: [_1]','<span class="LC_cusr_emph">'.$env{'form.ccuname'}.':'.$env{'form.ccdomain'}.' ('.$userinfo.')</span>').'</a>',
3489: '<a href="javascript:backPage(document.userupdate)">'.&mt('Create/Modify Another User').'</a>']));
1.233 raeburn 3490: }
1.220 raeburn 3491: }
3492: }
3493:
1.334 raeburn 3494: sub display_userinfo {
1.362 raeburn 3495: my ($r,$changed,$order,$canshow,$requestcourses,$usertools,$requestauthor,
3496: $userenv,$changedhash,$namechangedhash,$oldsetting,$oldsettingtext,
1.334 raeburn 3497: $newsetting,$newsettingtext) = @_;
3498: return unless (ref($order) eq 'ARRAY' &&
3499: ref($canshow) eq 'HASH' &&
3500: ref($requestcourses) eq 'ARRAY' &&
1.362 raeburn 3501: ref($requestauthor) eq 'ARRAY' &&
1.334 raeburn 3502: ref($usertools) eq 'ARRAY' &&
3503: ref($userenv) eq 'HASH' &&
3504: ref($changedhash) eq 'HASH' &&
3505: ref($oldsetting) eq 'HASH' &&
3506: ref($oldsettingtext) eq 'HASH' &&
3507: ref($newsetting) eq 'HASH' &&
3508: ref($newsettingtext) eq 'HASH');
3509: my %lt=&Apache::lonlocal::texthash(
1.372 raeburn 3510: 'ui' => 'User Information',
1.334 raeburn 3511: 'uic' => 'User Information Changed',
3512: 'firstname' => 'First Name',
3513: 'middlename' => 'Middle Name',
3514: 'lastname' => 'Last Name',
3515: 'generation' => 'Generation',
3516: 'id' => 'Student/Employee ID',
3517: 'permanentemail' => 'Permanent e-mail address',
1.378 raeburn 3518: 'portfolioquota' => 'Disk space allocated to portfolio files',
1.385 bisitz 3519: 'authorquota' => 'Disk space allocated to Authoring Space',
1.334 raeburn 3520: 'blog' => 'Blog Availability',
1.361 raeburn 3521: 'webdav' => 'WebDAV Availability',
1.334 raeburn 3522: 'aboutme' => 'Personal Information Page Availability',
3523: 'portfolio' => 'Portfolio Availability',
3524: 'official' => 'Can Request Official Courses',
3525: 'unofficial' => 'Can Request Unofficial Courses',
3526: 'community' => 'Can Request Communities',
1.384 raeburn 3527: 'textbook' => 'Can Request Textbook Courses',
1.362 raeburn 3528: 'requestauthor' => 'Can Request Author Role',
1.334 raeburn 3529: 'inststatus' => "Affiliation",
3530: 'prvs' => 'Previous Value:',
3531: 'chto' => 'Changed To:'
3532: );
3533: if ($changed) {
1.372 raeburn 3534: $r->print('<h3>'.$lt{'uic'}.'</h3>'.
1.367 golterma 3535: &Apache::loncommon::start_data_table().
3536: &Apache::loncommon::start_data_table_header_row());
1.334 raeburn 3537: $r->print("<th> </th>\n");
1.367 golterma 3538: $r->print('<th><b>'.$lt{'prvs'}.'</b></th>');
3539: $r->print('<th><span class="LC_nobreak"><b>'.$lt{'chto'}.'</b></span></th>');
3540: $r->print(&Apache::loncommon::end_data_table_header_row());
3541: my @userinfo = ('firstname','middlename','lastname','generation','permanentemail','id');
3542:
1.334 raeburn 3543: foreach my $item (@userinfo) {
3544: my $value = $env{'form.c'.$item};
1.367 golterma 3545: #show changes only:
1.383 raeburn 3546: unless ($value eq $userenv->{$item}){
1.367 golterma 3547: $r->print(&Apache::loncommon::start_data_table_row());
3548: $r->print("<td>$lt{$item}</td>\n");
1.383 raeburn 3549: $r->print("<td>".$userenv->{$item}."</td>\n");
1.367 golterma 3550: $r->print("<td>$value </td>\n");
3551: $r->print(&Apache::loncommon::end_data_table_row());
1.334 raeburn 3552: }
3553: }
3554: foreach my $entry (@{$order}) {
1.383 raeburn 3555: if ($canshow->{$entry}) {
3556: if (($entry eq 'requestcourses') || ($entry eq 'reqcrsotherdom') || ($entry eq 'requestauthor')) {
3557: my @items;
3558: if ($entry eq 'requestauthor') {
3559: @items = ($entry);
3560: } else {
3561: @items = @{$requestcourses};
1.384 raeburn 3562: }
1.383 raeburn 3563: foreach my $item (@items) {
3564: if (($newsetting->{$item} ne $oldsetting->{$item}) ||
3565: ($newsettingtext->{$item} ne $oldsettingtext->{$item})) {
3566: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3567: $r->print("<td>$lt{$item}</td>\n");
3568: $r->print("<td>".$oldsetting->{$item});
3569: if ($oldsettingtext->{$item}) {
3570: if ($oldsetting->{$item}) {
3571: $r->print(' -- ');
3572: }
3573: $r->print($oldsettingtext->{$item});
3574: }
3575: $r->print("</td>\n");
3576: $r->print("<td>".$newsetting->{$item});
3577: if ($newsettingtext->{$item}) {
3578: if ($newsetting->{$item}) {
3579: $r->print(' -- ');
3580: }
3581: $r->print($newsettingtext->{$item});
3582: }
3583: $r->print("</td>\n");
3584: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.334 raeburn 3585: }
3586: }
3587: } elsif ($entry eq 'tools') {
3588: foreach my $item (@{$usertools}) {
1.383 raeburn 3589: if ($newsetting->{$item} ne $oldsetting->{$item}) {
3590: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3591: $r->print("<td>$lt{$item}</td>\n");
3592: $r->print("<td>".$oldsetting->{$item}.' '.$oldsettingtext->{$item}."</td>\n");
3593: $r->print("<td>".$newsetting->{$item}.' '.$newsettingtext->{$item}."</td>\n");
3594: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.334 raeburn 3595: }
3596: }
1.378 raeburn 3597: } elsif ($entry eq 'quota') {
3598: if ((ref($oldsetting->{$entry}) eq 'HASH') && (ref($oldsettingtext->{$entry}) eq 'HASH') &&
3599: (ref($newsetting->{$entry}) eq 'HASH') && (ref($newsettingtext->{$entry}) eq 'HASH')) {
3600: foreach my $name ('portfolio','author') {
1.383 raeburn 3601: if ($newsetting->{$entry}->{$name} ne $oldsetting->{$entry}->{$name}) {
3602: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3603: $r->print("<td>$lt{$name.$entry}</td>\n");
3604: $r->print("<td>".$oldsettingtext->{$entry}->{$name}."</td>\n");
3605: $r->print("<td>".$newsettingtext->{$entry}->{$name}."</td>\n");
3606: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.378 raeburn 3607: }
3608: }
3609: }
1.334 raeburn 3610: } else {
1.383 raeburn 3611: if ($newsetting->{$entry} ne $oldsetting->{$entry}) {
3612: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3613: $r->print("<td>$lt{$entry}</td>\n");
3614: $r->print("<td>".$oldsetting->{$entry}.' '.$oldsettingtext->{$entry}."</td>\n");
3615: $r->print("<td>".$newsetting->{$entry}.' '.$newsettingtext->{$entry}."</td>\n");
3616: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.334 raeburn 3617: }
3618: }
3619: }
3620: }
1.367 golterma 3621: $r->print(&Apache::loncommon::end_data_table().'<br />');
1.372 raeburn 3622: } else {
3623: $r->print('<h3>'.$lt{'ui'}.'</h3>'.
3624: '<p>'.&mt('No changes made to user information').'</p>');
1.334 raeburn 3625: }
3626: return;
3627: }
3628:
1.275 raeburn 3629: sub tool_changes {
3630: my ($context,$usertools,$oldaccess,$oldaccesstext,$userenv,$changeHash,
3631: $changed,$newaccess,$newaccesstext) = @_;
3632: if (!((ref($usertools) eq 'ARRAY') && (ref($oldaccess) eq 'HASH') &&
3633: (ref($oldaccesstext) eq 'HASH') && (ref($userenv) eq 'HASH') &&
3634: (ref($changeHash) eq 'HASH') && (ref($changed) eq 'HASH') &&
3635: (ref($newaccess) eq 'HASH') && (ref($newaccesstext) eq 'HASH'))) {
3636: return;
3637: }
1.383 raeburn 3638: my %reqdisplay = &requestchange_display();
1.300 raeburn 3639: if ($context eq 'reqcrsotherdom') {
1.309 raeburn 3640: my @options = ('approval','validate','autolimit');
1.306 raeburn 3641: my $optregex = join('|',@options);
1.300 raeburn 3642: my $cdom = $env{'request.role.domain'};
3643: foreach my $tool (@{$usertools}) {
1.383 raeburn 3644: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
1.314 raeburn 3645: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
1.300 raeburn 3646: $changeHash->{$context.'.'.$tool} = $userenv->{$context.'.'.$tool};
1.383 raeburn 3647: my ($newop,$limit);
1.314 raeburn 3648: if ($env{'form.'.$context.'_'.$tool}) {
3649: $newop = $env{'form.'.$context.'_'.$tool};
3650: if ($newop eq 'autolimit') {
1.383 raeburn 3651: $limit = $env{'form.'.$context.'_'.$tool.'_limit'};
1.314 raeburn 3652: $limit =~ s/\D+//g;
3653: $newop .= '='.$limit;
3654: }
3655: }
1.300 raeburn 3656: if ($userenv->{$context.'.'.$tool} eq '') {
1.314 raeburn 3657: if ($newop) {
3658: $changed->{$tool}=&tool_admin($tool,$cdom.':'.$newop,
1.300 raeburn 3659: $changeHash,$context);
3660: if ($changed->{$tool}) {
1.383 raeburn 3661: if ($newop =~ /^autolimit/) {
3662: if ($limit) {
3663: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3664: } else {
3665: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3666: }
3667: } else {
3668: $newaccesstext->{$tool} = $reqdisplay{$newop};
3669: }
1.300 raeburn 3670: } else {
3671: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
3672: }
3673: }
3674: } else {
3675: my @curr = split(',',$userenv->{$context.'.'.$tool});
3676: my @new;
3677: my $changedoms;
1.314 raeburn 3678: foreach my $req (@curr) {
3679: if ($req =~ /^\Q$cdom\E\:($optregex\=?\d*)$/) {
3680: my $oldop = $1;
1.383 raeburn 3681: if ($oldop =~ /^autolimit=(\d*)/) {
3682: my $limit = $1;
3683: if ($limit) {
3684: $oldaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3685: } else {
3686: $oldaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3687: }
3688: } else {
3689: $oldaccesstext->{$tool} = $reqdisplay{$oldop};
3690: }
1.314 raeburn 3691: if ($oldop ne $newop) {
3692: $changedoms = 1;
3693: foreach my $item (@curr) {
3694: my ($reqdom,$option) = split(':',$item);
3695: unless ($reqdom eq $cdom) {
3696: push(@new,$item);
3697: }
3698: }
3699: if ($newop) {
3700: push(@new,$cdom.':'.$newop);
1.300 raeburn 3701: }
1.314 raeburn 3702: @new = sort(@new);
1.300 raeburn 3703: }
1.314 raeburn 3704: last;
1.300 raeburn 3705: }
1.314 raeburn 3706: }
3707: if ((!$changedoms) && ($newop)) {
1.300 raeburn 3708: $changedoms = 1;
1.306 raeburn 3709: @new = sort(@curr,$cdom.':'.$newop);
1.300 raeburn 3710: }
3711: if ($changedoms) {
1.314 raeburn 3712: my $newdomstr;
1.300 raeburn 3713: if (@new) {
3714: $newdomstr = join(',',@new);
3715: }
3716: $changed->{$tool}=&tool_admin($tool,$newdomstr,$changeHash,
3717: $context);
3718: if ($changed->{$tool}) {
3719: if ($env{'form.'.$context.'_'.$tool}) {
1.306 raeburn 3720: if ($env{'form.'.$context.'_'.$tool} eq 'autolimit') {
1.314 raeburn 3721: my $limit = $env{'form.'.$context.'_'.$tool.'_limit'};
3722: $limit =~ s/\D+//g;
3723: if ($limit) {
1.383 raeburn 3724: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
1.314 raeburn 3725: } else {
1.383 raeburn 3726: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
1.306 raeburn 3727: }
1.314 raeburn 3728: } else {
1.306 raeburn 3729: $newaccesstext->{$tool} = $reqdisplay{$env{'form.'.$context.'_'.$tool}};
3730: }
1.300 raeburn 3731: } else {
1.383 raeburn 3732: $newaccesstext->{$tool} = &mt("availability set to 'off'");
1.300 raeburn 3733: }
3734: }
3735: }
3736: }
3737: }
3738: return;
3739: }
1.275 raeburn 3740: foreach my $tool (@{$usertools}) {
1.383 raeburn 3741: my ($newval,$limit,$envkey);
1.362 raeburn 3742: $envkey = $context.'.'.$tool;
1.306 raeburn 3743: if ($context eq 'requestcourses') {
3744: $newval = $env{'form.crsreq_'.$tool};
3745: if ($newval eq 'autolimit') {
1.383 raeburn 3746: $limit = $env{'form.crsreq_'.$tool.'_limit'};
3747: $limit =~ s/\D+//g;
3748: $newval .= '='.$limit;
1.306 raeburn 3749: }
1.362 raeburn 3750: } elsif ($context eq 'requestauthor') {
3751: $newval = $env{'form.'.$context};
3752: $envkey = $context;
1.314 raeburn 3753: } else {
1.306 raeburn 3754: $newval = $env{'form.'.$context.'_'.$tool};
3755: }
1.362 raeburn 3756: if ($userenv->{$envkey} ne '') {
1.275 raeburn 3757: $oldaccess->{$tool} = &mt('custom');
1.383 raeburn 3758: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3759: if ($userenv->{$envkey} =~ /^autolimit=(\d*)$/) {
3760: my $currlimit = $1;
3761: if ($currlimit eq '') {
3762: $oldaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3763: } else {
3764: $oldaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$currlimit);
3765: }
3766: } elsif ($userenv->{$envkey}) {
3767: $oldaccesstext->{$tool} = $reqdisplay{$userenv->{$envkey}};
3768: } else {
3769: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
3770: }
1.275 raeburn 3771: } else {
1.383 raeburn 3772: if ($userenv->{$envkey}) {
3773: $oldaccesstext->{$tool} = &mt("availability set to 'on'");
3774: } else {
3775: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
3776: }
1.275 raeburn 3777: }
1.362 raeburn 3778: $changeHash->{$envkey} = $userenv->{$envkey};
1.275 raeburn 3779: if ($env{'form.custom'.$tool} == 1) {
1.362 raeburn 3780: if ($newval ne $userenv->{$envkey}) {
1.306 raeburn 3781: $changed->{$tool} = &tool_admin($tool,$newval,$changeHash,
3782: $context);
1.275 raeburn 3783: if ($changed->{$tool}) {
3784: $newaccess->{$tool} = &mt('custom');
1.383 raeburn 3785: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3786: if ($newval =~ /^autolimit/) {
3787: if ($limit) {
3788: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3789: } else {
3790: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3791: }
3792: } elsif ($newval) {
3793: $newaccesstext->{$tool} = $reqdisplay{$newval};
3794: } else {
3795: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3796: }
1.275 raeburn 3797: } else {
1.383 raeburn 3798: if ($newval) {
3799: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3800: } else {
3801: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3802: }
1.275 raeburn 3803: }
3804: } else {
3805: $newaccess->{$tool} = $oldaccess->{$tool};
1.383 raeburn 3806: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3807: if ($newval =~ /^autolimit/) {
3808: if ($limit) {
3809: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3810: } else {
3811: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3812: }
3813: } elsif ($newval) {
3814: $newaccesstext->{$tool} = $reqdisplay{$newval};
3815: } else {
3816: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3817: }
1.275 raeburn 3818: } else {
1.383 raeburn 3819: if ($userenv->{$context.'.'.$tool}) {
3820: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3821: } else {
3822: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3823: }
1.275 raeburn 3824: }
3825: }
3826: } else {
3827: $newaccess->{$tool} = $oldaccess->{$tool};
3828: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
3829: }
3830: } else {
3831: $changed->{$tool} = &tool_admin($tool,'',$changeHash,$context);
3832: if ($changed->{$tool}) {
3833: $newaccess->{$tool} = &mt('default');
3834: } else {
3835: $newaccess->{$tool} = $oldaccess->{$tool};
1.383 raeburn 3836: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3837: if ($newval =~ /^autolimit/) {
3838: if ($limit) {
3839: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3840: } else {
3841: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3842: }
3843: } elsif ($newval) {
3844: $newaccesstext->{$tool} = $reqdisplay{$newval};
3845: } else {
3846: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3847: }
1.275 raeburn 3848: } else {
1.383 raeburn 3849: if ($userenv->{$context.'.'.$tool}) {
3850: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3851: } else {
3852: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3853: }
1.275 raeburn 3854: }
3855: }
3856: }
3857: } else {
3858: $oldaccess->{$tool} = &mt('default');
3859: if ($env{'form.custom'.$tool} == 1) {
1.306 raeburn 3860: $changed->{$tool} = &tool_admin($tool,$newval,$changeHash,
3861: $context);
1.275 raeburn 3862: if ($changed->{$tool}) {
3863: $newaccess->{$tool} = &mt('custom');
1.383 raeburn 3864: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3865: if ($newval =~ /^autolimit/) {
3866: if ($limit) {
3867: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3868: } else {
3869: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3870: }
3871: } elsif ($newval) {
3872: $newaccesstext->{$tool} = $reqdisplay{$newval};
3873: } else {
3874: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3875: }
1.275 raeburn 3876: } else {
1.383 raeburn 3877: if ($newval) {
3878: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3879: } else {
3880: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3881: }
1.275 raeburn 3882: }
3883: } else {
3884: $newaccess->{$tool} = $oldaccess->{$tool};
3885: }
3886: } else {
3887: $newaccess->{$tool} = $oldaccess->{$tool};
3888: }
3889: }
3890: }
3891: return;
3892: }
3893:
1.220 raeburn 3894: sub update_roles {
1.375 raeburn 3895: my ($r,$context,$showcredits) = @_;
1.4 www 3896: my $now=time;
1.225 raeburn 3897: my @rolechanges;
1.220 raeburn 3898: my %disallowed;
1.73 sakharuk 3899: $r->print('<h3>'.&mt('Modifying Roles').'</h3>');
1.404 raeburn 3900: foreach my $key (keys(%env)) {
1.135 raeburn 3901: next if (! $env{$key});
1.190 raeburn 3902: next if ($key eq 'form.action');
1.27 matthew 3903: # Revoke roles
1.135 raeburn 3904: if ($key=~/^form\.rev/) {
3905: if ($key=~/^form\.rev\:([^\_]+)\_([^\_\.]+)$/) {
1.64 www 3906: # Revoke standard role
1.170 albertel 3907: my ($scope,$role) = ($1,$2);
3908: my $result =
3909: &Apache::lonnet::revokerole($env{'form.ccdomain'},
3910: $env{'form.ccuname'},
1.239 raeburn 3911: $scope,$role,'','',$context);
1.367 golterma 3912: $r->print(&Apache::lonhtmlcommon::confirm_success(
1.369 bisitz 3913: &mt('Revoking [_1] in [_2]',
3914: &Apache::lonnet::plaintext($role),
1.372 raeburn 3915: &Apache::loncommon::show_role_extent($scope,$context,$role)),
1.369 bisitz 3916: $result ne "ok").'<br />');
3917: if ($result ne "ok") {
3918: $r->print(&mt('Error: [_1]',$result).'<br />');
3919: }
1.170 albertel 3920: if ($role eq 'st') {
1.202 raeburn 3921: my $result =
1.198 raeburn 3922: &Apache::lonuserutils::classlist_drop($scope,
3923: $env{'form.ccuname'},$env{'form.ccdomain'},
1.202 raeburn 3924: $now);
1.367 golterma 3925: $r->print(&Apache::lonhtmlcommon::confirm_success($result));
1.53 www 3926: }
1.225 raeburn 3927: if (!grep(/^\Q$role\E$/,@rolechanges)) {
3928: push(@rolechanges,$role);
3929: }
1.196 raeburn 3930: }
1.195 raeburn 3931: if ($key=~m{^form\.rev\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}s) {
1.64 www 3932: # Revoke custom role
1.369 bisitz 3933: my $result = &Apache::lonnet::revokecustomrole(
3934: $env{'form.ccdomain'},$env{'form.ccuname'},$1,$2,$3,$4,'','',$context);
1.367 golterma 3935: $r->print(&Apache::lonhtmlcommon::confirm_success(
1.369 bisitz 3936: &mt('Revoking custom role [_1] by [_2] in [_3]',
1.372 raeburn 3937: $4,$3.':'.$2,&Apache::loncommon::show_role_extent($1,$context,'cr')),
1.369 bisitz 3938: $result ne 'ok').'<br />');
3939: if ($result ne "ok") {
3940: $r->print(&mt('Error: [_1]',$result).'<br />');
3941: }
1.225 raeburn 3942: if (!grep(/^cr$/,@rolechanges)) {
3943: push(@rolechanges,'cr');
3944: }
1.64 www 3945: }
1.135 raeburn 3946: } elsif ($key=~/^form\.del/) {
3947: if ($key=~/^form\.del\:([^\_]+)\_([^\_\.]+)$/) {
1.116 raeburn 3948: # Delete standard role
1.170 albertel 3949: my ($scope,$role) = ($1,$2);
3950: my $result =
3951: &Apache::lonnet::assignrole($env{'form.ccdomain'},
3952: $env{'form.ccuname'},
1.239 raeburn 3953: $scope,$role,$now,0,1,'',
3954: $context);
1.367 golterma 3955: $r->print(&Apache::lonhtmlcommon::confirm_success(
3956: &mt('Deleting [_1] in [_2]',
1.369 bisitz 3957: &Apache::lonnet::plaintext($role),
1.372 raeburn 3958: &Apache::loncommon::show_role_extent($scope,$context,$role)),
1.369 bisitz 3959: $result ne 'ok').'<br />');
3960: if ($result ne "ok") {
3961: $r->print(&mt('Error: [_1]',$result).'<br />');
3962: }
1.367 golterma 3963:
1.170 albertel 3964: if ($role eq 'st') {
1.202 raeburn 3965: my $result =
1.198 raeburn 3966: &Apache::lonuserutils::classlist_drop($scope,
3967: $env{'form.ccuname'},$env{'form.ccdomain'},
1.202 raeburn 3968: $now);
1.369 bisitz 3969: $r->print(&Apache::lonhtmlcommon::confirm_success($result));
1.81 albertel 3970: }
1.225 raeburn 3971: if (!grep(/^\Q$role\E$/,@rolechanges)) {
3972: push(@rolechanges,$role);
3973: }
1.116 raeburn 3974: }
1.139 albertel 3975: if ($key=~m{^form\.del\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
1.116 raeburn 3976: my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
3977: # Delete custom role
1.369 bisitz 3978: my $result =
3979: &Apache::lonnet::assigncustomrole($env{'form.ccdomain'},
3980: $env{'form.ccuname'},$url,$rdom,$rnam,$rolename,$now,
3981: 0,1,$context);
3982: $r->print(&Apache::lonhtmlcommon::confirm_success(&mt('Deleting custom role [_1] by [_2] in [_3]',
1.372 raeburn 3983: $rolename,$rnam.':'.$rdom,&Apache::loncommon::show_role_extent($1,$context,'cr')),
1.369 bisitz 3984: $result ne "ok").'<br />');
3985: if ($result ne "ok") {
3986: $r->print(&mt('Error: [_1]',$result).'<br />');
3987: }
1.367 golterma 3988:
1.225 raeburn 3989: if (!grep(/^cr$/,@rolechanges)) {
3990: push(@rolechanges,'cr');
3991: }
1.116 raeburn 3992: }
1.135 raeburn 3993: } elsif ($key=~/^form\.ren/) {
1.101 albertel 3994: my $udom = $env{'form.ccdomain'};
3995: my $uname = $env{'form.ccuname'};
1.116 raeburn 3996: # Re-enable standard role
1.135 raeburn 3997: if ($key=~/^form\.ren\:([^\_]+)\_([^\_\.]+)$/) {
1.89 raeburn 3998: my $url = $1;
3999: my $role = $2;
4000: my $logmsg;
4001: my $output;
4002: if ($role eq 'st') {
1.141 albertel 4003: if ($url =~ m-^/($match_domain)/($match_courseid)/?(\w*)$-) {
1.374 raeburn 4004: my ($cdom,$cnum,$csec) = ($1,$2,$3);
1.375 raeburn 4005: my $credits;
4006: if ($showcredits) {
4007: my $defaultcredits =
4008: &Apache::lonuserutils::get_defaultcredits($cdom,$cnum);
4009: $credits = &get_user_credits($defaultcredits,$cdom,$cnum);
4010: }
4011: my $result = &Apache::loncommon::commit_studentrole(\$logmsg,$udom,$uname,$url,$role,$now,0,$cdom,$cnum,$csec,$context,$credits);
1.220 raeburn 4012: if (($result =~ /^error/) || ($result eq 'not_in_class') || ($result eq 'unknown_course') || ($result eq 'refused')) {
1.223 raeburn 4013: if ($result eq 'refused' && $logmsg) {
4014: $output = $logmsg;
4015: } else {
1.369 bisitz 4016: $output = &mt('Error: [_1]',$result)."\n";
1.223 raeburn 4017: }
1.89 raeburn 4018: } else {
1.372 raeburn 4019: $output = &Apache::lonhtmlcommon::confirm_success(&mt('Assigning [_1] in [_2] starting [_3]',
4020: &Apache::lonnet::plaintext($role),
4021: &Apache::loncommon::show_role_extent($url,$context,'st'),
4022: &Apache::lonlocal::locallocaltime($now))).'<br />'.$logmsg.'<br />';
1.89 raeburn 4023: }
4024: }
4025: } else {
1.101 albertel 4026: my $result=&Apache::lonnet::assignrole($env{'form.ccdomain'},
1.239 raeburn 4027: $env{'form.ccuname'},$url,$role,0,$now,'','',
4028: $context);
1.367 golterma 4029: $output = &Apache::lonhtmlcommon::confirm_success(&mt('Re-enabling [_1] in [_2]',
1.372 raeburn 4030: &Apache::lonnet::plaintext($role),
4031: &Apache::loncommon::show_role_extent($url,$context,$role)),$result ne "ok").'<br />';
1.369 bisitz 4032: if ($result ne "ok") {
4033: $output .= &mt('Error: [_1]',$result).'<br />';
4034: }
4035: }
1.89 raeburn 4036: $r->print($output);
1.225 raeburn 4037: if (!grep(/^\Q$role\E$/,@rolechanges)) {
4038: push(@rolechanges,$role);
4039: }
1.113 raeburn 4040: }
1.116 raeburn 4041: # Re-enable custom role
1.139 albertel 4042: if ($key=~m{^form\.ren\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
1.116 raeburn 4043: my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
4044: my $result = &Apache::lonnet::assigncustomrole(
4045: $env{'form.ccdomain'}, $env{'form.ccuname'},
1.240 raeburn 4046: $url,$rdom,$rnam,$rolename,0,$now,undef,$context);
1.369 bisitz 4047: $r->print(&Apache::lonhtmlcommon::confirm_success(
4048: &mt('Re-enabling custom role [_1] by [_2] in [_3]',
1.372 raeburn 4049: $rolename,$rnam.':'.$rdom,&Apache::loncommon::show_role_extent($1,$context,'cr')),
1.369 bisitz 4050: $result ne "ok").'<br />');
4051: if ($result ne "ok") {
4052: $r->print(&mt('Error: [_1]',$result).'<br />');
4053: }
1.225 raeburn 4054: if (!grep(/^cr$/,@rolechanges)) {
4055: push(@rolechanges,'cr');
4056: }
1.116 raeburn 4057: }
1.135 raeburn 4058: } elsif ($key=~/^form\.act/) {
1.101 albertel 4059: my $udom = $env{'form.ccdomain'};
4060: my $uname = $env{'form.ccuname'};
1.141 albertel 4061: if ($key=~/^form\.act\_($match_domain)\_($match_courseid)\_cr_cr_($match_domain)_($match_username)_([^\_]+)$/) {
1.65 www 4062: # Activate a custom role
1.83 albertel 4063: my ($one,$two,$three,$four,$five)=($1,$2,$3,$4,$5);
4064: my $url='/'.$one.'/'.$two;
4065: my $full=$one.'_'.$two.'_cr_cr_'.$three.'_'.$four.'_'.$five;
1.65 www 4066:
1.101 albertel 4067: my $start = ( $env{'form.start_'.$full} ?
4068: $env{'form.start_'.$full} :
1.88 raeburn 4069: $now );
1.101 albertel 4070: my $end = ( $env{'form.end_'.$full} ?
4071: $env{'form.end_'.$full} :
1.88 raeburn 4072: 0 );
4073:
4074: # split multiple sections
4075: my %sections = ();
1.101 albertel 4076: my $num_sections = &build_roles($env{'form.sec_'.$full},\%sections,$5);
1.88 raeburn 4077: if ($num_sections == 0) {
1.240 raeburn 4078: $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$url,$three,$four,$five,$start,$end,$context));
1.88 raeburn 4079: } else {
1.114 albertel 4080: my %curr_groups =
1.117 raeburn 4081: &Apache::longroup::coursegroups($one,$two);
1.404 raeburn 4082: foreach my $sec (sort {$a cmp $b} keys(%sections)) {
1.113 raeburn 4083: if (($sec eq 'none') || ($sec eq 'all') ||
4084: exists($curr_groups{$sec})) {
4085: $disallowed{$sec} = $url;
4086: next;
4087: }
4088: my $securl = $url.'/'.$sec;
1.240 raeburn 4089: $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$securl,$three,$four,$five,$start,$end,$context));
1.88 raeburn 4090: }
4091: }
1.225 raeburn 4092: if (!grep(/^cr$/,@rolechanges)) {
4093: push(@rolechanges,'cr');
4094: }
1.142 raeburn 4095: } elsif ($key=~/^form\.act\_($match_domain)\_($match_name)\_([^\_]+)$/) {
1.27 matthew 4096: # Activate roles for sections with 3 id numbers
4097: # set start, end times, and the url for the class
1.83 albertel 4098: my ($one,$two,$three)=($1,$2,$3);
1.101 albertel 4099: my $start = ( $env{'form.start_'.$one.'_'.$two.'_'.$three} ?
4100: $env{'form.start_'.$one.'_'.$two.'_'.$three} :
1.27 matthew 4101: $now );
1.101 albertel 4102: my $end = ( $env{'form.end_'.$one.'_'.$two.'_'.$three} ?
4103: $env{'form.end_'.$one.'_'.$two.'_'.$three} :
1.27 matthew 4104: 0 );
1.83 albertel 4105: my $url='/'.$one.'/'.$two;
1.88 raeburn 4106: my $type = 'three';
4107: # split multiple sections
4108: my %sections = ();
1.101 albertel 4109: my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two.'_'.$three},\%sections,$three);
1.375 raeburn 4110: my $credits;
4111: if ($three eq 'st') {
4112: if ($showcredits) {
4113: my $defaultcredits =
4114: &Apache::lonuserutils::get_defaultcredits($one,$two);
4115: $credits = $env{'form.credits_'.$one.'_'.$two.'_'.$three};
4116: $credits =~ s/[^\d\.]//g;
4117: if ($credits eq $defaultcredits) {
4118: undef($credits);
4119: }
4120: }
4121: }
1.88 raeburn 4122: if ($num_sections == 0) {
1.375 raeburn 4123: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'',$context,$credits));
1.88 raeburn 4124: } else {
1.114 albertel 4125: my %curr_groups =
1.117 raeburn 4126: &Apache::longroup::coursegroups($one,$two);
1.88 raeburn 4127: my $emptysec = 0;
1.404 raeburn 4128: foreach my $sec (sort {$a cmp $b} keys(%sections)) {
1.88 raeburn 4129: $sec =~ s/\W//g;
1.113 raeburn 4130: if ($sec ne '') {
4131: if (($sec eq 'none') || ($sec eq 'all') ||
4132: exists($curr_groups{$sec})) {
4133: $disallowed{$sec} = $url;
4134: next;
4135: }
1.88 raeburn 4136: my $securl = $url.'/'.$sec;
1.375 raeburn 4137: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$three,$start,$end,$one,$two,$sec,$context,$credits));
1.88 raeburn 4138: } else {
4139: $emptysec = 1;
4140: }
4141: }
4142: if ($emptysec) {
1.375 raeburn 4143: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'',$context,$credits));
1.88 raeburn 4144: }
1.225 raeburn 4145: }
4146: if (!grep(/^\Q$three\E$/,@rolechanges)) {
4147: push(@rolechanges,$three);
4148: }
1.135 raeburn 4149: } elsif ($key=~/^form\.act\_([^\_]+)\_([^\_]+)$/) {
1.27 matthew 4150: # Activate roles for sections with two id numbers
4151: # set start, end times, and the url for the class
1.101 albertel 4152: my $start = ( $env{'form.start_'.$1.'_'.$2} ?
4153: $env{'form.start_'.$1.'_'.$2} :
1.27 matthew 4154: $now );
1.101 albertel 4155: my $end = ( $env{'form.end_'.$1.'_'.$2} ?
4156: $env{'form.end_'.$1.'_'.$2} :
1.27 matthew 4157: 0 );
1.225 raeburn 4158: my $one = $1;
4159: my $two = $2;
4160: my $url='/'.$one.'/';
1.88 raeburn 4161: # split multiple sections
4162: my %sections = ();
1.225 raeburn 4163: my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two},\%sections,$two);
1.88 raeburn 4164: if ($num_sections == 0) {
1.240 raeburn 4165: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,'',$context));
1.88 raeburn 4166: } else {
4167: my $emptysec = 0;
1.404 raeburn 4168: foreach my $sec (sort {$a cmp $b} keys(%sections)) {
1.88 raeburn 4169: if ($sec ne '') {
4170: my $securl = $url.'/'.$sec;
1.240 raeburn 4171: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$two,$start,$end,$one,undef,$sec,$context));
1.88 raeburn 4172: } else {
4173: $emptysec = 1;
4174: }
4175: }
4176: if ($emptysec) {
1.240 raeburn 4177: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,'',$context));
1.88 raeburn 4178: }
4179: }
1.225 raeburn 4180: if (!grep(/^\Q$two\E$/,@rolechanges)) {
4181: push(@rolechanges,$two);
4182: }
1.64 www 4183: } else {
1.190 raeburn 4184: $r->print('<p><span class="LC_error">'.&mt('ERROR').': '.&mt('Unknown command').' <tt>'.$key.'</tt></span></p><br />');
1.64 www 4185: }
1.113 raeburn 4186: foreach my $key (sort(keys(%disallowed))) {
1.274 bisitz 4187: $r->print('<p class="LC_warning">');
1.113 raeburn 4188: if (($key eq 'none') || ($key eq 'all')) {
1.274 bisitz 4189: $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 4190: } else {
1.274 bisitz 4191: $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 4192: }
1.274 bisitz 4193: $r->print('</p><p>'
4194: .&mt('Please [_1]go back[_2] and choose a different section name.'
4195: ,'<a href="javascript:history.go(-1)'
4196: ,'</a>')
4197: .'</p><br />'
4198: );
1.113 raeburn 4199: }
4200: }
1.101 albertel 4201: } # End of foreach (keys(%env))
1.75 www 4202: # Flush the course logs so reverse user roles immediately updated
1.349 raeburn 4203: $r->register_cleanup(\&Apache::lonnet::flushcourselogs);
1.225 raeburn 4204: if (@rolechanges == 0) {
1.372 raeburn 4205: $r->print('<p>'.&mt('No roles to modify').'</p>');
1.193 raeburn 4206: }
1.225 raeburn 4207: return @rolechanges;
1.220 raeburn 4208: }
4209:
1.375 raeburn 4210: sub get_user_credits {
4211: my ($uname,$udom,$defaultcredits,$cdom,$cnum) = @_;
4212: if ($cdom eq '' || $cnum eq '') {
4213: return unless ($env{'request.course.id'});
4214: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
4215: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
4216: }
4217: my $credits;
4218: my %currhash =
4219: &Apache::lonnet::get('classlist',[$uname.':'.$udom],$cdom,$cnum);
4220: if (keys(%currhash) > 0) {
4221: my @items = split(/:/,$currhash{$uname.':'.$udom});
4222: my $crdidx = &Apache::loncoursedata::CL_CREDITS() - 3;
4223: $credits = $items[$crdidx];
4224: $credits =~ s/[^\d\.]//g;
4225: }
4226: if ($credits eq $defaultcredits) {
4227: undef($credits);
4228: }
4229: return $credits;
4230: }
4231:
1.220 raeburn 4232: sub enroll_single_student {
1.375 raeburn 4233: my ($r,$uhome,$amode,$genpwd,$now,$newuser,$context,$crstype,
4234: $showcredits,$defaultcredits) = @_;
1.318 raeburn 4235: $r->print('<h3>');
4236: if ($crstype eq 'Community') {
4237: $r->print(&mt('Enrolling Member'));
4238: } else {
4239: $r->print(&mt('Enrolling Student'));
4240: }
4241: $r->print('</h3>');
1.220 raeburn 4242:
4243: # Remove non alphanumeric values from section
4244: $env{'form.sections'}=~s/\W//g;
4245:
1.375 raeburn 4246: my $credits;
4247: if (($showcredits) && ($env{'form.credits'} ne '')) {
4248: $credits = $env{'form.credits'};
4249: $credits =~ s/[^\d\.]//g;
4250: if ($credits ne '') {
4251: if ($credits eq $defaultcredits) {
4252: undef($credits);
4253: }
4254: }
4255: }
4256:
1.220 raeburn 4257: # Clean out any old student roles the user has in this class.
4258: &Apache::lonuserutils::modifystudent($env{'form.ccdomain'},
4259: $env{'form.ccuname'},$env{'request.course.id'},undef,$uhome);
4260: my ($startdate,$enddate) = &Apache::lonuserutils::get_dates_from_form();
4261: my $enroll_result =
4262: &Apache::lonnet::modify_student_enrollment($env{'form.ccdomain'},
4263: $env{'form.ccuname'},$env{'form.cid'},$env{'form.cfirstname'},
4264: $env{'form.cmiddlename'},$env{'form.clastname'},
4265: $env{'form.generation'},$env{'form.sections'},$enddate,
1.375 raeburn 4266: $startdate,'manual',undef,$env{'request.course.id'},'',$context,
4267: $credits);
1.220 raeburn 4268: if ($enroll_result =~ /^ok/) {
1.381 bisitz 4269: $r->print(&mt('[_1] enrolled','<b>'.$env{'form.ccuname'}.':'.$env{'form.ccdomain'}.'</b>'));
1.220 raeburn 4270: if ($env{'form.sections'} ne '') {
4271: $r->print(' '.&mt('in section [_1]',$env{'form.sections'}));
4272: }
4273: my ($showstart,$showend);
4274: if ($startdate <= $now) {
4275: $showstart = &mt('Access starts immediately');
4276: } else {
4277: $showstart = &mt('Access starts: ').&Apache::lonlocal::locallocaltime($startdate);
4278: }
4279: if ($enddate == 0) {
4280: $showend = &mt('ends: no ending date');
4281: } else {
4282: $showend = &mt('ends: ').&Apache::lonlocal::locallocaltime($enddate);
4283: }
4284: $r->print('.<br />'.$showstart.'; '.$showend);
4285: if ($startdate <= $now && !$newuser) {
1.386 bisitz 4286: $r->print('<p class="LC_info">');
1.318 raeburn 4287: if ($crstype eq 'Community') {
1.392 raeburn 4288: $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 4289: } else {
1.392 raeburn 4290: $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 4291: }
4292: $r->print('</p>');
1.220 raeburn 4293: }
4294: } else {
4295: $r->print(&mt('unable to enroll').": ".$enroll_result);
4296: }
4297: return;
1.188 raeburn 4298: }
4299:
1.204 raeburn 4300: sub get_defaultquota_text {
4301: my ($settingstatus) = @_;
4302: my $defquotatext;
4303: if ($settingstatus eq '') {
1.383 raeburn 4304: $defquotatext = &mt('default');
1.204 raeburn 4305: } else {
4306: my ($usertypes,$order) =
4307: &Apache::lonnet::retrieve_inst_usertypes($env{'form.ccdomain'});
4308: if ($usertypes->{$settingstatus} eq '') {
1.383 raeburn 4309: $defquotatext = &mt('default');
1.204 raeburn 4310: } else {
1.383 raeburn 4311: $defquotatext = &mt('default for [_1]',$usertypes->{$settingstatus});
1.204 raeburn 4312: }
4313: }
4314: return $defquotatext;
4315: }
4316:
1.188 raeburn 4317: sub update_result_form {
4318: my ($uhome) = @_;
4319: my $outcome =
1.367 golterma 4320: '<form name="userupdate" method="post" action="">'."\n";
1.160 raeburn 4321: foreach my $item ('srchby','srchin','srchtype','srchterm','srchdomain','ccuname','ccdomain') {
1.188 raeburn 4322: $outcome .= '<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n";
1.160 raeburn 4323: }
1.207 raeburn 4324: if ($env{'form.origname'} ne '') {
4325: $outcome .= '<input type="hidden" name="origname" value="'.$env{'form.origname'}.'" />'."\n";
4326: }
1.160 raeburn 4327: foreach my $item ('sortby','seluname','seludom') {
4328: if (exists($env{'form.'.$item})) {
1.188 raeburn 4329: $outcome .= '<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n";
1.160 raeburn 4330: }
4331: }
1.188 raeburn 4332: if ($uhome eq 'no_host') {
4333: $outcome .= '<input type="hidden" name="forcenewuser" value="1" />'."\n";
4334: }
4335: $outcome .= '<input type="hidden" name="phase" value="" />'."\n".
1.383 raeburn 4336: '<input type="hidden" name="currstate" value="" />'."\n".
4337: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n".
1.188 raeburn 4338: '</form>';
4339: return $outcome;
1.4 www 4340: }
4341:
1.149 raeburn 4342: sub quota_admin {
1.378 raeburn 4343: my ($setquota,$changeHash,$name) = @_;
1.149 raeburn 4344: my $quotachanged;
4345: if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
4346: # Current user has quota modification privileges
1.267 raeburn 4347: if (ref($changeHash) eq 'HASH') {
4348: $quotachanged = 1;
1.378 raeburn 4349: $changeHash->{$name.'quota'} = $setquota;
1.267 raeburn 4350: }
1.149 raeburn 4351: }
4352: return $quotachanged;
4353: }
4354:
1.267 raeburn 4355: sub tool_admin {
1.275 raeburn 4356: my ($tool,$settool,$changeHash,$context) = @_;
4357: my $canchange = 0;
1.279 raeburn 4358: if ($context eq 'requestcourses') {
1.275 raeburn 4359: if (&Apache::lonnet::allowed('ccc',$env{'form.ccdomain'})) {
4360: $canchange = 1;
4361: }
1.300 raeburn 4362: } elsif ($context eq 'reqcrsotherdom') {
4363: if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
4364: $canchange = 1;
4365: }
1.362 raeburn 4366: } elsif ($context eq 'requestauthor') {
4367: if (&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) {
4368: $canchange = 1;
4369: }
1.275 raeburn 4370: } elsif (&Apache::lonnet::allowed('mut',$env{'form.ccdomain'})) {
4371: # Current user has quota modification privileges
4372: $canchange = 1;
4373: }
1.267 raeburn 4374: my $toolchanged;
1.275 raeburn 4375: if ($canchange) {
1.267 raeburn 4376: if (ref($changeHash) eq 'HASH') {
4377: $toolchanged = 1;
1.362 raeburn 4378: if ($tool eq 'requestauthor') {
4379: $changeHash->{$context} = $settool;
4380: } else {
4381: $changeHash->{$context.'.'.$tool} = $settool;
4382: }
1.267 raeburn 4383: }
4384: }
4385: return $toolchanged;
4386: }
4387:
1.88 raeburn 4388: sub build_roles {
1.89 raeburn 4389: my ($sectionstr,$sections,$role) = @_;
1.88 raeburn 4390: my $num_sections = 0;
4391: if ($sectionstr=~ /,/) {
4392: my @secnums = split/,/,$sectionstr;
1.89 raeburn 4393: if ($role eq 'st') {
4394: $secnums[0] =~ s/\W//g;
4395: $$sections{$secnums[0]} = 1;
4396: $num_sections = 1;
4397: } else {
4398: foreach my $sec (@secnums) {
4399: $sec =~ ~s/\W//g;
1.150 banghart 4400: if (!($sec eq "")) {
1.89 raeburn 4401: if (exists($$sections{$sec})) {
4402: $$sections{$sec} ++;
4403: } else {
4404: $$sections{$sec} = 1;
4405: $num_sections ++;
4406: }
1.88 raeburn 4407: }
4408: }
4409: }
4410: } else {
4411: $sectionstr=~s/\W//g;
4412: unless ($sectionstr eq '') {
4413: $$sections{$sectionstr} = 1;
4414: $num_sections ++;
4415: }
4416: }
1.129 albertel 4417:
1.88 raeburn 4418: return $num_sections;
4419: }
4420:
1.58 www 4421: # ========================================================== Custom Role Editor
4422:
4423: sub custom_role_editor {
1.406.2.14 raeburn 4424: my ($r,$context,$brcrum,$prefix,$permission) = @_;
1.324 raeburn 4425: my $action = $env{'form.customroleaction'};
1.406.2.14 raeburn 4426: my ($rolename,$helpitem);
1.324 raeburn 4427: if ($action eq 'new') {
4428: $rolename=$env{'form.newrolename'};
4429: } else {
4430: $rolename=$env{'form.rolename'};
1.59 www 4431: }
4432:
1.324 raeburn 4433: my ($crstype,$context);
4434: if ($env{'request.course.id'}) {
4435: $crstype = &Apache::loncommon::course_type();
4436: $context = 'course';
1.406.2.14 raeburn 4437: $helpitem = 'Course_Editing_Custom_Roles';
1.324 raeburn 4438: } else {
4439: $context = 'domain';
1.406.2.5 raeburn 4440: $crstype = 'course';
1.406.2.14 raeburn 4441: $helpitem = 'Domain_Editing_Custom_Roles';
1.324 raeburn 4442: }
1.351 raeburn 4443:
4444: $rolename=~s/[^A-Za-z0-9]//gs;
4445: if (!$rolename || $env{'form.phase'} eq 'pickrole') {
1.406.2.14 raeburn 4446: &print_username_entry_form($r,$context,undef,undef,undef,$crstype,$brcrum,
4447: $permission);
1.351 raeburn 4448: return;
4449: }
4450:
1.406.2.5 raeburn 4451: my $formname = 'form1';
4452: my %privs=();
4453: my $body_top = '<h2>';
4454: # ------------------------------------------------------- Does this role exist?
1.59 www 4455: my ($rdummy,$roledef)=
4456: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
4457: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1.406.2.5 raeburn 4458: $body_top .= &mt('Existing Role').' "';
1.61 www 4459: # ------------------------------------------------- Get current role privileges
1.406.2.5 raeburn 4460: ($privs{'system'},$privs{'domain'},$privs{'course'})=split(/\_/,$roledef);
4461: if ($privs{'system'} =~ /bre\&S/) {
4462: if ($context eq 'domain') {
4463: $crstype = 'Course';
4464: } elsif ($crstype eq 'Community') {
4465: $privs{'system'} =~ s/bre\&S//;
4466: }
4467: } elsif ($context eq 'domain') {
4468: $crstype = 'Course';
1.324 raeburn 4469: }
1.59 www 4470: } else {
1.406.2.5 raeburn 4471: $body_top .= &mt('New Role').' "';
4472: $roledef='';
1.59 www 4473: }
1.153 banghart 4474: $body_top .= $rolename.'"</h2>';
1.406.2.5 raeburn 4475:
4476: # ------------------------------------------------------- What can be assigned?
4477: my %full=();
4478: my %levels=(
4479: course => {},
4480: domain => {},
4481: system => {},
4482: );
4483: my %levelscurrent=(
4484: course => {},
4485: domain => {},
4486: system => {},
4487: );
4488: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
1.160 raeburn 4489: my ($jsback,$elements) = &crumb_utilities();
1.406.2.5 raeburn 4490: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
4491: my $head_script =
4492: &Apache::lonuserutils::custom_roledefs_js($context,$crstype,$formname,
4493: \%full,\@templateroles,$jsback);
1.351 raeburn 4494: push (@{$brcrum},
1.406.2.5 raeburn 4495: {href => "javascript:backPage(document.$formname,'pickrole','')",
1.351 raeburn 4496: text => "Pick custom role",
4497: faq => 282,bug=>'Instructor Interface',},
1.406.2.5 raeburn 4498: {href => "javascript:backPage(document.$formname,'','')",
1.351 raeburn 4499: text => "Edit custom role",
4500: faq => 282,
4501: bug => 'Instructor Interface',
1.406.2.14 raeburn 4502: help => $helpitem}
1.351 raeburn 4503: );
4504: my $args = { bread_crumbs => $brcrum,
4505: bread_crumbs_component => 'User Management'};
4506: $r->print(&Apache::loncommon::start_page('Custom Role Editor',
4507: $head_script,$args).
4508: $body_top);
1.406.2.5 raeburn 4509: $r->print('<form name="'.$formname.'" method="post" action="">'."\n".
4510: &Apache::lonuserutils::custom_role_header($context,$crstype,
4511: \@templateroles,$prefix));
1.264 bisitz 4512:
1.61 www 4513: $r->print(<<ENDCCF);
4514: <input type="hidden" name="phase" value="set_custom_roles" />
4515: <input type="hidden" name="rolename" value="$rolename" />
4516: ENDCCF
1.406.2.5 raeburn 4517: $r->print(&Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
4518: \%levelscurrent,$prefix));
1.135 raeburn 4519: $r->print(&Apache::loncommon::end_data_table().
1.190 raeburn 4520: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'.
1.160 raeburn 4521: '<input type="hidden" name="startrolename" value="'.$env{'form.rolename'}.
1.406.2.5 raeburn 4522: '" />'."\n".'<input type="hidden" name="currstate" value="" />'."\n".
1.160 raeburn 4523: '<input type="reset" value="'.&mt("Reset").'" />'."\n".
1.351 raeburn 4524: '<input type="submit" value="'.&mt('Save').'" /></form>');
1.61 www 4525: }
1.406.2.5 raeburn 4526:
1.61 www 4527: # ---------------------------------------------------------- Call to definerole
4528: sub set_custom_role {
1.406.2.14 raeburn 4529: my ($r,$context,$brcrum,$prefix,$permission) = @_;
1.101 albertel 4530: my $rolename=$env{'form.rolename'};
1.63 www 4531: $rolename=~s/[^A-Za-z0-9]//gs;
1.150 banghart 4532: if (!$rolename) {
1.406.2.14 raeburn 4533: &custom_role_editor($r,$context,$brcrum,$prefix,$permission);
1.61 www 4534: return;
4535: }
1.160 raeburn 4536: my ($jsback,$elements) = &crumb_utilities();
1.301 bisitz 4537: my $jscript = '<script type="text/javascript">'
4538: .'// <![CDATA['."\n"
4539: .$jsback."\n"
4540: .'// ]]>'."\n"
4541: .'</script>'."\n";
1.406.2.14 raeburn 4542: my $helpitem = 'Course_Editing_Custom_Roles';
4543: if ($context eq 'domain') {
4544: $helpitem = 'Domain_Editing_Custom_Roles';
4545: }
1.352 raeburn 4546: push(@{$brcrum},
4547: {href => "javascript:backPage(document.customresult,'pickrole','')",
4548: text => "Pick custom role",
4549: faq => 282,
4550: bug => 'Instructor Interface',},
4551: {href => "javascript:backPage(document.customresult,'selected_custom_edit','')",
4552: text => "Edit custom role",
4553: faq => 282,
4554: bug => 'Instructor Interface',},
4555: {href => "javascript:backPage(document.customresult,'set_custom_roles','')",
4556: text => "Result",
4557: faq => 282,
4558: bug => 'Instructor Interface',
1.406.2.14 raeburn 4559: help => $helpitem,}
1.352 raeburn 4560: );
4561: my $args = { bread_crumbs => $brcrum,
1.406.2.5 raeburn 4562: bread_crumbs_component => 'User Management'};
1.351 raeburn 4563: $r->print(&Apache::loncommon::start_page('Save Custom Role',$jscript,$args));
1.160 raeburn 4564:
1.393 raeburn 4565: my $newrole;
1.61 www 4566: my ($rdummy,$roledef)=
1.110 albertel 4567: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
4568:
1.61 www 4569: # ------------------------------------------------------- Does this role exist?
1.188 raeburn 4570: $r->print('<h3>');
1.61 www 4571: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1.73 sakharuk 4572: $r->print(&mt('Existing Role').' "');
1.61 www 4573: } else {
1.73 sakharuk 4574: $r->print(&mt('New Role').' "');
1.61 www 4575: $roledef='';
1.393 raeburn 4576: $newrole = 1;
1.61 www 4577: }
1.188 raeburn 4578: $r->print($rolename.'"</h3>');
1.406.2.5 raeburn 4579: # ------------------------------------------------- Assign role and show result
1.61 www 4580:
1.387 bisitz 4581: my $errmsg;
1.406.2.5 raeburn 4582: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$prefix);
4583: # Assign role and return result
4584: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
4585: $newprivs{'c'});
1.387 bisitz 4586: if ($result ne 'ok') {
4587: $errmsg = ': '.$result;
4588: }
4589: my $message =
4590: &Apache::lonhtmlcommon::confirm_success(
4591: &mt('Defining Role').$errmsg, ($result eq 'ok' ? 0 : 1));
1.101 albertel 4592: if ($env{'request.course.id'}) {
4593: my $url='/'.$env{'request.course.id'};
1.63 www 4594: $url=~s/\_/\//g;
1.387 bisitz 4595: $result =
4596: &Apache::lonnet::assigncustomrole(
4597: $env{'user.domain'},$env{'user.name'},
4598: $url,
4599: $env{'user.domain'},$env{'user.name'},
4600: $rolename,undef,undef,undef,$context);
4601: if ($result ne 'ok') {
4602: $errmsg = ': '.$result;
4603: }
4604: $message .=
4605: '<br />'
4606: .&Apache::lonhtmlcommon::confirm_success(
4607: &mt('Assigning Role to Self').$errmsg, ($result eq 'ok' ? 0 : 1));
1.63 www 4608: }
1.380 bisitz 4609: $r->print(
1.387 bisitz 4610: &Apache::loncommon::confirmwrapper($message)
4611: .'<br />'
4612: .&Apache::lonhtmlcommon::actionbox([
4613: '<a href="javascript:backPage(document.customresult,'."'pickrole'".')">'
4614: .&mt('Create or edit another custom role')
4615: .'</a>'])
1.380 bisitz 4616: .'<form name="customresult" method="post" action="">'
1.387 bisitz 4617: .&Apache::lonhtmlcommon::echo_form_input([])
4618: .'</form>'
1.380 bisitz 4619: );
1.58 www 4620: }
4621:
1.2 www 4622: # ================================================================ Main Handler
4623: sub handler {
4624: my $r = shift;
4625: if ($r->header_only) {
1.68 www 4626: &Apache::loncommon::content_type($r,'text/html');
1.2 www 4627: $r->send_http_header;
4628: return OK;
4629: }
1.406.2.14 raeburn 4630: my ($context,$crstype,$cid,$cnum,$cdom,$allhelpitems);
4631:
1.190 raeburn 4632: if ($env{'request.course.id'}) {
4633: $context = 'course';
1.318 raeburn 4634: $crstype = &Apache::loncommon::course_type();
1.190 raeburn 4635: } elsif ($env{'request.role'} =~ /^au\./) {
1.206 raeburn 4636: $context = 'author';
1.190 raeburn 4637: } else {
4638: $context = 'domain';
4639: }
1.375 raeburn 4640:
1.406.2.14 raeburn 4641: my ($permission,$allowed) =
4642: &Apache::lonuserutils::get_permission($context,$crstype);
4643:
4644: if ($allowed) {
4645: my @allhelp;
4646: if ($context eq 'course') {
4647: $cid = $env{'request.course.id'};
4648: $cdom = $env{'course.'.$cid.'.domain'};
4649: $cnum = $env{'course.'.$cid.'.num'};
4650:
4651: if ($permission->{'cusr'}) {
4652: push(@allhelp,'Course_Create_Class_List');
4653: }
4654: if ($permission->{'view'} || $permission->{'cusr'}) {
4655: push(@allhelp,('Course_Change_Privileges','Course_View_Class_List'));
4656: }
4657: if ($permission->{'custom'}) {
4658: push(@allhelp,'Course_Editing_Custom_Roles');
4659: }
4660: if ($permission->{'cusr'}) {
4661: push(@allhelp,('Course_Add_Student','Course_Drop_Student'));
4662: }
4663: unless ($permission->{'cusr_section'}) {
4664: if (&Apache::lonnet::auto_run($cnum,$cdom) && (($permission->{'cusr'}) || ($permission->{'view'}))) {
4665: push(@allhelp,'Course_Automated_Enrollment');
4666: }
4667: if ($permission->{'selfenrolladmin'}) {
4668: push(@allhelp,'Course_Approve_Selfenroll');
4669: }
4670: }
4671: if ($permission->{'grp_manage'}) {
4672: push(@allhelp,'Course_Manage_Group');
4673: }
4674: if ($permission->{'view'} || $permission->{'cusr'}) {
4675: push(@allhelp,'Course_User_Logs');
4676: }
4677: } elsif ($context eq 'author') {
4678: push(@allhelp,('Author_Change_Privileges','Author_Create_Coauthor_List',
4679: 'Author_View_Coauthor_List','Author_User_Logs'));
4680: } else {
4681: if ($permission->{'cusr'}) {
4682: push(@allhelp,'Domain_Change_Privileges');
4683: if ($permission->{'activity'}) {
4684: push(@allhelp,'Domain_User_Access_Logs');
4685: }
4686: push(@allhelp,('Domain_Create_Users','Domain_View_Users_List'));
4687: if ($permission->{'custom'}) {
4688: push(@allhelp,'Domain_Editing_Custom_Roles');
4689: }
4690: push(@allhelp,('Domain_Role_Approvals','Domain_Username_Approvals','Domain_Change_Logs'));
4691: } elsif ($permission->{'view'}) {
4692: push(@allhelp,'Domain_View_Privileges');
4693: if ($permission->{'activity'}) {
4694: push(@allhelp,'Domain_User_Access_Logs');
4695: }
4696: push(@allhelp,('Domain_View_Users_List','Domain_Change_Logs'));
4697: }
4698: }
4699: if (@allhelp) {
4700: $allhelpitems = join(',',@allhelp);
4701: }
4702: }
4703:
1.190 raeburn 4704: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.233 raeburn 4705: ['action','state','callingform','roletype','showrole','bulkaction','popup','phase',
1.391 raeburn 4706: 'username','domain','srchterm','srchdomain','srchin','srchby','srchtype','queue']);
1.190 raeburn 4707: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.351 raeburn 4708: my $args;
4709: my $brcrum = [];
4710: my $bread_crumbs_component = 'User Management';
1.391 raeburn 4711: if (($env{'form.action'} ne 'dateselect') && ($env{'form.action'} ne 'displayuserreq')) {
1.351 raeburn 4712: $brcrum = [{href=>"/adm/createuser",
4713: text=>"User Management",
1.406.2.14 raeburn 4714: help=>$allhelpitems}
1.351 raeburn 4715: ];
1.202 raeburn 4716: }
1.190 raeburn 4717: if (!$allowed) {
1.358 raeburn 4718: if ($context eq 'course') {
4719: $r->internal_redirect('/adm/viewclasslist');
4720: return OK;
4721: }
1.190 raeburn 4722: $env{'user.error.msg'}=
4723: "/adm/createuser:cst:0:0:Cannot create/modify user data ".
4724: "or view user status.";
4725: return HTTP_NOT_ACCEPTABLE;
4726: }
4727:
4728: &Apache::loncommon::content_type($r,'text/html');
4729: $r->send_http_header;
4730:
1.375 raeburn 4731: my $showcredits;
4732: if ((($context eq 'course') && ($crstype eq 'Course')) ||
4733: ($context eq 'domain')) {
4734: my %domdefaults =
4735: &Apache::lonnet::get_domain_defaults($env{'request.role.domain'});
4736: if ($domdefaults{'officialcredits'} || $domdefaults{'unofficialcredits'}) {
4737: $showcredits = 1;
4738: }
4739: }
4740:
1.190 raeburn 4741: # Main switch on form.action and form.state, as appropriate
4742: if (! exists($env{'form.action'})) {
1.351 raeburn 4743: $args = {bread_crumbs => $brcrum,
4744: bread_crumbs_component => $bread_crumbs_component};
4745: $r->print(&header(undef,$args));
1.318 raeburn 4746: $r->print(&print_main_menu($permission,$context,$crstype));
1.190 raeburn 4747: } elsif ($env{'form.action'} eq 'upload' && $permission->{'cusr'}) {
1.406.2.14 raeburn 4748: my $helpitem = 'Course_Create_Class_List';
4749: if ($context eq 'author') {
4750: $helpitem = 'Author_Create_Coauthor_List';
4751: } elsif ($context eq 'domain') {
4752: $helpitem = 'Domain_Create_Users';
4753: }
1.351 raeburn 4754: push(@{$brcrum},
4755: { href => '/adm/createuser?action=upload&state=',
4756: text => 'Upload Users List',
1.406.2.14 raeburn 4757: help => $helpitem,
1.351 raeburn 4758: });
4759: $bread_crumbs_component = 'Upload Users List';
4760: $args = {bread_crumbs => $brcrum,
4761: bread_crumbs_component => $bread_crumbs_component};
4762: $r->print(&header(undef,$args));
1.190 raeburn 4763: $r->print('<form name="studentform" method="post" '.
4764: 'enctype="multipart/form-data" '.
4765: ' action="/adm/createuser">'."\n");
4766: if (! exists($env{'form.state'})) {
4767: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
4768: } elsif ($env{'form.state'} eq 'got_file') {
1.406.2.15 raeburn 4769: my $result =
4770: &Apache::lonuserutils::print_upload_manager_form($r,$context,
4771: $permission,
4772: $crstype,$showcredits);
4773: if ($result eq 'missingdata') {
4774: delete($env{'form.state'});
4775: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
4776: }
1.190 raeburn 4777: } elsif ($env{'form.state'} eq 'enrolling') {
4778: if ($env{'form.datatoken'}) {
1.406.2.15 raeburn 4779: my $result = &Apache::lonuserutils::upfile_drop_add($r,$context,
4780: $permission,
4781: $showcredits);
4782: if ($result eq 'missingdata') {
4783: delete($env{'form.state'});
4784: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
4785: } elsif ($result eq 'invalidhome') {
4786: $env{'form.state'} = 'got_file';
4787: delete($env{'form.lcserver'});
4788: my $result =
4789: &Apache::lonuserutils::print_upload_manager_form($r,$context,$permission,
4790: $crstype,$showcredits);
4791: if ($result eq 'missingdata') {
4792: delete($env{'form.state'});
4793: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
4794: }
4795: }
4796: } else {
4797: delete($env{'form.state'});
4798: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
1.190 raeburn 4799: }
4800: } else {
4801: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
4802: }
1.406.2.15 raeburn 4803: $r->print('</form>');
1.406.2.5 raeburn 4804: } elsif (((($env{'form.action'} eq 'singleuser') || ($env{'form.action'}
4805: eq 'singlestudent')) && ($permission->{'cusr'})) ||
1.406.2.6 raeburn 4806: (($env{'form.action'} eq 'singleuser') && ($permission->{'view'})) ||
1.406.2.5 raeburn 4807: (($env{'form.action'} eq 'accesslogs') && ($permission->{'activity'}))) {
1.190 raeburn 4808: my $phase = $env{'form.phase'};
4809: my @search = ('srchterm','srchby','srchin','srchtype','srchdomain');
1.192 albertel 4810: &Apache::loncreateuser::restore_prev_selections();
4811: my $srch;
4812: foreach my $item (@search) {
4813: $srch->{$item} = $env{'form.'.$item};
4814: }
1.207 raeburn 4815: if (($phase eq 'get_user_info') || ($phase eq 'userpicked') ||
1.406.2.5 raeburn 4816: ($phase eq 'createnewuser') || ($phase eq 'activity')) {
1.207 raeburn 4817: if ($env{'form.phase'} eq 'createnewuser') {
4818: my $response;
4819: if ($env{'form.srchterm'} !~ /^$match_username$/) {
1.366 bisitz 4820: my $response =
4821: '<span class="LC_warning">'
4822: .&mt('You must specify a valid username. Only the following are allowed:'
4823: .' letters numbers - . @')
4824: .'</span>';
1.221 raeburn 4825: $env{'form.phase'} = '';
1.375 raeburn 4826: &print_username_entry_form($r,$context,$response,$srch,undef,
1.406.2.14 raeburn 4827: $crstype,$brcrum,$permission);
1.207 raeburn 4828: } else {
4829: my $ccuname =&LONCAPA::clean_username($srch->{'srchterm'});
4830: my $ccdomain=&LONCAPA::clean_domain($srch->{'srchdomain'});
4831: &print_user_modification_page($r,$ccuname,$ccdomain,
1.221 raeburn 4832: $srch,$response,$context,
1.375 raeburn 4833: $permission,$crstype,$brcrum,
4834: $showcredits);
1.207 raeburn 4835: }
4836: } elsif ($env{'form.phase'} eq 'get_user_info') {
1.190 raeburn 4837: my ($currstate,$response,$forcenewuser,$results) =
1.221 raeburn 4838: &user_search_result($context,$srch);
1.190 raeburn 4839: if ($env{'form.currstate'} eq 'modify') {
4840: $currstate = $env{'form.currstate'};
4841: }
4842: if ($currstate eq 'select') {
4843: &print_user_selection_page($r,$response,$srch,$results,
1.351 raeburn 4844: \@search,$context,undef,$crstype,
4845: $brcrum);
1.406.2.5 raeburn 4846: } elsif (($currstate eq 'modify') || ($env{'form.action'} eq 'accesslogs')) {
4847: my ($ccuname,$ccdomain,$uhome);
1.190 raeburn 4848: if (($srch->{'srchby'} eq 'uname') &&
4849: ($srch->{'srchtype'} eq 'exact')) {
4850: $ccuname = $srch->{'srchterm'};
4851: $ccdomain= $srch->{'srchdomain'};
4852: } else {
4853: my @matchedunames = keys(%{$results});
4854: ($ccuname,$ccdomain) = split(/:/,$matchedunames[0]);
4855: }
4856: $ccuname =&LONCAPA::clean_username($ccuname);
4857: $ccdomain=&LONCAPA::clean_domain($ccdomain);
1.406.2.5 raeburn 4858: if ($env{'form.action'} eq 'accesslogs') {
4859: my $uhome;
4860: if (($ccuname ne '') && ($ccdomain ne '')) {
4861: $uhome = &Apache::lonnet::homeserver($ccuname,$ccdomain);
4862: }
4863: if (($uhome eq '') || ($uhome eq 'no_host')) {
4864: $env{'form.phase'} = '';
4865: undef($forcenewuser);
4866: #if ($response) {
4867: # unless ($response =~ m{\Q<br /><br />\E$}) {
4868: # $response .= '<br /><br />';
4869: # }
4870: #}
4871: &print_username_entry_form($r,$context,$response,$srch,
1.406.2.14 raeburn 4872: $forcenewuser,$crstype,$brcrum,
4873: $permission);
1.406.2.5 raeburn 4874: } else {
4875: &print_useraccesslogs_display($r,$ccuname,$ccdomain,$permission,$brcrum);
4876: }
4877: } else {
4878: if ($env{'form.forcenewuser'}) {
4879: $response = '';
4880: }
4881: &print_user_modification_page($r,$ccuname,$ccdomain,
4882: $srch,$response,$context,
4883: $permission,$crstype,$brcrum);
1.190 raeburn 4884: }
4885: } elsif ($currstate eq 'query') {
1.351 raeburn 4886: &print_user_query_page($r,'createuser',$brcrum);
1.190 raeburn 4887: } else {
1.229 raeburn 4888: $env{'form.phase'} = '';
1.207 raeburn 4889: &print_username_entry_form($r,$context,$response,$srch,
1.406.2.14 raeburn 4890: $forcenewuser,$crstype,$brcrum,
4891: $permission);
1.190 raeburn 4892: }
4893: } elsif ($env{'form.phase'} eq 'userpicked') {
4894: my $ccuname = &LONCAPA::clean_username($env{'form.seluname'});
4895: my $ccdomain = &LONCAPA::clean_domain($env{'form.seludom'});
1.406.2.5 raeburn 4896: if ($env{'form.action'} eq 'accesslogs') {
4897: &print_useraccesslogs_display($r,$ccuname,$ccdomain,$permission,$brcrum);
4898: } else {
4899: &print_user_modification_page($r,$ccuname,$ccdomain,$srch,'',
4900: $context,$permission,$crstype,
4901: $brcrum);
4902: }
4903: } elsif ($env{'form.action'} eq 'accesslogs') {
4904: my $ccuname = &LONCAPA::clean_username($env{'form.accessuname'});
4905: my $ccdomain = &LONCAPA::clean_domain($env{'form.accessudom'});
4906: &print_useraccesslogs_display($r,$ccuname,$ccdomain,$permission,$brcrum);
1.190 raeburn 4907: }
4908: } elsif ($env{'form.phase'} eq 'update_user_data') {
1.406.2.17 raeburn 4909: &update_user_data($r,$context,$crstype,$brcrum,$showcredits,$permission);
1.190 raeburn 4910: } else {
1.351 raeburn 4911: &print_username_entry_form($r,$context,undef,$srch,undef,$crstype,
1.406.2.14 raeburn 4912: $brcrum,$permission);
1.190 raeburn 4913: }
4914: } elsif ($env{'form.action'} eq 'custom' && $permission->{'custom'}) {
1.406.2.5 raeburn 4915: my $prefix;
1.190 raeburn 4916: if ($env{'form.phase'} eq 'set_custom_roles') {
1.406.2.14 raeburn 4917: &set_custom_role($r,$context,$brcrum,$prefix,$permission);
1.190 raeburn 4918: } else {
1.406.2.14 raeburn 4919: &custom_role_editor($r,$context,$brcrum,$prefix,$permission);
1.190 raeburn 4920: }
1.362 raeburn 4921: } elsif (($env{'form.action'} eq 'processauthorreq') &&
4922: ($permission->{'cusr'}) &&
4923: (&Apache::lonnet::allowed('cau',$env{'request.role.domain'}))) {
4924: push(@{$brcrum},
4925: {href => '/adm/createuser?action=processauthorreq',
1.385 bisitz 4926: text => 'Authoring Space requests',
1.362 raeburn 4927: help => 'Domain_Role_Approvals'});
4928: $bread_crumbs_component = 'Authoring requests';
4929: if ($env{'form.state'} eq 'done') {
4930: push(@{$brcrum},
4931: {href => '/adm/createuser?action=authorreqqueue',
4932: text => 'Result',
4933: help => 'Domain_Role_Approvals'});
4934: $bread_crumbs_component = 'Authoring request result';
4935: }
4936: $args = { bread_crumbs => $brcrum,
4937: bread_crumbs_component => $bread_crumbs_component};
1.391 raeburn 4938: my $js = &usernamerequest_javascript();
4939: $r->print(&header(&add_script($js),$args));
1.362 raeburn 4940: if (!exists($env{'form.state'})) {
4941: $r->print(&Apache::loncoursequeueadmin::display_queued_requests('requestauthor',
4942: $env{'request.role.domain'}));
4943: } elsif ($env{'form.state'} eq 'done') {
4944: $r->print('<h3>'.&mt('Authoring request processing').'</h3>'."\n");
4945: $r->print(&Apache::loncoursequeueadmin::update_request_queue('requestauthor',
4946: $env{'request.role.domain'}));
4947: }
1.391 raeburn 4948: } elsif (($env{'form.action'} eq 'processusernamereq') &&
4949: ($permission->{'cusr'}) &&
4950: (&Apache::lonnet::allowed('cau',$env{'request.role.domain'}))) {
4951: push(@{$brcrum},
4952: {href => '/adm/createuser?action=processusernamereq',
4953: text => 'LON-CAPA account requests',
4954: help => 'Domain_Username_Approvals'});
4955: $bread_crumbs_component = 'Account requests';
4956: if ($env{'form.state'} eq 'done') {
4957: push(@{$brcrum},
4958: {href => '/adm/createuser?action=usernamereqqueue',
4959: text => 'Result',
4960: help => 'Domain_Username_Approvals'});
4961: $bread_crumbs_component = 'LON-CAPA account request result';
4962: }
4963: $args = { bread_crumbs => $brcrum,
4964: bread_crumbs_component => $bread_crumbs_component};
4965: my $js = &usernamerequest_javascript();
4966: $r->print(&header(&add_script($js),$args));
4967: if (!exists($env{'form.state'})) {
4968: $r->print(&Apache::loncoursequeueadmin::display_queued_requests('requestusername',
4969: $env{'request.role.domain'}));
4970: } elsif ($env{'form.state'} eq 'done') {
4971: $r->print('<h3>'.&mt('LON-CAPA account request processing').'</h3>'."\n");
4972: $r->print(&Apache::loncoursequeueadmin::update_request_queue('requestusername',
4973: $env{'request.role.domain'}));
4974: }
4975: } elsif (($env{'form.action'} eq 'displayuserreq') &&
4976: ($permission->{'cusr'})) {
4977: my $dom = $env{'form.domain'};
4978: my $uname = $env{'form.username'};
4979: my $warning;
4980: if (($dom =~ /^$match_domain$/) && (&Apache::lonnet::domain($dom) ne '')) {
4981: if (($dom eq $env{'request.role.domain'}) && (&Apache::lonnet::allowed('ccc',$dom))) {
4982: if (($uname =~ /^$match_username$/) && ($env{'form.queue'} eq 'approval')) {
4983: my $uhome = &Apache::lonnet::homeserver($uname,$dom);
4984: if ($uhome eq 'no_host') {
4985: my $queue = $env{'form.queue'};
4986: my $reqkey = &escape($uname).'_'.$queue;
4987: my $namespace = 'usernamequeue';
4988: my $domconfig = &Apache::lonnet::get_domainconfiguser($dom);
4989: my %queued =
4990: &Apache::lonnet::get($namespace,[$reqkey],$dom,$domconfig);
4991: unless ($queued{$reqkey}) {
4992: $warning = &mt('No information was found for this LON-CAPA account request.');
4993: }
4994: } else {
4995: $warning = &mt('A LON-CAPA account already exists for the requested username and domain.');
4996: }
4997: } else {
4998: $warning = &mt('LON-CAPA account request status check is for an invalid username.');
4999: }
5000: } else {
5001: $warning = &mt('You do not have rights to view LON-CAPA account requests in the domain specified.');
5002: }
5003: } else {
5004: $warning = &mt('LON-CAPA account request status check is for an invalid domain.');
5005: }
5006: my $args = { only_body => 1 };
5007: $r->print(&header(undef,$args).
5008: '<h3>'.&mt('LON-CAPA Account Request Details').'</h3>');
5009: if ($warning ne '') {
5010: $r->print('<div class="LC_warning">'.$warning.'</div>');
5011: } else {
5012: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
5013: my $domconfiguser = &Apache::lonnet::get_domainconfiguser($dom);
5014: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
5015: if (ref($domconfig{'usercreation'}) eq 'HASH') {
5016: if (ref($domconfig{'usercreation'}{'cancreate'}) eq 'HASH') {
5017: if (ref($domconfig{'usercreation'}{'cancreate'}{'emailusername'}) eq 'HASH') {
5018: my %info =
5019: &Apache::lonnet::get('nohist_requestedusernames',[$uname],$dom,$domconfiguser);
5020: if (ref($info{$uname}) eq 'HASH') {
1.396 raeburn 5021: my $usertype = $info{$uname}{'inststatus'};
5022: unless ($usertype) {
5023: $usertype = 'default';
5024: }
1.406.2.16 raeburn 5025: my ($showstatus,$showemail,$pickstart);
5026: my $numextras = 0;
5027: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
5028: if ((ref($types) eq 'ARRAY') && (@{$types} > 0)) {
5029: if (ref($usertypes) eq 'HASH') {
5030: if ($usertypes->{$usertype}) {
5031: $showstatus = $usertypes->{$usertype};
5032: } else {
5033: $showstatus = $othertitle;
5034: }
5035: if ($showstatus) {
5036: $numextras ++;
5037: }
5038: }
5039: }
5040: if (($info{$uname}{'email'} ne '') && ($info{$uname}{'email'} ne $uname)) {
5041: $showemail = $info{$uname}{'email'};
5042: $numextras ++;
5043: }
1.396 raeburn 5044: if (ref($domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}) eq 'HASH') {
5045: if ((ref($infofields) eq 'ARRAY') && (ref($infotitles) eq 'HASH')) {
1.406.2.16 raeburn 5046: $pickstart = 1;
1.396 raeburn 5047: $r->print('<div>'.&Apache::lonhtmlcommon::start_pick_box());
1.406.2.16 raeburn 5048: my ($num,$count);
1.396 raeburn 5049: $count = scalar(keys(%{$domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}}));
1.406.2.16 raeburn 5050: $count += $numextras;
1.396 raeburn 5051: foreach my $field (@{$infofields}) {
5052: next unless ($domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}{$field});
5053: next unless ($infotitles->{$field});
5054: $r->print(&Apache::lonhtmlcommon::row_title($infotitles->{$field}).
5055: $info{$uname}{$field});
5056: $num ++;
1.406.2.16 raeburn 5057: unless ($count == $num) {
1.396 raeburn 5058: $r->print(&Apache::lonhtmlcommon::row_closure());
5059: }
5060: }
1.406.2.16 raeburn 5061: }
5062: }
5063: if ($numextras) {
5064: unless ($pickstart) {
5065: $r->print('<div>'.&Apache::lonhtmlcommon::start_pick_box());
5066: $pickstart = 1;
5067: }
5068: if ($showemail) {
5069: my $closure = '';
5070: unless ($showstatus) {
5071: $closure = 1;
1.391 raeburn 5072: }
1.406.2.16 raeburn 5073: $r->print(&Apache::lonhtmlcommon::row_title(&mt('E-mail address')).
5074: $showemail.
5075: &Apache::lonhtmlcommon::row_closure($closure));
5076: }
5077: if ($showstatus) {
5078: $r->print(&Apache::lonhtmlcommon::row_title(&mt('Status type[_1](self-reported)','<br />')).
5079: $showstatus.
5080: &Apache::lonhtmlcommon::row_closure(1));
1.391 raeburn 5081: }
5082: }
1.406.2.16 raeburn 5083: if ($pickstart) {
5084: $r->print(&Apache::lonhtmlcommon::end_pick_box().'</div>');
5085: } else {
5086: $r->print('<div>'.&mt('No information to display for this account request.').'</div>');
5087: }
5088: } else {
5089: $r->print('<div>'.&mt('No information available for this account request.').'</div>');
1.391 raeburn 5090: }
5091: }
5092: }
5093: }
5094: }
1.406.2.16 raeburn 5095: $r->print(&close_popup_form());
1.207 raeburn 5096: } elsif (($env{'form.action'} eq 'listusers') &&
5097: ($permission->{'view'} || $permission->{'cusr'})) {
1.406.2.14 raeburn 5098: my $helpitem = 'Course_View_Class_List';
5099: if ($context eq 'author') {
5100: $helpitem = 'Author_View_Coauthor_List';
5101: } elsif ($context eq 'domain') {
5102: $helpitem = 'Domain_View_Users_List';
5103: }
1.202 raeburn 5104: if ($env{'form.phase'} eq 'bulkchange') {
1.351 raeburn 5105: push(@{$brcrum},
5106: {href => '/adm/createuser?action=listusers',
5107: text => "List Users"},
5108: {href => "/adm/createuser",
5109: text => "Result",
1.406.2.14 raeburn 5110: help => $helpitem});
1.351 raeburn 5111: $bread_crumbs_component = 'Update Users';
5112: $args = {bread_crumbs => $brcrum,
5113: bread_crumbs_component => $bread_crumbs_component};
5114: $r->print(&header(undef,$args));
1.202 raeburn 5115: my $setting = $env{'form.roletype'};
5116: my $choice = $env{'form.bulkaction'};
5117: if ($permission->{'cusr'}) {
1.336 raeburn 5118: &Apache::lonuserutils::update_user_list($r,$context,$setting,$choice,$crstype);
1.221 raeburn 5119: } else {
5120: $r->print(&mt('You are not authorized to make bulk changes to user roles'));
1.223 raeburn 5121: $r->print('<p><a href="/adm/createuser?action=listusers">'.&mt('Display User Lists').'</a>');
1.202 raeburn 5122: }
5123: } else {
1.351 raeburn 5124: push(@{$brcrum},
5125: {href => '/adm/createuser?action=listusers',
5126: text => "List Users",
1.406.2.14 raeburn 5127: help => $helpitem});
1.351 raeburn 5128: $bread_crumbs_component = 'List Users';
5129: $args = {bread_crumbs => $brcrum,
5130: bread_crumbs_component => $bread_crumbs_component};
1.202 raeburn 5131: my ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles);
5132: my $formname = 'studentform';
1.364 raeburn 5133: my $hidecall = "hide_searching();";
1.321 raeburn 5134: if (($context eq 'domain') && (($env{'form.roletype'} eq 'course') ||
5135: ($env{'form.roletype'} eq 'community'))) {
5136: if ($env{'form.roletype'} eq 'course') {
5137: ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles) =
5138: &Apache::lonuserutils::courses_selector($env{'request.role.domain'},
5139: $formname);
5140: } elsif ($env{'form.roletype'} eq 'community') {
5141: $cb_jscript =
5142: &Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
5143: my %elements = (
5144: coursepick => 'radio',
5145: coursetotal => 'text',
5146: courselist => 'text',
5147: );
5148: $jscript = &Apache::lonhtmlcommon::set_form_elements(\%elements);
5149: }
1.364 raeburn 5150: $jscript .= &verify_user_display($context)."\n".
5151: &Apache::loncommon::check_uncheck_jscript();
1.202 raeburn 5152: my $js = &add_script($jscript).$cb_jscript;
5153: my $loadcode =
5154: &Apache::lonuserutils::course_selector_loadcode($formname);
5155: if ($loadcode ne '') {
1.364 raeburn 5156: $args->{add_entries} = {onload => "$loadcode;$hidecall"};
5157: } else {
5158: $args->{add_entries} = {onload => $hidecall};
1.202 raeburn 5159: }
1.351 raeburn 5160: $r->print(&header($js,$args));
1.191 raeburn 5161: } else {
1.364 raeburn 5162: $args->{add_entries} = {onload => $hidecall};
5163: $jscript = &verify_user_display($context).
5164: &Apache::loncommon::check_uncheck_jscript();
5165: $r->print(&header(&add_script($jscript),$args));
1.191 raeburn 5166: }
1.202 raeburn 5167: &Apache::lonuserutils::print_userlist($r,undef,$permission,$context,
1.375 raeburn 5168: $formname,$totcodes,$codetitles,$idlist,$idlist_titles,
5169: $showcredits);
1.191 raeburn 5170: }
1.213 raeburn 5171: } elsif ($env{'form.action'} eq 'drop' && $permission->{'cusr'}) {
1.318 raeburn 5172: my $brtext;
5173: if ($crstype eq 'Community') {
5174: $brtext = 'Drop Members';
5175: } else {
5176: $brtext = 'Drop Students';
5177: }
1.351 raeburn 5178: push(@{$brcrum},
5179: {href => '/adm/createuser?action=drop',
5180: text => $brtext,
5181: help => 'Course_Drop_Student'});
5182: if ($env{'form.state'} eq 'done') {
5183: push(@{$brcrum},
5184: {href=>'/adm/createuser?action=drop',
5185: text=>"Result"});
5186: }
5187: $bread_crumbs_component = $brtext;
5188: $args = {bread_crumbs => $brcrum,
5189: bread_crumbs_component => $bread_crumbs_component};
5190: $r->print(&header(undef,$args));
1.213 raeburn 5191: if (!exists($env{'form.state'})) {
1.318 raeburn 5192: &Apache::lonuserutils::print_drop_menu($r,$context,$permission,$crstype);
1.213 raeburn 5193: } elsif ($env{'form.state'} eq 'done') {
5194: &Apache::lonuserutils::update_user_list($r,$context,undef,
5195: $env{'form.action'});
5196: }
1.202 raeburn 5197: } elsif ($env{'form.action'} eq 'dateselect') {
5198: if ($permission->{'cusr'}) {
1.351 raeburn 5199: $r->print(&header(undef,{'no_nav_bar' => 1}).
1.375 raeburn 5200: &Apache::lonuserutils::date_section_selector($context,$permission,
5201: $crstype,$showcredits));
1.202 raeburn 5202: } else {
1.351 raeburn 5203: $r->print(&header(undef,{'no_nav_bar' => 1}).
5204: '<span class="LC_error">'.&mt('You do not have permission to modify dates or sections for users').'</span>');
1.202 raeburn 5205: }
1.237 raeburn 5206: } elsif ($env{'form.action'} eq 'selfenroll') {
1.398 raeburn 5207: if ($permission->{selfenrolladmin}) {
5208: my %currsettings = (
5209: selfenroll_types => $env{'course.'.$cid.'.internal.selfenroll_types'},
5210: selfenroll_registered => $env{'course.'.$cid.'.internal.selfenroll_registered'},
5211: selfenroll_section => $env{'course.'.$cid.'.internal.selfenroll_section'},
5212: selfenroll_notifylist => $env{'course.'.$cid.'.internal.selfenroll_notifylist'},
5213: selfenroll_approval => $env{'course.'.$cid.'.internal.selfenroll_approval'},
5214: selfenroll_limit => $env{'course.'.$cid.'.internal.selfenroll_limit'},
5215: selfenroll_cap => $env{'course.'.$cid.'.internal.selfenroll_cap'},
5216: selfenroll_start_date => $env{'course.'.$cid.'.internal.selfenroll_start_date'},
5217: selfenroll_end_date => $env{'course.'.$cid.'.internal.selfenroll_end_date'},
5218: selfenroll_start_access => $env{'course.'.$cid.'.internal.selfenroll_start_access'},
5219: selfenroll_end_access => $env{'course.'.$cid.'.internal.selfenroll_end_access'},
5220: default_enrollment_start_date => $env{'course.'.$cid.'.default_enrollment_start_date'},
5221: default_enrollment_end_date => $env{'course.'.$cid.'.default_enrollment_end_date'},
1.400 raeburn 5222: uniquecode => $env{'course.'.$cid.'.internal.uniquecode'},
1.398 raeburn 5223: );
5224: push(@{$brcrum},
5225: {href => '/adm/createuser?action=selfenroll',
5226: text => "Configure Self-enrollment",
5227: help => 'Course_Self_Enrollment'});
5228: if (!exists($env{'form.state'})) {
5229: $args = { bread_crumbs => $brcrum,
5230: bread_crumbs_component => 'Configure Self-enrollment'};
5231: $r->print(&header(undef,$args));
5232: $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n");
5233: &print_selfenroll_menu($r,'course',$cid,$cdom,$cnum,\%currsettings);
5234: } elsif ($env{'form.state'} eq 'done') {
5235: push (@{$brcrum},
5236: {href=>'/adm/createuser?action=selfenroll',
5237: text=>"Result"});
5238: $args = { bread_crumbs => $brcrum,
5239: bread_crumbs_component => 'Self-enrollment result'};
5240: $r->print(&header(undef,$args));
5241: $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n");
1.400 raeburn 5242: &update_selfenroll_config($r,$cid,$cdom,$cnum,$context,$crstype,\%currsettings);
1.398 raeburn 5243: }
5244: } else {
5245: $r->print(&header(undef,{'no_nav_bar' => 1}).
5246: '<span class="LC_error">'.&mt('You do not have permission to configure self-enrollment').'</span>');
1.237 raeburn 5247: }
1.277 raeburn 5248: } elsif ($env{'form.action'} eq 'selfenrollqueue') {
1.406.2.6 raeburn 5249: if ($permission->{selfenrolladmin}) {
1.351 raeburn 5250: push(@{$brcrum},
5251: {href => '/adm/createuser?action=selfenrollqueue',
1.406.2.6 raeburn 5252: text => 'Enrollment requests',
1.406.2.14 raeburn 5253: help => 'Course_Approve_Selfenroll'});
1.406.2.6 raeburn 5254: $bread_crumbs_component = 'Enrollment requests';
5255: if ($env{'form.state'} eq 'done') {
5256: push(@{$brcrum},
5257: {href => '/adm/createuser?action=selfenrollqueue',
5258: text => 'Result',
1.406.2.14 raeburn 5259: help => 'Course_Approve_Selfenroll'});
1.406.2.6 raeburn 5260: $bread_crumbs_component = 'Enrollment result';
5261: }
5262: $args = { bread_crumbs => $brcrum,
5263: bread_crumbs_component => $bread_crumbs_component};
5264: $r->print(&header(undef,$args));
5265: my $coursedesc = $env{'course.'.$cid.'.description'};
5266: if (!exists($env{'form.state'})) {
5267: $r->print('<h3>'.&mt('Pending enrollment requests').'</h3>'."\n");
5268: $r->print(&Apache::loncoursequeueadmin::display_queued_requests($context,
5269: $cdom,$cnum));
5270: } elsif ($env{'form.state'} eq 'done') {
5271: $r->print('<h3>'.&mt('Enrollment request processing').'</h3>'."\n");
5272: $r->print(&Apache::loncoursequeueadmin::update_request_queue($context,
5273: $cdom,$cnum,$coursedesc));
5274: }
5275: } else {
5276: $r->print(&header(undef,{'no_nav_bar' => 1}).
5277: '<span class="LC_error">'.&mt('You do not have permission to manage self-enrollment').'</span>');
1.277 raeburn 5278: }
1.239 raeburn 5279: } elsif ($env{'form.action'} eq 'changelogs') {
1.406.2.6 raeburn 5280: if ($permission->{cusr} || $permission->{view}) {
5281: &print_userchangelogs_display($r,$context,$permission,$brcrum);
5282: } else {
5283: $r->print(&header(undef,{'no_nav_bar' => 1}).
5284: '<span class="LC_error">'.&mt('You do not have permission to view change logs').'</span>');
5285: }
1.406.2.10 raeburn 5286: } elsif ($env{'form.action'} eq 'helpdesk') {
5287: if (($permission->{'owner'}) || ($permission->{'co-owner'})) {
5288: if ($env{'form.state'} eq 'process') {
5289: if ($permission->{'owner'}) {
5290: &update_helpdeskaccess($r,$permission,$brcrum);
5291: } else {
5292: &print_helpdeskaccess_display($r,$permission,$brcrum);
5293: }
5294: } else {
5295: &print_helpdeskaccess_display($r,$permission,$brcrum);
5296: }
5297: } else {
5298: $r->print(&header(undef,{'no_nav_bar' => 1}).
5299: '<span class="LC_error">'.&mt('You do not have permission to view helpdesk access').'</span>');
5300: }
1.190 raeburn 5301: } else {
1.351 raeburn 5302: $bread_crumbs_component = 'User Management';
5303: $args = { bread_crumbs => $brcrum,
5304: bread_crumbs_component => $bread_crumbs_component};
5305: $r->print(&header(undef,$args));
1.318 raeburn 5306: $r->print(&print_main_menu($permission,$context,$crstype));
1.190 raeburn 5307: }
1.351 raeburn 5308: $r->print(&Apache::loncommon::end_page());
1.190 raeburn 5309: return OK;
5310: }
5311:
5312: sub header {
1.351 raeburn 5313: my ($jscript,$args) = @_;
1.190 raeburn 5314: my $start_page;
1.351 raeburn 5315: if (ref($args) eq 'HASH') {
5316: $start_page=&Apache::loncommon::start_page('User Management',$jscript,$args);
1.190 raeburn 5317: } else {
1.351 raeburn 5318: $start_page=&Apache::loncommon::start_page('User Management',$jscript);
1.190 raeburn 5319: }
5320: return $start_page;
5321: }
1.2 www 5322:
1.191 raeburn 5323: sub add_script {
5324: my ($js) = @_;
1.301 bisitz 5325: return '<script type="text/javascript">'."\n"
5326: .'// <![CDATA['."\n"
5327: .$js."\n"
5328: .'// ]]>'."\n"
5329: .'</script>'."\n";
1.191 raeburn 5330: }
5331:
1.391 raeburn 5332: sub usernamerequest_javascript {
5333: my $js = <<ENDJS;
5334:
5335: function openusernamereqdisplay(dom,uname,queue) {
5336: var url = '/adm/createuser?action=displayuserreq';
5337: url += '&domain='+dom+'&username='+uname+'&queue='+queue;
5338: var title = 'Account_Request_Browser';
5339: var options = 'scrollbars=1,resizable=1,menubar=0';
5340: options += ',width=700,height=600';
5341: var stdeditbrowser = open(url,title,options,'1');
5342: stdeditbrowser.focus();
5343: return;
5344: }
5345:
5346: ENDJS
5347: }
5348:
5349: sub close_popup_form {
5350: my $close= &mt('Close Window');
5351: return << "END";
5352: <p><form name="displayreq" action="" method="post">
5353: <input type="button" name="closeme" value="$close" onclick="javascript:self.close();" />
5354: </form></p>
5355: END
5356: }
5357:
1.202 raeburn 5358: sub verify_user_display {
1.364 raeburn 5359: my ($context) = @_;
1.374 raeburn 5360: my %lt = &Apache::lonlocal::texthash (
5361: course => 'course(s): description, section(s), status',
5362: community => 'community(s): description, section(s), status',
5363: author => 'author',
5364: );
1.364 raeburn 5365: my $photos;
5366: if (($context eq 'course') && $env{'request.course.id'}) {
5367: $photos = $env{'course.'.$env{'request.course.id'}.'.internal.showphoto'};
5368: }
1.202 raeburn 5369: my $output = <<"END";
5370:
1.364 raeburn 5371: function hide_searching() {
5372: if (document.getElementById('searching')) {
5373: document.getElementById('searching').style.display = 'none';
5374: }
5375: return;
5376: }
5377:
1.202 raeburn 5378: function display_update() {
5379: document.studentform.action.value = 'listusers';
5380: document.studentform.phase.value = 'display';
5381: document.studentform.submit();
5382: }
5383:
1.364 raeburn 5384: function updateCols(caller) {
5385: var context = '$context';
5386: var photos = '$photos';
5387: if (caller == 'Status') {
1.374 raeburn 5388: if ((context == 'domain') &&
5389: ((document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'course') ||
5390: (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community'))) {
1.364 raeburn 5391: document.getElementById('showcolstatus').checked = false;
5392: document.getElementById('showcolstatus').disabled = 'disabled';
5393: document.getElementById('showcolstart').checked = false;
5394: document.getElementById('showcolend').checked = false;
1.374 raeburn 5395: } else {
5396: if (document.studentform.Status.options[document.studentform.Status.selectedIndex].value == 'Any') {
5397: document.getElementById('showcolstatus').checked = true;
5398: document.getElementById('showcolstatus').disabled = '';
5399: document.getElementById('showcolstart').checked = true;
5400: document.getElementById('showcolend').checked = true;
5401: } else {
5402: document.getElementById('showcolstatus').checked = false;
5403: document.getElementById('showcolstatus').disabled = 'disabled';
5404: document.getElementById('showcolstart').checked = false;
5405: document.getElementById('showcolend').checked = false;
5406: }
1.364 raeburn 5407: }
5408: }
5409: if (caller == 'output') {
5410: if (photos == 1) {
5411: if (document.getElementById('showcolphoto')) {
5412: var photoitem = document.getElementById('showcolphoto');
5413: if (document.studentform.output.options[document.studentform.output.selectedIndex].value == 'html') {
5414: photoitem.checked = true;
5415: photoitem.disabled = '';
5416: } else {
5417: photoitem.checked = false;
5418: photoitem.disabled = 'disabled';
5419: }
5420: }
5421: }
5422: }
5423: if (caller == 'showrole') {
1.371 raeburn 5424: if ((document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'Any') ||
5425: (document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'cr')) {
1.364 raeburn 5426: document.getElementById('showcolrole').checked = true;
5427: document.getElementById('showcolrole').disabled = '';
5428: } else {
5429: document.getElementById('showcolrole').checked = false;
5430: document.getElementById('showcolrole').disabled = 'disabled';
5431: }
1.374 raeburn 5432: if (context == 'domain') {
1.382 raeburn 5433: var quotausageshow = 0;
1.374 raeburn 5434: if ((document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'course') ||
5435: (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community')) {
5436: document.getElementById('showcolstatus').checked = false;
5437: document.getElementById('showcolstatus').disabled = 'disabled';
5438: document.getElementById('showcolstart').checked = false;
5439: document.getElementById('showcolend').checked = false;
5440: } else {
5441: if (document.studentform.Status.options[document.studentform.Status.selectedIndex].value == 'Any') {
5442: document.getElementById('showcolstatus').checked = true;
5443: document.getElementById('showcolstatus').disabled = '';
5444: document.getElementById('showcolstart').checked = true;
5445: document.getElementById('showcolend').checked = true;
5446: }
5447: }
5448: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'domain') {
5449: document.getElementById('showcolextent').disabled = 'disabled';
5450: document.getElementById('showcolextent').checked = 'false';
5451: document.getElementById('showextent').style.display='none';
5452: document.getElementById('showcoltextextent').innerHTML = '';
1.382 raeburn 5453: if ((document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'au') ||
5454: (document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'Any')) {
5455: if (document.getElementById('showcolauthorusage')) {
5456: document.getElementById('showcolauthorusage').disabled = '';
5457: }
5458: if (document.getElementById('showcolauthorquota')) {
5459: document.getElementById('showcolauthorquota').disabled = '';
5460: }
5461: quotausageshow = 1;
5462: }
1.374 raeburn 5463: } else {
5464: document.getElementById('showextent').style.display='block';
5465: document.getElementById('showextent').style.textAlign='left';
5466: document.getElementById('showextent').style.textFace='normal';
5467: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'author') {
5468: document.getElementById('showcolextent').disabled = '';
5469: document.getElementById('showcolextent').checked = 'true';
5470: document.getElementById('showcoltextextent').innerHTML="$lt{'author'}";
5471: } else {
5472: document.getElementById('showcolextent').disabled = '';
5473: document.getElementById('showcolextent').checked = 'true';
5474: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community') {
5475: document.getElementById('showcoltextextent').innerHTML="$lt{'community'}";
5476: } else {
5477: document.getElementById('showcoltextextent').innerHTML="$lt{'course'}";
5478: }
5479: }
5480: }
1.382 raeburn 5481: if (quotausageshow == 0) {
5482: if (document.getElementById('showcolauthorusage')) {
5483: document.getElementById('showcolauthorusage').checked = false;
5484: document.getElementById('showcolauthorusage').disabled = 'disabled';
5485: }
5486: if (document.getElementById('showcolauthorquota')) {
5487: document.getElementById('showcolauthorquota').checked = false;
5488: document.getElementById('showcolauthorquota').disabled = 'disabled';
5489: }
5490: }
1.374 raeburn 5491: }
1.364 raeburn 5492: }
5493: return;
5494: }
5495:
1.202 raeburn 5496: END
5497: return $output;
5498:
5499: }
5500:
1.190 raeburn 5501: ###############################################################
5502: ###############################################################
5503: # Menu Phase One
5504: sub print_main_menu {
1.318 raeburn 5505: my ($permission,$context,$crstype) = @_;
5506: my $linkcontext = $context;
5507: my $stuterm = lc(&Apache::lonnet::plaintext('st',$crstype));
5508: if (($context eq 'course') && ($crstype eq 'Community')) {
5509: $linkcontext = lc($crstype);
5510: $stuterm = 'Members';
5511: }
1.208 raeburn 5512: my %links = (
1.298 droeschl 5513: domain => {
5514: upload => 'Upload a File of Users',
5515: singleuser => 'Add/Modify a User',
5516: listusers => 'Manage Users',
5517: },
5518: author => {
5519: upload => 'Upload a File of Co-authors',
5520: singleuser => 'Add/Modify a Co-author',
5521: listusers => 'Manage Co-authors',
5522: },
5523: course => {
5524: upload => 'Upload a File of Course Users',
5525: singleuser => 'Add/Modify a Course User',
1.354 www 5526: listusers => 'List and Modify Multiple Course Users',
1.298 droeschl 5527: },
1.318 raeburn 5528: community => {
5529: upload => 'Upload a File of Community Users',
5530: singleuser => 'Add/Modify a Community User',
1.354 www 5531: listusers => 'List and Modify Multiple Community Users',
1.318 raeburn 5532: },
5533: );
5534: my %linktitles = (
5535: domain => {
5536: singleuser => 'Add a user to the domain, and/or a course or community in the domain.',
5537: listusers => 'Show and manage users in this domain.',
5538: },
5539: author => {
5540: singleuser => 'Add a user with a co- or assistant author role.',
5541: listusers => 'Show and manage co- or assistant authors.',
5542: },
5543: course => {
5544: singleuser => 'Add a user with a certain role to this course.',
5545: listusers => 'Show and manage users in this course.',
5546: },
5547: community => {
5548: singleuser => 'Add a user with a certain role to this community.',
5549: listusers => 'Show and manage users in this community.',
5550: },
1.298 droeschl 5551: );
1.406.2.6 raeburn 5552: if ($linkcontext eq 'domain') {
5553: unless ($permission->{'cusr'}) {
5554: $links{'domain'}{'singleuser'} = 'View a User';
5555: $linktitles{'domain'}{'singleuser'} = 'View information about a user in the domain';
5556: }
5557: } elsif ($linkcontext eq 'course') {
5558: unless ($permission->{'cusr'}) {
5559: $links{'course'}{'singleuser'} = 'View a Course User';
5560: $linktitles{'course'}{'singleuser'} = 'View information about a user in this course';
5561: $links{'course'}{'listusers'} = 'List Course Users';
5562: $linktitles{'course'}{'listusers'} = 'Show information about users in this course';
5563: }
5564: } elsif ($linkcontext eq 'community') {
5565: unless ($permission->{'cusr'}) {
5566: $links{'community'}{'singleuser'} = 'View a Community User';
5567: $linktitles{'community'}{'singleuser'} = 'View information about a user in this community';
5568: $links{'community'}{'listusers'} = 'List Community Users';
5569: $linktitles{'community'}{'listusers'} = 'Show information about users in this community';
5570: }
5571: }
1.298 droeschl 5572: my @menu = ( {categorytitle => 'Single Users',
5573: items =>
5574: [
5575: {
1.318 raeburn 5576: linktext => $links{$linkcontext}{'singleuser'},
1.298 droeschl 5577: icon => 'edit-redo.png',
5578: #help => 'Course_Change_Privileges',
5579: url => '/adm/createuser?action=singleuser',
1.406.2.6 raeburn 5580: permission => ($permission->{'view'} || $permission->{'cusr'}),
1.318 raeburn 5581: linktitle => $linktitles{$linkcontext}{'singleuser'},
1.298 droeschl 5582: },
5583: ]},
5584:
5585: {categorytitle => 'Multiple Users',
5586: items =>
5587: [
5588: {
1.318 raeburn 5589: linktext => $links{$linkcontext}{'upload'},
1.340 wenzelju 5590: icon => 'uplusr.png',
1.298 droeschl 5591: #help => 'Course_Create_Class_List',
5592: url => '/adm/createuser?action=upload',
5593: permission => $permission->{'cusr'},
5594: linktitle => 'Upload a CSV or a text file containing users.',
5595: },
5596: {
1.318 raeburn 5597: linktext => $links{$linkcontext}{'listusers'},
1.340 wenzelju 5598: icon => 'mngcu.png',
1.298 droeschl 5599: #help => 'Course_View_Class_List',
5600: url => '/adm/createuser?action=listusers',
5601: permission => ($permission->{'view'} || $permission->{'cusr'}),
1.318 raeburn 5602: linktitle => $linktitles{$linkcontext}{'listusers'},
1.298 droeschl 5603: },
5604:
5605: ]},
5606:
5607: {categorytitle => 'Administration',
5608: items => [ ]},
5609: );
1.406.2.5 raeburn 5610:
1.265 mielkec 5611: if ($context eq 'domain'){
1.406.2.5 raeburn 5612: push(@{ $menu[0]->{items} }, # Single Users
5613: {
5614: linktext => 'User Access Log',
5615: icon => 'document-properties.png',
1.406.2.8 raeburn 5616: #help => 'Domain_User_Access_Logs',
1.406.2.5 raeburn 5617: url => '/adm/createuser?action=accesslogs',
5618: permission => $permission->{'activity'},
5619: linktitle => 'View user access log.',
5620: }
5621: );
1.298 droeschl 5622:
5623: push(@{ $menu[2]->{items} }, #Category: Administration
5624: {
5625: linktext => 'Custom Roles',
5626: icon => 'emblem-photos.png',
5627: #help => 'Course_Editing_Custom_Roles',
5628: url => '/adm/createuser?action=custom',
5629: permission => $permission->{'custom'},
5630: linktitle => 'Configure a custom role.',
5631: },
1.362 raeburn 5632: {
5633: linktext => 'Authoring Space Requests',
5634: icon => 'selfenrl-queue.png',
5635: #help => 'Domain_Role_Approvals',
5636: url => '/adm/createuser?action=processauthorreq',
5637: permission => $permission->{'cusr'},
5638: linktitle => 'Approve or reject author role requests',
5639: },
1.363 raeburn 5640: {
1.391 raeburn 5641: linktext => 'LON-CAPA Account Requests',
5642: icon => 'list-add.png',
5643: #help => 'Domain_Username_Approvals',
5644: url => '/adm/createuser?action=processusernamereq',
5645: permission => $permission->{'cusr'},
5646: linktitle => 'Approve or reject LON-CAPA account requests',
5647: },
5648: {
1.363 raeburn 5649: linktext => 'Change Log',
5650: icon => 'document-properties.png',
5651: #help => 'Course_User_Logs',
5652: url => '/adm/createuser?action=changelogs',
1.406.2.6 raeburn 5653: permission => ($permission->{'cusr'} || $permission->{'view'}),
1.363 raeburn 5654: linktitle => 'View change log.',
5655: },
1.298 droeschl 5656: );
5657:
1.265 mielkec 5658: }elsif ($context eq 'course'){
1.298 droeschl 5659: my ($cnum,$cdom) = &Apache::lonuserutils::get_course_identity();
1.318 raeburn 5660:
5661: my %linktext = (
5662: 'Course' => {
5663: single => 'Add/Modify a Student',
5664: drop => 'Drop Students',
5665: groups => 'Course Groups',
5666: },
5667: 'Community' => {
5668: single => 'Add/Modify a Member',
5669: drop => 'Drop Members',
5670: groups => 'Community Groups',
5671: },
5672: );
5673:
5674: my %linktitle = (
5675: 'Course' => {
5676: single => 'Add a user with the role of student to this course',
5677: drop => 'Remove a student from this course.',
5678: groups => 'Manage course groups',
5679: },
5680: 'Community' => {
5681: single => 'Add a user with the role of member to this community',
5682: drop => 'Remove a member from this community.',
5683: groups => 'Manage community groups',
5684: },
5685: );
5686:
1.298 droeschl 5687: push(@{ $menu[0]->{items} }, #Category: Single Users
5688: {
1.318 raeburn 5689: linktext => $linktext{$crstype}{'single'},
1.298 droeschl 5690: #help => 'Course_Add_Student',
5691: icon => 'list-add.png',
5692: url => '/adm/createuser?action=singlestudent',
5693: permission => $permission->{'cusr'},
1.318 raeburn 5694: linktitle => $linktitle{$crstype}{'single'},
1.298 droeschl 5695: },
5696: );
5697:
5698: push(@{ $menu[1]->{items} }, #Category: Multiple Users
5699: {
1.318 raeburn 5700: linktext => $linktext{$crstype}{'drop'},
1.298 droeschl 5701: icon => 'edit-undo.png',
5702: #help => 'Course_Drop_Student',
5703: url => '/adm/createuser?action=drop',
5704: permission => $permission->{'cusr'},
1.318 raeburn 5705: linktitle => $linktitle{$crstype}{'drop'},
1.298 droeschl 5706: },
5707: );
5708: push(@{ $menu[2]->{items} }, #Category: Administration
1.406.2.11 raeburn 5709: {
5710: linktext => 'Helpdesk Access',
5711: icon => 'helpdesk-access.png',
5712: #help => 'Course_Helpdesk_Access',
5713: url => '/adm/createuser?action=helpdesk',
5714: permission => ($permission->{'owner'} || $permission->{'co-owner'}),
5715: linktitle => 'Helpdesk access options',
5716: },
5717: {
1.298 droeschl 5718: linktext => 'Custom Roles',
5719: icon => 'emblem-photos.png',
5720: #help => 'Course_Editing_Custom_Roles',
5721: url => '/adm/createuser?action=custom',
5722: permission => $permission->{'custom'},
5723: linktitle => 'Configure a custom role.',
5724: },
5725: {
1.318 raeburn 5726: linktext => $linktext{$crstype}{'groups'},
1.333 wenzelju 5727: icon => 'grps.png',
1.298 droeschl 5728: #help => 'Course_Manage_Group',
5729: url => '/adm/coursegroups?refpage=cusr',
5730: permission => $permission->{'grp_manage'},
1.318 raeburn 5731: linktitle => $linktitle{$crstype}{'groups'},
1.298 droeschl 5732: },
5733: {
1.328 wenzelju 5734: linktext => 'Change Log',
1.298 droeschl 5735: icon => 'document-properties.png',
5736: #help => 'Course_User_Logs',
5737: url => '/adm/createuser?action=changelogs',
1.406.2.6 raeburn 5738: permission => ($permission->{'view'} || $permission->{'cusr'}),
1.298 droeschl 5739: linktitle => 'View change log.',
5740: },
5741: );
1.277 raeburn 5742: if ($env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_approval'}) {
1.298 droeschl 5743: push(@{ $menu[2]->{items} },
1.398 raeburn 5744: {
1.298 droeschl 5745: linktext => 'Enrollment Requests',
5746: icon => 'selfenrl-queue.png',
5747: #help => 'Course_Approve_Selfenroll',
5748: url => '/adm/createuser?action=selfenrollqueue',
1.398 raeburn 5749: permission => $permission->{'selfenrolladmin'},
1.298 droeschl 5750: linktitle =>'Approve or reject enrollment requests.',
5751: },
5752: );
1.277 raeburn 5753: }
1.298 droeschl 5754:
1.265 mielkec 5755: if (!exists($permission->{'cusr_section'})){
1.320 raeburn 5756: if ($crstype ne 'Community') {
5757: push(@{ $menu[2]->{items} },
5758: {
5759: linktext => 'Automated Enrollment',
5760: icon => 'roles.png',
5761: #help => 'Course_Automated_Enrollment',
5762: permission => (&Apache::lonnet::auto_run($cnum,$cdom)
1.406.2.6 raeburn 5763: && (($permission->{'cusr'}) ||
5764: ($permission->{'view'}))),
1.320 raeburn 5765: url => '/adm/populate',
5766: linktitle => 'Automated enrollment manager.',
5767: }
5768: );
5769: }
5770: push(@{ $menu[2]->{items} },
1.298 droeschl 5771: {
5772: linktext => 'User Self-Enrollment',
1.342 wenzelju 5773: icon => 'self_enroll.png',
1.298 droeschl 5774: #help => 'Course_Self_Enrollment',
5775: url => '/adm/createuser?action=selfenroll',
1.398 raeburn 5776: permission => $permission->{'selfenrolladmin'},
1.317 bisitz 5777: linktitle => 'Configure user self-enrollment.',
1.298 droeschl 5778: },
5779: );
5780: }
1.363 raeburn 5781: } elsif ($context eq 'author') {
1.370 raeburn 5782: push(@{ $menu[2]->{items} }, #Category: Administration
1.363 raeburn 5783: {
5784: linktext => 'Change Log',
5785: icon => 'document-properties.png',
5786: #help => 'Course_User_Logs',
5787: url => '/adm/createuser?action=changelogs',
5788: permission => $permission->{'cusr'},
5789: linktitle => 'View change log.',
5790: },
1.370 raeburn 5791: );
1.363 raeburn 5792: }
5793: return Apache::lonhtmlcommon::generate_menu(@menu);
1.250 raeburn 5794: # { text => 'View Log-in History',
5795: # help => 'Course_User_Logins',
5796: # action => 'logins',
5797: # permission => $permission->{'cusr'},
5798: # });
1.190 raeburn 5799: }
5800:
1.189 albertel 5801: sub restore_prev_selections {
5802: my %saveable_parameters = ('srchby' => 'scalar',
5803: 'srchin' => 'scalar',
5804: 'srchtype' => 'scalar',
5805: );
5806: &Apache::loncommon::store_settings('user','user_picker',
5807: \%saveable_parameters);
5808: &Apache::loncommon::restore_settings('user','user_picker',
5809: \%saveable_parameters);
5810: }
5811:
1.237 raeburn 5812: sub print_selfenroll_menu {
1.406.2.6 raeburn 5813: my ($r,$context,$cid,$cdom,$cnum,$currsettings,$additional,$readonly) = @_;
1.322 raeburn 5814: my $crstype = &Apache::loncommon::course_type();
1.398 raeburn 5815: my $formname = 'selfenroll';
1.237 raeburn 5816: my $nolink = 1;
1.398 raeburn 5817: my ($row,$lt) = &Apache::lonuserutils::get_selfenroll_titles();
1.237 raeburn 5818: my $groupslist = &Apache::lonuserutils::get_groupslist();
5819: my $setsec_js =
5820: &Apache::lonuserutils::setsections_javascript($formname,$groupslist);
1.249 raeburn 5821: my %alerts = &Apache::lonlocal::texthash(
5822: acto => 'Activation of self-enrollment was selected for the following domain(s)',
5823: butn => 'but no user types have been checked.',
5824: wilf => "Please uncheck 'activate' or check at least one type.",
5825: );
1.406.2.6 raeburn 5826: my $disabled;
5827: if ($readonly) {
5828: $disabled = ' disabled="disabled"';
5829: }
1.405 damieng 5830: &js_escape(\%alerts);
1.249 raeburn 5831: my $selfenroll_js = <<"ENDSCRIPT";
5832: function update_types(caller,num) {
5833: var delidx = getIndexByName('selfenroll_delete');
5834: var actidx = getIndexByName('selfenroll_activate');
5835: if (caller == 'selfenroll_all') {
5836: var selall;
5837: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
5838: if (document.$formname.selfenroll_all[i].checked) {
5839: selall = document.$formname.selfenroll_all[i].value;
5840: }
5841: }
5842: if (selall == 1) {
5843: if (delidx != -1) {
5844: if (document.$formname.selfenroll_delete.length) {
5845: for (var j=0; j<document.$formname.selfenroll_delete.length; j++) {
5846: document.$formname.selfenroll_delete[j].checked = true;
5847: }
5848: } else {
5849: document.$formname.elements[delidx].checked = true;
5850: }
5851: }
5852: if (actidx != -1) {
5853: if (document.$formname.selfenroll_activate.length) {
5854: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
5855: document.$formname.selfenroll_activate[j].checked = false;
5856: }
5857: } else {
5858: document.$formname.elements[actidx].checked = false;
5859: }
5860: }
5861: document.$formname.selfenroll_newdom.selectedIndex = 0;
5862: }
5863: }
5864: if (caller == 'selfenroll_activate') {
5865: if (document.$formname.selfenroll_activate.length) {
5866: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
5867: if (document.$formname.selfenroll_activate[j].value == num) {
5868: if (document.$formname.selfenroll_activate[j].checked) {
5869: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
5870: if (document.$formname.selfenroll_all[i].value == '1') {
5871: document.$formname.selfenroll_all[i].checked = false;
5872: }
5873: if (document.$formname.selfenroll_all[i].value == '0') {
5874: document.$formname.selfenroll_all[i].checked = true;
5875: }
5876: }
5877: }
5878: }
5879: }
5880: } else {
5881: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
5882: if (document.$formname.selfenroll_all[i].value == '1') {
5883: document.$formname.selfenroll_all[i].checked = false;
5884: }
5885: if (document.$formname.selfenroll_all[i].value == '0') {
5886: document.$formname.selfenroll_all[i].checked = true;
5887: }
5888: }
5889: }
5890: }
5891: if (caller == 'selfenroll_delete') {
5892: if (document.$formname.selfenroll_delete.length) {
5893: for (var j=0; j<document.$formname.selfenroll_delete.length; j++) {
5894: if (document.$formname.selfenroll_delete[j].value == num) {
5895: if (document.$formname.selfenroll_delete[j].checked) {
5896: var delindex = getIndexByName('selfenroll_types_'+num);
5897: if (delindex != -1) {
5898: if (document.$formname.elements[delindex].length) {
5899: for (var k=0; k<document.$formname.elements[delindex].length; k++) {
5900: document.$formname.elements[delindex][k].checked = false;
5901: }
5902: } else {
5903: document.$formname.elements[delindex].checked = false;
5904: }
5905: }
5906: }
5907: }
5908: }
5909: } else {
5910: if (document.$formname.selfenroll_delete.checked) {
5911: var delindex = getIndexByName('selfenroll_types_'+num);
5912: if (delindex != -1) {
5913: if (document.$formname.elements[delindex].length) {
5914: for (var k=0; k<document.$formname.elements[delindex].length; k++) {
5915: document.$formname.elements[delindex][k].checked = false;
5916: }
5917: } else {
5918: document.$formname.elements[delindex].checked = false;
5919: }
5920: }
5921: }
5922: }
5923: }
5924: return;
5925: }
5926:
5927: function validate_types(form) {
5928: var needaction = new Array();
5929: var countfail = 0;
5930: var actidx = getIndexByName('selfenroll_activate');
5931: if (actidx != -1) {
5932: if (document.$formname.selfenroll_activate.length) {
5933: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
5934: var num = document.$formname.selfenroll_activate[j].value;
5935: if (document.$formname.selfenroll_activate[j].checked) {
5936: countfail = check_types(num,countfail,needaction)
5937: }
5938: }
5939: } else {
5940: if (document.$formname.selfenroll_activate.checked) {
1.398 raeburn 5941: var num = document.$formname.selfenroll_activate.value;
1.249 raeburn 5942: countfail = check_types(num,countfail,needaction)
5943: }
5944: }
5945: }
5946: if (countfail > 0) {
5947: var msg = "$alerts{'acto'}\\n";
5948: var loopend = needaction.length -1;
5949: if (loopend > 0) {
5950: for (var m=0; m<loopend; m++) {
5951: msg += needaction[m]+", ";
5952: }
5953: }
5954: msg += needaction[loopend]+"\\n$alerts{'butn'}\\n$alerts{'wilf'}";
5955: alert(msg);
5956: return;
5957: }
5958: setSections(form);
5959: }
5960:
5961: function check_types(num,countfail,needaction) {
1.406.2.15 raeburn 5962: var boxname = 'selfenroll_types_'+num;
5963: var typeidx = getIndexByName(boxname);
1.249 raeburn 5964: var count = 0;
5965: if (typeidx != -1) {
1.406.2.15 raeburn 5966: if (document.$formname.elements[boxname].length) {
5967: for (var k=0; k<document.$formname.elements[boxname].length; k++) {
5968: if (document.$formname.elements[boxname][k].checked) {
1.249 raeburn 5969: count ++;
5970: }
5971: }
5972: } else {
5973: if (document.$formname.elements[typeidx].checked) {
5974: count ++;
5975: }
5976: }
5977: if (count == 0) {
5978: var domidx = getIndexByName('selfenroll_dom_'+num);
5979: if (domidx != -1) {
5980: var domname = document.$formname.elements[domidx].value;
5981: needaction[countfail] = domname;
5982: countfail ++;
5983: }
5984: }
5985: }
5986: return countfail;
5987: }
5988:
1.398 raeburn 5989: function toggleNotify() {
5990: var selfenrollApproval = 0;
5991: if (document.$formname.selfenroll_approval.length) {
5992: for (var i=0; i<document.$formname.selfenroll_approval.length; i++) {
5993: if (document.$formname.selfenroll_approval[i].checked) {
5994: selfenrollApproval = document.$formname.selfenroll_approval[i].value;
5995: break;
5996: }
5997: }
5998: }
5999: if (document.getElementById('notified')) {
6000: if (selfenrollApproval == 0) {
6001: document.getElementById('notified').style.display='none';
6002: } else {
6003: document.getElementById('notified').style.display='block';
6004: }
6005: }
6006: return;
6007: }
6008:
1.249 raeburn 6009: function getIndexByName(item) {
6010: for (var i=0;i<document.$formname.elements.length;i++) {
6011: if (document.$formname.elements[i].name == item) {
6012: return i;
6013: }
6014: }
6015: return -1;
6016: }
6017: ENDSCRIPT
1.256 raeburn 6018:
1.237 raeburn 6019: my $output = '<script type="text/javascript">'."\n".
1.301 bisitz 6020: '// <![CDATA['."\n".
1.249 raeburn 6021: $setsec_js."\n".$selfenroll_js."\n".
1.301 bisitz 6022: '// ]]>'."\n".
1.237 raeburn 6023: '</script>'."\n".
1.256 raeburn 6024: '<h3>'.$lt->{'selfenroll'}.'</h3>'."\n";
1.400 raeburn 6025:
6026: my $visactions = &cat_visibility();
6027: my ($cathash,%cattype);
6028: my %domconfig = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom);
6029: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
6030: $cathash = $domconfig{'coursecategories'}{'cats'};
6031: $cattype{'auth'} = $domconfig{'coursecategories'}{'auth'};
6032: $cattype{'unauth'} = $domconfig{'coursecategories'}{'unauth'};
1.406 raeburn 6033: if ($cattype{'auth'} eq '') {
6034: $cattype{'auth'} = 'std';
6035: }
6036: if ($cattype{'unauth'} eq '') {
6037: $cattype{'unauth'} = 'std';
6038: }
1.400 raeburn 6039: } else {
6040: $cathash = {};
6041: $cattype{'auth'} = 'std';
6042: $cattype{'unauth'} = 'std';
6043: }
6044: if (($cattype{'auth'} eq 'none') && ($cattype{'unauth'} eq 'none')) {
6045: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
6046: '<br />'.
6047: '<br />'.$visactions->{'take'}.'<ul>'.
6048: '<li>'.$visactions->{'dc_chgconf'}.'</li>'.
6049: '</ul>');
6050: } elsif (($cattype{'auth'} !~ /^(std|domonly)$/) && ($cattype{'unauth'} !~ /^(std|domonly)$/)) {
6051: if ($currsettings->{'uniquecode'}) {
6052: $r->print('<span class="LC_info">'.$visactions->{'vis'}.'</span>');
6053: } else {
6054: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
6055: '<br />'.
6056: '<br />'.$visactions->{'take'}.'<ul>'.
6057: '<li>'.$visactions->{'dc_setcode'}.'</li>'.
6058: '</ul><br />');
6059: }
6060: } else {
6061: my ($visible,$cansetvis,$vismsgs) = &visible_in_stdcat($cdom,$cnum,\%domconfig);
6062: if (ref($visactions) eq 'HASH') {
6063: if ($visible) {
6064: $output .= '<p class="LC_info">'.$visactions->{'vis'}.'</p>';
6065: } else {
6066: $output .= '<p class="LC_warning">'.$visactions->{'miss'}.'</p>'
6067: .$visactions->{'yous'}.
6068: '<p>'.$visactions->{'gen'}.'<br />'.$visactions->{'coca'};
6069: if (ref($vismsgs) eq 'ARRAY') {
6070: $output .= '<br />'.$visactions->{'make'}.'<ul>';
6071: foreach my $item (@{$vismsgs}) {
6072: $output .= '<li>'.$visactions->{$item}.'</li>';
6073: }
6074: $output .= '</ul>';
1.256 raeburn 6075: }
1.400 raeburn 6076: $output .= '</p>';
1.256 raeburn 6077: }
6078: }
6079: }
1.398 raeburn 6080: my $actionhref = '/adm/createuser';
6081: if ($context eq 'domain') {
6082: $actionhref = '/adm/modifycourse';
6083: }
1.400 raeburn 6084:
6085: my %noedit;
6086: unless ($context eq 'domain') {
6087: %noedit = &get_noedit_fields($cdom,$cnum,$crstype,$row);
6088: }
1.398 raeburn 6089: $output .= '<form name="'.$formname.'" method="post" action="'.$actionhref.'">'."\n".
1.256 raeburn 6090: &Apache::lonhtmlcommon::start_pick_box();
1.237 raeburn 6091: if (ref($row) eq 'ARRAY') {
6092: foreach my $item (@{$row}) {
6093: my $title = $item;
6094: if (ref($lt) eq 'HASH') {
6095: $title = $lt->{$item};
6096: }
1.297 bisitz 6097: $output .= &Apache::lonhtmlcommon::row_title($title);
1.237 raeburn 6098: if ($item eq 'types') {
1.398 raeburn 6099: my $curr_types;
6100: if (ref($currsettings) eq 'HASH') {
6101: $curr_types = $currsettings->{'selfenroll_types'};
6102: }
1.400 raeburn 6103: if ($noedit{$item}) {
6104: if ($curr_types eq '*') {
6105: $output .= &mt('Any user in any domain');
6106: } else {
6107: my @entries = split(/;/,$curr_types);
6108: if (@entries > 0) {
6109: $output .= '<ul>';
6110: foreach my $entry (@entries) {
6111: my ($currdom,$typestr) = split(/:/,$entry);
6112: next if ($typestr eq '');
6113: my $domdesc = &Apache::lonnet::domain($currdom);
6114: my @currinsttypes = split(',',$typestr);
6115: my ($othertitle,$usertypes,$types) =
6116: &Apache::loncommon::sorted_inst_types($currdom);
6117: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
6118: $usertypes->{'any'} = &mt('any user');
6119: if (keys(%{$usertypes}) > 0) {
6120: $usertypes->{'other'} = &mt('other users');
6121: }
6122: my @longinsttypes = map { $usertypes->{$_}; } @currinsttypes;
6123: $output .= '<li>'.$domdesc.':'.join(', ',@longinsttypes).'</li>';
6124: }
6125: }
6126: $output .= '</ul>';
6127: } else {
6128: $output .= &mt('None');
6129: }
6130: }
6131: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6132: next;
6133: }
1.241 raeburn 6134: my $showdomdesc = 1;
6135: my $includeempty = 1;
6136: my $num = 0;
6137: $output .= &Apache::loncommon::start_data_table().
6138: &Apache::loncommon::start_data_table_row()
6139: .'<td colspan="2"><span class="LC_nobreak"><label>'
6140: .&mt('Any user in any domain:')
6141: .' <input type="radio" name="selfenroll_all" value="1" ';
6142: if ($curr_types eq '*') {
6143: $output .= ' checked="checked" ';
6144: }
1.249 raeburn 6145: $output .= 'onchange="javascript:update_types('.
1.406.2.6 raeburn 6146: "'selfenroll_all'".');"'.$disabled.' />'.&mt('Yes').'</label>'.
1.249 raeburn 6147: ' <input type="radio" name="selfenroll_all" value="0" ';
1.241 raeburn 6148: if ($curr_types ne '*') {
6149: $output .= ' checked="checked" ';
6150: }
1.249 raeburn 6151: $output .= ' onchange="javascript:update_types('.
1.406.2.6 raeburn 6152: "'selfenroll_all'".');"'.$disabled.' />'.&mt('No').'</label></td>'.
1.249 raeburn 6153: &Apache::loncommon::end_data_table_row().
6154: &Apache::loncommon::end_data_table().
6155: &mt('Or').'<br />'.
6156: &Apache::loncommon::start_data_table();
1.241 raeburn 6157: my %currdoms;
1.249 raeburn 6158: if ($curr_types eq '') {
1.241 raeburn 6159: $output .= &new_selfenroll_dom_row($cdom,'0');
6160: } elsif ($curr_types ne '*') {
6161: my @entries = split(/;/,$curr_types);
6162: if (@entries > 0) {
6163: foreach my $entry (@entries) {
6164: my ($currdom,$typestr) = split(/:/,$entry);
6165: $currdoms{$currdom} = 1;
6166: my $domdesc = &Apache::lonnet::domain($currdom);
1.249 raeburn 6167: my @currinsttypes = split(',',$typestr);
1.241 raeburn 6168: $output .= &Apache::loncommon::start_data_table_row()
6169: .'<td valign="top"><span class="LC_nobreak">'.&mt('Domain:').'<b>'
6170: .' '.$domdesc.' ('.$currdom.')'
6171: .'</b><input type="hidden" name="selfenroll_dom_'.$num
6172: .'" value="'.$currdom.'" /></span><br />'
6173: .'<span class="LC_nobreak"><label><input type="checkbox" '
1.406.2.6 raeburn 6174: .'name="selfenroll_delete" value="'.$num.'" onchange="javascript:update_types('."'selfenroll_delete','$num'".');"'.$disabled.' />'
1.241 raeburn 6175: .&mt('Delete').'</label></span></td>';
1.249 raeburn 6176: $output .= '<td valign="top"> '.&mt('User types:').'<br />'
1.406.2.6 raeburn 6177: .&selfenroll_inst_types($num,$currdom,\@currinsttypes,$readonly).'</td>'
1.241 raeburn 6178: .&Apache::loncommon::end_data_table_row();
6179: $num ++;
6180: }
6181: }
6182: }
1.249 raeburn 6183: my $add_domtitle = &mt('Users in additional domain:');
1.241 raeburn 6184: if ($curr_types eq '*') {
1.249 raeburn 6185: $add_domtitle = &mt('Users in specific domain:');
1.241 raeburn 6186: } elsif ($curr_types eq '') {
1.249 raeburn 6187: $add_domtitle = &mt('Users in other domain:');
1.241 raeburn 6188: }
6189: $output .= &Apache::loncommon::start_data_table_row()
6190: .'<td colspan="2"><span class="LC_nobreak">'.$add_domtitle.'</span><br />'
6191: .&Apache::loncommon::select_dom_form('','selfenroll_newdom',
1.406.2.6 raeburn 6192: $includeempty,$showdomdesc,'','','',$readonly)
1.241 raeburn 6193: .'<input type="hidden" name="selfenroll_types_total" value="'.$num.'" />'
6194: .'</td>'.&Apache::loncommon::end_data_table_row()
6195: .&Apache::loncommon::end_data_table();
1.237 raeburn 6196: } elsif ($item eq 'registered') {
6197: my ($regon,$regoff);
1.398 raeburn 6198: my $registered;
6199: if (ref($currsettings) eq 'HASH') {
6200: $registered = $currsettings->{'selfenroll_registered'};
6201: }
1.400 raeburn 6202: if ($noedit{$item}) {
6203: if ($registered) {
6204: $output .= &mt('Must be registered in course');
6205: } else {
6206: $output .= &mt('No requirement');
6207: }
6208: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6209: next;
6210: }
1.398 raeburn 6211: if ($registered) {
1.237 raeburn 6212: $regon = ' checked="checked" ';
1.406.2.6 raeburn 6213: $regoff = '';
1.237 raeburn 6214: } else {
1.406.2.6 raeburn 6215: $regon = '';
1.237 raeburn 6216: $regoff = ' checked="checked" ';
6217: }
6218: $output .= '<label>'.
1.406.2.6 raeburn 6219: '<input type="radio" name="selfenroll_registered" value="1"'.$regon.$disabled.' />'.
1.244 bisitz 6220: &mt('Yes').'</label> <label>'.
1.406.2.6 raeburn 6221: '<input type="radio" name="selfenroll_registered" value="0"'.$regoff.$disabled.' />'.
1.244 bisitz 6222: &mt('No').'</label>';
1.237 raeburn 6223: } elsif ($item eq 'enroll_dates') {
1.398 raeburn 6224: my ($starttime,$endtime);
6225: if (ref($currsettings) eq 'HASH') {
6226: $starttime = $currsettings->{'selfenroll_start_date'};
6227: $endtime = $currsettings->{'selfenroll_end_date'};
6228: if ($starttime eq '') {
6229: $starttime = $currsettings->{'default_enrollment_start_date'};
6230: }
6231: if ($endtime eq '') {
6232: $endtime = $currsettings->{'default_enrollment_end_date'};
6233: }
1.237 raeburn 6234: }
1.400 raeburn 6235: if ($noedit{$item}) {
6236: $output .= &mt('From: [_1], to: [_2]',&Apache::lonlocal::locallocaltime($starttime),
6237: &Apache::lonlocal::locallocaltime($endtime));
6238: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6239: next;
6240: }
1.237 raeburn 6241: my $startform =
6242: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_start_date',$starttime,
1.406.2.6 raeburn 6243: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
1.237 raeburn 6244: my $endform =
6245: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_end_date',$endtime,
1.406.2.6 raeburn 6246: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
1.237 raeburn 6247: $output .= &selfenroll_date_forms($startform,$endform);
6248: } elsif ($item eq 'access_dates') {
1.398 raeburn 6249: my ($starttime,$endtime);
6250: if (ref($currsettings) eq 'HASH') {
6251: $starttime = $currsettings->{'selfenroll_start_access'};
6252: $endtime = $currsettings->{'selfenroll_end_access'};
6253: if ($starttime eq '') {
6254: $starttime = $currsettings->{'default_enrollment_start_date'};
6255: }
6256: if ($endtime eq '') {
6257: $endtime = $currsettings->{'default_enrollment_end_date'};
6258: }
1.237 raeburn 6259: }
1.400 raeburn 6260: if ($noedit{$item}) {
6261: $output .= &mt('From: [_1], to: [_2]',&Apache::lonlocal::locallocaltime($starttime),
6262: &Apache::lonlocal::locallocaltime($endtime));
6263: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6264: next;
6265: }
1.237 raeburn 6266: my $startform =
6267: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_start_access',$starttime,
1.406.2.6 raeburn 6268: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
1.237 raeburn 6269: my $endform =
6270: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_end_access',$endtime,
1.406.2.6 raeburn 6271: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
1.237 raeburn 6272: $output .= &selfenroll_date_forms($startform,$endform);
6273: } elsif ($item eq 'section') {
1.398 raeburn 6274: my $currsec;
6275: if (ref($currsettings) eq 'HASH') {
6276: $currsec = $currsettings->{'selfenroll_section'};
6277: }
1.237 raeburn 6278: my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum);
6279: my $newsecval;
6280: if ($currsec ne 'none' && $currsec ne '') {
6281: if (!defined($sections_count{$currsec})) {
6282: $newsecval = $currsec;
6283: }
6284: }
1.400 raeburn 6285: if ($noedit{$item}) {
6286: if ($currsec ne '') {
6287: $output .= $currsec;
6288: } else {
6289: $output .= &mt('No specific section');
6290: }
6291: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6292: next;
6293: }
1.237 raeburn 6294: my $sections_select =
1.406.2.6 raeburn 6295: &Apache::lonuserutils::course_sections(\%sections_count,'st',$currsec,$disabled);
1.237 raeburn 6296: $output .= '<table class="LC_createuser">'."\n".
6297: '<tr class="LC_section_row">'."\n".
6298: '<td align="center">'.&mt('Existing sections')."\n".
6299: '<br />'.$sections_select.'</td><td align="center">'.
6300: &mt('New section').'<br />'."\n".
1.406.2.6 raeburn 6301: '<input type="text" name="newsec" size="15" value="'.$newsecval.'"'.$disabled.' />'."\n".
1.237 raeburn 6302: '<input type="hidden" name="sections" value="" />'."\n".
6303: '</td></tr></table>'."\n";
1.276 raeburn 6304: } elsif ($item eq 'approval') {
1.398 raeburn 6305: my ($currnotified,$currapproval,%appchecked);
6306: my %selfdescs = &Apache::lonuserutils::selfenroll_default_descs();
1.406.2.6 raeburn 6307: if (ref($currsettings) eq 'HASH') {
1.398 raeburn 6308: $currnotified = $currsettings->{'selfenroll_notifylist'};
6309: $currapproval = $currsettings->{'selfenroll_approval'};
6310: }
6311: if ($currapproval !~ /^[012]$/) {
6312: $currapproval = 0;
6313: }
1.400 raeburn 6314: if ($noedit{$item}) {
6315: $output .= $selfdescs{'approval'}{$currapproval}.
6316: '<br />'.&mt('(Set by Domain Coordinator)');
6317: next;
6318: }
1.398 raeburn 6319: $appchecked{$currapproval} = ' checked="checked"';
6320: for my $i (0..2) {
6321: $output .= '<label>'.
6322: '<input type="radio" name="selfenroll_approval" value="'.$i.'"'.
1.406.2.6 raeburn 6323: $appchecked{$i}.' onclick="toggleNotify();"'.$disabled.' />'.
6324: $selfdescs{'approval'}{$i}.'</label>'.(' 'x2);
1.276 raeburn 6325: }
6326: my %advhash = &Apache::lonnet::get_course_adv_roles($cid,1);
6327: my (@ccs,%notified);
1.322 raeburn 6328: my $ccrole = 'cc';
6329: if ($crstype eq 'Community') {
6330: $ccrole = 'co';
6331: }
6332: if ($advhash{$ccrole}) {
6333: @ccs = split(/,/,$advhash{$ccrole});
1.276 raeburn 6334: }
6335: if ($currnotified) {
6336: foreach my $current (split(/,/,$currnotified)) {
6337: $notified{$current} = 1;
6338: if (!grep(/^\Q$current\E$/,@ccs)) {
6339: push(@ccs,$current);
6340: }
6341: }
6342: }
6343: if (@ccs) {
1.398 raeburn 6344: my $style;
6345: unless ($currapproval) {
6346: $style = ' style="display: none;"';
6347: }
6348: $output .= '<br /><div id="notified"'.$style.'>'.
6349: &mt('Personnel to be notified when an enrollment request needs approval, or has been approved:').' '.
6350: &Apache::loncommon::start_data_table().
1.276 raeburn 6351: &Apache::loncommon::start_data_table_row();
6352: my $count = 0;
6353: my $numcols = 4;
6354: foreach my $cc (sort(@ccs)) {
6355: my $notifyon;
6356: my ($ccuname,$ccudom) = split(/:/,$cc);
6357: if ($notified{$cc}) {
6358: $notifyon = ' checked="checked" ';
6359: }
6360: if ($count && !$count%$numcols) {
6361: $output .= &Apache::loncommon::end_data_table_row().
6362: &Apache::loncommon::start_data_table_row()
6363: }
6364: $output .= '<td><span class="LC_nobreak"><label>'.
1.406.2.6 raeburn 6365: '<input type="checkbox" name="selfenroll_notify"'.$notifyon.' value="'.$cc.'"'.$disabled.' />'.
1.276 raeburn 6366: &Apache::loncommon::plainname($ccuname,$ccudom).
6367: '</label></span></td>';
1.343 raeburn 6368: $count ++;
1.276 raeburn 6369: }
6370: my $rem = $count%$numcols;
6371: if ($rem) {
6372: my $emptycols = $numcols - $rem;
6373: for (my $i=0; $i<$emptycols; $i++) {
6374: $output .= '<td> </td>';
6375: }
6376: }
6377: $output .= &Apache::loncommon::end_data_table_row().
1.398 raeburn 6378: &Apache::loncommon::end_data_table().
6379: '</div>';
1.276 raeburn 6380: }
6381: } elsif ($item eq 'limit') {
1.398 raeburn 6382: my ($crslimit,$selflimit,$nolimit,$currlim,$currcap);
6383: if (ref($currsettings) eq 'HASH') {
6384: $currlim = $currsettings->{'selfenroll_limit'};
6385: $currcap = $currsettings->{'selfenroll_cap'};
6386: }
1.400 raeburn 6387: if ($noedit{$item}) {
6388: if (($currlim eq 'allstudents') || ($currlim eq 'selfenrolled')) {
6389: if ($currlim eq 'allstudents') {
6390: $output .= &mt('Limit by total students');
6391: } elsif ($currlim eq 'selfenrolled') {
6392: $output .= &mt('Limit by total self-enrolled students');
6393: }
6394: $output .= ' '.&mt('Maximum: [_1]',$currcap).
6395: '<br />'.&mt('(Set by Domain Coordinator)');
6396: } else {
6397: $output .= &mt('No limit').'<br />'.&mt('(Set by Domain Coordinator)');
6398: }
6399: next;
6400: }
1.276 raeburn 6401: if ($currlim eq 'allstudents') {
6402: $crslimit = ' checked="checked" ';
6403: $selflimit = ' ';
6404: $nolimit = ' ';
6405: } elsif ($currlim eq 'selfenrolled') {
6406: $crslimit = ' ';
6407: $selflimit = ' checked="checked" ';
6408: $nolimit = ' ';
6409: } else {
6410: $crslimit = ' ';
6411: $selflimit = ' ';
1.398 raeburn 6412: $nolimit = ' checked="checked" ';
1.276 raeburn 6413: }
6414: $output .= '<table><tr><td><label>'.
1.406.2.6 raeburn 6415: '<input type="radio" name="selfenroll_limit" value="none"'.$nolimit.$disabled.'/>'.
1.276 raeburn 6416: &mt('No limit').'</label></td><td><label>'.
1.406.2.6 raeburn 6417: '<input type="radio" name="selfenroll_limit" value="allstudents"'.$crslimit.$disabled.'/>'.
1.276 raeburn 6418: &mt('Limit by total students').'</label></td><td><label>'.
1.406.2.6 raeburn 6419: '<input type="radio" name="selfenroll_limit" value="selfenrolled"'.$selflimit.$disabled.'/>'.
1.276 raeburn 6420: &mt('Limit by total self-enrolled students').
6421: '</td></tr><tr>'.
6422: '<td> </td><td colspan="2"><span class="LC_nobreak">'.
6423: (' 'x3).&mt('Maximum number allowed: ').
1.406.2.6 raeburn 6424: '<input type="text" name="selfenroll_cap" size = "5" value="'.$currcap.'"'.$disabled.' /></td></tr></table>';
1.237 raeburn 6425: }
6426: $output .= &Apache::lonhtmlcommon::row_closure(1);
6427: }
6428: }
1.406.2.6 raeburn 6429: $output .= &Apache::lonhtmlcommon::end_pick_box().'<br />';
6430: unless ($readonly) {
6431: $output .= '<input type="button" name="selfenrollconf" value="'
6432: .&mt('Save').'" onclick="validate_types(this.form);" />';
6433: }
6434: $output .= '<input type="hidden" name="action" value="selfenroll" />'
1.406.2.11 raeburn 6435: .'<input type="hidden" name="state" value="done" />'."\n"
6436: .$additional.'</form>';
1.237 raeburn 6437: $r->print($output);
6438: return;
6439: }
6440:
1.400 raeburn 6441: sub get_noedit_fields {
6442: my ($cdom,$cnum,$crstype,$row) = @_;
6443: my %noedit;
6444: if (ref($row) eq 'ARRAY') {
6445: my %settings = &Apache::lonnet::get('environment',['internal.coursecode','internal.textbook',
6446: 'internal.selfenrollmgrdc',
6447: 'internal.selfenrollmgrcc'],$cdom,$cnum);
6448: my $type = &Apache::lonuserutils::get_extended_type($cdom,$cnum,$crstype,\%settings);
6449: my (%specific_managebydc,%specific_managebycc,%default_managebydc);
6450: map { $specific_managebydc{$_} = 1; } (split(/,/,$settings{'internal.selfenrollmgrdc'}));
6451: map { $specific_managebycc{$_} = 1; } (split(/,/,$settings{'internal.selfenrollmgrcc'}));
6452: my %domdefaults = &Apache::lonnet::get_domain_defaults($cdom);
6453: map { $default_managebydc{$_} = 1; } (split(/,/,$domdefaults{$type.'selfenrolladmdc'}));
6454:
6455: foreach my $item (@{$row}) {
6456: next if ($specific_managebycc{$item});
6457: if (($specific_managebydc{$item}) || ($default_managebydc{$item})) {
6458: $noedit{$item} = 1;
6459: }
6460: }
6461: }
6462: return %noedit;
6463: }
6464:
6465: sub visible_in_stdcat {
6466: my ($cdom,$cnum,$domconf) = @_;
6467: my ($cathash,%settable,@vismsgs,$cansetvis,$visible);
6468: unless (ref($domconf) eq 'HASH') {
6469: return ($visible,$cansetvis,\@vismsgs);
6470: }
6471: if (ref($domconf->{'coursecategories'}) eq 'HASH') {
6472: if ($domconf->{'coursecategories'}{'togglecats'} eq 'crs') {
1.256 raeburn 6473: $settable{'togglecats'} = 1;
6474: }
1.400 raeburn 6475: if ($domconf->{'coursecategories'}{'categorize'} eq 'crs') {
1.256 raeburn 6476: $settable{'categorize'} = 1;
6477: }
1.400 raeburn 6478: $cathash = $domconf->{'coursecategories'}{'cats'};
1.256 raeburn 6479: }
1.260 raeburn 6480: if ($settable{'togglecats'} && $settable{'categorize'}) {
1.256 raeburn 6481: $cansetvis = &mt('You are able to both assign a course category and choose to exclude this course from the catalog.');
6482: } elsif ($settable{'togglecats'}) {
6483: $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 6484: } elsif ($settable{'categorize'}) {
1.256 raeburn 6485: $cansetvis = &mt('You may assign a course category, but only a Domain Coordinator may choose to exclude this course from the catalog.');
6486: } else {
6487: $cansetvis = &mt('Only a Domain Coordinator may assign a course category or choose to exclude this course from the catalog.');
6488: }
6489:
6490: my %currsettings =
6491: &Apache::lonnet::get('environment',['hidefromcat','categories','internal.coursecode'],
6492: $cdom,$cnum);
1.400 raeburn 6493: $visible = 0;
1.256 raeburn 6494: if ($currsettings{'internal.coursecode'} ne '') {
1.400 raeburn 6495: if (ref($domconf->{'coursecategories'}) eq 'HASH') {
6496: $cathash = $domconf->{'coursecategories'}{'cats'};
1.256 raeburn 6497: if (ref($cathash) eq 'HASH') {
6498: if ($cathash->{'instcode::0'} eq '') {
6499: push(@vismsgs,'dc_addinst');
6500: } else {
6501: $visible = 1;
6502: }
6503: } else {
6504: $visible = 1;
6505: }
6506: } else {
6507: $visible = 1;
6508: }
6509: } else {
6510: if (ref($cathash) eq 'HASH') {
6511: if ($cathash->{'instcode::0'} ne '') {
6512: push(@vismsgs,'dc_instcode');
6513: }
6514: } else {
6515: push(@vismsgs,'dc_instcode');
6516: }
6517: }
6518: if ($currsettings{'categories'} ne '') {
6519: my $cathash;
1.400 raeburn 6520: if (ref($domconf->{'coursecategories'}) eq 'HASH') {
6521: $cathash = $domconf->{'coursecategories'}{'cats'};
1.256 raeburn 6522: if (ref($cathash) eq 'HASH') {
6523: if (keys(%{$cathash}) == 0) {
6524: push(@vismsgs,'dc_catalog');
6525: } elsif ((keys(%{$cathash}) == 1) && ($cathash->{'instcode::0'} ne '')) {
6526: push(@vismsgs,'dc_categories');
6527: } else {
6528: my @currcategories = split('&',$currsettings{'categories'});
6529: my $matched = 0;
6530: foreach my $cat (@currcategories) {
6531: if ($cathash->{$cat} ne '') {
6532: $visible = 1;
6533: $matched = 1;
6534: last;
6535: }
6536: }
6537: if (!$matched) {
1.260 raeburn 6538: if ($settable{'categorize'}) {
1.256 raeburn 6539: push(@vismsgs,'chgcat');
6540: } else {
6541: push(@vismsgs,'dc_chgcat');
6542: }
6543: }
6544: }
6545: }
6546: }
6547: } else {
6548: if (ref($cathash) eq 'HASH') {
6549: if ((keys(%{$cathash}) > 1) ||
6550: (keys(%{$cathash}) == 1) && ($cathash->{'instcode::0'} eq '')) {
1.260 raeburn 6551: if ($settable{'categorize'}) {
1.256 raeburn 6552: push(@vismsgs,'addcat');
6553: } else {
6554: push(@vismsgs,'dc_addcat');
6555: }
6556: }
6557: }
6558: }
6559: if ($currsettings{'hidefromcat'} eq 'yes') {
6560: $visible = 0;
6561: if ($settable{'togglecats'}) {
6562: unshift(@vismsgs,'unhide');
6563: } else {
6564: unshift(@vismsgs,'dc_unhide')
6565: }
6566: }
1.400 raeburn 6567: return ($visible,$cansetvis,\@vismsgs);
6568: }
6569:
6570: sub cat_visibility {
6571: my %visactions = &Apache::lonlocal::texthash(
6572: vis => 'This course/community currently appears in the Course/Community Catalog for this domain.',
6573: 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.',
6574: miss => 'This course/community does not currently appear in the Course/Community Catalog for this domain.',
6575: none => 'Display of a course catalog is disabled for this domain.',
6576: yous => 'You should remedy this if you plan to allow self-enrollment, otherwise students will have difficulty finding this course.',
6577: 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.',
6578: make => 'Make any changes to self-enrollment settings below, click "Save", then take action to include the course in the Catalog:',
6579: take => 'Take the following action to ensure the course appears in the Catalog:',
6580: dc_chgconf => 'Ask a domain coordinator to change the Catalog type for this domain.',
6581: dc_setcode => 'Ask a domain coordinator to assign a six character code to the course',
6582: dc_unhide => 'Ask a domain coordinator to change the "Exclude from course catalog" setting.',
6583: dc_addinst => 'Ask a domain coordinator to enable display the catalog of "Official courses (with institutional codes)".',
6584: dc_instcode => 'Ask a domain coordinator to assign an institutional code (if this is an official course).',
6585: dc_catalog => 'Ask a domain coordinator to enable or create at least one course category in the domain.',
6586: dc_categories => 'Ask a domain coordinator to create a hierarchy of categories and sub categories for courses in the domain.',
6587: 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',
6588: dc_addcat => 'Ask a domain coordinator to assign a category to the course.',
6589: );
6590: $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>"');
6591: $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>"');
6592: $visactions{'addcat'} = &mt('Use [_1]Categorize course[_2] to assign a category to the course.','"<a href="/adm/courseprefs?phase=display&actions=courseinfo">','</a>"');
6593: return \%visactions;
1.256 raeburn 6594: }
6595:
1.241 raeburn 6596: sub new_selfenroll_dom_row {
6597: my ($newdom,$num) = @_;
6598: my $domdesc = &Apache::lonnet::domain($newdom);
6599: my $output;
6600: if ($domdesc ne '') {
6601: $output .= &Apache::loncommon::start_data_table_row()
6602: .'<td valign="top"><span class="LC_nobreak">'.&mt('Domain:').' <b>'.$domdesc
6603: .' ('.$newdom.')</b><input type="hidden" name="selfenroll_dom_'.$num
1.249 raeburn 6604: .'" value="'.$newdom.'" /></span><br />'
6605: .'<span class="LC_nobreak"><label><input type="checkbox" '
6606: .'name="selfenroll_activate" value="'.$num.'" '
6607: .'onchange="javascript:update_types('
6608: ."'selfenroll_activate','$num'".');" />'
6609: .&mt('Activate').'</label></span></td>';
1.241 raeburn 6610: my @currinsttypes;
6611: $output .= '<td>'.&mt('User types:').'<br />'
6612: .&selfenroll_inst_types($num,$newdom,\@currinsttypes).'</td>'
6613: .&Apache::loncommon::end_data_table_row();
6614: }
6615: return $output;
6616: }
6617:
6618: sub selfenroll_inst_types {
1.406.2.6 raeburn 6619: my ($num,$currdom,$currinsttypes,$readonly) = @_;
1.241 raeburn 6620: my $output;
6621: my $numinrow = 4;
6622: my $count = 0;
6623: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($currdom);
1.247 raeburn 6624: my $othervalue = 'any';
1.406.2.6 raeburn 6625: my $disabled;
6626: if ($readonly) {
6627: $disabled = ' disabled="disabled"';
6628: }
1.241 raeburn 6629: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
1.251 raeburn 6630: if (keys(%{$usertypes}) > 0) {
1.247 raeburn 6631: $othervalue = 'other';
6632: }
1.241 raeburn 6633: $output .= '<table><tr>';
6634: foreach my $type (@{$types}) {
6635: if (($count > 0) && ($count%$numinrow == 0)) {
6636: $output .= '</tr><tr>';
6637: }
6638: if (defined($usertypes->{$type})) {
1.257 raeburn 6639: my $esc_type = &escape($type);
1.241 raeburn 6640: $output .= '<td><span class="LC_nobreak"><label><input type = "checkbox" value="'.
1.257 raeburn 6641: $esc_type.'" ';
1.241 raeburn 6642: if (ref($currinsttypes) eq 'ARRAY') {
6643: if (@{$currinsttypes} > 0) {
1.249 raeburn 6644: if (grep(/^any$/,@{$currinsttypes})) {
6645: $output .= 'checked="checked"';
1.257 raeburn 6646: } elsif (grep(/^\Q$esc_type\E$/,@{$currinsttypes})) {
1.241 raeburn 6647: $output .= 'checked="checked"';
6648: }
1.249 raeburn 6649: } else {
6650: $output .= 'checked="checked"';
1.241 raeburn 6651: }
6652: }
1.406.2.6 raeburn 6653: $output .= ' name="selfenroll_types_'.$num.'"'.$disabled.' />'.$usertypes->{$type}.'</label></span></td>';
1.241 raeburn 6654: }
6655: $count ++;
6656: }
6657: if (($count > 0) && ($count%$numinrow == 0)) {
6658: $output .= '</tr><tr>';
6659: }
1.249 raeburn 6660: $output .= '<td><span class="LC_nobreak"><label><input type = "checkbox" value="'.$othervalue.'"';
1.241 raeburn 6661: if (ref($currinsttypes) eq 'ARRAY') {
6662: if (@{$currinsttypes} > 0) {
1.249 raeburn 6663: if (grep(/^any$/,@{$currinsttypes})) {
6664: $output .= ' checked="checked"';
6665: } elsif ($othervalue eq 'other') {
6666: if (grep(/^\Q$othervalue\E$/,@{$currinsttypes})) {
6667: $output .= ' checked="checked"';
6668: }
1.241 raeburn 6669: }
1.249 raeburn 6670: } else {
6671: $output .= ' checked="checked"';
1.241 raeburn 6672: }
1.249 raeburn 6673: } else {
6674: $output .= ' checked="checked"';
1.241 raeburn 6675: }
1.406.2.6 raeburn 6676: $output .= ' name="selfenroll_types_'.$num.'"'.$disabled.' />'.$othertitle.'</label></span></td></tr></table>';
1.241 raeburn 6677: }
6678: return $output;
6679: }
6680:
1.237 raeburn 6681: sub selfenroll_date_forms {
6682: my ($startform,$endform) = @_;
6683: my $output .= &Apache::lonhtmlcommon::start_pick_box()."\n".
1.244 bisitz 6684: &Apache::lonhtmlcommon::row_title(&mt('Start date'),
1.237 raeburn 6685: 'LC_oddrow_value')."\n".
6686: $startform."\n".
6687: &Apache::lonhtmlcommon::row_closure(1).
1.244 bisitz 6688: &Apache::lonhtmlcommon::row_title(&mt('End date'),
1.237 raeburn 6689: 'LC_oddrow_value')."\n".
6690: $endform."\n".
6691: &Apache::lonhtmlcommon::row_closure(1).
6692: &Apache::lonhtmlcommon::end_pick_box();
6693: return $output;
6694: }
6695:
1.239 raeburn 6696: sub print_userchangelogs_display {
1.406.2.5 raeburn 6697: my ($r,$context,$permission,$brcrum) = @_;
1.363 raeburn 6698: my $formname = 'rolelog';
1.406.2.6 raeburn 6699: my ($username,$domain,$crstype,$viewablesec,%roleslog);
1.363 raeburn 6700: if ($context eq 'domain') {
6701: $domain = $env{'request.role.domain'};
6702: %roleslog=&Apache::lonnet::dump_dom('nohist_rolelog',$domain);
6703: } else {
6704: if ($context eq 'course') {
6705: $domain = $env{'course.'.$env{'request.course.id'}.'.domain'};
6706: $username = $env{'course.'.$env{'request.course.id'}.'.num'};
6707: $crstype = &Apache::loncommon::course_type();
1.406.2.6 raeburn 6708: $viewablesec = &Apache::lonuserutils::viewable_section($permission);
1.363 raeburn 6709: my %saveable_parameters = ('show' => 'scalar',);
6710: &Apache::loncommon::store_course_settings('roles_log',
6711: \%saveable_parameters);
6712: &Apache::loncommon::restore_course_settings('roles_log',
6713: \%saveable_parameters);
6714: } elsif ($context eq 'author') {
6715: $domain = $env{'user.domain'};
6716: if ($env{'request.role'} =~ m{^au\./\Q$domain\E/$}) {
6717: $username = $env{'user.name'};
6718: } else {
6719: undef($domain);
6720: }
6721: }
6722: if ($domain ne '' && $username ne '') {
6723: %roleslog=&Apache::lonnet::dump('nohist_rolelog',$domain,$username);
6724: }
6725: }
1.239 raeburn 6726: if ((keys(%roleslog))[0]=~/^error\:/) { undef(%roleslog); }
6727:
1.406.2.5 raeburn 6728: my $helpitem;
6729: if ($context eq 'course') {
6730: $helpitem = 'Course_User_Logs';
1.406.2.14 raeburn 6731: } elsif ($context eq 'domain') {
6732: $helpitem = 'Domain_Role_Logs';
6733: } elsif ($context eq 'author') {
6734: $helpitem = 'Author_User_Logs';
1.406.2.5 raeburn 6735: }
6736: push (@{$brcrum},
6737: {href => '/adm/createuser?action=changelogs',
6738: text => 'User Management Logs',
6739: help => $helpitem});
6740: my $bread_crumbs_component = 'User Changes';
6741: my $args = { bread_crumbs => $brcrum,
6742: bread_crumbs_component => $bread_crumbs_component};
6743:
6744: # Create navigation javascript
6745: my $jsnav = &userlogdisplay_js($formname);
6746:
6747: my $jscript = (<<ENDSCRIPT);
6748: <script type="text/javascript">
6749: // <![CDATA[
6750: $jsnav
6751: // ]]>
6752: </script>
6753: ENDSCRIPT
6754:
6755: # print page header
6756: $r->print(&header($jscript,$args));
6757:
1.239 raeburn 6758: # set defaults
6759: my $now = time();
6760: my $defstart = $now - (7*24*3600); #7 days ago
6761: my %defaults = (
6762: page => '1',
6763: show => '10',
6764: role => 'any',
6765: chgcontext => 'any',
6766: rolelog_start_date => $defstart,
6767: rolelog_end_date => $now,
6768: );
6769: my $more_records = 0;
6770:
6771: # set current
6772: my %curr;
6773: foreach my $item ('show','page','role','chgcontext') {
6774: $curr{$item} = $env{'form.'.$item};
6775: }
6776: my ($startdate,$enddate) =
6777: &Apache::lonuserutils::get_dates_from_form('rolelog_start_date','rolelog_end_date');
6778: $curr{'rolelog_start_date'} = $startdate;
6779: $curr{'rolelog_end_date'} = $enddate;
6780: foreach my $key (keys(%defaults)) {
6781: if ($curr{$key} eq '') {
6782: $curr{$key} = $defaults{$key};
6783: }
6784: }
1.248 raeburn 6785: my (%whodunit,%changed,$version);
6786: ($version) = ($r->dir_config('lonVersion') =~ /^([\d\.]+)\-/);
1.239 raeburn 6787: my ($minshown,$maxshown);
1.255 raeburn 6788: $minshown = 1;
1.239 raeburn 6789: my $count = 0;
1.406.2.5 raeburn 6790: if ($curr{'show'} =~ /\D/) {
6791: $curr{'page'} = 1;
6792: } else {
1.239 raeburn 6793: $maxshown = $curr{'page'} * $curr{'show'};
6794: if ($curr{'page'} > 1) {
6795: $minshown = 1 + ($curr{'page'} - 1) * $curr{'show'};
6796: }
6797: }
1.301 bisitz 6798:
1.327 raeburn 6799: # Form Header
6800: $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">'.
1.363 raeburn 6801: &role_display_filter($context,$formname,$domain,$username,\%curr,
6802: $version,$crstype));
1.327 raeburn 6803:
6804: my $showntableheader = 0;
6805:
6806: # Table Header
6807: my $tableheader =
6808: &Apache::loncommon::start_data_table_header_row()
6809: .'<th> </th>'
6810: .'<th>'.&mt('When').'</th>'
6811: .'<th>'.&mt('Who made the change').'</th>'
6812: .'<th>'.&mt('Changed User').'</th>'
1.363 raeburn 6813: .'<th>'.&mt('Role').'</th>';
6814:
6815: if ($context eq 'course') {
6816: $tableheader .= '<th>'.&mt('Section').'</th>';
6817: }
6818: $tableheader .=
6819: '<th>'.&mt('Context').'</th>'
1.327 raeburn 6820: .'<th>'.&mt('Start').'</th>'
6821: .'<th>'.&mt('End').'</th>'
6822: .&Apache::loncommon::end_data_table_header_row();
6823:
6824: # Display user change log data
1.239 raeburn 6825: foreach my $id (sort { $roleslog{$b}{'exe_time'}<=>$roleslog{$a}{'exe_time'} } (keys(%roleslog))) {
6826: next if (($roleslog{$id}{'exe_time'} < $curr{'rolelog_start_date'}) ||
6827: ($roleslog{$id}{'exe_time'} > $curr{'rolelog_end_date'}));
1.406.2.5 raeburn 6828: if ($curr{'show'} !~ /\D/) {
1.239 raeburn 6829: if ($count >= $curr{'page'} * $curr{'show'}) {
6830: $more_records = 1;
6831: last;
6832: }
6833: }
6834: if ($curr{'role'} ne 'any') {
6835: next if ($roleslog{$id}{'logentry'}{'role'} ne $curr{'role'});
6836: }
6837: if ($curr{'chgcontext'} ne 'any') {
6838: if ($curr{'chgcontext'} eq 'selfenroll') {
6839: next if (!$roleslog{$id}{'logentry'}{'selfenroll'});
6840: } else {
6841: next if ($roleslog{$id}{'logentry'}{'context'} ne $curr{'chgcontext'});
6842: }
6843: }
1.406.2.6 raeburn 6844: if (($context eq 'course') && ($viewablesec ne '')) {
6845: next if ($roleslog{$id}{'logentry'}{'section'} ne $viewablesec);
6846: }
1.239 raeburn 6847: $count ++;
6848: next if ($count < $minshown);
1.327 raeburn 6849: unless ($showntableheader) {
1.406.2.5 raeburn 6850: $r->print(&Apache::loncommon::start_data_table()
1.327 raeburn 6851: .$tableheader);
6852: $r->rflush();
6853: $showntableheader = 1;
6854: }
1.239 raeburn 6855: if ($whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}} eq '') {
6856: $whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}} =
6857: &Apache::loncommon::plainname($roleslog{$id}{'exe_uname'},$roleslog{$id}{'exe_udom'});
6858: }
6859: if ($changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}} eq '') {
6860: $changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}} =
6861: &Apache::loncommon::plainname($roleslog{$id}{'uname'},$roleslog{$id}{'udom'});
6862: }
6863: my $sec = $roleslog{$id}{'logentry'}{'section'};
6864: if ($sec eq '') {
6865: $sec = &mt('None');
6866: }
6867: my ($rolestart,$roleend);
6868: if ($roleslog{$id}{'delflag'}) {
6869: $rolestart = &mt('deleted');
6870: $roleend = &mt('deleted');
6871: } else {
6872: $rolestart = $roleslog{$id}{'logentry'}{'start'};
6873: $roleend = $roleslog{$id}{'logentry'}{'end'};
6874: if ($rolestart eq '' || $rolestart == 0) {
6875: $rolestart = &mt('No start date');
6876: } else {
6877: $rolestart = &Apache::lonlocal::locallocaltime($rolestart);
6878: }
6879: if ($roleend eq '' || $roleend == 0) {
6880: $roleend = &mt('No end date');
6881: } else {
6882: $roleend = &Apache::lonlocal::locallocaltime($roleend);
6883: }
6884: }
6885: my $chgcontext = $roleslog{$id}{'logentry'}{'context'};
6886: if ($roleslog{$id}{'logentry'}{'selfenroll'}) {
6887: $chgcontext = 'selfenroll';
6888: }
1.363 raeburn 6889: my %lt = &rolechg_contexts($context,$crstype);
1.239 raeburn 6890: if ($chgcontext ne '' && $lt{$chgcontext} ne '') {
6891: $chgcontext = $lt{$chgcontext};
6892: }
1.327 raeburn 6893: $r->print(
1.301 bisitz 6894: &Apache::loncommon::start_data_table_row()
6895: .'<td>'.$count.'</td>'
6896: .'<td>'.&Apache::lonlocal::locallocaltime($roleslog{$id}{'exe_time'}).'</td>'
6897: .'<td>'.$whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}}.'</td>'
6898: .'<td>'.$changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}}.'</td>'
1.363 raeburn 6899: .'<td>'.&Apache::lonnet::plaintext($roleslog{$id}{'logentry'}{'role'},$crstype).'</td>');
6900: if ($context eq 'course') {
6901: $r->print('<td>'.$sec.'</td>');
6902: }
6903: $r->print(
6904: '<td>'.$chgcontext.'</td>'
1.301 bisitz 6905: .'<td>'.$rolestart.'</td>'
6906: .'<td>'.$roleend.'</td>'
1.327 raeburn 6907: .&Apache::loncommon::end_data_table_row()."\n");
1.301 bisitz 6908: }
6909:
1.327 raeburn 6910: if ($showntableheader) { # Table footer, if content displayed above
1.406.2.5 raeburn 6911: $r->print(&Apache::loncommon::end_data_table().
6912: &userlogdisplay_navlinks(\%curr,$more_records));
1.327 raeburn 6913: } else { # No content displayed above
1.301 bisitz 6914: $r->print('<p class="LC_info">'
6915: .&mt('There are no records to display.')
6916: .'</p>'
6917: );
1.239 raeburn 6918: }
1.301 bisitz 6919:
1.327 raeburn 6920: # Form Footer
6921: $r->print(
6922: '<input type="hidden" name="page" value="'.$curr{'page'}.'" />'
6923: .'<input type="hidden" name="action" value="changelogs" />'
6924: .'</form>');
6925: return;
6926: }
1.301 bisitz 6927:
1.406.2.5 raeburn 6928: sub print_useraccesslogs_display {
6929: my ($r,$uname,$udom,$permission,$brcrum) = @_;
6930: my $formname = 'accesslog';
6931: my $form = 'document.accesslog';
6932:
6933: # set breadcrumbs
1.406.2.7 raeburn 6934: my %breadcrumb_text = &singleuser_breadcrumb('','domain',$udom);
1.406.2.12 raeburn 6935: my $prevphasestr;
6936: if ($env{'form.popup'}) {
6937: $brcrum = [];
6938: } else {
6939: push (@{$brcrum},
6940: {href => "javascript:backPage($form)",
6941: text => $breadcrumb_text{'search'}});
6942: my @prevphases;
6943: if ($env{'form.prevphases'}) {
6944: @prevphases = split(/,/,$env{'form.prevphases'});
6945: $prevphasestr = $env{'form.prevphases'};
6946: }
6947: if (($env{'form.phase'} eq 'userpicked') || (grep(/^userpicked$/,@prevphases))) {
6948: push(@{$brcrum},
6949: {href => "javascript:backPage($form,'get_user_info','select')",
6950: text => $breadcrumb_text{'userpicked'}});
6951: if ($env{'form.phase'} eq 'userpicked') {
6952: $prevphasestr = 'userpicked';
6953: }
1.406.2.5 raeburn 6954: }
6955: }
6956: push(@{$brcrum},
6957: {href => '/adm/createuser?action=accesslogs',
6958: text => 'User access logs',
1.406.2.8 raeburn 6959: help => 'Domain_User_Access_Logs'});
1.406.2.5 raeburn 6960: my $bread_crumbs_component = 'User Access Logs';
6961: my $args = { bread_crumbs => $brcrum,
6962: bread_crumbs_component => 'User Management'};
1.406.2.8 raeburn 6963: if ($env{'form.popup'}) {
6964: $args->{'no_nav_bar'} = 1;
1.406.2.12 raeburn 6965: $args->{'bread_crumbs_nomenu'} = 1;
1.406.2.8 raeburn 6966: }
1.406.2.5 raeburn 6967:
6968: # set javascript
6969: my ($jsback,$elements) = &crumb_utilities();
6970: my $jsnav = &userlogdisplay_js($formname);
6971:
6972: my $jscript = (<<ENDSCRIPT);
1.239 raeburn 6973: <script type="text/javascript">
1.301 bisitz 6974: // <![CDATA[
1.406.2.5 raeburn 6975:
6976: $jsback
6977: $jsnav
6978:
6979: // ]]>
6980: </script>
6981:
6982: ENDSCRIPT
6983:
6984: # print page header
6985: $r->print(&header($jscript,$args));
6986:
6987: # early out unless log data can be displayed.
6988: unless ($permission->{'activity'}) {
6989: $r->print('<p class="LC_warning">'
6990: .&mt('You do not have rights to display user access logs.')
1.406.2.12 raeburn 6991: .'</p>');
6992: if ($env{'form.popup'}) {
6993: $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a></p>');
6994: } else {
6995: $r->print(&earlyout_accesslog_form($formname,$prevphasestr,$udom));
6996: }
1.406.2.5 raeburn 6997: return;
6998: }
6999:
7000: unless ($udom eq $env{'request.role.domain'}) {
7001: $r->print('<p class="LC_warning">'
7002: .&mt("User's domain must match role's domain")
7003: .'</p>'
7004: .&earlyout_accesslog_form($formname,$prevphasestr,$udom));
7005: return;
7006: }
7007:
7008: if (($uname eq '') || ($udom eq '')) {
7009: $r->print('<p class="LC_warning">'
7010: .&mt('Invalid username or domain')
7011: .'</p>'
7012: .&earlyout_accesslog_form($formname,$prevphasestr,$udom));
7013: return;
7014: }
7015:
1.406.2.13 raeburn 7016: if (&Apache::lonnet::privileged($uname,$udom,
7017: [$env{'request.role.domain'}],['dc','su'])) {
7018: unless (&Apache::lonnet::privileged($env{'user.name'},$env{'user.domain'},
7019: [$env{'request.role.domain'}],['dc','su'])) {
7020: $r->print('<p class="LC_warning">'
7021: .&mt('You need to be a privileged user to display user access logs for [_1]',
7022: &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),
7023: $uname,$udom))
7024: .'</p>');
7025: if ($env{'form.popup'}) {
7026: $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a></p>');
7027: } else {
7028: $r->print(&earlyout_accesslog_form($formname,$prevphasestr,$udom));
7029: }
7030: return;
7031: }
7032: }
7033:
1.406.2.5 raeburn 7034: # set defaults
7035: my $now = time();
7036: my $defstart = $now - (7*24*3600);
7037: my %defaults = (
7038: page => '1',
7039: show => '10',
7040: activity => 'any',
7041: accesslog_start_date => $defstart,
7042: accesslog_end_date => $now,
7043: );
7044: my $more_records = 0;
7045:
7046: # set current
7047: my %curr;
7048: foreach my $item ('show','page','activity') {
7049: $curr{$item} = $env{'form.'.$item};
7050: }
7051: my ($startdate,$enddate) =
7052: &Apache::lonuserutils::get_dates_from_form('accesslog_start_date','accesslog_end_date');
7053: $curr{'accesslog_start_date'} = $startdate;
7054: $curr{'accesslog_end_date'} = $enddate;
7055: foreach my $key (keys(%defaults)) {
7056: if ($curr{$key} eq '') {
7057: $curr{$key} = $defaults{$key};
7058: }
7059: }
7060: my ($minshown,$maxshown);
7061: $minshown = 1;
7062: my $count = 0;
7063: if ($curr{'show'} =~ /\D/) {
7064: $curr{'page'} = 1;
7065: } else {
7066: $maxshown = $curr{'page'} * $curr{'show'};
7067: if ($curr{'page'} > 1) {
7068: $minshown = 1 + ($curr{'page'} - 1) * $curr{'show'};
7069: }
7070: }
7071:
7072: # form header
7073: $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">'.
7074: &activity_display_filter($formname,\%curr));
7075:
7076: my $showntableheader = 0;
7077: my ($nav_script,$nav_links);
7078:
7079: # table header
1.406.2.18! raeburn 7080: my $heading = '<h3>'.
1.406.2.12 raeburn 7081: &mt('User access logs for: [_1]',
1.406.2.18! raeburn 7082: &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),$uname,$udom)).'</h3>';
! 7083: my $tableheader = $heading
1.406.2.12 raeburn 7084: .&Apache::loncommon::start_data_table_header_row()
1.406.2.5 raeburn 7085: .'<th> </th>'
7086: .'<th>'.&mt('When').'</th>'
7087: .'<th>'.&mt('HostID').'</th>'
7088: .'<th>'.&mt('Event').'</th>'
7089: .'<th>'.&mt('Other data').'</th>'
7090: .&Apache::loncommon::end_data_table_header_row();
7091:
7092: my %filters=(
7093: start => $curr{'accesslog_start_date'},
7094: end => $curr{'accesslog_end_date'},
7095: action => $curr{'activity'},
7096: );
7097:
7098: my $reply = &Apache::lonnet::userlog_query($uname,$udom,%filters);
7099: unless ( ($reply =~/^timeout/) || ($reply =~/^error/) ) {
7100: my (%courses,%missing);
7101: my @results = split(/\&/,$reply);
7102: foreach my $item (reverse(@results)) {
7103: my ($timestamp,$host,$event) = split(/:/,$item);
7104: next unless ($event =~ /^(Log|Role)/);
7105: if ($curr{'show'} !~ /\D/) {
7106: if ($count >= $curr{'page'} * $curr{'show'}) {
7107: $more_records = 1;
7108: last;
7109: }
7110: }
7111: $count ++;
7112: next if ($count < $minshown);
7113: unless ($showntableheader) {
7114: $r->print($nav_script
7115: .&Apache::loncommon::start_data_table()
7116: .$tableheader);
7117: $r->rflush();
7118: $showntableheader = 1;
7119: }
1.406.2.6 raeburn 7120: my ($shown,$extra);
1.406.2.13 raeburn 7121: my ($event,$data) = split(/\s+/,&unescape($event),2);
1.406.2.5 raeburn 7122: if ($event eq 'Role') {
7123: my ($rolecode,$extent) = split(/\./,$data,2);
7124: next if ($extent eq '');
7125: my ($crstype,$desc,$info);
1.406.2.6 raeburn 7126: if ($extent =~ m{^/($match_domain)/($match_courseid)(?:/(\w+)|)$}) {
7127: my ($cdom,$cnum,$sec) = ($1,$2,$3);
1.406.2.5 raeburn 7128: my $cid = $cdom.'_'.$cnum;
7129: if (exists($courses{$cid})) {
7130: $crstype = $courses{$cid}{'type'};
7131: $desc = $courses{$cid}{'description'};
7132: } elsif ($missing{$cid}) {
7133: $crstype = 'Course';
7134: $desc = 'Course/Community';
7135: } else {
7136: my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',$cnum,undef,undef,'.');
7137: if (ref($crsinfo{$cdom.'_'.$cnum}) eq 'HASH') {
7138: $courses{$cid} = $crsinfo{$cid};
7139: $crstype = $crsinfo{$cid}{'type'};
7140: $desc = $crsinfo{$cid}{'description'};
7141: } else {
7142: $missing{$cid} = 1;
7143: }
7144: }
7145: $extra = &mt($crstype).': <a href="/public/'.$cdom.'/'.$cnum.'/syllabus">'.$desc.'</a>';
1.406.2.6 raeburn 7146: if ($sec ne '') {
7147: $extra .= ' ('.&mt('Section: [_1]',$sec).')';
7148: }
1.406.2.5 raeburn 7149: } elsif ($extent =~ m{^/($match_domain)/($match_username|$)}) {
7150: my ($dom,$name) = ($1,$2);
7151: if ($rolecode eq 'au') {
7152: $extra = '';
7153: } elsif ($rolecode =~ /^(ca|aa)$/) {
7154: $extra = &mt('Authoring Space: [_1]',$name.':'.$dom);
7155: } elsif ($rolecode =~ /^(li|dg|dh|dc|sc)$/) {
7156: $extra = &mt('Domain: [_1]',$dom);
7157: }
7158: }
7159: my $rolename;
7160: if ($rolecode =~ m{^cr/($match_domain)/($match_username)/(\w+)}) {
7161: my $role = $3;
7162: my $owner = "($2:$1)";
7163: if ($2 eq $1.'-domainconfig') {
7164: $owner = '(ad hoc)';
7165: }
7166: $rolename = &mt('Custom role: [_1]',$role.' '.$owner);
7167: } else {
7168: $rolename = &Apache::lonnet::plaintext($rolecode,$crstype);
7169: }
7170: $shown = &mt('Role selection: [_1]',$rolename);
7171: } else {
7172: $shown = &mt($event);
1.406.2.13 raeburn 7173: if ($data =~ /^webdav/) {
7174: my ($path,$clientip) = split(/\s+/,$data,2);
7175: $path =~ s/^webdav//;
7176: if ($clientip ne '') {
7177: $extra = &mt('Client IP address: [_1]',$clientip);
7178: }
7179: if ($path ne '') {
7180: $shown .= ' '.&mt('(WebDAV access to [_1])',$path);
7181: }
7182: } elsif ($data ne '') {
7183: $extra = &mt('Client IP address: [_1]',$data);
1.406.2.5 raeburn 7184: }
7185: }
7186: $r->print(
7187: &Apache::loncommon::start_data_table_row()
7188: .'<td>'.$count.'</td>'
7189: .'<td>'.&Apache::lonlocal::locallocaltime($timestamp).'</td>'
7190: .'<td>'.$host.'</td>'
7191: .'<td>'.$shown.'</td>'
7192: .'<td>'.$extra.'</td>'
7193: .&Apache::loncommon::end_data_table_row()."\n");
7194: }
7195: }
7196:
7197: if ($showntableheader) { # Table footer, if content displayed above
7198: $r->print(&Apache::loncommon::end_data_table().
7199: &userlogdisplay_navlinks(\%curr,$more_records));
7200: } else { # No content displayed above
1.406.2.18! raeburn 7201: $r->print($heading.'<p class="LC_info">'
1.406.2.5 raeburn 7202: .&mt('There are no records to display.')
7203: .'</p>');
7204: }
7205:
1.406.2.8 raeburn 7206: if ($env{'form.popup'} == 1) {
7207: $r->print('<input type="hidden" name="popup" value="1" />'."\n");
7208: }
7209:
1.406.2.5 raeburn 7210: # Form Footer
7211: $r->print(
7212: '<input type="hidden" name="currstate" value="" />'
7213: .'<input type="hidden" name="accessuname" value="'.$uname.'" />'
7214: .'<input type="hidden" name="accessudom" value="'.$udom.'" />'
7215: .'<input type="hidden" name="page" value="'.$curr{'page'}.'" />'
7216: .'<input type="hidden" name="prevphases" value="'.$prevphasestr.'" />'
7217: .'<input type="hidden" name="phase" value="activity" />'
7218: .'<input type="hidden" name="action" value="accesslogs" />'
7219: .'<input type="hidden" name="srchdomain" value="'.$udom.'" />'
7220: .'<input type="hidden" name="srchby" value="'.$env{'form.srchby'}.'" />'
7221: .'<input type="hidden" name="srchtype" value="'.$env{'form.srchtype'}.'" />'
7222: .'<input type="hidden" name="srchterm" value="'.&HTML::Entities::encode($env{'form.srchterm'},'<>"&').'" />'
7223: .'<input type="hidden" name="srchin" value="'.$env{'form.srchin'}.'" />'
7224: .'</form>');
7225: return;
7226: }
7227:
7228: sub earlyout_accesslog_form {
7229: my ($formname,$prevphasestr,$udom) = @_;
7230: my $srchterm = &HTML::Entities::encode($env{'form.srchterm'},'<>"&');
7231: return <<"END";
7232: <form action="/adm/createuser" method="post" name="$formname">
7233: <input type="hidden" name="currstate" value="" />
7234: <input type="hidden" name="prevphases" value="$prevphasestr" />
7235: <input type="hidden" name="phase" value="activity" />
7236: <input type="hidden" name="action" value="accesslogs" />
7237: <input type="hidden" name="srchdomain" value="$udom" />
7238: <input type="hidden" name="srchby" value="$env{'form.srchby'}" />
7239: <input type="hidden" name="srchtype" value="$env{'form.srchtype'}" />
7240: <input type="hidden" name="srchterm" value="$srchterm" />
7241: <input type="hidden" name="srchin" value="$env{'form.srchin'}" />
7242: </form>
7243: END
7244: }
7245:
7246: sub activity_display_filter {
7247: my ($formname,$curr) = @_;
7248: my $nolink = 1;
7249: my $output = '<table><tr><td valign="top">'.
7250: '<span class="LC_nobreak"><b>'.&mt('Actions/page:').'</b></span><br />'.
7251: &Apache::lonmeta::selectbox('show',$curr->{'show'},undef,
7252: (&mt('all'),5,10,20,50,100,1000,10000)).
7253: '</td><td> </td>';
7254: my $startform =
7255: &Apache::lonhtmlcommon::date_setter($formname,'accesslog_start_date',
7256: $curr->{'accesslog_start_date'},undef,
7257: undef,undef,undef,undef,undef,undef,$nolink);
7258: my $endform =
7259: &Apache::lonhtmlcommon::date_setter($formname,'accesslog_end_date',
7260: $curr->{'accesslog_end_date'},undef,
7261: undef,undef,undef,undef,undef,undef,$nolink);
7262: my %lt = &Apache::lonlocal::texthash (
7263: activity => 'Activity',
7264: Role => 'Role selection',
7265: log => 'Log-in or Logout',
7266: );
7267: $output .= '<td valign="top"><b>'.&mt('Window during which actions occurred:').'</b><br />'.
7268: '<table><tr><td>'.&mt('After:').
7269: '</td><td>'.$startform.'</td></tr>'.
7270: '<tr><td>'.&mt('Before:').'</td>'.
7271: '<td>'.$endform.'</td></tr></table>'.
7272: '</td>'.
7273: '<td> </td>'.
7274: '<td valign="top"><b>'.&mt('Activities').'</b><br />'.
7275: '<select name="activity"><option value="any"';
7276: if ($curr->{'activity'} eq 'any') {
7277: $output .= ' selected="selected"';
7278: }
7279: $output .= '>'.&mt('Any').'</option>'."\n";
7280: foreach my $activity ('Role','log') {
7281: my $selstr = '';
7282: if ($activity eq $curr->{'activity'}) {
7283: $selstr = ' selected="selected"';
7284: }
7285: $output .= '<option value="'.$activity.'"'.$selstr.'>'.$lt{$activity}.'</option>';
7286: }
7287: $output .= '</select></td>'.
7288: '</tr></table>';
7289: # Update Display button
7290: $output .= '<p>'
7291: .'<input type="submit" value="'.&mt('Update Display').'" />'
1.406.2.12 raeburn 7292: .'</p><hr />';
1.406.2.5 raeburn 7293: return $output;
7294: }
7295:
7296: sub userlogdisplay_js {
7297: my ($formname) = @_;
7298: return <<"ENDSCRIPT";
7299:
1.239 raeburn 7300: function chgPage(caller) {
7301: if (caller == 'previous') {
7302: document.$formname.page.value --;
7303: }
7304: if (caller == 'next') {
7305: document.$formname.page.value ++;
7306: }
1.327 raeburn 7307: document.$formname.submit();
1.239 raeburn 7308: return;
7309: }
7310: ENDSCRIPT
1.406.2.5 raeburn 7311: }
7312:
7313: sub userlogdisplay_navlinks {
7314: my ($curr,$more_records) = @_;
7315: return unless(ref($curr) eq 'HASH');
7316: # Navigation Buttons
7317: my $nav_links = '<p>';
7318: if (($curr->{'page'} > 1) || ($more_records)) {
7319: if (($curr->{'page'} > 1) && ($curr->{'show'} !~ /\D/)) {
7320: $nav_links .= '<input type="button"'
7321: .' onclick="javascript:chgPage('."'previous'".');"'
7322: .' value="'.&mt('Previous [_1] changes',$curr->{'show'})
7323: .'" /> ';
7324: }
7325: if ($more_records) {
7326: $nav_links .= '<input type="button"'
7327: .' onclick="javascript:chgPage('."'next'".');"'
7328: .' value="'.&mt('Next [_1] changes',$curr->{'show'})
7329: .'" />';
1.301 bisitz 7330: }
7331: }
1.406.2.5 raeburn 7332: $nav_links .= '</p>';
7333: return $nav_links;
1.239 raeburn 7334: }
7335:
7336: sub role_display_filter {
1.363 raeburn 7337: my ($context,$formname,$cdom,$cnum,$curr,$version,$crstype) = @_;
7338: my $lctype;
7339: if ($context eq 'course') {
7340: $lctype = lc($crstype);
7341: }
1.239 raeburn 7342: my $nolink = 1;
7343: my $output = '<table><tr><td valign="top">'.
1.301 bisitz 7344: '<span class="LC_nobreak"><b>'.&mt('Changes/page:').'</b></span><br />'.
1.239 raeburn 7345: &Apache::lonmeta::selectbox('show',$curr->{'show'},undef,
7346: (&mt('all'),5,10,20,50,100,1000,10000)).
7347: '</td><td> </td>';
7348: my $startform =
7349: &Apache::lonhtmlcommon::date_setter($formname,'rolelog_start_date',
7350: $curr->{'rolelog_start_date'},undef,
7351: undef,undef,undef,undef,undef,undef,$nolink);
7352: my $endform =
7353: &Apache::lonhtmlcommon::date_setter($formname,'rolelog_end_date',
7354: $curr->{'rolelog_end_date'},undef,
7355: undef,undef,undef,undef,undef,undef,$nolink);
1.363 raeburn 7356: my %lt = &rolechg_contexts($context,$crstype);
1.301 bisitz 7357: $output .= '<td valign="top"><b>'.&mt('Window during which changes occurred:').'</b><br />'.
7358: '<table><tr><td>'.&mt('After:').
7359: '</td><td>'.$startform.'</td></tr>'.
7360: '<tr><td>'.&mt('Before:').'</td>'.
7361: '<td>'.$endform.'</td></tr></table>'.
7362: '</td>'.
7363: '<td> </td>'.
1.239 raeburn 7364: '<td valign="top"><b>'.&mt('Role:').'</b><br />'.
7365: '<select name="role"><option value="any"';
7366: if ($curr->{'role'} eq 'any') {
7367: $output .= ' selected="selected"';
7368: }
7369: $output .= '>'.&mt('Any').'</option>'."\n";
1.363 raeburn 7370: my @roles = &Apache::lonuserutils::roles_by_context($context,1,$crstype);
1.239 raeburn 7371: foreach my $role (@roles) {
7372: my $plrole;
7373: if ($role eq 'cr') {
7374: $plrole = &mt('Custom Role');
7375: } else {
1.318 raeburn 7376: $plrole=&Apache::lonnet::plaintext($role,$crstype);
1.239 raeburn 7377: }
7378: my $selstr = '';
7379: if ($role eq $curr->{'role'}) {
7380: $selstr = ' selected="selected"';
7381: }
7382: $output .= ' <option value="'.$role.'"'.$selstr.'>'.$plrole.'</option>';
7383: }
1.301 bisitz 7384: $output .= '</select></td>'.
7385: '<td> </td>'.
7386: '<td valign="top"><b>'.
1.239 raeburn 7387: &mt('Context:').'</b><br /><select name="chgcontext">';
1.363 raeburn 7388: my @posscontexts;
7389: if ($context eq 'course') {
1.376 raeburn 7390: @posscontexts = ('any','automated','updatenow','createcourse','course','domain','selfenroll','requestcourses');
1.363 raeburn 7391: } elsif ($context eq 'domain') {
7392: @posscontexts = ('any','domain','requestauthor','domconfig','server');
7393: } else {
7394: @posscontexts = ('any','author','domain');
7395: }
7396: foreach my $chgtype (@posscontexts) {
1.239 raeburn 7397: my $selstr = '';
7398: if ($curr->{'chgcontext'} eq $chgtype) {
1.301 bisitz 7399: $selstr = ' selected="selected"';
1.239 raeburn 7400: }
1.363 raeburn 7401: if ($context eq 'course') {
1.376 raeburn 7402: if (($chgtype eq 'automated') || ($chgtype eq 'updatenow')) {
1.363 raeburn 7403: next if (!&Apache::lonnet::auto_run($cnum,$cdom));
7404: }
1.239 raeburn 7405: }
7406: $output .= '<option value="'.$chgtype.'"'.$selstr.'>'.$lt{$chgtype}.'</option>'."\n";
1.248 raeburn 7407: }
1.303 bisitz 7408: $output .= '</select></td>'
7409: .'</tr></table>';
7410:
7411: # Update Display button
7412: $output .= '<p>'
7413: .'<input type="submit" value="'.&mt('Update Display').'" />'
7414: .'</p>';
7415:
7416: # Server version info
1.363 raeburn 7417: my $needsrev = '2.11.0';
7418: if ($context eq 'course') {
7419: $needsrev = '2.7.0';
7420: }
7421:
1.303 bisitz 7422: $output .= '<p class="LC_info">'
7423: .&mt('Only changes made from servers running LON-CAPA [_1] or later are displayed.'
1.363 raeburn 7424: ,$needsrev);
1.248 raeburn 7425: if ($version) {
1.303 bisitz 7426: $output .= ' '.&mt('This LON-CAPA server is version [_1]',$version);
7427: }
7428: $output .= '</p><hr />';
1.239 raeburn 7429: return $output;
7430: }
7431:
7432: sub rolechg_contexts {
1.363 raeburn 7433: my ($context,$crstype) = @_;
7434: my %lt;
7435: if ($context eq 'course') {
7436: %lt = &Apache::lonlocal::texthash (
1.239 raeburn 7437: any => 'Any',
1.376 raeburn 7438: automated => 'Automated Enrollment',
1.239 raeburn 7439: updatenow => 'Roster Update',
7440: createcourse => 'Course Creation',
7441: course => 'User Management in course',
7442: domain => 'User Management in domain',
1.313 raeburn 7443: selfenroll => 'Self-enrolled',
1.318 raeburn 7444: requestcourses => 'Course Request',
1.239 raeburn 7445: );
1.363 raeburn 7446: if ($crstype eq 'Community') {
7447: $lt{'createcourse'} = &mt('Community Creation');
7448: $lt{'course'} = &mt('User Management in community');
7449: $lt{'requestcourses'} = &mt('Community Request');
7450: }
7451: } elsif ($context eq 'domain') {
7452: %lt = &Apache::lonlocal::texthash (
7453: any => 'Any',
7454: domain => 'User Management in domain',
7455: requestauthor => 'Authoring Request',
7456: server => 'Command line script (DC role)',
7457: domconfig => 'Self-enrolled',
7458: );
7459: } else {
7460: %lt = &Apache::lonlocal::texthash (
7461: any => 'Any',
7462: domain => 'User Management in domain',
7463: author => 'User Management by author',
7464: );
7465: }
1.239 raeburn 7466: return %lt;
7467: }
7468:
1.406.2.10 raeburn 7469: sub print_helpdeskaccess_display {
7470: my ($r,$permission,$brcrum) = @_;
7471: my $formname = 'helpdeskaccess';
7472: my $helpitem = 'Course_Helpdesk_Access';
7473: push (@{$brcrum},
7474: {href => '/adm/createuser?action=helpdesk',
7475: text => 'Helpdesk Access',
7476: help => $helpitem});
7477: my $bread_crumbs_component = 'Helpdesk Staff Access';
7478: my $args = { bread_crumbs => $brcrum,
7479: bread_crumbs_component => $bread_crumbs_component};
7480:
7481: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
7482: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
7483: my $confname = $cdom.'-domainconfig';
7484: my $crstype = &Apache::loncommon::course_type();
7485:
1.406.2.12 raeburn 7486: my @accesstypes = ('all','dh','da','none');
1.406.2.10 raeburn 7487: my ($numstatustypes,@jsarray);
7488: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($cdom);
7489: if (ref($types) eq 'ARRAY') {
7490: if (@{$types} > 0) {
7491: $numstatustypes = scalar(@{$types});
7492: push(@accesstypes,'status');
7493: @jsarray = ('bystatus');
7494: }
7495: }
7496: my %customroles = &get_domain_customroles($cdom,$confname);
1.406.2.12 raeburn 7497: my %domhelpdesk = &Apache::lonnet::get_active_domroles($cdom,['dh','da']);
1.406.2.10 raeburn 7498: if (keys(%domhelpdesk)) {
7499: push(@accesstypes,('inc','exc'));
7500: push(@jsarray,('notinc','notexc'));
7501: }
7502: push(@jsarray,'privs');
7503: my $hiddenstr = join("','",@jsarray);
7504: my $rolestr = join("','",sort(keys(%customroles)));
7505:
7506: my $jscript;
7507: my (%settings,%overridden);
7508: if (keys(%customroles)) {
7509: &get_adhocrole_settings($env{'request.course.id'},\@accesstypes,
7510: $types,\%customroles,\%settings,\%overridden);
7511: my %jsfull=();
7512: my %jslevels= (
7513: course => {},
7514: domain => {},
7515: system => {},
7516: );
7517: my %jslevelscurrent=(
7518: course => {},
7519: domain => {},
7520: system => {},
7521: );
7522: my (%privs,%jsprivs);
7523: &Apache::lonuserutils::custom_role_privs(\%privs,\%jsfull,\%jslevels,\%jslevelscurrent);
7524: foreach my $priv (keys(%jsfull)) {
7525: if ($jslevels{'course'}{$priv}) {
7526: $jsprivs{$priv} = 1;
7527: }
7528: }
7529: my (%elements,%stored);
7530: foreach my $role (keys(%customroles)) {
7531: $elements{$role.'_access'} = 'radio';
7532: $elements{$role.'_incrs'} = 'radio';
7533: if ($numstatustypes) {
7534: $elements{$role.'_status'} = 'checkbox';
7535: }
7536: if (keys(%domhelpdesk) > 0) {
7537: $elements{$role.'_staff_inc'} = 'checkbox';
7538: $elements{$role.'_staff_exc'} = 'checkbox';
7539: }
7540: $elements{$role.'_override'} = 'checkbox';
7541: if (ref($settings{$role}) eq 'HASH') {
7542: if ($settings{$role}{'access'} ne '') {
7543: my $curraccess = $settings{$role}{'access'};
7544: $stored{$role.'_access'} = $curraccess;
7545: $stored{$role.'_incrs'} = 1;
7546: if ($curraccess eq 'status') {
7547: if (ref($settings{$role}{'status'}) eq 'ARRAY') {
7548: $stored{$role.'_status'} = $settings{$role}{'status'};
7549: }
7550: } elsif (($curraccess eq 'exc') || ($curraccess eq 'inc')) {
7551: if (ref($settings{$role}{$curraccess}) eq 'ARRAY') {
7552: $stored{$role.'_staff_'.$curraccess} = $settings{$role}{$curraccess};
7553: }
7554: }
7555: } else {
7556: $stored{$role.'_incrs'} = 0;
7557: }
7558: $stored{$role.'_override'} = [];
7559: if ($env{'course.'.$env{'request.course.id'}.'.internal.adhocpriv.'.$role}) {
7560: if (ref($settings{$role}{'off'}) eq 'ARRAY') {
7561: foreach my $priv (@{$settings{$role}{'off'}}) {
7562: push(@{$stored{$role.'_override'}},$priv);
7563: }
7564: }
7565: if (ref($settings{$role}{'on'}) eq 'ARRAY') {
7566: foreach my $priv (@{$settings{$role}{'on'}}) {
7567: unless (grep(/^$priv$/,@{$stored{$role.'_override'}})) {
7568: push(@{$stored{$role.'_override'}},$priv);
7569: }
7570: }
7571: }
7572: }
7573: } else {
7574: $stored{$role.'_incrs'} = 0;
7575: }
7576: }
7577: $jscript = &Apache::lonhtmlcommon::set_form_elements(\%elements,\%stored);
7578: }
7579:
7580: my $js = <<"ENDJS";
7581: <script type="text/javascript">
7582: // <![CDATA[
7583: $jscript;
7584:
7585: function switchRoleTab(caller,role) {
7586: if (document.getElementById(role+'_maindiv')) {
7587: if (caller.id != 'LC_current_minitab') {
7588: if (document.getElementById('LC_current_minitab')) {
7589: document.getElementById('LC_current_minitab').id=null;
7590: }
7591: var roledivs = Array('$rolestr');
7592: if (roledivs.length > 0) {
7593: for (var i=0; i<roledivs.length; i++) {
7594: if (document.getElementById(roledivs[i]+'_maindiv')) {
7595: document.getElementById(roledivs[i]+'_maindiv').style.display='none';
7596: }
7597: }
7598: }
7599: caller.id = 'LC_current_minitab';
7600: document.getElementById(role+'_maindiv').style.display='block';
7601: }
7602: }
7603: return false;
7604: }
7605:
7606: function helpdeskAccess(role) {
7607: var curraccess = null;
7608: if (document.$formname.elements[role+'_access'].length) {
7609: for (var i=0; i<document.$formname.elements[role+'_access'].length; i++) {
7610: if (document.$formname.elements[role+'_access'][i].checked) {
7611: curraccess = document.$formname.elements[role+'_access'][i].value;
7612: }
7613: }
7614: }
7615: var shown = Array();
7616: var hidden = Array();
7617: if (curraccess == 'none') {
7618: hidden = Array ('$hiddenstr');
7619: } else {
7620: if (curraccess == 'status') {
7621: shown = Array ('bystatus','privs');
7622: hidden = Array ('notinc','notexc');
7623: } else {
7624: if (curraccess == 'exc') {
7625: shown = Array ('notexc','privs');
7626: hidden = Array ('notinc','bystatus');
7627: }
7628: if (curraccess == 'inc') {
7629: shown = Array ('notinc','privs');
7630: hidden = Array ('notexc','bystatus');
7631: }
7632: if (curraccess == 'all') {
7633: shown = Array ('privs');
7634: hidden = Array ('notinc','notexc','bystatus');
7635: }
7636: }
7637: }
7638: if (hidden.length > 0) {
7639: for (var i=0; i<hidden.length; i++) {
7640: if (document.getElementById(role+'_'+hidden[i])) {
7641: document.getElementById(role+'_'+hidden[i]).style.display = 'none';
7642: }
7643: }
7644: }
7645: if (shown.length > 0) {
7646: for (var i=0; i<shown.length; i++) {
7647: if (document.getElementById(role+'_'+shown[i])) {
7648: if (shown[i] == 'privs') {
7649: document.getElementById(role+'_'+shown[i]).style.display = 'block';
7650: } else {
7651: document.getElementById(role+'_'+shown[i]).style.display = 'inline';
7652: }
7653: }
7654: }
7655: }
7656: return;
7657: }
7658:
7659: function toggleAccess(role) {
7660: if ((document.getElementById(role+'_setincrs')) &&
7661: (document.getElementById(role+'_setindom'))) {
7662: for (var i=0; i<document.$formname.elements[role+'_incrs'].length; i++) {
7663: if (document.$formname.elements[role+'_incrs'][i].checked) {
7664: if (document.$formname.elements[role+'_incrs'][i].value == 1) {
7665: document.getElementById(role+'_setindom').style.display = 'none';
7666: document.getElementById(role+'_setincrs').style.display = 'block';
7667: } else {
7668: document.getElementById(role+'_setincrs').style.display = 'none';
7669: document.getElementById(role+'_setindom').style.display = 'block';
7670: }
7671: break;
7672: }
7673: }
7674: }
7675: return;
7676: }
7677:
7678: // ]]>
7679: </script>
7680: ENDJS
7681:
7682: $args->{add_entries} = {onload => "javascript:setFormElements(document.$formname)"};
7683:
7684: # print page header
7685: $r->print(&header($js,$args));
7686: # print form header
7687: $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">');
7688:
7689: if (keys(%customroles)) {
7690: my %lt = &Apache::lonlocal::texthash(
7691: 'aco' => 'As course owner you may override the defaults set in the domain for role usage and/or privileges.',
7692: 'rou' => 'Role usage',
7693: 'whi' => 'Which helpdesk personnel may use this role?',
7694: 'udd' => 'Use domain default',
1.406.2.12 raeburn 7695: 'all' => 'All with domain helpdesk or helpdesk assistant role',
7696: 'dh' => 'All with domain helpdesk role',
7697: 'da' => 'All with domain helpdesk assistant role',
1.406.2.10 raeburn 7698: 'none' => 'None',
7699: 'status' => 'Determined based on institutional status',
7700: 'inc' => 'Include all, but exclude specific personnel',
7701: 'exc' => 'Exclude all, but include specific personnel',
7702: 'hel' => 'Helpdesk',
7703: 'rpr' => 'Role privileges',
7704: );
7705: $lt{'tfh'} = &mt("Custom [_1]ad hoc[_2] course roles available for use by the domain's helpdesk are as follows",'<i>','</i>');
7706: my %domconfig = &Apache::lonnet::get_dom('configuration',['helpsettings'],$cdom);
7707: my (%domcurrent,%ordered,%description,%domusage,$disabled);
7708: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
7709: if (ref($domconfig{'helpsettings'}{'adhoc'}) eq 'HASH') {
7710: %domcurrent = %{$domconfig{'helpsettings'}{'adhoc'}};
7711: }
7712: }
7713: my $count = 0;
7714: foreach my $role (sort(keys(%customroles))) {
7715: my ($order,$desc,$access_in_dom);
7716: if (ref($domcurrent{$role}) eq 'HASH') {
7717: $order = $domcurrent{$role}{'order'};
7718: $desc = $domcurrent{$role}{'desc'};
7719: $access_in_dom = $domcurrent{$role}{'access'};
7720: }
7721: if ($order eq '') {
7722: $order = $count;
7723: }
7724: $ordered{$order} = $role;
7725: if ($desc ne '') {
7726: $description{$role} = $desc;
7727: } else {
7728: $description{$role}= $role;
7729: }
7730: $count++;
7731: }
7732: %domusage = &domain_adhoc_access(\%customroles,\%domcurrent,\@accesstypes,$usertypes,$othertitle);
7733: my @roles_by_num = ();
7734: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
7735: push(@roles_by_num,$ordered{$item});
7736: }
7737: $r->print('<p>'.$lt{'tfh'}.': <i>'.join('</i>, <i>',map { $description{$_}; } @roles_by_num).'</i>.');
7738: if ($permission->{'owner'}) {
7739: $r->print('<br />'.$lt{'aco'}.'</p><p>');
7740: $r->print('<input type="hidden" name="state" value="process" />'.
7741: '<input type="submit" value="'.&mt('Save changes').'" />');
7742: } else {
7743: if ($env{'course.'.$env{'request.course.id'}.'.internal.courseowner'}) {
7744: my ($ownername,$ownerdom) = split(/:/,$env{'course.'.$env{'request.course.id'}.'.internal.courseowner'});
7745: $r->print('<br />'.&mt('The course owner -- [_1] -- can override the default access and/or privileges for these ad hoc roles.',
7746: &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($ownername,$ownerdom),$ownername,$ownerdom)));
7747: }
7748: $disabled = ' disabled="disabled"';
7749: }
7750: $r->print('</p>');
7751:
7752: $r->print('<div id="LC_minitab_header"><ul>');
7753: my $count = 0;
7754: my %visibility;
7755: foreach my $role (@roles_by_num) {
7756: my $id;
7757: if ($count == 0) {
7758: $id=' id="LC_current_minitab"';
7759: $visibility{$role} = ' style="display:block"';
7760: } else {
7761: $visibility{$role} = ' style="display:none"';
7762: }
7763: $count ++;
7764: $r->print('<li'.$id.'><a href="#" onclick="javascript:switchRoleTab(this.parentNode,'."'$role'".');">'.$description{$role}.'</a></li>');
7765: }
7766: $r->print('</ul></div>');
7767:
7768: foreach my $role (@roles_by_num) {
7769: my %usecheck = (
7770: all => ' checked="checked"',
7771: );
7772: my %displaydiv = (
7773: status => 'none',
7774: inc => 'none',
7775: exc => 'none',
7776: priv => 'block',
7777: );
7778: my (%selected,$overridden,$incrscheck,$indomcheck,$indomvis,$incrsvis);
7779: if (ref($settings{$role}) eq 'HASH') {
7780: if ($settings{$role}{'access'} ne '') {
7781: $indomvis = ' style="display:none"';
7782: $incrsvis = ' style="display:block"';
7783: $incrscheck = ' checked="checked"';
7784: if ($settings{$role}{'access'} ne 'all') {
7785: $usecheck{$settings{$role}{'access'}} = $usecheck{'all'};
7786: delete($usecheck{'all'});
7787: if ($settings{$role}{'access'} eq 'status') {
7788: my $access = 'status';
7789: $displaydiv{$access} = 'inline';
7790: if (ref($settings{$role}{$access}) eq 'ARRAY') {
7791: $selected{$access} = $settings{$role}{$access};
7792: }
7793: } elsif ($settings{$role}{'access'} =~ /^(inc|exc)$/) {
7794: my $access = $1;
7795: $displaydiv{$access} = 'inline';
7796: if (ref($settings{$role}{$access}) eq 'ARRAY') {
7797: $selected{$access} = $settings{$role}{$access};
7798: }
7799: } elsif ($settings{$role}{'access'} eq 'none') {
7800: $displaydiv{'priv'} = 'none';
7801: }
7802: }
7803: } else {
7804: $indomcheck = ' checked="checked"';
7805: $indomvis = ' style="display:block"';
7806: $incrsvis = ' style="display:none"';
7807: }
7808: } else {
7809: $indomcheck = ' checked="checked"';
7810: $indomvis = ' style="display:block"';
7811: $incrsvis = ' style="display:none"';
7812: }
7813: $r->print('<div class="LC_left_float" id="'.$role.'_maindiv"'.$visibility{$role}.'>'.
7814: '<fieldset><legend>'.$lt{'rou'}.'</legend>'.
7815: '<p>'.$lt{'whi'}.' <span class="LC_nobreak">'.
7816: '<label><input type="radio" name="'.$role.'_incrs" value="1"'.$incrscheck.' onclick="toggleAccess('."'$role'".');"'.$disabled.'>'.
7817: &mt('Set here in [_1]',lc($crstype)).'</label>'.
7818: '<span>'.(' 'x2).
7819: '<label><input type="radio" name="'.$role.'_incrs" value="0"'.$indomcheck.' onclick="toggleAccess('."'$role'".');"'.$disabled.'>'.
7820: $lt{'udd'}.'</label><span></p>'.
7821: '<div id="'.$role.'_setindom"'.$indomvis.'>'.
7822: '<span class="LC_cusr_emph">'.$domusage{$role}.'</span></div>'.
7823: '<div id="'.$role.'_setincrs"'.$incrsvis.'>');
7824: foreach my $access (@accesstypes) {
7825: $r->print('<p><label><input type="radio" name="'.$role.'_access" value="'.$access.'" '.$usecheck{$access}.
7826: ' onclick="helpdeskAccess('."'$role'".');"'.$disabled.' />'.$lt{$access}.'</label>');
7827: if ($access eq 'status') {
7828: $r->print('<div id="'.$role.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
7829: &Apache::lonuserutils::adhoc_status_types($cdom,undef,$role,$selected{$access},
7830: $othertitle,$usertypes,$types,$disabled).
7831: '</div>');
7832: } elsif (($access eq 'inc') && (keys(%domhelpdesk) > 0)) {
7833: $r->print('<div id="'.$role.'_notinc" style="display:'.$displaydiv{$access}.'">'.
7834: &Apache::lonuserutils::adhoc_staff($access,undef,$role,$selected{$access},
7835: \%domhelpdesk,$disabled).
7836: '</div>');
7837: } elsif (($access eq 'exc') && (keys(%domhelpdesk) > 0)) {
7838: $r->print('<div id="'.$role.'_notexc" style="display:'.$displaydiv{$access}.'">'.
7839: &Apache::lonuserutils::adhoc_staff($access,undef,$role,$selected{$access},
7840: \%domhelpdesk,$disabled).
7841: '</div>');
7842: }
7843: $r->print('</p>');
7844: }
7845: $r->print('</div></fieldset>');
7846: my %full=();
7847: my %levels= (
7848: course => {},
7849: domain => {},
7850: system => {},
7851: );
7852: my %levelscurrent=(
7853: course => {},
7854: domain => {},
7855: system => {},
7856: );
7857: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
7858: $r->print('<fieldset id="'.$role.'_privs" style="display:'.$displaydiv{'priv'}.'">'.
7859: '<legend>'.$lt{'rpr'}.'</legend>'.
7860: &role_priv_table($role,$permission,$crstype,\%full,\%levels,\%levelscurrent,$overridden{$role}).
7861: '</fieldset></div><div style="padding:0;clear:both;margin:0;border:0"></div>');
7862: }
7863: if ($permission->{'owner'}) {
7864: $r->print('<p><input type="submit" value="'.&mt('Save changes').'" /></p>');
7865: }
7866: } else {
7867: $r->print(&mt('Helpdesk roles have not yet been created in this domain.'));
7868: }
7869: # Form Footer
7870: $r->print('<input type="hidden" name="action" value="helpdesk" />'
7871: .'</form>');
7872: return;
7873: }
7874:
7875: sub domain_adhoc_access {
7876: my ($roles,$domcurrent,$accesstypes,$usertypes,$othertitle) = @_;
7877: my %domusage;
7878: return unless ((ref($roles) eq 'HASH') && (ref($domcurrent) eq 'HASH') && (ref($accesstypes) eq 'ARRAY'));
7879: foreach my $role (keys(%{$roles})) {
7880: if (ref($domcurrent->{$role}) eq 'HASH') {
7881: my $access = $domcurrent->{$role}{'access'};
7882: if (($access eq '') || (!grep(/^\Q$access\E$/,@{$accesstypes}))) {
7883: $access = 'all';
1.406.2.12 raeburn 7884: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role',&Apache::lonnet::plaintext('dh'),
7885: &Apache::lonnet::plaintext('da'));
1.406.2.10 raeburn 7886: } elsif ($access eq 'status') {
7887: if (ref($domcurrent->{$role}{$access}) eq 'ARRAY') {
7888: my @shown;
7889: foreach my $type (@{$domcurrent->{$role}{$access}}) {
7890: unless ($type eq 'default') {
7891: if ($usertypes->{$type}) {
7892: push(@shown,$usertypes->{$type});
7893: }
7894: }
7895: }
7896: if (grep(/^default$/,@{$domcurrent->{$role}{$access}})) {
7897: push(@shown,$othertitle);
7898: }
7899: if (@shown) {
7900: my $shownstatus = join(' '.&mt('or').' ',@shown);
1.406.2.12 raeburn 7901: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role, and institutional status: [_3]',
7902: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'),$shownstatus);
1.406.2.10 raeburn 7903: } else {
7904: $domusage{$role} = &mt('No one in the domain');
7905: }
7906: }
7907: } elsif ($access eq 'inc') {
7908: my @dominc = ();
7909: if (ref($domcurrent->{$role}{'inc'}) eq 'ARRAY') {
7910: foreach my $user (@{$domcurrent->{$role}{'inc'}}) {
7911: my ($uname,$udom) = split(/:/,$user);
7912: push(@dominc,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),$uname,$udom));
7913: }
7914: my $showninc = join(', ',@dominc);
7915: if ($showninc ne '') {
1.406.2.12 raeburn 7916: $domusage{$role} = &mt('Include any user in domain with active [_1] or [_2] role, except: [_3]',
7917: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'),$showninc);
1.406.2.10 raeburn 7918: } else {
1.406.2.12 raeburn 7919: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role',
7920: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'));
1.406.2.10 raeburn 7921: }
7922: }
7923: } elsif ($access eq 'exc') {
7924: my @domexc = ();
7925: if (ref($domcurrent->{$role}{'exc'}) eq 'ARRAY') {
7926: foreach my $user (@{$domcurrent->{$role}{'exc'}}) {
7927: my ($uname,$udom) = split(/:/,$user);
7928: push(@domexc,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),$uname,$udom));
7929: }
7930: }
7931: my $shownexc = join(', ',@domexc);
7932: if ($shownexc ne '') {
1.406.2.12 raeburn 7933: $domusage{$role} = &mt('Only the following in the domain with active [_1] or [_2] role: [_3]',
7934: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'),$shownexc);
1.406.2.10 raeburn 7935: } else {
7936: $domusage{$role} = &mt('No one in the domain');
7937: }
7938: } elsif ($access eq 'none') {
7939: $domusage{$role} = &mt('No one in the domain');
1.406.2.12 raeburn 7940: } elsif ($access eq 'dh') {
1.406.2.10 raeburn 7941: $domusage{$role} = &mt('Any user in domain with active [_1] role',&Apache::lonnet::plaintext('dh'));
1.406.2.12 raeburn 7942: } elsif ($access eq 'da') {
7943: $domusage{$role} = &mt('Any user in domain with active [_1] role',&Apache::lonnet::plaintext('da'));
7944: } elsif ($access eq 'all') {
7945: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role',
7946: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'));
1.406.2.10 raeburn 7947: }
7948: } else {
1.406.2.12 raeburn 7949: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role',
7950: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'));
1.406.2.10 raeburn 7951: }
7952: }
7953: return %domusage;
7954: }
7955:
7956: sub get_domain_customroles {
7957: my ($cdom,$confname) = @_;
7958: my %existing=&Apache::lonnet::dump('roles',$cdom,$confname,'rolesdef_');
7959: my %customroles;
7960: foreach my $key (keys(%existing)) {
7961: if ($key=~/^rolesdef\_(\w+)$/) {
7962: my $rolename = $1;
7963: my %privs;
7964: ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
7965: $customroles{$rolename} = \%privs;
7966: }
7967: }
7968: return %customroles;
7969: }
7970:
7971: sub role_priv_table {
7972: my ($role,$permission,$crstype,$full,$levels,$levelscurrent,$overridden) = @_;
7973: return unless ((ref($full) eq 'HASH') && (ref($levels) eq 'HASH') &&
7974: (ref($levelscurrent) eq 'HASH'));
7975: my %lt=&Apache::lonlocal::texthash (
7976: 'crl' => 'Course Level Privilege',
7977: 'def' => 'Domain Defaults',
7978: 'ove' => 'Override in Course',
7979: 'ine' => 'In effect',
7980: 'dis' => 'Disabled',
7981: 'ena' => 'Enabled',
7982: );
7983: if ($crstype eq 'Community') {
7984: $lt{'ove'} = 'Override in Community',
7985: }
7986: my @status = ('Disabled','Enabled');
7987: my (%on,%off);
7988: if (ref($overridden) eq 'HASH') {
7989: if (ref($overridden->{'on'}) eq 'ARRAY') {
7990: map { $on{$_} = 1; } (@{$overridden->{'on'}});
7991: }
7992: if (ref($overridden->{'off'}) eq 'ARRAY') {
7993: map { $off{$_} = 1; } (@{$overridden->{'off'}});
7994: }
7995: }
7996: my $output=&Apache::loncommon::start_data_table().
7997: &Apache::loncommon::start_data_table_header_row().
7998: '<th>'.$lt{'crl'}.'</th><th>'.$lt{'def'}.'</th><th>'.$lt{'ove'}.
7999: '</th><th>'.$lt{'ine'}.'</th>'.
8000: &Apache::loncommon::end_data_table_header_row();
8001: foreach my $priv (sort(keys(%{$full}))) {
8002: next unless ($levels->{'course'}{$priv});
8003: my $privtext = &Apache::lonnet::plaintext($priv,$crstype);
8004: my ($default,$ineffect);
8005: if ($levelscurrent->{'course'}{$priv}) {
8006: $default = '<img src="/adm/lonIcons/navmap.correct.gif" alt="'.$lt{'ena'}.'" />';
8007: $ineffect = $default;
8008: }
8009: my ($customstatus,$checked);
8010: $output .= &Apache::loncommon::start_data_table_row().
8011: '<td>'.$privtext.'</td>'.
8012: '<td>'.$default.'</td><td>';
8013: if (($levelscurrent->{'course'}{$priv}) && ($off{$priv})) {
8014: if ($permission->{'owner'}) {
8015: $checked = ' checked="checked"';
8016: }
8017: $customstatus = '<img src="/adm/lonIcons/navmap.wrong.gif" alt="'.$lt{'dis'}.'" />';
8018: $ineffect = $customstatus;
8019: } elsif ((!$levelscurrent->{'course'}{$priv}) && ($on{$priv})) {
8020: if ($permission->{'owner'}) {
8021: $checked = ' checked="checked"';
8022: }
8023: $customstatus = '<img src="/adm/lonIcons/navmap.correct.gif" alt="'.$lt{'ena'}.'" />';
8024: $ineffect = $customstatus;
8025: }
8026: if ($permission->{'owner'}) {
8027: $output .= '<input type="checkbox" name="'.$role.'_override" value="'.$priv.'"'.$checked.' />';
8028: } else {
8029: $output .= $customstatus;
8030: }
8031: $output .= '</td><td>'.$ineffect.'</td>'.
8032: &Apache::loncommon::end_data_table_row();
8033: }
8034: $output .= &Apache::loncommon::end_data_table();
8035: return $output;
8036: }
8037:
8038: sub get_adhocrole_settings {
8039: my ($cid,$accesstypes,$types,$customroles,$settings,$overridden) = @_;
8040: return unless ((ref($accesstypes) eq 'ARRAY') && (ref($customroles) eq 'HASH') &&
8041: (ref($settings) eq 'HASH') && (ref($overridden) eq 'HASH'));
8042: foreach my $role (split(/,/,$env{'course.'.$cid.'.internal.adhocaccess'})) {
8043: my ($curraccess,$rest) = split(/=/,$env{'course.'.$cid.'.internal.adhoc.'.$role});
8044: if (($curraccess ne '') && (grep(/^\Q$curraccess\E$/,@{$accesstypes}))) {
8045: $settings->{$role}{'access'} = $curraccess;
8046: if (($curraccess eq 'status') && (ref($types) eq 'ARRAY')) {
8047: my @status = split(/,/,$rest);
8048: my @currstatus;
8049: foreach my $type (@status) {
8050: if ($type eq 'default') {
8051: push(@currstatus,$type);
8052: } elsif (grep(/^\Q$type\E$/,@{$types})) {
8053: push(@currstatus,$type);
8054: }
8055: }
8056: if (@currstatus) {
8057: $settings->{$role}{$curraccess} = \@currstatus;
8058: } elsif (($curraccess eq 'exc') || ($curraccess eq 'inc')) {
8059: my @personnel = split(/,/,$rest);
8060: $settings->{$role}{$curraccess} = \@personnel;
8061: }
8062: }
8063: }
8064: }
8065: foreach my $role (keys(%{$customroles})) {
8066: if ($env{'course.'.$cid.'.internal.adhocpriv.'.$role}) {
8067: my %currentprivs;
8068: if (ref($customroles->{$role}) eq 'HASH') {
8069: if (exists($customroles->{$role}{'course'})) {
8070: my %full=();
8071: my %levels= (
8072: course => {},
8073: domain => {},
8074: system => {},
8075: );
8076: my %levelscurrent=(
8077: course => {},
8078: domain => {},
8079: system => {},
8080: );
8081: &Apache::lonuserutils::custom_role_privs($customroles->{$role},\%full,\%levels,\%levelscurrent);
8082: %currentprivs = %{$levelscurrent{'course'}};
8083: }
8084: }
8085: foreach my $item (split(/,/,$env{'course.'.$cid.'.internal.adhocpriv.'.$role})) {
8086: next if ($item eq '');
8087: my ($rule,$rest) = split(/=/,$item);
8088: next unless (($rule eq 'off') || ($rule eq 'on'));
8089: foreach my $priv (split(/:/,$rest)) {
8090: if ($priv ne '') {
8091: if ($rule eq 'off') {
8092: push(@{$overridden->{$role}{'off'}},$priv);
8093: if ($currentprivs{$priv}) {
8094: push(@{$settings->{$role}{'off'}},$priv);
8095: }
8096: } else {
8097: push(@{$overridden->{$role}{'on'}},$priv);
8098: unless ($currentprivs{$priv}) {
8099: push(@{$settings->{$role}{'on'}},$priv);
8100: }
8101: }
8102: }
8103: }
8104: }
8105: }
8106: }
8107: return;
8108: }
8109:
8110: sub update_helpdeskaccess {
8111: my ($r,$permission,$brcrum) = @_;
8112: my $helpitem = 'Course_Helpdesk_Access';
8113: push (@{$brcrum},
8114: {href => '/adm/createuser?action=helpdesk',
8115: text => 'Helpdesk Access',
8116: help => $helpitem},
8117: {href => '/adm/createuser?action=helpdesk',
8118: text => 'Result',
8119: help => $helpitem}
8120: );
8121: my $bread_crumbs_component = 'Helpdesk Staff Access';
8122: my $args = { bread_crumbs => $brcrum,
8123: bread_crumbs_component => $bread_crumbs_component};
8124:
8125: # print page header
8126: $r->print(&header('',$args));
8127: unless ((ref($permission) eq 'HASH') && ($permission->{'owner'})) {
8128: $r->print('<p class="LC_error">'.&mt('You do not have permission to change helpdesk access.').'</p>');
8129: return;
8130: }
1.406.2.12 raeburn 8131: my @accesstypes = ('all','dh','da','none','status','inc','exc');
1.406.2.10 raeburn 8132: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
8133: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
8134: my $confname = $cdom.'-domainconfig';
8135: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($cdom);
8136: my $crstype = &Apache::loncommon::course_type();
8137: my %customroles = &get_domain_customroles($cdom,$confname);
8138: my (%settings,%overridden);
8139: &get_adhocrole_settings($env{'request.course.id'},\@accesstypes,
8140: $types,\%customroles,\%settings,\%overridden);
1.406.2.12 raeburn 8141: my %domhelpdesk = &Apache::lonnet::get_active_domroles($cdom,['dh','da']);
1.406.2.10 raeburn 8142: my (%changed,%storehash,@todelete);
8143:
8144: if (keys(%customroles)) {
8145: my (%newsettings,@incrs);
8146: foreach my $role (keys(%customroles)) {
8147: $newsettings{$role} = {
8148: access => '',
8149: status => '',
8150: exc => '',
8151: inc => '',
8152: on => '',
8153: off => '',
8154: };
8155: my %current;
8156: if (ref($settings{$role}) eq 'HASH') {
8157: %current = %{$settings{$role}};
8158: }
8159: if (ref($overridden{$role}) eq 'HASH') {
8160: $current{'overridden'} = $overridden{$role};
8161: }
8162: if ($env{'form.'.$role.'_incrs'}) {
8163: my $access = $env{'form.'.$role.'_access'};
8164: if (grep(/^\Q$access\E$/,@accesstypes)) {
8165: push(@incrs,$role);
8166: unless ($current{'access'} eq $access) {
8167: $changed{$role}{'access'} = 1;
8168: $storehash{'internal.adhoc.'.$role} = $access;
8169: }
8170: if ($access eq 'status') {
8171: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$role.'_status');
8172: my @stored;
8173: my @shownstatus;
8174: if (ref($types) eq 'ARRAY') {
8175: foreach my $type (sort(@statuses)) {
8176: if ($type eq 'default') {
8177: push(@stored,$type);
8178: } elsif (grep(/^\Q$type\E$/,@{$types})) {
8179: push(@stored,$type);
8180: push(@shownstatus,$usertypes->{$type});
8181: }
8182: }
8183: if (grep(/^default$/,@statuses)) {
8184: push(@shownstatus,$othertitle);
8185: }
8186: $storehash{'internal.adhoc.'.$role} .= '='.join(',',@stored);
8187: }
8188: $newsettings{$role}{'status'} = join(' '.&mt('or').' ',@shownstatus);
8189: if (ref($current{'status'}) eq 'ARRAY') {
8190: my @diffs = &Apache::loncommon::compare_arrays(\@stored,$current{'status'});
8191: if (@diffs) {
8192: $changed{$role}{'status'} = 1;
8193: }
8194: } elsif (@stored) {
8195: $changed{$role}{'status'} = 1;
8196: }
8197: } elsif (($access eq 'inc') || ($access eq 'exc')) {
8198: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$role.'_staff_'.$access);
8199: my @newspecstaff;
8200: my @stored;
8201: my @currstaff;
8202: foreach my $person (sort(@personnel)) {
8203: if ($domhelpdesk{$person}) {
8204: push(@stored,$person);
8205: }
8206: }
8207: if (ref($current{$access}) eq 'ARRAY') {
8208: my @diffs = &Apache::loncommon::compare_arrays(\@stored,$current{$access});
8209: if (@diffs) {
8210: $changed{$role}{$access} = 1;
8211: }
8212: } elsif (@stored) {
8213: $changed{$role}{$access} = 1;
8214: }
8215: $storehash{'internal.adhoc.'.$role} .= '='.join(',',@stored);
8216: foreach my $person (@stored) {
8217: my ($uname,$udom) = split(/:/,$person);
8218: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
8219: }
8220: $newsettings{$role}{$access} = join(', ',sort(@newspecstaff));
8221: }
8222: $newsettings{$role}{'access'} = $access;
8223: }
8224: } else {
8225: if (($current{'access'} ne '') && (grep(/^\Q$current{'access'}\E$/,@accesstypes))) {
8226: $changed{$role}{'access'} = 1;
8227: $newsettings{$role} = {};
8228: push(@todelete,'internal.adhoc.'.$role);
8229: }
8230: }
8231: if (($env{'form.'.$role.'_incrs'}) && ($env{'form.'.$role.'_access'} eq 'none')) {
8232: if (ref($current{'overridden'}) eq 'HASH') {
8233: push(@todelete,'internal.adhocpriv.'.$role);
8234: }
8235: } else {
8236: my %full=();
8237: my %levels= (
8238: course => {},
8239: domain => {},
8240: system => {},
8241: );
8242: my %levelscurrent=(
8243: course => {},
8244: domain => {},
8245: system => {},
8246: );
8247: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
8248: my (@updatedon,@updatedoff,@override);
8249: @override = &Apache::loncommon::get_env_multiple('form.'.$role.'_override');
8250: if (@override) {
8251: foreach my $priv (sort(keys(%full))) {
8252: next unless ($levels{'course'}{$priv});
8253: if (grep(/^\Q$priv\E$/,@override)) {
8254: if ($levelscurrent{'course'}{$priv}) {
8255: push(@updatedoff,$priv);
8256: } else {
8257: push(@updatedon,$priv);
8258: }
8259: }
8260: }
8261: }
8262: if (@updatedon) {
8263: $newsettings{$role}{'on'} = join('</li><li>', map { &Apache::lonnet::plaintext($_,$crstype) } (@updatedon));
8264: }
8265: if (@updatedoff) {
8266: $newsettings{$role}{'off'} = join('</li><li>', map { &Apache::lonnet::plaintext($_,$crstype) } (@updatedoff));
8267: }
8268: if (ref($current{'overridden'}) eq 'HASH') {
8269: if (ref($current{'overridden'}{'on'}) eq 'ARRAY') {
8270: if (@updatedon) {
8271: my @diffs = &Apache::loncommon::compare_arrays(\@updatedon,$current{'overridden'}{'on'});
8272: if (@diffs) {
8273: $changed{$role}{'on'} = 1;
8274: }
8275: } else {
8276: $changed{$role}{'on'} = 1;
8277: }
8278: } elsif (@updatedon) {
8279: $changed{$role}{'on'} = 1;
8280: }
8281: if (ref($current{'overridden'}{'off'}) eq 'ARRAY') {
8282: if (@updatedoff) {
8283: my @diffs = &Apache::loncommon::compare_arrays(\@updatedoff,$current{'overridden'}{'off'});
8284: if (@diffs) {
8285: $changed{$role}{'off'} = 1;
8286: }
8287: } else {
8288: $changed{$role}{'off'} = 1;
8289: }
8290: } elsif (@updatedoff) {
8291: $changed{$role}{'off'} = 1;
8292: }
8293: } else {
8294: if (@updatedon) {
8295: $changed{$role}{'on'} = 1;
8296: }
8297: if (@updatedoff) {
8298: $changed{$role}{'off'} = 1;
8299: }
8300: }
8301: if (ref($changed{$role}) eq 'HASH') {
8302: if (($changed{$role}{'on'} || $changed{$role}{'off'})) {
8303: my $newpriv;
8304: if (@updatedon) {
8305: $newpriv = 'on='.join(':',@updatedon);
8306: }
8307: if (@updatedoff) {
8308: $newpriv .= ($newpriv ? ',' : '' ).'off='.join(':',@updatedoff);
8309: }
8310: if ($newpriv eq '') {
8311: push(@todelete,'internal.adhocpriv.'.$role);
8312: } else {
8313: $storehash{'internal.adhocpriv.'.$role} = $newpriv;
8314: }
8315: }
8316: }
8317: }
8318: }
8319: if (@incrs) {
8320: $storehash{'internal.adhocaccess'} = join(',',@incrs);
8321: } elsif (@todelete) {
8322: push(@todelete,'internal.adhocaccess');
8323: }
8324: if (keys(%changed)) {
8325: my ($putres,$delres);
8326: if (keys(%storehash)) {
8327: $putres = &Apache::lonnet::put('environment',\%storehash,$cdom,$cnum);
8328: my %newenvhash;
8329: foreach my $key (keys(%storehash)) {
8330: $newenvhash{'course.'.$env{'request.course.id'}.'.'.$key} = $storehash{$key};
8331: }
8332: &Apache::lonnet::appenv(\%newenvhash);
8333: }
8334: if (@todelete) {
8335: $delres = &Apache::lonnet::del('environment',\@todelete,$cdom,$cnum);
8336: foreach my $key (@todelete) {
8337: &Apache::lonnet::delenv('course.'.$env{'request.course.id'}.'.'.$key);
8338: }
8339: }
8340: if (($putres eq 'ok') || ($delres eq 'ok')) {
8341: my %domconfig = &Apache::lonnet::get_dom('configuration',['helpsettings'],$cdom);
8342: my (%domcurrent,%ordered,%description,%domusage);
8343: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
8344: if (ref($domconfig{'helpsettings'}{'adhoc'}) eq 'HASH') {
8345: %domcurrent = %{$domconfig{'helpsettings'}{'adhoc'}};
8346: }
8347: }
8348: my $count = 0;
8349: foreach my $role (sort(keys(%customroles))) {
8350: my ($order,$desc);
8351: if (ref($domcurrent{$role}) eq 'HASH') {
8352: $order = $domcurrent{$role}{'order'};
8353: $desc = $domcurrent{$role}{'desc'};
8354: }
8355: if ($order eq '') {
8356: $order = $count;
8357: }
8358: $ordered{$order} = $role;
8359: if ($desc ne '') {
8360: $description{$role} = $desc;
8361: } else {
8362: $description{$role}= $role;
8363: }
8364: $count++;
8365: }
8366: my @roles_by_num = ();
8367: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
8368: push(@roles_by_num,$ordered{$item});
8369: }
8370: %domusage = &domain_adhoc_access(\%changed,\%domcurrent,\@accesstypes,$usertypes,$othertitle);
8371: $r->print(&mt('Helpdesk access settings have been changed as follows').'<br />');
8372: $r->print('<ul>');
8373: foreach my $role (@roles_by_num) {
8374: next unless (ref($changed{$role}) eq 'HASH');
8375: $r->print('<li>'.&mt('Ad hoc role').': <b>'.$description{$role}.'</b>'.
8376: '<ul>');
8377: if ($changed{$role}{'access'} || $changed{$role}{'status'} || $changed{$role}{'inc'} || $changed{$role}{'exc'}) {
8378: $r->print('<li>');
8379: if ($env{'form.'.$role.'_incrs'}) {
8380: if ($newsettings{$role}{'access'} eq 'all') {
8381: $r->print(&mt('All helpdesk staff can access '.lc($crstype).' with this role.'));
1.406.2.12 raeburn 8382: } elsif ($newsettings{$role}{'access'} eq 'dh') {
8383: $r->print(&mt('Helpdesk staff can use this role if they have an active [_1] role',
8384: &Apache::lonnet::plaintext('dh')));
8385: } elsif ($newsettings{$role}{'access'} eq 'da') {
8386: $r->print(&mt('Helpdesk staff can use this role if they have an active [_1] role',
8387: &Apache::lonnet::plaintext('da')));
1.406.2.10 raeburn 8388: } elsif ($newsettings{$role}{'access'} eq 'none') {
8389: $r->print(&mt('No helpdesk staff can access '.lc($crstype).' with this role.'));
8390: } elsif ($newsettings{$role}{'access'} eq 'status') {
8391: if ($newsettings{$role}{'status'}) {
8392: my ($access,$rest) = split(/=/,$storehash{'internal.adhoc.'.$role});
8393: if (split(/,/,$rest) > 1) {
8394: $r->print(&mt('Helpdesk staff can use this role if their institutional type is one of: [_1].',
8395: $newsettings{$role}{'status'}));
8396: } else {
8397: $r->print(&mt('Helpdesk staff can use this role if their institutional type is: [_1].',
8398: $newsettings{$role}{'status'}));
8399: }
8400: } else {
8401: $r->print(&mt('No helpdesk staff can access '.lc($crstype).' with this role.'));
8402: }
8403: } elsif ($newsettings{$role}{'access'} eq 'exc') {
8404: if ($newsettings{$role}{'exc'}) {
8405: $r->print(&mt('Helpdesk staff who can use this role are as follows:').' '.$newsettings{$role}{'exc'}.'.');
8406: } else {
8407: $r->print(&mt('No helpdesk staff can access '.lc($crstype).' with this role.'));
8408: }
8409: } elsif ($newsettings{$role}{'access'} eq 'inc') {
8410: if ($newsettings{$role}{'inc'}) {
8411: $r->print(&mt('All helpdesk staff may use this role except the following:').' '.$newsettings{$role}{'inc'}.'.');
8412: } else {
8413: $r->print(&mt('All helpdesk staff may use this role.'));
8414: }
8415: }
8416: } else {
8417: $r->print(&mt('Default access set in the domain now applies.').'<br />'.
8418: '<span class="LC_cusr_emph">'.$domusage{$role}.'</span>');
8419: }
8420: $r->print('</li>');
8421: }
8422: unless ($newsettings{$role}{'access'} eq 'none') {
8423: if ($changed{$role}{'off'}) {
8424: if ($newsettings{$role}{'off'}) {
8425: $r->print('<li>'.&mt('Privileges which are available by default for this ad hoc role, but are disabled for this specific '.lc($crstype).':').
8426: '<ul><li>'.$newsettings{$role}{'off'}.'</li></ul></li>');
8427: } else {
8428: $r->print('<li>'.&mt('All privileges available by default for this ad hoc role are enabled.').'</li>');
8429: }
8430: }
8431: if ($changed{$role}{'on'}) {
8432: if ($newsettings{$role}{'on'}) {
8433: $r->print('<li>'.&mt('Privileges which are not available by default for this ad hoc role, but are enabled for this specific '.lc($crstype).':').
8434: '<ul><li>'.$newsettings{$role}{'on'}.'</li></ul></li>');
8435: } else {
8436: $r->print('<li>'.&mt('None of the privileges unavailable by default for this ad hoc role are enabled.').'</li>');
8437: }
8438: }
8439: }
8440: $r->print('</ul></li>');
8441: }
8442: $r->print('</ul>');
8443: }
8444: } else {
8445: $r->print(&mt('No changes made to helpdesk access settings.'));
8446: }
8447: }
8448: return;
8449: }
8450:
1.27 matthew 8451: #-------------------------------------------------- functions for &phase_two
1.160 raeburn 8452: sub user_search_result {
1.221 raeburn 8453: my ($context,$srch) = @_;
1.160 raeburn 8454: my %allhomes;
8455: my %inst_matches;
8456: my %srch_results;
1.181 raeburn 8457: my ($response,$currstate,$forcenewuser,$dirsrchres);
1.183 raeburn 8458: $srch->{'srchterm'} =~ s/\s+/ /g;
1.176 raeburn 8459: if ($srch->{'srchby'} !~ /^(uname|lastname|lastfirst)$/) {
1.160 raeburn 8460: $response = &mt('Invalid search.');
8461: }
8462: if ($srch->{'srchin'} !~ /^(crs|dom|alc|instd)$/) {
8463: $response = &mt('Invalid search.');
8464: }
1.177 raeburn 8465: if ($srch->{'srchtype'} !~ /^(exact|contains|begins)$/) {
1.160 raeburn 8466: $response = &mt('Invalid search.');
8467: }
8468: if ($srch->{'srchterm'} eq '') {
8469: $response = &mt('You must enter a search term.');
8470: }
1.183 raeburn 8471: if ($srch->{'srchterm'} =~ /^\s+$/) {
8472: $response = &mt('Your search term must contain more than just spaces.');
8473: }
1.160 raeburn 8474: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'instd')) {
8475: if (($srch->{'srchdomain'} eq '') ||
1.163 albertel 8476: ! (&Apache::lonnet::domain($srch->{'srchdomain'}))) {
1.160 raeburn 8477: $response = &mt('You must specify a valid domain when searching in a domain or institutional directory.')
8478: }
8479: }
8480: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs') ||
8481: ($srch->{'srchin'} eq 'alc')) {
1.176 raeburn 8482: if ($srch->{'srchby'} eq 'uname') {
1.243 raeburn 8483: my $unamecheck = $srch->{'srchterm'};
8484: if ($srch->{'srchtype'} eq 'contains') {
8485: if ($unamecheck !~ /^\w/) {
8486: $unamecheck = 'a'.$unamecheck;
8487: }
8488: }
8489: if ($unamecheck !~ /^$match_username$/) {
1.176 raeburn 8490: $response = &mt('You must specify a valid username. Only the following are allowed: letters numbers - . @');
8491: }
1.160 raeburn 8492: }
8493: }
1.180 raeburn 8494: if ($response ne '') {
1.406.2.4 raeburn 8495: $response = '<span class="LC_warning">'.$response.'</span><br />';
1.180 raeburn 8496: }
1.160 raeburn 8497: if ($srch->{'srchin'} eq 'instd') {
1.406.2.3 raeburn 8498: my $instd_chk = &instdirectorysrch_check($srch);
1.160 raeburn 8499: if ($instd_chk ne 'ok') {
1.406.2.3 raeburn 8500: my $domd_chk = &domdirectorysrch_check($srch);
1.406.2.4 raeburn 8501: $response .= '<span class="LC_warning">'.$instd_chk.'</span><br />';
1.406.2.3 raeburn 8502: if ($domd_chk eq 'ok') {
1.406.2.4 raeburn 8503: $response .= &mt('You may want to search in the LON-CAPA domain instead of the institutional directory.');
1.406.2.3 raeburn 8504: }
1.406.2.5 raeburn 8505: $response .= '<br />';
1.406.2.3 raeburn 8506: }
8507: } else {
8508: unless (($context eq 'requestcrs') && ($srch->{'srchtype'} eq 'exact')) {
8509: my $domd_chk = &domdirectorysrch_check($srch);
1.406.2.14 raeburn 8510: if (($domd_chk ne 'ok') && ($env{'form.action'} ne 'accesslogs')) {
1.406.2.3 raeburn 8511: my $instd_chk = &instdirectorysrch_check($srch);
1.406.2.4 raeburn 8512: $response .= '<span class="LC_warning">'.$domd_chk.'</span><br />';
1.406.2.3 raeburn 8513: if ($instd_chk eq 'ok') {
1.406.2.4 raeburn 8514: $response .= &mt('You may want to search in the institutional directory instead of the LON-CAPA domain.');
1.406.2.3 raeburn 8515: }
1.406.2.5 raeburn 8516: $response .= '<br />';
1.406.2.3 raeburn 8517: }
1.160 raeburn 8518: }
8519: }
8520: if ($response ne '') {
1.180 raeburn 8521: return ($currstate,$response);
1.160 raeburn 8522: }
8523: if ($srch->{'srchby'} eq 'uname') {
8524: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs')) {
8525: if ($env{'form.forcenew'}) {
8526: if ($srch->{'srchdomain'} ne $env{'request.role.domain'}) {
8527: my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
8528: if ($uhome eq 'no_host') {
8529: my $domdesc = &Apache::lonnet::domain($env{'request.role.domain'},'description');
1.180 raeburn 8530: my $showdom = &display_domain_info($env{'request.role.domain'});
8531: $response = &mt('New users can only be created in the domain to which your current role belongs - [_1].',$showdom);
1.160 raeburn 8532: } else {
1.179 raeburn 8533: $currstate = 'modify';
1.160 raeburn 8534: }
8535: } else {
1.179 raeburn 8536: $currstate = 'modify';
1.160 raeburn 8537: }
8538: } else {
8539: if ($srch->{'srchin'} eq 'dom') {
1.162 raeburn 8540: if ($srch->{'srchtype'} eq 'exact') {
8541: my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
8542: if ($uhome eq 'no_host') {
1.179 raeburn 8543: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8544: &build_search_response($context,$srch,%srch_results);
1.162 raeburn 8545: } else {
1.179 raeburn 8546: $currstate = 'modify';
1.406.2.5 raeburn 8547: if ($env{'form.action'} eq 'accesslogs') {
8548: $currstate = 'activity';
8549: }
1.310 raeburn 8550: my $uname = $srch->{'srchterm'};
8551: my $udom = $srch->{'srchdomain'};
8552: $srch_results{$uname.':'.$udom} =
8553: { &Apache::lonnet::get('environment',
8554: ['firstname',
8555: 'lastname',
8556: 'permanentemail'],
8557: $udom,$uname)
8558: };
1.162 raeburn 8559: }
8560: } else {
8561: %srch_results = &Apache::lonnet::usersearch($srch);
1.179 raeburn 8562: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8563: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 8564: }
8565: } else {
1.167 albertel 8566: my $courseusers = &get_courseusers();
1.162 raeburn 8567: if ($srch->{'srchtype'} eq 'exact') {
1.167 albertel 8568: if (exists($courseusers->{$srch->{'srchterm'}.':'.$srch->{'srchdomain'}})) {
1.179 raeburn 8569: $currstate = 'modify';
1.162 raeburn 8570: } else {
1.179 raeburn 8571: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8572: &build_search_response($context,$srch,%srch_results);
1.162 raeburn 8573: }
1.160 raeburn 8574: } else {
1.167 albertel 8575: foreach my $user (keys(%$courseusers)) {
1.162 raeburn 8576: my ($cuname,$cudomain) = split(/:/,$user);
8577: if ($cudomain eq $srch->{'srchdomain'}) {
1.177 raeburn 8578: my $matched = 0;
8579: if ($srch->{'srchtype'} eq 'begins') {
8580: if ($cuname =~ /^\Q$srch->{'srchterm'}\E/i) {
8581: $matched = 1;
8582: }
8583: } else {
8584: if ($cuname =~ /\Q$srch->{'srchterm'}\E/i) {
8585: $matched = 1;
8586: }
8587: }
8588: if ($matched) {
1.167 albertel 8589: $srch_results{$user} =
8590: {&Apache::lonnet::get('environment',
8591: ['firstname',
8592: 'lastname',
1.194 albertel 8593: 'permanentemail'],
8594: $cudomain,$cuname)};
1.162 raeburn 8595: }
8596: }
8597: }
1.179 raeburn 8598: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8599: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 8600: }
8601: }
8602: }
8603: } elsif ($srch->{'srchin'} eq 'alc') {
1.179 raeburn 8604: $currstate = 'query';
1.160 raeburn 8605: } elsif ($srch->{'srchin'} eq 'instd') {
1.181 raeburn 8606: ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
8607: if ($dirsrchres eq 'ok') {
8608: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8609: &build_search_response($context,$srch,%srch_results);
1.181 raeburn 8610: } else {
8611: my $showdom = &display_domain_info($srch->{'srchdomain'});
8612: $response = '<span class="LC_warning">'.
8613: &mt('Institutional directory search is not available in domain: [_1]',$showdom).
8614: '</span><br />'.
8615: &mt('You may want to search in the LON-CAPA domain instead of the institutional directory.').
1.406.2.5 raeburn 8616: '<br />';
1.181 raeburn 8617: }
1.160 raeburn 8618: }
8619: } else {
8620: if ($srch->{'srchin'} eq 'dom') {
8621: %srch_results = &Apache::lonnet::usersearch($srch);
1.179 raeburn 8622: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8623: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 8624: } elsif ($srch->{'srchin'} eq 'crs') {
1.167 albertel 8625: my $courseusers = &get_courseusers();
8626: foreach my $user (keys(%$courseusers)) {
1.160 raeburn 8627: my ($uname,$udom) = split(/:/,$user);
8628: my %names = &Apache::loncommon::getnames($uname,$udom);
8629: my %emails = &Apache::loncommon::getemails($uname,$udom);
8630: if ($srch->{'srchby'} eq 'lastname') {
8631: if ((($srch->{'srchtype'} eq 'exact') &&
8632: ($names{'lastname'} eq $srch->{'srchterm'})) ||
1.177 raeburn 8633: (($srch->{'srchtype'} eq 'begins') &&
8634: ($names{'lastname'} =~ /^\Q$srch->{'srchterm'}\E/i)) ||
1.160 raeburn 8635: (($srch->{'srchtype'} eq 'contains') &&
8636: ($names{'lastname'} =~ /\Q$srch->{'srchterm'}\E/i))) {
8637: $srch_results{$user} = {firstname => $names{'firstname'},
8638: lastname => $names{'lastname'},
8639: permanentemail => $emails{'permanentemail'},
8640: };
8641: }
8642: } elsif ($srch->{'srchby'} eq 'lastfirst') {
8643: my ($srchlast,$srchfirst) = split(/,/,$srch->{'srchterm'});
1.177 raeburn 8644: $srchlast =~ s/\s+$//;
8645: $srchfirst =~ s/^\s+//;
1.160 raeburn 8646: if ($srch->{'srchtype'} eq 'exact') {
8647: if (($names{'lastname'} eq $srchlast) &&
8648: ($names{'firstname'} eq $srchfirst)) {
8649: $srch_results{$user} = {firstname => $names{'firstname'},
8650: lastname => $names{'lastname'},
8651: permanentemail => $emails{'permanentemail'},
8652:
8653: };
8654: }
1.177 raeburn 8655: } elsif ($srch->{'srchtype'} eq 'begins') {
8656: if (($names{'lastname'} =~ /^\Q$srchlast\E/i) &&
8657: ($names{'firstname'} =~ /^\Q$srchfirst\E/i)) {
8658: $srch_results{$user} = {firstname => $names{'firstname'},
8659: lastname => $names{'lastname'},
8660: permanentemail => $emails{'permanentemail'},
8661: };
8662: }
8663: } else {
1.160 raeburn 8664: if (($names{'lastname'} =~ /\Q$srchlast\E/i) &&
8665: ($names{'firstname'} =~ /\Q$srchfirst\E/i)) {
8666: $srch_results{$user} = {firstname => $names{'firstname'},
8667: lastname => $names{'lastname'},
8668: permanentemail => $emails{'permanentemail'},
8669: };
8670: }
8671: }
8672: }
8673: }
1.179 raeburn 8674: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8675: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 8676: } elsif ($srch->{'srchin'} eq 'alc') {
1.179 raeburn 8677: $currstate = 'query';
1.160 raeburn 8678: } elsif ($srch->{'srchin'} eq 'instd') {
1.181 raeburn 8679: ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
8680: if ($dirsrchres eq 'ok') {
8681: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8682: &build_search_response($context,$srch,%srch_results);
1.181 raeburn 8683: } else {
1.406.2.5 raeburn 8684: my $showdom = &display_domain_info($srch->{'srchdomain'});
8685: $response = '<span class="LC_warning">'.
1.181 raeburn 8686: &mt('Institutional directory search is not available in domain: [_1]',$showdom).
8687: '</span><br />'.
8688: &mt('You may want to search in the LON-CAPA domain instead of the institutional directory.').
1.406.2.5 raeburn 8689: '<br />';
1.181 raeburn 8690: }
1.160 raeburn 8691: }
8692: }
1.179 raeburn 8693: return ($currstate,$response,$forcenewuser,\%srch_results);
1.160 raeburn 8694: }
8695:
1.406.2.3 raeburn 8696: sub domdirectorysrch_check {
8697: my ($srch) = @_;
8698: my $response;
8699: my %dom_inst_srch = &Apache::lonnet::get_dom('configuration',
8700: ['directorysrch'],$srch->{'srchdomain'});
8701: my $showdom = &display_domain_info($srch->{'srchdomain'});
8702: if (ref($dom_inst_srch{'directorysrch'}) eq 'HASH') {
8703: if ($dom_inst_srch{'directorysrch'}{'lcavailable'} eq '0') {
8704: return &mt('LON-CAPA directory search is not available in domain: [_1]',$showdom);
8705: }
8706: if ($dom_inst_srch{'directorysrch'}{'lclocalonly'}) {
8707: if ($env{'request.role.domain'} ne $srch->{'srchdomain'}) {
8708: return &mt('LON-CAPA directory search in domain: [_1] is only allowed for users with a current role in the domain.',$showdom);
8709: }
8710: }
8711: }
8712: return 'ok';
8713: }
8714:
8715: sub instdirectorysrch_check {
1.160 raeburn 8716: my ($srch) = @_;
8717: my $can_search = 0;
8718: my $response;
8719: my %dom_inst_srch = &Apache::lonnet::get_dom('configuration',
8720: ['directorysrch'],$srch->{'srchdomain'});
1.180 raeburn 8721: my $showdom = &display_domain_info($srch->{'srchdomain'});
1.160 raeburn 8722: if (ref($dom_inst_srch{'directorysrch'}) eq 'HASH') {
8723: if (!$dom_inst_srch{'directorysrch'}{'available'}) {
1.180 raeburn 8724: return &mt('Institutional directory search is not available in domain: [_1]',$showdom);
1.160 raeburn 8725: }
8726: if ($dom_inst_srch{'directorysrch'}{'localonly'}) {
8727: if ($env{'request.role.domain'} ne $srch->{'srchdomain'}) {
1.180 raeburn 8728: return &mt('Institutional directory search in domain: [_1] is only allowed for users with a current role in the domain.',$showdom);
1.160 raeburn 8729: }
8730: my @usertypes = split(/:/,$env{'environment.inststatus'});
8731: if (!@usertypes) {
8732: push(@usertypes,'default');
8733: }
8734: if (ref($dom_inst_srch{'directorysrch'}{'cansearch'}) eq 'ARRAY') {
8735: foreach my $type (@usertypes) {
8736: if (grep(/^\Q$type\E$/,@{$dom_inst_srch{'directorysrch'}{'cansearch'}})) {
8737: $can_search = 1;
8738: last;
8739: }
8740: }
8741: }
8742: if (!$can_search) {
8743: my ($insttypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($srch->{'srchdomain'});
8744: my @longtypes;
8745: foreach my $item (@usertypes) {
1.229 raeburn 8746: if (defined($insttypes->{$item})) {
8747: push (@longtypes,$insttypes->{$item});
8748: } elsif ($item eq 'default') {
8749: push (@longtypes,&mt('other'));
8750: }
1.160 raeburn 8751: }
8752: my $insttype_str = join(', ',@longtypes);
1.180 raeburn 8753: return &mt('Institutional directory search in domain: [_1] is not available to your user type: ',$showdom).$insttype_str;
1.229 raeburn 8754: }
1.160 raeburn 8755: } else {
8756: $can_search = 1;
8757: }
8758: } else {
1.180 raeburn 8759: return &mt('Institutional directory search has not been configured for domain: [_1]',$showdom);
1.160 raeburn 8760: }
8761: my %longtext = &Apache::lonlocal::texthash (
1.167 albertel 8762: uname => 'username',
1.160 raeburn 8763: lastfirst => 'last name, first name',
1.167 albertel 8764: lastname => 'last name',
1.172 raeburn 8765: contains => 'contains',
1.178 raeburn 8766: exact => 'as exact match to',
8767: begins => 'begins with',
1.160 raeburn 8768: );
8769: if ($can_search) {
8770: if (ref($dom_inst_srch{'directorysrch'}{'searchby'}) eq 'ARRAY') {
8771: if (!grep(/^\Q$srch->{'srchby'}\E$/,@{$dom_inst_srch{'directorysrch'}{'searchby'}})) {
1.180 raeburn 8772: return &mt('Institutional directory search in domain: [_1] is not available for searching by "[_2]"',$showdom,$longtext{$srch->{'srchby'}});
1.160 raeburn 8773: }
8774: } else {
1.180 raeburn 8775: return &mt('Institutional directory search in domain: [_1] is not available.', $showdom);
1.160 raeburn 8776: }
8777: }
8778: if ($can_search) {
1.178 raeburn 8779: if (ref($dom_inst_srch{'directorysrch'}{'searchtypes'}) eq 'ARRAY') {
8780: if (grep(/^\Q$srch->{'srchtype'}\E/,@{$dom_inst_srch{'directorysrch'}{'searchtypes'}})) {
8781: return 'ok';
8782: } else {
1.180 raeburn 8783: return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
1.178 raeburn 8784: }
8785: } else {
8786: if ((($dom_inst_srch{'directorysrch'}{'searchtypes'} eq 'specify') &&
8787: ($srch->{'srchtype'} eq 'exact' || $srch->{'srchtype'} eq 'contains')) ||
8788: ($dom_inst_srch{'directorysrch'}{'searchtypes'} eq $srch->{'srchtype'})) {
8789: return 'ok';
8790: } else {
1.180 raeburn 8791: return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
1.178 raeburn 8792: }
1.160 raeburn 8793: }
8794: }
8795: }
8796:
8797: sub get_courseusers {
8798: my %advhash;
1.167 albertel 8799: my $classlist = &Apache::loncoursedata::get_classlist();
1.160 raeburn 8800: my %coursepersonnel=&Apache::lonnet::get_course_adv_roles();
8801: foreach my $role (sort(keys(%coursepersonnel))) {
8802: foreach my $user (split(/\,/,$coursepersonnel{$role})) {
1.167 albertel 8803: if (!exists($classlist->{$user})) {
8804: $classlist->{$user} = [];
8805: }
1.160 raeburn 8806: }
8807: }
1.167 albertel 8808: return $classlist;
1.160 raeburn 8809: }
8810:
8811: sub build_search_response {
1.221 raeburn 8812: my ($context,$srch,%srch_results) = @_;
1.179 raeburn 8813: my ($currstate,$response,$forcenewuser);
1.160 raeburn 8814: my %names = (
1.330 bisitz 8815: 'uname' => 'username',
8816: 'lastname' => 'last name',
1.160 raeburn 8817: 'lastfirst' => 'last name, first name',
1.330 bisitz 8818: 'crs' => 'this course',
8819: 'dom' => 'LON-CAPA domain',
8820: 'instd' => 'the institutional directory for domain',
1.160 raeburn 8821: );
8822:
8823: my %single = (
1.180 raeburn 8824: begins => 'A match',
1.160 raeburn 8825: contains => 'A match',
1.180 raeburn 8826: exact => 'An exact match',
1.160 raeburn 8827: );
8828: my %nomatch = (
1.180 raeburn 8829: begins => 'No match',
1.160 raeburn 8830: contains => 'No match',
1.180 raeburn 8831: exact => 'No exact match',
1.160 raeburn 8832: );
8833: if (keys(%srch_results) > 1) {
1.179 raeburn 8834: $currstate = 'select';
1.160 raeburn 8835: } else {
8836: if (keys(%srch_results) == 1) {
1.406.2.5 raeburn 8837: if ($env{'form.action'} eq 'accesslogs') {
8838: $currstate = 'activity';
8839: } else {
8840: $currstate = 'modify';
8841: }
1.180 raeburn 8842: $response = &mt("$single{$srch->{'srchtype'}} was found for the $names{$srch->{'srchby'}} ([_1]) in $names{$srch->{'srchin'}}.",$srch->{'srchterm'});
8843: if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
1.330 bisitz 8844: $response .= ': '.&display_domain_info($srch->{'srchdomain'});
1.180 raeburn 8845: }
1.330 bisitz 8846: } else { # Search has nothing found. Prepare message to user.
8847: $response = '<span class="LC_warning">';
1.180 raeburn 8848: if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
1.330 bisitz 8849: $response .= &mt("$nomatch{$srch->{'srchtype'}} found for the $names{$srch->{'srchby'}} [_1] in $names{$srch->{'srchin'}}: [_2]",
8850: '<b>'.$srch->{'srchterm'}.'</b>',
8851: &display_domain_info($srch->{'srchdomain'}));
8852: } else {
8853: $response .= &mt("$nomatch{$srch->{'srchtype'}} found for the $names{$srch->{'srchby'}} [_1] in $names{$srch->{'srchin'}}.",
8854: '<b>'.$srch->{'srchterm'}.'</b>');
1.180 raeburn 8855: }
8856: $response .= '</span>';
1.330 bisitz 8857:
1.160 raeburn 8858: if ($srch->{'srchin'} ne 'alc') {
8859: $forcenewuser = 1;
8860: my $cansrchinst = 0;
1.406.2.14 raeburn 8861: if (($srch->{'srchdomain'}) && ($env{'form.action'} ne 'accesslogs')) {
1.160 raeburn 8862: my %domconfig = &Apache::lonnet::get_dom('configuration',['directorysrch'],$srch->{'srchdomain'});
8863: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
8864: if ($domconfig{'directorysrch'}{'available'}) {
8865: $cansrchinst = 1;
8866: }
8867: }
8868: }
1.180 raeburn 8869: if ((($srch->{'srchby'} eq 'lastfirst') ||
8870: ($srch->{'srchby'} eq 'lastname')) &&
8871: ($srch->{'srchin'} eq 'dom')) {
8872: if ($cansrchinst) {
8873: $response .= '<br />'.&mt('You may want to broaden your search to a search of the institutional directory for the domain.');
1.160 raeburn 8874: }
8875: }
1.180 raeburn 8876: if ($srch->{'srchin'} eq 'crs') {
8877: $response .= '<br />'.&mt('You may want to broaden your search to the selected LON-CAPA domain.');
8878: }
8879: }
1.305 raeburn 8880: my $createdom = $env{'request.role.domain'};
8881: if ($context eq 'requestcrs') {
8882: if ($env{'form.coursedom'} ne '') {
8883: $createdom = $env{'form.coursedom'};
8884: }
8885: }
1.406.2.5 raeburn 8886: unless (($env{'form.action'} eq 'accesslogs') || (($srch->{'srchby'} eq 'uname') && ($srch->{'srchin'} eq 'dom') &&
8887: ($srch->{'srchtype'} eq 'exact') && ($srch->{'srchdomain'} eq $createdom))) {
1.221 raeburn 8888: my $cancreate =
1.305 raeburn 8889: &Apache::lonuserutils::can_create_user($createdom,$context);
8890: my $targetdom = '<span class="LC_cusr_emph">'.$createdom.'</span>';
1.221 raeburn 8891: if ($cancreate) {
1.305 raeburn 8892: my $showdom = &display_domain_info($createdom);
1.266 bisitz 8893: $response .= '<br /><br />'
8894: .'<b>'.&mt('To add a new user:').'</b>'
1.305 raeburn 8895: .'<br />';
8896: if ($context eq 'requestcrs') {
8897: $response .= &mt("(You can only define new users in the new course's domain - [_1])",$targetdom);
8898: } else {
8899: $response .= &mt("(You can only create new users in your current role's domain - [_1])",$targetdom);
8900: }
8901: $response .='<ul><li>'
1.266 bisitz 8902: .&mt("Set 'Domain/institution to search' to: [_1]",'<span class="LC_cusr_emph">'.$showdom.'</span>')
8903: .'</li><li>'
8904: .&mt("Set 'Search criteria' to: [_1]username is ..... in selected LON-CAPA domain[_2]",'<span class="LC_cusr_emph">','</span>')
8905: .'</li><li>'
8906: .&mt('Provide the proposed username')
8907: .'</li><li>'
8908: .&mt("Click 'Search'")
8909: .'</li></ul><br />';
1.221 raeburn 8910: } else {
1.406.2.7 raeburn 8911: unless (($context eq 'domain') && ($env{'form.action'} eq 'singleuser')) {
8912: my $helplink = ' href="javascript:helpMenu('."'display'".')"';
8913: $response .= '<br /><br />';
8914: if ($context eq 'requestcrs') {
8915: $response .= &mt("You are not authorized to define new users in the new course's domain - [_1].",$targetdom);
8916: } else {
8917: $response .= &mt("You are not authorized to create new users in your current role's domain - [_1].",$targetdom);
8918: }
8919: $response .= '<br />'
8920: .&mt('Please contact the [_1]helpdesk[_2] if you need to create a new user.'
8921: ,' <a'.$helplink.'>'
8922: ,'</a>')
8923: .'<br />';
1.305 raeburn 8924: }
1.221 raeburn 8925: }
1.160 raeburn 8926: }
8927: }
8928: }
1.179 raeburn 8929: return ($currstate,$response,$forcenewuser);
1.160 raeburn 8930: }
8931:
1.180 raeburn 8932: sub display_domain_info {
8933: my ($dom) = @_;
8934: my $output = $dom;
8935: if ($dom ne '') {
8936: my $domdesc = &Apache::lonnet::domain($dom,'description');
8937: if ($domdesc ne '') {
8938: $output .= ' <span class="LC_cusr_emph">('.$domdesc.')</span>';
8939: }
8940: }
8941: return $output;
8942: }
8943:
1.160 raeburn 8944: sub crumb_utilities {
8945: my %elements = (
8946: crtuser => {
8947: srchterm => 'text',
1.172 raeburn 8948: srchin => 'selectbox',
1.160 raeburn 8949: srchby => 'selectbox',
8950: srchtype => 'selectbox',
8951: srchdomain => 'selectbox',
8952: },
1.207 raeburn 8953: crtusername => {
8954: srchterm => 'text',
8955: srchdomain => 'selectbox',
8956: },
1.160 raeburn 8957: docustom => {
8958: rolename => 'selectbox',
8959: newrolename => 'textbox',
8960: },
1.179 raeburn 8961: studentform => {
8962: srchterm => 'text',
8963: srchin => 'selectbox',
8964: srchby => 'selectbox',
8965: srchtype => 'selectbox',
8966: srchdomain => 'selectbox',
8967: },
1.160 raeburn 8968: );
8969:
8970: my $jsback .= qq|
8971: function backPage(formname,prevphase,prevstate) {
1.211 raeburn 8972: if (typeof prevphase == 'undefined') {
8973: formname.phase.value = '';
8974: }
8975: else {
8976: formname.phase.value = prevphase;
8977: }
8978: if (typeof prevstate == 'undefined') {
8979: formname.currstate.value = '';
8980: }
8981: else {
8982: formname.currstate.value = prevstate;
8983: }
1.160 raeburn 8984: formname.submit();
8985: }
8986: |;
8987: return ($jsback,\%elements);
8988: }
8989:
1.26 matthew 8990: sub course_level_table {
1.375 raeburn 8991: my ($inccourses,$showcredits,$defaultcredits) = @_;
8992: return unless (ref($inccourses) eq 'HASH');
1.26 matthew 8993: my $table = '';
1.62 www 8994: # Custom Roles?
8995:
1.190 raeburn 8996: my %customroles=&Apache::lonuserutils::my_custom_roles();
1.89 raeburn 8997: my %lt=&Apache::lonlocal::texthash(
8998: 'exs' => "Existing sections",
8999: 'new' => "Define new section",
9000: 'ssd' => "Set Start Date",
9001: 'sed' => "Set End Date",
1.131 raeburn 9002: 'crl' => "Course Level",
1.89 raeburn 9003: 'act' => "Activate",
9004: 'rol' => "Role",
9005: 'ext' => "Extent",
1.113 raeburn 9006: 'grs' => "Section",
1.375 raeburn 9007: 'crd' => "Credits",
1.89 raeburn 9008: 'sta' => "Start",
9009: 'end' => "End"
9010: );
1.62 www 9011:
1.375 raeburn 9012: foreach my $protectedcourse (sort(keys(%{$inccourses}))) {
1.135 raeburn 9013: my $thiscourse=$protectedcourse;
1.26 matthew 9014: $thiscourse=~s:_:/:g;
9015: my %coursedata=&Apache::lonnet::coursedescription($thiscourse);
1.365 raeburn 9016: my $isowner = &Apache::lonuserutils::is_courseowner($protectedcourse,$coursedata{'internal.courseowner'});
1.26 matthew 9017: my $area=$coursedata{'description'};
1.321 raeburn 9018: my $crstype=$coursedata{'type'};
1.135 raeburn 9019: if (!defined($area)) { $area=&mt('Unavailable course').': '.$protectedcourse; }
1.89 raeburn 9020: my ($domain,$cnum)=split(/\//,$thiscourse);
1.115 albertel 9021: my %sections_count;
1.101 albertel 9022: if (defined($env{'request.course.id'})) {
9023: if ($env{'request.course.id'} eq $domain.'_'.$cnum) {
1.115 albertel 9024: %sections_count =
9025: &Apache::loncommon::get_sections($domain,$cnum);
1.92 raeburn 9026: }
9027: }
1.321 raeburn 9028: my @roles = &Apache::lonuserutils::roles_by_context('course','',$crstype);
1.213 raeburn 9029: foreach my $role (@roles) {
1.321 raeburn 9030: my $plrole=&Apache::lonnet::plaintext($role,$crstype);
1.329 raeburn 9031: if ((&Apache::lonnet::allowed('c'.$role,$thiscourse)) ||
9032: ((($role eq 'cc') || ($role eq 'co')) && ($isowner))) {
1.221 raeburn 9033: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
1.375 raeburn 9034: $plrole,\%sections_count,\%lt,
1.402 raeburn 9035: $showcredits,$defaultcredits,$crstype);
1.221 raeburn 9036: } elsif ($env{'request.course.sec'} ne '') {
9037: if (&Apache::lonnet::allowed('c'.$role,$thiscourse.'/'.
9038: $env{'request.course.sec'})) {
9039: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
1.375 raeburn 9040: $plrole,\%sections_count,\%lt,
1.402 raeburn 9041: $showcredits,$defaultcredits,$crstype);
1.26 matthew 9042: }
9043: }
9044: }
1.221 raeburn 9045: if (&Apache::lonnet::allowed('ccr',$thiscourse)) {
1.324 raeburn 9046: foreach my $cust (sort(keys(%customroles))) {
9047: next if ($crstype eq 'Community' && $customroles{$cust} =~ /bre\&S/);
1.221 raeburn 9048: my $role = 'cr_cr_'.$env{'user.domain'}.'_'.$env{'user.name'}.'_'.$cust;
9049: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
1.402 raeburn 9050: $cust,\%sections_count,\%lt,
9051: $showcredits,$defaultcredits,$crstype);
1.221 raeburn 9052: }
1.62 www 9053: }
1.26 matthew 9054: }
9055: return '' if ($table eq ''); # return nothing if there is nothing
9056: # in the table
1.188 raeburn 9057: my $result;
9058: if (!$env{'request.course.id'}) {
9059: $result = '<h4>'.$lt{'crl'}.'</h4>'."\n";
9060: }
9061: $result .=
1.136 raeburn 9062: &Apache::loncommon::start_data_table().
9063: &Apache::loncommon::start_data_table_header_row().
1.375 raeburn 9064: '<th>'.$lt{'act'}.'</th><th>'.$lt{'rol'}.'</th>'."\n".
1.402 raeburn 9065: '<th>'.$lt{'ext'}.'</th><th>'."\n";
9066: if ($showcredits) {
9067: $result .= $lt{'crd'}.'</th>';
9068: }
9069: $result .=
1.375 raeburn 9070: '<th>'.$lt{'grs'}.'</th><th>'.$lt{'sta'}.'</th>'."\n".
9071: '<th>'.$lt{'end'}.'</th>'.
1.136 raeburn 9072: &Apache::loncommon::end_data_table_header_row().
9073: $table.
9074: &Apache::loncommon::end_data_table();
1.26 matthew 9075: return $result;
9076: }
1.88 raeburn 9077:
1.221 raeburn 9078: sub course_level_row {
1.375 raeburn 9079: my ($protectedcourse,$role,$area,$domain,$plrole,$sections_count,
1.402 raeburn 9080: $lt,$showcredits,$defaultcredits,$crstype) = @_;
1.375 raeburn 9081: my $creditem;
1.222 raeburn 9082: my $row = &Apache::loncommon::start_data_table_row().
9083: ' <td><input type="checkbox" name="act_'.
9084: $protectedcourse.'_'.$role.'" /></td>'."\n".
9085: ' <td>'.$plrole.'</td>'."\n".
9086: ' <td>'.$area.'<br />Domain: '.$domain.'</td>'."\n";
1.402 raeburn 9087: if (($showcredits) && ($role eq 'st') && ($crstype eq 'Course')) {
1.375 raeburn 9088: $row .=
9089: '<td><input type="text" name="credits_'.$protectedcourse.'_'.
9090: $role.'" size="3" value="'.$defaultcredits.'" /></td>';
9091: } else {
9092: $row .= '<td> </td>';
9093: }
1.322 raeburn 9094: if (($role eq 'cc') || ($role eq 'co')) {
1.222 raeburn 9095: $row .= '<td> </td>';
1.221 raeburn 9096: } elsif ($env{'request.course.sec'} ne '') {
1.222 raeburn 9097: $row .= ' <td><input type="hidden" value="'.
9098: $env{'request.course.sec'}.'" '.
9099: 'name="sec_'.$protectedcourse.'_'.$role.'" />'.
9100: $env{'request.course.sec'}.'</td>';
1.221 raeburn 9101: } else {
9102: if (ref($sections_count) eq 'HASH') {
9103: my $currsec =
9104: &Apache::lonuserutils::course_sections($sections_count,
9105: $protectedcourse.'_'.$role);
1.222 raeburn 9106: $row .= '<td><table class="LC_createuser">'."\n".
9107: '<tr class="LC_section_row">'."\n".
9108: ' <td valign="top">'.$lt->{'exs'}.'<br />'.
9109: $currsec.'</td>'."\n".
9110: ' <td> </td>'."\n".
9111: ' <td valign="top"> '.$lt->{'new'}.'<br />'.
1.221 raeburn 9112: '<input type="text" name="newsec_'.$protectedcourse.'_'.$role.
9113: '" value="" />'.
9114: '<input type="hidden" '.
9115: 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'."\n".
1.222 raeburn 9116: '</tr></table></td>'."\n";
1.221 raeburn 9117: } else {
1.222 raeburn 9118: $row .= '<td><input type="text" size="10" '.
1.375 raeburn 9119: 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'."\n";
1.221 raeburn 9120: }
9121: }
1.222 raeburn 9122: $row .= <<ENDTIMEENTRY;
9123: <td><input type="hidden" name="start_$protectedcourse\_$role" value="" />
1.221 raeburn 9124: <a href=
9125: "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 9126: <td><input type="hidden" name="end_$protectedcourse\_$role" value="" />
1.221 raeburn 9127: <a href=
9128: "javascript:pjump('date_end','End Date $plrole',document.cu.end_$protectedcourse\_$role.value,'end_$protectedcourse\_$role','cu.pres','dateset')">$lt->{'sed'}</a></td>
9129: ENDTIMEENTRY
1.222 raeburn 9130: $row .= &Apache::loncommon::end_data_table_row();
9131: return $row;
1.221 raeburn 9132: }
9133:
1.88 raeburn 9134: sub course_level_dc {
1.375 raeburn 9135: my ($dcdom,$showcredits) = @_;
1.190 raeburn 9136: my %customroles=&Apache::lonuserutils::my_custom_roles();
1.213 raeburn 9137: my @roles = &Apache::lonuserutils::roles_by_context('course');
1.88 raeburn 9138: my $hiddenitems = '<input type="hidden" name="dcdomain" value="'.$dcdom.'" />'.
9139: '<input type="hidden" name="origdom" value="'.$dcdom.'" />'.
1.133 raeburn 9140: '<input type="hidden" name="dccourse" value="" />';
1.355 www 9141: my $courseform=&Apache::loncommon::selectcourse_link
1.356 raeburn 9142: ('cu','dccourse','dcdomain','coursedesc',undef,undef,'Select','crstype');
1.375 raeburn 9143: my $credit_elem;
9144: if ($showcredits) {
9145: $credit_elem = 'credits';
9146: }
9147: my $cb_jscript = &Apache::loncommon::coursebrowser_javascript($dcdom,'currsec','cu','role','Course/Community Browser',$credit_elem);
1.88 raeburn 9148: my %lt=&Apache::lonlocal::texthash(
9149: 'rol' => "Role",
1.113 raeburn 9150: 'grs' => "Section",
1.88 raeburn 9151: 'exs' => "Existing sections",
9152: 'new' => "Define new section",
9153: 'sta' => "Start",
9154: 'end' => "End",
9155: 'ssd' => "Set Start Date",
1.355 www 9156: 'sed' => "Set End Date",
1.375 raeburn 9157: 'scc' => "Course/Community",
9158: 'crd' => "Credits",
1.88 raeburn 9159: );
1.323 raeburn 9160: my $header = '<h4>'.&mt('Course/Community Level').'</h4>'.
1.136 raeburn 9161: &Apache::loncommon::start_data_table().
9162: &Apache::loncommon::start_data_table_header_row().
1.375 raeburn 9163: '<th>'.$lt{'scc'}.'</th><th>'.$lt{'rol'}.'</th>'."\n".
1.397 bisitz 9164: '<th>'.$lt{'grs'}.'</th>'."\n";
9165: $header .= '<th>'.$lt{'crd'}.'</th>'."\n" if ($showcredits);
9166: $header .= '<th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'."\n".
1.136 raeburn 9167: &Apache::loncommon::end_data_table_header_row();
1.143 raeburn 9168: my $otheritems = &Apache::loncommon::start_data_table_row()."\n".
1.356 raeburn 9169: '<td><br /><span class="LC_nobreak"><input type="text" name="coursedesc" value="" onfocus="this.blur();opencrsbrowser('."'cu','dccourse','dcdomain','coursedesc','','','','crstype'".')" />'.
9170: $courseform.(' ' x4).'</span></td>'."\n".
1.389 bisitz 9171: '<td valign="top"><br /><select name="role">'."\n";
1.213 raeburn 9172: foreach my $role (@roles) {
1.135 raeburn 9173: my $plrole=&Apache::lonnet::plaintext($role);
1.389 bisitz 9174: $otheritems .= ' <option value="'.$role.'">'.$plrole.'</option>';
1.88 raeburn 9175: }
1.404 raeburn 9176: if ( keys(%customroles) > 0) {
9177: foreach my $cust (sort(keys(%customroles))) {
1.101 albertel 9178: my $custrole='cr_cr_'.$env{'user.domain'}.
1.135 raeburn 9179: '_'.$env{'user.name'}.'_'.$cust;
1.389 bisitz 9180: $otheritems .= ' <option value="'.$custrole.'">'.$cust.'</option>';
1.88 raeburn 9181: }
9182: }
9183: $otheritems .= '</select></td><td>'.
9184: '<table border="0" cellspacing="0" cellpadding="0">'.
9185: '<tr><td valign="top"><b>'.$lt{'exs'}.'</b><br /><select name="currsec">'.
1.389 bisitz 9186: ' <option value=""><--'.&mt('Pick course first').'</option></select></td>'.
1.88 raeburn 9187: '<td> </td>'.
9188: '<td valign="top"> <b>'.$lt{'new'}.'</b><br />'.
1.113 raeburn 9189: '<input type="text" name="newsec" value="" />'.
1.237 raeburn 9190: '<input type="hidden" name="section" value="" />'.
1.323 raeburn 9191: '<input type="hidden" name="groups" value="" />'.
9192: '<input type="hidden" name="crstype" value="" /></td>'.
1.375 raeburn 9193: '</tr></table></td>'."\n";
9194: if ($showcredits) {
9195: $otheritems .= '<td><br />'."\n".
1.397 bisitz 9196: '<input type="text" size="3" name="credits" value="" /></td>'."\n";
1.375 raeburn 9197: }
1.88 raeburn 9198: $otheritems .= <<ENDTIMEENTRY;
1.323 raeburn 9199: <td><br /><input type="hidden" name="start" value='' />
1.88 raeburn 9200: <a href=
9201: "javascript:pjump('date_start','Start Date',document.cu.start.value,'start','cu.pres','dateset')">$lt{'ssd'}</a></td>
1.323 raeburn 9202: <td><br /><input type="hidden" name="end" value='' />
1.88 raeburn 9203: <a href=
9204: "javascript:pjump('date_end','End Date',document.cu.end.value,'end','cu.pres','dateset')">$lt{'sed'}</a></td>
9205: ENDTIMEENTRY
1.136 raeburn 9206: $otheritems .= &Apache::loncommon::end_data_table_row().
9207: &Apache::loncommon::end_data_table()."\n";
1.88 raeburn 9208: return $cb_jscript.$header.$hiddenitems.$otheritems;
9209: }
9210:
1.237 raeburn 9211: sub update_selfenroll_config {
1.400 raeburn 9212: my ($r,$cid,$cdom,$cnum,$context,$crstype,$currsettings) = @_;
1.398 raeburn 9213: return unless (ref($currsettings) eq 'HASH');
9214: my ($row,$lt) = &Apache::lonuserutils::get_selfenroll_titles();
9215: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
1.237 raeburn 9216: my (%changes,%warning);
1.241 raeburn 9217: my $curr_types;
1.400 raeburn 9218: my %noedit;
9219: unless ($context eq 'domain') {
9220: %noedit = &get_noedit_fields($cdom,$cnum,$crstype,$row);
9221: }
1.237 raeburn 9222: if (ref($row) eq 'ARRAY') {
9223: foreach my $item (@{$row}) {
1.400 raeburn 9224: next if ($noedit{$item});
1.237 raeburn 9225: if ($item eq 'enroll_dates') {
9226: my (%currenrolldate,%newenrolldate);
9227: foreach my $type ('start','end') {
1.398 raeburn 9228: $currenrolldate{$type} = $currsettings->{'selfenroll_'.$type.'_date'};
1.237 raeburn 9229: $newenrolldate{$type} = &Apache::lonhtmlcommon::get_date_from_form('selfenroll_'.$type.'_date');
9230: if ($newenrolldate{$type} ne $currenrolldate{$type}) {
9231: $changes{'internal.selfenroll_'.$type.'_date'} = $newenrolldate{$type};
9232: }
9233: }
9234: } elsif ($item eq 'access_dates') {
9235: my (%currdate,%newdate);
9236: foreach my $type ('start','end') {
1.398 raeburn 9237: $currdate{$type} = $currsettings->{'selfenroll_'.$type.'_access'};
1.237 raeburn 9238: $newdate{$type} = &Apache::lonhtmlcommon::get_date_from_form('selfenroll_'.$type.'_access');
9239: if ($newdate{$type} ne $currdate{$type}) {
9240: $changes{'internal.selfenroll_'.$type.'_access'} = $newdate{$type};
9241: }
9242: }
1.241 raeburn 9243: } elsif ($item eq 'types') {
1.398 raeburn 9244: $curr_types = $currsettings->{'selfenroll_'.$item};
1.241 raeburn 9245: if ($env{'form.selfenroll_all'}) {
9246: if ($curr_types ne '*') {
9247: $changes{'internal.selfenroll_types'} = '*';
9248: } else {
9249: next;
9250: }
9251: } else {
1.249 raeburn 9252: my %currdoms;
1.241 raeburn 9253: my @entries = split(/;/,$curr_types);
9254: my @deletedoms = &Apache::loncommon::get_env_multiple('form.selfenroll_delete');
1.249 raeburn 9255: my @activations = &Apache::loncommon::get_env_multiple('form.selfenroll_activate');
1.241 raeburn 9256: my $newnum = 0;
1.249 raeburn 9257: my @latesttypes;
9258: foreach my $num (@activations) {
9259: my @types = &Apache::loncommon::get_env_multiple('form.selfenroll_types_'.$num);
9260: if (@types > 0) {
1.241 raeburn 9261: @types = sort(@types);
9262: my $typestr = join(',',@types);
1.249 raeburn 9263: my $typedom = $env{'form.selfenroll_dom_'.$num};
9264: $latesttypes[$newnum] = $typedom.':'.$typestr;
9265: $currdoms{$typedom} = 1;
1.241 raeburn 9266: $newnum ++;
9267: }
9268: }
1.338 raeburn 9269: for (my $j=0; $j<$env{'form.selfenroll_types_total'}; $j++) {
9270: if ((!grep(/^$j$/,@deletedoms)) && (!grep(/^$j$/,@activations))) {
1.249 raeburn 9271: my @types = &Apache::loncommon::get_env_multiple('form.selfenroll_types_'.$j);
9272: if (@types > 0) {
9273: @types = sort(@types);
9274: my $typestr = join(',',@types);
9275: my $typedom = $env{'form.selfenroll_dom_'.$j};
9276: $latesttypes[$newnum] = $typedom.':'.$typestr;
9277: $currdoms{$typedom} = 1;
9278: $newnum ++;
9279: }
9280: }
9281: }
9282: if ($env{'form.selfenroll_newdom'} ne '') {
9283: my $typedom = $env{'form.selfenroll_newdom'};
9284: if ((!defined($currdoms{$typedom})) &&
9285: (&Apache::lonnet::domain($typedom) ne '')) {
9286: my $typestr;
9287: my ($othertitle,$usertypes,$types) =
9288: &Apache::loncommon::sorted_inst_types($typedom);
9289: my $othervalue = 'any';
9290: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
9291: if (@{$types} > 0) {
1.257 raeburn 9292: my @esc_types = map { &escape($_); } @{$types};
1.249 raeburn 9293: $othervalue = 'other';
1.258 raeburn 9294: $typestr = join(',',(@esc_types,$othervalue));
1.249 raeburn 9295: }
9296: $typestr = $othervalue;
9297: } else {
9298: $typestr = $othervalue;
9299: }
9300: $latesttypes[$newnum] = $typedom.':'.$typestr;
9301: $newnum ++ ;
9302: }
9303: }
1.241 raeburn 9304: my $selfenroll_types = join(';',@latesttypes);
9305: if ($selfenroll_types ne $curr_types) {
9306: $changes{'internal.selfenroll_types'} = $selfenroll_types;
9307: }
9308: }
1.276 raeburn 9309: } elsif ($item eq 'limit') {
9310: my $newlimit = $env{'form.selfenroll_limit'};
9311: my $newcap = $env{'form.selfenroll_cap'};
9312: $newcap =~s/\s+//g;
1.398 raeburn 9313: my $currlimit = $currsettings->{'selfenroll_limit'};
1.276 raeburn 9314: $currlimit = 'none' if ($currlimit eq '');
1.398 raeburn 9315: my $currcap = $currsettings->{'selfenroll_cap'};
1.276 raeburn 9316: if ($newlimit ne $currlimit) {
9317: if ($newlimit ne 'none') {
9318: if ($newcap =~ /^\d+$/) {
9319: if ($newcap ne $currcap) {
9320: $changes{'internal.selfenroll_cap'} = $newcap;
9321: }
9322: $changes{'internal.selfenroll_limit'} = $newlimit;
9323: } else {
1.398 raeburn 9324: $warning{$item} = &mt('Maximum enrollment setting unchanged.').'<br />'.
9325: &mt('The value provided was invalid - it must be a positive integer if enrollment is being limited.');
1.276 raeburn 9326: }
9327: } elsif ($currcap ne '') {
9328: $changes{'internal.selfenroll_cap'} = '';
9329: $changes{'internal.selfenroll_limit'} = $newlimit;
9330: }
9331: } elsif ($currlimit ne 'none') {
9332: if ($newcap =~ /^\d+$/) {
9333: if ($newcap ne $currcap) {
9334: $changes{'internal.selfenroll_cap'} = $newcap;
9335: }
9336: } else {
1.398 raeburn 9337: $warning{$item} = &mt('Maximum enrollment setting unchanged.').'<br />'.
9338: &mt('The value provided was invalid - it must be a positive integer if enrollment is being limited.');
1.276 raeburn 9339: }
9340: }
9341: } elsif ($item eq 'approval') {
9342: my (@currnotified,@newnotified);
1.398 raeburn 9343: my $currapproval = $currsettings->{'selfenroll_approval'};
9344: my $currnotifylist = $currsettings->{'selfenroll_notifylist'};
1.276 raeburn 9345: if ($currnotifylist ne '') {
9346: @currnotified = split(/,/,$currnotifylist);
9347: @currnotified = sort(@currnotified);
9348: }
9349: my $newapproval = $env{'form.selfenroll_approval'};
9350: @newnotified = &Apache::loncommon::get_env_multiple('form.selfenroll_notify');
9351: @newnotified = sort(@newnotified);
9352: if ($newapproval ne $currapproval) {
9353: $changes{'internal.selfenroll_approval'} = $newapproval;
9354: if (!$newapproval) {
9355: if ($currnotifylist ne '') {
9356: $changes{'internal.selfenroll_notifylist'} = '';
9357: }
9358: } else {
9359: my @differences =
1.295 raeburn 9360: &Apache::loncommon::compare_arrays(\@currnotified,\@newnotified);
1.276 raeburn 9361: if (@differences > 0) {
9362: if (@newnotified > 0) {
9363: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
9364: } else {
9365: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
9366: }
9367: }
9368: }
9369: } else {
1.295 raeburn 9370: my @differences = &Apache::loncommon::compare_arrays(\@currnotified,\@newnotified);
1.276 raeburn 9371: if (@differences > 0) {
9372: if (@newnotified > 0) {
9373: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
9374: } else {
9375: $changes{'internal.selfenroll_notifylist'} = '';
9376: }
9377: }
9378: }
1.237 raeburn 9379: } else {
1.398 raeburn 9380: my $curr_val = $currsettings->{'selfenroll_'.$item};
1.237 raeburn 9381: my $newval = $env{'form.selfenroll_'.$item};
9382: if ($item eq 'section') {
9383: $newval = $env{'form.sections'};
1.241 raeburn 9384: if (defined($curr_groups{$newval})) {
1.237 raeburn 9385: $newval = $curr_val;
1.398 raeburn 9386: $warning{$item} = &mt('Section for self-enrolled users unchanged as the proposed section is a group').'<br />'.
9387: &mt('Group names and section names must be distinct');
1.237 raeburn 9388: } elsif ($newval eq 'all') {
9389: $newval = $curr_val;
1.274 bisitz 9390: $warning{$item} = &mt('Section for self-enrolled users unchanged, as "all" is a reserved section name.');
1.237 raeburn 9391: }
9392: if ($newval eq '') {
9393: $newval = 'none';
9394: }
9395: }
9396: if ($newval ne $curr_val) {
9397: $changes{'internal.selfenroll_'.$item} = $newval;
9398: }
1.241 raeburn 9399: }
1.237 raeburn 9400: }
9401: if (keys(%warning) > 0) {
9402: foreach my $item (@{$row}) {
9403: if (exists($warning{$item})) {
9404: $r->print($warning{$item}.'<br />');
9405: }
9406: }
9407: }
9408: if (keys(%changes) > 0) {
9409: my $putresult = &Apache::lonnet::put('environment',\%changes,$cdom,$cnum);
9410: if ($putresult eq 'ok') {
9411: if ((exists($changes{'internal.selfenroll_types'})) ||
9412: (exists($changes{'internal.selfenroll_start_date'})) ||
9413: (exists($changes{'internal.selfenroll_end_date'}))) {
9414: my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',
9415: $cnum,undef,undef,'Course');
9416: my $chome = &Apache::lonnet::homeserver($cnum,$cdom);
1.398 raeburn 9417: if (ref($crsinfo{$cid}) eq 'HASH') {
1.237 raeburn 9418: foreach my $item ('selfenroll_types','selfenroll_start_date','selfenroll_end_date') {
9419: if (exists($changes{'internal.'.$item})) {
1.398 raeburn 9420: $crsinfo{$cid}{$item} = $changes{'internal.'.$item};
1.237 raeburn 9421: }
9422: }
9423: my $crsputresult =
9424: &Apache::lonnet::courseidput($cdom,\%crsinfo,
9425: $chome,'notime');
9426: }
9427: }
9428: $r->print(&mt('The following changes were made to self-enrollment settings:').'<ul>');
9429: foreach my $item (@{$row}) {
9430: my $title = $item;
9431: if (ref($lt) eq 'HASH') {
9432: $title = $lt->{$item};
9433: }
9434: if ($item eq 'enroll_dates') {
9435: foreach my $type ('start','end') {
9436: if (exists($changes{'internal.selfenroll_'.$type.'_date'})) {
9437: my $newdate = &Apache::lonlocal::locallocaltime($changes{'internal.selfenroll_'.$type.'_date'});
1.244 bisitz 9438: $r->print('<li>'.&mt('[_1]: "[_2]" set to "[_3]".',
1.237 raeburn 9439: $title,$type,$newdate).'</li>');
9440: }
9441: }
9442: } elsif ($item eq 'access_dates') {
9443: foreach my $type ('start','end') {
9444: if (exists($changes{'internal.selfenroll_'.$type.'_access'})) {
9445: my $newdate = &Apache::lonlocal::locallocaltime($changes{'internal.selfenroll_'.$type.'_access'});
1.244 bisitz 9446: $r->print('<li>'.&mt('[_1]: "[_2]" set to "[_3]".',
1.237 raeburn 9447: $title,$type,$newdate).'</li>');
9448: }
9449: }
1.276 raeburn 9450: } elsif ($item eq 'limit') {
9451: if ((exists($changes{'internal.selfenroll_limit'})) ||
9452: (exists($changes{'internal.selfenroll_cap'}))) {
9453: my ($newval,$newcap);
9454: if ($changes{'internal.selfenroll_cap'} ne '') {
9455: $newcap = $changes{'internal.selfenroll_cap'}
9456: } else {
1.398 raeburn 9457: $newcap = $currsettings->{'selfenroll_cap'};
1.276 raeburn 9458: }
9459: if ($changes{'internal.selfenroll_limit'} eq 'none') {
9460: $newval = &mt('No limit');
9461: } elsif ($changes{'internal.selfenroll_limit'} eq
9462: 'allstudents') {
9463: $newval = &mt('New self-enrollment no longer allowed when total (all students) reaches [_1].',$newcap);
9464: } elsif ($changes{'internal.selfenroll_limit'} eq 'selfenrolled') {
9465: $newval = &mt('New self-enrollment no longer allowed when total number of self-enrolled students reaches [_1].',$newcap);
9466: } else {
1.398 raeburn 9467: my $currlimit = $currsettings->{'selfenroll_limit'};
1.276 raeburn 9468: if ($currlimit eq 'allstudents') {
9469: $newval = &mt('New self-enrollment no longer allowed when total (all students) reaches [_1].',$newcap);
9470: } elsif ($changes{'internal.selfenroll_limit'} eq 'selfenrolled') {
1.308 raeburn 9471: $newval = &mt('New self-enrollment no longer allowed when total number of self-enrolled students reaches [_1].',$newcap);
1.276 raeburn 9472: }
9473: }
9474: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval).'</li>'."\n");
9475: }
9476: } elsif ($item eq 'approval') {
9477: if ((exists($changes{'internal.selfenroll_approval'})) ||
9478: (exists($changes{'internal.selfenroll_notifylist'}))) {
1.398 raeburn 9479: my %selfdescs = &Apache::lonuserutils::selfenroll_default_descs();
1.276 raeburn 9480: my ($newval,$newnotify);
9481: if (exists($changes{'internal.selfenroll_notifylist'})) {
9482: $newnotify = $changes{'internal.selfenroll_notifylist'};
9483: } else {
1.398 raeburn 9484: $newnotify = $currsettings->{'selfenroll_notifylist'};
1.276 raeburn 9485: }
1.398 raeburn 9486: if (exists($changes{'internal.selfenroll_approval'})) {
9487: if ($changes{'internal.selfenroll_approval'} !~ /^[012]$/) {
9488: $changes{'internal.selfenroll_approval'} = '0';
9489: }
9490: $newval = $selfdescs{'approval'}{$changes{'internal.selfenroll_approval'}};
1.276 raeburn 9491: } else {
1.398 raeburn 9492: my $currapproval = $currsettings->{'selfenroll_approval'};
9493: if ($currapproval !~ /^[012]$/) {
9494: $currapproval = 0;
1.276 raeburn 9495: }
1.398 raeburn 9496: $newval = $selfdescs{'approval'}{$currapproval};
1.276 raeburn 9497: }
9498: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval));
9499: if ($newnotify) {
1.277 raeburn 9500: $r->print('<br />'.&mt('The following will be notified when an enrollment request needs approval, or has been approved: [_1].',$newnotify));
1.276 raeburn 9501: } else {
1.277 raeburn 9502: $r->print('<br />'.&mt('No notifications sent when an enrollment request needs approval, or has been approved.'));
1.276 raeburn 9503: }
9504: $r->print('</li>'."\n");
9505: }
1.237 raeburn 9506: } else {
9507: if (exists($changes{'internal.selfenroll_'.$item})) {
1.241 raeburn 9508: my $newval = $changes{'internal.selfenroll_'.$item};
9509: if ($item eq 'types') {
9510: if ($newval eq '') {
9511: $newval = &mt('None');
9512: } elsif ($newval eq '*') {
9513: $newval = &mt('Any user in any domain');
9514: }
1.245 raeburn 9515: } elsif ($item eq 'registered') {
9516: if ($newval eq '1') {
9517: $newval = &mt('Yes');
9518: } elsif ($newval eq '0') {
9519: $newval = &mt('No');
9520: }
1.241 raeburn 9521: }
1.244 bisitz 9522: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval).'</li>'."\n");
1.237 raeburn 9523: }
9524: }
9525: }
9526: $r->print('</ul>');
1.398 raeburn 9527: if ($env{'course.'.$cid.'.description'} ne '') {
9528: my %newenvhash;
9529: foreach my $key (keys(%changes)) {
9530: $newenvhash{'course.'.$cid.'.'.$key} = $changes{$key};
9531: }
9532: &Apache::lonnet::appenv(\%newenvhash);
1.237 raeburn 9533: }
9534: } else {
1.398 raeburn 9535: $r->print(&mt('An error occurred when saving changes to self-enrollment settings in this course.').'<br />'.
9536: &mt('The error was: [_1].',$putresult));
1.237 raeburn 9537: }
9538: } else {
1.249 raeburn 9539: $r->print(&mt('No changes were made to the existing self-enrollment settings in this course.'));
1.237 raeburn 9540: }
9541: } else {
1.249 raeburn 9542: $r->print(&mt('No changes were made to the existing self-enrollment settings in this course.'));
1.241 raeburn 9543: }
1.400 raeburn 9544: my $visactions = &cat_visibility();
9545: my ($cathash,%cattype);
9546: my %domconfig = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom);
9547: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
9548: $cathash = $domconfig{'coursecategories'}{'cats'};
9549: $cattype{'auth'} = $domconfig{'coursecategories'}{'auth'};
9550: $cattype{'unauth'} = $domconfig{'coursecategories'}{'unauth'};
9551: } else {
9552: $cathash = {};
9553: $cattype{'auth'} = 'std';
9554: $cattype{'unauth'} = 'std';
9555: }
9556: if (($cattype{'auth'} eq 'none') && ($cattype{'unauth'} eq 'none')) {
9557: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
9558: '<br />'.
9559: '<br />'.$visactions->{'take'}.'<ul>'.
9560: '<li>'.$visactions->{'dc_chgconf'}.'</li>'.
9561: '</ul>');
9562: } elsif (($cattype{'auth'} !~ /^(std|domonly)$/) && ($cattype{'unauth'} !~ /^(std|domonly)$/)) {
9563: if ($currsettings->{'uniquecode'}) {
9564: $r->print('<span class="LC_info">'.$visactions->{'vis'}.'</span>');
9565: } else {
1.366 bisitz 9566: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
1.400 raeburn 9567: '<br />'.
9568: '<br />'.$visactions->{'take'}.'<ul>'.
9569: '<li>'.$visactions->{'dc_setcode'}.'</li>'.
9570: '</ul><br />');
9571: }
9572: } else {
9573: my ($visible,$cansetvis,$vismsgs) = &visible_in_stdcat($cdom,$cnum,\%domconfig);
9574: if (ref($visactions) eq 'HASH') {
9575: if (!$visible) {
9576: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
9577: '<br />');
9578: if (ref($vismsgs) eq 'ARRAY') {
9579: $r->print('<br />'.$visactions->{'take'}.'<ul>');
9580: foreach my $item (@{$vismsgs}) {
9581: $r->print('<li>'.$visactions->{$item}.'</li>');
9582: }
9583: $r->print('</ul>');
1.256 raeburn 9584: }
1.400 raeburn 9585: $r->print($cansetvis);
1.256 raeburn 9586: }
9587: }
9588: }
1.237 raeburn 9589: return;
9590: }
9591:
1.27 matthew 9592: #---------------------------------------------- end functions for &phase_two
1.29 matthew 9593:
9594: #--------------------------------- functions for &phase_two and &phase_three
9595:
9596: #--------------------------end of functions for &phase_two and &phase_three
1.372 raeburn 9597:
1.1 www 9598: 1;
9599: __END__
1.2 www 9600:
9601:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>