Annotation of loncom/interface/loncreateuser.pm, revision 1.447
1.20 harris41 1: # The LearningOnline Network with CAPA
1.1 www 2: # Create a user
3: #
1.447 ! raeburn 4: # $Id: loncreateuser.pm,v 1.446 2017/08/11 00:24:53 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.418 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.411 raeburn 255: 'placement' => 'Can request creation of placement tests',
1.362 raeburn 256: 'requestauthor' => 'Can request author space',
1.275 raeburn 257: );
1.279 raeburn 258: if ($context eq 'requestcourses') {
1.275 raeburn 259: %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
1.299 raeburn 260: 'requestcourses.official','requestcourses.unofficial',
1.411 raeburn 261: 'requestcourses.community','requestcourses.textbook',
262: 'requestcourses.placement');
263: @usertools = ('official','unofficial','community','textbook','placement');
1.309 raeburn 264: @options =('norequest','approval','autolimit','validate');
1.306 raeburn 265: %validations = &Apache::lonnet::auto_courserequest_checks($ccdomain);
266: %reqtitles = &courserequest_titles();
267: %reqdisplay = &courserequest_display();
268: $colspan = ' colspan="2"';
1.332 raeburn 269: %domconfig =
270: &Apache::lonnet::get_dom('configuration',['requestcourses'],$ccdomain);
1.418 raeburn 271: $isadv = &Apache::lonnet::is_advanced_user($ccdomain,$ccuname);
1.362 raeburn 272: } elsif ($context eq 'requestauthor') {
273: %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
274: 'requestauthor');
275: @usertools = ('requestauthor');
276: @options =('norequest','approval','automatic');
277: %reqtitles = &requestauthor_titles();
278: %reqdisplay = &requestauthor_display();
279: $colspan = ' colspan="2"';
280: %domconfig =
281: &Apache::lonnet::get_dom('configuration',['requestauthor'],$ccdomain);
1.275 raeburn 282: } else {
283: %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
1.361 raeburn 284: 'tools.aboutme','tools.portfolio','tools.blog',
285: 'tools.webdav');
286: @usertools = ('aboutme','blog','webdav','portfolio');
1.275 raeburn 287: }
288: foreach my $item (@usertools) {
1.306 raeburn 289: my ($custom_access,$curr_access,$cust_on,$cust_off,$tool_on,$tool_off,
290: $currdisp,$custdisp,$custradio);
1.275 raeburn 291: $cust_off = 'checked="checked" ';
292: $tool_on = 'checked="checked" ';
293: $curr_access =
294: &Apache::lonnet::usertools_access($ccuname,$ccdomain,$item,undef,
295: $context);
1.362 raeburn 296: if ($context eq 'requestauthor') {
297: if ($userenv{$context} ne '') {
298: $cust_on = ' checked="checked" ';
299: $cust_off = '';
300: }
301: } elsif ($userenv{$context.'.'.$item} ne '') {
1.306 raeburn 302: $cust_on = ' checked="checked" ';
303: $cust_off = '';
304: }
305: if ($context eq 'requestcourses') {
306: if ($userenv{$context.'.'.$item} eq '') {
1.314 raeburn 307: $custom_access = &mt('Currently from default setting.');
1.306 raeburn 308: } else {
309: $custom_access = &mt('Currently from custom setting.');
1.275 raeburn 310: }
1.362 raeburn 311: } elsif ($context eq 'requestauthor') {
312: if ($userenv{$context} eq '') {
313: $custom_access = &mt('Currently from default setting.');
314: } else {
315: $custom_access = &mt('Currently from custom setting.');
316: }
1.275 raeburn 317: } else {
1.306 raeburn 318: if ($userenv{$context.'.'.$item} eq '') {
1.314 raeburn 319: $custom_access =
1.306 raeburn 320: &mt('Availability determined currently from default setting.');
321: if (!$curr_access) {
322: $tool_off = 'checked="checked" ';
323: $tool_on = '';
324: }
325: } else {
1.314 raeburn 326: $custom_access =
1.306 raeburn 327: &mt('Availability determined currently from custom setting.');
328: if ($userenv{$context.'.'.$item} == 0) {
329: $tool_off = 'checked="checked" ';
330: $tool_on = '';
331: }
1.275 raeburn 332: }
333: }
334: $output .= ' <tr class="LC_info_row">'."\n".
1.306 raeburn 335: ' <td'.$colspan.'>'.$lt{$item}.'</td>'."\n".
1.275 raeburn 336: ' </tr>'."\n".
1.306 raeburn 337: &Apache::loncommon::start_data_table_row()."\n";
1.418 raeburn 338:
1.362 raeburn 339: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.306 raeburn 340: my ($curroption,$currlimit);
1.362 raeburn 341: my $envkey = $context.'.'.$item;
342: if ($context eq 'requestauthor') {
343: $envkey = $context;
344: }
345: if ($userenv{$envkey} ne '') {
346: $curroption = $userenv{$envkey};
1.332 raeburn 347: } else {
348: my (@inststatuses);
1.362 raeburn 349: if ($context eq 'requestcourses') {
350: $curroption =
351: &Apache::loncoursequeueadmin::get_processtype('course',$ccuname,$ccdomain,
352: $isadv,$ccdomain,$item,
353: \@inststatuses,\%domconfig);
354: } else {
355: $curroption =
356: &Apache::loncoursequeueadmin::get_processtype('requestauthor',$ccuname,$ccdomain,
357: $isadv,$ccdomain,undef,
358: \@inststatuses,\%domconfig);
359: }
1.332 raeburn 360: }
1.306 raeburn 361: if (!$curroption) {
362: $curroption = 'norequest';
363: }
364: if ($curroption =~ /^autolimit=(\d*)$/) {
365: $currlimit = $1;
1.314 raeburn 366: if ($currlimit eq '') {
367: $currdisp = &mt('Yes, automatic creation');
368: } else {
369: $currdisp = &mt('Yes, up to [quant,_1,request]/user',$currlimit);
370: }
1.306 raeburn 371: } else {
372: $currdisp = $reqdisplay{$curroption};
373: }
374: $custdisp = '<table>';
375: foreach my $option (@options) {
376: my $val = $option;
377: if ($option eq 'norequest') {
378: $val = 0;
379: }
380: if ($option eq 'validate') {
381: my $canvalidate = 0;
382: if (ref($validations{$item}) eq 'HASH') {
383: if ($validations{$item}{'_custom_'}) {
384: $canvalidate = 1;
385: }
386: }
387: next if (!$canvalidate);
388: }
389: my $checked = '';
390: if ($option eq $curroption) {
391: $checked = ' checked="checked"';
392: } elsif ($option eq 'autolimit') {
393: if ($curroption =~ /^autolimit/) {
394: $checked = ' checked="checked"';
395: }
396: }
1.362 raeburn 397: my $name = 'crsreq_'.$item;
398: if ($context eq 'requestauthor') {
399: $name = $item;
400: }
1.306 raeburn 401: $custdisp .= '<tr><td><span class="LC_nobreak"><label>'.
1.362 raeburn 402: '<input type="radio" name="'.$name.'" '.
403: 'value="'.$val.'"'.$checked.' />'.
1.306 raeburn 404: $reqtitles{$option}.'</label> ';
405: if ($option eq 'autolimit') {
1.362 raeburn 406: $custdisp .= '<input type="text" name="'.$name.
407: '_limit" size="1" '.
1.314 raeburn 408: 'value="'.$currlimit.'" /></span><br />'.
409: $reqtitles{'unlimited'};
1.362 raeburn 410: } else {
411: $custdisp .= '</span>';
412: }
413: $custdisp .= '</td></tr>';
1.306 raeburn 414: }
415: $custdisp .= '</table>';
416: $custradio = '</span></td><td>'.&mt('Custom setting').'<br />'.$custdisp;
417: } else {
418: $currdisp = ($curr_access?&mt('Yes'):&mt('No'));
1.362 raeburn 419: my $name = $context.'_'.$item;
420: if ($context eq 'requestauthor') {
421: $name = $context;
422: }
1.306 raeburn 423: $custdisp = '<span class="LC_nobreak"><label>'.
1.362 raeburn 424: '<input type="radio" name="'.$name.'"'.
1.361 raeburn 425: ' value="1" '.$tool_on.'/>'.&mt('On').'</label> <label>'.
1.362 raeburn 426: '<input type="radio" name="'.$name.'" value="0" '.
1.306 raeburn 427: $tool_off.'/>'.&mt('Off').'</label></span>';
428: $custradio = (' 'x2).'--'.$lt{'cusa'}.': '.$custdisp.
429: '</span>';
430: }
431: $output .= ' <td'.$colspan.'>'.$custom_access.(' 'x4).
1.419 raeburn 432: $lt{'avai'}.': '.$currdisp.'</td>'."\n".
1.418 raeburn 433: &Apache::loncommon::end_data_table_row()."\n";
434: unless (&Apache::lonnet::allowed('udp',$ccdomain)) {
435: $output .=
1.275 raeburn 436: &Apache::loncommon::start_data_table_row()."\n".
1.306 raeburn 437: ' <td style="vertical-align:top;"><span class="LC_nobreak">'.
438: $lt{'chse'}.': <label>'.
1.275 raeburn 439: '<input type="radio" name="custom'.$item.'" value="0" '.
1.306 raeburn 440: $cust_off.'/>'.$lt{'usde'}.'</label>'.(' ' x3).
441: '<label><input type="radio" name="custom'.$item.'" value="1" '.
442: $cust_on.'/>'.$lt{'uscu'}.'</label>'.$custradio.'</td>'.
1.275 raeburn 443: &Apache::loncommon::end_data_table_row()."\n";
1.418 raeburn 444: }
1.275 raeburn 445: }
446: return $output;
447: }
448:
1.300 raeburn 449: sub coursereq_externaluser {
450: my ($ccuname,$ccdomain,$cdom) = @_;
1.306 raeburn 451: my (@usertools,@options,%validations,%userenv,$output);
1.300 raeburn 452: my %lt = &Apache::lonlocal::texthash (
453: 'official' => 'Can request creation of official courses',
454: 'unofficial' => 'Can request creation of unofficial courses',
455: 'community' => 'Can request creation of communities',
1.384 raeburn 456: 'textbook' => 'Can request creation of textbook courses',
1.411 raeburn 457: 'placement' => 'Can request creation of placement tests',
1.300 raeburn 458: );
459:
460: %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
461: 'reqcrsotherdom.official','reqcrsotherdom.unofficial',
1.411 raeburn 462: 'reqcrsotherdom.community','reqcrsotherdom.textbook',
463: 'reqcrsotherdom.placement');
464: @usertools = ('official','unofficial','community','textbook','placement');
1.309 raeburn 465: @options = ('approval','validate','autolimit');
1.306 raeburn 466: %validations = &Apache::lonnet::auto_courserequest_checks($cdom);
467: my $optregex = join('|',@options);
468: my %reqtitles = &courserequest_titles();
1.300 raeburn 469: foreach my $item (@usertools) {
1.306 raeburn 470: my ($curroption,$currlimit,$tooloff);
1.300 raeburn 471: if ($userenv{'reqcrsotherdom.'.$item} ne '') {
472: my @curr = split(',',$userenv{'reqcrsotherdom.'.$item});
1.314 raeburn 473: foreach my $req (@curr) {
474: if ($req =~ /^\Q$cdom\E\:($optregex)=?(\d*)$/) {
475: $curroption = $1;
476: $currlimit = $2;
477: last;
1.306 raeburn 478: }
479: }
1.314 raeburn 480: if (!$curroption) {
481: $curroption = 'norequest';
482: $tooloff = ' checked="checked"';
483: }
1.306 raeburn 484: } else {
485: $curroption = 'norequest';
486: $tooloff = ' checked="checked"';
487: }
488: $output.= &Apache::loncommon::start_data_table_row()."\n".
1.314 raeburn 489: ' <td><span class="LC_nobreak">'.$lt{$item}.': </span></td><td>'.
490: '<table><tr><td valign="top">'."\n".
1.306 raeburn 491: '<label><input type="radio" name="reqcrsotherdom_'.$item.
1.314 raeburn 492: '" value=""'.$tooloff.' />'.$reqtitles{'norequest'}.
493: '</label></td>';
1.306 raeburn 494: foreach my $option (@options) {
495: if ($option eq 'validate') {
496: my $canvalidate = 0;
497: if (ref($validations{$item}) eq 'HASH') {
498: if ($validations{$item}{'_external_'}) {
499: $canvalidate = 1;
500: }
501: }
502: next if (!$canvalidate);
503: }
504: my $checked = '';
505: if ($option eq $curroption) {
506: $checked = ' checked="checked"';
507: }
1.314 raeburn 508: $output .= '<td valign="top"><span class="LC_nobreak"><label>'.
1.306 raeburn 509: '<input type="radio" name="reqcrsotherdom_'.$item.
510: '" value="'.$option.'"'.$checked.' />'.
1.314 raeburn 511: $reqtitles{$option}.'</label>';
1.306 raeburn 512: if ($option eq 'autolimit') {
1.314 raeburn 513: $output .= ' <input type="text" name="reqcrsotherdom_'.
1.306 raeburn 514: $item.'_limit" size="1" '.
1.314 raeburn 515: 'value="'.$currlimit.'" /></span>'.
516: '<br />'.$reqtitles{'unlimited'};
517: } else {
518: $output .= '</span>';
1.300 raeburn 519: }
1.314 raeburn 520: $output .= '</td>';
1.300 raeburn 521: }
1.314 raeburn 522: $output .= '</td></tr></table></td>'."\n".
1.300 raeburn 523: &Apache::loncommon::end_data_table_row()."\n";
524: }
525: return $output;
526: }
527:
1.362 raeburn 528: sub domainrole_req {
529: my ($ccuname,$ccdomain) = @_;
530: return '<br /><h3>'.
531: &mt('User Can Request Assignment of Domain Roles?').
532: '</h3>'."\n".
533: &Apache::loncommon::start_data_table().
534: &build_tools_display($ccuname,$ccdomain,
535: 'requestauthor').
536: &Apache::loncommon::end_data_table();
537: }
538:
1.306 raeburn 539: sub courserequest_titles {
540: my %titles = &Apache::lonlocal::texthash (
541: official => 'Official',
542: unofficial => 'Unofficial',
543: community => 'Communities',
1.384 raeburn 544: textbook => 'Textbook',
1.411 raeburn 545: placement => 'Placement Tests',
1.306 raeburn 546: norequest => 'Not allowed',
1.309 raeburn 547: approval => 'Approval by Dom. Coord.',
1.306 raeburn 548: validate => 'With validation',
549: autolimit => 'Numerical limit',
1.314 raeburn 550: unlimited => '(blank for unlimited)',
1.306 raeburn 551: );
552: return %titles;
553: }
554:
555: sub courserequest_display {
556: my %titles = &Apache::lonlocal::texthash (
1.309 raeburn 557: approval => 'Yes, need approval',
1.306 raeburn 558: validate => 'Yes, with validation',
559: norequest => 'No',
560: );
561: return %titles;
562: }
563:
1.362 raeburn 564: sub requestauthor_titles {
565: my %titles = &Apache::lonlocal::texthash (
566: norequest => 'Not allowed',
567: approval => 'Approval by Dom. Coord.',
568: automatic => 'Automatic approval',
569: );
570: return %titles;
571:
572: }
573:
574: sub requestauthor_display {
575: my %titles = &Apache::lonlocal::texthash (
576: approval => 'Yes, need approval',
577: automatic => 'Yes, automatic approval',
578: norequest => 'No',
579: );
580: return %titles;
581: }
582:
1.383 raeburn 583: sub requestchange_display {
584: my %titles = &Apache::lonlocal::texthash (
585: approval => "availability set to 'on' (approval required)",
586: automatic => "availability set to 'on' (automatic approval)",
587: norequest => "availability set to 'off'",
588: );
589: return %titles;
590: }
591:
1.362 raeburn 592: sub curr_requestauthor {
593: my ($uname,$udom,$isadv,$inststatuses,$domconfig) = @_;
594: return unless ((ref($inststatuses) eq 'ARRAY') && (ref($domconfig) eq 'HASH'));
595: if ($uname eq '' || $udom eq '') {
596: $uname = $env{'user.name'};
597: $udom = $env{'user.domain'};
598: $isadv = $env{'user.adv'};
599: }
600: my (%userenv,%settings,$val);
601: my @options = ('automatic','approval');
602: %userenv =
603: &Apache::lonnet::userenvironment($udom,$uname,'requestauthor','inststatus');
604: if ($userenv{'requestauthor'}) {
605: $val = $userenv{'requestauthor'};
606: @{$inststatuses} = ('_custom_');
607: } else {
608: my %alltasks;
609: if (ref($domconfig->{'requestauthor'}) eq 'HASH') {
610: %settings = %{$domconfig->{'requestauthor'}};
611: if (($isadv) && ($settings{'_LC_adv'} ne '')) {
612: $val = $settings{'_LC_adv'};
613: @{$inststatuses} = ('_LC_adv_');
614: } else {
615: if ($userenv{'inststatus'} ne '') {
616: @{$inststatuses} = split(',',$userenv{'inststatus'});
617: } else {
618: @{$inststatuses} = ('default');
619: }
620: foreach my $status (@{$inststatuses}) {
621: if (exists($settings{$status})) {
622: my $value = $settings{$status};
623: next unless ($value);
624: unless (exists($alltasks{$value})) {
625: if (ref($alltasks{$value}) eq 'ARRAY') {
626: unless(grep(/^\Q$status\E$/,@{$alltasks{$value}})) {
627: push(@{$alltasks{$value}},$status);
628: }
629: } else {
630: @{$alltasks{$value}} = ($status);
631: }
632: }
633: }
634: }
635: foreach my $option (@options) {
636: if ($alltasks{$option}) {
637: $val = $option;
638: last;
639: }
640: }
641: }
642: }
643: }
644: return $val;
645: }
646:
1.2 www 647: # =================================================================== Phase one
1.1 www 648:
1.42 matthew 649: sub print_username_entry_form {
1.439 raeburn 650: my ($r,$context,$response,$srch,$forcenewuser,$crstype,$brcrum,
651: $permission) = @_;
1.101 albertel 652: my $defdom=$env{'request.role.domain'};
1.160 raeburn 653: my $formtoset = 'crtuser';
654: if (exists($env{'form.startrolename'})) {
655: $formtoset = 'docustom';
656: $env{'form.rolename'} = $env{'form.startrolename'};
1.207 raeburn 657: } elsif ($env{'form.origform'} eq 'crtusername') {
658: $formtoset = $env{'form.origform'};
1.160 raeburn 659: }
660:
661: my ($jsback,$elements) = &crumb_utilities();
662:
663: my $jscript = &Apache::loncommon::studentbrowser_javascript()."\n".
1.165 albertel 664: '<script type="text/javascript">'."\n".
1.301 bisitz 665: '// <![CDATA['."\n".
666: &Apache::lonhtmlcommon::set_form_elements($elements->{$formtoset})."\n".
667: '// ]]>'."\n".
1.162 raeburn 668: '</script>'."\n";
1.160 raeburn 669:
1.324 raeburn 670: my %existingroles=&Apache::lonuserutils::my_custom_roles($crstype);
671: if (($env{'form.action'} eq 'custom') && (keys(%existingroles) > 0)
672: && (&Apache::lonnet::allowed('mcr','/'))) {
673: $jscript .= &customrole_javascript();
674: }
1.224 raeburn 675: my $helpitem = 'Course_Change_Privileges';
676: if ($env{'form.action'} eq 'custom') {
1.439 raeburn 677: if ($context eq 'course') {
678: $helpitem = 'Course_Editing_Custom_Roles';
679: } elsif ($context eq 'domain') {
680: $helpitem = 'Domain_Editing_Custom_Roles';
681: }
1.224 raeburn 682: } elsif ($env{'form.action'} eq 'singlestudent') {
683: $helpitem = 'Course_Add_Student';
1.416 raeburn 684: } elsif ($env{'form.action'} eq 'accesslogs') {
685: $helpitem = 'Domain_User_Access_Logs';
1.439 raeburn 686: } elsif ($context eq 'author') {
687: $helpitem = 'Author_Change_Privileges';
688: } elsif ($context eq 'domain') {
689: if ($permission->{'cusr'}) {
690: $helpitem = 'Domain_Change_Privileges';
691: } elsif ($permission->{'view'}) {
692: $helpitem = 'Domain_View_Privileges';
693: } else {
694: undef($helpitem);
695: }
1.224 raeburn 696: }
1.422 raeburn 697: my %breadcrumb_text = &singleuser_breadcrumb($crstype,$context,$defdom);
1.351 raeburn 698: if ($env{'form.action'} eq 'custom') {
699: push(@{$brcrum},
700: {href=>"javascript:backPage(document.crtuser)",
701: text=>"Pick custom role",
702: help => $helpitem,}
703: );
704: } else {
705: push (@{$brcrum},
706: {href => "javascript:backPage(document.crtuser)",
707: text => $breadcrumb_text{'search'},
708: help => $helpitem,
709: faq => 282,
710: bug => 'Instructor Interface',}
711: );
712: }
713: my %loaditems = (
714: 'onload' => "javascript:setFormElements(document.$formtoset)",
715: );
716: my $args = {bread_crumbs => $brcrum,
717: bread_crumbs_component => 'User Management',
718: add_entries => \%loaditems,};
719: $r->print(&Apache::loncommon::start_page('User Management',$jscript,$args));
720:
1.71 sakharuk 721: my %lt=&Apache::lonlocal::texthash(
1.229 raeburn 722: 'srst' => 'Search for a user and enroll as a student',
1.318 raeburn 723: 'srme' => 'Search for a user and enroll as a member',
1.229 raeburn 724: 'srad' => 'Search for a user and modify/add user information or roles',
1.422 raeburn 725: 'srvu' => 'Search for a user and view user information and roles',
1.416 raeburn 726: 'srva' => 'Search for a user and view access log information',
1.71 sakharuk 727: 'usr' => "Username",
728: 'dom' => "Domain",
1.324 raeburn 729: 'ecrp' => "Define or Edit Custom Role",
730: 'nr' => "role name",
1.282 schafran 731: 'cre' => "Next",
1.71 sakharuk 732: );
1.351 raeburn 733:
1.214 raeburn 734: if ($env{'form.action'} eq 'custom') {
1.190 raeburn 735: if (&Apache::lonnet::allowed('mcr','/')) {
1.324 raeburn 736: my $newroletext = &mt('Define new custom role:');
737: $r->print('<form action="/adm/createuser" method="post" name="docustom">'.
738: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'.
739: '<input type="hidden" name="phase" value="selected_custom_edit" />'.
740: '<h3>'.$lt{'ecrp'}.'</h3>'.
741: &Apache::loncommon::start_data_table().
742: &Apache::loncommon::start_data_table_row().
743: '<td>');
744: if (keys(%existingroles) > 0) {
745: $r->print('<br /><label><input type="radio" name="customroleaction" value="new" checked="checked" onclick="setCustomFields();" /><b>'.$newroletext.'</b></label>');
746: } else {
747: $r->print('<br /><input type="hidden" name="customroleaction" value="new" /><b>'.$newroletext.'</b>');
748: }
749: $r->print('</td><td align="center">'.$lt{'nr'}.'<br /><input type="text" size="15" name="newrolename" onfocus="setCustomAction('."'new'".');" /></td>'.
750: &Apache::loncommon::end_data_table_row());
751: if (keys(%existingroles) > 0) {
752: $r->print(&Apache::loncommon::start_data_table_row().'<td><br />'.
753: '<label><input type="radio" name="customroleaction" value="edit" onclick="setCustomFields();"/><b>'.
754: &mt('View/Modify existing role:').'</b></label></td>'.
755: '<td align="center"><br />'.
756: '<select name="rolename" onchange="setCustomAction('."'edit'".');">'.
1.326 raeburn 757: '<option value="" selected="selected">'.
1.324 raeburn 758: &mt('Select'));
759: foreach my $role (sort(keys(%existingroles))) {
1.326 raeburn 760: $r->print('<option value="'.$role.'">'.$role.'</option>');
1.324 raeburn 761: }
762: $r->print('</select>'.
763: '</td>'.
764: &Apache::loncommon::end_data_table_row());
765: }
766: $r->print(&Apache::loncommon::end_data_table().'<p>'.
767: '<input name="customeditor" type="submit" value="'.
768: $lt{'cre'}.'" /></p>'.
769: '</form>');
1.190 raeburn 770: }
1.213 raeburn 771: } else {
1.229 raeburn 772: my $actiontext = $lt{'srad'};
1.436 raeburn 773: my $fixeddom;
1.213 raeburn 774: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 775: if ($crstype eq 'Community') {
776: $actiontext = $lt{'srme'};
777: } else {
778: $actiontext = $lt{'srst'};
779: }
1.416 raeburn 780: } elsif ($env{'form.action'} eq 'accesslogs') {
1.417 raeburn 781: $actiontext = $lt{'srva'};
1.436 raeburn 782: $fixeddom = 1;
1.422 raeburn 783: } elsif (($env{'form.action'} eq 'singleuser') &&
784: ($context eq 'domain') && (!&Apache::lonnet::allowed('mau',$defdom))) {
785: $actiontext = $lt{'srvu'};
1.439 raeburn 786: $fixeddom = 1;
1.213 raeburn 787: }
1.324 raeburn 788: $r->print("<h3>$actiontext</h3>");
1.213 raeburn 789: if ($env{'form.origform'} ne 'crtusername') {
1.415 raeburn 790: if ($response) {
791: $r->print("\n<div>$response</div>".
792: '<br clear="all" />');
793: }
1.213 raeburn 794: }
1.436 raeburn 795: $r->print(&entry_form($defdom,$srch,$forcenewuser,$context,$response,$crstype,$fixeddom));
1.107 www 796: }
1.110 albertel 797: }
798:
1.324 raeburn 799: sub customrole_javascript {
800: my $js = <<"END";
801: <script type="text/javascript">
802: // <![CDATA[
803:
804: function setCustomFields() {
805: if (document.docustom.customroleaction.length > 0) {
806: for (var i=0; i<document.docustom.customroleaction.length; i++) {
807: if (document.docustom.customroleaction[i].checked) {
808: if (document.docustom.customroleaction[i].value == 'new') {
809: document.docustom.rolename.selectedIndex = 0;
810: } else {
811: document.docustom.newrolename.value = '';
812: }
813: }
814: }
815: }
816: return;
817: }
818:
819: function setCustomAction(caller) {
820: if (document.docustom.customroleaction.length > 0) {
821: for (var i=0; i<document.docustom.customroleaction.length; i++) {
822: if (document.docustom.customroleaction[i].value == caller) {
823: document.docustom.customroleaction[i].checked = true;
824: }
825: }
826: }
827: setCustomFields();
828: return;
829: }
830:
831: // ]]>
832: </script>
833: END
834: return $js;
835: }
836:
1.160 raeburn 837: sub entry_form {
1.416 raeburn 838: my ($dom,$srch,$forcenewuser,$context,$responsemsg,$crstype,$fixeddom) = @_;
1.229 raeburn 839: my ($usertype,$inexact);
1.214 raeburn 840: if (ref($srch) eq 'HASH') {
841: if (($srch->{'srchin'} eq 'dom') &&
842: ($srch->{'srchby'} eq 'uname') &&
843: ($srch->{'srchtype'} eq 'exact') &&
844: ($srch->{'srchdomain'} ne '') &&
845: ($srch->{'srchterm'} ne '')) {
1.353 raeburn 846: my (%curr_rules,%got_rules);
1.214 raeburn 847: my ($rules,$ruleorder) =
848: &Apache::lonnet::inst_userrules($srch->{'srchdomain'},'username');
1.353 raeburn 849: $usertype = &Apache::lonuserutils::check_usertype($srch->{'srchdomain'},$srch->{'srchterm'},$rules,\%curr_rules,\%got_rules);
1.229 raeburn 850: } else {
851: $inexact = 1;
1.214 raeburn 852: }
1.207 raeburn 853: }
1.438 raeburn 854: my ($cancreate,$noinstd);
855: if ($env{'form.action'} eq 'accesslogs') {
856: $noinstd = 1;
857: } else {
858: $cancreate =
859: &Apache::lonuserutils::can_create_user($dom,$context,$usertype);
860: }
1.412 raeburn 861: my ($userpicker,$cansearch) =
1.179 raeburn 862: &Apache::loncommon::user_picker($dom,$srch,$forcenewuser,
1.438 raeburn 863: 'document.crtuser',$cancreate,$usertype,$context,$fixeddom,$noinstd);
1.160 raeburn 864: my $srchbutton = &mt('Search');
1.229 raeburn 865: if ($env{'form.action'} eq 'singlestudent') {
866: $srchbutton = &mt('Search and Enroll');
1.416 raeburn 867: } elsif ($env{'form.action'} eq 'accesslogs') {
868: $srchbutton = &mt('Search');
1.229 raeburn 869: } elsif ($cancreate && $responsemsg ne '' && $inexact) {
870: $srchbutton = &mt('Search or Add New User');
871: }
1.412 raeburn 872: my $output;
873: if ($cansearch) {
874: $output = <<"ENDBLOCK";
1.160 raeburn 875: <form action="/adm/createuser" method="post" name="crtuser">
1.190 raeburn 876: <input type="hidden" name="action" value="$env{'form.action'}" />
1.160 raeburn 877: <input type="hidden" name="phase" value="get_user_info" />
878: $userpicker
1.179 raeburn 879: <input name="userrole" type="button" value="$srchbutton" onclick="javascript:validateEntry(document.crtuser)" />
1.160 raeburn 880: </form>
1.207 raeburn 881: ENDBLOCK
1.412 raeburn 882: } else {
883: $output = '<p>'.$userpicker.'</p>';
884: }
1.422 raeburn 885: if (($env{'form.phase'} eq '') && ($env{'form.action'} ne 'accesslogs') &&
1.430 raeburn 886: (!(($env{'form.action'} eq 'singleuser') && ($context eq 'domain') &&
1.422 raeburn 887: (!&Apache::lonnet::allowed('mau',$env{'request.role.domain'}))))) {
1.207 raeburn 888: my $defdom=$env{'request.role.domain'};
1.446 raeburn 889: my ($trusted,$untrusted);
1.444 raeburn 890: if ($context eq 'course') {
1.446 raeburn 891: ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('enroll',$defdom);
1.444 raeburn 892: } elsif ($context eq 'author') {
1.446 raeburn 893: ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('othcoau',$defdom);
1.444 raeburn 894: } elsif ($context eq 'domain') {
1.446 raeburn 895: ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('domroles',$defdom);
1.444 raeburn 896: }
1.446 raeburn 897: my $domform = &Apache::loncommon::select_dom_form($defdom,'srchdomain',undef,undef,undef,$trusted,$untrusted);
1.207 raeburn 898: my %lt=&Apache::lonlocal::texthash(
1.229 raeburn 899: 'enro' => 'Enroll one student',
1.318 raeburn 900: 'enrm' => 'Enroll one member',
1.229 raeburn 901: 'admo' => 'Add/modify a single user',
902: 'crea' => 'create new user if required',
903: 'uskn' => "username is known",
1.207 raeburn 904: 'crnu' => 'Create a new user',
905: 'usr' => 'Username',
906: 'dom' => 'in domain',
1.229 raeburn 907: 'enrl' => 'Enroll',
908: 'cram' => 'Create/Modify user',
1.207 raeburn 909: );
1.229 raeburn 910: my $sellink=&Apache::loncommon::selectstudent_link('crtusername','srchterm','srchdomain');
911: my ($title,$buttontext,$showresponse);
1.318 raeburn 912: if ($env{'form.action'} eq 'singlestudent') {
913: if ($crstype eq 'Community') {
914: $title = $lt{'enrm'};
915: } else {
916: $title = $lt{'enro'};
917: }
1.229 raeburn 918: $buttontext = $lt{'enrl'};
919: } else {
920: $title = $lt{'admo'};
921: $buttontext = $lt{'cram'};
922: }
923: if ($cancreate) {
924: $title .= ' <span class="LC_cusr_subheading">('.$lt{'crea'}.')</span>';
925: } else {
926: $title .= ' <span class="LC_cusr_subheading">('.$lt{'uskn'}.')</span>';
927: }
928: if ($env{'form.origform'} eq 'crtusername') {
929: $showresponse = $responsemsg;
930: }
1.207 raeburn 931: $output .= <<"ENDDOCUMENT";
1.229 raeburn 932: <br />
1.207 raeburn 933: <form action="/adm/createuser" method="post" name="crtusername">
934: <input type="hidden" name="action" value="$env{'form.action'}" />
935: <input type="hidden" name="phase" value="createnewuser" />
936: <input type="hidden" name="srchtype" value="exact" />
1.233 raeburn 937: <input type="hidden" name="srchby" value="uname" />
1.207 raeburn 938: <input type="hidden" name="srchin" value="dom" />
939: <input type="hidden" name="forcenewuser" value="1" />
940: <input type="hidden" name="origform" value="crtusername" />
1.229 raeburn 941: <h3>$title</h3>
942: $showresponse
1.207 raeburn 943: <table>
944: <tr>
945: <td>$lt{'usr'}:</td>
946: <td><input type="text" size="15" name="srchterm" /></td>
947: <td> $lt{'dom'}:</td><td>$domform</td>
1.229 raeburn 948: <td> $sellink </td>
949: <td> <input name="userrole" type="submit" value="$buttontext" /></td>
1.207 raeburn 950: </tr>
951: </table>
952: </form>
1.160 raeburn 953: ENDDOCUMENT
1.207 raeburn 954: }
1.160 raeburn 955: return $output;
956: }
1.110 albertel 957:
958: sub user_modification_js {
1.113 raeburn 959: my ($pjump_def,$dc_setcourse_code,$nondc_setsection_code,$groupslist)=@_;
960:
1.110 albertel 961: return <<END;
962: <script type="text/javascript" language="Javascript">
1.301 bisitz 963: // <![CDATA[
1.314 raeburn 964:
1.110 albertel 965: $pjump_def
966: $dc_setcourse_code
967:
968: function dateset() {
969: eval("document.cu."+document.cu.pres_marker.value+
970: ".value=document.cu.pres_value.value");
1.359 www 971: modalWindow.close();
1.110 albertel 972: }
973:
1.113 raeburn 974: $nondc_setsection_code
1.301 bisitz 975: // ]]>
1.110 albertel 976: </script>
977: END
1.2 www 978: }
979:
980: # =================================================================== Phase two
1.160 raeburn 981: sub print_user_selection_page {
1.351 raeburn 982: my ($r,$response,$srch,$srch_results,$srcharray,$context,$opener_elements,$crstype,$brcrum) = @_;
1.160 raeburn 983: my @fields = ('username','domain','lastname','firstname','permanentemail');
984: my $sortby = $env{'form.sortby'};
985:
986: if (!grep(/^\Q$sortby\E$/,@fields)) {
987: $sortby = 'lastname';
988: }
989:
990: my ($jsback,$elements) = &crumb_utilities();
991:
992: my $jscript = (<<ENDSCRIPT);
993: <script type="text/javascript">
1.301 bisitz 994: // <![CDATA[
1.160 raeburn 995: function pickuser(uname,udom) {
996: document.usersrchform.seluname.value=uname;
997: document.usersrchform.seludom.value=udom;
998: document.usersrchform.phase.value="userpicked";
999: document.usersrchform.submit();
1000: }
1001:
1002: $jsback
1.301 bisitz 1003: // ]]>
1.160 raeburn 1004: </script>
1005: ENDSCRIPT
1006:
1007: my %lt=&Apache::lonlocal::texthash(
1.179 raeburn 1008: 'usrch' => "User Search to add/modify roles",
1009: 'stusrch' => "User Search to enroll student",
1.318 raeburn 1010: 'memsrch' => "User Search to enroll member",
1.416 raeburn 1011: 'srcva' => "Search for a user and view access log information",
1.422 raeburn 1012: 'usrvu' => "User Search to view user roles",
1.179 raeburn 1013: 'usel' => "Select a user to add/modify roles",
1.422 raeburn 1014: 'suvr' => "Select a user to view roles",
1.318 raeburn 1015: 'stusel' => "Select a user to enroll as a student",
1016: 'memsel' => "Select a user to enroll as a member",
1.416 raeburn 1017: 'vacsel' => "Select a user to view access log",
1.160 raeburn 1018: 'username' => "username",
1019: 'domain' => "domain",
1020: 'lastname' => "last name",
1021: 'firstname' => "first name",
1022: 'permanentemail' => "permanent e-mail",
1023: );
1.302 raeburn 1024: if ($context eq 'requestcrs') {
1025: $r->print('<div>');
1026: } else {
1.422 raeburn 1027: my %breadcrumb_text = &singleuser_breadcrumb($crstype,$context,$srch->{'srchdomain'});
1.351 raeburn 1028: my $helpitem;
1029: if ($env{'form.action'} eq 'singleuser') {
1030: $helpitem = 'Course_Change_Privileges';
1031: } elsif ($env{'form.action'} eq 'singlestudent') {
1032: $helpitem = 'Course_Add_Student';
1.439 raeburn 1033: } elsif ($context eq 'author') {
1034: $helpitem = 'Author_Change_Privileges';
1035: } elsif ($context eq 'domain') {
1036: $helpitem = 'Domain_Change_Privileges';
1.351 raeburn 1037: }
1038: push (@{$brcrum},
1039: {href => "javascript:backPage(document.usersrchform,'','')",
1040: text => $breadcrumb_text{'search'},
1041: faq => 282,
1042: bug => 'Instructor Interface',},
1043: {href => "javascript:backPage(document.usersrchform,'get_user_info','select')",
1044: text => $breadcrumb_text{'userpicked'},
1045: faq => 282,
1046: bug => 'Instructor Interface',
1047: help => $helpitem}
1048: );
1049: $r->print(&Apache::loncommon::start_page('User Management',$jscript,{bread_crumbs => $brcrum}));
1.302 raeburn 1050: if ($env{'form.action'} eq 'singleuser') {
1.422 raeburn 1051: my $readonly;
1052: if (($context eq 'domain') && (!&Apache::lonnet::allowed('mau',$srch->{'srchdomain'}))) {
1053: $readonly = 1;
1054: $r->print("<b>$lt{'usrvu'}</b><br />");
1055: } else {
1056: $r->print("<b>$lt{'usrch'}</b><br />");
1057: }
1.318 raeburn 1058: $r->print(&entry_form($srch->{'srchdomain'},$srch,undef,$context,undef,$crstype));
1.422 raeburn 1059: if ($readonly) {
1060: $r->print('<h3>'.$lt{'suvr'}.'</h3>');
1061: } else {
1062: $r->print('<h3>'.$lt{'usel'}.'</h3>');
1063: }
1.302 raeburn 1064: } elsif ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1065: $r->print($jscript."<b>");
1066: if ($crstype eq 'Community') {
1067: $r->print($lt{'memsrch'});
1068: } else {
1069: $r->print($lt{'stusrch'});
1070: }
1071: $r->print("</b><br />");
1072: $r->print(&entry_form($srch->{'srchdomain'},$srch,undef,$context,undef,$crstype));
1073: $r->print('</form><h3>');
1074: if ($crstype eq 'Community') {
1075: $r->print($lt{'memsel'});
1076: } else {
1077: $r->print($lt{'stusel'});
1078: }
1079: $r->print('</h3>');
1.416 raeburn 1080: } elsif ($env{'form.action'} eq 'accesslogs') {
1081: $r->print("<b>$lt{'srcva'}</b><br />");
1.438 raeburn 1082: $r->print(&entry_form($srch->{'srchdomain'},$srch,undef,$context,undef,undef,1));
1.416 raeburn 1083: $r->print('<h3>'.$lt{'vacsel'}.'</h3>');
1.302 raeburn 1084: }
1.179 raeburn 1085: }
1.380 bisitz 1086: $r->print('<form name="usersrchform" method="post" action="">'.
1.160 raeburn 1087: &Apache::loncommon::start_data_table()."\n".
1088: &Apache::loncommon::start_data_table_header_row()."\n".
1089: ' <th> </th>'."\n");
1090: foreach my $field (@fields) {
1091: $r->print(' <th><a href="javascript:document.usersrchform.sortby.value='.
1092: "'".$field."'".';document.usersrchform.submit();">'.
1093: $lt{$field}.'</a></th>'."\n");
1094: }
1095: $r->print(&Apache::loncommon::end_data_table_header_row());
1096:
1097: my @sorted_users = sort {
1.167 albertel 1098: lc($srch_results->{$a}->{$sortby}) cmp lc($srch_results->{$b}->{$sortby})
1.160 raeburn 1099: ||
1.167 albertel 1100: lc($srch_results->{$a}->{lastname}) cmp lc($srch_results->{$b}->{lastname})
1.160 raeburn 1101: ||
1102: lc($srch_results->{$a}->{firstname}) cmp lc($srch_results->{$b}->{firstname})
1.167 albertel 1103: ||
1104: lc($a) cmp lc($b)
1.160 raeburn 1105: } (keys(%$srch_results));
1106:
1107: foreach my $user (@sorted_users) {
1108: my ($uname,$udom) = split(/:/,$user);
1.302 raeburn 1109: my $onclick;
1110: if ($context eq 'requestcrs') {
1.314 raeburn 1111: $onclick =
1.302 raeburn 1112: 'onclick="javascript:gochoose('."'$uname','$udom',".
1113: "'$srch_results->{$user}->{firstname}',".
1114: "'$srch_results->{$user}->{lastname}',".
1115: "'$srch_results->{$user}->{permanentemail}'".');"';
1116: } else {
1.314 raeburn 1117: $onclick =
1.302 raeburn 1118: ' onclick="javascript:pickuser('."'".$uname."'".','."'".$udom."'".');"';
1119: }
1.160 raeburn 1120: $r->print(&Apache::loncommon::start_data_table_row().
1.302 raeburn 1121: '<td><input type="button" name="seluser" value="'.&mt('Select').'" '.
1122: $onclick.' /></td>'.
1.160 raeburn 1123: '<td><tt>'.$uname.'</tt></td>'.
1124: '<td><tt>'.$udom.'</tt></td>');
1125: foreach my $field ('lastname','firstname','permanentemail') {
1126: $r->print('<td>'.$srch_results->{$user}->{$field}.'</td>');
1127: }
1128: $r->print(&Apache::loncommon::end_data_table_row());
1129: }
1130: $r->print(&Apache::loncommon::end_data_table().'<br /><br />');
1.179 raeburn 1131: if (ref($srcharray) eq 'ARRAY') {
1132: foreach my $item (@{$srcharray}) {
1133: $r->print('<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n");
1134: }
1135: }
1.160 raeburn 1136: $r->print(' <input type="hidden" name="sortby" value="'.$sortby.'" />'."\n".
1137: ' <input type="hidden" name="seluname" value="" />'."\n".
1138: ' <input type="hidden" name="seludom" value="" />'."\n".
1.179 raeburn 1139: ' <input type="hidden" name="currstate" value="select" />'."\n".
1.190 raeburn 1140: ' <input type="hidden" name="phase" value="get_user_info" />'."\n".
1.214 raeburn 1141: ' <input type="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n");
1.302 raeburn 1142: if ($context eq 'requestcrs') {
1143: $r->print($opener_elements.'</form></div>');
1144: } else {
1.351 raeburn 1145: $r->print($response.'</form>');
1.302 raeburn 1146: }
1.160 raeburn 1147: }
1148:
1149: sub print_user_query_page {
1.351 raeburn 1150: my ($r,$caller,$brcrum) = @_;
1.160 raeburn 1151: # FIXME - this is for a network-wide name search (similar to catalog search)
1152: # To use frames with similar behavior to catalog/portfolio search.
1153: # To be implemented.
1154: return;
1155: }
1156:
1.42 matthew 1157: sub print_user_modification_page {
1.375 raeburn 1158: my ($r,$ccuname,$ccdomain,$srch,$response,$context,$permission,$crstype,
1159: $brcrum,$showcredits) = @_;
1.185 raeburn 1160: if (($ccuname eq '') || ($ccdomain eq '')) {
1.215 raeburn 1161: my $usermsg = &mt('No username and/or domain provided.');
1162: $env{'form.phase'} = '';
1.439 raeburn 1163: &print_username_entry_form($r,$context,$usermsg,'','',$crstype,$brcrum,
1164: $permission);
1.58 www 1165: return;
1166: }
1.213 raeburn 1167: my ($form,$formname);
1168: if ($env{'form.action'} eq 'singlestudent') {
1169: $form = 'document.enrollstudent';
1170: $formname = 'enrollstudent';
1171: } else {
1172: $form = 'document.cu';
1173: $formname = 'cu';
1174: }
1.188 raeburn 1175: my %abv_auth = &auth_abbrev();
1.227 raeburn 1176: my (%rulematch,%inst_results,$newuser,%alerts,%curr_rules,%got_rules);
1.185 raeburn 1177: my $uhome=&Apache::lonnet::homeserver($ccuname,$ccdomain);
1178: if ($uhome eq 'no_host') {
1.215 raeburn 1179: my $usertype;
1180: my ($rules,$ruleorder) =
1181: &Apache::lonnet::inst_userrules($ccdomain,'username');
1182: $usertype =
1.353 raeburn 1183: &Apache::lonuserutils::check_usertype($ccdomain,$ccuname,$rules,
1.362 raeburn 1184: \%curr_rules,\%got_rules);
1.215 raeburn 1185: my $cancreate =
1186: &Apache::lonuserutils::can_create_user($ccdomain,$context,
1187: $usertype);
1188: if (!$cancreate) {
1.292 bisitz 1189: my $helplink = 'javascript:helpMenu('."'display'".')';
1.215 raeburn 1190: my %usertypetext = (
1191: official => 'institutional',
1192: unofficial => 'non-institutional',
1193: );
1194: my $response;
1195: if ($env{'form.origform'} eq 'crtusername') {
1.362 raeburn 1196: $response = '<span class="LC_warning">'.
1197: &mt('No match found for the username [_1] in LON-CAPA domain: [_2]',
1198: '<b>'.$ccuname.'</b>',$ccdomain).
1.215 raeburn 1199: '</span><br />';
1200: }
1.292 bisitz 1201: $response .= '<p class="LC_warning">'
1202: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
1.418 raeburn 1203: .' ';
1204: if ($context eq 'domain') {
1205: $response .= &mt('Please contact a [_1] for assistance.',
1206: &Apache::lonnet::plaintext('dc'));
1207: } else {
1208: $response .= &mt('Please contact the [_1]helpdesk[_2] for assistance.'
1209: ,'<a href="'.$helplink.'">','</a>');
1210: }
1211: $response .= '</p><br />';
1.215 raeburn 1212: $env{'form.phase'} = '';
1.439 raeburn 1213: &print_username_entry_form($r,$context,$response,undef,undef,$crstype,$brcrum,
1214: $permission);
1.215 raeburn 1215: return;
1216: }
1.188 raeburn 1217: $newuser = 1;
1.193 raeburn 1218: my $checkhash;
1219: my $checks = { 'username' => 1 };
1.196 raeburn 1220: $checkhash->{$ccuname.':'.$ccdomain} = { 'newuser' => $newuser };
1.193 raeburn 1221: &Apache::loncommon::user_rule_check($checkhash,$checks,
1.196 raeburn 1222: \%alerts,\%rulematch,\%inst_results,\%curr_rules,\%got_rules);
1223: if (ref($alerts{'username'}) eq 'HASH') {
1224: if (ref($alerts{'username'}{$ccdomain}) eq 'HASH') {
1225: my $domdesc =
1.193 raeburn 1226: &Apache::lonnet::domain($ccdomain,'description');
1.196 raeburn 1227: if ($alerts{'username'}{$ccdomain}{$ccuname}) {
1228: my $userchkmsg;
1229: if (ref($curr_rules{$ccdomain}) eq 'HASH') {
1230: $userchkmsg =
1231: &Apache::loncommon::instrule_disallow_msg('username',
1.193 raeburn 1232: $domdesc,1).
1233: &Apache::loncommon::user_rule_formats($ccdomain,
1234: $domdesc,$curr_rules{$ccdomain}{'username'},
1235: 'username');
1.196 raeburn 1236: }
1.215 raeburn 1237: $env{'form.phase'} = '';
1.439 raeburn 1238: &print_username_entry_form($r,$context,$userchkmsg,undef,undef,$crstype,$brcrum,
1239: $permission);
1.196 raeburn 1240: return;
1.215 raeburn 1241: }
1.193 raeburn 1242: }
1.185 raeburn 1243: }
1.187 raeburn 1244: } else {
1.188 raeburn 1245: $newuser = 0;
1.185 raeburn 1246: }
1.160 raeburn 1247: if ($response) {
1.215 raeburn 1248: $response = '<br />'.$response;
1.160 raeburn 1249: }
1.149 raeburn 1250:
1.52 matthew 1251: my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
1.88 raeburn 1252: my $dc_setcourse_code = '';
1.119 raeburn 1253: my $nondc_setsection_code = '';
1.112 albertel 1254: my %loaditem;
1.114 albertel 1255:
1.216 raeburn 1256: my $groupslist = &Apache::lonuserutils::get_groupslist();
1.88 raeburn 1257:
1.375 raeburn 1258: my $js = &validation_javascript($context,$ccdomain,$pjump_def,$crstype,
1.216 raeburn 1259: $groupslist,$newuser,$formname,\%loaditem);
1.422 raeburn 1260: my %breadcrumb_text = &singleuser_breadcrumb($crstype,$context,$ccdomain);
1.224 raeburn 1261: my $helpitem = 'Course_Change_Privileges';
1262: if ($env{'form.action'} eq 'singlestudent') {
1263: $helpitem = 'Course_Add_Student';
1.439 raeburn 1264: } elsif ($context eq 'author') {
1265: $helpitem = 'Author_Change_Privileges';
1266: } elsif ($context eq 'domain') {
1267: $helpitem = 'Domain_Change_Privileges';
1.224 raeburn 1268: }
1.351 raeburn 1269: push (@{$brcrum},
1270: {href => "javascript:backPage($form)",
1271: text => $breadcrumb_text{'search'},
1272: faq => 282,
1273: bug => 'Instructor Interface',});
1274: if ($env{'form.phase'} eq 'userpicked') {
1275: push(@{$brcrum},
1276: {href => "javascript:backPage($form,'get_user_info','select')",
1277: text => $breadcrumb_text{'userpicked'},
1278: faq => 282,
1279: bug => 'Instructor Interface',});
1280: }
1281: push(@{$brcrum},
1282: {href => "javascript:backPage($form,'$env{'form.phase'}','modify')",
1283: text => $breadcrumb_text{'modify'},
1284: faq => 282,
1285: bug => 'Instructor Interface',
1286: help => $helpitem});
1287: my $args = {'add_entries' => \%loaditem,
1288: 'bread_crumbs' => $brcrum,
1289: 'bread_crumbs_component' => 'User Management'};
1290: if ($env{'form.popup'}) {
1291: $args->{'no_nav_bar'} = 1;
1292: }
1293: my $start_page =
1294: &Apache::loncommon::start_page('User Management',$js,$args);
1.3 www 1295:
1.25 matthew 1296: my $forminfo =<<"ENDFORMINFO";
1.216 raeburn 1297: <form action="/adm/createuser" method="post" name="$formname">
1.190 raeburn 1298: <input type="hidden" name="phase" value="update_user_data" />
1.188 raeburn 1299: <input type="hidden" name="ccuname" value="$ccuname" />
1300: <input type="hidden" name="ccdomain" value="$ccdomain" />
1.157 albertel 1301: <input type="hidden" name="pres_value" value="" />
1302: <input type="hidden" name="pres_type" value="" />
1303: <input type="hidden" name="pres_marker" value="" />
1.25 matthew 1304: ENDFORMINFO
1.375 raeburn 1305: my (%inccourses,$roledom,$defaultcredits);
1.329 raeburn 1306: if ($context eq 'course') {
1307: $inccourses{$env{'request.course.id'}}=1;
1308: $roledom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1.375 raeburn 1309: if ($showcredits) {
1310: $defaultcredits = &Apache::lonuserutils::get_defaultcredits();
1311: }
1.329 raeburn 1312: } elsif ($context eq 'author') {
1313: $roledom = $env{'request.role.domain'};
1314: } elsif ($context eq 'domain') {
1315: foreach my $key (keys(%env)) {
1316: $roledom = $env{'request.role.domain'};
1317: if ($key=~/^user\.priv\.cm\.\/($roledom)\/($match_username)/) {
1318: $inccourses{$1.'_'.$2}=1;
1319: }
1320: }
1321: } else {
1322: foreach my $key (keys(%env)) {
1323: if ($key=~/^user\.priv\.cm\.\/($match_domain)\/($match_username)/) {
1324: $inccourses{$1.'_'.$2}=1;
1325: }
1.2 www 1326: }
1.24 matthew 1327: }
1.389 bisitz 1328: my $title = '';
1.216 raeburn 1329: if ($newuser) {
1.427 raeburn 1330: my ($portfolioform,$domroleform);
1.267 raeburn 1331: if ((&Apache::lonnet::allowed('mpq',$env{'request.role.domain'})) ||
1332: (&Apache::lonnet::allowed('mut',$env{'request.role.domain'}))) {
1333: # Current user has quota or user tools modification privileges
1.378 raeburn 1334: $portfolioform = '<br />'.&user_quotas($ccuname,$ccdomain);
1.134 raeburn 1335: }
1.383 raeburn 1336: if ((&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) &&
1337: ($ccdomain eq $env{'request.role.domain'})) {
1.362 raeburn 1338: $domroleform = '<br />'.&domainrole_req($ccuname,$ccdomain);
1339: }
1.227 raeburn 1340: &initialize_authen_forms($ccdomain,$formname);
1.188 raeburn 1341: my %lt=&Apache::lonlocal::texthash(
1342: 'lg' => 'Login Data',
1.190 raeburn 1343: 'hs' => "Home Server",
1.188 raeburn 1344: );
1.185 raeburn 1345: $r->print(<<ENDTITLE);
1.110 albertel 1346: $start_page
1.160 raeburn 1347: $response
1.25 matthew 1348: $forminfo
1.31 matthew 1349: <script type="text/javascript" language="Javascript">
1.301 bisitz 1350: // <![CDATA[
1.20 harris41 1351: $loginscript
1.301 bisitz 1352: // ]]>
1.31 matthew 1353: </script>
1.20 harris41 1354: <input type='hidden' name='makeuser' value='1' />
1.185 raeburn 1355: ENDTITLE
1.213 raeburn 1356: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1357: if ($crstype eq 'Community') {
1.389 bisitz 1358: $title = &mt('Create New User [_1] in domain [_2] as a member',
1359: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.318 raeburn 1360: } else {
1.389 bisitz 1361: $title = &mt('Create New User [_1] in domain [_2] as a student',
1362: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.318 raeburn 1363: }
1.389 bisitz 1364: } else {
1365: $title = &mt('Create New User [_1] in domain [_2]',
1366: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.213 raeburn 1367: }
1.389 bisitz 1368: $r->print('<h2>'.$title.'</h2>'."\n");
1369: $r->print('<div class="LC_left_float">');
1.393 raeburn 1370: $r->print(&personal_data_display($ccuname,$ccdomain,$newuser,$context,
1371: $inst_results{$ccuname.':'.$ccdomain}));
1372: # Option to disable student/employee ID conflict checking not offerred for new users.
1.187 raeburn 1373: my ($home_server_pick,$numlib) =
1374: &Apache::loncommon::home_server_form_item($ccdomain,'hserver',
1375: 'default','hide');
1376: if ($numlib > 1) {
1377: $r->print("
1.185 raeburn 1378: <br />
1.187 raeburn 1379: $lt{'hs'}: $home_server_pick
1380: <br />");
1381: } else {
1382: $r->print($home_server_pick);
1383: }
1.304 raeburn 1384: if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
1.362 raeburn 1385: $r->print('<br /><h3>'.
1386: &mt('User Can Request Creation of Courses/Communities in this Domain?').'</h3>'.
1.304 raeburn 1387: &Apache::loncommon::start_data_table().
1388: &build_tools_display($ccuname,$ccdomain,
1389: 'requestcourses').
1390: &Apache::loncommon::end_data_table());
1391: }
1.188 raeburn 1392: $r->print('</div>'."\n".'<div class="LC_left_float"><h3>'.
1393: $lt{'lg'}.'</h3>');
1.185 raeburn 1394: my ($fixedauth,$varauth,$authmsg);
1.193 raeburn 1395: if (ref($rulematch{$ccuname.':'.$ccdomain}) eq 'HASH') {
1396: my $matchedrule = $rulematch{$ccuname.':'.$ccdomain}{'username'};
1397: my ($rules,$ruleorder) =
1398: &Apache::lonnet::inst_userrules($ccdomain,'username');
1.185 raeburn 1399: if (ref($rules) eq 'HASH') {
1.193 raeburn 1400: if (ref($rules->{$matchedrule}) eq 'HASH') {
1401: my $authtype = $rules->{$matchedrule}{'authtype'};
1.185 raeburn 1402: if ($authtype !~ /^(krb4|krb5|int|fsys|loc)$/) {
1.190 raeburn 1403: $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1.275 raeburn 1404: } else {
1.193 raeburn 1405: my $authparm = $rules->{$matchedrule}{'authparm'};
1.273 raeburn 1406: $authmsg = $rules->{$matchedrule}{'authmsg'};
1.185 raeburn 1407: if ($authtype =~ /^krb(4|5)$/) {
1408: my $ver = $1;
1409: if ($authparm ne '') {
1410: $fixedauth = <<"KERB";
1411: <input type="hidden" name="login" value="krb" />
1412: <input type="hidden" name="krbver" value="$ver" />
1413: <input type="hidden" name="krbarg" value="$authparm" />
1414: KERB
1415: }
1416: } else {
1417: $fixedauth =
1418: '<input type="hidden" name="login" value="'.$authtype.'" />'."\n";
1.193 raeburn 1419: if ($rules->{$matchedrule}{'authparmfixed'}) {
1.185 raeburn 1420: $fixedauth .=
1421: '<input type="hidden" name="'.$authtype.'arg" value="'.$authparm.'" />'."\n";
1422: } else {
1.273 raeburn 1423: if ($authtype eq 'int') {
1424: $varauth = '<br />'.
1.301 bisitz 1425: &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 1426: } elsif ($authtype eq 'loc') {
1427: $varauth = '<br />'.
1428: &mt('[_1] Local Authentication with argument [_2]','','<input type="text" name="'.$authtype.'arg" value="" />')."\n";
1429: } else {
1430: $varauth =
1.185 raeburn 1431: '<input type="text" name="'.$authtype.'arg" value="" />'."\n";
1.273 raeburn 1432: }
1.185 raeburn 1433: }
1434: }
1435: }
1436: } else {
1.190 raeburn 1437: $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1.185 raeburn 1438: }
1439: }
1440: if ($authmsg) {
1441: $r->print(<<ENDAUTH);
1442: $fixedauth
1443: $authmsg
1444: $varauth
1445: ENDAUTH
1446: }
1447: } else {
1.190 raeburn 1448: $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1.187 raeburn 1449: }
1.427 raeburn 1450: $r->print($portfolioform.$domroleform);
1.215 raeburn 1451: if ($env{'form.action'} eq 'singlestudent') {
1452: $r->print(&date_sections_select($context,$newuser,$formname,
1.375 raeburn 1453: $permission,$crstype,$ccuname,
1454: $ccdomain,$showcredits));
1.215 raeburn 1455: }
1456: $r->print('</div><div class="LC_clear_float_footer"></div>');
1.216 raeburn 1457: } else { # user already exists
1.389 bisitz 1458: $r->print($start_page.$forminfo);
1.213 raeburn 1459: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1460: if ($crstype eq 'Community') {
1.389 bisitz 1461: $title = &mt('Enroll one member: [_1] in domain [_2]',
1462: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.318 raeburn 1463: } else {
1.389 bisitz 1464: $title = &mt('Enroll one student: [_1] in domain [_2]',
1465: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.318 raeburn 1466: }
1.213 raeburn 1467: } else {
1.418 raeburn 1468: if ($permission->{'cusr'}) {
1469: $title = &mt('Modify existing user: [_1] in domain [_2]',
1470: '"'.$ccuname.'"','"'.$ccdomain.'"');
1471: } else {
1472: $title = &mt('Existing user: [_1] in domain [_2]',
1.389 bisitz 1473: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.418 raeburn 1474: }
1.213 raeburn 1475: }
1.389 bisitz 1476: $r->print('<h2>'.$title.'</h2>'."\n");
1477: $r->print('<div class="LC_left_float">');
1.393 raeburn 1478: $r->print(&personal_data_display($ccuname,$ccdomain,$newuser,$context,
1479: $inst_results{$ccuname.':'.$ccdomain}));
1.430 raeburn 1480: if ((&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) ||
1.418 raeburn 1481: (&Apache::lonnet::allowed('udp',$env{'request.role.domain'}))) {
1.362 raeburn 1482: $r->print('<br /><h3>'.&mt('User Can Request Creation of Courses/Communities in this Domain?').'</h3>'.
1.300 raeburn 1483: &Apache::loncommon::start_data_table());
1.314 raeburn 1484: if ($env{'request.role.domain'} eq $ccdomain) {
1.300 raeburn 1485: $r->print(&build_tools_display($ccuname,$ccdomain,'requestcourses'));
1486: } else {
1.444 raeburn 1487: if (&Apache::lonnet::will_trust('reqcrs',$ccdomain,$env{'request.role.domain'})) {
1488: $r->print(&coursereq_externaluser($ccuname,$ccdomain,
1489: $env{'request.role.domain'}));
1490: }
1.300 raeburn 1491: }
1492: $r->print(&Apache::loncommon::end_data_table());
1.275 raeburn 1493: }
1.199 raeburn 1494: $r->print('</div>');
1.427 raeburn 1495: my @order = ('auth','quota','tools','requestauthor');
1.362 raeburn 1496: my %user_text;
1497: my ($isadv,$isauthor) =
1.418 raeburn 1498: &Apache::lonnet::is_advanced_user($ccdomain,$ccuname);
1.362 raeburn 1499: if ((!$isauthor) &&
1.418 raeburn 1500: ((&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) ||
1501: (&Apache::lonnet::allowed('udp',$env{'request.role.domain'}))) &&
1.430 raeburn 1502: ($env{'request.role.domain'} eq $ccdomain)) {
1.362 raeburn 1503: $user_text{'requestauthor'} = &domainrole_req($ccuname,$ccdomain);
1504: }
1505: $user_text{'auth'} = &user_authentication($ccuname,$ccdomain,$formname);
1.267 raeburn 1506: if ((&Apache::lonnet::allowed('mpq',$ccdomain)) ||
1.418 raeburn 1507: (&Apache::lonnet::allowed('mut',$ccdomain)) ||
1508: (&Apache::lonnet::allowed('udp',$ccdomain))) {
1.188 raeburn 1509: # Current user has quota modification privileges
1.378 raeburn 1510: $user_text{'quota'} = &user_quotas($ccuname,$ccdomain);
1.267 raeburn 1511: }
1512: if (!&Apache::lonnet::allowed('mpq',$ccdomain)) {
1513: if (&Apache::lonnet::allowed('mpq',$env{'request.role.domain'})) {
1514: my %lt=&Apache::lonlocal::texthash(
1.385 bisitz 1515: 'dska' => "Disk quotas for user's portfolio and Authoring Space",
1516: 'youd' => "You do not have privileges to modify the portfolio and/or Authoring Space quotas for this user.",
1.267 raeburn 1517: 'ichr' => "If a change is required, contact a domain coordinator for the domain",
1518: );
1.362 raeburn 1519: $user_text{'quota'} = <<ENDNOPORTPRIV;
1.188 raeburn 1520: <h3>$lt{'dska'}</h3>
1521: $lt{'youd'} $lt{'ichr'}: $ccdomain
1522: ENDNOPORTPRIV
1.267 raeburn 1523: }
1524: }
1525: if (!&Apache::lonnet::allowed('mut',$ccdomain)) {
1526: if (&Apache::lonnet::allowed('mut',$env{'request.role.domain'})) {
1527: my %lt=&Apache::lonlocal::texthash(
1528: 'utav' => "User Tools Availability",
1.361 raeburn 1529: 'yodo' => "You do not have privileges to modify Portfolio, Blog, WebDAV, or Personal Information Page settings for this user.",
1.267 raeburn 1530: 'ifch' => "If a change is required, contact a domain coordinator for the domain",
1531: );
1.362 raeburn 1532: $user_text{'tools'} = <<ENDNOTOOLSPRIV;
1.267 raeburn 1533: <h3>$lt{'utav'}</h3>
1534: $lt{'yodo'} $lt{'ifch'}: $ccdomain
1535: ENDNOTOOLSPRIV
1536: }
1.188 raeburn 1537: }
1.362 raeburn 1538: my $gotdiv = 0;
1539: foreach my $item (@order) {
1540: if ($user_text{$item} ne '') {
1541: unless ($gotdiv) {
1542: $r->print('<div class="LC_left_float">');
1543: $gotdiv = 1;
1544: }
1545: $r->print('<br />'.$user_text{$item});
1546: }
1547: }
1548: if ($env{'form.action'} eq 'singlestudent') {
1549: unless ($gotdiv) {
1550: $r->print('<div class="LC_left_float">');
1.213 raeburn 1551: }
1.375 raeburn 1552: my $credits;
1553: if ($showcredits) {
1554: $credits = &get_user_credits($ccuname,$ccdomain,$defaultcredits);
1555: if ($credits eq '') {
1556: $credits = $defaultcredits;
1557: }
1558: }
1.374 raeburn 1559: $r->print(&date_sections_select($context,$newuser,$formname,
1.375 raeburn 1560: $permission,$crstype,$ccuname,
1561: $ccdomain,$showcredits));
1.374 raeburn 1562: }
1.362 raeburn 1563: if ($gotdiv) {
1564: $r->print('</div><div class="LC_clear_float_footer"></div>');
1.188 raeburn 1565: }
1.418 raeburn 1566: my $statuses;
1567: if (($context eq 'domain') && (&Apache::lonnet::allowed('udp',$ccdomain)) &&
1568: (!&Apache::lonnet::allowed('mau',$ccdomain))) {
1569: $statuses = ['active'];
1570: } elsif (($context eq 'course') && ((&Apache::lonnet::allowed('vcl',$env{'request.course.id'})) ||
1571: ($env{'request.course.sec'} &&
1572: &Apache::lonnet::allowed('vcl',$env{'request.course.id'}.'/'.$env{'request.course.sec'})))) {
1.430 raeburn 1573: $statuses = ['active'];
1.418 raeburn 1574: }
1.217 raeburn 1575: if ($env{'form.action'} ne 'singlestudent') {
1.329 raeburn 1576: &display_existing_roles($r,$ccuname,$ccdomain,\%inccourses,$context,
1.418 raeburn 1577: $roledom,$crstype,$showcredits,$statuses);
1.217 raeburn 1578: }
1.25 matthew 1579: } ## End of new user/old user logic
1.218 raeburn 1580: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1581: my $btntxt;
1582: if ($crstype eq 'Community') {
1583: $btntxt = &mt('Enroll Member');
1584: } else {
1585: $btntxt = &mt('Enroll Student');
1586: }
1587: $r->print('<br /><input type="button" value="'.$btntxt.'" onclick="setSections(this.form)" />'."\n");
1.418 raeburn 1588: } elsif ($permission->{'cusr'}) {
1.393 raeburn 1589: $r->print('<div class="LC_left_float">'.
1590: '<fieldset><legend>'.&mt('Add Roles').'</legend>');
1.218 raeburn 1591: my $addrolesdisplay = 0;
1592: if ($context eq 'domain' || $context eq 'author') {
1593: $addrolesdisplay = &new_coauthor_roles($r,$ccuname,$ccdomain);
1594: }
1595: if ($context eq 'domain') {
1.357 raeburn 1596: my $add_domainroles = &new_domain_roles($r,$ccdomain);
1.218 raeburn 1597: if (!$addrolesdisplay) {
1598: $addrolesdisplay = $add_domainroles;
1.2 www 1599: }
1.375 raeburn 1600: $r->print(&course_level_dc($env{'request.role.domain'},$showcredits));
1.393 raeburn 1601: $r->print('</fieldset></div><div class="LC_clear_float_footer"></div>'.
1602: '<br /><input type="button" value="'.&mt('Save').'" onclick="setCourse()" />'."\n");
1.218 raeburn 1603: } elsif ($context eq 'author') {
1604: if ($addrolesdisplay) {
1.393 raeburn 1605: $r->print('</fieldset></div><div class="LC_clear_float_footer"></div>'.
1606: '<br /><input type="button" value="'.&mt('Save').'"');
1.218 raeburn 1607: if ($newuser) {
1.301 bisitz 1608: $r->print(' onclick="auth_check()" \>'."\n");
1.218 raeburn 1609: } else {
1.301 bisitz 1610: $r->print('onclick="this.form.submit()" \>'."\n");
1.218 raeburn 1611: }
1.188 raeburn 1612: } else {
1.393 raeburn 1613: $r->print('</fieldset></div>'.
1614: '<div class="LC_clear_float_footer"></div>'.
1615: '<br /><a href="javascript:backPage(document.cu)">'.
1.218 raeburn 1616: &mt('Back to previous page').'</a>');
1.188 raeburn 1617: }
1618: } else {
1.375 raeburn 1619: $r->print(&course_level_table(\%inccourses,$showcredits,$defaultcredits));
1.393 raeburn 1620: $r->print('</fieldset></div><div class="LC_clear_float_footer"></div>'.
1621: '<br /><input type="button" value="'.&mt('Save').'" onclick="setSections(this.form)" />'."\n");
1.188 raeburn 1622: }
1.88 raeburn 1623: }
1.188 raeburn 1624: $r->print(&Apache::lonhtmlcommon::echo_form_input(['phase','userrole','ccdomain','prevphase','currstate','ccuname','ccdomain']));
1.179 raeburn 1625: $r->print('<input type="hidden" name="currstate" value="" />');
1.393 raeburn 1626: $r->print('<input type="hidden" name="prevphase" value="'.$env{'form.phase'}.'" /></form><br /><br />');
1.218 raeburn 1627: return;
1.2 www 1628: }
1.1 www 1629:
1.213 raeburn 1630: sub singleuser_breadcrumb {
1.422 raeburn 1631: my ($crstype,$context,$domain) = @_;
1.213 raeburn 1632: my %breadcrumb_text;
1633: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1634: if ($crstype eq 'Community') {
1635: $breadcrumb_text{'search'} = 'Enroll a member';
1636: } else {
1637: $breadcrumb_text{'search'} = 'Enroll a student';
1638: }
1.422 raeburn 1639: $breadcrumb_text{'userpicked'} = 'Select a user';
1640: $breadcrumb_text{'modify'} = 'Set section/dates';
1.416 raeburn 1641: } elsif ($env{'form.action'} eq 'accesslogs') {
1642: $breadcrumb_text{'search'} = 'View access logs for a user';
1.422 raeburn 1643: $breadcrumb_text{'userpicked'} = 'Select a user';
1644: $breadcrumb_text{'activity'} = 'Activity';
1645: } elsif (($env{'form.action'} eq 'singleuser') && ($context eq 'domain') &&
1646: (!&Apache::lonnet::allowed('mau',$domain))) {
1647: $breadcrumb_text{'search'} = "View user's roles";
1648: $breadcrumb_text{'userpicked'} = 'Select a user';
1649: $breadcrumb_text{'modify'} = 'User roles';
1.213 raeburn 1650: } else {
1.229 raeburn 1651: $breadcrumb_text{'search'} = 'Create/modify a user';
1.422 raeburn 1652: $breadcrumb_text{'userpicked'} = 'Select a user';
1653: $breadcrumb_text{'modify'} = 'Set user role';
1.213 raeburn 1654: }
1655: return %breadcrumb_text;
1656: }
1657:
1658: sub date_sections_select {
1.375 raeburn 1659: my ($context,$newuser,$formname,$permission,$crstype,$ccuname,$ccdomain,
1660: $showcredits) = @_;
1661: my $credits;
1662: if ($showcredits) {
1663: my $defaultcredits = &Apache::lonuserutils::get_defaultcredits();
1664: $credits = &get_user_credits($ccuname,$ccdomain,$defaultcredits);
1665: if ($credits eq '') {
1666: $credits = $defaultcredits;
1667: }
1668: }
1.213 raeburn 1669: my $cid = $env{'request.course.id'};
1670: my ($cnum,$cdom) = &Apache::lonuserutils::get_course_identity($cid);
1671: my $date_table = '<h3>'.&mt('Starting and Ending Dates').'</h3>'."\n".
1672: &Apache::lonuserutils::date_setting_table(undef,undef,$context,
1673: undef,$formname,$permission);
1674: my $rowtitle = 'Section';
1.375 raeburn 1675: my $secbox = '<h3>'.&mt('Section and Credits').'</h3>'."\n".
1.213 raeburn 1676: &Apache::lonuserutils::section_picker($cdom,$cnum,'st',$rowtitle,
1.375 raeburn 1677: $permission,$context,'',$crstype,
1678: $showcredits,$credits);
1.213 raeburn 1679: my $output = $date_table.$secbox;
1680: return $output;
1681: }
1682:
1.216 raeburn 1683: sub validation_javascript {
1.375 raeburn 1684: my ($context,$ccdomain,$pjump_def,$crstype,$groupslist,$newuser,$formname,
1.216 raeburn 1685: $loaditem) = @_;
1686: my $dc_setcourse_code = '';
1687: my $nondc_setsection_code = '';
1688: if ($context eq 'domain') {
1689: my $dcdom = $env{'request.role.domain'};
1690: $loaditem->{'onload'} = "document.cu.coursedesc.value='';";
1.227 raeburn 1691: $dc_setcourse_code =
1692: &Apache::lonuserutils::dc_setcourse_js('cu','singleuser',$context);
1.216 raeburn 1693: } else {
1.227 raeburn 1694: my $checkauth;
1695: if (($newuser) || (&Apache::lonnet::allowed('mau',$ccdomain))) {
1696: $checkauth = 1;
1697: }
1698: if ($context eq 'course') {
1699: $nondc_setsection_code =
1700: &Apache::lonuserutils::setsections_javascript($formname,$groupslist,
1.375 raeburn 1701: undef,$checkauth,
1702: $crstype);
1.227 raeburn 1703: }
1704: if ($checkauth) {
1705: $nondc_setsection_code .=
1706: &Apache::lonuserutils::verify_authen($formname,$context);
1707: }
1.216 raeburn 1708: }
1709: my $js = &user_modification_js($pjump_def,$dc_setcourse_code,
1710: $nondc_setsection_code,$groupslist);
1711: my ($jsback,$elements) = &crumb_utilities();
1712: $js .= "\n".
1.301 bisitz 1713: '<script type="text/javascript">'."\n".
1714: '// <![CDATA['."\n".
1715: $jsback."\n".
1716: '// ]]>'."\n".
1717: '</script>'."\n";
1.216 raeburn 1718: return $js;
1719: }
1720:
1.217 raeburn 1721: sub display_existing_roles {
1.375 raeburn 1722: my ($r,$ccuname,$ccdomain,$inccourses,$context,$roledom,$crstype,
1.418 raeburn 1723: $showcredits,$statuses) = @_;
1.329 raeburn 1724: my $now=time;
1.418 raeburn 1725: my $showall = 1;
1726: my ($showexpired,$showactive);
1727: if ((ref($statuses) eq 'ARRAY') && (@{$statuses} > 0)) {
1728: $showall = 0;
1729: if (grep(/^expired$/,@{$statuses})) {
1730: $showexpired = 1;
1731: }
1732: if (grep(/^active$/,@{$statuses})) {
1733: $showactive = 1;
1734: }
1735: if ($showexpired && $showactive) {
1736: $showall = 1;
1737: }
1738: }
1.329 raeburn 1739: my %lt=&Apache::lonlocal::texthash(
1.217 raeburn 1740: 'rer' => "Existing Roles",
1741: 'rev' => "Revoke",
1742: 'del' => "Delete",
1743: 'ren' => "Re-Enable",
1744: 'rol' => "Role",
1745: 'ext' => "Extent",
1.375 raeburn 1746: 'crd' => "Credits",
1.217 raeburn 1747: 'sta' => "Start",
1748: 'end' => "End",
1749: );
1.329 raeburn 1750: my (%rolesdump,%roletext,%sortrole,%roleclass,%rolepriv);
1751: if ($context eq 'course' || $context eq 'author') {
1752: my @roles = &Apache::lonuserutils::roles_by_context($context,1,$crstype);
1753: my %roleshash =
1754: &Apache::lonnet::get_my_roles($ccuname,$ccdomain,'userroles',
1755: ['active','previous','future'],\@roles,$roledom,1);
1756: foreach my $key (keys(%roleshash)) {
1757: my ($start,$end) = split(':',$roleshash{$key});
1758: next if ($start eq '-1' || $end eq '-1');
1759: my ($rnum,$rdom,$role,$sec) = split(':',$key);
1760: if ($context eq 'course') {
1761: next unless (($rnum eq $env{'course.'.$env{'request.course.id'}.'.num'})
1762: && ($rdom eq $env{'course.'.$env{'request.course.id'}.'.domain'}));
1763: } elsif ($context eq 'author') {
1764: next unless (($rnum eq $env{'user.name'}) && ($rdom eq $env{'request.role.domain'}));
1765: }
1766: my ($newkey,$newvalue,$newrole);
1767: $newkey = '/'.$rdom.'/'.$rnum;
1768: if ($sec ne '') {
1769: $newkey .= '/'.$sec;
1770: }
1771: $newvalue = $role;
1772: if ($role =~ /^cr/) {
1773: $newrole = 'cr';
1774: } else {
1775: $newrole = $role;
1776: }
1777: $newkey .= '_'.$newrole;
1778: if ($start ne '' && $end ne '') {
1779: $newvalue .= '_'.$end.'_'.$start;
1.335 raeburn 1780: } elsif ($end ne '') {
1781: $newvalue .= '_'.$end;
1.329 raeburn 1782: }
1783: $rolesdump{$newkey} = $newvalue;
1784: }
1785: } else {
1.360 raeburn 1786: %rolesdump=&Apache::lonnet::dump('roles',$ccdomain,$ccuname);
1.329 raeburn 1787: }
1788: # Build up table of user roles to allow revocation and re-enabling of roles.
1789: my ($tmp) = keys(%rolesdump);
1790: return if ($tmp =~ /^(con_lost|error)/i);
1791: foreach my $area (sort { my $a1=join('_',(split('_',$a))[1,0]);
1792: my $b1=join('_',(split('_',$b))[1,0]);
1793: return $a1 cmp $b1;
1794: } keys(%rolesdump)) {
1795: next if ($area =~ /^rolesdef/);
1796: my $envkey=$area;
1797: my $role = $rolesdump{$area};
1798: my $thisrole=$area;
1799: $area =~ s/\_\w\w$//;
1800: my ($role_code,$role_end_time,$role_start_time) =
1801: split(/_/,$role);
1.418 raeburn 1802: my $active=1;
1803: $active=0 if (($role_end_time) && ($now>$role_end_time));
1804: if ($active) {
1805: next unless($showall || $showactive);
1806: } else {
1.430 raeburn 1807: next unless($showall || $showexpired);
1.418 raeburn 1808: }
1.217 raeburn 1809: # Is this a custom role? Get role owner and title.
1.329 raeburn 1810: my ($croleudom,$croleuname,$croletitle)=
1811: ($role_code=~m{^cr/($match_domain)/($match_username)/(\w+)$});
1812: my $allowed=0;
1813: my $delallowed=0;
1814: my $sortkey=$role_code;
1815: my $class='Unknown';
1.375 raeburn 1816: my $credits='';
1.418 raeburn 1817: my $csec;
1.421 raeburn 1818: if ($area =~ m{^/($match_domain)/($match_courseid)}) {
1.329 raeburn 1819: $class='Course';
1820: my ($coursedom,$coursedir) = ($1,$2);
1821: my $cid = $1.'_'.$2;
1822: # $1.'_'.$2 is the course id (eg. 103_12345abcef103l3).
1.421 raeburn 1823: next if ($envkey =~ m{^/$match_domain/$match_courseid/[A-Za-z0-9]+_gr$});
1.329 raeburn 1824: my %coursedata=
1825: &Apache::lonnet::coursedescription($cid);
1826: if ($coursedir =~ /^$match_community$/) {
1827: $class='Community';
1828: }
1829: $sortkey.="\0$coursedom";
1830: my $carea;
1831: if (defined($coursedata{'description'})) {
1832: $carea=$coursedata{'description'}.
1833: '<br />'.&mt('Domain').': '.$coursedom.(' 'x8).
1834: &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$coursedir,$coursedom);
1835: $sortkey.="\0".$coursedata{'description'};
1836: } else {
1837: if ($class eq 'Community') {
1838: $carea=&mt('Unavailable community').': '.$area;
1839: $sortkey.="\0".&mt('Unavailable community').': '.$area;
1.217 raeburn 1840: } else {
1841: $carea=&mt('Unavailable course').': '.$area;
1842: $sortkey.="\0".&mt('Unavailable course').': '.$area;
1843: }
1.329 raeburn 1844: }
1845: $sortkey.="\0$coursedir";
1846: $inccourses->{$cid}=1;
1.375 raeburn 1847: if (($showcredits) && ($class eq 'Course') && ($role_code eq 'st')) {
1848: my $defaultcredits = $coursedata{'internal.defaultcredits'};
1849: $credits =
1850: &get_user_credits($ccuname,$ccdomain,$defaultcredits,
1851: $coursedom,$coursedir);
1852: if ($credits eq '') {
1853: $credits = $defaultcredits;
1854: }
1855: }
1.329 raeburn 1856: if ((&Apache::lonnet::allowed('c'.$role_code,$coursedom.'/'.$coursedir)) ||
1857: (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) {
1858: $allowed=1;
1859: }
1860: unless ($allowed) {
1.365 raeburn 1861: my $isowner = &Apache::lonuserutils::is_courseowner($cid,$coursedata{'internal.courseowner'});
1.329 raeburn 1862: if ($isowner) {
1863: if (($role_code eq 'co') && ($class eq 'Community')) {
1864: $allowed = 1;
1865: } elsif (($role_code eq 'cc') && ($class eq 'Course')) {
1866: $allowed = 1;
1867: }
1.217 raeburn 1868: }
1.329 raeburn 1869: }
1870: if ((&Apache::lonnet::allowed('dro',$coursedom)) ||
1871: (&Apache::lonnet::allowed('dro',$ccdomain))) {
1872: $delallowed=1;
1873: }
1.217 raeburn 1874: # - custom role. Needs more info, too
1.329 raeburn 1875: if ($croletitle) {
1876: if (&Apache::lonnet::allowed('ccr',$coursedom.'/'.$coursedir)) {
1877: $allowed=1;
1878: $thisrole.='.'.$role_code;
1.217 raeburn 1879: }
1.329 raeburn 1880: }
1.418 raeburn 1881: if ($area=~m{^/($match_domain/$match_courseid/(\w+))}) {
1882: $csec = $2;
1883: $carea.='<br />'.&mt('Section: [_1]',$csec);
1884: $sortkey.="\0$csec";
1.329 raeburn 1885: if (!$allowed) {
1.418 raeburn 1886: if ($env{'request.course.sec'} eq $csec) {
1887: if (&Apache::lonnet::allowed('c'.$role_code,$1)) {
1.329 raeburn 1888: $allowed = 1;
1.217 raeburn 1889: }
1890: }
1891: }
1.329 raeburn 1892: }
1893: $area=$carea;
1894: } else {
1895: $sortkey.="\0".$area;
1896: # Determine if current user is able to revoke privileges
1897: if ($area=~m{^/($match_domain)/}) {
1898: if ((&Apache::lonnet::allowed('c'.$role_code,$1)) ||
1899: (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) {
1900: $allowed=1;
1.217 raeburn 1901: }
1.329 raeburn 1902: if (((&Apache::lonnet::allowed('dro',$1)) ||
1903: (&Apache::lonnet::allowed('dro',$ccdomain))) &&
1904: ($role_code ne 'dc')) {
1905: $delallowed=1;
1.217 raeburn 1906: }
1.329 raeburn 1907: } else {
1908: if (&Apache::lonnet::allowed('c'.$role_code,'/')) {
1.217 raeburn 1909: $allowed=1;
1910: }
1911: }
1.363 raeburn 1912: if ($role_code eq 'ca' || $role_code eq 'au' || $role_code eq 'aa') {
1.377 raeburn 1913: $class='Authoring Space';
1.329 raeburn 1914: } elsif ($role_code eq 'su') {
1915: $class='System';
1.217 raeburn 1916: } else {
1.329 raeburn 1917: $class='Domain';
1.217 raeburn 1918: }
1.329 raeburn 1919: }
1920: if (($role_code eq 'ca') || ($role_code eq 'aa')) {
1921: $area=~m{/($match_domain)/($match_username)};
1922: if (&Apache::lonuserutils::authorpriv($2,$1)) {
1923: $allowed=1;
1.217 raeburn 1924: } else {
1.329 raeburn 1925: $allowed=0;
1.217 raeburn 1926: }
1.329 raeburn 1927: }
1928: my $row = '';
1.418 raeburn 1929: if ($showall) {
1930: $row.= '<td>';
1931: if (($active) && ($allowed)) {
1932: $row.= '<input type="checkbox" name="rev:'.$thisrole.'" />';
1933: } else {
1934: if ($active) {
1935: $row.=' ';
1936: } else {
1937: $row.=&mt('expired or revoked');
1938: }
1939: }
1940: $row.='</td><td>';
1941: if ($allowed && !$active) {
1942: $row.= '<input type="checkbox" name="ren:'.$thisrole.'" />';
1943: } else {
1944: $row.=' ';
1945: }
1946: $row.='</td><td>';
1947: if ($delallowed) {
1948: $row.= '<input type="checkbox" name="del:'.$thisrole.'" />';
1.217 raeburn 1949: } else {
1.418 raeburn 1950: $row.=' ';
1.217 raeburn 1951: }
1.430 raeburn 1952: $row.= '</td>';
1.329 raeburn 1953: }
1954: my $plaintext='';
1955: if (!$croletitle) {
1.375 raeburn 1956: $plaintext=&Apache::lonnet::plaintext($role_code,$class);
1957: if (($showcredits) && ($credits ne '')) {
1958: $plaintext .= '<br/ ><span class="LC_nobreak">'.
1959: '<span class="LC_fontsize_small">'.
1960: &mt('Credits: [_1]',$credits).
1961: '</span></span>';
1962: }
1.329 raeburn 1963: } else {
1964: $plaintext=
1.395 bisitz 1965: &mt('Custom role [_1][_2]defined by [_3]',
1.346 bisitz 1966: '"'.$croletitle.'"',
1967: '<br />',
1968: $croleuname.':'.$croleudom);
1.329 raeburn 1969: }
1.418 raeburn 1970: $row.= '<td>'.$plaintext.'</td>'.
1971: '<td>'.$area.'</td>'.
1972: '<td>'.($role_start_time?&Apache::lonlocal::locallocaltime($role_start_time)
1973: : ' ' ).'</td>'.
1974: '<td>'.($role_end_time ?&Apache::lonlocal::locallocaltime($role_end_time)
1975: : ' ' ).'</td>';
1.329 raeburn 1976: $sortrole{$sortkey}=$envkey;
1977: $roletext{$envkey}=$row;
1978: $roleclass{$envkey}=$class;
1.418 raeburn 1979: if ($allowed) {
1980: $rolepriv{$envkey}='edit';
1981: } else {
1982: if ($context eq 'domain') {
1.420 raeburn 1983: if ((&Apache::lonnet::allowed('vur',$ccdomain)) &&
1.421 raeburn 1984: ($envkey=~m{^/$ccdomain/})) {
1.418 raeburn 1985: $rolepriv{$envkey}='view';
1986: }
1987: } elsif ($context eq 'course') {
1988: if ((&Apache::lonnet::allowed('vcl',$env{'request.course.id'})) ||
1989: ($env{'request.course.sec'} && ($env{'request.course.sec'} eq $csec) &&
1990: &Apache::lonnet::allowed('vcl',$env{'request.course.id'}.'/'.$env{'request.course.sec'}))) {
1991: $rolepriv{$envkey}='view';
1992: }
1993: }
1994: }
1.329 raeburn 1995: } # end of foreach (table building loop)
1996:
1997: my $rolesdisplay = 0;
1998: my %output = ();
1.377 raeburn 1999: foreach my $type ('Authoring Space','Course','Community','Domain','System','Unknown') {
1.329 raeburn 2000: $output{$type} = '';
2001: foreach my $which (sort {uc($a) cmp uc($b)} (keys(%sortrole))) {
2002: if ( ($roleclass{$sortrole{$which}} =~ /^\Q$type\E/ ) && ($rolepriv{$sortrole{$which}}) ) {
2003: $output{$type}.=
2004: &Apache::loncommon::start_data_table_row().
2005: $roletext{$sortrole{$which}}.
2006: &Apache::loncommon::end_data_table_row();
1.217 raeburn 2007: }
1.329 raeburn 2008: }
2009: unless($output{$type} eq '') {
2010: $output{$type} = '<tr class="LC_info_row">'.
2011: "<td align='center' colspan='7'>".&mt($type)."</td></tr>".
2012: $output{$type};
2013: $rolesdisplay = 1;
2014: }
2015: }
2016: if ($rolesdisplay == 1) {
2017: my $contextrole='';
2018: if ($env{'request.course.id'}) {
2019: if (&Apache::loncommon::course_type() eq 'Community') {
2020: $contextrole = &mt('Existing Roles in this Community');
1.290 bisitz 2021: } else {
1.329 raeburn 2022: $contextrole = &mt('Existing Roles in this Course');
1.290 bisitz 2023: }
1.329 raeburn 2024: } elsif ($env{'request.role'} =~ /^au\./) {
1.377 raeburn 2025: $contextrole = &mt('Existing Co-Author Roles in your Authoring Space');
1.329 raeburn 2026: } else {
1.418 raeburn 2027: if ($showall) {
2028: $contextrole = &mt('Existing Roles in this Domain');
2029: } elsif ($showactive) {
2030: $contextrole = &mt('Unexpired Roles in this Domain');
2031: } elsif ($showexpired) {
2032: $contextrole = &mt('Expired or Revoked Roles in this Domain');
2033: }
1.329 raeburn 2034: }
1.393 raeburn 2035: $r->print('<div class="LC_left_float">'.
1.375 raeburn 2036: '<fieldset><legend>'.$contextrole.'</legend>'.
1.217 raeburn 2037: &Apache::loncommon::start_data_table("LC_createuser").
1.418 raeburn 2038: &Apache::loncommon::start_data_table_header_row());
2039: if ($showall) {
2040: $r->print(
1.419 raeburn 2041: '<th>'.$lt{'rev'}.'</th><th>'.$lt{'ren'}.'</th><th>'.$lt{'del'}.'</th>'
1.418 raeburn 2042: );
2043: } elsif ($showexpired) {
2044: $r->print('<th>'.$lt{'rev'}.'</th>');
2045: }
2046: $r->print(
1.419 raeburn 2047: '<th>'.$lt{'rol'}.'</th><th>'.$lt{'ext'}.'</th>'.
2048: '<th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'.
1.217 raeburn 2049: &Apache::loncommon::end_data_table_header_row());
1.377 raeburn 2050: foreach my $type ('Authoring Space','Course','Community','Domain','System','Unknown') {
1.329 raeburn 2051: if ($output{$type}) {
2052: $r->print($output{$type}."\n");
1.217 raeburn 2053: }
2054: }
1.375 raeburn 2055: $r->print(&Apache::loncommon::end_data_table().
2056: '</fieldset></div>');
1.329 raeburn 2057: }
1.217 raeburn 2058: return;
2059: }
2060:
1.218 raeburn 2061: sub new_coauthor_roles {
2062: my ($r,$ccuname,$ccdomain) = @_;
2063: my $addrolesdisplay = 0;
2064: #
2065: # Co-Author
2066: #
2067: if (&Apache::lonuserutils::authorpriv($env{'user.name'},
2068: $env{'request.role.domain'}) &&
2069: ($env{'user.name'} ne $ccuname || $env{'user.domain'} ne $ccdomain)) {
2070: # No sense in assigning co-author role to yourself
2071: $addrolesdisplay = 1;
2072: my $cuname=$env{'user.name'};
2073: my $cudom=$env{'request.role.domain'};
2074: my %lt=&Apache::lonlocal::texthash(
1.377 raeburn 2075: 'cs' => "Authoring Space",
1.218 raeburn 2076: 'act' => "Activate",
2077: 'rol' => "Role",
2078: 'ext' => "Extent",
2079: 'sta' => "Start",
2080: 'end' => "End",
2081: 'cau' => "Co-Author",
2082: 'caa' => "Assistant Co-Author",
2083: 'ssd' => "Set Start Date",
2084: 'sed' => "Set End Date"
2085: );
2086: $r->print('<h4>'.$lt{'cs'}.'</h4>'."\n".
2087: &Apache::loncommon::start_data_table()."\n".
2088: &Apache::loncommon::start_data_table_header_row()."\n".
2089: '<th>'.$lt{'act'}.'</th><th>'.$lt{'rol'}.'</th>'.
2090: '<th>'.$lt{'ext'}.'</th><th>'.$lt{'sta'}.'</th>'.
2091: '<th>'.$lt{'end'}.'</th>'."\n".
2092: &Apache::loncommon::end_data_table_header_row()."\n".
2093: &Apache::loncommon::start_data_table_row().'
2094: <td>
1.291 bisitz 2095: <input type="checkbox" name="act_'.$cudom.'_'.$cuname.'_ca" />
1.218 raeburn 2096: </td>
2097: <td>'.$lt{'cau'}.'</td>
2098: <td>'.$cudom.'_'.$cuname.'</td>
2099: <td><input type="hidden" name="start_'.$cudom.'_'.$cuname.'_ca" value="" />
2100: <a href=
2101: "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>
2102: <td><input type="hidden" name="end_'.$cudom.'_'.$cuname.'_ca" value="" />
2103: <a href=
2104: "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".
2105: &Apache::loncommon::end_data_table_row()."\n".
2106: &Apache::loncommon::start_data_table_row()."\n".
1.291 bisitz 2107: '<td><input type="checkbox" name="act_'.$cudom.'_'.$cuname.'_aa" /></td>
1.218 raeburn 2108: <td>'.$lt{'caa'}.'</td>
2109: <td>'.$cudom.'_'.$cuname.'</td>
2110: <td><input type="hidden" name="start_'.$cudom.'_'.$cuname.'_aa" value="" />
2111: <a href=
2112: "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>
2113: <td><input type="hidden" name="end_'.$cudom.'_'.$cuname.'_aa" value="" />
2114: <a href=
2115: "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".
2116: &Apache::loncommon::end_data_table_row()."\n".
2117: &Apache::loncommon::end_data_table());
2118: } elsif ($env{'request.role'} =~ /^au\./) {
2119: if (!(&Apache::lonuserutils::authorpriv($env{'user.name'},
2120: $env{'request.role.domain'}))) {
2121: $r->print('<span class="LC_error">'.
2122: &mt('You do not have privileges to assign co-author roles.').
2123: '</span>');
2124: } elsif (($env{'user.name'} eq $ccuname) &&
2125: ($env{'user.domain'} eq $ccdomain)) {
1.377 raeburn 2126: $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 2127: }
2128: }
2129: return $addrolesdisplay;;
2130: }
2131:
2132: sub new_domain_roles {
1.357 raeburn 2133: my ($r,$ccdomain) = @_;
1.218 raeburn 2134: my $addrolesdisplay = 0;
2135: #
2136: # Domain level
2137: #
2138: my $num_domain_level = 0;
2139: my $domaintext =
2140: '<h4>'.&mt('Domain Level').'</h4>'.
2141: &Apache::loncommon::start_data_table().
2142: &Apache::loncommon::start_data_table_header_row().
2143: '<th>'.&mt('Activate').'</th><th>'.&mt('Role').'</th><th>'.
2144: &mt('Extent').'</th>'.
2145: '<th>'.&mt('Start').'</th><th>'.&mt('End').'</th>'.
2146: &Apache::loncommon::end_data_table_header_row();
1.312 raeburn 2147: my @allroles = &Apache::lonuserutils::roles_by_context('domain');
1.445 raeburn 2148: my $uprimary = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
2149: my $uintdom = &Apache::lonnet::internet_dom($uprimary);
1.218 raeburn 2150: foreach my $thisdomain (sort(&Apache::lonnet::all_domains())) {
1.312 raeburn 2151: foreach my $role (@allroles) {
2152: next if ($role eq 'ad');
1.357 raeburn 2153: next if (($role eq 'au') && ($ccdomain ne $thisdomain));
1.218 raeburn 2154: if (&Apache::lonnet::allowed('c'.$role,$thisdomain)) {
1.445 raeburn 2155: if ($role eq 'dc') {
2156: unless ($thisdomain eq $env{'request.role.domain'}) {
2157: my $domprim = &Apache::lonnet::domain($thisdomain,'primary');
2158: my $intdom = &Apache::lonnet::internet_dom($domprim);
2159: next unless ($uintdom eq $intdom);
2160: }
2161: }
1.218 raeburn 2162: my $plrole=&Apache::lonnet::plaintext($role);
2163: my %lt=&Apache::lonlocal::texthash(
2164: 'ssd' => "Set Start Date",
2165: 'sed' => "Set End Date"
2166: );
2167: $num_domain_level ++;
2168: $domaintext .=
2169: &Apache::loncommon::start_data_table_row().
1.291 bisitz 2170: '<td><input type="checkbox" name="act_'.$thisdomain.'_'.$role.'" /></td>
1.218 raeburn 2171: <td>'.$plrole.'</td>
2172: <td>'.$thisdomain.'</td>
2173: <td><input type="hidden" name="start_'.$thisdomain.'_'.$role.'" value="" />
2174: <a href=
2175: "javascript:pjump('."'date_start','Start Date $plrole',document.cu.start_$thisdomain\_$role.value,'start_$thisdomain\_$role','cu.pres','dateset'".')">'.$lt{'ssd'}.'</a></td>
2176: <td><input type="hidden" name="end_'.$thisdomain.'_'.$role.'" value="" />
2177: <a href=
2178: "javascript:pjump('."'date_end','End Date $plrole',document.cu.end_$thisdomain\_$role.value,'end_$thisdomain\_$role','cu.pres','dateset'".')">'.$lt{'sed'}.'</a></td>'.
2179: &Apache::loncommon::end_data_table_row();
2180: }
2181: }
2182: }
2183: $domaintext.= &Apache::loncommon::end_data_table();
2184: if ($num_domain_level > 0) {
2185: $r->print($domaintext);
2186: $addrolesdisplay = 1;
2187: }
2188: return $addrolesdisplay;
2189: }
2190:
1.188 raeburn 2191: sub user_authentication {
1.227 raeburn 2192: my ($ccuname,$ccdomain,$formname) = @_;
1.188 raeburn 2193: my $currentauth=&Apache::lonnet::queryauthenticate($ccuname,$ccdomain);
1.227 raeburn 2194: my $outcome;
1.418 raeburn 2195: my %lt=&Apache::lonlocal::texthash(
2196: 'err' => "ERROR",
2197: 'uuas' => "This user has an unrecognized authentication scheme",
2198: 'adcs' => "Please alert a domain coordinator of this situation",
2199: 'sldb' => "Please specify login data below",
2200: 'ld' => "Login Data"
2201: );
1.188 raeburn 2202: # Check for a bad authentication type
2203: if ($currentauth !~ /^(krb4|krb5|unix|internal|localauth):/) {
2204: # bad authentication scheme
2205: if (&Apache::lonnet::allowed('mau',$ccdomain)) {
1.227 raeburn 2206: &initialize_authen_forms($ccdomain,$formname);
2207:
1.190 raeburn 2208: my $choices = &Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc);
1.188 raeburn 2209: $outcome = <<ENDBADAUTH;
2210: <script type="text/javascript" language="Javascript">
1.301 bisitz 2211: // <![CDATA[
1.188 raeburn 2212: $loginscript
1.301 bisitz 2213: // ]]>
1.188 raeburn 2214: </script>
2215: <span class="LC_error">$lt{'err'}:
2216: $lt{'uuas'} ($currentauth). $lt{'sldb'}.</span>
2217: <h3>$lt{'ld'}</h3>
2218: $choices
2219: ENDBADAUTH
2220: } else {
2221: # This user is not allowed to modify the user's
2222: # authentication scheme, so just notify them of the problem
2223: $outcome = <<ENDBADAUTH;
2224: <span class="LC_error"> $lt{'err'}:
2225: $lt{'uuas'} ($currentauth). $lt{'adcs'}.
2226: </span>
2227: ENDBADAUTH
2228: }
2229: } else { # Authentication type is valid
1.418 raeburn 2230:
1.227 raeburn 2231: &initialize_authen_forms($ccdomain,$formname,$currentauth,'modifyuser');
1.205 raeburn 2232: my ($authformcurrent,$can_modify,@authform_others) =
1.188 raeburn 2233: &modify_login_block($ccdomain,$currentauth);
2234: if (&Apache::lonnet::allowed('mau',$ccdomain)) {
2235: # Current user has login modification privileges
2236: $outcome =
2237: '<script type="text/javascript" language="Javascript">'."\n".
1.301 bisitz 2238: '// <![CDATA['."\n".
1.188 raeburn 2239: $loginscript."\n".
1.301 bisitz 2240: '// ]]>'."\n".
1.188 raeburn 2241: '</script>'."\n".
2242: '<h3>'.$lt{'ld'}.'</h3>'.
2243: &Apache::loncommon::start_data_table().
1.205 raeburn 2244: &Apache::loncommon::start_data_table_row().
1.188 raeburn 2245: '<td>'.$authformnop;
1.418 raeburn 2246: if (($can_modify) && (&Apache::lonnet::allowed('mau',$ccdomain))) {
1.188 raeburn 2247: $outcome .= '</td>'."\n".
2248: &Apache::loncommon::end_data_table_row().
2249: &Apache::loncommon::start_data_table_row().
2250: '<td>'.$authformcurrent.'</td>'.
2251: &Apache::loncommon::end_data_table_row()."\n";
2252: } else {
1.200 raeburn 2253: $outcome .= ' ('.$authformcurrent.')</td>'.
2254: &Apache::loncommon::end_data_table_row()."\n";
1.188 raeburn 2255: }
1.418 raeburn 2256: if (&Apache::lonnet::allowed('mau',$ccdomain)) {
2257: foreach my $item (@authform_others) {
2258: $outcome .= &Apache::loncommon::start_data_table_row().
2259: '<td>'.$item.'</td>'.
2260: &Apache::loncommon::end_data_table_row()."\n";
2261: }
1.188 raeburn 2262: }
1.205 raeburn 2263: $outcome .= &Apache::loncommon::end_data_table();
1.188 raeburn 2264: } else {
1.418 raeburn 2265: if (&Apache::lonnet::allowed('udp',$ccdomain)) {
2266: # Current user has rights to view domain preferences for user's domain
2267: my $result;
2268: if ($currentauth =~ /^krb(4|5):([^:]*)$/) {
2269: my ($krbver,$krbrealm) = ($1,$2);
2270: if ($krbrealm eq '') {
2271: $result = &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
2272: } else {
2273: $result = &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
1.426 raeburn 2274: $krbrealm,$krbver);
1.418 raeburn 2275: }
2276: } elsif ($currentauth =~ /^internal:/) {
2277: $result = &mt('Currently internally authenticated.');
2278: } elsif ($currentauth =~ /^localauth:/) {
2279: $result = &mt('Currently using local (institutional) authentication.');
2280: } elsif ($currentauth =~ /^unix:/) {
2281: $result = &mt('Currently Filesystem Authenticated.');
2282: }
2283: $outcome = '<h3>'.$lt{'ld'}.'</h3>'.
2284: &Apache::loncommon::start_data_table().
2285: &Apache::loncommon::start_data_table_row().
2286: '<td>'.$result.'</td>'.
2287: &Apache::loncommon::end_data_table_row()."\n".
2288: &Apache::loncommon::end_data_table();
2289: } elsif (&Apache::lonnet::allowed('mau',$env{'request.role.domain'})) {
1.188 raeburn 2290: my %lt=&Apache::lonlocal::texthash(
2291: 'ccld' => "Change Current Login Data",
2292: 'yodo' => "You do not have privileges to modify the authentication configuration for this user.",
2293: 'ifch' => "If a change is required, contact a domain coordinator for the domain",
2294: );
2295: $outcome .= <<ENDNOPRIV;
2296: <h3>$lt{'ccld'}</h3>
2297: $lt{'yodo'} $lt{'ifch'}: $ccdomain
1.235 raeburn 2298: <input type="hidden" name="login" value="nochange" />
1.188 raeburn 2299: ENDNOPRIV
2300: }
2301: }
2302: } ## End of "check for bad authentication type" logic
2303: return $outcome;
2304: }
2305:
1.187 raeburn 2306: sub modify_login_block {
2307: my ($dom,$currentauth) = @_;
2308: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
2309: my ($authnum,%can_assign) =
2310: &Apache::loncommon::get_assignable_auth($dom);
1.205 raeburn 2311: my ($authformcurrent,@authform_others,$show_override_msg);
1.187 raeburn 2312: if ($currentauth=~/^krb(4|5):/) {
2313: $authformcurrent=$authformkrb;
2314: if ($can_assign{'int'}) {
1.205 raeburn 2315: push(@authform_others,$authformint);
1.187 raeburn 2316: }
2317: if ($can_assign{'loc'}) {
1.205 raeburn 2318: push(@authform_others,$authformloc);
1.187 raeburn 2319: }
2320: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
2321: $show_override_msg = 1;
2322: }
2323: } elsif ($currentauth=~/^internal:/) {
2324: $authformcurrent=$authformint;
2325: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205 raeburn 2326: push(@authform_others,$authformkrb);
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{'int'}) {
2332: $show_override_msg = 1;
2333: }
2334: } elsif ($currentauth=~/^unix:/) {
2335: $authformcurrent=$authformfsys;
2336: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205 raeburn 2337: push(@authform_others,$authformkrb);
1.187 raeburn 2338: }
2339: if ($can_assign{'int'}) {
1.205 raeburn 2340: push(@authform_others,$authformint);
1.187 raeburn 2341: }
2342: if ($can_assign{'loc'}) {
1.205 raeburn 2343: push(@authform_others,$authformloc);
1.187 raeburn 2344: }
2345: if ($can_assign{'fsys'}) {
2346: $show_override_msg = 1;
2347: }
2348: } elsif ($currentauth=~/^localauth:/) {
2349: $authformcurrent=$authformloc;
2350: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205 raeburn 2351: push(@authform_others,$authformkrb);
1.187 raeburn 2352: }
2353: if ($can_assign{'int'}) {
1.205 raeburn 2354: push(@authform_others,$authformint);
1.187 raeburn 2355: }
2356: if ($can_assign{'loc'}) {
2357: $show_override_msg = 1;
2358: }
2359: }
2360: if ($show_override_msg) {
1.205 raeburn 2361: $authformcurrent = '<table><tr><td colspan="3">'.$authformcurrent.
2362: '</td></tr>'."\n".
2363: '<tr><td> </td>'.
2364: '<td><b>'.&mt('Currently in use').'</b></td>'.
2365: '<td align="right"><span class="LC_cusr_emph">'.
1.187 raeburn 2366: &mt('will override current values').
1.205 raeburn 2367: '</span></td></tr></table>';
1.187 raeburn 2368: }
1.205 raeburn 2369: return ($authformcurrent,$show_override_msg,@authform_others);
1.187 raeburn 2370: }
2371:
1.188 raeburn 2372: sub personal_data_display {
1.391 raeburn 2373: my ($ccuname,$ccdomain,$newuser,$context,$inst_results,$rolesarray,
1.443 raeburn 2374: $now,$captchaform,$emailusername,$usertype,$usernameset,$condition,$excluded) = @_;
1.388 bisitz 2375: my ($output,%userenv,%canmodify,%canmodify_status);
1.219 raeburn 2376: my @userinfo = ('firstname','middlename','lastname','generation',
2377: 'permanentemail','id');
1.252 raeburn 2378: my $rowcount = 0;
2379: my $editable = 0;
1.391 raeburn 2380: my %textboxsize = (
2381: firstname => '15',
2382: middlename => '15',
2383: lastname => '15',
2384: generation => '5',
2385: permanentemail => '25',
2386: id => '15',
2387: );
2388:
2389: my %lt=&Apache::lonlocal::texthash(
2390: 'pd' => "Personal Data",
2391: 'firstname' => "First Name",
2392: 'middlename' => "Middle Name",
2393: 'lastname' => "Last Name",
2394: 'generation' => "Generation",
2395: 'permanentemail' => "Permanent e-mail address",
2396: 'id' => "Student/Employee ID",
2397: 'lg' => "Login Data",
2398: 'inststatus' => "Affiliation",
2399: 'email' => 'E-mail address',
2400: 'valid' => 'Validation',
1.442 raeburn 2401: 'username' => 'Username',
1.391 raeburn 2402: );
2403:
2404: %canmodify_status =
1.286 raeburn 2405: &Apache::lonuserutils::can_modify_userinfo($context,$ccdomain,
2406: ['inststatus'],$rolesarray);
1.253 raeburn 2407: if (!$newuser) {
1.188 raeburn 2408: # Get the users information
2409: %userenv = &Apache::lonnet::get('environment',
2410: ['firstname','middlename','lastname','generation',
1.286 raeburn 2411: 'permanentemail','id','inststatus'],$ccdomain,$ccuname);
1.219 raeburn 2412: %canmodify =
2413: &Apache::lonuserutils::can_modify_userinfo($context,$ccdomain,
1.252 raeburn 2414: \@userinfo,$rolesarray);
1.257 raeburn 2415: } elsif ($context eq 'selfcreate') {
1.391 raeburn 2416: if ($newuser eq 'email') {
1.396 raeburn 2417: if (ref($emailusername) eq 'HASH') {
2418: if (ref($emailusername->{$usertype}) eq 'HASH') {
2419: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
1.442 raeburn 2420: @userinfo = ();
1.396 raeburn 2421: if ((ref($infofields) eq 'ARRAY') && (ref($infotitles) eq 'HASH')) {
2422: foreach my $field (@{$infofields}) {
2423: if ($emailusername->{$usertype}->{$field}) {
2424: push(@userinfo,$field);
2425: $canmodify{$field} = 1;
2426: unless ($textboxsize{$field}) {
2427: $textboxsize{$field} = 25;
2428: }
2429: unless ($lt{$field}) {
2430: $lt{$field} = $infotitles->{$field};
2431: }
2432: if ($emailusername->{$usertype}->{$field} eq 'required') {
2433: $lt{$field} .= '<b>*</b>';
2434: }
1.391 raeburn 2435: }
2436: }
2437: }
2438: }
2439: }
2440: } else {
2441: %canmodify = &selfcreate_canmodify($context,$ccdomain,\@userinfo,
2442: $inst_results,$rolesarray);
2443: }
1.188 raeburn 2444: }
1.391 raeburn 2445:
1.188 raeburn 2446: my $genhelp=&Apache::loncommon::help_open_topic('Generation');
2447: $output = '<h3>'.$lt{'pd'}.'</h3>'.
2448: &Apache::lonhtmlcommon::start_pick_box();
1.391 raeburn 2449: if (($context eq 'selfcreate') && ($newuser eq 'email')) {
1.443 raeburn 2450: my $size = 25;
1.442 raeburn 2451: if ($condition) {
1.443 raeburn 2452: if ($condition =~ /^\@[^\@]+$/) {
2453: $size = 10;
1.442 raeburn 2454: } else {
2455: undef($condition);
2456: }
1.443 raeburn 2457: }
2458: if ($excluded) {
2459: unless ($excluded =~ /^\@[^\@]+$/) {
2460: undef($condition);
2461: }
1.442 raeburn 2462: }
1.396 raeburn 2463: $output .= &Apache::lonhtmlcommon::row_title($lt{'email'}.'<b>*</b>',undef,
1.391 raeburn 2464: 'LC_oddrow_value')."\n".
1.443 raeburn 2465: '<input type="text" name="uname" size="'.$size.'" value="" autocomplete="off" />';
2466: if ($condition) {
2467: $output .= $condition;
2468: } elsif ($excluded) {
2469: $output .= '<br /><span style="font-size: smaller">'.&mt('You must use an e-mail address that does not end with [_1]',
2470: $excluded).'</span>';
2471: }
2472: if ($usernameset eq 'first') {
2473: $output .= '<br /><span style="font-size: smaller">';
2474: if ($condition) {
2475: $output .= &mt('Your username in LON-CAPA will be the part of your e-mail address before [_1]',
2476: $condition);
2477: } else {
2478: $output .= &mt('Your username in LON-CAPA will be the part of your e-mail address before the @');
2479: }
2480: $output .= '</span>';
2481: }
1.391 raeburn 2482: $rowcount ++;
2483: $output .= &Apache::lonhtmlcommon::row_closure(1);
1.408 raeburn 2484: my $upassone = '<input type="password" name="upass'.$now.'" size="20" autocomplete="off" />';
2485: my $upasstwo = '<input type="password" name="upasscheck'.$now.'" size="20" autocomplete="off" />';
1.396 raeburn 2486: $output .= &Apache::lonhtmlcommon::row_title(&mt('Password').'<b>*</b>',
1.391 raeburn 2487: 'LC_pick_box_title',
2488: 'LC_oddrow_value')."\n".
2489: $upassone."\n".
2490: &Apache::lonhtmlcommon::row_closure(1)."\n".
1.396 raeburn 2491: &Apache::lonhtmlcommon::row_title(&mt('Confirm password').'<b>*</b>',
1.391 raeburn 2492: 'LC_pick_box_title',
2493: 'LC_oddrow_value')."\n".
2494: $upasstwo.
2495: &Apache::lonhtmlcommon::row_closure()."\n";
1.443 raeburn 2496: if ($usernameset eq 'free') {
2497: my $onclick = "toggleUsernameDisp(this,'selfcreateusername');";
1.442 raeburn 2498: $output .= &Apache::lonhtmlcommon::row_title($lt{'username'},undef,'LC_oddrow_value')."\n".
2499: &mt('Use e-mail address: ').
2500: '<label><input type="radio" name="emailused" value="1" checked="checked" onclick="'.$onclick.'" />'.&mt('Yes').'</label>'."\n".
2501: (' 'x2).
2502: '<label><input type="radio" name="emailused" value="0" onclick="'.$onclick.'" />'.&mt('No').'</label>'."\n".
2503: '<div id="selfcreateusername" style="display: none; font-size: smaller">'.
2504: '<br /><span class="LC_nobreak">'.&mt('Preferred username').
2505: ' <input type="text" name="username" value="" size="20" autocomplete="off"/>'.
2506: '</span></div>'."\n".&Apache::lonhtmlcommon::row_closure(1);
2507: $rowcount ++;
2508: }
1.391 raeburn 2509: }
1.188 raeburn 2510: foreach my $item (@userinfo) {
2511: my $rowtitle = $lt{$item};
1.252 raeburn 2512: my $hiderow = 0;
1.188 raeburn 2513: if ($item eq 'generation') {
2514: $rowtitle = $genhelp.$rowtitle;
2515: }
1.252 raeburn 2516: my $row = &Apache::lonhtmlcommon::row_title($rowtitle,undef,'LC_oddrow_value')."\n";
1.188 raeburn 2517: if ($newuser) {
1.210 raeburn 2518: if (ref($inst_results) eq 'HASH') {
2519: if ($inst_results->{$item} ne '') {
1.252 raeburn 2520: $row .= '<input type="hidden" name="c'.$item.'" value="'.$inst_results->{$item}.'" />'.$inst_results->{$item};
1.210 raeburn 2521: } else {
1.252 raeburn 2522: if ($context eq 'selfcreate') {
1.391 raeburn 2523: if ($canmodify{$item}) {
1.394 raeburn 2524: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" autocomplete="off" />';
1.252 raeburn 2525: $editable ++;
2526: } else {
2527: $hiderow = 1;
2528: }
1.253 raeburn 2529: } else {
2530: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
1.252 raeburn 2531: }
1.210 raeburn 2532: }
1.188 raeburn 2533: } else {
1.252 raeburn 2534: if ($context eq 'selfcreate') {
1.401 raeburn 2535: if ($canmodify{$item}) {
2536: if ($newuser eq 'email') {
2537: $row .= '<input type="text" name="'.$item.'" size="'.$textboxsize{$item}.'" value="" autocomplete="off" />';
1.287 raeburn 2538: } else {
1.401 raeburn 2539: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" autocomplete="off" />';
1.287 raeburn 2540: }
1.401 raeburn 2541: $editable ++;
2542: } else {
2543: $hiderow = 1;
1.252 raeburn 2544: }
1.253 raeburn 2545: } else {
2546: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
1.252 raeburn 2547: }
1.188 raeburn 2548: }
2549: } else {
1.219 raeburn 2550: if ($canmodify{$item}) {
1.252 raeburn 2551: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="'.$userenv{$item}.'" />';
1.393 raeburn 2552: if (($item eq 'id') && (!$newuser)) {
2553: $row .= '<br />'.&Apache::lonuserutils::forceid_change($context);
2554: }
1.188 raeburn 2555: } else {
1.252 raeburn 2556: $row .= $userenv{$item};
1.188 raeburn 2557: }
2558: }
1.252 raeburn 2559: $row .= &Apache::lonhtmlcommon::row_closure(1);
2560: if (!$hiderow) {
2561: $output .= $row;
2562: $rowcount ++;
2563: }
1.188 raeburn 2564: }
1.286 raeburn 2565: if (($canmodify_status{'inststatus'}) || ($context ne 'selfcreate')) {
2566: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($ccdomain);
2567: if (ref($types) eq 'ARRAY') {
2568: if (@{$types} > 0) {
2569: my ($hiderow,$shown);
2570: if ($canmodify_status{'inststatus'}) {
2571: $shown = &pick_inst_statuses($userenv{'inststatus'},$usertypes,$types);
2572: } else {
2573: if ($userenv{'inststatus'} eq '') {
2574: $hiderow = 1;
1.334 raeburn 2575: } else {
2576: my @showitems;
2577: foreach my $item ( map { &unescape($_); } split(':',$userenv{'inststatus'})) {
2578: if (exists($usertypes->{$item})) {
2579: push(@showitems,$usertypes->{$item});
2580: } else {
2581: push(@showitems,$item);
2582: }
2583: }
2584: if (@showitems) {
2585: $shown = join(', ',@showitems);
2586: } else {
2587: $hiderow = 1;
2588: }
1.286 raeburn 2589: }
2590: }
2591: if (!$hiderow) {
1.389 bisitz 2592: my $row = &Apache::lonhtmlcommon::row_title(&mt('Affiliations'),undef,'LC_oddrow_value')."\n".
1.286 raeburn 2593: $shown.&Apache::lonhtmlcommon::row_closure(1);
2594: if ($context eq 'selfcreate') {
2595: $rowcount ++;
2596: }
2597: $output .= $row;
2598: }
2599: }
2600: }
2601: }
1.391 raeburn 2602: if (($context eq 'selfcreate') && ($newuser eq 'email')) {
2603: if ($captchaform) {
1.410 raeburn 2604: $output .= &Apache::lonhtmlcommon::row_title($lt{'valid'}.'*',
2605: 'LC_pick_box_title')."\n".
2606: $captchaform."\n".'<br /><br />'.
1.391 raeburn 2607: &Apache::lonhtmlcommon::row_closure(1);
2608: $rowcount ++;
2609: }
2610: my $submit_text = &mt('Create account');
2611: $output .= &Apache::lonhtmlcommon::row_title()."\n".
2612: '<br /><input type="submit" name="createaccount" value="'.
2613: $submit_text.'" />'.
1.396 raeburn 2614: '<input type="hidden" name="type" value="'.$usertype.'" />'.
1.391 raeburn 2615: &Apache::lonhtmlcommon::row_closure(1);
2616: }
1.188 raeburn 2617: $output .= &Apache::lonhtmlcommon::end_pick_box();
1.206 raeburn 2618: if (wantarray) {
1.252 raeburn 2619: if ($context eq 'selfcreate') {
2620: return($output,$rowcount,$editable);
2621: } else {
1.388 bisitz 2622: return $output;
1.252 raeburn 2623: }
1.206 raeburn 2624: } else {
2625: return $output;
2626: }
1.188 raeburn 2627: }
2628:
1.286 raeburn 2629: sub pick_inst_statuses {
2630: my ($curr,$usertypes,$types) = @_;
2631: my ($output,$rem,@currtypes);
2632: if ($curr ne '') {
2633: @currtypes = map { &unescape($_); } split(/:/,$curr);
2634: }
2635: my $numinrow = 2;
2636: if (ref($types) eq 'ARRAY') {
2637: $output = '<table>';
2638: my $lastcolspan;
2639: for (my $i=0; $i<@{$types}; $i++) {
2640: if (defined($usertypes->{$types->[$i]})) {
2641: my $rem = $i%($numinrow);
2642: if ($rem == 0) {
2643: if ($i<@{$types}-1) {
2644: if ($i > 0) {
2645: $output .= '</tr>';
2646: }
2647: $output .= '<tr>';
2648: }
2649: } elsif ($i==@{$types}-1) {
2650: my $colsleft = $numinrow - $rem;
2651: if ($colsleft > 1) {
2652: $lastcolspan = ' colspan="'.$colsleft.'"';
2653: }
2654: }
2655: my $check = ' ';
2656: if (grep(/^\Q$types->[$i]\E$/,@currtypes)) {
2657: $check = ' checked="checked" ';
2658: }
2659: $output .= '<td class="LC_left_item"'.$lastcolspan.'>'.
2660: '<span class="LC_nobreak"><label>'.
2661: '<input type="checkbox" name="inststatus" '.
2662: 'value="'.$types->[$i].'"'.$check.'/>'.
2663: $usertypes->{$types->[$i]}.'</label></span></td>';
2664: }
2665: }
2666: $output .= '</tr></table>';
2667: }
2668: return $output;
2669: }
2670:
1.257 raeburn 2671: sub selfcreate_canmodify {
2672: my ($context,$dom,$userinfo,$inst_results,$rolesarray) = @_;
2673: if (ref($inst_results) eq 'HASH') {
2674: my @inststatuses = &get_inststatuses($inst_results);
2675: if (@inststatuses == 0) {
2676: @inststatuses = ('default');
2677: }
2678: $rolesarray = \@inststatuses;
2679: }
2680: my %canmodify =
2681: &Apache::lonuserutils::can_modify_userinfo($context,$dom,$userinfo,
2682: $rolesarray);
2683: return %canmodify;
2684: }
2685:
1.252 raeburn 2686: sub get_inststatuses {
2687: my ($insthashref) = @_;
2688: my @inststatuses = ();
2689: if (ref($insthashref) eq 'HASH') {
2690: if (ref($insthashref->{'inststatus'}) eq 'ARRAY') {
2691: @inststatuses = @{$insthashref->{'inststatus'}};
2692: }
2693: }
2694: return @inststatuses;
2695: }
2696:
1.4 www 2697: # ================================================================= Phase Three
1.42 matthew 2698: sub update_user_data {
1.375 raeburn 2699: my ($r,$context,$crstype,$brcrum,$showcredits) = @_;
1.101 albertel 2700: my $uhome=&Apache::lonnet::homeserver($env{'form.ccuname'},
2701: $env{'form.ccdomain'});
1.27 matthew 2702: # Error messages
1.188 raeburn 2703: my $error = '<span class="LC_error">'.&mt('Error').': ';
1.193 raeburn 2704: my $end = '</span><br /><br />';
2705: my $rtnlink = '<a href="javascript:backPage(document.userupdate,'.
1.188 raeburn 2706: "'$env{'form.prevphase'}','modify')".'" />'.
1.219 raeburn 2707: &mt('Return to previous page').'</a>'.
2708: &Apache::loncommon::end_page();
2709: my $now = time;
1.40 www 2710: my $title;
1.101 albertel 2711: if (exists($env{'form.makeuser'})) {
1.40 www 2712: $title='Set Privileges for New User';
2713: } else {
2714: $title='Modify User Privileges';
2715: }
1.213 raeburn 2716: my $newuser = 0;
1.160 raeburn 2717: my ($jsback,$elements) = &crumb_utilities();
2718: my $jscript = '<script type="text/javascript">'."\n".
1.301 bisitz 2719: '// <![CDATA['."\n".
2720: $jsback."\n".
2721: '// ]]>'."\n".
2722: '</script>'."\n";
1.422 raeburn 2723: my %breadcrumb_text = &singleuser_breadcrumb($crstype,$context,$env{'form.ccdomain'});
1.351 raeburn 2724: push (@{$brcrum},
2725: {href => "javascript:backPage(document.userupdate)",
2726: text => $breadcrumb_text{'search'},
2727: faq => 282,
2728: bug => 'Instructor Interface',}
2729: );
2730: if ($env{'form.prevphase'} eq 'userpicked') {
2731: push(@{$brcrum},
2732: {href => "javascript:backPage(document.userupdate,'get_user_info','select')",
2733: text => $breadcrumb_text{'userpicked'},
2734: faq => 282,
2735: bug => 'Instructor Interface',});
1.233 raeburn 2736: }
1.224 raeburn 2737: my $helpitem = 'Course_Change_Privileges';
2738: if ($env{'form.action'} eq 'singlestudent') {
2739: $helpitem = 'Course_Add_Student';
1.439 raeburn 2740: } elsif ($context eq 'author') {
2741: $helpitem = 'Author_Change_Privileges';
2742: } elsif ($context eq 'domain') {
2743: $helpitem = 'Domain_Change_Privileges';
1.224 raeburn 2744: }
1.351 raeburn 2745: push(@{$brcrum},
2746: {href => "javascript:backPage(document.userupdate,'$env{'form.prevphase'}','modify')",
2747: text => $breadcrumb_text{'modify'},
2748: faq => 282,
2749: bug => 'Instructor Interface',},
2750: {href => "/adm/createuser",
2751: text => "Result",
2752: faq => 282,
2753: bug => 'Instructor Interface',
2754: help => $helpitem});
2755: my $args = {bread_crumbs => $brcrum,
2756: bread_crumbs_component => 'User Management'};
2757: if ($env{'form.popup'}) {
2758: $args->{'no_nav_bar'} = 1;
2759: }
2760: $r->print(&Apache::loncommon::start_page($title,$jscript,$args));
1.188 raeburn 2761: $r->print(&update_result_form($uhome));
1.27 matthew 2762: # Check Inputs
1.101 albertel 2763: if (! $env{'form.ccuname'} ) {
1.193 raeburn 2764: $r->print($error.&mt('No login name specified').'.'.$end.$rtnlink);
1.27 matthew 2765: return;
2766: }
1.138 albertel 2767: if ( $env{'form.ccuname'} ne
2768: &LONCAPA::clean_username($env{'form.ccuname'}) ) {
1.281 bisitz 2769: $r->print($error.&mt('Invalid login name.').' '.
2770: &mt('Only letters, numbers, periods, dashes, @, and underscores are valid.').
1.193 raeburn 2771: $end.$rtnlink);
1.27 matthew 2772: return;
2773: }
1.101 albertel 2774: if (! $env{'form.ccdomain'} ) {
1.193 raeburn 2775: $r->print($error.&mt('No domain specified').'.'.$end.$rtnlink);
1.27 matthew 2776: return;
2777: }
1.138 albertel 2778: if ( $env{'form.ccdomain'} ne
2779: &LONCAPA::clean_domain($env{'form.ccdomain'}) ) {
1.281 bisitz 2780: $r->print($error.&mt('Invalid domain 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.219 raeburn 2785: if ($uhome eq 'no_host') {
2786: $newuser = 1;
2787: }
1.101 albertel 2788: if (! exists($env{'form.makeuser'})) {
1.29 matthew 2789: # Modifying an existing user, so check the validity of the name
2790: if ($uhome eq 'no_host') {
1.389 bisitz 2791: $r->print(
2792: $error
2793: .'<p class="LC_error">'
2794: .&mt('Unable to determine home server for [_1] in domain [_2].',
2795: '"'.$env{'form.ccuname'}.'"','"'.$env{'form.ccdomain'}.'"')
2796: .'</p>');
1.29 matthew 2797: return;
2798: }
2799: }
1.27 matthew 2800: # Determine authentication method and password for the user being modified
2801: my $amode='';
2802: my $genpwd='';
1.101 albertel 2803: if ($env{'form.login'} eq 'krb') {
1.41 albertel 2804: $amode='krb';
1.101 albertel 2805: $amode.=$env{'form.krbver'};
2806: $genpwd=$env{'form.krbarg'};
2807: } elsif ($env{'form.login'} eq 'int') {
1.27 matthew 2808: $amode='internal';
1.101 albertel 2809: $genpwd=$env{'form.intarg'};
2810: } elsif ($env{'form.login'} eq 'fsys') {
1.27 matthew 2811: $amode='unix';
1.101 albertel 2812: $genpwd=$env{'form.fsysarg'};
2813: } elsif ($env{'form.login'} eq 'loc') {
1.27 matthew 2814: $amode='localauth';
1.101 albertel 2815: $genpwd=$env{'form.locarg'};
1.27 matthew 2816: $genpwd=" " if (!$genpwd);
1.101 albertel 2817: } elsif (($env{'form.login'} eq 'nochange') ||
2818: ($env{'form.login'} eq '' )) {
1.34 matthew 2819: # There is no need to tell the user we did not change what they
2820: # did not ask us to change.
1.35 matthew 2821: # If they are creating a new user but have not specified login
2822: # information this will be caught below.
1.30 matthew 2823: } else {
1.367 golterma 2824: $r->print($error.&mt('Invalid login mode or password').$end.$rtnlink);
2825: return;
1.27 matthew 2826: }
1.164 albertel 2827:
1.188 raeburn 2828: $r->print('<h3>'.&mt('User [_1] in domain [_2]',
1.367 golterma 2829: $env{'form.ccuname'}.' ('.&Apache::loncommon::plainname($env{'form.ccuname'},
2830: $env{'form.ccdomain'}).')', $env{'form.ccdomain'}).'</h3>');
2831: my %prog_state = &Apache::lonhtmlcommon::Create_PrgWin($r,2);
1.344 bisitz 2832:
1.193 raeburn 2833: my (%alerts,%rulematch,%inst_results,%curr_rules);
1.334 raeburn 2834: my @userinfo = ('firstname','middlename','lastname','generation','permanentemail','id');
1.361 raeburn 2835: my @usertools = ('aboutme','blog','webdav','portfolio');
1.411 raeburn 2836: my @requestcourses = ('official','unofficial','community','textbook','placement');
1.362 raeburn 2837: my @requestauthor = ('requestauthor');
1.286 raeburn 2838: my ($othertitle,$usertypes,$types) =
2839: &Apache::loncommon::sorted_inst_types($env{'form.ccdomain'});
1.334 raeburn 2840: my %canmodify_status =
2841: &Apache::lonuserutils::can_modify_userinfo($context,$env{'form.ccdomain'},
2842: ['inststatus']);
1.101 albertel 2843: if ($env{'form.makeuser'}) {
1.164 albertel 2844: $r->print('<h3>'.&mt('Creating new account.').'</h3>');
1.27 matthew 2845: # Check for the authentication mode and password
2846: if (! $amode || ! $genpwd) {
1.193 raeburn 2847: $r->print($error.&mt('Invalid login mode or password').$end.$rtnlink);
1.27 matthew 2848: return;
1.18 albertel 2849: }
1.29 matthew 2850: # Determine desired host
1.101 albertel 2851: my $desiredhost = $env{'form.hserver'};
1.29 matthew 2852: if (lc($desiredhost) eq 'default') {
2853: $desiredhost = undef;
2854: } else {
1.147 albertel 2855: my %home_servers =
2856: &Apache::lonnet::get_servers($env{'form.ccdomain'},'library');
1.29 matthew 2857: if (! exists($home_servers{$desiredhost})) {
1.193 raeburn 2858: $r->print($error.&mt('Invalid home server specified').$end.$rtnlink);
2859: return;
2860: }
2861: }
2862: # Check ID format
2863: my %checkhash;
2864: my %checks = ('id' => 1);
2865: %{$checkhash{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}}} = (
1.219 raeburn 2866: 'newuser' => $newuser,
1.196 raeburn 2867: 'id' => $env{'form.cid'},
1.193 raeburn 2868: );
1.196 raeburn 2869: if ($env{'form.cid'} ne '') {
2870: &Apache::loncommon::user_rule_check(\%checkhash,\%checks,\%alerts,
2871: \%rulematch,\%inst_results,\%curr_rules);
2872: if (ref($alerts{'id'}) eq 'HASH') {
2873: if (ref($alerts{'id'}{$env{'form.ccdomain'}}) eq 'HASH') {
2874: my $domdesc =
2875: &Apache::lonnet::domain($env{'form.ccdomain'},'description');
2876: if ($alerts{'id'}{$env{'form.ccdomain'}}{$env{'form.cid'}}) {
2877: my $userchkmsg;
2878: if (ref($curr_rules{$env{'form.ccdomain'}}) eq 'HASH') {
2879: $userchkmsg =
2880: &Apache::loncommon::instrule_disallow_msg('id',
2881: $domdesc,1).
2882: &Apache::loncommon::user_rule_formats($env{'form.ccdomain'},
2883: $domdesc,$curr_rules{$env{'form.ccdomain'}}{'id'},'id');
2884: }
2885: $r->print($error.&mt('Invalid ID format').$end.
2886: $userchkmsg.$rtnlink);
2887: return;
2888: }
2889: }
1.29 matthew 2890: }
2891: }
1.367 golterma 2892: &Apache::lonhtmlcommon::Increment_PrgWin($r, \%prog_state);
1.27 matthew 2893: # Call modifyuser
2894: my $result = &Apache::lonnet::modifyuser
1.193 raeburn 2895: ($env{'form.ccdomain'},$env{'form.ccuname'},$env{'form.cid'},
1.188 raeburn 2896: $amode,$genpwd,$env{'form.cfirstname'},
2897: $env{'form.cmiddlename'},$env{'form.clastname'},
2898: $env{'form.cgeneration'},undef,$desiredhost,
2899: $env{'form.cpermanentemail'});
1.77 www 2900: $r->print(&mt('Generating user').': '.$result);
1.219 raeburn 2901: $uhome = &Apache::lonnet::homeserver($env{'form.ccuname'},
1.101 albertel 2902: $env{'form.ccdomain'});
1.334 raeburn 2903: my (%changeHash,%newcustom,%changed,%changedinfo);
1.267 raeburn 2904: if ($uhome ne 'no_host') {
1.334 raeburn 2905: if ($context eq 'domain') {
1.378 raeburn 2906: foreach my $name ('portfolio','author') {
2907: if ($env{'form.custom_'.$name.'quota'} == 1) {
2908: if ($env{'form.'.$name.'quota'} eq '') {
2909: $newcustom{$name.'quota'} = 0;
2910: } else {
2911: $newcustom{$name.'quota'} = $env{'form.'.$name.'quota'};
2912: $newcustom{$name.'quota'} =~ s/[^\d\.]//g;
2913: }
2914: if ("a_admin($newcustom{$name.'quota'},\%changeHash,$name)) {
2915: $changed{$name.'quota'} = 1;
2916: }
1.334 raeburn 2917: }
2918: }
2919: foreach my $item (@usertools) {
2920: if ($env{'form.custom'.$item} == 1) {
2921: $newcustom{$item} = $env{'form.tools_'.$item};
2922: $changed{$item} = &tool_admin($item,$newcustom{$item},
2923: \%changeHash,'tools');
2924: }
1.267 raeburn 2925: }
1.334 raeburn 2926: foreach my $item (@requestcourses) {
1.341 raeburn 2927: if ($env{'form.custom'.$item} == 1) {
2928: $newcustom{$item} = $env{'form.crsreq_'.$item};
2929: if ($env{'form.crsreq_'.$item} eq 'autolimit') {
2930: $newcustom{$item} .= '=';
1.383 raeburn 2931: $env{'form.crsreq_'.$item.'_limit'} =~ s/\D+//g;
2932: if ($env{'form.crsreq_'.$item.'_limit'}) {
1.341 raeburn 2933: $newcustom{$item} .= $env{'form.crsreq_'.$item.'_limit'};
2934: }
1.334 raeburn 2935: }
1.341 raeburn 2936: $changed{$item} = &tool_admin($item,$newcustom{$item},
2937: \%changeHash,'requestcourses');
1.334 raeburn 2938: }
1.275 raeburn 2939: }
1.362 raeburn 2940: if ($env{'form.customrequestauthor'} == 1) {
2941: $newcustom{'requestauthor'} = $env{'form.requestauthor'};
2942: $changed{'requestauthor'} = &tool_admin('requestauthor',
2943: $newcustom{'requestauthor'},
2944: \%changeHash,'requestauthor');
2945: }
1.275 raeburn 2946: }
1.334 raeburn 2947: if ($canmodify_status{'inststatus'}) {
2948: if (exists($env{'form.inststatus'})) {
2949: my @inststatuses = &Apache::loncommon::get_env_multiple('form.inststatus');
2950: if (@inststatuses > 0) {
2951: $changeHash{'inststatus'} = join(',',@inststatuses);
2952: $changed{'inststatus'} = $changeHash{'inststatus'};
1.306 raeburn 2953: }
2954: }
1.232 raeburn 2955: }
1.334 raeburn 2956: if (keys(%changed)) {
2957: foreach my $item (@userinfo) {
2958: $changeHash{$item} = $env{'form.c'.$item};
1.286 raeburn 2959: }
1.267 raeburn 2960: my $chgresult =
2961: &Apache::lonnet::put('environment',\%changeHash,
2962: $env{'form.ccdomain'},$env{'form.ccuname'});
2963: }
1.232 raeburn 2964: }
1.219 raeburn 2965: $r->print('<br />'.&mt('Home server').': '.$uhome.' '.
2966: &Apache::lonnet::hostname($uhome));
1.101 albertel 2967: } elsif (($env{'form.login'} ne 'nochange') &&
2968: ($env{'form.login'} ne '' )) {
1.27 matthew 2969: # Modify user privileges
2970: if (! $amode || ! $genpwd) {
1.193 raeburn 2971: $r->print($error.'Invalid login mode or password'.$end.$rtnlink);
1.27 matthew 2972: return;
1.20 harris41 2973: }
1.395 bisitz 2974: # Only allow authentication modification if the person has authority
1.101 albertel 2975: if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'})) {
1.20 harris41 2976: $r->print('Modifying authentication: '.
1.31 matthew 2977: &Apache::lonnet::modifyuserauth(
1.101 albertel 2978: $env{'form.ccdomain'},$env{'form.ccuname'},
1.21 harris41 2979: $amode,$genpwd));
1.102 albertel 2980: $r->print('<br />'.&mt('Home server').': '.&Apache::lonnet::homeserver
1.101 albertel 2981: ($env{'form.ccuname'},$env{'form.ccdomain'}));
1.4 www 2982: } else {
1.27 matthew 2983: # Okay, this is a non-fatal error.
1.395 bisitz 2984: $r->print($error.&mt('You do not have the authority to modify this users authentication information.').$end);
1.27 matthew 2985: }
1.28 matthew 2986: }
1.344 bisitz 2987: $r->rflush(); # Finish display of header before time consuming actions start
1.367 golterma 2988: &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state);
1.28 matthew 2989: ##
1.375 raeburn 2990: my (@userroles,%userupdate,$cnum,$cdom,$defaultcredits,%namechanged);
1.213 raeburn 2991: if ($context eq 'course') {
1.375 raeburn 2992: ($cnum,$cdom) =
2993: &Apache::lonuserutils::get_course_identity();
1.318 raeburn 2994: $crstype = &Apache::loncommon::course_type($cdom.'_'.$cnum);
1.375 raeburn 2995: if ($showcredits) {
2996: $defaultcredits = &Apache::lonuserutils::get_defaultcredits($cdom,$cnum);
2997: }
1.213 raeburn 2998: }
1.101 albertel 2999: if (! $env{'form.makeuser'} ) {
1.28 matthew 3000: # Check for need to change
3001: my %userenv = &Apache::lonnet::get
1.134 raeburn 3002: ('environment',['firstname','middlename','lastname','generation',
1.378 raeburn 3003: 'id','permanentemail','portfolioquota','authorquota','inststatus',
3004: 'tools.aboutme','tools.blog','tools.webdav','tools.portfolio',
1.361 raeburn 3005: 'requestcourses.official','requestcourses.unofficial',
1.384 raeburn 3006: 'requestcourses.community','requestcourses.textbook',
3007: 'reqcrsotherdom.official','reqcrsotherdom.unofficial',
3008: 'reqcrsotherdom.community','reqcrsotherdom.textbook',
1.427 raeburn 3009: 'reqcrsotherdom.placement','requestauthor'],
1.160 raeburn 3010: $env{'form.ccdomain'},$env{'form.ccuname'});
1.28 matthew 3011: my ($tmp) = keys(%userenv);
3012: if ($tmp =~ /^(con_lost|error)/i) {
3013: %userenv = ();
3014: }
1.206 raeburn 3015: my $no_forceid_alert;
3016: # Check to see if user information can be changed
3017: my %domconfig =
3018: &Apache::lonnet::get_dom('configuration',['usermodification'],
3019: $env{'form.ccdomain'});
1.213 raeburn 3020: my @statuses = ('active','future');
3021: my %roles = &Apache::lonnet::get_my_roles($env{'form.ccuname'},$env{'form.ccdomain'},'userroles',\@statuses,undef,$env{'request.role.domain'});
3022: my ($auname,$audom);
1.220 raeburn 3023: if ($context eq 'author') {
1.206 raeburn 3024: $auname = $env{'user.name'};
3025: $audom = $env{'user.domain'};
3026: }
3027: foreach my $item (keys(%roles)) {
1.220 raeburn 3028: my ($rolenum,$roledom,$role) = split(/:/,$item,-1);
1.206 raeburn 3029: if ($context eq 'course') {
3030: if ($cnum ne '' && $cdom ne '') {
3031: if ($rolenum eq $cnum && $roledom eq $cdom) {
3032: if (!grep(/^\Q$role\E$/,@userroles)) {
3033: push(@userroles,$role);
3034: }
3035: }
3036: }
3037: } elsif ($context eq 'author') {
3038: if ($rolenum eq $auname && $roledom eq $audom) {
3039: if (!grep(/^\Q$role\E$/,@userroles)) {
3040: push(@userroles,$role);
3041: }
3042: }
3043: }
3044: }
1.220 raeburn 3045: if ($env{'form.action'} eq 'singlestudent') {
3046: if (!grep(/^st$/,@userroles)) {
3047: push(@userroles,'st');
3048: }
3049: } else {
3050: # Check for course or co-author roles being activated or re-enabled
3051: if ($context eq 'author' || $context eq 'course') {
3052: foreach my $key (keys(%env)) {
3053: if ($context eq 'author') {
3054: if ($key=~/^form\.act_\Q$audom\E_\Q$auname\E_([^_]+)/) {
3055: if (!grep(/^\Q$1\E$/,@userroles)) {
3056: push(@userroles,$1);
3057: }
3058: } elsif ($key =~/^form\.ren\:\Q$audom\E\/\Q$auname\E_([^_]+)/) {
3059: if (!grep(/^\Q$1\E$/,@userroles)) {
3060: push(@userroles,$1);
3061: }
1.206 raeburn 3062: }
1.220 raeburn 3063: } elsif ($context eq 'course') {
3064: if ($key=~/^form\.act_\Q$cdom\E_\Q$cnum\E_([^_]+)/) {
3065: if (!grep(/^\Q$1\E$/,@userroles)) {
3066: push(@userroles,$1);
3067: }
3068: } elsif ($key =~/^form\.ren\:\Q$cdom\E\/\Q$cnum\E(\/?\w*)_([^_]+)/) {
3069: if (!grep(/^\Q$1\E$/,@userroles)) {
3070: push(@userroles,$1);
3071: }
1.206 raeburn 3072: }
3073: }
3074: }
3075: }
3076: }
3077: #Check to see if we can change personal data for the user
3078: my (@mod_disallowed,@longroles);
3079: foreach my $role (@userroles) {
3080: if ($role eq 'cr') {
3081: push(@longroles,'Custom');
3082: } else {
1.318 raeburn 3083: push(@longroles,&Apache::lonnet::plaintext($role,$crstype));
1.206 raeburn 3084: }
3085: }
1.219 raeburn 3086: my %canmodify = &Apache::lonuserutils::can_modify_userinfo($context,$env{'form.ccdomain'},\@userinfo,\@userroles);
3087: foreach my $item (@userinfo) {
1.28 matthew 3088: # Strip leading and trailing whitespace
1.203 raeburn 3089: $env{'form.c'.$item} =~ s/(\s+$|^\s+)//g;
1.219 raeburn 3090: if (!$canmodify{$item}) {
1.207 raeburn 3091: if (defined($env{'form.c'.$item})) {
3092: if ($env{'form.c'.$item} ne $userenv{$item}) {
3093: push(@mod_disallowed,$item);
3094: }
1.206 raeburn 3095: }
3096: $env{'form.c'.$item} = $userenv{$item};
3097: }
1.28 matthew 3098: }
1.259 bisitz 3099: # Check to see if we can change the Student/Employee ID
1.196 raeburn 3100: my $forceid = $env{'form.forceid'};
3101: my $recurseid = $env{'form.recurseid'};
3102: my (%alerts,%rulematch,%idinst_results,%curr_rules,%got_rules);
1.203 raeburn 3103: my %uidhash = &Apache::lonnet::idrget($env{'form.ccdomain'},
3104: $env{'form.ccuname'});
3105: if (($uidhash{$env{'form.ccuname'}}) &&
3106: ($uidhash{$env{'form.ccuname'}}!~/error\:/) &&
3107: (!$forceid)) {
3108: if ($env{'form.cid'} ne $uidhash{$env{'form.ccuname'}}) {
3109: $env{'form.cid'} = $userenv{'id'};
1.293 bisitz 3110: $no_forceid_alert = &mt('New student/employee ID does not match existing ID for this user.')
1.259 bisitz 3111: .'<br />'
3112: .&mt("Change is not permitted without checking the 'Force ID change' checkbox on the previous page.")
3113: .'<br />'."\n";
1.203 raeburn 3114: }
3115: }
3116: if ($env{'form.cid'} ne $userenv{'id'}) {
1.196 raeburn 3117: my $checkhash;
3118: my $checks = { 'id' => 1 };
3119: $checkhash->{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}} =
3120: { 'newuser' => $newuser,
3121: 'id' => $env{'form.cid'},
3122: };
3123: &Apache::loncommon::user_rule_check($checkhash,$checks,
3124: \%alerts,\%rulematch,\%idinst_results,\%curr_rules,\%got_rules);
3125: if (ref($alerts{'id'}) eq 'HASH') {
3126: if (ref($alerts{'id'}{$env{'form.ccdomain'}}) eq 'HASH') {
1.203 raeburn 3127: $env{'form.cid'} = $userenv{'id'};
1.196 raeburn 3128: }
3129: }
3130: }
1.378 raeburn 3131: my (%quotachanged,%oldquota,%newquota,%olddefquota,%newdefquota,
3132: $oldinststatus,$newinststatus,%oldisdefault,%newisdefault,%oldsettings,
1.339 raeburn 3133: %oldsettingstext,%newsettings,%newsettingstext,@disporder,
1.378 raeburn 3134: %oldsettingstatus,%newsettingstatus);
1.334 raeburn 3135: @disporder = ('inststatus');
3136: if ($env{'request.role.domain'} eq $env{'form.ccdomain'}) {
1.362 raeburn 3137: push(@disporder,'requestcourses','requestauthor');
1.334 raeburn 3138: } else {
3139: push(@disporder,'reqcrsotherdom');
3140: }
3141: push(@disporder,('quota','tools'));
1.338 raeburn 3142: $oldinststatus = $userenv{'inststatus'};
1.378 raeburn 3143: foreach my $name ('portfolio','author') {
3144: ($olddefquota{$name},$oldsettingstatus{$name}) =
3145: &Apache::loncommon::default_quota($env{'form.ccdomain'},$oldinststatus,$name);
3146: ($newdefquota{$name},$newsettingstatus{$name}) = ($olddefquota{$name},$oldsettingstatus{$name});
3147: }
1.334 raeburn 3148: my %canshow;
1.220 raeburn 3149: if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
1.334 raeburn 3150: $canshow{'quota'} = 1;
1.220 raeburn 3151: }
1.267 raeburn 3152: if (&Apache::lonnet::allowed('mut',$env{'form.ccdomain'})) {
1.334 raeburn 3153: $canshow{'tools'} = 1;
1.267 raeburn 3154: }
1.275 raeburn 3155: if (&Apache::lonnet::allowed('ccc',$env{'form.ccdomain'})) {
1.334 raeburn 3156: $canshow{'requestcourses'} = 1;
1.300 raeburn 3157: } elsif (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
1.334 raeburn 3158: $canshow{'reqcrsotherdom'} = 1;
1.275 raeburn 3159: }
1.286 raeburn 3160: if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'})) {
1.334 raeburn 3161: $canshow{'inststatus'} = 1;
1.286 raeburn 3162: }
1.362 raeburn 3163: if (&Apache::lonnet::allowed('cau',$env{'form.ccdomain'})) {
3164: $canshow{'requestauthor'} = 1;
3165: }
1.267 raeburn 3166: my (%changeHash,%changed);
1.286 raeburn 3167: if ($oldinststatus eq '') {
1.334 raeburn 3168: $oldsettings{'inststatus'} = $othertitle;
1.286 raeburn 3169: } else {
3170: if (ref($usertypes) eq 'HASH') {
1.334 raeburn 3171: $oldsettings{'inststatus'} = join(', ',map{ $usertypes->{ &unescape($_) }; } (split(/:/,$userenv{'inststatus'})));
1.286 raeburn 3172: } else {
1.334 raeburn 3173: $oldsettings{'inststatus'} = join(', ',map{ &unescape($_); } (split(/:/,$userenv{'inststatus'})));
1.286 raeburn 3174: }
3175: }
3176: $changeHash{'inststatus'} = $userenv{'inststatus'};
1.334 raeburn 3177: if ($canmodify_status{'inststatus'}) {
3178: $canshow{'inststatus'} = 1;
1.286 raeburn 3179: if (exists($env{'form.inststatus'})) {
3180: my @inststatuses = &Apache::loncommon::get_env_multiple('form.inststatus');
3181: if (@inststatuses > 0) {
3182: $newinststatus = join(':',map { &escape($_); } @inststatuses);
3183: $changeHash{'inststatus'} = $newinststatus;
3184: if ($newinststatus ne $oldinststatus) {
3185: $changed{'inststatus'} = $newinststatus;
1.378 raeburn 3186: foreach my $name ('portfolio','author') {
3187: ($newdefquota{$name},$newsettingstatus{$name}) =
3188: &Apache::loncommon::default_quota($env{'form.ccdomain'},$newinststatus,$name);
3189: }
1.286 raeburn 3190: }
3191: if (ref($usertypes) eq 'HASH') {
1.334 raeburn 3192: $newsettings{'inststatus'} = join(', ',map{ $usertypes->{$_}; } (@inststatuses));
1.286 raeburn 3193: } else {
1.337 raeburn 3194: $newsettings{'inststatus'} = join(', ',@inststatuses);
1.286 raeburn 3195: }
1.334 raeburn 3196: }
3197: } else {
3198: $newinststatus = '';
3199: $changeHash{'inststatus'} = $newinststatus;
3200: $newsettings{'inststatus'} = $othertitle;
3201: if ($newinststatus ne $oldinststatus) {
3202: $changed{'inststatus'} = $changeHash{'inststatus'};
1.378 raeburn 3203: foreach my $name ('portfolio','author') {
3204: ($newdefquota{$name},$newsettingstatus{$name}) =
3205: &Apache::loncommon::default_quota($env{'form.ccdomain'},$newinststatus,$name);
3206: }
1.286 raeburn 3207: }
3208: }
1.334 raeburn 3209: } elsif ($context ne 'selfcreate') {
3210: $canshow{'inststatus'} = 1;
1.337 raeburn 3211: $newsettings{'inststatus'} = $oldsettings{'inststatus'};
1.286 raeburn 3212: }
1.378 raeburn 3213: foreach my $name ('portfolio','author') {
3214: $changeHash{$name.'quota'} = $userenv{$name.'quota'};
3215: }
1.334 raeburn 3216: if ($context eq 'domain') {
1.378 raeburn 3217: foreach my $name ('portfolio','author') {
3218: if ($userenv{$name.'quota'} ne '') {
3219: $oldquota{$name} = $userenv{$name.'quota'};
3220: if ($env{'form.custom_'.$name.'quota'} == 1) {
3221: if ($env{'form.'.$name.'quota'} eq '') {
3222: $newquota{$name} = 0;
3223: } else {
3224: $newquota{$name} = $env{'form.'.$name.'quota'};
3225: $newquota{$name} =~ s/[^\d\.]//g;
3226: }
3227: if ($newquota{$name} != $oldquota{$name}) {
3228: if ("a_admin($newquota{$name},\%changeHash,$name)) {
3229: $changed{$name.'quota'} = 1;
3230: }
3231: }
1.334 raeburn 3232: } else {
1.378 raeburn 3233: if ("a_admin('',\%changeHash,$name)) {
3234: $changed{$name.'quota'} = 1;
3235: $newquota{$name} = $newdefquota{$name};
3236: $newisdefault{$name} = 1;
3237: }
1.334 raeburn 3238: }
1.149 raeburn 3239: } else {
1.378 raeburn 3240: $oldisdefault{$name} = 1;
3241: $oldquota{$name} = $olddefquota{$name};
3242: if ($env{'form.custom_'.$name.'quota'} == 1) {
3243: if ($env{'form.'.$name.'quota'} eq '') {
3244: $newquota{$name} = 0;
3245: } else {
3246: $newquota{$name} = $env{'form.'.$name.'quota'};
3247: $newquota{$name} =~ s/[^\d\.]//g;
3248: }
3249: if ("a_admin($newquota{$name},\%changeHash,$name)) {
3250: $changed{$name.'quota'} = 1;
3251: }
1.334 raeburn 3252: } else {
1.378 raeburn 3253: $newquota{$name} = $newdefquota{$name};
3254: $newisdefault{$name} = 1;
1.334 raeburn 3255: }
1.378 raeburn 3256: }
3257: if ($oldisdefault{$name}) {
3258: $oldsettingstext{'quota'}{$name} = &get_defaultquota_text($oldsettingstatus{$name});
1.383 raeburn 3259: } else {
3260: $oldsettingstext{'quota'}{$name} = &mt('custom quota: [_1] MB',$oldquota{$name});
1.378 raeburn 3261: }
3262: if ($newisdefault{$name}) {
3263: $newsettingstext{'quota'}{$name} = &get_defaultquota_text($newsettingstatus{$name});
1.383 raeburn 3264: } else {
3265: $newsettingstext{'quota'}{$name} = &mt('custom quota: [_1] MB',$newquota{$name});
1.134 raeburn 3266: }
3267: }
1.334 raeburn 3268: &tool_changes('tools',\@usertools,\%oldsettings,\%oldsettingstext,\%userenv,
3269: \%changeHash,\%changed,\%newsettings,\%newsettingstext);
3270: if ($env{'form.ccdomain'} eq $env{'request.role.domain'}) {
3271: &tool_changes('requestcourses',\@requestcourses,\%oldsettings,\%oldsettingstext,
3272: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
1.384 raeburn 3273: &tool_changes('requestauthor',\@requestauthor,\%oldsettings,\%oldsettingstext,
3274: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
1.149 raeburn 3275: } else {
1.334 raeburn 3276: &tool_changes('reqcrsotherdom',\@requestcourses,\%oldsettings,\%oldsettingstext,
3277: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
1.149 raeburn 3278: }
3279: }
1.334 raeburn 3280: foreach my $item (@userinfo) {
3281: if ($env{'form.c'.$item} ne $userenv{$item}) {
3282: $namechanged{$item} = 1;
3283: }
1.204 raeburn 3284: }
1.378 raeburn 3285: foreach my $name ('portfolio','author') {
1.390 bisitz 3286: $oldsettings{'quota'}{$name} = &mt('[_1] MB',$oldquota{$name});
3287: $newsettings{'quota'}{$name} = &mt('[_1] MB',$newquota{$name});
1.378 raeburn 3288: }
1.334 raeburn 3289: if ((keys(%namechanged) > 0) || (keys(%changed) > 0)) {
1.267 raeburn 3290: my ($chgresult,$namechgresult);
3291: if (keys(%changed) > 0) {
3292: $chgresult =
1.204 raeburn 3293: &Apache::lonnet::put('environment',\%changeHash,
3294: $env{'form.ccdomain'},$env{'form.ccuname'});
1.267 raeburn 3295: if ($chgresult eq 'ok') {
3296: if (($env{'user.name'} eq $env{'form.ccuname'}) &&
3297: ($env{'user.domain'} eq $env{'form.ccdomain'})) {
1.270 raeburn 3298: my %newenvhash;
3299: foreach my $key (keys(%changed)) {
1.411 raeburn 3300: if (($key eq 'official') || ($key eq 'unofficial') ||
3301: ($key eq 'community') || ($key eq 'textbook') ||
3302: ($key eq 'placement')) {
1.279 raeburn 3303: $newenvhash{'environment.requestcourses.'.$key} =
3304: $changeHash{'requestcourses.'.$key};
1.362 raeburn 3305: if ($changeHash{'requestcourses.'.$key}) {
1.332 raeburn 3306: $newenvhash{'environment.canrequest.'.$key} = 1;
1.279 raeburn 3307: } else {
3308: $newenvhash{'environment.canrequest.'.$key} =
3309: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
3310: $key,'reload','requestcourses');
3311: }
1.362 raeburn 3312: } elsif ($key eq 'requestauthor') {
3313: $newenvhash{'environment.'.$key} = $changeHash{$key};
3314: if ($changeHash{$key}) {
3315: $newenvhash{'environment.canrequest.author'} = 1;
3316: } else {
3317: $newenvhash{'environment.canrequest.author'} =
3318: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
3319: $key,'reload','requestauthor');
3320: }
1.275 raeburn 3321: } elsif ($key ne 'quota') {
1.270 raeburn 3322: $newenvhash{'environment.tools.'.$key} =
3323: $changeHash{'tools.'.$key};
1.279 raeburn 3324: if ($changeHash{'tools.'.$key} ne '') {
3325: $newenvhash{'environment.availabletools.'.$key} =
3326: $changeHash{'tools.'.$key};
3327: } else {
3328: $newenvhash{'environment.availabletools.'.$key} =
1.367 golterma 3329: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
3330: $key,'reload','tools');
1.279 raeburn 3331: }
1.270 raeburn 3332: }
3333: }
1.271 raeburn 3334: if (keys(%newenvhash)) {
3335: &Apache::lonnet::appenv(\%newenvhash);
3336: }
1.267 raeburn 3337: }
3338: }
1.204 raeburn 3339: }
1.334 raeburn 3340: if (keys(%namechanged) > 0) {
1.337 raeburn 3341: foreach my $field (@userinfo) {
3342: $changeHash{$field} = $env{'form.c'.$field};
3343: }
3344: # Make the change
1.204 raeburn 3345: $namechgresult =
3346: &Apache::lonnet::modifyuser($env{'form.ccdomain'},
3347: $env{'form.ccuname'},$changeHash{'id'},undef,undef,
3348: $changeHash{'firstname'},$changeHash{'middlename'},
3349: $changeHash{'lastname'},$changeHash{'generation'},
1.337 raeburn 3350: $changeHash{'id'},undef,$changeHash{'permanentemail'},undef,\@userinfo);
1.220 raeburn 3351: %userupdate = (
3352: lastname => $env{'form.clastname'},
3353: middlename => $env{'form.cmiddlename'},
3354: firstname => $env{'form.cfirstname'},
3355: generation => $env{'form.cgeneration'},
3356: id => $env{'form.cid'},
3357: );
1.204 raeburn 3358: }
1.334 raeburn 3359: if (((keys(%namechanged) > 0) && $namechgresult eq 'ok') ||
1.267 raeburn 3360: ((keys(%changed) > 0) && $chgresult eq 'ok')) {
1.28 matthew 3361: # Tell the user we changed the name
1.334 raeburn 3362: &display_userinfo($r,1,\@disporder,\%canshow,\@requestcourses,
1.362 raeburn 3363: \@usertools,\@requestauthor,\%userenv,\%changed,\%namechanged,
1.334 raeburn 3364: \%oldsettings, \%oldsettingstext,\%newsettings,
3365: \%newsettingstext);
1.203 raeburn 3366: if ($env{'form.cid'} ne $userenv{'id'}) {
3367: &Apache::lonnet::idput($env{'form.ccdomain'},
1.407 raeburn 3368: {$env{'form.ccuname'} => $env{'form.cid'}},$uhome,'ids');
1.203 raeburn 3369: if (($recurseid) &&
3370: (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'}))) {
3371: my $idresult =
3372: &Apache::lonuserutils::propagate_id_change(
3373: $env{'form.ccuname'},$env{'form.ccdomain'},
3374: \%userupdate);
3375: $r->print('<br />'.$idresult.'<br />');
3376: }
1.196 raeburn 3377: }
1.149 raeburn 3378: if (($env{'form.ccdomain'} eq $env{'user.domain'}) &&
3379: ($env{'form.ccuname'} eq $env{'user.name'})) {
3380: my %newenvhash;
3381: foreach my $key (keys(%changeHash)) {
3382: $newenvhash{'environment.'.$key} = $changeHash{$key};
3383: }
1.238 raeburn 3384: &Apache::lonnet::appenv(\%newenvhash);
1.149 raeburn 3385: }
1.28 matthew 3386: } else { # error occurred
1.389 bisitz 3387: $r->print(
3388: '<p class="LC_error">'
3389: .&mt('Unable to successfully change environment for [_1] in domain [_2].',
3390: '"'.$env{'form.ccuname'}.'"',
3391: '"'.$env{'form.ccdomain'}.'"')
3392: .'</p>');
1.28 matthew 3393: }
1.334 raeburn 3394: } else { # End of if ($env ... ) logic
1.275 raeburn 3395: # They did not want to change the users name, quota, tool availability,
3396: # or ability to request creation of courses,
1.267 raeburn 3397: # but we can still tell them what the name and quota and availabilities are
1.334 raeburn 3398: &display_userinfo($r,undef,\@disporder,\%canshow,\@requestcourses,
1.362 raeburn 3399: \@usertools,\@requestauthor,\%userenv,\%changed,\%namechanged,\%oldsettings,
1.334 raeburn 3400: \%oldsettingstext,\%newsettings,\%newsettingstext);
1.28 matthew 3401: }
1.206 raeburn 3402: if (@mod_disallowed) {
3403: my ($rolestr,$contextname);
3404: if (@longroles > 0) {
3405: $rolestr = join(', ',@longroles);
3406: } else {
3407: $rolestr = &mt('No roles');
3408: }
3409: if ($context eq 'course') {
1.399 bisitz 3410: $contextname = 'course';
1.206 raeburn 3411: } elsif ($context eq 'author') {
1.399 bisitz 3412: $contextname = 'co-author';
1.206 raeburn 3413: }
3414: $r->print(&mt('The following fields were not updated: ').'<ul>');
3415: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
3416: foreach my $field (@mod_disallowed) {
3417: $r->print('<li>'.$fieldtitles{$field}.'</li>'."\n");
3418: }
1.207 raeburn 3419: $r->print('</ul>');
3420: if (@mod_disallowed == 1) {
1.399 bisitz 3421: $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 3422: } else {
1.399 bisitz 3423: $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 3424: }
1.292 bisitz 3425: my $helplink = 'javascript:helpMenu('."'display'".')';
3426: $r->print('<span class="LC_cusr_emph">'.$rolestr.'</span><br />'
3427: .&mt('Please contact your [_1]helpdesk[_2] for more information.'
3428: ,'<a href="'.$helplink.'">','</a>')
3429: .'<br />');
1.206 raeburn 3430: }
1.259 bisitz 3431: $r->print('<span class="LC_warning">'
3432: .$no_forceid_alert
3433: .&Apache::lonuserutils::print_namespacing_alerts($env{'form.ccdomain'},\%alerts,\%curr_rules)
3434: .'</span>');
1.4 www 3435: }
1.367 golterma 3436: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
1.220 raeburn 3437: if ($env{'form.action'} eq 'singlestudent') {
1.375 raeburn 3438: &enroll_single_student($r,$uhome,$amode,$genpwd,$now,$newuser,$context,
3439: $crstype,$showcredits,$defaultcredits);
1.386 bisitz 3440: my $linktext = ($crstype eq 'Community' ?
3441: &mt('Enroll Another Member') : &mt('Enroll Another Student'));
3442: $r->print(
3443: &Apache::lonhtmlcommon::actionbox([
3444: '<a href="javascript:backPage(document.userupdate)">'
3445: .($crstype eq 'Community' ?
3446: &mt('Enroll Another Member') : &mt('Enroll Another Student'))
3447: .'</a>']));
1.220 raeburn 3448: } else {
1.375 raeburn 3449: my @rolechanges = &update_roles($r,$context,$showcredits);
1.334 raeburn 3450: if (keys(%namechanged) > 0) {
1.220 raeburn 3451: if ($context eq 'course') {
3452: if (@userroles > 0) {
1.225 raeburn 3453: if ((@rolechanges == 0) ||
3454: (!(grep(/^st$/,@rolechanges)))) {
3455: if (grep(/^st$/,@userroles)) {
3456: my $classlistupdated =
3457: &Apache::lonuserutils::update_classlist($cdom,
1.220 raeburn 3458: $cnum,$env{'form.ccdomain'},
3459: $env{'form.ccuname'},\%userupdate);
1.225 raeburn 3460: }
1.220 raeburn 3461: }
3462: }
3463: }
3464: }
1.226 raeburn 3465: my $userinfo = &Apache::loncommon::plainname($env{'form.ccuname'},
1.233 raeburn 3466: $env{'form.ccdomain'});
3467: if ($env{'form.popup'}) {
3468: $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a></p>');
3469: } else {
1.367 golterma 3470: $r->print('<br />'.&Apache::lonhtmlcommon::actionbox(['<a href="javascript:backPage(document.userupdate,'."'$env{'form.prevphase'}','modify'".')">'
3471: .&mt('Modify this user: [_1]','<span class="LC_cusr_emph">'.$env{'form.ccuname'}.':'.$env{'form.ccdomain'}.' ('.$userinfo.')</span>').'</a>',
3472: '<a href="javascript:backPage(document.userupdate)">'.&mt('Create/Modify Another User').'</a>']));
1.233 raeburn 3473: }
1.220 raeburn 3474: }
3475: }
3476:
1.334 raeburn 3477: sub display_userinfo {
1.362 raeburn 3478: my ($r,$changed,$order,$canshow,$requestcourses,$usertools,$requestauthor,
3479: $userenv,$changedhash,$namechangedhash,$oldsetting,$oldsettingtext,
1.334 raeburn 3480: $newsetting,$newsettingtext) = @_;
3481: return unless (ref($order) eq 'ARRAY' &&
3482: ref($canshow) eq 'HASH' &&
3483: ref($requestcourses) eq 'ARRAY' &&
1.362 raeburn 3484: ref($requestauthor) eq 'ARRAY' &&
1.334 raeburn 3485: ref($usertools) eq 'ARRAY' &&
3486: ref($userenv) eq 'HASH' &&
3487: ref($changedhash) eq 'HASH' &&
3488: ref($oldsetting) eq 'HASH' &&
3489: ref($oldsettingtext) eq 'HASH' &&
3490: ref($newsetting) eq 'HASH' &&
3491: ref($newsettingtext) eq 'HASH');
3492: my %lt=&Apache::lonlocal::texthash(
1.372 raeburn 3493: 'ui' => 'User Information',
1.334 raeburn 3494: 'uic' => 'User Information Changed',
3495: 'firstname' => 'First Name',
3496: 'middlename' => 'Middle Name',
3497: 'lastname' => 'Last Name',
3498: 'generation' => 'Generation',
3499: 'id' => 'Student/Employee ID',
3500: 'permanentemail' => 'Permanent e-mail address',
1.378 raeburn 3501: 'portfolioquota' => 'Disk space allocated to portfolio files',
1.385 bisitz 3502: 'authorquota' => 'Disk space allocated to Authoring Space',
1.334 raeburn 3503: 'blog' => 'Blog Availability',
1.361 raeburn 3504: 'webdav' => 'WebDAV Availability',
1.334 raeburn 3505: 'aboutme' => 'Personal Information Page Availability',
3506: 'portfolio' => 'Portfolio Availability',
3507: 'official' => 'Can Request Official Courses',
3508: 'unofficial' => 'Can Request Unofficial Courses',
3509: 'community' => 'Can Request Communities',
1.384 raeburn 3510: 'textbook' => 'Can Request Textbook Courses',
1.411 raeburn 3511: 'placement' => 'Can Request Placement Tests',
1.362 raeburn 3512: 'requestauthor' => 'Can Request Author Role',
1.334 raeburn 3513: 'inststatus' => "Affiliation",
3514: 'prvs' => 'Previous Value:',
3515: 'chto' => 'Changed To:'
3516: );
3517: if ($changed) {
1.372 raeburn 3518: $r->print('<h3>'.$lt{'uic'}.'</h3>'.
1.367 golterma 3519: &Apache::loncommon::start_data_table().
3520: &Apache::loncommon::start_data_table_header_row());
1.334 raeburn 3521: $r->print("<th> </th>\n");
1.367 golterma 3522: $r->print('<th><b>'.$lt{'prvs'}.'</b></th>');
3523: $r->print('<th><span class="LC_nobreak"><b>'.$lt{'chto'}.'</b></span></th>');
3524: $r->print(&Apache::loncommon::end_data_table_header_row());
3525: my @userinfo = ('firstname','middlename','lastname','generation','permanentemail','id');
3526:
1.334 raeburn 3527: foreach my $item (@userinfo) {
3528: my $value = $env{'form.c'.$item};
1.367 golterma 3529: #show changes only:
1.383 raeburn 3530: unless ($value eq $userenv->{$item}){
1.367 golterma 3531: $r->print(&Apache::loncommon::start_data_table_row());
3532: $r->print("<td>$lt{$item}</td>\n");
1.383 raeburn 3533: $r->print("<td>".$userenv->{$item}."</td>\n");
1.367 golterma 3534: $r->print("<td>$value </td>\n");
3535: $r->print(&Apache::loncommon::end_data_table_row());
1.334 raeburn 3536: }
3537: }
3538: foreach my $entry (@{$order}) {
1.383 raeburn 3539: if ($canshow->{$entry}) {
3540: if (($entry eq 'requestcourses') || ($entry eq 'reqcrsotherdom') || ($entry eq 'requestauthor')) {
3541: my @items;
3542: if ($entry eq 'requestauthor') {
3543: @items = ($entry);
3544: } else {
3545: @items = @{$requestcourses};
1.384 raeburn 3546: }
1.383 raeburn 3547: foreach my $item (@items) {
3548: if (($newsetting->{$item} ne $oldsetting->{$item}) ||
3549: ($newsettingtext->{$item} ne $oldsettingtext->{$item})) {
3550: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3551: $r->print("<td>$lt{$item}</td>\n");
3552: $r->print("<td>".$oldsetting->{$item});
3553: if ($oldsettingtext->{$item}) {
3554: if ($oldsetting->{$item}) {
3555: $r->print(' -- ');
3556: }
3557: $r->print($oldsettingtext->{$item});
3558: }
3559: $r->print("</td>\n");
3560: $r->print("<td>".$newsetting->{$item});
3561: if ($newsettingtext->{$item}) {
3562: if ($newsetting->{$item}) {
3563: $r->print(' -- ');
3564: }
3565: $r->print($newsettingtext->{$item});
3566: }
3567: $r->print("</td>\n");
3568: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.334 raeburn 3569: }
3570: }
3571: } elsif ($entry eq 'tools') {
3572: foreach my $item (@{$usertools}) {
1.383 raeburn 3573: if ($newsetting->{$item} ne $oldsetting->{$item}) {
3574: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3575: $r->print("<td>$lt{$item}</td>\n");
3576: $r->print("<td>".$oldsetting->{$item}.' '.$oldsettingtext->{$item}."</td>\n");
3577: $r->print("<td>".$newsetting->{$item}.' '.$newsettingtext->{$item}."</td>\n");
3578: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.334 raeburn 3579: }
3580: }
1.378 raeburn 3581: } elsif ($entry eq 'quota') {
3582: if ((ref($oldsetting->{$entry}) eq 'HASH') && (ref($oldsettingtext->{$entry}) eq 'HASH') &&
3583: (ref($newsetting->{$entry}) eq 'HASH') && (ref($newsettingtext->{$entry}) eq 'HASH')) {
3584: foreach my $name ('portfolio','author') {
1.383 raeburn 3585: if ($newsetting->{$entry}->{$name} ne $oldsetting->{$entry}->{$name}) {
3586: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3587: $r->print("<td>$lt{$name.$entry}</td>\n");
3588: $r->print("<td>".$oldsettingtext->{$entry}->{$name}."</td>\n");
3589: $r->print("<td>".$newsettingtext->{$entry}->{$name}."</td>\n");
3590: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.378 raeburn 3591: }
3592: }
3593: }
1.334 raeburn 3594: } else {
1.383 raeburn 3595: if ($newsetting->{$entry} ne $oldsetting->{$entry}) {
3596: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3597: $r->print("<td>$lt{$entry}</td>\n");
3598: $r->print("<td>".$oldsetting->{$entry}.' '.$oldsettingtext->{$entry}."</td>\n");
3599: $r->print("<td>".$newsetting->{$entry}.' '.$newsettingtext->{$entry}."</td>\n");
3600: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.334 raeburn 3601: }
3602: }
3603: }
3604: }
1.367 golterma 3605: $r->print(&Apache::loncommon::end_data_table().'<br />');
1.372 raeburn 3606: } else {
3607: $r->print('<h3>'.$lt{'ui'}.'</h3>'.
3608: '<p>'.&mt('No changes made to user information').'</p>');
1.334 raeburn 3609: }
3610: return;
3611: }
3612:
1.275 raeburn 3613: sub tool_changes {
3614: my ($context,$usertools,$oldaccess,$oldaccesstext,$userenv,$changeHash,
3615: $changed,$newaccess,$newaccesstext) = @_;
3616: if (!((ref($usertools) eq 'ARRAY') && (ref($oldaccess) eq 'HASH') &&
3617: (ref($oldaccesstext) eq 'HASH') && (ref($userenv) eq 'HASH') &&
3618: (ref($changeHash) eq 'HASH') && (ref($changed) eq 'HASH') &&
3619: (ref($newaccess) eq 'HASH') && (ref($newaccesstext) eq 'HASH'))) {
3620: return;
3621: }
1.383 raeburn 3622: my %reqdisplay = &requestchange_display();
1.300 raeburn 3623: if ($context eq 'reqcrsotherdom') {
1.309 raeburn 3624: my @options = ('approval','validate','autolimit');
1.306 raeburn 3625: my $optregex = join('|',@options);
1.300 raeburn 3626: my $cdom = $env{'request.role.domain'};
3627: foreach my $tool (@{$usertools}) {
1.383 raeburn 3628: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
1.314 raeburn 3629: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
1.300 raeburn 3630: $changeHash->{$context.'.'.$tool} = $userenv->{$context.'.'.$tool};
1.383 raeburn 3631: my ($newop,$limit);
1.314 raeburn 3632: if ($env{'form.'.$context.'_'.$tool}) {
3633: $newop = $env{'form.'.$context.'_'.$tool};
3634: if ($newop eq 'autolimit') {
1.383 raeburn 3635: $limit = $env{'form.'.$context.'_'.$tool.'_limit'};
1.314 raeburn 3636: $limit =~ s/\D+//g;
3637: $newop .= '='.$limit;
3638: }
3639: }
1.300 raeburn 3640: if ($userenv->{$context.'.'.$tool} eq '') {
1.314 raeburn 3641: if ($newop) {
3642: $changed->{$tool}=&tool_admin($tool,$cdom.':'.$newop,
1.300 raeburn 3643: $changeHash,$context);
3644: if ($changed->{$tool}) {
1.383 raeburn 3645: if ($newop =~ /^autolimit/) {
3646: if ($limit) {
3647: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3648: } else {
3649: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3650: }
3651: } else {
3652: $newaccesstext->{$tool} = $reqdisplay{$newop};
3653: }
1.300 raeburn 3654: } else {
3655: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
3656: }
3657: }
3658: } else {
3659: my @curr = split(',',$userenv->{$context.'.'.$tool});
3660: my @new;
3661: my $changedoms;
1.314 raeburn 3662: foreach my $req (@curr) {
3663: if ($req =~ /^\Q$cdom\E\:($optregex\=?\d*)$/) {
3664: my $oldop = $1;
1.383 raeburn 3665: if ($oldop =~ /^autolimit=(\d*)/) {
3666: my $limit = $1;
3667: if ($limit) {
3668: $oldaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3669: } else {
3670: $oldaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3671: }
3672: } else {
3673: $oldaccesstext->{$tool} = $reqdisplay{$oldop};
3674: }
1.314 raeburn 3675: if ($oldop ne $newop) {
3676: $changedoms = 1;
3677: foreach my $item (@curr) {
3678: my ($reqdom,$option) = split(':',$item);
3679: unless ($reqdom eq $cdom) {
3680: push(@new,$item);
3681: }
3682: }
3683: if ($newop) {
3684: push(@new,$cdom.':'.$newop);
1.300 raeburn 3685: }
1.314 raeburn 3686: @new = sort(@new);
1.300 raeburn 3687: }
1.314 raeburn 3688: last;
1.300 raeburn 3689: }
1.314 raeburn 3690: }
3691: if ((!$changedoms) && ($newop)) {
1.300 raeburn 3692: $changedoms = 1;
1.306 raeburn 3693: @new = sort(@curr,$cdom.':'.$newop);
1.300 raeburn 3694: }
3695: if ($changedoms) {
1.314 raeburn 3696: my $newdomstr;
1.300 raeburn 3697: if (@new) {
3698: $newdomstr = join(',',@new);
3699: }
3700: $changed->{$tool}=&tool_admin($tool,$newdomstr,$changeHash,
3701: $context);
3702: if ($changed->{$tool}) {
3703: if ($env{'form.'.$context.'_'.$tool}) {
1.306 raeburn 3704: if ($env{'form.'.$context.'_'.$tool} eq 'autolimit') {
1.314 raeburn 3705: my $limit = $env{'form.'.$context.'_'.$tool.'_limit'};
3706: $limit =~ s/\D+//g;
3707: if ($limit) {
1.383 raeburn 3708: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
1.314 raeburn 3709: } else {
1.383 raeburn 3710: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
1.306 raeburn 3711: }
1.314 raeburn 3712: } else {
1.306 raeburn 3713: $newaccesstext->{$tool} = $reqdisplay{$env{'form.'.$context.'_'.$tool}};
3714: }
1.300 raeburn 3715: } else {
1.383 raeburn 3716: $newaccesstext->{$tool} = &mt("availability set to 'off'");
1.300 raeburn 3717: }
3718: }
3719: }
3720: }
3721: }
3722: return;
3723: }
1.275 raeburn 3724: foreach my $tool (@{$usertools}) {
1.383 raeburn 3725: my ($newval,$limit,$envkey);
1.362 raeburn 3726: $envkey = $context.'.'.$tool;
1.306 raeburn 3727: if ($context eq 'requestcourses') {
3728: $newval = $env{'form.crsreq_'.$tool};
3729: if ($newval eq 'autolimit') {
1.383 raeburn 3730: $limit = $env{'form.crsreq_'.$tool.'_limit'};
3731: $limit =~ s/\D+//g;
3732: $newval .= '='.$limit;
1.306 raeburn 3733: }
1.362 raeburn 3734: } elsif ($context eq 'requestauthor') {
3735: $newval = $env{'form.'.$context};
3736: $envkey = $context;
1.314 raeburn 3737: } else {
1.306 raeburn 3738: $newval = $env{'form.'.$context.'_'.$tool};
3739: }
1.362 raeburn 3740: if ($userenv->{$envkey} ne '') {
1.275 raeburn 3741: $oldaccess->{$tool} = &mt('custom');
1.383 raeburn 3742: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3743: if ($userenv->{$envkey} =~ /^autolimit=(\d*)$/) {
3744: my $currlimit = $1;
3745: if ($currlimit eq '') {
3746: $oldaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3747: } else {
3748: $oldaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$currlimit);
3749: }
3750: } elsif ($userenv->{$envkey}) {
3751: $oldaccesstext->{$tool} = $reqdisplay{$userenv->{$envkey}};
3752: } else {
3753: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
3754: }
1.275 raeburn 3755: } else {
1.383 raeburn 3756: if ($userenv->{$envkey}) {
3757: $oldaccesstext->{$tool} = &mt("availability set to 'on'");
3758: } else {
3759: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
3760: }
1.275 raeburn 3761: }
1.362 raeburn 3762: $changeHash->{$envkey} = $userenv->{$envkey};
1.275 raeburn 3763: if ($env{'form.custom'.$tool} == 1) {
1.362 raeburn 3764: if ($newval ne $userenv->{$envkey}) {
1.306 raeburn 3765: $changed->{$tool} = &tool_admin($tool,$newval,$changeHash,
3766: $context);
1.275 raeburn 3767: if ($changed->{$tool}) {
3768: $newaccess->{$tool} = &mt('custom');
1.383 raeburn 3769: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3770: if ($newval =~ /^autolimit/) {
3771: if ($limit) {
3772: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3773: } else {
3774: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3775: }
3776: } elsif ($newval) {
3777: $newaccesstext->{$tool} = $reqdisplay{$newval};
3778: } else {
3779: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3780: }
1.275 raeburn 3781: } else {
1.383 raeburn 3782: if ($newval) {
3783: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3784: } else {
3785: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3786: }
1.275 raeburn 3787: }
3788: } else {
3789: $newaccess->{$tool} = $oldaccess->{$tool};
1.383 raeburn 3790: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3791: if ($newval =~ /^autolimit/) {
3792: if ($limit) {
3793: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3794: } else {
3795: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3796: }
3797: } elsif ($newval) {
3798: $newaccesstext->{$tool} = $reqdisplay{$newval};
3799: } else {
3800: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3801: }
1.275 raeburn 3802: } else {
1.383 raeburn 3803: if ($userenv->{$context.'.'.$tool}) {
3804: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3805: } else {
3806: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3807: }
1.275 raeburn 3808: }
3809: }
3810: } else {
3811: $newaccess->{$tool} = $oldaccess->{$tool};
3812: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
3813: }
3814: } else {
3815: $changed->{$tool} = &tool_admin($tool,'',$changeHash,$context);
3816: if ($changed->{$tool}) {
3817: $newaccess->{$tool} = &mt('default');
3818: } else {
3819: $newaccess->{$tool} = $oldaccess->{$tool};
1.383 raeburn 3820: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3821: if ($newval =~ /^autolimit/) {
3822: if ($limit) {
3823: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3824: } else {
3825: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3826: }
3827: } elsif ($newval) {
3828: $newaccesstext->{$tool} = $reqdisplay{$newval};
3829: } else {
3830: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3831: }
1.275 raeburn 3832: } else {
1.383 raeburn 3833: if ($userenv->{$context.'.'.$tool}) {
3834: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3835: } else {
3836: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3837: }
1.275 raeburn 3838: }
3839: }
3840: }
3841: } else {
3842: $oldaccess->{$tool} = &mt('default');
3843: if ($env{'form.custom'.$tool} == 1) {
1.306 raeburn 3844: $changed->{$tool} = &tool_admin($tool,$newval,$changeHash,
3845: $context);
1.275 raeburn 3846: if ($changed->{$tool}) {
3847: $newaccess->{$tool} = &mt('custom');
1.383 raeburn 3848: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3849: if ($newval =~ /^autolimit/) {
3850: if ($limit) {
3851: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3852: } else {
3853: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3854: }
3855: } elsif ($newval) {
3856: $newaccesstext->{$tool} = $reqdisplay{$newval};
3857: } else {
3858: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3859: }
1.275 raeburn 3860: } else {
1.383 raeburn 3861: if ($newval) {
3862: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3863: } else {
3864: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3865: }
1.275 raeburn 3866: }
3867: } else {
3868: $newaccess->{$tool} = $oldaccess->{$tool};
3869: }
3870: } else {
3871: $newaccess->{$tool} = $oldaccess->{$tool};
3872: }
3873: }
3874: }
3875: return;
3876: }
3877:
1.220 raeburn 3878: sub update_roles {
1.375 raeburn 3879: my ($r,$context,$showcredits) = @_;
1.4 www 3880: my $now=time;
1.225 raeburn 3881: my @rolechanges;
1.220 raeburn 3882: my %disallowed;
1.73 sakharuk 3883: $r->print('<h3>'.&mt('Modifying Roles').'</h3>');
1.404 raeburn 3884: foreach my $key (keys(%env)) {
1.135 raeburn 3885: next if (! $env{$key});
1.190 raeburn 3886: next if ($key eq 'form.action');
1.27 matthew 3887: # Revoke roles
1.135 raeburn 3888: if ($key=~/^form\.rev/) {
3889: if ($key=~/^form\.rev\:([^\_]+)\_([^\_\.]+)$/) {
1.64 www 3890: # Revoke standard role
1.170 albertel 3891: my ($scope,$role) = ($1,$2);
3892: my $result =
3893: &Apache::lonnet::revokerole($env{'form.ccdomain'},
3894: $env{'form.ccuname'},
1.239 raeburn 3895: $scope,$role,'','',$context);
1.367 golterma 3896: $r->print(&Apache::lonhtmlcommon::confirm_success(
1.369 bisitz 3897: &mt('Revoking [_1] in [_2]',
3898: &Apache::lonnet::plaintext($role),
1.372 raeburn 3899: &Apache::loncommon::show_role_extent($scope,$context,$role)),
1.369 bisitz 3900: $result ne "ok").'<br />');
3901: if ($result ne "ok") {
3902: $r->print(&mt('Error: [_1]',$result).'<br />');
3903: }
1.170 albertel 3904: if ($role eq 'st') {
1.202 raeburn 3905: my $result =
1.198 raeburn 3906: &Apache::lonuserutils::classlist_drop($scope,
3907: $env{'form.ccuname'},$env{'form.ccdomain'},
1.202 raeburn 3908: $now);
1.367 golterma 3909: $r->print(&Apache::lonhtmlcommon::confirm_success($result));
1.53 www 3910: }
1.225 raeburn 3911: if (!grep(/^\Q$role\E$/,@rolechanges)) {
3912: push(@rolechanges,$role);
3913: }
1.196 raeburn 3914: }
1.195 raeburn 3915: if ($key=~m{^form\.rev\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}s) {
1.64 www 3916: # Revoke custom role
1.369 bisitz 3917: my $result = &Apache::lonnet::revokecustomrole(
3918: $env{'form.ccdomain'},$env{'form.ccuname'},$1,$2,$3,$4,'','',$context);
1.367 golterma 3919: $r->print(&Apache::lonhtmlcommon::confirm_success(
1.369 bisitz 3920: &mt('Revoking custom role [_1] by [_2] in [_3]',
1.372 raeburn 3921: $4,$3.':'.$2,&Apache::loncommon::show_role_extent($1,$context,'cr')),
1.369 bisitz 3922: $result ne 'ok').'<br />');
3923: if ($result ne "ok") {
3924: $r->print(&mt('Error: [_1]',$result).'<br />');
3925: }
1.225 raeburn 3926: if (!grep(/^cr$/,@rolechanges)) {
3927: push(@rolechanges,'cr');
3928: }
1.64 www 3929: }
1.135 raeburn 3930: } elsif ($key=~/^form\.del/) {
3931: if ($key=~/^form\.del\:([^\_]+)\_([^\_\.]+)$/) {
1.116 raeburn 3932: # Delete standard role
1.170 albertel 3933: my ($scope,$role) = ($1,$2);
3934: my $result =
3935: &Apache::lonnet::assignrole($env{'form.ccdomain'},
3936: $env{'form.ccuname'},
1.239 raeburn 3937: $scope,$role,$now,0,1,'',
3938: $context);
1.367 golterma 3939: $r->print(&Apache::lonhtmlcommon::confirm_success(
3940: &mt('Deleting [_1] in [_2]',
1.369 bisitz 3941: &Apache::lonnet::plaintext($role),
1.372 raeburn 3942: &Apache::loncommon::show_role_extent($scope,$context,$role)),
1.369 bisitz 3943: $result ne 'ok').'<br />');
3944: if ($result ne "ok") {
3945: $r->print(&mt('Error: [_1]',$result).'<br />');
3946: }
1.367 golterma 3947:
1.170 albertel 3948: if ($role eq 'st') {
1.202 raeburn 3949: my $result =
1.198 raeburn 3950: &Apache::lonuserutils::classlist_drop($scope,
3951: $env{'form.ccuname'},$env{'form.ccdomain'},
1.202 raeburn 3952: $now);
1.369 bisitz 3953: $r->print(&Apache::lonhtmlcommon::confirm_success($result));
1.81 albertel 3954: }
1.225 raeburn 3955: if (!grep(/^\Q$role\E$/,@rolechanges)) {
3956: push(@rolechanges,$role);
3957: }
1.116 raeburn 3958: }
1.139 albertel 3959: if ($key=~m{^form\.del\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
1.116 raeburn 3960: my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
3961: # Delete custom role
1.369 bisitz 3962: my $result =
3963: &Apache::lonnet::assigncustomrole($env{'form.ccdomain'},
3964: $env{'form.ccuname'},$url,$rdom,$rnam,$rolename,$now,
3965: 0,1,$context);
3966: $r->print(&Apache::lonhtmlcommon::confirm_success(&mt('Deleting custom role [_1] by [_2] in [_3]',
1.372 raeburn 3967: $rolename,$rnam.':'.$rdom,&Apache::loncommon::show_role_extent($1,$context,'cr')),
1.369 bisitz 3968: $result ne "ok").'<br />');
3969: if ($result ne "ok") {
3970: $r->print(&mt('Error: [_1]',$result).'<br />');
3971: }
1.367 golterma 3972:
1.225 raeburn 3973: if (!grep(/^cr$/,@rolechanges)) {
3974: push(@rolechanges,'cr');
3975: }
1.116 raeburn 3976: }
1.135 raeburn 3977: } elsif ($key=~/^form\.ren/) {
1.101 albertel 3978: my $udom = $env{'form.ccdomain'};
3979: my $uname = $env{'form.ccuname'};
1.116 raeburn 3980: # Re-enable standard role
1.135 raeburn 3981: if ($key=~/^form\.ren\:([^\_]+)\_([^\_\.]+)$/) {
1.89 raeburn 3982: my $url = $1;
3983: my $role = $2;
3984: my $logmsg;
3985: my $output;
3986: if ($role eq 'st') {
1.141 albertel 3987: if ($url =~ m-^/($match_domain)/($match_courseid)/?(\w*)$-) {
1.374 raeburn 3988: my ($cdom,$cnum,$csec) = ($1,$2,$3);
1.375 raeburn 3989: my $credits;
3990: if ($showcredits) {
3991: my $defaultcredits =
3992: &Apache::lonuserutils::get_defaultcredits($cdom,$cnum);
3993: $credits = &get_user_credits($defaultcredits,$cdom,$cnum);
3994: }
3995: my $result = &Apache::loncommon::commit_studentrole(\$logmsg,$udom,$uname,$url,$role,$now,0,$cdom,$cnum,$csec,$context,$credits);
1.220 raeburn 3996: if (($result =~ /^error/) || ($result eq 'not_in_class') || ($result eq 'unknown_course') || ($result eq 'refused')) {
1.223 raeburn 3997: if ($result eq 'refused' && $logmsg) {
3998: $output = $logmsg;
3999: } else {
1.369 bisitz 4000: $output = &mt('Error: [_1]',$result)."\n";
1.223 raeburn 4001: }
1.89 raeburn 4002: } else {
1.372 raeburn 4003: $output = &Apache::lonhtmlcommon::confirm_success(&mt('Assigning [_1] in [_2] starting [_3]',
4004: &Apache::lonnet::plaintext($role),
4005: &Apache::loncommon::show_role_extent($url,$context,'st'),
4006: &Apache::lonlocal::locallocaltime($now))).'<br />'.$logmsg.'<br />';
1.89 raeburn 4007: }
4008: }
4009: } else {
1.101 albertel 4010: my $result=&Apache::lonnet::assignrole($env{'form.ccdomain'},
1.239 raeburn 4011: $env{'form.ccuname'},$url,$role,0,$now,'','',
4012: $context);
1.367 golterma 4013: $output = &Apache::lonhtmlcommon::confirm_success(&mt('Re-enabling [_1] in [_2]',
1.372 raeburn 4014: &Apache::lonnet::plaintext($role),
4015: &Apache::loncommon::show_role_extent($url,$context,$role)),$result ne "ok").'<br />';
1.369 bisitz 4016: if ($result ne "ok") {
4017: $output .= &mt('Error: [_1]',$result).'<br />';
4018: }
4019: }
1.89 raeburn 4020: $r->print($output);
1.225 raeburn 4021: if (!grep(/^\Q$role\E$/,@rolechanges)) {
4022: push(@rolechanges,$role);
4023: }
1.113 raeburn 4024: }
1.116 raeburn 4025: # Re-enable custom role
1.139 albertel 4026: if ($key=~m{^form\.ren\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
1.116 raeburn 4027: my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
4028: my $result = &Apache::lonnet::assigncustomrole(
4029: $env{'form.ccdomain'}, $env{'form.ccuname'},
1.240 raeburn 4030: $url,$rdom,$rnam,$rolename,0,$now,undef,$context);
1.369 bisitz 4031: $r->print(&Apache::lonhtmlcommon::confirm_success(
4032: &mt('Re-enabling custom role [_1] by [_2] in [_3]',
1.372 raeburn 4033: $rolename,$rnam.':'.$rdom,&Apache::loncommon::show_role_extent($1,$context,'cr')),
1.369 bisitz 4034: $result ne "ok").'<br />');
4035: if ($result ne "ok") {
4036: $r->print(&mt('Error: [_1]',$result).'<br />');
4037: }
1.225 raeburn 4038: if (!grep(/^cr$/,@rolechanges)) {
4039: push(@rolechanges,'cr');
4040: }
1.116 raeburn 4041: }
1.135 raeburn 4042: } elsif ($key=~/^form\.act/) {
1.101 albertel 4043: my $udom = $env{'form.ccdomain'};
4044: my $uname = $env{'form.ccuname'};
1.141 albertel 4045: if ($key=~/^form\.act\_($match_domain)\_($match_courseid)\_cr_cr_($match_domain)_($match_username)_([^\_]+)$/) {
1.65 www 4046: # Activate a custom role
1.83 albertel 4047: my ($one,$two,$three,$four,$five)=($1,$2,$3,$4,$5);
4048: my $url='/'.$one.'/'.$two;
4049: my $full=$one.'_'.$two.'_cr_cr_'.$three.'_'.$four.'_'.$five;
1.65 www 4050:
1.101 albertel 4051: my $start = ( $env{'form.start_'.$full} ?
4052: $env{'form.start_'.$full} :
1.88 raeburn 4053: $now );
1.101 albertel 4054: my $end = ( $env{'form.end_'.$full} ?
4055: $env{'form.end_'.$full} :
1.88 raeburn 4056: 0 );
4057:
4058: # split multiple sections
4059: my %sections = ();
1.101 albertel 4060: my $num_sections = &build_roles($env{'form.sec_'.$full},\%sections,$5);
1.88 raeburn 4061: if ($num_sections == 0) {
1.240 raeburn 4062: $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$url,$three,$four,$five,$start,$end,$context));
1.88 raeburn 4063: } else {
1.114 albertel 4064: my %curr_groups =
1.117 raeburn 4065: &Apache::longroup::coursegroups($one,$two);
1.404 raeburn 4066: foreach my $sec (sort {$a cmp $b} keys(%sections)) {
1.113 raeburn 4067: if (($sec eq 'none') || ($sec eq 'all') ||
4068: exists($curr_groups{$sec})) {
4069: $disallowed{$sec} = $url;
4070: next;
4071: }
4072: my $securl = $url.'/'.$sec;
1.240 raeburn 4073: $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$securl,$three,$four,$five,$start,$end,$context));
1.88 raeburn 4074: }
4075: }
1.225 raeburn 4076: if (!grep(/^cr$/,@rolechanges)) {
4077: push(@rolechanges,'cr');
4078: }
1.142 raeburn 4079: } elsif ($key=~/^form\.act\_($match_domain)\_($match_name)\_([^\_]+)$/) {
1.27 matthew 4080: # Activate roles for sections with 3 id numbers
4081: # set start, end times, and the url for the class
1.83 albertel 4082: my ($one,$two,$three)=($1,$2,$3);
1.101 albertel 4083: my $start = ( $env{'form.start_'.$one.'_'.$two.'_'.$three} ?
4084: $env{'form.start_'.$one.'_'.$two.'_'.$three} :
1.27 matthew 4085: $now );
1.101 albertel 4086: my $end = ( $env{'form.end_'.$one.'_'.$two.'_'.$three} ?
4087: $env{'form.end_'.$one.'_'.$two.'_'.$three} :
1.27 matthew 4088: 0 );
1.83 albertel 4089: my $url='/'.$one.'/'.$two;
1.88 raeburn 4090: my $type = 'three';
4091: # split multiple sections
4092: my %sections = ();
1.101 albertel 4093: my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two.'_'.$three},\%sections,$three);
1.375 raeburn 4094: my $credits;
4095: if ($three eq 'st') {
4096: if ($showcredits) {
4097: my $defaultcredits =
4098: &Apache::lonuserutils::get_defaultcredits($one,$two);
4099: $credits = $env{'form.credits_'.$one.'_'.$two.'_'.$three};
4100: $credits =~ s/[^\d\.]//g;
4101: if ($credits eq $defaultcredits) {
4102: undef($credits);
4103: }
4104: }
4105: }
1.88 raeburn 4106: if ($num_sections == 0) {
1.375 raeburn 4107: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'',$context,$credits));
1.88 raeburn 4108: } else {
1.114 albertel 4109: my %curr_groups =
1.117 raeburn 4110: &Apache::longroup::coursegroups($one,$two);
1.88 raeburn 4111: my $emptysec = 0;
1.404 raeburn 4112: foreach my $sec (sort {$a cmp $b} keys(%sections)) {
1.88 raeburn 4113: $sec =~ s/\W//g;
1.113 raeburn 4114: if ($sec ne '') {
4115: if (($sec eq 'none') || ($sec eq 'all') ||
4116: exists($curr_groups{$sec})) {
4117: $disallowed{$sec} = $url;
4118: next;
4119: }
1.88 raeburn 4120: my $securl = $url.'/'.$sec;
1.375 raeburn 4121: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$three,$start,$end,$one,$two,$sec,$context,$credits));
1.88 raeburn 4122: } else {
4123: $emptysec = 1;
4124: }
4125: }
4126: if ($emptysec) {
1.375 raeburn 4127: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'',$context,$credits));
1.88 raeburn 4128: }
1.225 raeburn 4129: }
4130: if (!grep(/^\Q$three\E$/,@rolechanges)) {
4131: push(@rolechanges,$three);
4132: }
1.135 raeburn 4133: } elsif ($key=~/^form\.act\_([^\_]+)\_([^\_]+)$/) {
1.27 matthew 4134: # Activate roles for sections with two id numbers
4135: # set start, end times, and the url for the class
1.101 albertel 4136: my $start = ( $env{'form.start_'.$1.'_'.$2} ?
4137: $env{'form.start_'.$1.'_'.$2} :
1.27 matthew 4138: $now );
1.101 albertel 4139: my $end = ( $env{'form.end_'.$1.'_'.$2} ?
4140: $env{'form.end_'.$1.'_'.$2} :
1.27 matthew 4141: 0 );
1.225 raeburn 4142: my $one = $1;
4143: my $two = $2;
4144: my $url='/'.$one.'/';
1.88 raeburn 4145: # split multiple sections
4146: my %sections = ();
1.225 raeburn 4147: my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two},\%sections,$two);
1.88 raeburn 4148: if ($num_sections == 0) {
1.240 raeburn 4149: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,'',$context));
1.88 raeburn 4150: } else {
4151: my $emptysec = 0;
1.404 raeburn 4152: foreach my $sec (sort {$a cmp $b} keys(%sections)) {
1.88 raeburn 4153: if ($sec ne '') {
4154: my $securl = $url.'/'.$sec;
1.240 raeburn 4155: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$two,$start,$end,$one,undef,$sec,$context));
1.88 raeburn 4156: } else {
4157: $emptysec = 1;
4158: }
4159: }
4160: if ($emptysec) {
1.240 raeburn 4161: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,'',$context));
1.88 raeburn 4162: }
4163: }
1.225 raeburn 4164: if (!grep(/^\Q$two\E$/,@rolechanges)) {
4165: push(@rolechanges,$two);
4166: }
1.64 www 4167: } else {
1.190 raeburn 4168: $r->print('<p><span class="LC_error">'.&mt('ERROR').': '.&mt('Unknown command').' <tt>'.$key.'</tt></span></p><br />');
1.64 www 4169: }
1.113 raeburn 4170: foreach my $key (sort(keys(%disallowed))) {
1.274 bisitz 4171: $r->print('<p class="LC_warning">');
1.113 raeburn 4172: if (($key eq 'none') || ($key eq 'all')) {
1.274 bisitz 4173: $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 4174: } else {
1.274 bisitz 4175: $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 4176: }
1.274 bisitz 4177: $r->print('</p><p>'
4178: .&mt('Please [_1]go back[_2] and choose a different section name.'
4179: ,'<a href="javascript:history.go(-1)'
4180: ,'</a>')
4181: .'</p><br />'
4182: );
1.113 raeburn 4183: }
4184: }
1.101 albertel 4185: } # End of foreach (keys(%env))
1.75 www 4186: # Flush the course logs so reverse user roles immediately updated
1.349 raeburn 4187: $r->register_cleanup(\&Apache::lonnet::flushcourselogs);
1.225 raeburn 4188: if (@rolechanges == 0) {
1.372 raeburn 4189: $r->print('<p>'.&mt('No roles to modify').'</p>');
1.193 raeburn 4190: }
1.225 raeburn 4191: return @rolechanges;
1.220 raeburn 4192: }
4193:
1.375 raeburn 4194: sub get_user_credits {
4195: my ($uname,$udom,$defaultcredits,$cdom,$cnum) = @_;
4196: if ($cdom eq '' || $cnum eq '') {
4197: return unless ($env{'request.course.id'});
4198: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
4199: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
4200: }
4201: my $credits;
4202: my %currhash =
4203: &Apache::lonnet::get('classlist',[$uname.':'.$udom],$cdom,$cnum);
4204: if (keys(%currhash) > 0) {
4205: my @items = split(/:/,$currhash{$uname.':'.$udom});
4206: my $crdidx = &Apache::loncoursedata::CL_CREDITS() - 3;
4207: $credits = $items[$crdidx];
4208: $credits =~ s/[^\d\.]//g;
4209: }
4210: if ($credits eq $defaultcredits) {
4211: undef($credits);
4212: }
4213: return $credits;
4214: }
4215:
1.220 raeburn 4216: sub enroll_single_student {
1.375 raeburn 4217: my ($r,$uhome,$amode,$genpwd,$now,$newuser,$context,$crstype,
4218: $showcredits,$defaultcredits) = @_;
1.318 raeburn 4219: $r->print('<h3>');
4220: if ($crstype eq 'Community') {
4221: $r->print(&mt('Enrolling Member'));
4222: } else {
4223: $r->print(&mt('Enrolling Student'));
4224: }
4225: $r->print('</h3>');
1.220 raeburn 4226:
4227: # Remove non alphanumeric values from section
4228: $env{'form.sections'}=~s/\W//g;
4229:
1.375 raeburn 4230: my $credits;
4231: if (($showcredits) && ($env{'form.credits'} ne '')) {
4232: $credits = $env{'form.credits'};
4233: $credits =~ s/[^\d\.]//g;
4234: if ($credits ne '') {
4235: if ($credits eq $defaultcredits) {
4236: undef($credits);
4237: }
4238: }
4239: }
4240:
1.220 raeburn 4241: # Clean out any old student roles the user has in this class.
4242: &Apache::lonuserutils::modifystudent($env{'form.ccdomain'},
4243: $env{'form.ccuname'},$env{'request.course.id'},undef,$uhome);
4244: my ($startdate,$enddate) = &Apache::lonuserutils::get_dates_from_form();
4245: my $enroll_result =
4246: &Apache::lonnet::modify_student_enrollment($env{'form.ccdomain'},
4247: $env{'form.ccuname'},$env{'form.cid'},$env{'form.cfirstname'},
4248: $env{'form.cmiddlename'},$env{'form.clastname'},
4249: $env{'form.generation'},$env{'form.sections'},$enddate,
1.375 raeburn 4250: $startdate,'manual',undef,$env{'request.course.id'},'',$context,
4251: $credits);
1.220 raeburn 4252: if ($enroll_result =~ /^ok/) {
1.381 bisitz 4253: $r->print(&mt('[_1] enrolled','<b>'.$env{'form.ccuname'}.':'.$env{'form.ccdomain'}.'</b>'));
1.220 raeburn 4254: if ($env{'form.sections'} ne '') {
4255: $r->print(' '.&mt('in section [_1]',$env{'form.sections'}));
4256: }
4257: my ($showstart,$showend);
4258: if ($startdate <= $now) {
4259: $showstart = &mt('Access starts immediately');
4260: } else {
4261: $showstart = &mt('Access starts: ').&Apache::lonlocal::locallocaltime($startdate);
4262: }
4263: if ($enddate == 0) {
4264: $showend = &mt('ends: no ending date');
4265: } else {
4266: $showend = &mt('ends: ').&Apache::lonlocal::locallocaltime($enddate);
4267: }
4268: $r->print('.<br />'.$showstart.'; '.$showend);
4269: if ($startdate <= $now && !$newuser) {
1.386 bisitz 4270: $r->print('<p class="LC_info">');
1.318 raeburn 4271: if ($crstype eq 'Community') {
1.392 raeburn 4272: $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 4273: } else {
1.392 raeburn 4274: $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 4275: }
4276: $r->print('</p>');
1.220 raeburn 4277: }
4278: } else {
4279: $r->print(&mt('unable to enroll').": ".$enroll_result);
4280: }
4281: return;
1.188 raeburn 4282: }
4283:
1.204 raeburn 4284: sub get_defaultquota_text {
4285: my ($settingstatus) = @_;
4286: my $defquotatext;
4287: if ($settingstatus eq '') {
1.383 raeburn 4288: $defquotatext = &mt('default');
1.204 raeburn 4289: } else {
4290: my ($usertypes,$order) =
4291: &Apache::lonnet::retrieve_inst_usertypes($env{'form.ccdomain'});
4292: if ($usertypes->{$settingstatus} eq '') {
1.383 raeburn 4293: $defquotatext = &mt('default');
1.204 raeburn 4294: } else {
1.383 raeburn 4295: $defquotatext = &mt('default for [_1]',$usertypes->{$settingstatus});
1.204 raeburn 4296: }
4297: }
4298: return $defquotatext;
4299: }
4300:
1.188 raeburn 4301: sub update_result_form {
4302: my ($uhome) = @_;
4303: my $outcome =
1.367 golterma 4304: '<form name="userupdate" method="post" action="">'."\n";
1.160 raeburn 4305: foreach my $item ('srchby','srchin','srchtype','srchterm','srchdomain','ccuname','ccdomain') {
1.188 raeburn 4306: $outcome .= '<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n";
1.160 raeburn 4307: }
1.207 raeburn 4308: if ($env{'form.origname'} ne '') {
4309: $outcome .= '<input type="hidden" name="origname" value="'.$env{'form.origname'}.'" />'."\n";
4310: }
1.160 raeburn 4311: foreach my $item ('sortby','seluname','seludom') {
4312: if (exists($env{'form.'.$item})) {
1.188 raeburn 4313: $outcome .= '<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n";
1.160 raeburn 4314: }
4315: }
1.188 raeburn 4316: if ($uhome eq 'no_host') {
4317: $outcome .= '<input type="hidden" name="forcenewuser" value="1" />'."\n";
4318: }
4319: $outcome .= '<input type="hidden" name="phase" value="" />'."\n".
1.383 raeburn 4320: '<input type="hidden" name="currstate" value="" />'."\n".
4321: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n".
1.188 raeburn 4322: '</form>';
4323: return $outcome;
1.4 www 4324: }
4325:
1.149 raeburn 4326: sub quota_admin {
1.378 raeburn 4327: my ($setquota,$changeHash,$name) = @_;
1.149 raeburn 4328: my $quotachanged;
4329: if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
4330: # Current user has quota modification privileges
1.267 raeburn 4331: if (ref($changeHash) eq 'HASH') {
4332: $quotachanged = 1;
1.378 raeburn 4333: $changeHash->{$name.'quota'} = $setquota;
1.267 raeburn 4334: }
1.149 raeburn 4335: }
4336: return $quotachanged;
4337: }
4338:
1.267 raeburn 4339: sub tool_admin {
1.275 raeburn 4340: my ($tool,$settool,$changeHash,$context) = @_;
4341: my $canchange = 0;
1.279 raeburn 4342: if ($context eq 'requestcourses') {
1.275 raeburn 4343: if (&Apache::lonnet::allowed('ccc',$env{'form.ccdomain'})) {
4344: $canchange = 1;
4345: }
1.300 raeburn 4346: } elsif ($context eq 'reqcrsotherdom') {
4347: if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
4348: $canchange = 1;
4349: }
1.362 raeburn 4350: } elsif ($context eq 'requestauthor') {
4351: if (&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) {
4352: $canchange = 1;
4353: }
1.275 raeburn 4354: } elsif (&Apache::lonnet::allowed('mut',$env{'form.ccdomain'})) {
4355: # Current user has quota modification privileges
4356: $canchange = 1;
4357: }
1.267 raeburn 4358: my $toolchanged;
1.275 raeburn 4359: if ($canchange) {
1.267 raeburn 4360: if (ref($changeHash) eq 'HASH') {
4361: $toolchanged = 1;
1.362 raeburn 4362: if ($tool eq 'requestauthor') {
4363: $changeHash->{$context} = $settool;
4364: } else {
4365: $changeHash->{$context.'.'.$tool} = $settool;
4366: }
1.267 raeburn 4367: }
4368: }
4369: return $toolchanged;
4370: }
4371:
1.88 raeburn 4372: sub build_roles {
1.89 raeburn 4373: my ($sectionstr,$sections,$role) = @_;
1.88 raeburn 4374: my $num_sections = 0;
4375: if ($sectionstr=~ /,/) {
4376: my @secnums = split/,/,$sectionstr;
1.89 raeburn 4377: if ($role eq 'st') {
4378: $secnums[0] =~ s/\W//g;
4379: $$sections{$secnums[0]} = 1;
4380: $num_sections = 1;
4381: } else {
4382: foreach my $sec (@secnums) {
4383: $sec =~ ~s/\W//g;
1.150 banghart 4384: if (!($sec eq "")) {
1.89 raeburn 4385: if (exists($$sections{$sec})) {
4386: $$sections{$sec} ++;
4387: } else {
4388: $$sections{$sec} = 1;
4389: $num_sections ++;
4390: }
1.88 raeburn 4391: }
4392: }
4393: }
4394: } else {
4395: $sectionstr=~s/\W//g;
4396: unless ($sectionstr eq '') {
4397: $$sections{$sectionstr} = 1;
4398: $num_sections ++;
4399: }
4400: }
1.129 albertel 4401:
1.88 raeburn 4402: return $num_sections;
4403: }
4404:
1.58 www 4405: # ========================================================== Custom Role Editor
4406:
4407: sub custom_role_editor {
1.439 raeburn 4408: my ($r,$context,$brcrum,$prefix,$permission) = @_;
1.324 raeburn 4409: my $action = $env{'form.customroleaction'};
1.439 raeburn 4410: my ($rolename,$helpitem);
1.324 raeburn 4411: if ($action eq 'new') {
4412: $rolename=$env{'form.newrolename'};
4413: } else {
4414: $rolename=$env{'form.rolename'};
1.59 www 4415: }
4416:
1.324 raeburn 4417: my ($crstype,$context);
4418: if ($env{'request.course.id'}) {
4419: $crstype = &Apache::loncommon::course_type();
4420: $context = 'course';
1.439 raeburn 4421: $helpitem = 'Course_Editing_Custom_Roles';
1.324 raeburn 4422: } else {
4423: $context = 'domain';
1.414 raeburn 4424: $crstype = 'course';
1.439 raeburn 4425: $helpitem = 'Domain_Editing_Custom_Roles';
1.324 raeburn 4426: }
1.351 raeburn 4427:
4428: $rolename=~s/[^A-Za-z0-9]//gs;
4429: if (!$rolename || $env{'form.phase'} eq 'pickrole') {
1.439 raeburn 4430: &print_username_entry_form($r,$context,undef,undef,undef,$crstype,$brcrum,
4431: $permission);
1.351 raeburn 4432: return;
4433: }
4434:
1.414 raeburn 4435: my $formname = 'form1';
4436: my %privs=();
4437: my $body_top = '<h2>';
4438: # ------------------------------------------------------- Does this role exist?
1.59 www 4439: my ($rdummy,$roledef)=
4440: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
4441: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1.414 raeburn 4442: $body_top .= &mt('Existing Role').' "';
1.61 www 4443: # ------------------------------------------------- Get current role privileges
1.414 raeburn 4444: ($privs{'system'},$privs{'domain'},$privs{'course'})=split(/\_/,$roledef);
4445: if ($privs{'system'} =~ /bre\&S/) {
4446: if ($context eq 'domain') {
1.417 raeburn 4447: $crstype = 'Course';
1.414 raeburn 4448: } elsif ($crstype eq 'Community') {
4449: $privs{'system'} =~ s/bre\&S//;
4450: }
4451: } elsif ($context eq 'domain') {
4452: $crstype = 'Course';
1.324 raeburn 4453: }
1.59 www 4454: } else {
1.414 raeburn 4455: $body_top .= &mt('New Role').' "';
4456: $roledef='';
1.59 www 4457: }
1.153 banghart 4458: $body_top .= $rolename.'"</h2>';
1.414 raeburn 4459:
4460: # ------------------------------------------------------- What can be assigned?
4461: my %full=();
1.417 raeburn 4462: my %levels=(
1.414 raeburn 4463: course => {},
4464: domain => {},
4465: system => {},
4466: );
4467: my %levelscurrent=(
4468: course => {},
4469: domain => {},
4470: system => {},
4471: );
4472: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
1.160 raeburn 4473: my ($jsback,$elements) = &crumb_utilities();
1.414 raeburn 4474: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
1.417 raeburn 4475: my $head_script =
1.414 raeburn 4476: &Apache::lonuserutils::custom_roledefs_js($context,$crstype,$formname,
4477: \%full,\@templateroles,$jsback);
1.351 raeburn 4478: push (@{$brcrum},
1.414 raeburn 4479: {href => "javascript:backPage(document.$formname,'pickrole','')",
1.351 raeburn 4480: text => "Pick custom role",
4481: faq => 282,bug=>'Instructor Interface',},
1.414 raeburn 4482: {href => "javascript:backPage(document.$formname,'','')",
1.351 raeburn 4483: text => "Edit custom role",
4484: faq => 282,
4485: bug => 'Instructor Interface',
1.439 raeburn 4486: help => $helpitem}
1.351 raeburn 4487: );
4488: my $args = { bread_crumbs => $brcrum,
4489: bread_crumbs_component => 'User Management'};
4490: $r->print(&Apache::loncommon::start_page('Custom Role Editor',
4491: $head_script,$args).
4492: $body_top);
1.414 raeburn 4493: $r->print('<form name="'.$formname.'" method="post" action="">'."\n".
4494: &Apache::lonuserutils::custom_role_header($context,$crstype,
4495: \@templateroles,$prefix));
1.264 bisitz 4496:
1.61 www 4497: $r->print(<<ENDCCF);
4498: <input type="hidden" name="phase" value="set_custom_roles" />
4499: <input type="hidden" name="rolename" value="$rolename" />
4500: ENDCCF
1.414 raeburn 4501: $r->print(&Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
4502: \%levelscurrent,$prefix));
1.135 raeburn 4503: $r->print(&Apache::loncommon::end_data_table().
1.190 raeburn 4504: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'.
1.160 raeburn 4505: '<input type="hidden" name="startrolename" value="'.$env{'form.rolename'}.
1.417 raeburn 4506: '" />'."\n".'<input type="hidden" name="currstate" value="" />'."\n".
1.160 raeburn 4507: '<input type="reset" value="'.&mt("Reset").'" />'."\n".
1.351 raeburn 4508: '<input type="submit" value="'.&mt('Save').'" /></form>');
1.61 www 4509: }
1.414 raeburn 4510:
1.61 www 4511: # ---------------------------------------------------------- Call to definerole
4512: sub set_custom_role {
1.439 raeburn 4513: my ($r,$context,$brcrum,$prefix,$permission) = @_;
1.101 albertel 4514: my $rolename=$env{'form.rolename'};
1.63 www 4515: $rolename=~s/[^A-Za-z0-9]//gs;
1.150 banghart 4516: if (!$rolename) {
1.439 raeburn 4517: &custom_role_editor($r,$context,$brcrum,$prefix,$permission);
1.61 www 4518: return;
4519: }
1.160 raeburn 4520: my ($jsback,$elements) = &crumb_utilities();
1.301 bisitz 4521: my $jscript = '<script type="text/javascript">'
4522: .'// <![CDATA['."\n"
4523: .$jsback."\n"
4524: .'// ]]>'."\n"
4525: .'</script>'."\n";
1.439 raeburn 4526: my $helpitem = 'Course_Editing_Custom_Roles';
4527: if ($context eq 'domain') {
4528: $helpitem = 'Domain_Editing_Custom_Roles';
4529: }
1.352 raeburn 4530: push(@{$brcrum},
4531: {href => "javascript:backPage(document.customresult,'pickrole','')",
4532: text => "Pick custom role",
4533: faq => 282,
4534: bug => 'Instructor Interface',},
4535: {href => "javascript:backPage(document.customresult,'selected_custom_edit','')",
4536: text => "Edit custom role",
4537: faq => 282,
4538: bug => 'Instructor Interface',},
4539: {href => "javascript:backPage(document.customresult,'set_custom_roles','')",
4540: text => "Result",
4541: faq => 282,
4542: bug => 'Instructor Interface',
1.439 raeburn 4543: help => $helpitem,}
1.352 raeburn 4544: );
4545: my $args = { bread_crumbs => $brcrum,
1.414 raeburn 4546: bread_crumbs_component => 'User Management'};
1.351 raeburn 4547: $r->print(&Apache::loncommon::start_page('Save Custom Role',$jscript,$args));
1.160 raeburn 4548:
1.393 raeburn 4549: my $newrole;
1.61 www 4550: my ($rdummy,$roledef)=
1.110 albertel 4551: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
4552:
1.61 www 4553: # ------------------------------------------------------- Does this role exist?
1.188 raeburn 4554: $r->print('<h3>');
1.61 www 4555: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1.73 sakharuk 4556: $r->print(&mt('Existing Role').' "');
1.61 www 4557: } else {
1.73 sakharuk 4558: $r->print(&mt('New Role').' "');
1.61 www 4559: $roledef='';
1.393 raeburn 4560: $newrole = 1;
1.61 www 4561: }
1.188 raeburn 4562: $r->print($rolename.'"</h3>');
1.414 raeburn 4563: # ------------------------------------------------- Assign role and show result
1.61 www 4564:
1.387 bisitz 4565: my $errmsg;
1.414 raeburn 4566: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$prefix);
4567: # Assign role and return result
4568: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
4569: $newprivs{'c'});
1.387 bisitz 4570: if ($result ne 'ok') {
4571: $errmsg = ': '.$result;
4572: }
4573: my $message =
4574: &Apache::lonhtmlcommon::confirm_success(
4575: &mt('Defining Role').$errmsg, ($result eq 'ok' ? 0 : 1));
1.101 albertel 4576: if ($env{'request.course.id'}) {
4577: my $url='/'.$env{'request.course.id'};
1.63 www 4578: $url=~s/\_/\//g;
1.387 bisitz 4579: $result =
4580: &Apache::lonnet::assigncustomrole(
4581: $env{'user.domain'},$env{'user.name'},
4582: $url,
4583: $env{'user.domain'},$env{'user.name'},
4584: $rolename,undef,undef,undef,$context);
4585: if ($result ne 'ok') {
4586: $errmsg = ': '.$result;
4587: }
4588: $message .=
4589: '<br />'
4590: .&Apache::lonhtmlcommon::confirm_success(
4591: &mt('Assigning Role to Self').$errmsg, ($result eq 'ok' ? 0 : 1));
1.63 www 4592: }
1.380 bisitz 4593: $r->print(
1.387 bisitz 4594: &Apache::loncommon::confirmwrapper($message)
4595: .'<br />'
4596: .&Apache::lonhtmlcommon::actionbox([
4597: '<a href="javascript:backPage(document.customresult,'."'pickrole'".')">'
4598: .&mt('Create or edit another custom role')
4599: .'</a>'])
1.380 bisitz 4600: .'<form name="customresult" method="post" action="">'
1.387 bisitz 4601: .&Apache::lonhtmlcommon::echo_form_input([])
4602: .'</form>'
1.380 bisitz 4603: );
1.58 www 4604: }
4605:
1.2 www 4606: # ================================================================ Main Handler
4607: sub handler {
4608: my $r = shift;
4609: if ($r->header_only) {
1.68 www 4610: &Apache::loncommon::content_type($r,'text/html');
1.2 www 4611: $r->send_http_header;
4612: return OK;
4613: }
1.439 raeburn 4614: my ($context,$crstype,$cid,$cnum,$cdom,$allhelpitems);
4615:
1.190 raeburn 4616: if ($env{'request.course.id'}) {
4617: $context = 'course';
1.318 raeburn 4618: $crstype = &Apache::loncommon::course_type();
1.190 raeburn 4619: } elsif ($env{'request.role'} =~ /^au\./) {
1.206 raeburn 4620: $context = 'author';
1.190 raeburn 4621: } else {
4622: $context = 'domain';
4623: }
1.375 raeburn 4624:
1.439 raeburn 4625: my ($permission,$allowed) =
4626: &Apache::lonuserutils::get_permission($context,$crstype);
4627:
4628: if ($allowed) {
4629: my @allhelp;
4630: if ($context eq 'course') {
4631: $cid = $env{'request.course.id'};
4632: $cdom = $env{'course.'.$cid.'.domain'};
4633: $cnum = $env{'course.'.$cid.'.num'};
4634:
4635: if ($permission->{'cusr'}) {
4636: push(@allhelp,'Course_Create_Class_List');
4637: }
4638: if ($permission->{'view'} || $permission->{'cusr'}) {
4639: push(@allhelp,('Course_Change_Privileges','Course_View_Class_List'));
4640: }
4641: if ($permission->{'custom'}) {
4642: push(@allhelp,'Course_Editing_Custom_Roles');
4643: }
4644: if ($permission->{'cusr'}) {
4645: push(@allhelp,('Course_Add_Student','Course_Drop_Student'));
4646: }
4647: unless ($permission->{'cusr_section'}) {
4648: if (&Apache::lonnet::auto_run($cnum,$cdom) && (($permission->{'cusr'}) || ($permission->{'view'}))) {
4649: push(@allhelp,'Course_Automated_Enrollment');
4650: }
4651: if ($permission->{'selfenrolladmin'}) {
4652: push(@allhelp,'Course_Approve_Selfenroll');
4653: }
4654: }
4655: if ($permission->{'grp_manage'}) {
4656: push(@allhelp,'Course_Manage_Group');
4657: }
4658: if ($permission->{'view'} || $permission->{'cusr'}) {
4659: push(@allhelp,'Course_User_Logs');
4660: }
4661: } elsif ($context eq 'author') {
4662: push(@allhelp,('Author_Change_Privileges','Author_Create_Coauthor_List',
4663: 'Author_View_Coauthor_List','Author_User_Logs'));
4664: } else {
4665: if ($permission->{'cusr'}) {
4666: push(@allhelp,'Domain_Change_Privileges');
4667: if ($permission->{'activity'}) {
4668: push(@allhelp,'Domain_User_Access_Logs');
4669: }
4670: push(@allhelp,('Domain_Create_Users','Domain_View_Users_List'));
4671: if ($permission->{'custom'}) {
4672: push(@allhelp,'Domain_Editing_Custom_Roles');
4673: }
4674: push(@allhelp,('Domain_Role_Approvals','Domain_Username_Approvals','Domain_Change_Logs'));
4675: } elsif ($permission->{'view'}) {
4676: push(@allhelp,'Domain_View_Privileges');
4677: if ($permission->{'activity'}) {
4678: push(@allhelp,'Domain_User_Access_Logs');
4679: }
4680: push(@allhelp,('Domain_View_Users_List','Domain_Change_Logs'));
4681: }
4682: }
4683: if (@allhelp) {
4684: $allhelpitems = join(',',@allhelp);
4685: }
4686: }
4687:
1.190 raeburn 4688: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.233 raeburn 4689: ['action','state','callingform','roletype','showrole','bulkaction','popup','phase',
1.391 raeburn 4690: 'username','domain','srchterm','srchdomain','srchin','srchby','srchtype','queue']);
1.190 raeburn 4691: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.351 raeburn 4692: my $args;
4693: my $brcrum = [];
4694: my $bread_crumbs_component = 'User Management';
1.391 raeburn 4695: if (($env{'form.action'} ne 'dateselect') && ($env{'form.action'} ne 'displayuserreq')) {
1.351 raeburn 4696: $brcrum = [{href=>"/adm/createuser",
4697: text=>"User Management",
1.439 raeburn 4698: help=>$allhelpitems}
1.351 raeburn 4699: ];
1.202 raeburn 4700: }
1.190 raeburn 4701: if (!$allowed) {
1.358 raeburn 4702: if ($context eq 'course') {
4703: $r->internal_redirect('/adm/viewclasslist');
4704: return OK;
4705: }
1.190 raeburn 4706: $env{'user.error.msg'}=
4707: "/adm/createuser:cst:0:0:Cannot create/modify user data ".
4708: "or view user status.";
4709: return HTTP_NOT_ACCEPTABLE;
4710: }
4711:
4712: &Apache::loncommon::content_type($r,'text/html');
4713: $r->send_http_header;
4714:
1.375 raeburn 4715: my $showcredits;
4716: if ((($context eq 'course') && ($crstype eq 'Course')) ||
4717: ($context eq 'domain')) {
4718: my %domdefaults =
4719: &Apache::lonnet::get_domain_defaults($env{'request.role.domain'});
4720: if ($domdefaults{'officialcredits'} || $domdefaults{'unofficialcredits'}) {
4721: $showcredits = 1;
4722: }
4723: }
4724:
1.190 raeburn 4725: # Main switch on form.action and form.state, as appropriate
4726: if (! exists($env{'form.action'})) {
1.351 raeburn 4727: $args = {bread_crumbs => $brcrum,
4728: bread_crumbs_component => $bread_crumbs_component};
4729: $r->print(&header(undef,$args));
1.318 raeburn 4730: $r->print(&print_main_menu($permission,$context,$crstype));
1.190 raeburn 4731: } elsif ($env{'form.action'} eq 'upload' && $permission->{'cusr'}) {
1.439 raeburn 4732: my $helpitem = 'Course_Create_Class_List';
4733: if ($context eq 'author') {
4734: $helpitem = 'Author_Create_Coauthor_List';
4735: } elsif ($context eq 'domain') {
4736: $helpitem = 'Domain_Create_Users';
4737: }
1.351 raeburn 4738: push(@{$brcrum},
4739: { href => '/adm/createuser?action=upload&state=',
4740: text => 'Upload Users List',
1.439 raeburn 4741: help => $helpitem,
1.351 raeburn 4742: });
4743: $bread_crumbs_component = 'Upload Users List';
4744: $args = {bread_crumbs => $brcrum,
4745: bread_crumbs_component => $bread_crumbs_component};
4746: $r->print(&header(undef,$args));
1.190 raeburn 4747: $r->print('<form name="studentform" method="post" '.
4748: 'enctype="multipart/form-data" '.
4749: ' action="/adm/createuser">'."\n");
4750: if (! exists($env{'form.state'})) {
4751: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
4752: } elsif ($env{'form.state'} eq 'got_file') {
1.375 raeburn 4753: &Apache::lonuserutils::print_upload_manager_form($r,$context,$permission,
4754: $crstype,$showcredits);
1.190 raeburn 4755: } elsif ($env{'form.state'} eq 'enrolling') {
4756: if ($env{'form.datatoken'}) {
1.375 raeburn 4757: &Apache::lonuserutils::upfile_drop_add($r,$context,$permission,
4758: $showcredits);
1.190 raeburn 4759: }
4760: } else {
4761: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
4762: }
1.447 ! raeburn 4763: $r->print('</form>');
1.416 raeburn 4764: } elsif (((($env{'form.action'} eq 'singleuser') || ($env{'form.action'}
4765: eq 'singlestudent')) && ($permission->{'cusr'})) ||
1.418 raeburn 4766: (($env{'form.action'} eq 'singleuser') && ($permission->{'view'})) ||
1.416 raeburn 4767: (($env{'form.action'} eq 'accesslogs') && ($permission->{'activity'}))) {
1.190 raeburn 4768: my $phase = $env{'form.phase'};
4769: my @search = ('srchterm','srchby','srchin','srchtype','srchdomain');
1.192 albertel 4770: &Apache::loncreateuser::restore_prev_selections();
4771: my $srch;
4772: foreach my $item (@search) {
4773: $srch->{$item} = $env{'form.'.$item};
4774: }
1.207 raeburn 4775: if (($phase eq 'get_user_info') || ($phase eq 'userpicked') ||
1.416 raeburn 4776: ($phase eq 'createnewuser') || ($phase eq 'activity')) {
1.207 raeburn 4777: if ($env{'form.phase'} eq 'createnewuser') {
4778: my $response;
4779: if ($env{'form.srchterm'} !~ /^$match_username$/) {
1.366 bisitz 4780: my $response =
4781: '<span class="LC_warning">'
4782: .&mt('You must specify a valid username. Only the following are allowed:'
4783: .' letters numbers - . @')
4784: .'</span>';
1.221 raeburn 4785: $env{'form.phase'} = '';
1.375 raeburn 4786: &print_username_entry_form($r,$context,$response,$srch,undef,
1.439 raeburn 4787: $crstype,$brcrum,$permission);
1.207 raeburn 4788: } else {
4789: my $ccuname =&LONCAPA::clean_username($srch->{'srchterm'});
4790: my $ccdomain=&LONCAPA::clean_domain($srch->{'srchdomain'});
4791: &print_user_modification_page($r,$ccuname,$ccdomain,
1.221 raeburn 4792: $srch,$response,$context,
1.375 raeburn 4793: $permission,$crstype,$brcrum,
4794: $showcredits);
1.207 raeburn 4795: }
4796: } elsif ($env{'form.phase'} eq 'get_user_info') {
1.190 raeburn 4797: my ($currstate,$response,$forcenewuser,$results) =
1.221 raeburn 4798: &user_search_result($context,$srch);
1.190 raeburn 4799: if ($env{'form.currstate'} eq 'modify') {
4800: $currstate = $env{'form.currstate'};
4801: }
4802: if ($currstate eq 'select') {
4803: &print_user_selection_page($r,$response,$srch,$results,
1.351 raeburn 4804: \@search,$context,undef,$crstype,
4805: $brcrum);
1.416 raeburn 4806: } elsif (($currstate eq 'modify') || ($env{'form.action'} eq 'accesslogs')) {
4807: my ($ccuname,$ccdomain,$uhome);
1.190 raeburn 4808: if (($srch->{'srchby'} eq 'uname') &&
4809: ($srch->{'srchtype'} eq 'exact')) {
4810: $ccuname = $srch->{'srchterm'};
4811: $ccdomain= $srch->{'srchdomain'};
4812: } else {
4813: my @matchedunames = keys(%{$results});
4814: ($ccuname,$ccdomain) = split(/:/,$matchedunames[0]);
4815: }
4816: $ccuname =&LONCAPA::clean_username($ccuname);
4817: $ccdomain=&LONCAPA::clean_domain($ccdomain);
1.416 raeburn 4818: if ($env{'form.action'} eq 'accesslogs') {
4819: my $uhome;
4820: if (($ccuname ne '') && ($ccdomain ne '')) {
4821: $uhome = &Apache::lonnet::homeserver($ccuname,$ccdomain);
4822: }
4823: if (($uhome eq '') || ($uhome eq 'no_host')) {
4824: $env{'form.phase'} = '';
4825: undef($forcenewuser);
4826: #if ($response) {
4827: # unless ($response =~ m{\Q<br /><br />\E$}) {
4828: # $response .= '<br /><br />';
4829: # }
4830: #}
4831: &print_username_entry_form($r,$context,$response,$srch,
1.439 raeburn 4832: $forcenewuser,$crstype,$brcrum,
4833: $permission);
1.416 raeburn 4834: } else {
4835: &print_useraccesslogs_display($r,$ccuname,$ccdomain,$permission,$brcrum);
4836: }
4837: } else {
4838: if ($env{'form.forcenewuser'}) {
4839: $response = '';
4840: }
4841: &print_user_modification_page($r,$ccuname,$ccdomain,
4842: $srch,$response,$context,
4843: $permission,$crstype,$brcrum);
1.190 raeburn 4844: }
4845: } elsif ($currstate eq 'query') {
1.351 raeburn 4846: &print_user_query_page($r,'createuser',$brcrum);
1.190 raeburn 4847: } else {
1.229 raeburn 4848: $env{'form.phase'} = '';
1.207 raeburn 4849: &print_username_entry_form($r,$context,$response,$srch,
1.439 raeburn 4850: $forcenewuser,$crstype,$brcrum,
4851: $permission);
1.190 raeburn 4852: }
4853: } elsif ($env{'form.phase'} eq 'userpicked') {
4854: my $ccuname = &LONCAPA::clean_username($env{'form.seluname'});
4855: my $ccdomain = &LONCAPA::clean_domain($env{'form.seludom'});
1.416 raeburn 4856: if ($env{'form.action'} eq 'accesslogs') {
4857: &print_useraccesslogs_display($r,$ccuname,$ccdomain,$permission,$brcrum);
4858: } else {
4859: &print_user_modification_page($r,$ccuname,$ccdomain,$srch,'',
4860: $context,$permission,$crstype,
4861: $brcrum);
4862: }
4863: } elsif ($env{'form.action'} eq 'accesslogs') {
4864: my $ccuname = &LONCAPA::clean_username($env{'form.accessuname'});
4865: my $ccdomain = &LONCAPA::clean_domain($env{'form.accessudom'});
4866: &print_useraccesslogs_display($r,$ccuname,$ccdomain,$permission,$brcrum);
1.190 raeburn 4867: }
4868: } elsif ($env{'form.phase'} eq 'update_user_data') {
1.375 raeburn 4869: &update_user_data($r,$context,$crstype,$brcrum,$showcredits);
1.190 raeburn 4870: } else {
1.351 raeburn 4871: &print_username_entry_form($r,$context,undef,$srch,undef,$crstype,
1.439 raeburn 4872: $brcrum,$permission);
1.190 raeburn 4873: }
4874: } elsif ($env{'form.action'} eq 'custom' && $permission->{'custom'}) {
1.414 raeburn 4875: my $prefix;
1.190 raeburn 4876: if ($env{'form.phase'} eq 'set_custom_roles') {
1.439 raeburn 4877: &set_custom_role($r,$context,$brcrum,$prefix,$permission);
1.190 raeburn 4878: } else {
1.439 raeburn 4879: &custom_role_editor($r,$context,$brcrum,$prefix,$permission);
1.190 raeburn 4880: }
1.362 raeburn 4881: } elsif (($env{'form.action'} eq 'processauthorreq') &&
4882: ($permission->{'cusr'}) &&
4883: (&Apache::lonnet::allowed('cau',$env{'request.role.domain'}))) {
4884: push(@{$brcrum},
4885: {href => '/adm/createuser?action=processauthorreq',
1.385 bisitz 4886: text => 'Authoring Space requests',
1.362 raeburn 4887: help => 'Domain_Role_Approvals'});
4888: $bread_crumbs_component = 'Authoring requests';
4889: if ($env{'form.state'} eq 'done') {
4890: push(@{$brcrum},
4891: {href => '/adm/createuser?action=authorreqqueue',
4892: text => 'Result',
4893: help => 'Domain_Role_Approvals'});
4894: $bread_crumbs_component = 'Authoring request result';
4895: }
4896: $args = { bread_crumbs => $brcrum,
4897: bread_crumbs_component => $bread_crumbs_component};
1.391 raeburn 4898: my $js = &usernamerequest_javascript();
4899: $r->print(&header(&add_script($js),$args));
1.362 raeburn 4900: if (!exists($env{'form.state'})) {
4901: $r->print(&Apache::loncoursequeueadmin::display_queued_requests('requestauthor',
4902: $env{'request.role.domain'}));
4903: } elsif ($env{'form.state'} eq 'done') {
4904: $r->print('<h3>'.&mt('Authoring request processing').'</h3>'."\n");
4905: $r->print(&Apache::loncoursequeueadmin::update_request_queue('requestauthor',
4906: $env{'request.role.domain'}));
4907: }
1.391 raeburn 4908: } elsif (($env{'form.action'} eq 'processusernamereq') &&
4909: ($permission->{'cusr'}) &&
4910: (&Apache::lonnet::allowed('cau',$env{'request.role.domain'}))) {
4911: push(@{$brcrum},
4912: {href => '/adm/createuser?action=processusernamereq',
4913: text => 'LON-CAPA account requests',
4914: help => 'Domain_Username_Approvals'});
4915: $bread_crumbs_component = 'Account requests';
4916: if ($env{'form.state'} eq 'done') {
4917: push(@{$brcrum},
4918: {href => '/adm/createuser?action=usernamereqqueue',
4919: text => 'Result',
4920: help => 'Domain_Username_Approvals'});
4921: $bread_crumbs_component = 'LON-CAPA account request result';
4922: }
4923: $args = { bread_crumbs => $brcrum,
4924: bread_crumbs_component => $bread_crumbs_component};
4925: my $js = &usernamerequest_javascript();
4926: $r->print(&header(&add_script($js),$args));
4927: if (!exists($env{'form.state'})) {
4928: $r->print(&Apache::loncoursequeueadmin::display_queued_requests('requestusername',
4929: $env{'request.role.domain'}));
4930: } elsif ($env{'form.state'} eq 'done') {
4931: $r->print('<h3>'.&mt('LON-CAPA account request processing').'</h3>'."\n");
4932: $r->print(&Apache::loncoursequeueadmin::update_request_queue('requestusername',
4933: $env{'request.role.domain'}));
4934: }
4935: } elsif (($env{'form.action'} eq 'displayuserreq') &&
4936: ($permission->{'cusr'})) {
4937: my $dom = $env{'form.domain'};
4938: my $uname = $env{'form.username'};
4939: my $warning;
4940: if (($dom =~ /^$match_domain$/) && (&Apache::lonnet::domain($dom) ne '')) {
4941: if (($dom eq $env{'request.role.domain'}) && (&Apache::lonnet::allowed('ccc',$dom))) {
4942: if (($uname =~ /^$match_username$/) && ($env{'form.queue'} eq 'approval')) {
4943: my $uhome = &Apache::lonnet::homeserver($uname,$dom);
4944: if ($uhome eq 'no_host') {
4945: my $queue = $env{'form.queue'};
4946: my $reqkey = &escape($uname).'_'.$queue;
4947: my $namespace = 'usernamequeue';
4948: my $domconfig = &Apache::lonnet::get_domainconfiguser($dom);
4949: my %queued =
4950: &Apache::lonnet::get($namespace,[$reqkey],$dom,$domconfig);
4951: unless ($queued{$reqkey}) {
4952: $warning = &mt('No information was found for this LON-CAPA account request.');
4953: }
4954: } else {
4955: $warning = &mt('A LON-CAPA account already exists for the requested username and domain.');
4956: }
4957: } else {
4958: $warning = &mt('LON-CAPA account request status check is for an invalid username.');
4959: }
4960: } else {
4961: $warning = &mt('You do not have rights to view LON-CAPA account requests in the domain specified.');
4962: }
4963: } else {
4964: $warning = &mt('LON-CAPA account request status check is for an invalid domain.');
4965: }
4966: my $args = { only_body => 1 };
4967: $r->print(&header(undef,$args).
4968: '<h3>'.&mt('LON-CAPA Account Request Details').'</h3>');
4969: if ($warning ne '') {
4970: $r->print('<div class="LC_warning">'.$warning.'</div>');
4971: } else {
4972: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
4973: my $domconfiguser = &Apache::lonnet::get_domainconfiguser($dom);
4974: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
4975: if (ref($domconfig{'usercreation'}) eq 'HASH') {
4976: if (ref($domconfig{'usercreation'}{'cancreate'}) eq 'HASH') {
4977: if (ref($domconfig{'usercreation'}{'cancreate'}{'emailusername'}) eq 'HASH') {
4978: my %info =
4979: &Apache::lonnet::get('nohist_requestedusernames',[$uname],$dom,$domconfiguser);
4980: if (ref($info{$uname}) eq 'HASH') {
1.396 raeburn 4981: my $usertype = $info{$uname}{'inststatus'};
4982: unless ($usertype) {
4983: $usertype = 'default';
4984: }
1.442 raeburn 4985: my ($showstatus,$showemail,$pickstart);
4986: my $numextras = 0;
4987: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.443 raeburn 4988: if ((ref($types) eq 'ARRAY') && (@{$types} > 0)) {
4989: if (ref($usertypes) eq 'HASH') {
4990: if ($usertypes->{$usertype}) {
4991: $showstatus = $usertypes->{$usertype};
4992: } else {
4993: $showstatus = $othertitle;
4994: }
4995: if ($showstatus) {
4996: $numextras ++;
4997: }
1.442 raeburn 4998: }
4999: }
5000: if (($info{$uname}{'email'} ne '') && ($info{$uname}{'email'} ne $uname)) {
5001: $showemail = $info{$uname}{'email'};
5002: $numextras ++;
5003: }
1.396 raeburn 5004: if (ref($domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}) eq 'HASH') {
5005: if ((ref($infofields) eq 'ARRAY') && (ref($infotitles) eq 'HASH')) {
1.442 raeburn 5006: $pickstart = 1;
1.396 raeburn 5007: $r->print('<div>'.&Apache::lonhtmlcommon::start_pick_box());
1.442 raeburn 5008: my ($num,$count);
1.396 raeburn 5009: $count = scalar(keys(%{$domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}}));
1.442 raeburn 5010: $count += $numextras;
1.396 raeburn 5011: foreach my $field (@{$infofields}) {
5012: next unless ($domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}{$field});
5013: next unless ($infotitles->{$field});
5014: $r->print(&Apache::lonhtmlcommon::row_title($infotitles->{$field}).
5015: $info{$uname}{$field});
5016: $num ++;
1.442 raeburn 5017: unless ($count == $num) {
1.396 raeburn 5018: $r->print(&Apache::lonhtmlcommon::row_closure());
5019: }
5020: }
1.442 raeburn 5021: }
5022: }
5023: if ($numextras) {
5024: unless ($pickstart) {
5025: $r->print('<div>'.&Apache::lonhtmlcommon::start_pick_box());
5026: $pickstart = 1;
5027: }
5028: if ($showemail) {
5029: my $closure = '';
5030: unless ($showstatus) {
5031: $closure = 1;
1.391 raeburn 5032: }
1.442 raeburn 5033: $r->print(&Apache::lonhtmlcommon::row_title(&mt('E-mail address')).
5034: $showemail.
5035: &Apache::lonhtmlcommon::row_closure($closure));
1.391 raeburn 5036: }
1.442 raeburn 5037: if ($showstatus) {
5038: $r->print(&Apache::lonhtmlcommon::row_title(&mt('Status type[_1](self-reported)','<br />')).
5039: $showstatus.
5040: &Apache::lonhtmlcommon::row_closure(1));
5041: }
5042: }
5043: if ($pickstart) {
5044: $r->print(&Apache::lonhtmlcommon::end_pick_box().'</div>');
5045: } else {
5046: $r->print('<div>'.&mt('No information to display for this account request.').'</div>');
1.391 raeburn 5047: }
1.442 raeburn 5048: } else {
5049: $r->print('<div>'.&mt('No information available for this account request.').'</div>');
1.391 raeburn 5050: }
5051: }
5052: }
5053: }
5054: }
1.442 raeburn 5055: $r->print(&close_popup_form());
1.207 raeburn 5056: } elsif (($env{'form.action'} eq 'listusers') &&
5057: ($permission->{'view'} || $permission->{'cusr'})) {
1.439 raeburn 5058: my $helpitem = 'Course_View_Class_List';
5059: if ($context eq 'author') {
5060: $helpitem = 'Author_View_Coauthor_List';
5061: } elsif ($context eq 'domain') {
5062: $helpitem = 'Domain_View_Users_List';
5063: }
1.202 raeburn 5064: if ($env{'form.phase'} eq 'bulkchange') {
1.351 raeburn 5065: push(@{$brcrum},
5066: {href => '/adm/createuser?action=listusers',
5067: text => "List Users"},
5068: {href => "/adm/createuser",
5069: text => "Result",
1.439 raeburn 5070: help => $helpitem});
1.351 raeburn 5071: $bread_crumbs_component = 'Update Users';
5072: $args = {bread_crumbs => $brcrum,
5073: bread_crumbs_component => $bread_crumbs_component};
5074: $r->print(&header(undef,$args));
1.202 raeburn 5075: my $setting = $env{'form.roletype'};
5076: my $choice = $env{'form.bulkaction'};
5077: if ($permission->{'cusr'}) {
1.336 raeburn 5078: &Apache::lonuserutils::update_user_list($r,$context,$setting,$choice,$crstype);
1.221 raeburn 5079: } else {
5080: $r->print(&mt('You are not authorized to make bulk changes to user roles'));
1.223 raeburn 5081: $r->print('<p><a href="/adm/createuser?action=listusers">'.&mt('Display User Lists').'</a>');
1.202 raeburn 5082: }
5083: } else {
1.351 raeburn 5084: push(@{$brcrum},
5085: {href => '/adm/createuser?action=listusers',
5086: text => "List Users",
1.439 raeburn 5087: help => $helpitem});
1.351 raeburn 5088: $bread_crumbs_component = 'List Users';
5089: $args = {bread_crumbs => $brcrum,
5090: bread_crumbs_component => $bread_crumbs_component};
1.202 raeburn 5091: my ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles);
5092: my $formname = 'studentform';
1.364 raeburn 5093: my $hidecall = "hide_searching();";
1.321 raeburn 5094: if (($context eq 'domain') && (($env{'form.roletype'} eq 'course') ||
5095: ($env{'form.roletype'} eq 'community'))) {
5096: if ($env{'form.roletype'} eq 'course') {
5097: ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles) =
5098: &Apache::lonuserutils::courses_selector($env{'request.role.domain'},
5099: $formname);
5100: } elsif ($env{'form.roletype'} eq 'community') {
5101: $cb_jscript =
5102: &Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
5103: my %elements = (
5104: coursepick => 'radio',
5105: coursetotal => 'text',
5106: courselist => 'text',
5107: );
5108: $jscript = &Apache::lonhtmlcommon::set_form_elements(\%elements);
5109: }
1.364 raeburn 5110: $jscript .= &verify_user_display($context)."\n".
5111: &Apache::loncommon::check_uncheck_jscript();
1.202 raeburn 5112: my $js = &add_script($jscript).$cb_jscript;
5113: my $loadcode =
5114: &Apache::lonuserutils::course_selector_loadcode($formname);
5115: if ($loadcode ne '') {
1.364 raeburn 5116: $args->{add_entries} = {onload => "$loadcode;$hidecall"};
5117: } else {
5118: $args->{add_entries} = {onload => $hidecall};
1.202 raeburn 5119: }
1.351 raeburn 5120: $r->print(&header($js,$args));
1.191 raeburn 5121: } else {
1.364 raeburn 5122: $args->{add_entries} = {onload => $hidecall};
5123: $jscript = &verify_user_display($context).
5124: &Apache::loncommon::check_uncheck_jscript();
5125: $r->print(&header(&add_script($jscript),$args));
1.191 raeburn 5126: }
1.202 raeburn 5127: &Apache::lonuserutils::print_userlist($r,undef,$permission,$context,
1.375 raeburn 5128: $formname,$totcodes,$codetitles,$idlist,$idlist_titles,
5129: $showcredits);
1.191 raeburn 5130: }
1.213 raeburn 5131: } elsif ($env{'form.action'} eq 'drop' && $permission->{'cusr'}) {
1.318 raeburn 5132: my $brtext;
5133: if ($crstype eq 'Community') {
5134: $brtext = 'Drop Members';
5135: } else {
5136: $brtext = 'Drop Students';
5137: }
1.351 raeburn 5138: push(@{$brcrum},
5139: {href => '/adm/createuser?action=drop',
5140: text => $brtext,
5141: help => 'Course_Drop_Student'});
5142: if ($env{'form.state'} eq 'done') {
5143: push(@{$brcrum},
5144: {href=>'/adm/createuser?action=drop',
5145: text=>"Result"});
5146: }
5147: $bread_crumbs_component = $brtext;
5148: $args = {bread_crumbs => $brcrum,
5149: bread_crumbs_component => $bread_crumbs_component};
5150: $r->print(&header(undef,$args));
1.213 raeburn 5151: if (!exists($env{'form.state'})) {
1.318 raeburn 5152: &Apache::lonuserutils::print_drop_menu($r,$context,$permission,$crstype);
1.213 raeburn 5153: } elsif ($env{'form.state'} eq 'done') {
5154: &Apache::lonuserutils::update_user_list($r,$context,undef,
5155: $env{'form.action'});
5156: }
1.202 raeburn 5157: } elsif ($env{'form.action'} eq 'dateselect') {
5158: if ($permission->{'cusr'}) {
1.351 raeburn 5159: $r->print(&header(undef,{'no_nav_bar' => 1}).
1.375 raeburn 5160: &Apache::lonuserutils::date_section_selector($context,$permission,
5161: $crstype,$showcredits));
1.202 raeburn 5162: } else {
1.351 raeburn 5163: $r->print(&header(undef,{'no_nav_bar' => 1}).
5164: '<span class="LC_error">'.&mt('You do not have permission to modify dates or sections for users').'</span>');
1.202 raeburn 5165: }
1.237 raeburn 5166: } elsif ($env{'form.action'} eq 'selfenroll') {
1.398 raeburn 5167: if ($permission->{selfenrolladmin}) {
5168: my %currsettings = (
5169: selfenroll_types => $env{'course.'.$cid.'.internal.selfenroll_types'},
5170: selfenroll_registered => $env{'course.'.$cid.'.internal.selfenroll_registered'},
5171: selfenroll_section => $env{'course.'.$cid.'.internal.selfenroll_section'},
5172: selfenroll_notifylist => $env{'course.'.$cid.'.internal.selfenroll_notifylist'},
5173: selfenroll_approval => $env{'course.'.$cid.'.internal.selfenroll_approval'},
5174: selfenroll_limit => $env{'course.'.$cid.'.internal.selfenroll_limit'},
5175: selfenroll_cap => $env{'course.'.$cid.'.internal.selfenroll_cap'},
5176: selfenroll_start_date => $env{'course.'.$cid.'.internal.selfenroll_start_date'},
5177: selfenroll_end_date => $env{'course.'.$cid.'.internal.selfenroll_end_date'},
5178: selfenroll_start_access => $env{'course.'.$cid.'.internal.selfenroll_start_access'},
5179: selfenroll_end_access => $env{'course.'.$cid.'.internal.selfenroll_end_access'},
5180: default_enrollment_start_date => $env{'course.'.$cid.'.default_enrollment_start_date'},
5181: default_enrollment_end_date => $env{'course.'.$cid.'.default_enrollment_end_date'},
1.400 raeburn 5182: uniquecode => $env{'course.'.$cid.'.internal.uniquecode'},
1.398 raeburn 5183: );
5184: push(@{$brcrum},
5185: {href => '/adm/createuser?action=selfenroll',
5186: text => "Configure Self-enrollment",
5187: help => 'Course_Self_Enrollment'});
5188: if (!exists($env{'form.state'})) {
5189: $args = { bread_crumbs => $brcrum,
5190: bread_crumbs_component => 'Configure Self-enrollment'};
5191: $r->print(&header(undef,$args));
5192: $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n");
5193: &print_selfenroll_menu($r,'course',$cid,$cdom,$cnum,\%currsettings);
5194: } elsif ($env{'form.state'} eq 'done') {
5195: push (@{$brcrum},
5196: {href=>'/adm/createuser?action=selfenroll',
5197: text=>"Result"});
5198: $args = { bread_crumbs => $brcrum,
5199: bread_crumbs_component => 'Self-enrollment result'};
5200: $r->print(&header(undef,$args));
5201: $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n");
1.400 raeburn 5202: &update_selfenroll_config($r,$cid,$cdom,$cnum,$context,$crstype,\%currsettings);
1.398 raeburn 5203: }
5204: } else {
5205: $r->print(&header(undef,{'no_nav_bar' => 1}).
5206: '<span class="LC_error">'.&mt('You do not have permission to configure self-enrollment').'</span>');
1.237 raeburn 5207: }
1.277 raeburn 5208: } elsif ($env{'form.action'} eq 'selfenrollqueue') {
1.418 raeburn 5209: if ($permission->{selfenrolladmin}) {
1.351 raeburn 5210: push(@{$brcrum},
5211: {href => '/adm/createuser?action=selfenrollqueue',
1.418 raeburn 5212: text => 'Enrollment requests',
1.439 raeburn 5213: help => 'Course_Approve_Selfenroll'});
1.418 raeburn 5214: $bread_crumbs_component = 'Enrollment requests';
5215: if ($env{'form.state'} eq 'done') {
5216: push(@{$brcrum},
5217: {href => '/adm/createuser?action=selfenrollqueue',
5218: text => 'Result',
1.439 raeburn 5219: help => 'Course_Approve_Selfenroll'});
1.418 raeburn 5220: $bread_crumbs_component = 'Enrollment result';
5221: }
5222: $args = { bread_crumbs => $brcrum,
5223: bread_crumbs_component => $bread_crumbs_component};
5224: $r->print(&header(undef,$args));
5225: my $coursedesc = $env{'course.'.$cid.'.description'};
5226: if (!exists($env{'form.state'})) {
5227: $r->print('<h3>'.&mt('Pending enrollment requests').'</h3>'."\n");
5228: $r->print(&Apache::loncoursequeueadmin::display_queued_requests($context,
5229: $cdom,$cnum));
5230: } elsif ($env{'form.state'} eq 'done') {
5231: $r->print('<h3>'.&mt('Enrollment request processing').'</h3>'."\n");
5232: $r->print(&Apache::loncoursequeueadmin::update_request_queue($context,
1.430 raeburn 5233: $cdom,$cnum,$coursedesc));
1.418 raeburn 5234: }
5235: } else {
5236: $r->print(&header(undef,{'no_nav_bar' => 1}).
5237: '<span class="LC_error">'.&mt('You do not have permission to manage self-enrollment').'</span>');
1.351 raeburn 5238: }
1.418 raeburn 5239: } elsif ($env{'form.action'} eq 'changelogs') {
5240: if ($permission->{cusr} || $permission->{view}) {
5241: &print_userchangelogs_display($r,$context,$permission,$brcrum);
5242: } else {
5243: $r->print(&header(undef,{'no_nav_bar' => 1}).
5244: '<span class="LC_error">'.&mt('You do not have permission to view change logs').'</span>');
1.277 raeburn 5245: }
1.428 raeburn 5246: } elsif ($env{'form.action'} eq 'helpdesk') {
5247: if (($permission->{'owner'}) || ($permission->{'co-owner'})) {
5248: if ($env{'form.state'} eq 'process') {
5249: if ($permission->{'owner'}) {
5250: &update_helpdeskaccess($r,$permission,$brcrum);
5251: } else {
5252: &print_helpdeskaccess_display($r,$permission,$brcrum);
1.430 raeburn 5253: }
1.428 raeburn 5254: } else {
5255: &print_helpdeskaccess_display($r,$permission,$brcrum);
5256: }
5257: } else {
5258: $r->print(&header(undef,{'no_nav_bar' => 1}).
5259: '<span class="LC_error">'.&mt('You do not have permission to view helpdesk access').'</span>');
5260: }
1.190 raeburn 5261: } else {
1.351 raeburn 5262: $bread_crumbs_component = 'User Management';
5263: $args = { bread_crumbs => $brcrum,
5264: bread_crumbs_component => $bread_crumbs_component};
5265: $r->print(&header(undef,$args));
1.318 raeburn 5266: $r->print(&print_main_menu($permission,$context,$crstype));
1.190 raeburn 5267: }
1.351 raeburn 5268: $r->print(&Apache::loncommon::end_page());
1.190 raeburn 5269: return OK;
5270: }
5271:
5272: sub header {
1.351 raeburn 5273: my ($jscript,$args) = @_;
1.190 raeburn 5274: my $start_page;
1.351 raeburn 5275: if (ref($args) eq 'HASH') {
5276: $start_page=&Apache::loncommon::start_page('User Management',$jscript,$args);
1.190 raeburn 5277: } else {
1.351 raeburn 5278: $start_page=&Apache::loncommon::start_page('User Management',$jscript);
1.190 raeburn 5279: }
5280: return $start_page;
5281: }
1.2 www 5282:
1.191 raeburn 5283: sub add_script {
5284: my ($js) = @_;
1.301 bisitz 5285: return '<script type="text/javascript">'."\n"
5286: .'// <![CDATA['."\n"
5287: .$js."\n"
5288: .'// ]]>'."\n"
5289: .'</script>'."\n";
1.191 raeburn 5290: }
5291:
1.391 raeburn 5292: sub usernamerequest_javascript {
5293: my $js = <<ENDJS;
5294:
5295: function openusernamereqdisplay(dom,uname,queue) {
5296: var url = '/adm/createuser?action=displayuserreq';
5297: url += '&domain='+dom+'&username='+uname+'&queue='+queue;
5298: var title = 'Account_Request_Browser';
5299: var options = 'scrollbars=1,resizable=1,menubar=0';
5300: options += ',width=700,height=600';
5301: var stdeditbrowser = open(url,title,options,'1');
5302: stdeditbrowser.focus();
5303: return;
5304: }
5305:
5306: ENDJS
5307: }
5308:
5309: sub close_popup_form {
5310: my $close= &mt('Close Window');
5311: return << "END";
5312: <p><form name="displayreq" action="" method="post">
5313: <input type="button" name="closeme" value="$close" onclick="javascript:self.close();" />
5314: </form></p>
5315: END
5316: }
5317:
1.202 raeburn 5318: sub verify_user_display {
1.364 raeburn 5319: my ($context) = @_;
1.374 raeburn 5320: my %lt = &Apache::lonlocal::texthash (
5321: course => 'course(s): description, section(s), status',
5322: community => 'community(s): description, section(s), status',
5323: author => 'author',
5324: );
1.364 raeburn 5325: my $photos;
5326: if (($context eq 'course') && $env{'request.course.id'}) {
5327: $photos = $env{'course.'.$env{'request.course.id'}.'.internal.showphoto'};
5328: }
1.202 raeburn 5329: my $output = <<"END";
5330:
1.364 raeburn 5331: function hide_searching() {
5332: if (document.getElementById('searching')) {
5333: document.getElementById('searching').style.display = 'none';
5334: }
5335: return;
5336: }
5337:
1.202 raeburn 5338: function display_update() {
5339: document.studentform.action.value = 'listusers';
5340: document.studentform.phase.value = 'display';
5341: document.studentform.submit();
5342: }
5343:
1.364 raeburn 5344: function updateCols(caller) {
5345: var context = '$context';
5346: var photos = '$photos';
5347: if (caller == 'Status') {
1.374 raeburn 5348: if ((context == 'domain') &&
5349: ((document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'course') ||
5350: (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community'))) {
1.364 raeburn 5351: document.getElementById('showcolstatus').checked = false;
5352: document.getElementById('showcolstatus').disabled = 'disabled';
5353: document.getElementById('showcolstart').checked = false;
5354: document.getElementById('showcolend').checked = false;
1.374 raeburn 5355: } else {
5356: if (document.studentform.Status.options[document.studentform.Status.selectedIndex].value == 'Any') {
5357: document.getElementById('showcolstatus').checked = true;
5358: document.getElementById('showcolstatus').disabled = '';
5359: document.getElementById('showcolstart').checked = true;
5360: document.getElementById('showcolend').checked = true;
5361: } else {
5362: document.getElementById('showcolstatus').checked = false;
5363: document.getElementById('showcolstatus').disabled = 'disabled';
5364: document.getElementById('showcolstart').checked = false;
5365: document.getElementById('showcolend').checked = false;
5366: }
1.364 raeburn 5367: }
5368: }
5369: if (caller == 'output') {
5370: if (photos == 1) {
5371: if (document.getElementById('showcolphoto')) {
5372: var photoitem = document.getElementById('showcolphoto');
5373: if (document.studentform.output.options[document.studentform.output.selectedIndex].value == 'html') {
5374: photoitem.checked = true;
5375: photoitem.disabled = '';
5376: } else {
5377: photoitem.checked = false;
5378: photoitem.disabled = 'disabled';
5379: }
5380: }
5381: }
5382: }
5383: if (caller == 'showrole') {
1.371 raeburn 5384: if ((document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'Any') ||
5385: (document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'cr')) {
1.364 raeburn 5386: document.getElementById('showcolrole').checked = true;
5387: document.getElementById('showcolrole').disabled = '';
5388: } else {
5389: document.getElementById('showcolrole').checked = false;
5390: document.getElementById('showcolrole').disabled = 'disabled';
5391: }
1.374 raeburn 5392: if (context == 'domain') {
1.382 raeburn 5393: var quotausageshow = 0;
1.374 raeburn 5394: if ((document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'course') ||
5395: (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community')) {
5396: document.getElementById('showcolstatus').checked = false;
5397: document.getElementById('showcolstatus').disabled = 'disabled';
5398: document.getElementById('showcolstart').checked = false;
5399: document.getElementById('showcolend').checked = false;
5400: } else {
5401: if (document.studentform.Status.options[document.studentform.Status.selectedIndex].value == 'Any') {
5402: document.getElementById('showcolstatus').checked = true;
5403: document.getElementById('showcolstatus').disabled = '';
5404: document.getElementById('showcolstart').checked = true;
5405: document.getElementById('showcolend').checked = true;
5406: }
5407: }
5408: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'domain') {
5409: document.getElementById('showcolextent').disabled = 'disabled';
5410: document.getElementById('showcolextent').checked = 'false';
5411: document.getElementById('showextent').style.display='none';
5412: document.getElementById('showcoltextextent').innerHTML = '';
1.382 raeburn 5413: if ((document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'au') ||
5414: (document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'Any')) {
5415: if (document.getElementById('showcolauthorusage')) {
5416: document.getElementById('showcolauthorusage').disabled = '';
5417: }
5418: if (document.getElementById('showcolauthorquota')) {
5419: document.getElementById('showcolauthorquota').disabled = '';
5420: }
5421: quotausageshow = 1;
5422: }
1.374 raeburn 5423: } else {
5424: document.getElementById('showextent').style.display='block';
5425: document.getElementById('showextent').style.textAlign='left';
5426: document.getElementById('showextent').style.textFace='normal';
5427: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'author') {
5428: document.getElementById('showcolextent').disabled = '';
5429: document.getElementById('showcolextent').checked = 'true';
5430: document.getElementById('showcoltextextent').innerHTML="$lt{'author'}";
5431: } else {
5432: document.getElementById('showcolextent').disabled = '';
5433: document.getElementById('showcolextent').checked = 'true';
5434: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community') {
5435: document.getElementById('showcoltextextent').innerHTML="$lt{'community'}";
5436: } else {
5437: document.getElementById('showcoltextextent').innerHTML="$lt{'course'}";
5438: }
5439: }
5440: }
1.382 raeburn 5441: if (quotausageshow == 0) {
5442: if (document.getElementById('showcolauthorusage')) {
5443: document.getElementById('showcolauthorusage').checked = false;
5444: document.getElementById('showcolauthorusage').disabled = 'disabled';
5445: }
5446: if (document.getElementById('showcolauthorquota')) {
5447: document.getElementById('showcolauthorquota').checked = false;
5448: document.getElementById('showcolauthorquota').disabled = 'disabled';
5449: }
5450: }
1.374 raeburn 5451: }
1.364 raeburn 5452: }
5453: return;
5454: }
5455:
1.202 raeburn 5456: END
5457: return $output;
5458:
5459: }
5460:
1.190 raeburn 5461: ###############################################################
5462: ###############################################################
5463: # Menu Phase One
5464: sub print_main_menu {
1.318 raeburn 5465: my ($permission,$context,$crstype) = @_;
5466: my $linkcontext = $context;
5467: my $stuterm = lc(&Apache::lonnet::plaintext('st',$crstype));
5468: if (($context eq 'course') && ($crstype eq 'Community')) {
5469: $linkcontext = lc($crstype);
5470: $stuterm = 'Members';
5471: }
1.208 raeburn 5472: my %links = (
1.298 droeschl 5473: domain => {
5474: upload => 'Upload a File of Users',
5475: singleuser => 'Add/Modify a User',
5476: listusers => 'Manage Users',
5477: },
5478: author => {
5479: upload => 'Upload a File of Co-authors',
5480: singleuser => 'Add/Modify a Co-author',
5481: listusers => 'Manage Co-authors',
5482: },
5483: course => {
5484: upload => 'Upload a File of Course Users',
5485: singleuser => 'Add/Modify a Course User',
1.354 www 5486: listusers => 'List and Modify Multiple Course Users',
1.298 droeschl 5487: },
1.318 raeburn 5488: community => {
5489: upload => 'Upload a File of Community Users',
5490: singleuser => 'Add/Modify a Community User',
1.354 www 5491: listusers => 'List and Modify Multiple Community Users',
1.318 raeburn 5492: },
5493: );
5494: my %linktitles = (
5495: domain => {
5496: singleuser => 'Add a user to the domain, and/or a course or community in the domain.',
5497: listusers => 'Show and manage users in this domain.',
5498: },
5499: author => {
5500: singleuser => 'Add a user with a co- or assistant author role.',
5501: listusers => 'Show and manage co- or assistant authors.',
5502: },
5503: course => {
5504: singleuser => 'Add a user with a certain role to this course.',
5505: listusers => 'Show and manage users in this course.',
5506: },
5507: community => {
5508: singleuser => 'Add a user with a certain role to this community.',
5509: listusers => 'Show and manage users in this community.',
5510: },
1.298 droeschl 5511: );
1.418 raeburn 5512: if ($linkcontext eq 'domain') {
5513: unless ($permission->{'cusr'}) {
1.430 raeburn 5514: $links{'domain'}{'singleuser'} = 'View a User';
1.418 raeburn 5515: $linktitles{'domain'}{'singleuser'} = 'View information about a user in the domain';
5516: }
5517: } elsif ($linkcontext eq 'course') {
5518: unless ($permission->{'cusr'}) {
5519: $links{'course'}{'singleuser'} = 'View a Course User';
5520: $linktitles{'course'}{'singleuser'} = 'View information about a user in this course';
5521: $links{'course'}{'listusers'} = 'List Course Users';
5522: $linktitles{'course'}{'listusers'} = 'Show information about users in this course';
5523: }
5524: } elsif ($linkcontext eq 'community') {
5525: unless ($permission->{'cusr'}) {
5526: $links{'community'}{'singleuser'} = 'View a Community User';
5527: $linktitles{'community'}{'singleuser'} = 'View information about a user in this community';
5528: $links{'community'}{'listusers'} = 'List Community Users';
5529: $linktitles{'community'}{'listusers'} = 'Show information about users in this community';
5530: }
5531: }
1.298 droeschl 5532: my @menu = ( {categorytitle => 'Single Users',
5533: items =>
5534: [
5535: {
1.318 raeburn 5536: linktext => $links{$linkcontext}{'singleuser'},
1.298 droeschl 5537: icon => 'edit-redo.png',
5538: #help => 'Course_Change_Privileges',
5539: url => '/adm/createuser?action=singleuser',
1.418 raeburn 5540: permission => ($permission->{'view'} || $permission->{'cusr'}),
1.318 raeburn 5541: linktitle => $linktitles{$linkcontext}{'singleuser'},
1.298 droeschl 5542: },
5543: ]},
5544:
5545: {categorytitle => 'Multiple Users',
5546: items =>
5547: [
5548: {
1.318 raeburn 5549: linktext => $links{$linkcontext}{'upload'},
1.340 wenzelju 5550: icon => 'uplusr.png',
1.298 droeschl 5551: #help => 'Course_Create_Class_List',
5552: url => '/adm/createuser?action=upload',
5553: permission => $permission->{'cusr'},
5554: linktitle => 'Upload a CSV or a text file containing users.',
5555: },
5556: {
1.318 raeburn 5557: linktext => $links{$linkcontext}{'listusers'},
1.340 wenzelju 5558: icon => 'mngcu.png',
1.298 droeschl 5559: #help => 'Course_View_Class_List',
5560: url => '/adm/createuser?action=listusers',
5561: permission => ($permission->{'view'} || $permission->{'cusr'}),
1.318 raeburn 5562: linktitle => $linktitles{$linkcontext}{'listusers'},
1.298 droeschl 5563: },
5564:
5565: ]},
5566:
5567: {categorytitle => 'Administration',
5568: items => [ ]},
5569: );
1.415 raeburn 5570:
1.265 mielkec 5571: if ($context eq 'domain'){
1.416 raeburn 5572: push(@{ $menu[0]->{items} }, # Single Users
5573: {
5574: linktext => 'User Access Log',
1.417 raeburn 5575: icon => 'document-properties.png',
1.425 raeburn 5576: #help => 'Domain_User_Access_Logs',
1.416 raeburn 5577: url => '/adm/createuser?action=accesslogs',
5578: permission => $permission->{'activity'},
5579: linktitle => 'View user access log.',
5580: }
5581: );
1.298 droeschl 5582:
5583: push(@{ $menu[2]->{items} }, #Category: Administration
5584: {
5585: linktext => 'Custom Roles',
5586: icon => 'emblem-photos.png',
5587: #help => 'Course_Editing_Custom_Roles',
5588: url => '/adm/createuser?action=custom',
5589: permission => $permission->{'custom'},
5590: linktitle => 'Configure a custom role.',
5591: },
1.362 raeburn 5592: {
5593: linktext => 'Authoring Space Requests',
5594: icon => 'selfenrl-queue.png',
5595: #help => 'Domain_Role_Approvals',
5596: url => '/adm/createuser?action=processauthorreq',
5597: permission => $permission->{'cusr'},
5598: linktitle => 'Approve or reject author role requests',
5599: },
1.363 raeburn 5600: {
1.391 raeburn 5601: linktext => 'LON-CAPA Account Requests',
5602: icon => 'list-add.png',
5603: #help => 'Domain_Username_Approvals',
5604: url => '/adm/createuser?action=processusernamereq',
5605: permission => $permission->{'cusr'},
5606: linktitle => 'Approve or reject LON-CAPA account requests',
5607: },
5608: {
1.363 raeburn 5609: linktext => 'Change Log',
5610: icon => 'document-properties.png',
5611: #help => 'Course_User_Logs',
5612: url => '/adm/createuser?action=changelogs',
1.418 raeburn 5613: permission => ($permission->{'cusr'} || $permission->{'view'}),
1.363 raeburn 5614: linktitle => 'View change log.',
5615: },
1.298 droeschl 5616: );
5617:
1.265 mielkec 5618: }elsif ($context eq 'course'){
1.298 droeschl 5619: my ($cnum,$cdom) = &Apache::lonuserutils::get_course_identity();
1.318 raeburn 5620:
5621: my %linktext = (
5622: 'Course' => {
5623: single => 'Add/Modify a Student',
5624: drop => 'Drop Students',
5625: groups => 'Course Groups',
5626: },
5627: 'Community' => {
5628: single => 'Add/Modify a Member',
5629: drop => 'Drop Members',
5630: groups => 'Community Groups',
5631: },
5632: );
1.411 raeburn 5633: $linktext{'Placement'} = $linktext{'Course'};
1.318 raeburn 5634:
5635: my %linktitle = (
5636: 'Course' => {
5637: single => 'Add a user with the role of student to this course',
5638: drop => 'Remove a student from this course.',
5639: groups => 'Manage course groups',
5640: },
5641: 'Community' => {
5642: single => 'Add a user with the role of member to this community',
5643: drop => 'Remove a member from this community.',
5644: groups => 'Manage community groups',
5645: },
5646: );
5647:
1.411 raeburn 5648: $linktitle{'Placement'} = $linktitle{'Course'};
5649:
1.298 droeschl 5650: push(@{ $menu[0]->{items} }, #Category: Single Users
5651: {
1.318 raeburn 5652: linktext => $linktext{$crstype}{'single'},
1.298 droeschl 5653: #help => 'Course_Add_Student',
5654: icon => 'list-add.png',
5655: url => '/adm/createuser?action=singlestudent',
5656: permission => $permission->{'cusr'},
1.318 raeburn 5657: linktitle => $linktitle{$crstype}{'single'},
1.298 droeschl 5658: },
5659: );
5660:
5661: push(@{ $menu[1]->{items} }, #Category: Multiple Users
5662: {
1.318 raeburn 5663: linktext => $linktext{$crstype}{'drop'},
1.298 droeschl 5664: icon => 'edit-undo.png',
5665: #help => 'Course_Drop_Student',
5666: url => '/adm/createuser?action=drop',
5667: permission => $permission->{'cusr'},
1.318 raeburn 5668: linktitle => $linktitle{$crstype}{'drop'},
1.298 droeschl 5669: },
5670: );
5671: push(@{ $menu[2]->{items} }, #Category: Administration
1.428 raeburn 5672: {
5673: linktext => 'Helpdesk Access',
5674: icon => 'helpdesk-access.png',
5675: #help => 'Course_Helpdesk_Access',
5676: url => '/adm/createuser?action=helpdesk',
5677: permission => ($permission->{'owner'} || $permission->{'co-owner'}),
5678: linktitle => 'Helpdesk access options',
5679: },
5680: {
1.298 droeschl 5681: linktext => 'Custom Roles',
5682: icon => 'emblem-photos.png',
5683: #help => 'Course_Editing_Custom_Roles',
5684: url => '/adm/createuser?action=custom',
5685: permission => $permission->{'custom'},
5686: linktitle => 'Configure a custom role.',
5687: },
5688: {
1.318 raeburn 5689: linktext => $linktext{$crstype}{'groups'},
1.333 wenzelju 5690: icon => 'grps.png',
1.298 droeschl 5691: #help => 'Course_Manage_Group',
5692: url => '/adm/coursegroups?refpage=cusr',
5693: permission => $permission->{'grp_manage'},
1.318 raeburn 5694: linktitle => $linktitle{$crstype}{'groups'},
1.298 droeschl 5695: },
5696: {
1.328 wenzelju 5697: linktext => 'Change Log',
1.298 droeschl 5698: icon => 'document-properties.png',
5699: #help => 'Course_User_Logs',
5700: url => '/adm/createuser?action=changelogs',
1.418 raeburn 5701: permission => ($permission->{'view'} || $permission->{'cusr'}),
1.298 droeschl 5702: linktitle => 'View change log.',
5703: },
5704: );
1.277 raeburn 5705: if ($env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_approval'}) {
1.298 droeschl 5706: push(@{ $menu[2]->{items} },
1.398 raeburn 5707: {
1.298 droeschl 5708: linktext => 'Enrollment Requests',
5709: icon => 'selfenrl-queue.png',
5710: #help => 'Course_Approve_Selfenroll',
5711: url => '/adm/createuser?action=selfenrollqueue',
1.398 raeburn 5712: permission => $permission->{'selfenrolladmin'},
1.298 droeschl 5713: linktitle =>'Approve or reject enrollment requests.',
5714: },
5715: );
1.277 raeburn 5716: }
1.298 droeschl 5717:
1.265 mielkec 5718: if (!exists($permission->{'cusr_section'})){
1.320 raeburn 5719: if ($crstype ne 'Community') {
5720: push(@{ $menu[2]->{items} },
5721: {
5722: linktext => 'Automated Enrollment',
5723: icon => 'roles.png',
5724: #help => 'Course_Automated_Enrollment',
5725: permission => (&Apache::lonnet::auto_run($cnum,$cdom)
1.418 raeburn 5726: && (($permission->{'cusr'}) ||
5727: ($permission->{'view'}))),
1.320 raeburn 5728: url => '/adm/populate',
5729: linktitle => 'Automated enrollment manager.',
5730: }
5731: );
5732: }
5733: push(@{ $menu[2]->{items} },
1.298 droeschl 5734: {
5735: linktext => 'User Self-Enrollment',
1.342 wenzelju 5736: icon => 'self_enroll.png',
1.298 droeschl 5737: #help => 'Course_Self_Enrollment',
5738: url => '/adm/createuser?action=selfenroll',
1.398 raeburn 5739: permission => $permission->{'selfenrolladmin'},
1.317 bisitz 5740: linktitle => 'Configure user self-enrollment.',
1.298 droeschl 5741: },
5742: );
5743: }
1.363 raeburn 5744: } elsif ($context eq 'author') {
1.370 raeburn 5745: push(@{ $menu[2]->{items} }, #Category: Administration
1.363 raeburn 5746: {
5747: linktext => 'Change Log',
5748: icon => 'document-properties.png',
5749: #help => 'Course_User_Logs',
5750: url => '/adm/createuser?action=changelogs',
5751: permission => $permission->{'cusr'},
5752: linktitle => 'View change log.',
5753: },
1.370 raeburn 5754: );
1.363 raeburn 5755: }
5756: return Apache::lonhtmlcommon::generate_menu(@menu);
1.250 raeburn 5757: # { text => 'View Log-in History',
5758: # help => 'Course_User_Logins',
5759: # action => 'logins',
5760: # permission => $permission->{'cusr'},
5761: # });
1.190 raeburn 5762: }
5763:
1.189 albertel 5764: sub restore_prev_selections {
5765: my %saveable_parameters = ('srchby' => 'scalar',
5766: 'srchin' => 'scalar',
5767: 'srchtype' => 'scalar',
5768: );
5769: &Apache::loncommon::store_settings('user','user_picker',
5770: \%saveable_parameters);
5771: &Apache::loncommon::restore_settings('user','user_picker',
5772: \%saveable_parameters);
5773: }
5774:
1.237 raeburn 5775: sub print_selfenroll_menu {
1.418 raeburn 5776: my ($r,$context,$cid,$cdom,$cnum,$currsettings,$additional,$readonly) = @_;
1.322 raeburn 5777: my $crstype = &Apache::loncommon::course_type();
1.398 raeburn 5778: my $formname = 'selfenroll';
1.237 raeburn 5779: my $nolink = 1;
1.398 raeburn 5780: my ($row,$lt) = &Apache::lonuserutils::get_selfenroll_titles();
1.237 raeburn 5781: my $groupslist = &Apache::lonuserutils::get_groupslist();
5782: my $setsec_js =
5783: &Apache::lonuserutils::setsections_javascript($formname,$groupslist);
1.249 raeburn 5784: my %alerts = &Apache::lonlocal::texthash(
5785: acto => 'Activation of self-enrollment was selected for the following domain(s)',
5786: butn => 'but no user types have been checked.',
5787: wilf => "Please uncheck 'activate' or check at least one type.",
5788: );
1.418 raeburn 5789: my $disabled;
5790: if ($readonly) {
5791: $disabled = ' disabled="disabled"';
5792: }
1.405 damieng 5793: &js_escape(\%alerts);
1.249 raeburn 5794: my $selfenroll_js = <<"ENDSCRIPT";
5795: function update_types(caller,num) {
5796: var delidx = getIndexByName('selfenroll_delete');
5797: var actidx = getIndexByName('selfenroll_activate');
5798: if (caller == 'selfenroll_all') {
5799: var selall;
5800: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
5801: if (document.$formname.selfenroll_all[i].checked) {
5802: selall = document.$formname.selfenroll_all[i].value;
5803: }
5804: }
5805: if (selall == 1) {
5806: if (delidx != -1) {
5807: if (document.$formname.selfenroll_delete.length) {
5808: for (var j=0; j<document.$formname.selfenroll_delete.length; j++) {
5809: document.$formname.selfenroll_delete[j].checked = true;
5810: }
5811: } else {
5812: document.$formname.elements[delidx].checked = true;
5813: }
5814: }
5815: if (actidx != -1) {
5816: if (document.$formname.selfenroll_activate.length) {
5817: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
5818: document.$formname.selfenroll_activate[j].checked = false;
5819: }
5820: } else {
5821: document.$formname.elements[actidx].checked = false;
5822: }
5823: }
5824: document.$formname.selfenroll_newdom.selectedIndex = 0;
5825: }
5826: }
5827: if (caller == 'selfenroll_activate') {
5828: if (document.$formname.selfenroll_activate.length) {
5829: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
5830: if (document.$formname.selfenroll_activate[j].value == num) {
5831: if (document.$formname.selfenroll_activate[j].checked) {
5832: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
5833: if (document.$formname.selfenroll_all[i].value == '1') {
5834: document.$formname.selfenroll_all[i].checked = false;
5835: }
5836: if (document.$formname.selfenroll_all[i].value == '0') {
5837: document.$formname.selfenroll_all[i].checked = true;
5838: }
5839: }
5840: }
5841: }
5842: }
5843: } else {
5844: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
5845: if (document.$formname.selfenroll_all[i].value == '1') {
5846: document.$formname.selfenroll_all[i].checked = false;
5847: }
5848: if (document.$formname.selfenroll_all[i].value == '0') {
5849: document.$formname.selfenroll_all[i].checked = true;
5850: }
5851: }
5852: }
5853: }
5854: if (caller == 'selfenroll_delete') {
5855: if (document.$formname.selfenroll_delete.length) {
5856: for (var j=0; j<document.$formname.selfenroll_delete.length; j++) {
5857: if (document.$formname.selfenroll_delete[j].value == num) {
5858: if (document.$formname.selfenroll_delete[j].checked) {
5859: var delindex = getIndexByName('selfenroll_types_'+num);
5860: if (delindex != -1) {
5861: if (document.$formname.elements[delindex].length) {
5862: for (var k=0; k<document.$formname.elements[delindex].length; k++) {
5863: document.$formname.elements[delindex][k].checked = false;
5864: }
5865: } else {
5866: document.$formname.elements[delindex].checked = false;
5867: }
5868: }
5869: }
5870: }
5871: }
5872: } else {
5873: if (document.$formname.selfenroll_delete.checked) {
5874: var delindex = getIndexByName('selfenroll_types_'+num);
5875: if (delindex != -1) {
5876: if (document.$formname.elements[delindex].length) {
5877: for (var k=0; k<document.$formname.elements[delindex].length; k++) {
5878: document.$formname.elements[delindex][k].checked = false;
5879: }
5880: } else {
5881: document.$formname.elements[delindex].checked = false;
5882: }
5883: }
5884: }
5885: }
5886: }
5887: return;
5888: }
5889:
5890: function validate_types(form) {
5891: var needaction = new Array();
5892: var countfail = 0;
5893: var actidx = getIndexByName('selfenroll_activate');
5894: if (actidx != -1) {
5895: if (document.$formname.selfenroll_activate.length) {
5896: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
5897: var num = document.$formname.selfenroll_activate[j].value;
5898: if (document.$formname.selfenroll_activate[j].checked) {
5899: countfail = check_types(num,countfail,needaction)
5900: }
5901: }
5902: } else {
5903: if (document.$formname.selfenroll_activate.checked) {
1.398 raeburn 5904: var num = document.$formname.selfenroll_activate.value;
1.249 raeburn 5905: countfail = check_types(num,countfail,needaction)
5906: }
5907: }
5908: }
5909: if (countfail > 0) {
5910: var msg = "$alerts{'acto'}\\n";
5911: var loopend = needaction.length -1;
5912: if (loopend > 0) {
5913: for (var m=0; m<loopend; m++) {
5914: msg += needaction[m]+", ";
5915: }
5916: }
5917: msg += needaction[loopend]+"\\n$alerts{'butn'}\\n$alerts{'wilf'}";
5918: alert(msg);
5919: return;
5920: }
5921: setSections(form);
5922: }
5923:
5924: function check_types(num,countfail,needaction) {
1.441 raeburn 5925: var boxname = 'selfenroll_types_'+num;
5926: var typeidx = getIndexByName(boxname);
1.249 raeburn 5927: var count = 0;
5928: if (typeidx != -1) {
1.441 raeburn 5929: if (document.$formname.elements[boxname].length) {
5930: for (var k=0; k<document.$formname.elements[boxname].length; k++) {
5931: if (document.$formname.elements[boxname][k].checked) {
1.249 raeburn 5932: count ++;
5933: }
5934: }
5935: } else {
5936: if (document.$formname.elements[typeidx].checked) {
5937: count ++;
5938: }
5939: }
5940: if (count == 0) {
5941: var domidx = getIndexByName('selfenroll_dom_'+num);
5942: if (domidx != -1) {
5943: var domname = document.$formname.elements[domidx].value;
5944: needaction[countfail] = domname;
5945: countfail ++;
5946: }
5947: }
5948: }
5949: return countfail;
5950: }
5951:
1.398 raeburn 5952: function toggleNotify() {
5953: var selfenrollApproval = 0;
5954: if (document.$formname.selfenroll_approval.length) {
5955: for (var i=0; i<document.$formname.selfenroll_approval.length; i++) {
5956: if (document.$formname.selfenroll_approval[i].checked) {
5957: selfenrollApproval = document.$formname.selfenroll_approval[i].value;
5958: break;
5959: }
5960: }
5961: }
5962: if (document.getElementById('notified')) {
5963: if (selfenrollApproval == 0) {
5964: document.getElementById('notified').style.display='none';
5965: } else {
5966: document.getElementById('notified').style.display='block';
5967: }
5968: }
5969: return;
5970: }
5971:
1.249 raeburn 5972: function getIndexByName(item) {
5973: for (var i=0;i<document.$formname.elements.length;i++) {
5974: if (document.$formname.elements[i].name == item) {
5975: return i;
5976: }
5977: }
5978: return -1;
5979: }
5980: ENDSCRIPT
1.256 raeburn 5981:
1.237 raeburn 5982: my $output = '<script type="text/javascript">'."\n".
1.301 bisitz 5983: '// <![CDATA['."\n".
1.249 raeburn 5984: $setsec_js."\n".$selfenroll_js."\n".
1.301 bisitz 5985: '// ]]>'."\n".
1.237 raeburn 5986: '</script>'."\n".
1.256 raeburn 5987: '<h3>'.$lt->{'selfenroll'}.'</h3>'."\n";
1.400 raeburn 5988:
5989: my $visactions = &cat_visibility();
5990: my ($cathash,%cattype);
5991: my %domconfig = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom);
5992: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
5993: $cathash = $domconfig{'coursecategories'}{'cats'};
5994: $cattype{'auth'} = $domconfig{'coursecategories'}{'auth'};
5995: $cattype{'unauth'} = $domconfig{'coursecategories'}{'unauth'};
1.406 raeburn 5996: if ($cattype{'auth'} eq '') {
5997: $cattype{'auth'} = 'std';
5998: }
5999: if ($cattype{'unauth'} eq '') {
6000: $cattype{'unauth'} = 'std';
6001: }
1.400 raeburn 6002: } else {
6003: $cathash = {};
6004: $cattype{'auth'} = 'std';
6005: $cattype{'unauth'} = 'std';
6006: }
6007: if (($cattype{'auth'} eq 'none') && ($cattype{'unauth'} eq 'none')) {
6008: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
6009: '<br />'.
6010: '<br />'.$visactions->{'take'}.'<ul>'.
6011: '<li>'.$visactions->{'dc_chgconf'}.'</li>'.
6012: '</ul>');
6013: } elsif (($cattype{'auth'} !~ /^(std|domonly)$/) && ($cattype{'unauth'} !~ /^(std|domonly)$/)) {
6014: if ($currsettings->{'uniquecode'}) {
6015: $r->print('<span class="LC_info">'.$visactions->{'vis'}.'</span>');
6016: } else {
6017: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
6018: '<br />'.
6019: '<br />'.$visactions->{'take'}.'<ul>'.
6020: '<li>'.$visactions->{'dc_setcode'}.'</li>'.
6021: '</ul><br />');
6022: }
6023: } else {
6024: my ($visible,$cansetvis,$vismsgs) = &visible_in_stdcat($cdom,$cnum,\%domconfig);
6025: if (ref($visactions) eq 'HASH') {
6026: if ($visible) {
6027: $output .= '<p class="LC_info">'.$visactions->{'vis'}.'</p>';
6028: } else {
6029: $output .= '<p class="LC_warning">'.$visactions->{'miss'}.'</p>'
6030: .$visactions->{'yous'}.
6031: '<p>'.$visactions->{'gen'}.'<br />'.$visactions->{'coca'};
6032: if (ref($vismsgs) eq 'ARRAY') {
6033: $output .= '<br />'.$visactions->{'make'}.'<ul>';
6034: foreach my $item (@{$vismsgs}) {
6035: $output .= '<li>'.$visactions->{$item}.'</li>';
6036: }
6037: $output .= '</ul>';
1.256 raeburn 6038: }
1.400 raeburn 6039: $output .= '</p>';
1.256 raeburn 6040: }
6041: }
6042: }
1.398 raeburn 6043: my $actionhref = '/adm/createuser';
6044: if ($context eq 'domain') {
6045: $actionhref = '/adm/modifycourse';
6046: }
1.400 raeburn 6047:
6048: my %noedit;
6049: unless ($context eq 'domain') {
6050: %noedit = &get_noedit_fields($cdom,$cnum,$crstype,$row);
6051: }
1.398 raeburn 6052: $output .= '<form name="'.$formname.'" method="post" action="'.$actionhref.'">'."\n".
1.256 raeburn 6053: &Apache::lonhtmlcommon::start_pick_box();
1.237 raeburn 6054: if (ref($row) eq 'ARRAY') {
6055: foreach my $item (@{$row}) {
6056: my $title = $item;
6057: if (ref($lt) eq 'HASH') {
6058: $title = $lt->{$item};
6059: }
1.297 bisitz 6060: $output .= &Apache::lonhtmlcommon::row_title($title);
1.237 raeburn 6061: if ($item eq 'types') {
1.398 raeburn 6062: my $curr_types;
6063: if (ref($currsettings) eq 'HASH') {
6064: $curr_types = $currsettings->{'selfenroll_types'};
6065: }
1.400 raeburn 6066: if ($noedit{$item}) {
6067: if ($curr_types eq '*') {
6068: $output .= &mt('Any user in any domain');
6069: } else {
6070: my @entries = split(/;/,$curr_types);
6071: if (@entries > 0) {
6072: $output .= '<ul>';
6073: foreach my $entry (@entries) {
6074: my ($currdom,$typestr) = split(/:/,$entry);
6075: next if ($typestr eq '');
6076: my $domdesc = &Apache::lonnet::domain($currdom);
6077: my @currinsttypes = split(',',$typestr);
6078: my ($othertitle,$usertypes,$types) =
6079: &Apache::loncommon::sorted_inst_types($currdom);
6080: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
6081: $usertypes->{'any'} = &mt('any user');
6082: if (keys(%{$usertypes}) > 0) {
6083: $usertypes->{'other'} = &mt('other users');
6084: }
6085: my @longinsttypes = map { $usertypes->{$_}; } @currinsttypes;
6086: $output .= '<li>'.$domdesc.':'.join(', ',@longinsttypes).'</li>';
6087: }
6088: }
6089: $output .= '</ul>';
6090: } else {
6091: $output .= &mt('None');
6092: }
6093: }
6094: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6095: next;
6096: }
1.241 raeburn 6097: my $showdomdesc = 1;
6098: my $includeempty = 1;
6099: my $num = 0;
6100: $output .= &Apache::loncommon::start_data_table().
6101: &Apache::loncommon::start_data_table_row()
6102: .'<td colspan="2"><span class="LC_nobreak"><label>'
6103: .&mt('Any user in any domain:')
6104: .' <input type="radio" name="selfenroll_all" value="1" ';
6105: if ($curr_types eq '*') {
6106: $output .= ' checked="checked" ';
6107: }
1.249 raeburn 6108: $output .= 'onchange="javascript:update_types('.
1.418 raeburn 6109: "'selfenroll_all'".');"'.$disabled.' />'.&mt('Yes').'</label>'.
1.249 raeburn 6110: ' <input type="radio" name="selfenroll_all" value="0" ';
1.241 raeburn 6111: if ($curr_types ne '*') {
6112: $output .= ' checked="checked" ';
6113: }
1.249 raeburn 6114: $output .= ' onchange="javascript:update_types('.
1.418 raeburn 6115: "'selfenroll_all'".');"'.$disabled.' />'.&mt('No').'</label></td>'.
1.249 raeburn 6116: &Apache::loncommon::end_data_table_row().
6117: &Apache::loncommon::end_data_table().
6118: &mt('Or').'<br />'.
6119: &Apache::loncommon::start_data_table();
1.241 raeburn 6120: my %currdoms;
1.249 raeburn 6121: if ($curr_types eq '') {
1.241 raeburn 6122: $output .= &new_selfenroll_dom_row($cdom,'0');
6123: } elsif ($curr_types ne '*') {
6124: my @entries = split(/;/,$curr_types);
6125: if (@entries > 0) {
6126: foreach my $entry (@entries) {
6127: my ($currdom,$typestr) = split(/:/,$entry);
6128: $currdoms{$currdom} = 1;
6129: my $domdesc = &Apache::lonnet::domain($currdom);
1.249 raeburn 6130: my @currinsttypes = split(',',$typestr);
1.241 raeburn 6131: $output .= &Apache::loncommon::start_data_table_row()
6132: .'<td valign="top"><span class="LC_nobreak">'.&mt('Domain:').'<b>'
6133: .' '.$domdesc.' ('.$currdom.')'
6134: .'</b><input type="hidden" name="selfenroll_dom_'.$num
6135: .'" value="'.$currdom.'" /></span><br />'
6136: .'<span class="LC_nobreak"><label><input type="checkbox" '
1.418 raeburn 6137: .'name="selfenroll_delete" value="'.$num.'" onchange="javascript:update_types('."'selfenroll_delete','$num'".');"'.$disabled.' />'
1.241 raeburn 6138: .&mt('Delete').'</label></span></td>';
1.249 raeburn 6139: $output .= '<td valign="top"> '.&mt('User types:').'<br />'
1.418 raeburn 6140: .&selfenroll_inst_types($num,$currdom,\@currinsttypes,$readonly).'</td>'
1.241 raeburn 6141: .&Apache::loncommon::end_data_table_row();
6142: $num ++;
6143: }
6144: }
6145: }
1.249 raeburn 6146: my $add_domtitle = &mt('Users in additional domain:');
1.241 raeburn 6147: if ($curr_types eq '*') {
1.249 raeburn 6148: $add_domtitle = &mt('Users in specific domain:');
1.241 raeburn 6149: } elsif ($curr_types eq '') {
1.249 raeburn 6150: $add_domtitle = &mt('Users in other domain:');
1.241 raeburn 6151: }
1.446 raeburn 6152: my ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('enroll',$cdom);
1.241 raeburn 6153: $output .= &Apache::loncommon::start_data_table_row()
6154: .'<td colspan="2"><span class="LC_nobreak">'.$add_domtitle.'</span><br />'
6155: .&Apache::loncommon::select_dom_form('','selfenroll_newdom',
1.446 raeburn 6156: $includeempty,$showdomdesc,'',$trusted,$untrusted,$readonly)
1.241 raeburn 6157: .'<input type="hidden" name="selfenroll_types_total" value="'.$num.'" />'
6158: .'</td>'.&Apache::loncommon::end_data_table_row()
6159: .&Apache::loncommon::end_data_table();
1.237 raeburn 6160: } elsif ($item eq 'registered') {
6161: my ($regon,$regoff);
1.398 raeburn 6162: my $registered;
6163: if (ref($currsettings) eq 'HASH') {
6164: $registered = $currsettings->{'selfenroll_registered'};
6165: }
1.400 raeburn 6166: if ($noedit{$item}) {
6167: if ($registered) {
6168: $output .= &mt('Must be registered in course');
6169: } else {
6170: $output .= &mt('No requirement');
6171: }
6172: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6173: next;
6174: }
1.398 raeburn 6175: if ($registered) {
1.237 raeburn 6176: $regon = ' checked="checked" ';
1.419 raeburn 6177: $regoff = '';
1.237 raeburn 6178: } else {
1.419 raeburn 6179: $regon = '';
1.237 raeburn 6180: $regoff = ' checked="checked" ';
6181: }
6182: $output .= '<label>'.
1.419 raeburn 6183: '<input type="radio" name="selfenroll_registered" value="1"'.$regon.$disabled.' />'.
1.244 bisitz 6184: &mt('Yes').'</label> <label>'.
1.419 raeburn 6185: '<input type="radio" name="selfenroll_registered" value="0"'.$regoff.$disabled.' />'.
1.244 bisitz 6186: &mt('No').'</label>';
1.237 raeburn 6187: } elsif ($item eq 'enroll_dates') {
1.398 raeburn 6188: my ($starttime,$endtime);
6189: if (ref($currsettings) eq 'HASH') {
6190: $starttime = $currsettings->{'selfenroll_start_date'};
6191: $endtime = $currsettings->{'selfenroll_end_date'};
6192: if ($starttime eq '') {
6193: $starttime = $currsettings->{'default_enrollment_start_date'};
6194: }
6195: if ($endtime eq '') {
6196: $endtime = $currsettings->{'default_enrollment_end_date'};
6197: }
1.237 raeburn 6198: }
1.400 raeburn 6199: if ($noedit{$item}) {
6200: $output .= &mt('From: [_1], to: [_2]',&Apache::lonlocal::locallocaltime($starttime),
6201: &Apache::lonlocal::locallocaltime($endtime));
6202: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6203: next;
6204: }
1.237 raeburn 6205: my $startform =
6206: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_start_date',$starttime,
1.418 raeburn 6207: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
1.237 raeburn 6208: my $endform =
6209: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_end_date',$endtime,
1.418 raeburn 6210: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
1.237 raeburn 6211: $output .= &selfenroll_date_forms($startform,$endform);
6212: } elsif ($item eq 'access_dates') {
1.398 raeburn 6213: my ($starttime,$endtime);
6214: if (ref($currsettings) eq 'HASH') {
6215: $starttime = $currsettings->{'selfenroll_start_access'};
6216: $endtime = $currsettings->{'selfenroll_end_access'};
6217: if ($starttime eq '') {
6218: $starttime = $currsettings->{'default_enrollment_start_date'};
6219: }
6220: if ($endtime eq '') {
6221: $endtime = $currsettings->{'default_enrollment_end_date'};
6222: }
1.237 raeburn 6223: }
1.400 raeburn 6224: if ($noedit{$item}) {
6225: $output .= &mt('From: [_1], to: [_2]',&Apache::lonlocal::locallocaltime($starttime),
6226: &Apache::lonlocal::locallocaltime($endtime));
6227: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6228: next;
6229: }
1.237 raeburn 6230: my $startform =
6231: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_start_access',$starttime,
1.418 raeburn 6232: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
1.237 raeburn 6233: my $endform =
6234: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_end_access',$endtime,
1.418 raeburn 6235: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
1.237 raeburn 6236: $output .= &selfenroll_date_forms($startform,$endform);
6237: } elsif ($item eq 'section') {
1.398 raeburn 6238: my $currsec;
6239: if (ref($currsettings) eq 'HASH') {
6240: $currsec = $currsettings->{'selfenroll_section'};
6241: }
1.237 raeburn 6242: my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum);
6243: my $newsecval;
6244: if ($currsec ne 'none' && $currsec ne '') {
6245: if (!defined($sections_count{$currsec})) {
6246: $newsecval = $currsec;
6247: }
6248: }
1.400 raeburn 6249: if ($noedit{$item}) {
6250: if ($currsec ne '') {
6251: $output .= $currsec;
6252: } else {
6253: $output .= &mt('No specific section');
6254: }
6255: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6256: next;
6257: }
1.237 raeburn 6258: my $sections_select =
1.418 raeburn 6259: &Apache::lonuserutils::course_sections(\%sections_count,'st',$currsec,$disabled);
1.237 raeburn 6260: $output .= '<table class="LC_createuser">'."\n".
6261: '<tr class="LC_section_row">'."\n".
6262: '<td align="center">'.&mt('Existing sections')."\n".
6263: '<br />'.$sections_select.'</td><td align="center">'.
6264: &mt('New section').'<br />'."\n".
1.418 raeburn 6265: '<input type="text" name="newsec" size="15" value="'.$newsecval.'"'.$disabled.' />'."\n".
1.237 raeburn 6266: '<input type="hidden" name="sections" value="" />'."\n".
6267: '</td></tr></table>'."\n";
1.276 raeburn 6268: } elsif ($item eq 'approval') {
1.398 raeburn 6269: my ($currnotified,$currapproval,%appchecked);
6270: my %selfdescs = &Apache::lonuserutils::selfenroll_default_descs();
1.430 raeburn 6271: if (ref($currsettings) eq 'HASH') {
1.398 raeburn 6272: $currnotified = $currsettings->{'selfenroll_notifylist'};
6273: $currapproval = $currsettings->{'selfenroll_approval'};
6274: }
6275: if ($currapproval !~ /^[012]$/) {
6276: $currapproval = 0;
6277: }
1.400 raeburn 6278: if ($noedit{$item}) {
6279: $output .= $selfdescs{'approval'}{$currapproval}.
6280: '<br />'.&mt('(Set by Domain Coordinator)');
6281: next;
6282: }
1.398 raeburn 6283: $appchecked{$currapproval} = ' checked="checked"';
6284: for my $i (0..2) {
6285: $output .= '<label>'.
6286: '<input type="radio" name="selfenroll_approval" value="'.$i.'"'.
1.418 raeburn 6287: $appchecked{$i}.' onclick="toggleNotify();"'.$disabled.' />'.
6288: $selfdescs{'approval'}{$i}.'</label>'.(' 'x2);
1.276 raeburn 6289: }
6290: my %advhash = &Apache::lonnet::get_course_adv_roles($cid,1);
6291: my (@ccs,%notified);
1.322 raeburn 6292: my $ccrole = 'cc';
6293: if ($crstype eq 'Community') {
6294: $ccrole = 'co';
6295: }
6296: if ($advhash{$ccrole}) {
6297: @ccs = split(/,/,$advhash{$ccrole});
1.276 raeburn 6298: }
6299: if ($currnotified) {
6300: foreach my $current (split(/,/,$currnotified)) {
6301: $notified{$current} = 1;
6302: if (!grep(/^\Q$current\E$/,@ccs)) {
6303: push(@ccs,$current);
6304: }
6305: }
6306: }
6307: if (@ccs) {
1.398 raeburn 6308: my $style;
6309: unless ($currapproval) {
6310: $style = ' style="display: none;"';
6311: }
6312: $output .= '<br /><div id="notified"'.$style.'>'.
6313: &mt('Personnel to be notified when an enrollment request needs approval, or has been approved:').' '.
6314: &Apache::loncommon::start_data_table().
1.276 raeburn 6315: &Apache::loncommon::start_data_table_row();
6316: my $count = 0;
6317: my $numcols = 4;
6318: foreach my $cc (sort(@ccs)) {
6319: my $notifyon;
6320: my ($ccuname,$ccudom) = split(/:/,$cc);
6321: if ($notified{$cc}) {
6322: $notifyon = ' checked="checked" ';
6323: }
6324: if ($count && !$count%$numcols) {
6325: $output .= &Apache::loncommon::end_data_table_row().
6326: &Apache::loncommon::start_data_table_row()
6327: }
6328: $output .= '<td><span class="LC_nobreak"><label>'.
1.418 raeburn 6329: '<input type="checkbox" name="selfenroll_notify"'.$notifyon.' value="'.$cc.'"'.$disabled.' />'.
1.276 raeburn 6330: &Apache::loncommon::plainname($ccuname,$ccudom).
6331: '</label></span></td>';
1.343 raeburn 6332: $count ++;
1.276 raeburn 6333: }
6334: my $rem = $count%$numcols;
6335: if ($rem) {
6336: my $emptycols = $numcols - $rem;
6337: for (my $i=0; $i<$emptycols; $i++) {
6338: $output .= '<td> </td>';
6339: }
6340: }
6341: $output .= &Apache::loncommon::end_data_table_row().
1.398 raeburn 6342: &Apache::loncommon::end_data_table().
6343: '</div>';
1.276 raeburn 6344: }
6345: } elsif ($item eq 'limit') {
1.398 raeburn 6346: my ($crslimit,$selflimit,$nolimit,$currlim,$currcap);
6347: if (ref($currsettings) eq 'HASH') {
6348: $currlim = $currsettings->{'selfenroll_limit'};
6349: $currcap = $currsettings->{'selfenroll_cap'};
6350: }
1.400 raeburn 6351: if ($noedit{$item}) {
6352: if (($currlim eq 'allstudents') || ($currlim eq 'selfenrolled')) {
6353: if ($currlim eq 'allstudents') {
6354: $output .= &mt('Limit by total students');
6355: } elsif ($currlim eq 'selfenrolled') {
6356: $output .= &mt('Limit by total self-enrolled students');
6357: }
6358: $output .= ' '.&mt('Maximum: [_1]',$currcap).
6359: '<br />'.&mt('(Set by Domain Coordinator)');
6360: } else {
6361: $output .= &mt('No limit').'<br />'.&mt('(Set by Domain Coordinator)');
6362: }
6363: next;
6364: }
1.276 raeburn 6365: if ($currlim eq 'allstudents') {
6366: $crslimit = ' checked="checked" ';
6367: $selflimit = ' ';
6368: $nolimit = ' ';
6369: } elsif ($currlim eq 'selfenrolled') {
6370: $crslimit = ' ';
6371: $selflimit = ' checked="checked" ';
6372: $nolimit = ' ';
6373: } else {
6374: $crslimit = ' ';
6375: $selflimit = ' ';
1.398 raeburn 6376: $nolimit = ' checked="checked" ';
1.276 raeburn 6377: }
6378: $output .= '<table><tr><td><label>'.
1.418 raeburn 6379: '<input type="radio" name="selfenroll_limit" value="none"'.$nolimit.$disabled.'/>'.
1.276 raeburn 6380: &mt('No limit').'</label></td><td><label>'.
1.418 raeburn 6381: '<input type="radio" name="selfenroll_limit" value="allstudents"'.$crslimit.$disabled.'/>'.
1.276 raeburn 6382: &mt('Limit by total students').'</label></td><td><label>'.
1.418 raeburn 6383: '<input type="radio" name="selfenroll_limit" value="selfenrolled"'.$selflimit.$disabled.'/>'.
1.276 raeburn 6384: &mt('Limit by total self-enrolled students').
6385: '</td></tr><tr>'.
6386: '<td> </td><td colspan="2"><span class="LC_nobreak">'.
6387: (' 'x3).&mt('Maximum number allowed: ').
1.418 raeburn 6388: '<input type="text" name="selfenroll_cap" size = "5" value="'.$currcap.'"'.$disabled.' /></td></tr></table>';
1.237 raeburn 6389: }
6390: $output .= &Apache::lonhtmlcommon::row_closure(1);
6391: }
6392: }
1.418 raeburn 6393: $output .= &Apache::lonhtmlcommon::end_pick_box().'<br />';
6394: unless ($readonly) {
6395: $output .= '<input type="button" name="selfenrollconf" value="'
6396: .&mt('Save').'" onclick="validate_types(this.form);" />';
6397: }
6398: $output .= '<input type="hidden" name="action" value="selfenroll" />'
6399: .'<input type="hidden" name="state" value="done" />'."\n"
6400: .$additional.'</form>';
1.237 raeburn 6401: $r->print($output);
6402: return;
6403: }
6404:
1.400 raeburn 6405: sub get_noedit_fields {
6406: my ($cdom,$cnum,$crstype,$row) = @_;
6407: my %noedit;
6408: if (ref($row) eq 'ARRAY') {
6409: my %settings = &Apache::lonnet::get('environment',['internal.coursecode','internal.textbook',
6410: 'internal.selfenrollmgrdc',
6411: 'internal.selfenrollmgrcc'],$cdom,$cnum);
6412: my $type = &Apache::lonuserutils::get_extended_type($cdom,$cnum,$crstype,\%settings);
6413: my (%specific_managebydc,%specific_managebycc,%default_managebydc);
6414: map { $specific_managebydc{$_} = 1; } (split(/,/,$settings{'internal.selfenrollmgrdc'}));
6415: map { $specific_managebycc{$_} = 1; } (split(/,/,$settings{'internal.selfenrollmgrcc'}));
6416: my %domdefaults = &Apache::lonnet::get_domain_defaults($cdom);
6417: map { $default_managebydc{$_} = 1; } (split(/,/,$domdefaults{$type.'selfenrolladmdc'}));
6418:
6419: foreach my $item (@{$row}) {
6420: next if ($specific_managebycc{$item});
6421: if (($specific_managebydc{$item}) || ($default_managebydc{$item})) {
6422: $noedit{$item} = 1;
6423: }
6424: }
6425: }
6426: return %noedit;
6427: }
6428:
6429: sub visible_in_stdcat {
6430: my ($cdom,$cnum,$domconf) = @_;
6431: my ($cathash,%settable,@vismsgs,$cansetvis,$visible);
6432: unless (ref($domconf) eq 'HASH') {
6433: return ($visible,$cansetvis,\@vismsgs);
6434: }
6435: if (ref($domconf->{'coursecategories'}) eq 'HASH') {
6436: if ($domconf->{'coursecategories'}{'togglecats'} eq 'crs') {
1.256 raeburn 6437: $settable{'togglecats'} = 1;
6438: }
1.400 raeburn 6439: if ($domconf->{'coursecategories'}{'categorize'} eq 'crs') {
1.256 raeburn 6440: $settable{'categorize'} = 1;
6441: }
1.400 raeburn 6442: $cathash = $domconf->{'coursecategories'}{'cats'};
1.256 raeburn 6443: }
1.260 raeburn 6444: if ($settable{'togglecats'} && $settable{'categorize'}) {
1.256 raeburn 6445: $cansetvis = &mt('You are able to both assign a course category and choose to exclude this course from the catalog.');
6446: } elsif ($settable{'togglecats'}) {
6447: $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 6448: } elsif ($settable{'categorize'}) {
1.256 raeburn 6449: $cansetvis = &mt('You may assign a course category, but only a Domain Coordinator may choose to exclude this course from the catalog.');
6450: } else {
6451: $cansetvis = &mt('Only a Domain Coordinator may assign a course category or choose to exclude this course from the catalog.');
6452: }
6453:
6454: my %currsettings =
6455: &Apache::lonnet::get('environment',['hidefromcat','categories','internal.coursecode'],
6456: $cdom,$cnum);
1.400 raeburn 6457: $visible = 0;
1.256 raeburn 6458: if ($currsettings{'internal.coursecode'} ne '') {
1.400 raeburn 6459: if (ref($domconf->{'coursecategories'}) eq 'HASH') {
6460: $cathash = $domconf->{'coursecategories'}{'cats'};
1.256 raeburn 6461: if (ref($cathash) eq 'HASH') {
6462: if ($cathash->{'instcode::0'} eq '') {
6463: push(@vismsgs,'dc_addinst');
6464: } else {
6465: $visible = 1;
6466: }
6467: } else {
6468: $visible = 1;
6469: }
6470: } else {
6471: $visible = 1;
6472: }
6473: } else {
6474: if (ref($cathash) eq 'HASH') {
6475: if ($cathash->{'instcode::0'} ne '') {
6476: push(@vismsgs,'dc_instcode');
6477: }
6478: } else {
6479: push(@vismsgs,'dc_instcode');
6480: }
6481: }
6482: if ($currsettings{'categories'} ne '') {
6483: my $cathash;
1.400 raeburn 6484: if (ref($domconf->{'coursecategories'}) eq 'HASH') {
6485: $cathash = $domconf->{'coursecategories'}{'cats'};
1.256 raeburn 6486: if (ref($cathash) eq 'HASH') {
6487: if (keys(%{$cathash}) == 0) {
6488: push(@vismsgs,'dc_catalog');
6489: } elsif ((keys(%{$cathash}) == 1) && ($cathash->{'instcode::0'} ne '')) {
6490: push(@vismsgs,'dc_categories');
6491: } else {
6492: my @currcategories = split('&',$currsettings{'categories'});
6493: my $matched = 0;
6494: foreach my $cat (@currcategories) {
6495: if ($cathash->{$cat} ne '') {
6496: $visible = 1;
6497: $matched = 1;
6498: last;
6499: }
6500: }
6501: if (!$matched) {
1.260 raeburn 6502: if ($settable{'categorize'}) {
1.256 raeburn 6503: push(@vismsgs,'chgcat');
6504: } else {
6505: push(@vismsgs,'dc_chgcat');
6506: }
6507: }
6508: }
6509: }
6510: }
6511: } else {
6512: if (ref($cathash) eq 'HASH') {
6513: if ((keys(%{$cathash}) > 1) ||
6514: (keys(%{$cathash}) == 1) && ($cathash->{'instcode::0'} eq '')) {
1.260 raeburn 6515: if ($settable{'categorize'}) {
1.256 raeburn 6516: push(@vismsgs,'addcat');
6517: } else {
6518: push(@vismsgs,'dc_addcat');
6519: }
6520: }
6521: }
6522: }
6523: if ($currsettings{'hidefromcat'} eq 'yes') {
6524: $visible = 0;
6525: if ($settable{'togglecats'}) {
6526: unshift(@vismsgs,'unhide');
6527: } else {
6528: unshift(@vismsgs,'dc_unhide')
6529: }
6530: }
1.400 raeburn 6531: return ($visible,$cansetvis,\@vismsgs);
6532: }
6533:
6534: sub cat_visibility {
6535: my %visactions = &Apache::lonlocal::texthash(
6536: vis => 'This course/community currently appears in the Course/Community Catalog for this domain.',
6537: 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.',
6538: miss => 'This course/community does not currently appear in the Course/Community Catalog for this domain.',
6539: none => 'Display of a course catalog is disabled for this domain.',
6540: yous => 'You should remedy this if you plan to allow self-enrollment, otherwise students will have difficulty finding this course.',
6541: 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.',
6542: make => 'Make any changes to self-enrollment settings below, click "Save", then take action to include the course in the Catalog:',
6543: take => 'Take the following action to ensure the course appears in the Catalog:',
6544: dc_chgconf => 'Ask a domain coordinator to change the Catalog type for this domain.',
6545: dc_setcode => 'Ask a domain coordinator to assign a six character code to the course',
6546: dc_unhide => 'Ask a domain coordinator to change the "Exclude from course catalog" setting.',
6547: dc_addinst => 'Ask a domain coordinator to enable display the catalog of "Official courses (with institutional codes)".',
6548: dc_instcode => 'Ask a domain coordinator to assign an institutional code (if this is an official course).',
6549: dc_catalog => 'Ask a domain coordinator to enable or create at least one course category in the domain.',
6550: dc_categories => 'Ask a domain coordinator to create a hierarchy of categories and sub categories for courses in the domain.',
6551: 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',
6552: dc_addcat => 'Ask a domain coordinator to assign a category to the course.',
6553: );
6554: $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>"');
6555: $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>"');
6556: $visactions{'addcat'} = &mt('Use [_1]Categorize course[_2] to assign a category to the course.','"<a href="/adm/courseprefs?phase=display&actions=courseinfo">','</a>"');
6557: return \%visactions;
1.256 raeburn 6558: }
6559:
1.241 raeburn 6560: sub new_selfenroll_dom_row {
6561: my ($newdom,$num) = @_;
6562: my $domdesc = &Apache::lonnet::domain($newdom);
6563: my $output;
6564: if ($domdesc ne '') {
6565: $output .= &Apache::loncommon::start_data_table_row()
6566: .'<td valign="top"><span class="LC_nobreak">'.&mt('Domain:').' <b>'.$domdesc
6567: .' ('.$newdom.')</b><input type="hidden" name="selfenroll_dom_'.$num
1.249 raeburn 6568: .'" value="'.$newdom.'" /></span><br />'
6569: .'<span class="LC_nobreak"><label><input type="checkbox" '
6570: .'name="selfenroll_activate" value="'.$num.'" '
6571: .'onchange="javascript:update_types('
6572: ."'selfenroll_activate','$num'".');" />'
6573: .&mt('Activate').'</label></span></td>';
1.241 raeburn 6574: my @currinsttypes;
6575: $output .= '<td>'.&mt('User types:').'<br />'
6576: .&selfenroll_inst_types($num,$newdom,\@currinsttypes).'</td>'
6577: .&Apache::loncommon::end_data_table_row();
6578: }
6579: return $output;
6580: }
6581:
6582: sub selfenroll_inst_types {
1.418 raeburn 6583: my ($num,$currdom,$currinsttypes,$readonly) = @_;
1.241 raeburn 6584: my $output;
6585: my $numinrow = 4;
6586: my $count = 0;
6587: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($currdom);
1.247 raeburn 6588: my $othervalue = 'any';
1.418 raeburn 6589: my $disabled;
6590: if ($readonly) {
6591: $disabled = ' disabled="disabled"';
6592: }
1.241 raeburn 6593: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
1.251 raeburn 6594: if (keys(%{$usertypes}) > 0) {
1.247 raeburn 6595: $othervalue = 'other';
6596: }
1.241 raeburn 6597: $output .= '<table><tr>';
6598: foreach my $type (@{$types}) {
6599: if (($count > 0) && ($count%$numinrow == 0)) {
6600: $output .= '</tr><tr>';
6601: }
6602: if (defined($usertypes->{$type})) {
1.257 raeburn 6603: my $esc_type = &escape($type);
1.241 raeburn 6604: $output .= '<td><span class="LC_nobreak"><label><input type = "checkbox" value="'.
1.257 raeburn 6605: $esc_type.'" ';
1.241 raeburn 6606: if (ref($currinsttypes) eq 'ARRAY') {
6607: if (@{$currinsttypes} > 0) {
1.249 raeburn 6608: if (grep(/^any$/,@{$currinsttypes})) {
6609: $output .= 'checked="checked"';
1.257 raeburn 6610: } elsif (grep(/^\Q$esc_type\E$/,@{$currinsttypes})) {
1.241 raeburn 6611: $output .= 'checked="checked"';
6612: }
1.249 raeburn 6613: } else {
6614: $output .= 'checked="checked"';
1.241 raeburn 6615: }
6616: }
1.418 raeburn 6617: $output .= ' name="selfenroll_types_'.$num.'"'.$disabled.' />'.$usertypes->{$type}.'</label></span></td>';
1.241 raeburn 6618: }
6619: $count ++;
6620: }
6621: if (($count > 0) && ($count%$numinrow == 0)) {
6622: $output .= '</tr><tr>';
6623: }
1.249 raeburn 6624: $output .= '<td><span class="LC_nobreak"><label><input type = "checkbox" value="'.$othervalue.'"';
1.241 raeburn 6625: if (ref($currinsttypes) eq 'ARRAY') {
6626: if (@{$currinsttypes} > 0) {
1.249 raeburn 6627: if (grep(/^any$/,@{$currinsttypes})) {
6628: $output .= ' checked="checked"';
6629: } elsif ($othervalue eq 'other') {
6630: if (grep(/^\Q$othervalue\E$/,@{$currinsttypes})) {
6631: $output .= ' checked="checked"';
6632: }
1.241 raeburn 6633: }
1.249 raeburn 6634: } else {
6635: $output .= ' checked="checked"';
1.241 raeburn 6636: }
1.249 raeburn 6637: } else {
6638: $output .= ' checked="checked"';
1.241 raeburn 6639: }
1.418 raeburn 6640: $output .= ' name="selfenroll_types_'.$num.'"'.$disabled.' />'.$othertitle.'</label></span></td></tr></table>';
1.241 raeburn 6641: }
6642: return $output;
6643: }
6644:
1.237 raeburn 6645: sub selfenroll_date_forms {
6646: my ($startform,$endform) = @_;
6647: my $output .= &Apache::lonhtmlcommon::start_pick_box()."\n".
1.244 bisitz 6648: &Apache::lonhtmlcommon::row_title(&mt('Start date'),
1.237 raeburn 6649: 'LC_oddrow_value')."\n".
6650: $startform."\n".
6651: &Apache::lonhtmlcommon::row_closure(1).
1.244 bisitz 6652: &Apache::lonhtmlcommon::row_title(&mt('End date'),
1.237 raeburn 6653: 'LC_oddrow_value')."\n".
6654: $endform."\n".
6655: &Apache::lonhtmlcommon::row_closure(1).
6656: &Apache::lonhtmlcommon::end_pick_box();
6657: return $output;
6658: }
6659:
1.239 raeburn 6660: sub print_userchangelogs_display {
1.415 raeburn 6661: my ($r,$context,$permission,$brcrum) = @_;
1.363 raeburn 6662: my $formname = 'rolelog';
1.418 raeburn 6663: my ($username,$domain,$crstype,$viewablesec,%roleslog);
1.363 raeburn 6664: if ($context eq 'domain') {
6665: $domain = $env{'request.role.domain'};
6666: %roleslog=&Apache::lonnet::dump_dom('nohist_rolelog',$domain);
6667: } else {
6668: if ($context eq 'course') {
6669: $domain = $env{'course.'.$env{'request.course.id'}.'.domain'};
6670: $username = $env{'course.'.$env{'request.course.id'}.'.num'};
6671: $crstype = &Apache::loncommon::course_type();
1.418 raeburn 6672: $viewablesec = &Apache::lonuserutils::viewable_section($permission);
1.363 raeburn 6673: my %saveable_parameters = ('show' => 'scalar',);
6674: &Apache::loncommon::store_course_settings('roles_log',
6675: \%saveable_parameters);
6676: &Apache::loncommon::restore_course_settings('roles_log',
6677: \%saveable_parameters);
6678: } elsif ($context eq 'author') {
6679: $domain = $env{'user.domain'};
6680: if ($env{'request.role'} =~ m{^au\./\Q$domain\E/$}) {
6681: $username = $env{'user.name'};
6682: } else {
6683: undef($domain);
6684: }
6685: }
6686: if ($domain ne '' && $username ne '') {
6687: %roleslog=&Apache::lonnet::dump('nohist_rolelog',$domain,$username);
6688: }
6689: }
1.239 raeburn 6690: if ((keys(%roleslog))[0]=~/^error\:/) { undef(%roleslog); }
6691:
1.415 raeburn 6692: my $helpitem;
6693: if ($context eq 'course') {
6694: $helpitem = 'Course_User_Logs';
1.439 raeburn 6695: } elsif ($context eq 'domain') {
6696: $helpitem = 'Domain_Role_Logs';
6697: } elsif ($context eq 'author') {
6698: $helpitem = 'Author_User_Logs';
1.415 raeburn 6699: }
6700: push (@{$brcrum},
6701: {href => '/adm/createuser?action=changelogs',
6702: text => 'User Management Logs',
6703: help => $helpitem});
6704: my $bread_crumbs_component = 'User Changes';
6705: my $args = { bread_crumbs => $brcrum,
6706: bread_crumbs_component => $bread_crumbs_component};
6707:
6708: # Create navigation javascript
6709: my $jsnav = &userlogdisplay_js($formname);
6710:
6711: my $jscript = (<<ENDSCRIPT);
6712: <script type="text/javascript">
6713: // <![CDATA[
6714: $jsnav
6715: // ]]>
6716: </script>
6717: ENDSCRIPT
6718:
6719: # print page header
6720: $r->print(&header($jscript,$args));
6721:
1.239 raeburn 6722: # set defaults
6723: my $now = time();
6724: my $defstart = $now - (7*24*3600); #7 days ago
6725: my %defaults = (
6726: page => '1',
6727: show => '10',
6728: role => 'any',
6729: chgcontext => 'any',
6730: rolelog_start_date => $defstart,
6731: rolelog_end_date => $now,
6732: );
6733: my $more_records = 0;
6734:
6735: # set current
6736: my %curr;
6737: foreach my $item ('show','page','role','chgcontext') {
6738: $curr{$item} = $env{'form.'.$item};
6739: }
6740: my ($startdate,$enddate) =
6741: &Apache::lonuserutils::get_dates_from_form('rolelog_start_date','rolelog_end_date');
6742: $curr{'rolelog_start_date'} = $startdate;
6743: $curr{'rolelog_end_date'} = $enddate;
6744: foreach my $key (keys(%defaults)) {
6745: if ($curr{$key} eq '') {
6746: $curr{$key} = $defaults{$key};
6747: }
6748: }
1.248 raeburn 6749: my (%whodunit,%changed,$version);
6750: ($version) = ($r->dir_config('lonVersion') =~ /^([\d\.]+)\-/);
1.239 raeburn 6751: my ($minshown,$maxshown);
1.255 raeburn 6752: $minshown = 1;
1.239 raeburn 6753: my $count = 0;
1.415 raeburn 6754: if ($curr{'show'} =~ /\D/) {
6755: $curr{'page'} = 1;
6756: } else {
1.239 raeburn 6757: $maxshown = $curr{'page'} * $curr{'show'};
6758: if ($curr{'page'} > 1) {
6759: $minshown = 1 + ($curr{'page'} - 1) * $curr{'show'};
6760: }
6761: }
1.301 bisitz 6762:
1.327 raeburn 6763: # Form Header
6764: $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">'.
1.363 raeburn 6765: &role_display_filter($context,$formname,$domain,$username,\%curr,
6766: $version,$crstype));
1.327 raeburn 6767:
6768: my $showntableheader = 0;
6769:
6770: # Table Header
6771: my $tableheader =
6772: &Apache::loncommon::start_data_table_header_row()
6773: .'<th> </th>'
6774: .'<th>'.&mt('When').'</th>'
6775: .'<th>'.&mt('Who made the change').'</th>'
6776: .'<th>'.&mt('Changed User').'</th>'
1.363 raeburn 6777: .'<th>'.&mt('Role').'</th>';
6778:
6779: if ($context eq 'course') {
6780: $tableheader .= '<th>'.&mt('Section').'</th>';
6781: }
6782: $tableheader .=
6783: '<th>'.&mt('Context').'</th>'
1.327 raeburn 6784: .'<th>'.&mt('Start').'</th>'
6785: .'<th>'.&mt('End').'</th>'
6786: .&Apache::loncommon::end_data_table_header_row();
6787:
6788: # Display user change log data
1.239 raeburn 6789: foreach my $id (sort { $roleslog{$b}{'exe_time'}<=>$roleslog{$a}{'exe_time'} } (keys(%roleslog))) {
6790: next if (($roleslog{$id}{'exe_time'} < $curr{'rolelog_start_date'}) ||
6791: ($roleslog{$id}{'exe_time'} > $curr{'rolelog_end_date'}));
1.415 raeburn 6792: if ($curr{'show'} !~ /\D/) {
1.239 raeburn 6793: if ($count >= $curr{'page'} * $curr{'show'}) {
6794: $more_records = 1;
6795: last;
6796: }
6797: }
6798: if ($curr{'role'} ne 'any') {
6799: next if ($roleslog{$id}{'logentry'}{'role'} ne $curr{'role'});
6800: }
6801: if ($curr{'chgcontext'} ne 'any') {
6802: if ($curr{'chgcontext'} eq 'selfenroll') {
6803: next if (!$roleslog{$id}{'logentry'}{'selfenroll'});
6804: } else {
6805: next if ($roleslog{$id}{'logentry'}{'context'} ne $curr{'chgcontext'});
6806: }
6807: }
1.418 raeburn 6808: if (($context eq 'course') && ($viewablesec ne '')) {
1.430 raeburn 6809: next if ($roleslog{$id}{'logentry'}{'section'} ne $viewablesec);
1.418 raeburn 6810: }
1.239 raeburn 6811: $count ++;
6812: next if ($count < $minshown);
1.327 raeburn 6813: unless ($showntableheader) {
1.415 raeburn 6814: $r->print(&Apache::loncommon::start_data_table()
1.327 raeburn 6815: .$tableheader);
6816: $r->rflush();
6817: $showntableheader = 1;
6818: }
1.239 raeburn 6819: if ($whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}} eq '') {
6820: $whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}} =
6821: &Apache::loncommon::plainname($roleslog{$id}{'exe_uname'},$roleslog{$id}{'exe_udom'});
6822: }
6823: if ($changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}} eq '') {
6824: $changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}} =
6825: &Apache::loncommon::plainname($roleslog{$id}{'uname'},$roleslog{$id}{'udom'});
6826: }
6827: my $sec = $roleslog{$id}{'logentry'}{'section'};
6828: if ($sec eq '') {
6829: $sec = &mt('None');
6830: }
6831: my ($rolestart,$roleend);
6832: if ($roleslog{$id}{'delflag'}) {
6833: $rolestart = &mt('deleted');
6834: $roleend = &mt('deleted');
6835: } else {
6836: $rolestart = $roleslog{$id}{'logentry'}{'start'};
6837: $roleend = $roleslog{$id}{'logentry'}{'end'};
6838: if ($rolestart eq '' || $rolestart == 0) {
6839: $rolestart = &mt('No start date');
6840: } else {
6841: $rolestart = &Apache::lonlocal::locallocaltime($rolestart);
6842: }
6843: if ($roleend eq '' || $roleend == 0) {
6844: $roleend = &mt('No end date');
6845: } else {
6846: $roleend = &Apache::lonlocal::locallocaltime($roleend);
6847: }
6848: }
6849: my $chgcontext = $roleslog{$id}{'logentry'}{'context'};
6850: if ($roleslog{$id}{'logentry'}{'selfenroll'}) {
6851: $chgcontext = 'selfenroll';
6852: }
1.363 raeburn 6853: my %lt = &rolechg_contexts($context,$crstype);
1.239 raeburn 6854: if ($chgcontext ne '' && $lt{$chgcontext} ne '') {
6855: $chgcontext = $lt{$chgcontext};
6856: }
1.327 raeburn 6857: $r->print(
1.301 bisitz 6858: &Apache::loncommon::start_data_table_row()
6859: .'<td>'.$count.'</td>'
6860: .'<td>'.&Apache::lonlocal::locallocaltime($roleslog{$id}{'exe_time'}).'</td>'
6861: .'<td>'.$whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}}.'</td>'
6862: .'<td>'.$changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}}.'</td>'
1.363 raeburn 6863: .'<td>'.&Apache::lonnet::plaintext($roleslog{$id}{'logentry'}{'role'},$crstype).'</td>');
6864: if ($context eq 'course') {
6865: $r->print('<td>'.$sec.'</td>');
6866: }
6867: $r->print(
6868: '<td>'.$chgcontext.'</td>'
1.301 bisitz 6869: .'<td>'.$rolestart.'</td>'
6870: .'<td>'.$roleend.'</td>'
1.327 raeburn 6871: .&Apache::loncommon::end_data_table_row()."\n");
1.301 bisitz 6872: }
6873:
1.327 raeburn 6874: if ($showntableheader) { # Table footer, if content displayed above
1.415 raeburn 6875: $r->print(&Apache::loncommon::end_data_table().
6876: &userlogdisplay_navlinks(\%curr,$more_records));
1.327 raeburn 6877: } else { # No content displayed above
1.301 bisitz 6878: $r->print('<p class="LC_info">'
6879: .&mt('There are no records to display.')
6880: .'</p>'
6881: );
1.239 raeburn 6882: }
1.301 bisitz 6883:
1.327 raeburn 6884: # Form Footer
6885: $r->print(
6886: '<input type="hidden" name="page" value="'.$curr{'page'}.'" />'
6887: .'<input type="hidden" name="action" value="changelogs" />'
6888: .'</form>');
6889: return;
6890: }
1.301 bisitz 6891:
1.416 raeburn 6892: sub print_useraccesslogs_display {
6893: my ($r,$uname,$udom,$permission,$brcrum) = @_;
6894: my $formname = 'accesslog';
6895: my $form = 'document.accesslog';
6896:
6897: # set breadcrumbs
1.422 raeburn 6898: my %breadcrumb_text = &singleuser_breadcrumb('','domain',$udom);
1.431 raeburn 6899: my $prevphasestr;
6900: if ($env{'form.popup'}) {
6901: $brcrum = [];
6902: } else {
6903: push (@{$brcrum},
6904: {href => "javascript:backPage($form)",
6905: text => $breadcrumb_text{'search'}});
6906: my @prevphases;
6907: if ($env{'form.prevphases'}) {
6908: @prevphases = split(/,/,$env{'form.prevphases'});
6909: $prevphasestr = $env{'form.prevphases'};
6910: }
6911: if (($env{'form.phase'} eq 'userpicked') || (grep(/^userpicked$/,@prevphases))) {
6912: push(@{$brcrum},
6913: {href => "javascript:backPage($form,'get_user_info','select')",
6914: text => $breadcrumb_text{'userpicked'}});
6915: if ($env{'form.phase'} eq 'userpicked') {
6916: $prevphasestr = 'userpicked';
6917: }
1.416 raeburn 6918: }
6919: }
6920: push(@{$brcrum},
6921: {href => '/adm/createuser?action=accesslogs',
6922: text => 'User access logs',
1.424 raeburn 6923: help => 'Domain_User_Access_Logs'});
1.416 raeburn 6924: my $bread_crumbs_component = 'User Access Logs';
6925: my $args = { bread_crumbs => $brcrum,
6926: bread_crumbs_component => 'User Management'};
1.423 raeburn 6927: if ($env{'form.popup'}) {
6928: $args->{'no_nav_bar'} = 1;
1.431 raeburn 6929: $args->{'bread_crumbs_nomenu'} = 1;
1.423 raeburn 6930: }
1.416 raeburn 6931:
1.417 raeburn 6932: # set javascript
1.416 raeburn 6933: my ($jsback,$elements) = &crumb_utilities();
6934: my $jsnav = &userlogdisplay_js($formname);
6935:
6936: my $jscript = (<<ENDSCRIPT);
6937: <script type="text/javascript">
6938: // <![CDATA[
6939:
6940: $jsback
6941: $jsnav
6942:
6943: // ]]>
6944: </script>
6945:
6946: ENDSCRIPT
6947:
1.417 raeburn 6948: # print page header
1.416 raeburn 6949: $r->print(&header($jscript,$args));
6950:
6951: # early out unless log data can be displayed.
6952: unless ($permission->{'activity'}) {
6953: $r->print('<p class="LC_warning">'
6954: .&mt('You do not have rights to display user access logs.')
1.431 raeburn 6955: .'</p>');
6956: if ($env{'form.popup'}) {
6957: $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a></p>');
6958: } else {
6959: $r->print(&earlyout_accesslog_form($formname,$prevphasestr,$udom));
6960: }
1.416 raeburn 6961: return;
6962: }
6963:
6964: unless ($udom eq $env{'request.role.domain'}) {
6965: $r->print('<p class="LC_warning">'
6966: .&mt("User's domain must match role's domain")
6967: .'</p>'
6968: .&earlyout_accesslog_form($formname,$prevphasestr,$udom));
1.417 raeburn 6969: return;
1.416 raeburn 6970: }
6971:
6972: if (($uname eq '') || ($udom eq '')) {
6973: $r->print('<p class="LC_warning">'
6974: .&mt('Invalid username or domain')
6975: .'</p>'
6976: .&earlyout_accesslog_form($formname,$prevphasestr,$udom));
6977: return;
6978: }
6979:
1.437 raeburn 6980: if (&Apache::lonnet::privileged($uname,$udom,
6981: [$env{'request.role.domain'}],['dc','su'])) {
6982: unless (&Apache::lonnet::privileged($env{'user.name'},$env{'user.domain'},
6983: [$env{'request.role.domain'}],['dc','su'])) {
6984: $r->print('<p class="LC_warning">'
6985: .&mt('You need to be a privileged user to display user access logs for [_1]',
6986: &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),
6987: $uname,$udom))
6988: .'</p>');
6989: if ($env{'form.popup'}) {
6990: $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a></p>');
6991: } else {
6992: $r->print(&earlyout_accesslog_form($formname,$prevphasestr,$udom));
6993: }
6994: return;
6995: }
6996: }
6997:
1.416 raeburn 6998: # set defaults
6999: my $now = time();
7000: my $defstart = $now - (7*24*3600);
7001: my %defaults = (
7002: page => '1',
7003: show => '10',
7004: activity => 'any',
7005: accesslog_start_date => $defstart,
7006: accesslog_end_date => $now,
7007: );
7008: my $more_records = 0;
7009:
7010: # set current
7011: my %curr;
7012: foreach my $item ('show','page','activity') {
7013: $curr{$item} = $env{'form.'.$item};
7014: }
7015: my ($startdate,$enddate) =
7016: &Apache::lonuserutils::get_dates_from_form('accesslog_start_date','accesslog_end_date');
7017: $curr{'accesslog_start_date'} = $startdate;
7018: $curr{'accesslog_end_date'} = $enddate;
7019: foreach my $key (keys(%defaults)) {
7020: if ($curr{$key} eq '') {
7021: $curr{$key} = $defaults{$key};
7022: }
7023: }
7024: my ($minshown,$maxshown);
7025: $minshown = 1;
7026: my $count = 0;
7027: if ($curr{'show'} =~ /\D/) {
7028: $curr{'page'} = 1;
7029: } else {
7030: $maxshown = $curr{'page'} * $curr{'show'};
7031: if ($curr{'page'} > 1) {
7032: $minshown = 1 + ($curr{'page'} - 1) * $curr{'show'};
7033: }
7034: }
7035:
7036: # form header
7037: $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">'.
7038: &activity_display_filter($formname,\%curr));
7039:
7040: my $showntableheader = 0;
7041: my ($nav_script,$nav_links);
7042:
7043: # table header
1.431 raeburn 7044: my $tableheader = '<h3>'.
7045: &mt('User access logs for: [_1]',
7046: &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),$uname,$udom)).'</h3>'
7047: .&Apache::loncommon::start_data_table_header_row()
1.416 raeburn 7048: .'<th> </th>'
7049: .'<th>'.&mt('When').'</th>'
7050: .'<th>'.&mt('HostID').'</th>'
7051: .'<th>'.&mt('Event').'</th>'
7052: .'<th>'.&mt('Other data').'</th>'
7053: .&Apache::loncommon::end_data_table_header_row();
7054:
7055: my %filters=(
7056: start => $curr{'accesslog_start_date'},
7057: end => $curr{'accesslog_end_date'},
7058: action => $curr{'activity'},
7059: );
7060:
7061: my $reply = &Apache::lonnet::userlog_query($uname,$udom,%filters);
7062: unless ( ($reply =~/^timeout/) || ($reply =~/^error/) ) {
7063: my (%courses,%missing);
7064: my @results = split(/\&/,$reply);
7065: foreach my $item (reverse(@results)) {
7066: my ($timestamp,$host,$event) = split(/:/,$item);
7067: next unless ($event =~ /^(Log|Role)/);
7068: if ($curr{'show'} !~ /\D/) {
7069: if ($count >= $curr{'page'} * $curr{'show'}) {
7070: $more_records = 1;
7071: last;
7072: }
7073: }
7074: $count ++;
7075: next if ($count < $minshown);
7076: unless ($showntableheader) {
7077: $r->print($nav_script
7078: .&Apache::loncommon::start_data_table()
7079: .$tableheader);
7080: $r->rflush();
7081: $showntableheader = 1;
7082: }
1.418 raeburn 7083: my ($shown,$extra);
1.437 raeburn 7084: my ($event,$data) = split(/\s+/,&unescape($event),2);
1.416 raeburn 7085: if ($event eq 'Role') {
7086: my ($rolecode,$extent) = split(/\./,$data,2);
7087: next if ($extent eq '');
7088: my ($crstype,$desc,$info);
1.418 raeburn 7089: if ($extent =~ m{^/($match_domain)/($match_courseid)(?:/(\w+)|)$}) {
7090: my ($cdom,$cnum,$sec) = ($1,$2,$3);
1.416 raeburn 7091: my $cid = $cdom.'_'.$cnum;
7092: if (exists($courses{$cid})) {
7093: $crstype = $courses{$cid}{'type'};
7094: $desc = $courses{$cid}{'description'};
7095: } elsif ($missing{$cid}) {
7096: $crstype = 'Course';
7097: $desc = 'Course/Community';
7098: } else {
7099: my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',$cnum,undef,undef,'.');
7100: if (ref($crsinfo{$cdom.'_'.$cnum}) eq 'HASH') {
7101: $courses{$cid} = $crsinfo{$cid};
7102: $crstype = $crsinfo{$cid}{'type'};
7103: $desc = $crsinfo{$cid}{'description'};
7104: } else {
7105: $missing{$cid} = 1;
7106: }
7107: }
7108: $extra = &mt($crstype).': <a href="/public/'.$cdom.'/'.$cnum.'/syllabus">'.$desc.'</a>';
1.418 raeburn 7109: if ($sec ne '') {
7110: $extra .= ' ('.&mt('Section: [_1]',$sec).')';
7111: }
1.416 raeburn 7112: } elsif ($extent =~ m{^/($match_domain)/($match_username|$)}) {
7113: my ($dom,$name) = ($1,$2);
7114: if ($rolecode eq 'au') {
7115: $extra = '';
7116: } elsif ($rolecode =~ /^(ca|aa)$/) {
1.417 raeburn 7117: $extra = &mt('Authoring Space: [_1]',$name.':'.$dom);
1.416 raeburn 7118: } elsif ($rolecode =~ /^(li|dg|dh|dc|sc)$/) {
7119: $extra = &mt('Domain: [_1]',$dom);
7120: }
7121: }
7122: my $rolename;
7123: if ($rolecode =~ m{^cr/($match_domain)/($match_username)/(\w+)}) {
7124: my $role = $3;
1.417 raeburn 7125: my $owner = "($2:$1)";
1.416 raeburn 7126: if ($2 eq $1.'-domainconfig') {
7127: $owner = '(ad hoc)';
1.417 raeburn 7128: }
1.416 raeburn 7129: $rolename = &mt('Custom role: [_1]',$role.' '.$owner);
7130: } else {
7131: $rolename = &Apache::lonnet::plaintext($rolecode,$crstype);
7132: }
7133: $shown = &mt('Role selection: [_1]',$rolename);
7134: } else {
7135: $shown = &mt($event);
1.437 raeburn 7136: if ($data =~ /^webdav/) {
7137: my ($path,$clientip) = split(/\s+/,$data,2);
7138: $path =~ s/^webdav//;
7139: if ($clientip ne '') {
7140: $extra = &mt('Client IP address: [_1]',$clientip);
7141: }
7142: if ($path ne '') {
7143: $shown .= ' '.&mt('(WebDAV access to [_1])',$path);
7144: }
7145: } elsif ($data ne '') {
7146: $extra = &mt('Client IP address: [_1]',$data);
1.416 raeburn 7147: }
7148: }
7149: $r->print(
7150: &Apache::loncommon::start_data_table_row()
7151: .'<td>'.$count.'</td>'
7152: .'<td>'.&Apache::lonlocal::locallocaltime($timestamp).'</td>'
7153: .'<td>'.$host.'</td>'
7154: .'<td>'.$shown.'</td>'
7155: .'<td>'.$extra.'</td>'
7156: .&Apache::loncommon::end_data_table_row()."\n");
7157: }
7158: }
7159:
7160: if ($showntableheader) { # Table footer, if content displayed above
7161: $r->print(&Apache::loncommon::end_data_table().
7162: &userlogdisplay_navlinks(\%curr,$more_records));
7163: } else { # No content displayed above
7164: $r->print('<p class="LC_info">'
7165: .&mt('There are no records to display.')
7166: .'</p>');
7167: }
7168:
1.423 raeburn 7169: if ($env{'form.popup'} == 1) {
7170: $r->print('<input type="hidden" name="popup" value="1" />'."\n");
7171: }
7172:
1.416 raeburn 7173: # Form Footer
7174: $r->print(
7175: '<input type="hidden" name="currstate" value="" />'
7176: .'<input type="hidden" name="accessuname" value="'.$uname.'" />'
7177: .'<input type="hidden" name="accessudom" value="'.$udom.'" />'
7178: .'<input type="hidden" name="page" value="'.$curr{'page'}.'" />'
7179: .'<input type="hidden" name="prevphases" value="'.$prevphasestr.'" />'
7180: .'<input type="hidden" name="phase" value="activity" />'
7181: .'<input type="hidden" name="action" value="accesslogs" />'
7182: .'<input type="hidden" name="srchdomain" value="'.$udom.'" />'
7183: .'<input type="hidden" name="srchby" value="'.$env{'form.srchby'}.'" />'
7184: .'<input type="hidden" name="srchtype" value="'.$env{'form.srchtype'}.'" />'
7185: .'<input type="hidden" name="srchterm" value="'.&HTML::Entities::encode($env{'form.srchterm'},'<>"&').'" />'
7186: .'<input type="hidden" name="srchin" value="'.$env{'form.srchin'}.'" />'
7187: .'</form>');
7188: return;
7189: }
7190:
7191: sub earlyout_accesslog_form {
7192: my ($formname,$prevphasestr,$udom) = @_;
7193: my $srchterm = &HTML::Entities::encode($env{'form.srchterm'},'<>"&');
7194: return <<"END";
7195: <form action="/adm/createuser" method="post" name="$formname">
7196: <input type="hidden" name="currstate" value="" />
7197: <input type="hidden" name="prevphases" value="$prevphasestr" />
7198: <input type="hidden" name="phase" value="activity" />
7199: <input type="hidden" name="action" value="accesslogs" />
7200: <input type="hidden" name="srchdomain" value="$udom" />
7201: <input type="hidden" name="srchby" value="$env{'form.srchby'}" />
7202: <input type="hidden" name="srchtype" value="$env{'form.srchtype'}" />
7203: <input type="hidden" name="srchterm" value="$srchterm" />
7204: <input type="hidden" name="srchin" value="$env{'form.srchin'}" />
7205: </form>
7206: END
7207: }
7208:
7209: sub activity_display_filter {
7210: my ($formname,$curr) = @_;
7211: my $nolink = 1;
7212: my $output = '<table><tr><td valign="top">'.
7213: '<span class="LC_nobreak"><b>'.&mt('Actions/page:').'</b></span><br />'.
7214: &Apache::lonmeta::selectbox('show',$curr->{'show'},undef,
7215: (&mt('all'),5,10,20,50,100,1000,10000)).
7216: '</td><td> </td>';
7217: my $startform =
7218: &Apache::lonhtmlcommon::date_setter($formname,'accesslog_start_date',
7219: $curr->{'accesslog_start_date'},undef,
7220: undef,undef,undef,undef,undef,undef,$nolink);
7221: my $endform =
7222: &Apache::lonhtmlcommon::date_setter($formname,'accesslog_end_date',
7223: $curr->{'accesslog_end_date'},undef,
7224: undef,undef,undef,undef,undef,undef,$nolink);
7225: my %lt = &Apache::lonlocal::texthash (
7226: activity => 'Activity',
7227: Role => 'Role selection',
7228: log => 'Log-in or Logout',
7229: );
7230: $output .= '<td valign="top"><b>'.&mt('Window during which actions occurred:').'</b><br />'.
7231: '<table><tr><td>'.&mt('After:').
7232: '</td><td>'.$startform.'</td></tr>'.
7233: '<tr><td>'.&mt('Before:').'</td>'.
7234: '<td>'.$endform.'</td></tr></table>'.
7235: '</td>'.
7236: '<td> </td>'.
7237: '<td valign="top"><b>'.&mt('Activities').'</b><br />'.
7238: '<select name="activity"><option value="any"';
7239: if ($curr->{'activity'} eq 'any') {
7240: $output .= ' selected="selected"';
7241: }
7242: $output .= '>'.&mt('Any').'</option>'."\n";
7243: foreach my $activity ('Role','log') {
7244: my $selstr = '';
7245: if ($activity eq $curr->{'activity'}) {
7246: $selstr = ' selected="selected"';
7247: }
7248: $output .= '<option value="'.$activity.'"'.$selstr.'>'.$lt{$activity}.'</option>';
7249: }
7250: $output .= '</select></td>'.
7251: '</tr></table>';
7252: # Update Display button
7253: $output .= '<p>'
7254: .'<input type="submit" value="'.&mt('Update Display').'" />'
1.431 raeburn 7255: .'</p><hr />';
1.416 raeburn 7256: return $output;
7257: }
7258:
1.415 raeburn 7259: sub userlogdisplay_js {
7260: my ($formname) = @_;
7261: return <<"ENDSCRIPT";
7262:
1.239 raeburn 7263: function chgPage(caller) {
7264: if (caller == 'previous') {
7265: document.$formname.page.value --;
7266: }
7267: if (caller == 'next') {
7268: document.$formname.page.value ++;
7269: }
1.327 raeburn 7270: document.$formname.submit();
1.239 raeburn 7271: return;
7272: }
7273: ENDSCRIPT
1.415 raeburn 7274: }
7275:
7276: sub userlogdisplay_navlinks {
7277: my ($curr,$more_records) = @_;
7278: return unless(ref($curr) eq 'HASH');
7279: # Navigation Buttons
7280: my $nav_links = '<p>';
7281: if (($curr->{'page'} > 1) || ($more_records)) {
7282: if (($curr->{'page'} > 1) && ($curr->{'show'} !~ /\D/)) {
7283: $nav_links .= '<input type="button"'
7284: .' onclick="javascript:chgPage('."'previous'".');"'
7285: .' value="'.&mt('Previous [_1] changes',$curr->{'show'})
7286: .'" /> ';
7287: }
7288: if ($more_records) {
7289: $nav_links .= '<input type="button"'
7290: .' onclick="javascript:chgPage('."'next'".');"'
7291: .' value="'.&mt('Next [_1] changes',$curr->{'show'})
7292: .'" />';
1.301 bisitz 7293: }
7294: }
1.415 raeburn 7295: $nav_links .= '</p>';
7296: return $nav_links;
1.239 raeburn 7297: }
7298:
7299: sub role_display_filter {
1.363 raeburn 7300: my ($context,$formname,$cdom,$cnum,$curr,$version,$crstype) = @_;
7301: my $lctype;
7302: if ($context eq 'course') {
7303: $lctype = lc($crstype);
7304: }
1.239 raeburn 7305: my $nolink = 1;
7306: my $output = '<table><tr><td valign="top">'.
1.301 bisitz 7307: '<span class="LC_nobreak"><b>'.&mt('Changes/page:').'</b></span><br />'.
1.239 raeburn 7308: &Apache::lonmeta::selectbox('show',$curr->{'show'},undef,
7309: (&mt('all'),5,10,20,50,100,1000,10000)).
7310: '</td><td> </td>';
7311: my $startform =
7312: &Apache::lonhtmlcommon::date_setter($formname,'rolelog_start_date',
7313: $curr->{'rolelog_start_date'},undef,
7314: undef,undef,undef,undef,undef,undef,$nolink);
7315: my $endform =
7316: &Apache::lonhtmlcommon::date_setter($formname,'rolelog_end_date',
7317: $curr->{'rolelog_end_date'},undef,
7318: undef,undef,undef,undef,undef,undef,$nolink);
1.363 raeburn 7319: my %lt = &rolechg_contexts($context,$crstype);
1.301 bisitz 7320: $output .= '<td valign="top"><b>'.&mt('Window during which changes occurred:').'</b><br />'.
7321: '<table><tr><td>'.&mt('After:').
7322: '</td><td>'.$startform.'</td></tr>'.
7323: '<tr><td>'.&mt('Before:').'</td>'.
7324: '<td>'.$endform.'</td></tr></table>'.
7325: '</td>'.
7326: '<td> </td>'.
1.239 raeburn 7327: '<td valign="top"><b>'.&mt('Role:').'</b><br />'.
7328: '<select name="role"><option value="any"';
7329: if ($curr->{'role'} eq 'any') {
7330: $output .= ' selected="selected"';
7331: }
7332: $output .= '>'.&mt('Any').'</option>'."\n";
1.363 raeburn 7333: my @roles = &Apache::lonuserutils::roles_by_context($context,1,$crstype);
1.239 raeburn 7334: foreach my $role (@roles) {
7335: my $plrole;
7336: if ($role eq 'cr') {
7337: $plrole = &mt('Custom Role');
7338: } else {
1.318 raeburn 7339: $plrole=&Apache::lonnet::plaintext($role,$crstype);
1.239 raeburn 7340: }
7341: my $selstr = '';
7342: if ($role eq $curr->{'role'}) {
7343: $selstr = ' selected="selected"';
7344: }
7345: $output .= ' <option value="'.$role.'"'.$selstr.'>'.$plrole.'</option>';
7346: }
1.301 bisitz 7347: $output .= '</select></td>'.
7348: '<td> </td>'.
7349: '<td valign="top"><b>'.
1.239 raeburn 7350: &mt('Context:').'</b><br /><select name="chgcontext">';
1.363 raeburn 7351: my @posscontexts;
7352: if ($context eq 'course') {
1.376 raeburn 7353: @posscontexts = ('any','automated','updatenow','createcourse','course','domain','selfenroll','requestcourses');
1.363 raeburn 7354: } elsif ($context eq 'domain') {
7355: @posscontexts = ('any','domain','requestauthor','domconfig','server');
7356: } else {
7357: @posscontexts = ('any','author','domain');
7358: }
7359: foreach my $chgtype (@posscontexts) {
1.239 raeburn 7360: my $selstr = '';
7361: if ($curr->{'chgcontext'} eq $chgtype) {
1.301 bisitz 7362: $selstr = ' selected="selected"';
1.239 raeburn 7363: }
1.363 raeburn 7364: if ($context eq 'course') {
1.376 raeburn 7365: if (($chgtype eq 'automated') || ($chgtype eq 'updatenow')) {
1.363 raeburn 7366: next if (!&Apache::lonnet::auto_run($cnum,$cdom));
7367: }
1.239 raeburn 7368: }
7369: $output .= '<option value="'.$chgtype.'"'.$selstr.'>'.$lt{$chgtype}.'</option>'."\n";
1.248 raeburn 7370: }
1.303 bisitz 7371: $output .= '</select></td>'
7372: .'</tr></table>';
7373:
7374: # Update Display button
7375: $output .= '<p>'
7376: .'<input type="submit" value="'.&mt('Update Display').'" />'
7377: .'</p>';
7378:
7379: # Server version info
1.363 raeburn 7380: my $needsrev = '2.11.0';
7381: if ($context eq 'course') {
7382: $needsrev = '2.7.0';
7383: }
7384:
1.303 bisitz 7385: $output .= '<p class="LC_info">'
7386: .&mt('Only changes made from servers running LON-CAPA [_1] or later are displayed.'
1.363 raeburn 7387: ,$needsrev);
1.248 raeburn 7388: if ($version) {
1.303 bisitz 7389: $output .= ' '.&mt('This LON-CAPA server is version [_1]',$version);
7390: }
7391: $output .= '</p><hr />';
1.239 raeburn 7392: return $output;
7393: }
7394:
7395: sub rolechg_contexts {
1.363 raeburn 7396: my ($context,$crstype) = @_;
7397: my %lt;
7398: if ($context eq 'course') {
7399: %lt = &Apache::lonlocal::texthash (
1.239 raeburn 7400: any => 'Any',
1.376 raeburn 7401: automated => 'Automated Enrollment',
1.239 raeburn 7402: updatenow => 'Roster Update',
7403: createcourse => 'Course Creation',
7404: course => 'User Management in course',
7405: domain => 'User Management in domain',
1.313 raeburn 7406: selfenroll => 'Self-enrolled',
1.318 raeburn 7407: requestcourses => 'Course Request',
1.239 raeburn 7408: );
1.363 raeburn 7409: if ($crstype eq 'Community') {
7410: $lt{'createcourse'} = &mt('Community Creation');
7411: $lt{'course'} = &mt('User Management in community');
7412: $lt{'requestcourses'} = &mt('Community Request');
7413: }
7414: } elsif ($context eq 'domain') {
7415: %lt = &Apache::lonlocal::texthash (
7416: any => 'Any',
7417: domain => 'User Management in domain',
7418: requestauthor => 'Authoring Request',
7419: server => 'Command line script (DC role)',
7420: domconfig => 'Self-enrolled',
7421: );
7422: } else {
7423: %lt = &Apache::lonlocal::texthash (
7424: any => 'Any',
7425: domain => 'User Management in domain',
7426: author => 'User Management by author',
7427: );
7428: }
1.239 raeburn 7429: return %lt;
7430: }
7431:
1.428 raeburn 7432: sub print_helpdeskaccess_display {
7433: my ($r,$permission,$brcrum) = @_;
7434: my $formname = 'helpdeskaccess';
7435: my $helpitem = 'Course_Helpdesk_Access';
7436: push (@{$brcrum},
7437: {href => '/adm/createuser?action=helpdesk',
7438: text => 'Helpdesk Access',
7439: help => $helpitem});
7440: my $bread_crumbs_component = 'Helpdesk Staff Access';
7441: my $args = { bread_crumbs => $brcrum,
7442: bread_crumbs_component => $bread_crumbs_component};
7443:
7444: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
7445: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
7446: my $confname = $cdom.'-domainconfig';
7447: my $crstype = &Apache::loncommon::course_type();
7448:
1.434 raeburn 7449: my @accesstypes = ('all','dh','da','none');
1.428 raeburn 7450: my ($numstatustypes,@jsarray);
7451: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($cdom);
7452: if (ref($types) eq 'ARRAY') {
1.430 raeburn 7453: if (@{$types} > 0) {
1.428 raeburn 7454: $numstatustypes = scalar(@{$types});
7455: push(@accesstypes,'status');
7456: @jsarray = ('bystatus');
7457: }
7458: }
7459: my %customroles = &get_domain_customroles($cdom,$confname);
1.432 raeburn 7460: my %domhelpdesk = &Apache::lonnet::get_active_domroles($cdom,['dh','da']);
1.428 raeburn 7461: if (keys(%domhelpdesk)) {
7462: push(@accesstypes,('inc','exc'));
7463: push(@jsarray,('notinc','notexc'));
7464: }
7465: push(@jsarray,'privs');
7466: my $hiddenstr = join("','",@jsarray);
7467: my $rolestr = join("','",sort(keys(%customroles)));
7468:
7469: my $jscript;
7470: my (%settings,%overridden);
7471: if (keys(%customroles)) {
7472: &get_adhocrole_settings($env{'request.course.id'},\@accesstypes,
7473: $types,\%customroles,\%settings,\%overridden);
7474: my %jsfull=();
7475: my %jslevels= (
7476: course => {},
7477: domain => {},
7478: system => {},
7479: );
7480: my %jslevelscurrent=(
7481: course => {},
7482: domain => {},
7483: system => {},
7484: );
7485: my (%privs,%jsprivs);
7486: &Apache::lonuserutils::custom_role_privs(\%privs,\%jsfull,\%jslevels,\%jslevelscurrent);
7487: foreach my $priv (keys(%jsfull)) {
7488: if ($jslevels{'course'}{$priv}) {
7489: $jsprivs{$priv} = 1;
7490: }
7491: }
7492: my (%elements,%stored);
7493: foreach my $role (keys(%customroles)) {
7494: $elements{$role.'_access'} = 'radio';
7495: $elements{$role.'_incrs'} = 'radio';
7496: if ($numstatustypes) {
7497: $elements{$role.'_status'} = 'checkbox';
7498: }
7499: if (keys(%domhelpdesk) > 0) {
7500: $elements{$role.'_staff_inc'} = 'checkbox';
7501: $elements{$role.'_staff_exc'} = 'checkbox';
7502: }
1.430 raeburn 7503: $elements{$role.'_override'} = 'checkbox';
1.428 raeburn 7504: if (ref($settings{$role}) eq 'HASH') {
7505: if ($settings{$role}{'access'} ne '') {
7506: my $curraccess = $settings{$role}{'access'};
7507: $stored{$role.'_access'} = $curraccess;
7508: $stored{$role.'_incrs'} = 1;
7509: if ($curraccess eq 'status') {
7510: if (ref($settings{$role}{'status'}) eq 'ARRAY') {
7511: $stored{$role.'_status'} = $settings{$role}{'status'};
7512: }
7513: } elsif (($curraccess eq 'exc') || ($curraccess eq 'inc')) {
7514: if (ref($settings{$role}{$curraccess}) eq 'ARRAY') {
7515: $stored{$role.'_staff_'.$curraccess} = $settings{$role}{$curraccess};
7516: }
7517: }
7518: } else {
7519: $stored{$role.'_incrs'} = 0;
7520: }
7521: $stored{$role.'_override'} = [];
7522: if ($env{'course.'.$env{'request.course.id'}.'.internal.adhocpriv.'.$role}) {
7523: if (ref($settings{$role}{'off'}) eq 'ARRAY') {
7524: foreach my $priv (@{$settings{$role}{'off'}}) {
7525: push(@{$stored{$role.'_override'}},$priv);
7526: }
7527: }
7528: if (ref($settings{$role}{'on'}) eq 'ARRAY') {
7529: foreach my $priv (@{$settings{$role}{'on'}}) {
7530: unless (grep(/^$priv$/,@{$stored{$role.'_override'}})) {
7531: push(@{$stored{$role.'_override'}},$priv);
7532: }
7533: }
7534: }
7535: }
7536: } else {
7537: $stored{$role.'_incrs'} = 0;
7538: }
7539: }
7540: $jscript = &Apache::lonhtmlcommon::set_form_elements(\%elements,\%stored);
7541: }
7542:
7543: my $js = <<"ENDJS";
7544: <script type="text/javascript">
7545: // <![CDATA[
7546: $jscript;
7547:
7548: function switchRoleTab(caller,role) {
7549: if (document.getElementById(role+'_maindiv')) {
7550: if (caller.id != 'LC_current_minitab') {
7551: if (document.getElementById('LC_current_minitab')) {
7552: document.getElementById('LC_current_minitab').id=null;
7553: }
7554: var roledivs = Array('$rolestr');
7555: if (roledivs.length > 0) {
7556: for (var i=0; i<roledivs.length; i++) {
7557: if (document.getElementById(roledivs[i]+'_maindiv')) {
7558: document.getElementById(roledivs[i]+'_maindiv').style.display='none';
7559: }
7560: }
7561: }
7562: caller.id = 'LC_current_minitab';
7563: document.getElementById(role+'_maindiv').style.display='block';
7564: }
7565: }
7566: return false;
1.430 raeburn 7567: }
1.428 raeburn 7568:
7569: function helpdeskAccess(role) {
7570: var curraccess = null;
7571: if (document.$formname.elements[role+'_access'].length) {
7572: for (var i=0; i<document.$formname.elements[role+'_access'].length; i++) {
7573: if (document.$formname.elements[role+'_access'][i].checked) {
7574: curraccess = document.$formname.elements[role+'_access'][i].value;
7575: }
7576: }
7577: }
7578: var shown = Array();
7579: var hidden = Array();
7580: if (curraccess == 'none') {
1.430 raeburn 7581: hidden = Array ('$hiddenstr');
1.428 raeburn 7582: } else {
7583: if (curraccess == 'status') {
1.430 raeburn 7584: shown = Array ('bystatus','privs');
7585: hidden = Array ('notinc','notexc');
1.428 raeburn 7586: } else {
7587: if (curraccess == 'exc') {
7588: shown = Array ('notexc','privs');
7589: hidden = Array ('notinc','bystatus');
7590: }
7591: if (curraccess == 'inc') {
7592: shown = Array ('notinc','privs');
7593: hidden = Array ('notexc','bystatus');
7594: }
7595: if (curraccess == 'all') {
7596: shown = Array ('privs');
7597: hidden = Array ('notinc','notexc','bystatus');
7598: }
7599: }
7600: }
7601: if (hidden.length > 0) {
7602: for (var i=0; i<hidden.length; i++) {
7603: if (document.getElementById(role+'_'+hidden[i])) {
1.430 raeburn 7604: document.getElementById(role+'_'+hidden[i]).style.display = 'none';
1.428 raeburn 7605: }
7606: }
7607: }
7608: if (shown.length > 0) {
7609: for (var i=0; i<shown.length; i++) {
7610: if (document.getElementById(role+'_'+shown[i])) {
7611: if (shown[i] == 'privs') {
7612: document.getElementById(role+'_'+shown[i]).style.display = 'block';
7613: } else {
7614: document.getElementById(role+'_'+shown[i]).style.display = 'inline';
7615: }
7616: }
7617: }
7618: }
7619: return;
7620: }
7621:
7622: function toggleAccess(role) {
7623: if ((document.getElementById(role+'_setincrs')) &&
7624: (document.getElementById(role+'_setindom'))) {
7625: for (var i=0; i<document.$formname.elements[role+'_incrs'].length; i++) {
7626: if (document.$formname.elements[role+'_incrs'][i].checked) {
7627: if (document.$formname.elements[role+'_incrs'][i].value == 1) {
7628: document.getElementById(role+'_setindom').style.display = 'none';
1.430 raeburn 7629: document.getElementById(role+'_setincrs').style.display = 'block';
1.428 raeburn 7630: } else {
7631: document.getElementById(role+'_setincrs').style.display = 'none';
7632: document.getElementById(role+'_setindom').style.display = 'block';
7633: }
7634: break;
7635: }
7636: }
7637: }
7638: return;
7639: }
7640:
7641: // ]]>
7642: </script>
7643: ENDJS
7644:
7645: $args->{add_entries} = {onload => "javascript:setFormElements(document.$formname)"};
7646:
7647: # print page header
7648: $r->print(&header($js,$args));
7649: # print form header
7650: $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">');
7651:
7652: if (keys(%customroles)) {
7653: my %lt = &Apache::lonlocal::texthash(
7654: 'aco' => 'As course owner you may override the defaults set in the domain for role usage and/or privileges.',
7655: 'rou' => 'Role usage',
7656: 'whi' => 'Which helpdesk personnel may use this role?',
7657: 'udd' => 'Use domain default',
1.433 raeburn 7658: 'all' => 'All with domain helpdesk or helpdesk assistant role',
1.434 raeburn 7659: 'dh' => 'All with domain helpdesk role',
7660: 'da' => 'All with domain helpdesk assistant role',
1.428 raeburn 7661: 'none' => 'None',
7662: 'status' => 'Determined based on institutional status',
1.430 raeburn 7663: 'inc' => 'Include all, but exclude specific personnel',
1.428 raeburn 7664: 'exc' => 'Exclude all, but include specific personnel',
7665: 'hel' => 'Helpdesk',
7666: 'rpr' => 'Role privileges',
7667: );
7668: $lt{'tfh'} = &mt("Custom [_1]ad hoc[_2] course roles available for use by the domain's helpdesk are as follows",'<i>','</i>');
7669: my %domconfig = &Apache::lonnet::get_dom('configuration',['helpsettings'],$cdom);
7670: my (%domcurrent,%ordered,%description,%domusage,$disabled);
7671: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
7672: if (ref($domconfig{'helpsettings'}{'adhoc'}) eq 'HASH') {
7673: %domcurrent = %{$domconfig{'helpsettings'}{'adhoc'}};
7674: }
7675: }
7676: my $count = 0;
7677: foreach my $role (sort(keys(%customroles))) {
7678: my ($order,$desc,$access_in_dom);
7679: if (ref($domcurrent{$role}) eq 'HASH') {
7680: $order = $domcurrent{$role}{'order'};
7681: $desc = $domcurrent{$role}{'desc'};
7682: $access_in_dom = $domcurrent{$role}{'access'};
7683: }
7684: if ($order eq '') {
7685: $order = $count;
7686: }
7687: $ordered{$order} = $role;
7688: if ($desc ne '') {
7689: $description{$role} = $desc;
7690: } else {
7691: $description{$role}= $role;
7692: }
7693: $count++;
7694: }
7695: %domusage = &domain_adhoc_access(\%customroles,\%domcurrent,\@accesstypes,$usertypes,$othertitle);
7696: my @roles_by_num = ();
7697: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
7698: push(@roles_by_num,$ordered{$item});
1.430 raeburn 7699: }
1.429 raeburn 7700: $r->print('<p>'.$lt{'tfh'}.': <i>'.join('</i>, <i>',map { $description{$_}; } @roles_by_num).'</i>.');
1.428 raeburn 7701: if ($permission->{'owner'}) {
7702: $r->print('<br />'.$lt{'aco'}.'</p><p>');
7703: $r->print('<input type="hidden" name="state" value="process" />'.
7704: '<input type="submit" value="'.&mt('Save changes').'" />');
7705: } else {
7706: if ($env{'course.'.$env{'request.course.id'}.'.internal.courseowner'}) {
7707: my ($ownername,$ownerdom) = split(/:/,$env{'course.'.$env{'request.course.id'}.'.internal.courseowner'});
7708: $r->print('<br />'.&mt('The course owner -- [_1] -- can override the default access and/or privileges for these ad hoc roles.',
7709: &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($ownername,$ownerdom),$ownername,$ownerdom)));
7710: }
7711: $disabled = ' disabled="disabled"';
7712: }
7713: $r->print('</p>');
7714:
7715: $r->print('<div id="LC_minitab_header"><ul>');
7716: my $count = 0;
7717: my %visibility;
7718: foreach my $role (@roles_by_num) {
7719: my $id;
7720: if ($count == 0) {
7721: $id=' id="LC_current_minitab"';
1.430 raeburn 7722: $visibility{$role} = ' style="display:block"';
1.428 raeburn 7723: } else {
7724: $visibility{$role} = ' style="display:none"';
7725: }
7726: $count ++;
7727: $r->print('<li'.$id.'><a href="#" onclick="javascript:switchRoleTab(this.parentNode,'."'$role'".');">'.$description{$role}.'</a></li>');
7728: }
7729: $r->print('</ul></div>');
7730:
7731: foreach my $role (@roles_by_num) {
7732: my %usecheck = (
7733: all => ' checked="checked"',
7734: );
7735: my %displaydiv = (
7736: status => 'none',
7737: inc => 'none',
7738: exc => 'none',
7739: priv => 'block',
7740: );
7741: my (%selected,$overridden,$incrscheck,$indomcheck,$indomvis,$incrsvis);
1.430 raeburn 7742: if (ref($settings{$role}) eq 'HASH') {
1.428 raeburn 7743: if ($settings{$role}{'access'} ne '') {
7744: $indomvis = ' style="display:none"';
7745: $incrsvis = ' style="display:block"';
1.430 raeburn 7746: $incrscheck = ' checked="checked"';
1.428 raeburn 7747: if ($settings{$role}{'access'} ne 'all') {
7748: $usecheck{$settings{$role}{'access'}} = $usecheck{'all'};
7749: delete($usecheck{'all'});
7750: if ($settings{$role}{'access'} eq 'status') {
7751: my $access = 'status';
7752: $displaydiv{$access} = 'inline';
7753: if (ref($settings{$role}{$access}) eq 'ARRAY') {
7754: $selected{$access} = $settings{$role}{$access};
7755: }
7756: } elsif ($settings{$role}{'access'} =~ /^(inc|exc)$/) {
7757: my $access = $1;
7758: $displaydiv{$access} = 'inline';
7759: if (ref($settings{$role}{$access}) eq 'ARRAY') {
7760: $selected{$access} = $settings{$role}{$access};
7761: }
7762: } elsif ($settings{$role}{'access'} eq 'none') {
7763: $displaydiv{'priv'} = 'none';
7764: }
7765: }
7766: } else {
7767: $indomcheck = ' checked="checked"';
7768: $indomvis = ' style="display:block"';
7769: $incrsvis = ' style="display:none"';
7770: }
7771: } else {
7772: $indomcheck = ' checked="checked"';
1.430 raeburn 7773: $indomvis = ' style="display:block"';
1.428 raeburn 7774: $incrsvis = ' style="display:none"';
7775: }
7776: $r->print('<div class="LC_left_float" id="'.$role.'_maindiv"'.$visibility{$role}.'>'.
7777: '<fieldset><legend>'.$lt{'rou'}.'</legend>'.
7778: '<p>'.$lt{'whi'}.' <span class="LC_nobreak">'.
7779: '<label><input type="radio" name="'.$role.'_incrs" value="1"'.$incrscheck.' onclick="toggleAccess('."'$role'".');"'.$disabled.'>'.
7780: &mt('Set here in [_1]',lc($crstype)).'</label>'.
7781: '<span>'.(' 'x2).
7782: '<label><input type="radio" name="'.$role.'_incrs" value="0"'.$indomcheck.' onclick="toggleAccess('."'$role'".');"'.$disabled.'>'.
7783: $lt{'udd'}.'</label><span></p>'.
7784: '<div id="'.$role.'_setindom"'.$indomvis.'>'.
7785: '<span class="LC_cusr_emph">'.$domusage{$role}.'</span></div>'.
7786: '<div id="'.$role.'_setincrs"'.$incrsvis.'>');
7787: foreach my $access (@accesstypes) {
7788: $r->print('<p><label><input type="radio" name="'.$role.'_access" value="'.$access.'" '.$usecheck{$access}.
7789: ' onclick="helpdeskAccess('."'$role'".');"'.$disabled.' />'.$lt{$access}.'</label>');
7790: if ($access eq 'status') {
7791: $r->print('<div id="'.$role.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
7792: &Apache::lonuserutils::adhoc_status_types($cdom,undef,$role,$selected{$access},
7793: $othertitle,$usertypes,$types,$disabled).
7794: '</div>');
7795: } elsif (($access eq 'inc') && (keys(%domhelpdesk) > 0)) {
7796: $r->print('<div id="'.$role.'_notinc" style="display:'.$displaydiv{$access}.'">'.
7797: &Apache::lonuserutils::adhoc_staff($access,undef,$role,$selected{$access},
7798: \%domhelpdesk,$disabled).
7799: '</div>');
7800: } elsif (($access eq 'exc') && (keys(%domhelpdesk) > 0)) {
7801: $r->print('<div id="'.$role.'_notexc" style="display:'.$displaydiv{$access}.'">'.
7802: &Apache::lonuserutils::adhoc_staff($access,undef,$role,$selected{$access},
7803: \%domhelpdesk,$disabled).
7804: '</div>');
7805: }
7806: $r->print('</p>');
7807: }
7808: $r->print('</div></fieldset>');
7809: my %full=();
7810: my %levels= (
7811: course => {},
7812: domain => {},
7813: system => {},
7814: );
7815: my %levelscurrent=(
7816: course => {},
7817: domain => {},
7818: system => {},
7819: );
7820: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
7821: $r->print('<fieldset id="'.$role.'_privs" style="display:'.$displaydiv{'priv'}.'">'.
7822: '<legend>'.$lt{'rpr'}.'</legend>'.
7823: &role_priv_table($role,$permission,$crstype,\%full,\%levels,\%levelscurrent,$overridden{$role}).
7824: '</fieldset></div><div style="padding:0;clear:both;margin:0;border:0"></div>');
7825: }
1.429 raeburn 7826: if ($permission->{'owner'}) {
7827: $r->print('<p><input type="submit" value="'.&mt('Save changes').'" /></p>');
7828: }
1.428 raeburn 7829: } else {
7830: $r->print(&mt('Helpdesk roles have not yet been created in this domain.'));
7831: }
7832: # Form Footer
7833: $r->print('<input type="hidden" name="action" value="helpdesk" />'
7834: .'</form>');
7835: return;
7836: }
7837:
7838: sub domain_adhoc_access {
7839: my ($roles,$domcurrent,$accesstypes,$usertypes,$othertitle) = @_;
7840: my %domusage;
7841: return unless ((ref($roles) eq 'HASH') && (ref($domcurrent) eq 'HASH') && (ref($accesstypes) eq 'ARRAY'));
7842: foreach my $role (keys(%{$roles})) {
7843: if (ref($domcurrent->{$role}) eq 'HASH') {
7844: my $access = $domcurrent->{$role}{'access'};
7845: if (($access eq '') || (!grep(/^\Q$access\E$/,@{$accesstypes}))) {
7846: $access = 'all';
1.432 raeburn 7847: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role',&Apache::lonnet::plaintext('dh'),
7848: &Apache::lonnet::plaintext('da'));
1.428 raeburn 7849: } elsif ($access eq 'status') {
7850: if (ref($domcurrent->{$role}{$access}) eq 'ARRAY') {
7851: my @shown;
7852: foreach my $type (@{$domcurrent->{$role}{$access}}) {
7853: unless ($type eq 'default') {
7854: if ($usertypes->{$type}) {
7855: push(@shown,$usertypes->{$type});
7856: }
7857: }
7858: }
7859: if (grep(/^default$/,@{$domcurrent->{$role}{$access}})) {
7860: push(@shown,$othertitle);
7861: }
7862: if (@shown) {
7863: my $shownstatus = join(' '.&mt('or').' ',@shown);
1.432 raeburn 7864: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role, and institutional status: [_3]',
7865: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'),$shownstatus);
1.428 raeburn 7866: } else {
7867: $domusage{$role} = &mt('No one in the domain');
7868: }
7869: }
7870: } elsif ($access eq 'inc') {
7871: my @dominc = ();
7872: if (ref($domcurrent->{$role}{'inc'}) eq 'ARRAY') {
7873: foreach my $user (@{$domcurrent->{$role}{'inc'}}) {
7874: my ($uname,$udom) = split(/:/,$user);
7875: push(@dominc,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),$uname,$udom));
7876: }
7877: my $showninc = join(', ',@dominc);
7878: if ($showninc ne '') {
1.432 raeburn 7879: $domusage{$role} = &mt('Include any user in domain with active [_1] or [_2] role, except: [_3]',
7880: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'),$showninc);
1.428 raeburn 7881: } else {
1.432 raeburn 7882: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role',
7883: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'));
1.428 raeburn 7884: }
7885: }
7886: } elsif ($access eq 'exc') {
7887: my @domexc = ();
7888: if (ref($domcurrent->{$role}{'exc'}) eq 'ARRAY') {
7889: foreach my $user (@{$domcurrent->{$role}{'exc'}}) {
7890: my ($uname,$udom) = split(/:/,$user);
7891: push(@domexc,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),$uname,$udom));
7892: }
7893: }
7894: my $shownexc = join(', ',@domexc);
7895: if ($shownexc ne '') {
1.432 raeburn 7896: $domusage{$role} = &mt('Only the following in the domain with active [_1] or [_2] role: [_3]',
7897: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'),$shownexc);
1.428 raeburn 7898: } else {
7899: $domusage{$role} = &mt('No one in the domain');
7900: }
7901: } elsif ($access eq 'none') {
7902: $domusage{$role} = &mt('No one in the domain');
1.434 raeburn 7903: } elsif ($access eq 'dh') {
1.433 raeburn 7904: $domusage{$role} = &mt('Any user in domain with active [_1] role',&Apache::lonnet::plaintext('dh'));
1.434 raeburn 7905: } elsif ($access eq 'da') {
1.433 raeburn 7906: $domusage{$role} = &mt('Any user in domain with active [_1] role',&Apache::lonnet::plaintext('da'));
1.428 raeburn 7907: } elsif ($access eq 'all') {
1.432 raeburn 7908: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role',
7909: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'));
1.428 raeburn 7910: }
7911: } else {
1.432 raeburn 7912: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role',
7913: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'));
1.428 raeburn 7914: }
7915: }
7916: return %domusage;
7917: }
7918:
7919: sub get_domain_customroles {
7920: my ($cdom,$confname) = @_;
7921: my %existing=&Apache::lonnet::dump('roles',$cdom,$confname,'rolesdef_');
7922: my %customroles;
7923: foreach my $key (keys(%existing)) {
7924: if ($key=~/^rolesdef\_(\w+)$/) {
7925: my $rolename = $1;
7926: my %privs;
7927: ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
7928: $customroles{$rolename} = \%privs;
7929: }
7930: }
7931: return %customroles;
7932: }
7933:
7934: sub role_priv_table {
7935: my ($role,$permission,$crstype,$full,$levels,$levelscurrent,$overridden) = @_;
7936: return unless ((ref($full) eq 'HASH') && (ref($levels) eq 'HASH') &&
7937: (ref($levelscurrent) eq 'HASH'));
7938: my %lt=&Apache::lonlocal::texthash (
7939: 'crl' => 'Course Level Privilege',
7940: 'def' => 'Domain Defaults',
7941: 'ove' => 'Override in Course',
7942: 'ine' => 'In effect',
7943: 'dis' => 'Disabled',
7944: 'ena' => 'Enabled',
7945: );
7946: if ($crstype eq 'Community') {
7947: $lt{'ove'} = 'Override in Community',
7948: }
7949: my @status = ('Disabled','Enabled');
7950: my (%on,%off);
7951: if (ref($overridden) eq 'HASH') {
7952: if (ref($overridden->{'on'}) eq 'ARRAY') {
7953: map { $on{$_} = 1; } (@{$overridden->{'on'}});
7954: }
7955: if (ref($overridden->{'off'}) eq 'ARRAY') {
7956: map { $off{$_} = 1; } (@{$overridden->{'off'}});
7957: }
7958: }
7959: my $output=&Apache::loncommon::start_data_table().
7960: &Apache::loncommon::start_data_table_header_row().
7961: '<th>'.$lt{'crl'}.'</th><th>'.$lt{'def'}.'</th><th>'.$lt{'ove'}.
7962: '</th><th>'.$lt{'ine'}.'</th>'.
7963: &Apache::loncommon::end_data_table_header_row();
7964: foreach my $priv (sort(keys(%{$full}))) {
7965: next unless ($levels->{'course'}{$priv});
7966: my $privtext = &Apache::lonnet::plaintext($priv,$crstype);
7967: my ($default,$ineffect);
7968: if ($levelscurrent->{'course'}{$priv}) {
7969: $default = '<img src="/adm/lonIcons/navmap.correct.gif" alt="'.$lt{'ena'}.'" />';
7970: $ineffect = $default;
7971: }
7972: my ($customstatus,$checked);
7973: $output .= &Apache::loncommon::start_data_table_row().
7974: '<td>'.$privtext.'</td>'.
7975: '<td>'.$default.'</td><td>';
7976: if (($levelscurrent->{'course'}{$priv}) && ($off{$priv})) {
7977: if ($permission->{'owner'}) {
7978: $checked = ' checked="checked"';
7979: }
7980: $customstatus = '<img src="/adm/lonIcons/navmap.wrong.gif" alt="'.$lt{'dis'}.'" />';
1.430 raeburn 7981: $ineffect = $customstatus;
1.428 raeburn 7982: } elsif ((!$levelscurrent->{'course'}{$priv}) && ($on{$priv})) {
7983: if ($permission->{'owner'}) {
1.430 raeburn 7984: $checked = ' checked="checked"';
1.428 raeburn 7985: }
7986: $customstatus = '<img src="/adm/lonIcons/navmap.correct.gif" alt="'.$lt{'ena'}.'" />';
1.430 raeburn 7987: $ineffect = $customstatus;
1.428 raeburn 7988: }
7989: if ($permission->{'owner'}) {
7990: $output .= '<input type="checkbox" name="'.$role.'_override" value="'.$priv.'"'.$checked.' />';
7991: } else {
7992: $output .= $customstatus;
7993: }
7994: $output .= '</td><td>'.$ineffect.'</td>'.
7995: &Apache::loncommon::end_data_table_row();
7996: }
7997: $output .= &Apache::loncommon::end_data_table();
7998: return $output;
7999: }
8000:
8001: sub get_adhocrole_settings {
1.430 raeburn 8002: my ($cid,$accesstypes,$types,$customroles,$settings,$overridden) = @_;
1.428 raeburn 8003: return unless ((ref($accesstypes) eq 'ARRAY') && (ref($customroles) eq 'HASH') &&
8004: (ref($settings) eq 'HASH') && (ref($overridden) eq 'HASH'));
8005: foreach my $role (split(/,/,$env{'course.'.$cid.'.internal.adhocaccess'})) {
8006: my ($curraccess,$rest) = split(/=/,$env{'course.'.$cid.'.internal.adhoc.'.$role});
8007: if (($curraccess ne '') && (grep(/^\Q$curraccess\E$/,@{$accesstypes}))) {
8008: $settings->{$role}{'access'} = $curraccess;
8009: if (($curraccess eq 'status') && (ref($types) eq 'ARRAY')) {
8010: my @status = split(/,/,$rest);
8011: my @currstatus;
8012: foreach my $type (@status) {
8013: if ($type eq 'default') {
8014: push(@currstatus,$type);
8015: } elsif (grep(/^\Q$type\E$/,@{$types})) {
8016: push(@currstatus,$type);
8017: }
8018: }
8019: if (@currstatus) {
8020: $settings->{$role}{$curraccess} = \@currstatus;
8021: } elsif (($curraccess eq 'exc') || ($curraccess eq 'inc')) {
8022: my @personnel = split(/,/,$rest);
8023: $settings->{$role}{$curraccess} = \@personnel;
8024: }
8025: }
8026: }
8027: }
8028: foreach my $role (keys(%{$customroles})) {
8029: if ($env{'course.'.$cid.'.internal.adhocpriv.'.$role}) {
8030: my %currentprivs;
8031: if (ref($customroles->{$role}) eq 'HASH') {
8032: if (exists($customroles->{$role}{'course'})) {
8033: my %full=();
8034: my %levels= (
8035: course => {},
8036: domain => {},
8037: system => {},
8038: );
8039: my %levelscurrent=(
8040: course => {},
8041: domain => {},
8042: system => {},
8043: );
8044: &Apache::lonuserutils::custom_role_privs($customroles->{$role},\%full,\%levels,\%levelscurrent);
8045: %currentprivs = %{$levelscurrent{'course'}};
8046: }
8047: }
8048: foreach my $item (split(/,/,$env{'course.'.$cid.'.internal.adhocpriv.'.$role})) {
8049: next if ($item eq '');
8050: my ($rule,$rest) = split(/=/,$item);
8051: next unless (($rule eq 'off') || ($rule eq 'on'));
8052: foreach my $priv (split(/:/,$rest)) {
8053: if ($priv ne '') {
8054: if ($rule eq 'off') {
8055: push(@{$overridden->{$role}{'off'}},$priv);
8056: if ($currentprivs{$priv}) {
8057: push(@{$settings->{$role}{'off'}},$priv);
8058: }
8059: } else {
8060: push(@{$overridden->{$role}{'on'}},$priv);
8061: unless ($currentprivs{$priv}) {
8062: push(@{$settings->{$role}{'on'}},$priv);
8063: }
8064: }
8065: }
8066: }
8067: }
8068: }
8069: }
8070: return;
8071: }
8072:
8073: sub update_helpdeskaccess {
8074: my ($r,$permission,$brcrum) = @_;
8075: my $helpitem = 'Course_Helpdesk_Access';
8076: push (@{$brcrum},
8077: {href => '/adm/createuser?action=helpdesk',
8078: text => 'Helpdesk Access',
8079: help => $helpitem},
8080: {href => '/adm/createuser?action=helpdesk',
8081: text => 'Result',
8082: help => $helpitem}
8083: );
8084: my $bread_crumbs_component = 'Helpdesk Staff Access';
8085: my $args = { bread_crumbs => $brcrum,
8086: bread_crumbs_component => $bread_crumbs_component};
8087:
8088: # print page header
8089: $r->print(&header('',$args));
8090: unless ((ref($permission) eq 'HASH') && ($permission->{'owner'})) {
8091: $r->print('<p class="LC_error">'.&mt('You do not have permission to change helpdesk access.').'</p>');
8092: return;
8093: }
1.434 raeburn 8094: my @accesstypes = ('all','dh','da','none','status','inc','exc');
1.428 raeburn 8095: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
8096: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
8097: my $confname = $cdom.'-domainconfig';
8098: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($cdom);
8099: my $crstype = &Apache::loncommon::course_type();
8100: my %customroles = &get_domain_customroles($cdom,$confname);
8101: my (%settings,%overridden);
8102: &get_adhocrole_settings($env{'request.course.id'},\@accesstypes,
8103: $types,\%customroles,\%settings,\%overridden);
1.432 raeburn 8104: my %domhelpdesk = &Apache::lonnet::get_active_domroles($cdom,['dh','da']);
1.428 raeburn 8105: my (%changed,%storehash,@todelete);
8106:
8107: if (keys(%customroles)) {
8108: my (%newsettings,@incrs);
8109: foreach my $role (keys(%customroles)) {
8110: $newsettings{$role} = {
8111: access => '',
8112: status => '',
8113: exc => '',
8114: inc => '',
8115: on => '',
8116: off => '',
8117: };
8118: my %current;
8119: if (ref($settings{$role}) eq 'HASH') {
8120: %current = %{$settings{$role}};
8121: }
8122: if (ref($overridden{$role}) eq 'HASH') {
8123: $current{'overridden'} = $overridden{$role};
8124: }
8125: if ($env{'form.'.$role.'_incrs'}) {
8126: my $access = $env{'form.'.$role.'_access'};
8127: if (grep(/^\Q$access\E$/,@accesstypes)) {
8128: push(@incrs,$role);
8129: unless ($current{'access'} eq $access) {
8130: $changed{$role}{'access'} = 1;
1.430 raeburn 8131: $storehash{'internal.adhoc.'.$role} = $access;
1.428 raeburn 8132: }
8133: if ($access eq 'status') {
8134: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$role.'_status');
8135: my @stored;
8136: my @shownstatus;
8137: if (ref($types) eq 'ARRAY') {
8138: foreach my $type (sort(@statuses)) {
8139: if ($type eq 'default') {
8140: push(@stored,$type);
8141: } elsif (grep(/^\Q$type\E$/,@{$types})) {
8142: push(@stored,$type);
8143: push(@shownstatus,$usertypes->{$type});
8144: }
8145: }
8146: if (grep(/^default$/,@statuses)) {
8147: push(@shownstatus,$othertitle);
8148: }
8149: $storehash{'internal.adhoc.'.$role} .= '='.join(',',@stored);
8150: }
8151: $newsettings{$role}{'status'} = join(' '.&mt('or').' ',@shownstatus);
8152: if (ref($current{'status'}) eq 'ARRAY') {
8153: my @diffs = &Apache::loncommon::compare_arrays(\@stored,$current{'status'});
8154: if (@diffs) {
8155: $changed{$role}{'status'} = 1;
8156: }
8157: } elsif (@stored) {
8158: $changed{$role}{'status'} = 1;
8159: }
8160: } elsif (($access eq 'inc') || ($access eq 'exc')) {
8161: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$role.'_staff_'.$access);
8162: my @newspecstaff;
8163: my @stored;
8164: my @currstaff;
8165: foreach my $person (sort(@personnel)) {
8166: if ($domhelpdesk{$person}) {
1.430 raeburn 8167: push(@stored,$person);
1.428 raeburn 8168: }
8169: }
8170: if (ref($current{$access}) eq 'ARRAY') {
8171: my @diffs = &Apache::loncommon::compare_arrays(\@stored,$current{$access});
8172: if (@diffs) {
8173: $changed{$role}{$access} = 1;
8174: }
8175: } elsif (@stored) {
8176: $changed{$role}{$access} = 1;
8177: }
8178: $storehash{'internal.adhoc.'.$role} .= '='.join(',',@stored);
8179: foreach my $person (@stored) {
8180: my ($uname,$udom) = split(/:/,$person);
8181: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
8182: }
8183: $newsettings{$role}{$access} = join(', ',sort(@newspecstaff));
8184: }
8185: $newsettings{$role}{'access'} = $access;
8186: }
8187: } else {
8188: if (($current{'access'} ne '') && (grep(/^\Q$current{'access'}\E$/,@accesstypes))) {
8189: $changed{$role}{'access'} = 1;
8190: $newsettings{$role} = {};
8191: push(@todelete,'internal.adhoc.'.$role);
8192: }
8193: }
8194: if (($env{'form.'.$role.'_incrs'}) && ($env{'form.'.$role.'_access'} eq 'none')) {
8195: if (ref($current{'overridden'}) eq 'HASH') {
8196: push(@todelete,'internal.adhocpriv.'.$role);
8197: }
8198: } else {
8199: my %full=();
8200: my %levels= (
8201: course => {},
8202: domain => {},
8203: system => {},
8204: );
8205: my %levelscurrent=(
8206: course => {},
8207: domain => {},
8208: system => {},
8209: );
8210: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
8211: my (@updatedon,@updatedoff,@override);
8212: @override = &Apache::loncommon::get_env_multiple('form.'.$role.'_override');
1.430 raeburn 8213: if (@override) {
1.428 raeburn 8214: foreach my $priv (sort(keys(%full))) {
8215: next unless ($levels{'course'}{$priv});
8216: if (grep(/^\Q$priv\E$/,@override)) {
8217: if ($levelscurrent{'course'}{$priv}) {
8218: push(@updatedoff,$priv);
8219: } else {
8220: push(@updatedon,$priv);
8221: }
8222: }
8223: }
8224: }
8225: if (@updatedon) {
1.430 raeburn 8226: $newsettings{$role}{'on'} = join('</li><li>', map { &Apache::lonnet::plaintext($_,$crstype) } (@updatedon));
1.428 raeburn 8227: }
8228: if (@updatedoff) {
8229: $newsettings{$role}{'off'} = join('</li><li>', map { &Apache::lonnet::plaintext($_,$crstype) } (@updatedoff));
8230: }
8231: if (ref($current{'overridden'}) eq 'HASH') {
8232: if (ref($current{'overridden'}{'on'}) eq 'ARRAY') {
8233: if (@updatedon) {
8234: my @diffs = &Apache::loncommon::compare_arrays(\@updatedon,$current{'overridden'}{'on'});
8235: if (@diffs) {
8236: $changed{$role}{'on'} = 1;
8237: }
8238: } else {
8239: $changed{$role}{'on'} = 1;
8240: }
8241: } elsif (@updatedon) {
8242: $changed{$role}{'on'} = 1;
8243: }
8244: if (ref($current{'overridden'}{'off'}) eq 'ARRAY') {
8245: if (@updatedoff) {
8246: my @diffs = &Apache::loncommon::compare_arrays(\@updatedoff,$current{'overridden'}{'off'});
8247: if (@diffs) {
8248: $changed{$role}{'off'} = 1;
8249: }
8250: } else {
8251: $changed{$role}{'off'} = 1;
8252: }
8253: } elsif (@updatedoff) {
8254: $changed{$role}{'off'} = 1;
8255: }
8256: } else {
8257: if (@updatedon) {
8258: $changed{$role}{'on'} = 1;
8259: }
8260: if (@updatedoff) {
8261: $changed{$role}{'off'} = 1;
8262: }
8263: }
8264: if (ref($changed{$role}) eq 'HASH') {
8265: if (($changed{$role}{'on'} || $changed{$role}{'off'})) {
8266: my $newpriv;
8267: if (@updatedon) {
8268: $newpriv = 'on='.join(':',@updatedon);
8269: }
8270: if (@updatedoff) {
8271: $newpriv .= ($newpriv ? ',' : '' ).'off='.join(':',@updatedoff);
8272: }
8273: if ($newpriv eq '') {
8274: push(@todelete,'internal.adhocpriv.'.$role);
8275: } else {
8276: $storehash{'internal.adhocpriv.'.$role} = $newpriv;
8277: }
8278: }
8279: }
8280: }
8281: }
8282: if (@incrs) {
8283: $storehash{'internal.adhocaccess'} = join(',',@incrs);
8284: } elsif (@todelete) {
8285: push(@todelete,'internal.adhocaccess');
8286: }
8287: if (keys(%changed)) {
8288: my ($putres,$delres);
8289: if (keys(%storehash)) {
8290: $putres = &Apache::lonnet::put('environment',\%storehash,$cdom,$cnum);
8291: my %newenvhash;
8292: foreach my $key (keys(%storehash)) {
8293: $newenvhash{'course.'.$env{'request.course.id'}.'.'.$key} = $storehash{$key};
8294: }
8295: &Apache::lonnet::appenv(\%newenvhash);
8296: }
8297: if (@todelete) {
8298: $delres = &Apache::lonnet::del('environment',\@todelete,$cdom,$cnum);
8299: foreach my $key (@todelete) {
8300: &Apache::lonnet::delenv('course.'.$env{'request.course.id'}.'.'.$key);
8301: }
8302: }
8303: if (($putres eq 'ok') || ($delres eq 'ok')) {
8304: my %domconfig = &Apache::lonnet::get_dom('configuration',['helpsettings'],$cdom);
8305: my (%domcurrent,%ordered,%description,%domusage);
8306: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
8307: if (ref($domconfig{'helpsettings'}{'adhoc'}) eq 'HASH') {
8308: %domcurrent = %{$domconfig{'helpsettings'}{'adhoc'}};
8309: }
8310: }
8311: my $count = 0;
8312: foreach my $role (sort(keys(%customroles))) {
8313: my ($order,$desc);
8314: if (ref($domcurrent{$role}) eq 'HASH') {
8315: $order = $domcurrent{$role}{'order'};
8316: $desc = $domcurrent{$role}{'desc'};
8317: }
8318: if ($order eq '') {
8319: $order = $count;
8320: }
8321: $ordered{$order} = $role;
8322: if ($desc ne '') {
8323: $description{$role} = $desc;
8324: } else {
8325: $description{$role}= $role;
8326: }
8327: $count++;
8328: }
8329: my @roles_by_num = ();
8330: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
8331: push(@roles_by_num,$ordered{$item});
8332: }
8333: %domusage = &domain_adhoc_access(\%changed,\%domcurrent,\@accesstypes,$usertypes,$othertitle);
1.430 raeburn 8334: $r->print(&mt('Helpdesk access settings have been changed as follows').'<br />');
1.428 raeburn 8335: $r->print('<ul>');
8336: foreach my $role (@roles_by_num) {
8337: next unless (ref($changed{$role}) eq 'HASH');
8338: $r->print('<li>'.&mt('Ad hoc role').': <b>'.$description{$role}.'</b>'.
8339: '<ul>');
1.430 raeburn 8340: if ($changed{$role}{'access'} || $changed{$role}{'status'} || $changed{$role}{'inc'} || $changed{$role}{'exc'}) {
1.428 raeburn 8341: $r->print('<li>');
8342: if ($env{'form.'.$role.'_incrs'}) {
8343: if ($newsettings{$role}{'access'} eq 'all') {
8344: $r->print(&mt('All helpdesk staff can access '.lc($crstype).' with this role.'));
1.434 raeburn 8345: } elsif ($newsettings{$role}{'access'} eq 'dh') {
1.433 raeburn 8346: $r->print(&mt('Helpdesk staff can use this role if they have an active [_1] role',
8347: &Apache::lonnet::plaintext('dh')));
1.434 raeburn 8348: } elsif ($newsettings{$role}{'access'} eq 'da') {
1.433 raeburn 8349: $r->print(&mt('Helpdesk staff can use this role if they have an active [_1] role',
8350: &Apache::lonnet::plaintext('da')));
1.428 raeburn 8351: } elsif ($newsettings{$role}{'access'} eq 'none') {
8352: $r->print(&mt('No helpdesk staff can access '.lc($crstype).' with this role.'));
8353: } elsif ($newsettings{$role}{'access'} eq 'status') {
8354: if ($newsettings{$role}{'status'}) {
8355: my ($access,$rest) = split(/=/,$storehash{'internal.adhoc.'.$role});
1.430 raeburn 8356: if (split(/,/,$rest) > 1) {
1.428 raeburn 8357: $r->print(&mt('Helpdesk staff can use this role if their institutional type is one of: [_1].',
8358: $newsettings{$role}{'status'}));
8359: } else {
8360: $r->print(&mt('Helpdesk staff can use this role if their institutional type is: [_1].',
8361: $newsettings{$role}{'status'}));
8362: }
8363: } else {
8364: $r->print(&mt('No helpdesk staff can access '.lc($crstype).' with this role.'));
8365: }
8366: } elsif ($newsettings{$role}{'access'} eq 'exc') {
8367: if ($newsettings{$role}{'exc'}) {
8368: $r->print(&mt('Helpdesk staff who can use this role are as follows:').' '.$newsettings{$role}{'exc'}.'.');
8369: } else {
8370: $r->print(&mt('No helpdesk staff can access '.lc($crstype).' with this role.'));
8371: }
8372: } elsif ($newsettings{$role}{'access'} eq 'inc') {
8373: if ($newsettings{$role}{'inc'}) {
8374: $r->print(&mt('All helpdesk staff may use this role except the following:').' '.$newsettings{$role}{'inc'}.'.');
8375: } else {
8376: $r->print(&mt('All helpdesk staff may use this role.'));
8377: }
8378: }
8379: } else {
8380: $r->print(&mt('Default access set in the domain now applies.').'<br />'.
8381: '<span class="LC_cusr_emph">'.$domusage{$role}.'</span>');
8382: }
8383: $r->print('</li>');
8384: }
8385: unless ($newsettings{$role}{'access'} eq 'none') {
8386: if ($changed{$role}{'off'}) {
8387: if ($newsettings{$role}{'off'}) {
8388: $r->print('<li>'.&mt('Privileges which are available by default for this ad hoc role, but are disabled for this specific '.lc($crstype).':').
8389: '<ul><li>'.$newsettings{$role}{'off'}.'</li></ul></li>');
8390: } else {
1.430 raeburn 8391: $r->print('<li>'.&mt('All privileges available by default for this ad hoc role are enabled.').'</li>');
1.428 raeburn 8392: }
8393: }
1.430 raeburn 8394: if ($changed{$role}{'on'}) {
1.428 raeburn 8395: if ($newsettings{$role}{'on'}) {
8396: $r->print('<li>'.&mt('Privileges which are not available by default for this ad hoc role, but are enabled for this specific '.lc($crstype).':').
8397: '<ul><li>'.$newsettings{$role}{'on'}.'</li></ul></li>');
8398: } else {
1.430 raeburn 8399: $r->print('<li>'.&mt('None of the privileges unavailable by default for this ad hoc role are enabled.').'</li>');
1.428 raeburn 8400: }
8401: }
8402: }
8403: $r->print('</ul></li>');
8404: }
8405: $r->print('</ul>');
8406: }
8407: } else {
1.430 raeburn 8408: $r->print(&mt('No changes made to helpdesk access settings.'));
1.428 raeburn 8409: }
8410: }
8411: return;
8412: }
8413:
1.27 matthew 8414: #-------------------------------------------------- functions for &phase_two
1.160 raeburn 8415: sub user_search_result {
1.221 raeburn 8416: my ($context,$srch) = @_;
1.160 raeburn 8417: my %allhomes;
8418: my %inst_matches;
8419: my %srch_results;
1.181 raeburn 8420: my ($response,$currstate,$forcenewuser,$dirsrchres);
1.183 raeburn 8421: $srch->{'srchterm'} =~ s/\s+/ /g;
1.176 raeburn 8422: if ($srch->{'srchby'} !~ /^(uname|lastname|lastfirst)$/) {
1.160 raeburn 8423: $response = &mt('Invalid search.');
8424: }
8425: if ($srch->{'srchin'} !~ /^(crs|dom|alc|instd)$/) {
8426: $response = &mt('Invalid search.');
8427: }
1.177 raeburn 8428: if ($srch->{'srchtype'} !~ /^(exact|contains|begins)$/) {
1.160 raeburn 8429: $response = &mt('Invalid search.');
8430: }
8431: if ($srch->{'srchterm'} eq '') {
8432: $response = &mt('You must enter a search term.');
8433: }
1.183 raeburn 8434: if ($srch->{'srchterm'} =~ /^\s+$/) {
8435: $response = &mt('Your search term must contain more than just spaces.');
8436: }
1.160 raeburn 8437: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'instd')) {
8438: if (($srch->{'srchdomain'} eq '') ||
1.163 albertel 8439: ! (&Apache::lonnet::domain($srch->{'srchdomain'}))) {
1.160 raeburn 8440: $response = &mt('You must specify a valid domain when searching in a domain or institutional directory.')
8441: }
8442: }
8443: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs') ||
8444: ($srch->{'srchin'} eq 'alc')) {
1.176 raeburn 8445: if ($srch->{'srchby'} eq 'uname') {
1.243 raeburn 8446: my $unamecheck = $srch->{'srchterm'};
8447: if ($srch->{'srchtype'} eq 'contains') {
8448: if ($unamecheck !~ /^\w/) {
8449: $unamecheck = 'a'.$unamecheck;
8450: }
8451: }
8452: if ($unamecheck !~ /^$match_username$/) {
1.176 raeburn 8453: $response = &mt('You must specify a valid username. Only the following are allowed: letters numbers - . @');
8454: }
1.160 raeburn 8455: }
8456: }
1.180 raeburn 8457: if ($response ne '') {
1.413 raeburn 8458: $response = '<span class="LC_warning">'.$response.'</span><br />';
1.180 raeburn 8459: }
1.160 raeburn 8460: if ($srch->{'srchin'} eq 'instd') {
1.412 raeburn 8461: my $instd_chk = &instdirectorysrch_check($srch);
1.160 raeburn 8462: if ($instd_chk ne 'ok') {
1.412 raeburn 8463: my $domd_chk = &domdirectorysrch_check($srch);
1.413 raeburn 8464: $response .= '<span class="LC_warning">'.$instd_chk.'</span><br />';
1.412 raeburn 8465: if ($domd_chk eq 'ok') {
1.435 raeburn 8466: $response .= &mt('You may want to search in the LON-CAPA domain instead of in the institutional directory.');
1.412 raeburn 8467: }
1.415 raeburn 8468: $response .= '<br />';
1.412 raeburn 8469: }
8470: } else {
1.417 raeburn 8471: unless (($context eq 'requestcrs') && ($srch->{'srchtype'} eq 'exact')) {
1.412 raeburn 8472: my $domd_chk = &domdirectorysrch_check($srch);
1.438 raeburn 8473: if (($domd_chk ne 'ok') && ($env{'form.action'} ne 'accesslogs')) {
1.412 raeburn 8474: my $instd_chk = &instdirectorysrch_check($srch);
1.413 raeburn 8475: $response .= '<span class="LC_warning">'.$domd_chk.'</span><br />';
1.412 raeburn 8476: if ($instd_chk eq 'ok') {
1.435 raeburn 8477: $response .= &mt('You may want to search in the institutional directory instead of in the LON-CAPA domain.');
1.412 raeburn 8478: }
1.415 raeburn 8479: $response .= '<br />';
1.412 raeburn 8480: }
1.160 raeburn 8481: }
8482: }
8483: if ($response ne '') {
1.180 raeburn 8484: return ($currstate,$response);
1.160 raeburn 8485: }
8486: if ($srch->{'srchby'} eq 'uname') {
8487: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs')) {
8488: if ($env{'form.forcenew'}) {
8489: if ($srch->{'srchdomain'} ne $env{'request.role.domain'}) {
8490: my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
8491: if ($uhome eq 'no_host') {
8492: my $domdesc = &Apache::lonnet::domain($env{'request.role.domain'},'description');
1.180 raeburn 8493: my $showdom = &display_domain_info($env{'request.role.domain'});
8494: $response = &mt('New users can only be created in the domain to which your current role belongs - [_1].',$showdom);
1.160 raeburn 8495: } else {
1.179 raeburn 8496: $currstate = 'modify';
1.160 raeburn 8497: }
8498: } else {
1.179 raeburn 8499: $currstate = 'modify';
1.160 raeburn 8500: }
8501: } else {
8502: if ($srch->{'srchin'} eq 'dom') {
1.162 raeburn 8503: if ($srch->{'srchtype'} eq 'exact') {
8504: my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
8505: if ($uhome eq 'no_host') {
1.179 raeburn 8506: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8507: &build_search_response($context,$srch,%srch_results);
1.162 raeburn 8508: } else {
1.179 raeburn 8509: $currstate = 'modify';
1.416 raeburn 8510: if ($env{'form.action'} eq 'accesslogs') {
8511: $currstate = 'activity';
8512: }
1.310 raeburn 8513: my $uname = $srch->{'srchterm'};
8514: my $udom = $srch->{'srchdomain'};
8515: $srch_results{$uname.':'.$udom} =
8516: { &Apache::lonnet::get('environment',
8517: ['firstname',
8518: 'lastname',
8519: 'permanentemail'],
8520: $udom,$uname)
8521: };
1.162 raeburn 8522: }
8523: } else {
8524: %srch_results = &Apache::lonnet::usersearch($srch);
1.179 raeburn 8525: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8526: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 8527: }
8528: } else {
1.167 albertel 8529: my $courseusers = &get_courseusers();
1.162 raeburn 8530: if ($srch->{'srchtype'} eq 'exact') {
1.167 albertel 8531: if (exists($courseusers->{$srch->{'srchterm'}.':'.$srch->{'srchdomain'}})) {
1.179 raeburn 8532: $currstate = 'modify';
1.162 raeburn 8533: } else {
1.179 raeburn 8534: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8535: &build_search_response($context,$srch,%srch_results);
1.162 raeburn 8536: }
1.160 raeburn 8537: } else {
1.167 albertel 8538: foreach my $user (keys(%$courseusers)) {
1.162 raeburn 8539: my ($cuname,$cudomain) = split(/:/,$user);
8540: if ($cudomain eq $srch->{'srchdomain'}) {
1.177 raeburn 8541: my $matched = 0;
8542: if ($srch->{'srchtype'} eq 'begins') {
8543: if ($cuname =~ /^\Q$srch->{'srchterm'}\E/i) {
8544: $matched = 1;
8545: }
8546: } else {
8547: if ($cuname =~ /\Q$srch->{'srchterm'}\E/i) {
8548: $matched = 1;
8549: }
8550: }
8551: if ($matched) {
1.167 albertel 8552: $srch_results{$user} =
8553: {&Apache::lonnet::get('environment',
8554: ['firstname',
8555: 'lastname',
1.194 albertel 8556: 'permanentemail'],
8557: $cudomain,$cuname)};
1.162 raeburn 8558: }
8559: }
8560: }
1.179 raeburn 8561: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8562: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 8563: }
8564: }
8565: }
8566: } elsif ($srch->{'srchin'} eq 'alc') {
1.179 raeburn 8567: $currstate = 'query';
1.160 raeburn 8568: } elsif ($srch->{'srchin'} eq 'instd') {
1.181 raeburn 8569: ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
8570: if ($dirsrchres eq 'ok') {
8571: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8572: &build_search_response($context,$srch,%srch_results);
1.181 raeburn 8573: } else {
8574: my $showdom = &display_domain_info($srch->{'srchdomain'});
8575: $response = '<span class="LC_warning">'.
8576: &mt('Institutional directory search is not available in domain: [_1]',$showdom).
8577: '</span><br />'.
1.435 raeburn 8578: &mt('You may want to search in the LON-CAPA domain instead of in the institutional directory.').
1.415 raeburn 8579: '<br />';
1.181 raeburn 8580: }
1.160 raeburn 8581: }
8582: } else {
8583: if ($srch->{'srchin'} eq 'dom') {
8584: %srch_results = &Apache::lonnet::usersearch($srch);
1.179 raeburn 8585: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8586: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 8587: } elsif ($srch->{'srchin'} eq 'crs') {
1.167 albertel 8588: my $courseusers = &get_courseusers();
8589: foreach my $user (keys(%$courseusers)) {
1.160 raeburn 8590: my ($uname,$udom) = split(/:/,$user);
8591: my %names = &Apache::loncommon::getnames($uname,$udom);
8592: my %emails = &Apache::loncommon::getemails($uname,$udom);
8593: if ($srch->{'srchby'} eq 'lastname') {
8594: if ((($srch->{'srchtype'} eq 'exact') &&
8595: ($names{'lastname'} eq $srch->{'srchterm'})) ||
1.177 raeburn 8596: (($srch->{'srchtype'} eq 'begins') &&
8597: ($names{'lastname'} =~ /^\Q$srch->{'srchterm'}\E/i)) ||
1.160 raeburn 8598: (($srch->{'srchtype'} eq 'contains') &&
8599: ($names{'lastname'} =~ /\Q$srch->{'srchterm'}\E/i))) {
8600: $srch_results{$user} = {firstname => $names{'firstname'},
8601: lastname => $names{'lastname'},
8602: permanentemail => $emails{'permanentemail'},
8603: };
8604: }
8605: } elsif ($srch->{'srchby'} eq 'lastfirst') {
8606: my ($srchlast,$srchfirst) = split(/,/,$srch->{'srchterm'});
1.177 raeburn 8607: $srchlast =~ s/\s+$//;
8608: $srchfirst =~ s/^\s+//;
1.160 raeburn 8609: if ($srch->{'srchtype'} eq 'exact') {
8610: if (($names{'lastname'} eq $srchlast) &&
8611: ($names{'firstname'} eq $srchfirst)) {
8612: $srch_results{$user} = {firstname => $names{'firstname'},
8613: lastname => $names{'lastname'},
8614: permanentemail => $emails{'permanentemail'},
8615:
8616: };
8617: }
1.177 raeburn 8618: } elsif ($srch->{'srchtype'} eq 'begins') {
8619: if (($names{'lastname'} =~ /^\Q$srchlast\E/i) &&
8620: ($names{'firstname'} =~ /^\Q$srchfirst\E/i)) {
8621: $srch_results{$user} = {firstname => $names{'firstname'},
8622: lastname => $names{'lastname'},
8623: permanentemail => $emails{'permanentemail'},
8624: };
8625: }
8626: } else {
1.160 raeburn 8627: if (($names{'lastname'} =~ /\Q$srchlast\E/i) &&
8628: ($names{'firstname'} =~ /\Q$srchfirst\E/i)) {
8629: $srch_results{$user} = {firstname => $names{'firstname'},
8630: lastname => $names{'lastname'},
8631: permanentemail => $emails{'permanentemail'},
8632: };
8633: }
8634: }
8635: }
8636: }
1.179 raeburn 8637: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8638: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 8639: } elsif ($srch->{'srchin'} eq 'alc') {
1.179 raeburn 8640: $currstate = 'query';
1.160 raeburn 8641: } elsif ($srch->{'srchin'} eq 'instd') {
1.181 raeburn 8642: ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
8643: if ($dirsrchres eq 'ok') {
8644: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8645: &build_search_response($context,$srch,%srch_results);
1.181 raeburn 8646: } else {
1.412 raeburn 8647: my $showdom = &display_domain_info($srch->{'srchdomain'});
8648: $response = '<span class="LC_warning">'.
1.181 raeburn 8649: &mt('Institutional directory search is not available in domain: [_1]',$showdom).
8650: '</span><br />'.
1.435 raeburn 8651: &mt('You may want to search in the LON-CAPA domain instead of in the institutional directory.').
1.415 raeburn 8652: '<br />';
1.181 raeburn 8653: }
1.160 raeburn 8654: }
8655: }
1.179 raeburn 8656: return ($currstate,$response,$forcenewuser,\%srch_results);
1.160 raeburn 8657: }
8658:
1.412 raeburn 8659: sub domdirectorysrch_check {
8660: my ($srch) = @_;
8661: my $response;
8662: my %dom_inst_srch = &Apache::lonnet::get_dom('configuration',
8663: ['directorysrch'],$srch->{'srchdomain'});
8664: my $showdom = &display_domain_info($srch->{'srchdomain'});
8665: if (ref($dom_inst_srch{'directorysrch'}) eq 'HASH') {
8666: if ($dom_inst_srch{'directorysrch'}{'lcavailable'} eq '0') {
8667: return &mt('LON-CAPA directory search is not available in domain: [_1]',$showdom);
8668: }
8669: if ($dom_inst_srch{'directorysrch'}{'lclocalonly'}) {
8670: if ($env{'request.role.domain'} ne $srch->{'srchdomain'}) {
8671: return &mt('LON-CAPA directory search in domain: [_1] is only allowed for users with a current role in the domain.',$showdom);
8672: }
8673: }
8674: }
8675: return 'ok';
8676: }
8677:
8678: sub instdirectorysrch_check {
1.160 raeburn 8679: my ($srch) = @_;
8680: my $can_search = 0;
8681: my $response;
8682: my %dom_inst_srch = &Apache::lonnet::get_dom('configuration',
8683: ['directorysrch'],$srch->{'srchdomain'});
1.180 raeburn 8684: my $showdom = &display_domain_info($srch->{'srchdomain'});
1.160 raeburn 8685: if (ref($dom_inst_srch{'directorysrch'}) eq 'HASH') {
8686: if (!$dom_inst_srch{'directorysrch'}{'available'}) {
1.180 raeburn 8687: return &mt('Institutional directory search is not available in domain: [_1]',$showdom);
1.160 raeburn 8688: }
8689: if ($dom_inst_srch{'directorysrch'}{'localonly'}) {
8690: if ($env{'request.role.domain'} ne $srch->{'srchdomain'}) {
1.180 raeburn 8691: return &mt('Institutional directory search in domain: [_1] is only allowed for users with a current role in the domain.',$showdom);
1.160 raeburn 8692: }
8693: my @usertypes = split(/:/,$env{'environment.inststatus'});
8694: if (!@usertypes) {
8695: push(@usertypes,'default');
8696: }
8697: if (ref($dom_inst_srch{'directorysrch'}{'cansearch'}) eq 'ARRAY') {
8698: foreach my $type (@usertypes) {
8699: if (grep(/^\Q$type\E$/,@{$dom_inst_srch{'directorysrch'}{'cansearch'}})) {
8700: $can_search = 1;
8701: last;
8702: }
8703: }
8704: }
8705: if (!$can_search) {
8706: my ($insttypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($srch->{'srchdomain'});
8707: my @longtypes;
8708: foreach my $item (@usertypes) {
1.229 raeburn 8709: if (defined($insttypes->{$item})) {
8710: push (@longtypes,$insttypes->{$item});
8711: } elsif ($item eq 'default') {
8712: push (@longtypes,&mt('other'));
8713: }
1.160 raeburn 8714: }
8715: my $insttype_str = join(', ',@longtypes);
1.180 raeburn 8716: return &mt('Institutional directory search in domain: [_1] is not available to your user type: ',$showdom).$insttype_str;
1.229 raeburn 8717: }
1.160 raeburn 8718: } else {
8719: $can_search = 1;
8720: }
8721: } else {
1.180 raeburn 8722: return &mt('Institutional directory search has not been configured for domain: [_1]',$showdom);
1.160 raeburn 8723: }
8724: my %longtext = &Apache::lonlocal::texthash (
1.167 albertel 8725: uname => 'username',
1.160 raeburn 8726: lastfirst => 'last name, first name',
1.167 albertel 8727: lastname => 'last name',
1.172 raeburn 8728: contains => 'contains',
1.178 raeburn 8729: exact => 'as exact match to',
8730: begins => 'begins with',
1.160 raeburn 8731: );
8732: if ($can_search) {
8733: if (ref($dom_inst_srch{'directorysrch'}{'searchby'}) eq 'ARRAY') {
8734: if (!grep(/^\Q$srch->{'srchby'}\E$/,@{$dom_inst_srch{'directorysrch'}{'searchby'}})) {
1.180 raeburn 8735: return &mt('Institutional directory search in domain: [_1] is not available for searching by "[_2]"',$showdom,$longtext{$srch->{'srchby'}});
1.160 raeburn 8736: }
8737: } else {
1.180 raeburn 8738: return &mt('Institutional directory search in domain: [_1] is not available.', $showdom);
1.160 raeburn 8739: }
8740: }
8741: if ($can_search) {
1.178 raeburn 8742: if (ref($dom_inst_srch{'directorysrch'}{'searchtypes'}) eq 'ARRAY') {
8743: if (grep(/^\Q$srch->{'srchtype'}\E/,@{$dom_inst_srch{'directorysrch'}{'searchtypes'}})) {
8744: return 'ok';
8745: } else {
1.180 raeburn 8746: return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
1.178 raeburn 8747: }
8748: } else {
8749: if ((($dom_inst_srch{'directorysrch'}{'searchtypes'} eq 'specify') &&
8750: ($srch->{'srchtype'} eq 'exact' || $srch->{'srchtype'} eq 'contains')) ||
8751: ($dom_inst_srch{'directorysrch'}{'searchtypes'} eq $srch->{'srchtype'})) {
8752: return 'ok';
8753: } else {
1.180 raeburn 8754: return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
1.178 raeburn 8755: }
1.160 raeburn 8756: }
8757: }
8758: }
8759:
8760: sub get_courseusers {
8761: my %advhash;
1.167 albertel 8762: my $classlist = &Apache::loncoursedata::get_classlist();
1.160 raeburn 8763: my %coursepersonnel=&Apache::lonnet::get_course_adv_roles();
8764: foreach my $role (sort(keys(%coursepersonnel))) {
8765: foreach my $user (split(/\,/,$coursepersonnel{$role})) {
1.167 albertel 8766: if (!exists($classlist->{$user})) {
8767: $classlist->{$user} = [];
8768: }
1.160 raeburn 8769: }
8770: }
1.167 albertel 8771: return $classlist;
1.160 raeburn 8772: }
8773:
8774: sub build_search_response {
1.221 raeburn 8775: my ($context,$srch,%srch_results) = @_;
1.179 raeburn 8776: my ($currstate,$response,$forcenewuser);
1.160 raeburn 8777: my %names = (
1.330 bisitz 8778: 'uname' => 'username',
8779: 'lastname' => 'last name',
1.160 raeburn 8780: 'lastfirst' => 'last name, first name',
1.330 bisitz 8781: 'crs' => 'this course',
8782: 'dom' => 'LON-CAPA domain',
8783: 'instd' => 'the institutional directory for domain',
1.160 raeburn 8784: );
8785:
8786: my %single = (
1.180 raeburn 8787: begins => 'A match',
1.160 raeburn 8788: contains => 'A match',
1.180 raeburn 8789: exact => 'An exact match',
1.160 raeburn 8790: );
8791: my %nomatch = (
1.180 raeburn 8792: begins => 'No match',
1.160 raeburn 8793: contains => 'No match',
1.180 raeburn 8794: exact => 'No exact match',
1.160 raeburn 8795: );
8796: if (keys(%srch_results) > 1) {
1.179 raeburn 8797: $currstate = 'select';
1.160 raeburn 8798: } else {
8799: if (keys(%srch_results) == 1) {
1.416 raeburn 8800: if ($env{'form.action'} eq 'accesslogs') {
8801: $currstate = 'activity';
8802: } else {
8803: $currstate = 'modify';
8804: }
1.180 raeburn 8805: $response = &mt("$single{$srch->{'srchtype'}} was found for the $names{$srch->{'srchby'}} ([_1]) in $names{$srch->{'srchin'}}.",$srch->{'srchterm'});
8806: if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
1.330 bisitz 8807: $response .= ': '.&display_domain_info($srch->{'srchdomain'});
1.180 raeburn 8808: }
1.330 bisitz 8809: } else { # Search has nothing found. Prepare message to user.
8810: $response = '<span class="LC_warning">';
1.180 raeburn 8811: if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
1.330 bisitz 8812: $response .= &mt("$nomatch{$srch->{'srchtype'}} found for the $names{$srch->{'srchby'}} [_1] in $names{$srch->{'srchin'}}: [_2]",
8813: '<b>'.$srch->{'srchterm'}.'</b>',
8814: &display_domain_info($srch->{'srchdomain'}));
8815: } else {
8816: $response .= &mt("$nomatch{$srch->{'srchtype'}} found for the $names{$srch->{'srchby'}} [_1] in $names{$srch->{'srchin'}}.",
8817: '<b>'.$srch->{'srchterm'}.'</b>');
1.180 raeburn 8818: }
8819: $response .= '</span>';
1.330 bisitz 8820:
1.160 raeburn 8821: if ($srch->{'srchin'} ne 'alc') {
8822: $forcenewuser = 1;
8823: my $cansrchinst = 0;
1.438 raeburn 8824: if (($srch->{'srchdomain'}) && ($env{'form.action'} ne 'accesslogs')) {
1.160 raeburn 8825: my %domconfig = &Apache::lonnet::get_dom('configuration',['directorysrch'],$srch->{'srchdomain'});
8826: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
8827: if ($domconfig{'directorysrch'}{'available'}) {
8828: $cansrchinst = 1;
8829: }
8830: }
8831: }
1.180 raeburn 8832: if ((($srch->{'srchby'} eq 'lastfirst') ||
8833: ($srch->{'srchby'} eq 'lastname')) &&
8834: ($srch->{'srchin'} eq 'dom')) {
8835: if ($cansrchinst) {
8836: $response .= '<br />'.&mt('You may want to broaden your search to a search of the institutional directory for the domain.');
1.160 raeburn 8837: }
8838: }
1.180 raeburn 8839: if ($srch->{'srchin'} eq 'crs') {
8840: $response .= '<br />'.&mt('You may want to broaden your search to the selected LON-CAPA domain.');
8841: }
8842: }
1.305 raeburn 8843: my $createdom = $env{'request.role.domain'};
8844: if ($context eq 'requestcrs') {
8845: if ($env{'form.coursedom'} ne '') {
8846: $createdom = $env{'form.coursedom'};
8847: }
8848: }
1.416 raeburn 8849: unless (($env{'form.action'} eq 'accesslogs') || (($srch->{'srchby'} eq 'uname') && ($srch->{'srchin'} eq 'dom') &&
8850: ($srch->{'srchtype'} eq 'exact') && ($srch->{'srchdomain'} eq $createdom))) {
1.221 raeburn 8851: my $cancreate =
1.305 raeburn 8852: &Apache::lonuserutils::can_create_user($createdom,$context);
8853: my $targetdom = '<span class="LC_cusr_emph">'.$createdom.'</span>';
1.221 raeburn 8854: if ($cancreate) {
1.305 raeburn 8855: my $showdom = &display_domain_info($createdom);
1.266 bisitz 8856: $response .= '<br /><br />'
8857: .'<b>'.&mt('To add a new user:').'</b>'
1.305 raeburn 8858: .'<br />';
8859: if ($context eq 'requestcrs') {
8860: $response .= &mt("(You can only define new users in the new course's domain - [_1])",$targetdom);
8861: } else {
8862: $response .= &mt("(You can only create new users in your current role's domain - [_1])",$targetdom);
8863: }
8864: $response .='<ul><li>'
1.266 bisitz 8865: .&mt("Set 'Domain/institution to search' to: [_1]",'<span class="LC_cusr_emph">'.$showdom.'</span>')
8866: .'</li><li>'
8867: .&mt("Set 'Search criteria' to: [_1]username is ..... in selected LON-CAPA domain[_2]",'<span class="LC_cusr_emph">','</span>')
8868: .'</li><li>'
8869: .&mt('Provide the proposed username')
8870: .'</li><li>'
8871: .&mt("Click 'Search'")
8872: .'</li></ul><br />';
1.221 raeburn 8873: } else {
1.422 raeburn 8874: unless (($context eq 'domain') && ($env{'form.action'} eq 'singleuser')) {
8875: my $helplink = ' href="javascript:helpMenu('."'display'".')"';
8876: $response .= '<br /><br />';
8877: if ($context eq 'requestcrs') {
8878: $response .= &mt("You are not authorized to define new users in the new course's domain - [_1].",$targetdom);
8879: } else {
8880: $response .= &mt("You are not authorized to create new users in your current role's domain - [_1].",$targetdom);
8881: }
8882: $response .= '<br />'
8883: .&mt('Please contact the [_1]helpdesk[_2] if you need to create a new user.'
8884: ,' <a'.$helplink.'>'
8885: ,'</a>')
8886: .'<br />';
1.305 raeburn 8887: }
1.221 raeburn 8888: }
1.160 raeburn 8889: }
8890: }
8891: }
1.179 raeburn 8892: return ($currstate,$response,$forcenewuser);
1.160 raeburn 8893: }
8894:
1.180 raeburn 8895: sub display_domain_info {
8896: my ($dom) = @_;
8897: my $output = $dom;
8898: if ($dom ne '') {
8899: my $domdesc = &Apache::lonnet::domain($dom,'description');
8900: if ($domdesc ne '') {
8901: $output .= ' <span class="LC_cusr_emph">('.$domdesc.')</span>';
8902: }
8903: }
8904: return $output;
8905: }
8906:
1.160 raeburn 8907: sub crumb_utilities {
8908: my %elements = (
8909: crtuser => {
8910: srchterm => 'text',
1.172 raeburn 8911: srchin => 'selectbox',
1.160 raeburn 8912: srchby => 'selectbox',
8913: srchtype => 'selectbox',
8914: srchdomain => 'selectbox',
8915: },
1.207 raeburn 8916: crtusername => {
8917: srchterm => 'text',
8918: srchdomain => 'selectbox',
8919: },
1.160 raeburn 8920: docustom => {
8921: rolename => 'selectbox',
8922: newrolename => 'textbox',
8923: },
1.179 raeburn 8924: studentform => {
8925: srchterm => 'text',
8926: srchin => 'selectbox',
8927: srchby => 'selectbox',
8928: srchtype => 'selectbox',
8929: srchdomain => 'selectbox',
8930: },
1.160 raeburn 8931: );
8932:
8933: my $jsback .= qq|
8934: function backPage(formname,prevphase,prevstate) {
1.211 raeburn 8935: if (typeof prevphase == 'undefined') {
8936: formname.phase.value = '';
8937: }
8938: else {
8939: formname.phase.value = prevphase;
8940: }
8941: if (typeof prevstate == 'undefined') {
8942: formname.currstate.value = '';
8943: }
8944: else {
8945: formname.currstate.value = prevstate;
8946: }
1.160 raeburn 8947: formname.submit();
8948: }
8949: |;
8950: return ($jsback,\%elements);
8951: }
8952:
1.26 matthew 8953: sub course_level_table {
1.375 raeburn 8954: my ($inccourses,$showcredits,$defaultcredits) = @_;
8955: return unless (ref($inccourses) eq 'HASH');
1.26 matthew 8956: my $table = '';
1.62 www 8957: # Custom Roles?
8958:
1.190 raeburn 8959: my %customroles=&Apache::lonuserutils::my_custom_roles();
1.89 raeburn 8960: my %lt=&Apache::lonlocal::texthash(
8961: 'exs' => "Existing sections",
8962: 'new' => "Define new section",
8963: 'ssd' => "Set Start Date",
8964: 'sed' => "Set End Date",
1.131 raeburn 8965: 'crl' => "Course Level",
1.89 raeburn 8966: 'act' => "Activate",
8967: 'rol' => "Role",
8968: 'ext' => "Extent",
1.113 raeburn 8969: 'grs' => "Section",
1.375 raeburn 8970: 'crd' => "Credits",
1.89 raeburn 8971: 'sta' => "Start",
8972: 'end' => "End"
8973: );
1.62 www 8974:
1.375 raeburn 8975: foreach my $protectedcourse (sort(keys(%{$inccourses}))) {
1.135 raeburn 8976: my $thiscourse=$protectedcourse;
1.26 matthew 8977: $thiscourse=~s:_:/:g;
8978: my %coursedata=&Apache::lonnet::coursedescription($thiscourse);
1.365 raeburn 8979: my $isowner = &Apache::lonuserutils::is_courseowner($protectedcourse,$coursedata{'internal.courseowner'});
1.26 matthew 8980: my $area=$coursedata{'description'};
1.321 raeburn 8981: my $crstype=$coursedata{'type'};
1.135 raeburn 8982: if (!defined($area)) { $area=&mt('Unavailable course').': '.$protectedcourse; }
1.89 raeburn 8983: my ($domain,$cnum)=split(/\//,$thiscourse);
1.115 albertel 8984: my %sections_count;
1.101 albertel 8985: if (defined($env{'request.course.id'})) {
8986: if ($env{'request.course.id'} eq $domain.'_'.$cnum) {
1.115 albertel 8987: %sections_count =
8988: &Apache::loncommon::get_sections($domain,$cnum);
1.92 raeburn 8989: }
8990: }
1.321 raeburn 8991: my @roles = &Apache::lonuserutils::roles_by_context('course','',$crstype);
1.213 raeburn 8992: foreach my $role (@roles) {
1.321 raeburn 8993: my $plrole=&Apache::lonnet::plaintext($role,$crstype);
1.329 raeburn 8994: if ((&Apache::lonnet::allowed('c'.$role,$thiscourse)) ||
8995: ((($role eq 'cc') || ($role eq 'co')) && ($isowner))) {
1.221 raeburn 8996: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
1.375 raeburn 8997: $plrole,\%sections_count,\%lt,
1.402 raeburn 8998: $showcredits,$defaultcredits,$crstype);
1.221 raeburn 8999: } elsif ($env{'request.course.sec'} ne '') {
9000: if (&Apache::lonnet::allowed('c'.$role,$thiscourse.'/'.
9001: $env{'request.course.sec'})) {
9002: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
1.375 raeburn 9003: $plrole,\%sections_count,\%lt,
1.402 raeburn 9004: $showcredits,$defaultcredits,$crstype);
1.26 matthew 9005: }
9006: }
9007: }
1.221 raeburn 9008: if (&Apache::lonnet::allowed('ccr',$thiscourse)) {
1.324 raeburn 9009: foreach my $cust (sort(keys(%customroles))) {
9010: next if ($crstype eq 'Community' && $customroles{$cust} =~ /bre\&S/);
1.221 raeburn 9011: my $role = 'cr_cr_'.$env{'user.domain'}.'_'.$env{'user.name'}.'_'.$cust;
9012: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
1.402 raeburn 9013: $cust,\%sections_count,\%lt,
9014: $showcredits,$defaultcredits,$crstype);
1.221 raeburn 9015: }
1.62 www 9016: }
1.26 matthew 9017: }
9018: return '' if ($table eq ''); # return nothing if there is nothing
9019: # in the table
1.188 raeburn 9020: my $result;
9021: if (!$env{'request.course.id'}) {
9022: $result = '<h4>'.$lt{'crl'}.'</h4>'."\n";
9023: }
9024: $result .=
1.136 raeburn 9025: &Apache::loncommon::start_data_table().
9026: &Apache::loncommon::start_data_table_header_row().
1.375 raeburn 9027: '<th>'.$lt{'act'}.'</th><th>'.$lt{'rol'}.'</th>'."\n".
1.402 raeburn 9028: '<th>'.$lt{'ext'}.'</th><th>'."\n";
9029: if ($showcredits) {
9030: $result .= $lt{'crd'}.'</th>';
9031: }
9032: $result .=
1.375 raeburn 9033: '<th>'.$lt{'grs'}.'</th><th>'.$lt{'sta'}.'</th>'."\n".
9034: '<th>'.$lt{'end'}.'</th>'.
1.136 raeburn 9035: &Apache::loncommon::end_data_table_header_row().
9036: $table.
9037: &Apache::loncommon::end_data_table();
1.26 matthew 9038: return $result;
9039: }
1.88 raeburn 9040:
1.221 raeburn 9041: sub course_level_row {
1.375 raeburn 9042: my ($protectedcourse,$role,$area,$domain,$plrole,$sections_count,
1.402 raeburn 9043: $lt,$showcredits,$defaultcredits,$crstype) = @_;
1.375 raeburn 9044: my $creditem;
1.222 raeburn 9045: my $row = &Apache::loncommon::start_data_table_row().
9046: ' <td><input type="checkbox" name="act_'.
9047: $protectedcourse.'_'.$role.'" /></td>'."\n".
9048: ' <td>'.$plrole.'</td>'."\n".
9049: ' <td>'.$area.'<br />Domain: '.$domain.'</td>'."\n";
1.402 raeburn 9050: if (($showcredits) && ($role eq 'st') && ($crstype eq 'Course')) {
1.375 raeburn 9051: $row .=
9052: '<td><input type="text" name="credits_'.$protectedcourse.'_'.
9053: $role.'" size="3" value="'.$defaultcredits.'" /></td>';
9054: } else {
9055: $row .= '<td> </td>';
9056: }
1.322 raeburn 9057: if (($role eq 'cc') || ($role eq 'co')) {
1.222 raeburn 9058: $row .= '<td> </td>';
1.221 raeburn 9059: } elsif ($env{'request.course.sec'} ne '') {
1.222 raeburn 9060: $row .= ' <td><input type="hidden" value="'.
9061: $env{'request.course.sec'}.'" '.
9062: 'name="sec_'.$protectedcourse.'_'.$role.'" />'.
9063: $env{'request.course.sec'}.'</td>';
1.221 raeburn 9064: } else {
9065: if (ref($sections_count) eq 'HASH') {
9066: my $currsec =
9067: &Apache::lonuserutils::course_sections($sections_count,
9068: $protectedcourse.'_'.$role);
1.222 raeburn 9069: $row .= '<td><table class="LC_createuser">'."\n".
9070: '<tr class="LC_section_row">'."\n".
9071: ' <td valign="top">'.$lt->{'exs'}.'<br />'.
9072: $currsec.'</td>'."\n".
9073: ' <td> </td>'."\n".
9074: ' <td valign="top"> '.$lt->{'new'}.'<br />'.
1.221 raeburn 9075: '<input type="text" name="newsec_'.$protectedcourse.'_'.$role.
9076: '" value="" />'.
9077: '<input type="hidden" '.
9078: 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'."\n".
1.222 raeburn 9079: '</tr></table></td>'."\n";
1.221 raeburn 9080: } else {
1.222 raeburn 9081: $row .= '<td><input type="text" size="10" '.
1.375 raeburn 9082: 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'."\n";
1.221 raeburn 9083: }
9084: }
1.222 raeburn 9085: $row .= <<ENDTIMEENTRY;
9086: <td><input type="hidden" name="start_$protectedcourse\_$role" value="" />
1.221 raeburn 9087: <a href=
9088: "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 9089: <td><input type="hidden" name="end_$protectedcourse\_$role" value="" />
1.221 raeburn 9090: <a href=
9091: "javascript:pjump('date_end','End Date $plrole',document.cu.end_$protectedcourse\_$role.value,'end_$protectedcourse\_$role','cu.pres','dateset')">$lt->{'sed'}</a></td>
9092: ENDTIMEENTRY
1.222 raeburn 9093: $row .= &Apache::loncommon::end_data_table_row();
9094: return $row;
1.221 raeburn 9095: }
9096:
1.88 raeburn 9097: sub course_level_dc {
1.375 raeburn 9098: my ($dcdom,$showcredits) = @_;
1.190 raeburn 9099: my %customroles=&Apache::lonuserutils::my_custom_roles();
1.213 raeburn 9100: my @roles = &Apache::lonuserutils::roles_by_context('course');
1.88 raeburn 9101: my $hiddenitems = '<input type="hidden" name="dcdomain" value="'.$dcdom.'" />'.
9102: '<input type="hidden" name="origdom" value="'.$dcdom.'" />'.
1.133 raeburn 9103: '<input type="hidden" name="dccourse" value="" />';
1.355 www 9104: my $courseform=&Apache::loncommon::selectcourse_link
1.356 raeburn 9105: ('cu','dccourse','dcdomain','coursedesc',undef,undef,'Select','crstype');
1.375 raeburn 9106: my $credit_elem;
9107: if ($showcredits) {
9108: $credit_elem = 'credits';
9109: }
9110: my $cb_jscript = &Apache::loncommon::coursebrowser_javascript($dcdom,'currsec','cu','role','Course/Community Browser',$credit_elem);
1.88 raeburn 9111: my %lt=&Apache::lonlocal::texthash(
9112: 'rol' => "Role",
1.113 raeburn 9113: 'grs' => "Section",
1.88 raeburn 9114: 'exs' => "Existing sections",
9115: 'new' => "Define new section",
9116: 'sta' => "Start",
9117: 'end' => "End",
9118: 'ssd' => "Set Start Date",
1.355 www 9119: 'sed' => "Set End Date",
1.375 raeburn 9120: 'scc' => "Course/Community",
9121: 'crd' => "Credits",
1.88 raeburn 9122: );
1.323 raeburn 9123: my $header = '<h4>'.&mt('Course/Community Level').'</h4>'.
1.136 raeburn 9124: &Apache::loncommon::start_data_table().
9125: &Apache::loncommon::start_data_table_header_row().
1.375 raeburn 9126: '<th>'.$lt{'scc'}.'</th><th>'.$lt{'rol'}.'</th>'."\n".
1.397 bisitz 9127: '<th>'.$lt{'grs'}.'</th>'."\n";
9128: $header .= '<th>'.$lt{'crd'}.'</th>'."\n" if ($showcredits);
9129: $header .= '<th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'."\n".
1.136 raeburn 9130: &Apache::loncommon::end_data_table_header_row();
1.143 raeburn 9131: my $otheritems = &Apache::loncommon::start_data_table_row()."\n".
1.356 raeburn 9132: '<td><br /><span class="LC_nobreak"><input type="text" name="coursedesc" value="" onfocus="this.blur();opencrsbrowser('."'cu','dccourse','dcdomain','coursedesc','','','','crstype'".')" />'.
9133: $courseform.(' ' x4).'</span></td>'."\n".
1.389 bisitz 9134: '<td valign="top"><br /><select name="role">'."\n";
1.213 raeburn 9135: foreach my $role (@roles) {
1.135 raeburn 9136: my $plrole=&Apache::lonnet::plaintext($role);
1.389 bisitz 9137: $otheritems .= ' <option value="'.$role.'">'.$plrole.'</option>';
1.88 raeburn 9138: }
1.404 raeburn 9139: if ( keys(%customroles) > 0) {
9140: foreach my $cust (sort(keys(%customroles))) {
1.101 albertel 9141: my $custrole='cr_cr_'.$env{'user.domain'}.
1.135 raeburn 9142: '_'.$env{'user.name'}.'_'.$cust;
1.389 bisitz 9143: $otheritems .= ' <option value="'.$custrole.'">'.$cust.'</option>';
1.88 raeburn 9144: }
9145: }
9146: $otheritems .= '</select></td><td>'.
9147: '<table border="0" cellspacing="0" cellpadding="0">'.
9148: '<tr><td valign="top"><b>'.$lt{'exs'}.'</b><br /><select name="currsec">'.
1.389 bisitz 9149: ' <option value=""><--'.&mt('Pick course first').'</option></select></td>'.
1.88 raeburn 9150: '<td> </td>'.
9151: '<td valign="top"> <b>'.$lt{'new'}.'</b><br />'.
1.113 raeburn 9152: '<input type="text" name="newsec" value="" />'.
1.237 raeburn 9153: '<input type="hidden" name="section" value="" />'.
1.323 raeburn 9154: '<input type="hidden" name="groups" value="" />'.
9155: '<input type="hidden" name="crstype" value="" /></td>'.
1.375 raeburn 9156: '</tr></table></td>'."\n";
9157: if ($showcredits) {
9158: $otheritems .= '<td><br />'."\n".
1.397 bisitz 9159: '<input type="text" size="3" name="credits" value="" /></td>'."\n";
1.375 raeburn 9160: }
1.88 raeburn 9161: $otheritems .= <<ENDTIMEENTRY;
1.323 raeburn 9162: <td><br /><input type="hidden" name="start" value='' />
1.88 raeburn 9163: <a href=
9164: "javascript:pjump('date_start','Start Date',document.cu.start.value,'start','cu.pres','dateset')">$lt{'ssd'}</a></td>
1.323 raeburn 9165: <td><br /><input type="hidden" name="end" value='' />
1.88 raeburn 9166: <a href=
9167: "javascript:pjump('date_end','End Date',document.cu.end.value,'end','cu.pres','dateset')">$lt{'sed'}</a></td>
9168: ENDTIMEENTRY
1.136 raeburn 9169: $otheritems .= &Apache::loncommon::end_data_table_row().
9170: &Apache::loncommon::end_data_table()."\n";
1.88 raeburn 9171: return $cb_jscript.$header.$hiddenitems.$otheritems;
9172: }
9173:
1.237 raeburn 9174: sub update_selfenroll_config {
1.400 raeburn 9175: my ($r,$cid,$cdom,$cnum,$context,$crstype,$currsettings) = @_;
1.398 raeburn 9176: return unless (ref($currsettings) eq 'HASH');
9177: my ($row,$lt) = &Apache::lonuserutils::get_selfenroll_titles();
9178: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
1.237 raeburn 9179: my (%changes,%warning);
1.241 raeburn 9180: my $curr_types;
1.400 raeburn 9181: my %noedit;
9182: unless ($context eq 'domain') {
9183: %noedit = &get_noedit_fields($cdom,$cnum,$crstype,$row);
9184: }
1.237 raeburn 9185: if (ref($row) eq 'ARRAY') {
9186: foreach my $item (@{$row}) {
1.400 raeburn 9187: next if ($noedit{$item});
1.237 raeburn 9188: if ($item eq 'enroll_dates') {
9189: my (%currenrolldate,%newenrolldate);
9190: foreach my $type ('start','end') {
1.398 raeburn 9191: $currenrolldate{$type} = $currsettings->{'selfenroll_'.$type.'_date'};
1.237 raeburn 9192: $newenrolldate{$type} = &Apache::lonhtmlcommon::get_date_from_form('selfenroll_'.$type.'_date');
9193: if ($newenrolldate{$type} ne $currenrolldate{$type}) {
9194: $changes{'internal.selfenroll_'.$type.'_date'} = $newenrolldate{$type};
9195: }
9196: }
9197: } elsif ($item eq 'access_dates') {
9198: my (%currdate,%newdate);
9199: foreach my $type ('start','end') {
1.398 raeburn 9200: $currdate{$type} = $currsettings->{'selfenroll_'.$type.'_access'};
1.237 raeburn 9201: $newdate{$type} = &Apache::lonhtmlcommon::get_date_from_form('selfenroll_'.$type.'_access');
9202: if ($newdate{$type} ne $currdate{$type}) {
9203: $changes{'internal.selfenroll_'.$type.'_access'} = $newdate{$type};
9204: }
9205: }
1.241 raeburn 9206: } elsif ($item eq 'types') {
1.398 raeburn 9207: $curr_types = $currsettings->{'selfenroll_'.$item};
1.241 raeburn 9208: if ($env{'form.selfenroll_all'}) {
9209: if ($curr_types ne '*') {
9210: $changes{'internal.selfenroll_types'} = '*';
9211: } else {
9212: next;
9213: }
9214: } else {
1.249 raeburn 9215: my %currdoms;
1.241 raeburn 9216: my @entries = split(/;/,$curr_types);
9217: my @deletedoms = &Apache::loncommon::get_env_multiple('form.selfenroll_delete');
1.249 raeburn 9218: my @activations = &Apache::loncommon::get_env_multiple('form.selfenroll_activate');
1.241 raeburn 9219: my $newnum = 0;
1.249 raeburn 9220: my @latesttypes;
9221: foreach my $num (@activations) {
9222: my @types = &Apache::loncommon::get_env_multiple('form.selfenroll_types_'.$num);
9223: if (@types > 0) {
1.241 raeburn 9224: @types = sort(@types);
9225: my $typestr = join(',',@types);
1.249 raeburn 9226: my $typedom = $env{'form.selfenroll_dom_'.$num};
9227: $latesttypes[$newnum] = $typedom.':'.$typestr;
9228: $currdoms{$typedom} = 1;
1.241 raeburn 9229: $newnum ++;
9230: }
9231: }
1.338 raeburn 9232: for (my $j=0; $j<$env{'form.selfenroll_types_total'}; $j++) {
9233: if ((!grep(/^$j$/,@deletedoms)) && (!grep(/^$j$/,@activations))) {
1.249 raeburn 9234: my @types = &Apache::loncommon::get_env_multiple('form.selfenroll_types_'.$j);
9235: if (@types > 0) {
9236: @types = sort(@types);
9237: my $typestr = join(',',@types);
9238: my $typedom = $env{'form.selfenroll_dom_'.$j};
9239: $latesttypes[$newnum] = $typedom.':'.$typestr;
9240: $currdoms{$typedom} = 1;
9241: $newnum ++;
9242: }
9243: }
9244: }
9245: if ($env{'form.selfenroll_newdom'} ne '') {
9246: my $typedom = $env{'form.selfenroll_newdom'};
9247: if ((!defined($currdoms{$typedom})) &&
9248: (&Apache::lonnet::domain($typedom) ne '')) {
9249: my $typestr;
9250: my ($othertitle,$usertypes,$types) =
9251: &Apache::loncommon::sorted_inst_types($typedom);
9252: my $othervalue = 'any';
9253: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
9254: if (@{$types} > 0) {
1.257 raeburn 9255: my @esc_types = map { &escape($_); } @{$types};
1.249 raeburn 9256: $othervalue = 'other';
1.258 raeburn 9257: $typestr = join(',',(@esc_types,$othervalue));
1.249 raeburn 9258: }
9259: $typestr = $othervalue;
9260: } else {
9261: $typestr = $othervalue;
9262: }
9263: $latesttypes[$newnum] = $typedom.':'.$typestr;
9264: $newnum ++ ;
9265: }
9266: }
1.241 raeburn 9267: my $selfenroll_types = join(';',@latesttypes);
9268: if ($selfenroll_types ne $curr_types) {
9269: $changes{'internal.selfenroll_types'} = $selfenroll_types;
9270: }
9271: }
1.276 raeburn 9272: } elsif ($item eq 'limit') {
9273: my $newlimit = $env{'form.selfenroll_limit'};
9274: my $newcap = $env{'form.selfenroll_cap'};
9275: $newcap =~s/\s+//g;
1.398 raeburn 9276: my $currlimit = $currsettings->{'selfenroll_limit'};
1.276 raeburn 9277: $currlimit = 'none' if ($currlimit eq '');
1.398 raeburn 9278: my $currcap = $currsettings->{'selfenroll_cap'};
1.276 raeburn 9279: if ($newlimit ne $currlimit) {
9280: if ($newlimit ne 'none') {
9281: if ($newcap =~ /^\d+$/) {
9282: if ($newcap ne $currcap) {
9283: $changes{'internal.selfenroll_cap'} = $newcap;
9284: }
9285: $changes{'internal.selfenroll_limit'} = $newlimit;
9286: } else {
1.398 raeburn 9287: $warning{$item} = &mt('Maximum enrollment setting unchanged.').'<br />'.
9288: &mt('The value provided was invalid - it must be a positive integer if enrollment is being limited.');
1.276 raeburn 9289: }
9290: } elsif ($currcap ne '') {
9291: $changes{'internal.selfenroll_cap'} = '';
9292: $changes{'internal.selfenroll_limit'} = $newlimit;
9293: }
9294: } elsif ($currlimit ne 'none') {
9295: if ($newcap =~ /^\d+$/) {
9296: if ($newcap ne $currcap) {
9297: $changes{'internal.selfenroll_cap'} = $newcap;
9298: }
9299: } else {
1.398 raeburn 9300: $warning{$item} = &mt('Maximum enrollment setting unchanged.').'<br />'.
9301: &mt('The value provided was invalid - it must be a positive integer if enrollment is being limited.');
1.276 raeburn 9302: }
9303: }
9304: } elsif ($item eq 'approval') {
9305: my (@currnotified,@newnotified);
1.398 raeburn 9306: my $currapproval = $currsettings->{'selfenroll_approval'};
9307: my $currnotifylist = $currsettings->{'selfenroll_notifylist'};
1.276 raeburn 9308: if ($currnotifylist ne '') {
9309: @currnotified = split(/,/,$currnotifylist);
9310: @currnotified = sort(@currnotified);
9311: }
9312: my $newapproval = $env{'form.selfenroll_approval'};
9313: @newnotified = &Apache::loncommon::get_env_multiple('form.selfenroll_notify');
9314: @newnotified = sort(@newnotified);
9315: if ($newapproval ne $currapproval) {
9316: $changes{'internal.selfenroll_approval'} = $newapproval;
9317: if (!$newapproval) {
9318: if ($currnotifylist ne '') {
9319: $changes{'internal.selfenroll_notifylist'} = '';
9320: }
9321: } else {
9322: my @differences =
1.295 raeburn 9323: &Apache::loncommon::compare_arrays(\@currnotified,\@newnotified);
1.276 raeburn 9324: if (@differences > 0) {
9325: if (@newnotified > 0) {
9326: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
9327: } else {
9328: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
9329: }
9330: }
9331: }
9332: } else {
1.295 raeburn 9333: my @differences = &Apache::loncommon::compare_arrays(\@currnotified,\@newnotified);
1.276 raeburn 9334: if (@differences > 0) {
9335: if (@newnotified > 0) {
9336: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
9337: } else {
9338: $changes{'internal.selfenroll_notifylist'} = '';
9339: }
9340: }
9341: }
1.237 raeburn 9342: } else {
1.398 raeburn 9343: my $curr_val = $currsettings->{'selfenroll_'.$item};
1.237 raeburn 9344: my $newval = $env{'form.selfenroll_'.$item};
9345: if ($item eq 'section') {
9346: $newval = $env{'form.sections'};
1.241 raeburn 9347: if (defined($curr_groups{$newval})) {
1.237 raeburn 9348: $newval = $curr_val;
1.398 raeburn 9349: $warning{$item} = &mt('Section for self-enrolled users unchanged as the proposed section is a group').'<br />'.
9350: &mt('Group names and section names must be distinct');
1.237 raeburn 9351: } elsif ($newval eq 'all') {
9352: $newval = $curr_val;
1.274 bisitz 9353: $warning{$item} = &mt('Section for self-enrolled users unchanged, as "all" is a reserved section name.');
1.237 raeburn 9354: }
9355: if ($newval eq '') {
9356: $newval = 'none';
9357: }
9358: }
9359: if ($newval ne $curr_val) {
9360: $changes{'internal.selfenroll_'.$item} = $newval;
9361: }
1.241 raeburn 9362: }
1.237 raeburn 9363: }
9364: if (keys(%warning) > 0) {
9365: foreach my $item (@{$row}) {
9366: if (exists($warning{$item})) {
9367: $r->print($warning{$item}.'<br />');
9368: }
9369: }
9370: }
9371: if (keys(%changes) > 0) {
9372: my $putresult = &Apache::lonnet::put('environment',\%changes,$cdom,$cnum);
9373: if ($putresult eq 'ok') {
9374: if ((exists($changes{'internal.selfenroll_types'})) ||
9375: (exists($changes{'internal.selfenroll_start_date'})) ||
9376: (exists($changes{'internal.selfenroll_end_date'}))) {
9377: my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',
9378: $cnum,undef,undef,'Course');
9379: my $chome = &Apache::lonnet::homeserver($cnum,$cdom);
1.398 raeburn 9380: if (ref($crsinfo{$cid}) eq 'HASH') {
1.237 raeburn 9381: foreach my $item ('selfenroll_types','selfenroll_start_date','selfenroll_end_date') {
9382: if (exists($changes{'internal.'.$item})) {
1.398 raeburn 9383: $crsinfo{$cid}{$item} = $changes{'internal.'.$item};
1.237 raeburn 9384: }
9385: }
9386: my $crsputresult =
9387: &Apache::lonnet::courseidput($cdom,\%crsinfo,
9388: $chome,'notime');
9389: }
9390: }
9391: $r->print(&mt('The following changes were made to self-enrollment settings:').'<ul>');
9392: foreach my $item (@{$row}) {
9393: my $title = $item;
9394: if (ref($lt) eq 'HASH') {
9395: $title = $lt->{$item};
9396: }
9397: if ($item eq 'enroll_dates') {
9398: foreach my $type ('start','end') {
9399: if (exists($changes{'internal.selfenroll_'.$type.'_date'})) {
9400: my $newdate = &Apache::lonlocal::locallocaltime($changes{'internal.selfenroll_'.$type.'_date'});
1.244 bisitz 9401: $r->print('<li>'.&mt('[_1]: "[_2]" set to "[_3]".',
1.237 raeburn 9402: $title,$type,$newdate).'</li>');
9403: }
9404: }
9405: } elsif ($item eq 'access_dates') {
9406: foreach my $type ('start','end') {
9407: if (exists($changes{'internal.selfenroll_'.$type.'_access'})) {
9408: my $newdate = &Apache::lonlocal::locallocaltime($changes{'internal.selfenroll_'.$type.'_access'});
1.244 bisitz 9409: $r->print('<li>'.&mt('[_1]: "[_2]" set to "[_3]".',
1.237 raeburn 9410: $title,$type,$newdate).'</li>');
9411: }
9412: }
1.276 raeburn 9413: } elsif ($item eq 'limit') {
9414: if ((exists($changes{'internal.selfenroll_limit'})) ||
9415: (exists($changes{'internal.selfenroll_cap'}))) {
9416: my ($newval,$newcap);
9417: if ($changes{'internal.selfenroll_cap'} ne '') {
9418: $newcap = $changes{'internal.selfenroll_cap'}
9419: } else {
1.398 raeburn 9420: $newcap = $currsettings->{'selfenroll_cap'};
1.276 raeburn 9421: }
9422: if ($changes{'internal.selfenroll_limit'} eq 'none') {
9423: $newval = &mt('No limit');
9424: } elsif ($changes{'internal.selfenroll_limit'} eq
9425: 'allstudents') {
9426: $newval = &mt('New self-enrollment no longer allowed when total (all students) reaches [_1].',$newcap);
9427: } elsif ($changes{'internal.selfenroll_limit'} eq 'selfenrolled') {
9428: $newval = &mt('New self-enrollment no longer allowed when total number of self-enrolled students reaches [_1].',$newcap);
9429: } else {
1.398 raeburn 9430: my $currlimit = $currsettings->{'selfenroll_limit'};
1.276 raeburn 9431: if ($currlimit eq 'allstudents') {
9432: $newval = &mt('New self-enrollment no longer allowed when total (all students) reaches [_1].',$newcap);
9433: } elsif ($changes{'internal.selfenroll_limit'} eq 'selfenrolled') {
1.308 raeburn 9434: $newval = &mt('New self-enrollment no longer allowed when total number of self-enrolled students reaches [_1].',$newcap);
1.276 raeburn 9435: }
9436: }
9437: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval).'</li>'."\n");
9438: }
9439: } elsif ($item eq 'approval') {
9440: if ((exists($changes{'internal.selfenroll_approval'})) ||
9441: (exists($changes{'internal.selfenroll_notifylist'}))) {
1.398 raeburn 9442: my %selfdescs = &Apache::lonuserutils::selfenroll_default_descs();
1.276 raeburn 9443: my ($newval,$newnotify);
9444: if (exists($changes{'internal.selfenroll_notifylist'})) {
9445: $newnotify = $changes{'internal.selfenroll_notifylist'};
9446: } else {
1.398 raeburn 9447: $newnotify = $currsettings->{'selfenroll_notifylist'};
1.276 raeburn 9448: }
1.398 raeburn 9449: if (exists($changes{'internal.selfenroll_approval'})) {
9450: if ($changes{'internal.selfenroll_approval'} !~ /^[012]$/) {
9451: $changes{'internal.selfenroll_approval'} = '0';
9452: }
9453: $newval = $selfdescs{'approval'}{$changes{'internal.selfenroll_approval'}};
1.276 raeburn 9454: } else {
1.398 raeburn 9455: my $currapproval = $currsettings->{'selfenroll_approval'};
9456: if ($currapproval !~ /^[012]$/) {
9457: $currapproval = 0;
1.276 raeburn 9458: }
1.398 raeburn 9459: $newval = $selfdescs{'approval'}{$currapproval};
1.276 raeburn 9460: }
9461: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval));
9462: if ($newnotify) {
1.277 raeburn 9463: $r->print('<br />'.&mt('The following will be notified when an enrollment request needs approval, or has been approved: [_1].',$newnotify));
1.276 raeburn 9464: } else {
1.277 raeburn 9465: $r->print('<br />'.&mt('No notifications sent when an enrollment request needs approval, or has been approved.'));
1.276 raeburn 9466: }
9467: $r->print('</li>'."\n");
9468: }
1.237 raeburn 9469: } else {
9470: if (exists($changes{'internal.selfenroll_'.$item})) {
1.241 raeburn 9471: my $newval = $changes{'internal.selfenroll_'.$item};
9472: if ($item eq 'types') {
9473: if ($newval eq '') {
9474: $newval = &mt('None');
9475: } elsif ($newval eq '*') {
9476: $newval = &mt('Any user in any domain');
9477: }
1.245 raeburn 9478: } elsif ($item eq 'registered') {
9479: if ($newval eq '1') {
9480: $newval = &mt('Yes');
9481: } elsif ($newval eq '0') {
9482: $newval = &mt('No');
9483: }
1.241 raeburn 9484: }
1.244 bisitz 9485: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval).'</li>'."\n");
1.237 raeburn 9486: }
9487: }
9488: }
9489: $r->print('</ul>');
1.398 raeburn 9490: if ($env{'course.'.$cid.'.description'} ne '') {
9491: my %newenvhash;
9492: foreach my $key (keys(%changes)) {
9493: $newenvhash{'course.'.$cid.'.'.$key} = $changes{$key};
9494: }
9495: &Apache::lonnet::appenv(\%newenvhash);
1.237 raeburn 9496: }
9497: } else {
1.398 raeburn 9498: $r->print(&mt('An error occurred when saving changes to self-enrollment settings in this course.').'<br />'.
9499: &mt('The error was: [_1].',$putresult));
1.237 raeburn 9500: }
9501: } else {
1.249 raeburn 9502: $r->print(&mt('No changes were made to the existing self-enrollment settings in this course.'));
1.237 raeburn 9503: }
9504: } else {
1.249 raeburn 9505: $r->print(&mt('No changes were made to the existing self-enrollment settings in this course.'));
1.241 raeburn 9506: }
1.400 raeburn 9507: my $visactions = &cat_visibility();
9508: my ($cathash,%cattype);
9509: my %domconfig = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom);
9510: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
9511: $cathash = $domconfig{'coursecategories'}{'cats'};
9512: $cattype{'auth'} = $domconfig{'coursecategories'}{'auth'};
9513: $cattype{'unauth'} = $domconfig{'coursecategories'}{'unauth'};
9514: } else {
9515: $cathash = {};
9516: $cattype{'auth'} = 'std';
9517: $cattype{'unauth'} = 'std';
9518: }
9519: if (($cattype{'auth'} eq 'none') && ($cattype{'unauth'} eq 'none')) {
9520: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
9521: '<br />'.
9522: '<br />'.$visactions->{'take'}.'<ul>'.
9523: '<li>'.$visactions->{'dc_chgconf'}.'</li>'.
9524: '</ul>');
9525: } elsif (($cattype{'auth'} !~ /^(std|domonly)$/) && ($cattype{'unauth'} !~ /^(std|domonly)$/)) {
9526: if ($currsettings->{'uniquecode'}) {
9527: $r->print('<span class="LC_info">'.$visactions->{'vis'}.'</span>');
9528: } else {
1.366 bisitz 9529: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
1.400 raeburn 9530: '<br />'.
9531: '<br />'.$visactions->{'take'}.'<ul>'.
9532: '<li>'.$visactions->{'dc_setcode'}.'</li>'.
9533: '</ul><br />');
9534: }
9535: } else {
9536: my ($visible,$cansetvis,$vismsgs) = &visible_in_stdcat($cdom,$cnum,\%domconfig);
9537: if (ref($visactions) eq 'HASH') {
9538: if (!$visible) {
9539: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
9540: '<br />');
9541: if (ref($vismsgs) eq 'ARRAY') {
9542: $r->print('<br />'.$visactions->{'take'}.'<ul>');
9543: foreach my $item (@{$vismsgs}) {
9544: $r->print('<li>'.$visactions->{$item}.'</li>');
9545: }
9546: $r->print('</ul>');
1.256 raeburn 9547: }
1.400 raeburn 9548: $r->print($cansetvis);
1.256 raeburn 9549: }
9550: }
9551: }
1.237 raeburn 9552: return;
9553: }
9554:
1.27 matthew 9555: #---------------------------------------------- end functions for &phase_two
1.29 matthew 9556:
9557: #--------------------------------- functions for &phase_two and &phase_three
9558:
9559: #--------------------------end of functions for &phase_two and &phase_three
1.372 raeburn 9560:
1.1 www 9561: 1;
9562: __END__
1.2 www 9563:
9564:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>