Annotation of loncom/interface/loncreateuser.pm, revision 1.448
1.20 harris41 1: # The LearningOnline Network with CAPA
1.1 www 2: # Create a user
3: #
1.448 ! raeburn 4: # $Id: loncreateuser.pm,v 1.447 2017/11/04 20:23:23 raeburn Exp $
1.22 albertel 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
1.20 harris41 28: ###
29:
1.1 www 30: package Apache::loncreateuser;
1.66 bowersj2 31:
32: =pod
33:
34: =head1 NAME
35:
1.263 jms 36: Apache::loncreateuser.pm
1.66 bowersj2 37:
38: =head1 SYNOPSIS
39:
1.263 jms 40: Handler to create users and custom roles
41:
42: Provides an Apache handler for creating users,
1.66 bowersj2 43: editing their login parameters, roles, and removing roles, and
44: also creating and assigning custom roles.
45:
46: =head1 OVERVIEW
47:
48: =head2 Custom Roles
49:
50: In LON-CAPA, roles are actually collections of privileges. "Teaching
51: Assistant", "Course Coordinator", and other such roles are really just
52: collection of privileges that are useful in many circumstances.
53:
1.324 raeburn 54: Custom roles can be defined by a Domain Coordinator, Course Coordinator
55: or Community Coordinator via the Manage User functionality.
56: The custom role editor screen will show all privileges which can be
57: assigned to users. For a complete list of privileges, please see
58: C</home/httpd/lonTabs/rolesplain.tab>.
1.66 bowersj2 59:
1.324 raeburn 60: Custom role definitions are stored in the C<roles.db> file of the creator
61: of the role.
1.66 bowersj2 62:
63: =cut
1.1 www 64:
65: use strict;
66: use Apache::Constants qw(:common :http);
67: use Apache::lonnet;
1.54 bowersj2 68: use Apache::loncommon;
1.68 www 69: use Apache::lonlocal;
1.117 raeburn 70: use Apache::longroup;
1.190 raeburn 71: use Apache::lonuserutils;
1.307 raeburn 72: use Apache::loncoursequeueadmin;
1.139 albertel 73: use LONCAPA qw(:DEFAULT :match);
1.1 www 74:
1.20 harris41 75: my $loginscript; # piece of javascript used in two separate instances
76: my $authformnop;
77: my $authformkrb;
78: my $authformint;
79: my $authformfsys;
80: my $authformloc;
81:
1.94 matthew 82: sub initialize_authen_forms {
1.227 raeburn 83: my ($dom,$formname,$curr_authtype,$mode) = @_;
84: my ($krbdef,$krbdefdom) = &Apache::loncommon::get_kerberos_defaults($dom);
85: my %param = ( formname => $formname,
1.187 raeburn 86: kerb_def_dom => $krbdefdom,
1.227 raeburn 87: kerb_def_auth => $krbdef,
1.187 raeburn 88: domain => $dom,
89: );
1.188 raeburn 90: my %abv_auth = &auth_abbrev();
1.227 raeburn 91: if ($curr_authtype =~ /^(krb4|krb5|internal|localauth|unix):(.*)$/) {
1.188 raeburn 92: my $long_auth = $1;
1.227 raeburn 93: my $curr_autharg = $2;
1.188 raeburn 94: my %abv_auth = &auth_abbrev();
95: $param{'curr_authtype'} = $abv_auth{$long_auth};
96: if ($long_auth =~ /^krb(4|5)$/) {
97: $param{'curr_kerb_ver'} = $1;
1.227 raeburn 98: $param{'curr_autharg'} = $curr_autharg;
1.188 raeburn 99: }
1.205 raeburn 100: if ($mode eq 'modifyuser') {
101: $param{'mode'} = $mode;
102: }
1.187 raeburn 103: }
1.227 raeburn 104: $loginscript = &Apache::loncommon::authform_header(%param);
105: $authformkrb = &Apache::loncommon::authform_kerberos(%param);
1.31 matthew 106: $authformnop = &Apache::loncommon::authform_nochange(%param);
107: $authformint = &Apache::loncommon::authform_internal(%param);
108: $authformfsys = &Apache::loncommon::authform_filesystem(%param);
109: $authformloc = &Apache::loncommon::authform_local(%param);
1.20 harris41 110: }
111:
1.188 raeburn 112: sub auth_abbrev {
113: my %abv_auth = (
1.368 raeburn 114: krb5 => 'krb',
115: krb4 => 'krb',
116: internal => 'int',
117: localauth => 'loc',
118: unix => 'fsys',
1.188 raeburn 119: );
120: return %abv_auth;
121: }
1.43 www 122:
1.134 raeburn 123: # ====================================================
124:
1.378 raeburn 125: sub user_quotas {
1.134 raeburn 126: my ($ccuname,$ccdomain) = @_;
127: my %lt = &Apache::lonlocal::texthash(
1.267 raeburn 128: 'usrt' => "User Tools",
129: 'cust' => "Custom quota",
130: 'chqu' => "Change quota",
1.134 raeburn 131: );
1.378 raeburn 132:
1.149 raeburn 133: my $quota_javascript = <<"END_SCRIPT";
134: <script type="text/javascript">
1.301 bisitz 135: // <![CDATA[
1.378 raeburn 136: function quota_changes(caller,context) {
137: var customoff = document.getElementById('custom_'+context+'quota_off');
138: var customon = document.getElementById('custom_'+context+'quota_on');
139: var number = document.getElementById(context+'quota');
1.149 raeburn 140: if (caller == "custom") {
1.378 raeburn 141: if (customoff) {
142: if (customoff.checked) {
143: number.value = "";
144: }
1.149 raeburn 145: }
146: }
147: if (caller == "quota") {
1.378 raeburn 148: if (customon) {
149: customon.checked = true;
150: }
1.149 raeburn 151: }
1.378 raeburn 152: return;
1.149 raeburn 153: }
1.301 bisitz 154: // ]]>
1.149 raeburn 155: </script>
156: END_SCRIPT
1.378 raeburn 157: my $longinsttype;
158: my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($ccdomain);
1.267 raeburn 159: my $output = $quota_javascript."\n".
160: '<h3>'.$lt{'usrt'}.'</h3>'."\n".
161: &Apache::loncommon::start_data_table();
162:
1.418 raeburn 163: if ((&Apache::lonnet::allowed('mut',$ccdomain)) ||
164: (&Apache::lonnet::allowed('udp',$ccdomain))) {
1.275 raeburn 165: $output .= &build_tools_display($ccuname,$ccdomain,'tools');
1.267 raeburn 166: }
1.378 raeburn 167:
168: my %titles = &Apache::lonlocal::texthash (
169: portfolio => "Disk space allocated to user's portfolio files",
1.385 bisitz 170: author => "Disk space allocated to user's Authoring Space (if role assigned)",
1.378 raeburn 171: );
172: foreach my $name ('portfolio','author') {
173: my ($currquota,$quotatype,$inststatus,$defquota) =
174: &Apache::loncommon::get_user_quota($ccuname,$ccdomain,$name);
175: if ($longinsttype eq '') {
176: if ($inststatus ne '') {
177: if ($usertypes->{$inststatus} ne '') {
178: $longinsttype = $usertypes->{$inststatus};
179: }
180: }
181: }
182: my ($showquota,$custom_on,$custom_off,$defaultinfo);
183: $custom_on = ' ';
184: $custom_off = ' checked="checked" ';
185: if ($quotatype eq 'custom') {
186: $custom_on = $custom_off;
187: $custom_off = ' ';
188: $showquota = $currquota;
189: if ($longinsttype eq '') {
190: $defaultinfo = &mt('For this user, the default quota would be [_1]'
1.383 raeburn 191: .' MB.',$defquota);
1.378 raeburn 192: } else {
193: $defaultinfo = &mt("For this user, the default quota would be [_1]".
1.383 raeburn 194: " MB, as determined by the user's institutional".
1.378 raeburn 195: " affiliation ([_2]).",$defquota,$longinsttype);
196: }
197: } else {
198: if ($longinsttype eq '') {
199: $defaultinfo = &mt('For this user, the default quota is [_1]'
1.383 raeburn 200: .' MB.',$defquota);
1.378 raeburn 201: } else {
202: $defaultinfo = &mt("For this user, the default quota of [_1]".
1.383 raeburn 203: " MB, is determined by the user's institutional".
1.378 raeburn 204: " affiliation ([_2]).",$defquota,$longinsttype);
205: }
206: }
207:
208: if (&Apache::lonnet::allowed('mpq',$ccdomain)) {
209: $output .= '<tr class="LC_info_row">'."\n".
210: ' <td>'.$titles{$name}.'</td>'."\n".
211: ' </tr>'."\n".
212: &Apache::loncommon::start_data_table_row()."\n".
1.390 bisitz 213: ' <td><span class="LC_nobreak">'.
214: &mt('Current quota: [_1] MB',$currquota).'</span> '.
1.378 raeburn 215: $defaultinfo.'</td>'."\n".
216: &Apache::loncommon::end_data_table_row()."\n".
217: &Apache::loncommon::start_data_table_row()."\n".
218: ' <td><span class="LC_nobreak">'.$lt{'chqu'}.
219: ': <label>'.
220: '<input type="radio" name="custom_'.$name.'quota" id="custom_'.$name.'quota_off" '.
1.379 raeburn 221: 'value="0" '.$custom_off.' onchange="javascript:quota_changes('."'custom','$name'".');"'.
1.390 bisitz 222: ' /><span class="LC_nobreak">'.
223: &mt('Default ([_1] MB)',$defquota).'</span></label> '.
1.378 raeburn 224: ' <label><input type="radio" name="custom_'.$name.'quota" id="custom_'.$name.'quota_on" '.
1.379 raeburn 225: 'value="1" '.$custom_on.' onchange="javascript:quota_changes('."'custom','$name'".');"'.
1.378 raeburn 226: ' />'.$lt{'cust'}.':</label> '.
1.379 raeburn 227: '<input type="text" name="'.$name.'quota" id="'.$name.'quota" size ="5" '.
228: 'value="'.$showquota.'" onfocus="javascript:quota_changes('."'quota','$name'".');"'.
1.390 bisitz 229: ' /> '.&mt('MB').'</span></td>'."\n".
1.378 raeburn 230: &Apache::loncommon::end_data_table_row()."\n";
231: }
232: }
1.267 raeburn 233: $output .= &Apache::loncommon::end_data_table();
1.134 raeburn 234: return $output;
235: }
236:
1.275 raeburn 237: sub build_tools_display {
238: my ($ccuname,$ccdomain,$context) = @_;
1.306 raeburn 239: my (@usertools,%userenv,$output,@options,%validations,%reqtitles,%reqdisplay,
1.332 raeburn 240: $colspan,$isadv,%domconfig);
1.275 raeburn 241: my %lt = &Apache::lonlocal::texthash (
242: 'blog' => "Personal User Blog",
243: 'aboutme' => "Personal Information Page",
1.385 bisitz 244: 'webdav' => "WebDAV access to Authoring Spaces (if SSL and author/co-author)",
1.275 raeburn 245: 'portfolio' => "Personal User Portfolio",
246: 'avai' => "Available",
247: 'cusa' => "availability",
248: 'chse' => "Change setting",
249: 'usde' => "Use default",
250: 'uscu' => "Use custom",
251: 'official' => 'Can request creation of official courses',
1.299 raeburn 252: 'unofficial' => 'Can request creation of unofficial courses',
253: 'community' => 'Can request creation of communities',
1.384 raeburn 254: 'textbook' => 'Can request creation of textbook courses',
1.411 raeburn 255: 'placement' => 'Can request creation of placement tests',
1.362 raeburn 256: 'requestauthor' => 'Can request author space',
1.275 raeburn 257: );
1.279 raeburn 258: if ($context eq 'requestcourses') {
1.275 raeburn 259: %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
1.299 raeburn 260: 'requestcourses.official','requestcourses.unofficial',
1.411 raeburn 261: 'requestcourses.community','requestcourses.textbook',
262: 'requestcourses.placement');
263: @usertools = ('official','unofficial','community','textbook','placement');
1.309 raeburn 264: @options =('norequest','approval','autolimit','validate');
1.306 raeburn 265: %validations = &Apache::lonnet::auto_courserequest_checks($ccdomain);
266: %reqtitles = &courserequest_titles();
267: %reqdisplay = &courserequest_display();
268: $colspan = ' colspan="2"';
1.332 raeburn 269: %domconfig =
270: &Apache::lonnet::get_dom('configuration',['requestcourses'],$ccdomain);
1.418 raeburn 271: $isadv = &Apache::lonnet::is_advanced_user($ccdomain,$ccuname);
1.362 raeburn 272: } elsif ($context eq 'requestauthor') {
273: %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
274: 'requestauthor');
275: @usertools = ('requestauthor');
276: @options =('norequest','approval','automatic');
277: %reqtitles = &requestauthor_titles();
278: %reqdisplay = &requestauthor_display();
279: $colspan = ' colspan="2"';
280: %domconfig =
281: &Apache::lonnet::get_dom('configuration',['requestauthor'],$ccdomain);
1.275 raeburn 282: } else {
283: %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
1.361 raeburn 284: 'tools.aboutme','tools.portfolio','tools.blog',
285: 'tools.webdav');
286: @usertools = ('aboutme','blog','webdav','portfolio');
1.275 raeburn 287: }
288: foreach my $item (@usertools) {
1.306 raeburn 289: my ($custom_access,$curr_access,$cust_on,$cust_off,$tool_on,$tool_off,
290: $currdisp,$custdisp,$custradio);
1.275 raeburn 291: $cust_off = 'checked="checked" ';
292: $tool_on = 'checked="checked" ';
293: $curr_access =
294: &Apache::lonnet::usertools_access($ccuname,$ccdomain,$item,undef,
295: $context);
1.362 raeburn 296: if ($context eq 'requestauthor') {
297: if ($userenv{$context} ne '') {
298: $cust_on = ' checked="checked" ';
299: $cust_off = '';
300: }
301: } elsif ($userenv{$context.'.'.$item} ne '') {
1.306 raeburn 302: $cust_on = ' checked="checked" ';
303: $cust_off = '';
304: }
305: if ($context eq 'requestcourses') {
306: if ($userenv{$context.'.'.$item} eq '') {
1.314 raeburn 307: $custom_access = &mt('Currently from default setting.');
1.306 raeburn 308: } else {
309: $custom_access = &mt('Currently from custom setting.');
1.275 raeburn 310: }
1.362 raeburn 311: } elsif ($context eq 'requestauthor') {
312: if ($userenv{$context} eq '') {
313: $custom_access = &mt('Currently from default setting.');
314: } else {
315: $custom_access = &mt('Currently from custom setting.');
316: }
1.275 raeburn 317: } else {
1.306 raeburn 318: if ($userenv{$context.'.'.$item} eq '') {
1.314 raeburn 319: $custom_access =
1.306 raeburn 320: &mt('Availability determined currently from default setting.');
321: if (!$curr_access) {
322: $tool_off = 'checked="checked" ';
323: $tool_on = '';
324: }
325: } else {
1.314 raeburn 326: $custom_access =
1.306 raeburn 327: &mt('Availability determined currently from custom setting.');
328: if ($userenv{$context.'.'.$item} == 0) {
329: $tool_off = 'checked="checked" ';
330: $tool_on = '';
331: }
1.275 raeburn 332: }
333: }
334: $output .= ' <tr class="LC_info_row">'."\n".
1.306 raeburn 335: ' <td'.$colspan.'>'.$lt{$item}.'</td>'."\n".
1.275 raeburn 336: ' </tr>'."\n".
1.306 raeburn 337: &Apache::loncommon::start_data_table_row()."\n";
1.418 raeburn 338:
1.362 raeburn 339: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.306 raeburn 340: my ($curroption,$currlimit);
1.362 raeburn 341: my $envkey = $context.'.'.$item;
342: if ($context eq 'requestauthor') {
343: $envkey = $context;
344: }
345: if ($userenv{$envkey} ne '') {
346: $curroption = $userenv{$envkey};
1.332 raeburn 347: } else {
348: my (@inststatuses);
1.362 raeburn 349: if ($context eq 'requestcourses') {
350: $curroption =
351: &Apache::loncoursequeueadmin::get_processtype('course',$ccuname,$ccdomain,
352: $isadv,$ccdomain,$item,
353: \@inststatuses,\%domconfig);
354: } else {
355: $curroption =
356: &Apache::loncoursequeueadmin::get_processtype('requestauthor',$ccuname,$ccdomain,
357: $isadv,$ccdomain,undef,
358: \@inststatuses,\%domconfig);
359: }
1.332 raeburn 360: }
1.306 raeburn 361: if (!$curroption) {
362: $curroption = 'norequest';
363: }
364: if ($curroption =~ /^autolimit=(\d*)$/) {
365: $currlimit = $1;
1.314 raeburn 366: if ($currlimit eq '') {
367: $currdisp = &mt('Yes, automatic creation');
368: } else {
369: $currdisp = &mt('Yes, up to [quant,_1,request]/user',$currlimit);
370: }
1.306 raeburn 371: } else {
372: $currdisp = $reqdisplay{$curroption};
373: }
374: $custdisp = '<table>';
375: foreach my $option (@options) {
376: my $val = $option;
377: if ($option eq 'norequest') {
378: $val = 0;
379: }
380: if ($option eq 'validate') {
381: my $canvalidate = 0;
382: if (ref($validations{$item}) eq 'HASH') {
383: if ($validations{$item}{'_custom_'}) {
384: $canvalidate = 1;
385: }
386: }
387: next if (!$canvalidate);
388: }
389: my $checked = '';
390: if ($option eq $curroption) {
391: $checked = ' checked="checked"';
392: } elsif ($option eq 'autolimit') {
393: if ($curroption =~ /^autolimit/) {
394: $checked = ' checked="checked"';
395: }
396: }
1.362 raeburn 397: my $name = 'crsreq_'.$item;
398: if ($context eq 'requestauthor') {
399: $name = $item;
400: }
1.306 raeburn 401: $custdisp .= '<tr><td><span class="LC_nobreak"><label>'.
1.362 raeburn 402: '<input type="radio" name="'.$name.'" '.
403: 'value="'.$val.'"'.$checked.' />'.
1.306 raeburn 404: $reqtitles{$option}.'</label> ';
405: if ($option eq 'autolimit') {
1.362 raeburn 406: $custdisp .= '<input type="text" name="'.$name.
407: '_limit" size="1" '.
1.314 raeburn 408: 'value="'.$currlimit.'" /></span><br />'.
409: $reqtitles{'unlimited'};
1.362 raeburn 410: } else {
411: $custdisp .= '</span>';
412: }
413: $custdisp .= '</td></tr>';
1.306 raeburn 414: }
415: $custdisp .= '</table>';
416: $custradio = '</span></td><td>'.&mt('Custom setting').'<br />'.$custdisp;
417: } else {
418: $currdisp = ($curr_access?&mt('Yes'):&mt('No'));
1.362 raeburn 419: my $name = $context.'_'.$item;
420: if ($context eq 'requestauthor') {
421: $name = $context;
422: }
1.306 raeburn 423: $custdisp = '<span class="LC_nobreak"><label>'.
1.362 raeburn 424: '<input type="radio" name="'.$name.'"'.
1.361 raeburn 425: ' value="1" '.$tool_on.'/>'.&mt('On').'</label> <label>'.
1.362 raeburn 426: '<input type="radio" name="'.$name.'" value="0" '.
1.306 raeburn 427: $tool_off.'/>'.&mt('Off').'</label></span>';
428: $custradio = (' 'x2).'--'.$lt{'cusa'}.': '.$custdisp.
429: '</span>';
430: }
431: $output .= ' <td'.$colspan.'>'.$custom_access.(' 'x4).
1.419 raeburn 432: $lt{'avai'}.': '.$currdisp.'</td>'."\n".
1.418 raeburn 433: &Apache::loncommon::end_data_table_row()."\n";
434: unless (&Apache::lonnet::allowed('udp',$ccdomain)) {
435: $output .=
1.275 raeburn 436: &Apache::loncommon::start_data_table_row()."\n".
1.306 raeburn 437: ' <td style="vertical-align:top;"><span class="LC_nobreak">'.
438: $lt{'chse'}.': <label>'.
1.275 raeburn 439: '<input type="radio" name="custom'.$item.'" value="0" '.
1.306 raeburn 440: $cust_off.'/>'.$lt{'usde'}.'</label>'.(' ' x3).
441: '<label><input type="radio" name="custom'.$item.'" value="1" '.
442: $cust_on.'/>'.$lt{'uscu'}.'</label>'.$custradio.'</td>'.
1.275 raeburn 443: &Apache::loncommon::end_data_table_row()."\n";
1.418 raeburn 444: }
1.275 raeburn 445: }
446: return $output;
447: }
448:
1.300 raeburn 449: sub coursereq_externaluser {
450: my ($ccuname,$ccdomain,$cdom) = @_;
1.306 raeburn 451: my (@usertools,@options,%validations,%userenv,$output);
1.300 raeburn 452: my %lt = &Apache::lonlocal::texthash (
453: 'official' => 'Can request creation of official courses',
454: 'unofficial' => 'Can request creation of unofficial courses',
455: 'community' => 'Can request creation of communities',
1.384 raeburn 456: 'textbook' => 'Can request creation of textbook courses',
1.411 raeburn 457: 'placement' => 'Can request creation of placement tests',
1.300 raeburn 458: );
459:
460: %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
461: 'reqcrsotherdom.official','reqcrsotherdom.unofficial',
1.411 raeburn 462: 'reqcrsotherdom.community','reqcrsotherdom.textbook',
463: 'reqcrsotherdom.placement');
464: @usertools = ('official','unofficial','community','textbook','placement');
1.309 raeburn 465: @options = ('approval','validate','autolimit');
1.306 raeburn 466: %validations = &Apache::lonnet::auto_courserequest_checks($cdom);
467: my $optregex = join('|',@options);
468: my %reqtitles = &courserequest_titles();
1.300 raeburn 469: foreach my $item (@usertools) {
1.306 raeburn 470: my ($curroption,$currlimit,$tooloff);
1.300 raeburn 471: if ($userenv{'reqcrsotherdom.'.$item} ne '') {
472: my @curr = split(',',$userenv{'reqcrsotherdom.'.$item});
1.314 raeburn 473: foreach my $req (@curr) {
474: if ($req =~ /^\Q$cdom\E\:($optregex)=?(\d*)$/) {
475: $curroption = $1;
476: $currlimit = $2;
477: last;
1.306 raeburn 478: }
479: }
1.314 raeburn 480: if (!$curroption) {
481: $curroption = 'norequest';
482: $tooloff = ' checked="checked"';
483: }
1.306 raeburn 484: } else {
485: $curroption = 'norequest';
486: $tooloff = ' checked="checked"';
487: }
488: $output.= &Apache::loncommon::start_data_table_row()."\n".
1.314 raeburn 489: ' <td><span class="LC_nobreak">'.$lt{$item}.': </span></td><td>'.
490: '<table><tr><td valign="top">'."\n".
1.306 raeburn 491: '<label><input type="radio" name="reqcrsotherdom_'.$item.
1.314 raeburn 492: '" value=""'.$tooloff.' />'.$reqtitles{'norequest'}.
493: '</label></td>';
1.306 raeburn 494: foreach my $option (@options) {
495: if ($option eq 'validate') {
496: my $canvalidate = 0;
497: if (ref($validations{$item}) eq 'HASH') {
498: if ($validations{$item}{'_external_'}) {
499: $canvalidate = 1;
500: }
501: }
502: next if (!$canvalidate);
503: }
504: my $checked = '';
505: if ($option eq $curroption) {
506: $checked = ' checked="checked"';
507: }
1.314 raeburn 508: $output .= '<td valign="top"><span class="LC_nobreak"><label>'.
1.306 raeburn 509: '<input type="radio" name="reqcrsotherdom_'.$item.
510: '" value="'.$option.'"'.$checked.' />'.
1.314 raeburn 511: $reqtitles{$option}.'</label>';
1.306 raeburn 512: if ($option eq 'autolimit') {
1.314 raeburn 513: $output .= ' <input type="text" name="reqcrsotherdom_'.
1.306 raeburn 514: $item.'_limit" size="1" '.
1.314 raeburn 515: 'value="'.$currlimit.'" /></span>'.
516: '<br />'.$reqtitles{'unlimited'};
517: } else {
518: $output .= '</span>';
1.300 raeburn 519: }
1.314 raeburn 520: $output .= '</td>';
1.300 raeburn 521: }
1.314 raeburn 522: $output .= '</td></tr></table></td>'."\n".
1.300 raeburn 523: &Apache::loncommon::end_data_table_row()."\n";
524: }
525: return $output;
526: }
527:
1.362 raeburn 528: sub domainrole_req {
529: my ($ccuname,$ccdomain) = @_;
530: return '<br /><h3>'.
531: &mt('User Can Request Assignment of Domain Roles?').
532: '</h3>'."\n".
533: &Apache::loncommon::start_data_table().
534: &build_tools_display($ccuname,$ccdomain,
535: 'requestauthor').
536: &Apache::loncommon::end_data_table();
537: }
538:
1.306 raeburn 539: sub courserequest_titles {
540: my %titles = &Apache::lonlocal::texthash (
541: official => 'Official',
542: unofficial => 'Unofficial',
543: community => 'Communities',
1.384 raeburn 544: textbook => 'Textbook',
1.411 raeburn 545: placement => 'Placement Tests',
1.306 raeburn 546: norequest => 'Not allowed',
1.309 raeburn 547: approval => 'Approval by Dom. Coord.',
1.306 raeburn 548: validate => 'With validation',
549: autolimit => 'Numerical limit',
1.314 raeburn 550: unlimited => '(blank for unlimited)',
1.306 raeburn 551: );
552: return %titles;
553: }
554:
555: sub courserequest_display {
556: my %titles = &Apache::lonlocal::texthash (
1.309 raeburn 557: approval => 'Yes, need approval',
1.306 raeburn 558: validate => 'Yes, with validation',
559: norequest => 'No',
560: );
561: return %titles;
562: }
563:
1.362 raeburn 564: sub requestauthor_titles {
565: my %titles = &Apache::lonlocal::texthash (
566: norequest => 'Not allowed',
567: approval => 'Approval by Dom. Coord.',
568: automatic => 'Automatic approval',
569: );
570: return %titles;
571:
572: }
573:
574: sub requestauthor_display {
575: my %titles = &Apache::lonlocal::texthash (
576: approval => 'Yes, need approval',
577: automatic => 'Yes, automatic approval',
578: norequest => 'No',
579: );
580: return %titles;
581: }
582:
1.383 raeburn 583: sub requestchange_display {
584: my %titles = &Apache::lonlocal::texthash (
585: approval => "availability set to 'on' (approval required)",
586: automatic => "availability set to 'on' (automatic approval)",
587: norequest => "availability set to 'off'",
588: );
589: return %titles;
590: }
591:
1.362 raeburn 592: sub curr_requestauthor {
593: my ($uname,$udom,$isadv,$inststatuses,$domconfig) = @_;
594: return unless ((ref($inststatuses) eq 'ARRAY') && (ref($domconfig) eq 'HASH'));
595: if ($uname eq '' || $udom eq '') {
596: $uname = $env{'user.name'};
597: $udom = $env{'user.domain'};
598: $isadv = $env{'user.adv'};
599: }
600: my (%userenv,%settings,$val);
601: my @options = ('automatic','approval');
602: %userenv =
603: &Apache::lonnet::userenvironment($udom,$uname,'requestauthor','inststatus');
604: if ($userenv{'requestauthor'}) {
605: $val = $userenv{'requestauthor'};
606: @{$inststatuses} = ('_custom_');
607: } else {
608: my %alltasks;
609: if (ref($domconfig->{'requestauthor'}) eq 'HASH') {
610: %settings = %{$domconfig->{'requestauthor'}};
611: if (($isadv) && ($settings{'_LC_adv'} ne '')) {
612: $val = $settings{'_LC_adv'};
613: @{$inststatuses} = ('_LC_adv_');
614: } else {
615: if ($userenv{'inststatus'} ne '') {
616: @{$inststatuses} = split(',',$userenv{'inststatus'});
617: } else {
618: @{$inststatuses} = ('default');
619: }
620: foreach my $status (@{$inststatuses}) {
621: if (exists($settings{$status})) {
622: my $value = $settings{$status};
623: next unless ($value);
624: unless (exists($alltasks{$value})) {
625: if (ref($alltasks{$value}) eq 'ARRAY') {
626: unless(grep(/^\Q$status\E$/,@{$alltasks{$value}})) {
627: push(@{$alltasks{$value}},$status);
628: }
629: } else {
630: @{$alltasks{$value}} = ($status);
631: }
632: }
633: }
634: }
635: foreach my $option (@options) {
636: if ($alltasks{$option}) {
637: $val = $option;
638: last;
639: }
640: }
641: }
642: }
643: }
644: return $val;
645: }
646:
1.2 www 647: # =================================================================== Phase one
1.1 www 648:
1.42 matthew 649: sub print_username_entry_form {
1.439 raeburn 650: my ($r,$context,$response,$srch,$forcenewuser,$crstype,$brcrum,
651: $permission) = @_;
1.101 albertel 652: my $defdom=$env{'request.role.domain'};
1.160 raeburn 653: my $formtoset = 'crtuser';
654: if (exists($env{'form.startrolename'})) {
655: $formtoset = 'docustom';
656: $env{'form.rolename'} = $env{'form.startrolename'};
1.207 raeburn 657: } elsif ($env{'form.origform'} eq 'crtusername') {
658: $formtoset = $env{'form.origform'};
1.160 raeburn 659: }
660:
661: my ($jsback,$elements) = &crumb_utilities();
662:
663: my $jscript = &Apache::loncommon::studentbrowser_javascript()."\n".
1.165 albertel 664: '<script type="text/javascript">'."\n".
1.301 bisitz 665: '// <![CDATA['."\n".
666: &Apache::lonhtmlcommon::set_form_elements($elements->{$formtoset})."\n".
667: '// ]]>'."\n".
1.162 raeburn 668: '</script>'."\n";
1.160 raeburn 669:
1.324 raeburn 670: my %existingroles=&Apache::lonuserutils::my_custom_roles($crstype);
671: if (($env{'form.action'} eq 'custom') && (keys(%existingroles) > 0)
672: && (&Apache::lonnet::allowed('mcr','/'))) {
673: $jscript .= &customrole_javascript();
674: }
1.224 raeburn 675: my $helpitem = 'Course_Change_Privileges';
676: if ($env{'form.action'} eq 'custom') {
1.439 raeburn 677: if ($context eq 'course') {
678: $helpitem = 'Course_Editing_Custom_Roles';
679: } elsif ($context eq 'domain') {
680: $helpitem = 'Domain_Editing_Custom_Roles';
681: }
1.224 raeburn 682: } elsif ($env{'form.action'} eq 'singlestudent') {
683: $helpitem = 'Course_Add_Student';
1.416 raeburn 684: } elsif ($env{'form.action'} eq 'accesslogs') {
685: $helpitem = 'Domain_User_Access_Logs';
1.439 raeburn 686: } elsif ($context eq 'author') {
687: $helpitem = 'Author_Change_Privileges';
688: } elsif ($context eq 'domain') {
689: if ($permission->{'cusr'}) {
690: $helpitem = 'Domain_Change_Privileges';
691: } elsif ($permission->{'view'}) {
692: $helpitem = 'Domain_View_Privileges';
693: } else {
694: undef($helpitem);
695: }
1.224 raeburn 696: }
1.422 raeburn 697: my %breadcrumb_text = &singleuser_breadcrumb($crstype,$context,$defdom);
1.351 raeburn 698: if ($env{'form.action'} eq 'custom') {
699: push(@{$brcrum},
700: {href=>"javascript:backPage(document.crtuser)",
701: text=>"Pick custom role",
702: help => $helpitem,}
703: );
704: } else {
705: push (@{$brcrum},
706: {href => "javascript:backPage(document.crtuser)",
707: text => $breadcrumb_text{'search'},
708: help => $helpitem,
709: faq => 282,
710: bug => 'Instructor Interface',}
711: );
712: }
713: my %loaditems = (
714: 'onload' => "javascript:setFormElements(document.$formtoset)",
715: );
716: my $args = {bread_crumbs => $brcrum,
717: bread_crumbs_component => 'User Management',
718: add_entries => \%loaditems,};
719: $r->print(&Apache::loncommon::start_page('User Management',$jscript,$args));
720:
1.71 sakharuk 721: my %lt=&Apache::lonlocal::texthash(
1.229 raeburn 722: 'srst' => 'Search for a user and enroll as a student',
1.318 raeburn 723: 'srme' => 'Search for a user and enroll as a member',
1.229 raeburn 724: 'srad' => 'Search for a user and modify/add user information or roles',
1.422 raeburn 725: 'srvu' => 'Search for a user and view user information and roles',
1.416 raeburn 726: 'srva' => 'Search for a user and view access log information',
1.71 sakharuk 727: 'usr' => "Username",
728: 'dom' => "Domain",
1.324 raeburn 729: 'ecrp' => "Define or Edit Custom Role",
730: 'nr' => "role name",
1.282 schafran 731: 'cre' => "Next",
1.71 sakharuk 732: );
1.351 raeburn 733:
1.214 raeburn 734: if ($env{'form.action'} eq 'custom') {
1.190 raeburn 735: if (&Apache::lonnet::allowed('mcr','/')) {
1.324 raeburn 736: my $newroletext = &mt('Define new custom role:');
737: $r->print('<form action="/adm/createuser" method="post" name="docustom">'.
738: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'.
739: '<input type="hidden" name="phase" value="selected_custom_edit" />'.
740: '<h3>'.$lt{'ecrp'}.'</h3>'.
741: &Apache::loncommon::start_data_table().
742: &Apache::loncommon::start_data_table_row().
743: '<td>');
744: if (keys(%existingroles) > 0) {
745: $r->print('<br /><label><input type="radio" name="customroleaction" value="new" checked="checked" onclick="setCustomFields();" /><b>'.$newroletext.'</b></label>');
746: } else {
747: $r->print('<br /><input type="hidden" name="customroleaction" value="new" /><b>'.$newroletext.'</b>');
748: }
749: $r->print('</td><td align="center">'.$lt{'nr'}.'<br /><input type="text" size="15" name="newrolename" onfocus="setCustomAction('."'new'".');" /></td>'.
750: &Apache::loncommon::end_data_table_row());
751: if (keys(%existingroles) > 0) {
752: $r->print(&Apache::loncommon::start_data_table_row().'<td><br />'.
753: '<label><input type="radio" name="customroleaction" value="edit" onclick="setCustomFields();"/><b>'.
754: &mt('View/Modify existing role:').'</b></label></td>'.
755: '<td align="center"><br />'.
756: '<select name="rolename" onchange="setCustomAction('."'edit'".');">'.
1.326 raeburn 757: '<option value="" selected="selected">'.
1.324 raeburn 758: &mt('Select'));
759: foreach my $role (sort(keys(%existingroles))) {
1.326 raeburn 760: $r->print('<option value="'.$role.'">'.$role.'</option>');
1.324 raeburn 761: }
762: $r->print('</select>'.
763: '</td>'.
764: &Apache::loncommon::end_data_table_row());
765: }
766: $r->print(&Apache::loncommon::end_data_table().'<p>'.
767: '<input name="customeditor" type="submit" value="'.
768: $lt{'cre'}.'" /></p>'.
769: '</form>');
1.190 raeburn 770: }
1.213 raeburn 771: } else {
1.229 raeburn 772: my $actiontext = $lt{'srad'};
1.436 raeburn 773: my $fixeddom;
1.213 raeburn 774: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 775: if ($crstype eq 'Community') {
776: $actiontext = $lt{'srme'};
777: } else {
778: $actiontext = $lt{'srst'};
779: }
1.416 raeburn 780: } elsif ($env{'form.action'} eq 'accesslogs') {
1.417 raeburn 781: $actiontext = $lt{'srva'};
1.436 raeburn 782: $fixeddom = 1;
1.422 raeburn 783: } elsif (($env{'form.action'} eq 'singleuser') &&
784: ($context eq 'domain') && (!&Apache::lonnet::allowed('mau',$defdom))) {
785: $actiontext = $lt{'srvu'};
1.439 raeburn 786: $fixeddom = 1;
1.213 raeburn 787: }
1.324 raeburn 788: $r->print("<h3>$actiontext</h3>");
1.213 raeburn 789: if ($env{'form.origform'} ne 'crtusername') {
1.415 raeburn 790: if ($response) {
791: $r->print("\n<div>$response</div>".
792: '<br clear="all" />');
793: }
1.213 raeburn 794: }
1.436 raeburn 795: $r->print(&entry_form($defdom,$srch,$forcenewuser,$context,$response,$crstype,$fixeddom));
1.107 www 796: }
1.110 albertel 797: }
798:
1.324 raeburn 799: sub customrole_javascript {
800: my $js = <<"END";
801: <script type="text/javascript">
802: // <![CDATA[
803:
804: function setCustomFields() {
805: if (document.docustom.customroleaction.length > 0) {
806: for (var i=0; i<document.docustom.customroleaction.length; i++) {
807: if (document.docustom.customroleaction[i].checked) {
808: if (document.docustom.customroleaction[i].value == 'new') {
809: document.docustom.rolename.selectedIndex = 0;
810: } else {
811: document.docustom.newrolename.value = '';
812: }
813: }
814: }
815: }
816: return;
817: }
818:
819: function setCustomAction(caller) {
820: if (document.docustom.customroleaction.length > 0) {
821: for (var i=0; i<document.docustom.customroleaction.length; i++) {
822: if (document.docustom.customroleaction[i].value == caller) {
823: document.docustom.customroleaction[i].checked = true;
824: }
825: }
826: }
827: setCustomFields();
828: return;
829: }
830:
831: // ]]>
832: </script>
833: END
834: return $js;
835: }
836:
1.160 raeburn 837: sub entry_form {
1.416 raeburn 838: my ($dom,$srch,$forcenewuser,$context,$responsemsg,$crstype,$fixeddom) = @_;
1.229 raeburn 839: my ($usertype,$inexact);
1.214 raeburn 840: if (ref($srch) eq 'HASH') {
841: if (($srch->{'srchin'} eq 'dom') &&
842: ($srch->{'srchby'} eq 'uname') &&
843: ($srch->{'srchtype'} eq 'exact') &&
844: ($srch->{'srchdomain'} ne '') &&
845: ($srch->{'srchterm'} ne '')) {
1.353 raeburn 846: my (%curr_rules,%got_rules);
1.214 raeburn 847: my ($rules,$ruleorder) =
848: &Apache::lonnet::inst_userrules($srch->{'srchdomain'},'username');
1.353 raeburn 849: $usertype = &Apache::lonuserutils::check_usertype($srch->{'srchdomain'},$srch->{'srchterm'},$rules,\%curr_rules,\%got_rules);
1.229 raeburn 850: } else {
851: $inexact = 1;
1.214 raeburn 852: }
1.207 raeburn 853: }
1.438 raeburn 854: my ($cancreate,$noinstd);
855: if ($env{'form.action'} eq 'accesslogs') {
856: $noinstd = 1;
857: } else {
858: $cancreate =
859: &Apache::lonuserutils::can_create_user($dom,$context,$usertype);
860: }
1.412 raeburn 861: my ($userpicker,$cansearch) =
1.179 raeburn 862: &Apache::loncommon::user_picker($dom,$srch,$forcenewuser,
1.438 raeburn 863: 'document.crtuser',$cancreate,$usertype,$context,$fixeddom,$noinstd);
1.160 raeburn 864: my $srchbutton = &mt('Search');
1.229 raeburn 865: if ($env{'form.action'} eq 'singlestudent') {
866: $srchbutton = &mt('Search and Enroll');
1.416 raeburn 867: } elsif ($env{'form.action'} eq 'accesslogs') {
868: $srchbutton = &mt('Search');
1.229 raeburn 869: } elsif ($cancreate && $responsemsg ne '' && $inexact) {
870: $srchbutton = &mt('Search or Add New User');
871: }
1.412 raeburn 872: my $output;
873: if ($cansearch) {
874: $output = <<"ENDBLOCK";
1.160 raeburn 875: <form action="/adm/createuser" method="post" name="crtuser">
1.190 raeburn 876: <input type="hidden" name="action" value="$env{'form.action'}" />
1.160 raeburn 877: <input type="hidden" name="phase" value="get_user_info" />
878: $userpicker
1.179 raeburn 879: <input name="userrole" type="button" value="$srchbutton" onclick="javascript:validateEntry(document.crtuser)" />
1.160 raeburn 880: </form>
1.207 raeburn 881: ENDBLOCK
1.412 raeburn 882: } else {
883: $output = '<p>'.$userpicker.'</p>';
884: }
1.422 raeburn 885: if (($env{'form.phase'} eq '') && ($env{'form.action'} ne 'accesslogs') &&
1.430 raeburn 886: (!(($env{'form.action'} eq 'singleuser') && ($context eq 'domain') &&
1.422 raeburn 887: (!&Apache::lonnet::allowed('mau',$env{'request.role.domain'}))))) {
1.207 raeburn 888: my $defdom=$env{'request.role.domain'};
1.446 raeburn 889: my ($trusted,$untrusted);
1.444 raeburn 890: if ($context eq 'course') {
1.446 raeburn 891: ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('enroll',$defdom);
1.444 raeburn 892: } elsif ($context eq 'author') {
1.446 raeburn 893: ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('othcoau',$defdom);
1.444 raeburn 894: } elsif ($context eq 'domain') {
1.446 raeburn 895: ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('domroles',$defdom);
1.444 raeburn 896: }
1.446 raeburn 897: my $domform = &Apache::loncommon::select_dom_form($defdom,'srchdomain',undef,undef,undef,$trusted,$untrusted);
1.207 raeburn 898: my %lt=&Apache::lonlocal::texthash(
1.229 raeburn 899: 'enro' => 'Enroll one student',
1.318 raeburn 900: 'enrm' => 'Enroll one member',
1.229 raeburn 901: 'admo' => 'Add/modify a single user',
902: 'crea' => 'create new user if required',
903: 'uskn' => "username is known",
1.207 raeburn 904: 'crnu' => 'Create a new user',
905: 'usr' => 'Username',
906: 'dom' => 'in domain',
1.229 raeburn 907: 'enrl' => 'Enroll',
908: 'cram' => 'Create/Modify user',
1.207 raeburn 909: );
1.229 raeburn 910: my $sellink=&Apache::loncommon::selectstudent_link('crtusername','srchterm','srchdomain');
911: my ($title,$buttontext,$showresponse);
1.318 raeburn 912: if ($env{'form.action'} eq 'singlestudent') {
913: if ($crstype eq 'Community') {
914: $title = $lt{'enrm'};
915: } else {
916: $title = $lt{'enro'};
917: }
1.229 raeburn 918: $buttontext = $lt{'enrl'};
919: } else {
920: $title = $lt{'admo'};
921: $buttontext = $lt{'cram'};
922: }
923: if ($cancreate) {
924: $title .= ' <span class="LC_cusr_subheading">('.$lt{'crea'}.')</span>';
925: } else {
926: $title .= ' <span class="LC_cusr_subheading">('.$lt{'uskn'}.')</span>';
927: }
928: if ($env{'form.origform'} eq 'crtusername') {
929: $showresponse = $responsemsg;
930: }
1.207 raeburn 931: $output .= <<"ENDDOCUMENT";
1.229 raeburn 932: <br />
1.207 raeburn 933: <form action="/adm/createuser" method="post" name="crtusername">
934: <input type="hidden" name="action" value="$env{'form.action'}" />
935: <input type="hidden" name="phase" value="createnewuser" />
936: <input type="hidden" name="srchtype" value="exact" />
1.233 raeburn 937: <input type="hidden" name="srchby" value="uname" />
1.207 raeburn 938: <input type="hidden" name="srchin" value="dom" />
939: <input type="hidden" name="forcenewuser" value="1" />
940: <input type="hidden" name="origform" value="crtusername" />
1.229 raeburn 941: <h3>$title</h3>
942: $showresponse
1.207 raeburn 943: <table>
944: <tr>
945: <td>$lt{'usr'}:</td>
946: <td><input type="text" size="15" name="srchterm" /></td>
947: <td> $lt{'dom'}:</td><td>$domform</td>
1.229 raeburn 948: <td> $sellink </td>
949: <td> <input name="userrole" type="submit" value="$buttontext" /></td>
1.207 raeburn 950: </tr>
951: </table>
952: </form>
1.160 raeburn 953: ENDDOCUMENT
1.207 raeburn 954: }
1.160 raeburn 955: return $output;
956: }
1.110 albertel 957:
958: sub user_modification_js {
1.113 raeburn 959: my ($pjump_def,$dc_setcourse_code,$nondc_setsection_code,$groupslist)=@_;
960:
1.110 albertel 961: return <<END;
962: <script type="text/javascript" language="Javascript">
1.301 bisitz 963: // <![CDATA[
1.314 raeburn 964:
1.110 albertel 965: $pjump_def
966: $dc_setcourse_code
967:
968: function dateset() {
969: eval("document.cu."+document.cu.pres_marker.value+
970: ".value=document.cu.pres_value.value");
1.359 www 971: modalWindow.close();
1.110 albertel 972: }
973:
1.113 raeburn 974: $nondc_setsection_code
1.301 bisitz 975: // ]]>
1.110 albertel 976: </script>
977: END
1.2 www 978: }
979:
980: # =================================================================== Phase two
1.160 raeburn 981: sub print_user_selection_page {
1.351 raeburn 982: my ($r,$response,$srch,$srch_results,$srcharray,$context,$opener_elements,$crstype,$brcrum) = @_;
1.160 raeburn 983: my @fields = ('username','domain','lastname','firstname','permanentemail');
984: my $sortby = $env{'form.sortby'};
985:
986: if (!grep(/^\Q$sortby\E$/,@fields)) {
987: $sortby = 'lastname';
988: }
989:
990: my ($jsback,$elements) = &crumb_utilities();
991:
992: my $jscript = (<<ENDSCRIPT);
993: <script type="text/javascript">
1.301 bisitz 994: // <![CDATA[
1.160 raeburn 995: function pickuser(uname,udom) {
996: document.usersrchform.seluname.value=uname;
997: document.usersrchform.seludom.value=udom;
998: document.usersrchform.phase.value="userpicked";
999: document.usersrchform.submit();
1000: }
1001:
1002: $jsback
1.301 bisitz 1003: // ]]>
1.160 raeburn 1004: </script>
1005: ENDSCRIPT
1006:
1007: my %lt=&Apache::lonlocal::texthash(
1.179 raeburn 1008: 'usrch' => "User Search to add/modify roles",
1009: 'stusrch' => "User Search to enroll student",
1.318 raeburn 1010: 'memsrch' => "User Search to enroll member",
1.416 raeburn 1011: 'srcva' => "Search for a user and view access log information",
1.422 raeburn 1012: 'usrvu' => "User Search to view user roles",
1.179 raeburn 1013: 'usel' => "Select a user to add/modify roles",
1.422 raeburn 1014: 'suvr' => "Select a user to view roles",
1.318 raeburn 1015: 'stusel' => "Select a user to enroll as a student",
1016: 'memsel' => "Select a user to enroll as a member",
1.416 raeburn 1017: 'vacsel' => "Select a user to view access log",
1.160 raeburn 1018: 'username' => "username",
1019: 'domain' => "domain",
1020: 'lastname' => "last name",
1021: 'firstname' => "first name",
1022: 'permanentemail' => "permanent e-mail",
1023: );
1.302 raeburn 1024: if ($context eq 'requestcrs') {
1025: $r->print('<div>');
1026: } else {
1.422 raeburn 1027: my %breadcrumb_text = &singleuser_breadcrumb($crstype,$context,$srch->{'srchdomain'});
1.351 raeburn 1028: my $helpitem;
1029: if ($env{'form.action'} eq 'singleuser') {
1030: $helpitem = 'Course_Change_Privileges';
1031: } elsif ($env{'form.action'} eq 'singlestudent') {
1032: $helpitem = 'Course_Add_Student';
1.439 raeburn 1033: } elsif ($context eq 'author') {
1034: $helpitem = 'Author_Change_Privileges';
1035: } elsif ($context eq 'domain') {
1036: $helpitem = 'Domain_Change_Privileges';
1.351 raeburn 1037: }
1038: push (@{$brcrum},
1039: {href => "javascript:backPage(document.usersrchform,'','')",
1040: text => $breadcrumb_text{'search'},
1041: faq => 282,
1042: bug => 'Instructor Interface',},
1043: {href => "javascript:backPage(document.usersrchform,'get_user_info','select')",
1044: text => $breadcrumb_text{'userpicked'},
1045: faq => 282,
1046: bug => 'Instructor Interface',
1047: help => $helpitem}
1048: );
1049: $r->print(&Apache::loncommon::start_page('User Management',$jscript,{bread_crumbs => $brcrum}));
1.302 raeburn 1050: if ($env{'form.action'} eq 'singleuser') {
1.422 raeburn 1051: my $readonly;
1052: if (($context eq 'domain') && (!&Apache::lonnet::allowed('mau',$srch->{'srchdomain'}))) {
1053: $readonly = 1;
1054: $r->print("<b>$lt{'usrvu'}</b><br />");
1055: } else {
1056: $r->print("<b>$lt{'usrch'}</b><br />");
1057: }
1.318 raeburn 1058: $r->print(&entry_form($srch->{'srchdomain'},$srch,undef,$context,undef,$crstype));
1.422 raeburn 1059: if ($readonly) {
1060: $r->print('<h3>'.$lt{'suvr'}.'</h3>');
1061: } else {
1062: $r->print('<h3>'.$lt{'usel'}.'</h3>');
1063: }
1.302 raeburn 1064: } elsif ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1065: $r->print($jscript."<b>");
1066: if ($crstype eq 'Community') {
1067: $r->print($lt{'memsrch'});
1068: } else {
1069: $r->print($lt{'stusrch'});
1070: }
1071: $r->print("</b><br />");
1072: $r->print(&entry_form($srch->{'srchdomain'},$srch,undef,$context,undef,$crstype));
1073: $r->print('</form><h3>');
1074: if ($crstype eq 'Community') {
1075: $r->print($lt{'memsel'});
1076: } else {
1077: $r->print($lt{'stusel'});
1078: }
1079: $r->print('</h3>');
1.416 raeburn 1080: } elsif ($env{'form.action'} eq 'accesslogs') {
1081: $r->print("<b>$lt{'srcva'}</b><br />");
1.438 raeburn 1082: $r->print(&entry_form($srch->{'srchdomain'},$srch,undef,$context,undef,undef,1));
1.416 raeburn 1083: $r->print('<h3>'.$lt{'vacsel'}.'</h3>');
1.302 raeburn 1084: }
1.179 raeburn 1085: }
1.380 bisitz 1086: $r->print('<form name="usersrchform" method="post" action="">'.
1.160 raeburn 1087: &Apache::loncommon::start_data_table()."\n".
1088: &Apache::loncommon::start_data_table_header_row()."\n".
1089: ' <th> </th>'."\n");
1090: foreach my $field (@fields) {
1091: $r->print(' <th><a href="javascript:document.usersrchform.sortby.value='.
1092: "'".$field."'".';document.usersrchform.submit();">'.
1093: $lt{$field}.'</a></th>'."\n");
1094: }
1095: $r->print(&Apache::loncommon::end_data_table_header_row());
1096:
1097: my @sorted_users = sort {
1.167 albertel 1098: lc($srch_results->{$a}->{$sortby}) cmp lc($srch_results->{$b}->{$sortby})
1.160 raeburn 1099: ||
1.167 albertel 1100: lc($srch_results->{$a}->{lastname}) cmp lc($srch_results->{$b}->{lastname})
1.160 raeburn 1101: ||
1102: lc($srch_results->{$a}->{firstname}) cmp lc($srch_results->{$b}->{firstname})
1.167 albertel 1103: ||
1104: lc($a) cmp lc($b)
1.160 raeburn 1105: } (keys(%$srch_results));
1106:
1107: foreach my $user (@sorted_users) {
1108: my ($uname,$udom) = split(/:/,$user);
1.302 raeburn 1109: my $onclick;
1110: if ($context eq 'requestcrs') {
1.314 raeburn 1111: $onclick =
1.302 raeburn 1112: 'onclick="javascript:gochoose('."'$uname','$udom',".
1113: "'$srch_results->{$user}->{firstname}',".
1114: "'$srch_results->{$user}->{lastname}',".
1115: "'$srch_results->{$user}->{permanentemail}'".');"';
1116: } else {
1.314 raeburn 1117: $onclick =
1.302 raeburn 1118: ' onclick="javascript:pickuser('."'".$uname."'".','."'".$udom."'".');"';
1119: }
1.160 raeburn 1120: $r->print(&Apache::loncommon::start_data_table_row().
1.302 raeburn 1121: '<td><input type="button" name="seluser" value="'.&mt('Select').'" '.
1122: $onclick.' /></td>'.
1.160 raeburn 1123: '<td><tt>'.$uname.'</tt></td>'.
1124: '<td><tt>'.$udom.'</tt></td>');
1125: foreach my $field ('lastname','firstname','permanentemail') {
1126: $r->print('<td>'.$srch_results->{$user}->{$field}.'</td>');
1127: }
1128: $r->print(&Apache::loncommon::end_data_table_row());
1129: }
1130: $r->print(&Apache::loncommon::end_data_table().'<br /><br />');
1.179 raeburn 1131: if (ref($srcharray) eq 'ARRAY') {
1132: foreach my $item (@{$srcharray}) {
1133: $r->print('<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n");
1134: }
1135: }
1.160 raeburn 1136: $r->print(' <input type="hidden" name="sortby" value="'.$sortby.'" />'."\n".
1137: ' <input type="hidden" name="seluname" value="" />'."\n".
1138: ' <input type="hidden" name="seludom" value="" />'."\n".
1.179 raeburn 1139: ' <input type="hidden" name="currstate" value="select" />'."\n".
1.190 raeburn 1140: ' <input type="hidden" name="phase" value="get_user_info" />'."\n".
1.214 raeburn 1141: ' <input type="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n");
1.302 raeburn 1142: if ($context eq 'requestcrs') {
1143: $r->print($opener_elements.'</form></div>');
1144: } else {
1.351 raeburn 1145: $r->print($response.'</form>');
1.302 raeburn 1146: }
1.160 raeburn 1147: }
1148:
1149: sub print_user_query_page {
1.351 raeburn 1150: my ($r,$caller,$brcrum) = @_;
1.160 raeburn 1151: # FIXME - this is for a network-wide name search (similar to catalog search)
1152: # To use frames with similar behavior to catalog/portfolio search.
1153: # To be implemented.
1154: return;
1155: }
1156:
1.42 matthew 1157: sub print_user_modification_page {
1.375 raeburn 1158: my ($r,$ccuname,$ccdomain,$srch,$response,$context,$permission,$crstype,
1159: $brcrum,$showcredits) = @_;
1.185 raeburn 1160: if (($ccuname eq '') || ($ccdomain eq '')) {
1.215 raeburn 1161: my $usermsg = &mt('No username and/or domain provided.');
1162: $env{'form.phase'} = '';
1.439 raeburn 1163: &print_username_entry_form($r,$context,$usermsg,'','',$crstype,$brcrum,
1164: $permission);
1.58 www 1165: return;
1166: }
1.213 raeburn 1167: my ($form,$formname);
1168: if ($env{'form.action'} eq 'singlestudent') {
1169: $form = 'document.enrollstudent';
1170: $formname = 'enrollstudent';
1171: } else {
1172: $form = 'document.cu';
1173: $formname = 'cu';
1174: }
1.188 raeburn 1175: my %abv_auth = &auth_abbrev();
1.227 raeburn 1176: my (%rulematch,%inst_results,$newuser,%alerts,%curr_rules,%got_rules);
1.185 raeburn 1177: my $uhome=&Apache::lonnet::homeserver($ccuname,$ccdomain);
1178: if ($uhome eq 'no_host') {
1.215 raeburn 1179: my $usertype;
1180: my ($rules,$ruleorder) =
1181: &Apache::lonnet::inst_userrules($ccdomain,'username');
1182: $usertype =
1.353 raeburn 1183: &Apache::lonuserutils::check_usertype($ccdomain,$ccuname,$rules,
1.362 raeburn 1184: \%curr_rules,\%got_rules);
1.215 raeburn 1185: my $cancreate =
1186: &Apache::lonuserutils::can_create_user($ccdomain,$context,
1187: $usertype);
1188: if (!$cancreate) {
1.292 bisitz 1189: my $helplink = 'javascript:helpMenu('."'display'".')';
1.215 raeburn 1190: my %usertypetext = (
1191: official => 'institutional',
1192: unofficial => 'non-institutional',
1193: );
1194: my $response;
1195: if ($env{'form.origform'} eq 'crtusername') {
1.362 raeburn 1196: $response = '<span class="LC_warning">'.
1197: &mt('No match found for the username [_1] in LON-CAPA domain: [_2]',
1198: '<b>'.$ccuname.'</b>',$ccdomain).
1.215 raeburn 1199: '</span><br />';
1200: }
1.292 bisitz 1201: $response .= '<p class="LC_warning">'
1202: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
1.418 raeburn 1203: .' ';
1204: if ($context eq 'domain') {
1205: $response .= &mt('Please contact a [_1] for assistance.',
1206: &Apache::lonnet::plaintext('dc'));
1207: } else {
1208: $response .= &mt('Please contact the [_1]helpdesk[_2] for assistance.'
1209: ,'<a href="'.$helplink.'">','</a>');
1210: }
1211: $response .= '</p><br />';
1.215 raeburn 1212: $env{'form.phase'} = '';
1.439 raeburn 1213: &print_username_entry_form($r,$context,$response,undef,undef,$crstype,$brcrum,
1214: $permission);
1.215 raeburn 1215: return;
1216: }
1.188 raeburn 1217: $newuser = 1;
1.193 raeburn 1218: my $checkhash;
1219: my $checks = { 'username' => 1 };
1.196 raeburn 1220: $checkhash->{$ccuname.':'.$ccdomain} = { 'newuser' => $newuser };
1.193 raeburn 1221: &Apache::loncommon::user_rule_check($checkhash,$checks,
1.196 raeburn 1222: \%alerts,\%rulematch,\%inst_results,\%curr_rules,\%got_rules);
1223: if (ref($alerts{'username'}) eq 'HASH') {
1224: if (ref($alerts{'username'}{$ccdomain}) eq 'HASH') {
1225: my $domdesc =
1.193 raeburn 1226: &Apache::lonnet::domain($ccdomain,'description');
1.196 raeburn 1227: if ($alerts{'username'}{$ccdomain}{$ccuname}) {
1228: my $userchkmsg;
1229: if (ref($curr_rules{$ccdomain}) eq 'HASH') {
1230: $userchkmsg =
1231: &Apache::loncommon::instrule_disallow_msg('username',
1.193 raeburn 1232: $domdesc,1).
1233: &Apache::loncommon::user_rule_formats($ccdomain,
1234: $domdesc,$curr_rules{$ccdomain}{'username'},
1235: 'username');
1.196 raeburn 1236: }
1.215 raeburn 1237: $env{'form.phase'} = '';
1.439 raeburn 1238: &print_username_entry_form($r,$context,$userchkmsg,undef,undef,$crstype,$brcrum,
1239: $permission);
1.196 raeburn 1240: return;
1.215 raeburn 1241: }
1.193 raeburn 1242: }
1.185 raeburn 1243: }
1.187 raeburn 1244: } else {
1.188 raeburn 1245: $newuser = 0;
1.185 raeburn 1246: }
1.160 raeburn 1247: if ($response) {
1.215 raeburn 1248: $response = '<br />'.$response;
1.160 raeburn 1249: }
1.149 raeburn 1250:
1.52 matthew 1251: my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
1.88 raeburn 1252: my $dc_setcourse_code = '';
1.119 raeburn 1253: my $nondc_setsection_code = '';
1.112 albertel 1254: my %loaditem;
1.114 albertel 1255:
1.216 raeburn 1256: my $groupslist = &Apache::lonuserutils::get_groupslist();
1.88 raeburn 1257:
1.375 raeburn 1258: my $js = &validation_javascript($context,$ccdomain,$pjump_def,$crstype,
1.216 raeburn 1259: $groupslist,$newuser,$formname,\%loaditem);
1.422 raeburn 1260: my %breadcrumb_text = &singleuser_breadcrumb($crstype,$context,$ccdomain);
1.224 raeburn 1261: my $helpitem = 'Course_Change_Privileges';
1262: if ($env{'form.action'} eq 'singlestudent') {
1263: $helpitem = 'Course_Add_Student';
1.439 raeburn 1264: } elsif ($context eq 'author') {
1265: $helpitem = 'Author_Change_Privileges';
1266: } elsif ($context eq 'domain') {
1267: $helpitem = 'Domain_Change_Privileges';
1.224 raeburn 1268: }
1.351 raeburn 1269: push (@{$brcrum},
1270: {href => "javascript:backPage($form)",
1271: text => $breadcrumb_text{'search'},
1272: faq => 282,
1273: bug => 'Instructor Interface',});
1274: if ($env{'form.phase'} eq 'userpicked') {
1275: push(@{$brcrum},
1276: {href => "javascript:backPage($form,'get_user_info','select')",
1277: text => $breadcrumb_text{'userpicked'},
1278: faq => 282,
1279: bug => 'Instructor Interface',});
1280: }
1281: push(@{$brcrum},
1282: {href => "javascript:backPage($form,'$env{'form.phase'}','modify')",
1283: text => $breadcrumb_text{'modify'},
1284: faq => 282,
1285: bug => 'Instructor Interface',
1286: help => $helpitem});
1287: my $args = {'add_entries' => \%loaditem,
1288: 'bread_crumbs' => $brcrum,
1289: 'bread_crumbs_component' => 'User Management'};
1290: if ($env{'form.popup'}) {
1291: $args->{'no_nav_bar'} = 1;
1292: }
1293: my $start_page =
1294: &Apache::loncommon::start_page('User Management',$js,$args);
1.3 www 1295:
1.25 matthew 1296: my $forminfo =<<"ENDFORMINFO";
1.216 raeburn 1297: <form action="/adm/createuser" method="post" name="$formname">
1.190 raeburn 1298: <input type="hidden" name="phase" value="update_user_data" />
1.188 raeburn 1299: <input type="hidden" name="ccuname" value="$ccuname" />
1300: <input type="hidden" name="ccdomain" value="$ccdomain" />
1.157 albertel 1301: <input type="hidden" name="pres_value" value="" />
1302: <input type="hidden" name="pres_type" value="" />
1303: <input type="hidden" name="pres_marker" value="" />
1.25 matthew 1304: ENDFORMINFO
1.375 raeburn 1305: my (%inccourses,$roledom,$defaultcredits);
1.329 raeburn 1306: if ($context eq 'course') {
1307: $inccourses{$env{'request.course.id'}}=1;
1308: $roledom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1.375 raeburn 1309: if ($showcredits) {
1310: $defaultcredits = &Apache::lonuserutils::get_defaultcredits();
1311: }
1.329 raeburn 1312: } elsif ($context eq 'author') {
1313: $roledom = $env{'request.role.domain'};
1314: } elsif ($context eq 'domain') {
1315: foreach my $key (keys(%env)) {
1316: $roledom = $env{'request.role.domain'};
1317: if ($key=~/^user\.priv\.cm\.\/($roledom)\/($match_username)/) {
1318: $inccourses{$1.'_'.$2}=1;
1319: }
1320: }
1321: } else {
1322: foreach my $key (keys(%env)) {
1323: if ($key=~/^user\.priv\.cm\.\/($match_domain)\/($match_username)/) {
1324: $inccourses{$1.'_'.$2}=1;
1325: }
1.2 www 1326: }
1.24 matthew 1327: }
1.389 bisitz 1328: my $title = '';
1.216 raeburn 1329: if ($newuser) {
1.427 raeburn 1330: my ($portfolioform,$domroleform);
1.267 raeburn 1331: if ((&Apache::lonnet::allowed('mpq',$env{'request.role.domain'})) ||
1332: (&Apache::lonnet::allowed('mut',$env{'request.role.domain'}))) {
1333: # Current user has quota or user tools modification privileges
1.378 raeburn 1334: $portfolioform = '<br />'.&user_quotas($ccuname,$ccdomain);
1.134 raeburn 1335: }
1.383 raeburn 1336: if ((&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) &&
1337: ($ccdomain eq $env{'request.role.domain'})) {
1.362 raeburn 1338: $domroleform = '<br />'.&domainrole_req($ccuname,$ccdomain);
1339: }
1.227 raeburn 1340: &initialize_authen_forms($ccdomain,$formname);
1.188 raeburn 1341: my %lt=&Apache::lonlocal::texthash(
1342: 'lg' => 'Login Data',
1.190 raeburn 1343: 'hs' => "Home Server",
1.188 raeburn 1344: );
1.185 raeburn 1345: $r->print(<<ENDTITLE);
1.110 albertel 1346: $start_page
1.160 raeburn 1347: $response
1.25 matthew 1348: $forminfo
1.31 matthew 1349: <script type="text/javascript" language="Javascript">
1.301 bisitz 1350: // <![CDATA[
1.20 harris41 1351: $loginscript
1.301 bisitz 1352: // ]]>
1.31 matthew 1353: </script>
1.20 harris41 1354: <input type='hidden' name='makeuser' value='1' />
1.185 raeburn 1355: ENDTITLE
1.213 raeburn 1356: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1357: if ($crstype eq 'Community') {
1.389 bisitz 1358: $title = &mt('Create New User [_1] in domain [_2] as a member',
1359: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.318 raeburn 1360: } else {
1.389 bisitz 1361: $title = &mt('Create New User [_1] in domain [_2] as a student',
1362: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.318 raeburn 1363: }
1.389 bisitz 1364: } else {
1365: $title = &mt('Create New User [_1] in domain [_2]',
1366: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.213 raeburn 1367: }
1.389 bisitz 1368: $r->print('<h2>'.$title.'</h2>'."\n");
1369: $r->print('<div class="LC_left_float">');
1.393 raeburn 1370: $r->print(&personal_data_display($ccuname,$ccdomain,$newuser,$context,
1371: $inst_results{$ccuname.':'.$ccdomain}));
1372: # Option to disable student/employee ID conflict checking not offerred for new users.
1.187 raeburn 1373: my ($home_server_pick,$numlib) =
1374: &Apache::loncommon::home_server_form_item($ccdomain,'hserver',
1375: 'default','hide');
1376: if ($numlib > 1) {
1377: $r->print("
1.185 raeburn 1378: <br />
1.187 raeburn 1379: $lt{'hs'}: $home_server_pick
1380: <br />");
1381: } else {
1382: $r->print($home_server_pick);
1383: }
1.304 raeburn 1384: if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
1.362 raeburn 1385: $r->print('<br /><h3>'.
1386: &mt('User Can Request Creation of Courses/Communities in this Domain?').'</h3>'.
1.304 raeburn 1387: &Apache::loncommon::start_data_table().
1388: &build_tools_display($ccuname,$ccdomain,
1389: 'requestcourses').
1390: &Apache::loncommon::end_data_table());
1391: }
1.188 raeburn 1392: $r->print('</div>'."\n".'<div class="LC_left_float"><h3>'.
1393: $lt{'lg'}.'</h3>');
1.185 raeburn 1394: my ($fixedauth,$varauth,$authmsg);
1.193 raeburn 1395: if (ref($rulematch{$ccuname.':'.$ccdomain}) eq 'HASH') {
1396: my $matchedrule = $rulematch{$ccuname.':'.$ccdomain}{'username'};
1397: my ($rules,$ruleorder) =
1398: &Apache::lonnet::inst_userrules($ccdomain,'username');
1.185 raeburn 1399: if (ref($rules) eq 'HASH') {
1.193 raeburn 1400: if (ref($rules->{$matchedrule}) eq 'HASH') {
1401: my $authtype = $rules->{$matchedrule}{'authtype'};
1.185 raeburn 1402: if ($authtype !~ /^(krb4|krb5|int|fsys|loc)$/) {
1.190 raeburn 1403: $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1.275 raeburn 1404: } else {
1.193 raeburn 1405: my $authparm = $rules->{$matchedrule}{'authparm'};
1.273 raeburn 1406: $authmsg = $rules->{$matchedrule}{'authmsg'};
1.185 raeburn 1407: if ($authtype =~ /^krb(4|5)$/) {
1408: my $ver = $1;
1409: if ($authparm ne '') {
1410: $fixedauth = <<"KERB";
1411: <input type="hidden" name="login" value="krb" />
1412: <input type="hidden" name="krbver" value="$ver" />
1413: <input type="hidden" name="krbarg" value="$authparm" />
1414: KERB
1415: }
1416: } else {
1417: $fixedauth =
1418: '<input type="hidden" name="login" value="'.$authtype.'" />'."\n";
1.193 raeburn 1419: if ($rules->{$matchedrule}{'authparmfixed'}) {
1.185 raeburn 1420: $fixedauth .=
1421: '<input type="hidden" name="'.$authtype.'arg" value="'.$authparm.'" />'."\n";
1422: } else {
1.273 raeburn 1423: if ($authtype eq 'int') {
1424: $varauth = '<br />'.
1.301 bisitz 1425: &mt('[_1] Internally authenticated (with initial password [_2])','','<input type="password" size="10" name="intarg" value="" />')."<label><input type=\"checkbox\" name=\"visible\" onclick='if (this.checked) { this.form.intarg.type=\"text\" } else { this.form.intarg.type=\"password\" }' />".&mt('Visible input').'</label>';
1.273 raeburn 1426: } elsif ($authtype eq 'loc') {
1427: $varauth = '<br />'.
1428: &mt('[_1] Local Authentication with argument [_2]','','<input type="text" name="'.$authtype.'arg" value="" />')."\n";
1429: } else {
1430: $varauth =
1.185 raeburn 1431: '<input type="text" name="'.$authtype.'arg" value="" />'."\n";
1.273 raeburn 1432: }
1.185 raeburn 1433: }
1434: }
1435: }
1436: } else {
1.190 raeburn 1437: $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1.185 raeburn 1438: }
1439: }
1440: if ($authmsg) {
1441: $r->print(<<ENDAUTH);
1442: $fixedauth
1443: $authmsg
1444: $varauth
1445: ENDAUTH
1446: }
1447: } else {
1.190 raeburn 1448: $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1.187 raeburn 1449: }
1.427 raeburn 1450: $r->print($portfolioform.$domroleform);
1.215 raeburn 1451: if ($env{'form.action'} eq 'singlestudent') {
1452: $r->print(&date_sections_select($context,$newuser,$formname,
1.375 raeburn 1453: $permission,$crstype,$ccuname,
1454: $ccdomain,$showcredits));
1.215 raeburn 1455: }
1456: $r->print('</div><div class="LC_clear_float_footer"></div>');
1.216 raeburn 1457: } else { # user already exists
1.389 bisitz 1458: $r->print($start_page.$forminfo);
1.213 raeburn 1459: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1460: if ($crstype eq 'Community') {
1.389 bisitz 1461: $title = &mt('Enroll one member: [_1] in domain [_2]',
1462: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.318 raeburn 1463: } else {
1.389 bisitz 1464: $title = &mt('Enroll one student: [_1] in domain [_2]',
1465: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.318 raeburn 1466: }
1.213 raeburn 1467: } else {
1.418 raeburn 1468: if ($permission->{'cusr'}) {
1469: $title = &mt('Modify existing user: [_1] in domain [_2]',
1470: '"'.$ccuname.'"','"'.$ccdomain.'"');
1471: } else {
1472: $title = &mt('Existing user: [_1] in domain [_2]',
1.389 bisitz 1473: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.418 raeburn 1474: }
1.213 raeburn 1475: }
1.389 bisitz 1476: $r->print('<h2>'.$title.'</h2>'."\n");
1477: $r->print('<div class="LC_left_float">');
1.393 raeburn 1478: $r->print(&personal_data_display($ccuname,$ccdomain,$newuser,$context,
1479: $inst_results{$ccuname.':'.$ccdomain}));
1.430 raeburn 1480: if ((&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) ||
1.418 raeburn 1481: (&Apache::lonnet::allowed('udp',$env{'request.role.domain'}))) {
1.362 raeburn 1482: $r->print('<br /><h3>'.&mt('User Can Request Creation of Courses/Communities in this Domain?').'</h3>'.
1.300 raeburn 1483: &Apache::loncommon::start_data_table());
1.314 raeburn 1484: if ($env{'request.role.domain'} eq $ccdomain) {
1.300 raeburn 1485: $r->print(&build_tools_display($ccuname,$ccdomain,'requestcourses'));
1486: } else {
1.444 raeburn 1487: if (&Apache::lonnet::will_trust('reqcrs',$ccdomain,$env{'request.role.domain'})) {
1488: $r->print(&coursereq_externaluser($ccuname,$ccdomain,
1489: $env{'request.role.domain'}));
1490: }
1.300 raeburn 1491: }
1492: $r->print(&Apache::loncommon::end_data_table());
1.275 raeburn 1493: }
1.199 raeburn 1494: $r->print('</div>');
1.427 raeburn 1495: my @order = ('auth','quota','tools','requestauthor');
1.362 raeburn 1496: my %user_text;
1497: my ($isadv,$isauthor) =
1.418 raeburn 1498: &Apache::lonnet::is_advanced_user($ccdomain,$ccuname);
1.362 raeburn 1499: if ((!$isauthor) &&
1.418 raeburn 1500: ((&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) ||
1501: (&Apache::lonnet::allowed('udp',$env{'request.role.domain'}))) &&
1.430 raeburn 1502: ($env{'request.role.domain'} eq $ccdomain)) {
1.362 raeburn 1503: $user_text{'requestauthor'} = &domainrole_req($ccuname,$ccdomain);
1504: }
1505: $user_text{'auth'} = &user_authentication($ccuname,$ccdomain,$formname);
1.267 raeburn 1506: if ((&Apache::lonnet::allowed('mpq',$ccdomain)) ||
1.418 raeburn 1507: (&Apache::lonnet::allowed('mut',$ccdomain)) ||
1508: (&Apache::lonnet::allowed('udp',$ccdomain))) {
1.188 raeburn 1509: # Current user has quota modification privileges
1.378 raeburn 1510: $user_text{'quota'} = &user_quotas($ccuname,$ccdomain);
1.267 raeburn 1511: }
1512: if (!&Apache::lonnet::allowed('mpq',$ccdomain)) {
1513: if (&Apache::lonnet::allowed('mpq',$env{'request.role.domain'})) {
1514: my %lt=&Apache::lonlocal::texthash(
1.385 bisitz 1515: 'dska' => "Disk quotas for user's portfolio and Authoring Space",
1516: 'youd' => "You do not have privileges to modify the portfolio and/or Authoring Space quotas for this user.",
1.267 raeburn 1517: 'ichr' => "If a change is required, contact a domain coordinator for the domain",
1518: );
1.362 raeburn 1519: $user_text{'quota'} = <<ENDNOPORTPRIV;
1.188 raeburn 1520: <h3>$lt{'dska'}</h3>
1521: $lt{'youd'} $lt{'ichr'}: $ccdomain
1522: ENDNOPORTPRIV
1.267 raeburn 1523: }
1524: }
1525: if (!&Apache::lonnet::allowed('mut',$ccdomain)) {
1526: if (&Apache::lonnet::allowed('mut',$env{'request.role.domain'})) {
1527: my %lt=&Apache::lonlocal::texthash(
1528: 'utav' => "User Tools Availability",
1.361 raeburn 1529: 'yodo' => "You do not have privileges to modify Portfolio, Blog, WebDAV, or Personal Information Page settings for this user.",
1.267 raeburn 1530: 'ifch' => "If a change is required, contact a domain coordinator for the domain",
1531: );
1.362 raeburn 1532: $user_text{'tools'} = <<ENDNOTOOLSPRIV;
1.267 raeburn 1533: <h3>$lt{'utav'}</h3>
1534: $lt{'yodo'} $lt{'ifch'}: $ccdomain
1535: ENDNOTOOLSPRIV
1536: }
1.188 raeburn 1537: }
1.362 raeburn 1538: my $gotdiv = 0;
1539: foreach my $item (@order) {
1540: if ($user_text{$item} ne '') {
1541: unless ($gotdiv) {
1542: $r->print('<div class="LC_left_float">');
1543: $gotdiv = 1;
1544: }
1545: $r->print('<br />'.$user_text{$item});
1546: }
1547: }
1548: if ($env{'form.action'} eq 'singlestudent') {
1549: unless ($gotdiv) {
1550: $r->print('<div class="LC_left_float">');
1.213 raeburn 1551: }
1.375 raeburn 1552: my $credits;
1553: if ($showcredits) {
1554: $credits = &get_user_credits($ccuname,$ccdomain,$defaultcredits);
1555: if ($credits eq '') {
1556: $credits = $defaultcredits;
1557: }
1558: }
1.374 raeburn 1559: $r->print(&date_sections_select($context,$newuser,$formname,
1.375 raeburn 1560: $permission,$crstype,$ccuname,
1561: $ccdomain,$showcredits));
1.374 raeburn 1562: }
1.362 raeburn 1563: if ($gotdiv) {
1564: $r->print('</div><div class="LC_clear_float_footer"></div>');
1.188 raeburn 1565: }
1.418 raeburn 1566: my $statuses;
1567: if (($context eq 'domain') && (&Apache::lonnet::allowed('udp',$ccdomain)) &&
1568: (!&Apache::lonnet::allowed('mau',$ccdomain))) {
1569: $statuses = ['active'];
1570: } elsif (($context eq 'course') && ((&Apache::lonnet::allowed('vcl',$env{'request.course.id'})) ||
1571: ($env{'request.course.sec'} &&
1572: &Apache::lonnet::allowed('vcl',$env{'request.course.id'}.'/'.$env{'request.course.sec'})))) {
1.430 raeburn 1573: $statuses = ['active'];
1.418 raeburn 1574: }
1.217 raeburn 1575: if ($env{'form.action'} ne 'singlestudent') {
1.329 raeburn 1576: &display_existing_roles($r,$ccuname,$ccdomain,\%inccourses,$context,
1.418 raeburn 1577: $roledom,$crstype,$showcredits,$statuses);
1.217 raeburn 1578: }
1.25 matthew 1579: } ## End of new user/old user logic
1.218 raeburn 1580: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1581: my $btntxt;
1582: if ($crstype eq 'Community') {
1583: $btntxt = &mt('Enroll Member');
1584: } else {
1585: $btntxt = &mt('Enroll Student');
1586: }
1587: $r->print('<br /><input type="button" value="'.$btntxt.'" onclick="setSections(this.form)" />'."\n");
1.418 raeburn 1588: } elsif ($permission->{'cusr'}) {
1.393 raeburn 1589: $r->print('<div class="LC_left_float">'.
1590: '<fieldset><legend>'.&mt('Add Roles').'</legend>');
1.218 raeburn 1591: my $addrolesdisplay = 0;
1592: if ($context eq 'domain' || $context eq 'author') {
1593: $addrolesdisplay = &new_coauthor_roles($r,$ccuname,$ccdomain);
1594: }
1595: if ($context eq 'domain') {
1.357 raeburn 1596: my $add_domainroles = &new_domain_roles($r,$ccdomain);
1.218 raeburn 1597: if (!$addrolesdisplay) {
1598: $addrolesdisplay = $add_domainroles;
1.2 www 1599: }
1.375 raeburn 1600: $r->print(&course_level_dc($env{'request.role.domain'},$showcredits));
1.393 raeburn 1601: $r->print('</fieldset></div><div class="LC_clear_float_footer"></div>'.
1602: '<br /><input type="button" value="'.&mt('Save').'" onclick="setCourse()" />'."\n");
1.218 raeburn 1603: } elsif ($context eq 'author') {
1604: if ($addrolesdisplay) {
1.393 raeburn 1605: $r->print('</fieldset></div><div class="LC_clear_float_footer"></div>'.
1606: '<br /><input type="button" value="'.&mt('Save').'"');
1.218 raeburn 1607: if ($newuser) {
1.301 bisitz 1608: $r->print(' onclick="auth_check()" \>'."\n");
1.218 raeburn 1609: } else {
1.301 bisitz 1610: $r->print('onclick="this.form.submit()" \>'."\n");
1.218 raeburn 1611: }
1.188 raeburn 1612: } else {
1.393 raeburn 1613: $r->print('</fieldset></div>'.
1614: '<div class="LC_clear_float_footer"></div>'.
1615: '<br /><a href="javascript:backPage(document.cu)">'.
1.218 raeburn 1616: &mt('Back to previous page').'</a>');
1.188 raeburn 1617: }
1618: } else {
1.375 raeburn 1619: $r->print(&course_level_table(\%inccourses,$showcredits,$defaultcredits));
1.393 raeburn 1620: $r->print('</fieldset></div><div class="LC_clear_float_footer"></div>'.
1621: '<br /><input type="button" value="'.&mt('Save').'" onclick="setSections(this.form)" />'."\n");
1.188 raeburn 1622: }
1.88 raeburn 1623: }
1.188 raeburn 1624: $r->print(&Apache::lonhtmlcommon::echo_form_input(['phase','userrole','ccdomain','prevphase','currstate','ccuname','ccdomain']));
1.179 raeburn 1625: $r->print('<input type="hidden" name="currstate" value="" />');
1.393 raeburn 1626: $r->print('<input type="hidden" name="prevphase" value="'.$env{'form.phase'}.'" /></form><br /><br />');
1.218 raeburn 1627: return;
1.2 www 1628: }
1.1 www 1629:
1.213 raeburn 1630: sub singleuser_breadcrumb {
1.422 raeburn 1631: my ($crstype,$context,$domain) = @_;
1.213 raeburn 1632: my %breadcrumb_text;
1633: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1634: if ($crstype eq 'Community') {
1635: $breadcrumb_text{'search'} = 'Enroll a member';
1636: } else {
1637: $breadcrumb_text{'search'} = 'Enroll a student';
1638: }
1.422 raeburn 1639: $breadcrumb_text{'userpicked'} = 'Select a user';
1640: $breadcrumb_text{'modify'} = 'Set section/dates';
1.416 raeburn 1641: } elsif ($env{'form.action'} eq 'accesslogs') {
1642: $breadcrumb_text{'search'} = 'View access logs for a user';
1.422 raeburn 1643: $breadcrumb_text{'userpicked'} = 'Select a user';
1644: $breadcrumb_text{'activity'} = 'Activity';
1645: } elsif (($env{'form.action'} eq 'singleuser') && ($context eq 'domain') &&
1646: (!&Apache::lonnet::allowed('mau',$domain))) {
1647: $breadcrumb_text{'search'} = "View user's roles";
1648: $breadcrumb_text{'userpicked'} = 'Select a user';
1649: $breadcrumb_text{'modify'} = 'User roles';
1.213 raeburn 1650: } else {
1.229 raeburn 1651: $breadcrumb_text{'search'} = 'Create/modify a user';
1.422 raeburn 1652: $breadcrumb_text{'userpicked'} = 'Select a user';
1653: $breadcrumb_text{'modify'} = 'Set user role';
1.213 raeburn 1654: }
1655: return %breadcrumb_text;
1656: }
1657:
1658: sub date_sections_select {
1.375 raeburn 1659: my ($context,$newuser,$formname,$permission,$crstype,$ccuname,$ccdomain,
1660: $showcredits) = @_;
1661: my $credits;
1662: if ($showcredits) {
1663: my $defaultcredits = &Apache::lonuserutils::get_defaultcredits();
1664: $credits = &get_user_credits($ccuname,$ccdomain,$defaultcredits);
1665: if ($credits eq '') {
1666: $credits = $defaultcredits;
1667: }
1668: }
1.213 raeburn 1669: my $cid = $env{'request.course.id'};
1670: my ($cnum,$cdom) = &Apache::lonuserutils::get_course_identity($cid);
1671: my $date_table = '<h3>'.&mt('Starting and Ending Dates').'</h3>'."\n".
1672: &Apache::lonuserutils::date_setting_table(undef,undef,$context,
1673: undef,$formname,$permission);
1674: my $rowtitle = 'Section';
1.375 raeburn 1675: my $secbox = '<h3>'.&mt('Section and Credits').'</h3>'."\n".
1.213 raeburn 1676: &Apache::lonuserutils::section_picker($cdom,$cnum,'st',$rowtitle,
1.375 raeburn 1677: $permission,$context,'',$crstype,
1678: $showcredits,$credits);
1.213 raeburn 1679: my $output = $date_table.$secbox;
1680: return $output;
1681: }
1682:
1.216 raeburn 1683: sub validation_javascript {
1.375 raeburn 1684: my ($context,$ccdomain,$pjump_def,$crstype,$groupslist,$newuser,$formname,
1.216 raeburn 1685: $loaditem) = @_;
1686: my $dc_setcourse_code = '';
1687: my $nondc_setsection_code = '';
1688: if ($context eq 'domain') {
1689: my $dcdom = $env{'request.role.domain'};
1690: $loaditem->{'onload'} = "document.cu.coursedesc.value='';";
1.227 raeburn 1691: $dc_setcourse_code =
1692: &Apache::lonuserutils::dc_setcourse_js('cu','singleuser',$context);
1.216 raeburn 1693: } else {
1.227 raeburn 1694: my $checkauth;
1695: if (($newuser) || (&Apache::lonnet::allowed('mau',$ccdomain))) {
1696: $checkauth = 1;
1697: }
1698: if ($context eq 'course') {
1699: $nondc_setsection_code =
1700: &Apache::lonuserutils::setsections_javascript($formname,$groupslist,
1.375 raeburn 1701: undef,$checkauth,
1702: $crstype);
1.227 raeburn 1703: }
1704: if ($checkauth) {
1705: $nondc_setsection_code .=
1706: &Apache::lonuserutils::verify_authen($formname,$context);
1707: }
1.216 raeburn 1708: }
1709: my $js = &user_modification_js($pjump_def,$dc_setcourse_code,
1710: $nondc_setsection_code,$groupslist);
1711: my ($jsback,$elements) = &crumb_utilities();
1712: $js .= "\n".
1.301 bisitz 1713: '<script type="text/javascript">'."\n".
1714: '// <![CDATA['."\n".
1715: $jsback."\n".
1716: '// ]]>'."\n".
1717: '</script>'."\n";
1.216 raeburn 1718: return $js;
1719: }
1720:
1.217 raeburn 1721: sub display_existing_roles {
1.375 raeburn 1722: my ($r,$ccuname,$ccdomain,$inccourses,$context,$roledom,$crstype,
1.418 raeburn 1723: $showcredits,$statuses) = @_;
1.329 raeburn 1724: my $now=time;
1.418 raeburn 1725: my $showall = 1;
1726: my ($showexpired,$showactive);
1727: if ((ref($statuses) eq 'ARRAY') && (@{$statuses} > 0)) {
1728: $showall = 0;
1729: if (grep(/^expired$/,@{$statuses})) {
1730: $showexpired = 1;
1731: }
1732: if (grep(/^active$/,@{$statuses})) {
1733: $showactive = 1;
1734: }
1735: if ($showexpired && $showactive) {
1736: $showall = 1;
1737: }
1738: }
1.329 raeburn 1739: my %lt=&Apache::lonlocal::texthash(
1.217 raeburn 1740: 'rer' => "Existing Roles",
1741: 'rev' => "Revoke",
1742: 'del' => "Delete",
1743: 'ren' => "Re-Enable",
1744: 'rol' => "Role",
1745: 'ext' => "Extent",
1.375 raeburn 1746: 'crd' => "Credits",
1.217 raeburn 1747: 'sta' => "Start",
1748: 'end' => "End",
1749: );
1.329 raeburn 1750: my (%rolesdump,%roletext,%sortrole,%roleclass,%rolepriv);
1751: if ($context eq 'course' || $context eq 'author') {
1752: my @roles = &Apache::lonuserutils::roles_by_context($context,1,$crstype);
1753: my %roleshash =
1754: &Apache::lonnet::get_my_roles($ccuname,$ccdomain,'userroles',
1755: ['active','previous','future'],\@roles,$roledom,1);
1756: foreach my $key (keys(%roleshash)) {
1757: my ($start,$end) = split(':',$roleshash{$key});
1758: next if ($start eq '-1' || $end eq '-1');
1759: my ($rnum,$rdom,$role,$sec) = split(':',$key);
1760: if ($context eq 'course') {
1761: next unless (($rnum eq $env{'course.'.$env{'request.course.id'}.'.num'})
1762: && ($rdom eq $env{'course.'.$env{'request.course.id'}.'.domain'}));
1763: } elsif ($context eq 'author') {
1764: next unless (($rnum eq $env{'user.name'}) && ($rdom eq $env{'request.role.domain'}));
1765: }
1766: my ($newkey,$newvalue,$newrole);
1767: $newkey = '/'.$rdom.'/'.$rnum;
1768: if ($sec ne '') {
1769: $newkey .= '/'.$sec;
1770: }
1771: $newvalue = $role;
1772: if ($role =~ /^cr/) {
1773: $newrole = 'cr';
1774: } else {
1775: $newrole = $role;
1776: }
1777: $newkey .= '_'.$newrole;
1778: if ($start ne '' && $end ne '') {
1779: $newvalue .= '_'.$end.'_'.$start;
1.335 raeburn 1780: } elsif ($end ne '') {
1781: $newvalue .= '_'.$end;
1.329 raeburn 1782: }
1783: $rolesdump{$newkey} = $newvalue;
1784: }
1785: } else {
1.360 raeburn 1786: %rolesdump=&Apache::lonnet::dump('roles',$ccdomain,$ccuname);
1.329 raeburn 1787: }
1788: # Build up table of user roles to allow revocation and re-enabling of roles.
1789: my ($tmp) = keys(%rolesdump);
1790: return if ($tmp =~ /^(con_lost|error)/i);
1791: foreach my $area (sort { my $a1=join('_',(split('_',$a))[1,0]);
1792: my $b1=join('_',(split('_',$b))[1,0]);
1793: return $a1 cmp $b1;
1794: } keys(%rolesdump)) {
1795: next if ($area =~ /^rolesdef/);
1796: my $envkey=$area;
1797: my $role = $rolesdump{$area};
1798: my $thisrole=$area;
1799: $area =~ s/\_\w\w$//;
1800: my ($role_code,$role_end_time,$role_start_time) =
1801: split(/_/,$role);
1.418 raeburn 1802: my $active=1;
1803: $active=0 if (($role_end_time) && ($now>$role_end_time));
1804: if ($active) {
1805: next unless($showall || $showactive);
1806: } else {
1.430 raeburn 1807: next unless($showall || $showexpired);
1.418 raeburn 1808: }
1.217 raeburn 1809: # Is this a custom role? Get role owner and title.
1.329 raeburn 1810: my ($croleudom,$croleuname,$croletitle)=
1811: ($role_code=~m{^cr/($match_domain)/($match_username)/(\w+)$});
1812: my $allowed=0;
1813: my $delallowed=0;
1814: my $sortkey=$role_code;
1815: my $class='Unknown';
1.375 raeburn 1816: my $credits='';
1.418 raeburn 1817: my $csec;
1.421 raeburn 1818: if ($area =~ m{^/($match_domain)/($match_courseid)}) {
1.329 raeburn 1819: $class='Course';
1820: my ($coursedom,$coursedir) = ($1,$2);
1821: my $cid = $1.'_'.$2;
1822: # $1.'_'.$2 is the course id (eg. 103_12345abcef103l3).
1.421 raeburn 1823: next if ($envkey =~ m{^/$match_domain/$match_courseid/[A-Za-z0-9]+_gr$});
1.329 raeburn 1824: my %coursedata=
1825: &Apache::lonnet::coursedescription($cid);
1826: if ($coursedir =~ /^$match_community$/) {
1827: $class='Community';
1828: }
1829: $sortkey.="\0$coursedom";
1830: my $carea;
1831: if (defined($coursedata{'description'})) {
1832: $carea=$coursedata{'description'}.
1833: '<br />'.&mt('Domain').': '.$coursedom.(' 'x8).
1834: &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$coursedir,$coursedom);
1835: $sortkey.="\0".$coursedata{'description'};
1836: } else {
1837: if ($class eq 'Community') {
1838: $carea=&mt('Unavailable community').': '.$area;
1839: $sortkey.="\0".&mt('Unavailable community').': '.$area;
1.217 raeburn 1840: } else {
1841: $carea=&mt('Unavailable course').': '.$area;
1842: $sortkey.="\0".&mt('Unavailable course').': '.$area;
1843: }
1.329 raeburn 1844: }
1845: $sortkey.="\0$coursedir";
1846: $inccourses->{$cid}=1;
1.375 raeburn 1847: if (($showcredits) && ($class eq 'Course') && ($role_code eq 'st')) {
1848: my $defaultcredits = $coursedata{'internal.defaultcredits'};
1849: $credits =
1850: &get_user_credits($ccuname,$ccdomain,$defaultcredits,
1851: $coursedom,$coursedir);
1852: if ($credits eq '') {
1853: $credits = $defaultcredits;
1854: }
1855: }
1.329 raeburn 1856: if ((&Apache::lonnet::allowed('c'.$role_code,$coursedom.'/'.$coursedir)) ||
1857: (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) {
1858: $allowed=1;
1859: }
1860: unless ($allowed) {
1.365 raeburn 1861: my $isowner = &Apache::lonuserutils::is_courseowner($cid,$coursedata{'internal.courseowner'});
1.329 raeburn 1862: if ($isowner) {
1863: if (($role_code eq 'co') && ($class eq 'Community')) {
1864: $allowed = 1;
1865: } elsif (($role_code eq 'cc') && ($class eq 'Course')) {
1866: $allowed = 1;
1867: }
1.217 raeburn 1868: }
1.329 raeburn 1869: }
1870: if ((&Apache::lonnet::allowed('dro',$coursedom)) ||
1871: (&Apache::lonnet::allowed('dro',$ccdomain))) {
1872: $delallowed=1;
1873: }
1.217 raeburn 1874: # - custom role. Needs more info, too
1.329 raeburn 1875: if ($croletitle) {
1876: if (&Apache::lonnet::allowed('ccr',$coursedom.'/'.$coursedir)) {
1877: $allowed=1;
1878: $thisrole.='.'.$role_code;
1.217 raeburn 1879: }
1.329 raeburn 1880: }
1.418 raeburn 1881: if ($area=~m{^/($match_domain/$match_courseid/(\w+))}) {
1882: $csec = $2;
1883: $carea.='<br />'.&mt('Section: [_1]',$csec);
1884: $sortkey.="\0$csec";
1.329 raeburn 1885: if (!$allowed) {
1.418 raeburn 1886: if ($env{'request.course.sec'} eq $csec) {
1887: if (&Apache::lonnet::allowed('c'.$role_code,$1)) {
1.329 raeburn 1888: $allowed = 1;
1.217 raeburn 1889: }
1890: }
1891: }
1.329 raeburn 1892: }
1893: $area=$carea;
1894: } else {
1895: $sortkey.="\0".$area;
1896: # Determine if current user is able to revoke privileges
1897: if ($area=~m{^/($match_domain)/}) {
1898: if ((&Apache::lonnet::allowed('c'.$role_code,$1)) ||
1899: (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) {
1900: $allowed=1;
1.217 raeburn 1901: }
1.329 raeburn 1902: if (((&Apache::lonnet::allowed('dro',$1)) ||
1903: (&Apache::lonnet::allowed('dro',$ccdomain))) &&
1904: ($role_code ne 'dc')) {
1905: $delallowed=1;
1.217 raeburn 1906: }
1.329 raeburn 1907: } else {
1908: if (&Apache::lonnet::allowed('c'.$role_code,'/')) {
1.217 raeburn 1909: $allowed=1;
1910: }
1911: }
1.363 raeburn 1912: if ($role_code eq 'ca' || $role_code eq 'au' || $role_code eq 'aa') {
1.377 raeburn 1913: $class='Authoring Space';
1.329 raeburn 1914: } elsif ($role_code eq 'su') {
1915: $class='System';
1.217 raeburn 1916: } else {
1.329 raeburn 1917: $class='Domain';
1.217 raeburn 1918: }
1.329 raeburn 1919: }
1920: if (($role_code eq 'ca') || ($role_code eq 'aa')) {
1921: $area=~m{/($match_domain)/($match_username)};
1922: if (&Apache::lonuserutils::authorpriv($2,$1)) {
1923: $allowed=1;
1.217 raeburn 1924: } else {
1.329 raeburn 1925: $allowed=0;
1.217 raeburn 1926: }
1.329 raeburn 1927: }
1928: my $row = '';
1.418 raeburn 1929: if ($showall) {
1930: $row.= '<td>';
1931: if (($active) && ($allowed)) {
1932: $row.= '<input type="checkbox" name="rev:'.$thisrole.'" />';
1933: } else {
1934: if ($active) {
1935: $row.=' ';
1936: } else {
1937: $row.=&mt('expired or revoked');
1938: }
1939: }
1940: $row.='</td><td>';
1941: if ($allowed && !$active) {
1942: $row.= '<input type="checkbox" name="ren:'.$thisrole.'" />';
1943: } else {
1944: $row.=' ';
1945: }
1946: $row.='</td><td>';
1947: if ($delallowed) {
1948: $row.= '<input type="checkbox" name="del:'.$thisrole.'" />';
1.217 raeburn 1949: } else {
1.418 raeburn 1950: $row.=' ';
1.217 raeburn 1951: }
1.430 raeburn 1952: $row.= '</td>';
1.329 raeburn 1953: }
1954: my $plaintext='';
1955: if (!$croletitle) {
1.375 raeburn 1956: $plaintext=&Apache::lonnet::plaintext($role_code,$class);
1957: if (($showcredits) && ($credits ne '')) {
1958: $plaintext .= '<br/ ><span class="LC_nobreak">'.
1959: '<span class="LC_fontsize_small">'.
1960: &mt('Credits: [_1]',$credits).
1961: '</span></span>';
1962: }
1.329 raeburn 1963: } else {
1964: $plaintext=
1.395 bisitz 1965: &mt('Custom role [_1][_2]defined by [_3]',
1.346 bisitz 1966: '"'.$croletitle.'"',
1967: '<br />',
1968: $croleuname.':'.$croleudom);
1.329 raeburn 1969: }
1.418 raeburn 1970: $row.= '<td>'.$plaintext.'</td>'.
1971: '<td>'.$area.'</td>'.
1972: '<td>'.($role_start_time?&Apache::lonlocal::locallocaltime($role_start_time)
1973: : ' ' ).'</td>'.
1974: '<td>'.($role_end_time ?&Apache::lonlocal::locallocaltime($role_end_time)
1975: : ' ' ).'</td>';
1.329 raeburn 1976: $sortrole{$sortkey}=$envkey;
1977: $roletext{$envkey}=$row;
1978: $roleclass{$envkey}=$class;
1.418 raeburn 1979: if ($allowed) {
1980: $rolepriv{$envkey}='edit';
1981: } else {
1982: if ($context eq 'domain') {
1.420 raeburn 1983: if ((&Apache::lonnet::allowed('vur',$ccdomain)) &&
1.421 raeburn 1984: ($envkey=~m{^/$ccdomain/})) {
1.418 raeburn 1985: $rolepriv{$envkey}='view';
1986: }
1987: } elsif ($context eq 'course') {
1988: if ((&Apache::lonnet::allowed('vcl',$env{'request.course.id'})) ||
1989: ($env{'request.course.sec'} && ($env{'request.course.sec'} eq $csec) &&
1990: &Apache::lonnet::allowed('vcl',$env{'request.course.id'}.'/'.$env{'request.course.sec'}))) {
1991: $rolepriv{$envkey}='view';
1992: }
1993: }
1994: }
1.329 raeburn 1995: } # end of foreach (table building loop)
1996:
1997: my $rolesdisplay = 0;
1998: my %output = ();
1.377 raeburn 1999: foreach my $type ('Authoring Space','Course','Community','Domain','System','Unknown') {
1.329 raeburn 2000: $output{$type} = '';
2001: foreach my $which (sort {uc($a) cmp uc($b)} (keys(%sortrole))) {
2002: if ( ($roleclass{$sortrole{$which}} =~ /^\Q$type\E/ ) && ($rolepriv{$sortrole{$which}}) ) {
2003: $output{$type}.=
2004: &Apache::loncommon::start_data_table_row().
2005: $roletext{$sortrole{$which}}.
2006: &Apache::loncommon::end_data_table_row();
1.217 raeburn 2007: }
1.329 raeburn 2008: }
2009: unless($output{$type} eq '') {
2010: $output{$type} = '<tr class="LC_info_row">'.
2011: "<td align='center' colspan='7'>".&mt($type)."</td></tr>".
2012: $output{$type};
2013: $rolesdisplay = 1;
2014: }
2015: }
2016: if ($rolesdisplay == 1) {
2017: my $contextrole='';
2018: if ($env{'request.course.id'}) {
2019: if (&Apache::loncommon::course_type() eq 'Community') {
2020: $contextrole = &mt('Existing Roles in this Community');
1.290 bisitz 2021: } else {
1.329 raeburn 2022: $contextrole = &mt('Existing Roles in this Course');
1.290 bisitz 2023: }
1.329 raeburn 2024: } elsif ($env{'request.role'} =~ /^au\./) {
1.377 raeburn 2025: $contextrole = &mt('Existing Co-Author Roles in your Authoring Space');
1.329 raeburn 2026: } else {
1.418 raeburn 2027: if ($showall) {
2028: $contextrole = &mt('Existing Roles in this Domain');
2029: } elsif ($showactive) {
2030: $contextrole = &mt('Unexpired Roles in this Domain');
2031: } elsif ($showexpired) {
2032: $contextrole = &mt('Expired or Revoked Roles in this Domain');
2033: }
1.329 raeburn 2034: }
1.393 raeburn 2035: $r->print('<div class="LC_left_float">'.
1.375 raeburn 2036: '<fieldset><legend>'.$contextrole.'</legend>'.
1.217 raeburn 2037: &Apache::loncommon::start_data_table("LC_createuser").
1.418 raeburn 2038: &Apache::loncommon::start_data_table_header_row());
2039: if ($showall) {
2040: $r->print(
1.419 raeburn 2041: '<th>'.$lt{'rev'}.'</th><th>'.$lt{'ren'}.'</th><th>'.$lt{'del'}.'</th>'
1.418 raeburn 2042: );
2043: } elsif ($showexpired) {
2044: $r->print('<th>'.$lt{'rev'}.'</th>');
2045: }
2046: $r->print(
1.419 raeburn 2047: '<th>'.$lt{'rol'}.'</th><th>'.$lt{'ext'}.'</th>'.
2048: '<th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'.
1.217 raeburn 2049: &Apache::loncommon::end_data_table_header_row());
1.377 raeburn 2050: foreach my $type ('Authoring Space','Course','Community','Domain','System','Unknown') {
1.329 raeburn 2051: if ($output{$type}) {
2052: $r->print($output{$type}."\n");
1.217 raeburn 2053: }
2054: }
1.375 raeburn 2055: $r->print(&Apache::loncommon::end_data_table().
2056: '</fieldset></div>');
1.329 raeburn 2057: }
1.217 raeburn 2058: return;
2059: }
2060:
1.218 raeburn 2061: sub new_coauthor_roles {
2062: my ($r,$ccuname,$ccdomain) = @_;
2063: my $addrolesdisplay = 0;
2064: #
2065: # Co-Author
2066: #
2067: if (&Apache::lonuserutils::authorpriv($env{'user.name'},
2068: $env{'request.role.domain'}) &&
2069: ($env{'user.name'} ne $ccuname || $env{'user.domain'} ne $ccdomain)) {
2070: # No sense in assigning co-author role to yourself
2071: $addrolesdisplay = 1;
2072: my $cuname=$env{'user.name'};
2073: my $cudom=$env{'request.role.domain'};
2074: my %lt=&Apache::lonlocal::texthash(
1.377 raeburn 2075: 'cs' => "Authoring Space",
1.218 raeburn 2076: 'act' => "Activate",
2077: 'rol' => "Role",
2078: 'ext' => "Extent",
2079: 'sta' => "Start",
2080: 'end' => "End",
2081: 'cau' => "Co-Author",
2082: 'caa' => "Assistant Co-Author",
2083: 'ssd' => "Set Start Date",
2084: 'sed' => "Set End Date"
2085: );
2086: $r->print('<h4>'.$lt{'cs'}.'</h4>'."\n".
2087: &Apache::loncommon::start_data_table()."\n".
2088: &Apache::loncommon::start_data_table_header_row()."\n".
2089: '<th>'.$lt{'act'}.'</th><th>'.$lt{'rol'}.'</th>'.
2090: '<th>'.$lt{'ext'}.'</th><th>'.$lt{'sta'}.'</th>'.
2091: '<th>'.$lt{'end'}.'</th>'."\n".
2092: &Apache::loncommon::end_data_table_header_row()."\n".
2093: &Apache::loncommon::start_data_table_row().'
2094: <td>
1.291 bisitz 2095: <input type="checkbox" name="act_'.$cudom.'_'.$cuname.'_ca" />
1.218 raeburn 2096: </td>
2097: <td>'.$lt{'cau'}.'</td>
2098: <td>'.$cudom.'_'.$cuname.'</td>
2099: <td><input type="hidden" name="start_'.$cudom.'_'.$cuname.'_ca" value="" />
2100: <a href=
2101: "javascript:pjump('."'date_start','Start Date Co-Author',document.cu.start_$cudom\_$cuname\_ca.value,'start_$cudom\_$cuname\_ca','cu.pres','dateset'".')">'.$lt{'ssd'}.'</a></td>
2102: <td><input type="hidden" name="end_'.$cudom.'_'.$cuname.'_ca" value="" />
2103: <a href=
2104: "javascript:pjump('."'date_end','End Date Co-Author',document.cu.end_$cudom\_$cuname\_ca.value,'end_$cudom\_$cuname\_ca','cu.pres','dateset'".')">'.$lt{'sed'}.'</a></td>'."\n".
2105: &Apache::loncommon::end_data_table_row()."\n".
2106: &Apache::loncommon::start_data_table_row()."\n".
1.291 bisitz 2107: '<td><input type="checkbox" name="act_'.$cudom.'_'.$cuname.'_aa" /></td>
1.218 raeburn 2108: <td>'.$lt{'caa'}.'</td>
2109: <td>'.$cudom.'_'.$cuname.'</td>
2110: <td><input type="hidden" name="start_'.$cudom.'_'.$cuname.'_aa" value="" />
2111: <a href=
2112: "javascript:pjump('."'date_start','Start Date Assistant Co-Author',document.cu.start_$cudom\_$cuname\_aa.value,'start_$cudom\_$cuname\_aa','cu.pres','dateset'".')">'.$lt{'ssd'}.'</a></td>
2113: <td><input type="hidden" name="end_'.$cudom.'_'.$cuname.'_aa" value="" />
2114: <a href=
2115: "javascript:pjump('."'date_end','End Date Assistant Co-Author',document.cu.end_$cudom\_$cuname\_aa.value,'end_$cudom\_$cuname\_aa','cu.pres','dateset'".')">'.$lt{'sed'}.'</a></td>'."\n".
2116: &Apache::loncommon::end_data_table_row()."\n".
2117: &Apache::loncommon::end_data_table());
2118: } elsif ($env{'request.role'} =~ /^au\./) {
2119: if (!(&Apache::lonuserutils::authorpriv($env{'user.name'},
2120: $env{'request.role.domain'}))) {
2121: $r->print('<span class="LC_error">'.
2122: &mt('You do not have privileges to assign co-author roles.').
2123: '</span>');
2124: } elsif (($env{'user.name'} eq $ccuname) &&
2125: ($env{'user.domain'} eq $ccdomain)) {
1.377 raeburn 2126: $r->print(&mt('Assigning yourself a co-author or assistant co-author role in your own author area in Authoring Space is not permitted'));
1.218 raeburn 2127: }
2128: }
2129: return $addrolesdisplay;;
2130: }
2131:
2132: sub new_domain_roles {
1.357 raeburn 2133: my ($r,$ccdomain) = @_;
1.218 raeburn 2134: my $addrolesdisplay = 0;
2135: #
2136: # Domain level
2137: #
2138: my $num_domain_level = 0;
2139: my $domaintext =
2140: '<h4>'.&mt('Domain Level').'</h4>'.
2141: &Apache::loncommon::start_data_table().
2142: &Apache::loncommon::start_data_table_header_row().
2143: '<th>'.&mt('Activate').'</th><th>'.&mt('Role').'</th><th>'.
2144: &mt('Extent').'</th>'.
2145: '<th>'.&mt('Start').'</th><th>'.&mt('End').'</th>'.
2146: &Apache::loncommon::end_data_table_header_row();
1.312 raeburn 2147: my @allroles = &Apache::lonuserutils::roles_by_context('domain');
1.445 raeburn 2148: my $uprimary = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
2149: my $uintdom = &Apache::lonnet::internet_dom($uprimary);
1.218 raeburn 2150: foreach my $thisdomain (sort(&Apache::lonnet::all_domains())) {
1.312 raeburn 2151: foreach my $role (@allroles) {
2152: next if ($role eq 'ad');
1.357 raeburn 2153: next if (($role eq 'au') && ($ccdomain ne $thisdomain));
1.218 raeburn 2154: if (&Apache::lonnet::allowed('c'.$role,$thisdomain)) {
1.445 raeburn 2155: if ($role eq 'dc') {
2156: unless ($thisdomain eq $env{'request.role.domain'}) {
2157: my $domprim = &Apache::lonnet::domain($thisdomain,'primary');
2158: my $intdom = &Apache::lonnet::internet_dom($domprim);
2159: next unless ($uintdom eq $intdom);
2160: }
2161: }
1.218 raeburn 2162: my $plrole=&Apache::lonnet::plaintext($role);
2163: my %lt=&Apache::lonlocal::texthash(
2164: 'ssd' => "Set Start Date",
2165: 'sed' => "Set End Date"
2166: );
2167: $num_domain_level ++;
2168: $domaintext .=
2169: &Apache::loncommon::start_data_table_row().
1.291 bisitz 2170: '<td><input type="checkbox" name="act_'.$thisdomain.'_'.$role.'" /></td>
1.218 raeburn 2171: <td>'.$plrole.'</td>
2172: <td>'.$thisdomain.'</td>
2173: <td><input type="hidden" name="start_'.$thisdomain.'_'.$role.'" value="" />
2174: <a href=
2175: "javascript:pjump('."'date_start','Start Date $plrole',document.cu.start_$thisdomain\_$role.value,'start_$thisdomain\_$role','cu.pres','dateset'".')">'.$lt{'ssd'}.'</a></td>
2176: <td><input type="hidden" name="end_'.$thisdomain.'_'.$role.'" value="" />
2177: <a href=
2178: "javascript:pjump('."'date_end','End Date $plrole',document.cu.end_$thisdomain\_$role.value,'end_$thisdomain\_$role','cu.pres','dateset'".')">'.$lt{'sed'}.'</a></td>'.
2179: &Apache::loncommon::end_data_table_row();
2180: }
2181: }
2182: }
2183: $domaintext.= &Apache::loncommon::end_data_table();
2184: if ($num_domain_level > 0) {
2185: $r->print($domaintext);
2186: $addrolesdisplay = 1;
2187: }
2188: return $addrolesdisplay;
2189: }
2190:
1.188 raeburn 2191: sub user_authentication {
1.227 raeburn 2192: my ($ccuname,$ccdomain,$formname) = @_;
1.188 raeburn 2193: my $currentauth=&Apache::lonnet::queryauthenticate($ccuname,$ccdomain);
1.227 raeburn 2194: my $outcome;
1.418 raeburn 2195: my %lt=&Apache::lonlocal::texthash(
2196: 'err' => "ERROR",
2197: 'uuas' => "This user has an unrecognized authentication scheme",
2198: 'adcs' => "Please alert a domain coordinator of this situation",
2199: 'sldb' => "Please specify login data below",
2200: 'ld' => "Login Data"
2201: );
1.188 raeburn 2202: # Check for a bad authentication type
2203: if ($currentauth !~ /^(krb4|krb5|unix|internal|localauth):/) {
2204: # bad authentication scheme
2205: if (&Apache::lonnet::allowed('mau',$ccdomain)) {
1.227 raeburn 2206: &initialize_authen_forms($ccdomain,$formname);
2207:
1.190 raeburn 2208: my $choices = &Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc);
1.188 raeburn 2209: $outcome = <<ENDBADAUTH;
2210: <script type="text/javascript" language="Javascript">
1.301 bisitz 2211: // <![CDATA[
1.188 raeburn 2212: $loginscript
1.301 bisitz 2213: // ]]>
1.188 raeburn 2214: </script>
2215: <span class="LC_error">$lt{'err'}:
2216: $lt{'uuas'} ($currentauth). $lt{'sldb'}.</span>
2217: <h3>$lt{'ld'}</h3>
2218: $choices
2219: ENDBADAUTH
2220: } else {
2221: # This user is not allowed to modify the user's
2222: # authentication scheme, so just notify them of the problem
2223: $outcome = <<ENDBADAUTH;
2224: <span class="LC_error"> $lt{'err'}:
2225: $lt{'uuas'} ($currentauth). $lt{'adcs'}.
2226: </span>
2227: ENDBADAUTH
2228: }
2229: } else { # Authentication type is valid
1.418 raeburn 2230:
1.227 raeburn 2231: &initialize_authen_forms($ccdomain,$formname,$currentauth,'modifyuser');
1.205 raeburn 2232: my ($authformcurrent,$can_modify,@authform_others) =
1.188 raeburn 2233: &modify_login_block($ccdomain,$currentauth);
2234: if (&Apache::lonnet::allowed('mau',$ccdomain)) {
2235: # Current user has login modification privileges
2236: $outcome =
2237: '<script type="text/javascript" language="Javascript">'."\n".
1.301 bisitz 2238: '// <![CDATA['."\n".
1.188 raeburn 2239: $loginscript."\n".
1.301 bisitz 2240: '// ]]>'."\n".
1.188 raeburn 2241: '</script>'."\n".
2242: '<h3>'.$lt{'ld'}.'</h3>'.
2243: &Apache::loncommon::start_data_table().
1.205 raeburn 2244: &Apache::loncommon::start_data_table_row().
1.188 raeburn 2245: '<td>'.$authformnop;
1.418 raeburn 2246: if (($can_modify) && (&Apache::lonnet::allowed('mau',$ccdomain))) {
1.188 raeburn 2247: $outcome .= '</td>'."\n".
2248: &Apache::loncommon::end_data_table_row().
2249: &Apache::loncommon::start_data_table_row().
2250: '<td>'.$authformcurrent.'</td>'.
2251: &Apache::loncommon::end_data_table_row()."\n";
2252: } else {
1.200 raeburn 2253: $outcome .= ' ('.$authformcurrent.')</td>'.
2254: &Apache::loncommon::end_data_table_row()."\n";
1.188 raeburn 2255: }
1.418 raeburn 2256: if (&Apache::lonnet::allowed('mau',$ccdomain)) {
2257: foreach my $item (@authform_others) {
2258: $outcome .= &Apache::loncommon::start_data_table_row().
2259: '<td>'.$item.'</td>'.
2260: &Apache::loncommon::end_data_table_row()."\n";
2261: }
1.188 raeburn 2262: }
1.205 raeburn 2263: $outcome .= &Apache::loncommon::end_data_table();
1.188 raeburn 2264: } else {
1.418 raeburn 2265: if (&Apache::lonnet::allowed('udp',$ccdomain)) {
2266: # Current user has rights to view domain preferences for user's domain
2267: my $result;
2268: if ($currentauth =~ /^krb(4|5):([^:]*)$/) {
2269: my ($krbver,$krbrealm) = ($1,$2);
2270: if ($krbrealm eq '') {
2271: $result = &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
2272: } else {
2273: $result = &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
1.426 raeburn 2274: $krbrealm,$krbver);
1.418 raeburn 2275: }
2276: } elsif ($currentauth =~ /^internal:/) {
2277: $result = &mt('Currently internally authenticated.');
2278: } elsif ($currentauth =~ /^localauth:/) {
2279: $result = &mt('Currently using local (institutional) authentication.');
2280: } elsif ($currentauth =~ /^unix:/) {
2281: $result = &mt('Currently Filesystem Authenticated.');
2282: }
2283: $outcome = '<h3>'.$lt{'ld'}.'</h3>'.
2284: &Apache::loncommon::start_data_table().
2285: &Apache::loncommon::start_data_table_row().
2286: '<td>'.$result.'</td>'.
2287: &Apache::loncommon::end_data_table_row()."\n".
2288: &Apache::loncommon::end_data_table();
2289: } elsif (&Apache::lonnet::allowed('mau',$env{'request.role.domain'})) {
1.188 raeburn 2290: my %lt=&Apache::lonlocal::texthash(
2291: 'ccld' => "Change Current Login Data",
2292: 'yodo' => "You do not have privileges to modify the authentication configuration for this user.",
2293: 'ifch' => "If a change is required, contact a domain coordinator for the domain",
2294: );
2295: $outcome .= <<ENDNOPRIV;
2296: <h3>$lt{'ccld'}</h3>
2297: $lt{'yodo'} $lt{'ifch'}: $ccdomain
1.235 raeburn 2298: <input type="hidden" name="login" value="nochange" />
1.188 raeburn 2299: ENDNOPRIV
2300: }
2301: }
2302: } ## End of "check for bad authentication type" logic
2303: return $outcome;
2304: }
2305:
1.187 raeburn 2306: sub modify_login_block {
2307: my ($dom,$currentauth) = @_;
2308: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
2309: my ($authnum,%can_assign) =
2310: &Apache::loncommon::get_assignable_auth($dom);
1.205 raeburn 2311: my ($authformcurrent,@authform_others,$show_override_msg);
1.187 raeburn 2312: if ($currentauth=~/^krb(4|5):/) {
2313: $authformcurrent=$authformkrb;
2314: if ($can_assign{'int'}) {
1.205 raeburn 2315: push(@authform_others,$authformint);
1.187 raeburn 2316: }
2317: if ($can_assign{'loc'}) {
1.205 raeburn 2318: push(@authform_others,$authformloc);
1.187 raeburn 2319: }
2320: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
2321: $show_override_msg = 1;
2322: }
2323: } elsif ($currentauth=~/^internal:/) {
2324: $authformcurrent=$authformint;
2325: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205 raeburn 2326: push(@authform_others,$authformkrb);
1.187 raeburn 2327: }
2328: if ($can_assign{'loc'}) {
1.205 raeburn 2329: push(@authform_others,$authformloc);
1.187 raeburn 2330: }
2331: if ($can_assign{'int'}) {
2332: $show_override_msg = 1;
2333: }
2334: } elsif ($currentauth=~/^unix:/) {
2335: $authformcurrent=$authformfsys;
2336: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205 raeburn 2337: push(@authform_others,$authformkrb);
1.187 raeburn 2338: }
2339: if ($can_assign{'int'}) {
1.205 raeburn 2340: push(@authform_others,$authformint);
1.187 raeburn 2341: }
2342: if ($can_assign{'loc'}) {
1.205 raeburn 2343: push(@authform_others,$authformloc);
1.187 raeburn 2344: }
2345: if ($can_assign{'fsys'}) {
2346: $show_override_msg = 1;
2347: }
2348: } elsif ($currentauth=~/^localauth:/) {
2349: $authformcurrent=$authformloc;
2350: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205 raeburn 2351: push(@authform_others,$authformkrb);
1.187 raeburn 2352: }
2353: if ($can_assign{'int'}) {
1.205 raeburn 2354: push(@authform_others,$authformint);
1.187 raeburn 2355: }
2356: if ($can_assign{'loc'}) {
2357: $show_override_msg = 1;
2358: }
2359: }
2360: if ($show_override_msg) {
1.205 raeburn 2361: $authformcurrent = '<table><tr><td colspan="3">'.$authformcurrent.
2362: '</td></tr>'."\n".
2363: '<tr><td> </td>'.
2364: '<td><b>'.&mt('Currently in use').'</b></td>'.
2365: '<td align="right"><span class="LC_cusr_emph">'.
1.187 raeburn 2366: &mt('will override current values').
1.205 raeburn 2367: '</span></td></tr></table>';
1.187 raeburn 2368: }
1.205 raeburn 2369: return ($authformcurrent,$show_override_msg,@authform_others);
1.187 raeburn 2370: }
2371:
1.188 raeburn 2372: sub personal_data_display {
1.391 raeburn 2373: my ($ccuname,$ccdomain,$newuser,$context,$inst_results,$rolesarray,
1.443 raeburn 2374: $now,$captchaform,$emailusername,$usertype,$usernameset,$condition,$excluded) = @_;
1.388 bisitz 2375: my ($output,%userenv,%canmodify,%canmodify_status);
1.219 raeburn 2376: my @userinfo = ('firstname','middlename','lastname','generation',
2377: 'permanentemail','id');
1.252 raeburn 2378: my $rowcount = 0;
2379: my $editable = 0;
1.391 raeburn 2380: my %textboxsize = (
2381: firstname => '15',
2382: middlename => '15',
2383: lastname => '15',
2384: generation => '5',
2385: permanentemail => '25',
2386: id => '15',
2387: );
2388:
2389: my %lt=&Apache::lonlocal::texthash(
2390: 'pd' => "Personal Data",
2391: 'firstname' => "First Name",
2392: 'middlename' => "Middle Name",
2393: 'lastname' => "Last Name",
2394: 'generation' => "Generation",
2395: 'permanentemail' => "Permanent e-mail address",
2396: 'id' => "Student/Employee ID",
2397: 'lg' => "Login Data",
2398: 'inststatus' => "Affiliation",
2399: 'email' => 'E-mail address',
2400: 'valid' => 'Validation',
1.442 raeburn 2401: 'username' => 'Username',
1.391 raeburn 2402: );
2403:
2404: %canmodify_status =
1.286 raeburn 2405: &Apache::lonuserutils::can_modify_userinfo($context,$ccdomain,
2406: ['inststatus'],$rolesarray);
1.253 raeburn 2407: if (!$newuser) {
1.188 raeburn 2408: # Get the users information
2409: %userenv = &Apache::lonnet::get('environment',
2410: ['firstname','middlename','lastname','generation',
1.286 raeburn 2411: 'permanentemail','id','inststatus'],$ccdomain,$ccuname);
1.219 raeburn 2412: %canmodify =
2413: &Apache::lonuserutils::can_modify_userinfo($context,$ccdomain,
1.252 raeburn 2414: \@userinfo,$rolesarray);
1.257 raeburn 2415: } elsif ($context eq 'selfcreate') {
1.391 raeburn 2416: if ($newuser eq 'email') {
1.396 raeburn 2417: if (ref($emailusername) eq 'HASH') {
2418: if (ref($emailusername->{$usertype}) eq 'HASH') {
2419: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
1.442 raeburn 2420: @userinfo = ();
1.396 raeburn 2421: if ((ref($infofields) eq 'ARRAY') && (ref($infotitles) eq 'HASH')) {
2422: foreach my $field (@{$infofields}) {
2423: if ($emailusername->{$usertype}->{$field}) {
2424: push(@userinfo,$field);
2425: $canmodify{$field} = 1;
2426: unless ($textboxsize{$field}) {
2427: $textboxsize{$field} = 25;
2428: }
2429: unless ($lt{$field}) {
2430: $lt{$field} = $infotitles->{$field};
2431: }
2432: if ($emailusername->{$usertype}->{$field} eq 'required') {
2433: $lt{$field} .= '<b>*</b>';
2434: }
1.391 raeburn 2435: }
2436: }
2437: }
2438: }
2439: }
2440: } else {
2441: %canmodify = &selfcreate_canmodify($context,$ccdomain,\@userinfo,
2442: $inst_results,$rolesarray);
2443: }
1.188 raeburn 2444: }
1.391 raeburn 2445:
1.188 raeburn 2446: my $genhelp=&Apache::loncommon::help_open_topic('Generation');
2447: $output = '<h3>'.$lt{'pd'}.'</h3>'.
2448: &Apache::lonhtmlcommon::start_pick_box();
1.391 raeburn 2449: if (($context eq 'selfcreate') && ($newuser eq 'email')) {
1.443 raeburn 2450: my $size = 25;
1.442 raeburn 2451: if ($condition) {
1.443 raeburn 2452: if ($condition =~ /^\@[^\@]+$/) {
2453: $size = 10;
1.442 raeburn 2454: } else {
2455: undef($condition);
2456: }
1.443 raeburn 2457: }
2458: if ($excluded) {
2459: unless ($excluded =~ /^\@[^\@]+$/) {
2460: undef($condition);
2461: }
1.442 raeburn 2462: }
1.396 raeburn 2463: $output .= &Apache::lonhtmlcommon::row_title($lt{'email'}.'<b>*</b>',undef,
1.391 raeburn 2464: 'LC_oddrow_value')."\n".
1.443 raeburn 2465: '<input type="text" name="uname" size="'.$size.'" value="" autocomplete="off" />';
2466: if ($condition) {
2467: $output .= $condition;
2468: } elsif ($excluded) {
2469: $output .= '<br /><span style="font-size: smaller">'.&mt('You must use an e-mail address that does not end with [_1]',
2470: $excluded).'</span>';
2471: }
2472: if ($usernameset eq 'first') {
2473: $output .= '<br /><span style="font-size: smaller">';
2474: if ($condition) {
2475: $output .= &mt('Your username in LON-CAPA will be the part of your e-mail address before [_1]',
2476: $condition);
2477: } else {
2478: $output .= &mt('Your username in LON-CAPA will be the part of your e-mail address before the @');
2479: }
2480: $output .= '</span>';
2481: }
1.391 raeburn 2482: $rowcount ++;
2483: $output .= &Apache::lonhtmlcommon::row_closure(1);
1.408 raeburn 2484: my $upassone = '<input type="password" name="upass'.$now.'" size="20" autocomplete="off" />';
2485: my $upasstwo = '<input type="password" name="upasscheck'.$now.'" size="20" autocomplete="off" />';
1.396 raeburn 2486: $output .= &Apache::lonhtmlcommon::row_title(&mt('Password').'<b>*</b>',
1.391 raeburn 2487: 'LC_pick_box_title',
2488: 'LC_oddrow_value')."\n".
2489: $upassone."\n".
2490: &Apache::lonhtmlcommon::row_closure(1)."\n".
1.396 raeburn 2491: &Apache::lonhtmlcommon::row_title(&mt('Confirm password').'<b>*</b>',
1.391 raeburn 2492: 'LC_pick_box_title',
2493: 'LC_oddrow_value')."\n".
2494: $upasstwo.
2495: &Apache::lonhtmlcommon::row_closure()."\n";
1.443 raeburn 2496: if ($usernameset eq 'free') {
2497: my $onclick = "toggleUsernameDisp(this,'selfcreateusername');";
1.442 raeburn 2498: $output .= &Apache::lonhtmlcommon::row_title($lt{'username'},undef,'LC_oddrow_value')."\n".
2499: &mt('Use e-mail address: ').
2500: '<label><input type="radio" name="emailused" value="1" checked="checked" onclick="'.$onclick.'" />'.&mt('Yes').'</label>'."\n".
2501: (' 'x2).
2502: '<label><input type="radio" name="emailused" value="0" onclick="'.$onclick.'" />'.&mt('No').'</label>'."\n".
2503: '<div id="selfcreateusername" style="display: none; font-size: smaller">'.
2504: '<br /><span class="LC_nobreak">'.&mt('Preferred username').
2505: ' <input type="text" name="username" value="" size="20" autocomplete="off"/>'.
2506: '</span></div>'."\n".&Apache::lonhtmlcommon::row_closure(1);
2507: $rowcount ++;
2508: }
1.391 raeburn 2509: }
1.188 raeburn 2510: foreach my $item (@userinfo) {
2511: my $rowtitle = $lt{$item};
1.252 raeburn 2512: my $hiderow = 0;
1.188 raeburn 2513: if ($item eq 'generation') {
2514: $rowtitle = $genhelp.$rowtitle;
2515: }
1.252 raeburn 2516: my $row = &Apache::lonhtmlcommon::row_title($rowtitle,undef,'LC_oddrow_value')."\n";
1.188 raeburn 2517: if ($newuser) {
1.210 raeburn 2518: if (ref($inst_results) eq 'HASH') {
2519: if ($inst_results->{$item} ne '') {
1.252 raeburn 2520: $row .= '<input type="hidden" name="c'.$item.'" value="'.$inst_results->{$item}.'" />'.$inst_results->{$item};
1.210 raeburn 2521: } else {
1.252 raeburn 2522: if ($context eq 'selfcreate') {
1.391 raeburn 2523: if ($canmodify{$item}) {
1.394 raeburn 2524: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" autocomplete="off" />';
1.252 raeburn 2525: $editable ++;
2526: } else {
2527: $hiderow = 1;
2528: }
1.253 raeburn 2529: } else {
2530: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
1.252 raeburn 2531: }
1.210 raeburn 2532: }
1.188 raeburn 2533: } else {
1.252 raeburn 2534: if ($context eq 'selfcreate') {
1.401 raeburn 2535: if ($canmodify{$item}) {
2536: if ($newuser eq 'email') {
2537: $row .= '<input type="text" name="'.$item.'" size="'.$textboxsize{$item}.'" value="" autocomplete="off" />';
1.287 raeburn 2538: } else {
1.401 raeburn 2539: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" autocomplete="off" />';
1.287 raeburn 2540: }
1.401 raeburn 2541: $editable ++;
2542: } else {
2543: $hiderow = 1;
1.252 raeburn 2544: }
1.253 raeburn 2545: } else {
2546: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
1.252 raeburn 2547: }
1.188 raeburn 2548: }
2549: } else {
1.219 raeburn 2550: if ($canmodify{$item}) {
1.252 raeburn 2551: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="'.$userenv{$item}.'" />';
1.393 raeburn 2552: if (($item eq 'id') && (!$newuser)) {
2553: $row .= '<br />'.&Apache::lonuserutils::forceid_change($context);
2554: }
1.188 raeburn 2555: } else {
1.252 raeburn 2556: $row .= $userenv{$item};
1.188 raeburn 2557: }
2558: }
1.252 raeburn 2559: $row .= &Apache::lonhtmlcommon::row_closure(1);
2560: if (!$hiderow) {
2561: $output .= $row;
2562: $rowcount ++;
2563: }
1.188 raeburn 2564: }
1.286 raeburn 2565: if (($canmodify_status{'inststatus'}) || ($context ne 'selfcreate')) {
2566: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($ccdomain);
2567: if (ref($types) eq 'ARRAY') {
2568: if (@{$types} > 0) {
2569: my ($hiderow,$shown);
2570: if ($canmodify_status{'inststatus'}) {
2571: $shown = &pick_inst_statuses($userenv{'inststatus'},$usertypes,$types);
2572: } else {
2573: if ($userenv{'inststatus'} eq '') {
2574: $hiderow = 1;
1.334 raeburn 2575: } else {
2576: my @showitems;
2577: foreach my $item ( map { &unescape($_); } split(':',$userenv{'inststatus'})) {
2578: if (exists($usertypes->{$item})) {
2579: push(@showitems,$usertypes->{$item});
2580: } else {
2581: push(@showitems,$item);
2582: }
2583: }
2584: if (@showitems) {
2585: $shown = join(', ',@showitems);
2586: } else {
2587: $hiderow = 1;
2588: }
1.286 raeburn 2589: }
2590: }
2591: if (!$hiderow) {
1.389 bisitz 2592: my $row = &Apache::lonhtmlcommon::row_title(&mt('Affiliations'),undef,'LC_oddrow_value')."\n".
1.286 raeburn 2593: $shown.&Apache::lonhtmlcommon::row_closure(1);
2594: if ($context eq 'selfcreate') {
2595: $rowcount ++;
2596: }
2597: $output .= $row;
2598: }
2599: }
2600: }
2601: }
1.391 raeburn 2602: if (($context eq 'selfcreate') && ($newuser eq 'email')) {
2603: if ($captchaform) {
1.410 raeburn 2604: $output .= &Apache::lonhtmlcommon::row_title($lt{'valid'}.'*',
2605: 'LC_pick_box_title')."\n".
2606: $captchaform."\n".'<br /><br />'.
1.391 raeburn 2607: &Apache::lonhtmlcommon::row_closure(1);
2608: $rowcount ++;
2609: }
2610: my $submit_text = &mt('Create account');
2611: $output .= &Apache::lonhtmlcommon::row_title()."\n".
2612: '<br /><input type="submit" name="createaccount" value="'.
2613: $submit_text.'" />'.
1.396 raeburn 2614: '<input type="hidden" name="type" value="'.$usertype.'" />'.
1.391 raeburn 2615: &Apache::lonhtmlcommon::row_closure(1);
2616: }
1.188 raeburn 2617: $output .= &Apache::lonhtmlcommon::end_pick_box();
1.206 raeburn 2618: if (wantarray) {
1.252 raeburn 2619: if ($context eq 'selfcreate') {
2620: return($output,$rowcount,$editable);
2621: } else {
1.388 bisitz 2622: return $output;
1.252 raeburn 2623: }
1.206 raeburn 2624: } else {
2625: return $output;
2626: }
1.188 raeburn 2627: }
2628:
1.286 raeburn 2629: sub pick_inst_statuses {
2630: my ($curr,$usertypes,$types) = @_;
2631: my ($output,$rem,@currtypes);
2632: if ($curr ne '') {
2633: @currtypes = map { &unescape($_); } split(/:/,$curr);
2634: }
2635: my $numinrow = 2;
2636: if (ref($types) eq 'ARRAY') {
2637: $output = '<table>';
2638: my $lastcolspan;
2639: for (my $i=0; $i<@{$types}; $i++) {
2640: if (defined($usertypes->{$types->[$i]})) {
2641: my $rem = $i%($numinrow);
2642: if ($rem == 0) {
2643: if ($i<@{$types}-1) {
2644: if ($i > 0) {
2645: $output .= '</tr>';
2646: }
2647: $output .= '<tr>';
2648: }
2649: } elsif ($i==@{$types}-1) {
2650: my $colsleft = $numinrow - $rem;
2651: if ($colsleft > 1) {
2652: $lastcolspan = ' colspan="'.$colsleft.'"';
2653: }
2654: }
2655: my $check = ' ';
2656: if (grep(/^\Q$types->[$i]\E$/,@currtypes)) {
2657: $check = ' checked="checked" ';
2658: }
2659: $output .= '<td class="LC_left_item"'.$lastcolspan.'>'.
2660: '<span class="LC_nobreak"><label>'.
2661: '<input type="checkbox" name="inststatus" '.
2662: 'value="'.$types->[$i].'"'.$check.'/>'.
2663: $usertypes->{$types->[$i]}.'</label></span></td>';
2664: }
2665: }
2666: $output .= '</tr></table>';
2667: }
2668: return $output;
2669: }
2670:
1.257 raeburn 2671: sub selfcreate_canmodify {
2672: my ($context,$dom,$userinfo,$inst_results,$rolesarray) = @_;
2673: if (ref($inst_results) eq 'HASH') {
2674: my @inststatuses = &get_inststatuses($inst_results);
2675: if (@inststatuses == 0) {
2676: @inststatuses = ('default');
2677: }
2678: $rolesarray = \@inststatuses;
2679: }
2680: my %canmodify =
2681: &Apache::lonuserutils::can_modify_userinfo($context,$dom,$userinfo,
2682: $rolesarray);
2683: return %canmodify;
2684: }
2685:
1.252 raeburn 2686: sub get_inststatuses {
2687: my ($insthashref) = @_;
2688: my @inststatuses = ();
2689: if (ref($insthashref) eq 'HASH') {
2690: if (ref($insthashref->{'inststatus'}) eq 'ARRAY') {
2691: @inststatuses = @{$insthashref->{'inststatus'}};
2692: }
2693: }
2694: return @inststatuses;
2695: }
2696:
1.4 www 2697: # ================================================================= Phase Three
1.42 matthew 2698: sub update_user_data {
1.375 raeburn 2699: my ($r,$context,$crstype,$brcrum,$showcredits) = @_;
1.101 albertel 2700: my $uhome=&Apache::lonnet::homeserver($env{'form.ccuname'},
2701: $env{'form.ccdomain'});
1.27 matthew 2702: # Error messages
1.188 raeburn 2703: my $error = '<span class="LC_error">'.&mt('Error').': ';
1.193 raeburn 2704: my $end = '</span><br /><br />';
2705: my $rtnlink = '<a href="javascript:backPage(document.userupdate,'.
1.188 raeburn 2706: "'$env{'form.prevphase'}','modify')".'" />'.
1.219 raeburn 2707: &mt('Return to previous page').'</a>'.
2708: &Apache::loncommon::end_page();
2709: my $now = time;
1.40 www 2710: my $title;
1.101 albertel 2711: if (exists($env{'form.makeuser'})) {
1.40 www 2712: $title='Set Privileges for New User';
2713: } else {
2714: $title='Modify User Privileges';
2715: }
1.213 raeburn 2716: my $newuser = 0;
1.160 raeburn 2717: my ($jsback,$elements) = &crumb_utilities();
2718: my $jscript = '<script type="text/javascript">'."\n".
1.301 bisitz 2719: '// <![CDATA['."\n".
2720: $jsback."\n".
2721: '// ]]>'."\n".
2722: '</script>'."\n";
1.422 raeburn 2723: my %breadcrumb_text = &singleuser_breadcrumb($crstype,$context,$env{'form.ccdomain'});
1.351 raeburn 2724: push (@{$brcrum},
2725: {href => "javascript:backPage(document.userupdate)",
2726: text => $breadcrumb_text{'search'},
2727: faq => 282,
2728: bug => 'Instructor Interface',}
2729: );
2730: if ($env{'form.prevphase'} eq 'userpicked') {
2731: push(@{$brcrum},
2732: {href => "javascript:backPage(document.userupdate,'get_user_info','select')",
2733: text => $breadcrumb_text{'userpicked'},
2734: faq => 282,
2735: bug => 'Instructor Interface',});
1.233 raeburn 2736: }
1.224 raeburn 2737: my $helpitem = 'Course_Change_Privileges';
2738: if ($env{'form.action'} eq 'singlestudent') {
2739: $helpitem = 'Course_Add_Student';
1.439 raeburn 2740: } elsif ($context eq 'author') {
2741: $helpitem = 'Author_Change_Privileges';
2742: } elsif ($context eq 'domain') {
2743: $helpitem = 'Domain_Change_Privileges';
1.224 raeburn 2744: }
1.351 raeburn 2745: push(@{$brcrum},
2746: {href => "javascript:backPage(document.userupdate,'$env{'form.prevphase'}','modify')",
2747: text => $breadcrumb_text{'modify'},
2748: faq => 282,
2749: bug => 'Instructor Interface',},
2750: {href => "/adm/createuser",
2751: text => "Result",
2752: faq => 282,
2753: bug => 'Instructor Interface',
2754: help => $helpitem});
2755: my $args = {bread_crumbs => $brcrum,
2756: bread_crumbs_component => 'User Management'};
2757: if ($env{'form.popup'}) {
2758: $args->{'no_nav_bar'} = 1;
2759: }
2760: $r->print(&Apache::loncommon::start_page($title,$jscript,$args));
1.188 raeburn 2761: $r->print(&update_result_form($uhome));
1.27 matthew 2762: # Check Inputs
1.101 albertel 2763: if (! $env{'form.ccuname'} ) {
1.193 raeburn 2764: $r->print($error.&mt('No login name specified').'.'.$end.$rtnlink);
1.27 matthew 2765: return;
2766: }
1.138 albertel 2767: if ( $env{'form.ccuname'} ne
2768: &LONCAPA::clean_username($env{'form.ccuname'}) ) {
1.281 bisitz 2769: $r->print($error.&mt('Invalid login name.').' '.
2770: &mt('Only letters, numbers, periods, dashes, @, and underscores are valid.').
1.193 raeburn 2771: $end.$rtnlink);
1.27 matthew 2772: return;
2773: }
1.101 albertel 2774: if (! $env{'form.ccdomain'} ) {
1.193 raeburn 2775: $r->print($error.&mt('No domain specified').'.'.$end.$rtnlink);
1.27 matthew 2776: return;
2777: }
1.138 albertel 2778: if ( $env{'form.ccdomain'} ne
2779: &LONCAPA::clean_domain($env{'form.ccdomain'}) ) {
1.281 bisitz 2780: $r->print($error.&mt('Invalid domain name.').' '.
2781: &mt('Only letters, numbers, periods, dashes, and underscores are valid.').
1.193 raeburn 2782: $end.$rtnlink);
1.27 matthew 2783: return;
2784: }
1.219 raeburn 2785: if ($uhome eq 'no_host') {
2786: $newuser = 1;
2787: }
1.101 albertel 2788: if (! exists($env{'form.makeuser'})) {
1.29 matthew 2789: # Modifying an existing user, so check the validity of the name
2790: if ($uhome eq 'no_host') {
1.389 bisitz 2791: $r->print(
2792: $error
2793: .'<p class="LC_error">'
2794: .&mt('Unable to determine home server for [_1] in domain [_2].',
2795: '"'.$env{'form.ccuname'}.'"','"'.$env{'form.ccdomain'}.'"')
2796: .'</p>');
1.29 matthew 2797: return;
2798: }
2799: }
1.27 matthew 2800: # Determine authentication method and password for the user being modified
2801: my $amode='';
2802: my $genpwd='';
1.101 albertel 2803: if ($env{'form.login'} eq 'krb') {
1.41 albertel 2804: $amode='krb';
1.101 albertel 2805: $amode.=$env{'form.krbver'};
2806: $genpwd=$env{'form.krbarg'};
2807: } elsif ($env{'form.login'} eq 'int') {
1.27 matthew 2808: $amode='internal';
1.101 albertel 2809: $genpwd=$env{'form.intarg'};
2810: } elsif ($env{'form.login'} eq 'fsys') {
1.27 matthew 2811: $amode='unix';
1.101 albertel 2812: $genpwd=$env{'form.fsysarg'};
2813: } elsif ($env{'form.login'} eq 'loc') {
1.27 matthew 2814: $amode='localauth';
1.101 albertel 2815: $genpwd=$env{'form.locarg'};
1.27 matthew 2816: $genpwd=" " if (!$genpwd);
1.101 albertel 2817: } elsif (($env{'form.login'} eq 'nochange') ||
2818: ($env{'form.login'} eq '' )) {
1.34 matthew 2819: # There is no need to tell the user we did not change what they
2820: # did not ask us to change.
1.35 matthew 2821: # If they are creating a new user but have not specified login
2822: # information this will be caught below.
1.30 matthew 2823: } else {
1.367 golterma 2824: $r->print($error.&mt('Invalid login mode or password').$end.$rtnlink);
2825: return;
1.27 matthew 2826: }
1.164 albertel 2827:
1.188 raeburn 2828: $r->print('<h3>'.&mt('User [_1] in domain [_2]',
1.367 golterma 2829: $env{'form.ccuname'}.' ('.&Apache::loncommon::plainname($env{'form.ccuname'},
2830: $env{'form.ccdomain'}).')', $env{'form.ccdomain'}).'</h3>');
2831: my %prog_state = &Apache::lonhtmlcommon::Create_PrgWin($r,2);
1.344 bisitz 2832:
1.193 raeburn 2833: my (%alerts,%rulematch,%inst_results,%curr_rules);
1.334 raeburn 2834: my @userinfo = ('firstname','middlename','lastname','generation','permanentemail','id');
1.361 raeburn 2835: my @usertools = ('aboutme','blog','webdav','portfolio');
1.411 raeburn 2836: my @requestcourses = ('official','unofficial','community','textbook','placement');
1.362 raeburn 2837: my @requestauthor = ('requestauthor');
1.286 raeburn 2838: my ($othertitle,$usertypes,$types) =
2839: &Apache::loncommon::sorted_inst_types($env{'form.ccdomain'});
1.334 raeburn 2840: my %canmodify_status =
2841: &Apache::lonuserutils::can_modify_userinfo($context,$env{'form.ccdomain'},
2842: ['inststatus']);
1.101 albertel 2843: if ($env{'form.makeuser'}) {
1.164 albertel 2844: $r->print('<h3>'.&mt('Creating new account.').'</h3>');
1.27 matthew 2845: # Check for the authentication mode and password
2846: if (! $amode || ! $genpwd) {
1.193 raeburn 2847: $r->print($error.&mt('Invalid login mode or password').$end.$rtnlink);
1.27 matthew 2848: return;
1.18 albertel 2849: }
1.29 matthew 2850: # Determine desired host
1.101 albertel 2851: my $desiredhost = $env{'form.hserver'};
1.29 matthew 2852: if (lc($desiredhost) eq 'default') {
2853: $desiredhost = undef;
2854: } else {
1.147 albertel 2855: my %home_servers =
2856: &Apache::lonnet::get_servers($env{'form.ccdomain'},'library');
1.29 matthew 2857: if (! exists($home_servers{$desiredhost})) {
1.193 raeburn 2858: $r->print($error.&mt('Invalid home server specified').$end.$rtnlink);
2859: return;
2860: }
2861: }
2862: # Check ID format
2863: my %checkhash;
2864: my %checks = ('id' => 1);
2865: %{$checkhash{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}}} = (
1.219 raeburn 2866: 'newuser' => $newuser,
1.196 raeburn 2867: 'id' => $env{'form.cid'},
1.193 raeburn 2868: );
1.196 raeburn 2869: if ($env{'form.cid'} ne '') {
2870: &Apache::loncommon::user_rule_check(\%checkhash,\%checks,\%alerts,
2871: \%rulematch,\%inst_results,\%curr_rules);
2872: if (ref($alerts{'id'}) eq 'HASH') {
2873: if (ref($alerts{'id'}{$env{'form.ccdomain'}}) eq 'HASH') {
2874: my $domdesc =
2875: &Apache::lonnet::domain($env{'form.ccdomain'},'description');
2876: if ($alerts{'id'}{$env{'form.ccdomain'}}{$env{'form.cid'}}) {
2877: my $userchkmsg;
2878: if (ref($curr_rules{$env{'form.ccdomain'}}) eq 'HASH') {
2879: $userchkmsg =
2880: &Apache::loncommon::instrule_disallow_msg('id',
2881: $domdesc,1).
2882: &Apache::loncommon::user_rule_formats($env{'form.ccdomain'},
2883: $domdesc,$curr_rules{$env{'form.ccdomain'}}{'id'},'id');
2884: }
2885: $r->print($error.&mt('Invalid ID format').$end.
2886: $userchkmsg.$rtnlink);
2887: return;
2888: }
2889: }
1.29 matthew 2890: }
2891: }
1.367 golterma 2892: &Apache::lonhtmlcommon::Increment_PrgWin($r, \%prog_state);
1.27 matthew 2893: # Call modifyuser
2894: my $result = &Apache::lonnet::modifyuser
1.193 raeburn 2895: ($env{'form.ccdomain'},$env{'form.ccuname'},$env{'form.cid'},
1.188 raeburn 2896: $amode,$genpwd,$env{'form.cfirstname'},
2897: $env{'form.cmiddlename'},$env{'form.clastname'},
2898: $env{'form.cgeneration'},undef,$desiredhost,
2899: $env{'form.cpermanentemail'});
1.77 www 2900: $r->print(&mt('Generating user').': '.$result);
1.219 raeburn 2901: $uhome = &Apache::lonnet::homeserver($env{'form.ccuname'},
1.101 albertel 2902: $env{'form.ccdomain'});
1.334 raeburn 2903: my (%changeHash,%newcustom,%changed,%changedinfo);
1.267 raeburn 2904: if ($uhome ne 'no_host') {
1.334 raeburn 2905: if ($context eq 'domain') {
1.378 raeburn 2906: foreach my $name ('portfolio','author') {
2907: if ($env{'form.custom_'.$name.'quota'} == 1) {
2908: if ($env{'form.'.$name.'quota'} eq '') {
2909: $newcustom{$name.'quota'} = 0;
2910: } else {
2911: $newcustom{$name.'quota'} = $env{'form.'.$name.'quota'};
2912: $newcustom{$name.'quota'} =~ s/[^\d\.]//g;
2913: }
2914: if ("a_admin($newcustom{$name.'quota'},\%changeHash,$name)) {
2915: $changed{$name.'quota'} = 1;
2916: }
1.334 raeburn 2917: }
2918: }
2919: foreach my $item (@usertools) {
2920: if ($env{'form.custom'.$item} == 1) {
2921: $newcustom{$item} = $env{'form.tools_'.$item};
2922: $changed{$item} = &tool_admin($item,$newcustom{$item},
2923: \%changeHash,'tools');
2924: }
1.267 raeburn 2925: }
1.334 raeburn 2926: foreach my $item (@requestcourses) {
1.341 raeburn 2927: if ($env{'form.custom'.$item} == 1) {
2928: $newcustom{$item} = $env{'form.crsreq_'.$item};
2929: if ($env{'form.crsreq_'.$item} eq 'autolimit') {
2930: $newcustom{$item} .= '=';
1.383 raeburn 2931: $env{'form.crsreq_'.$item.'_limit'} =~ s/\D+//g;
2932: if ($env{'form.crsreq_'.$item.'_limit'}) {
1.341 raeburn 2933: $newcustom{$item} .= $env{'form.crsreq_'.$item.'_limit'};
2934: }
1.334 raeburn 2935: }
1.341 raeburn 2936: $changed{$item} = &tool_admin($item,$newcustom{$item},
2937: \%changeHash,'requestcourses');
1.334 raeburn 2938: }
1.275 raeburn 2939: }
1.362 raeburn 2940: if ($env{'form.customrequestauthor'} == 1) {
2941: $newcustom{'requestauthor'} = $env{'form.requestauthor'};
2942: $changed{'requestauthor'} = &tool_admin('requestauthor',
2943: $newcustom{'requestauthor'},
2944: \%changeHash,'requestauthor');
2945: }
1.275 raeburn 2946: }
1.334 raeburn 2947: if ($canmodify_status{'inststatus'}) {
2948: if (exists($env{'form.inststatus'})) {
2949: my @inststatuses = &Apache::loncommon::get_env_multiple('form.inststatus');
2950: if (@inststatuses > 0) {
2951: $changeHash{'inststatus'} = join(',',@inststatuses);
2952: $changed{'inststatus'} = $changeHash{'inststatus'};
1.306 raeburn 2953: }
2954: }
1.232 raeburn 2955: }
1.334 raeburn 2956: if (keys(%changed)) {
2957: foreach my $item (@userinfo) {
2958: $changeHash{$item} = $env{'form.c'.$item};
1.286 raeburn 2959: }
1.267 raeburn 2960: my $chgresult =
2961: &Apache::lonnet::put('environment',\%changeHash,
2962: $env{'form.ccdomain'},$env{'form.ccuname'});
2963: }
1.232 raeburn 2964: }
1.219 raeburn 2965: $r->print('<br />'.&mt('Home server').': '.$uhome.' '.
2966: &Apache::lonnet::hostname($uhome));
1.101 albertel 2967: } elsif (($env{'form.login'} ne 'nochange') &&
2968: ($env{'form.login'} ne '' )) {
1.27 matthew 2969: # Modify user privileges
2970: if (! $amode || ! $genpwd) {
1.193 raeburn 2971: $r->print($error.'Invalid login mode or password'.$end.$rtnlink);
1.27 matthew 2972: return;
1.20 harris41 2973: }
1.395 bisitz 2974: # Only allow authentication modification if the person has authority
1.101 albertel 2975: if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'})) {
1.20 harris41 2976: $r->print('Modifying authentication: '.
1.31 matthew 2977: &Apache::lonnet::modifyuserauth(
1.101 albertel 2978: $env{'form.ccdomain'},$env{'form.ccuname'},
1.21 harris41 2979: $amode,$genpwd));
1.102 albertel 2980: $r->print('<br />'.&mt('Home server').': '.&Apache::lonnet::homeserver
1.101 albertel 2981: ($env{'form.ccuname'},$env{'form.ccdomain'}));
1.4 www 2982: } else {
1.27 matthew 2983: # Okay, this is a non-fatal error.
1.395 bisitz 2984: $r->print($error.&mt('You do not have the authority to modify this users authentication information.').$end);
1.27 matthew 2985: }
1.28 matthew 2986: }
1.344 bisitz 2987: $r->rflush(); # Finish display of header before time consuming actions start
1.367 golterma 2988: &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state);
1.28 matthew 2989: ##
1.375 raeburn 2990: my (@userroles,%userupdate,$cnum,$cdom,$defaultcredits,%namechanged);
1.213 raeburn 2991: if ($context eq 'course') {
1.375 raeburn 2992: ($cnum,$cdom) =
2993: &Apache::lonuserutils::get_course_identity();
1.318 raeburn 2994: $crstype = &Apache::loncommon::course_type($cdom.'_'.$cnum);
1.375 raeburn 2995: if ($showcredits) {
2996: $defaultcredits = &Apache::lonuserutils::get_defaultcredits($cdom,$cnum);
2997: }
1.213 raeburn 2998: }
1.101 albertel 2999: if (! $env{'form.makeuser'} ) {
1.28 matthew 3000: # Check for need to change
3001: my %userenv = &Apache::lonnet::get
1.134 raeburn 3002: ('environment',['firstname','middlename','lastname','generation',
1.378 raeburn 3003: 'id','permanentemail','portfolioquota','authorquota','inststatus',
3004: 'tools.aboutme','tools.blog','tools.webdav','tools.portfolio',
1.361 raeburn 3005: 'requestcourses.official','requestcourses.unofficial',
1.384 raeburn 3006: 'requestcourses.community','requestcourses.textbook',
3007: 'reqcrsotherdom.official','reqcrsotherdom.unofficial',
3008: 'reqcrsotherdom.community','reqcrsotherdom.textbook',
1.427 raeburn 3009: 'reqcrsotherdom.placement','requestauthor'],
1.160 raeburn 3010: $env{'form.ccdomain'},$env{'form.ccuname'});
1.28 matthew 3011: my ($tmp) = keys(%userenv);
3012: if ($tmp =~ /^(con_lost|error)/i) {
3013: %userenv = ();
3014: }
1.206 raeburn 3015: my $no_forceid_alert;
3016: # Check to see if user information can be changed
3017: my %domconfig =
3018: &Apache::lonnet::get_dom('configuration',['usermodification'],
3019: $env{'form.ccdomain'});
1.213 raeburn 3020: my @statuses = ('active','future');
3021: my %roles = &Apache::lonnet::get_my_roles($env{'form.ccuname'},$env{'form.ccdomain'},'userroles',\@statuses,undef,$env{'request.role.domain'});
3022: my ($auname,$audom);
1.220 raeburn 3023: if ($context eq 'author') {
1.206 raeburn 3024: $auname = $env{'user.name'};
3025: $audom = $env{'user.domain'};
3026: }
3027: foreach my $item (keys(%roles)) {
1.220 raeburn 3028: my ($rolenum,$roledom,$role) = split(/:/,$item,-1);
1.206 raeburn 3029: if ($context eq 'course') {
3030: if ($cnum ne '' && $cdom ne '') {
3031: if ($rolenum eq $cnum && $roledom eq $cdom) {
3032: if (!grep(/^\Q$role\E$/,@userroles)) {
3033: push(@userroles,$role);
3034: }
3035: }
3036: }
3037: } elsif ($context eq 'author') {
3038: if ($rolenum eq $auname && $roledom eq $audom) {
3039: if (!grep(/^\Q$role\E$/,@userroles)) {
3040: push(@userroles,$role);
3041: }
3042: }
3043: }
3044: }
1.220 raeburn 3045: if ($env{'form.action'} eq 'singlestudent') {
3046: if (!grep(/^st$/,@userroles)) {
3047: push(@userroles,'st');
3048: }
3049: } else {
3050: # Check for course or co-author roles being activated or re-enabled
3051: if ($context eq 'author' || $context eq 'course') {
3052: foreach my $key (keys(%env)) {
3053: if ($context eq 'author') {
3054: if ($key=~/^form\.act_\Q$audom\E_\Q$auname\E_([^_]+)/) {
3055: if (!grep(/^\Q$1\E$/,@userroles)) {
3056: push(@userroles,$1);
3057: }
3058: } elsif ($key =~/^form\.ren\:\Q$audom\E\/\Q$auname\E_([^_]+)/) {
3059: if (!grep(/^\Q$1\E$/,@userroles)) {
3060: push(@userroles,$1);
3061: }
1.206 raeburn 3062: }
1.220 raeburn 3063: } elsif ($context eq 'course') {
3064: if ($key=~/^form\.act_\Q$cdom\E_\Q$cnum\E_([^_]+)/) {
3065: if (!grep(/^\Q$1\E$/,@userroles)) {
3066: push(@userroles,$1);
3067: }
3068: } elsif ($key =~/^form\.ren\:\Q$cdom\E\/\Q$cnum\E(\/?\w*)_([^_]+)/) {
3069: if (!grep(/^\Q$1\E$/,@userroles)) {
3070: push(@userroles,$1);
3071: }
1.206 raeburn 3072: }
3073: }
3074: }
3075: }
3076: }
3077: #Check to see if we can change personal data for the user
3078: my (@mod_disallowed,@longroles);
3079: foreach my $role (@userroles) {
3080: if ($role eq 'cr') {
3081: push(@longroles,'Custom');
3082: } else {
1.318 raeburn 3083: push(@longroles,&Apache::lonnet::plaintext($role,$crstype));
1.206 raeburn 3084: }
3085: }
1.219 raeburn 3086: my %canmodify = &Apache::lonuserutils::can_modify_userinfo($context,$env{'form.ccdomain'},\@userinfo,\@userroles);
3087: foreach my $item (@userinfo) {
1.28 matthew 3088: # Strip leading and trailing whitespace
1.203 raeburn 3089: $env{'form.c'.$item} =~ s/(\s+$|^\s+)//g;
1.219 raeburn 3090: if (!$canmodify{$item}) {
1.207 raeburn 3091: if (defined($env{'form.c'.$item})) {
3092: if ($env{'form.c'.$item} ne $userenv{$item}) {
3093: push(@mod_disallowed,$item);
3094: }
1.206 raeburn 3095: }
3096: $env{'form.c'.$item} = $userenv{$item};
3097: }
1.28 matthew 3098: }
1.259 bisitz 3099: # Check to see if we can change the Student/Employee ID
1.196 raeburn 3100: my $forceid = $env{'form.forceid'};
3101: my $recurseid = $env{'form.recurseid'};
3102: my (%alerts,%rulematch,%idinst_results,%curr_rules,%got_rules);
1.203 raeburn 3103: my %uidhash = &Apache::lonnet::idrget($env{'form.ccdomain'},
3104: $env{'form.ccuname'});
3105: if (($uidhash{$env{'form.ccuname'}}) &&
3106: ($uidhash{$env{'form.ccuname'}}!~/error\:/) &&
3107: (!$forceid)) {
3108: if ($env{'form.cid'} ne $uidhash{$env{'form.ccuname'}}) {
3109: $env{'form.cid'} = $userenv{'id'};
1.293 bisitz 3110: $no_forceid_alert = &mt('New student/employee ID does not match existing ID for this user.')
1.259 bisitz 3111: .'<br />'
3112: .&mt("Change is not permitted without checking the 'Force ID change' checkbox on the previous page.")
3113: .'<br />'."\n";
1.203 raeburn 3114: }
3115: }
3116: if ($env{'form.cid'} ne $userenv{'id'}) {
1.196 raeburn 3117: my $checkhash;
3118: my $checks = { 'id' => 1 };
3119: $checkhash->{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}} =
3120: { 'newuser' => $newuser,
3121: 'id' => $env{'form.cid'},
3122: };
3123: &Apache::loncommon::user_rule_check($checkhash,$checks,
3124: \%alerts,\%rulematch,\%idinst_results,\%curr_rules,\%got_rules);
3125: if (ref($alerts{'id'}) eq 'HASH') {
3126: if (ref($alerts{'id'}{$env{'form.ccdomain'}}) eq 'HASH') {
1.203 raeburn 3127: $env{'form.cid'} = $userenv{'id'};
1.196 raeburn 3128: }
3129: }
3130: }
1.378 raeburn 3131: my (%quotachanged,%oldquota,%newquota,%olddefquota,%newdefquota,
3132: $oldinststatus,$newinststatus,%oldisdefault,%newisdefault,%oldsettings,
1.339 raeburn 3133: %oldsettingstext,%newsettings,%newsettingstext,@disporder,
1.378 raeburn 3134: %oldsettingstatus,%newsettingstatus);
1.334 raeburn 3135: @disporder = ('inststatus');
3136: if ($env{'request.role.domain'} eq $env{'form.ccdomain'}) {
1.362 raeburn 3137: push(@disporder,'requestcourses','requestauthor');
1.334 raeburn 3138: } else {
3139: push(@disporder,'reqcrsotherdom');
3140: }
3141: push(@disporder,('quota','tools'));
1.338 raeburn 3142: $oldinststatus = $userenv{'inststatus'};
1.378 raeburn 3143: foreach my $name ('portfolio','author') {
3144: ($olddefquota{$name},$oldsettingstatus{$name}) =
3145: &Apache::loncommon::default_quota($env{'form.ccdomain'},$oldinststatus,$name);
3146: ($newdefquota{$name},$newsettingstatus{$name}) = ($olddefquota{$name},$oldsettingstatus{$name});
3147: }
1.334 raeburn 3148: my %canshow;
1.220 raeburn 3149: if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
1.334 raeburn 3150: $canshow{'quota'} = 1;
1.220 raeburn 3151: }
1.267 raeburn 3152: if (&Apache::lonnet::allowed('mut',$env{'form.ccdomain'})) {
1.334 raeburn 3153: $canshow{'tools'} = 1;
1.267 raeburn 3154: }
1.275 raeburn 3155: if (&Apache::lonnet::allowed('ccc',$env{'form.ccdomain'})) {
1.334 raeburn 3156: $canshow{'requestcourses'} = 1;
1.300 raeburn 3157: } elsif (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
1.334 raeburn 3158: $canshow{'reqcrsotherdom'} = 1;
1.275 raeburn 3159: }
1.286 raeburn 3160: if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'})) {
1.334 raeburn 3161: $canshow{'inststatus'} = 1;
1.286 raeburn 3162: }
1.362 raeburn 3163: if (&Apache::lonnet::allowed('cau',$env{'form.ccdomain'})) {
3164: $canshow{'requestauthor'} = 1;
3165: }
1.267 raeburn 3166: my (%changeHash,%changed);
1.286 raeburn 3167: if ($oldinststatus eq '') {
1.334 raeburn 3168: $oldsettings{'inststatus'} = $othertitle;
1.286 raeburn 3169: } else {
3170: if (ref($usertypes) eq 'HASH') {
1.334 raeburn 3171: $oldsettings{'inststatus'} = join(', ',map{ $usertypes->{ &unescape($_) }; } (split(/:/,$userenv{'inststatus'})));
1.286 raeburn 3172: } else {
1.334 raeburn 3173: $oldsettings{'inststatus'} = join(', ',map{ &unescape($_); } (split(/:/,$userenv{'inststatus'})));
1.286 raeburn 3174: }
3175: }
3176: $changeHash{'inststatus'} = $userenv{'inststatus'};
1.334 raeburn 3177: if ($canmodify_status{'inststatus'}) {
3178: $canshow{'inststatus'} = 1;
1.286 raeburn 3179: if (exists($env{'form.inststatus'})) {
3180: my @inststatuses = &Apache::loncommon::get_env_multiple('form.inststatus');
3181: if (@inststatuses > 0) {
3182: $newinststatus = join(':',map { &escape($_); } @inststatuses);
3183: $changeHash{'inststatus'} = $newinststatus;
3184: if ($newinststatus ne $oldinststatus) {
3185: $changed{'inststatus'} = $newinststatus;
1.378 raeburn 3186: foreach my $name ('portfolio','author') {
3187: ($newdefquota{$name},$newsettingstatus{$name}) =
3188: &Apache::loncommon::default_quota($env{'form.ccdomain'},$newinststatus,$name);
3189: }
1.286 raeburn 3190: }
3191: if (ref($usertypes) eq 'HASH') {
1.334 raeburn 3192: $newsettings{'inststatus'} = join(', ',map{ $usertypes->{$_}; } (@inststatuses));
1.286 raeburn 3193: } else {
1.337 raeburn 3194: $newsettings{'inststatus'} = join(', ',@inststatuses);
1.286 raeburn 3195: }
1.334 raeburn 3196: }
3197: } else {
3198: $newinststatus = '';
3199: $changeHash{'inststatus'} = $newinststatus;
3200: $newsettings{'inststatus'} = $othertitle;
3201: if ($newinststatus ne $oldinststatus) {
3202: $changed{'inststatus'} = $changeHash{'inststatus'};
1.378 raeburn 3203: foreach my $name ('portfolio','author') {
3204: ($newdefquota{$name},$newsettingstatus{$name}) =
3205: &Apache::loncommon::default_quota($env{'form.ccdomain'},$newinststatus,$name);
3206: }
1.286 raeburn 3207: }
3208: }
1.334 raeburn 3209: } elsif ($context ne 'selfcreate') {
3210: $canshow{'inststatus'} = 1;
1.337 raeburn 3211: $newsettings{'inststatus'} = $oldsettings{'inststatus'};
1.286 raeburn 3212: }
1.378 raeburn 3213: foreach my $name ('portfolio','author') {
3214: $changeHash{$name.'quota'} = $userenv{$name.'quota'};
3215: }
1.334 raeburn 3216: if ($context eq 'domain') {
1.378 raeburn 3217: foreach my $name ('portfolio','author') {
3218: if ($userenv{$name.'quota'} ne '') {
3219: $oldquota{$name} = $userenv{$name.'quota'};
3220: if ($env{'form.custom_'.$name.'quota'} == 1) {
3221: if ($env{'form.'.$name.'quota'} eq '') {
3222: $newquota{$name} = 0;
3223: } else {
3224: $newquota{$name} = $env{'form.'.$name.'quota'};
3225: $newquota{$name} =~ s/[^\d\.]//g;
3226: }
3227: if ($newquota{$name} != $oldquota{$name}) {
3228: if ("a_admin($newquota{$name},\%changeHash,$name)) {
3229: $changed{$name.'quota'} = 1;
3230: }
3231: }
1.334 raeburn 3232: } else {
1.378 raeburn 3233: if ("a_admin('',\%changeHash,$name)) {
3234: $changed{$name.'quota'} = 1;
3235: $newquota{$name} = $newdefquota{$name};
3236: $newisdefault{$name} = 1;
3237: }
1.334 raeburn 3238: }
1.149 raeburn 3239: } else {
1.378 raeburn 3240: $oldisdefault{$name} = 1;
3241: $oldquota{$name} = $olddefquota{$name};
3242: if ($env{'form.custom_'.$name.'quota'} == 1) {
3243: if ($env{'form.'.$name.'quota'} eq '') {
3244: $newquota{$name} = 0;
3245: } else {
3246: $newquota{$name} = $env{'form.'.$name.'quota'};
3247: $newquota{$name} =~ s/[^\d\.]//g;
3248: }
3249: if ("a_admin($newquota{$name},\%changeHash,$name)) {
3250: $changed{$name.'quota'} = 1;
3251: }
1.334 raeburn 3252: } else {
1.378 raeburn 3253: $newquota{$name} = $newdefquota{$name};
3254: $newisdefault{$name} = 1;
1.334 raeburn 3255: }
1.378 raeburn 3256: }
3257: if ($oldisdefault{$name}) {
3258: $oldsettingstext{'quota'}{$name} = &get_defaultquota_text($oldsettingstatus{$name});
1.383 raeburn 3259: } else {
3260: $oldsettingstext{'quota'}{$name} = &mt('custom quota: [_1] MB',$oldquota{$name});
1.378 raeburn 3261: }
3262: if ($newisdefault{$name}) {
3263: $newsettingstext{'quota'}{$name} = &get_defaultquota_text($newsettingstatus{$name});
1.383 raeburn 3264: } else {
3265: $newsettingstext{'quota'}{$name} = &mt('custom quota: [_1] MB',$newquota{$name});
1.134 raeburn 3266: }
3267: }
1.334 raeburn 3268: &tool_changes('tools',\@usertools,\%oldsettings,\%oldsettingstext,\%userenv,
3269: \%changeHash,\%changed,\%newsettings,\%newsettingstext);
3270: if ($env{'form.ccdomain'} eq $env{'request.role.domain'}) {
3271: &tool_changes('requestcourses',\@requestcourses,\%oldsettings,\%oldsettingstext,
3272: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
1.384 raeburn 3273: &tool_changes('requestauthor',\@requestauthor,\%oldsettings,\%oldsettingstext,
3274: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
1.149 raeburn 3275: } else {
1.334 raeburn 3276: &tool_changes('reqcrsotherdom',\@requestcourses,\%oldsettings,\%oldsettingstext,
3277: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
1.149 raeburn 3278: }
3279: }
1.334 raeburn 3280: foreach my $item (@userinfo) {
3281: if ($env{'form.c'.$item} ne $userenv{$item}) {
3282: $namechanged{$item} = 1;
3283: }
1.204 raeburn 3284: }
1.378 raeburn 3285: foreach my $name ('portfolio','author') {
1.390 bisitz 3286: $oldsettings{'quota'}{$name} = &mt('[_1] MB',$oldquota{$name});
3287: $newsettings{'quota'}{$name} = &mt('[_1] MB',$newquota{$name});
1.378 raeburn 3288: }
1.334 raeburn 3289: if ((keys(%namechanged) > 0) || (keys(%changed) > 0)) {
1.267 raeburn 3290: my ($chgresult,$namechgresult);
3291: if (keys(%changed) > 0) {
3292: $chgresult =
1.204 raeburn 3293: &Apache::lonnet::put('environment',\%changeHash,
3294: $env{'form.ccdomain'},$env{'form.ccuname'});
1.267 raeburn 3295: if ($chgresult eq 'ok') {
3296: if (($env{'user.name'} eq $env{'form.ccuname'}) &&
3297: ($env{'user.domain'} eq $env{'form.ccdomain'})) {
1.270 raeburn 3298: my %newenvhash;
3299: foreach my $key (keys(%changed)) {
1.411 raeburn 3300: if (($key eq 'official') || ($key eq 'unofficial') ||
3301: ($key eq 'community') || ($key eq 'textbook') ||
3302: ($key eq 'placement')) {
1.279 raeburn 3303: $newenvhash{'environment.requestcourses.'.$key} =
3304: $changeHash{'requestcourses.'.$key};
1.362 raeburn 3305: if ($changeHash{'requestcourses.'.$key}) {
1.332 raeburn 3306: $newenvhash{'environment.canrequest.'.$key} = 1;
1.279 raeburn 3307: } else {
3308: $newenvhash{'environment.canrequest.'.$key} =
3309: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
3310: $key,'reload','requestcourses');
3311: }
1.362 raeburn 3312: } elsif ($key eq 'requestauthor') {
3313: $newenvhash{'environment.'.$key} = $changeHash{$key};
3314: if ($changeHash{$key}) {
3315: $newenvhash{'environment.canrequest.author'} = 1;
3316: } else {
3317: $newenvhash{'environment.canrequest.author'} =
3318: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
3319: $key,'reload','requestauthor');
3320: }
1.275 raeburn 3321: } elsif ($key ne 'quota') {
1.270 raeburn 3322: $newenvhash{'environment.tools.'.$key} =
3323: $changeHash{'tools.'.$key};
1.279 raeburn 3324: if ($changeHash{'tools.'.$key} ne '') {
3325: $newenvhash{'environment.availabletools.'.$key} =
3326: $changeHash{'tools.'.$key};
3327: } else {
3328: $newenvhash{'environment.availabletools.'.$key} =
1.367 golterma 3329: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
3330: $key,'reload','tools');
1.279 raeburn 3331: }
1.270 raeburn 3332: }
3333: }
1.271 raeburn 3334: if (keys(%newenvhash)) {
3335: &Apache::lonnet::appenv(\%newenvhash);
3336: }
1.267 raeburn 3337: }
3338: }
1.204 raeburn 3339: }
1.334 raeburn 3340: if (keys(%namechanged) > 0) {
1.337 raeburn 3341: foreach my $field (@userinfo) {
3342: $changeHash{$field} = $env{'form.c'.$field};
3343: }
3344: # Make the change
1.204 raeburn 3345: $namechgresult =
3346: &Apache::lonnet::modifyuser($env{'form.ccdomain'},
3347: $env{'form.ccuname'},$changeHash{'id'},undef,undef,
3348: $changeHash{'firstname'},$changeHash{'middlename'},
3349: $changeHash{'lastname'},$changeHash{'generation'},
1.337 raeburn 3350: $changeHash{'id'},undef,$changeHash{'permanentemail'},undef,\@userinfo);
1.220 raeburn 3351: %userupdate = (
3352: lastname => $env{'form.clastname'},
3353: middlename => $env{'form.cmiddlename'},
3354: firstname => $env{'form.cfirstname'},
3355: generation => $env{'form.cgeneration'},
3356: id => $env{'form.cid'},
3357: );
1.204 raeburn 3358: }
1.334 raeburn 3359: if (((keys(%namechanged) > 0) && $namechgresult eq 'ok') ||
1.267 raeburn 3360: ((keys(%changed) > 0) && $chgresult eq 'ok')) {
1.28 matthew 3361: # Tell the user we changed the name
1.334 raeburn 3362: &display_userinfo($r,1,\@disporder,\%canshow,\@requestcourses,
1.362 raeburn 3363: \@usertools,\@requestauthor,\%userenv,\%changed,\%namechanged,
1.334 raeburn 3364: \%oldsettings, \%oldsettingstext,\%newsettings,
3365: \%newsettingstext);
1.203 raeburn 3366: if ($env{'form.cid'} ne $userenv{'id'}) {
3367: &Apache::lonnet::idput($env{'form.ccdomain'},
1.407 raeburn 3368: {$env{'form.ccuname'} => $env{'form.cid'}},$uhome,'ids');
1.203 raeburn 3369: if (($recurseid) &&
3370: (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'}))) {
3371: my $idresult =
3372: &Apache::lonuserutils::propagate_id_change(
3373: $env{'form.ccuname'},$env{'form.ccdomain'},
3374: \%userupdate);
3375: $r->print('<br />'.$idresult.'<br />');
3376: }
1.196 raeburn 3377: }
1.149 raeburn 3378: if (($env{'form.ccdomain'} eq $env{'user.domain'}) &&
3379: ($env{'form.ccuname'} eq $env{'user.name'})) {
3380: my %newenvhash;
3381: foreach my $key (keys(%changeHash)) {
3382: $newenvhash{'environment.'.$key} = $changeHash{$key};
3383: }
1.238 raeburn 3384: &Apache::lonnet::appenv(\%newenvhash);
1.149 raeburn 3385: }
1.28 matthew 3386: } else { # error occurred
1.389 bisitz 3387: $r->print(
3388: '<p class="LC_error">'
3389: .&mt('Unable to successfully change environment for [_1] in domain [_2].',
3390: '"'.$env{'form.ccuname'}.'"',
3391: '"'.$env{'form.ccdomain'}.'"')
3392: .'</p>');
1.28 matthew 3393: }
1.334 raeburn 3394: } else { # End of if ($env ... ) logic
1.275 raeburn 3395: # They did not want to change the users name, quota, tool availability,
3396: # or ability to request creation of courses,
1.267 raeburn 3397: # but we can still tell them what the name and quota and availabilities are
1.334 raeburn 3398: &display_userinfo($r,undef,\@disporder,\%canshow,\@requestcourses,
1.362 raeburn 3399: \@usertools,\@requestauthor,\%userenv,\%changed,\%namechanged,\%oldsettings,
1.334 raeburn 3400: \%oldsettingstext,\%newsettings,\%newsettingstext);
1.28 matthew 3401: }
1.206 raeburn 3402: if (@mod_disallowed) {
3403: my ($rolestr,$contextname);
3404: if (@longroles > 0) {
3405: $rolestr = join(', ',@longroles);
3406: } else {
3407: $rolestr = &mt('No roles');
3408: }
3409: if ($context eq 'course') {
1.399 bisitz 3410: $contextname = 'course';
1.206 raeburn 3411: } elsif ($context eq 'author') {
1.399 bisitz 3412: $contextname = 'co-author';
1.206 raeburn 3413: }
3414: $r->print(&mt('The following fields were not updated: ').'<ul>');
3415: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
3416: foreach my $field (@mod_disallowed) {
3417: $r->print('<li>'.$fieldtitles{$field}.'</li>'."\n");
3418: }
1.207 raeburn 3419: $r->print('</ul>');
3420: if (@mod_disallowed == 1) {
1.399 bisitz 3421: $r->print(&mt("You do not have the authority to change this field given the user's current set of active/future $contextname roles:"));
1.207 raeburn 3422: } else {
1.399 bisitz 3423: $r->print(&mt("You do not have the authority to change these fields given the user's current set of active/future $contextname roles:"));
1.207 raeburn 3424: }
1.292 bisitz 3425: my $helplink = 'javascript:helpMenu('."'display'".')';
3426: $r->print('<span class="LC_cusr_emph">'.$rolestr.'</span><br />'
3427: .&mt('Please contact your [_1]helpdesk[_2] for more information.'
3428: ,'<a href="'.$helplink.'">','</a>')
3429: .'<br />');
1.206 raeburn 3430: }
1.259 bisitz 3431: $r->print('<span class="LC_warning">'
3432: .$no_forceid_alert
3433: .&Apache::lonuserutils::print_namespacing_alerts($env{'form.ccdomain'},\%alerts,\%curr_rules)
3434: .'</span>');
1.4 www 3435: }
1.367 golterma 3436: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
1.220 raeburn 3437: if ($env{'form.action'} eq 'singlestudent') {
1.375 raeburn 3438: &enroll_single_student($r,$uhome,$amode,$genpwd,$now,$newuser,$context,
3439: $crstype,$showcredits,$defaultcredits);
1.386 bisitz 3440: my $linktext = ($crstype eq 'Community' ?
3441: &mt('Enroll Another Member') : &mt('Enroll Another Student'));
3442: $r->print(
3443: &Apache::lonhtmlcommon::actionbox([
3444: '<a href="javascript:backPage(document.userupdate)">'
3445: .($crstype eq 'Community' ?
3446: &mt('Enroll Another Member') : &mt('Enroll Another Student'))
3447: .'</a>']));
1.220 raeburn 3448: } else {
1.375 raeburn 3449: my @rolechanges = &update_roles($r,$context,$showcredits);
1.334 raeburn 3450: if (keys(%namechanged) > 0) {
1.220 raeburn 3451: if ($context eq 'course') {
3452: if (@userroles > 0) {
1.225 raeburn 3453: if ((@rolechanges == 0) ||
3454: (!(grep(/^st$/,@rolechanges)))) {
3455: if (grep(/^st$/,@userroles)) {
3456: my $classlistupdated =
3457: &Apache::lonuserutils::update_classlist($cdom,
1.220 raeburn 3458: $cnum,$env{'form.ccdomain'},
3459: $env{'form.ccuname'},\%userupdate);
1.225 raeburn 3460: }
1.220 raeburn 3461: }
3462: }
3463: }
3464: }
1.226 raeburn 3465: my $userinfo = &Apache::loncommon::plainname($env{'form.ccuname'},
1.233 raeburn 3466: $env{'form.ccdomain'});
3467: if ($env{'form.popup'}) {
3468: $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a></p>');
3469: } else {
1.367 golterma 3470: $r->print('<br />'.&Apache::lonhtmlcommon::actionbox(['<a href="javascript:backPage(document.userupdate,'."'$env{'form.prevphase'}','modify'".')">'
3471: .&mt('Modify this user: [_1]','<span class="LC_cusr_emph">'.$env{'form.ccuname'}.':'.$env{'form.ccdomain'}.' ('.$userinfo.')</span>').'</a>',
3472: '<a href="javascript:backPage(document.userupdate)">'.&mt('Create/Modify Another User').'</a>']));
1.233 raeburn 3473: }
1.220 raeburn 3474: }
3475: }
3476:
1.334 raeburn 3477: sub display_userinfo {
1.362 raeburn 3478: my ($r,$changed,$order,$canshow,$requestcourses,$usertools,$requestauthor,
3479: $userenv,$changedhash,$namechangedhash,$oldsetting,$oldsettingtext,
1.334 raeburn 3480: $newsetting,$newsettingtext) = @_;
3481: return unless (ref($order) eq 'ARRAY' &&
3482: ref($canshow) eq 'HASH' &&
3483: ref($requestcourses) eq 'ARRAY' &&
1.362 raeburn 3484: ref($requestauthor) eq 'ARRAY' &&
1.334 raeburn 3485: ref($usertools) eq 'ARRAY' &&
3486: ref($userenv) eq 'HASH' &&
3487: ref($changedhash) eq 'HASH' &&
3488: ref($oldsetting) eq 'HASH' &&
3489: ref($oldsettingtext) eq 'HASH' &&
3490: ref($newsetting) eq 'HASH' &&
3491: ref($newsettingtext) eq 'HASH');
3492: my %lt=&Apache::lonlocal::texthash(
1.372 raeburn 3493: 'ui' => 'User Information',
1.334 raeburn 3494: 'uic' => 'User Information Changed',
3495: 'firstname' => 'First Name',
3496: 'middlename' => 'Middle Name',
3497: 'lastname' => 'Last Name',
3498: 'generation' => 'Generation',
3499: 'id' => 'Student/Employee ID',
3500: 'permanentemail' => 'Permanent e-mail address',
1.378 raeburn 3501: 'portfolioquota' => 'Disk space allocated to portfolio files',
1.385 bisitz 3502: 'authorquota' => 'Disk space allocated to Authoring Space',
1.334 raeburn 3503: 'blog' => 'Blog Availability',
1.361 raeburn 3504: 'webdav' => 'WebDAV Availability',
1.334 raeburn 3505: 'aboutme' => 'Personal Information Page Availability',
3506: 'portfolio' => 'Portfolio Availability',
3507: 'official' => 'Can Request Official Courses',
3508: 'unofficial' => 'Can Request Unofficial Courses',
3509: 'community' => 'Can Request Communities',
1.384 raeburn 3510: 'textbook' => 'Can Request Textbook Courses',
1.411 raeburn 3511: 'placement' => 'Can Request Placement Tests',
1.362 raeburn 3512: 'requestauthor' => 'Can Request Author Role',
1.334 raeburn 3513: 'inststatus' => "Affiliation",
3514: 'prvs' => 'Previous Value:',
3515: 'chto' => 'Changed To:'
3516: );
3517: if ($changed) {
1.372 raeburn 3518: $r->print('<h3>'.$lt{'uic'}.'</h3>'.
1.367 golterma 3519: &Apache::loncommon::start_data_table().
3520: &Apache::loncommon::start_data_table_header_row());
1.334 raeburn 3521: $r->print("<th> </th>\n");
1.367 golterma 3522: $r->print('<th><b>'.$lt{'prvs'}.'</b></th>');
3523: $r->print('<th><span class="LC_nobreak"><b>'.$lt{'chto'}.'</b></span></th>');
3524: $r->print(&Apache::loncommon::end_data_table_header_row());
3525: my @userinfo = ('firstname','middlename','lastname','generation','permanentemail','id');
3526:
1.334 raeburn 3527: foreach my $item (@userinfo) {
3528: my $value = $env{'form.c'.$item};
1.367 golterma 3529: #show changes only:
1.383 raeburn 3530: unless ($value eq $userenv->{$item}){
1.367 golterma 3531: $r->print(&Apache::loncommon::start_data_table_row());
3532: $r->print("<td>$lt{$item}</td>\n");
1.383 raeburn 3533: $r->print("<td>".$userenv->{$item}."</td>\n");
1.367 golterma 3534: $r->print("<td>$value </td>\n");
3535: $r->print(&Apache::loncommon::end_data_table_row());
1.334 raeburn 3536: }
3537: }
3538: foreach my $entry (@{$order}) {
1.383 raeburn 3539: if ($canshow->{$entry}) {
3540: if (($entry eq 'requestcourses') || ($entry eq 'reqcrsotherdom') || ($entry eq 'requestauthor')) {
3541: my @items;
3542: if ($entry eq 'requestauthor') {
3543: @items = ($entry);
3544: } else {
3545: @items = @{$requestcourses};
1.384 raeburn 3546: }
1.383 raeburn 3547: foreach my $item (@items) {
3548: if (($newsetting->{$item} ne $oldsetting->{$item}) ||
3549: ($newsettingtext->{$item} ne $oldsettingtext->{$item})) {
3550: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3551: $r->print("<td>$lt{$item}</td>\n");
3552: $r->print("<td>".$oldsetting->{$item});
3553: if ($oldsettingtext->{$item}) {
3554: if ($oldsetting->{$item}) {
3555: $r->print(' -- ');
3556: }
3557: $r->print($oldsettingtext->{$item});
3558: }
3559: $r->print("</td>\n");
3560: $r->print("<td>".$newsetting->{$item});
3561: if ($newsettingtext->{$item}) {
3562: if ($newsetting->{$item}) {
3563: $r->print(' -- ');
3564: }
3565: $r->print($newsettingtext->{$item});
3566: }
3567: $r->print("</td>\n");
3568: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.334 raeburn 3569: }
3570: }
3571: } elsif ($entry eq 'tools') {
3572: foreach my $item (@{$usertools}) {
1.383 raeburn 3573: if ($newsetting->{$item} ne $oldsetting->{$item}) {
3574: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3575: $r->print("<td>$lt{$item}</td>\n");
3576: $r->print("<td>".$oldsetting->{$item}.' '.$oldsettingtext->{$item}."</td>\n");
3577: $r->print("<td>".$newsetting->{$item}.' '.$newsettingtext->{$item}."</td>\n");
3578: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.334 raeburn 3579: }
3580: }
1.378 raeburn 3581: } elsif ($entry eq 'quota') {
3582: if ((ref($oldsetting->{$entry}) eq 'HASH') && (ref($oldsettingtext->{$entry}) eq 'HASH') &&
3583: (ref($newsetting->{$entry}) eq 'HASH') && (ref($newsettingtext->{$entry}) eq 'HASH')) {
3584: foreach my $name ('portfolio','author') {
1.383 raeburn 3585: if ($newsetting->{$entry}->{$name} ne $oldsetting->{$entry}->{$name}) {
3586: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3587: $r->print("<td>$lt{$name.$entry}</td>\n");
3588: $r->print("<td>".$oldsettingtext->{$entry}->{$name}."</td>\n");
3589: $r->print("<td>".$newsettingtext->{$entry}->{$name}."</td>\n");
3590: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.378 raeburn 3591: }
3592: }
3593: }
1.334 raeburn 3594: } else {
1.383 raeburn 3595: if ($newsetting->{$entry} ne $oldsetting->{$entry}) {
3596: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3597: $r->print("<td>$lt{$entry}</td>\n");
3598: $r->print("<td>".$oldsetting->{$entry}.' '.$oldsettingtext->{$entry}."</td>\n");
3599: $r->print("<td>".$newsetting->{$entry}.' '.$newsettingtext->{$entry}."</td>\n");
3600: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.334 raeburn 3601: }
3602: }
3603: }
3604: }
1.367 golterma 3605: $r->print(&Apache::loncommon::end_data_table().'<br />');
1.372 raeburn 3606: } else {
3607: $r->print('<h3>'.$lt{'ui'}.'</h3>'.
3608: '<p>'.&mt('No changes made to user information').'</p>');
1.334 raeburn 3609: }
3610: return;
3611: }
3612:
1.275 raeburn 3613: sub tool_changes {
3614: my ($context,$usertools,$oldaccess,$oldaccesstext,$userenv,$changeHash,
3615: $changed,$newaccess,$newaccesstext) = @_;
3616: if (!((ref($usertools) eq 'ARRAY') && (ref($oldaccess) eq 'HASH') &&
3617: (ref($oldaccesstext) eq 'HASH') && (ref($userenv) eq 'HASH') &&
3618: (ref($changeHash) eq 'HASH') && (ref($changed) eq 'HASH') &&
3619: (ref($newaccess) eq 'HASH') && (ref($newaccesstext) eq 'HASH'))) {
3620: return;
3621: }
1.383 raeburn 3622: my %reqdisplay = &requestchange_display();
1.300 raeburn 3623: if ($context eq 'reqcrsotherdom') {
1.309 raeburn 3624: my @options = ('approval','validate','autolimit');
1.306 raeburn 3625: my $optregex = join('|',@options);
1.300 raeburn 3626: my $cdom = $env{'request.role.domain'};
3627: foreach my $tool (@{$usertools}) {
1.383 raeburn 3628: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
1.314 raeburn 3629: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
1.300 raeburn 3630: $changeHash->{$context.'.'.$tool} = $userenv->{$context.'.'.$tool};
1.383 raeburn 3631: my ($newop,$limit);
1.314 raeburn 3632: if ($env{'form.'.$context.'_'.$tool}) {
3633: $newop = $env{'form.'.$context.'_'.$tool};
3634: if ($newop eq 'autolimit') {
1.383 raeburn 3635: $limit = $env{'form.'.$context.'_'.$tool.'_limit'};
1.314 raeburn 3636: $limit =~ s/\D+//g;
3637: $newop .= '='.$limit;
3638: }
3639: }
1.300 raeburn 3640: if ($userenv->{$context.'.'.$tool} eq '') {
1.314 raeburn 3641: if ($newop) {
3642: $changed->{$tool}=&tool_admin($tool,$cdom.':'.$newop,
1.300 raeburn 3643: $changeHash,$context);
3644: if ($changed->{$tool}) {
1.383 raeburn 3645: if ($newop =~ /^autolimit/) {
3646: if ($limit) {
3647: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3648: } else {
3649: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3650: }
3651: } else {
3652: $newaccesstext->{$tool} = $reqdisplay{$newop};
3653: }
1.300 raeburn 3654: } else {
3655: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
3656: }
3657: }
3658: } else {
3659: my @curr = split(',',$userenv->{$context.'.'.$tool});
3660: my @new;
3661: my $changedoms;
1.314 raeburn 3662: foreach my $req (@curr) {
3663: if ($req =~ /^\Q$cdom\E\:($optregex\=?\d*)$/) {
3664: my $oldop = $1;
1.383 raeburn 3665: if ($oldop =~ /^autolimit=(\d*)/) {
3666: my $limit = $1;
3667: if ($limit) {
3668: $oldaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3669: } else {
3670: $oldaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3671: }
3672: } else {
3673: $oldaccesstext->{$tool} = $reqdisplay{$oldop};
3674: }
1.314 raeburn 3675: if ($oldop ne $newop) {
3676: $changedoms = 1;
3677: foreach my $item (@curr) {
3678: my ($reqdom,$option) = split(':',$item);
3679: unless ($reqdom eq $cdom) {
3680: push(@new,$item);
3681: }
3682: }
3683: if ($newop) {
3684: push(@new,$cdom.':'.$newop);
1.300 raeburn 3685: }
1.314 raeburn 3686: @new = sort(@new);
1.300 raeburn 3687: }
1.314 raeburn 3688: last;
1.300 raeburn 3689: }
1.314 raeburn 3690: }
3691: if ((!$changedoms) && ($newop)) {
1.300 raeburn 3692: $changedoms = 1;
1.306 raeburn 3693: @new = sort(@curr,$cdom.':'.$newop);
1.300 raeburn 3694: }
3695: if ($changedoms) {
1.314 raeburn 3696: my $newdomstr;
1.300 raeburn 3697: if (@new) {
3698: $newdomstr = join(',',@new);
3699: }
3700: $changed->{$tool}=&tool_admin($tool,$newdomstr,$changeHash,
3701: $context);
3702: if ($changed->{$tool}) {
3703: if ($env{'form.'.$context.'_'.$tool}) {
1.306 raeburn 3704: if ($env{'form.'.$context.'_'.$tool} eq 'autolimit') {
1.314 raeburn 3705: my $limit = $env{'form.'.$context.'_'.$tool.'_limit'};
3706: $limit =~ s/\D+//g;
3707: if ($limit) {
1.383 raeburn 3708: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
1.314 raeburn 3709: } else {
1.383 raeburn 3710: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
1.306 raeburn 3711: }
1.314 raeburn 3712: } else {
1.306 raeburn 3713: $newaccesstext->{$tool} = $reqdisplay{$env{'form.'.$context.'_'.$tool}};
3714: }
1.300 raeburn 3715: } else {
1.383 raeburn 3716: $newaccesstext->{$tool} = &mt("availability set to 'off'");
1.300 raeburn 3717: }
3718: }
3719: }
3720: }
3721: }
3722: return;
3723: }
1.275 raeburn 3724: foreach my $tool (@{$usertools}) {
1.383 raeburn 3725: my ($newval,$limit,$envkey);
1.362 raeburn 3726: $envkey = $context.'.'.$tool;
1.306 raeburn 3727: if ($context eq 'requestcourses') {
3728: $newval = $env{'form.crsreq_'.$tool};
3729: if ($newval eq 'autolimit') {
1.383 raeburn 3730: $limit = $env{'form.crsreq_'.$tool.'_limit'};
3731: $limit =~ s/\D+//g;
3732: $newval .= '='.$limit;
1.306 raeburn 3733: }
1.362 raeburn 3734: } elsif ($context eq 'requestauthor') {
3735: $newval = $env{'form.'.$context};
3736: $envkey = $context;
1.314 raeburn 3737: } else {
1.306 raeburn 3738: $newval = $env{'form.'.$context.'_'.$tool};
3739: }
1.362 raeburn 3740: if ($userenv->{$envkey} ne '') {
1.275 raeburn 3741: $oldaccess->{$tool} = &mt('custom');
1.383 raeburn 3742: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3743: if ($userenv->{$envkey} =~ /^autolimit=(\d*)$/) {
3744: my $currlimit = $1;
3745: if ($currlimit eq '') {
3746: $oldaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3747: } else {
3748: $oldaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$currlimit);
3749: }
3750: } elsif ($userenv->{$envkey}) {
3751: $oldaccesstext->{$tool} = $reqdisplay{$userenv->{$envkey}};
3752: } else {
3753: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
3754: }
1.275 raeburn 3755: } else {
1.383 raeburn 3756: if ($userenv->{$envkey}) {
3757: $oldaccesstext->{$tool} = &mt("availability set to 'on'");
3758: } else {
3759: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
3760: }
1.275 raeburn 3761: }
1.362 raeburn 3762: $changeHash->{$envkey} = $userenv->{$envkey};
1.275 raeburn 3763: if ($env{'form.custom'.$tool} == 1) {
1.362 raeburn 3764: if ($newval ne $userenv->{$envkey}) {
1.306 raeburn 3765: $changed->{$tool} = &tool_admin($tool,$newval,$changeHash,
3766: $context);
1.275 raeburn 3767: if ($changed->{$tool}) {
3768: $newaccess->{$tool} = &mt('custom');
1.383 raeburn 3769: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3770: if ($newval =~ /^autolimit/) {
3771: if ($limit) {
3772: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3773: } else {
3774: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3775: }
3776: } elsif ($newval) {
3777: $newaccesstext->{$tool} = $reqdisplay{$newval};
3778: } else {
3779: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3780: }
1.275 raeburn 3781: } else {
1.383 raeburn 3782: if ($newval) {
3783: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3784: } else {
3785: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3786: }
1.275 raeburn 3787: }
3788: } else {
3789: $newaccess->{$tool} = $oldaccess->{$tool};
1.383 raeburn 3790: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3791: if ($newval =~ /^autolimit/) {
3792: if ($limit) {
3793: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3794: } else {
3795: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3796: }
3797: } elsif ($newval) {
3798: $newaccesstext->{$tool} = $reqdisplay{$newval};
3799: } else {
3800: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3801: }
1.275 raeburn 3802: } else {
1.383 raeburn 3803: if ($userenv->{$context.'.'.$tool}) {
3804: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3805: } else {
3806: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3807: }
1.275 raeburn 3808: }
3809: }
3810: } else {
3811: $newaccess->{$tool} = $oldaccess->{$tool};
3812: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
3813: }
3814: } else {
3815: $changed->{$tool} = &tool_admin($tool,'',$changeHash,$context);
3816: if ($changed->{$tool}) {
3817: $newaccess->{$tool} = &mt('default');
3818: } else {
3819: $newaccess->{$tool} = $oldaccess->{$tool};
1.383 raeburn 3820: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3821: if ($newval =~ /^autolimit/) {
3822: if ($limit) {
3823: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3824: } else {
3825: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3826: }
3827: } elsif ($newval) {
3828: $newaccesstext->{$tool} = $reqdisplay{$newval};
3829: } else {
3830: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3831: }
1.275 raeburn 3832: } else {
1.383 raeburn 3833: if ($userenv->{$context.'.'.$tool}) {
3834: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3835: } else {
3836: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3837: }
1.275 raeburn 3838: }
3839: }
3840: }
3841: } else {
3842: $oldaccess->{$tool} = &mt('default');
3843: if ($env{'form.custom'.$tool} == 1) {
1.306 raeburn 3844: $changed->{$tool} = &tool_admin($tool,$newval,$changeHash,
3845: $context);
1.275 raeburn 3846: if ($changed->{$tool}) {
3847: $newaccess->{$tool} = &mt('custom');
1.383 raeburn 3848: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3849: if ($newval =~ /^autolimit/) {
3850: if ($limit) {
3851: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3852: } else {
3853: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3854: }
3855: } elsif ($newval) {
3856: $newaccesstext->{$tool} = $reqdisplay{$newval};
3857: } else {
3858: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3859: }
1.275 raeburn 3860: } else {
1.383 raeburn 3861: if ($newval) {
3862: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3863: } else {
3864: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3865: }
1.275 raeburn 3866: }
3867: } else {
3868: $newaccess->{$tool} = $oldaccess->{$tool};
3869: }
3870: } else {
3871: $newaccess->{$tool} = $oldaccess->{$tool};
3872: }
3873: }
3874: }
3875: return;
3876: }
3877:
1.220 raeburn 3878: sub update_roles {
1.375 raeburn 3879: my ($r,$context,$showcredits) = @_;
1.4 www 3880: my $now=time;
1.225 raeburn 3881: my @rolechanges;
1.220 raeburn 3882: my %disallowed;
1.73 sakharuk 3883: $r->print('<h3>'.&mt('Modifying Roles').'</h3>');
1.404 raeburn 3884: foreach my $key (keys(%env)) {
1.135 raeburn 3885: next if (! $env{$key});
1.190 raeburn 3886: next if ($key eq 'form.action');
1.27 matthew 3887: # Revoke roles
1.135 raeburn 3888: if ($key=~/^form\.rev/) {
3889: if ($key=~/^form\.rev\:([^\_]+)\_([^\_\.]+)$/) {
1.64 www 3890: # Revoke standard role
1.170 albertel 3891: my ($scope,$role) = ($1,$2);
3892: my $result =
3893: &Apache::lonnet::revokerole($env{'form.ccdomain'},
3894: $env{'form.ccuname'},
1.239 raeburn 3895: $scope,$role,'','',$context);
1.367 golterma 3896: $r->print(&Apache::lonhtmlcommon::confirm_success(
1.369 bisitz 3897: &mt('Revoking [_1] in [_2]',
3898: &Apache::lonnet::plaintext($role),
1.372 raeburn 3899: &Apache::loncommon::show_role_extent($scope,$context,$role)),
1.369 bisitz 3900: $result ne "ok").'<br />');
3901: if ($result ne "ok") {
3902: $r->print(&mt('Error: [_1]',$result).'<br />');
3903: }
1.170 albertel 3904: if ($role eq 'st') {
1.202 raeburn 3905: my $result =
1.198 raeburn 3906: &Apache::lonuserutils::classlist_drop($scope,
3907: $env{'form.ccuname'},$env{'form.ccdomain'},
1.202 raeburn 3908: $now);
1.367 golterma 3909: $r->print(&Apache::lonhtmlcommon::confirm_success($result));
1.53 www 3910: }
1.225 raeburn 3911: if (!grep(/^\Q$role\E$/,@rolechanges)) {
3912: push(@rolechanges,$role);
3913: }
1.196 raeburn 3914: }
1.195 raeburn 3915: if ($key=~m{^form\.rev\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}s) {
1.64 www 3916: # Revoke custom role
1.369 bisitz 3917: my $result = &Apache::lonnet::revokecustomrole(
3918: $env{'form.ccdomain'},$env{'form.ccuname'},$1,$2,$3,$4,'','',$context);
1.367 golterma 3919: $r->print(&Apache::lonhtmlcommon::confirm_success(
1.369 bisitz 3920: &mt('Revoking custom role [_1] by [_2] in [_3]',
1.372 raeburn 3921: $4,$3.':'.$2,&Apache::loncommon::show_role_extent($1,$context,'cr')),
1.369 bisitz 3922: $result ne 'ok').'<br />');
3923: if ($result ne "ok") {
3924: $r->print(&mt('Error: [_1]',$result).'<br />');
3925: }
1.225 raeburn 3926: if (!grep(/^cr$/,@rolechanges)) {
3927: push(@rolechanges,'cr');
3928: }
1.64 www 3929: }
1.135 raeburn 3930: } elsif ($key=~/^form\.del/) {
3931: if ($key=~/^form\.del\:([^\_]+)\_([^\_\.]+)$/) {
1.116 raeburn 3932: # Delete standard role
1.170 albertel 3933: my ($scope,$role) = ($1,$2);
3934: my $result =
3935: &Apache::lonnet::assignrole($env{'form.ccdomain'},
3936: $env{'form.ccuname'},
1.239 raeburn 3937: $scope,$role,$now,0,1,'',
3938: $context);
1.367 golterma 3939: $r->print(&Apache::lonhtmlcommon::confirm_success(
3940: &mt('Deleting [_1] in [_2]',
1.369 bisitz 3941: &Apache::lonnet::plaintext($role),
1.372 raeburn 3942: &Apache::loncommon::show_role_extent($scope,$context,$role)),
1.369 bisitz 3943: $result ne 'ok').'<br />');
3944: if ($result ne "ok") {
3945: $r->print(&mt('Error: [_1]',$result).'<br />');
3946: }
1.367 golterma 3947:
1.170 albertel 3948: if ($role eq 'st') {
1.202 raeburn 3949: my $result =
1.198 raeburn 3950: &Apache::lonuserutils::classlist_drop($scope,
3951: $env{'form.ccuname'},$env{'form.ccdomain'},
1.202 raeburn 3952: $now);
1.369 bisitz 3953: $r->print(&Apache::lonhtmlcommon::confirm_success($result));
1.81 albertel 3954: }
1.225 raeburn 3955: if (!grep(/^\Q$role\E$/,@rolechanges)) {
3956: push(@rolechanges,$role);
3957: }
1.116 raeburn 3958: }
1.139 albertel 3959: if ($key=~m{^form\.del\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
1.116 raeburn 3960: my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
3961: # Delete custom role
1.369 bisitz 3962: my $result =
3963: &Apache::lonnet::assigncustomrole($env{'form.ccdomain'},
3964: $env{'form.ccuname'},$url,$rdom,$rnam,$rolename,$now,
3965: 0,1,$context);
3966: $r->print(&Apache::lonhtmlcommon::confirm_success(&mt('Deleting custom role [_1] by [_2] in [_3]',
1.372 raeburn 3967: $rolename,$rnam.':'.$rdom,&Apache::loncommon::show_role_extent($1,$context,'cr')),
1.369 bisitz 3968: $result ne "ok").'<br />');
3969: if ($result ne "ok") {
3970: $r->print(&mt('Error: [_1]',$result).'<br />');
3971: }
1.367 golterma 3972:
1.225 raeburn 3973: if (!grep(/^cr$/,@rolechanges)) {
3974: push(@rolechanges,'cr');
3975: }
1.116 raeburn 3976: }
1.135 raeburn 3977: } elsif ($key=~/^form\.ren/) {
1.101 albertel 3978: my $udom = $env{'form.ccdomain'};
3979: my $uname = $env{'form.ccuname'};
1.116 raeburn 3980: # Re-enable standard role
1.135 raeburn 3981: if ($key=~/^form\.ren\:([^\_]+)\_([^\_\.]+)$/) {
1.89 raeburn 3982: my $url = $1;
3983: my $role = $2;
3984: my $logmsg;
3985: my $output;
3986: if ($role eq 'st') {
1.141 albertel 3987: if ($url =~ m-^/($match_domain)/($match_courseid)/?(\w*)$-) {
1.374 raeburn 3988: my ($cdom,$cnum,$csec) = ($1,$2,$3);
1.375 raeburn 3989: my $credits;
3990: if ($showcredits) {
3991: my $defaultcredits =
3992: &Apache::lonuserutils::get_defaultcredits($cdom,$cnum);
3993: $credits = &get_user_credits($defaultcredits,$cdom,$cnum);
3994: }
3995: my $result = &Apache::loncommon::commit_studentrole(\$logmsg,$udom,$uname,$url,$role,$now,0,$cdom,$cnum,$csec,$context,$credits);
1.220 raeburn 3996: if (($result =~ /^error/) || ($result eq 'not_in_class') || ($result eq 'unknown_course') || ($result eq 'refused')) {
1.223 raeburn 3997: if ($result eq 'refused' && $logmsg) {
3998: $output = $logmsg;
3999: } else {
1.369 bisitz 4000: $output = &mt('Error: [_1]',$result)."\n";
1.223 raeburn 4001: }
1.89 raeburn 4002: } else {
1.372 raeburn 4003: $output = &Apache::lonhtmlcommon::confirm_success(&mt('Assigning [_1] in [_2] starting [_3]',
4004: &Apache::lonnet::plaintext($role),
4005: &Apache::loncommon::show_role_extent($url,$context,'st'),
4006: &Apache::lonlocal::locallocaltime($now))).'<br />'.$logmsg.'<br />';
1.89 raeburn 4007: }
4008: }
4009: } else {
1.101 albertel 4010: my $result=&Apache::lonnet::assignrole($env{'form.ccdomain'},
1.239 raeburn 4011: $env{'form.ccuname'},$url,$role,0,$now,'','',
4012: $context);
1.367 golterma 4013: $output = &Apache::lonhtmlcommon::confirm_success(&mt('Re-enabling [_1] in [_2]',
1.372 raeburn 4014: &Apache::lonnet::plaintext($role),
4015: &Apache::loncommon::show_role_extent($url,$context,$role)),$result ne "ok").'<br />';
1.369 bisitz 4016: if ($result ne "ok") {
4017: $output .= &mt('Error: [_1]',$result).'<br />';
4018: }
4019: }
1.89 raeburn 4020: $r->print($output);
1.225 raeburn 4021: if (!grep(/^\Q$role\E$/,@rolechanges)) {
4022: push(@rolechanges,$role);
4023: }
1.113 raeburn 4024: }
1.116 raeburn 4025: # Re-enable custom role
1.139 albertel 4026: if ($key=~m{^form\.ren\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
1.116 raeburn 4027: my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
4028: my $result = &Apache::lonnet::assigncustomrole(
4029: $env{'form.ccdomain'}, $env{'form.ccuname'},
1.240 raeburn 4030: $url,$rdom,$rnam,$rolename,0,$now,undef,$context);
1.369 bisitz 4031: $r->print(&Apache::lonhtmlcommon::confirm_success(
4032: &mt('Re-enabling custom role [_1] by [_2] in [_3]',
1.372 raeburn 4033: $rolename,$rnam.':'.$rdom,&Apache::loncommon::show_role_extent($1,$context,'cr')),
1.369 bisitz 4034: $result ne "ok").'<br />');
4035: if ($result ne "ok") {
4036: $r->print(&mt('Error: [_1]',$result).'<br />');
4037: }
1.225 raeburn 4038: if (!grep(/^cr$/,@rolechanges)) {
4039: push(@rolechanges,'cr');
4040: }
1.116 raeburn 4041: }
1.135 raeburn 4042: } elsif ($key=~/^form\.act/) {
1.101 albertel 4043: my $udom = $env{'form.ccdomain'};
4044: my $uname = $env{'form.ccuname'};
1.141 albertel 4045: if ($key=~/^form\.act\_($match_domain)\_($match_courseid)\_cr_cr_($match_domain)_($match_username)_([^\_]+)$/) {
1.65 www 4046: # Activate a custom role
1.83 albertel 4047: my ($one,$two,$three,$four,$five)=($1,$2,$3,$4,$5);
4048: my $url='/'.$one.'/'.$two;
4049: my $full=$one.'_'.$two.'_cr_cr_'.$three.'_'.$four.'_'.$five;
1.65 www 4050:
1.101 albertel 4051: my $start = ( $env{'form.start_'.$full} ?
4052: $env{'form.start_'.$full} :
1.88 raeburn 4053: $now );
1.101 albertel 4054: my $end = ( $env{'form.end_'.$full} ?
4055: $env{'form.end_'.$full} :
1.88 raeburn 4056: 0 );
4057:
4058: # split multiple sections
4059: my %sections = ();
1.101 albertel 4060: my $num_sections = &build_roles($env{'form.sec_'.$full},\%sections,$5);
1.88 raeburn 4061: if ($num_sections == 0) {
1.240 raeburn 4062: $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$url,$three,$four,$five,$start,$end,$context));
1.88 raeburn 4063: } else {
1.114 albertel 4064: my %curr_groups =
1.117 raeburn 4065: &Apache::longroup::coursegroups($one,$two);
1.404 raeburn 4066: foreach my $sec (sort {$a cmp $b} keys(%sections)) {
1.113 raeburn 4067: if (($sec eq 'none') || ($sec eq 'all') ||
4068: exists($curr_groups{$sec})) {
4069: $disallowed{$sec} = $url;
4070: next;
4071: }
4072: my $securl = $url.'/'.$sec;
1.240 raeburn 4073: $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$securl,$three,$four,$five,$start,$end,$context));
1.88 raeburn 4074: }
4075: }
1.225 raeburn 4076: if (!grep(/^cr$/,@rolechanges)) {
4077: push(@rolechanges,'cr');
4078: }
1.142 raeburn 4079: } elsif ($key=~/^form\.act\_($match_domain)\_($match_name)\_([^\_]+)$/) {
1.27 matthew 4080: # Activate roles for sections with 3 id numbers
4081: # set start, end times, and the url for the class
1.83 albertel 4082: my ($one,$two,$three)=($1,$2,$3);
1.101 albertel 4083: my $start = ( $env{'form.start_'.$one.'_'.$two.'_'.$three} ?
4084: $env{'form.start_'.$one.'_'.$two.'_'.$three} :
1.27 matthew 4085: $now );
1.101 albertel 4086: my $end = ( $env{'form.end_'.$one.'_'.$two.'_'.$three} ?
4087: $env{'form.end_'.$one.'_'.$two.'_'.$three} :
1.27 matthew 4088: 0 );
1.83 albertel 4089: my $url='/'.$one.'/'.$two;
1.88 raeburn 4090: my $type = 'three';
4091: # split multiple sections
4092: my %sections = ();
1.101 albertel 4093: my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two.'_'.$three},\%sections,$three);
1.375 raeburn 4094: my $credits;
4095: if ($three eq 'st') {
4096: if ($showcredits) {
4097: my $defaultcredits =
4098: &Apache::lonuserutils::get_defaultcredits($one,$two);
4099: $credits = $env{'form.credits_'.$one.'_'.$two.'_'.$three};
4100: $credits =~ s/[^\d\.]//g;
4101: if ($credits eq $defaultcredits) {
4102: undef($credits);
4103: }
4104: }
4105: }
1.88 raeburn 4106: if ($num_sections == 0) {
1.375 raeburn 4107: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'',$context,$credits));
1.88 raeburn 4108: } else {
1.114 albertel 4109: my %curr_groups =
1.117 raeburn 4110: &Apache::longroup::coursegroups($one,$two);
1.88 raeburn 4111: my $emptysec = 0;
1.404 raeburn 4112: foreach my $sec (sort {$a cmp $b} keys(%sections)) {
1.88 raeburn 4113: $sec =~ s/\W//g;
1.113 raeburn 4114: if ($sec ne '') {
4115: if (($sec eq 'none') || ($sec eq 'all') ||
4116: exists($curr_groups{$sec})) {
4117: $disallowed{$sec} = $url;
4118: next;
4119: }
1.88 raeburn 4120: my $securl = $url.'/'.$sec;
1.375 raeburn 4121: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$three,$start,$end,$one,$two,$sec,$context,$credits));
1.88 raeburn 4122: } else {
4123: $emptysec = 1;
4124: }
4125: }
4126: if ($emptysec) {
1.375 raeburn 4127: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'',$context,$credits));
1.88 raeburn 4128: }
1.225 raeburn 4129: }
4130: if (!grep(/^\Q$three\E$/,@rolechanges)) {
4131: push(@rolechanges,$three);
4132: }
1.135 raeburn 4133: } elsif ($key=~/^form\.act\_([^\_]+)\_([^\_]+)$/) {
1.27 matthew 4134: # Activate roles for sections with two id numbers
4135: # set start, end times, and the url for the class
1.101 albertel 4136: my $start = ( $env{'form.start_'.$1.'_'.$2} ?
4137: $env{'form.start_'.$1.'_'.$2} :
1.27 matthew 4138: $now );
1.101 albertel 4139: my $end = ( $env{'form.end_'.$1.'_'.$2} ?
4140: $env{'form.end_'.$1.'_'.$2} :
1.27 matthew 4141: 0 );
1.225 raeburn 4142: my $one = $1;
4143: my $two = $2;
4144: my $url='/'.$one.'/';
1.88 raeburn 4145: # split multiple sections
4146: my %sections = ();
1.225 raeburn 4147: my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two},\%sections,$two);
1.88 raeburn 4148: if ($num_sections == 0) {
1.240 raeburn 4149: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,'',$context));
1.88 raeburn 4150: } else {
4151: my $emptysec = 0;
1.404 raeburn 4152: foreach my $sec (sort {$a cmp $b} keys(%sections)) {
1.88 raeburn 4153: if ($sec ne '') {
4154: my $securl = $url.'/'.$sec;
1.240 raeburn 4155: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$two,$start,$end,$one,undef,$sec,$context));
1.88 raeburn 4156: } else {
4157: $emptysec = 1;
4158: }
4159: }
4160: if ($emptysec) {
1.240 raeburn 4161: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,'',$context));
1.88 raeburn 4162: }
4163: }
1.225 raeburn 4164: if (!grep(/^\Q$two\E$/,@rolechanges)) {
4165: push(@rolechanges,$two);
4166: }
1.64 www 4167: } else {
1.190 raeburn 4168: $r->print('<p><span class="LC_error">'.&mt('ERROR').': '.&mt('Unknown command').' <tt>'.$key.'</tt></span></p><br />');
1.64 www 4169: }
1.113 raeburn 4170: foreach my $key (sort(keys(%disallowed))) {
1.274 bisitz 4171: $r->print('<p class="LC_warning">');
1.113 raeburn 4172: if (($key eq 'none') || ($key eq 'all')) {
1.274 bisitz 4173: $r->print(&mt('[_1] may not be used as the name for a section, as it is a reserved word.','<tt>'.$key.'</tt>'));
1.113 raeburn 4174: } else {
1.274 bisitz 4175: $r->print(&mt('[_1] may not be used as the name for a section, as it is the name of a course group.','<tt>'.$key.'</tt>'));
1.113 raeburn 4176: }
1.274 bisitz 4177: $r->print('</p><p>'
4178: .&mt('Please [_1]go back[_2] and choose a different section name.'
4179: ,'<a href="javascript:history.go(-1)'
4180: ,'</a>')
4181: .'</p><br />'
4182: );
1.113 raeburn 4183: }
4184: }
1.101 albertel 4185: } # End of foreach (keys(%env))
1.75 www 4186: # Flush the course logs so reverse user roles immediately updated
1.349 raeburn 4187: $r->register_cleanup(\&Apache::lonnet::flushcourselogs);
1.225 raeburn 4188: if (@rolechanges == 0) {
1.372 raeburn 4189: $r->print('<p>'.&mt('No roles to modify').'</p>');
1.193 raeburn 4190: }
1.225 raeburn 4191: return @rolechanges;
1.220 raeburn 4192: }
4193:
1.375 raeburn 4194: sub get_user_credits {
4195: my ($uname,$udom,$defaultcredits,$cdom,$cnum) = @_;
4196: if ($cdom eq '' || $cnum eq '') {
4197: return unless ($env{'request.course.id'});
4198: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
4199: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
4200: }
4201: my $credits;
4202: my %currhash =
4203: &Apache::lonnet::get('classlist',[$uname.':'.$udom],$cdom,$cnum);
4204: if (keys(%currhash) > 0) {
4205: my @items = split(/:/,$currhash{$uname.':'.$udom});
4206: my $crdidx = &Apache::loncoursedata::CL_CREDITS() - 3;
4207: $credits = $items[$crdidx];
4208: $credits =~ s/[^\d\.]//g;
4209: }
4210: if ($credits eq $defaultcredits) {
4211: undef($credits);
4212: }
4213: return $credits;
4214: }
4215:
1.220 raeburn 4216: sub enroll_single_student {
1.375 raeburn 4217: my ($r,$uhome,$amode,$genpwd,$now,$newuser,$context,$crstype,
4218: $showcredits,$defaultcredits) = @_;
1.318 raeburn 4219: $r->print('<h3>');
4220: if ($crstype eq 'Community') {
4221: $r->print(&mt('Enrolling Member'));
4222: } else {
4223: $r->print(&mt('Enrolling Student'));
4224: }
4225: $r->print('</h3>');
1.220 raeburn 4226:
4227: # Remove non alphanumeric values from section
4228: $env{'form.sections'}=~s/\W//g;
4229:
1.375 raeburn 4230: my $credits;
4231: if (($showcredits) && ($env{'form.credits'} ne '')) {
4232: $credits = $env{'form.credits'};
4233: $credits =~ s/[^\d\.]//g;
4234: if ($credits ne '') {
4235: if ($credits eq $defaultcredits) {
4236: undef($credits);
4237: }
4238: }
4239: }
4240:
1.220 raeburn 4241: # Clean out any old student roles the user has in this class.
4242: &Apache::lonuserutils::modifystudent($env{'form.ccdomain'},
4243: $env{'form.ccuname'},$env{'request.course.id'},undef,$uhome);
4244: my ($startdate,$enddate) = &Apache::lonuserutils::get_dates_from_form();
4245: my $enroll_result =
4246: &Apache::lonnet::modify_student_enrollment($env{'form.ccdomain'},
4247: $env{'form.ccuname'},$env{'form.cid'},$env{'form.cfirstname'},
4248: $env{'form.cmiddlename'},$env{'form.clastname'},
4249: $env{'form.generation'},$env{'form.sections'},$enddate,
1.375 raeburn 4250: $startdate,'manual',undef,$env{'request.course.id'},'',$context,
4251: $credits);
1.220 raeburn 4252: if ($enroll_result =~ /^ok/) {
1.381 bisitz 4253: $r->print(&mt('[_1] enrolled','<b>'.$env{'form.ccuname'}.':'.$env{'form.ccdomain'}.'</b>'));
1.220 raeburn 4254: if ($env{'form.sections'} ne '') {
4255: $r->print(' '.&mt('in section [_1]',$env{'form.sections'}));
4256: }
4257: my ($showstart,$showend);
4258: if ($startdate <= $now) {
4259: $showstart = &mt('Access starts immediately');
4260: } else {
4261: $showstart = &mt('Access starts: ').&Apache::lonlocal::locallocaltime($startdate);
4262: }
4263: if ($enddate == 0) {
4264: $showend = &mt('ends: no ending date');
4265: } else {
4266: $showend = &mt('ends: ').&Apache::lonlocal::locallocaltime($enddate);
4267: }
4268: $r->print('.<br />'.$showstart.'; '.$showend);
4269: if ($startdate <= $now && !$newuser) {
1.386 bisitz 4270: $r->print('<p class="LC_info">');
1.318 raeburn 4271: if ($crstype eq 'Community') {
1.392 raeburn 4272: $r->print(&mt('If the member is currently logged-in to LON-CAPA, the new role can be displayed by using the "Check for changes" link on the Roles/Courses page.'));
1.318 raeburn 4273: } else {
1.392 raeburn 4274: $r->print(&mt('If the student is currently logged-in to LON-CAPA, the new role can be displayed by using the "Check for changes" link on the Roles/Courses page.'));
1.318 raeburn 4275: }
4276: $r->print('</p>');
1.220 raeburn 4277: }
4278: } else {
4279: $r->print(&mt('unable to enroll').": ".$enroll_result);
4280: }
4281: return;
1.188 raeburn 4282: }
4283:
1.204 raeburn 4284: sub get_defaultquota_text {
4285: my ($settingstatus) = @_;
4286: my $defquotatext;
4287: if ($settingstatus eq '') {
1.383 raeburn 4288: $defquotatext = &mt('default');
1.204 raeburn 4289: } else {
4290: my ($usertypes,$order) =
4291: &Apache::lonnet::retrieve_inst_usertypes($env{'form.ccdomain'});
4292: if ($usertypes->{$settingstatus} eq '') {
1.383 raeburn 4293: $defquotatext = &mt('default');
1.204 raeburn 4294: } else {
1.383 raeburn 4295: $defquotatext = &mt('default for [_1]',$usertypes->{$settingstatus});
1.204 raeburn 4296: }
4297: }
4298: return $defquotatext;
4299: }
4300:
1.188 raeburn 4301: sub update_result_form {
4302: my ($uhome) = @_;
4303: my $outcome =
1.367 golterma 4304: '<form name="userupdate" method="post" action="">'."\n";
1.160 raeburn 4305: foreach my $item ('srchby','srchin','srchtype','srchterm','srchdomain','ccuname','ccdomain') {
1.188 raeburn 4306: $outcome .= '<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n";
1.160 raeburn 4307: }
1.207 raeburn 4308: if ($env{'form.origname'} ne '') {
4309: $outcome .= '<input type="hidden" name="origname" value="'.$env{'form.origname'}.'" />'."\n";
4310: }
1.160 raeburn 4311: foreach my $item ('sortby','seluname','seludom') {
4312: if (exists($env{'form.'.$item})) {
1.188 raeburn 4313: $outcome .= '<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n";
1.160 raeburn 4314: }
4315: }
1.188 raeburn 4316: if ($uhome eq 'no_host') {
4317: $outcome .= '<input type="hidden" name="forcenewuser" value="1" />'."\n";
4318: }
4319: $outcome .= '<input type="hidden" name="phase" value="" />'."\n".
1.383 raeburn 4320: '<input type="hidden" name="currstate" value="" />'."\n".
4321: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n".
1.188 raeburn 4322: '</form>';
4323: return $outcome;
1.4 www 4324: }
4325:
1.149 raeburn 4326: sub quota_admin {
1.378 raeburn 4327: my ($setquota,$changeHash,$name) = @_;
1.149 raeburn 4328: my $quotachanged;
4329: if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
4330: # Current user has quota modification privileges
1.267 raeburn 4331: if (ref($changeHash) eq 'HASH') {
4332: $quotachanged = 1;
1.378 raeburn 4333: $changeHash->{$name.'quota'} = $setquota;
1.267 raeburn 4334: }
1.149 raeburn 4335: }
4336: return $quotachanged;
4337: }
4338:
1.267 raeburn 4339: sub tool_admin {
1.275 raeburn 4340: my ($tool,$settool,$changeHash,$context) = @_;
4341: my $canchange = 0;
1.279 raeburn 4342: if ($context eq 'requestcourses') {
1.275 raeburn 4343: if (&Apache::lonnet::allowed('ccc',$env{'form.ccdomain'})) {
4344: $canchange = 1;
4345: }
1.300 raeburn 4346: } elsif ($context eq 'reqcrsotherdom') {
4347: if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
4348: $canchange = 1;
4349: }
1.362 raeburn 4350: } elsif ($context eq 'requestauthor') {
4351: if (&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) {
4352: $canchange = 1;
4353: }
1.275 raeburn 4354: } elsif (&Apache::lonnet::allowed('mut',$env{'form.ccdomain'})) {
4355: # Current user has quota modification privileges
4356: $canchange = 1;
4357: }
1.267 raeburn 4358: my $toolchanged;
1.275 raeburn 4359: if ($canchange) {
1.267 raeburn 4360: if (ref($changeHash) eq 'HASH') {
4361: $toolchanged = 1;
1.362 raeburn 4362: if ($tool eq 'requestauthor') {
4363: $changeHash->{$context} = $settool;
4364: } else {
4365: $changeHash->{$context.'.'.$tool} = $settool;
4366: }
1.267 raeburn 4367: }
4368: }
4369: return $toolchanged;
4370: }
4371:
1.88 raeburn 4372: sub build_roles {
1.89 raeburn 4373: my ($sectionstr,$sections,$role) = @_;
1.88 raeburn 4374: my $num_sections = 0;
4375: if ($sectionstr=~ /,/) {
4376: my @secnums = split/,/,$sectionstr;
1.89 raeburn 4377: if ($role eq 'st') {
4378: $secnums[0] =~ s/\W//g;
4379: $$sections{$secnums[0]} = 1;
4380: $num_sections = 1;
4381: } else {
4382: foreach my $sec (@secnums) {
4383: $sec =~ ~s/\W//g;
1.150 banghart 4384: if (!($sec eq "")) {
1.89 raeburn 4385: if (exists($$sections{$sec})) {
4386: $$sections{$sec} ++;
4387: } else {
4388: $$sections{$sec} = 1;
4389: $num_sections ++;
4390: }
1.88 raeburn 4391: }
4392: }
4393: }
4394: } else {
4395: $sectionstr=~s/\W//g;
4396: unless ($sectionstr eq '') {
4397: $$sections{$sectionstr} = 1;
4398: $num_sections ++;
4399: }
4400: }
1.129 albertel 4401:
1.88 raeburn 4402: return $num_sections;
4403: }
4404:
1.58 www 4405: # ========================================================== Custom Role Editor
4406:
4407: sub custom_role_editor {
1.439 raeburn 4408: my ($r,$context,$brcrum,$prefix,$permission) = @_;
1.324 raeburn 4409: my $action = $env{'form.customroleaction'};
1.439 raeburn 4410: my ($rolename,$helpitem);
1.324 raeburn 4411: if ($action eq 'new') {
4412: $rolename=$env{'form.newrolename'};
4413: } else {
4414: $rolename=$env{'form.rolename'};
1.59 www 4415: }
4416:
1.324 raeburn 4417: my ($crstype,$context);
4418: if ($env{'request.course.id'}) {
4419: $crstype = &Apache::loncommon::course_type();
4420: $context = 'course';
1.439 raeburn 4421: $helpitem = 'Course_Editing_Custom_Roles';
1.324 raeburn 4422: } else {
4423: $context = 'domain';
1.414 raeburn 4424: $crstype = 'course';
1.439 raeburn 4425: $helpitem = 'Domain_Editing_Custom_Roles';
1.324 raeburn 4426: }
1.351 raeburn 4427:
4428: $rolename=~s/[^A-Za-z0-9]//gs;
4429: if (!$rolename || $env{'form.phase'} eq 'pickrole') {
1.439 raeburn 4430: &print_username_entry_form($r,$context,undef,undef,undef,$crstype,$brcrum,
4431: $permission);
1.351 raeburn 4432: return;
4433: }
4434:
1.414 raeburn 4435: my $formname = 'form1';
4436: my %privs=();
4437: my $body_top = '<h2>';
4438: # ------------------------------------------------------- Does this role exist?
1.59 www 4439: my ($rdummy,$roledef)=
4440: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
4441: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1.414 raeburn 4442: $body_top .= &mt('Existing Role').' "';
1.61 www 4443: # ------------------------------------------------- Get current role privileges
1.414 raeburn 4444: ($privs{'system'},$privs{'domain'},$privs{'course'})=split(/\_/,$roledef);
4445: if ($privs{'system'} =~ /bre\&S/) {
4446: if ($context eq 'domain') {
1.417 raeburn 4447: $crstype = 'Course';
1.414 raeburn 4448: } elsif ($crstype eq 'Community') {
4449: $privs{'system'} =~ s/bre\&S//;
4450: }
4451: } elsif ($context eq 'domain') {
4452: $crstype = 'Course';
1.324 raeburn 4453: }
1.59 www 4454: } else {
1.414 raeburn 4455: $body_top .= &mt('New Role').' "';
4456: $roledef='';
1.59 www 4457: }
1.153 banghart 4458: $body_top .= $rolename.'"</h2>';
1.414 raeburn 4459:
4460: # ------------------------------------------------------- What can be assigned?
4461: my %full=();
1.417 raeburn 4462: my %levels=(
1.414 raeburn 4463: course => {},
4464: domain => {},
4465: system => {},
4466: );
4467: my %levelscurrent=(
4468: course => {},
4469: domain => {},
4470: system => {},
4471: );
4472: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
1.160 raeburn 4473: my ($jsback,$elements) = &crumb_utilities();
1.414 raeburn 4474: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
1.417 raeburn 4475: my $head_script =
1.414 raeburn 4476: &Apache::lonuserutils::custom_roledefs_js($context,$crstype,$formname,
4477: \%full,\@templateroles,$jsback);
1.351 raeburn 4478: push (@{$brcrum},
1.414 raeburn 4479: {href => "javascript:backPage(document.$formname,'pickrole','')",
1.351 raeburn 4480: text => "Pick custom role",
4481: faq => 282,bug=>'Instructor Interface',},
1.414 raeburn 4482: {href => "javascript:backPage(document.$formname,'','')",
1.351 raeburn 4483: text => "Edit custom role",
4484: faq => 282,
4485: bug => 'Instructor Interface',
1.439 raeburn 4486: help => $helpitem}
1.351 raeburn 4487: );
4488: my $args = { bread_crumbs => $brcrum,
4489: bread_crumbs_component => 'User Management'};
4490: $r->print(&Apache::loncommon::start_page('Custom Role Editor',
4491: $head_script,$args).
4492: $body_top);
1.414 raeburn 4493: $r->print('<form name="'.$formname.'" method="post" action="">'."\n".
4494: &Apache::lonuserutils::custom_role_header($context,$crstype,
4495: \@templateroles,$prefix));
1.264 bisitz 4496:
1.61 www 4497: $r->print(<<ENDCCF);
4498: <input type="hidden" name="phase" value="set_custom_roles" />
4499: <input type="hidden" name="rolename" value="$rolename" />
4500: ENDCCF
1.414 raeburn 4501: $r->print(&Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
4502: \%levelscurrent,$prefix));
1.135 raeburn 4503: $r->print(&Apache::loncommon::end_data_table().
1.190 raeburn 4504: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'.
1.160 raeburn 4505: '<input type="hidden" name="startrolename" value="'.$env{'form.rolename'}.
1.417 raeburn 4506: '" />'."\n".'<input type="hidden" name="currstate" value="" />'."\n".
1.160 raeburn 4507: '<input type="reset" value="'.&mt("Reset").'" />'."\n".
1.351 raeburn 4508: '<input type="submit" value="'.&mt('Save').'" /></form>');
1.61 www 4509: }
1.414 raeburn 4510:
1.61 www 4511: # ---------------------------------------------------------- Call to definerole
4512: sub set_custom_role {
1.439 raeburn 4513: my ($r,$context,$brcrum,$prefix,$permission) = @_;
1.101 albertel 4514: my $rolename=$env{'form.rolename'};
1.63 www 4515: $rolename=~s/[^A-Za-z0-9]//gs;
1.150 banghart 4516: if (!$rolename) {
1.439 raeburn 4517: &custom_role_editor($r,$context,$brcrum,$prefix,$permission);
1.61 www 4518: return;
4519: }
1.160 raeburn 4520: my ($jsback,$elements) = &crumb_utilities();
1.301 bisitz 4521: my $jscript = '<script type="text/javascript">'
4522: .'// <![CDATA['."\n"
4523: .$jsback."\n"
4524: .'// ]]>'."\n"
4525: .'</script>'."\n";
1.439 raeburn 4526: my $helpitem = 'Course_Editing_Custom_Roles';
4527: if ($context eq 'domain') {
4528: $helpitem = 'Domain_Editing_Custom_Roles';
4529: }
1.352 raeburn 4530: push(@{$brcrum},
4531: {href => "javascript:backPage(document.customresult,'pickrole','')",
4532: text => "Pick custom role",
4533: faq => 282,
4534: bug => 'Instructor Interface',},
4535: {href => "javascript:backPage(document.customresult,'selected_custom_edit','')",
4536: text => "Edit custom role",
4537: faq => 282,
4538: bug => 'Instructor Interface',},
4539: {href => "javascript:backPage(document.customresult,'set_custom_roles','')",
4540: text => "Result",
4541: faq => 282,
4542: bug => 'Instructor Interface',
1.439 raeburn 4543: help => $helpitem,}
1.352 raeburn 4544: );
4545: my $args = { bread_crumbs => $brcrum,
1.414 raeburn 4546: bread_crumbs_component => 'User Management'};
1.351 raeburn 4547: $r->print(&Apache::loncommon::start_page('Save Custom Role',$jscript,$args));
1.160 raeburn 4548:
1.393 raeburn 4549: my $newrole;
1.61 www 4550: my ($rdummy,$roledef)=
1.110 albertel 4551: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
4552:
1.61 www 4553: # ------------------------------------------------------- Does this role exist?
1.188 raeburn 4554: $r->print('<h3>');
1.61 www 4555: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1.73 sakharuk 4556: $r->print(&mt('Existing Role').' "');
1.61 www 4557: } else {
1.73 sakharuk 4558: $r->print(&mt('New Role').' "');
1.61 www 4559: $roledef='';
1.393 raeburn 4560: $newrole = 1;
1.61 www 4561: }
1.188 raeburn 4562: $r->print($rolename.'"</h3>');
1.414 raeburn 4563: # ------------------------------------------------- Assign role and show result
1.61 www 4564:
1.387 bisitz 4565: my $errmsg;
1.414 raeburn 4566: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$prefix);
4567: # Assign role and return result
4568: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
4569: $newprivs{'c'});
1.387 bisitz 4570: if ($result ne 'ok') {
4571: $errmsg = ': '.$result;
4572: }
4573: my $message =
4574: &Apache::lonhtmlcommon::confirm_success(
4575: &mt('Defining Role').$errmsg, ($result eq 'ok' ? 0 : 1));
1.101 albertel 4576: if ($env{'request.course.id'}) {
4577: my $url='/'.$env{'request.course.id'};
1.63 www 4578: $url=~s/\_/\//g;
1.387 bisitz 4579: $result =
4580: &Apache::lonnet::assigncustomrole(
4581: $env{'user.domain'},$env{'user.name'},
4582: $url,
4583: $env{'user.domain'},$env{'user.name'},
4584: $rolename,undef,undef,undef,$context);
4585: if ($result ne 'ok') {
4586: $errmsg = ': '.$result;
4587: }
4588: $message .=
4589: '<br />'
4590: .&Apache::lonhtmlcommon::confirm_success(
4591: &mt('Assigning Role to Self').$errmsg, ($result eq 'ok' ? 0 : 1));
1.63 www 4592: }
1.380 bisitz 4593: $r->print(
1.387 bisitz 4594: &Apache::loncommon::confirmwrapper($message)
4595: .'<br />'
4596: .&Apache::lonhtmlcommon::actionbox([
4597: '<a href="javascript:backPage(document.customresult,'."'pickrole'".')">'
4598: .&mt('Create or edit another custom role')
4599: .'</a>'])
1.380 bisitz 4600: .'<form name="customresult" method="post" action="">'
1.387 bisitz 4601: .&Apache::lonhtmlcommon::echo_form_input([])
4602: .'</form>'
1.380 bisitz 4603: );
1.58 www 4604: }
4605:
1.2 www 4606: # ================================================================ Main Handler
4607: sub handler {
4608: my $r = shift;
4609: if ($r->header_only) {
1.68 www 4610: &Apache::loncommon::content_type($r,'text/html');
1.2 www 4611: $r->send_http_header;
4612: return OK;
4613: }
1.439 raeburn 4614: my ($context,$crstype,$cid,$cnum,$cdom,$allhelpitems);
4615:
1.190 raeburn 4616: if ($env{'request.course.id'}) {
4617: $context = 'course';
1.318 raeburn 4618: $crstype = &Apache::loncommon::course_type();
1.190 raeburn 4619: } elsif ($env{'request.role'} =~ /^au\./) {
1.206 raeburn 4620: $context = 'author';
1.190 raeburn 4621: } else {
4622: $context = 'domain';
4623: }
1.375 raeburn 4624:
1.439 raeburn 4625: my ($permission,$allowed) =
4626: &Apache::lonuserutils::get_permission($context,$crstype);
4627:
4628: if ($allowed) {
4629: my @allhelp;
4630: if ($context eq 'course') {
4631: $cid = $env{'request.course.id'};
4632: $cdom = $env{'course.'.$cid.'.domain'};
4633: $cnum = $env{'course.'.$cid.'.num'};
4634:
4635: if ($permission->{'cusr'}) {
4636: push(@allhelp,'Course_Create_Class_List');
4637: }
4638: if ($permission->{'view'} || $permission->{'cusr'}) {
4639: push(@allhelp,('Course_Change_Privileges','Course_View_Class_List'));
4640: }
4641: if ($permission->{'custom'}) {
4642: push(@allhelp,'Course_Editing_Custom_Roles');
4643: }
4644: if ($permission->{'cusr'}) {
4645: push(@allhelp,('Course_Add_Student','Course_Drop_Student'));
4646: }
4647: unless ($permission->{'cusr_section'}) {
4648: if (&Apache::lonnet::auto_run($cnum,$cdom) && (($permission->{'cusr'}) || ($permission->{'view'}))) {
4649: push(@allhelp,'Course_Automated_Enrollment');
4650: }
4651: if ($permission->{'selfenrolladmin'}) {
4652: push(@allhelp,'Course_Approve_Selfenroll');
4653: }
4654: }
4655: if ($permission->{'grp_manage'}) {
4656: push(@allhelp,'Course_Manage_Group');
4657: }
4658: if ($permission->{'view'} || $permission->{'cusr'}) {
4659: push(@allhelp,'Course_User_Logs');
4660: }
4661: } elsif ($context eq 'author') {
4662: push(@allhelp,('Author_Change_Privileges','Author_Create_Coauthor_List',
4663: 'Author_View_Coauthor_List','Author_User_Logs'));
4664: } else {
4665: if ($permission->{'cusr'}) {
4666: push(@allhelp,'Domain_Change_Privileges');
4667: if ($permission->{'activity'}) {
4668: push(@allhelp,'Domain_User_Access_Logs');
4669: }
4670: push(@allhelp,('Domain_Create_Users','Domain_View_Users_List'));
4671: if ($permission->{'custom'}) {
4672: push(@allhelp,'Domain_Editing_Custom_Roles');
4673: }
4674: push(@allhelp,('Domain_Role_Approvals','Domain_Username_Approvals','Domain_Change_Logs'));
4675: } elsif ($permission->{'view'}) {
4676: push(@allhelp,'Domain_View_Privileges');
4677: if ($permission->{'activity'}) {
4678: push(@allhelp,'Domain_User_Access_Logs');
4679: }
4680: push(@allhelp,('Domain_View_Users_List','Domain_Change_Logs'));
4681: }
4682: }
4683: if (@allhelp) {
4684: $allhelpitems = join(',',@allhelp);
4685: }
4686: }
4687:
1.190 raeburn 4688: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.233 raeburn 4689: ['action','state','callingform','roletype','showrole','bulkaction','popup','phase',
1.391 raeburn 4690: 'username','domain','srchterm','srchdomain','srchin','srchby','srchtype','queue']);
1.190 raeburn 4691: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.351 raeburn 4692: my $args;
4693: my $brcrum = [];
4694: my $bread_crumbs_component = 'User Management';
1.391 raeburn 4695: if (($env{'form.action'} ne 'dateselect') && ($env{'form.action'} ne 'displayuserreq')) {
1.351 raeburn 4696: $brcrum = [{href=>"/adm/createuser",
4697: text=>"User Management",
1.439 raeburn 4698: help=>$allhelpitems}
1.351 raeburn 4699: ];
1.202 raeburn 4700: }
1.190 raeburn 4701: if (!$allowed) {
1.358 raeburn 4702: if ($context eq 'course') {
4703: $r->internal_redirect('/adm/viewclasslist');
4704: return OK;
4705: }
1.190 raeburn 4706: $env{'user.error.msg'}=
4707: "/adm/createuser:cst:0:0:Cannot create/modify user data ".
4708: "or view user status.";
4709: return HTTP_NOT_ACCEPTABLE;
4710: }
4711:
4712: &Apache::loncommon::content_type($r,'text/html');
4713: $r->send_http_header;
4714:
1.375 raeburn 4715: my $showcredits;
4716: if ((($context eq 'course') && ($crstype eq 'Course')) ||
4717: ($context eq 'domain')) {
4718: my %domdefaults =
4719: &Apache::lonnet::get_domain_defaults($env{'request.role.domain'});
4720: if ($domdefaults{'officialcredits'} || $domdefaults{'unofficialcredits'}) {
4721: $showcredits = 1;
4722: }
4723: }
4724:
1.190 raeburn 4725: # Main switch on form.action and form.state, as appropriate
4726: if (! exists($env{'form.action'})) {
1.351 raeburn 4727: $args = {bread_crumbs => $brcrum,
4728: bread_crumbs_component => $bread_crumbs_component};
4729: $r->print(&header(undef,$args));
1.318 raeburn 4730: $r->print(&print_main_menu($permission,$context,$crstype));
1.190 raeburn 4731: } elsif ($env{'form.action'} eq 'upload' && $permission->{'cusr'}) {
1.439 raeburn 4732: my $helpitem = 'Course_Create_Class_List';
4733: if ($context eq 'author') {
4734: $helpitem = 'Author_Create_Coauthor_List';
4735: } elsif ($context eq 'domain') {
4736: $helpitem = 'Domain_Create_Users';
4737: }
1.351 raeburn 4738: push(@{$brcrum},
4739: { href => '/adm/createuser?action=upload&state=',
4740: text => 'Upload Users List',
1.439 raeburn 4741: help => $helpitem,
1.351 raeburn 4742: });
4743: $bread_crumbs_component = 'Upload Users List';
4744: $args = {bread_crumbs => $brcrum,
4745: bread_crumbs_component => $bread_crumbs_component};
4746: $r->print(&header(undef,$args));
1.190 raeburn 4747: $r->print('<form name="studentform" method="post" '.
4748: 'enctype="multipart/form-data" '.
4749: ' action="/adm/createuser">'."\n");
4750: if (! exists($env{'form.state'})) {
4751: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
4752: } elsif ($env{'form.state'} eq 'got_file') {
1.448 ! raeburn 4753: my $result =
! 4754: &Apache::lonuserutils::print_upload_manager_form($r,$context,
! 4755: $permission,
! 4756: $crstype,$showcredits);
! 4757: if ($result eq 'missingdata') {
! 4758: delete($env{'form.state'});
! 4759: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
! 4760: }
1.190 raeburn 4761: } elsif ($env{'form.state'} eq 'enrolling') {
4762: if ($env{'form.datatoken'}) {
1.448 ! raeburn 4763: my $result = &Apache::lonuserutils::upfile_drop_add($r,$context,
! 4764: $permission,
! 4765: $showcredits);
! 4766: if ($result eq 'missingdata') {
! 4767: delete($env{'form.state'});
! 4768: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
! 4769: } elsif ($result eq 'invalidhome') {
! 4770: $env{'form.state'} = 'got_file';
! 4771: delete($env{'form.lcserver'});
! 4772: my $result =
! 4773: &Apache::lonuserutils::print_upload_manager_form($r,$context,$permission,
! 4774: $crstype,$showcredits);
! 4775: if ($result eq 'missingdata') {
! 4776: delete($env{'form.state'});
! 4777: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
! 4778: }
! 4779: }
! 4780: } else {
! 4781: delete($env{'form.state'});
! 4782: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
1.190 raeburn 4783: }
4784: } else {
4785: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
4786: }
1.447 raeburn 4787: $r->print('</form>');
1.416 raeburn 4788: } elsif (((($env{'form.action'} eq 'singleuser') || ($env{'form.action'}
4789: eq 'singlestudent')) && ($permission->{'cusr'})) ||
1.418 raeburn 4790: (($env{'form.action'} eq 'singleuser') && ($permission->{'view'})) ||
1.416 raeburn 4791: (($env{'form.action'} eq 'accesslogs') && ($permission->{'activity'}))) {
1.190 raeburn 4792: my $phase = $env{'form.phase'};
4793: my @search = ('srchterm','srchby','srchin','srchtype','srchdomain');
1.192 albertel 4794: &Apache::loncreateuser::restore_prev_selections();
4795: my $srch;
4796: foreach my $item (@search) {
4797: $srch->{$item} = $env{'form.'.$item};
4798: }
1.207 raeburn 4799: if (($phase eq 'get_user_info') || ($phase eq 'userpicked') ||
1.416 raeburn 4800: ($phase eq 'createnewuser') || ($phase eq 'activity')) {
1.207 raeburn 4801: if ($env{'form.phase'} eq 'createnewuser') {
4802: my $response;
4803: if ($env{'form.srchterm'} !~ /^$match_username$/) {
1.366 bisitz 4804: my $response =
4805: '<span class="LC_warning">'
4806: .&mt('You must specify a valid username. Only the following are allowed:'
4807: .' letters numbers - . @')
4808: .'</span>';
1.221 raeburn 4809: $env{'form.phase'} = '';
1.375 raeburn 4810: &print_username_entry_form($r,$context,$response,$srch,undef,
1.439 raeburn 4811: $crstype,$brcrum,$permission);
1.207 raeburn 4812: } else {
4813: my $ccuname =&LONCAPA::clean_username($srch->{'srchterm'});
4814: my $ccdomain=&LONCAPA::clean_domain($srch->{'srchdomain'});
4815: &print_user_modification_page($r,$ccuname,$ccdomain,
1.221 raeburn 4816: $srch,$response,$context,
1.375 raeburn 4817: $permission,$crstype,$brcrum,
4818: $showcredits);
1.207 raeburn 4819: }
4820: } elsif ($env{'form.phase'} eq 'get_user_info') {
1.190 raeburn 4821: my ($currstate,$response,$forcenewuser,$results) =
1.221 raeburn 4822: &user_search_result($context,$srch);
1.190 raeburn 4823: if ($env{'form.currstate'} eq 'modify') {
4824: $currstate = $env{'form.currstate'};
4825: }
4826: if ($currstate eq 'select') {
4827: &print_user_selection_page($r,$response,$srch,$results,
1.351 raeburn 4828: \@search,$context,undef,$crstype,
4829: $brcrum);
1.416 raeburn 4830: } elsif (($currstate eq 'modify') || ($env{'form.action'} eq 'accesslogs')) {
4831: my ($ccuname,$ccdomain,$uhome);
1.190 raeburn 4832: if (($srch->{'srchby'} eq 'uname') &&
4833: ($srch->{'srchtype'} eq 'exact')) {
4834: $ccuname = $srch->{'srchterm'};
4835: $ccdomain= $srch->{'srchdomain'};
4836: } else {
4837: my @matchedunames = keys(%{$results});
4838: ($ccuname,$ccdomain) = split(/:/,$matchedunames[0]);
4839: }
4840: $ccuname =&LONCAPA::clean_username($ccuname);
4841: $ccdomain=&LONCAPA::clean_domain($ccdomain);
1.416 raeburn 4842: if ($env{'form.action'} eq 'accesslogs') {
4843: my $uhome;
4844: if (($ccuname ne '') && ($ccdomain ne '')) {
4845: $uhome = &Apache::lonnet::homeserver($ccuname,$ccdomain);
4846: }
4847: if (($uhome eq '') || ($uhome eq 'no_host')) {
4848: $env{'form.phase'} = '';
4849: undef($forcenewuser);
4850: #if ($response) {
4851: # unless ($response =~ m{\Q<br /><br />\E$}) {
4852: # $response .= '<br /><br />';
4853: # }
4854: #}
4855: &print_username_entry_form($r,$context,$response,$srch,
1.439 raeburn 4856: $forcenewuser,$crstype,$brcrum,
4857: $permission);
1.416 raeburn 4858: } else {
4859: &print_useraccesslogs_display($r,$ccuname,$ccdomain,$permission,$brcrum);
4860: }
4861: } else {
4862: if ($env{'form.forcenewuser'}) {
4863: $response = '';
4864: }
4865: &print_user_modification_page($r,$ccuname,$ccdomain,
4866: $srch,$response,$context,
4867: $permission,$crstype,$brcrum);
1.190 raeburn 4868: }
4869: } elsif ($currstate eq 'query') {
1.351 raeburn 4870: &print_user_query_page($r,'createuser',$brcrum);
1.190 raeburn 4871: } else {
1.229 raeburn 4872: $env{'form.phase'} = '';
1.207 raeburn 4873: &print_username_entry_form($r,$context,$response,$srch,
1.439 raeburn 4874: $forcenewuser,$crstype,$brcrum,
4875: $permission);
1.190 raeburn 4876: }
4877: } elsif ($env{'form.phase'} eq 'userpicked') {
4878: my $ccuname = &LONCAPA::clean_username($env{'form.seluname'});
4879: my $ccdomain = &LONCAPA::clean_domain($env{'form.seludom'});
1.416 raeburn 4880: if ($env{'form.action'} eq 'accesslogs') {
4881: &print_useraccesslogs_display($r,$ccuname,$ccdomain,$permission,$brcrum);
4882: } else {
4883: &print_user_modification_page($r,$ccuname,$ccdomain,$srch,'',
4884: $context,$permission,$crstype,
4885: $brcrum);
4886: }
4887: } elsif ($env{'form.action'} eq 'accesslogs') {
4888: my $ccuname = &LONCAPA::clean_username($env{'form.accessuname'});
4889: my $ccdomain = &LONCAPA::clean_domain($env{'form.accessudom'});
4890: &print_useraccesslogs_display($r,$ccuname,$ccdomain,$permission,$brcrum);
1.190 raeburn 4891: }
4892: } elsif ($env{'form.phase'} eq 'update_user_data') {
1.375 raeburn 4893: &update_user_data($r,$context,$crstype,$brcrum,$showcredits);
1.190 raeburn 4894: } else {
1.351 raeburn 4895: &print_username_entry_form($r,$context,undef,$srch,undef,$crstype,
1.439 raeburn 4896: $brcrum,$permission);
1.190 raeburn 4897: }
4898: } elsif ($env{'form.action'} eq 'custom' && $permission->{'custom'}) {
1.414 raeburn 4899: my $prefix;
1.190 raeburn 4900: if ($env{'form.phase'} eq 'set_custom_roles') {
1.439 raeburn 4901: &set_custom_role($r,$context,$brcrum,$prefix,$permission);
1.190 raeburn 4902: } else {
1.439 raeburn 4903: &custom_role_editor($r,$context,$brcrum,$prefix,$permission);
1.190 raeburn 4904: }
1.362 raeburn 4905: } elsif (($env{'form.action'} eq 'processauthorreq') &&
4906: ($permission->{'cusr'}) &&
4907: (&Apache::lonnet::allowed('cau',$env{'request.role.domain'}))) {
4908: push(@{$brcrum},
4909: {href => '/adm/createuser?action=processauthorreq',
1.385 bisitz 4910: text => 'Authoring Space requests',
1.362 raeburn 4911: help => 'Domain_Role_Approvals'});
4912: $bread_crumbs_component = 'Authoring requests';
4913: if ($env{'form.state'} eq 'done') {
4914: push(@{$brcrum},
4915: {href => '/adm/createuser?action=authorreqqueue',
4916: text => 'Result',
4917: help => 'Domain_Role_Approvals'});
4918: $bread_crumbs_component = 'Authoring request result';
4919: }
4920: $args = { bread_crumbs => $brcrum,
4921: bread_crumbs_component => $bread_crumbs_component};
1.391 raeburn 4922: my $js = &usernamerequest_javascript();
4923: $r->print(&header(&add_script($js),$args));
1.362 raeburn 4924: if (!exists($env{'form.state'})) {
4925: $r->print(&Apache::loncoursequeueadmin::display_queued_requests('requestauthor',
4926: $env{'request.role.domain'}));
4927: } elsif ($env{'form.state'} eq 'done') {
4928: $r->print('<h3>'.&mt('Authoring request processing').'</h3>'."\n");
4929: $r->print(&Apache::loncoursequeueadmin::update_request_queue('requestauthor',
4930: $env{'request.role.domain'}));
4931: }
1.391 raeburn 4932: } elsif (($env{'form.action'} eq 'processusernamereq') &&
4933: ($permission->{'cusr'}) &&
4934: (&Apache::lonnet::allowed('cau',$env{'request.role.domain'}))) {
4935: push(@{$brcrum},
4936: {href => '/adm/createuser?action=processusernamereq',
4937: text => 'LON-CAPA account requests',
4938: help => 'Domain_Username_Approvals'});
4939: $bread_crumbs_component = 'Account requests';
4940: if ($env{'form.state'} eq 'done') {
4941: push(@{$brcrum},
4942: {href => '/adm/createuser?action=usernamereqqueue',
4943: text => 'Result',
4944: help => 'Domain_Username_Approvals'});
4945: $bread_crumbs_component = 'LON-CAPA account request result';
4946: }
4947: $args = { bread_crumbs => $brcrum,
4948: bread_crumbs_component => $bread_crumbs_component};
4949: my $js = &usernamerequest_javascript();
4950: $r->print(&header(&add_script($js),$args));
4951: if (!exists($env{'form.state'})) {
4952: $r->print(&Apache::loncoursequeueadmin::display_queued_requests('requestusername',
4953: $env{'request.role.domain'}));
4954: } elsif ($env{'form.state'} eq 'done') {
4955: $r->print('<h3>'.&mt('LON-CAPA account request processing').'</h3>'."\n");
4956: $r->print(&Apache::loncoursequeueadmin::update_request_queue('requestusername',
4957: $env{'request.role.domain'}));
4958: }
4959: } elsif (($env{'form.action'} eq 'displayuserreq') &&
4960: ($permission->{'cusr'})) {
4961: my $dom = $env{'form.domain'};
4962: my $uname = $env{'form.username'};
4963: my $warning;
4964: if (($dom =~ /^$match_domain$/) && (&Apache::lonnet::domain($dom) ne '')) {
4965: if (($dom eq $env{'request.role.domain'}) && (&Apache::lonnet::allowed('ccc',$dom))) {
4966: if (($uname =~ /^$match_username$/) && ($env{'form.queue'} eq 'approval')) {
4967: my $uhome = &Apache::lonnet::homeserver($uname,$dom);
4968: if ($uhome eq 'no_host') {
4969: my $queue = $env{'form.queue'};
4970: my $reqkey = &escape($uname).'_'.$queue;
4971: my $namespace = 'usernamequeue';
4972: my $domconfig = &Apache::lonnet::get_domainconfiguser($dom);
4973: my %queued =
4974: &Apache::lonnet::get($namespace,[$reqkey],$dom,$domconfig);
4975: unless ($queued{$reqkey}) {
4976: $warning = &mt('No information was found for this LON-CAPA account request.');
4977: }
4978: } else {
4979: $warning = &mt('A LON-CAPA account already exists for the requested username and domain.');
4980: }
4981: } else {
4982: $warning = &mt('LON-CAPA account request status check is for an invalid username.');
4983: }
4984: } else {
4985: $warning = &mt('You do not have rights to view LON-CAPA account requests in the domain specified.');
4986: }
4987: } else {
4988: $warning = &mt('LON-CAPA account request status check is for an invalid domain.');
4989: }
4990: my $args = { only_body => 1 };
4991: $r->print(&header(undef,$args).
4992: '<h3>'.&mt('LON-CAPA Account Request Details').'</h3>');
4993: if ($warning ne '') {
4994: $r->print('<div class="LC_warning">'.$warning.'</div>');
4995: } else {
4996: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
4997: my $domconfiguser = &Apache::lonnet::get_domainconfiguser($dom);
4998: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
4999: if (ref($domconfig{'usercreation'}) eq 'HASH') {
5000: if (ref($domconfig{'usercreation'}{'cancreate'}) eq 'HASH') {
5001: if (ref($domconfig{'usercreation'}{'cancreate'}{'emailusername'}) eq 'HASH') {
5002: my %info =
5003: &Apache::lonnet::get('nohist_requestedusernames',[$uname],$dom,$domconfiguser);
5004: if (ref($info{$uname}) eq 'HASH') {
1.396 raeburn 5005: my $usertype = $info{$uname}{'inststatus'};
5006: unless ($usertype) {
5007: $usertype = 'default';
5008: }
1.442 raeburn 5009: my ($showstatus,$showemail,$pickstart);
5010: my $numextras = 0;
5011: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.443 raeburn 5012: if ((ref($types) eq 'ARRAY') && (@{$types} > 0)) {
5013: if (ref($usertypes) eq 'HASH') {
5014: if ($usertypes->{$usertype}) {
5015: $showstatus = $usertypes->{$usertype};
5016: } else {
5017: $showstatus = $othertitle;
5018: }
5019: if ($showstatus) {
5020: $numextras ++;
5021: }
1.442 raeburn 5022: }
5023: }
5024: if (($info{$uname}{'email'} ne '') && ($info{$uname}{'email'} ne $uname)) {
5025: $showemail = $info{$uname}{'email'};
5026: $numextras ++;
5027: }
1.396 raeburn 5028: if (ref($domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}) eq 'HASH') {
5029: if ((ref($infofields) eq 'ARRAY') && (ref($infotitles) eq 'HASH')) {
1.442 raeburn 5030: $pickstart = 1;
1.396 raeburn 5031: $r->print('<div>'.&Apache::lonhtmlcommon::start_pick_box());
1.442 raeburn 5032: my ($num,$count);
1.396 raeburn 5033: $count = scalar(keys(%{$domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}}));
1.442 raeburn 5034: $count += $numextras;
1.396 raeburn 5035: foreach my $field (@{$infofields}) {
5036: next unless ($domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}{$field});
5037: next unless ($infotitles->{$field});
5038: $r->print(&Apache::lonhtmlcommon::row_title($infotitles->{$field}).
5039: $info{$uname}{$field});
5040: $num ++;
1.442 raeburn 5041: unless ($count == $num) {
1.396 raeburn 5042: $r->print(&Apache::lonhtmlcommon::row_closure());
5043: }
5044: }
1.442 raeburn 5045: }
5046: }
5047: if ($numextras) {
5048: unless ($pickstart) {
5049: $r->print('<div>'.&Apache::lonhtmlcommon::start_pick_box());
5050: $pickstart = 1;
5051: }
5052: if ($showemail) {
5053: my $closure = '';
5054: unless ($showstatus) {
5055: $closure = 1;
1.391 raeburn 5056: }
1.442 raeburn 5057: $r->print(&Apache::lonhtmlcommon::row_title(&mt('E-mail address')).
5058: $showemail.
5059: &Apache::lonhtmlcommon::row_closure($closure));
1.391 raeburn 5060: }
1.442 raeburn 5061: if ($showstatus) {
5062: $r->print(&Apache::lonhtmlcommon::row_title(&mt('Status type[_1](self-reported)','<br />')).
5063: $showstatus.
5064: &Apache::lonhtmlcommon::row_closure(1));
5065: }
5066: }
5067: if ($pickstart) {
5068: $r->print(&Apache::lonhtmlcommon::end_pick_box().'</div>');
5069: } else {
5070: $r->print('<div>'.&mt('No information to display for this account request.').'</div>');
1.391 raeburn 5071: }
1.442 raeburn 5072: } else {
5073: $r->print('<div>'.&mt('No information available for this account request.').'</div>');
1.391 raeburn 5074: }
5075: }
5076: }
5077: }
5078: }
1.442 raeburn 5079: $r->print(&close_popup_form());
1.207 raeburn 5080: } elsif (($env{'form.action'} eq 'listusers') &&
5081: ($permission->{'view'} || $permission->{'cusr'})) {
1.439 raeburn 5082: my $helpitem = 'Course_View_Class_List';
5083: if ($context eq 'author') {
5084: $helpitem = 'Author_View_Coauthor_List';
5085: } elsif ($context eq 'domain') {
5086: $helpitem = 'Domain_View_Users_List';
5087: }
1.202 raeburn 5088: if ($env{'form.phase'} eq 'bulkchange') {
1.351 raeburn 5089: push(@{$brcrum},
5090: {href => '/adm/createuser?action=listusers',
5091: text => "List Users"},
5092: {href => "/adm/createuser",
5093: text => "Result",
1.439 raeburn 5094: help => $helpitem});
1.351 raeburn 5095: $bread_crumbs_component = 'Update Users';
5096: $args = {bread_crumbs => $brcrum,
5097: bread_crumbs_component => $bread_crumbs_component};
5098: $r->print(&header(undef,$args));
1.202 raeburn 5099: my $setting = $env{'form.roletype'};
5100: my $choice = $env{'form.bulkaction'};
5101: if ($permission->{'cusr'}) {
1.336 raeburn 5102: &Apache::lonuserutils::update_user_list($r,$context,$setting,$choice,$crstype);
1.221 raeburn 5103: } else {
5104: $r->print(&mt('You are not authorized to make bulk changes to user roles'));
1.223 raeburn 5105: $r->print('<p><a href="/adm/createuser?action=listusers">'.&mt('Display User Lists').'</a>');
1.202 raeburn 5106: }
5107: } else {
1.351 raeburn 5108: push(@{$brcrum},
5109: {href => '/adm/createuser?action=listusers',
5110: text => "List Users",
1.439 raeburn 5111: help => $helpitem});
1.351 raeburn 5112: $bread_crumbs_component = 'List Users';
5113: $args = {bread_crumbs => $brcrum,
5114: bread_crumbs_component => $bread_crumbs_component};
1.202 raeburn 5115: my ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles);
5116: my $formname = 'studentform';
1.364 raeburn 5117: my $hidecall = "hide_searching();";
1.321 raeburn 5118: if (($context eq 'domain') && (($env{'form.roletype'} eq 'course') ||
5119: ($env{'form.roletype'} eq 'community'))) {
5120: if ($env{'form.roletype'} eq 'course') {
5121: ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles) =
5122: &Apache::lonuserutils::courses_selector($env{'request.role.domain'},
5123: $formname);
5124: } elsif ($env{'form.roletype'} eq 'community') {
5125: $cb_jscript =
5126: &Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
5127: my %elements = (
5128: coursepick => 'radio',
5129: coursetotal => 'text',
5130: courselist => 'text',
5131: );
5132: $jscript = &Apache::lonhtmlcommon::set_form_elements(\%elements);
5133: }
1.364 raeburn 5134: $jscript .= &verify_user_display($context)."\n".
5135: &Apache::loncommon::check_uncheck_jscript();
1.202 raeburn 5136: my $js = &add_script($jscript).$cb_jscript;
5137: my $loadcode =
5138: &Apache::lonuserutils::course_selector_loadcode($formname);
5139: if ($loadcode ne '') {
1.364 raeburn 5140: $args->{add_entries} = {onload => "$loadcode;$hidecall"};
5141: } else {
5142: $args->{add_entries} = {onload => $hidecall};
1.202 raeburn 5143: }
1.351 raeburn 5144: $r->print(&header($js,$args));
1.191 raeburn 5145: } else {
1.364 raeburn 5146: $args->{add_entries} = {onload => $hidecall};
5147: $jscript = &verify_user_display($context).
5148: &Apache::loncommon::check_uncheck_jscript();
5149: $r->print(&header(&add_script($jscript),$args));
1.191 raeburn 5150: }
1.202 raeburn 5151: &Apache::lonuserutils::print_userlist($r,undef,$permission,$context,
1.375 raeburn 5152: $formname,$totcodes,$codetitles,$idlist,$idlist_titles,
5153: $showcredits);
1.191 raeburn 5154: }
1.213 raeburn 5155: } elsif ($env{'form.action'} eq 'drop' && $permission->{'cusr'}) {
1.318 raeburn 5156: my $brtext;
5157: if ($crstype eq 'Community') {
5158: $brtext = 'Drop Members';
5159: } else {
5160: $brtext = 'Drop Students';
5161: }
1.351 raeburn 5162: push(@{$brcrum},
5163: {href => '/adm/createuser?action=drop',
5164: text => $brtext,
5165: help => 'Course_Drop_Student'});
5166: if ($env{'form.state'} eq 'done') {
5167: push(@{$brcrum},
5168: {href=>'/adm/createuser?action=drop',
5169: text=>"Result"});
5170: }
5171: $bread_crumbs_component = $brtext;
5172: $args = {bread_crumbs => $brcrum,
5173: bread_crumbs_component => $bread_crumbs_component};
5174: $r->print(&header(undef,$args));
1.213 raeburn 5175: if (!exists($env{'form.state'})) {
1.318 raeburn 5176: &Apache::lonuserutils::print_drop_menu($r,$context,$permission,$crstype);
1.213 raeburn 5177: } elsif ($env{'form.state'} eq 'done') {
5178: &Apache::lonuserutils::update_user_list($r,$context,undef,
5179: $env{'form.action'});
5180: }
1.202 raeburn 5181: } elsif ($env{'form.action'} eq 'dateselect') {
5182: if ($permission->{'cusr'}) {
1.351 raeburn 5183: $r->print(&header(undef,{'no_nav_bar' => 1}).
1.375 raeburn 5184: &Apache::lonuserutils::date_section_selector($context,$permission,
5185: $crstype,$showcredits));
1.202 raeburn 5186: } else {
1.351 raeburn 5187: $r->print(&header(undef,{'no_nav_bar' => 1}).
5188: '<span class="LC_error">'.&mt('You do not have permission to modify dates or sections for users').'</span>');
1.202 raeburn 5189: }
1.237 raeburn 5190: } elsif ($env{'form.action'} eq 'selfenroll') {
1.398 raeburn 5191: if ($permission->{selfenrolladmin}) {
5192: my %currsettings = (
5193: selfenroll_types => $env{'course.'.$cid.'.internal.selfenroll_types'},
5194: selfenroll_registered => $env{'course.'.$cid.'.internal.selfenroll_registered'},
5195: selfenroll_section => $env{'course.'.$cid.'.internal.selfenroll_section'},
5196: selfenroll_notifylist => $env{'course.'.$cid.'.internal.selfenroll_notifylist'},
5197: selfenroll_approval => $env{'course.'.$cid.'.internal.selfenroll_approval'},
5198: selfenroll_limit => $env{'course.'.$cid.'.internal.selfenroll_limit'},
5199: selfenroll_cap => $env{'course.'.$cid.'.internal.selfenroll_cap'},
5200: selfenroll_start_date => $env{'course.'.$cid.'.internal.selfenroll_start_date'},
5201: selfenroll_end_date => $env{'course.'.$cid.'.internal.selfenroll_end_date'},
5202: selfenroll_start_access => $env{'course.'.$cid.'.internal.selfenroll_start_access'},
5203: selfenroll_end_access => $env{'course.'.$cid.'.internal.selfenroll_end_access'},
5204: default_enrollment_start_date => $env{'course.'.$cid.'.default_enrollment_start_date'},
5205: default_enrollment_end_date => $env{'course.'.$cid.'.default_enrollment_end_date'},
1.400 raeburn 5206: uniquecode => $env{'course.'.$cid.'.internal.uniquecode'},
1.398 raeburn 5207: );
5208: push(@{$brcrum},
5209: {href => '/adm/createuser?action=selfenroll',
5210: text => "Configure Self-enrollment",
5211: help => 'Course_Self_Enrollment'});
5212: if (!exists($env{'form.state'})) {
5213: $args = { bread_crumbs => $brcrum,
5214: bread_crumbs_component => 'Configure Self-enrollment'};
5215: $r->print(&header(undef,$args));
5216: $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n");
5217: &print_selfenroll_menu($r,'course',$cid,$cdom,$cnum,\%currsettings);
5218: } elsif ($env{'form.state'} eq 'done') {
5219: push (@{$brcrum},
5220: {href=>'/adm/createuser?action=selfenroll',
5221: text=>"Result"});
5222: $args = { bread_crumbs => $brcrum,
5223: bread_crumbs_component => 'Self-enrollment result'};
5224: $r->print(&header(undef,$args));
5225: $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n");
1.400 raeburn 5226: &update_selfenroll_config($r,$cid,$cdom,$cnum,$context,$crstype,\%currsettings);
1.398 raeburn 5227: }
5228: } else {
5229: $r->print(&header(undef,{'no_nav_bar' => 1}).
5230: '<span class="LC_error">'.&mt('You do not have permission to configure self-enrollment').'</span>');
1.237 raeburn 5231: }
1.277 raeburn 5232: } elsif ($env{'form.action'} eq 'selfenrollqueue') {
1.418 raeburn 5233: if ($permission->{selfenrolladmin}) {
1.351 raeburn 5234: push(@{$brcrum},
5235: {href => '/adm/createuser?action=selfenrollqueue',
1.418 raeburn 5236: text => 'Enrollment requests',
1.439 raeburn 5237: help => 'Course_Approve_Selfenroll'});
1.418 raeburn 5238: $bread_crumbs_component = 'Enrollment requests';
5239: if ($env{'form.state'} eq 'done') {
5240: push(@{$brcrum},
5241: {href => '/adm/createuser?action=selfenrollqueue',
5242: text => 'Result',
1.439 raeburn 5243: help => 'Course_Approve_Selfenroll'});
1.418 raeburn 5244: $bread_crumbs_component = 'Enrollment result';
5245: }
5246: $args = { bread_crumbs => $brcrum,
5247: bread_crumbs_component => $bread_crumbs_component};
5248: $r->print(&header(undef,$args));
5249: my $coursedesc = $env{'course.'.$cid.'.description'};
5250: if (!exists($env{'form.state'})) {
5251: $r->print('<h3>'.&mt('Pending enrollment requests').'</h3>'."\n");
5252: $r->print(&Apache::loncoursequeueadmin::display_queued_requests($context,
5253: $cdom,$cnum));
5254: } elsif ($env{'form.state'} eq 'done') {
5255: $r->print('<h3>'.&mt('Enrollment request processing').'</h3>'."\n");
5256: $r->print(&Apache::loncoursequeueadmin::update_request_queue($context,
1.430 raeburn 5257: $cdom,$cnum,$coursedesc));
1.418 raeburn 5258: }
5259: } else {
5260: $r->print(&header(undef,{'no_nav_bar' => 1}).
5261: '<span class="LC_error">'.&mt('You do not have permission to manage self-enrollment').'</span>');
1.351 raeburn 5262: }
1.418 raeburn 5263: } elsif ($env{'form.action'} eq 'changelogs') {
5264: if ($permission->{cusr} || $permission->{view}) {
5265: &print_userchangelogs_display($r,$context,$permission,$brcrum);
5266: } else {
5267: $r->print(&header(undef,{'no_nav_bar' => 1}).
5268: '<span class="LC_error">'.&mt('You do not have permission to view change logs').'</span>');
1.277 raeburn 5269: }
1.428 raeburn 5270: } elsif ($env{'form.action'} eq 'helpdesk') {
5271: if (($permission->{'owner'}) || ($permission->{'co-owner'})) {
5272: if ($env{'form.state'} eq 'process') {
5273: if ($permission->{'owner'}) {
5274: &update_helpdeskaccess($r,$permission,$brcrum);
5275: } else {
5276: &print_helpdeskaccess_display($r,$permission,$brcrum);
1.430 raeburn 5277: }
1.428 raeburn 5278: } else {
5279: &print_helpdeskaccess_display($r,$permission,$brcrum);
5280: }
5281: } else {
5282: $r->print(&header(undef,{'no_nav_bar' => 1}).
5283: '<span class="LC_error">'.&mt('You do not have permission to view helpdesk access').'</span>');
5284: }
1.190 raeburn 5285: } else {
1.351 raeburn 5286: $bread_crumbs_component = 'User Management';
5287: $args = { bread_crumbs => $brcrum,
5288: bread_crumbs_component => $bread_crumbs_component};
5289: $r->print(&header(undef,$args));
1.318 raeburn 5290: $r->print(&print_main_menu($permission,$context,$crstype));
1.190 raeburn 5291: }
1.351 raeburn 5292: $r->print(&Apache::loncommon::end_page());
1.190 raeburn 5293: return OK;
5294: }
5295:
5296: sub header {
1.351 raeburn 5297: my ($jscript,$args) = @_;
1.190 raeburn 5298: my $start_page;
1.351 raeburn 5299: if (ref($args) eq 'HASH') {
5300: $start_page=&Apache::loncommon::start_page('User Management',$jscript,$args);
1.190 raeburn 5301: } else {
1.351 raeburn 5302: $start_page=&Apache::loncommon::start_page('User Management',$jscript);
1.190 raeburn 5303: }
5304: return $start_page;
5305: }
1.2 www 5306:
1.191 raeburn 5307: sub add_script {
5308: my ($js) = @_;
1.301 bisitz 5309: return '<script type="text/javascript">'."\n"
5310: .'// <![CDATA['."\n"
5311: .$js."\n"
5312: .'// ]]>'."\n"
5313: .'</script>'."\n";
1.191 raeburn 5314: }
5315:
1.391 raeburn 5316: sub usernamerequest_javascript {
5317: my $js = <<ENDJS;
5318:
5319: function openusernamereqdisplay(dom,uname,queue) {
5320: var url = '/adm/createuser?action=displayuserreq';
5321: url += '&domain='+dom+'&username='+uname+'&queue='+queue;
5322: var title = 'Account_Request_Browser';
5323: var options = 'scrollbars=1,resizable=1,menubar=0';
5324: options += ',width=700,height=600';
5325: var stdeditbrowser = open(url,title,options,'1');
5326: stdeditbrowser.focus();
5327: return;
5328: }
5329:
5330: ENDJS
5331: }
5332:
5333: sub close_popup_form {
5334: my $close= &mt('Close Window');
5335: return << "END";
5336: <p><form name="displayreq" action="" method="post">
5337: <input type="button" name="closeme" value="$close" onclick="javascript:self.close();" />
5338: </form></p>
5339: END
5340: }
5341:
1.202 raeburn 5342: sub verify_user_display {
1.364 raeburn 5343: my ($context) = @_;
1.374 raeburn 5344: my %lt = &Apache::lonlocal::texthash (
5345: course => 'course(s): description, section(s), status',
5346: community => 'community(s): description, section(s), status',
5347: author => 'author',
5348: );
1.364 raeburn 5349: my $photos;
5350: if (($context eq 'course') && $env{'request.course.id'}) {
5351: $photos = $env{'course.'.$env{'request.course.id'}.'.internal.showphoto'};
5352: }
1.202 raeburn 5353: my $output = <<"END";
5354:
1.364 raeburn 5355: function hide_searching() {
5356: if (document.getElementById('searching')) {
5357: document.getElementById('searching').style.display = 'none';
5358: }
5359: return;
5360: }
5361:
1.202 raeburn 5362: function display_update() {
5363: document.studentform.action.value = 'listusers';
5364: document.studentform.phase.value = 'display';
5365: document.studentform.submit();
5366: }
5367:
1.364 raeburn 5368: function updateCols(caller) {
5369: var context = '$context';
5370: var photos = '$photos';
5371: if (caller == 'Status') {
1.374 raeburn 5372: if ((context == 'domain') &&
5373: ((document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'course') ||
5374: (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community'))) {
1.364 raeburn 5375: document.getElementById('showcolstatus').checked = false;
5376: document.getElementById('showcolstatus').disabled = 'disabled';
5377: document.getElementById('showcolstart').checked = false;
5378: document.getElementById('showcolend').checked = false;
1.374 raeburn 5379: } else {
5380: if (document.studentform.Status.options[document.studentform.Status.selectedIndex].value == 'Any') {
5381: document.getElementById('showcolstatus').checked = true;
5382: document.getElementById('showcolstatus').disabled = '';
5383: document.getElementById('showcolstart').checked = true;
5384: document.getElementById('showcolend').checked = true;
5385: } else {
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: }
1.364 raeburn 5391: }
5392: }
5393: if (caller == 'output') {
5394: if (photos == 1) {
5395: if (document.getElementById('showcolphoto')) {
5396: var photoitem = document.getElementById('showcolphoto');
5397: if (document.studentform.output.options[document.studentform.output.selectedIndex].value == 'html') {
5398: photoitem.checked = true;
5399: photoitem.disabled = '';
5400: } else {
5401: photoitem.checked = false;
5402: photoitem.disabled = 'disabled';
5403: }
5404: }
5405: }
5406: }
5407: if (caller == 'showrole') {
1.371 raeburn 5408: if ((document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'Any') ||
5409: (document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'cr')) {
1.364 raeburn 5410: document.getElementById('showcolrole').checked = true;
5411: document.getElementById('showcolrole').disabled = '';
5412: } else {
5413: document.getElementById('showcolrole').checked = false;
5414: document.getElementById('showcolrole').disabled = 'disabled';
5415: }
1.374 raeburn 5416: if (context == 'domain') {
1.382 raeburn 5417: var quotausageshow = 0;
1.374 raeburn 5418: if ((document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'course') ||
5419: (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community')) {
5420: document.getElementById('showcolstatus').checked = false;
5421: document.getElementById('showcolstatus').disabled = 'disabled';
5422: document.getElementById('showcolstart').checked = false;
5423: document.getElementById('showcolend').checked = false;
5424: } else {
5425: if (document.studentform.Status.options[document.studentform.Status.selectedIndex].value == 'Any') {
5426: document.getElementById('showcolstatus').checked = true;
5427: document.getElementById('showcolstatus').disabled = '';
5428: document.getElementById('showcolstart').checked = true;
5429: document.getElementById('showcolend').checked = true;
5430: }
5431: }
5432: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'domain') {
5433: document.getElementById('showcolextent').disabled = 'disabled';
5434: document.getElementById('showcolextent').checked = 'false';
5435: document.getElementById('showextent').style.display='none';
5436: document.getElementById('showcoltextextent').innerHTML = '';
1.382 raeburn 5437: if ((document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'au') ||
5438: (document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'Any')) {
5439: if (document.getElementById('showcolauthorusage')) {
5440: document.getElementById('showcolauthorusage').disabled = '';
5441: }
5442: if (document.getElementById('showcolauthorquota')) {
5443: document.getElementById('showcolauthorquota').disabled = '';
5444: }
5445: quotausageshow = 1;
5446: }
1.374 raeburn 5447: } else {
5448: document.getElementById('showextent').style.display='block';
5449: document.getElementById('showextent').style.textAlign='left';
5450: document.getElementById('showextent').style.textFace='normal';
5451: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'author') {
5452: document.getElementById('showcolextent').disabled = '';
5453: document.getElementById('showcolextent').checked = 'true';
5454: document.getElementById('showcoltextextent').innerHTML="$lt{'author'}";
5455: } else {
5456: document.getElementById('showcolextent').disabled = '';
5457: document.getElementById('showcolextent').checked = 'true';
5458: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community') {
5459: document.getElementById('showcoltextextent').innerHTML="$lt{'community'}";
5460: } else {
5461: document.getElementById('showcoltextextent').innerHTML="$lt{'course'}";
5462: }
5463: }
5464: }
1.382 raeburn 5465: if (quotausageshow == 0) {
5466: if (document.getElementById('showcolauthorusage')) {
5467: document.getElementById('showcolauthorusage').checked = false;
5468: document.getElementById('showcolauthorusage').disabled = 'disabled';
5469: }
5470: if (document.getElementById('showcolauthorquota')) {
5471: document.getElementById('showcolauthorquota').checked = false;
5472: document.getElementById('showcolauthorquota').disabled = 'disabled';
5473: }
5474: }
1.374 raeburn 5475: }
1.364 raeburn 5476: }
5477: return;
5478: }
5479:
1.202 raeburn 5480: END
5481: return $output;
5482:
5483: }
5484:
1.190 raeburn 5485: ###############################################################
5486: ###############################################################
5487: # Menu Phase One
5488: sub print_main_menu {
1.318 raeburn 5489: my ($permission,$context,$crstype) = @_;
5490: my $linkcontext = $context;
5491: my $stuterm = lc(&Apache::lonnet::plaintext('st',$crstype));
5492: if (($context eq 'course') && ($crstype eq 'Community')) {
5493: $linkcontext = lc($crstype);
5494: $stuterm = 'Members';
5495: }
1.208 raeburn 5496: my %links = (
1.298 droeschl 5497: domain => {
5498: upload => 'Upload a File of Users',
5499: singleuser => 'Add/Modify a User',
5500: listusers => 'Manage Users',
5501: },
5502: author => {
5503: upload => 'Upload a File of Co-authors',
5504: singleuser => 'Add/Modify a Co-author',
5505: listusers => 'Manage Co-authors',
5506: },
5507: course => {
5508: upload => 'Upload a File of Course Users',
5509: singleuser => 'Add/Modify a Course User',
1.354 www 5510: listusers => 'List and Modify Multiple Course Users',
1.298 droeschl 5511: },
1.318 raeburn 5512: community => {
5513: upload => 'Upload a File of Community Users',
5514: singleuser => 'Add/Modify a Community User',
1.354 www 5515: listusers => 'List and Modify Multiple Community Users',
1.318 raeburn 5516: },
5517: );
5518: my %linktitles = (
5519: domain => {
5520: singleuser => 'Add a user to the domain, and/or a course or community in the domain.',
5521: listusers => 'Show and manage users in this domain.',
5522: },
5523: author => {
5524: singleuser => 'Add a user with a co- or assistant author role.',
5525: listusers => 'Show and manage co- or assistant authors.',
5526: },
5527: course => {
5528: singleuser => 'Add a user with a certain role to this course.',
5529: listusers => 'Show and manage users in this course.',
5530: },
5531: community => {
5532: singleuser => 'Add a user with a certain role to this community.',
5533: listusers => 'Show and manage users in this community.',
5534: },
1.298 droeschl 5535: );
1.418 raeburn 5536: if ($linkcontext eq 'domain') {
5537: unless ($permission->{'cusr'}) {
1.430 raeburn 5538: $links{'domain'}{'singleuser'} = 'View a User';
1.418 raeburn 5539: $linktitles{'domain'}{'singleuser'} = 'View information about a user in the domain';
5540: }
5541: } elsif ($linkcontext eq 'course') {
5542: unless ($permission->{'cusr'}) {
5543: $links{'course'}{'singleuser'} = 'View a Course User';
5544: $linktitles{'course'}{'singleuser'} = 'View information about a user in this course';
5545: $links{'course'}{'listusers'} = 'List Course Users';
5546: $linktitles{'course'}{'listusers'} = 'Show information about users in this course';
5547: }
5548: } elsif ($linkcontext eq 'community') {
5549: unless ($permission->{'cusr'}) {
5550: $links{'community'}{'singleuser'} = 'View a Community User';
5551: $linktitles{'community'}{'singleuser'} = 'View information about a user in this community';
5552: $links{'community'}{'listusers'} = 'List Community Users';
5553: $linktitles{'community'}{'listusers'} = 'Show information about users in this community';
5554: }
5555: }
1.298 droeschl 5556: my @menu = ( {categorytitle => 'Single Users',
5557: items =>
5558: [
5559: {
1.318 raeburn 5560: linktext => $links{$linkcontext}{'singleuser'},
1.298 droeschl 5561: icon => 'edit-redo.png',
5562: #help => 'Course_Change_Privileges',
5563: url => '/adm/createuser?action=singleuser',
1.418 raeburn 5564: permission => ($permission->{'view'} || $permission->{'cusr'}),
1.318 raeburn 5565: linktitle => $linktitles{$linkcontext}{'singleuser'},
1.298 droeschl 5566: },
5567: ]},
5568:
5569: {categorytitle => 'Multiple Users',
5570: items =>
5571: [
5572: {
1.318 raeburn 5573: linktext => $links{$linkcontext}{'upload'},
1.340 wenzelju 5574: icon => 'uplusr.png',
1.298 droeschl 5575: #help => 'Course_Create_Class_List',
5576: url => '/adm/createuser?action=upload',
5577: permission => $permission->{'cusr'},
5578: linktitle => 'Upload a CSV or a text file containing users.',
5579: },
5580: {
1.318 raeburn 5581: linktext => $links{$linkcontext}{'listusers'},
1.340 wenzelju 5582: icon => 'mngcu.png',
1.298 droeschl 5583: #help => 'Course_View_Class_List',
5584: url => '/adm/createuser?action=listusers',
5585: permission => ($permission->{'view'} || $permission->{'cusr'}),
1.318 raeburn 5586: linktitle => $linktitles{$linkcontext}{'listusers'},
1.298 droeschl 5587: },
5588:
5589: ]},
5590:
5591: {categorytitle => 'Administration',
5592: items => [ ]},
5593: );
1.415 raeburn 5594:
1.265 mielkec 5595: if ($context eq 'domain'){
1.416 raeburn 5596: push(@{ $menu[0]->{items} }, # Single Users
5597: {
5598: linktext => 'User Access Log',
1.417 raeburn 5599: icon => 'document-properties.png',
1.425 raeburn 5600: #help => 'Domain_User_Access_Logs',
1.416 raeburn 5601: url => '/adm/createuser?action=accesslogs',
5602: permission => $permission->{'activity'},
5603: linktitle => 'View user access log.',
5604: }
5605: );
1.298 droeschl 5606:
5607: push(@{ $menu[2]->{items} }, #Category: Administration
5608: {
5609: linktext => 'Custom Roles',
5610: icon => 'emblem-photos.png',
5611: #help => 'Course_Editing_Custom_Roles',
5612: url => '/adm/createuser?action=custom',
5613: permission => $permission->{'custom'},
5614: linktitle => 'Configure a custom role.',
5615: },
1.362 raeburn 5616: {
5617: linktext => 'Authoring Space Requests',
5618: icon => 'selfenrl-queue.png',
5619: #help => 'Domain_Role_Approvals',
5620: url => '/adm/createuser?action=processauthorreq',
5621: permission => $permission->{'cusr'},
5622: linktitle => 'Approve or reject author role requests',
5623: },
1.363 raeburn 5624: {
1.391 raeburn 5625: linktext => 'LON-CAPA Account Requests',
5626: icon => 'list-add.png',
5627: #help => 'Domain_Username_Approvals',
5628: url => '/adm/createuser?action=processusernamereq',
5629: permission => $permission->{'cusr'},
5630: linktitle => 'Approve or reject LON-CAPA account requests',
5631: },
5632: {
1.363 raeburn 5633: linktext => 'Change Log',
5634: icon => 'document-properties.png',
5635: #help => 'Course_User_Logs',
5636: url => '/adm/createuser?action=changelogs',
1.418 raeburn 5637: permission => ($permission->{'cusr'} || $permission->{'view'}),
1.363 raeburn 5638: linktitle => 'View change log.',
5639: },
1.298 droeschl 5640: );
5641:
1.265 mielkec 5642: }elsif ($context eq 'course'){
1.298 droeschl 5643: my ($cnum,$cdom) = &Apache::lonuserutils::get_course_identity();
1.318 raeburn 5644:
5645: my %linktext = (
5646: 'Course' => {
5647: single => 'Add/Modify a Student',
5648: drop => 'Drop Students',
5649: groups => 'Course Groups',
5650: },
5651: 'Community' => {
5652: single => 'Add/Modify a Member',
5653: drop => 'Drop Members',
5654: groups => 'Community Groups',
5655: },
5656: );
1.411 raeburn 5657: $linktext{'Placement'} = $linktext{'Course'};
1.318 raeburn 5658:
5659: my %linktitle = (
5660: 'Course' => {
5661: single => 'Add a user with the role of student to this course',
5662: drop => 'Remove a student from this course.',
5663: groups => 'Manage course groups',
5664: },
5665: 'Community' => {
5666: single => 'Add a user with the role of member to this community',
5667: drop => 'Remove a member from this community.',
5668: groups => 'Manage community groups',
5669: },
5670: );
5671:
1.411 raeburn 5672: $linktitle{'Placement'} = $linktitle{'Course'};
5673:
1.298 droeschl 5674: push(@{ $menu[0]->{items} }, #Category: Single Users
5675: {
1.318 raeburn 5676: linktext => $linktext{$crstype}{'single'},
1.298 droeschl 5677: #help => 'Course_Add_Student',
5678: icon => 'list-add.png',
5679: url => '/adm/createuser?action=singlestudent',
5680: permission => $permission->{'cusr'},
1.318 raeburn 5681: linktitle => $linktitle{$crstype}{'single'},
1.298 droeschl 5682: },
5683: );
5684:
5685: push(@{ $menu[1]->{items} }, #Category: Multiple Users
5686: {
1.318 raeburn 5687: linktext => $linktext{$crstype}{'drop'},
1.298 droeschl 5688: icon => 'edit-undo.png',
5689: #help => 'Course_Drop_Student',
5690: url => '/adm/createuser?action=drop',
5691: permission => $permission->{'cusr'},
1.318 raeburn 5692: linktitle => $linktitle{$crstype}{'drop'},
1.298 droeschl 5693: },
5694: );
5695: push(@{ $menu[2]->{items} }, #Category: Administration
1.428 raeburn 5696: {
5697: linktext => 'Helpdesk Access',
5698: icon => 'helpdesk-access.png',
5699: #help => 'Course_Helpdesk_Access',
5700: url => '/adm/createuser?action=helpdesk',
5701: permission => ($permission->{'owner'} || $permission->{'co-owner'}),
5702: linktitle => 'Helpdesk access options',
5703: },
5704: {
1.298 droeschl 5705: linktext => 'Custom Roles',
5706: icon => 'emblem-photos.png',
5707: #help => 'Course_Editing_Custom_Roles',
5708: url => '/adm/createuser?action=custom',
5709: permission => $permission->{'custom'},
5710: linktitle => 'Configure a custom role.',
5711: },
5712: {
1.318 raeburn 5713: linktext => $linktext{$crstype}{'groups'},
1.333 wenzelju 5714: icon => 'grps.png',
1.298 droeschl 5715: #help => 'Course_Manage_Group',
5716: url => '/adm/coursegroups?refpage=cusr',
5717: permission => $permission->{'grp_manage'},
1.318 raeburn 5718: linktitle => $linktitle{$crstype}{'groups'},
1.298 droeschl 5719: },
5720: {
1.328 wenzelju 5721: linktext => 'Change Log',
1.298 droeschl 5722: icon => 'document-properties.png',
5723: #help => 'Course_User_Logs',
5724: url => '/adm/createuser?action=changelogs',
1.418 raeburn 5725: permission => ($permission->{'view'} || $permission->{'cusr'}),
1.298 droeschl 5726: linktitle => 'View change log.',
5727: },
5728: );
1.277 raeburn 5729: if ($env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_approval'}) {
1.298 droeschl 5730: push(@{ $menu[2]->{items} },
1.398 raeburn 5731: {
1.298 droeschl 5732: linktext => 'Enrollment Requests',
5733: icon => 'selfenrl-queue.png',
5734: #help => 'Course_Approve_Selfenroll',
5735: url => '/adm/createuser?action=selfenrollqueue',
1.398 raeburn 5736: permission => $permission->{'selfenrolladmin'},
1.298 droeschl 5737: linktitle =>'Approve or reject enrollment requests.',
5738: },
5739: );
1.277 raeburn 5740: }
1.298 droeschl 5741:
1.265 mielkec 5742: if (!exists($permission->{'cusr_section'})){
1.320 raeburn 5743: if ($crstype ne 'Community') {
5744: push(@{ $menu[2]->{items} },
5745: {
5746: linktext => 'Automated Enrollment',
5747: icon => 'roles.png',
5748: #help => 'Course_Automated_Enrollment',
5749: permission => (&Apache::lonnet::auto_run($cnum,$cdom)
1.418 raeburn 5750: && (($permission->{'cusr'}) ||
5751: ($permission->{'view'}))),
1.320 raeburn 5752: url => '/adm/populate',
5753: linktitle => 'Automated enrollment manager.',
5754: }
5755: );
5756: }
5757: push(@{ $menu[2]->{items} },
1.298 droeschl 5758: {
5759: linktext => 'User Self-Enrollment',
1.342 wenzelju 5760: icon => 'self_enroll.png',
1.298 droeschl 5761: #help => 'Course_Self_Enrollment',
5762: url => '/adm/createuser?action=selfenroll',
1.398 raeburn 5763: permission => $permission->{'selfenrolladmin'},
1.317 bisitz 5764: linktitle => 'Configure user self-enrollment.',
1.298 droeschl 5765: },
5766: );
5767: }
1.363 raeburn 5768: } elsif ($context eq 'author') {
1.370 raeburn 5769: push(@{ $menu[2]->{items} }, #Category: Administration
1.363 raeburn 5770: {
5771: linktext => 'Change Log',
5772: icon => 'document-properties.png',
5773: #help => 'Course_User_Logs',
5774: url => '/adm/createuser?action=changelogs',
5775: permission => $permission->{'cusr'},
5776: linktitle => 'View change log.',
5777: },
1.370 raeburn 5778: );
1.363 raeburn 5779: }
5780: return Apache::lonhtmlcommon::generate_menu(@menu);
1.250 raeburn 5781: # { text => 'View Log-in History',
5782: # help => 'Course_User_Logins',
5783: # action => 'logins',
5784: # permission => $permission->{'cusr'},
5785: # });
1.190 raeburn 5786: }
5787:
1.189 albertel 5788: sub restore_prev_selections {
5789: my %saveable_parameters = ('srchby' => 'scalar',
5790: 'srchin' => 'scalar',
5791: 'srchtype' => 'scalar',
5792: );
5793: &Apache::loncommon::store_settings('user','user_picker',
5794: \%saveable_parameters);
5795: &Apache::loncommon::restore_settings('user','user_picker',
5796: \%saveable_parameters);
5797: }
5798:
1.237 raeburn 5799: sub print_selfenroll_menu {
1.418 raeburn 5800: my ($r,$context,$cid,$cdom,$cnum,$currsettings,$additional,$readonly) = @_;
1.322 raeburn 5801: my $crstype = &Apache::loncommon::course_type();
1.398 raeburn 5802: my $formname = 'selfenroll';
1.237 raeburn 5803: my $nolink = 1;
1.398 raeburn 5804: my ($row,$lt) = &Apache::lonuserutils::get_selfenroll_titles();
1.237 raeburn 5805: my $groupslist = &Apache::lonuserutils::get_groupslist();
5806: my $setsec_js =
5807: &Apache::lonuserutils::setsections_javascript($formname,$groupslist);
1.249 raeburn 5808: my %alerts = &Apache::lonlocal::texthash(
5809: acto => 'Activation of self-enrollment was selected for the following domain(s)',
5810: butn => 'but no user types have been checked.',
5811: wilf => "Please uncheck 'activate' or check at least one type.",
5812: );
1.418 raeburn 5813: my $disabled;
5814: if ($readonly) {
5815: $disabled = ' disabled="disabled"';
5816: }
1.405 damieng 5817: &js_escape(\%alerts);
1.249 raeburn 5818: my $selfenroll_js = <<"ENDSCRIPT";
5819: function update_types(caller,num) {
5820: var delidx = getIndexByName('selfenroll_delete');
5821: var actidx = getIndexByName('selfenroll_activate');
5822: if (caller == 'selfenroll_all') {
5823: var selall;
5824: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
5825: if (document.$formname.selfenroll_all[i].checked) {
5826: selall = document.$formname.selfenroll_all[i].value;
5827: }
5828: }
5829: if (selall == 1) {
5830: if (delidx != -1) {
5831: if (document.$formname.selfenroll_delete.length) {
5832: for (var j=0; j<document.$formname.selfenroll_delete.length; j++) {
5833: document.$formname.selfenroll_delete[j].checked = true;
5834: }
5835: } else {
5836: document.$formname.elements[delidx].checked = true;
5837: }
5838: }
5839: if (actidx != -1) {
5840: if (document.$formname.selfenroll_activate.length) {
5841: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
5842: document.$formname.selfenroll_activate[j].checked = false;
5843: }
5844: } else {
5845: document.$formname.elements[actidx].checked = false;
5846: }
5847: }
5848: document.$formname.selfenroll_newdom.selectedIndex = 0;
5849: }
5850: }
5851: if (caller == 'selfenroll_activate') {
5852: if (document.$formname.selfenroll_activate.length) {
5853: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
5854: if (document.$formname.selfenroll_activate[j].value == num) {
5855: if (document.$formname.selfenroll_activate[j].checked) {
5856: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
5857: if (document.$formname.selfenroll_all[i].value == '1') {
5858: document.$formname.selfenroll_all[i].checked = false;
5859: }
5860: if (document.$formname.selfenroll_all[i].value == '0') {
5861: document.$formname.selfenroll_all[i].checked = true;
5862: }
5863: }
5864: }
5865: }
5866: }
5867: } else {
5868: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
5869: if (document.$formname.selfenroll_all[i].value == '1') {
5870: document.$formname.selfenroll_all[i].checked = false;
5871: }
5872: if (document.$formname.selfenroll_all[i].value == '0') {
5873: document.$formname.selfenroll_all[i].checked = true;
5874: }
5875: }
5876: }
5877: }
5878: if (caller == 'selfenroll_delete') {
5879: if (document.$formname.selfenroll_delete.length) {
5880: for (var j=0; j<document.$formname.selfenroll_delete.length; j++) {
5881: if (document.$formname.selfenroll_delete[j].value == num) {
5882: if (document.$formname.selfenroll_delete[j].checked) {
5883: var delindex = getIndexByName('selfenroll_types_'+num);
5884: if (delindex != -1) {
5885: if (document.$formname.elements[delindex].length) {
5886: for (var k=0; k<document.$formname.elements[delindex].length; k++) {
5887: document.$formname.elements[delindex][k].checked = false;
5888: }
5889: } else {
5890: document.$formname.elements[delindex].checked = false;
5891: }
5892: }
5893: }
5894: }
5895: }
5896: } else {
5897: if (document.$formname.selfenroll_delete.checked) {
5898: var delindex = getIndexByName('selfenroll_types_'+num);
5899: if (delindex != -1) {
5900: if (document.$formname.elements[delindex].length) {
5901: for (var k=0; k<document.$formname.elements[delindex].length; k++) {
5902: document.$formname.elements[delindex][k].checked = false;
5903: }
5904: } else {
5905: document.$formname.elements[delindex].checked = false;
5906: }
5907: }
5908: }
5909: }
5910: }
5911: return;
5912: }
5913:
5914: function validate_types(form) {
5915: var needaction = new Array();
5916: var countfail = 0;
5917: var actidx = getIndexByName('selfenroll_activate');
5918: if (actidx != -1) {
5919: if (document.$formname.selfenroll_activate.length) {
5920: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
5921: var num = document.$formname.selfenroll_activate[j].value;
5922: if (document.$formname.selfenroll_activate[j].checked) {
5923: countfail = check_types(num,countfail,needaction)
5924: }
5925: }
5926: } else {
5927: if (document.$formname.selfenroll_activate.checked) {
1.398 raeburn 5928: var num = document.$formname.selfenroll_activate.value;
1.249 raeburn 5929: countfail = check_types(num,countfail,needaction)
5930: }
5931: }
5932: }
5933: if (countfail > 0) {
5934: var msg = "$alerts{'acto'}\\n";
5935: var loopend = needaction.length -1;
5936: if (loopend > 0) {
5937: for (var m=0; m<loopend; m++) {
5938: msg += needaction[m]+", ";
5939: }
5940: }
5941: msg += needaction[loopend]+"\\n$alerts{'butn'}\\n$alerts{'wilf'}";
5942: alert(msg);
5943: return;
5944: }
5945: setSections(form);
5946: }
5947:
5948: function check_types(num,countfail,needaction) {
1.441 raeburn 5949: var boxname = 'selfenroll_types_'+num;
5950: var typeidx = getIndexByName(boxname);
1.249 raeburn 5951: var count = 0;
5952: if (typeidx != -1) {
1.441 raeburn 5953: if (document.$formname.elements[boxname].length) {
5954: for (var k=0; k<document.$formname.elements[boxname].length; k++) {
5955: if (document.$formname.elements[boxname][k].checked) {
1.249 raeburn 5956: count ++;
5957: }
5958: }
5959: } else {
5960: if (document.$formname.elements[typeidx].checked) {
5961: count ++;
5962: }
5963: }
5964: if (count == 0) {
5965: var domidx = getIndexByName('selfenroll_dom_'+num);
5966: if (domidx != -1) {
5967: var domname = document.$formname.elements[domidx].value;
5968: needaction[countfail] = domname;
5969: countfail ++;
5970: }
5971: }
5972: }
5973: return countfail;
5974: }
5975:
1.398 raeburn 5976: function toggleNotify() {
5977: var selfenrollApproval = 0;
5978: if (document.$formname.selfenroll_approval.length) {
5979: for (var i=0; i<document.$formname.selfenroll_approval.length; i++) {
5980: if (document.$formname.selfenroll_approval[i].checked) {
5981: selfenrollApproval = document.$formname.selfenroll_approval[i].value;
5982: break;
5983: }
5984: }
5985: }
5986: if (document.getElementById('notified')) {
5987: if (selfenrollApproval == 0) {
5988: document.getElementById('notified').style.display='none';
5989: } else {
5990: document.getElementById('notified').style.display='block';
5991: }
5992: }
5993: return;
5994: }
5995:
1.249 raeburn 5996: function getIndexByName(item) {
5997: for (var i=0;i<document.$formname.elements.length;i++) {
5998: if (document.$formname.elements[i].name == item) {
5999: return i;
6000: }
6001: }
6002: return -1;
6003: }
6004: ENDSCRIPT
1.256 raeburn 6005:
1.237 raeburn 6006: my $output = '<script type="text/javascript">'."\n".
1.301 bisitz 6007: '// <![CDATA['."\n".
1.249 raeburn 6008: $setsec_js."\n".$selfenroll_js."\n".
1.301 bisitz 6009: '// ]]>'."\n".
1.237 raeburn 6010: '</script>'."\n".
1.256 raeburn 6011: '<h3>'.$lt->{'selfenroll'}.'</h3>'."\n";
1.400 raeburn 6012:
6013: my $visactions = &cat_visibility();
6014: my ($cathash,%cattype);
6015: my %domconfig = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom);
6016: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
6017: $cathash = $domconfig{'coursecategories'}{'cats'};
6018: $cattype{'auth'} = $domconfig{'coursecategories'}{'auth'};
6019: $cattype{'unauth'} = $domconfig{'coursecategories'}{'unauth'};
1.406 raeburn 6020: if ($cattype{'auth'} eq '') {
6021: $cattype{'auth'} = 'std';
6022: }
6023: if ($cattype{'unauth'} eq '') {
6024: $cattype{'unauth'} = 'std';
6025: }
1.400 raeburn 6026: } else {
6027: $cathash = {};
6028: $cattype{'auth'} = 'std';
6029: $cattype{'unauth'} = 'std';
6030: }
6031: if (($cattype{'auth'} eq 'none') && ($cattype{'unauth'} eq 'none')) {
6032: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
6033: '<br />'.
6034: '<br />'.$visactions->{'take'}.'<ul>'.
6035: '<li>'.$visactions->{'dc_chgconf'}.'</li>'.
6036: '</ul>');
6037: } elsif (($cattype{'auth'} !~ /^(std|domonly)$/) && ($cattype{'unauth'} !~ /^(std|domonly)$/)) {
6038: if ($currsettings->{'uniquecode'}) {
6039: $r->print('<span class="LC_info">'.$visactions->{'vis'}.'</span>');
6040: } else {
6041: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
6042: '<br />'.
6043: '<br />'.$visactions->{'take'}.'<ul>'.
6044: '<li>'.$visactions->{'dc_setcode'}.'</li>'.
6045: '</ul><br />');
6046: }
6047: } else {
6048: my ($visible,$cansetvis,$vismsgs) = &visible_in_stdcat($cdom,$cnum,\%domconfig);
6049: if (ref($visactions) eq 'HASH') {
6050: if ($visible) {
6051: $output .= '<p class="LC_info">'.$visactions->{'vis'}.'</p>';
6052: } else {
6053: $output .= '<p class="LC_warning">'.$visactions->{'miss'}.'</p>'
6054: .$visactions->{'yous'}.
6055: '<p>'.$visactions->{'gen'}.'<br />'.$visactions->{'coca'};
6056: if (ref($vismsgs) eq 'ARRAY') {
6057: $output .= '<br />'.$visactions->{'make'}.'<ul>';
6058: foreach my $item (@{$vismsgs}) {
6059: $output .= '<li>'.$visactions->{$item}.'</li>';
6060: }
6061: $output .= '</ul>';
1.256 raeburn 6062: }
1.400 raeburn 6063: $output .= '</p>';
1.256 raeburn 6064: }
6065: }
6066: }
1.398 raeburn 6067: my $actionhref = '/adm/createuser';
6068: if ($context eq 'domain') {
6069: $actionhref = '/adm/modifycourse';
6070: }
1.400 raeburn 6071:
6072: my %noedit;
6073: unless ($context eq 'domain') {
6074: %noedit = &get_noedit_fields($cdom,$cnum,$crstype,$row);
6075: }
1.398 raeburn 6076: $output .= '<form name="'.$formname.'" method="post" action="'.$actionhref.'">'."\n".
1.256 raeburn 6077: &Apache::lonhtmlcommon::start_pick_box();
1.237 raeburn 6078: if (ref($row) eq 'ARRAY') {
6079: foreach my $item (@{$row}) {
6080: my $title = $item;
6081: if (ref($lt) eq 'HASH') {
6082: $title = $lt->{$item};
6083: }
1.297 bisitz 6084: $output .= &Apache::lonhtmlcommon::row_title($title);
1.237 raeburn 6085: if ($item eq 'types') {
1.398 raeburn 6086: my $curr_types;
6087: if (ref($currsettings) eq 'HASH') {
6088: $curr_types = $currsettings->{'selfenroll_types'};
6089: }
1.400 raeburn 6090: if ($noedit{$item}) {
6091: if ($curr_types eq '*') {
6092: $output .= &mt('Any user in any domain');
6093: } else {
6094: my @entries = split(/;/,$curr_types);
6095: if (@entries > 0) {
6096: $output .= '<ul>';
6097: foreach my $entry (@entries) {
6098: my ($currdom,$typestr) = split(/:/,$entry);
6099: next if ($typestr eq '');
6100: my $domdesc = &Apache::lonnet::domain($currdom);
6101: my @currinsttypes = split(',',$typestr);
6102: my ($othertitle,$usertypes,$types) =
6103: &Apache::loncommon::sorted_inst_types($currdom);
6104: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
6105: $usertypes->{'any'} = &mt('any user');
6106: if (keys(%{$usertypes}) > 0) {
6107: $usertypes->{'other'} = &mt('other users');
6108: }
6109: my @longinsttypes = map { $usertypes->{$_}; } @currinsttypes;
6110: $output .= '<li>'.$domdesc.':'.join(', ',@longinsttypes).'</li>';
6111: }
6112: }
6113: $output .= '</ul>';
6114: } else {
6115: $output .= &mt('None');
6116: }
6117: }
6118: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6119: next;
6120: }
1.241 raeburn 6121: my $showdomdesc = 1;
6122: my $includeempty = 1;
6123: my $num = 0;
6124: $output .= &Apache::loncommon::start_data_table().
6125: &Apache::loncommon::start_data_table_row()
6126: .'<td colspan="2"><span class="LC_nobreak"><label>'
6127: .&mt('Any user in any domain:')
6128: .' <input type="radio" name="selfenroll_all" value="1" ';
6129: if ($curr_types eq '*') {
6130: $output .= ' checked="checked" ';
6131: }
1.249 raeburn 6132: $output .= 'onchange="javascript:update_types('.
1.418 raeburn 6133: "'selfenroll_all'".');"'.$disabled.' />'.&mt('Yes').'</label>'.
1.249 raeburn 6134: ' <input type="radio" name="selfenroll_all" value="0" ';
1.241 raeburn 6135: if ($curr_types ne '*') {
6136: $output .= ' checked="checked" ';
6137: }
1.249 raeburn 6138: $output .= ' onchange="javascript:update_types('.
1.418 raeburn 6139: "'selfenroll_all'".');"'.$disabled.' />'.&mt('No').'</label></td>'.
1.249 raeburn 6140: &Apache::loncommon::end_data_table_row().
6141: &Apache::loncommon::end_data_table().
6142: &mt('Or').'<br />'.
6143: &Apache::loncommon::start_data_table();
1.241 raeburn 6144: my %currdoms;
1.249 raeburn 6145: if ($curr_types eq '') {
1.241 raeburn 6146: $output .= &new_selfenroll_dom_row($cdom,'0');
6147: } elsif ($curr_types ne '*') {
6148: my @entries = split(/;/,$curr_types);
6149: if (@entries > 0) {
6150: foreach my $entry (@entries) {
6151: my ($currdom,$typestr) = split(/:/,$entry);
6152: $currdoms{$currdom} = 1;
6153: my $domdesc = &Apache::lonnet::domain($currdom);
1.249 raeburn 6154: my @currinsttypes = split(',',$typestr);
1.241 raeburn 6155: $output .= &Apache::loncommon::start_data_table_row()
6156: .'<td valign="top"><span class="LC_nobreak">'.&mt('Domain:').'<b>'
6157: .' '.$domdesc.' ('.$currdom.')'
6158: .'</b><input type="hidden" name="selfenroll_dom_'.$num
6159: .'" value="'.$currdom.'" /></span><br />'
6160: .'<span class="LC_nobreak"><label><input type="checkbox" '
1.418 raeburn 6161: .'name="selfenroll_delete" value="'.$num.'" onchange="javascript:update_types('."'selfenroll_delete','$num'".');"'.$disabled.' />'
1.241 raeburn 6162: .&mt('Delete').'</label></span></td>';
1.249 raeburn 6163: $output .= '<td valign="top"> '.&mt('User types:').'<br />'
1.418 raeburn 6164: .&selfenroll_inst_types($num,$currdom,\@currinsttypes,$readonly).'</td>'
1.241 raeburn 6165: .&Apache::loncommon::end_data_table_row();
6166: $num ++;
6167: }
6168: }
6169: }
1.249 raeburn 6170: my $add_domtitle = &mt('Users in additional domain:');
1.241 raeburn 6171: if ($curr_types eq '*') {
1.249 raeburn 6172: $add_domtitle = &mt('Users in specific domain:');
1.241 raeburn 6173: } elsif ($curr_types eq '') {
1.249 raeburn 6174: $add_domtitle = &mt('Users in other domain:');
1.241 raeburn 6175: }
1.446 raeburn 6176: my ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('enroll',$cdom);
1.241 raeburn 6177: $output .= &Apache::loncommon::start_data_table_row()
6178: .'<td colspan="2"><span class="LC_nobreak">'.$add_domtitle.'</span><br />'
6179: .&Apache::loncommon::select_dom_form('','selfenroll_newdom',
1.446 raeburn 6180: $includeempty,$showdomdesc,'',$trusted,$untrusted,$readonly)
1.241 raeburn 6181: .'<input type="hidden" name="selfenroll_types_total" value="'.$num.'" />'
6182: .'</td>'.&Apache::loncommon::end_data_table_row()
6183: .&Apache::loncommon::end_data_table();
1.237 raeburn 6184: } elsif ($item eq 'registered') {
6185: my ($regon,$regoff);
1.398 raeburn 6186: my $registered;
6187: if (ref($currsettings) eq 'HASH') {
6188: $registered = $currsettings->{'selfenroll_registered'};
6189: }
1.400 raeburn 6190: if ($noedit{$item}) {
6191: if ($registered) {
6192: $output .= &mt('Must be registered in course');
6193: } else {
6194: $output .= &mt('No requirement');
6195: }
6196: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6197: next;
6198: }
1.398 raeburn 6199: if ($registered) {
1.237 raeburn 6200: $regon = ' checked="checked" ';
1.419 raeburn 6201: $regoff = '';
1.237 raeburn 6202: } else {
1.419 raeburn 6203: $regon = '';
1.237 raeburn 6204: $regoff = ' checked="checked" ';
6205: }
6206: $output .= '<label>'.
1.419 raeburn 6207: '<input type="radio" name="selfenroll_registered" value="1"'.$regon.$disabled.' />'.
1.244 bisitz 6208: &mt('Yes').'</label> <label>'.
1.419 raeburn 6209: '<input type="radio" name="selfenroll_registered" value="0"'.$regoff.$disabled.' />'.
1.244 bisitz 6210: &mt('No').'</label>';
1.237 raeburn 6211: } elsif ($item eq 'enroll_dates') {
1.398 raeburn 6212: my ($starttime,$endtime);
6213: if (ref($currsettings) eq 'HASH') {
6214: $starttime = $currsettings->{'selfenroll_start_date'};
6215: $endtime = $currsettings->{'selfenroll_end_date'};
6216: if ($starttime eq '') {
6217: $starttime = $currsettings->{'default_enrollment_start_date'};
6218: }
6219: if ($endtime eq '') {
6220: $endtime = $currsettings->{'default_enrollment_end_date'};
6221: }
1.237 raeburn 6222: }
1.400 raeburn 6223: if ($noedit{$item}) {
6224: $output .= &mt('From: [_1], to: [_2]',&Apache::lonlocal::locallocaltime($starttime),
6225: &Apache::lonlocal::locallocaltime($endtime));
6226: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6227: next;
6228: }
1.237 raeburn 6229: my $startform =
6230: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_start_date',$starttime,
1.418 raeburn 6231: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
1.237 raeburn 6232: my $endform =
6233: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_end_date',$endtime,
1.418 raeburn 6234: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
1.237 raeburn 6235: $output .= &selfenroll_date_forms($startform,$endform);
6236: } elsif ($item eq 'access_dates') {
1.398 raeburn 6237: my ($starttime,$endtime);
6238: if (ref($currsettings) eq 'HASH') {
6239: $starttime = $currsettings->{'selfenroll_start_access'};
6240: $endtime = $currsettings->{'selfenroll_end_access'};
6241: if ($starttime eq '') {
6242: $starttime = $currsettings->{'default_enrollment_start_date'};
6243: }
6244: if ($endtime eq '') {
6245: $endtime = $currsettings->{'default_enrollment_end_date'};
6246: }
1.237 raeburn 6247: }
1.400 raeburn 6248: if ($noedit{$item}) {
6249: $output .= &mt('From: [_1], to: [_2]',&Apache::lonlocal::locallocaltime($starttime),
6250: &Apache::lonlocal::locallocaltime($endtime));
6251: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6252: next;
6253: }
1.237 raeburn 6254: my $startform =
6255: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_start_access',$starttime,
1.418 raeburn 6256: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
1.237 raeburn 6257: my $endform =
6258: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_end_access',$endtime,
1.418 raeburn 6259: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
1.237 raeburn 6260: $output .= &selfenroll_date_forms($startform,$endform);
6261: } elsif ($item eq 'section') {
1.398 raeburn 6262: my $currsec;
6263: if (ref($currsettings) eq 'HASH') {
6264: $currsec = $currsettings->{'selfenroll_section'};
6265: }
1.237 raeburn 6266: my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum);
6267: my $newsecval;
6268: if ($currsec ne 'none' && $currsec ne '') {
6269: if (!defined($sections_count{$currsec})) {
6270: $newsecval = $currsec;
6271: }
6272: }
1.400 raeburn 6273: if ($noedit{$item}) {
6274: if ($currsec ne '') {
6275: $output .= $currsec;
6276: } else {
6277: $output .= &mt('No specific section');
6278: }
6279: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6280: next;
6281: }
1.237 raeburn 6282: my $sections_select =
1.418 raeburn 6283: &Apache::lonuserutils::course_sections(\%sections_count,'st',$currsec,$disabled);
1.237 raeburn 6284: $output .= '<table class="LC_createuser">'."\n".
6285: '<tr class="LC_section_row">'."\n".
6286: '<td align="center">'.&mt('Existing sections')."\n".
6287: '<br />'.$sections_select.'</td><td align="center">'.
6288: &mt('New section').'<br />'."\n".
1.418 raeburn 6289: '<input type="text" name="newsec" size="15" value="'.$newsecval.'"'.$disabled.' />'."\n".
1.237 raeburn 6290: '<input type="hidden" name="sections" value="" />'."\n".
6291: '</td></tr></table>'."\n";
1.276 raeburn 6292: } elsif ($item eq 'approval') {
1.398 raeburn 6293: my ($currnotified,$currapproval,%appchecked);
6294: my %selfdescs = &Apache::lonuserutils::selfenroll_default_descs();
1.430 raeburn 6295: if (ref($currsettings) eq 'HASH') {
1.398 raeburn 6296: $currnotified = $currsettings->{'selfenroll_notifylist'};
6297: $currapproval = $currsettings->{'selfenroll_approval'};
6298: }
6299: if ($currapproval !~ /^[012]$/) {
6300: $currapproval = 0;
6301: }
1.400 raeburn 6302: if ($noedit{$item}) {
6303: $output .= $selfdescs{'approval'}{$currapproval}.
6304: '<br />'.&mt('(Set by Domain Coordinator)');
6305: next;
6306: }
1.398 raeburn 6307: $appchecked{$currapproval} = ' checked="checked"';
6308: for my $i (0..2) {
6309: $output .= '<label>'.
6310: '<input type="radio" name="selfenroll_approval" value="'.$i.'"'.
1.418 raeburn 6311: $appchecked{$i}.' onclick="toggleNotify();"'.$disabled.' />'.
6312: $selfdescs{'approval'}{$i}.'</label>'.(' 'x2);
1.276 raeburn 6313: }
6314: my %advhash = &Apache::lonnet::get_course_adv_roles($cid,1);
6315: my (@ccs,%notified);
1.322 raeburn 6316: my $ccrole = 'cc';
6317: if ($crstype eq 'Community') {
6318: $ccrole = 'co';
6319: }
6320: if ($advhash{$ccrole}) {
6321: @ccs = split(/,/,$advhash{$ccrole});
1.276 raeburn 6322: }
6323: if ($currnotified) {
6324: foreach my $current (split(/,/,$currnotified)) {
6325: $notified{$current} = 1;
6326: if (!grep(/^\Q$current\E$/,@ccs)) {
6327: push(@ccs,$current);
6328: }
6329: }
6330: }
6331: if (@ccs) {
1.398 raeburn 6332: my $style;
6333: unless ($currapproval) {
6334: $style = ' style="display: none;"';
6335: }
6336: $output .= '<br /><div id="notified"'.$style.'>'.
6337: &mt('Personnel to be notified when an enrollment request needs approval, or has been approved:').' '.
6338: &Apache::loncommon::start_data_table().
1.276 raeburn 6339: &Apache::loncommon::start_data_table_row();
6340: my $count = 0;
6341: my $numcols = 4;
6342: foreach my $cc (sort(@ccs)) {
6343: my $notifyon;
6344: my ($ccuname,$ccudom) = split(/:/,$cc);
6345: if ($notified{$cc}) {
6346: $notifyon = ' checked="checked" ';
6347: }
6348: if ($count && !$count%$numcols) {
6349: $output .= &Apache::loncommon::end_data_table_row().
6350: &Apache::loncommon::start_data_table_row()
6351: }
6352: $output .= '<td><span class="LC_nobreak"><label>'.
1.418 raeburn 6353: '<input type="checkbox" name="selfenroll_notify"'.$notifyon.' value="'.$cc.'"'.$disabled.' />'.
1.276 raeburn 6354: &Apache::loncommon::plainname($ccuname,$ccudom).
6355: '</label></span></td>';
1.343 raeburn 6356: $count ++;
1.276 raeburn 6357: }
6358: my $rem = $count%$numcols;
6359: if ($rem) {
6360: my $emptycols = $numcols - $rem;
6361: for (my $i=0; $i<$emptycols; $i++) {
6362: $output .= '<td> </td>';
6363: }
6364: }
6365: $output .= &Apache::loncommon::end_data_table_row().
1.398 raeburn 6366: &Apache::loncommon::end_data_table().
6367: '</div>';
1.276 raeburn 6368: }
6369: } elsif ($item eq 'limit') {
1.398 raeburn 6370: my ($crslimit,$selflimit,$nolimit,$currlim,$currcap);
6371: if (ref($currsettings) eq 'HASH') {
6372: $currlim = $currsettings->{'selfenroll_limit'};
6373: $currcap = $currsettings->{'selfenroll_cap'};
6374: }
1.400 raeburn 6375: if ($noedit{$item}) {
6376: if (($currlim eq 'allstudents') || ($currlim eq 'selfenrolled')) {
6377: if ($currlim eq 'allstudents') {
6378: $output .= &mt('Limit by total students');
6379: } elsif ($currlim eq 'selfenrolled') {
6380: $output .= &mt('Limit by total self-enrolled students');
6381: }
6382: $output .= ' '.&mt('Maximum: [_1]',$currcap).
6383: '<br />'.&mt('(Set by Domain Coordinator)');
6384: } else {
6385: $output .= &mt('No limit').'<br />'.&mt('(Set by Domain Coordinator)');
6386: }
6387: next;
6388: }
1.276 raeburn 6389: if ($currlim eq 'allstudents') {
6390: $crslimit = ' checked="checked" ';
6391: $selflimit = ' ';
6392: $nolimit = ' ';
6393: } elsif ($currlim eq 'selfenrolled') {
6394: $crslimit = ' ';
6395: $selflimit = ' checked="checked" ';
6396: $nolimit = ' ';
6397: } else {
6398: $crslimit = ' ';
6399: $selflimit = ' ';
1.398 raeburn 6400: $nolimit = ' checked="checked" ';
1.276 raeburn 6401: }
6402: $output .= '<table><tr><td><label>'.
1.418 raeburn 6403: '<input type="radio" name="selfenroll_limit" value="none"'.$nolimit.$disabled.'/>'.
1.276 raeburn 6404: &mt('No limit').'</label></td><td><label>'.
1.418 raeburn 6405: '<input type="radio" name="selfenroll_limit" value="allstudents"'.$crslimit.$disabled.'/>'.
1.276 raeburn 6406: &mt('Limit by total students').'</label></td><td><label>'.
1.418 raeburn 6407: '<input type="radio" name="selfenroll_limit" value="selfenrolled"'.$selflimit.$disabled.'/>'.
1.276 raeburn 6408: &mt('Limit by total self-enrolled students').
6409: '</td></tr><tr>'.
6410: '<td> </td><td colspan="2"><span class="LC_nobreak">'.
6411: (' 'x3).&mt('Maximum number allowed: ').
1.418 raeburn 6412: '<input type="text" name="selfenroll_cap" size = "5" value="'.$currcap.'"'.$disabled.' /></td></tr></table>';
1.237 raeburn 6413: }
6414: $output .= &Apache::lonhtmlcommon::row_closure(1);
6415: }
6416: }
1.418 raeburn 6417: $output .= &Apache::lonhtmlcommon::end_pick_box().'<br />';
6418: unless ($readonly) {
6419: $output .= '<input type="button" name="selfenrollconf" value="'
6420: .&mt('Save').'" onclick="validate_types(this.form);" />';
6421: }
6422: $output .= '<input type="hidden" name="action" value="selfenroll" />'
6423: .'<input type="hidden" name="state" value="done" />'."\n"
6424: .$additional.'</form>';
1.237 raeburn 6425: $r->print($output);
6426: return;
6427: }
6428:
1.400 raeburn 6429: sub get_noedit_fields {
6430: my ($cdom,$cnum,$crstype,$row) = @_;
6431: my %noedit;
6432: if (ref($row) eq 'ARRAY') {
6433: my %settings = &Apache::lonnet::get('environment',['internal.coursecode','internal.textbook',
6434: 'internal.selfenrollmgrdc',
6435: 'internal.selfenrollmgrcc'],$cdom,$cnum);
6436: my $type = &Apache::lonuserutils::get_extended_type($cdom,$cnum,$crstype,\%settings);
6437: my (%specific_managebydc,%specific_managebycc,%default_managebydc);
6438: map { $specific_managebydc{$_} = 1; } (split(/,/,$settings{'internal.selfenrollmgrdc'}));
6439: map { $specific_managebycc{$_} = 1; } (split(/,/,$settings{'internal.selfenrollmgrcc'}));
6440: my %domdefaults = &Apache::lonnet::get_domain_defaults($cdom);
6441: map { $default_managebydc{$_} = 1; } (split(/,/,$domdefaults{$type.'selfenrolladmdc'}));
6442:
6443: foreach my $item (@{$row}) {
6444: next if ($specific_managebycc{$item});
6445: if (($specific_managebydc{$item}) || ($default_managebydc{$item})) {
6446: $noedit{$item} = 1;
6447: }
6448: }
6449: }
6450: return %noedit;
6451: }
6452:
6453: sub visible_in_stdcat {
6454: my ($cdom,$cnum,$domconf) = @_;
6455: my ($cathash,%settable,@vismsgs,$cansetvis,$visible);
6456: unless (ref($domconf) eq 'HASH') {
6457: return ($visible,$cansetvis,\@vismsgs);
6458: }
6459: if (ref($domconf->{'coursecategories'}) eq 'HASH') {
6460: if ($domconf->{'coursecategories'}{'togglecats'} eq 'crs') {
1.256 raeburn 6461: $settable{'togglecats'} = 1;
6462: }
1.400 raeburn 6463: if ($domconf->{'coursecategories'}{'categorize'} eq 'crs') {
1.256 raeburn 6464: $settable{'categorize'} = 1;
6465: }
1.400 raeburn 6466: $cathash = $domconf->{'coursecategories'}{'cats'};
1.256 raeburn 6467: }
1.260 raeburn 6468: if ($settable{'togglecats'} && $settable{'categorize'}) {
1.256 raeburn 6469: $cansetvis = &mt('You are able to both assign a course category and choose to exclude this course from the catalog.');
6470: } elsif ($settable{'togglecats'}) {
6471: $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 6472: } elsif ($settable{'categorize'}) {
1.256 raeburn 6473: $cansetvis = &mt('You may assign a course category, but only a Domain Coordinator may choose to exclude this course from the catalog.');
6474: } else {
6475: $cansetvis = &mt('Only a Domain Coordinator may assign a course category or choose to exclude this course from the catalog.');
6476: }
6477:
6478: my %currsettings =
6479: &Apache::lonnet::get('environment',['hidefromcat','categories','internal.coursecode'],
6480: $cdom,$cnum);
1.400 raeburn 6481: $visible = 0;
1.256 raeburn 6482: if ($currsettings{'internal.coursecode'} ne '') {
1.400 raeburn 6483: if (ref($domconf->{'coursecategories'}) eq 'HASH') {
6484: $cathash = $domconf->{'coursecategories'}{'cats'};
1.256 raeburn 6485: if (ref($cathash) eq 'HASH') {
6486: if ($cathash->{'instcode::0'} eq '') {
6487: push(@vismsgs,'dc_addinst');
6488: } else {
6489: $visible = 1;
6490: }
6491: } else {
6492: $visible = 1;
6493: }
6494: } else {
6495: $visible = 1;
6496: }
6497: } else {
6498: if (ref($cathash) eq 'HASH') {
6499: if ($cathash->{'instcode::0'} ne '') {
6500: push(@vismsgs,'dc_instcode');
6501: }
6502: } else {
6503: push(@vismsgs,'dc_instcode');
6504: }
6505: }
6506: if ($currsettings{'categories'} ne '') {
6507: my $cathash;
1.400 raeburn 6508: if (ref($domconf->{'coursecategories'}) eq 'HASH') {
6509: $cathash = $domconf->{'coursecategories'}{'cats'};
1.256 raeburn 6510: if (ref($cathash) eq 'HASH') {
6511: if (keys(%{$cathash}) == 0) {
6512: push(@vismsgs,'dc_catalog');
6513: } elsif ((keys(%{$cathash}) == 1) && ($cathash->{'instcode::0'} ne '')) {
6514: push(@vismsgs,'dc_categories');
6515: } else {
6516: my @currcategories = split('&',$currsettings{'categories'});
6517: my $matched = 0;
6518: foreach my $cat (@currcategories) {
6519: if ($cathash->{$cat} ne '') {
6520: $visible = 1;
6521: $matched = 1;
6522: last;
6523: }
6524: }
6525: if (!$matched) {
1.260 raeburn 6526: if ($settable{'categorize'}) {
1.256 raeburn 6527: push(@vismsgs,'chgcat');
6528: } else {
6529: push(@vismsgs,'dc_chgcat');
6530: }
6531: }
6532: }
6533: }
6534: }
6535: } else {
6536: if (ref($cathash) eq 'HASH') {
6537: if ((keys(%{$cathash}) > 1) ||
6538: (keys(%{$cathash}) == 1) && ($cathash->{'instcode::0'} eq '')) {
1.260 raeburn 6539: if ($settable{'categorize'}) {
1.256 raeburn 6540: push(@vismsgs,'addcat');
6541: } else {
6542: push(@vismsgs,'dc_addcat');
6543: }
6544: }
6545: }
6546: }
6547: if ($currsettings{'hidefromcat'} eq 'yes') {
6548: $visible = 0;
6549: if ($settable{'togglecats'}) {
6550: unshift(@vismsgs,'unhide');
6551: } else {
6552: unshift(@vismsgs,'dc_unhide')
6553: }
6554: }
1.400 raeburn 6555: return ($visible,$cansetvis,\@vismsgs);
6556: }
6557:
6558: sub cat_visibility {
6559: my %visactions = &Apache::lonlocal::texthash(
6560: vis => 'This course/community currently appears in the Course/Community Catalog for this domain.',
6561: 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.',
6562: miss => 'This course/community does not currently appear in the Course/Community Catalog for this domain.',
6563: none => 'Display of a course catalog is disabled for this domain.',
6564: yous => 'You should remedy this if you plan to allow self-enrollment, otherwise students will have difficulty finding this course.',
6565: 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.',
6566: make => 'Make any changes to self-enrollment settings below, click "Save", then take action to include the course in the Catalog:',
6567: take => 'Take the following action to ensure the course appears in the Catalog:',
6568: dc_chgconf => 'Ask a domain coordinator to change the Catalog type for this domain.',
6569: dc_setcode => 'Ask a domain coordinator to assign a six character code to the course',
6570: dc_unhide => 'Ask a domain coordinator to change the "Exclude from course catalog" setting.',
6571: dc_addinst => 'Ask a domain coordinator to enable display the catalog of "Official courses (with institutional codes)".',
6572: dc_instcode => 'Ask a domain coordinator to assign an institutional code (if this is an official course).',
6573: dc_catalog => 'Ask a domain coordinator to enable or create at least one course category in the domain.',
6574: dc_categories => 'Ask a domain coordinator to create a hierarchy of categories and sub categories for courses in the domain.',
6575: 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',
6576: dc_addcat => 'Ask a domain coordinator to assign a category to the course.',
6577: );
6578: $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>"');
6579: $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>"');
6580: $visactions{'addcat'} = &mt('Use [_1]Categorize course[_2] to assign a category to the course.','"<a href="/adm/courseprefs?phase=display&actions=courseinfo">','</a>"');
6581: return \%visactions;
1.256 raeburn 6582: }
6583:
1.241 raeburn 6584: sub new_selfenroll_dom_row {
6585: my ($newdom,$num) = @_;
6586: my $domdesc = &Apache::lonnet::domain($newdom);
6587: my $output;
6588: if ($domdesc ne '') {
6589: $output .= &Apache::loncommon::start_data_table_row()
6590: .'<td valign="top"><span class="LC_nobreak">'.&mt('Domain:').' <b>'.$domdesc
6591: .' ('.$newdom.')</b><input type="hidden" name="selfenroll_dom_'.$num
1.249 raeburn 6592: .'" value="'.$newdom.'" /></span><br />'
6593: .'<span class="LC_nobreak"><label><input type="checkbox" '
6594: .'name="selfenroll_activate" value="'.$num.'" '
6595: .'onchange="javascript:update_types('
6596: ."'selfenroll_activate','$num'".');" />'
6597: .&mt('Activate').'</label></span></td>';
1.241 raeburn 6598: my @currinsttypes;
6599: $output .= '<td>'.&mt('User types:').'<br />'
6600: .&selfenroll_inst_types($num,$newdom,\@currinsttypes).'</td>'
6601: .&Apache::loncommon::end_data_table_row();
6602: }
6603: return $output;
6604: }
6605:
6606: sub selfenroll_inst_types {
1.418 raeburn 6607: my ($num,$currdom,$currinsttypes,$readonly) = @_;
1.241 raeburn 6608: my $output;
6609: my $numinrow = 4;
6610: my $count = 0;
6611: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($currdom);
1.247 raeburn 6612: my $othervalue = 'any';
1.418 raeburn 6613: my $disabled;
6614: if ($readonly) {
6615: $disabled = ' disabled="disabled"';
6616: }
1.241 raeburn 6617: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
1.251 raeburn 6618: if (keys(%{$usertypes}) > 0) {
1.247 raeburn 6619: $othervalue = 'other';
6620: }
1.241 raeburn 6621: $output .= '<table><tr>';
6622: foreach my $type (@{$types}) {
6623: if (($count > 0) && ($count%$numinrow == 0)) {
6624: $output .= '</tr><tr>';
6625: }
6626: if (defined($usertypes->{$type})) {
1.257 raeburn 6627: my $esc_type = &escape($type);
1.241 raeburn 6628: $output .= '<td><span class="LC_nobreak"><label><input type = "checkbox" value="'.
1.257 raeburn 6629: $esc_type.'" ';
1.241 raeburn 6630: if (ref($currinsttypes) eq 'ARRAY') {
6631: if (@{$currinsttypes} > 0) {
1.249 raeburn 6632: if (grep(/^any$/,@{$currinsttypes})) {
6633: $output .= 'checked="checked"';
1.257 raeburn 6634: } elsif (grep(/^\Q$esc_type\E$/,@{$currinsttypes})) {
1.241 raeburn 6635: $output .= 'checked="checked"';
6636: }
1.249 raeburn 6637: } else {
6638: $output .= 'checked="checked"';
1.241 raeburn 6639: }
6640: }
1.418 raeburn 6641: $output .= ' name="selfenroll_types_'.$num.'"'.$disabled.' />'.$usertypes->{$type}.'</label></span></td>';
1.241 raeburn 6642: }
6643: $count ++;
6644: }
6645: if (($count > 0) && ($count%$numinrow == 0)) {
6646: $output .= '</tr><tr>';
6647: }
1.249 raeburn 6648: $output .= '<td><span class="LC_nobreak"><label><input type = "checkbox" value="'.$othervalue.'"';
1.241 raeburn 6649: if (ref($currinsttypes) eq 'ARRAY') {
6650: if (@{$currinsttypes} > 0) {
1.249 raeburn 6651: if (grep(/^any$/,@{$currinsttypes})) {
6652: $output .= ' checked="checked"';
6653: } elsif ($othervalue eq 'other') {
6654: if (grep(/^\Q$othervalue\E$/,@{$currinsttypes})) {
6655: $output .= ' checked="checked"';
6656: }
1.241 raeburn 6657: }
1.249 raeburn 6658: } else {
6659: $output .= ' checked="checked"';
1.241 raeburn 6660: }
1.249 raeburn 6661: } else {
6662: $output .= ' checked="checked"';
1.241 raeburn 6663: }
1.418 raeburn 6664: $output .= ' name="selfenroll_types_'.$num.'"'.$disabled.' />'.$othertitle.'</label></span></td></tr></table>';
1.241 raeburn 6665: }
6666: return $output;
6667: }
6668:
1.237 raeburn 6669: sub selfenroll_date_forms {
6670: my ($startform,$endform) = @_;
6671: my $output .= &Apache::lonhtmlcommon::start_pick_box()."\n".
1.244 bisitz 6672: &Apache::lonhtmlcommon::row_title(&mt('Start date'),
1.237 raeburn 6673: 'LC_oddrow_value')."\n".
6674: $startform."\n".
6675: &Apache::lonhtmlcommon::row_closure(1).
1.244 bisitz 6676: &Apache::lonhtmlcommon::row_title(&mt('End date'),
1.237 raeburn 6677: 'LC_oddrow_value')."\n".
6678: $endform."\n".
6679: &Apache::lonhtmlcommon::row_closure(1).
6680: &Apache::lonhtmlcommon::end_pick_box();
6681: return $output;
6682: }
6683:
1.239 raeburn 6684: sub print_userchangelogs_display {
1.415 raeburn 6685: my ($r,$context,$permission,$brcrum) = @_;
1.363 raeburn 6686: my $formname = 'rolelog';
1.418 raeburn 6687: my ($username,$domain,$crstype,$viewablesec,%roleslog);
1.363 raeburn 6688: if ($context eq 'domain') {
6689: $domain = $env{'request.role.domain'};
6690: %roleslog=&Apache::lonnet::dump_dom('nohist_rolelog',$domain);
6691: } else {
6692: if ($context eq 'course') {
6693: $domain = $env{'course.'.$env{'request.course.id'}.'.domain'};
6694: $username = $env{'course.'.$env{'request.course.id'}.'.num'};
6695: $crstype = &Apache::loncommon::course_type();
1.418 raeburn 6696: $viewablesec = &Apache::lonuserutils::viewable_section($permission);
1.363 raeburn 6697: my %saveable_parameters = ('show' => 'scalar',);
6698: &Apache::loncommon::store_course_settings('roles_log',
6699: \%saveable_parameters);
6700: &Apache::loncommon::restore_course_settings('roles_log',
6701: \%saveable_parameters);
6702: } elsif ($context eq 'author') {
6703: $domain = $env{'user.domain'};
6704: if ($env{'request.role'} =~ m{^au\./\Q$domain\E/$}) {
6705: $username = $env{'user.name'};
6706: } else {
6707: undef($domain);
6708: }
6709: }
6710: if ($domain ne '' && $username ne '') {
6711: %roleslog=&Apache::lonnet::dump('nohist_rolelog',$domain,$username);
6712: }
6713: }
1.239 raeburn 6714: if ((keys(%roleslog))[0]=~/^error\:/) { undef(%roleslog); }
6715:
1.415 raeburn 6716: my $helpitem;
6717: if ($context eq 'course') {
6718: $helpitem = 'Course_User_Logs';
1.439 raeburn 6719: } elsif ($context eq 'domain') {
6720: $helpitem = 'Domain_Role_Logs';
6721: } elsif ($context eq 'author') {
6722: $helpitem = 'Author_User_Logs';
1.415 raeburn 6723: }
6724: push (@{$brcrum},
6725: {href => '/adm/createuser?action=changelogs',
6726: text => 'User Management Logs',
6727: help => $helpitem});
6728: my $bread_crumbs_component = 'User Changes';
6729: my $args = { bread_crumbs => $brcrum,
6730: bread_crumbs_component => $bread_crumbs_component};
6731:
6732: # Create navigation javascript
6733: my $jsnav = &userlogdisplay_js($formname);
6734:
6735: my $jscript = (<<ENDSCRIPT);
6736: <script type="text/javascript">
6737: // <![CDATA[
6738: $jsnav
6739: // ]]>
6740: </script>
6741: ENDSCRIPT
6742:
6743: # print page header
6744: $r->print(&header($jscript,$args));
6745:
1.239 raeburn 6746: # set defaults
6747: my $now = time();
6748: my $defstart = $now - (7*24*3600); #7 days ago
6749: my %defaults = (
6750: page => '1',
6751: show => '10',
6752: role => 'any',
6753: chgcontext => 'any',
6754: rolelog_start_date => $defstart,
6755: rolelog_end_date => $now,
6756: );
6757: my $more_records = 0;
6758:
6759: # set current
6760: my %curr;
6761: foreach my $item ('show','page','role','chgcontext') {
6762: $curr{$item} = $env{'form.'.$item};
6763: }
6764: my ($startdate,$enddate) =
6765: &Apache::lonuserutils::get_dates_from_form('rolelog_start_date','rolelog_end_date');
6766: $curr{'rolelog_start_date'} = $startdate;
6767: $curr{'rolelog_end_date'} = $enddate;
6768: foreach my $key (keys(%defaults)) {
6769: if ($curr{$key} eq '') {
6770: $curr{$key} = $defaults{$key};
6771: }
6772: }
1.248 raeburn 6773: my (%whodunit,%changed,$version);
6774: ($version) = ($r->dir_config('lonVersion') =~ /^([\d\.]+)\-/);
1.239 raeburn 6775: my ($minshown,$maxshown);
1.255 raeburn 6776: $minshown = 1;
1.239 raeburn 6777: my $count = 0;
1.415 raeburn 6778: if ($curr{'show'} =~ /\D/) {
6779: $curr{'page'} = 1;
6780: } else {
1.239 raeburn 6781: $maxshown = $curr{'page'} * $curr{'show'};
6782: if ($curr{'page'} > 1) {
6783: $minshown = 1 + ($curr{'page'} - 1) * $curr{'show'};
6784: }
6785: }
1.301 bisitz 6786:
1.327 raeburn 6787: # Form Header
6788: $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">'.
1.363 raeburn 6789: &role_display_filter($context,$formname,$domain,$username,\%curr,
6790: $version,$crstype));
1.327 raeburn 6791:
6792: my $showntableheader = 0;
6793:
6794: # Table Header
6795: my $tableheader =
6796: &Apache::loncommon::start_data_table_header_row()
6797: .'<th> </th>'
6798: .'<th>'.&mt('When').'</th>'
6799: .'<th>'.&mt('Who made the change').'</th>'
6800: .'<th>'.&mt('Changed User').'</th>'
1.363 raeburn 6801: .'<th>'.&mt('Role').'</th>';
6802:
6803: if ($context eq 'course') {
6804: $tableheader .= '<th>'.&mt('Section').'</th>';
6805: }
6806: $tableheader .=
6807: '<th>'.&mt('Context').'</th>'
1.327 raeburn 6808: .'<th>'.&mt('Start').'</th>'
6809: .'<th>'.&mt('End').'</th>'
6810: .&Apache::loncommon::end_data_table_header_row();
6811:
6812: # Display user change log data
1.239 raeburn 6813: foreach my $id (sort { $roleslog{$b}{'exe_time'}<=>$roleslog{$a}{'exe_time'} } (keys(%roleslog))) {
6814: next if (($roleslog{$id}{'exe_time'} < $curr{'rolelog_start_date'}) ||
6815: ($roleslog{$id}{'exe_time'} > $curr{'rolelog_end_date'}));
1.415 raeburn 6816: if ($curr{'show'} !~ /\D/) {
1.239 raeburn 6817: if ($count >= $curr{'page'} * $curr{'show'}) {
6818: $more_records = 1;
6819: last;
6820: }
6821: }
6822: if ($curr{'role'} ne 'any') {
6823: next if ($roleslog{$id}{'logentry'}{'role'} ne $curr{'role'});
6824: }
6825: if ($curr{'chgcontext'} ne 'any') {
6826: if ($curr{'chgcontext'} eq 'selfenroll') {
6827: next if (!$roleslog{$id}{'logentry'}{'selfenroll'});
6828: } else {
6829: next if ($roleslog{$id}{'logentry'}{'context'} ne $curr{'chgcontext'});
6830: }
6831: }
1.418 raeburn 6832: if (($context eq 'course') && ($viewablesec ne '')) {
1.430 raeburn 6833: next if ($roleslog{$id}{'logentry'}{'section'} ne $viewablesec);
1.418 raeburn 6834: }
1.239 raeburn 6835: $count ++;
6836: next if ($count < $minshown);
1.327 raeburn 6837: unless ($showntableheader) {
1.415 raeburn 6838: $r->print(&Apache::loncommon::start_data_table()
1.327 raeburn 6839: .$tableheader);
6840: $r->rflush();
6841: $showntableheader = 1;
6842: }
1.239 raeburn 6843: if ($whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}} eq '') {
6844: $whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}} =
6845: &Apache::loncommon::plainname($roleslog{$id}{'exe_uname'},$roleslog{$id}{'exe_udom'});
6846: }
6847: if ($changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}} eq '') {
6848: $changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}} =
6849: &Apache::loncommon::plainname($roleslog{$id}{'uname'},$roleslog{$id}{'udom'});
6850: }
6851: my $sec = $roleslog{$id}{'logentry'}{'section'};
6852: if ($sec eq '') {
6853: $sec = &mt('None');
6854: }
6855: my ($rolestart,$roleend);
6856: if ($roleslog{$id}{'delflag'}) {
6857: $rolestart = &mt('deleted');
6858: $roleend = &mt('deleted');
6859: } else {
6860: $rolestart = $roleslog{$id}{'logentry'}{'start'};
6861: $roleend = $roleslog{$id}{'logentry'}{'end'};
6862: if ($rolestart eq '' || $rolestart == 0) {
6863: $rolestart = &mt('No start date');
6864: } else {
6865: $rolestart = &Apache::lonlocal::locallocaltime($rolestart);
6866: }
6867: if ($roleend eq '' || $roleend == 0) {
6868: $roleend = &mt('No end date');
6869: } else {
6870: $roleend = &Apache::lonlocal::locallocaltime($roleend);
6871: }
6872: }
6873: my $chgcontext = $roleslog{$id}{'logentry'}{'context'};
6874: if ($roleslog{$id}{'logentry'}{'selfenroll'}) {
6875: $chgcontext = 'selfenroll';
6876: }
1.363 raeburn 6877: my %lt = &rolechg_contexts($context,$crstype);
1.239 raeburn 6878: if ($chgcontext ne '' && $lt{$chgcontext} ne '') {
6879: $chgcontext = $lt{$chgcontext};
6880: }
1.327 raeburn 6881: $r->print(
1.301 bisitz 6882: &Apache::loncommon::start_data_table_row()
6883: .'<td>'.$count.'</td>'
6884: .'<td>'.&Apache::lonlocal::locallocaltime($roleslog{$id}{'exe_time'}).'</td>'
6885: .'<td>'.$whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}}.'</td>'
6886: .'<td>'.$changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}}.'</td>'
1.363 raeburn 6887: .'<td>'.&Apache::lonnet::plaintext($roleslog{$id}{'logentry'}{'role'},$crstype).'</td>');
6888: if ($context eq 'course') {
6889: $r->print('<td>'.$sec.'</td>');
6890: }
6891: $r->print(
6892: '<td>'.$chgcontext.'</td>'
1.301 bisitz 6893: .'<td>'.$rolestart.'</td>'
6894: .'<td>'.$roleend.'</td>'
1.327 raeburn 6895: .&Apache::loncommon::end_data_table_row()."\n");
1.301 bisitz 6896: }
6897:
1.327 raeburn 6898: if ($showntableheader) { # Table footer, if content displayed above
1.415 raeburn 6899: $r->print(&Apache::loncommon::end_data_table().
6900: &userlogdisplay_navlinks(\%curr,$more_records));
1.327 raeburn 6901: } else { # No content displayed above
1.301 bisitz 6902: $r->print('<p class="LC_info">'
6903: .&mt('There are no records to display.')
6904: .'</p>'
6905: );
1.239 raeburn 6906: }
1.301 bisitz 6907:
1.327 raeburn 6908: # Form Footer
6909: $r->print(
6910: '<input type="hidden" name="page" value="'.$curr{'page'}.'" />'
6911: .'<input type="hidden" name="action" value="changelogs" />'
6912: .'</form>');
6913: return;
6914: }
1.301 bisitz 6915:
1.416 raeburn 6916: sub print_useraccesslogs_display {
6917: my ($r,$uname,$udom,$permission,$brcrum) = @_;
6918: my $formname = 'accesslog';
6919: my $form = 'document.accesslog';
6920:
6921: # set breadcrumbs
1.422 raeburn 6922: my %breadcrumb_text = &singleuser_breadcrumb('','domain',$udom);
1.431 raeburn 6923: my $prevphasestr;
6924: if ($env{'form.popup'}) {
6925: $brcrum = [];
6926: } else {
6927: push (@{$brcrum},
6928: {href => "javascript:backPage($form)",
6929: text => $breadcrumb_text{'search'}});
6930: my @prevphases;
6931: if ($env{'form.prevphases'}) {
6932: @prevphases = split(/,/,$env{'form.prevphases'});
6933: $prevphasestr = $env{'form.prevphases'};
6934: }
6935: if (($env{'form.phase'} eq 'userpicked') || (grep(/^userpicked$/,@prevphases))) {
6936: push(@{$brcrum},
6937: {href => "javascript:backPage($form,'get_user_info','select')",
6938: text => $breadcrumb_text{'userpicked'}});
6939: if ($env{'form.phase'} eq 'userpicked') {
6940: $prevphasestr = 'userpicked';
6941: }
1.416 raeburn 6942: }
6943: }
6944: push(@{$brcrum},
6945: {href => '/adm/createuser?action=accesslogs',
6946: text => 'User access logs',
1.424 raeburn 6947: help => 'Domain_User_Access_Logs'});
1.416 raeburn 6948: my $bread_crumbs_component = 'User Access Logs';
6949: my $args = { bread_crumbs => $brcrum,
6950: bread_crumbs_component => 'User Management'};
1.423 raeburn 6951: if ($env{'form.popup'}) {
6952: $args->{'no_nav_bar'} = 1;
1.431 raeburn 6953: $args->{'bread_crumbs_nomenu'} = 1;
1.423 raeburn 6954: }
1.416 raeburn 6955:
1.417 raeburn 6956: # set javascript
1.416 raeburn 6957: my ($jsback,$elements) = &crumb_utilities();
6958: my $jsnav = &userlogdisplay_js($formname);
6959:
6960: my $jscript = (<<ENDSCRIPT);
6961: <script type="text/javascript">
6962: // <![CDATA[
6963:
6964: $jsback
6965: $jsnav
6966:
6967: // ]]>
6968: </script>
6969:
6970: ENDSCRIPT
6971:
1.417 raeburn 6972: # print page header
1.416 raeburn 6973: $r->print(&header($jscript,$args));
6974:
6975: # early out unless log data can be displayed.
6976: unless ($permission->{'activity'}) {
6977: $r->print('<p class="LC_warning">'
6978: .&mt('You do not have rights to display user access logs.')
1.431 raeburn 6979: .'</p>');
6980: if ($env{'form.popup'}) {
6981: $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a></p>');
6982: } else {
6983: $r->print(&earlyout_accesslog_form($formname,$prevphasestr,$udom));
6984: }
1.416 raeburn 6985: return;
6986: }
6987:
6988: unless ($udom eq $env{'request.role.domain'}) {
6989: $r->print('<p class="LC_warning">'
6990: .&mt("User's domain must match role's domain")
6991: .'</p>'
6992: .&earlyout_accesslog_form($formname,$prevphasestr,$udom));
1.417 raeburn 6993: return;
1.416 raeburn 6994: }
6995:
6996: if (($uname eq '') || ($udom eq '')) {
6997: $r->print('<p class="LC_warning">'
6998: .&mt('Invalid username or domain')
6999: .'</p>'
7000: .&earlyout_accesslog_form($formname,$prevphasestr,$udom));
7001: return;
7002: }
7003:
1.437 raeburn 7004: if (&Apache::lonnet::privileged($uname,$udom,
7005: [$env{'request.role.domain'}],['dc','su'])) {
7006: unless (&Apache::lonnet::privileged($env{'user.name'},$env{'user.domain'},
7007: [$env{'request.role.domain'}],['dc','su'])) {
7008: $r->print('<p class="LC_warning">'
7009: .&mt('You need to be a privileged user to display user access logs for [_1]',
7010: &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),
7011: $uname,$udom))
7012: .'</p>');
7013: if ($env{'form.popup'}) {
7014: $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a></p>');
7015: } else {
7016: $r->print(&earlyout_accesslog_form($formname,$prevphasestr,$udom));
7017: }
7018: return;
7019: }
7020: }
7021:
1.416 raeburn 7022: # set defaults
7023: my $now = time();
7024: my $defstart = $now - (7*24*3600);
7025: my %defaults = (
7026: page => '1',
7027: show => '10',
7028: activity => 'any',
7029: accesslog_start_date => $defstart,
7030: accesslog_end_date => $now,
7031: );
7032: my $more_records = 0;
7033:
7034: # set current
7035: my %curr;
7036: foreach my $item ('show','page','activity') {
7037: $curr{$item} = $env{'form.'.$item};
7038: }
7039: my ($startdate,$enddate) =
7040: &Apache::lonuserutils::get_dates_from_form('accesslog_start_date','accesslog_end_date');
7041: $curr{'accesslog_start_date'} = $startdate;
7042: $curr{'accesslog_end_date'} = $enddate;
7043: foreach my $key (keys(%defaults)) {
7044: if ($curr{$key} eq '') {
7045: $curr{$key} = $defaults{$key};
7046: }
7047: }
7048: my ($minshown,$maxshown);
7049: $minshown = 1;
7050: my $count = 0;
7051: if ($curr{'show'} =~ /\D/) {
7052: $curr{'page'} = 1;
7053: } else {
7054: $maxshown = $curr{'page'} * $curr{'show'};
7055: if ($curr{'page'} > 1) {
7056: $minshown = 1 + ($curr{'page'} - 1) * $curr{'show'};
7057: }
7058: }
7059:
7060: # form header
7061: $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">'.
7062: &activity_display_filter($formname,\%curr));
7063:
7064: my $showntableheader = 0;
7065: my ($nav_script,$nav_links);
7066:
7067: # table header
1.431 raeburn 7068: my $tableheader = '<h3>'.
7069: &mt('User access logs for: [_1]',
7070: &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),$uname,$udom)).'</h3>'
7071: .&Apache::loncommon::start_data_table_header_row()
1.416 raeburn 7072: .'<th> </th>'
7073: .'<th>'.&mt('When').'</th>'
7074: .'<th>'.&mt('HostID').'</th>'
7075: .'<th>'.&mt('Event').'</th>'
7076: .'<th>'.&mt('Other data').'</th>'
7077: .&Apache::loncommon::end_data_table_header_row();
7078:
7079: my %filters=(
7080: start => $curr{'accesslog_start_date'},
7081: end => $curr{'accesslog_end_date'},
7082: action => $curr{'activity'},
7083: );
7084:
7085: my $reply = &Apache::lonnet::userlog_query($uname,$udom,%filters);
7086: unless ( ($reply =~/^timeout/) || ($reply =~/^error/) ) {
7087: my (%courses,%missing);
7088: my @results = split(/\&/,$reply);
7089: foreach my $item (reverse(@results)) {
7090: my ($timestamp,$host,$event) = split(/:/,$item);
7091: next unless ($event =~ /^(Log|Role)/);
7092: if ($curr{'show'} !~ /\D/) {
7093: if ($count >= $curr{'page'} * $curr{'show'}) {
7094: $more_records = 1;
7095: last;
7096: }
7097: }
7098: $count ++;
7099: next if ($count < $minshown);
7100: unless ($showntableheader) {
7101: $r->print($nav_script
7102: .&Apache::loncommon::start_data_table()
7103: .$tableheader);
7104: $r->rflush();
7105: $showntableheader = 1;
7106: }
1.418 raeburn 7107: my ($shown,$extra);
1.437 raeburn 7108: my ($event,$data) = split(/\s+/,&unescape($event),2);
1.416 raeburn 7109: if ($event eq 'Role') {
7110: my ($rolecode,$extent) = split(/\./,$data,2);
7111: next if ($extent eq '');
7112: my ($crstype,$desc,$info);
1.418 raeburn 7113: if ($extent =~ m{^/($match_domain)/($match_courseid)(?:/(\w+)|)$}) {
7114: my ($cdom,$cnum,$sec) = ($1,$2,$3);
1.416 raeburn 7115: my $cid = $cdom.'_'.$cnum;
7116: if (exists($courses{$cid})) {
7117: $crstype = $courses{$cid}{'type'};
7118: $desc = $courses{$cid}{'description'};
7119: } elsif ($missing{$cid}) {
7120: $crstype = 'Course';
7121: $desc = 'Course/Community';
7122: } else {
7123: my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',$cnum,undef,undef,'.');
7124: if (ref($crsinfo{$cdom.'_'.$cnum}) eq 'HASH') {
7125: $courses{$cid} = $crsinfo{$cid};
7126: $crstype = $crsinfo{$cid}{'type'};
7127: $desc = $crsinfo{$cid}{'description'};
7128: } else {
7129: $missing{$cid} = 1;
7130: }
7131: }
7132: $extra = &mt($crstype).': <a href="/public/'.$cdom.'/'.$cnum.'/syllabus">'.$desc.'</a>';
1.418 raeburn 7133: if ($sec ne '') {
7134: $extra .= ' ('.&mt('Section: [_1]',$sec).')';
7135: }
1.416 raeburn 7136: } elsif ($extent =~ m{^/($match_domain)/($match_username|$)}) {
7137: my ($dom,$name) = ($1,$2);
7138: if ($rolecode eq 'au') {
7139: $extra = '';
7140: } elsif ($rolecode =~ /^(ca|aa)$/) {
1.417 raeburn 7141: $extra = &mt('Authoring Space: [_1]',$name.':'.$dom);
1.416 raeburn 7142: } elsif ($rolecode =~ /^(li|dg|dh|dc|sc)$/) {
7143: $extra = &mt('Domain: [_1]',$dom);
7144: }
7145: }
7146: my $rolename;
7147: if ($rolecode =~ m{^cr/($match_domain)/($match_username)/(\w+)}) {
7148: my $role = $3;
1.417 raeburn 7149: my $owner = "($2:$1)";
1.416 raeburn 7150: if ($2 eq $1.'-domainconfig') {
7151: $owner = '(ad hoc)';
1.417 raeburn 7152: }
1.416 raeburn 7153: $rolename = &mt('Custom role: [_1]',$role.' '.$owner);
7154: } else {
7155: $rolename = &Apache::lonnet::plaintext($rolecode,$crstype);
7156: }
7157: $shown = &mt('Role selection: [_1]',$rolename);
7158: } else {
7159: $shown = &mt($event);
1.437 raeburn 7160: if ($data =~ /^webdav/) {
7161: my ($path,$clientip) = split(/\s+/,$data,2);
7162: $path =~ s/^webdav//;
7163: if ($clientip ne '') {
7164: $extra = &mt('Client IP address: [_1]',$clientip);
7165: }
7166: if ($path ne '') {
7167: $shown .= ' '.&mt('(WebDAV access to [_1])',$path);
7168: }
7169: } elsif ($data ne '') {
7170: $extra = &mt('Client IP address: [_1]',$data);
1.416 raeburn 7171: }
7172: }
7173: $r->print(
7174: &Apache::loncommon::start_data_table_row()
7175: .'<td>'.$count.'</td>'
7176: .'<td>'.&Apache::lonlocal::locallocaltime($timestamp).'</td>'
7177: .'<td>'.$host.'</td>'
7178: .'<td>'.$shown.'</td>'
7179: .'<td>'.$extra.'</td>'
7180: .&Apache::loncommon::end_data_table_row()."\n");
7181: }
7182: }
7183:
7184: if ($showntableheader) { # Table footer, if content displayed above
7185: $r->print(&Apache::loncommon::end_data_table().
7186: &userlogdisplay_navlinks(\%curr,$more_records));
7187: } else { # No content displayed above
7188: $r->print('<p class="LC_info">'
7189: .&mt('There are no records to display.')
7190: .'</p>');
7191: }
7192:
1.423 raeburn 7193: if ($env{'form.popup'} == 1) {
7194: $r->print('<input type="hidden" name="popup" value="1" />'."\n");
7195: }
7196:
1.416 raeburn 7197: # Form Footer
7198: $r->print(
7199: '<input type="hidden" name="currstate" value="" />'
7200: .'<input type="hidden" name="accessuname" value="'.$uname.'" />'
7201: .'<input type="hidden" name="accessudom" value="'.$udom.'" />'
7202: .'<input type="hidden" name="page" value="'.$curr{'page'}.'" />'
7203: .'<input type="hidden" name="prevphases" value="'.$prevphasestr.'" />'
7204: .'<input type="hidden" name="phase" value="activity" />'
7205: .'<input type="hidden" name="action" value="accesslogs" />'
7206: .'<input type="hidden" name="srchdomain" value="'.$udom.'" />'
7207: .'<input type="hidden" name="srchby" value="'.$env{'form.srchby'}.'" />'
7208: .'<input type="hidden" name="srchtype" value="'.$env{'form.srchtype'}.'" />'
7209: .'<input type="hidden" name="srchterm" value="'.&HTML::Entities::encode($env{'form.srchterm'},'<>"&').'" />'
7210: .'<input type="hidden" name="srchin" value="'.$env{'form.srchin'}.'" />'
7211: .'</form>');
7212: return;
7213: }
7214:
7215: sub earlyout_accesslog_form {
7216: my ($formname,$prevphasestr,$udom) = @_;
7217: my $srchterm = &HTML::Entities::encode($env{'form.srchterm'},'<>"&');
7218: return <<"END";
7219: <form action="/adm/createuser" method="post" name="$formname">
7220: <input type="hidden" name="currstate" value="" />
7221: <input type="hidden" name="prevphases" value="$prevphasestr" />
7222: <input type="hidden" name="phase" value="activity" />
7223: <input type="hidden" name="action" value="accesslogs" />
7224: <input type="hidden" name="srchdomain" value="$udom" />
7225: <input type="hidden" name="srchby" value="$env{'form.srchby'}" />
7226: <input type="hidden" name="srchtype" value="$env{'form.srchtype'}" />
7227: <input type="hidden" name="srchterm" value="$srchterm" />
7228: <input type="hidden" name="srchin" value="$env{'form.srchin'}" />
7229: </form>
7230: END
7231: }
7232:
7233: sub activity_display_filter {
7234: my ($formname,$curr) = @_;
7235: my $nolink = 1;
7236: my $output = '<table><tr><td valign="top">'.
7237: '<span class="LC_nobreak"><b>'.&mt('Actions/page:').'</b></span><br />'.
7238: &Apache::lonmeta::selectbox('show',$curr->{'show'},undef,
7239: (&mt('all'),5,10,20,50,100,1000,10000)).
7240: '</td><td> </td>';
7241: my $startform =
7242: &Apache::lonhtmlcommon::date_setter($formname,'accesslog_start_date',
7243: $curr->{'accesslog_start_date'},undef,
7244: undef,undef,undef,undef,undef,undef,$nolink);
7245: my $endform =
7246: &Apache::lonhtmlcommon::date_setter($formname,'accesslog_end_date',
7247: $curr->{'accesslog_end_date'},undef,
7248: undef,undef,undef,undef,undef,undef,$nolink);
7249: my %lt = &Apache::lonlocal::texthash (
7250: activity => 'Activity',
7251: Role => 'Role selection',
7252: log => 'Log-in or Logout',
7253: );
7254: $output .= '<td valign="top"><b>'.&mt('Window during which actions occurred:').'</b><br />'.
7255: '<table><tr><td>'.&mt('After:').
7256: '</td><td>'.$startform.'</td></tr>'.
7257: '<tr><td>'.&mt('Before:').'</td>'.
7258: '<td>'.$endform.'</td></tr></table>'.
7259: '</td>'.
7260: '<td> </td>'.
7261: '<td valign="top"><b>'.&mt('Activities').'</b><br />'.
7262: '<select name="activity"><option value="any"';
7263: if ($curr->{'activity'} eq 'any') {
7264: $output .= ' selected="selected"';
7265: }
7266: $output .= '>'.&mt('Any').'</option>'."\n";
7267: foreach my $activity ('Role','log') {
7268: my $selstr = '';
7269: if ($activity eq $curr->{'activity'}) {
7270: $selstr = ' selected="selected"';
7271: }
7272: $output .= '<option value="'.$activity.'"'.$selstr.'>'.$lt{$activity}.'</option>';
7273: }
7274: $output .= '</select></td>'.
7275: '</tr></table>';
7276: # Update Display button
7277: $output .= '<p>'
7278: .'<input type="submit" value="'.&mt('Update Display').'" />'
1.431 raeburn 7279: .'</p><hr />';
1.416 raeburn 7280: return $output;
7281: }
7282:
1.415 raeburn 7283: sub userlogdisplay_js {
7284: my ($formname) = @_;
7285: return <<"ENDSCRIPT";
7286:
1.239 raeburn 7287: function chgPage(caller) {
7288: if (caller == 'previous') {
7289: document.$formname.page.value --;
7290: }
7291: if (caller == 'next') {
7292: document.$formname.page.value ++;
7293: }
1.327 raeburn 7294: document.$formname.submit();
1.239 raeburn 7295: return;
7296: }
7297: ENDSCRIPT
1.415 raeburn 7298: }
7299:
7300: sub userlogdisplay_navlinks {
7301: my ($curr,$more_records) = @_;
7302: return unless(ref($curr) eq 'HASH');
7303: # Navigation Buttons
7304: my $nav_links = '<p>';
7305: if (($curr->{'page'} > 1) || ($more_records)) {
7306: if (($curr->{'page'} > 1) && ($curr->{'show'} !~ /\D/)) {
7307: $nav_links .= '<input type="button"'
7308: .' onclick="javascript:chgPage('."'previous'".');"'
7309: .' value="'.&mt('Previous [_1] changes',$curr->{'show'})
7310: .'" /> ';
7311: }
7312: if ($more_records) {
7313: $nav_links .= '<input type="button"'
7314: .' onclick="javascript:chgPage('."'next'".');"'
7315: .' value="'.&mt('Next [_1] changes',$curr->{'show'})
7316: .'" />';
1.301 bisitz 7317: }
7318: }
1.415 raeburn 7319: $nav_links .= '</p>';
7320: return $nav_links;
1.239 raeburn 7321: }
7322:
7323: sub role_display_filter {
1.363 raeburn 7324: my ($context,$formname,$cdom,$cnum,$curr,$version,$crstype) = @_;
7325: my $lctype;
7326: if ($context eq 'course') {
7327: $lctype = lc($crstype);
7328: }
1.239 raeburn 7329: my $nolink = 1;
7330: my $output = '<table><tr><td valign="top">'.
1.301 bisitz 7331: '<span class="LC_nobreak"><b>'.&mt('Changes/page:').'</b></span><br />'.
1.239 raeburn 7332: &Apache::lonmeta::selectbox('show',$curr->{'show'},undef,
7333: (&mt('all'),5,10,20,50,100,1000,10000)).
7334: '</td><td> </td>';
7335: my $startform =
7336: &Apache::lonhtmlcommon::date_setter($formname,'rolelog_start_date',
7337: $curr->{'rolelog_start_date'},undef,
7338: undef,undef,undef,undef,undef,undef,$nolink);
7339: my $endform =
7340: &Apache::lonhtmlcommon::date_setter($formname,'rolelog_end_date',
7341: $curr->{'rolelog_end_date'},undef,
7342: undef,undef,undef,undef,undef,undef,$nolink);
1.363 raeburn 7343: my %lt = &rolechg_contexts($context,$crstype);
1.301 bisitz 7344: $output .= '<td valign="top"><b>'.&mt('Window during which changes occurred:').'</b><br />'.
7345: '<table><tr><td>'.&mt('After:').
7346: '</td><td>'.$startform.'</td></tr>'.
7347: '<tr><td>'.&mt('Before:').'</td>'.
7348: '<td>'.$endform.'</td></tr></table>'.
7349: '</td>'.
7350: '<td> </td>'.
1.239 raeburn 7351: '<td valign="top"><b>'.&mt('Role:').'</b><br />'.
7352: '<select name="role"><option value="any"';
7353: if ($curr->{'role'} eq 'any') {
7354: $output .= ' selected="selected"';
7355: }
7356: $output .= '>'.&mt('Any').'</option>'."\n";
1.363 raeburn 7357: my @roles = &Apache::lonuserutils::roles_by_context($context,1,$crstype);
1.239 raeburn 7358: foreach my $role (@roles) {
7359: my $plrole;
7360: if ($role eq 'cr') {
7361: $plrole = &mt('Custom Role');
7362: } else {
1.318 raeburn 7363: $plrole=&Apache::lonnet::plaintext($role,$crstype);
1.239 raeburn 7364: }
7365: my $selstr = '';
7366: if ($role eq $curr->{'role'}) {
7367: $selstr = ' selected="selected"';
7368: }
7369: $output .= ' <option value="'.$role.'"'.$selstr.'>'.$plrole.'</option>';
7370: }
1.301 bisitz 7371: $output .= '</select></td>'.
7372: '<td> </td>'.
7373: '<td valign="top"><b>'.
1.239 raeburn 7374: &mt('Context:').'</b><br /><select name="chgcontext">';
1.363 raeburn 7375: my @posscontexts;
7376: if ($context eq 'course') {
1.376 raeburn 7377: @posscontexts = ('any','automated','updatenow','createcourse','course','domain','selfenroll','requestcourses');
1.363 raeburn 7378: } elsif ($context eq 'domain') {
7379: @posscontexts = ('any','domain','requestauthor','domconfig','server');
7380: } else {
7381: @posscontexts = ('any','author','domain');
7382: }
7383: foreach my $chgtype (@posscontexts) {
1.239 raeburn 7384: my $selstr = '';
7385: if ($curr->{'chgcontext'} eq $chgtype) {
1.301 bisitz 7386: $selstr = ' selected="selected"';
1.239 raeburn 7387: }
1.363 raeburn 7388: if ($context eq 'course') {
1.376 raeburn 7389: if (($chgtype eq 'automated') || ($chgtype eq 'updatenow')) {
1.363 raeburn 7390: next if (!&Apache::lonnet::auto_run($cnum,$cdom));
7391: }
1.239 raeburn 7392: }
7393: $output .= '<option value="'.$chgtype.'"'.$selstr.'>'.$lt{$chgtype}.'</option>'."\n";
1.248 raeburn 7394: }
1.303 bisitz 7395: $output .= '</select></td>'
7396: .'</tr></table>';
7397:
7398: # Update Display button
7399: $output .= '<p>'
7400: .'<input type="submit" value="'.&mt('Update Display').'" />'
7401: .'</p>';
7402:
7403: # Server version info
1.363 raeburn 7404: my $needsrev = '2.11.0';
7405: if ($context eq 'course') {
7406: $needsrev = '2.7.0';
7407: }
7408:
1.303 bisitz 7409: $output .= '<p class="LC_info">'
7410: .&mt('Only changes made from servers running LON-CAPA [_1] or later are displayed.'
1.363 raeburn 7411: ,$needsrev);
1.248 raeburn 7412: if ($version) {
1.303 bisitz 7413: $output .= ' '.&mt('This LON-CAPA server is version [_1]',$version);
7414: }
7415: $output .= '</p><hr />';
1.239 raeburn 7416: return $output;
7417: }
7418:
7419: sub rolechg_contexts {
1.363 raeburn 7420: my ($context,$crstype) = @_;
7421: my %lt;
7422: if ($context eq 'course') {
7423: %lt = &Apache::lonlocal::texthash (
1.239 raeburn 7424: any => 'Any',
1.376 raeburn 7425: automated => 'Automated Enrollment',
1.239 raeburn 7426: updatenow => 'Roster Update',
7427: createcourse => 'Course Creation',
7428: course => 'User Management in course',
7429: domain => 'User Management in domain',
1.313 raeburn 7430: selfenroll => 'Self-enrolled',
1.318 raeburn 7431: requestcourses => 'Course Request',
1.239 raeburn 7432: );
1.363 raeburn 7433: if ($crstype eq 'Community') {
7434: $lt{'createcourse'} = &mt('Community Creation');
7435: $lt{'course'} = &mt('User Management in community');
7436: $lt{'requestcourses'} = &mt('Community Request');
7437: }
7438: } elsif ($context eq 'domain') {
7439: %lt = &Apache::lonlocal::texthash (
7440: any => 'Any',
7441: domain => 'User Management in domain',
7442: requestauthor => 'Authoring Request',
7443: server => 'Command line script (DC role)',
7444: domconfig => 'Self-enrolled',
7445: );
7446: } else {
7447: %lt = &Apache::lonlocal::texthash (
7448: any => 'Any',
7449: domain => 'User Management in domain',
7450: author => 'User Management by author',
7451: );
7452: }
1.239 raeburn 7453: return %lt;
7454: }
7455:
1.428 raeburn 7456: sub print_helpdeskaccess_display {
7457: my ($r,$permission,$brcrum) = @_;
7458: my $formname = 'helpdeskaccess';
7459: my $helpitem = 'Course_Helpdesk_Access';
7460: push (@{$brcrum},
7461: {href => '/adm/createuser?action=helpdesk',
7462: text => 'Helpdesk Access',
7463: help => $helpitem});
7464: my $bread_crumbs_component = 'Helpdesk Staff Access';
7465: my $args = { bread_crumbs => $brcrum,
7466: bread_crumbs_component => $bread_crumbs_component};
7467:
7468: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
7469: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
7470: my $confname = $cdom.'-domainconfig';
7471: my $crstype = &Apache::loncommon::course_type();
7472:
1.434 raeburn 7473: my @accesstypes = ('all','dh','da','none');
1.428 raeburn 7474: my ($numstatustypes,@jsarray);
7475: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($cdom);
7476: if (ref($types) eq 'ARRAY') {
1.430 raeburn 7477: if (@{$types} > 0) {
1.428 raeburn 7478: $numstatustypes = scalar(@{$types});
7479: push(@accesstypes,'status');
7480: @jsarray = ('bystatus');
7481: }
7482: }
7483: my %customroles = &get_domain_customroles($cdom,$confname);
1.432 raeburn 7484: my %domhelpdesk = &Apache::lonnet::get_active_domroles($cdom,['dh','da']);
1.428 raeburn 7485: if (keys(%domhelpdesk)) {
7486: push(@accesstypes,('inc','exc'));
7487: push(@jsarray,('notinc','notexc'));
7488: }
7489: push(@jsarray,'privs');
7490: my $hiddenstr = join("','",@jsarray);
7491: my $rolestr = join("','",sort(keys(%customroles)));
7492:
7493: my $jscript;
7494: my (%settings,%overridden);
7495: if (keys(%customroles)) {
7496: &get_adhocrole_settings($env{'request.course.id'},\@accesstypes,
7497: $types,\%customroles,\%settings,\%overridden);
7498: my %jsfull=();
7499: my %jslevels= (
7500: course => {},
7501: domain => {},
7502: system => {},
7503: );
7504: my %jslevelscurrent=(
7505: course => {},
7506: domain => {},
7507: system => {},
7508: );
7509: my (%privs,%jsprivs);
7510: &Apache::lonuserutils::custom_role_privs(\%privs,\%jsfull,\%jslevels,\%jslevelscurrent);
7511: foreach my $priv (keys(%jsfull)) {
7512: if ($jslevels{'course'}{$priv}) {
7513: $jsprivs{$priv} = 1;
7514: }
7515: }
7516: my (%elements,%stored);
7517: foreach my $role (keys(%customroles)) {
7518: $elements{$role.'_access'} = 'radio';
7519: $elements{$role.'_incrs'} = 'radio';
7520: if ($numstatustypes) {
7521: $elements{$role.'_status'} = 'checkbox';
7522: }
7523: if (keys(%domhelpdesk) > 0) {
7524: $elements{$role.'_staff_inc'} = 'checkbox';
7525: $elements{$role.'_staff_exc'} = 'checkbox';
7526: }
1.430 raeburn 7527: $elements{$role.'_override'} = 'checkbox';
1.428 raeburn 7528: if (ref($settings{$role}) eq 'HASH') {
7529: if ($settings{$role}{'access'} ne '') {
7530: my $curraccess = $settings{$role}{'access'};
7531: $stored{$role.'_access'} = $curraccess;
7532: $stored{$role.'_incrs'} = 1;
7533: if ($curraccess eq 'status') {
7534: if (ref($settings{$role}{'status'}) eq 'ARRAY') {
7535: $stored{$role.'_status'} = $settings{$role}{'status'};
7536: }
7537: } elsif (($curraccess eq 'exc') || ($curraccess eq 'inc')) {
7538: if (ref($settings{$role}{$curraccess}) eq 'ARRAY') {
7539: $stored{$role.'_staff_'.$curraccess} = $settings{$role}{$curraccess};
7540: }
7541: }
7542: } else {
7543: $stored{$role.'_incrs'} = 0;
7544: }
7545: $stored{$role.'_override'} = [];
7546: if ($env{'course.'.$env{'request.course.id'}.'.internal.adhocpriv.'.$role}) {
7547: if (ref($settings{$role}{'off'}) eq 'ARRAY') {
7548: foreach my $priv (@{$settings{$role}{'off'}}) {
7549: push(@{$stored{$role.'_override'}},$priv);
7550: }
7551: }
7552: if (ref($settings{$role}{'on'}) eq 'ARRAY') {
7553: foreach my $priv (@{$settings{$role}{'on'}}) {
7554: unless (grep(/^$priv$/,@{$stored{$role.'_override'}})) {
7555: push(@{$stored{$role.'_override'}},$priv);
7556: }
7557: }
7558: }
7559: }
7560: } else {
7561: $stored{$role.'_incrs'} = 0;
7562: }
7563: }
7564: $jscript = &Apache::lonhtmlcommon::set_form_elements(\%elements,\%stored);
7565: }
7566:
7567: my $js = <<"ENDJS";
7568: <script type="text/javascript">
7569: // <![CDATA[
7570: $jscript;
7571:
7572: function switchRoleTab(caller,role) {
7573: if (document.getElementById(role+'_maindiv')) {
7574: if (caller.id != 'LC_current_minitab') {
7575: if (document.getElementById('LC_current_minitab')) {
7576: document.getElementById('LC_current_minitab').id=null;
7577: }
7578: var roledivs = Array('$rolestr');
7579: if (roledivs.length > 0) {
7580: for (var i=0; i<roledivs.length; i++) {
7581: if (document.getElementById(roledivs[i]+'_maindiv')) {
7582: document.getElementById(roledivs[i]+'_maindiv').style.display='none';
7583: }
7584: }
7585: }
7586: caller.id = 'LC_current_minitab';
7587: document.getElementById(role+'_maindiv').style.display='block';
7588: }
7589: }
7590: return false;
1.430 raeburn 7591: }
1.428 raeburn 7592:
7593: function helpdeskAccess(role) {
7594: var curraccess = null;
7595: if (document.$formname.elements[role+'_access'].length) {
7596: for (var i=0; i<document.$formname.elements[role+'_access'].length; i++) {
7597: if (document.$formname.elements[role+'_access'][i].checked) {
7598: curraccess = document.$formname.elements[role+'_access'][i].value;
7599: }
7600: }
7601: }
7602: var shown = Array();
7603: var hidden = Array();
7604: if (curraccess == 'none') {
1.430 raeburn 7605: hidden = Array ('$hiddenstr');
1.428 raeburn 7606: } else {
7607: if (curraccess == 'status') {
1.430 raeburn 7608: shown = Array ('bystatus','privs');
7609: hidden = Array ('notinc','notexc');
1.428 raeburn 7610: } else {
7611: if (curraccess == 'exc') {
7612: shown = Array ('notexc','privs');
7613: hidden = Array ('notinc','bystatus');
7614: }
7615: if (curraccess == 'inc') {
7616: shown = Array ('notinc','privs');
7617: hidden = Array ('notexc','bystatus');
7618: }
7619: if (curraccess == 'all') {
7620: shown = Array ('privs');
7621: hidden = Array ('notinc','notexc','bystatus');
7622: }
7623: }
7624: }
7625: if (hidden.length > 0) {
7626: for (var i=0; i<hidden.length; i++) {
7627: if (document.getElementById(role+'_'+hidden[i])) {
1.430 raeburn 7628: document.getElementById(role+'_'+hidden[i]).style.display = 'none';
1.428 raeburn 7629: }
7630: }
7631: }
7632: if (shown.length > 0) {
7633: for (var i=0; i<shown.length; i++) {
7634: if (document.getElementById(role+'_'+shown[i])) {
7635: if (shown[i] == 'privs') {
7636: document.getElementById(role+'_'+shown[i]).style.display = 'block';
7637: } else {
7638: document.getElementById(role+'_'+shown[i]).style.display = 'inline';
7639: }
7640: }
7641: }
7642: }
7643: return;
7644: }
7645:
7646: function toggleAccess(role) {
7647: if ((document.getElementById(role+'_setincrs')) &&
7648: (document.getElementById(role+'_setindom'))) {
7649: for (var i=0; i<document.$formname.elements[role+'_incrs'].length; i++) {
7650: if (document.$formname.elements[role+'_incrs'][i].checked) {
7651: if (document.$formname.elements[role+'_incrs'][i].value == 1) {
7652: document.getElementById(role+'_setindom').style.display = 'none';
1.430 raeburn 7653: document.getElementById(role+'_setincrs').style.display = 'block';
1.428 raeburn 7654: } else {
7655: document.getElementById(role+'_setincrs').style.display = 'none';
7656: document.getElementById(role+'_setindom').style.display = 'block';
7657: }
7658: break;
7659: }
7660: }
7661: }
7662: return;
7663: }
7664:
7665: // ]]>
7666: </script>
7667: ENDJS
7668:
7669: $args->{add_entries} = {onload => "javascript:setFormElements(document.$formname)"};
7670:
7671: # print page header
7672: $r->print(&header($js,$args));
7673: # print form header
7674: $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">');
7675:
7676: if (keys(%customroles)) {
7677: my %lt = &Apache::lonlocal::texthash(
7678: 'aco' => 'As course owner you may override the defaults set in the domain for role usage and/or privileges.',
7679: 'rou' => 'Role usage',
7680: 'whi' => 'Which helpdesk personnel may use this role?',
7681: 'udd' => 'Use domain default',
1.433 raeburn 7682: 'all' => 'All with domain helpdesk or helpdesk assistant role',
1.434 raeburn 7683: 'dh' => 'All with domain helpdesk role',
7684: 'da' => 'All with domain helpdesk assistant role',
1.428 raeburn 7685: 'none' => 'None',
7686: 'status' => 'Determined based on institutional status',
1.430 raeburn 7687: 'inc' => 'Include all, but exclude specific personnel',
1.428 raeburn 7688: 'exc' => 'Exclude all, but include specific personnel',
7689: 'hel' => 'Helpdesk',
7690: 'rpr' => 'Role privileges',
7691: );
7692: $lt{'tfh'} = &mt("Custom [_1]ad hoc[_2] course roles available for use by the domain's helpdesk are as follows",'<i>','</i>');
7693: my %domconfig = &Apache::lonnet::get_dom('configuration',['helpsettings'],$cdom);
7694: my (%domcurrent,%ordered,%description,%domusage,$disabled);
7695: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
7696: if (ref($domconfig{'helpsettings'}{'adhoc'}) eq 'HASH') {
7697: %domcurrent = %{$domconfig{'helpsettings'}{'adhoc'}};
7698: }
7699: }
7700: my $count = 0;
7701: foreach my $role (sort(keys(%customroles))) {
7702: my ($order,$desc,$access_in_dom);
7703: if (ref($domcurrent{$role}) eq 'HASH') {
7704: $order = $domcurrent{$role}{'order'};
7705: $desc = $domcurrent{$role}{'desc'};
7706: $access_in_dom = $domcurrent{$role}{'access'};
7707: }
7708: if ($order eq '') {
7709: $order = $count;
7710: }
7711: $ordered{$order} = $role;
7712: if ($desc ne '') {
7713: $description{$role} = $desc;
7714: } else {
7715: $description{$role}= $role;
7716: }
7717: $count++;
7718: }
7719: %domusage = &domain_adhoc_access(\%customroles,\%domcurrent,\@accesstypes,$usertypes,$othertitle);
7720: my @roles_by_num = ();
7721: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
7722: push(@roles_by_num,$ordered{$item});
1.430 raeburn 7723: }
1.429 raeburn 7724: $r->print('<p>'.$lt{'tfh'}.': <i>'.join('</i>, <i>',map { $description{$_}; } @roles_by_num).'</i>.');
1.428 raeburn 7725: if ($permission->{'owner'}) {
7726: $r->print('<br />'.$lt{'aco'}.'</p><p>');
7727: $r->print('<input type="hidden" name="state" value="process" />'.
7728: '<input type="submit" value="'.&mt('Save changes').'" />');
7729: } else {
7730: if ($env{'course.'.$env{'request.course.id'}.'.internal.courseowner'}) {
7731: my ($ownername,$ownerdom) = split(/:/,$env{'course.'.$env{'request.course.id'}.'.internal.courseowner'});
7732: $r->print('<br />'.&mt('The course owner -- [_1] -- can override the default access and/or privileges for these ad hoc roles.',
7733: &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($ownername,$ownerdom),$ownername,$ownerdom)));
7734: }
7735: $disabled = ' disabled="disabled"';
7736: }
7737: $r->print('</p>');
7738:
7739: $r->print('<div id="LC_minitab_header"><ul>');
7740: my $count = 0;
7741: my %visibility;
7742: foreach my $role (@roles_by_num) {
7743: my $id;
7744: if ($count == 0) {
7745: $id=' id="LC_current_minitab"';
1.430 raeburn 7746: $visibility{$role} = ' style="display:block"';
1.428 raeburn 7747: } else {
7748: $visibility{$role} = ' style="display:none"';
7749: }
7750: $count ++;
7751: $r->print('<li'.$id.'><a href="#" onclick="javascript:switchRoleTab(this.parentNode,'."'$role'".');">'.$description{$role}.'</a></li>');
7752: }
7753: $r->print('</ul></div>');
7754:
7755: foreach my $role (@roles_by_num) {
7756: my %usecheck = (
7757: all => ' checked="checked"',
7758: );
7759: my %displaydiv = (
7760: status => 'none',
7761: inc => 'none',
7762: exc => 'none',
7763: priv => 'block',
7764: );
7765: my (%selected,$overridden,$incrscheck,$indomcheck,$indomvis,$incrsvis);
1.430 raeburn 7766: if (ref($settings{$role}) eq 'HASH') {
1.428 raeburn 7767: if ($settings{$role}{'access'} ne '') {
7768: $indomvis = ' style="display:none"';
7769: $incrsvis = ' style="display:block"';
1.430 raeburn 7770: $incrscheck = ' checked="checked"';
1.428 raeburn 7771: if ($settings{$role}{'access'} ne 'all') {
7772: $usecheck{$settings{$role}{'access'}} = $usecheck{'all'};
7773: delete($usecheck{'all'});
7774: if ($settings{$role}{'access'} eq 'status') {
7775: my $access = 'status';
7776: $displaydiv{$access} = 'inline';
7777: if (ref($settings{$role}{$access}) eq 'ARRAY') {
7778: $selected{$access} = $settings{$role}{$access};
7779: }
7780: } elsif ($settings{$role}{'access'} =~ /^(inc|exc)$/) {
7781: my $access = $1;
7782: $displaydiv{$access} = 'inline';
7783: if (ref($settings{$role}{$access}) eq 'ARRAY') {
7784: $selected{$access} = $settings{$role}{$access};
7785: }
7786: } elsif ($settings{$role}{'access'} eq 'none') {
7787: $displaydiv{'priv'} = 'none';
7788: }
7789: }
7790: } else {
7791: $indomcheck = ' checked="checked"';
7792: $indomvis = ' style="display:block"';
7793: $incrsvis = ' style="display:none"';
7794: }
7795: } else {
7796: $indomcheck = ' checked="checked"';
1.430 raeburn 7797: $indomvis = ' style="display:block"';
1.428 raeburn 7798: $incrsvis = ' style="display:none"';
7799: }
7800: $r->print('<div class="LC_left_float" id="'.$role.'_maindiv"'.$visibility{$role}.'>'.
7801: '<fieldset><legend>'.$lt{'rou'}.'</legend>'.
7802: '<p>'.$lt{'whi'}.' <span class="LC_nobreak">'.
7803: '<label><input type="radio" name="'.$role.'_incrs" value="1"'.$incrscheck.' onclick="toggleAccess('."'$role'".');"'.$disabled.'>'.
7804: &mt('Set here in [_1]',lc($crstype)).'</label>'.
7805: '<span>'.(' 'x2).
7806: '<label><input type="radio" name="'.$role.'_incrs" value="0"'.$indomcheck.' onclick="toggleAccess('."'$role'".');"'.$disabled.'>'.
7807: $lt{'udd'}.'</label><span></p>'.
7808: '<div id="'.$role.'_setindom"'.$indomvis.'>'.
7809: '<span class="LC_cusr_emph">'.$domusage{$role}.'</span></div>'.
7810: '<div id="'.$role.'_setincrs"'.$incrsvis.'>');
7811: foreach my $access (@accesstypes) {
7812: $r->print('<p><label><input type="radio" name="'.$role.'_access" value="'.$access.'" '.$usecheck{$access}.
7813: ' onclick="helpdeskAccess('."'$role'".');"'.$disabled.' />'.$lt{$access}.'</label>');
7814: if ($access eq 'status') {
7815: $r->print('<div id="'.$role.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
7816: &Apache::lonuserutils::adhoc_status_types($cdom,undef,$role,$selected{$access},
7817: $othertitle,$usertypes,$types,$disabled).
7818: '</div>');
7819: } elsif (($access eq 'inc') && (keys(%domhelpdesk) > 0)) {
7820: $r->print('<div id="'.$role.'_notinc" style="display:'.$displaydiv{$access}.'">'.
7821: &Apache::lonuserutils::adhoc_staff($access,undef,$role,$selected{$access},
7822: \%domhelpdesk,$disabled).
7823: '</div>');
7824: } elsif (($access eq 'exc') && (keys(%domhelpdesk) > 0)) {
7825: $r->print('<div id="'.$role.'_notexc" style="display:'.$displaydiv{$access}.'">'.
7826: &Apache::lonuserutils::adhoc_staff($access,undef,$role,$selected{$access},
7827: \%domhelpdesk,$disabled).
7828: '</div>');
7829: }
7830: $r->print('</p>');
7831: }
7832: $r->print('</div></fieldset>');
7833: my %full=();
7834: my %levels= (
7835: course => {},
7836: domain => {},
7837: system => {},
7838: );
7839: my %levelscurrent=(
7840: course => {},
7841: domain => {},
7842: system => {},
7843: );
7844: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
7845: $r->print('<fieldset id="'.$role.'_privs" style="display:'.$displaydiv{'priv'}.'">'.
7846: '<legend>'.$lt{'rpr'}.'</legend>'.
7847: &role_priv_table($role,$permission,$crstype,\%full,\%levels,\%levelscurrent,$overridden{$role}).
7848: '</fieldset></div><div style="padding:0;clear:both;margin:0;border:0"></div>');
7849: }
1.429 raeburn 7850: if ($permission->{'owner'}) {
7851: $r->print('<p><input type="submit" value="'.&mt('Save changes').'" /></p>');
7852: }
1.428 raeburn 7853: } else {
7854: $r->print(&mt('Helpdesk roles have not yet been created in this domain.'));
7855: }
7856: # Form Footer
7857: $r->print('<input type="hidden" name="action" value="helpdesk" />'
7858: .'</form>');
7859: return;
7860: }
7861:
7862: sub domain_adhoc_access {
7863: my ($roles,$domcurrent,$accesstypes,$usertypes,$othertitle) = @_;
7864: my %domusage;
7865: return unless ((ref($roles) eq 'HASH') && (ref($domcurrent) eq 'HASH') && (ref($accesstypes) eq 'ARRAY'));
7866: foreach my $role (keys(%{$roles})) {
7867: if (ref($domcurrent->{$role}) eq 'HASH') {
7868: my $access = $domcurrent->{$role}{'access'};
7869: if (($access eq '') || (!grep(/^\Q$access\E$/,@{$accesstypes}))) {
7870: $access = 'all';
1.432 raeburn 7871: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role',&Apache::lonnet::plaintext('dh'),
7872: &Apache::lonnet::plaintext('da'));
1.428 raeburn 7873: } elsif ($access eq 'status') {
7874: if (ref($domcurrent->{$role}{$access}) eq 'ARRAY') {
7875: my @shown;
7876: foreach my $type (@{$domcurrent->{$role}{$access}}) {
7877: unless ($type eq 'default') {
7878: if ($usertypes->{$type}) {
7879: push(@shown,$usertypes->{$type});
7880: }
7881: }
7882: }
7883: if (grep(/^default$/,@{$domcurrent->{$role}{$access}})) {
7884: push(@shown,$othertitle);
7885: }
7886: if (@shown) {
7887: my $shownstatus = join(' '.&mt('or').' ',@shown);
1.432 raeburn 7888: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role, and institutional status: [_3]',
7889: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'),$shownstatus);
1.428 raeburn 7890: } else {
7891: $domusage{$role} = &mt('No one in the domain');
7892: }
7893: }
7894: } elsif ($access eq 'inc') {
7895: my @dominc = ();
7896: if (ref($domcurrent->{$role}{'inc'}) eq 'ARRAY') {
7897: foreach my $user (@{$domcurrent->{$role}{'inc'}}) {
7898: my ($uname,$udom) = split(/:/,$user);
7899: push(@dominc,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),$uname,$udom));
7900: }
7901: my $showninc = join(', ',@dominc);
7902: if ($showninc ne '') {
1.432 raeburn 7903: $domusage{$role} = &mt('Include any user in domain with active [_1] or [_2] role, except: [_3]',
7904: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'),$showninc);
1.428 raeburn 7905: } else {
1.432 raeburn 7906: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role',
7907: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'));
1.428 raeburn 7908: }
7909: }
7910: } elsif ($access eq 'exc') {
7911: my @domexc = ();
7912: if (ref($domcurrent->{$role}{'exc'}) eq 'ARRAY') {
7913: foreach my $user (@{$domcurrent->{$role}{'exc'}}) {
7914: my ($uname,$udom) = split(/:/,$user);
7915: push(@domexc,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),$uname,$udom));
7916: }
7917: }
7918: my $shownexc = join(', ',@domexc);
7919: if ($shownexc ne '') {
1.432 raeburn 7920: $domusage{$role} = &mt('Only the following in the domain with active [_1] or [_2] role: [_3]',
7921: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'),$shownexc);
1.428 raeburn 7922: } else {
7923: $domusage{$role} = &mt('No one in the domain');
7924: }
7925: } elsif ($access eq 'none') {
7926: $domusage{$role} = &mt('No one in the domain');
1.434 raeburn 7927: } elsif ($access eq 'dh') {
1.433 raeburn 7928: $domusage{$role} = &mt('Any user in domain with active [_1] role',&Apache::lonnet::plaintext('dh'));
1.434 raeburn 7929: } elsif ($access eq 'da') {
1.433 raeburn 7930: $domusage{$role} = &mt('Any user in domain with active [_1] role',&Apache::lonnet::plaintext('da'));
1.428 raeburn 7931: } elsif ($access eq 'all') {
1.432 raeburn 7932: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role',
7933: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'));
1.428 raeburn 7934: }
7935: } else {
1.432 raeburn 7936: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role',
7937: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'));
1.428 raeburn 7938: }
7939: }
7940: return %domusage;
7941: }
7942:
7943: sub get_domain_customroles {
7944: my ($cdom,$confname) = @_;
7945: my %existing=&Apache::lonnet::dump('roles',$cdom,$confname,'rolesdef_');
7946: my %customroles;
7947: foreach my $key (keys(%existing)) {
7948: if ($key=~/^rolesdef\_(\w+)$/) {
7949: my $rolename = $1;
7950: my %privs;
7951: ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
7952: $customroles{$rolename} = \%privs;
7953: }
7954: }
7955: return %customroles;
7956: }
7957:
7958: sub role_priv_table {
7959: my ($role,$permission,$crstype,$full,$levels,$levelscurrent,$overridden) = @_;
7960: return unless ((ref($full) eq 'HASH') && (ref($levels) eq 'HASH') &&
7961: (ref($levelscurrent) eq 'HASH'));
7962: my %lt=&Apache::lonlocal::texthash (
7963: 'crl' => 'Course Level Privilege',
7964: 'def' => 'Domain Defaults',
7965: 'ove' => 'Override in Course',
7966: 'ine' => 'In effect',
7967: 'dis' => 'Disabled',
7968: 'ena' => 'Enabled',
7969: );
7970: if ($crstype eq 'Community') {
7971: $lt{'ove'} = 'Override in Community',
7972: }
7973: my @status = ('Disabled','Enabled');
7974: my (%on,%off);
7975: if (ref($overridden) eq 'HASH') {
7976: if (ref($overridden->{'on'}) eq 'ARRAY') {
7977: map { $on{$_} = 1; } (@{$overridden->{'on'}});
7978: }
7979: if (ref($overridden->{'off'}) eq 'ARRAY') {
7980: map { $off{$_} = 1; } (@{$overridden->{'off'}});
7981: }
7982: }
7983: my $output=&Apache::loncommon::start_data_table().
7984: &Apache::loncommon::start_data_table_header_row().
7985: '<th>'.$lt{'crl'}.'</th><th>'.$lt{'def'}.'</th><th>'.$lt{'ove'}.
7986: '</th><th>'.$lt{'ine'}.'</th>'.
7987: &Apache::loncommon::end_data_table_header_row();
7988: foreach my $priv (sort(keys(%{$full}))) {
7989: next unless ($levels->{'course'}{$priv});
7990: my $privtext = &Apache::lonnet::plaintext($priv,$crstype);
7991: my ($default,$ineffect);
7992: if ($levelscurrent->{'course'}{$priv}) {
7993: $default = '<img src="/adm/lonIcons/navmap.correct.gif" alt="'.$lt{'ena'}.'" />';
7994: $ineffect = $default;
7995: }
7996: my ($customstatus,$checked);
7997: $output .= &Apache::loncommon::start_data_table_row().
7998: '<td>'.$privtext.'</td>'.
7999: '<td>'.$default.'</td><td>';
8000: if (($levelscurrent->{'course'}{$priv}) && ($off{$priv})) {
8001: if ($permission->{'owner'}) {
8002: $checked = ' checked="checked"';
8003: }
8004: $customstatus = '<img src="/adm/lonIcons/navmap.wrong.gif" alt="'.$lt{'dis'}.'" />';
1.430 raeburn 8005: $ineffect = $customstatus;
1.428 raeburn 8006: } elsif ((!$levelscurrent->{'course'}{$priv}) && ($on{$priv})) {
8007: if ($permission->{'owner'}) {
1.430 raeburn 8008: $checked = ' checked="checked"';
1.428 raeburn 8009: }
8010: $customstatus = '<img src="/adm/lonIcons/navmap.correct.gif" alt="'.$lt{'ena'}.'" />';
1.430 raeburn 8011: $ineffect = $customstatus;
1.428 raeburn 8012: }
8013: if ($permission->{'owner'}) {
8014: $output .= '<input type="checkbox" name="'.$role.'_override" value="'.$priv.'"'.$checked.' />';
8015: } else {
8016: $output .= $customstatus;
8017: }
8018: $output .= '</td><td>'.$ineffect.'</td>'.
8019: &Apache::loncommon::end_data_table_row();
8020: }
8021: $output .= &Apache::loncommon::end_data_table();
8022: return $output;
8023: }
8024:
8025: sub get_adhocrole_settings {
1.430 raeburn 8026: my ($cid,$accesstypes,$types,$customroles,$settings,$overridden) = @_;
1.428 raeburn 8027: return unless ((ref($accesstypes) eq 'ARRAY') && (ref($customroles) eq 'HASH') &&
8028: (ref($settings) eq 'HASH') && (ref($overridden) eq 'HASH'));
8029: foreach my $role (split(/,/,$env{'course.'.$cid.'.internal.adhocaccess'})) {
8030: my ($curraccess,$rest) = split(/=/,$env{'course.'.$cid.'.internal.adhoc.'.$role});
8031: if (($curraccess ne '') && (grep(/^\Q$curraccess\E$/,@{$accesstypes}))) {
8032: $settings->{$role}{'access'} = $curraccess;
8033: if (($curraccess eq 'status') && (ref($types) eq 'ARRAY')) {
8034: my @status = split(/,/,$rest);
8035: my @currstatus;
8036: foreach my $type (@status) {
8037: if ($type eq 'default') {
8038: push(@currstatus,$type);
8039: } elsif (grep(/^\Q$type\E$/,@{$types})) {
8040: push(@currstatus,$type);
8041: }
8042: }
8043: if (@currstatus) {
8044: $settings->{$role}{$curraccess} = \@currstatus;
8045: } elsif (($curraccess eq 'exc') || ($curraccess eq 'inc')) {
8046: my @personnel = split(/,/,$rest);
8047: $settings->{$role}{$curraccess} = \@personnel;
8048: }
8049: }
8050: }
8051: }
8052: foreach my $role (keys(%{$customroles})) {
8053: if ($env{'course.'.$cid.'.internal.adhocpriv.'.$role}) {
8054: my %currentprivs;
8055: if (ref($customroles->{$role}) eq 'HASH') {
8056: if (exists($customroles->{$role}{'course'})) {
8057: my %full=();
8058: my %levels= (
8059: course => {},
8060: domain => {},
8061: system => {},
8062: );
8063: my %levelscurrent=(
8064: course => {},
8065: domain => {},
8066: system => {},
8067: );
8068: &Apache::lonuserutils::custom_role_privs($customroles->{$role},\%full,\%levels,\%levelscurrent);
8069: %currentprivs = %{$levelscurrent{'course'}};
8070: }
8071: }
8072: foreach my $item (split(/,/,$env{'course.'.$cid.'.internal.adhocpriv.'.$role})) {
8073: next if ($item eq '');
8074: my ($rule,$rest) = split(/=/,$item);
8075: next unless (($rule eq 'off') || ($rule eq 'on'));
8076: foreach my $priv (split(/:/,$rest)) {
8077: if ($priv ne '') {
8078: if ($rule eq 'off') {
8079: push(@{$overridden->{$role}{'off'}},$priv);
8080: if ($currentprivs{$priv}) {
8081: push(@{$settings->{$role}{'off'}},$priv);
8082: }
8083: } else {
8084: push(@{$overridden->{$role}{'on'}},$priv);
8085: unless ($currentprivs{$priv}) {
8086: push(@{$settings->{$role}{'on'}},$priv);
8087: }
8088: }
8089: }
8090: }
8091: }
8092: }
8093: }
8094: return;
8095: }
8096:
8097: sub update_helpdeskaccess {
8098: my ($r,$permission,$brcrum) = @_;
8099: my $helpitem = 'Course_Helpdesk_Access';
8100: push (@{$brcrum},
8101: {href => '/adm/createuser?action=helpdesk',
8102: text => 'Helpdesk Access',
8103: help => $helpitem},
8104: {href => '/adm/createuser?action=helpdesk',
8105: text => 'Result',
8106: help => $helpitem}
8107: );
8108: my $bread_crumbs_component = 'Helpdesk Staff Access';
8109: my $args = { bread_crumbs => $brcrum,
8110: bread_crumbs_component => $bread_crumbs_component};
8111:
8112: # print page header
8113: $r->print(&header('',$args));
8114: unless ((ref($permission) eq 'HASH') && ($permission->{'owner'})) {
8115: $r->print('<p class="LC_error">'.&mt('You do not have permission to change helpdesk access.').'</p>');
8116: return;
8117: }
1.434 raeburn 8118: my @accesstypes = ('all','dh','da','none','status','inc','exc');
1.428 raeburn 8119: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
8120: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
8121: my $confname = $cdom.'-domainconfig';
8122: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($cdom);
8123: my $crstype = &Apache::loncommon::course_type();
8124: my %customroles = &get_domain_customroles($cdom,$confname);
8125: my (%settings,%overridden);
8126: &get_adhocrole_settings($env{'request.course.id'},\@accesstypes,
8127: $types,\%customroles,\%settings,\%overridden);
1.432 raeburn 8128: my %domhelpdesk = &Apache::lonnet::get_active_domroles($cdom,['dh','da']);
1.428 raeburn 8129: my (%changed,%storehash,@todelete);
8130:
8131: if (keys(%customroles)) {
8132: my (%newsettings,@incrs);
8133: foreach my $role (keys(%customroles)) {
8134: $newsettings{$role} = {
8135: access => '',
8136: status => '',
8137: exc => '',
8138: inc => '',
8139: on => '',
8140: off => '',
8141: };
8142: my %current;
8143: if (ref($settings{$role}) eq 'HASH') {
8144: %current = %{$settings{$role}};
8145: }
8146: if (ref($overridden{$role}) eq 'HASH') {
8147: $current{'overridden'} = $overridden{$role};
8148: }
8149: if ($env{'form.'.$role.'_incrs'}) {
8150: my $access = $env{'form.'.$role.'_access'};
8151: if (grep(/^\Q$access\E$/,@accesstypes)) {
8152: push(@incrs,$role);
8153: unless ($current{'access'} eq $access) {
8154: $changed{$role}{'access'} = 1;
1.430 raeburn 8155: $storehash{'internal.adhoc.'.$role} = $access;
1.428 raeburn 8156: }
8157: if ($access eq 'status') {
8158: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$role.'_status');
8159: my @stored;
8160: my @shownstatus;
8161: if (ref($types) eq 'ARRAY') {
8162: foreach my $type (sort(@statuses)) {
8163: if ($type eq 'default') {
8164: push(@stored,$type);
8165: } elsif (grep(/^\Q$type\E$/,@{$types})) {
8166: push(@stored,$type);
8167: push(@shownstatus,$usertypes->{$type});
8168: }
8169: }
8170: if (grep(/^default$/,@statuses)) {
8171: push(@shownstatus,$othertitle);
8172: }
8173: $storehash{'internal.adhoc.'.$role} .= '='.join(',',@stored);
8174: }
8175: $newsettings{$role}{'status'} = join(' '.&mt('or').' ',@shownstatus);
8176: if (ref($current{'status'}) eq 'ARRAY') {
8177: my @diffs = &Apache::loncommon::compare_arrays(\@stored,$current{'status'});
8178: if (@diffs) {
8179: $changed{$role}{'status'} = 1;
8180: }
8181: } elsif (@stored) {
8182: $changed{$role}{'status'} = 1;
8183: }
8184: } elsif (($access eq 'inc') || ($access eq 'exc')) {
8185: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$role.'_staff_'.$access);
8186: my @newspecstaff;
8187: my @stored;
8188: my @currstaff;
8189: foreach my $person (sort(@personnel)) {
8190: if ($domhelpdesk{$person}) {
1.430 raeburn 8191: push(@stored,$person);
1.428 raeburn 8192: }
8193: }
8194: if (ref($current{$access}) eq 'ARRAY') {
8195: my @diffs = &Apache::loncommon::compare_arrays(\@stored,$current{$access});
8196: if (@diffs) {
8197: $changed{$role}{$access} = 1;
8198: }
8199: } elsif (@stored) {
8200: $changed{$role}{$access} = 1;
8201: }
8202: $storehash{'internal.adhoc.'.$role} .= '='.join(',',@stored);
8203: foreach my $person (@stored) {
8204: my ($uname,$udom) = split(/:/,$person);
8205: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
8206: }
8207: $newsettings{$role}{$access} = join(', ',sort(@newspecstaff));
8208: }
8209: $newsettings{$role}{'access'} = $access;
8210: }
8211: } else {
8212: if (($current{'access'} ne '') && (grep(/^\Q$current{'access'}\E$/,@accesstypes))) {
8213: $changed{$role}{'access'} = 1;
8214: $newsettings{$role} = {};
8215: push(@todelete,'internal.adhoc.'.$role);
8216: }
8217: }
8218: if (($env{'form.'.$role.'_incrs'}) && ($env{'form.'.$role.'_access'} eq 'none')) {
8219: if (ref($current{'overridden'}) eq 'HASH') {
8220: push(@todelete,'internal.adhocpriv.'.$role);
8221: }
8222: } else {
8223: my %full=();
8224: my %levels= (
8225: course => {},
8226: domain => {},
8227: system => {},
8228: );
8229: my %levelscurrent=(
8230: course => {},
8231: domain => {},
8232: system => {},
8233: );
8234: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
8235: my (@updatedon,@updatedoff,@override);
8236: @override = &Apache::loncommon::get_env_multiple('form.'.$role.'_override');
1.430 raeburn 8237: if (@override) {
1.428 raeburn 8238: foreach my $priv (sort(keys(%full))) {
8239: next unless ($levels{'course'}{$priv});
8240: if (grep(/^\Q$priv\E$/,@override)) {
8241: if ($levelscurrent{'course'}{$priv}) {
8242: push(@updatedoff,$priv);
8243: } else {
8244: push(@updatedon,$priv);
8245: }
8246: }
8247: }
8248: }
8249: if (@updatedon) {
1.430 raeburn 8250: $newsettings{$role}{'on'} = join('</li><li>', map { &Apache::lonnet::plaintext($_,$crstype) } (@updatedon));
1.428 raeburn 8251: }
8252: if (@updatedoff) {
8253: $newsettings{$role}{'off'} = join('</li><li>', map { &Apache::lonnet::plaintext($_,$crstype) } (@updatedoff));
8254: }
8255: if (ref($current{'overridden'}) eq 'HASH') {
8256: if (ref($current{'overridden'}{'on'}) eq 'ARRAY') {
8257: if (@updatedon) {
8258: my @diffs = &Apache::loncommon::compare_arrays(\@updatedon,$current{'overridden'}{'on'});
8259: if (@diffs) {
8260: $changed{$role}{'on'} = 1;
8261: }
8262: } else {
8263: $changed{$role}{'on'} = 1;
8264: }
8265: } elsif (@updatedon) {
8266: $changed{$role}{'on'} = 1;
8267: }
8268: if (ref($current{'overridden'}{'off'}) eq 'ARRAY') {
8269: if (@updatedoff) {
8270: my @diffs = &Apache::loncommon::compare_arrays(\@updatedoff,$current{'overridden'}{'off'});
8271: if (@diffs) {
8272: $changed{$role}{'off'} = 1;
8273: }
8274: } else {
8275: $changed{$role}{'off'} = 1;
8276: }
8277: } elsif (@updatedoff) {
8278: $changed{$role}{'off'} = 1;
8279: }
8280: } else {
8281: if (@updatedon) {
8282: $changed{$role}{'on'} = 1;
8283: }
8284: if (@updatedoff) {
8285: $changed{$role}{'off'} = 1;
8286: }
8287: }
8288: if (ref($changed{$role}) eq 'HASH') {
8289: if (($changed{$role}{'on'} || $changed{$role}{'off'})) {
8290: my $newpriv;
8291: if (@updatedon) {
8292: $newpriv = 'on='.join(':',@updatedon);
8293: }
8294: if (@updatedoff) {
8295: $newpriv .= ($newpriv ? ',' : '' ).'off='.join(':',@updatedoff);
8296: }
8297: if ($newpriv eq '') {
8298: push(@todelete,'internal.adhocpriv.'.$role);
8299: } else {
8300: $storehash{'internal.adhocpriv.'.$role} = $newpriv;
8301: }
8302: }
8303: }
8304: }
8305: }
8306: if (@incrs) {
8307: $storehash{'internal.adhocaccess'} = join(',',@incrs);
8308: } elsif (@todelete) {
8309: push(@todelete,'internal.adhocaccess');
8310: }
8311: if (keys(%changed)) {
8312: my ($putres,$delres);
8313: if (keys(%storehash)) {
8314: $putres = &Apache::lonnet::put('environment',\%storehash,$cdom,$cnum);
8315: my %newenvhash;
8316: foreach my $key (keys(%storehash)) {
8317: $newenvhash{'course.'.$env{'request.course.id'}.'.'.$key} = $storehash{$key};
8318: }
8319: &Apache::lonnet::appenv(\%newenvhash);
8320: }
8321: if (@todelete) {
8322: $delres = &Apache::lonnet::del('environment',\@todelete,$cdom,$cnum);
8323: foreach my $key (@todelete) {
8324: &Apache::lonnet::delenv('course.'.$env{'request.course.id'}.'.'.$key);
8325: }
8326: }
8327: if (($putres eq 'ok') || ($delres eq 'ok')) {
8328: my %domconfig = &Apache::lonnet::get_dom('configuration',['helpsettings'],$cdom);
8329: my (%domcurrent,%ordered,%description,%domusage);
8330: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
8331: if (ref($domconfig{'helpsettings'}{'adhoc'}) eq 'HASH') {
8332: %domcurrent = %{$domconfig{'helpsettings'}{'adhoc'}};
8333: }
8334: }
8335: my $count = 0;
8336: foreach my $role (sort(keys(%customroles))) {
8337: my ($order,$desc);
8338: if (ref($domcurrent{$role}) eq 'HASH') {
8339: $order = $domcurrent{$role}{'order'};
8340: $desc = $domcurrent{$role}{'desc'};
8341: }
8342: if ($order eq '') {
8343: $order = $count;
8344: }
8345: $ordered{$order} = $role;
8346: if ($desc ne '') {
8347: $description{$role} = $desc;
8348: } else {
8349: $description{$role}= $role;
8350: }
8351: $count++;
8352: }
8353: my @roles_by_num = ();
8354: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
8355: push(@roles_by_num,$ordered{$item});
8356: }
8357: %domusage = &domain_adhoc_access(\%changed,\%domcurrent,\@accesstypes,$usertypes,$othertitle);
1.430 raeburn 8358: $r->print(&mt('Helpdesk access settings have been changed as follows').'<br />');
1.428 raeburn 8359: $r->print('<ul>');
8360: foreach my $role (@roles_by_num) {
8361: next unless (ref($changed{$role}) eq 'HASH');
8362: $r->print('<li>'.&mt('Ad hoc role').': <b>'.$description{$role}.'</b>'.
8363: '<ul>');
1.430 raeburn 8364: if ($changed{$role}{'access'} || $changed{$role}{'status'} || $changed{$role}{'inc'} || $changed{$role}{'exc'}) {
1.428 raeburn 8365: $r->print('<li>');
8366: if ($env{'form.'.$role.'_incrs'}) {
8367: if ($newsettings{$role}{'access'} eq 'all') {
8368: $r->print(&mt('All helpdesk staff can access '.lc($crstype).' with this role.'));
1.434 raeburn 8369: } elsif ($newsettings{$role}{'access'} eq 'dh') {
1.433 raeburn 8370: $r->print(&mt('Helpdesk staff can use this role if they have an active [_1] role',
8371: &Apache::lonnet::plaintext('dh')));
1.434 raeburn 8372: } elsif ($newsettings{$role}{'access'} eq 'da') {
1.433 raeburn 8373: $r->print(&mt('Helpdesk staff can use this role if they have an active [_1] role',
8374: &Apache::lonnet::plaintext('da')));
1.428 raeburn 8375: } elsif ($newsettings{$role}{'access'} eq 'none') {
8376: $r->print(&mt('No helpdesk staff can access '.lc($crstype).' with this role.'));
8377: } elsif ($newsettings{$role}{'access'} eq 'status') {
8378: if ($newsettings{$role}{'status'}) {
8379: my ($access,$rest) = split(/=/,$storehash{'internal.adhoc.'.$role});
1.430 raeburn 8380: if (split(/,/,$rest) > 1) {
1.428 raeburn 8381: $r->print(&mt('Helpdesk staff can use this role if their institutional type is one of: [_1].',
8382: $newsettings{$role}{'status'}));
8383: } else {
8384: $r->print(&mt('Helpdesk staff can use this role if their institutional type is: [_1].',
8385: $newsettings{$role}{'status'}));
8386: }
8387: } else {
8388: $r->print(&mt('No helpdesk staff can access '.lc($crstype).' with this role.'));
8389: }
8390: } elsif ($newsettings{$role}{'access'} eq 'exc') {
8391: if ($newsettings{$role}{'exc'}) {
8392: $r->print(&mt('Helpdesk staff who can use this role are as follows:').' '.$newsettings{$role}{'exc'}.'.');
8393: } else {
8394: $r->print(&mt('No helpdesk staff can access '.lc($crstype).' with this role.'));
8395: }
8396: } elsif ($newsettings{$role}{'access'} eq 'inc') {
8397: if ($newsettings{$role}{'inc'}) {
8398: $r->print(&mt('All helpdesk staff may use this role except the following:').' '.$newsettings{$role}{'inc'}.'.');
8399: } else {
8400: $r->print(&mt('All helpdesk staff may use this role.'));
8401: }
8402: }
8403: } else {
8404: $r->print(&mt('Default access set in the domain now applies.').'<br />'.
8405: '<span class="LC_cusr_emph">'.$domusage{$role}.'</span>');
8406: }
8407: $r->print('</li>');
8408: }
8409: unless ($newsettings{$role}{'access'} eq 'none') {
8410: if ($changed{$role}{'off'}) {
8411: if ($newsettings{$role}{'off'}) {
8412: $r->print('<li>'.&mt('Privileges which are available by default for this ad hoc role, but are disabled for this specific '.lc($crstype).':').
8413: '<ul><li>'.$newsettings{$role}{'off'}.'</li></ul></li>');
8414: } else {
1.430 raeburn 8415: $r->print('<li>'.&mt('All privileges available by default for this ad hoc role are enabled.').'</li>');
1.428 raeburn 8416: }
8417: }
1.430 raeburn 8418: if ($changed{$role}{'on'}) {
1.428 raeburn 8419: if ($newsettings{$role}{'on'}) {
8420: $r->print('<li>'.&mt('Privileges which are not available by default for this ad hoc role, but are enabled for this specific '.lc($crstype).':').
8421: '<ul><li>'.$newsettings{$role}{'on'}.'</li></ul></li>');
8422: } else {
1.430 raeburn 8423: $r->print('<li>'.&mt('None of the privileges unavailable by default for this ad hoc role are enabled.').'</li>');
1.428 raeburn 8424: }
8425: }
8426: }
8427: $r->print('</ul></li>');
8428: }
8429: $r->print('</ul>');
8430: }
8431: } else {
1.430 raeburn 8432: $r->print(&mt('No changes made to helpdesk access settings.'));
1.428 raeburn 8433: }
8434: }
8435: return;
8436: }
8437:
1.27 matthew 8438: #-------------------------------------------------- functions for &phase_two
1.160 raeburn 8439: sub user_search_result {
1.221 raeburn 8440: my ($context,$srch) = @_;
1.160 raeburn 8441: my %allhomes;
8442: my %inst_matches;
8443: my %srch_results;
1.181 raeburn 8444: my ($response,$currstate,$forcenewuser,$dirsrchres);
1.183 raeburn 8445: $srch->{'srchterm'} =~ s/\s+/ /g;
1.176 raeburn 8446: if ($srch->{'srchby'} !~ /^(uname|lastname|lastfirst)$/) {
1.160 raeburn 8447: $response = &mt('Invalid search.');
8448: }
8449: if ($srch->{'srchin'} !~ /^(crs|dom|alc|instd)$/) {
8450: $response = &mt('Invalid search.');
8451: }
1.177 raeburn 8452: if ($srch->{'srchtype'} !~ /^(exact|contains|begins)$/) {
1.160 raeburn 8453: $response = &mt('Invalid search.');
8454: }
8455: if ($srch->{'srchterm'} eq '') {
8456: $response = &mt('You must enter a search term.');
8457: }
1.183 raeburn 8458: if ($srch->{'srchterm'} =~ /^\s+$/) {
8459: $response = &mt('Your search term must contain more than just spaces.');
8460: }
1.160 raeburn 8461: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'instd')) {
8462: if (($srch->{'srchdomain'} eq '') ||
1.163 albertel 8463: ! (&Apache::lonnet::domain($srch->{'srchdomain'}))) {
1.160 raeburn 8464: $response = &mt('You must specify a valid domain when searching in a domain or institutional directory.')
8465: }
8466: }
8467: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs') ||
8468: ($srch->{'srchin'} eq 'alc')) {
1.176 raeburn 8469: if ($srch->{'srchby'} eq 'uname') {
1.243 raeburn 8470: my $unamecheck = $srch->{'srchterm'};
8471: if ($srch->{'srchtype'} eq 'contains') {
8472: if ($unamecheck !~ /^\w/) {
8473: $unamecheck = 'a'.$unamecheck;
8474: }
8475: }
8476: if ($unamecheck !~ /^$match_username$/) {
1.176 raeburn 8477: $response = &mt('You must specify a valid username. Only the following are allowed: letters numbers - . @');
8478: }
1.160 raeburn 8479: }
8480: }
1.180 raeburn 8481: if ($response ne '') {
1.413 raeburn 8482: $response = '<span class="LC_warning">'.$response.'</span><br />';
1.180 raeburn 8483: }
1.160 raeburn 8484: if ($srch->{'srchin'} eq 'instd') {
1.412 raeburn 8485: my $instd_chk = &instdirectorysrch_check($srch);
1.160 raeburn 8486: if ($instd_chk ne 'ok') {
1.412 raeburn 8487: my $domd_chk = &domdirectorysrch_check($srch);
1.413 raeburn 8488: $response .= '<span class="LC_warning">'.$instd_chk.'</span><br />';
1.412 raeburn 8489: if ($domd_chk eq 'ok') {
1.435 raeburn 8490: $response .= &mt('You may want to search in the LON-CAPA domain instead of in the institutional directory.');
1.412 raeburn 8491: }
1.415 raeburn 8492: $response .= '<br />';
1.412 raeburn 8493: }
8494: } else {
1.417 raeburn 8495: unless (($context eq 'requestcrs') && ($srch->{'srchtype'} eq 'exact')) {
1.412 raeburn 8496: my $domd_chk = &domdirectorysrch_check($srch);
1.438 raeburn 8497: if (($domd_chk ne 'ok') && ($env{'form.action'} ne 'accesslogs')) {
1.412 raeburn 8498: my $instd_chk = &instdirectorysrch_check($srch);
1.413 raeburn 8499: $response .= '<span class="LC_warning">'.$domd_chk.'</span><br />';
1.412 raeburn 8500: if ($instd_chk eq 'ok') {
1.435 raeburn 8501: $response .= &mt('You may want to search in the institutional directory instead of in the LON-CAPA domain.');
1.412 raeburn 8502: }
1.415 raeburn 8503: $response .= '<br />';
1.412 raeburn 8504: }
1.160 raeburn 8505: }
8506: }
8507: if ($response ne '') {
1.180 raeburn 8508: return ($currstate,$response);
1.160 raeburn 8509: }
8510: if ($srch->{'srchby'} eq 'uname') {
8511: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs')) {
8512: if ($env{'form.forcenew'}) {
8513: if ($srch->{'srchdomain'} ne $env{'request.role.domain'}) {
8514: my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
8515: if ($uhome eq 'no_host') {
8516: my $domdesc = &Apache::lonnet::domain($env{'request.role.domain'},'description');
1.180 raeburn 8517: my $showdom = &display_domain_info($env{'request.role.domain'});
8518: $response = &mt('New users can only be created in the domain to which your current role belongs - [_1].',$showdom);
1.160 raeburn 8519: } else {
1.179 raeburn 8520: $currstate = 'modify';
1.160 raeburn 8521: }
8522: } else {
1.179 raeburn 8523: $currstate = 'modify';
1.160 raeburn 8524: }
8525: } else {
8526: if ($srch->{'srchin'} eq 'dom') {
1.162 raeburn 8527: if ($srch->{'srchtype'} eq 'exact') {
8528: my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
8529: if ($uhome eq 'no_host') {
1.179 raeburn 8530: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8531: &build_search_response($context,$srch,%srch_results);
1.162 raeburn 8532: } else {
1.179 raeburn 8533: $currstate = 'modify';
1.416 raeburn 8534: if ($env{'form.action'} eq 'accesslogs') {
8535: $currstate = 'activity';
8536: }
1.310 raeburn 8537: my $uname = $srch->{'srchterm'};
8538: my $udom = $srch->{'srchdomain'};
8539: $srch_results{$uname.':'.$udom} =
8540: { &Apache::lonnet::get('environment',
8541: ['firstname',
8542: 'lastname',
8543: 'permanentemail'],
8544: $udom,$uname)
8545: };
1.162 raeburn 8546: }
8547: } else {
8548: %srch_results = &Apache::lonnet::usersearch($srch);
1.179 raeburn 8549: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8550: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 8551: }
8552: } else {
1.167 albertel 8553: my $courseusers = &get_courseusers();
1.162 raeburn 8554: if ($srch->{'srchtype'} eq 'exact') {
1.167 albertel 8555: if (exists($courseusers->{$srch->{'srchterm'}.':'.$srch->{'srchdomain'}})) {
1.179 raeburn 8556: $currstate = 'modify';
1.162 raeburn 8557: } else {
1.179 raeburn 8558: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8559: &build_search_response($context,$srch,%srch_results);
1.162 raeburn 8560: }
1.160 raeburn 8561: } else {
1.167 albertel 8562: foreach my $user (keys(%$courseusers)) {
1.162 raeburn 8563: my ($cuname,$cudomain) = split(/:/,$user);
8564: if ($cudomain eq $srch->{'srchdomain'}) {
1.177 raeburn 8565: my $matched = 0;
8566: if ($srch->{'srchtype'} eq 'begins') {
8567: if ($cuname =~ /^\Q$srch->{'srchterm'}\E/i) {
8568: $matched = 1;
8569: }
8570: } else {
8571: if ($cuname =~ /\Q$srch->{'srchterm'}\E/i) {
8572: $matched = 1;
8573: }
8574: }
8575: if ($matched) {
1.167 albertel 8576: $srch_results{$user} =
8577: {&Apache::lonnet::get('environment',
8578: ['firstname',
8579: 'lastname',
1.194 albertel 8580: 'permanentemail'],
8581: $cudomain,$cuname)};
1.162 raeburn 8582: }
8583: }
8584: }
1.179 raeburn 8585: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8586: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 8587: }
8588: }
8589: }
8590: } elsif ($srch->{'srchin'} eq 'alc') {
1.179 raeburn 8591: $currstate = 'query';
1.160 raeburn 8592: } elsif ($srch->{'srchin'} eq 'instd') {
1.181 raeburn 8593: ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
8594: if ($dirsrchres eq 'ok') {
8595: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8596: &build_search_response($context,$srch,%srch_results);
1.181 raeburn 8597: } else {
8598: my $showdom = &display_domain_info($srch->{'srchdomain'});
8599: $response = '<span class="LC_warning">'.
8600: &mt('Institutional directory search is not available in domain: [_1]',$showdom).
8601: '</span><br />'.
1.435 raeburn 8602: &mt('You may want to search in the LON-CAPA domain instead of in the institutional directory.').
1.415 raeburn 8603: '<br />';
1.181 raeburn 8604: }
1.160 raeburn 8605: }
8606: } else {
8607: if ($srch->{'srchin'} eq 'dom') {
8608: %srch_results = &Apache::lonnet::usersearch($srch);
1.179 raeburn 8609: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8610: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 8611: } elsif ($srch->{'srchin'} eq 'crs') {
1.167 albertel 8612: my $courseusers = &get_courseusers();
8613: foreach my $user (keys(%$courseusers)) {
1.160 raeburn 8614: my ($uname,$udom) = split(/:/,$user);
8615: my %names = &Apache::loncommon::getnames($uname,$udom);
8616: my %emails = &Apache::loncommon::getemails($uname,$udom);
8617: if ($srch->{'srchby'} eq 'lastname') {
8618: if ((($srch->{'srchtype'} eq 'exact') &&
8619: ($names{'lastname'} eq $srch->{'srchterm'})) ||
1.177 raeburn 8620: (($srch->{'srchtype'} eq 'begins') &&
8621: ($names{'lastname'} =~ /^\Q$srch->{'srchterm'}\E/i)) ||
1.160 raeburn 8622: (($srch->{'srchtype'} eq 'contains') &&
8623: ($names{'lastname'} =~ /\Q$srch->{'srchterm'}\E/i))) {
8624: $srch_results{$user} = {firstname => $names{'firstname'},
8625: lastname => $names{'lastname'},
8626: permanentemail => $emails{'permanentemail'},
8627: };
8628: }
8629: } elsif ($srch->{'srchby'} eq 'lastfirst') {
8630: my ($srchlast,$srchfirst) = split(/,/,$srch->{'srchterm'});
1.177 raeburn 8631: $srchlast =~ s/\s+$//;
8632: $srchfirst =~ s/^\s+//;
1.160 raeburn 8633: if ($srch->{'srchtype'} eq 'exact') {
8634: if (($names{'lastname'} eq $srchlast) &&
8635: ($names{'firstname'} eq $srchfirst)) {
8636: $srch_results{$user} = {firstname => $names{'firstname'},
8637: lastname => $names{'lastname'},
8638: permanentemail => $emails{'permanentemail'},
8639:
8640: };
8641: }
1.177 raeburn 8642: } elsif ($srch->{'srchtype'} eq 'begins') {
8643: if (($names{'lastname'} =~ /^\Q$srchlast\E/i) &&
8644: ($names{'firstname'} =~ /^\Q$srchfirst\E/i)) {
8645: $srch_results{$user} = {firstname => $names{'firstname'},
8646: lastname => $names{'lastname'},
8647: permanentemail => $emails{'permanentemail'},
8648: };
8649: }
8650: } else {
1.160 raeburn 8651: if (($names{'lastname'} =~ /\Q$srchlast\E/i) &&
8652: ($names{'firstname'} =~ /\Q$srchfirst\E/i)) {
8653: $srch_results{$user} = {firstname => $names{'firstname'},
8654: lastname => $names{'lastname'},
8655: permanentemail => $emails{'permanentemail'},
8656: };
8657: }
8658: }
8659: }
8660: }
1.179 raeburn 8661: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8662: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 8663: } elsif ($srch->{'srchin'} eq 'alc') {
1.179 raeburn 8664: $currstate = 'query';
1.160 raeburn 8665: } elsif ($srch->{'srchin'} eq 'instd') {
1.181 raeburn 8666: ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
8667: if ($dirsrchres eq 'ok') {
8668: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8669: &build_search_response($context,$srch,%srch_results);
1.181 raeburn 8670: } else {
1.412 raeburn 8671: my $showdom = &display_domain_info($srch->{'srchdomain'});
8672: $response = '<span class="LC_warning">'.
1.181 raeburn 8673: &mt('Institutional directory search is not available in domain: [_1]',$showdom).
8674: '</span><br />'.
1.435 raeburn 8675: &mt('You may want to search in the LON-CAPA domain instead of in the institutional directory.').
1.415 raeburn 8676: '<br />';
1.181 raeburn 8677: }
1.160 raeburn 8678: }
8679: }
1.179 raeburn 8680: return ($currstate,$response,$forcenewuser,\%srch_results);
1.160 raeburn 8681: }
8682:
1.412 raeburn 8683: sub domdirectorysrch_check {
8684: my ($srch) = @_;
8685: my $response;
8686: my %dom_inst_srch = &Apache::lonnet::get_dom('configuration',
8687: ['directorysrch'],$srch->{'srchdomain'});
8688: my $showdom = &display_domain_info($srch->{'srchdomain'});
8689: if (ref($dom_inst_srch{'directorysrch'}) eq 'HASH') {
8690: if ($dom_inst_srch{'directorysrch'}{'lcavailable'} eq '0') {
8691: return &mt('LON-CAPA directory search is not available in domain: [_1]',$showdom);
8692: }
8693: if ($dom_inst_srch{'directorysrch'}{'lclocalonly'}) {
8694: if ($env{'request.role.domain'} ne $srch->{'srchdomain'}) {
8695: return &mt('LON-CAPA directory search in domain: [_1] is only allowed for users with a current role in the domain.',$showdom);
8696: }
8697: }
8698: }
8699: return 'ok';
8700: }
8701:
8702: sub instdirectorysrch_check {
1.160 raeburn 8703: my ($srch) = @_;
8704: my $can_search = 0;
8705: my $response;
8706: my %dom_inst_srch = &Apache::lonnet::get_dom('configuration',
8707: ['directorysrch'],$srch->{'srchdomain'});
1.180 raeburn 8708: my $showdom = &display_domain_info($srch->{'srchdomain'});
1.160 raeburn 8709: if (ref($dom_inst_srch{'directorysrch'}) eq 'HASH') {
8710: if (!$dom_inst_srch{'directorysrch'}{'available'}) {
1.180 raeburn 8711: return &mt('Institutional directory search is not available in domain: [_1]',$showdom);
1.160 raeburn 8712: }
8713: if ($dom_inst_srch{'directorysrch'}{'localonly'}) {
8714: if ($env{'request.role.domain'} ne $srch->{'srchdomain'}) {
1.180 raeburn 8715: return &mt('Institutional directory search in domain: [_1] is only allowed for users with a current role in the domain.',$showdom);
1.160 raeburn 8716: }
8717: my @usertypes = split(/:/,$env{'environment.inststatus'});
8718: if (!@usertypes) {
8719: push(@usertypes,'default');
8720: }
8721: if (ref($dom_inst_srch{'directorysrch'}{'cansearch'}) eq 'ARRAY') {
8722: foreach my $type (@usertypes) {
8723: if (grep(/^\Q$type\E$/,@{$dom_inst_srch{'directorysrch'}{'cansearch'}})) {
8724: $can_search = 1;
8725: last;
8726: }
8727: }
8728: }
8729: if (!$can_search) {
8730: my ($insttypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($srch->{'srchdomain'});
8731: my @longtypes;
8732: foreach my $item (@usertypes) {
1.229 raeburn 8733: if (defined($insttypes->{$item})) {
8734: push (@longtypes,$insttypes->{$item});
8735: } elsif ($item eq 'default') {
8736: push (@longtypes,&mt('other'));
8737: }
1.160 raeburn 8738: }
8739: my $insttype_str = join(', ',@longtypes);
1.180 raeburn 8740: return &mt('Institutional directory search in domain: [_1] is not available to your user type: ',$showdom).$insttype_str;
1.229 raeburn 8741: }
1.160 raeburn 8742: } else {
8743: $can_search = 1;
8744: }
8745: } else {
1.180 raeburn 8746: return &mt('Institutional directory search has not been configured for domain: [_1]',$showdom);
1.160 raeburn 8747: }
8748: my %longtext = &Apache::lonlocal::texthash (
1.167 albertel 8749: uname => 'username',
1.160 raeburn 8750: lastfirst => 'last name, first name',
1.167 albertel 8751: lastname => 'last name',
1.172 raeburn 8752: contains => 'contains',
1.178 raeburn 8753: exact => 'as exact match to',
8754: begins => 'begins with',
1.160 raeburn 8755: );
8756: if ($can_search) {
8757: if (ref($dom_inst_srch{'directorysrch'}{'searchby'}) eq 'ARRAY') {
8758: if (!grep(/^\Q$srch->{'srchby'}\E$/,@{$dom_inst_srch{'directorysrch'}{'searchby'}})) {
1.180 raeburn 8759: return &mt('Institutional directory search in domain: [_1] is not available for searching by "[_2]"',$showdom,$longtext{$srch->{'srchby'}});
1.160 raeburn 8760: }
8761: } else {
1.180 raeburn 8762: return &mt('Institutional directory search in domain: [_1] is not available.', $showdom);
1.160 raeburn 8763: }
8764: }
8765: if ($can_search) {
1.178 raeburn 8766: if (ref($dom_inst_srch{'directorysrch'}{'searchtypes'}) eq 'ARRAY') {
8767: if (grep(/^\Q$srch->{'srchtype'}\E/,@{$dom_inst_srch{'directorysrch'}{'searchtypes'}})) {
8768: return 'ok';
8769: } else {
1.180 raeburn 8770: return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
1.178 raeburn 8771: }
8772: } else {
8773: if ((($dom_inst_srch{'directorysrch'}{'searchtypes'} eq 'specify') &&
8774: ($srch->{'srchtype'} eq 'exact' || $srch->{'srchtype'} eq 'contains')) ||
8775: ($dom_inst_srch{'directorysrch'}{'searchtypes'} eq $srch->{'srchtype'})) {
8776: return 'ok';
8777: } else {
1.180 raeburn 8778: return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
1.178 raeburn 8779: }
1.160 raeburn 8780: }
8781: }
8782: }
8783:
8784: sub get_courseusers {
8785: my %advhash;
1.167 albertel 8786: my $classlist = &Apache::loncoursedata::get_classlist();
1.160 raeburn 8787: my %coursepersonnel=&Apache::lonnet::get_course_adv_roles();
8788: foreach my $role (sort(keys(%coursepersonnel))) {
8789: foreach my $user (split(/\,/,$coursepersonnel{$role})) {
1.167 albertel 8790: if (!exists($classlist->{$user})) {
8791: $classlist->{$user} = [];
8792: }
1.160 raeburn 8793: }
8794: }
1.167 albertel 8795: return $classlist;
1.160 raeburn 8796: }
8797:
8798: sub build_search_response {
1.221 raeburn 8799: my ($context,$srch,%srch_results) = @_;
1.179 raeburn 8800: my ($currstate,$response,$forcenewuser);
1.160 raeburn 8801: my %names = (
1.330 bisitz 8802: 'uname' => 'username',
8803: 'lastname' => 'last name',
1.160 raeburn 8804: 'lastfirst' => 'last name, first name',
1.330 bisitz 8805: 'crs' => 'this course',
8806: 'dom' => 'LON-CAPA domain',
8807: 'instd' => 'the institutional directory for domain',
1.160 raeburn 8808: );
8809:
8810: my %single = (
1.180 raeburn 8811: begins => 'A match',
1.160 raeburn 8812: contains => 'A match',
1.180 raeburn 8813: exact => 'An exact match',
1.160 raeburn 8814: );
8815: my %nomatch = (
1.180 raeburn 8816: begins => 'No match',
1.160 raeburn 8817: contains => 'No match',
1.180 raeburn 8818: exact => 'No exact match',
1.160 raeburn 8819: );
8820: if (keys(%srch_results) > 1) {
1.179 raeburn 8821: $currstate = 'select';
1.160 raeburn 8822: } else {
8823: if (keys(%srch_results) == 1) {
1.416 raeburn 8824: if ($env{'form.action'} eq 'accesslogs') {
8825: $currstate = 'activity';
8826: } else {
8827: $currstate = 'modify';
8828: }
1.180 raeburn 8829: $response = &mt("$single{$srch->{'srchtype'}} was found for the $names{$srch->{'srchby'}} ([_1]) in $names{$srch->{'srchin'}}.",$srch->{'srchterm'});
8830: if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
1.330 bisitz 8831: $response .= ': '.&display_domain_info($srch->{'srchdomain'});
1.180 raeburn 8832: }
1.330 bisitz 8833: } else { # Search has nothing found. Prepare message to user.
8834: $response = '<span class="LC_warning">';
1.180 raeburn 8835: if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
1.330 bisitz 8836: $response .= &mt("$nomatch{$srch->{'srchtype'}} found for the $names{$srch->{'srchby'}} [_1] in $names{$srch->{'srchin'}}: [_2]",
8837: '<b>'.$srch->{'srchterm'}.'</b>',
8838: &display_domain_info($srch->{'srchdomain'}));
8839: } else {
8840: $response .= &mt("$nomatch{$srch->{'srchtype'}} found for the $names{$srch->{'srchby'}} [_1] in $names{$srch->{'srchin'}}.",
8841: '<b>'.$srch->{'srchterm'}.'</b>');
1.180 raeburn 8842: }
8843: $response .= '</span>';
1.330 bisitz 8844:
1.160 raeburn 8845: if ($srch->{'srchin'} ne 'alc') {
8846: $forcenewuser = 1;
8847: my $cansrchinst = 0;
1.438 raeburn 8848: if (($srch->{'srchdomain'}) && ($env{'form.action'} ne 'accesslogs')) {
1.160 raeburn 8849: my %domconfig = &Apache::lonnet::get_dom('configuration',['directorysrch'],$srch->{'srchdomain'});
8850: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
8851: if ($domconfig{'directorysrch'}{'available'}) {
8852: $cansrchinst = 1;
8853: }
8854: }
8855: }
1.180 raeburn 8856: if ((($srch->{'srchby'} eq 'lastfirst') ||
8857: ($srch->{'srchby'} eq 'lastname')) &&
8858: ($srch->{'srchin'} eq 'dom')) {
8859: if ($cansrchinst) {
8860: $response .= '<br />'.&mt('You may want to broaden your search to a search of the institutional directory for the domain.');
1.160 raeburn 8861: }
8862: }
1.180 raeburn 8863: if ($srch->{'srchin'} eq 'crs') {
8864: $response .= '<br />'.&mt('You may want to broaden your search to the selected LON-CAPA domain.');
8865: }
8866: }
1.305 raeburn 8867: my $createdom = $env{'request.role.domain'};
8868: if ($context eq 'requestcrs') {
8869: if ($env{'form.coursedom'} ne '') {
8870: $createdom = $env{'form.coursedom'};
8871: }
8872: }
1.416 raeburn 8873: unless (($env{'form.action'} eq 'accesslogs') || (($srch->{'srchby'} eq 'uname') && ($srch->{'srchin'} eq 'dom') &&
8874: ($srch->{'srchtype'} eq 'exact') && ($srch->{'srchdomain'} eq $createdom))) {
1.221 raeburn 8875: my $cancreate =
1.305 raeburn 8876: &Apache::lonuserutils::can_create_user($createdom,$context);
8877: my $targetdom = '<span class="LC_cusr_emph">'.$createdom.'</span>';
1.221 raeburn 8878: if ($cancreate) {
1.305 raeburn 8879: my $showdom = &display_domain_info($createdom);
1.266 bisitz 8880: $response .= '<br /><br />'
8881: .'<b>'.&mt('To add a new user:').'</b>'
1.305 raeburn 8882: .'<br />';
8883: if ($context eq 'requestcrs') {
8884: $response .= &mt("(You can only define new users in the new course's domain - [_1])",$targetdom);
8885: } else {
8886: $response .= &mt("(You can only create new users in your current role's domain - [_1])",$targetdom);
8887: }
8888: $response .='<ul><li>'
1.266 bisitz 8889: .&mt("Set 'Domain/institution to search' to: [_1]",'<span class="LC_cusr_emph">'.$showdom.'</span>')
8890: .'</li><li>'
8891: .&mt("Set 'Search criteria' to: [_1]username is ..... in selected LON-CAPA domain[_2]",'<span class="LC_cusr_emph">','</span>')
8892: .'</li><li>'
8893: .&mt('Provide the proposed username')
8894: .'</li><li>'
8895: .&mt("Click 'Search'")
8896: .'</li></ul><br />';
1.221 raeburn 8897: } else {
1.422 raeburn 8898: unless (($context eq 'domain') && ($env{'form.action'} eq 'singleuser')) {
8899: my $helplink = ' href="javascript:helpMenu('."'display'".')"';
8900: $response .= '<br /><br />';
8901: if ($context eq 'requestcrs') {
8902: $response .= &mt("You are not authorized to define new users in the new course's domain - [_1].",$targetdom);
8903: } else {
8904: $response .= &mt("You are not authorized to create new users in your current role's domain - [_1].",$targetdom);
8905: }
8906: $response .= '<br />'
8907: .&mt('Please contact the [_1]helpdesk[_2] if you need to create a new user.'
8908: ,' <a'.$helplink.'>'
8909: ,'</a>')
8910: .'<br />';
1.305 raeburn 8911: }
1.221 raeburn 8912: }
1.160 raeburn 8913: }
8914: }
8915: }
1.179 raeburn 8916: return ($currstate,$response,$forcenewuser);
1.160 raeburn 8917: }
8918:
1.180 raeburn 8919: sub display_domain_info {
8920: my ($dom) = @_;
8921: my $output = $dom;
8922: if ($dom ne '') {
8923: my $domdesc = &Apache::lonnet::domain($dom,'description');
8924: if ($domdesc ne '') {
8925: $output .= ' <span class="LC_cusr_emph">('.$domdesc.')</span>';
8926: }
8927: }
8928: return $output;
8929: }
8930:
1.160 raeburn 8931: sub crumb_utilities {
8932: my %elements = (
8933: crtuser => {
8934: srchterm => 'text',
1.172 raeburn 8935: srchin => 'selectbox',
1.160 raeburn 8936: srchby => 'selectbox',
8937: srchtype => 'selectbox',
8938: srchdomain => 'selectbox',
8939: },
1.207 raeburn 8940: crtusername => {
8941: srchterm => 'text',
8942: srchdomain => 'selectbox',
8943: },
1.160 raeburn 8944: docustom => {
8945: rolename => 'selectbox',
8946: newrolename => 'textbox',
8947: },
1.179 raeburn 8948: studentform => {
8949: srchterm => 'text',
8950: srchin => 'selectbox',
8951: srchby => 'selectbox',
8952: srchtype => 'selectbox',
8953: srchdomain => 'selectbox',
8954: },
1.160 raeburn 8955: );
8956:
8957: my $jsback .= qq|
8958: function backPage(formname,prevphase,prevstate) {
1.211 raeburn 8959: if (typeof prevphase == 'undefined') {
8960: formname.phase.value = '';
8961: }
8962: else {
8963: formname.phase.value = prevphase;
8964: }
8965: if (typeof prevstate == 'undefined') {
8966: formname.currstate.value = '';
8967: }
8968: else {
8969: formname.currstate.value = prevstate;
8970: }
1.160 raeburn 8971: formname.submit();
8972: }
8973: |;
8974: return ($jsback,\%elements);
8975: }
8976:
1.26 matthew 8977: sub course_level_table {
1.375 raeburn 8978: my ($inccourses,$showcredits,$defaultcredits) = @_;
8979: return unless (ref($inccourses) eq 'HASH');
1.26 matthew 8980: my $table = '';
1.62 www 8981: # Custom Roles?
8982:
1.190 raeburn 8983: my %customroles=&Apache::lonuserutils::my_custom_roles();
1.89 raeburn 8984: my %lt=&Apache::lonlocal::texthash(
8985: 'exs' => "Existing sections",
8986: 'new' => "Define new section",
8987: 'ssd' => "Set Start Date",
8988: 'sed' => "Set End Date",
1.131 raeburn 8989: 'crl' => "Course Level",
1.89 raeburn 8990: 'act' => "Activate",
8991: 'rol' => "Role",
8992: 'ext' => "Extent",
1.113 raeburn 8993: 'grs' => "Section",
1.375 raeburn 8994: 'crd' => "Credits",
1.89 raeburn 8995: 'sta' => "Start",
8996: 'end' => "End"
8997: );
1.62 www 8998:
1.375 raeburn 8999: foreach my $protectedcourse (sort(keys(%{$inccourses}))) {
1.135 raeburn 9000: my $thiscourse=$protectedcourse;
1.26 matthew 9001: $thiscourse=~s:_:/:g;
9002: my %coursedata=&Apache::lonnet::coursedescription($thiscourse);
1.365 raeburn 9003: my $isowner = &Apache::lonuserutils::is_courseowner($protectedcourse,$coursedata{'internal.courseowner'});
1.26 matthew 9004: my $area=$coursedata{'description'};
1.321 raeburn 9005: my $crstype=$coursedata{'type'};
1.135 raeburn 9006: if (!defined($area)) { $area=&mt('Unavailable course').': '.$protectedcourse; }
1.89 raeburn 9007: my ($domain,$cnum)=split(/\//,$thiscourse);
1.115 albertel 9008: my %sections_count;
1.101 albertel 9009: if (defined($env{'request.course.id'})) {
9010: if ($env{'request.course.id'} eq $domain.'_'.$cnum) {
1.115 albertel 9011: %sections_count =
9012: &Apache::loncommon::get_sections($domain,$cnum);
1.92 raeburn 9013: }
9014: }
1.321 raeburn 9015: my @roles = &Apache::lonuserutils::roles_by_context('course','',$crstype);
1.213 raeburn 9016: foreach my $role (@roles) {
1.321 raeburn 9017: my $plrole=&Apache::lonnet::plaintext($role,$crstype);
1.329 raeburn 9018: if ((&Apache::lonnet::allowed('c'.$role,$thiscourse)) ||
9019: ((($role eq 'cc') || ($role eq 'co')) && ($isowner))) {
1.221 raeburn 9020: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
1.375 raeburn 9021: $plrole,\%sections_count,\%lt,
1.402 raeburn 9022: $showcredits,$defaultcredits,$crstype);
1.221 raeburn 9023: } elsif ($env{'request.course.sec'} ne '') {
9024: if (&Apache::lonnet::allowed('c'.$role,$thiscourse.'/'.
9025: $env{'request.course.sec'})) {
9026: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
1.375 raeburn 9027: $plrole,\%sections_count,\%lt,
1.402 raeburn 9028: $showcredits,$defaultcredits,$crstype);
1.26 matthew 9029: }
9030: }
9031: }
1.221 raeburn 9032: if (&Apache::lonnet::allowed('ccr',$thiscourse)) {
1.324 raeburn 9033: foreach my $cust (sort(keys(%customroles))) {
9034: next if ($crstype eq 'Community' && $customroles{$cust} =~ /bre\&S/);
1.221 raeburn 9035: my $role = 'cr_cr_'.$env{'user.domain'}.'_'.$env{'user.name'}.'_'.$cust;
9036: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
1.402 raeburn 9037: $cust,\%sections_count,\%lt,
9038: $showcredits,$defaultcredits,$crstype);
1.221 raeburn 9039: }
1.62 www 9040: }
1.26 matthew 9041: }
9042: return '' if ($table eq ''); # return nothing if there is nothing
9043: # in the table
1.188 raeburn 9044: my $result;
9045: if (!$env{'request.course.id'}) {
9046: $result = '<h4>'.$lt{'crl'}.'</h4>'."\n";
9047: }
9048: $result .=
1.136 raeburn 9049: &Apache::loncommon::start_data_table().
9050: &Apache::loncommon::start_data_table_header_row().
1.375 raeburn 9051: '<th>'.$lt{'act'}.'</th><th>'.$lt{'rol'}.'</th>'."\n".
1.402 raeburn 9052: '<th>'.$lt{'ext'}.'</th><th>'."\n";
9053: if ($showcredits) {
9054: $result .= $lt{'crd'}.'</th>';
9055: }
9056: $result .=
1.375 raeburn 9057: '<th>'.$lt{'grs'}.'</th><th>'.$lt{'sta'}.'</th>'."\n".
9058: '<th>'.$lt{'end'}.'</th>'.
1.136 raeburn 9059: &Apache::loncommon::end_data_table_header_row().
9060: $table.
9061: &Apache::loncommon::end_data_table();
1.26 matthew 9062: return $result;
9063: }
1.88 raeburn 9064:
1.221 raeburn 9065: sub course_level_row {
1.375 raeburn 9066: my ($protectedcourse,$role,$area,$domain,$plrole,$sections_count,
1.402 raeburn 9067: $lt,$showcredits,$defaultcredits,$crstype) = @_;
1.375 raeburn 9068: my $creditem;
1.222 raeburn 9069: my $row = &Apache::loncommon::start_data_table_row().
9070: ' <td><input type="checkbox" name="act_'.
9071: $protectedcourse.'_'.$role.'" /></td>'."\n".
9072: ' <td>'.$plrole.'</td>'."\n".
9073: ' <td>'.$area.'<br />Domain: '.$domain.'</td>'."\n";
1.402 raeburn 9074: if (($showcredits) && ($role eq 'st') && ($crstype eq 'Course')) {
1.375 raeburn 9075: $row .=
9076: '<td><input type="text" name="credits_'.$protectedcourse.'_'.
9077: $role.'" size="3" value="'.$defaultcredits.'" /></td>';
9078: } else {
9079: $row .= '<td> </td>';
9080: }
1.322 raeburn 9081: if (($role eq 'cc') || ($role eq 'co')) {
1.222 raeburn 9082: $row .= '<td> </td>';
1.221 raeburn 9083: } elsif ($env{'request.course.sec'} ne '') {
1.222 raeburn 9084: $row .= ' <td><input type="hidden" value="'.
9085: $env{'request.course.sec'}.'" '.
9086: 'name="sec_'.$protectedcourse.'_'.$role.'" />'.
9087: $env{'request.course.sec'}.'</td>';
1.221 raeburn 9088: } else {
9089: if (ref($sections_count) eq 'HASH') {
9090: my $currsec =
9091: &Apache::lonuserutils::course_sections($sections_count,
9092: $protectedcourse.'_'.$role);
1.222 raeburn 9093: $row .= '<td><table class="LC_createuser">'."\n".
9094: '<tr class="LC_section_row">'."\n".
9095: ' <td valign="top">'.$lt->{'exs'}.'<br />'.
9096: $currsec.'</td>'."\n".
9097: ' <td> </td>'."\n".
9098: ' <td valign="top"> '.$lt->{'new'}.'<br />'.
1.221 raeburn 9099: '<input type="text" name="newsec_'.$protectedcourse.'_'.$role.
9100: '" value="" />'.
9101: '<input type="hidden" '.
9102: 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'."\n".
1.222 raeburn 9103: '</tr></table></td>'."\n";
1.221 raeburn 9104: } else {
1.222 raeburn 9105: $row .= '<td><input type="text" size="10" '.
1.375 raeburn 9106: 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'."\n";
1.221 raeburn 9107: }
9108: }
1.222 raeburn 9109: $row .= <<ENDTIMEENTRY;
9110: <td><input type="hidden" name="start_$protectedcourse\_$role" value="" />
1.221 raeburn 9111: <a href=
9112: "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 9113: <td><input type="hidden" name="end_$protectedcourse\_$role" value="" />
1.221 raeburn 9114: <a href=
9115: "javascript:pjump('date_end','End Date $plrole',document.cu.end_$protectedcourse\_$role.value,'end_$protectedcourse\_$role','cu.pres','dateset')">$lt->{'sed'}</a></td>
9116: ENDTIMEENTRY
1.222 raeburn 9117: $row .= &Apache::loncommon::end_data_table_row();
9118: return $row;
1.221 raeburn 9119: }
9120:
1.88 raeburn 9121: sub course_level_dc {
1.375 raeburn 9122: my ($dcdom,$showcredits) = @_;
1.190 raeburn 9123: my %customroles=&Apache::lonuserutils::my_custom_roles();
1.213 raeburn 9124: my @roles = &Apache::lonuserutils::roles_by_context('course');
1.88 raeburn 9125: my $hiddenitems = '<input type="hidden" name="dcdomain" value="'.$dcdom.'" />'.
9126: '<input type="hidden" name="origdom" value="'.$dcdom.'" />'.
1.133 raeburn 9127: '<input type="hidden" name="dccourse" value="" />';
1.355 www 9128: my $courseform=&Apache::loncommon::selectcourse_link
1.356 raeburn 9129: ('cu','dccourse','dcdomain','coursedesc',undef,undef,'Select','crstype');
1.375 raeburn 9130: my $credit_elem;
9131: if ($showcredits) {
9132: $credit_elem = 'credits';
9133: }
9134: my $cb_jscript = &Apache::loncommon::coursebrowser_javascript($dcdom,'currsec','cu','role','Course/Community Browser',$credit_elem);
1.88 raeburn 9135: my %lt=&Apache::lonlocal::texthash(
9136: 'rol' => "Role",
1.113 raeburn 9137: 'grs' => "Section",
1.88 raeburn 9138: 'exs' => "Existing sections",
9139: 'new' => "Define new section",
9140: 'sta' => "Start",
9141: 'end' => "End",
9142: 'ssd' => "Set Start Date",
1.355 www 9143: 'sed' => "Set End Date",
1.375 raeburn 9144: 'scc' => "Course/Community",
9145: 'crd' => "Credits",
1.88 raeburn 9146: );
1.323 raeburn 9147: my $header = '<h4>'.&mt('Course/Community Level').'</h4>'.
1.136 raeburn 9148: &Apache::loncommon::start_data_table().
9149: &Apache::loncommon::start_data_table_header_row().
1.375 raeburn 9150: '<th>'.$lt{'scc'}.'</th><th>'.$lt{'rol'}.'</th>'."\n".
1.397 bisitz 9151: '<th>'.$lt{'grs'}.'</th>'."\n";
9152: $header .= '<th>'.$lt{'crd'}.'</th>'."\n" if ($showcredits);
9153: $header .= '<th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'."\n".
1.136 raeburn 9154: &Apache::loncommon::end_data_table_header_row();
1.143 raeburn 9155: my $otheritems = &Apache::loncommon::start_data_table_row()."\n".
1.356 raeburn 9156: '<td><br /><span class="LC_nobreak"><input type="text" name="coursedesc" value="" onfocus="this.blur();opencrsbrowser('."'cu','dccourse','dcdomain','coursedesc','','','','crstype'".')" />'.
9157: $courseform.(' ' x4).'</span></td>'."\n".
1.389 bisitz 9158: '<td valign="top"><br /><select name="role">'."\n";
1.213 raeburn 9159: foreach my $role (@roles) {
1.135 raeburn 9160: my $plrole=&Apache::lonnet::plaintext($role);
1.389 bisitz 9161: $otheritems .= ' <option value="'.$role.'">'.$plrole.'</option>';
1.88 raeburn 9162: }
1.404 raeburn 9163: if ( keys(%customroles) > 0) {
9164: foreach my $cust (sort(keys(%customroles))) {
1.101 albertel 9165: my $custrole='cr_cr_'.$env{'user.domain'}.
1.135 raeburn 9166: '_'.$env{'user.name'}.'_'.$cust;
1.389 bisitz 9167: $otheritems .= ' <option value="'.$custrole.'">'.$cust.'</option>';
1.88 raeburn 9168: }
9169: }
9170: $otheritems .= '</select></td><td>'.
9171: '<table border="0" cellspacing="0" cellpadding="0">'.
9172: '<tr><td valign="top"><b>'.$lt{'exs'}.'</b><br /><select name="currsec">'.
1.389 bisitz 9173: ' <option value=""><--'.&mt('Pick course first').'</option></select></td>'.
1.88 raeburn 9174: '<td> </td>'.
9175: '<td valign="top"> <b>'.$lt{'new'}.'</b><br />'.
1.113 raeburn 9176: '<input type="text" name="newsec" value="" />'.
1.237 raeburn 9177: '<input type="hidden" name="section" value="" />'.
1.323 raeburn 9178: '<input type="hidden" name="groups" value="" />'.
9179: '<input type="hidden" name="crstype" value="" /></td>'.
1.375 raeburn 9180: '</tr></table></td>'."\n";
9181: if ($showcredits) {
9182: $otheritems .= '<td><br />'."\n".
1.397 bisitz 9183: '<input type="text" size="3" name="credits" value="" /></td>'."\n";
1.375 raeburn 9184: }
1.88 raeburn 9185: $otheritems .= <<ENDTIMEENTRY;
1.323 raeburn 9186: <td><br /><input type="hidden" name="start" value='' />
1.88 raeburn 9187: <a href=
9188: "javascript:pjump('date_start','Start Date',document.cu.start.value,'start','cu.pres','dateset')">$lt{'ssd'}</a></td>
1.323 raeburn 9189: <td><br /><input type="hidden" name="end" value='' />
1.88 raeburn 9190: <a href=
9191: "javascript:pjump('date_end','End Date',document.cu.end.value,'end','cu.pres','dateset')">$lt{'sed'}</a></td>
9192: ENDTIMEENTRY
1.136 raeburn 9193: $otheritems .= &Apache::loncommon::end_data_table_row().
9194: &Apache::loncommon::end_data_table()."\n";
1.88 raeburn 9195: return $cb_jscript.$header.$hiddenitems.$otheritems;
9196: }
9197:
1.237 raeburn 9198: sub update_selfenroll_config {
1.400 raeburn 9199: my ($r,$cid,$cdom,$cnum,$context,$crstype,$currsettings) = @_;
1.398 raeburn 9200: return unless (ref($currsettings) eq 'HASH');
9201: my ($row,$lt) = &Apache::lonuserutils::get_selfenroll_titles();
9202: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
1.237 raeburn 9203: my (%changes,%warning);
1.241 raeburn 9204: my $curr_types;
1.400 raeburn 9205: my %noedit;
9206: unless ($context eq 'domain') {
9207: %noedit = &get_noedit_fields($cdom,$cnum,$crstype,$row);
9208: }
1.237 raeburn 9209: if (ref($row) eq 'ARRAY') {
9210: foreach my $item (@{$row}) {
1.400 raeburn 9211: next if ($noedit{$item});
1.237 raeburn 9212: if ($item eq 'enroll_dates') {
9213: my (%currenrolldate,%newenrolldate);
9214: foreach my $type ('start','end') {
1.398 raeburn 9215: $currenrolldate{$type} = $currsettings->{'selfenroll_'.$type.'_date'};
1.237 raeburn 9216: $newenrolldate{$type} = &Apache::lonhtmlcommon::get_date_from_form('selfenroll_'.$type.'_date');
9217: if ($newenrolldate{$type} ne $currenrolldate{$type}) {
9218: $changes{'internal.selfenroll_'.$type.'_date'} = $newenrolldate{$type};
9219: }
9220: }
9221: } elsif ($item eq 'access_dates') {
9222: my (%currdate,%newdate);
9223: foreach my $type ('start','end') {
1.398 raeburn 9224: $currdate{$type} = $currsettings->{'selfenroll_'.$type.'_access'};
1.237 raeburn 9225: $newdate{$type} = &Apache::lonhtmlcommon::get_date_from_form('selfenroll_'.$type.'_access');
9226: if ($newdate{$type} ne $currdate{$type}) {
9227: $changes{'internal.selfenroll_'.$type.'_access'} = $newdate{$type};
9228: }
9229: }
1.241 raeburn 9230: } elsif ($item eq 'types') {
1.398 raeburn 9231: $curr_types = $currsettings->{'selfenroll_'.$item};
1.241 raeburn 9232: if ($env{'form.selfenroll_all'}) {
9233: if ($curr_types ne '*') {
9234: $changes{'internal.selfenroll_types'} = '*';
9235: } else {
9236: next;
9237: }
9238: } else {
1.249 raeburn 9239: my %currdoms;
1.241 raeburn 9240: my @entries = split(/;/,$curr_types);
9241: my @deletedoms = &Apache::loncommon::get_env_multiple('form.selfenroll_delete');
1.249 raeburn 9242: my @activations = &Apache::loncommon::get_env_multiple('form.selfenroll_activate');
1.241 raeburn 9243: my $newnum = 0;
1.249 raeburn 9244: my @latesttypes;
9245: foreach my $num (@activations) {
9246: my @types = &Apache::loncommon::get_env_multiple('form.selfenroll_types_'.$num);
9247: if (@types > 0) {
1.241 raeburn 9248: @types = sort(@types);
9249: my $typestr = join(',',@types);
1.249 raeburn 9250: my $typedom = $env{'form.selfenroll_dom_'.$num};
9251: $latesttypes[$newnum] = $typedom.':'.$typestr;
9252: $currdoms{$typedom} = 1;
1.241 raeburn 9253: $newnum ++;
9254: }
9255: }
1.338 raeburn 9256: for (my $j=0; $j<$env{'form.selfenroll_types_total'}; $j++) {
9257: if ((!grep(/^$j$/,@deletedoms)) && (!grep(/^$j$/,@activations))) {
1.249 raeburn 9258: my @types = &Apache::loncommon::get_env_multiple('form.selfenroll_types_'.$j);
9259: if (@types > 0) {
9260: @types = sort(@types);
9261: my $typestr = join(',',@types);
9262: my $typedom = $env{'form.selfenroll_dom_'.$j};
9263: $latesttypes[$newnum] = $typedom.':'.$typestr;
9264: $currdoms{$typedom} = 1;
9265: $newnum ++;
9266: }
9267: }
9268: }
9269: if ($env{'form.selfenroll_newdom'} ne '') {
9270: my $typedom = $env{'form.selfenroll_newdom'};
9271: if ((!defined($currdoms{$typedom})) &&
9272: (&Apache::lonnet::domain($typedom) ne '')) {
9273: my $typestr;
9274: my ($othertitle,$usertypes,$types) =
9275: &Apache::loncommon::sorted_inst_types($typedom);
9276: my $othervalue = 'any';
9277: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
9278: if (@{$types} > 0) {
1.257 raeburn 9279: my @esc_types = map { &escape($_); } @{$types};
1.249 raeburn 9280: $othervalue = 'other';
1.258 raeburn 9281: $typestr = join(',',(@esc_types,$othervalue));
1.249 raeburn 9282: }
9283: $typestr = $othervalue;
9284: } else {
9285: $typestr = $othervalue;
9286: }
9287: $latesttypes[$newnum] = $typedom.':'.$typestr;
9288: $newnum ++ ;
9289: }
9290: }
1.241 raeburn 9291: my $selfenroll_types = join(';',@latesttypes);
9292: if ($selfenroll_types ne $curr_types) {
9293: $changes{'internal.selfenroll_types'} = $selfenroll_types;
9294: }
9295: }
1.276 raeburn 9296: } elsif ($item eq 'limit') {
9297: my $newlimit = $env{'form.selfenroll_limit'};
9298: my $newcap = $env{'form.selfenroll_cap'};
9299: $newcap =~s/\s+//g;
1.398 raeburn 9300: my $currlimit = $currsettings->{'selfenroll_limit'};
1.276 raeburn 9301: $currlimit = 'none' if ($currlimit eq '');
1.398 raeburn 9302: my $currcap = $currsettings->{'selfenroll_cap'};
1.276 raeburn 9303: if ($newlimit ne $currlimit) {
9304: if ($newlimit ne 'none') {
9305: if ($newcap =~ /^\d+$/) {
9306: if ($newcap ne $currcap) {
9307: $changes{'internal.selfenroll_cap'} = $newcap;
9308: }
9309: $changes{'internal.selfenroll_limit'} = $newlimit;
9310: } else {
1.398 raeburn 9311: $warning{$item} = &mt('Maximum enrollment setting unchanged.').'<br />'.
9312: &mt('The value provided was invalid - it must be a positive integer if enrollment is being limited.');
1.276 raeburn 9313: }
9314: } elsif ($currcap ne '') {
9315: $changes{'internal.selfenroll_cap'} = '';
9316: $changes{'internal.selfenroll_limit'} = $newlimit;
9317: }
9318: } elsif ($currlimit ne 'none') {
9319: if ($newcap =~ /^\d+$/) {
9320: if ($newcap ne $currcap) {
9321: $changes{'internal.selfenroll_cap'} = $newcap;
9322: }
9323: } else {
1.398 raeburn 9324: $warning{$item} = &mt('Maximum enrollment setting unchanged.').'<br />'.
9325: &mt('The value provided was invalid - it must be a positive integer if enrollment is being limited.');
1.276 raeburn 9326: }
9327: }
9328: } elsif ($item eq 'approval') {
9329: my (@currnotified,@newnotified);
1.398 raeburn 9330: my $currapproval = $currsettings->{'selfenroll_approval'};
9331: my $currnotifylist = $currsettings->{'selfenroll_notifylist'};
1.276 raeburn 9332: if ($currnotifylist ne '') {
9333: @currnotified = split(/,/,$currnotifylist);
9334: @currnotified = sort(@currnotified);
9335: }
9336: my $newapproval = $env{'form.selfenroll_approval'};
9337: @newnotified = &Apache::loncommon::get_env_multiple('form.selfenroll_notify');
9338: @newnotified = sort(@newnotified);
9339: if ($newapproval ne $currapproval) {
9340: $changes{'internal.selfenroll_approval'} = $newapproval;
9341: if (!$newapproval) {
9342: if ($currnotifylist ne '') {
9343: $changes{'internal.selfenroll_notifylist'} = '';
9344: }
9345: } else {
9346: my @differences =
1.295 raeburn 9347: &Apache::loncommon::compare_arrays(\@currnotified,\@newnotified);
1.276 raeburn 9348: if (@differences > 0) {
9349: if (@newnotified > 0) {
9350: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
9351: } else {
9352: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
9353: }
9354: }
9355: }
9356: } else {
1.295 raeburn 9357: my @differences = &Apache::loncommon::compare_arrays(\@currnotified,\@newnotified);
1.276 raeburn 9358: if (@differences > 0) {
9359: if (@newnotified > 0) {
9360: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
9361: } else {
9362: $changes{'internal.selfenroll_notifylist'} = '';
9363: }
9364: }
9365: }
1.237 raeburn 9366: } else {
1.398 raeburn 9367: my $curr_val = $currsettings->{'selfenroll_'.$item};
1.237 raeburn 9368: my $newval = $env{'form.selfenroll_'.$item};
9369: if ($item eq 'section') {
9370: $newval = $env{'form.sections'};
1.241 raeburn 9371: if (defined($curr_groups{$newval})) {
1.237 raeburn 9372: $newval = $curr_val;
1.398 raeburn 9373: $warning{$item} = &mt('Section for self-enrolled users unchanged as the proposed section is a group').'<br />'.
9374: &mt('Group names and section names must be distinct');
1.237 raeburn 9375: } elsif ($newval eq 'all') {
9376: $newval = $curr_val;
1.274 bisitz 9377: $warning{$item} = &mt('Section for self-enrolled users unchanged, as "all" is a reserved section name.');
1.237 raeburn 9378: }
9379: if ($newval eq '') {
9380: $newval = 'none';
9381: }
9382: }
9383: if ($newval ne $curr_val) {
9384: $changes{'internal.selfenroll_'.$item} = $newval;
9385: }
1.241 raeburn 9386: }
1.237 raeburn 9387: }
9388: if (keys(%warning) > 0) {
9389: foreach my $item (@{$row}) {
9390: if (exists($warning{$item})) {
9391: $r->print($warning{$item}.'<br />');
9392: }
9393: }
9394: }
9395: if (keys(%changes) > 0) {
9396: my $putresult = &Apache::lonnet::put('environment',\%changes,$cdom,$cnum);
9397: if ($putresult eq 'ok') {
9398: if ((exists($changes{'internal.selfenroll_types'})) ||
9399: (exists($changes{'internal.selfenroll_start_date'})) ||
9400: (exists($changes{'internal.selfenroll_end_date'}))) {
9401: my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',
9402: $cnum,undef,undef,'Course');
9403: my $chome = &Apache::lonnet::homeserver($cnum,$cdom);
1.398 raeburn 9404: if (ref($crsinfo{$cid}) eq 'HASH') {
1.237 raeburn 9405: foreach my $item ('selfenroll_types','selfenroll_start_date','selfenroll_end_date') {
9406: if (exists($changes{'internal.'.$item})) {
1.398 raeburn 9407: $crsinfo{$cid}{$item} = $changes{'internal.'.$item};
1.237 raeburn 9408: }
9409: }
9410: my $crsputresult =
9411: &Apache::lonnet::courseidput($cdom,\%crsinfo,
9412: $chome,'notime');
9413: }
9414: }
9415: $r->print(&mt('The following changes were made to self-enrollment settings:').'<ul>');
9416: foreach my $item (@{$row}) {
9417: my $title = $item;
9418: if (ref($lt) eq 'HASH') {
9419: $title = $lt->{$item};
9420: }
9421: if ($item eq 'enroll_dates') {
9422: foreach my $type ('start','end') {
9423: if (exists($changes{'internal.selfenroll_'.$type.'_date'})) {
9424: my $newdate = &Apache::lonlocal::locallocaltime($changes{'internal.selfenroll_'.$type.'_date'});
1.244 bisitz 9425: $r->print('<li>'.&mt('[_1]: "[_2]" set to "[_3]".',
1.237 raeburn 9426: $title,$type,$newdate).'</li>');
9427: }
9428: }
9429: } elsif ($item eq 'access_dates') {
9430: foreach my $type ('start','end') {
9431: if (exists($changes{'internal.selfenroll_'.$type.'_access'})) {
9432: my $newdate = &Apache::lonlocal::locallocaltime($changes{'internal.selfenroll_'.$type.'_access'});
1.244 bisitz 9433: $r->print('<li>'.&mt('[_1]: "[_2]" set to "[_3]".',
1.237 raeburn 9434: $title,$type,$newdate).'</li>');
9435: }
9436: }
1.276 raeburn 9437: } elsif ($item eq 'limit') {
9438: if ((exists($changes{'internal.selfenroll_limit'})) ||
9439: (exists($changes{'internal.selfenroll_cap'}))) {
9440: my ($newval,$newcap);
9441: if ($changes{'internal.selfenroll_cap'} ne '') {
9442: $newcap = $changes{'internal.selfenroll_cap'}
9443: } else {
1.398 raeburn 9444: $newcap = $currsettings->{'selfenroll_cap'};
1.276 raeburn 9445: }
9446: if ($changes{'internal.selfenroll_limit'} eq 'none') {
9447: $newval = &mt('No limit');
9448: } elsif ($changes{'internal.selfenroll_limit'} eq
9449: 'allstudents') {
9450: $newval = &mt('New self-enrollment no longer allowed when total (all students) reaches [_1].',$newcap);
9451: } elsif ($changes{'internal.selfenroll_limit'} eq 'selfenrolled') {
9452: $newval = &mt('New self-enrollment no longer allowed when total number of self-enrolled students reaches [_1].',$newcap);
9453: } else {
1.398 raeburn 9454: my $currlimit = $currsettings->{'selfenroll_limit'};
1.276 raeburn 9455: if ($currlimit eq 'allstudents') {
9456: $newval = &mt('New self-enrollment no longer allowed when total (all students) reaches [_1].',$newcap);
9457: } elsif ($changes{'internal.selfenroll_limit'} eq 'selfenrolled') {
1.308 raeburn 9458: $newval = &mt('New self-enrollment no longer allowed when total number of self-enrolled students reaches [_1].',$newcap);
1.276 raeburn 9459: }
9460: }
9461: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval).'</li>'."\n");
9462: }
9463: } elsif ($item eq 'approval') {
9464: if ((exists($changes{'internal.selfenroll_approval'})) ||
9465: (exists($changes{'internal.selfenroll_notifylist'}))) {
1.398 raeburn 9466: my %selfdescs = &Apache::lonuserutils::selfenroll_default_descs();
1.276 raeburn 9467: my ($newval,$newnotify);
9468: if (exists($changes{'internal.selfenroll_notifylist'})) {
9469: $newnotify = $changes{'internal.selfenroll_notifylist'};
9470: } else {
1.398 raeburn 9471: $newnotify = $currsettings->{'selfenroll_notifylist'};
1.276 raeburn 9472: }
1.398 raeburn 9473: if (exists($changes{'internal.selfenroll_approval'})) {
9474: if ($changes{'internal.selfenroll_approval'} !~ /^[012]$/) {
9475: $changes{'internal.selfenroll_approval'} = '0';
9476: }
9477: $newval = $selfdescs{'approval'}{$changes{'internal.selfenroll_approval'}};
1.276 raeburn 9478: } else {
1.398 raeburn 9479: my $currapproval = $currsettings->{'selfenroll_approval'};
9480: if ($currapproval !~ /^[012]$/) {
9481: $currapproval = 0;
1.276 raeburn 9482: }
1.398 raeburn 9483: $newval = $selfdescs{'approval'}{$currapproval};
1.276 raeburn 9484: }
9485: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval));
9486: if ($newnotify) {
1.277 raeburn 9487: $r->print('<br />'.&mt('The following will be notified when an enrollment request needs approval, or has been approved: [_1].',$newnotify));
1.276 raeburn 9488: } else {
1.277 raeburn 9489: $r->print('<br />'.&mt('No notifications sent when an enrollment request needs approval, or has been approved.'));
1.276 raeburn 9490: }
9491: $r->print('</li>'."\n");
9492: }
1.237 raeburn 9493: } else {
9494: if (exists($changes{'internal.selfenroll_'.$item})) {
1.241 raeburn 9495: my $newval = $changes{'internal.selfenroll_'.$item};
9496: if ($item eq 'types') {
9497: if ($newval eq '') {
9498: $newval = &mt('None');
9499: } elsif ($newval eq '*') {
9500: $newval = &mt('Any user in any domain');
9501: }
1.245 raeburn 9502: } elsif ($item eq 'registered') {
9503: if ($newval eq '1') {
9504: $newval = &mt('Yes');
9505: } elsif ($newval eq '0') {
9506: $newval = &mt('No');
9507: }
1.241 raeburn 9508: }
1.244 bisitz 9509: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval).'</li>'."\n");
1.237 raeburn 9510: }
9511: }
9512: }
9513: $r->print('</ul>');
1.398 raeburn 9514: if ($env{'course.'.$cid.'.description'} ne '') {
9515: my %newenvhash;
9516: foreach my $key (keys(%changes)) {
9517: $newenvhash{'course.'.$cid.'.'.$key} = $changes{$key};
9518: }
9519: &Apache::lonnet::appenv(\%newenvhash);
1.237 raeburn 9520: }
9521: } else {
1.398 raeburn 9522: $r->print(&mt('An error occurred when saving changes to self-enrollment settings in this course.').'<br />'.
9523: &mt('The error was: [_1].',$putresult));
1.237 raeburn 9524: }
9525: } else {
1.249 raeburn 9526: $r->print(&mt('No changes were made to the existing self-enrollment settings in this course.'));
1.237 raeburn 9527: }
9528: } else {
1.249 raeburn 9529: $r->print(&mt('No changes were made to the existing self-enrollment settings in this course.'));
1.241 raeburn 9530: }
1.400 raeburn 9531: my $visactions = &cat_visibility();
9532: my ($cathash,%cattype);
9533: my %domconfig = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom);
9534: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
9535: $cathash = $domconfig{'coursecategories'}{'cats'};
9536: $cattype{'auth'} = $domconfig{'coursecategories'}{'auth'};
9537: $cattype{'unauth'} = $domconfig{'coursecategories'}{'unauth'};
9538: } else {
9539: $cathash = {};
9540: $cattype{'auth'} = 'std';
9541: $cattype{'unauth'} = 'std';
9542: }
9543: if (($cattype{'auth'} eq 'none') && ($cattype{'unauth'} eq 'none')) {
9544: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
9545: '<br />'.
9546: '<br />'.$visactions->{'take'}.'<ul>'.
9547: '<li>'.$visactions->{'dc_chgconf'}.'</li>'.
9548: '</ul>');
9549: } elsif (($cattype{'auth'} !~ /^(std|domonly)$/) && ($cattype{'unauth'} !~ /^(std|domonly)$/)) {
9550: if ($currsettings->{'uniquecode'}) {
9551: $r->print('<span class="LC_info">'.$visactions->{'vis'}.'</span>');
9552: } else {
1.366 bisitz 9553: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
1.400 raeburn 9554: '<br />'.
9555: '<br />'.$visactions->{'take'}.'<ul>'.
9556: '<li>'.$visactions->{'dc_setcode'}.'</li>'.
9557: '</ul><br />');
9558: }
9559: } else {
9560: my ($visible,$cansetvis,$vismsgs) = &visible_in_stdcat($cdom,$cnum,\%domconfig);
9561: if (ref($visactions) eq 'HASH') {
9562: if (!$visible) {
9563: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
9564: '<br />');
9565: if (ref($vismsgs) eq 'ARRAY') {
9566: $r->print('<br />'.$visactions->{'take'}.'<ul>');
9567: foreach my $item (@{$vismsgs}) {
9568: $r->print('<li>'.$visactions->{$item}.'</li>');
9569: }
9570: $r->print('</ul>');
1.256 raeburn 9571: }
1.400 raeburn 9572: $r->print($cansetvis);
1.256 raeburn 9573: }
9574: }
9575: }
1.237 raeburn 9576: return;
9577: }
9578:
1.27 matthew 9579: #---------------------------------------------- end functions for &phase_two
1.29 matthew 9580:
9581: #--------------------------------- functions for &phase_two and &phase_three
9582:
9583: #--------------------------end of functions for &phase_two and &phase_three
1.372 raeburn 9584:
1.1 www 9585: 1;
9586: __END__
1.2 www 9587:
9588:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>