Annotation of loncom/interface/loncreateuser.pm, revision 1.419
1.20 harris41 1: # The LearningOnline Network with CAPA
1.1 www 2: # Create a user
3: #
1.419 ! raeburn 4: # $Id: loncreateuser.pm,v 1.418 2016/11/09 16:35:46 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.329 raeburn 1839: if ($area =~ m{^/($match_domain)/($match_courseid)} ) {
1840: $class='Course';
1841: my ($coursedom,$coursedir) = ($1,$2);
1842: my $cid = $1.'_'.$2;
1843: # $1.'_'.$2 is the course id (eg. 103_12345abcef103l3).
1844: my %coursedata=
1845: &Apache::lonnet::coursedescription($cid);
1846: if ($coursedir =~ /^$match_community$/) {
1847: $class='Community';
1848: }
1849: $sortkey.="\0$coursedom";
1850: my $carea;
1851: if (defined($coursedata{'description'})) {
1852: $carea=$coursedata{'description'}.
1853: '<br />'.&mt('Domain').': '.$coursedom.(' 'x8).
1854: &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$coursedir,$coursedom);
1855: $sortkey.="\0".$coursedata{'description'};
1856: } else {
1857: if ($class eq 'Community') {
1858: $carea=&mt('Unavailable community').': '.$area;
1859: $sortkey.="\0".&mt('Unavailable community').': '.$area;
1.217 raeburn 1860: } else {
1861: $carea=&mt('Unavailable course').': '.$area;
1862: $sortkey.="\0".&mt('Unavailable course').': '.$area;
1863: }
1.329 raeburn 1864: }
1865: $sortkey.="\0$coursedir";
1866: $inccourses->{$cid}=1;
1.375 raeburn 1867: if (($showcredits) && ($class eq 'Course') && ($role_code eq 'st')) {
1868: my $defaultcredits = $coursedata{'internal.defaultcredits'};
1869: $credits =
1870: &get_user_credits($ccuname,$ccdomain,$defaultcredits,
1871: $coursedom,$coursedir);
1872: if ($credits eq '') {
1873: $credits = $defaultcredits;
1874: }
1875: }
1.329 raeburn 1876: if ((&Apache::lonnet::allowed('c'.$role_code,$coursedom.'/'.$coursedir)) ||
1877: (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) {
1878: $allowed=1;
1879: }
1880: unless ($allowed) {
1.365 raeburn 1881: my $isowner = &Apache::lonuserutils::is_courseowner($cid,$coursedata{'internal.courseowner'});
1.329 raeburn 1882: if ($isowner) {
1883: if (($role_code eq 'co') && ($class eq 'Community')) {
1884: $allowed = 1;
1885: } elsif (($role_code eq 'cc') && ($class eq 'Course')) {
1886: $allowed = 1;
1887: }
1.217 raeburn 1888: }
1.329 raeburn 1889: }
1890: if ((&Apache::lonnet::allowed('dro',$coursedom)) ||
1891: (&Apache::lonnet::allowed('dro',$ccdomain))) {
1892: $delallowed=1;
1893: }
1.217 raeburn 1894: # - custom role. Needs more info, too
1.329 raeburn 1895: if ($croletitle) {
1896: if (&Apache::lonnet::allowed('ccr',$coursedom.'/'.$coursedir)) {
1897: $allowed=1;
1898: $thisrole.='.'.$role_code;
1.217 raeburn 1899: }
1.329 raeburn 1900: }
1.418 raeburn 1901: if ($area=~m{^/($match_domain/$match_courseid/(\w+))}) {
1902: $csec = $2;
1903: $carea.='<br />'.&mt('Section: [_1]',$csec);
1904: $sortkey.="\0$csec";
1.329 raeburn 1905: if (!$allowed) {
1.418 raeburn 1906: if ($env{'request.course.sec'} eq $csec) {
1907: if (&Apache::lonnet::allowed('c'.$role_code,$1)) {
1.329 raeburn 1908: $allowed = 1;
1.217 raeburn 1909: }
1910: }
1911: }
1.329 raeburn 1912: }
1913: $area=$carea;
1914: } else {
1915: $sortkey.="\0".$area;
1916: # Determine if current user is able to revoke privileges
1917: if ($area=~m{^/($match_domain)/}) {
1918: if ((&Apache::lonnet::allowed('c'.$role_code,$1)) ||
1919: (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) {
1920: $allowed=1;
1.217 raeburn 1921: }
1.329 raeburn 1922: if (((&Apache::lonnet::allowed('dro',$1)) ||
1923: (&Apache::lonnet::allowed('dro',$ccdomain))) &&
1924: ($role_code ne 'dc')) {
1925: $delallowed=1;
1.217 raeburn 1926: }
1.329 raeburn 1927: } else {
1928: if (&Apache::lonnet::allowed('c'.$role_code,'/')) {
1.217 raeburn 1929: $allowed=1;
1930: }
1931: }
1.363 raeburn 1932: if ($role_code eq 'ca' || $role_code eq 'au' || $role_code eq 'aa') {
1.377 raeburn 1933: $class='Authoring Space';
1.329 raeburn 1934: } elsif ($role_code eq 'su') {
1935: $class='System';
1.217 raeburn 1936: } else {
1.329 raeburn 1937: $class='Domain';
1.217 raeburn 1938: }
1.329 raeburn 1939: }
1940: if (($role_code eq 'ca') || ($role_code eq 'aa')) {
1941: $area=~m{/($match_domain)/($match_username)};
1942: if (&Apache::lonuserutils::authorpriv($2,$1)) {
1943: $allowed=1;
1.217 raeburn 1944: } else {
1.329 raeburn 1945: $allowed=0;
1.217 raeburn 1946: }
1.329 raeburn 1947: }
1948: my $row = '';
1.418 raeburn 1949: if ($showall) {
1950: $row.= '<td>';
1951: if (($active) && ($allowed)) {
1952: $row.= '<input type="checkbox" name="rev:'.$thisrole.'" />';
1953: } else {
1954: if ($active) {
1955: $row.=' ';
1956: } else {
1957: $row.=&mt('expired or revoked');
1958: }
1959: }
1960: $row.='</td><td>';
1961: if ($allowed && !$active) {
1962: $row.= '<input type="checkbox" name="ren:'.$thisrole.'" />';
1963: } else {
1964: $row.=' ';
1965: }
1966: $row.='</td><td>';
1967: if ($delallowed) {
1968: $row.= '<input type="checkbox" name="del:'.$thisrole.'" />';
1.217 raeburn 1969: } else {
1.418 raeburn 1970: $row.=' ';
1.217 raeburn 1971: }
1.418 raeburn 1972: $row.= '</td>';
1.329 raeburn 1973: }
1974: my $plaintext='';
1975: if (!$croletitle) {
1.375 raeburn 1976: $plaintext=&Apache::lonnet::plaintext($role_code,$class);
1977: if (($showcredits) && ($credits ne '')) {
1978: $plaintext .= '<br/ ><span class="LC_nobreak">'.
1979: '<span class="LC_fontsize_small">'.
1980: &mt('Credits: [_1]',$credits).
1981: '</span></span>';
1982: }
1.329 raeburn 1983: } else {
1984: $plaintext=
1.395 bisitz 1985: &mt('Custom role [_1][_2]defined by [_3]',
1.346 bisitz 1986: '"'.$croletitle.'"',
1987: '<br />',
1988: $croleuname.':'.$croleudom);
1.329 raeburn 1989: }
1.418 raeburn 1990: $row.= '<td>'.$plaintext.'</td>'.
1991: '<td>'.$area.'</td>'.
1992: '<td>'.($role_start_time?&Apache::lonlocal::locallocaltime($role_start_time)
1993: : ' ' ).'</td>'.
1994: '<td>'.($role_end_time ?&Apache::lonlocal::locallocaltime($role_end_time)
1995: : ' ' ).'</td>';
1.329 raeburn 1996: $sortrole{$sortkey}=$envkey;
1997: $roletext{$envkey}=$row;
1998: $roleclass{$envkey}=$class;
1.418 raeburn 1999: if ($allowed) {
2000: $rolepriv{$envkey}='edit';
2001: } else {
2002: if ($context eq 'domain') {
2003: if (&Apache::lonnet::allowed('vur',$ccdomain)) {
2004: $rolepriv{$envkey}='view';
2005: }
2006: } elsif ($context eq 'course') {
2007: if ((&Apache::lonnet::allowed('vcl',$env{'request.course.id'})) ||
2008: ($env{'request.course.sec'} && ($env{'request.course.sec'} eq $csec) &&
2009: &Apache::lonnet::allowed('vcl',$env{'request.course.id'}.'/'.$env{'request.course.sec'}))) {
2010: $rolepriv{$envkey}='view';
2011: }
2012: }
2013: }
1.329 raeburn 2014: } # end of foreach (table building loop)
2015:
2016: my $rolesdisplay = 0;
2017: my %output = ();
1.377 raeburn 2018: foreach my $type ('Authoring Space','Course','Community','Domain','System','Unknown') {
1.329 raeburn 2019: $output{$type} = '';
2020: foreach my $which (sort {uc($a) cmp uc($b)} (keys(%sortrole))) {
2021: if ( ($roleclass{$sortrole{$which}} =~ /^\Q$type\E/ ) && ($rolepriv{$sortrole{$which}}) ) {
2022: $output{$type}.=
2023: &Apache::loncommon::start_data_table_row().
2024: $roletext{$sortrole{$which}}.
2025: &Apache::loncommon::end_data_table_row();
1.217 raeburn 2026: }
1.329 raeburn 2027: }
2028: unless($output{$type} eq '') {
2029: $output{$type} = '<tr class="LC_info_row">'.
2030: "<td align='center' colspan='7'>".&mt($type)."</td></tr>".
2031: $output{$type};
2032: $rolesdisplay = 1;
2033: }
2034: }
2035: if ($rolesdisplay == 1) {
2036: my $contextrole='';
2037: if ($env{'request.course.id'}) {
2038: if (&Apache::loncommon::course_type() eq 'Community') {
2039: $contextrole = &mt('Existing Roles in this Community');
1.290 bisitz 2040: } else {
1.329 raeburn 2041: $contextrole = &mt('Existing Roles in this Course');
1.290 bisitz 2042: }
1.329 raeburn 2043: } elsif ($env{'request.role'} =~ /^au\./) {
1.377 raeburn 2044: $contextrole = &mt('Existing Co-Author Roles in your Authoring Space');
1.329 raeburn 2045: } else {
1.418 raeburn 2046: if ($showall) {
2047: $contextrole = &mt('Existing Roles in this Domain');
2048: } elsif ($showactive) {
2049: $contextrole = &mt('Unexpired Roles in this Domain');
2050: } elsif ($showexpired) {
2051: $contextrole = &mt('Expired or Revoked Roles in this Domain');
2052: }
1.329 raeburn 2053: }
1.393 raeburn 2054: $r->print('<div class="LC_left_float">'.
1.375 raeburn 2055: '<fieldset><legend>'.$contextrole.'</legend>'.
1.217 raeburn 2056: &Apache::loncommon::start_data_table("LC_createuser").
1.418 raeburn 2057: &Apache::loncommon::start_data_table_header_row());
2058: if ($showall) {
2059: $r->print(
1.419 ! raeburn 2060: '<th>'.$lt{'rev'}.'</th><th>'.$lt{'ren'}.'</th><th>'.$lt{'del'}.'</th>'
1.418 raeburn 2061: );
2062: } elsif ($showexpired) {
2063: $r->print('<th>'.$lt{'rev'}.'</th>');
2064: }
2065: $r->print(
1.419 ! raeburn 2066: '<th>'.$lt{'rol'}.'</th><th>'.$lt{'ext'}.'</th>'.
! 2067: '<th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'.
1.217 raeburn 2068: &Apache::loncommon::end_data_table_header_row());
1.377 raeburn 2069: foreach my $type ('Authoring Space','Course','Community','Domain','System','Unknown') {
1.329 raeburn 2070: if ($output{$type}) {
2071: $r->print($output{$type}."\n");
1.217 raeburn 2072: }
2073: }
1.375 raeburn 2074: $r->print(&Apache::loncommon::end_data_table().
2075: '</fieldset></div>');
1.329 raeburn 2076: }
1.217 raeburn 2077: return;
2078: }
2079:
1.218 raeburn 2080: sub new_coauthor_roles {
2081: my ($r,$ccuname,$ccdomain) = @_;
2082: my $addrolesdisplay = 0;
2083: #
2084: # Co-Author
2085: #
2086: if (&Apache::lonuserutils::authorpriv($env{'user.name'},
2087: $env{'request.role.domain'}) &&
2088: ($env{'user.name'} ne $ccuname || $env{'user.domain'} ne $ccdomain)) {
2089: # No sense in assigning co-author role to yourself
2090: $addrolesdisplay = 1;
2091: my $cuname=$env{'user.name'};
2092: my $cudom=$env{'request.role.domain'};
2093: my %lt=&Apache::lonlocal::texthash(
1.377 raeburn 2094: 'cs' => "Authoring Space",
1.218 raeburn 2095: 'act' => "Activate",
2096: 'rol' => "Role",
2097: 'ext' => "Extent",
2098: 'sta' => "Start",
2099: 'end' => "End",
2100: 'cau' => "Co-Author",
2101: 'caa' => "Assistant Co-Author",
2102: 'ssd' => "Set Start Date",
2103: 'sed' => "Set End Date"
2104: );
2105: $r->print('<h4>'.$lt{'cs'}.'</h4>'."\n".
2106: &Apache::loncommon::start_data_table()."\n".
2107: &Apache::loncommon::start_data_table_header_row()."\n".
2108: '<th>'.$lt{'act'}.'</th><th>'.$lt{'rol'}.'</th>'.
2109: '<th>'.$lt{'ext'}.'</th><th>'.$lt{'sta'}.'</th>'.
2110: '<th>'.$lt{'end'}.'</th>'."\n".
2111: &Apache::loncommon::end_data_table_header_row()."\n".
2112: &Apache::loncommon::start_data_table_row().'
2113: <td>
1.291 bisitz 2114: <input type="checkbox" name="act_'.$cudom.'_'.$cuname.'_ca" />
1.218 raeburn 2115: </td>
2116: <td>'.$lt{'cau'}.'</td>
2117: <td>'.$cudom.'_'.$cuname.'</td>
2118: <td><input type="hidden" name="start_'.$cudom.'_'.$cuname.'_ca" value="" />
2119: <a href=
2120: "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>
2121: <td><input type="hidden" name="end_'.$cudom.'_'.$cuname.'_ca" value="" />
2122: <a href=
2123: "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".
2124: &Apache::loncommon::end_data_table_row()."\n".
2125: &Apache::loncommon::start_data_table_row()."\n".
1.291 bisitz 2126: '<td><input type="checkbox" name="act_'.$cudom.'_'.$cuname.'_aa" /></td>
1.218 raeburn 2127: <td>'.$lt{'caa'}.'</td>
2128: <td>'.$cudom.'_'.$cuname.'</td>
2129: <td><input type="hidden" name="start_'.$cudom.'_'.$cuname.'_aa" value="" />
2130: <a href=
2131: "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>
2132: <td><input type="hidden" name="end_'.$cudom.'_'.$cuname.'_aa" value="" />
2133: <a href=
2134: "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".
2135: &Apache::loncommon::end_data_table_row()."\n".
2136: &Apache::loncommon::end_data_table());
2137: } elsif ($env{'request.role'} =~ /^au\./) {
2138: if (!(&Apache::lonuserutils::authorpriv($env{'user.name'},
2139: $env{'request.role.domain'}))) {
2140: $r->print('<span class="LC_error">'.
2141: &mt('You do not have privileges to assign co-author roles.').
2142: '</span>');
2143: } elsif (($env{'user.name'} eq $ccuname) &&
2144: ($env{'user.domain'} eq $ccdomain)) {
1.377 raeburn 2145: $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 2146: }
2147: }
2148: return $addrolesdisplay;;
2149: }
2150:
2151: sub new_domain_roles {
1.357 raeburn 2152: my ($r,$ccdomain) = @_;
1.218 raeburn 2153: my $addrolesdisplay = 0;
2154: #
2155: # Domain level
2156: #
2157: my $num_domain_level = 0;
2158: my $domaintext =
2159: '<h4>'.&mt('Domain Level').'</h4>'.
2160: &Apache::loncommon::start_data_table().
2161: &Apache::loncommon::start_data_table_header_row().
2162: '<th>'.&mt('Activate').'</th><th>'.&mt('Role').'</th><th>'.
2163: &mt('Extent').'</th>'.
2164: '<th>'.&mt('Start').'</th><th>'.&mt('End').'</th>'.
2165: &Apache::loncommon::end_data_table_header_row();
1.312 raeburn 2166: my @allroles = &Apache::lonuserutils::roles_by_context('domain');
1.218 raeburn 2167: foreach my $thisdomain (sort(&Apache::lonnet::all_domains())) {
1.312 raeburn 2168: foreach my $role (@allroles) {
2169: next if ($role eq 'ad');
1.357 raeburn 2170: next if (($role eq 'au') && ($ccdomain ne $thisdomain));
1.218 raeburn 2171: if (&Apache::lonnet::allowed('c'.$role,$thisdomain)) {
2172: my $plrole=&Apache::lonnet::plaintext($role);
2173: my %lt=&Apache::lonlocal::texthash(
2174: 'ssd' => "Set Start Date",
2175: 'sed' => "Set End Date"
2176: );
2177: $num_domain_level ++;
2178: $domaintext .=
2179: &Apache::loncommon::start_data_table_row().
1.291 bisitz 2180: '<td><input type="checkbox" name="act_'.$thisdomain.'_'.$role.'" /></td>
1.218 raeburn 2181: <td>'.$plrole.'</td>
2182: <td>'.$thisdomain.'</td>
2183: <td><input type="hidden" name="start_'.$thisdomain.'_'.$role.'" value="" />
2184: <a href=
2185: "javascript:pjump('."'date_start','Start Date $plrole',document.cu.start_$thisdomain\_$role.value,'start_$thisdomain\_$role','cu.pres','dateset'".')">'.$lt{'ssd'}.'</a></td>
2186: <td><input type="hidden" name="end_'.$thisdomain.'_'.$role.'" value="" />
2187: <a href=
2188: "javascript:pjump('."'date_end','End Date $plrole',document.cu.end_$thisdomain\_$role.value,'end_$thisdomain\_$role','cu.pres','dateset'".')">'.$lt{'sed'}.'</a></td>'.
2189: &Apache::loncommon::end_data_table_row();
2190: }
2191: }
2192: }
2193: $domaintext.= &Apache::loncommon::end_data_table();
2194: if ($num_domain_level > 0) {
2195: $r->print($domaintext);
2196: $addrolesdisplay = 1;
2197: }
2198: return $addrolesdisplay;
2199: }
2200:
1.188 raeburn 2201: sub user_authentication {
1.227 raeburn 2202: my ($ccuname,$ccdomain,$formname) = @_;
1.188 raeburn 2203: my $currentauth=&Apache::lonnet::queryauthenticate($ccuname,$ccdomain);
1.227 raeburn 2204: my $outcome;
1.418 raeburn 2205: my %lt=&Apache::lonlocal::texthash(
2206: 'err' => "ERROR",
2207: 'uuas' => "This user has an unrecognized authentication scheme",
2208: 'adcs' => "Please alert a domain coordinator of this situation",
2209: 'sldb' => "Please specify login data below",
2210: 'ld' => "Login Data"
2211: );
1.188 raeburn 2212: # Check for a bad authentication type
2213: if ($currentauth !~ /^(krb4|krb5|unix|internal|localauth):/) {
2214: # bad authentication scheme
2215: if (&Apache::lonnet::allowed('mau',$ccdomain)) {
1.227 raeburn 2216: &initialize_authen_forms($ccdomain,$formname);
2217:
1.190 raeburn 2218: my $choices = &Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc);
1.188 raeburn 2219: $outcome = <<ENDBADAUTH;
2220: <script type="text/javascript" language="Javascript">
1.301 bisitz 2221: // <![CDATA[
1.188 raeburn 2222: $loginscript
1.301 bisitz 2223: // ]]>
1.188 raeburn 2224: </script>
2225: <span class="LC_error">$lt{'err'}:
2226: $lt{'uuas'} ($currentauth). $lt{'sldb'}.</span>
2227: <h3>$lt{'ld'}</h3>
2228: $choices
2229: ENDBADAUTH
2230: } else {
2231: # This user is not allowed to modify the user's
2232: # authentication scheme, so just notify them of the problem
2233: $outcome = <<ENDBADAUTH;
2234: <span class="LC_error"> $lt{'err'}:
2235: $lt{'uuas'} ($currentauth). $lt{'adcs'}.
2236: </span>
2237: ENDBADAUTH
2238: }
2239: } else { # Authentication type is valid
1.418 raeburn 2240:
1.227 raeburn 2241: &initialize_authen_forms($ccdomain,$formname,$currentauth,'modifyuser');
1.205 raeburn 2242: my ($authformcurrent,$can_modify,@authform_others) =
1.188 raeburn 2243: &modify_login_block($ccdomain,$currentauth);
2244: if (&Apache::lonnet::allowed('mau',$ccdomain)) {
2245: # Current user has login modification privileges
2246: $outcome =
2247: '<script type="text/javascript" language="Javascript">'."\n".
1.301 bisitz 2248: '// <![CDATA['."\n".
1.188 raeburn 2249: $loginscript."\n".
1.301 bisitz 2250: '// ]]>'."\n".
1.188 raeburn 2251: '</script>'."\n".
2252: '<h3>'.$lt{'ld'}.'</h3>'.
2253: &Apache::loncommon::start_data_table().
1.205 raeburn 2254: &Apache::loncommon::start_data_table_row().
1.188 raeburn 2255: '<td>'.$authformnop;
1.418 raeburn 2256: if (($can_modify) && (&Apache::lonnet::allowed('mau',$ccdomain))) {
1.188 raeburn 2257: $outcome .= '</td>'."\n".
2258: &Apache::loncommon::end_data_table_row().
2259: &Apache::loncommon::start_data_table_row().
2260: '<td>'.$authformcurrent.'</td>'.
2261: &Apache::loncommon::end_data_table_row()."\n";
2262: } else {
1.200 raeburn 2263: $outcome .= ' ('.$authformcurrent.')</td>'.
2264: &Apache::loncommon::end_data_table_row()."\n";
1.188 raeburn 2265: }
1.418 raeburn 2266: if (&Apache::lonnet::allowed('mau',$ccdomain)) {
2267: foreach my $item (@authform_others) {
2268: $outcome .= &Apache::loncommon::start_data_table_row().
2269: '<td>'.$item.'</td>'.
2270: &Apache::loncommon::end_data_table_row()."\n";
2271: }
1.188 raeburn 2272: }
1.205 raeburn 2273: $outcome .= &Apache::loncommon::end_data_table();
1.188 raeburn 2274: } else {
1.418 raeburn 2275: if (&Apache::lonnet::allowed('udp',$ccdomain)) {
2276: # Current user has rights to view domain preferences for user's domain
2277: my $result;
2278: if ($currentauth =~ /^krb(4|5):([^:]*)$/) {
2279: my ($krbver,$krbrealm) = ($1,$2);
2280: if ($krbrealm eq '') {
2281: $result = &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
2282: } else {
2283: $result = &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
2284: $krbver,$krbrealm);
2285: }
2286: } elsif ($currentauth =~ /^internal:/) {
2287: $result = &mt('Currently internally authenticated.');
2288: } elsif ($currentauth =~ /^localauth:/) {
2289: $result = &mt('Currently using local (institutional) authentication.');
2290: } elsif ($currentauth =~ /^unix:/) {
2291: $result = &mt('Currently Filesystem Authenticated.');
2292: }
2293: $outcome = '<h3>'.$lt{'ld'}.'</h3>'.
2294: &Apache::loncommon::start_data_table().
2295: &Apache::loncommon::start_data_table_row().
2296: '<td>'.$result.'</td>'.
2297: &Apache::loncommon::end_data_table_row()."\n".
2298: &Apache::loncommon::end_data_table();
2299: } elsif (&Apache::lonnet::allowed('mau',$env{'request.role.domain'})) {
1.188 raeburn 2300: my %lt=&Apache::lonlocal::texthash(
2301: 'ccld' => "Change Current Login Data",
2302: 'yodo' => "You do not have privileges to modify the authentication configuration for this user.",
2303: 'ifch' => "If a change is required, contact a domain coordinator for the domain",
2304: );
2305: $outcome .= <<ENDNOPRIV;
2306: <h3>$lt{'ccld'}</h3>
2307: $lt{'yodo'} $lt{'ifch'}: $ccdomain
1.235 raeburn 2308: <input type="hidden" name="login" value="nochange" />
1.188 raeburn 2309: ENDNOPRIV
2310: }
2311: }
2312: } ## End of "check for bad authentication type" logic
2313: return $outcome;
2314: }
2315:
1.187 raeburn 2316: sub modify_login_block {
2317: my ($dom,$currentauth) = @_;
2318: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
2319: my ($authnum,%can_assign) =
2320: &Apache::loncommon::get_assignable_auth($dom);
1.205 raeburn 2321: my ($authformcurrent,@authform_others,$show_override_msg);
1.187 raeburn 2322: if ($currentauth=~/^krb(4|5):/) {
2323: $authformcurrent=$authformkrb;
2324: if ($can_assign{'int'}) {
1.205 raeburn 2325: push(@authform_others,$authformint);
1.187 raeburn 2326: }
2327: if ($can_assign{'loc'}) {
1.205 raeburn 2328: push(@authform_others,$authformloc);
1.187 raeburn 2329: }
2330: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
2331: $show_override_msg = 1;
2332: }
2333: } elsif ($currentauth=~/^internal:/) {
2334: $authformcurrent=$authformint;
2335: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205 raeburn 2336: push(@authform_others,$authformkrb);
1.187 raeburn 2337: }
2338: if ($can_assign{'loc'}) {
1.205 raeburn 2339: push(@authform_others,$authformloc);
1.187 raeburn 2340: }
2341: if ($can_assign{'int'}) {
2342: $show_override_msg = 1;
2343: }
2344: } elsif ($currentauth=~/^unix:/) {
2345: $authformcurrent=$authformfsys;
2346: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205 raeburn 2347: push(@authform_others,$authformkrb);
1.187 raeburn 2348: }
2349: if ($can_assign{'int'}) {
1.205 raeburn 2350: push(@authform_others,$authformint);
1.187 raeburn 2351: }
2352: if ($can_assign{'loc'}) {
1.205 raeburn 2353: push(@authform_others,$authformloc);
1.187 raeburn 2354: }
2355: if ($can_assign{'fsys'}) {
2356: $show_override_msg = 1;
2357: }
2358: } elsif ($currentauth=~/^localauth:/) {
2359: $authformcurrent=$authformloc;
2360: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205 raeburn 2361: push(@authform_others,$authformkrb);
1.187 raeburn 2362: }
2363: if ($can_assign{'int'}) {
1.205 raeburn 2364: push(@authform_others,$authformint);
1.187 raeburn 2365: }
2366: if ($can_assign{'loc'}) {
2367: $show_override_msg = 1;
2368: }
2369: }
2370: if ($show_override_msg) {
1.205 raeburn 2371: $authformcurrent = '<table><tr><td colspan="3">'.$authformcurrent.
2372: '</td></tr>'."\n".
2373: '<tr><td> </td>'.
2374: '<td><b>'.&mt('Currently in use').'</b></td>'.
2375: '<td align="right"><span class="LC_cusr_emph">'.
1.187 raeburn 2376: &mt('will override current values').
1.205 raeburn 2377: '</span></td></tr></table>';
1.187 raeburn 2378: }
1.205 raeburn 2379: return ($authformcurrent,$show_override_msg,@authform_others);
1.187 raeburn 2380: }
2381:
1.188 raeburn 2382: sub personal_data_display {
1.391 raeburn 2383: my ($ccuname,$ccdomain,$newuser,$context,$inst_results,$rolesarray,
1.410 raeburn 2384: $now,$captchaform,$emailusername,$usertype) = @_;
1.388 bisitz 2385: my ($output,%userenv,%canmodify,%canmodify_status);
1.219 raeburn 2386: my @userinfo = ('firstname','middlename','lastname','generation',
2387: 'permanentemail','id');
1.252 raeburn 2388: my $rowcount = 0;
2389: my $editable = 0;
1.391 raeburn 2390: my %textboxsize = (
2391: firstname => '15',
2392: middlename => '15',
2393: lastname => '15',
2394: generation => '5',
2395: permanentemail => '25',
2396: id => '15',
2397: );
2398:
2399: my %lt=&Apache::lonlocal::texthash(
2400: 'pd' => "Personal Data",
2401: 'firstname' => "First Name",
2402: 'middlename' => "Middle Name",
2403: 'lastname' => "Last Name",
2404: 'generation' => "Generation",
2405: 'permanentemail' => "Permanent e-mail address",
2406: 'id' => "Student/Employee ID",
2407: 'lg' => "Login Data",
2408: 'inststatus' => "Affiliation",
2409: 'email' => 'E-mail address',
2410: 'valid' => 'Validation',
2411: );
2412:
2413: %canmodify_status =
1.286 raeburn 2414: &Apache::lonuserutils::can_modify_userinfo($context,$ccdomain,
2415: ['inststatus'],$rolesarray);
1.253 raeburn 2416: if (!$newuser) {
1.188 raeburn 2417: # Get the users information
2418: %userenv = &Apache::lonnet::get('environment',
2419: ['firstname','middlename','lastname','generation',
1.286 raeburn 2420: 'permanentemail','id','inststatus'],$ccdomain,$ccuname);
1.219 raeburn 2421: %canmodify =
2422: &Apache::lonuserutils::can_modify_userinfo($context,$ccdomain,
1.252 raeburn 2423: \@userinfo,$rolesarray);
1.257 raeburn 2424: } elsif ($context eq 'selfcreate') {
1.391 raeburn 2425: if ($newuser eq 'email') {
1.396 raeburn 2426: if (ref($emailusername) eq 'HASH') {
2427: if (ref($emailusername->{$usertype}) eq 'HASH') {
2428: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
2429: @userinfo = ();
2430: if ((ref($infofields) eq 'ARRAY') && (ref($infotitles) eq 'HASH')) {
2431: foreach my $field (@{$infofields}) {
2432: if ($emailusername->{$usertype}->{$field}) {
2433: push(@userinfo,$field);
2434: $canmodify{$field} = 1;
2435: unless ($textboxsize{$field}) {
2436: $textboxsize{$field} = 25;
2437: }
2438: unless ($lt{$field}) {
2439: $lt{$field} = $infotitles->{$field};
2440: }
2441: if ($emailusername->{$usertype}->{$field} eq 'required') {
2442: $lt{$field} .= '<b>*</b>';
2443: }
1.391 raeburn 2444: }
2445: }
2446: }
2447: }
2448: }
2449: } else {
2450: %canmodify = &selfcreate_canmodify($context,$ccdomain,\@userinfo,
2451: $inst_results,$rolesarray);
2452: }
1.188 raeburn 2453: }
1.391 raeburn 2454:
1.188 raeburn 2455: my $genhelp=&Apache::loncommon::help_open_topic('Generation');
2456: $output = '<h3>'.$lt{'pd'}.'</h3>'.
2457: &Apache::lonhtmlcommon::start_pick_box();
1.391 raeburn 2458: if (($context eq 'selfcreate') && ($newuser eq 'email')) {
1.396 raeburn 2459: $output .= &Apache::lonhtmlcommon::row_title($lt{'email'}.'<b>*</b>',undef,
1.391 raeburn 2460: 'LC_oddrow_value')."\n".
1.394 raeburn 2461: '<input type="text" name="uname" size="25" value="" autocomplete="off" />';
1.391 raeburn 2462: $rowcount ++;
2463: $output .= &Apache::lonhtmlcommon::row_closure(1);
1.408 raeburn 2464: my $upassone = '<input type="password" name="upass'.$now.'" size="20" autocomplete="off" />';
2465: my $upasstwo = '<input type="password" name="upasscheck'.$now.'" size="20" autocomplete="off" />';
1.396 raeburn 2466: $output .= &Apache::lonhtmlcommon::row_title(&mt('Password').'<b>*</b>',
1.391 raeburn 2467: 'LC_pick_box_title',
2468: 'LC_oddrow_value')."\n".
2469: $upassone."\n".
2470: &Apache::lonhtmlcommon::row_closure(1)."\n".
1.396 raeburn 2471: &Apache::lonhtmlcommon::row_title(&mt('Confirm password').'<b>*</b>',
1.391 raeburn 2472: 'LC_pick_box_title',
2473: 'LC_oddrow_value')."\n".
2474: $upasstwo.
2475: &Apache::lonhtmlcommon::row_closure()."\n";
2476: }
1.188 raeburn 2477: foreach my $item (@userinfo) {
2478: my $rowtitle = $lt{$item};
1.252 raeburn 2479: my $hiderow = 0;
1.188 raeburn 2480: if ($item eq 'generation') {
2481: $rowtitle = $genhelp.$rowtitle;
2482: }
1.252 raeburn 2483: my $row = &Apache::lonhtmlcommon::row_title($rowtitle,undef,'LC_oddrow_value')."\n";
1.188 raeburn 2484: if ($newuser) {
1.210 raeburn 2485: if (ref($inst_results) eq 'HASH') {
2486: if ($inst_results->{$item} ne '') {
1.252 raeburn 2487: $row .= '<input type="hidden" name="c'.$item.'" value="'.$inst_results->{$item}.'" />'.$inst_results->{$item};
1.210 raeburn 2488: } else {
1.252 raeburn 2489: if ($context eq 'selfcreate') {
1.391 raeburn 2490: if ($canmodify{$item}) {
1.394 raeburn 2491: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" autocomplete="off" />';
1.252 raeburn 2492: $editable ++;
2493: } else {
2494: $hiderow = 1;
2495: }
1.253 raeburn 2496: } else {
2497: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
1.252 raeburn 2498: }
1.210 raeburn 2499: }
1.188 raeburn 2500: } else {
1.252 raeburn 2501: if ($context eq 'selfcreate') {
1.401 raeburn 2502: if ($canmodify{$item}) {
2503: if ($newuser eq 'email') {
2504: $row .= '<input type="text" name="'.$item.'" size="'.$textboxsize{$item}.'" value="" autocomplete="off" />';
1.287 raeburn 2505: } else {
1.401 raeburn 2506: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" autocomplete="off" />';
1.287 raeburn 2507: }
1.401 raeburn 2508: $editable ++;
2509: } else {
2510: $hiderow = 1;
1.252 raeburn 2511: }
1.253 raeburn 2512: } else {
2513: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
1.252 raeburn 2514: }
1.188 raeburn 2515: }
2516: } else {
1.219 raeburn 2517: if ($canmodify{$item}) {
1.252 raeburn 2518: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="'.$userenv{$item}.'" />';
1.393 raeburn 2519: if (($item eq 'id') && (!$newuser)) {
2520: $row .= '<br />'.&Apache::lonuserutils::forceid_change($context);
2521: }
1.188 raeburn 2522: } else {
1.252 raeburn 2523: $row .= $userenv{$item};
1.188 raeburn 2524: }
2525: }
1.252 raeburn 2526: $row .= &Apache::lonhtmlcommon::row_closure(1);
2527: if (!$hiderow) {
2528: $output .= $row;
2529: $rowcount ++;
2530: }
1.188 raeburn 2531: }
1.286 raeburn 2532: if (($canmodify_status{'inststatus'}) || ($context ne 'selfcreate')) {
2533: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($ccdomain);
2534: if (ref($types) eq 'ARRAY') {
2535: if (@{$types} > 0) {
2536: my ($hiderow,$shown);
2537: if ($canmodify_status{'inststatus'}) {
2538: $shown = &pick_inst_statuses($userenv{'inststatus'},$usertypes,$types);
2539: } else {
2540: if ($userenv{'inststatus'} eq '') {
2541: $hiderow = 1;
1.334 raeburn 2542: } else {
2543: my @showitems;
2544: foreach my $item ( map { &unescape($_); } split(':',$userenv{'inststatus'})) {
2545: if (exists($usertypes->{$item})) {
2546: push(@showitems,$usertypes->{$item});
2547: } else {
2548: push(@showitems,$item);
2549: }
2550: }
2551: if (@showitems) {
2552: $shown = join(', ',@showitems);
2553: } else {
2554: $hiderow = 1;
2555: }
1.286 raeburn 2556: }
2557: }
2558: if (!$hiderow) {
1.389 bisitz 2559: my $row = &Apache::lonhtmlcommon::row_title(&mt('Affiliations'),undef,'LC_oddrow_value')."\n".
1.286 raeburn 2560: $shown.&Apache::lonhtmlcommon::row_closure(1);
2561: if ($context eq 'selfcreate') {
2562: $rowcount ++;
2563: }
2564: $output .= $row;
2565: }
2566: }
2567: }
2568: }
1.391 raeburn 2569: if (($context eq 'selfcreate') && ($newuser eq 'email')) {
2570: if ($captchaform) {
1.410 raeburn 2571: $output .= &Apache::lonhtmlcommon::row_title($lt{'valid'}.'*',
2572: 'LC_pick_box_title')."\n".
2573: $captchaform."\n".'<br /><br />'.
1.391 raeburn 2574: &Apache::lonhtmlcommon::row_closure(1);
2575: $rowcount ++;
2576: }
2577: my $submit_text = &mt('Create account');
2578: $output .= &Apache::lonhtmlcommon::row_title()."\n".
2579: '<br /><input type="submit" name="createaccount" value="'.
2580: $submit_text.'" />'.
1.396 raeburn 2581: '<input type="hidden" name="type" value="'.$usertype.'" />'.
1.391 raeburn 2582: &Apache::lonhtmlcommon::row_closure(1);
2583: }
1.188 raeburn 2584: $output .= &Apache::lonhtmlcommon::end_pick_box();
1.206 raeburn 2585: if (wantarray) {
1.252 raeburn 2586: if ($context eq 'selfcreate') {
2587: return($output,$rowcount,$editable);
2588: } else {
1.388 bisitz 2589: return $output;
1.252 raeburn 2590: }
1.206 raeburn 2591: } else {
2592: return $output;
2593: }
1.188 raeburn 2594: }
2595:
1.286 raeburn 2596: sub pick_inst_statuses {
2597: my ($curr,$usertypes,$types) = @_;
2598: my ($output,$rem,@currtypes);
2599: if ($curr ne '') {
2600: @currtypes = map { &unescape($_); } split(/:/,$curr);
2601: }
2602: my $numinrow = 2;
2603: if (ref($types) eq 'ARRAY') {
2604: $output = '<table>';
2605: my $lastcolspan;
2606: for (my $i=0; $i<@{$types}; $i++) {
2607: if (defined($usertypes->{$types->[$i]})) {
2608: my $rem = $i%($numinrow);
2609: if ($rem == 0) {
2610: if ($i<@{$types}-1) {
2611: if ($i > 0) {
2612: $output .= '</tr>';
2613: }
2614: $output .= '<tr>';
2615: }
2616: } elsif ($i==@{$types}-1) {
2617: my $colsleft = $numinrow - $rem;
2618: if ($colsleft > 1) {
2619: $lastcolspan = ' colspan="'.$colsleft.'"';
2620: }
2621: }
2622: my $check = ' ';
2623: if (grep(/^\Q$types->[$i]\E$/,@currtypes)) {
2624: $check = ' checked="checked" ';
2625: }
2626: $output .= '<td class="LC_left_item"'.$lastcolspan.'>'.
2627: '<span class="LC_nobreak"><label>'.
2628: '<input type="checkbox" name="inststatus" '.
2629: 'value="'.$types->[$i].'"'.$check.'/>'.
2630: $usertypes->{$types->[$i]}.'</label></span></td>';
2631: }
2632: }
2633: $output .= '</tr></table>';
2634: }
2635: return $output;
2636: }
2637:
1.257 raeburn 2638: sub selfcreate_canmodify {
2639: my ($context,$dom,$userinfo,$inst_results,$rolesarray) = @_;
2640: if (ref($inst_results) eq 'HASH') {
2641: my @inststatuses = &get_inststatuses($inst_results);
2642: if (@inststatuses == 0) {
2643: @inststatuses = ('default');
2644: }
2645: $rolesarray = \@inststatuses;
2646: }
2647: my %canmodify =
2648: &Apache::lonuserutils::can_modify_userinfo($context,$dom,$userinfo,
2649: $rolesarray);
2650: return %canmodify;
2651: }
2652:
1.252 raeburn 2653: sub get_inststatuses {
2654: my ($insthashref) = @_;
2655: my @inststatuses = ();
2656: if (ref($insthashref) eq 'HASH') {
2657: if (ref($insthashref->{'inststatus'}) eq 'ARRAY') {
2658: @inststatuses = @{$insthashref->{'inststatus'}};
2659: }
2660: }
2661: return @inststatuses;
2662: }
2663:
1.4 www 2664: # ================================================================= Phase Three
1.42 matthew 2665: sub update_user_data {
1.375 raeburn 2666: my ($r,$context,$crstype,$brcrum,$showcredits) = @_;
1.101 albertel 2667: my $uhome=&Apache::lonnet::homeserver($env{'form.ccuname'},
2668: $env{'form.ccdomain'});
1.27 matthew 2669: # Error messages
1.188 raeburn 2670: my $error = '<span class="LC_error">'.&mt('Error').': ';
1.193 raeburn 2671: my $end = '</span><br /><br />';
2672: my $rtnlink = '<a href="javascript:backPage(document.userupdate,'.
1.188 raeburn 2673: "'$env{'form.prevphase'}','modify')".'" />'.
1.219 raeburn 2674: &mt('Return to previous page').'</a>'.
2675: &Apache::loncommon::end_page();
2676: my $now = time;
1.40 www 2677: my $title;
1.101 albertel 2678: if (exists($env{'form.makeuser'})) {
1.40 www 2679: $title='Set Privileges for New User';
2680: } else {
2681: $title='Modify User Privileges';
2682: }
1.213 raeburn 2683: my $newuser = 0;
1.160 raeburn 2684: my ($jsback,$elements) = &crumb_utilities();
2685: my $jscript = '<script type="text/javascript">'."\n".
1.301 bisitz 2686: '// <![CDATA['."\n".
2687: $jsback."\n".
2688: '// ]]>'."\n".
2689: '</script>'."\n";
1.318 raeburn 2690: my %breadcrumb_text = &singleuser_breadcrumb($crstype);
1.351 raeburn 2691: push (@{$brcrum},
2692: {href => "javascript:backPage(document.userupdate)",
2693: text => $breadcrumb_text{'search'},
2694: faq => 282,
2695: bug => 'Instructor Interface',}
2696: );
2697: if ($env{'form.prevphase'} eq 'userpicked') {
2698: push(@{$brcrum},
2699: {href => "javascript:backPage(document.userupdate,'get_user_info','select')",
2700: text => $breadcrumb_text{'userpicked'},
2701: faq => 282,
2702: bug => 'Instructor Interface',});
1.233 raeburn 2703: }
1.224 raeburn 2704: my $helpitem = 'Course_Change_Privileges';
2705: if ($env{'form.action'} eq 'singlestudent') {
2706: $helpitem = 'Course_Add_Student';
2707: }
1.351 raeburn 2708: push(@{$brcrum},
2709: {href => "javascript:backPage(document.userupdate,'$env{'form.prevphase'}','modify')",
2710: text => $breadcrumb_text{'modify'},
2711: faq => 282,
2712: bug => 'Instructor Interface',},
2713: {href => "/adm/createuser",
2714: text => "Result",
2715: faq => 282,
2716: bug => 'Instructor Interface',
2717: help => $helpitem});
2718: my $args = {bread_crumbs => $brcrum,
2719: bread_crumbs_component => 'User Management'};
2720: if ($env{'form.popup'}) {
2721: $args->{'no_nav_bar'} = 1;
2722: }
2723: $r->print(&Apache::loncommon::start_page($title,$jscript,$args));
1.188 raeburn 2724: $r->print(&update_result_form($uhome));
1.27 matthew 2725: # Check Inputs
1.101 albertel 2726: if (! $env{'form.ccuname'} ) {
1.193 raeburn 2727: $r->print($error.&mt('No login name specified').'.'.$end.$rtnlink);
1.27 matthew 2728: return;
2729: }
1.138 albertel 2730: if ( $env{'form.ccuname'} ne
2731: &LONCAPA::clean_username($env{'form.ccuname'}) ) {
1.281 bisitz 2732: $r->print($error.&mt('Invalid login name.').' '.
2733: &mt('Only letters, numbers, periods, dashes, @, and underscores are valid.').
1.193 raeburn 2734: $end.$rtnlink);
1.27 matthew 2735: return;
2736: }
1.101 albertel 2737: if (! $env{'form.ccdomain'} ) {
1.193 raeburn 2738: $r->print($error.&mt('No domain specified').'.'.$end.$rtnlink);
1.27 matthew 2739: return;
2740: }
1.138 albertel 2741: if ( $env{'form.ccdomain'} ne
2742: &LONCAPA::clean_domain($env{'form.ccdomain'}) ) {
1.281 bisitz 2743: $r->print($error.&mt('Invalid domain name.').' '.
2744: &mt('Only letters, numbers, periods, dashes, and underscores are valid.').
1.193 raeburn 2745: $end.$rtnlink);
1.27 matthew 2746: return;
2747: }
1.219 raeburn 2748: if ($uhome eq 'no_host') {
2749: $newuser = 1;
2750: }
1.101 albertel 2751: if (! exists($env{'form.makeuser'})) {
1.29 matthew 2752: # Modifying an existing user, so check the validity of the name
2753: if ($uhome eq 'no_host') {
1.389 bisitz 2754: $r->print(
2755: $error
2756: .'<p class="LC_error">'
2757: .&mt('Unable to determine home server for [_1] in domain [_2].',
2758: '"'.$env{'form.ccuname'}.'"','"'.$env{'form.ccdomain'}.'"')
2759: .'</p>');
1.29 matthew 2760: return;
2761: }
2762: }
1.27 matthew 2763: # Determine authentication method and password for the user being modified
2764: my $amode='';
2765: my $genpwd='';
1.101 albertel 2766: if ($env{'form.login'} eq 'krb') {
1.41 albertel 2767: $amode='krb';
1.101 albertel 2768: $amode.=$env{'form.krbver'};
2769: $genpwd=$env{'form.krbarg'};
2770: } elsif ($env{'form.login'} eq 'int') {
1.27 matthew 2771: $amode='internal';
1.101 albertel 2772: $genpwd=$env{'form.intarg'};
2773: } elsif ($env{'form.login'} eq 'fsys') {
1.27 matthew 2774: $amode='unix';
1.101 albertel 2775: $genpwd=$env{'form.fsysarg'};
2776: } elsif ($env{'form.login'} eq 'loc') {
1.27 matthew 2777: $amode='localauth';
1.101 albertel 2778: $genpwd=$env{'form.locarg'};
1.27 matthew 2779: $genpwd=" " if (!$genpwd);
1.101 albertel 2780: } elsif (($env{'form.login'} eq 'nochange') ||
2781: ($env{'form.login'} eq '' )) {
1.34 matthew 2782: # There is no need to tell the user we did not change what they
2783: # did not ask us to change.
1.35 matthew 2784: # If they are creating a new user but have not specified login
2785: # information this will be caught below.
1.30 matthew 2786: } else {
1.367 golterma 2787: $r->print($error.&mt('Invalid login mode or password').$end.$rtnlink);
2788: return;
1.27 matthew 2789: }
1.164 albertel 2790:
1.188 raeburn 2791: $r->print('<h3>'.&mt('User [_1] in domain [_2]',
1.367 golterma 2792: $env{'form.ccuname'}.' ('.&Apache::loncommon::plainname($env{'form.ccuname'},
2793: $env{'form.ccdomain'}).')', $env{'form.ccdomain'}).'</h3>');
2794: my %prog_state = &Apache::lonhtmlcommon::Create_PrgWin($r,2);
1.344 bisitz 2795:
1.193 raeburn 2796: my (%alerts,%rulematch,%inst_results,%curr_rules);
1.334 raeburn 2797: my @userinfo = ('firstname','middlename','lastname','generation','permanentemail','id');
1.361 raeburn 2798: my @usertools = ('aboutme','blog','webdav','portfolio');
1.411 raeburn 2799: my @requestcourses = ('official','unofficial','community','textbook','placement');
1.362 raeburn 2800: my @requestauthor = ('requestauthor');
1.286 raeburn 2801: my ($othertitle,$usertypes,$types) =
2802: &Apache::loncommon::sorted_inst_types($env{'form.ccdomain'});
1.334 raeburn 2803: my %canmodify_status =
2804: &Apache::lonuserutils::can_modify_userinfo($context,$env{'form.ccdomain'},
2805: ['inststatus']);
1.101 albertel 2806: if ($env{'form.makeuser'}) {
1.164 albertel 2807: $r->print('<h3>'.&mt('Creating new account.').'</h3>');
1.27 matthew 2808: # Check for the authentication mode and password
2809: if (! $amode || ! $genpwd) {
1.193 raeburn 2810: $r->print($error.&mt('Invalid login mode or password').$end.$rtnlink);
1.27 matthew 2811: return;
1.18 albertel 2812: }
1.29 matthew 2813: # Determine desired host
1.101 albertel 2814: my $desiredhost = $env{'form.hserver'};
1.29 matthew 2815: if (lc($desiredhost) eq 'default') {
2816: $desiredhost = undef;
2817: } else {
1.147 albertel 2818: my %home_servers =
2819: &Apache::lonnet::get_servers($env{'form.ccdomain'},'library');
1.29 matthew 2820: if (! exists($home_servers{$desiredhost})) {
1.193 raeburn 2821: $r->print($error.&mt('Invalid home server specified').$end.$rtnlink);
2822: return;
2823: }
2824: }
2825: # Check ID format
2826: my %checkhash;
2827: my %checks = ('id' => 1);
2828: %{$checkhash{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}}} = (
1.219 raeburn 2829: 'newuser' => $newuser,
1.196 raeburn 2830: 'id' => $env{'form.cid'},
1.193 raeburn 2831: );
1.196 raeburn 2832: if ($env{'form.cid'} ne '') {
2833: &Apache::loncommon::user_rule_check(\%checkhash,\%checks,\%alerts,
2834: \%rulematch,\%inst_results,\%curr_rules);
2835: if (ref($alerts{'id'}) eq 'HASH') {
2836: if (ref($alerts{'id'}{$env{'form.ccdomain'}}) eq 'HASH') {
2837: my $domdesc =
2838: &Apache::lonnet::domain($env{'form.ccdomain'},'description');
2839: if ($alerts{'id'}{$env{'form.ccdomain'}}{$env{'form.cid'}}) {
2840: my $userchkmsg;
2841: if (ref($curr_rules{$env{'form.ccdomain'}}) eq 'HASH') {
2842: $userchkmsg =
2843: &Apache::loncommon::instrule_disallow_msg('id',
2844: $domdesc,1).
2845: &Apache::loncommon::user_rule_formats($env{'form.ccdomain'},
2846: $domdesc,$curr_rules{$env{'form.ccdomain'}}{'id'},'id');
2847: }
2848: $r->print($error.&mt('Invalid ID format').$end.
2849: $userchkmsg.$rtnlink);
2850: return;
2851: }
2852: }
1.29 matthew 2853: }
2854: }
1.367 golterma 2855: &Apache::lonhtmlcommon::Increment_PrgWin($r, \%prog_state);
1.27 matthew 2856: # Call modifyuser
2857: my $result = &Apache::lonnet::modifyuser
1.193 raeburn 2858: ($env{'form.ccdomain'},$env{'form.ccuname'},$env{'form.cid'},
1.188 raeburn 2859: $amode,$genpwd,$env{'form.cfirstname'},
2860: $env{'form.cmiddlename'},$env{'form.clastname'},
2861: $env{'form.cgeneration'},undef,$desiredhost,
2862: $env{'form.cpermanentemail'});
1.77 www 2863: $r->print(&mt('Generating user').': '.$result);
1.219 raeburn 2864: $uhome = &Apache::lonnet::homeserver($env{'form.ccuname'},
1.101 albertel 2865: $env{'form.ccdomain'});
1.334 raeburn 2866: my (%changeHash,%newcustom,%changed,%changedinfo);
1.267 raeburn 2867: if ($uhome ne 'no_host') {
1.334 raeburn 2868: if ($context eq 'domain') {
1.378 raeburn 2869: foreach my $name ('portfolio','author') {
2870: if ($env{'form.custom_'.$name.'quota'} == 1) {
2871: if ($env{'form.'.$name.'quota'} eq '') {
2872: $newcustom{$name.'quota'} = 0;
2873: } else {
2874: $newcustom{$name.'quota'} = $env{'form.'.$name.'quota'};
2875: $newcustom{$name.'quota'} =~ s/[^\d\.]//g;
2876: }
2877: if ("a_admin($newcustom{$name.'quota'},\%changeHash,$name)) {
2878: $changed{$name.'quota'} = 1;
2879: }
1.334 raeburn 2880: }
2881: }
2882: foreach my $item (@usertools) {
2883: if ($env{'form.custom'.$item} == 1) {
2884: $newcustom{$item} = $env{'form.tools_'.$item};
2885: $changed{$item} = &tool_admin($item,$newcustom{$item},
2886: \%changeHash,'tools');
2887: }
1.267 raeburn 2888: }
1.334 raeburn 2889: foreach my $item (@requestcourses) {
1.341 raeburn 2890: if ($env{'form.custom'.$item} == 1) {
2891: $newcustom{$item} = $env{'form.crsreq_'.$item};
2892: if ($env{'form.crsreq_'.$item} eq 'autolimit') {
2893: $newcustom{$item} .= '=';
1.383 raeburn 2894: $env{'form.crsreq_'.$item.'_limit'} =~ s/\D+//g;
2895: if ($env{'form.crsreq_'.$item.'_limit'}) {
1.341 raeburn 2896: $newcustom{$item} .= $env{'form.crsreq_'.$item.'_limit'};
2897: }
1.334 raeburn 2898: }
1.341 raeburn 2899: $changed{$item} = &tool_admin($item,$newcustom{$item},
2900: \%changeHash,'requestcourses');
1.334 raeburn 2901: }
1.275 raeburn 2902: }
1.362 raeburn 2903: if ($env{'form.customrequestauthor'} == 1) {
2904: $newcustom{'requestauthor'} = $env{'form.requestauthor'};
2905: $changed{'requestauthor'} = &tool_admin('requestauthor',
2906: $newcustom{'requestauthor'},
2907: \%changeHash,'requestauthor');
2908: }
1.414 raeburn 2909: if (&Apache::lonnet::allowed('cdh',$env{'request.role.domain'})) {
2910: my @adds = &Apache::loncommon::get_env_multiple('form.adhocroleadd');
2911: if (&adhocrole_changes(\%changeHash)) {
2912: $changed{'adhocroles.'.$env{'request.role.domain'}} = $changeHash{'adhocroles.'.$env{'request.role.domain'}};
1.417 raeburn 2913: }
1.414 raeburn 2914: }
1.275 raeburn 2915: }
1.334 raeburn 2916: if ($canmodify_status{'inststatus'}) {
2917: if (exists($env{'form.inststatus'})) {
2918: my @inststatuses = &Apache::loncommon::get_env_multiple('form.inststatus');
2919: if (@inststatuses > 0) {
2920: $changeHash{'inststatus'} = join(',',@inststatuses);
2921: $changed{'inststatus'} = $changeHash{'inststatus'};
1.306 raeburn 2922: }
2923: }
1.232 raeburn 2924: }
1.334 raeburn 2925: if (keys(%changed)) {
2926: foreach my $item (@userinfo) {
2927: $changeHash{$item} = $env{'form.c'.$item};
1.286 raeburn 2928: }
1.267 raeburn 2929: my $chgresult =
2930: &Apache::lonnet::put('environment',\%changeHash,
2931: $env{'form.ccdomain'},$env{'form.ccuname'});
2932: }
1.232 raeburn 2933: }
1.219 raeburn 2934: $r->print('<br />'.&mt('Home server').': '.$uhome.' '.
2935: &Apache::lonnet::hostname($uhome));
1.101 albertel 2936: } elsif (($env{'form.login'} ne 'nochange') &&
2937: ($env{'form.login'} ne '' )) {
1.27 matthew 2938: # Modify user privileges
2939: if (! $amode || ! $genpwd) {
1.193 raeburn 2940: $r->print($error.'Invalid login mode or password'.$end.$rtnlink);
1.27 matthew 2941: return;
1.20 harris41 2942: }
1.395 bisitz 2943: # Only allow authentication modification if the person has authority
1.101 albertel 2944: if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'})) {
1.20 harris41 2945: $r->print('Modifying authentication: '.
1.31 matthew 2946: &Apache::lonnet::modifyuserauth(
1.101 albertel 2947: $env{'form.ccdomain'},$env{'form.ccuname'},
1.21 harris41 2948: $amode,$genpwd));
1.102 albertel 2949: $r->print('<br />'.&mt('Home server').': '.&Apache::lonnet::homeserver
1.101 albertel 2950: ($env{'form.ccuname'},$env{'form.ccdomain'}));
1.4 www 2951: } else {
1.27 matthew 2952: # Okay, this is a non-fatal error.
1.395 bisitz 2953: $r->print($error.&mt('You do not have the authority to modify this users authentication information.').$end);
1.27 matthew 2954: }
1.28 matthew 2955: }
1.344 bisitz 2956: $r->rflush(); # Finish display of header before time consuming actions start
1.367 golterma 2957: &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state);
1.28 matthew 2958: ##
1.375 raeburn 2959: my (@userroles,%userupdate,$cnum,$cdom,$defaultcredits,%namechanged);
1.213 raeburn 2960: if ($context eq 'course') {
1.375 raeburn 2961: ($cnum,$cdom) =
2962: &Apache::lonuserutils::get_course_identity();
1.318 raeburn 2963: $crstype = &Apache::loncommon::course_type($cdom.'_'.$cnum);
1.375 raeburn 2964: if ($showcredits) {
2965: $defaultcredits = &Apache::lonuserutils::get_defaultcredits($cdom,$cnum);
2966: }
1.213 raeburn 2967: }
1.101 albertel 2968: if (! $env{'form.makeuser'} ) {
1.28 matthew 2969: # Check for need to change
2970: my %userenv = &Apache::lonnet::get
1.134 raeburn 2971: ('environment',['firstname','middlename','lastname','generation',
1.378 raeburn 2972: 'id','permanentemail','portfolioquota','authorquota','inststatus',
2973: 'tools.aboutme','tools.blog','tools.webdav','tools.portfolio',
1.361 raeburn 2974: 'requestcourses.official','requestcourses.unofficial',
1.384 raeburn 2975: 'requestcourses.community','requestcourses.textbook',
2976: 'reqcrsotherdom.official','reqcrsotherdom.unofficial',
2977: 'reqcrsotherdom.community','reqcrsotherdom.textbook',
1.414 raeburn 2978: 'reqcrsotherdom.placement','requestauthor',
2979: 'adhocroles.'.$env{'request.role.domain'}],
1.160 raeburn 2980: $env{'form.ccdomain'},$env{'form.ccuname'});
1.28 matthew 2981: my ($tmp) = keys(%userenv);
2982: if ($tmp =~ /^(con_lost|error)/i) {
2983: %userenv = ();
2984: }
1.206 raeburn 2985: my $no_forceid_alert;
2986: # Check to see if user information can be changed
2987: my %domconfig =
2988: &Apache::lonnet::get_dom('configuration',['usermodification'],
2989: $env{'form.ccdomain'});
1.213 raeburn 2990: my @statuses = ('active','future');
2991: my %roles = &Apache::lonnet::get_my_roles($env{'form.ccuname'},$env{'form.ccdomain'},'userroles',\@statuses,undef,$env{'request.role.domain'});
2992: my ($auname,$audom);
1.220 raeburn 2993: if ($context eq 'author') {
1.206 raeburn 2994: $auname = $env{'user.name'};
2995: $audom = $env{'user.domain'};
2996: }
2997: foreach my $item (keys(%roles)) {
1.220 raeburn 2998: my ($rolenum,$roledom,$role) = split(/:/,$item,-1);
1.206 raeburn 2999: if ($context eq 'course') {
3000: if ($cnum ne '' && $cdom ne '') {
3001: if ($rolenum eq $cnum && $roledom eq $cdom) {
3002: if (!grep(/^\Q$role\E$/,@userroles)) {
3003: push(@userroles,$role);
3004: }
3005: }
3006: }
3007: } elsif ($context eq 'author') {
3008: if ($rolenum eq $auname && $roledom eq $audom) {
3009: if (!grep(/^\Q$role\E$/,@userroles)) {
3010: push(@userroles,$role);
3011: }
3012: }
3013: }
3014: }
1.220 raeburn 3015: if ($env{'form.action'} eq 'singlestudent') {
3016: if (!grep(/^st$/,@userroles)) {
3017: push(@userroles,'st');
3018: }
3019: } else {
3020: # Check for course or co-author roles being activated or re-enabled
3021: if ($context eq 'author' || $context eq 'course') {
3022: foreach my $key (keys(%env)) {
3023: if ($context eq 'author') {
3024: if ($key=~/^form\.act_\Q$audom\E_\Q$auname\E_([^_]+)/) {
3025: if (!grep(/^\Q$1\E$/,@userroles)) {
3026: push(@userroles,$1);
3027: }
3028: } elsif ($key =~/^form\.ren\:\Q$audom\E\/\Q$auname\E_([^_]+)/) {
3029: if (!grep(/^\Q$1\E$/,@userroles)) {
3030: push(@userroles,$1);
3031: }
1.206 raeburn 3032: }
1.220 raeburn 3033: } elsif ($context eq 'course') {
3034: if ($key=~/^form\.act_\Q$cdom\E_\Q$cnum\E_([^_]+)/) {
3035: if (!grep(/^\Q$1\E$/,@userroles)) {
3036: push(@userroles,$1);
3037: }
3038: } elsif ($key =~/^form\.ren\:\Q$cdom\E\/\Q$cnum\E(\/?\w*)_([^_]+)/) {
3039: if (!grep(/^\Q$1\E$/,@userroles)) {
3040: push(@userroles,$1);
3041: }
1.206 raeburn 3042: }
3043: }
3044: }
3045: }
3046: }
3047: #Check to see if we can change personal data for the user
3048: my (@mod_disallowed,@longroles);
3049: foreach my $role (@userroles) {
3050: if ($role eq 'cr') {
3051: push(@longroles,'Custom');
3052: } else {
1.318 raeburn 3053: push(@longroles,&Apache::lonnet::plaintext($role,$crstype));
1.206 raeburn 3054: }
3055: }
1.219 raeburn 3056: my %canmodify = &Apache::lonuserutils::can_modify_userinfo($context,$env{'form.ccdomain'},\@userinfo,\@userroles);
3057: foreach my $item (@userinfo) {
1.28 matthew 3058: # Strip leading and trailing whitespace
1.203 raeburn 3059: $env{'form.c'.$item} =~ s/(\s+$|^\s+)//g;
1.219 raeburn 3060: if (!$canmodify{$item}) {
1.207 raeburn 3061: if (defined($env{'form.c'.$item})) {
3062: if ($env{'form.c'.$item} ne $userenv{$item}) {
3063: push(@mod_disallowed,$item);
3064: }
1.206 raeburn 3065: }
3066: $env{'form.c'.$item} = $userenv{$item};
3067: }
1.28 matthew 3068: }
1.259 bisitz 3069: # Check to see if we can change the Student/Employee ID
1.196 raeburn 3070: my $forceid = $env{'form.forceid'};
3071: my $recurseid = $env{'form.recurseid'};
3072: my (%alerts,%rulematch,%idinst_results,%curr_rules,%got_rules);
1.203 raeburn 3073: my %uidhash = &Apache::lonnet::idrget($env{'form.ccdomain'},
3074: $env{'form.ccuname'});
3075: if (($uidhash{$env{'form.ccuname'}}) &&
3076: ($uidhash{$env{'form.ccuname'}}!~/error\:/) &&
3077: (!$forceid)) {
3078: if ($env{'form.cid'} ne $uidhash{$env{'form.ccuname'}}) {
3079: $env{'form.cid'} = $userenv{'id'};
1.293 bisitz 3080: $no_forceid_alert = &mt('New student/employee ID does not match existing ID for this user.')
1.259 bisitz 3081: .'<br />'
3082: .&mt("Change is not permitted without checking the 'Force ID change' checkbox on the previous page.")
3083: .'<br />'."\n";
1.203 raeburn 3084: }
3085: }
3086: if ($env{'form.cid'} ne $userenv{'id'}) {
1.196 raeburn 3087: my $checkhash;
3088: my $checks = { 'id' => 1 };
3089: $checkhash->{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}} =
3090: { 'newuser' => $newuser,
3091: 'id' => $env{'form.cid'},
3092: };
3093: &Apache::loncommon::user_rule_check($checkhash,$checks,
3094: \%alerts,\%rulematch,\%idinst_results,\%curr_rules,\%got_rules);
3095: if (ref($alerts{'id'}) eq 'HASH') {
3096: if (ref($alerts{'id'}{$env{'form.ccdomain'}}) eq 'HASH') {
1.203 raeburn 3097: $env{'form.cid'} = $userenv{'id'};
1.196 raeburn 3098: }
3099: }
3100: }
1.378 raeburn 3101: my (%quotachanged,%oldquota,%newquota,%olddefquota,%newdefquota,
3102: $oldinststatus,$newinststatus,%oldisdefault,%newisdefault,%oldsettings,
1.339 raeburn 3103: %oldsettingstext,%newsettings,%newsettingstext,@disporder,
1.378 raeburn 3104: %oldsettingstatus,%newsettingstatus);
1.334 raeburn 3105: @disporder = ('inststatus');
3106: if ($env{'request.role.domain'} eq $env{'form.ccdomain'}) {
1.362 raeburn 3107: push(@disporder,'requestcourses','requestauthor');
1.334 raeburn 3108: } else {
3109: push(@disporder,'reqcrsotherdom');
3110: }
3111: push(@disporder,('quota','tools'));
1.338 raeburn 3112: $oldinststatus = $userenv{'inststatus'};
1.378 raeburn 3113: foreach my $name ('portfolio','author') {
3114: ($olddefquota{$name},$oldsettingstatus{$name}) =
3115: &Apache::loncommon::default_quota($env{'form.ccdomain'},$oldinststatus,$name);
3116: ($newdefquota{$name},$newsettingstatus{$name}) = ($olddefquota{$name},$oldsettingstatus{$name});
3117: }
1.414 raeburn 3118: push(@disporder,'adhocroles');
1.334 raeburn 3119: my %canshow;
1.220 raeburn 3120: if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
1.334 raeburn 3121: $canshow{'quota'} = 1;
1.220 raeburn 3122: }
1.267 raeburn 3123: if (&Apache::lonnet::allowed('mut',$env{'form.ccdomain'})) {
1.334 raeburn 3124: $canshow{'tools'} = 1;
1.267 raeburn 3125: }
1.275 raeburn 3126: if (&Apache::lonnet::allowed('ccc',$env{'form.ccdomain'})) {
1.334 raeburn 3127: $canshow{'requestcourses'} = 1;
1.300 raeburn 3128: } elsif (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
1.334 raeburn 3129: $canshow{'reqcrsotherdom'} = 1;
1.275 raeburn 3130: }
1.286 raeburn 3131: if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'})) {
1.334 raeburn 3132: $canshow{'inststatus'} = 1;
1.286 raeburn 3133: }
1.362 raeburn 3134: if (&Apache::lonnet::allowed('cau',$env{'form.ccdomain'})) {
3135: $canshow{'requestauthor'} = 1;
3136: }
1.414 raeburn 3137: if (&Apache::lonnet::allowed('cdh',$env{'request.role.domain'})) {
3138: $canshow{'adhocroles'} = 1;
3139: }
1.267 raeburn 3140: my (%changeHash,%changed);
1.286 raeburn 3141: if ($oldinststatus eq '') {
1.334 raeburn 3142: $oldsettings{'inststatus'} = $othertitle;
1.286 raeburn 3143: } else {
3144: if (ref($usertypes) eq 'HASH') {
1.334 raeburn 3145: $oldsettings{'inststatus'} = join(', ',map{ $usertypes->{ &unescape($_) }; } (split(/:/,$userenv{'inststatus'})));
1.286 raeburn 3146: } else {
1.334 raeburn 3147: $oldsettings{'inststatus'} = join(', ',map{ &unescape($_); } (split(/:/,$userenv{'inststatus'})));
1.286 raeburn 3148: }
3149: }
3150: $changeHash{'inststatus'} = $userenv{'inststatus'};
1.334 raeburn 3151: if ($canmodify_status{'inststatus'}) {
3152: $canshow{'inststatus'} = 1;
1.286 raeburn 3153: if (exists($env{'form.inststatus'})) {
3154: my @inststatuses = &Apache::loncommon::get_env_multiple('form.inststatus');
3155: if (@inststatuses > 0) {
3156: $newinststatus = join(':',map { &escape($_); } @inststatuses);
3157: $changeHash{'inststatus'} = $newinststatus;
3158: if ($newinststatus ne $oldinststatus) {
3159: $changed{'inststatus'} = $newinststatus;
1.378 raeburn 3160: foreach my $name ('portfolio','author') {
3161: ($newdefquota{$name},$newsettingstatus{$name}) =
3162: &Apache::loncommon::default_quota($env{'form.ccdomain'},$newinststatus,$name);
3163: }
1.286 raeburn 3164: }
3165: if (ref($usertypes) eq 'HASH') {
1.334 raeburn 3166: $newsettings{'inststatus'} = join(', ',map{ $usertypes->{$_}; } (@inststatuses));
1.286 raeburn 3167: } else {
1.337 raeburn 3168: $newsettings{'inststatus'} = join(', ',@inststatuses);
1.286 raeburn 3169: }
1.334 raeburn 3170: }
3171: } else {
3172: $newinststatus = '';
3173: $changeHash{'inststatus'} = $newinststatus;
3174: $newsettings{'inststatus'} = $othertitle;
3175: if ($newinststatus ne $oldinststatus) {
3176: $changed{'inststatus'} = $changeHash{'inststatus'};
1.378 raeburn 3177: foreach my $name ('portfolio','author') {
3178: ($newdefquota{$name},$newsettingstatus{$name}) =
3179: &Apache::loncommon::default_quota($env{'form.ccdomain'},$newinststatus,$name);
3180: }
1.286 raeburn 3181: }
3182: }
1.334 raeburn 3183: } elsif ($context ne 'selfcreate') {
3184: $canshow{'inststatus'} = 1;
1.337 raeburn 3185: $newsettings{'inststatus'} = $oldsettings{'inststatus'};
1.286 raeburn 3186: }
1.378 raeburn 3187: foreach my $name ('portfolio','author') {
3188: $changeHash{$name.'quota'} = $userenv{$name.'quota'};
3189: }
1.334 raeburn 3190: if ($context eq 'domain') {
1.378 raeburn 3191: foreach my $name ('portfolio','author') {
3192: if ($userenv{$name.'quota'} ne '') {
3193: $oldquota{$name} = $userenv{$name.'quota'};
3194: if ($env{'form.custom_'.$name.'quota'} == 1) {
3195: if ($env{'form.'.$name.'quota'} eq '') {
3196: $newquota{$name} = 0;
3197: } else {
3198: $newquota{$name} = $env{'form.'.$name.'quota'};
3199: $newquota{$name} =~ s/[^\d\.]//g;
3200: }
3201: if ($newquota{$name} != $oldquota{$name}) {
3202: if ("a_admin($newquota{$name},\%changeHash,$name)) {
3203: $changed{$name.'quota'} = 1;
3204: }
3205: }
1.334 raeburn 3206: } else {
1.378 raeburn 3207: if ("a_admin('',\%changeHash,$name)) {
3208: $changed{$name.'quota'} = 1;
3209: $newquota{$name} = $newdefquota{$name};
3210: $newisdefault{$name} = 1;
3211: }
1.334 raeburn 3212: }
1.149 raeburn 3213: } else {
1.378 raeburn 3214: $oldisdefault{$name} = 1;
3215: $oldquota{$name} = $olddefquota{$name};
3216: if ($env{'form.custom_'.$name.'quota'} == 1) {
3217: if ($env{'form.'.$name.'quota'} eq '') {
3218: $newquota{$name} = 0;
3219: } else {
3220: $newquota{$name} = $env{'form.'.$name.'quota'};
3221: $newquota{$name} =~ s/[^\d\.]//g;
3222: }
3223: if ("a_admin($newquota{$name},\%changeHash,$name)) {
3224: $changed{$name.'quota'} = 1;
3225: }
1.334 raeburn 3226: } else {
1.378 raeburn 3227: $newquota{$name} = $newdefquota{$name};
3228: $newisdefault{$name} = 1;
1.334 raeburn 3229: }
1.378 raeburn 3230: }
3231: if ($oldisdefault{$name}) {
3232: $oldsettingstext{'quota'}{$name} = &get_defaultquota_text($oldsettingstatus{$name});
1.383 raeburn 3233: } else {
3234: $oldsettingstext{'quota'}{$name} = &mt('custom quota: [_1] MB',$oldquota{$name});
1.378 raeburn 3235: }
3236: if ($newisdefault{$name}) {
3237: $newsettingstext{'quota'}{$name} = &get_defaultquota_text($newsettingstatus{$name});
1.383 raeburn 3238: } else {
3239: $newsettingstext{'quota'}{$name} = &mt('custom quota: [_1] MB',$newquota{$name});
1.134 raeburn 3240: }
3241: }
1.334 raeburn 3242: &tool_changes('tools',\@usertools,\%oldsettings,\%oldsettingstext,\%userenv,
3243: \%changeHash,\%changed,\%newsettings,\%newsettingstext);
3244: if ($env{'form.ccdomain'} eq $env{'request.role.domain'}) {
3245: &tool_changes('requestcourses',\@requestcourses,\%oldsettings,\%oldsettingstext,
3246: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
1.384 raeburn 3247: &tool_changes('requestauthor',\@requestauthor,\%oldsettings,\%oldsettingstext,
3248: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
1.149 raeburn 3249: } else {
1.334 raeburn 3250: &tool_changes('reqcrsotherdom',\@requestcourses,\%oldsettings,\%oldsettingstext,
3251: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
1.149 raeburn 3252: }
1.414 raeburn 3253: if ($userenv{'adhocroles.'.$env{'request.role.domain'}}) {
3254: $changeHash{'adhocroles.'.$env{'request.role.domain'}} = $userenv{'adhocroles.'.$env{'request.role.domain'}};
3255: }
3256: if (&adhocrole_changes(\%changeHash,\%userenv)) {
3257: $changed{'adhocroles'} = 1;
3258: $oldsettings{'adhocroles'} = $userenv{'adhocroles.'.$env{'request.role.domain'}};
1.417 raeburn 3259: $newsettings{'adhocroles'} = $changeHash{'adhocroles.'.$env{'request.role.domain'}};
1.414 raeburn 3260: }
1.149 raeburn 3261: }
1.334 raeburn 3262: foreach my $item (@userinfo) {
3263: if ($env{'form.c'.$item} ne $userenv{$item}) {
3264: $namechanged{$item} = 1;
3265: }
1.204 raeburn 3266: }
1.378 raeburn 3267: foreach my $name ('portfolio','author') {
1.390 bisitz 3268: $oldsettings{'quota'}{$name} = &mt('[_1] MB',$oldquota{$name});
3269: $newsettings{'quota'}{$name} = &mt('[_1] MB',$newquota{$name});
1.378 raeburn 3270: }
1.334 raeburn 3271: if ((keys(%namechanged) > 0) || (keys(%changed) > 0)) {
1.267 raeburn 3272: my ($chgresult,$namechgresult);
3273: if (keys(%changed) > 0) {
3274: $chgresult =
1.204 raeburn 3275: &Apache::lonnet::put('environment',\%changeHash,
3276: $env{'form.ccdomain'},$env{'form.ccuname'});
1.267 raeburn 3277: if ($chgresult eq 'ok') {
3278: if (($env{'user.name'} eq $env{'form.ccuname'}) &&
3279: ($env{'user.domain'} eq $env{'form.ccdomain'})) {
1.270 raeburn 3280: my %newenvhash;
3281: foreach my $key (keys(%changed)) {
1.411 raeburn 3282: if (($key eq 'official') || ($key eq 'unofficial') ||
3283: ($key eq 'community') || ($key eq 'textbook') ||
3284: ($key eq 'placement')) {
1.279 raeburn 3285: $newenvhash{'environment.requestcourses.'.$key} =
3286: $changeHash{'requestcourses.'.$key};
1.362 raeburn 3287: if ($changeHash{'requestcourses.'.$key}) {
1.332 raeburn 3288: $newenvhash{'environment.canrequest.'.$key} = 1;
1.279 raeburn 3289: } else {
3290: $newenvhash{'environment.canrequest.'.$key} =
3291: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
3292: $key,'reload','requestcourses');
3293: }
1.362 raeburn 3294: } elsif ($key eq 'requestauthor') {
3295: $newenvhash{'environment.'.$key} = $changeHash{$key};
3296: if ($changeHash{$key}) {
3297: $newenvhash{'environment.canrequest.author'} = 1;
3298: } else {
3299: $newenvhash{'environment.canrequest.author'} =
3300: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
3301: $key,'reload','requestauthor');
3302: }
1.414 raeburn 3303: } elsif ($key eq 'adhocroles') {
3304: $newenvhash{'adhocroles.'.$env{'request.role.domain'}} =
3305: $changeHash{'adhocroles.'.$env{'request.role.domain'}};
1.275 raeburn 3306: } elsif ($key ne 'quota') {
1.270 raeburn 3307: $newenvhash{'environment.tools.'.$key} =
3308: $changeHash{'tools.'.$key};
1.279 raeburn 3309: if ($changeHash{'tools.'.$key} ne '') {
3310: $newenvhash{'environment.availabletools.'.$key} =
3311: $changeHash{'tools.'.$key};
3312: } else {
3313: $newenvhash{'environment.availabletools.'.$key} =
1.367 golterma 3314: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
3315: $key,'reload','tools');
1.279 raeburn 3316: }
1.270 raeburn 3317: }
3318: }
1.271 raeburn 3319: if (keys(%newenvhash)) {
3320: &Apache::lonnet::appenv(\%newenvhash);
3321: }
1.267 raeburn 3322: }
3323: }
1.204 raeburn 3324: }
1.334 raeburn 3325: if (keys(%namechanged) > 0) {
1.337 raeburn 3326: foreach my $field (@userinfo) {
3327: $changeHash{$field} = $env{'form.c'.$field};
3328: }
3329: # Make the change
1.204 raeburn 3330: $namechgresult =
3331: &Apache::lonnet::modifyuser($env{'form.ccdomain'},
3332: $env{'form.ccuname'},$changeHash{'id'},undef,undef,
3333: $changeHash{'firstname'},$changeHash{'middlename'},
3334: $changeHash{'lastname'},$changeHash{'generation'},
1.337 raeburn 3335: $changeHash{'id'},undef,$changeHash{'permanentemail'},undef,\@userinfo);
1.220 raeburn 3336: %userupdate = (
3337: lastname => $env{'form.clastname'},
3338: middlename => $env{'form.cmiddlename'},
3339: firstname => $env{'form.cfirstname'},
3340: generation => $env{'form.cgeneration'},
3341: id => $env{'form.cid'},
3342: );
1.204 raeburn 3343: }
1.334 raeburn 3344: if (((keys(%namechanged) > 0) && $namechgresult eq 'ok') ||
1.267 raeburn 3345: ((keys(%changed) > 0) && $chgresult eq 'ok')) {
1.28 matthew 3346: # Tell the user we changed the name
1.334 raeburn 3347: &display_userinfo($r,1,\@disporder,\%canshow,\@requestcourses,
1.362 raeburn 3348: \@usertools,\@requestauthor,\%userenv,\%changed,\%namechanged,
1.334 raeburn 3349: \%oldsettings, \%oldsettingstext,\%newsettings,
3350: \%newsettingstext);
1.203 raeburn 3351: if ($env{'form.cid'} ne $userenv{'id'}) {
3352: &Apache::lonnet::idput($env{'form.ccdomain'},
1.407 raeburn 3353: {$env{'form.ccuname'} => $env{'form.cid'}},$uhome,'ids');
1.203 raeburn 3354: if (($recurseid) &&
3355: (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'}))) {
3356: my $idresult =
3357: &Apache::lonuserutils::propagate_id_change(
3358: $env{'form.ccuname'},$env{'form.ccdomain'},
3359: \%userupdate);
3360: $r->print('<br />'.$idresult.'<br />');
3361: }
1.196 raeburn 3362: }
1.149 raeburn 3363: if (($env{'form.ccdomain'} eq $env{'user.domain'}) &&
3364: ($env{'form.ccuname'} eq $env{'user.name'})) {
3365: my %newenvhash;
3366: foreach my $key (keys(%changeHash)) {
3367: $newenvhash{'environment.'.$key} = $changeHash{$key};
3368: }
1.238 raeburn 3369: &Apache::lonnet::appenv(\%newenvhash);
1.149 raeburn 3370: }
1.28 matthew 3371: } else { # error occurred
1.389 bisitz 3372: $r->print(
3373: '<p class="LC_error">'
3374: .&mt('Unable to successfully change environment for [_1] in domain [_2].',
3375: '"'.$env{'form.ccuname'}.'"',
3376: '"'.$env{'form.ccdomain'}.'"')
3377: .'</p>');
1.28 matthew 3378: }
1.334 raeburn 3379: } else { # End of if ($env ... ) logic
1.275 raeburn 3380: # They did not want to change the users name, quota, tool availability,
3381: # or ability to request creation of courses,
1.267 raeburn 3382: # but we can still tell them what the name and quota and availabilities are
1.334 raeburn 3383: &display_userinfo($r,undef,\@disporder,\%canshow,\@requestcourses,
1.362 raeburn 3384: \@usertools,\@requestauthor,\%userenv,\%changed,\%namechanged,\%oldsettings,
1.334 raeburn 3385: \%oldsettingstext,\%newsettings,\%newsettingstext);
1.28 matthew 3386: }
1.206 raeburn 3387: if (@mod_disallowed) {
3388: my ($rolestr,$contextname);
3389: if (@longroles > 0) {
3390: $rolestr = join(', ',@longroles);
3391: } else {
3392: $rolestr = &mt('No roles');
3393: }
3394: if ($context eq 'course') {
1.399 bisitz 3395: $contextname = 'course';
1.206 raeburn 3396: } elsif ($context eq 'author') {
1.399 bisitz 3397: $contextname = 'co-author';
1.206 raeburn 3398: }
3399: $r->print(&mt('The following fields were not updated: ').'<ul>');
3400: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
3401: foreach my $field (@mod_disallowed) {
3402: $r->print('<li>'.$fieldtitles{$field}.'</li>'."\n");
3403: }
1.207 raeburn 3404: $r->print('</ul>');
3405: if (@mod_disallowed == 1) {
1.399 bisitz 3406: $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 3407: } else {
1.399 bisitz 3408: $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 3409: }
1.292 bisitz 3410: my $helplink = 'javascript:helpMenu('."'display'".')';
3411: $r->print('<span class="LC_cusr_emph">'.$rolestr.'</span><br />'
3412: .&mt('Please contact your [_1]helpdesk[_2] for more information.'
3413: ,'<a href="'.$helplink.'">','</a>')
3414: .'<br />');
1.206 raeburn 3415: }
1.259 bisitz 3416: $r->print('<span class="LC_warning">'
3417: .$no_forceid_alert
3418: .&Apache::lonuserutils::print_namespacing_alerts($env{'form.ccdomain'},\%alerts,\%curr_rules)
3419: .'</span>');
1.4 www 3420: }
1.367 golterma 3421: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
1.220 raeburn 3422: if ($env{'form.action'} eq 'singlestudent') {
1.375 raeburn 3423: &enroll_single_student($r,$uhome,$amode,$genpwd,$now,$newuser,$context,
3424: $crstype,$showcredits,$defaultcredits);
1.386 bisitz 3425: my $linktext = ($crstype eq 'Community' ?
3426: &mt('Enroll Another Member') : &mt('Enroll Another Student'));
3427: $r->print(
3428: &Apache::lonhtmlcommon::actionbox([
3429: '<a href="javascript:backPage(document.userupdate)">'
3430: .($crstype eq 'Community' ?
3431: &mt('Enroll Another Member') : &mt('Enroll Another Student'))
3432: .'</a>']));
1.220 raeburn 3433: } else {
1.375 raeburn 3434: my @rolechanges = &update_roles($r,$context,$showcredits);
1.334 raeburn 3435: if (keys(%namechanged) > 0) {
1.220 raeburn 3436: if ($context eq 'course') {
3437: if (@userroles > 0) {
1.225 raeburn 3438: if ((@rolechanges == 0) ||
3439: (!(grep(/^st$/,@rolechanges)))) {
3440: if (grep(/^st$/,@userroles)) {
3441: my $classlistupdated =
3442: &Apache::lonuserutils::update_classlist($cdom,
1.220 raeburn 3443: $cnum,$env{'form.ccdomain'},
3444: $env{'form.ccuname'},\%userupdate);
1.225 raeburn 3445: }
1.220 raeburn 3446: }
3447: }
3448: }
3449: }
1.226 raeburn 3450: my $userinfo = &Apache::loncommon::plainname($env{'form.ccuname'},
1.233 raeburn 3451: $env{'form.ccdomain'});
3452: if ($env{'form.popup'}) {
3453: $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a></p>');
3454: } else {
1.367 golterma 3455: $r->print('<br />'.&Apache::lonhtmlcommon::actionbox(['<a href="javascript:backPage(document.userupdate,'."'$env{'form.prevphase'}','modify'".')">'
3456: .&mt('Modify this user: [_1]','<span class="LC_cusr_emph">'.$env{'form.ccuname'}.':'.$env{'form.ccdomain'}.' ('.$userinfo.')</span>').'</a>',
3457: '<a href="javascript:backPage(document.userupdate)">'.&mt('Create/Modify Another User').'</a>']));
1.233 raeburn 3458: }
1.220 raeburn 3459: }
3460: }
3461:
1.334 raeburn 3462: sub display_userinfo {
1.362 raeburn 3463: my ($r,$changed,$order,$canshow,$requestcourses,$usertools,$requestauthor,
3464: $userenv,$changedhash,$namechangedhash,$oldsetting,$oldsettingtext,
1.334 raeburn 3465: $newsetting,$newsettingtext) = @_;
3466: return unless (ref($order) eq 'ARRAY' &&
3467: ref($canshow) eq 'HASH' &&
3468: ref($requestcourses) eq 'ARRAY' &&
1.362 raeburn 3469: ref($requestauthor) eq 'ARRAY' &&
1.334 raeburn 3470: ref($usertools) eq 'ARRAY' &&
3471: ref($userenv) eq 'HASH' &&
3472: ref($changedhash) eq 'HASH' &&
3473: ref($oldsetting) eq 'HASH' &&
3474: ref($oldsettingtext) eq 'HASH' &&
3475: ref($newsetting) eq 'HASH' &&
3476: ref($newsettingtext) eq 'HASH');
3477: my %lt=&Apache::lonlocal::texthash(
1.372 raeburn 3478: 'ui' => 'User Information',
1.334 raeburn 3479: 'uic' => 'User Information Changed',
3480: 'firstname' => 'First Name',
3481: 'middlename' => 'Middle Name',
3482: 'lastname' => 'Last Name',
3483: 'generation' => 'Generation',
3484: 'id' => 'Student/Employee ID',
3485: 'permanentemail' => 'Permanent e-mail address',
1.378 raeburn 3486: 'portfolioquota' => 'Disk space allocated to portfolio files',
1.385 bisitz 3487: 'authorquota' => 'Disk space allocated to Authoring Space',
1.334 raeburn 3488: 'blog' => 'Blog Availability',
1.361 raeburn 3489: 'webdav' => 'WebDAV Availability',
1.334 raeburn 3490: 'aboutme' => 'Personal Information Page Availability',
3491: 'portfolio' => 'Portfolio Availability',
3492: 'official' => 'Can Request Official Courses',
3493: 'unofficial' => 'Can Request Unofficial Courses',
3494: 'community' => 'Can Request Communities',
1.384 raeburn 3495: 'textbook' => 'Can Request Textbook Courses',
1.411 raeburn 3496: 'placement' => 'Can Request Placement Tests',
1.362 raeburn 3497: 'requestauthor' => 'Can Request Author Role',
1.414 raeburn 3498: 'adhocroles' => 'Ad Hoc Roles Selectable via Helpdesk Role',
1.334 raeburn 3499: 'inststatus' => "Affiliation",
3500: 'prvs' => 'Previous Value:',
3501: 'chto' => 'Changed To:'
3502: );
3503: if ($changed) {
1.372 raeburn 3504: $r->print('<h3>'.$lt{'uic'}.'</h3>'.
1.367 golterma 3505: &Apache::loncommon::start_data_table().
3506: &Apache::loncommon::start_data_table_header_row());
1.334 raeburn 3507: $r->print("<th> </th>\n");
1.367 golterma 3508: $r->print('<th><b>'.$lt{'prvs'}.'</b></th>');
3509: $r->print('<th><span class="LC_nobreak"><b>'.$lt{'chto'}.'</b></span></th>');
3510: $r->print(&Apache::loncommon::end_data_table_header_row());
3511: my @userinfo = ('firstname','middlename','lastname','generation','permanentemail','id');
3512:
1.334 raeburn 3513: foreach my $item (@userinfo) {
3514: my $value = $env{'form.c'.$item};
1.367 golterma 3515: #show changes only:
1.383 raeburn 3516: unless ($value eq $userenv->{$item}){
1.367 golterma 3517: $r->print(&Apache::loncommon::start_data_table_row());
3518: $r->print("<td>$lt{$item}</td>\n");
1.383 raeburn 3519: $r->print("<td>".$userenv->{$item}."</td>\n");
1.367 golterma 3520: $r->print("<td>$value </td>\n");
3521: $r->print(&Apache::loncommon::end_data_table_row());
1.334 raeburn 3522: }
3523: }
3524: foreach my $entry (@{$order}) {
1.383 raeburn 3525: if ($canshow->{$entry}) {
3526: if (($entry eq 'requestcourses') || ($entry eq 'reqcrsotherdom') || ($entry eq 'requestauthor')) {
3527: my @items;
3528: if ($entry eq 'requestauthor') {
3529: @items = ($entry);
3530: } else {
3531: @items = @{$requestcourses};
1.384 raeburn 3532: }
1.383 raeburn 3533: foreach my $item (@items) {
3534: if (($newsetting->{$item} ne $oldsetting->{$item}) ||
3535: ($newsettingtext->{$item} ne $oldsettingtext->{$item})) {
3536: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3537: $r->print("<td>$lt{$item}</td>\n");
3538: $r->print("<td>".$oldsetting->{$item});
3539: if ($oldsettingtext->{$item}) {
3540: if ($oldsetting->{$item}) {
3541: $r->print(' -- ');
3542: }
3543: $r->print($oldsettingtext->{$item});
3544: }
3545: $r->print("</td>\n");
3546: $r->print("<td>".$newsetting->{$item});
3547: if ($newsettingtext->{$item}) {
3548: if ($newsetting->{$item}) {
3549: $r->print(' -- ');
3550: }
3551: $r->print($newsettingtext->{$item});
3552: }
3553: $r->print("</td>\n");
3554: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.334 raeburn 3555: }
3556: }
3557: } elsif ($entry eq 'tools') {
3558: foreach my $item (@{$usertools}) {
1.383 raeburn 3559: if ($newsetting->{$item} ne $oldsetting->{$item}) {
3560: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3561: $r->print("<td>$lt{$item}</td>\n");
3562: $r->print("<td>".$oldsetting->{$item}.' '.$oldsettingtext->{$item}."</td>\n");
3563: $r->print("<td>".$newsetting->{$item}.' '.$newsettingtext->{$item}."</td>\n");
3564: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.334 raeburn 3565: }
3566: }
1.378 raeburn 3567: } elsif ($entry eq 'quota') {
3568: if ((ref($oldsetting->{$entry}) eq 'HASH') && (ref($oldsettingtext->{$entry}) eq 'HASH') &&
3569: (ref($newsetting->{$entry}) eq 'HASH') && (ref($newsettingtext->{$entry}) eq 'HASH')) {
3570: foreach my $name ('portfolio','author') {
1.383 raeburn 3571: if ($newsetting->{$entry}->{$name} ne $oldsetting->{$entry}->{$name}) {
3572: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3573: $r->print("<td>$lt{$name.$entry}</td>\n");
3574: $r->print("<td>".$oldsettingtext->{$entry}->{$name}."</td>\n");
3575: $r->print("<td>".$newsettingtext->{$entry}->{$name}."</td>\n");
3576: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.378 raeburn 3577: }
3578: }
3579: }
1.334 raeburn 3580: } else {
1.383 raeburn 3581: if ($newsetting->{$entry} ne $oldsetting->{$entry}) {
3582: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3583: $r->print("<td>$lt{$entry}</td>\n");
3584: $r->print("<td>".$oldsetting->{$entry}.' '.$oldsettingtext->{$entry}."</td>\n");
3585: $r->print("<td>".$newsetting->{$entry}.' '.$newsettingtext->{$entry}."</td>\n");
3586: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.334 raeburn 3587: }
3588: }
3589: }
3590: }
1.367 golterma 3591: $r->print(&Apache::loncommon::end_data_table().'<br />');
1.372 raeburn 3592: } else {
3593: $r->print('<h3>'.$lt{'ui'}.'</h3>'.
3594: '<p>'.&mt('No changes made to user information').'</p>');
1.334 raeburn 3595: }
3596: return;
3597: }
3598:
1.275 raeburn 3599: sub tool_changes {
3600: my ($context,$usertools,$oldaccess,$oldaccesstext,$userenv,$changeHash,
3601: $changed,$newaccess,$newaccesstext) = @_;
3602: if (!((ref($usertools) eq 'ARRAY') && (ref($oldaccess) eq 'HASH') &&
3603: (ref($oldaccesstext) eq 'HASH') && (ref($userenv) eq 'HASH') &&
3604: (ref($changeHash) eq 'HASH') && (ref($changed) eq 'HASH') &&
3605: (ref($newaccess) eq 'HASH') && (ref($newaccesstext) eq 'HASH'))) {
3606: return;
3607: }
1.383 raeburn 3608: my %reqdisplay = &requestchange_display();
1.300 raeburn 3609: if ($context eq 'reqcrsotherdom') {
1.309 raeburn 3610: my @options = ('approval','validate','autolimit');
1.306 raeburn 3611: my $optregex = join('|',@options);
1.300 raeburn 3612: my $cdom = $env{'request.role.domain'};
3613: foreach my $tool (@{$usertools}) {
1.383 raeburn 3614: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
1.314 raeburn 3615: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
1.300 raeburn 3616: $changeHash->{$context.'.'.$tool} = $userenv->{$context.'.'.$tool};
1.383 raeburn 3617: my ($newop,$limit);
1.314 raeburn 3618: if ($env{'form.'.$context.'_'.$tool}) {
3619: $newop = $env{'form.'.$context.'_'.$tool};
3620: if ($newop eq 'autolimit') {
1.383 raeburn 3621: $limit = $env{'form.'.$context.'_'.$tool.'_limit'};
1.314 raeburn 3622: $limit =~ s/\D+//g;
3623: $newop .= '='.$limit;
3624: }
3625: }
1.300 raeburn 3626: if ($userenv->{$context.'.'.$tool} eq '') {
1.314 raeburn 3627: if ($newop) {
3628: $changed->{$tool}=&tool_admin($tool,$cdom.':'.$newop,
1.300 raeburn 3629: $changeHash,$context);
3630: if ($changed->{$tool}) {
1.383 raeburn 3631: if ($newop =~ /^autolimit/) {
3632: if ($limit) {
3633: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3634: } else {
3635: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3636: }
3637: } else {
3638: $newaccesstext->{$tool} = $reqdisplay{$newop};
3639: }
1.300 raeburn 3640: } else {
3641: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
3642: }
3643: }
3644: } else {
3645: my @curr = split(',',$userenv->{$context.'.'.$tool});
3646: my @new;
3647: my $changedoms;
1.314 raeburn 3648: foreach my $req (@curr) {
3649: if ($req =~ /^\Q$cdom\E\:($optregex\=?\d*)$/) {
3650: my $oldop = $1;
1.383 raeburn 3651: if ($oldop =~ /^autolimit=(\d*)/) {
3652: my $limit = $1;
3653: if ($limit) {
3654: $oldaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3655: } else {
3656: $oldaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3657: }
3658: } else {
3659: $oldaccesstext->{$tool} = $reqdisplay{$oldop};
3660: }
1.314 raeburn 3661: if ($oldop ne $newop) {
3662: $changedoms = 1;
3663: foreach my $item (@curr) {
3664: my ($reqdom,$option) = split(':',$item);
3665: unless ($reqdom eq $cdom) {
3666: push(@new,$item);
3667: }
3668: }
3669: if ($newop) {
3670: push(@new,$cdom.':'.$newop);
1.300 raeburn 3671: }
1.314 raeburn 3672: @new = sort(@new);
1.300 raeburn 3673: }
1.314 raeburn 3674: last;
1.300 raeburn 3675: }
1.314 raeburn 3676: }
3677: if ((!$changedoms) && ($newop)) {
1.300 raeburn 3678: $changedoms = 1;
1.306 raeburn 3679: @new = sort(@curr,$cdom.':'.$newop);
1.300 raeburn 3680: }
3681: if ($changedoms) {
1.314 raeburn 3682: my $newdomstr;
1.300 raeburn 3683: if (@new) {
3684: $newdomstr = join(',',@new);
3685: }
3686: $changed->{$tool}=&tool_admin($tool,$newdomstr,$changeHash,
3687: $context);
3688: if ($changed->{$tool}) {
3689: if ($env{'form.'.$context.'_'.$tool}) {
1.306 raeburn 3690: if ($env{'form.'.$context.'_'.$tool} eq 'autolimit') {
1.314 raeburn 3691: my $limit = $env{'form.'.$context.'_'.$tool.'_limit'};
3692: $limit =~ s/\D+//g;
3693: if ($limit) {
1.383 raeburn 3694: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
1.314 raeburn 3695: } else {
1.383 raeburn 3696: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
1.306 raeburn 3697: }
1.314 raeburn 3698: } else {
1.306 raeburn 3699: $newaccesstext->{$tool} = $reqdisplay{$env{'form.'.$context.'_'.$tool}};
3700: }
1.300 raeburn 3701: } else {
1.383 raeburn 3702: $newaccesstext->{$tool} = &mt("availability set to 'off'");
1.300 raeburn 3703: }
3704: }
3705: }
3706: }
3707: }
3708: return;
3709: }
1.275 raeburn 3710: foreach my $tool (@{$usertools}) {
1.383 raeburn 3711: my ($newval,$limit,$envkey);
1.362 raeburn 3712: $envkey = $context.'.'.$tool;
1.306 raeburn 3713: if ($context eq 'requestcourses') {
3714: $newval = $env{'form.crsreq_'.$tool};
3715: if ($newval eq 'autolimit') {
1.383 raeburn 3716: $limit = $env{'form.crsreq_'.$tool.'_limit'};
3717: $limit =~ s/\D+//g;
3718: $newval .= '='.$limit;
1.306 raeburn 3719: }
1.362 raeburn 3720: } elsif ($context eq 'requestauthor') {
3721: $newval = $env{'form.'.$context};
3722: $envkey = $context;
1.314 raeburn 3723: } else {
1.306 raeburn 3724: $newval = $env{'form.'.$context.'_'.$tool};
3725: }
1.362 raeburn 3726: if ($userenv->{$envkey} ne '') {
1.275 raeburn 3727: $oldaccess->{$tool} = &mt('custom');
1.383 raeburn 3728: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3729: if ($userenv->{$envkey} =~ /^autolimit=(\d*)$/) {
3730: my $currlimit = $1;
3731: if ($currlimit eq '') {
3732: $oldaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3733: } else {
3734: $oldaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$currlimit);
3735: }
3736: } elsif ($userenv->{$envkey}) {
3737: $oldaccesstext->{$tool} = $reqdisplay{$userenv->{$envkey}};
3738: } else {
3739: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
3740: }
1.275 raeburn 3741: } else {
1.383 raeburn 3742: if ($userenv->{$envkey}) {
3743: $oldaccesstext->{$tool} = &mt("availability set to 'on'");
3744: } else {
3745: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
3746: }
1.275 raeburn 3747: }
1.362 raeburn 3748: $changeHash->{$envkey} = $userenv->{$envkey};
1.275 raeburn 3749: if ($env{'form.custom'.$tool} == 1) {
1.362 raeburn 3750: if ($newval ne $userenv->{$envkey}) {
1.306 raeburn 3751: $changed->{$tool} = &tool_admin($tool,$newval,$changeHash,
3752: $context);
1.275 raeburn 3753: if ($changed->{$tool}) {
3754: $newaccess->{$tool} = &mt('custom');
1.383 raeburn 3755: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3756: if ($newval =~ /^autolimit/) {
3757: if ($limit) {
3758: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3759: } else {
3760: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3761: }
3762: } elsif ($newval) {
3763: $newaccesstext->{$tool} = $reqdisplay{$newval};
3764: } else {
3765: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3766: }
1.275 raeburn 3767: } else {
1.383 raeburn 3768: if ($newval) {
3769: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3770: } else {
3771: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3772: }
1.275 raeburn 3773: }
3774: } else {
3775: $newaccess->{$tool} = $oldaccess->{$tool};
1.383 raeburn 3776: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3777: if ($newval =~ /^autolimit/) {
3778: if ($limit) {
3779: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3780: } else {
3781: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3782: }
3783: } elsif ($newval) {
3784: $newaccesstext->{$tool} = $reqdisplay{$newval};
3785: } else {
3786: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3787: }
1.275 raeburn 3788: } else {
1.383 raeburn 3789: if ($userenv->{$context.'.'.$tool}) {
3790: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3791: } else {
3792: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3793: }
1.275 raeburn 3794: }
3795: }
3796: } else {
3797: $newaccess->{$tool} = $oldaccess->{$tool};
3798: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
3799: }
3800: } else {
3801: $changed->{$tool} = &tool_admin($tool,'',$changeHash,$context);
3802: if ($changed->{$tool}) {
3803: $newaccess->{$tool} = &mt('default');
3804: } else {
3805: $newaccess->{$tool} = $oldaccess->{$tool};
1.383 raeburn 3806: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3807: if ($newval =~ /^autolimit/) {
3808: if ($limit) {
3809: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3810: } else {
3811: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3812: }
3813: } elsif ($newval) {
3814: $newaccesstext->{$tool} = $reqdisplay{$newval};
3815: } else {
3816: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3817: }
1.275 raeburn 3818: } else {
1.383 raeburn 3819: if ($userenv->{$context.'.'.$tool}) {
3820: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3821: } else {
3822: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3823: }
1.275 raeburn 3824: }
3825: }
3826: }
3827: } else {
3828: $oldaccess->{$tool} = &mt('default');
3829: if ($env{'form.custom'.$tool} == 1) {
1.306 raeburn 3830: $changed->{$tool} = &tool_admin($tool,$newval,$changeHash,
3831: $context);
1.275 raeburn 3832: if ($changed->{$tool}) {
3833: $newaccess->{$tool} = &mt('custom');
1.383 raeburn 3834: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3835: if ($newval =~ /^autolimit/) {
3836: if ($limit) {
3837: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3838: } else {
3839: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3840: }
3841: } elsif ($newval) {
3842: $newaccesstext->{$tool} = $reqdisplay{$newval};
3843: } else {
3844: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3845: }
1.275 raeburn 3846: } else {
1.383 raeburn 3847: if ($newval) {
3848: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3849: } else {
3850: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3851: }
1.275 raeburn 3852: }
3853: } else {
3854: $newaccess->{$tool} = $oldaccess->{$tool};
3855: }
3856: } else {
3857: $newaccess->{$tool} = $oldaccess->{$tool};
3858: }
3859: }
3860: }
3861: return;
3862: }
3863:
1.414 raeburn 3864: sub adhocrole_changes {
3865: my ($changehashref,$userenv) = @_;
3866: my @adds = &Apache::loncommon::get_env_multiple('form.adhocroleadd');
3867: my @dels = &Apache::loncommon::get_env_multiple('form.adhocroledel');
3868: my (@saved,@added,@alladhoc,$changed);
3869: my $adhoc_key = 'adhocroles.'.$env{'request.role.domain'};
3870: if (!$env{'form.makeuser'}) {
3871: if (ref($userenv) eq 'HASH') {
3872: my @current;
3873: if ($userenv->{$adhoc_key}) {
3874: @current = split(/,/,$userenv->{$adhoc_key});
3875: if (@dels) {
3876: foreach my $curr (@current) {
1.417 raeburn 3877: next if ($curr eq '');
1.414 raeburn 3878: unless (grep(/\Q$curr\E$/,@dels)) {
3879: push(@saved,$curr);
3880: }
3881: }
3882: $changed = 1;
3883: } else {
3884: @saved = @current;
3885: }
3886: }
3887: }
3888: }
3889: if (@adds) {
3890: my $confname = &Apache::lonnet::get_domainconfiguser($env{'request.role.domain'});
3891: my %existing=&Apache::lonnet::dump('roles',$env{'request.role.domain'},
3892: $confname,'rolesdef_');
3893: foreach my $poss (@adds) {
3894: if (exists($existing{'rolesdef_'.$poss})) {
3895: push(@added,$poss);
3896: $changed = 1;
3897: }
3898: }
3899: }
3900: if (@added) {
3901: if (@saved) {
3902: foreach my $add (@added) {
3903: unless (grep(/^\Q$add\E$/,@saved)) {
3904: push(@alladhoc,$add);
3905: }
3906: }
3907: } else {
3908: push(@alladhoc,@added);
3909: }
3910: }
3911: if (@saved) {
3912: push(@alladhoc,@saved);
3913: }
3914: if (@alladhoc) {
1.417 raeburn 3915: my $adhocstr = join(',',sort(@alladhoc));
1.414 raeburn 3916: $changehashref->{$adhoc_key} = $adhocstr;
3917: } elsif (@dels) {
3918: &Apache::lonnet::del('environment',[$adhoc_key],$env{'form.ccdomain'},$env{'form.ccuname'});
3919: delete($changehashref->{$adhoc_key});
3920: if (($env{'form.ccdomain'} eq $env{'user.domain'}) &&
3921: ($env{'form.ccuname'} eq $env{'user.name'})) {
3922: &Apache::lonnet::delenv($adhoc_key);
3923: }
3924: }
3925: return $changed;
3926: }
3927:
1.220 raeburn 3928: sub update_roles {
1.375 raeburn 3929: my ($r,$context,$showcredits) = @_;
1.4 www 3930: my $now=time;
1.225 raeburn 3931: my @rolechanges;
1.220 raeburn 3932: my %disallowed;
1.73 sakharuk 3933: $r->print('<h3>'.&mt('Modifying Roles').'</h3>');
1.404 raeburn 3934: foreach my $key (keys(%env)) {
1.135 raeburn 3935: next if (! $env{$key});
1.190 raeburn 3936: next if ($key eq 'form.action');
1.27 matthew 3937: # Revoke roles
1.135 raeburn 3938: if ($key=~/^form\.rev/) {
3939: if ($key=~/^form\.rev\:([^\_]+)\_([^\_\.]+)$/) {
1.64 www 3940: # Revoke standard role
1.170 albertel 3941: my ($scope,$role) = ($1,$2);
3942: my $result =
3943: &Apache::lonnet::revokerole($env{'form.ccdomain'},
3944: $env{'form.ccuname'},
1.239 raeburn 3945: $scope,$role,'','',$context);
1.367 golterma 3946: $r->print(&Apache::lonhtmlcommon::confirm_success(
1.369 bisitz 3947: &mt('Revoking [_1] in [_2]',
3948: &Apache::lonnet::plaintext($role),
1.372 raeburn 3949: &Apache::loncommon::show_role_extent($scope,$context,$role)),
1.369 bisitz 3950: $result ne "ok").'<br />');
3951: if ($result ne "ok") {
3952: $r->print(&mt('Error: [_1]',$result).'<br />');
3953: }
1.170 albertel 3954: if ($role eq 'st') {
1.202 raeburn 3955: my $result =
1.198 raeburn 3956: &Apache::lonuserutils::classlist_drop($scope,
3957: $env{'form.ccuname'},$env{'form.ccdomain'},
1.202 raeburn 3958: $now);
1.367 golterma 3959: $r->print(&Apache::lonhtmlcommon::confirm_success($result));
1.53 www 3960: }
1.225 raeburn 3961: if (!grep(/^\Q$role\E$/,@rolechanges)) {
3962: push(@rolechanges,$role);
3963: }
1.196 raeburn 3964: }
1.195 raeburn 3965: if ($key=~m{^form\.rev\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}s) {
1.64 www 3966: # Revoke custom role
1.369 bisitz 3967: my $result = &Apache::lonnet::revokecustomrole(
3968: $env{'form.ccdomain'},$env{'form.ccuname'},$1,$2,$3,$4,'','',$context);
1.367 golterma 3969: $r->print(&Apache::lonhtmlcommon::confirm_success(
1.369 bisitz 3970: &mt('Revoking custom role [_1] by [_2] in [_3]',
1.372 raeburn 3971: $4,$3.':'.$2,&Apache::loncommon::show_role_extent($1,$context,'cr')),
1.369 bisitz 3972: $result ne 'ok').'<br />');
3973: if ($result ne "ok") {
3974: $r->print(&mt('Error: [_1]',$result).'<br />');
3975: }
1.225 raeburn 3976: if (!grep(/^cr$/,@rolechanges)) {
3977: push(@rolechanges,'cr');
3978: }
1.64 www 3979: }
1.135 raeburn 3980: } elsif ($key=~/^form\.del/) {
3981: if ($key=~/^form\.del\:([^\_]+)\_([^\_\.]+)$/) {
1.116 raeburn 3982: # Delete standard role
1.170 albertel 3983: my ($scope,$role) = ($1,$2);
3984: my $result =
3985: &Apache::lonnet::assignrole($env{'form.ccdomain'},
3986: $env{'form.ccuname'},
1.239 raeburn 3987: $scope,$role,$now,0,1,'',
3988: $context);
1.367 golterma 3989: $r->print(&Apache::lonhtmlcommon::confirm_success(
3990: &mt('Deleting [_1] in [_2]',
1.369 bisitz 3991: &Apache::lonnet::plaintext($role),
1.372 raeburn 3992: &Apache::loncommon::show_role_extent($scope,$context,$role)),
1.369 bisitz 3993: $result ne 'ok').'<br />');
3994: if ($result ne "ok") {
3995: $r->print(&mt('Error: [_1]',$result).'<br />');
3996: }
1.367 golterma 3997:
1.170 albertel 3998: if ($role eq 'st') {
1.202 raeburn 3999: my $result =
1.198 raeburn 4000: &Apache::lonuserutils::classlist_drop($scope,
4001: $env{'form.ccuname'},$env{'form.ccdomain'},
1.202 raeburn 4002: $now);
1.369 bisitz 4003: $r->print(&Apache::lonhtmlcommon::confirm_success($result));
1.81 albertel 4004: }
1.225 raeburn 4005: if (!grep(/^\Q$role\E$/,@rolechanges)) {
4006: push(@rolechanges,$role);
4007: }
1.116 raeburn 4008: }
1.139 albertel 4009: if ($key=~m{^form\.del\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
1.116 raeburn 4010: my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
4011: # Delete custom role
1.369 bisitz 4012: my $result =
4013: &Apache::lonnet::assigncustomrole($env{'form.ccdomain'},
4014: $env{'form.ccuname'},$url,$rdom,$rnam,$rolename,$now,
4015: 0,1,$context);
4016: $r->print(&Apache::lonhtmlcommon::confirm_success(&mt('Deleting custom role [_1] by [_2] in [_3]',
1.372 raeburn 4017: $rolename,$rnam.':'.$rdom,&Apache::loncommon::show_role_extent($1,$context,'cr')),
1.369 bisitz 4018: $result ne "ok").'<br />');
4019: if ($result ne "ok") {
4020: $r->print(&mt('Error: [_1]',$result).'<br />');
4021: }
1.367 golterma 4022:
1.225 raeburn 4023: if (!grep(/^cr$/,@rolechanges)) {
4024: push(@rolechanges,'cr');
4025: }
1.116 raeburn 4026: }
1.135 raeburn 4027: } elsif ($key=~/^form\.ren/) {
1.101 albertel 4028: my $udom = $env{'form.ccdomain'};
4029: my $uname = $env{'form.ccuname'};
1.116 raeburn 4030: # Re-enable standard role
1.135 raeburn 4031: if ($key=~/^form\.ren\:([^\_]+)\_([^\_\.]+)$/) {
1.89 raeburn 4032: my $url = $1;
4033: my $role = $2;
4034: my $logmsg;
4035: my $output;
4036: if ($role eq 'st') {
1.141 albertel 4037: if ($url =~ m-^/($match_domain)/($match_courseid)/?(\w*)$-) {
1.374 raeburn 4038: my ($cdom,$cnum,$csec) = ($1,$2,$3);
1.375 raeburn 4039: my $credits;
4040: if ($showcredits) {
4041: my $defaultcredits =
4042: &Apache::lonuserutils::get_defaultcredits($cdom,$cnum);
4043: $credits = &get_user_credits($defaultcredits,$cdom,$cnum);
4044: }
4045: my $result = &Apache::loncommon::commit_studentrole(\$logmsg,$udom,$uname,$url,$role,$now,0,$cdom,$cnum,$csec,$context,$credits);
1.220 raeburn 4046: if (($result =~ /^error/) || ($result eq 'not_in_class') || ($result eq 'unknown_course') || ($result eq 'refused')) {
1.223 raeburn 4047: if ($result eq 'refused' && $logmsg) {
4048: $output = $logmsg;
4049: } else {
1.369 bisitz 4050: $output = &mt('Error: [_1]',$result)."\n";
1.223 raeburn 4051: }
1.89 raeburn 4052: } else {
1.372 raeburn 4053: $output = &Apache::lonhtmlcommon::confirm_success(&mt('Assigning [_1] in [_2] starting [_3]',
4054: &Apache::lonnet::plaintext($role),
4055: &Apache::loncommon::show_role_extent($url,$context,'st'),
4056: &Apache::lonlocal::locallocaltime($now))).'<br />'.$logmsg.'<br />';
1.89 raeburn 4057: }
4058: }
4059: } else {
1.101 albertel 4060: my $result=&Apache::lonnet::assignrole($env{'form.ccdomain'},
1.239 raeburn 4061: $env{'form.ccuname'},$url,$role,0,$now,'','',
4062: $context);
1.367 golterma 4063: $output = &Apache::lonhtmlcommon::confirm_success(&mt('Re-enabling [_1] in [_2]',
1.372 raeburn 4064: &Apache::lonnet::plaintext($role),
4065: &Apache::loncommon::show_role_extent($url,$context,$role)),$result ne "ok").'<br />';
1.369 bisitz 4066: if ($result ne "ok") {
4067: $output .= &mt('Error: [_1]',$result).'<br />';
4068: }
4069: }
1.89 raeburn 4070: $r->print($output);
1.225 raeburn 4071: if (!grep(/^\Q$role\E$/,@rolechanges)) {
4072: push(@rolechanges,$role);
4073: }
1.113 raeburn 4074: }
1.116 raeburn 4075: # Re-enable custom role
1.139 albertel 4076: if ($key=~m{^form\.ren\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
1.116 raeburn 4077: my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
4078: my $result = &Apache::lonnet::assigncustomrole(
4079: $env{'form.ccdomain'}, $env{'form.ccuname'},
1.240 raeburn 4080: $url,$rdom,$rnam,$rolename,0,$now,undef,$context);
1.369 bisitz 4081: $r->print(&Apache::lonhtmlcommon::confirm_success(
4082: &mt('Re-enabling custom role [_1] by [_2] in [_3]',
1.372 raeburn 4083: $rolename,$rnam.':'.$rdom,&Apache::loncommon::show_role_extent($1,$context,'cr')),
1.369 bisitz 4084: $result ne "ok").'<br />');
4085: if ($result ne "ok") {
4086: $r->print(&mt('Error: [_1]',$result).'<br />');
4087: }
1.225 raeburn 4088: if (!grep(/^cr$/,@rolechanges)) {
4089: push(@rolechanges,'cr');
4090: }
1.116 raeburn 4091: }
1.135 raeburn 4092: } elsif ($key=~/^form\.act/) {
1.101 albertel 4093: my $udom = $env{'form.ccdomain'};
4094: my $uname = $env{'form.ccuname'};
1.141 albertel 4095: if ($key=~/^form\.act\_($match_domain)\_($match_courseid)\_cr_cr_($match_domain)_($match_username)_([^\_]+)$/) {
1.65 www 4096: # Activate a custom role
1.83 albertel 4097: my ($one,$two,$three,$four,$five)=($1,$2,$3,$4,$5);
4098: my $url='/'.$one.'/'.$two;
4099: my $full=$one.'_'.$two.'_cr_cr_'.$three.'_'.$four.'_'.$five;
1.65 www 4100:
1.101 albertel 4101: my $start = ( $env{'form.start_'.$full} ?
4102: $env{'form.start_'.$full} :
1.88 raeburn 4103: $now );
1.101 albertel 4104: my $end = ( $env{'form.end_'.$full} ?
4105: $env{'form.end_'.$full} :
1.88 raeburn 4106: 0 );
4107:
4108: # split multiple sections
4109: my %sections = ();
1.101 albertel 4110: my $num_sections = &build_roles($env{'form.sec_'.$full},\%sections,$5);
1.88 raeburn 4111: if ($num_sections == 0) {
1.240 raeburn 4112: $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$url,$three,$four,$five,$start,$end,$context));
1.88 raeburn 4113: } else {
1.114 albertel 4114: my %curr_groups =
1.117 raeburn 4115: &Apache::longroup::coursegroups($one,$two);
1.404 raeburn 4116: foreach my $sec (sort {$a cmp $b} keys(%sections)) {
1.113 raeburn 4117: if (($sec eq 'none') || ($sec eq 'all') ||
4118: exists($curr_groups{$sec})) {
4119: $disallowed{$sec} = $url;
4120: next;
4121: }
4122: my $securl = $url.'/'.$sec;
1.240 raeburn 4123: $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$securl,$three,$four,$five,$start,$end,$context));
1.88 raeburn 4124: }
4125: }
1.225 raeburn 4126: if (!grep(/^cr$/,@rolechanges)) {
4127: push(@rolechanges,'cr');
4128: }
1.142 raeburn 4129: } elsif ($key=~/^form\.act\_($match_domain)\_($match_name)\_([^\_]+)$/) {
1.27 matthew 4130: # Activate roles for sections with 3 id numbers
4131: # set start, end times, and the url for the class
1.83 albertel 4132: my ($one,$two,$three)=($1,$2,$3);
1.101 albertel 4133: my $start = ( $env{'form.start_'.$one.'_'.$two.'_'.$three} ?
4134: $env{'form.start_'.$one.'_'.$two.'_'.$three} :
1.27 matthew 4135: $now );
1.101 albertel 4136: my $end = ( $env{'form.end_'.$one.'_'.$two.'_'.$three} ?
4137: $env{'form.end_'.$one.'_'.$two.'_'.$three} :
1.27 matthew 4138: 0 );
1.83 albertel 4139: my $url='/'.$one.'/'.$two;
1.88 raeburn 4140: my $type = 'three';
4141: # split multiple sections
4142: my %sections = ();
1.101 albertel 4143: my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two.'_'.$three},\%sections,$three);
1.375 raeburn 4144: my $credits;
4145: if ($three eq 'st') {
4146: if ($showcredits) {
4147: my $defaultcredits =
4148: &Apache::lonuserutils::get_defaultcredits($one,$two);
4149: $credits = $env{'form.credits_'.$one.'_'.$two.'_'.$three};
4150: $credits =~ s/[^\d\.]//g;
4151: if ($credits eq $defaultcredits) {
4152: undef($credits);
4153: }
4154: }
4155: }
1.88 raeburn 4156: if ($num_sections == 0) {
1.375 raeburn 4157: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'',$context,$credits));
1.88 raeburn 4158: } else {
1.114 albertel 4159: my %curr_groups =
1.117 raeburn 4160: &Apache::longroup::coursegroups($one,$two);
1.88 raeburn 4161: my $emptysec = 0;
1.404 raeburn 4162: foreach my $sec (sort {$a cmp $b} keys(%sections)) {
1.88 raeburn 4163: $sec =~ s/\W//g;
1.113 raeburn 4164: if ($sec ne '') {
4165: if (($sec eq 'none') || ($sec eq 'all') ||
4166: exists($curr_groups{$sec})) {
4167: $disallowed{$sec} = $url;
4168: next;
4169: }
1.88 raeburn 4170: my $securl = $url.'/'.$sec;
1.375 raeburn 4171: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$three,$start,$end,$one,$two,$sec,$context,$credits));
1.88 raeburn 4172: } else {
4173: $emptysec = 1;
4174: }
4175: }
4176: if ($emptysec) {
1.375 raeburn 4177: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'',$context,$credits));
1.88 raeburn 4178: }
1.225 raeburn 4179: }
4180: if (!grep(/^\Q$three\E$/,@rolechanges)) {
4181: push(@rolechanges,$three);
4182: }
1.135 raeburn 4183: } elsif ($key=~/^form\.act\_([^\_]+)\_([^\_]+)$/) {
1.27 matthew 4184: # Activate roles for sections with two id numbers
4185: # set start, end times, and the url for the class
1.101 albertel 4186: my $start = ( $env{'form.start_'.$1.'_'.$2} ?
4187: $env{'form.start_'.$1.'_'.$2} :
1.27 matthew 4188: $now );
1.101 albertel 4189: my $end = ( $env{'form.end_'.$1.'_'.$2} ?
4190: $env{'form.end_'.$1.'_'.$2} :
1.27 matthew 4191: 0 );
1.225 raeburn 4192: my $one = $1;
4193: my $two = $2;
4194: my $url='/'.$one.'/';
1.88 raeburn 4195: # split multiple sections
4196: my %sections = ();
1.225 raeburn 4197: my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two},\%sections,$two);
1.88 raeburn 4198: if ($num_sections == 0) {
1.240 raeburn 4199: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,'',$context));
1.88 raeburn 4200: } else {
4201: my $emptysec = 0;
1.404 raeburn 4202: foreach my $sec (sort {$a cmp $b} keys(%sections)) {
1.88 raeburn 4203: if ($sec ne '') {
4204: my $securl = $url.'/'.$sec;
1.240 raeburn 4205: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$two,$start,$end,$one,undef,$sec,$context));
1.88 raeburn 4206: } else {
4207: $emptysec = 1;
4208: }
4209: }
4210: if ($emptysec) {
1.240 raeburn 4211: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,'',$context));
1.88 raeburn 4212: }
4213: }
1.225 raeburn 4214: if (!grep(/^\Q$two\E$/,@rolechanges)) {
4215: push(@rolechanges,$two);
4216: }
1.64 www 4217: } else {
1.190 raeburn 4218: $r->print('<p><span class="LC_error">'.&mt('ERROR').': '.&mt('Unknown command').' <tt>'.$key.'</tt></span></p><br />');
1.64 www 4219: }
1.113 raeburn 4220: foreach my $key (sort(keys(%disallowed))) {
1.274 bisitz 4221: $r->print('<p class="LC_warning">');
1.113 raeburn 4222: if (($key eq 'none') || ($key eq 'all')) {
1.274 bisitz 4223: $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 4224: } else {
1.274 bisitz 4225: $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 4226: }
1.274 bisitz 4227: $r->print('</p><p>'
4228: .&mt('Please [_1]go back[_2] and choose a different section name.'
4229: ,'<a href="javascript:history.go(-1)'
4230: ,'</a>')
4231: .'</p><br />'
4232: );
1.113 raeburn 4233: }
4234: }
1.101 albertel 4235: } # End of foreach (keys(%env))
1.75 www 4236: # Flush the course logs so reverse user roles immediately updated
1.349 raeburn 4237: $r->register_cleanup(\&Apache::lonnet::flushcourselogs);
1.225 raeburn 4238: if (@rolechanges == 0) {
1.372 raeburn 4239: $r->print('<p>'.&mt('No roles to modify').'</p>');
1.193 raeburn 4240: }
1.225 raeburn 4241: return @rolechanges;
1.220 raeburn 4242: }
4243:
1.375 raeburn 4244: sub get_user_credits {
4245: my ($uname,$udom,$defaultcredits,$cdom,$cnum) = @_;
4246: if ($cdom eq '' || $cnum eq '') {
4247: return unless ($env{'request.course.id'});
4248: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
4249: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
4250: }
4251: my $credits;
4252: my %currhash =
4253: &Apache::lonnet::get('classlist',[$uname.':'.$udom],$cdom,$cnum);
4254: if (keys(%currhash) > 0) {
4255: my @items = split(/:/,$currhash{$uname.':'.$udom});
4256: my $crdidx = &Apache::loncoursedata::CL_CREDITS() - 3;
4257: $credits = $items[$crdidx];
4258: $credits =~ s/[^\d\.]//g;
4259: }
4260: if ($credits eq $defaultcredits) {
4261: undef($credits);
4262: }
4263: return $credits;
4264: }
4265:
1.220 raeburn 4266: sub enroll_single_student {
1.375 raeburn 4267: my ($r,$uhome,$amode,$genpwd,$now,$newuser,$context,$crstype,
4268: $showcredits,$defaultcredits) = @_;
1.318 raeburn 4269: $r->print('<h3>');
4270: if ($crstype eq 'Community') {
4271: $r->print(&mt('Enrolling Member'));
4272: } else {
4273: $r->print(&mt('Enrolling Student'));
4274: }
4275: $r->print('</h3>');
1.220 raeburn 4276:
4277: # Remove non alphanumeric values from section
4278: $env{'form.sections'}=~s/\W//g;
4279:
1.375 raeburn 4280: my $credits;
4281: if (($showcredits) && ($env{'form.credits'} ne '')) {
4282: $credits = $env{'form.credits'};
4283: $credits =~ s/[^\d\.]//g;
4284: if ($credits ne '') {
4285: if ($credits eq $defaultcredits) {
4286: undef($credits);
4287: }
4288: }
4289: }
4290:
1.220 raeburn 4291: # Clean out any old student roles the user has in this class.
4292: &Apache::lonuserutils::modifystudent($env{'form.ccdomain'},
4293: $env{'form.ccuname'},$env{'request.course.id'},undef,$uhome);
4294: my ($startdate,$enddate) = &Apache::lonuserutils::get_dates_from_form();
4295: my $enroll_result =
4296: &Apache::lonnet::modify_student_enrollment($env{'form.ccdomain'},
4297: $env{'form.ccuname'},$env{'form.cid'},$env{'form.cfirstname'},
4298: $env{'form.cmiddlename'},$env{'form.clastname'},
4299: $env{'form.generation'},$env{'form.sections'},$enddate,
1.375 raeburn 4300: $startdate,'manual',undef,$env{'request.course.id'},'',$context,
4301: $credits);
1.220 raeburn 4302: if ($enroll_result =~ /^ok/) {
1.381 bisitz 4303: $r->print(&mt('[_1] enrolled','<b>'.$env{'form.ccuname'}.':'.$env{'form.ccdomain'}.'</b>'));
1.220 raeburn 4304: if ($env{'form.sections'} ne '') {
4305: $r->print(' '.&mt('in section [_1]',$env{'form.sections'}));
4306: }
4307: my ($showstart,$showend);
4308: if ($startdate <= $now) {
4309: $showstart = &mt('Access starts immediately');
4310: } else {
4311: $showstart = &mt('Access starts: ').&Apache::lonlocal::locallocaltime($startdate);
4312: }
4313: if ($enddate == 0) {
4314: $showend = &mt('ends: no ending date');
4315: } else {
4316: $showend = &mt('ends: ').&Apache::lonlocal::locallocaltime($enddate);
4317: }
4318: $r->print('.<br />'.$showstart.'; '.$showend);
4319: if ($startdate <= $now && !$newuser) {
1.386 bisitz 4320: $r->print('<p class="LC_info">');
1.318 raeburn 4321: if ($crstype eq 'Community') {
1.392 raeburn 4322: $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 4323: } else {
1.392 raeburn 4324: $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 4325: }
4326: $r->print('</p>');
1.220 raeburn 4327: }
4328: } else {
4329: $r->print(&mt('unable to enroll').": ".$enroll_result);
4330: }
4331: return;
1.188 raeburn 4332: }
4333:
1.204 raeburn 4334: sub get_defaultquota_text {
4335: my ($settingstatus) = @_;
4336: my $defquotatext;
4337: if ($settingstatus eq '') {
1.383 raeburn 4338: $defquotatext = &mt('default');
1.204 raeburn 4339: } else {
4340: my ($usertypes,$order) =
4341: &Apache::lonnet::retrieve_inst_usertypes($env{'form.ccdomain'});
4342: if ($usertypes->{$settingstatus} eq '') {
1.383 raeburn 4343: $defquotatext = &mt('default');
1.204 raeburn 4344: } else {
1.383 raeburn 4345: $defquotatext = &mt('default for [_1]',$usertypes->{$settingstatus});
1.204 raeburn 4346: }
4347: }
4348: return $defquotatext;
4349: }
4350:
1.188 raeburn 4351: sub update_result_form {
4352: my ($uhome) = @_;
4353: my $outcome =
1.367 golterma 4354: '<form name="userupdate" method="post" action="">'."\n";
1.160 raeburn 4355: foreach my $item ('srchby','srchin','srchtype','srchterm','srchdomain','ccuname','ccdomain') {
1.188 raeburn 4356: $outcome .= '<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n";
1.160 raeburn 4357: }
1.207 raeburn 4358: if ($env{'form.origname'} ne '') {
4359: $outcome .= '<input type="hidden" name="origname" value="'.$env{'form.origname'}.'" />'."\n";
4360: }
1.160 raeburn 4361: foreach my $item ('sortby','seluname','seludom') {
4362: if (exists($env{'form.'.$item})) {
1.188 raeburn 4363: $outcome .= '<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n";
1.160 raeburn 4364: }
4365: }
1.188 raeburn 4366: if ($uhome eq 'no_host') {
4367: $outcome .= '<input type="hidden" name="forcenewuser" value="1" />'."\n";
4368: }
4369: $outcome .= '<input type="hidden" name="phase" value="" />'."\n".
1.383 raeburn 4370: '<input type="hidden" name="currstate" value="" />'."\n".
4371: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n".
1.188 raeburn 4372: '</form>';
4373: return $outcome;
1.4 www 4374: }
4375:
1.149 raeburn 4376: sub quota_admin {
1.378 raeburn 4377: my ($setquota,$changeHash,$name) = @_;
1.149 raeburn 4378: my $quotachanged;
4379: if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
4380: # Current user has quota modification privileges
1.267 raeburn 4381: if (ref($changeHash) eq 'HASH') {
4382: $quotachanged = 1;
1.378 raeburn 4383: $changeHash->{$name.'quota'} = $setquota;
1.267 raeburn 4384: }
1.149 raeburn 4385: }
4386: return $quotachanged;
4387: }
4388:
1.267 raeburn 4389: sub tool_admin {
1.275 raeburn 4390: my ($tool,$settool,$changeHash,$context) = @_;
4391: my $canchange = 0;
1.279 raeburn 4392: if ($context eq 'requestcourses') {
1.275 raeburn 4393: if (&Apache::lonnet::allowed('ccc',$env{'form.ccdomain'})) {
4394: $canchange = 1;
4395: }
1.300 raeburn 4396: } elsif ($context eq 'reqcrsotherdom') {
4397: if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
4398: $canchange = 1;
4399: }
1.362 raeburn 4400: } elsif ($context eq 'requestauthor') {
4401: if (&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) {
4402: $canchange = 1;
4403: }
1.275 raeburn 4404: } elsif (&Apache::lonnet::allowed('mut',$env{'form.ccdomain'})) {
4405: # Current user has quota modification privileges
4406: $canchange = 1;
4407: }
1.267 raeburn 4408: my $toolchanged;
1.275 raeburn 4409: if ($canchange) {
1.267 raeburn 4410: if (ref($changeHash) eq 'HASH') {
4411: $toolchanged = 1;
1.362 raeburn 4412: if ($tool eq 'requestauthor') {
4413: $changeHash->{$context} = $settool;
4414: } else {
4415: $changeHash->{$context.'.'.$tool} = $settool;
4416: }
1.267 raeburn 4417: }
4418: }
4419: return $toolchanged;
4420: }
4421:
1.88 raeburn 4422: sub build_roles {
1.89 raeburn 4423: my ($sectionstr,$sections,$role) = @_;
1.88 raeburn 4424: my $num_sections = 0;
4425: if ($sectionstr=~ /,/) {
4426: my @secnums = split/,/,$sectionstr;
1.89 raeburn 4427: if ($role eq 'st') {
4428: $secnums[0] =~ s/\W//g;
4429: $$sections{$secnums[0]} = 1;
4430: $num_sections = 1;
4431: } else {
4432: foreach my $sec (@secnums) {
4433: $sec =~ ~s/\W//g;
1.150 banghart 4434: if (!($sec eq "")) {
1.89 raeburn 4435: if (exists($$sections{$sec})) {
4436: $$sections{$sec} ++;
4437: } else {
4438: $$sections{$sec} = 1;
4439: $num_sections ++;
4440: }
1.88 raeburn 4441: }
4442: }
4443: }
4444: } else {
4445: $sectionstr=~s/\W//g;
4446: unless ($sectionstr eq '') {
4447: $$sections{$sectionstr} = 1;
4448: $num_sections ++;
4449: }
4450: }
1.129 albertel 4451:
1.88 raeburn 4452: return $num_sections;
4453: }
4454:
1.58 www 4455: # ========================================================== Custom Role Editor
4456:
4457: sub custom_role_editor {
1.414 raeburn 4458: my ($r,$brcrum,$prefix) = @_;
1.324 raeburn 4459: my $action = $env{'form.customroleaction'};
4460: my $rolename;
4461: if ($action eq 'new') {
4462: $rolename=$env{'form.newrolename'};
4463: } else {
4464: $rolename=$env{'form.rolename'};
1.59 www 4465: }
4466:
1.324 raeburn 4467: my ($crstype,$context);
4468: if ($env{'request.course.id'}) {
4469: $crstype = &Apache::loncommon::course_type();
4470: $context = 'course';
4471: } else {
4472: $context = 'domain';
1.414 raeburn 4473: $crstype = 'course';
1.324 raeburn 4474: }
1.351 raeburn 4475:
4476: $rolename=~s/[^A-Za-z0-9]//gs;
4477: if (!$rolename || $env{'form.phase'} eq 'pickrole') {
4478: &print_username_entry_form($r,undef,undef,undef,undef,$crstype,$brcrum);
4479: return;
4480: }
4481:
1.414 raeburn 4482: my $formname = 'form1';
4483: my %privs=();
4484: my $body_top = '<h2>';
4485: # ------------------------------------------------------- Does this role exist?
1.59 www 4486: my ($rdummy,$roledef)=
4487: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
4488: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1.414 raeburn 4489: $body_top .= &mt('Existing Role').' "';
1.61 www 4490: # ------------------------------------------------- Get current role privileges
1.414 raeburn 4491: ($privs{'system'},$privs{'domain'},$privs{'course'})=split(/\_/,$roledef);
4492: if ($privs{'system'} =~ /bre\&S/) {
4493: if ($context eq 'domain') {
1.417 raeburn 4494: $crstype = 'Course';
1.414 raeburn 4495: } elsif ($crstype eq 'Community') {
4496: $privs{'system'} =~ s/bre\&S//;
4497: }
4498: } elsif ($context eq 'domain') {
4499: $crstype = 'Course';
1.324 raeburn 4500: }
1.59 www 4501: } else {
1.414 raeburn 4502: $body_top .= &mt('New Role').' "';
4503: $roledef='';
1.59 www 4504: }
1.153 banghart 4505: $body_top .= $rolename.'"</h2>';
1.414 raeburn 4506:
4507: # ------------------------------------------------------- What can be assigned?
4508: my %full=();
1.417 raeburn 4509: my %levels=(
1.414 raeburn 4510: course => {},
4511: domain => {},
4512: system => {},
4513: );
4514: my %levelscurrent=(
4515: course => {},
4516: domain => {},
4517: system => {},
4518: );
4519: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
1.160 raeburn 4520: my ($jsback,$elements) = &crumb_utilities();
1.414 raeburn 4521: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
1.417 raeburn 4522: my $head_script =
1.414 raeburn 4523: &Apache::lonuserutils::custom_roledefs_js($context,$crstype,$formname,
4524: \%full,\@templateroles,$jsback);
1.351 raeburn 4525: push (@{$brcrum},
1.414 raeburn 4526: {href => "javascript:backPage(document.$formname,'pickrole','')",
1.351 raeburn 4527: text => "Pick custom role",
4528: faq => 282,bug=>'Instructor Interface',},
1.414 raeburn 4529: {href => "javascript:backPage(document.$formname,'','')",
1.351 raeburn 4530: text => "Edit custom role",
4531: faq => 282,
4532: bug => 'Instructor Interface',
4533: help => 'Course_Editing_Custom_Roles'}
4534: );
4535: my $args = { bread_crumbs => $brcrum,
4536: bread_crumbs_component => 'User Management'};
4537:
4538: $r->print(&Apache::loncommon::start_page('Custom Role Editor',
4539: $head_script,$args).
4540: $body_top);
1.414 raeburn 4541: $r->print('<form name="'.$formname.'" method="post" action="">'."\n".
4542: &Apache::lonuserutils::custom_role_header($context,$crstype,
4543: \@templateroles,$prefix));
1.264 bisitz 4544:
1.61 www 4545: $r->print(<<ENDCCF);
4546: <input type="hidden" name="phase" value="set_custom_roles" />
4547: <input type="hidden" name="rolename" value="$rolename" />
4548: ENDCCF
1.414 raeburn 4549: $r->print(&Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
4550: \%levelscurrent,$prefix));
1.135 raeburn 4551: $r->print(&Apache::loncommon::end_data_table().
1.190 raeburn 4552: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'.
1.160 raeburn 4553: '<input type="hidden" name="startrolename" value="'.$env{'form.rolename'}.
1.417 raeburn 4554: '" />'."\n".'<input type="hidden" name="currstate" value="" />'."\n".
1.160 raeburn 4555: '<input type="reset" value="'.&mt("Reset").'" />'."\n".
1.351 raeburn 4556: '<input type="submit" value="'.&mt('Save').'" /></form>');
1.61 www 4557: }
1.414 raeburn 4558:
1.61 www 4559: # ---------------------------------------------------------- Call to definerole
4560: sub set_custom_role {
1.414 raeburn 4561: my ($r,$context,$brcrum,$prefix) = @_;
1.101 albertel 4562: my $rolename=$env{'form.rolename'};
1.63 www 4563: $rolename=~s/[^A-Za-z0-9]//gs;
1.150 banghart 4564: if (!$rolename) {
1.414 raeburn 4565: &custom_role_editor($r,$brcrum,$prefix);
1.61 www 4566: return;
4567: }
1.160 raeburn 4568: my ($jsback,$elements) = &crumb_utilities();
1.301 bisitz 4569: my $jscript = '<script type="text/javascript">'
4570: .'// <![CDATA['."\n"
4571: .$jsback."\n"
4572: .'// ]]>'."\n"
4573: .'</script>'."\n";
1.352 raeburn 4574: push(@{$brcrum},
4575: {href => "javascript:backPage(document.customresult,'pickrole','')",
4576: text => "Pick custom role",
4577: faq => 282,
4578: bug => 'Instructor Interface',},
4579: {href => "javascript:backPage(document.customresult,'selected_custom_edit','')",
4580: text => "Edit custom role",
4581: faq => 282,
4582: bug => 'Instructor Interface',},
4583: {href => "javascript:backPage(document.customresult,'set_custom_roles','')",
4584: text => "Result",
4585: faq => 282,
4586: bug => 'Instructor Interface',
4587: help => 'Course_Editing_Custom_Roles'},
4588: );
4589: my $args = { bread_crumbs => $brcrum,
1.414 raeburn 4590: bread_crumbs_component => 'User Management'};
1.351 raeburn 4591: $r->print(&Apache::loncommon::start_page('Save Custom Role',$jscript,$args));
1.160 raeburn 4592:
1.393 raeburn 4593: my $newrole;
1.61 www 4594: my ($rdummy,$roledef)=
1.110 albertel 4595: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
4596:
1.61 www 4597: # ------------------------------------------------------- Does this role exist?
1.188 raeburn 4598: $r->print('<h3>');
1.61 www 4599: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1.73 sakharuk 4600: $r->print(&mt('Existing Role').' "');
1.61 www 4601: } else {
1.73 sakharuk 4602: $r->print(&mt('New Role').' "');
1.61 www 4603: $roledef='';
1.393 raeburn 4604: $newrole = 1;
1.61 www 4605: }
1.188 raeburn 4606: $r->print($rolename.'"</h3>');
1.414 raeburn 4607: # ------------------------------------------------- Assign role and show result
1.61 www 4608:
1.387 bisitz 4609: my $errmsg;
1.414 raeburn 4610: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$prefix);
4611: # Assign role and return result
4612: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
4613: $newprivs{'c'});
1.387 bisitz 4614: if ($result ne 'ok') {
4615: $errmsg = ': '.$result;
4616: }
4617: my $message =
4618: &Apache::lonhtmlcommon::confirm_success(
4619: &mt('Defining Role').$errmsg, ($result eq 'ok' ? 0 : 1));
1.101 albertel 4620: if ($env{'request.course.id'}) {
4621: my $url='/'.$env{'request.course.id'};
1.63 www 4622: $url=~s/\_/\//g;
1.387 bisitz 4623: $result =
4624: &Apache::lonnet::assigncustomrole(
4625: $env{'user.domain'},$env{'user.name'},
4626: $url,
4627: $env{'user.domain'},$env{'user.name'},
4628: $rolename,undef,undef,undef,$context);
4629: if ($result ne 'ok') {
4630: $errmsg = ': '.$result;
4631: }
4632: $message .=
4633: '<br />'
4634: .&Apache::lonhtmlcommon::confirm_success(
4635: &mt('Assigning Role to Self').$errmsg, ($result eq 'ok' ? 0 : 1));
1.63 www 4636: }
1.380 bisitz 4637: $r->print(
1.387 bisitz 4638: &Apache::loncommon::confirmwrapper($message)
4639: .'<br />'
4640: .&Apache::lonhtmlcommon::actionbox([
4641: '<a href="javascript:backPage(document.customresult,'."'pickrole'".')">'
4642: .&mt('Create or edit another custom role')
4643: .'</a>'])
1.380 bisitz 4644: .'<form name="customresult" method="post" action="">'
1.387 bisitz 4645: .&Apache::lonhtmlcommon::echo_form_input([])
4646: .'</form>'
1.380 bisitz 4647: );
1.58 www 4648: }
4649:
1.2 www 4650: # ================================================================ Main Handler
4651: sub handler {
4652: my $r = shift;
4653: if ($r->header_only) {
1.68 www 4654: &Apache::loncommon::content_type($r,'text/html');
1.2 www 4655: $r->send_http_header;
4656: return OK;
4657: }
1.318 raeburn 4658: my ($context,$crstype);
1.190 raeburn 4659: if ($env{'request.course.id'}) {
4660: $context = 'course';
1.318 raeburn 4661: $crstype = &Apache::loncommon::course_type();
1.190 raeburn 4662: } elsif ($env{'request.role'} =~ /^au\./) {
1.206 raeburn 4663: $context = 'author';
1.190 raeburn 4664: } else {
4665: $context = 'domain';
4666: }
1.375 raeburn 4667:
1.190 raeburn 4668: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.233 raeburn 4669: ['action','state','callingform','roletype','showrole','bulkaction','popup','phase',
1.391 raeburn 4670: 'username','domain','srchterm','srchdomain','srchin','srchby','srchtype','queue']);
1.190 raeburn 4671: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.351 raeburn 4672: my $args;
4673: my $brcrum = [];
4674: my $bread_crumbs_component = 'User Management';
1.391 raeburn 4675: if (($env{'form.action'} ne 'dateselect') && ($env{'form.action'} ne 'displayuserreq')) {
1.351 raeburn 4676: $brcrum = [{href=>"/adm/createuser",
4677: text=>"User Management",
4678: 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'}
4679: ];
1.202 raeburn 4680: }
1.289 droeschl 4681: #SD Following files not added to help, because the corresponding .tex-files seem to
4682: #be missing: Course_Approve_Selfenroll,Course_User_Logs,
1.209 raeburn 4683: my ($permission,$allowed) =
1.318 raeburn 4684: &Apache::lonuserutils::get_permission($context,$crstype);
1.190 raeburn 4685: if (!$allowed) {
1.358 raeburn 4686: if ($context eq 'course') {
4687: $r->internal_redirect('/adm/viewclasslist');
4688: return OK;
4689: }
1.190 raeburn 4690: $env{'user.error.msg'}=
4691: "/adm/createuser:cst:0:0:Cannot create/modify user data ".
4692: "or view user status.";
4693: return HTTP_NOT_ACCEPTABLE;
4694: }
4695:
4696: &Apache::loncommon::content_type($r,'text/html');
4697: $r->send_http_header;
4698:
1.375 raeburn 4699: my $showcredits;
4700: if ((($context eq 'course') && ($crstype eq 'Course')) ||
4701: ($context eq 'domain')) {
4702: my %domdefaults =
4703: &Apache::lonnet::get_domain_defaults($env{'request.role.domain'});
4704: if ($domdefaults{'officialcredits'} || $domdefaults{'unofficialcredits'}) {
4705: $showcredits = 1;
4706: }
4707: }
4708:
1.190 raeburn 4709: # Main switch on form.action and form.state, as appropriate
4710: if (! exists($env{'form.action'})) {
1.351 raeburn 4711: $args = {bread_crumbs => $brcrum,
4712: bread_crumbs_component => $bread_crumbs_component};
4713: $r->print(&header(undef,$args));
1.318 raeburn 4714: $r->print(&print_main_menu($permission,$context,$crstype));
1.190 raeburn 4715: } elsif ($env{'form.action'} eq 'upload' && $permission->{'cusr'}) {
1.351 raeburn 4716: push(@{$brcrum},
4717: { href => '/adm/createuser?action=upload&state=',
4718: text => 'Upload Users List',
4719: help => 'Course_Create_Class_List',
4720: });
4721: $bread_crumbs_component = 'Upload Users List';
4722: $args = {bread_crumbs => $brcrum,
4723: bread_crumbs_component => $bread_crumbs_component};
4724: $r->print(&header(undef,$args));
1.190 raeburn 4725: $r->print('<form name="studentform" method="post" '.
4726: 'enctype="multipart/form-data" '.
4727: ' action="/adm/createuser">'."\n");
4728: if (! exists($env{'form.state'})) {
4729: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
4730: } elsif ($env{'form.state'} eq 'got_file') {
1.375 raeburn 4731: &Apache::lonuserutils::print_upload_manager_form($r,$context,$permission,
4732: $crstype,$showcredits);
1.190 raeburn 4733: } elsif ($env{'form.state'} eq 'enrolling') {
4734: if ($env{'form.datatoken'}) {
1.375 raeburn 4735: &Apache::lonuserutils::upfile_drop_add($r,$context,$permission,
4736: $showcredits);
1.190 raeburn 4737: }
4738: } else {
4739: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
4740: }
1.416 raeburn 4741: } elsif (((($env{'form.action'} eq 'singleuser') || ($env{'form.action'}
4742: eq 'singlestudent')) && ($permission->{'cusr'})) ||
1.418 raeburn 4743: (($env{'form.action'} eq 'singleuser') && ($permission->{'view'})) ||
1.416 raeburn 4744: (($env{'form.action'} eq 'accesslogs') && ($permission->{'activity'}))) {
1.190 raeburn 4745: my $phase = $env{'form.phase'};
4746: my @search = ('srchterm','srchby','srchin','srchtype','srchdomain');
1.192 albertel 4747: &Apache::loncreateuser::restore_prev_selections();
4748: my $srch;
4749: foreach my $item (@search) {
4750: $srch->{$item} = $env{'form.'.$item};
4751: }
1.207 raeburn 4752: if (($phase eq 'get_user_info') || ($phase eq 'userpicked') ||
1.416 raeburn 4753: ($phase eq 'createnewuser') || ($phase eq 'activity')) {
1.207 raeburn 4754: if ($env{'form.phase'} eq 'createnewuser') {
4755: my $response;
4756: if ($env{'form.srchterm'} !~ /^$match_username$/) {
1.366 bisitz 4757: my $response =
4758: '<span class="LC_warning">'
4759: .&mt('You must specify a valid username. Only the following are allowed:'
4760: .' letters numbers - . @')
4761: .'</span>';
1.221 raeburn 4762: $env{'form.phase'} = '';
1.375 raeburn 4763: &print_username_entry_form($r,$context,$response,$srch,undef,
4764: $crstype,$brcrum,$showcredits);
1.207 raeburn 4765: } else {
4766: my $ccuname =&LONCAPA::clean_username($srch->{'srchterm'});
4767: my $ccdomain=&LONCAPA::clean_domain($srch->{'srchdomain'});
4768: &print_user_modification_page($r,$ccuname,$ccdomain,
1.221 raeburn 4769: $srch,$response,$context,
1.375 raeburn 4770: $permission,$crstype,$brcrum,
4771: $showcredits);
1.207 raeburn 4772: }
4773: } elsif ($env{'form.phase'} eq 'get_user_info') {
1.190 raeburn 4774: my ($currstate,$response,$forcenewuser,$results) =
1.221 raeburn 4775: &user_search_result($context,$srch);
1.190 raeburn 4776: if ($env{'form.currstate'} eq 'modify') {
4777: $currstate = $env{'form.currstate'};
4778: }
4779: if ($currstate eq 'select') {
4780: &print_user_selection_page($r,$response,$srch,$results,
1.351 raeburn 4781: \@search,$context,undef,$crstype,
4782: $brcrum);
1.416 raeburn 4783: } elsif (($currstate eq 'modify') || ($env{'form.action'} eq 'accesslogs')) {
4784: my ($ccuname,$ccdomain,$uhome);
1.190 raeburn 4785: if (($srch->{'srchby'} eq 'uname') &&
4786: ($srch->{'srchtype'} eq 'exact')) {
4787: $ccuname = $srch->{'srchterm'};
4788: $ccdomain= $srch->{'srchdomain'};
4789: } else {
4790: my @matchedunames = keys(%{$results});
4791: ($ccuname,$ccdomain) = split(/:/,$matchedunames[0]);
4792: }
4793: $ccuname =&LONCAPA::clean_username($ccuname);
4794: $ccdomain=&LONCAPA::clean_domain($ccdomain);
1.416 raeburn 4795: if ($env{'form.action'} eq 'accesslogs') {
4796: my $uhome;
4797: if (($ccuname ne '') && ($ccdomain ne '')) {
4798: $uhome = &Apache::lonnet::homeserver($ccuname,$ccdomain);
4799: }
4800: if (($uhome eq '') || ($uhome eq 'no_host')) {
4801: $env{'form.phase'} = '';
4802: undef($forcenewuser);
4803: #if ($response) {
4804: # unless ($response =~ m{\Q<br /><br />\E$}) {
4805: # $response .= '<br /><br />';
4806: # }
4807: #}
4808: &print_username_entry_form($r,$context,$response,$srch,
4809: $forcenewuser,$crstype,$brcrum);
4810: } else {
4811: &print_useraccesslogs_display($r,$ccuname,$ccdomain,$permission,$brcrum);
4812: }
4813: } else {
4814: if ($env{'form.forcenewuser'}) {
4815: $response = '';
4816: }
4817: &print_user_modification_page($r,$ccuname,$ccdomain,
4818: $srch,$response,$context,
4819: $permission,$crstype,$brcrum);
1.190 raeburn 4820: }
4821: } elsif ($currstate eq 'query') {
1.351 raeburn 4822: &print_user_query_page($r,'createuser',$brcrum);
1.190 raeburn 4823: } else {
1.229 raeburn 4824: $env{'form.phase'} = '';
1.207 raeburn 4825: &print_username_entry_form($r,$context,$response,$srch,
1.351 raeburn 4826: $forcenewuser,$crstype,$brcrum);
1.190 raeburn 4827: }
4828: } elsif ($env{'form.phase'} eq 'userpicked') {
4829: my $ccuname = &LONCAPA::clean_username($env{'form.seluname'});
4830: my $ccdomain = &LONCAPA::clean_domain($env{'form.seludom'});
1.416 raeburn 4831: if ($env{'form.action'} eq 'accesslogs') {
4832: &print_useraccesslogs_display($r,$ccuname,$ccdomain,$permission,$brcrum);
4833: } else {
4834: &print_user_modification_page($r,$ccuname,$ccdomain,$srch,'',
4835: $context,$permission,$crstype,
4836: $brcrum);
4837: }
4838: } elsif ($env{'form.action'} eq 'accesslogs') {
4839: my $ccuname = &LONCAPA::clean_username($env{'form.accessuname'});
4840: my $ccdomain = &LONCAPA::clean_domain($env{'form.accessudom'});
4841: &print_useraccesslogs_display($r,$ccuname,$ccdomain,$permission,$brcrum);
1.190 raeburn 4842: }
4843: } elsif ($env{'form.phase'} eq 'update_user_data') {
1.375 raeburn 4844: &update_user_data($r,$context,$crstype,$brcrum,$showcredits);
1.190 raeburn 4845: } else {
1.351 raeburn 4846: &print_username_entry_form($r,$context,undef,$srch,undef,$crstype,
4847: $brcrum);
1.190 raeburn 4848: }
4849: } elsif ($env{'form.action'} eq 'custom' && $permission->{'custom'}) {
1.414 raeburn 4850: my $prefix;
1.190 raeburn 4851: if ($env{'form.phase'} eq 'set_custom_roles') {
1.414 raeburn 4852: &set_custom_role($r,$context,$brcrum,$prefix);
1.190 raeburn 4853: } else {
1.414 raeburn 4854: &custom_role_editor($r,$brcrum,$prefix);
1.190 raeburn 4855: }
1.362 raeburn 4856: } elsif (($env{'form.action'} eq 'processauthorreq') &&
4857: ($permission->{'cusr'}) &&
4858: (&Apache::lonnet::allowed('cau',$env{'request.role.domain'}))) {
4859: push(@{$brcrum},
4860: {href => '/adm/createuser?action=processauthorreq',
1.385 bisitz 4861: text => 'Authoring Space requests',
1.362 raeburn 4862: help => 'Domain_Role_Approvals'});
4863: $bread_crumbs_component = 'Authoring requests';
4864: if ($env{'form.state'} eq 'done') {
4865: push(@{$brcrum},
4866: {href => '/adm/createuser?action=authorreqqueue',
4867: text => 'Result',
4868: help => 'Domain_Role_Approvals'});
4869: $bread_crumbs_component = 'Authoring request result';
4870: }
4871: $args = { bread_crumbs => $brcrum,
4872: bread_crumbs_component => $bread_crumbs_component};
1.391 raeburn 4873: my $js = &usernamerequest_javascript();
4874: $r->print(&header(&add_script($js),$args));
1.362 raeburn 4875: if (!exists($env{'form.state'})) {
4876: $r->print(&Apache::loncoursequeueadmin::display_queued_requests('requestauthor',
4877: $env{'request.role.domain'}));
4878: } elsif ($env{'form.state'} eq 'done') {
4879: $r->print('<h3>'.&mt('Authoring request processing').'</h3>'."\n");
4880: $r->print(&Apache::loncoursequeueadmin::update_request_queue('requestauthor',
4881: $env{'request.role.domain'}));
4882: }
1.391 raeburn 4883: } elsif (($env{'form.action'} eq 'processusernamereq') &&
4884: ($permission->{'cusr'}) &&
4885: (&Apache::lonnet::allowed('cau',$env{'request.role.domain'}))) {
4886: push(@{$brcrum},
4887: {href => '/adm/createuser?action=processusernamereq',
4888: text => 'LON-CAPA account requests',
4889: help => 'Domain_Username_Approvals'});
4890: $bread_crumbs_component = 'Account requests';
4891: if ($env{'form.state'} eq 'done') {
4892: push(@{$brcrum},
4893: {href => '/adm/createuser?action=usernamereqqueue',
4894: text => 'Result',
4895: help => 'Domain_Username_Approvals'});
4896: $bread_crumbs_component = 'LON-CAPA account request result';
4897: }
4898: $args = { bread_crumbs => $brcrum,
4899: bread_crumbs_component => $bread_crumbs_component};
4900: my $js = &usernamerequest_javascript();
4901: $r->print(&header(&add_script($js),$args));
4902: if (!exists($env{'form.state'})) {
4903: $r->print(&Apache::loncoursequeueadmin::display_queued_requests('requestusername',
4904: $env{'request.role.domain'}));
4905: } elsif ($env{'form.state'} eq 'done') {
4906: $r->print('<h3>'.&mt('LON-CAPA account request processing').'</h3>'."\n");
4907: $r->print(&Apache::loncoursequeueadmin::update_request_queue('requestusername',
4908: $env{'request.role.domain'}));
4909: }
4910: } elsif (($env{'form.action'} eq 'displayuserreq') &&
4911: ($permission->{'cusr'})) {
4912: my $dom = $env{'form.domain'};
4913: my $uname = $env{'form.username'};
4914: my $warning;
4915: if (($dom =~ /^$match_domain$/) && (&Apache::lonnet::domain($dom) ne '')) {
4916: if (($dom eq $env{'request.role.domain'}) && (&Apache::lonnet::allowed('ccc',$dom))) {
4917: if (($uname =~ /^$match_username$/) && ($env{'form.queue'} eq 'approval')) {
4918: my $uhome = &Apache::lonnet::homeserver($uname,$dom);
4919: if ($uhome eq 'no_host') {
4920: my $queue = $env{'form.queue'};
4921: my $reqkey = &escape($uname).'_'.$queue;
4922: my $namespace = 'usernamequeue';
4923: my $domconfig = &Apache::lonnet::get_domainconfiguser($dom);
4924: my %queued =
4925: &Apache::lonnet::get($namespace,[$reqkey],$dom,$domconfig);
4926: unless ($queued{$reqkey}) {
4927: $warning = &mt('No information was found for this LON-CAPA account request.');
4928: }
4929: } else {
4930: $warning = &mt('A LON-CAPA account already exists for the requested username and domain.');
4931: }
4932: } else {
4933: $warning = &mt('LON-CAPA account request status check is for an invalid username.');
4934: }
4935: } else {
4936: $warning = &mt('You do not have rights to view LON-CAPA account requests in the domain specified.');
4937: }
4938: } else {
4939: $warning = &mt('LON-CAPA account request status check is for an invalid domain.');
4940: }
4941: my $args = { only_body => 1 };
4942: $r->print(&header(undef,$args).
4943: '<h3>'.&mt('LON-CAPA Account Request Details').'</h3>');
4944: if ($warning ne '') {
4945: $r->print('<div class="LC_warning">'.$warning.'</div>');
4946: } else {
4947: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
4948: my $domconfiguser = &Apache::lonnet::get_domainconfiguser($dom);
4949: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
4950: if (ref($domconfig{'usercreation'}) eq 'HASH') {
4951: if (ref($domconfig{'usercreation'}{'cancreate'}) eq 'HASH') {
4952: if (ref($domconfig{'usercreation'}{'cancreate'}{'emailusername'}) eq 'HASH') {
4953: my %info =
4954: &Apache::lonnet::get('nohist_requestedusernames',[$uname],$dom,$domconfiguser);
4955: if (ref($info{$uname}) eq 'HASH') {
1.396 raeburn 4956: my $usertype = $info{$uname}{'inststatus'};
4957: unless ($usertype) {
4958: $usertype = 'default';
4959: }
4960: if (ref($domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}) eq 'HASH') {
4961: if ((ref($infofields) eq 'ARRAY') && (ref($infotitles) eq 'HASH')) {
4962: $r->print('<div>'.&Apache::lonhtmlcommon::start_pick_box());
4963: my ($num,$count,$showstatus);
4964: $count = scalar(keys(%{$domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}}));
4965: unless ($usertype eq 'default') {
4966: my ($othertitle,$usertypes,$types) =
4967: &Apache::loncommon::sorted_inst_types($dom);
4968: if (ref($usertypes) eq 'HASH') {
4969: if ($usertypes->{$usertype}) {
4970: $showstatus = $usertypes->{$usertype};
4971: $count ++;
4972: }
4973: }
4974: }
4975: foreach my $field (@{$infofields}) {
4976: next unless ($domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}{$field});
4977: next unless ($infotitles->{$field});
4978: $r->print(&Apache::lonhtmlcommon::row_title($infotitles->{$field}).
4979: $info{$uname}{$field});
4980: $num ++;
4981: if ($count == $num) {
4982: $r->print(&Apache::lonhtmlcommon::row_closure(1));
4983: } else {
4984: $r->print(&Apache::lonhtmlcommon::row_closure());
4985: }
4986: }
4987: if ($showstatus) {
4988: $r->print(&Apache::lonhtmlcommon::row_title(&mt('Status type (self-reported)')).
4989: $showstatus.
4990: &Apache::lonhtmlcommon::row_closure(1));
1.391 raeburn 4991: }
1.396 raeburn 4992: $r->print(&Apache::lonhtmlcommon::end_pick_box().'</div>');
1.391 raeburn 4993: }
4994: }
4995: }
4996: }
4997: }
4998: }
4999: $r->print(&close_popup_form());
5000: }
1.207 raeburn 5001: } elsif (($env{'form.action'} eq 'listusers') &&
5002: ($permission->{'view'} || $permission->{'cusr'})) {
1.202 raeburn 5003: if ($env{'form.phase'} eq 'bulkchange') {
1.351 raeburn 5004: push(@{$brcrum},
5005: {href => '/adm/createuser?action=listusers',
5006: text => "List Users"},
5007: {href => "/adm/createuser",
5008: text => "Result",
5009: help => 'Course_View_Class_List'});
5010: $bread_crumbs_component = 'Update Users';
5011: $args = {bread_crumbs => $brcrum,
5012: bread_crumbs_component => $bread_crumbs_component};
5013: $r->print(&header(undef,$args));
1.202 raeburn 5014: my $setting = $env{'form.roletype'};
5015: my $choice = $env{'form.bulkaction'};
5016: if ($permission->{'cusr'}) {
1.336 raeburn 5017: &Apache::lonuserutils::update_user_list($r,$context,$setting,$choice,$crstype);
1.221 raeburn 5018: } else {
5019: $r->print(&mt('You are not authorized to make bulk changes to user roles'));
1.223 raeburn 5020: $r->print('<p><a href="/adm/createuser?action=listusers">'.&mt('Display User Lists').'</a>');
1.202 raeburn 5021: }
5022: } else {
1.351 raeburn 5023: push(@{$brcrum},
5024: {href => '/adm/createuser?action=listusers',
5025: text => "List Users",
5026: help => 'Course_View_Class_List'});
5027: $bread_crumbs_component = 'List Users';
5028: $args = {bread_crumbs => $brcrum,
5029: bread_crumbs_component => $bread_crumbs_component};
1.202 raeburn 5030: my ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles);
5031: my $formname = 'studentform';
1.364 raeburn 5032: my $hidecall = "hide_searching();";
1.321 raeburn 5033: if (($context eq 'domain') && (($env{'form.roletype'} eq 'course') ||
5034: ($env{'form.roletype'} eq 'community'))) {
5035: if ($env{'form.roletype'} eq 'course') {
5036: ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles) =
5037: &Apache::lonuserutils::courses_selector($env{'request.role.domain'},
5038: $formname);
5039: } elsif ($env{'form.roletype'} eq 'community') {
5040: $cb_jscript =
5041: &Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
5042: my %elements = (
5043: coursepick => 'radio',
5044: coursetotal => 'text',
5045: courselist => 'text',
5046: );
5047: $jscript = &Apache::lonhtmlcommon::set_form_elements(\%elements);
5048: }
1.364 raeburn 5049: $jscript .= &verify_user_display($context)."\n".
5050: &Apache::loncommon::check_uncheck_jscript();
1.202 raeburn 5051: my $js = &add_script($jscript).$cb_jscript;
5052: my $loadcode =
5053: &Apache::lonuserutils::course_selector_loadcode($formname);
5054: if ($loadcode ne '') {
1.364 raeburn 5055: $args->{add_entries} = {onload => "$loadcode;$hidecall"};
5056: } else {
5057: $args->{add_entries} = {onload => $hidecall};
1.202 raeburn 5058: }
1.351 raeburn 5059: $r->print(&header($js,$args));
1.191 raeburn 5060: } else {
1.364 raeburn 5061: $args->{add_entries} = {onload => $hidecall};
5062: $jscript = &verify_user_display($context).
5063: &Apache::loncommon::check_uncheck_jscript();
5064: $r->print(&header(&add_script($jscript),$args));
1.191 raeburn 5065: }
1.202 raeburn 5066: &Apache::lonuserutils::print_userlist($r,undef,$permission,$context,
1.375 raeburn 5067: $formname,$totcodes,$codetitles,$idlist,$idlist_titles,
5068: $showcredits);
1.191 raeburn 5069: }
1.213 raeburn 5070: } elsif ($env{'form.action'} eq 'drop' && $permission->{'cusr'}) {
1.318 raeburn 5071: my $brtext;
5072: if ($crstype eq 'Community') {
5073: $brtext = 'Drop Members';
5074: } else {
5075: $brtext = 'Drop Students';
5076: }
1.351 raeburn 5077: push(@{$brcrum},
5078: {href => '/adm/createuser?action=drop',
5079: text => $brtext,
5080: help => 'Course_Drop_Student'});
5081: if ($env{'form.state'} eq 'done') {
5082: push(@{$brcrum},
5083: {href=>'/adm/createuser?action=drop',
5084: text=>"Result"});
5085: }
5086: $bread_crumbs_component = $brtext;
5087: $args = {bread_crumbs => $brcrum,
5088: bread_crumbs_component => $bread_crumbs_component};
5089: $r->print(&header(undef,$args));
1.213 raeburn 5090: if (!exists($env{'form.state'})) {
1.318 raeburn 5091: &Apache::lonuserutils::print_drop_menu($r,$context,$permission,$crstype);
1.213 raeburn 5092: } elsif ($env{'form.state'} eq 'done') {
5093: &Apache::lonuserutils::update_user_list($r,$context,undef,
5094: $env{'form.action'});
5095: }
1.202 raeburn 5096: } elsif ($env{'form.action'} eq 'dateselect') {
5097: if ($permission->{'cusr'}) {
1.351 raeburn 5098: $r->print(&header(undef,{'no_nav_bar' => 1}).
1.375 raeburn 5099: &Apache::lonuserutils::date_section_selector($context,$permission,
5100: $crstype,$showcredits));
1.202 raeburn 5101: } else {
1.351 raeburn 5102: $r->print(&header(undef,{'no_nav_bar' => 1}).
5103: '<span class="LC_error">'.&mt('You do not have permission to modify dates or sections for users').'</span>');
1.202 raeburn 5104: }
1.237 raeburn 5105: } elsif ($env{'form.action'} eq 'selfenroll') {
1.398 raeburn 5106: if ($permission->{selfenrolladmin}) {
5107: my $cid = $env{'request.course.id'};
5108: my $cdom = $env{'course.'.$cid.'.domain'};
5109: my $cnum = $env{'course.'.$cid.'.num'};
5110: my %currsettings = (
5111: selfenroll_types => $env{'course.'.$cid.'.internal.selfenroll_types'},
5112: selfenroll_registered => $env{'course.'.$cid.'.internal.selfenroll_registered'},
5113: selfenroll_section => $env{'course.'.$cid.'.internal.selfenroll_section'},
5114: selfenroll_notifylist => $env{'course.'.$cid.'.internal.selfenroll_notifylist'},
5115: selfenroll_approval => $env{'course.'.$cid.'.internal.selfenroll_approval'},
5116: selfenroll_limit => $env{'course.'.$cid.'.internal.selfenroll_limit'},
5117: selfenroll_cap => $env{'course.'.$cid.'.internal.selfenroll_cap'},
5118: selfenroll_start_date => $env{'course.'.$cid.'.internal.selfenroll_start_date'},
5119: selfenroll_end_date => $env{'course.'.$cid.'.internal.selfenroll_end_date'},
5120: selfenroll_start_access => $env{'course.'.$cid.'.internal.selfenroll_start_access'},
5121: selfenroll_end_access => $env{'course.'.$cid.'.internal.selfenroll_end_access'},
5122: default_enrollment_start_date => $env{'course.'.$cid.'.default_enrollment_start_date'},
5123: default_enrollment_end_date => $env{'course.'.$cid.'.default_enrollment_end_date'},
1.400 raeburn 5124: uniquecode => $env{'course.'.$cid.'.internal.uniquecode'},
1.398 raeburn 5125: );
5126: push(@{$brcrum},
5127: {href => '/adm/createuser?action=selfenroll',
5128: text => "Configure Self-enrollment",
5129: help => 'Course_Self_Enrollment'});
5130: if (!exists($env{'form.state'})) {
5131: $args = { bread_crumbs => $brcrum,
5132: bread_crumbs_component => 'Configure Self-enrollment'};
5133: $r->print(&header(undef,$args));
5134: $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n");
5135: &print_selfenroll_menu($r,'course',$cid,$cdom,$cnum,\%currsettings);
5136: } elsif ($env{'form.state'} eq 'done') {
5137: push (@{$brcrum},
5138: {href=>'/adm/createuser?action=selfenroll',
5139: text=>"Result"});
5140: $args = { bread_crumbs => $brcrum,
5141: bread_crumbs_component => 'Self-enrollment result'};
5142: $r->print(&header(undef,$args));
5143: $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n");
1.400 raeburn 5144: &update_selfenroll_config($r,$cid,$cdom,$cnum,$context,$crstype,\%currsettings);
1.398 raeburn 5145: }
5146: } else {
5147: $r->print(&header(undef,{'no_nav_bar' => 1}).
5148: '<span class="LC_error">'.&mt('You do not have permission to configure self-enrollment').'</span>');
1.237 raeburn 5149: }
1.277 raeburn 5150: } elsif ($env{'form.action'} eq 'selfenrollqueue') {
1.418 raeburn 5151: if ($permission->{selfenrolladmin}) {
1.351 raeburn 5152: push(@{$brcrum},
5153: {href => '/adm/createuser?action=selfenrollqueue',
1.418 raeburn 5154: text => 'Enrollment requests',
1.351 raeburn 5155: help => 'Course_Self_Enrollment'});
1.418 raeburn 5156: $bread_crumbs_component = 'Enrollment requests';
5157: if ($env{'form.state'} eq 'done') {
5158: push(@{$brcrum},
5159: {href => '/adm/createuser?action=selfenrollqueue',
5160: text => 'Result',
5161: help => 'Course_Self_Enrollment'});
5162: $bread_crumbs_component = 'Enrollment result';
5163: }
5164: $args = { bread_crumbs => $brcrum,
5165: bread_crumbs_component => $bread_crumbs_component};
5166: $r->print(&header(undef,$args));
5167: my $cid = $env{'request.course.id'};
5168: my $cdom = $env{'course.'.$cid.'.domain'};
5169: my $cnum = $env{'course.'.$cid.'.num'};
5170: my $coursedesc = $env{'course.'.$cid.'.description'};
5171: if (!exists($env{'form.state'})) {
5172: $r->print('<h3>'.&mt('Pending enrollment requests').'</h3>'."\n");
5173: $r->print(&Apache::loncoursequeueadmin::display_queued_requests($context,
5174: $cdom,$cnum));
5175: } elsif ($env{'form.state'} eq 'done') {
5176: $r->print('<h3>'.&mt('Enrollment request processing').'</h3>'."\n");
5177: $r->print(&Apache::loncoursequeueadmin::update_request_queue($context,
5178: $cdom,$cnum,$coursedesc));
5179: }
5180: } else {
5181: $r->print(&header(undef,{'no_nav_bar' => 1}).
5182: '<span class="LC_error">'.&mt('You do not have permission to manage self-enrollment').'</span>');
1.351 raeburn 5183: }
1.418 raeburn 5184: } elsif ($env{'form.action'} eq 'changelogs') {
5185: if ($permission->{cusr} || $permission->{view}) {
5186: &print_userchangelogs_display($r,$context,$permission,$brcrum);
5187: } else {
5188: $r->print(&header(undef,{'no_nav_bar' => 1}).
5189: '<span class="LC_error">'.&mt('You do not have permission to view change logs').'</span>');
1.277 raeburn 5190: }
1.190 raeburn 5191: } else {
1.351 raeburn 5192: $bread_crumbs_component = 'User Management';
5193: $args = { bread_crumbs => $brcrum,
5194: bread_crumbs_component => $bread_crumbs_component};
5195: $r->print(&header(undef,$args));
1.318 raeburn 5196: $r->print(&print_main_menu($permission,$context,$crstype));
1.190 raeburn 5197: }
1.351 raeburn 5198: $r->print(&Apache::loncommon::end_page());
1.190 raeburn 5199: return OK;
5200: }
5201:
5202: sub header {
1.351 raeburn 5203: my ($jscript,$args) = @_;
1.190 raeburn 5204: my $start_page;
1.351 raeburn 5205: if (ref($args) eq 'HASH') {
5206: $start_page=&Apache::loncommon::start_page('User Management',$jscript,$args);
1.190 raeburn 5207: } else {
1.351 raeburn 5208: $start_page=&Apache::loncommon::start_page('User Management',$jscript);
1.190 raeburn 5209: }
5210: return $start_page;
5211: }
1.2 www 5212:
1.191 raeburn 5213: sub add_script {
5214: my ($js) = @_;
1.301 bisitz 5215: return '<script type="text/javascript">'."\n"
5216: .'// <![CDATA['."\n"
5217: .$js."\n"
5218: .'// ]]>'."\n"
5219: .'</script>'."\n";
1.191 raeburn 5220: }
5221:
1.391 raeburn 5222: sub usernamerequest_javascript {
5223: my $js = <<ENDJS;
5224:
5225: function openusernamereqdisplay(dom,uname,queue) {
5226: var url = '/adm/createuser?action=displayuserreq';
5227: url += '&domain='+dom+'&username='+uname+'&queue='+queue;
5228: var title = 'Account_Request_Browser';
5229: var options = 'scrollbars=1,resizable=1,menubar=0';
5230: options += ',width=700,height=600';
5231: var stdeditbrowser = open(url,title,options,'1');
5232: stdeditbrowser.focus();
5233: return;
5234: }
5235:
5236: ENDJS
5237: }
5238:
5239: sub close_popup_form {
5240: my $close= &mt('Close Window');
5241: return << "END";
5242: <p><form name="displayreq" action="" method="post">
5243: <input type="button" name="closeme" value="$close" onclick="javascript:self.close();" />
5244: </form></p>
5245: END
5246: }
5247:
1.202 raeburn 5248: sub verify_user_display {
1.364 raeburn 5249: my ($context) = @_;
1.374 raeburn 5250: my %lt = &Apache::lonlocal::texthash (
5251: course => 'course(s): description, section(s), status',
5252: community => 'community(s): description, section(s), status',
5253: author => 'author',
5254: );
1.364 raeburn 5255: my $photos;
5256: if (($context eq 'course') && $env{'request.course.id'}) {
5257: $photos = $env{'course.'.$env{'request.course.id'}.'.internal.showphoto'};
5258: }
1.202 raeburn 5259: my $output = <<"END";
5260:
1.364 raeburn 5261: function hide_searching() {
5262: if (document.getElementById('searching')) {
5263: document.getElementById('searching').style.display = 'none';
5264: }
5265: return;
5266: }
5267:
1.202 raeburn 5268: function display_update() {
5269: document.studentform.action.value = 'listusers';
5270: document.studentform.phase.value = 'display';
5271: document.studentform.submit();
5272: }
5273:
1.364 raeburn 5274: function updateCols(caller) {
5275: var context = '$context';
5276: var photos = '$photos';
5277: if (caller == 'Status') {
1.374 raeburn 5278: if ((context == 'domain') &&
5279: ((document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'course') ||
5280: (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community'))) {
1.364 raeburn 5281: document.getElementById('showcolstatus').checked = false;
5282: document.getElementById('showcolstatus').disabled = 'disabled';
5283: document.getElementById('showcolstart').checked = false;
5284: document.getElementById('showcolend').checked = false;
1.374 raeburn 5285: } else {
5286: if (document.studentform.Status.options[document.studentform.Status.selectedIndex].value == 'Any') {
5287: document.getElementById('showcolstatus').checked = true;
5288: document.getElementById('showcolstatus').disabled = '';
5289: document.getElementById('showcolstart').checked = true;
5290: document.getElementById('showcolend').checked = true;
5291: } else {
5292: document.getElementById('showcolstatus').checked = false;
5293: document.getElementById('showcolstatus').disabled = 'disabled';
5294: document.getElementById('showcolstart').checked = false;
5295: document.getElementById('showcolend').checked = false;
5296: }
1.364 raeburn 5297: }
5298: }
5299: if (caller == 'output') {
5300: if (photos == 1) {
5301: if (document.getElementById('showcolphoto')) {
5302: var photoitem = document.getElementById('showcolphoto');
5303: if (document.studentform.output.options[document.studentform.output.selectedIndex].value == 'html') {
5304: photoitem.checked = true;
5305: photoitem.disabled = '';
5306: } else {
5307: photoitem.checked = false;
5308: photoitem.disabled = 'disabled';
5309: }
5310: }
5311: }
5312: }
5313: if (caller == 'showrole') {
1.371 raeburn 5314: if ((document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'Any') ||
5315: (document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'cr')) {
1.364 raeburn 5316: document.getElementById('showcolrole').checked = true;
5317: document.getElementById('showcolrole').disabled = '';
5318: } else {
5319: document.getElementById('showcolrole').checked = false;
5320: document.getElementById('showcolrole').disabled = 'disabled';
5321: }
1.374 raeburn 5322: if (context == 'domain') {
1.382 raeburn 5323: var quotausageshow = 0;
1.374 raeburn 5324: if ((document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'course') ||
5325: (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community')) {
5326: document.getElementById('showcolstatus').checked = false;
5327: document.getElementById('showcolstatus').disabled = 'disabled';
5328: document.getElementById('showcolstart').checked = false;
5329: document.getElementById('showcolend').checked = false;
5330: } else {
5331: if (document.studentform.Status.options[document.studentform.Status.selectedIndex].value == 'Any') {
5332: document.getElementById('showcolstatus').checked = true;
5333: document.getElementById('showcolstatus').disabled = '';
5334: document.getElementById('showcolstart').checked = true;
5335: document.getElementById('showcolend').checked = true;
5336: }
5337: }
5338: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'domain') {
5339: document.getElementById('showcolextent').disabled = 'disabled';
5340: document.getElementById('showcolextent').checked = 'false';
5341: document.getElementById('showextent').style.display='none';
5342: document.getElementById('showcoltextextent').innerHTML = '';
1.382 raeburn 5343: if ((document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'au') ||
5344: (document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'Any')) {
5345: if (document.getElementById('showcolauthorusage')) {
5346: document.getElementById('showcolauthorusage').disabled = '';
5347: }
5348: if (document.getElementById('showcolauthorquota')) {
5349: document.getElementById('showcolauthorquota').disabled = '';
5350: }
5351: quotausageshow = 1;
5352: }
1.374 raeburn 5353: } else {
5354: document.getElementById('showextent').style.display='block';
5355: document.getElementById('showextent').style.textAlign='left';
5356: document.getElementById('showextent').style.textFace='normal';
5357: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'author') {
5358: document.getElementById('showcolextent').disabled = '';
5359: document.getElementById('showcolextent').checked = 'true';
5360: document.getElementById('showcoltextextent').innerHTML="$lt{'author'}";
5361: } else {
5362: document.getElementById('showcolextent').disabled = '';
5363: document.getElementById('showcolextent').checked = 'true';
5364: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community') {
5365: document.getElementById('showcoltextextent').innerHTML="$lt{'community'}";
5366: } else {
5367: document.getElementById('showcoltextextent').innerHTML="$lt{'course'}";
5368: }
5369: }
5370: }
1.382 raeburn 5371: if (quotausageshow == 0) {
5372: if (document.getElementById('showcolauthorusage')) {
5373: document.getElementById('showcolauthorusage').checked = false;
5374: document.getElementById('showcolauthorusage').disabled = 'disabled';
5375: }
5376: if (document.getElementById('showcolauthorquota')) {
5377: document.getElementById('showcolauthorquota').checked = false;
5378: document.getElementById('showcolauthorquota').disabled = 'disabled';
5379: }
5380: }
1.374 raeburn 5381: }
1.364 raeburn 5382: }
5383: return;
5384: }
5385:
1.202 raeburn 5386: END
5387: return $output;
5388:
5389: }
5390:
1.190 raeburn 5391: ###############################################################
5392: ###############################################################
5393: # Menu Phase One
5394: sub print_main_menu {
1.318 raeburn 5395: my ($permission,$context,$crstype) = @_;
5396: my $linkcontext = $context;
5397: my $stuterm = lc(&Apache::lonnet::plaintext('st',$crstype));
5398: if (($context eq 'course') && ($crstype eq 'Community')) {
5399: $linkcontext = lc($crstype);
5400: $stuterm = 'Members';
5401: }
1.208 raeburn 5402: my %links = (
1.298 droeschl 5403: domain => {
5404: upload => 'Upload a File of Users',
5405: singleuser => 'Add/Modify a User',
5406: listusers => 'Manage Users',
5407: },
5408: author => {
5409: upload => 'Upload a File of Co-authors',
5410: singleuser => 'Add/Modify a Co-author',
5411: listusers => 'Manage Co-authors',
5412: },
5413: course => {
5414: upload => 'Upload a File of Course Users',
5415: singleuser => 'Add/Modify a Course User',
1.354 www 5416: listusers => 'List and Modify Multiple Course Users',
1.298 droeschl 5417: },
1.318 raeburn 5418: community => {
5419: upload => 'Upload a File of Community Users',
5420: singleuser => 'Add/Modify a Community User',
1.354 www 5421: listusers => 'List and Modify Multiple Community Users',
1.318 raeburn 5422: },
5423: );
5424: my %linktitles = (
5425: domain => {
5426: singleuser => 'Add a user to the domain, and/or a course or community in the domain.',
5427: listusers => 'Show and manage users in this domain.',
5428: },
5429: author => {
5430: singleuser => 'Add a user with a co- or assistant author role.',
5431: listusers => 'Show and manage co- or assistant authors.',
5432: },
5433: course => {
5434: singleuser => 'Add a user with a certain role to this course.',
5435: listusers => 'Show and manage users in this course.',
5436: },
5437: community => {
5438: singleuser => 'Add a user with a certain role to this community.',
5439: listusers => 'Show and manage users in this community.',
5440: },
1.298 droeschl 5441: );
1.418 raeburn 5442: if ($linkcontext eq 'domain') {
5443: unless ($permission->{'cusr'}) {
5444: $links{'domain'}{'singleuser'} = 'View a User';
5445: $linktitles{'domain'}{'singleuser'} = 'View information about a user in the domain';
5446:
5447: }
5448: } elsif ($linkcontext eq 'course') {
5449: unless ($permission->{'cusr'}) {
5450: $links{'course'}{'singleuser'} = 'View a Course User';
5451: $linktitles{'course'}{'singleuser'} = 'View information about a user in this course';
5452: $links{'course'}{'listusers'} = 'List Course Users';
5453: $linktitles{'course'}{'listusers'} = 'Show information about users in this course';
5454: }
5455: } elsif ($linkcontext eq 'community') {
5456: unless ($permission->{'cusr'}) {
5457: $links{'community'}{'singleuser'} = 'View a Community User';
5458: $linktitles{'community'}{'singleuser'} = 'View information about a user in this community';
5459: $links{'community'}{'listusers'} = 'List Community Users';
5460: $linktitles{'community'}{'listusers'} = 'Show information about users in this community';
5461: }
5462: }
1.298 droeschl 5463: my @menu = ( {categorytitle => 'Single Users',
5464: items =>
5465: [
5466: {
1.318 raeburn 5467: linktext => $links{$linkcontext}{'singleuser'},
1.298 droeschl 5468: icon => 'edit-redo.png',
5469: #help => 'Course_Change_Privileges',
5470: url => '/adm/createuser?action=singleuser',
1.418 raeburn 5471: permission => ($permission->{'view'} || $permission->{'cusr'}),
1.318 raeburn 5472: linktitle => $linktitles{$linkcontext}{'singleuser'},
1.298 droeschl 5473: },
5474: ]},
5475:
5476: {categorytitle => 'Multiple Users',
5477: items =>
5478: [
5479: {
1.318 raeburn 5480: linktext => $links{$linkcontext}{'upload'},
1.340 wenzelju 5481: icon => 'uplusr.png',
1.298 droeschl 5482: #help => 'Course_Create_Class_List',
5483: url => '/adm/createuser?action=upload',
5484: permission => $permission->{'cusr'},
5485: linktitle => 'Upload a CSV or a text file containing users.',
5486: },
5487: {
1.318 raeburn 5488: linktext => $links{$linkcontext}{'listusers'},
1.340 wenzelju 5489: icon => 'mngcu.png',
1.298 droeschl 5490: #help => 'Course_View_Class_List',
5491: url => '/adm/createuser?action=listusers',
5492: permission => ($permission->{'view'} || $permission->{'cusr'}),
1.318 raeburn 5493: linktitle => $linktitles{$linkcontext}{'listusers'},
1.298 droeschl 5494: },
5495:
5496: ]},
5497:
5498: {categorytitle => 'Administration',
5499: items => [ ]},
5500: );
1.415 raeburn 5501:
1.265 mielkec 5502: if ($context eq 'domain'){
1.416 raeburn 5503: push(@{ $menu[0]->{items} }, # Single Users
5504: {
5505: linktext => 'User Access Log',
1.417 raeburn 5506: icon => 'document-properties.png',
1.416 raeburn 5507: #help => 'User_Access_Logs',
5508: url => '/adm/createuser?action=accesslogs',
5509: permission => $permission->{'activity'},
5510: linktitle => 'View user access log.',
5511: }
5512: );
1.298 droeschl 5513:
5514: push(@{ $menu[2]->{items} }, #Category: Administration
5515: {
5516: linktext => 'Custom Roles',
5517: icon => 'emblem-photos.png',
5518: #help => 'Course_Editing_Custom_Roles',
5519: url => '/adm/createuser?action=custom',
5520: permission => $permission->{'custom'},
5521: linktitle => 'Configure a custom role.',
5522: },
1.362 raeburn 5523: {
5524: linktext => 'Authoring Space Requests',
5525: icon => 'selfenrl-queue.png',
5526: #help => 'Domain_Role_Approvals',
5527: url => '/adm/createuser?action=processauthorreq',
5528: permission => $permission->{'cusr'},
5529: linktitle => 'Approve or reject author role requests',
5530: },
1.363 raeburn 5531: {
1.391 raeburn 5532: linktext => 'LON-CAPA Account Requests',
5533: icon => 'list-add.png',
5534: #help => 'Domain_Username_Approvals',
5535: url => '/adm/createuser?action=processusernamereq',
5536: permission => $permission->{'cusr'},
5537: linktitle => 'Approve or reject LON-CAPA account requests',
5538: },
5539: {
1.363 raeburn 5540: linktext => 'Change Log',
5541: icon => 'document-properties.png',
5542: #help => 'Course_User_Logs',
5543: url => '/adm/createuser?action=changelogs',
1.418 raeburn 5544: permission => ($permission->{'cusr'} || $permission->{'view'}),
1.363 raeburn 5545: linktitle => 'View change log.',
5546: },
1.298 droeschl 5547: );
5548:
1.265 mielkec 5549: }elsif ($context eq 'course'){
1.298 droeschl 5550: my ($cnum,$cdom) = &Apache::lonuserutils::get_course_identity();
1.318 raeburn 5551:
5552: my %linktext = (
5553: 'Course' => {
5554: single => 'Add/Modify a Student',
5555: drop => 'Drop Students',
5556: groups => 'Course Groups',
5557: },
5558: 'Community' => {
5559: single => 'Add/Modify a Member',
5560: drop => 'Drop Members',
5561: groups => 'Community Groups',
5562: },
5563: );
1.411 raeburn 5564: $linktext{'Placement'} = $linktext{'Course'};
1.318 raeburn 5565:
5566: my %linktitle = (
5567: 'Course' => {
5568: single => 'Add a user with the role of student to this course',
5569: drop => 'Remove a student from this course.',
5570: groups => 'Manage course groups',
5571: },
5572: 'Community' => {
5573: single => 'Add a user with the role of member to this community',
5574: drop => 'Remove a member from this community.',
5575: groups => 'Manage community groups',
5576: },
5577: );
5578:
1.411 raeburn 5579: $linktitle{'Placement'} = $linktitle{'Course'};
5580:
1.298 droeschl 5581: push(@{ $menu[0]->{items} }, #Category: Single Users
5582: {
1.318 raeburn 5583: linktext => $linktext{$crstype}{'single'},
1.298 droeschl 5584: #help => 'Course_Add_Student',
5585: icon => 'list-add.png',
5586: url => '/adm/createuser?action=singlestudent',
5587: permission => $permission->{'cusr'},
1.318 raeburn 5588: linktitle => $linktitle{$crstype}{'single'},
1.298 droeschl 5589: },
5590: );
5591:
5592: push(@{ $menu[1]->{items} }, #Category: Multiple Users
5593: {
1.318 raeburn 5594: linktext => $linktext{$crstype}{'drop'},
1.298 droeschl 5595: icon => 'edit-undo.png',
5596: #help => 'Course_Drop_Student',
5597: url => '/adm/createuser?action=drop',
5598: permission => $permission->{'cusr'},
1.318 raeburn 5599: linktitle => $linktitle{$crstype}{'drop'},
1.298 droeschl 5600: },
5601: );
5602: push(@{ $menu[2]->{items} }, #Category: Administration
5603: {
5604: linktext => 'Custom Roles',
5605: icon => 'emblem-photos.png',
5606: #help => 'Course_Editing_Custom_Roles',
5607: url => '/adm/createuser?action=custom',
5608: permission => $permission->{'custom'},
5609: linktitle => 'Configure a custom role.',
5610: },
5611: {
1.318 raeburn 5612: linktext => $linktext{$crstype}{'groups'},
1.333 wenzelju 5613: icon => 'grps.png',
1.298 droeschl 5614: #help => 'Course_Manage_Group',
5615: url => '/adm/coursegroups?refpage=cusr',
5616: permission => $permission->{'grp_manage'},
1.318 raeburn 5617: linktitle => $linktitle{$crstype}{'groups'},
1.298 droeschl 5618: },
5619: {
1.328 wenzelju 5620: linktext => 'Change Log',
1.298 droeschl 5621: icon => 'document-properties.png',
5622: #help => 'Course_User_Logs',
5623: url => '/adm/createuser?action=changelogs',
1.418 raeburn 5624: permission => ($permission->{'view'} || $permission->{'cusr'}),
1.298 droeschl 5625: linktitle => 'View change log.',
5626: },
5627: );
1.277 raeburn 5628: if ($env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_approval'}) {
1.298 droeschl 5629: push(@{ $menu[2]->{items} },
1.398 raeburn 5630: {
1.298 droeschl 5631: linktext => 'Enrollment Requests',
5632: icon => 'selfenrl-queue.png',
5633: #help => 'Course_Approve_Selfenroll',
5634: url => '/adm/createuser?action=selfenrollqueue',
1.398 raeburn 5635: permission => $permission->{'selfenrolladmin'},
1.298 droeschl 5636: linktitle =>'Approve or reject enrollment requests.',
5637: },
5638: );
1.277 raeburn 5639: }
1.298 droeschl 5640:
1.265 mielkec 5641: if (!exists($permission->{'cusr_section'})){
1.320 raeburn 5642: if ($crstype ne 'Community') {
5643: push(@{ $menu[2]->{items} },
5644: {
5645: linktext => 'Automated Enrollment',
5646: icon => 'roles.png',
5647: #help => 'Course_Automated_Enrollment',
5648: permission => (&Apache::lonnet::auto_run($cnum,$cdom)
1.418 raeburn 5649: && (($permission->{'cusr'}) ||
5650: ($permission->{'view'}))),
1.320 raeburn 5651: url => '/adm/populate',
5652: linktitle => 'Automated enrollment manager.',
5653: }
5654: );
5655: }
5656: push(@{ $menu[2]->{items} },
1.298 droeschl 5657: {
5658: linktext => 'User Self-Enrollment',
1.342 wenzelju 5659: icon => 'self_enroll.png',
1.298 droeschl 5660: #help => 'Course_Self_Enrollment',
5661: url => '/adm/createuser?action=selfenroll',
1.398 raeburn 5662: permission => $permission->{'selfenrolladmin'},
1.317 bisitz 5663: linktitle => 'Configure user self-enrollment.',
1.298 droeschl 5664: },
5665: );
5666: }
1.363 raeburn 5667: } elsif ($context eq 'author') {
1.370 raeburn 5668: push(@{ $menu[2]->{items} }, #Category: Administration
1.363 raeburn 5669: {
5670: linktext => 'Change Log',
5671: icon => 'document-properties.png',
5672: #help => 'Course_User_Logs',
5673: url => '/adm/createuser?action=changelogs',
5674: permission => $permission->{'cusr'},
5675: linktitle => 'View change log.',
5676: },
1.370 raeburn 5677: );
1.363 raeburn 5678: }
5679: return Apache::lonhtmlcommon::generate_menu(@menu);
1.250 raeburn 5680: # { text => 'View Log-in History',
5681: # help => 'Course_User_Logins',
5682: # action => 'logins',
5683: # permission => $permission->{'cusr'},
5684: # });
1.190 raeburn 5685: }
5686:
1.189 albertel 5687: sub restore_prev_selections {
5688: my %saveable_parameters = ('srchby' => 'scalar',
5689: 'srchin' => 'scalar',
5690: 'srchtype' => 'scalar',
5691: );
5692: &Apache::loncommon::store_settings('user','user_picker',
5693: \%saveable_parameters);
5694: &Apache::loncommon::restore_settings('user','user_picker',
5695: \%saveable_parameters);
5696: }
5697:
1.237 raeburn 5698: sub print_selfenroll_menu {
1.418 raeburn 5699: my ($r,$context,$cid,$cdom,$cnum,$currsettings,$additional,$readonly) = @_;
1.322 raeburn 5700: my $crstype = &Apache::loncommon::course_type();
1.398 raeburn 5701: my $formname = 'selfenroll';
1.237 raeburn 5702: my $nolink = 1;
1.398 raeburn 5703: my ($row,$lt) = &Apache::lonuserutils::get_selfenroll_titles();
1.237 raeburn 5704: my $groupslist = &Apache::lonuserutils::get_groupslist();
5705: my $setsec_js =
5706: &Apache::lonuserutils::setsections_javascript($formname,$groupslist);
1.249 raeburn 5707: my %alerts = &Apache::lonlocal::texthash(
5708: acto => 'Activation of self-enrollment was selected for the following domain(s)',
5709: butn => 'but no user types have been checked.',
5710: wilf => "Please uncheck 'activate' or check at least one type.",
5711: );
1.418 raeburn 5712: my $disabled;
5713: if ($readonly) {
5714: $disabled = ' disabled="disabled"';
5715: }
1.405 damieng 5716: &js_escape(\%alerts);
1.249 raeburn 5717: my $selfenroll_js = <<"ENDSCRIPT";
5718: function update_types(caller,num) {
5719: var delidx = getIndexByName('selfenroll_delete');
5720: var actidx = getIndexByName('selfenroll_activate');
5721: if (caller == 'selfenroll_all') {
5722: var selall;
5723: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
5724: if (document.$formname.selfenroll_all[i].checked) {
5725: selall = document.$formname.selfenroll_all[i].value;
5726: }
5727: }
5728: if (selall == 1) {
5729: if (delidx != -1) {
5730: if (document.$formname.selfenroll_delete.length) {
5731: for (var j=0; j<document.$formname.selfenroll_delete.length; j++) {
5732: document.$formname.selfenroll_delete[j].checked = true;
5733: }
5734: } else {
5735: document.$formname.elements[delidx].checked = true;
5736: }
5737: }
5738: if (actidx != -1) {
5739: if (document.$formname.selfenroll_activate.length) {
5740: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
5741: document.$formname.selfenroll_activate[j].checked = false;
5742: }
5743: } else {
5744: document.$formname.elements[actidx].checked = false;
5745: }
5746: }
5747: document.$formname.selfenroll_newdom.selectedIndex = 0;
5748: }
5749: }
5750: if (caller == 'selfenroll_activate') {
5751: if (document.$formname.selfenroll_activate.length) {
5752: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
5753: if (document.$formname.selfenroll_activate[j].value == num) {
5754: if (document.$formname.selfenroll_activate[j].checked) {
5755: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
5756: if (document.$formname.selfenroll_all[i].value == '1') {
5757: document.$formname.selfenroll_all[i].checked = false;
5758: }
5759: if (document.$formname.selfenroll_all[i].value == '0') {
5760: document.$formname.selfenroll_all[i].checked = true;
5761: }
5762: }
5763: }
5764: }
5765: }
5766: } else {
5767: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
5768: if (document.$formname.selfenroll_all[i].value == '1') {
5769: document.$formname.selfenroll_all[i].checked = false;
5770: }
5771: if (document.$formname.selfenroll_all[i].value == '0') {
5772: document.$formname.selfenroll_all[i].checked = true;
5773: }
5774: }
5775: }
5776: }
5777: if (caller == 'selfenroll_delete') {
5778: if (document.$formname.selfenroll_delete.length) {
5779: for (var j=0; j<document.$formname.selfenroll_delete.length; j++) {
5780: if (document.$formname.selfenroll_delete[j].value == num) {
5781: if (document.$formname.selfenroll_delete[j].checked) {
5782: var delindex = getIndexByName('selfenroll_types_'+num);
5783: if (delindex != -1) {
5784: if (document.$formname.elements[delindex].length) {
5785: for (var k=0; k<document.$formname.elements[delindex].length; k++) {
5786: document.$formname.elements[delindex][k].checked = false;
5787: }
5788: } else {
5789: document.$formname.elements[delindex].checked = false;
5790: }
5791: }
5792: }
5793: }
5794: }
5795: } else {
5796: if (document.$formname.selfenroll_delete.checked) {
5797: var delindex = getIndexByName('selfenroll_types_'+num);
5798: if (delindex != -1) {
5799: if (document.$formname.elements[delindex].length) {
5800: for (var k=0; k<document.$formname.elements[delindex].length; k++) {
5801: document.$formname.elements[delindex][k].checked = false;
5802: }
5803: } else {
5804: document.$formname.elements[delindex].checked = false;
5805: }
5806: }
5807: }
5808: }
5809: }
5810: return;
5811: }
5812:
5813: function validate_types(form) {
5814: var needaction = new Array();
5815: var countfail = 0;
5816: var actidx = getIndexByName('selfenroll_activate');
5817: if (actidx != -1) {
5818: if (document.$formname.selfenroll_activate.length) {
5819: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
5820: var num = document.$formname.selfenroll_activate[j].value;
5821: if (document.$formname.selfenroll_activate[j].checked) {
5822: countfail = check_types(num,countfail,needaction)
5823: }
5824: }
5825: } else {
5826: if (document.$formname.selfenroll_activate.checked) {
1.398 raeburn 5827: var num = document.$formname.selfenroll_activate.value;
1.249 raeburn 5828: countfail = check_types(num,countfail,needaction)
5829: }
5830: }
5831: }
5832: if (countfail > 0) {
5833: var msg = "$alerts{'acto'}\\n";
5834: var loopend = needaction.length -1;
5835: if (loopend > 0) {
5836: for (var m=0; m<loopend; m++) {
5837: msg += needaction[m]+", ";
5838: }
5839: }
5840: msg += needaction[loopend]+"\\n$alerts{'butn'}\\n$alerts{'wilf'}";
5841: alert(msg);
5842: return;
5843: }
5844: setSections(form);
5845: }
5846:
5847: function check_types(num,countfail,needaction) {
5848: var typeidx = getIndexByName('selfenroll_types_'+num);
5849: var count = 0;
5850: if (typeidx != -1) {
5851: if (document.$formname.elements[typeidx].length) {
5852: for (var k=0; k<document.$formname.elements[typeidx].length; k++) {
5853: if (document.$formname.elements[typeidx][k].checked) {
5854: count ++;
5855: }
5856: }
5857: } else {
5858: if (document.$formname.elements[typeidx].checked) {
5859: count ++;
5860: }
5861: }
5862: if (count == 0) {
5863: var domidx = getIndexByName('selfenroll_dom_'+num);
5864: if (domidx != -1) {
5865: var domname = document.$formname.elements[domidx].value;
5866: needaction[countfail] = domname;
5867: countfail ++;
5868: }
5869: }
5870: }
5871: return countfail;
5872: }
5873:
1.398 raeburn 5874: function toggleNotify() {
5875: var selfenrollApproval = 0;
5876: if (document.$formname.selfenroll_approval.length) {
5877: for (var i=0; i<document.$formname.selfenroll_approval.length; i++) {
5878: if (document.$formname.selfenroll_approval[i].checked) {
5879: selfenrollApproval = document.$formname.selfenroll_approval[i].value;
5880: break;
5881: }
5882: }
5883: }
5884: if (document.getElementById('notified')) {
5885: if (selfenrollApproval == 0) {
5886: document.getElementById('notified').style.display='none';
5887: } else {
5888: document.getElementById('notified').style.display='block';
5889: }
5890: }
5891: return;
5892: }
5893:
1.249 raeburn 5894: function getIndexByName(item) {
5895: for (var i=0;i<document.$formname.elements.length;i++) {
5896: if (document.$formname.elements[i].name == item) {
5897: return i;
5898: }
5899: }
5900: return -1;
5901: }
5902: ENDSCRIPT
1.256 raeburn 5903:
1.237 raeburn 5904: my $output = '<script type="text/javascript">'."\n".
1.301 bisitz 5905: '// <![CDATA['."\n".
1.249 raeburn 5906: $setsec_js."\n".$selfenroll_js."\n".
1.301 bisitz 5907: '// ]]>'."\n".
1.237 raeburn 5908: '</script>'."\n".
1.256 raeburn 5909: '<h3>'.$lt->{'selfenroll'}.'</h3>'."\n";
1.400 raeburn 5910:
5911: my $visactions = &cat_visibility();
5912: my ($cathash,%cattype);
5913: my %domconfig = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom);
5914: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
5915: $cathash = $domconfig{'coursecategories'}{'cats'};
5916: $cattype{'auth'} = $domconfig{'coursecategories'}{'auth'};
5917: $cattype{'unauth'} = $domconfig{'coursecategories'}{'unauth'};
1.406 raeburn 5918: if ($cattype{'auth'} eq '') {
5919: $cattype{'auth'} = 'std';
5920: }
5921: if ($cattype{'unauth'} eq '') {
5922: $cattype{'unauth'} = 'std';
5923: }
1.400 raeburn 5924: } else {
5925: $cathash = {};
5926: $cattype{'auth'} = 'std';
5927: $cattype{'unauth'} = 'std';
5928: }
5929: if (($cattype{'auth'} eq 'none') && ($cattype{'unauth'} eq 'none')) {
5930: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
5931: '<br />'.
5932: '<br />'.$visactions->{'take'}.'<ul>'.
5933: '<li>'.$visactions->{'dc_chgconf'}.'</li>'.
5934: '</ul>');
5935: } elsif (($cattype{'auth'} !~ /^(std|domonly)$/) && ($cattype{'unauth'} !~ /^(std|domonly)$/)) {
5936: if ($currsettings->{'uniquecode'}) {
5937: $r->print('<span class="LC_info">'.$visactions->{'vis'}.'</span>');
5938: } else {
5939: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
5940: '<br />'.
5941: '<br />'.$visactions->{'take'}.'<ul>'.
5942: '<li>'.$visactions->{'dc_setcode'}.'</li>'.
5943: '</ul><br />');
5944: }
5945: } else {
5946: my ($visible,$cansetvis,$vismsgs) = &visible_in_stdcat($cdom,$cnum,\%domconfig);
5947: if (ref($visactions) eq 'HASH') {
5948: if ($visible) {
5949: $output .= '<p class="LC_info">'.$visactions->{'vis'}.'</p>';
5950: } else {
5951: $output .= '<p class="LC_warning">'.$visactions->{'miss'}.'</p>'
5952: .$visactions->{'yous'}.
5953: '<p>'.$visactions->{'gen'}.'<br />'.$visactions->{'coca'};
5954: if (ref($vismsgs) eq 'ARRAY') {
5955: $output .= '<br />'.$visactions->{'make'}.'<ul>';
5956: foreach my $item (@{$vismsgs}) {
5957: $output .= '<li>'.$visactions->{$item}.'</li>';
5958: }
5959: $output .= '</ul>';
1.256 raeburn 5960: }
1.400 raeburn 5961: $output .= '</p>';
1.256 raeburn 5962: }
5963: }
5964: }
1.398 raeburn 5965: my $actionhref = '/adm/createuser';
5966: if ($context eq 'domain') {
5967: $actionhref = '/adm/modifycourse';
5968: }
1.400 raeburn 5969:
5970: my %noedit;
5971: unless ($context eq 'domain') {
5972: %noedit = &get_noedit_fields($cdom,$cnum,$crstype,$row);
5973: }
1.398 raeburn 5974: $output .= '<form name="'.$formname.'" method="post" action="'.$actionhref.'">'."\n".
1.256 raeburn 5975: &Apache::lonhtmlcommon::start_pick_box();
1.237 raeburn 5976: if (ref($row) eq 'ARRAY') {
5977: foreach my $item (@{$row}) {
5978: my $title = $item;
5979: if (ref($lt) eq 'HASH') {
5980: $title = $lt->{$item};
5981: }
1.297 bisitz 5982: $output .= &Apache::lonhtmlcommon::row_title($title);
1.237 raeburn 5983: if ($item eq 'types') {
1.398 raeburn 5984: my $curr_types;
5985: if (ref($currsettings) eq 'HASH') {
5986: $curr_types = $currsettings->{'selfenroll_types'};
5987: }
1.400 raeburn 5988: if ($noedit{$item}) {
5989: if ($curr_types eq '*') {
5990: $output .= &mt('Any user in any domain');
5991: } else {
5992: my @entries = split(/;/,$curr_types);
5993: if (@entries > 0) {
5994: $output .= '<ul>';
5995: foreach my $entry (@entries) {
5996: my ($currdom,$typestr) = split(/:/,$entry);
5997: next if ($typestr eq '');
5998: my $domdesc = &Apache::lonnet::domain($currdom);
5999: my @currinsttypes = split(',',$typestr);
6000: my ($othertitle,$usertypes,$types) =
6001: &Apache::loncommon::sorted_inst_types($currdom);
6002: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
6003: $usertypes->{'any'} = &mt('any user');
6004: if (keys(%{$usertypes}) > 0) {
6005: $usertypes->{'other'} = &mt('other users');
6006: }
6007: my @longinsttypes = map { $usertypes->{$_}; } @currinsttypes;
6008: $output .= '<li>'.$domdesc.':'.join(', ',@longinsttypes).'</li>';
6009: }
6010: }
6011: $output .= '</ul>';
6012: } else {
6013: $output .= &mt('None');
6014: }
6015: }
6016: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6017: next;
6018: }
1.241 raeburn 6019: my $showdomdesc = 1;
6020: my $includeempty = 1;
6021: my $num = 0;
6022: $output .= &Apache::loncommon::start_data_table().
6023: &Apache::loncommon::start_data_table_row()
6024: .'<td colspan="2"><span class="LC_nobreak"><label>'
6025: .&mt('Any user in any domain:')
6026: .' <input type="radio" name="selfenroll_all" value="1" ';
6027: if ($curr_types eq '*') {
6028: $output .= ' checked="checked" ';
6029: }
1.249 raeburn 6030: $output .= 'onchange="javascript:update_types('.
1.418 raeburn 6031: "'selfenroll_all'".');"'.$disabled.' />'.&mt('Yes').'</label>'.
1.249 raeburn 6032: ' <input type="radio" name="selfenroll_all" value="0" ';
1.241 raeburn 6033: if ($curr_types ne '*') {
6034: $output .= ' checked="checked" ';
6035: }
1.249 raeburn 6036: $output .= ' onchange="javascript:update_types('.
1.418 raeburn 6037: "'selfenroll_all'".');"'.$disabled.' />'.&mt('No').'</label></td>'.
1.249 raeburn 6038: &Apache::loncommon::end_data_table_row().
6039: &Apache::loncommon::end_data_table().
6040: &mt('Or').'<br />'.
6041: &Apache::loncommon::start_data_table();
1.241 raeburn 6042: my %currdoms;
1.249 raeburn 6043: if ($curr_types eq '') {
1.241 raeburn 6044: $output .= &new_selfenroll_dom_row($cdom,'0');
6045: } elsif ($curr_types ne '*') {
6046: my @entries = split(/;/,$curr_types);
6047: if (@entries > 0) {
6048: foreach my $entry (@entries) {
6049: my ($currdom,$typestr) = split(/:/,$entry);
6050: $currdoms{$currdom} = 1;
6051: my $domdesc = &Apache::lonnet::domain($currdom);
1.249 raeburn 6052: my @currinsttypes = split(',',$typestr);
1.241 raeburn 6053: $output .= &Apache::loncommon::start_data_table_row()
6054: .'<td valign="top"><span class="LC_nobreak">'.&mt('Domain:').'<b>'
6055: .' '.$domdesc.' ('.$currdom.')'
6056: .'</b><input type="hidden" name="selfenroll_dom_'.$num
6057: .'" value="'.$currdom.'" /></span><br />'
6058: .'<span class="LC_nobreak"><label><input type="checkbox" '
1.418 raeburn 6059: .'name="selfenroll_delete" value="'.$num.'" onchange="javascript:update_types('."'selfenroll_delete','$num'".');"'.$disabled.' />'
1.241 raeburn 6060: .&mt('Delete').'</label></span></td>';
1.249 raeburn 6061: $output .= '<td valign="top"> '.&mt('User types:').'<br />'
1.418 raeburn 6062: .&selfenroll_inst_types($num,$currdom,\@currinsttypes,$readonly).'</td>'
1.241 raeburn 6063: .&Apache::loncommon::end_data_table_row();
6064: $num ++;
6065: }
6066: }
6067: }
1.249 raeburn 6068: my $add_domtitle = &mt('Users in additional domain:');
1.241 raeburn 6069: if ($curr_types eq '*') {
1.249 raeburn 6070: $add_domtitle = &mt('Users in specific domain:');
1.241 raeburn 6071: } elsif ($curr_types eq '') {
1.249 raeburn 6072: $add_domtitle = &mt('Users in other domain:');
1.241 raeburn 6073: }
6074: $output .= &Apache::loncommon::start_data_table_row()
6075: .'<td colspan="2"><span class="LC_nobreak">'.$add_domtitle.'</span><br />'
6076: .&Apache::loncommon::select_dom_form('','selfenroll_newdom',
1.418 raeburn 6077: $includeempty,$showdomdesc,'','','',$readonly)
1.241 raeburn 6078: .'<input type="hidden" name="selfenroll_types_total" value="'.$num.'" />'
6079: .'</td>'.&Apache::loncommon::end_data_table_row()
6080: .&Apache::loncommon::end_data_table();
1.237 raeburn 6081: } elsif ($item eq 'registered') {
6082: my ($regon,$regoff);
1.398 raeburn 6083: my $registered;
6084: if (ref($currsettings) eq 'HASH') {
6085: $registered = $currsettings->{'selfenroll_registered'};
6086: }
1.400 raeburn 6087: if ($noedit{$item}) {
6088: if ($registered) {
6089: $output .= &mt('Must be registered in course');
6090: } else {
6091: $output .= &mt('No requirement');
6092: }
6093: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6094: next;
6095: }
1.398 raeburn 6096: if ($registered) {
1.237 raeburn 6097: $regon = ' checked="checked" ';
1.419 ! raeburn 6098: $regoff = '';
1.237 raeburn 6099: } else {
1.419 ! raeburn 6100: $regon = '';
1.237 raeburn 6101: $regoff = ' checked="checked" ';
6102: }
6103: $output .= '<label>'.
1.419 ! raeburn 6104: '<input type="radio" name="selfenroll_registered" value="1"'.$regon.$disabled.' />'.
1.244 bisitz 6105: &mt('Yes').'</label> <label>'.
1.419 ! raeburn 6106: '<input type="radio" name="selfenroll_registered" value="0"'.$regoff.$disabled.' />'.
1.244 bisitz 6107: &mt('No').'</label>';
1.237 raeburn 6108: } elsif ($item eq 'enroll_dates') {
1.398 raeburn 6109: my ($starttime,$endtime);
6110: if (ref($currsettings) eq 'HASH') {
6111: $starttime = $currsettings->{'selfenroll_start_date'};
6112: $endtime = $currsettings->{'selfenroll_end_date'};
6113: if ($starttime eq '') {
6114: $starttime = $currsettings->{'default_enrollment_start_date'};
6115: }
6116: if ($endtime eq '') {
6117: $endtime = $currsettings->{'default_enrollment_end_date'};
6118: }
1.237 raeburn 6119: }
1.400 raeburn 6120: if ($noedit{$item}) {
6121: $output .= &mt('From: [_1], to: [_2]',&Apache::lonlocal::locallocaltime($starttime),
6122: &Apache::lonlocal::locallocaltime($endtime));
6123: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6124: next;
6125: }
1.237 raeburn 6126: my $startform =
6127: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_start_date',$starttime,
1.418 raeburn 6128: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
1.237 raeburn 6129: my $endform =
6130: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_end_date',$endtime,
1.418 raeburn 6131: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
1.237 raeburn 6132: $output .= &selfenroll_date_forms($startform,$endform);
6133: } elsif ($item eq 'access_dates') {
1.398 raeburn 6134: my ($starttime,$endtime);
6135: if (ref($currsettings) eq 'HASH') {
6136: $starttime = $currsettings->{'selfenroll_start_access'};
6137: $endtime = $currsettings->{'selfenroll_end_access'};
6138: if ($starttime eq '') {
6139: $starttime = $currsettings->{'default_enrollment_start_date'};
6140: }
6141: if ($endtime eq '') {
6142: $endtime = $currsettings->{'default_enrollment_end_date'};
6143: }
1.237 raeburn 6144: }
1.400 raeburn 6145: if ($noedit{$item}) {
6146: $output .= &mt('From: [_1], to: [_2]',&Apache::lonlocal::locallocaltime($starttime),
6147: &Apache::lonlocal::locallocaltime($endtime));
6148: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6149: next;
6150: }
1.237 raeburn 6151: my $startform =
6152: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_start_access',$starttime,
1.418 raeburn 6153: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
1.237 raeburn 6154: my $endform =
6155: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_end_access',$endtime,
1.418 raeburn 6156: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
1.237 raeburn 6157: $output .= &selfenroll_date_forms($startform,$endform);
6158: } elsif ($item eq 'section') {
1.398 raeburn 6159: my $currsec;
6160: if (ref($currsettings) eq 'HASH') {
6161: $currsec = $currsettings->{'selfenroll_section'};
6162: }
1.237 raeburn 6163: my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum);
6164: my $newsecval;
6165: if ($currsec ne 'none' && $currsec ne '') {
6166: if (!defined($sections_count{$currsec})) {
6167: $newsecval = $currsec;
6168: }
6169: }
1.400 raeburn 6170: if ($noedit{$item}) {
6171: if ($currsec ne '') {
6172: $output .= $currsec;
6173: } else {
6174: $output .= &mt('No specific section');
6175: }
6176: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6177: next;
6178: }
1.237 raeburn 6179: my $sections_select =
1.418 raeburn 6180: &Apache::lonuserutils::course_sections(\%sections_count,'st',$currsec,$disabled);
1.237 raeburn 6181: $output .= '<table class="LC_createuser">'."\n".
6182: '<tr class="LC_section_row">'."\n".
6183: '<td align="center">'.&mt('Existing sections')."\n".
6184: '<br />'.$sections_select.'</td><td align="center">'.
6185: &mt('New section').'<br />'."\n".
1.418 raeburn 6186: '<input type="text" name="newsec" size="15" value="'.$newsecval.'"'.$disabled.' />'."\n".
1.237 raeburn 6187: '<input type="hidden" name="sections" value="" />'."\n".
6188: '</td></tr></table>'."\n";
1.276 raeburn 6189: } elsif ($item eq 'approval') {
1.398 raeburn 6190: my ($currnotified,$currapproval,%appchecked);
6191: my %selfdescs = &Apache::lonuserutils::selfenroll_default_descs();
6192: if (ref($currsettings) eq 'HASH') {
6193: $currnotified = $currsettings->{'selfenroll_notifylist'};
6194: $currapproval = $currsettings->{'selfenroll_approval'};
6195: }
6196: if ($currapproval !~ /^[012]$/) {
6197: $currapproval = 0;
6198: }
1.400 raeburn 6199: if ($noedit{$item}) {
6200: $output .= $selfdescs{'approval'}{$currapproval}.
6201: '<br />'.&mt('(Set by Domain Coordinator)');
6202: next;
6203: }
1.398 raeburn 6204: $appchecked{$currapproval} = ' checked="checked"';
6205: for my $i (0..2) {
6206: $output .= '<label>'.
6207: '<input type="radio" name="selfenroll_approval" value="'.$i.'"'.
1.418 raeburn 6208: $appchecked{$i}.' onclick="toggleNotify();"'.$disabled.' />'.
6209: $selfdescs{'approval'}{$i}.'</label>'.(' 'x2);
1.276 raeburn 6210: }
6211: my %advhash = &Apache::lonnet::get_course_adv_roles($cid,1);
6212: my (@ccs,%notified);
1.322 raeburn 6213: my $ccrole = 'cc';
6214: if ($crstype eq 'Community') {
6215: $ccrole = 'co';
6216: }
6217: if ($advhash{$ccrole}) {
6218: @ccs = split(/,/,$advhash{$ccrole});
1.276 raeburn 6219: }
6220: if ($currnotified) {
6221: foreach my $current (split(/,/,$currnotified)) {
6222: $notified{$current} = 1;
6223: if (!grep(/^\Q$current\E$/,@ccs)) {
6224: push(@ccs,$current);
6225: }
6226: }
6227: }
6228: if (@ccs) {
1.398 raeburn 6229: my $style;
6230: unless ($currapproval) {
6231: $style = ' style="display: none;"';
6232: }
6233: $output .= '<br /><div id="notified"'.$style.'>'.
6234: &mt('Personnel to be notified when an enrollment request needs approval, or has been approved:').' '.
6235: &Apache::loncommon::start_data_table().
1.276 raeburn 6236: &Apache::loncommon::start_data_table_row();
6237: my $count = 0;
6238: my $numcols = 4;
6239: foreach my $cc (sort(@ccs)) {
6240: my $notifyon;
6241: my ($ccuname,$ccudom) = split(/:/,$cc);
6242: if ($notified{$cc}) {
6243: $notifyon = ' checked="checked" ';
6244: }
6245: if ($count && !$count%$numcols) {
6246: $output .= &Apache::loncommon::end_data_table_row().
6247: &Apache::loncommon::start_data_table_row()
6248: }
6249: $output .= '<td><span class="LC_nobreak"><label>'.
1.418 raeburn 6250: '<input type="checkbox" name="selfenroll_notify"'.$notifyon.' value="'.$cc.'"'.$disabled.' />'.
1.276 raeburn 6251: &Apache::loncommon::plainname($ccuname,$ccudom).
6252: '</label></span></td>';
1.343 raeburn 6253: $count ++;
1.276 raeburn 6254: }
6255: my $rem = $count%$numcols;
6256: if ($rem) {
6257: my $emptycols = $numcols - $rem;
6258: for (my $i=0; $i<$emptycols; $i++) {
6259: $output .= '<td> </td>';
6260: }
6261: }
6262: $output .= &Apache::loncommon::end_data_table_row().
1.398 raeburn 6263: &Apache::loncommon::end_data_table().
6264: '</div>';
1.276 raeburn 6265: }
6266: } elsif ($item eq 'limit') {
1.398 raeburn 6267: my ($crslimit,$selflimit,$nolimit,$currlim,$currcap);
6268: if (ref($currsettings) eq 'HASH') {
6269: $currlim = $currsettings->{'selfenroll_limit'};
6270: $currcap = $currsettings->{'selfenroll_cap'};
6271: }
1.400 raeburn 6272: if ($noedit{$item}) {
6273: if (($currlim eq 'allstudents') || ($currlim eq 'selfenrolled')) {
6274: if ($currlim eq 'allstudents') {
6275: $output .= &mt('Limit by total students');
6276: } elsif ($currlim eq 'selfenrolled') {
6277: $output .= &mt('Limit by total self-enrolled students');
6278: }
6279: $output .= ' '.&mt('Maximum: [_1]',$currcap).
6280: '<br />'.&mt('(Set by Domain Coordinator)');
6281: } else {
6282: $output .= &mt('No limit').'<br />'.&mt('(Set by Domain Coordinator)');
6283: }
6284: next;
6285: }
1.276 raeburn 6286: if ($currlim eq 'allstudents') {
6287: $crslimit = ' checked="checked" ';
6288: $selflimit = ' ';
6289: $nolimit = ' ';
6290: } elsif ($currlim eq 'selfenrolled') {
6291: $crslimit = ' ';
6292: $selflimit = ' checked="checked" ';
6293: $nolimit = ' ';
6294: } else {
6295: $crslimit = ' ';
6296: $selflimit = ' ';
1.398 raeburn 6297: $nolimit = ' checked="checked" ';
1.276 raeburn 6298: }
6299: $output .= '<table><tr><td><label>'.
1.418 raeburn 6300: '<input type="radio" name="selfenroll_limit" value="none"'.$nolimit.$disabled.'/>'.
1.276 raeburn 6301: &mt('No limit').'</label></td><td><label>'.
1.418 raeburn 6302: '<input type="radio" name="selfenroll_limit" value="allstudents"'.$crslimit.$disabled.'/>'.
1.276 raeburn 6303: &mt('Limit by total students').'</label></td><td><label>'.
1.418 raeburn 6304: '<input type="radio" name="selfenroll_limit" value="selfenrolled"'.$selflimit.$disabled.'/>'.
1.276 raeburn 6305: &mt('Limit by total self-enrolled students').
6306: '</td></tr><tr>'.
6307: '<td> </td><td colspan="2"><span class="LC_nobreak">'.
6308: (' 'x3).&mt('Maximum number allowed: ').
1.418 raeburn 6309: '<input type="text" name="selfenroll_cap" size = "5" value="'.$currcap.'"'.$disabled.' /></td></tr></table>';
1.237 raeburn 6310: }
6311: $output .= &Apache::lonhtmlcommon::row_closure(1);
6312: }
6313: }
1.418 raeburn 6314: $output .= &Apache::lonhtmlcommon::end_pick_box().'<br />';
6315: unless ($readonly) {
6316: $output .= '<input type="button" name="selfenrollconf" value="'
6317: .&mt('Save').'" onclick="validate_types(this.form);" />';
6318: }
6319: $output .= '<input type="hidden" name="action" value="selfenroll" />'
6320: .'<input type="hidden" name="state" value="done" />'."\n"
6321: .$additional.'</form>';
1.237 raeburn 6322: $r->print($output);
6323: return;
6324: }
6325:
1.400 raeburn 6326: sub get_noedit_fields {
6327: my ($cdom,$cnum,$crstype,$row) = @_;
6328: my %noedit;
6329: if (ref($row) eq 'ARRAY') {
6330: my %settings = &Apache::lonnet::get('environment',['internal.coursecode','internal.textbook',
6331: 'internal.selfenrollmgrdc',
6332: 'internal.selfenrollmgrcc'],$cdom,$cnum);
6333: my $type = &Apache::lonuserutils::get_extended_type($cdom,$cnum,$crstype,\%settings);
6334: my (%specific_managebydc,%specific_managebycc,%default_managebydc);
6335: map { $specific_managebydc{$_} = 1; } (split(/,/,$settings{'internal.selfenrollmgrdc'}));
6336: map { $specific_managebycc{$_} = 1; } (split(/,/,$settings{'internal.selfenrollmgrcc'}));
6337: my %domdefaults = &Apache::lonnet::get_domain_defaults($cdom);
6338: map { $default_managebydc{$_} = 1; } (split(/,/,$domdefaults{$type.'selfenrolladmdc'}));
6339:
6340: foreach my $item (@{$row}) {
6341: next if ($specific_managebycc{$item});
6342: if (($specific_managebydc{$item}) || ($default_managebydc{$item})) {
6343: $noedit{$item} = 1;
6344: }
6345: }
6346: }
6347: return %noedit;
6348: }
6349:
6350: sub visible_in_stdcat {
6351: my ($cdom,$cnum,$domconf) = @_;
6352: my ($cathash,%settable,@vismsgs,$cansetvis,$visible);
6353: unless (ref($domconf) eq 'HASH') {
6354: return ($visible,$cansetvis,\@vismsgs);
6355: }
6356: if (ref($domconf->{'coursecategories'}) eq 'HASH') {
6357: if ($domconf->{'coursecategories'}{'togglecats'} eq 'crs') {
1.256 raeburn 6358: $settable{'togglecats'} = 1;
6359: }
1.400 raeburn 6360: if ($domconf->{'coursecategories'}{'categorize'} eq 'crs') {
1.256 raeburn 6361: $settable{'categorize'} = 1;
6362: }
1.400 raeburn 6363: $cathash = $domconf->{'coursecategories'}{'cats'};
1.256 raeburn 6364: }
1.260 raeburn 6365: if ($settable{'togglecats'} && $settable{'categorize'}) {
1.256 raeburn 6366: $cansetvis = &mt('You are able to both assign a course category and choose to exclude this course from the catalog.');
6367: } elsif ($settable{'togglecats'}) {
6368: $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 6369: } elsif ($settable{'categorize'}) {
1.256 raeburn 6370: $cansetvis = &mt('You may assign a course category, but only a Domain Coordinator may choose to exclude this course from the catalog.');
6371: } else {
6372: $cansetvis = &mt('Only a Domain Coordinator may assign a course category or choose to exclude this course from the catalog.');
6373: }
6374:
6375: my %currsettings =
6376: &Apache::lonnet::get('environment',['hidefromcat','categories','internal.coursecode'],
6377: $cdom,$cnum);
1.400 raeburn 6378: $visible = 0;
1.256 raeburn 6379: if ($currsettings{'internal.coursecode'} ne '') {
1.400 raeburn 6380: if (ref($domconf->{'coursecategories'}) eq 'HASH') {
6381: $cathash = $domconf->{'coursecategories'}{'cats'};
1.256 raeburn 6382: if (ref($cathash) eq 'HASH') {
6383: if ($cathash->{'instcode::0'} eq '') {
6384: push(@vismsgs,'dc_addinst');
6385: } else {
6386: $visible = 1;
6387: }
6388: } else {
6389: $visible = 1;
6390: }
6391: } else {
6392: $visible = 1;
6393: }
6394: } else {
6395: if (ref($cathash) eq 'HASH') {
6396: if ($cathash->{'instcode::0'} ne '') {
6397: push(@vismsgs,'dc_instcode');
6398: }
6399: } else {
6400: push(@vismsgs,'dc_instcode');
6401: }
6402: }
6403: if ($currsettings{'categories'} ne '') {
6404: my $cathash;
1.400 raeburn 6405: if (ref($domconf->{'coursecategories'}) eq 'HASH') {
6406: $cathash = $domconf->{'coursecategories'}{'cats'};
1.256 raeburn 6407: if (ref($cathash) eq 'HASH') {
6408: if (keys(%{$cathash}) == 0) {
6409: push(@vismsgs,'dc_catalog');
6410: } elsif ((keys(%{$cathash}) == 1) && ($cathash->{'instcode::0'} ne '')) {
6411: push(@vismsgs,'dc_categories');
6412: } else {
6413: my @currcategories = split('&',$currsettings{'categories'});
6414: my $matched = 0;
6415: foreach my $cat (@currcategories) {
6416: if ($cathash->{$cat} ne '') {
6417: $visible = 1;
6418: $matched = 1;
6419: last;
6420: }
6421: }
6422: if (!$matched) {
1.260 raeburn 6423: if ($settable{'categorize'}) {
1.256 raeburn 6424: push(@vismsgs,'chgcat');
6425: } else {
6426: push(@vismsgs,'dc_chgcat');
6427: }
6428: }
6429: }
6430: }
6431: }
6432: } else {
6433: if (ref($cathash) eq 'HASH') {
6434: if ((keys(%{$cathash}) > 1) ||
6435: (keys(%{$cathash}) == 1) && ($cathash->{'instcode::0'} eq '')) {
1.260 raeburn 6436: if ($settable{'categorize'}) {
1.256 raeburn 6437: push(@vismsgs,'addcat');
6438: } else {
6439: push(@vismsgs,'dc_addcat');
6440: }
6441: }
6442: }
6443: }
6444: if ($currsettings{'hidefromcat'} eq 'yes') {
6445: $visible = 0;
6446: if ($settable{'togglecats'}) {
6447: unshift(@vismsgs,'unhide');
6448: } else {
6449: unshift(@vismsgs,'dc_unhide')
6450: }
6451: }
1.400 raeburn 6452: return ($visible,$cansetvis,\@vismsgs);
6453: }
6454:
6455: sub cat_visibility {
6456: my %visactions = &Apache::lonlocal::texthash(
6457: vis => 'This course/community currently appears in the Course/Community Catalog for this domain.',
6458: 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.',
6459: miss => 'This course/community does not currently appear in the Course/Community Catalog for this domain.',
6460: none => 'Display of a course catalog is disabled for this domain.',
6461: yous => 'You should remedy this if you plan to allow self-enrollment, otherwise students will have difficulty finding this course.',
6462: 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.',
6463: make => 'Make any changes to self-enrollment settings below, click "Save", then take action to include the course in the Catalog:',
6464: take => 'Take the following action to ensure the course appears in the Catalog:',
6465: dc_chgconf => 'Ask a domain coordinator to change the Catalog type for this domain.',
6466: dc_setcode => 'Ask a domain coordinator to assign a six character code to the course',
6467: dc_unhide => 'Ask a domain coordinator to change the "Exclude from course catalog" setting.',
6468: dc_addinst => 'Ask a domain coordinator to enable display the catalog of "Official courses (with institutional codes)".',
6469: dc_instcode => 'Ask a domain coordinator to assign an institutional code (if this is an official course).',
6470: dc_catalog => 'Ask a domain coordinator to enable or create at least one course category in the domain.',
6471: dc_categories => 'Ask a domain coordinator to create a hierarchy of categories and sub categories for courses in the domain.',
6472: 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',
6473: dc_addcat => 'Ask a domain coordinator to assign a category to the course.',
6474: );
6475: $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>"');
6476: $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>"');
6477: $visactions{'addcat'} = &mt('Use [_1]Categorize course[_2] to assign a category to the course.','"<a href="/adm/courseprefs?phase=display&actions=courseinfo">','</a>"');
6478: return \%visactions;
1.256 raeburn 6479: }
6480:
1.241 raeburn 6481: sub new_selfenroll_dom_row {
6482: my ($newdom,$num) = @_;
6483: my $domdesc = &Apache::lonnet::domain($newdom);
6484: my $output;
6485: if ($domdesc ne '') {
6486: $output .= &Apache::loncommon::start_data_table_row()
6487: .'<td valign="top"><span class="LC_nobreak">'.&mt('Domain:').' <b>'.$domdesc
6488: .' ('.$newdom.')</b><input type="hidden" name="selfenroll_dom_'.$num
1.249 raeburn 6489: .'" value="'.$newdom.'" /></span><br />'
6490: .'<span class="LC_nobreak"><label><input type="checkbox" '
6491: .'name="selfenroll_activate" value="'.$num.'" '
6492: .'onchange="javascript:update_types('
6493: ."'selfenroll_activate','$num'".');" />'
6494: .&mt('Activate').'</label></span></td>';
1.241 raeburn 6495: my @currinsttypes;
6496: $output .= '<td>'.&mt('User types:').'<br />'
6497: .&selfenroll_inst_types($num,$newdom,\@currinsttypes).'</td>'
6498: .&Apache::loncommon::end_data_table_row();
6499: }
6500: return $output;
6501: }
6502:
6503: sub selfenroll_inst_types {
1.418 raeburn 6504: my ($num,$currdom,$currinsttypes,$readonly) = @_;
1.241 raeburn 6505: my $output;
6506: my $numinrow = 4;
6507: my $count = 0;
6508: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($currdom);
1.247 raeburn 6509: my $othervalue = 'any';
1.418 raeburn 6510: my $disabled;
6511: if ($readonly) {
6512: $disabled = ' disabled="disabled"';
6513: }
1.241 raeburn 6514: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
1.251 raeburn 6515: if (keys(%{$usertypes}) > 0) {
1.247 raeburn 6516: $othervalue = 'other';
6517: }
1.241 raeburn 6518: $output .= '<table><tr>';
6519: foreach my $type (@{$types}) {
6520: if (($count > 0) && ($count%$numinrow == 0)) {
6521: $output .= '</tr><tr>';
6522: }
6523: if (defined($usertypes->{$type})) {
1.257 raeburn 6524: my $esc_type = &escape($type);
1.241 raeburn 6525: $output .= '<td><span class="LC_nobreak"><label><input type = "checkbox" value="'.
1.257 raeburn 6526: $esc_type.'" ';
1.241 raeburn 6527: if (ref($currinsttypes) eq 'ARRAY') {
6528: if (@{$currinsttypes} > 0) {
1.249 raeburn 6529: if (grep(/^any$/,@{$currinsttypes})) {
6530: $output .= 'checked="checked"';
1.257 raeburn 6531: } elsif (grep(/^\Q$esc_type\E$/,@{$currinsttypes})) {
1.241 raeburn 6532: $output .= 'checked="checked"';
6533: }
1.249 raeburn 6534: } else {
6535: $output .= 'checked="checked"';
1.241 raeburn 6536: }
6537: }
1.418 raeburn 6538: $output .= ' name="selfenroll_types_'.$num.'"'.$disabled.' />'.$usertypes->{$type}.'</label></span></td>';
1.241 raeburn 6539: }
6540: $count ++;
6541: }
6542: if (($count > 0) && ($count%$numinrow == 0)) {
6543: $output .= '</tr><tr>';
6544: }
1.249 raeburn 6545: $output .= '<td><span class="LC_nobreak"><label><input type = "checkbox" value="'.$othervalue.'"';
1.241 raeburn 6546: if (ref($currinsttypes) eq 'ARRAY') {
6547: if (@{$currinsttypes} > 0) {
1.249 raeburn 6548: if (grep(/^any$/,@{$currinsttypes})) {
6549: $output .= ' checked="checked"';
6550: } elsif ($othervalue eq 'other') {
6551: if (grep(/^\Q$othervalue\E$/,@{$currinsttypes})) {
6552: $output .= ' checked="checked"';
6553: }
1.241 raeburn 6554: }
1.249 raeburn 6555: } else {
6556: $output .= ' checked="checked"';
1.241 raeburn 6557: }
1.249 raeburn 6558: } else {
6559: $output .= ' checked="checked"';
1.241 raeburn 6560: }
1.418 raeburn 6561: $output .= ' name="selfenroll_types_'.$num.'"'.$disabled.' />'.$othertitle.'</label></span></td></tr></table>';
1.241 raeburn 6562: }
6563: return $output;
6564: }
6565:
1.237 raeburn 6566: sub selfenroll_date_forms {
6567: my ($startform,$endform) = @_;
6568: my $output .= &Apache::lonhtmlcommon::start_pick_box()."\n".
1.244 bisitz 6569: &Apache::lonhtmlcommon::row_title(&mt('Start date'),
1.237 raeburn 6570: 'LC_oddrow_value')."\n".
6571: $startform."\n".
6572: &Apache::lonhtmlcommon::row_closure(1).
1.244 bisitz 6573: &Apache::lonhtmlcommon::row_title(&mt('End date'),
1.237 raeburn 6574: 'LC_oddrow_value')."\n".
6575: $endform."\n".
6576: &Apache::lonhtmlcommon::row_closure(1).
6577: &Apache::lonhtmlcommon::end_pick_box();
6578: return $output;
6579: }
6580:
1.239 raeburn 6581: sub print_userchangelogs_display {
1.415 raeburn 6582: my ($r,$context,$permission,$brcrum) = @_;
1.363 raeburn 6583: my $formname = 'rolelog';
1.418 raeburn 6584: my ($username,$domain,$crstype,$viewablesec,%roleslog);
1.363 raeburn 6585: if ($context eq 'domain') {
6586: $domain = $env{'request.role.domain'};
6587: %roleslog=&Apache::lonnet::dump_dom('nohist_rolelog',$domain);
6588: } else {
6589: if ($context eq 'course') {
6590: $domain = $env{'course.'.$env{'request.course.id'}.'.domain'};
6591: $username = $env{'course.'.$env{'request.course.id'}.'.num'};
6592: $crstype = &Apache::loncommon::course_type();
1.418 raeburn 6593: $viewablesec = &Apache::lonuserutils::viewable_section($permission);
1.363 raeburn 6594: my %saveable_parameters = ('show' => 'scalar',);
6595: &Apache::loncommon::store_course_settings('roles_log',
6596: \%saveable_parameters);
6597: &Apache::loncommon::restore_course_settings('roles_log',
6598: \%saveable_parameters);
6599: } elsif ($context eq 'author') {
6600: $domain = $env{'user.domain'};
6601: if ($env{'request.role'} =~ m{^au\./\Q$domain\E/$}) {
6602: $username = $env{'user.name'};
6603: } else {
6604: undef($domain);
6605: }
6606: }
6607: if ($domain ne '' && $username ne '') {
6608: %roleslog=&Apache::lonnet::dump('nohist_rolelog',$domain,$username);
6609: }
6610: }
1.239 raeburn 6611: if ((keys(%roleslog))[0]=~/^error\:/) { undef(%roleslog); }
6612:
1.415 raeburn 6613: my $helpitem;
6614: if ($context eq 'course') {
6615: $helpitem = 'Course_User_Logs';
6616: }
6617: push (@{$brcrum},
6618: {href => '/adm/createuser?action=changelogs',
6619: text => 'User Management Logs',
6620: help => $helpitem});
6621: my $bread_crumbs_component = 'User Changes';
6622: my $args = { bread_crumbs => $brcrum,
6623: bread_crumbs_component => $bread_crumbs_component};
6624:
6625: # Create navigation javascript
6626: my $jsnav = &userlogdisplay_js($formname);
6627:
6628: my $jscript = (<<ENDSCRIPT);
6629: <script type="text/javascript">
6630: // <![CDATA[
6631: $jsnav
6632: // ]]>
6633: </script>
6634: ENDSCRIPT
6635:
6636: # print page header
6637: $r->print(&header($jscript,$args));
6638:
1.239 raeburn 6639: # set defaults
6640: my $now = time();
6641: my $defstart = $now - (7*24*3600); #7 days ago
6642: my %defaults = (
6643: page => '1',
6644: show => '10',
6645: role => 'any',
6646: chgcontext => 'any',
6647: rolelog_start_date => $defstart,
6648: rolelog_end_date => $now,
6649: );
6650: my $more_records = 0;
6651:
6652: # set current
6653: my %curr;
6654: foreach my $item ('show','page','role','chgcontext') {
6655: $curr{$item} = $env{'form.'.$item};
6656: }
6657: my ($startdate,$enddate) =
6658: &Apache::lonuserutils::get_dates_from_form('rolelog_start_date','rolelog_end_date');
6659: $curr{'rolelog_start_date'} = $startdate;
6660: $curr{'rolelog_end_date'} = $enddate;
6661: foreach my $key (keys(%defaults)) {
6662: if ($curr{$key} eq '') {
6663: $curr{$key} = $defaults{$key};
6664: }
6665: }
1.248 raeburn 6666: my (%whodunit,%changed,$version);
6667: ($version) = ($r->dir_config('lonVersion') =~ /^([\d\.]+)\-/);
1.239 raeburn 6668: my ($minshown,$maxshown);
1.255 raeburn 6669: $minshown = 1;
1.239 raeburn 6670: my $count = 0;
1.415 raeburn 6671: if ($curr{'show'} =~ /\D/) {
6672: $curr{'page'} = 1;
6673: } else {
1.239 raeburn 6674: $maxshown = $curr{'page'} * $curr{'show'};
6675: if ($curr{'page'} > 1) {
6676: $minshown = 1 + ($curr{'page'} - 1) * $curr{'show'};
6677: }
6678: }
1.301 bisitz 6679:
1.327 raeburn 6680: # Form Header
6681: $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">'.
1.363 raeburn 6682: &role_display_filter($context,$formname,$domain,$username,\%curr,
6683: $version,$crstype));
1.327 raeburn 6684:
6685: my $showntableheader = 0;
6686:
6687: # Table Header
6688: my $tableheader =
6689: &Apache::loncommon::start_data_table_header_row()
6690: .'<th> </th>'
6691: .'<th>'.&mt('When').'</th>'
6692: .'<th>'.&mt('Who made the change').'</th>'
6693: .'<th>'.&mt('Changed User').'</th>'
1.363 raeburn 6694: .'<th>'.&mt('Role').'</th>';
6695:
6696: if ($context eq 'course') {
6697: $tableheader .= '<th>'.&mt('Section').'</th>';
6698: }
6699: $tableheader .=
6700: '<th>'.&mt('Context').'</th>'
1.327 raeburn 6701: .'<th>'.&mt('Start').'</th>'
6702: .'<th>'.&mt('End').'</th>'
6703: .&Apache::loncommon::end_data_table_header_row();
6704:
6705: # Display user change log data
1.239 raeburn 6706: foreach my $id (sort { $roleslog{$b}{'exe_time'}<=>$roleslog{$a}{'exe_time'} } (keys(%roleslog))) {
6707: next if (($roleslog{$id}{'exe_time'} < $curr{'rolelog_start_date'}) ||
6708: ($roleslog{$id}{'exe_time'} > $curr{'rolelog_end_date'}));
1.415 raeburn 6709: if ($curr{'show'} !~ /\D/) {
1.239 raeburn 6710: if ($count >= $curr{'page'} * $curr{'show'}) {
6711: $more_records = 1;
6712: last;
6713: }
6714: }
6715: if ($curr{'role'} ne 'any') {
6716: next if ($roleslog{$id}{'logentry'}{'role'} ne $curr{'role'});
6717: }
6718: if ($curr{'chgcontext'} ne 'any') {
6719: if ($curr{'chgcontext'} eq 'selfenroll') {
6720: next if (!$roleslog{$id}{'logentry'}{'selfenroll'});
6721: } else {
6722: next if ($roleslog{$id}{'logentry'}{'context'} ne $curr{'chgcontext'});
6723: }
6724: }
1.418 raeburn 6725: if (($context eq 'course') && ($viewablesec ne '')) {
6726: next if ($roleslog{$id}{'logentry'}{'section'} ne $viewablesec);
6727: }
1.239 raeburn 6728: $count ++;
6729: next if ($count < $minshown);
1.327 raeburn 6730: unless ($showntableheader) {
1.415 raeburn 6731: $r->print(&Apache::loncommon::start_data_table()
1.327 raeburn 6732: .$tableheader);
6733: $r->rflush();
6734: $showntableheader = 1;
6735: }
1.239 raeburn 6736: if ($whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}} eq '') {
6737: $whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}} =
6738: &Apache::loncommon::plainname($roleslog{$id}{'exe_uname'},$roleslog{$id}{'exe_udom'});
6739: }
6740: if ($changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}} eq '') {
6741: $changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}} =
6742: &Apache::loncommon::plainname($roleslog{$id}{'uname'},$roleslog{$id}{'udom'});
6743: }
6744: my $sec = $roleslog{$id}{'logentry'}{'section'};
6745: if ($sec eq '') {
6746: $sec = &mt('None');
6747: }
6748: my ($rolestart,$roleend);
6749: if ($roleslog{$id}{'delflag'}) {
6750: $rolestart = &mt('deleted');
6751: $roleend = &mt('deleted');
6752: } else {
6753: $rolestart = $roleslog{$id}{'logentry'}{'start'};
6754: $roleend = $roleslog{$id}{'logentry'}{'end'};
6755: if ($rolestart eq '' || $rolestart == 0) {
6756: $rolestart = &mt('No start date');
6757: } else {
6758: $rolestart = &Apache::lonlocal::locallocaltime($rolestart);
6759: }
6760: if ($roleend eq '' || $roleend == 0) {
6761: $roleend = &mt('No end date');
6762: } else {
6763: $roleend = &Apache::lonlocal::locallocaltime($roleend);
6764: }
6765: }
6766: my $chgcontext = $roleslog{$id}{'logentry'}{'context'};
6767: if ($roleslog{$id}{'logentry'}{'selfenroll'}) {
6768: $chgcontext = 'selfenroll';
6769: }
1.363 raeburn 6770: my %lt = &rolechg_contexts($context,$crstype);
1.239 raeburn 6771: if ($chgcontext ne '' && $lt{$chgcontext} ne '') {
6772: $chgcontext = $lt{$chgcontext};
6773: }
1.327 raeburn 6774: $r->print(
1.301 bisitz 6775: &Apache::loncommon::start_data_table_row()
6776: .'<td>'.$count.'</td>'
6777: .'<td>'.&Apache::lonlocal::locallocaltime($roleslog{$id}{'exe_time'}).'</td>'
6778: .'<td>'.$whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}}.'</td>'
6779: .'<td>'.$changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}}.'</td>'
1.363 raeburn 6780: .'<td>'.&Apache::lonnet::plaintext($roleslog{$id}{'logentry'}{'role'},$crstype).'</td>');
6781: if ($context eq 'course') {
6782: $r->print('<td>'.$sec.'</td>');
6783: }
6784: $r->print(
6785: '<td>'.$chgcontext.'</td>'
1.301 bisitz 6786: .'<td>'.$rolestart.'</td>'
6787: .'<td>'.$roleend.'</td>'
1.327 raeburn 6788: .&Apache::loncommon::end_data_table_row()."\n");
1.301 bisitz 6789: }
6790:
1.327 raeburn 6791: if ($showntableheader) { # Table footer, if content displayed above
1.415 raeburn 6792: $r->print(&Apache::loncommon::end_data_table().
6793: &userlogdisplay_navlinks(\%curr,$more_records));
1.327 raeburn 6794: } else { # No content displayed above
1.301 bisitz 6795: $r->print('<p class="LC_info">'
6796: .&mt('There are no records to display.')
6797: .'</p>'
6798: );
1.239 raeburn 6799: }
1.301 bisitz 6800:
1.327 raeburn 6801: # Form Footer
6802: $r->print(
6803: '<input type="hidden" name="page" value="'.$curr{'page'}.'" />'
6804: .'<input type="hidden" name="action" value="changelogs" />'
6805: .'</form>');
6806: return;
6807: }
1.301 bisitz 6808:
1.416 raeburn 6809: sub print_useraccesslogs_display {
6810: my ($r,$uname,$udom,$permission,$brcrum) = @_;
6811: my $formname = 'accesslog';
6812: my $form = 'document.accesslog';
6813:
6814: # set breadcrumbs
6815: my %breadcrumb_text = &singleuser_breadcrumb();
6816: push (@{$brcrum},
6817: {href => "javascript:backPage($form)",
6818: text => $breadcrumb_text{'search'}});
6819: my (@prevphases,$prevphasestr);
6820: if ($env{'form.prevphases'}) {
6821: @prevphases = split(/,/,$env{'form.prevphases'});
6822: $prevphasestr = $env{'form.prevphases'};
6823: }
6824: if (($env{'form.phase'} eq 'userpicked') || (grep(/^userpicked$/,@prevphases))) {
6825: push(@{$brcrum},
6826: {href => "javascript:backPage($form,'get_user_info','select')",
6827: text => $breadcrumb_text{'userpicked'}});
6828: if ($env{'form.phase'} eq 'userpicked') {
6829: $prevphasestr = 'userpicked';
6830: }
6831: }
6832: push(@{$brcrum},
6833: {href => '/adm/createuser?action=accesslogs',
6834: text => 'User access logs',
6835: help => 'User_Access_Logs'});
6836: my $bread_crumbs_component = 'User Access Logs';
6837: my $args = { bread_crumbs => $brcrum,
6838: bread_crumbs_component => 'User Management'};
6839:
1.417 raeburn 6840: # set javascript
1.416 raeburn 6841: my ($jsback,$elements) = &crumb_utilities();
6842: my $jsnav = &userlogdisplay_js($formname);
6843:
6844: my $jscript = (<<ENDSCRIPT);
6845: <script type="text/javascript">
6846: // <![CDATA[
6847:
6848: $jsback
6849: $jsnav
6850:
6851: // ]]>
6852: </script>
6853:
6854: ENDSCRIPT
6855:
1.417 raeburn 6856: # print page header
1.416 raeburn 6857: $r->print(&header($jscript,$args));
6858:
6859: # early out unless log data can be displayed.
6860: unless ($permission->{'activity'}) {
6861: $r->print('<p class="LC_warning">'
6862: .&mt('You do not have rights to display user access logs.')
6863: .'</p>'
6864: .&earlyout_accesslog_form($formname,$prevphasestr,$udom));
6865: return;
6866: }
6867:
6868: unless ($udom eq $env{'request.role.domain'}) {
6869: $r->print('<p class="LC_warning">'
6870: .&mt("User's domain must match role's domain")
6871: .'</p>'
6872: .&earlyout_accesslog_form($formname,$prevphasestr,$udom));
1.417 raeburn 6873: return;
1.416 raeburn 6874: }
6875:
6876: if (($uname eq '') || ($udom eq '')) {
6877: $r->print('<p class="LC_warning">'
6878: .&mt('Invalid username or domain')
6879: .'</p>'
6880: .&earlyout_accesslog_form($formname,$prevphasestr,$udom));
6881: return;
6882: }
6883:
6884: # set defaults
6885: my $now = time();
6886: my $defstart = $now - (7*24*3600);
6887: my %defaults = (
6888: page => '1',
6889: show => '10',
6890: activity => 'any',
6891: accesslog_start_date => $defstart,
6892: accesslog_end_date => $now,
6893: );
6894: my $more_records = 0;
6895:
6896: # set current
6897: my %curr;
6898: foreach my $item ('show','page','activity') {
6899: $curr{$item} = $env{'form.'.$item};
6900: }
6901: my ($startdate,$enddate) =
6902: &Apache::lonuserutils::get_dates_from_form('accesslog_start_date','accesslog_end_date');
6903: $curr{'accesslog_start_date'} = $startdate;
6904: $curr{'accesslog_end_date'} = $enddate;
6905: foreach my $key (keys(%defaults)) {
6906: if ($curr{$key} eq '') {
6907: $curr{$key} = $defaults{$key};
6908: }
6909: }
6910: my ($minshown,$maxshown);
6911: $minshown = 1;
6912: my $count = 0;
6913: if ($curr{'show'} =~ /\D/) {
6914: $curr{'page'} = 1;
6915: } else {
6916: $maxshown = $curr{'page'} * $curr{'show'};
6917: if ($curr{'page'} > 1) {
6918: $minshown = 1 + ($curr{'page'} - 1) * $curr{'show'};
6919: }
6920: }
6921:
6922: # form header
6923: $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">'.
6924: &activity_display_filter($formname,\%curr));
6925:
6926: my $showntableheader = 0;
6927: my ($nav_script,$nav_links);
6928:
6929: # table header
6930: my $tableheader =
6931: &Apache::loncommon::start_data_table_header_row()
6932: .'<th> </th>'
6933: .'<th>'.&mt('When').'</th>'
6934: .'<th>'.&mt('HostID').'</th>'
6935: .'<th>'.&mt('Event').'</th>'
6936: .'<th>'.&mt('Other data').'</th>'
6937: .&Apache::loncommon::end_data_table_header_row();
6938:
6939: my %filters=(
6940: start => $curr{'accesslog_start_date'},
6941: end => $curr{'accesslog_end_date'},
6942: action => $curr{'activity'},
6943: );
6944:
6945: my $reply = &Apache::lonnet::userlog_query($uname,$udom,%filters);
6946: unless ( ($reply =~/^timeout/) || ($reply =~/^error/) ) {
6947: my (%courses,%missing);
6948: my @results = split(/\&/,$reply);
6949: foreach my $item (reverse(@results)) {
6950: my ($timestamp,$host,$event) = split(/:/,$item);
6951: next unless ($event =~ /^(Log|Role)/);
6952: if ($curr{'show'} !~ /\D/) {
6953: if ($count >= $curr{'page'} * $curr{'show'}) {
6954: $more_records = 1;
6955: last;
6956: }
6957: }
6958: $count ++;
6959: next if ($count < $minshown);
6960: unless ($showntableheader) {
6961: $r->print($nav_script
6962: .&Apache::loncommon::start_data_table()
6963: .$tableheader);
6964: $r->rflush();
6965: $showntableheader = 1;
6966: }
1.418 raeburn 6967: my ($shown,$extra);
1.416 raeburn 6968: my ($event,$data) = split(/\s+/,&unescape($event));
6969: if ($event eq 'Role') {
6970: my ($rolecode,$extent) = split(/\./,$data,2);
6971: next if ($extent eq '');
6972: my ($crstype,$desc,$info);
1.418 raeburn 6973: if ($extent =~ m{^/($match_domain)/($match_courseid)(?:/(\w+)|)$}) {
6974: my ($cdom,$cnum,$sec) = ($1,$2,$3);
1.416 raeburn 6975: my $cid = $cdom.'_'.$cnum;
6976: if (exists($courses{$cid})) {
6977: $crstype = $courses{$cid}{'type'};
6978: $desc = $courses{$cid}{'description'};
6979: } elsif ($missing{$cid}) {
6980: $crstype = 'Course';
6981: $desc = 'Course/Community';
6982: } else {
6983: my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',$cnum,undef,undef,'.');
6984: if (ref($crsinfo{$cdom.'_'.$cnum}) eq 'HASH') {
6985: $courses{$cid} = $crsinfo{$cid};
6986: $crstype = $crsinfo{$cid}{'type'};
6987: $desc = $crsinfo{$cid}{'description'};
6988: } else {
6989: $missing{$cid} = 1;
6990: }
6991: }
6992: $extra = &mt($crstype).': <a href="/public/'.$cdom.'/'.$cnum.'/syllabus">'.$desc.'</a>';
1.418 raeburn 6993: if ($sec ne '') {
6994: $extra .= ' ('.&mt('Section: [_1]',$sec).')';
6995: }
1.416 raeburn 6996: } elsif ($extent =~ m{^/($match_domain)/($match_username|$)}) {
6997: my ($dom,$name) = ($1,$2);
6998: if ($rolecode eq 'au') {
6999: $extra = '';
7000: } elsif ($rolecode =~ /^(ca|aa)$/) {
1.417 raeburn 7001: $extra = &mt('Authoring Space: [_1]',$name.':'.$dom);
1.416 raeburn 7002: } elsif ($rolecode =~ /^(li|dg|dh|dc|sc)$/) {
7003: $extra = &mt('Domain: [_1]',$dom);
7004: }
7005: }
7006: my $rolename;
7007: if ($rolecode =~ m{^cr/($match_domain)/($match_username)/(\w+)}) {
7008: my $role = $3;
1.417 raeburn 7009: my $owner = "($2:$1)";
1.416 raeburn 7010: if ($2 eq $1.'-domainconfig') {
7011: $owner = '(ad hoc)';
1.417 raeburn 7012: }
1.416 raeburn 7013: $rolename = &mt('Custom role: [_1]',$role.' '.$owner);
7014: } else {
7015: $rolename = &Apache::lonnet::plaintext($rolecode,$crstype);
7016: }
7017: $shown = &mt('Role selection: [_1]',$rolename);
7018: } else {
7019: $shown = &mt($event);
7020: if ($data ne '') {
7021: $extra = &mt('Client IP address: [_1]',$data);
7022: }
7023: }
7024: $r->print(
7025: &Apache::loncommon::start_data_table_row()
7026: .'<td>'.$count.'</td>'
7027: .'<td>'.&Apache::lonlocal::locallocaltime($timestamp).'</td>'
7028: .'<td>'.$host.'</td>'
7029: .'<td>'.$shown.'</td>'
7030: .'<td>'.$extra.'</td>'
7031: .&Apache::loncommon::end_data_table_row()."\n");
7032: }
7033: }
7034:
7035: if ($showntableheader) { # Table footer, if content displayed above
7036: $r->print(&Apache::loncommon::end_data_table().
7037: &userlogdisplay_navlinks(\%curr,$more_records));
7038: } else { # No content displayed above
7039: $r->print('<p class="LC_info">'
7040: .&mt('There are no records to display.')
7041: .'</p>');
7042: }
7043:
7044: # Form Footer
7045: $r->print(
7046: '<input type="hidden" name="currstate" value="" />'
7047: .'<input type="hidden" name="accessuname" value="'.$uname.'" />'
7048: .'<input type="hidden" name="accessudom" value="'.$udom.'" />'
7049: .'<input type="hidden" name="page" value="'.$curr{'page'}.'" />'
7050: .'<input type="hidden" name="prevphases" value="'.$prevphasestr.'" />'
7051: .'<input type="hidden" name="phase" value="activity" />'
7052: .'<input type="hidden" name="action" value="accesslogs" />'
7053: .'<input type="hidden" name="srchdomain" value="'.$udom.'" />'
7054: .'<input type="hidden" name="srchby" value="'.$env{'form.srchby'}.'" />'
7055: .'<input type="hidden" name="srchtype" value="'.$env{'form.srchtype'}.'" />'
7056: .'<input type="hidden" name="srchterm" value="'.&HTML::Entities::encode($env{'form.srchterm'},'<>"&').'" />'
7057: .'<input type="hidden" name="srchin" value="'.$env{'form.srchin'}.'" />'
7058: .'</form>');
7059: return;
7060: }
7061:
7062: sub earlyout_accesslog_form {
7063: my ($formname,$prevphasestr,$udom) = @_;
7064: my $srchterm = &HTML::Entities::encode($env{'form.srchterm'},'<>"&');
7065: return <<"END";
7066: <form action="/adm/createuser" method="post" name="$formname">
7067: <input type="hidden" name="currstate" value="" />
7068: <input type="hidden" name="prevphases" value="$prevphasestr" />
7069: <input type="hidden" name="phase" value="activity" />
7070: <input type="hidden" name="action" value="accesslogs" />
7071: <input type="hidden" name="srchdomain" value="$udom" />
7072: <input type="hidden" name="srchby" value="$env{'form.srchby'}" />
7073: <input type="hidden" name="srchtype" value="$env{'form.srchtype'}" />
7074: <input type="hidden" name="srchterm" value="$srchterm" />
7075: <input type="hidden" name="srchin" value="$env{'form.srchin'}" />
7076: </form>
7077: END
7078: }
7079:
7080: sub activity_display_filter {
7081: my ($formname,$curr) = @_;
7082: my $nolink = 1;
7083: my $output = '<table><tr><td valign="top">'.
7084: '<span class="LC_nobreak"><b>'.&mt('Actions/page:').'</b></span><br />'.
7085: &Apache::lonmeta::selectbox('show',$curr->{'show'},undef,
7086: (&mt('all'),5,10,20,50,100,1000,10000)).
7087: '</td><td> </td>';
7088: my $startform =
7089: &Apache::lonhtmlcommon::date_setter($formname,'accesslog_start_date',
7090: $curr->{'accesslog_start_date'},undef,
7091: undef,undef,undef,undef,undef,undef,$nolink);
7092: my $endform =
7093: &Apache::lonhtmlcommon::date_setter($formname,'accesslog_end_date',
7094: $curr->{'accesslog_end_date'},undef,
7095: undef,undef,undef,undef,undef,undef,$nolink);
7096: my %lt = &Apache::lonlocal::texthash (
7097: activity => 'Activity',
7098: Role => 'Role selection',
7099: log => 'Log-in or Logout',
7100: );
7101: $output .= '<td valign="top"><b>'.&mt('Window during which actions occurred:').'</b><br />'.
7102: '<table><tr><td>'.&mt('After:').
7103: '</td><td>'.$startform.'</td></tr>'.
7104: '<tr><td>'.&mt('Before:').'</td>'.
7105: '<td>'.$endform.'</td></tr></table>'.
7106: '</td>'.
7107: '<td> </td>'.
7108: '<td valign="top"><b>'.&mt('Activities').'</b><br />'.
7109: '<select name="activity"><option value="any"';
7110: if ($curr->{'activity'} eq 'any') {
7111: $output .= ' selected="selected"';
7112: }
7113: $output .= '>'.&mt('Any').'</option>'."\n";
7114: foreach my $activity ('Role','log') {
7115: my $selstr = '';
7116: if ($activity eq $curr->{'activity'}) {
7117: $selstr = ' selected="selected"';
7118: }
7119: $output .= '<option value="'.$activity.'"'.$selstr.'>'.$lt{$activity}.'</option>';
7120: }
7121: $output .= '</select></td>'.
7122: '</tr></table>';
7123: # Update Display button
7124: $output .= '<p>'
7125: .'<input type="submit" value="'.&mt('Update Display').'" />'
7126: .'</p>';
7127: return $output;
7128: }
7129:
1.415 raeburn 7130: sub userlogdisplay_js {
7131: my ($formname) = @_;
7132: return <<"ENDSCRIPT";
7133:
1.239 raeburn 7134: function chgPage(caller) {
7135: if (caller == 'previous') {
7136: document.$formname.page.value --;
7137: }
7138: if (caller == 'next') {
7139: document.$formname.page.value ++;
7140: }
1.327 raeburn 7141: document.$formname.submit();
1.239 raeburn 7142: return;
7143: }
7144: ENDSCRIPT
1.415 raeburn 7145: }
7146:
7147: sub userlogdisplay_navlinks {
7148: my ($curr,$more_records) = @_;
7149: return unless(ref($curr) eq 'HASH');
7150: # Navigation Buttons
7151: my $nav_links = '<p>';
7152: if (($curr->{'page'} > 1) || ($more_records)) {
7153: if (($curr->{'page'} > 1) && ($curr->{'show'} !~ /\D/)) {
7154: $nav_links .= '<input type="button"'
7155: .' onclick="javascript:chgPage('."'previous'".');"'
7156: .' value="'.&mt('Previous [_1] changes',$curr->{'show'})
7157: .'" /> ';
7158: }
7159: if ($more_records) {
7160: $nav_links .= '<input type="button"'
7161: .' onclick="javascript:chgPage('."'next'".');"'
7162: .' value="'.&mt('Next [_1] changes',$curr->{'show'})
7163: .'" />';
1.301 bisitz 7164: }
7165: }
1.415 raeburn 7166: $nav_links .= '</p>';
7167: return $nav_links;
1.239 raeburn 7168: }
7169:
7170: sub role_display_filter {
1.363 raeburn 7171: my ($context,$formname,$cdom,$cnum,$curr,$version,$crstype) = @_;
7172: my $lctype;
7173: if ($context eq 'course') {
7174: $lctype = lc($crstype);
7175: }
1.239 raeburn 7176: my $nolink = 1;
7177: my $output = '<table><tr><td valign="top">'.
1.301 bisitz 7178: '<span class="LC_nobreak"><b>'.&mt('Changes/page:').'</b></span><br />'.
1.239 raeburn 7179: &Apache::lonmeta::selectbox('show',$curr->{'show'},undef,
7180: (&mt('all'),5,10,20,50,100,1000,10000)).
7181: '</td><td> </td>';
7182: my $startform =
7183: &Apache::lonhtmlcommon::date_setter($formname,'rolelog_start_date',
7184: $curr->{'rolelog_start_date'},undef,
7185: undef,undef,undef,undef,undef,undef,$nolink);
7186: my $endform =
7187: &Apache::lonhtmlcommon::date_setter($formname,'rolelog_end_date',
7188: $curr->{'rolelog_end_date'},undef,
7189: undef,undef,undef,undef,undef,undef,$nolink);
1.363 raeburn 7190: my %lt = &rolechg_contexts($context,$crstype);
1.301 bisitz 7191: $output .= '<td valign="top"><b>'.&mt('Window during which changes occurred:').'</b><br />'.
7192: '<table><tr><td>'.&mt('After:').
7193: '</td><td>'.$startform.'</td></tr>'.
7194: '<tr><td>'.&mt('Before:').'</td>'.
7195: '<td>'.$endform.'</td></tr></table>'.
7196: '</td>'.
7197: '<td> </td>'.
1.239 raeburn 7198: '<td valign="top"><b>'.&mt('Role:').'</b><br />'.
7199: '<select name="role"><option value="any"';
7200: if ($curr->{'role'} eq 'any') {
7201: $output .= ' selected="selected"';
7202: }
7203: $output .= '>'.&mt('Any').'</option>'."\n";
1.363 raeburn 7204: my @roles = &Apache::lonuserutils::roles_by_context($context,1,$crstype);
1.239 raeburn 7205: foreach my $role (@roles) {
7206: my $plrole;
7207: if ($role eq 'cr') {
7208: $plrole = &mt('Custom Role');
7209: } else {
1.318 raeburn 7210: $plrole=&Apache::lonnet::plaintext($role,$crstype);
1.239 raeburn 7211: }
7212: my $selstr = '';
7213: if ($role eq $curr->{'role'}) {
7214: $selstr = ' selected="selected"';
7215: }
7216: $output .= ' <option value="'.$role.'"'.$selstr.'>'.$plrole.'</option>';
7217: }
1.301 bisitz 7218: $output .= '</select></td>'.
7219: '<td> </td>'.
7220: '<td valign="top"><b>'.
1.239 raeburn 7221: &mt('Context:').'</b><br /><select name="chgcontext">';
1.363 raeburn 7222: my @posscontexts;
7223: if ($context eq 'course') {
1.376 raeburn 7224: @posscontexts = ('any','automated','updatenow','createcourse','course','domain','selfenroll','requestcourses');
1.363 raeburn 7225: } elsif ($context eq 'domain') {
7226: @posscontexts = ('any','domain','requestauthor','domconfig','server');
7227: } else {
7228: @posscontexts = ('any','author','domain');
7229: }
7230: foreach my $chgtype (@posscontexts) {
1.239 raeburn 7231: my $selstr = '';
7232: if ($curr->{'chgcontext'} eq $chgtype) {
1.301 bisitz 7233: $selstr = ' selected="selected"';
1.239 raeburn 7234: }
1.363 raeburn 7235: if ($context eq 'course') {
1.376 raeburn 7236: if (($chgtype eq 'automated') || ($chgtype eq 'updatenow')) {
1.363 raeburn 7237: next if (!&Apache::lonnet::auto_run($cnum,$cdom));
7238: }
1.239 raeburn 7239: }
7240: $output .= '<option value="'.$chgtype.'"'.$selstr.'>'.$lt{$chgtype}.'</option>'."\n";
1.248 raeburn 7241: }
1.303 bisitz 7242: $output .= '</select></td>'
7243: .'</tr></table>';
7244:
7245: # Update Display button
7246: $output .= '<p>'
7247: .'<input type="submit" value="'.&mt('Update Display').'" />'
7248: .'</p>';
7249:
7250: # Server version info
1.363 raeburn 7251: my $needsrev = '2.11.0';
7252: if ($context eq 'course') {
7253: $needsrev = '2.7.0';
7254: }
7255:
1.303 bisitz 7256: $output .= '<p class="LC_info">'
7257: .&mt('Only changes made from servers running LON-CAPA [_1] or later are displayed.'
1.363 raeburn 7258: ,$needsrev);
1.248 raeburn 7259: if ($version) {
1.303 bisitz 7260: $output .= ' '.&mt('This LON-CAPA server is version [_1]',$version);
7261: }
7262: $output .= '</p><hr />';
1.239 raeburn 7263: return $output;
7264: }
7265:
7266: sub rolechg_contexts {
1.363 raeburn 7267: my ($context,$crstype) = @_;
7268: my %lt;
7269: if ($context eq 'course') {
7270: %lt = &Apache::lonlocal::texthash (
1.239 raeburn 7271: any => 'Any',
1.376 raeburn 7272: automated => 'Automated Enrollment',
1.239 raeburn 7273: updatenow => 'Roster Update',
7274: createcourse => 'Course Creation',
7275: course => 'User Management in course',
7276: domain => 'User Management in domain',
1.313 raeburn 7277: selfenroll => 'Self-enrolled',
1.318 raeburn 7278: requestcourses => 'Course Request',
1.239 raeburn 7279: );
1.363 raeburn 7280: if ($crstype eq 'Community') {
7281: $lt{'createcourse'} = &mt('Community Creation');
7282: $lt{'course'} = &mt('User Management in community');
7283: $lt{'requestcourses'} = &mt('Community Request');
7284: }
7285: } elsif ($context eq 'domain') {
7286: %lt = &Apache::lonlocal::texthash (
7287: any => 'Any',
7288: domain => 'User Management in domain',
7289: requestauthor => 'Authoring Request',
7290: server => 'Command line script (DC role)',
7291: domconfig => 'Self-enrolled',
7292: );
7293: } else {
7294: %lt = &Apache::lonlocal::texthash (
7295: any => 'Any',
7296: domain => 'User Management in domain',
7297: author => 'User Management by author',
7298: );
7299: }
1.239 raeburn 7300: return %lt;
7301: }
7302:
1.27 matthew 7303: #-------------------------------------------------- functions for &phase_two
1.160 raeburn 7304: sub user_search_result {
1.221 raeburn 7305: my ($context,$srch) = @_;
1.160 raeburn 7306: my %allhomes;
7307: my %inst_matches;
7308: my %srch_results;
1.181 raeburn 7309: my ($response,$currstate,$forcenewuser,$dirsrchres);
1.183 raeburn 7310: $srch->{'srchterm'} =~ s/\s+/ /g;
1.176 raeburn 7311: if ($srch->{'srchby'} !~ /^(uname|lastname|lastfirst)$/) {
1.160 raeburn 7312: $response = &mt('Invalid search.');
7313: }
7314: if ($srch->{'srchin'} !~ /^(crs|dom|alc|instd)$/) {
7315: $response = &mt('Invalid search.');
7316: }
1.177 raeburn 7317: if ($srch->{'srchtype'} !~ /^(exact|contains|begins)$/) {
1.160 raeburn 7318: $response = &mt('Invalid search.');
7319: }
7320: if ($srch->{'srchterm'} eq '') {
7321: $response = &mt('You must enter a search term.');
7322: }
1.183 raeburn 7323: if ($srch->{'srchterm'} =~ /^\s+$/) {
7324: $response = &mt('Your search term must contain more than just spaces.');
7325: }
1.160 raeburn 7326: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'instd')) {
7327: if (($srch->{'srchdomain'} eq '') ||
1.163 albertel 7328: ! (&Apache::lonnet::domain($srch->{'srchdomain'}))) {
1.160 raeburn 7329: $response = &mt('You must specify a valid domain when searching in a domain or institutional directory.')
7330: }
7331: }
7332: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs') ||
7333: ($srch->{'srchin'} eq 'alc')) {
1.176 raeburn 7334: if ($srch->{'srchby'} eq 'uname') {
1.243 raeburn 7335: my $unamecheck = $srch->{'srchterm'};
7336: if ($srch->{'srchtype'} eq 'contains') {
7337: if ($unamecheck !~ /^\w/) {
7338: $unamecheck = 'a'.$unamecheck;
7339: }
7340: }
7341: if ($unamecheck !~ /^$match_username$/) {
1.176 raeburn 7342: $response = &mt('You must specify a valid username. Only the following are allowed: letters numbers - . @');
7343: }
1.160 raeburn 7344: }
7345: }
1.180 raeburn 7346: if ($response ne '') {
1.413 raeburn 7347: $response = '<span class="LC_warning">'.$response.'</span><br />';
1.180 raeburn 7348: }
1.160 raeburn 7349: if ($srch->{'srchin'} eq 'instd') {
1.412 raeburn 7350: my $instd_chk = &instdirectorysrch_check($srch);
1.160 raeburn 7351: if ($instd_chk ne 'ok') {
1.412 raeburn 7352: my $domd_chk = &domdirectorysrch_check($srch);
1.413 raeburn 7353: $response .= '<span class="LC_warning">'.$instd_chk.'</span><br />';
1.412 raeburn 7354: if ($domd_chk eq 'ok') {
1.413 raeburn 7355: $response .= &mt('You may want to search in the LON-CAPA domain instead of the institutional directory.');
1.412 raeburn 7356: }
1.415 raeburn 7357: $response .= '<br />';
1.412 raeburn 7358: }
7359: } else {
1.417 raeburn 7360: unless (($context eq 'requestcrs') && ($srch->{'srchtype'} eq 'exact')) {
1.412 raeburn 7361: my $domd_chk = &domdirectorysrch_check($srch);
7362: if ($domd_chk ne 'ok') {
7363: my $instd_chk = &instdirectorysrch_check($srch);
1.413 raeburn 7364: $response .= '<span class="LC_warning">'.$domd_chk.'</span><br />';
1.412 raeburn 7365: if ($instd_chk eq 'ok') {
1.413 raeburn 7366: $response .= &mt('You may want to search in the institutional directory instead of the LON-CAPA domain.');
1.412 raeburn 7367: }
1.415 raeburn 7368: $response .= '<br />';
1.412 raeburn 7369: }
1.160 raeburn 7370: }
7371: }
7372: if ($response ne '') {
1.180 raeburn 7373: return ($currstate,$response);
1.160 raeburn 7374: }
7375: if ($srch->{'srchby'} eq 'uname') {
7376: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs')) {
7377: if ($env{'form.forcenew'}) {
7378: if ($srch->{'srchdomain'} ne $env{'request.role.domain'}) {
7379: my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
7380: if ($uhome eq 'no_host') {
7381: my $domdesc = &Apache::lonnet::domain($env{'request.role.domain'},'description');
1.180 raeburn 7382: my $showdom = &display_domain_info($env{'request.role.domain'});
7383: $response = &mt('New users can only be created in the domain to which your current role belongs - [_1].',$showdom);
1.160 raeburn 7384: } else {
1.179 raeburn 7385: $currstate = 'modify';
1.160 raeburn 7386: }
7387: } else {
1.179 raeburn 7388: $currstate = 'modify';
1.160 raeburn 7389: }
7390: } else {
7391: if ($srch->{'srchin'} eq 'dom') {
1.162 raeburn 7392: if ($srch->{'srchtype'} eq 'exact') {
7393: my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
7394: if ($uhome eq 'no_host') {
1.179 raeburn 7395: ($currstate,$response,$forcenewuser) =
1.221 raeburn 7396: &build_search_response($context,$srch,%srch_results);
1.162 raeburn 7397: } else {
1.179 raeburn 7398: $currstate = 'modify';
1.416 raeburn 7399: if ($env{'form.action'} eq 'accesslogs') {
7400: $currstate = 'activity';
7401: }
1.310 raeburn 7402: my $uname = $srch->{'srchterm'};
7403: my $udom = $srch->{'srchdomain'};
7404: $srch_results{$uname.':'.$udom} =
7405: { &Apache::lonnet::get('environment',
7406: ['firstname',
7407: 'lastname',
7408: 'permanentemail'],
7409: $udom,$uname)
7410: };
1.162 raeburn 7411: }
7412: } else {
7413: %srch_results = &Apache::lonnet::usersearch($srch);
1.179 raeburn 7414: ($currstate,$response,$forcenewuser) =
1.221 raeburn 7415: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 7416: }
7417: } else {
1.167 albertel 7418: my $courseusers = &get_courseusers();
1.162 raeburn 7419: if ($srch->{'srchtype'} eq 'exact') {
1.167 albertel 7420: if (exists($courseusers->{$srch->{'srchterm'}.':'.$srch->{'srchdomain'}})) {
1.179 raeburn 7421: $currstate = 'modify';
1.162 raeburn 7422: } else {
1.179 raeburn 7423: ($currstate,$response,$forcenewuser) =
1.221 raeburn 7424: &build_search_response($context,$srch,%srch_results);
1.162 raeburn 7425: }
1.160 raeburn 7426: } else {
1.167 albertel 7427: foreach my $user (keys(%$courseusers)) {
1.162 raeburn 7428: my ($cuname,$cudomain) = split(/:/,$user);
7429: if ($cudomain eq $srch->{'srchdomain'}) {
1.177 raeburn 7430: my $matched = 0;
7431: if ($srch->{'srchtype'} eq 'begins') {
7432: if ($cuname =~ /^\Q$srch->{'srchterm'}\E/i) {
7433: $matched = 1;
7434: }
7435: } else {
7436: if ($cuname =~ /\Q$srch->{'srchterm'}\E/i) {
7437: $matched = 1;
7438: }
7439: }
7440: if ($matched) {
1.167 albertel 7441: $srch_results{$user} =
7442: {&Apache::lonnet::get('environment',
7443: ['firstname',
7444: 'lastname',
1.194 albertel 7445: 'permanentemail'],
7446: $cudomain,$cuname)};
1.162 raeburn 7447: }
7448: }
7449: }
1.179 raeburn 7450: ($currstate,$response,$forcenewuser) =
1.221 raeburn 7451: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 7452: }
7453: }
7454: }
7455: } elsif ($srch->{'srchin'} eq 'alc') {
1.179 raeburn 7456: $currstate = 'query';
1.160 raeburn 7457: } elsif ($srch->{'srchin'} eq 'instd') {
1.181 raeburn 7458: ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
7459: if ($dirsrchres eq 'ok') {
7460: ($currstate,$response,$forcenewuser) =
1.221 raeburn 7461: &build_search_response($context,$srch,%srch_results);
1.181 raeburn 7462: } else {
7463: my $showdom = &display_domain_info($srch->{'srchdomain'});
7464: $response = '<span class="LC_warning">'.
7465: &mt('Institutional directory search is not available in domain: [_1]',$showdom).
7466: '</span><br />'.
7467: &mt('You may want to search in the LON-CAPA domain instead of the institutional directory.').
1.415 raeburn 7468: '<br />';
1.181 raeburn 7469: }
1.160 raeburn 7470: }
7471: } else {
7472: if ($srch->{'srchin'} eq 'dom') {
7473: %srch_results = &Apache::lonnet::usersearch($srch);
1.179 raeburn 7474: ($currstate,$response,$forcenewuser) =
1.221 raeburn 7475: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 7476: } elsif ($srch->{'srchin'} eq 'crs') {
1.167 albertel 7477: my $courseusers = &get_courseusers();
7478: foreach my $user (keys(%$courseusers)) {
1.160 raeburn 7479: my ($uname,$udom) = split(/:/,$user);
7480: my %names = &Apache::loncommon::getnames($uname,$udom);
7481: my %emails = &Apache::loncommon::getemails($uname,$udom);
7482: if ($srch->{'srchby'} eq 'lastname') {
7483: if ((($srch->{'srchtype'} eq 'exact') &&
7484: ($names{'lastname'} eq $srch->{'srchterm'})) ||
1.177 raeburn 7485: (($srch->{'srchtype'} eq 'begins') &&
7486: ($names{'lastname'} =~ /^\Q$srch->{'srchterm'}\E/i)) ||
1.160 raeburn 7487: (($srch->{'srchtype'} eq 'contains') &&
7488: ($names{'lastname'} =~ /\Q$srch->{'srchterm'}\E/i))) {
7489: $srch_results{$user} = {firstname => $names{'firstname'},
7490: lastname => $names{'lastname'},
7491: permanentemail => $emails{'permanentemail'},
7492: };
7493: }
7494: } elsif ($srch->{'srchby'} eq 'lastfirst') {
7495: my ($srchlast,$srchfirst) = split(/,/,$srch->{'srchterm'});
1.177 raeburn 7496: $srchlast =~ s/\s+$//;
7497: $srchfirst =~ s/^\s+//;
1.160 raeburn 7498: if ($srch->{'srchtype'} eq 'exact') {
7499: if (($names{'lastname'} eq $srchlast) &&
7500: ($names{'firstname'} eq $srchfirst)) {
7501: $srch_results{$user} = {firstname => $names{'firstname'},
7502: lastname => $names{'lastname'},
7503: permanentemail => $emails{'permanentemail'},
7504:
7505: };
7506: }
1.177 raeburn 7507: } elsif ($srch->{'srchtype'} eq 'begins') {
7508: if (($names{'lastname'} =~ /^\Q$srchlast\E/i) &&
7509: ($names{'firstname'} =~ /^\Q$srchfirst\E/i)) {
7510: $srch_results{$user} = {firstname => $names{'firstname'},
7511: lastname => $names{'lastname'},
7512: permanentemail => $emails{'permanentemail'},
7513: };
7514: }
7515: } else {
1.160 raeburn 7516: if (($names{'lastname'} =~ /\Q$srchlast\E/i) &&
7517: ($names{'firstname'} =~ /\Q$srchfirst\E/i)) {
7518: $srch_results{$user} = {firstname => $names{'firstname'},
7519: lastname => $names{'lastname'},
7520: permanentemail => $emails{'permanentemail'},
7521: };
7522: }
7523: }
7524: }
7525: }
1.179 raeburn 7526: ($currstate,$response,$forcenewuser) =
1.221 raeburn 7527: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 7528: } elsif ($srch->{'srchin'} eq 'alc') {
1.179 raeburn 7529: $currstate = 'query';
1.160 raeburn 7530: } elsif ($srch->{'srchin'} eq 'instd') {
1.181 raeburn 7531: ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
7532: if ($dirsrchres eq 'ok') {
7533: ($currstate,$response,$forcenewuser) =
1.221 raeburn 7534: &build_search_response($context,$srch,%srch_results);
1.181 raeburn 7535: } else {
1.412 raeburn 7536: my $showdom = &display_domain_info($srch->{'srchdomain'});
7537: $response = '<span class="LC_warning">'.
1.181 raeburn 7538: &mt('Institutional directory search is not available in domain: [_1]',$showdom).
7539: '</span><br />'.
7540: &mt('You may want to search in the LON-CAPA domain instead of the institutional directory.').
1.415 raeburn 7541: '<br />';
1.181 raeburn 7542: }
1.160 raeburn 7543: }
7544: }
1.179 raeburn 7545: return ($currstate,$response,$forcenewuser,\%srch_results);
1.160 raeburn 7546: }
7547:
1.412 raeburn 7548: sub domdirectorysrch_check {
7549: my ($srch) = @_;
7550: my $response;
7551: my %dom_inst_srch = &Apache::lonnet::get_dom('configuration',
7552: ['directorysrch'],$srch->{'srchdomain'});
7553: my $showdom = &display_domain_info($srch->{'srchdomain'});
7554: if (ref($dom_inst_srch{'directorysrch'}) eq 'HASH') {
7555: if ($dom_inst_srch{'directorysrch'}{'lcavailable'} eq '0') {
7556: return &mt('LON-CAPA directory search is not available in domain: [_1]',$showdom);
7557: }
7558: if ($dom_inst_srch{'directorysrch'}{'lclocalonly'}) {
7559: if ($env{'request.role.domain'} ne $srch->{'srchdomain'}) {
7560: return &mt('LON-CAPA directory search in domain: [_1] is only allowed for users with a current role in the domain.',$showdom);
7561: }
7562: }
7563: }
7564: return 'ok';
7565: }
7566:
7567: sub instdirectorysrch_check {
1.160 raeburn 7568: my ($srch) = @_;
7569: my $can_search = 0;
7570: my $response;
7571: my %dom_inst_srch = &Apache::lonnet::get_dom('configuration',
7572: ['directorysrch'],$srch->{'srchdomain'});
1.180 raeburn 7573: my $showdom = &display_domain_info($srch->{'srchdomain'});
1.160 raeburn 7574: if (ref($dom_inst_srch{'directorysrch'}) eq 'HASH') {
7575: if (!$dom_inst_srch{'directorysrch'}{'available'}) {
1.180 raeburn 7576: return &mt('Institutional directory search is not available in domain: [_1]',$showdom);
1.160 raeburn 7577: }
7578: if ($dom_inst_srch{'directorysrch'}{'localonly'}) {
7579: if ($env{'request.role.domain'} ne $srch->{'srchdomain'}) {
1.180 raeburn 7580: return &mt('Institutional directory search in domain: [_1] is only allowed for users with a current role in the domain.',$showdom);
1.160 raeburn 7581: }
7582: my @usertypes = split(/:/,$env{'environment.inststatus'});
7583: if (!@usertypes) {
7584: push(@usertypes,'default');
7585: }
7586: if (ref($dom_inst_srch{'directorysrch'}{'cansearch'}) eq 'ARRAY') {
7587: foreach my $type (@usertypes) {
7588: if (grep(/^\Q$type\E$/,@{$dom_inst_srch{'directorysrch'}{'cansearch'}})) {
7589: $can_search = 1;
7590: last;
7591: }
7592: }
7593: }
7594: if (!$can_search) {
7595: my ($insttypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($srch->{'srchdomain'});
7596: my @longtypes;
7597: foreach my $item (@usertypes) {
1.229 raeburn 7598: if (defined($insttypes->{$item})) {
7599: push (@longtypes,$insttypes->{$item});
7600: } elsif ($item eq 'default') {
7601: push (@longtypes,&mt('other'));
7602: }
1.160 raeburn 7603: }
7604: my $insttype_str = join(', ',@longtypes);
1.180 raeburn 7605: return &mt('Institutional directory search in domain: [_1] is not available to your user type: ',$showdom).$insttype_str;
1.229 raeburn 7606: }
1.160 raeburn 7607: } else {
7608: $can_search = 1;
7609: }
7610: } else {
1.180 raeburn 7611: return &mt('Institutional directory search has not been configured for domain: [_1]',$showdom);
1.160 raeburn 7612: }
7613: my %longtext = &Apache::lonlocal::texthash (
1.167 albertel 7614: uname => 'username',
1.160 raeburn 7615: lastfirst => 'last name, first name',
1.167 albertel 7616: lastname => 'last name',
1.172 raeburn 7617: contains => 'contains',
1.178 raeburn 7618: exact => 'as exact match to',
7619: begins => 'begins with',
1.160 raeburn 7620: );
7621: if ($can_search) {
7622: if (ref($dom_inst_srch{'directorysrch'}{'searchby'}) eq 'ARRAY') {
7623: if (!grep(/^\Q$srch->{'srchby'}\E$/,@{$dom_inst_srch{'directorysrch'}{'searchby'}})) {
1.180 raeburn 7624: return &mt('Institutional directory search in domain: [_1] is not available for searching by "[_2]"',$showdom,$longtext{$srch->{'srchby'}});
1.160 raeburn 7625: }
7626: } else {
1.180 raeburn 7627: return &mt('Institutional directory search in domain: [_1] is not available.', $showdom);
1.160 raeburn 7628: }
7629: }
7630: if ($can_search) {
1.178 raeburn 7631: if (ref($dom_inst_srch{'directorysrch'}{'searchtypes'}) eq 'ARRAY') {
7632: if (grep(/^\Q$srch->{'srchtype'}\E/,@{$dom_inst_srch{'directorysrch'}{'searchtypes'}})) {
7633: return 'ok';
7634: } else {
1.180 raeburn 7635: return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
1.178 raeburn 7636: }
7637: } else {
7638: if ((($dom_inst_srch{'directorysrch'}{'searchtypes'} eq 'specify') &&
7639: ($srch->{'srchtype'} eq 'exact' || $srch->{'srchtype'} eq 'contains')) ||
7640: ($dom_inst_srch{'directorysrch'}{'searchtypes'} eq $srch->{'srchtype'})) {
7641: return 'ok';
7642: } else {
1.180 raeburn 7643: return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
1.178 raeburn 7644: }
1.160 raeburn 7645: }
7646: }
7647: }
7648:
7649: sub get_courseusers {
7650: my %advhash;
1.167 albertel 7651: my $classlist = &Apache::loncoursedata::get_classlist();
1.160 raeburn 7652: my %coursepersonnel=&Apache::lonnet::get_course_adv_roles();
7653: foreach my $role (sort(keys(%coursepersonnel))) {
7654: foreach my $user (split(/\,/,$coursepersonnel{$role})) {
1.167 albertel 7655: if (!exists($classlist->{$user})) {
7656: $classlist->{$user} = [];
7657: }
1.160 raeburn 7658: }
7659: }
1.167 albertel 7660: return $classlist;
1.160 raeburn 7661: }
7662:
7663: sub build_search_response {
1.221 raeburn 7664: my ($context,$srch,%srch_results) = @_;
1.179 raeburn 7665: my ($currstate,$response,$forcenewuser);
1.160 raeburn 7666: my %names = (
1.330 bisitz 7667: 'uname' => 'username',
7668: 'lastname' => 'last name',
1.160 raeburn 7669: 'lastfirst' => 'last name, first name',
1.330 bisitz 7670: 'crs' => 'this course',
7671: 'dom' => 'LON-CAPA domain',
7672: 'instd' => 'the institutional directory for domain',
1.160 raeburn 7673: );
7674:
7675: my %single = (
1.180 raeburn 7676: begins => 'A match',
1.160 raeburn 7677: contains => 'A match',
1.180 raeburn 7678: exact => 'An exact match',
1.160 raeburn 7679: );
7680: my %nomatch = (
1.180 raeburn 7681: begins => 'No match',
1.160 raeburn 7682: contains => 'No match',
1.180 raeburn 7683: exact => 'No exact match',
1.160 raeburn 7684: );
7685: if (keys(%srch_results) > 1) {
1.179 raeburn 7686: $currstate = 'select';
1.160 raeburn 7687: } else {
7688: if (keys(%srch_results) == 1) {
1.416 raeburn 7689: if ($env{'form.action'} eq 'accesslogs') {
7690: $currstate = 'activity';
7691: } else {
7692: $currstate = 'modify';
7693: }
1.180 raeburn 7694: $response = &mt("$single{$srch->{'srchtype'}} was found for the $names{$srch->{'srchby'}} ([_1]) in $names{$srch->{'srchin'}}.",$srch->{'srchterm'});
7695: if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
1.330 bisitz 7696: $response .= ': '.&display_domain_info($srch->{'srchdomain'});
1.180 raeburn 7697: }
1.330 bisitz 7698: } else { # Search has nothing found. Prepare message to user.
7699: $response = '<span class="LC_warning">';
1.180 raeburn 7700: if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
1.330 bisitz 7701: $response .= &mt("$nomatch{$srch->{'srchtype'}} found for the $names{$srch->{'srchby'}} [_1] in $names{$srch->{'srchin'}}: [_2]",
7702: '<b>'.$srch->{'srchterm'}.'</b>',
7703: &display_domain_info($srch->{'srchdomain'}));
7704: } else {
7705: $response .= &mt("$nomatch{$srch->{'srchtype'}} found for the $names{$srch->{'srchby'}} [_1] in $names{$srch->{'srchin'}}.",
7706: '<b>'.$srch->{'srchterm'}.'</b>');
1.180 raeburn 7707: }
7708: $response .= '</span>';
1.330 bisitz 7709:
1.160 raeburn 7710: if ($srch->{'srchin'} ne 'alc') {
7711: $forcenewuser = 1;
7712: my $cansrchinst = 0;
7713: if ($srch->{'srchdomain'}) {
7714: my %domconfig = &Apache::lonnet::get_dom('configuration',['directorysrch'],$srch->{'srchdomain'});
7715: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
7716: if ($domconfig{'directorysrch'}{'available'}) {
7717: $cansrchinst = 1;
7718: }
7719: }
7720: }
1.180 raeburn 7721: if ((($srch->{'srchby'} eq 'lastfirst') ||
7722: ($srch->{'srchby'} eq 'lastname')) &&
7723: ($srch->{'srchin'} eq 'dom')) {
7724: if ($cansrchinst) {
7725: $response .= '<br />'.&mt('You may want to broaden your search to a search of the institutional directory for the domain.');
1.160 raeburn 7726: }
7727: }
1.180 raeburn 7728: if ($srch->{'srchin'} eq 'crs') {
7729: $response .= '<br />'.&mt('You may want to broaden your search to the selected LON-CAPA domain.');
7730: }
7731: }
1.305 raeburn 7732: my $createdom = $env{'request.role.domain'};
7733: if ($context eq 'requestcrs') {
7734: if ($env{'form.coursedom'} ne '') {
7735: $createdom = $env{'form.coursedom'};
7736: }
7737: }
1.416 raeburn 7738: unless (($env{'form.action'} eq 'accesslogs') || (($srch->{'srchby'} eq 'uname') && ($srch->{'srchin'} eq 'dom') &&
7739: ($srch->{'srchtype'} eq 'exact') && ($srch->{'srchdomain'} eq $createdom))) {
1.221 raeburn 7740: my $cancreate =
1.305 raeburn 7741: &Apache::lonuserutils::can_create_user($createdom,$context);
7742: my $targetdom = '<span class="LC_cusr_emph">'.$createdom.'</span>';
1.221 raeburn 7743: if ($cancreate) {
1.305 raeburn 7744: my $showdom = &display_domain_info($createdom);
1.266 bisitz 7745: $response .= '<br /><br />'
7746: .'<b>'.&mt('To add a new user:').'</b>'
1.305 raeburn 7747: .'<br />';
7748: if ($context eq 'requestcrs') {
7749: $response .= &mt("(You can only define new users in the new course's domain - [_1])",$targetdom);
7750: } else {
7751: $response .= &mt("(You can only create new users in your current role's domain - [_1])",$targetdom);
7752: }
7753: $response .='<ul><li>'
1.266 bisitz 7754: .&mt("Set 'Domain/institution to search' to: [_1]",'<span class="LC_cusr_emph">'.$showdom.'</span>')
7755: .'</li><li>'
7756: .&mt("Set 'Search criteria' to: [_1]username is ..... in selected LON-CAPA domain[_2]",'<span class="LC_cusr_emph">','</span>')
7757: .'</li><li>'
7758: .&mt('Provide the proposed username')
7759: .'</li><li>'
7760: .&mt("Click 'Search'")
7761: .'</li></ul><br />';
1.221 raeburn 7762: } else {
7763: my $helplink = ' href="javascript:helpMenu('."'display'".')"';
1.305 raeburn 7764: $response .= '<br /><br />';
7765: if ($context eq 'requestcrs') {
1.314 raeburn 7766: $response .= &mt("You are not authorized to define new users in the new course's domain - [_1].",$targetdom);
1.305 raeburn 7767: } else {
7768: $response .= &mt("You are not authorized to create new users in your current role's domain - [_1].",$targetdom);
7769: }
7770: $response .= '<br />'
7771: .&mt('Please contact the [_1]helpdesk[_2] if you need to create a new user.'
1.266 bisitz 7772: ,' <a'.$helplink.'>'
7773: ,'</a>')
1.415 raeburn 7774: .'<br />';
1.221 raeburn 7775: }
1.160 raeburn 7776: }
7777: }
7778: }
1.179 raeburn 7779: return ($currstate,$response,$forcenewuser);
1.160 raeburn 7780: }
7781:
1.180 raeburn 7782: sub display_domain_info {
7783: my ($dom) = @_;
7784: my $output = $dom;
7785: if ($dom ne '') {
7786: my $domdesc = &Apache::lonnet::domain($dom,'description');
7787: if ($domdesc ne '') {
7788: $output .= ' <span class="LC_cusr_emph">('.$domdesc.')</span>';
7789: }
7790: }
7791: return $output;
7792: }
7793:
1.160 raeburn 7794: sub crumb_utilities {
7795: my %elements = (
7796: crtuser => {
7797: srchterm => 'text',
1.172 raeburn 7798: srchin => 'selectbox',
1.160 raeburn 7799: srchby => 'selectbox',
7800: srchtype => 'selectbox',
7801: srchdomain => 'selectbox',
7802: },
1.207 raeburn 7803: crtusername => {
7804: srchterm => 'text',
7805: srchdomain => 'selectbox',
7806: },
1.160 raeburn 7807: docustom => {
7808: rolename => 'selectbox',
7809: newrolename => 'textbox',
7810: },
1.179 raeburn 7811: studentform => {
7812: srchterm => 'text',
7813: srchin => 'selectbox',
7814: srchby => 'selectbox',
7815: srchtype => 'selectbox',
7816: srchdomain => 'selectbox',
7817: },
1.160 raeburn 7818: );
7819:
7820: my $jsback .= qq|
7821: function backPage(formname,prevphase,prevstate) {
1.211 raeburn 7822: if (typeof prevphase == 'undefined') {
7823: formname.phase.value = '';
7824: }
7825: else {
7826: formname.phase.value = prevphase;
7827: }
7828: if (typeof prevstate == 'undefined') {
7829: formname.currstate.value = '';
7830: }
7831: else {
7832: formname.currstate.value = prevstate;
7833: }
1.160 raeburn 7834: formname.submit();
7835: }
7836: |;
7837: return ($jsback,\%elements);
7838: }
7839:
1.26 matthew 7840: sub course_level_table {
1.375 raeburn 7841: my ($inccourses,$showcredits,$defaultcredits) = @_;
7842: return unless (ref($inccourses) eq 'HASH');
1.26 matthew 7843: my $table = '';
1.62 www 7844: # Custom Roles?
7845:
1.190 raeburn 7846: my %customroles=&Apache::lonuserutils::my_custom_roles();
1.89 raeburn 7847: my %lt=&Apache::lonlocal::texthash(
7848: 'exs' => "Existing sections",
7849: 'new' => "Define new section",
7850: 'ssd' => "Set Start Date",
7851: 'sed' => "Set End Date",
1.131 raeburn 7852: 'crl' => "Course Level",
1.89 raeburn 7853: 'act' => "Activate",
7854: 'rol' => "Role",
7855: 'ext' => "Extent",
1.113 raeburn 7856: 'grs' => "Section",
1.375 raeburn 7857: 'crd' => "Credits",
1.89 raeburn 7858: 'sta' => "Start",
7859: 'end' => "End"
7860: );
1.62 www 7861:
1.375 raeburn 7862: foreach my $protectedcourse (sort(keys(%{$inccourses}))) {
1.135 raeburn 7863: my $thiscourse=$protectedcourse;
1.26 matthew 7864: $thiscourse=~s:_:/:g;
7865: my %coursedata=&Apache::lonnet::coursedescription($thiscourse);
1.365 raeburn 7866: my $isowner = &Apache::lonuserutils::is_courseowner($protectedcourse,$coursedata{'internal.courseowner'});
1.26 matthew 7867: my $area=$coursedata{'description'};
1.321 raeburn 7868: my $crstype=$coursedata{'type'};
1.135 raeburn 7869: if (!defined($area)) { $area=&mt('Unavailable course').': '.$protectedcourse; }
1.89 raeburn 7870: my ($domain,$cnum)=split(/\//,$thiscourse);
1.115 albertel 7871: my %sections_count;
1.101 albertel 7872: if (defined($env{'request.course.id'})) {
7873: if ($env{'request.course.id'} eq $domain.'_'.$cnum) {
1.115 albertel 7874: %sections_count =
7875: &Apache::loncommon::get_sections($domain,$cnum);
1.92 raeburn 7876: }
7877: }
1.321 raeburn 7878: my @roles = &Apache::lonuserutils::roles_by_context('course','',$crstype);
1.213 raeburn 7879: foreach my $role (@roles) {
1.321 raeburn 7880: my $plrole=&Apache::lonnet::plaintext($role,$crstype);
1.329 raeburn 7881: if ((&Apache::lonnet::allowed('c'.$role,$thiscourse)) ||
7882: ((($role eq 'cc') || ($role eq 'co')) && ($isowner))) {
1.221 raeburn 7883: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
1.375 raeburn 7884: $plrole,\%sections_count,\%lt,
1.402 raeburn 7885: $showcredits,$defaultcredits,$crstype);
1.221 raeburn 7886: } elsif ($env{'request.course.sec'} ne '') {
7887: if (&Apache::lonnet::allowed('c'.$role,$thiscourse.'/'.
7888: $env{'request.course.sec'})) {
7889: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
1.375 raeburn 7890: $plrole,\%sections_count,\%lt,
1.402 raeburn 7891: $showcredits,$defaultcredits,$crstype);
1.26 matthew 7892: }
7893: }
7894: }
1.221 raeburn 7895: if (&Apache::lonnet::allowed('ccr',$thiscourse)) {
1.324 raeburn 7896: foreach my $cust (sort(keys(%customroles))) {
7897: next if ($crstype eq 'Community' && $customroles{$cust} =~ /bre\&S/);
1.221 raeburn 7898: my $role = 'cr_cr_'.$env{'user.domain'}.'_'.$env{'user.name'}.'_'.$cust;
7899: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
1.402 raeburn 7900: $cust,\%sections_count,\%lt,
7901: $showcredits,$defaultcredits,$crstype);
1.221 raeburn 7902: }
1.62 www 7903: }
1.26 matthew 7904: }
7905: return '' if ($table eq ''); # return nothing if there is nothing
7906: # in the table
1.188 raeburn 7907: my $result;
7908: if (!$env{'request.course.id'}) {
7909: $result = '<h4>'.$lt{'crl'}.'</h4>'."\n";
7910: }
7911: $result .=
1.136 raeburn 7912: &Apache::loncommon::start_data_table().
7913: &Apache::loncommon::start_data_table_header_row().
1.375 raeburn 7914: '<th>'.$lt{'act'}.'</th><th>'.$lt{'rol'}.'</th>'."\n".
1.402 raeburn 7915: '<th>'.$lt{'ext'}.'</th><th>'."\n";
7916: if ($showcredits) {
7917: $result .= $lt{'crd'}.'</th>';
7918: }
7919: $result .=
1.375 raeburn 7920: '<th>'.$lt{'grs'}.'</th><th>'.$lt{'sta'}.'</th>'."\n".
7921: '<th>'.$lt{'end'}.'</th>'.
1.136 raeburn 7922: &Apache::loncommon::end_data_table_header_row().
7923: $table.
7924: &Apache::loncommon::end_data_table();
1.26 matthew 7925: return $result;
7926: }
1.88 raeburn 7927:
1.221 raeburn 7928: sub course_level_row {
1.375 raeburn 7929: my ($protectedcourse,$role,$area,$domain,$plrole,$sections_count,
1.402 raeburn 7930: $lt,$showcredits,$defaultcredits,$crstype) = @_;
1.375 raeburn 7931: my $creditem;
1.222 raeburn 7932: my $row = &Apache::loncommon::start_data_table_row().
7933: ' <td><input type="checkbox" name="act_'.
7934: $protectedcourse.'_'.$role.'" /></td>'."\n".
7935: ' <td>'.$plrole.'</td>'."\n".
7936: ' <td>'.$area.'<br />Domain: '.$domain.'</td>'."\n";
1.402 raeburn 7937: if (($showcredits) && ($role eq 'st') && ($crstype eq 'Course')) {
1.375 raeburn 7938: $row .=
7939: '<td><input type="text" name="credits_'.$protectedcourse.'_'.
7940: $role.'" size="3" value="'.$defaultcredits.'" /></td>';
7941: } else {
7942: $row .= '<td> </td>';
7943: }
1.322 raeburn 7944: if (($role eq 'cc') || ($role eq 'co')) {
1.222 raeburn 7945: $row .= '<td> </td>';
1.221 raeburn 7946: } elsif ($env{'request.course.sec'} ne '') {
1.222 raeburn 7947: $row .= ' <td><input type="hidden" value="'.
7948: $env{'request.course.sec'}.'" '.
7949: 'name="sec_'.$protectedcourse.'_'.$role.'" />'.
7950: $env{'request.course.sec'}.'</td>';
1.221 raeburn 7951: } else {
7952: if (ref($sections_count) eq 'HASH') {
7953: my $currsec =
7954: &Apache::lonuserutils::course_sections($sections_count,
7955: $protectedcourse.'_'.$role);
1.222 raeburn 7956: $row .= '<td><table class="LC_createuser">'."\n".
7957: '<tr class="LC_section_row">'."\n".
7958: ' <td valign="top">'.$lt->{'exs'}.'<br />'.
7959: $currsec.'</td>'."\n".
7960: ' <td> </td>'."\n".
7961: ' <td valign="top"> '.$lt->{'new'}.'<br />'.
1.221 raeburn 7962: '<input type="text" name="newsec_'.$protectedcourse.'_'.$role.
7963: '" value="" />'.
7964: '<input type="hidden" '.
7965: 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'."\n".
1.222 raeburn 7966: '</tr></table></td>'."\n";
1.221 raeburn 7967: } else {
1.222 raeburn 7968: $row .= '<td><input type="text" size="10" '.
1.375 raeburn 7969: 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'."\n";
1.221 raeburn 7970: }
7971: }
1.222 raeburn 7972: $row .= <<ENDTIMEENTRY;
7973: <td><input type="hidden" name="start_$protectedcourse\_$role" value="" />
1.221 raeburn 7974: <a href=
7975: "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 7976: <td><input type="hidden" name="end_$protectedcourse\_$role" value="" />
1.221 raeburn 7977: <a href=
7978: "javascript:pjump('date_end','End Date $plrole',document.cu.end_$protectedcourse\_$role.value,'end_$protectedcourse\_$role','cu.pres','dateset')">$lt->{'sed'}</a></td>
7979: ENDTIMEENTRY
1.222 raeburn 7980: $row .= &Apache::loncommon::end_data_table_row();
7981: return $row;
1.221 raeburn 7982: }
7983:
1.88 raeburn 7984: sub course_level_dc {
1.375 raeburn 7985: my ($dcdom,$showcredits) = @_;
1.190 raeburn 7986: my %customroles=&Apache::lonuserutils::my_custom_roles();
1.213 raeburn 7987: my @roles = &Apache::lonuserutils::roles_by_context('course');
1.88 raeburn 7988: my $hiddenitems = '<input type="hidden" name="dcdomain" value="'.$dcdom.'" />'.
7989: '<input type="hidden" name="origdom" value="'.$dcdom.'" />'.
1.133 raeburn 7990: '<input type="hidden" name="dccourse" value="" />';
1.355 www 7991: my $courseform=&Apache::loncommon::selectcourse_link
1.356 raeburn 7992: ('cu','dccourse','dcdomain','coursedesc',undef,undef,'Select','crstype');
1.375 raeburn 7993: my $credit_elem;
7994: if ($showcredits) {
7995: $credit_elem = 'credits';
7996: }
7997: my $cb_jscript = &Apache::loncommon::coursebrowser_javascript($dcdom,'currsec','cu','role','Course/Community Browser',$credit_elem);
1.88 raeburn 7998: my %lt=&Apache::lonlocal::texthash(
7999: 'rol' => "Role",
1.113 raeburn 8000: 'grs' => "Section",
1.88 raeburn 8001: 'exs' => "Existing sections",
8002: 'new' => "Define new section",
8003: 'sta' => "Start",
8004: 'end' => "End",
8005: 'ssd' => "Set Start Date",
1.355 www 8006: 'sed' => "Set End Date",
1.375 raeburn 8007: 'scc' => "Course/Community",
8008: 'crd' => "Credits",
1.88 raeburn 8009: );
1.323 raeburn 8010: my $header = '<h4>'.&mt('Course/Community Level').'</h4>'.
1.136 raeburn 8011: &Apache::loncommon::start_data_table().
8012: &Apache::loncommon::start_data_table_header_row().
1.375 raeburn 8013: '<th>'.$lt{'scc'}.'</th><th>'.$lt{'rol'}.'</th>'."\n".
1.397 bisitz 8014: '<th>'.$lt{'grs'}.'</th>'."\n";
8015: $header .= '<th>'.$lt{'crd'}.'</th>'."\n" if ($showcredits);
8016: $header .= '<th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'."\n".
1.136 raeburn 8017: &Apache::loncommon::end_data_table_header_row();
1.143 raeburn 8018: my $otheritems = &Apache::loncommon::start_data_table_row()."\n".
1.356 raeburn 8019: '<td><br /><span class="LC_nobreak"><input type="text" name="coursedesc" value="" onfocus="this.blur();opencrsbrowser('."'cu','dccourse','dcdomain','coursedesc','','','','crstype'".')" />'.
8020: $courseform.(' ' x4).'</span></td>'."\n".
1.389 bisitz 8021: '<td valign="top"><br /><select name="role">'."\n";
1.213 raeburn 8022: foreach my $role (@roles) {
1.135 raeburn 8023: my $plrole=&Apache::lonnet::plaintext($role);
1.389 bisitz 8024: $otheritems .= ' <option value="'.$role.'">'.$plrole.'</option>';
1.88 raeburn 8025: }
1.404 raeburn 8026: if ( keys(%customroles) > 0) {
8027: foreach my $cust (sort(keys(%customroles))) {
1.101 albertel 8028: my $custrole='cr_cr_'.$env{'user.domain'}.
1.135 raeburn 8029: '_'.$env{'user.name'}.'_'.$cust;
1.389 bisitz 8030: $otheritems .= ' <option value="'.$custrole.'">'.$cust.'</option>';
1.88 raeburn 8031: }
8032: }
8033: $otheritems .= '</select></td><td>'.
8034: '<table border="0" cellspacing="0" cellpadding="0">'.
8035: '<tr><td valign="top"><b>'.$lt{'exs'}.'</b><br /><select name="currsec">'.
1.389 bisitz 8036: ' <option value=""><--'.&mt('Pick course first').'</option></select></td>'.
1.88 raeburn 8037: '<td> </td>'.
8038: '<td valign="top"> <b>'.$lt{'new'}.'</b><br />'.
1.113 raeburn 8039: '<input type="text" name="newsec" value="" />'.
1.237 raeburn 8040: '<input type="hidden" name="section" value="" />'.
1.323 raeburn 8041: '<input type="hidden" name="groups" value="" />'.
8042: '<input type="hidden" name="crstype" value="" /></td>'.
1.375 raeburn 8043: '</tr></table></td>'."\n";
8044: if ($showcredits) {
8045: $otheritems .= '<td><br />'."\n".
1.397 bisitz 8046: '<input type="text" size="3" name="credits" value="" /></td>'."\n";
1.375 raeburn 8047: }
1.88 raeburn 8048: $otheritems .= <<ENDTIMEENTRY;
1.323 raeburn 8049: <td><br /><input type="hidden" name="start" value='' />
1.88 raeburn 8050: <a href=
8051: "javascript:pjump('date_start','Start Date',document.cu.start.value,'start','cu.pres','dateset')">$lt{'ssd'}</a></td>
1.323 raeburn 8052: <td><br /><input type="hidden" name="end" value='' />
1.88 raeburn 8053: <a href=
8054: "javascript:pjump('date_end','End Date',document.cu.end.value,'end','cu.pres','dateset')">$lt{'sed'}</a></td>
8055: ENDTIMEENTRY
1.136 raeburn 8056: $otheritems .= &Apache::loncommon::end_data_table_row().
8057: &Apache::loncommon::end_data_table()."\n";
1.88 raeburn 8058: return $cb_jscript.$header.$hiddenitems.$otheritems;
8059: }
8060:
1.237 raeburn 8061: sub update_selfenroll_config {
1.400 raeburn 8062: my ($r,$cid,$cdom,$cnum,$context,$crstype,$currsettings) = @_;
1.398 raeburn 8063: return unless (ref($currsettings) eq 'HASH');
8064: my ($row,$lt) = &Apache::lonuserutils::get_selfenroll_titles();
8065: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
1.237 raeburn 8066: my (%changes,%warning);
1.241 raeburn 8067: my $curr_types;
1.400 raeburn 8068: my %noedit;
8069: unless ($context eq 'domain') {
8070: %noedit = &get_noedit_fields($cdom,$cnum,$crstype,$row);
8071: }
1.237 raeburn 8072: if (ref($row) eq 'ARRAY') {
8073: foreach my $item (@{$row}) {
1.400 raeburn 8074: next if ($noedit{$item});
1.237 raeburn 8075: if ($item eq 'enroll_dates') {
8076: my (%currenrolldate,%newenrolldate);
8077: foreach my $type ('start','end') {
1.398 raeburn 8078: $currenrolldate{$type} = $currsettings->{'selfenroll_'.$type.'_date'};
1.237 raeburn 8079: $newenrolldate{$type} = &Apache::lonhtmlcommon::get_date_from_form('selfenroll_'.$type.'_date');
8080: if ($newenrolldate{$type} ne $currenrolldate{$type}) {
8081: $changes{'internal.selfenroll_'.$type.'_date'} = $newenrolldate{$type};
8082: }
8083: }
8084: } elsif ($item eq 'access_dates') {
8085: my (%currdate,%newdate);
8086: foreach my $type ('start','end') {
1.398 raeburn 8087: $currdate{$type} = $currsettings->{'selfenroll_'.$type.'_access'};
1.237 raeburn 8088: $newdate{$type} = &Apache::lonhtmlcommon::get_date_from_form('selfenroll_'.$type.'_access');
8089: if ($newdate{$type} ne $currdate{$type}) {
8090: $changes{'internal.selfenroll_'.$type.'_access'} = $newdate{$type};
8091: }
8092: }
1.241 raeburn 8093: } elsif ($item eq 'types') {
1.398 raeburn 8094: $curr_types = $currsettings->{'selfenroll_'.$item};
1.241 raeburn 8095: if ($env{'form.selfenroll_all'}) {
8096: if ($curr_types ne '*') {
8097: $changes{'internal.selfenroll_types'} = '*';
8098: } else {
8099: next;
8100: }
8101: } else {
1.249 raeburn 8102: my %currdoms;
1.241 raeburn 8103: my @entries = split(/;/,$curr_types);
8104: my @deletedoms = &Apache::loncommon::get_env_multiple('form.selfenroll_delete');
1.249 raeburn 8105: my @activations = &Apache::loncommon::get_env_multiple('form.selfenroll_activate');
1.241 raeburn 8106: my $newnum = 0;
1.249 raeburn 8107: my @latesttypes;
8108: foreach my $num (@activations) {
8109: my @types = &Apache::loncommon::get_env_multiple('form.selfenroll_types_'.$num);
8110: if (@types > 0) {
1.241 raeburn 8111: @types = sort(@types);
8112: my $typestr = join(',',@types);
1.249 raeburn 8113: my $typedom = $env{'form.selfenroll_dom_'.$num};
8114: $latesttypes[$newnum] = $typedom.':'.$typestr;
8115: $currdoms{$typedom} = 1;
1.241 raeburn 8116: $newnum ++;
8117: }
8118: }
1.338 raeburn 8119: for (my $j=0; $j<$env{'form.selfenroll_types_total'}; $j++) {
8120: if ((!grep(/^$j$/,@deletedoms)) && (!grep(/^$j$/,@activations))) {
1.249 raeburn 8121: my @types = &Apache::loncommon::get_env_multiple('form.selfenroll_types_'.$j);
8122: if (@types > 0) {
8123: @types = sort(@types);
8124: my $typestr = join(',',@types);
8125: my $typedom = $env{'form.selfenroll_dom_'.$j};
8126: $latesttypes[$newnum] = $typedom.':'.$typestr;
8127: $currdoms{$typedom} = 1;
8128: $newnum ++;
8129: }
8130: }
8131: }
8132: if ($env{'form.selfenroll_newdom'} ne '') {
8133: my $typedom = $env{'form.selfenroll_newdom'};
8134: if ((!defined($currdoms{$typedom})) &&
8135: (&Apache::lonnet::domain($typedom) ne '')) {
8136: my $typestr;
8137: my ($othertitle,$usertypes,$types) =
8138: &Apache::loncommon::sorted_inst_types($typedom);
8139: my $othervalue = 'any';
8140: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
8141: if (@{$types} > 0) {
1.257 raeburn 8142: my @esc_types = map { &escape($_); } @{$types};
1.249 raeburn 8143: $othervalue = 'other';
1.258 raeburn 8144: $typestr = join(',',(@esc_types,$othervalue));
1.249 raeburn 8145: }
8146: $typestr = $othervalue;
8147: } else {
8148: $typestr = $othervalue;
8149: }
8150: $latesttypes[$newnum] = $typedom.':'.$typestr;
8151: $newnum ++ ;
8152: }
8153: }
1.241 raeburn 8154: my $selfenroll_types = join(';',@latesttypes);
8155: if ($selfenroll_types ne $curr_types) {
8156: $changes{'internal.selfenroll_types'} = $selfenroll_types;
8157: }
8158: }
1.276 raeburn 8159: } elsif ($item eq 'limit') {
8160: my $newlimit = $env{'form.selfenroll_limit'};
8161: my $newcap = $env{'form.selfenroll_cap'};
8162: $newcap =~s/\s+//g;
1.398 raeburn 8163: my $currlimit = $currsettings->{'selfenroll_limit'};
1.276 raeburn 8164: $currlimit = 'none' if ($currlimit eq '');
1.398 raeburn 8165: my $currcap = $currsettings->{'selfenroll_cap'};
1.276 raeburn 8166: if ($newlimit ne $currlimit) {
8167: if ($newlimit ne 'none') {
8168: if ($newcap =~ /^\d+$/) {
8169: if ($newcap ne $currcap) {
8170: $changes{'internal.selfenroll_cap'} = $newcap;
8171: }
8172: $changes{'internal.selfenroll_limit'} = $newlimit;
8173: } else {
1.398 raeburn 8174: $warning{$item} = &mt('Maximum enrollment setting unchanged.').'<br />'.
8175: &mt('The value provided was invalid - it must be a positive integer if enrollment is being limited.');
1.276 raeburn 8176: }
8177: } elsif ($currcap ne '') {
8178: $changes{'internal.selfenroll_cap'} = '';
8179: $changes{'internal.selfenroll_limit'} = $newlimit;
8180: }
8181: } elsif ($currlimit ne 'none') {
8182: if ($newcap =~ /^\d+$/) {
8183: if ($newcap ne $currcap) {
8184: $changes{'internal.selfenroll_cap'} = $newcap;
8185: }
8186: } else {
1.398 raeburn 8187: $warning{$item} = &mt('Maximum enrollment setting unchanged.').'<br />'.
8188: &mt('The value provided was invalid - it must be a positive integer if enrollment is being limited.');
1.276 raeburn 8189: }
8190: }
8191: } elsif ($item eq 'approval') {
8192: my (@currnotified,@newnotified);
1.398 raeburn 8193: my $currapproval = $currsettings->{'selfenroll_approval'};
8194: my $currnotifylist = $currsettings->{'selfenroll_notifylist'};
1.276 raeburn 8195: if ($currnotifylist ne '') {
8196: @currnotified = split(/,/,$currnotifylist);
8197: @currnotified = sort(@currnotified);
8198: }
8199: my $newapproval = $env{'form.selfenroll_approval'};
8200: @newnotified = &Apache::loncommon::get_env_multiple('form.selfenroll_notify');
8201: @newnotified = sort(@newnotified);
8202: if ($newapproval ne $currapproval) {
8203: $changes{'internal.selfenroll_approval'} = $newapproval;
8204: if (!$newapproval) {
8205: if ($currnotifylist ne '') {
8206: $changes{'internal.selfenroll_notifylist'} = '';
8207: }
8208: } else {
8209: my @differences =
1.295 raeburn 8210: &Apache::loncommon::compare_arrays(\@currnotified,\@newnotified);
1.276 raeburn 8211: if (@differences > 0) {
8212: if (@newnotified > 0) {
8213: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
8214: } else {
8215: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
8216: }
8217: }
8218: }
8219: } else {
1.295 raeburn 8220: my @differences = &Apache::loncommon::compare_arrays(\@currnotified,\@newnotified);
1.276 raeburn 8221: if (@differences > 0) {
8222: if (@newnotified > 0) {
8223: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
8224: } else {
8225: $changes{'internal.selfenroll_notifylist'} = '';
8226: }
8227: }
8228: }
1.237 raeburn 8229: } else {
1.398 raeburn 8230: my $curr_val = $currsettings->{'selfenroll_'.$item};
1.237 raeburn 8231: my $newval = $env{'form.selfenroll_'.$item};
8232: if ($item eq 'section') {
8233: $newval = $env{'form.sections'};
1.241 raeburn 8234: if (defined($curr_groups{$newval})) {
1.237 raeburn 8235: $newval = $curr_val;
1.398 raeburn 8236: $warning{$item} = &mt('Section for self-enrolled users unchanged as the proposed section is a group').'<br />'.
8237: &mt('Group names and section names must be distinct');
1.237 raeburn 8238: } elsif ($newval eq 'all') {
8239: $newval = $curr_val;
1.274 bisitz 8240: $warning{$item} = &mt('Section for self-enrolled users unchanged, as "all" is a reserved section name.');
1.237 raeburn 8241: }
8242: if ($newval eq '') {
8243: $newval = 'none';
8244: }
8245: }
8246: if ($newval ne $curr_val) {
8247: $changes{'internal.selfenroll_'.$item} = $newval;
8248: }
1.241 raeburn 8249: }
1.237 raeburn 8250: }
8251: if (keys(%warning) > 0) {
8252: foreach my $item (@{$row}) {
8253: if (exists($warning{$item})) {
8254: $r->print($warning{$item}.'<br />');
8255: }
8256: }
8257: }
8258: if (keys(%changes) > 0) {
8259: my $putresult = &Apache::lonnet::put('environment',\%changes,$cdom,$cnum);
8260: if ($putresult eq 'ok') {
8261: if ((exists($changes{'internal.selfenroll_types'})) ||
8262: (exists($changes{'internal.selfenroll_start_date'})) ||
8263: (exists($changes{'internal.selfenroll_end_date'}))) {
8264: my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',
8265: $cnum,undef,undef,'Course');
8266: my $chome = &Apache::lonnet::homeserver($cnum,$cdom);
1.398 raeburn 8267: if (ref($crsinfo{$cid}) eq 'HASH') {
1.237 raeburn 8268: foreach my $item ('selfenroll_types','selfenroll_start_date','selfenroll_end_date') {
8269: if (exists($changes{'internal.'.$item})) {
1.398 raeburn 8270: $crsinfo{$cid}{$item} = $changes{'internal.'.$item};
1.237 raeburn 8271: }
8272: }
8273: my $crsputresult =
8274: &Apache::lonnet::courseidput($cdom,\%crsinfo,
8275: $chome,'notime');
8276: }
8277: }
8278: $r->print(&mt('The following changes were made to self-enrollment settings:').'<ul>');
8279: foreach my $item (@{$row}) {
8280: my $title = $item;
8281: if (ref($lt) eq 'HASH') {
8282: $title = $lt->{$item};
8283: }
8284: if ($item eq 'enroll_dates') {
8285: foreach my $type ('start','end') {
8286: if (exists($changes{'internal.selfenroll_'.$type.'_date'})) {
8287: my $newdate = &Apache::lonlocal::locallocaltime($changes{'internal.selfenroll_'.$type.'_date'});
1.244 bisitz 8288: $r->print('<li>'.&mt('[_1]: "[_2]" set to "[_3]".',
1.237 raeburn 8289: $title,$type,$newdate).'</li>');
8290: }
8291: }
8292: } elsif ($item eq 'access_dates') {
8293: foreach my $type ('start','end') {
8294: if (exists($changes{'internal.selfenroll_'.$type.'_access'})) {
8295: my $newdate = &Apache::lonlocal::locallocaltime($changes{'internal.selfenroll_'.$type.'_access'});
1.244 bisitz 8296: $r->print('<li>'.&mt('[_1]: "[_2]" set to "[_3]".',
1.237 raeburn 8297: $title,$type,$newdate).'</li>');
8298: }
8299: }
1.276 raeburn 8300: } elsif ($item eq 'limit') {
8301: if ((exists($changes{'internal.selfenroll_limit'})) ||
8302: (exists($changes{'internal.selfenroll_cap'}))) {
8303: my ($newval,$newcap);
8304: if ($changes{'internal.selfenroll_cap'} ne '') {
8305: $newcap = $changes{'internal.selfenroll_cap'}
8306: } else {
1.398 raeburn 8307: $newcap = $currsettings->{'selfenroll_cap'};
1.276 raeburn 8308: }
8309: if ($changes{'internal.selfenroll_limit'} eq 'none') {
8310: $newval = &mt('No limit');
8311: } elsif ($changes{'internal.selfenroll_limit'} eq
8312: 'allstudents') {
8313: $newval = &mt('New self-enrollment no longer allowed when total (all students) reaches [_1].',$newcap);
8314: } elsif ($changes{'internal.selfenroll_limit'} eq 'selfenrolled') {
8315: $newval = &mt('New self-enrollment no longer allowed when total number of self-enrolled students reaches [_1].',$newcap);
8316: } else {
1.398 raeburn 8317: my $currlimit = $currsettings->{'selfenroll_limit'};
1.276 raeburn 8318: if ($currlimit eq 'allstudents') {
8319: $newval = &mt('New self-enrollment no longer allowed when total (all students) reaches [_1].',$newcap);
8320: } elsif ($changes{'internal.selfenroll_limit'} eq 'selfenrolled') {
1.308 raeburn 8321: $newval = &mt('New self-enrollment no longer allowed when total number of self-enrolled students reaches [_1].',$newcap);
1.276 raeburn 8322: }
8323: }
8324: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval).'</li>'."\n");
8325: }
8326: } elsif ($item eq 'approval') {
8327: if ((exists($changes{'internal.selfenroll_approval'})) ||
8328: (exists($changes{'internal.selfenroll_notifylist'}))) {
1.398 raeburn 8329: my %selfdescs = &Apache::lonuserutils::selfenroll_default_descs();
1.276 raeburn 8330: my ($newval,$newnotify);
8331: if (exists($changes{'internal.selfenroll_notifylist'})) {
8332: $newnotify = $changes{'internal.selfenroll_notifylist'};
8333: } else {
1.398 raeburn 8334: $newnotify = $currsettings->{'selfenroll_notifylist'};
1.276 raeburn 8335: }
1.398 raeburn 8336: if (exists($changes{'internal.selfenroll_approval'})) {
8337: if ($changes{'internal.selfenroll_approval'} !~ /^[012]$/) {
8338: $changes{'internal.selfenroll_approval'} = '0';
8339: }
8340: $newval = $selfdescs{'approval'}{$changes{'internal.selfenroll_approval'}};
1.276 raeburn 8341: } else {
1.398 raeburn 8342: my $currapproval = $currsettings->{'selfenroll_approval'};
8343: if ($currapproval !~ /^[012]$/) {
8344: $currapproval = 0;
1.276 raeburn 8345: }
1.398 raeburn 8346: $newval = $selfdescs{'approval'}{$currapproval};
1.276 raeburn 8347: }
8348: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval));
8349: if ($newnotify) {
1.277 raeburn 8350: $r->print('<br />'.&mt('The following will be notified when an enrollment request needs approval, or has been approved: [_1].',$newnotify));
1.276 raeburn 8351: } else {
1.277 raeburn 8352: $r->print('<br />'.&mt('No notifications sent when an enrollment request needs approval, or has been approved.'));
1.276 raeburn 8353: }
8354: $r->print('</li>'."\n");
8355: }
1.237 raeburn 8356: } else {
8357: if (exists($changes{'internal.selfenroll_'.$item})) {
1.241 raeburn 8358: my $newval = $changes{'internal.selfenroll_'.$item};
8359: if ($item eq 'types') {
8360: if ($newval eq '') {
8361: $newval = &mt('None');
8362: } elsif ($newval eq '*') {
8363: $newval = &mt('Any user in any domain');
8364: }
1.245 raeburn 8365: } elsif ($item eq 'registered') {
8366: if ($newval eq '1') {
8367: $newval = &mt('Yes');
8368: } elsif ($newval eq '0') {
8369: $newval = &mt('No');
8370: }
1.241 raeburn 8371: }
1.244 bisitz 8372: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval).'</li>'."\n");
1.237 raeburn 8373: }
8374: }
8375: }
8376: $r->print('</ul>');
1.398 raeburn 8377: if ($env{'course.'.$cid.'.description'} ne '') {
8378: my %newenvhash;
8379: foreach my $key (keys(%changes)) {
8380: $newenvhash{'course.'.$cid.'.'.$key} = $changes{$key};
8381: }
8382: &Apache::lonnet::appenv(\%newenvhash);
1.237 raeburn 8383: }
8384: } else {
1.398 raeburn 8385: $r->print(&mt('An error occurred when saving changes to self-enrollment settings in this course.').'<br />'.
8386: &mt('The error was: [_1].',$putresult));
1.237 raeburn 8387: }
8388: } else {
1.249 raeburn 8389: $r->print(&mt('No changes were made to the existing self-enrollment settings in this course.'));
1.237 raeburn 8390: }
8391: } else {
1.249 raeburn 8392: $r->print(&mt('No changes were made to the existing self-enrollment settings in this course.'));
1.241 raeburn 8393: }
1.400 raeburn 8394: my $visactions = &cat_visibility();
8395: my ($cathash,%cattype);
8396: my %domconfig = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom);
8397: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
8398: $cathash = $domconfig{'coursecategories'}{'cats'};
8399: $cattype{'auth'} = $domconfig{'coursecategories'}{'auth'};
8400: $cattype{'unauth'} = $domconfig{'coursecategories'}{'unauth'};
8401: } else {
8402: $cathash = {};
8403: $cattype{'auth'} = 'std';
8404: $cattype{'unauth'} = 'std';
8405: }
8406: if (($cattype{'auth'} eq 'none') && ($cattype{'unauth'} eq 'none')) {
8407: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
8408: '<br />'.
8409: '<br />'.$visactions->{'take'}.'<ul>'.
8410: '<li>'.$visactions->{'dc_chgconf'}.'</li>'.
8411: '</ul>');
8412: } elsif (($cattype{'auth'} !~ /^(std|domonly)$/) && ($cattype{'unauth'} !~ /^(std|domonly)$/)) {
8413: if ($currsettings->{'uniquecode'}) {
8414: $r->print('<span class="LC_info">'.$visactions->{'vis'}.'</span>');
8415: } else {
1.366 bisitz 8416: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
1.400 raeburn 8417: '<br />'.
8418: '<br />'.$visactions->{'take'}.'<ul>'.
8419: '<li>'.$visactions->{'dc_setcode'}.'</li>'.
8420: '</ul><br />');
8421: }
8422: } else {
8423: my ($visible,$cansetvis,$vismsgs) = &visible_in_stdcat($cdom,$cnum,\%domconfig);
8424: if (ref($visactions) eq 'HASH') {
8425: if (!$visible) {
8426: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
8427: '<br />');
8428: if (ref($vismsgs) eq 'ARRAY') {
8429: $r->print('<br />'.$visactions->{'take'}.'<ul>');
8430: foreach my $item (@{$vismsgs}) {
8431: $r->print('<li>'.$visactions->{$item}.'</li>');
8432: }
8433: $r->print('</ul>');
1.256 raeburn 8434: }
1.400 raeburn 8435: $r->print($cansetvis);
1.256 raeburn 8436: }
8437: }
8438: }
1.237 raeburn 8439: return;
8440: }
8441:
1.27 matthew 8442: #---------------------------------------------- end functions for &phase_two
1.29 matthew 8443:
8444: #--------------------------------- functions for &phase_two and &phase_three
8445:
8446: #--------------------------end of functions for &phase_two and &phase_three
1.372 raeburn 8447:
1.1 www 8448: 1;
8449: __END__
1.2 www 8450:
8451:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>