Annotation of loncom/interface/loncreateuser.pm, revision 1.444
1.20 harris41 1: # The LearningOnline Network with CAPA
1.1 www 2: # Create a user
3: #
1.444 ! raeburn 4: # $Id: loncreateuser.pm,v 1.443 2017/08/03 16:22:09 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.444 ! raeburn 889: my ($trustedref,$untrustedref);
! 890: if ($context eq 'course') {
! 891: ($trustedref,$untrustedref) = &Apache::lonnet::trusted_domains('enroll',$defdom);
! 892: } elsif ($context eq 'author') {
! 893: ($trustedref,$untrustedref) = &Apache::lonnet::trusted_domains('othcoau',$defdom);
! 894: } elsif ($context eq 'domain') {
! 895: ($trustedref,$untrustedref) = &Apache::lonnet::trusted_domains('domroles',$defdom);
! 896: }
! 897: my $domform = &Apache::loncommon::select_dom_form($defdom,'srchdomain',undef,undef,undef,$trustedref,$untrustedref);
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.218 raeburn 2148: foreach my $thisdomain (sort(&Apache::lonnet::all_domains())) {
1.312 raeburn 2149: foreach my $role (@allroles) {
2150: next if ($role eq 'ad');
1.357 raeburn 2151: next if (($role eq 'au') && ($ccdomain ne $thisdomain));
1.218 raeburn 2152: if (&Apache::lonnet::allowed('c'.$role,$thisdomain)) {
2153: my $plrole=&Apache::lonnet::plaintext($role);
2154: my %lt=&Apache::lonlocal::texthash(
2155: 'ssd' => "Set Start Date",
2156: 'sed' => "Set End Date"
2157: );
2158: $num_domain_level ++;
2159: $domaintext .=
2160: &Apache::loncommon::start_data_table_row().
1.291 bisitz 2161: '<td><input type="checkbox" name="act_'.$thisdomain.'_'.$role.'" /></td>
1.218 raeburn 2162: <td>'.$plrole.'</td>
2163: <td>'.$thisdomain.'</td>
2164: <td><input type="hidden" name="start_'.$thisdomain.'_'.$role.'" value="" />
2165: <a href=
2166: "javascript:pjump('."'date_start','Start Date $plrole',document.cu.start_$thisdomain\_$role.value,'start_$thisdomain\_$role','cu.pres','dateset'".')">'.$lt{'ssd'}.'</a></td>
2167: <td><input type="hidden" name="end_'.$thisdomain.'_'.$role.'" value="" />
2168: <a href=
2169: "javascript:pjump('."'date_end','End Date $plrole',document.cu.end_$thisdomain\_$role.value,'end_$thisdomain\_$role','cu.pres','dateset'".')">'.$lt{'sed'}.'</a></td>'.
2170: &Apache::loncommon::end_data_table_row();
2171: }
2172: }
2173: }
2174: $domaintext.= &Apache::loncommon::end_data_table();
2175: if ($num_domain_level > 0) {
2176: $r->print($domaintext);
2177: $addrolesdisplay = 1;
2178: }
2179: return $addrolesdisplay;
2180: }
2181:
1.188 raeburn 2182: sub user_authentication {
1.227 raeburn 2183: my ($ccuname,$ccdomain,$formname) = @_;
1.188 raeburn 2184: my $currentauth=&Apache::lonnet::queryauthenticate($ccuname,$ccdomain);
1.227 raeburn 2185: my $outcome;
1.418 raeburn 2186: my %lt=&Apache::lonlocal::texthash(
2187: 'err' => "ERROR",
2188: 'uuas' => "This user has an unrecognized authentication scheme",
2189: 'adcs' => "Please alert a domain coordinator of this situation",
2190: 'sldb' => "Please specify login data below",
2191: 'ld' => "Login Data"
2192: );
1.188 raeburn 2193: # Check for a bad authentication type
2194: if ($currentauth !~ /^(krb4|krb5|unix|internal|localauth):/) {
2195: # bad authentication scheme
2196: if (&Apache::lonnet::allowed('mau',$ccdomain)) {
1.227 raeburn 2197: &initialize_authen_forms($ccdomain,$formname);
2198:
1.190 raeburn 2199: my $choices = &Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc);
1.188 raeburn 2200: $outcome = <<ENDBADAUTH;
2201: <script type="text/javascript" language="Javascript">
1.301 bisitz 2202: // <![CDATA[
1.188 raeburn 2203: $loginscript
1.301 bisitz 2204: // ]]>
1.188 raeburn 2205: </script>
2206: <span class="LC_error">$lt{'err'}:
2207: $lt{'uuas'} ($currentauth). $lt{'sldb'}.</span>
2208: <h3>$lt{'ld'}</h3>
2209: $choices
2210: ENDBADAUTH
2211: } else {
2212: # This user is not allowed to modify the user's
2213: # authentication scheme, so just notify them of the problem
2214: $outcome = <<ENDBADAUTH;
2215: <span class="LC_error"> $lt{'err'}:
2216: $lt{'uuas'} ($currentauth). $lt{'adcs'}.
2217: </span>
2218: ENDBADAUTH
2219: }
2220: } else { # Authentication type is valid
1.418 raeburn 2221:
1.227 raeburn 2222: &initialize_authen_forms($ccdomain,$formname,$currentauth,'modifyuser');
1.205 raeburn 2223: my ($authformcurrent,$can_modify,@authform_others) =
1.188 raeburn 2224: &modify_login_block($ccdomain,$currentauth);
2225: if (&Apache::lonnet::allowed('mau',$ccdomain)) {
2226: # Current user has login modification privileges
2227: $outcome =
2228: '<script type="text/javascript" language="Javascript">'."\n".
1.301 bisitz 2229: '// <![CDATA['."\n".
1.188 raeburn 2230: $loginscript."\n".
1.301 bisitz 2231: '// ]]>'."\n".
1.188 raeburn 2232: '</script>'."\n".
2233: '<h3>'.$lt{'ld'}.'</h3>'.
2234: &Apache::loncommon::start_data_table().
1.205 raeburn 2235: &Apache::loncommon::start_data_table_row().
1.188 raeburn 2236: '<td>'.$authformnop;
1.418 raeburn 2237: if (($can_modify) && (&Apache::lonnet::allowed('mau',$ccdomain))) {
1.188 raeburn 2238: $outcome .= '</td>'."\n".
2239: &Apache::loncommon::end_data_table_row().
2240: &Apache::loncommon::start_data_table_row().
2241: '<td>'.$authformcurrent.'</td>'.
2242: &Apache::loncommon::end_data_table_row()."\n";
2243: } else {
1.200 raeburn 2244: $outcome .= ' ('.$authformcurrent.')</td>'.
2245: &Apache::loncommon::end_data_table_row()."\n";
1.188 raeburn 2246: }
1.418 raeburn 2247: if (&Apache::lonnet::allowed('mau',$ccdomain)) {
2248: foreach my $item (@authform_others) {
2249: $outcome .= &Apache::loncommon::start_data_table_row().
2250: '<td>'.$item.'</td>'.
2251: &Apache::loncommon::end_data_table_row()."\n";
2252: }
1.188 raeburn 2253: }
1.205 raeburn 2254: $outcome .= &Apache::loncommon::end_data_table();
1.188 raeburn 2255: } else {
1.418 raeburn 2256: if (&Apache::lonnet::allowed('udp',$ccdomain)) {
2257: # Current user has rights to view domain preferences for user's domain
2258: my $result;
2259: if ($currentauth =~ /^krb(4|5):([^:]*)$/) {
2260: my ($krbver,$krbrealm) = ($1,$2);
2261: if ($krbrealm eq '') {
2262: $result = &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
2263: } else {
2264: $result = &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
1.426 raeburn 2265: $krbrealm,$krbver);
1.418 raeburn 2266: }
2267: } elsif ($currentauth =~ /^internal:/) {
2268: $result = &mt('Currently internally authenticated.');
2269: } elsif ($currentauth =~ /^localauth:/) {
2270: $result = &mt('Currently using local (institutional) authentication.');
2271: } elsif ($currentauth =~ /^unix:/) {
2272: $result = &mt('Currently Filesystem Authenticated.');
2273: }
2274: $outcome = '<h3>'.$lt{'ld'}.'</h3>'.
2275: &Apache::loncommon::start_data_table().
2276: &Apache::loncommon::start_data_table_row().
2277: '<td>'.$result.'</td>'.
2278: &Apache::loncommon::end_data_table_row()."\n".
2279: &Apache::loncommon::end_data_table();
2280: } elsif (&Apache::lonnet::allowed('mau',$env{'request.role.domain'})) {
1.188 raeburn 2281: my %lt=&Apache::lonlocal::texthash(
2282: 'ccld' => "Change Current Login Data",
2283: 'yodo' => "You do not have privileges to modify the authentication configuration for this user.",
2284: 'ifch' => "If a change is required, contact a domain coordinator for the domain",
2285: );
2286: $outcome .= <<ENDNOPRIV;
2287: <h3>$lt{'ccld'}</h3>
2288: $lt{'yodo'} $lt{'ifch'}: $ccdomain
1.235 raeburn 2289: <input type="hidden" name="login" value="nochange" />
1.188 raeburn 2290: ENDNOPRIV
2291: }
2292: }
2293: } ## End of "check for bad authentication type" logic
2294: return $outcome;
2295: }
2296:
1.187 raeburn 2297: sub modify_login_block {
2298: my ($dom,$currentauth) = @_;
2299: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
2300: my ($authnum,%can_assign) =
2301: &Apache::loncommon::get_assignable_auth($dom);
1.205 raeburn 2302: my ($authformcurrent,@authform_others,$show_override_msg);
1.187 raeburn 2303: if ($currentauth=~/^krb(4|5):/) {
2304: $authformcurrent=$authformkrb;
2305: if ($can_assign{'int'}) {
1.205 raeburn 2306: push(@authform_others,$authformint);
1.187 raeburn 2307: }
2308: if ($can_assign{'loc'}) {
1.205 raeburn 2309: push(@authform_others,$authformloc);
1.187 raeburn 2310: }
2311: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
2312: $show_override_msg = 1;
2313: }
2314: } elsif ($currentauth=~/^internal:/) {
2315: $authformcurrent=$authformint;
2316: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205 raeburn 2317: push(@authform_others,$authformkrb);
1.187 raeburn 2318: }
2319: if ($can_assign{'loc'}) {
1.205 raeburn 2320: push(@authform_others,$authformloc);
1.187 raeburn 2321: }
2322: if ($can_assign{'int'}) {
2323: $show_override_msg = 1;
2324: }
2325: } elsif ($currentauth=~/^unix:/) {
2326: $authformcurrent=$authformfsys;
2327: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205 raeburn 2328: push(@authform_others,$authformkrb);
1.187 raeburn 2329: }
2330: if ($can_assign{'int'}) {
1.205 raeburn 2331: push(@authform_others,$authformint);
1.187 raeburn 2332: }
2333: if ($can_assign{'loc'}) {
1.205 raeburn 2334: push(@authform_others,$authformloc);
1.187 raeburn 2335: }
2336: if ($can_assign{'fsys'}) {
2337: $show_override_msg = 1;
2338: }
2339: } elsif ($currentauth=~/^localauth:/) {
2340: $authformcurrent=$authformloc;
2341: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205 raeburn 2342: push(@authform_others,$authformkrb);
1.187 raeburn 2343: }
2344: if ($can_assign{'int'}) {
1.205 raeburn 2345: push(@authform_others,$authformint);
1.187 raeburn 2346: }
2347: if ($can_assign{'loc'}) {
2348: $show_override_msg = 1;
2349: }
2350: }
2351: if ($show_override_msg) {
1.205 raeburn 2352: $authformcurrent = '<table><tr><td colspan="3">'.$authformcurrent.
2353: '</td></tr>'."\n".
2354: '<tr><td> </td>'.
2355: '<td><b>'.&mt('Currently in use').'</b></td>'.
2356: '<td align="right"><span class="LC_cusr_emph">'.
1.187 raeburn 2357: &mt('will override current values').
1.205 raeburn 2358: '</span></td></tr></table>';
1.187 raeburn 2359: }
1.205 raeburn 2360: return ($authformcurrent,$show_override_msg,@authform_others);
1.187 raeburn 2361: }
2362:
1.188 raeburn 2363: sub personal_data_display {
1.391 raeburn 2364: my ($ccuname,$ccdomain,$newuser,$context,$inst_results,$rolesarray,
1.443 raeburn 2365: $now,$captchaform,$emailusername,$usertype,$usernameset,$condition,$excluded) = @_;
1.388 bisitz 2366: my ($output,%userenv,%canmodify,%canmodify_status);
1.219 raeburn 2367: my @userinfo = ('firstname','middlename','lastname','generation',
2368: 'permanentemail','id');
1.252 raeburn 2369: my $rowcount = 0;
2370: my $editable = 0;
1.391 raeburn 2371: my %textboxsize = (
2372: firstname => '15',
2373: middlename => '15',
2374: lastname => '15',
2375: generation => '5',
2376: permanentemail => '25',
2377: id => '15',
2378: );
2379:
2380: my %lt=&Apache::lonlocal::texthash(
2381: 'pd' => "Personal Data",
2382: 'firstname' => "First Name",
2383: 'middlename' => "Middle Name",
2384: 'lastname' => "Last Name",
2385: 'generation' => "Generation",
2386: 'permanentemail' => "Permanent e-mail address",
2387: 'id' => "Student/Employee ID",
2388: 'lg' => "Login Data",
2389: 'inststatus' => "Affiliation",
2390: 'email' => 'E-mail address',
2391: 'valid' => 'Validation',
1.442 raeburn 2392: 'username' => 'Username',
1.391 raeburn 2393: );
2394:
2395: %canmodify_status =
1.286 raeburn 2396: &Apache::lonuserutils::can_modify_userinfo($context,$ccdomain,
2397: ['inststatus'],$rolesarray);
1.253 raeburn 2398: if (!$newuser) {
1.188 raeburn 2399: # Get the users information
2400: %userenv = &Apache::lonnet::get('environment',
2401: ['firstname','middlename','lastname','generation',
1.286 raeburn 2402: 'permanentemail','id','inststatus'],$ccdomain,$ccuname);
1.219 raeburn 2403: %canmodify =
2404: &Apache::lonuserutils::can_modify_userinfo($context,$ccdomain,
1.252 raeburn 2405: \@userinfo,$rolesarray);
1.257 raeburn 2406: } elsif ($context eq 'selfcreate') {
1.391 raeburn 2407: if ($newuser eq 'email') {
1.396 raeburn 2408: if (ref($emailusername) eq 'HASH') {
2409: if (ref($emailusername->{$usertype}) eq 'HASH') {
2410: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
1.442 raeburn 2411: @userinfo = ();
1.396 raeburn 2412: if ((ref($infofields) eq 'ARRAY') && (ref($infotitles) eq 'HASH')) {
2413: foreach my $field (@{$infofields}) {
2414: if ($emailusername->{$usertype}->{$field}) {
2415: push(@userinfo,$field);
2416: $canmodify{$field} = 1;
2417: unless ($textboxsize{$field}) {
2418: $textboxsize{$field} = 25;
2419: }
2420: unless ($lt{$field}) {
2421: $lt{$field} = $infotitles->{$field};
2422: }
2423: if ($emailusername->{$usertype}->{$field} eq 'required') {
2424: $lt{$field} .= '<b>*</b>';
2425: }
1.391 raeburn 2426: }
2427: }
2428: }
2429: }
2430: }
2431: } else {
2432: %canmodify = &selfcreate_canmodify($context,$ccdomain,\@userinfo,
2433: $inst_results,$rolesarray);
2434: }
1.188 raeburn 2435: }
1.391 raeburn 2436:
1.188 raeburn 2437: my $genhelp=&Apache::loncommon::help_open_topic('Generation');
2438: $output = '<h3>'.$lt{'pd'}.'</h3>'.
2439: &Apache::lonhtmlcommon::start_pick_box();
1.391 raeburn 2440: if (($context eq 'selfcreate') && ($newuser eq 'email')) {
1.443 raeburn 2441: my $size = 25;
1.442 raeburn 2442: if ($condition) {
1.443 raeburn 2443: if ($condition =~ /^\@[^\@]+$/) {
2444: $size = 10;
1.442 raeburn 2445: } else {
2446: undef($condition);
2447: }
1.443 raeburn 2448: }
2449: if ($excluded) {
2450: unless ($excluded =~ /^\@[^\@]+$/) {
2451: undef($condition);
2452: }
1.442 raeburn 2453: }
1.396 raeburn 2454: $output .= &Apache::lonhtmlcommon::row_title($lt{'email'}.'<b>*</b>',undef,
1.391 raeburn 2455: 'LC_oddrow_value')."\n".
1.443 raeburn 2456: '<input type="text" name="uname" size="'.$size.'" value="" autocomplete="off" />';
2457: if ($condition) {
2458: $output .= $condition;
2459: } elsif ($excluded) {
2460: $output .= '<br /><span style="font-size: smaller">'.&mt('You must use an e-mail address that does not end with [_1]',
2461: $excluded).'</span>';
2462: }
2463: if ($usernameset eq 'first') {
2464: $output .= '<br /><span style="font-size: smaller">';
2465: if ($condition) {
2466: $output .= &mt('Your username in LON-CAPA will be the part of your e-mail address before [_1]',
2467: $condition);
2468: } else {
2469: $output .= &mt('Your username in LON-CAPA will be the part of your e-mail address before the @');
2470: }
2471: $output .= '</span>';
2472: }
1.391 raeburn 2473: $rowcount ++;
2474: $output .= &Apache::lonhtmlcommon::row_closure(1);
1.408 raeburn 2475: my $upassone = '<input type="password" name="upass'.$now.'" size="20" autocomplete="off" />';
2476: my $upasstwo = '<input type="password" name="upasscheck'.$now.'" size="20" autocomplete="off" />';
1.396 raeburn 2477: $output .= &Apache::lonhtmlcommon::row_title(&mt('Password').'<b>*</b>',
1.391 raeburn 2478: 'LC_pick_box_title',
2479: 'LC_oddrow_value')."\n".
2480: $upassone."\n".
2481: &Apache::lonhtmlcommon::row_closure(1)."\n".
1.396 raeburn 2482: &Apache::lonhtmlcommon::row_title(&mt('Confirm password').'<b>*</b>',
1.391 raeburn 2483: 'LC_pick_box_title',
2484: 'LC_oddrow_value')."\n".
2485: $upasstwo.
2486: &Apache::lonhtmlcommon::row_closure()."\n";
1.443 raeburn 2487: if ($usernameset eq 'free') {
2488: my $onclick = "toggleUsernameDisp(this,'selfcreateusername');";
1.442 raeburn 2489: $output .= &Apache::lonhtmlcommon::row_title($lt{'username'},undef,'LC_oddrow_value')."\n".
2490: &mt('Use e-mail address: ').
2491: '<label><input type="radio" name="emailused" value="1" checked="checked" onclick="'.$onclick.'" />'.&mt('Yes').'</label>'."\n".
2492: (' 'x2).
2493: '<label><input type="radio" name="emailused" value="0" onclick="'.$onclick.'" />'.&mt('No').'</label>'."\n".
2494: '<div id="selfcreateusername" style="display: none; font-size: smaller">'.
2495: '<br /><span class="LC_nobreak">'.&mt('Preferred username').
2496: ' <input type="text" name="username" value="" size="20" autocomplete="off"/>'.
2497: '</span></div>'."\n".&Apache::lonhtmlcommon::row_closure(1);
2498: $rowcount ++;
2499: }
1.391 raeburn 2500: }
1.188 raeburn 2501: foreach my $item (@userinfo) {
2502: my $rowtitle = $lt{$item};
1.252 raeburn 2503: my $hiderow = 0;
1.188 raeburn 2504: if ($item eq 'generation') {
2505: $rowtitle = $genhelp.$rowtitle;
2506: }
1.252 raeburn 2507: my $row = &Apache::lonhtmlcommon::row_title($rowtitle,undef,'LC_oddrow_value')."\n";
1.188 raeburn 2508: if ($newuser) {
1.210 raeburn 2509: if (ref($inst_results) eq 'HASH') {
2510: if ($inst_results->{$item} ne '') {
1.252 raeburn 2511: $row .= '<input type="hidden" name="c'.$item.'" value="'.$inst_results->{$item}.'" />'.$inst_results->{$item};
1.210 raeburn 2512: } else {
1.252 raeburn 2513: if ($context eq 'selfcreate') {
1.391 raeburn 2514: if ($canmodify{$item}) {
1.394 raeburn 2515: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" autocomplete="off" />';
1.252 raeburn 2516: $editable ++;
2517: } else {
2518: $hiderow = 1;
2519: }
1.253 raeburn 2520: } else {
2521: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
1.252 raeburn 2522: }
1.210 raeburn 2523: }
1.188 raeburn 2524: } else {
1.252 raeburn 2525: if ($context eq 'selfcreate') {
1.401 raeburn 2526: if ($canmodify{$item}) {
2527: if ($newuser eq 'email') {
2528: $row .= '<input type="text" name="'.$item.'" size="'.$textboxsize{$item}.'" value="" autocomplete="off" />';
1.287 raeburn 2529: } else {
1.401 raeburn 2530: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" autocomplete="off" />';
1.287 raeburn 2531: }
1.401 raeburn 2532: $editable ++;
2533: } else {
2534: $hiderow = 1;
1.252 raeburn 2535: }
1.253 raeburn 2536: } else {
2537: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
1.252 raeburn 2538: }
1.188 raeburn 2539: }
2540: } else {
1.219 raeburn 2541: if ($canmodify{$item}) {
1.252 raeburn 2542: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="'.$userenv{$item}.'" />';
1.393 raeburn 2543: if (($item eq 'id') && (!$newuser)) {
2544: $row .= '<br />'.&Apache::lonuserutils::forceid_change($context);
2545: }
1.188 raeburn 2546: } else {
1.252 raeburn 2547: $row .= $userenv{$item};
1.188 raeburn 2548: }
2549: }
1.252 raeburn 2550: $row .= &Apache::lonhtmlcommon::row_closure(1);
2551: if (!$hiderow) {
2552: $output .= $row;
2553: $rowcount ++;
2554: }
1.188 raeburn 2555: }
1.286 raeburn 2556: if (($canmodify_status{'inststatus'}) || ($context ne 'selfcreate')) {
2557: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($ccdomain);
2558: if (ref($types) eq 'ARRAY') {
2559: if (@{$types} > 0) {
2560: my ($hiderow,$shown);
2561: if ($canmodify_status{'inststatus'}) {
2562: $shown = &pick_inst_statuses($userenv{'inststatus'},$usertypes,$types);
2563: } else {
2564: if ($userenv{'inststatus'} eq '') {
2565: $hiderow = 1;
1.334 raeburn 2566: } else {
2567: my @showitems;
2568: foreach my $item ( map { &unescape($_); } split(':',$userenv{'inststatus'})) {
2569: if (exists($usertypes->{$item})) {
2570: push(@showitems,$usertypes->{$item});
2571: } else {
2572: push(@showitems,$item);
2573: }
2574: }
2575: if (@showitems) {
2576: $shown = join(', ',@showitems);
2577: } else {
2578: $hiderow = 1;
2579: }
1.286 raeburn 2580: }
2581: }
2582: if (!$hiderow) {
1.389 bisitz 2583: my $row = &Apache::lonhtmlcommon::row_title(&mt('Affiliations'),undef,'LC_oddrow_value')."\n".
1.286 raeburn 2584: $shown.&Apache::lonhtmlcommon::row_closure(1);
2585: if ($context eq 'selfcreate') {
2586: $rowcount ++;
2587: }
2588: $output .= $row;
2589: }
2590: }
2591: }
2592: }
1.391 raeburn 2593: if (($context eq 'selfcreate') && ($newuser eq 'email')) {
2594: if ($captchaform) {
1.410 raeburn 2595: $output .= &Apache::lonhtmlcommon::row_title($lt{'valid'}.'*',
2596: 'LC_pick_box_title')."\n".
2597: $captchaform."\n".'<br /><br />'.
1.391 raeburn 2598: &Apache::lonhtmlcommon::row_closure(1);
2599: $rowcount ++;
2600: }
2601: my $submit_text = &mt('Create account');
2602: $output .= &Apache::lonhtmlcommon::row_title()."\n".
2603: '<br /><input type="submit" name="createaccount" value="'.
2604: $submit_text.'" />'.
1.396 raeburn 2605: '<input type="hidden" name="type" value="'.$usertype.'" />'.
1.391 raeburn 2606: &Apache::lonhtmlcommon::row_closure(1);
2607: }
1.188 raeburn 2608: $output .= &Apache::lonhtmlcommon::end_pick_box();
1.206 raeburn 2609: if (wantarray) {
1.252 raeburn 2610: if ($context eq 'selfcreate') {
2611: return($output,$rowcount,$editable);
2612: } else {
1.388 bisitz 2613: return $output;
1.252 raeburn 2614: }
1.206 raeburn 2615: } else {
2616: return $output;
2617: }
1.188 raeburn 2618: }
2619:
1.286 raeburn 2620: sub pick_inst_statuses {
2621: my ($curr,$usertypes,$types) = @_;
2622: my ($output,$rem,@currtypes);
2623: if ($curr ne '') {
2624: @currtypes = map { &unescape($_); } split(/:/,$curr);
2625: }
2626: my $numinrow = 2;
2627: if (ref($types) eq 'ARRAY') {
2628: $output = '<table>';
2629: my $lastcolspan;
2630: for (my $i=0; $i<@{$types}; $i++) {
2631: if (defined($usertypes->{$types->[$i]})) {
2632: my $rem = $i%($numinrow);
2633: if ($rem == 0) {
2634: if ($i<@{$types}-1) {
2635: if ($i > 0) {
2636: $output .= '</tr>';
2637: }
2638: $output .= '<tr>';
2639: }
2640: } elsif ($i==@{$types}-1) {
2641: my $colsleft = $numinrow - $rem;
2642: if ($colsleft > 1) {
2643: $lastcolspan = ' colspan="'.$colsleft.'"';
2644: }
2645: }
2646: my $check = ' ';
2647: if (grep(/^\Q$types->[$i]\E$/,@currtypes)) {
2648: $check = ' checked="checked" ';
2649: }
2650: $output .= '<td class="LC_left_item"'.$lastcolspan.'>'.
2651: '<span class="LC_nobreak"><label>'.
2652: '<input type="checkbox" name="inststatus" '.
2653: 'value="'.$types->[$i].'"'.$check.'/>'.
2654: $usertypes->{$types->[$i]}.'</label></span></td>';
2655: }
2656: }
2657: $output .= '</tr></table>';
2658: }
2659: return $output;
2660: }
2661:
1.257 raeburn 2662: sub selfcreate_canmodify {
2663: my ($context,$dom,$userinfo,$inst_results,$rolesarray) = @_;
2664: if (ref($inst_results) eq 'HASH') {
2665: my @inststatuses = &get_inststatuses($inst_results);
2666: if (@inststatuses == 0) {
2667: @inststatuses = ('default');
2668: }
2669: $rolesarray = \@inststatuses;
2670: }
2671: my %canmodify =
2672: &Apache::lonuserutils::can_modify_userinfo($context,$dom,$userinfo,
2673: $rolesarray);
2674: return %canmodify;
2675: }
2676:
1.252 raeburn 2677: sub get_inststatuses {
2678: my ($insthashref) = @_;
2679: my @inststatuses = ();
2680: if (ref($insthashref) eq 'HASH') {
2681: if (ref($insthashref->{'inststatus'}) eq 'ARRAY') {
2682: @inststatuses = @{$insthashref->{'inststatus'}};
2683: }
2684: }
2685: return @inststatuses;
2686: }
2687:
1.4 www 2688: # ================================================================= Phase Three
1.42 matthew 2689: sub update_user_data {
1.375 raeburn 2690: my ($r,$context,$crstype,$brcrum,$showcredits) = @_;
1.101 albertel 2691: my $uhome=&Apache::lonnet::homeserver($env{'form.ccuname'},
2692: $env{'form.ccdomain'});
1.27 matthew 2693: # Error messages
1.188 raeburn 2694: my $error = '<span class="LC_error">'.&mt('Error').': ';
1.193 raeburn 2695: my $end = '</span><br /><br />';
2696: my $rtnlink = '<a href="javascript:backPage(document.userupdate,'.
1.188 raeburn 2697: "'$env{'form.prevphase'}','modify')".'" />'.
1.219 raeburn 2698: &mt('Return to previous page').'</a>'.
2699: &Apache::loncommon::end_page();
2700: my $now = time;
1.40 www 2701: my $title;
1.101 albertel 2702: if (exists($env{'form.makeuser'})) {
1.40 www 2703: $title='Set Privileges for New User';
2704: } else {
2705: $title='Modify User Privileges';
2706: }
1.213 raeburn 2707: my $newuser = 0;
1.160 raeburn 2708: my ($jsback,$elements) = &crumb_utilities();
2709: my $jscript = '<script type="text/javascript">'."\n".
1.301 bisitz 2710: '// <![CDATA['."\n".
2711: $jsback."\n".
2712: '// ]]>'."\n".
2713: '</script>'."\n";
1.422 raeburn 2714: my %breadcrumb_text = &singleuser_breadcrumb($crstype,$context,$env{'form.ccdomain'});
1.351 raeburn 2715: push (@{$brcrum},
2716: {href => "javascript:backPage(document.userupdate)",
2717: text => $breadcrumb_text{'search'},
2718: faq => 282,
2719: bug => 'Instructor Interface',}
2720: );
2721: if ($env{'form.prevphase'} eq 'userpicked') {
2722: push(@{$brcrum},
2723: {href => "javascript:backPage(document.userupdate,'get_user_info','select')",
2724: text => $breadcrumb_text{'userpicked'},
2725: faq => 282,
2726: bug => 'Instructor Interface',});
1.233 raeburn 2727: }
1.224 raeburn 2728: my $helpitem = 'Course_Change_Privileges';
2729: if ($env{'form.action'} eq 'singlestudent') {
2730: $helpitem = 'Course_Add_Student';
1.439 raeburn 2731: } elsif ($context eq 'author') {
2732: $helpitem = 'Author_Change_Privileges';
2733: } elsif ($context eq 'domain') {
2734: $helpitem = 'Domain_Change_Privileges';
1.224 raeburn 2735: }
1.351 raeburn 2736: push(@{$brcrum},
2737: {href => "javascript:backPage(document.userupdate,'$env{'form.prevphase'}','modify')",
2738: text => $breadcrumb_text{'modify'},
2739: faq => 282,
2740: bug => 'Instructor Interface',},
2741: {href => "/adm/createuser",
2742: text => "Result",
2743: faq => 282,
2744: bug => 'Instructor Interface',
2745: help => $helpitem});
2746: my $args = {bread_crumbs => $brcrum,
2747: bread_crumbs_component => 'User Management'};
2748: if ($env{'form.popup'}) {
2749: $args->{'no_nav_bar'} = 1;
2750: }
2751: $r->print(&Apache::loncommon::start_page($title,$jscript,$args));
1.188 raeburn 2752: $r->print(&update_result_form($uhome));
1.27 matthew 2753: # Check Inputs
1.101 albertel 2754: if (! $env{'form.ccuname'} ) {
1.193 raeburn 2755: $r->print($error.&mt('No login name specified').'.'.$end.$rtnlink);
1.27 matthew 2756: return;
2757: }
1.138 albertel 2758: if ( $env{'form.ccuname'} ne
2759: &LONCAPA::clean_username($env{'form.ccuname'}) ) {
1.281 bisitz 2760: $r->print($error.&mt('Invalid login name.').' '.
2761: &mt('Only letters, numbers, periods, dashes, @, and underscores are valid.').
1.193 raeburn 2762: $end.$rtnlink);
1.27 matthew 2763: return;
2764: }
1.101 albertel 2765: if (! $env{'form.ccdomain'} ) {
1.193 raeburn 2766: $r->print($error.&mt('No domain specified').'.'.$end.$rtnlink);
1.27 matthew 2767: return;
2768: }
1.138 albertel 2769: if ( $env{'form.ccdomain'} ne
2770: &LONCAPA::clean_domain($env{'form.ccdomain'}) ) {
1.281 bisitz 2771: $r->print($error.&mt('Invalid domain name.').' '.
2772: &mt('Only letters, numbers, periods, dashes, and underscores are valid.').
1.193 raeburn 2773: $end.$rtnlink);
1.27 matthew 2774: return;
2775: }
1.219 raeburn 2776: if ($uhome eq 'no_host') {
2777: $newuser = 1;
2778: }
1.101 albertel 2779: if (! exists($env{'form.makeuser'})) {
1.29 matthew 2780: # Modifying an existing user, so check the validity of the name
2781: if ($uhome eq 'no_host') {
1.389 bisitz 2782: $r->print(
2783: $error
2784: .'<p class="LC_error">'
2785: .&mt('Unable to determine home server for [_1] in domain [_2].',
2786: '"'.$env{'form.ccuname'}.'"','"'.$env{'form.ccdomain'}.'"')
2787: .'</p>');
1.29 matthew 2788: return;
2789: }
2790: }
1.27 matthew 2791: # Determine authentication method and password for the user being modified
2792: my $amode='';
2793: my $genpwd='';
1.101 albertel 2794: if ($env{'form.login'} eq 'krb') {
1.41 albertel 2795: $amode='krb';
1.101 albertel 2796: $amode.=$env{'form.krbver'};
2797: $genpwd=$env{'form.krbarg'};
2798: } elsif ($env{'form.login'} eq 'int') {
1.27 matthew 2799: $amode='internal';
1.101 albertel 2800: $genpwd=$env{'form.intarg'};
2801: } elsif ($env{'form.login'} eq 'fsys') {
1.27 matthew 2802: $amode='unix';
1.101 albertel 2803: $genpwd=$env{'form.fsysarg'};
2804: } elsif ($env{'form.login'} eq 'loc') {
1.27 matthew 2805: $amode='localauth';
1.101 albertel 2806: $genpwd=$env{'form.locarg'};
1.27 matthew 2807: $genpwd=" " if (!$genpwd);
1.101 albertel 2808: } elsif (($env{'form.login'} eq 'nochange') ||
2809: ($env{'form.login'} eq '' )) {
1.34 matthew 2810: # There is no need to tell the user we did not change what they
2811: # did not ask us to change.
1.35 matthew 2812: # If they are creating a new user but have not specified login
2813: # information this will be caught below.
1.30 matthew 2814: } else {
1.367 golterma 2815: $r->print($error.&mt('Invalid login mode or password').$end.$rtnlink);
2816: return;
1.27 matthew 2817: }
1.164 albertel 2818:
1.188 raeburn 2819: $r->print('<h3>'.&mt('User [_1] in domain [_2]',
1.367 golterma 2820: $env{'form.ccuname'}.' ('.&Apache::loncommon::plainname($env{'form.ccuname'},
2821: $env{'form.ccdomain'}).')', $env{'form.ccdomain'}).'</h3>');
2822: my %prog_state = &Apache::lonhtmlcommon::Create_PrgWin($r,2);
1.344 bisitz 2823:
1.193 raeburn 2824: my (%alerts,%rulematch,%inst_results,%curr_rules);
1.334 raeburn 2825: my @userinfo = ('firstname','middlename','lastname','generation','permanentemail','id');
1.361 raeburn 2826: my @usertools = ('aboutme','blog','webdav','portfolio');
1.411 raeburn 2827: my @requestcourses = ('official','unofficial','community','textbook','placement');
1.362 raeburn 2828: my @requestauthor = ('requestauthor');
1.286 raeburn 2829: my ($othertitle,$usertypes,$types) =
2830: &Apache::loncommon::sorted_inst_types($env{'form.ccdomain'});
1.334 raeburn 2831: my %canmodify_status =
2832: &Apache::lonuserutils::can_modify_userinfo($context,$env{'form.ccdomain'},
2833: ['inststatus']);
1.101 albertel 2834: if ($env{'form.makeuser'}) {
1.164 albertel 2835: $r->print('<h3>'.&mt('Creating new account.').'</h3>');
1.27 matthew 2836: # Check for the authentication mode and password
2837: if (! $amode || ! $genpwd) {
1.193 raeburn 2838: $r->print($error.&mt('Invalid login mode or password').$end.$rtnlink);
1.27 matthew 2839: return;
1.18 albertel 2840: }
1.29 matthew 2841: # Determine desired host
1.101 albertel 2842: my $desiredhost = $env{'form.hserver'};
1.29 matthew 2843: if (lc($desiredhost) eq 'default') {
2844: $desiredhost = undef;
2845: } else {
1.147 albertel 2846: my %home_servers =
2847: &Apache::lonnet::get_servers($env{'form.ccdomain'},'library');
1.29 matthew 2848: if (! exists($home_servers{$desiredhost})) {
1.193 raeburn 2849: $r->print($error.&mt('Invalid home server specified').$end.$rtnlink);
2850: return;
2851: }
2852: }
2853: # Check ID format
2854: my %checkhash;
2855: my %checks = ('id' => 1);
2856: %{$checkhash{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}}} = (
1.219 raeburn 2857: 'newuser' => $newuser,
1.196 raeburn 2858: 'id' => $env{'form.cid'},
1.193 raeburn 2859: );
1.196 raeburn 2860: if ($env{'form.cid'} ne '') {
2861: &Apache::loncommon::user_rule_check(\%checkhash,\%checks,\%alerts,
2862: \%rulematch,\%inst_results,\%curr_rules);
2863: if (ref($alerts{'id'}) eq 'HASH') {
2864: if (ref($alerts{'id'}{$env{'form.ccdomain'}}) eq 'HASH') {
2865: my $domdesc =
2866: &Apache::lonnet::domain($env{'form.ccdomain'},'description');
2867: if ($alerts{'id'}{$env{'form.ccdomain'}}{$env{'form.cid'}}) {
2868: my $userchkmsg;
2869: if (ref($curr_rules{$env{'form.ccdomain'}}) eq 'HASH') {
2870: $userchkmsg =
2871: &Apache::loncommon::instrule_disallow_msg('id',
2872: $domdesc,1).
2873: &Apache::loncommon::user_rule_formats($env{'form.ccdomain'},
2874: $domdesc,$curr_rules{$env{'form.ccdomain'}}{'id'},'id');
2875: }
2876: $r->print($error.&mt('Invalid ID format').$end.
2877: $userchkmsg.$rtnlink);
2878: return;
2879: }
2880: }
1.29 matthew 2881: }
2882: }
1.367 golterma 2883: &Apache::lonhtmlcommon::Increment_PrgWin($r, \%prog_state);
1.27 matthew 2884: # Call modifyuser
2885: my $result = &Apache::lonnet::modifyuser
1.193 raeburn 2886: ($env{'form.ccdomain'},$env{'form.ccuname'},$env{'form.cid'},
1.188 raeburn 2887: $amode,$genpwd,$env{'form.cfirstname'},
2888: $env{'form.cmiddlename'},$env{'form.clastname'},
2889: $env{'form.cgeneration'},undef,$desiredhost,
2890: $env{'form.cpermanentemail'});
1.77 www 2891: $r->print(&mt('Generating user').': '.$result);
1.219 raeburn 2892: $uhome = &Apache::lonnet::homeserver($env{'form.ccuname'},
1.101 albertel 2893: $env{'form.ccdomain'});
1.334 raeburn 2894: my (%changeHash,%newcustom,%changed,%changedinfo);
1.267 raeburn 2895: if ($uhome ne 'no_host') {
1.334 raeburn 2896: if ($context eq 'domain') {
1.378 raeburn 2897: foreach my $name ('portfolio','author') {
2898: if ($env{'form.custom_'.$name.'quota'} == 1) {
2899: if ($env{'form.'.$name.'quota'} eq '') {
2900: $newcustom{$name.'quota'} = 0;
2901: } else {
2902: $newcustom{$name.'quota'} = $env{'form.'.$name.'quota'};
2903: $newcustom{$name.'quota'} =~ s/[^\d\.]//g;
2904: }
2905: if ("a_admin($newcustom{$name.'quota'},\%changeHash,$name)) {
2906: $changed{$name.'quota'} = 1;
2907: }
1.334 raeburn 2908: }
2909: }
2910: foreach my $item (@usertools) {
2911: if ($env{'form.custom'.$item} == 1) {
2912: $newcustom{$item} = $env{'form.tools_'.$item};
2913: $changed{$item} = &tool_admin($item,$newcustom{$item},
2914: \%changeHash,'tools');
2915: }
1.267 raeburn 2916: }
1.334 raeburn 2917: foreach my $item (@requestcourses) {
1.341 raeburn 2918: if ($env{'form.custom'.$item} == 1) {
2919: $newcustom{$item} = $env{'form.crsreq_'.$item};
2920: if ($env{'form.crsreq_'.$item} eq 'autolimit') {
2921: $newcustom{$item} .= '=';
1.383 raeburn 2922: $env{'form.crsreq_'.$item.'_limit'} =~ s/\D+//g;
2923: if ($env{'form.crsreq_'.$item.'_limit'}) {
1.341 raeburn 2924: $newcustom{$item} .= $env{'form.crsreq_'.$item.'_limit'};
2925: }
1.334 raeburn 2926: }
1.341 raeburn 2927: $changed{$item} = &tool_admin($item,$newcustom{$item},
2928: \%changeHash,'requestcourses');
1.334 raeburn 2929: }
1.275 raeburn 2930: }
1.362 raeburn 2931: if ($env{'form.customrequestauthor'} == 1) {
2932: $newcustom{'requestauthor'} = $env{'form.requestauthor'};
2933: $changed{'requestauthor'} = &tool_admin('requestauthor',
2934: $newcustom{'requestauthor'},
2935: \%changeHash,'requestauthor');
2936: }
1.275 raeburn 2937: }
1.334 raeburn 2938: if ($canmodify_status{'inststatus'}) {
2939: if (exists($env{'form.inststatus'})) {
2940: my @inststatuses = &Apache::loncommon::get_env_multiple('form.inststatus');
2941: if (@inststatuses > 0) {
2942: $changeHash{'inststatus'} = join(',',@inststatuses);
2943: $changed{'inststatus'} = $changeHash{'inststatus'};
1.306 raeburn 2944: }
2945: }
1.232 raeburn 2946: }
1.334 raeburn 2947: if (keys(%changed)) {
2948: foreach my $item (@userinfo) {
2949: $changeHash{$item} = $env{'form.c'.$item};
1.286 raeburn 2950: }
1.267 raeburn 2951: my $chgresult =
2952: &Apache::lonnet::put('environment',\%changeHash,
2953: $env{'form.ccdomain'},$env{'form.ccuname'});
2954: }
1.232 raeburn 2955: }
1.219 raeburn 2956: $r->print('<br />'.&mt('Home server').': '.$uhome.' '.
2957: &Apache::lonnet::hostname($uhome));
1.101 albertel 2958: } elsif (($env{'form.login'} ne 'nochange') &&
2959: ($env{'form.login'} ne '' )) {
1.27 matthew 2960: # Modify user privileges
2961: if (! $amode || ! $genpwd) {
1.193 raeburn 2962: $r->print($error.'Invalid login mode or password'.$end.$rtnlink);
1.27 matthew 2963: return;
1.20 harris41 2964: }
1.395 bisitz 2965: # Only allow authentication modification if the person has authority
1.101 albertel 2966: if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'})) {
1.20 harris41 2967: $r->print('Modifying authentication: '.
1.31 matthew 2968: &Apache::lonnet::modifyuserauth(
1.101 albertel 2969: $env{'form.ccdomain'},$env{'form.ccuname'},
1.21 harris41 2970: $amode,$genpwd));
1.102 albertel 2971: $r->print('<br />'.&mt('Home server').': '.&Apache::lonnet::homeserver
1.101 albertel 2972: ($env{'form.ccuname'},$env{'form.ccdomain'}));
1.4 www 2973: } else {
1.27 matthew 2974: # Okay, this is a non-fatal error.
1.395 bisitz 2975: $r->print($error.&mt('You do not have the authority to modify this users authentication information.').$end);
1.27 matthew 2976: }
1.28 matthew 2977: }
1.344 bisitz 2978: $r->rflush(); # Finish display of header before time consuming actions start
1.367 golterma 2979: &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state);
1.28 matthew 2980: ##
1.375 raeburn 2981: my (@userroles,%userupdate,$cnum,$cdom,$defaultcredits,%namechanged);
1.213 raeburn 2982: if ($context eq 'course') {
1.375 raeburn 2983: ($cnum,$cdom) =
2984: &Apache::lonuserutils::get_course_identity();
1.318 raeburn 2985: $crstype = &Apache::loncommon::course_type($cdom.'_'.$cnum);
1.375 raeburn 2986: if ($showcredits) {
2987: $defaultcredits = &Apache::lonuserutils::get_defaultcredits($cdom,$cnum);
2988: }
1.213 raeburn 2989: }
1.101 albertel 2990: if (! $env{'form.makeuser'} ) {
1.28 matthew 2991: # Check for need to change
2992: my %userenv = &Apache::lonnet::get
1.134 raeburn 2993: ('environment',['firstname','middlename','lastname','generation',
1.378 raeburn 2994: 'id','permanentemail','portfolioquota','authorquota','inststatus',
2995: 'tools.aboutme','tools.blog','tools.webdav','tools.portfolio',
1.361 raeburn 2996: 'requestcourses.official','requestcourses.unofficial',
1.384 raeburn 2997: 'requestcourses.community','requestcourses.textbook',
2998: 'reqcrsotherdom.official','reqcrsotherdom.unofficial',
2999: 'reqcrsotherdom.community','reqcrsotherdom.textbook',
1.427 raeburn 3000: 'reqcrsotherdom.placement','requestauthor'],
1.160 raeburn 3001: $env{'form.ccdomain'},$env{'form.ccuname'});
1.28 matthew 3002: my ($tmp) = keys(%userenv);
3003: if ($tmp =~ /^(con_lost|error)/i) {
3004: %userenv = ();
3005: }
1.206 raeburn 3006: my $no_forceid_alert;
3007: # Check to see if user information can be changed
3008: my %domconfig =
3009: &Apache::lonnet::get_dom('configuration',['usermodification'],
3010: $env{'form.ccdomain'});
1.213 raeburn 3011: my @statuses = ('active','future');
3012: my %roles = &Apache::lonnet::get_my_roles($env{'form.ccuname'},$env{'form.ccdomain'},'userroles',\@statuses,undef,$env{'request.role.domain'});
3013: my ($auname,$audom);
1.220 raeburn 3014: if ($context eq 'author') {
1.206 raeburn 3015: $auname = $env{'user.name'};
3016: $audom = $env{'user.domain'};
3017: }
3018: foreach my $item (keys(%roles)) {
1.220 raeburn 3019: my ($rolenum,$roledom,$role) = split(/:/,$item,-1);
1.206 raeburn 3020: if ($context eq 'course') {
3021: if ($cnum ne '' && $cdom ne '') {
3022: if ($rolenum eq $cnum && $roledom eq $cdom) {
3023: if (!grep(/^\Q$role\E$/,@userroles)) {
3024: push(@userroles,$role);
3025: }
3026: }
3027: }
3028: } elsif ($context eq 'author') {
3029: if ($rolenum eq $auname && $roledom eq $audom) {
3030: if (!grep(/^\Q$role\E$/,@userroles)) {
3031: push(@userroles,$role);
3032: }
3033: }
3034: }
3035: }
1.220 raeburn 3036: if ($env{'form.action'} eq 'singlestudent') {
3037: if (!grep(/^st$/,@userroles)) {
3038: push(@userroles,'st');
3039: }
3040: } else {
3041: # Check for course or co-author roles being activated or re-enabled
3042: if ($context eq 'author' || $context eq 'course') {
3043: foreach my $key (keys(%env)) {
3044: if ($context eq 'author') {
3045: if ($key=~/^form\.act_\Q$audom\E_\Q$auname\E_([^_]+)/) {
3046: if (!grep(/^\Q$1\E$/,@userroles)) {
3047: push(@userroles,$1);
3048: }
3049: } elsif ($key =~/^form\.ren\:\Q$audom\E\/\Q$auname\E_([^_]+)/) {
3050: if (!grep(/^\Q$1\E$/,@userroles)) {
3051: push(@userroles,$1);
3052: }
1.206 raeburn 3053: }
1.220 raeburn 3054: } elsif ($context eq 'course') {
3055: if ($key=~/^form\.act_\Q$cdom\E_\Q$cnum\E_([^_]+)/) {
3056: if (!grep(/^\Q$1\E$/,@userroles)) {
3057: push(@userroles,$1);
3058: }
3059: } elsif ($key =~/^form\.ren\:\Q$cdom\E\/\Q$cnum\E(\/?\w*)_([^_]+)/) {
3060: if (!grep(/^\Q$1\E$/,@userroles)) {
3061: push(@userroles,$1);
3062: }
1.206 raeburn 3063: }
3064: }
3065: }
3066: }
3067: }
3068: #Check to see if we can change personal data for the user
3069: my (@mod_disallowed,@longroles);
3070: foreach my $role (@userroles) {
3071: if ($role eq 'cr') {
3072: push(@longroles,'Custom');
3073: } else {
1.318 raeburn 3074: push(@longroles,&Apache::lonnet::plaintext($role,$crstype));
1.206 raeburn 3075: }
3076: }
1.219 raeburn 3077: my %canmodify = &Apache::lonuserutils::can_modify_userinfo($context,$env{'form.ccdomain'},\@userinfo,\@userroles);
3078: foreach my $item (@userinfo) {
1.28 matthew 3079: # Strip leading and trailing whitespace
1.203 raeburn 3080: $env{'form.c'.$item} =~ s/(\s+$|^\s+)//g;
1.219 raeburn 3081: if (!$canmodify{$item}) {
1.207 raeburn 3082: if (defined($env{'form.c'.$item})) {
3083: if ($env{'form.c'.$item} ne $userenv{$item}) {
3084: push(@mod_disallowed,$item);
3085: }
1.206 raeburn 3086: }
3087: $env{'form.c'.$item} = $userenv{$item};
3088: }
1.28 matthew 3089: }
1.259 bisitz 3090: # Check to see if we can change the Student/Employee ID
1.196 raeburn 3091: my $forceid = $env{'form.forceid'};
3092: my $recurseid = $env{'form.recurseid'};
3093: my (%alerts,%rulematch,%idinst_results,%curr_rules,%got_rules);
1.203 raeburn 3094: my %uidhash = &Apache::lonnet::idrget($env{'form.ccdomain'},
3095: $env{'form.ccuname'});
3096: if (($uidhash{$env{'form.ccuname'}}) &&
3097: ($uidhash{$env{'form.ccuname'}}!~/error\:/) &&
3098: (!$forceid)) {
3099: if ($env{'form.cid'} ne $uidhash{$env{'form.ccuname'}}) {
3100: $env{'form.cid'} = $userenv{'id'};
1.293 bisitz 3101: $no_forceid_alert = &mt('New student/employee ID does not match existing ID for this user.')
1.259 bisitz 3102: .'<br />'
3103: .&mt("Change is not permitted without checking the 'Force ID change' checkbox on the previous page.")
3104: .'<br />'."\n";
1.203 raeburn 3105: }
3106: }
3107: if ($env{'form.cid'} ne $userenv{'id'}) {
1.196 raeburn 3108: my $checkhash;
3109: my $checks = { 'id' => 1 };
3110: $checkhash->{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}} =
3111: { 'newuser' => $newuser,
3112: 'id' => $env{'form.cid'},
3113: };
3114: &Apache::loncommon::user_rule_check($checkhash,$checks,
3115: \%alerts,\%rulematch,\%idinst_results,\%curr_rules,\%got_rules);
3116: if (ref($alerts{'id'}) eq 'HASH') {
3117: if (ref($alerts{'id'}{$env{'form.ccdomain'}}) eq 'HASH') {
1.203 raeburn 3118: $env{'form.cid'} = $userenv{'id'};
1.196 raeburn 3119: }
3120: }
3121: }
1.378 raeburn 3122: my (%quotachanged,%oldquota,%newquota,%olddefquota,%newdefquota,
3123: $oldinststatus,$newinststatus,%oldisdefault,%newisdefault,%oldsettings,
1.339 raeburn 3124: %oldsettingstext,%newsettings,%newsettingstext,@disporder,
1.378 raeburn 3125: %oldsettingstatus,%newsettingstatus);
1.334 raeburn 3126: @disporder = ('inststatus');
3127: if ($env{'request.role.domain'} eq $env{'form.ccdomain'}) {
1.362 raeburn 3128: push(@disporder,'requestcourses','requestauthor');
1.334 raeburn 3129: } else {
3130: push(@disporder,'reqcrsotherdom');
3131: }
3132: push(@disporder,('quota','tools'));
1.338 raeburn 3133: $oldinststatus = $userenv{'inststatus'};
1.378 raeburn 3134: foreach my $name ('portfolio','author') {
3135: ($olddefquota{$name},$oldsettingstatus{$name}) =
3136: &Apache::loncommon::default_quota($env{'form.ccdomain'},$oldinststatus,$name);
3137: ($newdefquota{$name},$newsettingstatus{$name}) = ($olddefquota{$name},$oldsettingstatus{$name});
3138: }
1.334 raeburn 3139: my %canshow;
1.220 raeburn 3140: if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
1.334 raeburn 3141: $canshow{'quota'} = 1;
1.220 raeburn 3142: }
1.267 raeburn 3143: if (&Apache::lonnet::allowed('mut',$env{'form.ccdomain'})) {
1.334 raeburn 3144: $canshow{'tools'} = 1;
1.267 raeburn 3145: }
1.275 raeburn 3146: if (&Apache::lonnet::allowed('ccc',$env{'form.ccdomain'})) {
1.334 raeburn 3147: $canshow{'requestcourses'} = 1;
1.300 raeburn 3148: } elsif (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
1.334 raeburn 3149: $canshow{'reqcrsotherdom'} = 1;
1.275 raeburn 3150: }
1.286 raeburn 3151: if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'})) {
1.334 raeburn 3152: $canshow{'inststatus'} = 1;
1.286 raeburn 3153: }
1.362 raeburn 3154: if (&Apache::lonnet::allowed('cau',$env{'form.ccdomain'})) {
3155: $canshow{'requestauthor'} = 1;
3156: }
1.267 raeburn 3157: my (%changeHash,%changed);
1.286 raeburn 3158: if ($oldinststatus eq '') {
1.334 raeburn 3159: $oldsettings{'inststatus'} = $othertitle;
1.286 raeburn 3160: } else {
3161: if (ref($usertypes) eq 'HASH') {
1.334 raeburn 3162: $oldsettings{'inststatus'} = join(', ',map{ $usertypes->{ &unescape($_) }; } (split(/:/,$userenv{'inststatus'})));
1.286 raeburn 3163: } else {
1.334 raeburn 3164: $oldsettings{'inststatus'} = join(', ',map{ &unescape($_); } (split(/:/,$userenv{'inststatus'})));
1.286 raeburn 3165: }
3166: }
3167: $changeHash{'inststatus'} = $userenv{'inststatus'};
1.334 raeburn 3168: if ($canmodify_status{'inststatus'}) {
3169: $canshow{'inststatus'} = 1;
1.286 raeburn 3170: if (exists($env{'form.inststatus'})) {
3171: my @inststatuses = &Apache::loncommon::get_env_multiple('form.inststatus');
3172: if (@inststatuses > 0) {
3173: $newinststatus = join(':',map { &escape($_); } @inststatuses);
3174: $changeHash{'inststatus'} = $newinststatus;
3175: if ($newinststatus ne $oldinststatus) {
3176: $changed{'inststatus'} = $newinststatus;
1.378 raeburn 3177: foreach my $name ('portfolio','author') {
3178: ($newdefquota{$name},$newsettingstatus{$name}) =
3179: &Apache::loncommon::default_quota($env{'form.ccdomain'},$newinststatus,$name);
3180: }
1.286 raeburn 3181: }
3182: if (ref($usertypes) eq 'HASH') {
1.334 raeburn 3183: $newsettings{'inststatus'} = join(', ',map{ $usertypes->{$_}; } (@inststatuses));
1.286 raeburn 3184: } else {
1.337 raeburn 3185: $newsettings{'inststatus'} = join(', ',@inststatuses);
1.286 raeburn 3186: }
1.334 raeburn 3187: }
3188: } else {
3189: $newinststatus = '';
3190: $changeHash{'inststatus'} = $newinststatus;
3191: $newsettings{'inststatus'} = $othertitle;
3192: if ($newinststatus ne $oldinststatus) {
3193: $changed{'inststatus'} = $changeHash{'inststatus'};
1.378 raeburn 3194: foreach my $name ('portfolio','author') {
3195: ($newdefquota{$name},$newsettingstatus{$name}) =
3196: &Apache::loncommon::default_quota($env{'form.ccdomain'},$newinststatus,$name);
3197: }
1.286 raeburn 3198: }
3199: }
1.334 raeburn 3200: } elsif ($context ne 'selfcreate') {
3201: $canshow{'inststatus'} = 1;
1.337 raeburn 3202: $newsettings{'inststatus'} = $oldsettings{'inststatus'};
1.286 raeburn 3203: }
1.378 raeburn 3204: foreach my $name ('portfolio','author') {
3205: $changeHash{$name.'quota'} = $userenv{$name.'quota'};
3206: }
1.334 raeburn 3207: if ($context eq 'domain') {
1.378 raeburn 3208: foreach my $name ('portfolio','author') {
3209: if ($userenv{$name.'quota'} ne '') {
3210: $oldquota{$name} = $userenv{$name.'quota'};
3211: if ($env{'form.custom_'.$name.'quota'} == 1) {
3212: if ($env{'form.'.$name.'quota'} eq '') {
3213: $newquota{$name} = 0;
3214: } else {
3215: $newquota{$name} = $env{'form.'.$name.'quota'};
3216: $newquota{$name} =~ s/[^\d\.]//g;
3217: }
3218: if ($newquota{$name} != $oldquota{$name}) {
3219: if ("a_admin($newquota{$name},\%changeHash,$name)) {
3220: $changed{$name.'quota'} = 1;
3221: }
3222: }
1.334 raeburn 3223: } else {
1.378 raeburn 3224: if ("a_admin('',\%changeHash,$name)) {
3225: $changed{$name.'quota'} = 1;
3226: $newquota{$name} = $newdefquota{$name};
3227: $newisdefault{$name} = 1;
3228: }
1.334 raeburn 3229: }
1.149 raeburn 3230: } else {
1.378 raeburn 3231: $oldisdefault{$name} = 1;
3232: $oldquota{$name} = $olddefquota{$name};
3233: if ($env{'form.custom_'.$name.'quota'} == 1) {
3234: if ($env{'form.'.$name.'quota'} eq '') {
3235: $newquota{$name} = 0;
3236: } else {
3237: $newquota{$name} = $env{'form.'.$name.'quota'};
3238: $newquota{$name} =~ s/[^\d\.]//g;
3239: }
3240: if ("a_admin($newquota{$name},\%changeHash,$name)) {
3241: $changed{$name.'quota'} = 1;
3242: }
1.334 raeburn 3243: } else {
1.378 raeburn 3244: $newquota{$name} = $newdefquota{$name};
3245: $newisdefault{$name} = 1;
1.334 raeburn 3246: }
1.378 raeburn 3247: }
3248: if ($oldisdefault{$name}) {
3249: $oldsettingstext{'quota'}{$name} = &get_defaultquota_text($oldsettingstatus{$name});
1.383 raeburn 3250: } else {
3251: $oldsettingstext{'quota'}{$name} = &mt('custom quota: [_1] MB',$oldquota{$name});
1.378 raeburn 3252: }
3253: if ($newisdefault{$name}) {
3254: $newsettingstext{'quota'}{$name} = &get_defaultquota_text($newsettingstatus{$name});
1.383 raeburn 3255: } else {
3256: $newsettingstext{'quota'}{$name} = &mt('custom quota: [_1] MB',$newquota{$name});
1.134 raeburn 3257: }
3258: }
1.334 raeburn 3259: &tool_changes('tools',\@usertools,\%oldsettings,\%oldsettingstext,\%userenv,
3260: \%changeHash,\%changed,\%newsettings,\%newsettingstext);
3261: if ($env{'form.ccdomain'} eq $env{'request.role.domain'}) {
3262: &tool_changes('requestcourses',\@requestcourses,\%oldsettings,\%oldsettingstext,
3263: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
1.384 raeburn 3264: &tool_changes('requestauthor',\@requestauthor,\%oldsettings,\%oldsettingstext,
3265: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
1.149 raeburn 3266: } else {
1.334 raeburn 3267: &tool_changes('reqcrsotherdom',\@requestcourses,\%oldsettings,\%oldsettingstext,
3268: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
1.149 raeburn 3269: }
3270: }
1.334 raeburn 3271: foreach my $item (@userinfo) {
3272: if ($env{'form.c'.$item} ne $userenv{$item}) {
3273: $namechanged{$item} = 1;
3274: }
1.204 raeburn 3275: }
1.378 raeburn 3276: foreach my $name ('portfolio','author') {
1.390 bisitz 3277: $oldsettings{'quota'}{$name} = &mt('[_1] MB',$oldquota{$name});
3278: $newsettings{'quota'}{$name} = &mt('[_1] MB',$newquota{$name});
1.378 raeburn 3279: }
1.334 raeburn 3280: if ((keys(%namechanged) > 0) || (keys(%changed) > 0)) {
1.267 raeburn 3281: my ($chgresult,$namechgresult);
3282: if (keys(%changed) > 0) {
3283: $chgresult =
1.204 raeburn 3284: &Apache::lonnet::put('environment',\%changeHash,
3285: $env{'form.ccdomain'},$env{'form.ccuname'});
1.267 raeburn 3286: if ($chgresult eq 'ok') {
3287: if (($env{'user.name'} eq $env{'form.ccuname'}) &&
3288: ($env{'user.domain'} eq $env{'form.ccdomain'})) {
1.270 raeburn 3289: my %newenvhash;
3290: foreach my $key (keys(%changed)) {
1.411 raeburn 3291: if (($key eq 'official') || ($key eq 'unofficial') ||
3292: ($key eq 'community') || ($key eq 'textbook') ||
3293: ($key eq 'placement')) {
1.279 raeburn 3294: $newenvhash{'environment.requestcourses.'.$key} =
3295: $changeHash{'requestcourses.'.$key};
1.362 raeburn 3296: if ($changeHash{'requestcourses.'.$key}) {
1.332 raeburn 3297: $newenvhash{'environment.canrequest.'.$key} = 1;
1.279 raeburn 3298: } else {
3299: $newenvhash{'environment.canrequest.'.$key} =
3300: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
3301: $key,'reload','requestcourses');
3302: }
1.362 raeburn 3303: } elsif ($key eq 'requestauthor') {
3304: $newenvhash{'environment.'.$key} = $changeHash{$key};
3305: if ($changeHash{$key}) {
3306: $newenvhash{'environment.canrequest.author'} = 1;
3307: } else {
3308: $newenvhash{'environment.canrequest.author'} =
3309: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
3310: $key,'reload','requestauthor');
3311: }
1.275 raeburn 3312: } elsif ($key ne 'quota') {
1.270 raeburn 3313: $newenvhash{'environment.tools.'.$key} =
3314: $changeHash{'tools.'.$key};
1.279 raeburn 3315: if ($changeHash{'tools.'.$key} ne '') {
3316: $newenvhash{'environment.availabletools.'.$key} =
3317: $changeHash{'tools.'.$key};
3318: } else {
3319: $newenvhash{'environment.availabletools.'.$key} =
1.367 golterma 3320: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
3321: $key,'reload','tools');
1.279 raeburn 3322: }
1.270 raeburn 3323: }
3324: }
1.271 raeburn 3325: if (keys(%newenvhash)) {
3326: &Apache::lonnet::appenv(\%newenvhash);
3327: }
1.267 raeburn 3328: }
3329: }
1.204 raeburn 3330: }
1.334 raeburn 3331: if (keys(%namechanged) > 0) {
1.337 raeburn 3332: foreach my $field (@userinfo) {
3333: $changeHash{$field} = $env{'form.c'.$field};
3334: }
3335: # Make the change
1.204 raeburn 3336: $namechgresult =
3337: &Apache::lonnet::modifyuser($env{'form.ccdomain'},
3338: $env{'form.ccuname'},$changeHash{'id'},undef,undef,
3339: $changeHash{'firstname'},$changeHash{'middlename'},
3340: $changeHash{'lastname'},$changeHash{'generation'},
1.337 raeburn 3341: $changeHash{'id'},undef,$changeHash{'permanentemail'},undef,\@userinfo);
1.220 raeburn 3342: %userupdate = (
3343: lastname => $env{'form.clastname'},
3344: middlename => $env{'form.cmiddlename'},
3345: firstname => $env{'form.cfirstname'},
3346: generation => $env{'form.cgeneration'},
3347: id => $env{'form.cid'},
3348: );
1.204 raeburn 3349: }
1.334 raeburn 3350: if (((keys(%namechanged) > 0) && $namechgresult eq 'ok') ||
1.267 raeburn 3351: ((keys(%changed) > 0) && $chgresult eq 'ok')) {
1.28 matthew 3352: # Tell the user we changed the name
1.334 raeburn 3353: &display_userinfo($r,1,\@disporder,\%canshow,\@requestcourses,
1.362 raeburn 3354: \@usertools,\@requestauthor,\%userenv,\%changed,\%namechanged,
1.334 raeburn 3355: \%oldsettings, \%oldsettingstext,\%newsettings,
3356: \%newsettingstext);
1.203 raeburn 3357: if ($env{'form.cid'} ne $userenv{'id'}) {
3358: &Apache::lonnet::idput($env{'form.ccdomain'},
1.407 raeburn 3359: {$env{'form.ccuname'} => $env{'form.cid'}},$uhome,'ids');
1.203 raeburn 3360: if (($recurseid) &&
3361: (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'}))) {
3362: my $idresult =
3363: &Apache::lonuserutils::propagate_id_change(
3364: $env{'form.ccuname'},$env{'form.ccdomain'},
3365: \%userupdate);
3366: $r->print('<br />'.$idresult.'<br />');
3367: }
1.196 raeburn 3368: }
1.149 raeburn 3369: if (($env{'form.ccdomain'} eq $env{'user.domain'}) &&
3370: ($env{'form.ccuname'} eq $env{'user.name'})) {
3371: my %newenvhash;
3372: foreach my $key (keys(%changeHash)) {
3373: $newenvhash{'environment.'.$key} = $changeHash{$key};
3374: }
1.238 raeburn 3375: &Apache::lonnet::appenv(\%newenvhash);
1.149 raeburn 3376: }
1.28 matthew 3377: } else { # error occurred
1.389 bisitz 3378: $r->print(
3379: '<p class="LC_error">'
3380: .&mt('Unable to successfully change environment for [_1] in domain [_2].',
3381: '"'.$env{'form.ccuname'}.'"',
3382: '"'.$env{'form.ccdomain'}.'"')
3383: .'</p>');
1.28 matthew 3384: }
1.334 raeburn 3385: } else { # End of if ($env ... ) logic
1.275 raeburn 3386: # They did not want to change the users name, quota, tool availability,
3387: # or ability to request creation of courses,
1.267 raeburn 3388: # but we can still tell them what the name and quota and availabilities are
1.334 raeburn 3389: &display_userinfo($r,undef,\@disporder,\%canshow,\@requestcourses,
1.362 raeburn 3390: \@usertools,\@requestauthor,\%userenv,\%changed,\%namechanged,\%oldsettings,
1.334 raeburn 3391: \%oldsettingstext,\%newsettings,\%newsettingstext);
1.28 matthew 3392: }
1.206 raeburn 3393: if (@mod_disallowed) {
3394: my ($rolestr,$contextname);
3395: if (@longroles > 0) {
3396: $rolestr = join(', ',@longroles);
3397: } else {
3398: $rolestr = &mt('No roles');
3399: }
3400: if ($context eq 'course') {
1.399 bisitz 3401: $contextname = 'course';
1.206 raeburn 3402: } elsif ($context eq 'author') {
1.399 bisitz 3403: $contextname = 'co-author';
1.206 raeburn 3404: }
3405: $r->print(&mt('The following fields were not updated: ').'<ul>');
3406: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
3407: foreach my $field (@mod_disallowed) {
3408: $r->print('<li>'.$fieldtitles{$field}.'</li>'."\n");
3409: }
1.207 raeburn 3410: $r->print('</ul>');
3411: if (@mod_disallowed == 1) {
1.399 bisitz 3412: $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 3413: } else {
1.399 bisitz 3414: $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 3415: }
1.292 bisitz 3416: my $helplink = 'javascript:helpMenu('."'display'".')';
3417: $r->print('<span class="LC_cusr_emph">'.$rolestr.'</span><br />'
3418: .&mt('Please contact your [_1]helpdesk[_2] for more information.'
3419: ,'<a href="'.$helplink.'">','</a>')
3420: .'<br />');
1.206 raeburn 3421: }
1.259 bisitz 3422: $r->print('<span class="LC_warning">'
3423: .$no_forceid_alert
3424: .&Apache::lonuserutils::print_namespacing_alerts($env{'form.ccdomain'},\%alerts,\%curr_rules)
3425: .'</span>');
1.4 www 3426: }
1.367 golterma 3427: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
1.220 raeburn 3428: if ($env{'form.action'} eq 'singlestudent') {
1.375 raeburn 3429: &enroll_single_student($r,$uhome,$amode,$genpwd,$now,$newuser,$context,
3430: $crstype,$showcredits,$defaultcredits);
1.386 bisitz 3431: my $linktext = ($crstype eq 'Community' ?
3432: &mt('Enroll Another Member') : &mt('Enroll Another Student'));
3433: $r->print(
3434: &Apache::lonhtmlcommon::actionbox([
3435: '<a href="javascript:backPage(document.userupdate)">'
3436: .($crstype eq 'Community' ?
3437: &mt('Enroll Another Member') : &mt('Enroll Another Student'))
3438: .'</a>']));
1.220 raeburn 3439: } else {
1.375 raeburn 3440: my @rolechanges = &update_roles($r,$context,$showcredits);
1.334 raeburn 3441: if (keys(%namechanged) > 0) {
1.220 raeburn 3442: if ($context eq 'course') {
3443: if (@userroles > 0) {
1.225 raeburn 3444: if ((@rolechanges == 0) ||
3445: (!(grep(/^st$/,@rolechanges)))) {
3446: if (grep(/^st$/,@userroles)) {
3447: my $classlistupdated =
3448: &Apache::lonuserutils::update_classlist($cdom,
1.220 raeburn 3449: $cnum,$env{'form.ccdomain'},
3450: $env{'form.ccuname'},\%userupdate);
1.225 raeburn 3451: }
1.220 raeburn 3452: }
3453: }
3454: }
3455: }
1.226 raeburn 3456: my $userinfo = &Apache::loncommon::plainname($env{'form.ccuname'},
1.233 raeburn 3457: $env{'form.ccdomain'});
3458: if ($env{'form.popup'}) {
3459: $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a></p>');
3460: } else {
1.367 golterma 3461: $r->print('<br />'.&Apache::lonhtmlcommon::actionbox(['<a href="javascript:backPage(document.userupdate,'."'$env{'form.prevphase'}','modify'".')">'
3462: .&mt('Modify this user: [_1]','<span class="LC_cusr_emph">'.$env{'form.ccuname'}.':'.$env{'form.ccdomain'}.' ('.$userinfo.')</span>').'</a>',
3463: '<a href="javascript:backPage(document.userupdate)">'.&mt('Create/Modify Another User').'</a>']));
1.233 raeburn 3464: }
1.220 raeburn 3465: }
3466: }
3467:
1.334 raeburn 3468: sub display_userinfo {
1.362 raeburn 3469: my ($r,$changed,$order,$canshow,$requestcourses,$usertools,$requestauthor,
3470: $userenv,$changedhash,$namechangedhash,$oldsetting,$oldsettingtext,
1.334 raeburn 3471: $newsetting,$newsettingtext) = @_;
3472: return unless (ref($order) eq 'ARRAY' &&
3473: ref($canshow) eq 'HASH' &&
3474: ref($requestcourses) eq 'ARRAY' &&
1.362 raeburn 3475: ref($requestauthor) eq 'ARRAY' &&
1.334 raeburn 3476: ref($usertools) eq 'ARRAY' &&
3477: ref($userenv) eq 'HASH' &&
3478: ref($changedhash) eq 'HASH' &&
3479: ref($oldsetting) eq 'HASH' &&
3480: ref($oldsettingtext) eq 'HASH' &&
3481: ref($newsetting) eq 'HASH' &&
3482: ref($newsettingtext) eq 'HASH');
3483: my %lt=&Apache::lonlocal::texthash(
1.372 raeburn 3484: 'ui' => 'User Information',
1.334 raeburn 3485: 'uic' => 'User Information Changed',
3486: 'firstname' => 'First Name',
3487: 'middlename' => 'Middle Name',
3488: 'lastname' => 'Last Name',
3489: 'generation' => 'Generation',
3490: 'id' => 'Student/Employee ID',
3491: 'permanentemail' => 'Permanent e-mail address',
1.378 raeburn 3492: 'portfolioquota' => 'Disk space allocated to portfolio files',
1.385 bisitz 3493: 'authorquota' => 'Disk space allocated to Authoring Space',
1.334 raeburn 3494: 'blog' => 'Blog Availability',
1.361 raeburn 3495: 'webdav' => 'WebDAV Availability',
1.334 raeburn 3496: 'aboutme' => 'Personal Information Page Availability',
3497: 'portfolio' => 'Portfolio Availability',
3498: 'official' => 'Can Request Official Courses',
3499: 'unofficial' => 'Can Request Unofficial Courses',
3500: 'community' => 'Can Request Communities',
1.384 raeburn 3501: 'textbook' => 'Can Request Textbook Courses',
1.411 raeburn 3502: 'placement' => 'Can Request Placement Tests',
1.362 raeburn 3503: 'requestauthor' => 'Can Request Author Role',
1.334 raeburn 3504: 'inststatus' => "Affiliation",
3505: 'prvs' => 'Previous Value:',
3506: 'chto' => 'Changed To:'
3507: );
3508: if ($changed) {
1.372 raeburn 3509: $r->print('<h3>'.$lt{'uic'}.'</h3>'.
1.367 golterma 3510: &Apache::loncommon::start_data_table().
3511: &Apache::loncommon::start_data_table_header_row());
1.334 raeburn 3512: $r->print("<th> </th>\n");
1.367 golterma 3513: $r->print('<th><b>'.$lt{'prvs'}.'</b></th>');
3514: $r->print('<th><span class="LC_nobreak"><b>'.$lt{'chto'}.'</b></span></th>');
3515: $r->print(&Apache::loncommon::end_data_table_header_row());
3516: my @userinfo = ('firstname','middlename','lastname','generation','permanentemail','id');
3517:
1.334 raeburn 3518: foreach my $item (@userinfo) {
3519: my $value = $env{'form.c'.$item};
1.367 golterma 3520: #show changes only:
1.383 raeburn 3521: unless ($value eq $userenv->{$item}){
1.367 golterma 3522: $r->print(&Apache::loncommon::start_data_table_row());
3523: $r->print("<td>$lt{$item}</td>\n");
1.383 raeburn 3524: $r->print("<td>".$userenv->{$item}."</td>\n");
1.367 golterma 3525: $r->print("<td>$value </td>\n");
3526: $r->print(&Apache::loncommon::end_data_table_row());
1.334 raeburn 3527: }
3528: }
3529: foreach my $entry (@{$order}) {
1.383 raeburn 3530: if ($canshow->{$entry}) {
3531: if (($entry eq 'requestcourses') || ($entry eq 'reqcrsotherdom') || ($entry eq 'requestauthor')) {
3532: my @items;
3533: if ($entry eq 'requestauthor') {
3534: @items = ($entry);
3535: } else {
3536: @items = @{$requestcourses};
1.384 raeburn 3537: }
1.383 raeburn 3538: foreach my $item (@items) {
3539: if (($newsetting->{$item} ne $oldsetting->{$item}) ||
3540: ($newsettingtext->{$item} ne $oldsettingtext->{$item})) {
3541: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3542: $r->print("<td>$lt{$item}</td>\n");
3543: $r->print("<td>".$oldsetting->{$item});
3544: if ($oldsettingtext->{$item}) {
3545: if ($oldsetting->{$item}) {
3546: $r->print(' -- ');
3547: }
3548: $r->print($oldsettingtext->{$item});
3549: }
3550: $r->print("</td>\n");
3551: $r->print("<td>".$newsetting->{$item});
3552: if ($newsettingtext->{$item}) {
3553: if ($newsetting->{$item}) {
3554: $r->print(' -- ');
3555: }
3556: $r->print($newsettingtext->{$item});
3557: }
3558: $r->print("</td>\n");
3559: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.334 raeburn 3560: }
3561: }
3562: } elsif ($entry eq 'tools') {
3563: foreach my $item (@{$usertools}) {
1.383 raeburn 3564: if ($newsetting->{$item} ne $oldsetting->{$item}) {
3565: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3566: $r->print("<td>$lt{$item}</td>\n");
3567: $r->print("<td>".$oldsetting->{$item}.' '.$oldsettingtext->{$item}."</td>\n");
3568: $r->print("<td>".$newsetting->{$item}.' '.$newsettingtext->{$item}."</td>\n");
3569: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.334 raeburn 3570: }
3571: }
1.378 raeburn 3572: } elsif ($entry eq 'quota') {
3573: if ((ref($oldsetting->{$entry}) eq 'HASH') && (ref($oldsettingtext->{$entry}) eq 'HASH') &&
3574: (ref($newsetting->{$entry}) eq 'HASH') && (ref($newsettingtext->{$entry}) eq 'HASH')) {
3575: foreach my $name ('portfolio','author') {
1.383 raeburn 3576: if ($newsetting->{$entry}->{$name} ne $oldsetting->{$entry}->{$name}) {
3577: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3578: $r->print("<td>$lt{$name.$entry}</td>\n");
3579: $r->print("<td>".$oldsettingtext->{$entry}->{$name}."</td>\n");
3580: $r->print("<td>".$newsettingtext->{$entry}->{$name}."</td>\n");
3581: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.378 raeburn 3582: }
3583: }
3584: }
1.334 raeburn 3585: } else {
1.383 raeburn 3586: if ($newsetting->{$entry} ne $oldsetting->{$entry}) {
3587: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3588: $r->print("<td>$lt{$entry}</td>\n");
3589: $r->print("<td>".$oldsetting->{$entry}.' '.$oldsettingtext->{$entry}."</td>\n");
3590: $r->print("<td>".$newsetting->{$entry}.' '.$newsettingtext->{$entry}."</td>\n");
3591: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.334 raeburn 3592: }
3593: }
3594: }
3595: }
1.367 golterma 3596: $r->print(&Apache::loncommon::end_data_table().'<br />');
1.372 raeburn 3597: } else {
3598: $r->print('<h3>'.$lt{'ui'}.'</h3>'.
3599: '<p>'.&mt('No changes made to user information').'</p>');
1.334 raeburn 3600: }
3601: return;
3602: }
3603:
1.275 raeburn 3604: sub tool_changes {
3605: my ($context,$usertools,$oldaccess,$oldaccesstext,$userenv,$changeHash,
3606: $changed,$newaccess,$newaccesstext) = @_;
3607: if (!((ref($usertools) eq 'ARRAY') && (ref($oldaccess) eq 'HASH') &&
3608: (ref($oldaccesstext) eq 'HASH') && (ref($userenv) eq 'HASH') &&
3609: (ref($changeHash) eq 'HASH') && (ref($changed) eq 'HASH') &&
3610: (ref($newaccess) eq 'HASH') && (ref($newaccesstext) eq 'HASH'))) {
3611: return;
3612: }
1.383 raeburn 3613: my %reqdisplay = &requestchange_display();
1.300 raeburn 3614: if ($context eq 'reqcrsotherdom') {
1.309 raeburn 3615: my @options = ('approval','validate','autolimit');
1.306 raeburn 3616: my $optregex = join('|',@options);
1.300 raeburn 3617: my $cdom = $env{'request.role.domain'};
3618: foreach my $tool (@{$usertools}) {
1.383 raeburn 3619: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
1.314 raeburn 3620: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
1.300 raeburn 3621: $changeHash->{$context.'.'.$tool} = $userenv->{$context.'.'.$tool};
1.383 raeburn 3622: my ($newop,$limit);
1.314 raeburn 3623: if ($env{'form.'.$context.'_'.$tool}) {
3624: $newop = $env{'form.'.$context.'_'.$tool};
3625: if ($newop eq 'autolimit') {
1.383 raeburn 3626: $limit = $env{'form.'.$context.'_'.$tool.'_limit'};
1.314 raeburn 3627: $limit =~ s/\D+//g;
3628: $newop .= '='.$limit;
3629: }
3630: }
1.300 raeburn 3631: if ($userenv->{$context.'.'.$tool} eq '') {
1.314 raeburn 3632: if ($newop) {
3633: $changed->{$tool}=&tool_admin($tool,$cdom.':'.$newop,
1.300 raeburn 3634: $changeHash,$context);
3635: if ($changed->{$tool}) {
1.383 raeburn 3636: if ($newop =~ /^autolimit/) {
3637: if ($limit) {
3638: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3639: } else {
3640: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3641: }
3642: } else {
3643: $newaccesstext->{$tool} = $reqdisplay{$newop};
3644: }
1.300 raeburn 3645: } else {
3646: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
3647: }
3648: }
3649: } else {
3650: my @curr = split(',',$userenv->{$context.'.'.$tool});
3651: my @new;
3652: my $changedoms;
1.314 raeburn 3653: foreach my $req (@curr) {
3654: if ($req =~ /^\Q$cdom\E\:($optregex\=?\d*)$/) {
3655: my $oldop = $1;
1.383 raeburn 3656: if ($oldop =~ /^autolimit=(\d*)/) {
3657: my $limit = $1;
3658: if ($limit) {
3659: $oldaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3660: } else {
3661: $oldaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3662: }
3663: } else {
3664: $oldaccesstext->{$tool} = $reqdisplay{$oldop};
3665: }
1.314 raeburn 3666: if ($oldop ne $newop) {
3667: $changedoms = 1;
3668: foreach my $item (@curr) {
3669: my ($reqdom,$option) = split(':',$item);
3670: unless ($reqdom eq $cdom) {
3671: push(@new,$item);
3672: }
3673: }
3674: if ($newop) {
3675: push(@new,$cdom.':'.$newop);
1.300 raeburn 3676: }
1.314 raeburn 3677: @new = sort(@new);
1.300 raeburn 3678: }
1.314 raeburn 3679: last;
1.300 raeburn 3680: }
1.314 raeburn 3681: }
3682: if ((!$changedoms) && ($newop)) {
1.300 raeburn 3683: $changedoms = 1;
1.306 raeburn 3684: @new = sort(@curr,$cdom.':'.$newop);
1.300 raeburn 3685: }
3686: if ($changedoms) {
1.314 raeburn 3687: my $newdomstr;
1.300 raeburn 3688: if (@new) {
3689: $newdomstr = join(',',@new);
3690: }
3691: $changed->{$tool}=&tool_admin($tool,$newdomstr,$changeHash,
3692: $context);
3693: if ($changed->{$tool}) {
3694: if ($env{'form.'.$context.'_'.$tool}) {
1.306 raeburn 3695: if ($env{'form.'.$context.'_'.$tool} eq 'autolimit') {
1.314 raeburn 3696: my $limit = $env{'form.'.$context.'_'.$tool.'_limit'};
3697: $limit =~ s/\D+//g;
3698: if ($limit) {
1.383 raeburn 3699: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
1.314 raeburn 3700: } else {
1.383 raeburn 3701: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
1.306 raeburn 3702: }
1.314 raeburn 3703: } else {
1.306 raeburn 3704: $newaccesstext->{$tool} = $reqdisplay{$env{'form.'.$context.'_'.$tool}};
3705: }
1.300 raeburn 3706: } else {
1.383 raeburn 3707: $newaccesstext->{$tool} = &mt("availability set to 'off'");
1.300 raeburn 3708: }
3709: }
3710: }
3711: }
3712: }
3713: return;
3714: }
1.275 raeburn 3715: foreach my $tool (@{$usertools}) {
1.383 raeburn 3716: my ($newval,$limit,$envkey);
1.362 raeburn 3717: $envkey = $context.'.'.$tool;
1.306 raeburn 3718: if ($context eq 'requestcourses') {
3719: $newval = $env{'form.crsreq_'.$tool};
3720: if ($newval eq 'autolimit') {
1.383 raeburn 3721: $limit = $env{'form.crsreq_'.$tool.'_limit'};
3722: $limit =~ s/\D+//g;
3723: $newval .= '='.$limit;
1.306 raeburn 3724: }
1.362 raeburn 3725: } elsif ($context eq 'requestauthor') {
3726: $newval = $env{'form.'.$context};
3727: $envkey = $context;
1.314 raeburn 3728: } else {
1.306 raeburn 3729: $newval = $env{'form.'.$context.'_'.$tool};
3730: }
1.362 raeburn 3731: if ($userenv->{$envkey} ne '') {
1.275 raeburn 3732: $oldaccess->{$tool} = &mt('custom');
1.383 raeburn 3733: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3734: if ($userenv->{$envkey} =~ /^autolimit=(\d*)$/) {
3735: my $currlimit = $1;
3736: if ($currlimit eq '') {
3737: $oldaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3738: } else {
3739: $oldaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$currlimit);
3740: }
3741: } elsif ($userenv->{$envkey}) {
3742: $oldaccesstext->{$tool} = $reqdisplay{$userenv->{$envkey}};
3743: } else {
3744: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
3745: }
1.275 raeburn 3746: } else {
1.383 raeburn 3747: if ($userenv->{$envkey}) {
3748: $oldaccesstext->{$tool} = &mt("availability set to 'on'");
3749: } else {
3750: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
3751: }
1.275 raeburn 3752: }
1.362 raeburn 3753: $changeHash->{$envkey} = $userenv->{$envkey};
1.275 raeburn 3754: if ($env{'form.custom'.$tool} == 1) {
1.362 raeburn 3755: if ($newval ne $userenv->{$envkey}) {
1.306 raeburn 3756: $changed->{$tool} = &tool_admin($tool,$newval,$changeHash,
3757: $context);
1.275 raeburn 3758: if ($changed->{$tool}) {
3759: $newaccess->{$tool} = &mt('custom');
1.383 raeburn 3760: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3761: if ($newval =~ /^autolimit/) {
3762: if ($limit) {
3763: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3764: } else {
3765: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3766: }
3767: } elsif ($newval) {
3768: $newaccesstext->{$tool} = $reqdisplay{$newval};
3769: } else {
3770: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3771: }
1.275 raeburn 3772: } else {
1.383 raeburn 3773: if ($newval) {
3774: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3775: } else {
3776: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3777: }
1.275 raeburn 3778: }
3779: } else {
3780: $newaccess->{$tool} = $oldaccess->{$tool};
1.383 raeburn 3781: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3782: if ($newval =~ /^autolimit/) {
3783: if ($limit) {
3784: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3785: } else {
3786: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3787: }
3788: } elsif ($newval) {
3789: $newaccesstext->{$tool} = $reqdisplay{$newval};
3790: } else {
3791: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3792: }
1.275 raeburn 3793: } else {
1.383 raeburn 3794: if ($userenv->{$context.'.'.$tool}) {
3795: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3796: } else {
3797: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3798: }
1.275 raeburn 3799: }
3800: }
3801: } else {
3802: $newaccess->{$tool} = $oldaccess->{$tool};
3803: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
3804: }
3805: } else {
3806: $changed->{$tool} = &tool_admin($tool,'',$changeHash,$context);
3807: if ($changed->{$tool}) {
3808: $newaccess->{$tool} = &mt('default');
3809: } else {
3810: $newaccess->{$tool} = $oldaccess->{$tool};
1.383 raeburn 3811: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3812: if ($newval =~ /^autolimit/) {
3813: if ($limit) {
3814: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3815: } else {
3816: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3817: }
3818: } elsif ($newval) {
3819: $newaccesstext->{$tool} = $reqdisplay{$newval};
3820: } else {
3821: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3822: }
1.275 raeburn 3823: } else {
1.383 raeburn 3824: if ($userenv->{$context.'.'.$tool}) {
3825: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3826: } else {
3827: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3828: }
1.275 raeburn 3829: }
3830: }
3831: }
3832: } else {
3833: $oldaccess->{$tool} = &mt('default');
3834: if ($env{'form.custom'.$tool} == 1) {
1.306 raeburn 3835: $changed->{$tool} = &tool_admin($tool,$newval,$changeHash,
3836: $context);
1.275 raeburn 3837: if ($changed->{$tool}) {
3838: $newaccess->{$tool} = &mt('custom');
1.383 raeburn 3839: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3840: if ($newval =~ /^autolimit/) {
3841: if ($limit) {
3842: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3843: } else {
3844: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3845: }
3846: } elsif ($newval) {
3847: $newaccesstext->{$tool} = $reqdisplay{$newval};
3848: } else {
3849: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3850: }
1.275 raeburn 3851: } else {
1.383 raeburn 3852: if ($newval) {
3853: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3854: } else {
3855: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3856: }
1.275 raeburn 3857: }
3858: } else {
3859: $newaccess->{$tool} = $oldaccess->{$tool};
3860: }
3861: } else {
3862: $newaccess->{$tool} = $oldaccess->{$tool};
3863: }
3864: }
3865: }
3866: return;
3867: }
3868:
1.220 raeburn 3869: sub update_roles {
1.375 raeburn 3870: my ($r,$context,$showcredits) = @_;
1.4 www 3871: my $now=time;
1.225 raeburn 3872: my @rolechanges;
1.220 raeburn 3873: my %disallowed;
1.73 sakharuk 3874: $r->print('<h3>'.&mt('Modifying Roles').'</h3>');
1.404 raeburn 3875: foreach my $key (keys(%env)) {
1.135 raeburn 3876: next if (! $env{$key});
1.190 raeburn 3877: next if ($key eq 'form.action');
1.27 matthew 3878: # Revoke roles
1.135 raeburn 3879: if ($key=~/^form\.rev/) {
3880: if ($key=~/^form\.rev\:([^\_]+)\_([^\_\.]+)$/) {
1.64 www 3881: # Revoke standard role
1.170 albertel 3882: my ($scope,$role) = ($1,$2);
3883: my $result =
3884: &Apache::lonnet::revokerole($env{'form.ccdomain'},
3885: $env{'form.ccuname'},
1.239 raeburn 3886: $scope,$role,'','',$context);
1.367 golterma 3887: $r->print(&Apache::lonhtmlcommon::confirm_success(
1.369 bisitz 3888: &mt('Revoking [_1] in [_2]',
3889: &Apache::lonnet::plaintext($role),
1.372 raeburn 3890: &Apache::loncommon::show_role_extent($scope,$context,$role)),
1.369 bisitz 3891: $result ne "ok").'<br />');
3892: if ($result ne "ok") {
3893: $r->print(&mt('Error: [_1]',$result).'<br />');
3894: }
1.170 albertel 3895: if ($role eq 'st') {
1.202 raeburn 3896: my $result =
1.198 raeburn 3897: &Apache::lonuserutils::classlist_drop($scope,
3898: $env{'form.ccuname'},$env{'form.ccdomain'},
1.202 raeburn 3899: $now);
1.367 golterma 3900: $r->print(&Apache::lonhtmlcommon::confirm_success($result));
1.53 www 3901: }
1.225 raeburn 3902: if (!grep(/^\Q$role\E$/,@rolechanges)) {
3903: push(@rolechanges,$role);
3904: }
1.196 raeburn 3905: }
1.195 raeburn 3906: if ($key=~m{^form\.rev\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}s) {
1.64 www 3907: # Revoke custom role
1.369 bisitz 3908: my $result = &Apache::lonnet::revokecustomrole(
3909: $env{'form.ccdomain'},$env{'form.ccuname'},$1,$2,$3,$4,'','',$context);
1.367 golterma 3910: $r->print(&Apache::lonhtmlcommon::confirm_success(
1.369 bisitz 3911: &mt('Revoking custom role [_1] by [_2] in [_3]',
1.372 raeburn 3912: $4,$3.':'.$2,&Apache::loncommon::show_role_extent($1,$context,'cr')),
1.369 bisitz 3913: $result ne 'ok').'<br />');
3914: if ($result ne "ok") {
3915: $r->print(&mt('Error: [_1]',$result).'<br />');
3916: }
1.225 raeburn 3917: if (!grep(/^cr$/,@rolechanges)) {
3918: push(@rolechanges,'cr');
3919: }
1.64 www 3920: }
1.135 raeburn 3921: } elsif ($key=~/^form\.del/) {
3922: if ($key=~/^form\.del\:([^\_]+)\_([^\_\.]+)$/) {
1.116 raeburn 3923: # Delete standard role
1.170 albertel 3924: my ($scope,$role) = ($1,$2);
3925: my $result =
3926: &Apache::lonnet::assignrole($env{'form.ccdomain'},
3927: $env{'form.ccuname'},
1.239 raeburn 3928: $scope,$role,$now,0,1,'',
3929: $context);
1.367 golterma 3930: $r->print(&Apache::lonhtmlcommon::confirm_success(
3931: &mt('Deleting [_1] in [_2]',
1.369 bisitz 3932: &Apache::lonnet::plaintext($role),
1.372 raeburn 3933: &Apache::loncommon::show_role_extent($scope,$context,$role)),
1.369 bisitz 3934: $result ne 'ok').'<br />');
3935: if ($result ne "ok") {
3936: $r->print(&mt('Error: [_1]',$result).'<br />');
3937: }
1.367 golterma 3938:
1.170 albertel 3939: if ($role eq 'st') {
1.202 raeburn 3940: my $result =
1.198 raeburn 3941: &Apache::lonuserutils::classlist_drop($scope,
3942: $env{'form.ccuname'},$env{'form.ccdomain'},
1.202 raeburn 3943: $now);
1.369 bisitz 3944: $r->print(&Apache::lonhtmlcommon::confirm_success($result));
1.81 albertel 3945: }
1.225 raeburn 3946: if (!grep(/^\Q$role\E$/,@rolechanges)) {
3947: push(@rolechanges,$role);
3948: }
1.116 raeburn 3949: }
1.139 albertel 3950: if ($key=~m{^form\.del\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
1.116 raeburn 3951: my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
3952: # Delete custom role
1.369 bisitz 3953: my $result =
3954: &Apache::lonnet::assigncustomrole($env{'form.ccdomain'},
3955: $env{'form.ccuname'},$url,$rdom,$rnam,$rolename,$now,
3956: 0,1,$context);
3957: $r->print(&Apache::lonhtmlcommon::confirm_success(&mt('Deleting custom role [_1] by [_2] in [_3]',
1.372 raeburn 3958: $rolename,$rnam.':'.$rdom,&Apache::loncommon::show_role_extent($1,$context,'cr')),
1.369 bisitz 3959: $result ne "ok").'<br />');
3960: if ($result ne "ok") {
3961: $r->print(&mt('Error: [_1]',$result).'<br />');
3962: }
1.367 golterma 3963:
1.225 raeburn 3964: if (!grep(/^cr$/,@rolechanges)) {
3965: push(@rolechanges,'cr');
3966: }
1.116 raeburn 3967: }
1.135 raeburn 3968: } elsif ($key=~/^form\.ren/) {
1.101 albertel 3969: my $udom = $env{'form.ccdomain'};
3970: my $uname = $env{'form.ccuname'};
1.116 raeburn 3971: # Re-enable standard role
1.135 raeburn 3972: if ($key=~/^form\.ren\:([^\_]+)\_([^\_\.]+)$/) {
1.89 raeburn 3973: my $url = $1;
3974: my $role = $2;
3975: my $logmsg;
3976: my $output;
3977: if ($role eq 'st') {
1.141 albertel 3978: if ($url =~ m-^/($match_domain)/($match_courseid)/?(\w*)$-) {
1.374 raeburn 3979: my ($cdom,$cnum,$csec) = ($1,$2,$3);
1.375 raeburn 3980: my $credits;
3981: if ($showcredits) {
3982: my $defaultcredits =
3983: &Apache::lonuserutils::get_defaultcredits($cdom,$cnum);
3984: $credits = &get_user_credits($defaultcredits,$cdom,$cnum);
3985: }
3986: my $result = &Apache::loncommon::commit_studentrole(\$logmsg,$udom,$uname,$url,$role,$now,0,$cdom,$cnum,$csec,$context,$credits);
1.220 raeburn 3987: if (($result =~ /^error/) || ($result eq 'not_in_class') || ($result eq 'unknown_course') || ($result eq 'refused')) {
1.223 raeburn 3988: if ($result eq 'refused' && $logmsg) {
3989: $output = $logmsg;
3990: } else {
1.369 bisitz 3991: $output = &mt('Error: [_1]',$result)."\n";
1.223 raeburn 3992: }
1.89 raeburn 3993: } else {
1.372 raeburn 3994: $output = &Apache::lonhtmlcommon::confirm_success(&mt('Assigning [_1] in [_2] starting [_3]',
3995: &Apache::lonnet::plaintext($role),
3996: &Apache::loncommon::show_role_extent($url,$context,'st'),
3997: &Apache::lonlocal::locallocaltime($now))).'<br />'.$logmsg.'<br />';
1.89 raeburn 3998: }
3999: }
4000: } else {
1.101 albertel 4001: my $result=&Apache::lonnet::assignrole($env{'form.ccdomain'},
1.239 raeburn 4002: $env{'form.ccuname'},$url,$role,0,$now,'','',
4003: $context);
1.367 golterma 4004: $output = &Apache::lonhtmlcommon::confirm_success(&mt('Re-enabling [_1] in [_2]',
1.372 raeburn 4005: &Apache::lonnet::plaintext($role),
4006: &Apache::loncommon::show_role_extent($url,$context,$role)),$result ne "ok").'<br />';
1.369 bisitz 4007: if ($result ne "ok") {
4008: $output .= &mt('Error: [_1]',$result).'<br />';
4009: }
4010: }
1.89 raeburn 4011: $r->print($output);
1.225 raeburn 4012: if (!grep(/^\Q$role\E$/,@rolechanges)) {
4013: push(@rolechanges,$role);
4014: }
1.113 raeburn 4015: }
1.116 raeburn 4016: # Re-enable custom role
1.139 albertel 4017: if ($key=~m{^form\.ren\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
1.116 raeburn 4018: my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
4019: my $result = &Apache::lonnet::assigncustomrole(
4020: $env{'form.ccdomain'}, $env{'form.ccuname'},
1.240 raeburn 4021: $url,$rdom,$rnam,$rolename,0,$now,undef,$context);
1.369 bisitz 4022: $r->print(&Apache::lonhtmlcommon::confirm_success(
4023: &mt('Re-enabling custom role [_1] by [_2] in [_3]',
1.372 raeburn 4024: $rolename,$rnam.':'.$rdom,&Apache::loncommon::show_role_extent($1,$context,'cr')),
1.369 bisitz 4025: $result ne "ok").'<br />');
4026: if ($result ne "ok") {
4027: $r->print(&mt('Error: [_1]',$result).'<br />');
4028: }
1.225 raeburn 4029: if (!grep(/^cr$/,@rolechanges)) {
4030: push(@rolechanges,'cr');
4031: }
1.116 raeburn 4032: }
1.135 raeburn 4033: } elsif ($key=~/^form\.act/) {
1.101 albertel 4034: my $udom = $env{'form.ccdomain'};
4035: my $uname = $env{'form.ccuname'};
1.141 albertel 4036: if ($key=~/^form\.act\_($match_domain)\_($match_courseid)\_cr_cr_($match_domain)_($match_username)_([^\_]+)$/) {
1.65 www 4037: # Activate a custom role
1.83 albertel 4038: my ($one,$two,$three,$four,$five)=($1,$2,$3,$4,$5);
4039: my $url='/'.$one.'/'.$two;
4040: my $full=$one.'_'.$two.'_cr_cr_'.$three.'_'.$four.'_'.$five;
1.65 www 4041:
1.101 albertel 4042: my $start = ( $env{'form.start_'.$full} ?
4043: $env{'form.start_'.$full} :
1.88 raeburn 4044: $now );
1.101 albertel 4045: my $end = ( $env{'form.end_'.$full} ?
4046: $env{'form.end_'.$full} :
1.88 raeburn 4047: 0 );
4048:
4049: # split multiple sections
4050: my %sections = ();
1.101 albertel 4051: my $num_sections = &build_roles($env{'form.sec_'.$full},\%sections,$5);
1.88 raeburn 4052: if ($num_sections == 0) {
1.240 raeburn 4053: $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$url,$three,$four,$five,$start,$end,$context));
1.88 raeburn 4054: } else {
1.114 albertel 4055: my %curr_groups =
1.117 raeburn 4056: &Apache::longroup::coursegroups($one,$two);
1.404 raeburn 4057: foreach my $sec (sort {$a cmp $b} keys(%sections)) {
1.113 raeburn 4058: if (($sec eq 'none') || ($sec eq 'all') ||
4059: exists($curr_groups{$sec})) {
4060: $disallowed{$sec} = $url;
4061: next;
4062: }
4063: my $securl = $url.'/'.$sec;
1.240 raeburn 4064: $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$securl,$three,$four,$five,$start,$end,$context));
1.88 raeburn 4065: }
4066: }
1.225 raeburn 4067: if (!grep(/^cr$/,@rolechanges)) {
4068: push(@rolechanges,'cr');
4069: }
1.142 raeburn 4070: } elsif ($key=~/^form\.act\_($match_domain)\_($match_name)\_([^\_]+)$/) {
1.27 matthew 4071: # Activate roles for sections with 3 id numbers
4072: # set start, end times, and the url for the class
1.83 albertel 4073: my ($one,$two,$three)=($1,$2,$3);
1.101 albertel 4074: my $start = ( $env{'form.start_'.$one.'_'.$two.'_'.$three} ?
4075: $env{'form.start_'.$one.'_'.$two.'_'.$three} :
1.27 matthew 4076: $now );
1.101 albertel 4077: my $end = ( $env{'form.end_'.$one.'_'.$two.'_'.$three} ?
4078: $env{'form.end_'.$one.'_'.$two.'_'.$three} :
1.27 matthew 4079: 0 );
1.83 albertel 4080: my $url='/'.$one.'/'.$two;
1.88 raeburn 4081: my $type = 'three';
4082: # split multiple sections
4083: my %sections = ();
1.101 albertel 4084: my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two.'_'.$three},\%sections,$three);
1.375 raeburn 4085: my $credits;
4086: if ($three eq 'st') {
4087: if ($showcredits) {
4088: my $defaultcredits =
4089: &Apache::lonuserutils::get_defaultcredits($one,$two);
4090: $credits = $env{'form.credits_'.$one.'_'.$two.'_'.$three};
4091: $credits =~ s/[^\d\.]//g;
4092: if ($credits eq $defaultcredits) {
4093: undef($credits);
4094: }
4095: }
4096: }
1.88 raeburn 4097: if ($num_sections == 0) {
1.375 raeburn 4098: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'',$context,$credits));
1.88 raeburn 4099: } else {
1.114 albertel 4100: my %curr_groups =
1.117 raeburn 4101: &Apache::longroup::coursegroups($one,$two);
1.88 raeburn 4102: my $emptysec = 0;
1.404 raeburn 4103: foreach my $sec (sort {$a cmp $b} keys(%sections)) {
1.88 raeburn 4104: $sec =~ s/\W//g;
1.113 raeburn 4105: if ($sec ne '') {
4106: if (($sec eq 'none') || ($sec eq 'all') ||
4107: exists($curr_groups{$sec})) {
4108: $disallowed{$sec} = $url;
4109: next;
4110: }
1.88 raeburn 4111: my $securl = $url.'/'.$sec;
1.375 raeburn 4112: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$three,$start,$end,$one,$two,$sec,$context,$credits));
1.88 raeburn 4113: } else {
4114: $emptysec = 1;
4115: }
4116: }
4117: if ($emptysec) {
1.375 raeburn 4118: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'',$context,$credits));
1.88 raeburn 4119: }
1.225 raeburn 4120: }
4121: if (!grep(/^\Q$three\E$/,@rolechanges)) {
4122: push(@rolechanges,$three);
4123: }
1.135 raeburn 4124: } elsif ($key=~/^form\.act\_([^\_]+)\_([^\_]+)$/) {
1.27 matthew 4125: # Activate roles for sections with two id numbers
4126: # set start, end times, and the url for the class
1.101 albertel 4127: my $start = ( $env{'form.start_'.$1.'_'.$2} ?
4128: $env{'form.start_'.$1.'_'.$2} :
1.27 matthew 4129: $now );
1.101 albertel 4130: my $end = ( $env{'form.end_'.$1.'_'.$2} ?
4131: $env{'form.end_'.$1.'_'.$2} :
1.27 matthew 4132: 0 );
1.225 raeburn 4133: my $one = $1;
4134: my $two = $2;
4135: my $url='/'.$one.'/';
1.88 raeburn 4136: # split multiple sections
4137: my %sections = ();
1.225 raeburn 4138: my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two},\%sections,$two);
1.88 raeburn 4139: if ($num_sections == 0) {
1.240 raeburn 4140: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,'',$context));
1.88 raeburn 4141: } else {
4142: my $emptysec = 0;
1.404 raeburn 4143: foreach my $sec (sort {$a cmp $b} keys(%sections)) {
1.88 raeburn 4144: if ($sec ne '') {
4145: my $securl = $url.'/'.$sec;
1.240 raeburn 4146: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$two,$start,$end,$one,undef,$sec,$context));
1.88 raeburn 4147: } else {
4148: $emptysec = 1;
4149: }
4150: }
4151: if ($emptysec) {
1.240 raeburn 4152: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,'',$context));
1.88 raeburn 4153: }
4154: }
1.225 raeburn 4155: if (!grep(/^\Q$two\E$/,@rolechanges)) {
4156: push(@rolechanges,$two);
4157: }
1.64 www 4158: } else {
1.190 raeburn 4159: $r->print('<p><span class="LC_error">'.&mt('ERROR').': '.&mt('Unknown command').' <tt>'.$key.'</tt></span></p><br />');
1.64 www 4160: }
1.113 raeburn 4161: foreach my $key (sort(keys(%disallowed))) {
1.274 bisitz 4162: $r->print('<p class="LC_warning">');
1.113 raeburn 4163: if (($key eq 'none') || ($key eq 'all')) {
1.274 bisitz 4164: $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 4165: } else {
1.274 bisitz 4166: $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 4167: }
1.274 bisitz 4168: $r->print('</p><p>'
4169: .&mt('Please [_1]go back[_2] and choose a different section name.'
4170: ,'<a href="javascript:history.go(-1)'
4171: ,'</a>')
4172: .'</p><br />'
4173: );
1.113 raeburn 4174: }
4175: }
1.101 albertel 4176: } # End of foreach (keys(%env))
1.75 www 4177: # Flush the course logs so reverse user roles immediately updated
1.349 raeburn 4178: $r->register_cleanup(\&Apache::lonnet::flushcourselogs);
1.225 raeburn 4179: if (@rolechanges == 0) {
1.372 raeburn 4180: $r->print('<p>'.&mt('No roles to modify').'</p>');
1.193 raeburn 4181: }
1.225 raeburn 4182: return @rolechanges;
1.220 raeburn 4183: }
4184:
1.375 raeburn 4185: sub get_user_credits {
4186: my ($uname,$udom,$defaultcredits,$cdom,$cnum) = @_;
4187: if ($cdom eq '' || $cnum eq '') {
4188: return unless ($env{'request.course.id'});
4189: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
4190: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
4191: }
4192: my $credits;
4193: my %currhash =
4194: &Apache::lonnet::get('classlist',[$uname.':'.$udom],$cdom,$cnum);
4195: if (keys(%currhash) > 0) {
4196: my @items = split(/:/,$currhash{$uname.':'.$udom});
4197: my $crdidx = &Apache::loncoursedata::CL_CREDITS() - 3;
4198: $credits = $items[$crdidx];
4199: $credits =~ s/[^\d\.]//g;
4200: }
4201: if ($credits eq $defaultcredits) {
4202: undef($credits);
4203: }
4204: return $credits;
4205: }
4206:
1.220 raeburn 4207: sub enroll_single_student {
1.375 raeburn 4208: my ($r,$uhome,$amode,$genpwd,$now,$newuser,$context,$crstype,
4209: $showcredits,$defaultcredits) = @_;
1.318 raeburn 4210: $r->print('<h3>');
4211: if ($crstype eq 'Community') {
4212: $r->print(&mt('Enrolling Member'));
4213: } else {
4214: $r->print(&mt('Enrolling Student'));
4215: }
4216: $r->print('</h3>');
1.220 raeburn 4217:
4218: # Remove non alphanumeric values from section
4219: $env{'form.sections'}=~s/\W//g;
4220:
1.375 raeburn 4221: my $credits;
4222: if (($showcredits) && ($env{'form.credits'} ne '')) {
4223: $credits = $env{'form.credits'};
4224: $credits =~ s/[^\d\.]//g;
4225: if ($credits ne '') {
4226: if ($credits eq $defaultcredits) {
4227: undef($credits);
4228: }
4229: }
4230: }
4231:
1.220 raeburn 4232: # Clean out any old student roles the user has in this class.
4233: &Apache::lonuserutils::modifystudent($env{'form.ccdomain'},
4234: $env{'form.ccuname'},$env{'request.course.id'},undef,$uhome);
4235: my ($startdate,$enddate) = &Apache::lonuserutils::get_dates_from_form();
4236: my $enroll_result =
4237: &Apache::lonnet::modify_student_enrollment($env{'form.ccdomain'},
4238: $env{'form.ccuname'},$env{'form.cid'},$env{'form.cfirstname'},
4239: $env{'form.cmiddlename'},$env{'form.clastname'},
4240: $env{'form.generation'},$env{'form.sections'},$enddate,
1.375 raeburn 4241: $startdate,'manual',undef,$env{'request.course.id'},'',$context,
4242: $credits);
1.220 raeburn 4243: if ($enroll_result =~ /^ok/) {
1.381 bisitz 4244: $r->print(&mt('[_1] enrolled','<b>'.$env{'form.ccuname'}.':'.$env{'form.ccdomain'}.'</b>'));
1.220 raeburn 4245: if ($env{'form.sections'} ne '') {
4246: $r->print(' '.&mt('in section [_1]',$env{'form.sections'}));
4247: }
4248: my ($showstart,$showend);
4249: if ($startdate <= $now) {
4250: $showstart = &mt('Access starts immediately');
4251: } else {
4252: $showstart = &mt('Access starts: ').&Apache::lonlocal::locallocaltime($startdate);
4253: }
4254: if ($enddate == 0) {
4255: $showend = &mt('ends: no ending date');
4256: } else {
4257: $showend = &mt('ends: ').&Apache::lonlocal::locallocaltime($enddate);
4258: }
4259: $r->print('.<br />'.$showstart.'; '.$showend);
4260: if ($startdate <= $now && !$newuser) {
1.386 bisitz 4261: $r->print('<p class="LC_info">');
1.318 raeburn 4262: if ($crstype eq 'Community') {
1.392 raeburn 4263: $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 4264: } else {
1.392 raeburn 4265: $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 4266: }
4267: $r->print('</p>');
1.220 raeburn 4268: }
4269: } else {
4270: $r->print(&mt('unable to enroll').": ".$enroll_result);
4271: }
4272: return;
1.188 raeburn 4273: }
4274:
1.204 raeburn 4275: sub get_defaultquota_text {
4276: my ($settingstatus) = @_;
4277: my $defquotatext;
4278: if ($settingstatus eq '') {
1.383 raeburn 4279: $defquotatext = &mt('default');
1.204 raeburn 4280: } else {
4281: my ($usertypes,$order) =
4282: &Apache::lonnet::retrieve_inst_usertypes($env{'form.ccdomain'});
4283: if ($usertypes->{$settingstatus} eq '') {
1.383 raeburn 4284: $defquotatext = &mt('default');
1.204 raeburn 4285: } else {
1.383 raeburn 4286: $defquotatext = &mt('default for [_1]',$usertypes->{$settingstatus});
1.204 raeburn 4287: }
4288: }
4289: return $defquotatext;
4290: }
4291:
1.188 raeburn 4292: sub update_result_form {
4293: my ($uhome) = @_;
4294: my $outcome =
1.367 golterma 4295: '<form name="userupdate" method="post" action="">'."\n";
1.160 raeburn 4296: foreach my $item ('srchby','srchin','srchtype','srchterm','srchdomain','ccuname','ccdomain') {
1.188 raeburn 4297: $outcome .= '<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n";
1.160 raeburn 4298: }
1.207 raeburn 4299: if ($env{'form.origname'} ne '') {
4300: $outcome .= '<input type="hidden" name="origname" value="'.$env{'form.origname'}.'" />'."\n";
4301: }
1.160 raeburn 4302: foreach my $item ('sortby','seluname','seludom') {
4303: if (exists($env{'form.'.$item})) {
1.188 raeburn 4304: $outcome .= '<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n";
1.160 raeburn 4305: }
4306: }
1.188 raeburn 4307: if ($uhome eq 'no_host') {
4308: $outcome .= '<input type="hidden" name="forcenewuser" value="1" />'."\n";
4309: }
4310: $outcome .= '<input type="hidden" name="phase" value="" />'."\n".
1.383 raeburn 4311: '<input type="hidden" name="currstate" value="" />'."\n".
4312: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n".
1.188 raeburn 4313: '</form>';
4314: return $outcome;
1.4 www 4315: }
4316:
1.149 raeburn 4317: sub quota_admin {
1.378 raeburn 4318: my ($setquota,$changeHash,$name) = @_;
1.149 raeburn 4319: my $quotachanged;
4320: if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
4321: # Current user has quota modification privileges
1.267 raeburn 4322: if (ref($changeHash) eq 'HASH') {
4323: $quotachanged = 1;
1.378 raeburn 4324: $changeHash->{$name.'quota'} = $setquota;
1.267 raeburn 4325: }
1.149 raeburn 4326: }
4327: return $quotachanged;
4328: }
4329:
1.267 raeburn 4330: sub tool_admin {
1.275 raeburn 4331: my ($tool,$settool,$changeHash,$context) = @_;
4332: my $canchange = 0;
1.279 raeburn 4333: if ($context eq 'requestcourses') {
1.275 raeburn 4334: if (&Apache::lonnet::allowed('ccc',$env{'form.ccdomain'})) {
4335: $canchange = 1;
4336: }
1.300 raeburn 4337: } elsif ($context eq 'reqcrsotherdom') {
4338: if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
4339: $canchange = 1;
4340: }
1.362 raeburn 4341: } elsif ($context eq 'requestauthor') {
4342: if (&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) {
4343: $canchange = 1;
4344: }
1.275 raeburn 4345: } elsif (&Apache::lonnet::allowed('mut',$env{'form.ccdomain'})) {
4346: # Current user has quota modification privileges
4347: $canchange = 1;
4348: }
1.267 raeburn 4349: my $toolchanged;
1.275 raeburn 4350: if ($canchange) {
1.267 raeburn 4351: if (ref($changeHash) eq 'HASH') {
4352: $toolchanged = 1;
1.362 raeburn 4353: if ($tool eq 'requestauthor') {
4354: $changeHash->{$context} = $settool;
4355: } else {
4356: $changeHash->{$context.'.'.$tool} = $settool;
4357: }
1.267 raeburn 4358: }
4359: }
4360: return $toolchanged;
4361: }
4362:
1.88 raeburn 4363: sub build_roles {
1.89 raeburn 4364: my ($sectionstr,$sections,$role) = @_;
1.88 raeburn 4365: my $num_sections = 0;
4366: if ($sectionstr=~ /,/) {
4367: my @secnums = split/,/,$sectionstr;
1.89 raeburn 4368: if ($role eq 'st') {
4369: $secnums[0] =~ s/\W//g;
4370: $$sections{$secnums[0]} = 1;
4371: $num_sections = 1;
4372: } else {
4373: foreach my $sec (@secnums) {
4374: $sec =~ ~s/\W//g;
1.150 banghart 4375: if (!($sec eq "")) {
1.89 raeburn 4376: if (exists($$sections{$sec})) {
4377: $$sections{$sec} ++;
4378: } else {
4379: $$sections{$sec} = 1;
4380: $num_sections ++;
4381: }
1.88 raeburn 4382: }
4383: }
4384: }
4385: } else {
4386: $sectionstr=~s/\W//g;
4387: unless ($sectionstr eq '') {
4388: $$sections{$sectionstr} = 1;
4389: $num_sections ++;
4390: }
4391: }
1.129 albertel 4392:
1.88 raeburn 4393: return $num_sections;
4394: }
4395:
1.58 www 4396: # ========================================================== Custom Role Editor
4397:
4398: sub custom_role_editor {
1.439 raeburn 4399: my ($r,$context,$brcrum,$prefix,$permission) = @_;
1.324 raeburn 4400: my $action = $env{'form.customroleaction'};
1.439 raeburn 4401: my ($rolename,$helpitem);
1.324 raeburn 4402: if ($action eq 'new') {
4403: $rolename=$env{'form.newrolename'};
4404: } else {
4405: $rolename=$env{'form.rolename'};
1.59 www 4406: }
4407:
1.324 raeburn 4408: my ($crstype,$context);
4409: if ($env{'request.course.id'}) {
4410: $crstype = &Apache::loncommon::course_type();
4411: $context = 'course';
1.439 raeburn 4412: $helpitem = 'Course_Editing_Custom_Roles';
1.324 raeburn 4413: } else {
4414: $context = 'domain';
1.414 raeburn 4415: $crstype = 'course';
1.439 raeburn 4416: $helpitem = 'Domain_Editing_Custom_Roles';
1.324 raeburn 4417: }
1.351 raeburn 4418:
4419: $rolename=~s/[^A-Za-z0-9]//gs;
4420: if (!$rolename || $env{'form.phase'} eq 'pickrole') {
1.439 raeburn 4421: &print_username_entry_form($r,$context,undef,undef,undef,$crstype,$brcrum,
4422: $permission);
1.351 raeburn 4423: return;
4424: }
4425:
1.414 raeburn 4426: my $formname = 'form1';
4427: my %privs=();
4428: my $body_top = '<h2>';
4429: # ------------------------------------------------------- Does this role exist?
1.59 www 4430: my ($rdummy,$roledef)=
4431: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
4432: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1.414 raeburn 4433: $body_top .= &mt('Existing Role').' "';
1.61 www 4434: # ------------------------------------------------- Get current role privileges
1.414 raeburn 4435: ($privs{'system'},$privs{'domain'},$privs{'course'})=split(/\_/,$roledef);
4436: if ($privs{'system'} =~ /bre\&S/) {
4437: if ($context eq 'domain') {
1.417 raeburn 4438: $crstype = 'Course';
1.414 raeburn 4439: } elsif ($crstype eq 'Community') {
4440: $privs{'system'} =~ s/bre\&S//;
4441: }
4442: } elsif ($context eq 'domain') {
4443: $crstype = 'Course';
1.324 raeburn 4444: }
1.59 www 4445: } else {
1.414 raeburn 4446: $body_top .= &mt('New Role').' "';
4447: $roledef='';
1.59 www 4448: }
1.153 banghart 4449: $body_top .= $rolename.'"</h2>';
1.414 raeburn 4450:
4451: # ------------------------------------------------------- What can be assigned?
4452: my %full=();
1.417 raeburn 4453: my %levels=(
1.414 raeburn 4454: course => {},
4455: domain => {},
4456: system => {},
4457: );
4458: my %levelscurrent=(
4459: course => {},
4460: domain => {},
4461: system => {},
4462: );
4463: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
1.160 raeburn 4464: my ($jsback,$elements) = &crumb_utilities();
1.414 raeburn 4465: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
1.417 raeburn 4466: my $head_script =
1.414 raeburn 4467: &Apache::lonuserutils::custom_roledefs_js($context,$crstype,$formname,
4468: \%full,\@templateroles,$jsback);
1.351 raeburn 4469: push (@{$brcrum},
1.414 raeburn 4470: {href => "javascript:backPage(document.$formname,'pickrole','')",
1.351 raeburn 4471: text => "Pick custom role",
4472: faq => 282,bug=>'Instructor Interface',},
1.414 raeburn 4473: {href => "javascript:backPage(document.$formname,'','')",
1.351 raeburn 4474: text => "Edit custom role",
4475: faq => 282,
4476: bug => 'Instructor Interface',
1.439 raeburn 4477: help => $helpitem}
1.351 raeburn 4478: );
4479: my $args = { bread_crumbs => $brcrum,
4480: bread_crumbs_component => 'User Management'};
4481: $r->print(&Apache::loncommon::start_page('Custom Role Editor',
4482: $head_script,$args).
4483: $body_top);
1.414 raeburn 4484: $r->print('<form name="'.$formname.'" method="post" action="">'."\n".
4485: &Apache::lonuserutils::custom_role_header($context,$crstype,
4486: \@templateroles,$prefix));
1.264 bisitz 4487:
1.61 www 4488: $r->print(<<ENDCCF);
4489: <input type="hidden" name="phase" value="set_custom_roles" />
4490: <input type="hidden" name="rolename" value="$rolename" />
4491: ENDCCF
1.414 raeburn 4492: $r->print(&Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
4493: \%levelscurrent,$prefix));
1.135 raeburn 4494: $r->print(&Apache::loncommon::end_data_table().
1.190 raeburn 4495: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'.
1.160 raeburn 4496: '<input type="hidden" name="startrolename" value="'.$env{'form.rolename'}.
1.417 raeburn 4497: '" />'."\n".'<input type="hidden" name="currstate" value="" />'."\n".
1.160 raeburn 4498: '<input type="reset" value="'.&mt("Reset").'" />'."\n".
1.351 raeburn 4499: '<input type="submit" value="'.&mt('Save').'" /></form>');
1.61 www 4500: }
1.414 raeburn 4501:
1.61 www 4502: # ---------------------------------------------------------- Call to definerole
4503: sub set_custom_role {
1.439 raeburn 4504: my ($r,$context,$brcrum,$prefix,$permission) = @_;
1.101 albertel 4505: my $rolename=$env{'form.rolename'};
1.63 www 4506: $rolename=~s/[^A-Za-z0-9]//gs;
1.150 banghart 4507: if (!$rolename) {
1.439 raeburn 4508: &custom_role_editor($r,$context,$brcrum,$prefix,$permission);
1.61 www 4509: return;
4510: }
1.160 raeburn 4511: my ($jsback,$elements) = &crumb_utilities();
1.301 bisitz 4512: my $jscript = '<script type="text/javascript">'
4513: .'// <![CDATA['."\n"
4514: .$jsback."\n"
4515: .'// ]]>'."\n"
4516: .'</script>'."\n";
1.439 raeburn 4517: my $helpitem = 'Course_Editing_Custom_Roles';
4518: if ($context eq 'domain') {
4519: $helpitem = 'Domain_Editing_Custom_Roles';
4520: }
1.352 raeburn 4521: push(@{$brcrum},
4522: {href => "javascript:backPage(document.customresult,'pickrole','')",
4523: text => "Pick custom role",
4524: faq => 282,
4525: bug => 'Instructor Interface',},
4526: {href => "javascript:backPage(document.customresult,'selected_custom_edit','')",
4527: text => "Edit custom role",
4528: faq => 282,
4529: bug => 'Instructor Interface',},
4530: {href => "javascript:backPage(document.customresult,'set_custom_roles','')",
4531: text => "Result",
4532: faq => 282,
4533: bug => 'Instructor Interface',
1.439 raeburn 4534: help => $helpitem,}
1.352 raeburn 4535: );
4536: my $args = { bread_crumbs => $brcrum,
1.414 raeburn 4537: bread_crumbs_component => 'User Management'};
1.351 raeburn 4538: $r->print(&Apache::loncommon::start_page('Save Custom Role',$jscript,$args));
1.160 raeburn 4539:
1.393 raeburn 4540: my $newrole;
1.61 www 4541: my ($rdummy,$roledef)=
1.110 albertel 4542: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
4543:
1.61 www 4544: # ------------------------------------------------------- Does this role exist?
1.188 raeburn 4545: $r->print('<h3>');
1.61 www 4546: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1.73 sakharuk 4547: $r->print(&mt('Existing Role').' "');
1.61 www 4548: } else {
1.73 sakharuk 4549: $r->print(&mt('New Role').' "');
1.61 www 4550: $roledef='';
1.393 raeburn 4551: $newrole = 1;
1.61 www 4552: }
1.188 raeburn 4553: $r->print($rolename.'"</h3>');
1.414 raeburn 4554: # ------------------------------------------------- Assign role and show result
1.61 www 4555:
1.387 bisitz 4556: my $errmsg;
1.414 raeburn 4557: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$prefix);
4558: # Assign role and return result
4559: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
4560: $newprivs{'c'});
1.387 bisitz 4561: if ($result ne 'ok') {
4562: $errmsg = ': '.$result;
4563: }
4564: my $message =
4565: &Apache::lonhtmlcommon::confirm_success(
4566: &mt('Defining Role').$errmsg, ($result eq 'ok' ? 0 : 1));
1.101 albertel 4567: if ($env{'request.course.id'}) {
4568: my $url='/'.$env{'request.course.id'};
1.63 www 4569: $url=~s/\_/\//g;
1.387 bisitz 4570: $result =
4571: &Apache::lonnet::assigncustomrole(
4572: $env{'user.domain'},$env{'user.name'},
4573: $url,
4574: $env{'user.domain'},$env{'user.name'},
4575: $rolename,undef,undef,undef,$context);
4576: if ($result ne 'ok') {
4577: $errmsg = ': '.$result;
4578: }
4579: $message .=
4580: '<br />'
4581: .&Apache::lonhtmlcommon::confirm_success(
4582: &mt('Assigning Role to Self').$errmsg, ($result eq 'ok' ? 0 : 1));
1.63 www 4583: }
1.380 bisitz 4584: $r->print(
1.387 bisitz 4585: &Apache::loncommon::confirmwrapper($message)
4586: .'<br />'
4587: .&Apache::lonhtmlcommon::actionbox([
4588: '<a href="javascript:backPage(document.customresult,'."'pickrole'".')">'
4589: .&mt('Create or edit another custom role')
4590: .'</a>'])
1.380 bisitz 4591: .'<form name="customresult" method="post" action="">'
1.387 bisitz 4592: .&Apache::lonhtmlcommon::echo_form_input([])
4593: .'</form>'
1.380 bisitz 4594: );
1.58 www 4595: }
4596:
1.2 www 4597: # ================================================================ Main Handler
4598: sub handler {
4599: my $r = shift;
4600: if ($r->header_only) {
1.68 www 4601: &Apache::loncommon::content_type($r,'text/html');
1.2 www 4602: $r->send_http_header;
4603: return OK;
4604: }
1.439 raeburn 4605: my ($context,$crstype,$cid,$cnum,$cdom,$allhelpitems);
4606:
1.190 raeburn 4607: if ($env{'request.course.id'}) {
4608: $context = 'course';
1.318 raeburn 4609: $crstype = &Apache::loncommon::course_type();
1.190 raeburn 4610: } elsif ($env{'request.role'} =~ /^au\./) {
1.206 raeburn 4611: $context = 'author';
1.190 raeburn 4612: } else {
4613: $context = 'domain';
4614: }
1.375 raeburn 4615:
1.439 raeburn 4616: my ($permission,$allowed) =
4617: &Apache::lonuserutils::get_permission($context,$crstype);
4618:
4619: if ($allowed) {
4620: my @allhelp;
4621: if ($context eq 'course') {
4622: $cid = $env{'request.course.id'};
4623: $cdom = $env{'course.'.$cid.'.domain'};
4624: $cnum = $env{'course.'.$cid.'.num'};
4625:
4626: if ($permission->{'cusr'}) {
4627: push(@allhelp,'Course_Create_Class_List');
4628: }
4629: if ($permission->{'view'} || $permission->{'cusr'}) {
4630: push(@allhelp,('Course_Change_Privileges','Course_View_Class_List'));
4631: }
4632: if ($permission->{'custom'}) {
4633: push(@allhelp,'Course_Editing_Custom_Roles');
4634: }
4635: if ($permission->{'cusr'}) {
4636: push(@allhelp,('Course_Add_Student','Course_Drop_Student'));
4637: }
4638: unless ($permission->{'cusr_section'}) {
4639: if (&Apache::lonnet::auto_run($cnum,$cdom) && (($permission->{'cusr'}) || ($permission->{'view'}))) {
4640: push(@allhelp,'Course_Automated_Enrollment');
4641: }
4642: if ($permission->{'selfenrolladmin'}) {
4643: push(@allhelp,'Course_Approve_Selfenroll');
4644: }
4645: }
4646: if ($permission->{'grp_manage'}) {
4647: push(@allhelp,'Course_Manage_Group');
4648: }
4649: if ($permission->{'view'} || $permission->{'cusr'}) {
4650: push(@allhelp,'Course_User_Logs');
4651: }
4652: } elsif ($context eq 'author') {
4653: push(@allhelp,('Author_Change_Privileges','Author_Create_Coauthor_List',
4654: 'Author_View_Coauthor_List','Author_User_Logs'));
4655: } else {
4656: if ($permission->{'cusr'}) {
4657: push(@allhelp,'Domain_Change_Privileges');
4658: if ($permission->{'activity'}) {
4659: push(@allhelp,'Domain_User_Access_Logs');
4660: }
4661: push(@allhelp,('Domain_Create_Users','Domain_View_Users_List'));
4662: if ($permission->{'custom'}) {
4663: push(@allhelp,'Domain_Editing_Custom_Roles');
4664: }
4665: push(@allhelp,('Domain_Role_Approvals','Domain_Username_Approvals','Domain_Change_Logs'));
4666: } elsif ($permission->{'view'}) {
4667: push(@allhelp,'Domain_View_Privileges');
4668: if ($permission->{'activity'}) {
4669: push(@allhelp,'Domain_User_Access_Logs');
4670: }
4671: push(@allhelp,('Domain_View_Users_List','Domain_Change_Logs'));
4672: }
4673: }
4674: if (@allhelp) {
4675: $allhelpitems = join(',',@allhelp);
4676: }
4677: }
4678:
1.190 raeburn 4679: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.233 raeburn 4680: ['action','state','callingform','roletype','showrole','bulkaction','popup','phase',
1.391 raeburn 4681: 'username','domain','srchterm','srchdomain','srchin','srchby','srchtype','queue']);
1.190 raeburn 4682: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.351 raeburn 4683: my $args;
4684: my $brcrum = [];
4685: my $bread_crumbs_component = 'User Management';
1.391 raeburn 4686: if (($env{'form.action'} ne 'dateselect') && ($env{'form.action'} ne 'displayuserreq')) {
1.351 raeburn 4687: $brcrum = [{href=>"/adm/createuser",
4688: text=>"User Management",
1.439 raeburn 4689: help=>$allhelpitems}
1.351 raeburn 4690: ];
1.202 raeburn 4691: }
1.190 raeburn 4692: if (!$allowed) {
1.358 raeburn 4693: if ($context eq 'course') {
4694: $r->internal_redirect('/adm/viewclasslist');
4695: return OK;
4696: }
1.190 raeburn 4697: $env{'user.error.msg'}=
4698: "/adm/createuser:cst:0:0:Cannot create/modify user data ".
4699: "or view user status.";
4700: return HTTP_NOT_ACCEPTABLE;
4701: }
4702:
4703: &Apache::loncommon::content_type($r,'text/html');
4704: $r->send_http_header;
4705:
1.375 raeburn 4706: my $showcredits;
4707: if ((($context eq 'course') && ($crstype eq 'Course')) ||
4708: ($context eq 'domain')) {
4709: my %domdefaults =
4710: &Apache::lonnet::get_domain_defaults($env{'request.role.domain'});
4711: if ($domdefaults{'officialcredits'} || $domdefaults{'unofficialcredits'}) {
4712: $showcredits = 1;
4713: }
4714: }
4715:
1.190 raeburn 4716: # Main switch on form.action and form.state, as appropriate
4717: if (! exists($env{'form.action'})) {
1.351 raeburn 4718: $args = {bread_crumbs => $brcrum,
4719: bread_crumbs_component => $bread_crumbs_component};
4720: $r->print(&header(undef,$args));
1.318 raeburn 4721: $r->print(&print_main_menu($permission,$context,$crstype));
1.190 raeburn 4722: } elsif ($env{'form.action'} eq 'upload' && $permission->{'cusr'}) {
1.439 raeburn 4723: my $helpitem = 'Course_Create_Class_List';
4724: if ($context eq 'author') {
4725: $helpitem = 'Author_Create_Coauthor_List';
4726: } elsif ($context eq 'domain') {
4727: $helpitem = 'Domain_Create_Users';
4728: }
1.351 raeburn 4729: push(@{$brcrum},
4730: { href => '/adm/createuser?action=upload&state=',
4731: text => 'Upload Users List',
1.439 raeburn 4732: help => $helpitem,
1.351 raeburn 4733: });
4734: $bread_crumbs_component = 'Upload Users List';
4735: $args = {bread_crumbs => $brcrum,
4736: bread_crumbs_component => $bread_crumbs_component};
4737: $r->print(&header(undef,$args));
1.190 raeburn 4738: $r->print('<form name="studentform" method="post" '.
4739: 'enctype="multipart/form-data" '.
4740: ' action="/adm/createuser">'."\n");
4741: if (! exists($env{'form.state'})) {
4742: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
4743: } elsif ($env{'form.state'} eq 'got_file') {
1.375 raeburn 4744: &Apache::lonuserutils::print_upload_manager_form($r,$context,$permission,
4745: $crstype,$showcredits);
1.190 raeburn 4746: } elsif ($env{'form.state'} eq 'enrolling') {
4747: if ($env{'form.datatoken'}) {
1.375 raeburn 4748: &Apache::lonuserutils::upfile_drop_add($r,$context,$permission,
4749: $showcredits);
1.190 raeburn 4750: }
4751: } else {
4752: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
4753: }
1.416 raeburn 4754: } elsif (((($env{'form.action'} eq 'singleuser') || ($env{'form.action'}
4755: eq 'singlestudent')) && ($permission->{'cusr'})) ||
1.418 raeburn 4756: (($env{'form.action'} eq 'singleuser') && ($permission->{'view'})) ||
1.416 raeburn 4757: (($env{'form.action'} eq 'accesslogs') && ($permission->{'activity'}))) {
1.190 raeburn 4758: my $phase = $env{'form.phase'};
4759: my @search = ('srchterm','srchby','srchin','srchtype','srchdomain');
1.192 albertel 4760: &Apache::loncreateuser::restore_prev_selections();
4761: my $srch;
4762: foreach my $item (@search) {
4763: $srch->{$item} = $env{'form.'.$item};
4764: }
1.207 raeburn 4765: if (($phase eq 'get_user_info') || ($phase eq 'userpicked') ||
1.416 raeburn 4766: ($phase eq 'createnewuser') || ($phase eq 'activity')) {
1.207 raeburn 4767: if ($env{'form.phase'} eq 'createnewuser') {
4768: my $response;
4769: if ($env{'form.srchterm'} !~ /^$match_username$/) {
1.366 bisitz 4770: my $response =
4771: '<span class="LC_warning">'
4772: .&mt('You must specify a valid username. Only the following are allowed:'
4773: .' letters numbers - . @')
4774: .'</span>';
1.221 raeburn 4775: $env{'form.phase'} = '';
1.375 raeburn 4776: &print_username_entry_form($r,$context,$response,$srch,undef,
1.439 raeburn 4777: $crstype,$brcrum,$permission);
1.207 raeburn 4778: } else {
4779: my $ccuname =&LONCAPA::clean_username($srch->{'srchterm'});
4780: my $ccdomain=&LONCAPA::clean_domain($srch->{'srchdomain'});
4781: &print_user_modification_page($r,$ccuname,$ccdomain,
1.221 raeburn 4782: $srch,$response,$context,
1.375 raeburn 4783: $permission,$crstype,$brcrum,
4784: $showcredits);
1.207 raeburn 4785: }
4786: } elsif ($env{'form.phase'} eq 'get_user_info') {
1.190 raeburn 4787: my ($currstate,$response,$forcenewuser,$results) =
1.221 raeburn 4788: &user_search_result($context,$srch);
1.190 raeburn 4789: if ($env{'form.currstate'} eq 'modify') {
4790: $currstate = $env{'form.currstate'};
4791: }
4792: if ($currstate eq 'select') {
4793: &print_user_selection_page($r,$response,$srch,$results,
1.351 raeburn 4794: \@search,$context,undef,$crstype,
4795: $brcrum);
1.416 raeburn 4796: } elsif (($currstate eq 'modify') || ($env{'form.action'} eq 'accesslogs')) {
4797: my ($ccuname,$ccdomain,$uhome);
1.190 raeburn 4798: if (($srch->{'srchby'} eq 'uname') &&
4799: ($srch->{'srchtype'} eq 'exact')) {
4800: $ccuname = $srch->{'srchterm'};
4801: $ccdomain= $srch->{'srchdomain'};
4802: } else {
4803: my @matchedunames = keys(%{$results});
4804: ($ccuname,$ccdomain) = split(/:/,$matchedunames[0]);
4805: }
4806: $ccuname =&LONCAPA::clean_username($ccuname);
4807: $ccdomain=&LONCAPA::clean_domain($ccdomain);
1.416 raeburn 4808: if ($env{'form.action'} eq 'accesslogs') {
4809: my $uhome;
4810: if (($ccuname ne '') && ($ccdomain ne '')) {
4811: $uhome = &Apache::lonnet::homeserver($ccuname,$ccdomain);
4812: }
4813: if (($uhome eq '') || ($uhome eq 'no_host')) {
4814: $env{'form.phase'} = '';
4815: undef($forcenewuser);
4816: #if ($response) {
4817: # unless ($response =~ m{\Q<br /><br />\E$}) {
4818: # $response .= '<br /><br />';
4819: # }
4820: #}
4821: &print_username_entry_form($r,$context,$response,$srch,
1.439 raeburn 4822: $forcenewuser,$crstype,$brcrum,
4823: $permission);
1.416 raeburn 4824: } else {
4825: &print_useraccesslogs_display($r,$ccuname,$ccdomain,$permission,$brcrum);
4826: }
4827: } else {
4828: if ($env{'form.forcenewuser'}) {
4829: $response = '';
4830: }
4831: &print_user_modification_page($r,$ccuname,$ccdomain,
4832: $srch,$response,$context,
4833: $permission,$crstype,$brcrum);
1.190 raeburn 4834: }
4835: } elsif ($currstate eq 'query') {
1.351 raeburn 4836: &print_user_query_page($r,'createuser',$brcrum);
1.190 raeburn 4837: } else {
1.229 raeburn 4838: $env{'form.phase'} = '';
1.207 raeburn 4839: &print_username_entry_form($r,$context,$response,$srch,
1.439 raeburn 4840: $forcenewuser,$crstype,$brcrum,
4841: $permission);
1.190 raeburn 4842: }
4843: } elsif ($env{'form.phase'} eq 'userpicked') {
4844: my $ccuname = &LONCAPA::clean_username($env{'form.seluname'});
4845: my $ccdomain = &LONCAPA::clean_domain($env{'form.seludom'});
1.416 raeburn 4846: if ($env{'form.action'} eq 'accesslogs') {
4847: &print_useraccesslogs_display($r,$ccuname,$ccdomain,$permission,$brcrum);
4848: } else {
4849: &print_user_modification_page($r,$ccuname,$ccdomain,$srch,'',
4850: $context,$permission,$crstype,
4851: $brcrum);
4852: }
4853: } elsif ($env{'form.action'} eq 'accesslogs') {
4854: my $ccuname = &LONCAPA::clean_username($env{'form.accessuname'});
4855: my $ccdomain = &LONCAPA::clean_domain($env{'form.accessudom'});
4856: &print_useraccesslogs_display($r,$ccuname,$ccdomain,$permission,$brcrum);
1.190 raeburn 4857: }
4858: } elsif ($env{'form.phase'} eq 'update_user_data') {
1.375 raeburn 4859: &update_user_data($r,$context,$crstype,$brcrum,$showcredits);
1.190 raeburn 4860: } else {
1.351 raeburn 4861: &print_username_entry_form($r,$context,undef,$srch,undef,$crstype,
1.439 raeburn 4862: $brcrum,$permission);
1.190 raeburn 4863: }
4864: } elsif ($env{'form.action'} eq 'custom' && $permission->{'custom'}) {
1.414 raeburn 4865: my $prefix;
1.190 raeburn 4866: if ($env{'form.phase'} eq 'set_custom_roles') {
1.439 raeburn 4867: &set_custom_role($r,$context,$brcrum,$prefix,$permission);
1.190 raeburn 4868: } else {
1.439 raeburn 4869: &custom_role_editor($r,$context,$brcrum,$prefix,$permission);
1.190 raeburn 4870: }
1.362 raeburn 4871: } elsif (($env{'form.action'} eq 'processauthorreq') &&
4872: ($permission->{'cusr'}) &&
4873: (&Apache::lonnet::allowed('cau',$env{'request.role.domain'}))) {
4874: push(@{$brcrum},
4875: {href => '/adm/createuser?action=processauthorreq',
1.385 bisitz 4876: text => 'Authoring Space requests',
1.362 raeburn 4877: help => 'Domain_Role_Approvals'});
4878: $bread_crumbs_component = 'Authoring requests';
4879: if ($env{'form.state'} eq 'done') {
4880: push(@{$brcrum},
4881: {href => '/adm/createuser?action=authorreqqueue',
4882: text => 'Result',
4883: help => 'Domain_Role_Approvals'});
4884: $bread_crumbs_component = 'Authoring request result';
4885: }
4886: $args = { bread_crumbs => $brcrum,
4887: bread_crumbs_component => $bread_crumbs_component};
1.391 raeburn 4888: my $js = &usernamerequest_javascript();
4889: $r->print(&header(&add_script($js),$args));
1.362 raeburn 4890: if (!exists($env{'form.state'})) {
4891: $r->print(&Apache::loncoursequeueadmin::display_queued_requests('requestauthor',
4892: $env{'request.role.domain'}));
4893: } elsif ($env{'form.state'} eq 'done') {
4894: $r->print('<h3>'.&mt('Authoring request processing').'</h3>'."\n");
4895: $r->print(&Apache::loncoursequeueadmin::update_request_queue('requestauthor',
4896: $env{'request.role.domain'}));
4897: }
1.391 raeburn 4898: } elsif (($env{'form.action'} eq 'processusernamereq') &&
4899: ($permission->{'cusr'}) &&
4900: (&Apache::lonnet::allowed('cau',$env{'request.role.domain'}))) {
4901: push(@{$brcrum},
4902: {href => '/adm/createuser?action=processusernamereq',
4903: text => 'LON-CAPA account requests',
4904: help => 'Domain_Username_Approvals'});
4905: $bread_crumbs_component = 'Account requests';
4906: if ($env{'form.state'} eq 'done') {
4907: push(@{$brcrum},
4908: {href => '/adm/createuser?action=usernamereqqueue',
4909: text => 'Result',
4910: help => 'Domain_Username_Approvals'});
4911: $bread_crumbs_component = 'LON-CAPA account request result';
4912: }
4913: $args = { bread_crumbs => $brcrum,
4914: bread_crumbs_component => $bread_crumbs_component};
4915: my $js = &usernamerequest_javascript();
4916: $r->print(&header(&add_script($js),$args));
4917: if (!exists($env{'form.state'})) {
4918: $r->print(&Apache::loncoursequeueadmin::display_queued_requests('requestusername',
4919: $env{'request.role.domain'}));
4920: } elsif ($env{'form.state'} eq 'done') {
4921: $r->print('<h3>'.&mt('LON-CAPA account request processing').'</h3>'."\n");
4922: $r->print(&Apache::loncoursequeueadmin::update_request_queue('requestusername',
4923: $env{'request.role.domain'}));
4924: }
4925: } elsif (($env{'form.action'} eq 'displayuserreq') &&
4926: ($permission->{'cusr'})) {
4927: my $dom = $env{'form.domain'};
4928: my $uname = $env{'form.username'};
4929: my $warning;
4930: if (($dom =~ /^$match_domain$/) && (&Apache::lonnet::domain($dom) ne '')) {
4931: if (($dom eq $env{'request.role.domain'}) && (&Apache::lonnet::allowed('ccc',$dom))) {
4932: if (($uname =~ /^$match_username$/) && ($env{'form.queue'} eq 'approval')) {
4933: my $uhome = &Apache::lonnet::homeserver($uname,$dom);
4934: if ($uhome eq 'no_host') {
4935: my $queue = $env{'form.queue'};
4936: my $reqkey = &escape($uname).'_'.$queue;
4937: my $namespace = 'usernamequeue';
4938: my $domconfig = &Apache::lonnet::get_domainconfiguser($dom);
4939: my %queued =
4940: &Apache::lonnet::get($namespace,[$reqkey],$dom,$domconfig);
4941: unless ($queued{$reqkey}) {
4942: $warning = &mt('No information was found for this LON-CAPA account request.');
4943: }
4944: } else {
4945: $warning = &mt('A LON-CAPA account already exists for the requested username and domain.');
4946: }
4947: } else {
4948: $warning = &mt('LON-CAPA account request status check is for an invalid username.');
4949: }
4950: } else {
4951: $warning = &mt('You do not have rights to view LON-CAPA account requests in the domain specified.');
4952: }
4953: } else {
4954: $warning = &mt('LON-CAPA account request status check is for an invalid domain.');
4955: }
4956: my $args = { only_body => 1 };
4957: $r->print(&header(undef,$args).
4958: '<h3>'.&mt('LON-CAPA Account Request Details').'</h3>');
4959: if ($warning ne '') {
4960: $r->print('<div class="LC_warning">'.$warning.'</div>');
4961: } else {
4962: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
4963: my $domconfiguser = &Apache::lonnet::get_domainconfiguser($dom);
4964: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
4965: if (ref($domconfig{'usercreation'}) eq 'HASH') {
4966: if (ref($domconfig{'usercreation'}{'cancreate'}) eq 'HASH') {
4967: if (ref($domconfig{'usercreation'}{'cancreate'}{'emailusername'}) eq 'HASH') {
4968: my %info =
4969: &Apache::lonnet::get('nohist_requestedusernames',[$uname],$dom,$domconfiguser);
4970: if (ref($info{$uname}) eq 'HASH') {
1.396 raeburn 4971: my $usertype = $info{$uname}{'inststatus'};
4972: unless ($usertype) {
4973: $usertype = 'default';
4974: }
1.442 raeburn 4975: my ($showstatus,$showemail,$pickstart);
4976: my $numextras = 0;
4977: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.443 raeburn 4978: if ((ref($types) eq 'ARRAY') && (@{$types} > 0)) {
4979: if (ref($usertypes) eq 'HASH') {
4980: if ($usertypes->{$usertype}) {
4981: $showstatus = $usertypes->{$usertype};
4982: } else {
4983: $showstatus = $othertitle;
4984: }
4985: if ($showstatus) {
4986: $numextras ++;
4987: }
1.442 raeburn 4988: }
4989: }
4990: if (($info{$uname}{'email'} ne '') && ($info{$uname}{'email'} ne $uname)) {
4991: $showemail = $info{$uname}{'email'};
4992: $numextras ++;
4993: }
1.396 raeburn 4994: if (ref($domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}) eq 'HASH') {
4995: if ((ref($infofields) eq 'ARRAY') && (ref($infotitles) eq 'HASH')) {
1.442 raeburn 4996: $pickstart = 1;
1.396 raeburn 4997: $r->print('<div>'.&Apache::lonhtmlcommon::start_pick_box());
1.442 raeburn 4998: my ($num,$count);
1.396 raeburn 4999: $count = scalar(keys(%{$domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}}));
1.442 raeburn 5000: $count += $numextras;
1.396 raeburn 5001: foreach my $field (@{$infofields}) {
5002: next unless ($domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}{$field});
5003: next unless ($infotitles->{$field});
5004: $r->print(&Apache::lonhtmlcommon::row_title($infotitles->{$field}).
5005: $info{$uname}{$field});
5006: $num ++;
1.442 raeburn 5007: unless ($count == $num) {
1.396 raeburn 5008: $r->print(&Apache::lonhtmlcommon::row_closure());
5009: }
5010: }
1.442 raeburn 5011: }
5012: }
5013: if ($numextras) {
5014: unless ($pickstart) {
5015: $r->print('<div>'.&Apache::lonhtmlcommon::start_pick_box());
5016: $pickstart = 1;
5017: }
5018: if ($showemail) {
5019: my $closure = '';
5020: unless ($showstatus) {
5021: $closure = 1;
1.391 raeburn 5022: }
1.442 raeburn 5023: $r->print(&Apache::lonhtmlcommon::row_title(&mt('E-mail address')).
5024: $showemail.
5025: &Apache::lonhtmlcommon::row_closure($closure));
1.391 raeburn 5026: }
1.442 raeburn 5027: if ($showstatus) {
5028: $r->print(&Apache::lonhtmlcommon::row_title(&mt('Status type[_1](self-reported)','<br />')).
5029: $showstatus.
5030: &Apache::lonhtmlcommon::row_closure(1));
5031: }
5032: }
5033: if ($pickstart) {
5034: $r->print(&Apache::lonhtmlcommon::end_pick_box().'</div>');
5035: } else {
5036: $r->print('<div>'.&mt('No information to display for this account request.').'</div>');
1.391 raeburn 5037: }
1.442 raeburn 5038: } else {
5039: $r->print('<div>'.&mt('No information available for this account request.').'</div>');
1.391 raeburn 5040: }
5041: }
5042: }
5043: }
5044: }
1.442 raeburn 5045: $r->print(&close_popup_form());
1.207 raeburn 5046: } elsif (($env{'form.action'} eq 'listusers') &&
5047: ($permission->{'view'} || $permission->{'cusr'})) {
1.439 raeburn 5048: my $helpitem = 'Course_View_Class_List';
5049: if ($context eq 'author') {
5050: $helpitem = 'Author_View_Coauthor_List';
5051: } elsif ($context eq 'domain') {
5052: $helpitem = 'Domain_View_Users_List';
5053: }
1.202 raeburn 5054: if ($env{'form.phase'} eq 'bulkchange') {
1.351 raeburn 5055: push(@{$brcrum},
5056: {href => '/adm/createuser?action=listusers',
5057: text => "List Users"},
5058: {href => "/adm/createuser",
5059: text => "Result",
1.439 raeburn 5060: help => $helpitem});
1.351 raeburn 5061: $bread_crumbs_component = 'Update Users';
5062: $args = {bread_crumbs => $brcrum,
5063: bread_crumbs_component => $bread_crumbs_component};
5064: $r->print(&header(undef,$args));
1.202 raeburn 5065: my $setting = $env{'form.roletype'};
5066: my $choice = $env{'form.bulkaction'};
5067: if ($permission->{'cusr'}) {
1.336 raeburn 5068: &Apache::lonuserutils::update_user_list($r,$context,$setting,$choice,$crstype);
1.221 raeburn 5069: } else {
5070: $r->print(&mt('You are not authorized to make bulk changes to user roles'));
1.223 raeburn 5071: $r->print('<p><a href="/adm/createuser?action=listusers">'.&mt('Display User Lists').'</a>');
1.202 raeburn 5072: }
5073: } else {
1.351 raeburn 5074: push(@{$brcrum},
5075: {href => '/adm/createuser?action=listusers',
5076: text => "List Users",
1.439 raeburn 5077: help => $helpitem});
1.351 raeburn 5078: $bread_crumbs_component = 'List Users';
5079: $args = {bread_crumbs => $brcrum,
5080: bread_crumbs_component => $bread_crumbs_component};
1.202 raeburn 5081: my ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles);
5082: my $formname = 'studentform';
1.364 raeburn 5083: my $hidecall = "hide_searching();";
1.321 raeburn 5084: if (($context eq 'domain') && (($env{'form.roletype'} eq 'course') ||
5085: ($env{'form.roletype'} eq 'community'))) {
5086: if ($env{'form.roletype'} eq 'course') {
5087: ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles) =
5088: &Apache::lonuserutils::courses_selector($env{'request.role.domain'},
5089: $formname);
5090: } elsif ($env{'form.roletype'} eq 'community') {
5091: $cb_jscript =
5092: &Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
5093: my %elements = (
5094: coursepick => 'radio',
5095: coursetotal => 'text',
5096: courselist => 'text',
5097: );
5098: $jscript = &Apache::lonhtmlcommon::set_form_elements(\%elements);
5099: }
1.364 raeburn 5100: $jscript .= &verify_user_display($context)."\n".
5101: &Apache::loncommon::check_uncheck_jscript();
1.202 raeburn 5102: my $js = &add_script($jscript).$cb_jscript;
5103: my $loadcode =
5104: &Apache::lonuserutils::course_selector_loadcode($formname);
5105: if ($loadcode ne '') {
1.364 raeburn 5106: $args->{add_entries} = {onload => "$loadcode;$hidecall"};
5107: } else {
5108: $args->{add_entries} = {onload => $hidecall};
1.202 raeburn 5109: }
1.351 raeburn 5110: $r->print(&header($js,$args));
1.191 raeburn 5111: } else {
1.364 raeburn 5112: $args->{add_entries} = {onload => $hidecall};
5113: $jscript = &verify_user_display($context).
5114: &Apache::loncommon::check_uncheck_jscript();
5115: $r->print(&header(&add_script($jscript),$args));
1.191 raeburn 5116: }
1.202 raeburn 5117: &Apache::lonuserutils::print_userlist($r,undef,$permission,$context,
1.375 raeburn 5118: $formname,$totcodes,$codetitles,$idlist,$idlist_titles,
5119: $showcredits);
1.191 raeburn 5120: }
1.213 raeburn 5121: } elsif ($env{'form.action'} eq 'drop' && $permission->{'cusr'}) {
1.318 raeburn 5122: my $brtext;
5123: if ($crstype eq 'Community') {
5124: $brtext = 'Drop Members';
5125: } else {
5126: $brtext = 'Drop Students';
5127: }
1.351 raeburn 5128: push(@{$brcrum},
5129: {href => '/adm/createuser?action=drop',
5130: text => $brtext,
5131: help => 'Course_Drop_Student'});
5132: if ($env{'form.state'} eq 'done') {
5133: push(@{$brcrum},
5134: {href=>'/adm/createuser?action=drop',
5135: text=>"Result"});
5136: }
5137: $bread_crumbs_component = $brtext;
5138: $args = {bread_crumbs => $brcrum,
5139: bread_crumbs_component => $bread_crumbs_component};
5140: $r->print(&header(undef,$args));
1.213 raeburn 5141: if (!exists($env{'form.state'})) {
1.318 raeburn 5142: &Apache::lonuserutils::print_drop_menu($r,$context,$permission,$crstype);
1.213 raeburn 5143: } elsif ($env{'form.state'} eq 'done') {
5144: &Apache::lonuserutils::update_user_list($r,$context,undef,
5145: $env{'form.action'});
5146: }
1.202 raeburn 5147: } elsif ($env{'form.action'} eq 'dateselect') {
5148: if ($permission->{'cusr'}) {
1.351 raeburn 5149: $r->print(&header(undef,{'no_nav_bar' => 1}).
1.375 raeburn 5150: &Apache::lonuserutils::date_section_selector($context,$permission,
5151: $crstype,$showcredits));
1.202 raeburn 5152: } else {
1.351 raeburn 5153: $r->print(&header(undef,{'no_nav_bar' => 1}).
5154: '<span class="LC_error">'.&mt('You do not have permission to modify dates or sections for users').'</span>');
1.202 raeburn 5155: }
1.237 raeburn 5156: } elsif ($env{'form.action'} eq 'selfenroll') {
1.398 raeburn 5157: if ($permission->{selfenrolladmin}) {
5158: my %currsettings = (
5159: selfenroll_types => $env{'course.'.$cid.'.internal.selfenroll_types'},
5160: selfenroll_registered => $env{'course.'.$cid.'.internal.selfenroll_registered'},
5161: selfenroll_section => $env{'course.'.$cid.'.internal.selfenroll_section'},
5162: selfenroll_notifylist => $env{'course.'.$cid.'.internal.selfenroll_notifylist'},
5163: selfenroll_approval => $env{'course.'.$cid.'.internal.selfenroll_approval'},
5164: selfenroll_limit => $env{'course.'.$cid.'.internal.selfenroll_limit'},
5165: selfenroll_cap => $env{'course.'.$cid.'.internal.selfenroll_cap'},
5166: selfenroll_start_date => $env{'course.'.$cid.'.internal.selfenroll_start_date'},
5167: selfenroll_end_date => $env{'course.'.$cid.'.internal.selfenroll_end_date'},
5168: selfenroll_start_access => $env{'course.'.$cid.'.internal.selfenroll_start_access'},
5169: selfenroll_end_access => $env{'course.'.$cid.'.internal.selfenroll_end_access'},
5170: default_enrollment_start_date => $env{'course.'.$cid.'.default_enrollment_start_date'},
5171: default_enrollment_end_date => $env{'course.'.$cid.'.default_enrollment_end_date'},
1.400 raeburn 5172: uniquecode => $env{'course.'.$cid.'.internal.uniquecode'},
1.398 raeburn 5173: );
5174: push(@{$brcrum},
5175: {href => '/adm/createuser?action=selfenroll',
5176: text => "Configure Self-enrollment",
5177: help => 'Course_Self_Enrollment'});
5178: if (!exists($env{'form.state'})) {
5179: $args = { bread_crumbs => $brcrum,
5180: bread_crumbs_component => 'Configure Self-enrollment'};
5181: $r->print(&header(undef,$args));
5182: $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n");
5183: &print_selfenroll_menu($r,'course',$cid,$cdom,$cnum,\%currsettings);
5184: } elsif ($env{'form.state'} eq 'done') {
5185: push (@{$brcrum},
5186: {href=>'/adm/createuser?action=selfenroll',
5187: text=>"Result"});
5188: $args = { bread_crumbs => $brcrum,
5189: bread_crumbs_component => 'Self-enrollment result'};
5190: $r->print(&header(undef,$args));
5191: $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n");
1.400 raeburn 5192: &update_selfenroll_config($r,$cid,$cdom,$cnum,$context,$crstype,\%currsettings);
1.398 raeburn 5193: }
5194: } else {
5195: $r->print(&header(undef,{'no_nav_bar' => 1}).
5196: '<span class="LC_error">'.&mt('You do not have permission to configure self-enrollment').'</span>');
1.237 raeburn 5197: }
1.277 raeburn 5198: } elsif ($env{'form.action'} eq 'selfenrollqueue') {
1.418 raeburn 5199: if ($permission->{selfenrolladmin}) {
1.351 raeburn 5200: push(@{$brcrum},
5201: {href => '/adm/createuser?action=selfenrollqueue',
1.418 raeburn 5202: text => 'Enrollment requests',
1.439 raeburn 5203: help => 'Course_Approve_Selfenroll'});
1.418 raeburn 5204: $bread_crumbs_component = 'Enrollment requests';
5205: if ($env{'form.state'} eq 'done') {
5206: push(@{$brcrum},
5207: {href => '/adm/createuser?action=selfenrollqueue',
5208: text => 'Result',
1.439 raeburn 5209: help => 'Course_Approve_Selfenroll'});
1.418 raeburn 5210: $bread_crumbs_component = 'Enrollment result';
5211: }
5212: $args = { bread_crumbs => $brcrum,
5213: bread_crumbs_component => $bread_crumbs_component};
5214: $r->print(&header(undef,$args));
5215: my $coursedesc = $env{'course.'.$cid.'.description'};
5216: if (!exists($env{'form.state'})) {
5217: $r->print('<h3>'.&mt('Pending enrollment requests').'</h3>'."\n");
5218: $r->print(&Apache::loncoursequeueadmin::display_queued_requests($context,
5219: $cdom,$cnum));
5220: } elsif ($env{'form.state'} eq 'done') {
5221: $r->print('<h3>'.&mt('Enrollment request processing').'</h3>'."\n");
5222: $r->print(&Apache::loncoursequeueadmin::update_request_queue($context,
1.430 raeburn 5223: $cdom,$cnum,$coursedesc));
1.418 raeburn 5224: }
5225: } else {
5226: $r->print(&header(undef,{'no_nav_bar' => 1}).
5227: '<span class="LC_error">'.&mt('You do not have permission to manage self-enrollment').'</span>');
1.351 raeburn 5228: }
1.418 raeburn 5229: } elsif ($env{'form.action'} eq 'changelogs') {
5230: if ($permission->{cusr} || $permission->{view}) {
5231: &print_userchangelogs_display($r,$context,$permission,$brcrum);
5232: } else {
5233: $r->print(&header(undef,{'no_nav_bar' => 1}).
5234: '<span class="LC_error">'.&mt('You do not have permission to view change logs').'</span>');
1.277 raeburn 5235: }
1.428 raeburn 5236: } elsif ($env{'form.action'} eq 'helpdesk') {
5237: if (($permission->{'owner'}) || ($permission->{'co-owner'})) {
5238: if ($env{'form.state'} eq 'process') {
5239: if ($permission->{'owner'}) {
5240: &update_helpdeskaccess($r,$permission,$brcrum);
5241: } else {
5242: &print_helpdeskaccess_display($r,$permission,$brcrum);
1.430 raeburn 5243: }
1.428 raeburn 5244: } else {
5245: &print_helpdeskaccess_display($r,$permission,$brcrum);
5246: }
5247: } else {
5248: $r->print(&header(undef,{'no_nav_bar' => 1}).
5249: '<span class="LC_error">'.&mt('You do not have permission to view helpdesk access').'</span>');
5250: }
1.190 raeburn 5251: } else {
1.351 raeburn 5252: $bread_crumbs_component = 'User Management';
5253: $args = { bread_crumbs => $brcrum,
5254: bread_crumbs_component => $bread_crumbs_component};
5255: $r->print(&header(undef,$args));
1.318 raeburn 5256: $r->print(&print_main_menu($permission,$context,$crstype));
1.190 raeburn 5257: }
1.351 raeburn 5258: $r->print(&Apache::loncommon::end_page());
1.190 raeburn 5259: return OK;
5260: }
5261:
5262: sub header {
1.351 raeburn 5263: my ($jscript,$args) = @_;
1.190 raeburn 5264: my $start_page;
1.351 raeburn 5265: if (ref($args) eq 'HASH') {
5266: $start_page=&Apache::loncommon::start_page('User Management',$jscript,$args);
1.190 raeburn 5267: } else {
1.351 raeburn 5268: $start_page=&Apache::loncommon::start_page('User Management',$jscript);
1.190 raeburn 5269: }
5270: return $start_page;
5271: }
1.2 www 5272:
1.191 raeburn 5273: sub add_script {
5274: my ($js) = @_;
1.301 bisitz 5275: return '<script type="text/javascript">'."\n"
5276: .'// <![CDATA['."\n"
5277: .$js."\n"
5278: .'// ]]>'."\n"
5279: .'</script>'."\n";
1.191 raeburn 5280: }
5281:
1.391 raeburn 5282: sub usernamerequest_javascript {
5283: my $js = <<ENDJS;
5284:
5285: function openusernamereqdisplay(dom,uname,queue) {
5286: var url = '/adm/createuser?action=displayuserreq';
5287: url += '&domain='+dom+'&username='+uname+'&queue='+queue;
5288: var title = 'Account_Request_Browser';
5289: var options = 'scrollbars=1,resizable=1,menubar=0';
5290: options += ',width=700,height=600';
5291: var stdeditbrowser = open(url,title,options,'1');
5292: stdeditbrowser.focus();
5293: return;
5294: }
5295:
5296: ENDJS
5297: }
5298:
5299: sub close_popup_form {
5300: my $close= &mt('Close Window');
5301: return << "END";
5302: <p><form name="displayreq" action="" method="post">
5303: <input type="button" name="closeme" value="$close" onclick="javascript:self.close();" />
5304: </form></p>
5305: END
5306: }
5307:
1.202 raeburn 5308: sub verify_user_display {
1.364 raeburn 5309: my ($context) = @_;
1.374 raeburn 5310: my %lt = &Apache::lonlocal::texthash (
5311: course => 'course(s): description, section(s), status',
5312: community => 'community(s): description, section(s), status',
5313: author => 'author',
5314: );
1.364 raeburn 5315: my $photos;
5316: if (($context eq 'course') && $env{'request.course.id'}) {
5317: $photos = $env{'course.'.$env{'request.course.id'}.'.internal.showphoto'};
5318: }
1.202 raeburn 5319: my $output = <<"END";
5320:
1.364 raeburn 5321: function hide_searching() {
5322: if (document.getElementById('searching')) {
5323: document.getElementById('searching').style.display = 'none';
5324: }
5325: return;
5326: }
5327:
1.202 raeburn 5328: function display_update() {
5329: document.studentform.action.value = 'listusers';
5330: document.studentform.phase.value = 'display';
5331: document.studentform.submit();
5332: }
5333:
1.364 raeburn 5334: function updateCols(caller) {
5335: var context = '$context';
5336: var photos = '$photos';
5337: if (caller == 'Status') {
1.374 raeburn 5338: if ((context == 'domain') &&
5339: ((document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'course') ||
5340: (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community'))) {
1.364 raeburn 5341: document.getElementById('showcolstatus').checked = false;
5342: document.getElementById('showcolstatus').disabled = 'disabled';
5343: document.getElementById('showcolstart').checked = false;
5344: document.getElementById('showcolend').checked = false;
1.374 raeburn 5345: } else {
5346: if (document.studentform.Status.options[document.studentform.Status.selectedIndex].value == 'Any') {
5347: document.getElementById('showcolstatus').checked = true;
5348: document.getElementById('showcolstatus').disabled = '';
5349: document.getElementById('showcolstart').checked = true;
5350: document.getElementById('showcolend').checked = true;
5351: } else {
5352: document.getElementById('showcolstatus').checked = false;
5353: document.getElementById('showcolstatus').disabled = 'disabled';
5354: document.getElementById('showcolstart').checked = false;
5355: document.getElementById('showcolend').checked = false;
5356: }
1.364 raeburn 5357: }
5358: }
5359: if (caller == 'output') {
5360: if (photos == 1) {
5361: if (document.getElementById('showcolphoto')) {
5362: var photoitem = document.getElementById('showcolphoto');
5363: if (document.studentform.output.options[document.studentform.output.selectedIndex].value == 'html') {
5364: photoitem.checked = true;
5365: photoitem.disabled = '';
5366: } else {
5367: photoitem.checked = false;
5368: photoitem.disabled = 'disabled';
5369: }
5370: }
5371: }
5372: }
5373: if (caller == 'showrole') {
1.371 raeburn 5374: if ((document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'Any') ||
5375: (document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'cr')) {
1.364 raeburn 5376: document.getElementById('showcolrole').checked = true;
5377: document.getElementById('showcolrole').disabled = '';
5378: } else {
5379: document.getElementById('showcolrole').checked = false;
5380: document.getElementById('showcolrole').disabled = 'disabled';
5381: }
1.374 raeburn 5382: if (context == 'domain') {
1.382 raeburn 5383: var quotausageshow = 0;
1.374 raeburn 5384: if ((document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'course') ||
5385: (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community')) {
5386: document.getElementById('showcolstatus').checked = false;
5387: document.getElementById('showcolstatus').disabled = 'disabled';
5388: document.getElementById('showcolstart').checked = false;
5389: document.getElementById('showcolend').checked = false;
5390: } else {
5391: if (document.studentform.Status.options[document.studentform.Status.selectedIndex].value == 'Any') {
5392: document.getElementById('showcolstatus').checked = true;
5393: document.getElementById('showcolstatus').disabled = '';
5394: document.getElementById('showcolstart').checked = true;
5395: document.getElementById('showcolend').checked = true;
5396: }
5397: }
5398: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'domain') {
5399: document.getElementById('showcolextent').disabled = 'disabled';
5400: document.getElementById('showcolextent').checked = 'false';
5401: document.getElementById('showextent').style.display='none';
5402: document.getElementById('showcoltextextent').innerHTML = '';
1.382 raeburn 5403: if ((document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'au') ||
5404: (document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'Any')) {
5405: if (document.getElementById('showcolauthorusage')) {
5406: document.getElementById('showcolauthorusage').disabled = '';
5407: }
5408: if (document.getElementById('showcolauthorquota')) {
5409: document.getElementById('showcolauthorquota').disabled = '';
5410: }
5411: quotausageshow = 1;
5412: }
1.374 raeburn 5413: } else {
5414: document.getElementById('showextent').style.display='block';
5415: document.getElementById('showextent').style.textAlign='left';
5416: document.getElementById('showextent').style.textFace='normal';
5417: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'author') {
5418: document.getElementById('showcolextent').disabled = '';
5419: document.getElementById('showcolextent').checked = 'true';
5420: document.getElementById('showcoltextextent').innerHTML="$lt{'author'}";
5421: } else {
5422: document.getElementById('showcolextent').disabled = '';
5423: document.getElementById('showcolextent').checked = 'true';
5424: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community') {
5425: document.getElementById('showcoltextextent').innerHTML="$lt{'community'}";
5426: } else {
5427: document.getElementById('showcoltextextent').innerHTML="$lt{'course'}";
5428: }
5429: }
5430: }
1.382 raeburn 5431: if (quotausageshow == 0) {
5432: if (document.getElementById('showcolauthorusage')) {
5433: document.getElementById('showcolauthorusage').checked = false;
5434: document.getElementById('showcolauthorusage').disabled = 'disabled';
5435: }
5436: if (document.getElementById('showcolauthorquota')) {
5437: document.getElementById('showcolauthorquota').checked = false;
5438: document.getElementById('showcolauthorquota').disabled = 'disabled';
5439: }
5440: }
1.374 raeburn 5441: }
1.364 raeburn 5442: }
5443: return;
5444: }
5445:
1.202 raeburn 5446: END
5447: return $output;
5448:
5449: }
5450:
1.190 raeburn 5451: ###############################################################
5452: ###############################################################
5453: # Menu Phase One
5454: sub print_main_menu {
1.318 raeburn 5455: my ($permission,$context,$crstype) = @_;
5456: my $linkcontext = $context;
5457: my $stuterm = lc(&Apache::lonnet::plaintext('st',$crstype));
5458: if (($context eq 'course') && ($crstype eq 'Community')) {
5459: $linkcontext = lc($crstype);
5460: $stuterm = 'Members';
5461: }
1.208 raeburn 5462: my %links = (
1.298 droeschl 5463: domain => {
5464: upload => 'Upload a File of Users',
5465: singleuser => 'Add/Modify a User',
5466: listusers => 'Manage Users',
5467: },
5468: author => {
5469: upload => 'Upload a File of Co-authors',
5470: singleuser => 'Add/Modify a Co-author',
5471: listusers => 'Manage Co-authors',
5472: },
5473: course => {
5474: upload => 'Upload a File of Course Users',
5475: singleuser => 'Add/Modify a Course User',
1.354 www 5476: listusers => 'List and Modify Multiple Course Users',
1.298 droeschl 5477: },
1.318 raeburn 5478: community => {
5479: upload => 'Upload a File of Community Users',
5480: singleuser => 'Add/Modify a Community User',
1.354 www 5481: listusers => 'List and Modify Multiple Community Users',
1.318 raeburn 5482: },
5483: );
5484: my %linktitles = (
5485: domain => {
5486: singleuser => 'Add a user to the domain, and/or a course or community in the domain.',
5487: listusers => 'Show and manage users in this domain.',
5488: },
5489: author => {
5490: singleuser => 'Add a user with a co- or assistant author role.',
5491: listusers => 'Show and manage co- or assistant authors.',
5492: },
5493: course => {
5494: singleuser => 'Add a user with a certain role to this course.',
5495: listusers => 'Show and manage users in this course.',
5496: },
5497: community => {
5498: singleuser => 'Add a user with a certain role to this community.',
5499: listusers => 'Show and manage users in this community.',
5500: },
1.298 droeschl 5501: );
1.418 raeburn 5502: if ($linkcontext eq 'domain') {
5503: unless ($permission->{'cusr'}) {
1.430 raeburn 5504: $links{'domain'}{'singleuser'} = 'View a User';
1.418 raeburn 5505: $linktitles{'domain'}{'singleuser'} = 'View information about a user in the domain';
5506: }
5507: } elsif ($linkcontext eq 'course') {
5508: unless ($permission->{'cusr'}) {
5509: $links{'course'}{'singleuser'} = 'View a Course User';
5510: $linktitles{'course'}{'singleuser'} = 'View information about a user in this course';
5511: $links{'course'}{'listusers'} = 'List Course Users';
5512: $linktitles{'course'}{'listusers'} = 'Show information about users in this course';
5513: }
5514: } elsif ($linkcontext eq 'community') {
5515: unless ($permission->{'cusr'}) {
5516: $links{'community'}{'singleuser'} = 'View a Community User';
5517: $linktitles{'community'}{'singleuser'} = 'View information about a user in this community';
5518: $links{'community'}{'listusers'} = 'List Community Users';
5519: $linktitles{'community'}{'listusers'} = 'Show information about users in this community';
5520: }
5521: }
1.298 droeschl 5522: my @menu = ( {categorytitle => 'Single Users',
5523: items =>
5524: [
5525: {
1.318 raeburn 5526: linktext => $links{$linkcontext}{'singleuser'},
1.298 droeschl 5527: icon => 'edit-redo.png',
5528: #help => 'Course_Change_Privileges',
5529: url => '/adm/createuser?action=singleuser',
1.418 raeburn 5530: permission => ($permission->{'view'} || $permission->{'cusr'}),
1.318 raeburn 5531: linktitle => $linktitles{$linkcontext}{'singleuser'},
1.298 droeschl 5532: },
5533: ]},
5534:
5535: {categorytitle => 'Multiple Users',
5536: items =>
5537: [
5538: {
1.318 raeburn 5539: linktext => $links{$linkcontext}{'upload'},
1.340 wenzelju 5540: icon => 'uplusr.png',
1.298 droeschl 5541: #help => 'Course_Create_Class_List',
5542: url => '/adm/createuser?action=upload',
5543: permission => $permission->{'cusr'},
5544: linktitle => 'Upload a CSV or a text file containing users.',
5545: },
5546: {
1.318 raeburn 5547: linktext => $links{$linkcontext}{'listusers'},
1.340 wenzelju 5548: icon => 'mngcu.png',
1.298 droeschl 5549: #help => 'Course_View_Class_List',
5550: url => '/adm/createuser?action=listusers',
5551: permission => ($permission->{'view'} || $permission->{'cusr'}),
1.318 raeburn 5552: linktitle => $linktitles{$linkcontext}{'listusers'},
1.298 droeschl 5553: },
5554:
5555: ]},
5556:
5557: {categorytitle => 'Administration',
5558: items => [ ]},
5559: );
1.415 raeburn 5560:
1.265 mielkec 5561: if ($context eq 'domain'){
1.416 raeburn 5562: push(@{ $menu[0]->{items} }, # Single Users
5563: {
5564: linktext => 'User Access Log',
1.417 raeburn 5565: icon => 'document-properties.png',
1.425 raeburn 5566: #help => 'Domain_User_Access_Logs',
1.416 raeburn 5567: url => '/adm/createuser?action=accesslogs',
5568: permission => $permission->{'activity'},
5569: linktitle => 'View user access log.',
5570: }
5571: );
1.298 droeschl 5572:
5573: push(@{ $menu[2]->{items} }, #Category: Administration
5574: {
5575: linktext => 'Custom Roles',
5576: icon => 'emblem-photos.png',
5577: #help => 'Course_Editing_Custom_Roles',
5578: url => '/adm/createuser?action=custom',
5579: permission => $permission->{'custom'},
5580: linktitle => 'Configure a custom role.',
5581: },
1.362 raeburn 5582: {
5583: linktext => 'Authoring Space Requests',
5584: icon => 'selfenrl-queue.png',
5585: #help => 'Domain_Role_Approvals',
5586: url => '/adm/createuser?action=processauthorreq',
5587: permission => $permission->{'cusr'},
5588: linktitle => 'Approve or reject author role requests',
5589: },
1.363 raeburn 5590: {
1.391 raeburn 5591: linktext => 'LON-CAPA Account Requests',
5592: icon => 'list-add.png',
5593: #help => 'Domain_Username_Approvals',
5594: url => '/adm/createuser?action=processusernamereq',
5595: permission => $permission->{'cusr'},
5596: linktitle => 'Approve or reject LON-CAPA account requests',
5597: },
5598: {
1.363 raeburn 5599: linktext => 'Change Log',
5600: icon => 'document-properties.png',
5601: #help => 'Course_User_Logs',
5602: url => '/adm/createuser?action=changelogs',
1.418 raeburn 5603: permission => ($permission->{'cusr'} || $permission->{'view'}),
1.363 raeburn 5604: linktitle => 'View change log.',
5605: },
1.298 droeschl 5606: );
5607:
1.265 mielkec 5608: }elsif ($context eq 'course'){
1.298 droeschl 5609: my ($cnum,$cdom) = &Apache::lonuserutils::get_course_identity();
1.318 raeburn 5610:
5611: my %linktext = (
5612: 'Course' => {
5613: single => 'Add/Modify a Student',
5614: drop => 'Drop Students',
5615: groups => 'Course Groups',
5616: },
5617: 'Community' => {
5618: single => 'Add/Modify a Member',
5619: drop => 'Drop Members',
5620: groups => 'Community Groups',
5621: },
5622: );
1.411 raeburn 5623: $linktext{'Placement'} = $linktext{'Course'};
1.318 raeburn 5624:
5625: my %linktitle = (
5626: 'Course' => {
5627: single => 'Add a user with the role of student to this course',
5628: drop => 'Remove a student from this course.',
5629: groups => 'Manage course groups',
5630: },
5631: 'Community' => {
5632: single => 'Add a user with the role of member to this community',
5633: drop => 'Remove a member from this community.',
5634: groups => 'Manage community groups',
5635: },
5636: );
5637:
1.411 raeburn 5638: $linktitle{'Placement'} = $linktitle{'Course'};
5639:
1.298 droeschl 5640: push(@{ $menu[0]->{items} }, #Category: Single Users
5641: {
1.318 raeburn 5642: linktext => $linktext{$crstype}{'single'},
1.298 droeschl 5643: #help => 'Course_Add_Student',
5644: icon => 'list-add.png',
5645: url => '/adm/createuser?action=singlestudent',
5646: permission => $permission->{'cusr'},
1.318 raeburn 5647: linktitle => $linktitle{$crstype}{'single'},
1.298 droeschl 5648: },
5649: );
5650:
5651: push(@{ $menu[1]->{items} }, #Category: Multiple Users
5652: {
1.318 raeburn 5653: linktext => $linktext{$crstype}{'drop'},
1.298 droeschl 5654: icon => 'edit-undo.png',
5655: #help => 'Course_Drop_Student',
5656: url => '/adm/createuser?action=drop',
5657: permission => $permission->{'cusr'},
1.318 raeburn 5658: linktitle => $linktitle{$crstype}{'drop'},
1.298 droeschl 5659: },
5660: );
5661: push(@{ $menu[2]->{items} }, #Category: Administration
1.428 raeburn 5662: {
5663: linktext => 'Helpdesk Access',
5664: icon => 'helpdesk-access.png',
5665: #help => 'Course_Helpdesk_Access',
5666: url => '/adm/createuser?action=helpdesk',
5667: permission => ($permission->{'owner'} || $permission->{'co-owner'}),
5668: linktitle => 'Helpdesk access options',
5669: },
5670: {
1.298 droeschl 5671: linktext => 'Custom Roles',
5672: icon => 'emblem-photos.png',
5673: #help => 'Course_Editing_Custom_Roles',
5674: url => '/adm/createuser?action=custom',
5675: permission => $permission->{'custom'},
5676: linktitle => 'Configure a custom role.',
5677: },
5678: {
1.318 raeburn 5679: linktext => $linktext{$crstype}{'groups'},
1.333 wenzelju 5680: icon => 'grps.png',
1.298 droeschl 5681: #help => 'Course_Manage_Group',
5682: url => '/adm/coursegroups?refpage=cusr',
5683: permission => $permission->{'grp_manage'},
1.318 raeburn 5684: linktitle => $linktitle{$crstype}{'groups'},
1.298 droeschl 5685: },
5686: {
1.328 wenzelju 5687: linktext => 'Change Log',
1.298 droeschl 5688: icon => 'document-properties.png',
5689: #help => 'Course_User_Logs',
5690: url => '/adm/createuser?action=changelogs',
1.418 raeburn 5691: permission => ($permission->{'view'} || $permission->{'cusr'}),
1.298 droeschl 5692: linktitle => 'View change log.',
5693: },
5694: );
1.277 raeburn 5695: if ($env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_approval'}) {
1.298 droeschl 5696: push(@{ $menu[2]->{items} },
1.398 raeburn 5697: {
1.298 droeschl 5698: linktext => 'Enrollment Requests',
5699: icon => 'selfenrl-queue.png',
5700: #help => 'Course_Approve_Selfenroll',
5701: url => '/adm/createuser?action=selfenrollqueue',
1.398 raeburn 5702: permission => $permission->{'selfenrolladmin'},
1.298 droeschl 5703: linktitle =>'Approve or reject enrollment requests.',
5704: },
5705: );
1.277 raeburn 5706: }
1.298 droeschl 5707:
1.265 mielkec 5708: if (!exists($permission->{'cusr_section'})){
1.320 raeburn 5709: if ($crstype ne 'Community') {
5710: push(@{ $menu[2]->{items} },
5711: {
5712: linktext => 'Automated Enrollment',
5713: icon => 'roles.png',
5714: #help => 'Course_Automated_Enrollment',
5715: permission => (&Apache::lonnet::auto_run($cnum,$cdom)
1.418 raeburn 5716: && (($permission->{'cusr'}) ||
5717: ($permission->{'view'}))),
1.320 raeburn 5718: url => '/adm/populate',
5719: linktitle => 'Automated enrollment manager.',
5720: }
5721: );
5722: }
5723: push(@{ $menu[2]->{items} },
1.298 droeschl 5724: {
5725: linktext => 'User Self-Enrollment',
1.342 wenzelju 5726: icon => 'self_enroll.png',
1.298 droeschl 5727: #help => 'Course_Self_Enrollment',
5728: url => '/adm/createuser?action=selfenroll',
1.398 raeburn 5729: permission => $permission->{'selfenrolladmin'},
1.317 bisitz 5730: linktitle => 'Configure user self-enrollment.',
1.298 droeschl 5731: },
5732: );
5733: }
1.363 raeburn 5734: } elsif ($context eq 'author') {
1.370 raeburn 5735: push(@{ $menu[2]->{items} }, #Category: Administration
1.363 raeburn 5736: {
5737: linktext => 'Change Log',
5738: icon => 'document-properties.png',
5739: #help => 'Course_User_Logs',
5740: url => '/adm/createuser?action=changelogs',
5741: permission => $permission->{'cusr'},
5742: linktitle => 'View change log.',
5743: },
1.370 raeburn 5744: );
1.363 raeburn 5745: }
5746: return Apache::lonhtmlcommon::generate_menu(@menu);
1.250 raeburn 5747: # { text => 'View Log-in History',
5748: # help => 'Course_User_Logins',
5749: # action => 'logins',
5750: # permission => $permission->{'cusr'},
5751: # });
1.190 raeburn 5752: }
5753:
1.189 albertel 5754: sub restore_prev_selections {
5755: my %saveable_parameters = ('srchby' => 'scalar',
5756: 'srchin' => 'scalar',
5757: 'srchtype' => 'scalar',
5758: );
5759: &Apache::loncommon::store_settings('user','user_picker',
5760: \%saveable_parameters);
5761: &Apache::loncommon::restore_settings('user','user_picker',
5762: \%saveable_parameters);
5763: }
5764:
1.237 raeburn 5765: sub print_selfenroll_menu {
1.418 raeburn 5766: my ($r,$context,$cid,$cdom,$cnum,$currsettings,$additional,$readonly) = @_;
1.322 raeburn 5767: my $crstype = &Apache::loncommon::course_type();
1.398 raeburn 5768: my $formname = 'selfenroll';
1.237 raeburn 5769: my $nolink = 1;
1.398 raeburn 5770: my ($row,$lt) = &Apache::lonuserutils::get_selfenroll_titles();
1.237 raeburn 5771: my $groupslist = &Apache::lonuserutils::get_groupslist();
5772: my $setsec_js =
5773: &Apache::lonuserutils::setsections_javascript($formname,$groupslist);
1.249 raeburn 5774: my %alerts = &Apache::lonlocal::texthash(
5775: acto => 'Activation of self-enrollment was selected for the following domain(s)',
5776: butn => 'but no user types have been checked.',
5777: wilf => "Please uncheck 'activate' or check at least one type.",
5778: );
1.418 raeburn 5779: my $disabled;
5780: if ($readonly) {
5781: $disabled = ' disabled="disabled"';
5782: }
1.405 damieng 5783: &js_escape(\%alerts);
1.249 raeburn 5784: my $selfenroll_js = <<"ENDSCRIPT";
5785: function update_types(caller,num) {
5786: var delidx = getIndexByName('selfenroll_delete');
5787: var actidx = getIndexByName('selfenroll_activate');
5788: if (caller == 'selfenroll_all') {
5789: var selall;
5790: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
5791: if (document.$formname.selfenroll_all[i].checked) {
5792: selall = document.$formname.selfenroll_all[i].value;
5793: }
5794: }
5795: if (selall == 1) {
5796: if (delidx != -1) {
5797: if (document.$formname.selfenroll_delete.length) {
5798: for (var j=0; j<document.$formname.selfenroll_delete.length; j++) {
5799: document.$formname.selfenroll_delete[j].checked = true;
5800: }
5801: } else {
5802: document.$formname.elements[delidx].checked = true;
5803: }
5804: }
5805: if (actidx != -1) {
5806: if (document.$formname.selfenroll_activate.length) {
5807: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
5808: document.$formname.selfenroll_activate[j].checked = false;
5809: }
5810: } else {
5811: document.$formname.elements[actidx].checked = false;
5812: }
5813: }
5814: document.$formname.selfenroll_newdom.selectedIndex = 0;
5815: }
5816: }
5817: if (caller == 'selfenroll_activate') {
5818: if (document.$formname.selfenroll_activate.length) {
5819: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
5820: if (document.$formname.selfenroll_activate[j].value == num) {
5821: if (document.$formname.selfenroll_activate[j].checked) {
5822: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
5823: if (document.$formname.selfenroll_all[i].value == '1') {
5824: document.$formname.selfenroll_all[i].checked = false;
5825: }
5826: if (document.$formname.selfenroll_all[i].value == '0') {
5827: document.$formname.selfenroll_all[i].checked = true;
5828: }
5829: }
5830: }
5831: }
5832: }
5833: } else {
5834: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
5835: if (document.$formname.selfenroll_all[i].value == '1') {
5836: document.$formname.selfenroll_all[i].checked = false;
5837: }
5838: if (document.$formname.selfenroll_all[i].value == '0') {
5839: document.$formname.selfenroll_all[i].checked = true;
5840: }
5841: }
5842: }
5843: }
5844: if (caller == 'selfenroll_delete') {
5845: if (document.$formname.selfenroll_delete.length) {
5846: for (var j=0; j<document.$formname.selfenroll_delete.length; j++) {
5847: if (document.$formname.selfenroll_delete[j].value == num) {
5848: if (document.$formname.selfenroll_delete[j].checked) {
5849: var delindex = getIndexByName('selfenroll_types_'+num);
5850: if (delindex != -1) {
5851: if (document.$formname.elements[delindex].length) {
5852: for (var k=0; k<document.$formname.elements[delindex].length; k++) {
5853: document.$formname.elements[delindex][k].checked = false;
5854: }
5855: } else {
5856: document.$formname.elements[delindex].checked = false;
5857: }
5858: }
5859: }
5860: }
5861: }
5862: } else {
5863: if (document.$formname.selfenroll_delete.checked) {
5864: var delindex = getIndexByName('selfenroll_types_'+num);
5865: if (delindex != -1) {
5866: if (document.$formname.elements[delindex].length) {
5867: for (var k=0; k<document.$formname.elements[delindex].length; k++) {
5868: document.$formname.elements[delindex][k].checked = false;
5869: }
5870: } else {
5871: document.$formname.elements[delindex].checked = false;
5872: }
5873: }
5874: }
5875: }
5876: }
5877: return;
5878: }
5879:
5880: function validate_types(form) {
5881: var needaction = new Array();
5882: var countfail = 0;
5883: var actidx = getIndexByName('selfenroll_activate');
5884: if (actidx != -1) {
5885: if (document.$formname.selfenroll_activate.length) {
5886: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
5887: var num = document.$formname.selfenroll_activate[j].value;
5888: if (document.$formname.selfenroll_activate[j].checked) {
5889: countfail = check_types(num,countfail,needaction)
5890: }
5891: }
5892: } else {
5893: if (document.$formname.selfenroll_activate.checked) {
1.398 raeburn 5894: var num = document.$formname.selfenroll_activate.value;
1.249 raeburn 5895: countfail = check_types(num,countfail,needaction)
5896: }
5897: }
5898: }
5899: if (countfail > 0) {
5900: var msg = "$alerts{'acto'}\\n";
5901: var loopend = needaction.length -1;
5902: if (loopend > 0) {
5903: for (var m=0; m<loopend; m++) {
5904: msg += needaction[m]+", ";
5905: }
5906: }
5907: msg += needaction[loopend]+"\\n$alerts{'butn'}\\n$alerts{'wilf'}";
5908: alert(msg);
5909: return;
5910: }
5911: setSections(form);
5912: }
5913:
5914: function check_types(num,countfail,needaction) {
1.441 raeburn 5915: var boxname = 'selfenroll_types_'+num;
5916: var typeidx = getIndexByName(boxname);
1.249 raeburn 5917: var count = 0;
5918: if (typeidx != -1) {
1.441 raeburn 5919: if (document.$formname.elements[boxname].length) {
5920: for (var k=0; k<document.$formname.elements[boxname].length; k++) {
5921: if (document.$formname.elements[boxname][k].checked) {
1.249 raeburn 5922: count ++;
5923: }
5924: }
5925: } else {
5926: if (document.$formname.elements[typeidx].checked) {
5927: count ++;
5928: }
5929: }
5930: if (count == 0) {
5931: var domidx = getIndexByName('selfenroll_dom_'+num);
5932: if (domidx != -1) {
5933: var domname = document.$formname.elements[domidx].value;
5934: needaction[countfail] = domname;
5935: countfail ++;
5936: }
5937: }
5938: }
5939: return countfail;
5940: }
5941:
1.398 raeburn 5942: function toggleNotify() {
5943: var selfenrollApproval = 0;
5944: if (document.$formname.selfenroll_approval.length) {
5945: for (var i=0; i<document.$formname.selfenroll_approval.length; i++) {
5946: if (document.$formname.selfenroll_approval[i].checked) {
5947: selfenrollApproval = document.$formname.selfenroll_approval[i].value;
5948: break;
5949: }
5950: }
5951: }
5952: if (document.getElementById('notified')) {
5953: if (selfenrollApproval == 0) {
5954: document.getElementById('notified').style.display='none';
5955: } else {
5956: document.getElementById('notified').style.display='block';
5957: }
5958: }
5959: return;
5960: }
5961:
1.249 raeburn 5962: function getIndexByName(item) {
5963: for (var i=0;i<document.$formname.elements.length;i++) {
5964: if (document.$formname.elements[i].name == item) {
5965: return i;
5966: }
5967: }
5968: return -1;
5969: }
5970: ENDSCRIPT
1.256 raeburn 5971:
1.237 raeburn 5972: my $output = '<script type="text/javascript">'."\n".
1.301 bisitz 5973: '// <![CDATA['."\n".
1.249 raeburn 5974: $setsec_js."\n".$selfenroll_js."\n".
1.301 bisitz 5975: '// ]]>'."\n".
1.237 raeburn 5976: '</script>'."\n".
1.256 raeburn 5977: '<h3>'.$lt->{'selfenroll'}.'</h3>'."\n";
1.400 raeburn 5978:
5979: my $visactions = &cat_visibility();
5980: my ($cathash,%cattype);
5981: my %domconfig = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom);
5982: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
5983: $cathash = $domconfig{'coursecategories'}{'cats'};
5984: $cattype{'auth'} = $domconfig{'coursecategories'}{'auth'};
5985: $cattype{'unauth'} = $domconfig{'coursecategories'}{'unauth'};
1.406 raeburn 5986: if ($cattype{'auth'} eq '') {
5987: $cattype{'auth'} = 'std';
5988: }
5989: if ($cattype{'unauth'} eq '') {
5990: $cattype{'unauth'} = 'std';
5991: }
1.400 raeburn 5992: } else {
5993: $cathash = {};
5994: $cattype{'auth'} = 'std';
5995: $cattype{'unauth'} = 'std';
5996: }
5997: if (($cattype{'auth'} eq 'none') && ($cattype{'unauth'} eq 'none')) {
5998: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
5999: '<br />'.
6000: '<br />'.$visactions->{'take'}.'<ul>'.
6001: '<li>'.$visactions->{'dc_chgconf'}.'</li>'.
6002: '</ul>');
6003: } elsif (($cattype{'auth'} !~ /^(std|domonly)$/) && ($cattype{'unauth'} !~ /^(std|domonly)$/)) {
6004: if ($currsettings->{'uniquecode'}) {
6005: $r->print('<span class="LC_info">'.$visactions->{'vis'}.'</span>');
6006: } else {
6007: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
6008: '<br />'.
6009: '<br />'.$visactions->{'take'}.'<ul>'.
6010: '<li>'.$visactions->{'dc_setcode'}.'</li>'.
6011: '</ul><br />');
6012: }
6013: } else {
6014: my ($visible,$cansetvis,$vismsgs) = &visible_in_stdcat($cdom,$cnum,\%domconfig);
6015: if (ref($visactions) eq 'HASH') {
6016: if ($visible) {
6017: $output .= '<p class="LC_info">'.$visactions->{'vis'}.'</p>';
6018: } else {
6019: $output .= '<p class="LC_warning">'.$visactions->{'miss'}.'</p>'
6020: .$visactions->{'yous'}.
6021: '<p>'.$visactions->{'gen'}.'<br />'.$visactions->{'coca'};
6022: if (ref($vismsgs) eq 'ARRAY') {
6023: $output .= '<br />'.$visactions->{'make'}.'<ul>';
6024: foreach my $item (@{$vismsgs}) {
6025: $output .= '<li>'.$visactions->{$item}.'</li>';
6026: }
6027: $output .= '</ul>';
1.256 raeburn 6028: }
1.400 raeburn 6029: $output .= '</p>';
1.256 raeburn 6030: }
6031: }
6032: }
1.398 raeburn 6033: my $actionhref = '/adm/createuser';
6034: if ($context eq 'domain') {
6035: $actionhref = '/adm/modifycourse';
6036: }
1.400 raeburn 6037:
6038: my %noedit;
6039: unless ($context eq 'domain') {
6040: %noedit = &get_noedit_fields($cdom,$cnum,$crstype,$row);
6041: }
1.398 raeburn 6042: $output .= '<form name="'.$formname.'" method="post" action="'.$actionhref.'">'."\n".
1.256 raeburn 6043: &Apache::lonhtmlcommon::start_pick_box();
1.237 raeburn 6044: if (ref($row) eq 'ARRAY') {
6045: foreach my $item (@{$row}) {
6046: my $title = $item;
6047: if (ref($lt) eq 'HASH') {
6048: $title = $lt->{$item};
6049: }
1.297 bisitz 6050: $output .= &Apache::lonhtmlcommon::row_title($title);
1.237 raeburn 6051: if ($item eq 'types') {
1.398 raeburn 6052: my $curr_types;
6053: if (ref($currsettings) eq 'HASH') {
6054: $curr_types = $currsettings->{'selfenroll_types'};
6055: }
1.400 raeburn 6056: if ($noedit{$item}) {
6057: if ($curr_types eq '*') {
6058: $output .= &mt('Any user in any domain');
6059: } else {
6060: my @entries = split(/;/,$curr_types);
6061: if (@entries > 0) {
6062: $output .= '<ul>';
6063: foreach my $entry (@entries) {
6064: my ($currdom,$typestr) = split(/:/,$entry);
6065: next if ($typestr eq '');
6066: my $domdesc = &Apache::lonnet::domain($currdom);
6067: my @currinsttypes = split(',',$typestr);
6068: my ($othertitle,$usertypes,$types) =
6069: &Apache::loncommon::sorted_inst_types($currdom);
6070: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
6071: $usertypes->{'any'} = &mt('any user');
6072: if (keys(%{$usertypes}) > 0) {
6073: $usertypes->{'other'} = &mt('other users');
6074: }
6075: my @longinsttypes = map { $usertypes->{$_}; } @currinsttypes;
6076: $output .= '<li>'.$domdesc.':'.join(', ',@longinsttypes).'</li>';
6077: }
6078: }
6079: $output .= '</ul>';
6080: } else {
6081: $output .= &mt('None');
6082: }
6083: }
6084: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6085: next;
6086: }
1.241 raeburn 6087: my $showdomdesc = 1;
6088: my $includeempty = 1;
6089: my $num = 0;
6090: $output .= &Apache::loncommon::start_data_table().
6091: &Apache::loncommon::start_data_table_row()
6092: .'<td colspan="2"><span class="LC_nobreak"><label>'
6093: .&mt('Any user in any domain:')
6094: .' <input type="radio" name="selfenroll_all" value="1" ';
6095: if ($curr_types eq '*') {
6096: $output .= ' checked="checked" ';
6097: }
1.249 raeburn 6098: $output .= 'onchange="javascript:update_types('.
1.418 raeburn 6099: "'selfenroll_all'".');"'.$disabled.' />'.&mt('Yes').'</label>'.
1.249 raeburn 6100: ' <input type="radio" name="selfenroll_all" value="0" ';
1.241 raeburn 6101: if ($curr_types ne '*') {
6102: $output .= ' checked="checked" ';
6103: }
1.249 raeburn 6104: $output .= ' onchange="javascript:update_types('.
1.418 raeburn 6105: "'selfenroll_all'".');"'.$disabled.' />'.&mt('No').'</label></td>'.
1.249 raeburn 6106: &Apache::loncommon::end_data_table_row().
6107: &Apache::loncommon::end_data_table().
6108: &mt('Or').'<br />'.
6109: &Apache::loncommon::start_data_table();
1.241 raeburn 6110: my %currdoms;
1.249 raeburn 6111: if ($curr_types eq '') {
1.241 raeburn 6112: $output .= &new_selfenroll_dom_row($cdom,'0');
6113: } elsif ($curr_types ne '*') {
6114: my @entries = split(/;/,$curr_types);
6115: if (@entries > 0) {
6116: foreach my $entry (@entries) {
6117: my ($currdom,$typestr) = split(/:/,$entry);
6118: $currdoms{$currdom} = 1;
6119: my $domdesc = &Apache::lonnet::domain($currdom);
1.249 raeburn 6120: my @currinsttypes = split(',',$typestr);
1.241 raeburn 6121: $output .= &Apache::loncommon::start_data_table_row()
6122: .'<td valign="top"><span class="LC_nobreak">'.&mt('Domain:').'<b>'
6123: .' '.$domdesc.' ('.$currdom.')'
6124: .'</b><input type="hidden" name="selfenroll_dom_'.$num
6125: .'" value="'.$currdom.'" /></span><br />'
6126: .'<span class="LC_nobreak"><label><input type="checkbox" '
1.418 raeburn 6127: .'name="selfenroll_delete" value="'.$num.'" onchange="javascript:update_types('."'selfenroll_delete','$num'".');"'.$disabled.' />'
1.241 raeburn 6128: .&mt('Delete').'</label></span></td>';
1.249 raeburn 6129: $output .= '<td valign="top"> '.&mt('User types:').'<br />'
1.418 raeburn 6130: .&selfenroll_inst_types($num,$currdom,\@currinsttypes,$readonly).'</td>'
1.241 raeburn 6131: .&Apache::loncommon::end_data_table_row();
6132: $num ++;
6133: }
6134: }
6135: }
1.249 raeburn 6136: my $add_domtitle = &mt('Users in additional domain:');
1.241 raeburn 6137: if ($curr_types eq '*') {
1.249 raeburn 6138: $add_domtitle = &mt('Users in specific domain:');
1.241 raeburn 6139: } elsif ($curr_types eq '') {
1.249 raeburn 6140: $add_domtitle = &mt('Users in other domain:');
1.241 raeburn 6141: }
1.444 ! raeburn 6142: my ($trustedref,$untrustedref) = &Apache::lonnet::trusted_domains('enroll',$cdom);
1.241 raeburn 6143: $output .= &Apache::loncommon::start_data_table_row()
6144: .'<td colspan="2"><span class="LC_nobreak">'.$add_domtitle.'</span><br />'
6145: .&Apache::loncommon::select_dom_form('','selfenroll_newdom',
1.444 ! raeburn 6146: $includeempty,$showdomdesc,'',$trustedref,$untrustedref,$readonly)
1.241 raeburn 6147: .'<input type="hidden" name="selfenroll_types_total" value="'.$num.'" />'
6148: .'</td>'.&Apache::loncommon::end_data_table_row()
6149: .&Apache::loncommon::end_data_table();
1.237 raeburn 6150: } elsif ($item eq 'registered') {
6151: my ($regon,$regoff);
1.398 raeburn 6152: my $registered;
6153: if (ref($currsettings) eq 'HASH') {
6154: $registered = $currsettings->{'selfenroll_registered'};
6155: }
1.400 raeburn 6156: if ($noedit{$item}) {
6157: if ($registered) {
6158: $output .= &mt('Must be registered in course');
6159: } else {
6160: $output .= &mt('No requirement');
6161: }
6162: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6163: next;
6164: }
1.398 raeburn 6165: if ($registered) {
1.237 raeburn 6166: $regon = ' checked="checked" ';
1.419 raeburn 6167: $regoff = '';
1.237 raeburn 6168: } else {
1.419 raeburn 6169: $regon = '';
1.237 raeburn 6170: $regoff = ' checked="checked" ';
6171: }
6172: $output .= '<label>'.
1.419 raeburn 6173: '<input type="radio" name="selfenroll_registered" value="1"'.$regon.$disabled.' />'.
1.244 bisitz 6174: &mt('Yes').'</label> <label>'.
1.419 raeburn 6175: '<input type="radio" name="selfenroll_registered" value="0"'.$regoff.$disabled.' />'.
1.244 bisitz 6176: &mt('No').'</label>';
1.237 raeburn 6177: } elsif ($item eq 'enroll_dates') {
1.398 raeburn 6178: my ($starttime,$endtime);
6179: if (ref($currsettings) eq 'HASH') {
6180: $starttime = $currsettings->{'selfenroll_start_date'};
6181: $endtime = $currsettings->{'selfenroll_end_date'};
6182: if ($starttime eq '') {
6183: $starttime = $currsettings->{'default_enrollment_start_date'};
6184: }
6185: if ($endtime eq '') {
6186: $endtime = $currsettings->{'default_enrollment_end_date'};
6187: }
1.237 raeburn 6188: }
1.400 raeburn 6189: if ($noedit{$item}) {
6190: $output .= &mt('From: [_1], to: [_2]',&Apache::lonlocal::locallocaltime($starttime),
6191: &Apache::lonlocal::locallocaltime($endtime));
6192: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6193: next;
6194: }
1.237 raeburn 6195: my $startform =
6196: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_start_date',$starttime,
1.418 raeburn 6197: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
1.237 raeburn 6198: my $endform =
6199: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_end_date',$endtime,
1.418 raeburn 6200: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
1.237 raeburn 6201: $output .= &selfenroll_date_forms($startform,$endform);
6202: } elsif ($item eq 'access_dates') {
1.398 raeburn 6203: my ($starttime,$endtime);
6204: if (ref($currsettings) eq 'HASH') {
6205: $starttime = $currsettings->{'selfenroll_start_access'};
6206: $endtime = $currsettings->{'selfenroll_end_access'};
6207: if ($starttime eq '') {
6208: $starttime = $currsettings->{'default_enrollment_start_date'};
6209: }
6210: if ($endtime eq '') {
6211: $endtime = $currsettings->{'default_enrollment_end_date'};
6212: }
1.237 raeburn 6213: }
1.400 raeburn 6214: if ($noedit{$item}) {
6215: $output .= &mt('From: [_1], to: [_2]',&Apache::lonlocal::locallocaltime($starttime),
6216: &Apache::lonlocal::locallocaltime($endtime));
6217: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6218: next;
6219: }
1.237 raeburn 6220: my $startform =
6221: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_start_access',$starttime,
1.418 raeburn 6222: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
1.237 raeburn 6223: my $endform =
6224: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_end_access',$endtime,
1.418 raeburn 6225: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
1.237 raeburn 6226: $output .= &selfenroll_date_forms($startform,$endform);
6227: } elsif ($item eq 'section') {
1.398 raeburn 6228: my $currsec;
6229: if (ref($currsettings) eq 'HASH') {
6230: $currsec = $currsettings->{'selfenroll_section'};
6231: }
1.237 raeburn 6232: my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum);
6233: my $newsecval;
6234: if ($currsec ne 'none' && $currsec ne '') {
6235: if (!defined($sections_count{$currsec})) {
6236: $newsecval = $currsec;
6237: }
6238: }
1.400 raeburn 6239: if ($noedit{$item}) {
6240: if ($currsec ne '') {
6241: $output .= $currsec;
6242: } else {
6243: $output .= &mt('No specific section');
6244: }
6245: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6246: next;
6247: }
1.237 raeburn 6248: my $sections_select =
1.418 raeburn 6249: &Apache::lonuserutils::course_sections(\%sections_count,'st',$currsec,$disabled);
1.237 raeburn 6250: $output .= '<table class="LC_createuser">'."\n".
6251: '<tr class="LC_section_row">'."\n".
6252: '<td align="center">'.&mt('Existing sections')."\n".
6253: '<br />'.$sections_select.'</td><td align="center">'.
6254: &mt('New section').'<br />'."\n".
1.418 raeburn 6255: '<input type="text" name="newsec" size="15" value="'.$newsecval.'"'.$disabled.' />'."\n".
1.237 raeburn 6256: '<input type="hidden" name="sections" value="" />'."\n".
6257: '</td></tr></table>'."\n";
1.276 raeburn 6258: } elsif ($item eq 'approval') {
1.398 raeburn 6259: my ($currnotified,$currapproval,%appchecked);
6260: my %selfdescs = &Apache::lonuserutils::selfenroll_default_descs();
1.430 raeburn 6261: if (ref($currsettings) eq 'HASH') {
1.398 raeburn 6262: $currnotified = $currsettings->{'selfenroll_notifylist'};
6263: $currapproval = $currsettings->{'selfenroll_approval'};
6264: }
6265: if ($currapproval !~ /^[012]$/) {
6266: $currapproval = 0;
6267: }
1.400 raeburn 6268: if ($noedit{$item}) {
6269: $output .= $selfdescs{'approval'}{$currapproval}.
6270: '<br />'.&mt('(Set by Domain Coordinator)');
6271: next;
6272: }
1.398 raeburn 6273: $appchecked{$currapproval} = ' checked="checked"';
6274: for my $i (0..2) {
6275: $output .= '<label>'.
6276: '<input type="radio" name="selfenroll_approval" value="'.$i.'"'.
1.418 raeburn 6277: $appchecked{$i}.' onclick="toggleNotify();"'.$disabled.' />'.
6278: $selfdescs{'approval'}{$i}.'</label>'.(' 'x2);
1.276 raeburn 6279: }
6280: my %advhash = &Apache::lonnet::get_course_adv_roles($cid,1);
6281: my (@ccs,%notified);
1.322 raeburn 6282: my $ccrole = 'cc';
6283: if ($crstype eq 'Community') {
6284: $ccrole = 'co';
6285: }
6286: if ($advhash{$ccrole}) {
6287: @ccs = split(/,/,$advhash{$ccrole});
1.276 raeburn 6288: }
6289: if ($currnotified) {
6290: foreach my $current (split(/,/,$currnotified)) {
6291: $notified{$current} = 1;
6292: if (!grep(/^\Q$current\E$/,@ccs)) {
6293: push(@ccs,$current);
6294: }
6295: }
6296: }
6297: if (@ccs) {
1.398 raeburn 6298: my $style;
6299: unless ($currapproval) {
6300: $style = ' style="display: none;"';
6301: }
6302: $output .= '<br /><div id="notified"'.$style.'>'.
6303: &mt('Personnel to be notified when an enrollment request needs approval, or has been approved:').' '.
6304: &Apache::loncommon::start_data_table().
1.276 raeburn 6305: &Apache::loncommon::start_data_table_row();
6306: my $count = 0;
6307: my $numcols = 4;
6308: foreach my $cc (sort(@ccs)) {
6309: my $notifyon;
6310: my ($ccuname,$ccudom) = split(/:/,$cc);
6311: if ($notified{$cc}) {
6312: $notifyon = ' checked="checked" ';
6313: }
6314: if ($count && !$count%$numcols) {
6315: $output .= &Apache::loncommon::end_data_table_row().
6316: &Apache::loncommon::start_data_table_row()
6317: }
6318: $output .= '<td><span class="LC_nobreak"><label>'.
1.418 raeburn 6319: '<input type="checkbox" name="selfenroll_notify"'.$notifyon.' value="'.$cc.'"'.$disabled.' />'.
1.276 raeburn 6320: &Apache::loncommon::plainname($ccuname,$ccudom).
6321: '</label></span></td>';
1.343 raeburn 6322: $count ++;
1.276 raeburn 6323: }
6324: my $rem = $count%$numcols;
6325: if ($rem) {
6326: my $emptycols = $numcols - $rem;
6327: for (my $i=0; $i<$emptycols; $i++) {
6328: $output .= '<td> </td>';
6329: }
6330: }
6331: $output .= &Apache::loncommon::end_data_table_row().
1.398 raeburn 6332: &Apache::loncommon::end_data_table().
6333: '</div>';
1.276 raeburn 6334: }
6335: } elsif ($item eq 'limit') {
1.398 raeburn 6336: my ($crslimit,$selflimit,$nolimit,$currlim,$currcap);
6337: if (ref($currsettings) eq 'HASH') {
6338: $currlim = $currsettings->{'selfenroll_limit'};
6339: $currcap = $currsettings->{'selfenroll_cap'};
6340: }
1.400 raeburn 6341: if ($noedit{$item}) {
6342: if (($currlim eq 'allstudents') || ($currlim eq 'selfenrolled')) {
6343: if ($currlim eq 'allstudents') {
6344: $output .= &mt('Limit by total students');
6345: } elsif ($currlim eq 'selfenrolled') {
6346: $output .= &mt('Limit by total self-enrolled students');
6347: }
6348: $output .= ' '.&mt('Maximum: [_1]',$currcap).
6349: '<br />'.&mt('(Set by Domain Coordinator)');
6350: } else {
6351: $output .= &mt('No limit').'<br />'.&mt('(Set by Domain Coordinator)');
6352: }
6353: next;
6354: }
1.276 raeburn 6355: if ($currlim eq 'allstudents') {
6356: $crslimit = ' checked="checked" ';
6357: $selflimit = ' ';
6358: $nolimit = ' ';
6359: } elsif ($currlim eq 'selfenrolled') {
6360: $crslimit = ' ';
6361: $selflimit = ' checked="checked" ';
6362: $nolimit = ' ';
6363: } else {
6364: $crslimit = ' ';
6365: $selflimit = ' ';
1.398 raeburn 6366: $nolimit = ' checked="checked" ';
1.276 raeburn 6367: }
6368: $output .= '<table><tr><td><label>'.
1.418 raeburn 6369: '<input type="radio" name="selfenroll_limit" value="none"'.$nolimit.$disabled.'/>'.
1.276 raeburn 6370: &mt('No limit').'</label></td><td><label>'.
1.418 raeburn 6371: '<input type="radio" name="selfenroll_limit" value="allstudents"'.$crslimit.$disabled.'/>'.
1.276 raeburn 6372: &mt('Limit by total students').'</label></td><td><label>'.
1.418 raeburn 6373: '<input type="radio" name="selfenroll_limit" value="selfenrolled"'.$selflimit.$disabled.'/>'.
1.276 raeburn 6374: &mt('Limit by total self-enrolled students').
6375: '</td></tr><tr>'.
6376: '<td> </td><td colspan="2"><span class="LC_nobreak">'.
6377: (' 'x3).&mt('Maximum number allowed: ').
1.418 raeburn 6378: '<input type="text" name="selfenroll_cap" size = "5" value="'.$currcap.'"'.$disabled.' /></td></tr></table>';
1.237 raeburn 6379: }
6380: $output .= &Apache::lonhtmlcommon::row_closure(1);
6381: }
6382: }
1.418 raeburn 6383: $output .= &Apache::lonhtmlcommon::end_pick_box().'<br />';
6384: unless ($readonly) {
6385: $output .= '<input type="button" name="selfenrollconf" value="'
6386: .&mt('Save').'" onclick="validate_types(this.form);" />';
6387: }
6388: $output .= '<input type="hidden" name="action" value="selfenroll" />'
6389: .'<input type="hidden" name="state" value="done" />'."\n"
6390: .$additional.'</form>';
1.237 raeburn 6391: $r->print($output);
6392: return;
6393: }
6394:
1.400 raeburn 6395: sub get_noedit_fields {
6396: my ($cdom,$cnum,$crstype,$row) = @_;
6397: my %noedit;
6398: if (ref($row) eq 'ARRAY') {
6399: my %settings = &Apache::lonnet::get('environment',['internal.coursecode','internal.textbook',
6400: 'internal.selfenrollmgrdc',
6401: 'internal.selfenrollmgrcc'],$cdom,$cnum);
6402: my $type = &Apache::lonuserutils::get_extended_type($cdom,$cnum,$crstype,\%settings);
6403: my (%specific_managebydc,%specific_managebycc,%default_managebydc);
6404: map { $specific_managebydc{$_} = 1; } (split(/,/,$settings{'internal.selfenrollmgrdc'}));
6405: map { $specific_managebycc{$_} = 1; } (split(/,/,$settings{'internal.selfenrollmgrcc'}));
6406: my %domdefaults = &Apache::lonnet::get_domain_defaults($cdom);
6407: map { $default_managebydc{$_} = 1; } (split(/,/,$domdefaults{$type.'selfenrolladmdc'}));
6408:
6409: foreach my $item (@{$row}) {
6410: next if ($specific_managebycc{$item});
6411: if (($specific_managebydc{$item}) || ($default_managebydc{$item})) {
6412: $noedit{$item} = 1;
6413: }
6414: }
6415: }
6416: return %noedit;
6417: }
6418:
6419: sub visible_in_stdcat {
6420: my ($cdom,$cnum,$domconf) = @_;
6421: my ($cathash,%settable,@vismsgs,$cansetvis,$visible);
6422: unless (ref($domconf) eq 'HASH') {
6423: return ($visible,$cansetvis,\@vismsgs);
6424: }
6425: if (ref($domconf->{'coursecategories'}) eq 'HASH') {
6426: if ($domconf->{'coursecategories'}{'togglecats'} eq 'crs') {
1.256 raeburn 6427: $settable{'togglecats'} = 1;
6428: }
1.400 raeburn 6429: if ($domconf->{'coursecategories'}{'categorize'} eq 'crs') {
1.256 raeburn 6430: $settable{'categorize'} = 1;
6431: }
1.400 raeburn 6432: $cathash = $domconf->{'coursecategories'}{'cats'};
1.256 raeburn 6433: }
1.260 raeburn 6434: if ($settable{'togglecats'} && $settable{'categorize'}) {
1.256 raeburn 6435: $cansetvis = &mt('You are able to both assign a course category and choose to exclude this course from the catalog.');
6436: } elsif ($settable{'togglecats'}) {
6437: $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 6438: } elsif ($settable{'categorize'}) {
1.256 raeburn 6439: $cansetvis = &mt('You may assign a course category, but only a Domain Coordinator may choose to exclude this course from the catalog.');
6440: } else {
6441: $cansetvis = &mt('Only a Domain Coordinator may assign a course category or choose to exclude this course from the catalog.');
6442: }
6443:
6444: my %currsettings =
6445: &Apache::lonnet::get('environment',['hidefromcat','categories','internal.coursecode'],
6446: $cdom,$cnum);
1.400 raeburn 6447: $visible = 0;
1.256 raeburn 6448: if ($currsettings{'internal.coursecode'} ne '') {
1.400 raeburn 6449: if (ref($domconf->{'coursecategories'}) eq 'HASH') {
6450: $cathash = $domconf->{'coursecategories'}{'cats'};
1.256 raeburn 6451: if (ref($cathash) eq 'HASH') {
6452: if ($cathash->{'instcode::0'} eq '') {
6453: push(@vismsgs,'dc_addinst');
6454: } else {
6455: $visible = 1;
6456: }
6457: } else {
6458: $visible = 1;
6459: }
6460: } else {
6461: $visible = 1;
6462: }
6463: } else {
6464: if (ref($cathash) eq 'HASH') {
6465: if ($cathash->{'instcode::0'} ne '') {
6466: push(@vismsgs,'dc_instcode');
6467: }
6468: } else {
6469: push(@vismsgs,'dc_instcode');
6470: }
6471: }
6472: if ($currsettings{'categories'} ne '') {
6473: my $cathash;
1.400 raeburn 6474: if (ref($domconf->{'coursecategories'}) eq 'HASH') {
6475: $cathash = $domconf->{'coursecategories'}{'cats'};
1.256 raeburn 6476: if (ref($cathash) eq 'HASH') {
6477: if (keys(%{$cathash}) == 0) {
6478: push(@vismsgs,'dc_catalog');
6479: } elsif ((keys(%{$cathash}) == 1) && ($cathash->{'instcode::0'} ne '')) {
6480: push(@vismsgs,'dc_categories');
6481: } else {
6482: my @currcategories = split('&',$currsettings{'categories'});
6483: my $matched = 0;
6484: foreach my $cat (@currcategories) {
6485: if ($cathash->{$cat} ne '') {
6486: $visible = 1;
6487: $matched = 1;
6488: last;
6489: }
6490: }
6491: if (!$matched) {
1.260 raeburn 6492: if ($settable{'categorize'}) {
1.256 raeburn 6493: push(@vismsgs,'chgcat');
6494: } else {
6495: push(@vismsgs,'dc_chgcat');
6496: }
6497: }
6498: }
6499: }
6500: }
6501: } else {
6502: if (ref($cathash) eq 'HASH') {
6503: if ((keys(%{$cathash}) > 1) ||
6504: (keys(%{$cathash}) == 1) && ($cathash->{'instcode::0'} eq '')) {
1.260 raeburn 6505: if ($settable{'categorize'}) {
1.256 raeburn 6506: push(@vismsgs,'addcat');
6507: } else {
6508: push(@vismsgs,'dc_addcat');
6509: }
6510: }
6511: }
6512: }
6513: if ($currsettings{'hidefromcat'} eq 'yes') {
6514: $visible = 0;
6515: if ($settable{'togglecats'}) {
6516: unshift(@vismsgs,'unhide');
6517: } else {
6518: unshift(@vismsgs,'dc_unhide')
6519: }
6520: }
1.400 raeburn 6521: return ($visible,$cansetvis,\@vismsgs);
6522: }
6523:
6524: sub cat_visibility {
6525: my %visactions = &Apache::lonlocal::texthash(
6526: vis => 'This course/community currently appears in the Course/Community Catalog for this domain.',
6527: 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.',
6528: miss => 'This course/community does not currently appear in the Course/Community Catalog for this domain.',
6529: none => 'Display of a course catalog is disabled for this domain.',
6530: yous => 'You should remedy this if you plan to allow self-enrollment, otherwise students will have difficulty finding this course.',
6531: 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.',
6532: make => 'Make any changes to self-enrollment settings below, click "Save", then take action to include the course in the Catalog:',
6533: take => 'Take the following action to ensure the course appears in the Catalog:',
6534: dc_chgconf => 'Ask a domain coordinator to change the Catalog type for this domain.',
6535: dc_setcode => 'Ask a domain coordinator to assign a six character code to the course',
6536: dc_unhide => 'Ask a domain coordinator to change the "Exclude from course catalog" setting.',
6537: dc_addinst => 'Ask a domain coordinator to enable display the catalog of "Official courses (with institutional codes)".',
6538: dc_instcode => 'Ask a domain coordinator to assign an institutional code (if this is an official course).',
6539: dc_catalog => 'Ask a domain coordinator to enable or create at least one course category in the domain.',
6540: dc_categories => 'Ask a domain coordinator to create a hierarchy of categories and sub categories for courses in the domain.',
6541: 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',
6542: dc_addcat => 'Ask a domain coordinator to assign a category to the course.',
6543: );
6544: $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>"');
6545: $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>"');
6546: $visactions{'addcat'} = &mt('Use [_1]Categorize course[_2] to assign a category to the course.','"<a href="/adm/courseprefs?phase=display&actions=courseinfo">','</a>"');
6547: return \%visactions;
1.256 raeburn 6548: }
6549:
1.241 raeburn 6550: sub new_selfenroll_dom_row {
6551: my ($newdom,$num) = @_;
6552: my $domdesc = &Apache::lonnet::domain($newdom);
6553: my $output;
6554: if ($domdesc ne '') {
6555: $output .= &Apache::loncommon::start_data_table_row()
6556: .'<td valign="top"><span class="LC_nobreak">'.&mt('Domain:').' <b>'.$domdesc
6557: .' ('.$newdom.')</b><input type="hidden" name="selfenroll_dom_'.$num
1.249 raeburn 6558: .'" value="'.$newdom.'" /></span><br />'
6559: .'<span class="LC_nobreak"><label><input type="checkbox" '
6560: .'name="selfenroll_activate" value="'.$num.'" '
6561: .'onchange="javascript:update_types('
6562: ."'selfenroll_activate','$num'".');" />'
6563: .&mt('Activate').'</label></span></td>';
1.241 raeburn 6564: my @currinsttypes;
6565: $output .= '<td>'.&mt('User types:').'<br />'
6566: .&selfenroll_inst_types($num,$newdom,\@currinsttypes).'</td>'
6567: .&Apache::loncommon::end_data_table_row();
6568: }
6569: return $output;
6570: }
6571:
6572: sub selfenroll_inst_types {
1.418 raeburn 6573: my ($num,$currdom,$currinsttypes,$readonly) = @_;
1.241 raeburn 6574: my $output;
6575: my $numinrow = 4;
6576: my $count = 0;
6577: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($currdom);
1.247 raeburn 6578: my $othervalue = 'any';
1.418 raeburn 6579: my $disabled;
6580: if ($readonly) {
6581: $disabled = ' disabled="disabled"';
6582: }
1.241 raeburn 6583: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
1.251 raeburn 6584: if (keys(%{$usertypes}) > 0) {
1.247 raeburn 6585: $othervalue = 'other';
6586: }
1.241 raeburn 6587: $output .= '<table><tr>';
6588: foreach my $type (@{$types}) {
6589: if (($count > 0) && ($count%$numinrow == 0)) {
6590: $output .= '</tr><tr>';
6591: }
6592: if (defined($usertypes->{$type})) {
1.257 raeburn 6593: my $esc_type = &escape($type);
1.241 raeburn 6594: $output .= '<td><span class="LC_nobreak"><label><input type = "checkbox" value="'.
1.257 raeburn 6595: $esc_type.'" ';
1.241 raeburn 6596: if (ref($currinsttypes) eq 'ARRAY') {
6597: if (@{$currinsttypes} > 0) {
1.249 raeburn 6598: if (grep(/^any$/,@{$currinsttypes})) {
6599: $output .= 'checked="checked"';
1.257 raeburn 6600: } elsif (grep(/^\Q$esc_type\E$/,@{$currinsttypes})) {
1.241 raeburn 6601: $output .= 'checked="checked"';
6602: }
1.249 raeburn 6603: } else {
6604: $output .= 'checked="checked"';
1.241 raeburn 6605: }
6606: }
1.418 raeburn 6607: $output .= ' name="selfenroll_types_'.$num.'"'.$disabled.' />'.$usertypes->{$type}.'</label></span></td>';
1.241 raeburn 6608: }
6609: $count ++;
6610: }
6611: if (($count > 0) && ($count%$numinrow == 0)) {
6612: $output .= '</tr><tr>';
6613: }
1.249 raeburn 6614: $output .= '<td><span class="LC_nobreak"><label><input type = "checkbox" value="'.$othervalue.'"';
1.241 raeburn 6615: if (ref($currinsttypes) eq 'ARRAY') {
6616: if (@{$currinsttypes} > 0) {
1.249 raeburn 6617: if (grep(/^any$/,@{$currinsttypes})) {
6618: $output .= ' checked="checked"';
6619: } elsif ($othervalue eq 'other') {
6620: if (grep(/^\Q$othervalue\E$/,@{$currinsttypes})) {
6621: $output .= ' checked="checked"';
6622: }
1.241 raeburn 6623: }
1.249 raeburn 6624: } else {
6625: $output .= ' checked="checked"';
1.241 raeburn 6626: }
1.249 raeburn 6627: } else {
6628: $output .= ' checked="checked"';
1.241 raeburn 6629: }
1.418 raeburn 6630: $output .= ' name="selfenroll_types_'.$num.'"'.$disabled.' />'.$othertitle.'</label></span></td></tr></table>';
1.241 raeburn 6631: }
6632: return $output;
6633: }
6634:
1.237 raeburn 6635: sub selfenroll_date_forms {
6636: my ($startform,$endform) = @_;
6637: my $output .= &Apache::lonhtmlcommon::start_pick_box()."\n".
1.244 bisitz 6638: &Apache::lonhtmlcommon::row_title(&mt('Start date'),
1.237 raeburn 6639: 'LC_oddrow_value')."\n".
6640: $startform."\n".
6641: &Apache::lonhtmlcommon::row_closure(1).
1.244 bisitz 6642: &Apache::lonhtmlcommon::row_title(&mt('End date'),
1.237 raeburn 6643: 'LC_oddrow_value')."\n".
6644: $endform."\n".
6645: &Apache::lonhtmlcommon::row_closure(1).
6646: &Apache::lonhtmlcommon::end_pick_box();
6647: return $output;
6648: }
6649:
1.239 raeburn 6650: sub print_userchangelogs_display {
1.415 raeburn 6651: my ($r,$context,$permission,$brcrum) = @_;
1.363 raeburn 6652: my $formname = 'rolelog';
1.418 raeburn 6653: my ($username,$domain,$crstype,$viewablesec,%roleslog);
1.363 raeburn 6654: if ($context eq 'domain') {
6655: $domain = $env{'request.role.domain'};
6656: %roleslog=&Apache::lonnet::dump_dom('nohist_rolelog',$domain);
6657: } else {
6658: if ($context eq 'course') {
6659: $domain = $env{'course.'.$env{'request.course.id'}.'.domain'};
6660: $username = $env{'course.'.$env{'request.course.id'}.'.num'};
6661: $crstype = &Apache::loncommon::course_type();
1.418 raeburn 6662: $viewablesec = &Apache::lonuserutils::viewable_section($permission);
1.363 raeburn 6663: my %saveable_parameters = ('show' => 'scalar',);
6664: &Apache::loncommon::store_course_settings('roles_log',
6665: \%saveable_parameters);
6666: &Apache::loncommon::restore_course_settings('roles_log',
6667: \%saveable_parameters);
6668: } elsif ($context eq 'author') {
6669: $domain = $env{'user.domain'};
6670: if ($env{'request.role'} =~ m{^au\./\Q$domain\E/$}) {
6671: $username = $env{'user.name'};
6672: } else {
6673: undef($domain);
6674: }
6675: }
6676: if ($domain ne '' && $username ne '') {
6677: %roleslog=&Apache::lonnet::dump('nohist_rolelog',$domain,$username);
6678: }
6679: }
1.239 raeburn 6680: if ((keys(%roleslog))[0]=~/^error\:/) { undef(%roleslog); }
6681:
1.415 raeburn 6682: my $helpitem;
6683: if ($context eq 'course') {
6684: $helpitem = 'Course_User_Logs';
1.439 raeburn 6685: } elsif ($context eq 'domain') {
6686: $helpitem = 'Domain_Role_Logs';
6687: } elsif ($context eq 'author') {
6688: $helpitem = 'Author_User_Logs';
1.415 raeburn 6689: }
6690: push (@{$brcrum},
6691: {href => '/adm/createuser?action=changelogs',
6692: text => 'User Management Logs',
6693: help => $helpitem});
6694: my $bread_crumbs_component = 'User Changes';
6695: my $args = { bread_crumbs => $brcrum,
6696: bread_crumbs_component => $bread_crumbs_component};
6697:
6698: # Create navigation javascript
6699: my $jsnav = &userlogdisplay_js($formname);
6700:
6701: my $jscript = (<<ENDSCRIPT);
6702: <script type="text/javascript">
6703: // <![CDATA[
6704: $jsnav
6705: // ]]>
6706: </script>
6707: ENDSCRIPT
6708:
6709: # print page header
6710: $r->print(&header($jscript,$args));
6711:
1.239 raeburn 6712: # set defaults
6713: my $now = time();
6714: my $defstart = $now - (7*24*3600); #7 days ago
6715: my %defaults = (
6716: page => '1',
6717: show => '10',
6718: role => 'any',
6719: chgcontext => 'any',
6720: rolelog_start_date => $defstart,
6721: rolelog_end_date => $now,
6722: );
6723: my $more_records = 0;
6724:
6725: # set current
6726: my %curr;
6727: foreach my $item ('show','page','role','chgcontext') {
6728: $curr{$item} = $env{'form.'.$item};
6729: }
6730: my ($startdate,$enddate) =
6731: &Apache::lonuserutils::get_dates_from_form('rolelog_start_date','rolelog_end_date');
6732: $curr{'rolelog_start_date'} = $startdate;
6733: $curr{'rolelog_end_date'} = $enddate;
6734: foreach my $key (keys(%defaults)) {
6735: if ($curr{$key} eq '') {
6736: $curr{$key} = $defaults{$key};
6737: }
6738: }
1.248 raeburn 6739: my (%whodunit,%changed,$version);
6740: ($version) = ($r->dir_config('lonVersion') =~ /^([\d\.]+)\-/);
1.239 raeburn 6741: my ($minshown,$maxshown);
1.255 raeburn 6742: $minshown = 1;
1.239 raeburn 6743: my $count = 0;
1.415 raeburn 6744: if ($curr{'show'} =~ /\D/) {
6745: $curr{'page'} = 1;
6746: } else {
1.239 raeburn 6747: $maxshown = $curr{'page'} * $curr{'show'};
6748: if ($curr{'page'} > 1) {
6749: $minshown = 1 + ($curr{'page'} - 1) * $curr{'show'};
6750: }
6751: }
1.301 bisitz 6752:
1.327 raeburn 6753: # Form Header
6754: $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">'.
1.363 raeburn 6755: &role_display_filter($context,$formname,$domain,$username,\%curr,
6756: $version,$crstype));
1.327 raeburn 6757:
6758: my $showntableheader = 0;
6759:
6760: # Table Header
6761: my $tableheader =
6762: &Apache::loncommon::start_data_table_header_row()
6763: .'<th> </th>'
6764: .'<th>'.&mt('When').'</th>'
6765: .'<th>'.&mt('Who made the change').'</th>'
6766: .'<th>'.&mt('Changed User').'</th>'
1.363 raeburn 6767: .'<th>'.&mt('Role').'</th>';
6768:
6769: if ($context eq 'course') {
6770: $tableheader .= '<th>'.&mt('Section').'</th>';
6771: }
6772: $tableheader .=
6773: '<th>'.&mt('Context').'</th>'
1.327 raeburn 6774: .'<th>'.&mt('Start').'</th>'
6775: .'<th>'.&mt('End').'</th>'
6776: .&Apache::loncommon::end_data_table_header_row();
6777:
6778: # Display user change log data
1.239 raeburn 6779: foreach my $id (sort { $roleslog{$b}{'exe_time'}<=>$roleslog{$a}{'exe_time'} } (keys(%roleslog))) {
6780: next if (($roleslog{$id}{'exe_time'} < $curr{'rolelog_start_date'}) ||
6781: ($roleslog{$id}{'exe_time'} > $curr{'rolelog_end_date'}));
1.415 raeburn 6782: if ($curr{'show'} !~ /\D/) {
1.239 raeburn 6783: if ($count >= $curr{'page'} * $curr{'show'}) {
6784: $more_records = 1;
6785: last;
6786: }
6787: }
6788: if ($curr{'role'} ne 'any') {
6789: next if ($roleslog{$id}{'logentry'}{'role'} ne $curr{'role'});
6790: }
6791: if ($curr{'chgcontext'} ne 'any') {
6792: if ($curr{'chgcontext'} eq 'selfenroll') {
6793: next if (!$roleslog{$id}{'logentry'}{'selfenroll'});
6794: } else {
6795: next if ($roleslog{$id}{'logentry'}{'context'} ne $curr{'chgcontext'});
6796: }
6797: }
1.418 raeburn 6798: if (($context eq 'course') && ($viewablesec ne '')) {
1.430 raeburn 6799: next if ($roleslog{$id}{'logentry'}{'section'} ne $viewablesec);
1.418 raeburn 6800: }
1.239 raeburn 6801: $count ++;
6802: next if ($count < $minshown);
1.327 raeburn 6803: unless ($showntableheader) {
1.415 raeburn 6804: $r->print(&Apache::loncommon::start_data_table()
1.327 raeburn 6805: .$tableheader);
6806: $r->rflush();
6807: $showntableheader = 1;
6808: }
1.239 raeburn 6809: if ($whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}} eq '') {
6810: $whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}} =
6811: &Apache::loncommon::plainname($roleslog{$id}{'exe_uname'},$roleslog{$id}{'exe_udom'});
6812: }
6813: if ($changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}} eq '') {
6814: $changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}} =
6815: &Apache::loncommon::plainname($roleslog{$id}{'uname'},$roleslog{$id}{'udom'});
6816: }
6817: my $sec = $roleslog{$id}{'logentry'}{'section'};
6818: if ($sec eq '') {
6819: $sec = &mt('None');
6820: }
6821: my ($rolestart,$roleend);
6822: if ($roleslog{$id}{'delflag'}) {
6823: $rolestart = &mt('deleted');
6824: $roleend = &mt('deleted');
6825: } else {
6826: $rolestart = $roleslog{$id}{'logentry'}{'start'};
6827: $roleend = $roleslog{$id}{'logentry'}{'end'};
6828: if ($rolestart eq '' || $rolestart == 0) {
6829: $rolestart = &mt('No start date');
6830: } else {
6831: $rolestart = &Apache::lonlocal::locallocaltime($rolestart);
6832: }
6833: if ($roleend eq '' || $roleend == 0) {
6834: $roleend = &mt('No end date');
6835: } else {
6836: $roleend = &Apache::lonlocal::locallocaltime($roleend);
6837: }
6838: }
6839: my $chgcontext = $roleslog{$id}{'logentry'}{'context'};
6840: if ($roleslog{$id}{'logentry'}{'selfenroll'}) {
6841: $chgcontext = 'selfenroll';
6842: }
1.363 raeburn 6843: my %lt = &rolechg_contexts($context,$crstype);
1.239 raeburn 6844: if ($chgcontext ne '' && $lt{$chgcontext} ne '') {
6845: $chgcontext = $lt{$chgcontext};
6846: }
1.327 raeburn 6847: $r->print(
1.301 bisitz 6848: &Apache::loncommon::start_data_table_row()
6849: .'<td>'.$count.'</td>'
6850: .'<td>'.&Apache::lonlocal::locallocaltime($roleslog{$id}{'exe_time'}).'</td>'
6851: .'<td>'.$whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}}.'</td>'
6852: .'<td>'.$changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}}.'</td>'
1.363 raeburn 6853: .'<td>'.&Apache::lonnet::plaintext($roleslog{$id}{'logentry'}{'role'},$crstype).'</td>');
6854: if ($context eq 'course') {
6855: $r->print('<td>'.$sec.'</td>');
6856: }
6857: $r->print(
6858: '<td>'.$chgcontext.'</td>'
1.301 bisitz 6859: .'<td>'.$rolestart.'</td>'
6860: .'<td>'.$roleend.'</td>'
1.327 raeburn 6861: .&Apache::loncommon::end_data_table_row()."\n");
1.301 bisitz 6862: }
6863:
1.327 raeburn 6864: if ($showntableheader) { # Table footer, if content displayed above
1.415 raeburn 6865: $r->print(&Apache::loncommon::end_data_table().
6866: &userlogdisplay_navlinks(\%curr,$more_records));
1.327 raeburn 6867: } else { # No content displayed above
1.301 bisitz 6868: $r->print('<p class="LC_info">'
6869: .&mt('There are no records to display.')
6870: .'</p>'
6871: );
1.239 raeburn 6872: }
1.301 bisitz 6873:
1.327 raeburn 6874: # Form Footer
6875: $r->print(
6876: '<input type="hidden" name="page" value="'.$curr{'page'}.'" />'
6877: .'<input type="hidden" name="action" value="changelogs" />'
6878: .'</form>');
6879: return;
6880: }
1.301 bisitz 6881:
1.416 raeburn 6882: sub print_useraccesslogs_display {
6883: my ($r,$uname,$udom,$permission,$brcrum) = @_;
6884: my $formname = 'accesslog';
6885: my $form = 'document.accesslog';
6886:
6887: # set breadcrumbs
1.422 raeburn 6888: my %breadcrumb_text = &singleuser_breadcrumb('','domain',$udom);
1.431 raeburn 6889: my $prevphasestr;
6890: if ($env{'form.popup'}) {
6891: $brcrum = [];
6892: } else {
6893: push (@{$brcrum},
6894: {href => "javascript:backPage($form)",
6895: text => $breadcrumb_text{'search'}});
6896: my @prevphases;
6897: if ($env{'form.prevphases'}) {
6898: @prevphases = split(/,/,$env{'form.prevphases'});
6899: $prevphasestr = $env{'form.prevphases'};
6900: }
6901: if (($env{'form.phase'} eq 'userpicked') || (grep(/^userpicked$/,@prevphases))) {
6902: push(@{$brcrum},
6903: {href => "javascript:backPage($form,'get_user_info','select')",
6904: text => $breadcrumb_text{'userpicked'}});
6905: if ($env{'form.phase'} eq 'userpicked') {
6906: $prevphasestr = 'userpicked';
6907: }
1.416 raeburn 6908: }
6909: }
6910: push(@{$brcrum},
6911: {href => '/adm/createuser?action=accesslogs',
6912: text => 'User access logs',
1.424 raeburn 6913: help => 'Domain_User_Access_Logs'});
1.416 raeburn 6914: my $bread_crumbs_component = 'User Access Logs';
6915: my $args = { bread_crumbs => $brcrum,
6916: bread_crumbs_component => 'User Management'};
1.423 raeburn 6917: if ($env{'form.popup'}) {
6918: $args->{'no_nav_bar'} = 1;
1.431 raeburn 6919: $args->{'bread_crumbs_nomenu'} = 1;
1.423 raeburn 6920: }
1.416 raeburn 6921:
1.417 raeburn 6922: # set javascript
1.416 raeburn 6923: my ($jsback,$elements) = &crumb_utilities();
6924: my $jsnav = &userlogdisplay_js($formname);
6925:
6926: my $jscript = (<<ENDSCRIPT);
6927: <script type="text/javascript">
6928: // <![CDATA[
6929:
6930: $jsback
6931: $jsnav
6932:
6933: // ]]>
6934: </script>
6935:
6936: ENDSCRIPT
6937:
1.417 raeburn 6938: # print page header
1.416 raeburn 6939: $r->print(&header($jscript,$args));
6940:
6941: # early out unless log data can be displayed.
6942: unless ($permission->{'activity'}) {
6943: $r->print('<p class="LC_warning">'
6944: .&mt('You do not have rights to display user access logs.')
1.431 raeburn 6945: .'</p>');
6946: if ($env{'form.popup'}) {
6947: $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a></p>');
6948: } else {
6949: $r->print(&earlyout_accesslog_form($formname,$prevphasestr,$udom));
6950: }
1.416 raeburn 6951: return;
6952: }
6953:
6954: unless ($udom eq $env{'request.role.domain'}) {
6955: $r->print('<p class="LC_warning">'
6956: .&mt("User's domain must match role's domain")
6957: .'</p>'
6958: .&earlyout_accesslog_form($formname,$prevphasestr,$udom));
1.417 raeburn 6959: return;
1.416 raeburn 6960: }
6961:
6962: if (($uname eq '') || ($udom eq '')) {
6963: $r->print('<p class="LC_warning">'
6964: .&mt('Invalid username or domain')
6965: .'</p>'
6966: .&earlyout_accesslog_form($formname,$prevphasestr,$udom));
6967: return;
6968: }
6969:
1.437 raeburn 6970: if (&Apache::lonnet::privileged($uname,$udom,
6971: [$env{'request.role.domain'}],['dc','su'])) {
6972: unless (&Apache::lonnet::privileged($env{'user.name'},$env{'user.domain'},
6973: [$env{'request.role.domain'}],['dc','su'])) {
6974: $r->print('<p class="LC_warning">'
6975: .&mt('You need to be a privileged user to display user access logs for [_1]',
6976: &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),
6977: $uname,$udom))
6978: .'</p>');
6979: if ($env{'form.popup'}) {
6980: $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a></p>');
6981: } else {
6982: $r->print(&earlyout_accesslog_form($formname,$prevphasestr,$udom));
6983: }
6984: return;
6985: }
6986: }
6987:
1.416 raeburn 6988: # set defaults
6989: my $now = time();
6990: my $defstart = $now - (7*24*3600);
6991: my %defaults = (
6992: page => '1',
6993: show => '10',
6994: activity => 'any',
6995: accesslog_start_date => $defstart,
6996: accesslog_end_date => $now,
6997: );
6998: my $more_records = 0;
6999:
7000: # set current
7001: my %curr;
7002: foreach my $item ('show','page','activity') {
7003: $curr{$item} = $env{'form.'.$item};
7004: }
7005: my ($startdate,$enddate) =
7006: &Apache::lonuserutils::get_dates_from_form('accesslog_start_date','accesslog_end_date');
7007: $curr{'accesslog_start_date'} = $startdate;
7008: $curr{'accesslog_end_date'} = $enddate;
7009: foreach my $key (keys(%defaults)) {
7010: if ($curr{$key} eq '') {
7011: $curr{$key} = $defaults{$key};
7012: }
7013: }
7014: my ($minshown,$maxshown);
7015: $minshown = 1;
7016: my $count = 0;
7017: if ($curr{'show'} =~ /\D/) {
7018: $curr{'page'} = 1;
7019: } else {
7020: $maxshown = $curr{'page'} * $curr{'show'};
7021: if ($curr{'page'} > 1) {
7022: $minshown = 1 + ($curr{'page'} - 1) * $curr{'show'};
7023: }
7024: }
7025:
7026: # form header
7027: $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">'.
7028: &activity_display_filter($formname,\%curr));
7029:
7030: my $showntableheader = 0;
7031: my ($nav_script,$nav_links);
7032:
7033: # table header
1.431 raeburn 7034: my $tableheader = '<h3>'.
7035: &mt('User access logs for: [_1]',
7036: &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),$uname,$udom)).'</h3>'
7037: .&Apache::loncommon::start_data_table_header_row()
1.416 raeburn 7038: .'<th> </th>'
7039: .'<th>'.&mt('When').'</th>'
7040: .'<th>'.&mt('HostID').'</th>'
7041: .'<th>'.&mt('Event').'</th>'
7042: .'<th>'.&mt('Other data').'</th>'
7043: .&Apache::loncommon::end_data_table_header_row();
7044:
7045: my %filters=(
7046: start => $curr{'accesslog_start_date'},
7047: end => $curr{'accesslog_end_date'},
7048: action => $curr{'activity'},
7049: );
7050:
7051: my $reply = &Apache::lonnet::userlog_query($uname,$udom,%filters);
7052: unless ( ($reply =~/^timeout/) || ($reply =~/^error/) ) {
7053: my (%courses,%missing);
7054: my @results = split(/\&/,$reply);
7055: foreach my $item (reverse(@results)) {
7056: my ($timestamp,$host,$event) = split(/:/,$item);
7057: next unless ($event =~ /^(Log|Role)/);
7058: if ($curr{'show'} !~ /\D/) {
7059: if ($count >= $curr{'page'} * $curr{'show'}) {
7060: $more_records = 1;
7061: last;
7062: }
7063: }
7064: $count ++;
7065: next if ($count < $minshown);
7066: unless ($showntableheader) {
7067: $r->print($nav_script
7068: .&Apache::loncommon::start_data_table()
7069: .$tableheader);
7070: $r->rflush();
7071: $showntableheader = 1;
7072: }
1.418 raeburn 7073: my ($shown,$extra);
1.437 raeburn 7074: my ($event,$data) = split(/\s+/,&unescape($event),2);
1.416 raeburn 7075: if ($event eq 'Role') {
7076: my ($rolecode,$extent) = split(/\./,$data,2);
7077: next if ($extent eq '');
7078: my ($crstype,$desc,$info);
1.418 raeburn 7079: if ($extent =~ m{^/($match_domain)/($match_courseid)(?:/(\w+)|)$}) {
7080: my ($cdom,$cnum,$sec) = ($1,$2,$3);
1.416 raeburn 7081: my $cid = $cdom.'_'.$cnum;
7082: if (exists($courses{$cid})) {
7083: $crstype = $courses{$cid}{'type'};
7084: $desc = $courses{$cid}{'description'};
7085: } elsif ($missing{$cid}) {
7086: $crstype = 'Course';
7087: $desc = 'Course/Community';
7088: } else {
7089: my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',$cnum,undef,undef,'.');
7090: if (ref($crsinfo{$cdom.'_'.$cnum}) eq 'HASH') {
7091: $courses{$cid} = $crsinfo{$cid};
7092: $crstype = $crsinfo{$cid}{'type'};
7093: $desc = $crsinfo{$cid}{'description'};
7094: } else {
7095: $missing{$cid} = 1;
7096: }
7097: }
7098: $extra = &mt($crstype).': <a href="/public/'.$cdom.'/'.$cnum.'/syllabus">'.$desc.'</a>';
1.418 raeburn 7099: if ($sec ne '') {
7100: $extra .= ' ('.&mt('Section: [_1]',$sec).')';
7101: }
1.416 raeburn 7102: } elsif ($extent =~ m{^/($match_domain)/($match_username|$)}) {
7103: my ($dom,$name) = ($1,$2);
7104: if ($rolecode eq 'au') {
7105: $extra = '';
7106: } elsif ($rolecode =~ /^(ca|aa)$/) {
1.417 raeburn 7107: $extra = &mt('Authoring Space: [_1]',$name.':'.$dom);
1.416 raeburn 7108: } elsif ($rolecode =~ /^(li|dg|dh|dc|sc)$/) {
7109: $extra = &mt('Domain: [_1]',$dom);
7110: }
7111: }
7112: my $rolename;
7113: if ($rolecode =~ m{^cr/($match_domain)/($match_username)/(\w+)}) {
7114: my $role = $3;
1.417 raeburn 7115: my $owner = "($2:$1)";
1.416 raeburn 7116: if ($2 eq $1.'-domainconfig') {
7117: $owner = '(ad hoc)';
1.417 raeburn 7118: }
1.416 raeburn 7119: $rolename = &mt('Custom role: [_1]',$role.' '.$owner);
7120: } else {
7121: $rolename = &Apache::lonnet::plaintext($rolecode,$crstype);
7122: }
7123: $shown = &mt('Role selection: [_1]',$rolename);
7124: } else {
7125: $shown = &mt($event);
1.437 raeburn 7126: if ($data =~ /^webdav/) {
7127: my ($path,$clientip) = split(/\s+/,$data,2);
7128: $path =~ s/^webdav//;
7129: if ($clientip ne '') {
7130: $extra = &mt('Client IP address: [_1]',$clientip);
7131: }
7132: if ($path ne '') {
7133: $shown .= ' '.&mt('(WebDAV access to [_1])',$path);
7134: }
7135: } elsif ($data ne '') {
7136: $extra = &mt('Client IP address: [_1]',$data);
1.416 raeburn 7137: }
7138: }
7139: $r->print(
7140: &Apache::loncommon::start_data_table_row()
7141: .'<td>'.$count.'</td>'
7142: .'<td>'.&Apache::lonlocal::locallocaltime($timestamp).'</td>'
7143: .'<td>'.$host.'</td>'
7144: .'<td>'.$shown.'</td>'
7145: .'<td>'.$extra.'</td>'
7146: .&Apache::loncommon::end_data_table_row()."\n");
7147: }
7148: }
7149:
7150: if ($showntableheader) { # Table footer, if content displayed above
7151: $r->print(&Apache::loncommon::end_data_table().
7152: &userlogdisplay_navlinks(\%curr,$more_records));
7153: } else { # No content displayed above
7154: $r->print('<p class="LC_info">'
7155: .&mt('There are no records to display.')
7156: .'</p>');
7157: }
7158:
1.423 raeburn 7159: if ($env{'form.popup'} == 1) {
7160: $r->print('<input type="hidden" name="popup" value="1" />'."\n");
7161: }
7162:
1.416 raeburn 7163: # Form Footer
7164: $r->print(
7165: '<input type="hidden" name="currstate" value="" />'
7166: .'<input type="hidden" name="accessuname" value="'.$uname.'" />'
7167: .'<input type="hidden" name="accessudom" value="'.$udom.'" />'
7168: .'<input type="hidden" name="page" value="'.$curr{'page'}.'" />'
7169: .'<input type="hidden" name="prevphases" value="'.$prevphasestr.'" />'
7170: .'<input type="hidden" name="phase" value="activity" />'
7171: .'<input type="hidden" name="action" value="accesslogs" />'
7172: .'<input type="hidden" name="srchdomain" value="'.$udom.'" />'
7173: .'<input type="hidden" name="srchby" value="'.$env{'form.srchby'}.'" />'
7174: .'<input type="hidden" name="srchtype" value="'.$env{'form.srchtype'}.'" />'
7175: .'<input type="hidden" name="srchterm" value="'.&HTML::Entities::encode($env{'form.srchterm'},'<>"&').'" />'
7176: .'<input type="hidden" name="srchin" value="'.$env{'form.srchin'}.'" />'
7177: .'</form>');
7178: return;
7179: }
7180:
7181: sub earlyout_accesslog_form {
7182: my ($formname,$prevphasestr,$udom) = @_;
7183: my $srchterm = &HTML::Entities::encode($env{'form.srchterm'},'<>"&');
7184: return <<"END";
7185: <form action="/adm/createuser" method="post" name="$formname">
7186: <input type="hidden" name="currstate" value="" />
7187: <input type="hidden" name="prevphases" value="$prevphasestr" />
7188: <input type="hidden" name="phase" value="activity" />
7189: <input type="hidden" name="action" value="accesslogs" />
7190: <input type="hidden" name="srchdomain" value="$udom" />
7191: <input type="hidden" name="srchby" value="$env{'form.srchby'}" />
7192: <input type="hidden" name="srchtype" value="$env{'form.srchtype'}" />
7193: <input type="hidden" name="srchterm" value="$srchterm" />
7194: <input type="hidden" name="srchin" value="$env{'form.srchin'}" />
7195: </form>
7196: END
7197: }
7198:
7199: sub activity_display_filter {
7200: my ($formname,$curr) = @_;
7201: my $nolink = 1;
7202: my $output = '<table><tr><td valign="top">'.
7203: '<span class="LC_nobreak"><b>'.&mt('Actions/page:').'</b></span><br />'.
7204: &Apache::lonmeta::selectbox('show',$curr->{'show'},undef,
7205: (&mt('all'),5,10,20,50,100,1000,10000)).
7206: '</td><td> </td>';
7207: my $startform =
7208: &Apache::lonhtmlcommon::date_setter($formname,'accesslog_start_date',
7209: $curr->{'accesslog_start_date'},undef,
7210: undef,undef,undef,undef,undef,undef,$nolink);
7211: my $endform =
7212: &Apache::lonhtmlcommon::date_setter($formname,'accesslog_end_date',
7213: $curr->{'accesslog_end_date'},undef,
7214: undef,undef,undef,undef,undef,undef,$nolink);
7215: my %lt = &Apache::lonlocal::texthash (
7216: activity => 'Activity',
7217: Role => 'Role selection',
7218: log => 'Log-in or Logout',
7219: );
7220: $output .= '<td valign="top"><b>'.&mt('Window during which actions occurred:').'</b><br />'.
7221: '<table><tr><td>'.&mt('After:').
7222: '</td><td>'.$startform.'</td></tr>'.
7223: '<tr><td>'.&mt('Before:').'</td>'.
7224: '<td>'.$endform.'</td></tr></table>'.
7225: '</td>'.
7226: '<td> </td>'.
7227: '<td valign="top"><b>'.&mt('Activities').'</b><br />'.
7228: '<select name="activity"><option value="any"';
7229: if ($curr->{'activity'} eq 'any') {
7230: $output .= ' selected="selected"';
7231: }
7232: $output .= '>'.&mt('Any').'</option>'."\n";
7233: foreach my $activity ('Role','log') {
7234: my $selstr = '';
7235: if ($activity eq $curr->{'activity'}) {
7236: $selstr = ' selected="selected"';
7237: }
7238: $output .= '<option value="'.$activity.'"'.$selstr.'>'.$lt{$activity}.'</option>';
7239: }
7240: $output .= '</select></td>'.
7241: '</tr></table>';
7242: # Update Display button
7243: $output .= '<p>'
7244: .'<input type="submit" value="'.&mt('Update Display').'" />'
1.431 raeburn 7245: .'</p><hr />';
1.416 raeburn 7246: return $output;
7247: }
7248:
1.415 raeburn 7249: sub userlogdisplay_js {
7250: my ($formname) = @_;
7251: return <<"ENDSCRIPT";
7252:
1.239 raeburn 7253: function chgPage(caller) {
7254: if (caller == 'previous') {
7255: document.$formname.page.value --;
7256: }
7257: if (caller == 'next') {
7258: document.$formname.page.value ++;
7259: }
1.327 raeburn 7260: document.$formname.submit();
1.239 raeburn 7261: return;
7262: }
7263: ENDSCRIPT
1.415 raeburn 7264: }
7265:
7266: sub userlogdisplay_navlinks {
7267: my ($curr,$more_records) = @_;
7268: return unless(ref($curr) eq 'HASH');
7269: # Navigation Buttons
7270: my $nav_links = '<p>';
7271: if (($curr->{'page'} > 1) || ($more_records)) {
7272: if (($curr->{'page'} > 1) && ($curr->{'show'} !~ /\D/)) {
7273: $nav_links .= '<input type="button"'
7274: .' onclick="javascript:chgPage('."'previous'".');"'
7275: .' value="'.&mt('Previous [_1] changes',$curr->{'show'})
7276: .'" /> ';
7277: }
7278: if ($more_records) {
7279: $nav_links .= '<input type="button"'
7280: .' onclick="javascript:chgPage('."'next'".');"'
7281: .' value="'.&mt('Next [_1] changes',$curr->{'show'})
7282: .'" />';
1.301 bisitz 7283: }
7284: }
1.415 raeburn 7285: $nav_links .= '</p>';
7286: return $nav_links;
1.239 raeburn 7287: }
7288:
7289: sub role_display_filter {
1.363 raeburn 7290: my ($context,$formname,$cdom,$cnum,$curr,$version,$crstype) = @_;
7291: my $lctype;
7292: if ($context eq 'course') {
7293: $lctype = lc($crstype);
7294: }
1.239 raeburn 7295: my $nolink = 1;
7296: my $output = '<table><tr><td valign="top">'.
1.301 bisitz 7297: '<span class="LC_nobreak"><b>'.&mt('Changes/page:').'</b></span><br />'.
1.239 raeburn 7298: &Apache::lonmeta::selectbox('show',$curr->{'show'},undef,
7299: (&mt('all'),5,10,20,50,100,1000,10000)).
7300: '</td><td> </td>';
7301: my $startform =
7302: &Apache::lonhtmlcommon::date_setter($formname,'rolelog_start_date',
7303: $curr->{'rolelog_start_date'},undef,
7304: undef,undef,undef,undef,undef,undef,$nolink);
7305: my $endform =
7306: &Apache::lonhtmlcommon::date_setter($formname,'rolelog_end_date',
7307: $curr->{'rolelog_end_date'},undef,
7308: undef,undef,undef,undef,undef,undef,$nolink);
1.363 raeburn 7309: my %lt = &rolechg_contexts($context,$crstype);
1.301 bisitz 7310: $output .= '<td valign="top"><b>'.&mt('Window during which changes occurred:').'</b><br />'.
7311: '<table><tr><td>'.&mt('After:').
7312: '</td><td>'.$startform.'</td></tr>'.
7313: '<tr><td>'.&mt('Before:').'</td>'.
7314: '<td>'.$endform.'</td></tr></table>'.
7315: '</td>'.
7316: '<td> </td>'.
1.239 raeburn 7317: '<td valign="top"><b>'.&mt('Role:').'</b><br />'.
7318: '<select name="role"><option value="any"';
7319: if ($curr->{'role'} eq 'any') {
7320: $output .= ' selected="selected"';
7321: }
7322: $output .= '>'.&mt('Any').'</option>'."\n";
1.363 raeburn 7323: my @roles = &Apache::lonuserutils::roles_by_context($context,1,$crstype);
1.239 raeburn 7324: foreach my $role (@roles) {
7325: my $plrole;
7326: if ($role eq 'cr') {
7327: $plrole = &mt('Custom Role');
7328: } else {
1.318 raeburn 7329: $plrole=&Apache::lonnet::plaintext($role,$crstype);
1.239 raeburn 7330: }
7331: my $selstr = '';
7332: if ($role eq $curr->{'role'}) {
7333: $selstr = ' selected="selected"';
7334: }
7335: $output .= ' <option value="'.$role.'"'.$selstr.'>'.$plrole.'</option>';
7336: }
1.301 bisitz 7337: $output .= '</select></td>'.
7338: '<td> </td>'.
7339: '<td valign="top"><b>'.
1.239 raeburn 7340: &mt('Context:').'</b><br /><select name="chgcontext">';
1.363 raeburn 7341: my @posscontexts;
7342: if ($context eq 'course') {
1.376 raeburn 7343: @posscontexts = ('any','automated','updatenow','createcourse','course','domain','selfenroll','requestcourses');
1.363 raeburn 7344: } elsif ($context eq 'domain') {
7345: @posscontexts = ('any','domain','requestauthor','domconfig','server');
7346: } else {
7347: @posscontexts = ('any','author','domain');
7348: }
7349: foreach my $chgtype (@posscontexts) {
1.239 raeburn 7350: my $selstr = '';
7351: if ($curr->{'chgcontext'} eq $chgtype) {
1.301 bisitz 7352: $selstr = ' selected="selected"';
1.239 raeburn 7353: }
1.363 raeburn 7354: if ($context eq 'course') {
1.376 raeburn 7355: if (($chgtype eq 'automated') || ($chgtype eq 'updatenow')) {
1.363 raeburn 7356: next if (!&Apache::lonnet::auto_run($cnum,$cdom));
7357: }
1.239 raeburn 7358: }
7359: $output .= '<option value="'.$chgtype.'"'.$selstr.'>'.$lt{$chgtype}.'</option>'."\n";
1.248 raeburn 7360: }
1.303 bisitz 7361: $output .= '</select></td>'
7362: .'</tr></table>';
7363:
7364: # Update Display button
7365: $output .= '<p>'
7366: .'<input type="submit" value="'.&mt('Update Display').'" />'
7367: .'</p>';
7368:
7369: # Server version info
1.363 raeburn 7370: my $needsrev = '2.11.0';
7371: if ($context eq 'course') {
7372: $needsrev = '2.7.0';
7373: }
7374:
1.303 bisitz 7375: $output .= '<p class="LC_info">'
7376: .&mt('Only changes made from servers running LON-CAPA [_1] or later are displayed.'
1.363 raeburn 7377: ,$needsrev);
1.248 raeburn 7378: if ($version) {
1.303 bisitz 7379: $output .= ' '.&mt('This LON-CAPA server is version [_1]',$version);
7380: }
7381: $output .= '</p><hr />';
1.239 raeburn 7382: return $output;
7383: }
7384:
7385: sub rolechg_contexts {
1.363 raeburn 7386: my ($context,$crstype) = @_;
7387: my %lt;
7388: if ($context eq 'course') {
7389: %lt = &Apache::lonlocal::texthash (
1.239 raeburn 7390: any => 'Any',
1.376 raeburn 7391: automated => 'Automated Enrollment',
1.239 raeburn 7392: updatenow => 'Roster Update',
7393: createcourse => 'Course Creation',
7394: course => 'User Management in course',
7395: domain => 'User Management in domain',
1.313 raeburn 7396: selfenroll => 'Self-enrolled',
1.318 raeburn 7397: requestcourses => 'Course Request',
1.239 raeburn 7398: );
1.363 raeburn 7399: if ($crstype eq 'Community') {
7400: $lt{'createcourse'} = &mt('Community Creation');
7401: $lt{'course'} = &mt('User Management in community');
7402: $lt{'requestcourses'} = &mt('Community Request');
7403: }
7404: } elsif ($context eq 'domain') {
7405: %lt = &Apache::lonlocal::texthash (
7406: any => 'Any',
7407: domain => 'User Management in domain',
7408: requestauthor => 'Authoring Request',
7409: server => 'Command line script (DC role)',
7410: domconfig => 'Self-enrolled',
7411: );
7412: } else {
7413: %lt = &Apache::lonlocal::texthash (
7414: any => 'Any',
7415: domain => 'User Management in domain',
7416: author => 'User Management by author',
7417: );
7418: }
1.239 raeburn 7419: return %lt;
7420: }
7421:
1.428 raeburn 7422: sub print_helpdeskaccess_display {
7423: my ($r,$permission,$brcrum) = @_;
7424: my $formname = 'helpdeskaccess';
7425: my $helpitem = 'Course_Helpdesk_Access';
7426: push (@{$brcrum},
7427: {href => '/adm/createuser?action=helpdesk',
7428: text => 'Helpdesk Access',
7429: help => $helpitem});
7430: my $bread_crumbs_component = 'Helpdesk Staff Access';
7431: my $args = { bread_crumbs => $brcrum,
7432: bread_crumbs_component => $bread_crumbs_component};
7433:
7434: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
7435: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
7436: my $confname = $cdom.'-domainconfig';
7437: my $crstype = &Apache::loncommon::course_type();
7438:
1.434 raeburn 7439: my @accesstypes = ('all','dh','da','none');
1.428 raeburn 7440: my ($numstatustypes,@jsarray);
7441: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($cdom);
7442: if (ref($types) eq 'ARRAY') {
1.430 raeburn 7443: if (@{$types} > 0) {
1.428 raeburn 7444: $numstatustypes = scalar(@{$types});
7445: push(@accesstypes,'status');
7446: @jsarray = ('bystatus');
7447: }
7448: }
7449: my %customroles = &get_domain_customroles($cdom,$confname);
1.432 raeburn 7450: my %domhelpdesk = &Apache::lonnet::get_active_domroles($cdom,['dh','da']);
1.428 raeburn 7451: if (keys(%domhelpdesk)) {
7452: push(@accesstypes,('inc','exc'));
7453: push(@jsarray,('notinc','notexc'));
7454: }
7455: push(@jsarray,'privs');
7456: my $hiddenstr = join("','",@jsarray);
7457: my $rolestr = join("','",sort(keys(%customroles)));
7458:
7459: my $jscript;
7460: my (%settings,%overridden);
7461: if (keys(%customroles)) {
7462: &get_adhocrole_settings($env{'request.course.id'},\@accesstypes,
7463: $types,\%customroles,\%settings,\%overridden);
7464: my %jsfull=();
7465: my %jslevels= (
7466: course => {},
7467: domain => {},
7468: system => {},
7469: );
7470: my %jslevelscurrent=(
7471: course => {},
7472: domain => {},
7473: system => {},
7474: );
7475: my (%privs,%jsprivs);
7476: &Apache::lonuserutils::custom_role_privs(\%privs,\%jsfull,\%jslevels,\%jslevelscurrent);
7477: foreach my $priv (keys(%jsfull)) {
7478: if ($jslevels{'course'}{$priv}) {
7479: $jsprivs{$priv} = 1;
7480: }
7481: }
7482: my (%elements,%stored);
7483: foreach my $role (keys(%customroles)) {
7484: $elements{$role.'_access'} = 'radio';
7485: $elements{$role.'_incrs'} = 'radio';
7486: if ($numstatustypes) {
7487: $elements{$role.'_status'} = 'checkbox';
7488: }
7489: if (keys(%domhelpdesk) > 0) {
7490: $elements{$role.'_staff_inc'} = 'checkbox';
7491: $elements{$role.'_staff_exc'} = 'checkbox';
7492: }
1.430 raeburn 7493: $elements{$role.'_override'} = 'checkbox';
1.428 raeburn 7494: if (ref($settings{$role}) eq 'HASH') {
7495: if ($settings{$role}{'access'} ne '') {
7496: my $curraccess = $settings{$role}{'access'};
7497: $stored{$role.'_access'} = $curraccess;
7498: $stored{$role.'_incrs'} = 1;
7499: if ($curraccess eq 'status') {
7500: if (ref($settings{$role}{'status'}) eq 'ARRAY') {
7501: $stored{$role.'_status'} = $settings{$role}{'status'};
7502: }
7503: } elsif (($curraccess eq 'exc') || ($curraccess eq 'inc')) {
7504: if (ref($settings{$role}{$curraccess}) eq 'ARRAY') {
7505: $stored{$role.'_staff_'.$curraccess} = $settings{$role}{$curraccess};
7506: }
7507: }
7508: } else {
7509: $stored{$role.'_incrs'} = 0;
7510: }
7511: $stored{$role.'_override'} = [];
7512: if ($env{'course.'.$env{'request.course.id'}.'.internal.adhocpriv.'.$role}) {
7513: if (ref($settings{$role}{'off'}) eq 'ARRAY') {
7514: foreach my $priv (@{$settings{$role}{'off'}}) {
7515: push(@{$stored{$role.'_override'}},$priv);
7516: }
7517: }
7518: if (ref($settings{$role}{'on'}) eq 'ARRAY') {
7519: foreach my $priv (@{$settings{$role}{'on'}}) {
7520: unless (grep(/^$priv$/,@{$stored{$role.'_override'}})) {
7521: push(@{$stored{$role.'_override'}},$priv);
7522: }
7523: }
7524: }
7525: }
7526: } else {
7527: $stored{$role.'_incrs'} = 0;
7528: }
7529: }
7530: $jscript = &Apache::lonhtmlcommon::set_form_elements(\%elements,\%stored);
7531: }
7532:
7533: my $js = <<"ENDJS";
7534: <script type="text/javascript">
7535: // <![CDATA[
7536: $jscript;
7537:
7538: function switchRoleTab(caller,role) {
7539: if (document.getElementById(role+'_maindiv')) {
7540: if (caller.id != 'LC_current_minitab') {
7541: if (document.getElementById('LC_current_minitab')) {
7542: document.getElementById('LC_current_minitab').id=null;
7543: }
7544: var roledivs = Array('$rolestr');
7545: if (roledivs.length > 0) {
7546: for (var i=0; i<roledivs.length; i++) {
7547: if (document.getElementById(roledivs[i]+'_maindiv')) {
7548: document.getElementById(roledivs[i]+'_maindiv').style.display='none';
7549: }
7550: }
7551: }
7552: caller.id = 'LC_current_minitab';
7553: document.getElementById(role+'_maindiv').style.display='block';
7554: }
7555: }
7556: return false;
1.430 raeburn 7557: }
1.428 raeburn 7558:
7559: function helpdeskAccess(role) {
7560: var curraccess = null;
7561: if (document.$formname.elements[role+'_access'].length) {
7562: for (var i=0; i<document.$formname.elements[role+'_access'].length; i++) {
7563: if (document.$formname.elements[role+'_access'][i].checked) {
7564: curraccess = document.$formname.elements[role+'_access'][i].value;
7565: }
7566: }
7567: }
7568: var shown = Array();
7569: var hidden = Array();
7570: if (curraccess == 'none') {
1.430 raeburn 7571: hidden = Array ('$hiddenstr');
1.428 raeburn 7572: } else {
7573: if (curraccess == 'status') {
1.430 raeburn 7574: shown = Array ('bystatus','privs');
7575: hidden = Array ('notinc','notexc');
1.428 raeburn 7576: } else {
7577: if (curraccess == 'exc') {
7578: shown = Array ('notexc','privs');
7579: hidden = Array ('notinc','bystatus');
7580: }
7581: if (curraccess == 'inc') {
7582: shown = Array ('notinc','privs');
7583: hidden = Array ('notexc','bystatus');
7584: }
7585: if (curraccess == 'all') {
7586: shown = Array ('privs');
7587: hidden = Array ('notinc','notexc','bystatus');
7588: }
7589: }
7590: }
7591: if (hidden.length > 0) {
7592: for (var i=0; i<hidden.length; i++) {
7593: if (document.getElementById(role+'_'+hidden[i])) {
1.430 raeburn 7594: document.getElementById(role+'_'+hidden[i]).style.display = 'none';
1.428 raeburn 7595: }
7596: }
7597: }
7598: if (shown.length > 0) {
7599: for (var i=0; i<shown.length; i++) {
7600: if (document.getElementById(role+'_'+shown[i])) {
7601: if (shown[i] == 'privs') {
7602: document.getElementById(role+'_'+shown[i]).style.display = 'block';
7603: } else {
7604: document.getElementById(role+'_'+shown[i]).style.display = 'inline';
7605: }
7606: }
7607: }
7608: }
7609: return;
7610: }
7611:
7612: function toggleAccess(role) {
7613: if ((document.getElementById(role+'_setincrs')) &&
7614: (document.getElementById(role+'_setindom'))) {
7615: for (var i=0; i<document.$formname.elements[role+'_incrs'].length; i++) {
7616: if (document.$formname.elements[role+'_incrs'][i].checked) {
7617: if (document.$formname.elements[role+'_incrs'][i].value == 1) {
7618: document.getElementById(role+'_setindom').style.display = 'none';
1.430 raeburn 7619: document.getElementById(role+'_setincrs').style.display = 'block';
1.428 raeburn 7620: } else {
7621: document.getElementById(role+'_setincrs').style.display = 'none';
7622: document.getElementById(role+'_setindom').style.display = 'block';
7623: }
7624: break;
7625: }
7626: }
7627: }
7628: return;
7629: }
7630:
7631: // ]]>
7632: </script>
7633: ENDJS
7634:
7635: $args->{add_entries} = {onload => "javascript:setFormElements(document.$formname)"};
7636:
7637: # print page header
7638: $r->print(&header($js,$args));
7639: # print form header
7640: $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">');
7641:
7642: if (keys(%customroles)) {
7643: my %lt = &Apache::lonlocal::texthash(
7644: 'aco' => 'As course owner you may override the defaults set in the domain for role usage and/or privileges.',
7645: 'rou' => 'Role usage',
7646: 'whi' => 'Which helpdesk personnel may use this role?',
7647: 'udd' => 'Use domain default',
1.433 raeburn 7648: 'all' => 'All with domain helpdesk or helpdesk assistant role',
1.434 raeburn 7649: 'dh' => 'All with domain helpdesk role',
7650: 'da' => 'All with domain helpdesk assistant role',
1.428 raeburn 7651: 'none' => 'None',
7652: 'status' => 'Determined based on institutional status',
1.430 raeburn 7653: 'inc' => 'Include all, but exclude specific personnel',
1.428 raeburn 7654: 'exc' => 'Exclude all, but include specific personnel',
7655: 'hel' => 'Helpdesk',
7656: 'rpr' => 'Role privileges',
7657: );
7658: $lt{'tfh'} = &mt("Custom [_1]ad hoc[_2] course roles available for use by the domain's helpdesk are as follows",'<i>','</i>');
7659: my %domconfig = &Apache::lonnet::get_dom('configuration',['helpsettings'],$cdom);
7660: my (%domcurrent,%ordered,%description,%domusage,$disabled);
7661: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
7662: if (ref($domconfig{'helpsettings'}{'adhoc'}) eq 'HASH') {
7663: %domcurrent = %{$domconfig{'helpsettings'}{'adhoc'}};
7664: }
7665: }
7666: my $count = 0;
7667: foreach my $role (sort(keys(%customroles))) {
7668: my ($order,$desc,$access_in_dom);
7669: if (ref($domcurrent{$role}) eq 'HASH') {
7670: $order = $domcurrent{$role}{'order'};
7671: $desc = $domcurrent{$role}{'desc'};
7672: $access_in_dom = $domcurrent{$role}{'access'};
7673: }
7674: if ($order eq '') {
7675: $order = $count;
7676: }
7677: $ordered{$order} = $role;
7678: if ($desc ne '') {
7679: $description{$role} = $desc;
7680: } else {
7681: $description{$role}= $role;
7682: }
7683: $count++;
7684: }
7685: %domusage = &domain_adhoc_access(\%customroles,\%domcurrent,\@accesstypes,$usertypes,$othertitle);
7686: my @roles_by_num = ();
7687: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
7688: push(@roles_by_num,$ordered{$item});
1.430 raeburn 7689: }
1.429 raeburn 7690: $r->print('<p>'.$lt{'tfh'}.': <i>'.join('</i>, <i>',map { $description{$_}; } @roles_by_num).'</i>.');
1.428 raeburn 7691: if ($permission->{'owner'}) {
7692: $r->print('<br />'.$lt{'aco'}.'</p><p>');
7693: $r->print('<input type="hidden" name="state" value="process" />'.
7694: '<input type="submit" value="'.&mt('Save changes').'" />');
7695: } else {
7696: if ($env{'course.'.$env{'request.course.id'}.'.internal.courseowner'}) {
7697: my ($ownername,$ownerdom) = split(/:/,$env{'course.'.$env{'request.course.id'}.'.internal.courseowner'});
7698: $r->print('<br />'.&mt('The course owner -- [_1] -- can override the default access and/or privileges for these ad hoc roles.',
7699: &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($ownername,$ownerdom),$ownername,$ownerdom)));
7700: }
7701: $disabled = ' disabled="disabled"';
7702: }
7703: $r->print('</p>');
7704:
7705: $r->print('<div id="LC_minitab_header"><ul>');
7706: my $count = 0;
7707: my %visibility;
7708: foreach my $role (@roles_by_num) {
7709: my $id;
7710: if ($count == 0) {
7711: $id=' id="LC_current_minitab"';
1.430 raeburn 7712: $visibility{$role} = ' style="display:block"';
1.428 raeburn 7713: } else {
7714: $visibility{$role} = ' style="display:none"';
7715: }
7716: $count ++;
7717: $r->print('<li'.$id.'><a href="#" onclick="javascript:switchRoleTab(this.parentNode,'."'$role'".');">'.$description{$role}.'</a></li>');
7718: }
7719: $r->print('</ul></div>');
7720:
7721: foreach my $role (@roles_by_num) {
7722: my %usecheck = (
7723: all => ' checked="checked"',
7724: );
7725: my %displaydiv = (
7726: status => 'none',
7727: inc => 'none',
7728: exc => 'none',
7729: priv => 'block',
7730: );
7731: my (%selected,$overridden,$incrscheck,$indomcheck,$indomvis,$incrsvis);
1.430 raeburn 7732: if (ref($settings{$role}) eq 'HASH') {
1.428 raeburn 7733: if ($settings{$role}{'access'} ne '') {
7734: $indomvis = ' style="display:none"';
7735: $incrsvis = ' style="display:block"';
1.430 raeburn 7736: $incrscheck = ' checked="checked"';
1.428 raeburn 7737: if ($settings{$role}{'access'} ne 'all') {
7738: $usecheck{$settings{$role}{'access'}} = $usecheck{'all'};
7739: delete($usecheck{'all'});
7740: if ($settings{$role}{'access'} eq 'status') {
7741: my $access = 'status';
7742: $displaydiv{$access} = 'inline';
7743: if (ref($settings{$role}{$access}) eq 'ARRAY') {
7744: $selected{$access} = $settings{$role}{$access};
7745: }
7746: } elsif ($settings{$role}{'access'} =~ /^(inc|exc)$/) {
7747: my $access = $1;
7748: $displaydiv{$access} = 'inline';
7749: if (ref($settings{$role}{$access}) eq 'ARRAY') {
7750: $selected{$access} = $settings{$role}{$access};
7751: }
7752: } elsif ($settings{$role}{'access'} eq 'none') {
7753: $displaydiv{'priv'} = 'none';
7754: }
7755: }
7756: } else {
7757: $indomcheck = ' checked="checked"';
7758: $indomvis = ' style="display:block"';
7759: $incrsvis = ' style="display:none"';
7760: }
7761: } else {
7762: $indomcheck = ' checked="checked"';
1.430 raeburn 7763: $indomvis = ' style="display:block"';
1.428 raeburn 7764: $incrsvis = ' style="display:none"';
7765: }
7766: $r->print('<div class="LC_left_float" id="'.$role.'_maindiv"'.$visibility{$role}.'>'.
7767: '<fieldset><legend>'.$lt{'rou'}.'</legend>'.
7768: '<p>'.$lt{'whi'}.' <span class="LC_nobreak">'.
7769: '<label><input type="radio" name="'.$role.'_incrs" value="1"'.$incrscheck.' onclick="toggleAccess('."'$role'".');"'.$disabled.'>'.
7770: &mt('Set here in [_1]',lc($crstype)).'</label>'.
7771: '<span>'.(' 'x2).
7772: '<label><input type="radio" name="'.$role.'_incrs" value="0"'.$indomcheck.' onclick="toggleAccess('."'$role'".');"'.$disabled.'>'.
7773: $lt{'udd'}.'</label><span></p>'.
7774: '<div id="'.$role.'_setindom"'.$indomvis.'>'.
7775: '<span class="LC_cusr_emph">'.$domusage{$role}.'</span></div>'.
7776: '<div id="'.$role.'_setincrs"'.$incrsvis.'>');
7777: foreach my $access (@accesstypes) {
7778: $r->print('<p><label><input type="radio" name="'.$role.'_access" value="'.$access.'" '.$usecheck{$access}.
7779: ' onclick="helpdeskAccess('."'$role'".');"'.$disabled.' />'.$lt{$access}.'</label>');
7780: if ($access eq 'status') {
7781: $r->print('<div id="'.$role.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
7782: &Apache::lonuserutils::adhoc_status_types($cdom,undef,$role,$selected{$access},
7783: $othertitle,$usertypes,$types,$disabled).
7784: '</div>');
7785: } elsif (($access eq 'inc') && (keys(%domhelpdesk) > 0)) {
7786: $r->print('<div id="'.$role.'_notinc" style="display:'.$displaydiv{$access}.'">'.
7787: &Apache::lonuserutils::adhoc_staff($access,undef,$role,$selected{$access},
7788: \%domhelpdesk,$disabled).
7789: '</div>');
7790: } elsif (($access eq 'exc') && (keys(%domhelpdesk) > 0)) {
7791: $r->print('<div id="'.$role.'_notexc" style="display:'.$displaydiv{$access}.'">'.
7792: &Apache::lonuserutils::adhoc_staff($access,undef,$role,$selected{$access},
7793: \%domhelpdesk,$disabled).
7794: '</div>');
7795: }
7796: $r->print('</p>');
7797: }
7798: $r->print('</div></fieldset>');
7799: my %full=();
7800: my %levels= (
7801: course => {},
7802: domain => {},
7803: system => {},
7804: );
7805: my %levelscurrent=(
7806: course => {},
7807: domain => {},
7808: system => {},
7809: );
7810: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
7811: $r->print('<fieldset id="'.$role.'_privs" style="display:'.$displaydiv{'priv'}.'">'.
7812: '<legend>'.$lt{'rpr'}.'</legend>'.
7813: &role_priv_table($role,$permission,$crstype,\%full,\%levels,\%levelscurrent,$overridden{$role}).
7814: '</fieldset></div><div style="padding:0;clear:both;margin:0;border:0"></div>');
7815: }
1.429 raeburn 7816: if ($permission->{'owner'}) {
7817: $r->print('<p><input type="submit" value="'.&mt('Save changes').'" /></p>');
7818: }
1.428 raeburn 7819: } else {
7820: $r->print(&mt('Helpdesk roles have not yet been created in this domain.'));
7821: }
7822: # Form Footer
7823: $r->print('<input type="hidden" name="action" value="helpdesk" />'
7824: .'</form>');
7825: return;
7826: }
7827:
7828: sub domain_adhoc_access {
7829: my ($roles,$domcurrent,$accesstypes,$usertypes,$othertitle) = @_;
7830: my %domusage;
7831: return unless ((ref($roles) eq 'HASH') && (ref($domcurrent) eq 'HASH') && (ref($accesstypes) eq 'ARRAY'));
7832: foreach my $role (keys(%{$roles})) {
7833: if (ref($domcurrent->{$role}) eq 'HASH') {
7834: my $access = $domcurrent->{$role}{'access'};
7835: if (($access eq '') || (!grep(/^\Q$access\E$/,@{$accesstypes}))) {
7836: $access = 'all';
1.432 raeburn 7837: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role',&Apache::lonnet::plaintext('dh'),
7838: &Apache::lonnet::plaintext('da'));
1.428 raeburn 7839: } elsif ($access eq 'status') {
7840: if (ref($domcurrent->{$role}{$access}) eq 'ARRAY') {
7841: my @shown;
7842: foreach my $type (@{$domcurrent->{$role}{$access}}) {
7843: unless ($type eq 'default') {
7844: if ($usertypes->{$type}) {
7845: push(@shown,$usertypes->{$type});
7846: }
7847: }
7848: }
7849: if (grep(/^default$/,@{$domcurrent->{$role}{$access}})) {
7850: push(@shown,$othertitle);
7851: }
7852: if (@shown) {
7853: my $shownstatus = join(' '.&mt('or').' ',@shown);
1.432 raeburn 7854: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role, and institutional status: [_3]',
7855: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'),$shownstatus);
1.428 raeburn 7856: } else {
7857: $domusage{$role} = &mt('No one in the domain');
7858: }
7859: }
7860: } elsif ($access eq 'inc') {
7861: my @dominc = ();
7862: if (ref($domcurrent->{$role}{'inc'}) eq 'ARRAY') {
7863: foreach my $user (@{$domcurrent->{$role}{'inc'}}) {
7864: my ($uname,$udom) = split(/:/,$user);
7865: push(@dominc,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),$uname,$udom));
7866: }
7867: my $showninc = join(', ',@dominc);
7868: if ($showninc ne '') {
1.432 raeburn 7869: $domusage{$role} = &mt('Include any user in domain with active [_1] or [_2] role, except: [_3]',
7870: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'),$showninc);
1.428 raeburn 7871: } else {
1.432 raeburn 7872: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role',
7873: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'));
1.428 raeburn 7874: }
7875: }
7876: } elsif ($access eq 'exc') {
7877: my @domexc = ();
7878: if (ref($domcurrent->{$role}{'exc'}) eq 'ARRAY') {
7879: foreach my $user (@{$domcurrent->{$role}{'exc'}}) {
7880: my ($uname,$udom) = split(/:/,$user);
7881: push(@domexc,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),$uname,$udom));
7882: }
7883: }
7884: my $shownexc = join(', ',@domexc);
7885: if ($shownexc ne '') {
1.432 raeburn 7886: $domusage{$role} = &mt('Only the following in the domain with active [_1] or [_2] role: [_3]',
7887: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'),$shownexc);
1.428 raeburn 7888: } else {
7889: $domusage{$role} = &mt('No one in the domain');
7890: }
7891: } elsif ($access eq 'none') {
7892: $domusage{$role} = &mt('No one in the domain');
1.434 raeburn 7893: } elsif ($access eq 'dh') {
1.433 raeburn 7894: $domusage{$role} = &mt('Any user in domain with active [_1] role',&Apache::lonnet::plaintext('dh'));
1.434 raeburn 7895: } elsif ($access eq 'da') {
1.433 raeburn 7896: $domusage{$role} = &mt('Any user in domain with active [_1] role',&Apache::lonnet::plaintext('da'));
1.428 raeburn 7897: } elsif ($access eq 'all') {
1.432 raeburn 7898: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role',
7899: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'));
1.428 raeburn 7900: }
7901: } else {
1.432 raeburn 7902: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role',
7903: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'));
1.428 raeburn 7904: }
7905: }
7906: return %domusage;
7907: }
7908:
7909: sub get_domain_customroles {
7910: my ($cdom,$confname) = @_;
7911: my %existing=&Apache::lonnet::dump('roles',$cdom,$confname,'rolesdef_');
7912: my %customroles;
7913: foreach my $key (keys(%existing)) {
7914: if ($key=~/^rolesdef\_(\w+)$/) {
7915: my $rolename = $1;
7916: my %privs;
7917: ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
7918: $customroles{$rolename} = \%privs;
7919: }
7920: }
7921: return %customroles;
7922: }
7923:
7924: sub role_priv_table {
7925: my ($role,$permission,$crstype,$full,$levels,$levelscurrent,$overridden) = @_;
7926: return unless ((ref($full) eq 'HASH') && (ref($levels) eq 'HASH') &&
7927: (ref($levelscurrent) eq 'HASH'));
7928: my %lt=&Apache::lonlocal::texthash (
7929: 'crl' => 'Course Level Privilege',
7930: 'def' => 'Domain Defaults',
7931: 'ove' => 'Override in Course',
7932: 'ine' => 'In effect',
7933: 'dis' => 'Disabled',
7934: 'ena' => 'Enabled',
7935: );
7936: if ($crstype eq 'Community') {
7937: $lt{'ove'} = 'Override in Community',
7938: }
7939: my @status = ('Disabled','Enabled');
7940: my (%on,%off);
7941: if (ref($overridden) eq 'HASH') {
7942: if (ref($overridden->{'on'}) eq 'ARRAY') {
7943: map { $on{$_} = 1; } (@{$overridden->{'on'}});
7944: }
7945: if (ref($overridden->{'off'}) eq 'ARRAY') {
7946: map { $off{$_} = 1; } (@{$overridden->{'off'}});
7947: }
7948: }
7949: my $output=&Apache::loncommon::start_data_table().
7950: &Apache::loncommon::start_data_table_header_row().
7951: '<th>'.$lt{'crl'}.'</th><th>'.$lt{'def'}.'</th><th>'.$lt{'ove'}.
7952: '</th><th>'.$lt{'ine'}.'</th>'.
7953: &Apache::loncommon::end_data_table_header_row();
7954: foreach my $priv (sort(keys(%{$full}))) {
7955: next unless ($levels->{'course'}{$priv});
7956: my $privtext = &Apache::lonnet::plaintext($priv,$crstype);
7957: my ($default,$ineffect);
7958: if ($levelscurrent->{'course'}{$priv}) {
7959: $default = '<img src="/adm/lonIcons/navmap.correct.gif" alt="'.$lt{'ena'}.'" />';
7960: $ineffect = $default;
7961: }
7962: my ($customstatus,$checked);
7963: $output .= &Apache::loncommon::start_data_table_row().
7964: '<td>'.$privtext.'</td>'.
7965: '<td>'.$default.'</td><td>';
7966: if (($levelscurrent->{'course'}{$priv}) && ($off{$priv})) {
7967: if ($permission->{'owner'}) {
7968: $checked = ' checked="checked"';
7969: }
7970: $customstatus = '<img src="/adm/lonIcons/navmap.wrong.gif" alt="'.$lt{'dis'}.'" />';
1.430 raeburn 7971: $ineffect = $customstatus;
1.428 raeburn 7972: } elsif ((!$levelscurrent->{'course'}{$priv}) && ($on{$priv})) {
7973: if ($permission->{'owner'}) {
1.430 raeburn 7974: $checked = ' checked="checked"';
1.428 raeburn 7975: }
7976: $customstatus = '<img src="/adm/lonIcons/navmap.correct.gif" alt="'.$lt{'ena'}.'" />';
1.430 raeburn 7977: $ineffect = $customstatus;
1.428 raeburn 7978: }
7979: if ($permission->{'owner'}) {
7980: $output .= '<input type="checkbox" name="'.$role.'_override" value="'.$priv.'"'.$checked.' />';
7981: } else {
7982: $output .= $customstatus;
7983: }
7984: $output .= '</td><td>'.$ineffect.'</td>'.
7985: &Apache::loncommon::end_data_table_row();
7986: }
7987: $output .= &Apache::loncommon::end_data_table();
7988: return $output;
7989: }
7990:
7991: sub get_adhocrole_settings {
1.430 raeburn 7992: my ($cid,$accesstypes,$types,$customroles,$settings,$overridden) = @_;
1.428 raeburn 7993: return unless ((ref($accesstypes) eq 'ARRAY') && (ref($customroles) eq 'HASH') &&
7994: (ref($settings) eq 'HASH') && (ref($overridden) eq 'HASH'));
7995: foreach my $role (split(/,/,$env{'course.'.$cid.'.internal.adhocaccess'})) {
7996: my ($curraccess,$rest) = split(/=/,$env{'course.'.$cid.'.internal.adhoc.'.$role});
7997: if (($curraccess ne '') && (grep(/^\Q$curraccess\E$/,@{$accesstypes}))) {
7998: $settings->{$role}{'access'} = $curraccess;
7999: if (($curraccess eq 'status') && (ref($types) eq 'ARRAY')) {
8000: my @status = split(/,/,$rest);
8001: my @currstatus;
8002: foreach my $type (@status) {
8003: if ($type eq 'default') {
8004: push(@currstatus,$type);
8005: } elsif (grep(/^\Q$type\E$/,@{$types})) {
8006: push(@currstatus,$type);
8007: }
8008: }
8009: if (@currstatus) {
8010: $settings->{$role}{$curraccess} = \@currstatus;
8011: } elsif (($curraccess eq 'exc') || ($curraccess eq 'inc')) {
8012: my @personnel = split(/,/,$rest);
8013: $settings->{$role}{$curraccess} = \@personnel;
8014: }
8015: }
8016: }
8017: }
8018: foreach my $role (keys(%{$customroles})) {
8019: if ($env{'course.'.$cid.'.internal.adhocpriv.'.$role}) {
8020: my %currentprivs;
8021: if (ref($customroles->{$role}) eq 'HASH') {
8022: if (exists($customroles->{$role}{'course'})) {
8023: my %full=();
8024: my %levels= (
8025: course => {},
8026: domain => {},
8027: system => {},
8028: );
8029: my %levelscurrent=(
8030: course => {},
8031: domain => {},
8032: system => {},
8033: );
8034: &Apache::lonuserutils::custom_role_privs($customroles->{$role},\%full,\%levels,\%levelscurrent);
8035: %currentprivs = %{$levelscurrent{'course'}};
8036: }
8037: }
8038: foreach my $item (split(/,/,$env{'course.'.$cid.'.internal.adhocpriv.'.$role})) {
8039: next if ($item eq '');
8040: my ($rule,$rest) = split(/=/,$item);
8041: next unless (($rule eq 'off') || ($rule eq 'on'));
8042: foreach my $priv (split(/:/,$rest)) {
8043: if ($priv ne '') {
8044: if ($rule eq 'off') {
8045: push(@{$overridden->{$role}{'off'}},$priv);
8046: if ($currentprivs{$priv}) {
8047: push(@{$settings->{$role}{'off'}},$priv);
8048: }
8049: } else {
8050: push(@{$overridden->{$role}{'on'}},$priv);
8051: unless ($currentprivs{$priv}) {
8052: push(@{$settings->{$role}{'on'}},$priv);
8053: }
8054: }
8055: }
8056: }
8057: }
8058: }
8059: }
8060: return;
8061: }
8062:
8063: sub update_helpdeskaccess {
8064: my ($r,$permission,$brcrum) = @_;
8065: my $helpitem = 'Course_Helpdesk_Access';
8066: push (@{$brcrum},
8067: {href => '/adm/createuser?action=helpdesk',
8068: text => 'Helpdesk Access',
8069: help => $helpitem},
8070: {href => '/adm/createuser?action=helpdesk',
8071: text => 'Result',
8072: help => $helpitem}
8073: );
8074: my $bread_crumbs_component = 'Helpdesk Staff Access';
8075: my $args = { bread_crumbs => $brcrum,
8076: bread_crumbs_component => $bread_crumbs_component};
8077:
8078: # print page header
8079: $r->print(&header('',$args));
8080: unless ((ref($permission) eq 'HASH') && ($permission->{'owner'})) {
8081: $r->print('<p class="LC_error">'.&mt('You do not have permission to change helpdesk access.').'</p>');
8082: return;
8083: }
1.434 raeburn 8084: my @accesstypes = ('all','dh','da','none','status','inc','exc');
1.428 raeburn 8085: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
8086: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
8087: my $confname = $cdom.'-domainconfig';
8088: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($cdom);
8089: my $crstype = &Apache::loncommon::course_type();
8090: my %customroles = &get_domain_customroles($cdom,$confname);
8091: my (%settings,%overridden);
8092: &get_adhocrole_settings($env{'request.course.id'},\@accesstypes,
8093: $types,\%customroles,\%settings,\%overridden);
1.432 raeburn 8094: my %domhelpdesk = &Apache::lonnet::get_active_domroles($cdom,['dh','da']);
1.428 raeburn 8095: my (%changed,%storehash,@todelete);
8096:
8097: if (keys(%customroles)) {
8098: my (%newsettings,@incrs);
8099: foreach my $role (keys(%customroles)) {
8100: $newsettings{$role} = {
8101: access => '',
8102: status => '',
8103: exc => '',
8104: inc => '',
8105: on => '',
8106: off => '',
8107: };
8108: my %current;
8109: if (ref($settings{$role}) eq 'HASH') {
8110: %current = %{$settings{$role}};
8111: }
8112: if (ref($overridden{$role}) eq 'HASH') {
8113: $current{'overridden'} = $overridden{$role};
8114: }
8115: if ($env{'form.'.$role.'_incrs'}) {
8116: my $access = $env{'form.'.$role.'_access'};
8117: if (grep(/^\Q$access\E$/,@accesstypes)) {
8118: push(@incrs,$role);
8119: unless ($current{'access'} eq $access) {
8120: $changed{$role}{'access'} = 1;
1.430 raeburn 8121: $storehash{'internal.adhoc.'.$role} = $access;
1.428 raeburn 8122: }
8123: if ($access eq 'status') {
8124: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$role.'_status');
8125: my @stored;
8126: my @shownstatus;
8127: if (ref($types) eq 'ARRAY') {
8128: foreach my $type (sort(@statuses)) {
8129: if ($type eq 'default') {
8130: push(@stored,$type);
8131: } elsif (grep(/^\Q$type\E$/,@{$types})) {
8132: push(@stored,$type);
8133: push(@shownstatus,$usertypes->{$type});
8134: }
8135: }
8136: if (grep(/^default$/,@statuses)) {
8137: push(@shownstatus,$othertitle);
8138: }
8139: $storehash{'internal.adhoc.'.$role} .= '='.join(',',@stored);
8140: }
8141: $newsettings{$role}{'status'} = join(' '.&mt('or').' ',@shownstatus);
8142: if (ref($current{'status'}) eq 'ARRAY') {
8143: my @diffs = &Apache::loncommon::compare_arrays(\@stored,$current{'status'});
8144: if (@diffs) {
8145: $changed{$role}{'status'} = 1;
8146: }
8147: } elsif (@stored) {
8148: $changed{$role}{'status'} = 1;
8149: }
8150: } elsif (($access eq 'inc') || ($access eq 'exc')) {
8151: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$role.'_staff_'.$access);
8152: my @newspecstaff;
8153: my @stored;
8154: my @currstaff;
8155: foreach my $person (sort(@personnel)) {
8156: if ($domhelpdesk{$person}) {
1.430 raeburn 8157: push(@stored,$person);
1.428 raeburn 8158: }
8159: }
8160: if (ref($current{$access}) eq 'ARRAY') {
8161: my @diffs = &Apache::loncommon::compare_arrays(\@stored,$current{$access});
8162: if (@diffs) {
8163: $changed{$role}{$access} = 1;
8164: }
8165: } elsif (@stored) {
8166: $changed{$role}{$access} = 1;
8167: }
8168: $storehash{'internal.adhoc.'.$role} .= '='.join(',',@stored);
8169: foreach my $person (@stored) {
8170: my ($uname,$udom) = split(/:/,$person);
8171: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
8172: }
8173: $newsettings{$role}{$access} = join(', ',sort(@newspecstaff));
8174: }
8175: $newsettings{$role}{'access'} = $access;
8176: }
8177: } else {
8178: if (($current{'access'} ne '') && (grep(/^\Q$current{'access'}\E$/,@accesstypes))) {
8179: $changed{$role}{'access'} = 1;
8180: $newsettings{$role} = {};
8181: push(@todelete,'internal.adhoc.'.$role);
8182: }
8183: }
8184: if (($env{'form.'.$role.'_incrs'}) && ($env{'form.'.$role.'_access'} eq 'none')) {
8185: if (ref($current{'overridden'}) eq 'HASH') {
8186: push(@todelete,'internal.adhocpriv.'.$role);
8187: }
8188: } else {
8189: my %full=();
8190: my %levels= (
8191: course => {},
8192: domain => {},
8193: system => {},
8194: );
8195: my %levelscurrent=(
8196: course => {},
8197: domain => {},
8198: system => {},
8199: );
8200: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
8201: my (@updatedon,@updatedoff,@override);
8202: @override = &Apache::loncommon::get_env_multiple('form.'.$role.'_override');
1.430 raeburn 8203: if (@override) {
1.428 raeburn 8204: foreach my $priv (sort(keys(%full))) {
8205: next unless ($levels{'course'}{$priv});
8206: if (grep(/^\Q$priv\E$/,@override)) {
8207: if ($levelscurrent{'course'}{$priv}) {
8208: push(@updatedoff,$priv);
8209: } else {
8210: push(@updatedon,$priv);
8211: }
8212: }
8213: }
8214: }
8215: if (@updatedon) {
1.430 raeburn 8216: $newsettings{$role}{'on'} = join('</li><li>', map { &Apache::lonnet::plaintext($_,$crstype) } (@updatedon));
1.428 raeburn 8217: }
8218: if (@updatedoff) {
8219: $newsettings{$role}{'off'} = join('</li><li>', map { &Apache::lonnet::plaintext($_,$crstype) } (@updatedoff));
8220: }
8221: if (ref($current{'overridden'}) eq 'HASH') {
8222: if (ref($current{'overridden'}{'on'}) eq 'ARRAY') {
8223: if (@updatedon) {
8224: my @diffs = &Apache::loncommon::compare_arrays(\@updatedon,$current{'overridden'}{'on'});
8225: if (@diffs) {
8226: $changed{$role}{'on'} = 1;
8227: }
8228: } else {
8229: $changed{$role}{'on'} = 1;
8230: }
8231: } elsif (@updatedon) {
8232: $changed{$role}{'on'} = 1;
8233: }
8234: if (ref($current{'overridden'}{'off'}) eq 'ARRAY') {
8235: if (@updatedoff) {
8236: my @diffs = &Apache::loncommon::compare_arrays(\@updatedoff,$current{'overridden'}{'off'});
8237: if (@diffs) {
8238: $changed{$role}{'off'} = 1;
8239: }
8240: } else {
8241: $changed{$role}{'off'} = 1;
8242: }
8243: } elsif (@updatedoff) {
8244: $changed{$role}{'off'} = 1;
8245: }
8246: } else {
8247: if (@updatedon) {
8248: $changed{$role}{'on'} = 1;
8249: }
8250: if (@updatedoff) {
8251: $changed{$role}{'off'} = 1;
8252: }
8253: }
8254: if (ref($changed{$role}) eq 'HASH') {
8255: if (($changed{$role}{'on'} || $changed{$role}{'off'})) {
8256: my $newpriv;
8257: if (@updatedon) {
8258: $newpriv = 'on='.join(':',@updatedon);
8259: }
8260: if (@updatedoff) {
8261: $newpriv .= ($newpriv ? ',' : '' ).'off='.join(':',@updatedoff);
8262: }
8263: if ($newpriv eq '') {
8264: push(@todelete,'internal.adhocpriv.'.$role);
8265: } else {
8266: $storehash{'internal.adhocpriv.'.$role} = $newpriv;
8267: }
8268: }
8269: }
8270: }
8271: }
8272: if (@incrs) {
8273: $storehash{'internal.adhocaccess'} = join(',',@incrs);
8274: } elsif (@todelete) {
8275: push(@todelete,'internal.adhocaccess');
8276: }
8277: if (keys(%changed)) {
8278: my ($putres,$delres);
8279: if (keys(%storehash)) {
8280: $putres = &Apache::lonnet::put('environment',\%storehash,$cdom,$cnum);
8281: my %newenvhash;
8282: foreach my $key (keys(%storehash)) {
8283: $newenvhash{'course.'.$env{'request.course.id'}.'.'.$key} = $storehash{$key};
8284: }
8285: &Apache::lonnet::appenv(\%newenvhash);
8286: }
8287: if (@todelete) {
8288: $delres = &Apache::lonnet::del('environment',\@todelete,$cdom,$cnum);
8289: foreach my $key (@todelete) {
8290: &Apache::lonnet::delenv('course.'.$env{'request.course.id'}.'.'.$key);
8291: }
8292: }
8293: if (($putres eq 'ok') || ($delres eq 'ok')) {
8294: my %domconfig = &Apache::lonnet::get_dom('configuration',['helpsettings'],$cdom);
8295: my (%domcurrent,%ordered,%description,%domusage);
8296: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
8297: if (ref($domconfig{'helpsettings'}{'adhoc'}) eq 'HASH') {
8298: %domcurrent = %{$domconfig{'helpsettings'}{'adhoc'}};
8299: }
8300: }
8301: my $count = 0;
8302: foreach my $role (sort(keys(%customroles))) {
8303: my ($order,$desc);
8304: if (ref($domcurrent{$role}) eq 'HASH') {
8305: $order = $domcurrent{$role}{'order'};
8306: $desc = $domcurrent{$role}{'desc'};
8307: }
8308: if ($order eq '') {
8309: $order = $count;
8310: }
8311: $ordered{$order} = $role;
8312: if ($desc ne '') {
8313: $description{$role} = $desc;
8314: } else {
8315: $description{$role}= $role;
8316: }
8317: $count++;
8318: }
8319: my @roles_by_num = ();
8320: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
8321: push(@roles_by_num,$ordered{$item});
8322: }
8323: %domusage = &domain_adhoc_access(\%changed,\%domcurrent,\@accesstypes,$usertypes,$othertitle);
1.430 raeburn 8324: $r->print(&mt('Helpdesk access settings have been changed as follows').'<br />');
1.428 raeburn 8325: $r->print('<ul>');
8326: foreach my $role (@roles_by_num) {
8327: next unless (ref($changed{$role}) eq 'HASH');
8328: $r->print('<li>'.&mt('Ad hoc role').': <b>'.$description{$role}.'</b>'.
8329: '<ul>');
1.430 raeburn 8330: if ($changed{$role}{'access'} || $changed{$role}{'status'} || $changed{$role}{'inc'} || $changed{$role}{'exc'}) {
1.428 raeburn 8331: $r->print('<li>');
8332: if ($env{'form.'.$role.'_incrs'}) {
8333: if ($newsettings{$role}{'access'} eq 'all') {
8334: $r->print(&mt('All helpdesk staff can access '.lc($crstype).' with this role.'));
1.434 raeburn 8335: } elsif ($newsettings{$role}{'access'} eq 'dh') {
1.433 raeburn 8336: $r->print(&mt('Helpdesk staff can use this role if they have an active [_1] role',
8337: &Apache::lonnet::plaintext('dh')));
1.434 raeburn 8338: } elsif ($newsettings{$role}{'access'} eq 'da') {
1.433 raeburn 8339: $r->print(&mt('Helpdesk staff can use this role if they have an active [_1] role',
8340: &Apache::lonnet::plaintext('da')));
1.428 raeburn 8341: } elsif ($newsettings{$role}{'access'} eq 'none') {
8342: $r->print(&mt('No helpdesk staff can access '.lc($crstype).' with this role.'));
8343: } elsif ($newsettings{$role}{'access'} eq 'status') {
8344: if ($newsettings{$role}{'status'}) {
8345: my ($access,$rest) = split(/=/,$storehash{'internal.adhoc.'.$role});
1.430 raeburn 8346: if (split(/,/,$rest) > 1) {
1.428 raeburn 8347: $r->print(&mt('Helpdesk staff can use this role if their institutional type is one of: [_1].',
8348: $newsettings{$role}{'status'}));
8349: } else {
8350: $r->print(&mt('Helpdesk staff can use this role if their institutional type is: [_1].',
8351: $newsettings{$role}{'status'}));
8352: }
8353: } else {
8354: $r->print(&mt('No helpdesk staff can access '.lc($crstype).' with this role.'));
8355: }
8356: } elsif ($newsettings{$role}{'access'} eq 'exc') {
8357: if ($newsettings{$role}{'exc'}) {
8358: $r->print(&mt('Helpdesk staff who can use this role are as follows:').' '.$newsettings{$role}{'exc'}.'.');
8359: } else {
8360: $r->print(&mt('No helpdesk staff can access '.lc($crstype).' with this role.'));
8361: }
8362: } elsif ($newsettings{$role}{'access'} eq 'inc') {
8363: if ($newsettings{$role}{'inc'}) {
8364: $r->print(&mt('All helpdesk staff may use this role except the following:').' '.$newsettings{$role}{'inc'}.'.');
8365: } else {
8366: $r->print(&mt('All helpdesk staff may use this role.'));
8367: }
8368: }
8369: } else {
8370: $r->print(&mt('Default access set in the domain now applies.').'<br />'.
8371: '<span class="LC_cusr_emph">'.$domusage{$role}.'</span>');
8372: }
8373: $r->print('</li>');
8374: }
8375: unless ($newsettings{$role}{'access'} eq 'none') {
8376: if ($changed{$role}{'off'}) {
8377: if ($newsettings{$role}{'off'}) {
8378: $r->print('<li>'.&mt('Privileges which are available by default for this ad hoc role, but are disabled for this specific '.lc($crstype).':').
8379: '<ul><li>'.$newsettings{$role}{'off'}.'</li></ul></li>');
8380: } else {
1.430 raeburn 8381: $r->print('<li>'.&mt('All privileges available by default for this ad hoc role are enabled.').'</li>');
1.428 raeburn 8382: }
8383: }
1.430 raeburn 8384: if ($changed{$role}{'on'}) {
1.428 raeburn 8385: if ($newsettings{$role}{'on'}) {
8386: $r->print('<li>'.&mt('Privileges which are not available by default for this ad hoc role, but are enabled for this specific '.lc($crstype).':').
8387: '<ul><li>'.$newsettings{$role}{'on'}.'</li></ul></li>');
8388: } else {
1.430 raeburn 8389: $r->print('<li>'.&mt('None of the privileges unavailable by default for this ad hoc role are enabled.').'</li>');
1.428 raeburn 8390: }
8391: }
8392: }
8393: $r->print('</ul></li>');
8394: }
8395: $r->print('</ul>');
8396: }
8397: } else {
1.430 raeburn 8398: $r->print(&mt('No changes made to helpdesk access settings.'));
1.428 raeburn 8399: }
8400: }
8401: return;
8402: }
8403:
1.27 matthew 8404: #-------------------------------------------------- functions for &phase_two
1.160 raeburn 8405: sub user_search_result {
1.221 raeburn 8406: my ($context,$srch) = @_;
1.160 raeburn 8407: my %allhomes;
8408: my %inst_matches;
8409: my %srch_results;
1.181 raeburn 8410: my ($response,$currstate,$forcenewuser,$dirsrchres);
1.183 raeburn 8411: $srch->{'srchterm'} =~ s/\s+/ /g;
1.176 raeburn 8412: if ($srch->{'srchby'} !~ /^(uname|lastname|lastfirst)$/) {
1.160 raeburn 8413: $response = &mt('Invalid search.');
8414: }
8415: if ($srch->{'srchin'} !~ /^(crs|dom|alc|instd)$/) {
8416: $response = &mt('Invalid search.');
8417: }
1.177 raeburn 8418: if ($srch->{'srchtype'} !~ /^(exact|contains|begins)$/) {
1.160 raeburn 8419: $response = &mt('Invalid search.');
8420: }
8421: if ($srch->{'srchterm'} eq '') {
8422: $response = &mt('You must enter a search term.');
8423: }
1.183 raeburn 8424: if ($srch->{'srchterm'} =~ /^\s+$/) {
8425: $response = &mt('Your search term must contain more than just spaces.');
8426: }
1.160 raeburn 8427: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'instd')) {
8428: if (($srch->{'srchdomain'} eq '') ||
1.163 albertel 8429: ! (&Apache::lonnet::domain($srch->{'srchdomain'}))) {
1.160 raeburn 8430: $response = &mt('You must specify a valid domain when searching in a domain or institutional directory.')
8431: }
8432: }
8433: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs') ||
8434: ($srch->{'srchin'} eq 'alc')) {
1.176 raeburn 8435: if ($srch->{'srchby'} eq 'uname') {
1.243 raeburn 8436: my $unamecheck = $srch->{'srchterm'};
8437: if ($srch->{'srchtype'} eq 'contains') {
8438: if ($unamecheck !~ /^\w/) {
8439: $unamecheck = 'a'.$unamecheck;
8440: }
8441: }
8442: if ($unamecheck !~ /^$match_username$/) {
1.176 raeburn 8443: $response = &mt('You must specify a valid username. Only the following are allowed: letters numbers - . @');
8444: }
1.160 raeburn 8445: }
8446: }
1.180 raeburn 8447: if ($response ne '') {
1.413 raeburn 8448: $response = '<span class="LC_warning">'.$response.'</span><br />';
1.180 raeburn 8449: }
1.160 raeburn 8450: if ($srch->{'srchin'} eq 'instd') {
1.412 raeburn 8451: my $instd_chk = &instdirectorysrch_check($srch);
1.160 raeburn 8452: if ($instd_chk ne 'ok') {
1.412 raeburn 8453: my $domd_chk = &domdirectorysrch_check($srch);
1.413 raeburn 8454: $response .= '<span class="LC_warning">'.$instd_chk.'</span><br />';
1.412 raeburn 8455: if ($domd_chk eq 'ok') {
1.435 raeburn 8456: $response .= &mt('You may want to search in the LON-CAPA domain instead of in the institutional directory.');
1.412 raeburn 8457: }
1.415 raeburn 8458: $response .= '<br />';
1.412 raeburn 8459: }
8460: } else {
1.417 raeburn 8461: unless (($context eq 'requestcrs') && ($srch->{'srchtype'} eq 'exact')) {
1.412 raeburn 8462: my $domd_chk = &domdirectorysrch_check($srch);
1.438 raeburn 8463: if (($domd_chk ne 'ok') && ($env{'form.action'} ne 'accesslogs')) {
1.412 raeburn 8464: my $instd_chk = &instdirectorysrch_check($srch);
1.413 raeburn 8465: $response .= '<span class="LC_warning">'.$domd_chk.'</span><br />';
1.412 raeburn 8466: if ($instd_chk eq 'ok') {
1.435 raeburn 8467: $response .= &mt('You may want to search in the institutional directory instead of in the LON-CAPA domain.');
1.412 raeburn 8468: }
1.415 raeburn 8469: $response .= '<br />';
1.412 raeburn 8470: }
1.160 raeburn 8471: }
8472: }
8473: if ($response ne '') {
1.180 raeburn 8474: return ($currstate,$response);
1.160 raeburn 8475: }
8476: if ($srch->{'srchby'} eq 'uname') {
8477: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs')) {
8478: if ($env{'form.forcenew'}) {
8479: if ($srch->{'srchdomain'} ne $env{'request.role.domain'}) {
8480: my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
8481: if ($uhome eq 'no_host') {
8482: my $domdesc = &Apache::lonnet::domain($env{'request.role.domain'},'description');
1.180 raeburn 8483: my $showdom = &display_domain_info($env{'request.role.domain'});
8484: $response = &mt('New users can only be created in the domain to which your current role belongs - [_1].',$showdom);
1.160 raeburn 8485: } else {
1.179 raeburn 8486: $currstate = 'modify';
1.160 raeburn 8487: }
8488: } else {
1.179 raeburn 8489: $currstate = 'modify';
1.160 raeburn 8490: }
8491: } else {
8492: if ($srch->{'srchin'} eq 'dom') {
1.162 raeburn 8493: if ($srch->{'srchtype'} eq 'exact') {
8494: my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
8495: if ($uhome eq 'no_host') {
1.179 raeburn 8496: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8497: &build_search_response($context,$srch,%srch_results);
1.162 raeburn 8498: } else {
1.179 raeburn 8499: $currstate = 'modify';
1.416 raeburn 8500: if ($env{'form.action'} eq 'accesslogs') {
8501: $currstate = 'activity';
8502: }
1.310 raeburn 8503: my $uname = $srch->{'srchterm'};
8504: my $udom = $srch->{'srchdomain'};
8505: $srch_results{$uname.':'.$udom} =
8506: { &Apache::lonnet::get('environment',
8507: ['firstname',
8508: 'lastname',
8509: 'permanentemail'],
8510: $udom,$uname)
8511: };
1.162 raeburn 8512: }
8513: } else {
8514: %srch_results = &Apache::lonnet::usersearch($srch);
1.179 raeburn 8515: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8516: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 8517: }
8518: } else {
1.167 albertel 8519: my $courseusers = &get_courseusers();
1.162 raeburn 8520: if ($srch->{'srchtype'} eq 'exact') {
1.167 albertel 8521: if (exists($courseusers->{$srch->{'srchterm'}.':'.$srch->{'srchdomain'}})) {
1.179 raeburn 8522: $currstate = 'modify';
1.162 raeburn 8523: } else {
1.179 raeburn 8524: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8525: &build_search_response($context,$srch,%srch_results);
1.162 raeburn 8526: }
1.160 raeburn 8527: } else {
1.167 albertel 8528: foreach my $user (keys(%$courseusers)) {
1.162 raeburn 8529: my ($cuname,$cudomain) = split(/:/,$user);
8530: if ($cudomain eq $srch->{'srchdomain'}) {
1.177 raeburn 8531: my $matched = 0;
8532: if ($srch->{'srchtype'} eq 'begins') {
8533: if ($cuname =~ /^\Q$srch->{'srchterm'}\E/i) {
8534: $matched = 1;
8535: }
8536: } else {
8537: if ($cuname =~ /\Q$srch->{'srchterm'}\E/i) {
8538: $matched = 1;
8539: }
8540: }
8541: if ($matched) {
1.167 albertel 8542: $srch_results{$user} =
8543: {&Apache::lonnet::get('environment',
8544: ['firstname',
8545: 'lastname',
1.194 albertel 8546: 'permanentemail'],
8547: $cudomain,$cuname)};
1.162 raeburn 8548: }
8549: }
8550: }
1.179 raeburn 8551: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8552: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 8553: }
8554: }
8555: }
8556: } elsif ($srch->{'srchin'} eq 'alc') {
1.179 raeburn 8557: $currstate = 'query';
1.160 raeburn 8558: } elsif ($srch->{'srchin'} eq 'instd') {
1.181 raeburn 8559: ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
8560: if ($dirsrchres eq 'ok') {
8561: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8562: &build_search_response($context,$srch,%srch_results);
1.181 raeburn 8563: } else {
8564: my $showdom = &display_domain_info($srch->{'srchdomain'});
8565: $response = '<span class="LC_warning">'.
8566: &mt('Institutional directory search is not available in domain: [_1]',$showdom).
8567: '</span><br />'.
1.435 raeburn 8568: &mt('You may want to search in the LON-CAPA domain instead of in the institutional directory.').
1.415 raeburn 8569: '<br />';
1.181 raeburn 8570: }
1.160 raeburn 8571: }
8572: } else {
8573: if ($srch->{'srchin'} eq 'dom') {
8574: %srch_results = &Apache::lonnet::usersearch($srch);
1.179 raeburn 8575: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8576: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 8577: } elsif ($srch->{'srchin'} eq 'crs') {
1.167 albertel 8578: my $courseusers = &get_courseusers();
8579: foreach my $user (keys(%$courseusers)) {
1.160 raeburn 8580: my ($uname,$udom) = split(/:/,$user);
8581: my %names = &Apache::loncommon::getnames($uname,$udom);
8582: my %emails = &Apache::loncommon::getemails($uname,$udom);
8583: if ($srch->{'srchby'} eq 'lastname') {
8584: if ((($srch->{'srchtype'} eq 'exact') &&
8585: ($names{'lastname'} eq $srch->{'srchterm'})) ||
1.177 raeburn 8586: (($srch->{'srchtype'} eq 'begins') &&
8587: ($names{'lastname'} =~ /^\Q$srch->{'srchterm'}\E/i)) ||
1.160 raeburn 8588: (($srch->{'srchtype'} eq 'contains') &&
8589: ($names{'lastname'} =~ /\Q$srch->{'srchterm'}\E/i))) {
8590: $srch_results{$user} = {firstname => $names{'firstname'},
8591: lastname => $names{'lastname'},
8592: permanentemail => $emails{'permanentemail'},
8593: };
8594: }
8595: } elsif ($srch->{'srchby'} eq 'lastfirst') {
8596: my ($srchlast,$srchfirst) = split(/,/,$srch->{'srchterm'});
1.177 raeburn 8597: $srchlast =~ s/\s+$//;
8598: $srchfirst =~ s/^\s+//;
1.160 raeburn 8599: if ($srch->{'srchtype'} eq 'exact') {
8600: if (($names{'lastname'} eq $srchlast) &&
8601: ($names{'firstname'} eq $srchfirst)) {
8602: $srch_results{$user} = {firstname => $names{'firstname'},
8603: lastname => $names{'lastname'},
8604: permanentemail => $emails{'permanentemail'},
8605:
8606: };
8607: }
1.177 raeburn 8608: } elsif ($srch->{'srchtype'} eq 'begins') {
8609: if (($names{'lastname'} =~ /^\Q$srchlast\E/i) &&
8610: ($names{'firstname'} =~ /^\Q$srchfirst\E/i)) {
8611: $srch_results{$user} = {firstname => $names{'firstname'},
8612: lastname => $names{'lastname'},
8613: permanentemail => $emails{'permanentemail'},
8614: };
8615: }
8616: } else {
1.160 raeburn 8617: if (($names{'lastname'} =~ /\Q$srchlast\E/i) &&
8618: ($names{'firstname'} =~ /\Q$srchfirst\E/i)) {
8619: $srch_results{$user} = {firstname => $names{'firstname'},
8620: lastname => $names{'lastname'},
8621: permanentemail => $emails{'permanentemail'},
8622: };
8623: }
8624: }
8625: }
8626: }
1.179 raeburn 8627: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8628: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 8629: } elsif ($srch->{'srchin'} eq 'alc') {
1.179 raeburn 8630: $currstate = 'query';
1.160 raeburn 8631: } elsif ($srch->{'srchin'} eq 'instd') {
1.181 raeburn 8632: ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
8633: if ($dirsrchres eq 'ok') {
8634: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8635: &build_search_response($context,$srch,%srch_results);
1.181 raeburn 8636: } else {
1.412 raeburn 8637: my $showdom = &display_domain_info($srch->{'srchdomain'});
8638: $response = '<span class="LC_warning">'.
1.181 raeburn 8639: &mt('Institutional directory search is not available in domain: [_1]',$showdom).
8640: '</span><br />'.
1.435 raeburn 8641: &mt('You may want to search in the LON-CAPA domain instead of in the institutional directory.').
1.415 raeburn 8642: '<br />';
1.181 raeburn 8643: }
1.160 raeburn 8644: }
8645: }
1.179 raeburn 8646: return ($currstate,$response,$forcenewuser,\%srch_results);
1.160 raeburn 8647: }
8648:
1.412 raeburn 8649: sub domdirectorysrch_check {
8650: my ($srch) = @_;
8651: my $response;
8652: my %dom_inst_srch = &Apache::lonnet::get_dom('configuration',
8653: ['directorysrch'],$srch->{'srchdomain'});
8654: my $showdom = &display_domain_info($srch->{'srchdomain'});
8655: if (ref($dom_inst_srch{'directorysrch'}) eq 'HASH') {
8656: if ($dom_inst_srch{'directorysrch'}{'lcavailable'} eq '0') {
8657: return &mt('LON-CAPA directory search is not available in domain: [_1]',$showdom);
8658: }
8659: if ($dom_inst_srch{'directorysrch'}{'lclocalonly'}) {
8660: if ($env{'request.role.domain'} ne $srch->{'srchdomain'}) {
8661: return &mt('LON-CAPA directory search in domain: [_1] is only allowed for users with a current role in the domain.',$showdom);
8662: }
8663: }
8664: }
8665: return 'ok';
8666: }
8667:
8668: sub instdirectorysrch_check {
1.160 raeburn 8669: my ($srch) = @_;
8670: my $can_search = 0;
8671: my $response;
8672: my %dom_inst_srch = &Apache::lonnet::get_dom('configuration',
8673: ['directorysrch'],$srch->{'srchdomain'});
1.180 raeburn 8674: my $showdom = &display_domain_info($srch->{'srchdomain'});
1.160 raeburn 8675: if (ref($dom_inst_srch{'directorysrch'}) eq 'HASH') {
8676: if (!$dom_inst_srch{'directorysrch'}{'available'}) {
1.180 raeburn 8677: return &mt('Institutional directory search is not available in domain: [_1]',$showdom);
1.160 raeburn 8678: }
8679: if ($dom_inst_srch{'directorysrch'}{'localonly'}) {
8680: if ($env{'request.role.domain'} ne $srch->{'srchdomain'}) {
1.180 raeburn 8681: return &mt('Institutional directory search in domain: [_1] is only allowed for users with a current role in the domain.',$showdom);
1.160 raeburn 8682: }
8683: my @usertypes = split(/:/,$env{'environment.inststatus'});
8684: if (!@usertypes) {
8685: push(@usertypes,'default');
8686: }
8687: if (ref($dom_inst_srch{'directorysrch'}{'cansearch'}) eq 'ARRAY') {
8688: foreach my $type (@usertypes) {
8689: if (grep(/^\Q$type\E$/,@{$dom_inst_srch{'directorysrch'}{'cansearch'}})) {
8690: $can_search = 1;
8691: last;
8692: }
8693: }
8694: }
8695: if (!$can_search) {
8696: my ($insttypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($srch->{'srchdomain'});
8697: my @longtypes;
8698: foreach my $item (@usertypes) {
1.229 raeburn 8699: if (defined($insttypes->{$item})) {
8700: push (@longtypes,$insttypes->{$item});
8701: } elsif ($item eq 'default') {
8702: push (@longtypes,&mt('other'));
8703: }
1.160 raeburn 8704: }
8705: my $insttype_str = join(', ',@longtypes);
1.180 raeburn 8706: return &mt('Institutional directory search in domain: [_1] is not available to your user type: ',$showdom).$insttype_str;
1.229 raeburn 8707: }
1.160 raeburn 8708: } else {
8709: $can_search = 1;
8710: }
8711: } else {
1.180 raeburn 8712: return &mt('Institutional directory search has not been configured for domain: [_1]',$showdom);
1.160 raeburn 8713: }
8714: my %longtext = &Apache::lonlocal::texthash (
1.167 albertel 8715: uname => 'username',
1.160 raeburn 8716: lastfirst => 'last name, first name',
1.167 albertel 8717: lastname => 'last name',
1.172 raeburn 8718: contains => 'contains',
1.178 raeburn 8719: exact => 'as exact match to',
8720: begins => 'begins with',
1.160 raeburn 8721: );
8722: if ($can_search) {
8723: if (ref($dom_inst_srch{'directorysrch'}{'searchby'}) eq 'ARRAY') {
8724: if (!grep(/^\Q$srch->{'srchby'}\E$/,@{$dom_inst_srch{'directorysrch'}{'searchby'}})) {
1.180 raeburn 8725: return &mt('Institutional directory search in domain: [_1] is not available for searching by "[_2]"',$showdom,$longtext{$srch->{'srchby'}});
1.160 raeburn 8726: }
8727: } else {
1.180 raeburn 8728: return &mt('Institutional directory search in domain: [_1] is not available.', $showdom);
1.160 raeburn 8729: }
8730: }
8731: if ($can_search) {
1.178 raeburn 8732: if (ref($dom_inst_srch{'directorysrch'}{'searchtypes'}) eq 'ARRAY') {
8733: if (grep(/^\Q$srch->{'srchtype'}\E/,@{$dom_inst_srch{'directorysrch'}{'searchtypes'}})) {
8734: return 'ok';
8735: } else {
1.180 raeburn 8736: return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
1.178 raeburn 8737: }
8738: } else {
8739: if ((($dom_inst_srch{'directorysrch'}{'searchtypes'} eq 'specify') &&
8740: ($srch->{'srchtype'} eq 'exact' || $srch->{'srchtype'} eq 'contains')) ||
8741: ($dom_inst_srch{'directorysrch'}{'searchtypes'} eq $srch->{'srchtype'})) {
8742: return 'ok';
8743: } else {
1.180 raeburn 8744: return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
1.178 raeburn 8745: }
1.160 raeburn 8746: }
8747: }
8748: }
8749:
8750: sub get_courseusers {
8751: my %advhash;
1.167 albertel 8752: my $classlist = &Apache::loncoursedata::get_classlist();
1.160 raeburn 8753: my %coursepersonnel=&Apache::lonnet::get_course_adv_roles();
8754: foreach my $role (sort(keys(%coursepersonnel))) {
8755: foreach my $user (split(/\,/,$coursepersonnel{$role})) {
1.167 albertel 8756: if (!exists($classlist->{$user})) {
8757: $classlist->{$user} = [];
8758: }
1.160 raeburn 8759: }
8760: }
1.167 albertel 8761: return $classlist;
1.160 raeburn 8762: }
8763:
8764: sub build_search_response {
1.221 raeburn 8765: my ($context,$srch,%srch_results) = @_;
1.179 raeburn 8766: my ($currstate,$response,$forcenewuser);
1.160 raeburn 8767: my %names = (
1.330 bisitz 8768: 'uname' => 'username',
8769: 'lastname' => 'last name',
1.160 raeburn 8770: 'lastfirst' => 'last name, first name',
1.330 bisitz 8771: 'crs' => 'this course',
8772: 'dom' => 'LON-CAPA domain',
8773: 'instd' => 'the institutional directory for domain',
1.160 raeburn 8774: );
8775:
8776: my %single = (
1.180 raeburn 8777: begins => 'A match',
1.160 raeburn 8778: contains => 'A match',
1.180 raeburn 8779: exact => 'An exact match',
1.160 raeburn 8780: );
8781: my %nomatch = (
1.180 raeburn 8782: begins => 'No match',
1.160 raeburn 8783: contains => 'No match',
1.180 raeburn 8784: exact => 'No exact match',
1.160 raeburn 8785: );
8786: if (keys(%srch_results) > 1) {
1.179 raeburn 8787: $currstate = 'select';
1.160 raeburn 8788: } else {
8789: if (keys(%srch_results) == 1) {
1.416 raeburn 8790: if ($env{'form.action'} eq 'accesslogs') {
8791: $currstate = 'activity';
8792: } else {
8793: $currstate = 'modify';
8794: }
1.180 raeburn 8795: $response = &mt("$single{$srch->{'srchtype'}} was found for the $names{$srch->{'srchby'}} ([_1]) in $names{$srch->{'srchin'}}.",$srch->{'srchterm'});
8796: if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
1.330 bisitz 8797: $response .= ': '.&display_domain_info($srch->{'srchdomain'});
1.180 raeburn 8798: }
1.330 bisitz 8799: } else { # Search has nothing found. Prepare message to user.
8800: $response = '<span class="LC_warning">';
1.180 raeburn 8801: if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
1.330 bisitz 8802: $response .= &mt("$nomatch{$srch->{'srchtype'}} found for the $names{$srch->{'srchby'}} [_1] in $names{$srch->{'srchin'}}: [_2]",
8803: '<b>'.$srch->{'srchterm'}.'</b>',
8804: &display_domain_info($srch->{'srchdomain'}));
8805: } else {
8806: $response .= &mt("$nomatch{$srch->{'srchtype'}} found for the $names{$srch->{'srchby'}} [_1] in $names{$srch->{'srchin'}}.",
8807: '<b>'.$srch->{'srchterm'}.'</b>');
1.180 raeburn 8808: }
8809: $response .= '</span>';
1.330 bisitz 8810:
1.160 raeburn 8811: if ($srch->{'srchin'} ne 'alc') {
8812: $forcenewuser = 1;
8813: my $cansrchinst = 0;
1.438 raeburn 8814: if (($srch->{'srchdomain'}) && ($env{'form.action'} ne 'accesslogs')) {
1.160 raeburn 8815: my %domconfig = &Apache::lonnet::get_dom('configuration',['directorysrch'],$srch->{'srchdomain'});
8816: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
8817: if ($domconfig{'directorysrch'}{'available'}) {
8818: $cansrchinst = 1;
8819: }
8820: }
8821: }
1.180 raeburn 8822: if ((($srch->{'srchby'} eq 'lastfirst') ||
8823: ($srch->{'srchby'} eq 'lastname')) &&
8824: ($srch->{'srchin'} eq 'dom')) {
8825: if ($cansrchinst) {
8826: $response .= '<br />'.&mt('You may want to broaden your search to a search of the institutional directory for the domain.');
1.160 raeburn 8827: }
8828: }
1.180 raeburn 8829: if ($srch->{'srchin'} eq 'crs') {
8830: $response .= '<br />'.&mt('You may want to broaden your search to the selected LON-CAPA domain.');
8831: }
8832: }
1.305 raeburn 8833: my $createdom = $env{'request.role.domain'};
8834: if ($context eq 'requestcrs') {
8835: if ($env{'form.coursedom'} ne '') {
8836: $createdom = $env{'form.coursedom'};
8837: }
8838: }
1.416 raeburn 8839: unless (($env{'form.action'} eq 'accesslogs') || (($srch->{'srchby'} eq 'uname') && ($srch->{'srchin'} eq 'dom') &&
8840: ($srch->{'srchtype'} eq 'exact') && ($srch->{'srchdomain'} eq $createdom))) {
1.221 raeburn 8841: my $cancreate =
1.305 raeburn 8842: &Apache::lonuserutils::can_create_user($createdom,$context);
8843: my $targetdom = '<span class="LC_cusr_emph">'.$createdom.'</span>';
1.221 raeburn 8844: if ($cancreate) {
1.305 raeburn 8845: my $showdom = &display_domain_info($createdom);
1.266 bisitz 8846: $response .= '<br /><br />'
8847: .'<b>'.&mt('To add a new user:').'</b>'
1.305 raeburn 8848: .'<br />';
8849: if ($context eq 'requestcrs') {
8850: $response .= &mt("(You can only define new users in the new course's domain - [_1])",$targetdom);
8851: } else {
8852: $response .= &mt("(You can only create new users in your current role's domain - [_1])",$targetdom);
8853: }
8854: $response .='<ul><li>'
1.266 bisitz 8855: .&mt("Set 'Domain/institution to search' to: [_1]",'<span class="LC_cusr_emph">'.$showdom.'</span>')
8856: .'</li><li>'
8857: .&mt("Set 'Search criteria' to: [_1]username is ..... in selected LON-CAPA domain[_2]",'<span class="LC_cusr_emph">','</span>')
8858: .'</li><li>'
8859: .&mt('Provide the proposed username')
8860: .'</li><li>'
8861: .&mt("Click 'Search'")
8862: .'</li></ul><br />';
1.221 raeburn 8863: } else {
1.422 raeburn 8864: unless (($context eq 'domain') && ($env{'form.action'} eq 'singleuser')) {
8865: my $helplink = ' href="javascript:helpMenu('."'display'".')"';
8866: $response .= '<br /><br />';
8867: if ($context eq 'requestcrs') {
8868: $response .= &mt("You are not authorized to define new users in the new course's domain - [_1].",$targetdom);
8869: } else {
8870: $response .= &mt("You are not authorized to create new users in your current role's domain - [_1].",$targetdom);
8871: }
8872: $response .= '<br />'
8873: .&mt('Please contact the [_1]helpdesk[_2] if you need to create a new user.'
8874: ,' <a'.$helplink.'>'
8875: ,'</a>')
8876: .'<br />';
1.305 raeburn 8877: }
1.221 raeburn 8878: }
1.160 raeburn 8879: }
8880: }
8881: }
1.179 raeburn 8882: return ($currstate,$response,$forcenewuser);
1.160 raeburn 8883: }
8884:
1.180 raeburn 8885: sub display_domain_info {
8886: my ($dom) = @_;
8887: my $output = $dom;
8888: if ($dom ne '') {
8889: my $domdesc = &Apache::lonnet::domain($dom,'description');
8890: if ($domdesc ne '') {
8891: $output .= ' <span class="LC_cusr_emph">('.$domdesc.')</span>';
8892: }
8893: }
8894: return $output;
8895: }
8896:
1.160 raeburn 8897: sub crumb_utilities {
8898: my %elements = (
8899: crtuser => {
8900: srchterm => 'text',
1.172 raeburn 8901: srchin => 'selectbox',
1.160 raeburn 8902: srchby => 'selectbox',
8903: srchtype => 'selectbox',
8904: srchdomain => 'selectbox',
8905: },
1.207 raeburn 8906: crtusername => {
8907: srchterm => 'text',
8908: srchdomain => 'selectbox',
8909: },
1.160 raeburn 8910: docustom => {
8911: rolename => 'selectbox',
8912: newrolename => 'textbox',
8913: },
1.179 raeburn 8914: studentform => {
8915: srchterm => 'text',
8916: srchin => 'selectbox',
8917: srchby => 'selectbox',
8918: srchtype => 'selectbox',
8919: srchdomain => 'selectbox',
8920: },
1.160 raeburn 8921: );
8922:
8923: my $jsback .= qq|
8924: function backPage(formname,prevphase,prevstate) {
1.211 raeburn 8925: if (typeof prevphase == 'undefined') {
8926: formname.phase.value = '';
8927: }
8928: else {
8929: formname.phase.value = prevphase;
8930: }
8931: if (typeof prevstate == 'undefined') {
8932: formname.currstate.value = '';
8933: }
8934: else {
8935: formname.currstate.value = prevstate;
8936: }
1.160 raeburn 8937: formname.submit();
8938: }
8939: |;
8940: return ($jsback,\%elements);
8941: }
8942:
1.26 matthew 8943: sub course_level_table {
1.375 raeburn 8944: my ($inccourses,$showcredits,$defaultcredits) = @_;
8945: return unless (ref($inccourses) eq 'HASH');
1.26 matthew 8946: my $table = '';
1.62 www 8947: # Custom Roles?
8948:
1.190 raeburn 8949: my %customroles=&Apache::lonuserutils::my_custom_roles();
1.89 raeburn 8950: my %lt=&Apache::lonlocal::texthash(
8951: 'exs' => "Existing sections",
8952: 'new' => "Define new section",
8953: 'ssd' => "Set Start Date",
8954: 'sed' => "Set End Date",
1.131 raeburn 8955: 'crl' => "Course Level",
1.89 raeburn 8956: 'act' => "Activate",
8957: 'rol' => "Role",
8958: 'ext' => "Extent",
1.113 raeburn 8959: 'grs' => "Section",
1.375 raeburn 8960: 'crd' => "Credits",
1.89 raeburn 8961: 'sta' => "Start",
8962: 'end' => "End"
8963: );
1.62 www 8964:
1.375 raeburn 8965: foreach my $protectedcourse (sort(keys(%{$inccourses}))) {
1.135 raeburn 8966: my $thiscourse=$protectedcourse;
1.26 matthew 8967: $thiscourse=~s:_:/:g;
8968: my %coursedata=&Apache::lonnet::coursedescription($thiscourse);
1.365 raeburn 8969: my $isowner = &Apache::lonuserutils::is_courseowner($protectedcourse,$coursedata{'internal.courseowner'});
1.26 matthew 8970: my $area=$coursedata{'description'};
1.321 raeburn 8971: my $crstype=$coursedata{'type'};
1.135 raeburn 8972: if (!defined($area)) { $area=&mt('Unavailable course').': '.$protectedcourse; }
1.89 raeburn 8973: my ($domain,$cnum)=split(/\//,$thiscourse);
1.115 albertel 8974: my %sections_count;
1.101 albertel 8975: if (defined($env{'request.course.id'})) {
8976: if ($env{'request.course.id'} eq $domain.'_'.$cnum) {
1.115 albertel 8977: %sections_count =
8978: &Apache::loncommon::get_sections($domain,$cnum);
1.92 raeburn 8979: }
8980: }
1.321 raeburn 8981: my @roles = &Apache::lonuserutils::roles_by_context('course','',$crstype);
1.213 raeburn 8982: foreach my $role (@roles) {
1.321 raeburn 8983: my $plrole=&Apache::lonnet::plaintext($role,$crstype);
1.329 raeburn 8984: if ((&Apache::lonnet::allowed('c'.$role,$thiscourse)) ||
8985: ((($role eq 'cc') || ($role eq 'co')) && ($isowner))) {
1.221 raeburn 8986: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
1.375 raeburn 8987: $plrole,\%sections_count,\%lt,
1.402 raeburn 8988: $showcredits,$defaultcredits,$crstype);
1.221 raeburn 8989: } elsif ($env{'request.course.sec'} ne '') {
8990: if (&Apache::lonnet::allowed('c'.$role,$thiscourse.'/'.
8991: $env{'request.course.sec'})) {
8992: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
1.375 raeburn 8993: $plrole,\%sections_count,\%lt,
1.402 raeburn 8994: $showcredits,$defaultcredits,$crstype);
1.26 matthew 8995: }
8996: }
8997: }
1.221 raeburn 8998: if (&Apache::lonnet::allowed('ccr',$thiscourse)) {
1.324 raeburn 8999: foreach my $cust (sort(keys(%customroles))) {
9000: next if ($crstype eq 'Community' && $customroles{$cust} =~ /bre\&S/);
1.221 raeburn 9001: my $role = 'cr_cr_'.$env{'user.domain'}.'_'.$env{'user.name'}.'_'.$cust;
9002: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
1.402 raeburn 9003: $cust,\%sections_count,\%lt,
9004: $showcredits,$defaultcredits,$crstype);
1.221 raeburn 9005: }
1.62 www 9006: }
1.26 matthew 9007: }
9008: return '' if ($table eq ''); # return nothing if there is nothing
9009: # in the table
1.188 raeburn 9010: my $result;
9011: if (!$env{'request.course.id'}) {
9012: $result = '<h4>'.$lt{'crl'}.'</h4>'."\n";
9013: }
9014: $result .=
1.136 raeburn 9015: &Apache::loncommon::start_data_table().
9016: &Apache::loncommon::start_data_table_header_row().
1.375 raeburn 9017: '<th>'.$lt{'act'}.'</th><th>'.$lt{'rol'}.'</th>'."\n".
1.402 raeburn 9018: '<th>'.$lt{'ext'}.'</th><th>'."\n";
9019: if ($showcredits) {
9020: $result .= $lt{'crd'}.'</th>';
9021: }
9022: $result .=
1.375 raeburn 9023: '<th>'.$lt{'grs'}.'</th><th>'.$lt{'sta'}.'</th>'."\n".
9024: '<th>'.$lt{'end'}.'</th>'.
1.136 raeburn 9025: &Apache::loncommon::end_data_table_header_row().
9026: $table.
9027: &Apache::loncommon::end_data_table();
1.26 matthew 9028: return $result;
9029: }
1.88 raeburn 9030:
1.221 raeburn 9031: sub course_level_row {
1.375 raeburn 9032: my ($protectedcourse,$role,$area,$domain,$plrole,$sections_count,
1.402 raeburn 9033: $lt,$showcredits,$defaultcredits,$crstype) = @_;
1.375 raeburn 9034: my $creditem;
1.222 raeburn 9035: my $row = &Apache::loncommon::start_data_table_row().
9036: ' <td><input type="checkbox" name="act_'.
9037: $protectedcourse.'_'.$role.'" /></td>'."\n".
9038: ' <td>'.$plrole.'</td>'."\n".
9039: ' <td>'.$area.'<br />Domain: '.$domain.'</td>'."\n";
1.402 raeburn 9040: if (($showcredits) && ($role eq 'st') && ($crstype eq 'Course')) {
1.375 raeburn 9041: $row .=
9042: '<td><input type="text" name="credits_'.$protectedcourse.'_'.
9043: $role.'" size="3" value="'.$defaultcredits.'" /></td>';
9044: } else {
9045: $row .= '<td> </td>';
9046: }
1.322 raeburn 9047: if (($role eq 'cc') || ($role eq 'co')) {
1.222 raeburn 9048: $row .= '<td> </td>';
1.221 raeburn 9049: } elsif ($env{'request.course.sec'} ne '') {
1.222 raeburn 9050: $row .= ' <td><input type="hidden" value="'.
9051: $env{'request.course.sec'}.'" '.
9052: 'name="sec_'.$protectedcourse.'_'.$role.'" />'.
9053: $env{'request.course.sec'}.'</td>';
1.221 raeburn 9054: } else {
9055: if (ref($sections_count) eq 'HASH') {
9056: my $currsec =
9057: &Apache::lonuserutils::course_sections($sections_count,
9058: $protectedcourse.'_'.$role);
1.222 raeburn 9059: $row .= '<td><table class="LC_createuser">'."\n".
9060: '<tr class="LC_section_row">'."\n".
9061: ' <td valign="top">'.$lt->{'exs'}.'<br />'.
9062: $currsec.'</td>'."\n".
9063: ' <td> </td>'."\n".
9064: ' <td valign="top"> '.$lt->{'new'}.'<br />'.
1.221 raeburn 9065: '<input type="text" name="newsec_'.$protectedcourse.'_'.$role.
9066: '" value="" />'.
9067: '<input type="hidden" '.
9068: 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'."\n".
1.222 raeburn 9069: '</tr></table></td>'."\n";
1.221 raeburn 9070: } else {
1.222 raeburn 9071: $row .= '<td><input type="text" size="10" '.
1.375 raeburn 9072: 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'."\n";
1.221 raeburn 9073: }
9074: }
1.222 raeburn 9075: $row .= <<ENDTIMEENTRY;
9076: <td><input type="hidden" name="start_$protectedcourse\_$role" value="" />
1.221 raeburn 9077: <a href=
9078: "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 9079: <td><input type="hidden" name="end_$protectedcourse\_$role" value="" />
1.221 raeburn 9080: <a href=
9081: "javascript:pjump('date_end','End Date $plrole',document.cu.end_$protectedcourse\_$role.value,'end_$protectedcourse\_$role','cu.pres','dateset')">$lt->{'sed'}</a></td>
9082: ENDTIMEENTRY
1.222 raeburn 9083: $row .= &Apache::loncommon::end_data_table_row();
9084: return $row;
1.221 raeburn 9085: }
9086:
1.88 raeburn 9087: sub course_level_dc {
1.375 raeburn 9088: my ($dcdom,$showcredits) = @_;
1.190 raeburn 9089: my %customroles=&Apache::lonuserutils::my_custom_roles();
1.213 raeburn 9090: my @roles = &Apache::lonuserutils::roles_by_context('course');
1.88 raeburn 9091: my $hiddenitems = '<input type="hidden" name="dcdomain" value="'.$dcdom.'" />'.
9092: '<input type="hidden" name="origdom" value="'.$dcdom.'" />'.
1.133 raeburn 9093: '<input type="hidden" name="dccourse" value="" />';
1.355 www 9094: my $courseform=&Apache::loncommon::selectcourse_link
1.356 raeburn 9095: ('cu','dccourse','dcdomain','coursedesc',undef,undef,'Select','crstype');
1.375 raeburn 9096: my $credit_elem;
9097: if ($showcredits) {
9098: $credit_elem = 'credits';
9099: }
9100: my $cb_jscript = &Apache::loncommon::coursebrowser_javascript($dcdom,'currsec','cu','role','Course/Community Browser',$credit_elem);
1.88 raeburn 9101: my %lt=&Apache::lonlocal::texthash(
9102: 'rol' => "Role",
1.113 raeburn 9103: 'grs' => "Section",
1.88 raeburn 9104: 'exs' => "Existing sections",
9105: 'new' => "Define new section",
9106: 'sta' => "Start",
9107: 'end' => "End",
9108: 'ssd' => "Set Start Date",
1.355 www 9109: 'sed' => "Set End Date",
1.375 raeburn 9110: 'scc' => "Course/Community",
9111: 'crd' => "Credits",
1.88 raeburn 9112: );
1.323 raeburn 9113: my $header = '<h4>'.&mt('Course/Community Level').'</h4>'.
1.136 raeburn 9114: &Apache::loncommon::start_data_table().
9115: &Apache::loncommon::start_data_table_header_row().
1.375 raeburn 9116: '<th>'.$lt{'scc'}.'</th><th>'.$lt{'rol'}.'</th>'."\n".
1.397 bisitz 9117: '<th>'.$lt{'grs'}.'</th>'."\n";
9118: $header .= '<th>'.$lt{'crd'}.'</th>'."\n" if ($showcredits);
9119: $header .= '<th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'."\n".
1.136 raeburn 9120: &Apache::loncommon::end_data_table_header_row();
1.143 raeburn 9121: my $otheritems = &Apache::loncommon::start_data_table_row()."\n".
1.356 raeburn 9122: '<td><br /><span class="LC_nobreak"><input type="text" name="coursedesc" value="" onfocus="this.blur();opencrsbrowser('."'cu','dccourse','dcdomain','coursedesc','','','','crstype'".')" />'.
9123: $courseform.(' ' x4).'</span></td>'."\n".
1.389 bisitz 9124: '<td valign="top"><br /><select name="role">'."\n";
1.213 raeburn 9125: foreach my $role (@roles) {
1.135 raeburn 9126: my $plrole=&Apache::lonnet::plaintext($role);
1.389 bisitz 9127: $otheritems .= ' <option value="'.$role.'">'.$plrole.'</option>';
1.88 raeburn 9128: }
1.404 raeburn 9129: if ( keys(%customroles) > 0) {
9130: foreach my $cust (sort(keys(%customroles))) {
1.101 albertel 9131: my $custrole='cr_cr_'.$env{'user.domain'}.
1.135 raeburn 9132: '_'.$env{'user.name'}.'_'.$cust;
1.389 bisitz 9133: $otheritems .= ' <option value="'.$custrole.'">'.$cust.'</option>';
1.88 raeburn 9134: }
9135: }
9136: $otheritems .= '</select></td><td>'.
9137: '<table border="0" cellspacing="0" cellpadding="0">'.
9138: '<tr><td valign="top"><b>'.$lt{'exs'}.'</b><br /><select name="currsec">'.
1.389 bisitz 9139: ' <option value=""><--'.&mt('Pick course first').'</option></select></td>'.
1.88 raeburn 9140: '<td> </td>'.
9141: '<td valign="top"> <b>'.$lt{'new'}.'</b><br />'.
1.113 raeburn 9142: '<input type="text" name="newsec" value="" />'.
1.237 raeburn 9143: '<input type="hidden" name="section" value="" />'.
1.323 raeburn 9144: '<input type="hidden" name="groups" value="" />'.
9145: '<input type="hidden" name="crstype" value="" /></td>'.
1.375 raeburn 9146: '</tr></table></td>'."\n";
9147: if ($showcredits) {
9148: $otheritems .= '<td><br />'."\n".
1.397 bisitz 9149: '<input type="text" size="3" name="credits" value="" /></td>'."\n";
1.375 raeburn 9150: }
1.88 raeburn 9151: $otheritems .= <<ENDTIMEENTRY;
1.323 raeburn 9152: <td><br /><input type="hidden" name="start" value='' />
1.88 raeburn 9153: <a href=
9154: "javascript:pjump('date_start','Start Date',document.cu.start.value,'start','cu.pres','dateset')">$lt{'ssd'}</a></td>
1.323 raeburn 9155: <td><br /><input type="hidden" name="end" value='' />
1.88 raeburn 9156: <a href=
9157: "javascript:pjump('date_end','End Date',document.cu.end.value,'end','cu.pres','dateset')">$lt{'sed'}</a></td>
9158: ENDTIMEENTRY
1.136 raeburn 9159: $otheritems .= &Apache::loncommon::end_data_table_row().
9160: &Apache::loncommon::end_data_table()."\n";
1.88 raeburn 9161: return $cb_jscript.$header.$hiddenitems.$otheritems;
9162: }
9163:
1.237 raeburn 9164: sub update_selfenroll_config {
1.400 raeburn 9165: my ($r,$cid,$cdom,$cnum,$context,$crstype,$currsettings) = @_;
1.398 raeburn 9166: return unless (ref($currsettings) eq 'HASH');
9167: my ($row,$lt) = &Apache::lonuserutils::get_selfenroll_titles();
9168: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
1.237 raeburn 9169: my (%changes,%warning);
1.241 raeburn 9170: my $curr_types;
1.400 raeburn 9171: my %noedit;
9172: unless ($context eq 'domain') {
9173: %noedit = &get_noedit_fields($cdom,$cnum,$crstype,$row);
9174: }
1.237 raeburn 9175: if (ref($row) eq 'ARRAY') {
9176: foreach my $item (@{$row}) {
1.400 raeburn 9177: next if ($noedit{$item});
1.237 raeburn 9178: if ($item eq 'enroll_dates') {
9179: my (%currenrolldate,%newenrolldate);
9180: foreach my $type ('start','end') {
1.398 raeburn 9181: $currenrolldate{$type} = $currsettings->{'selfenroll_'.$type.'_date'};
1.237 raeburn 9182: $newenrolldate{$type} = &Apache::lonhtmlcommon::get_date_from_form('selfenroll_'.$type.'_date');
9183: if ($newenrolldate{$type} ne $currenrolldate{$type}) {
9184: $changes{'internal.selfenroll_'.$type.'_date'} = $newenrolldate{$type};
9185: }
9186: }
9187: } elsif ($item eq 'access_dates') {
9188: my (%currdate,%newdate);
9189: foreach my $type ('start','end') {
1.398 raeburn 9190: $currdate{$type} = $currsettings->{'selfenroll_'.$type.'_access'};
1.237 raeburn 9191: $newdate{$type} = &Apache::lonhtmlcommon::get_date_from_form('selfenroll_'.$type.'_access');
9192: if ($newdate{$type} ne $currdate{$type}) {
9193: $changes{'internal.selfenroll_'.$type.'_access'} = $newdate{$type};
9194: }
9195: }
1.241 raeburn 9196: } elsif ($item eq 'types') {
1.398 raeburn 9197: $curr_types = $currsettings->{'selfenroll_'.$item};
1.241 raeburn 9198: if ($env{'form.selfenroll_all'}) {
9199: if ($curr_types ne '*') {
9200: $changes{'internal.selfenroll_types'} = '*';
9201: } else {
9202: next;
9203: }
9204: } else {
1.249 raeburn 9205: my %currdoms;
1.241 raeburn 9206: my @entries = split(/;/,$curr_types);
9207: my @deletedoms = &Apache::loncommon::get_env_multiple('form.selfenroll_delete');
1.249 raeburn 9208: my @activations = &Apache::loncommon::get_env_multiple('form.selfenroll_activate');
1.241 raeburn 9209: my $newnum = 0;
1.249 raeburn 9210: my @latesttypes;
9211: foreach my $num (@activations) {
9212: my @types = &Apache::loncommon::get_env_multiple('form.selfenroll_types_'.$num);
9213: if (@types > 0) {
1.241 raeburn 9214: @types = sort(@types);
9215: my $typestr = join(',',@types);
1.249 raeburn 9216: my $typedom = $env{'form.selfenroll_dom_'.$num};
9217: $latesttypes[$newnum] = $typedom.':'.$typestr;
9218: $currdoms{$typedom} = 1;
1.241 raeburn 9219: $newnum ++;
9220: }
9221: }
1.338 raeburn 9222: for (my $j=0; $j<$env{'form.selfenroll_types_total'}; $j++) {
9223: if ((!grep(/^$j$/,@deletedoms)) && (!grep(/^$j$/,@activations))) {
1.249 raeburn 9224: my @types = &Apache::loncommon::get_env_multiple('form.selfenroll_types_'.$j);
9225: if (@types > 0) {
9226: @types = sort(@types);
9227: my $typestr = join(',',@types);
9228: my $typedom = $env{'form.selfenroll_dom_'.$j};
9229: $latesttypes[$newnum] = $typedom.':'.$typestr;
9230: $currdoms{$typedom} = 1;
9231: $newnum ++;
9232: }
9233: }
9234: }
9235: if ($env{'form.selfenroll_newdom'} ne '') {
9236: my $typedom = $env{'form.selfenroll_newdom'};
9237: if ((!defined($currdoms{$typedom})) &&
9238: (&Apache::lonnet::domain($typedom) ne '')) {
9239: my $typestr;
9240: my ($othertitle,$usertypes,$types) =
9241: &Apache::loncommon::sorted_inst_types($typedom);
9242: my $othervalue = 'any';
9243: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
9244: if (@{$types} > 0) {
1.257 raeburn 9245: my @esc_types = map { &escape($_); } @{$types};
1.249 raeburn 9246: $othervalue = 'other';
1.258 raeburn 9247: $typestr = join(',',(@esc_types,$othervalue));
1.249 raeburn 9248: }
9249: $typestr = $othervalue;
9250: } else {
9251: $typestr = $othervalue;
9252: }
9253: $latesttypes[$newnum] = $typedom.':'.$typestr;
9254: $newnum ++ ;
9255: }
9256: }
1.241 raeburn 9257: my $selfenroll_types = join(';',@latesttypes);
9258: if ($selfenroll_types ne $curr_types) {
9259: $changes{'internal.selfenroll_types'} = $selfenroll_types;
9260: }
9261: }
1.276 raeburn 9262: } elsif ($item eq 'limit') {
9263: my $newlimit = $env{'form.selfenroll_limit'};
9264: my $newcap = $env{'form.selfenroll_cap'};
9265: $newcap =~s/\s+//g;
1.398 raeburn 9266: my $currlimit = $currsettings->{'selfenroll_limit'};
1.276 raeburn 9267: $currlimit = 'none' if ($currlimit eq '');
1.398 raeburn 9268: my $currcap = $currsettings->{'selfenroll_cap'};
1.276 raeburn 9269: if ($newlimit ne $currlimit) {
9270: if ($newlimit ne 'none') {
9271: if ($newcap =~ /^\d+$/) {
9272: if ($newcap ne $currcap) {
9273: $changes{'internal.selfenroll_cap'} = $newcap;
9274: }
9275: $changes{'internal.selfenroll_limit'} = $newlimit;
9276: } else {
1.398 raeburn 9277: $warning{$item} = &mt('Maximum enrollment setting unchanged.').'<br />'.
9278: &mt('The value provided was invalid - it must be a positive integer if enrollment is being limited.');
1.276 raeburn 9279: }
9280: } elsif ($currcap ne '') {
9281: $changes{'internal.selfenroll_cap'} = '';
9282: $changes{'internal.selfenroll_limit'} = $newlimit;
9283: }
9284: } elsif ($currlimit ne 'none') {
9285: if ($newcap =~ /^\d+$/) {
9286: if ($newcap ne $currcap) {
9287: $changes{'internal.selfenroll_cap'} = $newcap;
9288: }
9289: } else {
1.398 raeburn 9290: $warning{$item} = &mt('Maximum enrollment setting unchanged.').'<br />'.
9291: &mt('The value provided was invalid - it must be a positive integer if enrollment is being limited.');
1.276 raeburn 9292: }
9293: }
9294: } elsif ($item eq 'approval') {
9295: my (@currnotified,@newnotified);
1.398 raeburn 9296: my $currapproval = $currsettings->{'selfenroll_approval'};
9297: my $currnotifylist = $currsettings->{'selfenroll_notifylist'};
1.276 raeburn 9298: if ($currnotifylist ne '') {
9299: @currnotified = split(/,/,$currnotifylist);
9300: @currnotified = sort(@currnotified);
9301: }
9302: my $newapproval = $env{'form.selfenroll_approval'};
9303: @newnotified = &Apache::loncommon::get_env_multiple('form.selfenroll_notify');
9304: @newnotified = sort(@newnotified);
9305: if ($newapproval ne $currapproval) {
9306: $changes{'internal.selfenroll_approval'} = $newapproval;
9307: if (!$newapproval) {
9308: if ($currnotifylist ne '') {
9309: $changes{'internal.selfenroll_notifylist'} = '';
9310: }
9311: } else {
9312: my @differences =
1.295 raeburn 9313: &Apache::loncommon::compare_arrays(\@currnotified,\@newnotified);
1.276 raeburn 9314: if (@differences > 0) {
9315: if (@newnotified > 0) {
9316: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
9317: } else {
9318: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
9319: }
9320: }
9321: }
9322: } else {
1.295 raeburn 9323: my @differences = &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'} = '';
9329: }
9330: }
9331: }
1.237 raeburn 9332: } else {
1.398 raeburn 9333: my $curr_val = $currsettings->{'selfenroll_'.$item};
1.237 raeburn 9334: my $newval = $env{'form.selfenroll_'.$item};
9335: if ($item eq 'section') {
9336: $newval = $env{'form.sections'};
1.241 raeburn 9337: if (defined($curr_groups{$newval})) {
1.237 raeburn 9338: $newval = $curr_val;
1.398 raeburn 9339: $warning{$item} = &mt('Section for self-enrolled users unchanged as the proposed section is a group').'<br />'.
9340: &mt('Group names and section names must be distinct');
1.237 raeburn 9341: } elsif ($newval eq 'all') {
9342: $newval = $curr_val;
1.274 bisitz 9343: $warning{$item} = &mt('Section for self-enrolled users unchanged, as "all" is a reserved section name.');
1.237 raeburn 9344: }
9345: if ($newval eq '') {
9346: $newval = 'none';
9347: }
9348: }
9349: if ($newval ne $curr_val) {
9350: $changes{'internal.selfenroll_'.$item} = $newval;
9351: }
1.241 raeburn 9352: }
1.237 raeburn 9353: }
9354: if (keys(%warning) > 0) {
9355: foreach my $item (@{$row}) {
9356: if (exists($warning{$item})) {
9357: $r->print($warning{$item}.'<br />');
9358: }
9359: }
9360: }
9361: if (keys(%changes) > 0) {
9362: my $putresult = &Apache::lonnet::put('environment',\%changes,$cdom,$cnum);
9363: if ($putresult eq 'ok') {
9364: if ((exists($changes{'internal.selfenroll_types'})) ||
9365: (exists($changes{'internal.selfenroll_start_date'})) ||
9366: (exists($changes{'internal.selfenroll_end_date'}))) {
9367: my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',
9368: $cnum,undef,undef,'Course');
9369: my $chome = &Apache::lonnet::homeserver($cnum,$cdom);
1.398 raeburn 9370: if (ref($crsinfo{$cid}) eq 'HASH') {
1.237 raeburn 9371: foreach my $item ('selfenroll_types','selfenroll_start_date','selfenroll_end_date') {
9372: if (exists($changes{'internal.'.$item})) {
1.398 raeburn 9373: $crsinfo{$cid}{$item} = $changes{'internal.'.$item};
1.237 raeburn 9374: }
9375: }
9376: my $crsputresult =
9377: &Apache::lonnet::courseidput($cdom,\%crsinfo,
9378: $chome,'notime');
9379: }
9380: }
9381: $r->print(&mt('The following changes were made to self-enrollment settings:').'<ul>');
9382: foreach my $item (@{$row}) {
9383: my $title = $item;
9384: if (ref($lt) eq 'HASH') {
9385: $title = $lt->{$item};
9386: }
9387: if ($item eq 'enroll_dates') {
9388: foreach my $type ('start','end') {
9389: if (exists($changes{'internal.selfenroll_'.$type.'_date'})) {
9390: my $newdate = &Apache::lonlocal::locallocaltime($changes{'internal.selfenroll_'.$type.'_date'});
1.244 bisitz 9391: $r->print('<li>'.&mt('[_1]: "[_2]" set to "[_3]".',
1.237 raeburn 9392: $title,$type,$newdate).'</li>');
9393: }
9394: }
9395: } elsif ($item eq 'access_dates') {
9396: foreach my $type ('start','end') {
9397: if (exists($changes{'internal.selfenroll_'.$type.'_access'})) {
9398: my $newdate = &Apache::lonlocal::locallocaltime($changes{'internal.selfenroll_'.$type.'_access'});
1.244 bisitz 9399: $r->print('<li>'.&mt('[_1]: "[_2]" set to "[_3]".',
1.237 raeburn 9400: $title,$type,$newdate).'</li>');
9401: }
9402: }
1.276 raeburn 9403: } elsif ($item eq 'limit') {
9404: if ((exists($changes{'internal.selfenroll_limit'})) ||
9405: (exists($changes{'internal.selfenroll_cap'}))) {
9406: my ($newval,$newcap);
9407: if ($changes{'internal.selfenroll_cap'} ne '') {
9408: $newcap = $changes{'internal.selfenroll_cap'}
9409: } else {
1.398 raeburn 9410: $newcap = $currsettings->{'selfenroll_cap'};
1.276 raeburn 9411: }
9412: if ($changes{'internal.selfenroll_limit'} eq 'none') {
9413: $newval = &mt('No limit');
9414: } elsif ($changes{'internal.selfenroll_limit'} eq
9415: 'allstudents') {
9416: $newval = &mt('New self-enrollment no longer allowed when total (all students) reaches [_1].',$newcap);
9417: } elsif ($changes{'internal.selfenroll_limit'} eq 'selfenrolled') {
9418: $newval = &mt('New self-enrollment no longer allowed when total number of self-enrolled students reaches [_1].',$newcap);
9419: } else {
1.398 raeburn 9420: my $currlimit = $currsettings->{'selfenroll_limit'};
1.276 raeburn 9421: if ($currlimit eq 'allstudents') {
9422: $newval = &mt('New self-enrollment no longer allowed when total (all students) reaches [_1].',$newcap);
9423: } elsif ($changes{'internal.selfenroll_limit'} eq 'selfenrolled') {
1.308 raeburn 9424: $newval = &mt('New self-enrollment no longer allowed when total number of self-enrolled students reaches [_1].',$newcap);
1.276 raeburn 9425: }
9426: }
9427: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval).'</li>'."\n");
9428: }
9429: } elsif ($item eq 'approval') {
9430: if ((exists($changes{'internal.selfenroll_approval'})) ||
9431: (exists($changes{'internal.selfenroll_notifylist'}))) {
1.398 raeburn 9432: my %selfdescs = &Apache::lonuserutils::selfenroll_default_descs();
1.276 raeburn 9433: my ($newval,$newnotify);
9434: if (exists($changes{'internal.selfenroll_notifylist'})) {
9435: $newnotify = $changes{'internal.selfenroll_notifylist'};
9436: } else {
1.398 raeburn 9437: $newnotify = $currsettings->{'selfenroll_notifylist'};
1.276 raeburn 9438: }
1.398 raeburn 9439: if (exists($changes{'internal.selfenroll_approval'})) {
9440: if ($changes{'internal.selfenroll_approval'} !~ /^[012]$/) {
9441: $changes{'internal.selfenroll_approval'} = '0';
9442: }
9443: $newval = $selfdescs{'approval'}{$changes{'internal.selfenroll_approval'}};
1.276 raeburn 9444: } else {
1.398 raeburn 9445: my $currapproval = $currsettings->{'selfenroll_approval'};
9446: if ($currapproval !~ /^[012]$/) {
9447: $currapproval = 0;
1.276 raeburn 9448: }
1.398 raeburn 9449: $newval = $selfdescs{'approval'}{$currapproval};
1.276 raeburn 9450: }
9451: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval));
9452: if ($newnotify) {
1.277 raeburn 9453: $r->print('<br />'.&mt('The following will be notified when an enrollment request needs approval, or has been approved: [_1].',$newnotify));
1.276 raeburn 9454: } else {
1.277 raeburn 9455: $r->print('<br />'.&mt('No notifications sent when an enrollment request needs approval, or has been approved.'));
1.276 raeburn 9456: }
9457: $r->print('</li>'."\n");
9458: }
1.237 raeburn 9459: } else {
9460: if (exists($changes{'internal.selfenroll_'.$item})) {
1.241 raeburn 9461: my $newval = $changes{'internal.selfenroll_'.$item};
9462: if ($item eq 'types') {
9463: if ($newval eq '') {
9464: $newval = &mt('None');
9465: } elsif ($newval eq '*') {
9466: $newval = &mt('Any user in any domain');
9467: }
1.245 raeburn 9468: } elsif ($item eq 'registered') {
9469: if ($newval eq '1') {
9470: $newval = &mt('Yes');
9471: } elsif ($newval eq '0') {
9472: $newval = &mt('No');
9473: }
1.241 raeburn 9474: }
1.244 bisitz 9475: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval).'</li>'."\n");
1.237 raeburn 9476: }
9477: }
9478: }
9479: $r->print('</ul>');
1.398 raeburn 9480: if ($env{'course.'.$cid.'.description'} ne '') {
9481: my %newenvhash;
9482: foreach my $key (keys(%changes)) {
9483: $newenvhash{'course.'.$cid.'.'.$key} = $changes{$key};
9484: }
9485: &Apache::lonnet::appenv(\%newenvhash);
1.237 raeburn 9486: }
9487: } else {
1.398 raeburn 9488: $r->print(&mt('An error occurred when saving changes to self-enrollment settings in this course.').'<br />'.
9489: &mt('The error was: [_1].',$putresult));
1.237 raeburn 9490: }
9491: } else {
1.249 raeburn 9492: $r->print(&mt('No changes were made to the existing self-enrollment settings in this course.'));
1.237 raeburn 9493: }
9494: } else {
1.249 raeburn 9495: $r->print(&mt('No changes were made to the existing self-enrollment settings in this course.'));
1.241 raeburn 9496: }
1.400 raeburn 9497: my $visactions = &cat_visibility();
9498: my ($cathash,%cattype);
9499: my %domconfig = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom);
9500: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
9501: $cathash = $domconfig{'coursecategories'}{'cats'};
9502: $cattype{'auth'} = $domconfig{'coursecategories'}{'auth'};
9503: $cattype{'unauth'} = $domconfig{'coursecategories'}{'unauth'};
9504: } else {
9505: $cathash = {};
9506: $cattype{'auth'} = 'std';
9507: $cattype{'unauth'} = 'std';
9508: }
9509: if (($cattype{'auth'} eq 'none') && ($cattype{'unauth'} eq 'none')) {
9510: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
9511: '<br />'.
9512: '<br />'.$visactions->{'take'}.'<ul>'.
9513: '<li>'.$visactions->{'dc_chgconf'}.'</li>'.
9514: '</ul>');
9515: } elsif (($cattype{'auth'} !~ /^(std|domonly)$/) && ($cattype{'unauth'} !~ /^(std|domonly)$/)) {
9516: if ($currsettings->{'uniquecode'}) {
9517: $r->print('<span class="LC_info">'.$visactions->{'vis'}.'</span>');
9518: } else {
1.366 bisitz 9519: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
1.400 raeburn 9520: '<br />'.
9521: '<br />'.$visactions->{'take'}.'<ul>'.
9522: '<li>'.$visactions->{'dc_setcode'}.'</li>'.
9523: '</ul><br />');
9524: }
9525: } else {
9526: my ($visible,$cansetvis,$vismsgs) = &visible_in_stdcat($cdom,$cnum,\%domconfig);
9527: if (ref($visactions) eq 'HASH') {
9528: if (!$visible) {
9529: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
9530: '<br />');
9531: if (ref($vismsgs) eq 'ARRAY') {
9532: $r->print('<br />'.$visactions->{'take'}.'<ul>');
9533: foreach my $item (@{$vismsgs}) {
9534: $r->print('<li>'.$visactions->{$item}.'</li>');
9535: }
9536: $r->print('</ul>');
1.256 raeburn 9537: }
1.400 raeburn 9538: $r->print($cansetvis);
1.256 raeburn 9539: }
9540: }
9541: }
1.237 raeburn 9542: return;
9543: }
9544:
1.27 matthew 9545: #---------------------------------------------- end functions for &phase_two
1.29 matthew 9546:
9547: #--------------------------------- functions for &phase_two and &phase_three
9548:
9549: #--------------------------end of functions for &phase_two and &phase_three
1.372 raeburn 9550:
1.1 www 9551: 1;
9552: __END__
1.2 www 9553:
9554:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>