Annotation of loncom/interface/loncreateuser.pm, revision 1.406.2.20.2.1
1.20 harris41 1: # The LearningOnline Network with CAPA
1.1 www 2: # Create a user
3: #
1.406.2.20.2. (raeburn 4:): # $Id: loncreateuser.pm,v 1.406.2.20 2021/12/13 20:53:06 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.406.2.20 raeburn 74: use HTML::Entities;
1.1 www 75:
1.20 harris41 76: my $loginscript; # piece of javascript used in two separate instances
77: my $authformnop;
78: my $authformkrb;
79: my $authformint;
80: my $authformfsys;
81: my $authformloc;
82:
1.94 matthew 83: sub initialize_authen_forms {
1.227 raeburn 84: my ($dom,$formname,$curr_authtype,$mode) = @_;
85: my ($krbdef,$krbdefdom) = &Apache::loncommon::get_kerberos_defaults($dom);
86: my %param = ( formname => $formname,
1.187 raeburn 87: kerb_def_dom => $krbdefdom,
1.227 raeburn 88: kerb_def_auth => $krbdef,
1.187 raeburn 89: domain => $dom,
90: );
1.188 raeburn 91: my %abv_auth = &auth_abbrev();
1.227 raeburn 92: if ($curr_authtype =~ /^(krb4|krb5|internal|localauth|unix):(.*)$/) {
1.188 raeburn 93: my $long_auth = $1;
1.227 raeburn 94: my $curr_autharg = $2;
1.188 raeburn 95: my %abv_auth = &auth_abbrev();
96: $param{'curr_authtype'} = $abv_auth{$long_auth};
97: if ($long_auth =~ /^krb(4|5)$/) {
98: $param{'curr_kerb_ver'} = $1;
1.227 raeburn 99: $param{'curr_autharg'} = $curr_autharg;
1.188 raeburn 100: }
1.205 raeburn 101: if ($mode eq 'modifyuser') {
102: $param{'mode'} = $mode;
103: }
1.187 raeburn 104: }
1.227 raeburn 105: $loginscript = &Apache::loncommon::authform_header(%param);
106: $authformkrb = &Apache::loncommon::authform_kerberos(%param);
1.31 matthew 107: $authformnop = &Apache::loncommon::authform_nochange(%param);
108: $authformint = &Apache::loncommon::authform_internal(%param);
109: $authformfsys = &Apache::loncommon::authform_filesystem(%param);
110: $authformloc = &Apache::loncommon::authform_local(%param);
1.20 harris41 111: }
112:
1.188 raeburn 113: sub auth_abbrev {
114: my %abv_auth = (
1.368 raeburn 115: krb5 => 'krb',
116: krb4 => 'krb',
117: internal => 'int',
118: localauth => 'loc',
119: unix => 'fsys',
1.188 raeburn 120: );
121: return %abv_auth;
122: }
1.43 www 123:
1.134 raeburn 124: # ====================================================
125:
1.378 raeburn 126: sub user_quotas {
1.134 raeburn 127: my ($ccuname,$ccdomain) = @_;
128: my %lt = &Apache::lonlocal::texthash(
1.267 raeburn 129: 'usrt' => "User Tools",
130: 'cust' => "Custom quota",
131: 'chqu' => "Change quota",
1.134 raeburn 132: );
1.378 raeburn 133:
1.149 raeburn 134: my $quota_javascript = <<"END_SCRIPT";
135: <script type="text/javascript">
1.301 bisitz 136: // <![CDATA[
1.378 raeburn 137: function quota_changes(caller,context) {
138: var customoff = document.getElementById('custom_'+context+'quota_off');
139: var customon = document.getElementById('custom_'+context+'quota_on');
140: var number = document.getElementById(context+'quota');
1.149 raeburn 141: if (caller == "custom") {
1.378 raeburn 142: if (customoff) {
143: if (customoff.checked) {
144: number.value = "";
145: }
1.149 raeburn 146: }
147: }
148: if (caller == "quota") {
1.378 raeburn 149: if (customon) {
150: customon.checked = true;
151: }
1.149 raeburn 152: }
1.378 raeburn 153: return;
1.149 raeburn 154: }
1.301 bisitz 155: // ]]>
1.149 raeburn 156: </script>
157: END_SCRIPT
1.378 raeburn 158: my $longinsttype;
159: my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($ccdomain);
1.267 raeburn 160: my $output = $quota_javascript."\n".
161: '<h3>'.$lt{'usrt'}.'</h3>'."\n".
162: &Apache::loncommon::start_data_table();
163:
1.406.2.6 raeburn 164: if ((&Apache::lonnet::allowed('mut',$ccdomain)) ||
165: (&Apache::lonnet::allowed('udp',$ccdomain))) {
1.275 raeburn 166: $output .= &build_tools_display($ccuname,$ccdomain,'tools');
1.267 raeburn 167: }
1.378 raeburn 168:
169: my %titles = &Apache::lonlocal::texthash (
170: portfolio => "Disk space allocated to user's portfolio files",
1.385 bisitz 171: author => "Disk space allocated to user's Authoring Space (if role assigned)",
1.378 raeburn 172: );
173: foreach my $name ('portfolio','author') {
174: my ($currquota,$quotatype,$inststatus,$defquota) =
175: &Apache::loncommon::get_user_quota($ccuname,$ccdomain,$name);
176: if ($longinsttype eq '') {
177: if ($inststatus ne '') {
178: if ($usertypes->{$inststatus} ne '') {
179: $longinsttype = $usertypes->{$inststatus};
180: }
181: }
182: }
183: my ($showquota,$custom_on,$custom_off,$defaultinfo);
184: $custom_on = ' ';
185: $custom_off = ' checked="checked" ';
186: if ($quotatype eq 'custom') {
187: $custom_on = $custom_off;
188: $custom_off = ' ';
189: $showquota = $currquota;
190: if ($longinsttype eq '') {
191: $defaultinfo = &mt('For this user, the default quota would be [_1]'
1.383 raeburn 192: .' MB.',$defquota);
1.378 raeburn 193: } else {
194: $defaultinfo = &mt("For this user, the default quota would be [_1]".
1.383 raeburn 195: " MB, as determined by the user's institutional".
1.378 raeburn 196: " affiliation ([_2]).",$defquota,$longinsttype);
197: }
198: } else {
199: if ($longinsttype eq '') {
200: $defaultinfo = &mt('For this user, the default quota is [_1]'
1.383 raeburn 201: .' MB.',$defquota);
1.378 raeburn 202: } else {
203: $defaultinfo = &mt("For this user, the default quota of [_1]".
1.383 raeburn 204: " MB, is determined by the user's institutional".
1.378 raeburn 205: " affiliation ([_2]).",$defquota,$longinsttype);
206: }
207: }
208:
209: if (&Apache::lonnet::allowed('mpq',$ccdomain)) {
210: $output .= '<tr class="LC_info_row">'."\n".
211: ' <td>'.$titles{$name}.'</td>'."\n".
212: ' </tr>'."\n".
213: &Apache::loncommon::start_data_table_row()."\n".
1.390 bisitz 214: ' <td><span class="LC_nobreak">'.
215: &mt('Current quota: [_1] MB',$currquota).'</span> '.
1.378 raeburn 216: $defaultinfo.'</td>'."\n".
217: &Apache::loncommon::end_data_table_row()."\n".
218: &Apache::loncommon::start_data_table_row()."\n".
219: ' <td><span class="LC_nobreak">'.$lt{'chqu'}.
220: ': <label>'.
221: '<input type="radio" name="custom_'.$name.'quota" id="custom_'.$name.'quota_off" '.
1.379 raeburn 222: 'value="0" '.$custom_off.' onchange="javascript:quota_changes('."'custom','$name'".');"'.
1.390 bisitz 223: ' /><span class="LC_nobreak">'.
224: &mt('Default ([_1] MB)',$defquota).'</span></label> '.
1.378 raeburn 225: ' <label><input type="radio" name="custom_'.$name.'quota" id="custom_'.$name.'quota_on" '.
1.379 raeburn 226: 'value="1" '.$custom_on.' onchange="javascript:quota_changes('."'custom','$name'".');"'.
1.378 raeburn 227: ' />'.$lt{'cust'}.':</label> '.
1.379 raeburn 228: '<input type="text" name="'.$name.'quota" id="'.$name.'quota" size ="5" '.
229: 'value="'.$showquota.'" onfocus="javascript:quota_changes('."'quota','$name'".');"'.
1.390 bisitz 230: ' /> '.&mt('MB').'</span></td>'."\n".
1.378 raeburn 231: &Apache::loncommon::end_data_table_row()."\n";
232: }
233: }
1.267 raeburn 234: $output .= &Apache::loncommon::end_data_table();
1.134 raeburn 235: return $output;
236: }
237:
1.275 raeburn 238: sub build_tools_display {
239: my ($ccuname,$ccdomain,$context) = @_;
1.306 raeburn 240: my (@usertools,%userenv,$output,@options,%validations,%reqtitles,%reqdisplay,
1.332 raeburn 241: $colspan,$isadv,%domconfig);
1.275 raeburn 242: my %lt = &Apache::lonlocal::texthash (
243: 'blog' => "Personal User Blog",
244: 'aboutme' => "Personal Information Page",
1.385 bisitz 245: 'webdav' => "WebDAV access to Authoring Spaces (if SSL and author/co-author)",
1.275 raeburn 246: 'portfolio' => "Personal User Portfolio",
1.406.2.20.2. (raeburn 247:): 'timezone' => "Can set Time Zone",
1.275 raeburn 248: 'avai' => "Available",
249: 'cusa' => "availability",
250: 'chse' => "Change setting",
251: 'usde' => "Use default",
252: 'uscu' => "Use custom",
253: 'official' => 'Can request creation of official courses',
1.299 raeburn 254: 'unofficial' => 'Can request creation of unofficial courses',
255: 'community' => 'Can request creation of communities',
1.384 raeburn 256: 'textbook' => 'Can request creation of textbook courses',
1.362 raeburn 257: 'requestauthor' => 'Can request author space',
1.275 raeburn 258: );
1.279 raeburn 259: if ($context eq 'requestcourses') {
1.275 raeburn 260: %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
1.299 raeburn 261: 'requestcourses.official','requestcourses.unofficial',
1.384 raeburn 262: 'requestcourses.community','requestcourses.textbook');
263: @usertools = ('official','unofficial','community','textbook');
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.406.2.6 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',
1.406.2.20.2. (raeburn 285:): 'tools.webdav','tools.timezone');
286:): @usertools = ('aboutme','blog','webdav','portfolio','timezone');
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.362 raeburn 338: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.306 raeburn 339: my ($curroption,$currlimit);
1.362 raeburn 340: my $envkey = $context.'.'.$item;
341: if ($context eq 'requestauthor') {
342: $envkey = $context;
343: }
344: if ($userenv{$envkey} ne '') {
345: $curroption = $userenv{$envkey};
1.332 raeburn 346: } else {
347: my (@inststatuses);
1.362 raeburn 348: if ($context eq 'requestcourses') {
349: $curroption =
350: &Apache::loncoursequeueadmin::get_processtype('course',$ccuname,$ccdomain,
351: $isadv,$ccdomain,$item,
352: \@inststatuses,\%domconfig);
353: } else {
354: $curroption =
355: &Apache::loncoursequeueadmin::get_processtype('requestauthor',$ccuname,$ccdomain,
356: $isadv,$ccdomain,undef,
357: \@inststatuses,\%domconfig);
358: }
1.332 raeburn 359: }
1.306 raeburn 360: if (!$curroption) {
361: $curroption = 'norequest';
362: }
363: if ($curroption =~ /^autolimit=(\d*)$/) {
364: $currlimit = $1;
1.314 raeburn 365: if ($currlimit eq '') {
366: $currdisp = &mt('Yes, automatic creation');
367: } else {
368: $currdisp = &mt('Yes, up to [quant,_1,request]/user',$currlimit);
369: }
1.306 raeburn 370: } else {
371: $currdisp = $reqdisplay{$curroption};
372: }
373: $custdisp = '<table>';
374: foreach my $option (@options) {
375: my $val = $option;
376: if ($option eq 'norequest') {
377: $val = 0;
378: }
379: if ($option eq 'validate') {
380: my $canvalidate = 0;
381: if (ref($validations{$item}) eq 'HASH') {
382: if ($validations{$item}{'_custom_'}) {
383: $canvalidate = 1;
384: }
385: }
386: next if (!$canvalidate);
387: }
388: my $checked = '';
389: if ($option eq $curroption) {
390: $checked = ' checked="checked"';
391: } elsif ($option eq 'autolimit') {
392: if ($curroption =~ /^autolimit/) {
393: $checked = ' checked="checked"';
394: }
395: }
1.362 raeburn 396: my $name = 'crsreq_'.$item;
397: if ($context eq 'requestauthor') {
398: $name = $item;
399: }
1.306 raeburn 400: $custdisp .= '<tr><td><span class="LC_nobreak"><label>'.
1.362 raeburn 401: '<input type="radio" name="'.$name.'" '.
402: 'value="'.$val.'"'.$checked.' />'.
1.306 raeburn 403: $reqtitles{$option}.'</label> ';
404: if ($option eq 'autolimit') {
1.362 raeburn 405: $custdisp .= '<input type="text" name="'.$name.
406: '_limit" size="1" '.
1.314 raeburn 407: 'value="'.$currlimit.'" /></span><br />'.
408: $reqtitles{'unlimited'};
1.362 raeburn 409: } else {
410: $custdisp .= '</span>';
411: }
412: $custdisp .= '</td></tr>';
1.306 raeburn 413: }
414: $custdisp .= '</table>';
415: $custradio = '</span></td><td>'.&mt('Custom setting').'<br />'.$custdisp;
416: } else {
417: $currdisp = ($curr_access?&mt('Yes'):&mt('No'));
1.362 raeburn 418: my $name = $context.'_'.$item;
419: if ($context eq 'requestauthor') {
420: $name = $context;
421: }
1.306 raeburn 422: $custdisp = '<span class="LC_nobreak"><label>'.
1.362 raeburn 423: '<input type="radio" name="'.$name.'"'.
1.361 raeburn 424: ' value="1" '.$tool_on.'/>'.&mt('On').'</label> <label>'.
1.362 raeburn 425: '<input type="radio" name="'.$name.'" value="0" '.
1.306 raeburn 426: $tool_off.'/>'.&mt('Off').'</label></span>';
427: $custradio = (' 'x2).'--'.$lt{'cusa'}.': '.$custdisp.
428: '</span>';
429: }
430: $output .= ' <td'.$colspan.'>'.$custom_access.(' 'x4).
431: $lt{'avai'}.': '.$currdisp.'</td>'."\n".
1.406.2.6 raeburn 432: &Apache::loncommon::end_data_table_row()."\n";
433: unless (&Apache::lonnet::allowed('udp',$ccdomain)) {
434: $output .=
1.275 raeburn 435: &Apache::loncommon::start_data_table_row()."\n".
1.306 raeburn 436: ' <td style="vertical-align:top;"><span class="LC_nobreak">'.
437: $lt{'chse'}.': <label>'.
1.275 raeburn 438: '<input type="radio" name="custom'.$item.'" value="0" '.
1.306 raeburn 439: $cust_off.'/>'.$lt{'usde'}.'</label>'.(' ' x3).
440: '<label><input type="radio" name="custom'.$item.'" value="1" '.
441: $cust_on.'/>'.$lt{'uscu'}.'</label>'.$custradio.'</td>'.
1.275 raeburn 442: &Apache::loncommon::end_data_table_row()."\n";
1.406.2.6 raeburn 443: }
1.275 raeburn 444: }
445: return $output;
446: }
447:
1.300 raeburn 448: sub coursereq_externaluser {
449: my ($ccuname,$ccdomain,$cdom) = @_;
1.306 raeburn 450: my (@usertools,@options,%validations,%userenv,$output);
1.300 raeburn 451: my %lt = &Apache::lonlocal::texthash (
452: 'official' => 'Can request creation of official courses',
453: 'unofficial' => 'Can request creation of unofficial courses',
454: 'community' => 'Can request creation of communities',
1.384 raeburn 455: 'textbook' => 'Can request creation of textbook courses',
1.300 raeburn 456: );
457:
458: %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
459: 'reqcrsotherdom.official','reqcrsotherdom.unofficial',
1.384 raeburn 460: 'reqcrsotherdom.community','reqcrsotherdom.textbook');
461: @usertools = ('official','unofficial','community','textbook');
1.309 raeburn 462: @options = ('approval','validate','autolimit');
1.306 raeburn 463: %validations = &Apache::lonnet::auto_courserequest_checks($cdom);
464: my $optregex = join('|',@options);
465: my %reqtitles = &courserequest_titles();
1.300 raeburn 466: foreach my $item (@usertools) {
1.306 raeburn 467: my ($curroption,$currlimit,$tooloff);
1.300 raeburn 468: if ($userenv{'reqcrsotherdom.'.$item} ne '') {
469: my @curr = split(',',$userenv{'reqcrsotherdom.'.$item});
1.314 raeburn 470: foreach my $req (@curr) {
471: if ($req =~ /^\Q$cdom\E\:($optregex)=?(\d*)$/) {
472: $curroption = $1;
473: $currlimit = $2;
474: last;
1.306 raeburn 475: }
476: }
1.314 raeburn 477: if (!$curroption) {
478: $curroption = 'norequest';
479: $tooloff = ' checked="checked"';
480: }
1.306 raeburn 481: } else {
482: $curroption = 'norequest';
483: $tooloff = ' checked="checked"';
484: }
485: $output.= &Apache::loncommon::start_data_table_row()."\n".
1.314 raeburn 486: ' <td><span class="LC_nobreak">'.$lt{$item}.': </span></td><td>'.
487: '<table><tr><td valign="top">'."\n".
1.306 raeburn 488: '<label><input type="radio" name="reqcrsotherdom_'.$item.
1.314 raeburn 489: '" value=""'.$tooloff.' />'.$reqtitles{'norequest'}.
490: '</label></td>';
1.306 raeburn 491: foreach my $option (@options) {
492: if ($option eq 'validate') {
493: my $canvalidate = 0;
494: if (ref($validations{$item}) eq 'HASH') {
495: if ($validations{$item}{'_external_'}) {
496: $canvalidate = 1;
497: }
498: }
499: next if (!$canvalidate);
500: }
501: my $checked = '';
502: if ($option eq $curroption) {
503: $checked = ' checked="checked"';
504: }
1.314 raeburn 505: $output .= '<td valign="top"><span class="LC_nobreak"><label>'.
1.306 raeburn 506: '<input type="radio" name="reqcrsotherdom_'.$item.
507: '" value="'.$option.'"'.$checked.' />'.
1.314 raeburn 508: $reqtitles{$option}.'</label>';
1.306 raeburn 509: if ($option eq 'autolimit') {
1.314 raeburn 510: $output .= ' <input type="text" name="reqcrsotherdom_'.
1.306 raeburn 511: $item.'_limit" size="1" '.
1.314 raeburn 512: 'value="'.$currlimit.'" /></span>'.
513: '<br />'.$reqtitles{'unlimited'};
514: } else {
515: $output .= '</span>';
1.300 raeburn 516: }
1.314 raeburn 517: $output .= '</td>';
1.300 raeburn 518: }
1.314 raeburn 519: $output .= '</td></tr></table></td>'."\n".
1.300 raeburn 520: &Apache::loncommon::end_data_table_row()."\n";
521: }
522: return $output;
523: }
524:
1.362 raeburn 525: sub domainrole_req {
526: my ($ccuname,$ccdomain) = @_;
527: return '<br /><h3>'.
528: &mt('User Can Request Assignment of Domain Roles?').
529: '</h3>'."\n".
530: &Apache::loncommon::start_data_table().
531: &build_tools_display($ccuname,$ccdomain,
532: 'requestauthor').
533: &Apache::loncommon::end_data_table();
534: }
535:
1.306 raeburn 536: sub courserequest_titles {
537: my %titles = &Apache::lonlocal::texthash (
538: official => 'Official',
539: unofficial => 'Unofficial',
540: community => 'Communities',
1.384 raeburn 541: textbook => 'Textbook',
1.306 raeburn 542: norequest => 'Not allowed',
1.309 raeburn 543: approval => 'Approval by Dom. Coord.',
1.306 raeburn 544: validate => 'With validation',
545: autolimit => 'Numerical limit',
1.314 raeburn 546: unlimited => '(blank for unlimited)',
1.306 raeburn 547: );
548: return %titles;
549: }
550:
551: sub courserequest_display {
552: my %titles = &Apache::lonlocal::texthash (
1.309 raeburn 553: approval => 'Yes, need approval',
1.306 raeburn 554: validate => 'Yes, with validation',
555: norequest => 'No',
556: );
557: return %titles;
558: }
559:
1.362 raeburn 560: sub requestauthor_titles {
561: my %titles = &Apache::lonlocal::texthash (
562: norequest => 'Not allowed',
563: approval => 'Approval by Dom. Coord.',
564: automatic => 'Automatic approval',
565: );
566: return %titles;
567:
568: }
569:
570: sub requestauthor_display {
571: my %titles = &Apache::lonlocal::texthash (
572: approval => 'Yes, need approval',
573: automatic => 'Yes, automatic approval',
574: norequest => 'No',
575: );
576: return %titles;
577: }
578:
1.383 raeburn 579: sub requestchange_display {
580: my %titles = &Apache::lonlocal::texthash (
581: approval => "availability set to 'on' (approval required)",
582: automatic => "availability set to 'on' (automatic approval)",
583: norequest => "availability set to 'off'",
584: );
585: return %titles;
586: }
587:
1.362 raeburn 588: sub curr_requestauthor {
589: my ($uname,$udom,$isadv,$inststatuses,$domconfig) = @_;
590: return unless ((ref($inststatuses) eq 'ARRAY') && (ref($domconfig) eq 'HASH'));
591: if ($uname eq '' || $udom eq '') {
592: $uname = $env{'user.name'};
593: $udom = $env{'user.domain'};
594: $isadv = $env{'user.adv'};
595: }
596: my (%userenv,%settings,$val);
597: my @options = ('automatic','approval');
598: %userenv =
599: &Apache::lonnet::userenvironment($udom,$uname,'requestauthor','inststatus');
600: if ($userenv{'requestauthor'}) {
601: $val = $userenv{'requestauthor'};
602: @{$inststatuses} = ('_custom_');
603: } else {
604: my %alltasks;
605: if (ref($domconfig->{'requestauthor'}) eq 'HASH') {
606: %settings = %{$domconfig->{'requestauthor'}};
607: if (($isadv) && ($settings{'_LC_adv'} ne '')) {
608: $val = $settings{'_LC_adv'};
609: @{$inststatuses} = ('_LC_adv_');
610: } else {
611: if ($userenv{'inststatus'} ne '') {
612: @{$inststatuses} = split(',',$userenv{'inststatus'});
613: } else {
614: @{$inststatuses} = ('default');
615: }
616: foreach my $status (@{$inststatuses}) {
617: if (exists($settings{$status})) {
618: my $value = $settings{$status};
619: next unless ($value);
620: unless (exists($alltasks{$value})) {
621: if (ref($alltasks{$value}) eq 'ARRAY') {
622: unless(grep(/^\Q$status\E$/,@{$alltasks{$value}})) {
623: push(@{$alltasks{$value}},$status);
624: }
625: } else {
626: @{$alltasks{$value}} = ($status);
627: }
628: }
629: }
630: }
631: foreach my $option (@options) {
632: if ($alltasks{$option}) {
633: $val = $option;
634: last;
635: }
636: }
637: }
638: }
639: }
640: return $val;
641: }
642:
1.2 www 643: # =================================================================== Phase one
1.1 www 644:
1.42 matthew 645: sub print_username_entry_form {
1.406.2.14 raeburn 646: my ($r,$context,$response,$srch,$forcenewuser,$crstype,$brcrum,
647: $permission) = @_;
1.101 albertel 648: my $defdom=$env{'request.role.domain'};
1.160 raeburn 649: my $formtoset = 'crtuser';
650: if (exists($env{'form.startrolename'})) {
651: $formtoset = 'docustom';
652: $env{'form.rolename'} = $env{'form.startrolename'};
1.207 raeburn 653: } elsif ($env{'form.origform'} eq 'crtusername') {
654: $formtoset = $env{'form.origform'};
1.160 raeburn 655: }
656:
657: my ($jsback,$elements) = &crumb_utilities();
658:
659: my $jscript = &Apache::loncommon::studentbrowser_javascript()."\n".
1.165 albertel 660: '<script type="text/javascript">'."\n".
1.301 bisitz 661: '// <![CDATA['."\n".
662: &Apache::lonhtmlcommon::set_form_elements($elements->{$formtoset})."\n".
663: '// ]]>'."\n".
1.162 raeburn 664: '</script>'."\n";
1.160 raeburn 665:
1.324 raeburn 666: my %existingroles=&Apache::lonuserutils::my_custom_roles($crstype);
667: if (($env{'form.action'} eq 'custom') && (keys(%existingroles) > 0)
668: && (&Apache::lonnet::allowed('mcr','/'))) {
669: $jscript .= &customrole_javascript();
670: }
1.224 raeburn 671: my $helpitem = 'Course_Change_Privileges';
672: if ($env{'form.action'} eq 'custom') {
1.406.2.14 raeburn 673: if ($context eq 'course') {
674: $helpitem = 'Course_Editing_Custom_Roles';
675: } elsif ($context eq 'domain') {
676: $helpitem = 'Domain_Editing_Custom_Roles';
677: }
1.224 raeburn 678: } elsif ($env{'form.action'} eq 'singlestudent') {
679: $helpitem = 'Course_Add_Student';
1.406.2.5 raeburn 680: } elsif ($env{'form.action'} eq 'accesslogs') {
681: $helpitem = 'Domain_User_Access_Logs';
1.406.2.14 raeburn 682: } elsif ($context eq 'author') {
683: $helpitem = 'Author_Change_Privileges';
684: } elsif ($context eq 'domain') {
685: if ($permission->{'cusr'}) {
686: $helpitem = 'Domain_Change_Privileges';
687: } elsif ($permission->{'view'}) {
688: $helpitem = 'Domain_View_Privileges';
689: } else {
690: undef($helpitem);
691: }
1.224 raeburn 692: }
1.406.2.7 raeburn 693: my %breadcrumb_text = &singleuser_breadcrumb($crstype,$context,$defdom);
1.351 raeburn 694: if ($env{'form.action'} eq 'custom') {
695: push(@{$brcrum},
696: {href=>"javascript:backPage(document.crtuser)",
697: text=>"Pick custom role",
698: help => $helpitem,}
699: );
700: } else {
701: push (@{$brcrum},
702: {href => "javascript:backPage(document.crtuser)",
703: text => $breadcrumb_text{'search'},
704: help => $helpitem,
705: faq => 282,
706: bug => 'Instructor Interface',}
707: );
708: }
709: my %loaditems = (
710: 'onload' => "javascript:setFormElements(document.$formtoset)",
711: );
712: my $args = {bread_crumbs => $brcrum,
713: bread_crumbs_component => 'User Management',
714: add_entries => \%loaditems,};
715: $r->print(&Apache::loncommon::start_page('User Management',$jscript,$args));
716:
1.71 sakharuk 717: my %lt=&Apache::lonlocal::texthash(
1.229 raeburn 718: 'srst' => 'Search for a user and enroll as a student',
1.318 raeburn 719: 'srme' => 'Search for a user and enroll as a member',
1.229 raeburn 720: 'srad' => 'Search for a user and modify/add user information or roles',
1.406.2.7 raeburn 721: 'srvu' => 'Search for a user and view user information and roles',
1.406.2.5 raeburn 722: 'srva' => 'Search for a user and view access log information',
1.71 sakharuk 723: 'usr' => "Username",
724: 'dom' => "Domain",
1.324 raeburn 725: 'ecrp' => "Define or Edit Custom Role",
726: 'nr' => "role name",
1.282 schafran 727: 'cre' => "Next",
1.71 sakharuk 728: );
1.351 raeburn 729:
1.214 raeburn 730: if ($env{'form.action'} eq 'custom') {
1.190 raeburn 731: if (&Apache::lonnet::allowed('mcr','/')) {
1.324 raeburn 732: my $newroletext = &mt('Define new custom role:');
733: $r->print('<form action="/adm/createuser" method="post" name="docustom">'.
734: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'.
735: '<input type="hidden" name="phase" value="selected_custom_edit" />'.
736: '<h3>'.$lt{'ecrp'}.'</h3>'.
737: &Apache::loncommon::start_data_table().
738: &Apache::loncommon::start_data_table_row().
739: '<td>');
740: if (keys(%existingroles) > 0) {
741: $r->print('<br /><label><input type="radio" name="customroleaction" value="new" checked="checked" onclick="setCustomFields();" /><b>'.$newroletext.'</b></label>');
742: } else {
743: $r->print('<br /><input type="hidden" name="customroleaction" value="new" /><b>'.$newroletext.'</b>');
744: }
745: $r->print('</td><td align="center">'.$lt{'nr'}.'<br /><input type="text" size="15" name="newrolename" onfocus="setCustomAction('."'new'".');" /></td>'.
746: &Apache::loncommon::end_data_table_row());
747: if (keys(%existingroles) > 0) {
748: $r->print(&Apache::loncommon::start_data_table_row().'<td><br />'.
749: '<label><input type="radio" name="customroleaction" value="edit" onclick="setCustomFields();"/><b>'.
750: &mt('View/Modify existing role:').'</b></label></td>'.
751: '<td align="center"><br />'.
752: '<select name="rolename" onchange="setCustomAction('."'edit'".');">'.
1.326 raeburn 753: '<option value="" selected="selected">'.
1.324 raeburn 754: &mt('Select'));
755: foreach my $role (sort(keys(%existingroles))) {
1.326 raeburn 756: $r->print('<option value="'.$role.'">'.$role.'</option>');
1.324 raeburn 757: }
758: $r->print('</select>'.
759: '</td>'.
760: &Apache::loncommon::end_data_table_row());
761: }
762: $r->print(&Apache::loncommon::end_data_table().'<p>'.
763: '<input name="customeditor" type="submit" value="'.
764: $lt{'cre'}.'" /></p>'.
765: '</form>');
1.190 raeburn 766: }
1.213 raeburn 767: } else {
1.229 raeburn 768: my $actiontext = $lt{'srad'};
1.406.2.13 raeburn 769: my $fixeddom;
1.213 raeburn 770: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 771: if ($crstype eq 'Community') {
772: $actiontext = $lt{'srme'};
773: } else {
774: $actiontext = $lt{'srst'};
775: }
1.406.2.5 raeburn 776: } elsif ($env{'form.action'} eq 'accesslogs') {
777: $actiontext = $lt{'srva'};
1.406.2.13 raeburn 778: $fixeddom = 1;
1.406.2.7 raeburn 779: } elsif (($env{'form.action'} eq 'singleuser') &&
780: ($context eq 'domain') && (!&Apache::lonnet::allowed('mau',$defdom))) {
781: $actiontext = $lt{'srvu'};
1.406.2.14 raeburn 782: $fixeddom = 1;
1.213 raeburn 783: }
1.324 raeburn 784: $r->print("<h3>$actiontext</h3>");
1.213 raeburn 785: if ($env{'form.origform'} ne 'crtusername') {
1.406.2.5 raeburn 786: if ($response) {
787: $r->print("\n<div>$response</div>".
788: '<br clear="all" />');
789: }
1.213 raeburn 790: }
1.406.2.13 raeburn 791: $r->print(&entry_form($defdom,$srch,$forcenewuser,$context,$response,$crstype,$fixeddom));
1.107 www 792: }
1.110 albertel 793: }
794:
1.324 raeburn 795: sub customrole_javascript {
796: my $js = <<"END";
797: <script type="text/javascript">
798: // <![CDATA[
799:
800: function setCustomFields() {
801: if (document.docustom.customroleaction.length > 0) {
802: for (var i=0; i<document.docustom.customroleaction.length; i++) {
803: if (document.docustom.customroleaction[i].checked) {
804: if (document.docustom.customroleaction[i].value == 'new') {
805: document.docustom.rolename.selectedIndex = 0;
806: } else {
807: document.docustom.newrolename.value = '';
808: }
809: }
810: }
811: }
812: return;
813: }
814:
815: function setCustomAction(caller) {
816: if (document.docustom.customroleaction.length > 0) {
817: for (var i=0; i<document.docustom.customroleaction.length; i++) {
818: if (document.docustom.customroleaction[i].value == caller) {
819: document.docustom.customroleaction[i].checked = true;
820: }
821: }
822: }
823: setCustomFields();
824: return;
825: }
826:
827: // ]]>
828: </script>
829: END
830: return $js;
831: }
832:
1.160 raeburn 833: sub entry_form {
1.406.2.5 raeburn 834: my ($dom,$srch,$forcenewuser,$context,$responsemsg,$crstype,$fixeddom) = @_;
1.229 raeburn 835: my ($usertype,$inexact);
1.214 raeburn 836: if (ref($srch) eq 'HASH') {
837: if (($srch->{'srchin'} eq 'dom') &&
838: ($srch->{'srchby'} eq 'uname') &&
839: ($srch->{'srchtype'} eq 'exact') &&
840: ($srch->{'srchdomain'} ne '') &&
841: ($srch->{'srchterm'} ne '')) {
1.353 raeburn 842: my (%curr_rules,%got_rules);
1.214 raeburn 843: my ($rules,$ruleorder) =
844: &Apache::lonnet::inst_userrules($srch->{'srchdomain'},'username');
1.353 raeburn 845: $usertype = &Apache::lonuserutils::check_usertype($srch->{'srchdomain'},$srch->{'srchterm'},$rules,\%curr_rules,\%got_rules);
1.229 raeburn 846: } else {
847: $inexact = 1;
1.214 raeburn 848: }
1.207 raeburn 849: }
1.406.2.14 raeburn 850: my ($cancreate,$noinstd);
851: if ($env{'form.action'} eq 'accesslogs') {
852: $noinstd = 1;
853: } else {
854: $cancreate =
855: &Apache::lonuserutils::can_create_user($dom,$context,$usertype);
856: }
1.406.2.3 raeburn 857: my ($userpicker,$cansearch) =
1.179 raeburn 858: &Apache::loncommon::user_picker($dom,$srch,$forcenewuser,
1.406.2.14 raeburn 859: 'document.crtuser',$cancreate,$usertype,$context,$fixeddom,$noinstd);
1.160 raeburn 860: my $srchbutton = &mt('Search');
1.229 raeburn 861: if ($env{'form.action'} eq 'singlestudent') {
862: $srchbutton = &mt('Search and Enroll');
1.406.2.5 raeburn 863: } elsif ($env{'form.action'} eq 'accesslogs') {
864: $srchbutton = &mt('Search');
1.229 raeburn 865: } elsif ($cancreate && $responsemsg ne '' && $inexact) {
866: $srchbutton = &mt('Search or Add New User');
867: }
1.406.2.3 raeburn 868: my $output;
869: if ($cansearch) {
870: $output = <<"ENDBLOCK";
1.160 raeburn 871: <form action="/adm/createuser" method="post" name="crtuser">
1.190 raeburn 872: <input type="hidden" name="action" value="$env{'form.action'}" />
1.160 raeburn 873: <input type="hidden" name="phase" value="get_user_info" />
874: $userpicker
1.179 raeburn 875: <input name="userrole" type="button" value="$srchbutton" onclick="javascript:validateEntry(document.crtuser)" />
1.160 raeburn 876: </form>
1.207 raeburn 877: ENDBLOCK
1.406.2.3 raeburn 878: } else {
879: $output = '<p>'.$userpicker.'</p>';
880: }
1.406.2.7 raeburn 881: if (($env{'form.phase'} eq '') && ($env{'form.action'} ne 'accesslogs') &&
882: (!(($env{'form.action'} eq 'singleuser') && ($context eq 'domain') &&
883: (!&Apache::lonnet::allowed('mau',$env{'request.role.domain'}))))) {
1.207 raeburn 884: my $defdom=$env{'request.role.domain'};
885: my $domform = &Apache::loncommon::select_dom_form($defdom,'srchdomain');
886: my %lt=&Apache::lonlocal::texthash(
1.229 raeburn 887: 'enro' => 'Enroll one student',
1.318 raeburn 888: 'enrm' => 'Enroll one member',
1.229 raeburn 889: 'admo' => 'Add/modify a single user',
890: 'crea' => 'create new user if required',
891: 'uskn' => "username is known",
1.207 raeburn 892: 'crnu' => 'Create a new user',
893: 'usr' => 'Username',
894: 'dom' => 'in domain',
1.229 raeburn 895: 'enrl' => 'Enroll',
896: 'cram' => 'Create/Modify user',
1.207 raeburn 897: );
1.229 raeburn 898: my $sellink=&Apache::loncommon::selectstudent_link('crtusername','srchterm','srchdomain');
899: my ($title,$buttontext,$showresponse);
1.318 raeburn 900: if ($env{'form.action'} eq 'singlestudent') {
901: if ($crstype eq 'Community') {
902: $title = $lt{'enrm'};
903: } else {
904: $title = $lt{'enro'};
905: }
1.229 raeburn 906: $buttontext = $lt{'enrl'};
907: } else {
908: $title = $lt{'admo'};
909: $buttontext = $lt{'cram'};
910: }
911: if ($cancreate) {
912: $title .= ' <span class="LC_cusr_subheading">('.$lt{'crea'}.')</span>';
913: } else {
914: $title .= ' <span class="LC_cusr_subheading">('.$lt{'uskn'}.')</span>';
915: }
916: if ($env{'form.origform'} eq 'crtusername') {
917: $showresponse = $responsemsg;
918: }
1.207 raeburn 919: $output .= <<"ENDDOCUMENT";
1.229 raeburn 920: <br />
1.207 raeburn 921: <form action="/adm/createuser" method="post" name="crtusername">
922: <input type="hidden" name="action" value="$env{'form.action'}" />
923: <input type="hidden" name="phase" value="createnewuser" />
924: <input type="hidden" name="srchtype" value="exact" />
1.233 raeburn 925: <input type="hidden" name="srchby" value="uname" />
1.207 raeburn 926: <input type="hidden" name="srchin" value="dom" />
927: <input type="hidden" name="forcenewuser" value="1" />
928: <input type="hidden" name="origform" value="crtusername" />
1.229 raeburn 929: <h3>$title</h3>
930: $showresponse
1.207 raeburn 931: <table>
932: <tr>
933: <td>$lt{'usr'}:</td>
934: <td><input type="text" size="15" name="srchterm" /></td>
935: <td> $lt{'dom'}:</td><td>$domform</td>
1.229 raeburn 936: <td> $sellink </td>
937: <td> <input name="userrole" type="submit" value="$buttontext" /></td>
1.207 raeburn 938: </tr>
939: </table>
940: </form>
1.160 raeburn 941: ENDDOCUMENT
1.207 raeburn 942: }
1.160 raeburn 943: return $output;
944: }
1.110 albertel 945:
946: sub user_modification_js {
1.113 raeburn 947: my ($pjump_def,$dc_setcourse_code,$nondc_setsection_code,$groupslist)=@_;
948:
1.110 albertel 949: return <<END;
950: <script type="text/javascript" language="Javascript">
1.301 bisitz 951: // <![CDATA[
1.314 raeburn 952:
1.110 albertel 953: $pjump_def
954: $dc_setcourse_code
955:
956: function dateset() {
957: eval("document.cu."+document.cu.pres_marker.value+
958: ".value=document.cu.pres_value.value");
1.359 www 959: modalWindow.close();
1.110 albertel 960: }
961:
1.113 raeburn 962: $nondc_setsection_code
1.301 bisitz 963: // ]]>
1.110 albertel 964: </script>
965: END
1.2 www 966: }
967:
968: # =================================================================== Phase two
1.160 raeburn 969: sub print_user_selection_page {
1.351 raeburn 970: my ($r,$response,$srch,$srch_results,$srcharray,$context,$opener_elements,$crstype,$brcrum) = @_;
1.160 raeburn 971: my @fields = ('username','domain','lastname','firstname','permanentemail');
972: my $sortby = $env{'form.sortby'};
973:
974: if (!grep(/^\Q$sortby\E$/,@fields)) {
975: $sortby = 'lastname';
976: }
977:
978: my ($jsback,$elements) = &crumb_utilities();
979:
980: my $jscript = (<<ENDSCRIPT);
981: <script type="text/javascript">
1.301 bisitz 982: // <![CDATA[
1.160 raeburn 983: function pickuser(uname,udom) {
984: document.usersrchform.seluname.value=uname;
985: document.usersrchform.seludom.value=udom;
986: document.usersrchform.phase.value="userpicked";
987: document.usersrchform.submit();
988: }
989:
990: $jsback
1.301 bisitz 991: // ]]>
1.160 raeburn 992: </script>
993: ENDSCRIPT
994:
995: my %lt=&Apache::lonlocal::texthash(
1.179 raeburn 996: 'usrch' => "User Search to add/modify roles",
997: 'stusrch' => "User Search to enroll student",
1.318 raeburn 998: 'memsrch' => "User Search to enroll member",
1.406.2.5 raeburn 999: 'srcva' => "Search for a user and view access log information",
1.406.2.7 raeburn 1000: 'usrvu' => "User Search to view user roles",
1.179 raeburn 1001: 'usel' => "Select a user to add/modify roles",
1.406.2.7 raeburn 1002: 'suvr' => "Select a user to view roles",
1.318 raeburn 1003: 'stusel' => "Select a user to enroll as a student",
1004: 'memsel' => "Select a user to enroll as a member",
1.406.2.5 raeburn 1005: 'vacsel' => "Select a user to view access log",
1.160 raeburn 1006: 'username' => "username",
1007: 'domain' => "domain",
1008: 'lastname' => "last name",
1009: 'firstname' => "first name",
1010: 'permanentemail' => "permanent e-mail",
1011: );
1.302 raeburn 1012: if ($context eq 'requestcrs') {
1013: $r->print('<div>');
1014: } else {
1.406.2.7 raeburn 1015: my %breadcrumb_text = &singleuser_breadcrumb($crstype,$context,$srch->{'srchdomain'});
1.351 raeburn 1016: my $helpitem;
1017: if ($env{'form.action'} eq 'singleuser') {
1018: $helpitem = 'Course_Change_Privileges';
1019: } elsif ($env{'form.action'} eq 'singlestudent') {
1020: $helpitem = 'Course_Add_Student';
1.406.2.14 raeburn 1021: } elsif ($context eq 'author') {
1022: $helpitem = 'Author_Change_Privileges';
1023: } elsif ($context eq 'domain') {
1024: $helpitem = 'Domain_Change_Privileges';
1.351 raeburn 1025: }
1026: push (@{$brcrum},
1027: {href => "javascript:backPage(document.usersrchform,'','')",
1028: text => $breadcrumb_text{'search'},
1029: faq => 282,
1030: bug => 'Instructor Interface',},
1031: {href => "javascript:backPage(document.usersrchform,'get_user_info','select')",
1032: text => $breadcrumb_text{'userpicked'},
1033: faq => 282,
1034: bug => 'Instructor Interface',
1035: help => $helpitem}
1036: );
1037: $r->print(&Apache::loncommon::start_page('User Management',$jscript,{bread_crumbs => $brcrum}));
1.302 raeburn 1038: if ($env{'form.action'} eq 'singleuser') {
1.406.2.7 raeburn 1039: my $readonly;
1040: if (($context eq 'domain') && (!&Apache::lonnet::allowed('mau',$srch->{'srchdomain'}))) {
1041: $readonly = 1;
1042: $r->print("<b>$lt{'usrvu'}</b><br />");
1043: } else {
1044: $r->print("<b>$lt{'usrch'}</b><br />");
1045: }
1.318 raeburn 1046: $r->print(&entry_form($srch->{'srchdomain'},$srch,undef,$context,undef,$crstype));
1.406.2.7 raeburn 1047: if ($readonly) {
1048: $r->print('<h3>'.$lt{'suvr'}.'</h3>');
1049: } else {
1050: $r->print('<h3>'.$lt{'usel'}.'</h3>');
1051: }
1.302 raeburn 1052: } elsif ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1053: $r->print($jscript."<b>");
1054: if ($crstype eq 'Community') {
1055: $r->print($lt{'memsrch'});
1056: } else {
1057: $r->print($lt{'stusrch'});
1058: }
1059: $r->print("</b><br />");
1060: $r->print(&entry_form($srch->{'srchdomain'},$srch,undef,$context,undef,$crstype));
1061: $r->print('</form><h3>');
1062: if ($crstype eq 'Community') {
1063: $r->print($lt{'memsel'});
1064: } else {
1065: $r->print($lt{'stusel'});
1066: }
1067: $r->print('</h3>');
1.406.2.5 raeburn 1068: } elsif ($env{'form.action'} eq 'accesslogs') {
1069: $r->print("<b>$lt{'srcva'}</b><br />");
1.406.2.14 raeburn 1070: $r->print(&entry_form($srch->{'srchdomain'},$srch,undef,$context,undef,undef,1));
1.406.2.5 raeburn 1071: $r->print('<h3>'.$lt{'vacsel'}.'</h3>');
1.302 raeburn 1072: }
1.179 raeburn 1073: }
1.380 bisitz 1074: $r->print('<form name="usersrchform" method="post" action="">'.
1.160 raeburn 1075: &Apache::loncommon::start_data_table()."\n".
1076: &Apache::loncommon::start_data_table_header_row()."\n".
1077: ' <th> </th>'."\n");
1078: foreach my $field (@fields) {
1079: $r->print(' <th><a href="javascript:document.usersrchform.sortby.value='.
1080: "'".$field."'".';document.usersrchform.submit();">'.
1081: $lt{$field}.'</a></th>'."\n");
1082: }
1083: $r->print(&Apache::loncommon::end_data_table_header_row());
1084:
1085: my @sorted_users = sort {
1.167 albertel 1086: lc($srch_results->{$a}->{$sortby}) cmp lc($srch_results->{$b}->{$sortby})
1.160 raeburn 1087: ||
1.167 albertel 1088: lc($srch_results->{$a}->{lastname}) cmp lc($srch_results->{$b}->{lastname})
1.160 raeburn 1089: ||
1090: lc($srch_results->{$a}->{firstname}) cmp lc($srch_results->{$b}->{firstname})
1.167 albertel 1091: ||
1092: lc($a) cmp lc($b)
1.160 raeburn 1093: } (keys(%$srch_results));
1094:
1095: foreach my $user (@sorted_users) {
1096: my ($uname,$udom) = split(/:/,$user);
1.302 raeburn 1097: my $onclick;
1098: if ($context eq 'requestcrs') {
1.314 raeburn 1099: $onclick =
1.302 raeburn 1100: 'onclick="javascript:gochoose('."'$uname','$udom',".
1101: "'$srch_results->{$user}->{firstname}',".
1102: "'$srch_results->{$user}->{lastname}',".
1103: "'$srch_results->{$user}->{permanentemail}'".');"';
1104: } else {
1.314 raeburn 1105: $onclick =
1.302 raeburn 1106: ' onclick="javascript:pickuser('."'".$uname."'".','."'".$udom."'".');"';
1107: }
1.160 raeburn 1108: $r->print(&Apache::loncommon::start_data_table_row().
1.302 raeburn 1109: '<td><input type="button" name="seluser" value="'.&mt('Select').'" '.
1110: $onclick.' /></td>'.
1.160 raeburn 1111: '<td><tt>'.$uname.'</tt></td>'.
1112: '<td><tt>'.$udom.'</tt></td>');
1113: foreach my $field ('lastname','firstname','permanentemail') {
1114: $r->print('<td>'.$srch_results->{$user}->{$field}.'</td>');
1115: }
1116: $r->print(&Apache::loncommon::end_data_table_row());
1117: }
1118: $r->print(&Apache::loncommon::end_data_table().'<br /><br />');
1.179 raeburn 1119: if (ref($srcharray) eq 'ARRAY') {
1120: foreach my $item (@{$srcharray}) {
1121: $r->print('<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n");
1122: }
1123: }
1.160 raeburn 1124: $r->print(' <input type="hidden" name="sortby" value="'.$sortby.'" />'."\n".
1125: ' <input type="hidden" name="seluname" value="" />'."\n".
1126: ' <input type="hidden" name="seludom" value="" />'."\n".
1.179 raeburn 1127: ' <input type="hidden" name="currstate" value="select" />'."\n".
1.190 raeburn 1128: ' <input type="hidden" name="phase" value="get_user_info" />'."\n".
1.214 raeburn 1129: ' <input type="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n");
1.302 raeburn 1130: if ($context eq 'requestcrs') {
1131: $r->print($opener_elements.'</form></div>');
1132: } else {
1.351 raeburn 1133: $r->print($response.'</form>');
1.302 raeburn 1134: }
1.160 raeburn 1135: }
1136:
1137: sub print_user_query_page {
1.351 raeburn 1138: my ($r,$caller,$brcrum) = @_;
1.160 raeburn 1139: # FIXME - this is for a network-wide name search (similar to catalog search)
1140: # To use frames with similar behavior to catalog/portfolio search.
1141: # To be implemented.
1142: return;
1143: }
1144:
1.42 matthew 1145: sub print_user_modification_page {
1.375 raeburn 1146: my ($r,$ccuname,$ccdomain,$srch,$response,$context,$permission,$crstype,
1147: $brcrum,$showcredits) = @_;
1.185 raeburn 1148: if (($ccuname eq '') || ($ccdomain eq '')) {
1.215 raeburn 1149: my $usermsg = &mt('No username and/or domain provided.');
1150: $env{'form.phase'} = '';
1.406.2.14 raeburn 1151: &print_username_entry_form($r,$context,$usermsg,'','',$crstype,$brcrum,
1152: $permission);
1.58 www 1153: return;
1154: }
1.213 raeburn 1155: my ($form,$formname);
1156: if ($env{'form.action'} eq 'singlestudent') {
1157: $form = 'document.enrollstudent';
1158: $formname = 'enrollstudent';
1159: } else {
1160: $form = 'document.cu';
1161: $formname = 'cu';
1162: }
1.188 raeburn 1163: my %abv_auth = &auth_abbrev();
1.227 raeburn 1164: my (%rulematch,%inst_results,$newuser,%alerts,%curr_rules,%got_rules);
1.185 raeburn 1165: my $uhome=&Apache::lonnet::homeserver($ccuname,$ccdomain);
1166: if ($uhome eq 'no_host') {
1.215 raeburn 1167: my $usertype;
1168: my ($rules,$ruleorder) =
1169: &Apache::lonnet::inst_userrules($ccdomain,'username');
1170: $usertype =
1.353 raeburn 1171: &Apache::lonuserutils::check_usertype($ccdomain,$ccuname,$rules,
1.362 raeburn 1172: \%curr_rules,\%got_rules);
1.215 raeburn 1173: my $cancreate =
1174: &Apache::lonuserutils::can_create_user($ccdomain,$context,
1175: $usertype);
1176: if (!$cancreate) {
1.292 bisitz 1177: my $helplink = 'javascript:helpMenu('."'display'".')';
1.215 raeburn 1178: my %usertypetext = (
1179: official => 'institutional',
1180: unofficial => 'non-institutional',
1181: );
1182: my $response;
1183: if ($env{'form.origform'} eq 'crtusername') {
1.362 raeburn 1184: $response = '<span class="LC_warning">'.
1185: &mt('No match found for the username [_1] in LON-CAPA domain: [_2]',
1186: '<b>'.$ccuname.'</b>',$ccdomain).
1.215 raeburn 1187: '</span><br />';
1188: }
1.292 bisitz 1189: $response .= '<p class="LC_warning">'
1190: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
1.406.2.6 raeburn 1191: .' ';
1192: if ($context eq 'domain') {
1193: $response .= &mt('Please contact a [_1] for assistance.',
1194: &Apache::lonnet::plaintext('dc'));
1195: } else {
1196: $response .= &mt('Please contact the [_1]helpdesk[_2] for assistance.'
1197: ,'<a href="'.$helplink.'">','</a>');
1198: }
1199: $response .= '</p><br />';
1.215 raeburn 1200: $env{'form.phase'} = '';
1.406.2.14 raeburn 1201: &print_username_entry_form($r,$context,$response,undef,undef,$crstype,$brcrum,
1202: $permission);
1.215 raeburn 1203: return;
1204: }
1.188 raeburn 1205: $newuser = 1;
1.193 raeburn 1206: my $checkhash;
1207: my $checks = { 'username' => 1 };
1.196 raeburn 1208: $checkhash->{$ccuname.':'.$ccdomain} = { 'newuser' => $newuser };
1.193 raeburn 1209: &Apache::loncommon::user_rule_check($checkhash,$checks,
1.196 raeburn 1210: \%alerts,\%rulematch,\%inst_results,\%curr_rules,\%got_rules);
1211: if (ref($alerts{'username'}) eq 'HASH') {
1212: if (ref($alerts{'username'}{$ccdomain}) eq 'HASH') {
1213: my $domdesc =
1.193 raeburn 1214: &Apache::lonnet::domain($ccdomain,'description');
1.196 raeburn 1215: if ($alerts{'username'}{$ccdomain}{$ccuname}) {
1216: my $userchkmsg;
1217: if (ref($curr_rules{$ccdomain}) eq 'HASH') {
1218: $userchkmsg =
1219: &Apache::loncommon::instrule_disallow_msg('username',
1.193 raeburn 1220: $domdesc,1).
1221: &Apache::loncommon::user_rule_formats($ccdomain,
1222: $domdesc,$curr_rules{$ccdomain}{'username'},
1223: 'username');
1.196 raeburn 1224: }
1.215 raeburn 1225: $env{'form.phase'} = '';
1.406.2.14 raeburn 1226: &print_username_entry_form($r,$context,$userchkmsg,undef,undef,$crstype,$brcrum,
1227: $permission);
1.196 raeburn 1228: return;
1.215 raeburn 1229: }
1.193 raeburn 1230: }
1.185 raeburn 1231: }
1.187 raeburn 1232: } else {
1.188 raeburn 1233: $newuser = 0;
1.185 raeburn 1234: }
1.160 raeburn 1235: if ($response) {
1.215 raeburn 1236: $response = '<br />'.$response;
1.160 raeburn 1237: }
1.149 raeburn 1238:
1.52 matthew 1239: my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
1.88 raeburn 1240: my $dc_setcourse_code = '';
1.119 raeburn 1241: my $nondc_setsection_code = '';
1.112 albertel 1242: my %loaditem;
1.114 albertel 1243:
1.216 raeburn 1244: my $groupslist = &Apache::lonuserutils::get_groupslist();
1.88 raeburn 1245:
1.375 raeburn 1246: my $js = &validation_javascript($context,$ccdomain,$pjump_def,$crstype,
1.216 raeburn 1247: $groupslist,$newuser,$formname,\%loaditem);
1.406.2.7 raeburn 1248: my %breadcrumb_text = &singleuser_breadcrumb($crstype,$context,$ccdomain);
1.224 raeburn 1249: my $helpitem = 'Course_Change_Privileges';
1250: if ($env{'form.action'} eq 'singlestudent') {
1251: $helpitem = 'Course_Add_Student';
1.406.2.14 raeburn 1252: } elsif ($context eq 'author') {
1253: $helpitem = 'Author_Change_Privileges';
1254: } elsif ($context eq 'domain') {
1255: $helpitem = 'Domain_Change_Privileges';
1.224 raeburn 1256: }
1.351 raeburn 1257: push (@{$brcrum},
1258: {href => "javascript:backPage($form)",
1259: text => $breadcrumb_text{'search'},
1260: faq => 282,
1261: bug => 'Instructor Interface',});
1262: if ($env{'form.phase'} eq 'userpicked') {
1263: push(@{$brcrum},
1264: {href => "javascript:backPage($form,'get_user_info','select')",
1265: text => $breadcrumb_text{'userpicked'},
1266: faq => 282,
1267: bug => 'Instructor Interface',});
1268: }
1269: push(@{$brcrum},
1270: {href => "javascript:backPage($form,'$env{'form.phase'}','modify')",
1271: text => $breadcrumb_text{'modify'},
1272: faq => 282,
1273: bug => 'Instructor Interface',
1274: help => $helpitem});
1275: my $args = {'add_entries' => \%loaditem,
1276: 'bread_crumbs' => $brcrum,
1277: 'bread_crumbs_component' => 'User Management'};
1278: if ($env{'form.popup'}) {
1279: $args->{'no_nav_bar'} = 1;
1280: }
1281: my $start_page =
1282: &Apache::loncommon::start_page('User Management',$js,$args);
1.3 www 1283:
1.25 matthew 1284: my $forminfo =<<"ENDFORMINFO";
1.216 raeburn 1285: <form action="/adm/createuser" method="post" name="$formname">
1.190 raeburn 1286: <input type="hidden" name="phase" value="update_user_data" />
1.188 raeburn 1287: <input type="hidden" name="ccuname" value="$ccuname" />
1288: <input type="hidden" name="ccdomain" value="$ccdomain" />
1.157 albertel 1289: <input type="hidden" name="pres_value" value="" />
1290: <input type="hidden" name="pres_type" value="" />
1291: <input type="hidden" name="pres_marker" value="" />
1.25 matthew 1292: ENDFORMINFO
1.375 raeburn 1293: my (%inccourses,$roledom,$defaultcredits);
1.329 raeburn 1294: if ($context eq 'course') {
1295: $inccourses{$env{'request.course.id'}}=1;
1296: $roledom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1.375 raeburn 1297: if ($showcredits) {
1298: $defaultcredits = &Apache::lonuserutils::get_defaultcredits();
1299: }
1.329 raeburn 1300: } elsif ($context eq 'author') {
1301: $roledom = $env{'request.role.domain'};
1302: } elsif ($context eq 'domain') {
1303: foreach my $key (keys(%env)) {
1304: $roledom = $env{'request.role.domain'};
1305: if ($key=~/^user\.priv\.cm\.\/($roledom)\/($match_username)/) {
1306: $inccourses{$1.'_'.$2}=1;
1307: }
1308: }
1309: } else {
1310: foreach my $key (keys(%env)) {
1311: if ($key=~/^user\.priv\.cm\.\/($match_domain)\/($match_username)/) {
1312: $inccourses{$1.'_'.$2}=1;
1313: }
1.2 www 1314: }
1.24 matthew 1315: }
1.389 bisitz 1316: my $title = '';
1.216 raeburn 1317: if ($newuser) {
1.406.2.9 raeburn 1318: my ($portfolioform,$domroleform);
1.267 raeburn 1319: if ((&Apache::lonnet::allowed('mpq',$env{'request.role.domain'})) ||
1320: (&Apache::lonnet::allowed('mut',$env{'request.role.domain'}))) {
1321: # Current user has quota or user tools modification privileges
1.378 raeburn 1322: $portfolioform = '<br />'.&user_quotas($ccuname,$ccdomain);
1.134 raeburn 1323: }
1.383 raeburn 1324: if ((&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) &&
1325: ($ccdomain eq $env{'request.role.domain'})) {
1.362 raeburn 1326: $domroleform = '<br />'.&domainrole_req($ccuname,$ccdomain);
1327: }
1.227 raeburn 1328: &initialize_authen_forms($ccdomain,$formname);
1.188 raeburn 1329: my %lt=&Apache::lonlocal::texthash(
1330: 'lg' => 'Login Data',
1.190 raeburn 1331: 'hs' => "Home Server",
1.188 raeburn 1332: );
1.185 raeburn 1333: $r->print(<<ENDTITLE);
1.110 albertel 1334: $start_page
1.160 raeburn 1335: $response
1.25 matthew 1336: $forminfo
1.31 matthew 1337: <script type="text/javascript" language="Javascript">
1.301 bisitz 1338: // <![CDATA[
1.20 harris41 1339: $loginscript
1.301 bisitz 1340: // ]]>
1.31 matthew 1341: </script>
1.20 harris41 1342: <input type='hidden' name='makeuser' value='1' />
1.185 raeburn 1343: ENDTITLE
1.213 raeburn 1344: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1345: if ($crstype eq 'Community') {
1.389 bisitz 1346: $title = &mt('Create New User [_1] in domain [_2] as a member',
1347: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.318 raeburn 1348: } else {
1.389 bisitz 1349: $title = &mt('Create New User [_1] in domain [_2] as a student',
1350: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.318 raeburn 1351: }
1.389 bisitz 1352: } else {
1353: $title = &mt('Create New User [_1] in domain [_2]',
1354: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.213 raeburn 1355: }
1.389 bisitz 1356: $r->print('<h2>'.$title.'</h2>'."\n");
1357: $r->print('<div class="LC_left_float">');
1.393 raeburn 1358: $r->print(&personal_data_display($ccuname,$ccdomain,$newuser,$context,
1359: $inst_results{$ccuname.':'.$ccdomain}));
1360: # Option to disable student/employee ID conflict checking not offerred for new users.
1.187 raeburn 1361: my ($home_server_pick,$numlib) =
1362: &Apache::loncommon::home_server_form_item($ccdomain,'hserver',
1363: 'default','hide');
1364: if ($numlib > 1) {
1365: $r->print("
1.185 raeburn 1366: <br />
1.187 raeburn 1367: $lt{'hs'}: $home_server_pick
1368: <br />");
1369: } else {
1370: $r->print($home_server_pick);
1371: }
1.304 raeburn 1372: if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
1.362 raeburn 1373: $r->print('<br /><h3>'.
1374: &mt('User Can Request Creation of Courses/Communities in this Domain?').'</h3>'.
1.304 raeburn 1375: &Apache::loncommon::start_data_table().
1376: &build_tools_display($ccuname,$ccdomain,
1377: 'requestcourses').
1378: &Apache::loncommon::end_data_table());
1379: }
1.188 raeburn 1380: $r->print('</div>'."\n".'<div class="LC_left_float"><h3>'.
1381: $lt{'lg'}.'</h3>');
1.185 raeburn 1382: my ($fixedauth,$varauth,$authmsg);
1.193 raeburn 1383: if (ref($rulematch{$ccuname.':'.$ccdomain}) eq 'HASH') {
1384: my $matchedrule = $rulematch{$ccuname.':'.$ccdomain}{'username'};
1385: my ($rules,$ruleorder) =
1386: &Apache::lonnet::inst_userrules($ccdomain,'username');
1.185 raeburn 1387: if (ref($rules) eq 'HASH') {
1.193 raeburn 1388: if (ref($rules->{$matchedrule}) eq 'HASH') {
1389: my $authtype = $rules->{$matchedrule}{'authtype'};
1.185 raeburn 1390: if ($authtype !~ /^(krb4|krb5|int|fsys|loc)$/) {
1.190 raeburn 1391: $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1.275 raeburn 1392: } else {
1.193 raeburn 1393: my $authparm = $rules->{$matchedrule}{'authparm'};
1.273 raeburn 1394: $authmsg = $rules->{$matchedrule}{'authmsg'};
1.185 raeburn 1395: if ($authtype =~ /^krb(4|5)$/) {
1396: my $ver = $1;
1397: if ($authparm ne '') {
1398: $fixedauth = <<"KERB";
1399: <input type="hidden" name="login" value="krb" />
1400: <input type="hidden" name="krbver" value="$ver" />
1401: <input type="hidden" name="krbarg" value="$authparm" />
1402: KERB
1403: }
1404: } else {
1405: $fixedauth =
1406: '<input type="hidden" name="login" value="'.$authtype.'" />'."\n";
1.193 raeburn 1407: if ($rules->{$matchedrule}{'authparmfixed'}) {
1.185 raeburn 1408: $fixedauth .=
1409: '<input type="hidden" name="'.$authtype.'arg" value="'.$authparm.'" />'."\n";
1410: } else {
1.273 raeburn 1411: if ($authtype eq 'int') {
1412: $varauth = '<br />'.
1.301 bisitz 1413: &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 1414: } elsif ($authtype eq 'loc') {
1415: $varauth = '<br />'.
1416: &mt('[_1] Local Authentication with argument [_2]','','<input type="text" name="'.$authtype.'arg" value="" />')."\n";
1417: } else {
1418: $varauth =
1.185 raeburn 1419: '<input type="text" name="'.$authtype.'arg" value="" />'."\n";
1.273 raeburn 1420: }
1.185 raeburn 1421: }
1422: }
1423: }
1424: } else {
1.190 raeburn 1425: $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1.185 raeburn 1426: }
1427: }
1428: if ($authmsg) {
1429: $r->print(<<ENDAUTH);
1430: $fixedauth
1431: $authmsg
1432: $varauth
1433: ENDAUTH
1434: }
1435: } else {
1.190 raeburn 1436: $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1.187 raeburn 1437: }
1.406.2.9 raeburn 1438: $r->print($portfolioform.$domroleform);
1.215 raeburn 1439: if ($env{'form.action'} eq 'singlestudent') {
1440: $r->print(&date_sections_select($context,$newuser,$formname,
1.375 raeburn 1441: $permission,$crstype,$ccuname,
1442: $ccdomain,$showcredits));
1.215 raeburn 1443: }
1444: $r->print('</div><div class="LC_clear_float_footer"></div>');
1.216 raeburn 1445: } else { # user already exists
1.389 bisitz 1446: $r->print($start_page.$forminfo);
1.213 raeburn 1447: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1448: if ($crstype eq 'Community') {
1.389 bisitz 1449: $title = &mt('Enroll one member: [_1] in domain [_2]',
1450: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.318 raeburn 1451: } else {
1.389 bisitz 1452: $title = &mt('Enroll one student: [_1] in domain [_2]',
1453: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.318 raeburn 1454: }
1.213 raeburn 1455: } else {
1.406.2.6 raeburn 1456: if ($permission->{'cusr'}) {
1457: $title = &mt('Modify existing user: [_1] in domain [_2]',
1458: '"'.$ccuname.'"','"'.$ccdomain.'"');
1459: } else {
1460: $title = &mt('Existing user: [_1] in domain [_2]',
1.389 bisitz 1461: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.406.2.6 raeburn 1462: }
1.213 raeburn 1463: }
1.389 bisitz 1464: $r->print('<h2>'.$title.'</h2>'."\n");
1465: $r->print('<div class="LC_left_float">');
1.393 raeburn 1466: $r->print(&personal_data_display($ccuname,$ccdomain,$newuser,$context,
1467: $inst_results{$ccuname.':'.$ccdomain}));
1.406.2.6 raeburn 1468: if ((&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) ||
1469: (&Apache::lonnet::allowed('udp',$env{'request.role.domain'}))) {
1.362 raeburn 1470: $r->print('<br /><h3>'.&mt('User Can Request Creation of Courses/Communities in this Domain?').'</h3>'.
1.300 raeburn 1471: &Apache::loncommon::start_data_table());
1.314 raeburn 1472: if ($env{'request.role.domain'} eq $ccdomain) {
1.300 raeburn 1473: $r->print(&build_tools_display($ccuname,$ccdomain,'requestcourses'));
1474: } else {
1475: $r->print(&coursereq_externaluser($ccuname,$ccdomain,
1476: $env{'request.role.domain'}));
1477: }
1478: $r->print(&Apache::loncommon::end_data_table());
1.275 raeburn 1479: }
1.199 raeburn 1480: $r->print('</div>');
1.406.2.9 raeburn 1481: my @order = ('auth','quota','tools','requestauthor');
1.362 raeburn 1482: my %user_text;
1483: my ($isadv,$isauthor) =
1.406.2.6 raeburn 1484: &Apache::lonnet::is_advanced_user($ccdomain,$ccuname);
1.362 raeburn 1485: if ((!$isauthor) &&
1.406.2.6 raeburn 1486: ((&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) ||
1487: (&Apache::lonnet::allowed('udp',$env{'request.role.domain'}))) &&
1488: ($env{'request.role.domain'} eq $ccdomain)) {
1.362 raeburn 1489: $user_text{'requestauthor'} = &domainrole_req($ccuname,$ccdomain);
1490: }
1.406.2.17 raeburn 1491: $user_text{'auth'} = &user_authentication($ccuname,$ccdomain,$formname,$crstype,$permission);
1.267 raeburn 1492: if ((&Apache::lonnet::allowed('mpq',$ccdomain)) ||
1.406.2.6 raeburn 1493: (&Apache::lonnet::allowed('mut',$ccdomain)) ||
1494: (&Apache::lonnet::allowed('udp',$ccdomain))) {
1.188 raeburn 1495: # Current user has quota modification privileges
1.378 raeburn 1496: $user_text{'quota'} = &user_quotas($ccuname,$ccdomain);
1.267 raeburn 1497: }
1498: if (!&Apache::lonnet::allowed('mpq',$ccdomain)) {
1499: if (&Apache::lonnet::allowed('mpq',$env{'request.role.domain'})) {
1500: my %lt=&Apache::lonlocal::texthash(
1.385 bisitz 1501: 'dska' => "Disk quotas for user's portfolio and Authoring Space",
1502: 'youd' => "You do not have privileges to modify the portfolio and/or Authoring Space quotas for this user.",
1.267 raeburn 1503: 'ichr' => "If a change is required, contact a domain coordinator for the domain",
1504: );
1.362 raeburn 1505: $user_text{'quota'} = <<ENDNOPORTPRIV;
1.188 raeburn 1506: <h3>$lt{'dska'}</h3>
1507: $lt{'youd'} $lt{'ichr'}: $ccdomain
1508: ENDNOPORTPRIV
1.267 raeburn 1509: }
1510: }
1511: if (!&Apache::lonnet::allowed('mut',$ccdomain)) {
1512: if (&Apache::lonnet::allowed('mut',$env{'request.role.domain'})) {
1513: my %lt=&Apache::lonlocal::texthash(
1514: 'utav' => "User Tools Availability",
1.361 raeburn 1515: 'yodo' => "You do not have privileges to modify Portfolio, Blog, WebDAV, or Personal Information Page settings for this user.",
1.267 raeburn 1516: 'ifch' => "If a change is required, contact a domain coordinator for the domain",
1517: );
1.362 raeburn 1518: $user_text{'tools'} = <<ENDNOTOOLSPRIV;
1.267 raeburn 1519: <h3>$lt{'utav'}</h3>
1520: $lt{'yodo'} $lt{'ifch'}: $ccdomain
1521: ENDNOTOOLSPRIV
1522: }
1.188 raeburn 1523: }
1.362 raeburn 1524: my $gotdiv = 0;
1525: foreach my $item (@order) {
1526: if ($user_text{$item} ne '') {
1527: unless ($gotdiv) {
1528: $r->print('<div class="LC_left_float">');
1529: $gotdiv = 1;
1530: }
1531: $r->print('<br />'.$user_text{$item});
1532: }
1533: }
1534: if ($env{'form.action'} eq 'singlestudent') {
1535: unless ($gotdiv) {
1536: $r->print('<div class="LC_left_float">');
1.213 raeburn 1537: }
1.375 raeburn 1538: my $credits;
1539: if ($showcredits) {
1540: $credits = &get_user_credits($ccuname,$ccdomain,$defaultcredits);
1541: if ($credits eq '') {
1542: $credits = $defaultcredits;
1543: }
1544: }
1.374 raeburn 1545: $r->print(&date_sections_select($context,$newuser,$formname,
1.375 raeburn 1546: $permission,$crstype,$ccuname,
1547: $ccdomain,$showcredits));
1.374 raeburn 1548: }
1.362 raeburn 1549: if ($gotdiv) {
1550: $r->print('</div><div class="LC_clear_float_footer"></div>');
1.188 raeburn 1551: }
1.406.2.6 raeburn 1552: my $statuses;
1553: if (($context eq 'domain') && (&Apache::lonnet::allowed('udp',$ccdomain)) &&
1554: (!&Apache::lonnet::allowed('mau',$ccdomain))) {
1555: $statuses = ['active'];
1556: } elsif (($context eq 'course') && ((&Apache::lonnet::allowed('vcl',$env{'request.course.id'})) ||
1557: ($env{'request.course.sec'} &&
1558: &Apache::lonnet::allowed('vcl',$env{'request.course.id'}.'/'.$env{'request.course.sec'})))) {
1559: $statuses = ['active'];
1560: }
1.217 raeburn 1561: if ($env{'form.action'} ne 'singlestudent') {
1.329 raeburn 1562: &display_existing_roles($r,$ccuname,$ccdomain,\%inccourses,$context,
1.406.2.6 raeburn 1563: $roledom,$crstype,$showcredits,$statuses);
1.217 raeburn 1564: }
1.25 matthew 1565: } ## End of new user/old user logic
1.218 raeburn 1566: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1567: my $btntxt;
1568: if ($crstype eq 'Community') {
1569: $btntxt = &mt('Enroll Member');
1570: } else {
1571: $btntxt = &mt('Enroll Student');
1572: }
1573: $r->print('<br /><input type="button" value="'.$btntxt.'" onclick="setSections(this.form)" />'."\n");
1.406.2.6 raeburn 1574: } elsif ($permission->{'cusr'}) {
1.393 raeburn 1575: $r->print('<div class="LC_left_float">'.
1576: '<fieldset><legend>'.&mt('Add Roles').'</legend>');
1.218 raeburn 1577: my $addrolesdisplay = 0;
1578: if ($context eq 'domain' || $context eq 'author') {
1579: $addrolesdisplay = &new_coauthor_roles($r,$ccuname,$ccdomain);
1580: }
1581: if ($context eq 'domain') {
1.357 raeburn 1582: my $add_domainroles = &new_domain_roles($r,$ccdomain);
1.218 raeburn 1583: if (!$addrolesdisplay) {
1584: $addrolesdisplay = $add_domainroles;
1.2 www 1585: }
1.375 raeburn 1586: $r->print(&course_level_dc($env{'request.role.domain'},$showcredits));
1.393 raeburn 1587: $r->print('</fieldset></div><div class="LC_clear_float_footer"></div>'.
1588: '<br /><input type="button" value="'.&mt('Save').'" onclick="setCourse()" />'."\n");
1.218 raeburn 1589: } elsif ($context eq 'author') {
1590: if ($addrolesdisplay) {
1.393 raeburn 1591: $r->print('</fieldset></div><div class="LC_clear_float_footer"></div>'.
1592: '<br /><input type="button" value="'.&mt('Save').'"');
1.218 raeburn 1593: if ($newuser) {
1.301 bisitz 1594: $r->print(' onclick="auth_check()" \>'."\n");
1.218 raeburn 1595: } else {
1.301 bisitz 1596: $r->print('onclick="this.form.submit()" \>'."\n");
1.218 raeburn 1597: }
1.188 raeburn 1598: } else {
1.393 raeburn 1599: $r->print('</fieldset></div>'.
1600: '<div class="LC_clear_float_footer"></div>'.
1601: '<br /><a href="javascript:backPage(document.cu)">'.
1.218 raeburn 1602: &mt('Back to previous page').'</a>');
1.188 raeburn 1603: }
1604: } else {
1.375 raeburn 1605: $r->print(&course_level_table(\%inccourses,$showcredits,$defaultcredits));
1.393 raeburn 1606: $r->print('</fieldset></div><div class="LC_clear_float_footer"></div>'.
1607: '<br /><input type="button" value="'.&mt('Save').'" onclick="setSections(this.form)" />'."\n");
1.188 raeburn 1608: }
1.88 raeburn 1609: }
1.188 raeburn 1610: $r->print(&Apache::lonhtmlcommon::echo_form_input(['phase','userrole','ccdomain','prevphase','currstate','ccuname','ccdomain']));
1.179 raeburn 1611: $r->print('<input type="hidden" name="currstate" value="" />');
1.393 raeburn 1612: $r->print('<input type="hidden" name="prevphase" value="'.$env{'form.phase'}.'" /></form><br /><br />');
1.218 raeburn 1613: return;
1.2 www 1614: }
1.1 www 1615:
1.213 raeburn 1616: sub singleuser_breadcrumb {
1.406.2.7 raeburn 1617: my ($crstype,$context,$domain) = @_;
1.213 raeburn 1618: my %breadcrumb_text;
1619: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1620: if ($crstype eq 'Community') {
1621: $breadcrumb_text{'search'} = 'Enroll a member';
1622: } else {
1623: $breadcrumb_text{'search'} = 'Enroll a student';
1624: }
1.406.2.7 raeburn 1625: $breadcrumb_text{'userpicked'} = 'Select a user';
1626: $breadcrumb_text{'modify'} = 'Set section/dates';
1.406.2.5 raeburn 1627: } elsif ($env{'form.action'} eq 'accesslogs') {
1628: $breadcrumb_text{'search'} = 'View access logs for a user';
1.406.2.7 raeburn 1629: $breadcrumb_text{'userpicked'} = 'Select a user';
1630: $breadcrumb_text{'activity'} = 'Activity';
1631: } elsif (($env{'form.action'} eq 'singleuser') && ($context eq 'domain') &&
1632: (!&Apache::lonnet::allowed('mau',$domain))) {
1633: $breadcrumb_text{'search'} = "View user's roles";
1634: $breadcrumb_text{'userpicked'} = 'Select a user';
1635: $breadcrumb_text{'modify'} = 'User roles';
1.213 raeburn 1636: } else {
1.229 raeburn 1637: $breadcrumb_text{'search'} = 'Create/modify a user';
1.406.2.7 raeburn 1638: $breadcrumb_text{'userpicked'} = 'Select a user';
1639: $breadcrumb_text{'modify'} = 'Set user role';
1.213 raeburn 1640: }
1641: return %breadcrumb_text;
1642: }
1643:
1644: sub date_sections_select {
1.375 raeburn 1645: my ($context,$newuser,$formname,$permission,$crstype,$ccuname,$ccdomain,
1646: $showcredits) = @_;
1647: my $credits;
1648: if ($showcredits) {
1649: my $defaultcredits = &Apache::lonuserutils::get_defaultcredits();
1650: $credits = &get_user_credits($ccuname,$ccdomain,$defaultcredits);
1651: if ($credits eq '') {
1652: $credits = $defaultcredits;
1653: }
1654: }
1.213 raeburn 1655: my $cid = $env{'request.course.id'};
1656: my ($cnum,$cdom) = &Apache::lonuserutils::get_course_identity($cid);
1657: my $date_table = '<h3>'.&mt('Starting and Ending Dates').'</h3>'."\n".
1658: &Apache::lonuserutils::date_setting_table(undef,undef,$context,
1659: undef,$formname,$permission);
1660: my $rowtitle = 'Section';
1.375 raeburn 1661: my $secbox = '<h3>'.&mt('Section and Credits').'</h3>'."\n".
1.213 raeburn 1662: &Apache::lonuserutils::section_picker($cdom,$cnum,'st',$rowtitle,
1.375 raeburn 1663: $permission,$context,'',$crstype,
1664: $showcredits,$credits);
1.213 raeburn 1665: my $output = $date_table.$secbox;
1666: return $output;
1667: }
1668:
1.216 raeburn 1669: sub validation_javascript {
1.375 raeburn 1670: my ($context,$ccdomain,$pjump_def,$crstype,$groupslist,$newuser,$formname,
1.216 raeburn 1671: $loaditem) = @_;
1672: my $dc_setcourse_code = '';
1673: my $nondc_setsection_code = '';
1674: if ($context eq 'domain') {
1675: my $dcdom = $env{'request.role.domain'};
1676: $loaditem->{'onload'} = "document.cu.coursedesc.value='';";
1.227 raeburn 1677: $dc_setcourse_code =
1678: &Apache::lonuserutils::dc_setcourse_js('cu','singleuser',$context);
1.216 raeburn 1679: } else {
1.227 raeburn 1680: my $checkauth;
1681: if (($newuser) || (&Apache::lonnet::allowed('mau',$ccdomain))) {
1682: $checkauth = 1;
1683: }
1684: if ($context eq 'course') {
1685: $nondc_setsection_code =
1686: &Apache::lonuserutils::setsections_javascript($formname,$groupslist,
1.375 raeburn 1687: undef,$checkauth,
1688: $crstype);
1.227 raeburn 1689: }
1690: if ($checkauth) {
1691: $nondc_setsection_code .=
1692: &Apache::lonuserutils::verify_authen($formname,$context);
1693: }
1.216 raeburn 1694: }
1695: my $js = &user_modification_js($pjump_def,$dc_setcourse_code,
1696: $nondc_setsection_code,$groupslist);
1697: my ($jsback,$elements) = &crumb_utilities();
1698: $js .= "\n".
1.301 bisitz 1699: '<script type="text/javascript">'."\n".
1700: '// <![CDATA['."\n".
1701: $jsback."\n".
1702: '// ]]>'."\n".
1703: '</script>'."\n";
1.216 raeburn 1704: return $js;
1705: }
1706:
1.217 raeburn 1707: sub display_existing_roles {
1.375 raeburn 1708: my ($r,$ccuname,$ccdomain,$inccourses,$context,$roledom,$crstype,
1.406.2.6 raeburn 1709: $showcredits,$statuses) = @_;
1.329 raeburn 1710: my $now=time;
1.406.2.6 raeburn 1711: my $showall = 1;
1712: my ($showexpired,$showactive);
1713: if ((ref($statuses) eq 'ARRAY') && (@{$statuses} > 0)) {
1714: $showall = 0;
1715: if (grep(/^expired$/,@{$statuses})) {
1716: $showexpired = 1;
1717: }
1718: if (grep(/^active$/,@{$statuses})) {
1719: $showactive = 1;
1720: }
1721: if ($showexpired && $showactive) {
1722: $showall = 1;
1723: }
1724: }
1.329 raeburn 1725: my %lt=&Apache::lonlocal::texthash(
1.217 raeburn 1726: 'rer' => "Existing Roles",
1727: 'rev' => "Revoke",
1728: 'del' => "Delete",
1729: 'ren' => "Re-Enable",
1730: 'rol' => "Role",
1731: 'ext' => "Extent",
1.375 raeburn 1732: 'crd' => "Credits",
1.217 raeburn 1733: 'sta' => "Start",
1734: 'end' => "End",
1735: );
1.329 raeburn 1736: my (%rolesdump,%roletext,%sortrole,%roleclass,%rolepriv);
1737: if ($context eq 'course' || $context eq 'author') {
1738: my @roles = &Apache::lonuserutils::roles_by_context($context,1,$crstype);
1739: my %roleshash =
1740: &Apache::lonnet::get_my_roles($ccuname,$ccdomain,'userroles',
1741: ['active','previous','future'],\@roles,$roledom,1);
1742: foreach my $key (keys(%roleshash)) {
1743: my ($start,$end) = split(':',$roleshash{$key});
1744: next if ($start eq '-1' || $end eq '-1');
1745: my ($rnum,$rdom,$role,$sec) = split(':',$key);
1746: if ($context eq 'course') {
1747: next unless (($rnum eq $env{'course.'.$env{'request.course.id'}.'.num'})
1748: && ($rdom eq $env{'course.'.$env{'request.course.id'}.'.domain'}));
1749: } elsif ($context eq 'author') {
1750: next unless (($rnum eq $env{'user.name'}) && ($rdom eq $env{'request.role.domain'}));
1751: }
1752: my ($newkey,$newvalue,$newrole);
1753: $newkey = '/'.$rdom.'/'.$rnum;
1754: if ($sec ne '') {
1755: $newkey .= '/'.$sec;
1756: }
1757: $newvalue = $role;
1758: if ($role =~ /^cr/) {
1759: $newrole = 'cr';
1760: } else {
1761: $newrole = $role;
1762: }
1763: $newkey .= '_'.$newrole;
1764: if ($start ne '' && $end ne '') {
1765: $newvalue .= '_'.$end.'_'.$start;
1.335 raeburn 1766: } elsif ($end ne '') {
1767: $newvalue .= '_'.$end;
1.329 raeburn 1768: }
1769: $rolesdump{$newkey} = $newvalue;
1770: }
1771: } else {
1.360 raeburn 1772: %rolesdump=&Apache::lonnet::dump('roles',$ccdomain,$ccuname);
1.329 raeburn 1773: }
1774: # Build up table of user roles to allow revocation and re-enabling of roles.
1775: my ($tmp) = keys(%rolesdump);
1776: return if ($tmp =~ /^(con_lost|error)/i);
1777: foreach my $area (sort { my $a1=join('_',(split('_',$a))[1,0]);
1778: my $b1=join('_',(split('_',$b))[1,0]);
1779: return $a1 cmp $b1;
1780: } keys(%rolesdump)) {
1781: next if ($area =~ /^rolesdef/);
1782: my $envkey=$area;
1783: my $role = $rolesdump{$area};
1784: my $thisrole=$area;
1785: $area =~ s/\_\w\w$//;
1786: my ($role_code,$role_end_time,$role_start_time) =
1787: split(/_/,$role);
1.406.2.6 raeburn 1788: my $active=1;
1789: $active=0 if (($role_end_time) && ($now>$role_end_time));
1790: if ($active) {
1791: next unless($showall || $showactive);
1792: } else {
1793: next unless($showall || $showexpired);
1794: }
1.217 raeburn 1795: # Is this a custom role? Get role owner and title.
1.329 raeburn 1796: my ($croleudom,$croleuname,$croletitle)=
1797: ($role_code=~m{^cr/($match_domain)/($match_username)/(\w+)$});
1798: my $allowed=0;
1799: my $delallowed=0;
1800: my $sortkey=$role_code;
1801: my $class='Unknown';
1.375 raeburn 1802: my $credits='';
1.406.2.6 raeburn 1803: my $csec;
1.406.2.7 raeburn 1804: if ($area =~ m{^/($match_domain)/($match_courseid)}) {
1.329 raeburn 1805: $class='Course';
1806: my ($coursedom,$coursedir) = ($1,$2);
1807: my $cid = $1.'_'.$2;
1808: # $1.'_'.$2 is the course id (eg. 103_12345abcef103l3).
1.406.2.7 raeburn 1809: next if ($envkey =~ m{^/$match_domain/$match_courseid/[A-Za-z0-9]+_gr$});
1.329 raeburn 1810: my %coursedata=
1811: &Apache::lonnet::coursedescription($cid);
1812: if ($coursedir =~ /^$match_community$/) {
1813: $class='Community';
1814: }
1815: $sortkey.="\0$coursedom";
1816: my $carea;
1817: if (defined($coursedata{'description'})) {
1818: $carea=$coursedata{'description'}.
1819: '<br />'.&mt('Domain').': '.$coursedom.(' 'x8).
1820: &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$coursedir,$coursedom);
1821: $sortkey.="\0".$coursedata{'description'};
1822: } else {
1823: if ($class eq 'Community') {
1824: $carea=&mt('Unavailable community').': '.$area;
1825: $sortkey.="\0".&mt('Unavailable community').': '.$area;
1.217 raeburn 1826: } else {
1827: $carea=&mt('Unavailable course').': '.$area;
1828: $sortkey.="\0".&mt('Unavailable course').': '.$area;
1829: }
1.329 raeburn 1830: }
1831: $sortkey.="\0$coursedir";
1832: $inccourses->{$cid}=1;
1.375 raeburn 1833: if (($showcredits) && ($class eq 'Course') && ($role_code eq 'st')) {
1834: my $defaultcredits = $coursedata{'internal.defaultcredits'};
1835: $credits =
1836: &get_user_credits($ccuname,$ccdomain,$defaultcredits,
1837: $coursedom,$coursedir);
1838: if ($credits eq '') {
1839: $credits = $defaultcredits;
1840: }
1841: }
1.329 raeburn 1842: if ((&Apache::lonnet::allowed('c'.$role_code,$coursedom.'/'.$coursedir)) ||
1843: (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) {
1844: $allowed=1;
1845: }
1846: unless ($allowed) {
1.365 raeburn 1847: my $isowner = &Apache::lonuserutils::is_courseowner($cid,$coursedata{'internal.courseowner'});
1.329 raeburn 1848: if ($isowner) {
1849: if (($role_code eq 'co') && ($class eq 'Community')) {
1850: $allowed = 1;
1851: } elsif (($role_code eq 'cc') && ($class eq 'Course')) {
1852: $allowed = 1;
1853: }
1.217 raeburn 1854: }
1.329 raeburn 1855: }
1856: if ((&Apache::lonnet::allowed('dro',$coursedom)) ||
1857: (&Apache::lonnet::allowed('dro',$ccdomain))) {
1858: $delallowed=1;
1859: }
1.217 raeburn 1860: # - custom role. Needs more info, too
1.329 raeburn 1861: if ($croletitle) {
1862: if (&Apache::lonnet::allowed('ccr',$coursedom.'/'.$coursedir)) {
1863: $allowed=1;
1864: $thisrole.='.'.$role_code;
1.217 raeburn 1865: }
1.329 raeburn 1866: }
1.406.2.6 raeburn 1867: if ($area=~m{^/($match_domain/$match_courseid/(\w+))}) {
1868: $csec = $2;
1869: $carea.='<br />'.&mt('Section: [_1]',$csec);
1870: $sortkey.="\0$csec";
1.329 raeburn 1871: if (!$allowed) {
1.406.2.6 raeburn 1872: if ($env{'request.course.sec'} eq $csec) {
1873: if (&Apache::lonnet::allowed('c'.$role_code,$1)) {
1.329 raeburn 1874: $allowed = 1;
1.217 raeburn 1875: }
1876: }
1877: }
1.329 raeburn 1878: }
1879: $area=$carea;
1880: } else {
1881: $sortkey.="\0".$area;
1882: # Determine if current user is able to revoke privileges
1883: if ($area=~m{^/($match_domain)/}) {
1884: if ((&Apache::lonnet::allowed('c'.$role_code,$1)) ||
1885: (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) {
1886: $allowed=1;
1.217 raeburn 1887: }
1.329 raeburn 1888: if (((&Apache::lonnet::allowed('dro',$1)) ||
1889: (&Apache::lonnet::allowed('dro',$ccdomain))) &&
1890: ($role_code ne 'dc')) {
1891: $delallowed=1;
1.217 raeburn 1892: }
1.329 raeburn 1893: } else {
1894: if (&Apache::lonnet::allowed('c'.$role_code,'/')) {
1.217 raeburn 1895: $allowed=1;
1896: }
1897: }
1.363 raeburn 1898: if ($role_code eq 'ca' || $role_code eq 'au' || $role_code eq 'aa') {
1.377 raeburn 1899: $class='Authoring Space';
1.329 raeburn 1900: } elsif ($role_code eq 'su') {
1901: $class='System';
1.217 raeburn 1902: } else {
1.329 raeburn 1903: $class='Domain';
1.217 raeburn 1904: }
1.329 raeburn 1905: }
1906: if (($role_code eq 'ca') || ($role_code eq 'aa')) {
1907: $area=~m{/($match_domain)/($match_username)};
1908: if (&Apache::lonuserutils::authorpriv($2,$1)) {
1909: $allowed=1;
1.217 raeburn 1910: } else {
1.329 raeburn 1911: $allowed=0;
1.217 raeburn 1912: }
1.329 raeburn 1913: }
1914: my $row = '';
1.406.2.6 raeburn 1915: if ($showall) {
1916: $row.= '<td>';
1917: if (($active) && ($allowed)) {
1918: $row.= '<input type="checkbox" name="rev:'.$thisrole.'" />';
1.217 raeburn 1919: } else {
1.406.2.6 raeburn 1920: if ($active) {
1921: $row.=' ';
1922: } else {
1923: $row.=&mt('expired or revoked');
1924: }
1.217 raeburn 1925: }
1.406.2.6 raeburn 1926: $row.='</td><td>';
1927: if ($allowed && !$active) {
1928: $row.= '<input type="checkbox" name="ren:'.$thisrole.'" />';
1929: } else {
1930: $row.=' ';
1931: }
1932: $row.='</td><td>';
1933: if ($delallowed) {
1934: $row.= '<input type="checkbox" name="del:'.$thisrole.'" />';
1935: } else {
1936: $row.=' ';
1937: }
1938: $row.= '</td>';
1.329 raeburn 1939: }
1940: my $plaintext='';
1941: if (!$croletitle) {
1.375 raeburn 1942: $plaintext=&Apache::lonnet::plaintext($role_code,$class);
1943: if (($showcredits) && ($credits ne '')) {
1944: $plaintext .= '<br/ ><span class="LC_nobreak">'.
1945: '<span class="LC_fontsize_small">'.
1946: &mt('Credits: [_1]',$credits).
1947: '</span></span>';
1948: }
1.329 raeburn 1949: } else {
1950: $plaintext=
1.395 bisitz 1951: &mt('Custom role [_1][_2]defined by [_3]',
1.346 bisitz 1952: '"'.$croletitle.'"',
1953: '<br />',
1954: $croleuname.':'.$croleudom);
1.329 raeburn 1955: }
1.406.2.6 raeburn 1956: $row.= '<td>'.$plaintext.'</td>'.
1957: '<td>'.$area.'</td>'.
1958: '<td>'.($role_start_time?&Apache::lonlocal::locallocaltime($role_start_time)
1959: : ' ' ).'</td>'.
1960: '<td>'.($role_end_time ?&Apache::lonlocal::locallocaltime($role_end_time)
1961: : ' ' ).'</td>';
1.329 raeburn 1962: $sortrole{$sortkey}=$envkey;
1963: $roletext{$envkey}=$row;
1964: $roleclass{$envkey}=$class;
1.406.2.6 raeburn 1965: if ($allowed) {
1966: $rolepriv{$envkey}='edit';
1967: } else {
1968: if ($context eq 'domain') {
1.406.2.7 raeburn 1969: if ((&Apache::lonnet::allowed('vur',$ccdomain)) &&
1970: ($envkey=~m{^/$ccdomain/})) {
1.406.2.6 raeburn 1971: $rolepriv{$envkey}='view';
1972: }
1973: } elsif ($context eq 'course') {
1974: if ((&Apache::lonnet::allowed('vcl',$env{'request.course.id'})) ||
1975: ($env{'request.course.sec'} && ($env{'request.course.sec'} eq $csec) &&
1976: &Apache::lonnet::allowed('vcl',$env{'request.course.id'}.'/'.$env{'request.course.sec'}))) {
1977: $rolepriv{$envkey}='view';
1978: }
1979: }
1980: }
1.329 raeburn 1981: } # end of foreach (table building loop)
1982:
1983: my $rolesdisplay = 0;
1984: my %output = ();
1.377 raeburn 1985: foreach my $type ('Authoring Space','Course','Community','Domain','System','Unknown') {
1.329 raeburn 1986: $output{$type} = '';
1987: foreach my $which (sort {uc($a) cmp uc($b)} (keys(%sortrole))) {
1988: if ( ($roleclass{$sortrole{$which}} =~ /^\Q$type\E/ ) && ($rolepriv{$sortrole{$which}}) ) {
1989: $output{$type}.=
1990: &Apache::loncommon::start_data_table_row().
1991: $roletext{$sortrole{$which}}.
1992: &Apache::loncommon::end_data_table_row();
1.217 raeburn 1993: }
1.329 raeburn 1994: }
1995: unless($output{$type} eq '') {
1996: $output{$type} = '<tr class="LC_info_row">'.
1997: "<td align='center' colspan='7'>".&mt($type)."</td></tr>".
1998: $output{$type};
1999: $rolesdisplay = 1;
2000: }
2001: }
2002: if ($rolesdisplay == 1) {
2003: my $contextrole='';
2004: if ($env{'request.course.id'}) {
2005: if (&Apache::loncommon::course_type() eq 'Community') {
2006: $contextrole = &mt('Existing Roles in this Community');
1.290 bisitz 2007: } else {
1.329 raeburn 2008: $contextrole = &mt('Existing Roles in this Course');
1.290 bisitz 2009: }
1.329 raeburn 2010: } elsif ($env{'request.role'} =~ /^au\./) {
1.377 raeburn 2011: $contextrole = &mt('Existing Co-Author Roles in your Authoring Space');
1.329 raeburn 2012: } else {
1.406.2.6 raeburn 2013: if ($showall) {
2014: $contextrole = &mt('Existing Roles in this Domain');
2015: } elsif ($showactive) {
2016: $contextrole = &mt('Unexpired Roles in this Domain');
2017: } elsif ($showexpired) {
2018: $contextrole = &mt('Expired or Revoked Roles in this Domain');
2019: }
1.329 raeburn 2020: }
1.393 raeburn 2021: $r->print('<div class="LC_left_float">'.
1.375 raeburn 2022: '<fieldset><legend>'.$contextrole.'</legend>'.
1.217 raeburn 2023: &Apache::loncommon::start_data_table("LC_createuser").
1.406.2.6 raeburn 2024: &Apache::loncommon::start_data_table_header_row());
2025: if ($showall) {
2026: $r->print(
2027: '<th>'.$lt{'rev'}.'</th><th>'.$lt{'ren'}.'</th><th>'.$lt{'del'}.'</th>'
2028: );
2029: } elsif ($showexpired) {
2030: $r->print('<th>'.$lt{'rev'}.'</th>');
2031: }
2032: $r->print(
2033: '<th>'.$lt{'rol'}.'</th><th>'.$lt{'ext'}.'</th>'.
2034: '<th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'.
1.217 raeburn 2035: &Apache::loncommon::end_data_table_header_row());
1.377 raeburn 2036: foreach my $type ('Authoring Space','Course','Community','Domain','System','Unknown') {
1.329 raeburn 2037: if ($output{$type}) {
2038: $r->print($output{$type}."\n");
1.217 raeburn 2039: }
2040: }
1.375 raeburn 2041: $r->print(&Apache::loncommon::end_data_table().
2042: '</fieldset></div>');
1.329 raeburn 2043: }
1.217 raeburn 2044: return;
2045: }
2046:
1.218 raeburn 2047: sub new_coauthor_roles {
2048: my ($r,$ccuname,$ccdomain) = @_;
2049: my $addrolesdisplay = 0;
2050: #
2051: # Co-Author
2052: #
2053: if (&Apache::lonuserutils::authorpriv($env{'user.name'},
2054: $env{'request.role.domain'}) &&
2055: ($env{'user.name'} ne $ccuname || $env{'user.domain'} ne $ccdomain)) {
2056: # No sense in assigning co-author role to yourself
2057: $addrolesdisplay = 1;
2058: my $cuname=$env{'user.name'};
2059: my $cudom=$env{'request.role.domain'};
2060: my %lt=&Apache::lonlocal::texthash(
1.377 raeburn 2061: 'cs' => "Authoring Space",
1.218 raeburn 2062: 'act' => "Activate",
2063: 'rol' => "Role",
2064: 'ext' => "Extent",
2065: 'sta' => "Start",
2066: 'end' => "End",
2067: 'cau' => "Co-Author",
2068: 'caa' => "Assistant Co-Author",
2069: 'ssd' => "Set Start Date",
2070: 'sed' => "Set End Date"
2071: );
2072: $r->print('<h4>'.$lt{'cs'}.'</h4>'."\n".
2073: &Apache::loncommon::start_data_table()."\n".
2074: &Apache::loncommon::start_data_table_header_row()."\n".
2075: '<th>'.$lt{'act'}.'</th><th>'.$lt{'rol'}.'</th>'.
2076: '<th>'.$lt{'ext'}.'</th><th>'.$lt{'sta'}.'</th>'.
2077: '<th>'.$lt{'end'}.'</th>'."\n".
2078: &Apache::loncommon::end_data_table_header_row()."\n".
2079: &Apache::loncommon::start_data_table_row().'
2080: <td>
1.291 bisitz 2081: <input type="checkbox" name="act_'.$cudom.'_'.$cuname.'_ca" />
1.218 raeburn 2082: </td>
2083: <td>'.$lt{'cau'}.'</td>
2084: <td>'.$cudom.'_'.$cuname.'</td>
2085: <td><input type="hidden" name="start_'.$cudom.'_'.$cuname.'_ca" value="" />
2086: <a href=
2087: "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>
2088: <td><input type="hidden" name="end_'.$cudom.'_'.$cuname.'_ca" value="" />
2089: <a href=
2090: "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".
2091: &Apache::loncommon::end_data_table_row()."\n".
2092: &Apache::loncommon::start_data_table_row()."\n".
1.291 bisitz 2093: '<td><input type="checkbox" name="act_'.$cudom.'_'.$cuname.'_aa" /></td>
1.218 raeburn 2094: <td>'.$lt{'caa'}.'</td>
2095: <td>'.$cudom.'_'.$cuname.'</td>
2096: <td><input type="hidden" name="start_'.$cudom.'_'.$cuname.'_aa" value="" />
2097: <a href=
2098: "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>
2099: <td><input type="hidden" name="end_'.$cudom.'_'.$cuname.'_aa" value="" />
2100: <a href=
2101: "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".
2102: &Apache::loncommon::end_data_table_row()."\n".
2103: &Apache::loncommon::end_data_table());
2104: } elsif ($env{'request.role'} =~ /^au\./) {
2105: if (!(&Apache::lonuserutils::authorpriv($env{'user.name'},
2106: $env{'request.role.domain'}))) {
2107: $r->print('<span class="LC_error">'.
2108: &mt('You do not have privileges to assign co-author roles.').
2109: '</span>');
2110: } elsif (($env{'user.name'} eq $ccuname) &&
2111: ($env{'user.domain'} eq $ccdomain)) {
1.377 raeburn 2112: $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 2113: }
2114: }
2115: return $addrolesdisplay;;
2116: }
2117:
2118: sub new_domain_roles {
1.357 raeburn 2119: my ($r,$ccdomain) = @_;
1.218 raeburn 2120: my $addrolesdisplay = 0;
2121: #
2122: # Domain level
2123: #
2124: my $num_domain_level = 0;
2125: my $domaintext =
2126: '<h4>'.&mt('Domain Level').'</h4>'.
2127: &Apache::loncommon::start_data_table().
2128: &Apache::loncommon::start_data_table_header_row().
2129: '<th>'.&mt('Activate').'</th><th>'.&mt('Role').'</th><th>'.
2130: &mt('Extent').'</th>'.
2131: '<th>'.&mt('Start').'</th><th>'.&mt('End').'</th>'.
2132: &Apache::loncommon::end_data_table_header_row();
1.312 raeburn 2133: my @allroles = &Apache::lonuserutils::roles_by_context('domain');
1.218 raeburn 2134: foreach my $thisdomain (sort(&Apache::lonnet::all_domains())) {
1.312 raeburn 2135: foreach my $role (@allroles) {
2136: next if ($role eq 'ad');
1.357 raeburn 2137: next if (($role eq 'au') && ($ccdomain ne $thisdomain));
1.218 raeburn 2138: if (&Apache::lonnet::allowed('c'.$role,$thisdomain)) {
2139: my $plrole=&Apache::lonnet::plaintext($role);
2140: my %lt=&Apache::lonlocal::texthash(
2141: 'ssd' => "Set Start Date",
2142: 'sed' => "Set End Date"
2143: );
2144: $num_domain_level ++;
2145: $domaintext .=
2146: &Apache::loncommon::start_data_table_row().
1.291 bisitz 2147: '<td><input type="checkbox" name="act_'.$thisdomain.'_'.$role.'" /></td>
1.218 raeburn 2148: <td>'.$plrole.'</td>
2149: <td>'.$thisdomain.'</td>
2150: <td><input type="hidden" name="start_'.$thisdomain.'_'.$role.'" value="" />
2151: <a href=
2152: "javascript:pjump('."'date_start','Start Date $plrole',document.cu.start_$thisdomain\_$role.value,'start_$thisdomain\_$role','cu.pres','dateset'".')">'.$lt{'ssd'}.'</a></td>
2153: <td><input type="hidden" name="end_'.$thisdomain.'_'.$role.'" value="" />
2154: <a href=
2155: "javascript:pjump('."'date_end','End Date $plrole',document.cu.end_$thisdomain\_$role.value,'end_$thisdomain\_$role','cu.pres','dateset'".')">'.$lt{'sed'}.'</a></td>'.
2156: &Apache::loncommon::end_data_table_row();
2157: }
2158: }
2159: }
2160: $domaintext.= &Apache::loncommon::end_data_table();
2161: if ($num_domain_level > 0) {
2162: $r->print($domaintext);
2163: $addrolesdisplay = 1;
2164: }
2165: return $addrolesdisplay;
2166: }
2167:
1.188 raeburn 2168: sub user_authentication {
1.406.2.17 raeburn 2169: my ($ccuname,$ccdomain,$formname,$crstype,$permission) = @_;
1.188 raeburn 2170: my $currentauth=&Apache::lonnet::queryauthenticate($ccuname,$ccdomain);
1.227 raeburn 2171: my $outcome;
1.406.2.6 raeburn 2172: my %lt=&Apache::lonlocal::texthash(
2173: 'err' => "ERROR",
2174: 'uuas' => "This user has an unrecognized authentication scheme",
2175: 'adcs' => "Please alert a domain coordinator of this situation",
2176: 'sldb' => "Please specify login data below",
2177: 'ld' => "Login Data"
2178: );
1.188 raeburn 2179: # Check for a bad authentication type
2180: if ($currentauth !~ /^(krb4|krb5|unix|internal|localauth):/) {
2181: # bad authentication scheme
2182: if (&Apache::lonnet::allowed('mau',$ccdomain)) {
1.227 raeburn 2183: &initialize_authen_forms($ccdomain,$formname);
2184:
1.190 raeburn 2185: my $choices = &Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc);
1.188 raeburn 2186: $outcome = <<ENDBADAUTH;
2187: <script type="text/javascript" language="Javascript">
1.301 bisitz 2188: // <![CDATA[
1.188 raeburn 2189: $loginscript
1.301 bisitz 2190: // ]]>
1.188 raeburn 2191: </script>
2192: <span class="LC_error">$lt{'err'}:
2193: $lt{'uuas'} ($currentauth). $lt{'sldb'}.</span>
2194: <h3>$lt{'ld'}</h3>
2195: $choices
2196: ENDBADAUTH
2197: } else {
2198: # This user is not allowed to modify the user's
2199: # authentication scheme, so just notify them of the problem
2200: $outcome = <<ENDBADAUTH;
2201: <span class="LC_error"> $lt{'err'}:
2202: $lt{'uuas'} ($currentauth). $lt{'adcs'}.
2203: </span>
2204: ENDBADAUTH
2205: }
2206: } else { # Authentication type is valid
1.227 raeburn 2207: &initialize_authen_forms($ccdomain,$formname,$currentauth,'modifyuser');
1.205 raeburn 2208: my ($authformcurrent,$can_modify,@authform_others) =
1.188 raeburn 2209: &modify_login_block($ccdomain,$currentauth);
2210: if (&Apache::lonnet::allowed('mau',$ccdomain)) {
2211: # Current user has login modification privileges
2212: $outcome =
2213: '<script type="text/javascript" language="Javascript">'."\n".
1.301 bisitz 2214: '// <![CDATA['."\n".
1.188 raeburn 2215: $loginscript."\n".
1.301 bisitz 2216: '// ]]>'."\n".
1.188 raeburn 2217: '</script>'."\n".
2218: '<h3>'.$lt{'ld'}.'</h3>'.
2219: &Apache::loncommon::start_data_table().
1.205 raeburn 2220: &Apache::loncommon::start_data_table_row().
1.188 raeburn 2221: '<td>'.$authformnop;
1.406.2.6 raeburn 2222: if (($can_modify) && (&Apache::lonnet::allowed('mau',$ccdomain))) {
1.188 raeburn 2223: $outcome .= '</td>'."\n".
2224: &Apache::loncommon::end_data_table_row().
2225: &Apache::loncommon::start_data_table_row().
2226: '<td>'.$authformcurrent.'</td>'.
2227: &Apache::loncommon::end_data_table_row()."\n";
2228: } else {
1.200 raeburn 2229: $outcome .= ' ('.$authformcurrent.')</td>'.
2230: &Apache::loncommon::end_data_table_row()."\n";
1.188 raeburn 2231: }
1.406.2.6 raeburn 2232: if (&Apache::lonnet::allowed('mau',$ccdomain)) {
2233: foreach my $item (@authform_others) {
2234: $outcome .= &Apache::loncommon::start_data_table_row().
2235: '<td>'.$item.'</td>'.
2236: &Apache::loncommon::end_data_table_row()."\n";
2237: }
1.188 raeburn 2238: }
1.205 raeburn 2239: $outcome .= &Apache::loncommon::end_data_table();
1.188 raeburn 2240: } else {
1.406.2.17 raeburn 2241: if (($currentauth =~ /^internal:/) &&
2242: (&Apache::lonuserutils::can_change_internalpass($ccuname,$ccdomain,$crstype,$permission))) {
2243: $outcome = <<"ENDJS";
2244: <script type="text/javascript">
2245: // <![CDATA[
2246: function togglePwd(form) {
2247: if (form.newintpwd.length) {
2248: if (document.getElementById('LC_ownersetpwd')) {
2249: for (var i=0; i<form.newintpwd.length; i++) {
2250: if (form.newintpwd[i].checked) {
2251: if (form.newintpwd[i].value == 1) {
2252: document.getElementById('LC_ownersetpwd').style.display = 'inline-block';
2253: } else {
2254: document.getElementById('LC_ownersetpwd').style.display = 'none';
2255: }
2256: }
2257: }
2258: }
2259: }
2260: }
2261: // ]]>
2262: </script>
2263: ENDJS
2264:
2265: $outcome .= '<h3>'.$lt{'ld'}.'</h3>'.
2266: &Apache::loncommon::start_data_table().
2267: &Apache::loncommon::start_data_table_row().
2268: '<td>'.&mt('Internally authenticated').'<br />'.&mt("Change user's password?").
2269: '<label><input type="radio" name="newintpwd" value="0" checked="checked" onclick="togglePwd(this.form);" />'.
2270: &mt('No').'</label>'.(' 'x2).
2271: '<label><input type="radio" name="newintpwd" value="1" onclick="togglePwd(this.form);" />'.&mt('Yes').'</label>'.
2272: '<div id="LC_ownersetpwd" style="display:none">'.
2273: ' '.&mt('Password').' <input type="password" size="15" name="intarg" value="" />'.
2274: '<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></div></td>'.
2275: &Apache::loncommon::end_data_table_row().
2276: &Apache::loncommon::end_data_table();
2277: }
1.406.2.6 raeburn 2278: if (&Apache::lonnet::allowed('udp',$ccdomain)) {
2279: # Current user has rights to view domain preferences for user's domain
2280: my $result;
2281: if ($currentauth =~ /^krb(4|5):([^:]*)$/) {
2282: my ($krbver,$krbrealm) = ($1,$2);
2283: if ($krbrealm eq '') {
2284: $result = &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
2285: } else {
2286: $result = &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
1.406.2.9 raeburn 2287: $krbrealm,$krbver);
1.406.2.6 raeburn 2288: }
2289: } elsif ($currentauth =~ /^internal:/) {
2290: $result = &mt('Currently internally authenticated.');
2291: } elsif ($currentauth =~ /^localauth:/) {
2292: $result = &mt('Currently using local (institutional) authentication.');
2293: } elsif ($currentauth =~ /^unix:/) {
2294: $result = &mt('Currently Filesystem Authenticated.');
2295: }
2296: $outcome = '<h3>'.$lt{'ld'}.'</h3>'.
2297: &Apache::loncommon::start_data_table().
2298: &Apache::loncommon::start_data_table_row().
2299: '<td>'.$result.'</td>'.
2300: &Apache::loncommon::end_data_table_row()."\n".
2301: &Apache::loncommon::end_data_table();
2302: } elsif (&Apache::lonnet::allowed('mau',$env{'request.role.domain'})) {
1.188 raeburn 2303: my %lt=&Apache::lonlocal::texthash(
2304: 'ccld' => "Change Current Login Data",
2305: 'yodo' => "You do not have privileges to modify the authentication configuration for this user.",
2306: 'ifch' => "If a change is required, contact a domain coordinator for the domain",
2307: );
2308: $outcome .= <<ENDNOPRIV;
2309: <h3>$lt{'ccld'}</h3>
2310: $lt{'yodo'} $lt{'ifch'}: $ccdomain
1.235 raeburn 2311: <input type="hidden" name="login" value="nochange" />
1.188 raeburn 2312: ENDNOPRIV
2313: }
2314: }
2315: } ## End of "check for bad authentication type" logic
2316: return $outcome;
2317: }
2318:
1.187 raeburn 2319: sub modify_login_block {
2320: my ($dom,$currentauth) = @_;
2321: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
2322: my ($authnum,%can_assign) =
2323: &Apache::loncommon::get_assignable_auth($dom);
1.205 raeburn 2324: my ($authformcurrent,@authform_others,$show_override_msg);
1.187 raeburn 2325: if ($currentauth=~/^krb(4|5):/) {
2326: $authformcurrent=$authformkrb;
2327: if ($can_assign{'int'}) {
1.205 raeburn 2328: push(@authform_others,$authformint);
1.187 raeburn 2329: }
2330: if ($can_assign{'loc'}) {
1.205 raeburn 2331: push(@authform_others,$authformloc);
1.187 raeburn 2332: }
2333: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
2334: $show_override_msg = 1;
2335: }
2336: } elsif ($currentauth=~/^internal:/) {
2337: $authformcurrent=$authformint;
2338: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205 raeburn 2339: push(@authform_others,$authformkrb);
1.187 raeburn 2340: }
2341: if ($can_assign{'loc'}) {
1.205 raeburn 2342: push(@authform_others,$authformloc);
1.187 raeburn 2343: }
2344: if ($can_assign{'int'}) {
2345: $show_override_msg = 1;
2346: }
2347: } elsif ($currentauth=~/^unix:/) {
2348: $authformcurrent=$authformfsys;
2349: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205 raeburn 2350: push(@authform_others,$authformkrb);
1.187 raeburn 2351: }
2352: if ($can_assign{'int'}) {
1.205 raeburn 2353: push(@authform_others,$authformint);
1.187 raeburn 2354: }
2355: if ($can_assign{'loc'}) {
1.205 raeburn 2356: push(@authform_others,$authformloc);
1.187 raeburn 2357: }
2358: if ($can_assign{'fsys'}) {
2359: $show_override_msg = 1;
2360: }
2361: } elsif ($currentauth=~/^localauth:/) {
2362: $authformcurrent=$authformloc;
2363: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205 raeburn 2364: push(@authform_others,$authformkrb);
1.187 raeburn 2365: }
2366: if ($can_assign{'int'}) {
1.205 raeburn 2367: push(@authform_others,$authformint);
1.187 raeburn 2368: }
2369: if ($can_assign{'loc'}) {
2370: $show_override_msg = 1;
2371: }
2372: }
2373: if ($show_override_msg) {
1.205 raeburn 2374: $authformcurrent = '<table><tr><td colspan="3">'.$authformcurrent.
2375: '</td></tr>'."\n".
2376: '<tr><td> </td>'.
2377: '<td><b>'.&mt('Currently in use').'</b></td>'.
2378: '<td align="right"><span class="LC_cusr_emph">'.
1.187 raeburn 2379: &mt('will override current values').
1.205 raeburn 2380: '</span></td></tr></table>';
1.187 raeburn 2381: }
1.205 raeburn 2382: return ($authformcurrent,$show_override_msg,@authform_others);
1.187 raeburn 2383: }
2384:
1.188 raeburn 2385: sub personal_data_display {
1.406.2.20 raeburn 2386: my ($ccuname,$ccdomain,$newuser,$context,$inst_results,$rolesarray,$now,
2387: $captchaform,$emailusername,$usertype,$usernameset,$condition,$excluded,$showsubmit) = @_;
1.388 bisitz 2388: my ($output,%userenv,%canmodify,%canmodify_status);
1.219 raeburn 2389: my @userinfo = ('firstname','middlename','lastname','generation',
2390: 'permanentemail','id');
1.252 raeburn 2391: my $rowcount = 0;
2392: my $editable = 0;
1.391 raeburn 2393: my %textboxsize = (
2394: firstname => '15',
2395: middlename => '15',
2396: lastname => '15',
2397: generation => '5',
2398: permanentemail => '25',
2399: id => '15',
2400: );
2401:
2402: my %lt=&Apache::lonlocal::texthash(
2403: 'pd' => "Personal Data",
2404: 'firstname' => "First Name",
2405: 'middlename' => "Middle Name",
2406: 'lastname' => "Last Name",
2407: 'generation' => "Generation",
2408: 'permanentemail' => "Permanent e-mail address",
2409: 'id' => "Student/Employee ID",
2410: 'lg' => "Login Data",
2411: 'inststatus' => "Affiliation",
2412: 'email' => 'E-mail address',
2413: 'valid' => 'Validation',
1.406.2.16 raeburn 2414: 'username' => 'Username',
1.391 raeburn 2415: );
2416:
2417: %canmodify_status =
1.286 raeburn 2418: &Apache::lonuserutils::can_modify_userinfo($context,$ccdomain,
2419: ['inststatus'],$rolesarray);
1.253 raeburn 2420: if (!$newuser) {
1.188 raeburn 2421: # Get the users information
2422: %userenv = &Apache::lonnet::get('environment',
2423: ['firstname','middlename','lastname','generation',
1.286 raeburn 2424: 'permanentemail','id','inststatus'],$ccdomain,$ccuname);
1.219 raeburn 2425: %canmodify =
2426: &Apache::lonuserutils::can_modify_userinfo($context,$ccdomain,
1.252 raeburn 2427: \@userinfo,$rolesarray);
1.257 raeburn 2428: } elsif ($context eq 'selfcreate') {
1.391 raeburn 2429: if ($newuser eq 'email') {
1.396 raeburn 2430: if (ref($emailusername) eq 'HASH') {
2431: if (ref($emailusername->{$usertype}) eq 'HASH') {
2432: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
1.406.2.16 raeburn 2433: @userinfo = ();
1.396 raeburn 2434: if ((ref($infofields) eq 'ARRAY') && (ref($infotitles) eq 'HASH')) {
2435: foreach my $field (@{$infofields}) {
2436: if ($emailusername->{$usertype}->{$field}) {
2437: push(@userinfo,$field);
2438: $canmodify{$field} = 1;
2439: unless ($textboxsize{$field}) {
2440: $textboxsize{$field} = 25;
2441: }
2442: unless ($lt{$field}) {
2443: $lt{$field} = $infotitles->{$field};
2444: }
2445: if ($emailusername->{$usertype}->{$field} eq 'required') {
2446: $lt{$field} .= '<b>*</b>';
2447: }
1.391 raeburn 2448: }
2449: }
2450: }
2451: }
2452: }
2453: } else {
2454: %canmodify = &selfcreate_canmodify($context,$ccdomain,\@userinfo,
2455: $inst_results,$rolesarray);
2456: }
1.188 raeburn 2457: }
1.391 raeburn 2458:
1.188 raeburn 2459: my $genhelp=&Apache::loncommon::help_open_topic('Generation');
2460: $output = '<h3>'.$lt{'pd'}.'</h3>'.
2461: &Apache::lonhtmlcommon::start_pick_box();
1.391 raeburn 2462: if (($context eq 'selfcreate') && ($newuser eq 'email')) {
1.406.2.16 raeburn 2463: my $size = 25;
2464: if ($condition) {
2465: if ($condition =~ /^\@[^\@]+$/) {
2466: $size = 10;
2467: } else {
2468: undef($condition);
2469: }
2470: }
2471: if ($excluded) {
2472: unless ($excluded =~ /^\@[^\@]+$/) {
2473: undef($condition);
2474: }
2475: }
1.396 raeburn 2476: $output .= &Apache::lonhtmlcommon::row_title($lt{'email'}.'<b>*</b>',undef,
1.391 raeburn 2477: 'LC_oddrow_value')."\n".
1.406.2.16 raeburn 2478: '<input type="text" name="uname" size="'.$size.'" value="" autocomplete="off" />';
2479: if ($condition) {
2480: $output .= $condition;
2481: } elsif ($excluded) {
2482: $output .= '<br /><span style="font-size: smaller">'.&mt('You must use an e-mail address that does not end with [_1]',
2483: $excluded).'</span>';
2484: }
2485: if ($usernameset eq 'first') {
2486: $output .= '<br /><span style="font-size: smaller">';
2487: if ($condition) {
2488: $output .= &mt('Your username in LON-CAPA will be the part of your e-mail address before [_1]',
2489: $condition);
2490: } else {
2491: $output .= &mt('Your username in LON-CAPA will be the part of your e-mail address before the @');
2492: }
2493: $output .= '</span>';
2494: }
1.391 raeburn 2495: $rowcount ++;
2496: $output .= &Apache::lonhtmlcommon::row_closure(1);
1.406.2.1 raeburn 2497: my $upassone = '<input type="password" name="upass'.$now.'" size="20" autocomplete="off" />';
2498: my $upasstwo = '<input type="password" name="upasscheck'.$now.'" size="20" autocomplete="off" />';
1.396 raeburn 2499: $output .= &Apache::lonhtmlcommon::row_title(&mt('Password').'<b>*</b>',
1.391 raeburn 2500: 'LC_pick_box_title',
2501: 'LC_oddrow_value')."\n".
2502: $upassone."\n".
2503: &Apache::lonhtmlcommon::row_closure(1)."\n".
1.396 raeburn 2504: &Apache::lonhtmlcommon::row_title(&mt('Confirm password').'<b>*</b>',
1.391 raeburn 2505: 'LC_pick_box_title',
2506: 'LC_oddrow_value')."\n".
2507: $upasstwo.
2508: &Apache::lonhtmlcommon::row_closure()."\n";
1.406.2.16 raeburn 2509: if ($usernameset eq 'free') {
2510: my $onclick = "toggleUsernameDisp(this,'selfcreateusername');";
2511: $output .= &Apache::lonhtmlcommon::row_title($lt{'username'},undef,'LC_oddrow_value')."\n".
1.406.2.20 raeburn 2512: '<span class="LC_nobreak">'.&mt('Use e-mail address: ').
2513: '<label><input type="radio" name="emailused" value="1" checked="checked" onclick="'.$onclick.'" />'.
2514: &mt('Yes').'</label>'.(' 'x2).
2515: '<label><input type="radio" name="emailused" value="0" onclick="'.$onclick.'" />'.
2516: &mt('No').'</label></span>'."\n".
1.406.2.16 raeburn 2517: '<div id="selfcreateusername" style="display: none; font-size: smaller">'.
2518: '<br /><span class="LC_nobreak">'.&mt('Preferred username').
2519: ' <input type="text" name="username" value="" size="20" autocomplete="off"/>'.
2520: '</span></div>'."\n".&Apache::lonhtmlcommon::row_closure(1);
2521: $rowcount ++;
2522: }
1.391 raeburn 2523: }
1.188 raeburn 2524: foreach my $item (@userinfo) {
2525: my $rowtitle = $lt{$item};
1.252 raeburn 2526: my $hiderow = 0;
1.188 raeburn 2527: if ($item eq 'generation') {
2528: $rowtitle = $genhelp.$rowtitle;
2529: }
1.252 raeburn 2530: my $row = &Apache::lonhtmlcommon::row_title($rowtitle,undef,'LC_oddrow_value')."\n";
1.188 raeburn 2531: if ($newuser) {
1.210 raeburn 2532: if (ref($inst_results) eq 'HASH') {
2533: if ($inst_results->{$item} ne '') {
1.252 raeburn 2534: $row .= '<input type="hidden" name="c'.$item.'" value="'.$inst_results->{$item}.'" />'.$inst_results->{$item};
1.210 raeburn 2535: } else {
1.252 raeburn 2536: if ($context eq 'selfcreate') {
1.391 raeburn 2537: if ($canmodify{$item}) {
1.394 raeburn 2538: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" autocomplete="off" />';
1.252 raeburn 2539: $editable ++;
2540: } else {
2541: $hiderow = 1;
2542: }
1.253 raeburn 2543: } else {
2544: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
1.252 raeburn 2545: }
1.210 raeburn 2546: }
1.188 raeburn 2547: } else {
1.252 raeburn 2548: if ($context eq 'selfcreate') {
1.401 raeburn 2549: if ($canmodify{$item}) {
2550: if ($newuser eq 'email') {
2551: $row .= '<input type="text" name="'.$item.'" size="'.$textboxsize{$item}.'" value="" autocomplete="off" />';
1.287 raeburn 2552: } else {
1.401 raeburn 2553: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" autocomplete="off" />';
1.287 raeburn 2554: }
1.401 raeburn 2555: $editable ++;
2556: } else {
2557: $hiderow = 1;
1.252 raeburn 2558: }
1.253 raeburn 2559: } else {
2560: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
1.252 raeburn 2561: }
1.188 raeburn 2562: }
2563: } else {
1.219 raeburn 2564: if ($canmodify{$item}) {
1.252 raeburn 2565: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="'.$userenv{$item}.'" />';
1.393 raeburn 2566: if (($item eq 'id') && (!$newuser)) {
2567: $row .= '<br />'.&Apache::lonuserutils::forceid_change($context);
2568: }
1.188 raeburn 2569: } else {
1.252 raeburn 2570: $row .= $userenv{$item};
1.188 raeburn 2571: }
2572: }
1.252 raeburn 2573: $row .= &Apache::lonhtmlcommon::row_closure(1);
2574: if (!$hiderow) {
2575: $output .= $row;
2576: $rowcount ++;
2577: }
1.188 raeburn 2578: }
1.286 raeburn 2579: if (($canmodify_status{'inststatus'}) || ($context ne 'selfcreate')) {
2580: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($ccdomain);
2581: if (ref($types) eq 'ARRAY') {
2582: if (@{$types} > 0) {
2583: my ($hiderow,$shown);
2584: if ($canmodify_status{'inststatus'}) {
2585: $shown = &pick_inst_statuses($userenv{'inststatus'},$usertypes,$types);
2586: } else {
2587: if ($userenv{'inststatus'} eq '') {
2588: $hiderow = 1;
1.334 raeburn 2589: } else {
2590: my @showitems;
2591: foreach my $item ( map { &unescape($_); } split(':',$userenv{'inststatus'})) {
2592: if (exists($usertypes->{$item})) {
2593: push(@showitems,$usertypes->{$item});
2594: } else {
2595: push(@showitems,$item);
2596: }
2597: }
2598: if (@showitems) {
2599: $shown = join(', ',@showitems);
2600: } else {
2601: $hiderow = 1;
2602: }
1.286 raeburn 2603: }
2604: }
2605: if (!$hiderow) {
1.389 bisitz 2606: my $row = &Apache::lonhtmlcommon::row_title(&mt('Affiliations'),undef,'LC_oddrow_value')."\n".
1.286 raeburn 2607: $shown.&Apache::lonhtmlcommon::row_closure(1);
2608: if ($context eq 'selfcreate') {
2609: $rowcount ++;
2610: }
2611: $output .= $row;
2612: }
2613: }
2614: }
2615: }
1.391 raeburn 2616: if (($context eq 'selfcreate') && ($newuser eq 'email')) {
2617: if ($captchaform) {
1.406.2.2 raeburn 2618: $output .= &Apache::lonhtmlcommon::row_title($lt{'valid'}.'*',
1.391 raeburn 2619: 'LC_pick_box_title')."\n".
2620: $captchaform."\n".'<br /><br />'.
2621: &Apache::lonhtmlcommon::row_closure(1);
2622: $rowcount ++;
2623: }
1.406.2.20 raeburn 2624: if ($showsubmit) {
2625: my $submit_text = &mt('Create account');
2626: $output .= &Apache::lonhtmlcommon::row_title()."\n".
2627: '<br /><input type="submit" name="createaccount" value="'.
2628: $submit_text.'" />';
2629: if ($usertype ne '') {
2630: $output .= '<input type="hidden" name="type" value="'.$usertype.'" />'.
2631: &Apache::lonhtmlcommon::row_closure(1);
2632: }
2633: }
1.391 raeburn 2634: }
1.188 raeburn 2635: $output .= &Apache::lonhtmlcommon::end_pick_box();
1.206 raeburn 2636: if (wantarray) {
1.252 raeburn 2637: if ($context eq 'selfcreate') {
2638: return($output,$rowcount,$editable);
2639: } else {
1.388 bisitz 2640: return $output;
1.252 raeburn 2641: }
1.206 raeburn 2642: } else {
2643: return $output;
2644: }
1.188 raeburn 2645: }
2646:
1.286 raeburn 2647: sub pick_inst_statuses {
2648: my ($curr,$usertypes,$types) = @_;
2649: my ($output,$rem,@currtypes);
2650: if ($curr ne '') {
2651: @currtypes = map { &unescape($_); } split(/:/,$curr);
2652: }
2653: my $numinrow = 2;
2654: if (ref($types) eq 'ARRAY') {
2655: $output = '<table>';
2656: my $lastcolspan;
2657: for (my $i=0; $i<@{$types}; $i++) {
2658: if (defined($usertypes->{$types->[$i]})) {
2659: my $rem = $i%($numinrow);
2660: if ($rem == 0) {
2661: if ($i<@{$types}-1) {
2662: if ($i > 0) {
2663: $output .= '</tr>';
2664: }
2665: $output .= '<tr>';
2666: }
2667: } elsif ($i==@{$types}-1) {
2668: my $colsleft = $numinrow - $rem;
2669: if ($colsleft > 1) {
2670: $lastcolspan = ' colspan="'.$colsleft.'"';
2671: }
2672: }
2673: my $check = ' ';
2674: if (grep(/^\Q$types->[$i]\E$/,@currtypes)) {
2675: $check = ' checked="checked" ';
2676: }
2677: $output .= '<td class="LC_left_item"'.$lastcolspan.'>'.
2678: '<span class="LC_nobreak"><label>'.
2679: '<input type="checkbox" name="inststatus" '.
2680: 'value="'.$types->[$i].'"'.$check.'/>'.
2681: $usertypes->{$types->[$i]}.'</label></span></td>';
2682: }
2683: }
2684: $output .= '</tr></table>';
2685: }
2686: return $output;
2687: }
2688:
1.257 raeburn 2689: sub selfcreate_canmodify {
2690: my ($context,$dom,$userinfo,$inst_results,$rolesarray) = @_;
2691: if (ref($inst_results) eq 'HASH') {
2692: my @inststatuses = &get_inststatuses($inst_results);
2693: if (@inststatuses == 0) {
2694: @inststatuses = ('default');
2695: }
2696: $rolesarray = \@inststatuses;
2697: }
2698: my %canmodify =
2699: &Apache::lonuserutils::can_modify_userinfo($context,$dom,$userinfo,
2700: $rolesarray);
2701: return %canmodify;
2702: }
2703:
1.252 raeburn 2704: sub get_inststatuses {
2705: my ($insthashref) = @_;
2706: my @inststatuses = ();
2707: if (ref($insthashref) eq 'HASH') {
2708: if (ref($insthashref->{'inststatus'}) eq 'ARRAY') {
2709: @inststatuses = @{$insthashref->{'inststatus'}};
2710: }
2711: }
2712: return @inststatuses;
2713: }
2714:
1.4 www 2715: # ================================================================= Phase Three
1.42 matthew 2716: sub update_user_data {
1.406.2.17 raeburn 2717: my ($r,$context,$crstype,$brcrum,$showcredits,$permission) = @_;
1.101 albertel 2718: my $uhome=&Apache::lonnet::homeserver($env{'form.ccuname'},
2719: $env{'form.ccdomain'});
1.27 matthew 2720: # Error messages
1.188 raeburn 2721: my $error = '<span class="LC_error">'.&mt('Error').': ';
1.193 raeburn 2722: my $end = '</span><br /><br />';
2723: my $rtnlink = '<a href="javascript:backPage(document.userupdate,'.
1.188 raeburn 2724: "'$env{'form.prevphase'}','modify')".'" />'.
1.219 raeburn 2725: &mt('Return to previous page').'</a>'.
2726: &Apache::loncommon::end_page();
2727: my $now = time;
1.40 www 2728: my $title;
1.101 albertel 2729: if (exists($env{'form.makeuser'})) {
1.40 www 2730: $title='Set Privileges for New User';
2731: } else {
2732: $title='Modify User Privileges';
2733: }
1.213 raeburn 2734: my $newuser = 0;
1.160 raeburn 2735: my ($jsback,$elements) = &crumb_utilities();
2736: my $jscript = '<script type="text/javascript">'."\n".
1.301 bisitz 2737: '// <![CDATA['."\n".
2738: $jsback."\n".
2739: '// ]]>'."\n".
2740: '</script>'."\n";
1.406.2.7 raeburn 2741: my %breadcrumb_text = &singleuser_breadcrumb($crstype,$context,$env{'form.ccdomain'});
1.351 raeburn 2742: push (@{$brcrum},
2743: {href => "javascript:backPage(document.userupdate)",
2744: text => $breadcrumb_text{'search'},
2745: faq => 282,
2746: bug => 'Instructor Interface',}
2747: );
2748: if ($env{'form.prevphase'} eq 'userpicked') {
2749: push(@{$brcrum},
2750: {href => "javascript:backPage(document.userupdate,'get_user_info','select')",
2751: text => $breadcrumb_text{'userpicked'},
2752: faq => 282,
2753: bug => 'Instructor Interface',});
1.233 raeburn 2754: }
1.224 raeburn 2755: my $helpitem = 'Course_Change_Privileges';
2756: if ($env{'form.action'} eq 'singlestudent') {
2757: $helpitem = 'Course_Add_Student';
1.406.2.14 raeburn 2758: } elsif ($context eq 'author') {
2759: $helpitem = 'Author_Change_Privileges';
2760: } elsif ($context eq 'domain') {
2761: $helpitem = 'Domain_Change_Privileges';
1.224 raeburn 2762: }
1.351 raeburn 2763: push(@{$brcrum},
2764: {href => "javascript:backPage(document.userupdate,'$env{'form.prevphase'}','modify')",
2765: text => $breadcrumb_text{'modify'},
2766: faq => 282,
2767: bug => 'Instructor Interface',},
2768: {href => "/adm/createuser",
2769: text => "Result",
2770: faq => 282,
2771: bug => 'Instructor Interface',
2772: help => $helpitem});
2773: my $args = {bread_crumbs => $brcrum,
2774: bread_crumbs_component => 'User Management'};
2775: if ($env{'form.popup'}) {
2776: $args->{'no_nav_bar'} = 1;
2777: }
2778: $r->print(&Apache::loncommon::start_page($title,$jscript,$args));
1.188 raeburn 2779: $r->print(&update_result_form($uhome));
1.27 matthew 2780: # Check Inputs
1.101 albertel 2781: if (! $env{'form.ccuname'} ) {
1.193 raeburn 2782: $r->print($error.&mt('No login name specified').'.'.$end.$rtnlink);
1.27 matthew 2783: return;
2784: }
1.138 albertel 2785: if ( $env{'form.ccuname'} ne
2786: &LONCAPA::clean_username($env{'form.ccuname'}) ) {
1.281 bisitz 2787: $r->print($error.&mt('Invalid login name.').' '.
2788: &mt('Only letters, numbers, periods, dashes, @, and underscores are valid.').
1.193 raeburn 2789: $end.$rtnlink);
1.27 matthew 2790: return;
2791: }
1.101 albertel 2792: if (! $env{'form.ccdomain'} ) {
1.193 raeburn 2793: $r->print($error.&mt('No domain specified').'.'.$end.$rtnlink);
1.27 matthew 2794: return;
2795: }
1.138 albertel 2796: if ( $env{'form.ccdomain'} ne
2797: &LONCAPA::clean_domain($env{'form.ccdomain'}) ) {
1.281 bisitz 2798: $r->print($error.&mt('Invalid domain name.').' '.
2799: &mt('Only letters, numbers, periods, dashes, and underscores are valid.').
1.193 raeburn 2800: $end.$rtnlink);
1.27 matthew 2801: return;
2802: }
1.219 raeburn 2803: if ($uhome eq 'no_host') {
2804: $newuser = 1;
2805: }
1.101 albertel 2806: if (! exists($env{'form.makeuser'})) {
1.29 matthew 2807: # Modifying an existing user, so check the validity of the name
2808: if ($uhome eq 'no_host') {
1.389 bisitz 2809: $r->print(
2810: $error
2811: .'<p class="LC_error">'
2812: .&mt('Unable to determine home server for [_1] in domain [_2].',
2813: '"'.$env{'form.ccuname'}.'"','"'.$env{'form.ccdomain'}.'"')
2814: .'</p>');
1.29 matthew 2815: return;
2816: }
2817: }
1.27 matthew 2818: # Determine authentication method and password for the user being modified
2819: my $amode='';
2820: my $genpwd='';
1.101 albertel 2821: if ($env{'form.login'} eq 'krb') {
1.41 albertel 2822: $amode='krb';
1.101 albertel 2823: $amode.=$env{'form.krbver'};
2824: $genpwd=$env{'form.krbarg'};
2825: } elsif ($env{'form.login'} eq 'int') {
1.27 matthew 2826: $amode='internal';
1.101 albertel 2827: $genpwd=$env{'form.intarg'};
2828: } elsif ($env{'form.login'} eq 'fsys') {
1.27 matthew 2829: $amode='unix';
1.101 albertel 2830: $genpwd=$env{'form.fsysarg'};
2831: } elsif ($env{'form.login'} eq 'loc') {
1.27 matthew 2832: $amode='localauth';
1.101 albertel 2833: $genpwd=$env{'form.locarg'};
1.27 matthew 2834: $genpwd=" " if (!$genpwd);
1.101 albertel 2835: } elsif (($env{'form.login'} eq 'nochange') ||
2836: ($env{'form.login'} eq '' )) {
1.34 matthew 2837: # There is no need to tell the user we did not change what they
2838: # did not ask us to change.
1.35 matthew 2839: # If they are creating a new user but have not specified login
2840: # information this will be caught below.
1.30 matthew 2841: } else {
1.367 golterma 2842: $r->print($error.&mt('Invalid login mode or password').$end.$rtnlink);
2843: return;
1.27 matthew 2844: }
1.164 albertel 2845:
1.188 raeburn 2846: $r->print('<h3>'.&mt('User [_1] in domain [_2]',
1.367 golterma 2847: $env{'form.ccuname'}.' ('.&Apache::loncommon::plainname($env{'form.ccuname'},
2848: $env{'form.ccdomain'}).')', $env{'form.ccdomain'}).'</h3>');
2849: my %prog_state = &Apache::lonhtmlcommon::Create_PrgWin($r,2);
1.344 bisitz 2850:
1.193 raeburn 2851: my (%alerts,%rulematch,%inst_results,%curr_rules);
1.334 raeburn 2852: my @userinfo = ('firstname','middlename','lastname','generation','permanentemail','id');
1.406.2.20.2. (raeburn 2853:): my @usertools = ('aboutme','blog','webdav','portfolio','timezone');
1.384 raeburn 2854: my @requestcourses = ('official','unofficial','community','textbook');
1.362 raeburn 2855: my @requestauthor = ('requestauthor');
1.286 raeburn 2856: my ($othertitle,$usertypes,$types) =
2857: &Apache::loncommon::sorted_inst_types($env{'form.ccdomain'});
1.334 raeburn 2858: my %canmodify_status =
2859: &Apache::lonuserutils::can_modify_userinfo($context,$env{'form.ccdomain'},
2860: ['inststatus']);
1.101 albertel 2861: if ($env{'form.makeuser'}) {
1.164 albertel 2862: $r->print('<h3>'.&mt('Creating new account.').'</h3>');
1.27 matthew 2863: # Check for the authentication mode and password
2864: if (! $amode || ! $genpwd) {
1.193 raeburn 2865: $r->print($error.&mt('Invalid login mode or password').$end.$rtnlink);
1.27 matthew 2866: return;
1.18 albertel 2867: }
1.29 matthew 2868: # Determine desired host
1.101 albertel 2869: my $desiredhost = $env{'form.hserver'};
1.29 matthew 2870: if (lc($desiredhost) eq 'default') {
2871: $desiredhost = undef;
2872: } else {
1.147 albertel 2873: my %home_servers =
2874: &Apache::lonnet::get_servers($env{'form.ccdomain'},'library');
1.29 matthew 2875: if (! exists($home_servers{$desiredhost})) {
1.193 raeburn 2876: $r->print($error.&mt('Invalid home server specified').$end.$rtnlink);
2877: return;
2878: }
2879: }
2880: # Check ID format
2881: my %checkhash;
2882: my %checks = ('id' => 1);
2883: %{$checkhash{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}}} = (
1.219 raeburn 2884: 'newuser' => $newuser,
1.196 raeburn 2885: 'id' => $env{'form.cid'},
1.193 raeburn 2886: );
1.196 raeburn 2887: if ($env{'form.cid'} ne '') {
2888: &Apache::loncommon::user_rule_check(\%checkhash,\%checks,\%alerts,
2889: \%rulematch,\%inst_results,\%curr_rules);
2890: if (ref($alerts{'id'}) eq 'HASH') {
2891: if (ref($alerts{'id'}{$env{'form.ccdomain'}}) eq 'HASH') {
2892: my $domdesc =
2893: &Apache::lonnet::domain($env{'form.ccdomain'},'description');
2894: if ($alerts{'id'}{$env{'form.ccdomain'}}{$env{'form.cid'}}) {
2895: my $userchkmsg;
2896: if (ref($curr_rules{$env{'form.ccdomain'}}) eq 'HASH') {
2897: $userchkmsg =
2898: &Apache::loncommon::instrule_disallow_msg('id',
2899: $domdesc,1).
2900: &Apache::loncommon::user_rule_formats($env{'form.ccdomain'},
2901: $domdesc,$curr_rules{$env{'form.ccdomain'}}{'id'},'id');
2902: }
2903: $r->print($error.&mt('Invalid ID format').$end.
2904: $userchkmsg.$rtnlink);
2905: return;
2906: }
2907: }
1.29 matthew 2908: }
2909: }
1.367 golterma 2910: &Apache::lonhtmlcommon::Increment_PrgWin($r, \%prog_state);
1.27 matthew 2911: # Call modifyuser
2912: my $result = &Apache::lonnet::modifyuser
1.193 raeburn 2913: ($env{'form.ccdomain'},$env{'form.ccuname'},$env{'form.cid'},
1.188 raeburn 2914: $amode,$genpwd,$env{'form.cfirstname'},
2915: $env{'form.cmiddlename'},$env{'form.clastname'},
2916: $env{'form.cgeneration'},undef,$desiredhost,
2917: $env{'form.cpermanentemail'});
1.77 www 2918: $r->print(&mt('Generating user').': '.$result);
1.219 raeburn 2919: $uhome = &Apache::lonnet::homeserver($env{'form.ccuname'},
1.101 albertel 2920: $env{'form.ccdomain'});
1.334 raeburn 2921: my (%changeHash,%newcustom,%changed,%changedinfo);
1.267 raeburn 2922: if ($uhome ne 'no_host') {
1.334 raeburn 2923: if ($context eq 'domain') {
1.378 raeburn 2924: foreach my $name ('portfolio','author') {
2925: if ($env{'form.custom_'.$name.'quota'} == 1) {
2926: if ($env{'form.'.$name.'quota'} eq '') {
2927: $newcustom{$name.'quota'} = 0;
2928: } else {
2929: $newcustom{$name.'quota'} = $env{'form.'.$name.'quota'};
2930: $newcustom{$name.'quota'} =~ s/[^\d\.]//g;
2931: }
2932: if ("a_admin($newcustom{$name.'quota'},\%changeHash,$name)) {
2933: $changed{$name.'quota'} = 1;
2934: }
1.334 raeburn 2935: }
2936: }
2937: foreach my $item (@usertools) {
2938: if ($env{'form.custom'.$item} == 1) {
2939: $newcustom{$item} = $env{'form.tools_'.$item};
2940: $changed{$item} = &tool_admin($item,$newcustom{$item},
2941: \%changeHash,'tools');
2942: }
1.267 raeburn 2943: }
1.334 raeburn 2944: foreach my $item (@requestcourses) {
1.341 raeburn 2945: if ($env{'form.custom'.$item} == 1) {
2946: $newcustom{$item} = $env{'form.crsreq_'.$item};
2947: if ($env{'form.crsreq_'.$item} eq 'autolimit') {
2948: $newcustom{$item} .= '=';
1.383 raeburn 2949: $env{'form.crsreq_'.$item.'_limit'} =~ s/\D+//g;
2950: if ($env{'form.crsreq_'.$item.'_limit'}) {
1.341 raeburn 2951: $newcustom{$item} .= $env{'form.crsreq_'.$item.'_limit'};
2952: }
1.334 raeburn 2953: }
1.341 raeburn 2954: $changed{$item} = &tool_admin($item,$newcustom{$item},
2955: \%changeHash,'requestcourses');
1.334 raeburn 2956: }
1.275 raeburn 2957: }
1.362 raeburn 2958: if ($env{'form.customrequestauthor'} == 1) {
2959: $newcustom{'requestauthor'} = $env{'form.requestauthor'};
2960: $changed{'requestauthor'} = &tool_admin('requestauthor',
2961: $newcustom{'requestauthor'},
2962: \%changeHash,'requestauthor');
2963: }
1.275 raeburn 2964: }
1.334 raeburn 2965: if ($canmodify_status{'inststatus'}) {
2966: if (exists($env{'form.inststatus'})) {
2967: my @inststatuses = &Apache::loncommon::get_env_multiple('form.inststatus');
2968: if (@inststatuses > 0) {
2969: $changeHash{'inststatus'} = join(',',@inststatuses);
2970: $changed{'inststatus'} = $changeHash{'inststatus'};
1.306 raeburn 2971: }
2972: }
1.232 raeburn 2973: }
1.334 raeburn 2974: if (keys(%changed)) {
2975: foreach my $item (@userinfo) {
2976: $changeHash{$item} = $env{'form.c'.$item};
1.286 raeburn 2977: }
1.267 raeburn 2978: my $chgresult =
2979: &Apache::lonnet::put('environment',\%changeHash,
2980: $env{'form.ccdomain'},$env{'form.ccuname'});
2981: }
1.232 raeburn 2982: }
1.406.2.19 raeburn 2983: $r->print('<br />'.&mt('Home Server').': '.$uhome.' '.
1.219 raeburn 2984: &Apache::lonnet::hostname($uhome));
1.101 albertel 2985: } elsif (($env{'form.login'} ne 'nochange') &&
2986: ($env{'form.login'} ne '' )) {
1.27 matthew 2987: # Modify user privileges
2988: if (! $amode || ! $genpwd) {
1.193 raeburn 2989: $r->print($error.'Invalid login mode or password'.$end.$rtnlink);
1.27 matthew 2990: return;
1.20 harris41 2991: }
1.395 bisitz 2992: # Only allow authentication modification if the person has authority
1.101 albertel 2993: if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'})) {
1.20 harris41 2994: $r->print('Modifying authentication: '.
1.31 matthew 2995: &Apache::lonnet::modifyuserauth(
1.101 albertel 2996: $env{'form.ccdomain'},$env{'form.ccuname'},
1.21 harris41 2997: $amode,$genpwd));
1.406.2.19 raeburn 2998: $r->print('<br />'.&mt('Home Server').': '.&Apache::lonnet::homeserver
1.101 albertel 2999: ($env{'form.ccuname'},$env{'form.ccdomain'}));
1.4 www 3000: } else {
1.27 matthew 3001: # Okay, this is a non-fatal error.
1.406.2.17 raeburn 3002: $r->print($error.&mt('You do not have privileges to modify the authentication configuration for this user.').$end);
1.27 matthew 3003: }
1.406.2.17 raeburn 3004: } elsif (($env{'form.intarg'} ne '') &&
3005: (&Apache::lonnet::queryauthenticate($env{'form.ccuname'},$env{'form.ccdomain'}) =~ /^internal:/) &&
3006: (&Apache::lonuserutils::can_change_internalpass($env{'form.ccuname'},$env{'form.ccdomain'},$crstype,$permission))) {
3007: $r->print('Modifying authentication: '.
3008: &Apache::lonnet::modifyuserauth(
3009: $env{'form.ccdomain'},$env{'form.ccuname'},
3010: 'internal',$env{'form.intarg'}));
1.28 matthew 3011: }
1.344 bisitz 3012: $r->rflush(); # Finish display of header before time consuming actions start
1.367 golterma 3013: &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state);
1.28 matthew 3014: ##
1.375 raeburn 3015: my (@userroles,%userupdate,$cnum,$cdom,$defaultcredits,%namechanged);
1.213 raeburn 3016: if ($context eq 'course') {
1.375 raeburn 3017: ($cnum,$cdom) =
3018: &Apache::lonuserutils::get_course_identity();
1.318 raeburn 3019: $crstype = &Apache::loncommon::course_type($cdom.'_'.$cnum);
1.375 raeburn 3020: if ($showcredits) {
3021: $defaultcredits = &Apache::lonuserutils::get_defaultcredits($cdom,$cnum);
3022: }
1.213 raeburn 3023: }
1.101 albertel 3024: if (! $env{'form.makeuser'} ) {
1.28 matthew 3025: # Check for need to change
3026: my %userenv = &Apache::lonnet::get
1.134 raeburn 3027: ('environment',['firstname','middlename','lastname','generation',
1.378 raeburn 3028: 'id','permanentemail','portfolioquota','authorquota','inststatus',
1.406.2.20.2. (raeburn 3029:): 'tools.aboutme','tools.blog','tools.webdav',
3030:): 'tools.portfolio','tools.timezone',
1.361 raeburn 3031: 'requestcourses.official','requestcourses.unofficial',
1.384 raeburn 3032: 'requestcourses.community','requestcourses.textbook',
3033: 'reqcrsotherdom.official','reqcrsotherdom.unofficial',
3034: 'reqcrsotherdom.community','reqcrsotherdom.textbook',
1.406.2.9 raeburn 3035: 'requestauthor'],
1.160 raeburn 3036: $env{'form.ccdomain'},$env{'form.ccuname'});
1.28 matthew 3037: my ($tmp) = keys(%userenv);
3038: if ($tmp =~ /^(con_lost|error)/i) {
3039: %userenv = ();
3040: }
1.206 raeburn 3041: my $no_forceid_alert;
3042: # Check to see if user information can be changed
3043: my %domconfig =
3044: &Apache::lonnet::get_dom('configuration',['usermodification'],
3045: $env{'form.ccdomain'});
1.213 raeburn 3046: my @statuses = ('active','future');
3047: my %roles = &Apache::lonnet::get_my_roles($env{'form.ccuname'},$env{'form.ccdomain'},'userroles',\@statuses,undef,$env{'request.role.domain'});
3048: my ($auname,$audom);
1.220 raeburn 3049: if ($context eq 'author') {
1.206 raeburn 3050: $auname = $env{'user.name'};
3051: $audom = $env{'user.domain'};
3052: }
3053: foreach my $item (keys(%roles)) {
1.220 raeburn 3054: my ($rolenum,$roledom,$role) = split(/:/,$item,-1);
1.206 raeburn 3055: if ($context eq 'course') {
3056: if ($cnum ne '' && $cdom ne '') {
3057: if ($rolenum eq $cnum && $roledom eq $cdom) {
3058: if (!grep(/^\Q$role\E$/,@userroles)) {
3059: push(@userroles,$role);
3060: }
3061: }
3062: }
3063: } elsif ($context eq 'author') {
3064: if ($rolenum eq $auname && $roledom eq $audom) {
3065: if (!grep(/^\Q$role\E$/,@userroles)) {
3066: push(@userroles,$role);
3067: }
3068: }
3069: }
3070: }
1.220 raeburn 3071: if ($env{'form.action'} eq 'singlestudent') {
3072: if (!grep(/^st$/,@userroles)) {
3073: push(@userroles,'st');
3074: }
3075: } else {
3076: # Check for course or co-author roles being activated or re-enabled
3077: if ($context eq 'author' || $context eq 'course') {
3078: foreach my $key (keys(%env)) {
3079: if ($context eq 'author') {
3080: if ($key=~/^form\.act_\Q$audom\E_\Q$auname\E_([^_]+)/) {
3081: if (!grep(/^\Q$1\E$/,@userroles)) {
3082: push(@userroles,$1);
3083: }
3084: } elsif ($key =~/^form\.ren\:\Q$audom\E\/\Q$auname\E_([^_]+)/) {
3085: if (!grep(/^\Q$1\E$/,@userroles)) {
3086: push(@userroles,$1);
3087: }
1.206 raeburn 3088: }
1.220 raeburn 3089: } elsif ($context eq 'course') {
3090: if ($key=~/^form\.act_\Q$cdom\E_\Q$cnum\E_([^_]+)/) {
3091: if (!grep(/^\Q$1\E$/,@userroles)) {
3092: push(@userroles,$1);
3093: }
3094: } elsif ($key =~/^form\.ren\:\Q$cdom\E\/\Q$cnum\E(\/?\w*)_([^_]+)/) {
3095: if (!grep(/^\Q$1\E$/,@userroles)) {
3096: push(@userroles,$1);
3097: }
1.206 raeburn 3098: }
3099: }
3100: }
3101: }
3102: }
3103: #Check to see if we can change personal data for the user
3104: my (@mod_disallowed,@longroles);
3105: foreach my $role (@userroles) {
3106: if ($role eq 'cr') {
3107: push(@longroles,'Custom');
3108: } else {
1.318 raeburn 3109: push(@longroles,&Apache::lonnet::plaintext($role,$crstype));
1.206 raeburn 3110: }
3111: }
1.219 raeburn 3112: my %canmodify = &Apache::lonuserutils::can_modify_userinfo($context,$env{'form.ccdomain'},\@userinfo,\@userroles);
3113: foreach my $item (@userinfo) {
1.28 matthew 3114: # Strip leading and trailing whitespace
1.203 raeburn 3115: $env{'form.c'.$item} =~ s/(\s+$|^\s+)//g;
1.219 raeburn 3116: if (!$canmodify{$item}) {
1.207 raeburn 3117: if (defined($env{'form.c'.$item})) {
3118: if ($env{'form.c'.$item} ne $userenv{$item}) {
3119: push(@mod_disallowed,$item);
3120: }
1.206 raeburn 3121: }
3122: $env{'form.c'.$item} = $userenv{$item};
3123: }
1.28 matthew 3124: }
1.259 bisitz 3125: # Check to see if we can change the Student/Employee ID
1.196 raeburn 3126: my $forceid = $env{'form.forceid'};
3127: my $recurseid = $env{'form.recurseid'};
3128: my (%alerts,%rulematch,%idinst_results,%curr_rules,%got_rules);
1.203 raeburn 3129: my %uidhash = &Apache::lonnet::idrget($env{'form.ccdomain'},
3130: $env{'form.ccuname'});
3131: if (($uidhash{$env{'form.ccuname'}}) &&
3132: ($uidhash{$env{'form.ccuname'}}!~/error\:/) &&
3133: (!$forceid)) {
3134: if ($env{'form.cid'} ne $uidhash{$env{'form.ccuname'}}) {
3135: $env{'form.cid'} = $userenv{'id'};
1.293 bisitz 3136: $no_forceid_alert = &mt('New student/employee ID does not match existing ID for this user.')
1.259 bisitz 3137: .'<br />'
3138: .&mt("Change is not permitted without checking the 'Force ID change' checkbox on the previous page.")
3139: .'<br />'."\n";
1.203 raeburn 3140: }
3141: }
3142: if ($env{'form.cid'} ne $userenv{'id'}) {
1.196 raeburn 3143: my $checkhash;
3144: my $checks = { 'id' => 1 };
3145: $checkhash->{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}} =
3146: { 'newuser' => $newuser,
3147: 'id' => $env{'form.cid'},
3148: };
3149: &Apache::loncommon::user_rule_check($checkhash,$checks,
3150: \%alerts,\%rulematch,\%idinst_results,\%curr_rules,\%got_rules);
3151: if (ref($alerts{'id'}) eq 'HASH') {
3152: if (ref($alerts{'id'}{$env{'form.ccdomain'}}) eq 'HASH') {
1.203 raeburn 3153: $env{'form.cid'} = $userenv{'id'};
1.196 raeburn 3154: }
3155: }
3156: }
1.378 raeburn 3157: my (%quotachanged,%oldquota,%newquota,%olddefquota,%newdefquota,
3158: $oldinststatus,$newinststatus,%oldisdefault,%newisdefault,%oldsettings,
1.339 raeburn 3159: %oldsettingstext,%newsettings,%newsettingstext,@disporder,
1.378 raeburn 3160: %oldsettingstatus,%newsettingstatus);
1.334 raeburn 3161: @disporder = ('inststatus');
3162: if ($env{'request.role.domain'} eq $env{'form.ccdomain'}) {
1.362 raeburn 3163: push(@disporder,'requestcourses','requestauthor');
1.334 raeburn 3164: } else {
3165: push(@disporder,'reqcrsotherdom');
3166: }
3167: push(@disporder,('quota','tools'));
1.338 raeburn 3168: $oldinststatus = $userenv{'inststatus'};
1.378 raeburn 3169: foreach my $name ('portfolio','author') {
3170: ($olddefquota{$name},$oldsettingstatus{$name}) =
3171: &Apache::loncommon::default_quota($env{'form.ccdomain'},$oldinststatus,$name);
3172: ($newdefquota{$name},$newsettingstatus{$name}) = ($olddefquota{$name},$oldsettingstatus{$name});
3173: }
1.334 raeburn 3174: my %canshow;
1.220 raeburn 3175: if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
1.334 raeburn 3176: $canshow{'quota'} = 1;
1.220 raeburn 3177: }
1.267 raeburn 3178: if (&Apache::lonnet::allowed('mut',$env{'form.ccdomain'})) {
1.334 raeburn 3179: $canshow{'tools'} = 1;
1.267 raeburn 3180: }
1.275 raeburn 3181: if (&Apache::lonnet::allowed('ccc',$env{'form.ccdomain'})) {
1.334 raeburn 3182: $canshow{'requestcourses'} = 1;
1.300 raeburn 3183: } elsif (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
1.334 raeburn 3184: $canshow{'reqcrsotherdom'} = 1;
1.275 raeburn 3185: }
1.286 raeburn 3186: if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'})) {
1.334 raeburn 3187: $canshow{'inststatus'} = 1;
1.286 raeburn 3188: }
1.362 raeburn 3189: if (&Apache::lonnet::allowed('cau',$env{'form.ccdomain'})) {
3190: $canshow{'requestauthor'} = 1;
3191: }
1.267 raeburn 3192: my (%changeHash,%changed);
1.286 raeburn 3193: if ($oldinststatus eq '') {
1.334 raeburn 3194: $oldsettings{'inststatus'} = $othertitle;
1.286 raeburn 3195: } else {
3196: if (ref($usertypes) eq 'HASH') {
1.334 raeburn 3197: $oldsettings{'inststatus'} = join(', ',map{ $usertypes->{ &unescape($_) }; } (split(/:/,$userenv{'inststatus'})));
1.286 raeburn 3198: } else {
1.334 raeburn 3199: $oldsettings{'inststatus'} = join(', ',map{ &unescape($_); } (split(/:/,$userenv{'inststatus'})));
1.286 raeburn 3200: }
3201: }
3202: $changeHash{'inststatus'} = $userenv{'inststatus'};
1.334 raeburn 3203: if ($canmodify_status{'inststatus'}) {
3204: $canshow{'inststatus'} = 1;
1.286 raeburn 3205: if (exists($env{'form.inststatus'})) {
3206: my @inststatuses = &Apache::loncommon::get_env_multiple('form.inststatus');
3207: if (@inststatuses > 0) {
3208: $newinststatus = join(':',map { &escape($_); } @inststatuses);
3209: $changeHash{'inststatus'} = $newinststatus;
3210: if ($newinststatus ne $oldinststatus) {
3211: $changed{'inststatus'} = $newinststatus;
1.378 raeburn 3212: foreach my $name ('portfolio','author') {
3213: ($newdefquota{$name},$newsettingstatus{$name}) =
3214: &Apache::loncommon::default_quota($env{'form.ccdomain'},$newinststatus,$name);
3215: }
1.286 raeburn 3216: }
3217: if (ref($usertypes) eq 'HASH') {
1.334 raeburn 3218: $newsettings{'inststatus'} = join(', ',map{ $usertypes->{$_}; } (@inststatuses));
1.286 raeburn 3219: } else {
1.337 raeburn 3220: $newsettings{'inststatus'} = join(', ',@inststatuses);
1.286 raeburn 3221: }
1.334 raeburn 3222: }
3223: } else {
3224: $newinststatus = '';
3225: $changeHash{'inststatus'} = $newinststatus;
3226: $newsettings{'inststatus'} = $othertitle;
3227: if ($newinststatus ne $oldinststatus) {
3228: $changed{'inststatus'} = $changeHash{'inststatus'};
1.378 raeburn 3229: foreach my $name ('portfolio','author') {
3230: ($newdefquota{$name},$newsettingstatus{$name}) =
3231: &Apache::loncommon::default_quota($env{'form.ccdomain'},$newinststatus,$name);
3232: }
1.286 raeburn 3233: }
3234: }
1.334 raeburn 3235: } elsif ($context ne 'selfcreate') {
3236: $canshow{'inststatus'} = 1;
1.337 raeburn 3237: $newsettings{'inststatus'} = $oldsettings{'inststatus'};
1.286 raeburn 3238: }
1.378 raeburn 3239: foreach my $name ('portfolio','author') {
3240: $changeHash{$name.'quota'} = $userenv{$name.'quota'};
3241: }
1.334 raeburn 3242: if ($context eq 'domain') {
1.378 raeburn 3243: foreach my $name ('portfolio','author') {
3244: if ($userenv{$name.'quota'} ne '') {
3245: $oldquota{$name} = $userenv{$name.'quota'};
3246: if ($env{'form.custom_'.$name.'quota'} == 1) {
3247: if ($env{'form.'.$name.'quota'} eq '') {
3248: $newquota{$name} = 0;
3249: } else {
3250: $newquota{$name} = $env{'form.'.$name.'quota'};
3251: $newquota{$name} =~ s/[^\d\.]//g;
3252: }
3253: if ($newquota{$name} != $oldquota{$name}) {
3254: if ("a_admin($newquota{$name},\%changeHash,$name)) {
3255: $changed{$name.'quota'} = 1;
3256: }
3257: }
1.334 raeburn 3258: } else {
1.378 raeburn 3259: if ("a_admin('',\%changeHash,$name)) {
3260: $changed{$name.'quota'} = 1;
3261: $newquota{$name} = $newdefquota{$name};
3262: $newisdefault{$name} = 1;
3263: }
1.334 raeburn 3264: }
1.149 raeburn 3265: } else {
1.378 raeburn 3266: $oldisdefault{$name} = 1;
3267: $oldquota{$name} = $olddefquota{$name};
3268: if ($env{'form.custom_'.$name.'quota'} == 1) {
3269: if ($env{'form.'.$name.'quota'} eq '') {
3270: $newquota{$name} = 0;
3271: } else {
3272: $newquota{$name} = $env{'form.'.$name.'quota'};
3273: $newquota{$name} =~ s/[^\d\.]//g;
3274: }
3275: if ("a_admin($newquota{$name},\%changeHash,$name)) {
3276: $changed{$name.'quota'} = 1;
3277: }
1.334 raeburn 3278: } else {
1.378 raeburn 3279: $newquota{$name} = $newdefquota{$name};
3280: $newisdefault{$name} = 1;
1.334 raeburn 3281: }
1.378 raeburn 3282: }
3283: if ($oldisdefault{$name}) {
3284: $oldsettingstext{'quota'}{$name} = &get_defaultquota_text($oldsettingstatus{$name});
1.383 raeburn 3285: } else {
3286: $oldsettingstext{'quota'}{$name} = &mt('custom quota: [_1] MB',$oldquota{$name});
1.378 raeburn 3287: }
3288: if ($newisdefault{$name}) {
3289: $newsettingstext{'quota'}{$name} = &get_defaultquota_text($newsettingstatus{$name});
1.383 raeburn 3290: } else {
3291: $newsettingstext{'quota'}{$name} = &mt('custom quota: [_1] MB',$newquota{$name});
1.134 raeburn 3292: }
3293: }
1.334 raeburn 3294: &tool_changes('tools',\@usertools,\%oldsettings,\%oldsettingstext,\%userenv,
3295: \%changeHash,\%changed,\%newsettings,\%newsettingstext);
3296: if ($env{'form.ccdomain'} eq $env{'request.role.domain'}) {
3297: &tool_changes('requestcourses',\@requestcourses,\%oldsettings,\%oldsettingstext,
3298: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
1.384 raeburn 3299: &tool_changes('requestauthor',\@requestauthor,\%oldsettings,\%oldsettingstext,
3300: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
1.149 raeburn 3301: } else {
1.334 raeburn 3302: &tool_changes('reqcrsotherdom',\@requestcourses,\%oldsettings,\%oldsettingstext,
3303: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
1.149 raeburn 3304: }
3305: }
1.334 raeburn 3306: foreach my $item (@userinfo) {
3307: if ($env{'form.c'.$item} ne $userenv{$item}) {
3308: $namechanged{$item} = 1;
3309: }
1.204 raeburn 3310: }
1.378 raeburn 3311: foreach my $name ('portfolio','author') {
1.390 bisitz 3312: $oldsettings{'quota'}{$name} = &mt('[_1] MB',$oldquota{$name});
3313: $newsettings{'quota'}{$name} = &mt('[_1] MB',$newquota{$name});
1.378 raeburn 3314: }
1.334 raeburn 3315: if ((keys(%namechanged) > 0) || (keys(%changed) > 0)) {
1.267 raeburn 3316: my ($chgresult,$namechgresult);
3317: if (keys(%changed) > 0) {
3318: $chgresult =
1.204 raeburn 3319: &Apache::lonnet::put('environment',\%changeHash,
3320: $env{'form.ccdomain'},$env{'form.ccuname'});
1.267 raeburn 3321: if ($chgresult eq 'ok') {
3322: if (($env{'user.name'} eq $env{'form.ccuname'}) &&
3323: ($env{'user.domain'} eq $env{'form.ccdomain'})) {
1.270 raeburn 3324: my %newenvhash;
3325: foreach my $key (keys(%changed)) {
1.299 raeburn 3326: if (($key eq 'official') || ($key eq 'unofficial')
1.403 raeburn 3327: || ($key eq 'community') || ($key eq 'textbook')) {
1.279 raeburn 3328: $newenvhash{'environment.requestcourses.'.$key} =
3329: $changeHash{'requestcourses.'.$key};
1.362 raeburn 3330: if ($changeHash{'requestcourses.'.$key}) {
1.332 raeburn 3331: $newenvhash{'environment.canrequest.'.$key} = 1;
1.279 raeburn 3332: } else {
3333: $newenvhash{'environment.canrequest.'.$key} =
3334: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
3335: $key,'reload','requestcourses');
3336: }
1.362 raeburn 3337: } elsif ($key eq 'requestauthor') {
3338: $newenvhash{'environment.'.$key} = $changeHash{$key};
3339: if ($changeHash{$key}) {
3340: $newenvhash{'environment.canrequest.author'} = 1;
3341: } else {
3342: $newenvhash{'environment.canrequest.author'} =
3343: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
3344: $key,'reload','requestauthor');
3345: }
1.275 raeburn 3346: } elsif ($key ne 'quota') {
1.270 raeburn 3347: $newenvhash{'environment.tools.'.$key} =
3348: $changeHash{'tools.'.$key};
1.279 raeburn 3349: if ($changeHash{'tools.'.$key} ne '') {
3350: $newenvhash{'environment.availabletools.'.$key} =
3351: $changeHash{'tools.'.$key};
3352: } else {
3353: $newenvhash{'environment.availabletools.'.$key} =
1.367 golterma 3354: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
3355: $key,'reload','tools');
1.279 raeburn 3356: }
1.270 raeburn 3357: }
3358: }
1.271 raeburn 3359: if (keys(%newenvhash)) {
3360: &Apache::lonnet::appenv(\%newenvhash);
3361: }
1.267 raeburn 3362: }
3363: }
1.204 raeburn 3364: }
1.334 raeburn 3365: if (keys(%namechanged) > 0) {
1.337 raeburn 3366: foreach my $field (@userinfo) {
3367: $changeHash{$field} = $env{'form.c'.$field};
3368: }
3369: # Make the change
1.204 raeburn 3370: $namechgresult =
3371: &Apache::lonnet::modifyuser($env{'form.ccdomain'},
3372: $env{'form.ccuname'},$changeHash{'id'},undef,undef,
3373: $changeHash{'firstname'},$changeHash{'middlename'},
3374: $changeHash{'lastname'},$changeHash{'generation'},
1.337 raeburn 3375: $changeHash{'id'},undef,$changeHash{'permanentemail'},undef,\@userinfo);
1.220 raeburn 3376: %userupdate = (
3377: lastname => $env{'form.clastname'},
3378: middlename => $env{'form.cmiddlename'},
3379: firstname => $env{'form.cfirstname'},
3380: generation => $env{'form.cgeneration'},
3381: id => $env{'form.cid'},
3382: );
1.204 raeburn 3383: }
1.334 raeburn 3384: if (((keys(%namechanged) > 0) && $namechgresult eq 'ok') ||
1.267 raeburn 3385: ((keys(%changed) > 0) && $chgresult eq 'ok')) {
1.28 matthew 3386: # Tell the user we changed the name
1.334 raeburn 3387: &display_userinfo($r,1,\@disporder,\%canshow,\@requestcourses,
1.362 raeburn 3388: \@usertools,\@requestauthor,\%userenv,\%changed,\%namechanged,
1.334 raeburn 3389: \%oldsettings, \%oldsettingstext,\%newsettings,
3390: \%newsettingstext);
1.203 raeburn 3391: if ($env{'form.cid'} ne $userenv{'id'}) {
3392: &Apache::lonnet::idput($env{'form.ccdomain'},
1.406.2.5 raeburn 3393: {$env{'form.ccuname'} => $env{'form.cid'}});
1.203 raeburn 3394: if (($recurseid) &&
3395: (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'}))) {
3396: my $idresult =
3397: &Apache::lonuserutils::propagate_id_change(
3398: $env{'form.ccuname'},$env{'form.ccdomain'},
3399: \%userupdate);
3400: $r->print('<br />'.$idresult.'<br />');
3401: }
1.196 raeburn 3402: }
1.149 raeburn 3403: if (($env{'form.ccdomain'} eq $env{'user.domain'}) &&
3404: ($env{'form.ccuname'} eq $env{'user.name'})) {
3405: my %newenvhash;
3406: foreach my $key (keys(%changeHash)) {
3407: $newenvhash{'environment.'.$key} = $changeHash{$key};
3408: }
1.238 raeburn 3409: &Apache::lonnet::appenv(\%newenvhash);
1.149 raeburn 3410: }
1.28 matthew 3411: } else { # error occurred
1.389 bisitz 3412: $r->print(
3413: '<p class="LC_error">'
3414: .&mt('Unable to successfully change environment for [_1] in domain [_2].',
3415: '"'.$env{'form.ccuname'}.'"',
3416: '"'.$env{'form.ccdomain'}.'"')
3417: .'</p>');
1.28 matthew 3418: }
1.334 raeburn 3419: } else { # End of if ($env ... ) logic
1.275 raeburn 3420: # They did not want to change the users name, quota, tool availability,
3421: # or ability to request creation of courses,
1.267 raeburn 3422: # but we can still tell them what the name and quota and availabilities are
1.334 raeburn 3423: &display_userinfo($r,undef,\@disporder,\%canshow,\@requestcourses,
1.362 raeburn 3424: \@usertools,\@requestauthor,\%userenv,\%changed,\%namechanged,\%oldsettings,
1.334 raeburn 3425: \%oldsettingstext,\%newsettings,\%newsettingstext);
1.28 matthew 3426: }
1.206 raeburn 3427: if (@mod_disallowed) {
3428: my ($rolestr,$contextname);
3429: if (@longroles > 0) {
3430: $rolestr = join(', ',@longroles);
3431: } else {
3432: $rolestr = &mt('No roles');
3433: }
3434: if ($context eq 'course') {
1.399 bisitz 3435: $contextname = 'course';
1.206 raeburn 3436: } elsif ($context eq 'author') {
1.399 bisitz 3437: $contextname = 'co-author';
1.206 raeburn 3438: }
3439: $r->print(&mt('The following fields were not updated: ').'<ul>');
3440: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
3441: foreach my $field (@mod_disallowed) {
3442: $r->print('<li>'.$fieldtitles{$field}.'</li>'."\n");
3443: }
1.207 raeburn 3444: $r->print('</ul>');
3445: if (@mod_disallowed == 1) {
1.399 bisitz 3446: $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 3447: } else {
1.399 bisitz 3448: $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 3449: }
1.292 bisitz 3450: my $helplink = 'javascript:helpMenu('."'display'".')';
3451: $r->print('<span class="LC_cusr_emph">'.$rolestr.'</span><br />'
3452: .&mt('Please contact your [_1]helpdesk[_2] for more information.'
3453: ,'<a href="'.$helplink.'">','</a>')
3454: .'<br />');
1.206 raeburn 3455: }
1.259 bisitz 3456: $r->print('<span class="LC_warning">'
3457: .$no_forceid_alert
3458: .&Apache::lonuserutils::print_namespacing_alerts($env{'form.ccdomain'},\%alerts,\%curr_rules)
3459: .'</span>');
1.4 www 3460: }
1.367 golterma 3461: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
1.220 raeburn 3462: if ($env{'form.action'} eq 'singlestudent') {
1.375 raeburn 3463: &enroll_single_student($r,$uhome,$amode,$genpwd,$now,$newuser,$context,
3464: $crstype,$showcredits,$defaultcredits);
1.386 bisitz 3465: my $linktext = ($crstype eq 'Community' ?
3466: &mt('Enroll Another Member') : &mt('Enroll Another Student'));
3467: $r->print(
3468: &Apache::lonhtmlcommon::actionbox([
3469: '<a href="javascript:backPage(document.userupdate)">'
3470: .($crstype eq 'Community' ?
3471: &mt('Enroll Another Member') : &mt('Enroll Another Student'))
3472: .'</a>']));
1.220 raeburn 3473: } else {
1.375 raeburn 3474: my @rolechanges = &update_roles($r,$context,$showcredits);
1.334 raeburn 3475: if (keys(%namechanged) > 0) {
1.220 raeburn 3476: if ($context eq 'course') {
3477: if (@userroles > 0) {
1.225 raeburn 3478: if ((@rolechanges == 0) ||
3479: (!(grep(/^st$/,@rolechanges)))) {
3480: if (grep(/^st$/,@userroles)) {
3481: my $classlistupdated =
3482: &Apache::lonuserutils::update_classlist($cdom,
1.220 raeburn 3483: $cnum,$env{'form.ccdomain'},
3484: $env{'form.ccuname'},\%userupdate);
1.225 raeburn 3485: }
1.220 raeburn 3486: }
3487: }
3488: }
3489: }
1.226 raeburn 3490: my $userinfo = &Apache::loncommon::plainname($env{'form.ccuname'},
1.233 raeburn 3491: $env{'form.ccdomain'});
3492: if ($env{'form.popup'}) {
3493: $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a></p>');
3494: } else {
1.367 golterma 3495: $r->print('<br />'.&Apache::lonhtmlcommon::actionbox(['<a href="javascript:backPage(document.userupdate,'."'$env{'form.prevphase'}','modify'".')">'
3496: .&mt('Modify this user: [_1]','<span class="LC_cusr_emph">'.$env{'form.ccuname'}.':'.$env{'form.ccdomain'}.' ('.$userinfo.')</span>').'</a>',
3497: '<a href="javascript:backPage(document.userupdate)">'.&mt('Create/Modify Another User').'</a>']));
1.233 raeburn 3498: }
1.220 raeburn 3499: }
3500: }
3501:
1.334 raeburn 3502: sub display_userinfo {
1.362 raeburn 3503: my ($r,$changed,$order,$canshow,$requestcourses,$usertools,$requestauthor,
3504: $userenv,$changedhash,$namechangedhash,$oldsetting,$oldsettingtext,
1.334 raeburn 3505: $newsetting,$newsettingtext) = @_;
3506: return unless (ref($order) eq 'ARRAY' &&
3507: ref($canshow) eq 'HASH' &&
3508: ref($requestcourses) eq 'ARRAY' &&
1.362 raeburn 3509: ref($requestauthor) eq 'ARRAY' &&
1.334 raeburn 3510: ref($usertools) eq 'ARRAY' &&
3511: ref($userenv) eq 'HASH' &&
3512: ref($changedhash) eq 'HASH' &&
3513: ref($oldsetting) eq 'HASH' &&
3514: ref($oldsettingtext) eq 'HASH' &&
3515: ref($newsetting) eq 'HASH' &&
3516: ref($newsettingtext) eq 'HASH');
3517: my %lt=&Apache::lonlocal::texthash(
1.372 raeburn 3518: 'ui' => 'User Information',
1.334 raeburn 3519: 'uic' => 'User Information Changed',
3520: 'firstname' => 'First Name',
3521: 'middlename' => 'Middle Name',
3522: 'lastname' => 'Last Name',
3523: 'generation' => 'Generation',
3524: 'id' => 'Student/Employee ID',
3525: 'permanentemail' => 'Permanent e-mail address',
1.378 raeburn 3526: 'portfolioquota' => 'Disk space allocated to portfolio files',
1.385 bisitz 3527: 'authorquota' => 'Disk space allocated to Authoring Space',
1.334 raeburn 3528: 'blog' => 'Blog Availability',
1.361 raeburn 3529: 'webdav' => 'WebDAV Availability',
1.334 raeburn 3530: 'aboutme' => 'Personal Information Page Availability',
3531: 'portfolio' => 'Portfolio Availability',
1.406.2.20.2. (raeburn 3532:): 'timezone' => 'Can set own Time Zone',
1.334 raeburn 3533: 'official' => 'Can Request Official Courses',
3534: 'unofficial' => 'Can Request Unofficial Courses',
3535: 'community' => 'Can Request Communities',
1.384 raeburn 3536: 'textbook' => 'Can Request Textbook Courses',
1.362 raeburn 3537: 'requestauthor' => 'Can Request Author Role',
1.334 raeburn 3538: 'inststatus' => "Affiliation",
3539: 'prvs' => 'Previous Value:',
3540: 'chto' => 'Changed To:'
3541: );
3542: if ($changed) {
1.372 raeburn 3543: $r->print('<h3>'.$lt{'uic'}.'</h3>'.
1.367 golterma 3544: &Apache::loncommon::start_data_table().
3545: &Apache::loncommon::start_data_table_header_row());
1.334 raeburn 3546: $r->print("<th> </th>\n");
1.367 golterma 3547: $r->print('<th><b>'.$lt{'prvs'}.'</b></th>');
3548: $r->print('<th><span class="LC_nobreak"><b>'.$lt{'chto'}.'</b></span></th>');
3549: $r->print(&Apache::loncommon::end_data_table_header_row());
3550: my @userinfo = ('firstname','middlename','lastname','generation','permanentemail','id');
3551:
1.334 raeburn 3552: foreach my $item (@userinfo) {
3553: my $value = $env{'form.c'.$item};
1.367 golterma 3554: #show changes only:
1.383 raeburn 3555: unless ($value eq $userenv->{$item}){
1.367 golterma 3556: $r->print(&Apache::loncommon::start_data_table_row());
3557: $r->print("<td>$lt{$item}</td>\n");
1.383 raeburn 3558: $r->print("<td>".$userenv->{$item}."</td>\n");
1.367 golterma 3559: $r->print("<td>$value </td>\n");
3560: $r->print(&Apache::loncommon::end_data_table_row());
1.334 raeburn 3561: }
3562: }
3563: foreach my $entry (@{$order}) {
1.383 raeburn 3564: if ($canshow->{$entry}) {
3565: if (($entry eq 'requestcourses') || ($entry eq 'reqcrsotherdom') || ($entry eq 'requestauthor')) {
3566: my @items;
3567: if ($entry eq 'requestauthor') {
3568: @items = ($entry);
3569: } else {
3570: @items = @{$requestcourses};
1.384 raeburn 3571: }
1.383 raeburn 3572: foreach my $item (@items) {
3573: if (($newsetting->{$item} ne $oldsetting->{$item}) ||
3574: ($newsettingtext->{$item} ne $oldsettingtext->{$item})) {
3575: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3576: $r->print("<td>$lt{$item}</td>\n");
3577: $r->print("<td>".$oldsetting->{$item});
3578: if ($oldsettingtext->{$item}) {
3579: if ($oldsetting->{$item}) {
3580: $r->print(' -- ');
3581: }
3582: $r->print($oldsettingtext->{$item});
3583: }
3584: $r->print("</td>\n");
3585: $r->print("<td>".$newsetting->{$item});
3586: if ($newsettingtext->{$item}) {
3587: if ($newsetting->{$item}) {
3588: $r->print(' -- ');
3589: }
3590: $r->print($newsettingtext->{$item});
3591: }
3592: $r->print("</td>\n");
3593: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.334 raeburn 3594: }
3595: }
3596: } elsif ($entry eq 'tools') {
3597: foreach my $item (@{$usertools}) {
1.383 raeburn 3598: if ($newsetting->{$item} ne $oldsetting->{$item}) {
3599: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3600: $r->print("<td>$lt{$item}</td>\n");
3601: $r->print("<td>".$oldsetting->{$item}.' '.$oldsettingtext->{$item}."</td>\n");
3602: $r->print("<td>".$newsetting->{$item}.' '.$newsettingtext->{$item}."</td>\n");
3603: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.334 raeburn 3604: }
3605: }
1.378 raeburn 3606: } elsif ($entry eq 'quota') {
3607: if ((ref($oldsetting->{$entry}) eq 'HASH') && (ref($oldsettingtext->{$entry}) eq 'HASH') &&
3608: (ref($newsetting->{$entry}) eq 'HASH') && (ref($newsettingtext->{$entry}) eq 'HASH')) {
3609: foreach my $name ('portfolio','author') {
1.383 raeburn 3610: if ($newsetting->{$entry}->{$name} ne $oldsetting->{$entry}->{$name}) {
3611: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3612: $r->print("<td>$lt{$name.$entry}</td>\n");
3613: $r->print("<td>".$oldsettingtext->{$entry}->{$name}."</td>\n");
3614: $r->print("<td>".$newsettingtext->{$entry}->{$name}."</td>\n");
3615: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.378 raeburn 3616: }
3617: }
3618: }
1.334 raeburn 3619: } else {
1.383 raeburn 3620: if ($newsetting->{$entry} ne $oldsetting->{$entry}) {
3621: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3622: $r->print("<td>$lt{$entry}</td>\n");
3623: $r->print("<td>".$oldsetting->{$entry}.' '.$oldsettingtext->{$entry}."</td>\n");
3624: $r->print("<td>".$newsetting->{$entry}.' '.$newsettingtext->{$entry}."</td>\n");
3625: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.334 raeburn 3626: }
3627: }
3628: }
3629: }
1.367 golterma 3630: $r->print(&Apache::loncommon::end_data_table().'<br />');
1.372 raeburn 3631: } else {
3632: $r->print('<h3>'.$lt{'ui'}.'</h3>'.
3633: '<p>'.&mt('No changes made to user information').'</p>');
1.334 raeburn 3634: }
3635: return;
3636: }
3637:
1.275 raeburn 3638: sub tool_changes {
3639: my ($context,$usertools,$oldaccess,$oldaccesstext,$userenv,$changeHash,
3640: $changed,$newaccess,$newaccesstext) = @_;
3641: if (!((ref($usertools) eq 'ARRAY') && (ref($oldaccess) eq 'HASH') &&
3642: (ref($oldaccesstext) eq 'HASH') && (ref($userenv) eq 'HASH') &&
3643: (ref($changeHash) eq 'HASH') && (ref($changed) eq 'HASH') &&
3644: (ref($newaccess) eq 'HASH') && (ref($newaccesstext) eq 'HASH'))) {
3645: return;
3646: }
1.383 raeburn 3647: my %reqdisplay = &requestchange_display();
1.300 raeburn 3648: if ($context eq 'reqcrsotherdom') {
1.309 raeburn 3649: my @options = ('approval','validate','autolimit');
1.306 raeburn 3650: my $optregex = join('|',@options);
1.300 raeburn 3651: my $cdom = $env{'request.role.domain'};
3652: foreach my $tool (@{$usertools}) {
1.383 raeburn 3653: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
1.314 raeburn 3654: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
1.300 raeburn 3655: $changeHash->{$context.'.'.$tool} = $userenv->{$context.'.'.$tool};
1.383 raeburn 3656: my ($newop,$limit);
1.314 raeburn 3657: if ($env{'form.'.$context.'_'.$tool}) {
3658: $newop = $env{'form.'.$context.'_'.$tool};
3659: if ($newop eq 'autolimit') {
1.383 raeburn 3660: $limit = $env{'form.'.$context.'_'.$tool.'_limit'};
1.314 raeburn 3661: $limit =~ s/\D+//g;
3662: $newop .= '='.$limit;
3663: }
3664: }
1.300 raeburn 3665: if ($userenv->{$context.'.'.$tool} eq '') {
1.314 raeburn 3666: if ($newop) {
3667: $changed->{$tool}=&tool_admin($tool,$cdom.':'.$newop,
1.300 raeburn 3668: $changeHash,$context);
3669: if ($changed->{$tool}) {
1.383 raeburn 3670: if ($newop =~ /^autolimit/) {
3671: if ($limit) {
3672: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3673: } else {
3674: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3675: }
3676: } else {
3677: $newaccesstext->{$tool} = $reqdisplay{$newop};
3678: }
1.300 raeburn 3679: } else {
3680: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
3681: }
3682: }
3683: } else {
3684: my @curr = split(',',$userenv->{$context.'.'.$tool});
3685: my @new;
3686: my $changedoms;
1.314 raeburn 3687: foreach my $req (@curr) {
3688: if ($req =~ /^\Q$cdom\E\:($optregex\=?\d*)$/) {
3689: my $oldop = $1;
1.383 raeburn 3690: if ($oldop =~ /^autolimit=(\d*)/) {
3691: my $limit = $1;
3692: if ($limit) {
3693: $oldaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3694: } else {
3695: $oldaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3696: }
3697: } else {
3698: $oldaccesstext->{$tool} = $reqdisplay{$oldop};
3699: }
1.314 raeburn 3700: if ($oldop ne $newop) {
3701: $changedoms = 1;
3702: foreach my $item (@curr) {
3703: my ($reqdom,$option) = split(':',$item);
3704: unless ($reqdom eq $cdom) {
3705: push(@new,$item);
3706: }
3707: }
3708: if ($newop) {
3709: push(@new,$cdom.':'.$newop);
1.300 raeburn 3710: }
1.314 raeburn 3711: @new = sort(@new);
1.300 raeburn 3712: }
1.314 raeburn 3713: last;
1.300 raeburn 3714: }
1.314 raeburn 3715: }
3716: if ((!$changedoms) && ($newop)) {
1.300 raeburn 3717: $changedoms = 1;
1.306 raeburn 3718: @new = sort(@curr,$cdom.':'.$newop);
1.300 raeburn 3719: }
3720: if ($changedoms) {
1.314 raeburn 3721: my $newdomstr;
1.300 raeburn 3722: if (@new) {
3723: $newdomstr = join(',',@new);
3724: }
3725: $changed->{$tool}=&tool_admin($tool,$newdomstr,$changeHash,
3726: $context);
3727: if ($changed->{$tool}) {
3728: if ($env{'form.'.$context.'_'.$tool}) {
1.306 raeburn 3729: if ($env{'form.'.$context.'_'.$tool} eq 'autolimit') {
1.314 raeburn 3730: my $limit = $env{'form.'.$context.'_'.$tool.'_limit'};
3731: $limit =~ s/\D+//g;
3732: if ($limit) {
1.383 raeburn 3733: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
1.314 raeburn 3734: } else {
1.383 raeburn 3735: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
1.306 raeburn 3736: }
1.314 raeburn 3737: } else {
1.306 raeburn 3738: $newaccesstext->{$tool} = $reqdisplay{$env{'form.'.$context.'_'.$tool}};
3739: }
1.300 raeburn 3740: } else {
1.383 raeburn 3741: $newaccesstext->{$tool} = &mt("availability set to 'off'");
1.300 raeburn 3742: }
3743: }
3744: }
3745: }
3746: }
3747: return;
3748: }
1.275 raeburn 3749: foreach my $tool (@{$usertools}) {
1.383 raeburn 3750: my ($newval,$limit,$envkey);
1.362 raeburn 3751: $envkey = $context.'.'.$tool;
1.306 raeburn 3752: if ($context eq 'requestcourses') {
3753: $newval = $env{'form.crsreq_'.$tool};
3754: if ($newval eq 'autolimit') {
1.383 raeburn 3755: $limit = $env{'form.crsreq_'.$tool.'_limit'};
3756: $limit =~ s/\D+//g;
3757: $newval .= '='.$limit;
1.306 raeburn 3758: }
1.362 raeburn 3759: } elsif ($context eq 'requestauthor') {
3760: $newval = $env{'form.'.$context};
3761: $envkey = $context;
1.314 raeburn 3762: } else {
1.306 raeburn 3763: $newval = $env{'form.'.$context.'_'.$tool};
3764: }
1.362 raeburn 3765: if ($userenv->{$envkey} ne '') {
1.275 raeburn 3766: $oldaccess->{$tool} = &mt('custom');
1.383 raeburn 3767: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3768: if ($userenv->{$envkey} =~ /^autolimit=(\d*)$/) {
3769: my $currlimit = $1;
3770: if ($currlimit eq '') {
3771: $oldaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3772: } else {
3773: $oldaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$currlimit);
3774: }
3775: } elsif ($userenv->{$envkey}) {
3776: $oldaccesstext->{$tool} = $reqdisplay{$userenv->{$envkey}};
3777: } else {
3778: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
3779: }
1.275 raeburn 3780: } else {
1.383 raeburn 3781: if ($userenv->{$envkey}) {
3782: $oldaccesstext->{$tool} = &mt("availability set to 'on'");
3783: } else {
3784: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
3785: }
1.275 raeburn 3786: }
1.362 raeburn 3787: $changeHash->{$envkey} = $userenv->{$envkey};
1.275 raeburn 3788: if ($env{'form.custom'.$tool} == 1) {
1.362 raeburn 3789: if ($newval ne $userenv->{$envkey}) {
1.306 raeburn 3790: $changed->{$tool} = &tool_admin($tool,$newval,$changeHash,
3791: $context);
1.275 raeburn 3792: if ($changed->{$tool}) {
3793: $newaccess->{$tool} = &mt('custom');
1.383 raeburn 3794: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3795: if ($newval =~ /^autolimit/) {
3796: if ($limit) {
3797: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3798: } else {
3799: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3800: }
3801: } elsif ($newval) {
3802: $newaccesstext->{$tool} = $reqdisplay{$newval};
3803: } else {
3804: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3805: }
1.275 raeburn 3806: } else {
1.383 raeburn 3807: if ($newval) {
3808: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3809: } else {
3810: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3811: }
1.275 raeburn 3812: }
3813: } else {
3814: $newaccess->{$tool} = $oldaccess->{$tool};
1.383 raeburn 3815: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3816: if ($newval =~ /^autolimit/) {
3817: if ($limit) {
3818: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3819: } else {
3820: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3821: }
3822: } elsif ($newval) {
3823: $newaccesstext->{$tool} = $reqdisplay{$newval};
3824: } else {
3825: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3826: }
1.275 raeburn 3827: } else {
1.383 raeburn 3828: if ($userenv->{$context.'.'.$tool}) {
3829: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3830: } else {
3831: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3832: }
1.275 raeburn 3833: }
3834: }
3835: } else {
3836: $newaccess->{$tool} = $oldaccess->{$tool};
3837: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
3838: }
3839: } else {
3840: $changed->{$tool} = &tool_admin($tool,'',$changeHash,$context);
3841: if ($changed->{$tool}) {
3842: $newaccess->{$tool} = &mt('default');
3843: } else {
3844: $newaccess->{$tool} = $oldaccess->{$tool};
1.383 raeburn 3845: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3846: if ($newval =~ /^autolimit/) {
3847: if ($limit) {
3848: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3849: } else {
3850: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3851: }
3852: } elsif ($newval) {
3853: $newaccesstext->{$tool} = $reqdisplay{$newval};
3854: } else {
3855: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3856: }
1.275 raeburn 3857: } else {
1.383 raeburn 3858: if ($userenv->{$context.'.'.$tool}) {
3859: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3860: } else {
3861: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3862: }
1.275 raeburn 3863: }
3864: }
3865: }
3866: } else {
3867: $oldaccess->{$tool} = &mt('default');
3868: if ($env{'form.custom'.$tool} == 1) {
1.306 raeburn 3869: $changed->{$tool} = &tool_admin($tool,$newval,$changeHash,
3870: $context);
1.275 raeburn 3871: if ($changed->{$tool}) {
3872: $newaccess->{$tool} = &mt('custom');
1.383 raeburn 3873: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3874: if ($newval =~ /^autolimit/) {
3875: if ($limit) {
3876: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3877: } else {
3878: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3879: }
3880: } elsif ($newval) {
3881: $newaccesstext->{$tool} = $reqdisplay{$newval};
3882: } else {
3883: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3884: }
1.275 raeburn 3885: } else {
1.383 raeburn 3886: if ($newval) {
3887: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3888: } else {
3889: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3890: }
1.275 raeburn 3891: }
3892: } else {
3893: $newaccess->{$tool} = $oldaccess->{$tool};
3894: }
3895: } else {
3896: $newaccess->{$tool} = $oldaccess->{$tool};
3897: }
3898: }
3899: }
3900: return;
3901: }
3902:
1.220 raeburn 3903: sub update_roles {
1.375 raeburn 3904: my ($r,$context,$showcredits) = @_;
1.4 www 3905: my $now=time;
1.225 raeburn 3906: my @rolechanges;
1.220 raeburn 3907: my %disallowed;
1.73 sakharuk 3908: $r->print('<h3>'.&mt('Modifying Roles').'</h3>');
1.404 raeburn 3909: foreach my $key (keys(%env)) {
1.135 raeburn 3910: next if (! $env{$key});
1.190 raeburn 3911: next if ($key eq 'form.action');
1.27 matthew 3912: # Revoke roles
1.135 raeburn 3913: if ($key=~/^form\.rev/) {
3914: if ($key=~/^form\.rev\:([^\_]+)\_([^\_\.]+)$/) {
1.64 www 3915: # Revoke standard role
1.170 albertel 3916: my ($scope,$role) = ($1,$2);
3917: my $result =
3918: &Apache::lonnet::revokerole($env{'form.ccdomain'},
3919: $env{'form.ccuname'},
1.239 raeburn 3920: $scope,$role,'','',$context);
1.367 golterma 3921: $r->print(&Apache::lonhtmlcommon::confirm_success(
1.369 bisitz 3922: &mt('Revoking [_1] in [_2]',
3923: &Apache::lonnet::plaintext($role),
1.372 raeburn 3924: &Apache::loncommon::show_role_extent($scope,$context,$role)),
1.369 bisitz 3925: $result ne "ok").'<br />');
3926: if ($result ne "ok") {
3927: $r->print(&mt('Error: [_1]',$result).'<br />');
3928: }
1.170 albertel 3929: if ($role eq 'st') {
1.202 raeburn 3930: my $result =
1.198 raeburn 3931: &Apache::lonuserutils::classlist_drop($scope,
3932: $env{'form.ccuname'},$env{'form.ccdomain'},
1.202 raeburn 3933: $now);
1.367 golterma 3934: $r->print(&Apache::lonhtmlcommon::confirm_success($result));
1.53 www 3935: }
1.225 raeburn 3936: if (!grep(/^\Q$role\E$/,@rolechanges)) {
3937: push(@rolechanges,$role);
3938: }
1.196 raeburn 3939: }
1.195 raeburn 3940: if ($key=~m{^form\.rev\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}s) {
1.64 www 3941: # Revoke custom role
1.369 bisitz 3942: my $result = &Apache::lonnet::revokecustomrole(
3943: $env{'form.ccdomain'},$env{'form.ccuname'},$1,$2,$3,$4,'','',$context);
1.367 golterma 3944: $r->print(&Apache::lonhtmlcommon::confirm_success(
1.369 bisitz 3945: &mt('Revoking custom role [_1] by [_2] in [_3]',
1.372 raeburn 3946: $4,$3.':'.$2,&Apache::loncommon::show_role_extent($1,$context,'cr')),
1.369 bisitz 3947: $result ne 'ok').'<br />');
3948: if ($result ne "ok") {
3949: $r->print(&mt('Error: [_1]',$result).'<br />');
3950: }
1.225 raeburn 3951: if (!grep(/^cr$/,@rolechanges)) {
3952: push(@rolechanges,'cr');
3953: }
1.64 www 3954: }
1.135 raeburn 3955: } elsif ($key=~/^form\.del/) {
3956: if ($key=~/^form\.del\:([^\_]+)\_([^\_\.]+)$/) {
1.116 raeburn 3957: # Delete standard role
1.170 albertel 3958: my ($scope,$role) = ($1,$2);
3959: my $result =
3960: &Apache::lonnet::assignrole($env{'form.ccdomain'},
3961: $env{'form.ccuname'},
1.239 raeburn 3962: $scope,$role,$now,0,1,'',
3963: $context);
1.367 golterma 3964: $r->print(&Apache::lonhtmlcommon::confirm_success(
3965: &mt('Deleting [_1] in [_2]',
1.369 bisitz 3966: &Apache::lonnet::plaintext($role),
1.372 raeburn 3967: &Apache::loncommon::show_role_extent($scope,$context,$role)),
1.369 bisitz 3968: $result ne 'ok').'<br />');
3969: if ($result ne "ok") {
3970: $r->print(&mt('Error: [_1]',$result).'<br />');
3971: }
1.367 golterma 3972:
1.170 albertel 3973: if ($role eq 'st') {
1.202 raeburn 3974: my $result =
1.198 raeburn 3975: &Apache::lonuserutils::classlist_drop($scope,
3976: $env{'form.ccuname'},$env{'form.ccdomain'},
1.202 raeburn 3977: $now);
1.369 bisitz 3978: $r->print(&Apache::lonhtmlcommon::confirm_success($result));
1.81 albertel 3979: }
1.225 raeburn 3980: if (!grep(/^\Q$role\E$/,@rolechanges)) {
3981: push(@rolechanges,$role);
3982: }
1.116 raeburn 3983: }
1.139 albertel 3984: if ($key=~m{^form\.del\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
1.116 raeburn 3985: my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
3986: # Delete custom role
1.369 bisitz 3987: my $result =
3988: &Apache::lonnet::assigncustomrole($env{'form.ccdomain'},
3989: $env{'form.ccuname'},$url,$rdom,$rnam,$rolename,$now,
3990: 0,1,$context);
3991: $r->print(&Apache::lonhtmlcommon::confirm_success(&mt('Deleting custom role [_1] by [_2] in [_3]',
1.372 raeburn 3992: $rolename,$rnam.':'.$rdom,&Apache::loncommon::show_role_extent($1,$context,'cr')),
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.225 raeburn 3998: if (!grep(/^cr$/,@rolechanges)) {
3999: push(@rolechanges,'cr');
4000: }
1.116 raeburn 4001: }
1.135 raeburn 4002: } elsif ($key=~/^form\.ren/) {
1.101 albertel 4003: my $udom = $env{'form.ccdomain'};
4004: my $uname = $env{'form.ccuname'};
1.116 raeburn 4005: # Re-enable standard role
1.135 raeburn 4006: if ($key=~/^form\.ren\:([^\_]+)\_([^\_\.]+)$/) {
1.89 raeburn 4007: my $url = $1;
4008: my $role = $2;
4009: my $logmsg;
4010: my $output;
4011: if ($role eq 'st') {
1.141 albertel 4012: if ($url =~ m-^/($match_domain)/($match_courseid)/?(\w*)$-) {
1.374 raeburn 4013: my ($cdom,$cnum,$csec) = ($1,$2,$3);
1.375 raeburn 4014: my $credits;
4015: if ($showcredits) {
4016: my $defaultcredits =
4017: &Apache::lonuserutils::get_defaultcredits($cdom,$cnum);
4018: $credits = &get_user_credits($defaultcredits,$cdom,$cnum);
4019: }
4020: my $result = &Apache::loncommon::commit_studentrole(\$logmsg,$udom,$uname,$url,$role,$now,0,$cdom,$cnum,$csec,$context,$credits);
1.220 raeburn 4021: if (($result =~ /^error/) || ($result eq 'not_in_class') || ($result eq 'unknown_course') || ($result eq 'refused')) {
1.223 raeburn 4022: if ($result eq 'refused' && $logmsg) {
4023: $output = $logmsg;
4024: } else {
1.369 bisitz 4025: $output = &mt('Error: [_1]',$result)."\n";
1.223 raeburn 4026: }
1.89 raeburn 4027: } else {
1.372 raeburn 4028: $output = &Apache::lonhtmlcommon::confirm_success(&mt('Assigning [_1] in [_2] starting [_3]',
4029: &Apache::lonnet::plaintext($role),
4030: &Apache::loncommon::show_role_extent($url,$context,'st'),
4031: &Apache::lonlocal::locallocaltime($now))).'<br />'.$logmsg.'<br />';
1.89 raeburn 4032: }
4033: }
4034: } else {
1.101 albertel 4035: my $result=&Apache::lonnet::assignrole($env{'form.ccdomain'},
1.239 raeburn 4036: $env{'form.ccuname'},$url,$role,0,$now,'','',
4037: $context);
1.367 golterma 4038: $output = &Apache::lonhtmlcommon::confirm_success(&mt('Re-enabling [_1] in [_2]',
1.372 raeburn 4039: &Apache::lonnet::plaintext($role),
4040: &Apache::loncommon::show_role_extent($url,$context,$role)),$result ne "ok").'<br />';
1.369 bisitz 4041: if ($result ne "ok") {
4042: $output .= &mt('Error: [_1]',$result).'<br />';
4043: }
4044: }
1.89 raeburn 4045: $r->print($output);
1.225 raeburn 4046: if (!grep(/^\Q$role\E$/,@rolechanges)) {
4047: push(@rolechanges,$role);
4048: }
1.113 raeburn 4049: }
1.116 raeburn 4050: # Re-enable custom role
1.139 albertel 4051: if ($key=~m{^form\.ren\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
1.116 raeburn 4052: my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
4053: my $result = &Apache::lonnet::assigncustomrole(
4054: $env{'form.ccdomain'}, $env{'form.ccuname'},
1.240 raeburn 4055: $url,$rdom,$rnam,$rolename,0,$now,undef,$context);
1.369 bisitz 4056: $r->print(&Apache::lonhtmlcommon::confirm_success(
4057: &mt('Re-enabling custom role [_1] by [_2] in [_3]',
1.372 raeburn 4058: $rolename,$rnam.':'.$rdom,&Apache::loncommon::show_role_extent($1,$context,'cr')),
1.369 bisitz 4059: $result ne "ok").'<br />');
4060: if ($result ne "ok") {
4061: $r->print(&mt('Error: [_1]',$result).'<br />');
4062: }
1.225 raeburn 4063: if (!grep(/^cr$/,@rolechanges)) {
4064: push(@rolechanges,'cr');
4065: }
1.116 raeburn 4066: }
1.135 raeburn 4067: } elsif ($key=~/^form\.act/) {
1.101 albertel 4068: my $udom = $env{'form.ccdomain'};
4069: my $uname = $env{'form.ccuname'};
1.141 albertel 4070: if ($key=~/^form\.act\_($match_domain)\_($match_courseid)\_cr_cr_($match_domain)_($match_username)_([^\_]+)$/) {
1.65 www 4071: # Activate a custom role
1.83 albertel 4072: my ($one,$two,$three,$four,$five)=($1,$2,$3,$4,$5);
4073: my $url='/'.$one.'/'.$two;
4074: my $full=$one.'_'.$two.'_cr_cr_'.$three.'_'.$four.'_'.$five;
1.65 www 4075:
1.101 albertel 4076: my $start = ( $env{'form.start_'.$full} ?
4077: $env{'form.start_'.$full} :
1.88 raeburn 4078: $now );
1.101 albertel 4079: my $end = ( $env{'form.end_'.$full} ?
4080: $env{'form.end_'.$full} :
1.88 raeburn 4081: 0 );
4082:
4083: # split multiple sections
4084: my %sections = ();
1.101 albertel 4085: my $num_sections = &build_roles($env{'form.sec_'.$full},\%sections,$5);
1.88 raeburn 4086: if ($num_sections == 0) {
1.240 raeburn 4087: $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$url,$three,$four,$five,$start,$end,$context));
1.88 raeburn 4088: } else {
1.114 albertel 4089: my %curr_groups =
1.117 raeburn 4090: &Apache::longroup::coursegroups($one,$two);
1.404 raeburn 4091: foreach my $sec (sort {$a cmp $b} keys(%sections)) {
1.113 raeburn 4092: if (($sec eq 'none') || ($sec eq 'all') ||
4093: exists($curr_groups{$sec})) {
4094: $disallowed{$sec} = $url;
4095: next;
4096: }
4097: my $securl = $url.'/'.$sec;
1.240 raeburn 4098: $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$securl,$three,$four,$five,$start,$end,$context));
1.88 raeburn 4099: }
4100: }
1.225 raeburn 4101: if (!grep(/^cr$/,@rolechanges)) {
4102: push(@rolechanges,'cr');
4103: }
1.142 raeburn 4104: } elsif ($key=~/^form\.act\_($match_domain)\_($match_name)\_([^\_]+)$/) {
1.27 matthew 4105: # Activate roles for sections with 3 id numbers
4106: # set start, end times, and the url for the class
1.83 albertel 4107: my ($one,$two,$three)=($1,$2,$3);
1.101 albertel 4108: my $start = ( $env{'form.start_'.$one.'_'.$two.'_'.$three} ?
4109: $env{'form.start_'.$one.'_'.$two.'_'.$three} :
1.27 matthew 4110: $now );
1.101 albertel 4111: my $end = ( $env{'form.end_'.$one.'_'.$two.'_'.$three} ?
4112: $env{'form.end_'.$one.'_'.$two.'_'.$three} :
1.27 matthew 4113: 0 );
1.83 albertel 4114: my $url='/'.$one.'/'.$two;
1.88 raeburn 4115: my $type = 'three';
4116: # split multiple sections
4117: my %sections = ();
1.101 albertel 4118: my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two.'_'.$three},\%sections,$three);
1.375 raeburn 4119: my $credits;
4120: if ($three eq 'st') {
4121: if ($showcredits) {
4122: my $defaultcredits =
4123: &Apache::lonuserutils::get_defaultcredits($one,$two);
4124: $credits = $env{'form.credits_'.$one.'_'.$two.'_'.$three};
4125: $credits =~ s/[^\d\.]//g;
4126: if ($credits eq $defaultcredits) {
4127: undef($credits);
4128: }
4129: }
4130: }
1.88 raeburn 4131: if ($num_sections == 0) {
1.375 raeburn 4132: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'',$context,$credits));
1.88 raeburn 4133: } else {
1.114 albertel 4134: my %curr_groups =
1.117 raeburn 4135: &Apache::longroup::coursegroups($one,$two);
1.88 raeburn 4136: my $emptysec = 0;
1.404 raeburn 4137: foreach my $sec (sort {$a cmp $b} keys(%sections)) {
1.88 raeburn 4138: $sec =~ s/\W//g;
1.113 raeburn 4139: if ($sec ne '') {
4140: if (($sec eq 'none') || ($sec eq 'all') ||
4141: exists($curr_groups{$sec})) {
4142: $disallowed{$sec} = $url;
4143: next;
4144: }
1.88 raeburn 4145: my $securl = $url.'/'.$sec;
1.375 raeburn 4146: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$three,$start,$end,$one,$two,$sec,$context,$credits));
1.88 raeburn 4147: } else {
4148: $emptysec = 1;
4149: }
4150: }
4151: if ($emptysec) {
1.375 raeburn 4152: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'',$context,$credits));
1.88 raeburn 4153: }
1.225 raeburn 4154: }
4155: if (!grep(/^\Q$three\E$/,@rolechanges)) {
4156: push(@rolechanges,$three);
4157: }
1.135 raeburn 4158: } elsif ($key=~/^form\.act\_([^\_]+)\_([^\_]+)$/) {
1.27 matthew 4159: # Activate roles for sections with two id numbers
4160: # set start, end times, and the url for the class
1.101 albertel 4161: my $start = ( $env{'form.start_'.$1.'_'.$2} ?
4162: $env{'form.start_'.$1.'_'.$2} :
1.27 matthew 4163: $now );
1.101 albertel 4164: my $end = ( $env{'form.end_'.$1.'_'.$2} ?
4165: $env{'form.end_'.$1.'_'.$2} :
1.27 matthew 4166: 0 );
1.225 raeburn 4167: my $one = $1;
4168: my $two = $2;
4169: my $url='/'.$one.'/';
1.88 raeburn 4170: # split multiple sections
4171: my %sections = ();
1.225 raeburn 4172: my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two},\%sections,$two);
1.88 raeburn 4173: if ($num_sections == 0) {
1.240 raeburn 4174: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,'',$context));
1.88 raeburn 4175: } else {
4176: my $emptysec = 0;
1.404 raeburn 4177: foreach my $sec (sort {$a cmp $b} keys(%sections)) {
1.88 raeburn 4178: if ($sec ne '') {
4179: my $securl = $url.'/'.$sec;
1.240 raeburn 4180: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$two,$start,$end,$one,undef,$sec,$context));
1.88 raeburn 4181: } else {
4182: $emptysec = 1;
4183: }
4184: }
4185: if ($emptysec) {
1.240 raeburn 4186: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,'',$context));
1.88 raeburn 4187: }
4188: }
1.225 raeburn 4189: if (!grep(/^\Q$two\E$/,@rolechanges)) {
4190: push(@rolechanges,$two);
4191: }
1.64 www 4192: } else {
1.190 raeburn 4193: $r->print('<p><span class="LC_error">'.&mt('ERROR').': '.&mt('Unknown command').' <tt>'.$key.'</tt></span></p><br />');
1.64 www 4194: }
1.113 raeburn 4195: foreach my $key (sort(keys(%disallowed))) {
1.274 bisitz 4196: $r->print('<p class="LC_warning">');
1.113 raeburn 4197: if (($key eq 'none') || ($key eq 'all')) {
1.274 bisitz 4198: $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 4199: } else {
1.274 bisitz 4200: $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 4201: }
1.274 bisitz 4202: $r->print('</p><p>'
4203: .&mt('Please [_1]go back[_2] and choose a different section name.'
4204: ,'<a href="javascript:history.go(-1)'
4205: ,'</a>')
4206: .'</p><br />'
4207: );
1.113 raeburn 4208: }
4209: }
1.101 albertel 4210: } # End of foreach (keys(%env))
1.75 www 4211: # Flush the course logs so reverse user roles immediately updated
1.349 raeburn 4212: $r->register_cleanup(\&Apache::lonnet::flushcourselogs);
1.225 raeburn 4213: if (@rolechanges == 0) {
1.372 raeburn 4214: $r->print('<p>'.&mt('No roles to modify').'</p>');
1.193 raeburn 4215: }
1.225 raeburn 4216: return @rolechanges;
1.220 raeburn 4217: }
4218:
1.375 raeburn 4219: sub get_user_credits {
4220: my ($uname,$udom,$defaultcredits,$cdom,$cnum) = @_;
4221: if ($cdom eq '' || $cnum eq '') {
4222: return unless ($env{'request.course.id'});
4223: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
4224: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
4225: }
4226: my $credits;
4227: my %currhash =
4228: &Apache::lonnet::get('classlist',[$uname.':'.$udom],$cdom,$cnum);
4229: if (keys(%currhash) > 0) {
4230: my @items = split(/:/,$currhash{$uname.':'.$udom});
4231: my $crdidx = &Apache::loncoursedata::CL_CREDITS() - 3;
4232: $credits = $items[$crdidx];
4233: $credits =~ s/[^\d\.]//g;
4234: }
4235: if ($credits eq $defaultcredits) {
4236: undef($credits);
4237: }
4238: return $credits;
4239: }
4240:
1.220 raeburn 4241: sub enroll_single_student {
1.375 raeburn 4242: my ($r,$uhome,$amode,$genpwd,$now,$newuser,$context,$crstype,
4243: $showcredits,$defaultcredits) = @_;
1.318 raeburn 4244: $r->print('<h3>');
4245: if ($crstype eq 'Community') {
4246: $r->print(&mt('Enrolling Member'));
4247: } else {
4248: $r->print(&mt('Enrolling Student'));
4249: }
4250: $r->print('</h3>');
1.220 raeburn 4251:
4252: # Remove non alphanumeric values from section
4253: $env{'form.sections'}=~s/\W//g;
4254:
1.375 raeburn 4255: my $credits;
4256: if (($showcredits) && ($env{'form.credits'} ne '')) {
4257: $credits = $env{'form.credits'};
4258: $credits =~ s/[^\d\.]//g;
4259: if ($credits ne '') {
4260: if ($credits eq $defaultcredits) {
4261: undef($credits);
4262: }
4263: }
4264: }
4265:
1.220 raeburn 4266: # Clean out any old student roles the user has in this class.
4267: &Apache::lonuserutils::modifystudent($env{'form.ccdomain'},
4268: $env{'form.ccuname'},$env{'request.course.id'},undef,$uhome);
4269: my ($startdate,$enddate) = &Apache::lonuserutils::get_dates_from_form();
4270: my $enroll_result =
4271: &Apache::lonnet::modify_student_enrollment($env{'form.ccdomain'},
4272: $env{'form.ccuname'},$env{'form.cid'},$env{'form.cfirstname'},
4273: $env{'form.cmiddlename'},$env{'form.clastname'},
4274: $env{'form.generation'},$env{'form.sections'},$enddate,
1.375 raeburn 4275: $startdate,'manual',undef,$env{'request.course.id'},'',$context,
4276: $credits);
1.220 raeburn 4277: if ($enroll_result =~ /^ok/) {
1.381 bisitz 4278: $r->print(&mt('[_1] enrolled','<b>'.$env{'form.ccuname'}.':'.$env{'form.ccdomain'}.'</b>'));
1.220 raeburn 4279: if ($env{'form.sections'} ne '') {
4280: $r->print(' '.&mt('in section [_1]',$env{'form.sections'}));
4281: }
4282: my ($showstart,$showend);
4283: if ($startdate <= $now) {
4284: $showstart = &mt('Access starts immediately');
4285: } else {
4286: $showstart = &mt('Access starts: ').&Apache::lonlocal::locallocaltime($startdate);
4287: }
4288: if ($enddate == 0) {
4289: $showend = &mt('ends: no ending date');
4290: } else {
4291: $showend = &mt('ends: ').&Apache::lonlocal::locallocaltime($enddate);
4292: }
4293: $r->print('.<br />'.$showstart.'; '.$showend);
4294: if ($startdate <= $now && !$newuser) {
1.386 bisitz 4295: $r->print('<p class="LC_info">');
1.318 raeburn 4296: if ($crstype eq 'Community') {
1.392 raeburn 4297: $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 4298: } else {
1.392 raeburn 4299: $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 4300: }
4301: $r->print('</p>');
1.220 raeburn 4302: }
4303: } else {
4304: $r->print(&mt('unable to enroll').": ".$enroll_result);
4305: }
4306: return;
1.188 raeburn 4307: }
4308:
1.204 raeburn 4309: sub get_defaultquota_text {
4310: my ($settingstatus) = @_;
4311: my $defquotatext;
4312: if ($settingstatus eq '') {
1.383 raeburn 4313: $defquotatext = &mt('default');
1.204 raeburn 4314: } else {
4315: my ($usertypes,$order) =
4316: &Apache::lonnet::retrieve_inst_usertypes($env{'form.ccdomain'});
4317: if ($usertypes->{$settingstatus} eq '') {
1.383 raeburn 4318: $defquotatext = &mt('default');
1.204 raeburn 4319: } else {
1.383 raeburn 4320: $defquotatext = &mt('default for [_1]',$usertypes->{$settingstatus});
1.204 raeburn 4321: }
4322: }
4323: return $defquotatext;
4324: }
4325:
1.188 raeburn 4326: sub update_result_form {
4327: my ($uhome) = @_;
4328: my $outcome =
1.367 golterma 4329: '<form name="userupdate" method="post" action="">'."\n";
1.160 raeburn 4330: foreach my $item ('srchby','srchin','srchtype','srchterm','srchdomain','ccuname','ccdomain') {
1.188 raeburn 4331: $outcome .= '<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n";
1.160 raeburn 4332: }
1.207 raeburn 4333: if ($env{'form.origname'} ne '') {
4334: $outcome .= '<input type="hidden" name="origname" value="'.$env{'form.origname'}.'" />'."\n";
4335: }
1.160 raeburn 4336: foreach my $item ('sortby','seluname','seludom') {
4337: if (exists($env{'form.'.$item})) {
1.188 raeburn 4338: $outcome .= '<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n";
1.160 raeburn 4339: }
4340: }
1.188 raeburn 4341: if ($uhome eq 'no_host') {
4342: $outcome .= '<input type="hidden" name="forcenewuser" value="1" />'."\n";
4343: }
4344: $outcome .= '<input type="hidden" name="phase" value="" />'."\n".
1.383 raeburn 4345: '<input type="hidden" name="currstate" value="" />'."\n".
4346: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n".
1.188 raeburn 4347: '</form>';
4348: return $outcome;
1.4 www 4349: }
4350:
1.149 raeburn 4351: sub quota_admin {
1.378 raeburn 4352: my ($setquota,$changeHash,$name) = @_;
1.149 raeburn 4353: my $quotachanged;
4354: if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
4355: # Current user has quota modification privileges
1.267 raeburn 4356: if (ref($changeHash) eq 'HASH') {
4357: $quotachanged = 1;
1.378 raeburn 4358: $changeHash->{$name.'quota'} = $setquota;
1.267 raeburn 4359: }
1.149 raeburn 4360: }
4361: return $quotachanged;
4362: }
4363:
1.267 raeburn 4364: sub tool_admin {
1.275 raeburn 4365: my ($tool,$settool,$changeHash,$context) = @_;
4366: my $canchange = 0;
1.279 raeburn 4367: if ($context eq 'requestcourses') {
1.275 raeburn 4368: if (&Apache::lonnet::allowed('ccc',$env{'form.ccdomain'})) {
4369: $canchange = 1;
4370: }
1.300 raeburn 4371: } elsif ($context eq 'reqcrsotherdom') {
4372: if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
4373: $canchange = 1;
4374: }
1.362 raeburn 4375: } elsif ($context eq 'requestauthor') {
4376: if (&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) {
4377: $canchange = 1;
4378: }
1.275 raeburn 4379: } elsif (&Apache::lonnet::allowed('mut',$env{'form.ccdomain'})) {
4380: # Current user has quota modification privileges
4381: $canchange = 1;
4382: }
1.267 raeburn 4383: my $toolchanged;
1.275 raeburn 4384: if ($canchange) {
1.267 raeburn 4385: if (ref($changeHash) eq 'HASH') {
4386: $toolchanged = 1;
1.362 raeburn 4387: if ($tool eq 'requestauthor') {
4388: $changeHash->{$context} = $settool;
4389: } else {
4390: $changeHash->{$context.'.'.$tool} = $settool;
4391: }
1.267 raeburn 4392: }
4393: }
4394: return $toolchanged;
4395: }
4396:
1.88 raeburn 4397: sub build_roles {
1.89 raeburn 4398: my ($sectionstr,$sections,$role) = @_;
1.88 raeburn 4399: my $num_sections = 0;
4400: if ($sectionstr=~ /,/) {
4401: my @secnums = split/,/,$sectionstr;
1.89 raeburn 4402: if ($role eq 'st') {
4403: $secnums[0] =~ s/\W//g;
4404: $$sections{$secnums[0]} = 1;
4405: $num_sections = 1;
4406: } else {
4407: foreach my $sec (@secnums) {
4408: $sec =~ ~s/\W//g;
1.150 banghart 4409: if (!($sec eq "")) {
1.89 raeburn 4410: if (exists($$sections{$sec})) {
4411: $$sections{$sec} ++;
4412: } else {
4413: $$sections{$sec} = 1;
4414: $num_sections ++;
4415: }
1.88 raeburn 4416: }
4417: }
4418: }
4419: } else {
4420: $sectionstr=~s/\W//g;
4421: unless ($sectionstr eq '') {
4422: $$sections{$sectionstr} = 1;
4423: $num_sections ++;
4424: }
4425: }
1.129 albertel 4426:
1.88 raeburn 4427: return $num_sections;
4428: }
4429:
1.58 www 4430: # ========================================================== Custom Role Editor
4431:
4432: sub custom_role_editor {
1.406.2.14 raeburn 4433: my ($r,$context,$brcrum,$prefix,$permission) = @_;
1.324 raeburn 4434: my $action = $env{'form.customroleaction'};
1.406.2.14 raeburn 4435: my ($rolename,$helpitem);
1.324 raeburn 4436: if ($action eq 'new') {
4437: $rolename=$env{'form.newrolename'};
4438: } else {
4439: $rolename=$env{'form.rolename'};
1.59 www 4440: }
4441:
1.324 raeburn 4442: my ($crstype,$context);
4443: if ($env{'request.course.id'}) {
4444: $crstype = &Apache::loncommon::course_type();
4445: $context = 'course';
1.406.2.14 raeburn 4446: $helpitem = 'Course_Editing_Custom_Roles';
1.324 raeburn 4447: } else {
4448: $context = 'domain';
1.406.2.5 raeburn 4449: $crstype = 'course';
1.406.2.14 raeburn 4450: $helpitem = 'Domain_Editing_Custom_Roles';
1.324 raeburn 4451: }
1.351 raeburn 4452:
4453: $rolename=~s/[^A-Za-z0-9]//gs;
4454: if (!$rolename || $env{'form.phase'} eq 'pickrole') {
1.406.2.14 raeburn 4455: &print_username_entry_form($r,$context,undef,undef,undef,$crstype,$brcrum,
4456: $permission);
1.351 raeburn 4457: return;
4458: }
4459:
1.406.2.5 raeburn 4460: my $formname = 'form1';
4461: my %privs=();
4462: my $body_top = '<h2>';
4463: # ------------------------------------------------------- Does this role exist?
1.59 www 4464: my ($rdummy,$roledef)=
4465: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
4466: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1.406.2.5 raeburn 4467: $body_top .= &mt('Existing Role').' "';
1.61 www 4468: # ------------------------------------------------- Get current role privileges
1.406.2.5 raeburn 4469: ($privs{'system'},$privs{'domain'},$privs{'course'})=split(/\_/,$roledef);
4470: if ($privs{'system'} =~ /bre\&S/) {
4471: if ($context eq 'domain') {
4472: $crstype = 'Course';
4473: } elsif ($crstype eq 'Community') {
4474: $privs{'system'} =~ s/bre\&S//;
4475: }
4476: } elsif ($context eq 'domain') {
4477: $crstype = 'Course';
1.324 raeburn 4478: }
1.59 www 4479: } else {
1.406.2.5 raeburn 4480: $body_top .= &mt('New Role').' "';
4481: $roledef='';
1.59 www 4482: }
1.153 banghart 4483: $body_top .= $rolename.'"</h2>';
1.406.2.5 raeburn 4484:
4485: # ------------------------------------------------------- What can be assigned?
4486: my %full=();
4487: my %levels=(
4488: course => {},
4489: domain => {},
4490: system => {},
4491: );
4492: my %levelscurrent=(
4493: course => {},
4494: domain => {},
4495: system => {},
4496: );
4497: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
1.160 raeburn 4498: my ($jsback,$elements) = &crumb_utilities();
1.406.2.5 raeburn 4499: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
4500: my $head_script =
4501: &Apache::lonuserutils::custom_roledefs_js($context,$crstype,$formname,
4502: \%full,\@templateroles,$jsback);
1.351 raeburn 4503: push (@{$brcrum},
1.406.2.5 raeburn 4504: {href => "javascript:backPage(document.$formname,'pickrole','')",
1.351 raeburn 4505: text => "Pick custom role",
4506: faq => 282,bug=>'Instructor Interface',},
1.406.2.5 raeburn 4507: {href => "javascript:backPage(document.$formname,'','')",
1.351 raeburn 4508: text => "Edit custom role",
4509: faq => 282,
4510: bug => 'Instructor Interface',
1.406.2.14 raeburn 4511: help => $helpitem}
1.351 raeburn 4512: );
4513: my $args = { bread_crumbs => $brcrum,
4514: bread_crumbs_component => 'User Management'};
4515: $r->print(&Apache::loncommon::start_page('Custom Role Editor',
4516: $head_script,$args).
4517: $body_top);
1.406.2.5 raeburn 4518: $r->print('<form name="'.$formname.'" method="post" action="">'."\n".
4519: &Apache::lonuserutils::custom_role_header($context,$crstype,
4520: \@templateroles,$prefix));
1.264 bisitz 4521:
1.61 www 4522: $r->print(<<ENDCCF);
4523: <input type="hidden" name="phase" value="set_custom_roles" />
4524: <input type="hidden" name="rolename" value="$rolename" />
4525: ENDCCF
1.406.2.5 raeburn 4526: $r->print(&Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
4527: \%levelscurrent,$prefix));
1.135 raeburn 4528: $r->print(&Apache::loncommon::end_data_table().
1.190 raeburn 4529: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'.
1.160 raeburn 4530: '<input type="hidden" name="startrolename" value="'.$env{'form.rolename'}.
1.406.2.5 raeburn 4531: '" />'."\n".'<input type="hidden" name="currstate" value="" />'."\n".
1.160 raeburn 4532: '<input type="reset" value="'.&mt("Reset").'" />'."\n".
1.351 raeburn 4533: '<input type="submit" value="'.&mt('Save').'" /></form>');
1.61 www 4534: }
1.406.2.5 raeburn 4535:
1.61 www 4536: # ---------------------------------------------------------- Call to definerole
4537: sub set_custom_role {
1.406.2.14 raeburn 4538: my ($r,$context,$brcrum,$prefix,$permission) = @_;
1.101 albertel 4539: my $rolename=$env{'form.rolename'};
1.63 www 4540: $rolename=~s/[^A-Za-z0-9]//gs;
1.150 banghart 4541: if (!$rolename) {
1.406.2.14 raeburn 4542: &custom_role_editor($r,$context,$brcrum,$prefix,$permission);
1.61 www 4543: return;
4544: }
1.160 raeburn 4545: my ($jsback,$elements) = &crumb_utilities();
1.301 bisitz 4546: my $jscript = '<script type="text/javascript">'
4547: .'// <![CDATA['."\n"
4548: .$jsback."\n"
4549: .'// ]]>'."\n"
4550: .'</script>'."\n";
1.406.2.14 raeburn 4551: my $helpitem = 'Course_Editing_Custom_Roles';
4552: if ($context eq 'domain') {
4553: $helpitem = 'Domain_Editing_Custom_Roles';
4554: }
1.352 raeburn 4555: push(@{$brcrum},
4556: {href => "javascript:backPage(document.customresult,'pickrole','')",
4557: text => "Pick custom role",
4558: faq => 282,
4559: bug => 'Instructor Interface',},
4560: {href => "javascript:backPage(document.customresult,'selected_custom_edit','')",
4561: text => "Edit custom role",
4562: faq => 282,
4563: bug => 'Instructor Interface',},
4564: {href => "javascript:backPage(document.customresult,'set_custom_roles','')",
4565: text => "Result",
4566: faq => 282,
4567: bug => 'Instructor Interface',
1.406.2.14 raeburn 4568: help => $helpitem,}
1.352 raeburn 4569: );
4570: my $args = { bread_crumbs => $brcrum,
1.406.2.5 raeburn 4571: bread_crumbs_component => 'User Management'};
1.351 raeburn 4572: $r->print(&Apache::loncommon::start_page('Save Custom Role',$jscript,$args));
1.160 raeburn 4573:
1.393 raeburn 4574: my $newrole;
1.61 www 4575: my ($rdummy,$roledef)=
1.110 albertel 4576: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
4577:
1.61 www 4578: # ------------------------------------------------------- Does this role exist?
1.188 raeburn 4579: $r->print('<h3>');
1.61 www 4580: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1.73 sakharuk 4581: $r->print(&mt('Existing Role').' "');
1.61 www 4582: } else {
1.73 sakharuk 4583: $r->print(&mt('New Role').' "');
1.61 www 4584: $roledef='';
1.393 raeburn 4585: $newrole = 1;
1.61 www 4586: }
1.188 raeburn 4587: $r->print($rolename.'"</h3>');
1.406.2.5 raeburn 4588: # ------------------------------------------------- Assign role and show result
1.61 www 4589:
1.387 bisitz 4590: my $errmsg;
1.406.2.5 raeburn 4591: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$prefix);
4592: # Assign role and return result
4593: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
4594: $newprivs{'c'});
1.387 bisitz 4595: if ($result ne 'ok') {
4596: $errmsg = ': '.$result;
4597: }
4598: my $message =
4599: &Apache::lonhtmlcommon::confirm_success(
4600: &mt('Defining Role').$errmsg, ($result eq 'ok' ? 0 : 1));
1.101 albertel 4601: if ($env{'request.course.id'}) {
4602: my $url='/'.$env{'request.course.id'};
1.63 www 4603: $url=~s/\_/\//g;
1.387 bisitz 4604: $result =
4605: &Apache::lonnet::assigncustomrole(
4606: $env{'user.domain'},$env{'user.name'},
4607: $url,
4608: $env{'user.domain'},$env{'user.name'},
4609: $rolename,undef,undef,undef,$context);
4610: if ($result ne 'ok') {
4611: $errmsg = ': '.$result;
4612: }
4613: $message .=
4614: '<br />'
4615: .&Apache::lonhtmlcommon::confirm_success(
4616: &mt('Assigning Role to Self').$errmsg, ($result eq 'ok' ? 0 : 1));
1.63 www 4617: }
1.380 bisitz 4618: $r->print(
1.387 bisitz 4619: &Apache::loncommon::confirmwrapper($message)
4620: .'<br />'
4621: .&Apache::lonhtmlcommon::actionbox([
4622: '<a href="javascript:backPage(document.customresult,'."'pickrole'".')">'
4623: .&mt('Create or edit another custom role')
4624: .'</a>'])
1.380 bisitz 4625: .'<form name="customresult" method="post" action="">'
1.387 bisitz 4626: .&Apache::lonhtmlcommon::echo_form_input([])
4627: .'</form>'
1.380 bisitz 4628: );
1.58 www 4629: }
4630:
1.2 www 4631: # ================================================================ Main Handler
4632: sub handler {
4633: my $r = shift;
4634: if ($r->header_only) {
1.68 www 4635: &Apache::loncommon::content_type($r,'text/html');
1.2 www 4636: $r->send_http_header;
4637: return OK;
4638: }
1.406.2.14 raeburn 4639: my ($context,$crstype,$cid,$cnum,$cdom,$allhelpitems);
4640:
1.190 raeburn 4641: if ($env{'request.course.id'}) {
4642: $context = 'course';
1.318 raeburn 4643: $crstype = &Apache::loncommon::course_type();
1.190 raeburn 4644: } elsif ($env{'request.role'} =~ /^au\./) {
1.206 raeburn 4645: $context = 'author';
1.190 raeburn 4646: } else {
4647: $context = 'domain';
4648: }
1.375 raeburn 4649:
1.406.2.14 raeburn 4650: my ($permission,$allowed) =
4651: &Apache::lonuserutils::get_permission($context,$crstype);
4652:
4653: if ($allowed) {
4654: my @allhelp;
4655: if ($context eq 'course') {
4656: $cid = $env{'request.course.id'};
4657: $cdom = $env{'course.'.$cid.'.domain'};
4658: $cnum = $env{'course.'.$cid.'.num'};
4659:
4660: if ($permission->{'cusr'}) {
4661: push(@allhelp,'Course_Create_Class_List');
4662: }
4663: if ($permission->{'view'} || $permission->{'cusr'}) {
4664: push(@allhelp,('Course_Change_Privileges','Course_View_Class_List'));
4665: }
4666: if ($permission->{'custom'}) {
4667: push(@allhelp,'Course_Editing_Custom_Roles');
4668: }
4669: if ($permission->{'cusr'}) {
4670: push(@allhelp,('Course_Add_Student','Course_Drop_Student'));
4671: }
4672: unless ($permission->{'cusr_section'}) {
4673: if (&Apache::lonnet::auto_run($cnum,$cdom) && (($permission->{'cusr'}) || ($permission->{'view'}))) {
4674: push(@allhelp,'Course_Automated_Enrollment');
4675: }
4676: if ($permission->{'selfenrolladmin'}) {
4677: push(@allhelp,'Course_Approve_Selfenroll');
4678: }
4679: }
4680: if ($permission->{'grp_manage'}) {
4681: push(@allhelp,'Course_Manage_Group');
4682: }
4683: if ($permission->{'view'} || $permission->{'cusr'}) {
4684: push(@allhelp,'Course_User_Logs');
4685: }
4686: } elsif ($context eq 'author') {
4687: push(@allhelp,('Author_Change_Privileges','Author_Create_Coauthor_List',
4688: 'Author_View_Coauthor_List','Author_User_Logs'));
4689: } else {
4690: if ($permission->{'cusr'}) {
4691: push(@allhelp,'Domain_Change_Privileges');
4692: if ($permission->{'activity'}) {
4693: push(@allhelp,'Domain_User_Access_Logs');
4694: }
4695: push(@allhelp,('Domain_Create_Users','Domain_View_Users_List'));
4696: if ($permission->{'custom'}) {
4697: push(@allhelp,'Domain_Editing_Custom_Roles');
4698: }
4699: push(@allhelp,('Domain_Role_Approvals','Domain_Username_Approvals','Domain_Change_Logs'));
4700: } elsif ($permission->{'view'}) {
4701: push(@allhelp,'Domain_View_Privileges');
4702: if ($permission->{'activity'}) {
4703: push(@allhelp,'Domain_User_Access_Logs');
4704: }
4705: push(@allhelp,('Domain_View_Users_List','Domain_Change_Logs'));
4706: }
4707: }
4708: if (@allhelp) {
4709: $allhelpitems = join(',',@allhelp);
4710: }
4711: }
4712:
1.190 raeburn 4713: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.233 raeburn 4714: ['action','state','callingform','roletype','showrole','bulkaction','popup','phase',
1.391 raeburn 4715: 'username','domain','srchterm','srchdomain','srchin','srchby','srchtype','queue']);
1.190 raeburn 4716: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.351 raeburn 4717: my $args;
4718: my $brcrum = [];
4719: my $bread_crumbs_component = 'User Management';
1.391 raeburn 4720: if (($env{'form.action'} ne 'dateselect') && ($env{'form.action'} ne 'displayuserreq')) {
1.351 raeburn 4721: $brcrum = [{href=>"/adm/createuser",
4722: text=>"User Management",
1.406.2.14 raeburn 4723: help=>$allhelpitems}
1.351 raeburn 4724: ];
1.202 raeburn 4725: }
1.190 raeburn 4726: if (!$allowed) {
1.358 raeburn 4727: if ($context eq 'course') {
4728: $r->internal_redirect('/adm/viewclasslist');
4729: return OK;
4730: }
1.190 raeburn 4731: $env{'user.error.msg'}=
4732: "/adm/createuser:cst:0:0:Cannot create/modify user data ".
4733: "or view user status.";
4734: return HTTP_NOT_ACCEPTABLE;
4735: }
4736:
4737: &Apache::loncommon::content_type($r,'text/html');
4738: $r->send_http_header;
4739:
1.375 raeburn 4740: my $showcredits;
4741: if ((($context eq 'course') && ($crstype eq 'Course')) ||
4742: ($context eq 'domain')) {
4743: my %domdefaults =
4744: &Apache::lonnet::get_domain_defaults($env{'request.role.domain'});
4745: if ($domdefaults{'officialcredits'} || $domdefaults{'unofficialcredits'}) {
4746: $showcredits = 1;
4747: }
4748: }
4749:
1.190 raeburn 4750: # Main switch on form.action and form.state, as appropriate
4751: if (! exists($env{'form.action'})) {
1.351 raeburn 4752: $args = {bread_crumbs => $brcrum,
4753: bread_crumbs_component => $bread_crumbs_component};
4754: $r->print(&header(undef,$args));
1.318 raeburn 4755: $r->print(&print_main_menu($permission,$context,$crstype));
1.190 raeburn 4756: } elsif ($env{'form.action'} eq 'upload' && $permission->{'cusr'}) {
1.406.2.14 raeburn 4757: my $helpitem = 'Course_Create_Class_List';
4758: if ($context eq 'author') {
4759: $helpitem = 'Author_Create_Coauthor_List';
4760: } elsif ($context eq 'domain') {
4761: $helpitem = 'Domain_Create_Users';
4762: }
1.351 raeburn 4763: push(@{$brcrum},
4764: { href => '/adm/createuser?action=upload&state=',
4765: text => 'Upload Users List',
1.406.2.14 raeburn 4766: help => $helpitem,
1.351 raeburn 4767: });
4768: $bread_crumbs_component = 'Upload Users List';
4769: $args = {bread_crumbs => $brcrum,
4770: bread_crumbs_component => $bread_crumbs_component};
4771: $r->print(&header(undef,$args));
1.190 raeburn 4772: $r->print('<form name="studentform" method="post" '.
4773: 'enctype="multipart/form-data" '.
4774: ' action="/adm/createuser">'."\n");
4775: if (! exists($env{'form.state'})) {
4776: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
4777: } elsif ($env{'form.state'} eq 'got_file') {
1.406.2.15 raeburn 4778: my $result =
4779: &Apache::lonuserutils::print_upload_manager_form($r,$context,
4780: $permission,
4781: $crstype,$showcredits);
4782: if ($result eq 'missingdata') {
4783: delete($env{'form.state'});
4784: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
4785: }
1.190 raeburn 4786: } elsif ($env{'form.state'} eq 'enrolling') {
4787: if ($env{'form.datatoken'}) {
1.406.2.15 raeburn 4788: my $result = &Apache::lonuserutils::upfile_drop_add($r,$context,
4789: $permission,
4790: $showcredits);
4791: if ($result eq 'missingdata') {
4792: delete($env{'form.state'});
4793: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
4794: } elsif ($result eq 'invalidhome') {
4795: $env{'form.state'} = 'got_file';
4796: delete($env{'form.lcserver'});
4797: my $result =
4798: &Apache::lonuserutils::print_upload_manager_form($r,$context,$permission,
4799: $crstype,$showcredits);
4800: if ($result eq 'missingdata') {
4801: delete($env{'form.state'});
4802: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
4803: }
4804: }
4805: } else {
4806: delete($env{'form.state'});
4807: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
1.190 raeburn 4808: }
4809: } else {
4810: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
4811: }
1.406.2.15 raeburn 4812: $r->print('</form>');
1.406.2.5 raeburn 4813: } elsif (((($env{'form.action'} eq 'singleuser') || ($env{'form.action'}
4814: eq 'singlestudent')) && ($permission->{'cusr'})) ||
1.406.2.6 raeburn 4815: (($env{'form.action'} eq 'singleuser') && ($permission->{'view'})) ||
1.406.2.5 raeburn 4816: (($env{'form.action'} eq 'accesslogs') && ($permission->{'activity'}))) {
1.190 raeburn 4817: my $phase = $env{'form.phase'};
4818: my @search = ('srchterm','srchby','srchin','srchtype','srchdomain');
1.192 albertel 4819: &Apache::loncreateuser::restore_prev_selections();
4820: my $srch;
4821: foreach my $item (@search) {
4822: $srch->{$item} = $env{'form.'.$item};
4823: }
1.207 raeburn 4824: if (($phase eq 'get_user_info') || ($phase eq 'userpicked') ||
1.406.2.5 raeburn 4825: ($phase eq 'createnewuser') || ($phase eq 'activity')) {
1.207 raeburn 4826: if ($env{'form.phase'} eq 'createnewuser') {
4827: my $response;
4828: if ($env{'form.srchterm'} !~ /^$match_username$/) {
1.366 bisitz 4829: my $response =
4830: '<span class="LC_warning">'
4831: .&mt('You must specify a valid username. Only the following are allowed:'
4832: .' letters numbers - . @')
4833: .'</span>';
1.221 raeburn 4834: $env{'form.phase'} = '';
1.375 raeburn 4835: &print_username_entry_form($r,$context,$response,$srch,undef,
1.406.2.14 raeburn 4836: $crstype,$brcrum,$permission);
1.207 raeburn 4837: } else {
4838: my $ccuname =&LONCAPA::clean_username($srch->{'srchterm'});
4839: my $ccdomain=&LONCAPA::clean_domain($srch->{'srchdomain'});
4840: &print_user_modification_page($r,$ccuname,$ccdomain,
1.221 raeburn 4841: $srch,$response,$context,
1.375 raeburn 4842: $permission,$crstype,$brcrum,
4843: $showcredits);
1.207 raeburn 4844: }
4845: } elsif ($env{'form.phase'} eq 'get_user_info') {
1.190 raeburn 4846: my ($currstate,$response,$forcenewuser,$results) =
1.221 raeburn 4847: &user_search_result($context,$srch);
1.190 raeburn 4848: if ($env{'form.currstate'} eq 'modify') {
4849: $currstate = $env{'form.currstate'};
4850: }
4851: if ($currstate eq 'select') {
4852: &print_user_selection_page($r,$response,$srch,$results,
1.351 raeburn 4853: \@search,$context,undef,$crstype,
4854: $brcrum);
1.406.2.5 raeburn 4855: } elsif (($currstate eq 'modify') || ($env{'form.action'} eq 'accesslogs')) {
4856: my ($ccuname,$ccdomain,$uhome);
1.190 raeburn 4857: if (($srch->{'srchby'} eq 'uname') &&
4858: ($srch->{'srchtype'} eq 'exact')) {
4859: $ccuname = $srch->{'srchterm'};
4860: $ccdomain= $srch->{'srchdomain'};
4861: } else {
4862: my @matchedunames = keys(%{$results});
4863: ($ccuname,$ccdomain) = split(/:/,$matchedunames[0]);
4864: }
4865: $ccuname =&LONCAPA::clean_username($ccuname);
4866: $ccdomain=&LONCAPA::clean_domain($ccdomain);
1.406.2.5 raeburn 4867: if ($env{'form.action'} eq 'accesslogs') {
4868: my $uhome;
4869: if (($ccuname ne '') && ($ccdomain ne '')) {
4870: $uhome = &Apache::lonnet::homeserver($ccuname,$ccdomain);
4871: }
4872: if (($uhome eq '') || ($uhome eq 'no_host')) {
4873: $env{'form.phase'} = '';
4874: undef($forcenewuser);
4875: #if ($response) {
4876: # unless ($response =~ m{\Q<br /><br />\E$}) {
4877: # $response .= '<br /><br />';
4878: # }
4879: #}
4880: &print_username_entry_form($r,$context,$response,$srch,
1.406.2.14 raeburn 4881: $forcenewuser,$crstype,$brcrum,
4882: $permission);
1.406.2.5 raeburn 4883: } else {
4884: &print_useraccesslogs_display($r,$ccuname,$ccdomain,$permission,$brcrum);
4885: }
4886: } else {
4887: if ($env{'form.forcenewuser'}) {
4888: $response = '';
4889: }
4890: &print_user_modification_page($r,$ccuname,$ccdomain,
4891: $srch,$response,$context,
4892: $permission,$crstype,$brcrum);
1.190 raeburn 4893: }
4894: } elsif ($currstate eq 'query') {
1.351 raeburn 4895: &print_user_query_page($r,'createuser',$brcrum);
1.190 raeburn 4896: } else {
1.229 raeburn 4897: $env{'form.phase'} = '';
1.207 raeburn 4898: &print_username_entry_form($r,$context,$response,$srch,
1.406.2.14 raeburn 4899: $forcenewuser,$crstype,$brcrum,
4900: $permission);
1.190 raeburn 4901: }
4902: } elsif ($env{'form.phase'} eq 'userpicked') {
4903: my $ccuname = &LONCAPA::clean_username($env{'form.seluname'});
4904: my $ccdomain = &LONCAPA::clean_domain($env{'form.seludom'});
1.406.2.5 raeburn 4905: if ($env{'form.action'} eq 'accesslogs') {
4906: &print_useraccesslogs_display($r,$ccuname,$ccdomain,$permission,$brcrum);
4907: } else {
4908: &print_user_modification_page($r,$ccuname,$ccdomain,$srch,'',
4909: $context,$permission,$crstype,
4910: $brcrum);
4911: }
4912: } elsif ($env{'form.action'} eq 'accesslogs') {
4913: my $ccuname = &LONCAPA::clean_username($env{'form.accessuname'});
4914: my $ccdomain = &LONCAPA::clean_domain($env{'form.accessudom'});
4915: &print_useraccesslogs_display($r,$ccuname,$ccdomain,$permission,$brcrum);
1.190 raeburn 4916: }
4917: } elsif ($env{'form.phase'} eq 'update_user_data') {
1.406.2.17 raeburn 4918: &update_user_data($r,$context,$crstype,$brcrum,$showcredits,$permission);
1.190 raeburn 4919: } else {
1.351 raeburn 4920: &print_username_entry_form($r,$context,undef,$srch,undef,$crstype,
1.406.2.14 raeburn 4921: $brcrum,$permission);
1.190 raeburn 4922: }
4923: } elsif ($env{'form.action'} eq 'custom' && $permission->{'custom'}) {
1.406.2.5 raeburn 4924: my $prefix;
1.190 raeburn 4925: if ($env{'form.phase'} eq 'set_custom_roles') {
1.406.2.14 raeburn 4926: &set_custom_role($r,$context,$brcrum,$prefix,$permission);
1.190 raeburn 4927: } else {
1.406.2.14 raeburn 4928: &custom_role_editor($r,$context,$brcrum,$prefix,$permission);
1.190 raeburn 4929: }
1.362 raeburn 4930: } elsif (($env{'form.action'} eq 'processauthorreq') &&
4931: ($permission->{'cusr'}) &&
4932: (&Apache::lonnet::allowed('cau',$env{'request.role.domain'}))) {
4933: push(@{$brcrum},
4934: {href => '/adm/createuser?action=processauthorreq',
1.385 bisitz 4935: text => 'Authoring Space requests',
1.362 raeburn 4936: help => 'Domain_Role_Approvals'});
4937: $bread_crumbs_component = 'Authoring requests';
4938: if ($env{'form.state'} eq 'done') {
4939: push(@{$brcrum},
4940: {href => '/adm/createuser?action=authorreqqueue',
4941: text => 'Result',
4942: help => 'Domain_Role_Approvals'});
4943: $bread_crumbs_component = 'Authoring request result';
4944: }
4945: $args = { bread_crumbs => $brcrum,
4946: bread_crumbs_component => $bread_crumbs_component};
1.391 raeburn 4947: my $js = &usernamerequest_javascript();
4948: $r->print(&header(&add_script($js),$args));
1.362 raeburn 4949: if (!exists($env{'form.state'})) {
4950: $r->print(&Apache::loncoursequeueadmin::display_queued_requests('requestauthor',
4951: $env{'request.role.domain'}));
4952: } elsif ($env{'form.state'} eq 'done') {
4953: $r->print('<h3>'.&mt('Authoring request processing').'</h3>'."\n");
4954: $r->print(&Apache::loncoursequeueadmin::update_request_queue('requestauthor',
4955: $env{'request.role.domain'}));
4956: }
1.391 raeburn 4957: } elsif (($env{'form.action'} eq 'processusernamereq') &&
4958: ($permission->{'cusr'}) &&
4959: (&Apache::lonnet::allowed('cau',$env{'request.role.domain'}))) {
4960: push(@{$brcrum},
4961: {href => '/adm/createuser?action=processusernamereq',
4962: text => 'LON-CAPA account requests',
4963: help => 'Domain_Username_Approvals'});
4964: $bread_crumbs_component = 'Account requests';
4965: if ($env{'form.state'} eq 'done') {
4966: push(@{$brcrum},
4967: {href => '/adm/createuser?action=usernamereqqueue',
4968: text => 'Result',
4969: help => 'Domain_Username_Approvals'});
4970: $bread_crumbs_component = 'LON-CAPA account request result';
4971: }
4972: $args = { bread_crumbs => $brcrum,
4973: bread_crumbs_component => $bread_crumbs_component};
4974: my $js = &usernamerequest_javascript();
4975: $r->print(&header(&add_script($js),$args));
4976: if (!exists($env{'form.state'})) {
4977: $r->print(&Apache::loncoursequeueadmin::display_queued_requests('requestusername',
4978: $env{'request.role.domain'}));
4979: } elsif ($env{'form.state'} eq 'done') {
4980: $r->print('<h3>'.&mt('LON-CAPA account request processing').'</h3>'."\n");
4981: $r->print(&Apache::loncoursequeueadmin::update_request_queue('requestusername',
4982: $env{'request.role.domain'}));
4983: }
4984: } elsif (($env{'form.action'} eq 'displayuserreq') &&
4985: ($permission->{'cusr'})) {
4986: my $dom = $env{'form.domain'};
4987: my $uname = $env{'form.username'};
4988: my $warning;
4989: if (($dom =~ /^$match_domain$/) && (&Apache::lonnet::domain($dom) ne '')) {
4990: if (($dom eq $env{'request.role.domain'}) && (&Apache::lonnet::allowed('ccc',$dom))) {
4991: if (($uname =~ /^$match_username$/) && ($env{'form.queue'} eq 'approval')) {
4992: my $uhome = &Apache::lonnet::homeserver($uname,$dom);
4993: if ($uhome eq 'no_host') {
4994: my $queue = $env{'form.queue'};
4995: my $reqkey = &escape($uname).'_'.$queue;
4996: my $namespace = 'usernamequeue';
4997: my $domconfig = &Apache::lonnet::get_domainconfiguser($dom);
4998: my %queued =
4999: &Apache::lonnet::get($namespace,[$reqkey],$dom,$domconfig);
5000: unless ($queued{$reqkey}) {
5001: $warning = &mt('No information was found for this LON-CAPA account request.');
5002: }
5003: } else {
5004: $warning = &mt('A LON-CAPA account already exists for the requested username and domain.');
5005: }
5006: } else {
5007: $warning = &mt('LON-CAPA account request status check is for an invalid username.');
5008: }
5009: } else {
5010: $warning = &mt('You do not have rights to view LON-CAPA account requests in the domain specified.');
5011: }
5012: } else {
5013: $warning = &mt('LON-CAPA account request status check is for an invalid domain.');
5014: }
5015: my $args = { only_body => 1 };
5016: $r->print(&header(undef,$args).
5017: '<h3>'.&mt('LON-CAPA Account Request Details').'</h3>');
5018: if ($warning ne '') {
5019: $r->print('<div class="LC_warning">'.$warning.'</div>');
5020: } else {
5021: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
5022: my $domconfiguser = &Apache::lonnet::get_domainconfiguser($dom);
5023: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
5024: if (ref($domconfig{'usercreation'}) eq 'HASH') {
5025: if (ref($domconfig{'usercreation'}{'cancreate'}) eq 'HASH') {
5026: if (ref($domconfig{'usercreation'}{'cancreate'}{'emailusername'}) eq 'HASH') {
5027: my %info =
5028: &Apache::lonnet::get('nohist_requestedusernames',[$uname],$dom,$domconfiguser);
5029: if (ref($info{$uname}) eq 'HASH') {
1.396 raeburn 5030: my $usertype = $info{$uname}{'inststatus'};
5031: unless ($usertype) {
5032: $usertype = 'default';
5033: }
1.406.2.16 raeburn 5034: my ($showstatus,$showemail,$pickstart);
5035: my $numextras = 0;
5036: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
5037: if ((ref($types) eq 'ARRAY') && (@{$types} > 0)) {
5038: if (ref($usertypes) eq 'HASH') {
5039: if ($usertypes->{$usertype}) {
5040: $showstatus = $usertypes->{$usertype};
5041: } else {
5042: $showstatus = $othertitle;
5043: }
5044: if ($showstatus) {
5045: $numextras ++;
5046: }
5047: }
5048: }
5049: if (($info{$uname}{'email'} ne '') && ($info{$uname}{'email'} ne $uname)) {
5050: $showemail = $info{$uname}{'email'};
5051: $numextras ++;
5052: }
1.396 raeburn 5053: if (ref($domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}) eq 'HASH') {
5054: if ((ref($infofields) eq 'ARRAY') && (ref($infotitles) eq 'HASH')) {
1.406.2.16 raeburn 5055: $pickstart = 1;
1.396 raeburn 5056: $r->print('<div>'.&Apache::lonhtmlcommon::start_pick_box());
1.406.2.16 raeburn 5057: my ($num,$count);
1.396 raeburn 5058: $count = scalar(keys(%{$domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}}));
1.406.2.16 raeburn 5059: $count += $numextras;
1.396 raeburn 5060: foreach my $field (@{$infofields}) {
5061: next unless ($domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}{$field});
5062: next unless ($infotitles->{$field});
5063: $r->print(&Apache::lonhtmlcommon::row_title($infotitles->{$field}).
5064: $info{$uname}{$field});
5065: $num ++;
1.406.2.16 raeburn 5066: unless ($count == $num) {
1.396 raeburn 5067: $r->print(&Apache::lonhtmlcommon::row_closure());
5068: }
5069: }
1.406.2.16 raeburn 5070: }
5071: }
5072: if ($numextras) {
5073: unless ($pickstart) {
5074: $r->print('<div>'.&Apache::lonhtmlcommon::start_pick_box());
5075: $pickstart = 1;
5076: }
5077: if ($showemail) {
5078: my $closure = '';
5079: unless ($showstatus) {
5080: $closure = 1;
1.391 raeburn 5081: }
1.406.2.16 raeburn 5082: $r->print(&Apache::lonhtmlcommon::row_title(&mt('E-mail address')).
5083: $showemail.
5084: &Apache::lonhtmlcommon::row_closure($closure));
5085: }
5086: if ($showstatus) {
5087: $r->print(&Apache::lonhtmlcommon::row_title(&mt('Status type[_1](self-reported)','<br />')).
5088: $showstatus.
5089: &Apache::lonhtmlcommon::row_closure(1));
1.391 raeburn 5090: }
5091: }
1.406.2.16 raeburn 5092: if ($pickstart) {
5093: $r->print(&Apache::lonhtmlcommon::end_pick_box().'</div>');
5094: } else {
5095: $r->print('<div>'.&mt('No information to display for this account request.').'</div>');
5096: }
5097: } else {
5098: $r->print('<div>'.&mt('No information available for this account request.').'</div>');
1.391 raeburn 5099: }
5100: }
5101: }
5102: }
5103: }
1.406.2.16 raeburn 5104: $r->print(&close_popup_form());
1.207 raeburn 5105: } elsif (($env{'form.action'} eq 'listusers') &&
5106: ($permission->{'view'} || $permission->{'cusr'})) {
1.406.2.14 raeburn 5107: my $helpitem = 'Course_View_Class_List';
5108: if ($context eq 'author') {
5109: $helpitem = 'Author_View_Coauthor_List';
5110: } elsif ($context eq 'domain') {
5111: $helpitem = 'Domain_View_Users_List';
5112: }
1.202 raeburn 5113: if ($env{'form.phase'} eq 'bulkchange') {
1.351 raeburn 5114: push(@{$brcrum},
5115: {href => '/adm/createuser?action=listusers',
5116: text => "List Users"},
5117: {href => "/adm/createuser",
5118: text => "Result",
1.406.2.14 raeburn 5119: help => $helpitem});
1.351 raeburn 5120: $bread_crumbs_component = 'Update Users';
5121: $args = {bread_crumbs => $brcrum,
5122: bread_crumbs_component => $bread_crumbs_component};
5123: $r->print(&header(undef,$args));
1.202 raeburn 5124: my $setting = $env{'form.roletype'};
5125: my $choice = $env{'form.bulkaction'};
5126: if ($permission->{'cusr'}) {
1.336 raeburn 5127: &Apache::lonuserutils::update_user_list($r,$context,$setting,$choice,$crstype);
1.221 raeburn 5128: } else {
5129: $r->print(&mt('You are not authorized to make bulk changes to user roles'));
1.223 raeburn 5130: $r->print('<p><a href="/adm/createuser?action=listusers">'.&mt('Display User Lists').'</a>');
1.202 raeburn 5131: }
5132: } else {
1.351 raeburn 5133: push(@{$brcrum},
5134: {href => '/adm/createuser?action=listusers',
5135: text => "List Users",
1.406.2.14 raeburn 5136: help => $helpitem});
1.351 raeburn 5137: $bread_crumbs_component = 'List Users';
5138: $args = {bread_crumbs => $brcrum,
5139: bread_crumbs_component => $bread_crumbs_component};
1.202 raeburn 5140: my ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles);
5141: my $formname = 'studentform';
1.364 raeburn 5142: my $hidecall = "hide_searching();";
1.321 raeburn 5143: if (($context eq 'domain') && (($env{'form.roletype'} eq 'course') ||
5144: ($env{'form.roletype'} eq 'community'))) {
5145: if ($env{'form.roletype'} eq 'course') {
5146: ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles) =
5147: &Apache::lonuserutils::courses_selector($env{'request.role.domain'},
5148: $formname);
5149: } elsif ($env{'form.roletype'} eq 'community') {
5150: $cb_jscript =
5151: &Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
5152: my %elements = (
5153: coursepick => 'radio',
5154: coursetotal => 'text',
5155: courselist => 'text',
5156: );
5157: $jscript = &Apache::lonhtmlcommon::set_form_elements(\%elements);
5158: }
1.364 raeburn 5159: $jscript .= &verify_user_display($context)."\n".
5160: &Apache::loncommon::check_uncheck_jscript();
1.202 raeburn 5161: my $js = &add_script($jscript).$cb_jscript;
5162: my $loadcode =
5163: &Apache::lonuserutils::course_selector_loadcode($formname);
5164: if ($loadcode ne '') {
1.364 raeburn 5165: $args->{add_entries} = {onload => "$loadcode;$hidecall"};
5166: } else {
5167: $args->{add_entries} = {onload => $hidecall};
1.202 raeburn 5168: }
1.351 raeburn 5169: $r->print(&header($js,$args));
1.191 raeburn 5170: } else {
1.364 raeburn 5171: $args->{add_entries} = {onload => $hidecall};
5172: $jscript = &verify_user_display($context).
5173: &Apache::loncommon::check_uncheck_jscript();
5174: $r->print(&header(&add_script($jscript),$args));
1.191 raeburn 5175: }
1.202 raeburn 5176: &Apache::lonuserutils::print_userlist($r,undef,$permission,$context,
1.375 raeburn 5177: $formname,$totcodes,$codetitles,$idlist,$idlist_titles,
5178: $showcredits);
1.191 raeburn 5179: }
1.213 raeburn 5180: } elsif ($env{'form.action'} eq 'drop' && $permission->{'cusr'}) {
1.318 raeburn 5181: my $brtext;
5182: if ($crstype eq 'Community') {
5183: $brtext = 'Drop Members';
5184: } else {
5185: $brtext = 'Drop Students';
5186: }
1.351 raeburn 5187: push(@{$brcrum},
5188: {href => '/adm/createuser?action=drop',
5189: text => $brtext,
5190: help => 'Course_Drop_Student'});
5191: if ($env{'form.state'} eq 'done') {
5192: push(@{$brcrum},
5193: {href=>'/adm/createuser?action=drop',
5194: text=>"Result"});
5195: }
5196: $bread_crumbs_component = $brtext;
5197: $args = {bread_crumbs => $brcrum,
5198: bread_crumbs_component => $bread_crumbs_component};
5199: $r->print(&header(undef,$args));
1.213 raeburn 5200: if (!exists($env{'form.state'})) {
1.318 raeburn 5201: &Apache::lonuserutils::print_drop_menu($r,$context,$permission,$crstype);
1.213 raeburn 5202: } elsif ($env{'form.state'} eq 'done') {
5203: &Apache::lonuserutils::update_user_list($r,$context,undef,
5204: $env{'form.action'});
5205: }
1.202 raeburn 5206: } elsif ($env{'form.action'} eq 'dateselect') {
5207: if ($permission->{'cusr'}) {
1.351 raeburn 5208: $r->print(&header(undef,{'no_nav_bar' => 1}).
1.375 raeburn 5209: &Apache::lonuserutils::date_section_selector($context,$permission,
5210: $crstype,$showcredits));
1.202 raeburn 5211: } else {
1.351 raeburn 5212: $r->print(&header(undef,{'no_nav_bar' => 1}).
5213: '<span class="LC_error">'.&mt('You do not have permission to modify dates or sections for users').'</span>');
1.202 raeburn 5214: }
1.237 raeburn 5215: } elsif ($env{'form.action'} eq 'selfenroll') {
1.398 raeburn 5216: if ($permission->{selfenrolladmin}) {
5217: my %currsettings = (
5218: selfenroll_types => $env{'course.'.$cid.'.internal.selfenroll_types'},
5219: selfenroll_registered => $env{'course.'.$cid.'.internal.selfenroll_registered'},
5220: selfenroll_section => $env{'course.'.$cid.'.internal.selfenroll_section'},
5221: selfenroll_notifylist => $env{'course.'.$cid.'.internal.selfenroll_notifylist'},
5222: selfenroll_approval => $env{'course.'.$cid.'.internal.selfenroll_approval'},
5223: selfenroll_limit => $env{'course.'.$cid.'.internal.selfenroll_limit'},
5224: selfenroll_cap => $env{'course.'.$cid.'.internal.selfenroll_cap'},
5225: selfenroll_start_date => $env{'course.'.$cid.'.internal.selfenroll_start_date'},
5226: selfenroll_end_date => $env{'course.'.$cid.'.internal.selfenroll_end_date'},
5227: selfenroll_start_access => $env{'course.'.$cid.'.internal.selfenroll_start_access'},
5228: selfenroll_end_access => $env{'course.'.$cid.'.internal.selfenroll_end_access'},
5229: default_enrollment_start_date => $env{'course.'.$cid.'.default_enrollment_start_date'},
5230: default_enrollment_end_date => $env{'course.'.$cid.'.default_enrollment_end_date'},
1.400 raeburn 5231: uniquecode => $env{'course.'.$cid.'.internal.uniquecode'},
1.398 raeburn 5232: );
5233: push(@{$brcrum},
5234: {href => '/adm/createuser?action=selfenroll',
5235: text => "Configure Self-enrollment",
5236: help => 'Course_Self_Enrollment'});
5237: if (!exists($env{'form.state'})) {
5238: $args = { bread_crumbs => $brcrum,
5239: bread_crumbs_component => 'Configure Self-enrollment'};
5240: $r->print(&header(undef,$args));
5241: $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n");
5242: &print_selfenroll_menu($r,'course',$cid,$cdom,$cnum,\%currsettings);
5243: } elsif ($env{'form.state'} eq 'done') {
5244: push (@{$brcrum},
5245: {href=>'/adm/createuser?action=selfenroll',
5246: text=>"Result"});
5247: $args = { bread_crumbs => $brcrum,
5248: bread_crumbs_component => 'Self-enrollment result'};
5249: $r->print(&header(undef,$args));
5250: $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n");
1.400 raeburn 5251: &update_selfenroll_config($r,$cid,$cdom,$cnum,$context,$crstype,\%currsettings);
1.398 raeburn 5252: }
5253: } else {
5254: $r->print(&header(undef,{'no_nav_bar' => 1}).
5255: '<span class="LC_error">'.&mt('You do not have permission to configure self-enrollment').'</span>');
1.237 raeburn 5256: }
1.277 raeburn 5257: } elsif ($env{'form.action'} eq 'selfenrollqueue') {
1.406.2.6 raeburn 5258: if ($permission->{selfenrolladmin}) {
1.351 raeburn 5259: push(@{$brcrum},
5260: {href => '/adm/createuser?action=selfenrollqueue',
1.406.2.6 raeburn 5261: text => 'Enrollment requests',
1.406.2.14 raeburn 5262: help => 'Course_Approve_Selfenroll'});
1.406.2.6 raeburn 5263: $bread_crumbs_component = 'Enrollment requests';
5264: if ($env{'form.state'} eq 'done') {
5265: push(@{$brcrum},
5266: {href => '/adm/createuser?action=selfenrollqueue',
5267: text => 'Result',
1.406.2.14 raeburn 5268: help => 'Course_Approve_Selfenroll'});
1.406.2.6 raeburn 5269: $bread_crumbs_component = 'Enrollment result';
5270: }
5271: $args = { bread_crumbs => $brcrum,
5272: bread_crumbs_component => $bread_crumbs_component};
5273: $r->print(&header(undef,$args));
5274: my $coursedesc = $env{'course.'.$cid.'.description'};
5275: if (!exists($env{'form.state'})) {
5276: $r->print('<h3>'.&mt('Pending enrollment requests').'</h3>'."\n");
5277: $r->print(&Apache::loncoursequeueadmin::display_queued_requests($context,
5278: $cdom,$cnum));
5279: } elsif ($env{'form.state'} eq 'done') {
5280: $r->print('<h3>'.&mt('Enrollment request processing').'</h3>'."\n");
5281: $r->print(&Apache::loncoursequeueadmin::update_request_queue($context,
5282: $cdom,$cnum,$coursedesc));
5283: }
5284: } else {
5285: $r->print(&header(undef,{'no_nav_bar' => 1}).
5286: '<span class="LC_error">'.&mt('You do not have permission to manage self-enrollment').'</span>');
1.277 raeburn 5287: }
1.239 raeburn 5288: } elsif ($env{'form.action'} eq 'changelogs') {
1.406.2.6 raeburn 5289: if ($permission->{cusr} || $permission->{view}) {
5290: &print_userchangelogs_display($r,$context,$permission,$brcrum);
5291: } else {
5292: $r->print(&header(undef,{'no_nav_bar' => 1}).
5293: '<span class="LC_error">'.&mt('You do not have permission to view change logs').'</span>');
5294: }
1.406.2.10 raeburn 5295: } elsif ($env{'form.action'} eq 'helpdesk') {
5296: if (($permission->{'owner'}) || ($permission->{'co-owner'})) {
5297: if ($env{'form.state'} eq 'process') {
5298: if ($permission->{'owner'}) {
5299: &update_helpdeskaccess($r,$permission,$brcrum);
5300: } else {
5301: &print_helpdeskaccess_display($r,$permission,$brcrum);
5302: }
5303: } else {
5304: &print_helpdeskaccess_display($r,$permission,$brcrum);
5305: }
5306: } else {
5307: $r->print(&header(undef,{'no_nav_bar' => 1}).
5308: '<span class="LC_error">'.&mt('You do not have permission to view helpdesk access').'</span>');
5309: }
1.190 raeburn 5310: } else {
1.351 raeburn 5311: $bread_crumbs_component = 'User Management';
5312: $args = { bread_crumbs => $brcrum,
5313: bread_crumbs_component => $bread_crumbs_component};
5314: $r->print(&header(undef,$args));
1.318 raeburn 5315: $r->print(&print_main_menu($permission,$context,$crstype));
1.190 raeburn 5316: }
1.351 raeburn 5317: $r->print(&Apache::loncommon::end_page());
1.190 raeburn 5318: return OK;
5319: }
5320:
5321: sub header {
1.351 raeburn 5322: my ($jscript,$args) = @_;
1.190 raeburn 5323: my $start_page;
1.351 raeburn 5324: if (ref($args) eq 'HASH') {
5325: $start_page=&Apache::loncommon::start_page('User Management',$jscript,$args);
1.190 raeburn 5326: } else {
1.351 raeburn 5327: $start_page=&Apache::loncommon::start_page('User Management',$jscript);
1.190 raeburn 5328: }
5329: return $start_page;
5330: }
1.2 www 5331:
1.191 raeburn 5332: sub add_script {
5333: my ($js) = @_;
1.301 bisitz 5334: return '<script type="text/javascript">'."\n"
5335: .'// <![CDATA['."\n"
5336: .$js."\n"
5337: .'// ]]>'."\n"
5338: .'</script>'."\n";
1.191 raeburn 5339: }
5340:
1.391 raeburn 5341: sub usernamerequest_javascript {
5342: my $js = <<ENDJS;
5343:
5344: function openusernamereqdisplay(dom,uname,queue) {
5345: var url = '/adm/createuser?action=displayuserreq';
5346: url += '&domain='+dom+'&username='+uname+'&queue='+queue;
5347: var title = 'Account_Request_Browser';
5348: var options = 'scrollbars=1,resizable=1,menubar=0';
5349: options += ',width=700,height=600';
5350: var stdeditbrowser = open(url,title,options,'1');
5351: stdeditbrowser.focus();
5352: return;
5353: }
5354:
5355: ENDJS
5356: }
5357:
5358: sub close_popup_form {
5359: my $close= &mt('Close Window');
5360: return << "END";
5361: <p><form name="displayreq" action="" method="post">
5362: <input type="button" name="closeme" value="$close" onclick="javascript:self.close();" />
5363: </form></p>
5364: END
5365: }
5366:
1.202 raeburn 5367: sub verify_user_display {
1.364 raeburn 5368: my ($context) = @_;
1.374 raeburn 5369: my %lt = &Apache::lonlocal::texthash (
5370: course => 'course(s): description, section(s), status',
5371: community => 'community(s): description, section(s), status',
5372: author => 'author',
5373: );
1.364 raeburn 5374: my $photos;
5375: if (($context eq 'course') && $env{'request.course.id'}) {
5376: $photos = $env{'course.'.$env{'request.course.id'}.'.internal.showphoto'};
5377: }
1.202 raeburn 5378: my $output = <<"END";
5379:
1.364 raeburn 5380: function hide_searching() {
5381: if (document.getElementById('searching')) {
5382: document.getElementById('searching').style.display = 'none';
5383: }
5384: return;
5385: }
5386:
1.202 raeburn 5387: function display_update() {
5388: document.studentform.action.value = 'listusers';
5389: document.studentform.phase.value = 'display';
5390: document.studentform.submit();
5391: }
5392:
1.364 raeburn 5393: function updateCols(caller) {
5394: var context = '$context';
5395: var photos = '$photos';
5396: if (caller == 'Status') {
1.374 raeburn 5397: if ((context == 'domain') &&
5398: ((document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'course') ||
5399: (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community'))) {
1.364 raeburn 5400: document.getElementById('showcolstatus').checked = false;
5401: document.getElementById('showcolstatus').disabled = 'disabled';
5402: document.getElementById('showcolstart').checked = false;
5403: document.getElementById('showcolend').checked = false;
1.374 raeburn 5404: } else {
5405: if (document.studentform.Status.options[document.studentform.Status.selectedIndex].value == 'Any') {
5406: document.getElementById('showcolstatus').checked = true;
5407: document.getElementById('showcolstatus').disabled = '';
5408: document.getElementById('showcolstart').checked = true;
5409: document.getElementById('showcolend').checked = true;
5410: } else {
5411: document.getElementById('showcolstatus').checked = false;
5412: document.getElementById('showcolstatus').disabled = 'disabled';
5413: document.getElementById('showcolstart').checked = false;
5414: document.getElementById('showcolend').checked = false;
5415: }
1.364 raeburn 5416: }
5417: }
5418: if (caller == 'output') {
5419: if (photos == 1) {
5420: if (document.getElementById('showcolphoto')) {
5421: var photoitem = document.getElementById('showcolphoto');
5422: if (document.studentform.output.options[document.studentform.output.selectedIndex].value == 'html') {
5423: photoitem.checked = true;
5424: photoitem.disabled = '';
5425: } else {
5426: photoitem.checked = false;
5427: photoitem.disabled = 'disabled';
5428: }
5429: }
5430: }
5431: }
5432: if (caller == 'showrole') {
1.371 raeburn 5433: if ((document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'Any') ||
5434: (document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'cr')) {
1.364 raeburn 5435: document.getElementById('showcolrole').checked = true;
5436: document.getElementById('showcolrole').disabled = '';
5437: } else {
5438: document.getElementById('showcolrole').checked = false;
5439: document.getElementById('showcolrole').disabled = 'disabled';
5440: }
1.374 raeburn 5441: if (context == 'domain') {
1.382 raeburn 5442: var quotausageshow = 0;
1.374 raeburn 5443: if ((document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'course') ||
5444: (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community')) {
5445: document.getElementById('showcolstatus').checked = false;
5446: document.getElementById('showcolstatus').disabled = 'disabled';
5447: document.getElementById('showcolstart').checked = false;
5448: document.getElementById('showcolend').checked = false;
5449: } else {
5450: if (document.studentform.Status.options[document.studentform.Status.selectedIndex].value == 'Any') {
5451: document.getElementById('showcolstatus').checked = true;
5452: document.getElementById('showcolstatus').disabled = '';
5453: document.getElementById('showcolstart').checked = true;
5454: document.getElementById('showcolend').checked = true;
5455: }
5456: }
5457: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'domain') {
5458: document.getElementById('showcolextent').disabled = 'disabled';
5459: document.getElementById('showcolextent').checked = 'false';
5460: document.getElementById('showextent').style.display='none';
5461: document.getElementById('showcoltextextent').innerHTML = '';
1.382 raeburn 5462: if ((document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'au') ||
5463: (document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'Any')) {
5464: if (document.getElementById('showcolauthorusage')) {
5465: document.getElementById('showcolauthorusage').disabled = '';
5466: }
5467: if (document.getElementById('showcolauthorquota')) {
5468: document.getElementById('showcolauthorquota').disabled = '';
5469: }
5470: quotausageshow = 1;
5471: }
1.374 raeburn 5472: } else {
5473: document.getElementById('showextent').style.display='block';
5474: document.getElementById('showextent').style.textAlign='left';
5475: document.getElementById('showextent').style.textFace='normal';
5476: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'author') {
5477: document.getElementById('showcolextent').disabled = '';
5478: document.getElementById('showcolextent').checked = 'true';
5479: document.getElementById('showcoltextextent').innerHTML="$lt{'author'}";
5480: } else {
5481: document.getElementById('showcolextent').disabled = '';
5482: document.getElementById('showcolextent').checked = 'true';
5483: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community') {
5484: document.getElementById('showcoltextextent').innerHTML="$lt{'community'}";
5485: } else {
5486: document.getElementById('showcoltextextent').innerHTML="$lt{'course'}";
5487: }
5488: }
5489: }
1.382 raeburn 5490: if (quotausageshow == 0) {
5491: if (document.getElementById('showcolauthorusage')) {
5492: document.getElementById('showcolauthorusage').checked = false;
5493: document.getElementById('showcolauthorusage').disabled = 'disabled';
5494: }
5495: if (document.getElementById('showcolauthorquota')) {
5496: document.getElementById('showcolauthorquota').checked = false;
5497: document.getElementById('showcolauthorquota').disabled = 'disabled';
5498: }
5499: }
1.374 raeburn 5500: }
1.364 raeburn 5501: }
5502: return;
5503: }
5504:
1.202 raeburn 5505: END
5506: return $output;
5507:
5508: }
5509:
1.190 raeburn 5510: ###############################################################
5511: ###############################################################
5512: # Menu Phase One
5513: sub print_main_menu {
1.318 raeburn 5514: my ($permission,$context,$crstype) = @_;
5515: my $linkcontext = $context;
5516: my $stuterm = lc(&Apache::lonnet::plaintext('st',$crstype));
5517: if (($context eq 'course') && ($crstype eq 'Community')) {
5518: $linkcontext = lc($crstype);
5519: $stuterm = 'Members';
5520: }
1.208 raeburn 5521: my %links = (
1.298 droeschl 5522: domain => {
5523: upload => 'Upload a File of Users',
5524: singleuser => 'Add/Modify a User',
5525: listusers => 'Manage Users',
5526: },
5527: author => {
5528: upload => 'Upload a File of Co-authors',
5529: singleuser => 'Add/Modify a Co-author',
5530: listusers => 'Manage Co-authors',
5531: },
5532: course => {
5533: upload => 'Upload a File of Course Users',
5534: singleuser => 'Add/Modify a Course User',
1.354 www 5535: listusers => 'List and Modify Multiple Course Users',
1.298 droeschl 5536: },
1.318 raeburn 5537: community => {
5538: upload => 'Upload a File of Community Users',
5539: singleuser => 'Add/Modify a Community User',
1.354 www 5540: listusers => 'List and Modify Multiple Community Users',
1.318 raeburn 5541: },
5542: );
5543: my %linktitles = (
5544: domain => {
5545: singleuser => 'Add a user to the domain, and/or a course or community in the domain.',
5546: listusers => 'Show and manage users in this domain.',
5547: },
5548: author => {
5549: singleuser => 'Add a user with a co- or assistant author role.',
5550: listusers => 'Show and manage co- or assistant authors.',
5551: },
5552: course => {
5553: singleuser => 'Add a user with a certain role to this course.',
5554: listusers => 'Show and manage users in this course.',
5555: },
5556: community => {
5557: singleuser => 'Add a user with a certain role to this community.',
5558: listusers => 'Show and manage users in this community.',
5559: },
1.298 droeschl 5560: );
1.406.2.6 raeburn 5561: if ($linkcontext eq 'domain') {
5562: unless ($permission->{'cusr'}) {
5563: $links{'domain'}{'singleuser'} = 'View a User';
5564: $linktitles{'domain'}{'singleuser'} = 'View information about a user in the domain';
5565: }
5566: } elsif ($linkcontext eq 'course') {
5567: unless ($permission->{'cusr'}) {
5568: $links{'course'}{'singleuser'} = 'View a Course User';
5569: $linktitles{'course'}{'singleuser'} = 'View information about a user in this course';
5570: $links{'course'}{'listusers'} = 'List Course Users';
5571: $linktitles{'course'}{'listusers'} = 'Show information about users in this course';
5572: }
5573: } elsif ($linkcontext eq 'community') {
5574: unless ($permission->{'cusr'}) {
5575: $links{'community'}{'singleuser'} = 'View a Community User';
5576: $linktitles{'community'}{'singleuser'} = 'View information about a user in this community';
5577: $links{'community'}{'listusers'} = 'List Community Users';
5578: $linktitles{'community'}{'listusers'} = 'Show information about users in this community';
5579: }
5580: }
1.298 droeschl 5581: my @menu = ( {categorytitle => 'Single Users',
5582: items =>
5583: [
5584: {
1.318 raeburn 5585: linktext => $links{$linkcontext}{'singleuser'},
1.298 droeschl 5586: icon => 'edit-redo.png',
5587: #help => 'Course_Change_Privileges',
5588: url => '/adm/createuser?action=singleuser',
1.406.2.6 raeburn 5589: permission => ($permission->{'view'} || $permission->{'cusr'}),
1.318 raeburn 5590: linktitle => $linktitles{$linkcontext}{'singleuser'},
1.298 droeschl 5591: },
5592: ]},
5593:
5594: {categorytitle => 'Multiple Users',
5595: items =>
5596: [
5597: {
1.318 raeburn 5598: linktext => $links{$linkcontext}{'upload'},
1.340 wenzelju 5599: icon => 'uplusr.png',
1.298 droeschl 5600: #help => 'Course_Create_Class_List',
5601: url => '/adm/createuser?action=upload',
5602: permission => $permission->{'cusr'},
5603: linktitle => 'Upload a CSV or a text file containing users.',
5604: },
5605: {
1.318 raeburn 5606: linktext => $links{$linkcontext}{'listusers'},
1.340 wenzelju 5607: icon => 'mngcu.png',
1.298 droeschl 5608: #help => 'Course_View_Class_List',
5609: url => '/adm/createuser?action=listusers',
5610: permission => ($permission->{'view'} || $permission->{'cusr'}),
1.318 raeburn 5611: linktitle => $linktitles{$linkcontext}{'listusers'},
1.298 droeschl 5612: },
5613:
5614: ]},
5615:
5616: {categorytitle => 'Administration',
5617: items => [ ]},
5618: );
1.406.2.5 raeburn 5619:
1.265 mielkec 5620: if ($context eq 'domain'){
1.406.2.5 raeburn 5621: push(@{ $menu[0]->{items} }, # Single Users
5622: {
5623: linktext => 'User Access Log',
5624: icon => 'document-properties.png',
1.406.2.8 raeburn 5625: #help => 'Domain_User_Access_Logs',
1.406.2.5 raeburn 5626: url => '/adm/createuser?action=accesslogs',
5627: permission => $permission->{'activity'},
5628: linktitle => 'View user access log.',
5629: }
5630: );
1.298 droeschl 5631:
5632: push(@{ $menu[2]->{items} }, #Category: Administration
5633: {
5634: linktext => 'Custom Roles',
5635: icon => 'emblem-photos.png',
5636: #help => 'Course_Editing_Custom_Roles',
5637: url => '/adm/createuser?action=custom',
5638: permission => $permission->{'custom'},
5639: linktitle => 'Configure a custom role.',
5640: },
1.362 raeburn 5641: {
5642: linktext => 'Authoring Space Requests',
5643: icon => 'selfenrl-queue.png',
5644: #help => 'Domain_Role_Approvals',
5645: url => '/adm/createuser?action=processauthorreq',
5646: permission => $permission->{'cusr'},
5647: linktitle => 'Approve or reject author role requests',
5648: },
1.363 raeburn 5649: {
1.391 raeburn 5650: linktext => 'LON-CAPA Account Requests',
5651: icon => 'list-add.png',
5652: #help => 'Domain_Username_Approvals',
5653: url => '/adm/createuser?action=processusernamereq',
5654: permission => $permission->{'cusr'},
5655: linktitle => 'Approve or reject LON-CAPA account requests',
5656: },
5657: {
1.363 raeburn 5658: linktext => 'Change Log',
5659: icon => 'document-properties.png',
5660: #help => 'Course_User_Logs',
5661: url => '/adm/createuser?action=changelogs',
1.406.2.6 raeburn 5662: permission => ($permission->{'cusr'} || $permission->{'view'}),
1.363 raeburn 5663: linktitle => 'View change log.',
5664: },
1.298 droeschl 5665: );
5666:
1.265 mielkec 5667: }elsif ($context eq 'course'){
1.298 droeschl 5668: my ($cnum,$cdom) = &Apache::lonuserutils::get_course_identity();
1.318 raeburn 5669:
5670: my %linktext = (
5671: 'Course' => {
5672: single => 'Add/Modify a Student',
5673: drop => 'Drop Students',
5674: groups => 'Course Groups',
5675: },
5676: 'Community' => {
5677: single => 'Add/Modify a Member',
5678: drop => 'Drop Members',
5679: groups => 'Community Groups',
5680: },
5681: );
5682:
5683: my %linktitle = (
5684: 'Course' => {
5685: single => 'Add a user with the role of student to this course',
5686: drop => 'Remove a student from this course.',
5687: groups => 'Manage course groups',
5688: },
5689: 'Community' => {
5690: single => 'Add a user with the role of member to this community',
5691: drop => 'Remove a member from this community.',
5692: groups => 'Manage community groups',
5693: },
5694: );
5695:
1.298 droeschl 5696: push(@{ $menu[0]->{items} }, #Category: Single Users
5697: {
1.318 raeburn 5698: linktext => $linktext{$crstype}{'single'},
1.298 droeschl 5699: #help => 'Course_Add_Student',
5700: icon => 'list-add.png',
5701: url => '/adm/createuser?action=singlestudent',
5702: permission => $permission->{'cusr'},
1.318 raeburn 5703: linktitle => $linktitle{$crstype}{'single'},
1.298 droeschl 5704: },
5705: );
5706:
5707: push(@{ $menu[1]->{items} }, #Category: Multiple Users
5708: {
1.318 raeburn 5709: linktext => $linktext{$crstype}{'drop'},
1.298 droeschl 5710: icon => 'edit-undo.png',
5711: #help => 'Course_Drop_Student',
5712: url => '/adm/createuser?action=drop',
5713: permission => $permission->{'cusr'},
1.318 raeburn 5714: linktitle => $linktitle{$crstype}{'drop'},
1.298 droeschl 5715: },
5716: );
5717: push(@{ $menu[2]->{items} }, #Category: Administration
1.406.2.11 raeburn 5718: {
5719: linktext => 'Helpdesk Access',
5720: icon => 'helpdesk-access.png',
5721: #help => 'Course_Helpdesk_Access',
5722: url => '/adm/createuser?action=helpdesk',
5723: permission => ($permission->{'owner'} || $permission->{'co-owner'}),
5724: linktitle => 'Helpdesk access options',
5725: },
5726: {
1.298 droeschl 5727: linktext => 'Custom Roles',
5728: icon => 'emblem-photos.png',
5729: #help => 'Course_Editing_Custom_Roles',
5730: url => '/adm/createuser?action=custom',
5731: permission => $permission->{'custom'},
5732: linktitle => 'Configure a custom role.',
5733: },
5734: {
1.318 raeburn 5735: linktext => $linktext{$crstype}{'groups'},
1.333 wenzelju 5736: icon => 'grps.png',
1.298 droeschl 5737: #help => 'Course_Manage_Group',
5738: url => '/adm/coursegroups?refpage=cusr',
5739: permission => $permission->{'grp_manage'},
1.318 raeburn 5740: linktitle => $linktitle{$crstype}{'groups'},
1.298 droeschl 5741: },
5742: {
1.328 wenzelju 5743: linktext => 'Change Log',
1.298 droeschl 5744: icon => 'document-properties.png',
5745: #help => 'Course_User_Logs',
5746: url => '/adm/createuser?action=changelogs',
1.406.2.6 raeburn 5747: permission => ($permission->{'view'} || $permission->{'cusr'}),
1.298 droeschl 5748: linktitle => 'View change log.',
5749: },
5750: );
1.277 raeburn 5751: if ($env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_approval'}) {
1.298 droeschl 5752: push(@{ $menu[2]->{items} },
1.398 raeburn 5753: {
1.298 droeschl 5754: linktext => 'Enrollment Requests',
5755: icon => 'selfenrl-queue.png',
5756: #help => 'Course_Approve_Selfenroll',
5757: url => '/adm/createuser?action=selfenrollqueue',
1.398 raeburn 5758: permission => $permission->{'selfenrolladmin'},
1.298 droeschl 5759: linktitle =>'Approve or reject enrollment requests.',
5760: },
5761: );
1.277 raeburn 5762: }
1.298 droeschl 5763:
1.265 mielkec 5764: if (!exists($permission->{'cusr_section'})){
1.320 raeburn 5765: if ($crstype ne 'Community') {
5766: push(@{ $menu[2]->{items} },
5767: {
5768: linktext => 'Automated Enrollment',
5769: icon => 'roles.png',
5770: #help => 'Course_Automated_Enrollment',
5771: permission => (&Apache::lonnet::auto_run($cnum,$cdom)
1.406.2.6 raeburn 5772: && (($permission->{'cusr'}) ||
5773: ($permission->{'view'}))),
1.320 raeburn 5774: url => '/adm/populate',
5775: linktitle => 'Automated enrollment manager.',
5776: }
5777: );
5778: }
5779: push(@{ $menu[2]->{items} },
1.298 droeschl 5780: {
5781: linktext => 'User Self-Enrollment',
1.342 wenzelju 5782: icon => 'self_enroll.png',
1.298 droeschl 5783: #help => 'Course_Self_Enrollment',
5784: url => '/adm/createuser?action=selfenroll',
1.398 raeburn 5785: permission => $permission->{'selfenrolladmin'},
1.317 bisitz 5786: linktitle => 'Configure user self-enrollment.',
1.298 droeschl 5787: },
5788: );
5789: }
1.363 raeburn 5790: } elsif ($context eq 'author') {
1.370 raeburn 5791: push(@{ $menu[2]->{items} }, #Category: Administration
1.363 raeburn 5792: {
5793: linktext => 'Change Log',
5794: icon => 'document-properties.png',
5795: #help => 'Course_User_Logs',
5796: url => '/adm/createuser?action=changelogs',
5797: permission => $permission->{'cusr'},
5798: linktitle => 'View change log.',
5799: },
1.370 raeburn 5800: );
1.363 raeburn 5801: }
5802: return Apache::lonhtmlcommon::generate_menu(@menu);
1.250 raeburn 5803: # { text => 'View Log-in History',
5804: # help => 'Course_User_Logins',
5805: # action => 'logins',
5806: # permission => $permission->{'cusr'},
5807: # });
1.190 raeburn 5808: }
5809:
1.189 albertel 5810: sub restore_prev_selections {
5811: my %saveable_parameters = ('srchby' => 'scalar',
5812: 'srchin' => 'scalar',
5813: 'srchtype' => 'scalar',
5814: );
5815: &Apache::loncommon::store_settings('user','user_picker',
5816: \%saveable_parameters);
5817: &Apache::loncommon::restore_settings('user','user_picker',
5818: \%saveable_parameters);
5819: }
5820:
1.237 raeburn 5821: sub print_selfenroll_menu {
1.406.2.6 raeburn 5822: my ($r,$context,$cid,$cdom,$cnum,$currsettings,$additional,$readonly) = @_;
1.322 raeburn 5823: my $crstype = &Apache::loncommon::course_type();
1.398 raeburn 5824: my $formname = 'selfenroll';
1.237 raeburn 5825: my $nolink = 1;
1.398 raeburn 5826: my ($row,$lt) = &Apache::lonuserutils::get_selfenroll_titles();
1.237 raeburn 5827: my $groupslist = &Apache::lonuserutils::get_groupslist();
5828: my $setsec_js =
5829: &Apache::lonuserutils::setsections_javascript($formname,$groupslist);
1.249 raeburn 5830: my %alerts = &Apache::lonlocal::texthash(
5831: acto => 'Activation of self-enrollment was selected for the following domain(s)',
5832: butn => 'but no user types have been checked.',
5833: wilf => "Please uncheck 'activate' or check at least one type.",
5834: );
1.406.2.6 raeburn 5835: my $disabled;
5836: if ($readonly) {
5837: $disabled = ' disabled="disabled"';
5838: }
1.405 damieng 5839: &js_escape(\%alerts);
1.249 raeburn 5840: my $selfenroll_js = <<"ENDSCRIPT";
5841: function update_types(caller,num) {
5842: var delidx = getIndexByName('selfenroll_delete');
5843: var actidx = getIndexByName('selfenroll_activate');
5844: if (caller == 'selfenroll_all') {
5845: var selall;
5846: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
5847: if (document.$formname.selfenroll_all[i].checked) {
5848: selall = document.$formname.selfenroll_all[i].value;
5849: }
5850: }
5851: if (selall == 1) {
5852: if (delidx != -1) {
5853: if (document.$formname.selfenroll_delete.length) {
5854: for (var j=0; j<document.$formname.selfenroll_delete.length; j++) {
5855: document.$formname.selfenroll_delete[j].checked = true;
5856: }
5857: } else {
5858: document.$formname.elements[delidx].checked = true;
5859: }
5860: }
5861: if (actidx != -1) {
5862: if (document.$formname.selfenroll_activate.length) {
5863: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
5864: document.$formname.selfenroll_activate[j].checked = false;
5865: }
5866: } else {
5867: document.$formname.elements[actidx].checked = false;
5868: }
5869: }
5870: document.$formname.selfenroll_newdom.selectedIndex = 0;
5871: }
5872: }
5873: if (caller == 'selfenroll_activate') {
5874: if (document.$formname.selfenroll_activate.length) {
5875: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
5876: if (document.$formname.selfenroll_activate[j].value == num) {
5877: if (document.$formname.selfenroll_activate[j].checked) {
5878: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
5879: if (document.$formname.selfenroll_all[i].value == '1') {
5880: document.$formname.selfenroll_all[i].checked = false;
5881: }
5882: if (document.$formname.selfenroll_all[i].value == '0') {
5883: document.$formname.selfenroll_all[i].checked = true;
5884: }
5885: }
5886: }
5887: }
5888: }
5889: } else {
5890: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
5891: if (document.$formname.selfenroll_all[i].value == '1') {
5892: document.$formname.selfenroll_all[i].checked = false;
5893: }
5894: if (document.$formname.selfenroll_all[i].value == '0') {
5895: document.$formname.selfenroll_all[i].checked = true;
5896: }
5897: }
5898: }
5899: }
5900: if (caller == 'selfenroll_delete') {
5901: if (document.$formname.selfenroll_delete.length) {
5902: for (var j=0; j<document.$formname.selfenroll_delete.length; j++) {
5903: if (document.$formname.selfenroll_delete[j].value == num) {
5904: if (document.$formname.selfenroll_delete[j].checked) {
5905: var delindex = getIndexByName('selfenroll_types_'+num);
5906: if (delindex != -1) {
5907: if (document.$formname.elements[delindex].length) {
5908: for (var k=0; k<document.$formname.elements[delindex].length; k++) {
5909: document.$formname.elements[delindex][k].checked = false;
5910: }
5911: } else {
5912: document.$formname.elements[delindex].checked = false;
5913: }
5914: }
5915: }
5916: }
5917: }
5918: } else {
5919: if (document.$formname.selfenroll_delete.checked) {
5920: var delindex = getIndexByName('selfenroll_types_'+num);
5921: if (delindex != -1) {
5922: if (document.$formname.elements[delindex].length) {
5923: for (var k=0; k<document.$formname.elements[delindex].length; k++) {
5924: document.$formname.elements[delindex][k].checked = false;
5925: }
5926: } else {
5927: document.$formname.elements[delindex].checked = false;
5928: }
5929: }
5930: }
5931: }
5932: }
5933: return;
5934: }
5935:
5936: function validate_types(form) {
5937: var needaction = new Array();
5938: var countfail = 0;
5939: var actidx = getIndexByName('selfenroll_activate');
5940: if (actidx != -1) {
5941: if (document.$formname.selfenroll_activate.length) {
5942: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
5943: var num = document.$formname.selfenroll_activate[j].value;
5944: if (document.$formname.selfenroll_activate[j].checked) {
5945: countfail = check_types(num,countfail,needaction)
5946: }
5947: }
5948: } else {
5949: if (document.$formname.selfenroll_activate.checked) {
1.398 raeburn 5950: var num = document.$formname.selfenroll_activate.value;
1.249 raeburn 5951: countfail = check_types(num,countfail,needaction)
5952: }
5953: }
5954: }
5955: if (countfail > 0) {
5956: var msg = "$alerts{'acto'}\\n";
5957: var loopend = needaction.length -1;
5958: if (loopend > 0) {
5959: for (var m=0; m<loopend; m++) {
5960: msg += needaction[m]+", ";
5961: }
5962: }
5963: msg += needaction[loopend]+"\\n$alerts{'butn'}\\n$alerts{'wilf'}";
5964: alert(msg);
5965: return;
5966: }
5967: setSections(form);
5968: }
5969:
5970: function check_types(num,countfail,needaction) {
1.406.2.15 raeburn 5971: var boxname = 'selfenroll_types_'+num;
5972: var typeidx = getIndexByName(boxname);
1.249 raeburn 5973: var count = 0;
5974: if (typeidx != -1) {
1.406.2.15 raeburn 5975: if (document.$formname.elements[boxname].length) {
5976: for (var k=0; k<document.$formname.elements[boxname].length; k++) {
5977: if (document.$formname.elements[boxname][k].checked) {
1.249 raeburn 5978: count ++;
5979: }
5980: }
5981: } else {
5982: if (document.$formname.elements[typeidx].checked) {
5983: count ++;
5984: }
5985: }
5986: if (count == 0) {
5987: var domidx = getIndexByName('selfenroll_dom_'+num);
5988: if (domidx != -1) {
5989: var domname = document.$formname.elements[domidx].value;
5990: needaction[countfail] = domname;
5991: countfail ++;
5992: }
5993: }
5994: }
5995: return countfail;
5996: }
5997:
1.398 raeburn 5998: function toggleNotify() {
5999: var selfenrollApproval = 0;
6000: if (document.$formname.selfenroll_approval.length) {
6001: for (var i=0; i<document.$formname.selfenroll_approval.length; i++) {
6002: if (document.$formname.selfenroll_approval[i].checked) {
6003: selfenrollApproval = document.$formname.selfenroll_approval[i].value;
6004: break;
6005: }
6006: }
6007: }
6008: if (document.getElementById('notified')) {
6009: if (selfenrollApproval == 0) {
6010: document.getElementById('notified').style.display='none';
6011: } else {
6012: document.getElementById('notified').style.display='block';
6013: }
6014: }
6015: return;
6016: }
6017:
1.249 raeburn 6018: function getIndexByName(item) {
6019: for (var i=0;i<document.$formname.elements.length;i++) {
6020: if (document.$formname.elements[i].name == item) {
6021: return i;
6022: }
6023: }
6024: return -1;
6025: }
6026: ENDSCRIPT
1.256 raeburn 6027:
1.237 raeburn 6028: my $output = '<script type="text/javascript">'."\n".
1.301 bisitz 6029: '// <![CDATA['."\n".
1.249 raeburn 6030: $setsec_js."\n".$selfenroll_js."\n".
1.301 bisitz 6031: '// ]]>'."\n".
1.237 raeburn 6032: '</script>'."\n".
1.256 raeburn 6033: '<h3>'.$lt->{'selfenroll'}.'</h3>'."\n";
1.400 raeburn 6034:
6035: my $visactions = &cat_visibility();
6036: my ($cathash,%cattype);
6037: my %domconfig = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom);
6038: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
6039: $cathash = $domconfig{'coursecategories'}{'cats'};
6040: $cattype{'auth'} = $domconfig{'coursecategories'}{'auth'};
6041: $cattype{'unauth'} = $domconfig{'coursecategories'}{'unauth'};
1.406 raeburn 6042: if ($cattype{'auth'} eq '') {
6043: $cattype{'auth'} = 'std';
6044: }
6045: if ($cattype{'unauth'} eq '') {
6046: $cattype{'unauth'} = 'std';
6047: }
1.400 raeburn 6048: } else {
6049: $cathash = {};
6050: $cattype{'auth'} = 'std';
6051: $cattype{'unauth'} = 'std';
6052: }
6053: if (($cattype{'auth'} eq 'none') && ($cattype{'unauth'} eq 'none')) {
6054: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
6055: '<br />'.
6056: '<br />'.$visactions->{'take'}.'<ul>'.
6057: '<li>'.$visactions->{'dc_chgconf'}.'</li>'.
6058: '</ul>');
6059: } elsif (($cattype{'auth'} !~ /^(std|domonly)$/) && ($cattype{'unauth'} !~ /^(std|domonly)$/)) {
6060: if ($currsettings->{'uniquecode'}) {
6061: $r->print('<span class="LC_info">'.$visactions->{'vis'}.'</span>');
6062: } else {
6063: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
6064: '<br />'.
6065: '<br />'.$visactions->{'take'}.'<ul>'.
6066: '<li>'.$visactions->{'dc_setcode'}.'</li>'.
6067: '</ul><br />');
6068: }
6069: } else {
6070: my ($visible,$cansetvis,$vismsgs) = &visible_in_stdcat($cdom,$cnum,\%domconfig);
6071: if (ref($visactions) eq 'HASH') {
6072: if ($visible) {
6073: $output .= '<p class="LC_info">'.$visactions->{'vis'}.'</p>';
6074: } else {
6075: $output .= '<p class="LC_warning">'.$visactions->{'miss'}.'</p>'
6076: .$visactions->{'yous'}.
6077: '<p>'.$visactions->{'gen'}.'<br />'.$visactions->{'coca'};
6078: if (ref($vismsgs) eq 'ARRAY') {
6079: $output .= '<br />'.$visactions->{'make'}.'<ul>';
6080: foreach my $item (@{$vismsgs}) {
6081: $output .= '<li>'.$visactions->{$item}.'</li>';
6082: }
6083: $output .= '</ul>';
1.256 raeburn 6084: }
1.400 raeburn 6085: $output .= '</p>';
1.256 raeburn 6086: }
6087: }
6088: }
1.398 raeburn 6089: my $actionhref = '/adm/createuser';
6090: if ($context eq 'domain') {
6091: $actionhref = '/adm/modifycourse';
6092: }
1.400 raeburn 6093:
6094: my %noedit;
6095: unless ($context eq 'domain') {
6096: %noedit = &get_noedit_fields($cdom,$cnum,$crstype,$row);
6097: }
1.398 raeburn 6098: $output .= '<form name="'.$formname.'" method="post" action="'.$actionhref.'">'."\n".
1.256 raeburn 6099: &Apache::lonhtmlcommon::start_pick_box();
1.237 raeburn 6100: if (ref($row) eq 'ARRAY') {
6101: foreach my $item (@{$row}) {
6102: my $title = $item;
6103: if (ref($lt) eq 'HASH') {
6104: $title = $lt->{$item};
6105: }
1.297 bisitz 6106: $output .= &Apache::lonhtmlcommon::row_title($title);
1.237 raeburn 6107: if ($item eq 'types') {
1.398 raeburn 6108: my $curr_types;
6109: if (ref($currsettings) eq 'HASH') {
6110: $curr_types = $currsettings->{'selfenroll_types'};
6111: }
1.400 raeburn 6112: if ($noedit{$item}) {
6113: if ($curr_types eq '*') {
6114: $output .= &mt('Any user in any domain');
6115: } else {
6116: my @entries = split(/;/,$curr_types);
6117: if (@entries > 0) {
6118: $output .= '<ul>';
6119: foreach my $entry (@entries) {
6120: my ($currdom,$typestr) = split(/:/,$entry);
6121: next if ($typestr eq '');
6122: my $domdesc = &Apache::lonnet::domain($currdom);
6123: my @currinsttypes = split(',',$typestr);
6124: my ($othertitle,$usertypes,$types) =
6125: &Apache::loncommon::sorted_inst_types($currdom);
6126: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
6127: $usertypes->{'any'} = &mt('any user');
6128: if (keys(%{$usertypes}) > 0) {
6129: $usertypes->{'other'} = &mt('other users');
6130: }
6131: my @longinsttypes = map { $usertypes->{$_}; } @currinsttypes;
6132: $output .= '<li>'.$domdesc.':'.join(', ',@longinsttypes).'</li>';
6133: }
6134: }
6135: $output .= '</ul>';
6136: } else {
6137: $output .= &mt('None');
6138: }
6139: }
6140: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6141: next;
6142: }
1.241 raeburn 6143: my $showdomdesc = 1;
6144: my $includeempty = 1;
6145: my $num = 0;
6146: $output .= &Apache::loncommon::start_data_table().
6147: &Apache::loncommon::start_data_table_row()
6148: .'<td colspan="2"><span class="LC_nobreak"><label>'
6149: .&mt('Any user in any domain:')
6150: .' <input type="radio" name="selfenroll_all" value="1" ';
6151: if ($curr_types eq '*') {
6152: $output .= ' checked="checked" ';
6153: }
1.249 raeburn 6154: $output .= 'onchange="javascript:update_types('.
1.406.2.6 raeburn 6155: "'selfenroll_all'".');"'.$disabled.' />'.&mt('Yes').'</label>'.
1.249 raeburn 6156: ' <input type="radio" name="selfenroll_all" value="0" ';
1.241 raeburn 6157: if ($curr_types ne '*') {
6158: $output .= ' checked="checked" ';
6159: }
1.249 raeburn 6160: $output .= ' onchange="javascript:update_types('.
1.406.2.6 raeburn 6161: "'selfenroll_all'".');"'.$disabled.' />'.&mt('No').'</label></td>'.
1.249 raeburn 6162: &Apache::loncommon::end_data_table_row().
6163: &Apache::loncommon::end_data_table().
6164: &mt('Or').'<br />'.
6165: &Apache::loncommon::start_data_table();
1.241 raeburn 6166: my %currdoms;
1.249 raeburn 6167: if ($curr_types eq '') {
1.241 raeburn 6168: $output .= &new_selfenroll_dom_row($cdom,'0');
6169: } elsif ($curr_types ne '*') {
6170: my @entries = split(/;/,$curr_types);
6171: if (@entries > 0) {
6172: foreach my $entry (@entries) {
6173: my ($currdom,$typestr) = split(/:/,$entry);
6174: $currdoms{$currdom} = 1;
6175: my $domdesc = &Apache::lonnet::domain($currdom);
1.249 raeburn 6176: my @currinsttypes = split(',',$typestr);
1.241 raeburn 6177: $output .= &Apache::loncommon::start_data_table_row()
6178: .'<td valign="top"><span class="LC_nobreak">'.&mt('Domain:').'<b>'
6179: .' '.$domdesc.' ('.$currdom.')'
6180: .'</b><input type="hidden" name="selfenroll_dom_'.$num
6181: .'" value="'.$currdom.'" /></span><br />'
6182: .'<span class="LC_nobreak"><label><input type="checkbox" '
1.406.2.6 raeburn 6183: .'name="selfenroll_delete" value="'.$num.'" onchange="javascript:update_types('."'selfenroll_delete','$num'".');"'.$disabled.' />'
1.241 raeburn 6184: .&mt('Delete').'</label></span></td>';
1.249 raeburn 6185: $output .= '<td valign="top"> '.&mt('User types:').'<br />'
1.406.2.6 raeburn 6186: .&selfenroll_inst_types($num,$currdom,\@currinsttypes,$readonly).'</td>'
1.241 raeburn 6187: .&Apache::loncommon::end_data_table_row();
6188: $num ++;
6189: }
6190: }
6191: }
1.249 raeburn 6192: my $add_domtitle = &mt('Users in additional domain:');
1.241 raeburn 6193: if ($curr_types eq '*') {
1.249 raeburn 6194: $add_domtitle = &mt('Users in specific domain:');
1.241 raeburn 6195: } elsif ($curr_types eq '') {
1.249 raeburn 6196: $add_domtitle = &mt('Users in other domain:');
1.241 raeburn 6197: }
6198: $output .= &Apache::loncommon::start_data_table_row()
6199: .'<td colspan="2"><span class="LC_nobreak">'.$add_domtitle.'</span><br />'
6200: .&Apache::loncommon::select_dom_form('','selfenroll_newdom',
1.406.2.6 raeburn 6201: $includeempty,$showdomdesc,'','','',$readonly)
1.241 raeburn 6202: .'<input type="hidden" name="selfenroll_types_total" value="'.$num.'" />'
6203: .'</td>'.&Apache::loncommon::end_data_table_row()
6204: .&Apache::loncommon::end_data_table();
1.237 raeburn 6205: } elsif ($item eq 'registered') {
6206: my ($regon,$regoff);
1.398 raeburn 6207: my $registered;
6208: if (ref($currsettings) eq 'HASH') {
6209: $registered = $currsettings->{'selfenroll_registered'};
6210: }
1.400 raeburn 6211: if ($noedit{$item}) {
6212: if ($registered) {
6213: $output .= &mt('Must be registered in course');
6214: } else {
6215: $output .= &mt('No requirement');
6216: }
6217: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6218: next;
6219: }
1.398 raeburn 6220: if ($registered) {
1.237 raeburn 6221: $regon = ' checked="checked" ';
1.406.2.6 raeburn 6222: $regoff = '';
1.237 raeburn 6223: } else {
1.406.2.6 raeburn 6224: $regon = '';
1.237 raeburn 6225: $regoff = ' checked="checked" ';
6226: }
6227: $output .= '<label>'.
1.406.2.6 raeburn 6228: '<input type="radio" name="selfenroll_registered" value="1"'.$regon.$disabled.' />'.
1.244 bisitz 6229: &mt('Yes').'</label> <label>'.
1.406.2.6 raeburn 6230: '<input type="radio" name="selfenroll_registered" value="0"'.$regoff.$disabled.' />'.
1.244 bisitz 6231: &mt('No').'</label>';
1.237 raeburn 6232: } elsif ($item eq 'enroll_dates') {
1.398 raeburn 6233: my ($starttime,$endtime);
6234: if (ref($currsettings) eq 'HASH') {
6235: $starttime = $currsettings->{'selfenroll_start_date'};
6236: $endtime = $currsettings->{'selfenroll_end_date'};
6237: if ($starttime eq '') {
6238: $starttime = $currsettings->{'default_enrollment_start_date'};
6239: }
6240: if ($endtime eq '') {
6241: $endtime = $currsettings->{'default_enrollment_end_date'};
6242: }
1.237 raeburn 6243: }
1.400 raeburn 6244: if ($noedit{$item}) {
6245: $output .= &mt('From: [_1], to: [_2]',&Apache::lonlocal::locallocaltime($starttime),
6246: &Apache::lonlocal::locallocaltime($endtime));
6247: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6248: next;
6249: }
1.237 raeburn 6250: my $startform =
6251: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_start_date',$starttime,
1.406.2.6 raeburn 6252: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
1.237 raeburn 6253: my $endform =
6254: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_end_date',$endtime,
1.406.2.6 raeburn 6255: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
1.237 raeburn 6256: $output .= &selfenroll_date_forms($startform,$endform);
6257: } elsif ($item eq 'access_dates') {
1.398 raeburn 6258: my ($starttime,$endtime);
6259: if (ref($currsettings) eq 'HASH') {
6260: $starttime = $currsettings->{'selfenroll_start_access'};
6261: $endtime = $currsettings->{'selfenroll_end_access'};
6262: if ($starttime eq '') {
6263: $starttime = $currsettings->{'default_enrollment_start_date'};
6264: }
6265: if ($endtime eq '') {
6266: $endtime = $currsettings->{'default_enrollment_end_date'};
6267: }
1.237 raeburn 6268: }
1.400 raeburn 6269: if ($noedit{$item}) {
6270: $output .= &mt('From: [_1], to: [_2]',&Apache::lonlocal::locallocaltime($starttime),
6271: &Apache::lonlocal::locallocaltime($endtime));
6272: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6273: next;
6274: }
1.237 raeburn 6275: my $startform =
6276: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_start_access',$starttime,
1.406.2.6 raeburn 6277: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
1.237 raeburn 6278: my $endform =
6279: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_end_access',$endtime,
1.406.2.6 raeburn 6280: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
1.237 raeburn 6281: $output .= &selfenroll_date_forms($startform,$endform);
6282: } elsif ($item eq 'section') {
1.398 raeburn 6283: my $currsec;
6284: if (ref($currsettings) eq 'HASH') {
6285: $currsec = $currsettings->{'selfenroll_section'};
6286: }
1.237 raeburn 6287: my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum);
6288: my $newsecval;
6289: if ($currsec ne 'none' && $currsec ne '') {
6290: if (!defined($sections_count{$currsec})) {
6291: $newsecval = $currsec;
6292: }
6293: }
1.400 raeburn 6294: if ($noedit{$item}) {
6295: if ($currsec ne '') {
6296: $output .= $currsec;
6297: } else {
6298: $output .= &mt('No specific section');
6299: }
6300: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6301: next;
6302: }
1.237 raeburn 6303: my $sections_select =
1.406.2.6 raeburn 6304: &Apache::lonuserutils::course_sections(\%sections_count,'st',$currsec,$disabled);
1.237 raeburn 6305: $output .= '<table class="LC_createuser">'."\n".
6306: '<tr class="LC_section_row">'."\n".
6307: '<td align="center">'.&mt('Existing sections')."\n".
6308: '<br />'.$sections_select.'</td><td align="center">'.
6309: &mt('New section').'<br />'."\n".
1.406.2.6 raeburn 6310: '<input type="text" name="newsec" size="15" value="'.$newsecval.'"'.$disabled.' />'."\n".
1.237 raeburn 6311: '<input type="hidden" name="sections" value="" />'."\n".
6312: '</td></tr></table>'."\n";
1.276 raeburn 6313: } elsif ($item eq 'approval') {
1.398 raeburn 6314: my ($currnotified,$currapproval,%appchecked);
6315: my %selfdescs = &Apache::lonuserutils::selfenroll_default_descs();
1.406.2.6 raeburn 6316: if (ref($currsettings) eq 'HASH') {
1.398 raeburn 6317: $currnotified = $currsettings->{'selfenroll_notifylist'};
6318: $currapproval = $currsettings->{'selfenroll_approval'};
6319: }
6320: if ($currapproval !~ /^[012]$/) {
6321: $currapproval = 0;
6322: }
1.400 raeburn 6323: if ($noedit{$item}) {
6324: $output .= $selfdescs{'approval'}{$currapproval}.
6325: '<br />'.&mt('(Set by Domain Coordinator)');
6326: next;
6327: }
1.398 raeburn 6328: $appchecked{$currapproval} = ' checked="checked"';
6329: for my $i (0..2) {
6330: $output .= '<label>'.
6331: '<input type="radio" name="selfenroll_approval" value="'.$i.'"'.
1.406.2.6 raeburn 6332: $appchecked{$i}.' onclick="toggleNotify();"'.$disabled.' />'.
6333: $selfdescs{'approval'}{$i}.'</label>'.(' 'x2);
1.276 raeburn 6334: }
6335: my %advhash = &Apache::lonnet::get_course_adv_roles($cid,1);
6336: my (@ccs,%notified);
1.322 raeburn 6337: my $ccrole = 'cc';
6338: if ($crstype eq 'Community') {
6339: $ccrole = 'co';
6340: }
6341: if ($advhash{$ccrole}) {
6342: @ccs = split(/,/,$advhash{$ccrole});
1.276 raeburn 6343: }
6344: if ($currnotified) {
6345: foreach my $current (split(/,/,$currnotified)) {
6346: $notified{$current} = 1;
6347: if (!grep(/^\Q$current\E$/,@ccs)) {
6348: push(@ccs,$current);
6349: }
6350: }
6351: }
6352: if (@ccs) {
1.398 raeburn 6353: my $style;
6354: unless ($currapproval) {
6355: $style = ' style="display: none;"';
6356: }
6357: $output .= '<br /><div id="notified"'.$style.'>'.
6358: &mt('Personnel to be notified when an enrollment request needs approval, or has been approved:').' '.
6359: &Apache::loncommon::start_data_table().
1.276 raeburn 6360: &Apache::loncommon::start_data_table_row();
6361: my $count = 0;
6362: my $numcols = 4;
6363: foreach my $cc (sort(@ccs)) {
6364: my $notifyon;
6365: my ($ccuname,$ccudom) = split(/:/,$cc);
6366: if ($notified{$cc}) {
6367: $notifyon = ' checked="checked" ';
6368: }
6369: if ($count && !$count%$numcols) {
6370: $output .= &Apache::loncommon::end_data_table_row().
6371: &Apache::loncommon::start_data_table_row()
6372: }
6373: $output .= '<td><span class="LC_nobreak"><label>'.
1.406.2.6 raeburn 6374: '<input type="checkbox" name="selfenroll_notify"'.$notifyon.' value="'.$cc.'"'.$disabled.' />'.
1.276 raeburn 6375: &Apache::loncommon::plainname($ccuname,$ccudom).
6376: '</label></span></td>';
1.343 raeburn 6377: $count ++;
1.276 raeburn 6378: }
6379: my $rem = $count%$numcols;
6380: if ($rem) {
6381: my $emptycols = $numcols - $rem;
6382: for (my $i=0; $i<$emptycols; $i++) {
6383: $output .= '<td> </td>';
6384: }
6385: }
6386: $output .= &Apache::loncommon::end_data_table_row().
1.398 raeburn 6387: &Apache::loncommon::end_data_table().
6388: '</div>';
1.276 raeburn 6389: }
6390: } elsif ($item eq 'limit') {
1.398 raeburn 6391: my ($crslimit,$selflimit,$nolimit,$currlim,$currcap);
6392: if (ref($currsettings) eq 'HASH') {
6393: $currlim = $currsettings->{'selfenroll_limit'};
6394: $currcap = $currsettings->{'selfenroll_cap'};
6395: }
1.400 raeburn 6396: if ($noedit{$item}) {
6397: if (($currlim eq 'allstudents') || ($currlim eq 'selfenrolled')) {
6398: if ($currlim eq 'allstudents') {
6399: $output .= &mt('Limit by total students');
6400: } elsif ($currlim eq 'selfenrolled') {
6401: $output .= &mt('Limit by total self-enrolled students');
6402: }
6403: $output .= ' '.&mt('Maximum: [_1]',$currcap).
6404: '<br />'.&mt('(Set by Domain Coordinator)');
6405: } else {
6406: $output .= &mt('No limit').'<br />'.&mt('(Set by Domain Coordinator)');
6407: }
6408: next;
6409: }
1.276 raeburn 6410: if ($currlim eq 'allstudents') {
6411: $crslimit = ' checked="checked" ';
6412: $selflimit = ' ';
6413: $nolimit = ' ';
6414: } elsif ($currlim eq 'selfenrolled') {
6415: $crslimit = ' ';
6416: $selflimit = ' checked="checked" ';
6417: $nolimit = ' ';
6418: } else {
6419: $crslimit = ' ';
6420: $selflimit = ' ';
1.398 raeburn 6421: $nolimit = ' checked="checked" ';
1.276 raeburn 6422: }
6423: $output .= '<table><tr><td><label>'.
1.406.2.6 raeburn 6424: '<input type="radio" name="selfenroll_limit" value="none"'.$nolimit.$disabled.'/>'.
1.276 raeburn 6425: &mt('No limit').'</label></td><td><label>'.
1.406.2.6 raeburn 6426: '<input type="radio" name="selfenroll_limit" value="allstudents"'.$crslimit.$disabled.'/>'.
1.276 raeburn 6427: &mt('Limit by total students').'</label></td><td><label>'.
1.406.2.6 raeburn 6428: '<input type="radio" name="selfenroll_limit" value="selfenrolled"'.$selflimit.$disabled.'/>'.
1.276 raeburn 6429: &mt('Limit by total self-enrolled students').
6430: '</td></tr><tr>'.
6431: '<td> </td><td colspan="2"><span class="LC_nobreak">'.
6432: (' 'x3).&mt('Maximum number allowed: ').
1.406.2.6 raeburn 6433: '<input type="text" name="selfenroll_cap" size = "5" value="'.$currcap.'"'.$disabled.' /></td></tr></table>';
1.237 raeburn 6434: }
6435: $output .= &Apache::lonhtmlcommon::row_closure(1);
6436: }
6437: }
1.406.2.6 raeburn 6438: $output .= &Apache::lonhtmlcommon::end_pick_box().'<br />';
6439: unless ($readonly) {
6440: $output .= '<input type="button" name="selfenrollconf" value="'
6441: .&mt('Save').'" onclick="validate_types(this.form);" />';
6442: }
6443: $output .= '<input type="hidden" name="action" value="selfenroll" />'
1.406.2.11 raeburn 6444: .'<input type="hidden" name="state" value="done" />'."\n"
6445: .$additional.'</form>';
1.237 raeburn 6446: $r->print($output);
6447: return;
6448: }
6449:
1.400 raeburn 6450: sub get_noedit_fields {
6451: my ($cdom,$cnum,$crstype,$row) = @_;
6452: my %noedit;
6453: if (ref($row) eq 'ARRAY') {
6454: my %settings = &Apache::lonnet::get('environment',['internal.coursecode','internal.textbook',
6455: 'internal.selfenrollmgrdc',
6456: 'internal.selfenrollmgrcc'],$cdom,$cnum);
6457: my $type = &Apache::lonuserutils::get_extended_type($cdom,$cnum,$crstype,\%settings);
6458: my (%specific_managebydc,%specific_managebycc,%default_managebydc);
6459: map { $specific_managebydc{$_} = 1; } (split(/,/,$settings{'internal.selfenrollmgrdc'}));
6460: map { $specific_managebycc{$_} = 1; } (split(/,/,$settings{'internal.selfenrollmgrcc'}));
6461: my %domdefaults = &Apache::lonnet::get_domain_defaults($cdom);
6462: map { $default_managebydc{$_} = 1; } (split(/,/,$domdefaults{$type.'selfenrolladmdc'}));
6463:
6464: foreach my $item (@{$row}) {
6465: next if ($specific_managebycc{$item});
6466: if (($specific_managebydc{$item}) || ($default_managebydc{$item})) {
6467: $noedit{$item} = 1;
6468: }
6469: }
6470: }
6471: return %noedit;
6472: }
6473:
6474: sub visible_in_stdcat {
6475: my ($cdom,$cnum,$domconf) = @_;
6476: my ($cathash,%settable,@vismsgs,$cansetvis,$visible);
6477: unless (ref($domconf) eq 'HASH') {
6478: return ($visible,$cansetvis,\@vismsgs);
6479: }
6480: if (ref($domconf->{'coursecategories'}) eq 'HASH') {
6481: if ($domconf->{'coursecategories'}{'togglecats'} eq 'crs') {
1.256 raeburn 6482: $settable{'togglecats'} = 1;
6483: }
1.400 raeburn 6484: if ($domconf->{'coursecategories'}{'categorize'} eq 'crs') {
1.256 raeburn 6485: $settable{'categorize'} = 1;
6486: }
1.400 raeburn 6487: $cathash = $domconf->{'coursecategories'}{'cats'};
1.256 raeburn 6488: }
1.260 raeburn 6489: if ($settable{'togglecats'} && $settable{'categorize'}) {
1.256 raeburn 6490: $cansetvis = &mt('You are able to both assign a course category and choose to exclude this course from the catalog.');
6491: } elsif ($settable{'togglecats'}) {
6492: $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 6493: } elsif ($settable{'categorize'}) {
1.256 raeburn 6494: $cansetvis = &mt('You may assign a course category, but only a Domain Coordinator may choose to exclude this course from the catalog.');
6495: } else {
6496: $cansetvis = &mt('Only a Domain Coordinator may assign a course category or choose to exclude this course from the catalog.');
6497: }
6498:
6499: my %currsettings =
6500: &Apache::lonnet::get('environment',['hidefromcat','categories','internal.coursecode'],
6501: $cdom,$cnum);
1.400 raeburn 6502: $visible = 0;
1.256 raeburn 6503: if ($currsettings{'internal.coursecode'} ne '') {
1.400 raeburn 6504: if (ref($domconf->{'coursecategories'}) eq 'HASH') {
6505: $cathash = $domconf->{'coursecategories'}{'cats'};
1.256 raeburn 6506: if (ref($cathash) eq 'HASH') {
6507: if ($cathash->{'instcode::0'} eq '') {
6508: push(@vismsgs,'dc_addinst');
6509: } else {
6510: $visible = 1;
6511: }
6512: } else {
6513: $visible = 1;
6514: }
6515: } else {
6516: $visible = 1;
6517: }
6518: } else {
6519: if (ref($cathash) eq 'HASH') {
6520: if ($cathash->{'instcode::0'} ne '') {
6521: push(@vismsgs,'dc_instcode');
6522: }
6523: } else {
6524: push(@vismsgs,'dc_instcode');
6525: }
6526: }
6527: if ($currsettings{'categories'} ne '') {
6528: my $cathash;
1.400 raeburn 6529: if (ref($domconf->{'coursecategories'}) eq 'HASH') {
6530: $cathash = $domconf->{'coursecategories'}{'cats'};
1.256 raeburn 6531: if (ref($cathash) eq 'HASH') {
6532: if (keys(%{$cathash}) == 0) {
6533: push(@vismsgs,'dc_catalog');
6534: } elsif ((keys(%{$cathash}) == 1) && ($cathash->{'instcode::0'} ne '')) {
6535: push(@vismsgs,'dc_categories');
6536: } else {
6537: my @currcategories = split('&',$currsettings{'categories'});
6538: my $matched = 0;
6539: foreach my $cat (@currcategories) {
6540: if ($cathash->{$cat} ne '') {
6541: $visible = 1;
6542: $matched = 1;
6543: last;
6544: }
6545: }
6546: if (!$matched) {
1.260 raeburn 6547: if ($settable{'categorize'}) {
1.256 raeburn 6548: push(@vismsgs,'chgcat');
6549: } else {
6550: push(@vismsgs,'dc_chgcat');
6551: }
6552: }
6553: }
6554: }
6555: }
6556: } else {
6557: if (ref($cathash) eq 'HASH') {
6558: if ((keys(%{$cathash}) > 1) ||
6559: (keys(%{$cathash}) == 1) && ($cathash->{'instcode::0'} eq '')) {
1.260 raeburn 6560: if ($settable{'categorize'}) {
1.256 raeburn 6561: push(@vismsgs,'addcat');
6562: } else {
6563: push(@vismsgs,'dc_addcat');
6564: }
6565: }
6566: }
6567: }
6568: if ($currsettings{'hidefromcat'} eq 'yes') {
6569: $visible = 0;
6570: if ($settable{'togglecats'}) {
6571: unshift(@vismsgs,'unhide');
6572: } else {
6573: unshift(@vismsgs,'dc_unhide')
6574: }
6575: }
1.400 raeburn 6576: return ($visible,$cansetvis,\@vismsgs);
6577: }
6578:
6579: sub cat_visibility {
6580: my %visactions = &Apache::lonlocal::texthash(
6581: vis => 'This course/community currently appears in the Course/Community Catalog for this domain.',
6582: 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.',
6583: miss => 'This course/community does not currently appear in the Course/Community Catalog for this domain.',
6584: none => 'Display of a course catalog is disabled for this domain.',
6585: yous => 'You should remedy this if you plan to allow self-enrollment, otherwise students will have difficulty finding this course.',
6586: 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.',
6587: make => 'Make any changes to self-enrollment settings below, click "Save", then take action to include the course in the Catalog:',
6588: take => 'Take the following action to ensure the course appears in the Catalog:',
6589: dc_chgconf => 'Ask a domain coordinator to change the Catalog type for this domain.',
6590: dc_setcode => 'Ask a domain coordinator to assign a six character code to the course',
6591: dc_unhide => 'Ask a domain coordinator to change the "Exclude from course catalog" setting.',
6592: dc_addinst => 'Ask a domain coordinator to enable display the catalog of "Official courses (with institutional codes)".',
6593: dc_instcode => 'Ask a domain coordinator to assign an institutional code (if this is an official course).',
6594: dc_catalog => 'Ask a domain coordinator to enable or create at least one course category in the domain.',
6595: dc_categories => 'Ask a domain coordinator to create a hierarchy of categories and sub categories for courses in the domain.',
6596: 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',
6597: dc_addcat => 'Ask a domain coordinator to assign a category to the course.',
6598: );
6599: $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>"');
6600: $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>"');
6601: $visactions{'addcat'} = &mt('Use [_1]Categorize course[_2] to assign a category to the course.','"<a href="/adm/courseprefs?phase=display&actions=courseinfo">','</a>"');
6602: return \%visactions;
1.256 raeburn 6603: }
6604:
1.241 raeburn 6605: sub new_selfenroll_dom_row {
6606: my ($newdom,$num) = @_;
6607: my $domdesc = &Apache::lonnet::domain($newdom);
6608: my $output;
6609: if ($domdesc ne '') {
6610: $output .= &Apache::loncommon::start_data_table_row()
6611: .'<td valign="top"><span class="LC_nobreak">'.&mt('Domain:').' <b>'.$domdesc
6612: .' ('.$newdom.')</b><input type="hidden" name="selfenroll_dom_'.$num
1.249 raeburn 6613: .'" value="'.$newdom.'" /></span><br />'
6614: .'<span class="LC_nobreak"><label><input type="checkbox" '
6615: .'name="selfenroll_activate" value="'.$num.'" '
6616: .'onchange="javascript:update_types('
6617: ."'selfenroll_activate','$num'".');" />'
6618: .&mt('Activate').'</label></span></td>';
1.241 raeburn 6619: my @currinsttypes;
6620: $output .= '<td>'.&mt('User types:').'<br />'
6621: .&selfenroll_inst_types($num,$newdom,\@currinsttypes).'</td>'
6622: .&Apache::loncommon::end_data_table_row();
6623: }
6624: return $output;
6625: }
6626:
6627: sub selfenroll_inst_types {
1.406.2.6 raeburn 6628: my ($num,$currdom,$currinsttypes,$readonly) = @_;
1.241 raeburn 6629: my $output;
6630: my $numinrow = 4;
6631: my $count = 0;
6632: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($currdom);
1.247 raeburn 6633: my $othervalue = 'any';
1.406.2.6 raeburn 6634: my $disabled;
6635: if ($readonly) {
6636: $disabled = ' disabled="disabled"';
6637: }
1.241 raeburn 6638: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
1.251 raeburn 6639: if (keys(%{$usertypes}) > 0) {
1.247 raeburn 6640: $othervalue = 'other';
6641: }
1.241 raeburn 6642: $output .= '<table><tr>';
6643: foreach my $type (@{$types}) {
6644: if (($count > 0) && ($count%$numinrow == 0)) {
6645: $output .= '</tr><tr>';
6646: }
6647: if (defined($usertypes->{$type})) {
1.257 raeburn 6648: my $esc_type = &escape($type);
1.241 raeburn 6649: $output .= '<td><span class="LC_nobreak"><label><input type = "checkbox" value="'.
1.257 raeburn 6650: $esc_type.'" ';
1.241 raeburn 6651: if (ref($currinsttypes) eq 'ARRAY') {
6652: if (@{$currinsttypes} > 0) {
1.249 raeburn 6653: if (grep(/^any$/,@{$currinsttypes})) {
6654: $output .= 'checked="checked"';
1.257 raeburn 6655: } elsif (grep(/^\Q$esc_type\E$/,@{$currinsttypes})) {
1.241 raeburn 6656: $output .= 'checked="checked"';
6657: }
1.249 raeburn 6658: } else {
6659: $output .= 'checked="checked"';
1.241 raeburn 6660: }
6661: }
1.406.2.6 raeburn 6662: $output .= ' name="selfenroll_types_'.$num.'"'.$disabled.' />'.$usertypes->{$type}.'</label></span></td>';
1.241 raeburn 6663: }
6664: $count ++;
6665: }
6666: if (($count > 0) && ($count%$numinrow == 0)) {
6667: $output .= '</tr><tr>';
6668: }
1.249 raeburn 6669: $output .= '<td><span class="LC_nobreak"><label><input type = "checkbox" value="'.$othervalue.'"';
1.241 raeburn 6670: if (ref($currinsttypes) eq 'ARRAY') {
6671: if (@{$currinsttypes} > 0) {
1.249 raeburn 6672: if (grep(/^any$/,@{$currinsttypes})) {
6673: $output .= ' checked="checked"';
6674: } elsif ($othervalue eq 'other') {
6675: if (grep(/^\Q$othervalue\E$/,@{$currinsttypes})) {
6676: $output .= ' checked="checked"';
6677: }
1.241 raeburn 6678: }
1.249 raeburn 6679: } else {
6680: $output .= ' checked="checked"';
1.241 raeburn 6681: }
1.249 raeburn 6682: } else {
6683: $output .= ' checked="checked"';
1.241 raeburn 6684: }
1.406.2.6 raeburn 6685: $output .= ' name="selfenroll_types_'.$num.'"'.$disabled.' />'.$othertitle.'</label></span></td></tr></table>';
1.241 raeburn 6686: }
6687: return $output;
6688: }
6689:
1.237 raeburn 6690: sub selfenroll_date_forms {
6691: my ($startform,$endform) = @_;
6692: my $output .= &Apache::lonhtmlcommon::start_pick_box()."\n".
1.244 bisitz 6693: &Apache::lonhtmlcommon::row_title(&mt('Start date'),
1.237 raeburn 6694: 'LC_oddrow_value')."\n".
6695: $startform."\n".
6696: &Apache::lonhtmlcommon::row_closure(1).
1.244 bisitz 6697: &Apache::lonhtmlcommon::row_title(&mt('End date'),
1.237 raeburn 6698: 'LC_oddrow_value')."\n".
6699: $endform."\n".
6700: &Apache::lonhtmlcommon::row_closure(1).
6701: &Apache::lonhtmlcommon::end_pick_box();
6702: return $output;
6703: }
6704:
1.239 raeburn 6705: sub print_userchangelogs_display {
1.406.2.5 raeburn 6706: my ($r,$context,$permission,$brcrum) = @_;
1.363 raeburn 6707: my $formname = 'rolelog';
1.406.2.6 raeburn 6708: my ($username,$domain,$crstype,$viewablesec,%roleslog);
1.363 raeburn 6709: if ($context eq 'domain') {
6710: $domain = $env{'request.role.domain'};
6711: %roleslog=&Apache::lonnet::dump_dom('nohist_rolelog',$domain);
6712: } else {
6713: if ($context eq 'course') {
6714: $domain = $env{'course.'.$env{'request.course.id'}.'.domain'};
6715: $username = $env{'course.'.$env{'request.course.id'}.'.num'};
6716: $crstype = &Apache::loncommon::course_type();
1.406.2.6 raeburn 6717: $viewablesec = &Apache::lonuserutils::viewable_section($permission);
1.363 raeburn 6718: my %saveable_parameters = ('show' => 'scalar',);
6719: &Apache::loncommon::store_course_settings('roles_log',
6720: \%saveable_parameters);
6721: &Apache::loncommon::restore_course_settings('roles_log',
6722: \%saveable_parameters);
6723: } elsif ($context eq 'author') {
6724: $domain = $env{'user.domain'};
6725: if ($env{'request.role'} =~ m{^au\./\Q$domain\E/$}) {
6726: $username = $env{'user.name'};
6727: } else {
6728: undef($domain);
6729: }
6730: }
6731: if ($domain ne '' && $username ne '') {
6732: %roleslog=&Apache::lonnet::dump('nohist_rolelog',$domain,$username);
6733: }
6734: }
1.239 raeburn 6735: if ((keys(%roleslog))[0]=~/^error\:/) { undef(%roleslog); }
6736:
1.406.2.5 raeburn 6737: my $helpitem;
6738: if ($context eq 'course') {
6739: $helpitem = 'Course_User_Logs';
1.406.2.14 raeburn 6740: } elsif ($context eq 'domain') {
6741: $helpitem = 'Domain_Role_Logs';
6742: } elsif ($context eq 'author') {
6743: $helpitem = 'Author_User_Logs';
1.406.2.5 raeburn 6744: }
6745: push (@{$brcrum},
6746: {href => '/adm/createuser?action=changelogs',
6747: text => 'User Management Logs',
6748: help => $helpitem});
6749: my $bread_crumbs_component = 'User Changes';
6750: my $args = { bread_crumbs => $brcrum,
6751: bread_crumbs_component => $bread_crumbs_component};
6752:
6753: # Create navigation javascript
6754: my $jsnav = &userlogdisplay_js($formname);
6755:
6756: my $jscript = (<<ENDSCRIPT);
6757: <script type="text/javascript">
6758: // <![CDATA[
6759: $jsnav
6760: // ]]>
6761: </script>
6762: ENDSCRIPT
6763:
6764: # print page header
6765: $r->print(&header($jscript,$args));
6766:
1.239 raeburn 6767: # set defaults
6768: my $now = time();
6769: my $defstart = $now - (7*24*3600); #7 days ago
6770: my %defaults = (
6771: page => '1',
6772: show => '10',
6773: role => 'any',
6774: chgcontext => 'any',
6775: rolelog_start_date => $defstart,
6776: rolelog_end_date => $now,
6777: );
6778: my $more_records = 0;
6779:
6780: # set current
6781: my %curr;
6782: foreach my $item ('show','page','role','chgcontext') {
6783: $curr{$item} = $env{'form.'.$item};
6784: }
6785: my ($startdate,$enddate) =
6786: &Apache::lonuserutils::get_dates_from_form('rolelog_start_date','rolelog_end_date');
6787: $curr{'rolelog_start_date'} = $startdate;
6788: $curr{'rolelog_end_date'} = $enddate;
6789: foreach my $key (keys(%defaults)) {
6790: if ($curr{$key} eq '') {
6791: $curr{$key} = $defaults{$key};
6792: }
6793: }
1.248 raeburn 6794: my (%whodunit,%changed,$version);
6795: ($version) = ($r->dir_config('lonVersion') =~ /^([\d\.]+)\-/);
1.239 raeburn 6796: my ($minshown,$maxshown);
1.255 raeburn 6797: $minshown = 1;
1.239 raeburn 6798: my $count = 0;
1.406.2.5 raeburn 6799: if ($curr{'show'} =~ /\D/) {
6800: $curr{'page'} = 1;
6801: } else {
1.239 raeburn 6802: $maxshown = $curr{'page'} * $curr{'show'};
6803: if ($curr{'page'} > 1) {
6804: $minshown = 1 + ($curr{'page'} - 1) * $curr{'show'};
6805: }
6806: }
1.301 bisitz 6807:
1.327 raeburn 6808: # Form Header
6809: $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">'.
1.363 raeburn 6810: &role_display_filter($context,$formname,$domain,$username,\%curr,
6811: $version,$crstype));
1.327 raeburn 6812:
6813: my $showntableheader = 0;
6814:
6815: # Table Header
6816: my $tableheader =
6817: &Apache::loncommon::start_data_table_header_row()
6818: .'<th> </th>'
6819: .'<th>'.&mt('When').'</th>'
6820: .'<th>'.&mt('Who made the change').'</th>'
6821: .'<th>'.&mt('Changed User').'</th>'
1.363 raeburn 6822: .'<th>'.&mt('Role').'</th>';
6823:
6824: if ($context eq 'course') {
6825: $tableheader .= '<th>'.&mt('Section').'</th>';
6826: }
6827: $tableheader .=
6828: '<th>'.&mt('Context').'</th>'
1.327 raeburn 6829: .'<th>'.&mt('Start').'</th>'
6830: .'<th>'.&mt('End').'</th>'
6831: .&Apache::loncommon::end_data_table_header_row();
6832:
6833: # Display user change log data
1.239 raeburn 6834: foreach my $id (sort { $roleslog{$b}{'exe_time'}<=>$roleslog{$a}{'exe_time'} } (keys(%roleslog))) {
6835: next if (($roleslog{$id}{'exe_time'} < $curr{'rolelog_start_date'}) ||
6836: ($roleslog{$id}{'exe_time'} > $curr{'rolelog_end_date'}));
1.406.2.5 raeburn 6837: if ($curr{'show'} !~ /\D/) {
1.239 raeburn 6838: if ($count >= $curr{'page'} * $curr{'show'}) {
6839: $more_records = 1;
6840: last;
6841: }
6842: }
6843: if ($curr{'role'} ne 'any') {
6844: next if ($roleslog{$id}{'logentry'}{'role'} ne $curr{'role'});
6845: }
6846: if ($curr{'chgcontext'} ne 'any') {
6847: if ($curr{'chgcontext'} eq 'selfenroll') {
6848: next if (!$roleslog{$id}{'logentry'}{'selfenroll'});
6849: } else {
6850: next if ($roleslog{$id}{'logentry'}{'context'} ne $curr{'chgcontext'});
6851: }
6852: }
1.406.2.6 raeburn 6853: if (($context eq 'course') && ($viewablesec ne '')) {
6854: next if ($roleslog{$id}{'logentry'}{'section'} ne $viewablesec);
6855: }
1.239 raeburn 6856: $count ++;
6857: next if ($count < $minshown);
1.327 raeburn 6858: unless ($showntableheader) {
1.406.2.5 raeburn 6859: $r->print(&Apache::loncommon::start_data_table()
1.327 raeburn 6860: .$tableheader);
6861: $r->rflush();
6862: $showntableheader = 1;
6863: }
1.239 raeburn 6864: if ($whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}} eq '') {
6865: $whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}} =
6866: &Apache::loncommon::plainname($roleslog{$id}{'exe_uname'},$roleslog{$id}{'exe_udom'});
6867: }
6868: if ($changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}} eq '') {
6869: $changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}} =
6870: &Apache::loncommon::plainname($roleslog{$id}{'uname'},$roleslog{$id}{'udom'});
6871: }
6872: my $sec = $roleslog{$id}{'logentry'}{'section'};
6873: if ($sec eq '') {
6874: $sec = &mt('None');
6875: }
6876: my ($rolestart,$roleend);
6877: if ($roleslog{$id}{'delflag'}) {
6878: $rolestart = &mt('deleted');
6879: $roleend = &mt('deleted');
6880: } else {
6881: $rolestart = $roleslog{$id}{'logentry'}{'start'};
6882: $roleend = $roleslog{$id}{'logentry'}{'end'};
6883: if ($rolestart eq '' || $rolestart == 0) {
6884: $rolestart = &mt('No start date');
6885: } else {
6886: $rolestart = &Apache::lonlocal::locallocaltime($rolestart);
6887: }
6888: if ($roleend eq '' || $roleend == 0) {
6889: $roleend = &mt('No end date');
6890: } else {
6891: $roleend = &Apache::lonlocal::locallocaltime($roleend);
6892: }
6893: }
6894: my $chgcontext = $roleslog{$id}{'logentry'}{'context'};
6895: if ($roleslog{$id}{'logentry'}{'selfenroll'}) {
6896: $chgcontext = 'selfenroll';
6897: }
1.363 raeburn 6898: my %lt = &rolechg_contexts($context,$crstype);
1.239 raeburn 6899: if ($chgcontext ne '' && $lt{$chgcontext} ne '') {
6900: $chgcontext = $lt{$chgcontext};
6901: }
1.327 raeburn 6902: $r->print(
1.301 bisitz 6903: &Apache::loncommon::start_data_table_row()
6904: .'<td>'.$count.'</td>'
6905: .'<td>'.&Apache::lonlocal::locallocaltime($roleslog{$id}{'exe_time'}).'</td>'
6906: .'<td>'.$whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}}.'</td>'
6907: .'<td>'.$changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}}.'</td>'
1.363 raeburn 6908: .'<td>'.&Apache::lonnet::plaintext($roleslog{$id}{'logentry'}{'role'},$crstype).'</td>');
6909: if ($context eq 'course') {
6910: $r->print('<td>'.$sec.'</td>');
6911: }
6912: $r->print(
6913: '<td>'.$chgcontext.'</td>'
1.301 bisitz 6914: .'<td>'.$rolestart.'</td>'
6915: .'<td>'.$roleend.'</td>'
1.327 raeburn 6916: .&Apache::loncommon::end_data_table_row()."\n");
1.301 bisitz 6917: }
6918:
1.327 raeburn 6919: if ($showntableheader) { # Table footer, if content displayed above
1.406.2.5 raeburn 6920: $r->print(&Apache::loncommon::end_data_table().
6921: &userlogdisplay_navlinks(\%curr,$more_records));
1.327 raeburn 6922: } else { # No content displayed above
1.301 bisitz 6923: $r->print('<p class="LC_info">'
6924: .&mt('There are no records to display.')
6925: .'</p>'
6926: );
1.239 raeburn 6927: }
1.301 bisitz 6928:
1.327 raeburn 6929: # Form Footer
6930: $r->print(
6931: '<input type="hidden" name="page" value="'.$curr{'page'}.'" />'
6932: .'<input type="hidden" name="action" value="changelogs" />'
6933: .'</form>');
6934: return;
6935: }
1.301 bisitz 6936:
1.406.2.5 raeburn 6937: sub print_useraccesslogs_display {
6938: my ($r,$uname,$udom,$permission,$brcrum) = @_;
6939: my $formname = 'accesslog';
6940: my $form = 'document.accesslog';
6941:
6942: # set breadcrumbs
1.406.2.7 raeburn 6943: my %breadcrumb_text = &singleuser_breadcrumb('','domain',$udom);
1.406.2.12 raeburn 6944: my $prevphasestr;
6945: if ($env{'form.popup'}) {
6946: $brcrum = [];
6947: } else {
6948: push (@{$brcrum},
6949: {href => "javascript:backPage($form)",
6950: text => $breadcrumb_text{'search'}});
6951: my @prevphases;
6952: if ($env{'form.prevphases'}) {
6953: @prevphases = split(/,/,$env{'form.prevphases'});
6954: $prevphasestr = $env{'form.prevphases'};
6955: }
6956: if (($env{'form.phase'} eq 'userpicked') || (grep(/^userpicked$/,@prevphases))) {
6957: push(@{$brcrum},
6958: {href => "javascript:backPage($form,'get_user_info','select')",
6959: text => $breadcrumb_text{'userpicked'}});
6960: if ($env{'form.phase'} eq 'userpicked') {
6961: $prevphasestr = 'userpicked';
6962: }
1.406.2.5 raeburn 6963: }
6964: }
6965: push(@{$brcrum},
6966: {href => '/adm/createuser?action=accesslogs',
6967: text => 'User access logs',
1.406.2.8 raeburn 6968: help => 'Domain_User_Access_Logs'});
1.406.2.5 raeburn 6969: my $bread_crumbs_component = 'User Access Logs';
6970: my $args = { bread_crumbs => $brcrum,
6971: bread_crumbs_component => 'User Management'};
1.406.2.8 raeburn 6972: if ($env{'form.popup'}) {
6973: $args->{'no_nav_bar'} = 1;
1.406.2.12 raeburn 6974: $args->{'bread_crumbs_nomenu'} = 1;
1.406.2.8 raeburn 6975: }
1.406.2.5 raeburn 6976:
6977: # set javascript
6978: my ($jsback,$elements) = &crumb_utilities();
6979: my $jsnav = &userlogdisplay_js($formname);
6980:
6981: my $jscript = (<<ENDSCRIPT);
1.239 raeburn 6982: <script type="text/javascript">
1.301 bisitz 6983: // <![CDATA[
1.406.2.5 raeburn 6984:
6985: $jsback
6986: $jsnav
6987:
6988: // ]]>
6989: </script>
6990:
6991: ENDSCRIPT
6992:
6993: # print page header
6994: $r->print(&header($jscript,$args));
6995:
6996: # early out unless log data can be displayed.
6997: unless ($permission->{'activity'}) {
6998: $r->print('<p class="LC_warning">'
6999: .&mt('You do not have rights to display user access logs.')
1.406.2.12 raeburn 7000: .'</p>');
7001: if ($env{'form.popup'}) {
7002: $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a></p>');
7003: } else {
7004: $r->print(&earlyout_accesslog_form($formname,$prevphasestr,$udom));
7005: }
1.406.2.5 raeburn 7006: return;
7007: }
7008:
7009: unless ($udom eq $env{'request.role.domain'}) {
7010: $r->print('<p class="LC_warning">'
7011: .&mt("User's domain must match role's domain")
7012: .'</p>'
7013: .&earlyout_accesslog_form($formname,$prevphasestr,$udom));
7014: return;
7015: }
7016:
7017: if (($uname eq '') || ($udom eq '')) {
7018: $r->print('<p class="LC_warning">'
7019: .&mt('Invalid username or domain')
7020: .'</p>'
7021: .&earlyout_accesslog_form($formname,$prevphasestr,$udom));
7022: return;
7023: }
7024:
1.406.2.13 raeburn 7025: if (&Apache::lonnet::privileged($uname,$udom,
7026: [$env{'request.role.domain'}],['dc','su'])) {
7027: unless (&Apache::lonnet::privileged($env{'user.name'},$env{'user.domain'},
7028: [$env{'request.role.domain'}],['dc','su'])) {
7029: $r->print('<p class="LC_warning">'
7030: .&mt('You need to be a privileged user to display user access logs for [_1]',
7031: &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),
7032: $uname,$udom))
7033: .'</p>');
7034: if ($env{'form.popup'}) {
7035: $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a></p>');
7036: } else {
7037: $r->print(&earlyout_accesslog_form($formname,$prevphasestr,$udom));
7038: }
7039: return;
7040: }
7041: }
7042:
1.406.2.5 raeburn 7043: # set defaults
7044: my $now = time();
7045: my $defstart = $now - (7*24*3600);
7046: my %defaults = (
7047: page => '1',
7048: show => '10',
7049: activity => 'any',
7050: accesslog_start_date => $defstart,
7051: accesslog_end_date => $now,
7052: );
7053: my $more_records = 0;
7054:
7055: # set current
7056: my %curr;
7057: foreach my $item ('show','page','activity') {
7058: $curr{$item} = $env{'form.'.$item};
7059: }
7060: my ($startdate,$enddate) =
7061: &Apache::lonuserutils::get_dates_from_form('accesslog_start_date','accesslog_end_date');
7062: $curr{'accesslog_start_date'} = $startdate;
7063: $curr{'accesslog_end_date'} = $enddate;
7064: foreach my $key (keys(%defaults)) {
7065: if ($curr{$key} eq '') {
7066: $curr{$key} = $defaults{$key};
7067: }
7068: }
7069: my ($minshown,$maxshown);
7070: $minshown = 1;
7071: my $count = 0;
7072: if ($curr{'show'} =~ /\D/) {
7073: $curr{'page'} = 1;
7074: } else {
7075: $maxshown = $curr{'page'} * $curr{'show'};
7076: if ($curr{'page'} > 1) {
7077: $minshown = 1 + ($curr{'page'} - 1) * $curr{'show'};
7078: }
7079: }
7080:
7081: # form header
7082: $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">'.
7083: &activity_display_filter($formname,\%curr));
7084:
7085: my $showntableheader = 0;
7086: my ($nav_script,$nav_links);
7087:
7088: # table header
1.406.2.18 raeburn 7089: my $heading = '<h3>'.
1.406.2.12 raeburn 7090: &mt('User access logs for: [_1]',
1.406.2.18 raeburn 7091: &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),$uname,$udom)).'</h3>';
7092: my $tableheader = $heading
1.406.2.12 raeburn 7093: .&Apache::loncommon::start_data_table_header_row()
1.406.2.5 raeburn 7094: .'<th> </th>'
7095: .'<th>'.&mt('When').'</th>'
7096: .'<th>'.&mt('HostID').'</th>'
7097: .'<th>'.&mt('Event').'</th>'
7098: .'<th>'.&mt('Other data').'</th>'
7099: .&Apache::loncommon::end_data_table_header_row();
7100:
7101: my %filters=(
7102: start => $curr{'accesslog_start_date'},
7103: end => $curr{'accesslog_end_date'},
7104: action => $curr{'activity'},
7105: );
7106:
7107: my $reply = &Apache::lonnet::userlog_query($uname,$udom,%filters);
7108: unless ( ($reply =~/^timeout/) || ($reply =~/^error/) ) {
7109: my (%courses,%missing);
7110: my @results = split(/\&/,$reply);
7111: foreach my $item (reverse(@results)) {
7112: my ($timestamp,$host,$event) = split(/:/,$item);
7113: next unless ($event =~ /^(Log|Role)/);
7114: if ($curr{'show'} !~ /\D/) {
7115: if ($count >= $curr{'page'} * $curr{'show'}) {
7116: $more_records = 1;
7117: last;
7118: }
7119: }
7120: $count ++;
7121: next if ($count < $minshown);
7122: unless ($showntableheader) {
7123: $r->print($nav_script
7124: .&Apache::loncommon::start_data_table()
7125: .$tableheader);
7126: $r->rflush();
7127: $showntableheader = 1;
7128: }
1.406.2.6 raeburn 7129: my ($shown,$extra);
1.406.2.13 raeburn 7130: my ($event,$data) = split(/\s+/,&unescape($event),2);
1.406.2.5 raeburn 7131: if ($event eq 'Role') {
7132: my ($rolecode,$extent) = split(/\./,$data,2);
7133: next if ($extent eq '');
7134: my ($crstype,$desc,$info);
1.406.2.6 raeburn 7135: if ($extent =~ m{^/($match_domain)/($match_courseid)(?:/(\w+)|)$}) {
7136: my ($cdom,$cnum,$sec) = ($1,$2,$3);
1.406.2.5 raeburn 7137: my $cid = $cdom.'_'.$cnum;
7138: if (exists($courses{$cid})) {
7139: $crstype = $courses{$cid}{'type'};
7140: $desc = $courses{$cid}{'description'};
7141: } elsif ($missing{$cid}) {
7142: $crstype = 'Course';
7143: $desc = 'Course/Community';
7144: } else {
7145: my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',$cnum,undef,undef,'.');
7146: if (ref($crsinfo{$cdom.'_'.$cnum}) eq 'HASH') {
7147: $courses{$cid} = $crsinfo{$cid};
7148: $crstype = $crsinfo{$cid}{'type'};
7149: $desc = $crsinfo{$cid}{'description'};
7150: } else {
7151: $missing{$cid} = 1;
7152: }
7153: }
7154: $extra = &mt($crstype).': <a href="/public/'.$cdom.'/'.$cnum.'/syllabus">'.$desc.'</a>';
1.406.2.6 raeburn 7155: if ($sec ne '') {
7156: $extra .= ' ('.&mt('Section: [_1]',$sec).')';
7157: }
1.406.2.5 raeburn 7158: } elsif ($extent =~ m{^/($match_domain)/($match_username|$)}) {
7159: my ($dom,$name) = ($1,$2);
7160: if ($rolecode eq 'au') {
7161: $extra = '';
7162: } elsif ($rolecode =~ /^(ca|aa)$/) {
7163: $extra = &mt('Authoring Space: [_1]',$name.':'.$dom);
7164: } elsif ($rolecode =~ /^(li|dg|dh|dc|sc)$/) {
7165: $extra = &mt('Domain: [_1]',$dom);
7166: }
7167: }
7168: my $rolename;
7169: if ($rolecode =~ m{^cr/($match_domain)/($match_username)/(\w+)}) {
7170: my $role = $3;
7171: my $owner = "($2:$1)";
7172: if ($2 eq $1.'-domainconfig') {
7173: $owner = '(ad hoc)';
7174: }
7175: $rolename = &mt('Custom role: [_1]',$role.' '.$owner);
7176: } else {
7177: $rolename = &Apache::lonnet::plaintext($rolecode,$crstype);
7178: }
7179: $shown = &mt('Role selection: [_1]',$rolename);
7180: } else {
7181: $shown = &mt($event);
1.406.2.13 raeburn 7182: if ($data =~ /^webdav/) {
7183: my ($path,$clientip) = split(/\s+/,$data,2);
7184: $path =~ s/^webdav//;
7185: if ($clientip ne '') {
7186: $extra = &mt('Client IP address: [_1]',$clientip);
7187: }
7188: if ($path ne '') {
7189: $shown .= ' '.&mt('(WebDAV access to [_1])',$path);
7190: }
7191: } elsif ($data ne '') {
7192: $extra = &mt('Client IP address: [_1]',$data);
1.406.2.5 raeburn 7193: }
7194: }
7195: $r->print(
7196: &Apache::loncommon::start_data_table_row()
7197: .'<td>'.$count.'</td>'
7198: .'<td>'.&Apache::lonlocal::locallocaltime($timestamp).'</td>'
7199: .'<td>'.$host.'</td>'
7200: .'<td>'.$shown.'</td>'
7201: .'<td>'.$extra.'</td>'
7202: .&Apache::loncommon::end_data_table_row()."\n");
7203: }
7204: }
7205:
7206: if ($showntableheader) { # Table footer, if content displayed above
7207: $r->print(&Apache::loncommon::end_data_table().
7208: &userlogdisplay_navlinks(\%curr,$more_records));
7209: } else { # No content displayed above
1.406.2.18 raeburn 7210: $r->print($heading.'<p class="LC_info">'
1.406.2.5 raeburn 7211: .&mt('There are no records to display.')
7212: .'</p>');
7213: }
7214:
1.406.2.8 raeburn 7215: if ($env{'form.popup'} == 1) {
7216: $r->print('<input type="hidden" name="popup" value="1" />'."\n");
7217: }
7218:
1.406.2.5 raeburn 7219: # Form Footer
7220: $r->print(
7221: '<input type="hidden" name="currstate" value="" />'
7222: .'<input type="hidden" name="accessuname" value="'.$uname.'" />'
7223: .'<input type="hidden" name="accessudom" value="'.$udom.'" />'
7224: .'<input type="hidden" name="page" value="'.$curr{'page'}.'" />'
7225: .'<input type="hidden" name="prevphases" value="'.$prevphasestr.'" />'
7226: .'<input type="hidden" name="phase" value="activity" />'
7227: .'<input type="hidden" name="action" value="accesslogs" />'
7228: .'<input type="hidden" name="srchdomain" value="'.$udom.'" />'
7229: .'<input type="hidden" name="srchby" value="'.$env{'form.srchby'}.'" />'
7230: .'<input type="hidden" name="srchtype" value="'.$env{'form.srchtype'}.'" />'
7231: .'<input type="hidden" name="srchterm" value="'.&HTML::Entities::encode($env{'form.srchterm'},'<>"&').'" />'
7232: .'<input type="hidden" name="srchin" value="'.$env{'form.srchin'}.'" />'
7233: .'</form>');
7234: return;
7235: }
7236:
7237: sub earlyout_accesslog_form {
7238: my ($formname,$prevphasestr,$udom) = @_;
7239: my $srchterm = &HTML::Entities::encode($env{'form.srchterm'},'<>"&');
7240: return <<"END";
7241: <form action="/adm/createuser" method="post" name="$formname">
7242: <input type="hidden" name="currstate" value="" />
7243: <input type="hidden" name="prevphases" value="$prevphasestr" />
7244: <input type="hidden" name="phase" value="activity" />
7245: <input type="hidden" name="action" value="accesslogs" />
7246: <input type="hidden" name="srchdomain" value="$udom" />
7247: <input type="hidden" name="srchby" value="$env{'form.srchby'}" />
7248: <input type="hidden" name="srchtype" value="$env{'form.srchtype'}" />
7249: <input type="hidden" name="srchterm" value="$srchterm" />
7250: <input type="hidden" name="srchin" value="$env{'form.srchin'}" />
7251: </form>
7252: END
7253: }
7254:
7255: sub activity_display_filter {
7256: my ($formname,$curr) = @_;
7257: my $nolink = 1;
7258: my $output = '<table><tr><td valign="top">'.
7259: '<span class="LC_nobreak"><b>'.&mt('Actions/page:').'</b></span><br />'.
7260: &Apache::lonmeta::selectbox('show',$curr->{'show'},undef,
7261: (&mt('all'),5,10,20,50,100,1000,10000)).
7262: '</td><td> </td>';
7263: my $startform =
7264: &Apache::lonhtmlcommon::date_setter($formname,'accesslog_start_date',
7265: $curr->{'accesslog_start_date'},undef,
7266: undef,undef,undef,undef,undef,undef,$nolink);
7267: my $endform =
7268: &Apache::lonhtmlcommon::date_setter($formname,'accesslog_end_date',
7269: $curr->{'accesslog_end_date'},undef,
7270: undef,undef,undef,undef,undef,undef,$nolink);
7271: my %lt = &Apache::lonlocal::texthash (
7272: activity => 'Activity',
7273: Role => 'Role selection',
7274: log => 'Log-in or Logout',
7275: );
7276: $output .= '<td valign="top"><b>'.&mt('Window during which actions occurred:').'</b><br />'.
7277: '<table><tr><td>'.&mt('After:').
7278: '</td><td>'.$startform.'</td></tr>'.
7279: '<tr><td>'.&mt('Before:').'</td>'.
7280: '<td>'.$endform.'</td></tr></table>'.
7281: '</td>'.
7282: '<td> </td>'.
7283: '<td valign="top"><b>'.&mt('Activities').'</b><br />'.
7284: '<select name="activity"><option value="any"';
7285: if ($curr->{'activity'} eq 'any') {
7286: $output .= ' selected="selected"';
7287: }
7288: $output .= '>'.&mt('Any').'</option>'."\n";
7289: foreach my $activity ('Role','log') {
7290: my $selstr = '';
7291: if ($activity eq $curr->{'activity'}) {
7292: $selstr = ' selected="selected"';
7293: }
7294: $output .= '<option value="'.$activity.'"'.$selstr.'>'.$lt{$activity}.'</option>';
7295: }
7296: $output .= '</select></td>'.
7297: '</tr></table>';
7298: # Update Display button
7299: $output .= '<p>'
7300: .'<input type="submit" value="'.&mt('Update Display').'" />'
1.406.2.12 raeburn 7301: .'</p><hr />';
1.406.2.5 raeburn 7302: return $output;
7303: }
7304:
7305: sub userlogdisplay_js {
7306: my ($formname) = @_;
7307: return <<"ENDSCRIPT";
7308:
1.239 raeburn 7309: function chgPage(caller) {
7310: if (caller == 'previous') {
7311: document.$formname.page.value --;
7312: }
7313: if (caller == 'next') {
7314: document.$formname.page.value ++;
7315: }
1.327 raeburn 7316: document.$formname.submit();
1.239 raeburn 7317: return;
7318: }
7319: ENDSCRIPT
1.406.2.5 raeburn 7320: }
7321:
7322: sub userlogdisplay_navlinks {
7323: my ($curr,$more_records) = @_;
7324: return unless(ref($curr) eq 'HASH');
7325: # Navigation Buttons
7326: my $nav_links = '<p>';
7327: if (($curr->{'page'} > 1) || ($more_records)) {
7328: if (($curr->{'page'} > 1) && ($curr->{'show'} !~ /\D/)) {
7329: $nav_links .= '<input type="button"'
7330: .' onclick="javascript:chgPage('."'previous'".');"'
7331: .' value="'.&mt('Previous [_1] changes',$curr->{'show'})
7332: .'" /> ';
7333: }
7334: if ($more_records) {
7335: $nav_links .= '<input type="button"'
7336: .' onclick="javascript:chgPage('."'next'".');"'
7337: .' value="'.&mt('Next [_1] changes',$curr->{'show'})
7338: .'" />';
1.301 bisitz 7339: }
7340: }
1.406.2.5 raeburn 7341: $nav_links .= '</p>';
7342: return $nav_links;
1.239 raeburn 7343: }
7344:
7345: sub role_display_filter {
1.363 raeburn 7346: my ($context,$formname,$cdom,$cnum,$curr,$version,$crstype) = @_;
7347: my $lctype;
7348: if ($context eq 'course') {
7349: $lctype = lc($crstype);
7350: }
1.239 raeburn 7351: my $nolink = 1;
7352: my $output = '<table><tr><td valign="top">'.
1.301 bisitz 7353: '<span class="LC_nobreak"><b>'.&mt('Changes/page:').'</b></span><br />'.
1.239 raeburn 7354: &Apache::lonmeta::selectbox('show',$curr->{'show'},undef,
7355: (&mt('all'),5,10,20,50,100,1000,10000)).
7356: '</td><td> </td>';
7357: my $startform =
7358: &Apache::lonhtmlcommon::date_setter($formname,'rolelog_start_date',
7359: $curr->{'rolelog_start_date'},undef,
7360: undef,undef,undef,undef,undef,undef,$nolink);
7361: my $endform =
7362: &Apache::lonhtmlcommon::date_setter($formname,'rolelog_end_date',
7363: $curr->{'rolelog_end_date'},undef,
7364: undef,undef,undef,undef,undef,undef,$nolink);
1.363 raeburn 7365: my %lt = &rolechg_contexts($context,$crstype);
1.301 bisitz 7366: $output .= '<td valign="top"><b>'.&mt('Window during which changes occurred:').'</b><br />'.
7367: '<table><tr><td>'.&mt('After:').
7368: '</td><td>'.$startform.'</td></tr>'.
7369: '<tr><td>'.&mt('Before:').'</td>'.
7370: '<td>'.$endform.'</td></tr></table>'.
7371: '</td>'.
7372: '<td> </td>'.
1.239 raeburn 7373: '<td valign="top"><b>'.&mt('Role:').'</b><br />'.
7374: '<select name="role"><option value="any"';
7375: if ($curr->{'role'} eq 'any') {
7376: $output .= ' selected="selected"';
7377: }
7378: $output .= '>'.&mt('Any').'</option>'."\n";
1.363 raeburn 7379: my @roles = &Apache::lonuserutils::roles_by_context($context,1,$crstype);
1.239 raeburn 7380: foreach my $role (@roles) {
7381: my $plrole;
7382: if ($role eq 'cr') {
7383: $plrole = &mt('Custom Role');
7384: } else {
1.318 raeburn 7385: $plrole=&Apache::lonnet::plaintext($role,$crstype);
1.239 raeburn 7386: }
7387: my $selstr = '';
7388: if ($role eq $curr->{'role'}) {
7389: $selstr = ' selected="selected"';
7390: }
7391: $output .= ' <option value="'.$role.'"'.$selstr.'>'.$plrole.'</option>';
7392: }
1.301 bisitz 7393: $output .= '</select></td>'.
7394: '<td> </td>'.
7395: '<td valign="top"><b>'.
1.239 raeburn 7396: &mt('Context:').'</b><br /><select name="chgcontext">';
1.363 raeburn 7397: my @posscontexts;
7398: if ($context eq 'course') {
1.406.2.20 raeburn 7399: @posscontexts = ('any','automated','updatenow','createcourse','course','domain','selfenroll','requestcourses','chgtype');
1.363 raeburn 7400: } elsif ($context eq 'domain') {
7401: @posscontexts = ('any','domain','requestauthor','domconfig','server');
7402: } else {
7403: @posscontexts = ('any','author','domain');
1.406.2.20 raeburn 7404: }
1.363 raeburn 7405: foreach my $chgtype (@posscontexts) {
1.239 raeburn 7406: my $selstr = '';
7407: if ($curr->{'chgcontext'} eq $chgtype) {
1.301 bisitz 7408: $selstr = ' selected="selected"';
1.239 raeburn 7409: }
1.363 raeburn 7410: if ($context eq 'course') {
1.376 raeburn 7411: if (($chgtype eq 'automated') || ($chgtype eq 'updatenow')) {
1.363 raeburn 7412: next if (!&Apache::lonnet::auto_run($cnum,$cdom));
7413: }
1.239 raeburn 7414: }
7415: $output .= '<option value="'.$chgtype.'"'.$selstr.'>'.$lt{$chgtype}.'</option>'."\n";
1.248 raeburn 7416: }
1.303 bisitz 7417: $output .= '</select></td>'
7418: .'</tr></table>';
7419:
7420: # Update Display button
7421: $output .= '<p>'
7422: .'<input type="submit" value="'.&mt('Update Display').'" />'
7423: .'</p>';
7424:
7425: # Server version info
1.363 raeburn 7426: my $needsrev = '2.11.0';
7427: if ($context eq 'course') {
7428: $needsrev = '2.7.0';
7429: }
7430:
1.303 bisitz 7431: $output .= '<p class="LC_info">'
7432: .&mt('Only changes made from servers running LON-CAPA [_1] or later are displayed.'
1.363 raeburn 7433: ,$needsrev);
1.248 raeburn 7434: if ($version) {
1.303 bisitz 7435: $output .= ' '.&mt('This LON-CAPA server is version [_1]',$version);
7436: }
7437: $output .= '</p><hr />';
1.239 raeburn 7438: return $output;
7439: }
7440:
7441: sub rolechg_contexts {
1.363 raeburn 7442: my ($context,$crstype) = @_;
7443: my %lt;
7444: if ($context eq 'course') {
7445: %lt = &Apache::lonlocal::texthash (
1.239 raeburn 7446: any => 'Any',
1.376 raeburn 7447: automated => 'Automated Enrollment',
1.406.2.20 raeburn 7448: chgtype => 'Enrollment Type/Lock Change',
1.239 raeburn 7449: updatenow => 'Roster Update',
7450: createcourse => 'Course Creation',
7451: course => 'User Management in course',
7452: domain => 'User Management in domain',
1.313 raeburn 7453: selfenroll => 'Self-enrolled',
1.318 raeburn 7454: requestcourses => 'Course Request',
1.239 raeburn 7455: );
1.363 raeburn 7456: if ($crstype eq 'Community') {
7457: $lt{'createcourse'} = &mt('Community Creation');
7458: $lt{'course'} = &mt('User Management in community');
7459: $lt{'requestcourses'} = &mt('Community Request');
7460: }
7461: } elsif ($context eq 'domain') {
7462: %lt = &Apache::lonlocal::texthash (
7463: any => 'Any',
7464: domain => 'User Management in domain',
7465: requestauthor => 'Authoring Request',
7466: server => 'Command line script (DC role)',
7467: domconfig => 'Self-enrolled',
7468: );
7469: } else {
7470: %lt = &Apache::lonlocal::texthash (
7471: any => 'Any',
7472: domain => 'User Management in domain',
7473: author => 'User Management by author',
7474: );
7475: }
1.239 raeburn 7476: return %lt;
7477: }
7478:
1.406.2.10 raeburn 7479: sub print_helpdeskaccess_display {
7480: my ($r,$permission,$brcrum) = @_;
7481: my $formname = 'helpdeskaccess';
7482: my $helpitem = 'Course_Helpdesk_Access';
7483: push (@{$brcrum},
7484: {href => '/adm/createuser?action=helpdesk',
7485: text => 'Helpdesk Access',
7486: help => $helpitem});
7487: my $bread_crumbs_component = 'Helpdesk Staff Access';
7488: my $args = { bread_crumbs => $brcrum,
7489: bread_crumbs_component => $bread_crumbs_component};
7490:
7491: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
7492: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
7493: my $confname = $cdom.'-domainconfig';
7494: my $crstype = &Apache::loncommon::course_type();
7495:
1.406.2.12 raeburn 7496: my @accesstypes = ('all','dh','da','none');
1.406.2.10 raeburn 7497: my ($numstatustypes,@jsarray);
7498: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($cdom);
7499: if (ref($types) eq 'ARRAY') {
7500: if (@{$types} > 0) {
7501: $numstatustypes = scalar(@{$types});
7502: push(@accesstypes,'status');
7503: @jsarray = ('bystatus');
7504: }
7505: }
7506: my %customroles = &get_domain_customroles($cdom,$confname);
1.406.2.12 raeburn 7507: my %domhelpdesk = &Apache::lonnet::get_active_domroles($cdom,['dh','da']);
1.406.2.10 raeburn 7508: if (keys(%domhelpdesk)) {
7509: push(@accesstypes,('inc','exc'));
7510: push(@jsarray,('notinc','notexc'));
7511: }
7512: push(@jsarray,'privs');
7513: my $hiddenstr = join("','",@jsarray);
7514: my $rolestr = join("','",sort(keys(%customroles)));
7515:
7516: my $jscript;
7517: my (%settings,%overridden);
7518: if (keys(%customroles)) {
7519: &get_adhocrole_settings($env{'request.course.id'},\@accesstypes,
7520: $types,\%customroles,\%settings,\%overridden);
7521: my %jsfull=();
7522: my %jslevels= (
7523: course => {},
7524: domain => {},
7525: system => {},
7526: );
7527: my %jslevelscurrent=(
7528: course => {},
7529: domain => {},
7530: system => {},
7531: );
7532: my (%privs,%jsprivs);
7533: &Apache::lonuserutils::custom_role_privs(\%privs,\%jsfull,\%jslevels,\%jslevelscurrent);
7534: foreach my $priv (keys(%jsfull)) {
7535: if ($jslevels{'course'}{$priv}) {
7536: $jsprivs{$priv} = 1;
7537: }
7538: }
7539: my (%elements,%stored);
7540: foreach my $role (keys(%customroles)) {
7541: $elements{$role.'_access'} = 'radio';
7542: $elements{$role.'_incrs'} = 'radio';
7543: if ($numstatustypes) {
7544: $elements{$role.'_status'} = 'checkbox';
7545: }
7546: if (keys(%domhelpdesk) > 0) {
7547: $elements{$role.'_staff_inc'} = 'checkbox';
7548: $elements{$role.'_staff_exc'} = 'checkbox';
7549: }
7550: $elements{$role.'_override'} = 'checkbox';
7551: if (ref($settings{$role}) eq 'HASH') {
7552: if ($settings{$role}{'access'} ne '') {
7553: my $curraccess = $settings{$role}{'access'};
7554: $stored{$role.'_access'} = $curraccess;
7555: $stored{$role.'_incrs'} = 1;
7556: if ($curraccess eq 'status') {
7557: if (ref($settings{$role}{'status'}) eq 'ARRAY') {
7558: $stored{$role.'_status'} = $settings{$role}{'status'};
7559: }
7560: } elsif (($curraccess eq 'exc') || ($curraccess eq 'inc')) {
7561: if (ref($settings{$role}{$curraccess}) eq 'ARRAY') {
7562: $stored{$role.'_staff_'.$curraccess} = $settings{$role}{$curraccess};
7563: }
7564: }
7565: } else {
7566: $stored{$role.'_incrs'} = 0;
7567: }
7568: $stored{$role.'_override'} = [];
7569: if ($env{'course.'.$env{'request.course.id'}.'.internal.adhocpriv.'.$role}) {
7570: if (ref($settings{$role}{'off'}) eq 'ARRAY') {
7571: foreach my $priv (@{$settings{$role}{'off'}}) {
7572: push(@{$stored{$role.'_override'}},$priv);
7573: }
7574: }
7575: if (ref($settings{$role}{'on'}) eq 'ARRAY') {
7576: foreach my $priv (@{$settings{$role}{'on'}}) {
7577: unless (grep(/^$priv$/,@{$stored{$role.'_override'}})) {
7578: push(@{$stored{$role.'_override'}},$priv);
7579: }
7580: }
7581: }
7582: }
7583: } else {
7584: $stored{$role.'_incrs'} = 0;
7585: }
7586: }
7587: $jscript = &Apache::lonhtmlcommon::set_form_elements(\%elements,\%stored);
7588: }
7589:
7590: my $js = <<"ENDJS";
7591: <script type="text/javascript">
7592: // <![CDATA[
7593: $jscript;
7594:
7595: function switchRoleTab(caller,role) {
7596: if (document.getElementById(role+'_maindiv')) {
7597: if (caller.id != 'LC_current_minitab') {
7598: if (document.getElementById('LC_current_minitab')) {
7599: document.getElementById('LC_current_minitab').id=null;
7600: }
7601: var roledivs = Array('$rolestr');
7602: if (roledivs.length > 0) {
7603: for (var i=0; i<roledivs.length; i++) {
7604: if (document.getElementById(roledivs[i]+'_maindiv')) {
7605: document.getElementById(roledivs[i]+'_maindiv').style.display='none';
7606: }
7607: }
7608: }
7609: caller.id = 'LC_current_minitab';
7610: document.getElementById(role+'_maindiv').style.display='block';
7611: }
7612: }
7613: return false;
7614: }
7615:
7616: function helpdeskAccess(role) {
7617: var curraccess = null;
7618: if (document.$formname.elements[role+'_access'].length) {
7619: for (var i=0; i<document.$formname.elements[role+'_access'].length; i++) {
7620: if (document.$formname.elements[role+'_access'][i].checked) {
7621: curraccess = document.$formname.elements[role+'_access'][i].value;
7622: }
7623: }
7624: }
7625: var shown = Array();
7626: var hidden = Array();
7627: if (curraccess == 'none') {
7628: hidden = Array ('$hiddenstr');
7629: } else {
7630: if (curraccess == 'status') {
7631: shown = Array ('bystatus','privs');
7632: hidden = Array ('notinc','notexc');
7633: } else {
7634: if (curraccess == 'exc') {
7635: shown = Array ('notexc','privs');
7636: hidden = Array ('notinc','bystatus');
7637: }
7638: if (curraccess == 'inc') {
7639: shown = Array ('notinc','privs');
7640: hidden = Array ('notexc','bystatus');
7641: }
7642: if (curraccess == 'all') {
7643: shown = Array ('privs');
7644: hidden = Array ('notinc','notexc','bystatus');
7645: }
7646: }
7647: }
7648: if (hidden.length > 0) {
7649: for (var i=0; i<hidden.length; i++) {
7650: if (document.getElementById(role+'_'+hidden[i])) {
7651: document.getElementById(role+'_'+hidden[i]).style.display = 'none';
7652: }
7653: }
7654: }
7655: if (shown.length > 0) {
7656: for (var i=0; i<shown.length; i++) {
7657: if (document.getElementById(role+'_'+shown[i])) {
7658: if (shown[i] == 'privs') {
7659: document.getElementById(role+'_'+shown[i]).style.display = 'block';
7660: } else {
7661: document.getElementById(role+'_'+shown[i]).style.display = 'inline';
7662: }
7663: }
7664: }
7665: }
7666: return;
7667: }
7668:
7669: function toggleAccess(role) {
7670: if ((document.getElementById(role+'_setincrs')) &&
7671: (document.getElementById(role+'_setindom'))) {
7672: for (var i=0; i<document.$formname.elements[role+'_incrs'].length; i++) {
7673: if (document.$formname.elements[role+'_incrs'][i].checked) {
7674: if (document.$formname.elements[role+'_incrs'][i].value == 1) {
7675: document.getElementById(role+'_setindom').style.display = 'none';
7676: document.getElementById(role+'_setincrs').style.display = 'block';
7677: } else {
7678: document.getElementById(role+'_setincrs').style.display = 'none';
7679: document.getElementById(role+'_setindom').style.display = 'block';
7680: }
7681: break;
7682: }
7683: }
7684: }
7685: return;
7686: }
7687:
7688: // ]]>
7689: </script>
7690: ENDJS
7691:
7692: $args->{add_entries} = {onload => "javascript:setFormElements(document.$formname)"};
7693:
7694: # print page header
7695: $r->print(&header($js,$args));
7696: # print form header
7697: $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">');
7698:
7699: if (keys(%customroles)) {
7700: my %lt = &Apache::lonlocal::texthash(
7701: 'aco' => 'As course owner you may override the defaults set in the domain for role usage and/or privileges.',
7702: 'rou' => 'Role usage',
7703: 'whi' => 'Which helpdesk personnel may use this role?',
7704: 'udd' => 'Use domain default',
1.406.2.12 raeburn 7705: 'all' => 'All with domain helpdesk or helpdesk assistant role',
7706: 'dh' => 'All with domain helpdesk role',
7707: 'da' => 'All with domain helpdesk assistant role',
1.406.2.10 raeburn 7708: 'none' => 'None',
7709: 'status' => 'Determined based on institutional status',
7710: 'inc' => 'Include all, but exclude specific personnel',
7711: 'exc' => 'Exclude all, but include specific personnel',
7712: 'hel' => 'Helpdesk',
7713: 'rpr' => 'Role privileges',
7714: );
7715: $lt{'tfh'} = &mt("Custom [_1]ad hoc[_2] course roles available for use by the domain's helpdesk are as follows",'<i>','</i>');
7716: my %domconfig = &Apache::lonnet::get_dom('configuration',['helpsettings'],$cdom);
7717: my (%domcurrent,%ordered,%description,%domusage,$disabled);
7718: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
7719: if (ref($domconfig{'helpsettings'}{'adhoc'}) eq 'HASH') {
7720: %domcurrent = %{$domconfig{'helpsettings'}{'adhoc'}};
7721: }
7722: }
7723: my $count = 0;
7724: foreach my $role (sort(keys(%customroles))) {
7725: my ($order,$desc,$access_in_dom);
7726: if (ref($domcurrent{$role}) eq 'HASH') {
7727: $order = $domcurrent{$role}{'order'};
7728: $desc = $domcurrent{$role}{'desc'};
7729: $access_in_dom = $domcurrent{$role}{'access'};
7730: }
7731: if ($order eq '') {
7732: $order = $count;
7733: }
7734: $ordered{$order} = $role;
7735: if ($desc ne '') {
7736: $description{$role} = $desc;
7737: } else {
7738: $description{$role}= $role;
7739: }
7740: $count++;
7741: }
7742: %domusage = &domain_adhoc_access(\%customroles,\%domcurrent,\@accesstypes,$usertypes,$othertitle);
7743: my @roles_by_num = ();
7744: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
7745: push(@roles_by_num,$ordered{$item});
7746: }
7747: $r->print('<p>'.$lt{'tfh'}.': <i>'.join('</i>, <i>',map { $description{$_}; } @roles_by_num).'</i>.');
7748: if ($permission->{'owner'}) {
7749: $r->print('<br />'.$lt{'aco'}.'</p><p>');
7750: $r->print('<input type="hidden" name="state" value="process" />'.
7751: '<input type="submit" value="'.&mt('Save changes').'" />');
7752: } else {
7753: if ($env{'course.'.$env{'request.course.id'}.'.internal.courseowner'}) {
7754: my ($ownername,$ownerdom) = split(/:/,$env{'course.'.$env{'request.course.id'}.'.internal.courseowner'});
7755: $r->print('<br />'.&mt('The course owner -- [_1] -- can override the default access and/or privileges for these ad hoc roles.',
7756: &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($ownername,$ownerdom),$ownername,$ownerdom)));
7757: }
7758: $disabled = ' disabled="disabled"';
7759: }
7760: $r->print('</p>');
7761:
7762: $r->print('<div id="LC_minitab_header"><ul>');
7763: my $count = 0;
7764: my %visibility;
7765: foreach my $role (@roles_by_num) {
7766: my $id;
7767: if ($count == 0) {
7768: $id=' id="LC_current_minitab"';
7769: $visibility{$role} = ' style="display:block"';
7770: } else {
7771: $visibility{$role} = ' style="display:none"';
7772: }
7773: $count ++;
7774: $r->print('<li'.$id.'><a href="#" onclick="javascript:switchRoleTab(this.parentNode,'."'$role'".');">'.$description{$role}.'</a></li>');
7775: }
7776: $r->print('</ul></div>');
7777:
7778: foreach my $role (@roles_by_num) {
7779: my %usecheck = (
7780: all => ' checked="checked"',
7781: );
7782: my %displaydiv = (
7783: status => 'none',
7784: inc => 'none',
7785: exc => 'none',
7786: priv => 'block',
7787: );
7788: my (%selected,$overridden,$incrscheck,$indomcheck,$indomvis,$incrsvis);
7789: if (ref($settings{$role}) eq 'HASH') {
7790: if ($settings{$role}{'access'} ne '') {
7791: $indomvis = ' style="display:none"';
7792: $incrsvis = ' style="display:block"';
7793: $incrscheck = ' checked="checked"';
7794: if ($settings{$role}{'access'} ne 'all') {
7795: $usecheck{$settings{$role}{'access'}} = $usecheck{'all'};
7796: delete($usecheck{'all'});
7797: if ($settings{$role}{'access'} eq 'status') {
7798: my $access = 'status';
7799: $displaydiv{$access} = 'inline';
7800: if (ref($settings{$role}{$access}) eq 'ARRAY') {
7801: $selected{$access} = $settings{$role}{$access};
7802: }
7803: } elsif ($settings{$role}{'access'} =~ /^(inc|exc)$/) {
7804: my $access = $1;
7805: $displaydiv{$access} = 'inline';
7806: if (ref($settings{$role}{$access}) eq 'ARRAY') {
7807: $selected{$access} = $settings{$role}{$access};
7808: }
7809: } elsif ($settings{$role}{'access'} eq 'none') {
7810: $displaydiv{'priv'} = 'none';
7811: }
7812: }
7813: } else {
7814: $indomcheck = ' checked="checked"';
7815: $indomvis = ' style="display:block"';
7816: $incrsvis = ' style="display:none"';
7817: }
7818: } else {
7819: $indomcheck = ' checked="checked"';
7820: $indomvis = ' style="display:block"';
7821: $incrsvis = ' style="display:none"';
7822: }
7823: $r->print('<div class="LC_left_float" id="'.$role.'_maindiv"'.$visibility{$role}.'>'.
7824: '<fieldset><legend>'.$lt{'rou'}.'</legend>'.
7825: '<p>'.$lt{'whi'}.' <span class="LC_nobreak">'.
7826: '<label><input type="radio" name="'.$role.'_incrs" value="1"'.$incrscheck.' onclick="toggleAccess('."'$role'".');"'.$disabled.'>'.
7827: &mt('Set here in [_1]',lc($crstype)).'</label>'.
7828: '<span>'.(' 'x2).
7829: '<label><input type="radio" name="'.$role.'_incrs" value="0"'.$indomcheck.' onclick="toggleAccess('."'$role'".');"'.$disabled.'>'.
7830: $lt{'udd'}.'</label><span></p>'.
7831: '<div id="'.$role.'_setindom"'.$indomvis.'>'.
7832: '<span class="LC_cusr_emph">'.$domusage{$role}.'</span></div>'.
7833: '<div id="'.$role.'_setincrs"'.$incrsvis.'>');
7834: foreach my $access (@accesstypes) {
7835: $r->print('<p><label><input type="radio" name="'.$role.'_access" value="'.$access.'" '.$usecheck{$access}.
7836: ' onclick="helpdeskAccess('."'$role'".');"'.$disabled.' />'.$lt{$access}.'</label>');
7837: if ($access eq 'status') {
7838: $r->print('<div id="'.$role.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
7839: &Apache::lonuserutils::adhoc_status_types($cdom,undef,$role,$selected{$access},
7840: $othertitle,$usertypes,$types,$disabled).
7841: '</div>');
7842: } elsif (($access eq 'inc') && (keys(%domhelpdesk) > 0)) {
7843: $r->print('<div id="'.$role.'_notinc" style="display:'.$displaydiv{$access}.'">'.
7844: &Apache::lonuserutils::adhoc_staff($access,undef,$role,$selected{$access},
7845: \%domhelpdesk,$disabled).
7846: '</div>');
7847: } elsif (($access eq 'exc') && (keys(%domhelpdesk) > 0)) {
7848: $r->print('<div id="'.$role.'_notexc" style="display:'.$displaydiv{$access}.'">'.
7849: &Apache::lonuserutils::adhoc_staff($access,undef,$role,$selected{$access},
7850: \%domhelpdesk,$disabled).
7851: '</div>');
7852: }
7853: $r->print('</p>');
7854: }
7855: $r->print('</div></fieldset>');
7856: my %full=();
7857: my %levels= (
7858: course => {},
7859: domain => {},
7860: system => {},
7861: );
7862: my %levelscurrent=(
7863: course => {},
7864: domain => {},
7865: system => {},
7866: );
7867: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
7868: $r->print('<fieldset id="'.$role.'_privs" style="display:'.$displaydiv{'priv'}.'">'.
7869: '<legend>'.$lt{'rpr'}.'</legend>'.
7870: &role_priv_table($role,$permission,$crstype,\%full,\%levels,\%levelscurrent,$overridden{$role}).
7871: '</fieldset></div><div style="padding:0;clear:both;margin:0;border:0"></div>');
7872: }
7873: if ($permission->{'owner'}) {
7874: $r->print('<p><input type="submit" value="'.&mt('Save changes').'" /></p>');
7875: }
7876: } else {
7877: $r->print(&mt('Helpdesk roles have not yet been created in this domain.'));
7878: }
7879: # Form Footer
7880: $r->print('<input type="hidden" name="action" value="helpdesk" />'
7881: .'</form>');
7882: return;
7883: }
7884:
7885: sub domain_adhoc_access {
7886: my ($roles,$domcurrent,$accesstypes,$usertypes,$othertitle) = @_;
7887: my %domusage;
7888: return unless ((ref($roles) eq 'HASH') && (ref($domcurrent) eq 'HASH') && (ref($accesstypes) eq 'ARRAY'));
7889: foreach my $role (keys(%{$roles})) {
7890: if (ref($domcurrent->{$role}) eq 'HASH') {
7891: my $access = $domcurrent->{$role}{'access'};
7892: if (($access eq '') || (!grep(/^\Q$access\E$/,@{$accesstypes}))) {
7893: $access = 'all';
1.406.2.12 raeburn 7894: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role',&Apache::lonnet::plaintext('dh'),
7895: &Apache::lonnet::plaintext('da'));
1.406.2.10 raeburn 7896: } elsif ($access eq 'status') {
7897: if (ref($domcurrent->{$role}{$access}) eq 'ARRAY') {
7898: my @shown;
7899: foreach my $type (@{$domcurrent->{$role}{$access}}) {
7900: unless ($type eq 'default') {
7901: if ($usertypes->{$type}) {
7902: push(@shown,$usertypes->{$type});
7903: }
7904: }
7905: }
7906: if (grep(/^default$/,@{$domcurrent->{$role}{$access}})) {
7907: push(@shown,$othertitle);
7908: }
7909: if (@shown) {
7910: my $shownstatus = join(' '.&mt('or').' ',@shown);
1.406.2.12 raeburn 7911: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role, and institutional status: [_3]',
7912: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'),$shownstatus);
1.406.2.10 raeburn 7913: } else {
7914: $domusage{$role} = &mt('No one in the domain');
7915: }
7916: }
7917: } elsif ($access eq 'inc') {
7918: my @dominc = ();
7919: if (ref($domcurrent->{$role}{'inc'}) eq 'ARRAY') {
7920: foreach my $user (@{$domcurrent->{$role}{'inc'}}) {
7921: my ($uname,$udom) = split(/:/,$user);
7922: push(@dominc,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),$uname,$udom));
7923: }
7924: my $showninc = join(', ',@dominc);
7925: if ($showninc ne '') {
1.406.2.12 raeburn 7926: $domusage{$role} = &mt('Include any user in domain with active [_1] or [_2] role, except: [_3]',
7927: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'),$showninc);
1.406.2.10 raeburn 7928: } else {
1.406.2.12 raeburn 7929: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role',
7930: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'));
1.406.2.10 raeburn 7931: }
7932: }
7933: } elsif ($access eq 'exc') {
7934: my @domexc = ();
7935: if (ref($domcurrent->{$role}{'exc'}) eq 'ARRAY') {
7936: foreach my $user (@{$domcurrent->{$role}{'exc'}}) {
7937: my ($uname,$udom) = split(/:/,$user);
7938: push(@domexc,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),$uname,$udom));
7939: }
7940: }
7941: my $shownexc = join(', ',@domexc);
7942: if ($shownexc ne '') {
1.406.2.12 raeburn 7943: $domusage{$role} = &mt('Only the following in the domain with active [_1] or [_2] role: [_3]',
7944: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'),$shownexc);
1.406.2.10 raeburn 7945: } else {
7946: $domusage{$role} = &mt('No one in the domain');
7947: }
7948: } elsif ($access eq 'none') {
7949: $domusage{$role} = &mt('No one in the domain');
1.406.2.12 raeburn 7950: } elsif ($access eq 'dh') {
1.406.2.10 raeburn 7951: $domusage{$role} = &mt('Any user in domain with active [_1] role',&Apache::lonnet::plaintext('dh'));
1.406.2.12 raeburn 7952: } elsif ($access eq 'da') {
7953: $domusage{$role} = &mt('Any user in domain with active [_1] role',&Apache::lonnet::plaintext('da'));
7954: } elsif ($access eq 'all') {
7955: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role',
7956: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'));
1.406.2.10 raeburn 7957: }
7958: } else {
1.406.2.12 raeburn 7959: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role',
7960: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'));
1.406.2.10 raeburn 7961: }
7962: }
7963: return %domusage;
7964: }
7965:
7966: sub get_domain_customroles {
7967: my ($cdom,$confname) = @_;
7968: my %existing=&Apache::lonnet::dump('roles',$cdom,$confname,'rolesdef_');
7969: my %customroles;
7970: foreach my $key (keys(%existing)) {
7971: if ($key=~/^rolesdef\_(\w+)$/) {
7972: my $rolename = $1;
7973: my %privs;
7974: ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
7975: $customroles{$rolename} = \%privs;
7976: }
7977: }
7978: return %customroles;
7979: }
7980:
7981: sub role_priv_table {
7982: my ($role,$permission,$crstype,$full,$levels,$levelscurrent,$overridden) = @_;
7983: return unless ((ref($full) eq 'HASH') && (ref($levels) eq 'HASH') &&
7984: (ref($levelscurrent) eq 'HASH'));
7985: my %lt=&Apache::lonlocal::texthash (
7986: 'crl' => 'Course Level Privilege',
7987: 'def' => 'Domain Defaults',
7988: 'ove' => 'Override in Course',
7989: 'ine' => 'In effect',
7990: 'dis' => 'Disabled',
7991: 'ena' => 'Enabled',
7992: );
7993: if ($crstype eq 'Community') {
7994: $lt{'ove'} = 'Override in Community',
7995: }
7996: my @status = ('Disabled','Enabled');
7997: my (%on,%off);
7998: if (ref($overridden) eq 'HASH') {
7999: if (ref($overridden->{'on'}) eq 'ARRAY') {
8000: map { $on{$_} = 1; } (@{$overridden->{'on'}});
8001: }
8002: if (ref($overridden->{'off'}) eq 'ARRAY') {
8003: map { $off{$_} = 1; } (@{$overridden->{'off'}});
8004: }
8005: }
8006: my $output=&Apache::loncommon::start_data_table().
8007: &Apache::loncommon::start_data_table_header_row().
8008: '<th>'.$lt{'crl'}.'</th><th>'.$lt{'def'}.'</th><th>'.$lt{'ove'}.
8009: '</th><th>'.$lt{'ine'}.'</th>'.
8010: &Apache::loncommon::end_data_table_header_row();
8011: foreach my $priv (sort(keys(%{$full}))) {
8012: next unless ($levels->{'course'}{$priv});
8013: my $privtext = &Apache::lonnet::plaintext($priv,$crstype);
8014: my ($default,$ineffect);
8015: if ($levelscurrent->{'course'}{$priv}) {
8016: $default = '<img src="/adm/lonIcons/navmap.correct.gif" alt="'.$lt{'ena'}.'" />';
8017: $ineffect = $default;
8018: }
8019: my ($customstatus,$checked);
8020: $output .= &Apache::loncommon::start_data_table_row().
8021: '<td>'.$privtext.'</td>'.
8022: '<td>'.$default.'</td><td>';
8023: if (($levelscurrent->{'course'}{$priv}) && ($off{$priv})) {
8024: if ($permission->{'owner'}) {
8025: $checked = ' checked="checked"';
8026: }
8027: $customstatus = '<img src="/adm/lonIcons/navmap.wrong.gif" alt="'.$lt{'dis'}.'" />';
8028: $ineffect = $customstatus;
8029: } elsif ((!$levelscurrent->{'course'}{$priv}) && ($on{$priv})) {
8030: if ($permission->{'owner'}) {
8031: $checked = ' checked="checked"';
8032: }
8033: $customstatus = '<img src="/adm/lonIcons/navmap.correct.gif" alt="'.$lt{'ena'}.'" />';
8034: $ineffect = $customstatus;
8035: }
8036: if ($permission->{'owner'}) {
8037: $output .= '<input type="checkbox" name="'.$role.'_override" value="'.$priv.'"'.$checked.' />';
8038: } else {
8039: $output .= $customstatus;
8040: }
8041: $output .= '</td><td>'.$ineffect.'</td>'.
8042: &Apache::loncommon::end_data_table_row();
8043: }
8044: $output .= &Apache::loncommon::end_data_table();
8045: return $output;
8046: }
8047:
8048: sub get_adhocrole_settings {
8049: my ($cid,$accesstypes,$types,$customroles,$settings,$overridden) = @_;
8050: return unless ((ref($accesstypes) eq 'ARRAY') && (ref($customroles) eq 'HASH') &&
8051: (ref($settings) eq 'HASH') && (ref($overridden) eq 'HASH'));
8052: foreach my $role (split(/,/,$env{'course.'.$cid.'.internal.adhocaccess'})) {
8053: my ($curraccess,$rest) = split(/=/,$env{'course.'.$cid.'.internal.adhoc.'.$role});
8054: if (($curraccess ne '') && (grep(/^\Q$curraccess\E$/,@{$accesstypes}))) {
8055: $settings->{$role}{'access'} = $curraccess;
8056: if (($curraccess eq 'status') && (ref($types) eq 'ARRAY')) {
8057: my @status = split(/,/,$rest);
8058: my @currstatus;
8059: foreach my $type (@status) {
8060: if ($type eq 'default') {
8061: push(@currstatus,$type);
8062: } elsif (grep(/^\Q$type\E$/,@{$types})) {
8063: push(@currstatus,$type);
8064: }
8065: }
8066: if (@currstatus) {
8067: $settings->{$role}{$curraccess} = \@currstatus;
8068: } elsif (($curraccess eq 'exc') || ($curraccess eq 'inc')) {
8069: my @personnel = split(/,/,$rest);
8070: $settings->{$role}{$curraccess} = \@personnel;
8071: }
8072: }
8073: }
8074: }
8075: foreach my $role (keys(%{$customroles})) {
8076: if ($env{'course.'.$cid.'.internal.adhocpriv.'.$role}) {
8077: my %currentprivs;
8078: if (ref($customroles->{$role}) eq 'HASH') {
8079: if (exists($customroles->{$role}{'course'})) {
8080: my %full=();
8081: my %levels= (
8082: course => {},
8083: domain => {},
8084: system => {},
8085: );
8086: my %levelscurrent=(
8087: course => {},
8088: domain => {},
8089: system => {},
8090: );
8091: &Apache::lonuserutils::custom_role_privs($customroles->{$role},\%full,\%levels,\%levelscurrent);
8092: %currentprivs = %{$levelscurrent{'course'}};
8093: }
8094: }
8095: foreach my $item (split(/,/,$env{'course.'.$cid.'.internal.adhocpriv.'.$role})) {
8096: next if ($item eq '');
8097: my ($rule,$rest) = split(/=/,$item);
8098: next unless (($rule eq 'off') || ($rule eq 'on'));
8099: foreach my $priv (split(/:/,$rest)) {
8100: if ($priv ne '') {
8101: if ($rule eq 'off') {
8102: push(@{$overridden->{$role}{'off'}},$priv);
8103: if ($currentprivs{$priv}) {
8104: push(@{$settings->{$role}{'off'}},$priv);
8105: }
8106: } else {
8107: push(@{$overridden->{$role}{'on'}},$priv);
8108: unless ($currentprivs{$priv}) {
8109: push(@{$settings->{$role}{'on'}},$priv);
8110: }
8111: }
8112: }
8113: }
8114: }
8115: }
8116: }
8117: return;
8118: }
8119:
8120: sub update_helpdeskaccess {
8121: my ($r,$permission,$brcrum) = @_;
8122: my $helpitem = 'Course_Helpdesk_Access';
8123: push (@{$brcrum},
8124: {href => '/adm/createuser?action=helpdesk',
8125: text => 'Helpdesk Access',
8126: help => $helpitem},
8127: {href => '/adm/createuser?action=helpdesk',
8128: text => 'Result',
8129: help => $helpitem}
8130: );
8131: my $bread_crumbs_component = 'Helpdesk Staff Access';
8132: my $args = { bread_crumbs => $brcrum,
8133: bread_crumbs_component => $bread_crumbs_component};
8134:
8135: # print page header
8136: $r->print(&header('',$args));
8137: unless ((ref($permission) eq 'HASH') && ($permission->{'owner'})) {
8138: $r->print('<p class="LC_error">'.&mt('You do not have permission to change helpdesk access.').'</p>');
8139: return;
8140: }
1.406.2.12 raeburn 8141: my @accesstypes = ('all','dh','da','none','status','inc','exc');
1.406.2.10 raeburn 8142: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
8143: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
8144: my $confname = $cdom.'-domainconfig';
8145: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($cdom);
8146: my $crstype = &Apache::loncommon::course_type();
8147: my %customroles = &get_domain_customroles($cdom,$confname);
8148: my (%settings,%overridden);
8149: &get_adhocrole_settings($env{'request.course.id'},\@accesstypes,
8150: $types,\%customroles,\%settings,\%overridden);
1.406.2.12 raeburn 8151: my %domhelpdesk = &Apache::lonnet::get_active_domroles($cdom,['dh','da']);
1.406.2.10 raeburn 8152: my (%changed,%storehash,@todelete);
8153:
8154: if (keys(%customroles)) {
8155: my (%newsettings,@incrs);
8156: foreach my $role (keys(%customroles)) {
8157: $newsettings{$role} = {
8158: access => '',
8159: status => '',
8160: exc => '',
8161: inc => '',
8162: on => '',
8163: off => '',
8164: };
8165: my %current;
8166: if (ref($settings{$role}) eq 'HASH') {
8167: %current = %{$settings{$role}};
8168: }
8169: if (ref($overridden{$role}) eq 'HASH') {
8170: $current{'overridden'} = $overridden{$role};
8171: }
8172: if ($env{'form.'.$role.'_incrs'}) {
8173: my $access = $env{'form.'.$role.'_access'};
8174: if (grep(/^\Q$access\E$/,@accesstypes)) {
8175: push(@incrs,$role);
8176: unless ($current{'access'} eq $access) {
8177: $changed{$role}{'access'} = 1;
8178: $storehash{'internal.adhoc.'.$role} = $access;
8179: }
8180: if ($access eq 'status') {
8181: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$role.'_status');
8182: my @stored;
8183: my @shownstatus;
8184: if (ref($types) eq 'ARRAY') {
8185: foreach my $type (sort(@statuses)) {
8186: if ($type eq 'default') {
8187: push(@stored,$type);
8188: } elsif (grep(/^\Q$type\E$/,@{$types})) {
8189: push(@stored,$type);
8190: push(@shownstatus,$usertypes->{$type});
8191: }
8192: }
8193: if (grep(/^default$/,@statuses)) {
8194: push(@shownstatus,$othertitle);
8195: }
8196: $storehash{'internal.adhoc.'.$role} .= '='.join(',',@stored);
8197: }
8198: $newsettings{$role}{'status'} = join(' '.&mt('or').' ',@shownstatus);
8199: if (ref($current{'status'}) eq 'ARRAY') {
8200: my @diffs = &Apache::loncommon::compare_arrays(\@stored,$current{'status'});
8201: if (@diffs) {
8202: $changed{$role}{'status'} = 1;
8203: }
8204: } elsif (@stored) {
8205: $changed{$role}{'status'} = 1;
8206: }
8207: } elsif (($access eq 'inc') || ($access eq 'exc')) {
8208: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$role.'_staff_'.$access);
8209: my @newspecstaff;
8210: my @stored;
8211: my @currstaff;
8212: foreach my $person (sort(@personnel)) {
8213: if ($domhelpdesk{$person}) {
8214: push(@stored,$person);
8215: }
8216: }
8217: if (ref($current{$access}) eq 'ARRAY') {
8218: my @diffs = &Apache::loncommon::compare_arrays(\@stored,$current{$access});
8219: if (@diffs) {
8220: $changed{$role}{$access} = 1;
8221: }
8222: } elsif (@stored) {
8223: $changed{$role}{$access} = 1;
8224: }
8225: $storehash{'internal.adhoc.'.$role} .= '='.join(',',@stored);
8226: foreach my $person (@stored) {
8227: my ($uname,$udom) = split(/:/,$person);
8228: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
8229: }
8230: $newsettings{$role}{$access} = join(', ',sort(@newspecstaff));
8231: }
8232: $newsettings{$role}{'access'} = $access;
8233: }
8234: } else {
8235: if (($current{'access'} ne '') && (grep(/^\Q$current{'access'}\E$/,@accesstypes))) {
8236: $changed{$role}{'access'} = 1;
8237: $newsettings{$role} = {};
8238: push(@todelete,'internal.adhoc.'.$role);
8239: }
8240: }
8241: if (($env{'form.'.$role.'_incrs'}) && ($env{'form.'.$role.'_access'} eq 'none')) {
8242: if (ref($current{'overridden'}) eq 'HASH') {
8243: push(@todelete,'internal.adhocpriv.'.$role);
8244: }
8245: } else {
8246: my %full=();
8247: my %levels= (
8248: course => {},
8249: domain => {},
8250: system => {},
8251: );
8252: my %levelscurrent=(
8253: course => {},
8254: domain => {},
8255: system => {},
8256: );
8257: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
8258: my (@updatedon,@updatedoff,@override);
8259: @override = &Apache::loncommon::get_env_multiple('form.'.$role.'_override');
8260: if (@override) {
8261: foreach my $priv (sort(keys(%full))) {
8262: next unless ($levels{'course'}{$priv});
8263: if (grep(/^\Q$priv\E$/,@override)) {
8264: if ($levelscurrent{'course'}{$priv}) {
8265: push(@updatedoff,$priv);
8266: } else {
8267: push(@updatedon,$priv);
8268: }
8269: }
8270: }
8271: }
8272: if (@updatedon) {
8273: $newsettings{$role}{'on'} = join('</li><li>', map { &Apache::lonnet::plaintext($_,$crstype) } (@updatedon));
8274: }
8275: if (@updatedoff) {
8276: $newsettings{$role}{'off'} = join('</li><li>', map { &Apache::lonnet::plaintext($_,$crstype) } (@updatedoff));
8277: }
8278: if (ref($current{'overridden'}) eq 'HASH') {
8279: if (ref($current{'overridden'}{'on'}) eq 'ARRAY') {
8280: if (@updatedon) {
8281: my @diffs = &Apache::loncommon::compare_arrays(\@updatedon,$current{'overridden'}{'on'});
8282: if (@diffs) {
8283: $changed{$role}{'on'} = 1;
8284: }
8285: } else {
8286: $changed{$role}{'on'} = 1;
8287: }
8288: } elsif (@updatedon) {
8289: $changed{$role}{'on'} = 1;
8290: }
8291: if (ref($current{'overridden'}{'off'}) eq 'ARRAY') {
8292: if (@updatedoff) {
8293: my @diffs = &Apache::loncommon::compare_arrays(\@updatedoff,$current{'overridden'}{'off'});
8294: if (@diffs) {
8295: $changed{$role}{'off'} = 1;
8296: }
8297: } else {
8298: $changed{$role}{'off'} = 1;
8299: }
8300: } elsif (@updatedoff) {
8301: $changed{$role}{'off'} = 1;
8302: }
8303: } else {
8304: if (@updatedon) {
8305: $changed{$role}{'on'} = 1;
8306: }
8307: if (@updatedoff) {
8308: $changed{$role}{'off'} = 1;
8309: }
8310: }
8311: if (ref($changed{$role}) eq 'HASH') {
8312: if (($changed{$role}{'on'} || $changed{$role}{'off'})) {
8313: my $newpriv;
8314: if (@updatedon) {
8315: $newpriv = 'on='.join(':',@updatedon);
8316: }
8317: if (@updatedoff) {
8318: $newpriv .= ($newpriv ? ',' : '' ).'off='.join(':',@updatedoff);
8319: }
8320: if ($newpriv eq '') {
8321: push(@todelete,'internal.adhocpriv.'.$role);
8322: } else {
8323: $storehash{'internal.adhocpriv.'.$role} = $newpriv;
8324: }
8325: }
8326: }
8327: }
8328: }
8329: if (@incrs) {
8330: $storehash{'internal.adhocaccess'} = join(',',@incrs);
8331: } elsif (@todelete) {
8332: push(@todelete,'internal.adhocaccess');
8333: }
8334: if (keys(%changed)) {
8335: my ($putres,$delres);
8336: if (keys(%storehash)) {
8337: $putres = &Apache::lonnet::put('environment',\%storehash,$cdom,$cnum);
8338: my %newenvhash;
8339: foreach my $key (keys(%storehash)) {
8340: $newenvhash{'course.'.$env{'request.course.id'}.'.'.$key} = $storehash{$key};
8341: }
8342: &Apache::lonnet::appenv(\%newenvhash);
8343: }
8344: if (@todelete) {
8345: $delres = &Apache::lonnet::del('environment',\@todelete,$cdom,$cnum);
8346: foreach my $key (@todelete) {
8347: &Apache::lonnet::delenv('course.'.$env{'request.course.id'}.'.'.$key);
8348: }
8349: }
8350: if (($putres eq 'ok') || ($delres eq 'ok')) {
8351: my %domconfig = &Apache::lonnet::get_dom('configuration',['helpsettings'],$cdom);
8352: my (%domcurrent,%ordered,%description,%domusage);
8353: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
8354: if (ref($domconfig{'helpsettings'}{'adhoc'}) eq 'HASH') {
8355: %domcurrent = %{$domconfig{'helpsettings'}{'adhoc'}};
8356: }
8357: }
8358: my $count = 0;
8359: foreach my $role (sort(keys(%customroles))) {
8360: my ($order,$desc);
8361: if (ref($domcurrent{$role}) eq 'HASH') {
8362: $order = $domcurrent{$role}{'order'};
8363: $desc = $domcurrent{$role}{'desc'};
8364: }
8365: if ($order eq '') {
8366: $order = $count;
8367: }
8368: $ordered{$order} = $role;
8369: if ($desc ne '') {
8370: $description{$role} = $desc;
8371: } else {
8372: $description{$role}= $role;
8373: }
8374: $count++;
8375: }
8376: my @roles_by_num = ();
8377: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
8378: push(@roles_by_num,$ordered{$item});
8379: }
8380: %domusage = &domain_adhoc_access(\%changed,\%domcurrent,\@accesstypes,$usertypes,$othertitle);
8381: $r->print(&mt('Helpdesk access settings have been changed as follows').'<br />');
8382: $r->print('<ul>');
8383: foreach my $role (@roles_by_num) {
8384: next unless (ref($changed{$role}) eq 'HASH');
8385: $r->print('<li>'.&mt('Ad hoc role').': <b>'.$description{$role}.'</b>'.
8386: '<ul>');
8387: if ($changed{$role}{'access'} || $changed{$role}{'status'} || $changed{$role}{'inc'} || $changed{$role}{'exc'}) {
8388: $r->print('<li>');
8389: if ($env{'form.'.$role.'_incrs'}) {
8390: if ($newsettings{$role}{'access'} eq 'all') {
8391: $r->print(&mt('All helpdesk staff can access '.lc($crstype).' with this role.'));
1.406.2.12 raeburn 8392: } elsif ($newsettings{$role}{'access'} eq 'dh') {
8393: $r->print(&mt('Helpdesk staff can use this role if they have an active [_1] role',
8394: &Apache::lonnet::plaintext('dh')));
8395: } elsif ($newsettings{$role}{'access'} eq 'da') {
8396: $r->print(&mt('Helpdesk staff can use this role if they have an active [_1] role',
8397: &Apache::lonnet::plaintext('da')));
1.406.2.10 raeburn 8398: } elsif ($newsettings{$role}{'access'} eq 'none') {
8399: $r->print(&mt('No helpdesk staff can access '.lc($crstype).' with this role.'));
8400: } elsif ($newsettings{$role}{'access'} eq 'status') {
8401: if ($newsettings{$role}{'status'}) {
8402: my ($access,$rest) = split(/=/,$storehash{'internal.adhoc.'.$role});
8403: if (split(/,/,$rest) > 1) {
8404: $r->print(&mt('Helpdesk staff can use this role if their institutional type is one of: [_1].',
8405: $newsettings{$role}{'status'}));
8406: } else {
8407: $r->print(&mt('Helpdesk staff can use this role if their institutional type is: [_1].',
8408: $newsettings{$role}{'status'}));
8409: }
8410: } else {
8411: $r->print(&mt('No helpdesk staff can access '.lc($crstype).' with this role.'));
8412: }
8413: } elsif ($newsettings{$role}{'access'} eq 'exc') {
8414: if ($newsettings{$role}{'exc'}) {
8415: $r->print(&mt('Helpdesk staff who can use this role are as follows:').' '.$newsettings{$role}{'exc'}.'.');
8416: } else {
8417: $r->print(&mt('No helpdesk staff can access '.lc($crstype).' with this role.'));
8418: }
8419: } elsif ($newsettings{$role}{'access'} eq 'inc') {
8420: if ($newsettings{$role}{'inc'}) {
8421: $r->print(&mt('All helpdesk staff may use this role except the following:').' '.$newsettings{$role}{'inc'}.'.');
8422: } else {
8423: $r->print(&mt('All helpdesk staff may use this role.'));
8424: }
8425: }
8426: } else {
8427: $r->print(&mt('Default access set in the domain now applies.').'<br />'.
8428: '<span class="LC_cusr_emph">'.$domusage{$role}.'</span>');
8429: }
8430: $r->print('</li>');
8431: }
8432: unless ($newsettings{$role}{'access'} eq 'none') {
8433: if ($changed{$role}{'off'}) {
8434: if ($newsettings{$role}{'off'}) {
8435: $r->print('<li>'.&mt('Privileges which are available by default for this ad hoc role, but are disabled for this specific '.lc($crstype).':').
8436: '<ul><li>'.$newsettings{$role}{'off'}.'</li></ul></li>');
8437: } else {
8438: $r->print('<li>'.&mt('All privileges available by default for this ad hoc role are enabled.').'</li>');
8439: }
8440: }
8441: if ($changed{$role}{'on'}) {
8442: if ($newsettings{$role}{'on'}) {
8443: $r->print('<li>'.&mt('Privileges which are not available by default for this ad hoc role, but are enabled for this specific '.lc($crstype).':').
8444: '<ul><li>'.$newsettings{$role}{'on'}.'</li></ul></li>');
8445: } else {
8446: $r->print('<li>'.&mt('None of the privileges unavailable by default for this ad hoc role are enabled.').'</li>');
8447: }
8448: }
8449: }
8450: $r->print('</ul></li>');
8451: }
8452: $r->print('</ul>');
8453: }
8454: } else {
8455: $r->print(&mt('No changes made to helpdesk access settings.'));
8456: }
8457: }
8458: return;
8459: }
8460:
1.27 matthew 8461: #-------------------------------------------------- functions for &phase_two
1.160 raeburn 8462: sub user_search_result {
1.221 raeburn 8463: my ($context,$srch) = @_;
1.160 raeburn 8464: my %allhomes;
8465: my %inst_matches;
8466: my %srch_results;
1.181 raeburn 8467: my ($response,$currstate,$forcenewuser,$dirsrchres);
1.183 raeburn 8468: $srch->{'srchterm'} =~ s/\s+/ /g;
1.176 raeburn 8469: if ($srch->{'srchby'} !~ /^(uname|lastname|lastfirst)$/) {
1.160 raeburn 8470: $response = &mt('Invalid search.');
8471: }
8472: if ($srch->{'srchin'} !~ /^(crs|dom|alc|instd)$/) {
8473: $response = &mt('Invalid search.');
8474: }
1.177 raeburn 8475: if ($srch->{'srchtype'} !~ /^(exact|contains|begins)$/) {
1.160 raeburn 8476: $response = &mt('Invalid search.');
8477: }
8478: if ($srch->{'srchterm'} eq '') {
8479: $response = &mt('You must enter a search term.');
8480: }
1.183 raeburn 8481: if ($srch->{'srchterm'} =~ /^\s+$/) {
8482: $response = &mt('Your search term must contain more than just spaces.');
8483: }
1.160 raeburn 8484: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'instd')) {
8485: if (($srch->{'srchdomain'} eq '') ||
1.163 albertel 8486: ! (&Apache::lonnet::domain($srch->{'srchdomain'}))) {
1.160 raeburn 8487: $response = &mt('You must specify a valid domain when searching in a domain or institutional directory.')
8488: }
8489: }
8490: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs') ||
8491: ($srch->{'srchin'} eq 'alc')) {
1.176 raeburn 8492: if ($srch->{'srchby'} eq 'uname') {
1.243 raeburn 8493: my $unamecheck = $srch->{'srchterm'};
8494: if ($srch->{'srchtype'} eq 'contains') {
8495: if ($unamecheck !~ /^\w/) {
8496: $unamecheck = 'a'.$unamecheck;
8497: }
8498: }
8499: if ($unamecheck !~ /^$match_username$/) {
1.176 raeburn 8500: $response = &mt('You must specify a valid username. Only the following are allowed: letters numbers - . @');
8501: }
1.160 raeburn 8502: }
8503: }
1.180 raeburn 8504: if ($response ne '') {
1.406.2.4 raeburn 8505: $response = '<span class="LC_warning">'.$response.'</span><br />';
1.180 raeburn 8506: }
1.160 raeburn 8507: if ($srch->{'srchin'} eq 'instd') {
1.406.2.3 raeburn 8508: my $instd_chk = &instdirectorysrch_check($srch);
1.160 raeburn 8509: if ($instd_chk ne 'ok') {
1.406.2.3 raeburn 8510: my $domd_chk = &domdirectorysrch_check($srch);
1.406.2.4 raeburn 8511: $response .= '<span class="LC_warning">'.$instd_chk.'</span><br />';
1.406.2.3 raeburn 8512: if ($domd_chk eq 'ok') {
1.406.2.4 raeburn 8513: $response .= &mt('You may want to search in the LON-CAPA domain instead of the institutional directory.');
1.406.2.3 raeburn 8514: }
1.406.2.5 raeburn 8515: $response .= '<br />';
1.406.2.3 raeburn 8516: }
8517: } else {
8518: unless (($context eq 'requestcrs') && ($srch->{'srchtype'} eq 'exact')) {
8519: my $domd_chk = &domdirectorysrch_check($srch);
1.406.2.14 raeburn 8520: if (($domd_chk ne 'ok') && ($env{'form.action'} ne 'accesslogs')) {
1.406.2.3 raeburn 8521: my $instd_chk = &instdirectorysrch_check($srch);
1.406.2.4 raeburn 8522: $response .= '<span class="LC_warning">'.$domd_chk.'</span><br />';
1.406.2.3 raeburn 8523: if ($instd_chk eq 'ok') {
1.406.2.4 raeburn 8524: $response .= &mt('You may want to search in the institutional directory instead of the LON-CAPA domain.');
1.406.2.3 raeburn 8525: }
1.406.2.5 raeburn 8526: $response .= '<br />';
1.406.2.3 raeburn 8527: }
1.160 raeburn 8528: }
8529: }
8530: if ($response ne '') {
1.180 raeburn 8531: return ($currstate,$response);
1.160 raeburn 8532: }
8533: if ($srch->{'srchby'} eq 'uname') {
8534: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs')) {
8535: if ($env{'form.forcenew'}) {
8536: if ($srch->{'srchdomain'} ne $env{'request.role.domain'}) {
8537: my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
8538: if ($uhome eq 'no_host') {
8539: my $domdesc = &Apache::lonnet::domain($env{'request.role.domain'},'description');
1.180 raeburn 8540: my $showdom = &display_domain_info($env{'request.role.domain'});
8541: $response = &mt('New users can only be created in the domain to which your current role belongs - [_1].',$showdom);
1.160 raeburn 8542: } else {
1.179 raeburn 8543: $currstate = 'modify';
1.160 raeburn 8544: }
8545: } else {
1.179 raeburn 8546: $currstate = 'modify';
1.160 raeburn 8547: }
8548: } else {
8549: if ($srch->{'srchin'} eq 'dom') {
1.162 raeburn 8550: if ($srch->{'srchtype'} eq 'exact') {
8551: my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
8552: if ($uhome eq 'no_host') {
1.179 raeburn 8553: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8554: &build_search_response($context,$srch,%srch_results);
1.162 raeburn 8555: } else {
1.179 raeburn 8556: $currstate = 'modify';
1.406.2.5 raeburn 8557: if ($env{'form.action'} eq 'accesslogs') {
8558: $currstate = 'activity';
8559: }
1.310 raeburn 8560: my $uname = $srch->{'srchterm'};
8561: my $udom = $srch->{'srchdomain'};
8562: $srch_results{$uname.':'.$udom} =
8563: { &Apache::lonnet::get('environment',
8564: ['firstname',
8565: 'lastname',
8566: 'permanentemail'],
8567: $udom,$uname)
8568: };
1.162 raeburn 8569: }
8570: } else {
8571: %srch_results = &Apache::lonnet::usersearch($srch);
1.179 raeburn 8572: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8573: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 8574: }
8575: } else {
1.167 albertel 8576: my $courseusers = &get_courseusers();
1.162 raeburn 8577: if ($srch->{'srchtype'} eq 'exact') {
1.167 albertel 8578: if (exists($courseusers->{$srch->{'srchterm'}.':'.$srch->{'srchdomain'}})) {
1.179 raeburn 8579: $currstate = 'modify';
1.162 raeburn 8580: } else {
1.179 raeburn 8581: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8582: &build_search_response($context,$srch,%srch_results);
1.162 raeburn 8583: }
1.160 raeburn 8584: } else {
1.167 albertel 8585: foreach my $user (keys(%$courseusers)) {
1.162 raeburn 8586: my ($cuname,$cudomain) = split(/:/,$user);
8587: if ($cudomain eq $srch->{'srchdomain'}) {
1.177 raeburn 8588: my $matched = 0;
8589: if ($srch->{'srchtype'} eq 'begins') {
8590: if ($cuname =~ /^\Q$srch->{'srchterm'}\E/i) {
8591: $matched = 1;
8592: }
8593: } else {
8594: if ($cuname =~ /\Q$srch->{'srchterm'}\E/i) {
8595: $matched = 1;
8596: }
8597: }
8598: if ($matched) {
1.167 albertel 8599: $srch_results{$user} =
8600: {&Apache::lonnet::get('environment',
8601: ['firstname',
8602: 'lastname',
1.194 albertel 8603: 'permanentemail'],
8604: $cudomain,$cuname)};
1.162 raeburn 8605: }
8606: }
8607: }
1.179 raeburn 8608: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8609: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 8610: }
8611: }
8612: }
8613: } elsif ($srch->{'srchin'} eq 'alc') {
1.179 raeburn 8614: $currstate = 'query';
1.160 raeburn 8615: } elsif ($srch->{'srchin'} eq 'instd') {
1.181 raeburn 8616: ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
8617: if ($dirsrchres eq 'ok') {
8618: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8619: &build_search_response($context,$srch,%srch_results);
1.181 raeburn 8620: } else {
8621: my $showdom = &display_domain_info($srch->{'srchdomain'});
8622: $response = '<span class="LC_warning">'.
8623: &mt('Institutional directory search is not available in domain: [_1]',$showdom).
8624: '</span><br />'.
8625: &mt('You may want to search in the LON-CAPA domain instead of the institutional directory.').
1.406.2.5 raeburn 8626: '<br />';
1.181 raeburn 8627: }
1.160 raeburn 8628: }
8629: } else {
8630: if ($srch->{'srchin'} eq 'dom') {
8631: %srch_results = &Apache::lonnet::usersearch($srch);
1.179 raeburn 8632: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8633: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 8634: } elsif ($srch->{'srchin'} eq 'crs') {
1.167 albertel 8635: my $courseusers = &get_courseusers();
8636: foreach my $user (keys(%$courseusers)) {
1.160 raeburn 8637: my ($uname,$udom) = split(/:/,$user);
8638: my %names = &Apache::loncommon::getnames($uname,$udom);
8639: my %emails = &Apache::loncommon::getemails($uname,$udom);
8640: if ($srch->{'srchby'} eq 'lastname') {
8641: if ((($srch->{'srchtype'} eq 'exact') &&
8642: ($names{'lastname'} eq $srch->{'srchterm'})) ||
1.177 raeburn 8643: (($srch->{'srchtype'} eq 'begins') &&
8644: ($names{'lastname'} =~ /^\Q$srch->{'srchterm'}\E/i)) ||
1.160 raeburn 8645: (($srch->{'srchtype'} eq 'contains') &&
8646: ($names{'lastname'} =~ /\Q$srch->{'srchterm'}\E/i))) {
8647: $srch_results{$user} = {firstname => $names{'firstname'},
8648: lastname => $names{'lastname'},
8649: permanentemail => $emails{'permanentemail'},
8650: };
8651: }
8652: } elsif ($srch->{'srchby'} eq 'lastfirst') {
8653: my ($srchlast,$srchfirst) = split(/,/,$srch->{'srchterm'});
1.177 raeburn 8654: $srchlast =~ s/\s+$//;
8655: $srchfirst =~ s/^\s+//;
1.160 raeburn 8656: if ($srch->{'srchtype'} eq 'exact') {
8657: if (($names{'lastname'} eq $srchlast) &&
8658: ($names{'firstname'} eq $srchfirst)) {
8659: $srch_results{$user} = {firstname => $names{'firstname'},
8660: lastname => $names{'lastname'},
8661: permanentemail => $emails{'permanentemail'},
8662:
8663: };
8664: }
1.177 raeburn 8665: } elsif ($srch->{'srchtype'} eq 'begins') {
8666: if (($names{'lastname'} =~ /^\Q$srchlast\E/i) &&
8667: ($names{'firstname'} =~ /^\Q$srchfirst\E/i)) {
8668: $srch_results{$user} = {firstname => $names{'firstname'},
8669: lastname => $names{'lastname'},
8670: permanentemail => $emails{'permanentemail'},
8671: };
8672: }
8673: } else {
1.160 raeburn 8674: if (($names{'lastname'} =~ /\Q$srchlast\E/i) &&
8675: ($names{'firstname'} =~ /\Q$srchfirst\E/i)) {
8676: $srch_results{$user} = {firstname => $names{'firstname'},
8677: lastname => $names{'lastname'},
8678: permanentemail => $emails{'permanentemail'},
8679: };
8680: }
8681: }
8682: }
8683: }
1.179 raeburn 8684: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8685: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 8686: } elsif ($srch->{'srchin'} eq 'alc') {
1.179 raeburn 8687: $currstate = 'query';
1.160 raeburn 8688: } elsif ($srch->{'srchin'} eq 'instd') {
1.181 raeburn 8689: ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
8690: if ($dirsrchres eq 'ok') {
8691: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8692: &build_search_response($context,$srch,%srch_results);
1.181 raeburn 8693: } else {
1.406.2.5 raeburn 8694: my $showdom = &display_domain_info($srch->{'srchdomain'});
8695: $response = '<span class="LC_warning">'.
1.181 raeburn 8696: &mt('Institutional directory search is not available in domain: [_1]',$showdom).
8697: '</span><br />'.
8698: &mt('You may want to search in the LON-CAPA domain instead of the institutional directory.').
1.406.2.5 raeburn 8699: '<br />';
1.181 raeburn 8700: }
1.160 raeburn 8701: }
8702: }
1.179 raeburn 8703: return ($currstate,$response,$forcenewuser,\%srch_results);
1.160 raeburn 8704: }
8705:
1.406.2.3 raeburn 8706: sub domdirectorysrch_check {
8707: my ($srch) = @_;
8708: my $response;
8709: my %dom_inst_srch = &Apache::lonnet::get_dom('configuration',
8710: ['directorysrch'],$srch->{'srchdomain'});
8711: my $showdom = &display_domain_info($srch->{'srchdomain'});
8712: if (ref($dom_inst_srch{'directorysrch'}) eq 'HASH') {
8713: if ($dom_inst_srch{'directorysrch'}{'lcavailable'} eq '0') {
8714: return &mt('LON-CAPA directory search is not available in domain: [_1]',$showdom);
8715: }
8716: if ($dom_inst_srch{'directorysrch'}{'lclocalonly'}) {
8717: if ($env{'request.role.domain'} ne $srch->{'srchdomain'}) {
8718: return &mt('LON-CAPA directory search in domain: [_1] is only allowed for users with a current role in the domain.',$showdom);
8719: }
8720: }
8721: }
8722: return 'ok';
8723: }
8724:
8725: sub instdirectorysrch_check {
1.160 raeburn 8726: my ($srch) = @_;
8727: my $can_search = 0;
8728: my $response;
8729: my %dom_inst_srch = &Apache::lonnet::get_dom('configuration',
8730: ['directorysrch'],$srch->{'srchdomain'});
1.180 raeburn 8731: my $showdom = &display_domain_info($srch->{'srchdomain'});
1.160 raeburn 8732: if (ref($dom_inst_srch{'directorysrch'}) eq 'HASH') {
8733: if (!$dom_inst_srch{'directorysrch'}{'available'}) {
1.180 raeburn 8734: return &mt('Institutional directory search is not available in domain: [_1]',$showdom);
1.160 raeburn 8735: }
8736: if ($dom_inst_srch{'directorysrch'}{'localonly'}) {
8737: if ($env{'request.role.domain'} ne $srch->{'srchdomain'}) {
1.180 raeburn 8738: return &mt('Institutional directory search in domain: [_1] is only allowed for users with a current role in the domain.',$showdom);
1.160 raeburn 8739: }
8740: my @usertypes = split(/:/,$env{'environment.inststatus'});
8741: if (!@usertypes) {
8742: push(@usertypes,'default');
8743: }
8744: if (ref($dom_inst_srch{'directorysrch'}{'cansearch'}) eq 'ARRAY') {
8745: foreach my $type (@usertypes) {
8746: if (grep(/^\Q$type\E$/,@{$dom_inst_srch{'directorysrch'}{'cansearch'}})) {
8747: $can_search = 1;
8748: last;
8749: }
8750: }
8751: }
8752: if (!$can_search) {
8753: my ($insttypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($srch->{'srchdomain'});
8754: my @longtypes;
8755: foreach my $item (@usertypes) {
1.229 raeburn 8756: if (defined($insttypes->{$item})) {
8757: push (@longtypes,$insttypes->{$item});
8758: } elsif ($item eq 'default') {
8759: push (@longtypes,&mt('other'));
8760: }
1.160 raeburn 8761: }
8762: my $insttype_str = join(', ',@longtypes);
1.180 raeburn 8763: return &mt('Institutional directory search in domain: [_1] is not available to your user type: ',$showdom).$insttype_str;
1.229 raeburn 8764: }
1.160 raeburn 8765: } else {
8766: $can_search = 1;
8767: }
8768: } else {
1.180 raeburn 8769: return &mt('Institutional directory search has not been configured for domain: [_1]',$showdom);
1.160 raeburn 8770: }
8771: my %longtext = &Apache::lonlocal::texthash (
1.167 albertel 8772: uname => 'username',
1.160 raeburn 8773: lastfirst => 'last name, first name',
1.167 albertel 8774: lastname => 'last name',
1.172 raeburn 8775: contains => 'contains',
1.178 raeburn 8776: exact => 'as exact match to',
8777: begins => 'begins with',
1.160 raeburn 8778: );
8779: if ($can_search) {
8780: if (ref($dom_inst_srch{'directorysrch'}{'searchby'}) eq 'ARRAY') {
8781: if (!grep(/^\Q$srch->{'srchby'}\E$/,@{$dom_inst_srch{'directorysrch'}{'searchby'}})) {
1.180 raeburn 8782: return &mt('Institutional directory search in domain: [_1] is not available for searching by "[_2]"',$showdom,$longtext{$srch->{'srchby'}});
1.160 raeburn 8783: }
8784: } else {
1.180 raeburn 8785: return &mt('Institutional directory search in domain: [_1] is not available.', $showdom);
1.160 raeburn 8786: }
8787: }
8788: if ($can_search) {
1.178 raeburn 8789: if (ref($dom_inst_srch{'directorysrch'}{'searchtypes'}) eq 'ARRAY') {
8790: if (grep(/^\Q$srch->{'srchtype'}\E/,@{$dom_inst_srch{'directorysrch'}{'searchtypes'}})) {
8791: return 'ok';
8792: } else {
1.180 raeburn 8793: return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
1.178 raeburn 8794: }
8795: } else {
8796: if ((($dom_inst_srch{'directorysrch'}{'searchtypes'} eq 'specify') &&
8797: ($srch->{'srchtype'} eq 'exact' || $srch->{'srchtype'} eq 'contains')) ||
8798: ($dom_inst_srch{'directorysrch'}{'searchtypes'} eq $srch->{'srchtype'})) {
8799: return 'ok';
8800: } else {
1.180 raeburn 8801: return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
1.178 raeburn 8802: }
1.160 raeburn 8803: }
8804: }
8805: }
8806:
8807: sub get_courseusers {
8808: my %advhash;
1.167 albertel 8809: my $classlist = &Apache::loncoursedata::get_classlist();
1.160 raeburn 8810: my %coursepersonnel=&Apache::lonnet::get_course_adv_roles();
8811: foreach my $role (sort(keys(%coursepersonnel))) {
8812: foreach my $user (split(/\,/,$coursepersonnel{$role})) {
1.167 albertel 8813: if (!exists($classlist->{$user})) {
8814: $classlist->{$user} = [];
8815: }
1.160 raeburn 8816: }
8817: }
1.167 albertel 8818: return $classlist;
1.160 raeburn 8819: }
8820:
8821: sub build_search_response {
1.221 raeburn 8822: my ($context,$srch,%srch_results) = @_;
1.179 raeburn 8823: my ($currstate,$response,$forcenewuser);
1.160 raeburn 8824: my %names = (
1.330 bisitz 8825: 'uname' => 'username',
8826: 'lastname' => 'last name',
1.160 raeburn 8827: 'lastfirst' => 'last name, first name',
1.330 bisitz 8828: 'crs' => 'this course',
8829: 'dom' => 'LON-CAPA domain',
8830: 'instd' => 'the institutional directory for domain',
1.160 raeburn 8831: );
8832:
8833: my %single = (
1.180 raeburn 8834: begins => 'A match',
1.160 raeburn 8835: contains => 'A match',
1.180 raeburn 8836: exact => 'An exact match',
1.160 raeburn 8837: );
8838: my %nomatch = (
1.180 raeburn 8839: begins => 'No match',
1.160 raeburn 8840: contains => 'No match',
1.180 raeburn 8841: exact => 'No exact match',
1.160 raeburn 8842: );
8843: if (keys(%srch_results) > 1) {
1.179 raeburn 8844: $currstate = 'select';
1.160 raeburn 8845: } else {
8846: if (keys(%srch_results) == 1) {
1.406.2.5 raeburn 8847: if ($env{'form.action'} eq 'accesslogs') {
8848: $currstate = 'activity';
8849: } else {
8850: $currstate = 'modify';
8851: }
1.180 raeburn 8852: $response = &mt("$single{$srch->{'srchtype'}} was found for the $names{$srch->{'srchby'}} ([_1]) in $names{$srch->{'srchin'}}.",$srch->{'srchterm'});
8853: if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
1.330 bisitz 8854: $response .= ': '.&display_domain_info($srch->{'srchdomain'});
1.180 raeburn 8855: }
1.330 bisitz 8856: } else { # Search has nothing found. Prepare message to user.
8857: $response = '<span class="LC_warning">';
1.180 raeburn 8858: if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
1.330 bisitz 8859: $response .= &mt("$nomatch{$srch->{'srchtype'}} found for the $names{$srch->{'srchby'}} [_1] in $names{$srch->{'srchin'}}: [_2]",
8860: '<b>'.$srch->{'srchterm'}.'</b>',
8861: &display_domain_info($srch->{'srchdomain'}));
8862: } else {
8863: $response .= &mt("$nomatch{$srch->{'srchtype'}} found for the $names{$srch->{'srchby'}} [_1] in $names{$srch->{'srchin'}}.",
8864: '<b>'.$srch->{'srchterm'}.'</b>');
1.180 raeburn 8865: }
8866: $response .= '</span>';
1.330 bisitz 8867:
1.160 raeburn 8868: if ($srch->{'srchin'} ne 'alc') {
8869: $forcenewuser = 1;
8870: my $cansrchinst = 0;
1.406.2.14 raeburn 8871: if (($srch->{'srchdomain'}) && ($env{'form.action'} ne 'accesslogs')) {
1.160 raeburn 8872: my %domconfig = &Apache::lonnet::get_dom('configuration',['directorysrch'],$srch->{'srchdomain'});
8873: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
8874: if ($domconfig{'directorysrch'}{'available'}) {
8875: $cansrchinst = 1;
8876: }
8877: }
8878: }
1.180 raeburn 8879: if ((($srch->{'srchby'} eq 'lastfirst') ||
8880: ($srch->{'srchby'} eq 'lastname')) &&
8881: ($srch->{'srchin'} eq 'dom')) {
8882: if ($cansrchinst) {
8883: $response .= '<br />'.&mt('You may want to broaden your search to a search of the institutional directory for the domain.');
1.160 raeburn 8884: }
8885: }
1.180 raeburn 8886: if ($srch->{'srchin'} eq 'crs') {
8887: $response .= '<br />'.&mt('You may want to broaden your search to the selected LON-CAPA domain.');
8888: }
8889: }
1.305 raeburn 8890: my $createdom = $env{'request.role.domain'};
8891: if ($context eq 'requestcrs') {
8892: if ($env{'form.coursedom'} ne '') {
8893: $createdom = $env{'form.coursedom'};
8894: }
8895: }
1.406.2.5 raeburn 8896: unless (($env{'form.action'} eq 'accesslogs') || (($srch->{'srchby'} eq 'uname') && ($srch->{'srchin'} eq 'dom') &&
8897: ($srch->{'srchtype'} eq 'exact') && ($srch->{'srchdomain'} eq $createdom))) {
1.221 raeburn 8898: my $cancreate =
1.305 raeburn 8899: &Apache::lonuserutils::can_create_user($createdom,$context);
8900: my $targetdom = '<span class="LC_cusr_emph">'.$createdom.'</span>';
1.221 raeburn 8901: if ($cancreate) {
1.305 raeburn 8902: my $showdom = &display_domain_info($createdom);
1.266 bisitz 8903: $response .= '<br /><br />'
8904: .'<b>'.&mt('To add a new user:').'</b>'
1.305 raeburn 8905: .'<br />';
8906: if ($context eq 'requestcrs') {
8907: $response .= &mt("(You can only define new users in the new course's domain - [_1])",$targetdom);
8908: } else {
8909: $response .= &mt("(You can only create new users in your current role's domain - [_1])",$targetdom);
8910: }
8911: $response .='<ul><li>'
1.266 bisitz 8912: .&mt("Set 'Domain/institution to search' to: [_1]",'<span class="LC_cusr_emph">'.$showdom.'</span>')
8913: .'</li><li>'
8914: .&mt("Set 'Search criteria' to: [_1]username is ..... in selected LON-CAPA domain[_2]",'<span class="LC_cusr_emph">','</span>')
8915: .'</li><li>'
8916: .&mt('Provide the proposed username')
8917: .'</li><li>'
8918: .&mt("Click 'Search'")
8919: .'</li></ul><br />';
1.221 raeburn 8920: } else {
1.406.2.7 raeburn 8921: unless (($context eq 'domain') && ($env{'form.action'} eq 'singleuser')) {
8922: my $helplink = ' href="javascript:helpMenu('."'display'".')"';
8923: $response .= '<br /><br />';
8924: if ($context eq 'requestcrs') {
8925: $response .= &mt("You are not authorized to define new users in the new course's domain - [_1].",$targetdom);
8926: } else {
8927: $response .= &mt("You are not authorized to create new users in your current role's domain - [_1].",$targetdom);
8928: }
8929: $response .= '<br />'
8930: .&mt('Please contact the [_1]helpdesk[_2] if you need to create a new user.'
8931: ,' <a'.$helplink.'>'
8932: ,'</a>')
8933: .'<br />';
1.305 raeburn 8934: }
1.221 raeburn 8935: }
1.160 raeburn 8936: }
8937: }
8938: }
1.179 raeburn 8939: return ($currstate,$response,$forcenewuser);
1.160 raeburn 8940: }
8941:
1.180 raeburn 8942: sub display_domain_info {
8943: my ($dom) = @_;
8944: my $output = $dom;
8945: if ($dom ne '') {
8946: my $domdesc = &Apache::lonnet::domain($dom,'description');
8947: if ($domdesc ne '') {
8948: $output .= ' <span class="LC_cusr_emph">('.$domdesc.')</span>';
8949: }
8950: }
8951: return $output;
8952: }
8953:
1.160 raeburn 8954: sub crumb_utilities {
8955: my %elements = (
8956: crtuser => {
8957: srchterm => 'text',
1.172 raeburn 8958: srchin => 'selectbox',
1.160 raeburn 8959: srchby => 'selectbox',
8960: srchtype => 'selectbox',
8961: srchdomain => 'selectbox',
8962: },
1.207 raeburn 8963: crtusername => {
8964: srchterm => 'text',
8965: srchdomain => 'selectbox',
8966: },
1.160 raeburn 8967: docustom => {
8968: rolename => 'selectbox',
8969: newrolename => 'textbox',
8970: },
1.179 raeburn 8971: studentform => {
8972: srchterm => 'text',
8973: srchin => 'selectbox',
8974: srchby => 'selectbox',
8975: srchtype => 'selectbox',
8976: srchdomain => 'selectbox',
8977: },
1.160 raeburn 8978: );
8979:
8980: my $jsback .= qq|
8981: function backPage(formname,prevphase,prevstate) {
1.211 raeburn 8982: if (typeof prevphase == 'undefined') {
8983: formname.phase.value = '';
8984: }
8985: else {
8986: formname.phase.value = prevphase;
8987: }
8988: if (typeof prevstate == 'undefined') {
8989: formname.currstate.value = '';
8990: }
8991: else {
8992: formname.currstate.value = prevstate;
8993: }
1.160 raeburn 8994: formname.submit();
8995: }
8996: |;
8997: return ($jsback,\%elements);
8998: }
8999:
1.26 matthew 9000: sub course_level_table {
1.375 raeburn 9001: my ($inccourses,$showcredits,$defaultcredits) = @_;
9002: return unless (ref($inccourses) eq 'HASH');
1.26 matthew 9003: my $table = '';
1.62 www 9004: # Custom Roles?
9005:
1.190 raeburn 9006: my %customroles=&Apache::lonuserutils::my_custom_roles();
1.89 raeburn 9007: my %lt=&Apache::lonlocal::texthash(
9008: 'exs' => "Existing sections",
9009: 'new' => "Define new section",
9010: 'ssd' => "Set Start Date",
9011: 'sed' => "Set End Date",
1.131 raeburn 9012: 'crl' => "Course Level",
1.89 raeburn 9013: 'act' => "Activate",
9014: 'rol' => "Role",
9015: 'ext' => "Extent",
1.113 raeburn 9016: 'grs' => "Section",
1.375 raeburn 9017: 'crd' => "Credits",
1.89 raeburn 9018: 'sta' => "Start",
9019: 'end' => "End"
9020: );
1.62 www 9021:
1.375 raeburn 9022: foreach my $protectedcourse (sort(keys(%{$inccourses}))) {
1.135 raeburn 9023: my $thiscourse=$protectedcourse;
1.26 matthew 9024: $thiscourse=~s:_:/:g;
9025: my %coursedata=&Apache::lonnet::coursedescription($thiscourse);
1.365 raeburn 9026: my $isowner = &Apache::lonuserutils::is_courseowner($protectedcourse,$coursedata{'internal.courseowner'});
1.26 matthew 9027: my $area=$coursedata{'description'};
1.321 raeburn 9028: my $crstype=$coursedata{'type'};
1.135 raeburn 9029: if (!defined($area)) { $area=&mt('Unavailable course').': '.$protectedcourse; }
1.89 raeburn 9030: my ($domain,$cnum)=split(/\//,$thiscourse);
1.115 albertel 9031: my %sections_count;
1.101 albertel 9032: if (defined($env{'request.course.id'})) {
9033: if ($env{'request.course.id'} eq $domain.'_'.$cnum) {
1.115 albertel 9034: %sections_count =
9035: &Apache::loncommon::get_sections($domain,$cnum);
1.92 raeburn 9036: }
9037: }
1.321 raeburn 9038: my @roles = &Apache::lonuserutils::roles_by_context('course','',$crstype);
1.213 raeburn 9039: foreach my $role (@roles) {
1.321 raeburn 9040: my $plrole=&Apache::lonnet::plaintext($role,$crstype);
1.329 raeburn 9041: if ((&Apache::lonnet::allowed('c'.$role,$thiscourse)) ||
9042: ((($role eq 'cc') || ($role eq 'co')) && ($isowner))) {
1.221 raeburn 9043: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
1.375 raeburn 9044: $plrole,\%sections_count,\%lt,
1.402 raeburn 9045: $showcredits,$defaultcredits,$crstype);
1.221 raeburn 9046: } elsif ($env{'request.course.sec'} ne '') {
9047: if (&Apache::lonnet::allowed('c'.$role,$thiscourse.'/'.
9048: $env{'request.course.sec'})) {
9049: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
1.375 raeburn 9050: $plrole,\%sections_count,\%lt,
1.402 raeburn 9051: $showcredits,$defaultcredits,$crstype);
1.26 matthew 9052: }
9053: }
9054: }
1.221 raeburn 9055: if (&Apache::lonnet::allowed('ccr',$thiscourse)) {
1.324 raeburn 9056: foreach my $cust (sort(keys(%customroles))) {
9057: next if ($crstype eq 'Community' && $customroles{$cust} =~ /bre\&S/);
1.221 raeburn 9058: my $role = 'cr_cr_'.$env{'user.domain'}.'_'.$env{'user.name'}.'_'.$cust;
9059: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
1.402 raeburn 9060: $cust,\%sections_count,\%lt,
9061: $showcredits,$defaultcredits,$crstype);
1.221 raeburn 9062: }
1.62 www 9063: }
1.26 matthew 9064: }
9065: return '' if ($table eq ''); # return nothing if there is nothing
9066: # in the table
1.188 raeburn 9067: my $result;
9068: if (!$env{'request.course.id'}) {
9069: $result = '<h4>'.$lt{'crl'}.'</h4>'."\n";
9070: }
9071: $result .=
1.136 raeburn 9072: &Apache::loncommon::start_data_table().
9073: &Apache::loncommon::start_data_table_header_row().
1.375 raeburn 9074: '<th>'.$lt{'act'}.'</th><th>'.$lt{'rol'}.'</th>'."\n".
1.402 raeburn 9075: '<th>'.$lt{'ext'}.'</th><th>'."\n";
9076: if ($showcredits) {
9077: $result .= $lt{'crd'}.'</th>';
9078: }
9079: $result .=
1.375 raeburn 9080: '<th>'.$lt{'grs'}.'</th><th>'.$lt{'sta'}.'</th>'."\n".
9081: '<th>'.$lt{'end'}.'</th>'.
1.136 raeburn 9082: &Apache::loncommon::end_data_table_header_row().
9083: $table.
9084: &Apache::loncommon::end_data_table();
1.26 matthew 9085: return $result;
9086: }
1.88 raeburn 9087:
1.221 raeburn 9088: sub course_level_row {
1.375 raeburn 9089: my ($protectedcourse,$role,$area,$domain,$plrole,$sections_count,
1.402 raeburn 9090: $lt,$showcredits,$defaultcredits,$crstype) = @_;
1.375 raeburn 9091: my $creditem;
1.222 raeburn 9092: my $row = &Apache::loncommon::start_data_table_row().
9093: ' <td><input type="checkbox" name="act_'.
9094: $protectedcourse.'_'.$role.'" /></td>'."\n".
9095: ' <td>'.$plrole.'</td>'."\n".
9096: ' <td>'.$area.'<br />Domain: '.$domain.'</td>'."\n";
1.402 raeburn 9097: if (($showcredits) && ($role eq 'st') && ($crstype eq 'Course')) {
1.375 raeburn 9098: $row .=
9099: '<td><input type="text" name="credits_'.$protectedcourse.'_'.
9100: $role.'" size="3" value="'.$defaultcredits.'" /></td>';
9101: } else {
9102: $row .= '<td> </td>';
9103: }
1.322 raeburn 9104: if (($role eq 'cc') || ($role eq 'co')) {
1.222 raeburn 9105: $row .= '<td> </td>';
1.221 raeburn 9106: } elsif ($env{'request.course.sec'} ne '') {
1.222 raeburn 9107: $row .= ' <td><input type="hidden" value="'.
9108: $env{'request.course.sec'}.'" '.
9109: 'name="sec_'.$protectedcourse.'_'.$role.'" />'.
9110: $env{'request.course.sec'}.'</td>';
1.221 raeburn 9111: } else {
9112: if (ref($sections_count) eq 'HASH') {
9113: my $currsec =
9114: &Apache::lonuserutils::course_sections($sections_count,
9115: $protectedcourse.'_'.$role);
1.222 raeburn 9116: $row .= '<td><table class="LC_createuser">'."\n".
9117: '<tr class="LC_section_row">'."\n".
9118: ' <td valign="top">'.$lt->{'exs'}.'<br />'.
9119: $currsec.'</td>'."\n".
9120: ' <td> </td>'."\n".
9121: ' <td valign="top"> '.$lt->{'new'}.'<br />'.
1.221 raeburn 9122: '<input type="text" name="newsec_'.$protectedcourse.'_'.$role.
9123: '" value="" />'.
9124: '<input type="hidden" '.
9125: 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'."\n".
1.222 raeburn 9126: '</tr></table></td>'."\n";
1.221 raeburn 9127: } else {
1.222 raeburn 9128: $row .= '<td><input type="text" size="10" '.
1.375 raeburn 9129: 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'."\n";
1.221 raeburn 9130: }
9131: }
1.222 raeburn 9132: $row .= <<ENDTIMEENTRY;
9133: <td><input type="hidden" name="start_$protectedcourse\_$role" value="" />
1.221 raeburn 9134: <a href=
9135: "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 9136: <td><input type="hidden" name="end_$protectedcourse\_$role" value="" />
1.221 raeburn 9137: <a href=
9138: "javascript:pjump('date_end','End Date $plrole',document.cu.end_$protectedcourse\_$role.value,'end_$protectedcourse\_$role','cu.pres','dateset')">$lt->{'sed'}</a></td>
9139: ENDTIMEENTRY
1.222 raeburn 9140: $row .= &Apache::loncommon::end_data_table_row();
9141: return $row;
1.221 raeburn 9142: }
9143:
1.88 raeburn 9144: sub course_level_dc {
1.375 raeburn 9145: my ($dcdom,$showcredits) = @_;
1.190 raeburn 9146: my %customroles=&Apache::lonuserutils::my_custom_roles();
1.213 raeburn 9147: my @roles = &Apache::lonuserutils::roles_by_context('course');
1.88 raeburn 9148: my $hiddenitems = '<input type="hidden" name="dcdomain" value="'.$dcdom.'" />'.
9149: '<input type="hidden" name="origdom" value="'.$dcdom.'" />'.
1.133 raeburn 9150: '<input type="hidden" name="dccourse" value="" />';
1.355 www 9151: my $courseform=&Apache::loncommon::selectcourse_link
1.356 raeburn 9152: ('cu','dccourse','dcdomain','coursedesc',undef,undef,'Select','crstype');
1.375 raeburn 9153: my $credit_elem;
9154: if ($showcredits) {
9155: $credit_elem = 'credits';
9156: }
9157: my $cb_jscript = &Apache::loncommon::coursebrowser_javascript($dcdom,'currsec','cu','role','Course/Community Browser',$credit_elem);
1.88 raeburn 9158: my %lt=&Apache::lonlocal::texthash(
9159: 'rol' => "Role",
1.113 raeburn 9160: 'grs' => "Section",
1.88 raeburn 9161: 'exs' => "Existing sections",
9162: 'new' => "Define new section",
9163: 'sta' => "Start",
9164: 'end' => "End",
9165: 'ssd' => "Set Start Date",
1.355 www 9166: 'sed' => "Set End Date",
1.375 raeburn 9167: 'scc' => "Course/Community",
9168: 'crd' => "Credits",
1.88 raeburn 9169: );
1.323 raeburn 9170: my $header = '<h4>'.&mt('Course/Community Level').'</h4>'.
1.136 raeburn 9171: &Apache::loncommon::start_data_table().
9172: &Apache::loncommon::start_data_table_header_row().
1.375 raeburn 9173: '<th>'.$lt{'scc'}.'</th><th>'.$lt{'rol'}.'</th>'."\n".
1.397 bisitz 9174: '<th>'.$lt{'grs'}.'</th>'."\n";
9175: $header .= '<th>'.$lt{'crd'}.'</th>'."\n" if ($showcredits);
9176: $header .= '<th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'."\n".
1.136 raeburn 9177: &Apache::loncommon::end_data_table_header_row();
1.143 raeburn 9178: my $otheritems = &Apache::loncommon::start_data_table_row()."\n".
1.356 raeburn 9179: '<td><br /><span class="LC_nobreak"><input type="text" name="coursedesc" value="" onfocus="this.blur();opencrsbrowser('."'cu','dccourse','dcdomain','coursedesc','','','','crstype'".')" />'.
9180: $courseform.(' ' x4).'</span></td>'."\n".
1.389 bisitz 9181: '<td valign="top"><br /><select name="role">'."\n";
1.213 raeburn 9182: foreach my $role (@roles) {
1.135 raeburn 9183: my $plrole=&Apache::lonnet::plaintext($role);
1.389 bisitz 9184: $otheritems .= ' <option value="'.$role.'">'.$plrole.'</option>';
1.88 raeburn 9185: }
1.404 raeburn 9186: if ( keys(%customroles) > 0) {
9187: foreach my $cust (sort(keys(%customroles))) {
1.101 albertel 9188: my $custrole='cr_cr_'.$env{'user.domain'}.
1.135 raeburn 9189: '_'.$env{'user.name'}.'_'.$cust;
1.389 bisitz 9190: $otheritems .= ' <option value="'.$custrole.'">'.$cust.'</option>';
1.88 raeburn 9191: }
9192: }
9193: $otheritems .= '</select></td><td>'.
9194: '<table border="0" cellspacing="0" cellpadding="0">'.
9195: '<tr><td valign="top"><b>'.$lt{'exs'}.'</b><br /><select name="currsec">'.
1.389 bisitz 9196: ' <option value=""><--'.&mt('Pick course first').'</option></select></td>'.
1.88 raeburn 9197: '<td> </td>'.
9198: '<td valign="top"> <b>'.$lt{'new'}.'</b><br />'.
1.113 raeburn 9199: '<input type="text" name="newsec" value="" />'.
1.237 raeburn 9200: '<input type="hidden" name="section" value="" />'.
1.323 raeburn 9201: '<input type="hidden" name="groups" value="" />'.
9202: '<input type="hidden" name="crstype" value="" /></td>'.
1.375 raeburn 9203: '</tr></table></td>'."\n";
9204: if ($showcredits) {
9205: $otheritems .= '<td><br />'."\n".
1.397 bisitz 9206: '<input type="text" size="3" name="credits" value="" /></td>'."\n";
1.375 raeburn 9207: }
1.88 raeburn 9208: $otheritems .= <<ENDTIMEENTRY;
1.323 raeburn 9209: <td><br /><input type="hidden" name="start" value='' />
1.88 raeburn 9210: <a href=
9211: "javascript:pjump('date_start','Start Date',document.cu.start.value,'start','cu.pres','dateset')">$lt{'ssd'}</a></td>
1.323 raeburn 9212: <td><br /><input type="hidden" name="end" value='' />
1.88 raeburn 9213: <a href=
9214: "javascript:pjump('date_end','End Date',document.cu.end.value,'end','cu.pres','dateset')">$lt{'sed'}</a></td>
9215: ENDTIMEENTRY
1.136 raeburn 9216: $otheritems .= &Apache::loncommon::end_data_table_row().
9217: &Apache::loncommon::end_data_table()."\n";
1.88 raeburn 9218: return $cb_jscript.$header.$hiddenitems.$otheritems;
9219: }
9220:
1.237 raeburn 9221: sub update_selfenroll_config {
1.400 raeburn 9222: my ($r,$cid,$cdom,$cnum,$context,$crstype,$currsettings) = @_;
1.398 raeburn 9223: return unless (ref($currsettings) eq 'HASH');
9224: my ($row,$lt) = &Apache::lonuserutils::get_selfenroll_titles();
9225: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
1.237 raeburn 9226: my (%changes,%warning);
1.241 raeburn 9227: my $curr_types;
1.400 raeburn 9228: my %noedit;
9229: unless ($context eq 'domain') {
9230: %noedit = &get_noedit_fields($cdom,$cnum,$crstype,$row);
9231: }
1.237 raeburn 9232: if (ref($row) eq 'ARRAY') {
9233: foreach my $item (@{$row}) {
1.400 raeburn 9234: next if ($noedit{$item});
1.237 raeburn 9235: if ($item eq 'enroll_dates') {
9236: my (%currenrolldate,%newenrolldate);
9237: foreach my $type ('start','end') {
1.398 raeburn 9238: $currenrolldate{$type} = $currsettings->{'selfenroll_'.$type.'_date'};
1.237 raeburn 9239: $newenrolldate{$type} = &Apache::lonhtmlcommon::get_date_from_form('selfenroll_'.$type.'_date');
9240: if ($newenrolldate{$type} ne $currenrolldate{$type}) {
9241: $changes{'internal.selfenroll_'.$type.'_date'} = $newenrolldate{$type};
9242: }
9243: }
9244: } elsif ($item eq 'access_dates') {
9245: my (%currdate,%newdate);
9246: foreach my $type ('start','end') {
1.398 raeburn 9247: $currdate{$type} = $currsettings->{'selfenroll_'.$type.'_access'};
1.237 raeburn 9248: $newdate{$type} = &Apache::lonhtmlcommon::get_date_from_form('selfenroll_'.$type.'_access');
9249: if ($newdate{$type} ne $currdate{$type}) {
9250: $changes{'internal.selfenroll_'.$type.'_access'} = $newdate{$type};
9251: }
9252: }
1.241 raeburn 9253: } elsif ($item eq 'types') {
1.398 raeburn 9254: $curr_types = $currsettings->{'selfenroll_'.$item};
1.241 raeburn 9255: if ($env{'form.selfenroll_all'}) {
9256: if ($curr_types ne '*') {
9257: $changes{'internal.selfenroll_types'} = '*';
9258: } else {
9259: next;
9260: }
9261: } else {
1.249 raeburn 9262: my %currdoms;
1.241 raeburn 9263: my @entries = split(/;/,$curr_types);
9264: my @deletedoms = &Apache::loncommon::get_env_multiple('form.selfenroll_delete');
1.249 raeburn 9265: my @activations = &Apache::loncommon::get_env_multiple('form.selfenroll_activate');
1.241 raeburn 9266: my $newnum = 0;
1.249 raeburn 9267: my @latesttypes;
9268: foreach my $num (@activations) {
9269: my @types = &Apache::loncommon::get_env_multiple('form.selfenroll_types_'.$num);
9270: if (@types > 0) {
1.241 raeburn 9271: @types = sort(@types);
9272: my $typestr = join(',',@types);
1.249 raeburn 9273: my $typedom = $env{'form.selfenroll_dom_'.$num};
9274: $latesttypes[$newnum] = $typedom.':'.$typestr;
9275: $currdoms{$typedom} = 1;
1.241 raeburn 9276: $newnum ++;
9277: }
9278: }
1.338 raeburn 9279: for (my $j=0; $j<$env{'form.selfenroll_types_total'}; $j++) {
9280: if ((!grep(/^$j$/,@deletedoms)) && (!grep(/^$j$/,@activations))) {
1.249 raeburn 9281: my @types = &Apache::loncommon::get_env_multiple('form.selfenroll_types_'.$j);
9282: if (@types > 0) {
9283: @types = sort(@types);
9284: my $typestr = join(',',@types);
9285: my $typedom = $env{'form.selfenroll_dom_'.$j};
9286: $latesttypes[$newnum] = $typedom.':'.$typestr;
9287: $currdoms{$typedom} = 1;
9288: $newnum ++;
9289: }
9290: }
9291: }
9292: if ($env{'form.selfenroll_newdom'} ne '') {
9293: my $typedom = $env{'form.selfenroll_newdom'};
9294: if ((!defined($currdoms{$typedom})) &&
9295: (&Apache::lonnet::domain($typedom) ne '')) {
9296: my $typestr;
9297: my ($othertitle,$usertypes,$types) =
9298: &Apache::loncommon::sorted_inst_types($typedom);
9299: my $othervalue = 'any';
9300: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
9301: if (@{$types} > 0) {
1.257 raeburn 9302: my @esc_types = map { &escape($_); } @{$types};
1.249 raeburn 9303: $othervalue = 'other';
1.258 raeburn 9304: $typestr = join(',',(@esc_types,$othervalue));
1.249 raeburn 9305: }
9306: $typestr = $othervalue;
9307: } else {
9308: $typestr = $othervalue;
9309: }
9310: $latesttypes[$newnum] = $typedom.':'.$typestr;
9311: $newnum ++ ;
9312: }
9313: }
1.241 raeburn 9314: my $selfenroll_types = join(';',@latesttypes);
9315: if ($selfenroll_types ne $curr_types) {
9316: $changes{'internal.selfenroll_types'} = $selfenroll_types;
9317: }
9318: }
1.276 raeburn 9319: } elsif ($item eq 'limit') {
9320: my $newlimit = $env{'form.selfenroll_limit'};
9321: my $newcap = $env{'form.selfenroll_cap'};
9322: $newcap =~s/\s+//g;
1.398 raeburn 9323: my $currlimit = $currsettings->{'selfenroll_limit'};
1.276 raeburn 9324: $currlimit = 'none' if ($currlimit eq '');
1.398 raeburn 9325: my $currcap = $currsettings->{'selfenroll_cap'};
1.276 raeburn 9326: if ($newlimit ne $currlimit) {
9327: if ($newlimit ne 'none') {
9328: if ($newcap =~ /^\d+$/) {
9329: if ($newcap ne $currcap) {
9330: $changes{'internal.selfenroll_cap'} = $newcap;
9331: }
9332: $changes{'internal.selfenroll_limit'} = $newlimit;
9333: } else {
1.398 raeburn 9334: $warning{$item} = &mt('Maximum enrollment setting unchanged.').'<br />'.
9335: &mt('The value provided was invalid - it must be a positive integer if enrollment is being limited.');
1.276 raeburn 9336: }
9337: } elsif ($currcap ne '') {
9338: $changes{'internal.selfenroll_cap'} = '';
9339: $changes{'internal.selfenroll_limit'} = $newlimit;
9340: }
9341: } elsif ($currlimit ne 'none') {
9342: if ($newcap =~ /^\d+$/) {
9343: if ($newcap ne $currcap) {
9344: $changes{'internal.selfenroll_cap'} = $newcap;
9345: }
9346: } else {
1.398 raeburn 9347: $warning{$item} = &mt('Maximum enrollment setting unchanged.').'<br />'.
9348: &mt('The value provided was invalid - it must be a positive integer if enrollment is being limited.');
1.276 raeburn 9349: }
9350: }
9351: } elsif ($item eq 'approval') {
9352: my (@currnotified,@newnotified);
1.398 raeburn 9353: my $currapproval = $currsettings->{'selfenroll_approval'};
9354: my $currnotifylist = $currsettings->{'selfenroll_notifylist'};
1.276 raeburn 9355: if ($currnotifylist ne '') {
9356: @currnotified = split(/,/,$currnotifylist);
9357: @currnotified = sort(@currnotified);
9358: }
9359: my $newapproval = $env{'form.selfenroll_approval'};
9360: @newnotified = &Apache::loncommon::get_env_multiple('form.selfenroll_notify');
9361: @newnotified = sort(@newnotified);
9362: if ($newapproval ne $currapproval) {
9363: $changes{'internal.selfenroll_approval'} = $newapproval;
9364: if (!$newapproval) {
9365: if ($currnotifylist ne '') {
9366: $changes{'internal.selfenroll_notifylist'} = '';
9367: }
9368: } else {
9369: my @differences =
1.295 raeburn 9370: &Apache::loncommon::compare_arrays(\@currnotified,\@newnotified);
1.276 raeburn 9371: if (@differences > 0) {
9372: if (@newnotified > 0) {
9373: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
9374: } else {
9375: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
9376: }
9377: }
9378: }
9379: } else {
1.295 raeburn 9380: my @differences = &Apache::loncommon::compare_arrays(\@currnotified,\@newnotified);
1.276 raeburn 9381: if (@differences > 0) {
9382: if (@newnotified > 0) {
9383: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
9384: } else {
9385: $changes{'internal.selfenroll_notifylist'} = '';
9386: }
9387: }
9388: }
1.237 raeburn 9389: } else {
1.398 raeburn 9390: my $curr_val = $currsettings->{'selfenroll_'.$item};
1.237 raeburn 9391: my $newval = $env{'form.selfenroll_'.$item};
9392: if ($item eq 'section') {
9393: $newval = $env{'form.sections'};
1.241 raeburn 9394: if (defined($curr_groups{$newval})) {
1.237 raeburn 9395: $newval = $curr_val;
1.398 raeburn 9396: $warning{$item} = &mt('Section for self-enrolled users unchanged as the proposed section is a group').'<br />'.
9397: &mt('Group names and section names must be distinct');
1.237 raeburn 9398: } elsif ($newval eq 'all') {
9399: $newval = $curr_val;
1.274 bisitz 9400: $warning{$item} = &mt('Section for self-enrolled users unchanged, as "all" is a reserved section name.');
1.237 raeburn 9401: }
9402: if ($newval eq '') {
9403: $newval = 'none';
9404: }
9405: }
9406: if ($newval ne $curr_val) {
9407: $changes{'internal.selfenroll_'.$item} = $newval;
9408: }
1.241 raeburn 9409: }
1.237 raeburn 9410: }
9411: if (keys(%warning) > 0) {
9412: foreach my $item (@{$row}) {
9413: if (exists($warning{$item})) {
9414: $r->print($warning{$item}.'<br />');
9415: }
9416: }
9417: }
9418: if (keys(%changes) > 0) {
9419: my $putresult = &Apache::lonnet::put('environment',\%changes,$cdom,$cnum);
9420: if ($putresult eq 'ok') {
9421: if ((exists($changes{'internal.selfenroll_types'})) ||
9422: (exists($changes{'internal.selfenroll_start_date'})) ||
9423: (exists($changes{'internal.selfenroll_end_date'}))) {
9424: my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',
9425: $cnum,undef,undef,'Course');
9426: my $chome = &Apache::lonnet::homeserver($cnum,$cdom);
1.398 raeburn 9427: if (ref($crsinfo{$cid}) eq 'HASH') {
1.237 raeburn 9428: foreach my $item ('selfenroll_types','selfenroll_start_date','selfenroll_end_date') {
9429: if (exists($changes{'internal.'.$item})) {
1.398 raeburn 9430: $crsinfo{$cid}{$item} = $changes{'internal.'.$item};
1.237 raeburn 9431: }
9432: }
9433: my $crsputresult =
9434: &Apache::lonnet::courseidput($cdom,\%crsinfo,
9435: $chome,'notime');
9436: }
9437: }
9438: $r->print(&mt('The following changes were made to self-enrollment settings:').'<ul>');
9439: foreach my $item (@{$row}) {
9440: my $title = $item;
9441: if (ref($lt) eq 'HASH') {
9442: $title = $lt->{$item};
9443: }
9444: if ($item eq 'enroll_dates') {
9445: foreach my $type ('start','end') {
9446: if (exists($changes{'internal.selfenroll_'.$type.'_date'})) {
9447: my $newdate = &Apache::lonlocal::locallocaltime($changes{'internal.selfenroll_'.$type.'_date'});
1.244 bisitz 9448: $r->print('<li>'.&mt('[_1]: "[_2]" set to "[_3]".',
1.237 raeburn 9449: $title,$type,$newdate).'</li>');
9450: }
9451: }
9452: } elsif ($item eq 'access_dates') {
9453: foreach my $type ('start','end') {
9454: if (exists($changes{'internal.selfenroll_'.$type.'_access'})) {
9455: my $newdate = &Apache::lonlocal::locallocaltime($changes{'internal.selfenroll_'.$type.'_access'});
1.244 bisitz 9456: $r->print('<li>'.&mt('[_1]: "[_2]" set to "[_3]".',
1.237 raeburn 9457: $title,$type,$newdate).'</li>');
9458: }
9459: }
1.276 raeburn 9460: } elsif ($item eq 'limit') {
9461: if ((exists($changes{'internal.selfenroll_limit'})) ||
9462: (exists($changes{'internal.selfenroll_cap'}))) {
9463: my ($newval,$newcap);
9464: if ($changes{'internal.selfenroll_cap'} ne '') {
9465: $newcap = $changes{'internal.selfenroll_cap'}
9466: } else {
1.398 raeburn 9467: $newcap = $currsettings->{'selfenroll_cap'};
1.276 raeburn 9468: }
9469: if ($changes{'internal.selfenroll_limit'} eq 'none') {
9470: $newval = &mt('No limit');
9471: } elsif ($changes{'internal.selfenroll_limit'} eq
9472: 'allstudents') {
9473: $newval = &mt('New self-enrollment no longer allowed when total (all students) reaches [_1].',$newcap);
9474: } elsif ($changes{'internal.selfenroll_limit'} eq 'selfenrolled') {
9475: $newval = &mt('New self-enrollment no longer allowed when total number of self-enrolled students reaches [_1].',$newcap);
9476: } else {
1.398 raeburn 9477: my $currlimit = $currsettings->{'selfenroll_limit'};
1.276 raeburn 9478: if ($currlimit eq 'allstudents') {
9479: $newval = &mt('New self-enrollment no longer allowed when total (all students) reaches [_1].',$newcap);
9480: } elsif ($changes{'internal.selfenroll_limit'} eq 'selfenrolled') {
1.308 raeburn 9481: $newval = &mt('New self-enrollment no longer allowed when total number of self-enrolled students reaches [_1].',$newcap);
1.276 raeburn 9482: }
9483: }
9484: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval).'</li>'."\n");
9485: }
9486: } elsif ($item eq 'approval') {
9487: if ((exists($changes{'internal.selfenroll_approval'})) ||
9488: (exists($changes{'internal.selfenroll_notifylist'}))) {
1.398 raeburn 9489: my %selfdescs = &Apache::lonuserutils::selfenroll_default_descs();
1.276 raeburn 9490: my ($newval,$newnotify);
9491: if (exists($changes{'internal.selfenroll_notifylist'})) {
9492: $newnotify = $changes{'internal.selfenroll_notifylist'};
9493: } else {
1.398 raeburn 9494: $newnotify = $currsettings->{'selfenroll_notifylist'};
1.276 raeburn 9495: }
1.398 raeburn 9496: if (exists($changes{'internal.selfenroll_approval'})) {
9497: if ($changes{'internal.selfenroll_approval'} !~ /^[012]$/) {
9498: $changes{'internal.selfenroll_approval'} = '0';
9499: }
9500: $newval = $selfdescs{'approval'}{$changes{'internal.selfenroll_approval'}};
1.276 raeburn 9501: } else {
1.398 raeburn 9502: my $currapproval = $currsettings->{'selfenroll_approval'};
9503: if ($currapproval !~ /^[012]$/) {
9504: $currapproval = 0;
1.276 raeburn 9505: }
1.398 raeburn 9506: $newval = $selfdescs{'approval'}{$currapproval};
1.276 raeburn 9507: }
9508: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval));
9509: if ($newnotify) {
1.277 raeburn 9510: $r->print('<br />'.&mt('The following will be notified when an enrollment request needs approval, or has been approved: [_1].',$newnotify));
1.276 raeburn 9511: } else {
1.277 raeburn 9512: $r->print('<br />'.&mt('No notifications sent when an enrollment request needs approval, or has been approved.'));
1.276 raeburn 9513: }
9514: $r->print('</li>'."\n");
9515: }
1.237 raeburn 9516: } else {
9517: if (exists($changes{'internal.selfenroll_'.$item})) {
1.241 raeburn 9518: my $newval = $changes{'internal.selfenroll_'.$item};
9519: if ($item eq 'types') {
9520: if ($newval eq '') {
9521: $newval = &mt('None');
9522: } elsif ($newval eq '*') {
9523: $newval = &mt('Any user in any domain');
9524: }
1.245 raeburn 9525: } elsif ($item eq 'registered') {
9526: if ($newval eq '1') {
9527: $newval = &mt('Yes');
9528: } elsif ($newval eq '0') {
9529: $newval = &mt('No');
9530: }
1.241 raeburn 9531: }
1.244 bisitz 9532: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval).'</li>'."\n");
1.237 raeburn 9533: }
9534: }
9535: }
9536: $r->print('</ul>');
1.398 raeburn 9537: if ($env{'course.'.$cid.'.description'} ne '') {
9538: my %newenvhash;
9539: foreach my $key (keys(%changes)) {
9540: $newenvhash{'course.'.$cid.'.'.$key} = $changes{$key};
9541: }
9542: &Apache::lonnet::appenv(\%newenvhash);
1.237 raeburn 9543: }
9544: } else {
1.398 raeburn 9545: $r->print(&mt('An error occurred when saving changes to self-enrollment settings in this course.').'<br />'.
9546: &mt('The error was: [_1].',$putresult));
1.237 raeburn 9547: }
9548: } else {
1.249 raeburn 9549: $r->print(&mt('No changes were made to the existing self-enrollment settings in this course.'));
1.237 raeburn 9550: }
9551: } else {
1.249 raeburn 9552: $r->print(&mt('No changes were made to the existing self-enrollment settings in this course.'));
1.241 raeburn 9553: }
1.400 raeburn 9554: my $visactions = &cat_visibility();
9555: my ($cathash,%cattype);
9556: my %domconfig = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom);
9557: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
9558: $cathash = $domconfig{'coursecategories'}{'cats'};
9559: $cattype{'auth'} = $domconfig{'coursecategories'}{'auth'};
9560: $cattype{'unauth'} = $domconfig{'coursecategories'}{'unauth'};
9561: } else {
9562: $cathash = {};
9563: $cattype{'auth'} = 'std';
9564: $cattype{'unauth'} = 'std';
9565: }
9566: if (($cattype{'auth'} eq 'none') && ($cattype{'unauth'} eq 'none')) {
9567: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
9568: '<br />'.
9569: '<br />'.$visactions->{'take'}.'<ul>'.
9570: '<li>'.$visactions->{'dc_chgconf'}.'</li>'.
9571: '</ul>');
9572: } elsif (($cattype{'auth'} !~ /^(std|domonly)$/) && ($cattype{'unauth'} !~ /^(std|domonly)$/)) {
9573: if ($currsettings->{'uniquecode'}) {
9574: $r->print('<span class="LC_info">'.$visactions->{'vis'}.'</span>');
9575: } else {
1.366 bisitz 9576: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
1.400 raeburn 9577: '<br />'.
9578: '<br />'.$visactions->{'take'}.'<ul>'.
9579: '<li>'.$visactions->{'dc_setcode'}.'</li>'.
9580: '</ul><br />');
9581: }
9582: } else {
9583: my ($visible,$cansetvis,$vismsgs) = &visible_in_stdcat($cdom,$cnum,\%domconfig);
9584: if (ref($visactions) eq 'HASH') {
9585: if (!$visible) {
9586: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
9587: '<br />');
9588: if (ref($vismsgs) eq 'ARRAY') {
9589: $r->print('<br />'.$visactions->{'take'}.'<ul>');
9590: foreach my $item (@{$vismsgs}) {
9591: $r->print('<li>'.$visactions->{$item}.'</li>');
9592: }
9593: $r->print('</ul>');
1.256 raeburn 9594: }
1.400 raeburn 9595: $r->print($cansetvis);
1.256 raeburn 9596: }
9597: }
9598: }
1.237 raeburn 9599: return;
9600: }
9601:
1.27 matthew 9602: #---------------------------------------------- end functions for &phase_two
1.29 matthew 9603:
9604: #--------------------------------- functions for &phase_two and &phase_three
9605:
9606: #--------------------------end of functions for &phase_two and &phase_three
1.372 raeburn 9607:
1.1 www 9608: 1;
9609: __END__
1.2 www 9610:
9611:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>