Annotation of loncom/interface/loncreateuser.pm, revision 1.424
1.20 harris41 1: # The LearningOnline Network with CAPA
1.1 www 2: # Create a user
3: #
1.424 ! raeburn 4: # $Id: loncreateuser.pm,v 1.423 2016/11/13 21:09:56 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.414 raeburn 539: sub domadhocroles {
540: my ($ccuname,$ccdomain) = @_;
1.417 raeburn 541: my $confname = &Apache::lonnet::get_domainconfiguser($env{'request.role.domain'});
1.414 raeburn 542: my %existing=&Apache::lonnet::dump('roles',$env{'request.role.domain'},
543: $confname,'rolesdef_');
1.418 raeburn 544: my ($output,$canmodify);
545: if (&Apache::lonnet::allowed('cdh',$env{'request.role.domain'})) {
546: $canmodify = 1;
547: }
1.414 raeburn 548: if (keys(%existing) > 0) {
549: my @current;
1.417 raeburn 550: my $curradhoc = 'adhocroles.'.$env{'request.role.domain'};
1.414 raeburn 551: my %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,$curradhoc);
552: if ($userenv{$curradhoc}) {
553: @current = split(/,/,$userenv{$curradhoc});
554: }
1.418 raeburn 555: if (!$canmodify && !@current) {
556: return;
557: }
1.414 raeburn 558: my %customroles;
559: foreach my $key (keys(%existing)) {
560: if ($key=~/^rolesdef\_(\w+)$/) {
561: my $rolename = $1;
562: my %privs;
563: ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
564: $customroles{$rolename} = \%privs;
565: }
566: }
567: $output = '<br /><h3>'.
568: &mt('Ad Hoc Course Roles Selectable via Helpdesk Role').
569: '</h3>'."\n".
570: &Apache::loncommon::start_data_table().
1.418 raeburn 571: &Apache::loncommon::start_data_table_header_row();
572: if ($canmodify) {
573: $output .= '<th>'.&mt('Action').'</th>';
574: }
575: $output .= '<th>'.&mt('Role').'</th>'.
576: '<th>'.&mt('Privileges in Course').'<th>'.
577: &Apache::loncommon::end_data_table_header_row();
1.414 raeburn 578: foreach my $key (sort(keys(%customroles))) {
1.418 raeburn 579: next if ((!$canmodify) && (!grep(/^\Q$key\E$/,@current)));
1.414 raeburn 580: $output .= &Apache::loncommon::start_data_table_row();
1.418 raeburn 581: if ($canmodify) {
582: if (grep(/^\Q$key\E$/,@current)) {
583: $output .= '<td><label>'.
584: '<input type="checkbox" name="adhocroledel" value="'.$key.'" />'.
585: &mt('Delete').'</label>'.
586: '</td>';
587: } else {
588: $output .= '<td><label>'.
589: '<input type="checkbox" name="adhocroleadd" value="'.$key.'" />'.
590: &mt('Add').'</label>'.
591: '</td>';
592: }
1.414 raeburn 593: }
594: $output .= '<td>'.$key.'</td><td>';
595: foreach my $level ('course','domain','system') {
596: if ($customroles{$key}{$level}) {
597: my $suffix;
598: if (($level eq 'domain') || ($level eq 'system')) {
599: $suffix = ' ('.&mt($level).')';
600: }
601: my @privs = split(/:/,$customroles{$key}{$level});
602: foreach my $item (@privs) {
1.417 raeburn 603: next if ($item eq '');
1.414 raeburn 604: my ($priv,$cond) = split(/\&/,$item);
605: $output .= &Apache::lonnet::plaintext($priv,'Course').$suffix.'<br />';
606: }
607: }
608: }
609: $output .= '</td>'.
610: &Apache::loncommon::end_data_table_row();
611: }
612: $output .= &Apache::loncommon::end_data_table();
613: }
614: return $output;
615: }
616:
1.306 raeburn 617: sub courserequest_titles {
618: my %titles = &Apache::lonlocal::texthash (
619: official => 'Official',
620: unofficial => 'Unofficial',
621: community => 'Communities',
1.384 raeburn 622: textbook => 'Textbook',
1.411 raeburn 623: placement => 'Placement Tests',
1.306 raeburn 624: norequest => 'Not allowed',
1.309 raeburn 625: approval => 'Approval by Dom. Coord.',
1.306 raeburn 626: validate => 'With validation',
627: autolimit => 'Numerical limit',
1.314 raeburn 628: unlimited => '(blank for unlimited)',
1.306 raeburn 629: );
630: return %titles;
631: }
632:
633: sub courserequest_display {
634: my %titles = &Apache::lonlocal::texthash (
1.309 raeburn 635: approval => 'Yes, need approval',
1.306 raeburn 636: validate => 'Yes, with validation',
637: norequest => 'No',
638: );
639: return %titles;
640: }
641:
1.362 raeburn 642: sub requestauthor_titles {
643: my %titles = &Apache::lonlocal::texthash (
644: norequest => 'Not allowed',
645: approval => 'Approval by Dom. Coord.',
646: automatic => 'Automatic approval',
647: );
648: return %titles;
649:
650: }
651:
652: sub requestauthor_display {
653: my %titles = &Apache::lonlocal::texthash (
654: approval => 'Yes, need approval',
655: automatic => 'Yes, automatic approval',
656: norequest => 'No',
657: );
658: return %titles;
659: }
660:
1.383 raeburn 661: sub requestchange_display {
662: my %titles = &Apache::lonlocal::texthash (
663: approval => "availability set to 'on' (approval required)",
664: automatic => "availability set to 'on' (automatic approval)",
665: norequest => "availability set to 'off'",
666: );
667: return %titles;
668: }
669:
1.362 raeburn 670: sub curr_requestauthor {
671: my ($uname,$udom,$isadv,$inststatuses,$domconfig) = @_;
672: return unless ((ref($inststatuses) eq 'ARRAY') && (ref($domconfig) eq 'HASH'));
673: if ($uname eq '' || $udom eq '') {
674: $uname = $env{'user.name'};
675: $udom = $env{'user.domain'};
676: $isadv = $env{'user.adv'};
677: }
678: my (%userenv,%settings,$val);
679: my @options = ('automatic','approval');
680: %userenv =
681: &Apache::lonnet::userenvironment($udom,$uname,'requestauthor','inststatus');
682: if ($userenv{'requestauthor'}) {
683: $val = $userenv{'requestauthor'};
684: @{$inststatuses} = ('_custom_');
685: } else {
686: my %alltasks;
687: if (ref($domconfig->{'requestauthor'}) eq 'HASH') {
688: %settings = %{$domconfig->{'requestauthor'}};
689: if (($isadv) && ($settings{'_LC_adv'} ne '')) {
690: $val = $settings{'_LC_adv'};
691: @{$inststatuses} = ('_LC_adv_');
692: } else {
693: if ($userenv{'inststatus'} ne '') {
694: @{$inststatuses} = split(',',$userenv{'inststatus'});
695: } else {
696: @{$inststatuses} = ('default');
697: }
698: foreach my $status (@{$inststatuses}) {
699: if (exists($settings{$status})) {
700: my $value = $settings{$status};
701: next unless ($value);
702: unless (exists($alltasks{$value})) {
703: if (ref($alltasks{$value}) eq 'ARRAY') {
704: unless(grep(/^\Q$status\E$/,@{$alltasks{$value}})) {
705: push(@{$alltasks{$value}},$status);
706: }
707: } else {
708: @{$alltasks{$value}} = ($status);
709: }
710: }
711: }
712: }
713: foreach my $option (@options) {
714: if ($alltasks{$option}) {
715: $val = $option;
716: last;
717: }
718: }
719: }
720: }
721: }
722: return $val;
723: }
724:
1.2 www 725: # =================================================================== Phase one
1.1 www 726:
1.42 matthew 727: sub print_username_entry_form {
1.351 raeburn 728: my ($r,$context,$response,$srch,$forcenewuser,$crstype,$brcrum) = @_;
1.101 albertel 729: my $defdom=$env{'request.role.domain'};
1.160 raeburn 730: my $formtoset = 'crtuser';
731: if (exists($env{'form.startrolename'})) {
732: $formtoset = 'docustom';
733: $env{'form.rolename'} = $env{'form.startrolename'};
1.207 raeburn 734: } elsif ($env{'form.origform'} eq 'crtusername') {
735: $formtoset = $env{'form.origform'};
1.160 raeburn 736: }
737:
738: my ($jsback,$elements) = &crumb_utilities();
739:
740: my $jscript = &Apache::loncommon::studentbrowser_javascript()."\n".
1.165 albertel 741: '<script type="text/javascript">'."\n".
1.301 bisitz 742: '// <![CDATA['."\n".
743: &Apache::lonhtmlcommon::set_form_elements($elements->{$formtoset})."\n".
744: '// ]]>'."\n".
1.162 raeburn 745: '</script>'."\n";
1.160 raeburn 746:
1.324 raeburn 747: my %existingroles=&Apache::lonuserutils::my_custom_roles($crstype);
748: if (($env{'form.action'} eq 'custom') && (keys(%existingroles) > 0)
749: && (&Apache::lonnet::allowed('mcr','/'))) {
750: $jscript .= &customrole_javascript();
751: }
1.224 raeburn 752: my $helpitem = 'Course_Change_Privileges';
753: if ($env{'form.action'} eq 'custom') {
754: $helpitem = 'Course_Editing_Custom_Roles';
755: } elsif ($env{'form.action'} eq 'singlestudent') {
756: $helpitem = 'Course_Add_Student';
1.416 raeburn 757: } elsif ($env{'form.action'} eq 'accesslogs') {
758: $helpitem = 'Domain_User_Access_Logs';
1.224 raeburn 759: }
1.422 raeburn 760: my %breadcrumb_text = &singleuser_breadcrumb($crstype,$context,$defdom);
1.351 raeburn 761: if ($env{'form.action'} eq 'custom') {
762: push(@{$brcrum},
763: {href=>"javascript:backPage(document.crtuser)",
764: text=>"Pick custom role",
765: help => $helpitem,}
766: );
767: } else {
768: push (@{$brcrum},
769: {href => "javascript:backPage(document.crtuser)",
770: text => $breadcrumb_text{'search'},
771: help => $helpitem,
772: faq => 282,
773: bug => 'Instructor Interface',}
774: );
775: }
776: my %loaditems = (
777: 'onload' => "javascript:setFormElements(document.$formtoset)",
778: );
779: my $args = {bread_crumbs => $brcrum,
780: bread_crumbs_component => 'User Management',
781: add_entries => \%loaditems,};
782: $r->print(&Apache::loncommon::start_page('User Management',$jscript,$args));
783:
1.71 sakharuk 784: my %lt=&Apache::lonlocal::texthash(
1.229 raeburn 785: 'srst' => 'Search for a user and enroll as a student',
1.318 raeburn 786: 'srme' => 'Search for a user and enroll as a member',
1.229 raeburn 787: 'srad' => 'Search for a user and modify/add user information or roles',
1.422 raeburn 788: 'srvu' => 'Search for a user and view user information and roles',
1.416 raeburn 789: 'srva' => 'Search for a user and view access log information',
1.71 sakharuk 790: 'usr' => "Username",
791: 'dom' => "Domain",
1.324 raeburn 792: 'ecrp' => "Define or Edit Custom Role",
793: 'nr' => "role name",
1.282 schafran 794: 'cre' => "Next",
1.71 sakharuk 795: );
1.351 raeburn 796:
1.214 raeburn 797: if ($env{'form.action'} eq 'custom') {
1.190 raeburn 798: if (&Apache::lonnet::allowed('mcr','/')) {
1.324 raeburn 799: my $newroletext = &mt('Define new custom role:');
800: $r->print('<form action="/adm/createuser" method="post" name="docustom">'.
801: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'.
802: '<input type="hidden" name="phase" value="selected_custom_edit" />'.
803: '<h3>'.$lt{'ecrp'}.'</h3>'.
804: &Apache::loncommon::start_data_table().
805: &Apache::loncommon::start_data_table_row().
806: '<td>');
807: if (keys(%existingroles) > 0) {
808: $r->print('<br /><label><input type="radio" name="customroleaction" value="new" checked="checked" onclick="setCustomFields();" /><b>'.$newroletext.'</b></label>');
809: } else {
810: $r->print('<br /><input type="hidden" name="customroleaction" value="new" /><b>'.$newroletext.'</b>');
811: }
812: $r->print('</td><td align="center">'.$lt{'nr'}.'<br /><input type="text" size="15" name="newrolename" onfocus="setCustomAction('."'new'".');" /></td>'.
813: &Apache::loncommon::end_data_table_row());
814: if (keys(%existingroles) > 0) {
815: $r->print(&Apache::loncommon::start_data_table_row().'<td><br />'.
816: '<label><input type="radio" name="customroleaction" value="edit" onclick="setCustomFields();"/><b>'.
817: &mt('View/Modify existing role:').'</b></label></td>'.
818: '<td align="center"><br />'.
819: '<select name="rolename" onchange="setCustomAction('."'edit'".');">'.
1.326 raeburn 820: '<option value="" selected="selected">'.
1.324 raeburn 821: &mt('Select'));
822: foreach my $role (sort(keys(%existingroles))) {
1.326 raeburn 823: $r->print('<option value="'.$role.'">'.$role.'</option>');
1.324 raeburn 824: }
825: $r->print('</select>'.
826: '</td>'.
827: &Apache::loncommon::end_data_table_row());
828: }
829: $r->print(&Apache::loncommon::end_data_table().'<p>'.
830: '<input name="customeditor" type="submit" value="'.
831: $lt{'cre'}.'" /></p>'.
832: '</form>');
1.190 raeburn 833: }
1.213 raeburn 834: } else {
1.229 raeburn 835: my $actiontext = $lt{'srad'};
1.213 raeburn 836: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 837: if ($crstype eq 'Community') {
838: $actiontext = $lt{'srme'};
839: } else {
840: $actiontext = $lt{'srst'};
841: }
1.416 raeburn 842: } elsif ($env{'form.action'} eq 'accesslogs') {
1.417 raeburn 843: $actiontext = $lt{'srva'};
1.422 raeburn 844: } elsif (($env{'form.action'} eq 'singleuser') &&
845: ($context eq 'domain') && (!&Apache::lonnet::allowed('mau',$defdom))) {
846: $actiontext = $lt{'srvu'};
1.213 raeburn 847: }
1.324 raeburn 848: $r->print("<h3>$actiontext</h3>");
1.213 raeburn 849: if ($env{'form.origform'} ne 'crtusername') {
1.415 raeburn 850: if ($response) {
851: $r->print("\n<div>$response</div>".
852: '<br clear="all" />');
853: }
1.213 raeburn 854: }
1.416 raeburn 855: $r->print(&entry_form($defdom,$srch,$forcenewuser,$context,$response,$crstype,1));
1.107 www 856: }
1.110 albertel 857: }
858:
1.324 raeburn 859: sub customrole_javascript {
860: my $js = <<"END";
861: <script type="text/javascript">
862: // <![CDATA[
863:
864: function setCustomFields() {
865: if (document.docustom.customroleaction.length > 0) {
866: for (var i=0; i<document.docustom.customroleaction.length; i++) {
867: if (document.docustom.customroleaction[i].checked) {
868: if (document.docustom.customroleaction[i].value == 'new') {
869: document.docustom.rolename.selectedIndex = 0;
870: } else {
871: document.docustom.newrolename.value = '';
872: }
873: }
874: }
875: }
876: return;
877: }
878:
879: function setCustomAction(caller) {
880: if (document.docustom.customroleaction.length > 0) {
881: for (var i=0; i<document.docustom.customroleaction.length; i++) {
882: if (document.docustom.customroleaction[i].value == caller) {
883: document.docustom.customroleaction[i].checked = true;
884: }
885: }
886: }
887: setCustomFields();
888: return;
889: }
890:
891: // ]]>
892: </script>
893: END
894: return $js;
895: }
896:
1.160 raeburn 897: sub entry_form {
1.416 raeburn 898: my ($dom,$srch,$forcenewuser,$context,$responsemsg,$crstype,$fixeddom) = @_;
1.229 raeburn 899: my ($usertype,$inexact);
1.214 raeburn 900: if (ref($srch) eq 'HASH') {
901: if (($srch->{'srchin'} eq 'dom') &&
902: ($srch->{'srchby'} eq 'uname') &&
903: ($srch->{'srchtype'} eq 'exact') &&
904: ($srch->{'srchdomain'} ne '') &&
905: ($srch->{'srchterm'} ne '')) {
1.353 raeburn 906: my (%curr_rules,%got_rules);
1.214 raeburn 907: my ($rules,$ruleorder) =
908: &Apache::lonnet::inst_userrules($srch->{'srchdomain'},'username');
1.353 raeburn 909: $usertype = &Apache::lonuserutils::check_usertype($srch->{'srchdomain'},$srch->{'srchterm'},$rules,\%curr_rules,\%got_rules);
1.229 raeburn 910: } else {
911: $inexact = 1;
1.214 raeburn 912: }
1.207 raeburn 913: }
1.214 raeburn 914: my $cancreate =
915: &Apache::lonuserutils::can_create_user($dom,$context,$usertype);
1.412 raeburn 916: my ($userpicker,$cansearch) =
1.179 raeburn 917: &Apache::loncommon::user_picker($dom,$srch,$forcenewuser,
1.416 raeburn 918: 'document.crtuser',$cancreate,$usertype,$context,$fixeddom);
1.160 raeburn 919: my $srchbutton = &mt('Search');
1.229 raeburn 920: if ($env{'form.action'} eq 'singlestudent') {
921: $srchbutton = &mt('Search and Enroll');
1.416 raeburn 922: } elsif ($env{'form.action'} eq 'accesslogs') {
923: $srchbutton = &mt('Search');
1.229 raeburn 924: } elsif ($cancreate && $responsemsg ne '' && $inexact) {
925: $srchbutton = &mt('Search or Add New User');
926: }
1.412 raeburn 927: my $output;
928: if ($cansearch) {
929: $output = <<"ENDBLOCK";
1.160 raeburn 930: <form action="/adm/createuser" method="post" name="crtuser">
1.190 raeburn 931: <input type="hidden" name="action" value="$env{'form.action'}" />
1.160 raeburn 932: <input type="hidden" name="phase" value="get_user_info" />
933: $userpicker
1.179 raeburn 934: <input name="userrole" type="button" value="$srchbutton" onclick="javascript:validateEntry(document.crtuser)" />
1.160 raeburn 935: </form>
1.207 raeburn 936: ENDBLOCK
1.412 raeburn 937: } else {
938: $output = '<p>'.$userpicker.'</p>';
939: }
1.422 raeburn 940: if (($env{'form.phase'} eq '') && ($env{'form.action'} ne 'accesslogs') &&
941: (!(($env{'form.action'} eq 'singleuser') && ($context eq 'domain') &&
942: (!&Apache::lonnet::allowed('mau',$env{'request.role.domain'}))))) {
1.207 raeburn 943: my $defdom=$env{'request.role.domain'};
944: my $domform = &Apache::loncommon::select_dom_form($defdom,'srchdomain');
945: my %lt=&Apache::lonlocal::texthash(
1.229 raeburn 946: 'enro' => 'Enroll one student',
1.318 raeburn 947: 'enrm' => 'Enroll one member',
1.229 raeburn 948: 'admo' => 'Add/modify a single user',
949: 'crea' => 'create new user if required',
950: 'uskn' => "username is known",
1.207 raeburn 951: 'crnu' => 'Create a new user',
952: 'usr' => 'Username',
953: 'dom' => 'in domain',
1.229 raeburn 954: 'enrl' => 'Enroll',
955: 'cram' => 'Create/Modify user',
1.207 raeburn 956: );
1.229 raeburn 957: my $sellink=&Apache::loncommon::selectstudent_link('crtusername','srchterm','srchdomain');
958: my ($title,$buttontext,$showresponse);
1.318 raeburn 959: if ($env{'form.action'} eq 'singlestudent') {
960: if ($crstype eq 'Community') {
961: $title = $lt{'enrm'};
962: } else {
963: $title = $lt{'enro'};
964: }
1.229 raeburn 965: $buttontext = $lt{'enrl'};
966: } else {
967: $title = $lt{'admo'};
968: $buttontext = $lt{'cram'};
969: }
970: if ($cancreate) {
971: $title .= ' <span class="LC_cusr_subheading">('.$lt{'crea'}.')</span>';
972: } else {
973: $title .= ' <span class="LC_cusr_subheading">('.$lt{'uskn'}.')</span>';
974: }
975: if ($env{'form.origform'} eq 'crtusername') {
976: $showresponse = $responsemsg;
977: }
1.207 raeburn 978: $output .= <<"ENDDOCUMENT";
1.229 raeburn 979: <br />
1.207 raeburn 980: <form action="/adm/createuser" method="post" name="crtusername">
981: <input type="hidden" name="action" value="$env{'form.action'}" />
982: <input type="hidden" name="phase" value="createnewuser" />
983: <input type="hidden" name="srchtype" value="exact" />
1.233 raeburn 984: <input type="hidden" name="srchby" value="uname" />
1.207 raeburn 985: <input type="hidden" name="srchin" value="dom" />
986: <input type="hidden" name="forcenewuser" value="1" />
987: <input type="hidden" name="origform" value="crtusername" />
1.229 raeburn 988: <h3>$title</h3>
989: $showresponse
1.207 raeburn 990: <table>
991: <tr>
992: <td>$lt{'usr'}:</td>
993: <td><input type="text" size="15" name="srchterm" /></td>
994: <td> $lt{'dom'}:</td><td>$domform</td>
1.229 raeburn 995: <td> $sellink </td>
996: <td> <input name="userrole" type="submit" value="$buttontext" /></td>
1.207 raeburn 997: </tr>
998: </table>
999: </form>
1.160 raeburn 1000: ENDDOCUMENT
1.207 raeburn 1001: }
1.160 raeburn 1002: return $output;
1003: }
1.110 albertel 1004:
1005: sub user_modification_js {
1.113 raeburn 1006: my ($pjump_def,$dc_setcourse_code,$nondc_setsection_code,$groupslist)=@_;
1007:
1.110 albertel 1008: return <<END;
1009: <script type="text/javascript" language="Javascript">
1.301 bisitz 1010: // <![CDATA[
1.314 raeburn 1011:
1.110 albertel 1012: $pjump_def
1013: $dc_setcourse_code
1014:
1015: function dateset() {
1016: eval("document.cu."+document.cu.pres_marker.value+
1017: ".value=document.cu.pres_value.value");
1.359 www 1018: modalWindow.close();
1.110 albertel 1019: }
1020:
1.113 raeburn 1021: $nondc_setsection_code
1.301 bisitz 1022: // ]]>
1.110 albertel 1023: </script>
1024: END
1.2 www 1025: }
1026:
1027: # =================================================================== Phase two
1.160 raeburn 1028: sub print_user_selection_page {
1.351 raeburn 1029: my ($r,$response,$srch,$srch_results,$srcharray,$context,$opener_elements,$crstype,$brcrum) = @_;
1.160 raeburn 1030: my @fields = ('username','domain','lastname','firstname','permanentemail');
1031: my $sortby = $env{'form.sortby'};
1032:
1033: if (!grep(/^\Q$sortby\E$/,@fields)) {
1034: $sortby = 'lastname';
1035: }
1036:
1037: my ($jsback,$elements) = &crumb_utilities();
1038:
1039: my $jscript = (<<ENDSCRIPT);
1040: <script type="text/javascript">
1.301 bisitz 1041: // <![CDATA[
1.160 raeburn 1042: function pickuser(uname,udom) {
1043: document.usersrchform.seluname.value=uname;
1044: document.usersrchform.seludom.value=udom;
1045: document.usersrchform.phase.value="userpicked";
1046: document.usersrchform.submit();
1047: }
1048:
1049: $jsback
1.301 bisitz 1050: // ]]>
1.160 raeburn 1051: </script>
1052: ENDSCRIPT
1053:
1054: my %lt=&Apache::lonlocal::texthash(
1.179 raeburn 1055: 'usrch' => "User Search to add/modify roles",
1056: 'stusrch' => "User Search to enroll student",
1.318 raeburn 1057: 'memsrch' => "User Search to enroll member",
1.416 raeburn 1058: 'srcva' => "Search for a user and view access log information",
1.422 raeburn 1059: 'usrvu' => "User Search to view user roles",
1.179 raeburn 1060: 'usel' => "Select a user to add/modify roles",
1.422 raeburn 1061: 'suvr' => "Select a user to view roles",
1.318 raeburn 1062: 'stusel' => "Select a user to enroll as a student",
1063: 'memsel' => "Select a user to enroll as a member",
1.416 raeburn 1064: 'vacsel' => "Select a user to view access log",
1.160 raeburn 1065: 'username' => "username",
1066: 'domain' => "domain",
1067: 'lastname' => "last name",
1068: 'firstname' => "first name",
1069: 'permanentemail' => "permanent e-mail",
1070: );
1.302 raeburn 1071: if ($context eq 'requestcrs') {
1072: $r->print('<div>');
1073: } else {
1.422 raeburn 1074: my %breadcrumb_text = &singleuser_breadcrumb($crstype,$context,$srch->{'srchdomain'});
1.351 raeburn 1075: my $helpitem;
1076: if ($env{'form.action'} eq 'singleuser') {
1077: $helpitem = 'Course_Change_Privileges';
1078: } elsif ($env{'form.action'} eq 'singlestudent') {
1079: $helpitem = 'Course_Add_Student';
1080: }
1081: push (@{$brcrum},
1082: {href => "javascript:backPage(document.usersrchform,'','')",
1083: text => $breadcrumb_text{'search'},
1084: faq => 282,
1085: bug => 'Instructor Interface',},
1086: {href => "javascript:backPage(document.usersrchform,'get_user_info','select')",
1087: text => $breadcrumb_text{'userpicked'},
1088: faq => 282,
1089: bug => 'Instructor Interface',
1090: help => $helpitem}
1091: );
1092: $r->print(&Apache::loncommon::start_page('User Management',$jscript,{bread_crumbs => $brcrum}));
1.302 raeburn 1093: if ($env{'form.action'} eq 'singleuser') {
1.422 raeburn 1094: my $readonly;
1095: if (($context eq 'domain') && (!&Apache::lonnet::allowed('mau',$srch->{'srchdomain'}))) {
1096: $readonly = 1;
1097: $r->print("<b>$lt{'usrvu'}</b><br />");
1098: } else {
1099: $r->print("<b>$lt{'usrch'}</b><br />");
1100: }
1.318 raeburn 1101: $r->print(&entry_form($srch->{'srchdomain'},$srch,undef,$context,undef,$crstype));
1.422 raeburn 1102: if ($readonly) {
1103: $r->print('<h3>'.$lt{'suvr'}.'</h3>');
1104: } else {
1105: $r->print('<h3>'.$lt{'usel'}.'</h3>');
1106: }
1.302 raeburn 1107: } elsif ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1108: $r->print($jscript."<b>");
1109: if ($crstype eq 'Community') {
1110: $r->print($lt{'memsrch'});
1111: } else {
1112: $r->print($lt{'stusrch'});
1113: }
1114: $r->print("</b><br />");
1115: $r->print(&entry_form($srch->{'srchdomain'},$srch,undef,$context,undef,$crstype));
1116: $r->print('</form><h3>');
1117: if ($crstype eq 'Community') {
1118: $r->print($lt{'memsel'});
1119: } else {
1120: $r->print($lt{'stusel'});
1121: }
1122: $r->print('</h3>');
1.416 raeburn 1123: } elsif ($env{'form.action'} eq 'accesslogs') {
1124: $r->print("<b>$lt{'srcva'}</b><br />");
1125: $r->print(&entry_form($srch->{'srchdomain'},$srch,undef,'accesslogs',undef,undef,1));
1126: $r->print('<h3>'.$lt{'vacsel'}.'</h3>');
1.302 raeburn 1127: }
1.179 raeburn 1128: }
1.380 bisitz 1129: $r->print('<form name="usersrchform" method="post" action="">'.
1.160 raeburn 1130: &Apache::loncommon::start_data_table()."\n".
1131: &Apache::loncommon::start_data_table_header_row()."\n".
1132: ' <th> </th>'."\n");
1133: foreach my $field (@fields) {
1134: $r->print(' <th><a href="javascript:document.usersrchform.sortby.value='.
1135: "'".$field."'".';document.usersrchform.submit();">'.
1136: $lt{$field}.'</a></th>'."\n");
1137: }
1138: $r->print(&Apache::loncommon::end_data_table_header_row());
1139:
1140: my @sorted_users = sort {
1.167 albertel 1141: lc($srch_results->{$a}->{$sortby}) cmp lc($srch_results->{$b}->{$sortby})
1.160 raeburn 1142: ||
1.167 albertel 1143: lc($srch_results->{$a}->{lastname}) cmp lc($srch_results->{$b}->{lastname})
1.160 raeburn 1144: ||
1145: lc($srch_results->{$a}->{firstname}) cmp lc($srch_results->{$b}->{firstname})
1.167 albertel 1146: ||
1147: lc($a) cmp lc($b)
1.160 raeburn 1148: } (keys(%$srch_results));
1149:
1150: foreach my $user (@sorted_users) {
1151: my ($uname,$udom) = split(/:/,$user);
1.302 raeburn 1152: my $onclick;
1153: if ($context eq 'requestcrs') {
1.314 raeburn 1154: $onclick =
1.302 raeburn 1155: 'onclick="javascript:gochoose('."'$uname','$udom',".
1156: "'$srch_results->{$user}->{firstname}',".
1157: "'$srch_results->{$user}->{lastname}',".
1158: "'$srch_results->{$user}->{permanentemail}'".');"';
1159: } else {
1.314 raeburn 1160: $onclick =
1.302 raeburn 1161: ' onclick="javascript:pickuser('."'".$uname."'".','."'".$udom."'".');"';
1162: }
1.160 raeburn 1163: $r->print(&Apache::loncommon::start_data_table_row().
1.302 raeburn 1164: '<td><input type="button" name="seluser" value="'.&mt('Select').'" '.
1165: $onclick.' /></td>'.
1.160 raeburn 1166: '<td><tt>'.$uname.'</tt></td>'.
1167: '<td><tt>'.$udom.'</tt></td>');
1168: foreach my $field ('lastname','firstname','permanentemail') {
1169: $r->print('<td>'.$srch_results->{$user}->{$field}.'</td>');
1170: }
1171: $r->print(&Apache::loncommon::end_data_table_row());
1172: }
1173: $r->print(&Apache::loncommon::end_data_table().'<br /><br />');
1.179 raeburn 1174: if (ref($srcharray) eq 'ARRAY') {
1175: foreach my $item (@{$srcharray}) {
1176: $r->print('<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n");
1177: }
1178: }
1.160 raeburn 1179: $r->print(' <input type="hidden" name="sortby" value="'.$sortby.'" />'."\n".
1180: ' <input type="hidden" name="seluname" value="" />'."\n".
1181: ' <input type="hidden" name="seludom" value="" />'."\n".
1.179 raeburn 1182: ' <input type="hidden" name="currstate" value="select" />'."\n".
1.190 raeburn 1183: ' <input type="hidden" name="phase" value="get_user_info" />'."\n".
1.214 raeburn 1184: ' <input type="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n");
1.302 raeburn 1185: if ($context eq 'requestcrs') {
1186: $r->print($opener_elements.'</form></div>');
1187: } else {
1.351 raeburn 1188: $r->print($response.'</form>');
1.302 raeburn 1189: }
1.160 raeburn 1190: }
1191:
1192: sub print_user_query_page {
1.351 raeburn 1193: my ($r,$caller,$brcrum) = @_;
1.160 raeburn 1194: # FIXME - this is for a network-wide name search (similar to catalog search)
1195: # To use frames with similar behavior to catalog/portfolio search.
1196: # To be implemented.
1197: return;
1198: }
1199:
1.42 matthew 1200: sub print_user_modification_page {
1.375 raeburn 1201: my ($r,$ccuname,$ccdomain,$srch,$response,$context,$permission,$crstype,
1202: $brcrum,$showcredits) = @_;
1.185 raeburn 1203: if (($ccuname eq '') || ($ccdomain eq '')) {
1.215 raeburn 1204: my $usermsg = &mt('No username and/or domain provided.');
1205: $env{'form.phase'} = '';
1.351 raeburn 1206: &print_username_entry_form($r,$context,$usermsg,'','',$crstype,$brcrum);
1.58 www 1207: return;
1208: }
1.213 raeburn 1209: my ($form,$formname);
1210: if ($env{'form.action'} eq 'singlestudent') {
1211: $form = 'document.enrollstudent';
1212: $formname = 'enrollstudent';
1213: } else {
1214: $form = 'document.cu';
1215: $formname = 'cu';
1216: }
1.188 raeburn 1217: my %abv_auth = &auth_abbrev();
1.227 raeburn 1218: my (%rulematch,%inst_results,$newuser,%alerts,%curr_rules,%got_rules);
1.185 raeburn 1219: my $uhome=&Apache::lonnet::homeserver($ccuname,$ccdomain);
1220: if ($uhome eq 'no_host') {
1.215 raeburn 1221: my $usertype;
1222: my ($rules,$ruleorder) =
1223: &Apache::lonnet::inst_userrules($ccdomain,'username');
1224: $usertype =
1.353 raeburn 1225: &Apache::lonuserutils::check_usertype($ccdomain,$ccuname,$rules,
1.362 raeburn 1226: \%curr_rules,\%got_rules);
1.215 raeburn 1227: my $cancreate =
1228: &Apache::lonuserutils::can_create_user($ccdomain,$context,
1229: $usertype);
1230: if (!$cancreate) {
1.292 bisitz 1231: my $helplink = 'javascript:helpMenu('."'display'".')';
1.215 raeburn 1232: my %usertypetext = (
1233: official => 'institutional',
1234: unofficial => 'non-institutional',
1235: );
1236: my $response;
1237: if ($env{'form.origform'} eq 'crtusername') {
1.362 raeburn 1238: $response = '<span class="LC_warning">'.
1239: &mt('No match found for the username [_1] in LON-CAPA domain: [_2]',
1240: '<b>'.$ccuname.'</b>',$ccdomain).
1.215 raeburn 1241: '</span><br />';
1242: }
1.292 bisitz 1243: $response .= '<p class="LC_warning">'
1244: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
1.418 raeburn 1245: .' ';
1246: if ($context eq 'domain') {
1247: $response .= &mt('Please contact a [_1] for assistance.',
1248: &Apache::lonnet::plaintext('dc'));
1249: } else {
1250: $response .= &mt('Please contact the [_1]helpdesk[_2] for assistance.'
1251: ,'<a href="'.$helplink.'">','</a>');
1252: }
1253: $response .= '</p><br />';
1.215 raeburn 1254: $env{'form.phase'} = '';
1.351 raeburn 1255: &print_username_entry_form($r,$context,$response,undef,undef,$crstype,$brcrum);
1.215 raeburn 1256: return;
1257: }
1.188 raeburn 1258: $newuser = 1;
1.193 raeburn 1259: my $checkhash;
1260: my $checks = { 'username' => 1 };
1.196 raeburn 1261: $checkhash->{$ccuname.':'.$ccdomain} = { 'newuser' => $newuser };
1.193 raeburn 1262: &Apache::loncommon::user_rule_check($checkhash,$checks,
1.196 raeburn 1263: \%alerts,\%rulematch,\%inst_results,\%curr_rules,\%got_rules);
1264: if (ref($alerts{'username'}) eq 'HASH') {
1265: if (ref($alerts{'username'}{$ccdomain}) eq 'HASH') {
1266: my $domdesc =
1.193 raeburn 1267: &Apache::lonnet::domain($ccdomain,'description');
1.196 raeburn 1268: if ($alerts{'username'}{$ccdomain}{$ccuname}) {
1269: my $userchkmsg;
1270: if (ref($curr_rules{$ccdomain}) eq 'HASH') {
1271: $userchkmsg =
1272: &Apache::loncommon::instrule_disallow_msg('username',
1.193 raeburn 1273: $domdesc,1).
1274: &Apache::loncommon::user_rule_formats($ccdomain,
1275: $domdesc,$curr_rules{$ccdomain}{'username'},
1276: 'username');
1.196 raeburn 1277: }
1.215 raeburn 1278: $env{'form.phase'} = '';
1.351 raeburn 1279: &print_username_entry_form($r,$context,$userchkmsg,undef,undef,$crstype,$brcrum);
1.196 raeburn 1280: return;
1.215 raeburn 1281: }
1.193 raeburn 1282: }
1.185 raeburn 1283: }
1.187 raeburn 1284: } else {
1.188 raeburn 1285: $newuser = 0;
1.185 raeburn 1286: }
1.160 raeburn 1287: if ($response) {
1.215 raeburn 1288: $response = '<br />'.$response;
1.160 raeburn 1289: }
1.149 raeburn 1290:
1.52 matthew 1291: my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
1.88 raeburn 1292: my $dc_setcourse_code = '';
1.119 raeburn 1293: my $nondc_setsection_code = '';
1.112 albertel 1294: my %loaditem;
1.114 albertel 1295:
1.216 raeburn 1296: my $groupslist = &Apache::lonuserutils::get_groupslist();
1.88 raeburn 1297:
1.375 raeburn 1298: my $js = &validation_javascript($context,$ccdomain,$pjump_def,$crstype,
1.216 raeburn 1299: $groupslist,$newuser,$formname,\%loaditem);
1.422 raeburn 1300: my %breadcrumb_text = &singleuser_breadcrumb($crstype,$context,$ccdomain);
1.224 raeburn 1301: my $helpitem = 'Course_Change_Privileges';
1302: if ($env{'form.action'} eq 'singlestudent') {
1303: $helpitem = 'Course_Add_Student';
1304: }
1.351 raeburn 1305: push (@{$brcrum},
1306: {href => "javascript:backPage($form)",
1307: text => $breadcrumb_text{'search'},
1308: faq => 282,
1309: bug => 'Instructor Interface',});
1310: if ($env{'form.phase'} eq 'userpicked') {
1311: push(@{$brcrum},
1312: {href => "javascript:backPage($form,'get_user_info','select')",
1313: text => $breadcrumb_text{'userpicked'},
1314: faq => 282,
1315: bug => 'Instructor Interface',});
1316: }
1317: push(@{$brcrum},
1318: {href => "javascript:backPage($form,'$env{'form.phase'}','modify')",
1319: text => $breadcrumb_text{'modify'},
1320: faq => 282,
1321: bug => 'Instructor Interface',
1322: help => $helpitem});
1323: my $args = {'add_entries' => \%loaditem,
1324: 'bread_crumbs' => $brcrum,
1325: 'bread_crumbs_component' => 'User Management'};
1326: if ($env{'form.popup'}) {
1327: $args->{'no_nav_bar'} = 1;
1328: }
1329: my $start_page =
1330: &Apache::loncommon::start_page('User Management',$js,$args);
1.3 www 1331:
1.25 matthew 1332: my $forminfo =<<"ENDFORMINFO";
1.216 raeburn 1333: <form action="/adm/createuser" method="post" name="$formname">
1.190 raeburn 1334: <input type="hidden" name="phase" value="update_user_data" />
1.188 raeburn 1335: <input type="hidden" name="ccuname" value="$ccuname" />
1336: <input type="hidden" name="ccdomain" value="$ccdomain" />
1.157 albertel 1337: <input type="hidden" name="pres_value" value="" />
1338: <input type="hidden" name="pres_type" value="" />
1339: <input type="hidden" name="pres_marker" value="" />
1.25 matthew 1340: ENDFORMINFO
1.375 raeburn 1341: my (%inccourses,$roledom,$defaultcredits);
1.329 raeburn 1342: if ($context eq 'course') {
1343: $inccourses{$env{'request.course.id'}}=1;
1344: $roledom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1.375 raeburn 1345: if ($showcredits) {
1346: $defaultcredits = &Apache::lonuserutils::get_defaultcredits();
1347: }
1.329 raeburn 1348: } elsif ($context eq 'author') {
1349: $roledom = $env{'request.role.domain'};
1350: } elsif ($context eq 'domain') {
1351: foreach my $key (keys(%env)) {
1352: $roledom = $env{'request.role.domain'};
1353: if ($key=~/^user\.priv\.cm\.\/($roledom)\/($match_username)/) {
1354: $inccourses{$1.'_'.$2}=1;
1355: }
1356: }
1357: } else {
1358: foreach my $key (keys(%env)) {
1359: if ($key=~/^user\.priv\.cm\.\/($match_domain)\/($match_username)/) {
1360: $inccourses{$1.'_'.$2}=1;
1361: }
1.2 www 1362: }
1.24 matthew 1363: }
1.389 bisitz 1364: my $title = '';
1.216 raeburn 1365: if ($newuser) {
1.414 raeburn 1366: my ($portfolioform,$domroleform,$adhocroleform);
1.267 raeburn 1367: if ((&Apache::lonnet::allowed('mpq',$env{'request.role.domain'})) ||
1368: (&Apache::lonnet::allowed('mut',$env{'request.role.domain'}))) {
1369: # Current user has quota or user tools modification privileges
1.378 raeburn 1370: $portfolioform = '<br />'.&user_quotas($ccuname,$ccdomain);
1.134 raeburn 1371: }
1.383 raeburn 1372: if ((&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) &&
1373: ($ccdomain eq $env{'request.role.domain'})) {
1.362 raeburn 1374: $domroleform = '<br />'.&domainrole_req($ccuname,$ccdomain);
1375: }
1.414 raeburn 1376: if (&Apache::lonnet::allowed('cdh',$env{'request.role.domain'})) {
1377: $adhocroleform = &domadhocroles($ccuname,$ccdomain);
1378: if ($adhocroleform) {
1379: $adhocroleform = '<br />'.$adhocroleform;
1380: }
1381: }
1.227 raeburn 1382: &initialize_authen_forms($ccdomain,$formname);
1.188 raeburn 1383: my %lt=&Apache::lonlocal::texthash(
1384: 'lg' => 'Login Data',
1.190 raeburn 1385: 'hs' => "Home Server",
1.188 raeburn 1386: );
1.185 raeburn 1387: $r->print(<<ENDTITLE);
1.110 albertel 1388: $start_page
1.160 raeburn 1389: $response
1.25 matthew 1390: $forminfo
1.31 matthew 1391: <script type="text/javascript" language="Javascript">
1.301 bisitz 1392: // <![CDATA[
1.20 harris41 1393: $loginscript
1.301 bisitz 1394: // ]]>
1.31 matthew 1395: </script>
1.20 harris41 1396: <input type='hidden' name='makeuser' value='1' />
1.185 raeburn 1397: ENDTITLE
1.213 raeburn 1398: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1399: if ($crstype eq 'Community') {
1.389 bisitz 1400: $title = &mt('Create New User [_1] in domain [_2] as a member',
1401: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.318 raeburn 1402: } else {
1.389 bisitz 1403: $title = &mt('Create New User [_1] in domain [_2] as a student',
1404: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.318 raeburn 1405: }
1.389 bisitz 1406: } else {
1407: $title = &mt('Create New User [_1] in domain [_2]',
1408: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.213 raeburn 1409: }
1.389 bisitz 1410: $r->print('<h2>'.$title.'</h2>'."\n");
1411: $r->print('<div class="LC_left_float">');
1.393 raeburn 1412: $r->print(&personal_data_display($ccuname,$ccdomain,$newuser,$context,
1413: $inst_results{$ccuname.':'.$ccdomain}));
1414: # Option to disable student/employee ID conflict checking not offerred for new users.
1.187 raeburn 1415: my ($home_server_pick,$numlib) =
1416: &Apache::loncommon::home_server_form_item($ccdomain,'hserver',
1417: 'default','hide');
1418: if ($numlib > 1) {
1419: $r->print("
1.185 raeburn 1420: <br />
1.187 raeburn 1421: $lt{'hs'}: $home_server_pick
1422: <br />");
1423: } else {
1424: $r->print($home_server_pick);
1425: }
1.304 raeburn 1426: if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
1.362 raeburn 1427: $r->print('<br /><h3>'.
1428: &mt('User Can Request Creation of Courses/Communities in this Domain?').'</h3>'.
1.304 raeburn 1429: &Apache::loncommon::start_data_table().
1430: &build_tools_display($ccuname,$ccdomain,
1431: 'requestcourses').
1432: &Apache::loncommon::end_data_table());
1433: }
1.188 raeburn 1434: $r->print('</div>'."\n".'<div class="LC_left_float"><h3>'.
1435: $lt{'lg'}.'</h3>');
1.185 raeburn 1436: my ($fixedauth,$varauth,$authmsg);
1.193 raeburn 1437: if (ref($rulematch{$ccuname.':'.$ccdomain}) eq 'HASH') {
1438: my $matchedrule = $rulematch{$ccuname.':'.$ccdomain}{'username'};
1439: my ($rules,$ruleorder) =
1440: &Apache::lonnet::inst_userrules($ccdomain,'username');
1.185 raeburn 1441: if (ref($rules) eq 'HASH') {
1.193 raeburn 1442: if (ref($rules->{$matchedrule}) eq 'HASH') {
1443: my $authtype = $rules->{$matchedrule}{'authtype'};
1.185 raeburn 1444: if ($authtype !~ /^(krb4|krb5|int|fsys|loc)$/) {
1.190 raeburn 1445: $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1.275 raeburn 1446: } else {
1.193 raeburn 1447: my $authparm = $rules->{$matchedrule}{'authparm'};
1.273 raeburn 1448: $authmsg = $rules->{$matchedrule}{'authmsg'};
1.185 raeburn 1449: if ($authtype =~ /^krb(4|5)$/) {
1450: my $ver = $1;
1451: if ($authparm ne '') {
1452: $fixedauth = <<"KERB";
1453: <input type="hidden" name="login" value="krb" />
1454: <input type="hidden" name="krbver" value="$ver" />
1455: <input type="hidden" name="krbarg" value="$authparm" />
1456: KERB
1457: }
1458: } else {
1459: $fixedauth =
1460: '<input type="hidden" name="login" value="'.$authtype.'" />'."\n";
1.193 raeburn 1461: if ($rules->{$matchedrule}{'authparmfixed'}) {
1.185 raeburn 1462: $fixedauth .=
1463: '<input type="hidden" name="'.$authtype.'arg" value="'.$authparm.'" />'."\n";
1464: } else {
1.273 raeburn 1465: if ($authtype eq 'int') {
1466: $varauth = '<br />'.
1.301 bisitz 1467: &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 1468: } elsif ($authtype eq 'loc') {
1469: $varauth = '<br />'.
1470: &mt('[_1] Local Authentication with argument [_2]','','<input type="text" name="'.$authtype.'arg" value="" />')."\n";
1471: } else {
1472: $varauth =
1.185 raeburn 1473: '<input type="text" name="'.$authtype.'arg" value="" />'."\n";
1.273 raeburn 1474: }
1.185 raeburn 1475: }
1476: }
1477: }
1478: } else {
1.190 raeburn 1479: $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1.185 raeburn 1480: }
1481: }
1482: if ($authmsg) {
1483: $r->print(<<ENDAUTH);
1484: $fixedauth
1485: $authmsg
1486: $varauth
1487: ENDAUTH
1488: }
1489: } else {
1.190 raeburn 1490: $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1.187 raeburn 1491: }
1.414 raeburn 1492: $r->print($portfolioform.$domroleform.$adhocroleform);
1.215 raeburn 1493: if ($env{'form.action'} eq 'singlestudent') {
1494: $r->print(&date_sections_select($context,$newuser,$formname,
1.375 raeburn 1495: $permission,$crstype,$ccuname,
1496: $ccdomain,$showcredits));
1.215 raeburn 1497: }
1498: $r->print('</div><div class="LC_clear_float_footer"></div>');
1.216 raeburn 1499: } else { # user already exists
1.389 bisitz 1500: $r->print($start_page.$forminfo);
1.213 raeburn 1501: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1502: if ($crstype eq 'Community') {
1.389 bisitz 1503: $title = &mt('Enroll one member: [_1] in domain [_2]',
1504: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.318 raeburn 1505: } else {
1.389 bisitz 1506: $title = &mt('Enroll one student: [_1] in domain [_2]',
1507: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.318 raeburn 1508: }
1.213 raeburn 1509: } else {
1.418 raeburn 1510: if ($permission->{'cusr'}) {
1511: $title = &mt('Modify existing user: [_1] in domain [_2]',
1512: '"'.$ccuname.'"','"'.$ccdomain.'"');
1513: } else {
1514: $title = &mt('Existing user: [_1] in domain [_2]',
1.389 bisitz 1515: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.418 raeburn 1516: }
1.213 raeburn 1517: }
1.389 bisitz 1518: $r->print('<h2>'.$title.'</h2>'."\n");
1519: $r->print('<div class="LC_left_float">');
1.393 raeburn 1520: $r->print(&personal_data_display($ccuname,$ccdomain,$newuser,$context,
1521: $inst_results{$ccuname.':'.$ccdomain}));
1.418 raeburn 1522: if ((&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) ||
1523: (&Apache::lonnet::allowed('udp',$env{'request.role.domain'}))) {
1.362 raeburn 1524: $r->print('<br /><h3>'.&mt('User Can Request Creation of Courses/Communities in this Domain?').'</h3>'.
1.300 raeburn 1525: &Apache::loncommon::start_data_table());
1.314 raeburn 1526: if ($env{'request.role.domain'} eq $ccdomain) {
1.300 raeburn 1527: $r->print(&build_tools_display($ccuname,$ccdomain,'requestcourses'));
1528: } else {
1529: $r->print(&coursereq_externaluser($ccuname,$ccdomain,
1530: $env{'request.role.domain'}));
1531: }
1532: $r->print(&Apache::loncommon::end_data_table());
1.275 raeburn 1533: }
1.199 raeburn 1534: $r->print('</div>');
1.414 raeburn 1535: my @order = ('auth','quota','tools','requestauthor','adhocroles');
1.362 raeburn 1536: my %user_text;
1537: my ($isadv,$isauthor) =
1.418 raeburn 1538: &Apache::lonnet::is_advanced_user($ccdomain,$ccuname);
1.362 raeburn 1539: if ((!$isauthor) &&
1.418 raeburn 1540: ((&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) ||
1541: (&Apache::lonnet::allowed('udp',$env{'request.role.domain'}))) &&
1542: ($env{'request.role.domain'} eq $ccdomain)) {
1.362 raeburn 1543: $user_text{'requestauthor'} = &domainrole_req($ccuname,$ccdomain);
1544: }
1.418 raeburn 1545: if ((&Apache::lonnet::allowed('cdh',$env{'request.role.domain'})) ||
1546: (&Apache::lonnet::allowed('udp',$env{'request.role.domain'}))) {
1.414 raeburn 1547: $user_text{'adhocroles'} = &domadhocroles($ccuname,$ccdomain);
1548: }
1.362 raeburn 1549: $user_text{'auth'} = &user_authentication($ccuname,$ccdomain,$formname);
1.267 raeburn 1550: if ((&Apache::lonnet::allowed('mpq',$ccdomain)) ||
1.418 raeburn 1551: (&Apache::lonnet::allowed('mut',$ccdomain)) ||
1552: (&Apache::lonnet::allowed('udp',$ccdomain))) {
1.188 raeburn 1553: # Current user has quota modification privileges
1.378 raeburn 1554: $user_text{'quota'} = &user_quotas($ccuname,$ccdomain);
1.267 raeburn 1555: }
1556: if (!&Apache::lonnet::allowed('mpq',$ccdomain)) {
1557: if (&Apache::lonnet::allowed('mpq',$env{'request.role.domain'})) {
1558: my %lt=&Apache::lonlocal::texthash(
1.385 bisitz 1559: 'dska' => "Disk quotas for user's portfolio and Authoring Space",
1560: 'youd' => "You do not have privileges to modify the portfolio and/or Authoring Space quotas for this user.",
1.267 raeburn 1561: 'ichr' => "If a change is required, contact a domain coordinator for the domain",
1562: );
1.362 raeburn 1563: $user_text{'quota'} = <<ENDNOPORTPRIV;
1.188 raeburn 1564: <h3>$lt{'dska'}</h3>
1565: $lt{'youd'} $lt{'ichr'}: $ccdomain
1566: ENDNOPORTPRIV
1.267 raeburn 1567: }
1568: }
1569: if (!&Apache::lonnet::allowed('mut',$ccdomain)) {
1570: if (&Apache::lonnet::allowed('mut',$env{'request.role.domain'})) {
1571: my %lt=&Apache::lonlocal::texthash(
1572: 'utav' => "User Tools Availability",
1.361 raeburn 1573: 'yodo' => "You do not have privileges to modify Portfolio, Blog, WebDAV, or Personal Information Page settings for this user.",
1.267 raeburn 1574: 'ifch' => "If a change is required, contact a domain coordinator for the domain",
1575: );
1.362 raeburn 1576: $user_text{'tools'} = <<ENDNOTOOLSPRIV;
1.267 raeburn 1577: <h3>$lt{'utav'}</h3>
1578: $lt{'yodo'} $lt{'ifch'}: $ccdomain
1579: ENDNOTOOLSPRIV
1580: }
1.188 raeburn 1581: }
1.362 raeburn 1582: my $gotdiv = 0;
1583: foreach my $item (@order) {
1584: if ($user_text{$item} ne '') {
1585: unless ($gotdiv) {
1586: $r->print('<div class="LC_left_float">');
1587: $gotdiv = 1;
1588: }
1589: $r->print('<br />'.$user_text{$item});
1590: }
1591: }
1592: if ($env{'form.action'} eq 'singlestudent') {
1593: unless ($gotdiv) {
1594: $r->print('<div class="LC_left_float">');
1.213 raeburn 1595: }
1.375 raeburn 1596: my $credits;
1597: if ($showcredits) {
1598: $credits = &get_user_credits($ccuname,$ccdomain,$defaultcredits);
1599: if ($credits eq '') {
1600: $credits = $defaultcredits;
1601: }
1602: }
1.374 raeburn 1603: $r->print(&date_sections_select($context,$newuser,$formname,
1.375 raeburn 1604: $permission,$crstype,$ccuname,
1605: $ccdomain,$showcredits));
1.374 raeburn 1606: }
1.362 raeburn 1607: if ($gotdiv) {
1608: $r->print('</div><div class="LC_clear_float_footer"></div>');
1.188 raeburn 1609: }
1.418 raeburn 1610: my $statuses;
1611: if (($context eq 'domain') && (&Apache::lonnet::allowed('udp',$ccdomain)) &&
1612: (!&Apache::lonnet::allowed('mau',$ccdomain))) {
1613: $statuses = ['active'];
1614: } elsif (($context eq 'course') && ((&Apache::lonnet::allowed('vcl',$env{'request.course.id'})) ||
1615: ($env{'request.course.sec'} &&
1616: &Apache::lonnet::allowed('vcl',$env{'request.course.id'}.'/'.$env{'request.course.sec'})))) {
1617: $statuses = ['active'];
1618: }
1.217 raeburn 1619: if ($env{'form.action'} ne 'singlestudent') {
1.329 raeburn 1620: &display_existing_roles($r,$ccuname,$ccdomain,\%inccourses,$context,
1.418 raeburn 1621: $roledom,$crstype,$showcredits,$statuses);
1.217 raeburn 1622: }
1.25 matthew 1623: } ## End of new user/old user logic
1.218 raeburn 1624: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1625: my $btntxt;
1626: if ($crstype eq 'Community') {
1627: $btntxt = &mt('Enroll Member');
1628: } else {
1629: $btntxt = &mt('Enroll Student');
1630: }
1631: $r->print('<br /><input type="button" value="'.$btntxt.'" onclick="setSections(this.form)" />'."\n");
1.418 raeburn 1632: } elsif ($permission->{'cusr'}) {
1.393 raeburn 1633: $r->print('<div class="LC_left_float">'.
1634: '<fieldset><legend>'.&mt('Add Roles').'</legend>');
1.218 raeburn 1635: my $addrolesdisplay = 0;
1636: if ($context eq 'domain' || $context eq 'author') {
1637: $addrolesdisplay = &new_coauthor_roles($r,$ccuname,$ccdomain);
1638: }
1639: if ($context eq 'domain') {
1.357 raeburn 1640: my $add_domainroles = &new_domain_roles($r,$ccdomain);
1.218 raeburn 1641: if (!$addrolesdisplay) {
1642: $addrolesdisplay = $add_domainroles;
1.2 www 1643: }
1.375 raeburn 1644: $r->print(&course_level_dc($env{'request.role.domain'},$showcredits));
1.393 raeburn 1645: $r->print('</fieldset></div><div class="LC_clear_float_footer"></div>'.
1646: '<br /><input type="button" value="'.&mt('Save').'" onclick="setCourse()" />'."\n");
1.218 raeburn 1647: } elsif ($context eq 'author') {
1648: if ($addrolesdisplay) {
1.393 raeburn 1649: $r->print('</fieldset></div><div class="LC_clear_float_footer"></div>'.
1650: '<br /><input type="button" value="'.&mt('Save').'"');
1.218 raeburn 1651: if ($newuser) {
1.301 bisitz 1652: $r->print(' onclick="auth_check()" \>'."\n");
1.218 raeburn 1653: } else {
1.301 bisitz 1654: $r->print('onclick="this.form.submit()" \>'."\n");
1.218 raeburn 1655: }
1.188 raeburn 1656: } else {
1.393 raeburn 1657: $r->print('</fieldset></div>'.
1658: '<div class="LC_clear_float_footer"></div>'.
1659: '<br /><a href="javascript:backPage(document.cu)">'.
1.218 raeburn 1660: &mt('Back to previous page').'</a>');
1.188 raeburn 1661: }
1662: } else {
1.375 raeburn 1663: $r->print(&course_level_table(\%inccourses,$showcredits,$defaultcredits));
1.393 raeburn 1664: $r->print('</fieldset></div><div class="LC_clear_float_footer"></div>'.
1665: '<br /><input type="button" value="'.&mt('Save').'" onclick="setSections(this.form)" />'."\n");
1.188 raeburn 1666: }
1.88 raeburn 1667: }
1.188 raeburn 1668: $r->print(&Apache::lonhtmlcommon::echo_form_input(['phase','userrole','ccdomain','prevphase','currstate','ccuname','ccdomain']));
1.179 raeburn 1669: $r->print('<input type="hidden" name="currstate" value="" />');
1.393 raeburn 1670: $r->print('<input type="hidden" name="prevphase" value="'.$env{'form.phase'}.'" /></form><br /><br />');
1.218 raeburn 1671: return;
1.2 www 1672: }
1.1 www 1673:
1.213 raeburn 1674: sub singleuser_breadcrumb {
1.422 raeburn 1675: my ($crstype,$context,$domain) = @_;
1.213 raeburn 1676: my %breadcrumb_text;
1677: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1678: if ($crstype eq 'Community') {
1679: $breadcrumb_text{'search'} = 'Enroll a member';
1680: } else {
1681: $breadcrumb_text{'search'} = 'Enroll a student';
1682: }
1.422 raeburn 1683: $breadcrumb_text{'userpicked'} = 'Select a user';
1684: $breadcrumb_text{'modify'} = 'Set section/dates';
1.416 raeburn 1685: } elsif ($env{'form.action'} eq 'accesslogs') {
1686: $breadcrumb_text{'search'} = 'View access logs for a user';
1.422 raeburn 1687: $breadcrumb_text{'userpicked'} = 'Select a user';
1688: $breadcrumb_text{'activity'} = 'Activity';
1689: } elsif (($env{'form.action'} eq 'singleuser') && ($context eq 'domain') &&
1690: (!&Apache::lonnet::allowed('mau',$domain))) {
1691: $breadcrumb_text{'search'} = "View user's roles";
1692: $breadcrumb_text{'userpicked'} = 'Select a user';
1693: $breadcrumb_text{'modify'} = 'User roles';
1.213 raeburn 1694: } else {
1.229 raeburn 1695: $breadcrumb_text{'search'} = 'Create/modify a user';
1.422 raeburn 1696: $breadcrumb_text{'userpicked'} = 'Select a user';
1697: $breadcrumb_text{'modify'} = 'Set user role';
1.213 raeburn 1698: }
1699: return %breadcrumb_text;
1700: }
1701:
1702: sub date_sections_select {
1.375 raeburn 1703: my ($context,$newuser,$formname,$permission,$crstype,$ccuname,$ccdomain,
1704: $showcredits) = @_;
1705: my $credits;
1706: if ($showcredits) {
1707: my $defaultcredits = &Apache::lonuserutils::get_defaultcredits();
1708: $credits = &get_user_credits($ccuname,$ccdomain,$defaultcredits);
1709: if ($credits eq '') {
1710: $credits = $defaultcredits;
1711: }
1712: }
1.213 raeburn 1713: my $cid = $env{'request.course.id'};
1714: my ($cnum,$cdom) = &Apache::lonuserutils::get_course_identity($cid);
1715: my $date_table = '<h3>'.&mt('Starting and Ending Dates').'</h3>'."\n".
1716: &Apache::lonuserutils::date_setting_table(undef,undef,$context,
1717: undef,$formname,$permission);
1718: my $rowtitle = 'Section';
1.375 raeburn 1719: my $secbox = '<h3>'.&mt('Section and Credits').'</h3>'."\n".
1.213 raeburn 1720: &Apache::lonuserutils::section_picker($cdom,$cnum,'st',$rowtitle,
1.375 raeburn 1721: $permission,$context,'',$crstype,
1722: $showcredits,$credits);
1.213 raeburn 1723: my $output = $date_table.$secbox;
1724: return $output;
1725: }
1726:
1.216 raeburn 1727: sub validation_javascript {
1.375 raeburn 1728: my ($context,$ccdomain,$pjump_def,$crstype,$groupslist,$newuser,$formname,
1.216 raeburn 1729: $loaditem) = @_;
1730: my $dc_setcourse_code = '';
1731: my $nondc_setsection_code = '';
1732: if ($context eq 'domain') {
1733: my $dcdom = $env{'request.role.domain'};
1734: $loaditem->{'onload'} = "document.cu.coursedesc.value='';";
1.227 raeburn 1735: $dc_setcourse_code =
1736: &Apache::lonuserutils::dc_setcourse_js('cu','singleuser',$context);
1.216 raeburn 1737: } else {
1.227 raeburn 1738: my $checkauth;
1739: if (($newuser) || (&Apache::lonnet::allowed('mau',$ccdomain))) {
1740: $checkauth = 1;
1741: }
1742: if ($context eq 'course') {
1743: $nondc_setsection_code =
1744: &Apache::lonuserutils::setsections_javascript($formname,$groupslist,
1.375 raeburn 1745: undef,$checkauth,
1746: $crstype);
1.227 raeburn 1747: }
1748: if ($checkauth) {
1749: $nondc_setsection_code .=
1750: &Apache::lonuserutils::verify_authen($formname,$context);
1751: }
1.216 raeburn 1752: }
1753: my $js = &user_modification_js($pjump_def,$dc_setcourse_code,
1754: $nondc_setsection_code,$groupslist);
1755: my ($jsback,$elements) = &crumb_utilities();
1756: $js .= "\n".
1.301 bisitz 1757: '<script type="text/javascript">'."\n".
1758: '// <![CDATA['."\n".
1759: $jsback."\n".
1760: '// ]]>'."\n".
1761: '</script>'."\n";
1.216 raeburn 1762: return $js;
1763: }
1764:
1.217 raeburn 1765: sub display_existing_roles {
1.375 raeburn 1766: my ($r,$ccuname,$ccdomain,$inccourses,$context,$roledom,$crstype,
1.418 raeburn 1767: $showcredits,$statuses) = @_;
1.329 raeburn 1768: my $now=time;
1.418 raeburn 1769: my $showall = 1;
1770: my ($showexpired,$showactive);
1771: if ((ref($statuses) eq 'ARRAY') && (@{$statuses} > 0)) {
1772: $showall = 0;
1773: if (grep(/^expired$/,@{$statuses})) {
1774: $showexpired = 1;
1775: }
1776: if (grep(/^active$/,@{$statuses})) {
1777: $showactive = 1;
1778: }
1779: if ($showexpired && $showactive) {
1780: $showall = 1;
1781: }
1782: }
1.329 raeburn 1783: my %lt=&Apache::lonlocal::texthash(
1.217 raeburn 1784: 'rer' => "Existing Roles",
1785: 'rev' => "Revoke",
1786: 'del' => "Delete",
1787: 'ren' => "Re-Enable",
1788: 'rol' => "Role",
1789: 'ext' => "Extent",
1.375 raeburn 1790: 'crd' => "Credits",
1.217 raeburn 1791: 'sta' => "Start",
1792: 'end' => "End",
1793: );
1.329 raeburn 1794: my (%rolesdump,%roletext,%sortrole,%roleclass,%rolepriv);
1795: if ($context eq 'course' || $context eq 'author') {
1796: my @roles = &Apache::lonuserutils::roles_by_context($context,1,$crstype);
1797: my %roleshash =
1798: &Apache::lonnet::get_my_roles($ccuname,$ccdomain,'userroles',
1799: ['active','previous','future'],\@roles,$roledom,1);
1800: foreach my $key (keys(%roleshash)) {
1801: my ($start,$end) = split(':',$roleshash{$key});
1802: next if ($start eq '-1' || $end eq '-1');
1803: my ($rnum,$rdom,$role,$sec) = split(':',$key);
1804: if ($context eq 'course') {
1805: next unless (($rnum eq $env{'course.'.$env{'request.course.id'}.'.num'})
1806: && ($rdom eq $env{'course.'.$env{'request.course.id'}.'.domain'}));
1807: } elsif ($context eq 'author') {
1808: next unless (($rnum eq $env{'user.name'}) && ($rdom eq $env{'request.role.domain'}));
1809: }
1810: my ($newkey,$newvalue,$newrole);
1811: $newkey = '/'.$rdom.'/'.$rnum;
1812: if ($sec ne '') {
1813: $newkey .= '/'.$sec;
1814: }
1815: $newvalue = $role;
1816: if ($role =~ /^cr/) {
1817: $newrole = 'cr';
1818: } else {
1819: $newrole = $role;
1820: }
1821: $newkey .= '_'.$newrole;
1822: if ($start ne '' && $end ne '') {
1823: $newvalue .= '_'.$end.'_'.$start;
1.335 raeburn 1824: } elsif ($end ne '') {
1825: $newvalue .= '_'.$end;
1.329 raeburn 1826: }
1827: $rolesdump{$newkey} = $newvalue;
1828: }
1829: } else {
1.360 raeburn 1830: %rolesdump=&Apache::lonnet::dump('roles',$ccdomain,$ccuname);
1.329 raeburn 1831: }
1832: # Build up table of user roles to allow revocation and re-enabling of roles.
1833: my ($tmp) = keys(%rolesdump);
1834: return if ($tmp =~ /^(con_lost|error)/i);
1835: foreach my $area (sort { my $a1=join('_',(split('_',$a))[1,0]);
1836: my $b1=join('_',(split('_',$b))[1,0]);
1837: return $a1 cmp $b1;
1838: } keys(%rolesdump)) {
1839: next if ($area =~ /^rolesdef/);
1840: my $envkey=$area;
1841: my $role = $rolesdump{$area};
1842: my $thisrole=$area;
1843: $area =~ s/\_\w\w$//;
1844: my ($role_code,$role_end_time,$role_start_time) =
1845: split(/_/,$role);
1.418 raeburn 1846: my $active=1;
1847: $active=0 if (($role_end_time) && ($now>$role_end_time));
1848: if ($active) {
1849: next unless($showall || $showactive);
1850: } else {
1851: next unless($showall || $showexpired);
1852: }
1.217 raeburn 1853: # Is this a custom role? Get role owner and title.
1.329 raeburn 1854: my ($croleudom,$croleuname,$croletitle)=
1855: ($role_code=~m{^cr/($match_domain)/($match_username)/(\w+)$});
1856: my $allowed=0;
1857: my $delallowed=0;
1858: my $sortkey=$role_code;
1859: my $class='Unknown';
1.375 raeburn 1860: my $credits='';
1.418 raeburn 1861: my $csec;
1.421 raeburn 1862: if ($area =~ m{^/($match_domain)/($match_courseid)}) {
1.329 raeburn 1863: $class='Course';
1864: my ($coursedom,$coursedir) = ($1,$2);
1865: my $cid = $1.'_'.$2;
1866: # $1.'_'.$2 is the course id (eg. 103_12345abcef103l3).
1.421 raeburn 1867: next if ($envkey =~ m{^/$match_domain/$match_courseid/[A-Za-z0-9]+_gr$});
1.329 raeburn 1868: my %coursedata=
1869: &Apache::lonnet::coursedescription($cid);
1870: if ($coursedir =~ /^$match_community$/) {
1871: $class='Community';
1872: }
1873: $sortkey.="\0$coursedom";
1874: my $carea;
1875: if (defined($coursedata{'description'})) {
1876: $carea=$coursedata{'description'}.
1877: '<br />'.&mt('Domain').': '.$coursedom.(' 'x8).
1878: &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$coursedir,$coursedom);
1879: $sortkey.="\0".$coursedata{'description'};
1880: } else {
1881: if ($class eq 'Community') {
1882: $carea=&mt('Unavailable community').': '.$area;
1883: $sortkey.="\0".&mt('Unavailable community').': '.$area;
1.217 raeburn 1884: } else {
1885: $carea=&mt('Unavailable course').': '.$area;
1886: $sortkey.="\0".&mt('Unavailable course').': '.$area;
1887: }
1.329 raeburn 1888: }
1889: $sortkey.="\0$coursedir";
1890: $inccourses->{$cid}=1;
1.375 raeburn 1891: if (($showcredits) && ($class eq 'Course') && ($role_code eq 'st')) {
1892: my $defaultcredits = $coursedata{'internal.defaultcredits'};
1893: $credits =
1894: &get_user_credits($ccuname,$ccdomain,$defaultcredits,
1895: $coursedom,$coursedir);
1896: if ($credits eq '') {
1897: $credits = $defaultcredits;
1898: }
1899: }
1.329 raeburn 1900: if ((&Apache::lonnet::allowed('c'.$role_code,$coursedom.'/'.$coursedir)) ||
1901: (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) {
1902: $allowed=1;
1903: }
1904: unless ($allowed) {
1.365 raeburn 1905: my $isowner = &Apache::lonuserutils::is_courseowner($cid,$coursedata{'internal.courseowner'});
1.329 raeburn 1906: if ($isowner) {
1907: if (($role_code eq 'co') && ($class eq 'Community')) {
1908: $allowed = 1;
1909: } elsif (($role_code eq 'cc') && ($class eq 'Course')) {
1910: $allowed = 1;
1911: }
1.217 raeburn 1912: }
1.329 raeburn 1913: }
1914: if ((&Apache::lonnet::allowed('dro',$coursedom)) ||
1915: (&Apache::lonnet::allowed('dro',$ccdomain))) {
1916: $delallowed=1;
1917: }
1.217 raeburn 1918: # - custom role. Needs more info, too
1.329 raeburn 1919: if ($croletitle) {
1920: if (&Apache::lonnet::allowed('ccr',$coursedom.'/'.$coursedir)) {
1921: $allowed=1;
1922: $thisrole.='.'.$role_code;
1.217 raeburn 1923: }
1.329 raeburn 1924: }
1.418 raeburn 1925: if ($area=~m{^/($match_domain/$match_courseid/(\w+))}) {
1926: $csec = $2;
1927: $carea.='<br />'.&mt('Section: [_1]',$csec);
1928: $sortkey.="\0$csec";
1.329 raeburn 1929: if (!$allowed) {
1.418 raeburn 1930: if ($env{'request.course.sec'} eq $csec) {
1931: if (&Apache::lonnet::allowed('c'.$role_code,$1)) {
1.329 raeburn 1932: $allowed = 1;
1.217 raeburn 1933: }
1934: }
1935: }
1.329 raeburn 1936: }
1937: $area=$carea;
1938: } else {
1939: $sortkey.="\0".$area;
1940: # Determine if current user is able to revoke privileges
1941: if ($area=~m{^/($match_domain)/}) {
1942: if ((&Apache::lonnet::allowed('c'.$role_code,$1)) ||
1943: (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) {
1944: $allowed=1;
1.217 raeburn 1945: }
1.329 raeburn 1946: if (((&Apache::lonnet::allowed('dro',$1)) ||
1947: (&Apache::lonnet::allowed('dro',$ccdomain))) &&
1948: ($role_code ne 'dc')) {
1949: $delallowed=1;
1.217 raeburn 1950: }
1.329 raeburn 1951: } else {
1952: if (&Apache::lonnet::allowed('c'.$role_code,'/')) {
1.217 raeburn 1953: $allowed=1;
1954: }
1955: }
1.363 raeburn 1956: if ($role_code eq 'ca' || $role_code eq 'au' || $role_code eq 'aa') {
1.377 raeburn 1957: $class='Authoring Space';
1.329 raeburn 1958: } elsif ($role_code eq 'su') {
1959: $class='System';
1.217 raeburn 1960: } else {
1.329 raeburn 1961: $class='Domain';
1.217 raeburn 1962: }
1.329 raeburn 1963: }
1964: if (($role_code eq 'ca') || ($role_code eq 'aa')) {
1965: $area=~m{/($match_domain)/($match_username)};
1966: if (&Apache::lonuserutils::authorpriv($2,$1)) {
1967: $allowed=1;
1.217 raeburn 1968: } else {
1.329 raeburn 1969: $allowed=0;
1.217 raeburn 1970: }
1.329 raeburn 1971: }
1972: my $row = '';
1.418 raeburn 1973: if ($showall) {
1974: $row.= '<td>';
1975: if (($active) && ($allowed)) {
1976: $row.= '<input type="checkbox" name="rev:'.$thisrole.'" />';
1977: } else {
1978: if ($active) {
1979: $row.=' ';
1980: } else {
1981: $row.=&mt('expired or revoked');
1982: }
1983: }
1984: $row.='</td><td>';
1985: if ($allowed && !$active) {
1986: $row.= '<input type="checkbox" name="ren:'.$thisrole.'" />';
1987: } else {
1988: $row.=' ';
1989: }
1990: $row.='</td><td>';
1991: if ($delallowed) {
1992: $row.= '<input type="checkbox" name="del:'.$thisrole.'" />';
1.217 raeburn 1993: } else {
1.418 raeburn 1994: $row.=' ';
1.217 raeburn 1995: }
1.418 raeburn 1996: $row.= '</td>';
1.329 raeburn 1997: }
1998: my $plaintext='';
1999: if (!$croletitle) {
1.375 raeburn 2000: $plaintext=&Apache::lonnet::plaintext($role_code,$class);
2001: if (($showcredits) && ($credits ne '')) {
2002: $plaintext .= '<br/ ><span class="LC_nobreak">'.
2003: '<span class="LC_fontsize_small">'.
2004: &mt('Credits: [_1]',$credits).
2005: '</span></span>';
2006: }
1.329 raeburn 2007: } else {
2008: $plaintext=
1.395 bisitz 2009: &mt('Custom role [_1][_2]defined by [_3]',
1.346 bisitz 2010: '"'.$croletitle.'"',
2011: '<br />',
2012: $croleuname.':'.$croleudom);
1.329 raeburn 2013: }
1.418 raeburn 2014: $row.= '<td>'.$plaintext.'</td>'.
2015: '<td>'.$area.'</td>'.
2016: '<td>'.($role_start_time?&Apache::lonlocal::locallocaltime($role_start_time)
2017: : ' ' ).'</td>'.
2018: '<td>'.($role_end_time ?&Apache::lonlocal::locallocaltime($role_end_time)
2019: : ' ' ).'</td>';
1.329 raeburn 2020: $sortrole{$sortkey}=$envkey;
2021: $roletext{$envkey}=$row;
2022: $roleclass{$envkey}=$class;
1.418 raeburn 2023: if ($allowed) {
2024: $rolepriv{$envkey}='edit';
2025: } else {
2026: if ($context eq 'domain') {
1.420 raeburn 2027: if ((&Apache::lonnet::allowed('vur',$ccdomain)) &&
1.421 raeburn 2028: ($envkey=~m{^/$ccdomain/})) {
1.418 raeburn 2029: $rolepriv{$envkey}='view';
2030: }
2031: } elsif ($context eq 'course') {
2032: if ((&Apache::lonnet::allowed('vcl',$env{'request.course.id'})) ||
2033: ($env{'request.course.sec'} && ($env{'request.course.sec'} eq $csec) &&
2034: &Apache::lonnet::allowed('vcl',$env{'request.course.id'}.'/'.$env{'request.course.sec'}))) {
2035: $rolepriv{$envkey}='view';
2036: }
2037: }
2038: }
1.329 raeburn 2039: } # end of foreach (table building loop)
2040:
2041: my $rolesdisplay = 0;
2042: my %output = ();
1.377 raeburn 2043: foreach my $type ('Authoring Space','Course','Community','Domain','System','Unknown') {
1.329 raeburn 2044: $output{$type} = '';
2045: foreach my $which (sort {uc($a) cmp uc($b)} (keys(%sortrole))) {
2046: if ( ($roleclass{$sortrole{$which}} =~ /^\Q$type\E/ ) && ($rolepriv{$sortrole{$which}}) ) {
2047: $output{$type}.=
2048: &Apache::loncommon::start_data_table_row().
2049: $roletext{$sortrole{$which}}.
2050: &Apache::loncommon::end_data_table_row();
1.217 raeburn 2051: }
1.329 raeburn 2052: }
2053: unless($output{$type} eq '') {
2054: $output{$type} = '<tr class="LC_info_row">'.
2055: "<td align='center' colspan='7'>".&mt($type)."</td></tr>".
2056: $output{$type};
2057: $rolesdisplay = 1;
2058: }
2059: }
2060: if ($rolesdisplay == 1) {
2061: my $contextrole='';
2062: if ($env{'request.course.id'}) {
2063: if (&Apache::loncommon::course_type() eq 'Community') {
2064: $contextrole = &mt('Existing Roles in this Community');
1.290 bisitz 2065: } else {
1.329 raeburn 2066: $contextrole = &mt('Existing Roles in this Course');
1.290 bisitz 2067: }
1.329 raeburn 2068: } elsif ($env{'request.role'} =~ /^au\./) {
1.377 raeburn 2069: $contextrole = &mt('Existing Co-Author Roles in your Authoring Space');
1.329 raeburn 2070: } else {
1.418 raeburn 2071: if ($showall) {
2072: $contextrole = &mt('Existing Roles in this Domain');
2073: } elsif ($showactive) {
2074: $contextrole = &mt('Unexpired Roles in this Domain');
2075: } elsif ($showexpired) {
2076: $contextrole = &mt('Expired or Revoked Roles in this Domain');
2077: }
1.329 raeburn 2078: }
1.393 raeburn 2079: $r->print('<div class="LC_left_float">'.
1.375 raeburn 2080: '<fieldset><legend>'.$contextrole.'</legend>'.
1.217 raeburn 2081: &Apache::loncommon::start_data_table("LC_createuser").
1.418 raeburn 2082: &Apache::loncommon::start_data_table_header_row());
2083: if ($showall) {
2084: $r->print(
1.419 raeburn 2085: '<th>'.$lt{'rev'}.'</th><th>'.$lt{'ren'}.'</th><th>'.$lt{'del'}.'</th>'
1.418 raeburn 2086: );
2087: } elsif ($showexpired) {
2088: $r->print('<th>'.$lt{'rev'}.'</th>');
2089: }
2090: $r->print(
1.419 raeburn 2091: '<th>'.$lt{'rol'}.'</th><th>'.$lt{'ext'}.'</th>'.
2092: '<th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'.
1.217 raeburn 2093: &Apache::loncommon::end_data_table_header_row());
1.377 raeburn 2094: foreach my $type ('Authoring Space','Course','Community','Domain','System','Unknown') {
1.329 raeburn 2095: if ($output{$type}) {
2096: $r->print($output{$type}."\n");
1.217 raeburn 2097: }
2098: }
1.375 raeburn 2099: $r->print(&Apache::loncommon::end_data_table().
2100: '</fieldset></div>');
1.329 raeburn 2101: }
1.217 raeburn 2102: return;
2103: }
2104:
1.218 raeburn 2105: sub new_coauthor_roles {
2106: my ($r,$ccuname,$ccdomain) = @_;
2107: my $addrolesdisplay = 0;
2108: #
2109: # Co-Author
2110: #
2111: if (&Apache::lonuserutils::authorpriv($env{'user.name'},
2112: $env{'request.role.domain'}) &&
2113: ($env{'user.name'} ne $ccuname || $env{'user.domain'} ne $ccdomain)) {
2114: # No sense in assigning co-author role to yourself
2115: $addrolesdisplay = 1;
2116: my $cuname=$env{'user.name'};
2117: my $cudom=$env{'request.role.domain'};
2118: my %lt=&Apache::lonlocal::texthash(
1.377 raeburn 2119: 'cs' => "Authoring Space",
1.218 raeburn 2120: 'act' => "Activate",
2121: 'rol' => "Role",
2122: 'ext' => "Extent",
2123: 'sta' => "Start",
2124: 'end' => "End",
2125: 'cau' => "Co-Author",
2126: 'caa' => "Assistant Co-Author",
2127: 'ssd' => "Set Start Date",
2128: 'sed' => "Set End Date"
2129: );
2130: $r->print('<h4>'.$lt{'cs'}.'</h4>'."\n".
2131: &Apache::loncommon::start_data_table()."\n".
2132: &Apache::loncommon::start_data_table_header_row()."\n".
2133: '<th>'.$lt{'act'}.'</th><th>'.$lt{'rol'}.'</th>'.
2134: '<th>'.$lt{'ext'}.'</th><th>'.$lt{'sta'}.'</th>'.
2135: '<th>'.$lt{'end'}.'</th>'."\n".
2136: &Apache::loncommon::end_data_table_header_row()."\n".
2137: &Apache::loncommon::start_data_table_row().'
2138: <td>
1.291 bisitz 2139: <input type="checkbox" name="act_'.$cudom.'_'.$cuname.'_ca" />
1.218 raeburn 2140: </td>
2141: <td>'.$lt{'cau'}.'</td>
2142: <td>'.$cudom.'_'.$cuname.'</td>
2143: <td><input type="hidden" name="start_'.$cudom.'_'.$cuname.'_ca" value="" />
2144: <a href=
2145: "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>
2146: <td><input type="hidden" name="end_'.$cudom.'_'.$cuname.'_ca" value="" />
2147: <a href=
2148: "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".
2149: &Apache::loncommon::end_data_table_row()."\n".
2150: &Apache::loncommon::start_data_table_row()."\n".
1.291 bisitz 2151: '<td><input type="checkbox" name="act_'.$cudom.'_'.$cuname.'_aa" /></td>
1.218 raeburn 2152: <td>'.$lt{'caa'}.'</td>
2153: <td>'.$cudom.'_'.$cuname.'</td>
2154: <td><input type="hidden" name="start_'.$cudom.'_'.$cuname.'_aa" value="" />
2155: <a href=
2156: "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>
2157: <td><input type="hidden" name="end_'.$cudom.'_'.$cuname.'_aa" value="" />
2158: <a href=
2159: "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".
2160: &Apache::loncommon::end_data_table_row()."\n".
2161: &Apache::loncommon::end_data_table());
2162: } elsif ($env{'request.role'} =~ /^au\./) {
2163: if (!(&Apache::lonuserutils::authorpriv($env{'user.name'},
2164: $env{'request.role.domain'}))) {
2165: $r->print('<span class="LC_error">'.
2166: &mt('You do not have privileges to assign co-author roles.').
2167: '</span>');
2168: } elsif (($env{'user.name'} eq $ccuname) &&
2169: ($env{'user.domain'} eq $ccdomain)) {
1.377 raeburn 2170: $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 2171: }
2172: }
2173: return $addrolesdisplay;;
2174: }
2175:
2176: sub new_domain_roles {
1.357 raeburn 2177: my ($r,$ccdomain) = @_;
1.218 raeburn 2178: my $addrolesdisplay = 0;
2179: #
2180: # Domain level
2181: #
2182: my $num_domain_level = 0;
2183: my $domaintext =
2184: '<h4>'.&mt('Domain Level').'</h4>'.
2185: &Apache::loncommon::start_data_table().
2186: &Apache::loncommon::start_data_table_header_row().
2187: '<th>'.&mt('Activate').'</th><th>'.&mt('Role').'</th><th>'.
2188: &mt('Extent').'</th>'.
2189: '<th>'.&mt('Start').'</th><th>'.&mt('End').'</th>'.
2190: &Apache::loncommon::end_data_table_header_row();
1.312 raeburn 2191: my @allroles = &Apache::lonuserutils::roles_by_context('domain');
1.218 raeburn 2192: foreach my $thisdomain (sort(&Apache::lonnet::all_domains())) {
1.312 raeburn 2193: foreach my $role (@allroles) {
2194: next if ($role eq 'ad');
1.357 raeburn 2195: next if (($role eq 'au') && ($ccdomain ne $thisdomain));
1.218 raeburn 2196: if (&Apache::lonnet::allowed('c'.$role,$thisdomain)) {
2197: my $plrole=&Apache::lonnet::plaintext($role);
2198: my %lt=&Apache::lonlocal::texthash(
2199: 'ssd' => "Set Start Date",
2200: 'sed' => "Set End Date"
2201: );
2202: $num_domain_level ++;
2203: $domaintext .=
2204: &Apache::loncommon::start_data_table_row().
1.291 bisitz 2205: '<td><input type="checkbox" name="act_'.$thisdomain.'_'.$role.'" /></td>
1.218 raeburn 2206: <td>'.$plrole.'</td>
2207: <td>'.$thisdomain.'</td>
2208: <td><input type="hidden" name="start_'.$thisdomain.'_'.$role.'" value="" />
2209: <a href=
2210: "javascript:pjump('."'date_start','Start Date $plrole',document.cu.start_$thisdomain\_$role.value,'start_$thisdomain\_$role','cu.pres','dateset'".')">'.$lt{'ssd'}.'</a></td>
2211: <td><input type="hidden" name="end_'.$thisdomain.'_'.$role.'" value="" />
2212: <a href=
2213: "javascript:pjump('."'date_end','End Date $plrole',document.cu.end_$thisdomain\_$role.value,'end_$thisdomain\_$role','cu.pres','dateset'".')">'.$lt{'sed'}.'</a></td>'.
2214: &Apache::loncommon::end_data_table_row();
2215: }
2216: }
2217: }
2218: $domaintext.= &Apache::loncommon::end_data_table();
2219: if ($num_domain_level > 0) {
2220: $r->print($domaintext);
2221: $addrolesdisplay = 1;
2222: }
2223: return $addrolesdisplay;
2224: }
2225:
1.188 raeburn 2226: sub user_authentication {
1.227 raeburn 2227: my ($ccuname,$ccdomain,$formname) = @_;
1.188 raeburn 2228: my $currentauth=&Apache::lonnet::queryauthenticate($ccuname,$ccdomain);
1.227 raeburn 2229: my $outcome;
1.418 raeburn 2230: my %lt=&Apache::lonlocal::texthash(
2231: 'err' => "ERROR",
2232: 'uuas' => "This user has an unrecognized authentication scheme",
2233: 'adcs' => "Please alert a domain coordinator of this situation",
2234: 'sldb' => "Please specify login data below",
2235: 'ld' => "Login Data"
2236: );
1.188 raeburn 2237: # Check for a bad authentication type
2238: if ($currentauth !~ /^(krb4|krb5|unix|internal|localauth):/) {
2239: # bad authentication scheme
2240: if (&Apache::lonnet::allowed('mau',$ccdomain)) {
1.227 raeburn 2241: &initialize_authen_forms($ccdomain,$formname);
2242:
1.190 raeburn 2243: my $choices = &Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc);
1.188 raeburn 2244: $outcome = <<ENDBADAUTH;
2245: <script type="text/javascript" language="Javascript">
1.301 bisitz 2246: // <![CDATA[
1.188 raeburn 2247: $loginscript
1.301 bisitz 2248: // ]]>
1.188 raeburn 2249: </script>
2250: <span class="LC_error">$lt{'err'}:
2251: $lt{'uuas'} ($currentauth). $lt{'sldb'}.</span>
2252: <h3>$lt{'ld'}</h3>
2253: $choices
2254: ENDBADAUTH
2255: } else {
2256: # This user is not allowed to modify the user's
2257: # authentication scheme, so just notify them of the problem
2258: $outcome = <<ENDBADAUTH;
2259: <span class="LC_error"> $lt{'err'}:
2260: $lt{'uuas'} ($currentauth). $lt{'adcs'}.
2261: </span>
2262: ENDBADAUTH
2263: }
2264: } else { # Authentication type is valid
1.418 raeburn 2265:
1.227 raeburn 2266: &initialize_authen_forms($ccdomain,$formname,$currentauth,'modifyuser');
1.205 raeburn 2267: my ($authformcurrent,$can_modify,@authform_others) =
1.188 raeburn 2268: &modify_login_block($ccdomain,$currentauth);
2269: if (&Apache::lonnet::allowed('mau',$ccdomain)) {
2270: # Current user has login modification privileges
2271: $outcome =
2272: '<script type="text/javascript" language="Javascript">'."\n".
1.301 bisitz 2273: '// <![CDATA['."\n".
1.188 raeburn 2274: $loginscript."\n".
1.301 bisitz 2275: '// ]]>'."\n".
1.188 raeburn 2276: '</script>'."\n".
2277: '<h3>'.$lt{'ld'}.'</h3>'.
2278: &Apache::loncommon::start_data_table().
1.205 raeburn 2279: &Apache::loncommon::start_data_table_row().
1.188 raeburn 2280: '<td>'.$authformnop;
1.418 raeburn 2281: if (($can_modify) && (&Apache::lonnet::allowed('mau',$ccdomain))) {
1.188 raeburn 2282: $outcome .= '</td>'."\n".
2283: &Apache::loncommon::end_data_table_row().
2284: &Apache::loncommon::start_data_table_row().
2285: '<td>'.$authformcurrent.'</td>'.
2286: &Apache::loncommon::end_data_table_row()."\n";
2287: } else {
1.200 raeburn 2288: $outcome .= ' ('.$authformcurrent.')</td>'.
2289: &Apache::loncommon::end_data_table_row()."\n";
1.188 raeburn 2290: }
1.418 raeburn 2291: if (&Apache::lonnet::allowed('mau',$ccdomain)) {
2292: foreach my $item (@authform_others) {
2293: $outcome .= &Apache::loncommon::start_data_table_row().
2294: '<td>'.$item.'</td>'.
2295: &Apache::loncommon::end_data_table_row()."\n";
2296: }
1.188 raeburn 2297: }
1.205 raeburn 2298: $outcome .= &Apache::loncommon::end_data_table();
1.188 raeburn 2299: } else {
1.418 raeburn 2300: if (&Apache::lonnet::allowed('udp',$ccdomain)) {
2301: # Current user has rights to view domain preferences for user's domain
2302: my $result;
2303: if ($currentauth =~ /^krb(4|5):([^:]*)$/) {
2304: my ($krbver,$krbrealm) = ($1,$2);
2305: if ($krbrealm eq '') {
2306: $result = &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
2307: } else {
2308: $result = &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
2309: $krbver,$krbrealm);
2310: }
2311: } elsif ($currentauth =~ /^internal:/) {
2312: $result = &mt('Currently internally authenticated.');
2313: } elsif ($currentauth =~ /^localauth:/) {
2314: $result = &mt('Currently using local (institutional) authentication.');
2315: } elsif ($currentauth =~ /^unix:/) {
2316: $result = &mt('Currently Filesystem Authenticated.');
2317: }
2318: $outcome = '<h3>'.$lt{'ld'}.'</h3>'.
2319: &Apache::loncommon::start_data_table().
2320: &Apache::loncommon::start_data_table_row().
2321: '<td>'.$result.'</td>'.
2322: &Apache::loncommon::end_data_table_row()."\n".
2323: &Apache::loncommon::end_data_table();
2324: } elsif (&Apache::lonnet::allowed('mau',$env{'request.role.domain'})) {
1.188 raeburn 2325: my %lt=&Apache::lonlocal::texthash(
2326: 'ccld' => "Change Current Login Data",
2327: 'yodo' => "You do not have privileges to modify the authentication configuration for this user.",
2328: 'ifch' => "If a change is required, contact a domain coordinator for the domain",
2329: );
2330: $outcome .= <<ENDNOPRIV;
2331: <h3>$lt{'ccld'}</h3>
2332: $lt{'yodo'} $lt{'ifch'}: $ccdomain
1.235 raeburn 2333: <input type="hidden" name="login" value="nochange" />
1.188 raeburn 2334: ENDNOPRIV
2335: }
2336: }
2337: } ## End of "check for bad authentication type" logic
2338: return $outcome;
2339: }
2340:
1.187 raeburn 2341: sub modify_login_block {
2342: my ($dom,$currentauth) = @_;
2343: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
2344: my ($authnum,%can_assign) =
2345: &Apache::loncommon::get_assignable_auth($dom);
1.205 raeburn 2346: my ($authformcurrent,@authform_others,$show_override_msg);
1.187 raeburn 2347: if ($currentauth=~/^krb(4|5):/) {
2348: $authformcurrent=$authformkrb;
2349: if ($can_assign{'int'}) {
1.205 raeburn 2350: push(@authform_others,$authformint);
1.187 raeburn 2351: }
2352: if ($can_assign{'loc'}) {
1.205 raeburn 2353: push(@authform_others,$authformloc);
1.187 raeburn 2354: }
2355: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
2356: $show_override_msg = 1;
2357: }
2358: } elsif ($currentauth=~/^internal:/) {
2359: $authformcurrent=$authformint;
2360: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205 raeburn 2361: push(@authform_others,$authformkrb);
1.187 raeburn 2362: }
2363: if ($can_assign{'loc'}) {
1.205 raeburn 2364: push(@authform_others,$authformloc);
1.187 raeburn 2365: }
2366: if ($can_assign{'int'}) {
2367: $show_override_msg = 1;
2368: }
2369: } elsif ($currentauth=~/^unix:/) {
2370: $authformcurrent=$authformfsys;
2371: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205 raeburn 2372: push(@authform_others,$authformkrb);
1.187 raeburn 2373: }
2374: if ($can_assign{'int'}) {
1.205 raeburn 2375: push(@authform_others,$authformint);
1.187 raeburn 2376: }
2377: if ($can_assign{'loc'}) {
1.205 raeburn 2378: push(@authform_others,$authformloc);
1.187 raeburn 2379: }
2380: if ($can_assign{'fsys'}) {
2381: $show_override_msg = 1;
2382: }
2383: } elsif ($currentauth=~/^localauth:/) {
2384: $authformcurrent=$authformloc;
2385: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205 raeburn 2386: push(@authform_others,$authformkrb);
1.187 raeburn 2387: }
2388: if ($can_assign{'int'}) {
1.205 raeburn 2389: push(@authform_others,$authformint);
1.187 raeburn 2390: }
2391: if ($can_assign{'loc'}) {
2392: $show_override_msg = 1;
2393: }
2394: }
2395: if ($show_override_msg) {
1.205 raeburn 2396: $authformcurrent = '<table><tr><td colspan="3">'.$authformcurrent.
2397: '</td></tr>'."\n".
2398: '<tr><td> </td>'.
2399: '<td><b>'.&mt('Currently in use').'</b></td>'.
2400: '<td align="right"><span class="LC_cusr_emph">'.
1.187 raeburn 2401: &mt('will override current values').
1.205 raeburn 2402: '</span></td></tr></table>';
1.187 raeburn 2403: }
1.205 raeburn 2404: return ($authformcurrent,$show_override_msg,@authform_others);
1.187 raeburn 2405: }
2406:
1.188 raeburn 2407: sub personal_data_display {
1.391 raeburn 2408: my ($ccuname,$ccdomain,$newuser,$context,$inst_results,$rolesarray,
1.410 raeburn 2409: $now,$captchaform,$emailusername,$usertype) = @_;
1.388 bisitz 2410: my ($output,%userenv,%canmodify,%canmodify_status);
1.219 raeburn 2411: my @userinfo = ('firstname','middlename','lastname','generation',
2412: 'permanentemail','id');
1.252 raeburn 2413: my $rowcount = 0;
2414: my $editable = 0;
1.391 raeburn 2415: my %textboxsize = (
2416: firstname => '15',
2417: middlename => '15',
2418: lastname => '15',
2419: generation => '5',
2420: permanentemail => '25',
2421: id => '15',
2422: );
2423:
2424: my %lt=&Apache::lonlocal::texthash(
2425: 'pd' => "Personal Data",
2426: 'firstname' => "First Name",
2427: 'middlename' => "Middle Name",
2428: 'lastname' => "Last Name",
2429: 'generation' => "Generation",
2430: 'permanentemail' => "Permanent e-mail address",
2431: 'id' => "Student/Employee ID",
2432: 'lg' => "Login Data",
2433: 'inststatus' => "Affiliation",
2434: 'email' => 'E-mail address',
2435: 'valid' => 'Validation',
2436: );
2437:
2438: %canmodify_status =
1.286 raeburn 2439: &Apache::lonuserutils::can_modify_userinfo($context,$ccdomain,
2440: ['inststatus'],$rolesarray);
1.253 raeburn 2441: if (!$newuser) {
1.188 raeburn 2442: # Get the users information
2443: %userenv = &Apache::lonnet::get('environment',
2444: ['firstname','middlename','lastname','generation',
1.286 raeburn 2445: 'permanentemail','id','inststatus'],$ccdomain,$ccuname);
1.219 raeburn 2446: %canmodify =
2447: &Apache::lonuserutils::can_modify_userinfo($context,$ccdomain,
1.252 raeburn 2448: \@userinfo,$rolesarray);
1.257 raeburn 2449: } elsif ($context eq 'selfcreate') {
1.391 raeburn 2450: if ($newuser eq 'email') {
1.396 raeburn 2451: if (ref($emailusername) eq 'HASH') {
2452: if (ref($emailusername->{$usertype}) eq 'HASH') {
2453: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
2454: @userinfo = ();
2455: if ((ref($infofields) eq 'ARRAY') && (ref($infotitles) eq 'HASH')) {
2456: foreach my $field (@{$infofields}) {
2457: if ($emailusername->{$usertype}->{$field}) {
2458: push(@userinfo,$field);
2459: $canmodify{$field} = 1;
2460: unless ($textboxsize{$field}) {
2461: $textboxsize{$field} = 25;
2462: }
2463: unless ($lt{$field}) {
2464: $lt{$field} = $infotitles->{$field};
2465: }
2466: if ($emailusername->{$usertype}->{$field} eq 'required') {
2467: $lt{$field} .= '<b>*</b>';
2468: }
1.391 raeburn 2469: }
2470: }
2471: }
2472: }
2473: }
2474: } else {
2475: %canmodify = &selfcreate_canmodify($context,$ccdomain,\@userinfo,
2476: $inst_results,$rolesarray);
2477: }
1.188 raeburn 2478: }
1.391 raeburn 2479:
1.188 raeburn 2480: my $genhelp=&Apache::loncommon::help_open_topic('Generation');
2481: $output = '<h3>'.$lt{'pd'}.'</h3>'.
2482: &Apache::lonhtmlcommon::start_pick_box();
1.391 raeburn 2483: if (($context eq 'selfcreate') && ($newuser eq 'email')) {
1.396 raeburn 2484: $output .= &Apache::lonhtmlcommon::row_title($lt{'email'}.'<b>*</b>',undef,
1.391 raeburn 2485: 'LC_oddrow_value')."\n".
1.394 raeburn 2486: '<input type="text" name="uname" size="25" value="" autocomplete="off" />';
1.391 raeburn 2487: $rowcount ++;
2488: $output .= &Apache::lonhtmlcommon::row_closure(1);
1.408 raeburn 2489: my $upassone = '<input type="password" name="upass'.$now.'" size="20" autocomplete="off" />';
2490: my $upasstwo = '<input type="password" name="upasscheck'.$now.'" size="20" autocomplete="off" />';
1.396 raeburn 2491: $output .= &Apache::lonhtmlcommon::row_title(&mt('Password').'<b>*</b>',
1.391 raeburn 2492: 'LC_pick_box_title',
2493: 'LC_oddrow_value')."\n".
2494: $upassone."\n".
2495: &Apache::lonhtmlcommon::row_closure(1)."\n".
1.396 raeburn 2496: &Apache::lonhtmlcommon::row_title(&mt('Confirm password').'<b>*</b>',
1.391 raeburn 2497: 'LC_pick_box_title',
2498: 'LC_oddrow_value')."\n".
2499: $upasstwo.
2500: &Apache::lonhtmlcommon::row_closure()."\n";
2501: }
1.188 raeburn 2502: foreach my $item (@userinfo) {
2503: my $rowtitle = $lt{$item};
1.252 raeburn 2504: my $hiderow = 0;
1.188 raeburn 2505: if ($item eq 'generation') {
2506: $rowtitle = $genhelp.$rowtitle;
2507: }
1.252 raeburn 2508: my $row = &Apache::lonhtmlcommon::row_title($rowtitle,undef,'LC_oddrow_value')."\n";
1.188 raeburn 2509: if ($newuser) {
1.210 raeburn 2510: if (ref($inst_results) eq 'HASH') {
2511: if ($inst_results->{$item} ne '') {
1.252 raeburn 2512: $row .= '<input type="hidden" name="c'.$item.'" value="'.$inst_results->{$item}.'" />'.$inst_results->{$item};
1.210 raeburn 2513: } else {
1.252 raeburn 2514: if ($context eq 'selfcreate') {
1.391 raeburn 2515: if ($canmodify{$item}) {
1.394 raeburn 2516: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" autocomplete="off" />';
1.252 raeburn 2517: $editable ++;
2518: } else {
2519: $hiderow = 1;
2520: }
1.253 raeburn 2521: } else {
2522: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
1.252 raeburn 2523: }
1.210 raeburn 2524: }
1.188 raeburn 2525: } else {
1.252 raeburn 2526: if ($context eq 'selfcreate') {
1.401 raeburn 2527: if ($canmodify{$item}) {
2528: if ($newuser eq 'email') {
2529: $row .= '<input type="text" name="'.$item.'" size="'.$textboxsize{$item}.'" value="" autocomplete="off" />';
1.287 raeburn 2530: } else {
1.401 raeburn 2531: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" autocomplete="off" />';
1.287 raeburn 2532: }
1.401 raeburn 2533: $editable ++;
2534: } else {
2535: $hiderow = 1;
1.252 raeburn 2536: }
1.253 raeburn 2537: } else {
2538: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
1.252 raeburn 2539: }
1.188 raeburn 2540: }
2541: } else {
1.219 raeburn 2542: if ($canmodify{$item}) {
1.252 raeburn 2543: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="'.$userenv{$item}.'" />';
1.393 raeburn 2544: if (($item eq 'id') && (!$newuser)) {
2545: $row .= '<br />'.&Apache::lonuserutils::forceid_change($context);
2546: }
1.188 raeburn 2547: } else {
1.252 raeburn 2548: $row .= $userenv{$item};
1.188 raeburn 2549: }
2550: }
1.252 raeburn 2551: $row .= &Apache::lonhtmlcommon::row_closure(1);
2552: if (!$hiderow) {
2553: $output .= $row;
2554: $rowcount ++;
2555: }
1.188 raeburn 2556: }
1.286 raeburn 2557: if (($canmodify_status{'inststatus'}) || ($context ne 'selfcreate')) {
2558: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($ccdomain);
2559: if (ref($types) eq 'ARRAY') {
2560: if (@{$types} > 0) {
2561: my ($hiderow,$shown);
2562: if ($canmodify_status{'inststatus'}) {
2563: $shown = &pick_inst_statuses($userenv{'inststatus'},$usertypes,$types);
2564: } else {
2565: if ($userenv{'inststatus'} eq '') {
2566: $hiderow = 1;
1.334 raeburn 2567: } else {
2568: my @showitems;
2569: foreach my $item ( map { &unescape($_); } split(':',$userenv{'inststatus'})) {
2570: if (exists($usertypes->{$item})) {
2571: push(@showitems,$usertypes->{$item});
2572: } else {
2573: push(@showitems,$item);
2574: }
2575: }
2576: if (@showitems) {
2577: $shown = join(', ',@showitems);
2578: } else {
2579: $hiderow = 1;
2580: }
1.286 raeburn 2581: }
2582: }
2583: if (!$hiderow) {
1.389 bisitz 2584: my $row = &Apache::lonhtmlcommon::row_title(&mt('Affiliations'),undef,'LC_oddrow_value')."\n".
1.286 raeburn 2585: $shown.&Apache::lonhtmlcommon::row_closure(1);
2586: if ($context eq 'selfcreate') {
2587: $rowcount ++;
2588: }
2589: $output .= $row;
2590: }
2591: }
2592: }
2593: }
1.391 raeburn 2594: if (($context eq 'selfcreate') && ($newuser eq 'email')) {
2595: if ($captchaform) {
1.410 raeburn 2596: $output .= &Apache::lonhtmlcommon::row_title($lt{'valid'}.'*',
2597: 'LC_pick_box_title')."\n".
2598: $captchaform."\n".'<br /><br />'.
1.391 raeburn 2599: &Apache::lonhtmlcommon::row_closure(1);
2600: $rowcount ++;
2601: }
2602: my $submit_text = &mt('Create account');
2603: $output .= &Apache::lonhtmlcommon::row_title()."\n".
2604: '<br /><input type="submit" name="createaccount" value="'.
2605: $submit_text.'" />'.
1.396 raeburn 2606: '<input type="hidden" name="type" value="'.$usertype.'" />'.
1.391 raeburn 2607: &Apache::lonhtmlcommon::row_closure(1);
2608: }
1.188 raeburn 2609: $output .= &Apache::lonhtmlcommon::end_pick_box();
1.206 raeburn 2610: if (wantarray) {
1.252 raeburn 2611: if ($context eq 'selfcreate') {
2612: return($output,$rowcount,$editable);
2613: } else {
1.388 bisitz 2614: return $output;
1.252 raeburn 2615: }
1.206 raeburn 2616: } else {
2617: return $output;
2618: }
1.188 raeburn 2619: }
2620:
1.286 raeburn 2621: sub pick_inst_statuses {
2622: my ($curr,$usertypes,$types) = @_;
2623: my ($output,$rem,@currtypes);
2624: if ($curr ne '') {
2625: @currtypes = map { &unescape($_); } split(/:/,$curr);
2626: }
2627: my $numinrow = 2;
2628: if (ref($types) eq 'ARRAY') {
2629: $output = '<table>';
2630: my $lastcolspan;
2631: for (my $i=0; $i<@{$types}; $i++) {
2632: if (defined($usertypes->{$types->[$i]})) {
2633: my $rem = $i%($numinrow);
2634: if ($rem == 0) {
2635: if ($i<@{$types}-1) {
2636: if ($i > 0) {
2637: $output .= '</tr>';
2638: }
2639: $output .= '<tr>';
2640: }
2641: } elsif ($i==@{$types}-1) {
2642: my $colsleft = $numinrow - $rem;
2643: if ($colsleft > 1) {
2644: $lastcolspan = ' colspan="'.$colsleft.'"';
2645: }
2646: }
2647: my $check = ' ';
2648: if (grep(/^\Q$types->[$i]\E$/,@currtypes)) {
2649: $check = ' checked="checked" ';
2650: }
2651: $output .= '<td class="LC_left_item"'.$lastcolspan.'>'.
2652: '<span class="LC_nobreak"><label>'.
2653: '<input type="checkbox" name="inststatus" '.
2654: 'value="'.$types->[$i].'"'.$check.'/>'.
2655: $usertypes->{$types->[$i]}.'</label></span></td>';
2656: }
2657: }
2658: $output .= '</tr></table>';
2659: }
2660: return $output;
2661: }
2662:
1.257 raeburn 2663: sub selfcreate_canmodify {
2664: my ($context,$dom,$userinfo,$inst_results,$rolesarray) = @_;
2665: if (ref($inst_results) eq 'HASH') {
2666: my @inststatuses = &get_inststatuses($inst_results);
2667: if (@inststatuses == 0) {
2668: @inststatuses = ('default');
2669: }
2670: $rolesarray = \@inststatuses;
2671: }
2672: my %canmodify =
2673: &Apache::lonuserutils::can_modify_userinfo($context,$dom,$userinfo,
2674: $rolesarray);
2675: return %canmodify;
2676: }
2677:
1.252 raeburn 2678: sub get_inststatuses {
2679: my ($insthashref) = @_;
2680: my @inststatuses = ();
2681: if (ref($insthashref) eq 'HASH') {
2682: if (ref($insthashref->{'inststatus'}) eq 'ARRAY') {
2683: @inststatuses = @{$insthashref->{'inststatus'}};
2684: }
2685: }
2686: return @inststatuses;
2687: }
2688:
1.4 www 2689: # ================================================================= Phase Three
1.42 matthew 2690: sub update_user_data {
1.375 raeburn 2691: my ($r,$context,$crstype,$brcrum,$showcredits) = @_;
1.101 albertel 2692: my $uhome=&Apache::lonnet::homeserver($env{'form.ccuname'},
2693: $env{'form.ccdomain'});
1.27 matthew 2694: # Error messages
1.188 raeburn 2695: my $error = '<span class="LC_error">'.&mt('Error').': ';
1.193 raeburn 2696: my $end = '</span><br /><br />';
2697: my $rtnlink = '<a href="javascript:backPage(document.userupdate,'.
1.188 raeburn 2698: "'$env{'form.prevphase'}','modify')".'" />'.
1.219 raeburn 2699: &mt('Return to previous page').'</a>'.
2700: &Apache::loncommon::end_page();
2701: my $now = time;
1.40 www 2702: my $title;
1.101 albertel 2703: if (exists($env{'form.makeuser'})) {
1.40 www 2704: $title='Set Privileges for New User';
2705: } else {
2706: $title='Modify User Privileges';
2707: }
1.213 raeburn 2708: my $newuser = 0;
1.160 raeburn 2709: my ($jsback,$elements) = &crumb_utilities();
2710: my $jscript = '<script type="text/javascript">'."\n".
1.301 bisitz 2711: '// <![CDATA['."\n".
2712: $jsback."\n".
2713: '// ]]>'."\n".
2714: '</script>'."\n";
1.422 raeburn 2715: my %breadcrumb_text = &singleuser_breadcrumb($crstype,$context,$env{'form.ccdomain'});
1.351 raeburn 2716: push (@{$brcrum},
2717: {href => "javascript:backPage(document.userupdate)",
2718: text => $breadcrumb_text{'search'},
2719: faq => 282,
2720: bug => 'Instructor Interface',}
2721: );
2722: if ($env{'form.prevphase'} eq 'userpicked') {
2723: push(@{$brcrum},
2724: {href => "javascript:backPage(document.userupdate,'get_user_info','select')",
2725: text => $breadcrumb_text{'userpicked'},
2726: faq => 282,
2727: bug => 'Instructor Interface',});
1.233 raeburn 2728: }
1.224 raeburn 2729: my $helpitem = 'Course_Change_Privileges';
2730: if ($env{'form.action'} eq 'singlestudent') {
2731: $helpitem = 'Course_Add_Student';
2732: }
1.351 raeburn 2733: push(@{$brcrum},
2734: {href => "javascript:backPage(document.userupdate,'$env{'form.prevphase'}','modify')",
2735: text => $breadcrumb_text{'modify'},
2736: faq => 282,
2737: bug => 'Instructor Interface',},
2738: {href => "/adm/createuser",
2739: text => "Result",
2740: faq => 282,
2741: bug => 'Instructor Interface',
2742: help => $helpitem});
2743: my $args = {bread_crumbs => $brcrum,
2744: bread_crumbs_component => 'User Management'};
2745: if ($env{'form.popup'}) {
2746: $args->{'no_nav_bar'} = 1;
2747: }
2748: $r->print(&Apache::loncommon::start_page($title,$jscript,$args));
1.188 raeburn 2749: $r->print(&update_result_form($uhome));
1.27 matthew 2750: # Check Inputs
1.101 albertel 2751: if (! $env{'form.ccuname'} ) {
1.193 raeburn 2752: $r->print($error.&mt('No login name specified').'.'.$end.$rtnlink);
1.27 matthew 2753: return;
2754: }
1.138 albertel 2755: if ( $env{'form.ccuname'} ne
2756: &LONCAPA::clean_username($env{'form.ccuname'}) ) {
1.281 bisitz 2757: $r->print($error.&mt('Invalid login name.').' '.
2758: &mt('Only letters, numbers, periods, dashes, @, and underscores are valid.').
1.193 raeburn 2759: $end.$rtnlink);
1.27 matthew 2760: return;
2761: }
1.101 albertel 2762: if (! $env{'form.ccdomain'} ) {
1.193 raeburn 2763: $r->print($error.&mt('No domain specified').'.'.$end.$rtnlink);
1.27 matthew 2764: return;
2765: }
1.138 albertel 2766: if ( $env{'form.ccdomain'} ne
2767: &LONCAPA::clean_domain($env{'form.ccdomain'}) ) {
1.281 bisitz 2768: $r->print($error.&mt('Invalid domain name.').' '.
2769: &mt('Only letters, numbers, periods, dashes, and underscores are valid.').
1.193 raeburn 2770: $end.$rtnlink);
1.27 matthew 2771: return;
2772: }
1.219 raeburn 2773: if ($uhome eq 'no_host') {
2774: $newuser = 1;
2775: }
1.101 albertel 2776: if (! exists($env{'form.makeuser'})) {
1.29 matthew 2777: # Modifying an existing user, so check the validity of the name
2778: if ($uhome eq 'no_host') {
1.389 bisitz 2779: $r->print(
2780: $error
2781: .'<p class="LC_error">'
2782: .&mt('Unable to determine home server for [_1] in domain [_2].',
2783: '"'.$env{'form.ccuname'}.'"','"'.$env{'form.ccdomain'}.'"')
2784: .'</p>');
1.29 matthew 2785: return;
2786: }
2787: }
1.27 matthew 2788: # Determine authentication method and password for the user being modified
2789: my $amode='';
2790: my $genpwd='';
1.101 albertel 2791: if ($env{'form.login'} eq 'krb') {
1.41 albertel 2792: $amode='krb';
1.101 albertel 2793: $amode.=$env{'form.krbver'};
2794: $genpwd=$env{'form.krbarg'};
2795: } elsif ($env{'form.login'} eq 'int') {
1.27 matthew 2796: $amode='internal';
1.101 albertel 2797: $genpwd=$env{'form.intarg'};
2798: } elsif ($env{'form.login'} eq 'fsys') {
1.27 matthew 2799: $amode='unix';
1.101 albertel 2800: $genpwd=$env{'form.fsysarg'};
2801: } elsif ($env{'form.login'} eq 'loc') {
1.27 matthew 2802: $amode='localauth';
1.101 albertel 2803: $genpwd=$env{'form.locarg'};
1.27 matthew 2804: $genpwd=" " if (!$genpwd);
1.101 albertel 2805: } elsif (($env{'form.login'} eq 'nochange') ||
2806: ($env{'form.login'} eq '' )) {
1.34 matthew 2807: # There is no need to tell the user we did not change what they
2808: # did not ask us to change.
1.35 matthew 2809: # If they are creating a new user but have not specified login
2810: # information this will be caught below.
1.30 matthew 2811: } else {
1.367 golterma 2812: $r->print($error.&mt('Invalid login mode or password').$end.$rtnlink);
2813: return;
1.27 matthew 2814: }
1.164 albertel 2815:
1.188 raeburn 2816: $r->print('<h3>'.&mt('User [_1] in domain [_2]',
1.367 golterma 2817: $env{'form.ccuname'}.' ('.&Apache::loncommon::plainname($env{'form.ccuname'},
2818: $env{'form.ccdomain'}).')', $env{'form.ccdomain'}).'</h3>');
2819: my %prog_state = &Apache::lonhtmlcommon::Create_PrgWin($r,2);
1.344 bisitz 2820:
1.193 raeburn 2821: my (%alerts,%rulematch,%inst_results,%curr_rules);
1.334 raeburn 2822: my @userinfo = ('firstname','middlename','lastname','generation','permanentemail','id');
1.361 raeburn 2823: my @usertools = ('aboutme','blog','webdav','portfolio');
1.411 raeburn 2824: my @requestcourses = ('official','unofficial','community','textbook','placement');
1.362 raeburn 2825: my @requestauthor = ('requestauthor');
1.286 raeburn 2826: my ($othertitle,$usertypes,$types) =
2827: &Apache::loncommon::sorted_inst_types($env{'form.ccdomain'});
1.334 raeburn 2828: my %canmodify_status =
2829: &Apache::lonuserutils::can_modify_userinfo($context,$env{'form.ccdomain'},
2830: ['inststatus']);
1.101 albertel 2831: if ($env{'form.makeuser'}) {
1.164 albertel 2832: $r->print('<h3>'.&mt('Creating new account.').'</h3>');
1.27 matthew 2833: # Check for the authentication mode and password
2834: if (! $amode || ! $genpwd) {
1.193 raeburn 2835: $r->print($error.&mt('Invalid login mode or password').$end.$rtnlink);
1.27 matthew 2836: return;
1.18 albertel 2837: }
1.29 matthew 2838: # Determine desired host
1.101 albertel 2839: my $desiredhost = $env{'form.hserver'};
1.29 matthew 2840: if (lc($desiredhost) eq 'default') {
2841: $desiredhost = undef;
2842: } else {
1.147 albertel 2843: my %home_servers =
2844: &Apache::lonnet::get_servers($env{'form.ccdomain'},'library');
1.29 matthew 2845: if (! exists($home_servers{$desiredhost})) {
1.193 raeburn 2846: $r->print($error.&mt('Invalid home server specified').$end.$rtnlink);
2847: return;
2848: }
2849: }
2850: # Check ID format
2851: my %checkhash;
2852: my %checks = ('id' => 1);
2853: %{$checkhash{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}}} = (
1.219 raeburn 2854: 'newuser' => $newuser,
1.196 raeburn 2855: 'id' => $env{'form.cid'},
1.193 raeburn 2856: );
1.196 raeburn 2857: if ($env{'form.cid'} ne '') {
2858: &Apache::loncommon::user_rule_check(\%checkhash,\%checks,\%alerts,
2859: \%rulematch,\%inst_results,\%curr_rules);
2860: if (ref($alerts{'id'}) eq 'HASH') {
2861: if (ref($alerts{'id'}{$env{'form.ccdomain'}}) eq 'HASH') {
2862: my $domdesc =
2863: &Apache::lonnet::domain($env{'form.ccdomain'},'description');
2864: if ($alerts{'id'}{$env{'form.ccdomain'}}{$env{'form.cid'}}) {
2865: my $userchkmsg;
2866: if (ref($curr_rules{$env{'form.ccdomain'}}) eq 'HASH') {
2867: $userchkmsg =
2868: &Apache::loncommon::instrule_disallow_msg('id',
2869: $domdesc,1).
2870: &Apache::loncommon::user_rule_formats($env{'form.ccdomain'},
2871: $domdesc,$curr_rules{$env{'form.ccdomain'}}{'id'},'id');
2872: }
2873: $r->print($error.&mt('Invalid ID format').$end.
2874: $userchkmsg.$rtnlink);
2875: return;
2876: }
2877: }
1.29 matthew 2878: }
2879: }
1.367 golterma 2880: &Apache::lonhtmlcommon::Increment_PrgWin($r, \%prog_state);
1.27 matthew 2881: # Call modifyuser
2882: my $result = &Apache::lonnet::modifyuser
1.193 raeburn 2883: ($env{'form.ccdomain'},$env{'form.ccuname'},$env{'form.cid'},
1.188 raeburn 2884: $amode,$genpwd,$env{'form.cfirstname'},
2885: $env{'form.cmiddlename'},$env{'form.clastname'},
2886: $env{'form.cgeneration'},undef,$desiredhost,
2887: $env{'form.cpermanentemail'});
1.77 www 2888: $r->print(&mt('Generating user').': '.$result);
1.219 raeburn 2889: $uhome = &Apache::lonnet::homeserver($env{'form.ccuname'},
1.101 albertel 2890: $env{'form.ccdomain'});
1.334 raeburn 2891: my (%changeHash,%newcustom,%changed,%changedinfo);
1.267 raeburn 2892: if ($uhome ne 'no_host') {
1.334 raeburn 2893: if ($context eq 'domain') {
1.378 raeburn 2894: foreach my $name ('portfolio','author') {
2895: if ($env{'form.custom_'.$name.'quota'} == 1) {
2896: if ($env{'form.'.$name.'quota'} eq '') {
2897: $newcustom{$name.'quota'} = 0;
2898: } else {
2899: $newcustom{$name.'quota'} = $env{'form.'.$name.'quota'};
2900: $newcustom{$name.'quota'} =~ s/[^\d\.]//g;
2901: }
2902: if ("a_admin($newcustom{$name.'quota'},\%changeHash,$name)) {
2903: $changed{$name.'quota'} = 1;
2904: }
1.334 raeburn 2905: }
2906: }
2907: foreach my $item (@usertools) {
2908: if ($env{'form.custom'.$item} == 1) {
2909: $newcustom{$item} = $env{'form.tools_'.$item};
2910: $changed{$item} = &tool_admin($item,$newcustom{$item},
2911: \%changeHash,'tools');
2912: }
1.267 raeburn 2913: }
1.334 raeburn 2914: foreach my $item (@requestcourses) {
1.341 raeburn 2915: if ($env{'form.custom'.$item} == 1) {
2916: $newcustom{$item} = $env{'form.crsreq_'.$item};
2917: if ($env{'form.crsreq_'.$item} eq 'autolimit') {
2918: $newcustom{$item} .= '=';
1.383 raeburn 2919: $env{'form.crsreq_'.$item.'_limit'} =~ s/\D+//g;
2920: if ($env{'form.crsreq_'.$item.'_limit'}) {
1.341 raeburn 2921: $newcustom{$item} .= $env{'form.crsreq_'.$item.'_limit'};
2922: }
1.334 raeburn 2923: }
1.341 raeburn 2924: $changed{$item} = &tool_admin($item,$newcustom{$item},
2925: \%changeHash,'requestcourses');
1.334 raeburn 2926: }
1.275 raeburn 2927: }
1.362 raeburn 2928: if ($env{'form.customrequestauthor'} == 1) {
2929: $newcustom{'requestauthor'} = $env{'form.requestauthor'};
2930: $changed{'requestauthor'} = &tool_admin('requestauthor',
2931: $newcustom{'requestauthor'},
2932: \%changeHash,'requestauthor');
2933: }
1.414 raeburn 2934: if (&Apache::lonnet::allowed('cdh',$env{'request.role.domain'})) {
2935: my @adds = &Apache::loncommon::get_env_multiple('form.adhocroleadd');
2936: if (&adhocrole_changes(\%changeHash)) {
2937: $changed{'adhocroles.'.$env{'request.role.domain'}} = $changeHash{'adhocroles.'.$env{'request.role.domain'}};
1.417 raeburn 2938: }
1.414 raeburn 2939: }
1.275 raeburn 2940: }
1.334 raeburn 2941: if ($canmodify_status{'inststatus'}) {
2942: if (exists($env{'form.inststatus'})) {
2943: my @inststatuses = &Apache::loncommon::get_env_multiple('form.inststatus');
2944: if (@inststatuses > 0) {
2945: $changeHash{'inststatus'} = join(',',@inststatuses);
2946: $changed{'inststatus'} = $changeHash{'inststatus'};
1.306 raeburn 2947: }
2948: }
1.232 raeburn 2949: }
1.334 raeburn 2950: if (keys(%changed)) {
2951: foreach my $item (@userinfo) {
2952: $changeHash{$item} = $env{'form.c'.$item};
1.286 raeburn 2953: }
1.267 raeburn 2954: my $chgresult =
2955: &Apache::lonnet::put('environment',\%changeHash,
2956: $env{'form.ccdomain'},$env{'form.ccuname'});
2957: }
1.232 raeburn 2958: }
1.219 raeburn 2959: $r->print('<br />'.&mt('Home server').': '.$uhome.' '.
2960: &Apache::lonnet::hostname($uhome));
1.101 albertel 2961: } elsif (($env{'form.login'} ne 'nochange') &&
2962: ($env{'form.login'} ne '' )) {
1.27 matthew 2963: # Modify user privileges
2964: if (! $amode || ! $genpwd) {
1.193 raeburn 2965: $r->print($error.'Invalid login mode or password'.$end.$rtnlink);
1.27 matthew 2966: return;
1.20 harris41 2967: }
1.395 bisitz 2968: # Only allow authentication modification if the person has authority
1.101 albertel 2969: if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'})) {
1.20 harris41 2970: $r->print('Modifying authentication: '.
1.31 matthew 2971: &Apache::lonnet::modifyuserauth(
1.101 albertel 2972: $env{'form.ccdomain'},$env{'form.ccuname'},
1.21 harris41 2973: $amode,$genpwd));
1.102 albertel 2974: $r->print('<br />'.&mt('Home server').': '.&Apache::lonnet::homeserver
1.101 albertel 2975: ($env{'form.ccuname'},$env{'form.ccdomain'}));
1.4 www 2976: } else {
1.27 matthew 2977: # Okay, this is a non-fatal error.
1.395 bisitz 2978: $r->print($error.&mt('You do not have the authority to modify this users authentication information.').$end);
1.27 matthew 2979: }
1.28 matthew 2980: }
1.344 bisitz 2981: $r->rflush(); # Finish display of header before time consuming actions start
1.367 golterma 2982: &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state);
1.28 matthew 2983: ##
1.375 raeburn 2984: my (@userroles,%userupdate,$cnum,$cdom,$defaultcredits,%namechanged);
1.213 raeburn 2985: if ($context eq 'course') {
1.375 raeburn 2986: ($cnum,$cdom) =
2987: &Apache::lonuserutils::get_course_identity();
1.318 raeburn 2988: $crstype = &Apache::loncommon::course_type($cdom.'_'.$cnum);
1.375 raeburn 2989: if ($showcredits) {
2990: $defaultcredits = &Apache::lonuserutils::get_defaultcredits($cdom,$cnum);
2991: }
1.213 raeburn 2992: }
1.101 albertel 2993: if (! $env{'form.makeuser'} ) {
1.28 matthew 2994: # Check for need to change
2995: my %userenv = &Apache::lonnet::get
1.134 raeburn 2996: ('environment',['firstname','middlename','lastname','generation',
1.378 raeburn 2997: 'id','permanentemail','portfolioquota','authorquota','inststatus',
2998: 'tools.aboutme','tools.blog','tools.webdav','tools.portfolio',
1.361 raeburn 2999: 'requestcourses.official','requestcourses.unofficial',
1.384 raeburn 3000: 'requestcourses.community','requestcourses.textbook',
3001: 'reqcrsotherdom.official','reqcrsotherdom.unofficial',
3002: 'reqcrsotherdom.community','reqcrsotherdom.textbook',
1.414 raeburn 3003: 'reqcrsotherdom.placement','requestauthor',
3004: 'adhocroles.'.$env{'request.role.domain'}],
1.160 raeburn 3005: $env{'form.ccdomain'},$env{'form.ccuname'});
1.28 matthew 3006: my ($tmp) = keys(%userenv);
3007: if ($tmp =~ /^(con_lost|error)/i) {
3008: %userenv = ();
3009: }
1.206 raeburn 3010: my $no_forceid_alert;
3011: # Check to see if user information can be changed
3012: my %domconfig =
3013: &Apache::lonnet::get_dom('configuration',['usermodification'],
3014: $env{'form.ccdomain'});
1.213 raeburn 3015: my @statuses = ('active','future');
3016: my %roles = &Apache::lonnet::get_my_roles($env{'form.ccuname'},$env{'form.ccdomain'},'userroles',\@statuses,undef,$env{'request.role.domain'});
3017: my ($auname,$audom);
1.220 raeburn 3018: if ($context eq 'author') {
1.206 raeburn 3019: $auname = $env{'user.name'};
3020: $audom = $env{'user.domain'};
3021: }
3022: foreach my $item (keys(%roles)) {
1.220 raeburn 3023: my ($rolenum,$roledom,$role) = split(/:/,$item,-1);
1.206 raeburn 3024: if ($context eq 'course') {
3025: if ($cnum ne '' && $cdom ne '') {
3026: if ($rolenum eq $cnum && $roledom eq $cdom) {
3027: if (!grep(/^\Q$role\E$/,@userroles)) {
3028: push(@userroles,$role);
3029: }
3030: }
3031: }
3032: } elsif ($context eq 'author') {
3033: if ($rolenum eq $auname && $roledom eq $audom) {
3034: if (!grep(/^\Q$role\E$/,@userroles)) {
3035: push(@userroles,$role);
3036: }
3037: }
3038: }
3039: }
1.220 raeburn 3040: if ($env{'form.action'} eq 'singlestudent') {
3041: if (!grep(/^st$/,@userroles)) {
3042: push(@userroles,'st');
3043: }
3044: } else {
3045: # Check for course or co-author roles being activated or re-enabled
3046: if ($context eq 'author' || $context eq 'course') {
3047: foreach my $key (keys(%env)) {
3048: if ($context eq 'author') {
3049: if ($key=~/^form\.act_\Q$audom\E_\Q$auname\E_([^_]+)/) {
3050: if (!grep(/^\Q$1\E$/,@userroles)) {
3051: push(@userroles,$1);
3052: }
3053: } elsif ($key =~/^form\.ren\:\Q$audom\E\/\Q$auname\E_([^_]+)/) {
3054: if (!grep(/^\Q$1\E$/,@userroles)) {
3055: push(@userroles,$1);
3056: }
1.206 raeburn 3057: }
1.220 raeburn 3058: } elsif ($context eq 'course') {
3059: if ($key=~/^form\.act_\Q$cdom\E_\Q$cnum\E_([^_]+)/) {
3060: if (!grep(/^\Q$1\E$/,@userroles)) {
3061: push(@userroles,$1);
3062: }
3063: } elsif ($key =~/^form\.ren\:\Q$cdom\E\/\Q$cnum\E(\/?\w*)_([^_]+)/) {
3064: if (!grep(/^\Q$1\E$/,@userroles)) {
3065: push(@userroles,$1);
3066: }
1.206 raeburn 3067: }
3068: }
3069: }
3070: }
3071: }
3072: #Check to see if we can change personal data for the user
3073: my (@mod_disallowed,@longroles);
3074: foreach my $role (@userroles) {
3075: if ($role eq 'cr') {
3076: push(@longroles,'Custom');
3077: } else {
1.318 raeburn 3078: push(@longroles,&Apache::lonnet::plaintext($role,$crstype));
1.206 raeburn 3079: }
3080: }
1.219 raeburn 3081: my %canmodify = &Apache::lonuserutils::can_modify_userinfo($context,$env{'form.ccdomain'},\@userinfo,\@userroles);
3082: foreach my $item (@userinfo) {
1.28 matthew 3083: # Strip leading and trailing whitespace
1.203 raeburn 3084: $env{'form.c'.$item} =~ s/(\s+$|^\s+)//g;
1.219 raeburn 3085: if (!$canmodify{$item}) {
1.207 raeburn 3086: if (defined($env{'form.c'.$item})) {
3087: if ($env{'form.c'.$item} ne $userenv{$item}) {
3088: push(@mod_disallowed,$item);
3089: }
1.206 raeburn 3090: }
3091: $env{'form.c'.$item} = $userenv{$item};
3092: }
1.28 matthew 3093: }
1.259 bisitz 3094: # Check to see if we can change the Student/Employee ID
1.196 raeburn 3095: my $forceid = $env{'form.forceid'};
3096: my $recurseid = $env{'form.recurseid'};
3097: my (%alerts,%rulematch,%idinst_results,%curr_rules,%got_rules);
1.203 raeburn 3098: my %uidhash = &Apache::lonnet::idrget($env{'form.ccdomain'},
3099: $env{'form.ccuname'});
3100: if (($uidhash{$env{'form.ccuname'}}) &&
3101: ($uidhash{$env{'form.ccuname'}}!~/error\:/) &&
3102: (!$forceid)) {
3103: if ($env{'form.cid'} ne $uidhash{$env{'form.ccuname'}}) {
3104: $env{'form.cid'} = $userenv{'id'};
1.293 bisitz 3105: $no_forceid_alert = &mt('New student/employee ID does not match existing ID for this user.')
1.259 bisitz 3106: .'<br />'
3107: .&mt("Change is not permitted without checking the 'Force ID change' checkbox on the previous page.")
3108: .'<br />'."\n";
1.203 raeburn 3109: }
3110: }
3111: if ($env{'form.cid'} ne $userenv{'id'}) {
1.196 raeburn 3112: my $checkhash;
3113: my $checks = { 'id' => 1 };
3114: $checkhash->{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}} =
3115: { 'newuser' => $newuser,
3116: 'id' => $env{'form.cid'},
3117: };
3118: &Apache::loncommon::user_rule_check($checkhash,$checks,
3119: \%alerts,\%rulematch,\%idinst_results,\%curr_rules,\%got_rules);
3120: if (ref($alerts{'id'}) eq 'HASH') {
3121: if (ref($alerts{'id'}{$env{'form.ccdomain'}}) eq 'HASH') {
1.203 raeburn 3122: $env{'form.cid'} = $userenv{'id'};
1.196 raeburn 3123: }
3124: }
3125: }
1.378 raeburn 3126: my (%quotachanged,%oldquota,%newquota,%olddefquota,%newdefquota,
3127: $oldinststatus,$newinststatus,%oldisdefault,%newisdefault,%oldsettings,
1.339 raeburn 3128: %oldsettingstext,%newsettings,%newsettingstext,@disporder,
1.378 raeburn 3129: %oldsettingstatus,%newsettingstatus);
1.334 raeburn 3130: @disporder = ('inststatus');
3131: if ($env{'request.role.domain'} eq $env{'form.ccdomain'}) {
1.362 raeburn 3132: push(@disporder,'requestcourses','requestauthor');
1.334 raeburn 3133: } else {
3134: push(@disporder,'reqcrsotherdom');
3135: }
3136: push(@disporder,('quota','tools'));
1.338 raeburn 3137: $oldinststatus = $userenv{'inststatus'};
1.378 raeburn 3138: foreach my $name ('portfolio','author') {
3139: ($olddefquota{$name},$oldsettingstatus{$name}) =
3140: &Apache::loncommon::default_quota($env{'form.ccdomain'},$oldinststatus,$name);
3141: ($newdefquota{$name},$newsettingstatus{$name}) = ($olddefquota{$name},$oldsettingstatus{$name});
3142: }
1.414 raeburn 3143: push(@disporder,'adhocroles');
1.334 raeburn 3144: my %canshow;
1.220 raeburn 3145: if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
1.334 raeburn 3146: $canshow{'quota'} = 1;
1.220 raeburn 3147: }
1.267 raeburn 3148: if (&Apache::lonnet::allowed('mut',$env{'form.ccdomain'})) {
1.334 raeburn 3149: $canshow{'tools'} = 1;
1.267 raeburn 3150: }
1.275 raeburn 3151: if (&Apache::lonnet::allowed('ccc',$env{'form.ccdomain'})) {
1.334 raeburn 3152: $canshow{'requestcourses'} = 1;
1.300 raeburn 3153: } elsif (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
1.334 raeburn 3154: $canshow{'reqcrsotherdom'} = 1;
1.275 raeburn 3155: }
1.286 raeburn 3156: if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'})) {
1.334 raeburn 3157: $canshow{'inststatus'} = 1;
1.286 raeburn 3158: }
1.362 raeburn 3159: if (&Apache::lonnet::allowed('cau',$env{'form.ccdomain'})) {
3160: $canshow{'requestauthor'} = 1;
3161: }
1.414 raeburn 3162: if (&Apache::lonnet::allowed('cdh',$env{'request.role.domain'})) {
3163: $canshow{'adhocroles'} = 1;
3164: }
1.267 raeburn 3165: my (%changeHash,%changed);
1.286 raeburn 3166: if ($oldinststatus eq '') {
1.334 raeburn 3167: $oldsettings{'inststatus'} = $othertitle;
1.286 raeburn 3168: } else {
3169: if (ref($usertypes) eq 'HASH') {
1.334 raeburn 3170: $oldsettings{'inststatus'} = join(', ',map{ $usertypes->{ &unescape($_) }; } (split(/:/,$userenv{'inststatus'})));
1.286 raeburn 3171: } else {
1.334 raeburn 3172: $oldsettings{'inststatus'} = join(', ',map{ &unescape($_); } (split(/:/,$userenv{'inststatus'})));
1.286 raeburn 3173: }
3174: }
3175: $changeHash{'inststatus'} = $userenv{'inststatus'};
1.334 raeburn 3176: if ($canmodify_status{'inststatus'}) {
3177: $canshow{'inststatus'} = 1;
1.286 raeburn 3178: if (exists($env{'form.inststatus'})) {
3179: my @inststatuses = &Apache::loncommon::get_env_multiple('form.inststatus');
3180: if (@inststatuses > 0) {
3181: $newinststatus = join(':',map { &escape($_); } @inststatuses);
3182: $changeHash{'inststatus'} = $newinststatus;
3183: if ($newinststatus ne $oldinststatus) {
3184: $changed{'inststatus'} = $newinststatus;
1.378 raeburn 3185: foreach my $name ('portfolio','author') {
3186: ($newdefquota{$name},$newsettingstatus{$name}) =
3187: &Apache::loncommon::default_quota($env{'form.ccdomain'},$newinststatus,$name);
3188: }
1.286 raeburn 3189: }
3190: if (ref($usertypes) eq 'HASH') {
1.334 raeburn 3191: $newsettings{'inststatus'} = join(', ',map{ $usertypes->{$_}; } (@inststatuses));
1.286 raeburn 3192: } else {
1.337 raeburn 3193: $newsettings{'inststatus'} = join(', ',@inststatuses);
1.286 raeburn 3194: }
1.334 raeburn 3195: }
3196: } else {
3197: $newinststatus = '';
3198: $changeHash{'inststatus'} = $newinststatus;
3199: $newsettings{'inststatus'} = $othertitle;
3200: if ($newinststatus ne $oldinststatus) {
3201: $changed{'inststatus'} = $changeHash{'inststatus'};
1.378 raeburn 3202: foreach my $name ('portfolio','author') {
3203: ($newdefquota{$name},$newsettingstatus{$name}) =
3204: &Apache::loncommon::default_quota($env{'form.ccdomain'},$newinststatus,$name);
3205: }
1.286 raeburn 3206: }
3207: }
1.334 raeburn 3208: } elsif ($context ne 'selfcreate') {
3209: $canshow{'inststatus'} = 1;
1.337 raeburn 3210: $newsettings{'inststatus'} = $oldsettings{'inststatus'};
1.286 raeburn 3211: }
1.378 raeburn 3212: foreach my $name ('portfolio','author') {
3213: $changeHash{$name.'quota'} = $userenv{$name.'quota'};
3214: }
1.334 raeburn 3215: if ($context eq 'domain') {
1.378 raeburn 3216: foreach my $name ('portfolio','author') {
3217: if ($userenv{$name.'quota'} ne '') {
3218: $oldquota{$name} = $userenv{$name.'quota'};
3219: if ($env{'form.custom_'.$name.'quota'} == 1) {
3220: if ($env{'form.'.$name.'quota'} eq '') {
3221: $newquota{$name} = 0;
3222: } else {
3223: $newquota{$name} = $env{'form.'.$name.'quota'};
3224: $newquota{$name} =~ s/[^\d\.]//g;
3225: }
3226: if ($newquota{$name} != $oldquota{$name}) {
3227: if ("a_admin($newquota{$name},\%changeHash,$name)) {
3228: $changed{$name.'quota'} = 1;
3229: }
3230: }
1.334 raeburn 3231: } else {
1.378 raeburn 3232: if ("a_admin('',\%changeHash,$name)) {
3233: $changed{$name.'quota'} = 1;
3234: $newquota{$name} = $newdefquota{$name};
3235: $newisdefault{$name} = 1;
3236: }
1.334 raeburn 3237: }
1.149 raeburn 3238: } else {
1.378 raeburn 3239: $oldisdefault{$name} = 1;
3240: $oldquota{$name} = $olddefquota{$name};
3241: if ($env{'form.custom_'.$name.'quota'} == 1) {
3242: if ($env{'form.'.$name.'quota'} eq '') {
3243: $newquota{$name} = 0;
3244: } else {
3245: $newquota{$name} = $env{'form.'.$name.'quota'};
3246: $newquota{$name} =~ s/[^\d\.]//g;
3247: }
3248: if ("a_admin($newquota{$name},\%changeHash,$name)) {
3249: $changed{$name.'quota'} = 1;
3250: }
1.334 raeburn 3251: } else {
1.378 raeburn 3252: $newquota{$name} = $newdefquota{$name};
3253: $newisdefault{$name} = 1;
1.334 raeburn 3254: }
1.378 raeburn 3255: }
3256: if ($oldisdefault{$name}) {
3257: $oldsettingstext{'quota'}{$name} = &get_defaultquota_text($oldsettingstatus{$name});
1.383 raeburn 3258: } else {
3259: $oldsettingstext{'quota'}{$name} = &mt('custom quota: [_1] MB',$oldquota{$name});
1.378 raeburn 3260: }
3261: if ($newisdefault{$name}) {
3262: $newsettingstext{'quota'}{$name} = &get_defaultquota_text($newsettingstatus{$name});
1.383 raeburn 3263: } else {
3264: $newsettingstext{'quota'}{$name} = &mt('custom quota: [_1] MB',$newquota{$name});
1.134 raeburn 3265: }
3266: }
1.334 raeburn 3267: &tool_changes('tools',\@usertools,\%oldsettings,\%oldsettingstext,\%userenv,
3268: \%changeHash,\%changed,\%newsettings,\%newsettingstext);
3269: if ($env{'form.ccdomain'} eq $env{'request.role.domain'}) {
3270: &tool_changes('requestcourses',\@requestcourses,\%oldsettings,\%oldsettingstext,
3271: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
1.384 raeburn 3272: &tool_changes('requestauthor',\@requestauthor,\%oldsettings,\%oldsettingstext,
3273: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
1.149 raeburn 3274: } else {
1.334 raeburn 3275: &tool_changes('reqcrsotherdom',\@requestcourses,\%oldsettings,\%oldsettingstext,
3276: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
1.149 raeburn 3277: }
1.414 raeburn 3278: if ($userenv{'adhocroles.'.$env{'request.role.domain'}}) {
3279: $changeHash{'adhocroles.'.$env{'request.role.domain'}} = $userenv{'adhocroles.'.$env{'request.role.domain'}};
3280: }
3281: if (&adhocrole_changes(\%changeHash,\%userenv)) {
3282: $changed{'adhocroles'} = 1;
3283: $oldsettings{'adhocroles'} = $userenv{'adhocroles.'.$env{'request.role.domain'}};
1.417 raeburn 3284: $newsettings{'adhocroles'} = $changeHash{'adhocroles.'.$env{'request.role.domain'}};
1.414 raeburn 3285: }
1.149 raeburn 3286: }
1.334 raeburn 3287: foreach my $item (@userinfo) {
3288: if ($env{'form.c'.$item} ne $userenv{$item}) {
3289: $namechanged{$item} = 1;
3290: }
1.204 raeburn 3291: }
1.378 raeburn 3292: foreach my $name ('portfolio','author') {
1.390 bisitz 3293: $oldsettings{'quota'}{$name} = &mt('[_1] MB',$oldquota{$name});
3294: $newsettings{'quota'}{$name} = &mt('[_1] MB',$newquota{$name});
1.378 raeburn 3295: }
1.334 raeburn 3296: if ((keys(%namechanged) > 0) || (keys(%changed) > 0)) {
1.267 raeburn 3297: my ($chgresult,$namechgresult);
3298: if (keys(%changed) > 0) {
3299: $chgresult =
1.204 raeburn 3300: &Apache::lonnet::put('environment',\%changeHash,
3301: $env{'form.ccdomain'},$env{'form.ccuname'});
1.267 raeburn 3302: if ($chgresult eq 'ok') {
3303: if (($env{'user.name'} eq $env{'form.ccuname'}) &&
3304: ($env{'user.domain'} eq $env{'form.ccdomain'})) {
1.270 raeburn 3305: my %newenvhash;
3306: foreach my $key (keys(%changed)) {
1.411 raeburn 3307: if (($key eq 'official') || ($key eq 'unofficial') ||
3308: ($key eq 'community') || ($key eq 'textbook') ||
3309: ($key eq 'placement')) {
1.279 raeburn 3310: $newenvhash{'environment.requestcourses.'.$key} =
3311: $changeHash{'requestcourses.'.$key};
1.362 raeburn 3312: if ($changeHash{'requestcourses.'.$key}) {
1.332 raeburn 3313: $newenvhash{'environment.canrequest.'.$key} = 1;
1.279 raeburn 3314: } else {
3315: $newenvhash{'environment.canrequest.'.$key} =
3316: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
3317: $key,'reload','requestcourses');
3318: }
1.362 raeburn 3319: } elsif ($key eq 'requestauthor') {
3320: $newenvhash{'environment.'.$key} = $changeHash{$key};
3321: if ($changeHash{$key}) {
3322: $newenvhash{'environment.canrequest.author'} = 1;
3323: } else {
3324: $newenvhash{'environment.canrequest.author'} =
3325: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
3326: $key,'reload','requestauthor');
3327: }
1.414 raeburn 3328: } elsif ($key eq 'adhocroles') {
3329: $newenvhash{'adhocroles.'.$env{'request.role.domain'}} =
3330: $changeHash{'adhocroles.'.$env{'request.role.domain'}};
1.275 raeburn 3331: } elsif ($key ne 'quota') {
1.270 raeburn 3332: $newenvhash{'environment.tools.'.$key} =
3333: $changeHash{'tools.'.$key};
1.279 raeburn 3334: if ($changeHash{'tools.'.$key} ne '') {
3335: $newenvhash{'environment.availabletools.'.$key} =
3336: $changeHash{'tools.'.$key};
3337: } else {
3338: $newenvhash{'environment.availabletools.'.$key} =
1.367 golterma 3339: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
3340: $key,'reload','tools');
1.279 raeburn 3341: }
1.270 raeburn 3342: }
3343: }
1.271 raeburn 3344: if (keys(%newenvhash)) {
3345: &Apache::lonnet::appenv(\%newenvhash);
3346: }
1.267 raeburn 3347: }
3348: }
1.204 raeburn 3349: }
1.334 raeburn 3350: if (keys(%namechanged) > 0) {
1.337 raeburn 3351: foreach my $field (@userinfo) {
3352: $changeHash{$field} = $env{'form.c'.$field};
3353: }
3354: # Make the change
1.204 raeburn 3355: $namechgresult =
3356: &Apache::lonnet::modifyuser($env{'form.ccdomain'},
3357: $env{'form.ccuname'},$changeHash{'id'},undef,undef,
3358: $changeHash{'firstname'},$changeHash{'middlename'},
3359: $changeHash{'lastname'},$changeHash{'generation'},
1.337 raeburn 3360: $changeHash{'id'},undef,$changeHash{'permanentemail'},undef,\@userinfo);
1.220 raeburn 3361: %userupdate = (
3362: lastname => $env{'form.clastname'},
3363: middlename => $env{'form.cmiddlename'},
3364: firstname => $env{'form.cfirstname'},
3365: generation => $env{'form.cgeneration'},
3366: id => $env{'form.cid'},
3367: );
1.204 raeburn 3368: }
1.334 raeburn 3369: if (((keys(%namechanged) > 0) && $namechgresult eq 'ok') ||
1.267 raeburn 3370: ((keys(%changed) > 0) && $chgresult eq 'ok')) {
1.28 matthew 3371: # Tell the user we changed the name
1.334 raeburn 3372: &display_userinfo($r,1,\@disporder,\%canshow,\@requestcourses,
1.362 raeburn 3373: \@usertools,\@requestauthor,\%userenv,\%changed,\%namechanged,
1.334 raeburn 3374: \%oldsettings, \%oldsettingstext,\%newsettings,
3375: \%newsettingstext);
1.203 raeburn 3376: if ($env{'form.cid'} ne $userenv{'id'}) {
3377: &Apache::lonnet::idput($env{'form.ccdomain'},
1.407 raeburn 3378: {$env{'form.ccuname'} => $env{'form.cid'}},$uhome,'ids');
1.203 raeburn 3379: if (($recurseid) &&
3380: (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'}))) {
3381: my $idresult =
3382: &Apache::lonuserutils::propagate_id_change(
3383: $env{'form.ccuname'},$env{'form.ccdomain'},
3384: \%userupdate);
3385: $r->print('<br />'.$idresult.'<br />');
3386: }
1.196 raeburn 3387: }
1.149 raeburn 3388: if (($env{'form.ccdomain'} eq $env{'user.domain'}) &&
3389: ($env{'form.ccuname'} eq $env{'user.name'})) {
3390: my %newenvhash;
3391: foreach my $key (keys(%changeHash)) {
3392: $newenvhash{'environment.'.$key} = $changeHash{$key};
3393: }
1.238 raeburn 3394: &Apache::lonnet::appenv(\%newenvhash);
1.149 raeburn 3395: }
1.28 matthew 3396: } else { # error occurred
1.389 bisitz 3397: $r->print(
3398: '<p class="LC_error">'
3399: .&mt('Unable to successfully change environment for [_1] in domain [_2].',
3400: '"'.$env{'form.ccuname'}.'"',
3401: '"'.$env{'form.ccdomain'}.'"')
3402: .'</p>');
1.28 matthew 3403: }
1.334 raeburn 3404: } else { # End of if ($env ... ) logic
1.275 raeburn 3405: # They did not want to change the users name, quota, tool availability,
3406: # or ability to request creation of courses,
1.267 raeburn 3407: # but we can still tell them what the name and quota and availabilities are
1.334 raeburn 3408: &display_userinfo($r,undef,\@disporder,\%canshow,\@requestcourses,
1.362 raeburn 3409: \@usertools,\@requestauthor,\%userenv,\%changed,\%namechanged,\%oldsettings,
1.334 raeburn 3410: \%oldsettingstext,\%newsettings,\%newsettingstext);
1.28 matthew 3411: }
1.206 raeburn 3412: if (@mod_disallowed) {
3413: my ($rolestr,$contextname);
3414: if (@longroles > 0) {
3415: $rolestr = join(', ',@longroles);
3416: } else {
3417: $rolestr = &mt('No roles');
3418: }
3419: if ($context eq 'course') {
1.399 bisitz 3420: $contextname = 'course';
1.206 raeburn 3421: } elsif ($context eq 'author') {
1.399 bisitz 3422: $contextname = 'co-author';
1.206 raeburn 3423: }
3424: $r->print(&mt('The following fields were not updated: ').'<ul>');
3425: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
3426: foreach my $field (@mod_disallowed) {
3427: $r->print('<li>'.$fieldtitles{$field}.'</li>'."\n");
3428: }
1.207 raeburn 3429: $r->print('</ul>');
3430: if (@mod_disallowed == 1) {
1.399 bisitz 3431: $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 3432: } else {
1.399 bisitz 3433: $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 3434: }
1.292 bisitz 3435: my $helplink = 'javascript:helpMenu('."'display'".')';
3436: $r->print('<span class="LC_cusr_emph">'.$rolestr.'</span><br />'
3437: .&mt('Please contact your [_1]helpdesk[_2] for more information.'
3438: ,'<a href="'.$helplink.'">','</a>')
3439: .'<br />');
1.206 raeburn 3440: }
1.259 bisitz 3441: $r->print('<span class="LC_warning">'
3442: .$no_forceid_alert
3443: .&Apache::lonuserutils::print_namespacing_alerts($env{'form.ccdomain'},\%alerts,\%curr_rules)
3444: .'</span>');
1.4 www 3445: }
1.367 golterma 3446: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
1.220 raeburn 3447: if ($env{'form.action'} eq 'singlestudent') {
1.375 raeburn 3448: &enroll_single_student($r,$uhome,$amode,$genpwd,$now,$newuser,$context,
3449: $crstype,$showcredits,$defaultcredits);
1.386 bisitz 3450: my $linktext = ($crstype eq 'Community' ?
3451: &mt('Enroll Another Member') : &mt('Enroll Another Student'));
3452: $r->print(
3453: &Apache::lonhtmlcommon::actionbox([
3454: '<a href="javascript:backPage(document.userupdate)">'
3455: .($crstype eq 'Community' ?
3456: &mt('Enroll Another Member') : &mt('Enroll Another Student'))
3457: .'</a>']));
1.220 raeburn 3458: } else {
1.375 raeburn 3459: my @rolechanges = &update_roles($r,$context,$showcredits);
1.334 raeburn 3460: if (keys(%namechanged) > 0) {
1.220 raeburn 3461: if ($context eq 'course') {
3462: if (@userroles > 0) {
1.225 raeburn 3463: if ((@rolechanges == 0) ||
3464: (!(grep(/^st$/,@rolechanges)))) {
3465: if (grep(/^st$/,@userroles)) {
3466: my $classlistupdated =
3467: &Apache::lonuserutils::update_classlist($cdom,
1.220 raeburn 3468: $cnum,$env{'form.ccdomain'},
3469: $env{'form.ccuname'},\%userupdate);
1.225 raeburn 3470: }
1.220 raeburn 3471: }
3472: }
3473: }
3474: }
1.226 raeburn 3475: my $userinfo = &Apache::loncommon::plainname($env{'form.ccuname'},
1.233 raeburn 3476: $env{'form.ccdomain'});
3477: if ($env{'form.popup'}) {
3478: $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a></p>');
3479: } else {
1.367 golterma 3480: $r->print('<br />'.&Apache::lonhtmlcommon::actionbox(['<a href="javascript:backPage(document.userupdate,'."'$env{'form.prevphase'}','modify'".')">'
3481: .&mt('Modify this user: [_1]','<span class="LC_cusr_emph">'.$env{'form.ccuname'}.':'.$env{'form.ccdomain'}.' ('.$userinfo.')</span>').'</a>',
3482: '<a href="javascript:backPage(document.userupdate)">'.&mt('Create/Modify Another User').'</a>']));
1.233 raeburn 3483: }
1.220 raeburn 3484: }
3485: }
3486:
1.334 raeburn 3487: sub display_userinfo {
1.362 raeburn 3488: my ($r,$changed,$order,$canshow,$requestcourses,$usertools,$requestauthor,
3489: $userenv,$changedhash,$namechangedhash,$oldsetting,$oldsettingtext,
1.334 raeburn 3490: $newsetting,$newsettingtext) = @_;
3491: return unless (ref($order) eq 'ARRAY' &&
3492: ref($canshow) eq 'HASH' &&
3493: ref($requestcourses) eq 'ARRAY' &&
1.362 raeburn 3494: ref($requestauthor) eq 'ARRAY' &&
1.334 raeburn 3495: ref($usertools) eq 'ARRAY' &&
3496: ref($userenv) eq 'HASH' &&
3497: ref($changedhash) eq 'HASH' &&
3498: ref($oldsetting) eq 'HASH' &&
3499: ref($oldsettingtext) eq 'HASH' &&
3500: ref($newsetting) eq 'HASH' &&
3501: ref($newsettingtext) eq 'HASH');
3502: my %lt=&Apache::lonlocal::texthash(
1.372 raeburn 3503: 'ui' => 'User Information',
1.334 raeburn 3504: 'uic' => 'User Information Changed',
3505: 'firstname' => 'First Name',
3506: 'middlename' => 'Middle Name',
3507: 'lastname' => 'Last Name',
3508: 'generation' => 'Generation',
3509: 'id' => 'Student/Employee ID',
3510: 'permanentemail' => 'Permanent e-mail address',
1.378 raeburn 3511: 'portfolioquota' => 'Disk space allocated to portfolio files',
1.385 bisitz 3512: 'authorquota' => 'Disk space allocated to Authoring Space',
1.334 raeburn 3513: 'blog' => 'Blog Availability',
1.361 raeburn 3514: 'webdav' => 'WebDAV Availability',
1.334 raeburn 3515: 'aboutme' => 'Personal Information Page Availability',
3516: 'portfolio' => 'Portfolio Availability',
3517: 'official' => 'Can Request Official Courses',
3518: 'unofficial' => 'Can Request Unofficial Courses',
3519: 'community' => 'Can Request Communities',
1.384 raeburn 3520: 'textbook' => 'Can Request Textbook Courses',
1.411 raeburn 3521: 'placement' => 'Can Request Placement Tests',
1.362 raeburn 3522: 'requestauthor' => 'Can Request Author Role',
1.414 raeburn 3523: 'adhocroles' => 'Ad Hoc Roles Selectable via Helpdesk Role',
1.334 raeburn 3524: 'inststatus' => "Affiliation",
3525: 'prvs' => 'Previous Value:',
3526: 'chto' => 'Changed To:'
3527: );
3528: if ($changed) {
1.372 raeburn 3529: $r->print('<h3>'.$lt{'uic'}.'</h3>'.
1.367 golterma 3530: &Apache::loncommon::start_data_table().
3531: &Apache::loncommon::start_data_table_header_row());
1.334 raeburn 3532: $r->print("<th> </th>\n");
1.367 golterma 3533: $r->print('<th><b>'.$lt{'prvs'}.'</b></th>');
3534: $r->print('<th><span class="LC_nobreak"><b>'.$lt{'chto'}.'</b></span></th>');
3535: $r->print(&Apache::loncommon::end_data_table_header_row());
3536: my @userinfo = ('firstname','middlename','lastname','generation','permanentemail','id');
3537:
1.334 raeburn 3538: foreach my $item (@userinfo) {
3539: my $value = $env{'form.c'.$item};
1.367 golterma 3540: #show changes only:
1.383 raeburn 3541: unless ($value eq $userenv->{$item}){
1.367 golterma 3542: $r->print(&Apache::loncommon::start_data_table_row());
3543: $r->print("<td>$lt{$item}</td>\n");
1.383 raeburn 3544: $r->print("<td>".$userenv->{$item}."</td>\n");
1.367 golterma 3545: $r->print("<td>$value </td>\n");
3546: $r->print(&Apache::loncommon::end_data_table_row());
1.334 raeburn 3547: }
3548: }
3549: foreach my $entry (@{$order}) {
1.383 raeburn 3550: if ($canshow->{$entry}) {
3551: if (($entry eq 'requestcourses') || ($entry eq 'reqcrsotherdom') || ($entry eq 'requestauthor')) {
3552: my @items;
3553: if ($entry eq 'requestauthor') {
3554: @items = ($entry);
3555: } else {
3556: @items = @{$requestcourses};
1.384 raeburn 3557: }
1.383 raeburn 3558: foreach my $item (@items) {
3559: if (($newsetting->{$item} ne $oldsetting->{$item}) ||
3560: ($newsettingtext->{$item} ne $oldsettingtext->{$item})) {
3561: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3562: $r->print("<td>$lt{$item}</td>\n");
3563: $r->print("<td>".$oldsetting->{$item});
3564: if ($oldsettingtext->{$item}) {
3565: if ($oldsetting->{$item}) {
3566: $r->print(' -- ');
3567: }
3568: $r->print($oldsettingtext->{$item});
3569: }
3570: $r->print("</td>\n");
3571: $r->print("<td>".$newsetting->{$item});
3572: if ($newsettingtext->{$item}) {
3573: if ($newsetting->{$item}) {
3574: $r->print(' -- ');
3575: }
3576: $r->print($newsettingtext->{$item});
3577: }
3578: $r->print("</td>\n");
3579: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.334 raeburn 3580: }
3581: }
3582: } elsif ($entry eq 'tools') {
3583: foreach my $item (@{$usertools}) {
1.383 raeburn 3584: if ($newsetting->{$item} ne $oldsetting->{$item}) {
3585: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3586: $r->print("<td>$lt{$item}</td>\n");
3587: $r->print("<td>".$oldsetting->{$item}.' '.$oldsettingtext->{$item}."</td>\n");
3588: $r->print("<td>".$newsetting->{$item}.' '.$newsettingtext->{$item}."</td>\n");
3589: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.334 raeburn 3590: }
3591: }
1.378 raeburn 3592: } elsif ($entry eq 'quota') {
3593: if ((ref($oldsetting->{$entry}) eq 'HASH') && (ref($oldsettingtext->{$entry}) eq 'HASH') &&
3594: (ref($newsetting->{$entry}) eq 'HASH') && (ref($newsettingtext->{$entry}) eq 'HASH')) {
3595: foreach my $name ('portfolio','author') {
1.383 raeburn 3596: if ($newsetting->{$entry}->{$name} ne $oldsetting->{$entry}->{$name}) {
3597: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3598: $r->print("<td>$lt{$name.$entry}</td>\n");
3599: $r->print("<td>".$oldsettingtext->{$entry}->{$name}."</td>\n");
3600: $r->print("<td>".$newsettingtext->{$entry}->{$name}."</td>\n");
3601: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.378 raeburn 3602: }
3603: }
3604: }
1.334 raeburn 3605: } else {
1.383 raeburn 3606: if ($newsetting->{$entry} ne $oldsetting->{$entry}) {
3607: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3608: $r->print("<td>$lt{$entry}</td>\n");
3609: $r->print("<td>".$oldsetting->{$entry}.' '.$oldsettingtext->{$entry}."</td>\n");
3610: $r->print("<td>".$newsetting->{$entry}.' '.$newsettingtext->{$entry}."</td>\n");
3611: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.334 raeburn 3612: }
3613: }
3614: }
3615: }
1.367 golterma 3616: $r->print(&Apache::loncommon::end_data_table().'<br />');
1.372 raeburn 3617: } else {
3618: $r->print('<h3>'.$lt{'ui'}.'</h3>'.
3619: '<p>'.&mt('No changes made to user information').'</p>');
1.334 raeburn 3620: }
3621: return;
3622: }
3623:
1.275 raeburn 3624: sub tool_changes {
3625: my ($context,$usertools,$oldaccess,$oldaccesstext,$userenv,$changeHash,
3626: $changed,$newaccess,$newaccesstext) = @_;
3627: if (!((ref($usertools) eq 'ARRAY') && (ref($oldaccess) eq 'HASH') &&
3628: (ref($oldaccesstext) eq 'HASH') && (ref($userenv) eq 'HASH') &&
3629: (ref($changeHash) eq 'HASH') && (ref($changed) eq 'HASH') &&
3630: (ref($newaccess) eq 'HASH') && (ref($newaccesstext) eq 'HASH'))) {
3631: return;
3632: }
1.383 raeburn 3633: my %reqdisplay = &requestchange_display();
1.300 raeburn 3634: if ($context eq 'reqcrsotherdom') {
1.309 raeburn 3635: my @options = ('approval','validate','autolimit');
1.306 raeburn 3636: my $optregex = join('|',@options);
1.300 raeburn 3637: my $cdom = $env{'request.role.domain'};
3638: foreach my $tool (@{$usertools}) {
1.383 raeburn 3639: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
1.314 raeburn 3640: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
1.300 raeburn 3641: $changeHash->{$context.'.'.$tool} = $userenv->{$context.'.'.$tool};
1.383 raeburn 3642: my ($newop,$limit);
1.314 raeburn 3643: if ($env{'form.'.$context.'_'.$tool}) {
3644: $newop = $env{'form.'.$context.'_'.$tool};
3645: if ($newop eq 'autolimit') {
1.383 raeburn 3646: $limit = $env{'form.'.$context.'_'.$tool.'_limit'};
1.314 raeburn 3647: $limit =~ s/\D+//g;
3648: $newop .= '='.$limit;
3649: }
3650: }
1.300 raeburn 3651: if ($userenv->{$context.'.'.$tool} eq '') {
1.314 raeburn 3652: if ($newop) {
3653: $changed->{$tool}=&tool_admin($tool,$cdom.':'.$newop,
1.300 raeburn 3654: $changeHash,$context);
3655: if ($changed->{$tool}) {
1.383 raeburn 3656: if ($newop =~ /^autolimit/) {
3657: if ($limit) {
3658: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3659: } else {
3660: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3661: }
3662: } else {
3663: $newaccesstext->{$tool} = $reqdisplay{$newop};
3664: }
1.300 raeburn 3665: } else {
3666: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
3667: }
3668: }
3669: } else {
3670: my @curr = split(',',$userenv->{$context.'.'.$tool});
3671: my @new;
3672: my $changedoms;
1.314 raeburn 3673: foreach my $req (@curr) {
3674: if ($req =~ /^\Q$cdom\E\:($optregex\=?\d*)$/) {
3675: my $oldop = $1;
1.383 raeburn 3676: if ($oldop =~ /^autolimit=(\d*)/) {
3677: my $limit = $1;
3678: if ($limit) {
3679: $oldaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3680: } else {
3681: $oldaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3682: }
3683: } else {
3684: $oldaccesstext->{$tool} = $reqdisplay{$oldop};
3685: }
1.314 raeburn 3686: if ($oldop ne $newop) {
3687: $changedoms = 1;
3688: foreach my $item (@curr) {
3689: my ($reqdom,$option) = split(':',$item);
3690: unless ($reqdom eq $cdom) {
3691: push(@new,$item);
3692: }
3693: }
3694: if ($newop) {
3695: push(@new,$cdom.':'.$newop);
1.300 raeburn 3696: }
1.314 raeburn 3697: @new = sort(@new);
1.300 raeburn 3698: }
1.314 raeburn 3699: last;
1.300 raeburn 3700: }
1.314 raeburn 3701: }
3702: if ((!$changedoms) && ($newop)) {
1.300 raeburn 3703: $changedoms = 1;
1.306 raeburn 3704: @new = sort(@curr,$cdom.':'.$newop);
1.300 raeburn 3705: }
3706: if ($changedoms) {
1.314 raeburn 3707: my $newdomstr;
1.300 raeburn 3708: if (@new) {
3709: $newdomstr = join(',',@new);
3710: }
3711: $changed->{$tool}=&tool_admin($tool,$newdomstr,$changeHash,
3712: $context);
3713: if ($changed->{$tool}) {
3714: if ($env{'form.'.$context.'_'.$tool}) {
1.306 raeburn 3715: if ($env{'form.'.$context.'_'.$tool} eq 'autolimit') {
1.314 raeburn 3716: my $limit = $env{'form.'.$context.'_'.$tool.'_limit'};
3717: $limit =~ s/\D+//g;
3718: if ($limit) {
1.383 raeburn 3719: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
1.314 raeburn 3720: } else {
1.383 raeburn 3721: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
1.306 raeburn 3722: }
1.314 raeburn 3723: } else {
1.306 raeburn 3724: $newaccesstext->{$tool} = $reqdisplay{$env{'form.'.$context.'_'.$tool}};
3725: }
1.300 raeburn 3726: } else {
1.383 raeburn 3727: $newaccesstext->{$tool} = &mt("availability set to 'off'");
1.300 raeburn 3728: }
3729: }
3730: }
3731: }
3732: }
3733: return;
3734: }
1.275 raeburn 3735: foreach my $tool (@{$usertools}) {
1.383 raeburn 3736: my ($newval,$limit,$envkey);
1.362 raeburn 3737: $envkey = $context.'.'.$tool;
1.306 raeburn 3738: if ($context eq 'requestcourses') {
3739: $newval = $env{'form.crsreq_'.$tool};
3740: if ($newval eq 'autolimit') {
1.383 raeburn 3741: $limit = $env{'form.crsreq_'.$tool.'_limit'};
3742: $limit =~ s/\D+//g;
3743: $newval .= '='.$limit;
1.306 raeburn 3744: }
1.362 raeburn 3745: } elsif ($context eq 'requestauthor') {
3746: $newval = $env{'form.'.$context};
3747: $envkey = $context;
1.314 raeburn 3748: } else {
1.306 raeburn 3749: $newval = $env{'form.'.$context.'_'.$tool};
3750: }
1.362 raeburn 3751: if ($userenv->{$envkey} ne '') {
1.275 raeburn 3752: $oldaccess->{$tool} = &mt('custom');
1.383 raeburn 3753: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3754: if ($userenv->{$envkey} =~ /^autolimit=(\d*)$/) {
3755: my $currlimit = $1;
3756: if ($currlimit eq '') {
3757: $oldaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3758: } else {
3759: $oldaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$currlimit);
3760: }
3761: } elsif ($userenv->{$envkey}) {
3762: $oldaccesstext->{$tool} = $reqdisplay{$userenv->{$envkey}};
3763: } else {
3764: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
3765: }
1.275 raeburn 3766: } else {
1.383 raeburn 3767: if ($userenv->{$envkey}) {
3768: $oldaccesstext->{$tool} = &mt("availability set to 'on'");
3769: } else {
3770: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
3771: }
1.275 raeburn 3772: }
1.362 raeburn 3773: $changeHash->{$envkey} = $userenv->{$envkey};
1.275 raeburn 3774: if ($env{'form.custom'.$tool} == 1) {
1.362 raeburn 3775: if ($newval ne $userenv->{$envkey}) {
1.306 raeburn 3776: $changed->{$tool} = &tool_admin($tool,$newval,$changeHash,
3777: $context);
1.275 raeburn 3778: if ($changed->{$tool}) {
3779: $newaccess->{$tool} = &mt('custom');
1.383 raeburn 3780: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3781: if ($newval =~ /^autolimit/) {
3782: if ($limit) {
3783: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3784: } else {
3785: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3786: }
3787: } elsif ($newval) {
3788: $newaccesstext->{$tool} = $reqdisplay{$newval};
3789: } else {
3790: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3791: }
1.275 raeburn 3792: } else {
1.383 raeburn 3793: if ($newval) {
3794: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3795: } else {
3796: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3797: }
1.275 raeburn 3798: }
3799: } else {
3800: $newaccess->{$tool} = $oldaccess->{$tool};
1.383 raeburn 3801: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3802: if ($newval =~ /^autolimit/) {
3803: if ($limit) {
3804: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3805: } else {
3806: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3807: }
3808: } elsif ($newval) {
3809: $newaccesstext->{$tool} = $reqdisplay{$newval};
3810: } else {
3811: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3812: }
1.275 raeburn 3813: } else {
1.383 raeburn 3814: if ($userenv->{$context.'.'.$tool}) {
3815: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3816: } else {
3817: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3818: }
1.275 raeburn 3819: }
3820: }
3821: } else {
3822: $newaccess->{$tool} = $oldaccess->{$tool};
3823: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
3824: }
3825: } else {
3826: $changed->{$tool} = &tool_admin($tool,'',$changeHash,$context);
3827: if ($changed->{$tool}) {
3828: $newaccess->{$tool} = &mt('default');
3829: } else {
3830: $newaccess->{$tool} = $oldaccess->{$tool};
1.383 raeburn 3831: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3832: if ($newval =~ /^autolimit/) {
3833: if ($limit) {
3834: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3835: } else {
3836: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3837: }
3838: } elsif ($newval) {
3839: $newaccesstext->{$tool} = $reqdisplay{$newval};
3840: } else {
3841: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3842: }
1.275 raeburn 3843: } else {
1.383 raeburn 3844: if ($userenv->{$context.'.'.$tool}) {
3845: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3846: } else {
3847: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3848: }
1.275 raeburn 3849: }
3850: }
3851: }
3852: } else {
3853: $oldaccess->{$tool} = &mt('default');
3854: if ($env{'form.custom'.$tool} == 1) {
1.306 raeburn 3855: $changed->{$tool} = &tool_admin($tool,$newval,$changeHash,
3856: $context);
1.275 raeburn 3857: if ($changed->{$tool}) {
3858: $newaccess->{$tool} = &mt('custom');
1.383 raeburn 3859: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3860: if ($newval =~ /^autolimit/) {
3861: if ($limit) {
3862: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3863: } else {
3864: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3865: }
3866: } elsif ($newval) {
3867: $newaccesstext->{$tool} = $reqdisplay{$newval};
3868: } else {
3869: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3870: }
1.275 raeburn 3871: } else {
1.383 raeburn 3872: if ($newval) {
3873: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3874: } else {
3875: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3876: }
1.275 raeburn 3877: }
3878: } else {
3879: $newaccess->{$tool} = $oldaccess->{$tool};
3880: }
3881: } else {
3882: $newaccess->{$tool} = $oldaccess->{$tool};
3883: }
3884: }
3885: }
3886: return;
3887: }
3888:
1.414 raeburn 3889: sub adhocrole_changes {
3890: my ($changehashref,$userenv) = @_;
3891: my @adds = &Apache::loncommon::get_env_multiple('form.adhocroleadd');
3892: my @dels = &Apache::loncommon::get_env_multiple('form.adhocroledel');
3893: my (@saved,@added,@alladhoc,$changed);
3894: my $adhoc_key = 'adhocroles.'.$env{'request.role.domain'};
3895: if (!$env{'form.makeuser'}) {
3896: if (ref($userenv) eq 'HASH') {
3897: my @current;
3898: if ($userenv->{$adhoc_key}) {
3899: @current = split(/,/,$userenv->{$adhoc_key});
3900: if (@dels) {
3901: foreach my $curr (@current) {
1.417 raeburn 3902: next if ($curr eq '');
1.414 raeburn 3903: unless (grep(/\Q$curr\E$/,@dels)) {
3904: push(@saved,$curr);
3905: }
3906: }
3907: $changed = 1;
3908: } else {
3909: @saved = @current;
3910: }
3911: }
3912: }
3913: }
3914: if (@adds) {
3915: my $confname = &Apache::lonnet::get_domainconfiguser($env{'request.role.domain'});
3916: my %existing=&Apache::lonnet::dump('roles',$env{'request.role.domain'},
3917: $confname,'rolesdef_');
3918: foreach my $poss (@adds) {
3919: if (exists($existing{'rolesdef_'.$poss})) {
3920: push(@added,$poss);
3921: $changed = 1;
3922: }
3923: }
3924: }
3925: if (@added) {
3926: if (@saved) {
3927: foreach my $add (@added) {
3928: unless (grep(/^\Q$add\E$/,@saved)) {
3929: push(@alladhoc,$add);
3930: }
3931: }
3932: } else {
3933: push(@alladhoc,@added);
3934: }
3935: }
3936: if (@saved) {
3937: push(@alladhoc,@saved);
3938: }
3939: if (@alladhoc) {
1.417 raeburn 3940: my $adhocstr = join(',',sort(@alladhoc));
1.414 raeburn 3941: $changehashref->{$adhoc_key} = $adhocstr;
3942: } elsif (@dels) {
3943: &Apache::lonnet::del('environment',[$adhoc_key],$env{'form.ccdomain'},$env{'form.ccuname'});
3944: delete($changehashref->{$adhoc_key});
3945: if (($env{'form.ccdomain'} eq $env{'user.domain'}) &&
3946: ($env{'form.ccuname'} eq $env{'user.name'})) {
3947: &Apache::lonnet::delenv($adhoc_key);
3948: }
3949: }
3950: return $changed;
3951: }
3952:
1.220 raeburn 3953: sub update_roles {
1.375 raeburn 3954: my ($r,$context,$showcredits) = @_;
1.4 www 3955: my $now=time;
1.225 raeburn 3956: my @rolechanges;
1.220 raeburn 3957: my %disallowed;
1.73 sakharuk 3958: $r->print('<h3>'.&mt('Modifying Roles').'</h3>');
1.404 raeburn 3959: foreach my $key (keys(%env)) {
1.135 raeburn 3960: next if (! $env{$key});
1.190 raeburn 3961: next if ($key eq 'form.action');
1.27 matthew 3962: # Revoke roles
1.135 raeburn 3963: if ($key=~/^form\.rev/) {
3964: if ($key=~/^form\.rev\:([^\_]+)\_([^\_\.]+)$/) {
1.64 www 3965: # Revoke standard role
1.170 albertel 3966: my ($scope,$role) = ($1,$2);
3967: my $result =
3968: &Apache::lonnet::revokerole($env{'form.ccdomain'},
3969: $env{'form.ccuname'},
1.239 raeburn 3970: $scope,$role,'','',$context);
1.367 golterma 3971: $r->print(&Apache::lonhtmlcommon::confirm_success(
1.369 bisitz 3972: &mt('Revoking [_1] in [_2]',
3973: &Apache::lonnet::plaintext($role),
1.372 raeburn 3974: &Apache::loncommon::show_role_extent($scope,$context,$role)),
1.369 bisitz 3975: $result ne "ok").'<br />');
3976: if ($result ne "ok") {
3977: $r->print(&mt('Error: [_1]',$result).'<br />');
3978: }
1.170 albertel 3979: if ($role eq 'st') {
1.202 raeburn 3980: my $result =
1.198 raeburn 3981: &Apache::lonuserutils::classlist_drop($scope,
3982: $env{'form.ccuname'},$env{'form.ccdomain'},
1.202 raeburn 3983: $now);
1.367 golterma 3984: $r->print(&Apache::lonhtmlcommon::confirm_success($result));
1.53 www 3985: }
1.225 raeburn 3986: if (!grep(/^\Q$role\E$/,@rolechanges)) {
3987: push(@rolechanges,$role);
3988: }
1.196 raeburn 3989: }
1.195 raeburn 3990: if ($key=~m{^form\.rev\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}s) {
1.64 www 3991: # Revoke custom role
1.369 bisitz 3992: my $result = &Apache::lonnet::revokecustomrole(
3993: $env{'form.ccdomain'},$env{'form.ccuname'},$1,$2,$3,$4,'','',$context);
1.367 golterma 3994: $r->print(&Apache::lonhtmlcommon::confirm_success(
1.369 bisitz 3995: &mt('Revoking custom role [_1] by [_2] in [_3]',
1.372 raeburn 3996: $4,$3.':'.$2,&Apache::loncommon::show_role_extent($1,$context,'cr')),
1.369 bisitz 3997: $result ne 'ok').'<br />');
3998: if ($result ne "ok") {
3999: $r->print(&mt('Error: [_1]',$result).'<br />');
4000: }
1.225 raeburn 4001: if (!grep(/^cr$/,@rolechanges)) {
4002: push(@rolechanges,'cr');
4003: }
1.64 www 4004: }
1.135 raeburn 4005: } elsif ($key=~/^form\.del/) {
4006: if ($key=~/^form\.del\:([^\_]+)\_([^\_\.]+)$/) {
1.116 raeburn 4007: # Delete standard role
1.170 albertel 4008: my ($scope,$role) = ($1,$2);
4009: my $result =
4010: &Apache::lonnet::assignrole($env{'form.ccdomain'},
4011: $env{'form.ccuname'},
1.239 raeburn 4012: $scope,$role,$now,0,1,'',
4013: $context);
1.367 golterma 4014: $r->print(&Apache::lonhtmlcommon::confirm_success(
4015: &mt('Deleting [_1] in [_2]',
1.369 bisitz 4016: &Apache::lonnet::plaintext($role),
1.372 raeburn 4017: &Apache::loncommon::show_role_extent($scope,$context,$role)),
1.369 bisitz 4018: $result ne 'ok').'<br />');
4019: if ($result ne "ok") {
4020: $r->print(&mt('Error: [_1]',$result).'<br />');
4021: }
1.367 golterma 4022:
1.170 albertel 4023: if ($role eq 'st') {
1.202 raeburn 4024: my $result =
1.198 raeburn 4025: &Apache::lonuserutils::classlist_drop($scope,
4026: $env{'form.ccuname'},$env{'form.ccdomain'},
1.202 raeburn 4027: $now);
1.369 bisitz 4028: $r->print(&Apache::lonhtmlcommon::confirm_success($result));
1.81 albertel 4029: }
1.225 raeburn 4030: if (!grep(/^\Q$role\E$/,@rolechanges)) {
4031: push(@rolechanges,$role);
4032: }
1.116 raeburn 4033: }
1.139 albertel 4034: if ($key=~m{^form\.del\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
1.116 raeburn 4035: my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
4036: # Delete custom role
1.369 bisitz 4037: my $result =
4038: &Apache::lonnet::assigncustomrole($env{'form.ccdomain'},
4039: $env{'form.ccuname'},$url,$rdom,$rnam,$rolename,$now,
4040: 0,1,$context);
4041: $r->print(&Apache::lonhtmlcommon::confirm_success(&mt('Deleting custom role [_1] by [_2] in [_3]',
1.372 raeburn 4042: $rolename,$rnam.':'.$rdom,&Apache::loncommon::show_role_extent($1,$context,'cr')),
1.369 bisitz 4043: $result ne "ok").'<br />');
4044: if ($result ne "ok") {
4045: $r->print(&mt('Error: [_1]',$result).'<br />');
4046: }
1.367 golterma 4047:
1.225 raeburn 4048: if (!grep(/^cr$/,@rolechanges)) {
4049: push(@rolechanges,'cr');
4050: }
1.116 raeburn 4051: }
1.135 raeburn 4052: } elsif ($key=~/^form\.ren/) {
1.101 albertel 4053: my $udom = $env{'form.ccdomain'};
4054: my $uname = $env{'form.ccuname'};
1.116 raeburn 4055: # Re-enable standard role
1.135 raeburn 4056: if ($key=~/^form\.ren\:([^\_]+)\_([^\_\.]+)$/) {
1.89 raeburn 4057: my $url = $1;
4058: my $role = $2;
4059: my $logmsg;
4060: my $output;
4061: if ($role eq 'st') {
1.141 albertel 4062: if ($url =~ m-^/($match_domain)/($match_courseid)/?(\w*)$-) {
1.374 raeburn 4063: my ($cdom,$cnum,$csec) = ($1,$2,$3);
1.375 raeburn 4064: my $credits;
4065: if ($showcredits) {
4066: my $defaultcredits =
4067: &Apache::lonuserutils::get_defaultcredits($cdom,$cnum);
4068: $credits = &get_user_credits($defaultcredits,$cdom,$cnum);
4069: }
4070: my $result = &Apache::loncommon::commit_studentrole(\$logmsg,$udom,$uname,$url,$role,$now,0,$cdom,$cnum,$csec,$context,$credits);
1.220 raeburn 4071: if (($result =~ /^error/) || ($result eq 'not_in_class') || ($result eq 'unknown_course') || ($result eq 'refused')) {
1.223 raeburn 4072: if ($result eq 'refused' && $logmsg) {
4073: $output = $logmsg;
4074: } else {
1.369 bisitz 4075: $output = &mt('Error: [_1]',$result)."\n";
1.223 raeburn 4076: }
1.89 raeburn 4077: } else {
1.372 raeburn 4078: $output = &Apache::lonhtmlcommon::confirm_success(&mt('Assigning [_1] in [_2] starting [_3]',
4079: &Apache::lonnet::plaintext($role),
4080: &Apache::loncommon::show_role_extent($url,$context,'st'),
4081: &Apache::lonlocal::locallocaltime($now))).'<br />'.$logmsg.'<br />';
1.89 raeburn 4082: }
4083: }
4084: } else {
1.101 albertel 4085: my $result=&Apache::lonnet::assignrole($env{'form.ccdomain'},
1.239 raeburn 4086: $env{'form.ccuname'},$url,$role,0,$now,'','',
4087: $context);
1.367 golterma 4088: $output = &Apache::lonhtmlcommon::confirm_success(&mt('Re-enabling [_1] in [_2]',
1.372 raeburn 4089: &Apache::lonnet::plaintext($role),
4090: &Apache::loncommon::show_role_extent($url,$context,$role)),$result ne "ok").'<br />';
1.369 bisitz 4091: if ($result ne "ok") {
4092: $output .= &mt('Error: [_1]',$result).'<br />';
4093: }
4094: }
1.89 raeburn 4095: $r->print($output);
1.225 raeburn 4096: if (!grep(/^\Q$role\E$/,@rolechanges)) {
4097: push(@rolechanges,$role);
4098: }
1.113 raeburn 4099: }
1.116 raeburn 4100: # Re-enable custom role
1.139 albertel 4101: if ($key=~m{^form\.ren\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
1.116 raeburn 4102: my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
4103: my $result = &Apache::lonnet::assigncustomrole(
4104: $env{'form.ccdomain'}, $env{'form.ccuname'},
1.240 raeburn 4105: $url,$rdom,$rnam,$rolename,0,$now,undef,$context);
1.369 bisitz 4106: $r->print(&Apache::lonhtmlcommon::confirm_success(
4107: &mt('Re-enabling custom role [_1] by [_2] in [_3]',
1.372 raeburn 4108: $rolename,$rnam.':'.$rdom,&Apache::loncommon::show_role_extent($1,$context,'cr')),
1.369 bisitz 4109: $result ne "ok").'<br />');
4110: if ($result ne "ok") {
4111: $r->print(&mt('Error: [_1]',$result).'<br />');
4112: }
1.225 raeburn 4113: if (!grep(/^cr$/,@rolechanges)) {
4114: push(@rolechanges,'cr');
4115: }
1.116 raeburn 4116: }
1.135 raeburn 4117: } elsif ($key=~/^form\.act/) {
1.101 albertel 4118: my $udom = $env{'form.ccdomain'};
4119: my $uname = $env{'form.ccuname'};
1.141 albertel 4120: if ($key=~/^form\.act\_($match_domain)\_($match_courseid)\_cr_cr_($match_domain)_($match_username)_([^\_]+)$/) {
1.65 www 4121: # Activate a custom role
1.83 albertel 4122: my ($one,$two,$three,$four,$five)=($1,$2,$3,$4,$5);
4123: my $url='/'.$one.'/'.$two;
4124: my $full=$one.'_'.$two.'_cr_cr_'.$three.'_'.$four.'_'.$five;
1.65 www 4125:
1.101 albertel 4126: my $start = ( $env{'form.start_'.$full} ?
4127: $env{'form.start_'.$full} :
1.88 raeburn 4128: $now );
1.101 albertel 4129: my $end = ( $env{'form.end_'.$full} ?
4130: $env{'form.end_'.$full} :
1.88 raeburn 4131: 0 );
4132:
4133: # split multiple sections
4134: my %sections = ();
1.101 albertel 4135: my $num_sections = &build_roles($env{'form.sec_'.$full},\%sections,$5);
1.88 raeburn 4136: if ($num_sections == 0) {
1.240 raeburn 4137: $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$url,$three,$four,$five,$start,$end,$context));
1.88 raeburn 4138: } else {
1.114 albertel 4139: my %curr_groups =
1.117 raeburn 4140: &Apache::longroup::coursegroups($one,$two);
1.404 raeburn 4141: foreach my $sec (sort {$a cmp $b} keys(%sections)) {
1.113 raeburn 4142: if (($sec eq 'none') || ($sec eq 'all') ||
4143: exists($curr_groups{$sec})) {
4144: $disallowed{$sec} = $url;
4145: next;
4146: }
4147: my $securl = $url.'/'.$sec;
1.240 raeburn 4148: $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$securl,$three,$four,$five,$start,$end,$context));
1.88 raeburn 4149: }
4150: }
1.225 raeburn 4151: if (!grep(/^cr$/,@rolechanges)) {
4152: push(@rolechanges,'cr');
4153: }
1.142 raeburn 4154: } elsif ($key=~/^form\.act\_($match_domain)\_($match_name)\_([^\_]+)$/) {
1.27 matthew 4155: # Activate roles for sections with 3 id numbers
4156: # set start, end times, and the url for the class
1.83 albertel 4157: my ($one,$two,$three)=($1,$2,$3);
1.101 albertel 4158: my $start = ( $env{'form.start_'.$one.'_'.$two.'_'.$three} ?
4159: $env{'form.start_'.$one.'_'.$two.'_'.$three} :
1.27 matthew 4160: $now );
1.101 albertel 4161: my $end = ( $env{'form.end_'.$one.'_'.$two.'_'.$three} ?
4162: $env{'form.end_'.$one.'_'.$two.'_'.$three} :
1.27 matthew 4163: 0 );
1.83 albertel 4164: my $url='/'.$one.'/'.$two;
1.88 raeburn 4165: my $type = 'three';
4166: # split multiple sections
4167: my %sections = ();
1.101 albertel 4168: my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two.'_'.$three},\%sections,$three);
1.375 raeburn 4169: my $credits;
4170: if ($three eq 'st') {
4171: if ($showcredits) {
4172: my $defaultcredits =
4173: &Apache::lonuserutils::get_defaultcredits($one,$two);
4174: $credits = $env{'form.credits_'.$one.'_'.$two.'_'.$three};
4175: $credits =~ s/[^\d\.]//g;
4176: if ($credits eq $defaultcredits) {
4177: undef($credits);
4178: }
4179: }
4180: }
1.88 raeburn 4181: if ($num_sections == 0) {
1.375 raeburn 4182: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'',$context,$credits));
1.88 raeburn 4183: } else {
1.114 albertel 4184: my %curr_groups =
1.117 raeburn 4185: &Apache::longroup::coursegroups($one,$two);
1.88 raeburn 4186: my $emptysec = 0;
1.404 raeburn 4187: foreach my $sec (sort {$a cmp $b} keys(%sections)) {
1.88 raeburn 4188: $sec =~ s/\W//g;
1.113 raeburn 4189: if ($sec ne '') {
4190: if (($sec eq 'none') || ($sec eq 'all') ||
4191: exists($curr_groups{$sec})) {
4192: $disallowed{$sec} = $url;
4193: next;
4194: }
1.88 raeburn 4195: my $securl = $url.'/'.$sec;
1.375 raeburn 4196: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$three,$start,$end,$one,$two,$sec,$context,$credits));
1.88 raeburn 4197: } else {
4198: $emptysec = 1;
4199: }
4200: }
4201: if ($emptysec) {
1.375 raeburn 4202: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'',$context,$credits));
1.88 raeburn 4203: }
1.225 raeburn 4204: }
4205: if (!grep(/^\Q$three\E$/,@rolechanges)) {
4206: push(@rolechanges,$three);
4207: }
1.135 raeburn 4208: } elsif ($key=~/^form\.act\_([^\_]+)\_([^\_]+)$/) {
1.27 matthew 4209: # Activate roles for sections with two id numbers
4210: # set start, end times, and the url for the class
1.101 albertel 4211: my $start = ( $env{'form.start_'.$1.'_'.$2} ?
4212: $env{'form.start_'.$1.'_'.$2} :
1.27 matthew 4213: $now );
1.101 albertel 4214: my $end = ( $env{'form.end_'.$1.'_'.$2} ?
4215: $env{'form.end_'.$1.'_'.$2} :
1.27 matthew 4216: 0 );
1.225 raeburn 4217: my $one = $1;
4218: my $two = $2;
4219: my $url='/'.$one.'/';
1.88 raeburn 4220: # split multiple sections
4221: my %sections = ();
1.225 raeburn 4222: my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two},\%sections,$two);
1.88 raeburn 4223: if ($num_sections == 0) {
1.240 raeburn 4224: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,'',$context));
1.88 raeburn 4225: } else {
4226: my $emptysec = 0;
1.404 raeburn 4227: foreach my $sec (sort {$a cmp $b} keys(%sections)) {
1.88 raeburn 4228: if ($sec ne '') {
4229: my $securl = $url.'/'.$sec;
1.240 raeburn 4230: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$two,$start,$end,$one,undef,$sec,$context));
1.88 raeburn 4231: } else {
4232: $emptysec = 1;
4233: }
4234: }
4235: if ($emptysec) {
1.240 raeburn 4236: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,'',$context));
1.88 raeburn 4237: }
4238: }
1.225 raeburn 4239: if (!grep(/^\Q$two\E$/,@rolechanges)) {
4240: push(@rolechanges,$two);
4241: }
1.64 www 4242: } else {
1.190 raeburn 4243: $r->print('<p><span class="LC_error">'.&mt('ERROR').': '.&mt('Unknown command').' <tt>'.$key.'</tt></span></p><br />');
1.64 www 4244: }
1.113 raeburn 4245: foreach my $key (sort(keys(%disallowed))) {
1.274 bisitz 4246: $r->print('<p class="LC_warning">');
1.113 raeburn 4247: if (($key eq 'none') || ($key eq 'all')) {
1.274 bisitz 4248: $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 4249: } else {
1.274 bisitz 4250: $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 4251: }
1.274 bisitz 4252: $r->print('</p><p>'
4253: .&mt('Please [_1]go back[_2] and choose a different section name.'
4254: ,'<a href="javascript:history.go(-1)'
4255: ,'</a>')
4256: .'</p><br />'
4257: );
1.113 raeburn 4258: }
4259: }
1.101 albertel 4260: } # End of foreach (keys(%env))
1.75 www 4261: # Flush the course logs so reverse user roles immediately updated
1.349 raeburn 4262: $r->register_cleanup(\&Apache::lonnet::flushcourselogs);
1.225 raeburn 4263: if (@rolechanges == 0) {
1.372 raeburn 4264: $r->print('<p>'.&mt('No roles to modify').'</p>');
1.193 raeburn 4265: }
1.225 raeburn 4266: return @rolechanges;
1.220 raeburn 4267: }
4268:
1.375 raeburn 4269: sub get_user_credits {
4270: my ($uname,$udom,$defaultcredits,$cdom,$cnum) = @_;
4271: if ($cdom eq '' || $cnum eq '') {
4272: return unless ($env{'request.course.id'});
4273: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
4274: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
4275: }
4276: my $credits;
4277: my %currhash =
4278: &Apache::lonnet::get('classlist',[$uname.':'.$udom],$cdom,$cnum);
4279: if (keys(%currhash) > 0) {
4280: my @items = split(/:/,$currhash{$uname.':'.$udom});
4281: my $crdidx = &Apache::loncoursedata::CL_CREDITS() - 3;
4282: $credits = $items[$crdidx];
4283: $credits =~ s/[^\d\.]//g;
4284: }
4285: if ($credits eq $defaultcredits) {
4286: undef($credits);
4287: }
4288: return $credits;
4289: }
4290:
1.220 raeburn 4291: sub enroll_single_student {
1.375 raeburn 4292: my ($r,$uhome,$amode,$genpwd,$now,$newuser,$context,$crstype,
4293: $showcredits,$defaultcredits) = @_;
1.318 raeburn 4294: $r->print('<h3>');
4295: if ($crstype eq 'Community') {
4296: $r->print(&mt('Enrolling Member'));
4297: } else {
4298: $r->print(&mt('Enrolling Student'));
4299: }
4300: $r->print('</h3>');
1.220 raeburn 4301:
4302: # Remove non alphanumeric values from section
4303: $env{'form.sections'}=~s/\W//g;
4304:
1.375 raeburn 4305: my $credits;
4306: if (($showcredits) && ($env{'form.credits'} ne '')) {
4307: $credits = $env{'form.credits'};
4308: $credits =~ s/[^\d\.]//g;
4309: if ($credits ne '') {
4310: if ($credits eq $defaultcredits) {
4311: undef($credits);
4312: }
4313: }
4314: }
4315:
1.220 raeburn 4316: # Clean out any old student roles the user has in this class.
4317: &Apache::lonuserutils::modifystudent($env{'form.ccdomain'},
4318: $env{'form.ccuname'},$env{'request.course.id'},undef,$uhome);
4319: my ($startdate,$enddate) = &Apache::lonuserutils::get_dates_from_form();
4320: my $enroll_result =
4321: &Apache::lonnet::modify_student_enrollment($env{'form.ccdomain'},
4322: $env{'form.ccuname'},$env{'form.cid'},$env{'form.cfirstname'},
4323: $env{'form.cmiddlename'},$env{'form.clastname'},
4324: $env{'form.generation'},$env{'form.sections'},$enddate,
1.375 raeburn 4325: $startdate,'manual',undef,$env{'request.course.id'},'',$context,
4326: $credits);
1.220 raeburn 4327: if ($enroll_result =~ /^ok/) {
1.381 bisitz 4328: $r->print(&mt('[_1] enrolled','<b>'.$env{'form.ccuname'}.':'.$env{'form.ccdomain'}.'</b>'));
1.220 raeburn 4329: if ($env{'form.sections'} ne '') {
4330: $r->print(' '.&mt('in section [_1]',$env{'form.sections'}));
4331: }
4332: my ($showstart,$showend);
4333: if ($startdate <= $now) {
4334: $showstart = &mt('Access starts immediately');
4335: } else {
4336: $showstart = &mt('Access starts: ').&Apache::lonlocal::locallocaltime($startdate);
4337: }
4338: if ($enddate == 0) {
4339: $showend = &mt('ends: no ending date');
4340: } else {
4341: $showend = &mt('ends: ').&Apache::lonlocal::locallocaltime($enddate);
4342: }
4343: $r->print('.<br />'.$showstart.'; '.$showend);
4344: if ($startdate <= $now && !$newuser) {
1.386 bisitz 4345: $r->print('<p class="LC_info">');
1.318 raeburn 4346: if ($crstype eq 'Community') {
1.392 raeburn 4347: $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 4348: } else {
1.392 raeburn 4349: $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 4350: }
4351: $r->print('</p>');
1.220 raeburn 4352: }
4353: } else {
4354: $r->print(&mt('unable to enroll').": ".$enroll_result);
4355: }
4356: return;
1.188 raeburn 4357: }
4358:
1.204 raeburn 4359: sub get_defaultquota_text {
4360: my ($settingstatus) = @_;
4361: my $defquotatext;
4362: if ($settingstatus eq '') {
1.383 raeburn 4363: $defquotatext = &mt('default');
1.204 raeburn 4364: } else {
4365: my ($usertypes,$order) =
4366: &Apache::lonnet::retrieve_inst_usertypes($env{'form.ccdomain'});
4367: if ($usertypes->{$settingstatus} eq '') {
1.383 raeburn 4368: $defquotatext = &mt('default');
1.204 raeburn 4369: } else {
1.383 raeburn 4370: $defquotatext = &mt('default for [_1]',$usertypes->{$settingstatus});
1.204 raeburn 4371: }
4372: }
4373: return $defquotatext;
4374: }
4375:
1.188 raeburn 4376: sub update_result_form {
4377: my ($uhome) = @_;
4378: my $outcome =
1.367 golterma 4379: '<form name="userupdate" method="post" action="">'."\n";
1.160 raeburn 4380: foreach my $item ('srchby','srchin','srchtype','srchterm','srchdomain','ccuname','ccdomain') {
1.188 raeburn 4381: $outcome .= '<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n";
1.160 raeburn 4382: }
1.207 raeburn 4383: if ($env{'form.origname'} ne '') {
4384: $outcome .= '<input type="hidden" name="origname" value="'.$env{'form.origname'}.'" />'."\n";
4385: }
1.160 raeburn 4386: foreach my $item ('sortby','seluname','seludom') {
4387: if (exists($env{'form.'.$item})) {
1.188 raeburn 4388: $outcome .= '<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n";
1.160 raeburn 4389: }
4390: }
1.188 raeburn 4391: if ($uhome eq 'no_host') {
4392: $outcome .= '<input type="hidden" name="forcenewuser" value="1" />'."\n";
4393: }
4394: $outcome .= '<input type="hidden" name="phase" value="" />'."\n".
1.383 raeburn 4395: '<input type="hidden" name="currstate" value="" />'."\n".
4396: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n".
1.188 raeburn 4397: '</form>';
4398: return $outcome;
1.4 www 4399: }
4400:
1.149 raeburn 4401: sub quota_admin {
1.378 raeburn 4402: my ($setquota,$changeHash,$name) = @_;
1.149 raeburn 4403: my $quotachanged;
4404: if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
4405: # Current user has quota modification privileges
1.267 raeburn 4406: if (ref($changeHash) eq 'HASH') {
4407: $quotachanged = 1;
1.378 raeburn 4408: $changeHash->{$name.'quota'} = $setquota;
1.267 raeburn 4409: }
1.149 raeburn 4410: }
4411: return $quotachanged;
4412: }
4413:
1.267 raeburn 4414: sub tool_admin {
1.275 raeburn 4415: my ($tool,$settool,$changeHash,$context) = @_;
4416: my $canchange = 0;
1.279 raeburn 4417: if ($context eq 'requestcourses') {
1.275 raeburn 4418: if (&Apache::lonnet::allowed('ccc',$env{'form.ccdomain'})) {
4419: $canchange = 1;
4420: }
1.300 raeburn 4421: } elsif ($context eq 'reqcrsotherdom') {
4422: if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
4423: $canchange = 1;
4424: }
1.362 raeburn 4425: } elsif ($context eq 'requestauthor') {
4426: if (&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) {
4427: $canchange = 1;
4428: }
1.275 raeburn 4429: } elsif (&Apache::lonnet::allowed('mut',$env{'form.ccdomain'})) {
4430: # Current user has quota modification privileges
4431: $canchange = 1;
4432: }
1.267 raeburn 4433: my $toolchanged;
1.275 raeburn 4434: if ($canchange) {
1.267 raeburn 4435: if (ref($changeHash) eq 'HASH') {
4436: $toolchanged = 1;
1.362 raeburn 4437: if ($tool eq 'requestauthor') {
4438: $changeHash->{$context} = $settool;
4439: } else {
4440: $changeHash->{$context.'.'.$tool} = $settool;
4441: }
1.267 raeburn 4442: }
4443: }
4444: return $toolchanged;
4445: }
4446:
1.88 raeburn 4447: sub build_roles {
1.89 raeburn 4448: my ($sectionstr,$sections,$role) = @_;
1.88 raeburn 4449: my $num_sections = 0;
4450: if ($sectionstr=~ /,/) {
4451: my @secnums = split/,/,$sectionstr;
1.89 raeburn 4452: if ($role eq 'st') {
4453: $secnums[0] =~ s/\W//g;
4454: $$sections{$secnums[0]} = 1;
4455: $num_sections = 1;
4456: } else {
4457: foreach my $sec (@secnums) {
4458: $sec =~ ~s/\W//g;
1.150 banghart 4459: if (!($sec eq "")) {
1.89 raeburn 4460: if (exists($$sections{$sec})) {
4461: $$sections{$sec} ++;
4462: } else {
4463: $$sections{$sec} = 1;
4464: $num_sections ++;
4465: }
1.88 raeburn 4466: }
4467: }
4468: }
4469: } else {
4470: $sectionstr=~s/\W//g;
4471: unless ($sectionstr eq '') {
4472: $$sections{$sectionstr} = 1;
4473: $num_sections ++;
4474: }
4475: }
1.129 albertel 4476:
1.88 raeburn 4477: return $num_sections;
4478: }
4479:
1.58 www 4480: # ========================================================== Custom Role Editor
4481:
4482: sub custom_role_editor {
1.414 raeburn 4483: my ($r,$brcrum,$prefix) = @_;
1.324 raeburn 4484: my $action = $env{'form.customroleaction'};
4485: my $rolename;
4486: if ($action eq 'new') {
4487: $rolename=$env{'form.newrolename'};
4488: } else {
4489: $rolename=$env{'form.rolename'};
1.59 www 4490: }
4491:
1.324 raeburn 4492: my ($crstype,$context);
4493: if ($env{'request.course.id'}) {
4494: $crstype = &Apache::loncommon::course_type();
4495: $context = 'course';
4496: } else {
4497: $context = 'domain';
1.414 raeburn 4498: $crstype = 'course';
1.324 raeburn 4499: }
1.351 raeburn 4500:
4501: $rolename=~s/[^A-Za-z0-9]//gs;
4502: if (!$rolename || $env{'form.phase'} eq 'pickrole') {
4503: &print_username_entry_form($r,undef,undef,undef,undef,$crstype,$brcrum);
4504: return;
4505: }
4506:
1.414 raeburn 4507: my $formname = 'form1';
4508: my %privs=();
4509: my $body_top = '<h2>';
4510: # ------------------------------------------------------- Does this role exist?
1.59 www 4511: my ($rdummy,$roledef)=
4512: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
4513: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1.414 raeburn 4514: $body_top .= &mt('Existing Role').' "';
1.61 www 4515: # ------------------------------------------------- Get current role privileges
1.414 raeburn 4516: ($privs{'system'},$privs{'domain'},$privs{'course'})=split(/\_/,$roledef);
4517: if ($privs{'system'} =~ /bre\&S/) {
4518: if ($context eq 'domain') {
1.417 raeburn 4519: $crstype = 'Course';
1.414 raeburn 4520: } elsif ($crstype eq 'Community') {
4521: $privs{'system'} =~ s/bre\&S//;
4522: }
4523: } elsif ($context eq 'domain') {
4524: $crstype = 'Course';
1.324 raeburn 4525: }
1.59 www 4526: } else {
1.414 raeburn 4527: $body_top .= &mt('New Role').' "';
4528: $roledef='';
1.59 www 4529: }
1.153 banghart 4530: $body_top .= $rolename.'"</h2>';
1.414 raeburn 4531:
4532: # ------------------------------------------------------- What can be assigned?
4533: my %full=();
1.417 raeburn 4534: my %levels=(
1.414 raeburn 4535: course => {},
4536: domain => {},
4537: system => {},
4538: );
4539: my %levelscurrent=(
4540: course => {},
4541: domain => {},
4542: system => {},
4543: );
4544: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
1.160 raeburn 4545: my ($jsback,$elements) = &crumb_utilities();
1.414 raeburn 4546: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
1.417 raeburn 4547: my $head_script =
1.414 raeburn 4548: &Apache::lonuserutils::custom_roledefs_js($context,$crstype,$formname,
4549: \%full,\@templateroles,$jsback);
1.351 raeburn 4550: push (@{$brcrum},
1.414 raeburn 4551: {href => "javascript:backPage(document.$formname,'pickrole','')",
1.351 raeburn 4552: text => "Pick custom role",
4553: faq => 282,bug=>'Instructor Interface',},
1.414 raeburn 4554: {href => "javascript:backPage(document.$formname,'','')",
1.351 raeburn 4555: text => "Edit custom role",
4556: faq => 282,
4557: bug => 'Instructor Interface',
4558: help => 'Course_Editing_Custom_Roles'}
4559: );
4560: my $args = { bread_crumbs => $brcrum,
4561: bread_crumbs_component => 'User Management'};
4562:
4563: $r->print(&Apache::loncommon::start_page('Custom Role Editor',
4564: $head_script,$args).
4565: $body_top);
1.414 raeburn 4566: $r->print('<form name="'.$formname.'" method="post" action="">'."\n".
4567: &Apache::lonuserutils::custom_role_header($context,$crstype,
4568: \@templateroles,$prefix));
1.264 bisitz 4569:
1.61 www 4570: $r->print(<<ENDCCF);
4571: <input type="hidden" name="phase" value="set_custom_roles" />
4572: <input type="hidden" name="rolename" value="$rolename" />
4573: ENDCCF
1.414 raeburn 4574: $r->print(&Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
4575: \%levelscurrent,$prefix));
1.135 raeburn 4576: $r->print(&Apache::loncommon::end_data_table().
1.190 raeburn 4577: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'.
1.160 raeburn 4578: '<input type="hidden" name="startrolename" value="'.$env{'form.rolename'}.
1.417 raeburn 4579: '" />'."\n".'<input type="hidden" name="currstate" value="" />'."\n".
1.160 raeburn 4580: '<input type="reset" value="'.&mt("Reset").'" />'."\n".
1.351 raeburn 4581: '<input type="submit" value="'.&mt('Save').'" /></form>');
1.61 www 4582: }
1.414 raeburn 4583:
1.61 www 4584: # ---------------------------------------------------------- Call to definerole
4585: sub set_custom_role {
1.414 raeburn 4586: my ($r,$context,$brcrum,$prefix) = @_;
1.101 albertel 4587: my $rolename=$env{'form.rolename'};
1.63 www 4588: $rolename=~s/[^A-Za-z0-9]//gs;
1.150 banghart 4589: if (!$rolename) {
1.414 raeburn 4590: &custom_role_editor($r,$brcrum,$prefix);
1.61 www 4591: return;
4592: }
1.160 raeburn 4593: my ($jsback,$elements) = &crumb_utilities();
1.301 bisitz 4594: my $jscript = '<script type="text/javascript">'
4595: .'// <![CDATA['."\n"
4596: .$jsback."\n"
4597: .'// ]]>'."\n"
4598: .'</script>'."\n";
1.352 raeburn 4599: push(@{$brcrum},
4600: {href => "javascript:backPage(document.customresult,'pickrole','')",
4601: text => "Pick custom role",
4602: faq => 282,
4603: bug => 'Instructor Interface',},
4604: {href => "javascript:backPage(document.customresult,'selected_custom_edit','')",
4605: text => "Edit custom role",
4606: faq => 282,
4607: bug => 'Instructor Interface',},
4608: {href => "javascript:backPage(document.customresult,'set_custom_roles','')",
4609: text => "Result",
4610: faq => 282,
4611: bug => 'Instructor Interface',
4612: help => 'Course_Editing_Custom_Roles'},
4613: );
4614: my $args = { bread_crumbs => $brcrum,
1.414 raeburn 4615: bread_crumbs_component => 'User Management'};
1.351 raeburn 4616: $r->print(&Apache::loncommon::start_page('Save Custom Role',$jscript,$args));
1.160 raeburn 4617:
1.393 raeburn 4618: my $newrole;
1.61 www 4619: my ($rdummy,$roledef)=
1.110 albertel 4620: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
4621:
1.61 www 4622: # ------------------------------------------------------- Does this role exist?
1.188 raeburn 4623: $r->print('<h3>');
1.61 www 4624: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1.73 sakharuk 4625: $r->print(&mt('Existing Role').' "');
1.61 www 4626: } else {
1.73 sakharuk 4627: $r->print(&mt('New Role').' "');
1.61 www 4628: $roledef='';
1.393 raeburn 4629: $newrole = 1;
1.61 www 4630: }
1.188 raeburn 4631: $r->print($rolename.'"</h3>');
1.414 raeburn 4632: # ------------------------------------------------- Assign role and show result
1.61 www 4633:
1.387 bisitz 4634: my $errmsg;
1.414 raeburn 4635: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$prefix);
4636: # Assign role and return result
4637: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
4638: $newprivs{'c'});
1.387 bisitz 4639: if ($result ne 'ok') {
4640: $errmsg = ': '.$result;
4641: }
4642: my $message =
4643: &Apache::lonhtmlcommon::confirm_success(
4644: &mt('Defining Role').$errmsg, ($result eq 'ok' ? 0 : 1));
1.101 albertel 4645: if ($env{'request.course.id'}) {
4646: my $url='/'.$env{'request.course.id'};
1.63 www 4647: $url=~s/\_/\//g;
1.387 bisitz 4648: $result =
4649: &Apache::lonnet::assigncustomrole(
4650: $env{'user.domain'},$env{'user.name'},
4651: $url,
4652: $env{'user.domain'},$env{'user.name'},
4653: $rolename,undef,undef,undef,$context);
4654: if ($result ne 'ok') {
4655: $errmsg = ': '.$result;
4656: }
4657: $message .=
4658: '<br />'
4659: .&Apache::lonhtmlcommon::confirm_success(
4660: &mt('Assigning Role to Self').$errmsg, ($result eq 'ok' ? 0 : 1));
1.63 www 4661: }
1.380 bisitz 4662: $r->print(
1.387 bisitz 4663: &Apache::loncommon::confirmwrapper($message)
4664: .'<br />'
4665: .&Apache::lonhtmlcommon::actionbox([
4666: '<a href="javascript:backPage(document.customresult,'."'pickrole'".')">'
4667: .&mt('Create or edit another custom role')
4668: .'</a>'])
1.380 bisitz 4669: .'<form name="customresult" method="post" action="">'
1.387 bisitz 4670: .&Apache::lonhtmlcommon::echo_form_input([])
4671: .'</form>'
1.380 bisitz 4672: );
1.58 www 4673: }
4674:
1.2 www 4675: # ================================================================ Main Handler
4676: sub handler {
4677: my $r = shift;
4678: if ($r->header_only) {
1.68 www 4679: &Apache::loncommon::content_type($r,'text/html');
1.2 www 4680: $r->send_http_header;
4681: return OK;
4682: }
1.318 raeburn 4683: my ($context,$crstype);
1.190 raeburn 4684: if ($env{'request.course.id'}) {
4685: $context = 'course';
1.318 raeburn 4686: $crstype = &Apache::loncommon::course_type();
1.190 raeburn 4687: } elsif ($env{'request.role'} =~ /^au\./) {
1.206 raeburn 4688: $context = 'author';
1.190 raeburn 4689: } else {
4690: $context = 'domain';
4691: }
1.375 raeburn 4692:
1.190 raeburn 4693: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.233 raeburn 4694: ['action','state','callingform','roletype','showrole','bulkaction','popup','phase',
1.391 raeburn 4695: 'username','domain','srchterm','srchdomain','srchin','srchby','srchtype','queue']);
1.190 raeburn 4696: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.351 raeburn 4697: my $args;
4698: my $brcrum = [];
4699: my $bread_crumbs_component = 'User Management';
1.391 raeburn 4700: if (($env{'form.action'} ne 'dateselect') && ($env{'form.action'} ne 'displayuserreq')) {
1.351 raeburn 4701: $brcrum = [{href=>"/adm/createuser",
4702: text=>"User Management",
4703: help=>'Course_Create_Class_List,Course_Change_Privileges,Course_View_Class_List,Course_Editing_Custom_Roles,Course_Add_Student,Course_Drop_Student,Course_Automated_Enrollment,Course_Self_Enrollment,Course_Manage_Group'}
4704: ];
1.202 raeburn 4705: }
1.289 droeschl 4706: #SD Following files not added to help, because the corresponding .tex-files seem to
4707: #be missing: Course_Approve_Selfenroll,Course_User_Logs,
1.209 raeburn 4708: my ($permission,$allowed) =
1.318 raeburn 4709: &Apache::lonuserutils::get_permission($context,$crstype);
1.190 raeburn 4710: if (!$allowed) {
1.358 raeburn 4711: if ($context eq 'course') {
4712: $r->internal_redirect('/adm/viewclasslist');
4713: return OK;
4714: }
1.190 raeburn 4715: $env{'user.error.msg'}=
4716: "/adm/createuser:cst:0:0:Cannot create/modify user data ".
4717: "or view user status.";
4718: return HTTP_NOT_ACCEPTABLE;
4719: }
4720:
4721: &Apache::loncommon::content_type($r,'text/html');
4722: $r->send_http_header;
4723:
1.375 raeburn 4724: my $showcredits;
4725: if ((($context eq 'course') && ($crstype eq 'Course')) ||
4726: ($context eq 'domain')) {
4727: my %domdefaults =
4728: &Apache::lonnet::get_domain_defaults($env{'request.role.domain'});
4729: if ($domdefaults{'officialcredits'} || $domdefaults{'unofficialcredits'}) {
4730: $showcredits = 1;
4731: }
4732: }
4733:
1.190 raeburn 4734: # Main switch on form.action and form.state, as appropriate
4735: if (! exists($env{'form.action'})) {
1.351 raeburn 4736: $args = {bread_crumbs => $brcrum,
4737: bread_crumbs_component => $bread_crumbs_component};
4738: $r->print(&header(undef,$args));
1.318 raeburn 4739: $r->print(&print_main_menu($permission,$context,$crstype));
1.190 raeburn 4740: } elsif ($env{'form.action'} eq 'upload' && $permission->{'cusr'}) {
1.351 raeburn 4741: push(@{$brcrum},
4742: { href => '/adm/createuser?action=upload&state=',
4743: text => 'Upload Users List',
4744: help => 'Course_Create_Class_List',
4745: });
4746: $bread_crumbs_component = 'Upload Users List';
4747: $args = {bread_crumbs => $brcrum,
4748: bread_crumbs_component => $bread_crumbs_component};
4749: $r->print(&header(undef,$args));
1.190 raeburn 4750: $r->print('<form name="studentform" method="post" '.
4751: 'enctype="multipart/form-data" '.
4752: ' action="/adm/createuser">'."\n");
4753: if (! exists($env{'form.state'})) {
4754: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
4755: } elsif ($env{'form.state'} eq 'got_file') {
1.375 raeburn 4756: &Apache::lonuserutils::print_upload_manager_form($r,$context,$permission,
4757: $crstype,$showcredits);
1.190 raeburn 4758: } elsif ($env{'form.state'} eq 'enrolling') {
4759: if ($env{'form.datatoken'}) {
1.375 raeburn 4760: &Apache::lonuserutils::upfile_drop_add($r,$context,$permission,
4761: $showcredits);
1.190 raeburn 4762: }
4763: } else {
4764: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
4765: }
1.416 raeburn 4766: } elsif (((($env{'form.action'} eq 'singleuser') || ($env{'form.action'}
4767: eq 'singlestudent')) && ($permission->{'cusr'})) ||
1.418 raeburn 4768: (($env{'form.action'} eq 'singleuser') && ($permission->{'view'})) ||
1.416 raeburn 4769: (($env{'form.action'} eq 'accesslogs') && ($permission->{'activity'}))) {
1.190 raeburn 4770: my $phase = $env{'form.phase'};
4771: my @search = ('srchterm','srchby','srchin','srchtype','srchdomain');
1.192 albertel 4772: &Apache::loncreateuser::restore_prev_selections();
4773: my $srch;
4774: foreach my $item (@search) {
4775: $srch->{$item} = $env{'form.'.$item};
4776: }
1.207 raeburn 4777: if (($phase eq 'get_user_info') || ($phase eq 'userpicked') ||
1.416 raeburn 4778: ($phase eq 'createnewuser') || ($phase eq 'activity')) {
1.207 raeburn 4779: if ($env{'form.phase'} eq 'createnewuser') {
4780: my $response;
4781: if ($env{'form.srchterm'} !~ /^$match_username$/) {
1.366 bisitz 4782: my $response =
4783: '<span class="LC_warning">'
4784: .&mt('You must specify a valid username. Only the following are allowed:'
4785: .' letters numbers - . @')
4786: .'</span>';
1.221 raeburn 4787: $env{'form.phase'} = '';
1.375 raeburn 4788: &print_username_entry_form($r,$context,$response,$srch,undef,
4789: $crstype,$brcrum,$showcredits);
1.207 raeburn 4790: } else {
4791: my $ccuname =&LONCAPA::clean_username($srch->{'srchterm'});
4792: my $ccdomain=&LONCAPA::clean_domain($srch->{'srchdomain'});
4793: &print_user_modification_page($r,$ccuname,$ccdomain,
1.221 raeburn 4794: $srch,$response,$context,
1.375 raeburn 4795: $permission,$crstype,$brcrum,
4796: $showcredits);
1.207 raeburn 4797: }
4798: } elsif ($env{'form.phase'} eq 'get_user_info') {
1.190 raeburn 4799: my ($currstate,$response,$forcenewuser,$results) =
1.221 raeburn 4800: &user_search_result($context,$srch);
1.190 raeburn 4801: if ($env{'form.currstate'} eq 'modify') {
4802: $currstate = $env{'form.currstate'};
4803: }
4804: if ($currstate eq 'select') {
4805: &print_user_selection_page($r,$response,$srch,$results,
1.351 raeburn 4806: \@search,$context,undef,$crstype,
4807: $brcrum);
1.416 raeburn 4808: } elsif (($currstate eq 'modify') || ($env{'form.action'} eq 'accesslogs')) {
4809: my ($ccuname,$ccdomain,$uhome);
1.190 raeburn 4810: if (($srch->{'srchby'} eq 'uname') &&
4811: ($srch->{'srchtype'} eq 'exact')) {
4812: $ccuname = $srch->{'srchterm'};
4813: $ccdomain= $srch->{'srchdomain'};
4814: } else {
4815: my @matchedunames = keys(%{$results});
4816: ($ccuname,$ccdomain) = split(/:/,$matchedunames[0]);
4817: }
4818: $ccuname =&LONCAPA::clean_username($ccuname);
4819: $ccdomain=&LONCAPA::clean_domain($ccdomain);
1.416 raeburn 4820: if ($env{'form.action'} eq 'accesslogs') {
4821: my $uhome;
4822: if (($ccuname ne '') && ($ccdomain ne '')) {
4823: $uhome = &Apache::lonnet::homeserver($ccuname,$ccdomain);
4824: }
4825: if (($uhome eq '') || ($uhome eq 'no_host')) {
4826: $env{'form.phase'} = '';
4827: undef($forcenewuser);
4828: #if ($response) {
4829: # unless ($response =~ m{\Q<br /><br />\E$}) {
4830: # $response .= '<br /><br />';
4831: # }
4832: #}
4833: &print_username_entry_form($r,$context,$response,$srch,
4834: $forcenewuser,$crstype,$brcrum);
4835: } else {
4836: &print_useraccesslogs_display($r,$ccuname,$ccdomain,$permission,$brcrum);
4837: }
4838: } else {
4839: if ($env{'form.forcenewuser'}) {
4840: $response = '';
4841: }
4842: &print_user_modification_page($r,$ccuname,$ccdomain,
4843: $srch,$response,$context,
4844: $permission,$crstype,$brcrum);
1.190 raeburn 4845: }
4846: } elsif ($currstate eq 'query') {
1.351 raeburn 4847: &print_user_query_page($r,'createuser',$brcrum);
1.190 raeburn 4848: } else {
1.229 raeburn 4849: $env{'form.phase'} = '';
1.207 raeburn 4850: &print_username_entry_form($r,$context,$response,$srch,
1.351 raeburn 4851: $forcenewuser,$crstype,$brcrum);
1.190 raeburn 4852: }
4853: } elsif ($env{'form.phase'} eq 'userpicked') {
4854: my $ccuname = &LONCAPA::clean_username($env{'form.seluname'});
4855: my $ccdomain = &LONCAPA::clean_domain($env{'form.seludom'});
1.416 raeburn 4856: if ($env{'form.action'} eq 'accesslogs') {
4857: &print_useraccesslogs_display($r,$ccuname,$ccdomain,$permission,$brcrum);
4858: } else {
4859: &print_user_modification_page($r,$ccuname,$ccdomain,$srch,'',
4860: $context,$permission,$crstype,
4861: $brcrum);
4862: }
4863: } elsif ($env{'form.action'} eq 'accesslogs') {
4864: my $ccuname = &LONCAPA::clean_username($env{'form.accessuname'});
4865: my $ccdomain = &LONCAPA::clean_domain($env{'form.accessudom'});
4866: &print_useraccesslogs_display($r,$ccuname,$ccdomain,$permission,$brcrum);
1.190 raeburn 4867: }
4868: } elsif ($env{'form.phase'} eq 'update_user_data') {
1.375 raeburn 4869: &update_user_data($r,$context,$crstype,$brcrum,$showcredits);
1.190 raeburn 4870: } else {
1.351 raeburn 4871: &print_username_entry_form($r,$context,undef,$srch,undef,$crstype,
4872: $brcrum);
1.190 raeburn 4873: }
4874: } elsif ($env{'form.action'} eq 'custom' && $permission->{'custom'}) {
1.414 raeburn 4875: my $prefix;
1.190 raeburn 4876: if ($env{'form.phase'} eq 'set_custom_roles') {
1.414 raeburn 4877: &set_custom_role($r,$context,$brcrum,$prefix);
1.190 raeburn 4878: } else {
1.414 raeburn 4879: &custom_role_editor($r,$brcrum,$prefix);
1.190 raeburn 4880: }
1.362 raeburn 4881: } elsif (($env{'form.action'} eq 'processauthorreq') &&
4882: ($permission->{'cusr'}) &&
4883: (&Apache::lonnet::allowed('cau',$env{'request.role.domain'}))) {
4884: push(@{$brcrum},
4885: {href => '/adm/createuser?action=processauthorreq',
1.385 bisitz 4886: text => 'Authoring Space requests',
1.362 raeburn 4887: help => 'Domain_Role_Approvals'});
4888: $bread_crumbs_component = 'Authoring requests';
4889: if ($env{'form.state'} eq 'done') {
4890: push(@{$brcrum},
4891: {href => '/adm/createuser?action=authorreqqueue',
4892: text => 'Result',
4893: help => 'Domain_Role_Approvals'});
4894: $bread_crumbs_component = 'Authoring request result';
4895: }
4896: $args = { bread_crumbs => $brcrum,
4897: bread_crumbs_component => $bread_crumbs_component};
1.391 raeburn 4898: my $js = &usernamerequest_javascript();
4899: $r->print(&header(&add_script($js),$args));
1.362 raeburn 4900: if (!exists($env{'form.state'})) {
4901: $r->print(&Apache::loncoursequeueadmin::display_queued_requests('requestauthor',
4902: $env{'request.role.domain'}));
4903: } elsif ($env{'form.state'} eq 'done') {
4904: $r->print('<h3>'.&mt('Authoring request processing').'</h3>'."\n");
4905: $r->print(&Apache::loncoursequeueadmin::update_request_queue('requestauthor',
4906: $env{'request.role.domain'}));
4907: }
1.391 raeburn 4908: } elsif (($env{'form.action'} eq 'processusernamereq') &&
4909: ($permission->{'cusr'}) &&
4910: (&Apache::lonnet::allowed('cau',$env{'request.role.domain'}))) {
4911: push(@{$brcrum},
4912: {href => '/adm/createuser?action=processusernamereq',
4913: text => 'LON-CAPA account requests',
4914: help => 'Domain_Username_Approvals'});
4915: $bread_crumbs_component = 'Account requests';
4916: if ($env{'form.state'} eq 'done') {
4917: push(@{$brcrum},
4918: {href => '/adm/createuser?action=usernamereqqueue',
4919: text => 'Result',
4920: help => 'Domain_Username_Approvals'});
4921: $bread_crumbs_component = 'LON-CAPA account request result';
4922: }
4923: $args = { bread_crumbs => $brcrum,
4924: bread_crumbs_component => $bread_crumbs_component};
4925: my $js = &usernamerequest_javascript();
4926: $r->print(&header(&add_script($js),$args));
4927: if (!exists($env{'form.state'})) {
4928: $r->print(&Apache::loncoursequeueadmin::display_queued_requests('requestusername',
4929: $env{'request.role.domain'}));
4930: } elsif ($env{'form.state'} eq 'done') {
4931: $r->print('<h3>'.&mt('LON-CAPA account request processing').'</h3>'."\n");
4932: $r->print(&Apache::loncoursequeueadmin::update_request_queue('requestusername',
4933: $env{'request.role.domain'}));
4934: }
4935: } elsif (($env{'form.action'} eq 'displayuserreq') &&
4936: ($permission->{'cusr'})) {
4937: my $dom = $env{'form.domain'};
4938: my $uname = $env{'form.username'};
4939: my $warning;
4940: if (($dom =~ /^$match_domain$/) && (&Apache::lonnet::domain($dom) ne '')) {
4941: if (($dom eq $env{'request.role.domain'}) && (&Apache::lonnet::allowed('ccc',$dom))) {
4942: if (($uname =~ /^$match_username$/) && ($env{'form.queue'} eq 'approval')) {
4943: my $uhome = &Apache::lonnet::homeserver($uname,$dom);
4944: if ($uhome eq 'no_host') {
4945: my $queue = $env{'form.queue'};
4946: my $reqkey = &escape($uname).'_'.$queue;
4947: my $namespace = 'usernamequeue';
4948: my $domconfig = &Apache::lonnet::get_domainconfiguser($dom);
4949: my %queued =
4950: &Apache::lonnet::get($namespace,[$reqkey],$dom,$domconfig);
4951: unless ($queued{$reqkey}) {
4952: $warning = &mt('No information was found for this LON-CAPA account request.');
4953: }
4954: } else {
4955: $warning = &mt('A LON-CAPA account already exists for the requested username and domain.');
4956: }
4957: } else {
4958: $warning = &mt('LON-CAPA account request status check is for an invalid username.');
4959: }
4960: } else {
4961: $warning = &mt('You do not have rights to view LON-CAPA account requests in the domain specified.');
4962: }
4963: } else {
4964: $warning = &mt('LON-CAPA account request status check is for an invalid domain.');
4965: }
4966: my $args = { only_body => 1 };
4967: $r->print(&header(undef,$args).
4968: '<h3>'.&mt('LON-CAPA Account Request Details').'</h3>');
4969: if ($warning ne '') {
4970: $r->print('<div class="LC_warning">'.$warning.'</div>');
4971: } else {
4972: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
4973: my $domconfiguser = &Apache::lonnet::get_domainconfiguser($dom);
4974: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
4975: if (ref($domconfig{'usercreation'}) eq 'HASH') {
4976: if (ref($domconfig{'usercreation'}{'cancreate'}) eq 'HASH') {
4977: if (ref($domconfig{'usercreation'}{'cancreate'}{'emailusername'}) eq 'HASH') {
4978: my %info =
4979: &Apache::lonnet::get('nohist_requestedusernames',[$uname],$dom,$domconfiguser);
4980: if (ref($info{$uname}) eq 'HASH') {
1.396 raeburn 4981: my $usertype = $info{$uname}{'inststatus'};
4982: unless ($usertype) {
4983: $usertype = 'default';
4984: }
4985: if (ref($domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}) eq 'HASH') {
4986: if ((ref($infofields) eq 'ARRAY') && (ref($infotitles) eq 'HASH')) {
4987: $r->print('<div>'.&Apache::lonhtmlcommon::start_pick_box());
4988: my ($num,$count,$showstatus);
4989: $count = scalar(keys(%{$domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}}));
4990: unless ($usertype eq 'default') {
4991: my ($othertitle,$usertypes,$types) =
4992: &Apache::loncommon::sorted_inst_types($dom);
4993: if (ref($usertypes) eq 'HASH') {
4994: if ($usertypes->{$usertype}) {
4995: $showstatus = $usertypes->{$usertype};
4996: $count ++;
4997: }
4998: }
4999: }
5000: foreach my $field (@{$infofields}) {
5001: next unless ($domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}{$field});
5002: next unless ($infotitles->{$field});
5003: $r->print(&Apache::lonhtmlcommon::row_title($infotitles->{$field}).
5004: $info{$uname}{$field});
5005: $num ++;
5006: if ($count == $num) {
5007: $r->print(&Apache::lonhtmlcommon::row_closure(1));
5008: } else {
5009: $r->print(&Apache::lonhtmlcommon::row_closure());
5010: }
5011: }
5012: if ($showstatus) {
5013: $r->print(&Apache::lonhtmlcommon::row_title(&mt('Status type (self-reported)')).
5014: $showstatus.
5015: &Apache::lonhtmlcommon::row_closure(1));
1.391 raeburn 5016: }
1.396 raeburn 5017: $r->print(&Apache::lonhtmlcommon::end_pick_box().'</div>');
1.391 raeburn 5018: }
5019: }
5020: }
5021: }
5022: }
5023: }
5024: $r->print(&close_popup_form());
5025: }
1.207 raeburn 5026: } elsif (($env{'form.action'} eq 'listusers') &&
5027: ($permission->{'view'} || $permission->{'cusr'})) {
1.202 raeburn 5028: if ($env{'form.phase'} eq 'bulkchange') {
1.351 raeburn 5029: push(@{$brcrum},
5030: {href => '/adm/createuser?action=listusers',
5031: text => "List Users"},
5032: {href => "/adm/createuser",
5033: text => "Result",
5034: help => 'Course_View_Class_List'});
5035: $bread_crumbs_component = 'Update Users';
5036: $args = {bread_crumbs => $brcrum,
5037: bread_crumbs_component => $bread_crumbs_component};
5038: $r->print(&header(undef,$args));
1.202 raeburn 5039: my $setting = $env{'form.roletype'};
5040: my $choice = $env{'form.bulkaction'};
5041: if ($permission->{'cusr'}) {
1.336 raeburn 5042: &Apache::lonuserutils::update_user_list($r,$context,$setting,$choice,$crstype);
1.221 raeburn 5043: } else {
5044: $r->print(&mt('You are not authorized to make bulk changes to user roles'));
1.223 raeburn 5045: $r->print('<p><a href="/adm/createuser?action=listusers">'.&mt('Display User Lists').'</a>');
1.202 raeburn 5046: }
5047: } else {
1.351 raeburn 5048: push(@{$brcrum},
5049: {href => '/adm/createuser?action=listusers',
5050: text => "List Users",
5051: help => 'Course_View_Class_List'});
5052: $bread_crumbs_component = 'List Users';
5053: $args = {bread_crumbs => $brcrum,
5054: bread_crumbs_component => $bread_crumbs_component};
1.202 raeburn 5055: my ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles);
5056: my $formname = 'studentform';
1.364 raeburn 5057: my $hidecall = "hide_searching();";
1.321 raeburn 5058: if (($context eq 'domain') && (($env{'form.roletype'} eq 'course') ||
5059: ($env{'form.roletype'} eq 'community'))) {
5060: if ($env{'form.roletype'} eq 'course') {
5061: ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles) =
5062: &Apache::lonuserutils::courses_selector($env{'request.role.domain'},
5063: $formname);
5064: } elsif ($env{'form.roletype'} eq 'community') {
5065: $cb_jscript =
5066: &Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
5067: my %elements = (
5068: coursepick => 'radio',
5069: coursetotal => 'text',
5070: courselist => 'text',
5071: );
5072: $jscript = &Apache::lonhtmlcommon::set_form_elements(\%elements);
5073: }
1.364 raeburn 5074: $jscript .= &verify_user_display($context)."\n".
5075: &Apache::loncommon::check_uncheck_jscript();
1.202 raeburn 5076: my $js = &add_script($jscript).$cb_jscript;
5077: my $loadcode =
5078: &Apache::lonuserutils::course_selector_loadcode($formname);
5079: if ($loadcode ne '') {
1.364 raeburn 5080: $args->{add_entries} = {onload => "$loadcode;$hidecall"};
5081: } else {
5082: $args->{add_entries} = {onload => $hidecall};
1.202 raeburn 5083: }
1.351 raeburn 5084: $r->print(&header($js,$args));
1.191 raeburn 5085: } else {
1.364 raeburn 5086: $args->{add_entries} = {onload => $hidecall};
5087: $jscript = &verify_user_display($context).
5088: &Apache::loncommon::check_uncheck_jscript();
5089: $r->print(&header(&add_script($jscript),$args));
1.191 raeburn 5090: }
1.202 raeburn 5091: &Apache::lonuserutils::print_userlist($r,undef,$permission,$context,
1.375 raeburn 5092: $formname,$totcodes,$codetitles,$idlist,$idlist_titles,
5093: $showcredits);
1.191 raeburn 5094: }
1.213 raeburn 5095: } elsif ($env{'form.action'} eq 'drop' && $permission->{'cusr'}) {
1.318 raeburn 5096: my $brtext;
5097: if ($crstype eq 'Community') {
5098: $brtext = 'Drop Members';
5099: } else {
5100: $brtext = 'Drop Students';
5101: }
1.351 raeburn 5102: push(@{$brcrum},
5103: {href => '/adm/createuser?action=drop',
5104: text => $brtext,
5105: help => 'Course_Drop_Student'});
5106: if ($env{'form.state'} eq 'done') {
5107: push(@{$brcrum},
5108: {href=>'/adm/createuser?action=drop',
5109: text=>"Result"});
5110: }
5111: $bread_crumbs_component = $brtext;
5112: $args = {bread_crumbs => $brcrum,
5113: bread_crumbs_component => $bread_crumbs_component};
5114: $r->print(&header(undef,$args));
1.213 raeburn 5115: if (!exists($env{'form.state'})) {
1.318 raeburn 5116: &Apache::lonuserutils::print_drop_menu($r,$context,$permission,$crstype);
1.213 raeburn 5117: } elsif ($env{'form.state'} eq 'done') {
5118: &Apache::lonuserutils::update_user_list($r,$context,undef,
5119: $env{'form.action'});
5120: }
1.202 raeburn 5121: } elsif ($env{'form.action'} eq 'dateselect') {
5122: if ($permission->{'cusr'}) {
1.351 raeburn 5123: $r->print(&header(undef,{'no_nav_bar' => 1}).
1.375 raeburn 5124: &Apache::lonuserutils::date_section_selector($context,$permission,
5125: $crstype,$showcredits));
1.202 raeburn 5126: } else {
1.351 raeburn 5127: $r->print(&header(undef,{'no_nav_bar' => 1}).
5128: '<span class="LC_error">'.&mt('You do not have permission to modify dates or sections for users').'</span>');
1.202 raeburn 5129: }
1.237 raeburn 5130: } elsif ($env{'form.action'} eq 'selfenroll') {
1.398 raeburn 5131: if ($permission->{selfenrolladmin}) {
5132: my $cid = $env{'request.course.id'};
5133: my $cdom = $env{'course.'.$cid.'.domain'};
5134: my $cnum = $env{'course.'.$cid.'.num'};
5135: my %currsettings = (
5136: selfenroll_types => $env{'course.'.$cid.'.internal.selfenroll_types'},
5137: selfenroll_registered => $env{'course.'.$cid.'.internal.selfenroll_registered'},
5138: selfenroll_section => $env{'course.'.$cid.'.internal.selfenroll_section'},
5139: selfenroll_notifylist => $env{'course.'.$cid.'.internal.selfenroll_notifylist'},
5140: selfenroll_approval => $env{'course.'.$cid.'.internal.selfenroll_approval'},
5141: selfenroll_limit => $env{'course.'.$cid.'.internal.selfenroll_limit'},
5142: selfenroll_cap => $env{'course.'.$cid.'.internal.selfenroll_cap'},
5143: selfenroll_start_date => $env{'course.'.$cid.'.internal.selfenroll_start_date'},
5144: selfenroll_end_date => $env{'course.'.$cid.'.internal.selfenroll_end_date'},
5145: selfenroll_start_access => $env{'course.'.$cid.'.internal.selfenroll_start_access'},
5146: selfenroll_end_access => $env{'course.'.$cid.'.internal.selfenroll_end_access'},
5147: default_enrollment_start_date => $env{'course.'.$cid.'.default_enrollment_start_date'},
5148: default_enrollment_end_date => $env{'course.'.$cid.'.default_enrollment_end_date'},
1.400 raeburn 5149: uniquecode => $env{'course.'.$cid.'.internal.uniquecode'},
1.398 raeburn 5150: );
5151: push(@{$brcrum},
5152: {href => '/adm/createuser?action=selfenroll',
5153: text => "Configure Self-enrollment",
5154: help => 'Course_Self_Enrollment'});
5155: if (!exists($env{'form.state'})) {
5156: $args = { bread_crumbs => $brcrum,
5157: bread_crumbs_component => 'Configure Self-enrollment'};
5158: $r->print(&header(undef,$args));
5159: $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n");
5160: &print_selfenroll_menu($r,'course',$cid,$cdom,$cnum,\%currsettings);
5161: } elsif ($env{'form.state'} eq 'done') {
5162: push (@{$brcrum},
5163: {href=>'/adm/createuser?action=selfenroll',
5164: text=>"Result"});
5165: $args = { bread_crumbs => $brcrum,
5166: bread_crumbs_component => 'Self-enrollment result'};
5167: $r->print(&header(undef,$args));
5168: $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n");
1.400 raeburn 5169: &update_selfenroll_config($r,$cid,$cdom,$cnum,$context,$crstype,\%currsettings);
1.398 raeburn 5170: }
5171: } else {
5172: $r->print(&header(undef,{'no_nav_bar' => 1}).
5173: '<span class="LC_error">'.&mt('You do not have permission to configure self-enrollment').'</span>');
1.237 raeburn 5174: }
1.277 raeburn 5175: } elsif ($env{'form.action'} eq 'selfenrollqueue') {
1.418 raeburn 5176: if ($permission->{selfenrolladmin}) {
1.351 raeburn 5177: push(@{$brcrum},
5178: {href => '/adm/createuser?action=selfenrollqueue',
1.418 raeburn 5179: text => 'Enrollment requests',
1.351 raeburn 5180: help => 'Course_Self_Enrollment'});
1.418 raeburn 5181: $bread_crumbs_component = 'Enrollment requests';
5182: if ($env{'form.state'} eq 'done') {
5183: push(@{$brcrum},
5184: {href => '/adm/createuser?action=selfenrollqueue',
5185: text => 'Result',
5186: help => 'Course_Self_Enrollment'});
5187: $bread_crumbs_component = 'Enrollment result';
5188: }
5189: $args = { bread_crumbs => $brcrum,
5190: bread_crumbs_component => $bread_crumbs_component};
5191: $r->print(&header(undef,$args));
5192: my $cid = $env{'request.course.id'};
5193: my $cdom = $env{'course.'.$cid.'.domain'};
5194: my $cnum = $env{'course.'.$cid.'.num'};
5195: my $coursedesc = $env{'course.'.$cid.'.description'};
5196: if (!exists($env{'form.state'})) {
5197: $r->print('<h3>'.&mt('Pending enrollment requests').'</h3>'."\n");
5198: $r->print(&Apache::loncoursequeueadmin::display_queued_requests($context,
5199: $cdom,$cnum));
5200: } elsif ($env{'form.state'} eq 'done') {
5201: $r->print('<h3>'.&mt('Enrollment request processing').'</h3>'."\n");
5202: $r->print(&Apache::loncoursequeueadmin::update_request_queue($context,
5203: $cdom,$cnum,$coursedesc));
5204: }
5205: } else {
5206: $r->print(&header(undef,{'no_nav_bar' => 1}).
5207: '<span class="LC_error">'.&mt('You do not have permission to manage self-enrollment').'</span>');
1.351 raeburn 5208: }
1.418 raeburn 5209: } elsif ($env{'form.action'} eq 'changelogs') {
5210: if ($permission->{cusr} || $permission->{view}) {
5211: &print_userchangelogs_display($r,$context,$permission,$brcrum);
5212: } else {
5213: $r->print(&header(undef,{'no_nav_bar' => 1}).
5214: '<span class="LC_error">'.&mt('You do not have permission to view change logs').'</span>');
1.277 raeburn 5215: }
1.190 raeburn 5216: } else {
1.351 raeburn 5217: $bread_crumbs_component = 'User Management';
5218: $args = { bread_crumbs => $brcrum,
5219: bread_crumbs_component => $bread_crumbs_component};
5220: $r->print(&header(undef,$args));
1.318 raeburn 5221: $r->print(&print_main_menu($permission,$context,$crstype));
1.190 raeburn 5222: }
1.351 raeburn 5223: $r->print(&Apache::loncommon::end_page());
1.190 raeburn 5224: return OK;
5225: }
5226:
5227: sub header {
1.351 raeburn 5228: my ($jscript,$args) = @_;
1.190 raeburn 5229: my $start_page;
1.351 raeburn 5230: if (ref($args) eq 'HASH') {
5231: $start_page=&Apache::loncommon::start_page('User Management',$jscript,$args);
1.190 raeburn 5232: } else {
1.351 raeburn 5233: $start_page=&Apache::loncommon::start_page('User Management',$jscript);
1.190 raeburn 5234: }
5235: return $start_page;
5236: }
1.2 www 5237:
1.191 raeburn 5238: sub add_script {
5239: my ($js) = @_;
1.301 bisitz 5240: return '<script type="text/javascript">'."\n"
5241: .'// <![CDATA['."\n"
5242: .$js."\n"
5243: .'// ]]>'."\n"
5244: .'</script>'."\n";
1.191 raeburn 5245: }
5246:
1.391 raeburn 5247: sub usernamerequest_javascript {
5248: my $js = <<ENDJS;
5249:
5250: function openusernamereqdisplay(dom,uname,queue) {
5251: var url = '/adm/createuser?action=displayuserreq';
5252: url += '&domain='+dom+'&username='+uname+'&queue='+queue;
5253: var title = 'Account_Request_Browser';
5254: var options = 'scrollbars=1,resizable=1,menubar=0';
5255: options += ',width=700,height=600';
5256: var stdeditbrowser = open(url,title,options,'1');
5257: stdeditbrowser.focus();
5258: return;
5259: }
5260:
5261: ENDJS
5262: }
5263:
5264: sub close_popup_form {
5265: my $close= &mt('Close Window');
5266: return << "END";
5267: <p><form name="displayreq" action="" method="post">
5268: <input type="button" name="closeme" value="$close" onclick="javascript:self.close();" />
5269: </form></p>
5270: END
5271: }
5272:
1.202 raeburn 5273: sub verify_user_display {
1.364 raeburn 5274: my ($context) = @_;
1.374 raeburn 5275: my %lt = &Apache::lonlocal::texthash (
5276: course => 'course(s): description, section(s), status',
5277: community => 'community(s): description, section(s), status',
5278: author => 'author',
5279: );
1.364 raeburn 5280: my $photos;
5281: if (($context eq 'course') && $env{'request.course.id'}) {
5282: $photos = $env{'course.'.$env{'request.course.id'}.'.internal.showphoto'};
5283: }
1.202 raeburn 5284: my $output = <<"END";
5285:
1.364 raeburn 5286: function hide_searching() {
5287: if (document.getElementById('searching')) {
5288: document.getElementById('searching').style.display = 'none';
5289: }
5290: return;
5291: }
5292:
1.202 raeburn 5293: function display_update() {
5294: document.studentform.action.value = 'listusers';
5295: document.studentform.phase.value = 'display';
5296: document.studentform.submit();
5297: }
5298:
1.364 raeburn 5299: function updateCols(caller) {
5300: var context = '$context';
5301: var photos = '$photos';
5302: if (caller == 'Status') {
1.374 raeburn 5303: if ((context == 'domain') &&
5304: ((document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'course') ||
5305: (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community'))) {
1.364 raeburn 5306: document.getElementById('showcolstatus').checked = false;
5307: document.getElementById('showcolstatus').disabled = 'disabled';
5308: document.getElementById('showcolstart').checked = false;
5309: document.getElementById('showcolend').checked = false;
1.374 raeburn 5310: } else {
5311: if (document.studentform.Status.options[document.studentform.Status.selectedIndex].value == 'Any') {
5312: document.getElementById('showcolstatus').checked = true;
5313: document.getElementById('showcolstatus').disabled = '';
5314: document.getElementById('showcolstart').checked = true;
5315: document.getElementById('showcolend').checked = true;
5316: } else {
5317: document.getElementById('showcolstatus').checked = false;
5318: document.getElementById('showcolstatus').disabled = 'disabled';
5319: document.getElementById('showcolstart').checked = false;
5320: document.getElementById('showcolend').checked = false;
5321: }
1.364 raeburn 5322: }
5323: }
5324: if (caller == 'output') {
5325: if (photos == 1) {
5326: if (document.getElementById('showcolphoto')) {
5327: var photoitem = document.getElementById('showcolphoto');
5328: if (document.studentform.output.options[document.studentform.output.selectedIndex].value == 'html') {
5329: photoitem.checked = true;
5330: photoitem.disabled = '';
5331: } else {
5332: photoitem.checked = false;
5333: photoitem.disabled = 'disabled';
5334: }
5335: }
5336: }
5337: }
5338: if (caller == 'showrole') {
1.371 raeburn 5339: if ((document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'Any') ||
5340: (document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'cr')) {
1.364 raeburn 5341: document.getElementById('showcolrole').checked = true;
5342: document.getElementById('showcolrole').disabled = '';
5343: } else {
5344: document.getElementById('showcolrole').checked = false;
5345: document.getElementById('showcolrole').disabled = 'disabled';
5346: }
1.374 raeburn 5347: if (context == 'domain') {
1.382 raeburn 5348: var quotausageshow = 0;
1.374 raeburn 5349: if ((document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'course') ||
5350: (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community')) {
5351: document.getElementById('showcolstatus').checked = false;
5352: document.getElementById('showcolstatus').disabled = 'disabled';
5353: document.getElementById('showcolstart').checked = false;
5354: document.getElementById('showcolend').checked = false;
5355: } else {
5356: if (document.studentform.Status.options[document.studentform.Status.selectedIndex].value == 'Any') {
5357: document.getElementById('showcolstatus').checked = true;
5358: document.getElementById('showcolstatus').disabled = '';
5359: document.getElementById('showcolstart').checked = true;
5360: document.getElementById('showcolend').checked = true;
5361: }
5362: }
5363: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'domain') {
5364: document.getElementById('showcolextent').disabled = 'disabled';
5365: document.getElementById('showcolextent').checked = 'false';
5366: document.getElementById('showextent').style.display='none';
5367: document.getElementById('showcoltextextent').innerHTML = '';
1.382 raeburn 5368: if ((document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'au') ||
5369: (document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'Any')) {
5370: if (document.getElementById('showcolauthorusage')) {
5371: document.getElementById('showcolauthorusage').disabled = '';
5372: }
5373: if (document.getElementById('showcolauthorquota')) {
5374: document.getElementById('showcolauthorquota').disabled = '';
5375: }
5376: quotausageshow = 1;
5377: }
1.374 raeburn 5378: } else {
5379: document.getElementById('showextent').style.display='block';
5380: document.getElementById('showextent').style.textAlign='left';
5381: document.getElementById('showextent').style.textFace='normal';
5382: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'author') {
5383: document.getElementById('showcolextent').disabled = '';
5384: document.getElementById('showcolextent').checked = 'true';
5385: document.getElementById('showcoltextextent').innerHTML="$lt{'author'}";
5386: } else {
5387: document.getElementById('showcolextent').disabled = '';
5388: document.getElementById('showcolextent').checked = 'true';
5389: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community') {
5390: document.getElementById('showcoltextextent').innerHTML="$lt{'community'}";
5391: } else {
5392: document.getElementById('showcoltextextent').innerHTML="$lt{'course'}";
5393: }
5394: }
5395: }
1.382 raeburn 5396: if (quotausageshow == 0) {
5397: if (document.getElementById('showcolauthorusage')) {
5398: document.getElementById('showcolauthorusage').checked = false;
5399: document.getElementById('showcolauthorusage').disabled = 'disabled';
5400: }
5401: if (document.getElementById('showcolauthorquota')) {
5402: document.getElementById('showcolauthorquota').checked = false;
5403: document.getElementById('showcolauthorquota').disabled = 'disabled';
5404: }
5405: }
1.374 raeburn 5406: }
1.364 raeburn 5407: }
5408: return;
5409: }
5410:
1.202 raeburn 5411: END
5412: return $output;
5413:
5414: }
5415:
1.190 raeburn 5416: ###############################################################
5417: ###############################################################
5418: # Menu Phase One
5419: sub print_main_menu {
1.318 raeburn 5420: my ($permission,$context,$crstype) = @_;
5421: my $linkcontext = $context;
5422: my $stuterm = lc(&Apache::lonnet::plaintext('st',$crstype));
5423: if (($context eq 'course') && ($crstype eq 'Community')) {
5424: $linkcontext = lc($crstype);
5425: $stuterm = 'Members';
5426: }
1.208 raeburn 5427: my %links = (
1.298 droeschl 5428: domain => {
5429: upload => 'Upload a File of Users',
5430: singleuser => 'Add/Modify a User',
5431: listusers => 'Manage Users',
5432: },
5433: author => {
5434: upload => 'Upload a File of Co-authors',
5435: singleuser => 'Add/Modify a Co-author',
5436: listusers => 'Manage Co-authors',
5437: },
5438: course => {
5439: upload => 'Upload a File of Course Users',
5440: singleuser => 'Add/Modify a Course User',
1.354 www 5441: listusers => 'List and Modify Multiple Course Users',
1.298 droeschl 5442: },
1.318 raeburn 5443: community => {
5444: upload => 'Upload a File of Community Users',
5445: singleuser => 'Add/Modify a Community User',
1.354 www 5446: listusers => 'List and Modify Multiple Community Users',
1.318 raeburn 5447: },
5448: );
5449: my %linktitles = (
5450: domain => {
5451: singleuser => 'Add a user to the domain, and/or a course or community in the domain.',
5452: listusers => 'Show and manage users in this domain.',
5453: },
5454: author => {
5455: singleuser => 'Add a user with a co- or assistant author role.',
5456: listusers => 'Show and manage co- or assistant authors.',
5457: },
5458: course => {
5459: singleuser => 'Add a user with a certain role to this course.',
5460: listusers => 'Show and manage users in this course.',
5461: },
5462: community => {
5463: singleuser => 'Add a user with a certain role to this community.',
5464: listusers => 'Show and manage users in this community.',
5465: },
1.298 droeschl 5466: );
1.418 raeburn 5467: if ($linkcontext eq 'domain') {
5468: unless ($permission->{'cusr'}) {
5469: $links{'domain'}{'singleuser'} = 'View a User';
5470: $linktitles{'domain'}{'singleuser'} = 'View information about a user in the domain';
5471:
5472: }
5473: } elsif ($linkcontext eq 'course') {
5474: unless ($permission->{'cusr'}) {
5475: $links{'course'}{'singleuser'} = 'View a Course User';
5476: $linktitles{'course'}{'singleuser'} = 'View information about a user in this course';
5477: $links{'course'}{'listusers'} = 'List Course Users';
5478: $linktitles{'course'}{'listusers'} = 'Show information about users in this course';
5479: }
5480: } elsif ($linkcontext eq 'community') {
5481: unless ($permission->{'cusr'}) {
5482: $links{'community'}{'singleuser'} = 'View a Community User';
5483: $linktitles{'community'}{'singleuser'} = 'View information about a user in this community';
5484: $links{'community'}{'listusers'} = 'List Community Users';
5485: $linktitles{'community'}{'listusers'} = 'Show information about users in this community';
5486: }
5487: }
1.298 droeschl 5488: my @menu = ( {categorytitle => 'Single Users',
5489: items =>
5490: [
5491: {
1.318 raeburn 5492: linktext => $links{$linkcontext}{'singleuser'},
1.298 droeschl 5493: icon => 'edit-redo.png',
5494: #help => 'Course_Change_Privileges',
5495: url => '/adm/createuser?action=singleuser',
1.418 raeburn 5496: permission => ($permission->{'view'} || $permission->{'cusr'}),
1.318 raeburn 5497: linktitle => $linktitles{$linkcontext}{'singleuser'},
1.298 droeschl 5498: },
5499: ]},
5500:
5501: {categorytitle => 'Multiple Users',
5502: items =>
5503: [
5504: {
1.318 raeburn 5505: linktext => $links{$linkcontext}{'upload'},
1.340 wenzelju 5506: icon => 'uplusr.png',
1.298 droeschl 5507: #help => 'Course_Create_Class_List',
5508: url => '/adm/createuser?action=upload',
5509: permission => $permission->{'cusr'},
5510: linktitle => 'Upload a CSV or a text file containing users.',
5511: },
5512: {
1.318 raeburn 5513: linktext => $links{$linkcontext}{'listusers'},
1.340 wenzelju 5514: icon => 'mngcu.png',
1.298 droeschl 5515: #help => 'Course_View_Class_List',
5516: url => '/adm/createuser?action=listusers',
5517: permission => ($permission->{'view'} || $permission->{'cusr'}),
1.318 raeburn 5518: linktitle => $linktitles{$linkcontext}{'listusers'},
1.298 droeschl 5519: },
5520:
5521: ]},
5522:
5523: {categorytitle => 'Administration',
5524: items => [ ]},
5525: );
1.415 raeburn 5526:
1.265 mielkec 5527: if ($context eq 'domain'){
1.416 raeburn 5528: push(@{ $menu[0]->{items} }, # Single Users
5529: {
5530: linktext => 'User Access Log',
1.417 raeburn 5531: icon => 'document-properties.png',
1.416 raeburn 5532: #help => 'User_Access_Logs',
5533: url => '/adm/createuser?action=accesslogs',
5534: permission => $permission->{'activity'},
5535: linktitle => 'View user access log.',
5536: }
5537: );
1.298 droeschl 5538:
5539: push(@{ $menu[2]->{items} }, #Category: Administration
5540: {
5541: linktext => 'Custom Roles',
5542: icon => 'emblem-photos.png',
5543: #help => 'Course_Editing_Custom_Roles',
5544: url => '/adm/createuser?action=custom',
5545: permission => $permission->{'custom'},
5546: linktitle => 'Configure a custom role.',
5547: },
1.362 raeburn 5548: {
5549: linktext => 'Authoring Space Requests',
5550: icon => 'selfenrl-queue.png',
5551: #help => 'Domain_Role_Approvals',
5552: url => '/adm/createuser?action=processauthorreq',
5553: permission => $permission->{'cusr'},
5554: linktitle => 'Approve or reject author role requests',
5555: },
1.363 raeburn 5556: {
1.391 raeburn 5557: linktext => 'LON-CAPA Account Requests',
5558: icon => 'list-add.png',
5559: #help => 'Domain_Username_Approvals',
5560: url => '/adm/createuser?action=processusernamereq',
5561: permission => $permission->{'cusr'},
5562: linktitle => 'Approve or reject LON-CAPA account requests',
5563: },
5564: {
1.363 raeburn 5565: linktext => 'Change Log',
5566: icon => 'document-properties.png',
5567: #help => 'Course_User_Logs',
5568: url => '/adm/createuser?action=changelogs',
1.418 raeburn 5569: permission => ($permission->{'cusr'} || $permission->{'view'}),
1.363 raeburn 5570: linktitle => 'View change log.',
5571: },
1.298 droeschl 5572: );
5573:
1.265 mielkec 5574: }elsif ($context eq 'course'){
1.298 droeschl 5575: my ($cnum,$cdom) = &Apache::lonuserutils::get_course_identity();
1.318 raeburn 5576:
5577: my %linktext = (
5578: 'Course' => {
5579: single => 'Add/Modify a Student',
5580: drop => 'Drop Students',
5581: groups => 'Course Groups',
5582: },
5583: 'Community' => {
5584: single => 'Add/Modify a Member',
5585: drop => 'Drop Members',
5586: groups => 'Community Groups',
5587: },
5588: );
1.411 raeburn 5589: $linktext{'Placement'} = $linktext{'Course'};
1.318 raeburn 5590:
5591: my %linktitle = (
5592: 'Course' => {
5593: single => 'Add a user with the role of student to this course',
5594: drop => 'Remove a student from this course.',
5595: groups => 'Manage course groups',
5596: },
5597: 'Community' => {
5598: single => 'Add a user with the role of member to this community',
5599: drop => 'Remove a member from this community.',
5600: groups => 'Manage community groups',
5601: },
5602: );
5603:
1.411 raeburn 5604: $linktitle{'Placement'} = $linktitle{'Course'};
5605:
1.298 droeschl 5606: push(@{ $menu[0]->{items} }, #Category: Single Users
5607: {
1.318 raeburn 5608: linktext => $linktext{$crstype}{'single'},
1.298 droeschl 5609: #help => 'Course_Add_Student',
5610: icon => 'list-add.png',
5611: url => '/adm/createuser?action=singlestudent',
5612: permission => $permission->{'cusr'},
1.318 raeburn 5613: linktitle => $linktitle{$crstype}{'single'},
1.298 droeschl 5614: },
5615: );
5616:
5617: push(@{ $menu[1]->{items} }, #Category: Multiple Users
5618: {
1.318 raeburn 5619: linktext => $linktext{$crstype}{'drop'},
1.298 droeschl 5620: icon => 'edit-undo.png',
5621: #help => 'Course_Drop_Student',
5622: url => '/adm/createuser?action=drop',
5623: permission => $permission->{'cusr'},
1.318 raeburn 5624: linktitle => $linktitle{$crstype}{'drop'},
1.298 droeschl 5625: },
5626: );
5627: push(@{ $menu[2]->{items} }, #Category: Administration
5628: {
5629: linktext => 'Custom Roles',
5630: icon => 'emblem-photos.png',
5631: #help => 'Course_Editing_Custom_Roles',
5632: url => '/adm/createuser?action=custom',
5633: permission => $permission->{'custom'},
5634: linktitle => 'Configure a custom role.',
5635: },
5636: {
1.318 raeburn 5637: linktext => $linktext{$crstype}{'groups'},
1.333 wenzelju 5638: icon => 'grps.png',
1.298 droeschl 5639: #help => 'Course_Manage_Group',
5640: url => '/adm/coursegroups?refpage=cusr',
5641: permission => $permission->{'grp_manage'},
1.318 raeburn 5642: linktitle => $linktitle{$crstype}{'groups'},
1.298 droeschl 5643: },
5644: {
1.328 wenzelju 5645: linktext => 'Change Log',
1.298 droeschl 5646: icon => 'document-properties.png',
5647: #help => 'Course_User_Logs',
5648: url => '/adm/createuser?action=changelogs',
1.418 raeburn 5649: permission => ($permission->{'view'} || $permission->{'cusr'}),
1.298 droeschl 5650: linktitle => 'View change log.',
5651: },
5652: );
1.277 raeburn 5653: if ($env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_approval'}) {
1.298 droeschl 5654: push(@{ $menu[2]->{items} },
1.398 raeburn 5655: {
1.298 droeschl 5656: linktext => 'Enrollment Requests',
5657: icon => 'selfenrl-queue.png',
5658: #help => 'Course_Approve_Selfenroll',
5659: url => '/adm/createuser?action=selfenrollqueue',
1.398 raeburn 5660: permission => $permission->{'selfenrolladmin'},
1.298 droeschl 5661: linktitle =>'Approve or reject enrollment requests.',
5662: },
5663: );
1.277 raeburn 5664: }
1.298 droeschl 5665:
1.265 mielkec 5666: if (!exists($permission->{'cusr_section'})){
1.320 raeburn 5667: if ($crstype ne 'Community') {
5668: push(@{ $menu[2]->{items} },
5669: {
5670: linktext => 'Automated Enrollment',
5671: icon => 'roles.png',
5672: #help => 'Course_Automated_Enrollment',
5673: permission => (&Apache::lonnet::auto_run($cnum,$cdom)
1.418 raeburn 5674: && (($permission->{'cusr'}) ||
5675: ($permission->{'view'}))),
1.320 raeburn 5676: url => '/adm/populate',
5677: linktitle => 'Automated enrollment manager.',
5678: }
5679: );
5680: }
5681: push(@{ $menu[2]->{items} },
1.298 droeschl 5682: {
5683: linktext => 'User Self-Enrollment',
1.342 wenzelju 5684: icon => 'self_enroll.png',
1.298 droeschl 5685: #help => 'Course_Self_Enrollment',
5686: url => '/adm/createuser?action=selfenroll',
1.398 raeburn 5687: permission => $permission->{'selfenrolladmin'},
1.317 bisitz 5688: linktitle => 'Configure user self-enrollment.',
1.298 droeschl 5689: },
5690: );
5691: }
1.363 raeburn 5692: } elsif ($context eq 'author') {
1.370 raeburn 5693: push(@{ $menu[2]->{items} }, #Category: Administration
1.363 raeburn 5694: {
5695: linktext => 'Change Log',
5696: icon => 'document-properties.png',
5697: #help => 'Course_User_Logs',
5698: url => '/adm/createuser?action=changelogs',
5699: permission => $permission->{'cusr'},
5700: linktitle => 'View change log.',
5701: },
1.370 raeburn 5702: );
1.363 raeburn 5703: }
5704: return Apache::lonhtmlcommon::generate_menu(@menu);
1.250 raeburn 5705: # { text => 'View Log-in History',
5706: # help => 'Course_User_Logins',
5707: # action => 'logins',
5708: # permission => $permission->{'cusr'},
5709: # });
1.190 raeburn 5710: }
5711:
1.189 albertel 5712: sub restore_prev_selections {
5713: my %saveable_parameters = ('srchby' => 'scalar',
5714: 'srchin' => 'scalar',
5715: 'srchtype' => 'scalar',
5716: );
5717: &Apache::loncommon::store_settings('user','user_picker',
5718: \%saveable_parameters);
5719: &Apache::loncommon::restore_settings('user','user_picker',
5720: \%saveable_parameters);
5721: }
5722:
1.237 raeburn 5723: sub print_selfenroll_menu {
1.418 raeburn 5724: my ($r,$context,$cid,$cdom,$cnum,$currsettings,$additional,$readonly) = @_;
1.322 raeburn 5725: my $crstype = &Apache::loncommon::course_type();
1.398 raeburn 5726: my $formname = 'selfenroll';
1.237 raeburn 5727: my $nolink = 1;
1.398 raeburn 5728: my ($row,$lt) = &Apache::lonuserutils::get_selfenroll_titles();
1.237 raeburn 5729: my $groupslist = &Apache::lonuserutils::get_groupslist();
5730: my $setsec_js =
5731: &Apache::lonuserutils::setsections_javascript($formname,$groupslist);
1.249 raeburn 5732: my %alerts = &Apache::lonlocal::texthash(
5733: acto => 'Activation of self-enrollment was selected for the following domain(s)',
5734: butn => 'but no user types have been checked.',
5735: wilf => "Please uncheck 'activate' or check at least one type.",
5736: );
1.418 raeburn 5737: my $disabled;
5738: if ($readonly) {
5739: $disabled = ' disabled="disabled"';
5740: }
1.405 damieng 5741: &js_escape(\%alerts);
1.249 raeburn 5742: my $selfenroll_js = <<"ENDSCRIPT";
5743: function update_types(caller,num) {
5744: var delidx = getIndexByName('selfenroll_delete');
5745: var actidx = getIndexByName('selfenroll_activate');
5746: if (caller == 'selfenroll_all') {
5747: var selall;
5748: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
5749: if (document.$formname.selfenroll_all[i].checked) {
5750: selall = document.$formname.selfenroll_all[i].value;
5751: }
5752: }
5753: if (selall == 1) {
5754: if (delidx != -1) {
5755: if (document.$formname.selfenroll_delete.length) {
5756: for (var j=0; j<document.$formname.selfenroll_delete.length; j++) {
5757: document.$formname.selfenroll_delete[j].checked = true;
5758: }
5759: } else {
5760: document.$formname.elements[delidx].checked = true;
5761: }
5762: }
5763: if (actidx != -1) {
5764: if (document.$formname.selfenroll_activate.length) {
5765: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
5766: document.$formname.selfenroll_activate[j].checked = false;
5767: }
5768: } else {
5769: document.$formname.elements[actidx].checked = false;
5770: }
5771: }
5772: document.$formname.selfenroll_newdom.selectedIndex = 0;
5773: }
5774: }
5775: if (caller == 'selfenroll_activate') {
5776: if (document.$formname.selfenroll_activate.length) {
5777: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
5778: if (document.$formname.selfenroll_activate[j].value == num) {
5779: if (document.$formname.selfenroll_activate[j].checked) {
5780: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
5781: if (document.$formname.selfenroll_all[i].value == '1') {
5782: document.$formname.selfenroll_all[i].checked = false;
5783: }
5784: if (document.$formname.selfenroll_all[i].value == '0') {
5785: document.$formname.selfenroll_all[i].checked = true;
5786: }
5787: }
5788: }
5789: }
5790: }
5791: } else {
5792: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
5793: if (document.$formname.selfenroll_all[i].value == '1') {
5794: document.$formname.selfenroll_all[i].checked = false;
5795: }
5796: if (document.$formname.selfenroll_all[i].value == '0') {
5797: document.$formname.selfenroll_all[i].checked = true;
5798: }
5799: }
5800: }
5801: }
5802: if (caller == 'selfenroll_delete') {
5803: if (document.$formname.selfenroll_delete.length) {
5804: for (var j=0; j<document.$formname.selfenroll_delete.length; j++) {
5805: if (document.$formname.selfenroll_delete[j].value == num) {
5806: if (document.$formname.selfenroll_delete[j].checked) {
5807: var delindex = getIndexByName('selfenroll_types_'+num);
5808: if (delindex != -1) {
5809: if (document.$formname.elements[delindex].length) {
5810: for (var k=0; k<document.$formname.elements[delindex].length; k++) {
5811: document.$formname.elements[delindex][k].checked = false;
5812: }
5813: } else {
5814: document.$formname.elements[delindex].checked = false;
5815: }
5816: }
5817: }
5818: }
5819: }
5820: } else {
5821: if (document.$formname.selfenroll_delete.checked) {
5822: var delindex = getIndexByName('selfenroll_types_'+num);
5823: if (delindex != -1) {
5824: if (document.$formname.elements[delindex].length) {
5825: for (var k=0; k<document.$formname.elements[delindex].length; k++) {
5826: document.$formname.elements[delindex][k].checked = false;
5827: }
5828: } else {
5829: document.$formname.elements[delindex].checked = false;
5830: }
5831: }
5832: }
5833: }
5834: }
5835: return;
5836: }
5837:
5838: function validate_types(form) {
5839: var needaction = new Array();
5840: var countfail = 0;
5841: var actidx = getIndexByName('selfenroll_activate');
5842: if (actidx != -1) {
5843: if (document.$formname.selfenroll_activate.length) {
5844: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
5845: var num = document.$formname.selfenroll_activate[j].value;
5846: if (document.$formname.selfenroll_activate[j].checked) {
5847: countfail = check_types(num,countfail,needaction)
5848: }
5849: }
5850: } else {
5851: if (document.$formname.selfenroll_activate.checked) {
1.398 raeburn 5852: var num = document.$formname.selfenroll_activate.value;
1.249 raeburn 5853: countfail = check_types(num,countfail,needaction)
5854: }
5855: }
5856: }
5857: if (countfail > 0) {
5858: var msg = "$alerts{'acto'}\\n";
5859: var loopend = needaction.length -1;
5860: if (loopend > 0) {
5861: for (var m=0; m<loopend; m++) {
5862: msg += needaction[m]+", ";
5863: }
5864: }
5865: msg += needaction[loopend]+"\\n$alerts{'butn'}\\n$alerts{'wilf'}";
5866: alert(msg);
5867: return;
5868: }
5869: setSections(form);
5870: }
5871:
5872: function check_types(num,countfail,needaction) {
5873: var typeidx = getIndexByName('selfenroll_types_'+num);
5874: var count = 0;
5875: if (typeidx != -1) {
5876: if (document.$formname.elements[typeidx].length) {
5877: for (var k=0; k<document.$formname.elements[typeidx].length; k++) {
5878: if (document.$formname.elements[typeidx][k].checked) {
5879: count ++;
5880: }
5881: }
5882: } else {
5883: if (document.$formname.elements[typeidx].checked) {
5884: count ++;
5885: }
5886: }
5887: if (count == 0) {
5888: var domidx = getIndexByName('selfenroll_dom_'+num);
5889: if (domidx != -1) {
5890: var domname = document.$formname.elements[domidx].value;
5891: needaction[countfail] = domname;
5892: countfail ++;
5893: }
5894: }
5895: }
5896: return countfail;
5897: }
5898:
1.398 raeburn 5899: function toggleNotify() {
5900: var selfenrollApproval = 0;
5901: if (document.$formname.selfenroll_approval.length) {
5902: for (var i=0; i<document.$formname.selfenroll_approval.length; i++) {
5903: if (document.$formname.selfenroll_approval[i].checked) {
5904: selfenrollApproval = document.$formname.selfenroll_approval[i].value;
5905: break;
5906: }
5907: }
5908: }
5909: if (document.getElementById('notified')) {
5910: if (selfenrollApproval == 0) {
5911: document.getElementById('notified').style.display='none';
5912: } else {
5913: document.getElementById('notified').style.display='block';
5914: }
5915: }
5916: return;
5917: }
5918:
1.249 raeburn 5919: function getIndexByName(item) {
5920: for (var i=0;i<document.$formname.elements.length;i++) {
5921: if (document.$formname.elements[i].name == item) {
5922: return i;
5923: }
5924: }
5925: return -1;
5926: }
5927: ENDSCRIPT
1.256 raeburn 5928:
1.237 raeburn 5929: my $output = '<script type="text/javascript">'."\n".
1.301 bisitz 5930: '// <![CDATA['."\n".
1.249 raeburn 5931: $setsec_js."\n".$selfenroll_js."\n".
1.301 bisitz 5932: '// ]]>'."\n".
1.237 raeburn 5933: '</script>'."\n".
1.256 raeburn 5934: '<h3>'.$lt->{'selfenroll'}.'</h3>'."\n";
1.400 raeburn 5935:
5936: my $visactions = &cat_visibility();
5937: my ($cathash,%cattype);
5938: my %domconfig = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom);
5939: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
5940: $cathash = $domconfig{'coursecategories'}{'cats'};
5941: $cattype{'auth'} = $domconfig{'coursecategories'}{'auth'};
5942: $cattype{'unauth'} = $domconfig{'coursecategories'}{'unauth'};
1.406 raeburn 5943: if ($cattype{'auth'} eq '') {
5944: $cattype{'auth'} = 'std';
5945: }
5946: if ($cattype{'unauth'} eq '') {
5947: $cattype{'unauth'} = 'std';
5948: }
1.400 raeburn 5949: } else {
5950: $cathash = {};
5951: $cattype{'auth'} = 'std';
5952: $cattype{'unauth'} = 'std';
5953: }
5954: if (($cattype{'auth'} eq 'none') && ($cattype{'unauth'} eq 'none')) {
5955: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
5956: '<br />'.
5957: '<br />'.$visactions->{'take'}.'<ul>'.
5958: '<li>'.$visactions->{'dc_chgconf'}.'</li>'.
5959: '</ul>');
5960: } elsif (($cattype{'auth'} !~ /^(std|domonly)$/) && ($cattype{'unauth'} !~ /^(std|domonly)$/)) {
5961: if ($currsettings->{'uniquecode'}) {
5962: $r->print('<span class="LC_info">'.$visactions->{'vis'}.'</span>');
5963: } else {
5964: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
5965: '<br />'.
5966: '<br />'.$visactions->{'take'}.'<ul>'.
5967: '<li>'.$visactions->{'dc_setcode'}.'</li>'.
5968: '</ul><br />');
5969: }
5970: } else {
5971: my ($visible,$cansetvis,$vismsgs) = &visible_in_stdcat($cdom,$cnum,\%domconfig);
5972: if (ref($visactions) eq 'HASH') {
5973: if ($visible) {
5974: $output .= '<p class="LC_info">'.$visactions->{'vis'}.'</p>';
5975: } else {
5976: $output .= '<p class="LC_warning">'.$visactions->{'miss'}.'</p>'
5977: .$visactions->{'yous'}.
5978: '<p>'.$visactions->{'gen'}.'<br />'.$visactions->{'coca'};
5979: if (ref($vismsgs) eq 'ARRAY') {
5980: $output .= '<br />'.$visactions->{'make'}.'<ul>';
5981: foreach my $item (@{$vismsgs}) {
5982: $output .= '<li>'.$visactions->{$item}.'</li>';
5983: }
5984: $output .= '</ul>';
1.256 raeburn 5985: }
1.400 raeburn 5986: $output .= '</p>';
1.256 raeburn 5987: }
5988: }
5989: }
1.398 raeburn 5990: my $actionhref = '/adm/createuser';
5991: if ($context eq 'domain') {
5992: $actionhref = '/adm/modifycourse';
5993: }
1.400 raeburn 5994:
5995: my %noedit;
5996: unless ($context eq 'domain') {
5997: %noedit = &get_noedit_fields($cdom,$cnum,$crstype,$row);
5998: }
1.398 raeburn 5999: $output .= '<form name="'.$formname.'" method="post" action="'.$actionhref.'">'."\n".
1.256 raeburn 6000: &Apache::lonhtmlcommon::start_pick_box();
1.237 raeburn 6001: if (ref($row) eq 'ARRAY') {
6002: foreach my $item (@{$row}) {
6003: my $title = $item;
6004: if (ref($lt) eq 'HASH') {
6005: $title = $lt->{$item};
6006: }
1.297 bisitz 6007: $output .= &Apache::lonhtmlcommon::row_title($title);
1.237 raeburn 6008: if ($item eq 'types') {
1.398 raeburn 6009: my $curr_types;
6010: if (ref($currsettings) eq 'HASH') {
6011: $curr_types = $currsettings->{'selfenroll_types'};
6012: }
1.400 raeburn 6013: if ($noedit{$item}) {
6014: if ($curr_types eq '*') {
6015: $output .= &mt('Any user in any domain');
6016: } else {
6017: my @entries = split(/;/,$curr_types);
6018: if (@entries > 0) {
6019: $output .= '<ul>';
6020: foreach my $entry (@entries) {
6021: my ($currdom,$typestr) = split(/:/,$entry);
6022: next if ($typestr eq '');
6023: my $domdesc = &Apache::lonnet::domain($currdom);
6024: my @currinsttypes = split(',',$typestr);
6025: my ($othertitle,$usertypes,$types) =
6026: &Apache::loncommon::sorted_inst_types($currdom);
6027: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
6028: $usertypes->{'any'} = &mt('any user');
6029: if (keys(%{$usertypes}) > 0) {
6030: $usertypes->{'other'} = &mt('other users');
6031: }
6032: my @longinsttypes = map { $usertypes->{$_}; } @currinsttypes;
6033: $output .= '<li>'.$domdesc.':'.join(', ',@longinsttypes).'</li>';
6034: }
6035: }
6036: $output .= '</ul>';
6037: } else {
6038: $output .= &mt('None');
6039: }
6040: }
6041: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6042: next;
6043: }
1.241 raeburn 6044: my $showdomdesc = 1;
6045: my $includeempty = 1;
6046: my $num = 0;
6047: $output .= &Apache::loncommon::start_data_table().
6048: &Apache::loncommon::start_data_table_row()
6049: .'<td colspan="2"><span class="LC_nobreak"><label>'
6050: .&mt('Any user in any domain:')
6051: .' <input type="radio" name="selfenroll_all" value="1" ';
6052: if ($curr_types eq '*') {
6053: $output .= ' checked="checked" ';
6054: }
1.249 raeburn 6055: $output .= 'onchange="javascript:update_types('.
1.418 raeburn 6056: "'selfenroll_all'".');"'.$disabled.' />'.&mt('Yes').'</label>'.
1.249 raeburn 6057: ' <input type="radio" name="selfenroll_all" value="0" ';
1.241 raeburn 6058: if ($curr_types ne '*') {
6059: $output .= ' checked="checked" ';
6060: }
1.249 raeburn 6061: $output .= ' onchange="javascript:update_types('.
1.418 raeburn 6062: "'selfenroll_all'".');"'.$disabled.' />'.&mt('No').'</label></td>'.
1.249 raeburn 6063: &Apache::loncommon::end_data_table_row().
6064: &Apache::loncommon::end_data_table().
6065: &mt('Or').'<br />'.
6066: &Apache::loncommon::start_data_table();
1.241 raeburn 6067: my %currdoms;
1.249 raeburn 6068: if ($curr_types eq '') {
1.241 raeburn 6069: $output .= &new_selfenroll_dom_row($cdom,'0');
6070: } elsif ($curr_types ne '*') {
6071: my @entries = split(/;/,$curr_types);
6072: if (@entries > 0) {
6073: foreach my $entry (@entries) {
6074: my ($currdom,$typestr) = split(/:/,$entry);
6075: $currdoms{$currdom} = 1;
6076: my $domdesc = &Apache::lonnet::domain($currdom);
1.249 raeburn 6077: my @currinsttypes = split(',',$typestr);
1.241 raeburn 6078: $output .= &Apache::loncommon::start_data_table_row()
6079: .'<td valign="top"><span class="LC_nobreak">'.&mt('Domain:').'<b>'
6080: .' '.$domdesc.' ('.$currdom.')'
6081: .'</b><input type="hidden" name="selfenroll_dom_'.$num
6082: .'" value="'.$currdom.'" /></span><br />'
6083: .'<span class="LC_nobreak"><label><input type="checkbox" '
1.418 raeburn 6084: .'name="selfenroll_delete" value="'.$num.'" onchange="javascript:update_types('."'selfenroll_delete','$num'".');"'.$disabled.' />'
1.241 raeburn 6085: .&mt('Delete').'</label></span></td>';
1.249 raeburn 6086: $output .= '<td valign="top"> '.&mt('User types:').'<br />'
1.418 raeburn 6087: .&selfenroll_inst_types($num,$currdom,\@currinsttypes,$readonly).'</td>'
1.241 raeburn 6088: .&Apache::loncommon::end_data_table_row();
6089: $num ++;
6090: }
6091: }
6092: }
1.249 raeburn 6093: my $add_domtitle = &mt('Users in additional domain:');
1.241 raeburn 6094: if ($curr_types eq '*') {
1.249 raeburn 6095: $add_domtitle = &mt('Users in specific domain:');
1.241 raeburn 6096: } elsif ($curr_types eq '') {
1.249 raeburn 6097: $add_domtitle = &mt('Users in other domain:');
1.241 raeburn 6098: }
6099: $output .= &Apache::loncommon::start_data_table_row()
6100: .'<td colspan="2"><span class="LC_nobreak">'.$add_domtitle.'</span><br />'
6101: .&Apache::loncommon::select_dom_form('','selfenroll_newdom',
1.418 raeburn 6102: $includeempty,$showdomdesc,'','','',$readonly)
1.241 raeburn 6103: .'<input type="hidden" name="selfenroll_types_total" value="'.$num.'" />'
6104: .'</td>'.&Apache::loncommon::end_data_table_row()
6105: .&Apache::loncommon::end_data_table();
1.237 raeburn 6106: } elsif ($item eq 'registered') {
6107: my ($regon,$regoff);
1.398 raeburn 6108: my $registered;
6109: if (ref($currsettings) eq 'HASH') {
6110: $registered = $currsettings->{'selfenroll_registered'};
6111: }
1.400 raeburn 6112: if ($noedit{$item}) {
6113: if ($registered) {
6114: $output .= &mt('Must be registered in course');
6115: } else {
6116: $output .= &mt('No requirement');
6117: }
6118: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6119: next;
6120: }
1.398 raeburn 6121: if ($registered) {
1.237 raeburn 6122: $regon = ' checked="checked" ';
1.419 raeburn 6123: $regoff = '';
1.237 raeburn 6124: } else {
1.419 raeburn 6125: $regon = '';
1.237 raeburn 6126: $regoff = ' checked="checked" ';
6127: }
6128: $output .= '<label>'.
1.419 raeburn 6129: '<input type="radio" name="selfenroll_registered" value="1"'.$regon.$disabled.' />'.
1.244 bisitz 6130: &mt('Yes').'</label> <label>'.
1.419 raeburn 6131: '<input type="radio" name="selfenroll_registered" value="0"'.$regoff.$disabled.' />'.
1.244 bisitz 6132: &mt('No').'</label>';
1.237 raeburn 6133: } elsif ($item eq 'enroll_dates') {
1.398 raeburn 6134: my ($starttime,$endtime);
6135: if (ref($currsettings) eq 'HASH') {
6136: $starttime = $currsettings->{'selfenroll_start_date'};
6137: $endtime = $currsettings->{'selfenroll_end_date'};
6138: if ($starttime eq '') {
6139: $starttime = $currsettings->{'default_enrollment_start_date'};
6140: }
6141: if ($endtime eq '') {
6142: $endtime = $currsettings->{'default_enrollment_end_date'};
6143: }
1.237 raeburn 6144: }
1.400 raeburn 6145: if ($noedit{$item}) {
6146: $output .= &mt('From: [_1], to: [_2]',&Apache::lonlocal::locallocaltime($starttime),
6147: &Apache::lonlocal::locallocaltime($endtime));
6148: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6149: next;
6150: }
1.237 raeburn 6151: my $startform =
6152: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_start_date',$starttime,
1.418 raeburn 6153: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
1.237 raeburn 6154: my $endform =
6155: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_end_date',$endtime,
1.418 raeburn 6156: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
1.237 raeburn 6157: $output .= &selfenroll_date_forms($startform,$endform);
6158: } elsif ($item eq 'access_dates') {
1.398 raeburn 6159: my ($starttime,$endtime);
6160: if (ref($currsettings) eq 'HASH') {
6161: $starttime = $currsettings->{'selfenroll_start_access'};
6162: $endtime = $currsettings->{'selfenroll_end_access'};
6163: if ($starttime eq '') {
6164: $starttime = $currsettings->{'default_enrollment_start_date'};
6165: }
6166: if ($endtime eq '') {
6167: $endtime = $currsettings->{'default_enrollment_end_date'};
6168: }
1.237 raeburn 6169: }
1.400 raeburn 6170: if ($noedit{$item}) {
6171: $output .= &mt('From: [_1], to: [_2]',&Apache::lonlocal::locallocaltime($starttime),
6172: &Apache::lonlocal::locallocaltime($endtime));
6173: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6174: next;
6175: }
1.237 raeburn 6176: my $startform =
6177: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_start_access',$starttime,
1.418 raeburn 6178: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
1.237 raeburn 6179: my $endform =
6180: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_end_access',$endtime,
1.418 raeburn 6181: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
1.237 raeburn 6182: $output .= &selfenroll_date_forms($startform,$endform);
6183: } elsif ($item eq 'section') {
1.398 raeburn 6184: my $currsec;
6185: if (ref($currsettings) eq 'HASH') {
6186: $currsec = $currsettings->{'selfenroll_section'};
6187: }
1.237 raeburn 6188: my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum);
6189: my $newsecval;
6190: if ($currsec ne 'none' && $currsec ne '') {
6191: if (!defined($sections_count{$currsec})) {
6192: $newsecval = $currsec;
6193: }
6194: }
1.400 raeburn 6195: if ($noedit{$item}) {
6196: if ($currsec ne '') {
6197: $output .= $currsec;
6198: } else {
6199: $output .= &mt('No specific section');
6200: }
6201: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6202: next;
6203: }
1.237 raeburn 6204: my $sections_select =
1.418 raeburn 6205: &Apache::lonuserutils::course_sections(\%sections_count,'st',$currsec,$disabled);
1.237 raeburn 6206: $output .= '<table class="LC_createuser">'."\n".
6207: '<tr class="LC_section_row">'."\n".
6208: '<td align="center">'.&mt('Existing sections')."\n".
6209: '<br />'.$sections_select.'</td><td align="center">'.
6210: &mt('New section').'<br />'."\n".
1.418 raeburn 6211: '<input type="text" name="newsec" size="15" value="'.$newsecval.'"'.$disabled.' />'."\n".
1.237 raeburn 6212: '<input type="hidden" name="sections" value="" />'."\n".
6213: '</td></tr></table>'."\n";
1.276 raeburn 6214: } elsif ($item eq 'approval') {
1.398 raeburn 6215: my ($currnotified,$currapproval,%appchecked);
6216: my %selfdescs = &Apache::lonuserutils::selfenroll_default_descs();
6217: if (ref($currsettings) eq 'HASH') {
6218: $currnotified = $currsettings->{'selfenroll_notifylist'};
6219: $currapproval = $currsettings->{'selfenroll_approval'};
6220: }
6221: if ($currapproval !~ /^[012]$/) {
6222: $currapproval = 0;
6223: }
1.400 raeburn 6224: if ($noedit{$item}) {
6225: $output .= $selfdescs{'approval'}{$currapproval}.
6226: '<br />'.&mt('(Set by Domain Coordinator)');
6227: next;
6228: }
1.398 raeburn 6229: $appchecked{$currapproval} = ' checked="checked"';
6230: for my $i (0..2) {
6231: $output .= '<label>'.
6232: '<input type="radio" name="selfenroll_approval" value="'.$i.'"'.
1.418 raeburn 6233: $appchecked{$i}.' onclick="toggleNotify();"'.$disabled.' />'.
6234: $selfdescs{'approval'}{$i}.'</label>'.(' 'x2);
1.276 raeburn 6235: }
6236: my %advhash = &Apache::lonnet::get_course_adv_roles($cid,1);
6237: my (@ccs,%notified);
1.322 raeburn 6238: my $ccrole = 'cc';
6239: if ($crstype eq 'Community') {
6240: $ccrole = 'co';
6241: }
6242: if ($advhash{$ccrole}) {
6243: @ccs = split(/,/,$advhash{$ccrole});
1.276 raeburn 6244: }
6245: if ($currnotified) {
6246: foreach my $current (split(/,/,$currnotified)) {
6247: $notified{$current} = 1;
6248: if (!grep(/^\Q$current\E$/,@ccs)) {
6249: push(@ccs,$current);
6250: }
6251: }
6252: }
6253: if (@ccs) {
1.398 raeburn 6254: my $style;
6255: unless ($currapproval) {
6256: $style = ' style="display: none;"';
6257: }
6258: $output .= '<br /><div id="notified"'.$style.'>'.
6259: &mt('Personnel to be notified when an enrollment request needs approval, or has been approved:').' '.
6260: &Apache::loncommon::start_data_table().
1.276 raeburn 6261: &Apache::loncommon::start_data_table_row();
6262: my $count = 0;
6263: my $numcols = 4;
6264: foreach my $cc (sort(@ccs)) {
6265: my $notifyon;
6266: my ($ccuname,$ccudom) = split(/:/,$cc);
6267: if ($notified{$cc}) {
6268: $notifyon = ' checked="checked" ';
6269: }
6270: if ($count && !$count%$numcols) {
6271: $output .= &Apache::loncommon::end_data_table_row().
6272: &Apache::loncommon::start_data_table_row()
6273: }
6274: $output .= '<td><span class="LC_nobreak"><label>'.
1.418 raeburn 6275: '<input type="checkbox" name="selfenroll_notify"'.$notifyon.' value="'.$cc.'"'.$disabled.' />'.
1.276 raeburn 6276: &Apache::loncommon::plainname($ccuname,$ccudom).
6277: '</label></span></td>';
1.343 raeburn 6278: $count ++;
1.276 raeburn 6279: }
6280: my $rem = $count%$numcols;
6281: if ($rem) {
6282: my $emptycols = $numcols - $rem;
6283: for (my $i=0; $i<$emptycols; $i++) {
6284: $output .= '<td> </td>';
6285: }
6286: }
6287: $output .= &Apache::loncommon::end_data_table_row().
1.398 raeburn 6288: &Apache::loncommon::end_data_table().
6289: '</div>';
1.276 raeburn 6290: }
6291: } elsif ($item eq 'limit') {
1.398 raeburn 6292: my ($crslimit,$selflimit,$nolimit,$currlim,$currcap);
6293: if (ref($currsettings) eq 'HASH') {
6294: $currlim = $currsettings->{'selfenroll_limit'};
6295: $currcap = $currsettings->{'selfenroll_cap'};
6296: }
1.400 raeburn 6297: if ($noedit{$item}) {
6298: if (($currlim eq 'allstudents') || ($currlim eq 'selfenrolled')) {
6299: if ($currlim eq 'allstudents') {
6300: $output .= &mt('Limit by total students');
6301: } elsif ($currlim eq 'selfenrolled') {
6302: $output .= &mt('Limit by total self-enrolled students');
6303: }
6304: $output .= ' '.&mt('Maximum: [_1]',$currcap).
6305: '<br />'.&mt('(Set by Domain Coordinator)');
6306: } else {
6307: $output .= &mt('No limit').'<br />'.&mt('(Set by Domain Coordinator)');
6308: }
6309: next;
6310: }
1.276 raeburn 6311: if ($currlim eq 'allstudents') {
6312: $crslimit = ' checked="checked" ';
6313: $selflimit = ' ';
6314: $nolimit = ' ';
6315: } elsif ($currlim eq 'selfenrolled') {
6316: $crslimit = ' ';
6317: $selflimit = ' checked="checked" ';
6318: $nolimit = ' ';
6319: } else {
6320: $crslimit = ' ';
6321: $selflimit = ' ';
1.398 raeburn 6322: $nolimit = ' checked="checked" ';
1.276 raeburn 6323: }
6324: $output .= '<table><tr><td><label>'.
1.418 raeburn 6325: '<input type="radio" name="selfenroll_limit" value="none"'.$nolimit.$disabled.'/>'.
1.276 raeburn 6326: &mt('No limit').'</label></td><td><label>'.
1.418 raeburn 6327: '<input type="radio" name="selfenroll_limit" value="allstudents"'.$crslimit.$disabled.'/>'.
1.276 raeburn 6328: &mt('Limit by total students').'</label></td><td><label>'.
1.418 raeburn 6329: '<input type="radio" name="selfenroll_limit" value="selfenrolled"'.$selflimit.$disabled.'/>'.
1.276 raeburn 6330: &mt('Limit by total self-enrolled students').
6331: '</td></tr><tr>'.
6332: '<td> </td><td colspan="2"><span class="LC_nobreak">'.
6333: (' 'x3).&mt('Maximum number allowed: ').
1.418 raeburn 6334: '<input type="text" name="selfenroll_cap" size = "5" value="'.$currcap.'"'.$disabled.' /></td></tr></table>';
1.237 raeburn 6335: }
6336: $output .= &Apache::lonhtmlcommon::row_closure(1);
6337: }
6338: }
1.418 raeburn 6339: $output .= &Apache::lonhtmlcommon::end_pick_box().'<br />';
6340: unless ($readonly) {
6341: $output .= '<input type="button" name="selfenrollconf" value="'
6342: .&mt('Save').'" onclick="validate_types(this.form);" />';
6343: }
6344: $output .= '<input type="hidden" name="action" value="selfenroll" />'
6345: .'<input type="hidden" name="state" value="done" />'."\n"
6346: .$additional.'</form>';
1.237 raeburn 6347: $r->print($output);
6348: return;
6349: }
6350:
1.400 raeburn 6351: sub get_noedit_fields {
6352: my ($cdom,$cnum,$crstype,$row) = @_;
6353: my %noedit;
6354: if (ref($row) eq 'ARRAY') {
6355: my %settings = &Apache::lonnet::get('environment',['internal.coursecode','internal.textbook',
6356: 'internal.selfenrollmgrdc',
6357: 'internal.selfenrollmgrcc'],$cdom,$cnum);
6358: my $type = &Apache::lonuserutils::get_extended_type($cdom,$cnum,$crstype,\%settings);
6359: my (%specific_managebydc,%specific_managebycc,%default_managebydc);
6360: map { $specific_managebydc{$_} = 1; } (split(/,/,$settings{'internal.selfenrollmgrdc'}));
6361: map { $specific_managebycc{$_} = 1; } (split(/,/,$settings{'internal.selfenrollmgrcc'}));
6362: my %domdefaults = &Apache::lonnet::get_domain_defaults($cdom);
6363: map { $default_managebydc{$_} = 1; } (split(/,/,$domdefaults{$type.'selfenrolladmdc'}));
6364:
6365: foreach my $item (@{$row}) {
6366: next if ($specific_managebycc{$item});
6367: if (($specific_managebydc{$item}) || ($default_managebydc{$item})) {
6368: $noedit{$item} = 1;
6369: }
6370: }
6371: }
6372: return %noedit;
6373: }
6374:
6375: sub visible_in_stdcat {
6376: my ($cdom,$cnum,$domconf) = @_;
6377: my ($cathash,%settable,@vismsgs,$cansetvis,$visible);
6378: unless (ref($domconf) eq 'HASH') {
6379: return ($visible,$cansetvis,\@vismsgs);
6380: }
6381: if (ref($domconf->{'coursecategories'}) eq 'HASH') {
6382: if ($domconf->{'coursecategories'}{'togglecats'} eq 'crs') {
1.256 raeburn 6383: $settable{'togglecats'} = 1;
6384: }
1.400 raeburn 6385: if ($domconf->{'coursecategories'}{'categorize'} eq 'crs') {
1.256 raeburn 6386: $settable{'categorize'} = 1;
6387: }
1.400 raeburn 6388: $cathash = $domconf->{'coursecategories'}{'cats'};
1.256 raeburn 6389: }
1.260 raeburn 6390: if ($settable{'togglecats'} && $settable{'categorize'}) {
1.256 raeburn 6391: $cansetvis = &mt('You are able to both assign a course category and choose to exclude this course from the catalog.');
6392: } elsif ($settable{'togglecats'}) {
6393: $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 6394: } elsif ($settable{'categorize'}) {
1.256 raeburn 6395: $cansetvis = &mt('You may assign a course category, but only a Domain Coordinator may choose to exclude this course from the catalog.');
6396: } else {
6397: $cansetvis = &mt('Only a Domain Coordinator may assign a course category or choose to exclude this course from the catalog.');
6398: }
6399:
6400: my %currsettings =
6401: &Apache::lonnet::get('environment',['hidefromcat','categories','internal.coursecode'],
6402: $cdom,$cnum);
1.400 raeburn 6403: $visible = 0;
1.256 raeburn 6404: if ($currsettings{'internal.coursecode'} ne '') {
1.400 raeburn 6405: if (ref($domconf->{'coursecategories'}) eq 'HASH') {
6406: $cathash = $domconf->{'coursecategories'}{'cats'};
1.256 raeburn 6407: if (ref($cathash) eq 'HASH') {
6408: if ($cathash->{'instcode::0'} eq '') {
6409: push(@vismsgs,'dc_addinst');
6410: } else {
6411: $visible = 1;
6412: }
6413: } else {
6414: $visible = 1;
6415: }
6416: } else {
6417: $visible = 1;
6418: }
6419: } else {
6420: if (ref($cathash) eq 'HASH') {
6421: if ($cathash->{'instcode::0'} ne '') {
6422: push(@vismsgs,'dc_instcode');
6423: }
6424: } else {
6425: push(@vismsgs,'dc_instcode');
6426: }
6427: }
6428: if ($currsettings{'categories'} ne '') {
6429: my $cathash;
1.400 raeburn 6430: if (ref($domconf->{'coursecategories'}) eq 'HASH') {
6431: $cathash = $domconf->{'coursecategories'}{'cats'};
1.256 raeburn 6432: if (ref($cathash) eq 'HASH') {
6433: if (keys(%{$cathash}) == 0) {
6434: push(@vismsgs,'dc_catalog');
6435: } elsif ((keys(%{$cathash}) == 1) && ($cathash->{'instcode::0'} ne '')) {
6436: push(@vismsgs,'dc_categories');
6437: } else {
6438: my @currcategories = split('&',$currsettings{'categories'});
6439: my $matched = 0;
6440: foreach my $cat (@currcategories) {
6441: if ($cathash->{$cat} ne '') {
6442: $visible = 1;
6443: $matched = 1;
6444: last;
6445: }
6446: }
6447: if (!$matched) {
1.260 raeburn 6448: if ($settable{'categorize'}) {
1.256 raeburn 6449: push(@vismsgs,'chgcat');
6450: } else {
6451: push(@vismsgs,'dc_chgcat');
6452: }
6453: }
6454: }
6455: }
6456: }
6457: } else {
6458: if (ref($cathash) eq 'HASH') {
6459: if ((keys(%{$cathash}) > 1) ||
6460: (keys(%{$cathash}) == 1) && ($cathash->{'instcode::0'} eq '')) {
1.260 raeburn 6461: if ($settable{'categorize'}) {
1.256 raeburn 6462: push(@vismsgs,'addcat');
6463: } else {
6464: push(@vismsgs,'dc_addcat');
6465: }
6466: }
6467: }
6468: }
6469: if ($currsettings{'hidefromcat'} eq 'yes') {
6470: $visible = 0;
6471: if ($settable{'togglecats'}) {
6472: unshift(@vismsgs,'unhide');
6473: } else {
6474: unshift(@vismsgs,'dc_unhide')
6475: }
6476: }
1.400 raeburn 6477: return ($visible,$cansetvis,\@vismsgs);
6478: }
6479:
6480: sub cat_visibility {
6481: my %visactions = &Apache::lonlocal::texthash(
6482: vis => 'This course/community currently appears in the Course/Community Catalog for this domain.',
6483: 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.',
6484: miss => 'This course/community does not currently appear in the Course/Community Catalog for this domain.',
6485: none => 'Display of a course catalog is disabled for this domain.',
6486: yous => 'You should remedy this if you plan to allow self-enrollment, otherwise students will have difficulty finding this course.',
6487: 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.',
6488: make => 'Make any changes to self-enrollment settings below, click "Save", then take action to include the course in the Catalog:',
6489: take => 'Take the following action to ensure the course appears in the Catalog:',
6490: dc_chgconf => 'Ask a domain coordinator to change the Catalog type for this domain.',
6491: dc_setcode => 'Ask a domain coordinator to assign a six character code to the course',
6492: dc_unhide => 'Ask a domain coordinator to change the "Exclude from course catalog" setting.',
6493: dc_addinst => 'Ask a domain coordinator to enable display the catalog of "Official courses (with institutional codes)".',
6494: dc_instcode => 'Ask a domain coordinator to assign an institutional code (if this is an official course).',
6495: dc_catalog => 'Ask a domain coordinator to enable or create at least one course category in the domain.',
6496: dc_categories => 'Ask a domain coordinator to create a hierarchy of categories and sub categories for courses in the domain.',
6497: 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',
6498: dc_addcat => 'Ask a domain coordinator to assign a category to the course.',
6499: );
6500: $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>"');
6501: $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>"');
6502: $visactions{'addcat'} = &mt('Use [_1]Categorize course[_2] to assign a category to the course.','"<a href="/adm/courseprefs?phase=display&actions=courseinfo">','</a>"');
6503: return \%visactions;
1.256 raeburn 6504: }
6505:
1.241 raeburn 6506: sub new_selfenroll_dom_row {
6507: my ($newdom,$num) = @_;
6508: my $domdesc = &Apache::lonnet::domain($newdom);
6509: my $output;
6510: if ($domdesc ne '') {
6511: $output .= &Apache::loncommon::start_data_table_row()
6512: .'<td valign="top"><span class="LC_nobreak">'.&mt('Domain:').' <b>'.$domdesc
6513: .' ('.$newdom.')</b><input type="hidden" name="selfenroll_dom_'.$num
1.249 raeburn 6514: .'" value="'.$newdom.'" /></span><br />'
6515: .'<span class="LC_nobreak"><label><input type="checkbox" '
6516: .'name="selfenroll_activate" value="'.$num.'" '
6517: .'onchange="javascript:update_types('
6518: ."'selfenroll_activate','$num'".');" />'
6519: .&mt('Activate').'</label></span></td>';
1.241 raeburn 6520: my @currinsttypes;
6521: $output .= '<td>'.&mt('User types:').'<br />'
6522: .&selfenroll_inst_types($num,$newdom,\@currinsttypes).'</td>'
6523: .&Apache::loncommon::end_data_table_row();
6524: }
6525: return $output;
6526: }
6527:
6528: sub selfenroll_inst_types {
1.418 raeburn 6529: my ($num,$currdom,$currinsttypes,$readonly) = @_;
1.241 raeburn 6530: my $output;
6531: my $numinrow = 4;
6532: my $count = 0;
6533: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($currdom);
1.247 raeburn 6534: my $othervalue = 'any';
1.418 raeburn 6535: my $disabled;
6536: if ($readonly) {
6537: $disabled = ' disabled="disabled"';
6538: }
1.241 raeburn 6539: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
1.251 raeburn 6540: if (keys(%{$usertypes}) > 0) {
1.247 raeburn 6541: $othervalue = 'other';
6542: }
1.241 raeburn 6543: $output .= '<table><tr>';
6544: foreach my $type (@{$types}) {
6545: if (($count > 0) && ($count%$numinrow == 0)) {
6546: $output .= '</tr><tr>';
6547: }
6548: if (defined($usertypes->{$type})) {
1.257 raeburn 6549: my $esc_type = &escape($type);
1.241 raeburn 6550: $output .= '<td><span class="LC_nobreak"><label><input type = "checkbox" value="'.
1.257 raeburn 6551: $esc_type.'" ';
1.241 raeburn 6552: if (ref($currinsttypes) eq 'ARRAY') {
6553: if (@{$currinsttypes} > 0) {
1.249 raeburn 6554: if (grep(/^any$/,@{$currinsttypes})) {
6555: $output .= 'checked="checked"';
1.257 raeburn 6556: } elsif (grep(/^\Q$esc_type\E$/,@{$currinsttypes})) {
1.241 raeburn 6557: $output .= 'checked="checked"';
6558: }
1.249 raeburn 6559: } else {
6560: $output .= 'checked="checked"';
1.241 raeburn 6561: }
6562: }
1.418 raeburn 6563: $output .= ' name="selfenroll_types_'.$num.'"'.$disabled.' />'.$usertypes->{$type}.'</label></span></td>';
1.241 raeburn 6564: }
6565: $count ++;
6566: }
6567: if (($count > 0) && ($count%$numinrow == 0)) {
6568: $output .= '</tr><tr>';
6569: }
1.249 raeburn 6570: $output .= '<td><span class="LC_nobreak"><label><input type = "checkbox" value="'.$othervalue.'"';
1.241 raeburn 6571: if (ref($currinsttypes) eq 'ARRAY') {
6572: if (@{$currinsttypes} > 0) {
1.249 raeburn 6573: if (grep(/^any$/,@{$currinsttypes})) {
6574: $output .= ' checked="checked"';
6575: } elsif ($othervalue eq 'other') {
6576: if (grep(/^\Q$othervalue\E$/,@{$currinsttypes})) {
6577: $output .= ' checked="checked"';
6578: }
1.241 raeburn 6579: }
1.249 raeburn 6580: } else {
6581: $output .= ' checked="checked"';
1.241 raeburn 6582: }
1.249 raeburn 6583: } else {
6584: $output .= ' checked="checked"';
1.241 raeburn 6585: }
1.418 raeburn 6586: $output .= ' name="selfenroll_types_'.$num.'"'.$disabled.' />'.$othertitle.'</label></span></td></tr></table>';
1.241 raeburn 6587: }
6588: return $output;
6589: }
6590:
1.237 raeburn 6591: sub selfenroll_date_forms {
6592: my ($startform,$endform) = @_;
6593: my $output .= &Apache::lonhtmlcommon::start_pick_box()."\n".
1.244 bisitz 6594: &Apache::lonhtmlcommon::row_title(&mt('Start date'),
1.237 raeburn 6595: 'LC_oddrow_value')."\n".
6596: $startform."\n".
6597: &Apache::lonhtmlcommon::row_closure(1).
1.244 bisitz 6598: &Apache::lonhtmlcommon::row_title(&mt('End date'),
1.237 raeburn 6599: 'LC_oddrow_value')."\n".
6600: $endform."\n".
6601: &Apache::lonhtmlcommon::row_closure(1).
6602: &Apache::lonhtmlcommon::end_pick_box();
6603: return $output;
6604: }
6605:
1.239 raeburn 6606: sub print_userchangelogs_display {
1.415 raeburn 6607: my ($r,$context,$permission,$brcrum) = @_;
1.363 raeburn 6608: my $formname = 'rolelog';
1.418 raeburn 6609: my ($username,$domain,$crstype,$viewablesec,%roleslog);
1.363 raeburn 6610: if ($context eq 'domain') {
6611: $domain = $env{'request.role.domain'};
6612: %roleslog=&Apache::lonnet::dump_dom('nohist_rolelog',$domain);
6613: } else {
6614: if ($context eq 'course') {
6615: $domain = $env{'course.'.$env{'request.course.id'}.'.domain'};
6616: $username = $env{'course.'.$env{'request.course.id'}.'.num'};
6617: $crstype = &Apache::loncommon::course_type();
1.418 raeburn 6618: $viewablesec = &Apache::lonuserutils::viewable_section($permission);
1.363 raeburn 6619: my %saveable_parameters = ('show' => 'scalar',);
6620: &Apache::loncommon::store_course_settings('roles_log',
6621: \%saveable_parameters);
6622: &Apache::loncommon::restore_course_settings('roles_log',
6623: \%saveable_parameters);
6624: } elsif ($context eq 'author') {
6625: $domain = $env{'user.domain'};
6626: if ($env{'request.role'} =~ m{^au\./\Q$domain\E/$}) {
6627: $username = $env{'user.name'};
6628: } else {
6629: undef($domain);
6630: }
6631: }
6632: if ($domain ne '' && $username ne '') {
6633: %roleslog=&Apache::lonnet::dump('nohist_rolelog',$domain,$username);
6634: }
6635: }
1.239 raeburn 6636: if ((keys(%roleslog))[0]=~/^error\:/) { undef(%roleslog); }
6637:
1.415 raeburn 6638: my $helpitem;
6639: if ($context eq 'course') {
6640: $helpitem = 'Course_User_Logs';
6641: }
6642: push (@{$brcrum},
6643: {href => '/adm/createuser?action=changelogs',
6644: text => 'User Management Logs',
6645: help => $helpitem});
6646: my $bread_crumbs_component = 'User Changes';
6647: my $args = { bread_crumbs => $brcrum,
6648: bread_crumbs_component => $bread_crumbs_component};
6649:
6650: # Create navigation javascript
6651: my $jsnav = &userlogdisplay_js($formname);
6652:
6653: my $jscript = (<<ENDSCRIPT);
6654: <script type="text/javascript">
6655: // <![CDATA[
6656: $jsnav
6657: // ]]>
6658: </script>
6659: ENDSCRIPT
6660:
6661: # print page header
6662: $r->print(&header($jscript,$args));
6663:
1.239 raeburn 6664: # set defaults
6665: my $now = time();
6666: my $defstart = $now - (7*24*3600); #7 days ago
6667: my %defaults = (
6668: page => '1',
6669: show => '10',
6670: role => 'any',
6671: chgcontext => 'any',
6672: rolelog_start_date => $defstart,
6673: rolelog_end_date => $now,
6674: );
6675: my $more_records = 0;
6676:
6677: # set current
6678: my %curr;
6679: foreach my $item ('show','page','role','chgcontext') {
6680: $curr{$item} = $env{'form.'.$item};
6681: }
6682: my ($startdate,$enddate) =
6683: &Apache::lonuserutils::get_dates_from_form('rolelog_start_date','rolelog_end_date');
6684: $curr{'rolelog_start_date'} = $startdate;
6685: $curr{'rolelog_end_date'} = $enddate;
6686: foreach my $key (keys(%defaults)) {
6687: if ($curr{$key} eq '') {
6688: $curr{$key} = $defaults{$key};
6689: }
6690: }
1.248 raeburn 6691: my (%whodunit,%changed,$version);
6692: ($version) = ($r->dir_config('lonVersion') =~ /^([\d\.]+)\-/);
1.239 raeburn 6693: my ($minshown,$maxshown);
1.255 raeburn 6694: $minshown = 1;
1.239 raeburn 6695: my $count = 0;
1.415 raeburn 6696: if ($curr{'show'} =~ /\D/) {
6697: $curr{'page'} = 1;
6698: } else {
1.239 raeburn 6699: $maxshown = $curr{'page'} * $curr{'show'};
6700: if ($curr{'page'} > 1) {
6701: $minshown = 1 + ($curr{'page'} - 1) * $curr{'show'};
6702: }
6703: }
1.301 bisitz 6704:
1.327 raeburn 6705: # Form Header
6706: $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">'.
1.363 raeburn 6707: &role_display_filter($context,$formname,$domain,$username,\%curr,
6708: $version,$crstype));
1.327 raeburn 6709:
6710: my $showntableheader = 0;
6711:
6712: # Table Header
6713: my $tableheader =
6714: &Apache::loncommon::start_data_table_header_row()
6715: .'<th> </th>'
6716: .'<th>'.&mt('When').'</th>'
6717: .'<th>'.&mt('Who made the change').'</th>'
6718: .'<th>'.&mt('Changed User').'</th>'
1.363 raeburn 6719: .'<th>'.&mt('Role').'</th>';
6720:
6721: if ($context eq 'course') {
6722: $tableheader .= '<th>'.&mt('Section').'</th>';
6723: }
6724: $tableheader .=
6725: '<th>'.&mt('Context').'</th>'
1.327 raeburn 6726: .'<th>'.&mt('Start').'</th>'
6727: .'<th>'.&mt('End').'</th>'
6728: .&Apache::loncommon::end_data_table_header_row();
6729:
6730: # Display user change log data
1.239 raeburn 6731: foreach my $id (sort { $roleslog{$b}{'exe_time'}<=>$roleslog{$a}{'exe_time'} } (keys(%roleslog))) {
6732: next if (($roleslog{$id}{'exe_time'} < $curr{'rolelog_start_date'}) ||
6733: ($roleslog{$id}{'exe_time'} > $curr{'rolelog_end_date'}));
1.415 raeburn 6734: if ($curr{'show'} !~ /\D/) {
1.239 raeburn 6735: if ($count >= $curr{'page'} * $curr{'show'}) {
6736: $more_records = 1;
6737: last;
6738: }
6739: }
6740: if ($curr{'role'} ne 'any') {
6741: next if ($roleslog{$id}{'logentry'}{'role'} ne $curr{'role'});
6742: }
6743: if ($curr{'chgcontext'} ne 'any') {
6744: if ($curr{'chgcontext'} eq 'selfenroll') {
6745: next if (!$roleslog{$id}{'logentry'}{'selfenroll'});
6746: } else {
6747: next if ($roleslog{$id}{'logentry'}{'context'} ne $curr{'chgcontext'});
6748: }
6749: }
1.418 raeburn 6750: if (($context eq 'course') && ($viewablesec ne '')) {
6751: next if ($roleslog{$id}{'logentry'}{'section'} ne $viewablesec);
6752: }
1.239 raeburn 6753: $count ++;
6754: next if ($count < $minshown);
1.327 raeburn 6755: unless ($showntableheader) {
1.415 raeburn 6756: $r->print(&Apache::loncommon::start_data_table()
1.327 raeburn 6757: .$tableheader);
6758: $r->rflush();
6759: $showntableheader = 1;
6760: }
1.239 raeburn 6761: if ($whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}} eq '') {
6762: $whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}} =
6763: &Apache::loncommon::plainname($roleslog{$id}{'exe_uname'},$roleslog{$id}{'exe_udom'});
6764: }
6765: if ($changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}} eq '') {
6766: $changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}} =
6767: &Apache::loncommon::plainname($roleslog{$id}{'uname'},$roleslog{$id}{'udom'});
6768: }
6769: my $sec = $roleslog{$id}{'logentry'}{'section'};
6770: if ($sec eq '') {
6771: $sec = &mt('None');
6772: }
6773: my ($rolestart,$roleend);
6774: if ($roleslog{$id}{'delflag'}) {
6775: $rolestart = &mt('deleted');
6776: $roleend = &mt('deleted');
6777: } else {
6778: $rolestart = $roleslog{$id}{'logentry'}{'start'};
6779: $roleend = $roleslog{$id}{'logentry'}{'end'};
6780: if ($rolestart eq '' || $rolestart == 0) {
6781: $rolestart = &mt('No start date');
6782: } else {
6783: $rolestart = &Apache::lonlocal::locallocaltime($rolestart);
6784: }
6785: if ($roleend eq '' || $roleend == 0) {
6786: $roleend = &mt('No end date');
6787: } else {
6788: $roleend = &Apache::lonlocal::locallocaltime($roleend);
6789: }
6790: }
6791: my $chgcontext = $roleslog{$id}{'logentry'}{'context'};
6792: if ($roleslog{$id}{'logentry'}{'selfenroll'}) {
6793: $chgcontext = 'selfenroll';
6794: }
1.363 raeburn 6795: my %lt = &rolechg_contexts($context,$crstype);
1.239 raeburn 6796: if ($chgcontext ne '' && $lt{$chgcontext} ne '') {
6797: $chgcontext = $lt{$chgcontext};
6798: }
1.327 raeburn 6799: $r->print(
1.301 bisitz 6800: &Apache::loncommon::start_data_table_row()
6801: .'<td>'.$count.'</td>'
6802: .'<td>'.&Apache::lonlocal::locallocaltime($roleslog{$id}{'exe_time'}).'</td>'
6803: .'<td>'.$whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}}.'</td>'
6804: .'<td>'.$changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}}.'</td>'
1.363 raeburn 6805: .'<td>'.&Apache::lonnet::plaintext($roleslog{$id}{'logentry'}{'role'},$crstype).'</td>');
6806: if ($context eq 'course') {
6807: $r->print('<td>'.$sec.'</td>');
6808: }
6809: $r->print(
6810: '<td>'.$chgcontext.'</td>'
1.301 bisitz 6811: .'<td>'.$rolestart.'</td>'
6812: .'<td>'.$roleend.'</td>'
1.327 raeburn 6813: .&Apache::loncommon::end_data_table_row()."\n");
1.301 bisitz 6814: }
6815:
1.327 raeburn 6816: if ($showntableheader) { # Table footer, if content displayed above
1.415 raeburn 6817: $r->print(&Apache::loncommon::end_data_table().
6818: &userlogdisplay_navlinks(\%curr,$more_records));
1.327 raeburn 6819: } else { # No content displayed above
1.301 bisitz 6820: $r->print('<p class="LC_info">'
6821: .&mt('There are no records to display.')
6822: .'</p>'
6823: );
1.239 raeburn 6824: }
1.301 bisitz 6825:
1.327 raeburn 6826: # Form Footer
6827: $r->print(
6828: '<input type="hidden" name="page" value="'.$curr{'page'}.'" />'
6829: .'<input type="hidden" name="action" value="changelogs" />'
6830: .'</form>');
6831: return;
6832: }
1.301 bisitz 6833:
1.416 raeburn 6834: sub print_useraccesslogs_display {
6835: my ($r,$uname,$udom,$permission,$brcrum) = @_;
6836: my $formname = 'accesslog';
6837: my $form = 'document.accesslog';
6838:
6839: # set breadcrumbs
1.422 raeburn 6840: my %breadcrumb_text = &singleuser_breadcrumb('','domain',$udom);
1.416 raeburn 6841: push (@{$brcrum},
6842: {href => "javascript:backPage($form)",
6843: text => $breadcrumb_text{'search'}});
6844: my (@prevphases,$prevphasestr);
6845: if ($env{'form.prevphases'}) {
6846: @prevphases = split(/,/,$env{'form.prevphases'});
6847: $prevphasestr = $env{'form.prevphases'};
6848: }
6849: if (($env{'form.phase'} eq 'userpicked') || (grep(/^userpicked$/,@prevphases))) {
6850: push(@{$brcrum},
6851: {href => "javascript:backPage($form,'get_user_info','select')",
6852: text => $breadcrumb_text{'userpicked'}});
6853: if ($env{'form.phase'} eq 'userpicked') {
6854: $prevphasestr = 'userpicked';
6855: }
6856: }
6857: push(@{$brcrum},
6858: {href => '/adm/createuser?action=accesslogs',
6859: text => 'User access logs',
1.424 ! raeburn 6860: help => 'Domain_User_Access_Logs'});
1.416 raeburn 6861: my $bread_crumbs_component = 'User Access Logs';
6862: my $args = { bread_crumbs => $brcrum,
6863: bread_crumbs_component => 'User Management'};
1.423 raeburn 6864: if ($env{'form.popup'}) {
6865: $args->{'no_nav_bar'} = 1;
6866: }
1.416 raeburn 6867:
1.417 raeburn 6868: # set javascript
1.416 raeburn 6869: my ($jsback,$elements) = &crumb_utilities();
6870: my $jsnav = &userlogdisplay_js($formname);
6871:
6872: my $jscript = (<<ENDSCRIPT);
6873: <script type="text/javascript">
6874: // <![CDATA[
6875:
6876: $jsback
6877: $jsnav
6878:
6879: // ]]>
6880: </script>
6881:
6882: ENDSCRIPT
6883:
1.417 raeburn 6884: # print page header
1.416 raeburn 6885: $r->print(&header($jscript,$args));
6886:
6887: # early out unless log data can be displayed.
6888: unless ($permission->{'activity'}) {
6889: $r->print('<p class="LC_warning">'
6890: .&mt('You do not have rights to display user access logs.')
6891: .'</p>'
6892: .&earlyout_accesslog_form($formname,$prevphasestr,$udom));
6893: return;
6894: }
6895:
6896: unless ($udom eq $env{'request.role.domain'}) {
6897: $r->print('<p class="LC_warning">'
6898: .&mt("User's domain must match role's domain")
6899: .'</p>'
6900: .&earlyout_accesslog_form($formname,$prevphasestr,$udom));
1.417 raeburn 6901: return;
1.416 raeburn 6902: }
6903:
6904: if (($uname eq '') || ($udom eq '')) {
6905: $r->print('<p class="LC_warning">'
6906: .&mt('Invalid username or domain')
6907: .'</p>'
6908: .&earlyout_accesslog_form($formname,$prevphasestr,$udom));
6909: return;
6910: }
6911:
6912: # set defaults
6913: my $now = time();
6914: my $defstart = $now - (7*24*3600);
6915: my %defaults = (
6916: page => '1',
6917: show => '10',
6918: activity => 'any',
6919: accesslog_start_date => $defstart,
6920: accesslog_end_date => $now,
6921: );
6922: my $more_records = 0;
6923:
6924: # set current
6925: my %curr;
6926: foreach my $item ('show','page','activity') {
6927: $curr{$item} = $env{'form.'.$item};
6928: }
6929: my ($startdate,$enddate) =
6930: &Apache::lonuserutils::get_dates_from_form('accesslog_start_date','accesslog_end_date');
6931: $curr{'accesslog_start_date'} = $startdate;
6932: $curr{'accesslog_end_date'} = $enddate;
6933: foreach my $key (keys(%defaults)) {
6934: if ($curr{$key} eq '') {
6935: $curr{$key} = $defaults{$key};
6936: }
6937: }
6938: my ($minshown,$maxshown);
6939: $minshown = 1;
6940: my $count = 0;
6941: if ($curr{'show'} =~ /\D/) {
6942: $curr{'page'} = 1;
6943: } else {
6944: $maxshown = $curr{'page'} * $curr{'show'};
6945: if ($curr{'page'} > 1) {
6946: $minshown = 1 + ($curr{'page'} - 1) * $curr{'show'};
6947: }
6948: }
6949:
6950: # form header
6951: $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">'.
6952: &activity_display_filter($formname,\%curr));
6953:
6954: my $showntableheader = 0;
6955: my ($nav_script,$nav_links);
6956:
6957: # table header
6958: my $tableheader =
6959: &Apache::loncommon::start_data_table_header_row()
6960: .'<th> </th>'
6961: .'<th>'.&mt('When').'</th>'
6962: .'<th>'.&mt('HostID').'</th>'
6963: .'<th>'.&mt('Event').'</th>'
6964: .'<th>'.&mt('Other data').'</th>'
6965: .&Apache::loncommon::end_data_table_header_row();
6966:
6967: my %filters=(
6968: start => $curr{'accesslog_start_date'},
6969: end => $curr{'accesslog_end_date'},
6970: action => $curr{'activity'},
6971: );
6972:
6973: my $reply = &Apache::lonnet::userlog_query($uname,$udom,%filters);
6974: unless ( ($reply =~/^timeout/) || ($reply =~/^error/) ) {
6975: my (%courses,%missing);
6976: my @results = split(/\&/,$reply);
6977: foreach my $item (reverse(@results)) {
6978: my ($timestamp,$host,$event) = split(/:/,$item);
6979: next unless ($event =~ /^(Log|Role)/);
6980: if ($curr{'show'} !~ /\D/) {
6981: if ($count >= $curr{'page'} * $curr{'show'}) {
6982: $more_records = 1;
6983: last;
6984: }
6985: }
6986: $count ++;
6987: next if ($count < $minshown);
6988: unless ($showntableheader) {
6989: $r->print($nav_script
6990: .&Apache::loncommon::start_data_table()
6991: .$tableheader);
6992: $r->rflush();
6993: $showntableheader = 1;
6994: }
1.418 raeburn 6995: my ($shown,$extra);
1.416 raeburn 6996: my ($event,$data) = split(/\s+/,&unescape($event));
6997: if ($event eq 'Role') {
6998: my ($rolecode,$extent) = split(/\./,$data,2);
6999: next if ($extent eq '');
7000: my ($crstype,$desc,$info);
1.418 raeburn 7001: if ($extent =~ m{^/($match_domain)/($match_courseid)(?:/(\w+)|)$}) {
7002: my ($cdom,$cnum,$sec) = ($1,$2,$3);
1.416 raeburn 7003: my $cid = $cdom.'_'.$cnum;
7004: if (exists($courses{$cid})) {
7005: $crstype = $courses{$cid}{'type'};
7006: $desc = $courses{$cid}{'description'};
7007: } elsif ($missing{$cid}) {
7008: $crstype = 'Course';
7009: $desc = 'Course/Community';
7010: } else {
7011: my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',$cnum,undef,undef,'.');
7012: if (ref($crsinfo{$cdom.'_'.$cnum}) eq 'HASH') {
7013: $courses{$cid} = $crsinfo{$cid};
7014: $crstype = $crsinfo{$cid}{'type'};
7015: $desc = $crsinfo{$cid}{'description'};
7016: } else {
7017: $missing{$cid} = 1;
7018: }
7019: }
7020: $extra = &mt($crstype).': <a href="/public/'.$cdom.'/'.$cnum.'/syllabus">'.$desc.'</a>';
1.418 raeburn 7021: if ($sec ne '') {
7022: $extra .= ' ('.&mt('Section: [_1]',$sec).')';
7023: }
1.416 raeburn 7024: } elsif ($extent =~ m{^/($match_domain)/($match_username|$)}) {
7025: my ($dom,$name) = ($1,$2);
7026: if ($rolecode eq 'au') {
7027: $extra = '';
7028: } elsif ($rolecode =~ /^(ca|aa)$/) {
1.417 raeburn 7029: $extra = &mt('Authoring Space: [_1]',$name.':'.$dom);
1.416 raeburn 7030: } elsif ($rolecode =~ /^(li|dg|dh|dc|sc)$/) {
7031: $extra = &mt('Domain: [_1]',$dom);
7032: }
7033: }
7034: my $rolename;
7035: if ($rolecode =~ m{^cr/($match_domain)/($match_username)/(\w+)}) {
7036: my $role = $3;
1.417 raeburn 7037: my $owner = "($2:$1)";
1.416 raeburn 7038: if ($2 eq $1.'-domainconfig') {
7039: $owner = '(ad hoc)';
1.417 raeburn 7040: }
1.416 raeburn 7041: $rolename = &mt('Custom role: [_1]',$role.' '.$owner);
7042: } else {
7043: $rolename = &Apache::lonnet::plaintext($rolecode,$crstype);
7044: }
7045: $shown = &mt('Role selection: [_1]',$rolename);
7046: } else {
7047: $shown = &mt($event);
7048: if ($data ne '') {
7049: $extra = &mt('Client IP address: [_1]',$data);
7050: }
7051: }
7052: $r->print(
7053: &Apache::loncommon::start_data_table_row()
7054: .'<td>'.$count.'</td>'
7055: .'<td>'.&Apache::lonlocal::locallocaltime($timestamp).'</td>'
7056: .'<td>'.$host.'</td>'
7057: .'<td>'.$shown.'</td>'
7058: .'<td>'.$extra.'</td>'
7059: .&Apache::loncommon::end_data_table_row()."\n");
7060: }
7061: }
7062:
7063: if ($showntableheader) { # Table footer, if content displayed above
7064: $r->print(&Apache::loncommon::end_data_table().
7065: &userlogdisplay_navlinks(\%curr,$more_records));
7066: } else { # No content displayed above
7067: $r->print('<p class="LC_info">'
7068: .&mt('There are no records to display.')
7069: .'</p>');
7070: }
7071:
1.423 raeburn 7072: if ($env{'form.popup'} == 1) {
7073: $r->print('<input type="hidden" name="popup" value="1" />'."\n");
7074: }
7075:
1.416 raeburn 7076: # Form Footer
7077: $r->print(
7078: '<input type="hidden" name="currstate" value="" />'
7079: .'<input type="hidden" name="accessuname" value="'.$uname.'" />'
7080: .'<input type="hidden" name="accessudom" value="'.$udom.'" />'
7081: .'<input type="hidden" name="page" value="'.$curr{'page'}.'" />'
7082: .'<input type="hidden" name="prevphases" value="'.$prevphasestr.'" />'
7083: .'<input type="hidden" name="phase" value="activity" />'
7084: .'<input type="hidden" name="action" value="accesslogs" />'
7085: .'<input type="hidden" name="srchdomain" value="'.$udom.'" />'
7086: .'<input type="hidden" name="srchby" value="'.$env{'form.srchby'}.'" />'
7087: .'<input type="hidden" name="srchtype" value="'.$env{'form.srchtype'}.'" />'
7088: .'<input type="hidden" name="srchterm" value="'.&HTML::Entities::encode($env{'form.srchterm'},'<>"&').'" />'
7089: .'<input type="hidden" name="srchin" value="'.$env{'form.srchin'}.'" />'
7090: .'</form>');
7091: return;
7092: }
7093:
7094: sub earlyout_accesslog_form {
7095: my ($formname,$prevphasestr,$udom) = @_;
7096: my $srchterm = &HTML::Entities::encode($env{'form.srchterm'},'<>"&');
7097: return <<"END";
7098: <form action="/adm/createuser" method="post" name="$formname">
7099: <input type="hidden" name="currstate" value="" />
7100: <input type="hidden" name="prevphases" value="$prevphasestr" />
7101: <input type="hidden" name="phase" value="activity" />
7102: <input type="hidden" name="action" value="accesslogs" />
7103: <input type="hidden" name="srchdomain" value="$udom" />
7104: <input type="hidden" name="srchby" value="$env{'form.srchby'}" />
7105: <input type="hidden" name="srchtype" value="$env{'form.srchtype'}" />
7106: <input type="hidden" name="srchterm" value="$srchterm" />
7107: <input type="hidden" name="srchin" value="$env{'form.srchin'}" />
7108: </form>
7109: END
7110: }
7111:
7112: sub activity_display_filter {
7113: my ($formname,$curr) = @_;
7114: my $nolink = 1;
7115: my $output = '<table><tr><td valign="top">'.
7116: '<span class="LC_nobreak"><b>'.&mt('Actions/page:').'</b></span><br />'.
7117: &Apache::lonmeta::selectbox('show',$curr->{'show'},undef,
7118: (&mt('all'),5,10,20,50,100,1000,10000)).
7119: '</td><td> </td>';
7120: my $startform =
7121: &Apache::lonhtmlcommon::date_setter($formname,'accesslog_start_date',
7122: $curr->{'accesslog_start_date'},undef,
7123: undef,undef,undef,undef,undef,undef,$nolink);
7124: my $endform =
7125: &Apache::lonhtmlcommon::date_setter($formname,'accesslog_end_date',
7126: $curr->{'accesslog_end_date'},undef,
7127: undef,undef,undef,undef,undef,undef,$nolink);
7128: my %lt = &Apache::lonlocal::texthash (
7129: activity => 'Activity',
7130: Role => 'Role selection',
7131: log => 'Log-in or Logout',
7132: );
7133: $output .= '<td valign="top"><b>'.&mt('Window during which actions occurred:').'</b><br />'.
7134: '<table><tr><td>'.&mt('After:').
7135: '</td><td>'.$startform.'</td></tr>'.
7136: '<tr><td>'.&mt('Before:').'</td>'.
7137: '<td>'.$endform.'</td></tr></table>'.
7138: '</td>'.
7139: '<td> </td>'.
7140: '<td valign="top"><b>'.&mt('Activities').'</b><br />'.
7141: '<select name="activity"><option value="any"';
7142: if ($curr->{'activity'} eq 'any') {
7143: $output .= ' selected="selected"';
7144: }
7145: $output .= '>'.&mt('Any').'</option>'."\n";
7146: foreach my $activity ('Role','log') {
7147: my $selstr = '';
7148: if ($activity eq $curr->{'activity'}) {
7149: $selstr = ' selected="selected"';
7150: }
7151: $output .= '<option value="'.$activity.'"'.$selstr.'>'.$lt{$activity}.'</option>';
7152: }
7153: $output .= '</select></td>'.
7154: '</tr></table>';
7155: # Update Display button
7156: $output .= '<p>'
7157: .'<input type="submit" value="'.&mt('Update Display').'" />'
7158: .'</p>';
7159: return $output;
7160: }
7161:
1.415 raeburn 7162: sub userlogdisplay_js {
7163: my ($formname) = @_;
7164: return <<"ENDSCRIPT";
7165:
1.239 raeburn 7166: function chgPage(caller) {
7167: if (caller == 'previous') {
7168: document.$formname.page.value --;
7169: }
7170: if (caller == 'next') {
7171: document.$formname.page.value ++;
7172: }
1.327 raeburn 7173: document.$formname.submit();
1.239 raeburn 7174: return;
7175: }
7176: ENDSCRIPT
1.415 raeburn 7177: }
7178:
7179: sub userlogdisplay_navlinks {
7180: my ($curr,$more_records) = @_;
7181: return unless(ref($curr) eq 'HASH');
7182: # Navigation Buttons
7183: my $nav_links = '<p>';
7184: if (($curr->{'page'} > 1) || ($more_records)) {
7185: if (($curr->{'page'} > 1) && ($curr->{'show'} !~ /\D/)) {
7186: $nav_links .= '<input type="button"'
7187: .' onclick="javascript:chgPage('."'previous'".');"'
7188: .' value="'.&mt('Previous [_1] changes',$curr->{'show'})
7189: .'" /> ';
7190: }
7191: if ($more_records) {
7192: $nav_links .= '<input type="button"'
7193: .' onclick="javascript:chgPage('."'next'".');"'
7194: .' value="'.&mt('Next [_1] changes',$curr->{'show'})
7195: .'" />';
1.301 bisitz 7196: }
7197: }
1.415 raeburn 7198: $nav_links .= '</p>';
7199: return $nav_links;
1.239 raeburn 7200: }
7201:
7202: sub role_display_filter {
1.363 raeburn 7203: my ($context,$formname,$cdom,$cnum,$curr,$version,$crstype) = @_;
7204: my $lctype;
7205: if ($context eq 'course') {
7206: $lctype = lc($crstype);
7207: }
1.239 raeburn 7208: my $nolink = 1;
7209: my $output = '<table><tr><td valign="top">'.
1.301 bisitz 7210: '<span class="LC_nobreak"><b>'.&mt('Changes/page:').'</b></span><br />'.
1.239 raeburn 7211: &Apache::lonmeta::selectbox('show',$curr->{'show'},undef,
7212: (&mt('all'),5,10,20,50,100,1000,10000)).
7213: '</td><td> </td>';
7214: my $startform =
7215: &Apache::lonhtmlcommon::date_setter($formname,'rolelog_start_date',
7216: $curr->{'rolelog_start_date'},undef,
7217: undef,undef,undef,undef,undef,undef,$nolink);
7218: my $endform =
7219: &Apache::lonhtmlcommon::date_setter($formname,'rolelog_end_date',
7220: $curr->{'rolelog_end_date'},undef,
7221: undef,undef,undef,undef,undef,undef,$nolink);
1.363 raeburn 7222: my %lt = &rolechg_contexts($context,$crstype);
1.301 bisitz 7223: $output .= '<td valign="top"><b>'.&mt('Window during which changes occurred:').'</b><br />'.
7224: '<table><tr><td>'.&mt('After:').
7225: '</td><td>'.$startform.'</td></tr>'.
7226: '<tr><td>'.&mt('Before:').'</td>'.
7227: '<td>'.$endform.'</td></tr></table>'.
7228: '</td>'.
7229: '<td> </td>'.
1.239 raeburn 7230: '<td valign="top"><b>'.&mt('Role:').'</b><br />'.
7231: '<select name="role"><option value="any"';
7232: if ($curr->{'role'} eq 'any') {
7233: $output .= ' selected="selected"';
7234: }
7235: $output .= '>'.&mt('Any').'</option>'."\n";
1.363 raeburn 7236: my @roles = &Apache::lonuserutils::roles_by_context($context,1,$crstype);
1.239 raeburn 7237: foreach my $role (@roles) {
7238: my $plrole;
7239: if ($role eq 'cr') {
7240: $plrole = &mt('Custom Role');
7241: } else {
1.318 raeburn 7242: $plrole=&Apache::lonnet::plaintext($role,$crstype);
1.239 raeburn 7243: }
7244: my $selstr = '';
7245: if ($role eq $curr->{'role'}) {
7246: $selstr = ' selected="selected"';
7247: }
7248: $output .= ' <option value="'.$role.'"'.$selstr.'>'.$plrole.'</option>';
7249: }
1.301 bisitz 7250: $output .= '</select></td>'.
7251: '<td> </td>'.
7252: '<td valign="top"><b>'.
1.239 raeburn 7253: &mt('Context:').'</b><br /><select name="chgcontext">';
1.363 raeburn 7254: my @posscontexts;
7255: if ($context eq 'course') {
1.376 raeburn 7256: @posscontexts = ('any','automated','updatenow','createcourse','course','domain','selfenroll','requestcourses');
1.363 raeburn 7257: } elsif ($context eq 'domain') {
7258: @posscontexts = ('any','domain','requestauthor','domconfig','server');
7259: } else {
7260: @posscontexts = ('any','author','domain');
7261: }
7262: foreach my $chgtype (@posscontexts) {
1.239 raeburn 7263: my $selstr = '';
7264: if ($curr->{'chgcontext'} eq $chgtype) {
1.301 bisitz 7265: $selstr = ' selected="selected"';
1.239 raeburn 7266: }
1.363 raeburn 7267: if ($context eq 'course') {
1.376 raeburn 7268: if (($chgtype eq 'automated') || ($chgtype eq 'updatenow')) {
1.363 raeburn 7269: next if (!&Apache::lonnet::auto_run($cnum,$cdom));
7270: }
1.239 raeburn 7271: }
7272: $output .= '<option value="'.$chgtype.'"'.$selstr.'>'.$lt{$chgtype}.'</option>'."\n";
1.248 raeburn 7273: }
1.303 bisitz 7274: $output .= '</select></td>'
7275: .'</tr></table>';
7276:
7277: # Update Display button
7278: $output .= '<p>'
7279: .'<input type="submit" value="'.&mt('Update Display').'" />'
7280: .'</p>';
7281:
7282: # Server version info
1.363 raeburn 7283: my $needsrev = '2.11.0';
7284: if ($context eq 'course') {
7285: $needsrev = '2.7.0';
7286: }
7287:
1.303 bisitz 7288: $output .= '<p class="LC_info">'
7289: .&mt('Only changes made from servers running LON-CAPA [_1] or later are displayed.'
1.363 raeburn 7290: ,$needsrev);
1.248 raeburn 7291: if ($version) {
1.303 bisitz 7292: $output .= ' '.&mt('This LON-CAPA server is version [_1]',$version);
7293: }
7294: $output .= '</p><hr />';
1.239 raeburn 7295: return $output;
7296: }
7297:
7298: sub rolechg_contexts {
1.363 raeburn 7299: my ($context,$crstype) = @_;
7300: my %lt;
7301: if ($context eq 'course') {
7302: %lt = &Apache::lonlocal::texthash (
1.239 raeburn 7303: any => 'Any',
1.376 raeburn 7304: automated => 'Automated Enrollment',
1.239 raeburn 7305: updatenow => 'Roster Update',
7306: createcourse => 'Course Creation',
7307: course => 'User Management in course',
7308: domain => 'User Management in domain',
1.313 raeburn 7309: selfenroll => 'Self-enrolled',
1.318 raeburn 7310: requestcourses => 'Course Request',
1.239 raeburn 7311: );
1.363 raeburn 7312: if ($crstype eq 'Community') {
7313: $lt{'createcourse'} = &mt('Community Creation');
7314: $lt{'course'} = &mt('User Management in community');
7315: $lt{'requestcourses'} = &mt('Community Request');
7316: }
7317: } elsif ($context eq 'domain') {
7318: %lt = &Apache::lonlocal::texthash (
7319: any => 'Any',
7320: domain => 'User Management in domain',
7321: requestauthor => 'Authoring Request',
7322: server => 'Command line script (DC role)',
7323: domconfig => 'Self-enrolled',
7324: );
7325: } else {
7326: %lt = &Apache::lonlocal::texthash (
7327: any => 'Any',
7328: domain => 'User Management in domain',
7329: author => 'User Management by author',
7330: );
7331: }
1.239 raeburn 7332: return %lt;
7333: }
7334:
1.27 matthew 7335: #-------------------------------------------------- functions for &phase_two
1.160 raeburn 7336: sub user_search_result {
1.221 raeburn 7337: my ($context,$srch) = @_;
1.160 raeburn 7338: my %allhomes;
7339: my %inst_matches;
7340: my %srch_results;
1.181 raeburn 7341: my ($response,$currstate,$forcenewuser,$dirsrchres);
1.183 raeburn 7342: $srch->{'srchterm'} =~ s/\s+/ /g;
1.176 raeburn 7343: if ($srch->{'srchby'} !~ /^(uname|lastname|lastfirst)$/) {
1.160 raeburn 7344: $response = &mt('Invalid search.');
7345: }
7346: if ($srch->{'srchin'} !~ /^(crs|dom|alc|instd)$/) {
7347: $response = &mt('Invalid search.');
7348: }
1.177 raeburn 7349: if ($srch->{'srchtype'} !~ /^(exact|contains|begins)$/) {
1.160 raeburn 7350: $response = &mt('Invalid search.');
7351: }
7352: if ($srch->{'srchterm'} eq '') {
7353: $response = &mt('You must enter a search term.');
7354: }
1.183 raeburn 7355: if ($srch->{'srchterm'} =~ /^\s+$/) {
7356: $response = &mt('Your search term must contain more than just spaces.');
7357: }
1.160 raeburn 7358: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'instd')) {
7359: if (($srch->{'srchdomain'} eq '') ||
1.163 albertel 7360: ! (&Apache::lonnet::domain($srch->{'srchdomain'}))) {
1.160 raeburn 7361: $response = &mt('You must specify a valid domain when searching in a domain or institutional directory.')
7362: }
7363: }
7364: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs') ||
7365: ($srch->{'srchin'} eq 'alc')) {
1.176 raeburn 7366: if ($srch->{'srchby'} eq 'uname') {
1.243 raeburn 7367: my $unamecheck = $srch->{'srchterm'};
7368: if ($srch->{'srchtype'} eq 'contains') {
7369: if ($unamecheck !~ /^\w/) {
7370: $unamecheck = 'a'.$unamecheck;
7371: }
7372: }
7373: if ($unamecheck !~ /^$match_username$/) {
1.176 raeburn 7374: $response = &mt('You must specify a valid username. Only the following are allowed: letters numbers - . @');
7375: }
1.160 raeburn 7376: }
7377: }
1.180 raeburn 7378: if ($response ne '') {
1.413 raeburn 7379: $response = '<span class="LC_warning">'.$response.'</span><br />';
1.180 raeburn 7380: }
1.160 raeburn 7381: if ($srch->{'srchin'} eq 'instd') {
1.412 raeburn 7382: my $instd_chk = &instdirectorysrch_check($srch);
1.160 raeburn 7383: if ($instd_chk ne 'ok') {
1.412 raeburn 7384: my $domd_chk = &domdirectorysrch_check($srch);
1.413 raeburn 7385: $response .= '<span class="LC_warning">'.$instd_chk.'</span><br />';
1.412 raeburn 7386: if ($domd_chk eq 'ok') {
1.413 raeburn 7387: $response .= &mt('You may want to search in the LON-CAPA domain instead of the institutional directory.');
1.412 raeburn 7388: }
1.415 raeburn 7389: $response .= '<br />';
1.412 raeburn 7390: }
7391: } else {
1.417 raeburn 7392: unless (($context eq 'requestcrs') && ($srch->{'srchtype'} eq 'exact')) {
1.412 raeburn 7393: my $domd_chk = &domdirectorysrch_check($srch);
7394: if ($domd_chk ne 'ok') {
7395: my $instd_chk = &instdirectorysrch_check($srch);
1.413 raeburn 7396: $response .= '<span class="LC_warning">'.$domd_chk.'</span><br />';
1.412 raeburn 7397: if ($instd_chk eq 'ok') {
1.413 raeburn 7398: $response .= &mt('You may want to search in the institutional directory instead of the LON-CAPA domain.');
1.412 raeburn 7399: }
1.415 raeburn 7400: $response .= '<br />';
1.412 raeburn 7401: }
1.160 raeburn 7402: }
7403: }
7404: if ($response ne '') {
1.180 raeburn 7405: return ($currstate,$response);
1.160 raeburn 7406: }
7407: if ($srch->{'srchby'} eq 'uname') {
7408: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs')) {
7409: if ($env{'form.forcenew'}) {
7410: if ($srch->{'srchdomain'} ne $env{'request.role.domain'}) {
7411: my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
7412: if ($uhome eq 'no_host') {
7413: my $domdesc = &Apache::lonnet::domain($env{'request.role.domain'},'description');
1.180 raeburn 7414: my $showdom = &display_domain_info($env{'request.role.domain'});
7415: $response = &mt('New users can only be created in the domain to which your current role belongs - [_1].',$showdom);
1.160 raeburn 7416: } else {
1.179 raeburn 7417: $currstate = 'modify';
1.160 raeburn 7418: }
7419: } else {
1.179 raeburn 7420: $currstate = 'modify';
1.160 raeburn 7421: }
7422: } else {
7423: if ($srch->{'srchin'} eq 'dom') {
1.162 raeburn 7424: if ($srch->{'srchtype'} eq 'exact') {
7425: my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
7426: if ($uhome eq 'no_host') {
1.179 raeburn 7427: ($currstate,$response,$forcenewuser) =
1.221 raeburn 7428: &build_search_response($context,$srch,%srch_results);
1.162 raeburn 7429: } else {
1.179 raeburn 7430: $currstate = 'modify';
1.416 raeburn 7431: if ($env{'form.action'} eq 'accesslogs') {
7432: $currstate = 'activity';
7433: }
1.310 raeburn 7434: my $uname = $srch->{'srchterm'};
7435: my $udom = $srch->{'srchdomain'};
7436: $srch_results{$uname.':'.$udom} =
7437: { &Apache::lonnet::get('environment',
7438: ['firstname',
7439: 'lastname',
7440: 'permanentemail'],
7441: $udom,$uname)
7442: };
1.162 raeburn 7443: }
7444: } else {
7445: %srch_results = &Apache::lonnet::usersearch($srch);
1.179 raeburn 7446: ($currstate,$response,$forcenewuser) =
1.221 raeburn 7447: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 7448: }
7449: } else {
1.167 albertel 7450: my $courseusers = &get_courseusers();
1.162 raeburn 7451: if ($srch->{'srchtype'} eq 'exact') {
1.167 albertel 7452: if (exists($courseusers->{$srch->{'srchterm'}.':'.$srch->{'srchdomain'}})) {
1.179 raeburn 7453: $currstate = 'modify';
1.162 raeburn 7454: } else {
1.179 raeburn 7455: ($currstate,$response,$forcenewuser) =
1.221 raeburn 7456: &build_search_response($context,$srch,%srch_results);
1.162 raeburn 7457: }
1.160 raeburn 7458: } else {
1.167 albertel 7459: foreach my $user (keys(%$courseusers)) {
1.162 raeburn 7460: my ($cuname,$cudomain) = split(/:/,$user);
7461: if ($cudomain eq $srch->{'srchdomain'}) {
1.177 raeburn 7462: my $matched = 0;
7463: if ($srch->{'srchtype'} eq 'begins') {
7464: if ($cuname =~ /^\Q$srch->{'srchterm'}\E/i) {
7465: $matched = 1;
7466: }
7467: } else {
7468: if ($cuname =~ /\Q$srch->{'srchterm'}\E/i) {
7469: $matched = 1;
7470: }
7471: }
7472: if ($matched) {
1.167 albertel 7473: $srch_results{$user} =
7474: {&Apache::lonnet::get('environment',
7475: ['firstname',
7476: 'lastname',
1.194 albertel 7477: 'permanentemail'],
7478: $cudomain,$cuname)};
1.162 raeburn 7479: }
7480: }
7481: }
1.179 raeburn 7482: ($currstate,$response,$forcenewuser) =
1.221 raeburn 7483: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 7484: }
7485: }
7486: }
7487: } elsif ($srch->{'srchin'} eq 'alc') {
1.179 raeburn 7488: $currstate = 'query';
1.160 raeburn 7489: } elsif ($srch->{'srchin'} eq 'instd') {
1.181 raeburn 7490: ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
7491: if ($dirsrchres eq 'ok') {
7492: ($currstate,$response,$forcenewuser) =
1.221 raeburn 7493: &build_search_response($context,$srch,%srch_results);
1.181 raeburn 7494: } else {
7495: my $showdom = &display_domain_info($srch->{'srchdomain'});
7496: $response = '<span class="LC_warning">'.
7497: &mt('Institutional directory search is not available in domain: [_1]',$showdom).
7498: '</span><br />'.
7499: &mt('You may want to search in the LON-CAPA domain instead of the institutional directory.').
1.415 raeburn 7500: '<br />';
1.181 raeburn 7501: }
1.160 raeburn 7502: }
7503: } else {
7504: if ($srch->{'srchin'} eq 'dom') {
7505: %srch_results = &Apache::lonnet::usersearch($srch);
1.179 raeburn 7506: ($currstate,$response,$forcenewuser) =
1.221 raeburn 7507: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 7508: } elsif ($srch->{'srchin'} eq 'crs') {
1.167 albertel 7509: my $courseusers = &get_courseusers();
7510: foreach my $user (keys(%$courseusers)) {
1.160 raeburn 7511: my ($uname,$udom) = split(/:/,$user);
7512: my %names = &Apache::loncommon::getnames($uname,$udom);
7513: my %emails = &Apache::loncommon::getemails($uname,$udom);
7514: if ($srch->{'srchby'} eq 'lastname') {
7515: if ((($srch->{'srchtype'} eq 'exact') &&
7516: ($names{'lastname'} eq $srch->{'srchterm'})) ||
1.177 raeburn 7517: (($srch->{'srchtype'} eq 'begins') &&
7518: ($names{'lastname'} =~ /^\Q$srch->{'srchterm'}\E/i)) ||
1.160 raeburn 7519: (($srch->{'srchtype'} eq 'contains') &&
7520: ($names{'lastname'} =~ /\Q$srch->{'srchterm'}\E/i))) {
7521: $srch_results{$user} = {firstname => $names{'firstname'},
7522: lastname => $names{'lastname'},
7523: permanentemail => $emails{'permanentemail'},
7524: };
7525: }
7526: } elsif ($srch->{'srchby'} eq 'lastfirst') {
7527: my ($srchlast,$srchfirst) = split(/,/,$srch->{'srchterm'});
1.177 raeburn 7528: $srchlast =~ s/\s+$//;
7529: $srchfirst =~ s/^\s+//;
1.160 raeburn 7530: if ($srch->{'srchtype'} eq 'exact') {
7531: if (($names{'lastname'} eq $srchlast) &&
7532: ($names{'firstname'} eq $srchfirst)) {
7533: $srch_results{$user} = {firstname => $names{'firstname'},
7534: lastname => $names{'lastname'},
7535: permanentemail => $emails{'permanentemail'},
7536:
7537: };
7538: }
1.177 raeburn 7539: } elsif ($srch->{'srchtype'} eq 'begins') {
7540: if (($names{'lastname'} =~ /^\Q$srchlast\E/i) &&
7541: ($names{'firstname'} =~ /^\Q$srchfirst\E/i)) {
7542: $srch_results{$user} = {firstname => $names{'firstname'},
7543: lastname => $names{'lastname'},
7544: permanentemail => $emails{'permanentemail'},
7545: };
7546: }
7547: } else {
1.160 raeburn 7548: if (($names{'lastname'} =~ /\Q$srchlast\E/i) &&
7549: ($names{'firstname'} =~ /\Q$srchfirst\E/i)) {
7550: $srch_results{$user} = {firstname => $names{'firstname'},
7551: lastname => $names{'lastname'},
7552: permanentemail => $emails{'permanentemail'},
7553: };
7554: }
7555: }
7556: }
7557: }
1.179 raeburn 7558: ($currstate,$response,$forcenewuser) =
1.221 raeburn 7559: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 7560: } elsif ($srch->{'srchin'} eq 'alc') {
1.179 raeburn 7561: $currstate = 'query';
1.160 raeburn 7562: } elsif ($srch->{'srchin'} eq 'instd') {
1.181 raeburn 7563: ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
7564: if ($dirsrchres eq 'ok') {
7565: ($currstate,$response,$forcenewuser) =
1.221 raeburn 7566: &build_search_response($context,$srch,%srch_results);
1.181 raeburn 7567: } else {
1.412 raeburn 7568: my $showdom = &display_domain_info($srch->{'srchdomain'});
7569: $response = '<span class="LC_warning">'.
1.181 raeburn 7570: &mt('Institutional directory search is not available in domain: [_1]',$showdom).
7571: '</span><br />'.
7572: &mt('You may want to search in the LON-CAPA domain instead of the institutional directory.').
1.415 raeburn 7573: '<br />';
1.181 raeburn 7574: }
1.160 raeburn 7575: }
7576: }
1.179 raeburn 7577: return ($currstate,$response,$forcenewuser,\%srch_results);
1.160 raeburn 7578: }
7579:
1.412 raeburn 7580: sub domdirectorysrch_check {
7581: my ($srch) = @_;
7582: my $response;
7583: my %dom_inst_srch = &Apache::lonnet::get_dom('configuration',
7584: ['directorysrch'],$srch->{'srchdomain'});
7585: my $showdom = &display_domain_info($srch->{'srchdomain'});
7586: if (ref($dom_inst_srch{'directorysrch'}) eq 'HASH') {
7587: if ($dom_inst_srch{'directorysrch'}{'lcavailable'} eq '0') {
7588: return &mt('LON-CAPA directory search is not available in domain: [_1]',$showdom);
7589: }
7590: if ($dom_inst_srch{'directorysrch'}{'lclocalonly'}) {
7591: if ($env{'request.role.domain'} ne $srch->{'srchdomain'}) {
7592: return &mt('LON-CAPA directory search in domain: [_1] is only allowed for users with a current role in the domain.',$showdom);
7593: }
7594: }
7595: }
7596: return 'ok';
7597: }
7598:
7599: sub instdirectorysrch_check {
1.160 raeburn 7600: my ($srch) = @_;
7601: my $can_search = 0;
7602: my $response;
7603: my %dom_inst_srch = &Apache::lonnet::get_dom('configuration',
7604: ['directorysrch'],$srch->{'srchdomain'});
1.180 raeburn 7605: my $showdom = &display_domain_info($srch->{'srchdomain'});
1.160 raeburn 7606: if (ref($dom_inst_srch{'directorysrch'}) eq 'HASH') {
7607: if (!$dom_inst_srch{'directorysrch'}{'available'}) {
1.180 raeburn 7608: return &mt('Institutional directory search is not available in domain: [_1]',$showdom);
1.160 raeburn 7609: }
7610: if ($dom_inst_srch{'directorysrch'}{'localonly'}) {
7611: if ($env{'request.role.domain'} ne $srch->{'srchdomain'}) {
1.180 raeburn 7612: return &mt('Institutional directory search in domain: [_1] is only allowed for users with a current role in the domain.',$showdom);
1.160 raeburn 7613: }
7614: my @usertypes = split(/:/,$env{'environment.inststatus'});
7615: if (!@usertypes) {
7616: push(@usertypes,'default');
7617: }
7618: if (ref($dom_inst_srch{'directorysrch'}{'cansearch'}) eq 'ARRAY') {
7619: foreach my $type (@usertypes) {
7620: if (grep(/^\Q$type\E$/,@{$dom_inst_srch{'directorysrch'}{'cansearch'}})) {
7621: $can_search = 1;
7622: last;
7623: }
7624: }
7625: }
7626: if (!$can_search) {
7627: my ($insttypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($srch->{'srchdomain'});
7628: my @longtypes;
7629: foreach my $item (@usertypes) {
1.229 raeburn 7630: if (defined($insttypes->{$item})) {
7631: push (@longtypes,$insttypes->{$item});
7632: } elsif ($item eq 'default') {
7633: push (@longtypes,&mt('other'));
7634: }
1.160 raeburn 7635: }
7636: my $insttype_str = join(', ',@longtypes);
1.180 raeburn 7637: return &mt('Institutional directory search in domain: [_1] is not available to your user type: ',$showdom).$insttype_str;
1.229 raeburn 7638: }
1.160 raeburn 7639: } else {
7640: $can_search = 1;
7641: }
7642: } else {
1.180 raeburn 7643: return &mt('Institutional directory search has not been configured for domain: [_1]',$showdom);
1.160 raeburn 7644: }
7645: my %longtext = &Apache::lonlocal::texthash (
1.167 albertel 7646: uname => 'username',
1.160 raeburn 7647: lastfirst => 'last name, first name',
1.167 albertel 7648: lastname => 'last name',
1.172 raeburn 7649: contains => 'contains',
1.178 raeburn 7650: exact => 'as exact match to',
7651: begins => 'begins with',
1.160 raeburn 7652: );
7653: if ($can_search) {
7654: if (ref($dom_inst_srch{'directorysrch'}{'searchby'}) eq 'ARRAY') {
7655: if (!grep(/^\Q$srch->{'srchby'}\E$/,@{$dom_inst_srch{'directorysrch'}{'searchby'}})) {
1.180 raeburn 7656: return &mt('Institutional directory search in domain: [_1] is not available for searching by "[_2]"',$showdom,$longtext{$srch->{'srchby'}});
1.160 raeburn 7657: }
7658: } else {
1.180 raeburn 7659: return &mt('Institutional directory search in domain: [_1] is not available.', $showdom);
1.160 raeburn 7660: }
7661: }
7662: if ($can_search) {
1.178 raeburn 7663: if (ref($dom_inst_srch{'directorysrch'}{'searchtypes'}) eq 'ARRAY') {
7664: if (grep(/^\Q$srch->{'srchtype'}\E/,@{$dom_inst_srch{'directorysrch'}{'searchtypes'}})) {
7665: return 'ok';
7666: } else {
1.180 raeburn 7667: return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
1.178 raeburn 7668: }
7669: } else {
7670: if ((($dom_inst_srch{'directorysrch'}{'searchtypes'} eq 'specify') &&
7671: ($srch->{'srchtype'} eq 'exact' || $srch->{'srchtype'} eq 'contains')) ||
7672: ($dom_inst_srch{'directorysrch'}{'searchtypes'} eq $srch->{'srchtype'})) {
7673: return 'ok';
7674: } else {
1.180 raeburn 7675: return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
1.178 raeburn 7676: }
1.160 raeburn 7677: }
7678: }
7679: }
7680:
7681: sub get_courseusers {
7682: my %advhash;
1.167 albertel 7683: my $classlist = &Apache::loncoursedata::get_classlist();
1.160 raeburn 7684: my %coursepersonnel=&Apache::lonnet::get_course_adv_roles();
7685: foreach my $role (sort(keys(%coursepersonnel))) {
7686: foreach my $user (split(/\,/,$coursepersonnel{$role})) {
1.167 albertel 7687: if (!exists($classlist->{$user})) {
7688: $classlist->{$user} = [];
7689: }
1.160 raeburn 7690: }
7691: }
1.167 albertel 7692: return $classlist;
1.160 raeburn 7693: }
7694:
7695: sub build_search_response {
1.221 raeburn 7696: my ($context,$srch,%srch_results) = @_;
1.179 raeburn 7697: my ($currstate,$response,$forcenewuser);
1.160 raeburn 7698: my %names = (
1.330 bisitz 7699: 'uname' => 'username',
7700: 'lastname' => 'last name',
1.160 raeburn 7701: 'lastfirst' => 'last name, first name',
1.330 bisitz 7702: 'crs' => 'this course',
7703: 'dom' => 'LON-CAPA domain',
7704: 'instd' => 'the institutional directory for domain',
1.160 raeburn 7705: );
7706:
7707: my %single = (
1.180 raeburn 7708: begins => 'A match',
1.160 raeburn 7709: contains => 'A match',
1.180 raeburn 7710: exact => 'An exact match',
1.160 raeburn 7711: );
7712: my %nomatch = (
1.180 raeburn 7713: begins => 'No match',
1.160 raeburn 7714: contains => 'No match',
1.180 raeburn 7715: exact => 'No exact match',
1.160 raeburn 7716: );
7717: if (keys(%srch_results) > 1) {
1.179 raeburn 7718: $currstate = 'select';
1.160 raeburn 7719: } else {
7720: if (keys(%srch_results) == 1) {
1.416 raeburn 7721: if ($env{'form.action'} eq 'accesslogs') {
7722: $currstate = 'activity';
7723: } else {
7724: $currstate = 'modify';
7725: }
1.180 raeburn 7726: $response = &mt("$single{$srch->{'srchtype'}} was found for the $names{$srch->{'srchby'}} ([_1]) in $names{$srch->{'srchin'}}.",$srch->{'srchterm'});
7727: if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
1.330 bisitz 7728: $response .= ': '.&display_domain_info($srch->{'srchdomain'});
1.180 raeburn 7729: }
1.330 bisitz 7730: } else { # Search has nothing found. Prepare message to user.
7731: $response = '<span class="LC_warning">';
1.180 raeburn 7732: if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
1.330 bisitz 7733: $response .= &mt("$nomatch{$srch->{'srchtype'}} found for the $names{$srch->{'srchby'}} [_1] in $names{$srch->{'srchin'}}: [_2]",
7734: '<b>'.$srch->{'srchterm'}.'</b>',
7735: &display_domain_info($srch->{'srchdomain'}));
7736: } else {
7737: $response .= &mt("$nomatch{$srch->{'srchtype'}} found for the $names{$srch->{'srchby'}} [_1] in $names{$srch->{'srchin'}}.",
7738: '<b>'.$srch->{'srchterm'}.'</b>');
1.180 raeburn 7739: }
7740: $response .= '</span>';
1.330 bisitz 7741:
1.160 raeburn 7742: if ($srch->{'srchin'} ne 'alc') {
7743: $forcenewuser = 1;
7744: my $cansrchinst = 0;
7745: if ($srch->{'srchdomain'}) {
7746: my %domconfig = &Apache::lonnet::get_dom('configuration',['directorysrch'],$srch->{'srchdomain'});
7747: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
7748: if ($domconfig{'directorysrch'}{'available'}) {
7749: $cansrchinst = 1;
7750: }
7751: }
7752: }
1.180 raeburn 7753: if ((($srch->{'srchby'} eq 'lastfirst') ||
7754: ($srch->{'srchby'} eq 'lastname')) &&
7755: ($srch->{'srchin'} eq 'dom')) {
7756: if ($cansrchinst) {
7757: $response .= '<br />'.&mt('You may want to broaden your search to a search of the institutional directory for the domain.');
1.160 raeburn 7758: }
7759: }
1.180 raeburn 7760: if ($srch->{'srchin'} eq 'crs') {
7761: $response .= '<br />'.&mt('You may want to broaden your search to the selected LON-CAPA domain.');
7762: }
7763: }
1.305 raeburn 7764: my $createdom = $env{'request.role.domain'};
7765: if ($context eq 'requestcrs') {
7766: if ($env{'form.coursedom'} ne '') {
7767: $createdom = $env{'form.coursedom'};
7768: }
7769: }
1.416 raeburn 7770: unless (($env{'form.action'} eq 'accesslogs') || (($srch->{'srchby'} eq 'uname') && ($srch->{'srchin'} eq 'dom') &&
7771: ($srch->{'srchtype'} eq 'exact') && ($srch->{'srchdomain'} eq $createdom))) {
1.221 raeburn 7772: my $cancreate =
1.305 raeburn 7773: &Apache::lonuserutils::can_create_user($createdom,$context);
7774: my $targetdom = '<span class="LC_cusr_emph">'.$createdom.'</span>';
1.221 raeburn 7775: if ($cancreate) {
1.305 raeburn 7776: my $showdom = &display_domain_info($createdom);
1.266 bisitz 7777: $response .= '<br /><br />'
7778: .'<b>'.&mt('To add a new user:').'</b>'
1.305 raeburn 7779: .'<br />';
7780: if ($context eq 'requestcrs') {
7781: $response .= &mt("(You can only define new users in the new course's domain - [_1])",$targetdom);
7782: } else {
7783: $response .= &mt("(You can only create new users in your current role's domain - [_1])",$targetdom);
7784: }
7785: $response .='<ul><li>'
1.266 bisitz 7786: .&mt("Set 'Domain/institution to search' to: [_1]",'<span class="LC_cusr_emph">'.$showdom.'</span>')
7787: .'</li><li>'
7788: .&mt("Set 'Search criteria' to: [_1]username is ..... in selected LON-CAPA domain[_2]",'<span class="LC_cusr_emph">','</span>')
7789: .'</li><li>'
7790: .&mt('Provide the proposed username')
7791: .'</li><li>'
7792: .&mt("Click 'Search'")
7793: .'</li></ul><br />';
1.221 raeburn 7794: } else {
1.422 raeburn 7795: unless (($context eq 'domain') && ($env{'form.action'} eq 'singleuser')) {
7796: my $helplink = ' href="javascript:helpMenu('."'display'".')"';
7797: $response .= '<br /><br />';
7798: if ($context eq 'requestcrs') {
7799: $response .= &mt("You are not authorized to define new users in the new course's domain - [_1].",$targetdom);
7800: } else {
7801: $response .= &mt("You are not authorized to create new users in your current role's domain - [_1].",$targetdom);
7802: }
7803: $response .= '<br />'
7804: .&mt('Please contact the [_1]helpdesk[_2] if you need to create a new user.'
7805: ,' <a'.$helplink.'>'
7806: ,'</a>')
7807: .'<br />';
7808:
1.305 raeburn 7809: }
1.221 raeburn 7810: }
1.160 raeburn 7811: }
7812: }
7813: }
1.179 raeburn 7814: return ($currstate,$response,$forcenewuser);
1.160 raeburn 7815: }
7816:
1.180 raeburn 7817: sub display_domain_info {
7818: my ($dom) = @_;
7819: my $output = $dom;
7820: if ($dom ne '') {
7821: my $domdesc = &Apache::lonnet::domain($dom,'description');
7822: if ($domdesc ne '') {
7823: $output .= ' <span class="LC_cusr_emph">('.$domdesc.')</span>';
7824: }
7825: }
7826: return $output;
7827: }
7828:
1.160 raeburn 7829: sub crumb_utilities {
7830: my %elements = (
7831: crtuser => {
7832: srchterm => 'text',
1.172 raeburn 7833: srchin => 'selectbox',
1.160 raeburn 7834: srchby => 'selectbox',
7835: srchtype => 'selectbox',
7836: srchdomain => 'selectbox',
7837: },
1.207 raeburn 7838: crtusername => {
7839: srchterm => 'text',
7840: srchdomain => 'selectbox',
7841: },
1.160 raeburn 7842: docustom => {
7843: rolename => 'selectbox',
7844: newrolename => 'textbox',
7845: },
1.179 raeburn 7846: studentform => {
7847: srchterm => 'text',
7848: srchin => 'selectbox',
7849: srchby => 'selectbox',
7850: srchtype => 'selectbox',
7851: srchdomain => 'selectbox',
7852: },
1.160 raeburn 7853: );
7854:
7855: my $jsback .= qq|
7856: function backPage(formname,prevphase,prevstate) {
1.211 raeburn 7857: if (typeof prevphase == 'undefined') {
7858: formname.phase.value = '';
7859: }
7860: else {
7861: formname.phase.value = prevphase;
7862: }
7863: if (typeof prevstate == 'undefined') {
7864: formname.currstate.value = '';
7865: }
7866: else {
7867: formname.currstate.value = prevstate;
7868: }
1.160 raeburn 7869: formname.submit();
7870: }
7871: |;
7872: return ($jsback,\%elements);
7873: }
7874:
1.26 matthew 7875: sub course_level_table {
1.375 raeburn 7876: my ($inccourses,$showcredits,$defaultcredits) = @_;
7877: return unless (ref($inccourses) eq 'HASH');
1.26 matthew 7878: my $table = '';
1.62 www 7879: # Custom Roles?
7880:
1.190 raeburn 7881: my %customroles=&Apache::lonuserutils::my_custom_roles();
1.89 raeburn 7882: my %lt=&Apache::lonlocal::texthash(
7883: 'exs' => "Existing sections",
7884: 'new' => "Define new section",
7885: 'ssd' => "Set Start Date",
7886: 'sed' => "Set End Date",
1.131 raeburn 7887: 'crl' => "Course Level",
1.89 raeburn 7888: 'act' => "Activate",
7889: 'rol' => "Role",
7890: 'ext' => "Extent",
1.113 raeburn 7891: 'grs' => "Section",
1.375 raeburn 7892: 'crd' => "Credits",
1.89 raeburn 7893: 'sta' => "Start",
7894: 'end' => "End"
7895: );
1.62 www 7896:
1.375 raeburn 7897: foreach my $protectedcourse (sort(keys(%{$inccourses}))) {
1.135 raeburn 7898: my $thiscourse=$protectedcourse;
1.26 matthew 7899: $thiscourse=~s:_:/:g;
7900: my %coursedata=&Apache::lonnet::coursedescription($thiscourse);
1.365 raeburn 7901: my $isowner = &Apache::lonuserutils::is_courseowner($protectedcourse,$coursedata{'internal.courseowner'});
1.26 matthew 7902: my $area=$coursedata{'description'};
1.321 raeburn 7903: my $crstype=$coursedata{'type'};
1.135 raeburn 7904: if (!defined($area)) { $area=&mt('Unavailable course').': '.$protectedcourse; }
1.89 raeburn 7905: my ($domain,$cnum)=split(/\//,$thiscourse);
1.115 albertel 7906: my %sections_count;
1.101 albertel 7907: if (defined($env{'request.course.id'})) {
7908: if ($env{'request.course.id'} eq $domain.'_'.$cnum) {
1.115 albertel 7909: %sections_count =
7910: &Apache::loncommon::get_sections($domain,$cnum);
1.92 raeburn 7911: }
7912: }
1.321 raeburn 7913: my @roles = &Apache::lonuserutils::roles_by_context('course','',$crstype);
1.213 raeburn 7914: foreach my $role (@roles) {
1.321 raeburn 7915: my $plrole=&Apache::lonnet::plaintext($role,$crstype);
1.329 raeburn 7916: if ((&Apache::lonnet::allowed('c'.$role,$thiscourse)) ||
7917: ((($role eq 'cc') || ($role eq 'co')) && ($isowner))) {
1.221 raeburn 7918: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
1.375 raeburn 7919: $plrole,\%sections_count,\%lt,
1.402 raeburn 7920: $showcredits,$defaultcredits,$crstype);
1.221 raeburn 7921: } elsif ($env{'request.course.sec'} ne '') {
7922: if (&Apache::lonnet::allowed('c'.$role,$thiscourse.'/'.
7923: $env{'request.course.sec'})) {
7924: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
1.375 raeburn 7925: $plrole,\%sections_count,\%lt,
1.402 raeburn 7926: $showcredits,$defaultcredits,$crstype);
1.26 matthew 7927: }
7928: }
7929: }
1.221 raeburn 7930: if (&Apache::lonnet::allowed('ccr',$thiscourse)) {
1.324 raeburn 7931: foreach my $cust (sort(keys(%customroles))) {
7932: next if ($crstype eq 'Community' && $customroles{$cust} =~ /bre\&S/);
1.221 raeburn 7933: my $role = 'cr_cr_'.$env{'user.domain'}.'_'.$env{'user.name'}.'_'.$cust;
7934: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
1.402 raeburn 7935: $cust,\%sections_count,\%lt,
7936: $showcredits,$defaultcredits,$crstype);
1.221 raeburn 7937: }
1.62 www 7938: }
1.26 matthew 7939: }
7940: return '' if ($table eq ''); # return nothing if there is nothing
7941: # in the table
1.188 raeburn 7942: my $result;
7943: if (!$env{'request.course.id'}) {
7944: $result = '<h4>'.$lt{'crl'}.'</h4>'."\n";
7945: }
7946: $result .=
1.136 raeburn 7947: &Apache::loncommon::start_data_table().
7948: &Apache::loncommon::start_data_table_header_row().
1.375 raeburn 7949: '<th>'.$lt{'act'}.'</th><th>'.$lt{'rol'}.'</th>'."\n".
1.402 raeburn 7950: '<th>'.$lt{'ext'}.'</th><th>'."\n";
7951: if ($showcredits) {
7952: $result .= $lt{'crd'}.'</th>';
7953: }
7954: $result .=
1.375 raeburn 7955: '<th>'.$lt{'grs'}.'</th><th>'.$lt{'sta'}.'</th>'."\n".
7956: '<th>'.$lt{'end'}.'</th>'.
1.136 raeburn 7957: &Apache::loncommon::end_data_table_header_row().
7958: $table.
7959: &Apache::loncommon::end_data_table();
1.26 matthew 7960: return $result;
7961: }
1.88 raeburn 7962:
1.221 raeburn 7963: sub course_level_row {
1.375 raeburn 7964: my ($protectedcourse,$role,$area,$domain,$plrole,$sections_count,
1.402 raeburn 7965: $lt,$showcredits,$defaultcredits,$crstype) = @_;
1.375 raeburn 7966: my $creditem;
1.222 raeburn 7967: my $row = &Apache::loncommon::start_data_table_row().
7968: ' <td><input type="checkbox" name="act_'.
7969: $protectedcourse.'_'.$role.'" /></td>'."\n".
7970: ' <td>'.$plrole.'</td>'."\n".
7971: ' <td>'.$area.'<br />Domain: '.$domain.'</td>'."\n";
1.402 raeburn 7972: if (($showcredits) && ($role eq 'st') && ($crstype eq 'Course')) {
1.375 raeburn 7973: $row .=
7974: '<td><input type="text" name="credits_'.$protectedcourse.'_'.
7975: $role.'" size="3" value="'.$defaultcredits.'" /></td>';
7976: } else {
7977: $row .= '<td> </td>';
7978: }
1.322 raeburn 7979: if (($role eq 'cc') || ($role eq 'co')) {
1.222 raeburn 7980: $row .= '<td> </td>';
1.221 raeburn 7981: } elsif ($env{'request.course.sec'} ne '') {
1.222 raeburn 7982: $row .= ' <td><input type="hidden" value="'.
7983: $env{'request.course.sec'}.'" '.
7984: 'name="sec_'.$protectedcourse.'_'.$role.'" />'.
7985: $env{'request.course.sec'}.'</td>';
1.221 raeburn 7986: } else {
7987: if (ref($sections_count) eq 'HASH') {
7988: my $currsec =
7989: &Apache::lonuserutils::course_sections($sections_count,
7990: $protectedcourse.'_'.$role);
1.222 raeburn 7991: $row .= '<td><table class="LC_createuser">'."\n".
7992: '<tr class="LC_section_row">'."\n".
7993: ' <td valign="top">'.$lt->{'exs'}.'<br />'.
7994: $currsec.'</td>'."\n".
7995: ' <td> </td>'."\n".
7996: ' <td valign="top"> '.$lt->{'new'}.'<br />'.
1.221 raeburn 7997: '<input type="text" name="newsec_'.$protectedcourse.'_'.$role.
7998: '" value="" />'.
7999: '<input type="hidden" '.
8000: 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'."\n".
1.222 raeburn 8001: '</tr></table></td>'."\n";
1.221 raeburn 8002: } else {
1.222 raeburn 8003: $row .= '<td><input type="text" size="10" '.
1.375 raeburn 8004: 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'."\n";
1.221 raeburn 8005: }
8006: }
1.222 raeburn 8007: $row .= <<ENDTIMEENTRY;
8008: <td><input type="hidden" name="start_$protectedcourse\_$role" value="" />
1.221 raeburn 8009: <a href=
8010: "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 8011: <td><input type="hidden" name="end_$protectedcourse\_$role" value="" />
1.221 raeburn 8012: <a href=
8013: "javascript:pjump('date_end','End Date $plrole',document.cu.end_$protectedcourse\_$role.value,'end_$protectedcourse\_$role','cu.pres','dateset')">$lt->{'sed'}</a></td>
8014: ENDTIMEENTRY
1.222 raeburn 8015: $row .= &Apache::loncommon::end_data_table_row();
8016: return $row;
1.221 raeburn 8017: }
8018:
1.88 raeburn 8019: sub course_level_dc {
1.375 raeburn 8020: my ($dcdom,$showcredits) = @_;
1.190 raeburn 8021: my %customroles=&Apache::lonuserutils::my_custom_roles();
1.213 raeburn 8022: my @roles = &Apache::lonuserutils::roles_by_context('course');
1.88 raeburn 8023: my $hiddenitems = '<input type="hidden" name="dcdomain" value="'.$dcdom.'" />'.
8024: '<input type="hidden" name="origdom" value="'.$dcdom.'" />'.
1.133 raeburn 8025: '<input type="hidden" name="dccourse" value="" />';
1.355 www 8026: my $courseform=&Apache::loncommon::selectcourse_link
1.356 raeburn 8027: ('cu','dccourse','dcdomain','coursedesc',undef,undef,'Select','crstype');
1.375 raeburn 8028: my $credit_elem;
8029: if ($showcredits) {
8030: $credit_elem = 'credits';
8031: }
8032: my $cb_jscript = &Apache::loncommon::coursebrowser_javascript($dcdom,'currsec','cu','role','Course/Community Browser',$credit_elem);
1.88 raeburn 8033: my %lt=&Apache::lonlocal::texthash(
8034: 'rol' => "Role",
1.113 raeburn 8035: 'grs' => "Section",
1.88 raeburn 8036: 'exs' => "Existing sections",
8037: 'new' => "Define new section",
8038: 'sta' => "Start",
8039: 'end' => "End",
8040: 'ssd' => "Set Start Date",
1.355 www 8041: 'sed' => "Set End Date",
1.375 raeburn 8042: 'scc' => "Course/Community",
8043: 'crd' => "Credits",
1.88 raeburn 8044: );
1.323 raeburn 8045: my $header = '<h4>'.&mt('Course/Community Level').'</h4>'.
1.136 raeburn 8046: &Apache::loncommon::start_data_table().
8047: &Apache::loncommon::start_data_table_header_row().
1.375 raeburn 8048: '<th>'.$lt{'scc'}.'</th><th>'.$lt{'rol'}.'</th>'."\n".
1.397 bisitz 8049: '<th>'.$lt{'grs'}.'</th>'."\n";
8050: $header .= '<th>'.$lt{'crd'}.'</th>'."\n" if ($showcredits);
8051: $header .= '<th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'."\n".
1.136 raeburn 8052: &Apache::loncommon::end_data_table_header_row();
1.143 raeburn 8053: my $otheritems = &Apache::loncommon::start_data_table_row()."\n".
1.356 raeburn 8054: '<td><br /><span class="LC_nobreak"><input type="text" name="coursedesc" value="" onfocus="this.blur();opencrsbrowser('."'cu','dccourse','dcdomain','coursedesc','','','','crstype'".')" />'.
8055: $courseform.(' ' x4).'</span></td>'."\n".
1.389 bisitz 8056: '<td valign="top"><br /><select name="role">'."\n";
1.213 raeburn 8057: foreach my $role (@roles) {
1.135 raeburn 8058: my $plrole=&Apache::lonnet::plaintext($role);
1.389 bisitz 8059: $otheritems .= ' <option value="'.$role.'">'.$plrole.'</option>';
1.88 raeburn 8060: }
1.404 raeburn 8061: if ( keys(%customroles) > 0) {
8062: foreach my $cust (sort(keys(%customroles))) {
1.101 albertel 8063: my $custrole='cr_cr_'.$env{'user.domain'}.
1.135 raeburn 8064: '_'.$env{'user.name'}.'_'.$cust;
1.389 bisitz 8065: $otheritems .= ' <option value="'.$custrole.'">'.$cust.'</option>';
1.88 raeburn 8066: }
8067: }
8068: $otheritems .= '</select></td><td>'.
8069: '<table border="0" cellspacing="0" cellpadding="0">'.
8070: '<tr><td valign="top"><b>'.$lt{'exs'}.'</b><br /><select name="currsec">'.
1.389 bisitz 8071: ' <option value=""><--'.&mt('Pick course first').'</option></select></td>'.
1.88 raeburn 8072: '<td> </td>'.
8073: '<td valign="top"> <b>'.$lt{'new'}.'</b><br />'.
1.113 raeburn 8074: '<input type="text" name="newsec" value="" />'.
1.237 raeburn 8075: '<input type="hidden" name="section" value="" />'.
1.323 raeburn 8076: '<input type="hidden" name="groups" value="" />'.
8077: '<input type="hidden" name="crstype" value="" /></td>'.
1.375 raeburn 8078: '</tr></table></td>'."\n";
8079: if ($showcredits) {
8080: $otheritems .= '<td><br />'."\n".
1.397 bisitz 8081: '<input type="text" size="3" name="credits" value="" /></td>'."\n";
1.375 raeburn 8082: }
1.88 raeburn 8083: $otheritems .= <<ENDTIMEENTRY;
1.323 raeburn 8084: <td><br /><input type="hidden" name="start" value='' />
1.88 raeburn 8085: <a href=
8086: "javascript:pjump('date_start','Start Date',document.cu.start.value,'start','cu.pres','dateset')">$lt{'ssd'}</a></td>
1.323 raeburn 8087: <td><br /><input type="hidden" name="end" value='' />
1.88 raeburn 8088: <a href=
8089: "javascript:pjump('date_end','End Date',document.cu.end.value,'end','cu.pres','dateset')">$lt{'sed'}</a></td>
8090: ENDTIMEENTRY
1.136 raeburn 8091: $otheritems .= &Apache::loncommon::end_data_table_row().
8092: &Apache::loncommon::end_data_table()."\n";
1.88 raeburn 8093: return $cb_jscript.$header.$hiddenitems.$otheritems;
8094: }
8095:
1.237 raeburn 8096: sub update_selfenroll_config {
1.400 raeburn 8097: my ($r,$cid,$cdom,$cnum,$context,$crstype,$currsettings) = @_;
1.398 raeburn 8098: return unless (ref($currsettings) eq 'HASH');
8099: my ($row,$lt) = &Apache::lonuserutils::get_selfenroll_titles();
8100: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
1.237 raeburn 8101: my (%changes,%warning);
1.241 raeburn 8102: my $curr_types;
1.400 raeburn 8103: my %noedit;
8104: unless ($context eq 'domain') {
8105: %noedit = &get_noedit_fields($cdom,$cnum,$crstype,$row);
8106: }
1.237 raeburn 8107: if (ref($row) eq 'ARRAY') {
8108: foreach my $item (@{$row}) {
1.400 raeburn 8109: next if ($noedit{$item});
1.237 raeburn 8110: if ($item eq 'enroll_dates') {
8111: my (%currenrolldate,%newenrolldate);
8112: foreach my $type ('start','end') {
1.398 raeburn 8113: $currenrolldate{$type} = $currsettings->{'selfenroll_'.$type.'_date'};
1.237 raeburn 8114: $newenrolldate{$type} = &Apache::lonhtmlcommon::get_date_from_form('selfenroll_'.$type.'_date');
8115: if ($newenrolldate{$type} ne $currenrolldate{$type}) {
8116: $changes{'internal.selfenroll_'.$type.'_date'} = $newenrolldate{$type};
8117: }
8118: }
8119: } elsif ($item eq 'access_dates') {
8120: my (%currdate,%newdate);
8121: foreach my $type ('start','end') {
1.398 raeburn 8122: $currdate{$type} = $currsettings->{'selfenroll_'.$type.'_access'};
1.237 raeburn 8123: $newdate{$type} = &Apache::lonhtmlcommon::get_date_from_form('selfenroll_'.$type.'_access');
8124: if ($newdate{$type} ne $currdate{$type}) {
8125: $changes{'internal.selfenroll_'.$type.'_access'} = $newdate{$type};
8126: }
8127: }
1.241 raeburn 8128: } elsif ($item eq 'types') {
1.398 raeburn 8129: $curr_types = $currsettings->{'selfenroll_'.$item};
1.241 raeburn 8130: if ($env{'form.selfenroll_all'}) {
8131: if ($curr_types ne '*') {
8132: $changes{'internal.selfenroll_types'} = '*';
8133: } else {
8134: next;
8135: }
8136: } else {
1.249 raeburn 8137: my %currdoms;
1.241 raeburn 8138: my @entries = split(/;/,$curr_types);
8139: my @deletedoms = &Apache::loncommon::get_env_multiple('form.selfenroll_delete');
1.249 raeburn 8140: my @activations = &Apache::loncommon::get_env_multiple('form.selfenroll_activate');
1.241 raeburn 8141: my $newnum = 0;
1.249 raeburn 8142: my @latesttypes;
8143: foreach my $num (@activations) {
8144: my @types = &Apache::loncommon::get_env_multiple('form.selfenroll_types_'.$num);
8145: if (@types > 0) {
1.241 raeburn 8146: @types = sort(@types);
8147: my $typestr = join(',',@types);
1.249 raeburn 8148: my $typedom = $env{'form.selfenroll_dom_'.$num};
8149: $latesttypes[$newnum] = $typedom.':'.$typestr;
8150: $currdoms{$typedom} = 1;
1.241 raeburn 8151: $newnum ++;
8152: }
8153: }
1.338 raeburn 8154: for (my $j=0; $j<$env{'form.selfenroll_types_total'}; $j++) {
8155: if ((!grep(/^$j$/,@deletedoms)) && (!grep(/^$j$/,@activations))) {
1.249 raeburn 8156: my @types = &Apache::loncommon::get_env_multiple('form.selfenroll_types_'.$j);
8157: if (@types > 0) {
8158: @types = sort(@types);
8159: my $typestr = join(',',@types);
8160: my $typedom = $env{'form.selfenroll_dom_'.$j};
8161: $latesttypes[$newnum] = $typedom.':'.$typestr;
8162: $currdoms{$typedom} = 1;
8163: $newnum ++;
8164: }
8165: }
8166: }
8167: if ($env{'form.selfenroll_newdom'} ne '') {
8168: my $typedom = $env{'form.selfenroll_newdom'};
8169: if ((!defined($currdoms{$typedom})) &&
8170: (&Apache::lonnet::domain($typedom) ne '')) {
8171: my $typestr;
8172: my ($othertitle,$usertypes,$types) =
8173: &Apache::loncommon::sorted_inst_types($typedom);
8174: my $othervalue = 'any';
8175: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
8176: if (@{$types} > 0) {
1.257 raeburn 8177: my @esc_types = map { &escape($_); } @{$types};
1.249 raeburn 8178: $othervalue = 'other';
1.258 raeburn 8179: $typestr = join(',',(@esc_types,$othervalue));
1.249 raeburn 8180: }
8181: $typestr = $othervalue;
8182: } else {
8183: $typestr = $othervalue;
8184: }
8185: $latesttypes[$newnum] = $typedom.':'.$typestr;
8186: $newnum ++ ;
8187: }
8188: }
1.241 raeburn 8189: my $selfenroll_types = join(';',@latesttypes);
8190: if ($selfenroll_types ne $curr_types) {
8191: $changes{'internal.selfenroll_types'} = $selfenroll_types;
8192: }
8193: }
1.276 raeburn 8194: } elsif ($item eq 'limit') {
8195: my $newlimit = $env{'form.selfenroll_limit'};
8196: my $newcap = $env{'form.selfenroll_cap'};
8197: $newcap =~s/\s+//g;
1.398 raeburn 8198: my $currlimit = $currsettings->{'selfenroll_limit'};
1.276 raeburn 8199: $currlimit = 'none' if ($currlimit eq '');
1.398 raeburn 8200: my $currcap = $currsettings->{'selfenroll_cap'};
1.276 raeburn 8201: if ($newlimit ne $currlimit) {
8202: if ($newlimit ne 'none') {
8203: if ($newcap =~ /^\d+$/) {
8204: if ($newcap ne $currcap) {
8205: $changes{'internal.selfenroll_cap'} = $newcap;
8206: }
8207: $changes{'internal.selfenroll_limit'} = $newlimit;
8208: } else {
1.398 raeburn 8209: $warning{$item} = &mt('Maximum enrollment setting unchanged.').'<br />'.
8210: &mt('The value provided was invalid - it must be a positive integer if enrollment is being limited.');
1.276 raeburn 8211: }
8212: } elsif ($currcap ne '') {
8213: $changes{'internal.selfenroll_cap'} = '';
8214: $changes{'internal.selfenroll_limit'} = $newlimit;
8215: }
8216: } elsif ($currlimit ne 'none') {
8217: if ($newcap =~ /^\d+$/) {
8218: if ($newcap ne $currcap) {
8219: $changes{'internal.selfenroll_cap'} = $newcap;
8220: }
8221: } else {
1.398 raeburn 8222: $warning{$item} = &mt('Maximum enrollment setting unchanged.').'<br />'.
8223: &mt('The value provided was invalid - it must be a positive integer if enrollment is being limited.');
1.276 raeburn 8224: }
8225: }
8226: } elsif ($item eq 'approval') {
8227: my (@currnotified,@newnotified);
1.398 raeburn 8228: my $currapproval = $currsettings->{'selfenroll_approval'};
8229: my $currnotifylist = $currsettings->{'selfenroll_notifylist'};
1.276 raeburn 8230: if ($currnotifylist ne '') {
8231: @currnotified = split(/,/,$currnotifylist);
8232: @currnotified = sort(@currnotified);
8233: }
8234: my $newapproval = $env{'form.selfenroll_approval'};
8235: @newnotified = &Apache::loncommon::get_env_multiple('form.selfenroll_notify');
8236: @newnotified = sort(@newnotified);
8237: if ($newapproval ne $currapproval) {
8238: $changes{'internal.selfenroll_approval'} = $newapproval;
8239: if (!$newapproval) {
8240: if ($currnotifylist ne '') {
8241: $changes{'internal.selfenroll_notifylist'} = '';
8242: }
8243: } else {
8244: my @differences =
1.295 raeburn 8245: &Apache::loncommon::compare_arrays(\@currnotified,\@newnotified);
1.276 raeburn 8246: if (@differences > 0) {
8247: if (@newnotified > 0) {
8248: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
8249: } else {
8250: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
8251: }
8252: }
8253: }
8254: } else {
1.295 raeburn 8255: my @differences = &Apache::loncommon::compare_arrays(\@currnotified,\@newnotified);
1.276 raeburn 8256: if (@differences > 0) {
8257: if (@newnotified > 0) {
8258: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
8259: } else {
8260: $changes{'internal.selfenroll_notifylist'} = '';
8261: }
8262: }
8263: }
1.237 raeburn 8264: } else {
1.398 raeburn 8265: my $curr_val = $currsettings->{'selfenroll_'.$item};
1.237 raeburn 8266: my $newval = $env{'form.selfenroll_'.$item};
8267: if ($item eq 'section') {
8268: $newval = $env{'form.sections'};
1.241 raeburn 8269: if (defined($curr_groups{$newval})) {
1.237 raeburn 8270: $newval = $curr_val;
1.398 raeburn 8271: $warning{$item} = &mt('Section for self-enrolled users unchanged as the proposed section is a group').'<br />'.
8272: &mt('Group names and section names must be distinct');
1.237 raeburn 8273: } elsif ($newval eq 'all') {
8274: $newval = $curr_val;
1.274 bisitz 8275: $warning{$item} = &mt('Section for self-enrolled users unchanged, as "all" is a reserved section name.');
1.237 raeburn 8276: }
8277: if ($newval eq '') {
8278: $newval = 'none';
8279: }
8280: }
8281: if ($newval ne $curr_val) {
8282: $changes{'internal.selfenroll_'.$item} = $newval;
8283: }
1.241 raeburn 8284: }
1.237 raeburn 8285: }
8286: if (keys(%warning) > 0) {
8287: foreach my $item (@{$row}) {
8288: if (exists($warning{$item})) {
8289: $r->print($warning{$item}.'<br />');
8290: }
8291: }
8292: }
8293: if (keys(%changes) > 0) {
8294: my $putresult = &Apache::lonnet::put('environment',\%changes,$cdom,$cnum);
8295: if ($putresult eq 'ok') {
8296: if ((exists($changes{'internal.selfenroll_types'})) ||
8297: (exists($changes{'internal.selfenroll_start_date'})) ||
8298: (exists($changes{'internal.selfenroll_end_date'}))) {
8299: my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',
8300: $cnum,undef,undef,'Course');
8301: my $chome = &Apache::lonnet::homeserver($cnum,$cdom);
1.398 raeburn 8302: if (ref($crsinfo{$cid}) eq 'HASH') {
1.237 raeburn 8303: foreach my $item ('selfenroll_types','selfenroll_start_date','selfenroll_end_date') {
8304: if (exists($changes{'internal.'.$item})) {
1.398 raeburn 8305: $crsinfo{$cid}{$item} = $changes{'internal.'.$item};
1.237 raeburn 8306: }
8307: }
8308: my $crsputresult =
8309: &Apache::lonnet::courseidput($cdom,\%crsinfo,
8310: $chome,'notime');
8311: }
8312: }
8313: $r->print(&mt('The following changes were made to self-enrollment settings:').'<ul>');
8314: foreach my $item (@{$row}) {
8315: my $title = $item;
8316: if (ref($lt) eq 'HASH') {
8317: $title = $lt->{$item};
8318: }
8319: if ($item eq 'enroll_dates') {
8320: foreach my $type ('start','end') {
8321: if (exists($changes{'internal.selfenroll_'.$type.'_date'})) {
8322: my $newdate = &Apache::lonlocal::locallocaltime($changes{'internal.selfenroll_'.$type.'_date'});
1.244 bisitz 8323: $r->print('<li>'.&mt('[_1]: "[_2]" set to "[_3]".',
1.237 raeburn 8324: $title,$type,$newdate).'</li>');
8325: }
8326: }
8327: } elsif ($item eq 'access_dates') {
8328: foreach my $type ('start','end') {
8329: if (exists($changes{'internal.selfenroll_'.$type.'_access'})) {
8330: my $newdate = &Apache::lonlocal::locallocaltime($changes{'internal.selfenroll_'.$type.'_access'});
1.244 bisitz 8331: $r->print('<li>'.&mt('[_1]: "[_2]" set to "[_3]".',
1.237 raeburn 8332: $title,$type,$newdate).'</li>');
8333: }
8334: }
1.276 raeburn 8335: } elsif ($item eq 'limit') {
8336: if ((exists($changes{'internal.selfenroll_limit'})) ||
8337: (exists($changes{'internal.selfenroll_cap'}))) {
8338: my ($newval,$newcap);
8339: if ($changes{'internal.selfenroll_cap'} ne '') {
8340: $newcap = $changes{'internal.selfenroll_cap'}
8341: } else {
1.398 raeburn 8342: $newcap = $currsettings->{'selfenroll_cap'};
1.276 raeburn 8343: }
8344: if ($changes{'internal.selfenroll_limit'} eq 'none') {
8345: $newval = &mt('No limit');
8346: } elsif ($changes{'internal.selfenroll_limit'} eq
8347: 'allstudents') {
8348: $newval = &mt('New self-enrollment no longer allowed when total (all students) reaches [_1].',$newcap);
8349: } elsif ($changes{'internal.selfenroll_limit'} eq 'selfenrolled') {
8350: $newval = &mt('New self-enrollment no longer allowed when total number of self-enrolled students reaches [_1].',$newcap);
8351: } else {
1.398 raeburn 8352: my $currlimit = $currsettings->{'selfenroll_limit'};
1.276 raeburn 8353: if ($currlimit eq 'allstudents') {
8354: $newval = &mt('New self-enrollment no longer allowed when total (all students) reaches [_1].',$newcap);
8355: } elsif ($changes{'internal.selfenroll_limit'} eq 'selfenrolled') {
1.308 raeburn 8356: $newval = &mt('New self-enrollment no longer allowed when total number of self-enrolled students reaches [_1].',$newcap);
1.276 raeburn 8357: }
8358: }
8359: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval).'</li>'."\n");
8360: }
8361: } elsif ($item eq 'approval') {
8362: if ((exists($changes{'internal.selfenroll_approval'})) ||
8363: (exists($changes{'internal.selfenroll_notifylist'}))) {
1.398 raeburn 8364: my %selfdescs = &Apache::lonuserutils::selfenroll_default_descs();
1.276 raeburn 8365: my ($newval,$newnotify);
8366: if (exists($changes{'internal.selfenroll_notifylist'})) {
8367: $newnotify = $changes{'internal.selfenroll_notifylist'};
8368: } else {
1.398 raeburn 8369: $newnotify = $currsettings->{'selfenroll_notifylist'};
1.276 raeburn 8370: }
1.398 raeburn 8371: if (exists($changes{'internal.selfenroll_approval'})) {
8372: if ($changes{'internal.selfenroll_approval'} !~ /^[012]$/) {
8373: $changes{'internal.selfenroll_approval'} = '0';
8374: }
8375: $newval = $selfdescs{'approval'}{$changes{'internal.selfenroll_approval'}};
1.276 raeburn 8376: } else {
1.398 raeburn 8377: my $currapproval = $currsettings->{'selfenroll_approval'};
8378: if ($currapproval !~ /^[012]$/) {
8379: $currapproval = 0;
1.276 raeburn 8380: }
1.398 raeburn 8381: $newval = $selfdescs{'approval'}{$currapproval};
1.276 raeburn 8382: }
8383: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval));
8384: if ($newnotify) {
1.277 raeburn 8385: $r->print('<br />'.&mt('The following will be notified when an enrollment request needs approval, or has been approved: [_1].',$newnotify));
1.276 raeburn 8386: } else {
1.277 raeburn 8387: $r->print('<br />'.&mt('No notifications sent when an enrollment request needs approval, or has been approved.'));
1.276 raeburn 8388: }
8389: $r->print('</li>'."\n");
8390: }
1.237 raeburn 8391: } else {
8392: if (exists($changes{'internal.selfenroll_'.$item})) {
1.241 raeburn 8393: my $newval = $changes{'internal.selfenroll_'.$item};
8394: if ($item eq 'types') {
8395: if ($newval eq '') {
8396: $newval = &mt('None');
8397: } elsif ($newval eq '*') {
8398: $newval = &mt('Any user in any domain');
8399: }
1.245 raeburn 8400: } elsif ($item eq 'registered') {
8401: if ($newval eq '1') {
8402: $newval = &mt('Yes');
8403: } elsif ($newval eq '0') {
8404: $newval = &mt('No');
8405: }
1.241 raeburn 8406: }
1.244 bisitz 8407: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval).'</li>'."\n");
1.237 raeburn 8408: }
8409: }
8410: }
8411: $r->print('</ul>');
1.398 raeburn 8412: if ($env{'course.'.$cid.'.description'} ne '') {
8413: my %newenvhash;
8414: foreach my $key (keys(%changes)) {
8415: $newenvhash{'course.'.$cid.'.'.$key} = $changes{$key};
8416: }
8417: &Apache::lonnet::appenv(\%newenvhash);
1.237 raeburn 8418: }
8419: } else {
1.398 raeburn 8420: $r->print(&mt('An error occurred when saving changes to self-enrollment settings in this course.').'<br />'.
8421: &mt('The error was: [_1].',$putresult));
1.237 raeburn 8422: }
8423: } else {
1.249 raeburn 8424: $r->print(&mt('No changes were made to the existing self-enrollment settings in this course.'));
1.237 raeburn 8425: }
8426: } else {
1.249 raeburn 8427: $r->print(&mt('No changes were made to the existing self-enrollment settings in this course.'));
1.241 raeburn 8428: }
1.400 raeburn 8429: my $visactions = &cat_visibility();
8430: my ($cathash,%cattype);
8431: my %domconfig = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom);
8432: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
8433: $cathash = $domconfig{'coursecategories'}{'cats'};
8434: $cattype{'auth'} = $domconfig{'coursecategories'}{'auth'};
8435: $cattype{'unauth'} = $domconfig{'coursecategories'}{'unauth'};
8436: } else {
8437: $cathash = {};
8438: $cattype{'auth'} = 'std';
8439: $cattype{'unauth'} = 'std';
8440: }
8441: if (($cattype{'auth'} eq 'none') && ($cattype{'unauth'} eq 'none')) {
8442: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
8443: '<br />'.
8444: '<br />'.$visactions->{'take'}.'<ul>'.
8445: '<li>'.$visactions->{'dc_chgconf'}.'</li>'.
8446: '</ul>');
8447: } elsif (($cattype{'auth'} !~ /^(std|domonly)$/) && ($cattype{'unauth'} !~ /^(std|domonly)$/)) {
8448: if ($currsettings->{'uniquecode'}) {
8449: $r->print('<span class="LC_info">'.$visactions->{'vis'}.'</span>');
8450: } else {
1.366 bisitz 8451: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
1.400 raeburn 8452: '<br />'.
8453: '<br />'.$visactions->{'take'}.'<ul>'.
8454: '<li>'.$visactions->{'dc_setcode'}.'</li>'.
8455: '</ul><br />');
8456: }
8457: } else {
8458: my ($visible,$cansetvis,$vismsgs) = &visible_in_stdcat($cdom,$cnum,\%domconfig);
8459: if (ref($visactions) eq 'HASH') {
8460: if (!$visible) {
8461: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
8462: '<br />');
8463: if (ref($vismsgs) eq 'ARRAY') {
8464: $r->print('<br />'.$visactions->{'take'}.'<ul>');
8465: foreach my $item (@{$vismsgs}) {
8466: $r->print('<li>'.$visactions->{$item}.'</li>');
8467: }
8468: $r->print('</ul>');
1.256 raeburn 8469: }
1.400 raeburn 8470: $r->print($cansetvis);
1.256 raeburn 8471: }
8472: }
8473: }
1.237 raeburn 8474: return;
8475: }
8476:
1.27 matthew 8477: #---------------------------------------------- end functions for &phase_two
1.29 matthew 8478:
8479: #--------------------------------- functions for &phase_two and &phase_three
8480:
8481: #--------------------------end of functions for &phase_two and &phase_three
1.372 raeburn 8482:
1.1 www 8483: 1;
8484: __END__
1.2 www 8485:
8486:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>