Annotation of loncom/interface/loncreateuser.pm, revision 1.421
1.20 harris41 1: # The LearningOnline Network with CAPA
1.1 www 2: # Create a user
3: #
1.421 ! raeburn 4: # $Id: loncreateuser.pm,v 1.420 2016/11/11 14:39:23 raeburn Exp $
1.22 albertel 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
1.20 harris41 28: ###
29:
1.1 www 30: package Apache::loncreateuser;
1.66 bowersj2 31:
32: =pod
33:
34: =head1 NAME
35:
1.263 jms 36: Apache::loncreateuser.pm
1.66 bowersj2 37:
38: =head1 SYNOPSIS
39:
1.263 jms 40: Handler to create users and custom roles
41:
42: Provides an Apache handler for creating users,
1.66 bowersj2 43: editing their login parameters, roles, and removing roles, and
44: also creating and assigning custom roles.
45:
46: =head1 OVERVIEW
47:
48: =head2 Custom Roles
49:
50: In LON-CAPA, roles are actually collections of privileges. "Teaching
51: Assistant", "Course Coordinator", and other such roles are really just
52: collection of privileges that are useful in many circumstances.
53:
1.324 raeburn 54: Custom roles can be defined by a Domain Coordinator, Course Coordinator
55: or Community Coordinator via the Manage User functionality.
56: The custom role editor screen will show all privileges which can be
57: assigned to users. For a complete list of privileges, please see
58: C</home/httpd/lonTabs/rolesplain.tab>.
1.66 bowersj2 59:
1.324 raeburn 60: Custom role definitions are stored in the C<roles.db> file of the creator
61: of the role.
1.66 bowersj2 62:
63: =cut
1.1 www 64:
65: use strict;
66: use Apache::Constants qw(:common :http);
67: use Apache::lonnet;
1.54 bowersj2 68: use Apache::loncommon;
1.68 www 69: use Apache::lonlocal;
1.117 raeburn 70: use Apache::longroup;
1.190 raeburn 71: use Apache::lonuserutils;
1.307 raeburn 72: use Apache::loncoursequeueadmin;
1.139 albertel 73: use LONCAPA qw(:DEFAULT :match);
1.1 www 74:
1.20 harris41 75: my $loginscript; # piece of javascript used in two separate instances
76: my $authformnop;
77: my $authformkrb;
78: my $authformint;
79: my $authformfsys;
80: my $authformloc;
81:
1.94 matthew 82: sub initialize_authen_forms {
1.227 raeburn 83: my ($dom,$formname,$curr_authtype,$mode) = @_;
84: my ($krbdef,$krbdefdom) = &Apache::loncommon::get_kerberos_defaults($dom);
85: my %param = ( formname => $formname,
1.187 raeburn 86: kerb_def_dom => $krbdefdom,
1.227 raeburn 87: kerb_def_auth => $krbdef,
1.187 raeburn 88: domain => $dom,
89: );
1.188 raeburn 90: my %abv_auth = &auth_abbrev();
1.227 raeburn 91: if ($curr_authtype =~ /^(krb4|krb5|internal|localauth|unix):(.*)$/) {
1.188 raeburn 92: my $long_auth = $1;
1.227 raeburn 93: my $curr_autharg = $2;
1.188 raeburn 94: my %abv_auth = &auth_abbrev();
95: $param{'curr_authtype'} = $abv_auth{$long_auth};
96: if ($long_auth =~ /^krb(4|5)$/) {
97: $param{'curr_kerb_ver'} = $1;
1.227 raeburn 98: $param{'curr_autharg'} = $curr_autharg;
1.188 raeburn 99: }
1.205 raeburn 100: if ($mode eq 'modifyuser') {
101: $param{'mode'} = $mode;
102: }
1.187 raeburn 103: }
1.227 raeburn 104: $loginscript = &Apache::loncommon::authform_header(%param);
105: $authformkrb = &Apache::loncommon::authform_kerberos(%param);
1.31 matthew 106: $authformnop = &Apache::loncommon::authform_nochange(%param);
107: $authformint = &Apache::loncommon::authform_internal(%param);
108: $authformfsys = &Apache::loncommon::authform_filesystem(%param);
109: $authformloc = &Apache::loncommon::authform_local(%param);
1.20 harris41 110: }
111:
1.188 raeburn 112: sub auth_abbrev {
113: my %abv_auth = (
1.368 raeburn 114: krb5 => 'krb',
115: krb4 => 'krb',
116: internal => 'int',
117: localauth => 'loc',
118: unix => 'fsys',
1.188 raeburn 119: );
120: return %abv_auth;
121: }
1.43 www 122:
1.134 raeburn 123: # ====================================================
124:
1.378 raeburn 125: sub user_quotas {
1.134 raeburn 126: my ($ccuname,$ccdomain) = @_;
127: my %lt = &Apache::lonlocal::texthash(
1.267 raeburn 128: 'usrt' => "User Tools",
129: 'cust' => "Custom quota",
130: 'chqu' => "Change quota",
1.134 raeburn 131: );
1.378 raeburn 132:
1.149 raeburn 133: my $quota_javascript = <<"END_SCRIPT";
134: <script type="text/javascript">
1.301 bisitz 135: // <![CDATA[
1.378 raeburn 136: function quota_changes(caller,context) {
137: var customoff = document.getElementById('custom_'+context+'quota_off');
138: var customon = document.getElementById('custom_'+context+'quota_on');
139: var number = document.getElementById(context+'quota');
1.149 raeburn 140: if (caller == "custom") {
1.378 raeburn 141: if (customoff) {
142: if (customoff.checked) {
143: number.value = "";
144: }
1.149 raeburn 145: }
146: }
147: if (caller == "quota") {
1.378 raeburn 148: if (customon) {
149: customon.checked = true;
150: }
1.149 raeburn 151: }
1.378 raeburn 152: return;
1.149 raeburn 153: }
1.301 bisitz 154: // ]]>
1.149 raeburn 155: </script>
156: END_SCRIPT
1.378 raeburn 157: my $longinsttype;
158: my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($ccdomain);
1.267 raeburn 159: my $output = $quota_javascript."\n".
160: '<h3>'.$lt{'usrt'}.'</h3>'."\n".
161: &Apache::loncommon::start_data_table();
162:
1.418 raeburn 163: if ((&Apache::lonnet::allowed('mut',$ccdomain)) ||
164: (&Apache::lonnet::allowed('udp',$ccdomain))) {
1.275 raeburn 165: $output .= &build_tools_display($ccuname,$ccdomain,'tools');
1.267 raeburn 166: }
1.378 raeburn 167:
168: my %titles = &Apache::lonlocal::texthash (
169: portfolio => "Disk space allocated to user's portfolio files",
1.385 bisitz 170: author => "Disk space allocated to user's Authoring Space (if role assigned)",
1.378 raeburn 171: );
172: foreach my $name ('portfolio','author') {
173: my ($currquota,$quotatype,$inststatus,$defquota) =
174: &Apache::loncommon::get_user_quota($ccuname,$ccdomain,$name);
175: if ($longinsttype eq '') {
176: if ($inststatus ne '') {
177: if ($usertypes->{$inststatus} ne '') {
178: $longinsttype = $usertypes->{$inststatus};
179: }
180: }
181: }
182: my ($showquota,$custom_on,$custom_off,$defaultinfo);
183: $custom_on = ' ';
184: $custom_off = ' checked="checked" ';
185: if ($quotatype eq 'custom') {
186: $custom_on = $custom_off;
187: $custom_off = ' ';
188: $showquota = $currquota;
189: if ($longinsttype eq '') {
190: $defaultinfo = &mt('For this user, the default quota would be [_1]'
1.383 raeburn 191: .' MB.',$defquota);
1.378 raeburn 192: } else {
193: $defaultinfo = &mt("For this user, the default quota would be [_1]".
1.383 raeburn 194: " MB, as determined by the user's institutional".
1.378 raeburn 195: " affiliation ([_2]).",$defquota,$longinsttype);
196: }
197: } else {
198: if ($longinsttype eq '') {
199: $defaultinfo = &mt('For this user, the default quota is [_1]'
1.383 raeburn 200: .' MB.',$defquota);
1.378 raeburn 201: } else {
202: $defaultinfo = &mt("For this user, the default quota of [_1]".
1.383 raeburn 203: " MB, is determined by the user's institutional".
1.378 raeburn 204: " affiliation ([_2]).",$defquota,$longinsttype);
205: }
206: }
207:
208: if (&Apache::lonnet::allowed('mpq',$ccdomain)) {
209: $output .= '<tr class="LC_info_row">'."\n".
210: ' <td>'.$titles{$name}.'</td>'."\n".
211: ' </tr>'."\n".
212: &Apache::loncommon::start_data_table_row()."\n".
1.390 bisitz 213: ' <td><span class="LC_nobreak">'.
214: &mt('Current quota: [_1] MB',$currquota).'</span> '.
1.378 raeburn 215: $defaultinfo.'</td>'."\n".
216: &Apache::loncommon::end_data_table_row()."\n".
217: &Apache::loncommon::start_data_table_row()."\n".
218: ' <td><span class="LC_nobreak">'.$lt{'chqu'}.
219: ': <label>'.
220: '<input type="radio" name="custom_'.$name.'quota" id="custom_'.$name.'quota_off" '.
1.379 raeburn 221: 'value="0" '.$custom_off.' onchange="javascript:quota_changes('."'custom','$name'".');"'.
1.390 bisitz 222: ' /><span class="LC_nobreak">'.
223: &mt('Default ([_1] MB)',$defquota).'</span></label> '.
1.378 raeburn 224: ' <label><input type="radio" name="custom_'.$name.'quota" id="custom_'.$name.'quota_on" '.
1.379 raeburn 225: 'value="1" '.$custom_on.' onchange="javascript:quota_changes('."'custom','$name'".');"'.
1.378 raeburn 226: ' />'.$lt{'cust'}.':</label> '.
1.379 raeburn 227: '<input type="text" name="'.$name.'quota" id="'.$name.'quota" size ="5" '.
228: 'value="'.$showquota.'" onfocus="javascript:quota_changes('."'quota','$name'".');"'.
1.390 bisitz 229: ' /> '.&mt('MB').'</span></td>'."\n".
1.378 raeburn 230: &Apache::loncommon::end_data_table_row()."\n";
231: }
232: }
1.267 raeburn 233: $output .= &Apache::loncommon::end_data_table();
1.134 raeburn 234: return $output;
235: }
236:
1.275 raeburn 237: sub build_tools_display {
238: my ($ccuname,$ccdomain,$context) = @_;
1.306 raeburn 239: my (@usertools,%userenv,$output,@options,%validations,%reqtitles,%reqdisplay,
1.332 raeburn 240: $colspan,$isadv,%domconfig);
1.275 raeburn 241: my %lt = &Apache::lonlocal::texthash (
242: 'blog' => "Personal User Blog",
243: 'aboutme' => "Personal Information Page",
1.385 bisitz 244: 'webdav' => "WebDAV access to Authoring Spaces (if SSL and author/co-author)",
1.275 raeburn 245: 'portfolio' => "Personal User Portfolio",
246: 'avai' => "Available",
247: 'cusa' => "availability",
248: 'chse' => "Change setting",
249: 'usde' => "Use default",
250: 'uscu' => "Use custom",
251: 'official' => 'Can request creation of official courses',
1.299 raeburn 252: 'unofficial' => 'Can request creation of unofficial courses',
253: 'community' => 'Can request creation of communities',
1.384 raeburn 254: 'textbook' => 'Can request creation of textbook courses',
1.411 raeburn 255: 'placement' => 'Can request creation of placement tests',
1.362 raeburn 256: 'requestauthor' => 'Can request author space',
1.275 raeburn 257: );
1.279 raeburn 258: if ($context eq 'requestcourses') {
1.275 raeburn 259: %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
1.299 raeburn 260: 'requestcourses.official','requestcourses.unofficial',
1.411 raeburn 261: 'requestcourses.community','requestcourses.textbook',
262: 'requestcourses.placement');
263: @usertools = ('official','unofficial','community','textbook','placement');
1.309 raeburn 264: @options =('norequest','approval','autolimit','validate');
1.306 raeburn 265: %validations = &Apache::lonnet::auto_courserequest_checks($ccdomain);
266: %reqtitles = &courserequest_titles();
267: %reqdisplay = &courserequest_display();
268: $colspan = ' colspan="2"';
1.332 raeburn 269: %domconfig =
270: &Apache::lonnet::get_dom('configuration',['requestcourses'],$ccdomain);
1.418 raeburn 271: $isadv = &Apache::lonnet::is_advanced_user($ccdomain,$ccuname);
1.362 raeburn 272: } elsif ($context eq 'requestauthor') {
273: %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
274: 'requestauthor');
275: @usertools = ('requestauthor');
276: @options =('norequest','approval','automatic');
277: %reqtitles = &requestauthor_titles();
278: %reqdisplay = &requestauthor_display();
279: $colspan = ' colspan="2"';
280: %domconfig =
281: &Apache::lonnet::get_dom('configuration',['requestauthor'],$ccdomain);
1.275 raeburn 282: } else {
283: %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
1.361 raeburn 284: 'tools.aboutme','tools.portfolio','tools.blog',
285: 'tools.webdav');
286: @usertools = ('aboutme','blog','webdav','portfolio');
1.275 raeburn 287: }
288: foreach my $item (@usertools) {
1.306 raeburn 289: my ($custom_access,$curr_access,$cust_on,$cust_off,$tool_on,$tool_off,
290: $currdisp,$custdisp,$custradio);
1.275 raeburn 291: $cust_off = 'checked="checked" ';
292: $tool_on = 'checked="checked" ';
293: $curr_access =
294: &Apache::lonnet::usertools_access($ccuname,$ccdomain,$item,undef,
295: $context);
1.362 raeburn 296: if ($context eq 'requestauthor') {
297: if ($userenv{$context} ne '') {
298: $cust_on = ' checked="checked" ';
299: $cust_off = '';
300: }
301: } elsif ($userenv{$context.'.'.$item} ne '') {
1.306 raeburn 302: $cust_on = ' checked="checked" ';
303: $cust_off = '';
304: }
305: if ($context eq 'requestcourses') {
306: if ($userenv{$context.'.'.$item} eq '') {
1.314 raeburn 307: $custom_access = &mt('Currently from default setting.');
1.306 raeburn 308: } else {
309: $custom_access = &mt('Currently from custom setting.');
1.275 raeburn 310: }
1.362 raeburn 311: } elsif ($context eq 'requestauthor') {
312: if ($userenv{$context} eq '') {
313: $custom_access = &mt('Currently from default setting.');
314: } else {
315: $custom_access = &mt('Currently from custom setting.');
316: }
1.275 raeburn 317: } else {
1.306 raeburn 318: if ($userenv{$context.'.'.$item} eq '') {
1.314 raeburn 319: $custom_access =
1.306 raeburn 320: &mt('Availability determined currently from default setting.');
321: if (!$curr_access) {
322: $tool_off = 'checked="checked" ';
323: $tool_on = '';
324: }
325: } else {
1.314 raeburn 326: $custom_access =
1.306 raeburn 327: &mt('Availability determined currently from custom setting.');
328: if ($userenv{$context.'.'.$item} == 0) {
329: $tool_off = 'checked="checked" ';
330: $tool_on = '';
331: }
1.275 raeburn 332: }
333: }
334: $output .= ' <tr class="LC_info_row">'."\n".
1.306 raeburn 335: ' <td'.$colspan.'>'.$lt{$item}.'</td>'."\n".
1.275 raeburn 336: ' </tr>'."\n".
1.306 raeburn 337: &Apache::loncommon::start_data_table_row()."\n";
1.418 raeburn 338:
1.362 raeburn 339: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.306 raeburn 340: my ($curroption,$currlimit);
1.362 raeburn 341: my $envkey = $context.'.'.$item;
342: if ($context eq 'requestauthor') {
343: $envkey = $context;
344: }
345: if ($userenv{$envkey} ne '') {
346: $curroption = $userenv{$envkey};
1.332 raeburn 347: } else {
348: my (@inststatuses);
1.362 raeburn 349: if ($context eq 'requestcourses') {
350: $curroption =
351: &Apache::loncoursequeueadmin::get_processtype('course',$ccuname,$ccdomain,
352: $isadv,$ccdomain,$item,
353: \@inststatuses,\%domconfig);
354: } else {
355: $curroption =
356: &Apache::loncoursequeueadmin::get_processtype('requestauthor',$ccuname,$ccdomain,
357: $isadv,$ccdomain,undef,
358: \@inststatuses,\%domconfig);
359: }
1.332 raeburn 360: }
1.306 raeburn 361: if (!$curroption) {
362: $curroption = 'norequest';
363: }
364: if ($curroption =~ /^autolimit=(\d*)$/) {
365: $currlimit = $1;
1.314 raeburn 366: if ($currlimit eq '') {
367: $currdisp = &mt('Yes, automatic creation');
368: } else {
369: $currdisp = &mt('Yes, up to [quant,_1,request]/user',$currlimit);
370: }
1.306 raeburn 371: } else {
372: $currdisp = $reqdisplay{$curroption};
373: }
374: $custdisp = '<table>';
375: foreach my $option (@options) {
376: my $val = $option;
377: if ($option eq 'norequest') {
378: $val = 0;
379: }
380: if ($option eq 'validate') {
381: my $canvalidate = 0;
382: if (ref($validations{$item}) eq 'HASH') {
383: if ($validations{$item}{'_custom_'}) {
384: $canvalidate = 1;
385: }
386: }
387: next if (!$canvalidate);
388: }
389: my $checked = '';
390: if ($option eq $curroption) {
391: $checked = ' checked="checked"';
392: } elsif ($option eq 'autolimit') {
393: if ($curroption =~ /^autolimit/) {
394: $checked = ' checked="checked"';
395: }
396: }
1.362 raeburn 397: my $name = 'crsreq_'.$item;
398: if ($context eq 'requestauthor') {
399: $name = $item;
400: }
1.306 raeburn 401: $custdisp .= '<tr><td><span class="LC_nobreak"><label>'.
1.362 raeburn 402: '<input type="radio" name="'.$name.'" '.
403: 'value="'.$val.'"'.$checked.' />'.
1.306 raeburn 404: $reqtitles{$option}.'</label> ';
405: if ($option eq 'autolimit') {
1.362 raeburn 406: $custdisp .= '<input type="text" name="'.$name.
407: '_limit" size="1" '.
1.314 raeburn 408: 'value="'.$currlimit.'" /></span><br />'.
409: $reqtitles{'unlimited'};
1.362 raeburn 410: } else {
411: $custdisp .= '</span>';
412: }
413: $custdisp .= '</td></tr>';
1.306 raeburn 414: }
415: $custdisp .= '</table>';
416: $custradio = '</span></td><td>'.&mt('Custom setting').'<br />'.$custdisp;
417: } else {
418: $currdisp = ($curr_access?&mt('Yes'):&mt('No'));
1.362 raeburn 419: my $name = $context.'_'.$item;
420: if ($context eq 'requestauthor') {
421: $name = $context;
422: }
1.306 raeburn 423: $custdisp = '<span class="LC_nobreak"><label>'.
1.362 raeburn 424: '<input type="radio" name="'.$name.'"'.
1.361 raeburn 425: ' value="1" '.$tool_on.'/>'.&mt('On').'</label> <label>'.
1.362 raeburn 426: '<input type="radio" name="'.$name.'" value="0" '.
1.306 raeburn 427: $tool_off.'/>'.&mt('Off').'</label></span>';
428: $custradio = (' 'x2).'--'.$lt{'cusa'}.': '.$custdisp.
429: '</span>';
430: }
431: $output .= ' <td'.$colspan.'>'.$custom_access.(' 'x4).
1.419 raeburn 432: $lt{'avai'}.': '.$currdisp.'</td>'."\n".
1.418 raeburn 433: &Apache::loncommon::end_data_table_row()."\n";
434: unless (&Apache::lonnet::allowed('udp',$ccdomain)) {
435: $output .=
1.275 raeburn 436: &Apache::loncommon::start_data_table_row()."\n".
1.306 raeburn 437: ' <td style="vertical-align:top;"><span class="LC_nobreak">'.
438: $lt{'chse'}.': <label>'.
1.275 raeburn 439: '<input type="radio" name="custom'.$item.'" value="0" '.
1.306 raeburn 440: $cust_off.'/>'.$lt{'usde'}.'</label>'.(' ' x3).
441: '<label><input type="radio" name="custom'.$item.'" value="1" '.
442: $cust_on.'/>'.$lt{'uscu'}.'</label>'.$custradio.'</td>'.
1.275 raeburn 443: &Apache::loncommon::end_data_table_row()."\n";
1.418 raeburn 444: }
1.275 raeburn 445: }
446: return $output;
447: }
448:
1.300 raeburn 449: sub coursereq_externaluser {
450: my ($ccuname,$ccdomain,$cdom) = @_;
1.306 raeburn 451: my (@usertools,@options,%validations,%userenv,$output);
1.300 raeburn 452: my %lt = &Apache::lonlocal::texthash (
453: 'official' => 'Can request creation of official courses',
454: 'unofficial' => 'Can request creation of unofficial courses',
455: 'community' => 'Can request creation of communities',
1.384 raeburn 456: 'textbook' => 'Can request creation of textbook courses',
1.411 raeburn 457: 'placement' => 'Can request creation of placement tests',
1.300 raeburn 458: );
459:
460: %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
461: 'reqcrsotherdom.official','reqcrsotherdom.unofficial',
1.411 raeburn 462: 'reqcrsotherdom.community','reqcrsotherdom.textbook',
463: 'reqcrsotherdom.placement');
464: @usertools = ('official','unofficial','community','textbook','placement');
1.309 raeburn 465: @options = ('approval','validate','autolimit');
1.306 raeburn 466: %validations = &Apache::lonnet::auto_courserequest_checks($cdom);
467: my $optregex = join('|',@options);
468: my %reqtitles = &courserequest_titles();
1.300 raeburn 469: foreach my $item (@usertools) {
1.306 raeburn 470: my ($curroption,$currlimit,$tooloff);
1.300 raeburn 471: if ($userenv{'reqcrsotherdom.'.$item} ne '') {
472: my @curr = split(',',$userenv{'reqcrsotherdom.'.$item});
1.314 raeburn 473: foreach my $req (@curr) {
474: if ($req =~ /^\Q$cdom\E\:($optregex)=?(\d*)$/) {
475: $curroption = $1;
476: $currlimit = $2;
477: last;
1.306 raeburn 478: }
479: }
1.314 raeburn 480: if (!$curroption) {
481: $curroption = 'norequest';
482: $tooloff = ' checked="checked"';
483: }
1.306 raeburn 484: } else {
485: $curroption = 'norequest';
486: $tooloff = ' checked="checked"';
487: }
488: $output.= &Apache::loncommon::start_data_table_row()."\n".
1.314 raeburn 489: ' <td><span class="LC_nobreak">'.$lt{$item}.': </span></td><td>'.
490: '<table><tr><td valign="top">'."\n".
1.306 raeburn 491: '<label><input type="radio" name="reqcrsotherdom_'.$item.
1.314 raeburn 492: '" value=""'.$tooloff.' />'.$reqtitles{'norequest'}.
493: '</label></td>';
1.306 raeburn 494: foreach my $option (@options) {
495: if ($option eq 'validate') {
496: my $canvalidate = 0;
497: if (ref($validations{$item}) eq 'HASH') {
498: if ($validations{$item}{'_external_'}) {
499: $canvalidate = 1;
500: }
501: }
502: next if (!$canvalidate);
503: }
504: my $checked = '';
505: if ($option eq $curroption) {
506: $checked = ' checked="checked"';
507: }
1.314 raeburn 508: $output .= '<td valign="top"><span class="LC_nobreak"><label>'.
1.306 raeburn 509: '<input type="radio" name="reqcrsotherdom_'.$item.
510: '" value="'.$option.'"'.$checked.' />'.
1.314 raeburn 511: $reqtitles{$option}.'</label>';
1.306 raeburn 512: if ($option eq 'autolimit') {
1.314 raeburn 513: $output .= ' <input type="text" name="reqcrsotherdom_'.
1.306 raeburn 514: $item.'_limit" size="1" '.
1.314 raeburn 515: 'value="'.$currlimit.'" /></span>'.
516: '<br />'.$reqtitles{'unlimited'};
517: } else {
518: $output .= '</span>';
1.300 raeburn 519: }
1.314 raeburn 520: $output .= '</td>';
1.300 raeburn 521: }
1.314 raeburn 522: $output .= '</td></tr></table></td>'."\n".
1.300 raeburn 523: &Apache::loncommon::end_data_table_row()."\n";
524: }
525: return $output;
526: }
527:
1.362 raeburn 528: sub domainrole_req {
529: my ($ccuname,$ccdomain) = @_;
530: return '<br /><h3>'.
531: &mt('User Can Request Assignment of Domain Roles?').
532: '</h3>'."\n".
533: &Apache::loncommon::start_data_table().
534: &build_tools_display($ccuname,$ccdomain,
535: 'requestauthor').
536: &Apache::loncommon::end_data_table();
537: }
538:
1.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.351 raeburn 760: my %breadcrumb_text = &singleuser_breadcrumb($crstype);
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.416 raeburn 788: 'srva' => 'Search for a user and view access log information',
1.71 sakharuk 789: 'usr' => "Username",
790: 'dom' => "Domain",
1.324 raeburn 791: 'ecrp' => "Define or Edit Custom Role",
792: 'nr' => "role name",
1.282 schafran 793: 'cre' => "Next",
1.71 sakharuk 794: );
1.351 raeburn 795:
1.214 raeburn 796: if ($env{'form.action'} eq 'custom') {
1.190 raeburn 797: if (&Apache::lonnet::allowed('mcr','/')) {
1.324 raeburn 798: my $newroletext = &mt('Define new custom role:');
799: $r->print('<form action="/adm/createuser" method="post" name="docustom">'.
800: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'.
801: '<input type="hidden" name="phase" value="selected_custom_edit" />'.
802: '<h3>'.$lt{'ecrp'}.'</h3>'.
803: &Apache::loncommon::start_data_table().
804: &Apache::loncommon::start_data_table_row().
805: '<td>');
806: if (keys(%existingroles) > 0) {
807: $r->print('<br /><label><input type="radio" name="customroleaction" value="new" checked="checked" onclick="setCustomFields();" /><b>'.$newroletext.'</b></label>');
808: } else {
809: $r->print('<br /><input type="hidden" name="customroleaction" value="new" /><b>'.$newroletext.'</b>');
810: }
811: $r->print('</td><td align="center">'.$lt{'nr'}.'<br /><input type="text" size="15" name="newrolename" onfocus="setCustomAction('."'new'".');" /></td>'.
812: &Apache::loncommon::end_data_table_row());
813: if (keys(%existingroles) > 0) {
814: $r->print(&Apache::loncommon::start_data_table_row().'<td><br />'.
815: '<label><input type="radio" name="customroleaction" value="edit" onclick="setCustomFields();"/><b>'.
816: &mt('View/Modify existing role:').'</b></label></td>'.
817: '<td align="center"><br />'.
818: '<select name="rolename" onchange="setCustomAction('."'edit'".');">'.
1.326 raeburn 819: '<option value="" selected="selected">'.
1.324 raeburn 820: &mt('Select'));
821: foreach my $role (sort(keys(%existingroles))) {
1.326 raeburn 822: $r->print('<option value="'.$role.'">'.$role.'</option>');
1.324 raeburn 823: }
824: $r->print('</select>'.
825: '</td>'.
826: &Apache::loncommon::end_data_table_row());
827: }
828: $r->print(&Apache::loncommon::end_data_table().'<p>'.
829: '<input name="customeditor" type="submit" value="'.
830: $lt{'cre'}.'" /></p>'.
831: '</form>');
1.190 raeburn 832: }
1.213 raeburn 833: } else {
1.229 raeburn 834: my $actiontext = $lt{'srad'};
1.213 raeburn 835: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 836: if ($crstype eq 'Community') {
837: $actiontext = $lt{'srme'};
838: } else {
839: $actiontext = $lt{'srst'};
840: }
1.416 raeburn 841: } elsif ($env{'form.action'} eq 'accesslogs') {
1.417 raeburn 842: $actiontext = $lt{'srva'};
1.213 raeburn 843: }
1.324 raeburn 844: $r->print("<h3>$actiontext</h3>");
1.213 raeburn 845: if ($env{'form.origform'} ne 'crtusername') {
1.415 raeburn 846: if ($response) {
847: $r->print("\n<div>$response</div>".
848: '<br clear="all" />');
849: }
1.213 raeburn 850: }
1.416 raeburn 851: $r->print(&entry_form($defdom,$srch,$forcenewuser,$context,$response,$crstype,1));
1.107 www 852: }
1.110 albertel 853: }
854:
1.324 raeburn 855: sub customrole_javascript {
856: my $js = <<"END";
857: <script type="text/javascript">
858: // <![CDATA[
859:
860: function setCustomFields() {
861: if (document.docustom.customroleaction.length > 0) {
862: for (var i=0; i<document.docustom.customroleaction.length; i++) {
863: if (document.docustom.customroleaction[i].checked) {
864: if (document.docustom.customroleaction[i].value == 'new') {
865: document.docustom.rolename.selectedIndex = 0;
866: } else {
867: document.docustom.newrolename.value = '';
868: }
869: }
870: }
871: }
872: return;
873: }
874:
875: function setCustomAction(caller) {
876: if (document.docustom.customroleaction.length > 0) {
877: for (var i=0; i<document.docustom.customroleaction.length; i++) {
878: if (document.docustom.customroleaction[i].value == caller) {
879: document.docustom.customroleaction[i].checked = true;
880: }
881: }
882: }
883: setCustomFields();
884: return;
885: }
886:
887: // ]]>
888: </script>
889: END
890: return $js;
891: }
892:
1.160 raeburn 893: sub entry_form {
1.416 raeburn 894: my ($dom,$srch,$forcenewuser,$context,$responsemsg,$crstype,$fixeddom) = @_;
1.229 raeburn 895: my ($usertype,$inexact);
1.214 raeburn 896: if (ref($srch) eq 'HASH') {
897: if (($srch->{'srchin'} eq 'dom') &&
898: ($srch->{'srchby'} eq 'uname') &&
899: ($srch->{'srchtype'} eq 'exact') &&
900: ($srch->{'srchdomain'} ne '') &&
901: ($srch->{'srchterm'} ne '')) {
1.353 raeburn 902: my (%curr_rules,%got_rules);
1.214 raeburn 903: my ($rules,$ruleorder) =
904: &Apache::lonnet::inst_userrules($srch->{'srchdomain'},'username');
1.353 raeburn 905: $usertype = &Apache::lonuserutils::check_usertype($srch->{'srchdomain'},$srch->{'srchterm'},$rules,\%curr_rules,\%got_rules);
1.229 raeburn 906: } else {
907: $inexact = 1;
1.214 raeburn 908: }
1.207 raeburn 909: }
1.214 raeburn 910: my $cancreate =
911: &Apache::lonuserutils::can_create_user($dom,$context,$usertype);
1.412 raeburn 912: my ($userpicker,$cansearch) =
1.179 raeburn 913: &Apache::loncommon::user_picker($dom,$srch,$forcenewuser,
1.416 raeburn 914: 'document.crtuser',$cancreate,$usertype,$context,$fixeddom);
1.160 raeburn 915: my $srchbutton = &mt('Search');
1.229 raeburn 916: if ($env{'form.action'} eq 'singlestudent') {
917: $srchbutton = &mt('Search and Enroll');
1.416 raeburn 918: } elsif ($env{'form.action'} eq 'accesslogs') {
919: $srchbutton = &mt('Search');
1.229 raeburn 920: } elsif ($cancreate && $responsemsg ne '' && $inexact) {
921: $srchbutton = &mt('Search or Add New User');
922: }
1.412 raeburn 923: my $output;
924: if ($cansearch) {
925: $output = <<"ENDBLOCK";
1.160 raeburn 926: <form action="/adm/createuser" method="post" name="crtuser">
1.190 raeburn 927: <input type="hidden" name="action" value="$env{'form.action'}" />
1.160 raeburn 928: <input type="hidden" name="phase" value="get_user_info" />
929: $userpicker
1.179 raeburn 930: <input name="userrole" type="button" value="$srchbutton" onclick="javascript:validateEntry(document.crtuser)" />
1.160 raeburn 931: </form>
1.207 raeburn 932: ENDBLOCK
1.412 raeburn 933: } else {
934: $output = '<p>'.$userpicker.'</p>';
935: }
1.416 raeburn 936: if (($env{'form.phase'} eq '') && ($env{'form.action'} ne 'accesslogs')) {
1.207 raeburn 937: my $defdom=$env{'request.role.domain'};
938: my $domform = &Apache::loncommon::select_dom_form($defdom,'srchdomain');
939: my %lt=&Apache::lonlocal::texthash(
1.229 raeburn 940: 'enro' => 'Enroll one student',
1.318 raeburn 941: 'enrm' => 'Enroll one member',
1.229 raeburn 942: 'admo' => 'Add/modify a single user',
943: 'crea' => 'create new user if required',
944: 'uskn' => "username is known",
1.207 raeburn 945: 'crnu' => 'Create a new user',
946: 'usr' => 'Username',
947: 'dom' => 'in domain',
1.229 raeburn 948: 'enrl' => 'Enroll',
949: 'cram' => 'Create/Modify user',
1.207 raeburn 950: );
1.229 raeburn 951: my $sellink=&Apache::loncommon::selectstudent_link('crtusername','srchterm','srchdomain');
952: my ($title,$buttontext,$showresponse);
1.318 raeburn 953: if ($env{'form.action'} eq 'singlestudent') {
954: if ($crstype eq 'Community') {
955: $title = $lt{'enrm'};
956: } else {
957: $title = $lt{'enro'};
958: }
1.229 raeburn 959: $buttontext = $lt{'enrl'};
960: } else {
961: $title = $lt{'admo'};
962: $buttontext = $lt{'cram'};
963: }
964: if ($cancreate) {
965: $title .= ' <span class="LC_cusr_subheading">('.$lt{'crea'}.')</span>';
966: } else {
967: $title .= ' <span class="LC_cusr_subheading">('.$lt{'uskn'}.')</span>';
968: }
969: if ($env{'form.origform'} eq 'crtusername') {
970: $showresponse = $responsemsg;
971: }
1.207 raeburn 972: $output .= <<"ENDDOCUMENT";
1.229 raeburn 973: <br />
1.207 raeburn 974: <form action="/adm/createuser" method="post" name="crtusername">
975: <input type="hidden" name="action" value="$env{'form.action'}" />
976: <input type="hidden" name="phase" value="createnewuser" />
977: <input type="hidden" name="srchtype" value="exact" />
1.233 raeburn 978: <input type="hidden" name="srchby" value="uname" />
1.207 raeburn 979: <input type="hidden" name="srchin" value="dom" />
980: <input type="hidden" name="forcenewuser" value="1" />
981: <input type="hidden" name="origform" value="crtusername" />
1.229 raeburn 982: <h3>$title</h3>
983: $showresponse
1.207 raeburn 984: <table>
985: <tr>
986: <td>$lt{'usr'}:</td>
987: <td><input type="text" size="15" name="srchterm" /></td>
988: <td> $lt{'dom'}:</td><td>$domform</td>
1.229 raeburn 989: <td> $sellink </td>
990: <td> <input name="userrole" type="submit" value="$buttontext" /></td>
1.207 raeburn 991: </tr>
992: </table>
993: </form>
1.160 raeburn 994: ENDDOCUMENT
1.207 raeburn 995: }
1.160 raeburn 996: return $output;
997: }
1.110 albertel 998:
999: sub user_modification_js {
1.113 raeburn 1000: my ($pjump_def,$dc_setcourse_code,$nondc_setsection_code,$groupslist)=@_;
1001:
1.110 albertel 1002: return <<END;
1003: <script type="text/javascript" language="Javascript">
1.301 bisitz 1004: // <![CDATA[
1.314 raeburn 1005:
1.110 albertel 1006: $pjump_def
1007: $dc_setcourse_code
1008:
1009: function dateset() {
1010: eval("document.cu."+document.cu.pres_marker.value+
1011: ".value=document.cu.pres_value.value");
1.359 www 1012: modalWindow.close();
1.110 albertel 1013: }
1014:
1.113 raeburn 1015: $nondc_setsection_code
1.301 bisitz 1016: // ]]>
1.110 albertel 1017: </script>
1018: END
1.2 www 1019: }
1020:
1021: # =================================================================== Phase two
1.160 raeburn 1022: sub print_user_selection_page {
1.351 raeburn 1023: my ($r,$response,$srch,$srch_results,$srcharray,$context,$opener_elements,$crstype,$brcrum) = @_;
1.160 raeburn 1024: my @fields = ('username','domain','lastname','firstname','permanentemail');
1025: my $sortby = $env{'form.sortby'};
1026:
1027: if (!grep(/^\Q$sortby\E$/,@fields)) {
1028: $sortby = 'lastname';
1029: }
1030:
1031: my ($jsback,$elements) = &crumb_utilities();
1032:
1033: my $jscript = (<<ENDSCRIPT);
1034: <script type="text/javascript">
1.301 bisitz 1035: // <![CDATA[
1.160 raeburn 1036: function pickuser(uname,udom) {
1037: document.usersrchform.seluname.value=uname;
1038: document.usersrchform.seludom.value=udom;
1039: document.usersrchform.phase.value="userpicked";
1040: document.usersrchform.submit();
1041: }
1042:
1043: $jsback
1.301 bisitz 1044: // ]]>
1.160 raeburn 1045: </script>
1046: ENDSCRIPT
1047:
1048: my %lt=&Apache::lonlocal::texthash(
1.179 raeburn 1049: 'usrch' => "User Search to add/modify roles",
1050: 'stusrch' => "User Search to enroll student",
1.318 raeburn 1051: 'memsrch' => "User Search to enroll member",
1.416 raeburn 1052: 'srcva' => "Search for a user and view access log information",
1.179 raeburn 1053: 'usel' => "Select a user to add/modify roles",
1.318 raeburn 1054: 'stusel' => "Select a user to enroll as a student",
1055: 'memsel' => "Select a user to enroll as a member",
1.416 raeburn 1056: 'vacsel' => "Select a user to view access log",
1.160 raeburn 1057: 'username' => "username",
1058: 'domain' => "domain",
1059: 'lastname' => "last name",
1060: 'firstname' => "first name",
1061: 'permanentemail' => "permanent e-mail",
1062: );
1.302 raeburn 1063: if ($context eq 'requestcrs') {
1064: $r->print('<div>');
1065: } else {
1.318 raeburn 1066: my %breadcrumb_text = &singleuser_breadcrumb($crstype);
1.351 raeburn 1067: my $helpitem;
1068: if ($env{'form.action'} eq 'singleuser') {
1069: $helpitem = 'Course_Change_Privileges';
1070: } elsif ($env{'form.action'} eq 'singlestudent') {
1071: $helpitem = 'Course_Add_Student';
1072: }
1073: push (@{$brcrum},
1074: {href => "javascript:backPage(document.usersrchform,'','')",
1075: text => $breadcrumb_text{'search'},
1076: faq => 282,
1077: bug => 'Instructor Interface',},
1078: {href => "javascript:backPage(document.usersrchform,'get_user_info','select')",
1079: text => $breadcrumb_text{'userpicked'},
1080: faq => 282,
1081: bug => 'Instructor Interface',
1082: help => $helpitem}
1083: );
1084: $r->print(&Apache::loncommon::start_page('User Management',$jscript,{bread_crumbs => $brcrum}));
1.302 raeburn 1085: if ($env{'form.action'} eq 'singleuser') {
1086: $r->print("<b>$lt{'usrch'}</b><br />");
1.318 raeburn 1087: $r->print(&entry_form($srch->{'srchdomain'},$srch,undef,$context,undef,$crstype));
1.302 raeburn 1088: $r->print('<h3>'.$lt{'usel'}.'</h3>');
1089: } elsif ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1090: $r->print($jscript."<b>");
1091: if ($crstype eq 'Community') {
1092: $r->print($lt{'memsrch'});
1093: } else {
1094: $r->print($lt{'stusrch'});
1095: }
1096: $r->print("</b><br />");
1097: $r->print(&entry_form($srch->{'srchdomain'},$srch,undef,$context,undef,$crstype));
1098: $r->print('</form><h3>');
1099: if ($crstype eq 'Community') {
1100: $r->print($lt{'memsel'});
1101: } else {
1102: $r->print($lt{'stusel'});
1103: }
1104: $r->print('</h3>');
1.416 raeburn 1105: } elsif ($env{'form.action'} eq 'accesslogs') {
1106: $r->print("<b>$lt{'srcva'}</b><br />");
1107: $r->print(&entry_form($srch->{'srchdomain'},$srch,undef,'accesslogs',undef,undef,1));
1108: $r->print('<h3>'.$lt{'vacsel'}.'</h3>');
1.302 raeburn 1109: }
1.179 raeburn 1110: }
1.380 bisitz 1111: $r->print('<form name="usersrchform" method="post" action="">'.
1.160 raeburn 1112: &Apache::loncommon::start_data_table()."\n".
1113: &Apache::loncommon::start_data_table_header_row()."\n".
1114: ' <th> </th>'."\n");
1115: foreach my $field (@fields) {
1116: $r->print(' <th><a href="javascript:document.usersrchform.sortby.value='.
1117: "'".$field."'".';document.usersrchform.submit();">'.
1118: $lt{$field}.'</a></th>'."\n");
1119: }
1120: $r->print(&Apache::loncommon::end_data_table_header_row());
1121:
1122: my @sorted_users = sort {
1.167 albertel 1123: lc($srch_results->{$a}->{$sortby}) cmp lc($srch_results->{$b}->{$sortby})
1.160 raeburn 1124: ||
1.167 albertel 1125: lc($srch_results->{$a}->{lastname}) cmp lc($srch_results->{$b}->{lastname})
1.160 raeburn 1126: ||
1127: lc($srch_results->{$a}->{firstname}) cmp lc($srch_results->{$b}->{firstname})
1.167 albertel 1128: ||
1129: lc($a) cmp lc($b)
1.160 raeburn 1130: } (keys(%$srch_results));
1131:
1132: foreach my $user (@sorted_users) {
1133: my ($uname,$udom) = split(/:/,$user);
1.302 raeburn 1134: my $onclick;
1135: if ($context eq 'requestcrs') {
1.314 raeburn 1136: $onclick =
1.302 raeburn 1137: 'onclick="javascript:gochoose('."'$uname','$udom',".
1138: "'$srch_results->{$user}->{firstname}',".
1139: "'$srch_results->{$user}->{lastname}',".
1140: "'$srch_results->{$user}->{permanentemail}'".');"';
1141: } else {
1.314 raeburn 1142: $onclick =
1.302 raeburn 1143: ' onclick="javascript:pickuser('."'".$uname."'".','."'".$udom."'".');"';
1144: }
1.160 raeburn 1145: $r->print(&Apache::loncommon::start_data_table_row().
1.302 raeburn 1146: '<td><input type="button" name="seluser" value="'.&mt('Select').'" '.
1147: $onclick.' /></td>'.
1.160 raeburn 1148: '<td><tt>'.$uname.'</tt></td>'.
1149: '<td><tt>'.$udom.'</tt></td>');
1150: foreach my $field ('lastname','firstname','permanentemail') {
1151: $r->print('<td>'.$srch_results->{$user}->{$field}.'</td>');
1152: }
1153: $r->print(&Apache::loncommon::end_data_table_row());
1154: }
1155: $r->print(&Apache::loncommon::end_data_table().'<br /><br />');
1.179 raeburn 1156: if (ref($srcharray) eq 'ARRAY') {
1157: foreach my $item (@{$srcharray}) {
1158: $r->print('<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n");
1159: }
1160: }
1.160 raeburn 1161: $r->print(' <input type="hidden" name="sortby" value="'.$sortby.'" />'."\n".
1162: ' <input type="hidden" name="seluname" value="" />'."\n".
1163: ' <input type="hidden" name="seludom" value="" />'."\n".
1.179 raeburn 1164: ' <input type="hidden" name="currstate" value="select" />'."\n".
1.190 raeburn 1165: ' <input type="hidden" name="phase" value="get_user_info" />'."\n".
1.214 raeburn 1166: ' <input type="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n");
1.302 raeburn 1167: if ($context eq 'requestcrs') {
1168: $r->print($opener_elements.'</form></div>');
1169: } else {
1.351 raeburn 1170: $r->print($response.'</form>');
1.302 raeburn 1171: }
1.160 raeburn 1172: }
1173:
1174: sub print_user_query_page {
1.351 raeburn 1175: my ($r,$caller,$brcrum) = @_;
1.160 raeburn 1176: # FIXME - this is for a network-wide name search (similar to catalog search)
1177: # To use frames with similar behavior to catalog/portfolio search.
1178: # To be implemented.
1179: return;
1180: }
1181:
1.42 matthew 1182: sub print_user_modification_page {
1.375 raeburn 1183: my ($r,$ccuname,$ccdomain,$srch,$response,$context,$permission,$crstype,
1184: $brcrum,$showcredits) = @_;
1.185 raeburn 1185: if (($ccuname eq '') || ($ccdomain eq '')) {
1.215 raeburn 1186: my $usermsg = &mt('No username and/or domain provided.');
1187: $env{'form.phase'} = '';
1.351 raeburn 1188: &print_username_entry_form($r,$context,$usermsg,'','',$crstype,$brcrum);
1.58 www 1189: return;
1190: }
1.213 raeburn 1191: my ($form,$formname);
1192: if ($env{'form.action'} eq 'singlestudent') {
1193: $form = 'document.enrollstudent';
1194: $formname = 'enrollstudent';
1195: } else {
1196: $form = 'document.cu';
1197: $formname = 'cu';
1198: }
1.188 raeburn 1199: my %abv_auth = &auth_abbrev();
1.227 raeburn 1200: my (%rulematch,%inst_results,$newuser,%alerts,%curr_rules,%got_rules);
1.185 raeburn 1201: my $uhome=&Apache::lonnet::homeserver($ccuname,$ccdomain);
1202: if ($uhome eq 'no_host') {
1.215 raeburn 1203: my $usertype;
1204: my ($rules,$ruleorder) =
1205: &Apache::lonnet::inst_userrules($ccdomain,'username');
1206: $usertype =
1.353 raeburn 1207: &Apache::lonuserutils::check_usertype($ccdomain,$ccuname,$rules,
1.362 raeburn 1208: \%curr_rules,\%got_rules);
1.215 raeburn 1209: my $cancreate =
1210: &Apache::lonuserutils::can_create_user($ccdomain,$context,
1211: $usertype);
1212: if (!$cancreate) {
1.292 bisitz 1213: my $helplink = 'javascript:helpMenu('."'display'".')';
1.215 raeburn 1214: my %usertypetext = (
1215: official => 'institutional',
1216: unofficial => 'non-institutional',
1217: );
1218: my $response;
1219: if ($env{'form.origform'} eq 'crtusername') {
1.362 raeburn 1220: $response = '<span class="LC_warning">'.
1221: &mt('No match found for the username [_1] in LON-CAPA domain: [_2]',
1222: '<b>'.$ccuname.'</b>',$ccdomain).
1.215 raeburn 1223: '</span><br />';
1224: }
1.292 bisitz 1225: $response .= '<p class="LC_warning">'
1226: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
1.418 raeburn 1227: .' ';
1228: if ($context eq 'domain') {
1229: $response .= &mt('Please contact a [_1] for assistance.',
1230: &Apache::lonnet::plaintext('dc'));
1231: } else {
1232: $response .= &mt('Please contact the [_1]helpdesk[_2] for assistance.'
1233: ,'<a href="'.$helplink.'">','</a>');
1234: }
1235: $response .= '</p><br />';
1.215 raeburn 1236: $env{'form.phase'} = '';
1.351 raeburn 1237: &print_username_entry_form($r,$context,$response,undef,undef,$crstype,$brcrum);
1.215 raeburn 1238: return;
1239: }
1.188 raeburn 1240: $newuser = 1;
1.193 raeburn 1241: my $checkhash;
1242: my $checks = { 'username' => 1 };
1.196 raeburn 1243: $checkhash->{$ccuname.':'.$ccdomain} = { 'newuser' => $newuser };
1.193 raeburn 1244: &Apache::loncommon::user_rule_check($checkhash,$checks,
1.196 raeburn 1245: \%alerts,\%rulematch,\%inst_results,\%curr_rules,\%got_rules);
1246: if (ref($alerts{'username'}) eq 'HASH') {
1247: if (ref($alerts{'username'}{$ccdomain}) eq 'HASH') {
1248: my $domdesc =
1.193 raeburn 1249: &Apache::lonnet::domain($ccdomain,'description');
1.196 raeburn 1250: if ($alerts{'username'}{$ccdomain}{$ccuname}) {
1251: my $userchkmsg;
1252: if (ref($curr_rules{$ccdomain}) eq 'HASH') {
1253: $userchkmsg =
1254: &Apache::loncommon::instrule_disallow_msg('username',
1.193 raeburn 1255: $domdesc,1).
1256: &Apache::loncommon::user_rule_formats($ccdomain,
1257: $domdesc,$curr_rules{$ccdomain}{'username'},
1258: 'username');
1.196 raeburn 1259: }
1.215 raeburn 1260: $env{'form.phase'} = '';
1.351 raeburn 1261: &print_username_entry_form($r,$context,$userchkmsg,undef,undef,$crstype,$brcrum);
1.196 raeburn 1262: return;
1.215 raeburn 1263: }
1.193 raeburn 1264: }
1.185 raeburn 1265: }
1.187 raeburn 1266: } else {
1.188 raeburn 1267: $newuser = 0;
1.185 raeburn 1268: }
1.160 raeburn 1269: if ($response) {
1.215 raeburn 1270: $response = '<br />'.$response;
1.160 raeburn 1271: }
1.149 raeburn 1272:
1.52 matthew 1273: my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
1.88 raeburn 1274: my $dc_setcourse_code = '';
1.119 raeburn 1275: my $nondc_setsection_code = '';
1.112 albertel 1276: my %loaditem;
1.114 albertel 1277:
1.216 raeburn 1278: my $groupslist = &Apache::lonuserutils::get_groupslist();
1.88 raeburn 1279:
1.375 raeburn 1280: my $js = &validation_javascript($context,$ccdomain,$pjump_def,$crstype,
1.216 raeburn 1281: $groupslist,$newuser,$formname,\%loaditem);
1.318 raeburn 1282: my %breadcrumb_text = &singleuser_breadcrumb($crstype);
1.224 raeburn 1283: my $helpitem = 'Course_Change_Privileges';
1284: if ($env{'form.action'} eq 'singlestudent') {
1285: $helpitem = 'Course_Add_Student';
1286: }
1.351 raeburn 1287: push (@{$brcrum},
1288: {href => "javascript:backPage($form)",
1289: text => $breadcrumb_text{'search'},
1290: faq => 282,
1291: bug => 'Instructor Interface',});
1292: if ($env{'form.phase'} eq 'userpicked') {
1293: push(@{$brcrum},
1294: {href => "javascript:backPage($form,'get_user_info','select')",
1295: text => $breadcrumb_text{'userpicked'},
1296: faq => 282,
1297: bug => 'Instructor Interface',});
1298: }
1299: push(@{$brcrum},
1300: {href => "javascript:backPage($form,'$env{'form.phase'}','modify')",
1301: text => $breadcrumb_text{'modify'},
1302: faq => 282,
1303: bug => 'Instructor Interface',
1304: help => $helpitem});
1305: my $args = {'add_entries' => \%loaditem,
1306: 'bread_crumbs' => $brcrum,
1307: 'bread_crumbs_component' => 'User Management'};
1308: if ($env{'form.popup'}) {
1309: $args->{'no_nav_bar'} = 1;
1310: }
1311: my $start_page =
1312: &Apache::loncommon::start_page('User Management',$js,$args);
1.3 www 1313:
1.25 matthew 1314: my $forminfo =<<"ENDFORMINFO";
1.216 raeburn 1315: <form action="/adm/createuser" method="post" name="$formname">
1.190 raeburn 1316: <input type="hidden" name="phase" value="update_user_data" />
1.188 raeburn 1317: <input type="hidden" name="ccuname" value="$ccuname" />
1318: <input type="hidden" name="ccdomain" value="$ccdomain" />
1.157 albertel 1319: <input type="hidden" name="pres_value" value="" />
1320: <input type="hidden" name="pres_type" value="" />
1321: <input type="hidden" name="pres_marker" value="" />
1.25 matthew 1322: ENDFORMINFO
1.375 raeburn 1323: my (%inccourses,$roledom,$defaultcredits);
1.329 raeburn 1324: if ($context eq 'course') {
1325: $inccourses{$env{'request.course.id'}}=1;
1326: $roledom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1.375 raeburn 1327: if ($showcredits) {
1328: $defaultcredits = &Apache::lonuserutils::get_defaultcredits();
1329: }
1.329 raeburn 1330: } elsif ($context eq 'author') {
1331: $roledom = $env{'request.role.domain'};
1332: } elsif ($context eq 'domain') {
1333: foreach my $key (keys(%env)) {
1334: $roledom = $env{'request.role.domain'};
1335: if ($key=~/^user\.priv\.cm\.\/($roledom)\/($match_username)/) {
1336: $inccourses{$1.'_'.$2}=1;
1337: }
1338: }
1339: } else {
1340: foreach my $key (keys(%env)) {
1341: if ($key=~/^user\.priv\.cm\.\/($match_domain)\/($match_username)/) {
1342: $inccourses{$1.'_'.$2}=1;
1343: }
1.2 www 1344: }
1.24 matthew 1345: }
1.389 bisitz 1346: my $title = '';
1.216 raeburn 1347: if ($newuser) {
1.414 raeburn 1348: my ($portfolioform,$domroleform,$adhocroleform);
1.267 raeburn 1349: if ((&Apache::lonnet::allowed('mpq',$env{'request.role.domain'})) ||
1350: (&Apache::lonnet::allowed('mut',$env{'request.role.domain'}))) {
1351: # Current user has quota or user tools modification privileges
1.378 raeburn 1352: $portfolioform = '<br />'.&user_quotas($ccuname,$ccdomain);
1.134 raeburn 1353: }
1.383 raeburn 1354: if ((&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) &&
1355: ($ccdomain eq $env{'request.role.domain'})) {
1.362 raeburn 1356: $domroleform = '<br />'.&domainrole_req($ccuname,$ccdomain);
1357: }
1.414 raeburn 1358: if (&Apache::lonnet::allowed('cdh',$env{'request.role.domain'})) {
1359: $adhocroleform = &domadhocroles($ccuname,$ccdomain);
1360: if ($adhocroleform) {
1361: $adhocroleform = '<br />'.$adhocroleform;
1362: }
1363: }
1.227 raeburn 1364: &initialize_authen_forms($ccdomain,$formname);
1.188 raeburn 1365: my %lt=&Apache::lonlocal::texthash(
1366: 'lg' => 'Login Data',
1.190 raeburn 1367: 'hs' => "Home Server",
1.188 raeburn 1368: );
1.185 raeburn 1369: $r->print(<<ENDTITLE);
1.110 albertel 1370: $start_page
1.160 raeburn 1371: $response
1.25 matthew 1372: $forminfo
1.31 matthew 1373: <script type="text/javascript" language="Javascript">
1.301 bisitz 1374: // <![CDATA[
1.20 harris41 1375: $loginscript
1.301 bisitz 1376: // ]]>
1.31 matthew 1377: </script>
1.20 harris41 1378: <input type='hidden' name='makeuser' value='1' />
1.185 raeburn 1379: ENDTITLE
1.213 raeburn 1380: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1381: if ($crstype eq 'Community') {
1.389 bisitz 1382: $title = &mt('Create New User [_1] in domain [_2] as a member',
1383: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.318 raeburn 1384: } else {
1.389 bisitz 1385: $title = &mt('Create New User [_1] in domain [_2] as a student',
1386: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.318 raeburn 1387: }
1.389 bisitz 1388: } else {
1389: $title = &mt('Create New User [_1] in domain [_2]',
1390: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.213 raeburn 1391: }
1.389 bisitz 1392: $r->print('<h2>'.$title.'</h2>'."\n");
1393: $r->print('<div class="LC_left_float">');
1.393 raeburn 1394: $r->print(&personal_data_display($ccuname,$ccdomain,$newuser,$context,
1395: $inst_results{$ccuname.':'.$ccdomain}));
1396: # Option to disable student/employee ID conflict checking not offerred for new users.
1.187 raeburn 1397: my ($home_server_pick,$numlib) =
1398: &Apache::loncommon::home_server_form_item($ccdomain,'hserver',
1399: 'default','hide');
1400: if ($numlib > 1) {
1401: $r->print("
1.185 raeburn 1402: <br />
1.187 raeburn 1403: $lt{'hs'}: $home_server_pick
1404: <br />");
1405: } else {
1406: $r->print($home_server_pick);
1407: }
1.304 raeburn 1408: if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
1.362 raeburn 1409: $r->print('<br /><h3>'.
1410: &mt('User Can Request Creation of Courses/Communities in this Domain?').'</h3>'.
1.304 raeburn 1411: &Apache::loncommon::start_data_table().
1412: &build_tools_display($ccuname,$ccdomain,
1413: 'requestcourses').
1414: &Apache::loncommon::end_data_table());
1415: }
1.188 raeburn 1416: $r->print('</div>'."\n".'<div class="LC_left_float"><h3>'.
1417: $lt{'lg'}.'</h3>');
1.185 raeburn 1418: my ($fixedauth,$varauth,$authmsg);
1.193 raeburn 1419: if (ref($rulematch{$ccuname.':'.$ccdomain}) eq 'HASH') {
1420: my $matchedrule = $rulematch{$ccuname.':'.$ccdomain}{'username'};
1421: my ($rules,$ruleorder) =
1422: &Apache::lonnet::inst_userrules($ccdomain,'username');
1.185 raeburn 1423: if (ref($rules) eq 'HASH') {
1.193 raeburn 1424: if (ref($rules->{$matchedrule}) eq 'HASH') {
1425: my $authtype = $rules->{$matchedrule}{'authtype'};
1.185 raeburn 1426: if ($authtype !~ /^(krb4|krb5|int|fsys|loc)$/) {
1.190 raeburn 1427: $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1.275 raeburn 1428: } else {
1.193 raeburn 1429: my $authparm = $rules->{$matchedrule}{'authparm'};
1.273 raeburn 1430: $authmsg = $rules->{$matchedrule}{'authmsg'};
1.185 raeburn 1431: if ($authtype =~ /^krb(4|5)$/) {
1432: my $ver = $1;
1433: if ($authparm ne '') {
1434: $fixedauth = <<"KERB";
1435: <input type="hidden" name="login" value="krb" />
1436: <input type="hidden" name="krbver" value="$ver" />
1437: <input type="hidden" name="krbarg" value="$authparm" />
1438: KERB
1439: }
1440: } else {
1441: $fixedauth =
1442: '<input type="hidden" name="login" value="'.$authtype.'" />'."\n";
1.193 raeburn 1443: if ($rules->{$matchedrule}{'authparmfixed'}) {
1.185 raeburn 1444: $fixedauth .=
1445: '<input type="hidden" name="'.$authtype.'arg" value="'.$authparm.'" />'."\n";
1446: } else {
1.273 raeburn 1447: if ($authtype eq 'int') {
1448: $varauth = '<br />'.
1.301 bisitz 1449: &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 1450: } elsif ($authtype eq 'loc') {
1451: $varauth = '<br />'.
1452: &mt('[_1] Local Authentication with argument [_2]','','<input type="text" name="'.$authtype.'arg" value="" />')."\n";
1453: } else {
1454: $varauth =
1.185 raeburn 1455: '<input type="text" name="'.$authtype.'arg" value="" />'."\n";
1.273 raeburn 1456: }
1.185 raeburn 1457: }
1458: }
1459: }
1460: } else {
1.190 raeburn 1461: $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1.185 raeburn 1462: }
1463: }
1464: if ($authmsg) {
1465: $r->print(<<ENDAUTH);
1466: $fixedauth
1467: $authmsg
1468: $varauth
1469: ENDAUTH
1470: }
1471: } else {
1.190 raeburn 1472: $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1.187 raeburn 1473: }
1.414 raeburn 1474: $r->print($portfolioform.$domroleform.$adhocroleform);
1.215 raeburn 1475: if ($env{'form.action'} eq 'singlestudent') {
1476: $r->print(&date_sections_select($context,$newuser,$formname,
1.375 raeburn 1477: $permission,$crstype,$ccuname,
1478: $ccdomain,$showcredits));
1.215 raeburn 1479: }
1480: $r->print('</div><div class="LC_clear_float_footer"></div>');
1.216 raeburn 1481: } else { # user already exists
1.389 bisitz 1482: $r->print($start_page.$forminfo);
1.213 raeburn 1483: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1484: if ($crstype eq 'Community') {
1.389 bisitz 1485: $title = &mt('Enroll one member: [_1] in domain [_2]',
1486: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.318 raeburn 1487: } else {
1.389 bisitz 1488: $title = &mt('Enroll one student: [_1] in domain [_2]',
1489: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.318 raeburn 1490: }
1.213 raeburn 1491: } else {
1.418 raeburn 1492: if ($permission->{'cusr'}) {
1493: $title = &mt('Modify existing user: [_1] in domain [_2]',
1494: '"'.$ccuname.'"','"'.$ccdomain.'"');
1495: } else {
1496: $title = &mt('Existing user: [_1] in domain [_2]',
1.389 bisitz 1497: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.418 raeburn 1498: }
1.213 raeburn 1499: }
1.389 bisitz 1500: $r->print('<h2>'.$title.'</h2>'."\n");
1501: $r->print('<div class="LC_left_float">');
1.393 raeburn 1502: $r->print(&personal_data_display($ccuname,$ccdomain,$newuser,$context,
1503: $inst_results{$ccuname.':'.$ccdomain}));
1.418 raeburn 1504: if ((&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) ||
1505: (&Apache::lonnet::allowed('udp',$env{'request.role.domain'}))) {
1.362 raeburn 1506: $r->print('<br /><h3>'.&mt('User Can Request Creation of Courses/Communities in this Domain?').'</h3>'.
1.300 raeburn 1507: &Apache::loncommon::start_data_table());
1.314 raeburn 1508: if ($env{'request.role.domain'} eq $ccdomain) {
1.300 raeburn 1509: $r->print(&build_tools_display($ccuname,$ccdomain,'requestcourses'));
1510: } else {
1511: $r->print(&coursereq_externaluser($ccuname,$ccdomain,
1512: $env{'request.role.domain'}));
1513: }
1514: $r->print(&Apache::loncommon::end_data_table());
1.275 raeburn 1515: }
1.199 raeburn 1516: $r->print('</div>');
1.414 raeburn 1517: my @order = ('auth','quota','tools','requestauthor','adhocroles');
1.362 raeburn 1518: my %user_text;
1519: my ($isadv,$isauthor) =
1.418 raeburn 1520: &Apache::lonnet::is_advanced_user($ccdomain,$ccuname);
1.362 raeburn 1521: if ((!$isauthor) &&
1.418 raeburn 1522: ((&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) ||
1523: (&Apache::lonnet::allowed('udp',$env{'request.role.domain'}))) &&
1524: ($env{'request.role.domain'} eq $ccdomain)) {
1.362 raeburn 1525: $user_text{'requestauthor'} = &domainrole_req($ccuname,$ccdomain);
1526: }
1.418 raeburn 1527: if ((&Apache::lonnet::allowed('cdh',$env{'request.role.domain'})) ||
1528: (&Apache::lonnet::allowed('udp',$env{'request.role.domain'}))) {
1.414 raeburn 1529: $user_text{'adhocroles'} = &domadhocroles($ccuname,$ccdomain);
1530: }
1.362 raeburn 1531: $user_text{'auth'} = &user_authentication($ccuname,$ccdomain,$formname);
1.267 raeburn 1532: if ((&Apache::lonnet::allowed('mpq',$ccdomain)) ||
1.418 raeburn 1533: (&Apache::lonnet::allowed('mut',$ccdomain)) ||
1534: (&Apache::lonnet::allowed('udp',$ccdomain))) {
1.188 raeburn 1535: # Current user has quota modification privileges
1.378 raeburn 1536: $user_text{'quota'} = &user_quotas($ccuname,$ccdomain);
1.267 raeburn 1537: }
1538: if (!&Apache::lonnet::allowed('mpq',$ccdomain)) {
1539: if (&Apache::lonnet::allowed('mpq',$env{'request.role.domain'})) {
1540: my %lt=&Apache::lonlocal::texthash(
1.385 bisitz 1541: 'dska' => "Disk quotas for user's portfolio and Authoring Space",
1542: 'youd' => "You do not have privileges to modify the portfolio and/or Authoring Space quotas for this user.",
1.267 raeburn 1543: 'ichr' => "If a change is required, contact a domain coordinator for the domain",
1544: );
1.362 raeburn 1545: $user_text{'quota'} = <<ENDNOPORTPRIV;
1.188 raeburn 1546: <h3>$lt{'dska'}</h3>
1547: $lt{'youd'} $lt{'ichr'}: $ccdomain
1548: ENDNOPORTPRIV
1.267 raeburn 1549: }
1550: }
1551: if (!&Apache::lonnet::allowed('mut',$ccdomain)) {
1552: if (&Apache::lonnet::allowed('mut',$env{'request.role.domain'})) {
1553: my %lt=&Apache::lonlocal::texthash(
1554: 'utav' => "User Tools Availability",
1.361 raeburn 1555: 'yodo' => "You do not have privileges to modify Portfolio, Blog, WebDAV, or Personal Information Page settings for this user.",
1.267 raeburn 1556: 'ifch' => "If a change is required, contact a domain coordinator for the domain",
1557: );
1.362 raeburn 1558: $user_text{'tools'} = <<ENDNOTOOLSPRIV;
1.267 raeburn 1559: <h3>$lt{'utav'}</h3>
1560: $lt{'yodo'} $lt{'ifch'}: $ccdomain
1561: ENDNOTOOLSPRIV
1562: }
1.188 raeburn 1563: }
1.362 raeburn 1564: my $gotdiv = 0;
1565: foreach my $item (@order) {
1566: if ($user_text{$item} ne '') {
1567: unless ($gotdiv) {
1568: $r->print('<div class="LC_left_float">');
1569: $gotdiv = 1;
1570: }
1571: $r->print('<br />'.$user_text{$item});
1572: }
1573: }
1574: if ($env{'form.action'} eq 'singlestudent') {
1575: unless ($gotdiv) {
1576: $r->print('<div class="LC_left_float">');
1.213 raeburn 1577: }
1.375 raeburn 1578: my $credits;
1579: if ($showcredits) {
1580: $credits = &get_user_credits($ccuname,$ccdomain,$defaultcredits);
1581: if ($credits eq '') {
1582: $credits = $defaultcredits;
1583: }
1584: }
1.374 raeburn 1585: $r->print(&date_sections_select($context,$newuser,$formname,
1.375 raeburn 1586: $permission,$crstype,$ccuname,
1587: $ccdomain,$showcredits));
1.374 raeburn 1588: }
1.362 raeburn 1589: if ($gotdiv) {
1590: $r->print('</div><div class="LC_clear_float_footer"></div>');
1.188 raeburn 1591: }
1.418 raeburn 1592: my $statuses;
1593: if (($context eq 'domain') && (&Apache::lonnet::allowed('udp',$ccdomain)) &&
1594: (!&Apache::lonnet::allowed('mau',$ccdomain))) {
1595: $statuses = ['active'];
1596: } elsif (($context eq 'course') && ((&Apache::lonnet::allowed('vcl',$env{'request.course.id'})) ||
1597: ($env{'request.course.sec'} &&
1598: &Apache::lonnet::allowed('vcl',$env{'request.course.id'}.'/'.$env{'request.course.sec'})))) {
1599: $statuses = ['active'];
1600: }
1.217 raeburn 1601: if ($env{'form.action'} ne 'singlestudent') {
1.329 raeburn 1602: &display_existing_roles($r,$ccuname,$ccdomain,\%inccourses,$context,
1.418 raeburn 1603: $roledom,$crstype,$showcredits,$statuses);
1.217 raeburn 1604: }
1.25 matthew 1605: } ## End of new user/old user logic
1.218 raeburn 1606: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1607: my $btntxt;
1608: if ($crstype eq 'Community') {
1609: $btntxt = &mt('Enroll Member');
1610: } else {
1611: $btntxt = &mt('Enroll Student');
1612: }
1613: $r->print('<br /><input type="button" value="'.$btntxt.'" onclick="setSections(this.form)" />'."\n");
1.418 raeburn 1614: } elsif ($permission->{'cusr'}) {
1.393 raeburn 1615: $r->print('<div class="LC_left_float">'.
1616: '<fieldset><legend>'.&mt('Add Roles').'</legend>');
1.218 raeburn 1617: my $addrolesdisplay = 0;
1618: if ($context eq 'domain' || $context eq 'author') {
1619: $addrolesdisplay = &new_coauthor_roles($r,$ccuname,$ccdomain);
1620: }
1621: if ($context eq 'domain') {
1.357 raeburn 1622: my $add_domainroles = &new_domain_roles($r,$ccdomain);
1.218 raeburn 1623: if (!$addrolesdisplay) {
1624: $addrolesdisplay = $add_domainroles;
1.2 www 1625: }
1.375 raeburn 1626: $r->print(&course_level_dc($env{'request.role.domain'},$showcredits));
1.393 raeburn 1627: $r->print('</fieldset></div><div class="LC_clear_float_footer"></div>'.
1628: '<br /><input type="button" value="'.&mt('Save').'" onclick="setCourse()" />'."\n");
1.218 raeburn 1629: } elsif ($context eq 'author') {
1630: if ($addrolesdisplay) {
1.393 raeburn 1631: $r->print('</fieldset></div><div class="LC_clear_float_footer"></div>'.
1632: '<br /><input type="button" value="'.&mt('Save').'"');
1.218 raeburn 1633: if ($newuser) {
1.301 bisitz 1634: $r->print(' onclick="auth_check()" \>'."\n");
1.218 raeburn 1635: } else {
1.301 bisitz 1636: $r->print('onclick="this.form.submit()" \>'."\n");
1.218 raeburn 1637: }
1.188 raeburn 1638: } else {
1.393 raeburn 1639: $r->print('</fieldset></div>'.
1640: '<div class="LC_clear_float_footer"></div>'.
1641: '<br /><a href="javascript:backPage(document.cu)">'.
1.218 raeburn 1642: &mt('Back to previous page').'</a>');
1.188 raeburn 1643: }
1644: } else {
1.375 raeburn 1645: $r->print(&course_level_table(\%inccourses,$showcredits,$defaultcredits));
1.393 raeburn 1646: $r->print('</fieldset></div><div class="LC_clear_float_footer"></div>'.
1647: '<br /><input type="button" value="'.&mt('Save').'" onclick="setSections(this.form)" />'."\n");
1.188 raeburn 1648: }
1.88 raeburn 1649: }
1.188 raeburn 1650: $r->print(&Apache::lonhtmlcommon::echo_form_input(['phase','userrole','ccdomain','prevphase','currstate','ccuname','ccdomain']));
1.179 raeburn 1651: $r->print('<input type="hidden" name="currstate" value="" />');
1.393 raeburn 1652: $r->print('<input type="hidden" name="prevphase" value="'.$env{'form.phase'}.'" /></form><br /><br />');
1.218 raeburn 1653: return;
1.2 www 1654: }
1.1 www 1655:
1.213 raeburn 1656: sub singleuser_breadcrumb {
1.318 raeburn 1657: my ($crstype) = @_;
1.213 raeburn 1658: my %breadcrumb_text;
1659: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1660: if ($crstype eq 'Community') {
1661: $breadcrumb_text{'search'} = 'Enroll a member';
1662: } else {
1663: $breadcrumb_text{'search'} = 'Enroll a student';
1664: }
1.213 raeburn 1665: $breadcrumb_text{'userpicked'} = 'Select a user',
1666: $breadcrumb_text{'modify'} = 'Set section/dates',
1.416 raeburn 1667: } elsif ($env{'form.action'} eq 'accesslogs') {
1668: $breadcrumb_text{'search'} = 'View access logs for a user';
1669: $breadcrumb_text{'userpicked'} = 'Select a user',
1670: $breadcrumb_text{'activity'} = 'Activity',
1.213 raeburn 1671: } else {
1.229 raeburn 1672: $breadcrumb_text{'search'} = 'Create/modify a user';
1.213 raeburn 1673: $breadcrumb_text{'userpicked'} = 'Select a user',
1674: $breadcrumb_text{'modify'} = 'Set user role',
1675: }
1676: return %breadcrumb_text;
1677: }
1678:
1679: sub date_sections_select {
1.375 raeburn 1680: my ($context,$newuser,$formname,$permission,$crstype,$ccuname,$ccdomain,
1681: $showcredits) = @_;
1682: my $credits;
1683: if ($showcredits) {
1684: my $defaultcredits = &Apache::lonuserutils::get_defaultcredits();
1685: $credits = &get_user_credits($ccuname,$ccdomain,$defaultcredits);
1686: if ($credits eq '') {
1687: $credits = $defaultcredits;
1688: }
1689: }
1.213 raeburn 1690: my $cid = $env{'request.course.id'};
1691: my ($cnum,$cdom) = &Apache::lonuserutils::get_course_identity($cid);
1692: my $date_table = '<h3>'.&mt('Starting and Ending Dates').'</h3>'."\n".
1693: &Apache::lonuserutils::date_setting_table(undef,undef,$context,
1694: undef,$formname,$permission);
1695: my $rowtitle = 'Section';
1.375 raeburn 1696: my $secbox = '<h3>'.&mt('Section and Credits').'</h3>'."\n".
1.213 raeburn 1697: &Apache::lonuserutils::section_picker($cdom,$cnum,'st',$rowtitle,
1.375 raeburn 1698: $permission,$context,'',$crstype,
1699: $showcredits,$credits);
1.213 raeburn 1700: my $output = $date_table.$secbox;
1701: return $output;
1702: }
1703:
1.216 raeburn 1704: sub validation_javascript {
1.375 raeburn 1705: my ($context,$ccdomain,$pjump_def,$crstype,$groupslist,$newuser,$formname,
1.216 raeburn 1706: $loaditem) = @_;
1707: my $dc_setcourse_code = '';
1708: my $nondc_setsection_code = '';
1709: if ($context eq 'domain') {
1710: my $dcdom = $env{'request.role.domain'};
1711: $loaditem->{'onload'} = "document.cu.coursedesc.value='';";
1.227 raeburn 1712: $dc_setcourse_code =
1713: &Apache::lonuserutils::dc_setcourse_js('cu','singleuser',$context);
1.216 raeburn 1714: } else {
1.227 raeburn 1715: my $checkauth;
1716: if (($newuser) || (&Apache::lonnet::allowed('mau',$ccdomain))) {
1717: $checkauth = 1;
1718: }
1719: if ($context eq 'course') {
1720: $nondc_setsection_code =
1721: &Apache::lonuserutils::setsections_javascript($formname,$groupslist,
1.375 raeburn 1722: undef,$checkauth,
1723: $crstype);
1.227 raeburn 1724: }
1725: if ($checkauth) {
1726: $nondc_setsection_code .=
1727: &Apache::lonuserutils::verify_authen($formname,$context);
1728: }
1.216 raeburn 1729: }
1730: my $js = &user_modification_js($pjump_def,$dc_setcourse_code,
1731: $nondc_setsection_code,$groupslist);
1732: my ($jsback,$elements) = &crumb_utilities();
1733: $js .= "\n".
1.301 bisitz 1734: '<script type="text/javascript">'."\n".
1735: '// <![CDATA['."\n".
1736: $jsback."\n".
1737: '// ]]>'."\n".
1738: '</script>'."\n";
1.216 raeburn 1739: return $js;
1740: }
1741:
1.217 raeburn 1742: sub display_existing_roles {
1.375 raeburn 1743: my ($r,$ccuname,$ccdomain,$inccourses,$context,$roledom,$crstype,
1.418 raeburn 1744: $showcredits,$statuses) = @_;
1.329 raeburn 1745: my $now=time;
1.418 raeburn 1746: my $showall = 1;
1747: my ($showexpired,$showactive);
1748: if ((ref($statuses) eq 'ARRAY') && (@{$statuses} > 0)) {
1749: $showall = 0;
1750: if (grep(/^expired$/,@{$statuses})) {
1751: $showexpired = 1;
1752: }
1753: if (grep(/^active$/,@{$statuses})) {
1754: $showactive = 1;
1755: }
1756: if ($showexpired && $showactive) {
1757: $showall = 1;
1758: }
1759: }
1.329 raeburn 1760: my %lt=&Apache::lonlocal::texthash(
1.217 raeburn 1761: 'rer' => "Existing Roles",
1762: 'rev' => "Revoke",
1763: 'del' => "Delete",
1764: 'ren' => "Re-Enable",
1765: 'rol' => "Role",
1766: 'ext' => "Extent",
1.375 raeburn 1767: 'crd' => "Credits",
1.217 raeburn 1768: 'sta' => "Start",
1769: 'end' => "End",
1770: );
1.329 raeburn 1771: my (%rolesdump,%roletext,%sortrole,%roleclass,%rolepriv);
1772: if ($context eq 'course' || $context eq 'author') {
1773: my @roles = &Apache::lonuserutils::roles_by_context($context,1,$crstype);
1774: my %roleshash =
1775: &Apache::lonnet::get_my_roles($ccuname,$ccdomain,'userroles',
1776: ['active','previous','future'],\@roles,$roledom,1);
1777: foreach my $key (keys(%roleshash)) {
1778: my ($start,$end) = split(':',$roleshash{$key});
1779: next if ($start eq '-1' || $end eq '-1');
1780: my ($rnum,$rdom,$role,$sec) = split(':',$key);
1781: if ($context eq 'course') {
1782: next unless (($rnum eq $env{'course.'.$env{'request.course.id'}.'.num'})
1783: && ($rdom eq $env{'course.'.$env{'request.course.id'}.'.domain'}));
1784: } elsif ($context eq 'author') {
1785: next unless (($rnum eq $env{'user.name'}) && ($rdom eq $env{'request.role.domain'}));
1786: }
1787: my ($newkey,$newvalue,$newrole);
1788: $newkey = '/'.$rdom.'/'.$rnum;
1789: if ($sec ne '') {
1790: $newkey .= '/'.$sec;
1791: }
1792: $newvalue = $role;
1793: if ($role =~ /^cr/) {
1794: $newrole = 'cr';
1795: } else {
1796: $newrole = $role;
1797: }
1798: $newkey .= '_'.$newrole;
1799: if ($start ne '' && $end ne '') {
1800: $newvalue .= '_'.$end.'_'.$start;
1.335 raeburn 1801: } elsif ($end ne '') {
1802: $newvalue .= '_'.$end;
1.329 raeburn 1803: }
1804: $rolesdump{$newkey} = $newvalue;
1805: }
1806: } else {
1.360 raeburn 1807: %rolesdump=&Apache::lonnet::dump('roles',$ccdomain,$ccuname);
1.329 raeburn 1808: }
1809: # Build up table of user roles to allow revocation and re-enabling of roles.
1810: my ($tmp) = keys(%rolesdump);
1811: return if ($tmp =~ /^(con_lost|error)/i);
1812: foreach my $area (sort { my $a1=join('_',(split('_',$a))[1,0]);
1813: my $b1=join('_',(split('_',$b))[1,0]);
1814: return $a1 cmp $b1;
1815: } keys(%rolesdump)) {
1816: next if ($area =~ /^rolesdef/);
1817: my $envkey=$area;
1818: my $role = $rolesdump{$area};
1819: my $thisrole=$area;
1820: $area =~ s/\_\w\w$//;
1821: my ($role_code,$role_end_time,$role_start_time) =
1822: split(/_/,$role);
1.418 raeburn 1823: my $active=1;
1824: $active=0 if (($role_end_time) && ($now>$role_end_time));
1825: if ($active) {
1826: next unless($showall || $showactive);
1827: } else {
1828: next unless($showall || $showexpired);
1829: }
1.217 raeburn 1830: # Is this a custom role? Get role owner and title.
1.329 raeburn 1831: my ($croleudom,$croleuname,$croletitle)=
1832: ($role_code=~m{^cr/($match_domain)/($match_username)/(\w+)$});
1833: my $allowed=0;
1834: my $delallowed=0;
1835: my $sortkey=$role_code;
1836: my $class='Unknown';
1.375 raeburn 1837: my $credits='';
1.418 raeburn 1838: my $csec;
1.421 ! raeburn 1839: if ($area =~ m{^/($match_domain)/($match_courseid)}) {
1.329 raeburn 1840: $class='Course';
1841: my ($coursedom,$coursedir) = ($1,$2);
1842: my $cid = $1.'_'.$2;
1843: # $1.'_'.$2 is the course id (eg. 103_12345abcef103l3).
1.421 ! raeburn 1844: next if ($envkey =~ m{^/$match_domain/$match_courseid/[A-Za-z0-9]+_gr$});
1.329 raeburn 1845: my %coursedata=
1846: &Apache::lonnet::coursedescription($cid);
1847: if ($coursedir =~ /^$match_community$/) {
1848: $class='Community';
1849: }
1850: $sortkey.="\0$coursedom";
1851: my $carea;
1852: if (defined($coursedata{'description'})) {
1853: $carea=$coursedata{'description'}.
1854: '<br />'.&mt('Domain').': '.$coursedom.(' 'x8).
1855: &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$coursedir,$coursedom);
1856: $sortkey.="\0".$coursedata{'description'};
1857: } else {
1858: if ($class eq 'Community') {
1859: $carea=&mt('Unavailable community').': '.$area;
1860: $sortkey.="\0".&mt('Unavailable community').': '.$area;
1.217 raeburn 1861: } else {
1862: $carea=&mt('Unavailable course').': '.$area;
1863: $sortkey.="\0".&mt('Unavailable course').': '.$area;
1864: }
1.329 raeburn 1865: }
1866: $sortkey.="\0$coursedir";
1867: $inccourses->{$cid}=1;
1.375 raeburn 1868: if (($showcredits) && ($class eq 'Course') && ($role_code eq 'st')) {
1869: my $defaultcredits = $coursedata{'internal.defaultcredits'};
1870: $credits =
1871: &get_user_credits($ccuname,$ccdomain,$defaultcredits,
1872: $coursedom,$coursedir);
1873: if ($credits eq '') {
1874: $credits = $defaultcredits;
1875: }
1876: }
1.329 raeburn 1877: if ((&Apache::lonnet::allowed('c'.$role_code,$coursedom.'/'.$coursedir)) ||
1878: (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) {
1879: $allowed=1;
1880: }
1881: unless ($allowed) {
1.365 raeburn 1882: my $isowner = &Apache::lonuserutils::is_courseowner($cid,$coursedata{'internal.courseowner'});
1.329 raeburn 1883: if ($isowner) {
1884: if (($role_code eq 'co') && ($class eq 'Community')) {
1885: $allowed = 1;
1886: } elsif (($role_code eq 'cc') && ($class eq 'Course')) {
1887: $allowed = 1;
1888: }
1.217 raeburn 1889: }
1.329 raeburn 1890: }
1891: if ((&Apache::lonnet::allowed('dro',$coursedom)) ||
1892: (&Apache::lonnet::allowed('dro',$ccdomain))) {
1893: $delallowed=1;
1894: }
1.217 raeburn 1895: # - custom role. Needs more info, too
1.329 raeburn 1896: if ($croletitle) {
1897: if (&Apache::lonnet::allowed('ccr',$coursedom.'/'.$coursedir)) {
1898: $allowed=1;
1899: $thisrole.='.'.$role_code;
1.217 raeburn 1900: }
1.329 raeburn 1901: }
1.418 raeburn 1902: if ($area=~m{^/($match_domain/$match_courseid/(\w+))}) {
1903: $csec = $2;
1904: $carea.='<br />'.&mt('Section: [_1]',$csec);
1905: $sortkey.="\0$csec";
1.329 raeburn 1906: if (!$allowed) {
1.418 raeburn 1907: if ($env{'request.course.sec'} eq $csec) {
1908: if (&Apache::lonnet::allowed('c'.$role_code,$1)) {
1.329 raeburn 1909: $allowed = 1;
1.217 raeburn 1910: }
1911: }
1912: }
1.329 raeburn 1913: }
1914: $area=$carea;
1915: } else {
1916: $sortkey.="\0".$area;
1917: # Determine if current user is able to revoke privileges
1918: if ($area=~m{^/($match_domain)/}) {
1919: if ((&Apache::lonnet::allowed('c'.$role_code,$1)) ||
1920: (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) {
1921: $allowed=1;
1.217 raeburn 1922: }
1.329 raeburn 1923: if (((&Apache::lonnet::allowed('dro',$1)) ||
1924: (&Apache::lonnet::allowed('dro',$ccdomain))) &&
1925: ($role_code ne 'dc')) {
1926: $delallowed=1;
1.217 raeburn 1927: }
1.329 raeburn 1928: } else {
1929: if (&Apache::lonnet::allowed('c'.$role_code,'/')) {
1.217 raeburn 1930: $allowed=1;
1931: }
1932: }
1.363 raeburn 1933: if ($role_code eq 'ca' || $role_code eq 'au' || $role_code eq 'aa') {
1.377 raeburn 1934: $class='Authoring Space';
1.329 raeburn 1935: } elsif ($role_code eq 'su') {
1936: $class='System';
1.217 raeburn 1937: } else {
1.329 raeburn 1938: $class='Domain';
1.217 raeburn 1939: }
1.329 raeburn 1940: }
1941: if (($role_code eq 'ca') || ($role_code eq 'aa')) {
1942: $area=~m{/($match_domain)/($match_username)};
1943: if (&Apache::lonuserutils::authorpriv($2,$1)) {
1944: $allowed=1;
1.217 raeburn 1945: } else {
1.329 raeburn 1946: $allowed=0;
1.217 raeburn 1947: }
1.329 raeburn 1948: }
1949: my $row = '';
1.418 raeburn 1950: if ($showall) {
1951: $row.= '<td>';
1952: if (($active) && ($allowed)) {
1953: $row.= '<input type="checkbox" name="rev:'.$thisrole.'" />';
1954: } else {
1955: if ($active) {
1956: $row.=' ';
1957: } else {
1958: $row.=&mt('expired or revoked');
1959: }
1960: }
1961: $row.='</td><td>';
1962: if ($allowed && !$active) {
1963: $row.= '<input type="checkbox" name="ren:'.$thisrole.'" />';
1964: } else {
1965: $row.=' ';
1966: }
1967: $row.='</td><td>';
1968: if ($delallowed) {
1969: $row.= '<input type="checkbox" name="del:'.$thisrole.'" />';
1.217 raeburn 1970: } else {
1.418 raeburn 1971: $row.=' ';
1.217 raeburn 1972: }
1.418 raeburn 1973: $row.= '</td>';
1.329 raeburn 1974: }
1975: my $plaintext='';
1976: if (!$croletitle) {
1.375 raeburn 1977: $plaintext=&Apache::lonnet::plaintext($role_code,$class);
1978: if (($showcredits) && ($credits ne '')) {
1979: $plaintext .= '<br/ ><span class="LC_nobreak">'.
1980: '<span class="LC_fontsize_small">'.
1981: &mt('Credits: [_1]',$credits).
1982: '</span></span>';
1983: }
1.329 raeburn 1984: } else {
1985: $plaintext=
1.395 bisitz 1986: &mt('Custom role [_1][_2]defined by [_3]',
1.346 bisitz 1987: '"'.$croletitle.'"',
1988: '<br />',
1989: $croleuname.':'.$croleudom);
1.329 raeburn 1990: }
1.418 raeburn 1991: $row.= '<td>'.$plaintext.'</td>'.
1992: '<td>'.$area.'</td>'.
1993: '<td>'.($role_start_time?&Apache::lonlocal::locallocaltime($role_start_time)
1994: : ' ' ).'</td>'.
1995: '<td>'.($role_end_time ?&Apache::lonlocal::locallocaltime($role_end_time)
1996: : ' ' ).'</td>';
1.329 raeburn 1997: $sortrole{$sortkey}=$envkey;
1998: $roletext{$envkey}=$row;
1999: $roleclass{$envkey}=$class;
1.418 raeburn 2000: if ($allowed) {
2001: $rolepriv{$envkey}='edit';
2002: } else {
2003: if ($context eq 'domain') {
1.420 raeburn 2004: if ((&Apache::lonnet::allowed('vur',$ccdomain)) &&
1.421 ! raeburn 2005: ($envkey=~m{^/$ccdomain/})) {
1.418 raeburn 2006: $rolepriv{$envkey}='view';
2007: }
2008: } elsif ($context eq 'course') {
2009: if ((&Apache::lonnet::allowed('vcl',$env{'request.course.id'})) ||
2010: ($env{'request.course.sec'} && ($env{'request.course.sec'} eq $csec) &&
2011: &Apache::lonnet::allowed('vcl',$env{'request.course.id'}.'/'.$env{'request.course.sec'}))) {
2012: $rolepriv{$envkey}='view';
2013: }
2014: }
2015: }
1.329 raeburn 2016: } # end of foreach (table building loop)
2017:
2018: my $rolesdisplay = 0;
2019: my %output = ();
1.377 raeburn 2020: foreach my $type ('Authoring Space','Course','Community','Domain','System','Unknown') {
1.329 raeburn 2021: $output{$type} = '';
2022: foreach my $which (sort {uc($a) cmp uc($b)} (keys(%sortrole))) {
2023: if ( ($roleclass{$sortrole{$which}} =~ /^\Q$type\E/ ) && ($rolepriv{$sortrole{$which}}) ) {
2024: $output{$type}.=
2025: &Apache::loncommon::start_data_table_row().
2026: $roletext{$sortrole{$which}}.
2027: &Apache::loncommon::end_data_table_row();
1.217 raeburn 2028: }
1.329 raeburn 2029: }
2030: unless($output{$type} eq '') {
2031: $output{$type} = '<tr class="LC_info_row">'.
2032: "<td align='center' colspan='7'>".&mt($type)."</td></tr>".
2033: $output{$type};
2034: $rolesdisplay = 1;
2035: }
2036: }
2037: if ($rolesdisplay == 1) {
2038: my $contextrole='';
2039: if ($env{'request.course.id'}) {
2040: if (&Apache::loncommon::course_type() eq 'Community') {
2041: $contextrole = &mt('Existing Roles in this Community');
1.290 bisitz 2042: } else {
1.329 raeburn 2043: $contextrole = &mt('Existing Roles in this Course');
1.290 bisitz 2044: }
1.329 raeburn 2045: } elsif ($env{'request.role'} =~ /^au\./) {
1.377 raeburn 2046: $contextrole = &mt('Existing Co-Author Roles in your Authoring Space');
1.329 raeburn 2047: } else {
1.418 raeburn 2048: if ($showall) {
2049: $contextrole = &mt('Existing Roles in this Domain');
2050: } elsif ($showactive) {
2051: $contextrole = &mt('Unexpired Roles in this Domain');
2052: } elsif ($showexpired) {
2053: $contextrole = &mt('Expired or Revoked Roles in this Domain');
2054: }
1.329 raeburn 2055: }
1.393 raeburn 2056: $r->print('<div class="LC_left_float">'.
1.375 raeburn 2057: '<fieldset><legend>'.$contextrole.'</legend>'.
1.217 raeburn 2058: &Apache::loncommon::start_data_table("LC_createuser").
1.418 raeburn 2059: &Apache::loncommon::start_data_table_header_row());
2060: if ($showall) {
2061: $r->print(
1.419 raeburn 2062: '<th>'.$lt{'rev'}.'</th><th>'.$lt{'ren'}.'</th><th>'.$lt{'del'}.'</th>'
1.418 raeburn 2063: );
2064: } elsif ($showexpired) {
2065: $r->print('<th>'.$lt{'rev'}.'</th>');
2066: }
2067: $r->print(
1.419 raeburn 2068: '<th>'.$lt{'rol'}.'</th><th>'.$lt{'ext'}.'</th>'.
2069: '<th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'.
1.217 raeburn 2070: &Apache::loncommon::end_data_table_header_row());
1.377 raeburn 2071: foreach my $type ('Authoring Space','Course','Community','Domain','System','Unknown') {
1.329 raeburn 2072: if ($output{$type}) {
2073: $r->print($output{$type}."\n");
1.217 raeburn 2074: }
2075: }
1.375 raeburn 2076: $r->print(&Apache::loncommon::end_data_table().
2077: '</fieldset></div>');
1.329 raeburn 2078: }
1.217 raeburn 2079: return;
2080: }
2081:
1.218 raeburn 2082: sub new_coauthor_roles {
2083: my ($r,$ccuname,$ccdomain) = @_;
2084: my $addrolesdisplay = 0;
2085: #
2086: # Co-Author
2087: #
2088: if (&Apache::lonuserutils::authorpriv($env{'user.name'},
2089: $env{'request.role.domain'}) &&
2090: ($env{'user.name'} ne $ccuname || $env{'user.domain'} ne $ccdomain)) {
2091: # No sense in assigning co-author role to yourself
2092: $addrolesdisplay = 1;
2093: my $cuname=$env{'user.name'};
2094: my $cudom=$env{'request.role.domain'};
2095: my %lt=&Apache::lonlocal::texthash(
1.377 raeburn 2096: 'cs' => "Authoring Space",
1.218 raeburn 2097: 'act' => "Activate",
2098: 'rol' => "Role",
2099: 'ext' => "Extent",
2100: 'sta' => "Start",
2101: 'end' => "End",
2102: 'cau' => "Co-Author",
2103: 'caa' => "Assistant Co-Author",
2104: 'ssd' => "Set Start Date",
2105: 'sed' => "Set End Date"
2106: );
2107: $r->print('<h4>'.$lt{'cs'}.'</h4>'."\n".
2108: &Apache::loncommon::start_data_table()."\n".
2109: &Apache::loncommon::start_data_table_header_row()."\n".
2110: '<th>'.$lt{'act'}.'</th><th>'.$lt{'rol'}.'</th>'.
2111: '<th>'.$lt{'ext'}.'</th><th>'.$lt{'sta'}.'</th>'.
2112: '<th>'.$lt{'end'}.'</th>'."\n".
2113: &Apache::loncommon::end_data_table_header_row()."\n".
2114: &Apache::loncommon::start_data_table_row().'
2115: <td>
1.291 bisitz 2116: <input type="checkbox" name="act_'.$cudom.'_'.$cuname.'_ca" />
1.218 raeburn 2117: </td>
2118: <td>'.$lt{'cau'}.'</td>
2119: <td>'.$cudom.'_'.$cuname.'</td>
2120: <td><input type="hidden" name="start_'.$cudom.'_'.$cuname.'_ca" value="" />
2121: <a href=
2122: "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>
2123: <td><input type="hidden" name="end_'.$cudom.'_'.$cuname.'_ca" value="" />
2124: <a href=
2125: "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".
2126: &Apache::loncommon::end_data_table_row()."\n".
2127: &Apache::loncommon::start_data_table_row()."\n".
1.291 bisitz 2128: '<td><input type="checkbox" name="act_'.$cudom.'_'.$cuname.'_aa" /></td>
1.218 raeburn 2129: <td>'.$lt{'caa'}.'</td>
2130: <td>'.$cudom.'_'.$cuname.'</td>
2131: <td><input type="hidden" name="start_'.$cudom.'_'.$cuname.'_aa" value="" />
2132: <a href=
2133: "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>
2134: <td><input type="hidden" name="end_'.$cudom.'_'.$cuname.'_aa" value="" />
2135: <a href=
2136: "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".
2137: &Apache::loncommon::end_data_table_row()."\n".
2138: &Apache::loncommon::end_data_table());
2139: } elsif ($env{'request.role'} =~ /^au\./) {
2140: if (!(&Apache::lonuserutils::authorpriv($env{'user.name'},
2141: $env{'request.role.domain'}))) {
2142: $r->print('<span class="LC_error">'.
2143: &mt('You do not have privileges to assign co-author roles.').
2144: '</span>');
2145: } elsif (($env{'user.name'} eq $ccuname) &&
2146: ($env{'user.domain'} eq $ccdomain)) {
1.377 raeburn 2147: $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 2148: }
2149: }
2150: return $addrolesdisplay;;
2151: }
2152:
2153: sub new_domain_roles {
1.357 raeburn 2154: my ($r,$ccdomain) = @_;
1.218 raeburn 2155: my $addrolesdisplay = 0;
2156: #
2157: # Domain level
2158: #
2159: my $num_domain_level = 0;
2160: my $domaintext =
2161: '<h4>'.&mt('Domain Level').'</h4>'.
2162: &Apache::loncommon::start_data_table().
2163: &Apache::loncommon::start_data_table_header_row().
2164: '<th>'.&mt('Activate').'</th><th>'.&mt('Role').'</th><th>'.
2165: &mt('Extent').'</th>'.
2166: '<th>'.&mt('Start').'</th><th>'.&mt('End').'</th>'.
2167: &Apache::loncommon::end_data_table_header_row();
1.312 raeburn 2168: my @allroles = &Apache::lonuserutils::roles_by_context('domain');
1.218 raeburn 2169: foreach my $thisdomain (sort(&Apache::lonnet::all_domains())) {
1.312 raeburn 2170: foreach my $role (@allroles) {
2171: next if ($role eq 'ad');
1.357 raeburn 2172: next if (($role eq 'au') && ($ccdomain ne $thisdomain));
1.218 raeburn 2173: if (&Apache::lonnet::allowed('c'.$role,$thisdomain)) {
2174: my $plrole=&Apache::lonnet::plaintext($role);
2175: my %lt=&Apache::lonlocal::texthash(
2176: 'ssd' => "Set Start Date",
2177: 'sed' => "Set End Date"
2178: );
2179: $num_domain_level ++;
2180: $domaintext .=
2181: &Apache::loncommon::start_data_table_row().
1.291 bisitz 2182: '<td><input type="checkbox" name="act_'.$thisdomain.'_'.$role.'" /></td>
1.218 raeburn 2183: <td>'.$plrole.'</td>
2184: <td>'.$thisdomain.'</td>
2185: <td><input type="hidden" name="start_'.$thisdomain.'_'.$role.'" value="" />
2186: <a href=
2187: "javascript:pjump('."'date_start','Start Date $plrole',document.cu.start_$thisdomain\_$role.value,'start_$thisdomain\_$role','cu.pres','dateset'".')">'.$lt{'ssd'}.'</a></td>
2188: <td><input type="hidden" name="end_'.$thisdomain.'_'.$role.'" value="" />
2189: <a href=
2190: "javascript:pjump('."'date_end','End Date $plrole',document.cu.end_$thisdomain\_$role.value,'end_$thisdomain\_$role','cu.pres','dateset'".')">'.$lt{'sed'}.'</a></td>'.
2191: &Apache::loncommon::end_data_table_row();
2192: }
2193: }
2194: }
2195: $domaintext.= &Apache::loncommon::end_data_table();
2196: if ($num_domain_level > 0) {
2197: $r->print($domaintext);
2198: $addrolesdisplay = 1;
2199: }
2200: return $addrolesdisplay;
2201: }
2202:
1.188 raeburn 2203: sub user_authentication {
1.227 raeburn 2204: my ($ccuname,$ccdomain,$formname) = @_;
1.188 raeburn 2205: my $currentauth=&Apache::lonnet::queryauthenticate($ccuname,$ccdomain);
1.227 raeburn 2206: my $outcome;
1.418 raeburn 2207: my %lt=&Apache::lonlocal::texthash(
2208: 'err' => "ERROR",
2209: 'uuas' => "This user has an unrecognized authentication scheme",
2210: 'adcs' => "Please alert a domain coordinator of this situation",
2211: 'sldb' => "Please specify login data below",
2212: 'ld' => "Login Data"
2213: );
1.188 raeburn 2214: # Check for a bad authentication type
2215: if ($currentauth !~ /^(krb4|krb5|unix|internal|localauth):/) {
2216: # bad authentication scheme
2217: if (&Apache::lonnet::allowed('mau',$ccdomain)) {
1.227 raeburn 2218: &initialize_authen_forms($ccdomain,$formname);
2219:
1.190 raeburn 2220: my $choices = &Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc);
1.188 raeburn 2221: $outcome = <<ENDBADAUTH;
2222: <script type="text/javascript" language="Javascript">
1.301 bisitz 2223: // <![CDATA[
1.188 raeburn 2224: $loginscript
1.301 bisitz 2225: // ]]>
1.188 raeburn 2226: </script>
2227: <span class="LC_error">$lt{'err'}:
2228: $lt{'uuas'} ($currentauth). $lt{'sldb'}.</span>
2229: <h3>$lt{'ld'}</h3>
2230: $choices
2231: ENDBADAUTH
2232: } else {
2233: # This user is not allowed to modify the user's
2234: # authentication scheme, so just notify them of the problem
2235: $outcome = <<ENDBADAUTH;
2236: <span class="LC_error"> $lt{'err'}:
2237: $lt{'uuas'} ($currentauth). $lt{'adcs'}.
2238: </span>
2239: ENDBADAUTH
2240: }
2241: } else { # Authentication type is valid
1.418 raeburn 2242:
1.227 raeburn 2243: &initialize_authen_forms($ccdomain,$formname,$currentauth,'modifyuser');
1.205 raeburn 2244: my ($authformcurrent,$can_modify,@authform_others) =
1.188 raeburn 2245: &modify_login_block($ccdomain,$currentauth);
2246: if (&Apache::lonnet::allowed('mau',$ccdomain)) {
2247: # Current user has login modification privileges
2248: $outcome =
2249: '<script type="text/javascript" language="Javascript">'."\n".
1.301 bisitz 2250: '// <![CDATA['."\n".
1.188 raeburn 2251: $loginscript."\n".
1.301 bisitz 2252: '// ]]>'."\n".
1.188 raeburn 2253: '</script>'."\n".
2254: '<h3>'.$lt{'ld'}.'</h3>'.
2255: &Apache::loncommon::start_data_table().
1.205 raeburn 2256: &Apache::loncommon::start_data_table_row().
1.188 raeburn 2257: '<td>'.$authformnop;
1.418 raeburn 2258: if (($can_modify) && (&Apache::lonnet::allowed('mau',$ccdomain))) {
1.188 raeburn 2259: $outcome .= '</td>'."\n".
2260: &Apache::loncommon::end_data_table_row().
2261: &Apache::loncommon::start_data_table_row().
2262: '<td>'.$authformcurrent.'</td>'.
2263: &Apache::loncommon::end_data_table_row()."\n";
2264: } else {
1.200 raeburn 2265: $outcome .= ' ('.$authformcurrent.')</td>'.
2266: &Apache::loncommon::end_data_table_row()."\n";
1.188 raeburn 2267: }
1.418 raeburn 2268: if (&Apache::lonnet::allowed('mau',$ccdomain)) {
2269: foreach my $item (@authform_others) {
2270: $outcome .= &Apache::loncommon::start_data_table_row().
2271: '<td>'.$item.'</td>'.
2272: &Apache::loncommon::end_data_table_row()."\n";
2273: }
1.188 raeburn 2274: }
1.205 raeburn 2275: $outcome .= &Apache::loncommon::end_data_table();
1.188 raeburn 2276: } else {
1.418 raeburn 2277: if (&Apache::lonnet::allowed('udp',$ccdomain)) {
2278: # Current user has rights to view domain preferences for user's domain
2279: my $result;
2280: if ($currentauth =~ /^krb(4|5):([^:]*)$/) {
2281: my ($krbver,$krbrealm) = ($1,$2);
2282: if ($krbrealm eq '') {
2283: $result = &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
2284: } else {
2285: $result = &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
2286: $krbver,$krbrealm);
2287: }
2288: } elsif ($currentauth =~ /^internal:/) {
2289: $result = &mt('Currently internally authenticated.');
2290: } elsif ($currentauth =~ /^localauth:/) {
2291: $result = &mt('Currently using local (institutional) authentication.');
2292: } elsif ($currentauth =~ /^unix:/) {
2293: $result = &mt('Currently Filesystem Authenticated.');
2294: }
2295: $outcome = '<h3>'.$lt{'ld'}.'</h3>'.
2296: &Apache::loncommon::start_data_table().
2297: &Apache::loncommon::start_data_table_row().
2298: '<td>'.$result.'</td>'.
2299: &Apache::loncommon::end_data_table_row()."\n".
2300: &Apache::loncommon::end_data_table();
2301: } elsif (&Apache::lonnet::allowed('mau',$env{'request.role.domain'})) {
1.188 raeburn 2302: my %lt=&Apache::lonlocal::texthash(
2303: 'ccld' => "Change Current Login Data",
2304: 'yodo' => "You do not have privileges to modify the authentication configuration for this user.",
2305: 'ifch' => "If a change is required, contact a domain coordinator for the domain",
2306: );
2307: $outcome .= <<ENDNOPRIV;
2308: <h3>$lt{'ccld'}</h3>
2309: $lt{'yodo'} $lt{'ifch'}: $ccdomain
1.235 raeburn 2310: <input type="hidden" name="login" value="nochange" />
1.188 raeburn 2311: ENDNOPRIV
2312: }
2313: }
2314: } ## End of "check for bad authentication type" logic
2315: return $outcome;
2316: }
2317:
1.187 raeburn 2318: sub modify_login_block {
2319: my ($dom,$currentauth) = @_;
2320: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
2321: my ($authnum,%can_assign) =
2322: &Apache::loncommon::get_assignable_auth($dom);
1.205 raeburn 2323: my ($authformcurrent,@authform_others,$show_override_msg);
1.187 raeburn 2324: if ($currentauth=~/^krb(4|5):/) {
2325: $authformcurrent=$authformkrb;
2326: if ($can_assign{'int'}) {
1.205 raeburn 2327: push(@authform_others,$authformint);
1.187 raeburn 2328: }
2329: if ($can_assign{'loc'}) {
1.205 raeburn 2330: push(@authform_others,$authformloc);
1.187 raeburn 2331: }
2332: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
2333: $show_override_msg = 1;
2334: }
2335: } elsif ($currentauth=~/^internal:/) {
2336: $authformcurrent=$authformint;
2337: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205 raeburn 2338: push(@authform_others,$authformkrb);
1.187 raeburn 2339: }
2340: if ($can_assign{'loc'}) {
1.205 raeburn 2341: push(@authform_others,$authformloc);
1.187 raeburn 2342: }
2343: if ($can_assign{'int'}) {
2344: $show_override_msg = 1;
2345: }
2346: } elsif ($currentauth=~/^unix:/) {
2347: $authformcurrent=$authformfsys;
2348: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205 raeburn 2349: push(@authform_others,$authformkrb);
1.187 raeburn 2350: }
2351: if ($can_assign{'int'}) {
1.205 raeburn 2352: push(@authform_others,$authformint);
1.187 raeburn 2353: }
2354: if ($can_assign{'loc'}) {
1.205 raeburn 2355: push(@authform_others,$authformloc);
1.187 raeburn 2356: }
2357: if ($can_assign{'fsys'}) {
2358: $show_override_msg = 1;
2359: }
2360: } elsif ($currentauth=~/^localauth:/) {
2361: $authformcurrent=$authformloc;
2362: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205 raeburn 2363: push(@authform_others,$authformkrb);
1.187 raeburn 2364: }
2365: if ($can_assign{'int'}) {
1.205 raeburn 2366: push(@authform_others,$authformint);
1.187 raeburn 2367: }
2368: if ($can_assign{'loc'}) {
2369: $show_override_msg = 1;
2370: }
2371: }
2372: if ($show_override_msg) {
1.205 raeburn 2373: $authformcurrent = '<table><tr><td colspan="3">'.$authformcurrent.
2374: '</td></tr>'."\n".
2375: '<tr><td> </td>'.
2376: '<td><b>'.&mt('Currently in use').'</b></td>'.
2377: '<td align="right"><span class="LC_cusr_emph">'.
1.187 raeburn 2378: &mt('will override current values').
1.205 raeburn 2379: '</span></td></tr></table>';
1.187 raeburn 2380: }
1.205 raeburn 2381: return ($authformcurrent,$show_override_msg,@authform_others);
1.187 raeburn 2382: }
2383:
1.188 raeburn 2384: sub personal_data_display {
1.391 raeburn 2385: my ($ccuname,$ccdomain,$newuser,$context,$inst_results,$rolesarray,
1.410 raeburn 2386: $now,$captchaform,$emailusername,$usertype) = @_;
1.388 bisitz 2387: my ($output,%userenv,%canmodify,%canmodify_status);
1.219 raeburn 2388: my @userinfo = ('firstname','middlename','lastname','generation',
2389: 'permanentemail','id');
1.252 raeburn 2390: my $rowcount = 0;
2391: my $editable = 0;
1.391 raeburn 2392: my %textboxsize = (
2393: firstname => '15',
2394: middlename => '15',
2395: lastname => '15',
2396: generation => '5',
2397: permanentemail => '25',
2398: id => '15',
2399: );
2400:
2401: my %lt=&Apache::lonlocal::texthash(
2402: 'pd' => "Personal Data",
2403: 'firstname' => "First Name",
2404: 'middlename' => "Middle Name",
2405: 'lastname' => "Last Name",
2406: 'generation' => "Generation",
2407: 'permanentemail' => "Permanent e-mail address",
2408: 'id' => "Student/Employee ID",
2409: 'lg' => "Login Data",
2410: 'inststatus' => "Affiliation",
2411: 'email' => 'E-mail address',
2412: 'valid' => 'Validation',
2413: );
2414:
2415: %canmodify_status =
1.286 raeburn 2416: &Apache::lonuserutils::can_modify_userinfo($context,$ccdomain,
2417: ['inststatus'],$rolesarray);
1.253 raeburn 2418: if (!$newuser) {
1.188 raeburn 2419: # Get the users information
2420: %userenv = &Apache::lonnet::get('environment',
2421: ['firstname','middlename','lastname','generation',
1.286 raeburn 2422: 'permanentemail','id','inststatus'],$ccdomain,$ccuname);
1.219 raeburn 2423: %canmodify =
2424: &Apache::lonuserutils::can_modify_userinfo($context,$ccdomain,
1.252 raeburn 2425: \@userinfo,$rolesarray);
1.257 raeburn 2426: } elsif ($context eq 'selfcreate') {
1.391 raeburn 2427: if ($newuser eq 'email') {
1.396 raeburn 2428: if (ref($emailusername) eq 'HASH') {
2429: if (ref($emailusername->{$usertype}) eq 'HASH') {
2430: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
2431: @userinfo = ();
2432: if ((ref($infofields) eq 'ARRAY') && (ref($infotitles) eq 'HASH')) {
2433: foreach my $field (@{$infofields}) {
2434: if ($emailusername->{$usertype}->{$field}) {
2435: push(@userinfo,$field);
2436: $canmodify{$field} = 1;
2437: unless ($textboxsize{$field}) {
2438: $textboxsize{$field} = 25;
2439: }
2440: unless ($lt{$field}) {
2441: $lt{$field} = $infotitles->{$field};
2442: }
2443: if ($emailusername->{$usertype}->{$field} eq 'required') {
2444: $lt{$field} .= '<b>*</b>';
2445: }
1.391 raeburn 2446: }
2447: }
2448: }
2449: }
2450: }
2451: } else {
2452: %canmodify = &selfcreate_canmodify($context,$ccdomain,\@userinfo,
2453: $inst_results,$rolesarray);
2454: }
1.188 raeburn 2455: }
1.391 raeburn 2456:
1.188 raeburn 2457: my $genhelp=&Apache::loncommon::help_open_topic('Generation');
2458: $output = '<h3>'.$lt{'pd'}.'</h3>'.
2459: &Apache::lonhtmlcommon::start_pick_box();
1.391 raeburn 2460: if (($context eq 'selfcreate') && ($newuser eq 'email')) {
1.396 raeburn 2461: $output .= &Apache::lonhtmlcommon::row_title($lt{'email'}.'<b>*</b>',undef,
1.391 raeburn 2462: 'LC_oddrow_value')."\n".
1.394 raeburn 2463: '<input type="text" name="uname" size="25" value="" autocomplete="off" />';
1.391 raeburn 2464: $rowcount ++;
2465: $output .= &Apache::lonhtmlcommon::row_closure(1);
1.408 raeburn 2466: my $upassone = '<input type="password" name="upass'.$now.'" size="20" autocomplete="off" />';
2467: my $upasstwo = '<input type="password" name="upasscheck'.$now.'" size="20" autocomplete="off" />';
1.396 raeburn 2468: $output .= &Apache::lonhtmlcommon::row_title(&mt('Password').'<b>*</b>',
1.391 raeburn 2469: 'LC_pick_box_title',
2470: 'LC_oddrow_value')."\n".
2471: $upassone."\n".
2472: &Apache::lonhtmlcommon::row_closure(1)."\n".
1.396 raeburn 2473: &Apache::lonhtmlcommon::row_title(&mt('Confirm password').'<b>*</b>',
1.391 raeburn 2474: 'LC_pick_box_title',
2475: 'LC_oddrow_value')."\n".
2476: $upasstwo.
2477: &Apache::lonhtmlcommon::row_closure()."\n";
2478: }
1.188 raeburn 2479: foreach my $item (@userinfo) {
2480: my $rowtitle = $lt{$item};
1.252 raeburn 2481: my $hiderow = 0;
1.188 raeburn 2482: if ($item eq 'generation') {
2483: $rowtitle = $genhelp.$rowtitle;
2484: }
1.252 raeburn 2485: my $row = &Apache::lonhtmlcommon::row_title($rowtitle,undef,'LC_oddrow_value')."\n";
1.188 raeburn 2486: if ($newuser) {
1.210 raeburn 2487: if (ref($inst_results) eq 'HASH') {
2488: if ($inst_results->{$item} ne '') {
1.252 raeburn 2489: $row .= '<input type="hidden" name="c'.$item.'" value="'.$inst_results->{$item}.'" />'.$inst_results->{$item};
1.210 raeburn 2490: } else {
1.252 raeburn 2491: if ($context eq 'selfcreate') {
1.391 raeburn 2492: if ($canmodify{$item}) {
1.394 raeburn 2493: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" autocomplete="off" />';
1.252 raeburn 2494: $editable ++;
2495: } else {
2496: $hiderow = 1;
2497: }
1.253 raeburn 2498: } else {
2499: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
1.252 raeburn 2500: }
1.210 raeburn 2501: }
1.188 raeburn 2502: } else {
1.252 raeburn 2503: if ($context eq 'selfcreate') {
1.401 raeburn 2504: if ($canmodify{$item}) {
2505: if ($newuser eq 'email') {
2506: $row .= '<input type="text" name="'.$item.'" size="'.$textboxsize{$item}.'" value="" autocomplete="off" />';
1.287 raeburn 2507: } else {
1.401 raeburn 2508: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" autocomplete="off" />';
1.287 raeburn 2509: }
1.401 raeburn 2510: $editable ++;
2511: } else {
2512: $hiderow = 1;
1.252 raeburn 2513: }
1.253 raeburn 2514: } else {
2515: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
1.252 raeburn 2516: }
1.188 raeburn 2517: }
2518: } else {
1.219 raeburn 2519: if ($canmodify{$item}) {
1.252 raeburn 2520: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="'.$userenv{$item}.'" />';
1.393 raeburn 2521: if (($item eq 'id') && (!$newuser)) {
2522: $row .= '<br />'.&Apache::lonuserutils::forceid_change($context);
2523: }
1.188 raeburn 2524: } else {
1.252 raeburn 2525: $row .= $userenv{$item};
1.188 raeburn 2526: }
2527: }
1.252 raeburn 2528: $row .= &Apache::lonhtmlcommon::row_closure(1);
2529: if (!$hiderow) {
2530: $output .= $row;
2531: $rowcount ++;
2532: }
1.188 raeburn 2533: }
1.286 raeburn 2534: if (($canmodify_status{'inststatus'}) || ($context ne 'selfcreate')) {
2535: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($ccdomain);
2536: if (ref($types) eq 'ARRAY') {
2537: if (@{$types} > 0) {
2538: my ($hiderow,$shown);
2539: if ($canmodify_status{'inststatus'}) {
2540: $shown = &pick_inst_statuses($userenv{'inststatus'},$usertypes,$types);
2541: } else {
2542: if ($userenv{'inststatus'} eq '') {
2543: $hiderow = 1;
1.334 raeburn 2544: } else {
2545: my @showitems;
2546: foreach my $item ( map { &unescape($_); } split(':',$userenv{'inststatus'})) {
2547: if (exists($usertypes->{$item})) {
2548: push(@showitems,$usertypes->{$item});
2549: } else {
2550: push(@showitems,$item);
2551: }
2552: }
2553: if (@showitems) {
2554: $shown = join(', ',@showitems);
2555: } else {
2556: $hiderow = 1;
2557: }
1.286 raeburn 2558: }
2559: }
2560: if (!$hiderow) {
1.389 bisitz 2561: my $row = &Apache::lonhtmlcommon::row_title(&mt('Affiliations'),undef,'LC_oddrow_value')."\n".
1.286 raeburn 2562: $shown.&Apache::lonhtmlcommon::row_closure(1);
2563: if ($context eq 'selfcreate') {
2564: $rowcount ++;
2565: }
2566: $output .= $row;
2567: }
2568: }
2569: }
2570: }
1.391 raeburn 2571: if (($context eq 'selfcreate') && ($newuser eq 'email')) {
2572: if ($captchaform) {
1.410 raeburn 2573: $output .= &Apache::lonhtmlcommon::row_title($lt{'valid'}.'*',
2574: 'LC_pick_box_title')."\n".
2575: $captchaform."\n".'<br /><br />'.
1.391 raeburn 2576: &Apache::lonhtmlcommon::row_closure(1);
2577: $rowcount ++;
2578: }
2579: my $submit_text = &mt('Create account');
2580: $output .= &Apache::lonhtmlcommon::row_title()."\n".
2581: '<br /><input type="submit" name="createaccount" value="'.
2582: $submit_text.'" />'.
1.396 raeburn 2583: '<input type="hidden" name="type" value="'.$usertype.'" />'.
1.391 raeburn 2584: &Apache::lonhtmlcommon::row_closure(1);
2585: }
1.188 raeburn 2586: $output .= &Apache::lonhtmlcommon::end_pick_box();
1.206 raeburn 2587: if (wantarray) {
1.252 raeburn 2588: if ($context eq 'selfcreate') {
2589: return($output,$rowcount,$editable);
2590: } else {
1.388 bisitz 2591: return $output;
1.252 raeburn 2592: }
1.206 raeburn 2593: } else {
2594: return $output;
2595: }
1.188 raeburn 2596: }
2597:
1.286 raeburn 2598: sub pick_inst_statuses {
2599: my ($curr,$usertypes,$types) = @_;
2600: my ($output,$rem,@currtypes);
2601: if ($curr ne '') {
2602: @currtypes = map { &unescape($_); } split(/:/,$curr);
2603: }
2604: my $numinrow = 2;
2605: if (ref($types) eq 'ARRAY') {
2606: $output = '<table>';
2607: my $lastcolspan;
2608: for (my $i=0; $i<@{$types}; $i++) {
2609: if (defined($usertypes->{$types->[$i]})) {
2610: my $rem = $i%($numinrow);
2611: if ($rem == 0) {
2612: if ($i<@{$types}-1) {
2613: if ($i > 0) {
2614: $output .= '</tr>';
2615: }
2616: $output .= '<tr>';
2617: }
2618: } elsif ($i==@{$types}-1) {
2619: my $colsleft = $numinrow - $rem;
2620: if ($colsleft > 1) {
2621: $lastcolspan = ' colspan="'.$colsleft.'"';
2622: }
2623: }
2624: my $check = ' ';
2625: if (grep(/^\Q$types->[$i]\E$/,@currtypes)) {
2626: $check = ' checked="checked" ';
2627: }
2628: $output .= '<td class="LC_left_item"'.$lastcolspan.'>'.
2629: '<span class="LC_nobreak"><label>'.
2630: '<input type="checkbox" name="inststatus" '.
2631: 'value="'.$types->[$i].'"'.$check.'/>'.
2632: $usertypes->{$types->[$i]}.'</label></span></td>';
2633: }
2634: }
2635: $output .= '</tr></table>';
2636: }
2637: return $output;
2638: }
2639:
1.257 raeburn 2640: sub selfcreate_canmodify {
2641: my ($context,$dom,$userinfo,$inst_results,$rolesarray) = @_;
2642: if (ref($inst_results) eq 'HASH') {
2643: my @inststatuses = &get_inststatuses($inst_results);
2644: if (@inststatuses == 0) {
2645: @inststatuses = ('default');
2646: }
2647: $rolesarray = \@inststatuses;
2648: }
2649: my %canmodify =
2650: &Apache::lonuserutils::can_modify_userinfo($context,$dom,$userinfo,
2651: $rolesarray);
2652: return %canmodify;
2653: }
2654:
1.252 raeburn 2655: sub get_inststatuses {
2656: my ($insthashref) = @_;
2657: my @inststatuses = ();
2658: if (ref($insthashref) eq 'HASH') {
2659: if (ref($insthashref->{'inststatus'}) eq 'ARRAY') {
2660: @inststatuses = @{$insthashref->{'inststatus'}};
2661: }
2662: }
2663: return @inststatuses;
2664: }
2665:
1.4 www 2666: # ================================================================= Phase Three
1.42 matthew 2667: sub update_user_data {
1.375 raeburn 2668: my ($r,$context,$crstype,$brcrum,$showcredits) = @_;
1.101 albertel 2669: my $uhome=&Apache::lonnet::homeserver($env{'form.ccuname'},
2670: $env{'form.ccdomain'});
1.27 matthew 2671: # Error messages
1.188 raeburn 2672: my $error = '<span class="LC_error">'.&mt('Error').': ';
1.193 raeburn 2673: my $end = '</span><br /><br />';
2674: my $rtnlink = '<a href="javascript:backPage(document.userupdate,'.
1.188 raeburn 2675: "'$env{'form.prevphase'}','modify')".'" />'.
1.219 raeburn 2676: &mt('Return to previous page').'</a>'.
2677: &Apache::loncommon::end_page();
2678: my $now = time;
1.40 www 2679: my $title;
1.101 albertel 2680: if (exists($env{'form.makeuser'})) {
1.40 www 2681: $title='Set Privileges for New User';
2682: } else {
2683: $title='Modify User Privileges';
2684: }
1.213 raeburn 2685: my $newuser = 0;
1.160 raeburn 2686: my ($jsback,$elements) = &crumb_utilities();
2687: my $jscript = '<script type="text/javascript">'."\n".
1.301 bisitz 2688: '// <![CDATA['."\n".
2689: $jsback."\n".
2690: '// ]]>'."\n".
2691: '</script>'."\n";
1.318 raeburn 2692: my %breadcrumb_text = &singleuser_breadcrumb($crstype);
1.351 raeburn 2693: push (@{$brcrum},
2694: {href => "javascript:backPage(document.userupdate)",
2695: text => $breadcrumb_text{'search'},
2696: faq => 282,
2697: bug => 'Instructor Interface',}
2698: );
2699: if ($env{'form.prevphase'} eq 'userpicked') {
2700: push(@{$brcrum},
2701: {href => "javascript:backPage(document.userupdate,'get_user_info','select')",
2702: text => $breadcrumb_text{'userpicked'},
2703: faq => 282,
2704: bug => 'Instructor Interface',});
1.233 raeburn 2705: }
1.224 raeburn 2706: my $helpitem = 'Course_Change_Privileges';
2707: if ($env{'form.action'} eq 'singlestudent') {
2708: $helpitem = 'Course_Add_Student';
2709: }
1.351 raeburn 2710: push(@{$brcrum},
2711: {href => "javascript:backPage(document.userupdate,'$env{'form.prevphase'}','modify')",
2712: text => $breadcrumb_text{'modify'},
2713: faq => 282,
2714: bug => 'Instructor Interface',},
2715: {href => "/adm/createuser",
2716: text => "Result",
2717: faq => 282,
2718: bug => 'Instructor Interface',
2719: help => $helpitem});
2720: my $args = {bread_crumbs => $brcrum,
2721: bread_crumbs_component => 'User Management'};
2722: if ($env{'form.popup'}) {
2723: $args->{'no_nav_bar'} = 1;
2724: }
2725: $r->print(&Apache::loncommon::start_page($title,$jscript,$args));
1.188 raeburn 2726: $r->print(&update_result_form($uhome));
1.27 matthew 2727: # Check Inputs
1.101 albertel 2728: if (! $env{'form.ccuname'} ) {
1.193 raeburn 2729: $r->print($error.&mt('No login name specified').'.'.$end.$rtnlink);
1.27 matthew 2730: return;
2731: }
1.138 albertel 2732: if ( $env{'form.ccuname'} ne
2733: &LONCAPA::clean_username($env{'form.ccuname'}) ) {
1.281 bisitz 2734: $r->print($error.&mt('Invalid login name.').' '.
2735: &mt('Only letters, numbers, periods, dashes, @, and underscores are valid.').
1.193 raeburn 2736: $end.$rtnlink);
1.27 matthew 2737: return;
2738: }
1.101 albertel 2739: if (! $env{'form.ccdomain'} ) {
1.193 raeburn 2740: $r->print($error.&mt('No domain specified').'.'.$end.$rtnlink);
1.27 matthew 2741: return;
2742: }
1.138 albertel 2743: if ( $env{'form.ccdomain'} ne
2744: &LONCAPA::clean_domain($env{'form.ccdomain'}) ) {
1.281 bisitz 2745: $r->print($error.&mt('Invalid domain name.').' '.
2746: &mt('Only letters, numbers, periods, dashes, and underscores are valid.').
1.193 raeburn 2747: $end.$rtnlink);
1.27 matthew 2748: return;
2749: }
1.219 raeburn 2750: if ($uhome eq 'no_host') {
2751: $newuser = 1;
2752: }
1.101 albertel 2753: if (! exists($env{'form.makeuser'})) {
1.29 matthew 2754: # Modifying an existing user, so check the validity of the name
2755: if ($uhome eq 'no_host') {
1.389 bisitz 2756: $r->print(
2757: $error
2758: .'<p class="LC_error">'
2759: .&mt('Unable to determine home server for [_1] in domain [_2].',
2760: '"'.$env{'form.ccuname'}.'"','"'.$env{'form.ccdomain'}.'"')
2761: .'</p>');
1.29 matthew 2762: return;
2763: }
2764: }
1.27 matthew 2765: # Determine authentication method and password for the user being modified
2766: my $amode='';
2767: my $genpwd='';
1.101 albertel 2768: if ($env{'form.login'} eq 'krb') {
1.41 albertel 2769: $amode='krb';
1.101 albertel 2770: $amode.=$env{'form.krbver'};
2771: $genpwd=$env{'form.krbarg'};
2772: } elsif ($env{'form.login'} eq 'int') {
1.27 matthew 2773: $amode='internal';
1.101 albertel 2774: $genpwd=$env{'form.intarg'};
2775: } elsif ($env{'form.login'} eq 'fsys') {
1.27 matthew 2776: $amode='unix';
1.101 albertel 2777: $genpwd=$env{'form.fsysarg'};
2778: } elsif ($env{'form.login'} eq 'loc') {
1.27 matthew 2779: $amode='localauth';
1.101 albertel 2780: $genpwd=$env{'form.locarg'};
1.27 matthew 2781: $genpwd=" " if (!$genpwd);
1.101 albertel 2782: } elsif (($env{'form.login'} eq 'nochange') ||
2783: ($env{'form.login'} eq '' )) {
1.34 matthew 2784: # There is no need to tell the user we did not change what they
2785: # did not ask us to change.
1.35 matthew 2786: # If they are creating a new user but have not specified login
2787: # information this will be caught below.
1.30 matthew 2788: } else {
1.367 golterma 2789: $r->print($error.&mt('Invalid login mode or password').$end.$rtnlink);
2790: return;
1.27 matthew 2791: }
1.164 albertel 2792:
1.188 raeburn 2793: $r->print('<h3>'.&mt('User [_1] in domain [_2]',
1.367 golterma 2794: $env{'form.ccuname'}.' ('.&Apache::loncommon::plainname($env{'form.ccuname'},
2795: $env{'form.ccdomain'}).')', $env{'form.ccdomain'}).'</h3>');
2796: my %prog_state = &Apache::lonhtmlcommon::Create_PrgWin($r,2);
1.344 bisitz 2797:
1.193 raeburn 2798: my (%alerts,%rulematch,%inst_results,%curr_rules);
1.334 raeburn 2799: my @userinfo = ('firstname','middlename','lastname','generation','permanentemail','id');
1.361 raeburn 2800: my @usertools = ('aboutme','blog','webdav','portfolio');
1.411 raeburn 2801: my @requestcourses = ('official','unofficial','community','textbook','placement');
1.362 raeburn 2802: my @requestauthor = ('requestauthor');
1.286 raeburn 2803: my ($othertitle,$usertypes,$types) =
2804: &Apache::loncommon::sorted_inst_types($env{'form.ccdomain'});
1.334 raeburn 2805: my %canmodify_status =
2806: &Apache::lonuserutils::can_modify_userinfo($context,$env{'form.ccdomain'},
2807: ['inststatus']);
1.101 albertel 2808: if ($env{'form.makeuser'}) {
1.164 albertel 2809: $r->print('<h3>'.&mt('Creating new account.').'</h3>');
1.27 matthew 2810: # Check for the authentication mode and password
2811: if (! $amode || ! $genpwd) {
1.193 raeburn 2812: $r->print($error.&mt('Invalid login mode or password').$end.$rtnlink);
1.27 matthew 2813: return;
1.18 albertel 2814: }
1.29 matthew 2815: # Determine desired host
1.101 albertel 2816: my $desiredhost = $env{'form.hserver'};
1.29 matthew 2817: if (lc($desiredhost) eq 'default') {
2818: $desiredhost = undef;
2819: } else {
1.147 albertel 2820: my %home_servers =
2821: &Apache::lonnet::get_servers($env{'form.ccdomain'},'library');
1.29 matthew 2822: if (! exists($home_servers{$desiredhost})) {
1.193 raeburn 2823: $r->print($error.&mt('Invalid home server specified').$end.$rtnlink);
2824: return;
2825: }
2826: }
2827: # Check ID format
2828: my %checkhash;
2829: my %checks = ('id' => 1);
2830: %{$checkhash{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}}} = (
1.219 raeburn 2831: 'newuser' => $newuser,
1.196 raeburn 2832: 'id' => $env{'form.cid'},
1.193 raeburn 2833: );
1.196 raeburn 2834: if ($env{'form.cid'} ne '') {
2835: &Apache::loncommon::user_rule_check(\%checkhash,\%checks,\%alerts,
2836: \%rulematch,\%inst_results,\%curr_rules);
2837: if (ref($alerts{'id'}) eq 'HASH') {
2838: if (ref($alerts{'id'}{$env{'form.ccdomain'}}) eq 'HASH') {
2839: my $domdesc =
2840: &Apache::lonnet::domain($env{'form.ccdomain'},'description');
2841: if ($alerts{'id'}{$env{'form.ccdomain'}}{$env{'form.cid'}}) {
2842: my $userchkmsg;
2843: if (ref($curr_rules{$env{'form.ccdomain'}}) eq 'HASH') {
2844: $userchkmsg =
2845: &Apache::loncommon::instrule_disallow_msg('id',
2846: $domdesc,1).
2847: &Apache::loncommon::user_rule_formats($env{'form.ccdomain'},
2848: $domdesc,$curr_rules{$env{'form.ccdomain'}}{'id'},'id');
2849: }
2850: $r->print($error.&mt('Invalid ID format').$end.
2851: $userchkmsg.$rtnlink);
2852: return;
2853: }
2854: }
1.29 matthew 2855: }
2856: }
1.367 golterma 2857: &Apache::lonhtmlcommon::Increment_PrgWin($r, \%prog_state);
1.27 matthew 2858: # Call modifyuser
2859: my $result = &Apache::lonnet::modifyuser
1.193 raeburn 2860: ($env{'form.ccdomain'},$env{'form.ccuname'},$env{'form.cid'},
1.188 raeburn 2861: $amode,$genpwd,$env{'form.cfirstname'},
2862: $env{'form.cmiddlename'},$env{'form.clastname'},
2863: $env{'form.cgeneration'},undef,$desiredhost,
2864: $env{'form.cpermanentemail'});
1.77 www 2865: $r->print(&mt('Generating user').': '.$result);
1.219 raeburn 2866: $uhome = &Apache::lonnet::homeserver($env{'form.ccuname'},
1.101 albertel 2867: $env{'form.ccdomain'});
1.334 raeburn 2868: my (%changeHash,%newcustom,%changed,%changedinfo);
1.267 raeburn 2869: if ($uhome ne 'no_host') {
1.334 raeburn 2870: if ($context eq 'domain') {
1.378 raeburn 2871: foreach my $name ('portfolio','author') {
2872: if ($env{'form.custom_'.$name.'quota'} == 1) {
2873: if ($env{'form.'.$name.'quota'} eq '') {
2874: $newcustom{$name.'quota'} = 0;
2875: } else {
2876: $newcustom{$name.'quota'} = $env{'form.'.$name.'quota'};
2877: $newcustom{$name.'quota'} =~ s/[^\d\.]//g;
2878: }
2879: if ("a_admin($newcustom{$name.'quota'},\%changeHash,$name)) {
2880: $changed{$name.'quota'} = 1;
2881: }
1.334 raeburn 2882: }
2883: }
2884: foreach my $item (@usertools) {
2885: if ($env{'form.custom'.$item} == 1) {
2886: $newcustom{$item} = $env{'form.tools_'.$item};
2887: $changed{$item} = &tool_admin($item,$newcustom{$item},
2888: \%changeHash,'tools');
2889: }
1.267 raeburn 2890: }
1.334 raeburn 2891: foreach my $item (@requestcourses) {
1.341 raeburn 2892: if ($env{'form.custom'.$item} == 1) {
2893: $newcustom{$item} = $env{'form.crsreq_'.$item};
2894: if ($env{'form.crsreq_'.$item} eq 'autolimit') {
2895: $newcustom{$item} .= '=';
1.383 raeburn 2896: $env{'form.crsreq_'.$item.'_limit'} =~ s/\D+//g;
2897: if ($env{'form.crsreq_'.$item.'_limit'}) {
1.341 raeburn 2898: $newcustom{$item} .= $env{'form.crsreq_'.$item.'_limit'};
2899: }
1.334 raeburn 2900: }
1.341 raeburn 2901: $changed{$item} = &tool_admin($item,$newcustom{$item},
2902: \%changeHash,'requestcourses');
1.334 raeburn 2903: }
1.275 raeburn 2904: }
1.362 raeburn 2905: if ($env{'form.customrequestauthor'} == 1) {
2906: $newcustom{'requestauthor'} = $env{'form.requestauthor'};
2907: $changed{'requestauthor'} = &tool_admin('requestauthor',
2908: $newcustom{'requestauthor'},
2909: \%changeHash,'requestauthor');
2910: }
1.414 raeburn 2911: if (&Apache::lonnet::allowed('cdh',$env{'request.role.domain'})) {
2912: my @adds = &Apache::loncommon::get_env_multiple('form.adhocroleadd');
2913: if (&adhocrole_changes(\%changeHash)) {
2914: $changed{'adhocroles.'.$env{'request.role.domain'}} = $changeHash{'adhocroles.'.$env{'request.role.domain'}};
1.417 raeburn 2915: }
1.414 raeburn 2916: }
1.275 raeburn 2917: }
1.334 raeburn 2918: if ($canmodify_status{'inststatus'}) {
2919: if (exists($env{'form.inststatus'})) {
2920: my @inststatuses = &Apache::loncommon::get_env_multiple('form.inststatus');
2921: if (@inststatuses > 0) {
2922: $changeHash{'inststatus'} = join(',',@inststatuses);
2923: $changed{'inststatus'} = $changeHash{'inststatus'};
1.306 raeburn 2924: }
2925: }
1.232 raeburn 2926: }
1.334 raeburn 2927: if (keys(%changed)) {
2928: foreach my $item (@userinfo) {
2929: $changeHash{$item} = $env{'form.c'.$item};
1.286 raeburn 2930: }
1.267 raeburn 2931: my $chgresult =
2932: &Apache::lonnet::put('environment',\%changeHash,
2933: $env{'form.ccdomain'},$env{'form.ccuname'});
2934: }
1.232 raeburn 2935: }
1.219 raeburn 2936: $r->print('<br />'.&mt('Home server').': '.$uhome.' '.
2937: &Apache::lonnet::hostname($uhome));
1.101 albertel 2938: } elsif (($env{'form.login'} ne 'nochange') &&
2939: ($env{'form.login'} ne '' )) {
1.27 matthew 2940: # Modify user privileges
2941: if (! $amode || ! $genpwd) {
1.193 raeburn 2942: $r->print($error.'Invalid login mode or password'.$end.$rtnlink);
1.27 matthew 2943: return;
1.20 harris41 2944: }
1.395 bisitz 2945: # Only allow authentication modification if the person has authority
1.101 albertel 2946: if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'})) {
1.20 harris41 2947: $r->print('Modifying authentication: '.
1.31 matthew 2948: &Apache::lonnet::modifyuserauth(
1.101 albertel 2949: $env{'form.ccdomain'},$env{'form.ccuname'},
1.21 harris41 2950: $amode,$genpwd));
1.102 albertel 2951: $r->print('<br />'.&mt('Home server').': '.&Apache::lonnet::homeserver
1.101 albertel 2952: ($env{'form.ccuname'},$env{'form.ccdomain'}));
1.4 www 2953: } else {
1.27 matthew 2954: # Okay, this is a non-fatal error.
1.395 bisitz 2955: $r->print($error.&mt('You do not have the authority to modify this users authentication information.').$end);
1.27 matthew 2956: }
1.28 matthew 2957: }
1.344 bisitz 2958: $r->rflush(); # Finish display of header before time consuming actions start
1.367 golterma 2959: &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state);
1.28 matthew 2960: ##
1.375 raeburn 2961: my (@userroles,%userupdate,$cnum,$cdom,$defaultcredits,%namechanged);
1.213 raeburn 2962: if ($context eq 'course') {
1.375 raeburn 2963: ($cnum,$cdom) =
2964: &Apache::lonuserutils::get_course_identity();
1.318 raeburn 2965: $crstype = &Apache::loncommon::course_type($cdom.'_'.$cnum);
1.375 raeburn 2966: if ($showcredits) {
2967: $defaultcredits = &Apache::lonuserutils::get_defaultcredits($cdom,$cnum);
2968: }
1.213 raeburn 2969: }
1.101 albertel 2970: if (! $env{'form.makeuser'} ) {
1.28 matthew 2971: # Check for need to change
2972: my %userenv = &Apache::lonnet::get
1.134 raeburn 2973: ('environment',['firstname','middlename','lastname','generation',
1.378 raeburn 2974: 'id','permanentemail','portfolioquota','authorquota','inststatus',
2975: 'tools.aboutme','tools.blog','tools.webdav','tools.portfolio',
1.361 raeburn 2976: 'requestcourses.official','requestcourses.unofficial',
1.384 raeburn 2977: 'requestcourses.community','requestcourses.textbook',
2978: 'reqcrsotherdom.official','reqcrsotherdom.unofficial',
2979: 'reqcrsotherdom.community','reqcrsotherdom.textbook',
1.414 raeburn 2980: 'reqcrsotherdom.placement','requestauthor',
2981: 'adhocroles.'.$env{'request.role.domain'}],
1.160 raeburn 2982: $env{'form.ccdomain'},$env{'form.ccuname'});
1.28 matthew 2983: my ($tmp) = keys(%userenv);
2984: if ($tmp =~ /^(con_lost|error)/i) {
2985: %userenv = ();
2986: }
1.206 raeburn 2987: my $no_forceid_alert;
2988: # Check to see if user information can be changed
2989: my %domconfig =
2990: &Apache::lonnet::get_dom('configuration',['usermodification'],
2991: $env{'form.ccdomain'});
1.213 raeburn 2992: my @statuses = ('active','future');
2993: my %roles = &Apache::lonnet::get_my_roles($env{'form.ccuname'},$env{'form.ccdomain'},'userroles',\@statuses,undef,$env{'request.role.domain'});
2994: my ($auname,$audom);
1.220 raeburn 2995: if ($context eq 'author') {
1.206 raeburn 2996: $auname = $env{'user.name'};
2997: $audom = $env{'user.domain'};
2998: }
2999: foreach my $item (keys(%roles)) {
1.220 raeburn 3000: my ($rolenum,$roledom,$role) = split(/:/,$item,-1);
1.206 raeburn 3001: if ($context eq 'course') {
3002: if ($cnum ne '' && $cdom ne '') {
3003: if ($rolenum eq $cnum && $roledom eq $cdom) {
3004: if (!grep(/^\Q$role\E$/,@userroles)) {
3005: push(@userroles,$role);
3006: }
3007: }
3008: }
3009: } elsif ($context eq 'author') {
3010: if ($rolenum eq $auname && $roledom eq $audom) {
3011: if (!grep(/^\Q$role\E$/,@userroles)) {
3012: push(@userroles,$role);
3013: }
3014: }
3015: }
3016: }
1.220 raeburn 3017: if ($env{'form.action'} eq 'singlestudent') {
3018: if (!grep(/^st$/,@userroles)) {
3019: push(@userroles,'st');
3020: }
3021: } else {
3022: # Check for course or co-author roles being activated or re-enabled
3023: if ($context eq 'author' || $context eq 'course') {
3024: foreach my $key (keys(%env)) {
3025: if ($context eq 'author') {
3026: if ($key=~/^form\.act_\Q$audom\E_\Q$auname\E_([^_]+)/) {
3027: if (!grep(/^\Q$1\E$/,@userroles)) {
3028: push(@userroles,$1);
3029: }
3030: } elsif ($key =~/^form\.ren\:\Q$audom\E\/\Q$auname\E_([^_]+)/) {
3031: if (!grep(/^\Q$1\E$/,@userroles)) {
3032: push(@userroles,$1);
3033: }
1.206 raeburn 3034: }
1.220 raeburn 3035: } elsif ($context eq 'course') {
3036: if ($key=~/^form\.act_\Q$cdom\E_\Q$cnum\E_([^_]+)/) {
3037: if (!grep(/^\Q$1\E$/,@userroles)) {
3038: push(@userroles,$1);
3039: }
3040: } elsif ($key =~/^form\.ren\:\Q$cdom\E\/\Q$cnum\E(\/?\w*)_([^_]+)/) {
3041: if (!grep(/^\Q$1\E$/,@userroles)) {
3042: push(@userroles,$1);
3043: }
1.206 raeburn 3044: }
3045: }
3046: }
3047: }
3048: }
3049: #Check to see if we can change personal data for the user
3050: my (@mod_disallowed,@longroles);
3051: foreach my $role (@userroles) {
3052: if ($role eq 'cr') {
3053: push(@longroles,'Custom');
3054: } else {
1.318 raeburn 3055: push(@longroles,&Apache::lonnet::plaintext($role,$crstype));
1.206 raeburn 3056: }
3057: }
1.219 raeburn 3058: my %canmodify = &Apache::lonuserutils::can_modify_userinfo($context,$env{'form.ccdomain'},\@userinfo,\@userroles);
3059: foreach my $item (@userinfo) {
1.28 matthew 3060: # Strip leading and trailing whitespace
1.203 raeburn 3061: $env{'form.c'.$item} =~ s/(\s+$|^\s+)//g;
1.219 raeburn 3062: if (!$canmodify{$item}) {
1.207 raeburn 3063: if (defined($env{'form.c'.$item})) {
3064: if ($env{'form.c'.$item} ne $userenv{$item}) {
3065: push(@mod_disallowed,$item);
3066: }
1.206 raeburn 3067: }
3068: $env{'form.c'.$item} = $userenv{$item};
3069: }
1.28 matthew 3070: }
1.259 bisitz 3071: # Check to see if we can change the Student/Employee ID
1.196 raeburn 3072: my $forceid = $env{'form.forceid'};
3073: my $recurseid = $env{'form.recurseid'};
3074: my (%alerts,%rulematch,%idinst_results,%curr_rules,%got_rules);
1.203 raeburn 3075: my %uidhash = &Apache::lonnet::idrget($env{'form.ccdomain'},
3076: $env{'form.ccuname'});
3077: if (($uidhash{$env{'form.ccuname'}}) &&
3078: ($uidhash{$env{'form.ccuname'}}!~/error\:/) &&
3079: (!$forceid)) {
3080: if ($env{'form.cid'} ne $uidhash{$env{'form.ccuname'}}) {
3081: $env{'form.cid'} = $userenv{'id'};
1.293 bisitz 3082: $no_forceid_alert = &mt('New student/employee ID does not match existing ID for this user.')
1.259 bisitz 3083: .'<br />'
3084: .&mt("Change is not permitted without checking the 'Force ID change' checkbox on the previous page.")
3085: .'<br />'."\n";
1.203 raeburn 3086: }
3087: }
3088: if ($env{'form.cid'} ne $userenv{'id'}) {
1.196 raeburn 3089: my $checkhash;
3090: my $checks = { 'id' => 1 };
3091: $checkhash->{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}} =
3092: { 'newuser' => $newuser,
3093: 'id' => $env{'form.cid'},
3094: };
3095: &Apache::loncommon::user_rule_check($checkhash,$checks,
3096: \%alerts,\%rulematch,\%idinst_results,\%curr_rules,\%got_rules);
3097: if (ref($alerts{'id'}) eq 'HASH') {
3098: if (ref($alerts{'id'}{$env{'form.ccdomain'}}) eq 'HASH') {
1.203 raeburn 3099: $env{'form.cid'} = $userenv{'id'};
1.196 raeburn 3100: }
3101: }
3102: }
1.378 raeburn 3103: my (%quotachanged,%oldquota,%newquota,%olddefquota,%newdefquota,
3104: $oldinststatus,$newinststatus,%oldisdefault,%newisdefault,%oldsettings,
1.339 raeburn 3105: %oldsettingstext,%newsettings,%newsettingstext,@disporder,
1.378 raeburn 3106: %oldsettingstatus,%newsettingstatus);
1.334 raeburn 3107: @disporder = ('inststatus');
3108: if ($env{'request.role.domain'} eq $env{'form.ccdomain'}) {
1.362 raeburn 3109: push(@disporder,'requestcourses','requestauthor');
1.334 raeburn 3110: } else {
3111: push(@disporder,'reqcrsotherdom');
3112: }
3113: push(@disporder,('quota','tools'));
1.338 raeburn 3114: $oldinststatus = $userenv{'inststatus'};
1.378 raeburn 3115: foreach my $name ('portfolio','author') {
3116: ($olddefquota{$name},$oldsettingstatus{$name}) =
3117: &Apache::loncommon::default_quota($env{'form.ccdomain'},$oldinststatus,$name);
3118: ($newdefquota{$name},$newsettingstatus{$name}) = ($olddefquota{$name},$oldsettingstatus{$name});
3119: }
1.414 raeburn 3120: push(@disporder,'adhocroles');
1.334 raeburn 3121: my %canshow;
1.220 raeburn 3122: if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
1.334 raeburn 3123: $canshow{'quota'} = 1;
1.220 raeburn 3124: }
1.267 raeburn 3125: if (&Apache::lonnet::allowed('mut',$env{'form.ccdomain'})) {
1.334 raeburn 3126: $canshow{'tools'} = 1;
1.267 raeburn 3127: }
1.275 raeburn 3128: if (&Apache::lonnet::allowed('ccc',$env{'form.ccdomain'})) {
1.334 raeburn 3129: $canshow{'requestcourses'} = 1;
1.300 raeburn 3130: } elsif (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
1.334 raeburn 3131: $canshow{'reqcrsotherdom'} = 1;
1.275 raeburn 3132: }
1.286 raeburn 3133: if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'})) {
1.334 raeburn 3134: $canshow{'inststatus'} = 1;
1.286 raeburn 3135: }
1.362 raeburn 3136: if (&Apache::lonnet::allowed('cau',$env{'form.ccdomain'})) {
3137: $canshow{'requestauthor'} = 1;
3138: }
1.414 raeburn 3139: if (&Apache::lonnet::allowed('cdh',$env{'request.role.domain'})) {
3140: $canshow{'adhocroles'} = 1;
3141: }
1.267 raeburn 3142: my (%changeHash,%changed);
1.286 raeburn 3143: if ($oldinststatus eq '') {
1.334 raeburn 3144: $oldsettings{'inststatus'} = $othertitle;
1.286 raeburn 3145: } else {
3146: if (ref($usertypes) eq 'HASH') {
1.334 raeburn 3147: $oldsettings{'inststatus'} = join(', ',map{ $usertypes->{ &unescape($_) }; } (split(/:/,$userenv{'inststatus'})));
1.286 raeburn 3148: } else {
1.334 raeburn 3149: $oldsettings{'inststatus'} = join(', ',map{ &unescape($_); } (split(/:/,$userenv{'inststatus'})));
1.286 raeburn 3150: }
3151: }
3152: $changeHash{'inststatus'} = $userenv{'inststatus'};
1.334 raeburn 3153: if ($canmodify_status{'inststatus'}) {
3154: $canshow{'inststatus'} = 1;
1.286 raeburn 3155: if (exists($env{'form.inststatus'})) {
3156: my @inststatuses = &Apache::loncommon::get_env_multiple('form.inststatus');
3157: if (@inststatuses > 0) {
3158: $newinststatus = join(':',map { &escape($_); } @inststatuses);
3159: $changeHash{'inststatus'} = $newinststatus;
3160: if ($newinststatus ne $oldinststatus) {
3161: $changed{'inststatus'} = $newinststatus;
1.378 raeburn 3162: foreach my $name ('portfolio','author') {
3163: ($newdefquota{$name},$newsettingstatus{$name}) =
3164: &Apache::loncommon::default_quota($env{'form.ccdomain'},$newinststatus,$name);
3165: }
1.286 raeburn 3166: }
3167: if (ref($usertypes) eq 'HASH') {
1.334 raeburn 3168: $newsettings{'inststatus'} = join(', ',map{ $usertypes->{$_}; } (@inststatuses));
1.286 raeburn 3169: } else {
1.337 raeburn 3170: $newsettings{'inststatus'} = join(', ',@inststatuses);
1.286 raeburn 3171: }
1.334 raeburn 3172: }
3173: } else {
3174: $newinststatus = '';
3175: $changeHash{'inststatus'} = $newinststatus;
3176: $newsettings{'inststatus'} = $othertitle;
3177: if ($newinststatus ne $oldinststatus) {
3178: $changed{'inststatus'} = $changeHash{'inststatus'};
1.378 raeburn 3179: foreach my $name ('portfolio','author') {
3180: ($newdefquota{$name},$newsettingstatus{$name}) =
3181: &Apache::loncommon::default_quota($env{'form.ccdomain'},$newinststatus,$name);
3182: }
1.286 raeburn 3183: }
3184: }
1.334 raeburn 3185: } elsif ($context ne 'selfcreate') {
3186: $canshow{'inststatus'} = 1;
1.337 raeburn 3187: $newsettings{'inststatus'} = $oldsettings{'inststatus'};
1.286 raeburn 3188: }
1.378 raeburn 3189: foreach my $name ('portfolio','author') {
3190: $changeHash{$name.'quota'} = $userenv{$name.'quota'};
3191: }
1.334 raeburn 3192: if ($context eq 'domain') {
1.378 raeburn 3193: foreach my $name ('portfolio','author') {
3194: if ($userenv{$name.'quota'} ne '') {
3195: $oldquota{$name} = $userenv{$name.'quota'};
3196: if ($env{'form.custom_'.$name.'quota'} == 1) {
3197: if ($env{'form.'.$name.'quota'} eq '') {
3198: $newquota{$name} = 0;
3199: } else {
3200: $newquota{$name} = $env{'form.'.$name.'quota'};
3201: $newquota{$name} =~ s/[^\d\.]//g;
3202: }
3203: if ($newquota{$name} != $oldquota{$name}) {
3204: if ("a_admin($newquota{$name},\%changeHash,$name)) {
3205: $changed{$name.'quota'} = 1;
3206: }
3207: }
1.334 raeburn 3208: } else {
1.378 raeburn 3209: if ("a_admin('',\%changeHash,$name)) {
3210: $changed{$name.'quota'} = 1;
3211: $newquota{$name} = $newdefquota{$name};
3212: $newisdefault{$name} = 1;
3213: }
1.334 raeburn 3214: }
1.149 raeburn 3215: } else {
1.378 raeburn 3216: $oldisdefault{$name} = 1;
3217: $oldquota{$name} = $olddefquota{$name};
3218: if ($env{'form.custom_'.$name.'quota'} == 1) {
3219: if ($env{'form.'.$name.'quota'} eq '') {
3220: $newquota{$name} = 0;
3221: } else {
3222: $newquota{$name} = $env{'form.'.$name.'quota'};
3223: $newquota{$name} =~ s/[^\d\.]//g;
3224: }
3225: if ("a_admin($newquota{$name},\%changeHash,$name)) {
3226: $changed{$name.'quota'} = 1;
3227: }
1.334 raeburn 3228: } else {
1.378 raeburn 3229: $newquota{$name} = $newdefquota{$name};
3230: $newisdefault{$name} = 1;
1.334 raeburn 3231: }
1.378 raeburn 3232: }
3233: if ($oldisdefault{$name}) {
3234: $oldsettingstext{'quota'}{$name} = &get_defaultquota_text($oldsettingstatus{$name});
1.383 raeburn 3235: } else {
3236: $oldsettingstext{'quota'}{$name} = &mt('custom quota: [_1] MB',$oldquota{$name});
1.378 raeburn 3237: }
3238: if ($newisdefault{$name}) {
3239: $newsettingstext{'quota'}{$name} = &get_defaultquota_text($newsettingstatus{$name});
1.383 raeburn 3240: } else {
3241: $newsettingstext{'quota'}{$name} = &mt('custom quota: [_1] MB',$newquota{$name});
1.134 raeburn 3242: }
3243: }
1.334 raeburn 3244: &tool_changes('tools',\@usertools,\%oldsettings,\%oldsettingstext,\%userenv,
3245: \%changeHash,\%changed,\%newsettings,\%newsettingstext);
3246: if ($env{'form.ccdomain'} eq $env{'request.role.domain'}) {
3247: &tool_changes('requestcourses',\@requestcourses,\%oldsettings,\%oldsettingstext,
3248: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
1.384 raeburn 3249: &tool_changes('requestauthor',\@requestauthor,\%oldsettings,\%oldsettingstext,
3250: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
1.149 raeburn 3251: } else {
1.334 raeburn 3252: &tool_changes('reqcrsotherdom',\@requestcourses,\%oldsettings,\%oldsettingstext,
3253: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
1.149 raeburn 3254: }
1.414 raeburn 3255: if ($userenv{'adhocroles.'.$env{'request.role.domain'}}) {
3256: $changeHash{'adhocroles.'.$env{'request.role.domain'}} = $userenv{'adhocroles.'.$env{'request.role.domain'}};
3257: }
3258: if (&adhocrole_changes(\%changeHash,\%userenv)) {
3259: $changed{'adhocroles'} = 1;
3260: $oldsettings{'adhocroles'} = $userenv{'adhocroles.'.$env{'request.role.domain'}};
1.417 raeburn 3261: $newsettings{'adhocroles'} = $changeHash{'adhocroles.'.$env{'request.role.domain'}};
1.414 raeburn 3262: }
1.149 raeburn 3263: }
1.334 raeburn 3264: foreach my $item (@userinfo) {
3265: if ($env{'form.c'.$item} ne $userenv{$item}) {
3266: $namechanged{$item} = 1;
3267: }
1.204 raeburn 3268: }
1.378 raeburn 3269: foreach my $name ('portfolio','author') {
1.390 bisitz 3270: $oldsettings{'quota'}{$name} = &mt('[_1] MB',$oldquota{$name});
3271: $newsettings{'quota'}{$name} = &mt('[_1] MB',$newquota{$name});
1.378 raeburn 3272: }
1.334 raeburn 3273: if ((keys(%namechanged) > 0) || (keys(%changed) > 0)) {
1.267 raeburn 3274: my ($chgresult,$namechgresult);
3275: if (keys(%changed) > 0) {
3276: $chgresult =
1.204 raeburn 3277: &Apache::lonnet::put('environment',\%changeHash,
3278: $env{'form.ccdomain'},$env{'form.ccuname'});
1.267 raeburn 3279: if ($chgresult eq 'ok') {
3280: if (($env{'user.name'} eq $env{'form.ccuname'}) &&
3281: ($env{'user.domain'} eq $env{'form.ccdomain'})) {
1.270 raeburn 3282: my %newenvhash;
3283: foreach my $key (keys(%changed)) {
1.411 raeburn 3284: if (($key eq 'official') || ($key eq 'unofficial') ||
3285: ($key eq 'community') || ($key eq 'textbook') ||
3286: ($key eq 'placement')) {
1.279 raeburn 3287: $newenvhash{'environment.requestcourses.'.$key} =
3288: $changeHash{'requestcourses.'.$key};
1.362 raeburn 3289: if ($changeHash{'requestcourses.'.$key}) {
1.332 raeburn 3290: $newenvhash{'environment.canrequest.'.$key} = 1;
1.279 raeburn 3291: } else {
3292: $newenvhash{'environment.canrequest.'.$key} =
3293: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
3294: $key,'reload','requestcourses');
3295: }
1.362 raeburn 3296: } elsif ($key eq 'requestauthor') {
3297: $newenvhash{'environment.'.$key} = $changeHash{$key};
3298: if ($changeHash{$key}) {
3299: $newenvhash{'environment.canrequest.author'} = 1;
3300: } else {
3301: $newenvhash{'environment.canrequest.author'} =
3302: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
3303: $key,'reload','requestauthor');
3304: }
1.414 raeburn 3305: } elsif ($key eq 'adhocroles') {
3306: $newenvhash{'adhocroles.'.$env{'request.role.domain'}} =
3307: $changeHash{'adhocroles.'.$env{'request.role.domain'}};
1.275 raeburn 3308: } elsif ($key ne 'quota') {
1.270 raeburn 3309: $newenvhash{'environment.tools.'.$key} =
3310: $changeHash{'tools.'.$key};
1.279 raeburn 3311: if ($changeHash{'tools.'.$key} ne '') {
3312: $newenvhash{'environment.availabletools.'.$key} =
3313: $changeHash{'tools.'.$key};
3314: } else {
3315: $newenvhash{'environment.availabletools.'.$key} =
1.367 golterma 3316: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
3317: $key,'reload','tools');
1.279 raeburn 3318: }
1.270 raeburn 3319: }
3320: }
1.271 raeburn 3321: if (keys(%newenvhash)) {
3322: &Apache::lonnet::appenv(\%newenvhash);
3323: }
1.267 raeburn 3324: }
3325: }
1.204 raeburn 3326: }
1.334 raeburn 3327: if (keys(%namechanged) > 0) {
1.337 raeburn 3328: foreach my $field (@userinfo) {
3329: $changeHash{$field} = $env{'form.c'.$field};
3330: }
3331: # Make the change
1.204 raeburn 3332: $namechgresult =
3333: &Apache::lonnet::modifyuser($env{'form.ccdomain'},
3334: $env{'form.ccuname'},$changeHash{'id'},undef,undef,
3335: $changeHash{'firstname'},$changeHash{'middlename'},
3336: $changeHash{'lastname'},$changeHash{'generation'},
1.337 raeburn 3337: $changeHash{'id'},undef,$changeHash{'permanentemail'},undef,\@userinfo);
1.220 raeburn 3338: %userupdate = (
3339: lastname => $env{'form.clastname'},
3340: middlename => $env{'form.cmiddlename'},
3341: firstname => $env{'form.cfirstname'},
3342: generation => $env{'form.cgeneration'},
3343: id => $env{'form.cid'},
3344: );
1.204 raeburn 3345: }
1.334 raeburn 3346: if (((keys(%namechanged) > 0) && $namechgresult eq 'ok') ||
1.267 raeburn 3347: ((keys(%changed) > 0) && $chgresult eq 'ok')) {
1.28 matthew 3348: # Tell the user we changed the name
1.334 raeburn 3349: &display_userinfo($r,1,\@disporder,\%canshow,\@requestcourses,
1.362 raeburn 3350: \@usertools,\@requestauthor,\%userenv,\%changed,\%namechanged,
1.334 raeburn 3351: \%oldsettings, \%oldsettingstext,\%newsettings,
3352: \%newsettingstext);
1.203 raeburn 3353: if ($env{'form.cid'} ne $userenv{'id'}) {
3354: &Apache::lonnet::idput($env{'form.ccdomain'},
1.407 raeburn 3355: {$env{'form.ccuname'} => $env{'form.cid'}},$uhome,'ids');
1.203 raeburn 3356: if (($recurseid) &&
3357: (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'}))) {
3358: my $idresult =
3359: &Apache::lonuserutils::propagate_id_change(
3360: $env{'form.ccuname'},$env{'form.ccdomain'},
3361: \%userupdate);
3362: $r->print('<br />'.$idresult.'<br />');
3363: }
1.196 raeburn 3364: }
1.149 raeburn 3365: if (($env{'form.ccdomain'} eq $env{'user.domain'}) &&
3366: ($env{'form.ccuname'} eq $env{'user.name'})) {
3367: my %newenvhash;
3368: foreach my $key (keys(%changeHash)) {
3369: $newenvhash{'environment.'.$key} = $changeHash{$key};
3370: }
1.238 raeburn 3371: &Apache::lonnet::appenv(\%newenvhash);
1.149 raeburn 3372: }
1.28 matthew 3373: } else { # error occurred
1.389 bisitz 3374: $r->print(
3375: '<p class="LC_error">'
3376: .&mt('Unable to successfully change environment for [_1] in domain [_2].',
3377: '"'.$env{'form.ccuname'}.'"',
3378: '"'.$env{'form.ccdomain'}.'"')
3379: .'</p>');
1.28 matthew 3380: }
1.334 raeburn 3381: } else { # End of if ($env ... ) logic
1.275 raeburn 3382: # They did not want to change the users name, quota, tool availability,
3383: # or ability to request creation of courses,
1.267 raeburn 3384: # but we can still tell them what the name and quota and availabilities are
1.334 raeburn 3385: &display_userinfo($r,undef,\@disporder,\%canshow,\@requestcourses,
1.362 raeburn 3386: \@usertools,\@requestauthor,\%userenv,\%changed,\%namechanged,\%oldsettings,
1.334 raeburn 3387: \%oldsettingstext,\%newsettings,\%newsettingstext);
1.28 matthew 3388: }
1.206 raeburn 3389: if (@mod_disallowed) {
3390: my ($rolestr,$contextname);
3391: if (@longroles > 0) {
3392: $rolestr = join(', ',@longroles);
3393: } else {
3394: $rolestr = &mt('No roles');
3395: }
3396: if ($context eq 'course') {
1.399 bisitz 3397: $contextname = 'course';
1.206 raeburn 3398: } elsif ($context eq 'author') {
1.399 bisitz 3399: $contextname = 'co-author';
1.206 raeburn 3400: }
3401: $r->print(&mt('The following fields were not updated: ').'<ul>');
3402: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
3403: foreach my $field (@mod_disallowed) {
3404: $r->print('<li>'.$fieldtitles{$field}.'</li>'."\n");
3405: }
1.207 raeburn 3406: $r->print('</ul>');
3407: if (@mod_disallowed == 1) {
1.399 bisitz 3408: $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 3409: } else {
1.399 bisitz 3410: $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 3411: }
1.292 bisitz 3412: my $helplink = 'javascript:helpMenu('."'display'".')';
3413: $r->print('<span class="LC_cusr_emph">'.$rolestr.'</span><br />'
3414: .&mt('Please contact your [_1]helpdesk[_2] for more information.'
3415: ,'<a href="'.$helplink.'">','</a>')
3416: .'<br />');
1.206 raeburn 3417: }
1.259 bisitz 3418: $r->print('<span class="LC_warning">'
3419: .$no_forceid_alert
3420: .&Apache::lonuserutils::print_namespacing_alerts($env{'form.ccdomain'},\%alerts,\%curr_rules)
3421: .'</span>');
1.4 www 3422: }
1.367 golterma 3423: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
1.220 raeburn 3424: if ($env{'form.action'} eq 'singlestudent') {
1.375 raeburn 3425: &enroll_single_student($r,$uhome,$amode,$genpwd,$now,$newuser,$context,
3426: $crstype,$showcredits,$defaultcredits);
1.386 bisitz 3427: my $linktext = ($crstype eq 'Community' ?
3428: &mt('Enroll Another Member') : &mt('Enroll Another Student'));
3429: $r->print(
3430: &Apache::lonhtmlcommon::actionbox([
3431: '<a href="javascript:backPage(document.userupdate)">'
3432: .($crstype eq 'Community' ?
3433: &mt('Enroll Another Member') : &mt('Enroll Another Student'))
3434: .'</a>']));
1.220 raeburn 3435: } else {
1.375 raeburn 3436: my @rolechanges = &update_roles($r,$context,$showcredits);
1.334 raeburn 3437: if (keys(%namechanged) > 0) {
1.220 raeburn 3438: if ($context eq 'course') {
3439: if (@userroles > 0) {
1.225 raeburn 3440: if ((@rolechanges == 0) ||
3441: (!(grep(/^st$/,@rolechanges)))) {
3442: if (grep(/^st$/,@userroles)) {
3443: my $classlistupdated =
3444: &Apache::lonuserutils::update_classlist($cdom,
1.220 raeburn 3445: $cnum,$env{'form.ccdomain'},
3446: $env{'form.ccuname'},\%userupdate);
1.225 raeburn 3447: }
1.220 raeburn 3448: }
3449: }
3450: }
3451: }
1.226 raeburn 3452: my $userinfo = &Apache::loncommon::plainname($env{'form.ccuname'},
1.233 raeburn 3453: $env{'form.ccdomain'});
3454: if ($env{'form.popup'}) {
3455: $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a></p>');
3456: } else {
1.367 golterma 3457: $r->print('<br />'.&Apache::lonhtmlcommon::actionbox(['<a href="javascript:backPage(document.userupdate,'."'$env{'form.prevphase'}','modify'".')">'
3458: .&mt('Modify this user: [_1]','<span class="LC_cusr_emph">'.$env{'form.ccuname'}.':'.$env{'form.ccdomain'}.' ('.$userinfo.')</span>').'</a>',
3459: '<a href="javascript:backPage(document.userupdate)">'.&mt('Create/Modify Another User').'</a>']));
1.233 raeburn 3460: }
1.220 raeburn 3461: }
3462: }
3463:
1.334 raeburn 3464: sub display_userinfo {
1.362 raeburn 3465: my ($r,$changed,$order,$canshow,$requestcourses,$usertools,$requestauthor,
3466: $userenv,$changedhash,$namechangedhash,$oldsetting,$oldsettingtext,
1.334 raeburn 3467: $newsetting,$newsettingtext) = @_;
3468: return unless (ref($order) eq 'ARRAY' &&
3469: ref($canshow) eq 'HASH' &&
3470: ref($requestcourses) eq 'ARRAY' &&
1.362 raeburn 3471: ref($requestauthor) eq 'ARRAY' &&
1.334 raeburn 3472: ref($usertools) eq 'ARRAY' &&
3473: ref($userenv) eq 'HASH' &&
3474: ref($changedhash) eq 'HASH' &&
3475: ref($oldsetting) eq 'HASH' &&
3476: ref($oldsettingtext) eq 'HASH' &&
3477: ref($newsetting) eq 'HASH' &&
3478: ref($newsettingtext) eq 'HASH');
3479: my %lt=&Apache::lonlocal::texthash(
1.372 raeburn 3480: 'ui' => 'User Information',
1.334 raeburn 3481: 'uic' => 'User Information Changed',
3482: 'firstname' => 'First Name',
3483: 'middlename' => 'Middle Name',
3484: 'lastname' => 'Last Name',
3485: 'generation' => 'Generation',
3486: 'id' => 'Student/Employee ID',
3487: 'permanentemail' => 'Permanent e-mail address',
1.378 raeburn 3488: 'portfolioquota' => 'Disk space allocated to portfolio files',
1.385 bisitz 3489: 'authorquota' => 'Disk space allocated to Authoring Space',
1.334 raeburn 3490: 'blog' => 'Blog Availability',
1.361 raeburn 3491: 'webdav' => 'WebDAV Availability',
1.334 raeburn 3492: 'aboutme' => 'Personal Information Page Availability',
3493: 'portfolio' => 'Portfolio Availability',
3494: 'official' => 'Can Request Official Courses',
3495: 'unofficial' => 'Can Request Unofficial Courses',
3496: 'community' => 'Can Request Communities',
1.384 raeburn 3497: 'textbook' => 'Can Request Textbook Courses',
1.411 raeburn 3498: 'placement' => 'Can Request Placement Tests',
1.362 raeburn 3499: 'requestauthor' => 'Can Request Author Role',
1.414 raeburn 3500: 'adhocroles' => 'Ad Hoc Roles Selectable via Helpdesk Role',
1.334 raeburn 3501: 'inststatus' => "Affiliation",
3502: 'prvs' => 'Previous Value:',
3503: 'chto' => 'Changed To:'
3504: );
3505: if ($changed) {
1.372 raeburn 3506: $r->print('<h3>'.$lt{'uic'}.'</h3>'.
1.367 golterma 3507: &Apache::loncommon::start_data_table().
3508: &Apache::loncommon::start_data_table_header_row());
1.334 raeburn 3509: $r->print("<th> </th>\n");
1.367 golterma 3510: $r->print('<th><b>'.$lt{'prvs'}.'</b></th>');
3511: $r->print('<th><span class="LC_nobreak"><b>'.$lt{'chto'}.'</b></span></th>');
3512: $r->print(&Apache::loncommon::end_data_table_header_row());
3513: my @userinfo = ('firstname','middlename','lastname','generation','permanentemail','id');
3514:
1.334 raeburn 3515: foreach my $item (@userinfo) {
3516: my $value = $env{'form.c'.$item};
1.367 golterma 3517: #show changes only:
1.383 raeburn 3518: unless ($value eq $userenv->{$item}){
1.367 golterma 3519: $r->print(&Apache::loncommon::start_data_table_row());
3520: $r->print("<td>$lt{$item}</td>\n");
1.383 raeburn 3521: $r->print("<td>".$userenv->{$item}."</td>\n");
1.367 golterma 3522: $r->print("<td>$value </td>\n");
3523: $r->print(&Apache::loncommon::end_data_table_row());
1.334 raeburn 3524: }
3525: }
3526: foreach my $entry (@{$order}) {
1.383 raeburn 3527: if ($canshow->{$entry}) {
3528: if (($entry eq 'requestcourses') || ($entry eq 'reqcrsotherdom') || ($entry eq 'requestauthor')) {
3529: my @items;
3530: if ($entry eq 'requestauthor') {
3531: @items = ($entry);
3532: } else {
3533: @items = @{$requestcourses};
1.384 raeburn 3534: }
1.383 raeburn 3535: foreach my $item (@items) {
3536: if (($newsetting->{$item} ne $oldsetting->{$item}) ||
3537: ($newsettingtext->{$item} ne $oldsettingtext->{$item})) {
3538: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3539: $r->print("<td>$lt{$item}</td>\n");
3540: $r->print("<td>".$oldsetting->{$item});
3541: if ($oldsettingtext->{$item}) {
3542: if ($oldsetting->{$item}) {
3543: $r->print(' -- ');
3544: }
3545: $r->print($oldsettingtext->{$item});
3546: }
3547: $r->print("</td>\n");
3548: $r->print("<td>".$newsetting->{$item});
3549: if ($newsettingtext->{$item}) {
3550: if ($newsetting->{$item}) {
3551: $r->print(' -- ');
3552: }
3553: $r->print($newsettingtext->{$item});
3554: }
3555: $r->print("</td>\n");
3556: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.334 raeburn 3557: }
3558: }
3559: } elsif ($entry eq 'tools') {
3560: foreach my $item (@{$usertools}) {
1.383 raeburn 3561: if ($newsetting->{$item} ne $oldsetting->{$item}) {
3562: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3563: $r->print("<td>$lt{$item}</td>\n");
3564: $r->print("<td>".$oldsetting->{$item}.' '.$oldsettingtext->{$item}."</td>\n");
3565: $r->print("<td>".$newsetting->{$item}.' '.$newsettingtext->{$item}."</td>\n");
3566: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.334 raeburn 3567: }
3568: }
1.378 raeburn 3569: } elsif ($entry eq 'quota') {
3570: if ((ref($oldsetting->{$entry}) eq 'HASH') && (ref($oldsettingtext->{$entry}) eq 'HASH') &&
3571: (ref($newsetting->{$entry}) eq 'HASH') && (ref($newsettingtext->{$entry}) eq 'HASH')) {
3572: foreach my $name ('portfolio','author') {
1.383 raeburn 3573: if ($newsetting->{$entry}->{$name} ne $oldsetting->{$entry}->{$name}) {
3574: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3575: $r->print("<td>$lt{$name.$entry}</td>\n");
3576: $r->print("<td>".$oldsettingtext->{$entry}->{$name}."</td>\n");
3577: $r->print("<td>".$newsettingtext->{$entry}->{$name}."</td>\n");
3578: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.378 raeburn 3579: }
3580: }
3581: }
1.334 raeburn 3582: } else {
1.383 raeburn 3583: if ($newsetting->{$entry} ne $oldsetting->{$entry}) {
3584: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3585: $r->print("<td>$lt{$entry}</td>\n");
3586: $r->print("<td>".$oldsetting->{$entry}.' '.$oldsettingtext->{$entry}."</td>\n");
3587: $r->print("<td>".$newsetting->{$entry}.' '.$newsettingtext->{$entry}."</td>\n");
3588: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.334 raeburn 3589: }
3590: }
3591: }
3592: }
1.367 golterma 3593: $r->print(&Apache::loncommon::end_data_table().'<br />');
1.372 raeburn 3594: } else {
3595: $r->print('<h3>'.$lt{'ui'}.'</h3>'.
3596: '<p>'.&mt('No changes made to user information').'</p>');
1.334 raeburn 3597: }
3598: return;
3599: }
3600:
1.275 raeburn 3601: sub tool_changes {
3602: my ($context,$usertools,$oldaccess,$oldaccesstext,$userenv,$changeHash,
3603: $changed,$newaccess,$newaccesstext) = @_;
3604: if (!((ref($usertools) eq 'ARRAY') && (ref($oldaccess) eq 'HASH') &&
3605: (ref($oldaccesstext) eq 'HASH') && (ref($userenv) eq 'HASH') &&
3606: (ref($changeHash) eq 'HASH') && (ref($changed) eq 'HASH') &&
3607: (ref($newaccess) eq 'HASH') && (ref($newaccesstext) eq 'HASH'))) {
3608: return;
3609: }
1.383 raeburn 3610: my %reqdisplay = &requestchange_display();
1.300 raeburn 3611: if ($context eq 'reqcrsotherdom') {
1.309 raeburn 3612: my @options = ('approval','validate','autolimit');
1.306 raeburn 3613: my $optregex = join('|',@options);
1.300 raeburn 3614: my $cdom = $env{'request.role.domain'};
3615: foreach my $tool (@{$usertools}) {
1.383 raeburn 3616: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
1.314 raeburn 3617: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
1.300 raeburn 3618: $changeHash->{$context.'.'.$tool} = $userenv->{$context.'.'.$tool};
1.383 raeburn 3619: my ($newop,$limit);
1.314 raeburn 3620: if ($env{'form.'.$context.'_'.$tool}) {
3621: $newop = $env{'form.'.$context.'_'.$tool};
3622: if ($newop eq 'autolimit') {
1.383 raeburn 3623: $limit = $env{'form.'.$context.'_'.$tool.'_limit'};
1.314 raeburn 3624: $limit =~ s/\D+//g;
3625: $newop .= '='.$limit;
3626: }
3627: }
1.300 raeburn 3628: if ($userenv->{$context.'.'.$tool} eq '') {
1.314 raeburn 3629: if ($newop) {
3630: $changed->{$tool}=&tool_admin($tool,$cdom.':'.$newop,
1.300 raeburn 3631: $changeHash,$context);
3632: if ($changed->{$tool}) {
1.383 raeburn 3633: if ($newop =~ /^autolimit/) {
3634: if ($limit) {
3635: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3636: } else {
3637: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3638: }
3639: } else {
3640: $newaccesstext->{$tool} = $reqdisplay{$newop};
3641: }
1.300 raeburn 3642: } else {
3643: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
3644: }
3645: }
3646: } else {
3647: my @curr = split(',',$userenv->{$context.'.'.$tool});
3648: my @new;
3649: my $changedoms;
1.314 raeburn 3650: foreach my $req (@curr) {
3651: if ($req =~ /^\Q$cdom\E\:($optregex\=?\d*)$/) {
3652: my $oldop = $1;
1.383 raeburn 3653: if ($oldop =~ /^autolimit=(\d*)/) {
3654: my $limit = $1;
3655: if ($limit) {
3656: $oldaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3657: } else {
3658: $oldaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3659: }
3660: } else {
3661: $oldaccesstext->{$tool} = $reqdisplay{$oldop};
3662: }
1.314 raeburn 3663: if ($oldop ne $newop) {
3664: $changedoms = 1;
3665: foreach my $item (@curr) {
3666: my ($reqdom,$option) = split(':',$item);
3667: unless ($reqdom eq $cdom) {
3668: push(@new,$item);
3669: }
3670: }
3671: if ($newop) {
3672: push(@new,$cdom.':'.$newop);
1.300 raeburn 3673: }
1.314 raeburn 3674: @new = sort(@new);
1.300 raeburn 3675: }
1.314 raeburn 3676: last;
1.300 raeburn 3677: }
1.314 raeburn 3678: }
3679: if ((!$changedoms) && ($newop)) {
1.300 raeburn 3680: $changedoms = 1;
1.306 raeburn 3681: @new = sort(@curr,$cdom.':'.$newop);
1.300 raeburn 3682: }
3683: if ($changedoms) {
1.314 raeburn 3684: my $newdomstr;
1.300 raeburn 3685: if (@new) {
3686: $newdomstr = join(',',@new);
3687: }
3688: $changed->{$tool}=&tool_admin($tool,$newdomstr,$changeHash,
3689: $context);
3690: if ($changed->{$tool}) {
3691: if ($env{'form.'.$context.'_'.$tool}) {
1.306 raeburn 3692: if ($env{'form.'.$context.'_'.$tool} eq 'autolimit') {
1.314 raeburn 3693: my $limit = $env{'form.'.$context.'_'.$tool.'_limit'};
3694: $limit =~ s/\D+//g;
3695: if ($limit) {
1.383 raeburn 3696: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
1.314 raeburn 3697: } else {
1.383 raeburn 3698: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
1.306 raeburn 3699: }
1.314 raeburn 3700: } else {
1.306 raeburn 3701: $newaccesstext->{$tool} = $reqdisplay{$env{'form.'.$context.'_'.$tool}};
3702: }
1.300 raeburn 3703: } else {
1.383 raeburn 3704: $newaccesstext->{$tool} = &mt("availability set to 'off'");
1.300 raeburn 3705: }
3706: }
3707: }
3708: }
3709: }
3710: return;
3711: }
1.275 raeburn 3712: foreach my $tool (@{$usertools}) {
1.383 raeburn 3713: my ($newval,$limit,$envkey);
1.362 raeburn 3714: $envkey = $context.'.'.$tool;
1.306 raeburn 3715: if ($context eq 'requestcourses') {
3716: $newval = $env{'form.crsreq_'.$tool};
3717: if ($newval eq 'autolimit') {
1.383 raeburn 3718: $limit = $env{'form.crsreq_'.$tool.'_limit'};
3719: $limit =~ s/\D+//g;
3720: $newval .= '='.$limit;
1.306 raeburn 3721: }
1.362 raeburn 3722: } elsif ($context eq 'requestauthor') {
3723: $newval = $env{'form.'.$context};
3724: $envkey = $context;
1.314 raeburn 3725: } else {
1.306 raeburn 3726: $newval = $env{'form.'.$context.'_'.$tool};
3727: }
1.362 raeburn 3728: if ($userenv->{$envkey} ne '') {
1.275 raeburn 3729: $oldaccess->{$tool} = &mt('custom');
1.383 raeburn 3730: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3731: if ($userenv->{$envkey} =~ /^autolimit=(\d*)$/) {
3732: my $currlimit = $1;
3733: if ($currlimit eq '') {
3734: $oldaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3735: } else {
3736: $oldaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$currlimit);
3737: }
3738: } elsif ($userenv->{$envkey}) {
3739: $oldaccesstext->{$tool} = $reqdisplay{$userenv->{$envkey}};
3740: } else {
3741: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
3742: }
1.275 raeburn 3743: } else {
1.383 raeburn 3744: if ($userenv->{$envkey}) {
3745: $oldaccesstext->{$tool} = &mt("availability set to 'on'");
3746: } else {
3747: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
3748: }
1.275 raeburn 3749: }
1.362 raeburn 3750: $changeHash->{$envkey} = $userenv->{$envkey};
1.275 raeburn 3751: if ($env{'form.custom'.$tool} == 1) {
1.362 raeburn 3752: if ($newval ne $userenv->{$envkey}) {
1.306 raeburn 3753: $changed->{$tool} = &tool_admin($tool,$newval,$changeHash,
3754: $context);
1.275 raeburn 3755: if ($changed->{$tool}) {
3756: $newaccess->{$tool} = &mt('custom');
1.383 raeburn 3757: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3758: if ($newval =~ /^autolimit/) {
3759: if ($limit) {
3760: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3761: } else {
3762: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3763: }
3764: } elsif ($newval) {
3765: $newaccesstext->{$tool} = $reqdisplay{$newval};
3766: } else {
3767: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3768: }
1.275 raeburn 3769: } else {
1.383 raeburn 3770: if ($newval) {
3771: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3772: } else {
3773: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3774: }
1.275 raeburn 3775: }
3776: } else {
3777: $newaccess->{$tool} = $oldaccess->{$tool};
1.383 raeburn 3778: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3779: if ($newval =~ /^autolimit/) {
3780: if ($limit) {
3781: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3782: } else {
3783: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3784: }
3785: } elsif ($newval) {
3786: $newaccesstext->{$tool} = $reqdisplay{$newval};
3787: } else {
3788: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3789: }
1.275 raeburn 3790: } else {
1.383 raeburn 3791: if ($userenv->{$context.'.'.$tool}) {
3792: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3793: } else {
3794: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3795: }
1.275 raeburn 3796: }
3797: }
3798: } else {
3799: $newaccess->{$tool} = $oldaccess->{$tool};
3800: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
3801: }
3802: } else {
3803: $changed->{$tool} = &tool_admin($tool,'',$changeHash,$context);
3804: if ($changed->{$tool}) {
3805: $newaccess->{$tool} = &mt('default');
3806: } else {
3807: $newaccess->{$tool} = $oldaccess->{$tool};
1.383 raeburn 3808: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3809: if ($newval =~ /^autolimit/) {
3810: if ($limit) {
3811: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3812: } else {
3813: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3814: }
3815: } elsif ($newval) {
3816: $newaccesstext->{$tool} = $reqdisplay{$newval};
3817: } else {
3818: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3819: }
1.275 raeburn 3820: } else {
1.383 raeburn 3821: if ($userenv->{$context.'.'.$tool}) {
3822: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3823: } else {
3824: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3825: }
1.275 raeburn 3826: }
3827: }
3828: }
3829: } else {
3830: $oldaccess->{$tool} = &mt('default');
3831: if ($env{'form.custom'.$tool} == 1) {
1.306 raeburn 3832: $changed->{$tool} = &tool_admin($tool,$newval,$changeHash,
3833: $context);
1.275 raeburn 3834: if ($changed->{$tool}) {
3835: $newaccess->{$tool} = &mt('custom');
1.383 raeburn 3836: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3837: if ($newval =~ /^autolimit/) {
3838: if ($limit) {
3839: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3840: } else {
3841: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3842: }
3843: } elsif ($newval) {
3844: $newaccesstext->{$tool} = $reqdisplay{$newval};
3845: } else {
3846: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3847: }
1.275 raeburn 3848: } else {
1.383 raeburn 3849: if ($newval) {
3850: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3851: } else {
3852: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3853: }
1.275 raeburn 3854: }
3855: } else {
3856: $newaccess->{$tool} = $oldaccess->{$tool};
3857: }
3858: } else {
3859: $newaccess->{$tool} = $oldaccess->{$tool};
3860: }
3861: }
3862: }
3863: return;
3864: }
3865:
1.414 raeburn 3866: sub adhocrole_changes {
3867: my ($changehashref,$userenv) = @_;
3868: my @adds = &Apache::loncommon::get_env_multiple('form.adhocroleadd');
3869: my @dels = &Apache::loncommon::get_env_multiple('form.adhocroledel');
3870: my (@saved,@added,@alladhoc,$changed);
3871: my $adhoc_key = 'adhocroles.'.$env{'request.role.domain'};
3872: if (!$env{'form.makeuser'}) {
3873: if (ref($userenv) eq 'HASH') {
3874: my @current;
3875: if ($userenv->{$adhoc_key}) {
3876: @current = split(/,/,$userenv->{$adhoc_key});
3877: if (@dels) {
3878: foreach my $curr (@current) {
1.417 raeburn 3879: next if ($curr eq '');
1.414 raeburn 3880: unless (grep(/\Q$curr\E$/,@dels)) {
3881: push(@saved,$curr);
3882: }
3883: }
3884: $changed = 1;
3885: } else {
3886: @saved = @current;
3887: }
3888: }
3889: }
3890: }
3891: if (@adds) {
3892: my $confname = &Apache::lonnet::get_domainconfiguser($env{'request.role.domain'});
3893: my %existing=&Apache::lonnet::dump('roles',$env{'request.role.domain'},
3894: $confname,'rolesdef_');
3895: foreach my $poss (@adds) {
3896: if (exists($existing{'rolesdef_'.$poss})) {
3897: push(@added,$poss);
3898: $changed = 1;
3899: }
3900: }
3901: }
3902: if (@added) {
3903: if (@saved) {
3904: foreach my $add (@added) {
3905: unless (grep(/^\Q$add\E$/,@saved)) {
3906: push(@alladhoc,$add);
3907: }
3908: }
3909: } else {
3910: push(@alladhoc,@added);
3911: }
3912: }
3913: if (@saved) {
3914: push(@alladhoc,@saved);
3915: }
3916: if (@alladhoc) {
1.417 raeburn 3917: my $adhocstr = join(',',sort(@alladhoc));
1.414 raeburn 3918: $changehashref->{$adhoc_key} = $adhocstr;
3919: } elsif (@dels) {
3920: &Apache::lonnet::del('environment',[$adhoc_key],$env{'form.ccdomain'},$env{'form.ccuname'});
3921: delete($changehashref->{$adhoc_key});
3922: if (($env{'form.ccdomain'} eq $env{'user.domain'}) &&
3923: ($env{'form.ccuname'} eq $env{'user.name'})) {
3924: &Apache::lonnet::delenv($adhoc_key);
3925: }
3926: }
3927: return $changed;
3928: }
3929:
1.220 raeburn 3930: sub update_roles {
1.375 raeburn 3931: my ($r,$context,$showcredits) = @_;
1.4 www 3932: my $now=time;
1.225 raeburn 3933: my @rolechanges;
1.220 raeburn 3934: my %disallowed;
1.73 sakharuk 3935: $r->print('<h3>'.&mt('Modifying Roles').'</h3>');
1.404 raeburn 3936: foreach my $key (keys(%env)) {
1.135 raeburn 3937: next if (! $env{$key});
1.190 raeburn 3938: next if ($key eq 'form.action');
1.27 matthew 3939: # Revoke roles
1.135 raeburn 3940: if ($key=~/^form\.rev/) {
3941: if ($key=~/^form\.rev\:([^\_]+)\_([^\_\.]+)$/) {
1.64 www 3942: # Revoke standard role
1.170 albertel 3943: my ($scope,$role) = ($1,$2);
3944: my $result =
3945: &Apache::lonnet::revokerole($env{'form.ccdomain'},
3946: $env{'form.ccuname'},
1.239 raeburn 3947: $scope,$role,'','',$context);
1.367 golterma 3948: $r->print(&Apache::lonhtmlcommon::confirm_success(
1.369 bisitz 3949: &mt('Revoking [_1] in [_2]',
3950: &Apache::lonnet::plaintext($role),
1.372 raeburn 3951: &Apache::loncommon::show_role_extent($scope,$context,$role)),
1.369 bisitz 3952: $result ne "ok").'<br />');
3953: if ($result ne "ok") {
3954: $r->print(&mt('Error: [_1]',$result).'<br />');
3955: }
1.170 albertel 3956: if ($role eq 'st') {
1.202 raeburn 3957: my $result =
1.198 raeburn 3958: &Apache::lonuserutils::classlist_drop($scope,
3959: $env{'form.ccuname'},$env{'form.ccdomain'},
1.202 raeburn 3960: $now);
1.367 golterma 3961: $r->print(&Apache::lonhtmlcommon::confirm_success($result));
1.53 www 3962: }
1.225 raeburn 3963: if (!grep(/^\Q$role\E$/,@rolechanges)) {
3964: push(@rolechanges,$role);
3965: }
1.196 raeburn 3966: }
1.195 raeburn 3967: if ($key=~m{^form\.rev\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}s) {
1.64 www 3968: # Revoke custom role
1.369 bisitz 3969: my $result = &Apache::lonnet::revokecustomrole(
3970: $env{'form.ccdomain'},$env{'form.ccuname'},$1,$2,$3,$4,'','',$context);
1.367 golterma 3971: $r->print(&Apache::lonhtmlcommon::confirm_success(
1.369 bisitz 3972: &mt('Revoking custom role [_1] by [_2] in [_3]',
1.372 raeburn 3973: $4,$3.':'.$2,&Apache::loncommon::show_role_extent($1,$context,'cr')),
1.369 bisitz 3974: $result ne 'ok').'<br />');
3975: if ($result ne "ok") {
3976: $r->print(&mt('Error: [_1]',$result).'<br />');
3977: }
1.225 raeburn 3978: if (!grep(/^cr$/,@rolechanges)) {
3979: push(@rolechanges,'cr');
3980: }
1.64 www 3981: }
1.135 raeburn 3982: } elsif ($key=~/^form\.del/) {
3983: if ($key=~/^form\.del\:([^\_]+)\_([^\_\.]+)$/) {
1.116 raeburn 3984: # Delete standard role
1.170 albertel 3985: my ($scope,$role) = ($1,$2);
3986: my $result =
3987: &Apache::lonnet::assignrole($env{'form.ccdomain'},
3988: $env{'form.ccuname'},
1.239 raeburn 3989: $scope,$role,$now,0,1,'',
3990: $context);
1.367 golterma 3991: $r->print(&Apache::lonhtmlcommon::confirm_success(
3992: &mt('Deleting [_1] in [_2]',
1.369 bisitz 3993: &Apache::lonnet::plaintext($role),
1.372 raeburn 3994: &Apache::loncommon::show_role_extent($scope,$context,$role)),
1.369 bisitz 3995: $result ne 'ok').'<br />');
3996: if ($result ne "ok") {
3997: $r->print(&mt('Error: [_1]',$result).'<br />');
3998: }
1.367 golterma 3999:
1.170 albertel 4000: if ($role eq 'st') {
1.202 raeburn 4001: my $result =
1.198 raeburn 4002: &Apache::lonuserutils::classlist_drop($scope,
4003: $env{'form.ccuname'},$env{'form.ccdomain'},
1.202 raeburn 4004: $now);
1.369 bisitz 4005: $r->print(&Apache::lonhtmlcommon::confirm_success($result));
1.81 albertel 4006: }
1.225 raeburn 4007: if (!grep(/^\Q$role\E$/,@rolechanges)) {
4008: push(@rolechanges,$role);
4009: }
1.116 raeburn 4010: }
1.139 albertel 4011: if ($key=~m{^form\.del\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
1.116 raeburn 4012: my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
4013: # Delete custom role
1.369 bisitz 4014: my $result =
4015: &Apache::lonnet::assigncustomrole($env{'form.ccdomain'},
4016: $env{'form.ccuname'},$url,$rdom,$rnam,$rolename,$now,
4017: 0,1,$context);
4018: $r->print(&Apache::lonhtmlcommon::confirm_success(&mt('Deleting custom role [_1] by [_2] in [_3]',
1.372 raeburn 4019: $rolename,$rnam.':'.$rdom,&Apache::loncommon::show_role_extent($1,$context,'cr')),
1.369 bisitz 4020: $result ne "ok").'<br />');
4021: if ($result ne "ok") {
4022: $r->print(&mt('Error: [_1]',$result).'<br />');
4023: }
1.367 golterma 4024:
1.225 raeburn 4025: if (!grep(/^cr$/,@rolechanges)) {
4026: push(@rolechanges,'cr');
4027: }
1.116 raeburn 4028: }
1.135 raeburn 4029: } elsif ($key=~/^form\.ren/) {
1.101 albertel 4030: my $udom = $env{'form.ccdomain'};
4031: my $uname = $env{'form.ccuname'};
1.116 raeburn 4032: # Re-enable standard role
1.135 raeburn 4033: if ($key=~/^form\.ren\:([^\_]+)\_([^\_\.]+)$/) {
1.89 raeburn 4034: my $url = $1;
4035: my $role = $2;
4036: my $logmsg;
4037: my $output;
4038: if ($role eq 'st') {
1.141 albertel 4039: if ($url =~ m-^/($match_domain)/($match_courseid)/?(\w*)$-) {
1.374 raeburn 4040: my ($cdom,$cnum,$csec) = ($1,$2,$3);
1.375 raeburn 4041: my $credits;
4042: if ($showcredits) {
4043: my $defaultcredits =
4044: &Apache::lonuserutils::get_defaultcredits($cdom,$cnum);
4045: $credits = &get_user_credits($defaultcredits,$cdom,$cnum);
4046: }
4047: my $result = &Apache::loncommon::commit_studentrole(\$logmsg,$udom,$uname,$url,$role,$now,0,$cdom,$cnum,$csec,$context,$credits);
1.220 raeburn 4048: if (($result =~ /^error/) || ($result eq 'not_in_class') || ($result eq 'unknown_course') || ($result eq 'refused')) {
1.223 raeburn 4049: if ($result eq 'refused' && $logmsg) {
4050: $output = $logmsg;
4051: } else {
1.369 bisitz 4052: $output = &mt('Error: [_1]',$result)."\n";
1.223 raeburn 4053: }
1.89 raeburn 4054: } else {
1.372 raeburn 4055: $output = &Apache::lonhtmlcommon::confirm_success(&mt('Assigning [_1] in [_2] starting [_3]',
4056: &Apache::lonnet::plaintext($role),
4057: &Apache::loncommon::show_role_extent($url,$context,'st'),
4058: &Apache::lonlocal::locallocaltime($now))).'<br />'.$logmsg.'<br />';
1.89 raeburn 4059: }
4060: }
4061: } else {
1.101 albertel 4062: my $result=&Apache::lonnet::assignrole($env{'form.ccdomain'},
1.239 raeburn 4063: $env{'form.ccuname'},$url,$role,0,$now,'','',
4064: $context);
1.367 golterma 4065: $output = &Apache::lonhtmlcommon::confirm_success(&mt('Re-enabling [_1] in [_2]',
1.372 raeburn 4066: &Apache::lonnet::plaintext($role),
4067: &Apache::loncommon::show_role_extent($url,$context,$role)),$result ne "ok").'<br />';
1.369 bisitz 4068: if ($result ne "ok") {
4069: $output .= &mt('Error: [_1]',$result).'<br />';
4070: }
4071: }
1.89 raeburn 4072: $r->print($output);
1.225 raeburn 4073: if (!grep(/^\Q$role\E$/,@rolechanges)) {
4074: push(@rolechanges,$role);
4075: }
1.113 raeburn 4076: }
1.116 raeburn 4077: # Re-enable custom role
1.139 albertel 4078: if ($key=~m{^form\.ren\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
1.116 raeburn 4079: my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
4080: my $result = &Apache::lonnet::assigncustomrole(
4081: $env{'form.ccdomain'}, $env{'form.ccuname'},
1.240 raeburn 4082: $url,$rdom,$rnam,$rolename,0,$now,undef,$context);
1.369 bisitz 4083: $r->print(&Apache::lonhtmlcommon::confirm_success(
4084: &mt('Re-enabling custom role [_1] by [_2] in [_3]',
1.372 raeburn 4085: $rolename,$rnam.':'.$rdom,&Apache::loncommon::show_role_extent($1,$context,'cr')),
1.369 bisitz 4086: $result ne "ok").'<br />');
4087: if ($result ne "ok") {
4088: $r->print(&mt('Error: [_1]',$result).'<br />');
4089: }
1.225 raeburn 4090: if (!grep(/^cr$/,@rolechanges)) {
4091: push(@rolechanges,'cr');
4092: }
1.116 raeburn 4093: }
1.135 raeburn 4094: } elsif ($key=~/^form\.act/) {
1.101 albertel 4095: my $udom = $env{'form.ccdomain'};
4096: my $uname = $env{'form.ccuname'};
1.141 albertel 4097: if ($key=~/^form\.act\_($match_domain)\_($match_courseid)\_cr_cr_($match_domain)_($match_username)_([^\_]+)$/) {
1.65 www 4098: # Activate a custom role
1.83 albertel 4099: my ($one,$two,$three,$four,$five)=($1,$2,$3,$4,$5);
4100: my $url='/'.$one.'/'.$two;
4101: my $full=$one.'_'.$two.'_cr_cr_'.$three.'_'.$four.'_'.$five;
1.65 www 4102:
1.101 albertel 4103: my $start = ( $env{'form.start_'.$full} ?
4104: $env{'form.start_'.$full} :
1.88 raeburn 4105: $now );
1.101 albertel 4106: my $end = ( $env{'form.end_'.$full} ?
4107: $env{'form.end_'.$full} :
1.88 raeburn 4108: 0 );
4109:
4110: # split multiple sections
4111: my %sections = ();
1.101 albertel 4112: my $num_sections = &build_roles($env{'form.sec_'.$full},\%sections,$5);
1.88 raeburn 4113: if ($num_sections == 0) {
1.240 raeburn 4114: $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$url,$three,$four,$five,$start,$end,$context));
1.88 raeburn 4115: } else {
1.114 albertel 4116: my %curr_groups =
1.117 raeburn 4117: &Apache::longroup::coursegroups($one,$two);
1.404 raeburn 4118: foreach my $sec (sort {$a cmp $b} keys(%sections)) {
1.113 raeburn 4119: if (($sec eq 'none') || ($sec eq 'all') ||
4120: exists($curr_groups{$sec})) {
4121: $disallowed{$sec} = $url;
4122: next;
4123: }
4124: my $securl = $url.'/'.$sec;
1.240 raeburn 4125: $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$securl,$three,$four,$five,$start,$end,$context));
1.88 raeburn 4126: }
4127: }
1.225 raeburn 4128: if (!grep(/^cr$/,@rolechanges)) {
4129: push(@rolechanges,'cr');
4130: }
1.142 raeburn 4131: } elsif ($key=~/^form\.act\_($match_domain)\_($match_name)\_([^\_]+)$/) {
1.27 matthew 4132: # Activate roles for sections with 3 id numbers
4133: # set start, end times, and the url for the class
1.83 albertel 4134: my ($one,$two,$three)=($1,$2,$3);
1.101 albertel 4135: my $start = ( $env{'form.start_'.$one.'_'.$two.'_'.$three} ?
4136: $env{'form.start_'.$one.'_'.$two.'_'.$three} :
1.27 matthew 4137: $now );
1.101 albertel 4138: my $end = ( $env{'form.end_'.$one.'_'.$two.'_'.$three} ?
4139: $env{'form.end_'.$one.'_'.$two.'_'.$three} :
1.27 matthew 4140: 0 );
1.83 albertel 4141: my $url='/'.$one.'/'.$two;
1.88 raeburn 4142: my $type = 'three';
4143: # split multiple sections
4144: my %sections = ();
1.101 albertel 4145: my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two.'_'.$three},\%sections,$three);
1.375 raeburn 4146: my $credits;
4147: if ($three eq 'st') {
4148: if ($showcredits) {
4149: my $defaultcredits =
4150: &Apache::lonuserutils::get_defaultcredits($one,$two);
4151: $credits = $env{'form.credits_'.$one.'_'.$two.'_'.$three};
4152: $credits =~ s/[^\d\.]//g;
4153: if ($credits eq $defaultcredits) {
4154: undef($credits);
4155: }
4156: }
4157: }
1.88 raeburn 4158: if ($num_sections == 0) {
1.375 raeburn 4159: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'',$context,$credits));
1.88 raeburn 4160: } else {
1.114 albertel 4161: my %curr_groups =
1.117 raeburn 4162: &Apache::longroup::coursegroups($one,$two);
1.88 raeburn 4163: my $emptysec = 0;
1.404 raeburn 4164: foreach my $sec (sort {$a cmp $b} keys(%sections)) {
1.88 raeburn 4165: $sec =~ s/\W//g;
1.113 raeburn 4166: if ($sec ne '') {
4167: if (($sec eq 'none') || ($sec eq 'all') ||
4168: exists($curr_groups{$sec})) {
4169: $disallowed{$sec} = $url;
4170: next;
4171: }
1.88 raeburn 4172: my $securl = $url.'/'.$sec;
1.375 raeburn 4173: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$three,$start,$end,$one,$two,$sec,$context,$credits));
1.88 raeburn 4174: } else {
4175: $emptysec = 1;
4176: }
4177: }
4178: if ($emptysec) {
1.375 raeburn 4179: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'',$context,$credits));
1.88 raeburn 4180: }
1.225 raeburn 4181: }
4182: if (!grep(/^\Q$three\E$/,@rolechanges)) {
4183: push(@rolechanges,$three);
4184: }
1.135 raeburn 4185: } elsif ($key=~/^form\.act\_([^\_]+)\_([^\_]+)$/) {
1.27 matthew 4186: # Activate roles for sections with two id numbers
4187: # set start, end times, and the url for the class
1.101 albertel 4188: my $start = ( $env{'form.start_'.$1.'_'.$2} ?
4189: $env{'form.start_'.$1.'_'.$2} :
1.27 matthew 4190: $now );
1.101 albertel 4191: my $end = ( $env{'form.end_'.$1.'_'.$2} ?
4192: $env{'form.end_'.$1.'_'.$2} :
1.27 matthew 4193: 0 );
1.225 raeburn 4194: my $one = $1;
4195: my $two = $2;
4196: my $url='/'.$one.'/';
1.88 raeburn 4197: # split multiple sections
4198: my %sections = ();
1.225 raeburn 4199: my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two},\%sections,$two);
1.88 raeburn 4200: if ($num_sections == 0) {
1.240 raeburn 4201: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,'',$context));
1.88 raeburn 4202: } else {
4203: my $emptysec = 0;
1.404 raeburn 4204: foreach my $sec (sort {$a cmp $b} keys(%sections)) {
1.88 raeburn 4205: if ($sec ne '') {
4206: my $securl = $url.'/'.$sec;
1.240 raeburn 4207: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$two,$start,$end,$one,undef,$sec,$context));
1.88 raeburn 4208: } else {
4209: $emptysec = 1;
4210: }
4211: }
4212: if ($emptysec) {
1.240 raeburn 4213: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,'',$context));
1.88 raeburn 4214: }
4215: }
1.225 raeburn 4216: if (!grep(/^\Q$two\E$/,@rolechanges)) {
4217: push(@rolechanges,$two);
4218: }
1.64 www 4219: } else {
1.190 raeburn 4220: $r->print('<p><span class="LC_error">'.&mt('ERROR').': '.&mt('Unknown command').' <tt>'.$key.'</tt></span></p><br />');
1.64 www 4221: }
1.113 raeburn 4222: foreach my $key (sort(keys(%disallowed))) {
1.274 bisitz 4223: $r->print('<p class="LC_warning">');
1.113 raeburn 4224: if (($key eq 'none') || ($key eq 'all')) {
1.274 bisitz 4225: $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 4226: } else {
1.274 bisitz 4227: $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 4228: }
1.274 bisitz 4229: $r->print('</p><p>'
4230: .&mt('Please [_1]go back[_2] and choose a different section name.'
4231: ,'<a href="javascript:history.go(-1)'
4232: ,'</a>')
4233: .'</p><br />'
4234: );
1.113 raeburn 4235: }
4236: }
1.101 albertel 4237: } # End of foreach (keys(%env))
1.75 www 4238: # Flush the course logs so reverse user roles immediately updated
1.349 raeburn 4239: $r->register_cleanup(\&Apache::lonnet::flushcourselogs);
1.225 raeburn 4240: if (@rolechanges == 0) {
1.372 raeburn 4241: $r->print('<p>'.&mt('No roles to modify').'</p>');
1.193 raeburn 4242: }
1.225 raeburn 4243: return @rolechanges;
1.220 raeburn 4244: }
4245:
1.375 raeburn 4246: sub get_user_credits {
4247: my ($uname,$udom,$defaultcredits,$cdom,$cnum) = @_;
4248: if ($cdom eq '' || $cnum eq '') {
4249: return unless ($env{'request.course.id'});
4250: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
4251: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
4252: }
4253: my $credits;
4254: my %currhash =
4255: &Apache::lonnet::get('classlist',[$uname.':'.$udom],$cdom,$cnum);
4256: if (keys(%currhash) > 0) {
4257: my @items = split(/:/,$currhash{$uname.':'.$udom});
4258: my $crdidx = &Apache::loncoursedata::CL_CREDITS() - 3;
4259: $credits = $items[$crdidx];
4260: $credits =~ s/[^\d\.]//g;
4261: }
4262: if ($credits eq $defaultcredits) {
4263: undef($credits);
4264: }
4265: return $credits;
4266: }
4267:
1.220 raeburn 4268: sub enroll_single_student {
1.375 raeburn 4269: my ($r,$uhome,$amode,$genpwd,$now,$newuser,$context,$crstype,
4270: $showcredits,$defaultcredits) = @_;
1.318 raeburn 4271: $r->print('<h3>');
4272: if ($crstype eq 'Community') {
4273: $r->print(&mt('Enrolling Member'));
4274: } else {
4275: $r->print(&mt('Enrolling Student'));
4276: }
4277: $r->print('</h3>');
1.220 raeburn 4278:
4279: # Remove non alphanumeric values from section
4280: $env{'form.sections'}=~s/\W//g;
4281:
1.375 raeburn 4282: my $credits;
4283: if (($showcredits) && ($env{'form.credits'} ne '')) {
4284: $credits = $env{'form.credits'};
4285: $credits =~ s/[^\d\.]//g;
4286: if ($credits ne '') {
4287: if ($credits eq $defaultcredits) {
4288: undef($credits);
4289: }
4290: }
4291: }
4292:
1.220 raeburn 4293: # Clean out any old student roles the user has in this class.
4294: &Apache::lonuserutils::modifystudent($env{'form.ccdomain'},
4295: $env{'form.ccuname'},$env{'request.course.id'},undef,$uhome);
4296: my ($startdate,$enddate) = &Apache::lonuserutils::get_dates_from_form();
4297: my $enroll_result =
4298: &Apache::lonnet::modify_student_enrollment($env{'form.ccdomain'},
4299: $env{'form.ccuname'},$env{'form.cid'},$env{'form.cfirstname'},
4300: $env{'form.cmiddlename'},$env{'form.clastname'},
4301: $env{'form.generation'},$env{'form.sections'},$enddate,
1.375 raeburn 4302: $startdate,'manual',undef,$env{'request.course.id'},'',$context,
4303: $credits);
1.220 raeburn 4304: if ($enroll_result =~ /^ok/) {
1.381 bisitz 4305: $r->print(&mt('[_1] enrolled','<b>'.$env{'form.ccuname'}.':'.$env{'form.ccdomain'}.'</b>'));
1.220 raeburn 4306: if ($env{'form.sections'} ne '') {
4307: $r->print(' '.&mt('in section [_1]',$env{'form.sections'}));
4308: }
4309: my ($showstart,$showend);
4310: if ($startdate <= $now) {
4311: $showstart = &mt('Access starts immediately');
4312: } else {
4313: $showstart = &mt('Access starts: ').&Apache::lonlocal::locallocaltime($startdate);
4314: }
4315: if ($enddate == 0) {
4316: $showend = &mt('ends: no ending date');
4317: } else {
4318: $showend = &mt('ends: ').&Apache::lonlocal::locallocaltime($enddate);
4319: }
4320: $r->print('.<br />'.$showstart.'; '.$showend);
4321: if ($startdate <= $now && !$newuser) {
1.386 bisitz 4322: $r->print('<p class="LC_info">');
1.318 raeburn 4323: if ($crstype eq 'Community') {
1.392 raeburn 4324: $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 4325: } else {
1.392 raeburn 4326: $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 4327: }
4328: $r->print('</p>');
1.220 raeburn 4329: }
4330: } else {
4331: $r->print(&mt('unable to enroll').": ".$enroll_result);
4332: }
4333: return;
1.188 raeburn 4334: }
4335:
1.204 raeburn 4336: sub get_defaultquota_text {
4337: my ($settingstatus) = @_;
4338: my $defquotatext;
4339: if ($settingstatus eq '') {
1.383 raeburn 4340: $defquotatext = &mt('default');
1.204 raeburn 4341: } else {
4342: my ($usertypes,$order) =
4343: &Apache::lonnet::retrieve_inst_usertypes($env{'form.ccdomain'});
4344: if ($usertypes->{$settingstatus} eq '') {
1.383 raeburn 4345: $defquotatext = &mt('default');
1.204 raeburn 4346: } else {
1.383 raeburn 4347: $defquotatext = &mt('default for [_1]',$usertypes->{$settingstatus});
1.204 raeburn 4348: }
4349: }
4350: return $defquotatext;
4351: }
4352:
1.188 raeburn 4353: sub update_result_form {
4354: my ($uhome) = @_;
4355: my $outcome =
1.367 golterma 4356: '<form name="userupdate" method="post" action="">'."\n";
1.160 raeburn 4357: foreach my $item ('srchby','srchin','srchtype','srchterm','srchdomain','ccuname','ccdomain') {
1.188 raeburn 4358: $outcome .= '<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n";
1.160 raeburn 4359: }
1.207 raeburn 4360: if ($env{'form.origname'} ne '') {
4361: $outcome .= '<input type="hidden" name="origname" value="'.$env{'form.origname'}.'" />'."\n";
4362: }
1.160 raeburn 4363: foreach my $item ('sortby','seluname','seludom') {
4364: if (exists($env{'form.'.$item})) {
1.188 raeburn 4365: $outcome .= '<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n";
1.160 raeburn 4366: }
4367: }
1.188 raeburn 4368: if ($uhome eq 'no_host') {
4369: $outcome .= '<input type="hidden" name="forcenewuser" value="1" />'."\n";
4370: }
4371: $outcome .= '<input type="hidden" name="phase" value="" />'."\n".
1.383 raeburn 4372: '<input type="hidden" name="currstate" value="" />'."\n".
4373: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n".
1.188 raeburn 4374: '</form>';
4375: return $outcome;
1.4 www 4376: }
4377:
1.149 raeburn 4378: sub quota_admin {
1.378 raeburn 4379: my ($setquota,$changeHash,$name) = @_;
1.149 raeburn 4380: my $quotachanged;
4381: if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
4382: # Current user has quota modification privileges
1.267 raeburn 4383: if (ref($changeHash) eq 'HASH') {
4384: $quotachanged = 1;
1.378 raeburn 4385: $changeHash->{$name.'quota'} = $setquota;
1.267 raeburn 4386: }
1.149 raeburn 4387: }
4388: return $quotachanged;
4389: }
4390:
1.267 raeburn 4391: sub tool_admin {
1.275 raeburn 4392: my ($tool,$settool,$changeHash,$context) = @_;
4393: my $canchange = 0;
1.279 raeburn 4394: if ($context eq 'requestcourses') {
1.275 raeburn 4395: if (&Apache::lonnet::allowed('ccc',$env{'form.ccdomain'})) {
4396: $canchange = 1;
4397: }
1.300 raeburn 4398: } elsif ($context eq 'reqcrsotherdom') {
4399: if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
4400: $canchange = 1;
4401: }
1.362 raeburn 4402: } elsif ($context eq 'requestauthor') {
4403: if (&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) {
4404: $canchange = 1;
4405: }
1.275 raeburn 4406: } elsif (&Apache::lonnet::allowed('mut',$env{'form.ccdomain'})) {
4407: # Current user has quota modification privileges
4408: $canchange = 1;
4409: }
1.267 raeburn 4410: my $toolchanged;
1.275 raeburn 4411: if ($canchange) {
1.267 raeburn 4412: if (ref($changeHash) eq 'HASH') {
4413: $toolchanged = 1;
1.362 raeburn 4414: if ($tool eq 'requestauthor') {
4415: $changeHash->{$context} = $settool;
4416: } else {
4417: $changeHash->{$context.'.'.$tool} = $settool;
4418: }
1.267 raeburn 4419: }
4420: }
4421: return $toolchanged;
4422: }
4423:
1.88 raeburn 4424: sub build_roles {
1.89 raeburn 4425: my ($sectionstr,$sections,$role) = @_;
1.88 raeburn 4426: my $num_sections = 0;
4427: if ($sectionstr=~ /,/) {
4428: my @secnums = split/,/,$sectionstr;
1.89 raeburn 4429: if ($role eq 'st') {
4430: $secnums[0] =~ s/\W//g;
4431: $$sections{$secnums[0]} = 1;
4432: $num_sections = 1;
4433: } else {
4434: foreach my $sec (@secnums) {
4435: $sec =~ ~s/\W//g;
1.150 banghart 4436: if (!($sec eq "")) {
1.89 raeburn 4437: if (exists($$sections{$sec})) {
4438: $$sections{$sec} ++;
4439: } else {
4440: $$sections{$sec} = 1;
4441: $num_sections ++;
4442: }
1.88 raeburn 4443: }
4444: }
4445: }
4446: } else {
4447: $sectionstr=~s/\W//g;
4448: unless ($sectionstr eq '') {
4449: $$sections{$sectionstr} = 1;
4450: $num_sections ++;
4451: }
4452: }
1.129 albertel 4453:
1.88 raeburn 4454: return $num_sections;
4455: }
4456:
1.58 www 4457: # ========================================================== Custom Role Editor
4458:
4459: sub custom_role_editor {
1.414 raeburn 4460: my ($r,$brcrum,$prefix) = @_;
1.324 raeburn 4461: my $action = $env{'form.customroleaction'};
4462: my $rolename;
4463: if ($action eq 'new') {
4464: $rolename=$env{'form.newrolename'};
4465: } else {
4466: $rolename=$env{'form.rolename'};
1.59 www 4467: }
4468:
1.324 raeburn 4469: my ($crstype,$context);
4470: if ($env{'request.course.id'}) {
4471: $crstype = &Apache::loncommon::course_type();
4472: $context = 'course';
4473: } else {
4474: $context = 'domain';
1.414 raeburn 4475: $crstype = 'course';
1.324 raeburn 4476: }
1.351 raeburn 4477:
4478: $rolename=~s/[^A-Za-z0-9]//gs;
4479: if (!$rolename || $env{'form.phase'} eq 'pickrole') {
4480: &print_username_entry_form($r,undef,undef,undef,undef,$crstype,$brcrum);
4481: return;
4482: }
4483:
1.414 raeburn 4484: my $formname = 'form1';
4485: my %privs=();
4486: my $body_top = '<h2>';
4487: # ------------------------------------------------------- Does this role exist?
1.59 www 4488: my ($rdummy,$roledef)=
4489: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
4490: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1.414 raeburn 4491: $body_top .= &mt('Existing Role').' "';
1.61 www 4492: # ------------------------------------------------- Get current role privileges
1.414 raeburn 4493: ($privs{'system'},$privs{'domain'},$privs{'course'})=split(/\_/,$roledef);
4494: if ($privs{'system'} =~ /bre\&S/) {
4495: if ($context eq 'domain') {
1.417 raeburn 4496: $crstype = 'Course';
1.414 raeburn 4497: } elsif ($crstype eq 'Community') {
4498: $privs{'system'} =~ s/bre\&S//;
4499: }
4500: } elsif ($context eq 'domain') {
4501: $crstype = 'Course';
1.324 raeburn 4502: }
1.59 www 4503: } else {
1.414 raeburn 4504: $body_top .= &mt('New Role').' "';
4505: $roledef='';
1.59 www 4506: }
1.153 banghart 4507: $body_top .= $rolename.'"</h2>';
1.414 raeburn 4508:
4509: # ------------------------------------------------------- What can be assigned?
4510: my %full=();
1.417 raeburn 4511: my %levels=(
1.414 raeburn 4512: course => {},
4513: domain => {},
4514: system => {},
4515: );
4516: my %levelscurrent=(
4517: course => {},
4518: domain => {},
4519: system => {},
4520: );
4521: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
1.160 raeburn 4522: my ($jsback,$elements) = &crumb_utilities();
1.414 raeburn 4523: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
1.417 raeburn 4524: my $head_script =
1.414 raeburn 4525: &Apache::lonuserutils::custom_roledefs_js($context,$crstype,$formname,
4526: \%full,\@templateroles,$jsback);
1.351 raeburn 4527: push (@{$brcrum},
1.414 raeburn 4528: {href => "javascript:backPage(document.$formname,'pickrole','')",
1.351 raeburn 4529: text => "Pick custom role",
4530: faq => 282,bug=>'Instructor Interface',},
1.414 raeburn 4531: {href => "javascript:backPage(document.$formname,'','')",
1.351 raeburn 4532: text => "Edit custom role",
4533: faq => 282,
4534: bug => 'Instructor Interface',
4535: help => 'Course_Editing_Custom_Roles'}
4536: );
4537: my $args = { bread_crumbs => $brcrum,
4538: bread_crumbs_component => 'User Management'};
4539:
4540: $r->print(&Apache::loncommon::start_page('Custom Role Editor',
4541: $head_script,$args).
4542: $body_top);
1.414 raeburn 4543: $r->print('<form name="'.$formname.'" method="post" action="">'."\n".
4544: &Apache::lonuserutils::custom_role_header($context,$crstype,
4545: \@templateroles,$prefix));
1.264 bisitz 4546:
1.61 www 4547: $r->print(<<ENDCCF);
4548: <input type="hidden" name="phase" value="set_custom_roles" />
4549: <input type="hidden" name="rolename" value="$rolename" />
4550: ENDCCF
1.414 raeburn 4551: $r->print(&Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
4552: \%levelscurrent,$prefix));
1.135 raeburn 4553: $r->print(&Apache::loncommon::end_data_table().
1.190 raeburn 4554: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'.
1.160 raeburn 4555: '<input type="hidden" name="startrolename" value="'.$env{'form.rolename'}.
1.417 raeburn 4556: '" />'."\n".'<input type="hidden" name="currstate" value="" />'."\n".
1.160 raeburn 4557: '<input type="reset" value="'.&mt("Reset").'" />'."\n".
1.351 raeburn 4558: '<input type="submit" value="'.&mt('Save').'" /></form>');
1.61 www 4559: }
1.414 raeburn 4560:
1.61 www 4561: # ---------------------------------------------------------- Call to definerole
4562: sub set_custom_role {
1.414 raeburn 4563: my ($r,$context,$brcrum,$prefix) = @_;
1.101 albertel 4564: my $rolename=$env{'form.rolename'};
1.63 www 4565: $rolename=~s/[^A-Za-z0-9]//gs;
1.150 banghart 4566: if (!$rolename) {
1.414 raeburn 4567: &custom_role_editor($r,$brcrum,$prefix);
1.61 www 4568: return;
4569: }
1.160 raeburn 4570: my ($jsback,$elements) = &crumb_utilities();
1.301 bisitz 4571: my $jscript = '<script type="text/javascript">'
4572: .'// <![CDATA['."\n"
4573: .$jsback."\n"
4574: .'// ]]>'."\n"
4575: .'</script>'."\n";
1.352 raeburn 4576: push(@{$brcrum},
4577: {href => "javascript:backPage(document.customresult,'pickrole','')",
4578: text => "Pick custom role",
4579: faq => 282,
4580: bug => 'Instructor Interface',},
4581: {href => "javascript:backPage(document.customresult,'selected_custom_edit','')",
4582: text => "Edit custom role",
4583: faq => 282,
4584: bug => 'Instructor Interface',},
4585: {href => "javascript:backPage(document.customresult,'set_custom_roles','')",
4586: text => "Result",
4587: faq => 282,
4588: bug => 'Instructor Interface',
4589: help => 'Course_Editing_Custom_Roles'},
4590: );
4591: my $args = { bread_crumbs => $brcrum,
1.414 raeburn 4592: bread_crumbs_component => 'User Management'};
1.351 raeburn 4593: $r->print(&Apache::loncommon::start_page('Save Custom Role',$jscript,$args));
1.160 raeburn 4594:
1.393 raeburn 4595: my $newrole;
1.61 www 4596: my ($rdummy,$roledef)=
1.110 albertel 4597: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
4598:
1.61 www 4599: # ------------------------------------------------------- Does this role exist?
1.188 raeburn 4600: $r->print('<h3>');
1.61 www 4601: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1.73 sakharuk 4602: $r->print(&mt('Existing Role').' "');
1.61 www 4603: } else {
1.73 sakharuk 4604: $r->print(&mt('New Role').' "');
1.61 www 4605: $roledef='';
1.393 raeburn 4606: $newrole = 1;
1.61 www 4607: }
1.188 raeburn 4608: $r->print($rolename.'"</h3>');
1.414 raeburn 4609: # ------------------------------------------------- Assign role and show result
1.61 www 4610:
1.387 bisitz 4611: my $errmsg;
1.414 raeburn 4612: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$prefix);
4613: # Assign role and return result
4614: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
4615: $newprivs{'c'});
1.387 bisitz 4616: if ($result ne 'ok') {
4617: $errmsg = ': '.$result;
4618: }
4619: my $message =
4620: &Apache::lonhtmlcommon::confirm_success(
4621: &mt('Defining Role').$errmsg, ($result eq 'ok' ? 0 : 1));
1.101 albertel 4622: if ($env{'request.course.id'}) {
4623: my $url='/'.$env{'request.course.id'};
1.63 www 4624: $url=~s/\_/\//g;
1.387 bisitz 4625: $result =
4626: &Apache::lonnet::assigncustomrole(
4627: $env{'user.domain'},$env{'user.name'},
4628: $url,
4629: $env{'user.domain'},$env{'user.name'},
4630: $rolename,undef,undef,undef,$context);
4631: if ($result ne 'ok') {
4632: $errmsg = ': '.$result;
4633: }
4634: $message .=
4635: '<br />'
4636: .&Apache::lonhtmlcommon::confirm_success(
4637: &mt('Assigning Role to Self').$errmsg, ($result eq 'ok' ? 0 : 1));
1.63 www 4638: }
1.380 bisitz 4639: $r->print(
1.387 bisitz 4640: &Apache::loncommon::confirmwrapper($message)
4641: .'<br />'
4642: .&Apache::lonhtmlcommon::actionbox([
4643: '<a href="javascript:backPage(document.customresult,'."'pickrole'".')">'
4644: .&mt('Create or edit another custom role')
4645: .'</a>'])
1.380 bisitz 4646: .'<form name="customresult" method="post" action="">'
1.387 bisitz 4647: .&Apache::lonhtmlcommon::echo_form_input([])
4648: .'</form>'
1.380 bisitz 4649: );
1.58 www 4650: }
4651:
1.2 www 4652: # ================================================================ Main Handler
4653: sub handler {
4654: my $r = shift;
4655: if ($r->header_only) {
1.68 www 4656: &Apache::loncommon::content_type($r,'text/html');
1.2 www 4657: $r->send_http_header;
4658: return OK;
4659: }
1.318 raeburn 4660: my ($context,$crstype);
1.190 raeburn 4661: if ($env{'request.course.id'}) {
4662: $context = 'course';
1.318 raeburn 4663: $crstype = &Apache::loncommon::course_type();
1.190 raeburn 4664: } elsif ($env{'request.role'} =~ /^au\./) {
1.206 raeburn 4665: $context = 'author';
1.190 raeburn 4666: } else {
4667: $context = 'domain';
4668: }
1.375 raeburn 4669:
1.190 raeburn 4670: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.233 raeburn 4671: ['action','state','callingform','roletype','showrole','bulkaction','popup','phase',
1.391 raeburn 4672: 'username','domain','srchterm','srchdomain','srchin','srchby','srchtype','queue']);
1.190 raeburn 4673: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.351 raeburn 4674: my $args;
4675: my $brcrum = [];
4676: my $bread_crumbs_component = 'User Management';
1.391 raeburn 4677: if (($env{'form.action'} ne 'dateselect') && ($env{'form.action'} ne 'displayuserreq')) {
1.351 raeburn 4678: $brcrum = [{href=>"/adm/createuser",
4679: text=>"User Management",
4680: 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'}
4681: ];
1.202 raeburn 4682: }
1.289 droeschl 4683: #SD Following files not added to help, because the corresponding .tex-files seem to
4684: #be missing: Course_Approve_Selfenroll,Course_User_Logs,
1.209 raeburn 4685: my ($permission,$allowed) =
1.318 raeburn 4686: &Apache::lonuserutils::get_permission($context,$crstype);
1.190 raeburn 4687: if (!$allowed) {
1.358 raeburn 4688: if ($context eq 'course') {
4689: $r->internal_redirect('/adm/viewclasslist');
4690: return OK;
4691: }
1.190 raeburn 4692: $env{'user.error.msg'}=
4693: "/adm/createuser:cst:0:0:Cannot create/modify user data ".
4694: "or view user status.";
4695: return HTTP_NOT_ACCEPTABLE;
4696: }
4697:
4698: &Apache::loncommon::content_type($r,'text/html');
4699: $r->send_http_header;
4700:
1.375 raeburn 4701: my $showcredits;
4702: if ((($context eq 'course') && ($crstype eq 'Course')) ||
4703: ($context eq 'domain')) {
4704: my %domdefaults =
4705: &Apache::lonnet::get_domain_defaults($env{'request.role.domain'});
4706: if ($domdefaults{'officialcredits'} || $domdefaults{'unofficialcredits'}) {
4707: $showcredits = 1;
4708: }
4709: }
4710:
1.190 raeburn 4711: # Main switch on form.action and form.state, as appropriate
4712: if (! exists($env{'form.action'})) {
1.351 raeburn 4713: $args = {bread_crumbs => $brcrum,
4714: bread_crumbs_component => $bread_crumbs_component};
4715: $r->print(&header(undef,$args));
1.318 raeburn 4716: $r->print(&print_main_menu($permission,$context,$crstype));
1.190 raeburn 4717: } elsif ($env{'form.action'} eq 'upload' && $permission->{'cusr'}) {
1.351 raeburn 4718: push(@{$brcrum},
4719: { href => '/adm/createuser?action=upload&state=',
4720: text => 'Upload Users List',
4721: help => 'Course_Create_Class_List',
4722: });
4723: $bread_crumbs_component = 'Upload Users List';
4724: $args = {bread_crumbs => $brcrum,
4725: bread_crumbs_component => $bread_crumbs_component};
4726: $r->print(&header(undef,$args));
1.190 raeburn 4727: $r->print('<form name="studentform" method="post" '.
4728: 'enctype="multipart/form-data" '.
4729: ' action="/adm/createuser">'."\n");
4730: if (! exists($env{'form.state'})) {
4731: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
4732: } elsif ($env{'form.state'} eq 'got_file') {
1.375 raeburn 4733: &Apache::lonuserutils::print_upload_manager_form($r,$context,$permission,
4734: $crstype,$showcredits);
1.190 raeburn 4735: } elsif ($env{'form.state'} eq 'enrolling') {
4736: if ($env{'form.datatoken'}) {
1.375 raeburn 4737: &Apache::lonuserutils::upfile_drop_add($r,$context,$permission,
4738: $showcredits);
1.190 raeburn 4739: }
4740: } else {
4741: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
4742: }
1.416 raeburn 4743: } elsif (((($env{'form.action'} eq 'singleuser') || ($env{'form.action'}
4744: eq 'singlestudent')) && ($permission->{'cusr'})) ||
1.418 raeburn 4745: (($env{'form.action'} eq 'singleuser') && ($permission->{'view'})) ||
1.416 raeburn 4746: (($env{'form.action'} eq 'accesslogs') && ($permission->{'activity'}))) {
1.190 raeburn 4747: my $phase = $env{'form.phase'};
4748: my @search = ('srchterm','srchby','srchin','srchtype','srchdomain');
1.192 albertel 4749: &Apache::loncreateuser::restore_prev_selections();
4750: my $srch;
4751: foreach my $item (@search) {
4752: $srch->{$item} = $env{'form.'.$item};
4753: }
1.207 raeburn 4754: if (($phase eq 'get_user_info') || ($phase eq 'userpicked') ||
1.416 raeburn 4755: ($phase eq 'createnewuser') || ($phase eq 'activity')) {
1.207 raeburn 4756: if ($env{'form.phase'} eq 'createnewuser') {
4757: my $response;
4758: if ($env{'form.srchterm'} !~ /^$match_username$/) {
1.366 bisitz 4759: my $response =
4760: '<span class="LC_warning">'
4761: .&mt('You must specify a valid username. Only the following are allowed:'
4762: .' letters numbers - . @')
4763: .'</span>';
1.221 raeburn 4764: $env{'form.phase'} = '';
1.375 raeburn 4765: &print_username_entry_form($r,$context,$response,$srch,undef,
4766: $crstype,$brcrum,$showcredits);
1.207 raeburn 4767: } else {
4768: my $ccuname =&LONCAPA::clean_username($srch->{'srchterm'});
4769: my $ccdomain=&LONCAPA::clean_domain($srch->{'srchdomain'});
4770: &print_user_modification_page($r,$ccuname,$ccdomain,
1.221 raeburn 4771: $srch,$response,$context,
1.375 raeburn 4772: $permission,$crstype,$brcrum,
4773: $showcredits);
1.207 raeburn 4774: }
4775: } elsif ($env{'form.phase'} eq 'get_user_info') {
1.190 raeburn 4776: my ($currstate,$response,$forcenewuser,$results) =
1.221 raeburn 4777: &user_search_result($context,$srch);
1.190 raeburn 4778: if ($env{'form.currstate'} eq 'modify') {
4779: $currstate = $env{'form.currstate'};
4780: }
4781: if ($currstate eq 'select') {
4782: &print_user_selection_page($r,$response,$srch,$results,
1.351 raeburn 4783: \@search,$context,undef,$crstype,
4784: $brcrum);
1.416 raeburn 4785: } elsif (($currstate eq 'modify') || ($env{'form.action'} eq 'accesslogs')) {
4786: my ($ccuname,$ccdomain,$uhome);
1.190 raeburn 4787: if (($srch->{'srchby'} eq 'uname') &&
4788: ($srch->{'srchtype'} eq 'exact')) {
4789: $ccuname = $srch->{'srchterm'};
4790: $ccdomain= $srch->{'srchdomain'};
4791: } else {
4792: my @matchedunames = keys(%{$results});
4793: ($ccuname,$ccdomain) = split(/:/,$matchedunames[0]);
4794: }
4795: $ccuname =&LONCAPA::clean_username($ccuname);
4796: $ccdomain=&LONCAPA::clean_domain($ccdomain);
1.416 raeburn 4797: if ($env{'form.action'} eq 'accesslogs') {
4798: my $uhome;
4799: if (($ccuname ne '') && ($ccdomain ne '')) {
4800: $uhome = &Apache::lonnet::homeserver($ccuname,$ccdomain);
4801: }
4802: if (($uhome eq '') || ($uhome eq 'no_host')) {
4803: $env{'form.phase'} = '';
4804: undef($forcenewuser);
4805: #if ($response) {
4806: # unless ($response =~ m{\Q<br /><br />\E$}) {
4807: # $response .= '<br /><br />';
4808: # }
4809: #}
4810: &print_username_entry_form($r,$context,$response,$srch,
4811: $forcenewuser,$crstype,$brcrum);
4812: } else {
4813: &print_useraccesslogs_display($r,$ccuname,$ccdomain,$permission,$brcrum);
4814: }
4815: } else {
4816: if ($env{'form.forcenewuser'}) {
4817: $response = '';
4818: }
4819: &print_user_modification_page($r,$ccuname,$ccdomain,
4820: $srch,$response,$context,
4821: $permission,$crstype,$brcrum);
1.190 raeburn 4822: }
4823: } elsif ($currstate eq 'query') {
1.351 raeburn 4824: &print_user_query_page($r,'createuser',$brcrum);
1.190 raeburn 4825: } else {
1.229 raeburn 4826: $env{'form.phase'} = '';
1.207 raeburn 4827: &print_username_entry_form($r,$context,$response,$srch,
1.351 raeburn 4828: $forcenewuser,$crstype,$brcrum);
1.190 raeburn 4829: }
4830: } elsif ($env{'form.phase'} eq 'userpicked') {
4831: my $ccuname = &LONCAPA::clean_username($env{'form.seluname'});
4832: my $ccdomain = &LONCAPA::clean_domain($env{'form.seludom'});
1.416 raeburn 4833: if ($env{'form.action'} eq 'accesslogs') {
4834: &print_useraccesslogs_display($r,$ccuname,$ccdomain,$permission,$brcrum);
4835: } else {
4836: &print_user_modification_page($r,$ccuname,$ccdomain,$srch,'',
4837: $context,$permission,$crstype,
4838: $brcrum);
4839: }
4840: } elsif ($env{'form.action'} eq 'accesslogs') {
4841: my $ccuname = &LONCAPA::clean_username($env{'form.accessuname'});
4842: my $ccdomain = &LONCAPA::clean_domain($env{'form.accessudom'});
4843: &print_useraccesslogs_display($r,$ccuname,$ccdomain,$permission,$brcrum);
1.190 raeburn 4844: }
4845: } elsif ($env{'form.phase'} eq 'update_user_data') {
1.375 raeburn 4846: &update_user_data($r,$context,$crstype,$brcrum,$showcredits);
1.190 raeburn 4847: } else {
1.351 raeburn 4848: &print_username_entry_form($r,$context,undef,$srch,undef,$crstype,
4849: $brcrum);
1.190 raeburn 4850: }
4851: } elsif ($env{'form.action'} eq 'custom' && $permission->{'custom'}) {
1.414 raeburn 4852: my $prefix;
1.190 raeburn 4853: if ($env{'form.phase'} eq 'set_custom_roles') {
1.414 raeburn 4854: &set_custom_role($r,$context,$brcrum,$prefix);
1.190 raeburn 4855: } else {
1.414 raeburn 4856: &custom_role_editor($r,$brcrum,$prefix);
1.190 raeburn 4857: }
1.362 raeburn 4858: } elsif (($env{'form.action'} eq 'processauthorreq') &&
4859: ($permission->{'cusr'}) &&
4860: (&Apache::lonnet::allowed('cau',$env{'request.role.domain'}))) {
4861: push(@{$brcrum},
4862: {href => '/adm/createuser?action=processauthorreq',
1.385 bisitz 4863: text => 'Authoring Space requests',
1.362 raeburn 4864: help => 'Domain_Role_Approvals'});
4865: $bread_crumbs_component = 'Authoring requests';
4866: if ($env{'form.state'} eq 'done') {
4867: push(@{$brcrum},
4868: {href => '/adm/createuser?action=authorreqqueue',
4869: text => 'Result',
4870: help => 'Domain_Role_Approvals'});
4871: $bread_crumbs_component = 'Authoring request result';
4872: }
4873: $args = { bread_crumbs => $brcrum,
4874: bread_crumbs_component => $bread_crumbs_component};
1.391 raeburn 4875: my $js = &usernamerequest_javascript();
4876: $r->print(&header(&add_script($js),$args));
1.362 raeburn 4877: if (!exists($env{'form.state'})) {
4878: $r->print(&Apache::loncoursequeueadmin::display_queued_requests('requestauthor',
4879: $env{'request.role.domain'}));
4880: } elsif ($env{'form.state'} eq 'done') {
4881: $r->print('<h3>'.&mt('Authoring request processing').'</h3>'."\n");
4882: $r->print(&Apache::loncoursequeueadmin::update_request_queue('requestauthor',
4883: $env{'request.role.domain'}));
4884: }
1.391 raeburn 4885: } elsif (($env{'form.action'} eq 'processusernamereq') &&
4886: ($permission->{'cusr'}) &&
4887: (&Apache::lonnet::allowed('cau',$env{'request.role.domain'}))) {
4888: push(@{$brcrum},
4889: {href => '/adm/createuser?action=processusernamereq',
4890: text => 'LON-CAPA account requests',
4891: help => 'Domain_Username_Approvals'});
4892: $bread_crumbs_component = 'Account requests';
4893: if ($env{'form.state'} eq 'done') {
4894: push(@{$brcrum},
4895: {href => '/adm/createuser?action=usernamereqqueue',
4896: text => 'Result',
4897: help => 'Domain_Username_Approvals'});
4898: $bread_crumbs_component = 'LON-CAPA account request result';
4899: }
4900: $args = { bread_crumbs => $brcrum,
4901: bread_crumbs_component => $bread_crumbs_component};
4902: my $js = &usernamerequest_javascript();
4903: $r->print(&header(&add_script($js),$args));
4904: if (!exists($env{'form.state'})) {
4905: $r->print(&Apache::loncoursequeueadmin::display_queued_requests('requestusername',
4906: $env{'request.role.domain'}));
4907: } elsif ($env{'form.state'} eq 'done') {
4908: $r->print('<h3>'.&mt('LON-CAPA account request processing').'</h3>'."\n");
4909: $r->print(&Apache::loncoursequeueadmin::update_request_queue('requestusername',
4910: $env{'request.role.domain'}));
4911: }
4912: } elsif (($env{'form.action'} eq 'displayuserreq') &&
4913: ($permission->{'cusr'})) {
4914: my $dom = $env{'form.domain'};
4915: my $uname = $env{'form.username'};
4916: my $warning;
4917: if (($dom =~ /^$match_domain$/) && (&Apache::lonnet::domain($dom) ne '')) {
4918: if (($dom eq $env{'request.role.domain'}) && (&Apache::lonnet::allowed('ccc',$dom))) {
4919: if (($uname =~ /^$match_username$/) && ($env{'form.queue'} eq 'approval')) {
4920: my $uhome = &Apache::lonnet::homeserver($uname,$dom);
4921: if ($uhome eq 'no_host') {
4922: my $queue = $env{'form.queue'};
4923: my $reqkey = &escape($uname).'_'.$queue;
4924: my $namespace = 'usernamequeue';
4925: my $domconfig = &Apache::lonnet::get_domainconfiguser($dom);
4926: my %queued =
4927: &Apache::lonnet::get($namespace,[$reqkey],$dom,$domconfig);
4928: unless ($queued{$reqkey}) {
4929: $warning = &mt('No information was found for this LON-CAPA account request.');
4930: }
4931: } else {
4932: $warning = &mt('A LON-CAPA account already exists for the requested username and domain.');
4933: }
4934: } else {
4935: $warning = &mt('LON-CAPA account request status check is for an invalid username.');
4936: }
4937: } else {
4938: $warning = &mt('You do not have rights to view LON-CAPA account requests in the domain specified.');
4939: }
4940: } else {
4941: $warning = &mt('LON-CAPA account request status check is for an invalid domain.');
4942: }
4943: my $args = { only_body => 1 };
4944: $r->print(&header(undef,$args).
4945: '<h3>'.&mt('LON-CAPA Account Request Details').'</h3>');
4946: if ($warning ne '') {
4947: $r->print('<div class="LC_warning">'.$warning.'</div>');
4948: } else {
4949: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
4950: my $domconfiguser = &Apache::lonnet::get_domainconfiguser($dom);
4951: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
4952: if (ref($domconfig{'usercreation'}) eq 'HASH') {
4953: if (ref($domconfig{'usercreation'}{'cancreate'}) eq 'HASH') {
4954: if (ref($domconfig{'usercreation'}{'cancreate'}{'emailusername'}) eq 'HASH') {
4955: my %info =
4956: &Apache::lonnet::get('nohist_requestedusernames',[$uname],$dom,$domconfiguser);
4957: if (ref($info{$uname}) eq 'HASH') {
1.396 raeburn 4958: my $usertype = $info{$uname}{'inststatus'};
4959: unless ($usertype) {
4960: $usertype = 'default';
4961: }
4962: if (ref($domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}) eq 'HASH') {
4963: if ((ref($infofields) eq 'ARRAY') && (ref($infotitles) eq 'HASH')) {
4964: $r->print('<div>'.&Apache::lonhtmlcommon::start_pick_box());
4965: my ($num,$count,$showstatus);
4966: $count = scalar(keys(%{$domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}}));
4967: unless ($usertype eq 'default') {
4968: my ($othertitle,$usertypes,$types) =
4969: &Apache::loncommon::sorted_inst_types($dom);
4970: if (ref($usertypes) eq 'HASH') {
4971: if ($usertypes->{$usertype}) {
4972: $showstatus = $usertypes->{$usertype};
4973: $count ++;
4974: }
4975: }
4976: }
4977: foreach my $field (@{$infofields}) {
4978: next unless ($domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}{$field});
4979: next unless ($infotitles->{$field});
4980: $r->print(&Apache::lonhtmlcommon::row_title($infotitles->{$field}).
4981: $info{$uname}{$field});
4982: $num ++;
4983: if ($count == $num) {
4984: $r->print(&Apache::lonhtmlcommon::row_closure(1));
4985: } else {
4986: $r->print(&Apache::lonhtmlcommon::row_closure());
4987: }
4988: }
4989: if ($showstatus) {
4990: $r->print(&Apache::lonhtmlcommon::row_title(&mt('Status type (self-reported)')).
4991: $showstatus.
4992: &Apache::lonhtmlcommon::row_closure(1));
1.391 raeburn 4993: }
1.396 raeburn 4994: $r->print(&Apache::lonhtmlcommon::end_pick_box().'</div>');
1.391 raeburn 4995: }
4996: }
4997: }
4998: }
4999: }
5000: }
5001: $r->print(&close_popup_form());
5002: }
1.207 raeburn 5003: } elsif (($env{'form.action'} eq 'listusers') &&
5004: ($permission->{'view'} || $permission->{'cusr'})) {
1.202 raeburn 5005: if ($env{'form.phase'} eq 'bulkchange') {
1.351 raeburn 5006: push(@{$brcrum},
5007: {href => '/adm/createuser?action=listusers',
5008: text => "List Users"},
5009: {href => "/adm/createuser",
5010: text => "Result",
5011: help => 'Course_View_Class_List'});
5012: $bread_crumbs_component = 'Update Users';
5013: $args = {bread_crumbs => $brcrum,
5014: bread_crumbs_component => $bread_crumbs_component};
5015: $r->print(&header(undef,$args));
1.202 raeburn 5016: my $setting = $env{'form.roletype'};
5017: my $choice = $env{'form.bulkaction'};
5018: if ($permission->{'cusr'}) {
1.336 raeburn 5019: &Apache::lonuserutils::update_user_list($r,$context,$setting,$choice,$crstype);
1.221 raeburn 5020: } else {
5021: $r->print(&mt('You are not authorized to make bulk changes to user roles'));
1.223 raeburn 5022: $r->print('<p><a href="/adm/createuser?action=listusers">'.&mt('Display User Lists').'</a>');
1.202 raeburn 5023: }
5024: } else {
1.351 raeburn 5025: push(@{$brcrum},
5026: {href => '/adm/createuser?action=listusers',
5027: text => "List Users",
5028: help => 'Course_View_Class_List'});
5029: $bread_crumbs_component = 'List Users';
5030: $args = {bread_crumbs => $brcrum,
5031: bread_crumbs_component => $bread_crumbs_component};
1.202 raeburn 5032: my ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles);
5033: my $formname = 'studentform';
1.364 raeburn 5034: my $hidecall = "hide_searching();";
1.321 raeburn 5035: if (($context eq 'domain') && (($env{'form.roletype'} eq 'course') ||
5036: ($env{'form.roletype'} eq 'community'))) {
5037: if ($env{'form.roletype'} eq 'course') {
5038: ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles) =
5039: &Apache::lonuserutils::courses_selector($env{'request.role.domain'},
5040: $formname);
5041: } elsif ($env{'form.roletype'} eq 'community') {
5042: $cb_jscript =
5043: &Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
5044: my %elements = (
5045: coursepick => 'radio',
5046: coursetotal => 'text',
5047: courselist => 'text',
5048: );
5049: $jscript = &Apache::lonhtmlcommon::set_form_elements(\%elements);
5050: }
1.364 raeburn 5051: $jscript .= &verify_user_display($context)."\n".
5052: &Apache::loncommon::check_uncheck_jscript();
1.202 raeburn 5053: my $js = &add_script($jscript).$cb_jscript;
5054: my $loadcode =
5055: &Apache::lonuserutils::course_selector_loadcode($formname);
5056: if ($loadcode ne '') {
1.364 raeburn 5057: $args->{add_entries} = {onload => "$loadcode;$hidecall"};
5058: } else {
5059: $args->{add_entries} = {onload => $hidecall};
1.202 raeburn 5060: }
1.351 raeburn 5061: $r->print(&header($js,$args));
1.191 raeburn 5062: } else {
1.364 raeburn 5063: $args->{add_entries} = {onload => $hidecall};
5064: $jscript = &verify_user_display($context).
5065: &Apache::loncommon::check_uncheck_jscript();
5066: $r->print(&header(&add_script($jscript),$args));
1.191 raeburn 5067: }
1.202 raeburn 5068: &Apache::lonuserutils::print_userlist($r,undef,$permission,$context,
1.375 raeburn 5069: $formname,$totcodes,$codetitles,$idlist,$idlist_titles,
5070: $showcredits);
1.191 raeburn 5071: }
1.213 raeburn 5072: } elsif ($env{'form.action'} eq 'drop' && $permission->{'cusr'}) {
1.318 raeburn 5073: my $brtext;
5074: if ($crstype eq 'Community') {
5075: $brtext = 'Drop Members';
5076: } else {
5077: $brtext = 'Drop Students';
5078: }
1.351 raeburn 5079: push(@{$brcrum},
5080: {href => '/adm/createuser?action=drop',
5081: text => $brtext,
5082: help => 'Course_Drop_Student'});
5083: if ($env{'form.state'} eq 'done') {
5084: push(@{$brcrum},
5085: {href=>'/adm/createuser?action=drop',
5086: text=>"Result"});
5087: }
5088: $bread_crumbs_component = $brtext;
5089: $args = {bread_crumbs => $brcrum,
5090: bread_crumbs_component => $bread_crumbs_component};
5091: $r->print(&header(undef,$args));
1.213 raeburn 5092: if (!exists($env{'form.state'})) {
1.318 raeburn 5093: &Apache::lonuserutils::print_drop_menu($r,$context,$permission,$crstype);
1.213 raeburn 5094: } elsif ($env{'form.state'} eq 'done') {
5095: &Apache::lonuserutils::update_user_list($r,$context,undef,
5096: $env{'form.action'});
5097: }
1.202 raeburn 5098: } elsif ($env{'form.action'} eq 'dateselect') {
5099: if ($permission->{'cusr'}) {
1.351 raeburn 5100: $r->print(&header(undef,{'no_nav_bar' => 1}).
1.375 raeburn 5101: &Apache::lonuserutils::date_section_selector($context,$permission,
5102: $crstype,$showcredits));
1.202 raeburn 5103: } else {
1.351 raeburn 5104: $r->print(&header(undef,{'no_nav_bar' => 1}).
5105: '<span class="LC_error">'.&mt('You do not have permission to modify dates or sections for users').'</span>');
1.202 raeburn 5106: }
1.237 raeburn 5107: } elsif ($env{'form.action'} eq 'selfenroll') {
1.398 raeburn 5108: if ($permission->{selfenrolladmin}) {
5109: my $cid = $env{'request.course.id'};
5110: my $cdom = $env{'course.'.$cid.'.domain'};
5111: my $cnum = $env{'course.'.$cid.'.num'};
5112: my %currsettings = (
5113: selfenroll_types => $env{'course.'.$cid.'.internal.selfenroll_types'},
5114: selfenroll_registered => $env{'course.'.$cid.'.internal.selfenroll_registered'},
5115: selfenroll_section => $env{'course.'.$cid.'.internal.selfenroll_section'},
5116: selfenroll_notifylist => $env{'course.'.$cid.'.internal.selfenroll_notifylist'},
5117: selfenroll_approval => $env{'course.'.$cid.'.internal.selfenroll_approval'},
5118: selfenroll_limit => $env{'course.'.$cid.'.internal.selfenroll_limit'},
5119: selfenroll_cap => $env{'course.'.$cid.'.internal.selfenroll_cap'},
5120: selfenroll_start_date => $env{'course.'.$cid.'.internal.selfenroll_start_date'},
5121: selfenroll_end_date => $env{'course.'.$cid.'.internal.selfenroll_end_date'},
5122: selfenroll_start_access => $env{'course.'.$cid.'.internal.selfenroll_start_access'},
5123: selfenroll_end_access => $env{'course.'.$cid.'.internal.selfenroll_end_access'},
5124: default_enrollment_start_date => $env{'course.'.$cid.'.default_enrollment_start_date'},
5125: default_enrollment_end_date => $env{'course.'.$cid.'.default_enrollment_end_date'},
1.400 raeburn 5126: uniquecode => $env{'course.'.$cid.'.internal.uniquecode'},
1.398 raeburn 5127: );
5128: push(@{$brcrum},
5129: {href => '/adm/createuser?action=selfenroll',
5130: text => "Configure Self-enrollment",
5131: help => 'Course_Self_Enrollment'});
5132: if (!exists($env{'form.state'})) {
5133: $args = { bread_crumbs => $brcrum,
5134: bread_crumbs_component => 'Configure Self-enrollment'};
5135: $r->print(&header(undef,$args));
5136: $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n");
5137: &print_selfenroll_menu($r,'course',$cid,$cdom,$cnum,\%currsettings);
5138: } elsif ($env{'form.state'} eq 'done') {
5139: push (@{$brcrum},
5140: {href=>'/adm/createuser?action=selfenroll',
5141: text=>"Result"});
5142: $args = { bread_crumbs => $brcrum,
5143: bread_crumbs_component => 'Self-enrollment result'};
5144: $r->print(&header(undef,$args));
5145: $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n");
1.400 raeburn 5146: &update_selfenroll_config($r,$cid,$cdom,$cnum,$context,$crstype,\%currsettings);
1.398 raeburn 5147: }
5148: } else {
5149: $r->print(&header(undef,{'no_nav_bar' => 1}).
5150: '<span class="LC_error">'.&mt('You do not have permission to configure self-enrollment').'</span>');
1.237 raeburn 5151: }
1.277 raeburn 5152: } elsif ($env{'form.action'} eq 'selfenrollqueue') {
1.418 raeburn 5153: if ($permission->{selfenrolladmin}) {
1.351 raeburn 5154: push(@{$brcrum},
5155: {href => '/adm/createuser?action=selfenrollqueue',
1.418 raeburn 5156: text => 'Enrollment requests',
1.351 raeburn 5157: help => 'Course_Self_Enrollment'});
1.418 raeburn 5158: $bread_crumbs_component = 'Enrollment requests';
5159: if ($env{'form.state'} eq 'done') {
5160: push(@{$brcrum},
5161: {href => '/adm/createuser?action=selfenrollqueue',
5162: text => 'Result',
5163: help => 'Course_Self_Enrollment'});
5164: $bread_crumbs_component = 'Enrollment result';
5165: }
5166: $args = { bread_crumbs => $brcrum,
5167: bread_crumbs_component => $bread_crumbs_component};
5168: $r->print(&header(undef,$args));
5169: my $cid = $env{'request.course.id'};
5170: my $cdom = $env{'course.'.$cid.'.domain'};
5171: my $cnum = $env{'course.'.$cid.'.num'};
5172: my $coursedesc = $env{'course.'.$cid.'.description'};
5173: if (!exists($env{'form.state'})) {
5174: $r->print('<h3>'.&mt('Pending enrollment requests').'</h3>'."\n");
5175: $r->print(&Apache::loncoursequeueadmin::display_queued_requests($context,
5176: $cdom,$cnum));
5177: } elsif ($env{'form.state'} eq 'done') {
5178: $r->print('<h3>'.&mt('Enrollment request processing').'</h3>'."\n");
5179: $r->print(&Apache::loncoursequeueadmin::update_request_queue($context,
5180: $cdom,$cnum,$coursedesc));
5181: }
5182: } else {
5183: $r->print(&header(undef,{'no_nav_bar' => 1}).
5184: '<span class="LC_error">'.&mt('You do not have permission to manage self-enrollment').'</span>');
1.351 raeburn 5185: }
1.418 raeburn 5186: } elsif ($env{'form.action'} eq 'changelogs') {
5187: if ($permission->{cusr} || $permission->{view}) {
5188: &print_userchangelogs_display($r,$context,$permission,$brcrum);
5189: } else {
5190: $r->print(&header(undef,{'no_nav_bar' => 1}).
5191: '<span class="LC_error">'.&mt('You do not have permission to view change logs').'</span>');
1.277 raeburn 5192: }
1.190 raeburn 5193: } else {
1.351 raeburn 5194: $bread_crumbs_component = 'User Management';
5195: $args = { bread_crumbs => $brcrum,
5196: bread_crumbs_component => $bread_crumbs_component};
5197: $r->print(&header(undef,$args));
1.318 raeburn 5198: $r->print(&print_main_menu($permission,$context,$crstype));
1.190 raeburn 5199: }
1.351 raeburn 5200: $r->print(&Apache::loncommon::end_page());
1.190 raeburn 5201: return OK;
5202: }
5203:
5204: sub header {
1.351 raeburn 5205: my ($jscript,$args) = @_;
1.190 raeburn 5206: my $start_page;
1.351 raeburn 5207: if (ref($args) eq 'HASH') {
5208: $start_page=&Apache::loncommon::start_page('User Management',$jscript,$args);
1.190 raeburn 5209: } else {
1.351 raeburn 5210: $start_page=&Apache::loncommon::start_page('User Management',$jscript);
1.190 raeburn 5211: }
5212: return $start_page;
5213: }
1.2 www 5214:
1.191 raeburn 5215: sub add_script {
5216: my ($js) = @_;
1.301 bisitz 5217: return '<script type="text/javascript">'."\n"
5218: .'// <![CDATA['."\n"
5219: .$js."\n"
5220: .'// ]]>'."\n"
5221: .'</script>'."\n";
1.191 raeburn 5222: }
5223:
1.391 raeburn 5224: sub usernamerequest_javascript {
5225: my $js = <<ENDJS;
5226:
5227: function openusernamereqdisplay(dom,uname,queue) {
5228: var url = '/adm/createuser?action=displayuserreq';
5229: url += '&domain='+dom+'&username='+uname+'&queue='+queue;
5230: var title = 'Account_Request_Browser';
5231: var options = 'scrollbars=1,resizable=1,menubar=0';
5232: options += ',width=700,height=600';
5233: var stdeditbrowser = open(url,title,options,'1');
5234: stdeditbrowser.focus();
5235: return;
5236: }
5237:
5238: ENDJS
5239: }
5240:
5241: sub close_popup_form {
5242: my $close= &mt('Close Window');
5243: return << "END";
5244: <p><form name="displayreq" action="" method="post">
5245: <input type="button" name="closeme" value="$close" onclick="javascript:self.close();" />
5246: </form></p>
5247: END
5248: }
5249:
1.202 raeburn 5250: sub verify_user_display {
1.364 raeburn 5251: my ($context) = @_;
1.374 raeburn 5252: my %lt = &Apache::lonlocal::texthash (
5253: course => 'course(s): description, section(s), status',
5254: community => 'community(s): description, section(s), status',
5255: author => 'author',
5256: );
1.364 raeburn 5257: my $photos;
5258: if (($context eq 'course') && $env{'request.course.id'}) {
5259: $photos = $env{'course.'.$env{'request.course.id'}.'.internal.showphoto'};
5260: }
1.202 raeburn 5261: my $output = <<"END";
5262:
1.364 raeburn 5263: function hide_searching() {
5264: if (document.getElementById('searching')) {
5265: document.getElementById('searching').style.display = 'none';
5266: }
5267: return;
5268: }
5269:
1.202 raeburn 5270: function display_update() {
5271: document.studentform.action.value = 'listusers';
5272: document.studentform.phase.value = 'display';
5273: document.studentform.submit();
5274: }
5275:
1.364 raeburn 5276: function updateCols(caller) {
5277: var context = '$context';
5278: var photos = '$photos';
5279: if (caller == 'Status') {
1.374 raeburn 5280: if ((context == 'domain') &&
5281: ((document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'course') ||
5282: (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community'))) {
1.364 raeburn 5283: document.getElementById('showcolstatus').checked = false;
5284: document.getElementById('showcolstatus').disabled = 'disabled';
5285: document.getElementById('showcolstart').checked = false;
5286: document.getElementById('showcolend').checked = false;
1.374 raeburn 5287: } else {
5288: if (document.studentform.Status.options[document.studentform.Status.selectedIndex].value == 'Any') {
5289: document.getElementById('showcolstatus').checked = true;
5290: document.getElementById('showcolstatus').disabled = '';
5291: document.getElementById('showcolstart').checked = true;
5292: document.getElementById('showcolend').checked = true;
5293: } else {
5294: document.getElementById('showcolstatus').checked = false;
5295: document.getElementById('showcolstatus').disabled = 'disabled';
5296: document.getElementById('showcolstart').checked = false;
5297: document.getElementById('showcolend').checked = false;
5298: }
1.364 raeburn 5299: }
5300: }
5301: if (caller == 'output') {
5302: if (photos == 1) {
5303: if (document.getElementById('showcolphoto')) {
5304: var photoitem = document.getElementById('showcolphoto');
5305: if (document.studentform.output.options[document.studentform.output.selectedIndex].value == 'html') {
5306: photoitem.checked = true;
5307: photoitem.disabled = '';
5308: } else {
5309: photoitem.checked = false;
5310: photoitem.disabled = 'disabled';
5311: }
5312: }
5313: }
5314: }
5315: if (caller == 'showrole') {
1.371 raeburn 5316: if ((document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'Any') ||
5317: (document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'cr')) {
1.364 raeburn 5318: document.getElementById('showcolrole').checked = true;
5319: document.getElementById('showcolrole').disabled = '';
5320: } else {
5321: document.getElementById('showcolrole').checked = false;
5322: document.getElementById('showcolrole').disabled = 'disabled';
5323: }
1.374 raeburn 5324: if (context == 'domain') {
1.382 raeburn 5325: var quotausageshow = 0;
1.374 raeburn 5326: if ((document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'course') ||
5327: (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community')) {
5328: document.getElementById('showcolstatus').checked = false;
5329: document.getElementById('showcolstatus').disabled = 'disabled';
5330: document.getElementById('showcolstart').checked = false;
5331: document.getElementById('showcolend').checked = false;
5332: } else {
5333: if (document.studentform.Status.options[document.studentform.Status.selectedIndex].value == 'Any') {
5334: document.getElementById('showcolstatus').checked = true;
5335: document.getElementById('showcolstatus').disabled = '';
5336: document.getElementById('showcolstart').checked = true;
5337: document.getElementById('showcolend').checked = true;
5338: }
5339: }
5340: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'domain') {
5341: document.getElementById('showcolextent').disabled = 'disabled';
5342: document.getElementById('showcolextent').checked = 'false';
5343: document.getElementById('showextent').style.display='none';
5344: document.getElementById('showcoltextextent').innerHTML = '';
1.382 raeburn 5345: if ((document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'au') ||
5346: (document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'Any')) {
5347: if (document.getElementById('showcolauthorusage')) {
5348: document.getElementById('showcolauthorusage').disabled = '';
5349: }
5350: if (document.getElementById('showcolauthorquota')) {
5351: document.getElementById('showcolauthorquota').disabled = '';
5352: }
5353: quotausageshow = 1;
5354: }
1.374 raeburn 5355: } else {
5356: document.getElementById('showextent').style.display='block';
5357: document.getElementById('showextent').style.textAlign='left';
5358: document.getElementById('showextent').style.textFace='normal';
5359: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'author') {
5360: document.getElementById('showcolextent').disabled = '';
5361: document.getElementById('showcolextent').checked = 'true';
5362: document.getElementById('showcoltextextent').innerHTML="$lt{'author'}";
5363: } else {
5364: document.getElementById('showcolextent').disabled = '';
5365: document.getElementById('showcolextent').checked = 'true';
5366: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community') {
5367: document.getElementById('showcoltextextent').innerHTML="$lt{'community'}";
5368: } else {
5369: document.getElementById('showcoltextextent').innerHTML="$lt{'course'}";
5370: }
5371: }
5372: }
1.382 raeburn 5373: if (quotausageshow == 0) {
5374: if (document.getElementById('showcolauthorusage')) {
5375: document.getElementById('showcolauthorusage').checked = false;
5376: document.getElementById('showcolauthorusage').disabled = 'disabled';
5377: }
5378: if (document.getElementById('showcolauthorquota')) {
5379: document.getElementById('showcolauthorquota').checked = false;
5380: document.getElementById('showcolauthorquota').disabled = 'disabled';
5381: }
5382: }
1.374 raeburn 5383: }
1.364 raeburn 5384: }
5385: return;
5386: }
5387:
1.202 raeburn 5388: END
5389: return $output;
5390:
5391: }
5392:
1.190 raeburn 5393: ###############################################################
5394: ###############################################################
5395: # Menu Phase One
5396: sub print_main_menu {
1.318 raeburn 5397: my ($permission,$context,$crstype) = @_;
5398: my $linkcontext = $context;
5399: my $stuterm = lc(&Apache::lonnet::plaintext('st',$crstype));
5400: if (($context eq 'course') && ($crstype eq 'Community')) {
5401: $linkcontext = lc($crstype);
5402: $stuterm = 'Members';
5403: }
1.208 raeburn 5404: my %links = (
1.298 droeschl 5405: domain => {
5406: upload => 'Upload a File of Users',
5407: singleuser => 'Add/Modify a User',
5408: listusers => 'Manage Users',
5409: },
5410: author => {
5411: upload => 'Upload a File of Co-authors',
5412: singleuser => 'Add/Modify a Co-author',
5413: listusers => 'Manage Co-authors',
5414: },
5415: course => {
5416: upload => 'Upload a File of Course Users',
5417: singleuser => 'Add/Modify a Course User',
1.354 www 5418: listusers => 'List and Modify Multiple Course Users',
1.298 droeschl 5419: },
1.318 raeburn 5420: community => {
5421: upload => 'Upload a File of Community Users',
5422: singleuser => 'Add/Modify a Community User',
1.354 www 5423: listusers => 'List and Modify Multiple Community Users',
1.318 raeburn 5424: },
5425: );
5426: my %linktitles = (
5427: domain => {
5428: singleuser => 'Add a user to the domain, and/or a course or community in the domain.',
5429: listusers => 'Show and manage users in this domain.',
5430: },
5431: author => {
5432: singleuser => 'Add a user with a co- or assistant author role.',
5433: listusers => 'Show and manage co- or assistant authors.',
5434: },
5435: course => {
5436: singleuser => 'Add a user with a certain role to this course.',
5437: listusers => 'Show and manage users in this course.',
5438: },
5439: community => {
5440: singleuser => 'Add a user with a certain role to this community.',
5441: listusers => 'Show and manage users in this community.',
5442: },
1.298 droeschl 5443: );
1.418 raeburn 5444: if ($linkcontext eq 'domain') {
5445: unless ($permission->{'cusr'}) {
5446: $links{'domain'}{'singleuser'} = 'View a User';
5447: $linktitles{'domain'}{'singleuser'} = 'View information about a user in the domain';
5448:
5449: }
5450: } elsif ($linkcontext eq 'course') {
5451: unless ($permission->{'cusr'}) {
5452: $links{'course'}{'singleuser'} = 'View a Course User';
5453: $linktitles{'course'}{'singleuser'} = 'View information about a user in this course';
5454: $links{'course'}{'listusers'} = 'List Course Users';
5455: $linktitles{'course'}{'listusers'} = 'Show information about users in this course';
5456: }
5457: } elsif ($linkcontext eq 'community') {
5458: unless ($permission->{'cusr'}) {
5459: $links{'community'}{'singleuser'} = 'View a Community User';
5460: $linktitles{'community'}{'singleuser'} = 'View information about a user in this community';
5461: $links{'community'}{'listusers'} = 'List Community Users';
5462: $linktitles{'community'}{'listusers'} = 'Show information about users in this community';
5463: }
5464: }
1.298 droeschl 5465: my @menu = ( {categorytitle => 'Single Users',
5466: items =>
5467: [
5468: {
1.318 raeburn 5469: linktext => $links{$linkcontext}{'singleuser'},
1.298 droeschl 5470: icon => 'edit-redo.png',
5471: #help => 'Course_Change_Privileges',
5472: url => '/adm/createuser?action=singleuser',
1.418 raeburn 5473: permission => ($permission->{'view'} || $permission->{'cusr'}),
1.318 raeburn 5474: linktitle => $linktitles{$linkcontext}{'singleuser'},
1.298 droeschl 5475: },
5476: ]},
5477:
5478: {categorytitle => 'Multiple Users',
5479: items =>
5480: [
5481: {
1.318 raeburn 5482: linktext => $links{$linkcontext}{'upload'},
1.340 wenzelju 5483: icon => 'uplusr.png',
1.298 droeschl 5484: #help => 'Course_Create_Class_List',
5485: url => '/adm/createuser?action=upload',
5486: permission => $permission->{'cusr'},
5487: linktitle => 'Upload a CSV or a text file containing users.',
5488: },
5489: {
1.318 raeburn 5490: linktext => $links{$linkcontext}{'listusers'},
1.340 wenzelju 5491: icon => 'mngcu.png',
1.298 droeschl 5492: #help => 'Course_View_Class_List',
5493: url => '/adm/createuser?action=listusers',
5494: permission => ($permission->{'view'} || $permission->{'cusr'}),
1.318 raeburn 5495: linktitle => $linktitles{$linkcontext}{'listusers'},
1.298 droeschl 5496: },
5497:
5498: ]},
5499:
5500: {categorytitle => 'Administration',
5501: items => [ ]},
5502: );
1.415 raeburn 5503:
1.265 mielkec 5504: if ($context eq 'domain'){
1.416 raeburn 5505: push(@{ $menu[0]->{items} }, # Single Users
5506: {
5507: linktext => 'User Access Log',
1.417 raeburn 5508: icon => 'document-properties.png',
1.416 raeburn 5509: #help => 'User_Access_Logs',
5510: url => '/adm/createuser?action=accesslogs',
5511: permission => $permission->{'activity'},
5512: linktitle => 'View user access log.',
5513: }
5514: );
1.298 droeschl 5515:
5516: push(@{ $menu[2]->{items} }, #Category: Administration
5517: {
5518: linktext => 'Custom Roles',
5519: icon => 'emblem-photos.png',
5520: #help => 'Course_Editing_Custom_Roles',
5521: url => '/adm/createuser?action=custom',
5522: permission => $permission->{'custom'},
5523: linktitle => 'Configure a custom role.',
5524: },
1.362 raeburn 5525: {
5526: linktext => 'Authoring Space Requests',
5527: icon => 'selfenrl-queue.png',
5528: #help => 'Domain_Role_Approvals',
5529: url => '/adm/createuser?action=processauthorreq',
5530: permission => $permission->{'cusr'},
5531: linktitle => 'Approve or reject author role requests',
5532: },
1.363 raeburn 5533: {
1.391 raeburn 5534: linktext => 'LON-CAPA Account Requests',
5535: icon => 'list-add.png',
5536: #help => 'Domain_Username_Approvals',
5537: url => '/adm/createuser?action=processusernamereq',
5538: permission => $permission->{'cusr'},
5539: linktitle => 'Approve or reject LON-CAPA account requests',
5540: },
5541: {
1.363 raeburn 5542: linktext => 'Change Log',
5543: icon => 'document-properties.png',
5544: #help => 'Course_User_Logs',
5545: url => '/adm/createuser?action=changelogs',
1.418 raeburn 5546: permission => ($permission->{'cusr'} || $permission->{'view'}),
1.363 raeburn 5547: linktitle => 'View change log.',
5548: },
1.298 droeschl 5549: );
5550:
1.265 mielkec 5551: }elsif ($context eq 'course'){
1.298 droeschl 5552: my ($cnum,$cdom) = &Apache::lonuserutils::get_course_identity();
1.318 raeburn 5553:
5554: my %linktext = (
5555: 'Course' => {
5556: single => 'Add/Modify a Student',
5557: drop => 'Drop Students',
5558: groups => 'Course Groups',
5559: },
5560: 'Community' => {
5561: single => 'Add/Modify a Member',
5562: drop => 'Drop Members',
5563: groups => 'Community Groups',
5564: },
5565: );
1.411 raeburn 5566: $linktext{'Placement'} = $linktext{'Course'};
1.318 raeburn 5567:
5568: my %linktitle = (
5569: 'Course' => {
5570: single => 'Add a user with the role of student to this course',
5571: drop => 'Remove a student from this course.',
5572: groups => 'Manage course groups',
5573: },
5574: 'Community' => {
5575: single => 'Add a user with the role of member to this community',
5576: drop => 'Remove a member from this community.',
5577: groups => 'Manage community groups',
5578: },
5579: );
5580:
1.411 raeburn 5581: $linktitle{'Placement'} = $linktitle{'Course'};
5582:
1.298 droeschl 5583: push(@{ $menu[0]->{items} }, #Category: Single Users
5584: {
1.318 raeburn 5585: linktext => $linktext{$crstype}{'single'},
1.298 droeschl 5586: #help => 'Course_Add_Student',
5587: icon => 'list-add.png',
5588: url => '/adm/createuser?action=singlestudent',
5589: permission => $permission->{'cusr'},
1.318 raeburn 5590: linktitle => $linktitle{$crstype}{'single'},
1.298 droeschl 5591: },
5592: );
5593:
5594: push(@{ $menu[1]->{items} }, #Category: Multiple Users
5595: {
1.318 raeburn 5596: linktext => $linktext{$crstype}{'drop'},
1.298 droeschl 5597: icon => 'edit-undo.png',
5598: #help => 'Course_Drop_Student',
5599: url => '/adm/createuser?action=drop',
5600: permission => $permission->{'cusr'},
1.318 raeburn 5601: linktitle => $linktitle{$crstype}{'drop'},
1.298 droeschl 5602: },
5603: );
5604: push(@{ $menu[2]->{items} }, #Category: Administration
5605: {
5606: linktext => 'Custom Roles',
5607: icon => 'emblem-photos.png',
5608: #help => 'Course_Editing_Custom_Roles',
5609: url => '/adm/createuser?action=custom',
5610: permission => $permission->{'custom'},
5611: linktitle => 'Configure a custom role.',
5612: },
5613: {
1.318 raeburn 5614: linktext => $linktext{$crstype}{'groups'},
1.333 wenzelju 5615: icon => 'grps.png',
1.298 droeschl 5616: #help => 'Course_Manage_Group',
5617: url => '/adm/coursegroups?refpage=cusr',
5618: permission => $permission->{'grp_manage'},
1.318 raeburn 5619: linktitle => $linktitle{$crstype}{'groups'},
1.298 droeschl 5620: },
5621: {
1.328 wenzelju 5622: linktext => 'Change Log',
1.298 droeschl 5623: icon => 'document-properties.png',
5624: #help => 'Course_User_Logs',
5625: url => '/adm/createuser?action=changelogs',
1.418 raeburn 5626: permission => ($permission->{'view'} || $permission->{'cusr'}),
1.298 droeschl 5627: linktitle => 'View change log.',
5628: },
5629: );
1.277 raeburn 5630: if ($env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_approval'}) {
1.298 droeschl 5631: push(@{ $menu[2]->{items} },
1.398 raeburn 5632: {
1.298 droeschl 5633: linktext => 'Enrollment Requests',
5634: icon => 'selfenrl-queue.png',
5635: #help => 'Course_Approve_Selfenroll',
5636: url => '/adm/createuser?action=selfenrollqueue',
1.398 raeburn 5637: permission => $permission->{'selfenrolladmin'},
1.298 droeschl 5638: linktitle =>'Approve or reject enrollment requests.',
5639: },
5640: );
1.277 raeburn 5641: }
1.298 droeschl 5642:
1.265 mielkec 5643: if (!exists($permission->{'cusr_section'})){
1.320 raeburn 5644: if ($crstype ne 'Community') {
5645: push(@{ $menu[2]->{items} },
5646: {
5647: linktext => 'Automated Enrollment',
5648: icon => 'roles.png',
5649: #help => 'Course_Automated_Enrollment',
5650: permission => (&Apache::lonnet::auto_run($cnum,$cdom)
1.418 raeburn 5651: && (($permission->{'cusr'}) ||
5652: ($permission->{'view'}))),
1.320 raeburn 5653: url => '/adm/populate',
5654: linktitle => 'Automated enrollment manager.',
5655: }
5656: );
5657: }
5658: push(@{ $menu[2]->{items} },
1.298 droeschl 5659: {
5660: linktext => 'User Self-Enrollment',
1.342 wenzelju 5661: icon => 'self_enroll.png',
1.298 droeschl 5662: #help => 'Course_Self_Enrollment',
5663: url => '/adm/createuser?action=selfenroll',
1.398 raeburn 5664: permission => $permission->{'selfenrolladmin'},
1.317 bisitz 5665: linktitle => 'Configure user self-enrollment.',
1.298 droeschl 5666: },
5667: );
5668: }
1.363 raeburn 5669: } elsif ($context eq 'author') {
1.370 raeburn 5670: push(@{ $menu[2]->{items} }, #Category: Administration
1.363 raeburn 5671: {
5672: linktext => 'Change Log',
5673: icon => 'document-properties.png',
5674: #help => 'Course_User_Logs',
5675: url => '/adm/createuser?action=changelogs',
5676: permission => $permission->{'cusr'},
5677: linktitle => 'View change log.',
5678: },
1.370 raeburn 5679: );
1.363 raeburn 5680: }
5681: return Apache::lonhtmlcommon::generate_menu(@menu);
1.250 raeburn 5682: # { text => 'View Log-in History',
5683: # help => 'Course_User_Logins',
5684: # action => 'logins',
5685: # permission => $permission->{'cusr'},
5686: # });
1.190 raeburn 5687: }
5688:
1.189 albertel 5689: sub restore_prev_selections {
5690: my %saveable_parameters = ('srchby' => 'scalar',
5691: 'srchin' => 'scalar',
5692: 'srchtype' => 'scalar',
5693: );
5694: &Apache::loncommon::store_settings('user','user_picker',
5695: \%saveable_parameters);
5696: &Apache::loncommon::restore_settings('user','user_picker',
5697: \%saveable_parameters);
5698: }
5699:
1.237 raeburn 5700: sub print_selfenroll_menu {
1.418 raeburn 5701: my ($r,$context,$cid,$cdom,$cnum,$currsettings,$additional,$readonly) = @_;
1.322 raeburn 5702: my $crstype = &Apache::loncommon::course_type();
1.398 raeburn 5703: my $formname = 'selfenroll';
1.237 raeburn 5704: my $nolink = 1;
1.398 raeburn 5705: my ($row,$lt) = &Apache::lonuserutils::get_selfenroll_titles();
1.237 raeburn 5706: my $groupslist = &Apache::lonuserutils::get_groupslist();
5707: my $setsec_js =
5708: &Apache::lonuserutils::setsections_javascript($formname,$groupslist);
1.249 raeburn 5709: my %alerts = &Apache::lonlocal::texthash(
5710: acto => 'Activation of self-enrollment was selected for the following domain(s)',
5711: butn => 'but no user types have been checked.',
5712: wilf => "Please uncheck 'activate' or check at least one type.",
5713: );
1.418 raeburn 5714: my $disabled;
5715: if ($readonly) {
5716: $disabled = ' disabled="disabled"';
5717: }
1.405 damieng 5718: &js_escape(\%alerts);
1.249 raeburn 5719: my $selfenroll_js = <<"ENDSCRIPT";
5720: function update_types(caller,num) {
5721: var delidx = getIndexByName('selfenroll_delete');
5722: var actidx = getIndexByName('selfenroll_activate');
5723: if (caller == 'selfenroll_all') {
5724: var selall;
5725: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
5726: if (document.$formname.selfenroll_all[i].checked) {
5727: selall = document.$formname.selfenroll_all[i].value;
5728: }
5729: }
5730: if (selall == 1) {
5731: if (delidx != -1) {
5732: if (document.$formname.selfenroll_delete.length) {
5733: for (var j=0; j<document.$formname.selfenroll_delete.length; j++) {
5734: document.$formname.selfenroll_delete[j].checked = true;
5735: }
5736: } else {
5737: document.$formname.elements[delidx].checked = true;
5738: }
5739: }
5740: if (actidx != -1) {
5741: if (document.$formname.selfenroll_activate.length) {
5742: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
5743: document.$formname.selfenroll_activate[j].checked = false;
5744: }
5745: } else {
5746: document.$formname.elements[actidx].checked = false;
5747: }
5748: }
5749: document.$formname.selfenroll_newdom.selectedIndex = 0;
5750: }
5751: }
5752: if (caller == 'selfenroll_activate') {
5753: if (document.$formname.selfenroll_activate.length) {
5754: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
5755: if (document.$formname.selfenroll_activate[j].value == num) {
5756: if (document.$formname.selfenroll_activate[j].checked) {
5757: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
5758: if (document.$formname.selfenroll_all[i].value == '1') {
5759: document.$formname.selfenroll_all[i].checked = false;
5760: }
5761: if (document.$formname.selfenroll_all[i].value == '0') {
5762: document.$formname.selfenroll_all[i].checked = true;
5763: }
5764: }
5765: }
5766: }
5767: }
5768: } else {
5769: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
5770: if (document.$formname.selfenroll_all[i].value == '1') {
5771: document.$formname.selfenroll_all[i].checked = false;
5772: }
5773: if (document.$formname.selfenroll_all[i].value == '0') {
5774: document.$formname.selfenroll_all[i].checked = true;
5775: }
5776: }
5777: }
5778: }
5779: if (caller == 'selfenroll_delete') {
5780: if (document.$formname.selfenroll_delete.length) {
5781: for (var j=0; j<document.$formname.selfenroll_delete.length; j++) {
5782: if (document.$formname.selfenroll_delete[j].value == num) {
5783: if (document.$formname.selfenroll_delete[j].checked) {
5784: var delindex = getIndexByName('selfenroll_types_'+num);
5785: if (delindex != -1) {
5786: if (document.$formname.elements[delindex].length) {
5787: for (var k=0; k<document.$formname.elements[delindex].length; k++) {
5788: document.$formname.elements[delindex][k].checked = false;
5789: }
5790: } else {
5791: document.$formname.elements[delindex].checked = false;
5792: }
5793: }
5794: }
5795: }
5796: }
5797: } else {
5798: if (document.$formname.selfenroll_delete.checked) {
5799: var delindex = getIndexByName('selfenroll_types_'+num);
5800: if (delindex != -1) {
5801: if (document.$formname.elements[delindex].length) {
5802: for (var k=0; k<document.$formname.elements[delindex].length; k++) {
5803: document.$formname.elements[delindex][k].checked = false;
5804: }
5805: } else {
5806: document.$formname.elements[delindex].checked = false;
5807: }
5808: }
5809: }
5810: }
5811: }
5812: return;
5813: }
5814:
5815: function validate_types(form) {
5816: var needaction = new Array();
5817: var countfail = 0;
5818: var actidx = getIndexByName('selfenroll_activate');
5819: if (actidx != -1) {
5820: if (document.$formname.selfenroll_activate.length) {
5821: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
5822: var num = document.$formname.selfenroll_activate[j].value;
5823: if (document.$formname.selfenroll_activate[j].checked) {
5824: countfail = check_types(num,countfail,needaction)
5825: }
5826: }
5827: } else {
5828: if (document.$formname.selfenroll_activate.checked) {
1.398 raeburn 5829: var num = document.$formname.selfenroll_activate.value;
1.249 raeburn 5830: countfail = check_types(num,countfail,needaction)
5831: }
5832: }
5833: }
5834: if (countfail > 0) {
5835: var msg = "$alerts{'acto'}\\n";
5836: var loopend = needaction.length -1;
5837: if (loopend > 0) {
5838: for (var m=0; m<loopend; m++) {
5839: msg += needaction[m]+", ";
5840: }
5841: }
5842: msg += needaction[loopend]+"\\n$alerts{'butn'}\\n$alerts{'wilf'}";
5843: alert(msg);
5844: return;
5845: }
5846: setSections(form);
5847: }
5848:
5849: function check_types(num,countfail,needaction) {
5850: var typeidx = getIndexByName('selfenroll_types_'+num);
5851: var count = 0;
5852: if (typeidx != -1) {
5853: if (document.$formname.elements[typeidx].length) {
5854: for (var k=0; k<document.$formname.elements[typeidx].length; k++) {
5855: if (document.$formname.elements[typeidx][k].checked) {
5856: count ++;
5857: }
5858: }
5859: } else {
5860: if (document.$formname.elements[typeidx].checked) {
5861: count ++;
5862: }
5863: }
5864: if (count == 0) {
5865: var domidx = getIndexByName('selfenroll_dom_'+num);
5866: if (domidx != -1) {
5867: var domname = document.$formname.elements[domidx].value;
5868: needaction[countfail] = domname;
5869: countfail ++;
5870: }
5871: }
5872: }
5873: return countfail;
5874: }
5875:
1.398 raeburn 5876: function toggleNotify() {
5877: var selfenrollApproval = 0;
5878: if (document.$formname.selfenroll_approval.length) {
5879: for (var i=0; i<document.$formname.selfenroll_approval.length; i++) {
5880: if (document.$formname.selfenroll_approval[i].checked) {
5881: selfenrollApproval = document.$formname.selfenroll_approval[i].value;
5882: break;
5883: }
5884: }
5885: }
5886: if (document.getElementById('notified')) {
5887: if (selfenrollApproval == 0) {
5888: document.getElementById('notified').style.display='none';
5889: } else {
5890: document.getElementById('notified').style.display='block';
5891: }
5892: }
5893: return;
5894: }
5895:
1.249 raeburn 5896: function getIndexByName(item) {
5897: for (var i=0;i<document.$formname.elements.length;i++) {
5898: if (document.$formname.elements[i].name == item) {
5899: return i;
5900: }
5901: }
5902: return -1;
5903: }
5904: ENDSCRIPT
1.256 raeburn 5905:
1.237 raeburn 5906: my $output = '<script type="text/javascript">'."\n".
1.301 bisitz 5907: '// <![CDATA['."\n".
1.249 raeburn 5908: $setsec_js."\n".$selfenroll_js."\n".
1.301 bisitz 5909: '// ]]>'."\n".
1.237 raeburn 5910: '</script>'."\n".
1.256 raeburn 5911: '<h3>'.$lt->{'selfenroll'}.'</h3>'."\n";
1.400 raeburn 5912:
5913: my $visactions = &cat_visibility();
5914: my ($cathash,%cattype);
5915: my %domconfig = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom);
5916: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
5917: $cathash = $domconfig{'coursecategories'}{'cats'};
5918: $cattype{'auth'} = $domconfig{'coursecategories'}{'auth'};
5919: $cattype{'unauth'} = $domconfig{'coursecategories'}{'unauth'};
1.406 raeburn 5920: if ($cattype{'auth'} eq '') {
5921: $cattype{'auth'} = 'std';
5922: }
5923: if ($cattype{'unauth'} eq '') {
5924: $cattype{'unauth'} = 'std';
5925: }
1.400 raeburn 5926: } else {
5927: $cathash = {};
5928: $cattype{'auth'} = 'std';
5929: $cattype{'unauth'} = 'std';
5930: }
5931: if (($cattype{'auth'} eq 'none') && ($cattype{'unauth'} eq 'none')) {
5932: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
5933: '<br />'.
5934: '<br />'.$visactions->{'take'}.'<ul>'.
5935: '<li>'.$visactions->{'dc_chgconf'}.'</li>'.
5936: '</ul>');
5937: } elsif (($cattype{'auth'} !~ /^(std|domonly)$/) && ($cattype{'unauth'} !~ /^(std|domonly)$/)) {
5938: if ($currsettings->{'uniquecode'}) {
5939: $r->print('<span class="LC_info">'.$visactions->{'vis'}.'</span>');
5940: } else {
5941: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
5942: '<br />'.
5943: '<br />'.$visactions->{'take'}.'<ul>'.
5944: '<li>'.$visactions->{'dc_setcode'}.'</li>'.
5945: '</ul><br />');
5946: }
5947: } else {
5948: my ($visible,$cansetvis,$vismsgs) = &visible_in_stdcat($cdom,$cnum,\%domconfig);
5949: if (ref($visactions) eq 'HASH') {
5950: if ($visible) {
5951: $output .= '<p class="LC_info">'.$visactions->{'vis'}.'</p>';
5952: } else {
5953: $output .= '<p class="LC_warning">'.$visactions->{'miss'}.'</p>'
5954: .$visactions->{'yous'}.
5955: '<p>'.$visactions->{'gen'}.'<br />'.$visactions->{'coca'};
5956: if (ref($vismsgs) eq 'ARRAY') {
5957: $output .= '<br />'.$visactions->{'make'}.'<ul>';
5958: foreach my $item (@{$vismsgs}) {
5959: $output .= '<li>'.$visactions->{$item}.'</li>';
5960: }
5961: $output .= '</ul>';
1.256 raeburn 5962: }
1.400 raeburn 5963: $output .= '</p>';
1.256 raeburn 5964: }
5965: }
5966: }
1.398 raeburn 5967: my $actionhref = '/adm/createuser';
5968: if ($context eq 'domain') {
5969: $actionhref = '/adm/modifycourse';
5970: }
1.400 raeburn 5971:
5972: my %noedit;
5973: unless ($context eq 'domain') {
5974: %noedit = &get_noedit_fields($cdom,$cnum,$crstype,$row);
5975: }
1.398 raeburn 5976: $output .= '<form name="'.$formname.'" method="post" action="'.$actionhref.'">'."\n".
1.256 raeburn 5977: &Apache::lonhtmlcommon::start_pick_box();
1.237 raeburn 5978: if (ref($row) eq 'ARRAY') {
5979: foreach my $item (@{$row}) {
5980: my $title = $item;
5981: if (ref($lt) eq 'HASH') {
5982: $title = $lt->{$item};
5983: }
1.297 bisitz 5984: $output .= &Apache::lonhtmlcommon::row_title($title);
1.237 raeburn 5985: if ($item eq 'types') {
1.398 raeburn 5986: my $curr_types;
5987: if (ref($currsettings) eq 'HASH') {
5988: $curr_types = $currsettings->{'selfenroll_types'};
5989: }
1.400 raeburn 5990: if ($noedit{$item}) {
5991: if ($curr_types eq '*') {
5992: $output .= &mt('Any user in any domain');
5993: } else {
5994: my @entries = split(/;/,$curr_types);
5995: if (@entries > 0) {
5996: $output .= '<ul>';
5997: foreach my $entry (@entries) {
5998: my ($currdom,$typestr) = split(/:/,$entry);
5999: next if ($typestr eq '');
6000: my $domdesc = &Apache::lonnet::domain($currdom);
6001: my @currinsttypes = split(',',$typestr);
6002: my ($othertitle,$usertypes,$types) =
6003: &Apache::loncommon::sorted_inst_types($currdom);
6004: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
6005: $usertypes->{'any'} = &mt('any user');
6006: if (keys(%{$usertypes}) > 0) {
6007: $usertypes->{'other'} = &mt('other users');
6008: }
6009: my @longinsttypes = map { $usertypes->{$_}; } @currinsttypes;
6010: $output .= '<li>'.$domdesc.':'.join(', ',@longinsttypes).'</li>';
6011: }
6012: }
6013: $output .= '</ul>';
6014: } else {
6015: $output .= &mt('None');
6016: }
6017: }
6018: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6019: next;
6020: }
1.241 raeburn 6021: my $showdomdesc = 1;
6022: my $includeempty = 1;
6023: my $num = 0;
6024: $output .= &Apache::loncommon::start_data_table().
6025: &Apache::loncommon::start_data_table_row()
6026: .'<td colspan="2"><span class="LC_nobreak"><label>'
6027: .&mt('Any user in any domain:')
6028: .' <input type="radio" name="selfenroll_all" value="1" ';
6029: if ($curr_types eq '*') {
6030: $output .= ' checked="checked" ';
6031: }
1.249 raeburn 6032: $output .= 'onchange="javascript:update_types('.
1.418 raeburn 6033: "'selfenroll_all'".');"'.$disabled.' />'.&mt('Yes').'</label>'.
1.249 raeburn 6034: ' <input type="radio" name="selfenroll_all" value="0" ';
1.241 raeburn 6035: if ($curr_types ne '*') {
6036: $output .= ' checked="checked" ';
6037: }
1.249 raeburn 6038: $output .= ' onchange="javascript:update_types('.
1.418 raeburn 6039: "'selfenroll_all'".');"'.$disabled.' />'.&mt('No').'</label></td>'.
1.249 raeburn 6040: &Apache::loncommon::end_data_table_row().
6041: &Apache::loncommon::end_data_table().
6042: &mt('Or').'<br />'.
6043: &Apache::loncommon::start_data_table();
1.241 raeburn 6044: my %currdoms;
1.249 raeburn 6045: if ($curr_types eq '') {
1.241 raeburn 6046: $output .= &new_selfenroll_dom_row($cdom,'0');
6047: } elsif ($curr_types ne '*') {
6048: my @entries = split(/;/,$curr_types);
6049: if (@entries > 0) {
6050: foreach my $entry (@entries) {
6051: my ($currdom,$typestr) = split(/:/,$entry);
6052: $currdoms{$currdom} = 1;
6053: my $domdesc = &Apache::lonnet::domain($currdom);
1.249 raeburn 6054: my @currinsttypes = split(',',$typestr);
1.241 raeburn 6055: $output .= &Apache::loncommon::start_data_table_row()
6056: .'<td valign="top"><span class="LC_nobreak">'.&mt('Domain:').'<b>'
6057: .' '.$domdesc.' ('.$currdom.')'
6058: .'</b><input type="hidden" name="selfenroll_dom_'.$num
6059: .'" value="'.$currdom.'" /></span><br />'
6060: .'<span class="LC_nobreak"><label><input type="checkbox" '
1.418 raeburn 6061: .'name="selfenroll_delete" value="'.$num.'" onchange="javascript:update_types('."'selfenroll_delete','$num'".');"'.$disabled.' />'
1.241 raeburn 6062: .&mt('Delete').'</label></span></td>';
1.249 raeburn 6063: $output .= '<td valign="top"> '.&mt('User types:').'<br />'
1.418 raeburn 6064: .&selfenroll_inst_types($num,$currdom,\@currinsttypes,$readonly).'</td>'
1.241 raeburn 6065: .&Apache::loncommon::end_data_table_row();
6066: $num ++;
6067: }
6068: }
6069: }
1.249 raeburn 6070: my $add_domtitle = &mt('Users in additional domain:');
1.241 raeburn 6071: if ($curr_types eq '*') {
1.249 raeburn 6072: $add_domtitle = &mt('Users in specific domain:');
1.241 raeburn 6073: } elsif ($curr_types eq '') {
1.249 raeburn 6074: $add_domtitle = &mt('Users in other domain:');
1.241 raeburn 6075: }
6076: $output .= &Apache::loncommon::start_data_table_row()
6077: .'<td colspan="2"><span class="LC_nobreak">'.$add_domtitle.'</span><br />'
6078: .&Apache::loncommon::select_dom_form('','selfenroll_newdom',
1.418 raeburn 6079: $includeempty,$showdomdesc,'','','',$readonly)
1.241 raeburn 6080: .'<input type="hidden" name="selfenroll_types_total" value="'.$num.'" />'
6081: .'</td>'.&Apache::loncommon::end_data_table_row()
6082: .&Apache::loncommon::end_data_table();
1.237 raeburn 6083: } elsif ($item eq 'registered') {
6084: my ($regon,$regoff);
1.398 raeburn 6085: my $registered;
6086: if (ref($currsettings) eq 'HASH') {
6087: $registered = $currsettings->{'selfenroll_registered'};
6088: }
1.400 raeburn 6089: if ($noedit{$item}) {
6090: if ($registered) {
6091: $output .= &mt('Must be registered in course');
6092: } else {
6093: $output .= &mt('No requirement');
6094: }
6095: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6096: next;
6097: }
1.398 raeburn 6098: if ($registered) {
1.237 raeburn 6099: $regon = ' checked="checked" ';
1.419 raeburn 6100: $regoff = '';
1.237 raeburn 6101: } else {
1.419 raeburn 6102: $regon = '';
1.237 raeburn 6103: $regoff = ' checked="checked" ';
6104: }
6105: $output .= '<label>'.
1.419 raeburn 6106: '<input type="radio" name="selfenroll_registered" value="1"'.$regon.$disabled.' />'.
1.244 bisitz 6107: &mt('Yes').'</label> <label>'.
1.419 raeburn 6108: '<input type="radio" name="selfenroll_registered" value="0"'.$regoff.$disabled.' />'.
1.244 bisitz 6109: &mt('No').'</label>';
1.237 raeburn 6110: } elsif ($item eq 'enroll_dates') {
1.398 raeburn 6111: my ($starttime,$endtime);
6112: if (ref($currsettings) eq 'HASH') {
6113: $starttime = $currsettings->{'selfenroll_start_date'};
6114: $endtime = $currsettings->{'selfenroll_end_date'};
6115: if ($starttime eq '') {
6116: $starttime = $currsettings->{'default_enrollment_start_date'};
6117: }
6118: if ($endtime eq '') {
6119: $endtime = $currsettings->{'default_enrollment_end_date'};
6120: }
1.237 raeburn 6121: }
1.400 raeburn 6122: if ($noedit{$item}) {
6123: $output .= &mt('From: [_1], to: [_2]',&Apache::lonlocal::locallocaltime($starttime),
6124: &Apache::lonlocal::locallocaltime($endtime));
6125: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6126: next;
6127: }
1.237 raeburn 6128: my $startform =
6129: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_start_date',$starttime,
1.418 raeburn 6130: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
1.237 raeburn 6131: my $endform =
6132: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_end_date',$endtime,
1.418 raeburn 6133: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
1.237 raeburn 6134: $output .= &selfenroll_date_forms($startform,$endform);
6135: } elsif ($item eq 'access_dates') {
1.398 raeburn 6136: my ($starttime,$endtime);
6137: if (ref($currsettings) eq 'HASH') {
6138: $starttime = $currsettings->{'selfenroll_start_access'};
6139: $endtime = $currsettings->{'selfenroll_end_access'};
6140: if ($starttime eq '') {
6141: $starttime = $currsettings->{'default_enrollment_start_date'};
6142: }
6143: if ($endtime eq '') {
6144: $endtime = $currsettings->{'default_enrollment_end_date'};
6145: }
1.237 raeburn 6146: }
1.400 raeburn 6147: if ($noedit{$item}) {
6148: $output .= &mt('From: [_1], to: [_2]',&Apache::lonlocal::locallocaltime($starttime),
6149: &Apache::lonlocal::locallocaltime($endtime));
6150: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6151: next;
6152: }
1.237 raeburn 6153: my $startform =
6154: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_start_access',$starttime,
1.418 raeburn 6155: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
1.237 raeburn 6156: my $endform =
6157: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_end_access',$endtime,
1.418 raeburn 6158: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
1.237 raeburn 6159: $output .= &selfenroll_date_forms($startform,$endform);
6160: } elsif ($item eq 'section') {
1.398 raeburn 6161: my $currsec;
6162: if (ref($currsettings) eq 'HASH') {
6163: $currsec = $currsettings->{'selfenroll_section'};
6164: }
1.237 raeburn 6165: my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum);
6166: my $newsecval;
6167: if ($currsec ne 'none' && $currsec ne '') {
6168: if (!defined($sections_count{$currsec})) {
6169: $newsecval = $currsec;
6170: }
6171: }
1.400 raeburn 6172: if ($noedit{$item}) {
6173: if ($currsec ne '') {
6174: $output .= $currsec;
6175: } else {
6176: $output .= &mt('No specific section');
6177: }
6178: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6179: next;
6180: }
1.237 raeburn 6181: my $sections_select =
1.418 raeburn 6182: &Apache::lonuserutils::course_sections(\%sections_count,'st',$currsec,$disabled);
1.237 raeburn 6183: $output .= '<table class="LC_createuser">'."\n".
6184: '<tr class="LC_section_row">'."\n".
6185: '<td align="center">'.&mt('Existing sections')."\n".
6186: '<br />'.$sections_select.'</td><td align="center">'.
6187: &mt('New section').'<br />'."\n".
1.418 raeburn 6188: '<input type="text" name="newsec" size="15" value="'.$newsecval.'"'.$disabled.' />'."\n".
1.237 raeburn 6189: '<input type="hidden" name="sections" value="" />'."\n".
6190: '</td></tr></table>'."\n";
1.276 raeburn 6191: } elsif ($item eq 'approval') {
1.398 raeburn 6192: my ($currnotified,$currapproval,%appchecked);
6193: my %selfdescs = &Apache::lonuserutils::selfenroll_default_descs();
6194: if (ref($currsettings) eq 'HASH') {
6195: $currnotified = $currsettings->{'selfenroll_notifylist'};
6196: $currapproval = $currsettings->{'selfenroll_approval'};
6197: }
6198: if ($currapproval !~ /^[012]$/) {
6199: $currapproval = 0;
6200: }
1.400 raeburn 6201: if ($noedit{$item}) {
6202: $output .= $selfdescs{'approval'}{$currapproval}.
6203: '<br />'.&mt('(Set by Domain Coordinator)');
6204: next;
6205: }
1.398 raeburn 6206: $appchecked{$currapproval} = ' checked="checked"';
6207: for my $i (0..2) {
6208: $output .= '<label>'.
6209: '<input type="radio" name="selfenroll_approval" value="'.$i.'"'.
1.418 raeburn 6210: $appchecked{$i}.' onclick="toggleNotify();"'.$disabled.' />'.
6211: $selfdescs{'approval'}{$i}.'</label>'.(' 'x2);
1.276 raeburn 6212: }
6213: my %advhash = &Apache::lonnet::get_course_adv_roles($cid,1);
6214: my (@ccs,%notified);
1.322 raeburn 6215: my $ccrole = 'cc';
6216: if ($crstype eq 'Community') {
6217: $ccrole = 'co';
6218: }
6219: if ($advhash{$ccrole}) {
6220: @ccs = split(/,/,$advhash{$ccrole});
1.276 raeburn 6221: }
6222: if ($currnotified) {
6223: foreach my $current (split(/,/,$currnotified)) {
6224: $notified{$current} = 1;
6225: if (!grep(/^\Q$current\E$/,@ccs)) {
6226: push(@ccs,$current);
6227: }
6228: }
6229: }
6230: if (@ccs) {
1.398 raeburn 6231: my $style;
6232: unless ($currapproval) {
6233: $style = ' style="display: none;"';
6234: }
6235: $output .= '<br /><div id="notified"'.$style.'>'.
6236: &mt('Personnel to be notified when an enrollment request needs approval, or has been approved:').' '.
6237: &Apache::loncommon::start_data_table().
1.276 raeburn 6238: &Apache::loncommon::start_data_table_row();
6239: my $count = 0;
6240: my $numcols = 4;
6241: foreach my $cc (sort(@ccs)) {
6242: my $notifyon;
6243: my ($ccuname,$ccudom) = split(/:/,$cc);
6244: if ($notified{$cc}) {
6245: $notifyon = ' checked="checked" ';
6246: }
6247: if ($count && !$count%$numcols) {
6248: $output .= &Apache::loncommon::end_data_table_row().
6249: &Apache::loncommon::start_data_table_row()
6250: }
6251: $output .= '<td><span class="LC_nobreak"><label>'.
1.418 raeburn 6252: '<input type="checkbox" name="selfenroll_notify"'.$notifyon.' value="'.$cc.'"'.$disabled.' />'.
1.276 raeburn 6253: &Apache::loncommon::plainname($ccuname,$ccudom).
6254: '</label></span></td>';
1.343 raeburn 6255: $count ++;
1.276 raeburn 6256: }
6257: my $rem = $count%$numcols;
6258: if ($rem) {
6259: my $emptycols = $numcols - $rem;
6260: for (my $i=0; $i<$emptycols; $i++) {
6261: $output .= '<td> </td>';
6262: }
6263: }
6264: $output .= &Apache::loncommon::end_data_table_row().
1.398 raeburn 6265: &Apache::loncommon::end_data_table().
6266: '</div>';
1.276 raeburn 6267: }
6268: } elsif ($item eq 'limit') {
1.398 raeburn 6269: my ($crslimit,$selflimit,$nolimit,$currlim,$currcap);
6270: if (ref($currsettings) eq 'HASH') {
6271: $currlim = $currsettings->{'selfenroll_limit'};
6272: $currcap = $currsettings->{'selfenroll_cap'};
6273: }
1.400 raeburn 6274: if ($noedit{$item}) {
6275: if (($currlim eq 'allstudents') || ($currlim eq 'selfenrolled')) {
6276: if ($currlim eq 'allstudents') {
6277: $output .= &mt('Limit by total students');
6278: } elsif ($currlim eq 'selfenrolled') {
6279: $output .= &mt('Limit by total self-enrolled students');
6280: }
6281: $output .= ' '.&mt('Maximum: [_1]',$currcap).
6282: '<br />'.&mt('(Set by Domain Coordinator)');
6283: } else {
6284: $output .= &mt('No limit').'<br />'.&mt('(Set by Domain Coordinator)');
6285: }
6286: next;
6287: }
1.276 raeburn 6288: if ($currlim eq 'allstudents') {
6289: $crslimit = ' checked="checked" ';
6290: $selflimit = ' ';
6291: $nolimit = ' ';
6292: } elsif ($currlim eq 'selfenrolled') {
6293: $crslimit = ' ';
6294: $selflimit = ' checked="checked" ';
6295: $nolimit = ' ';
6296: } else {
6297: $crslimit = ' ';
6298: $selflimit = ' ';
1.398 raeburn 6299: $nolimit = ' checked="checked" ';
1.276 raeburn 6300: }
6301: $output .= '<table><tr><td><label>'.
1.418 raeburn 6302: '<input type="radio" name="selfenroll_limit" value="none"'.$nolimit.$disabled.'/>'.
1.276 raeburn 6303: &mt('No limit').'</label></td><td><label>'.
1.418 raeburn 6304: '<input type="radio" name="selfenroll_limit" value="allstudents"'.$crslimit.$disabled.'/>'.
1.276 raeburn 6305: &mt('Limit by total students').'</label></td><td><label>'.
1.418 raeburn 6306: '<input type="radio" name="selfenroll_limit" value="selfenrolled"'.$selflimit.$disabled.'/>'.
1.276 raeburn 6307: &mt('Limit by total self-enrolled students').
6308: '</td></tr><tr>'.
6309: '<td> </td><td colspan="2"><span class="LC_nobreak">'.
6310: (' 'x3).&mt('Maximum number allowed: ').
1.418 raeburn 6311: '<input type="text" name="selfenroll_cap" size = "5" value="'.$currcap.'"'.$disabled.' /></td></tr></table>';
1.237 raeburn 6312: }
6313: $output .= &Apache::lonhtmlcommon::row_closure(1);
6314: }
6315: }
1.418 raeburn 6316: $output .= &Apache::lonhtmlcommon::end_pick_box().'<br />';
6317: unless ($readonly) {
6318: $output .= '<input type="button" name="selfenrollconf" value="'
6319: .&mt('Save').'" onclick="validate_types(this.form);" />';
6320: }
6321: $output .= '<input type="hidden" name="action" value="selfenroll" />'
6322: .'<input type="hidden" name="state" value="done" />'."\n"
6323: .$additional.'</form>';
1.237 raeburn 6324: $r->print($output);
6325: return;
6326: }
6327:
1.400 raeburn 6328: sub get_noedit_fields {
6329: my ($cdom,$cnum,$crstype,$row) = @_;
6330: my %noedit;
6331: if (ref($row) eq 'ARRAY') {
6332: my %settings = &Apache::lonnet::get('environment',['internal.coursecode','internal.textbook',
6333: 'internal.selfenrollmgrdc',
6334: 'internal.selfenrollmgrcc'],$cdom,$cnum);
6335: my $type = &Apache::lonuserutils::get_extended_type($cdom,$cnum,$crstype,\%settings);
6336: my (%specific_managebydc,%specific_managebycc,%default_managebydc);
6337: map { $specific_managebydc{$_} = 1; } (split(/,/,$settings{'internal.selfenrollmgrdc'}));
6338: map { $specific_managebycc{$_} = 1; } (split(/,/,$settings{'internal.selfenrollmgrcc'}));
6339: my %domdefaults = &Apache::lonnet::get_domain_defaults($cdom);
6340: map { $default_managebydc{$_} = 1; } (split(/,/,$domdefaults{$type.'selfenrolladmdc'}));
6341:
6342: foreach my $item (@{$row}) {
6343: next if ($specific_managebycc{$item});
6344: if (($specific_managebydc{$item}) || ($default_managebydc{$item})) {
6345: $noedit{$item} = 1;
6346: }
6347: }
6348: }
6349: return %noedit;
6350: }
6351:
6352: sub visible_in_stdcat {
6353: my ($cdom,$cnum,$domconf) = @_;
6354: my ($cathash,%settable,@vismsgs,$cansetvis,$visible);
6355: unless (ref($domconf) eq 'HASH') {
6356: return ($visible,$cansetvis,\@vismsgs);
6357: }
6358: if (ref($domconf->{'coursecategories'}) eq 'HASH') {
6359: if ($domconf->{'coursecategories'}{'togglecats'} eq 'crs') {
1.256 raeburn 6360: $settable{'togglecats'} = 1;
6361: }
1.400 raeburn 6362: if ($domconf->{'coursecategories'}{'categorize'} eq 'crs') {
1.256 raeburn 6363: $settable{'categorize'} = 1;
6364: }
1.400 raeburn 6365: $cathash = $domconf->{'coursecategories'}{'cats'};
1.256 raeburn 6366: }
1.260 raeburn 6367: if ($settable{'togglecats'} && $settable{'categorize'}) {
1.256 raeburn 6368: $cansetvis = &mt('You are able to both assign a course category and choose to exclude this course from the catalog.');
6369: } elsif ($settable{'togglecats'}) {
6370: $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 6371: } elsif ($settable{'categorize'}) {
1.256 raeburn 6372: $cansetvis = &mt('You may assign a course category, but only a Domain Coordinator may choose to exclude this course from the catalog.');
6373: } else {
6374: $cansetvis = &mt('Only a Domain Coordinator may assign a course category or choose to exclude this course from the catalog.');
6375: }
6376:
6377: my %currsettings =
6378: &Apache::lonnet::get('environment',['hidefromcat','categories','internal.coursecode'],
6379: $cdom,$cnum);
1.400 raeburn 6380: $visible = 0;
1.256 raeburn 6381: if ($currsettings{'internal.coursecode'} ne '') {
1.400 raeburn 6382: if (ref($domconf->{'coursecategories'}) eq 'HASH') {
6383: $cathash = $domconf->{'coursecategories'}{'cats'};
1.256 raeburn 6384: if (ref($cathash) eq 'HASH') {
6385: if ($cathash->{'instcode::0'} eq '') {
6386: push(@vismsgs,'dc_addinst');
6387: } else {
6388: $visible = 1;
6389: }
6390: } else {
6391: $visible = 1;
6392: }
6393: } else {
6394: $visible = 1;
6395: }
6396: } else {
6397: if (ref($cathash) eq 'HASH') {
6398: if ($cathash->{'instcode::0'} ne '') {
6399: push(@vismsgs,'dc_instcode');
6400: }
6401: } else {
6402: push(@vismsgs,'dc_instcode');
6403: }
6404: }
6405: if ($currsettings{'categories'} ne '') {
6406: my $cathash;
1.400 raeburn 6407: if (ref($domconf->{'coursecategories'}) eq 'HASH') {
6408: $cathash = $domconf->{'coursecategories'}{'cats'};
1.256 raeburn 6409: if (ref($cathash) eq 'HASH') {
6410: if (keys(%{$cathash}) == 0) {
6411: push(@vismsgs,'dc_catalog');
6412: } elsif ((keys(%{$cathash}) == 1) && ($cathash->{'instcode::0'} ne '')) {
6413: push(@vismsgs,'dc_categories');
6414: } else {
6415: my @currcategories = split('&',$currsettings{'categories'});
6416: my $matched = 0;
6417: foreach my $cat (@currcategories) {
6418: if ($cathash->{$cat} ne '') {
6419: $visible = 1;
6420: $matched = 1;
6421: last;
6422: }
6423: }
6424: if (!$matched) {
1.260 raeburn 6425: if ($settable{'categorize'}) {
1.256 raeburn 6426: push(@vismsgs,'chgcat');
6427: } else {
6428: push(@vismsgs,'dc_chgcat');
6429: }
6430: }
6431: }
6432: }
6433: }
6434: } else {
6435: if (ref($cathash) eq 'HASH') {
6436: if ((keys(%{$cathash}) > 1) ||
6437: (keys(%{$cathash}) == 1) && ($cathash->{'instcode::0'} eq '')) {
1.260 raeburn 6438: if ($settable{'categorize'}) {
1.256 raeburn 6439: push(@vismsgs,'addcat');
6440: } else {
6441: push(@vismsgs,'dc_addcat');
6442: }
6443: }
6444: }
6445: }
6446: if ($currsettings{'hidefromcat'} eq 'yes') {
6447: $visible = 0;
6448: if ($settable{'togglecats'}) {
6449: unshift(@vismsgs,'unhide');
6450: } else {
6451: unshift(@vismsgs,'dc_unhide')
6452: }
6453: }
1.400 raeburn 6454: return ($visible,$cansetvis,\@vismsgs);
6455: }
6456:
6457: sub cat_visibility {
6458: my %visactions = &Apache::lonlocal::texthash(
6459: vis => 'This course/community currently appears in the Course/Community Catalog for this domain.',
6460: 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.',
6461: miss => 'This course/community does not currently appear in the Course/Community Catalog for this domain.',
6462: none => 'Display of a course catalog is disabled for this domain.',
6463: yous => 'You should remedy this if you plan to allow self-enrollment, otherwise students will have difficulty finding this course.',
6464: 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.',
6465: make => 'Make any changes to self-enrollment settings below, click "Save", then take action to include the course in the Catalog:',
6466: take => 'Take the following action to ensure the course appears in the Catalog:',
6467: dc_chgconf => 'Ask a domain coordinator to change the Catalog type for this domain.',
6468: dc_setcode => 'Ask a domain coordinator to assign a six character code to the course',
6469: dc_unhide => 'Ask a domain coordinator to change the "Exclude from course catalog" setting.',
6470: dc_addinst => 'Ask a domain coordinator to enable display the catalog of "Official courses (with institutional codes)".',
6471: dc_instcode => 'Ask a domain coordinator to assign an institutional code (if this is an official course).',
6472: dc_catalog => 'Ask a domain coordinator to enable or create at least one course category in the domain.',
6473: dc_categories => 'Ask a domain coordinator to create a hierarchy of categories and sub categories for courses in the domain.',
6474: 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',
6475: dc_addcat => 'Ask a domain coordinator to assign a category to the course.',
6476: );
6477: $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>"');
6478: $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>"');
6479: $visactions{'addcat'} = &mt('Use [_1]Categorize course[_2] to assign a category to the course.','"<a href="/adm/courseprefs?phase=display&actions=courseinfo">','</a>"');
6480: return \%visactions;
1.256 raeburn 6481: }
6482:
1.241 raeburn 6483: sub new_selfenroll_dom_row {
6484: my ($newdom,$num) = @_;
6485: my $domdesc = &Apache::lonnet::domain($newdom);
6486: my $output;
6487: if ($domdesc ne '') {
6488: $output .= &Apache::loncommon::start_data_table_row()
6489: .'<td valign="top"><span class="LC_nobreak">'.&mt('Domain:').' <b>'.$domdesc
6490: .' ('.$newdom.')</b><input type="hidden" name="selfenroll_dom_'.$num
1.249 raeburn 6491: .'" value="'.$newdom.'" /></span><br />'
6492: .'<span class="LC_nobreak"><label><input type="checkbox" '
6493: .'name="selfenroll_activate" value="'.$num.'" '
6494: .'onchange="javascript:update_types('
6495: ."'selfenroll_activate','$num'".');" />'
6496: .&mt('Activate').'</label></span></td>';
1.241 raeburn 6497: my @currinsttypes;
6498: $output .= '<td>'.&mt('User types:').'<br />'
6499: .&selfenroll_inst_types($num,$newdom,\@currinsttypes).'</td>'
6500: .&Apache::loncommon::end_data_table_row();
6501: }
6502: return $output;
6503: }
6504:
6505: sub selfenroll_inst_types {
1.418 raeburn 6506: my ($num,$currdom,$currinsttypes,$readonly) = @_;
1.241 raeburn 6507: my $output;
6508: my $numinrow = 4;
6509: my $count = 0;
6510: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($currdom);
1.247 raeburn 6511: my $othervalue = 'any';
1.418 raeburn 6512: my $disabled;
6513: if ($readonly) {
6514: $disabled = ' disabled="disabled"';
6515: }
1.241 raeburn 6516: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
1.251 raeburn 6517: if (keys(%{$usertypes}) > 0) {
1.247 raeburn 6518: $othervalue = 'other';
6519: }
1.241 raeburn 6520: $output .= '<table><tr>';
6521: foreach my $type (@{$types}) {
6522: if (($count > 0) && ($count%$numinrow == 0)) {
6523: $output .= '</tr><tr>';
6524: }
6525: if (defined($usertypes->{$type})) {
1.257 raeburn 6526: my $esc_type = &escape($type);
1.241 raeburn 6527: $output .= '<td><span class="LC_nobreak"><label><input type = "checkbox" value="'.
1.257 raeburn 6528: $esc_type.'" ';
1.241 raeburn 6529: if (ref($currinsttypes) eq 'ARRAY') {
6530: if (@{$currinsttypes} > 0) {
1.249 raeburn 6531: if (grep(/^any$/,@{$currinsttypes})) {
6532: $output .= 'checked="checked"';
1.257 raeburn 6533: } elsif (grep(/^\Q$esc_type\E$/,@{$currinsttypes})) {
1.241 raeburn 6534: $output .= 'checked="checked"';
6535: }
1.249 raeburn 6536: } else {
6537: $output .= 'checked="checked"';
1.241 raeburn 6538: }
6539: }
1.418 raeburn 6540: $output .= ' name="selfenroll_types_'.$num.'"'.$disabled.' />'.$usertypes->{$type}.'</label></span></td>';
1.241 raeburn 6541: }
6542: $count ++;
6543: }
6544: if (($count > 0) && ($count%$numinrow == 0)) {
6545: $output .= '</tr><tr>';
6546: }
1.249 raeburn 6547: $output .= '<td><span class="LC_nobreak"><label><input type = "checkbox" value="'.$othervalue.'"';
1.241 raeburn 6548: if (ref($currinsttypes) eq 'ARRAY') {
6549: if (@{$currinsttypes} > 0) {
1.249 raeburn 6550: if (grep(/^any$/,@{$currinsttypes})) {
6551: $output .= ' checked="checked"';
6552: } elsif ($othervalue eq 'other') {
6553: if (grep(/^\Q$othervalue\E$/,@{$currinsttypes})) {
6554: $output .= ' checked="checked"';
6555: }
1.241 raeburn 6556: }
1.249 raeburn 6557: } else {
6558: $output .= ' checked="checked"';
1.241 raeburn 6559: }
1.249 raeburn 6560: } else {
6561: $output .= ' checked="checked"';
1.241 raeburn 6562: }
1.418 raeburn 6563: $output .= ' name="selfenroll_types_'.$num.'"'.$disabled.' />'.$othertitle.'</label></span></td></tr></table>';
1.241 raeburn 6564: }
6565: return $output;
6566: }
6567:
1.237 raeburn 6568: sub selfenroll_date_forms {
6569: my ($startform,$endform) = @_;
6570: my $output .= &Apache::lonhtmlcommon::start_pick_box()."\n".
1.244 bisitz 6571: &Apache::lonhtmlcommon::row_title(&mt('Start date'),
1.237 raeburn 6572: 'LC_oddrow_value')."\n".
6573: $startform."\n".
6574: &Apache::lonhtmlcommon::row_closure(1).
1.244 bisitz 6575: &Apache::lonhtmlcommon::row_title(&mt('End date'),
1.237 raeburn 6576: 'LC_oddrow_value')."\n".
6577: $endform."\n".
6578: &Apache::lonhtmlcommon::row_closure(1).
6579: &Apache::lonhtmlcommon::end_pick_box();
6580: return $output;
6581: }
6582:
1.239 raeburn 6583: sub print_userchangelogs_display {
1.415 raeburn 6584: my ($r,$context,$permission,$brcrum) = @_;
1.363 raeburn 6585: my $formname = 'rolelog';
1.418 raeburn 6586: my ($username,$domain,$crstype,$viewablesec,%roleslog);
1.363 raeburn 6587: if ($context eq 'domain') {
6588: $domain = $env{'request.role.domain'};
6589: %roleslog=&Apache::lonnet::dump_dom('nohist_rolelog',$domain);
6590: } else {
6591: if ($context eq 'course') {
6592: $domain = $env{'course.'.$env{'request.course.id'}.'.domain'};
6593: $username = $env{'course.'.$env{'request.course.id'}.'.num'};
6594: $crstype = &Apache::loncommon::course_type();
1.418 raeburn 6595: $viewablesec = &Apache::lonuserutils::viewable_section($permission);
1.363 raeburn 6596: my %saveable_parameters = ('show' => 'scalar',);
6597: &Apache::loncommon::store_course_settings('roles_log',
6598: \%saveable_parameters);
6599: &Apache::loncommon::restore_course_settings('roles_log',
6600: \%saveable_parameters);
6601: } elsif ($context eq 'author') {
6602: $domain = $env{'user.domain'};
6603: if ($env{'request.role'} =~ m{^au\./\Q$domain\E/$}) {
6604: $username = $env{'user.name'};
6605: } else {
6606: undef($domain);
6607: }
6608: }
6609: if ($domain ne '' && $username ne '') {
6610: %roleslog=&Apache::lonnet::dump('nohist_rolelog',$domain,$username);
6611: }
6612: }
1.239 raeburn 6613: if ((keys(%roleslog))[0]=~/^error\:/) { undef(%roleslog); }
6614:
1.415 raeburn 6615: my $helpitem;
6616: if ($context eq 'course') {
6617: $helpitem = 'Course_User_Logs';
6618: }
6619: push (@{$brcrum},
6620: {href => '/adm/createuser?action=changelogs',
6621: text => 'User Management Logs',
6622: help => $helpitem});
6623: my $bread_crumbs_component = 'User Changes';
6624: my $args = { bread_crumbs => $brcrum,
6625: bread_crumbs_component => $bread_crumbs_component};
6626:
6627: # Create navigation javascript
6628: my $jsnav = &userlogdisplay_js($formname);
6629:
6630: my $jscript = (<<ENDSCRIPT);
6631: <script type="text/javascript">
6632: // <![CDATA[
6633: $jsnav
6634: // ]]>
6635: </script>
6636: ENDSCRIPT
6637:
6638: # print page header
6639: $r->print(&header($jscript,$args));
6640:
1.239 raeburn 6641: # set defaults
6642: my $now = time();
6643: my $defstart = $now - (7*24*3600); #7 days ago
6644: my %defaults = (
6645: page => '1',
6646: show => '10',
6647: role => 'any',
6648: chgcontext => 'any',
6649: rolelog_start_date => $defstart,
6650: rolelog_end_date => $now,
6651: );
6652: my $more_records = 0;
6653:
6654: # set current
6655: my %curr;
6656: foreach my $item ('show','page','role','chgcontext') {
6657: $curr{$item} = $env{'form.'.$item};
6658: }
6659: my ($startdate,$enddate) =
6660: &Apache::lonuserutils::get_dates_from_form('rolelog_start_date','rolelog_end_date');
6661: $curr{'rolelog_start_date'} = $startdate;
6662: $curr{'rolelog_end_date'} = $enddate;
6663: foreach my $key (keys(%defaults)) {
6664: if ($curr{$key} eq '') {
6665: $curr{$key} = $defaults{$key};
6666: }
6667: }
1.248 raeburn 6668: my (%whodunit,%changed,$version);
6669: ($version) = ($r->dir_config('lonVersion') =~ /^([\d\.]+)\-/);
1.239 raeburn 6670: my ($minshown,$maxshown);
1.255 raeburn 6671: $minshown = 1;
1.239 raeburn 6672: my $count = 0;
1.415 raeburn 6673: if ($curr{'show'} =~ /\D/) {
6674: $curr{'page'} = 1;
6675: } else {
1.239 raeburn 6676: $maxshown = $curr{'page'} * $curr{'show'};
6677: if ($curr{'page'} > 1) {
6678: $minshown = 1 + ($curr{'page'} - 1) * $curr{'show'};
6679: }
6680: }
1.301 bisitz 6681:
1.327 raeburn 6682: # Form Header
6683: $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">'.
1.363 raeburn 6684: &role_display_filter($context,$formname,$domain,$username,\%curr,
6685: $version,$crstype));
1.327 raeburn 6686:
6687: my $showntableheader = 0;
6688:
6689: # Table Header
6690: my $tableheader =
6691: &Apache::loncommon::start_data_table_header_row()
6692: .'<th> </th>'
6693: .'<th>'.&mt('When').'</th>'
6694: .'<th>'.&mt('Who made the change').'</th>'
6695: .'<th>'.&mt('Changed User').'</th>'
1.363 raeburn 6696: .'<th>'.&mt('Role').'</th>';
6697:
6698: if ($context eq 'course') {
6699: $tableheader .= '<th>'.&mt('Section').'</th>';
6700: }
6701: $tableheader .=
6702: '<th>'.&mt('Context').'</th>'
1.327 raeburn 6703: .'<th>'.&mt('Start').'</th>'
6704: .'<th>'.&mt('End').'</th>'
6705: .&Apache::loncommon::end_data_table_header_row();
6706:
6707: # Display user change log data
1.239 raeburn 6708: foreach my $id (sort { $roleslog{$b}{'exe_time'}<=>$roleslog{$a}{'exe_time'} } (keys(%roleslog))) {
6709: next if (($roleslog{$id}{'exe_time'} < $curr{'rolelog_start_date'}) ||
6710: ($roleslog{$id}{'exe_time'} > $curr{'rolelog_end_date'}));
1.415 raeburn 6711: if ($curr{'show'} !~ /\D/) {
1.239 raeburn 6712: if ($count >= $curr{'page'} * $curr{'show'}) {
6713: $more_records = 1;
6714: last;
6715: }
6716: }
6717: if ($curr{'role'} ne 'any') {
6718: next if ($roleslog{$id}{'logentry'}{'role'} ne $curr{'role'});
6719: }
6720: if ($curr{'chgcontext'} ne 'any') {
6721: if ($curr{'chgcontext'} eq 'selfenroll') {
6722: next if (!$roleslog{$id}{'logentry'}{'selfenroll'});
6723: } else {
6724: next if ($roleslog{$id}{'logentry'}{'context'} ne $curr{'chgcontext'});
6725: }
6726: }
1.418 raeburn 6727: if (($context eq 'course') && ($viewablesec ne '')) {
6728: next if ($roleslog{$id}{'logentry'}{'section'} ne $viewablesec);
6729: }
1.239 raeburn 6730: $count ++;
6731: next if ($count < $minshown);
1.327 raeburn 6732: unless ($showntableheader) {
1.415 raeburn 6733: $r->print(&Apache::loncommon::start_data_table()
1.327 raeburn 6734: .$tableheader);
6735: $r->rflush();
6736: $showntableheader = 1;
6737: }
1.239 raeburn 6738: if ($whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}} eq '') {
6739: $whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}} =
6740: &Apache::loncommon::plainname($roleslog{$id}{'exe_uname'},$roleslog{$id}{'exe_udom'});
6741: }
6742: if ($changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}} eq '') {
6743: $changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}} =
6744: &Apache::loncommon::plainname($roleslog{$id}{'uname'},$roleslog{$id}{'udom'});
6745: }
6746: my $sec = $roleslog{$id}{'logentry'}{'section'};
6747: if ($sec eq '') {
6748: $sec = &mt('None');
6749: }
6750: my ($rolestart,$roleend);
6751: if ($roleslog{$id}{'delflag'}) {
6752: $rolestart = &mt('deleted');
6753: $roleend = &mt('deleted');
6754: } else {
6755: $rolestart = $roleslog{$id}{'logentry'}{'start'};
6756: $roleend = $roleslog{$id}{'logentry'}{'end'};
6757: if ($rolestart eq '' || $rolestart == 0) {
6758: $rolestart = &mt('No start date');
6759: } else {
6760: $rolestart = &Apache::lonlocal::locallocaltime($rolestart);
6761: }
6762: if ($roleend eq '' || $roleend == 0) {
6763: $roleend = &mt('No end date');
6764: } else {
6765: $roleend = &Apache::lonlocal::locallocaltime($roleend);
6766: }
6767: }
6768: my $chgcontext = $roleslog{$id}{'logentry'}{'context'};
6769: if ($roleslog{$id}{'logentry'}{'selfenroll'}) {
6770: $chgcontext = 'selfenroll';
6771: }
1.363 raeburn 6772: my %lt = &rolechg_contexts($context,$crstype);
1.239 raeburn 6773: if ($chgcontext ne '' && $lt{$chgcontext} ne '') {
6774: $chgcontext = $lt{$chgcontext};
6775: }
1.327 raeburn 6776: $r->print(
1.301 bisitz 6777: &Apache::loncommon::start_data_table_row()
6778: .'<td>'.$count.'</td>'
6779: .'<td>'.&Apache::lonlocal::locallocaltime($roleslog{$id}{'exe_time'}).'</td>'
6780: .'<td>'.$whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}}.'</td>'
6781: .'<td>'.$changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}}.'</td>'
1.363 raeburn 6782: .'<td>'.&Apache::lonnet::plaintext($roleslog{$id}{'logentry'}{'role'},$crstype).'</td>');
6783: if ($context eq 'course') {
6784: $r->print('<td>'.$sec.'</td>');
6785: }
6786: $r->print(
6787: '<td>'.$chgcontext.'</td>'
1.301 bisitz 6788: .'<td>'.$rolestart.'</td>'
6789: .'<td>'.$roleend.'</td>'
1.327 raeburn 6790: .&Apache::loncommon::end_data_table_row()."\n");
1.301 bisitz 6791: }
6792:
1.327 raeburn 6793: if ($showntableheader) { # Table footer, if content displayed above
1.415 raeburn 6794: $r->print(&Apache::loncommon::end_data_table().
6795: &userlogdisplay_navlinks(\%curr,$more_records));
1.327 raeburn 6796: } else { # No content displayed above
1.301 bisitz 6797: $r->print('<p class="LC_info">'
6798: .&mt('There are no records to display.')
6799: .'</p>'
6800: );
1.239 raeburn 6801: }
1.301 bisitz 6802:
1.327 raeburn 6803: # Form Footer
6804: $r->print(
6805: '<input type="hidden" name="page" value="'.$curr{'page'}.'" />'
6806: .'<input type="hidden" name="action" value="changelogs" />'
6807: .'</form>');
6808: return;
6809: }
1.301 bisitz 6810:
1.416 raeburn 6811: sub print_useraccesslogs_display {
6812: my ($r,$uname,$udom,$permission,$brcrum) = @_;
6813: my $formname = 'accesslog';
6814: my $form = 'document.accesslog';
6815:
6816: # set breadcrumbs
6817: my %breadcrumb_text = &singleuser_breadcrumb();
6818: push (@{$brcrum},
6819: {href => "javascript:backPage($form)",
6820: text => $breadcrumb_text{'search'}});
6821: my (@prevphases,$prevphasestr);
6822: if ($env{'form.prevphases'}) {
6823: @prevphases = split(/,/,$env{'form.prevphases'});
6824: $prevphasestr = $env{'form.prevphases'};
6825: }
6826: if (($env{'form.phase'} eq 'userpicked') || (grep(/^userpicked$/,@prevphases))) {
6827: push(@{$brcrum},
6828: {href => "javascript:backPage($form,'get_user_info','select')",
6829: text => $breadcrumb_text{'userpicked'}});
6830: if ($env{'form.phase'} eq 'userpicked') {
6831: $prevphasestr = 'userpicked';
6832: }
6833: }
6834: push(@{$brcrum},
6835: {href => '/adm/createuser?action=accesslogs',
6836: text => 'User access logs',
6837: help => 'User_Access_Logs'});
6838: my $bread_crumbs_component = 'User Access Logs';
6839: my $args = { bread_crumbs => $brcrum,
6840: bread_crumbs_component => 'User Management'};
6841:
1.417 raeburn 6842: # set javascript
1.416 raeburn 6843: my ($jsback,$elements) = &crumb_utilities();
6844: my $jsnav = &userlogdisplay_js($formname);
6845:
6846: my $jscript = (<<ENDSCRIPT);
6847: <script type="text/javascript">
6848: // <![CDATA[
6849:
6850: $jsback
6851: $jsnav
6852:
6853: // ]]>
6854: </script>
6855:
6856: ENDSCRIPT
6857:
1.417 raeburn 6858: # print page header
1.416 raeburn 6859: $r->print(&header($jscript,$args));
6860:
6861: # early out unless log data can be displayed.
6862: unless ($permission->{'activity'}) {
6863: $r->print('<p class="LC_warning">'
6864: .&mt('You do not have rights to display user access logs.')
6865: .'</p>'
6866: .&earlyout_accesslog_form($formname,$prevphasestr,$udom));
6867: return;
6868: }
6869:
6870: unless ($udom eq $env{'request.role.domain'}) {
6871: $r->print('<p class="LC_warning">'
6872: .&mt("User's domain must match role's domain")
6873: .'</p>'
6874: .&earlyout_accesslog_form($formname,$prevphasestr,$udom));
1.417 raeburn 6875: return;
1.416 raeburn 6876: }
6877:
6878: if (($uname eq '') || ($udom eq '')) {
6879: $r->print('<p class="LC_warning">'
6880: .&mt('Invalid username or domain')
6881: .'</p>'
6882: .&earlyout_accesslog_form($formname,$prevphasestr,$udom));
6883: return;
6884: }
6885:
6886: # set defaults
6887: my $now = time();
6888: my $defstart = $now - (7*24*3600);
6889: my %defaults = (
6890: page => '1',
6891: show => '10',
6892: activity => 'any',
6893: accesslog_start_date => $defstart,
6894: accesslog_end_date => $now,
6895: );
6896: my $more_records = 0;
6897:
6898: # set current
6899: my %curr;
6900: foreach my $item ('show','page','activity') {
6901: $curr{$item} = $env{'form.'.$item};
6902: }
6903: my ($startdate,$enddate) =
6904: &Apache::lonuserutils::get_dates_from_form('accesslog_start_date','accesslog_end_date');
6905: $curr{'accesslog_start_date'} = $startdate;
6906: $curr{'accesslog_end_date'} = $enddate;
6907: foreach my $key (keys(%defaults)) {
6908: if ($curr{$key} eq '') {
6909: $curr{$key} = $defaults{$key};
6910: }
6911: }
6912: my ($minshown,$maxshown);
6913: $minshown = 1;
6914: my $count = 0;
6915: if ($curr{'show'} =~ /\D/) {
6916: $curr{'page'} = 1;
6917: } else {
6918: $maxshown = $curr{'page'} * $curr{'show'};
6919: if ($curr{'page'} > 1) {
6920: $minshown = 1 + ($curr{'page'} - 1) * $curr{'show'};
6921: }
6922: }
6923:
6924: # form header
6925: $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">'.
6926: &activity_display_filter($formname,\%curr));
6927:
6928: my $showntableheader = 0;
6929: my ($nav_script,$nav_links);
6930:
6931: # table header
6932: my $tableheader =
6933: &Apache::loncommon::start_data_table_header_row()
6934: .'<th> </th>'
6935: .'<th>'.&mt('When').'</th>'
6936: .'<th>'.&mt('HostID').'</th>'
6937: .'<th>'.&mt('Event').'</th>'
6938: .'<th>'.&mt('Other data').'</th>'
6939: .&Apache::loncommon::end_data_table_header_row();
6940:
6941: my %filters=(
6942: start => $curr{'accesslog_start_date'},
6943: end => $curr{'accesslog_end_date'},
6944: action => $curr{'activity'},
6945: );
6946:
6947: my $reply = &Apache::lonnet::userlog_query($uname,$udom,%filters);
6948: unless ( ($reply =~/^timeout/) || ($reply =~/^error/) ) {
6949: my (%courses,%missing);
6950: my @results = split(/\&/,$reply);
6951: foreach my $item (reverse(@results)) {
6952: my ($timestamp,$host,$event) = split(/:/,$item);
6953: next unless ($event =~ /^(Log|Role)/);
6954: if ($curr{'show'} !~ /\D/) {
6955: if ($count >= $curr{'page'} * $curr{'show'}) {
6956: $more_records = 1;
6957: last;
6958: }
6959: }
6960: $count ++;
6961: next if ($count < $minshown);
6962: unless ($showntableheader) {
6963: $r->print($nav_script
6964: .&Apache::loncommon::start_data_table()
6965: .$tableheader);
6966: $r->rflush();
6967: $showntableheader = 1;
6968: }
1.418 raeburn 6969: my ($shown,$extra);
1.416 raeburn 6970: my ($event,$data) = split(/\s+/,&unescape($event));
6971: if ($event eq 'Role') {
6972: my ($rolecode,$extent) = split(/\./,$data,2);
6973: next if ($extent eq '');
6974: my ($crstype,$desc,$info);
1.418 raeburn 6975: if ($extent =~ m{^/($match_domain)/($match_courseid)(?:/(\w+)|)$}) {
6976: my ($cdom,$cnum,$sec) = ($1,$2,$3);
1.416 raeburn 6977: my $cid = $cdom.'_'.$cnum;
6978: if (exists($courses{$cid})) {
6979: $crstype = $courses{$cid}{'type'};
6980: $desc = $courses{$cid}{'description'};
6981: } elsif ($missing{$cid}) {
6982: $crstype = 'Course';
6983: $desc = 'Course/Community';
6984: } else {
6985: my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',$cnum,undef,undef,'.');
6986: if (ref($crsinfo{$cdom.'_'.$cnum}) eq 'HASH') {
6987: $courses{$cid} = $crsinfo{$cid};
6988: $crstype = $crsinfo{$cid}{'type'};
6989: $desc = $crsinfo{$cid}{'description'};
6990: } else {
6991: $missing{$cid} = 1;
6992: }
6993: }
6994: $extra = &mt($crstype).': <a href="/public/'.$cdom.'/'.$cnum.'/syllabus">'.$desc.'</a>';
1.418 raeburn 6995: if ($sec ne '') {
6996: $extra .= ' ('.&mt('Section: [_1]',$sec).')';
6997: }
1.416 raeburn 6998: } elsif ($extent =~ m{^/($match_domain)/($match_username|$)}) {
6999: my ($dom,$name) = ($1,$2);
7000: if ($rolecode eq 'au') {
7001: $extra = '';
7002: } elsif ($rolecode =~ /^(ca|aa)$/) {
1.417 raeburn 7003: $extra = &mt('Authoring Space: [_1]',$name.':'.$dom);
1.416 raeburn 7004: } elsif ($rolecode =~ /^(li|dg|dh|dc|sc)$/) {
7005: $extra = &mt('Domain: [_1]',$dom);
7006: }
7007: }
7008: my $rolename;
7009: if ($rolecode =~ m{^cr/($match_domain)/($match_username)/(\w+)}) {
7010: my $role = $3;
1.417 raeburn 7011: my $owner = "($2:$1)";
1.416 raeburn 7012: if ($2 eq $1.'-domainconfig') {
7013: $owner = '(ad hoc)';
1.417 raeburn 7014: }
1.416 raeburn 7015: $rolename = &mt('Custom role: [_1]',$role.' '.$owner);
7016: } else {
7017: $rolename = &Apache::lonnet::plaintext($rolecode,$crstype);
7018: }
7019: $shown = &mt('Role selection: [_1]',$rolename);
7020: } else {
7021: $shown = &mt($event);
7022: if ($data ne '') {
7023: $extra = &mt('Client IP address: [_1]',$data);
7024: }
7025: }
7026: $r->print(
7027: &Apache::loncommon::start_data_table_row()
7028: .'<td>'.$count.'</td>'
7029: .'<td>'.&Apache::lonlocal::locallocaltime($timestamp).'</td>'
7030: .'<td>'.$host.'</td>'
7031: .'<td>'.$shown.'</td>'
7032: .'<td>'.$extra.'</td>'
7033: .&Apache::loncommon::end_data_table_row()."\n");
7034: }
7035: }
7036:
7037: if ($showntableheader) { # Table footer, if content displayed above
7038: $r->print(&Apache::loncommon::end_data_table().
7039: &userlogdisplay_navlinks(\%curr,$more_records));
7040: } else { # No content displayed above
7041: $r->print('<p class="LC_info">'
7042: .&mt('There are no records to display.')
7043: .'</p>');
7044: }
7045:
7046: # Form Footer
7047: $r->print(
7048: '<input type="hidden" name="currstate" value="" />'
7049: .'<input type="hidden" name="accessuname" value="'.$uname.'" />'
7050: .'<input type="hidden" name="accessudom" value="'.$udom.'" />'
7051: .'<input type="hidden" name="page" value="'.$curr{'page'}.'" />'
7052: .'<input type="hidden" name="prevphases" value="'.$prevphasestr.'" />'
7053: .'<input type="hidden" name="phase" value="activity" />'
7054: .'<input type="hidden" name="action" value="accesslogs" />'
7055: .'<input type="hidden" name="srchdomain" value="'.$udom.'" />'
7056: .'<input type="hidden" name="srchby" value="'.$env{'form.srchby'}.'" />'
7057: .'<input type="hidden" name="srchtype" value="'.$env{'form.srchtype'}.'" />'
7058: .'<input type="hidden" name="srchterm" value="'.&HTML::Entities::encode($env{'form.srchterm'},'<>"&').'" />'
7059: .'<input type="hidden" name="srchin" value="'.$env{'form.srchin'}.'" />'
7060: .'</form>');
7061: return;
7062: }
7063:
7064: sub earlyout_accesslog_form {
7065: my ($formname,$prevphasestr,$udom) = @_;
7066: my $srchterm = &HTML::Entities::encode($env{'form.srchterm'},'<>"&');
7067: return <<"END";
7068: <form action="/adm/createuser" method="post" name="$formname">
7069: <input type="hidden" name="currstate" value="" />
7070: <input type="hidden" name="prevphases" value="$prevphasestr" />
7071: <input type="hidden" name="phase" value="activity" />
7072: <input type="hidden" name="action" value="accesslogs" />
7073: <input type="hidden" name="srchdomain" value="$udom" />
7074: <input type="hidden" name="srchby" value="$env{'form.srchby'}" />
7075: <input type="hidden" name="srchtype" value="$env{'form.srchtype'}" />
7076: <input type="hidden" name="srchterm" value="$srchterm" />
7077: <input type="hidden" name="srchin" value="$env{'form.srchin'}" />
7078: </form>
7079: END
7080: }
7081:
7082: sub activity_display_filter {
7083: my ($formname,$curr) = @_;
7084: my $nolink = 1;
7085: my $output = '<table><tr><td valign="top">'.
7086: '<span class="LC_nobreak"><b>'.&mt('Actions/page:').'</b></span><br />'.
7087: &Apache::lonmeta::selectbox('show',$curr->{'show'},undef,
7088: (&mt('all'),5,10,20,50,100,1000,10000)).
7089: '</td><td> </td>';
7090: my $startform =
7091: &Apache::lonhtmlcommon::date_setter($formname,'accesslog_start_date',
7092: $curr->{'accesslog_start_date'},undef,
7093: undef,undef,undef,undef,undef,undef,$nolink);
7094: my $endform =
7095: &Apache::lonhtmlcommon::date_setter($formname,'accesslog_end_date',
7096: $curr->{'accesslog_end_date'},undef,
7097: undef,undef,undef,undef,undef,undef,$nolink);
7098: my %lt = &Apache::lonlocal::texthash (
7099: activity => 'Activity',
7100: Role => 'Role selection',
7101: log => 'Log-in or Logout',
7102: );
7103: $output .= '<td valign="top"><b>'.&mt('Window during which actions occurred:').'</b><br />'.
7104: '<table><tr><td>'.&mt('After:').
7105: '</td><td>'.$startform.'</td></tr>'.
7106: '<tr><td>'.&mt('Before:').'</td>'.
7107: '<td>'.$endform.'</td></tr></table>'.
7108: '</td>'.
7109: '<td> </td>'.
7110: '<td valign="top"><b>'.&mt('Activities').'</b><br />'.
7111: '<select name="activity"><option value="any"';
7112: if ($curr->{'activity'} eq 'any') {
7113: $output .= ' selected="selected"';
7114: }
7115: $output .= '>'.&mt('Any').'</option>'."\n";
7116: foreach my $activity ('Role','log') {
7117: my $selstr = '';
7118: if ($activity eq $curr->{'activity'}) {
7119: $selstr = ' selected="selected"';
7120: }
7121: $output .= '<option value="'.$activity.'"'.$selstr.'>'.$lt{$activity}.'</option>';
7122: }
7123: $output .= '</select></td>'.
7124: '</tr></table>';
7125: # Update Display button
7126: $output .= '<p>'
7127: .'<input type="submit" value="'.&mt('Update Display').'" />'
7128: .'</p>';
7129: return $output;
7130: }
7131:
1.415 raeburn 7132: sub userlogdisplay_js {
7133: my ($formname) = @_;
7134: return <<"ENDSCRIPT";
7135:
1.239 raeburn 7136: function chgPage(caller) {
7137: if (caller == 'previous') {
7138: document.$formname.page.value --;
7139: }
7140: if (caller == 'next') {
7141: document.$formname.page.value ++;
7142: }
1.327 raeburn 7143: document.$formname.submit();
1.239 raeburn 7144: return;
7145: }
7146: ENDSCRIPT
1.415 raeburn 7147: }
7148:
7149: sub userlogdisplay_navlinks {
7150: my ($curr,$more_records) = @_;
7151: return unless(ref($curr) eq 'HASH');
7152: # Navigation Buttons
7153: my $nav_links = '<p>';
7154: if (($curr->{'page'} > 1) || ($more_records)) {
7155: if (($curr->{'page'} > 1) && ($curr->{'show'} !~ /\D/)) {
7156: $nav_links .= '<input type="button"'
7157: .' onclick="javascript:chgPage('."'previous'".');"'
7158: .' value="'.&mt('Previous [_1] changes',$curr->{'show'})
7159: .'" /> ';
7160: }
7161: if ($more_records) {
7162: $nav_links .= '<input type="button"'
7163: .' onclick="javascript:chgPage('."'next'".');"'
7164: .' value="'.&mt('Next [_1] changes',$curr->{'show'})
7165: .'" />';
1.301 bisitz 7166: }
7167: }
1.415 raeburn 7168: $nav_links .= '</p>';
7169: return $nav_links;
1.239 raeburn 7170: }
7171:
7172: sub role_display_filter {
1.363 raeburn 7173: my ($context,$formname,$cdom,$cnum,$curr,$version,$crstype) = @_;
7174: my $lctype;
7175: if ($context eq 'course') {
7176: $lctype = lc($crstype);
7177: }
1.239 raeburn 7178: my $nolink = 1;
7179: my $output = '<table><tr><td valign="top">'.
1.301 bisitz 7180: '<span class="LC_nobreak"><b>'.&mt('Changes/page:').'</b></span><br />'.
1.239 raeburn 7181: &Apache::lonmeta::selectbox('show',$curr->{'show'},undef,
7182: (&mt('all'),5,10,20,50,100,1000,10000)).
7183: '</td><td> </td>';
7184: my $startform =
7185: &Apache::lonhtmlcommon::date_setter($formname,'rolelog_start_date',
7186: $curr->{'rolelog_start_date'},undef,
7187: undef,undef,undef,undef,undef,undef,$nolink);
7188: my $endform =
7189: &Apache::lonhtmlcommon::date_setter($formname,'rolelog_end_date',
7190: $curr->{'rolelog_end_date'},undef,
7191: undef,undef,undef,undef,undef,undef,$nolink);
1.363 raeburn 7192: my %lt = &rolechg_contexts($context,$crstype);
1.301 bisitz 7193: $output .= '<td valign="top"><b>'.&mt('Window during which changes occurred:').'</b><br />'.
7194: '<table><tr><td>'.&mt('After:').
7195: '</td><td>'.$startform.'</td></tr>'.
7196: '<tr><td>'.&mt('Before:').'</td>'.
7197: '<td>'.$endform.'</td></tr></table>'.
7198: '</td>'.
7199: '<td> </td>'.
1.239 raeburn 7200: '<td valign="top"><b>'.&mt('Role:').'</b><br />'.
7201: '<select name="role"><option value="any"';
7202: if ($curr->{'role'} eq 'any') {
7203: $output .= ' selected="selected"';
7204: }
7205: $output .= '>'.&mt('Any').'</option>'."\n";
1.363 raeburn 7206: my @roles = &Apache::lonuserutils::roles_by_context($context,1,$crstype);
1.239 raeburn 7207: foreach my $role (@roles) {
7208: my $plrole;
7209: if ($role eq 'cr') {
7210: $plrole = &mt('Custom Role');
7211: } else {
1.318 raeburn 7212: $plrole=&Apache::lonnet::plaintext($role,$crstype);
1.239 raeburn 7213: }
7214: my $selstr = '';
7215: if ($role eq $curr->{'role'}) {
7216: $selstr = ' selected="selected"';
7217: }
7218: $output .= ' <option value="'.$role.'"'.$selstr.'>'.$plrole.'</option>';
7219: }
1.301 bisitz 7220: $output .= '</select></td>'.
7221: '<td> </td>'.
7222: '<td valign="top"><b>'.
1.239 raeburn 7223: &mt('Context:').'</b><br /><select name="chgcontext">';
1.363 raeburn 7224: my @posscontexts;
7225: if ($context eq 'course') {
1.376 raeburn 7226: @posscontexts = ('any','automated','updatenow','createcourse','course','domain','selfenroll','requestcourses');
1.363 raeburn 7227: } elsif ($context eq 'domain') {
7228: @posscontexts = ('any','domain','requestauthor','domconfig','server');
7229: } else {
7230: @posscontexts = ('any','author','domain');
7231: }
7232: foreach my $chgtype (@posscontexts) {
1.239 raeburn 7233: my $selstr = '';
7234: if ($curr->{'chgcontext'} eq $chgtype) {
1.301 bisitz 7235: $selstr = ' selected="selected"';
1.239 raeburn 7236: }
1.363 raeburn 7237: if ($context eq 'course') {
1.376 raeburn 7238: if (($chgtype eq 'automated') || ($chgtype eq 'updatenow')) {
1.363 raeburn 7239: next if (!&Apache::lonnet::auto_run($cnum,$cdom));
7240: }
1.239 raeburn 7241: }
7242: $output .= '<option value="'.$chgtype.'"'.$selstr.'>'.$lt{$chgtype}.'</option>'."\n";
1.248 raeburn 7243: }
1.303 bisitz 7244: $output .= '</select></td>'
7245: .'</tr></table>';
7246:
7247: # Update Display button
7248: $output .= '<p>'
7249: .'<input type="submit" value="'.&mt('Update Display').'" />'
7250: .'</p>';
7251:
7252: # Server version info
1.363 raeburn 7253: my $needsrev = '2.11.0';
7254: if ($context eq 'course') {
7255: $needsrev = '2.7.0';
7256: }
7257:
1.303 bisitz 7258: $output .= '<p class="LC_info">'
7259: .&mt('Only changes made from servers running LON-CAPA [_1] or later are displayed.'
1.363 raeburn 7260: ,$needsrev);
1.248 raeburn 7261: if ($version) {
1.303 bisitz 7262: $output .= ' '.&mt('This LON-CAPA server is version [_1]',$version);
7263: }
7264: $output .= '</p><hr />';
1.239 raeburn 7265: return $output;
7266: }
7267:
7268: sub rolechg_contexts {
1.363 raeburn 7269: my ($context,$crstype) = @_;
7270: my %lt;
7271: if ($context eq 'course') {
7272: %lt = &Apache::lonlocal::texthash (
1.239 raeburn 7273: any => 'Any',
1.376 raeburn 7274: automated => 'Automated Enrollment',
1.239 raeburn 7275: updatenow => 'Roster Update',
7276: createcourse => 'Course Creation',
7277: course => 'User Management in course',
7278: domain => 'User Management in domain',
1.313 raeburn 7279: selfenroll => 'Self-enrolled',
1.318 raeburn 7280: requestcourses => 'Course Request',
1.239 raeburn 7281: );
1.363 raeburn 7282: if ($crstype eq 'Community') {
7283: $lt{'createcourse'} = &mt('Community Creation');
7284: $lt{'course'} = &mt('User Management in community');
7285: $lt{'requestcourses'} = &mt('Community Request');
7286: }
7287: } elsif ($context eq 'domain') {
7288: %lt = &Apache::lonlocal::texthash (
7289: any => 'Any',
7290: domain => 'User Management in domain',
7291: requestauthor => 'Authoring Request',
7292: server => 'Command line script (DC role)',
7293: domconfig => 'Self-enrolled',
7294: );
7295: } else {
7296: %lt = &Apache::lonlocal::texthash (
7297: any => 'Any',
7298: domain => 'User Management in domain',
7299: author => 'User Management by author',
7300: );
7301: }
1.239 raeburn 7302: return %lt;
7303: }
7304:
1.27 matthew 7305: #-------------------------------------------------- functions for &phase_two
1.160 raeburn 7306: sub user_search_result {
1.221 raeburn 7307: my ($context,$srch) = @_;
1.160 raeburn 7308: my %allhomes;
7309: my %inst_matches;
7310: my %srch_results;
1.181 raeburn 7311: my ($response,$currstate,$forcenewuser,$dirsrchres);
1.183 raeburn 7312: $srch->{'srchterm'} =~ s/\s+/ /g;
1.176 raeburn 7313: if ($srch->{'srchby'} !~ /^(uname|lastname|lastfirst)$/) {
1.160 raeburn 7314: $response = &mt('Invalid search.');
7315: }
7316: if ($srch->{'srchin'} !~ /^(crs|dom|alc|instd)$/) {
7317: $response = &mt('Invalid search.');
7318: }
1.177 raeburn 7319: if ($srch->{'srchtype'} !~ /^(exact|contains|begins)$/) {
1.160 raeburn 7320: $response = &mt('Invalid search.');
7321: }
7322: if ($srch->{'srchterm'} eq '') {
7323: $response = &mt('You must enter a search term.');
7324: }
1.183 raeburn 7325: if ($srch->{'srchterm'} =~ /^\s+$/) {
7326: $response = &mt('Your search term must contain more than just spaces.');
7327: }
1.160 raeburn 7328: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'instd')) {
7329: if (($srch->{'srchdomain'} eq '') ||
1.163 albertel 7330: ! (&Apache::lonnet::domain($srch->{'srchdomain'}))) {
1.160 raeburn 7331: $response = &mt('You must specify a valid domain when searching in a domain or institutional directory.')
7332: }
7333: }
7334: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs') ||
7335: ($srch->{'srchin'} eq 'alc')) {
1.176 raeburn 7336: if ($srch->{'srchby'} eq 'uname') {
1.243 raeburn 7337: my $unamecheck = $srch->{'srchterm'};
7338: if ($srch->{'srchtype'} eq 'contains') {
7339: if ($unamecheck !~ /^\w/) {
7340: $unamecheck = 'a'.$unamecheck;
7341: }
7342: }
7343: if ($unamecheck !~ /^$match_username$/) {
1.176 raeburn 7344: $response = &mt('You must specify a valid username. Only the following are allowed: letters numbers - . @');
7345: }
1.160 raeburn 7346: }
7347: }
1.180 raeburn 7348: if ($response ne '') {
1.413 raeburn 7349: $response = '<span class="LC_warning">'.$response.'</span><br />';
1.180 raeburn 7350: }
1.160 raeburn 7351: if ($srch->{'srchin'} eq 'instd') {
1.412 raeburn 7352: my $instd_chk = &instdirectorysrch_check($srch);
1.160 raeburn 7353: if ($instd_chk ne 'ok') {
1.412 raeburn 7354: my $domd_chk = &domdirectorysrch_check($srch);
1.413 raeburn 7355: $response .= '<span class="LC_warning">'.$instd_chk.'</span><br />';
1.412 raeburn 7356: if ($domd_chk eq 'ok') {
1.413 raeburn 7357: $response .= &mt('You may want to search in the LON-CAPA domain instead of the institutional directory.');
1.412 raeburn 7358: }
1.415 raeburn 7359: $response .= '<br />';
1.412 raeburn 7360: }
7361: } else {
1.417 raeburn 7362: unless (($context eq 'requestcrs') && ($srch->{'srchtype'} eq 'exact')) {
1.412 raeburn 7363: my $domd_chk = &domdirectorysrch_check($srch);
7364: if ($domd_chk ne 'ok') {
7365: my $instd_chk = &instdirectorysrch_check($srch);
1.413 raeburn 7366: $response .= '<span class="LC_warning">'.$domd_chk.'</span><br />';
1.412 raeburn 7367: if ($instd_chk eq 'ok') {
1.413 raeburn 7368: $response .= &mt('You may want to search in the institutional directory instead of the LON-CAPA domain.');
1.412 raeburn 7369: }
1.415 raeburn 7370: $response .= '<br />';
1.412 raeburn 7371: }
1.160 raeburn 7372: }
7373: }
7374: if ($response ne '') {
1.180 raeburn 7375: return ($currstate,$response);
1.160 raeburn 7376: }
7377: if ($srch->{'srchby'} eq 'uname') {
7378: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs')) {
7379: if ($env{'form.forcenew'}) {
7380: if ($srch->{'srchdomain'} ne $env{'request.role.domain'}) {
7381: my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
7382: if ($uhome eq 'no_host') {
7383: my $domdesc = &Apache::lonnet::domain($env{'request.role.domain'},'description');
1.180 raeburn 7384: my $showdom = &display_domain_info($env{'request.role.domain'});
7385: $response = &mt('New users can only be created in the domain to which your current role belongs - [_1].',$showdom);
1.160 raeburn 7386: } else {
1.179 raeburn 7387: $currstate = 'modify';
1.160 raeburn 7388: }
7389: } else {
1.179 raeburn 7390: $currstate = 'modify';
1.160 raeburn 7391: }
7392: } else {
7393: if ($srch->{'srchin'} eq 'dom') {
1.162 raeburn 7394: if ($srch->{'srchtype'} eq 'exact') {
7395: my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
7396: if ($uhome eq 'no_host') {
1.179 raeburn 7397: ($currstate,$response,$forcenewuser) =
1.221 raeburn 7398: &build_search_response($context,$srch,%srch_results);
1.162 raeburn 7399: } else {
1.179 raeburn 7400: $currstate = 'modify';
1.416 raeburn 7401: if ($env{'form.action'} eq 'accesslogs') {
7402: $currstate = 'activity';
7403: }
1.310 raeburn 7404: my $uname = $srch->{'srchterm'};
7405: my $udom = $srch->{'srchdomain'};
7406: $srch_results{$uname.':'.$udom} =
7407: { &Apache::lonnet::get('environment',
7408: ['firstname',
7409: 'lastname',
7410: 'permanentemail'],
7411: $udom,$uname)
7412: };
1.162 raeburn 7413: }
7414: } else {
7415: %srch_results = &Apache::lonnet::usersearch($srch);
1.179 raeburn 7416: ($currstate,$response,$forcenewuser) =
1.221 raeburn 7417: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 7418: }
7419: } else {
1.167 albertel 7420: my $courseusers = &get_courseusers();
1.162 raeburn 7421: if ($srch->{'srchtype'} eq 'exact') {
1.167 albertel 7422: if (exists($courseusers->{$srch->{'srchterm'}.':'.$srch->{'srchdomain'}})) {
1.179 raeburn 7423: $currstate = 'modify';
1.162 raeburn 7424: } else {
1.179 raeburn 7425: ($currstate,$response,$forcenewuser) =
1.221 raeburn 7426: &build_search_response($context,$srch,%srch_results);
1.162 raeburn 7427: }
1.160 raeburn 7428: } else {
1.167 albertel 7429: foreach my $user (keys(%$courseusers)) {
1.162 raeburn 7430: my ($cuname,$cudomain) = split(/:/,$user);
7431: if ($cudomain eq $srch->{'srchdomain'}) {
1.177 raeburn 7432: my $matched = 0;
7433: if ($srch->{'srchtype'} eq 'begins') {
7434: if ($cuname =~ /^\Q$srch->{'srchterm'}\E/i) {
7435: $matched = 1;
7436: }
7437: } else {
7438: if ($cuname =~ /\Q$srch->{'srchterm'}\E/i) {
7439: $matched = 1;
7440: }
7441: }
7442: if ($matched) {
1.167 albertel 7443: $srch_results{$user} =
7444: {&Apache::lonnet::get('environment',
7445: ['firstname',
7446: 'lastname',
1.194 albertel 7447: 'permanentemail'],
7448: $cudomain,$cuname)};
1.162 raeburn 7449: }
7450: }
7451: }
1.179 raeburn 7452: ($currstate,$response,$forcenewuser) =
1.221 raeburn 7453: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 7454: }
7455: }
7456: }
7457: } elsif ($srch->{'srchin'} eq 'alc') {
1.179 raeburn 7458: $currstate = 'query';
1.160 raeburn 7459: } elsif ($srch->{'srchin'} eq 'instd') {
1.181 raeburn 7460: ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
7461: if ($dirsrchres eq 'ok') {
7462: ($currstate,$response,$forcenewuser) =
1.221 raeburn 7463: &build_search_response($context,$srch,%srch_results);
1.181 raeburn 7464: } else {
7465: my $showdom = &display_domain_info($srch->{'srchdomain'});
7466: $response = '<span class="LC_warning">'.
7467: &mt('Institutional directory search is not available in domain: [_1]',$showdom).
7468: '</span><br />'.
7469: &mt('You may want to search in the LON-CAPA domain instead of the institutional directory.').
1.415 raeburn 7470: '<br />';
1.181 raeburn 7471: }
1.160 raeburn 7472: }
7473: } else {
7474: if ($srch->{'srchin'} eq 'dom') {
7475: %srch_results = &Apache::lonnet::usersearch($srch);
1.179 raeburn 7476: ($currstate,$response,$forcenewuser) =
1.221 raeburn 7477: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 7478: } elsif ($srch->{'srchin'} eq 'crs') {
1.167 albertel 7479: my $courseusers = &get_courseusers();
7480: foreach my $user (keys(%$courseusers)) {
1.160 raeburn 7481: my ($uname,$udom) = split(/:/,$user);
7482: my %names = &Apache::loncommon::getnames($uname,$udom);
7483: my %emails = &Apache::loncommon::getemails($uname,$udom);
7484: if ($srch->{'srchby'} eq 'lastname') {
7485: if ((($srch->{'srchtype'} eq 'exact') &&
7486: ($names{'lastname'} eq $srch->{'srchterm'})) ||
1.177 raeburn 7487: (($srch->{'srchtype'} eq 'begins') &&
7488: ($names{'lastname'} =~ /^\Q$srch->{'srchterm'}\E/i)) ||
1.160 raeburn 7489: (($srch->{'srchtype'} eq 'contains') &&
7490: ($names{'lastname'} =~ /\Q$srch->{'srchterm'}\E/i))) {
7491: $srch_results{$user} = {firstname => $names{'firstname'},
7492: lastname => $names{'lastname'},
7493: permanentemail => $emails{'permanentemail'},
7494: };
7495: }
7496: } elsif ($srch->{'srchby'} eq 'lastfirst') {
7497: my ($srchlast,$srchfirst) = split(/,/,$srch->{'srchterm'});
1.177 raeburn 7498: $srchlast =~ s/\s+$//;
7499: $srchfirst =~ s/^\s+//;
1.160 raeburn 7500: if ($srch->{'srchtype'} eq 'exact') {
7501: if (($names{'lastname'} eq $srchlast) &&
7502: ($names{'firstname'} eq $srchfirst)) {
7503: $srch_results{$user} = {firstname => $names{'firstname'},
7504: lastname => $names{'lastname'},
7505: permanentemail => $emails{'permanentemail'},
7506:
7507: };
7508: }
1.177 raeburn 7509: } elsif ($srch->{'srchtype'} eq 'begins') {
7510: if (($names{'lastname'} =~ /^\Q$srchlast\E/i) &&
7511: ($names{'firstname'} =~ /^\Q$srchfirst\E/i)) {
7512: $srch_results{$user} = {firstname => $names{'firstname'},
7513: lastname => $names{'lastname'},
7514: permanentemail => $emails{'permanentemail'},
7515: };
7516: }
7517: } else {
1.160 raeburn 7518: if (($names{'lastname'} =~ /\Q$srchlast\E/i) &&
7519: ($names{'firstname'} =~ /\Q$srchfirst\E/i)) {
7520: $srch_results{$user} = {firstname => $names{'firstname'},
7521: lastname => $names{'lastname'},
7522: permanentemail => $emails{'permanentemail'},
7523: };
7524: }
7525: }
7526: }
7527: }
1.179 raeburn 7528: ($currstate,$response,$forcenewuser) =
1.221 raeburn 7529: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 7530: } elsif ($srch->{'srchin'} eq 'alc') {
1.179 raeburn 7531: $currstate = 'query';
1.160 raeburn 7532: } elsif ($srch->{'srchin'} eq 'instd') {
1.181 raeburn 7533: ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
7534: if ($dirsrchres eq 'ok') {
7535: ($currstate,$response,$forcenewuser) =
1.221 raeburn 7536: &build_search_response($context,$srch,%srch_results);
1.181 raeburn 7537: } else {
1.412 raeburn 7538: my $showdom = &display_domain_info($srch->{'srchdomain'});
7539: $response = '<span class="LC_warning">'.
1.181 raeburn 7540: &mt('Institutional directory search is not available in domain: [_1]',$showdom).
7541: '</span><br />'.
7542: &mt('You may want to search in the LON-CAPA domain instead of the institutional directory.').
1.415 raeburn 7543: '<br />';
1.181 raeburn 7544: }
1.160 raeburn 7545: }
7546: }
1.179 raeburn 7547: return ($currstate,$response,$forcenewuser,\%srch_results);
1.160 raeburn 7548: }
7549:
1.412 raeburn 7550: sub domdirectorysrch_check {
7551: my ($srch) = @_;
7552: my $response;
7553: my %dom_inst_srch = &Apache::lonnet::get_dom('configuration',
7554: ['directorysrch'],$srch->{'srchdomain'});
7555: my $showdom = &display_domain_info($srch->{'srchdomain'});
7556: if (ref($dom_inst_srch{'directorysrch'}) eq 'HASH') {
7557: if ($dom_inst_srch{'directorysrch'}{'lcavailable'} eq '0') {
7558: return &mt('LON-CAPA directory search is not available in domain: [_1]',$showdom);
7559: }
7560: if ($dom_inst_srch{'directorysrch'}{'lclocalonly'}) {
7561: if ($env{'request.role.domain'} ne $srch->{'srchdomain'}) {
7562: return &mt('LON-CAPA directory search in domain: [_1] is only allowed for users with a current role in the domain.',$showdom);
7563: }
7564: }
7565: }
7566: return 'ok';
7567: }
7568:
7569: sub instdirectorysrch_check {
1.160 raeburn 7570: my ($srch) = @_;
7571: my $can_search = 0;
7572: my $response;
7573: my %dom_inst_srch = &Apache::lonnet::get_dom('configuration',
7574: ['directorysrch'],$srch->{'srchdomain'});
1.180 raeburn 7575: my $showdom = &display_domain_info($srch->{'srchdomain'});
1.160 raeburn 7576: if (ref($dom_inst_srch{'directorysrch'}) eq 'HASH') {
7577: if (!$dom_inst_srch{'directorysrch'}{'available'}) {
1.180 raeburn 7578: return &mt('Institutional directory search is not available in domain: [_1]',$showdom);
1.160 raeburn 7579: }
7580: if ($dom_inst_srch{'directorysrch'}{'localonly'}) {
7581: if ($env{'request.role.domain'} ne $srch->{'srchdomain'}) {
1.180 raeburn 7582: return &mt('Institutional directory search in domain: [_1] is only allowed for users with a current role in the domain.',$showdom);
1.160 raeburn 7583: }
7584: my @usertypes = split(/:/,$env{'environment.inststatus'});
7585: if (!@usertypes) {
7586: push(@usertypes,'default');
7587: }
7588: if (ref($dom_inst_srch{'directorysrch'}{'cansearch'}) eq 'ARRAY') {
7589: foreach my $type (@usertypes) {
7590: if (grep(/^\Q$type\E$/,@{$dom_inst_srch{'directorysrch'}{'cansearch'}})) {
7591: $can_search = 1;
7592: last;
7593: }
7594: }
7595: }
7596: if (!$can_search) {
7597: my ($insttypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($srch->{'srchdomain'});
7598: my @longtypes;
7599: foreach my $item (@usertypes) {
1.229 raeburn 7600: if (defined($insttypes->{$item})) {
7601: push (@longtypes,$insttypes->{$item});
7602: } elsif ($item eq 'default') {
7603: push (@longtypes,&mt('other'));
7604: }
1.160 raeburn 7605: }
7606: my $insttype_str = join(', ',@longtypes);
1.180 raeburn 7607: return &mt('Institutional directory search in domain: [_1] is not available to your user type: ',$showdom).$insttype_str;
1.229 raeburn 7608: }
1.160 raeburn 7609: } else {
7610: $can_search = 1;
7611: }
7612: } else {
1.180 raeburn 7613: return &mt('Institutional directory search has not been configured for domain: [_1]',$showdom);
1.160 raeburn 7614: }
7615: my %longtext = &Apache::lonlocal::texthash (
1.167 albertel 7616: uname => 'username',
1.160 raeburn 7617: lastfirst => 'last name, first name',
1.167 albertel 7618: lastname => 'last name',
1.172 raeburn 7619: contains => 'contains',
1.178 raeburn 7620: exact => 'as exact match to',
7621: begins => 'begins with',
1.160 raeburn 7622: );
7623: if ($can_search) {
7624: if (ref($dom_inst_srch{'directorysrch'}{'searchby'}) eq 'ARRAY') {
7625: if (!grep(/^\Q$srch->{'srchby'}\E$/,@{$dom_inst_srch{'directorysrch'}{'searchby'}})) {
1.180 raeburn 7626: return &mt('Institutional directory search in domain: [_1] is not available for searching by "[_2]"',$showdom,$longtext{$srch->{'srchby'}});
1.160 raeburn 7627: }
7628: } else {
1.180 raeburn 7629: return &mt('Institutional directory search in domain: [_1] is not available.', $showdom);
1.160 raeburn 7630: }
7631: }
7632: if ($can_search) {
1.178 raeburn 7633: if (ref($dom_inst_srch{'directorysrch'}{'searchtypes'}) eq 'ARRAY') {
7634: if (grep(/^\Q$srch->{'srchtype'}\E/,@{$dom_inst_srch{'directorysrch'}{'searchtypes'}})) {
7635: return 'ok';
7636: } else {
1.180 raeburn 7637: return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
1.178 raeburn 7638: }
7639: } else {
7640: if ((($dom_inst_srch{'directorysrch'}{'searchtypes'} eq 'specify') &&
7641: ($srch->{'srchtype'} eq 'exact' || $srch->{'srchtype'} eq 'contains')) ||
7642: ($dom_inst_srch{'directorysrch'}{'searchtypes'} eq $srch->{'srchtype'})) {
7643: return 'ok';
7644: } else {
1.180 raeburn 7645: return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
1.178 raeburn 7646: }
1.160 raeburn 7647: }
7648: }
7649: }
7650:
7651: sub get_courseusers {
7652: my %advhash;
1.167 albertel 7653: my $classlist = &Apache::loncoursedata::get_classlist();
1.160 raeburn 7654: my %coursepersonnel=&Apache::lonnet::get_course_adv_roles();
7655: foreach my $role (sort(keys(%coursepersonnel))) {
7656: foreach my $user (split(/\,/,$coursepersonnel{$role})) {
1.167 albertel 7657: if (!exists($classlist->{$user})) {
7658: $classlist->{$user} = [];
7659: }
1.160 raeburn 7660: }
7661: }
1.167 albertel 7662: return $classlist;
1.160 raeburn 7663: }
7664:
7665: sub build_search_response {
1.221 raeburn 7666: my ($context,$srch,%srch_results) = @_;
1.179 raeburn 7667: my ($currstate,$response,$forcenewuser);
1.160 raeburn 7668: my %names = (
1.330 bisitz 7669: 'uname' => 'username',
7670: 'lastname' => 'last name',
1.160 raeburn 7671: 'lastfirst' => 'last name, first name',
1.330 bisitz 7672: 'crs' => 'this course',
7673: 'dom' => 'LON-CAPA domain',
7674: 'instd' => 'the institutional directory for domain',
1.160 raeburn 7675: );
7676:
7677: my %single = (
1.180 raeburn 7678: begins => 'A match',
1.160 raeburn 7679: contains => 'A match',
1.180 raeburn 7680: exact => 'An exact match',
1.160 raeburn 7681: );
7682: my %nomatch = (
1.180 raeburn 7683: begins => 'No match',
1.160 raeburn 7684: contains => 'No match',
1.180 raeburn 7685: exact => 'No exact match',
1.160 raeburn 7686: );
7687: if (keys(%srch_results) > 1) {
1.179 raeburn 7688: $currstate = 'select';
1.160 raeburn 7689: } else {
7690: if (keys(%srch_results) == 1) {
1.416 raeburn 7691: if ($env{'form.action'} eq 'accesslogs') {
7692: $currstate = 'activity';
7693: } else {
7694: $currstate = 'modify';
7695: }
1.180 raeburn 7696: $response = &mt("$single{$srch->{'srchtype'}} was found for the $names{$srch->{'srchby'}} ([_1]) in $names{$srch->{'srchin'}}.",$srch->{'srchterm'});
7697: if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
1.330 bisitz 7698: $response .= ': '.&display_domain_info($srch->{'srchdomain'});
1.180 raeburn 7699: }
1.330 bisitz 7700: } else { # Search has nothing found. Prepare message to user.
7701: $response = '<span class="LC_warning">';
1.180 raeburn 7702: if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
1.330 bisitz 7703: $response .= &mt("$nomatch{$srch->{'srchtype'}} found for the $names{$srch->{'srchby'}} [_1] in $names{$srch->{'srchin'}}: [_2]",
7704: '<b>'.$srch->{'srchterm'}.'</b>',
7705: &display_domain_info($srch->{'srchdomain'}));
7706: } else {
7707: $response .= &mt("$nomatch{$srch->{'srchtype'}} found for the $names{$srch->{'srchby'}} [_1] in $names{$srch->{'srchin'}}.",
7708: '<b>'.$srch->{'srchterm'}.'</b>');
1.180 raeburn 7709: }
7710: $response .= '</span>';
1.330 bisitz 7711:
1.160 raeburn 7712: if ($srch->{'srchin'} ne 'alc') {
7713: $forcenewuser = 1;
7714: my $cansrchinst = 0;
7715: if ($srch->{'srchdomain'}) {
7716: my %domconfig = &Apache::lonnet::get_dom('configuration',['directorysrch'],$srch->{'srchdomain'});
7717: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
7718: if ($domconfig{'directorysrch'}{'available'}) {
7719: $cansrchinst = 1;
7720: }
7721: }
7722: }
1.180 raeburn 7723: if ((($srch->{'srchby'} eq 'lastfirst') ||
7724: ($srch->{'srchby'} eq 'lastname')) &&
7725: ($srch->{'srchin'} eq 'dom')) {
7726: if ($cansrchinst) {
7727: $response .= '<br />'.&mt('You may want to broaden your search to a search of the institutional directory for the domain.');
1.160 raeburn 7728: }
7729: }
1.180 raeburn 7730: if ($srch->{'srchin'} eq 'crs') {
7731: $response .= '<br />'.&mt('You may want to broaden your search to the selected LON-CAPA domain.');
7732: }
7733: }
1.305 raeburn 7734: my $createdom = $env{'request.role.domain'};
7735: if ($context eq 'requestcrs') {
7736: if ($env{'form.coursedom'} ne '') {
7737: $createdom = $env{'form.coursedom'};
7738: }
7739: }
1.416 raeburn 7740: unless (($env{'form.action'} eq 'accesslogs') || (($srch->{'srchby'} eq 'uname') && ($srch->{'srchin'} eq 'dom') &&
7741: ($srch->{'srchtype'} eq 'exact') && ($srch->{'srchdomain'} eq $createdom))) {
1.221 raeburn 7742: my $cancreate =
1.305 raeburn 7743: &Apache::lonuserutils::can_create_user($createdom,$context);
7744: my $targetdom = '<span class="LC_cusr_emph">'.$createdom.'</span>';
1.221 raeburn 7745: if ($cancreate) {
1.305 raeburn 7746: my $showdom = &display_domain_info($createdom);
1.266 bisitz 7747: $response .= '<br /><br />'
7748: .'<b>'.&mt('To add a new user:').'</b>'
1.305 raeburn 7749: .'<br />';
7750: if ($context eq 'requestcrs') {
7751: $response .= &mt("(You can only define new users in the new course's domain - [_1])",$targetdom);
7752: } else {
7753: $response .= &mt("(You can only create new users in your current role's domain - [_1])",$targetdom);
7754: }
7755: $response .='<ul><li>'
1.266 bisitz 7756: .&mt("Set 'Domain/institution to search' to: [_1]",'<span class="LC_cusr_emph">'.$showdom.'</span>')
7757: .'</li><li>'
7758: .&mt("Set 'Search criteria' to: [_1]username is ..... in selected LON-CAPA domain[_2]",'<span class="LC_cusr_emph">','</span>')
7759: .'</li><li>'
7760: .&mt('Provide the proposed username')
7761: .'</li><li>'
7762: .&mt("Click 'Search'")
7763: .'</li></ul><br />';
1.221 raeburn 7764: } else {
7765: my $helplink = ' href="javascript:helpMenu('."'display'".')"';
1.305 raeburn 7766: $response .= '<br /><br />';
7767: if ($context eq 'requestcrs') {
1.314 raeburn 7768: $response .= &mt("You are not authorized to define new users in the new course's domain - [_1].",$targetdom);
1.305 raeburn 7769: } else {
7770: $response .= &mt("You are not authorized to create new users in your current role's domain - [_1].",$targetdom);
7771: }
7772: $response .= '<br />'
7773: .&mt('Please contact the [_1]helpdesk[_2] if you need to create a new user.'
1.266 bisitz 7774: ,' <a'.$helplink.'>'
7775: ,'</a>')
1.415 raeburn 7776: .'<br />';
1.221 raeburn 7777: }
1.160 raeburn 7778: }
7779: }
7780: }
1.179 raeburn 7781: return ($currstate,$response,$forcenewuser);
1.160 raeburn 7782: }
7783:
1.180 raeburn 7784: sub display_domain_info {
7785: my ($dom) = @_;
7786: my $output = $dom;
7787: if ($dom ne '') {
7788: my $domdesc = &Apache::lonnet::domain($dom,'description');
7789: if ($domdesc ne '') {
7790: $output .= ' <span class="LC_cusr_emph">('.$domdesc.')</span>';
7791: }
7792: }
7793: return $output;
7794: }
7795:
1.160 raeburn 7796: sub crumb_utilities {
7797: my %elements = (
7798: crtuser => {
7799: srchterm => 'text',
1.172 raeburn 7800: srchin => 'selectbox',
1.160 raeburn 7801: srchby => 'selectbox',
7802: srchtype => 'selectbox',
7803: srchdomain => 'selectbox',
7804: },
1.207 raeburn 7805: crtusername => {
7806: srchterm => 'text',
7807: srchdomain => 'selectbox',
7808: },
1.160 raeburn 7809: docustom => {
7810: rolename => 'selectbox',
7811: newrolename => 'textbox',
7812: },
1.179 raeburn 7813: studentform => {
7814: srchterm => 'text',
7815: srchin => 'selectbox',
7816: srchby => 'selectbox',
7817: srchtype => 'selectbox',
7818: srchdomain => 'selectbox',
7819: },
1.160 raeburn 7820: );
7821:
7822: my $jsback .= qq|
7823: function backPage(formname,prevphase,prevstate) {
1.211 raeburn 7824: if (typeof prevphase == 'undefined') {
7825: formname.phase.value = '';
7826: }
7827: else {
7828: formname.phase.value = prevphase;
7829: }
7830: if (typeof prevstate == 'undefined') {
7831: formname.currstate.value = '';
7832: }
7833: else {
7834: formname.currstate.value = prevstate;
7835: }
1.160 raeburn 7836: formname.submit();
7837: }
7838: |;
7839: return ($jsback,\%elements);
7840: }
7841:
1.26 matthew 7842: sub course_level_table {
1.375 raeburn 7843: my ($inccourses,$showcredits,$defaultcredits) = @_;
7844: return unless (ref($inccourses) eq 'HASH');
1.26 matthew 7845: my $table = '';
1.62 www 7846: # Custom Roles?
7847:
1.190 raeburn 7848: my %customroles=&Apache::lonuserutils::my_custom_roles();
1.89 raeburn 7849: my %lt=&Apache::lonlocal::texthash(
7850: 'exs' => "Existing sections",
7851: 'new' => "Define new section",
7852: 'ssd' => "Set Start Date",
7853: 'sed' => "Set End Date",
1.131 raeburn 7854: 'crl' => "Course Level",
1.89 raeburn 7855: 'act' => "Activate",
7856: 'rol' => "Role",
7857: 'ext' => "Extent",
1.113 raeburn 7858: 'grs' => "Section",
1.375 raeburn 7859: 'crd' => "Credits",
1.89 raeburn 7860: 'sta' => "Start",
7861: 'end' => "End"
7862: );
1.62 www 7863:
1.375 raeburn 7864: foreach my $protectedcourse (sort(keys(%{$inccourses}))) {
1.135 raeburn 7865: my $thiscourse=$protectedcourse;
1.26 matthew 7866: $thiscourse=~s:_:/:g;
7867: my %coursedata=&Apache::lonnet::coursedescription($thiscourse);
1.365 raeburn 7868: my $isowner = &Apache::lonuserutils::is_courseowner($protectedcourse,$coursedata{'internal.courseowner'});
1.26 matthew 7869: my $area=$coursedata{'description'};
1.321 raeburn 7870: my $crstype=$coursedata{'type'};
1.135 raeburn 7871: if (!defined($area)) { $area=&mt('Unavailable course').': '.$protectedcourse; }
1.89 raeburn 7872: my ($domain,$cnum)=split(/\//,$thiscourse);
1.115 albertel 7873: my %sections_count;
1.101 albertel 7874: if (defined($env{'request.course.id'})) {
7875: if ($env{'request.course.id'} eq $domain.'_'.$cnum) {
1.115 albertel 7876: %sections_count =
7877: &Apache::loncommon::get_sections($domain,$cnum);
1.92 raeburn 7878: }
7879: }
1.321 raeburn 7880: my @roles = &Apache::lonuserutils::roles_by_context('course','',$crstype);
1.213 raeburn 7881: foreach my $role (@roles) {
1.321 raeburn 7882: my $plrole=&Apache::lonnet::plaintext($role,$crstype);
1.329 raeburn 7883: if ((&Apache::lonnet::allowed('c'.$role,$thiscourse)) ||
7884: ((($role eq 'cc') || ($role eq 'co')) && ($isowner))) {
1.221 raeburn 7885: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
1.375 raeburn 7886: $plrole,\%sections_count,\%lt,
1.402 raeburn 7887: $showcredits,$defaultcredits,$crstype);
1.221 raeburn 7888: } elsif ($env{'request.course.sec'} ne '') {
7889: if (&Apache::lonnet::allowed('c'.$role,$thiscourse.'/'.
7890: $env{'request.course.sec'})) {
7891: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
1.375 raeburn 7892: $plrole,\%sections_count,\%lt,
1.402 raeburn 7893: $showcredits,$defaultcredits,$crstype);
1.26 matthew 7894: }
7895: }
7896: }
1.221 raeburn 7897: if (&Apache::lonnet::allowed('ccr',$thiscourse)) {
1.324 raeburn 7898: foreach my $cust (sort(keys(%customroles))) {
7899: next if ($crstype eq 'Community' && $customroles{$cust} =~ /bre\&S/);
1.221 raeburn 7900: my $role = 'cr_cr_'.$env{'user.domain'}.'_'.$env{'user.name'}.'_'.$cust;
7901: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
1.402 raeburn 7902: $cust,\%sections_count,\%lt,
7903: $showcredits,$defaultcredits,$crstype);
1.221 raeburn 7904: }
1.62 www 7905: }
1.26 matthew 7906: }
7907: return '' if ($table eq ''); # return nothing if there is nothing
7908: # in the table
1.188 raeburn 7909: my $result;
7910: if (!$env{'request.course.id'}) {
7911: $result = '<h4>'.$lt{'crl'}.'</h4>'."\n";
7912: }
7913: $result .=
1.136 raeburn 7914: &Apache::loncommon::start_data_table().
7915: &Apache::loncommon::start_data_table_header_row().
1.375 raeburn 7916: '<th>'.$lt{'act'}.'</th><th>'.$lt{'rol'}.'</th>'."\n".
1.402 raeburn 7917: '<th>'.$lt{'ext'}.'</th><th>'."\n";
7918: if ($showcredits) {
7919: $result .= $lt{'crd'}.'</th>';
7920: }
7921: $result .=
1.375 raeburn 7922: '<th>'.$lt{'grs'}.'</th><th>'.$lt{'sta'}.'</th>'."\n".
7923: '<th>'.$lt{'end'}.'</th>'.
1.136 raeburn 7924: &Apache::loncommon::end_data_table_header_row().
7925: $table.
7926: &Apache::loncommon::end_data_table();
1.26 matthew 7927: return $result;
7928: }
1.88 raeburn 7929:
1.221 raeburn 7930: sub course_level_row {
1.375 raeburn 7931: my ($protectedcourse,$role,$area,$domain,$plrole,$sections_count,
1.402 raeburn 7932: $lt,$showcredits,$defaultcredits,$crstype) = @_;
1.375 raeburn 7933: my $creditem;
1.222 raeburn 7934: my $row = &Apache::loncommon::start_data_table_row().
7935: ' <td><input type="checkbox" name="act_'.
7936: $protectedcourse.'_'.$role.'" /></td>'."\n".
7937: ' <td>'.$plrole.'</td>'."\n".
7938: ' <td>'.$area.'<br />Domain: '.$domain.'</td>'."\n";
1.402 raeburn 7939: if (($showcredits) && ($role eq 'st') && ($crstype eq 'Course')) {
1.375 raeburn 7940: $row .=
7941: '<td><input type="text" name="credits_'.$protectedcourse.'_'.
7942: $role.'" size="3" value="'.$defaultcredits.'" /></td>';
7943: } else {
7944: $row .= '<td> </td>';
7945: }
1.322 raeburn 7946: if (($role eq 'cc') || ($role eq 'co')) {
1.222 raeburn 7947: $row .= '<td> </td>';
1.221 raeburn 7948: } elsif ($env{'request.course.sec'} ne '') {
1.222 raeburn 7949: $row .= ' <td><input type="hidden" value="'.
7950: $env{'request.course.sec'}.'" '.
7951: 'name="sec_'.$protectedcourse.'_'.$role.'" />'.
7952: $env{'request.course.sec'}.'</td>';
1.221 raeburn 7953: } else {
7954: if (ref($sections_count) eq 'HASH') {
7955: my $currsec =
7956: &Apache::lonuserutils::course_sections($sections_count,
7957: $protectedcourse.'_'.$role);
1.222 raeburn 7958: $row .= '<td><table class="LC_createuser">'."\n".
7959: '<tr class="LC_section_row">'."\n".
7960: ' <td valign="top">'.$lt->{'exs'}.'<br />'.
7961: $currsec.'</td>'."\n".
7962: ' <td> </td>'."\n".
7963: ' <td valign="top"> '.$lt->{'new'}.'<br />'.
1.221 raeburn 7964: '<input type="text" name="newsec_'.$protectedcourse.'_'.$role.
7965: '" value="" />'.
7966: '<input type="hidden" '.
7967: 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'."\n".
1.222 raeburn 7968: '</tr></table></td>'."\n";
1.221 raeburn 7969: } else {
1.222 raeburn 7970: $row .= '<td><input type="text" size="10" '.
1.375 raeburn 7971: 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'."\n";
1.221 raeburn 7972: }
7973: }
1.222 raeburn 7974: $row .= <<ENDTIMEENTRY;
7975: <td><input type="hidden" name="start_$protectedcourse\_$role" value="" />
1.221 raeburn 7976: <a href=
7977: "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 7978: <td><input type="hidden" name="end_$protectedcourse\_$role" value="" />
1.221 raeburn 7979: <a href=
7980: "javascript:pjump('date_end','End Date $plrole',document.cu.end_$protectedcourse\_$role.value,'end_$protectedcourse\_$role','cu.pres','dateset')">$lt->{'sed'}</a></td>
7981: ENDTIMEENTRY
1.222 raeburn 7982: $row .= &Apache::loncommon::end_data_table_row();
7983: return $row;
1.221 raeburn 7984: }
7985:
1.88 raeburn 7986: sub course_level_dc {
1.375 raeburn 7987: my ($dcdom,$showcredits) = @_;
1.190 raeburn 7988: my %customroles=&Apache::lonuserutils::my_custom_roles();
1.213 raeburn 7989: my @roles = &Apache::lonuserutils::roles_by_context('course');
1.88 raeburn 7990: my $hiddenitems = '<input type="hidden" name="dcdomain" value="'.$dcdom.'" />'.
7991: '<input type="hidden" name="origdom" value="'.$dcdom.'" />'.
1.133 raeburn 7992: '<input type="hidden" name="dccourse" value="" />';
1.355 www 7993: my $courseform=&Apache::loncommon::selectcourse_link
1.356 raeburn 7994: ('cu','dccourse','dcdomain','coursedesc',undef,undef,'Select','crstype');
1.375 raeburn 7995: my $credit_elem;
7996: if ($showcredits) {
7997: $credit_elem = 'credits';
7998: }
7999: my $cb_jscript = &Apache::loncommon::coursebrowser_javascript($dcdom,'currsec','cu','role','Course/Community Browser',$credit_elem);
1.88 raeburn 8000: my %lt=&Apache::lonlocal::texthash(
8001: 'rol' => "Role",
1.113 raeburn 8002: 'grs' => "Section",
1.88 raeburn 8003: 'exs' => "Existing sections",
8004: 'new' => "Define new section",
8005: 'sta' => "Start",
8006: 'end' => "End",
8007: 'ssd' => "Set Start Date",
1.355 www 8008: 'sed' => "Set End Date",
1.375 raeburn 8009: 'scc' => "Course/Community",
8010: 'crd' => "Credits",
1.88 raeburn 8011: );
1.323 raeburn 8012: my $header = '<h4>'.&mt('Course/Community Level').'</h4>'.
1.136 raeburn 8013: &Apache::loncommon::start_data_table().
8014: &Apache::loncommon::start_data_table_header_row().
1.375 raeburn 8015: '<th>'.$lt{'scc'}.'</th><th>'.$lt{'rol'}.'</th>'."\n".
1.397 bisitz 8016: '<th>'.$lt{'grs'}.'</th>'."\n";
8017: $header .= '<th>'.$lt{'crd'}.'</th>'."\n" if ($showcredits);
8018: $header .= '<th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'."\n".
1.136 raeburn 8019: &Apache::loncommon::end_data_table_header_row();
1.143 raeburn 8020: my $otheritems = &Apache::loncommon::start_data_table_row()."\n".
1.356 raeburn 8021: '<td><br /><span class="LC_nobreak"><input type="text" name="coursedesc" value="" onfocus="this.blur();opencrsbrowser('."'cu','dccourse','dcdomain','coursedesc','','','','crstype'".')" />'.
8022: $courseform.(' ' x4).'</span></td>'."\n".
1.389 bisitz 8023: '<td valign="top"><br /><select name="role">'."\n";
1.213 raeburn 8024: foreach my $role (@roles) {
1.135 raeburn 8025: my $plrole=&Apache::lonnet::plaintext($role);
1.389 bisitz 8026: $otheritems .= ' <option value="'.$role.'">'.$plrole.'</option>';
1.88 raeburn 8027: }
1.404 raeburn 8028: if ( keys(%customroles) > 0) {
8029: foreach my $cust (sort(keys(%customroles))) {
1.101 albertel 8030: my $custrole='cr_cr_'.$env{'user.domain'}.
1.135 raeburn 8031: '_'.$env{'user.name'}.'_'.$cust;
1.389 bisitz 8032: $otheritems .= ' <option value="'.$custrole.'">'.$cust.'</option>';
1.88 raeburn 8033: }
8034: }
8035: $otheritems .= '</select></td><td>'.
8036: '<table border="0" cellspacing="0" cellpadding="0">'.
8037: '<tr><td valign="top"><b>'.$lt{'exs'}.'</b><br /><select name="currsec">'.
1.389 bisitz 8038: ' <option value=""><--'.&mt('Pick course first').'</option></select></td>'.
1.88 raeburn 8039: '<td> </td>'.
8040: '<td valign="top"> <b>'.$lt{'new'}.'</b><br />'.
1.113 raeburn 8041: '<input type="text" name="newsec" value="" />'.
1.237 raeburn 8042: '<input type="hidden" name="section" value="" />'.
1.323 raeburn 8043: '<input type="hidden" name="groups" value="" />'.
8044: '<input type="hidden" name="crstype" value="" /></td>'.
1.375 raeburn 8045: '</tr></table></td>'."\n";
8046: if ($showcredits) {
8047: $otheritems .= '<td><br />'."\n".
1.397 bisitz 8048: '<input type="text" size="3" name="credits" value="" /></td>'."\n";
1.375 raeburn 8049: }
1.88 raeburn 8050: $otheritems .= <<ENDTIMEENTRY;
1.323 raeburn 8051: <td><br /><input type="hidden" name="start" value='' />
1.88 raeburn 8052: <a href=
8053: "javascript:pjump('date_start','Start Date',document.cu.start.value,'start','cu.pres','dateset')">$lt{'ssd'}</a></td>
1.323 raeburn 8054: <td><br /><input type="hidden" name="end" value='' />
1.88 raeburn 8055: <a href=
8056: "javascript:pjump('date_end','End Date',document.cu.end.value,'end','cu.pres','dateset')">$lt{'sed'}</a></td>
8057: ENDTIMEENTRY
1.136 raeburn 8058: $otheritems .= &Apache::loncommon::end_data_table_row().
8059: &Apache::loncommon::end_data_table()."\n";
1.88 raeburn 8060: return $cb_jscript.$header.$hiddenitems.$otheritems;
8061: }
8062:
1.237 raeburn 8063: sub update_selfenroll_config {
1.400 raeburn 8064: my ($r,$cid,$cdom,$cnum,$context,$crstype,$currsettings) = @_;
1.398 raeburn 8065: return unless (ref($currsettings) eq 'HASH');
8066: my ($row,$lt) = &Apache::lonuserutils::get_selfenroll_titles();
8067: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
1.237 raeburn 8068: my (%changes,%warning);
1.241 raeburn 8069: my $curr_types;
1.400 raeburn 8070: my %noedit;
8071: unless ($context eq 'domain') {
8072: %noedit = &get_noedit_fields($cdom,$cnum,$crstype,$row);
8073: }
1.237 raeburn 8074: if (ref($row) eq 'ARRAY') {
8075: foreach my $item (@{$row}) {
1.400 raeburn 8076: next if ($noedit{$item});
1.237 raeburn 8077: if ($item eq 'enroll_dates') {
8078: my (%currenrolldate,%newenrolldate);
8079: foreach my $type ('start','end') {
1.398 raeburn 8080: $currenrolldate{$type} = $currsettings->{'selfenroll_'.$type.'_date'};
1.237 raeburn 8081: $newenrolldate{$type} = &Apache::lonhtmlcommon::get_date_from_form('selfenroll_'.$type.'_date');
8082: if ($newenrolldate{$type} ne $currenrolldate{$type}) {
8083: $changes{'internal.selfenroll_'.$type.'_date'} = $newenrolldate{$type};
8084: }
8085: }
8086: } elsif ($item eq 'access_dates') {
8087: my (%currdate,%newdate);
8088: foreach my $type ('start','end') {
1.398 raeburn 8089: $currdate{$type} = $currsettings->{'selfenroll_'.$type.'_access'};
1.237 raeburn 8090: $newdate{$type} = &Apache::lonhtmlcommon::get_date_from_form('selfenroll_'.$type.'_access');
8091: if ($newdate{$type} ne $currdate{$type}) {
8092: $changes{'internal.selfenroll_'.$type.'_access'} = $newdate{$type};
8093: }
8094: }
1.241 raeburn 8095: } elsif ($item eq 'types') {
1.398 raeburn 8096: $curr_types = $currsettings->{'selfenroll_'.$item};
1.241 raeburn 8097: if ($env{'form.selfenroll_all'}) {
8098: if ($curr_types ne '*') {
8099: $changes{'internal.selfenroll_types'} = '*';
8100: } else {
8101: next;
8102: }
8103: } else {
1.249 raeburn 8104: my %currdoms;
1.241 raeburn 8105: my @entries = split(/;/,$curr_types);
8106: my @deletedoms = &Apache::loncommon::get_env_multiple('form.selfenroll_delete');
1.249 raeburn 8107: my @activations = &Apache::loncommon::get_env_multiple('form.selfenroll_activate');
1.241 raeburn 8108: my $newnum = 0;
1.249 raeburn 8109: my @latesttypes;
8110: foreach my $num (@activations) {
8111: my @types = &Apache::loncommon::get_env_multiple('form.selfenroll_types_'.$num);
8112: if (@types > 0) {
1.241 raeburn 8113: @types = sort(@types);
8114: my $typestr = join(',',@types);
1.249 raeburn 8115: my $typedom = $env{'form.selfenroll_dom_'.$num};
8116: $latesttypes[$newnum] = $typedom.':'.$typestr;
8117: $currdoms{$typedom} = 1;
1.241 raeburn 8118: $newnum ++;
8119: }
8120: }
1.338 raeburn 8121: for (my $j=0; $j<$env{'form.selfenroll_types_total'}; $j++) {
8122: if ((!grep(/^$j$/,@deletedoms)) && (!grep(/^$j$/,@activations))) {
1.249 raeburn 8123: my @types = &Apache::loncommon::get_env_multiple('form.selfenroll_types_'.$j);
8124: if (@types > 0) {
8125: @types = sort(@types);
8126: my $typestr = join(',',@types);
8127: my $typedom = $env{'form.selfenroll_dom_'.$j};
8128: $latesttypes[$newnum] = $typedom.':'.$typestr;
8129: $currdoms{$typedom} = 1;
8130: $newnum ++;
8131: }
8132: }
8133: }
8134: if ($env{'form.selfenroll_newdom'} ne '') {
8135: my $typedom = $env{'form.selfenroll_newdom'};
8136: if ((!defined($currdoms{$typedom})) &&
8137: (&Apache::lonnet::domain($typedom) ne '')) {
8138: my $typestr;
8139: my ($othertitle,$usertypes,$types) =
8140: &Apache::loncommon::sorted_inst_types($typedom);
8141: my $othervalue = 'any';
8142: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
8143: if (@{$types} > 0) {
1.257 raeburn 8144: my @esc_types = map { &escape($_); } @{$types};
1.249 raeburn 8145: $othervalue = 'other';
1.258 raeburn 8146: $typestr = join(',',(@esc_types,$othervalue));
1.249 raeburn 8147: }
8148: $typestr = $othervalue;
8149: } else {
8150: $typestr = $othervalue;
8151: }
8152: $latesttypes[$newnum] = $typedom.':'.$typestr;
8153: $newnum ++ ;
8154: }
8155: }
1.241 raeburn 8156: my $selfenroll_types = join(';',@latesttypes);
8157: if ($selfenroll_types ne $curr_types) {
8158: $changes{'internal.selfenroll_types'} = $selfenroll_types;
8159: }
8160: }
1.276 raeburn 8161: } elsif ($item eq 'limit') {
8162: my $newlimit = $env{'form.selfenroll_limit'};
8163: my $newcap = $env{'form.selfenroll_cap'};
8164: $newcap =~s/\s+//g;
1.398 raeburn 8165: my $currlimit = $currsettings->{'selfenroll_limit'};
1.276 raeburn 8166: $currlimit = 'none' if ($currlimit eq '');
1.398 raeburn 8167: my $currcap = $currsettings->{'selfenroll_cap'};
1.276 raeburn 8168: if ($newlimit ne $currlimit) {
8169: if ($newlimit ne 'none') {
8170: if ($newcap =~ /^\d+$/) {
8171: if ($newcap ne $currcap) {
8172: $changes{'internal.selfenroll_cap'} = $newcap;
8173: }
8174: $changes{'internal.selfenroll_limit'} = $newlimit;
8175: } else {
1.398 raeburn 8176: $warning{$item} = &mt('Maximum enrollment setting unchanged.').'<br />'.
8177: &mt('The value provided was invalid - it must be a positive integer if enrollment is being limited.');
1.276 raeburn 8178: }
8179: } elsif ($currcap ne '') {
8180: $changes{'internal.selfenroll_cap'} = '';
8181: $changes{'internal.selfenroll_limit'} = $newlimit;
8182: }
8183: } elsif ($currlimit ne 'none') {
8184: if ($newcap =~ /^\d+$/) {
8185: if ($newcap ne $currcap) {
8186: $changes{'internal.selfenroll_cap'} = $newcap;
8187: }
8188: } else {
1.398 raeburn 8189: $warning{$item} = &mt('Maximum enrollment setting unchanged.').'<br />'.
8190: &mt('The value provided was invalid - it must be a positive integer if enrollment is being limited.');
1.276 raeburn 8191: }
8192: }
8193: } elsif ($item eq 'approval') {
8194: my (@currnotified,@newnotified);
1.398 raeburn 8195: my $currapproval = $currsettings->{'selfenroll_approval'};
8196: my $currnotifylist = $currsettings->{'selfenroll_notifylist'};
1.276 raeburn 8197: if ($currnotifylist ne '') {
8198: @currnotified = split(/,/,$currnotifylist);
8199: @currnotified = sort(@currnotified);
8200: }
8201: my $newapproval = $env{'form.selfenroll_approval'};
8202: @newnotified = &Apache::loncommon::get_env_multiple('form.selfenroll_notify');
8203: @newnotified = sort(@newnotified);
8204: if ($newapproval ne $currapproval) {
8205: $changes{'internal.selfenroll_approval'} = $newapproval;
8206: if (!$newapproval) {
8207: if ($currnotifylist ne '') {
8208: $changes{'internal.selfenroll_notifylist'} = '';
8209: }
8210: } else {
8211: my @differences =
1.295 raeburn 8212: &Apache::loncommon::compare_arrays(\@currnotified,\@newnotified);
1.276 raeburn 8213: if (@differences > 0) {
8214: if (@newnotified > 0) {
8215: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
8216: } else {
8217: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
8218: }
8219: }
8220: }
8221: } else {
1.295 raeburn 8222: my @differences = &Apache::loncommon::compare_arrays(\@currnotified,\@newnotified);
1.276 raeburn 8223: if (@differences > 0) {
8224: if (@newnotified > 0) {
8225: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
8226: } else {
8227: $changes{'internal.selfenroll_notifylist'} = '';
8228: }
8229: }
8230: }
1.237 raeburn 8231: } else {
1.398 raeburn 8232: my $curr_val = $currsettings->{'selfenroll_'.$item};
1.237 raeburn 8233: my $newval = $env{'form.selfenroll_'.$item};
8234: if ($item eq 'section') {
8235: $newval = $env{'form.sections'};
1.241 raeburn 8236: if (defined($curr_groups{$newval})) {
1.237 raeburn 8237: $newval = $curr_val;
1.398 raeburn 8238: $warning{$item} = &mt('Section for self-enrolled users unchanged as the proposed section is a group').'<br />'.
8239: &mt('Group names and section names must be distinct');
1.237 raeburn 8240: } elsif ($newval eq 'all') {
8241: $newval = $curr_val;
1.274 bisitz 8242: $warning{$item} = &mt('Section for self-enrolled users unchanged, as "all" is a reserved section name.');
1.237 raeburn 8243: }
8244: if ($newval eq '') {
8245: $newval = 'none';
8246: }
8247: }
8248: if ($newval ne $curr_val) {
8249: $changes{'internal.selfenroll_'.$item} = $newval;
8250: }
1.241 raeburn 8251: }
1.237 raeburn 8252: }
8253: if (keys(%warning) > 0) {
8254: foreach my $item (@{$row}) {
8255: if (exists($warning{$item})) {
8256: $r->print($warning{$item}.'<br />');
8257: }
8258: }
8259: }
8260: if (keys(%changes) > 0) {
8261: my $putresult = &Apache::lonnet::put('environment',\%changes,$cdom,$cnum);
8262: if ($putresult eq 'ok') {
8263: if ((exists($changes{'internal.selfenroll_types'})) ||
8264: (exists($changes{'internal.selfenroll_start_date'})) ||
8265: (exists($changes{'internal.selfenroll_end_date'}))) {
8266: my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',
8267: $cnum,undef,undef,'Course');
8268: my $chome = &Apache::lonnet::homeserver($cnum,$cdom);
1.398 raeburn 8269: if (ref($crsinfo{$cid}) eq 'HASH') {
1.237 raeburn 8270: foreach my $item ('selfenroll_types','selfenroll_start_date','selfenroll_end_date') {
8271: if (exists($changes{'internal.'.$item})) {
1.398 raeburn 8272: $crsinfo{$cid}{$item} = $changes{'internal.'.$item};
1.237 raeburn 8273: }
8274: }
8275: my $crsputresult =
8276: &Apache::lonnet::courseidput($cdom,\%crsinfo,
8277: $chome,'notime');
8278: }
8279: }
8280: $r->print(&mt('The following changes were made to self-enrollment settings:').'<ul>');
8281: foreach my $item (@{$row}) {
8282: my $title = $item;
8283: if (ref($lt) eq 'HASH') {
8284: $title = $lt->{$item};
8285: }
8286: if ($item eq 'enroll_dates') {
8287: foreach my $type ('start','end') {
8288: if (exists($changes{'internal.selfenroll_'.$type.'_date'})) {
8289: my $newdate = &Apache::lonlocal::locallocaltime($changes{'internal.selfenroll_'.$type.'_date'});
1.244 bisitz 8290: $r->print('<li>'.&mt('[_1]: "[_2]" set to "[_3]".',
1.237 raeburn 8291: $title,$type,$newdate).'</li>');
8292: }
8293: }
8294: } elsif ($item eq 'access_dates') {
8295: foreach my $type ('start','end') {
8296: if (exists($changes{'internal.selfenroll_'.$type.'_access'})) {
8297: my $newdate = &Apache::lonlocal::locallocaltime($changes{'internal.selfenroll_'.$type.'_access'});
1.244 bisitz 8298: $r->print('<li>'.&mt('[_1]: "[_2]" set to "[_3]".',
1.237 raeburn 8299: $title,$type,$newdate).'</li>');
8300: }
8301: }
1.276 raeburn 8302: } elsif ($item eq 'limit') {
8303: if ((exists($changes{'internal.selfenroll_limit'})) ||
8304: (exists($changes{'internal.selfenroll_cap'}))) {
8305: my ($newval,$newcap);
8306: if ($changes{'internal.selfenroll_cap'} ne '') {
8307: $newcap = $changes{'internal.selfenroll_cap'}
8308: } else {
1.398 raeburn 8309: $newcap = $currsettings->{'selfenroll_cap'};
1.276 raeburn 8310: }
8311: if ($changes{'internal.selfenroll_limit'} eq 'none') {
8312: $newval = &mt('No limit');
8313: } elsif ($changes{'internal.selfenroll_limit'} eq
8314: 'allstudents') {
8315: $newval = &mt('New self-enrollment no longer allowed when total (all students) reaches [_1].',$newcap);
8316: } elsif ($changes{'internal.selfenroll_limit'} eq 'selfenrolled') {
8317: $newval = &mt('New self-enrollment no longer allowed when total number of self-enrolled students reaches [_1].',$newcap);
8318: } else {
1.398 raeburn 8319: my $currlimit = $currsettings->{'selfenroll_limit'};
1.276 raeburn 8320: if ($currlimit eq 'allstudents') {
8321: $newval = &mt('New self-enrollment no longer allowed when total (all students) reaches [_1].',$newcap);
8322: } elsif ($changes{'internal.selfenroll_limit'} eq 'selfenrolled') {
1.308 raeburn 8323: $newval = &mt('New self-enrollment no longer allowed when total number of self-enrolled students reaches [_1].',$newcap);
1.276 raeburn 8324: }
8325: }
8326: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval).'</li>'."\n");
8327: }
8328: } elsif ($item eq 'approval') {
8329: if ((exists($changes{'internal.selfenroll_approval'})) ||
8330: (exists($changes{'internal.selfenroll_notifylist'}))) {
1.398 raeburn 8331: my %selfdescs = &Apache::lonuserutils::selfenroll_default_descs();
1.276 raeburn 8332: my ($newval,$newnotify);
8333: if (exists($changes{'internal.selfenroll_notifylist'})) {
8334: $newnotify = $changes{'internal.selfenroll_notifylist'};
8335: } else {
1.398 raeburn 8336: $newnotify = $currsettings->{'selfenroll_notifylist'};
1.276 raeburn 8337: }
1.398 raeburn 8338: if (exists($changes{'internal.selfenroll_approval'})) {
8339: if ($changes{'internal.selfenroll_approval'} !~ /^[012]$/) {
8340: $changes{'internal.selfenroll_approval'} = '0';
8341: }
8342: $newval = $selfdescs{'approval'}{$changes{'internal.selfenroll_approval'}};
1.276 raeburn 8343: } else {
1.398 raeburn 8344: my $currapproval = $currsettings->{'selfenroll_approval'};
8345: if ($currapproval !~ /^[012]$/) {
8346: $currapproval = 0;
1.276 raeburn 8347: }
1.398 raeburn 8348: $newval = $selfdescs{'approval'}{$currapproval};
1.276 raeburn 8349: }
8350: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval));
8351: if ($newnotify) {
1.277 raeburn 8352: $r->print('<br />'.&mt('The following will be notified when an enrollment request needs approval, or has been approved: [_1].',$newnotify));
1.276 raeburn 8353: } else {
1.277 raeburn 8354: $r->print('<br />'.&mt('No notifications sent when an enrollment request needs approval, or has been approved.'));
1.276 raeburn 8355: }
8356: $r->print('</li>'."\n");
8357: }
1.237 raeburn 8358: } else {
8359: if (exists($changes{'internal.selfenroll_'.$item})) {
1.241 raeburn 8360: my $newval = $changes{'internal.selfenroll_'.$item};
8361: if ($item eq 'types') {
8362: if ($newval eq '') {
8363: $newval = &mt('None');
8364: } elsif ($newval eq '*') {
8365: $newval = &mt('Any user in any domain');
8366: }
1.245 raeburn 8367: } elsif ($item eq 'registered') {
8368: if ($newval eq '1') {
8369: $newval = &mt('Yes');
8370: } elsif ($newval eq '0') {
8371: $newval = &mt('No');
8372: }
1.241 raeburn 8373: }
1.244 bisitz 8374: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval).'</li>'."\n");
1.237 raeburn 8375: }
8376: }
8377: }
8378: $r->print('</ul>');
1.398 raeburn 8379: if ($env{'course.'.$cid.'.description'} ne '') {
8380: my %newenvhash;
8381: foreach my $key (keys(%changes)) {
8382: $newenvhash{'course.'.$cid.'.'.$key} = $changes{$key};
8383: }
8384: &Apache::lonnet::appenv(\%newenvhash);
1.237 raeburn 8385: }
8386: } else {
1.398 raeburn 8387: $r->print(&mt('An error occurred when saving changes to self-enrollment settings in this course.').'<br />'.
8388: &mt('The error was: [_1].',$putresult));
1.237 raeburn 8389: }
8390: } else {
1.249 raeburn 8391: $r->print(&mt('No changes were made to the existing self-enrollment settings in this course.'));
1.237 raeburn 8392: }
8393: } else {
1.249 raeburn 8394: $r->print(&mt('No changes were made to the existing self-enrollment settings in this course.'));
1.241 raeburn 8395: }
1.400 raeburn 8396: my $visactions = &cat_visibility();
8397: my ($cathash,%cattype);
8398: my %domconfig = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom);
8399: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
8400: $cathash = $domconfig{'coursecategories'}{'cats'};
8401: $cattype{'auth'} = $domconfig{'coursecategories'}{'auth'};
8402: $cattype{'unauth'} = $domconfig{'coursecategories'}{'unauth'};
8403: } else {
8404: $cathash = {};
8405: $cattype{'auth'} = 'std';
8406: $cattype{'unauth'} = 'std';
8407: }
8408: if (($cattype{'auth'} eq 'none') && ($cattype{'unauth'} eq 'none')) {
8409: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
8410: '<br />'.
8411: '<br />'.$visactions->{'take'}.'<ul>'.
8412: '<li>'.$visactions->{'dc_chgconf'}.'</li>'.
8413: '</ul>');
8414: } elsif (($cattype{'auth'} !~ /^(std|domonly)$/) && ($cattype{'unauth'} !~ /^(std|domonly)$/)) {
8415: if ($currsettings->{'uniquecode'}) {
8416: $r->print('<span class="LC_info">'.$visactions->{'vis'}.'</span>');
8417: } else {
1.366 bisitz 8418: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
1.400 raeburn 8419: '<br />'.
8420: '<br />'.$visactions->{'take'}.'<ul>'.
8421: '<li>'.$visactions->{'dc_setcode'}.'</li>'.
8422: '</ul><br />');
8423: }
8424: } else {
8425: my ($visible,$cansetvis,$vismsgs) = &visible_in_stdcat($cdom,$cnum,\%domconfig);
8426: if (ref($visactions) eq 'HASH') {
8427: if (!$visible) {
8428: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
8429: '<br />');
8430: if (ref($vismsgs) eq 'ARRAY') {
8431: $r->print('<br />'.$visactions->{'take'}.'<ul>');
8432: foreach my $item (@{$vismsgs}) {
8433: $r->print('<li>'.$visactions->{$item}.'</li>');
8434: }
8435: $r->print('</ul>');
1.256 raeburn 8436: }
1.400 raeburn 8437: $r->print($cansetvis);
1.256 raeburn 8438: }
8439: }
8440: }
1.237 raeburn 8441: return;
8442: }
8443:
1.27 matthew 8444: #---------------------------------------------- end functions for &phase_two
1.29 matthew 8445:
8446: #--------------------------------- functions for &phase_two and &phase_three
8447:
8448: #--------------------------end of functions for &phase_two and &phase_three
1.372 raeburn 8449:
1.1 www 8450: 1;
8451: __END__
1.2 www 8452:
8453:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>