Annotation of loncom/interface/loncreateuser.pm, revision 1.406.2.14.2.1
1.20 harris41 1: # The LearningOnline Network with CAPA
1.1 www 2: # Create a user
3: #
1.406.2.14.2. (raeburn 4:): # $Id: loncreateuser.pm,v 1.406.2.14 2017/04/02 12:40:18 raeburn Exp $
1.22 albertel 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
1.20 harris41 28: ###
29:
1.1 www 30: package Apache::loncreateuser;
1.66 bowersj2 31:
32: =pod
33:
34: =head1 NAME
35:
1.263 jms 36: Apache::loncreateuser.pm
1.66 bowersj2 37:
38: =head1 SYNOPSIS
39:
1.263 jms 40: Handler to create users and custom roles
41:
42: Provides an Apache handler for creating users,
1.66 bowersj2 43: editing their login parameters, roles, and removing roles, and
44: also creating and assigning custom roles.
45:
46: =head1 OVERVIEW
47:
48: =head2 Custom Roles
49:
50: In LON-CAPA, roles are actually collections of privileges. "Teaching
51: Assistant", "Course Coordinator", and other such roles are really just
52: collection of privileges that are useful in many circumstances.
53:
1.324 raeburn 54: Custom roles can be defined by a Domain Coordinator, Course Coordinator
55: or Community Coordinator via the Manage User functionality.
56: The custom role editor screen will show all privileges which can be
57: assigned to users. For a complete list of privileges, please see
58: C</home/httpd/lonTabs/rolesplain.tab>.
1.66 bowersj2 59:
1.324 raeburn 60: Custom role definitions are stored in the C<roles.db> file of the creator
61: of the role.
1.66 bowersj2 62:
63: =cut
1.1 www 64:
65: use strict;
66: use Apache::Constants qw(:common :http);
67: use Apache::lonnet;
1.54 bowersj2 68: use Apache::loncommon;
1.68 www 69: use Apache::lonlocal;
1.117 raeburn 70: use Apache::longroup;
1.190 raeburn 71: use Apache::lonuserutils;
1.307 raeburn 72: use Apache::loncoursequeueadmin;
1.139 albertel 73: use LONCAPA qw(:DEFAULT :match);
1.1 www 74:
1.20 harris41 75: my $loginscript; # piece of javascript used in two separate instances
76: my $authformnop;
77: my $authformkrb;
78: my $authformint;
79: my $authformfsys;
80: my $authformloc;
81:
1.94 matthew 82: sub initialize_authen_forms {
1.227 raeburn 83: my ($dom,$formname,$curr_authtype,$mode) = @_;
84: my ($krbdef,$krbdefdom) = &Apache::loncommon::get_kerberos_defaults($dom);
85: my %param = ( formname => $formname,
1.187 raeburn 86: kerb_def_dom => $krbdefdom,
1.227 raeburn 87: kerb_def_auth => $krbdef,
1.187 raeburn 88: domain => $dom,
89: );
1.188 raeburn 90: my %abv_auth = &auth_abbrev();
1.227 raeburn 91: if ($curr_authtype =~ /^(krb4|krb5|internal|localauth|unix):(.*)$/) {
1.188 raeburn 92: my $long_auth = $1;
1.227 raeburn 93: my $curr_autharg = $2;
1.188 raeburn 94: my %abv_auth = &auth_abbrev();
95: $param{'curr_authtype'} = $abv_auth{$long_auth};
96: if ($long_auth =~ /^krb(4|5)$/) {
97: $param{'curr_kerb_ver'} = $1;
1.227 raeburn 98: $param{'curr_autharg'} = $curr_autharg;
1.188 raeburn 99: }
1.205 raeburn 100: if ($mode eq 'modifyuser') {
101: $param{'mode'} = $mode;
102: }
1.187 raeburn 103: }
1.227 raeburn 104: $loginscript = &Apache::loncommon::authform_header(%param);
105: $authformkrb = &Apache::loncommon::authform_kerberos(%param);
1.31 matthew 106: $authformnop = &Apache::loncommon::authform_nochange(%param);
107: $authformint = &Apache::loncommon::authform_internal(%param);
108: $authformfsys = &Apache::loncommon::authform_filesystem(%param);
109: $authformloc = &Apache::loncommon::authform_local(%param);
1.20 harris41 110: }
111:
1.188 raeburn 112: sub auth_abbrev {
113: my %abv_auth = (
1.368 raeburn 114: krb5 => 'krb',
115: krb4 => 'krb',
116: internal => 'int',
117: localauth => 'loc',
118: unix => 'fsys',
1.188 raeburn 119: );
120: return %abv_auth;
121: }
1.43 www 122:
1.134 raeburn 123: # ====================================================
124:
1.378 raeburn 125: sub user_quotas {
1.134 raeburn 126: my ($ccuname,$ccdomain) = @_;
127: my %lt = &Apache::lonlocal::texthash(
1.267 raeburn 128: 'usrt' => "User Tools",
129: 'cust' => "Custom quota",
130: 'chqu' => "Change quota",
1.134 raeburn 131: );
1.378 raeburn 132:
1.149 raeburn 133: my $quota_javascript = <<"END_SCRIPT";
134: <script type="text/javascript">
1.301 bisitz 135: // <![CDATA[
1.378 raeburn 136: function quota_changes(caller,context) {
137: var customoff = document.getElementById('custom_'+context+'quota_off');
138: var customon = document.getElementById('custom_'+context+'quota_on');
139: var number = document.getElementById(context+'quota');
1.149 raeburn 140: if (caller == "custom") {
1.378 raeburn 141: if (customoff) {
142: if (customoff.checked) {
143: number.value = "";
144: }
1.149 raeburn 145: }
146: }
147: if (caller == "quota") {
1.378 raeburn 148: if (customon) {
149: customon.checked = true;
150: }
1.149 raeburn 151: }
1.378 raeburn 152: return;
1.149 raeburn 153: }
1.301 bisitz 154: // ]]>
1.149 raeburn 155: </script>
156: END_SCRIPT
1.378 raeburn 157: my $longinsttype;
158: my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($ccdomain);
1.267 raeburn 159: my $output = $quota_javascript."\n".
160: '<h3>'.$lt{'usrt'}.'</h3>'."\n".
161: &Apache::loncommon::start_data_table();
162:
1.406.2.6 raeburn 163: if ((&Apache::lonnet::allowed('mut',$ccdomain)) ||
164: (&Apache::lonnet::allowed('udp',$ccdomain))) {
1.275 raeburn 165: $output .= &build_tools_display($ccuname,$ccdomain,'tools');
1.267 raeburn 166: }
1.378 raeburn 167:
168: my %titles = &Apache::lonlocal::texthash (
169: portfolio => "Disk space allocated to user's portfolio files",
1.385 bisitz 170: author => "Disk space allocated to user's Authoring Space (if role assigned)",
1.378 raeburn 171: );
172: foreach my $name ('portfolio','author') {
173: my ($currquota,$quotatype,$inststatus,$defquota) =
174: &Apache::loncommon::get_user_quota($ccuname,$ccdomain,$name);
175: if ($longinsttype eq '') {
176: if ($inststatus ne '') {
177: if ($usertypes->{$inststatus} ne '') {
178: $longinsttype = $usertypes->{$inststatus};
179: }
180: }
181: }
182: my ($showquota,$custom_on,$custom_off,$defaultinfo);
183: $custom_on = ' ';
184: $custom_off = ' checked="checked" ';
185: if ($quotatype eq 'custom') {
186: $custom_on = $custom_off;
187: $custom_off = ' ';
188: $showquota = $currquota;
189: if ($longinsttype eq '') {
190: $defaultinfo = &mt('For this user, the default quota would be [_1]'
1.383 raeburn 191: .' MB.',$defquota);
1.378 raeburn 192: } else {
193: $defaultinfo = &mt("For this user, the default quota would be [_1]".
1.383 raeburn 194: " MB, as determined by the user's institutional".
1.378 raeburn 195: " affiliation ([_2]).",$defquota,$longinsttype);
196: }
197: } else {
198: if ($longinsttype eq '') {
199: $defaultinfo = &mt('For this user, the default quota is [_1]'
1.383 raeburn 200: .' MB.',$defquota);
1.378 raeburn 201: } else {
202: $defaultinfo = &mt("For this user, the default quota of [_1]".
1.383 raeburn 203: " MB, is determined by the user's institutional".
1.378 raeburn 204: " affiliation ([_2]).",$defquota,$longinsttype);
205: }
206: }
207:
208: if (&Apache::lonnet::allowed('mpq',$ccdomain)) {
209: $output .= '<tr class="LC_info_row">'."\n".
210: ' <td>'.$titles{$name}.'</td>'."\n".
211: ' </tr>'."\n".
212: &Apache::loncommon::start_data_table_row()."\n".
1.390 bisitz 213: ' <td><span class="LC_nobreak">'.
214: &mt('Current quota: [_1] MB',$currquota).'</span> '.
1.378 raeburn 215: $defaultinfo.'</td>'."\n".
216: &Apache::loncommon::end_data_table_row()."\n".
217: &Apache::loncommon::start_data_table_row()."\n".
218: ' <td><span class="LC_nobreak">'.$lt{'chqu'}.
219: ': <label>'.
220: '<input type="radio" name="custom_'.$name.'quota" id="custom_'.$name.'quota_off" '.
1.379 raeburn 221: 'value="0" '.$custom_off.' onchange="javascript:quota_changes('."'custom','$name'".');"'.
1.390 bisitz 222: ' /><span class="LC_nobreak">'.
223: &mt('Default ([_1] MB)',$defquota).'</span></label> '.
1.378 raeburn 224: ' <label><input type="radio" name="custom_'.$name.'quota" id="custom_'.$name.'quota_on" '.
1.379 raeburn 225: 'value="1" '.$custom_on.' onchange="javascript:quota_changes('."'custom','$name'".');"'.
1.378 raeburn 226: ' />'.$lt{'cust'}.':</label> '.
1.379 raeburn 227: '<input type="text" name="'.$name.'quota" id="'.$name.'quota" size ="5" '.
228: 'value="'.$showquota.'" onfocus="javascript:quota_changes('."'quota','$name'".');"'.
1.390 bisitz 229: ' /> '.&mt('MB').'</span></td>'."\n".
1.378 raeburn 230: &Apache::loncommon::end_data_table_row()."\n";
231: }
232: }
1.267 raeburn 233: $output .= &Apache::loncommon::end_data_table();
1.134 raeburn 234: return $output;
235: }
236:
1.275 raeburn 237: sub build_tools_display {
238: my ($ccuname,$ccdomain,$context) = @_;
1.306 raeburn 239: my (@usertools,%userenv,$output,@options,%validations,%reqtitles,%reqdisplay,
1.332 raeburn 240: $colspan,$isadv,%domconfig);
1.275 raeburn 241: my %lt = &Apache::lonlocal::texthash (
242: 'blog' => "Personal User Blog",
243: 'aboutme' => "Personal Information Page",
1.385 bisitz 244: 'webdav' => "WebDAV access to Authoring Spaces (if SSL and author/co-author)",
1.275 raeburn 245: 'portfolio' => "Personal User Portfolio",
246: 'avai' => "Available",
247: 'cusa' => "availability",
248: 'chse' => "Change setting",
249: 'usde' => "Use default",
250: 'uscu' => "Use custom",
251: 'official' => 'Can request creation of official courses',
1.299 raeburn 252: 'unofficial' => 'Can request creation of unofficial courses',
253: 'community' => 'Can request creation of communities',
1.384 raeburn 254: 'textbook' => 'Can request creation of textbook courses',
1.362 raeburn 255: 'requestauthor' => 'Can request author space',
1.275 raeburn 256: );
1.279 raeburn 257: if ($context eq 'requestcourses') {
1.275 raeburn 258: %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
1.299 raeburn 259: 'requestcourses.official','requestcourses.unofficial',
1.384 raeburn 260: 'requestcourses.community','requestcourses.textbook');
261: @usertools = ('official','unofficial','community','textbook');
1.309 raeburn 262: @options =('norequest','approval','autolimit','validate');
1.306 raeburn 263: %validations = &Apache::lonnet::auto_courserequest_checks($ccdomain);
264: %reqtitles = &courserequest_titles();
265: %reqdisplay = &courserequest_display();
266: $colspan = ' colspan="2"';
1.332 raeburn 267: %domconfig =
268: &Apache::lonnet::get_dom('configuration',['requestcourses'],$ccdomain);
1.406.2.6 raeburn 269: $isadv = &Apache::lonnet::is_advanced_user($ccdomain,$ccuname);
1.362 raeburn 270: } elsif ($context eq 'requestauthor') {
271: %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
272: 'requestauthor');
273: @usertools = ('requestauthor');
274: @options =('norequest','approval','automatic');
275: %reqtitles = &requestauthor_titles();
276: %reqdisplay = &requestauthor_display();
277: $colspan = ' colspan="2"';
278: %domconfig =
279: &Apache::lonnet::get_dom('configuration',['requestauthor'],$ccdomain);
1.275 raeburn 280: } else {
281: %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
1.361 raeburn 282: 'tools.aboutme','tools.portfolio','tools.blog',
283: 'tools.webdav');
284: @usertools = ('aboutme','blog','webdav','portfolio');
1.275 raeburn 285: }
286: foreach my $item (@usertools) {
1.306 raeburn 287: my ($custom_access,$curr_access,$cust_on,$cust_off,$tool_on,$tool_off,
288: $currdisp,$custdisp,$custradio);
1.275 raeburn 289: $cust_off = 'checked="checked" ';
290: $tool_on = 'checked="checked" ';
291: $curr_access =
292: &Apache::lonnet::usertools_access($ccuname,$ccdomain,$item,undef,
293: $context);
1.362 raeburn 294: if ($context eq 'requestauthor') {
295: if ($userenv{$context} ne '') {
296: $cust_on = ' checked="checked" ';
297: $cust_off = '';
298: }
299: } elsif ($userenv{$context.'.'.$item} ne '') {
1.306 raeburn 300: $cust_on = ' checked="checked" ';
301: $cust_off = '';
302: }
303: if ($context eq 'requestcourses') {
304: if ($userenv{$context.'.'.$item} eq '') {
1.314 raeburn 305: $custom_access = &mt('Currently from default setting.');
1.306 raeburn 306: } else {
307: $custom_access = &mt('Currently from custom setting.');
1.275 raeburn 308: }
1.362 raeburn 309: } elsif ($context eq 'requestauthor') {
310: if ($userenv{$context} eq '') {
311: $custom_access = &mt('Currently from default setting.');
312: } else {
313: $custom_access = &mt('Currently from custom setting.');
314: }
1.275 raeburn 315: } else {
1.306 raeburn 316: if ($userenv{$context.'.'.$item} eq '') {
1.314 raeburn 317: $custom_access =
1.306 raeburn 318: &mt('Availability determined currently from default setting.');
319: if (!$curr_access) {
320: $tool_off = 'checked="checked" ';
321: $tool_on = '';
322: }
323: } else {
1.314 raeburn 324: $custom_access =
1.306 raeburn 325: &mt('Availability determined currently from custom setting.');
326: if ($userenv{$context.'.'.$item} == 0) {
327: $tool_off = 'checked="checked" ';
328: $tool_on = '';
329: }
1.275 raeburn 330: }
331: }
332: $output .= ' <tr class="LC_info_row">'."\n".
1.306 raeburn 333: ' <td'.$colspan.'>'.$lt{$item}.'</td>'."\n".
1.275 raeburn 334: ' </tr>'."\n".
1.306 raeburn 335: &Apache::loncommon::start_data_table_row()."\n";
1.362 raeburn 336: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.306 raeburn 337: my ($curroption,$currlimit);
1.362 raeburn 338: my $envkey = $context.'.'.$item;
339: if ($context eq 'requestauthor') {
340: $envkey = $context;
341: }
342: if ($userenv{$envkey} ne '') {
343: $curroption = $userenv{$envkey};
1.332 raeburn 344: } else {
345: my (@inststatuses);
1.362 raeburn 346: if ($context eq 'requestcourses') {
347: $curroption =
348: &Apache::loncoursequeueadmin::get_processtype('course',$ccuname,$ccdomain,
349: $isadv,$ccdomain,$item,
350: \@inststatuses,\%domconfig);
351: } else {
352: $curroption =
353: &Apache::loncoursequeueadmin::get_processtype('requestauthor',$ccuname,$ccdomain,
354: $isadv,$ccdomain,undef,
355: \@inststatuses,\%domconfig);
356: }
1.332 raeburn 357: }
1.306 raeburn 358: if (!$curroption) {
359: $curroption = 'norequest';
360: }
361: if ($curroption =~ /^autolimit=(\d*)$/) {
362: $currlimit = $1;
1.314 raeburn 363: if ($currlimit eq '') {
364: $currdisp = &mt('Yes, automatic creation');
365: } else {
366: $currdisp = &mt('Yes, up to [quant,_1,request]/user',$currlimit);
367: }
1.306 raeburn 368: } else {
369: $currdisp = $reqdisplay{$curroption};
370: }
371: $custdisp = '<table>';
372: foreach my $option (@options) {
373: my $val = $option;
374: if ($option eq 'norequest') {
375: $val = 0;
376: }
377: if ($option eq 'validate') {
378: my $canvalidate = 0;
379: if (ref($validations{$item}) eq 'HASH') {
380: if ($validations{$item}{'_custom_'}) {
381: $canvalidate = 1;
382: }
383: }
384: next if (!$canvalidate);
385: }
386: my $checked = '';
387: if ($option eq $curroption) {
388: $checked = ' checked="checked"';
389: } elsif ($option eq 'autolimit') {
390: if ($curroption =~ /^autolimit/) {
391: $checked = ' checked="checked"';
392: }
393: }
1.362 raeburn 394: my $name = 'crsreq_'.$item;
395: if ($context eq 'requestauthor') {
396: $name = $item;
397: }
1.306 raeburn 398: $custdisp .= '<tr><td><span class="LC_nobreak"><label>'.
1.362 raeburn 399: '<input type="radio" name="'.$name.'" '.
400: 'value="'.$val.'"'.$checked.' />'.
1.306 raeburn 401: $reqtitles{$option}.'</label> ';
402: if ($option eq 'autolimit') {
1.362 raeburn 403: $custdisp .= '<input type="text" name="'.$name.
404: '_limit" size="1" '.
1.314 raeburn 405: 'value="'.$currlimit.'" /></span><br />'.
406: $reqtitles{'unlimited'};
1.362 raeburn 407: } else {
408: $custdisp .= '</span>';
409: }
410: $custdisp .= '</td></tr>';
1.306 raeburn 411: }
412: $custdisp .= '</table>';
413: $custradio = '</span></td><td>'.&mt('Custom setting').'<br />'.$custdisp;
414: } else {
415: $currdisp = ($curr_access?&mt('Yes'):&mt('No'));
1.362 raeburn 416: my $name = $context.'_'.$item;
417: if ($context eq 'requestauthor') {
418: $name = $context;
419: }
1.306 raeburn 420: $custdisp = '<span class="LC_nobreak"><label>'.
1.362 raeburn 421: '<input type="radio" name="'.$name.'"'.
1.361 raeburn 422: ' value="1" '.$tool_on.'/>'.&mt('On').'</label> <label>'.
1.362 raeburn 423: '<input type="radio" name="'.$name.'" value="0" '.
1.306 raeburn 424: $tool_off.'/>'.&mt('Off').'</label></span>';
425: $custradio = (' 'x2).'--'.$lt{'cusa'}.': '.$custdisp.
426: '</span>';
427: }
428: $output .= ' <td'.$colspan.'>'.$custom_access.(' 'x4).
429: $lt{'avai'}.': '.$currdisp.'</td>'."\n".
1.406.2.6 raeburn 430: &Apache::loncommon::end_data_table_row()."\n";
431: unless (&Apache::lonnet::allowed('udp',$ccdomain)) {
432: $output .=
1.275 raeburn 433: &Apache::loncommon::start_data_table_row()."\n".
1.306 raeburn 434: ' <td style="vertical-align:top;"><span class="LC_nobreak">'.
435: $lt{'chse'}.': <label>'.
1.275 raeburn 436: '<input type="radio" name="custom'.$item.'" value="0" '.
1.306 raeburn 437: $cust_off.'/>'.$lt{'usde'}.'</label>'.(' ' x3).
438: '<label><input type="radio" name="custom'.$item.'" value="1" '.
439: $cust_on.'/>'.$lt{'uscu'}.'</label>'.$custradio.'</td>'.
1.275 raeburn 440: &Apache::loncommon::end_data_table_row()."\n";
1.406.2.6 raeburn 441: }
1.275 raeburn 442: }
443: return $output;
444: }
445:
1.300 raeburn 446: sub coursereq_externaluser {
447: my ($ccuname,$ccdomain,$cdom) = @_;
1.306 raeburn 448: my (@usertools,@options,%validations,%userenv,$output);
1.300 raeburn 449: my %lt = &Apache::lonlocal::texthash (
450: 'official' => 'Can request creation of official courses',
451: 'unofficial' => 'Can request creation of unofficial courses',
452: 'community' => 'Can request creation of communities',
1.384 raeburn 453: 'textbook' => 'Can request creation of textbook courses',
1.300 raeburn 454: );
455:
456: %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
457: 'reqcrsotherdom.official','reqcrsotherdom.unofficial',
1.384 raeburn 458: 'reqcrsotherdom.community','reqcrsotherdom.textbook');
459: @usertools = ('official','unofficial','community','textbook');
1.309 raeburn 460: @options = ('approval','validate','autolimit');
1.306 raeburn 461: %validations = &Apache::lonnet::auto_courserequest_checks($cdom);
462: my $optregex = join('|',@options);
463: my %reqtitles = &courserequest_titles();
1.300 raeburn 464: foreach my $item (@usertools) {
1.306 raeburn 465: my ($curroption,$currlimit,$tooloff);
1.300 raeburn 466: if ($userenv{'reqcrsotherdom.'.$item} ne '') {
467: my @curr = split(',',$userenv{'reqcrsotherdom.'.$item});
1.314 raeburn 468: foreach my $req (@curr) {
469: if ($req =~ /^\Q$cdom\E\:($optregex)=?(\d*)$/) {
470: $curroption = $1;
471: $currlimit = $2;
472: last;
1.306 raeburn 473: }
474: }
1.314 raeburn 475: if (!$curroption) {
476: $curroption = 'norequest';
477: $tooloff = ' checked="checked"';
478: }
1.306 raeburn 479: } else {
480: $curroption = 'norequest';
481: $tooloff = ' checked="checked"';
482: }
483: $output.= &Apache::loncommon::start_data_table_row()."\n".
1.314 raeburn 484: ' <td><span class="LC_nobreak">'.$lt{$item}.': </span></td><td>'.
485: '<table><tr><td valign="top">'."\n".
1.306 raeburn 486: '<label><input type="radio" name="reqcrsotherdom_'.$item.
1.314 raeburn 487: '" value=""'.$tooloff.' />'.$reqtitles{'norequest'}.
488: '</label></td>';
1.306 raeburn 489: foreach my $option (@options) {
490: if ($option eq 'validate') {
491: my $canvalidate = 0;
492: if (ref($validations{$item}) eq 'HASH') {
493: if ($validations{$item}{'_external_'}) {
494: $canvalidate = 1;
495: }
496: }
497: next if (!$canvalidate);
498: }
499: my $checked = '';
500: if ($option eq $curroption) {
501: $checked = ' checked="checked"';
502: }
1.314 raeburn 503: $output .= '<td valign="top"><span class="LC_nobreak"><label>'.
1.306 raeburn 504: '<input type="radio" name="reqcrsotherdom_'.$item.
505: '" value="'.$option.'"'.$checked.' />'.
1.314 raeburn 506: $reqtitles{$option}.'</label>';
1.306 raeburn 507: if ($option eq 'autolimit') {
1.314 raeburn 508: $output .= ' <input type="text" name="reqcrsotherdom_'.
1.306 raeburn 509: $item.'_limit" size="1" '.
1.314 raeburn 510: 'value="'.$currlimit.'" /></span>'.
511: '<br />'.$reqtitles{'unlimited'};
512: } else {
513: $output .= '</span>';
1.300 raeburn 514: }
1.314 raeburn 515: $output .= '</td>';
1.300 raeburn 516: }
1.314 raeburn 517: $output .= '</td></tr></table></td>'."\n".
1.300 raeburn 518: &Apache::loncommon::end_data_table_row()."\n";
519: }
520: return $output;
521: }
522:
1.362 raeburn 523: sub domainrole_req {
524: my ($ccuname,$ccdomain) = @_;
525: return '<br /><h3>'.
526: &mt('User Can Request Assignment of Domain Roles?').
527: '</h3>'."\n".
528: &Apache::loncommon::start_data_table().
529: &build_tools_display($ccuname,$ccdomain,
530: 'requestauthor').
531: &Apache::loncommon::end_data_table();
532: }
533:
1.306 raeburn 534: sub courserequest_titles {
535: my %titles = &Apache::lonlocal::texthash (
536: official => 'Official',
537: unofficial => 'Unofficial',
538: community => 'Communities',
1.384 raeburn 539: textbook => 'Textbook',
1.306 raeburn 540: norequest => 'Not allowed',
1.309 raeburn 541: approval => 'Approval by Dom. Coord.',
1.306 raeburn 542: validate => 'With validation',
543: autolimit => 'Numerical limit',
1.314 raeburn 544: unlimited => '(blank for unlimited)',
1.306 raeburn 545: );
546: return %titles;
547: }
548:
549: sub courserequest_display {
550: my %titles = &Apache::lonlocal::texthash (
1.309 raeburn 551: approval => 'Yes, need approval',
1.306 raeburn 552: validate => 'Yes, with validation',
553: norequest => 'No',
554: );
555: return %titles;
556: }
557:
1.362 raeburn 558: sub requestauthor_titles {
559: my %titles = &Apache::lonlocal::texthash (
560: norequest => 'Not allowed',
561: approval => 'Approval by Dom. Coord.',
562: automatic => 'Automatic approval',
563: );
564: return %titles;
565:
566: }
567:
568: sub requestauthor_display {
569: my %titles = &Apache::lonlocal::texthash (
570: approval => 'Yes, need approval',
571: automatic => 'Yes, automatic approval',
572: norequest => 'No',
573: );
574: return %titles;
575: }
576:
1.383 raeburn 577: sub requestchange_display {
578: my %titles = &Apache::lonlocal::texthash (
579: approval => "availability set to 'on' (approval required)",
580: automatic => "availability set to 'on' (automatic approval)",
581: norequest => "availability set to 'off'",
582: );
583: return %titles;
584: }
585:
1.362 raeburn 586: sub curr_requestauthor {
587: my ($uname,$udom,$isadv,$inststatuses,$domconfig) = @_;
588: return unless ((ref($inststatuses) eq 'ARRAY') && (ref($domconfig) eq 'HASH'));
589: if ($uname eq '' || $udom eq '') {
590: $uname = $env{'user.name'};
591: $udom = $env{'user.domain'};
592: $isadv = $env{'user.adv'};
593: }
594: my (%userenv,%settings,$val);
595: my @options = ('automatic','approval');
596: %userenv =
597: &Apache::lonnet::userenvironment($udom,$uname,'requestauthor','inststatus');
598: if ($userenv{'requestauthor'}) {
599: $val = $userenv{'requestauthor'};
600: @{$inststatuses} = ('_custom_');
601: } else {
602: my %alltasks;
603: if (ref($domconfig->{'requestauthor'}) eq 'HASH') {
604: %settings = %{$domconfig->{'requestauthor'}};
605: if (($isadv) && ($settings{'_LC_adv'} ne '')) {
606: $val = $settings{'_LC_adv'};
607: @{$inststatuses} = ('_LC_adv_');
608: } else {
609: if ($userenv{'inststatus'} ne '') {
610: @{$inststatuses} = split(',',$userenv{'inststatus'});
611: } else {
612: @{$inststatuses} = ('default');
613: }
614: foreach my $status (@{$inststatuses}) {
615: if (exists($settings{$status})) {
616: my $value = $settings{$status};
617: next unless ($value);
618: unless (exists($alltasks{$value})) {
619: if (ref($alltasks{$value}) eq 'ARRAY') {
620: unless(grep(/^\Q$status\E$/,@{$alltasks{$value}})) {
621: push(@{$alltasks{$value}},$status);
622: }
623: } else {
624: @{$alltasks{$value}} = ($status);
625: }
626: }
627: }
628: }
629: foreach my $option (@options) {
630: if ($alltasks{$option}) {
631: $val = $option;
632: last;
633: }
634: }
635: }
636: }
637: }
638: return $val;
639: }
640:
1.2 www 641: # =================================================================== Phase one
1.1 www 642:
1.42 matthew 643: sub print_username_entry_form {
1.406.2.14 raeburn 644: my ($r,$context,$response,$srch,$forcenewuser,$crstype,$brcrum,
645: $permission) = @_;
1.101 albertel 646: my $defdom=$env{'request.role.domain'};
1.160 raeburn 647: my $formtoset = 'crtuser';
648: if (exists($env{'form.startrolename'})) {
649: $formtoset = 'docustom';
650: $env{'form.rolename'} = $env{'form.startrolename'};
1.207 raeburn 651: } elsif ($env{'form.origform'} eq 'crtusername') {
652: $formtoset = $env{'form.origform'};
1.160 raeburn 653: }
654:
655: my ($jsback,$elements) = &crumb_utilities();
656:
657: my $jscript = &Apache::loncommon::studentbrowser_javascript()."\n".
1.165 albertel 658: '<script type="text/javascript">'."\n".
1.301 bisitz 659: '// <![CDATA['."\n".
660: &Apache::lonhtmlcommon::set_form_elements($elements->{$formtoset})."\n".
661: '// ]]>'."\n".
1.162 raeburn 662: '</script>'."\n";
1.160 raeburn 663:
1.324 raeburn 664: my %existingroles=&Apache::lonuserutils::my_custom_roles($crstype);
665: if (($env{'form.action'} eq 'custom') && (keys(%existingroles) > 0)
666: && (&Apache::lonnet::allowed('mcr','/'))) {
667: $jscript .= &customrole_javascript();
668: }
1.224 raeburn 669: my $helpitem = 'Course_Change_Privileges';
670: if ($env{'form.action'} eq 'custom') {
1.406.2.14 raeburn 671: if ($context eq 'course') {
672: $helpitem = 'Course_Editing_Custom_Roles';
673: } elsif ($context eq 'domain') {
674: $helpitem = 'Domain_Editing_Custom_Roles';
675: }
1.224 raeburn 676: } elsif ($env{'form.action'} eq 'singlestudent') {
677: $helpitem = 'Course_Add_Student';
1.406.2.5 raeburn 678: } elsif ($env{'form.action'} eq 'accesslogs') {
679: $helpitem = 'Domain_User_Access_Logs';
1.406.2.14 raeburn 680: } elsif ($context eq 'author') {
681: $helpitem = 'Author_Change_Privileges';
682: } elsif ($context eq 'domain') {
683: if ($permission->{'cusr'}) {
684: $helpitem = 'Domain_Change_Privileges';
685: } elsif ($permission->{'view'}) {
686: $helpitem = 'Domain_View_Privileges';
687: } else {
688: undef($helpitem);
689: }
1.224 raeburn 690: }
1.406.2.7 raeburn 691: my %breadcrumb_text = &singleuser_breadcrumb($crstype,$context,$defdom);
1.351 raeburn 692: if ($env{'form.action'} eq 'custom') {
693: push(@{$brcrum},
694: {href=>"javascript:backPage(document.crtuser)",
695: text=>"Pick custom role",
696: help => $helpitem,}
697: );
698: } else {
699: push (@{$brcrum},
700: {href => "javascript:backPage(document.crtuser)",
701: text => $breadcrumb_text{'search'},
702: help => $helpitem,
703: faq => 282,
704: bug => 'Instructor Interface',}
705: );
706: }
707: my %loaditems = (
708: 'onload' => "javascript:setFormElements(document.$formtoset)",
709: );
710: my $args = {bread_crumbs => $brcrum,
711: bread_crumbs_component => 'User Management',
712: add_entries => \%loaditems,};
713: $r->print(&Apache::loncommon::start_page('User Management',$jscript,$args));
714:
1.71 sakharuk 715: my %lt=&Apache::lonlocal::texthash(
1.229 raeburn 716: 'srst' => 'Search for a user and enroll as a student',
1.318 raeburn 717: 'srme' => 'Search for a user and enroll as a member',
1.229 raeburn 718: 'srad' => 'Search for a user and modify/add user information or roles',
1.406.2.7 raeburn 719: 'srvu' => 'Search for a user and view user information and roles',
1.406.2.5 raeburn 720: 'srva' => 'Search for a user and view access log information',
1.71 sakharuk 721: 'usr' => "Username",
722: 'dom' => "Domain",
1.324 raeburn 723: 'ecrp' => "Define or Edit Custom Role",
724: 'nr' => "role name",
1.282 schafran 725: 'cre' => "Next",
1.71 sakharuk 726: );
1.351 raeburn 727:
1.214 raeburn 728: if ($env{'form.action'} eq 'custom') {
1.190 raeburn 729: if (&Apache::lonnet::allowed('mcr','/')) {
1.324 raeburn 730: my $newroletext = &mt('Define new custom role:');
731: $r->print('<form action="/adm/createuser" method="post" name="docustom">'.
732: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'.
733: '<input type="hidden" name="phase" value="selected_custom_edit" />'.
734: '<h3>'.$lt{'ecrp'}.'</h3>'.
735: &Apache::loncommon::start_data_table().
736: &Apache::loncommon::start_data_table_row().
737: '<td>');
738: if (keys(%existingroles) > 0) {
739: $r->print('<br /><label><input type="radio" name="customroleaction" value="new" checked="checked" onclick="setCustomFields();" /><b>'.$newroletext.'</b></label>');
740: } else {
741: $r->print('<br /><input type="hidden" name="customroleaction" value="new" /><b>'.$newroletext.'</b>');
742: }
743: $r->print('</td><td align="center">'.$lt{'nr'}.'<br /><input type="text" size="15" name="newrolename" onfocus="setCustomAction('."'new'".');" /></td>'.
744: &Apache::loncommon::end_data_table_row());
745: if (keys(%existingroles) > 0) {
746: $r->print(&Apache::loncommon::start_data_table_row().'<td><br />'.
747: '<label><input type="radio" name="customroleaction" value="edit" onclick="setCustomFields();"/><b>'.
748: &mt('View/Modify existing role:').'</b></label></td>'.
749: '<td align="center"><br />'.
750: '<select name="rolename" onchange="setCustomAction('."'edit'".');">'.
1.326 raeburn 751: '<option value="" selected="selected">'.
1.324 raeburn 752: &mt('Select'));
753: foreach my $role (sort(keys(%existingroles))) {
1.326 raeburn 754: $r->print('<option value="'.$role.'">'.$role.'</option>');
1.324 raeburn 755: }
756: $r->print('</select>'.
757: '</td>'.
758: &Apache::loncommon::end_data_table_row());
759: }
760: $r->print(&Apache::loncommon::end_data_table().'<p>'.
761: '<input name="customeditor" type="submit" value="'.
762: $lt{'cre'}.'" /></p>'.
763: '</form>');
1.190 raeburn 764: }
1.213 raeburn 765: } else {
1.229 raeburn 766: my $actiontext = $lt{'srad'};
1.406.2.13 raeburn 767: my $fixeddom;
1.213 raeburn 768: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 769: if ($crstype eq 'Community') {
770: $actiontext = $lt{'srme'};
771: } else {
772: $actiontext = $lt{'srst'};
773: }
1.406.2.5 raeburn 774: } elsif ($env{'form.action'} eq 'accesslogs') {
775: $actiontext = $lt{'srva'};
1.406.2.13 raeburn 776: $fixeddom = 1;
1.406.2.7 raeburn 777: } elsif (($env{'form.action'} eq 'singleuser') &&
778: ($context eq 'domain') && (!&Apache::lonnet::allowed('mau',$defdom))) {
779: $actiontext = $lt{'srvu'};
1.406.2.14 raeburn 780: $fixeddom = 1;
1.213 raeburn 781: }
1.324 raeburn 782: $r->print("<h3>$actiontext</h3>");
1.213 raeburn 783: if ($env{'form.origform'} ne 'crtusername') {
1.406.2.5 raeburn 784: if ($response) {
785: $r->print("\n<div>$response</div>".
786: '<br clear="all" />');
787: }
1.213 raeburn 788: }
1.406.2.13 raeburn 789: $r->print(&entry_form($defdom,$srch,$forcenewuser,$context,$response,$crstype,$fixeddom));
1.107 www 790: }
1.110 albertel 791: }
792:
1.324 raeburn 793: sub customrole_javascript {
794: my $js = <<"END";
795: <script type="text/javascript">
796: // <![CDATA[
797:
798: function setCustomFields() {
799: if (document.docustom.customroleaction.length > 0) {
800: for (var i=0; i<document.docustom.customroleaction.length; i++) {
801: if (document.docustom.customroleaction[i].checked) {
802: if (document.docustom.customroleaction[i].value == 'new') {
803: document.docustom.rolename.selectedIndex = 0;
804: } else {
805: document.docustom.newrolename.value = '';
806: }
807: }
808: }
809: }
810: return;
811: }
812:
813: function setCustomAction(caller) {
814: if (document.docustom.customroleaction.length > 0) {
815: for (var i=0; i<document.docustom.customroleaction.length; i++) {
816: if (document.docustom.customroleaction[i].value == caller) {
817: document.docustom.customroleaction[i].checked = true;
818: }
819: }
820: }
821: setCustomFields();
822: return;
823: }
824:
825: // ]]>
826: </script>
827: END
828: return $js;
829: }
830:
1.160 raeburn 831: sub entry_form {
1.406.2.5 raeburn 832: my ($dom,$srch,$forcenewuser,$context,$responsemsg,$crstype,$fixeddom) = @_;
1.229 raeburn 833: my ($usertype,$inexact);
1.214 raeburn 834: if (ref($srch) eq 'HASH') {
835: if (($srch->{'srchin'} eq 'dom') &&
836: ($srch->{'srchby'} eq 'uname') &&
837: ($srch->{'srchtype'} eq 'exact') &&
838: ($srch->{'srchdomain'} ne '') &&
839: ($srch->{'srchterm'} ne '')) {
1.353 raeburn 840: my (%curr_rules,%got_rules);
1.214 raeburn 841: my ($rules,$ruleorder) =
842: &Apache::lonnet::inst_userrules($srch->{'srchdomain'},'username');
1.353 raeburn 843: $usertype = &Apache::lonuserutils::check_usertype($srch->{'srchdomain'},$srch->{'srchterm'},$rules,\%curr_rules,\%got_rules);
1.229 raeburn 844: } else {
845: $inexact = 1;
1.214 raeburn 846: }
1.207 raeburn 847: }
1.406.2.14 raeburn 848: my ($cancreate,$noinstd);
849: if ($env{'form.action'} eq 'accesslogs') {
850: $noinstd = 1;
851: } else {
852: $cancreate =
853: &Apache::lonuserutils::can_create_user($dom,$context,$usertype);
854: }
1.406.2.3 raeburn 855: my ($userpicker,$cansearch) =
1.179 raeburn 856: &Apache::loncommon::user_picker($dom,$srch,$forcenewuser,
1.406.2.14 raeburn 857: 'document.crtuser',$cancreate,$usertype,$context,$fixeddom,$noinstd);
1.160 raeburn 858: my $srchbutton = &mt('Search');
1.229 raeburn 859: if ($env{'form.action'} eq 'singlestudent') {
860: $srchbutton = &mt('Search and Enroll');
1.406.2.5 raeburn 861: } elsif ($env{'form.action'} eq 'accesslogs') {
862: $srchbutton = &mt('Search');
1.229 raeburn 863: } elsif ($cancreate && $responsemsg ne '' && $inexact) {
864: $srchbutton = &mt('Search or Add New User');
865: }
1.406.2.3 raeburn 866: my $output;
867: if ($cansearch) {
868: $output = <<"ENDBLOCK";
1.160 raeburn 869: <form action="/adm/createuser" method="post" name="crtuser">
1.190 raeburn 870: <input type="hidden" name="action" value="$env{'form.action'}" />
1.160 raeburn 871: <input type="hidden" name="phase" value="get_user_info" />
872: $userpicker
1.179 raeburn 873: <input name="userrole" type="button" value="$srchbutton" onclick="javascript:validateEntry(document.crtuser)" />
1.160 raeburn 874: </form>
1.207 raeburn 875: ENDBLOCK
1.406.2.3 raeburn 876: } else {
877: $output = '<p>'.$userpicker.'</p>';
878: }
1.406.2.7 raeburn 879: if (($env{'form.phase'} eq '') && ($env{'form.action'} ne 'accesslogs') &&
880: (!(($env{'form.action'} eq 'singleuser') && ($context eq 'domain') &&
881: (!&Apache::lonnet::allowed('mau',$env{'request.role.domain'}))))) {
1.207 raeburn 882: my $defdom=$env{'request.role.domain'};
883: my $domform = &Apache::loncommon::select_dom_form($defdom,'srchdomain');
884: my %lt=&Apache::lonlocal::texthash(
1.229 raeburn 885: 'enro' => 'Enroll one student',
1.318 raeburn 886: 'enrm' => 'Enroll one member',
1.229 raeburn 887: 'admo' => 'Add/modify a single user',
888: 'crea' => 'create new user if required',
889: 'uskn' => "username is known",
1.207 raeburn 890: 'crnu' => 'Create a new user',
891: 'usr' => 'Username',
892: 'dom' => 'in domain',
1.229 raeburn 893: 'enrl' => 'Enroll',
894: 'cram' => 'Create/Modify user',
1.207 raeburn 895: );
1.229 raeburn 896: my $sellink=&Apache::loncommon::selectstudent_link('crtusername','srchterm','srchdomain');
897: my ($title,$buttontext,$showresponse);
1.318 raeburn 898: if ($env{'form.action'} eq 'singlestudent') {
899: if ($crstype eq 'Community') {
900: $title = $lt{'enrm'};
901: } else {
902: $title = $lt{'enro'};
903: }
1.229 raeburn 904: $buttontext = $lt{'enrl'};
905: } else {
906: $title = $lt{'admo'};
907: $buttontext = $lt{'cram'};
908: }
909: if ($cancreate) {
910: $title .= ' <span class="LC_cusr_subheading">('.$lt{'crea'}.')</span>';
911: } else {
912: $title .= ' <span class="LC_cusr_subheading">('.$lt{'uskn'}.')</span>';
913: }
914: if ($env{'form.origform'} eq 'crtusername') {
915: $showresponse = $responsemsg;
916: }
1.207 raeburn 917: $output .= <<"ENDDOCUMENT";
1.229 raeburn 918: <br />
1.207 raeburn 919: <form action="/adm/createuser" method="post" name="crtusername">
920: <input type="hidden" name="action" value="$env{'form.action'}" />
921: <input type="hidden" name="phase" value="createnewuser" />
922: <input type="hidden" name="srchtype" value="exact" />
1.233 raeburn 923: <input type="hidden" name="srchby" value="uname" />
1.207 raeburn 924: <input type="hidden" name="srchin" value="dom" />
925: <input type="hidden" name="forcenewuser" value="1" />
926: <input type="hidden" name="origform" value="crtusername" />
1.229 raeburn 927: <h3>$title</h3>
928: $showresponse
1.207 raeburn 929: <table>
930: <tr>
931: <td>$lt{'usr'}:</td>
932: <td><input type="text" size="15" name="srchterm" /></td>
933: <td> $lt{'dom'}:</td><td>$domform</td>
1.229 raeburn 934: <td> $sellink </td>
935: <td> <input name="userrole" type="submit" value="$buttontext" /></td>
1.207 raeburn 936: </tr>
937: </table>
938: </form>
1.160 raeburn 939: ENDDOCUMENT
1.207 raeburn 940: }
1.160 raeburn 941: return $output;
942: }
1.110 albertel 943:
944: sub user_modification_js {
1.113 raeburn 945: my ($pjump_def,$dc_setcourse_code,$nondc_setsection_code,$groupslist)=@_;
946:
1.110 albertel 947: return <<END;
948: <script type="text/javascript" language="Javascript">
1.301 bisitz 949: // <![CDATA[
1.314 raeburn 950:
1.110 albertel 951: $pjump_def
952: $dc_setcourse_code
953:
954: function dateset() {
955: eval("document.cu."+document.cu.pres_marker.value+
956: ".value=document.cu.pres_value.value");
1.359 www 957: modalWindow.close();
1.110 albertel 958: }
959:
1.113 raeburn 960: $nondc_setsection_code
1.301 bisitz 961: // ]]>
1.110 albertel 962: </script>
963: END
1.2 www 964: }
965:
966: # =================================================================== Phase two
1.160 raeburn 967: sub print_user_selection_page {
1.351 raeburn 968: my ($r,$response,$srch,$srch_results,$srcharray,$context,$opener_elements,$crstype,$brcrum) = @_;
1.160 raeburn 969: my @fields = ('username','domain','lastname','firstname','permanentemail');
970: my $sortby = $env{'form.sortby'};
971:
972: if (!grep(/^\Q$sortby\E$/,@fields)) {
973: $sortby = 'lastname';
974: }
975:
976: my ($jsback,$elements) = &crumb_utilities();
977:
978: my $jscript = (<<ENDSCRIPT);
979: <script type="text/javascript">
1.301 bisitz 980: // <![CDATA[
1.160 raeburn 981: function pickuser(uname,udom) {
982: document.usersrchform.seluname.value=uname;
983: document.usersrchform.seludom.value=udom;
984: document.usersrchform.phase.value="userpicked";
985: document.usersrchform.submit();
986: }
987:
988: $jsback
1.301 bisitz 989: // ]]>
1.160 raeburn 990: </script>
991: ENDSCRIPT
992:
993: my %lt=&Apache::lonlocal::texthash(
1.179 raeburn 994: 'usrch' => "User Search to add/modify roles",
995: 'stusrch' => "User Search to enroll student",
1.318 raeburn 996: 'memsrch' => "User Search to enroll member",
1.406.2.5 raeburn 997: 'srcva' => "Search for a user and view access log information",
1.406.2.7 raeburn 998: 'usrvu' => "User Search to view user roles",
1.179 raeburn 999: 'usel' => "Select a user to add/modify roles",
1.406.2.7 raeburn 1000: 'suvr' => "Select a user to view roles",
1.318 raeburn 1001: 'stusel' => "Select a user to enroll as a student",
1002: 'memsel' => "Select a user to enroll as a member",
1.406.2.5 raeburn 1003: 'vacsel' => "Select a user to view access log",
1.160 raeburn 1004: 'username' => "username",
1005: 'domain' => "domain",
1006: 'lastname' => "last name",
1007: 'firstname' => "first name",
1008: 'permanentemail' => "permanent e-mail",
1009: );
1.302 raeburn 1010: if ($context eq 'requestcrs') {
1011: $r->print('<div>');
1012: } else {
1.406.2.7 raeburn 1013: my %breadcrumb_text = &singleuser_breadcrumb($crstype,$context,$srch->{'srchdomain'});
1.351 raeburn 1014: my $helpitem;
1015: if ($env{'form.action'} eq 'singleuser') {
1016: $helpitem = 'Course_Change_Privileges';
1017: } elsif ($env{'form.action'} eq 'singlestudent') {
1018: $helpitem = 'Course_Add_Student';
1.406.2.14 raeburn 1019: } elsif ($context eq 'author') {
1020: $helpitem = 'Author_Change_Privileges';
1021: } elsif ($context eq 'domain') {
1022: $helpitem = 'Domain_Change_Privileges';
1.351 raeburn 1023: }
1024: push (@{$brcrum},
1025: {href => "javascript:backPage(document.usersrchform,'','')",
1026: text => $breadcrumb_text{'search'},
1027: faq => 282,
1028: bug => 'Instructor Interface',},
1029: {href => "javascript:backPage(document.usersrchform,'get_user_info','select')",
1030: text => $breadcrumb_text{'userpicked'},
1031: faq => 282,
1032: bug => 'Instructor Interface',
1033: help => $helpitem}
1034: );
1035: $r->print(&Apache::loncommon::start_page('User Management',$jscript,{bread_crumbs => $brcrum}));
1.302 raeburn 1036: if ($env{'form.action'} eq 'singleuser') {
1.406.2.7 raeburn 1037: my $readonly;
1038: if (($context eq 'domain') && (!&Apache::lonnet::allowed('mau',$srch->{'srchdomain'}))) {
1039: $readonly = 1;
1040: $r->print("<b>$lt{'usrvu'}</b><br />");
1041: } else {
1042: $r->print("<b>$lt{'usrch'}</b><br />");
1043: }
1.318 raeburn 1044: $r->print(&entry_form($srch->{'srchdomain'},$srch,undef,$context,undef,$crstype));
1.406.2.7 raeburn 1045: if ($readonly) {
1046: $r->print('<h3>'.$lt{'suvr'}.'</h3>');
1047: } else {
1048: $r->print('<h3>'.$lt{'usel'}.'</h3>');
1049: }
1.302 raeburn 1050: } elsif ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1051: $r->print($jscript."<b>");
1052: if ($crstype eq 'Community') {
1053: $r->print($lt{'memsrch'});
1054: } else {
1055: $r->print($lt{'stusrch'});
1056: }
1057: $r->print("</b><br />");
1058: $r->print(&entry_form($srch->{'srchdomain'},$srch,undef,$context,undef,$crstype));
1059: $r->print('</form><h3>');
1060: if ($crstype eq 'Community') {
1061: $r->print($lt{'memsel'});
1062: } else {
1063: $r->print($lt{'stusel'});
1064: }
1065: $r->print('</h3>');
1.406.2.5 raeburn 1066: } elsif ($env{'form.action'} eq 'accesslogs') {
1067: $r->print("<b>$lt{'srcva'}</b><br />");
1.406.2.14 raeburn 1068: $r->print(&entry_form($srch->{'srchdomain'},$srch,undef,$context,undef,undef,1));
1.406.2.5 raeburn 1069: $r->print('<h3>'.$lt{'vacsel'}.'</h3>');
1.302 raeburn 1070: }
1.179 raeburn 1071: }
1.380 bisitz 1072: $r->print('<form name="usersrchform" method="post" action="">'.
1.160 raeburn 1073: &Apache::loncommon::start_data_table()."\n".
1074: &Apache::loncommon::start_data_table_header_row()."\n".
1075: ' <th> </th>'."\n");
1076: foreach my $field (@fields) {
1077: $r->print(' <th><a href="javascript:document.usersrchform.sortby.value='.
1078: "'".$field."'".';document.usersrchform.submit();">'.
1079: $lt{$field}.'</a></th>'."\n");
1080: }
1081: $r->print(&Apache::loncommon::end_data_table_header_row());
1082:
1083: my @sorted_users = sort {
1.167 albertel 1084: lc($srch_results->{$a}->{$sortby}) cmp lc($srch_results->{$b}->{$sortby})
1.160 raeburn 1085: ||
1.167 albertel 1086: lc($srch_results->{$a}->{lastname}) cmp lc($srch_results->{$b}->{lastname})
1.160 raeburn 1087: ||
1088: lc($srch_results->{$a}->{firstname}) cmp lc($srch_results->{$b}->{firstname})
1.167 albertel 1089: ||
1090: lc($a) cmp lc($b)
1.160 raeburn 1091: } (keys(%$srch_results));
1092:
1093: foreach my $user (@sorted_users) {
1094: my ($uname,$udom) = split(/:/,$user);
1.302 raeburn 1095: my $onclick;
1096: if ($context eq 'requestcrs') {
1.314 raeburn 1097: $onclick =
1.302 raeburn 1098: 'onclick="javascript:gochoose('."'$uname','$udom',".
1099: "'$srch_results->{$user}->{firstname}',".
1100: "'$srch_results->{$user}->{lastname}',".
1101: "'$srch_results->{$user}->{permanentemail}'".');"';
1102: } else {
1.314 raeburn 1103: $onclick =
1.302 raeburn 1104: ' onclick="javascript:pickuser('."'".$uname."'".','."'".$udom."'".');"';
1105: }
1.160 raeburn 1106: $r->print(&Apache::loncommon::start_data_table_row().
1.302 raeburn 1107: '<td><input type="button" name="seluser" value="'.&mt('Select').'" '.
1108: $onclick.' /></td>'.
1.160 raeburn 1109: '<td><tt>'.$uname.'</tt></td>'.
1110: '<td><tt>'.$udom.'</tt></td>');
1111: foreach my $field ('lastname','firstname','permanentemail') {
1112: $r->print('<td>'.$srch_results->{$user}->{$field}.'</td>');
1113: }
1114: $r->print(&Apache::loncommon::end_data_table_row());
1115: }
1116: $r->print(&Apache::loncommon::end_data_table().'<br /><br />');
1.179 raeburn 1117: if (ref($srcharray) eq 'ARRAY') {
1118: foreach my $item (@{$srcharray}) {
1119: $r->print('<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n");
1120: }
1121: }
1.160 raeburn 1122: $r->print(' <input type="hidden" name="sortby" value="'.$sortby.'" />'."\n".
1123: ' <input type="hidden" name="seluname" value="" />'."\n".
1124: ' <input type="hidden" name="seludom" value="" />'."\n".
1.179 raeburn 1125: ' <input type="hidden" name="currstate" value="select" />'."\n".
1.190 raeburn 1126: ' <input type="hidden" name="phase" value="get_user_info" />'."\n".
1.214 raeburn 1127: ' <input type="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n");
1.302 raeburn 1128: if ($context eq 'requestcrs') {
1129: $r->print($opener_elements.'</form></div>');
1130: } else {
1.351 raeburn 1131: $r->print($response.'</form>');
1.302 raeburn 1132: }
1.160 raeburn 1133: }
1134:
1135: sub print_user_query_page {
1.351 raeburn 1136: my ($r,$caller,$brcrum) = @_;
1.160 raeburn 1137: # FIXME - this is for a network-wide name search (similar to catalog search)
1138: # To use frames with similar behavior to catalog/portfolio search.
1139: # To be implemented.
1140: return;
1141: }
1142:
1.42 matthew 1143: sub print_user_modification_page {
1.375 raeburn 1144: my ($r,$ccuname,$ccdomain,$srch,$response,$context,$permission,$crstype,
1145: $brcrum,$showcredits) = @_;
1.185 raeburn 1146: if (($ccuname eq '') || ($ccdomain eq '')) {
1.215 raeburn 1147: my $usermsg = &mt('No username and/or domain provided.');
1148: $env{'form.phase'} = '';
1.406.2.14 raeburn 1149: &print_username_entry_form($r,$context,$usermsg,'','',$crstype,$brcrum,
1150: $permission);
1.58 www 1151: return;
1152: }
1.213 raeburn 1153: my ($form,$formname);
1154: if ($env{'form.action'} eq 'singlestudent') {
1155: $form = 'document.enrollstudent';
1156: $formname = 'enrollstudent';
1157: } else {
1158: $form = 'document.cu';
1159: $formname = 'cu';
1160: }
1.188 raeburn 1161: my %abv_auth = &auth_abbrev();
1.227 raeburn 1162: my (%rulematch,%inst_results,$newuser,%alerts,%curr_rules,%got_rules);
1.185 raeburn 1163: my $uhome=&Apache::lonnet::homeserver($ccuname,$ccdomain);
1164: if ($uhome eq 'no_host') {
1.215 raeburn 1165: my $usertype;
1166: my ($rules,$ruleorder) =
1167: &Apache::lonnet::inst_userrules($ccdomain,'username');
1168: $usertype =
1.353 raeburn 1169: &Apache::lonuserutils::check_usertype($ccdomain,$ccuname,$rules,
1.362 raeburn 1170: \%curr_rules,\%got_rules);
1.215 raeburn 1171: my $cancreate =
1172: &Apache::lonuserutils::can_create_user($ccdomain,$context,
1173: $usertype);
1174: if (!$cancreate) {
1.292 bisitz 1175: my $helplink = 'javascript:helpMenu('."'display'".')';
1.215 raeburn 1176: my %usertypetext = (
1177: official => 'institutional',
1178: unofficial => 'non-institutional',
1179: );
1180: my $response;
1181: if ($env{'form.origform'} eq 'crtusername') {
1.362 raeburn 1182: $response = '<span class="LC_warning">'.
1183: &mt('No match found for the username [_1] in LON-CAPA domain: [_2]',
1184: '<b>'.$ccuname.'</b>',$ccdomain).
1.215 raeburn 1185: '</span><br />';
1186: }
1.292 bisitz 1187: $response .= '<p class="LC_warning">'
1188: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
1.406.2.6 raeburn 1189: .' ';
1190: if ($context eq 'domain') {
1191: $response .= &mt('Please contact a [_1] for assistance.',
1192: &Apache::lonnet::plaintext('dc'));
1193: } else {
1194: $response .= &mt('Please contact the [_1]helpdesk[_2] for assistance.'
1195: ,'<a href="'.$helplink.'">','</a>');
1196: }
1197: $response .= '</p><br />';
1.215 raeburn 1198: $env{'form.phase'} = '';
1.406.2.14 raeburn 1199: &print_username_entry_form($r,$context,$response,undef,undef,$crstype,$brcrum,
1200: $permission);
1.215 raeburn 1201: return;
1202: }
1.188 raeburn 1203: $newuser = 1;
1.193 raeburn 1204: my $checkhash;
1205: my $checks = { 'username' => 1 };
1.196 raeburn 1206: $checkhash->{$ccuname.':'.$ccdomain} = { 'newuser' => $newuser };
1.193 raeburn 1207: &Apache::loncommon::user_rule_check($checkhash,$checks,
1.196 raeburn 1208: \%alerts,\%rulematch,\%inst_results,\%curr_rules,\%got_rules);
1209: if (ref($alerts{'username'}) eq 'HASH') {
1210: if (ref($alerts{'username'}{$ccdomain}) eq 'HASH') {
1211: my $domdesc =
1.193 raeburn 1212: &Apache::lonnet::domain($ccdomain,'description');
1.196 raeburn 1213: if ($alerts{'username'}{$ccdomain}{$ccuname}) {
1214: my $userchkmsg;
1215: if (ref($curr_rules{$ccdomain}) eq 'HASH') {
1216: $userchkmsg =
1217: &Apache::loncommon::instrule_disallow_msg('username',
1.193 raeburn 1218: $domdesc,1).
1219: &Apache::loncommon::user_rule_formats($ccdomain,
1220: $domdesc,$curr_rules{$ccdomain}{'username'},
1221: 'username');
1.196 raeburn 1222: }
1.215 raeburn 1223: $env{'form.phase'} = '';
1.406.2.14 raeburn 1224: &print_username_entry_form($r,$context,$userchkmsg,undef,undef,$crstype,$brcrum,
1225: $permission);
1.196 raeburn 1226: return;
1.215 raeburn 1227: }
1.193 raeburn 1228: }
1.185 raeburn 1229: }
1.187 raeburn 1230: } else {
1.188 raeburn 1231: $newuser = 0;
1.185 raeburn 1232: }
1.160 raeburn 1233: if ($response) {
1.215 raeburn 1234: $response = '<br />'.$response;
1.160 raeburn 1235: }
1.149 raeburn 1236:
1.52 matthew 1237: my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
1.88 raeburn 1238: my $dc_setcourse_code = '';
1.119 raeburn 1239: my $nondc_setsection_code = '';
1.112 albertel 1240: my %loaditem;
1.114 albertel 1241:
1.216 raeburn 1242: my $groupslist = &Apache::lonuserutils::get_groupslist();
1.88 raeburn 1243:
1.375 raeburn 1244: my $js = &validation_javascript($context,$ccdomain,$pjump_def,$crstype,
1.216 raeburn 1245: $groupslist,$newuser,$formname,\%loaditem);
1.406.2.7 raeburn 1246: my %breadcrumb_text = &singleuser_breadcrumb($crstype,$context,$ccdomain);
1.224 raeburn 1247: my $helpitem = 'Course_Change_Privileges';
1248: if ($env{'form.action'} eq 'singlestudent') {
1249: $helpitem = 'Course_Add_Student';
1.406.2.14 raeburn 1250: } elsif ($context eq 'author') {
1251: $helpitem = 'Author_Change_Privileges';
1252: } elsif ($context eq 'domain') {
1253: $helpitem = 'Domain_Change_Privileges';
1.224 raeburn 1254: }
1.351 raeburn 1255: push (@{$brcrum},
1256: {href => "javascript:backPage($form)",
1257: text => $breadcrumb_text{'search'},
1258: faq => 282,
1259: bug => 'Instructor Interface',});
1260: if ($env{'form.phase'} eq 'userpicked') {
1261: push(@{$brcrum},
1262: {href => "javascript:backPage($form,'get_user_info','select')",
1263: text => $breadcrumb_text{'userpicked'},
1264: faq => 282,
1265: bug => 'Instructor Interface',});
1266: }
1267: push(@{$brcrum},
1268: {href => "javascript:backPage($form,'$env{'form.phase'}','modify')",
1269: text => $breadcrumb_text{'modify'},
1270: faq => 282,
1271: bug => 'Instructor Interface',
1272: help => $helpitem});
1273: my $args = {'add_entries' => \%loaditem,
1274: 'bread_crumbs' => $brcrum,
1275: 'bread_crumbs_component' => 'User Management'};
1276: if ($env{'form.popup'}) {
1277: $args->{'no_nav_bar'} = 1;
1278: }
1279: my $start_page =
1280: &Apache::loncommon::start_page('User Management',$js,$args);
1.3 www 1281:
1.25 matthew 1282: my $forminfo =<<"ENDFORMINFO";
1.216 raeburn 1283: <form action="/adm/createuser" method="post" name="$formname">
1.190 raeburn 1284: <input type="hidden" name="phase" value="update_user_data" />
1.188 raeburn 1285: <input type="hidden" name="ccuname" value="$ccuname" />
1286: <input type="hidden" name="ccdomain" value="$ccdomain" />
1.157 albertel 1287: <input type="hidden" name="pres_value" value="" />
1288: <input type="hidden" name="pres_type" value="" />
1289: <input type="hidden" name="pres_marker" value="" />
1.25 matthew 1290: ENDFORMINFO
1.375 raeburn 1291: my (%inccourses,$roledom,$defaultcredits);
1.329 raeburn 1292: if ($context eq 'course') {
1293: $inccourses{$env{'request.course.id'}}=1;
1294: $roledom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1.375 raeburn 1295: if ($showcredits) {
1296: $defaultcredits = &Apache::lonuserutils::get_defaultcredits();
1297: }
1.329 raeburn 1298: } elsif ($context eq 'author') {
1299: $roledom = $env{'request.role.domain'};
1300: } elsif ($context eq 'domain') {
1301: foreach my $key (keys(%env)) {
1302: $roledom = $env{'request.role.domain'};
1303: if ($key=~/^user\.priv\.cm\.\/($roledom)\/($match_username)/) {
1304: $inccourses{$1.'_'.$2}=1;
1305: }
1306: }
1307: } else {
1308: foreach my $key (keys(%env)) {
1309: if ($key=~/^user\.priv\.cm\.\/($match_domain)\/($match_username)/) {
1310: $inccourses{$1.'_'.$2}=1;
1311: }
1.2 www 1312: }
1.24 matthew 1313: }
1.389 bisitz 1314: my $title = '';
1.216 raeburn 1315: if ($newuser) {
1.406.2.9 raeburn 1316: my ($portfolioform,$domroleform);
1.267 raeburn 1317: if ((&Apache::lonnet::allowed('mpq',$env{'request.role.domain'})) ||
1318: (&Apache::lonnet::allowed('mut',$env{'request.role.domain'}))) {
1319: # Current user has quota or user tools modification privileges
1.378 raeburn 1320: $portfolioform = '<br />'.&user_quotas($ccuname,$ccdomain);
1.134 raeburn 1321: }
1.383 raeburn 1322: if ((&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) &&
1323: ($ccdomain eq $env{'request.role.domain'})) {
1.362 raeburn 1324: $domroleform = '<br />'.&domainrole_req($ccuname,$ccdomain);
1325: }
1.227 raeburn 1326: &initialize_authen_forms($ccdomain,$formname);
1.188 raeburn 1327: my %lt=&Apache::lonlocal::texthash(
1328: 'lg' => 'Login Data',
1.190 raeburn 1329: 'hs' => "Home Server",
1.188 raeburn 1330: );
1.185 raeburn 1331: $r->print(<<ENDTITLE);
1.110 albertel 1332: $start_page
1.160 raeburn 1333: $response
1.25 matthew 1334: $forminfo
1.31 matthew 1335: <script type="text/javascript" language="Javascript">
1.301 bisitz 1336: // <![CDATA[
1.20 harris41 1337: $loginscript
1.301 bisitz 1338: // ]]>
1.31 matthew 1339: </script>
1.20 harris41 1340: <input type='hidden' name='makeuser' value='1' />
1.185 raeburn 1341: ENDTITLE
1.213 raeburn 1342: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1343: if ($crstype eq 'Community') {
1.389 bisitz 1344: $title = &mt('Create New User [_1] in domain [_2] as a member',
1345: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.318 raeburn 1346: } else {
1.389 bisitz 1347: $title = &mt('Create New User [_1] in domain [_2] as a student',
1348: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.318 raeburn 1349: }
1.389 bisitz 1350: } else {
1351: $title = &mt('Create New User [_1] in domain [_2]',
1352: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.213 raeburn 1353: }
1.389 bisitz 1354: $r->print('<h2>'.$title.'</h2>'."\n");
1355: $r->print('<div class="LC_left_float">');
1.393 raeburn 1356: $r->print(&personal_data_display($ccuname,$ccdomain,$newuser,$context,
1357: $inst_results{$ccuname.':'.$ccdomain}));
1358: # Option to disable student/employee ID conflict checking not offerred for new users.
1.187 raeburn 1359: my ($home_server_pick,$numlib) =
1360: &Apache::loncommon::home_server_form_item($ccdomain,'hserver',
1361: 'default','hide');
1362: if ($numlib > 1) {
1363: $r->print("
1.185 raeburn 1364: <br />
1.187 raeburn 1365: $lt{'hs'}: $home_server_pick
1366: <br />");
1367: } else {
1368: $r->print($home_server_pick);
1369: }
1.304 raeburn 1370: if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
1.362 raeburn 1371: $r->print('<br /><h3>'.
1372: &mt('User Can Request Creation of Courses/Communities in this Domain?').'</h3>'.
1.304 raeburn 1373: &Apache::loncommon::start_data_table().
1374: &build_tools_display($ccuname,$ccdomain,
1375: 'requestcourses').
1376: &Apache::loncommon::end_data_table());
1377: }
1.188 raeburn 1378: $r->print('</div>'."\n".'<div class="LC_left_float"><h3>'.
1379: $lt{'lg'}.'</h3>');
1.185 raeburn 1380: my ($fixedauth,$varauth,$authmsg);
1.193 raeburn 1381: if (ref($rulematch{$ccuname.':'.$ccdomain}) eq 'HASH') {
1382: my $matchedrule = $rulematch{$ccuname.':'.$ccdomain}{'username'};
1383: my ($rules,$ruleorder) =
1384: &Apache::lonnet::inst_userrules($ccdomain,'username');
1.185 raeburn 1385: if (ref($rules) eq 'HASH') {
1.193 raeburn 1386: if (ref($rules->{$matchedrule}) eq 'HASH') {
1387: my $authtype = $rules->{$matchedrule}{'authtype'};
1.185 raeburn 1388: if ($authtype !~ /^(krb4|krb5|int|fsys|loc)$/) {
1.190 raeburn 1389: $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1.275 raeburn 1390: } else {
1.193 raeburn 1391: my $authparm = $rules->{$matchedrule}{'authparm'};
1.273 raeburn 1392: $authmsg = $rules->{$matchedrule}{'authmsg'};
1.185 raeburn 1393: if ($authtype =~ /^krb(4|5)$/) {
1394: my $ver = $1;
1395: if ($authparm ne '') {
1396: $fixedauth = <<"KERB";
1397: <input type="hidden" name="login" value="krb" />
1398: <input type="hidden" name="krbver" value="$ver" />
1399: <input type="hidden" name="krbarg" value="$authparm" />
1400: KERB
1401: }
1402: } else {
1403: $fixedauth =
1404: '<input type="hidden" name="login" value="'.$authtype.'" />'."\n";
1.193 raeburn 1405: if ($rules->{$matchedrule}{'authparmfixed'}) {
1.185 raeburn 1406: $fixedauth .=
1407: '<input type="hidden" name="'.$authtype.'arg" value="'.$authparm.'" />'."\n";
1408: } else {
1.273 raeburn 1409: if ($authtype eq 'int') {
1410: $varauth = '<br />'.
1.301 bisitz 1411: &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 1412: } elsif ($authtype eq 'loc') {
1413: $varauth = '<br />'.
1414: &mt('[_1] Local Authentication with argument [_2]','','<input type="text" name="'.$authtype.'arg" value="" />')."\n";
1415: } else {
1416: $varauth =
1.185 raeburn 1417: '<input type="text" name="'.$authtype.'arg" value="" />'."\n";
1.273 raeburn 1418: }
1.185 raeburn 1419: }
1420: }
1421: }
1422: } else {
1.190 raeburn 1423: $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1.185 raeburn 1424: }
1425: }
1426: if ($authmsg) {
1427: $r->print(<<ENDAUTH);
1428: $fixedauth
1429: $authmsg
1430: $varauth
1431: ENDAUTH
1432: }
1433: } else {
1.190 raeburn 1434: $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1.187 raeburn 1435: }
1.406.2.9 raeburn 1436: $r->print($portfolioform.$domroleform);
1.215 raeburn 1437: if ($env{'form.action'} eq 'singlestudent') {
1438: $r->print(&date_sections_select($context,$newuser,$formname,
1.375 raeburn 1439: $permission,$crstype,$ccuname,
1440: $ccdomain,$showcredits));
1.215 raeburn 1441: }
1442: $r->print('</div><div class="LC_clear_float_footer"></div>');
1.216 raeburn 1443: } else { # user already exists
1.389 bisitz 1444: $r->print($start_page.$forminfo);
1.213 raeburn 1445: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1446: if ($crstype eq 'Community') {
1.389 bisitz 1447: $title = &mt('Enroll one member: [_1] in domain [_2]',
1448: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.318 raeburn 1449: } else {
1.389 bisitz 1450: $title = &mt('Enroll one student: [_1] in domain [_2]',
1451: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.318 raeburn 1452: }
1.213 raeburn 1453: } else {
1.406.2.6 raeburn 1454: if ($permission->{'cusr'}) {
1455: $title = &mt('Modify existing user: [_1] in domain [_2]',
1456: '"'.$ccuname.'"','"'.$ccdomain.'"');
1457: } else {
1458: $title = &mt('Existing user: [_1] in domain [_2]',
1.389 bisitz 1459: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.406.2.6 raeburn 1460: }
1.213 raeburn 1461: }
1.389 bisitz 1462: $r->print('<h2>'.$title.'</h2>'."\n");
1463: $r->print('<div class="LC_left_float">');
1.393 raeburn 1464: $r->print(&personal_data_display($ccuname,$ccdomain,$newuser,$context,
1465: $inst_results{$ccuname.':'.$ccdomain}));
1.406.2.6 raeburn 1466: if ((&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) ||
1467: (&Apache::lonnet::allowed('udp',$env{'request.role.domain'}))) {
1.362 raeburn 1468: $r->print('<br /><h3>'.&mt('User Can Request Creation of Courses/Communities in this Domain?').'</h3>'.
1.300 raeburn 1469: &Apache::loncommon::start_data_table());
1.314 raeburn 1470: if ($env{'request.role.domain'} eq $ccdomain) {
1.300 raeburn 1471: $r->print(&build_tools_display($ccuname,$ccdomain,'requestcourses'));
1472: } else {
1473: $r->print(&coursereq_externaluser($ccuname,$ccdomain,
1474: $env{'request.role.domain'}));
1475: }
1476: $r->print(&Apache::loncommon::end_data_table());
1.275 raeburn 1477: }
1.199 raeburn 1478: $r->print('</div>');
1.406.2.9 raeburn 1479: my @order = ('auth','quota','tools','requestauthor');
1.362 raeburn 1480: my %user_text;
1481: my ($isadv,$isauthor) =
1.406.2.6 raeburn 1482: &Apache::lonnet::is_advanced_user($ccdomain,$ccuname);
1.362 raeburn 1483: if ((!$isauthor) &&
1.406.2.6 raeburn 1484: ((&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) ||
1485: (&Apache::lonnet::allowed('udp',$env{'request.role.domain'}))) &&
1486: ($env{'request.role.domain'} eq $ccdomain)) {
1.362 raeburn 1487: $user_text{'requestauthor'} = &domainrole_req($ccuname,$ccdomain);
1488: }
1489: $user_text{'auth'} = &user_authentication($ccuname,$ccdomain,$formname);
1.267 raeburn 1490: if ((&Apache::lonnet::allowed('mpq',$ccdomain)) ||
1.406.2.6 raeburn 1491: (&Apache::lonnet::allowed('mut',$ccdomain)) ||
1492: (&Apache::lonnet::allowed('udp',$ccdomain))) {
1.188 raeburn 1493: # Current user has quota modification privileges
1.378 raeburn 1494: $user_text{'quota'} = &user_quotas($ccuname,$ccdomain);
1.267 raeburn 1495: }
1496: if (!&Apache::lonnet::allowed('mpq',$ccdomain)) {
1497: if (&Apache::lonnet::allowed('mpq',$env{'request.role.domain'})) {
1498: my %lt=&Apache::lonlocal::texthash(
1.385 bisitz 1499: 'dska' => "Disk quotas for user's portfolio and Authoring Space",
1500: 'youd' => "You do not have privileges to modify the portfolio and/or Authoring Space quotas for this user.",
1.267 raeburn 1501: 'ichr' => "If a change is required, contact a domain coordinator for the domain",
1502: );
1.362 raeburn 1503: $user_text{'quota'} = <<ENDNOPORTPRIV;
1.188 raeburn 1504: <h3>$lt{'dska'}</h3>
1505: $lt{'youd'} $lt{'ichr'}: $ccdomain
1506: ENDNOPORTPRIV
1.267 raeburn 1507: }
1508: }
1509: if (!&Apache::lonnet::allowed('mut',$ccdomain)) {
1510: if (&Apache::lonnet::allowed('mut',$env{'request.role.domain'})) {
1511: my %lt=&Apache::lonlocal::texthash(
1512: 'utav' => "User Tools Availability",
1.361 raeburn 1513: 'yodo' => "You do not have privileges to modify Portfolio, Blog, WebDAV, or Personal Information Page settings for this user.",
1.267 raeburn 1514: 'ifch' => "If a change is required, contact a domain coordinator for the domain",
1515: );
1.362 raeburn 1516: $user_text{'tools'} = <<ENDNOTOOLSPRIV;
1.267 raeburn 1517: <h3>$lt{'utav'}</h3>
1518: $lt{'yodo'} $lt{'ifch'}: $ccdomain
1519: ENDNOTOOLSPRIV
1520: }
1.188 raeburn 1521: }
1.362 raeburn 1522: my $gotdiv = 0;
1523: foreach my $item (@order) {
1524: if ($user_text{$item} ne '') {
1525: unless ($gotdiv) {
1526: $r->print('<div class="LC_left_float">');
1527: $gotdiv = 1;
1528: }
1529: $r->print('<br />'.$user_text{$item});
1530: }
1531: }
1532: if ($env{'form.action'} eq 'singlestudent') {
1533: unless ($gotdiv) {
1534: $r->print('<div class="LC_left_float">');
1.213 raeburn 1535: }
1.375 raeburn 1536: my $credits;
1537: if ($showcredits) {
1538: $credits = &get_user_credits($ccuname,$ccdomain,$defaultcredits);
1539: if ($credits eq '') {
1540: $credits = $defaultcredits;
1541: }
1542: }
1.374 raeburn 1543: $r->print(&date_sections_select($context,$newuser,$formname,
1.375 raeburn 1544: $permission,$crstype,$ccuname,
1545: $ccdomain,$showcredits));
1.374 raeburn 1546: }
1.362 raeburn 1547: if ($gotdiv) {
1548: $r->print('</div><div class="LC_clear_float_footer"></div>');
1.188 raeburn 1549: }
1.406.2.6 raeburn 1550: my $statuses;
1551: if (($context eq 'domain') && (&Apache::lonnet::allowed('udp',$ccdomain)) &&
1552: (!&Apache::lonnet::allowed('mau',$ccdomain))) {
1553: $statuses = ['active'];
1554: } elsif (($context eq 'course') && ((&Apache::lonnet::allowed('vcl',$env{'request.course.id'})) ||
1555: ($env{'request.course.sec'} &&
1556: &Apache::lonnet::allowed('vcl',$env{'request.course.id'}.'/'.$env{'request.course.sec'})))) {
1557: $statuses = ['active'];
1558: }
1.217 raeburn 1559: if ($env{'form.action'} ne 'singlestudent') {
1.329 raeburn 1560: &display_existing_roles($r,$ccuname,$ccdomain,\%inccourses,$context,
1.406.2.6 raeburn 1561: $roledom,$crstype,$showcredits,$statuses);
1.217 raeburn 1562: }
1.25 matthew 1563: } ## End of new user/old user logic
1.218 raeburn 1564: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1565: my $btntxt;
1566: if ($crstype eq 'Community') {
1567: $btntxt = &mt('Enroll Member');
1568: } else {
1569: $btntxt = &mt('Enroll Student');
1570: }
1571: $r->print('<br /><input type="button" value="'.$btntxt.'" onclick="setSections(this.form)" />'."\n");
1.406.2.6 raeburn 1572: } elsif ($permission->{'cusr'}) {
1.393 raeburn 1573: $r->print('<div class="LC_left_float">'.
1574: '<fieldset><legend>'.&mt('Add Roles').'</legend>');
1.218 raeburn 1575: my $addrolesdisplay = 0;
1576: if ($context eq 'domain' || $context eq 'author') {
1577: $addrolesdisplay = &new_coauthor_roles($r,$ccuname,$ccdomain);
1578: }
1579: if ($context eq 'domain') {
1.357 raeburn 1580: my $add_domainroles = &new_domain_roles($r,$ccdomain);
1.218 raeburn 1581: if (!$addrolesdisplay) {
1582: $addrolesdisplay = $add_domainroles;
1.2 www 1583: }
1.375 raeburn 1584: $r->print(&course_level_dc($env{'request.role.domain'},$showcredits));
1.393 raeburn 1585: $r->print('</fieldset></div><div class="LC_clear_float_footer"></div>'.
1586: '<br /><input type="button" value="'.&mt('Save').'" onclick="setCourse()" />'."\n");
1.218 raeburn 1587: } elsif ($context eq 'author') {
1588: if ($addrolesdisplay) {
1.393 raeburn 1589: $r->print('</fieldset></div><div class="LC_clear_float_footer"></div>'.
1590: '<br /><input type="button" value="'.&mt('Save').'"');
1.218 raeburn 1591: if ($newuser) {
1.301 bisitz 1592: $r->print(' onclick="auth_check()" \>'."\n");
1.218 raeburn 1593: } else {
1.301 bisitz 1594: $r->print('onclick="this.form.submit()" \>'."\n");
1.218 raeburn 1595: }
1.188 raeburn 1596: } else {
1.393 raeburn 1597: $r->print('</fieldset></div>'.
1598: '<div class="LC_clear_float_footer"></div>'.
1599: '<br /><a href="javascript:backPage(document.cu)">'.
1.218 raeburn 1600: &mt('Back to previous page').'</a>');
1.188 raeburn 1601: }
1602: } else {
1.375 raeburn 1603: $r->print(&course_level_table(\%inccourses,$showcredits,$defaultcredits));
1.393 raeburn 1604: $r->print('</fieldset></div><div class="LC_clear_float_footer"></div>'.
1605: '<br /><input type="button" value="'.&mt('Save').'" onclick="setSections(this.form)" />'."\n");
1.188 raeburn 1606: }
1.88 raeburn 1607: }
1.188 raeburn 1608: $r->print(&Apache::lonhtmlcommon::echo_form_input(['phase','userrole','ccdomain','prevphase','currstate','ccuname','ccdomain']));
1.179 raeburn 1609: $r->print('<input type="hidden" name="currstate" value="" />');
1.393 raeburn 1610: $r->print('<input type="hidden" name="prevphase" value="'.$env{'form.phase'}.'" /></form><br /><br />');
1.218 raeburn 1611: return;
1.2 www 1612: }
1.1 www 1613:
1.213 raeburn 1614: sub singleuser_breadcrumb {
1.406.2.7 raeburn 1615: my ($crstype,$context,$domain) = @_;
1.213 raeburn 1616: my %breadcrumb_text;
1617: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1618: if ($crstype eq 'Community') {
1619: $breadcrumb_text{'search'} = 'Enroll a member';
1620: } else {
1621: $breadcrumb_text{'search'} = 'Enroll a student';
1622: }
1.406.2.7 raeburn 1623: $breadcrumb_text{'userpicked'} = 'Select a user';
1624: $breadcrumb_text{'modify'} = 'Set section/dates';
1.406.2.5 raeburn 1625: } elsif ($env{'form.action'} eq 'accesslogs') {
1626: $breadcrumb_text{'search'} = 'View access logs for a user';
1.406.2.7 raeburn 1627: $breadcrumb_text{'userpicked'} = 'Select a user';
1628: $breadcrumb_text{'activity'} = 'Activity';
1629: } elsif (($env{'form.action'} eq 'singleuser') && ($context eq 'domain') &&
1630: (!&Apache::lonnet::allowed('mau',$domain))) {
1631: $breadcrumb_text{'search'} = "View user's roles";
1632: $breadcrumb_text{'userpicked'} = 'Select a user';
1633: $breadcrumb_text{'modify'} = 'User roles';
1.213 raeburn 1634: } else {
1.229 raeburn 1635: $breadcrumb_text{'search'} = 'Create/modify a user';
1.406.2.7 raeburn 1636: $breadcrumb_text{'userpicked'} = 'Select a user';
1637: $breadcrumb_text{'modify'} = 'Set user role';
1.213 raeburn 1638: }
1639: return %breadcrumb_text;
1640: }
1641:
1642: sub date_sections_select {
1.375 raeburn 1643: my ($context,$newuser,$formname,$permission,$crstype,$ccuname,$ccdomain,
1644: $showcredits) = @_;
1645: my $credits;
1646: if ($showcredits) {
1647: my $defaultcredits = &Apache::lonuserutils::get_defaultcredits();
1648: $credits = &get_user_credits($ccuname,$ccdomain,$defaultcredits);
1649: if ($credits eq '') {
1650: $credits = $defaultcredits;
1651: }
1652: }
1.213 raeburn 1653: my $cid = $env{'request.course.id'};
1654: my ($cnum,$cdom) = &Apache::lonuserutils::get_course_identity($cid);
1655: my $date_table = '<h3>'.&mt('Starting and Ending Dates').'</h3>'."\n".
1656: &Apache::lonuserutils::date_setting_table(undef,undef,$context,
1657: undef,$formname,$permission);
1658: my $rowtitle = 'Section';
1.375 raeburn 1659: my $secbox = '<h3>'.&mt('Section and Credits').'</h3>'."\n".
1.213 raeburn 1660: &Apache::lonuserutils::section_picker($cdom,$cnum,'st',$rowtitle,
1.375 raeburn 1661: $permission,$context,'',$crstype,
1662: $showcredits,$credits);
1.213 raeburn 1663: my $output = $date_table.$secbox;
1664: return $output;
1665: }
1666:
1.216 raeburn 1667: sub validation_javascript {
1.375 raeburn 1668: my ($context,$ccdomain,$pjump_def,$crstype,$groupslist,$newuser,$formname,
1.216 raeburn 1669: $loaditem) = @_;
1670: my $dc_setcourse_code = '';
1671: my $nondc_setsection_code = '';
1672: if ($context eq 'domain') {
1673: my $dcdom = $env{'request.role.domain'};
1674: $loaditem->{'onload'} = "document.cu.coursedesc.value='';";
1.227 raeburn 1675: $dc_setcourse_code =
1676: &Apache::lonuserutils::dc_setcourse_js('cu','singleuser',$context);
1.216 raeburn 1677: } else {
1.227 raeburn 1678: my $checkauth;
1679: if (($newuser) || (&Apache::lonnet::allowed('mau',$ccdomain))) {
1680: $checkauth = 1;
1681: }
1682: if ($context eq 'course') {
1683: $nondc_setsection_code =
1684: &Apache::lonuserutils::setsections_javascript($formname,$groupslist,
1.375 raeburn 1685: undef,$checkauth,
1686: $crstype);
1.227 raeburn 1687: }
1688: if ($checkauth) {
1689: $nondc_setsection_code .=
1690: &Apache::lonuserutils::verify_authen($formname,$context);
1691: }
1.216 raeburn 1692: }
1693: my $js = &user_modification_js($pjump_def,$dc_setcourse_code,
1694: $nondc_setsection_code,$groupslist);
1695: my ($jsback,$elements) = &crumb_utilities();
1696: $js .= "\n".
1.301 bisitz 1697: '<script type="text/javascript">'."\n".
1698: '// <![CDATA['."\n".
1699: $jsback."\n".
1700: '// ]]>'."\n".
1701: '</script>'."\n";
1.216 raeburn 1702: return $js;
1703: }
1704:
1.217 raeburn 1705: sub display_existing_roles {
1.375 raeburn 1706: my ($r,$ccuname,$ccdomain,$inccourses,$context,$roledom,$crstype,
1.406.2.6 raeburn 1707: $showcredits,$statuses) = @_;
1.329 raeburn 1708: my $now=time;
1.406.2.6 raeburn 1709: my $showall = 1;
1710: my ($showexpired,$showactive);
1711: if ((ref($statuses) eq 'ARRAY') && (@{$statuses} > 0)) {
1712: $showall = 0;
1713: if (grep(/^expired$/,@{$statuses})) {
1714: $showexpired = 1;
1715: }
1716: if (grep(/^active$/,@{$statuses})) {
1717: $showactive = 1;
1718: }
1719: if ($showexpired && $showactive) {
1720: $showall = 1;
1721: }
1722: }
1.329 raeburn 1723: my %lt=&Apache::lonlocal::texthash(
1.217 raeburn 1724: 'rer' => "Existing Roles",
1725: 'rev' => "Revoke",
1726: 'del' => "Delete",
1727: 'ren' => "Re-Enable",
1728: 'rol' => "Role",
1729: 'ext' => "Extent",
1.375 raeburn 1730: 'crd' => "Credits",
1.217 raeburn 1731: 'sta' => "Start",
1732: 'end' => "End",
1733: );
1.329 raeburn 1734: my (%rolesdump,%roletext,%sortrole,%roleclass,%rolepriv);
1735: if ($context eq 'course' || $context eq 'author') {
1736: my @roles = &Apache::lonuserutils::roles_by_context($context,1,$crstype);
1737: my %roleshash =
1738: &Apache::lonnet::get_my_roles($ccuname,$ccdomain,'userroles',
1739: ['active','previous','future'],\@roles,$roledom,1);
1740: foreach my $key (keys(%roleshash)) {
1741: my ($start,$end) = split(':',$roleshash{$key});
1742: next if ($start eq '-1' || $end eq '-1');
1743: my ($rnum,$rdom,$role,$sec) = split(':',$key);
1744: if ($context eq 'course') {
1745: next unless (($rnum eq $env{'course.'.$env{'request.course.id'}.'.num'})
1746: && ($rdom eq $env{'course.'.$env{'request.course.id'}.'.domain'}));
1747: } elsif ($context eq 'author') {
1748: next unless (($rnum eq $env{'user.name'}) && ($rdom eq $env{'request.role.domain'}));
1749: }
1750: my ($newkey,$newvalue,$newrole);
1751: $newkey = '/'.$rdom.'/'.$rnum;
1752: if ($sec ne '') {
1753: $newkey .= '/'.$sec;
1754: }
1755: $newvalue = $role;
1756: if ($role =~ /^cr/) {
1757: $newrole = 'cr';
1758: } else {
1759: $newrole = $role;
1760: }
1761: $newkey .= '_'.$newrole;
1762: if ($start ne '' && $end ne '') {
1763: $newvalue .= '_'.$end.'_'.$start;
1.335 raeburn 1764: } elsif ($end ne '') {
1765: $newvalue .= '_'.$end;
1.329 raeburn 1766: }
1767: $rolesdump{$newkey} = $newvalue;
1768: }
1769: } else {
1.360 raeburn 1770: %rolesdump=&Apache::lonnet::dump('roles',$ccdomain,$ccuname);
1.329 raeburn 1771: }
1772: # Build up table of user roles to allow revocation and re-enabling of roles.
1773: my ($tmp) = keys(%rolesdump);
1774: return if ($tmp =~ /^(con_lost|error)/i);
1775: foreach my $area (sort { my $a1=join('_',(split('_',$a))[1,0]);
1776: my $b1=join('_',(split('_',$b))[1,0]);
1777: return $a1 cmp $b1;
1778: } keys(%rolesdump)) {
1779: next if ($area =~ /^rolesdef/);
1780: my $envkey=$area;
1781: my $role = $rolesdump{$area};
1782: my $thisrole=$area;
1783: $area =~ s/\_\w\w$//;
1784: my ($role_code,$role_end_time,$role_start_time) =
1785: split(/_/,$role);
1.406.2.6 raeburn 1786: my $active=1;
1787: $active=0 if (($role_end_time) && ($now>$role_end_time));
1788: if ($active) {
1789: next unless($showall || $showactive);
1790: } else {
1791: next unless($showall || $showexpired);
1792: }
1.217 raeburn 1793: # Is this a custom role? Get role owner and title.
1.329 raeburn 1794: my ($croleudom,$croleuname,$croletitle)=
1795: ($role_code=~m{^cr/($match_domain)/($match_username)/(\w+)$});
1796: my $allowed=0;
1797: my $delallowed=0;
1798: my $sortkey=$role_code;
1799: my $class='Unknown';
1.375 raeburn 1800: my $credits='';
1.406.2.6 raeburn 1801: my $csec;
1.406.2.7 raeburn 1802: if ($area =~ m{^/($match_domain)/($match_courseid)}) {
1.329 raeburn 1803: $class='Course';
1804: my ($coursedom,$coursedir) = ($1,$2);
1805: my $cid = $1.'_'.$2;
1806: # $1.'_'.$2 is the course id (eg. 103_12345abcef103l3).
1.406.2.7 raeburn 1807: next if ($envkey =~ m{^/$match_domain/$match_courseid/[A-Za-z0-9]+_gr$});
1.329 raeburn 1808: my %coursedata=
1809: &Apache::lonnet::coursedescription($cid);
1810: if ($coursedir =~ /^$match_community$/) {
1811: $class='Community';
1812: }
1813: $sortkey.="\0$coursedom";
1814: my $carea;
1815: if (defined($coursedata{'description'})) {
1816: $carea=$coursedata{'description'}.
1817: '<br />'.&mt('Domain').': '.$coursedom.(' 'x8).
1818: &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$coursedir,$coursedom);
1819: $sortkey.="\0".$coursedata{'description'};
1820: } else {
1821: if ($class eq 'Community') {
1822: $carea=&mt('Unavailable community').': '.$area;
1823: $sortkey.="\0".&mt('Unavailable community').': '.$area;
1.217 raeburn 1824: } else {
1825: $carea=&mt('Unavailable course').': '.$area;
1826: $sortkey.="\0".&mt('Unavailable course').': '.$area;
1827: }
1.329 raeburn 1828: }
1829: $sortkey.="\0$coursedir";
1830: $inccourses->{$cid}=1;
1.375 raeburn 1831: if (($showcredits) && ($class eq 'Course') && ($role_code eq 'st')) {
1832: my $defaultcredits = $coursedata{'internal.defaultcredits'};
1833: $credits =
1834: &get_user_credits($ccuname,$ccdomain,$defaultcredits,
1835: $coursedom,$coursedir);
1836: if ($credits eq '') {
1837: $credits = $defaultcredits;
1838: }
1839: }
1.329 raeburn 1840: if ((&Apache::lonnet::allowed('c'.$role_code,$coursedom.'/'.$coursedir)) ||
1841: (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) {
1842: $allowed=1;
1843: }
1844: unless ($allowed) {
1.365 raeburn 1845: my $isowner = &Apache::lonuserutils::is_courseowner($cid,$coursedata{'internal.courseowner'});
1.329 raeburn 1846: if ($isowner) {
1847: if (($role_code eq 'co') && ($class eq 'Community')) {
1848: $allowed = 1;
1849: } elsif (($role_code eq 'cc') && ($class eq 'Course')) {
1850: $allowed = 1;
1851: }
1.217 raeburn 1852: }
1.329 raeburn 1853: }
1854: if ((&Apache::lonnet::allowed('dro',$coursedom)) ||
1855: (&Apache::lonnet::allowed('dro',$ccdomain))) {
1856: $delallowed=1;
1857: }
1.217 raeburn 1858: # - custom role. Needs more info, too
1.329 raeburn 1859: if ($croletitle) {
1860: if (&Apache::lonnet::allowed('ccr',$coursedom.'/'.$coursedir)) {
1861: $allowed=1;
1862: $thisrole.='.'.$role_code;
1.217 raeburn 1863: }
1.329 raeburn 1864: }
1.406.2.6 raeburn 1865: if ($area=~m{^/($match_domain/$match_courseid/(\w+))}) {
1866: $csec = $2;
1867: $carea.='<br />'.&mt('Section: [_1]',$csec);
1868: $sortkey.="\0$csec";
1.329 raeburn 1869: if (!$allowed) {
1.406.2.6 raeburn 1870: if ($env{'request.course.sec'} eq $csec) {
1871: if (&Apache::lonnet::allowed('c'.$role_code,$1)) {
1.329 raeburn 1872: $allowed = 1;
1.217 raeburn 1873: }
1874: }
1875: }
1.329 raeburn 1876: }
1877: $area=$carea;
1878: } else {
1879: $sortkey.="\0".$area;
1880: # Determine if current user is able to revoke privileges
1881: if ($area=~m{^/($match_domain)/}) {
1882: if ((&Apache::lonnet::allowed('c'.$role_code,$1)) ||
1883: (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) {
1884: $allowed=1;
1.217 raeburn 1885: }
1.329 raeburn 1886: if (((&Apache::lonnet::allowed('dro',$1)) ||
1887: (&Apache::lonnet::allowed('dro',$ccdomain))) &&
1888: ($role_code ne 'dc')) {
1889: $delallowed=1;
1.217 raeburn 1890: }
1.329 raeburn 1891: } else {
1892: if (&Apache::lonnet::allowed('c'.$role_code,'/')) {
1.217 raeburn 1893: $allowed=1;
1894: }
1895: }
1.363 raeburn 1896: if ($role_code eq 'ca' || $role_code eq 'au' || $role_code eq 'aa') {
1.377 raeburn 1897: $class='Authoring Space';
1.329 raeburn 1898: } elsif ($role_code eq 'su') {
1899: $class='System';
1.217 raeburn 1900: } else {
1.329 raeburn 1901: $class='Domain';
1.217 raeburn 1902: }
1.329 raeburn 1903: }
1904: if (($role_code eq 'ca') || ($role_code eq 'aa')) {
1905: $area=~m{/($match_domain)/($match_username)};
1906: if (&Apache::lonuserutils::authorpriv($2,$1)) {
1907: $allowed=1;
1.217 raeburn 1908: } else {
1.329 raeburn 1909: $allowed=0;
1.217 raeburn 1910: }
1.329 raeburn 1911: }
1912: my $row = '';
1.406.2.6 raeburn 1913: if ($showall) {
1914: $row.= '<td>';
1915: if (($active) && ($allowed)) {
1916: $row.= '<input type="checkbox" name="rev:'.$thisrole.'" />';
1.217 raeburn 1917: } else {
1.406.2.6 raeburn 1918: if ($active) {
1919: $row.=' ';
1920: } else {
1921: $row.=&mt('expired or revoked');
1922: }
1.217 raeburn 1923: }
1.406.2.6 raeburn 1924: $row.='</td><td>';
1925: if ($allowed && !$active) {
1926: $row.= '<input type="checkbox" name="ren:'.$thisrole.'" />';
1927: } else {
1928: $row.=' ';
1929: }
1930: $row.='</td><td>';
1931: if ($delallowed) {
1932: $row.= '<input type="checkbox" name="del:'.$thisrole.'" />';
1933: } else {
1934: $row.=' ';
1935: }
1936: $row.= '</td>';
1.329 raeburn 1937: }
1938: my $plaintext='';
1939: if (!$croletitle) {
1.375 raeburn 1940: $plaintext=&Apache::lonnet::plaintext($role_code,$class);
1941: if (($showcredits) && ($credits ne '')) {
1942: $plaintext .= '<br/ ><span class="LC_nobreak">'.
1943: '<span class="LC_fontsize_small">'.
1944: &mt('Credits: [_1]',$credits).
1945: '</span></span>';
1946: }
1.329 raeburn 1947: } else {
1948: $plaintext=
1.395 bisitz 1949: &mt('Custom role [_1][_2]defined by [_3]',
1.346 bisitz 1950: '"'.$croletitle.'"',
1951: '<br />',
1952: $croleuname.':'.$croleudom);
1.329 raeburn 1953: }
1.406.2.6 raeburn 1954: $row.= '<td>'.$plaintext.'</td>'.
1955: '<td>'.$area.'</td>'.
1956: '<td>'.($role_start_time?&Apache::lonlocal::locallocaltime($role_start_time)
1957: : ' ' ).'</td>'.
1958: '<td>'.($role_end_time ?&Apache::lonlocal::locallocaltime($role_end_time)
1959: : ' ' ).'</td>';
1.329 raeburn 1960: $sortrole{$sortkey}=$envkey;
1961: $roletext{$envkey}=$row;
1962: $roleclass{$envkey}=$class;
1.406.2.6 raeburn 1963: if ($allowed) {
1964: $rolepriv{$envkey}='edit';
1965: } else {
1966: if ($context eq 'domain') {
1.406.2.7 raeburn 1967: if ((&Apache::lonnet::allowed('vur',$ccdomain)) &&
1968: ($envkey=~m{^/$ccdomain/})) {
1.406.2.6 raeburn 1969: $rolepriv{$envkey}='view';
1970: }
1971: } elsif ($context eq 'course') {
1972: if ((&Apache::lonnet::allowed('vcl',$env{'request.course.id'})) ||
1973: ($env{'request.course.sec'} && ($env{'request.course.sec'} eq $csec) &&
1974: &Apache::lonnet::allowed('vcl',$env{'request.course.id'}.'/'.$env{'request.course.sec'}))) {
1975: $rolepriv{$envkey}='view';
1976: }
1977: }
1978: }
1.329 raeburn 1979: } # end of foreach (table building loop)
1980:
1981: my $rolesdisplay = 0;
1982: my %output = ();
1.377 raeburn 1983: foreach my $type ('Authoring Space','Course','Community','Domain','System','Unknown') {
1.329 raeburn 1984: $output{$type} = '';
1985: foreach my $which (sort {uc($a) cmp uc($b)} (keys(%sortrole))) {
1986: if ( ($roleclass{$sortrole{$which}} =~ /^\Q$type\E/ ) && ($rolepriv{$sortrole{$which}}) ) {
1987: $output{$type}.=
1988: &Apache::loncommon::start_data_table_row().
1989: $roletext{$sortrole{$which}}.
1990: &Apache::loncommon::end_data_table_row();
1.217 raeburn 1991: }
1.329 raeburn 1992: }
1993: unless($output{$type} eq '') {
1994: $output{$type} = '<tr class="LC_info_row">'.
1995: "<td align='center' colspan='7'>".&mt($type)."</td></tr>".
1996: $output{$type};
1997: $rolesdisplay = 1;
1998: }
1999: }
2000: if ($rolesdisplay == 1) {
2001: my $contextrole='';
2002: if ($env{'request.course.id'}) {
2003: if (&Apache::loncommon::course_type() eq 'Community') {
2004: $contextrole = &mt('Existing Roles in this Community');
1.290 bisitz 2005: } else {
1.329 raeburn 2006: $contextrole = &mt('Existing Roles in this Course');
1.290 bisitz 2007: }
1.329 raeburn 2008: } elsif ($env{'request.role'} =~ /^au\./) {
1.377 raeburn 2009: $contextrole = &mt('Existing Co-Author Roles in your Authoring Space');
1.329 raeburn 2010: } else {
1.406.2.6 raeburn 2011: if ($showall) {
2012: $contextrole = &mt('Existing Roles in this Domain');
2013: } elsif ($showactive) {
2014: $contextrole = &mt('Unexpired Roles in this Domain');
2015: } elsif ($showexpired) {
2016: $contextrole = &mt('Expired or Revoked Roles in this Domain');
2017: }
1.329 raeburn 2018: }
1.393 raeburn 2019: $r->print('<div class="LC_left_float">'.
1.375 raeburn 2020: '<fieldset><legend>'.$contextrole.'</legend>'.
1.217 raeburn 2021: &Apache::loncommon::start_data_table("LC_createuser").
1.406.2.6 raeburn 2022: &Apache::loncommon::start_data_table_header_row());
2023: if ($showall) {
2024: $r->print(
2025: '<th>'.$lt{'rev'}.'</th><th>'.$lt{'ren'}.'</th><th>'.$lt{'del'}.'</th>'
2026: );
2027: } elsif ($showexpired) {
2028: $r->print('<th>'.$lt{'rev'}.'</th>');
2029: }
2030: $r->print(
2031: '<th>'.$lt{'rol'}.'</th><th>'.$lt{'ext'}.'</th>'.
2032: '<th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'.
1.217 raeburn 2033: &Apache::loncommon::end_data_table_header_row());
1.377 raeburn 2034: foreach my $type ('Authoring Space','Course','Community','Domain','System','Unknown') {
1.329 raeburn 2035: if ($output{$type}) {
2036: $r->print($output{$type}."\n");
1.217 raeburn 2037: }
2038: }
1.375 raeburn 2039: $r->print(&Apache::loncommon::end_data_table().
2040: '</fieldset></div>');
1.329 raeburn 2041: }
1.217 raeburn 2042: return;
2043: }
2044:
1.218 raeburn 2045: sub new_coauthor_roles {
2046: my ($r,$ccuname,$ccdomain) = @_;
2047: my $addrolesdisplay = 0;
2048: #
2049: # Co-Author
2050: #
2051: if (&Apache::lonuserutils::authorpriv($env{'user.name'},
2052: $env{'request.role.domain'}) &&
2053: ($env{'user.name'} ne $ccuname || $env{'user.domain'} ne $ccdomain)) {
2054: # No sense in assigning co-author role to yourself
2055: $addrolesdisplay = 1;
2056: my $cuname=$env{'user.name'};
2057: my $cudom=$env{'request.role.domain'};
2058: my %lt=&Apache::lonlocal::texthash(
1.377 raeburn 2059: 'cs' => "Authoring Space",
1.218 raeburn 2060: 'act' => "Activate",
2061: 'rol' => "Role",
2062: 'ext' => "Extent",
2063: 'sta' => "Start",
2064: 'end' => "End",
2065: 'cau' => "Co-Author",
2066: 'caa' => "Assistant Co-Author",
2067: 'ssd' => "Set Start Date",
2068: 'sed' => "Set End Date"
2069: );
2070: $r->print('<h4>'.$lt{'cs'}.'</h4>'."\n".
2071: &Apache::loncommon::start_data_table()."\n".
2072: &Apache::loncommon::start_data_table_header_row()."\n".
2073: '<th>'.$lt{'act'}.'</th><th>'.$lt{'rol'}.'</th>'.
2074: '<th>'.$lt{'ext'}.'</th><th>'.$lt{'sta'}.'</th>'.
2075: '<th>'.$lt{'end'}.'</th>'."\n".
2076: &Apache::loncommon::end_data_table_header_row()."\n".
2077: &Apache::loncommon::start_data_table_row().'
2078: <td>
1.291 bisitz 2079: <input type="checkbox" name="act_'.$cudom.'_'.$cuname.'_ca" />
1.218 raeburn 2080: </td>
2081: <td>'.$lt{'cau'}.'</td>
2082: <td>'.$cudom.'_'.$cuname.'</td>
2083: <td><input type="hidden" name="start_'.$cudom.'_'.$cuname.'_ca" value="" />
2084: <a href=
2085: "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>
2086: <td><input type="hidden" name="end_'.$cudom.'_'.$cuname.'_ca" value="" />
2087: <a href=
2088: "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".
2089: &Apache::loncommon::end_data_table_row()."\n".
2090: &Apache::loncommon::start_data_table_row()."\n".
1.291 bisitz 2091: '<td><input type="checkbox" name="act_'.$cudom.'_'.$cuname.'_aa" /></td>
1.218 raeburn 2092: <td>'.$lt{'caa'}.'</td>
2093: <td>'.$cudom.'_'.$cuname.'</td>
2094: <td><input type="hidden" name="start_'.$cudom.'_'.$cuname.'_aa" value="" />
2095: <a href=
2096: "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>
2097: <td><input type="hidden" name="end_'.$cudom.'_'.$cuname.'_aa" value="" />
2098: <a href=
2099: "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".
2100: &Apache::loncommon::end_data_table_row()."\n".
2101: &Apache::loncommon::end_data_table());
2102: } elsif ($env{'request.role'} =~ /^au\./) {
2103: if (!(&Apache::lonuserutils::authorpriv($env{'user.name'},
2104: $env{'request.role.domain'}))) {
2105: $r->print('<span class="LC_error">'.
2106: &mt('You do not have privileges to assign co-author roles.').
2107: '</span>');
2108: } elsif (($env{'user.name'} eq $ccuname) &&
2109: ($env{'user.domain'} eq $ccdomain)) {
1.377 raeburn 2110: $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 2111: }
2112: }
2113: return $addrolesdisplay;;
2114: }
2115:
2116: sub new_domain_roles {
1.357 raeburn 2117: my ($r,$ccdomain) = @_;
1.218 raeburn 2118: my $addrolesdisplay = 0;
2119: #
2120: # Domain level
2121: #
2122: my $num_domain_level = 0;
2123: my $domaintext =
2124: '<h4>'.&mt('Domain Level').'</h4>'.
2125: &Apache::loncommon::start_data_table().
2126: &Apache::loncommon::start_data_table_header_row().
2127: '<th>'.&mt('Activate').'</th><th>'.&mt('Role').'</th><th>'.
2128: &mt('Extent').'</th>'.
2129: '<th>'.&mt('Start').'</th><th>'.&mt('End').'</th>'.
2130: &Apache::loncommon::end_data_table_header_row();
1.312 raeburn 2131: my @allroles = &Apache::lonuserutils::roles_by_context('domain');
1.218 raeburn 2132: foreach my $thisdomain (sort(&Apache::lonnet::all_domains())) {
1.312 raeburn 2133: foreach my $role (@allroles) {
2134: next if ($role eq 'ad');
1.357 raeburn 2135: next if (($role eq 'au') && ($ccdomain ne $thisdomain));
1.218 raeburn 2136: if (&Apache::lonnet::allowed('c'.$role,$thisdomain)) {
2137: my $plrole=&Apache::lonnet::plaintext($role);
2138: my %lt=&Apache::lonlocal::texthash(
2139: 'ssd' => "Set Start Date",
2140: 'sed' => "Set End Date"
2141: );
2142: $num_domain_level ++;
2143: $domaintext .=
2144: &Apache::loncommon::start_data_table_row().
1.291 bisitz 2145: '<td><input type="checkbox" name="act_'.$thisdomain.'_'.$role.'" /></td>
1.218 raeburn 2146: <td>'.$plrole.'</td>
2147: <td>'.$thisdomain.'</td>
2148: <td><input type="hidden" name="start_'.$thisdomain.'_'.$role.'" value="" />
2149: <a href=
2150: "javascript:pjump('."'date_start','Start Date $plrole',document.cu.start_$thisdomain\_$role.value,'start_$thisdomain\_$role','cu.pres','dateset'".')">'.$lt{'ssd'}.'</a></td>
2151: <td><input type="hidden" name="end_'.$thisdomain.'_'.$role.'" value="" />
2152: <a href=
2153: "javascript:pjump('."'date_end','End Date $plrole',document.cu.end_$thisdomain\_$role.value,'end_$thisdomain\_$role','cu.pres','dateset'".')">'.$lt{'sed'}.'</a></td>'.
2154: &Apache::loncommon::end_data_table_row();
2155: }
2156: }
2157: }
2158: $domaintext.= &Apache::loncommon::end_data_table();
2159: if ($num_domain_level > 0) {
2160: $r->print($domaintext);
2161: $addrolesdisplay = 1;
2162: }
2163: return $addrolesdisplay;
2164: }
2165:
1.188 raeburn 2166: sub user_authentication {
1.227 raeburn 2167: my ($ccuname,$ccdomain,$formname) = @_;
1.188 raeburn 2168: my $currentauth=&Apache::lonnet::queryauthenticate($ccuname,$ccdomain);
1.227 raeburn 2169: my $outcome;
1.406.2.6 raeburn 2170: my %lt=&Apache::lonlocal::texthash(
2171: 'err' => "ERROR",
2172: 'uuas' => "This user has an unrecognized authentication scheme",
2173: 'adcs' => "Please alert a domain coordinator of this situation",
2174: 'sldb' => "Please specify login data below",
2175: 'ld' => "Login Data"
2176: );
1.188 raeburn 2177: # Check for a bad authentication type
2178: if ($currentauth !~ /^(krb4|krb5|unix|internal|localauth):/) {
2179: # bad authentication scheme
2180: if (&Apache::lonnet::allowed('mau',$ccdomain)) {
1.227 raeburn 2181: &initialize_authen_forms($ccdomain,$formname);
2182:
1.190 raeburn 2183: my $choices = &Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc);
1.188 raeburn 2184: $outcome = <<ENDBADAUTH;
2185: <script type="text/javascript" language="Javascript">
1.301 bisitz 2186: // <![CDATA[
1.188 raeburn 2187: $loginscript
1.301 bisitz 2188: // ]]>
1.188 raeburn 2189: </script>
2190: <span class="LC_error">$lt{'err'}:
2191: $lt{'uuas'} ($currentauth). $lt{'sldb'}.</span>
2192: <h3>$lt{'ld'}</h3>
2193: $choices
2194: ENDBADAUTH
2195: } else {
2196: # This user is not allowed to modify the user's
2197: # authentication scheme, so just notify them of the problem
2198: $outcome = <<ENDBADAUTH;
2199: <span class="LC_error"> $lt{'err'}:
2200: $lt{'uuas'} ($currentauth). $lt{'adcs'}.
2201: </span>
2202: ENDBADAUTH
2203: }
2204: } else { # Authentication type is valid
1.227 raeburn 2205: &initialize_authen_forms($ccdomain,$formname,$currentauth,'modifyuser');
1.205 raeburn 2206: my ($authformcurrent,$can_modify,@authform_others) =
1.188 raeburn 2207: &modify_login_block($ccdomain,$currentauth);
2208: if (&Apache::lonnet::allowed('mau',$ccdomain)) {
2209: # Current user has login modification privileges
2210: $outcome =
2211: '<script type="text/javascript" language="Javascript">'."\n".
1.301 bisitz 2212: '// <![CDATA['."\n".
1.188 raeburn 2213: $loginscript."\n".
1.301 bisitz 2214: '// ]]>'."\n".
1.188 raeburn 2215: '</script>'."\n".
2216: '<h3>'.$lt{'ld'}.'</h3>'.
2217: &Apache::loncommon::start_data_table().
1.205 raeburn 2218: &Apache::loncommon::start_data_table_row().
1.188 raeburn 2219: '<td>'.$authformnop;
1.406.2.6 raeburn 2220: if (($can_modify) && (&Apache::lonnet::allowed('mau',$ccdomain))) {
1.188 raeburn 2221: $outcome .= '</td>'."\n".
2222: &Apache::loncommon::end_data_table_row().
2223: &Apache::loncommon::start_data_table_row().
2224: '<td>'.$authformcurrent.'</td>'.
2225: &Apache::loncommon::end_data_table_row()."\n";
2226: } else {
1.200 raeburn 2227: $outcome .= ' ('.$authformcurrent.')</td>'.
2228: &Apache::loncommon::end_data_table_row()."\n";
1.188 raeburn 2229: }
1.406.2.6 raeburn 2230: if (&Apache::lonnet::allowed('mau',$ccdomain)) {
2231: foreach my $item (@authform_others) {
2232: $outcome .= &Apache::loncommon::start_data_table_row().
2233: '<td>'.$item.'</td>'.
2234: &Apache::loncommon::end_data_table_row()."\n";
2235: }
1.188 raeburn 2236: }
1.205 raeburn 2237: $outcome .= &Apache::loncommon::end_data_table();
1.188 raeburn 2238: } else {
1.406.2.6 raeburn 2239: if (&Apache::lonnet::allowed('udp',$ccdomain)) {
2240: # Current user has rights to view domain preferences for user's domain
2241: my $result;
2242: if ($currentauth =~ /^krb(4|5):([^:]*)$/) {
2243: my ($krbver,$krbrealm) = ($1,$2);
2244: if ($krbrealm eq '') {
2245: $result = &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
2246: } else {
2247: $result = &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
1.406.2.9 raeburn 2248: $krbrealm,$krbver);
1.406.2.6 raeburn 2249: }
2250: } elsif ($currentauth =~ /^internal:/) {
2251: $result = &mt('Currently internally authenticated.');
2252: } elsif ($currentauth =~ /^localauth:/) {
2253: $result = &mt('Currently using local (institutional) authentication.');
2254: } elsif ($currentauth =~ /^unix:/) {
2255: $result = &mt('Currently Filesystem Authenticated.');
2256: }
2257: $outcome = '<h3>'.$lt{'ld'}.'</h3>'.
2258: &Apache::loncommon::start_data_table().
2259: &Apache::loncommon::start_data_table_row().
2260: '<td>'.$result.'</td>'.
2261: &Apache::loncommon::end_data_table_row()."\n".
2262: &Apache::loncommon::end_data_table();
2263: } elsif (&Apache::lonnet::allowed('mau',$env{'request.role.domain'})) {
1.188 raeburn 2264: my %lt=&Apache::lonlocal::texthash(
2265: 'ccld' => "Change Current Login Data",
2266: 'yodo' => "You do not have privileges to modify the authentication configuration for this user.",
2267: 'ifch' => "If a change is required, contact a domain coordinator for the domain",
2268: );
2269: $outcome .= <<ENDNOPRIV;
2270: <h3>$lt{'ccld'}</h3>
2271: $lt{'yodo'} $lt{'ifch'}: $ccdomain
1.235 raeburn 2272: <input type="hidden" name="login" value="nochange" />
1.188 raeburn 2273: ENDNOPRIV
2274: }
2275: }
2276: } ## End of "check for bad authentication type" logic
2277: return $outcome;
2278: }
2279:
1.187 raeburn 2280: sub modify_login_block {
2281: my ($dom,$currentauth) = @_;
2282: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
2283: my ($authnum,%can_assign) =
2284: &Apache::loncommon::get_assignable_auth($dom);
1.205 raeburn 2285: my ($authformcurrent,@authform_others,$show_override_msg);
1.187 raeburn 2286: if ($currentauth=~/^krb(4|5):/) {
2287: $authformcurrent=$authformkrb;
2288: if ($can_assign{'int'}) {
1.205 raeburn 2289: push(@authform_others,$authformint);
1.187 raeburn 2290: }
2291: if ($can_assign{'loc'}) {
1.205 raeburn 2292: push(@authform_others,$authformloc);
1.187 raeburn 2293: }
2294: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
2295: $show_override_msg = 1;
2296: }
2297: } elsif ($currentauth=~/^internal:/) {
2298: $authformcurrent=$authformint;
2299: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205 raeburn 2300: push(@authform_others,$authformkrb);
1.187 raeburn 2301: }
2302: if ($can_assign{'loc'}) {
1.205 raeburn 2303: push(@authform_others,$authformloc);
1.187 raeburn 2304: }
2305: if ($can_assign{'int'}) {
2306: $show_override_msg = 1;
2307: }
2308: } elsif ($currentauth=~/^unix:/) {
2309: $authformcurrent=$authformfsys;
2310: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205 raeburn 2311: push(@authform_others,$authformkrb);
1.187 raeburn 2312: }
2313: if ($can_assign{'int'}) {
1.205 raeburn 2314: push(@authform_others,$authformint);
1.187 raeburn 2315: }
2316: if ($can_assign{'loc'}) {
1.205 raeburn 2317: push(@authform_others,$authformloc);
1.187 raeburn 2318: }
2319: if ($can_assign{'fsys'}) {
2320: $show_override_msg = 1;
2321: }
2322: } elsif ($currentauth=~/^localauth:/) {
2323: $authformcurrent=$authformloc;
2324: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205 raeburn 2325: push(@authform_others,$authformkrb);
1.187 raeburn 2326: }
2327: if ($can_assign{'int'}) {
1.205 raeburn 2328: push(@authform_others,$authformint);
1.187 raeburn 2329: }
2330: if ($can_assign{'loc'}) {
2331: $show_override_msg = 1;
2332: }
2333: }
2334: if ($show_override_msg) {
1.205 raeburn 2335: $authformcurrent = '<table><tr><td colspan="3">'.$authformcurrent.
2336: '</td></tr>'."\n".
2337: '<tr><td> </td>'.
2338: '<td><b>'.&mt('Currently in use').'</b></td>'.
2339: '<td align="right"><span class="LC_cusr_emph">'.
1.187 raeburn 2340: &mt('will override current values').
1.205 raeburn 2341: '</span></td></tr></table>';
1.187 raeburn 2342: }
1.205 raeburn 2343: return ($authformcurrent,$show_override_msg,@authform_others);
1.187 raeburn 2344: }
2345:
1.188 raeburn 2346: sub personal_data_display {
1.391 raeburn 2347: my ($ccuname,$ccdomain,$newuser,$context,$inst_results,$rolesarray,
1.406.2.14.2. (raeburn 2348:): $now,$captchaform,$emailusername,$usertype,$usernameset,$condition,$excluded) = @_;
1.388 bisitz 2349: my ($output,%userenv,%canmodify,%canmodify_status);
1.219 raeburn 2350: my @userinfo = ('firstname','middlename','lastname','generation',
2351: 'permanentemail','id');
1.252 raeburn 2352: my $rowcount = 0;
2353: my $editable = 0;
1.391 raeburn 2354: my %textboxsize = (
2355: firstname => '15',
2356: middlename => '15',
2357: lastname => '15',
2358: generation => '5',
2359: permanentemail => '25',
2360: id => '15',
2361: );
2362:
2363: my %lt=&Apache::lonlocal::texthash(
2364: 'pd' => "Personal Data",
2365: 'firstname' => "First Name",
2366: 'middlename' => "Middle Name",
2367: 'lastname' => "Last Name",
2368: 'generation' => "Generation",
2369: 'permanentemail' => "Permanent e-mail address",
2370: 'id' => "Student/Employee ID",
2371: 'lg' => "Login Data",
2372: 'inststatus' => "Affiliation",
2373: 'email' => 'E-mail address',
2374: 'valid' => 'Validation',
1.406.2.14.2. (raeburn 2375:): 'username' => 'Username',
1.391 raeburn 2376: );
2377:
2378: %canmodify_status =
1.286 raeburn 2379: &Apache::lonuserutils::can_modify_userinfo($context,$ccdomain,
2380: ['inststatus'],$rolesarray);
1.253 raeburn 2381: if (!$newuser) {
1.188 raeburn 2382: # Get the users information
2383: %userenv = &Apache::lonnet::get('environment',
2384: ['firstname','middlename','lastname','generation',
1.286 raeburn 2385: 'permanentemail','id','inststatus'],$ccdomain,$ccuname);
1.219 raeburn 2386: %canmodify =
2387: &Apache::lonuserutils::can_modify_userinfo($context,$ccdomain,
1.252 raeburn 2388: \@userinfo,$rolesarray);
1.257 raeburn 2389: } elsif ($context eq 'selfcreate') {
1.391 raeburn 2390: if ($newuser eq 'email') {
1.396 raeburn 2391: if (ref($emailusername) eq 'HASH') {
2392: if (ref($emailusername->{$usertype}) eq 'HASH') {
2393: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
1.406.2.14.2. (raeburn 2394:): @userinfo = ();
1.396 raeburn 2395: if ((ref($infofields) eq 'ARRAY') && (ref($infotitles) eq 'HASH')) {
2396: foreach my $field (@{$infofields}) {
2397: if ($emailusername->{$usertype}->{$field}) {
2398: push(@userinfo,$field);
2399: $canmodify{$field} = 1;
2400: unless ($textboxsize{$field}) {
2401: $textboxsize{$field} = 25;
2402: }
2403: unless ($lt{$field}) {
2404: $lt{$field} = $infotitles->{$field};
2405: }
2406: if ($emailusername->{$usertype}->{$field} eq 'required') {
2407: $lt{$field} .= '<b>*</b>';
2408: }
1.391 raeburn 2409: }
2410: }
2411: }
2412: }
2413: }
2414: } else {
2415: %canmodify = &selfcreate_canmodify($context,$ccdomain,\@userinfo,
2416: $inst_results,$rolesarray);
2417: }
1.188 raeburn 2418: }
1.391 raeburn 2419:
1.188 raeburn 2420: my $genhelp=&Apache::loncommon::help_open_topic('Generation');
2421: $output = '<h3>'.$lt{'pd'}.'</h3>'.
2422: &Apache::lonhtmlcommon::start_pick_box();
1.391 raeburn 2423: if (($context eq 'selfcreate') && ($newuser eq 'email')) {
1.406.2.14.2. (raeburn 2424:): my $size = 25;
2425:): if ($condition) {
2426:): if ($condition =~ /^\@[^\@]+$/) {
2427:): $size = 10;
2428:): } else {
2429:): undef($condition);
2430:): }
2431:): }
2432:): if ($excluded) {
2433:): unless ($excluded =~ /^\@[^\@]+$/) {
2434:): undef($condition);
2435:): }
2436:): }
1.396 raeburn 2437: $output .= &Apache::lonhtmlcommon::row_title($lt{'email'}.'<b>*</b>',undef,
1.391 raeburn 2438: 'LC_oddrow_value')."\n".
1.406.2.14.2. (raeburn 2439:): '<input type="text" name="uname" size="'.$size.'" value="" autocomplete="off" />';
2440:): if ($condition) {
2441:): $output .= $condition;
2442:): } elsif ($excluded) {
2443:): $output .= '<br /><span style="font-size: smaller">'.&mt('You must use an e-mail address that does not end with [_1]',
2444:): $excluded).'</span>';
2445:): }
2446:): if ($usernameset eq 'first') {
2447:): $output .= '<br /><span style="font-size: smaller">';
2448:): if ($condition) {
2449:): $output .= &mt('Your username in LON-CAPA will be the part of your e-mail address before [_1]',
2450:): $condition);
2451:): } else {
2452:): $output .= &mt('Your username in LON-CAPA will be the part of your e-mail address before the @');
2453:): }
2454:): $output .= '</span>';
2455:): }
1.391 raeburn 2456: $rowcount ++;
2457: $output .= &Apache::lonhtmlcommon::row_closure(1);
1.406.2.1 raeburn 2458: my $upassone = '<input type="password" name="upass'.$now.'" size="20" autocomplete="off" />';
2459: my $upasstwo = '<input type="password" name="upasscheck'.$now.'" size="20" autocomplete="off" />';
1.396 raeburn 2460: $output .= &Apache::lonhtmlcommon::row_title(&mt('Password').'<b>*</b>',
1.391 raeburn 2461: 'LC_pick_box_title',
2462: 'LC_oddrow_value')."\n".
2463: $upassone."\n".
2464: &Apache::lonhtmlcommon::row_closure(1)."\n".
1.396 raeburn 2465: &Apache::lonhtmlcommon::row_title(&mt('Confirm password').'<b>*</b>',
1.391 raeburn 2466: 'LC_pick_box_title',
2467: 'LC_oddrow_value')."\n".
2468: $upasstwo.
2469: &Apache::lonhtmlcommon::row_closure()."\n";
1.406.2.14.2. (raeburn 2470:): if ($usernameset eq 'free') {
2471:): my $onclick = "toggleUsernameDisp(this,'selfcreateusername');";
2472:): $output .= &Apache::lonhtmlcommon::row_title($lt{'username'},undef,'LC_oddrow_value')."\n".
2473:): &mt('Use e-mail address: ').
2474:): '<label><input type="radio" name="emailused" value="1" checked="checked" onclick="'.$onclick.'" />'.&mt('Yes').'</label>'."\n".
2475:): (' 'x2).
2476:): '<label><input type="radio" name="emailused" value="0" onclick="'.$onclick.'" />'.&mt('No').'</label>'."\n".
2477:): '<div id="selfcreateusername" style="display: none; font-size: smaller">'.
2478:): '<br /><span class="LC_nobreak">'.&mt('Preferred username').
2479:): ' <input type="text" name="username" value="" size="20" autocomplete="off"/>'.
2480:): '</span></div>'."\n".&Apache::lonhtmlcommon::row_closure(1);
2481:): $rowcount ++;
2482:): }
1.391 raeburn 2483: }
1.188 raeburn 2484: foreach my $item (@userinfo) {
2485: my $rowtitle = $lt{$item};
1.252 raeburn 2486: my $hiderow = 0;
1.188 raeburn 2487: if ($item eq 'generation') {
2488: $rowtitle = $genhelp.$rowtitle;
2489: }
1.252 raeburn 2490: my $row = &Apache::lonhtmlcommon::row_title($rowtitle,undef,'LC_oddrow_value')."\n";
1.188 raeburn 2491: if ($newuser) {
1.210 raeburn 2492: if (ref($inst_results) eq 'HASH') {
2493: if ($inst_results->{$item} ne '') {
1.252 raeburn 2494: $row .= '<input type="hidden" name="c'.$item.'" value="'.$inst_results->{$item}.'" />'.$inst_results->{$item};
1.210 raeburn 2495: } else {
1.252 raeburn 2496: if ($context eq 'selfcreate') {
1.391 raeburn 2497: if ($canmodify{$item}) {
1.394 raeburn 2498: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" autocomplete="off" />';
1.252 raeburn 2499: $editable ++;
2500: } else {
2501: $hiderow = 1;
2502: }
1.253 raeburn 2503: } else {
2504: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
1.252 raeburn 2505: }
1.210 raeburn 2506: }
1.188 raeburn 2507: } else {
1.252 raeburn 2508: if ($context eq 'selfcreate') {
1.401 raeburn 2509: if ($canmodify{$item}) {
2510: if ($newuser eq 'email') {
2511: $row .= '<input type="text" name="'.$item.'" size="'.$textboxsize{$item}.'" value="" autocomplete="off" />';
1.287 raeburn 2512: } else {
1.401 raeburn 2513: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" autocomplete="off" />';
1.287 raeburn 2514: }
1.401 raeburn 2515: $editable ++;
2516: } else {
2517: $hiderow = 1;
1.252 raeburn 2518: }
1.253 raeburn 2519: } else {
2520: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
1.252 raeburn 2521: }
1.188 raeburn 2522: }
2523: } else {
1.219 raeburn 2524: if ($canmodify{$item}) {
1.252 raeburn 2525: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="'.$userenv{$item}.'" />';
1.393 raeburn 2526: if (($item eq 'id') && (!$newuser)) {
2527: $row .= '<br />'.&Apache::lonuserutils::forceid_change($context);
2528: }
1.188 raeburn 2529: } else {
1.252 raeburn 2530: $row .= $userenv{$item};
1.188 raeburn 2531: }
2532: }
1.252 raeburn 2533: $row .= &Apache::lonhtmlcommon::row_closure(1);
2534: if (!$hiderow) {
2535: $output .= $row;
2536: $rowcount ++;
2537: }
1.188 raeburn 2538: }
1.286 raeburn 2539: if (($canmodify_status{'inststatus'}) || ($context ne 'selfcreate')) {
2540: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($ccdomain);
2541: if (ref($types) eq 'ARRAY') {
2542: if (@{$types} > 0) {
2543: my ($hiderow,$shown);
2544: if ($canmodify_status{'inststatus'}) {
2545: $shown = &pick_inst_statuses($userenv{'inststatus'},$usertypes,$types);
2546: } else {
2547: if ($userenv{'inststatus'} eq '') {
2548: $hiderow = 1;
1.334 raeburn 2549: } else {
2550: my @showitems;
2551: foreach my $item ( map { &unescape($_); } split(':',$userenv{'inststatus'})) {
2552: if (exists($usertypes->{$item})) {
2553: push(@showitems,$usertypes->{$item});
2554: } else {
2555: push(@showitems,$item);
2556: }
2557: }
2558: if (@showitems) {
2559: $shown = join(', ',@showitems);
2560: } else {
2561: $hiderow = 1;
2562: }
1.286 raeburn 2563: }
2564: }
2565: if (!$hiderow) {
1.389 bisitz 2566: my $row = &Apache::lonhtmlcommon::row_title(&mt('Affiliations'),undef,'LC_oddrow_value')."\n".
1.286 raeburn 2567: $shown.&Apache::lonhtmlcommon::row_closure(1);
2568: if ($context eq 'selfcreate') {
2569: $rowcount ++;
2570: }
2571: $output .= $row;
2572: }
2573: }
2574: }
2575: }
1.391 raeburn 2576: if (($context eq 'selfcreate') && ($newuser eq 'email')) {
2577: if ($captchaform) {
1.406.2.2 raeburn 2578: $output .= &Apache::lonhtmlcommon::row_title($lt{'valid'}.'*',
1.391 raeburn 2579: 'LC_pick_box_title')."\n".
2580: $captchaform."\n".'<br /><br />'.
2581: &Apache::lonhtmlcommon::row_closure(1);
2582: $rowcount ++;
2583: }
2584: my $submit_text = &mt('Create account');
2585: $output .= &Apache::lonhtmlcommon::row_title()."\n".
2586: '<br /><input type="submit" name="createaccount" value="'.
2587: $submit_text.'" />'.
1.396 raeburn 2588: '<input type="hidden" name="type" value="'.$usertype.'" />'.
1.391 raeburn 2589: &Apache::lonhtmlcommon::row_closure(1);
2590: }
1.188 raeburn 2591: $output .= &Apache::lonhtmlcommon::end_pick_box();
1.206 raeburn 2592: if (wantarray) {
1.252 raeburn 2593: if ($context eq 'selfcreate') {
2594: return($output,$rowcount,$editable);
2595: } else {
1.388 bisitz 2596: return $output;
1.252 raeburn 2597: }
1.206 raeburn 2598: } else {
2599: return $output;
2600: }
1.188 raeburn 2601: }
2602:
1.286 raeburn 2603: sub pick_inst_statuses {
2604: my ($curr,$usertypes,$types) = @_;
2605: my ($output,$rem,@currtypes);
2606: if ($curr ne '') {
2607: @currtypes = map { &unescape($_); } split(/:/,$curr);
2608: }
2609: my $numinrow = 2;
2610: if (ref($types) eq 'ARRAY') {
2611: $output = '<table>';
2612: my $lastcolspan;
2613: for (my $i=0; $i<@{$types}; $i++) {
2614: if (defined($usertypes->{$types->[$i]})) {
2615: my $rem = $i%($numinrow);
2616: if ($rem == 0) {
2617: if ($i<@{$types}-1) {
2618: if ($i > 0) {
2619: $output .= '</tr>';
2620: }
2621: $output .= '<tr>';
2622: }
2623: } elsif ($i==@{$types}-1) {
2624: my $colsleft = $numinrow - $rem;
2625: if ($colsleft > 1) {
2626: $lastcolspan = ' colspan="'.$colsleft.'"';
2627: }
2628: }
2629: my $check = ' ';
2630: if (grep(/^\Q$types->[$i]\E$/,@currtypes)) {
2631: $check = ' checked="checked" ';
2632: }
2633: $output .= '<td class="LC_left_item"'.$lastcolspan.'>'.
2634: '<span class="LC_nobreak"><label>'.
2635: '<input type="checkbox" name="inststatus" '.
2636: 'value="'.$types->[$i].'"'.$check.'/>'.
2637: $usertypes->{$types->[$i]}.'</label></span></td>';
2638: }
2639: }
2640: $output .= '</tr></table>';
2641: }
2642: return $output;
2643: }
2644:
1.257 raeburn 2645: sub selfcreate_canmodify {
2646: my ($context,$dom,$userinfo,$inst_results,$rolesarray) = @_;
2647: if (ref($inst_results) eq 'HASH') {
2648: my @inststatuses = &get_inststatuses($inst_results);
2649: if (@inststatuses == 0) {
2650: @inststatuses = ('default');
2651: }
2652: $rolesarray = \@inststatuses;
2653: }
2654: my %canmodify =
2655: &Apache::lonuserutils::can_modify_userinfo($context,$dom,$userinfo,
2656: $rolesarray);
2657: return %canmodify;
2658: }
2659:
1.252 raeburn 2660: sub get_inststatuses {
2661: my ($insthashref) = @_;
2662: my @inststatuses = ();
2663: if (ref($insthashref) eq 'HASH') {
2664: if (ref($insthashref->{'inststatus'}) eq 'ARRAY') {
2665: @inststatuses = @{$insthashref->{'inststatus'}};
2666: }
2667: }
2668: return @inststatuses;
2669: }
2670:
1.4 www 2671: # ================================================================= Phase Three
1.42 matthew 2672: sub update_user_data {
1.375 raeburn 2673: my ($r,$context,$crstype,$brcrum,$showcredits) = @_;
1.101 albertel 2674: my $uhome=&Apache::lonnet::homeserver($env{'form.ccuname'},
2675: $env{'form.ccdomain'});
1.27 matthew 2676: # Error messages
1.188 raeburn 2677: my $error = '<span class="LC_error">'.&mt('Error').': ';
1.193 raeburn 2678: my $end = '</span><br /><br />';
2679: my $rtnlink = '<a href="javascript:backPage(document.userupdate,'.
1.188 raeburn 2680: "'$env{'form.prevphase'}','modify')".'" />'.
1.219 raeburn 2681: &mt('Return to previous page').'</a>'.
2682: &Apache::loncommon::end_page();
2683: my $now = time;
1.40 www 2684: my $title;
1.101 albertel 2685: if (exists($env{'form.makeuser'})) {
1.40 www 2686: $title='Set Privileges for New User';
2687: } else {
2688: $title='Modify User Privileges';
2689: }
1.213 raeburn 2690: my $newuser = 0;
1.160 raeburn 2691: my ($jsback,$elements) = &crumb_utilities();
2692: my $jscript = '<script type="text/javascript">'."\n".
1.301 bisitz 2693: '// <![CDATA['."\n".
2694: $jsback."\n".
2695: '// ]]>'."\n".
2696: '</script>'."\n";
1.406.2.7 raeburn 2697: my %breadcrumb_text = &singleuser_breadcrumb($crstype,$context,$env{'form.ccdomain'});
1.351 raeburn 2698: push (@{$brcrum},
2699: {href => "javascript:backPage(document.userupdate)",
2700: text => $breadcrumb_text{'search'},
2701: faq => 282,
2702: bug => 'Instructor Interface',}
2703: );
2704: if ($env{'form.prevphase'} eq 'userpicked') {
2705: push(@{$brcrum},
2706: {href => "javascript:backPage(document.userupdate,'get_user_info','select')",
2707: text => $breadcrumb_text{'userpicked'},
2708: faq => 282,
2709: bug => 'Instructor Interface',});
1.233 raeburn 2710: }
1.224 raeburn 2711: my $helpitem = 'Course_Change_Privileges';
2712: if ($env{'form.action'} eq 'singlestudent') {
2713: $helpitem = 'Course_Add_Student';
1.406.2.14 raeburn 2714: } elsif ($context eq 'author') {
2715: $helpitem = 'Author_Change_Privileges';
2716: } elsif ($context eq 'domain') {
2717: $helpitem = 'Domain_Change_Privileges';
1.224 raeburn 2718: }
1.351 raeburn 2719: push(@{$brcrum},
2720: {href => "javascript:backPage(document.userupdate,'$env{'form.prevphase'}','modify')",
2721: text => $breadcrumb_text{'modify'},
2722: faq => 282,
2723: bug => 'Instructor Interface',},
2724: {href => "/adm/createuser",
2725: text => "Result",
2726: faq => 282,
2727: bug => 'Instructor Interface',
2728: help => $helpitem});
2729: my $args = {bread_crumbs => $brcrum,
2730: bread_crumbs_component => 'User Management'};
2731: if ($env{'form.popup'}) {
2732: $args->{'no_nav_bar'} = 1;
2733: }
2734: $r->print(&Apache::loncommon::start_page($title,$jscript,$args));
1.188 raeburn 2735: $r->print(&update_result_form($uhome));
1.27 matthew 2736: # Check Inputs
1.101 albertel 2737: if (! $env{'form.ccuname'} ) {
1.193 raeburn 2738: $r->print($error.&mt('No login name specified').'.'.$end.$rtnlink);
1.27 matthew 2739: return;
2740: }
1.138 albertel 2741: if ( $env{'form.ccuname'} ne
2742: &LONCAPA::clean_username($env{'form.ccuname'}) ) {
1.281 bisitz 2743: $r->print($error.&mt('Invalid login name.').' '.
2744: &mt('Only letters, numbers, periods, dashes, @, and underscores are valid.').
1.193 raeburn 2745: $end.$rtnlink);
1.27 matthew 2746: return;
2747: }
1.101 albertel 2748: if (! $env{'form.ccdomain'} ) {
1.193 raeburn 2749: $r->print($error.&mt('No domain specified').'.'.$end.$rtnlink);
1.27 matthew 2750: return;
2751: }
1.138 albertel 2752: if ( $env{'form.ccdomain'} ne
2753: &LONCAPA::clean_domain($env{'form.ccdomain'}) ) {
1.281 bisitz 2754: $r->print($error.&mt('Invalid domain name.').' '.
2755: &mt('Only letters, numbers, periods, dashes, and underscores are valid.').
1.193 raeburn 2756: $end.$rtnlink);
1.27 matthew 2757: return;
2758: }
1.219 raeburn 2759: if ($uhome eq 'no_host') {
2760: $newuser = 1;
2761: }
1.101 albertel 2762: if (! exists($env{'form.makeuser'})) {
1.29 matthew 2763: # Modifying an existing user, so check the validity of the name
2764: if ($uhome eq 'no_host') {
1.389 bisitz 2765: $r->print(
2766: $error
2767: .'<p class="LC_error">'
2768: .&mt('Unable to determine home server for [_1] in domain [_2].',
2769: '"'.$env{'form.ccuname'}.'"','"'.$env{'form.ccdomain'}.'"')
2770: .'</p>');
1.29 matthew 2771: return;
2772: }
2773: }
1.27 matthew 2774: # Determine authentication method and password for the user being modified
2775: my $amode='';
2776: my $genpwd='';
1.101 albertel 2777: if ($env{'form.login'} eq 'krb') {
1.41 albertel 2778: $amode='krb';
1.101 albertel 2779: $amode.=$env{'form.krbver'};
2780: $genpwd=$env{'form.krbarg'};
2781: } elsif ($env{'form.login'} eq 'int') {
1.27 matthew 2782: $amode='internal';
1.101 albertel 2783: $genpwd=$env{'form.intarg'};
2784: } elsif ($env{'form.login'} eq 'fsys') {
1.27 matthew 2785: $amode='unix';
1.101 albertel 2786: $genpwd=$env{'form.fsysarg'};
2787: } elsif ($env{'form.login'} eq 'loc') {
1.27 matthew 2788: $amode='localauth';
1.101 albertel 2789: $genpwd=$env{'form.locarg'};
1.27 matthew 2790: $genpwd=" " if (!$genpwd);
1.101 albertel 2791: } elsif (($env{'form.login'} eq 'nochange') ||
2792: ($env{'form.login'} eq '' )) {
1.34 matthew 2793: # There is no need to tell the user we did not change what they
2794: # did not ask us to change.
1.35 matthew 2795: # If they are creating a new user but have not specified login
2796: # information this will be caught below.
1.30 matthew 2797: } else {
1.367 golterma 2798: $r->print($error.&mt('Invalid login mode or password').$end.$rtnlink);
2799: return;
1.27 matthew 2800: }
1.164 albertel 2801:
1.188 raeburn 2802: $r->print('<h3>'.&mt('User [_1] in domain [_2]',
1.367 golterma 2803: $env{'form.ccuname'}.' ('.&Apache::loncommon::plainname($env{'form.ccuname'},
2804: $env{'form.ccdomain'}).')', $env{'form.ccdomain'}).'</h3>');
2805: my %prog_state = &Apache::lonhtmlcommon::Create_PrgWin($r,2);
1.344 bisitz 2806:
1.193 raeburn 2807: my (%alerts,%rulematch,%inst_results,%curr_rules);
1.334 raeburn 2808: my @userinfo = ('firstname','middlename','lastname','generation','permanentemail','id');
1.361 raeburn 2809: my @usertools = ('aboutme','blog','webdav','portfolio');
1.384 raeburn 2810: my @requestcourses = ('official','unofficial','community','textbook');
1.362 raeburn 2811: my @requestauthor = ('requestauthor');
1.286 raeburn 2812: my ($othertitle,$usertypes,$types) =
2813: &Apache::loncommon::sorted_inst_types($env{'form.ccdomain'});
1.334 raeburn 2814: my %canmodify_status =
2815: &Apache::lonuserutils::can_modify_userinfo($context,$env{'form.ccdomain'},
2816: ['inststatus']);
1.101 albertel 2817: if ($env{'form.makeuser'}) {
1.164 albertel 2818: $r->print('<h3>'.&mt('Creating new account.').'</h3>');
1.27 matthew 2819: # Check for the authentication mode and password
2820: if (! $amode || ! $genpwd) {
1.193 raeburn 2821: $r->print($error.&mt('Invalid login mode or password').$end.$rtnlink);
1.27 matthew 2822: return;
1.18 albertel 2823: }
1.29 matthew 2824: # Determine desired host
1.101 albertel 2825: my $desiredhost = $env{'form.hserver'};
1.29 matthew 2826: if (lc($desiredhost) eq 'default') {
2827: $desiredhost = undef;
2828: } else {
1.147 albertel 2829: my %home_servers =
2830: &Apache::lonnet::get_servers($env{'form.ccdomain'},'library');
1.29 matthew 2831: if (! exists($home_servers{$desiredhost})) {
1.193 raeburn 2832: $r->print($error.&mt('Invalid home server specified').$end.$rtnlink);
2833: return;
2834: }
2835: }
2836: # Check ID format
2837: my %checkhash;
2838: my %checks = ('id' => 1);
2839: %{$checkhash{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}}} = (
1.219 raeburn 2840: 'newuser' => $newuser,
1.196 raeburn 2841: 'id' => $env{'form.cid'},
1.193 raeburn 2842: );
1.196 raeburn 2843: if ($env{'form.cid'} ne '') {
2844: &Apache::loncommon::user_rule_check(\%checkhash,\%checks,\%alerts,
2845: \%rulematch,\%inst_results,\%curr_rules);
2846: if (ref($alerts{'id'}) eq 'HASH') {
2847: if (ref($alerts{'id'}{$env{'form.ccdomain'}}) eq 'HASH') {
2848: my $domdesc =
2849: &Apache::lonnet::domain($env{'form.ccdomain'},'description');
2850: if ($alerts{'id'}{$env{'form.ccdomain'}}{$env{'form.cid'}}) {
2851: my $userchkmsg;
2852: if (ref($curr_rules{$env{'form.ccdomain'}}) eq 'HASH') {
2853: $userchkmsg =
2854: &Apache::loncommon::instrule_disallow_msg('id',
2855: $domdesc,1).
2856: &Apache::loncommon::user_rule_formats($env{'form.ccdomain'},
2857: $domdesc,$curr_rules{$env{'form.ccdomain'}}{'id'},'id');
2858: }
2859: $r->print($error.&mt('Invalid ID format').$end.
2860: $userchkmsg.$rtnlink);
2861: return;
2862: }
2863: }
1.29 matthew 2864: }
2865: }
1.367 golterma 2866: &Apache::lonhtmlcommon::Increment_PrgWin($r, \%prog_state);
1.27 matthew 2867: # Call modifyuser
2868: my $result = &Apache::lonnet::modifyuser
1.193 raeburn 2869: ($env{'form.ccdomain'},$env{'form.ccuname'},$env{'form.cid'},
1.188 raeburn 2870: $amode,$genpwd,$env{'form.cfirstname'},
2871: $env{'form.cmiddlename'},$env{'form.clastname'},
2872: $env{'form.cgeneration'},undef,$desiredhost,
2873: $env{'form.cpermanentemail'});
1.77 www 2874: $r->print(&mt('Generating user').': '.$result);
1.219 raeburn 2875: $uhome = &Apache::lonnet::homeserver($env{'form.ccuname'},
1.101 albertel 2876: $env{'form.ccdomain'});
1.334 raeburn 2877: my (%changeHash,%newcustom,%changed,%changedinfo);
1.267 raeburn 2878: if ($uhome ne 'no_host') {
1.334 raeburn 2879: if ($context eq 'domain') {
1.378 raeburn 2880: foreach my $name ('portfolio','author') {
2881: if ($env{'form.custom_'.$name.'quota'} == 1) {
2882: if ($env{'form.'.$name.'quota'} eq '') {
2883: $newcustom{$name.'quota'} = 0;
2884: } else {
2885: $newcustom{$name.'quota'} = $env{'form.'.$name.'quota'};
2886: $newcustom{$name.'quota'} =~ s/[^\d\.]//g;
2887: }
2888: if ("a_admin($newcustom{$name.'quota'},\%changeHash,$name)) {
2889: $changed{$name.'quota'} = 1;
2890: }
1.334 raeburn 2891: }
2892: }
2893: foreach my $item (@usertools) {
2894: if ($env{'form.custom'.$item} == 1) {
2895: $newcustom{$item} = $env{'form.tools_'.$item};
2896: $changed{$item} = &tool_admin($item,$newcustom{$item},
2897: \%changeHash,'tools');
2898: }
1.267 raeburn 2899: }
1.334 raeburn 2900: foreach my $item (@requestcourses) {
1.341 raeburn 2901: if ($env{'form.custom'.$item} == 1) {
2902: $newcustom{$item} = $env{'form.crsreq_'.$item};
2903: if ($env{'form.crsreq_'.$item} eq 'autolimit') {
2904: $newcustom{$item} .= '=';
1.383 raeburn 2905: $env{'form.crsreq_'.$item.'_limit'} =~ s/\D+//g;
2906: if ($env{'form.crsreq_'.$item.'_limit'}) {
1.341 raeburn 2907: $newcustom{$item} .= $env{'form.crsreq_'.$item.'_limit'};
2908: }
1.334 raeburn 2909: }
1.341 raeburn 2910: $changed{$item} = &tool_admin($item,$newcustom{$item},
2911: \%changeHash,'requestcourses');
1.334 raeburn 2912: }
1.275 raeburn 2913: }
1.362 raeburn 2914: if ($env{'form.customrequestauthor'} == 1) {
2915: $newcustom{'requestauthor'} = $env{'form.requestauthor'};
2916: $changed{'requestauthor'} = &tool_admin('requestauthor',
2917: $newcustom{'requestauthor'},
2918: \%changeHash,'requestauthor');
2919: }
1.275 raeburn 2920: }
1.334 raeburn 2921: if ($canmodify_status{'inststatus'}) {
2922: if (exists($env{'form.inststatus'})) {
2923: my @inststatuses = &Apache::loncommon::get_env_multiple('form.inststatus');
2924: if (@inststatuses > 0) {
2925: $changeHash{'inststatus'} = join(',',@inststatuses);
2926: $changed{'inststatus'} = $changeHash{'inststatus'};
1.306 raeburn 2927: }
2928: }
1.232 raeburn 2929: }
1.334 raeburn 2930: if (keys(%changed)) {
2931: foreach my $item (@userinfo) {
2932: $changeHash{$item} = $env{'form.c'.$item};
1.286 raeburn 2933: }
1.267 raeburn 2934: my $chgresult =
2935: &Apache::lonnet::put('environment',\%changeHash,
2936: $env{'form.ccdomain'},$env{'form.ccuname'});
2937: }
1.232 raeburn 2938: }
1.219 raeburn 2939: $r->print('<br />'.&mt('Home server').': '.$uhome.' '.
2940: &Apache::lonnet::hostname($uhome));
1.101 albertel 2941: } elsif (($env{'form.login'} ne 'nochange') &&
2942: ($env{'form.login'} ne '' )) {
1.27 matthew 2943: # Modify user privileges
2944: if (! $amode || ! $genpwd) {
1.193 raeburn 2945: $r->print($error.'Invalid login mode or password'.$end.$rtnlink);
1.27 matthew 2946: return;
1.20 harris41 2947: }
1.395 bisitz 2948: # Only allow authentication modification if the person has authority
1.101 albertel 2949: if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'})) {
1.20 harris41 2950: $r->print('Modifying authentication: '.
1.31 matthew 2951: &Apache::lonnet::modifyuserauth(
1.101 albertel 2952: $env{'form.ccdomain'},$env{'form.ccuname'},
1.21 harris41 2953: $amode,$genpwd));
1.102 albertel 2954: $r->print('<br />'.&mt('Home server').': '.&Apache::lonnet::homeserver
1.101 albertel 2955: ($env{'form.ccuname'},$env{'form.ccdomain'}));
1.4 www 2956: } else {
1.27 matthew 2957: # Okay, this is a non-fatal error.
1.395 bisitz 2958: $r->print($error.&mt('You do not have the authority to modify this users authentication information.').$end);
1.27 matthew 2959: }
1.28 matthew 2960: }
1.344 bisitz 2961: $r->rflush(); # Finish display of header before time consuming actions start
1.367 golterma 2962: &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state);
1.28 matthew 2963: ##
1.375 raeburn 2964: my (@userroles,%userupdate,$cnum,$cdom,$defaultcredits,%namechanged);
1.213 raeburn 2965: if ($context eq 'course') {
1.375 raeburn 2966: ($cnum,$cdom) =
2967: &Apache::lonuserutils::get_course_identity();
1.318 raeburn 2968: $crstype = &Apache::loncommon::course_type($cdom.'_'.$cnum);
1.375 raeburn 2969: if ($showcredits) {
2970: $defaultcredits = &Apache::lonuserutils::get_defaultcredits($cdom,$cnum);
2971: }
1.213 raeburn 2972: }
1.101 albertel 2973: if (! $env{'form.makeuser'} ) {
1.28 matthew 2974: # Check for need to change
2975: my %userenv = &Apache::lonnet::get
1.134 raeburn 2976: ('environment',['firstname','middlename','lastname','generation',
1.378 raeburn 2977: 'id','permanentemail','portfolioquota','authorquota','inststatus',
2978: 'tools.aboutme','tools.blog','tools.webdav','tools.portfolio',
1.361 raeburn 2979: 'requestcourses.official','requestcourses.unofficial',
1.384 raeburn 2980: 'requestcourses.community','requestcourses.textbook',
2981: 'reqcrsotherdom.official','reqcrsotherdom.unofficial',
2982: 'reqcrsotherdom.community','reqcrsotherdom.textbook',
1.406.2.9 raeburn 2983: 'requestauthor'],
1.160 raeburn 2984: $env{'form.ccdomain'},$env{'form.ccuname'});
1.28 matthew 2985: my ($tmp) = keys(%userenv);
2986: if ($tmp =~ /^(con_lost|error)/i) {
2987: %userenv = ();
2988: }
1.206 raeburn 2989: my $no_forceid_alert;
2990: # Check to see if user information can be changed
2991: my %domconfig =
2992: &Apache::lonnet::get_dom('configuration',['usermodification'],
2993: $env{'form.ccdomain'});
1.213 raeburn 2994: my @statuses = ('active','future');
2995: my %roles = &Apache::lonnet::get_my_roles($env{'form.ccuname'},$env{'form.ccdomain'},'userroles',\@statuses,undef,$env{'request.role.domain'});
2996: my ($auname,$audom);
1.220 raeburn 2997: if ($context eq 'author') {
1.206 raeburn 2998: $auname = $env{'user.name'};
2999: $audom = $env{'user.domain'};
3000: }
3001: foreach my $item (keys(%roles)) {
1.220 raeburn 3002: my ($rolenum,$roledom,$role) = split(/:/,$item,-1);
1.206 raeburn 3003: if ($context eq 'course') {
3004: if ($cnum ne '' && $cdom ne '') {
3005: if ($rolenum eq $cnum && $roledom eq $cdom) {
3006: if (!grep(/^\Q$role\E$/,@userroles)) {
3007: push(@userroles,$role);
3008: }
3009: }
3010: }
3011: } elsif ($context eq 'author') {
3012: if ($rolenum eq $auname && $roledom eq $audom) {
3013: if (!grep(/^\Q$role\E$/,@userroles)) {
3014: push(@userroles,$role);
3015: }
3016: }
3017: }
3018: }
1.220 raeburn 3019: if ($env{'form.action'} eq 'singlestudent') {
3020: if (!grep(/^st$/,@userroles)) {
3021: push(@userroles,'st');
3022: }
3023: } else {
3024: # Check for course or co-author roles being activated or re-enabled
3025: if ($context eq 'author' || $context eq 'course') {
3026: foreach my $key (keys(%env)) {
3027: if ($context eq 'author') {
3028: if ($key=~/^form\.act_\Q$audom\E_\Q$auname\E_([^_]+)/) {
3029: if (!grep(/^\Q$1\E$/,@userroles)) {
3030: push(@userroles,$1);
3031: }
3032: } elsif ($key =~/^form\.ren\:\Q$audom\E\/\Q$auname\E_([^_]+)/) {
3033: if (!grep(/^\Q$1\E$/,@userroles)) {
3034: push(@userroles,$1);
3035: }
1.206 raeburn 3036: }
1.220 raeburn 3037: } elsif ($context eq 'course') {
3038: if ($key=~/^form\.act_\Q$cdom\E_\Q$cnum\E_([^_]+)/) {
3039: if (!grep(/^\Q$1\E$/,@userroles)) {
3040: push(@userroles,$1);
3041: }
3042: } elsif ($key =~/^form\.ren\:\Q$cdom\E\/\Q$cnum\E(\/?\w*)_([^_]+)/) {
3043: if (!grep(/^\Q$1\E$/,@userroles)) {
3044: push(@userroles,$1);
3045: }
1.206 raeburn 3046: }
3047: }
3048: }
3049: }
3050: }
3051: #Check to see if we can change personal data for the user
3052: my (@mod_disallowed,@longroles);
3053: foreach my $role (@userroles) {
3054: if ($role eq 'cr') {
3055: push(@longroles,'Custom');
3056: } else {
1.318 raeburn 3057: push(@longroles,&Apache::lonnet::plaintext($role,$crstype));
1.206 raeburn 3058: }
3059: }
1.219 raeburn 3060: my %canmodify = &Apache::lonuserutils::can_modify_userinfo($context,$env{'form.ccdomain'},\@userinfo,\@userroles);
3061: foreach my $item (@userinfo) {
1.28 matthew 3062: # Strip leading and trailing whitespace
1.203 raeburn 3063: $env{'form.c'.$item} =~ s/(\s+$|^\s+)//g;
1.219 raeburn 3064: if (!$canmodify{$item}) {
1.207 raeburn 3065: if (defined($env{'form.c'.$item})) {
3066: if ($env{'form.c'.$item} ne $userenv{$item}) {
3067: push(@mod_disallowed,$item);
3068: }
1.206 raeburn 3069: }
3070: $env{'form.c'.$item} = $userenv{$item};
3071: }
1.28 matthew 3072: }
1.259 bisitz 3073: # Check to see if we can change the Student/Employee ID
1.196 raeburn 3074: my $forceid = $env{'form.forceid'};
3075: my $recurseid = $env{'form.recurseid'};
3076: my (%alerts,%rulematch,%idinst_results,%curr_rules,%got_rules);
1.203 raeburn 3077: my %uidhash = &Apache::lonnet::idrget($env{'form.ccdomain'},
3078: $env{'form.ccuname'});
3079: if (($uidhash{$env{'form.ccuname'}}) &&
3080: ($uidhash{$env{'form.ccuname'}}!~/error\:/) &&
3081: (!$forceid)) {
3082: if ($env{'form.cid'} ne $uidhash{$env{'form.ccuname'}}) {
3083: $env{'form.cid'} = $userenv{'id'};
1.293 bisitz 3084: $no_forceid_alert = &mt('New student/employee ID does not match existing ID for this user.')
1.259 bisitz 3085: .'<br />'
3086: .&mt("Change is not permitted without checking the 'Force ID change' checkbox on the previous page.")
3087: .'<br />'."\n";
1.203 raeburn 3088: }
3089: }
3090: if ($env{'form.cid'} ne $userenv{'id'}) {
1.196 raeburn 3091: my $checkhash;
3092: my $checks = { 'id' => 1 };
3093: $checkhash->{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}} =
3094: { 'newuser' => $newuser,
3095: 'id' => $env{'form.cid'},
3096: };
3097: &Apache::loncommon::user_rule_check($checkhash,$checks,
3098: \%alerts,\%rulematch,\%idinst_results,\%curr_rules,\%got_rules);
3099: if (ref($alerts{'id'}) eq 'HASH') {
3100: if (ref($alerts{'id'}{$env{'form.ccdomain'}}) eq 'HASH') {
1.203 raeburn 3101: $env{'form.cid'} = $userenv{'id'};
1.196 raeburn 3102: }
3103: }
3104: }
1.378 raeburn 3105: my (%quotachanged,%oldquota,%newquota,%olddefquota,%newdefquota,
3106: $oldinststatus,$newinststatus,%oldisdefault,%newisdefault,%oldsettings,
1.339 raeburn 3107: %oldsettingstext,%newsettings,%newsettingstext,@disporder,
1.378 raeburn 3108: %oldsettingstatus,%newsettingstatus);
1.334 raeburn 3109: @disporder = ('inststatus');
3110: if ($env{'request.role.domain'} eq $env{'form.ccdomain'}) {
1.362 raeburn 3111: push(@disporder,'requestcourses','requestauthor');
1.334 raeburn 3112: } else {
3113: push(@disporder,'reqcrsotherdom');
3114: }
3115: push(@disporder,('quota','tools'));
1.338 raeburn 3116: $oldinststatus = $userenv{'inststatus'};
1.378 raeburn 3117: foreach my $name ('portfolio','author') {
3118: ($olddefquota{$name},$oldsettingstatus{$name}) =
3119: &Apache::loncommon::default_quota($env{'form.ccdomain'},$oldinststatus,$name);
3120: ($newdefquota{$name},$newsettingstatus{$name}) = ($olddefquota{$name},$oldsettingstatus{$name});
3121: }
1.334 raeburn 3122: my %canshow;
1.220 raeburn 3123: if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
1.334 raeburn 3124: $canshow{'quota'} = 1;
1.220 raeburn 3125: }
1.267 raeburn 3126: if (&Apache::lonnet::allowed('mut',$env{'form.ccdomain'})) {
1.334 raeburn 3127: $canshow{'tools'} = 1;
1.267 raeburn 3128: }
1.275 raeburn 3129: if (&Apache::lonnet::allowed('ccc',$env{'form.ccdomain'})) {
1.334 raeburn 3130: $canshow{'requestcourses'} = 1;
1.300 raeburn 3131: } elsif (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
1.334 raeburn 3132: $canshow{'reqcrsotherdom'} = 1;
1.275 raeburn 3133: }
1.286 raeburn 3134: if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'})) {
1.334 raeburn 3135: $canshow{'inststatus'} = 1;
1.286 raeburn 3136: }
1.362 raeburn 3137: if (&Apache::lonnet::allowed('cau',$env{'form.ccdomain'})) {
3138: $canshow{'requestauthor'} = 1;
3139: }
1.267 raeburn 3140: my (%changeHash,%changed);
1.286 raeburn 3141: if ($oldinststatus eq '') {
1.334 raeburn 3142: $oldsettings{'inststatus'} = $othertitle;
1.286 raeburn 3143: } else {
3144: if (ref($usertypes) eq 'HASH') {
1.334 raeburn 3145: $oldsettings{'inststatus'} = join(', ',map{ $usertypes->{ &unescape($_) }; } (split(/:/,$userenv{'inststatus'})));
1.286 raeburn 3146: } else {
1.334 raeburn 3147: $oldsettings{'inststatus'} = join(', ',map{ &unescape($_); } (split(/:/,$userenv{'inststatus'})));
1.286 raeburn 3148: }
3149: }
3150: $changeHash{'inststatus'} = $userenv{'inststatus'};
1.334 raeburn 3151: if ($canmodify_status{'inststatus'}) {
3152: $canshow{'inststatus'} = 1;
1.286 raeburn 3153: if (exists($env{'form.inststatus'})) {
3154: my @inststatuses = &Apache::loncommon::get_env_multiple('form.inststatus');
3155: if (@inststatuses > 0) {
3156: $newinststatus = join(':',map { &escape($_); } @inststatuses);
3157: $changeHash{'inststatus'} = $newinststatus;
3158: if ($newinststatus ne $oldinststatus) {
3159: $changed{'inststatus'} = $newinststatus;
1.378 raeburn 3160: foreach my $name ('portfolio','author') {
3161: ($newdefquota{$name},$newsettingstatus{$name}) =
3162: &Apache::loncommon::default_quota($env{'form.ccdomain'},$newinststatus,$name);
3163: }
1.286 raeburn 3164: }
3165: if (ref($usertypes) eq 'HASH') {
1.334 raeburn 3166: $newsettings{'inststatus'} = join(', ',map{ $usertypes->{$_}; } (@inststatuses));
1.286 raeburn 3167: } else {
1.337 raeburn 3168: $newsettings{'inststatus'} = join(', ',@inststatuses);
1.286 raeburn 3169: }
1.334 raeburn 3170: }
3171: } else {
3172: $newinststatus = '';
3173: $changeHash{'inststatus'} = $newinststatus;
3174: $newsettings{'inststatus'} = $othertitle;
3175: if ($newinststatus ne $oldinststatus) {
3176: $changed{'inststatus'} = $changeHash{'inststatus'};
1.378 raeburn 3177: foreach my $name ('portfolio','author') {
3178: ($newdefquota{$name},$newsettingstatus{$name}) =
3179: &Apache::loncommon::default_quota($env{'form.ccdomain'},$newinststatus,$name);
3180: }
1.286 raeburn 3181: }
3182: }
1.334 raeburn 3183: } elsif ($context ne 'selfcreate') {
3184: $canshow{'inststatus'} = 1;
1.337 raeburn 3185: $newsettings{'inststatus'} = $oldsettings{'inststatus'};
1.286 raeburn 3186: }
1.378 raeburn 3187: foreach my $name ('portfolio','author') {
3188: $changeHash{$name.'quota'} = $userenv{$name.'quota'};
3189: }
1.334 raeburn 3190: if ($context eq 'domain') {
1.378 raeburn 3191: foreach my $name ('portfolio','author') {
3192: if ($userenv{$name.'quota'} ne '') {
3193: $oldquota{$name} = $userenv{$name.'quota'};
3194: if ($env{'form.custom_'.$name.'quota'} == 1) {
3195: if ($env{'form.'.$name.'quota'} eq '') {
3196: $newquota{$name} = 0;
3197: } else {
3198: $newquota{$name} = $env{'form.'.$name.'quota'};
3199: $newquota{$name} =~ s/[^\d\.]//g;
3200: }
3201: if ($newquota{$name} != $oldquota{$name}) {
3202: if ("a_admin($newquota{$name},\%changeHash,$name)) {
3203: $changed{$name.'quota'} = 1;
3204: }
3205: }
1.334 raeburn 3206: } else {
1.378 raeburn 3207: if ("a_admin('',\%changeHash,$name)) {
3208: $changed{$name.'quota'} = 1;
3209: $newquota{$name} = $newdefquota{$name};
3210: $newisdefault{$name} = 1;
3211: }
1.334 raeburn 3212: }
1.149 raeburn 3213: } else {
1.378 raeburn 3214: $oldisdefault{$name} = 1;
3215: $oldquota{$name} = $olddefquota{$name};
3216: if ($env{'form.custom_'.$name.'quota'} == 1) {
3217: if ($env{'form.'.$name.'quota'} eq '') {
3218: $newquota{$name} = 0;
3219: } else {
3220: $newquota{$name} = $env{'form.'.$name.'quota'};
3221: $newquota{$name} =~ s/[^\d\.]//g;
3222: }
3223: if ("a_admin($newquota{$name},\%changeHash,$name)) {
3224: $changed{$name.'quota'} = 1;
3225: }
1.334 raeburn 3226: } else {
1.378 raeburn 3227: $newquota{$name} = $newdefquota{$name};
3228: $newisdefault{$name} = 1;
1.334 raeburn 3229: }
1.378 raeburn 3230: }
3231: if ($oldisdefault{$name}) {
3232: $oldsettingstext{'quota'}{$name} = &get_defaultquota_text($oldsettingstatus{$name});
1.383 raeburn 3233: } else {
3234: $oldsettingstext{'quota'}{$name} = &mt('custom quota: [_1] MB',$oldquota{$name});
1.378 raeburn 3235: }
3236: if ($newisdefault{$name}) {
3237: $newsettingstext{'quota'}{$name} = &get_defaultquota_text($newsettingstatus{$name});
1.383 raeburn 3238: } else {
3239: $newsettingstext{'quota'}{$name} = &mt('custom quota: [_1] MB',$newquota{$name});
1.134 raeburn 3240: }
3241: }
1.334 raeburn 3242: &tool_changes('tools',\@usertools,\%oldsettings,\%oldsettingstext,\%userenv,
3243: \%changeHash,\%changed,\%newsettings,\%newsettingstext);
3244: if ($env{'form.ccdomain'} eq $env{'request.role.domain'}) {
3245: &tool_changes('requestcourses',\@requestcourses,\%oldsettings,\%oldsettingstext,
3246: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
1.384 raeburn 3247: &tool_changes('requestauthor',\@requestauthor,\%oldsettings,\%oldsettingstext,
3248: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
1.149 raeburn 3249: } else {
1.334 raeburn 3250: &tool_changes('reqcrsotherdom',\@requestcourses,\%oldsettings,\%oldsettingstext,
3251: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
1.149 raeburn 3252: }
3253: }
1.334 raeburn 3254: foreach my $item (@userinfo) {
3255: if ($env{'form.c'.$item} ne $userenv{$item}) {
3256: $namechanged{$item} = 1;
3257: }
1.204 raeburn 3258: }
1.378 raeburn 3259: foreach my $name ('portfolio','author') {
1.390 bisitz 3260: $oldsettings{'quota'}{$name} = &mt('[_1] MB',$oldquota{$name});
3261: $newsettings{'quota'}{$name} = &mt('[_1] MB',$newquota{$name});
1.378 raeburn 3262: }
1.334 raeburn 3263: if ((keys(%namechanged) > 0) || (keys(%changed) > 0)) {
1.267 raeburn 3264: my ($chgresult,$namechgresult);
3265: if (keys(%changed) > 0) {
3266: $chgresult =
1.204 raeburn 3267: &Apache::lonnet::put('environment',\%changeHash,
3268: $env{'form.ccdomain'},$env{'form.ccuname'});
1.267 raeburn 3269: if ($chgresult eq 'ok') {
3270: if (($env{'user.name'} eq $env{'form.ccuname'}) &&
3271: ($env{'user.domain'} eq $env{'form.ccdomain'})) {
1.270 raeburn 3272: my %newenvhash;
3273: foreach my $key (keys(%changed)) {
1.299 raeburn 3274: if (($key eq 'official') || ($key eq 'unofficial')
1.403 raeburn 3275: || ($key eq 'community') || ($key eq 'textbook')) {
1.279 raeburn 3276: $newenvhash{'environment.requestcourses.'.$key} =
3277: $changeHash{'requestcourses.'.$key};
1.362 raeburn 3278: if ($changeHash{'requestcourses.'.$key}) {
1.332 raeburn 3279: $newenvhash{'environment.canrequest.'.$key} = 1;
1.279 raeburn 3280: } else {
3281: $newenvhash{'environment.canrequest.'.$key} =
3282: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
3283: $key,'reload','requestcourses');
3284: }
1.362 raeburn 3285: } elsif ($key eq 'requestauthor') {
3286: $newenvhash{'environment.'.$key} = $changeHash{$key};
3287: if ($changeHash{$key}) {
3288: $newenvhash{'environment.canrequest.author'} = 1;
3289: } else {
3290: $newenvhash{'environment.canrequest.author'} =
3291: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
3292: $key,'reload','requestauthor');
3293: }
1.275 raeburn 3294: } elsif ($key ne 'quota') {
1.270 raeburn 3295: $newenvhash{'environment.tools.'.$key} =
3296: $changeHash{'tools.'.$key};
1.279 raeburn 3297: if ($changeHash{'tools.'.$key} ne '') {
3298: $newenvhash{'environment.availabletools.'.$key} =
3299: $changeHash{'tools.'.$key};
3300: } else {
3301: $newenvhash{'environment.availabletools.'.$key} =
1.367 golterma 3302: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
3303: $key,'reload','tools');
1.279 raeburn 3304: }
1.270 raeburn 3305: }
3306: }
1.271 raeburn 3307: if (keys(%newenvhash)) {
3308: &Apache::lonnet::appenv(\%newenvhash);
3309: }
1.267 raeburn 3310: }
3311: }
1.204 raeburn 3312: }
1.334 raeburn 3313: if (keys(%namechanged) > 0) {
1.337 raeburn 3314: foreach my $field (@userinfo) {
3315: $changeHash{$field} = $env{'form.c'.$field};
3316: }
3317: # Make the change
1.204 raeburn 3318: $namechgresult =
3319: &Apache::lonnet::modifyuser($env{'form.ccdomain'},
3320: $env{'form.ccuname'},$changeHash{'id'},undef,undef,
3321: $changeHash{'firstname'},$changeHash{'middlename'},
3322: $changeHash{'lastname'},$changeHash{'generation'},
1.337 raeburn 3323: $changeHash{'id'},undef,$changeHash{'permanentemail'},undef,\@userinfo);
1.220 raeburn 3324: %userupdate = (
3325: lastname => $env{'form.clastname'},
3326: middlename => $env{'form.cmiddlename'},
3327: firstname => $env{'form.cfirstname'},
3328: generation => $env{'form.cgeneration'},
3329: id => $env{'form.cid'},
3330: );
1.204 raeburn 3331: }
1.334 raeburn 3332: if (((keys(%namechanged) > 0) && $namechgresult eq 'ok') ||
1.267 raeburn 3333: ((keys(%changed) > 0) && $chgresult eq 'ok')) {
1.28 matthew 3334: # Tell the user we changed the name
1.334 raeburn 3335: &display_userinfo($r,1,\@disporder,\%canshow,\@requestcourses,
1.362 raeburn 3336: \@usertools,\@requestauthor,\%userenv,\%changed,\%namechanged,
1.334 raeburn 3337: \%oldsettings, \%oldsettingstext,\%newsettings,
3338: \%newsettingstext);
1.203 raeburn 3339: if ($env{'form.cid'} ne $userenv{'id'}) {
3340: &Apache::lonnet::idput($env{'form.ccdomain'},
1.406.2.5 raeburn 3341: {$env{'form.ccuname'} => $env{'form.cid'}});
1.203 raeburn 3342: if (($recurseid) &&
3343: (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'}))) {
3344: my $idresult =
3345: &Apache::lonuserutils::propagate_id_change(
3346: $env{'form.ccuname'},$env{'form.ccdomain'},
3347: \%userupdate);
3348: $r->print('<br />'.$idresult.'<br />');
3349: }
1.196 raeburn 3350: }
1.149 raeburn 3351: if (($env{'form.ccdomain'} eq $env{'user.domain'}) &&
3352: ($env{'form.ccuname'} eq $env{'user.name'})) {
3353: my %newenvhash;
3354: foreach my $key (keys(%changeHash)) {
3355: $newenvhash{'environment.'.$key} = $changeHash{$key};
3356: }
1.238 raeburn 3357: &Apache::lonnet::appenv(\%newenvhash);
1.149 raeburn 3358: }
1.28 matthew 3359: } else { # error occurred
1.389 bisitz 3360: $r->print(
3361: '<p class="LC_error">'
3362: .&mt('Unable to successfully change environment for [_1] in domain [_2].',
3363: '"'.$env{'form.ccuname'}.'"',
3364: '"'.$env{'form.ccdomain'}.'"')
3365: .'</p>');
1.28 matthew 3366: }
1.334 raeburn 3367: } else { # End of if ($env ... ) logic
1.275 raeburn 3368: # They did not want to change the users name, quota, tool availability,
3369: # or ability to request creation of courses,
1.267 raeburn 3370: # but we can still tell them what the name and quota and availabilities are
1.334 raeburn 3371: &display_userinfo($r,undef,\@disporder,\%canshow,\@requestcourses,
1.362 raeburn 3372: \@usertools,\@requestauthor,\%userenv,\%changed,\%namechanged,\%oldsettings,
1.334 raeburn 3373: \%oldsettingstext,\%newsettings,\%newsettingstext);
1.28 matthew 3374: }
1.206 raeburn 3375: if (@mod_disallowed) {
3376: my ($rolestr,$contextname);
3377: if (@longroles > 0) {
3378: $rolestr = join(', ',@longroles);
3379: } else {
3380: $rolestr = &mt('No roles');
3381: }
3382: if ($context eq 'course') {
1.399 bisitz 3383: $contextname = 'course';
1.206 raeburn 3384: } elsif ($context eq 'author') {
1.399 bisitz 3385: $contextname = 'co-author';
1.206 raeburn 3386: }
3387: $r->print(&mt('The following fields were not updated: ').'<ul>');
3388: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
3389: foreach my $field (@mod_disallowed) {
3390: $r->print('<li>'.$fieldtitles{$field}.'</li>'."\n");
3391: }
1.207 raeburn 3392: $r->print('</ul>');
3393: if (@mod_disallowed == 1) {
1.399 bisitz 3394: $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 3395: } else {
1.399 bisitz 3396: $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 3397: }
1.292 bisitz 3398: my $helplink = 'javascript:helpMenu('."'display'".')';
3399: $r->print('<span class="LC_cusr_emph">'.$rolestr.'</span><br />'
3400: .&mt('Please contact your [_1]helpdesk[_2] for more information.'
3401: ,'<a href="'.$helplink.'">','</a>')
3402: .'<br />');
1.206 raeburn 3403: }
1.259 bisitz 3404: $r->print('<span class="LC_warning">'
3405: .$no_forceid_alert
3406: .&Apache::lonuserutils::print_namespacing_alerts($env{'form.ccdomain'},\%alerts,\%curr_rules)
3407: .'</span>');
1.4 www 3408: }
1.367 golterma 3409: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
1.220 raeburn 3410: if ($env{'form.action'} eq 'singlestudent') {
1.375 raeburn 3411: &enroll_single_student($r,$uhome,$amode,$genpwd,$now,$newuser,$context,
3412: $crstype,$showcredits,$defaultcredits);
1.386 bisitz 3413: my $linktext = ($crstype eq 'Community' ?
3414: &mt('Enroll Another Member') : &mt('Enroll Another Student'));
3415: $r->print(
3416: &Apache::lonhtmlcommon::actionbox([
3417: '<a href="javascript:backPage(document.userupdate)">'
3418: .($crstype eq 'Community' ?
3419: &mt('Enroll Another Member') : &mt('Enroll Another Student'))
3420: .'</a>']));
1.220 raeburn 3421: } else {
1.375 raeburn 3422: my @rolechanges = &update_roles($r,$context,$showcredits);
1.334 raeburn 3423: if (keys(%namechanged) > 0) {
1.220 raeburn 3424: if ($context eq 'course') {
3425: if (@userroles > 0) {
1.225 raeburn 3426: if ((@rolechanges == 0) ||
3427: (!(grep(/^st$/,@rolechanges)))) {
3428: if (grep(/^st$/,@userroles)) {
3429: my $classlistupdated =
3430: &Apache::lonuserutils::update_classlist($cdom,
1.220 raeburn 3431: $cnum,$env{'form.ccdomain'},
3432: $env{'form.ccuname'},\%userupdate);
1.225 raeburn 3433: }
1.220 raeburn 3434: }
3435: }
3436: }
3437: }
1.226 raeburn 3438: my $userinfo = &Apache::loncommon::plainname($env{'form.ccuname'},
1.233 raeburn 3439: $env{'form.ccdomain'});
3440: if ($env{'form.popup'}) {
3441: $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a></p>');
3442: } else {
1.367 golterma 3443: $r->print('<br />'.&Apache::lonhtmlcommon::actionbox(['<a href="javascript:backPage(document.userupdate,'."'$env{'form.prevphase'}','modify'".')">'
3444: .&mt('Modify this user: [_1]','<span class="LC_cusr_emph">'.$env{'form.ccuname'}.':'.$env{'form.ccdomain'}.' ('.$userinfo.')</span>').'</a>',
3445: '<a href="javascript:backPage(document.userupdate)">'.&mt('Create/Modify Another User').'</a>']));
1.233 raeburn 3446: }
1.220 raeburn 3447: }
3448: }
3449:
1.334 raeburn 3450: sub display_userinfo {
1.362 raeburn 3451: my ($r,$changed,$order,$canshow,$requestcourses,$usertools,$requestauthor,
3452: $userenv,$changedhash,$namechangedhash,$oldsetting,$oldsettingtext,
1.334 raeburn 3453: $newsetting,$newsettingtext) = @_;
3454: return unless (ref($order) eq 'ARRAY' &&
3455: ref($canshow) eq 'HASH' &&
3456: ref($requestcourses) eq 'ARRAY' &&
1.362 raeburn 3457: ref($requestauthor) eq 'ARRAY' &&
1.334 raeburn 3458: ref($usertools) eq 'ARRAY' &&
3459: ref($userenv) eq 'HASH' &&
3460: ref($changedhash) eq 'HASH' &&
3461: ref($oldsetting) eq 'HASH' &&
3462: ref($oldsettingtext) eq 'HASH' &&
3463: ref($newsetting) eq 'HASH' &&
3464: ref($newsettingtext) eq 'HASH');
3465: my %lt=&Apache::lonlocal::texthash(
1.372 raeburn 3466: 'ui' => 'User Information',
1.334 raeburn 3467: 'uic' => 'User Information Changed',
3468: 'firstname' => 'First Name',
3469: 'middlename' => 'Middle Name',
3470: 'lastname' => 'Last Name',
3471: 'generation' => 'Generation',
3472: 'id' => 'Student/Employee ID',
3473: 'permanentemail' => 'Permanent e-mail address',
1.378 raeburn 3474: 'portfolioquota' => 'Disk space allocated to portfolio files',
1.385 bisitz 3475: 'authorquota' => 'Disk space allocated to Authoring Space',
1.334 raeburn 3476: 'blog' => 'Blog Availability',
1.361 raeburn 3477: 'webdav' => 'WebDAV Availability',
1.334 raeburn 3478: 'aboutme' => 'Personal Information Page Availability',
3479: 'portfolio' => 'Portfolio Availability',
3480: 'official' => 'Can Request Official Courses',
3481: 'unofficial' => 'Can Request Unofficial Courses',
3482: 'community' => 'Can Request Communities',
1.384 raeburn 3483: 'textbook' => 'Can Request Textbook Courses',
1.362 raeburn 3484: 'requestauthor' => 'Can Request Author Role',
1.334 raeburn 3485: 'inststatus' => "Affiliation",
3486: 'prvs' => 'Previous Value:',
3487: 'chto' => 'Changed To:'
3488: );
3489: if ($changed) {
1.372 raeburn 3490: $r->print('<h3>'.$lt{'uic'}.'</h3>'.
1.367 golterma 3491: &Apache::loncommon::start_data_table().
3492: &Apache::loncommon::start_data_table_header_row());
1.334 raeburn 3493: $r->print("<th> </th>\n");
1.367 golterma 3494: $r->print('<th><b>'.$lt{'prvs'}.'</b></th>');
3495: $r->print('<th><span class="LC_nobreak"><b>'.$lt{'chto'}.'</b></span></th>');
3496: $r->print(&Apache::loncommon::end_data_table_header_row());
3497: my @userinfo = ('firstname','middlename','lastname','generation','permanentemail','id');
3498:
1.334 raeburn 3499: foreach my $item (@userinfo) {
3500: my $value = $env{'form.c'.$item};
1.367 golterma 3501: #show changes only:
1.383 raeburn 3502: unless ($value eq $userenv->{$item}){
1.367 golterma 3503: $r->print(&Apache::loncommon::start_data_table_row());
3504: $r->print("<td>$lt{$item}</td>\n");
1.383 raeburn 3505: $r->print("<td>".$userenv->{$item}."</td>\n");
1.367 golterma 3506: $r->print("<td>$value </td>\n");
3507: $r->print(&Apache::loncommon::end_data_table_row());
1.334 raeburn 3508: }
3509: }
3510: foreach my $entry (@{$order}) {
1.383 raeburn 3511: if ($canshow->{$entry}) {
3512: if (($entry eq 'requestcourses') || ($entry eq 'reqcrsotherdom') || ($entry eq 'requestauthor')) {
3513: my @items;
3514: if ($entry eq 'requestauthor') {
3515: @items = ($entry);
3516: } else {
3517: @items = @{$requestcourses};
1.384 raeburn 3518: }
1.383 raeburn 3519: foreach my $item (@items) {
3520: if (($newsetting->{$item} ne $oldsetting->{$item}) ||
3521: ($newsettingtext->{$item} ne $oldsettingtext->{$item})) {
3522: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3523: $r->print("<td>$lt{$item}</td>\n");
3524: $r->print("<td>".$oldsetting->{$item});
3525: if ($oldsettingtext->{$item}) {
3526: if ($oldsetting->{$item}) {
3527: $r->print(' -- ');
3528: }
3529: $r->print($oldsettingtext->{$item});
3530: }
3531: $r->print("</td>\n");
3532: $r->print("<td>".$newsetting->{$item});
3533: if ($newsettingtext->{$item}) {
3534: if ($newsetting->{$item}) {
3535: $r->print(' -- ');
3536: }
3537: $r->print($newsettingtext->{$item});
3538: }
3539: $r->print("</td>\n");
3540: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.334 raeburn 3541: }
3542: }
3543: } elsif ($entry eq 'tools') {
3544: foreach my $item (@{$usertools}) {
1.383 raeburn 3545: if ($newsetting->{$item} ne $oldsetting->{$item}) {
3546: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3547: $r->print("<td>$lt{$item}</td>\n");
3548: $r->print("<td>".$oldsetting->{$item}.' '.$oldsettingtext->{$item}."</td>\n");
3549: $r->print("<td>".$newsetting->{$item}.' '.$newsettingtext->{$item}."</td>\n");
3550: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.334 raeburn 3551: }
3552: }
1.378 raeburn 3553: } elsif ($entry eq 'quota') {
3554: if ((ref($oldsetting->{$entry}) eq 'HASH') && (ref($oldsettingtext->{$entry}) eq 'HASH') &&
3555: (ref($newsetting->{$entry}) eq 'HASH') && (ref($newsettingtext->{$entry}) eq 'HASH')) {
3556: foreach my $name ('portfolio','author') {
1.383 raeburn 3557: if ($newsetting->{$entry}->{$name} ne $oldsetting->{$entry}->{$name}) {
3558: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3559: $r->print("<td>$lt{$name.$entry}</td>\n");
3560: $r->print("<td>".$oldsettingtext->{$entry}->{$name}."</td>\n");
3561: $r->print("<td>".$newsettingtext->{$entry}->{$name}."</td>\n");
3562: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.378 raeburn 3563: }
3564: }
3565: }
1.334 raeburn 3566: } else {
1.383 raeburn 3567: if ($newsetting->{$entry} ne $oldsetting->{$entry}) {
3568: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3569: $r->print("<td>$lt{$entry}</td>\n");
3570: $r->print("<td>".$oldsetting->{$entry}.' '.$oldsettingtext->{$entry}."</td>\n");
3571: $r->print("<td>".$newsetting->{$entry}.' '.$newsettingtext->{$entry}."</td>\n");
3572: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.334 raeburn 3573: }
3574: }
3575: }
3576: }
1.367 golterma 3577: $r->print(&Apache::loncommon::end_data_table().'<br />');
1.372 raeburn 3578: } else {
3579: $r->print('<h3>'.$lt{'ui'}.'</h3>'.
3580: '<p>'.&mt('No changes made to user information').'</p>');
1.334 raeburn 3581: }
3582: return;
3583: }
3584:
1.275 raeburn 3585: sub tool_changes {
3586: my ($context,$usertools,$oldaccess,$oldaccesstext,$userenv,$changeHash,
3587: $changed,$newaccess,$newaccesstext) = @_;
3588: if (!((ref($usertools) eq 'ARRAY') && (ref($oldaccess) eq 'HASH') &&
3589: (ref($oldaccesstext) eq 'HASH') && (ref($userenv) eq 'HASH') &&
3590: (ref($changeHash) eq 'HASH') && (ref($changed) eq 'HASH') &&
3591: (ref($newaccess) eq 'HASH') && (ref($newaccesstext) eq 'HASH'))) {
3592: return;
3593: }
1.383 raeburn 3594: my %reqdisplay = &requestchange_display();
1.300 raeburn 3595: if ($context eq 'reqcrsotherdom') {
1.309 raeburn 3596: my @options = ('approval','validate','autolimit');
1.306 raeburn 3597: my $optregex = join('|',@options);
1.300 raeburn 3598: my $cdom = $env{'request.role.domain'};
3599: foreach my $tool (@{$usertools}) {
1.383 raeburn 3600: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
1.314 raeburn 3601: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
1.300 raeburn 3602: $changeHash->{$context.'.'.$tool} = $userenv->{$context.'.'.$tool};
1.383 raeburn 3603: my ($newop,$limit);
1.314 raeburn 3604: if ($env{'form.'.$context.'_'.$tool}) {
3605: $newop = $env{'form.'.$context.'_'.$tool};
3606: if ($newop eq 'autolimit') {
1.383 raeburn 3607: $limit = $env{'form.'.$context.'_'.$tool.'_limit'};
1.314 raeburn 3608: $limit =~ s/\D+//g;
3609: $newop .= '='.$limit;
3610: }
3611: }
1.300 raeburn 3612: if ($userenv->{$context.'.'.$tool} eq '') {
1.314 raeburn 3613: if ($newop) {
3614: $changed->{$tool}=&tool_admin($tool,$cdom.':'.$newop,
1.300 raeburn 3615: $changeHash,$context);
3616: if ($changed->{$tool}) {
1.383 raeburn 3617: if ($newop =~ /^autolimit/) {
3618: if ($limit) {
3619: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3620: } else {
3621: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3622: }
3623: } else {
3624: $newaccesstext->{$tool} = $reqdisplay{$newop};
3625: }
1.300 raeburn 3626: } else {
3627: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
3628: }
3629: }
3630: } else {
3631: my @curr = split(',',$userenv->{$context.'.'.$tool});
3632: my @new;
3633: my $changedoms;
1.314 raeburn 3634: foreach my $req (@curr) {
3635: if ($req =~ /^\Q$cdom\E\:($optregex\=?\d*)$/) {
3636: my $oldop = $1;
1.383 raeburn 3637: if ($oldop =~ /^autolimit=(\d*)/) {
3638: my $limit = $1;
3639: if ($limit) {
3640: $oldaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3641: } else {
3642: $oldaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3643: }
3644: } else {
3645: $oldaccesstext->{$tool} = $reqdisplay{$oldop};
3646: }
1.314 raeburn 3647: if ($oldop ne $newop) {
3648: $changedoms = 1;
3649: foreach my $item (@curr) {
3650: my ($reqdom,$option) = split(':',$item);
3651: unless ($reqdom eq $cdom) {
3652: push(@new,$item);
3653: }
3654: }
3655: if ($newop) {
3656: push(@new,$cdom.':'.$newop);
1.300 raeburn 3657: }
1.314 raeburn 3658: @new = sort(@new);
1.300 raeburn 3659: }
1.314 raeburn 3660: last;
1.300 raeburn 3661: }
1.314 raeburn 3662: }
3663: if ((!$changedoms) && ($newop)) {
1.300 raeburn 3664: $changedoms = 1;
1.306 raeburn 3665: @new = sort(@curr,$cdom.':'.$newop);
1.300 raeburn 3666: }
3667: if ($changedoms) {
1.314 raeburn 3668: my $newdomstr;
1.300 raeburn 3669: if (@new) {
3670: $newdomstr = join(',',@new);
3671: }
3672: $changed->{$tool}=&tool_admin($tool,$newdomstr,$changeHash,
3673: $context);
3674: if ($changed->{$tool}) {
3675: if ($env{'form.'.$context.'_'.$tool}) {
1.306 raeburn 3676: if ($env{'form.'.$context.'_'.$tool} eq 'autolimit') {
1.314 raeburn 3677: my $limit = $env{'form.'.$context.'_'.$tool.'_limit'};
3678: $limit =~ s/\D+//g;
3679: if ($limit) {
1.383 raeburn 3680: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
1.314 raeburn 3681: } else {
1.383 raeburn 3682: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
1.306 raeburn 3683: }
1.314 raeburn 3684: } else {
1.306 raeburn 3685: $newaccesstext->{$tool} = $reqdisplay{$env{'form.'.$context.'_'.$tool}};
3686: }
1.300 raeburn 3687: } else {
1.383 raeburn 3688: $newaccesstext->{$tool} = &mt("availability set to 'off'");
1.300 raeburn 3689: }
3690: }
3691: }
3692: }
3693: }
3694: return;
3695: }
1.275 raeburn 3696: foreach my $tool (@{$usertools}) {
1.383 raeburn 3697: my ($newval,$limit,$envkey);
1.362 raeburn 3698: $envkey = $context.'.'.$tool;
1.306 raeburn 3699: if ($context eq 'requestcourses') {
3700: $newval = $env{'form.crsreq_'.$tool};
3701: if ($newval eq 'autolimit') {
1.383 raeburn 3702: $limit = $env{'form.crsreq_'.$tool.'_limit'};
3703: $limit =~ s/\D+//g;
3704: $newval .= '='.$limit;
1.306 raeburn 3705: }
1.362 raeburn 3706: } elsif ($context eq 'requestauthor') {
3707: $newval = $env{'form.'.$context};
3708: $envkey = $context;
1.314 raeburn 3709: } else {
1.306 raeburn 3710: $newval = $env{'form.'.$context.'_'.$tool};
3711: }
1.362 raeburn 3712: if ($userenv->{$envkey} ne '') {
1.275 raeburn 3713: $oldaccess->{$tool} = &mt('custom');
1.383 raeburn 3714: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3715: if ($userenv->{$envkey} =~ /^autolimit=(\d*)$/) {
3716: my $currlimit = $1;
3717: if ($currlimit eq '') {
3718: $oldaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3719: } else {
3720: $oldaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$currlimit);
3721: }
3722: } elsif ($userenv->{$envkey}) {
3723: $oldaccesstext->{$tool} = $reqdisplay{$userenv->{$envkey}};
3724: } else {
3725: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
3726: }
1.275 raeburn 3727: } else {
1.383 raeburn 3728: if ($userenv->{$envkey}) {
3729: $oldaccesstext->{$tool} = &mt("availability set to 'on'");
3730: } else {
3731: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
3732: }
1.275 raeburn 3733: }
1.362 raeburn 3734: $changeHash->{$envkey} = $userenv->{$envkey};
1.275 raeburn 3735: if ($env{'form.custom'.$tool} == 1) {
1.362 raeburn 3736: if ($newval ne $userenv->{$envkey}) {
1.306 raeburn 3737: $changed->{$tool} = &tool_admin($tool,$newval,$changeHash,
3738: $context);
1.275 raeburn 3739: if ($changed->{$tool}) {
3740: $newaccess->{$tool} = &mt('custom');
1.383 raeburn 3741: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3742: if ($newval =~ /^autolimit/) {
3743: if ($limit) {
3744: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3745: } else {
3746: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3747: }
3748: } elsif ($newval) {
3749: $newaccesstext->{$tool} = $reqdisplay{$newval};
3750: } else {
3751: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3752: }
1.275 raeburn 3753: } else {
1.383 raeburn 3754: if ($newval) {
3755: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3756: } else {
3757: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3758: }
1.275 raeburn 3759: }
3760: } else {
3761: $newaccess->{$tool} = $oldaccess->{$tool};
1.383 raeburn 3762: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3763: if ($newval =~ /^autolimit/) {
3764: if ($limit) {
3765: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3766: } else {
3767: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3768: }
3769: } elsif ($newval) {
3770: $newaccesstext->{$tool} = $reqdisplay{$newval};
3771: } else {
3772: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3773: }
1.275 raeburn 3774: } else {
1.383 raeburn 3775: if ($userenv->{$context.'.'.$tool}) {
3776: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3777: } else {
3778: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3779: }
1.275 raeburn 3780: }
3781: }
3782: } else {
3783: $newaccess->{$tool} = $oldaccess->{$tool};
3784: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
3785: }
3786: } else {
3787: $changed->{$tool} = &tool_admin($tool,'',$changeHash,$context);
3788: if ($changed->{$tool}) {
3789: $newaccess->{$tool} = &mt('default');
3790: } else {
3791: $newaccess->{$tool} = $oldaccess->{$tool};
1.383 raeburn 3792: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3793: if ($newval =~ /^autolimit/) {
3794: if ($limit) {
3795: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3796: } else {
3797: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3798: }
3799: } elsif ($newval) {
3800: $newaccesstext->{$tool} = $reqdisplay{$newval};
3801: } else {
3802: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3803: }
1.275 raeburn 3804: } else {
1.383 raeburn 3805: if ($userenv->{$context.'.'.$tool}) {
3806: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3807: } else {
3808: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3809: }
1.275 raeburn 3810: }
3811: }
3812: }
3813: } else {
3814: $oldaccess->{$tool} = &mt('default');
3815: if ($env{'form.custom'.$tool} == 1) {
1.306 raeburn 3816: $changed->{$tool} = &tool_admin($tool,$newval,$changeHash,
3817: $context);
1.275 raeburn 3818: if ($changed->{$tool}) {
3819: $newaccess->{$tool} = &mt('custom');
1.383 raeburn 3820: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3821: if ($newval =~ /^autolimit/) {
3822: if ($limit) {
3823: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3824: } else {
3825: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3826: }
3827: } elsif ($newval) {
3828: $newaccesstext->{$tool} = $reqdisplay{$newval};
3829: } else {
3830: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3831: }
1.275 raeburn 3832: } else {
1.383 raeburn 3833: if ($newval) {
3834: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3835: } else {
3836: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3837: }
1.275 raeburn 3838: }
3839: } else {
3840: $newaccess->{$tool} = $oldaccess->{$tool};
3841: }
3842: } else {
3843: $newaccess->{$tool} = $oldaccess->{$tool};
3844: }
3845: }
3846: }
3847: return;
3848: }
3849:
1.220 raeburn 3850: sub update_roles {
1.375 raeburn 3851: my ($r,$context,$showcredits) = @_;
1.4 www 3852: my $now=time;
1.225 raeburn 3853: my @rolechanges;
1.220 raeburn 3854: my %disallowed;
1.73 sakharuk 3855: $r->print('<h3>'.&mt('Modifying Roles').'</h3>');
1.404 raeburn 3856: foreach my $key (keys(%env)) {
1.135 raeburn 3857: next if (! $env{$key});
1.190 raeburn 3858: next if ($key eq 'form.action');
1.27 matthew 3859: # Revoke roles
1.135 raeburn 3860: if ($key=~/^form\.rev/) {
3861: if ($key=~/^form\.rev\:([^\_]+)\_([^\_\.]+)$/) {
1.64 www 3862: # Revoke standard role
1.170 albertel 3863: my ($scope,$role) = ($1,$2);
3864: my $result =
3865: &Apache::lonnet::revokerole($env{'form.ccdomain'},
3866: $env{'form.ccuname'},
1.239 raeburn 3867: $scope,$role,'','',$context);
1.367 golterma 3868: $r->print(&Apache::lonhtmlcommon::confirm_success(
1.369 bisitz 3869: &mt('Revoking [_1] in [_2]',
3870: &Apache::lonnet::plaintext($role),
1.372 raeburn 3871: &Apache::loncommon::show_role_extent($scope,$context,$role)),
1.369 bisitz 3872: $result ne "ok").'<br />');
3873: if ($result ne "ok") {
3874: $r->print(&mt('Error: [_1]',$result).'<br />');
3875: }
1.170 albertel 3876: if ($role eq 'st') {
1.202 raeburn 3877: my $result =
1.198 raeburn 3878: &Apache::lonuserutils::classlist_drop($scope,
3879: $env{'form.ccuname'},$env{'form.ccdomain'},
1.202 raeburn 3880: $now);
1.367 golterma 3881: $r->print(&Apache::lonhtmlcommon::confirm_success($result));
1.53 www 3882: }
1.225 raeburn 3883: if (!grep(/^\Q$role\E$/,@rolechanges)) {
3884: push(@rolechanges,$role);
3885: }
1.196 raeburn 3886: }
1.195 raeburn 3887: if ($key=~m{^form\.rev\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}s) {
1.64 www 3888: # Revoke custom role
1.369 bisitz 3889: my $result = &Apache::lonnet::revokecustomrole(
3890: $env{'form.ccdomain'},$env{'form.ccuname'},$1,$2,$3,$4,'','',$context);
1.367 golterma 3891: $r->print(&Apache::lonhtmlcommon::confirm_success(
1.369 bisitz 3892: &mt('Revoking custom role [_1] by [_2] in [_3]',
1.372 raeburn 3893: $4,$3.':'.$2,&Apache::loncommon::show_role_extent($1,$context,'cr')),
1.369 bisitz 3894: $result ne 'ok').'<br />');
3895: if ($result ne "ok") {
3896: $r->print(&mt('Error: [_1]',$result).'<br />');
3897: }
1.225 raeburn 3898: if (!grep(/^cr$/,@rolechanges)) {
3899: push(@rolechanges,'cr');
3900: }
1.64 www 3901: }
1.135 raeburn 3902: } elsif ($key=~/^form\.del/) {
3903: if ($key=~/^form\.del\:([^\_]+)\_([^\_\.]+)$/) {
1.116 raeburn 3904: # Delete standard role
1.170 albertel 3905: my ($scope,$role) = ($1,$2);
3906: my $result =
3907: &Apache::lonnet::assignrole($env{'form.ccdomain'},
3908: $env{'form.ccuname'},
1.239 raeburn 3909: $scope,$role,$now,0,1,'',
3910: $context);
1.367 golterma 3911: $r->print(&Apache::lonhtmlcommon::confirm_success(
3912: &mt('Deleting [_1] in [_2]',
1.369 bisitz 3913: &Apache::lonnet::plaintext($role),
1.372 raeburn 3914: &Apache::loncommon::show_role_extent($scope,$context,$role)),
1.369 bisitz 3915: $result ne 'ok').'<br />');
3916: if ($result ne "ok") {
3917: $r->print(&mt('Error: [_1]',$result).'<br />');
3918: }
1.367 golterma 3919:
1.170 albertel 3920: if ($role eq 'st') {
1.202 raeburn 3921: my $result =
1.198 raeburn 3922: &Apache::lonuserutils::classlist_drop($scope,
3923: $env{'form.ccuname'},$env{'form.ccdomain'},
1.202 raeburn 3924: $now);
1.369 bisitz 3925: $r->print(&Apache::lonhtmlcommon::confirm_success($result));
1.81 albertel 3926: }
1.225 raeburn 3927: if (!grep(/^\Q$role\E$/,@rolechanges)) {
3928: push(@rolechanges,$role);
3929: }
1.116 raeburn 3930: }
1.139 albertel 3931: if ($key=~m{^form\.del\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
1.116 raeburn 3932: my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
3933: # Delete custom role
1.369 bisitz 3934: my $result =
3935: &Apache::lonnet::assigncustomrole($env{'form.ccdomain'},
3936: $env{'form.ccuname'},$url,$rdom,$rnam,$rolename,$now,
3937: 0,1,$context);
3938: $r->print(&Apache::lonhtmlcommon::confirm_success(&mt('Deleting custom role [_1] by [_2] in [_3]',
1.372 raeburn 3939: $rolename,$rnam.':'.$rdom,&Apache::loncommon::show_role_extent($1,$context,'cr')),
1.369 bisitz 3940: $result ne "ok").'<br />');
3941: if ($result ne "ok") {
3942: $r->print(&mt('Error: [_1]',$result).'<br />');
3943: }
1.367 golterma 3944:
1.225 raeburn 3945: if (!grep(/^cr$/,@rolechanges)) {
3946: push(@rolechanges,'cr');
3947: }
1.116 raeburn 3948: }
1.135 raeburn 3949: } elsif ($key=~/^form\.ren/) {
1.101 albertel 3950: my $udom = $env{'form.ccdomain'};
3951: my $uname = $env{'form.ccuname'};
1.116 raeburn 3952: # Re-enable standard role
1.135 raeburn 3953: if ($key=~/^form\.ren\:([^\_]+)\_([^\_\.]+)$/) {
1.89 raeburn 3954: my $url = $1;
3955: my $role = $2;
3956: my $logmsg;
3957: my $output;
3958: if ($role eq 'st') {
1.141 albertel 3959: if ($url =~ m-^/($match_domain)/($match_courseid)/?(\w*)$-) {
1.374 raeburn 3960: my ($cdom,$cnum,$csec) = ($1,$2,$3);
1.375 raeburn 3961: my $credits;
3962: if ($showcredits) {
3963: my $defaultcredits =
3964: &Apache::lonuserutils::get_defaultcredits($cdom,$cnum);
3965: $credits = &get_user_credits($defaultcredits,$cdom,$cnum);
3966: }
3967: my $result = &Apache::loncommon::commit_studentrole(\$logmsg,$udom,$uname,$url,$role,$now,0,$cdom,$cnum,$csec,$context,$credits);
1.220 raeburn 3968: if (($result =~ /^error/) || ($result eq 'not_in_class') || ($result eq 'unknown_course') || ($result eq 'refused')) {
1.223 raeburn 3969: if ($result eq 'refused' && $logmsg) {
3970: $output = $logmsg;
3971: } else {
1.369 bisitz 3972: $output = &mt('Error: [_1]',$result)."\n";
1.223 raeburn 3973: }
1.89 raeburn 3974: } else {
1.372 raeburn 3975: $output = &Apache::lonhtmlcommon::confirm_success(&mt('Assigning [_1] in [_2] starting [_3]',
3976: &Apache::lonnet::plaintext($role),
3977: &Apache::loncommon::show_role_extent($url,$context,'st'),
3978: &Apache::lonlocal::locallocaltime($now))).'<br />'.$logmsg.'<br />';
1.89 raeburn 3979: }
3980: }
3981: } else {
1.101 albertel 3982: my $result=&Apache::lonnet::assignrole($env{'form.ccdomain'},
1.239 raeburn 3983: $env{'form.ccuname'},$url,$role,0,$now,'','',
3984: $context);
1.367 golterma 3985: $output = &Apache::lonhtmlcommon::confirm_success(&mt('Re-enabling [_1] in [_2]',
1.372 raeburn 3986: &Apache::lonnet::plaintext($role),
3987: &Apache::loncommon::show_role_extent($url,$context,$role)),$result ne "ok").'<br />';
1.369 bisitz 3988: if ($result ne "ok") {
3989: $output .= &mt('Error: [_1]',$result).'<br />';
3990: }
3991: }
1.89 raeburn 3992: $r->print($output);
1.225 raeburn 3993: if (!grep(/^\Q$role\E$/,@rolechanges)) {
3994: push(@rolechanges,$role);
3995: }
1.113 raeburn 3996: }
1.116 raeburn 3997: # Re-enable custom role
1.139 albertel 3998: if ($key=~m{^form\.ren\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
1.116 raeburn 3999: my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
4000: my $result = &Apache::lonnet::assigncustomrole(
4001: $env{'form.ccdomain'}, $env{'form.ccuname'},
1.240 raeburn 4002: $url,$rdom,$rnam,$rolename,0,$now,undef,$context);
1.369 bisitz 4003: $r->print(&Apache::lonhtmlcommon::confirm_success(
4004: &mt('Re-enabling custom role [_1] by [_2] in [_3]',
1.372 raeburn 4005: $rolename,$rnam.':'.$rdom,&Apache::loncommon::show_role_extent($1,$context,'cr')),
1.369 bisitz 4006: $result ne "ok").'<br />');
4007: if ($result ne "ok") {
4008: $r->print(&mt('Error: [_1]',$result).'<br />');
4009: }
1.225 raeburn 4010: if (!grep(/^cr$/,@rolechanges)) {
4011: push(@rolechanges,'cr');
4012: }
1.116 raeburn 4013: }
1.135 raeburn 4014: } elsif ($key=~/^form\.act/) {
1.101 albertel 4015: my $udom = $env{'form.ccdomain'};
4016: my $uname = $env{'form.ccuname'};
1.141 albertel 4017: if ($key=~/^form\.act\_($match_domain)\_($match_courseid)\_cr_cr_($match_domain)_($match_username)_([^\_]+)$/) {
1.65 www 4018: # Activate a custom role
1.83 albertel 4019: my ($one,$two,$three,$four,$five)=($1,$2,$3,$4,$5);
4020: my $url='/'.$one.'/'.$two;
4021: my $full=$one.'_'.$two.'_cr_cr_'.$three.'_'.$four.'_'.$five;
1.65 www 4022:
1.101 albertel 4023: my $start = ( $env{'form.start_'.$full} ?
4024: $env{'form.start_'.$full} :
1.88 raeburn 4025: $now );
1.101 albertel 4026: my $end = ( $env{'form.end_'.$full} ?
4027: $env{'form.end_'.$full} :
1.88 raeburn 4028: 0 );
4029:
4030: # split multiple sections
4031: my %sections = ();
1.101 albertel 4032: my $num_sections = &build_roles($env{'form.sec_'.$full},\%sections,$5);
1.88 raeburn 4033: if ($num_sections == 0) {
1.240 raeburn 4034: $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$url,$three,$four,$five,$start,$end,$context));
1.88 raeburn 4035: } else {
1.114 albertel 4036: my %curr_groups =
1.117 raeburn 4037: &Apache::longroup::coursegroups($one,$two);
1.404 raeburn 4038: foreach my $sec (sort {$a cmp $b} keys(%sections)) {
1.113 raeburn 4039: if (($sec eq 'none') || ($sec eq 'all') ||
4040: exists($curr_groups{$sec})) {
4041: $disallowed{$sec} = $url;
4042: next;
4043: }
4044: my $securl = $url.'/'.$sec;
1.240 raeburn 4045: $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$securl,$three,$four,$five,$start,$end,$context));
1.88 raeburn 4046: }
4047: }
1.225 raeburn 4048: if (!grep(/^cr$/,@rolechanges)) {
4049: push(@rolechanges,'cr');
4050: }
1.142 raeburn 4051: } elsif ($key=~/^form\.act\_($match_domain)\_($match_name)\_([^\_]+)$/) {
1.27 matthew 4052: # Activate roles for sections with 3 id numbers
4053: # set start, end times, and the url for the class
1.83 albertel 4054: my ($one,$two,$three)=($1,$2,$3);
1.101 albertel 4055: my $start = ( $env{'form.start_'.$one.'_'.$two.'_'.$three} ?
4056: $env{'form.start_'.$one.'_'.$two.'_'.$three} :
1.27 matthew 4057: $now );
1.101 albertel 4058: my $end = ( $env{'form.end_'.$one.'_'.$two.'_'.$three} ?
4059: $env{'form.end_'.$one.'_'.$two.'_'.$three} :
1.27 matthew 4060: 0 );
1.83 albertel 4061: my $url='/'.$one.'/'.$two;
1.88 raeburn 4062: my $type = 'three';
4063: # split multiple sections
4064: my %sections = ();
1.101 albertel 4065: my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two.'_'.$three},\%sections,$three);
1.375 raeburn 4066: my $credits;
4067: if ($three eq 'st') {
4068: if ($showcredits) {
4069: my $defaultcredits =
4070: &Apache::lonuserutils::get_defaultcredits($one,$two);
4071: $credits = $env{'form.credits_'.$one.'_'.$two.'_'.$three};
4072: $credits =~ s/[^\d\.]//g;
4073: if ($credits eq $defaultcredits) {
4074: undef($credits);
4075: }
4076: }
4077: }
1.88 raeburn 4078: if ($num_sections == 0) {
1.375 raeburn 4079: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'',$context,$credits));
1.88 raeburn 4080: } else {
1.114 albertel 4081: my %curr_groups =
1.117 raeburn 4082: &Apache::longroup::coursegroups($one,$two);
1.88 raeburn 4083: my $emptysec = 0;
1.404 raeburn 4084: foreach my $sec (sort {$a cmp $b} keys(%sections)) {
1.88 raeburn 4085: $sec =~ s/\W//g;
1.113 raeburn 4086: if ($sec ne '') {
4087: if (($sec eq 'none') || ($sec eq 'all') ||
4088: exists($curr_groups{$sec})) {
4089: $disallowed{$sec} = $url;
4090: next;
4091: }
1.88 raeburn 4092: my $securl = $url.'/'.$sec;
1.375 raeburn 4093: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$three,$start,$end,$one,$two,$sec,$context,$credits));
1.88 raeburn 4094: } else {
4095: $emptysec = 1;
4096: }
4097: }
4098: if ($emptysec) {
1.375 raeburn 4099: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'',$context,$credits));
1.88 raeburn 4100: }
1.225 raeburn 4101: }
4102: if (!grep(/^\Q$three\E$/,@rolechanges)) {
4103: push(@rolechanges,$three);
4104: }
1.135 raeburn 4105: } elsif ($key=~/^form\.act\_([^\_]+)\_([^\_]+)$/) {
1.27 matthew 4106: # Activate roles for sections with two id numbers
4107: # set start, end times, and the url for the class
1.101 albertel 4108: my $start = ( $env{'form.start_'.$1.'_'.$2} ?
4109: $env{'form.start_'.$1.'_'.$2} :
1.27 matthew 4110: $now );
1.101 albertel 4111: my $end = ( $env{'form.end_'.$1.'_'.$2} ?
4112: $env{'form.end_'.$1.'_'.$2} :
1.27 matthew 4113: 0 );
1.225 raeburn 4114: my $one = $1;
4115: my $two = $2;
4116: my $url='/'.$one.'/';
1.88 raeburn 4117: # split multiple sections
4118: my %sections = ();
1.225 raeburn 4119: my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two},\%sections,$two);
1.88 raeburn 4120: if ($num_sections == 0) {
1.240 raeburn 4121: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,'',$context));
1.88 raeburn 4122: } else {
4123: my $emptysec = 0;
1.404 raeburn 4124: foreach my $sec (sort {$a cmp $b} keys(%sections)) {
1.88 raeburn 4125: if ($sec ne '') {
4126: my $securl = $url.'/'.$sec;
1.240 raeburn 4127: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$two,$start,$end,$one,undef,$sec,$context));
1.88 raeburn 4128: } else {
4129: $emptysec = 1;
4130: }
4131: }
4132: if ($emptysec) {
1.240 raeburn 4133: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,'',$context));
1.88 raeburn 4134: }
4135: }
1.225 raeburn 4136: if (!grep(/^\Q$two\E$/,@rolechanges)) {
4137: push(@rolechanges,$two);
4138: }
1.64 www 4139: } else {
1.190 raeburn 4140: $r->print('<p><span class="LC_error">'.&mt('ERROR').': '.&mt('Unknown command').' <tt>'.$key.'</tt></span></p><br />');
1.64 www 4141: }
1.113 raeburn 4142: foreach my $key (sort(keys(%disallowed))) {
1.274 bisitz 4143: $r->print('<p class="LC_warning">');
1.113 raeburn 4144: if (($key eq 'none') || ($key eq 'all')) {
1.274 bisitz 4145: $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 4146: } else {
1.274 bisitz 4147: $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 4148: }
1.274 bisitz 4149: $r->print('</p><p>'
4150: .&mt('Please [_1]go back[_2] and choose a different section name.'
4151: ,'<a href="javascript:history.go(-1)'
4152: ,'</a>')
4153: .'</p><br />'
4154: );
1.113 raeburn 4155: }
4156: }
1.101 albertel 4157: } # End of foreach (keys(%env))
1.75 www 4158: # Flush the course logs so reverse user roles immediately updated
1.349 raeburn 4159: $r->register_cleanup(\&Apache::lonnet::flushcourselogs);
1.225 raeburn 4160: if (@rolechanges == 0) {
1.372 raeburn 4161: $r->print('<p>'.&mt('No roles to modify').'</p>');
1.193 raeburn 4162: }
1.225 raeburn 4163: return @rolechanges;
1.220 raeburn 4164: }
4165:
1.375 raeburn 4166: sub get_user_credits {
4167: my ($uname,$udom,$defaultcredits,$cdom,$cnum) = @_;
4168: if ($cdom eq '' || $cnum eq '') {
4169: return unless ($env{'request.course.id'});
4170: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
4171: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
4172: }
4173: my $credits;
4174: my %currhash =
4175: &Apache::lonnet::get('classlist',[$uname.':'.$udom],$cdom,$cnum);
4176: if (keys(%currhash) > 0) {
4177: my @items = split(/:/,$currhash{$uname.':'.$udom});
4178: my $crdidx = &Apache::loncoursedata::CL_CREDITS() - 3;
4179: $credits = $items[$crdidx];
4180: $credits =~ s/[^\d\.]//g;
4181: }
4182: if ($credits eq $defaultcredits) {
4183: undef($credits);
4184: }
4185: return $credits;
4186: }
4187:
1.220 raeburn 4188: sub enroll_single_student {
1.375 raeburn 4189: my ($r,$uhome,$amode,$genpwd,$now,$newuser,$context,$crstype,
4190: $showcredits,$defaultcredits) = @_;
1.318 raeburn 4191: $r->print('<h3>');
4192: if ($crstype eq 'Community') {
4193: $r->print(&mt('Enrolling Member'));
4194: } else {
4195: $r->print(&mt('Enrolling Student'));
4196: }
4197: $r->print('</h3>');
1.220 raeburn 4198:
4199: # Remove non alphanumeric values from section
4200: $env{'form.sections'}=~s/\W//g;
4201:
1.375 raeburn 4202: my $credits;
4203: if (($showcredits) && ($env{'form.credits'} ne '')) {
4204: $credits = $env{'form.credits'};
4205: $credits =~ s/[^\d\.]//g;
4206: if ($credits ne '') {
4207: if ($credits eq $defaultcredits) {
4208: undef($credits);
4209: }
4210: }
4211: }
4212:
1.220 raeburn 4213: # Clean out any old student roles the user has in this class.
4214: &Apache::lonuserutils::modifystudent($env{'form.ccdomain'},
4215: $env{'form.ccuname'},$env{'request.course.id'},undef,$uhome);
4216: my ($startdate,$enddate) = &Apache::lonuserutils::get_dates_from_form();
4217: my $enroll_result =
4218: &Apache::lonnet::modify_student_enrollment($env{'form.ccdomain'},
4219: $env{'form.ccuname'},$env{'form.cid'},$env{'form.cfirstname'},
4220: $env{'form.cmiddlename'},$env{'form.clastname'},
4221: $env{'form.generation'},$env{'form.sections'},$enddate,
1.375 raeburn 4222: $startdate,'manual',undef,$env{'request.course.id'},'',$context,
4223: $credits);
1.220 raeburn 4224: if ($enroll_result =~ /^ok/) {
1.381 bisitz 4225: $r->print(&mt('[_1] enrolled','<b>'.$env{'form.ccuname'}.':'.$env{'form.ccdomain'}.'</b>'));
1.220 raeburn 4226: if ($env{'form.sections'} ne '') {
4227: $r->print(' '.&mt('in section [_1]',$env{'form.sections'}));
4228: }
4229: my ($showstart,$showend);
4230: if ($startdate <= $now) {
4231: $showstart = &mt('Access starts immediately');
4232: } else {
4233: $showstart = &mt('Access starts: ').&Apache::lonlocal::locallocaltime($startdate);
4234: }
4235: if ($enddate == 0) {
4236: $showend = &mt('ends: no ending date');
4237: } else {
4238: $showend = &mt('ends: ').&Apache::lonlocal::locallocaltime($enddate);
4239: }
4240: $r->print('.<br />'.$showstart.'; '.$showend);
4241: if ($startdate <= $now && !$newuser) {
1.386 bisitz 4242: $r->print('<p class="LC_info">');
1.318 raeburn 4243: if ($crstype eq 'Community') {
1.392 raeburn 4244: $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 4245: } else {
1.392 raeburn 4246: $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 4247: }
4248: $r->print('</p>');
1.220 raeburn 4249: }
4250: } else {
4251: $r->print(&mt('unable to enroll').": ".$enroll_result);
4252: }
4253: return;
1.188 raeburn 4254: }
4255:
1.204 raeburn 4256: sub get_defaultquota_text {
4257: my ($settingstatus) = @_;
4258: my $defquotatext;
4259: if ($settingstatus eq '') {
1.383 raeburn 4260: $defquotatext = &mt('default');
1.204 raeburn 4261: } else {
4262: my ($usertypes,$order) =
4263: &Apache::lonnet::retrieve_inst_usertypes($env{'form.ccdomain'});
4264: if ($usertypes->{$settingstatus} eq '') {
1.383 raeburn 4265: $defquotatext = &mt('default');
1.204 raeburn 4266: } else {
1.383 raeburn 4267: $defquotatext = &mt('default for [_1]',$usertypes->{$settingstatus});
1.204 raeburn 4268: }
4269: }
4270: return $defquotatext;
4271: }
4272:
1.188 raeburn 4273: sub update_result_form {
4274: my ($uhome) = @_;
4275: my $outcome =
1.367 golterma 4276: '<form name="userupdate" method="post" action="">'."\n";
1.160 raeburn 4277: foreach my $item ('srchby','srchin','srchtype','srchterm','srchdomain','ccuname','ccdomain') {
1.188 raeburn 4278: $outcome .= '<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n";
1.160 raeburn 4279: }
1.207 raeburn 4280: if ($env{'form.origname'} ne '') {
4281: $outcome .= '<input type="hidden" name="origname" value="'.$env{'form.origname'}.'" />'."\n";
4282: }
1.160 raeburn 4283: foreach my $item ('sortby','seluname','seludom') {
4284: if (exists($env{'form.'.$item})) {
1.188 raeburn 4285: $outcome .= '<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n";
1.160 raeburn 4286: }
4287: }
1.188 raeburn 4288: if ($uhome eq 'no_host') {
4289: $outcome .= '<input type="hidden" name="forcenewuser" value="1" />'."\n";
4290: }
4291: $outcome .= '<input type="hidden" name="phase" value="" />'."\n".
1.383 raeburn 4292: '<input type="hidden" name="currstate" value="" />'."\n".
4293: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n".
1.188 raeburn 4294: '</form>';
4295: return $outcome;
1.4 www 4296: }
4297:
1.149 raeburn 4298: sub quota_admin {
1.378 raeburn 4299: my ($setquota,$changeHash,$name) = @_;
1.149 raeburn 4300: my $quotachanged;
4301: if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
4302: # Current user has quota modification privileges
1.267 raeburn 4303: if (ref($changeHash) eq 'HASH') {
4304: $quotachanged = 1;
1.378 raeburn 4305: $changeHash->{$name.'quota'} = $setquota;
1.267 raeburn 4306: }
1.149 raeburn 4307: }
4308: return $quotachanged;
4309: }
4310:
1.267 raeburn 4311: sub tool_admin {
1.275 raeburn 4312: my ($tool,$settool,$changeHash,$context) = @_;
4313: my $canchange = 0;
1.279 raeburn 4314: if ($context eq 'requestcourses') {
1.275 raeburn 4315: if (&Apache::lonnet::allowed('ccc',$env{'form.ccdomain'})) {
4316: $canchange = 1;
4317: }
1.300 raeburn 4318: } elsif ($context eq 'reqcrsotherdom') {
4319: if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
4320: $canchange = 1;
4321: }
1.362 raeburn 4322: } elsif ($context eq 'requestauthor') {
4323: if (&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) {
4324: $canchange = 1;
4325: }
1.275 raeburn 4326: } elsif (&Apache::lonnet::allowed('mut',$env{'form.ccdomain'})) {
4327: # Current user has quota modification privileges
4328: $canchange = 1;
4329: }
1.267 raeburn 4330: my $toolchanged;
1.275 raeburn 4331: if ($canchange) {
1.267 raeburn 4332: if (ref($changeHash) eq 'HASH') {
4333: $toolchanged = 1;
1.362 raeburn 4334: if ($tool eq 'requestauthor') {
4335: $changeHash->{$context} = $settool;
4336: } else {
4337: $changeHash->{$context.'.'.$tool} = $settool;
4338: }
1.267 raeburn 4339: }
4340: }
4341: return $toolchanged;
4342: }
4343:
1.88 raeburn 4344: sub build_roles {
1.89 raeburn 4345: my ($sectionstr,$sections,$role) = @_;
1.88 raeburn 4346: my $num_sections = 0;
4347: if ($sectionstr=~ /,/) {
4348: my @secnums = split/,/,$sectionstr;
1.89 raeburn 4349: if ($role eq 'st') {
4350: $secnums[0] =~ s/\W//g;
4351: $$sections{$secnums[0]} = 1;
4352: $num_sections = 1;
4353: } else {
4354: foreach my $sec (@secnums) {
4355: $sec =~ ~s/\W//g;
1.150 banghart 4356: if (!($sec eq "")) {
1.89 raeburn 4357: if (exists($$sections{$sec})) {
4358: $$sections{$sec} ++;
4359: } else {
4360: $$sections{$sec} = 1;
4361: $num_sections ++;
4362: }
1.88 raeburn 4363: }
4364: }
4365: }
4366: } else {
4367: $sectionstr=~s/\W//g;
4368: unless ($sectionstr eq '') {
4369: $$sections{$sectionstr} = 1;
4370: $num_sections ++;
4371: }
4372: }
1.129 albertel 4373:
1.88 raeburn 4374: return $num_sections;
4375: }
4376:
1.58 www 4377: # ========================================================== Custom Role Editor
4378:
4379: sub custom_role_editor {
1.406.2.14 raeburn 4380: my ($r,$context,$brcrum,$prefix,$permission) = @_;
1.324 raeburn 4381: my $action = $env{'form.customroleaction'};
1.406.2.14 raeburn 4382: my ($rolename,$helpitem);
1.324 raeburn 4383: if ($action eq 'new') {
4384: $rolename=$env{'form.newrolename'};
4385: } else {
4386: $rolename=$env{'form.rolename'};
1.59 www 4387: }
4388:
1.324 raeburn 4389: my ($crstype,$context);
4390: if ($env{'request.course.id'}) {
4391: $crstype = &Apache::loncommon::course_type();
4392: $context = 'course';
1.406.2.14 raeburn 4393: $helpitem = 'Course_Editing_Custom_Roles';
1.324 raeburn 4394: } else {
4395: $context = 'domain';
1.406.2.5 raeburn 4396: $crstype = 'course';
1.406.2.14 raeburn 4397: $helpitem = 'Domain_Editing_Custom_Roles';
1.324 raeburn 4398: }
1.351 raeburn 4399:
4400: $rolename=~s/[^A-Za-z0-9]//gs;
4401: if (!$rolename || $env{'form.phase'} eq 'pickrole') {
1.406.2.14 raeburn 4402: &print_username_entry_form($r,$context,undef,undef,undef,$crstype,$brcrum,
4403: $permission);
1.351 raeburn 4404: return;
4405: }
4406:
1.406.2.5 raeburn 4407: my $formname = 'form1';
4408: my %privs=();
4409: my $body_top = '<h2>';
4410: # ------------------------------------------------------- Does this role exist?
1.59 www 4411: my ($rdummy,$roledef)=
4412: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
4413: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1.406.2.5 raeburn 4414: $body_top .= &mt('Existing Role').' "';
1.61 www 4415: # ------------------------------------------------- Get current role privileges
1.406.2.5 raeburn 4416: ($privs{'system'},$privs{'domain'},$privs{'course'})=split(/\_/,$roledef);
4417: if ($privs{'system'} =~ /bre\&S/) {
4418: if ($context eq 'domain') {
4419: $crstype = 'Course';
4420: } elsif ($crstype eq 'Community') {
4421: $privs{'system'} =~ s/bre\&S//;
4422: }
4423: } elsif ($context eq 'domain') {
4424: $crstype = 'Course';
1.324 raeburn 4425: }
1.59 www 4426: } else {
1.406.2.5 raeburn 4427: $body_top .= &mt('New Role').' "';
4428: $roledef='';
1.59 www 4429: }
1.153 banghart 4430: $body_top .= $rolename.'"</h2>';
1.406.2.5 raeburn 4431:
4432: # ------------------------------------------------------- What can be assigned?
4433: my %full=();
4434: my %levels=(
4435: course => {},
4436: domain => {},
4437: system => {},
4438: );
4439: my %levelscurrent=(
4440: course => {},
4441: domain => {},
4442: system => {},
4443: );
4444: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
1.160 raeburn 4445: my ($jsback,$elements) = &crumb_utilities();
1.406.2.5 raeburn 4446: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
4447: my $head_script =
4448: &Apache::lonuserutils::custom_roledefs_js($context,$crstype,$formname,
4449: \%full,\@templateroles,$jsback);
1.351 raeburn 4450: push (@{$brcrum},
1.406.2.5 raeburn 4451: {href => "javascript:backPage(document.$formname,'pickrole','')",
1.351 raeburn 4452: text => "Pick custom role",
4453: faq => 282,bug=>'Instructor Interface',},
1.406.2.5 raeburn 4454: {href => "javascript:backPage(document.$formname,'','')",
1.351 raeburn 4455: text => "Edit custom role",
4456: faq => 282,
4457: bug => 'Instructor Interface',
1.406.2.14 raeburn 4458: help => $helpitem}
1.351 raeburn 4459: );
4460: my $args = { bread_crumbs => $brcrum,
4461: bread_crumbs_component => 'User Management'};
4462: $r->print(&Apache::loncommon::start_page('Custom Role Editor',
4463: $head_script,$args).
4464: $body_top);
1.406.2.5 raeburn 4465: $r->print('<form name="'.$formname.'" method="post" action="">'."\n".
4466: &Apache::lonuserutils::custom_role_header($context,$crstype,
4467: \@templateroles,$prefix));
1.264 bisitz 4468:
1.61 www 4469: $r->print(<<ENDCCF);
4470: <input type="hidden" name="phase" value="set_custom_roles" />
4471: <input type="hidden" name="rolename" value="$rolename" />
4472: ENDCCF
1.406.2.5 raeburn 4473: $r->print(&Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
4474: \%levelscurrent,$prefix));
1.135 raeburn 4475: $r->print(&Apache::loncommon::end_data_table().
1.190 raeburn 4476: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'.
1.160 raeburn 4477: '<input type="hidden" name="startrolename" value="'.$env{'form.rolename'}.
1.406.2.5 raeburn 4478: '" />'."\n".'<input type="hidden" name="currstate" value="" />'."\n".
1.160 raeburn 4479: '<input type="reset" value="'.&mt("Reset").'" />'."\n".
1.351 raeburn 4480: '<input type="submit" value="'.&mt('Save').'" /></form>');
1.61 www 4481: }
1.406.2.5 raeburn 4482:
1.61 www 4483: # ---------------------------------------------------------- Call to definerole
4484: sub set_custom_role {
1.406.2.14 raeburn 4485: my ($r,$context,$brcrum,$prefix,$permission) = @_;
1.101 albertel 4486: my $rolename=$env{'form.rolename'};
1.63 www 4487: $rolename=~s/[^A-Za-z0-9]//gs;
1.150 banghart 4488: if (!$rolename) {
1.406.2.14 raeburn 4489: &custom_role_editor($r,$context,$brcrum,$prefix,$permission);
1.61 www 4490: return;
4491: }
1.160 raeburn 4492: my ($jsback,$elements) = &crumb_utilities();
1.301 bisitz 4493: my $jscript = '<script type="text/javascript">'
4494: .'// <![CDATA['."\n"
4495: .$jsback."\n"
4496: .'// ]]>'."\n"
4497: .'</script>'."\n";
1.406.2.14 raeburn 4498: my $helpitem = 'Course_Editing_Custom_Roles';
4499: if ($context eq 'domain') {
4500: $helpitem = 'Domain_Editing_Custom_Roles';
4501: }
1.352 raeburn 4502: push(@{$brcrum},
4503: {href => "javascript:backPage(document.customresult,'pickrole','')",
4504: text => "Pick custom role",
4505: faq => 282,
4506: bug => 'Instructor Interface',},
4507: {href => "javascript:backPage(document.customresult,'selected_custom_edit','')",
4508: text => "Edit custom role",
4509: faq => 282,
4510: bug => 'Instructor Interface',},
4511: {href => "javascript:backPage(document.customresult,'set_custom_roles','')",
4512: text => "Result",
4513: faq => 282,
4514: bug => 'Instructor Interface',
1.406.2.14 raeburn 4515: help => $helpitem,}
1.352 raeburn 4516: );
4517: my $args = { bread_crumbs => $brcrum,
1.406.2.5 raeburn 4518: bread_crumbs_component => 'User Management'};
1.351 raeburn 4519: $r->print(&Apache::loncommon::start_page('Save Custom Role',$jscript,$args));
1.160 raeburn 4520:
1.393 raeburn 4521: my $newrole;
1.61 www 4522: my ($rdummy,$roledef)=
1.110 albertel 4523: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
4524:
1.61 www 4525: # ------------------------------------------------------- Does this role exist?
1.188 raeburn 4526: $r->print('<h3>');
1.61 www 4527: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1.73 sakharuk 4528: $r->print(&mt('Existing Role').' "');
1.61 www 4529: } else {
1.73 sakharuk 4530: $r->print(&mt('New Role').' "');
1.61 www 4531: $roledef='';
1.393 raeburn 4532: $newrole = 1;
1.61 www 4533: }
1.188 raeburn 4534: $r->print($rolename.'"</h3>');
1.406.2.5 raeburn 4535: # ------------------------------------------------- Assign role and show result
1.61 www 4536:
1.387 bisitz 4537: my $errmsg;
1.406.2.5 raeburn 4538: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$prefix);
4539: # Assign role and return result
4540: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
4541: $newprivs{'c'});
1.387 bisitz 4542: if ($result ne 'ok') {
4543: $errmsg = ': '.$result;
4544: }
4545: my $message =
4546: &Apache::lonhtmlcommon::confirm_success(
4547: &mt('Defining Role').$errmsg, ($result eq 'ok' ? 0 : 1));
1.101 albertel 4548: if ($env{'request.course.id'}) {
4549: my $url='/'.$env{'request.course.id'};
1.63 www 4550: $url=~s/\_/\//g;
1.387 bisitz 4551: $result =
4552: &Apache::lonnet::assigncustomrole(
4553: $env{'user.domain'},$env{'user.name'},
4554: $url,
4555: $env{'user.domain'},$env{'user.name'},
4556: $rolename,undef,undef,undef,$context);
4557: if ($result ne 'ok') {
4558: $errmsg = ': '.$result;
4559: }
4560: $message .=
4561: '<br />'
4562: .&Apache::lonhtmlcommon::confirm_success(
4563: &mt('Assigning Role to Self').$errmsg, ($result eq 'ok' ? 0 : 1));
1.63 www 4564: }
1.380 bisitz 4565: $r->print(
1.387 bisitz 4566: &Apache::loncommon::confirmwrapper($message)
4567: .'<br />'
4568: .&Apache::lonhtmlcommon::actionbox([
4569: '<a href="javascript:backPage(document.customresult,'."'pickrole'".')">'
4570: .&mt('Create or edit another custom role')
4571: .'</a>'])
1.380 bisitz 4572: .'<form name="customresult" method="post" action="">'
1.387 bisitz 4573: .&Apache::lonhtmlcommon::echo_form_input([])
4574: .'</form>'
1.380 bisitz 4575: );
1.58 www 4576: }
4577:
1.2 www 4578: # ================================================================ Main Handler
4579: sub handler {
4580: my $r = shift;
4581: if ($r->header_only) {
1.68 www 4582: &Apache::loncommon::content_type($r,'text/html');
1.2 www 4583: $r->send_http_header;
4584: return OK;
4585: }
1.406.2.14 raeburn 4586: my ($context,$crstype,$cid,$cnum,$cdom,$allhelpitems);
4587:
1.190 raeburn 4588: if ($env{'request.course.id'}) {
4589: $context = 'course';
1.318 raeburn 4590: $crstype = &Apache::loncommon::course_type();
1.190 raeburn 4591: } elsif ($env{'request.role'} =~ /^au\./) {
1.206 raeburn 4592: $context = 'author';
1.190 raeburn 4593: } else {
4594: $context = 'domain';
4595: }
1.375 raeburn 4596:
1.406.2.14 raeburn 4597: my ($permission,$allowed) =
4598: &Apache::lonuserutils::get_permission($context,$crstype);
4599:
4600: if ($allowed) {
4601: my @allhelp;
4602: if ($context eq 'course') {
4603: $cid = $env{'request.course.id'};
4604: $cdom = $env{'course.'.$cid.'.domain'};
4605: $cnum = $env{'course.'.$cid.'.num'};
4606:
4607: if ($permission->{'cusr'}) {
4608: push(@allhelp,'Course_Create_Class_List');
4609: }
4610: if ($permission->{'view'} || $permission->{'cusr'}) {
4611: push(@allhelp,('Course_Change_Privileges','Course_View_Class_List'));
4612: }
4613: if ($permission->{'custom'}) {
4614: push(@allhelp,'Course_Editing_Custom_Roles');
4615: }
4616: if ($permission->{'cusr'}) {
4617: push(@allhelp,('Course_Add_Student','Course_Drop_Student'));
4618: }
4619: unless ($permission->{'cusr_section'}) {
4620: if (&Apache::lonnet::auto_run($cnum,$cdom) && (($permission->{'cusr'}) || ($permission->{'view'}))) {
4621: push(@allhelp,'Course_Automated_Enrollment');
4622: }
4623: if ($permission->{'selfenrolladmin'}) {
4624: push(@allhelp,'Course_Approve_Selfenroll');
4625: }
4626: }
4627: if ($permission->{'grp_manage'}) {
4628: push(@allhelp,'Course_Manage_Group');
4629: }
4630: if ($permission->{'view'} || $permission->{'cusr'}) {
4631: push(@allhelp,'Course_User_Logs');
4632: }
4633: } elsif ($context eq 'author') {
4634: push(@allhelp,('Author_Change_Privileges','Author_Create_Coauthor_List',
4635: 'Author_View_Coauthor_List','Author_User_Logs'));
4636: } else {
4637: if ($permission->{'cusr'}) {
4638: push(@allhelp,'Domain_Change_Privileges');
4639: if ($permission->{'activity'}) {
4640: push(@allhelp,'Domain_User_Access_Logs');
4641: }
4642: push(@allhelp,('Domain_Create_Users','Domain_View_Users_List'));
4643: if ($permission->{'custom'}) {
4644: push(@allhelp,'Domain_Editing_Custom_Roles');
4645: }
4646: push(@allhelp,('Domain_Role_Approvals','Domain_Username_Approvals','Domain_Change_Logs'));
4647: } elsif ($permission->{'view'}) {
4648: push(@allhelp,'Domain_View_Privileges');
4649: if ($permission->{'activity'}) {
4650: push(@allhelp,'Domain_User_Access_Logs');
4651: }
4652: push(@allhelp,('Domain_View_Users_List','Domain_Change_Logs'));
4653: }
4654: }
4655: if (@allhelp) {
4656: $allhelpitems = join(',',@allhelp);
4657: }
4658: }
4659:
1.190 raeburn 4660: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.233 raeburn 4661: ['action','state','callingform','roletype','showrole','bulkaction','popup','phase',
1.391 raeburn 4662: 'username','domain','srchterm','srchdomain','srchin','srchby','srchtype','queue']);
1.190 raeburn 4663: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.351 raeburn 4664: my $args;
4665: my $brcrum = [];
4666: my $bread_crumbs_component = 'User Management';
1.391 raeburn 4667: if (($env{'form.action'} ne 'dateselect') && ($env{'form.action'} ne 'displayuserreq')) {
1.351 raeburn 4668: $brcrum = [{href=>"/adm/createuser",
4669: text=>"User Management",
1.406.2.14 raeburn 4670: help=>$allhelpitems}
1.351 raeburn 4671: ];
1.202 raeburn 4672: }
1.190 raeburn 4673: if (!$allowed) {
1.358 raeburn 4674: if ($context eq 'course') {
4675: $r->internal_redirect('/adm/viewclasslist');
4676: return OK;
4677: }
1.190 raeburn 4678: $env{'user.error.msg'}=
4679: "/adm/createuser:cst:0:0:Cannot create/modify user data ".
4680: "or view user status.";
4681: return HTTP_NOT_ACCEPTABLE;
4682: }
4683:
4684: &Apache::loncommon::content_type($r,'text/html');
4685: $r->send_http_header;
4686:
1.375 raeburn 4687: my $showcredits;
4688: if ((($context eq 'course') && ($crstype eq 'Course')) ||
4689: ($context eq 'domain')) {
4690: my %domdefaults =
4691: &Apache::lonnet::get_domain_defaults($env{'request.role.domain'});
4692: if ($domdefaults{'officialcredits'} || $domdefaults{'unofficialcredits'}) {
4693: $showcredits = 1;
4694: }
4695: }
4696:
1.190 raeburn 4697: # Main switch on form.action and form.state, as appropriate
4698: if (! exists($env{'form.action'})) {
1.351 raeburn 4699: $args = {bread_crumbs => $brcrum,
4700: bread_crumbs_component => $bread_crumbs_component};
4701: $r->print(&header(undef,$args));
1.318 raeburn 4702: $r->print(&print_main_menu($permission,$context,$crstype));
1.190 raeburn 4703: } elsif ($env{'form.action'} eq 'upload' && $permission->{'cusr'}) {
1.406.2.14 raeburn 4704: my $helpitem = 'Course_Create_Class_List';
4705: if ($context eq 'author') {
4706: $helpitem = 'Author_Create_Coauthor_List';
4707: } elsif ($context eq 'domain') {
4708: $helpitem = 'Domain_Create_Users';
4709: }
1.351 raeburn 4710: push(@{$brcrum},
4711: { href => '/adm/createuser?action=upload&state=',
4712: text => 'Upload Users List',
1.406.2.14 raeburn 4713: help => $helpitem,
1.351 raeburn 4714: });
4715: $bread_crumbs_component = 'Upload Users List';
4716: $args = {bread_crumbs => $brcrum,
4717: bread_crumbs_component => $bread_crumbs_component};
4718: $r->print(&header(undef,$args));
1.190 raeburn 4719: $r->print('<form name="studentform" method="post" '.
4720: 'enctype="multipart/form-data" '.
4721: ' action="/adm/createuser">'."\n");
4722: if (! exists($env{'form.state'})) {
4723: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
4724: } elsif ($env{'form.state'} eq 'got_file') {
1.375 raeburn 4725: &Apache::lonuserutils::print_upload_manager_form($r,$context,$permission,
4726: $crstype,$showcredits);
1.190 raeburn 4727: } elsif ($env{'form.state'} eq 'enrolling') {
4728: if ($env{'form.datatoken'}) {
1.375 raeburn 4729: &Apache::lonuserutils::upfile_drop_add($r,$context,$permission,
4730: $showcredits);
1.190 raeburn 4731: }
4732: } else {
4733: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
4734: }
1.406.2.5 raeburn 4735: } elsif (((($env{'form.action'} eq 'singleuser') || ($env{'form.action'}
4736: eq 'singlestudent')) && ($permission->{'cusr'})) ||
1.406.2.6 raeburn 4737: (($env{'form.action'} eq 'singleuser') && ($permission->{'view'})) ||
1.406.2.5 raeburn 4738: (($env{'form.action'} eq 'accesslogs') && ($permission->{'activity'}))) {
1.190 raeburn 4739: my $phase = $env{'form.phase'};
4740: my @search = ('srchterm','srchby','srchin','srchtype','srchdomain');
1.192 albertel 4741: &Apache::loncreateuser::restore_prev_selections();
4742: my $srch;
4743: foreach my $item (@search) {
4744: $srch->{$item} = $env{'form.'.$item};
4745: }
1.207 raeburn 4746: if (($phase eq 'get_user_info') || ($phase eq 'userpicked') ||
1.406.2.5 raeburn 4747: ($phase eq 'createnewuser') || ($phase eq 'activity')) {
1.207 raeburn 4748: if ($env{'form.phase'} eq 'createnewuser') {
4749: my $response;
4750: if ($env{'form.srchterm'} !~ /^$match_username$/) {
1.366 bisitz 4751: my $response =
4752: '<span class="LC_warning">'
4753: .&mt('You must specify a valid username. Only the following are allowed:'
4754: .' letters numbers - . @')
4755: .'</span>';
1.221 raeburn 4756: $env{'form.phase'} = '';
1.375 raeburn 4757: &print_username_entry_form($r,$context,$response,$srch,undef,
1.406.2.14 raeburn 4758: $crstype,$brcrum,$permission);
1.207 raeburn 4759: } else {
4760: my $ccuname =&LONCAPA::clean_username($srch->{'srchterm'});
4761: my $ccdomain=&LONCAPA::clean_domain($srch->{'srchdomain'});
4762: &print_user_modification_page($r,$ccuname,$ccdomain,
1.221 raeburn 4763: $srch,$response,$context,
1.375 raeburn 4764: $permission,$crstype,$brcrum,
4765: $showcredits);
1.207 raeburn 4766: }
4767: } elsif ($env{'form.phase'} eq 'get_user_info') {
1.190 raeburn 4768: my ($currstate,$response,$forcenewuser,$results) =
1.221 raeburn 4769: &user_search_result($context,$srch);
1.190 raeburn 4770: if ($env{'form.currstate'} eq 'modify') {
4771: $currstate = $env{'form.currstate'};
4772: }
4773: if ($currstate eq 'select') {
4774: &print_user_selection_page($r,$response,$srch,$results,
1.351 raeburn 4775: \@search,$context,undef,$crstype,
4776: $brcrum);
1.406.2.5 raeburn 4777: } elsif (($currstate eq 'modify') || ($env{'form.action'} eq 'accesslogs')) {
4778: my ($ccuname,$ccdomain,$uhome);
1.190 raeburn 4779: if (($srch->{'srchby'} eq 'uname') &&
4780: ($srch->{'srchtype'} eq 'exact')) {
4781: $ccuname = $srch->{'srchterm'};
4782: $ccdomain= $srch->{'srchdomain'};
4783: } else {
4784: my @matchedunames = keys(%{$results});
4785: ($ccuname,$ccdomain) = split(/:/,$matchedunames[0]);
4786: }
4787: $ccuname =&LONCAPA::clean_username($ccuname);
4788: $ccdomain=&LONCAPA::clean_domain($ccdomain);
1.406.2.5 raeburn 4789: if ($env{'form.action'} eq 'accesslogs') {
4790: my $uhome;
4791: if (($ccuname ne '') && ($ccdomain ne '')) {
4792: $uhome = &Apache::lonnet::homeserver($ccuname,$ccdomain);
4793: }
4794: if (($uhome eq '') || ($uhome eq 'no_host')) {
4795: $env{'form.phase'} = '';
4796: undef($forcenewuser);
4797: #if ($response) {
4798: # unless ($response =~ m{\Q<br /><br />\E$}) {
4799: # $response .= '<br /><br />';
4800: # }
4801: #}
4802: &print_username_entry_form($r,$context,$response,$srch,
1.406.2.14 raeburn 4803: $forcenewuser,$crstype,$brcrum,
4804: $permission);
1.406.2.5 raeburn 4805: } else {
4806: &print_useraccesslogs_display($r,$ccuname,$ccdomain,$permission,$brcrum);
4807: }
4808: } else {
4809: if ($env{'form.forcenewuser'}) {
4810: $response = '';
4811: }
4812: &print_user_modification_page($r,$ccuname,$ccdomain,
4813: $srch,$response,$context,
4814: $permission,$crstype,$brcrum);
1.190 raeburn 4815: }
4816: } elsif ($currstate eq 'query') {
1.351 raeburn 4817: &print_user_query_page($r,'createuser',$brcrum);
1.190 raeburn 4818: } else {
1.229 raeburn 4819: $env{'form.phase'} = '';
1.207 raeburn 4820: &print_username_entry_form($r,$context,$response,$srch,
1.406.2.14 raeburn 4821: $forcenewuser,$crstype,$brcrum,
4822: $permission);
1.190 raeburn 4823: }
4824: } elsif ($env{'form.phase'} eq 'userpicked') {
4825: my $ccuname = &LONCAPA::clean_username($env{'form.seluname'});
4826: my $ccdomain = &LONCAPA::clean_domain($env{'form.seludom'});
1.406.2.5 raeburn 4827: if ($env{'form.action'} eq 'accesslogs') {
4828: &print_useraccesslogs_display($r,$ccuname,$ccdomain,$permission,$brcrum);
4829: } else {
4830: &print_user_modification_page($r,$ccuname,$ccdomain,$srch,'',
4831: $context,$permission,$crstype,
4832: $brcrum);
4833: }
4834: } elsif ($env{'form.action'} eq 'accesslogs') {
4835: my $ccuname = &LONCAPA::clean_username($env{'form.accessuname'});
4836: my $ccdomain = &LONCAPA::clean_domain($env{'form.accessudom'});
4837: &print_useraccesslogs_display($r,$ccuname,$ccdomain,$permission,$brcrum);
1.190 raeburn 4838: }
4839: } elsif ($env{'form.phase'} eq 'update_user_data') {
1.375 raeburn 4840: &update_user_data($r,$context,$crstype,$brcrum,$showcredits);
1.190 raeburn 4841: } else {
1.351 raeburn 4842: &print_username_entry_form($r,$context,undef,$srch,undef,$crstype,
1.406.2.14 raeburn 4843: $brcrum,$permission);
1.190 raeburn 4844: }
4845: } elsif ($env{'form.action'} eq 'custom' && $permission->{'custom'}) {
1.406.2.5 raeburn 4846: my $prefix;
1.190 raeburn 4847: if ($env{'form.phase'} eq 'set_custom_roles') {
1.406.2.14 raeburn 4848: &set_custom_role($r,$context,$brcrum,$prefix,$permission);
1.190 raeburn 4849: } else {
1.406.2.14 raeburn 4850: &custom_role_editor($r,$context,$brcrum,$prefix,$permission);
1.190 raeburn 4851: }
1.362 raeburn 4852: } elsif (($env{'form.action'} eq 'processauthorreq') &&
4853: ($permission->{'cusr'}) &&
4854: (&Apache::lonnet::allowed('cau',$env{'request.role.domain'}))) {
4855: push(@{$brcrum},
4856: {href => '/adm/createuser?action=processauthorreq',
1.385 bisitz 4857: text => 'Authoring Space requests',
1.362 raeburn 4858: help => 'Domain_Role_Approvals'});
4859: $bread_crumbs_component = 'Authoring requests';
4860: if ($env{'form.state'} eq 'done') {
4861: push(@{$brcrum},
4862: {href => '/adm/createuser?action=authorreqqueue',
4863: text => 'Result',
4864: help => 'Domain_Role_Approvals'});
4865: $bread_crumbs_component = 'Authoring request result';
4866: }
4867: $args = { bread_crumbs => $brcrum,
4868: bread_crumbs_component => $bread_crumbs_component};
1.391 raeburn 4869: my $js = &usernamerequest_javascript();
4870: $r->print(&header(&add_script($js),$args));
1.362 raeburn 4871: if (!exists($env{'form.state'})) {
4872: $r->print(&Apache::loncoursequeueadmin::display_queued_requests('requestauthor',
4873: $env{'request.role.domain'}));
4874: } elsif ($env{'form.state'} eq 'done') {
4875: $r->print('<h3>'.&mt('Authoring request processing').'</h3>'."\n");
4876: $r->print(&Apache::loncoursequeueadmin::update_request_queue('requestauthor',
4877: $env{'request.role.domain'}));
4878: }
1.391 raeburn 4879: } elsif (($env{'form.action'} eq 'processusernamereq') &&
4880: ($permission->{'cusr'}) &&
4881: (&Apache::lonnet::allowed('cau',$env{'request.role.domain'}))) {
4882: push(@{$brcrum},
4883: {href => '/adm/createuser?action=processusernamereq',
4884: text => 'LON-CAPA account requests',
4885: help => 'Domain_Username_Approvals'});
4886: $bread_crumbs_component = 'Account requests';
4887: if ($env{'form.state'} eq 'done') {
4888: push(@{$brcrum},
4889: {href => '/adm/createuser?action=usernamereqqueue',
4890: text => 'Result',
4891: help => 'Domain_Username_Approvals'});
4892: $bread_crumbs_component = 'LON-CAPA account request result';
4893: }
4894: $args = { bread_crumbs => $brcrum,
4895: bread_crumbs_component => $bread_crumbs_component};
4896: my $js = &usernamerequest_javascript();
4897: $r->print(&header(&add_script($js),$args));
4898: if (!exists($env{'form.state'})) {
4899: $r->print(&Apache::loncoursequeueadmin::display_queued_requests('requestusername',
4900: $env{'request.role.domain'}));
4901: } elsif ($env{'form.state'} eq 'done') {
4902: $r->print('<h3>'.&mt('LON-CAPA account request processing').'</h3>'."\n");
4903: $r->print(&Apache::loncoursequeueadmin::update_request_queue('requestusername',
4904: $env{'request.role.domain'}));
4905: }
4906: } elsif (($env{'form.action'} eq 'displayuserreq') &&
4907: ($permission->{'cusr'})) {
4908: my $dom = $env{'form.domain'};
4909: my $uname = $env{'form.username'};
4910: my $warning;
4911: if (($dom =~ /^$match_domain$/) && (&Apache::lonnet::domain($dom) ne '')) {
4912: if (($dom eq $env{'request.role.domain'}) && (&Apache::lonnet::allowed('ccc',$dom))) {
4913: if (($uname =~ /^$match_username$/) && ($env{'form.queue'} eq 'approval')) {
4914: my $uhome = &Apache::lonnet::homeserver($uname,$dom);
4915: if ($uhome eq 'no_host') {
4916: my $queue = $env{'form.queue'};
4917: my $reqkey = &escape($uname).'_'.$queue;
4918: my $namespace = 'usernamequeue';
4919: my $domconfig = &Apache::lonnet::get_domainconfiguser($dom);
4920: my %queued =
4921: &Apache::lonnet::get($namespace,[$reqkey],$dom,$domconfig);
4922: unless ($queued{$reqkey}) {
4923: $warning = &mt('No information was found for this LON-CAPA account request.');
4924: }
4925: } else {
4926: $warning = &mt('A LON-CAPA account already exists for the requested username and domain.');
4927: }
4928: } else {
4929: $warning = &mt('LON-CAPA account request status check is for an invalid username.');
4930: }
4931: } else {
4932: $warning = &mt('You do not have rights to view LON-CAPA account requests in the domain specified.');
4933: }
4934: } else {
4935: $warning = &mt('LON-CAPA account request status check is for an invalid domain.');
4936: }
4937: my $args = { only_body => 1 };
4938: $r->print(&header(undef,$args).
4939: '<h3>'.&mt('LON-CAPA Account Request Details').'</h3>');
4940: if ($warning ne '') {
4941: $r->print('<div class="LC_warning">'.$warning.'</div>');
4942: } else {
4943: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
4944: my $domconfiguser = &Apache::lonnet::get_domainconfiguser($dom);
4945: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
4946: if (ref($domconfig{'usercreation'}) eq 'HASH') {
4947: if (ref($domconfig{'usercreation'}{'cancreate'}) eq 'HASH') {
4948: if (ref($domconfig{'usercreation'}{'cancreate'}{'emailusername'}) eq 'HASH') {
4949: my %info =
4950: &Apache::lonnet::get('nohist_requestedusernames',[$uname],$dom,$domconfiguser);
4951: if (ref($info{$uname}) eq 'HASH') {
1.396 raeburn 4952: my $usertype = $info{$uname}{'inststatus'};
4953: unless ($usertype) {
4954: $usertype = 'default';
4955: }
1.406.2.14.2. (raeburn 4956:): my ($showstatus,$showemail,$pickstart);
4957:): my $numextras = 0;
4958:): my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4959:): if ((ref($types) eq 'ARRAY') && (@{$types} > 0)) {
4960:): if (ref($usertypes) eq 'HASH') {
4961:): if ($usertypes->{$usertype}) {
4962:): $showstatus = $usertypes->{$usertype};
4963:): } else {
4964:): $showstatus = $othertitle;
4965:): }
4966:): if ($showstatus) {
4967:): $numextras ++;
4968:): }
4969:): }
4970:): }
4971:): if (($info{$uname}{'email'} ne '') && ($info{$uname}{'email'} ne $uname)) {
4972:): $showemail = $info{$uname}{'email'};
4973:): $numextras ++;
4974:): }
1.396 raeburn 4975: if (ref($domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}) eq 'HASH') {
4976: if ((ref($infofields) eq 'ARRAY') && (ref($infotitles) eq 'HASH')) {
1.406.2.14.2. (raeburn 4977:): $pickstart = 1;
1.396 raeburn 4978: $r->print('<div>'.&Apache::lonhtmlcommon::start_pick_box());
1.406.2.14.2. (raeburn 4979:): my ($num,$count);
1.396 raeburn 4980: $count = scalar(keys(%{$domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}}));
1.406.2.14.2. (raeburn 4981:): $count += $numextras;
1.396 raeburn 4982: foreach my $field (@{$infofields}) {
4983: next unless ($domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}{$field});
4984: next unless ($infotitles->{$field});
4985: $r->print(&Apache::lonhtmlcommon::row_title($infotitles->{$field}).
4986: $info{$uname}{$field});
4987: $num ++;
1.406.2.14.2. (raeburn 4988:): unless ($count == $num) {
1.396 raeburn 4989: $r->print(&Apache::lonhtmlcommon::row_closure());
4990: }
4991: }
1.406.2.14.2. (raeburn 4992:): }
4993:): }
4994:): if ($numextras) {
4995:): unless ($pickstart) {
4996:): $r->print('<div>'.&Apache::lonhtmlcommon::start_pick_box());
4997:): $pickstart = 1;
4998:): }
4999:): if ($showemail) {
5000:): my $closure = '';
5001:): unless ($showstatus) {
5002:): $closure = 1;
1.391 raeburn 5003: }
1.406.2.14.2. (raeburn 5004:): $r->print(&Apache::lonhtmlcommon::row_title(&mt('E-mail address')).
5005:): $showemail.
5006:): &Apache::lonhtmlcommon::row_closure($closure));
5007:): }
5008:): if ($showstatus) {
5009:): $r->print(&Apache::lonhtmlcommon::row_title(&mt('Status type[_1](self-reported)','<br />')).
5010:): $showstatus.
5011:): &Apache::lonhtmlcommon::row_closure(1));
1.391 raeburn 5012: }
5013: }
1.406.2.14.2. (raeburn 5014:): if ($pickstart) {
5015:): $r->print(&Apache::lonhtmlcommon::end_pick_box().'</div>');
5016:): } else {
5017:): $r->print('<div>'.&mt('No information to display for this account request.').'</div>');
5018:): }
5019:): } else {
5020:): $r->print('<div>'.&mt('No information available for this account request.').'</div>');
1.391 raeburn 5021: }
5022: }
5023: }
5024: }
5025: }
1.406.2.14.2. (raeburn 5026:): $r->print(&close_popup_form());
1.207 raeburn 5027: } elsif (($env{'form.action'} eq 'listusers') &&
5028: ($permission->{'view'} || $permission->{'cusr'})) {
1.406.2.14 raeburn 5029: my $helpitem = 'Course_View_Class_List';
5030: if ($context eq 'author') {
5031: $helpitem = 'Author_View_Coauthor_List';
5032: } elsif ($context eq 'domain') {
5033: $helpitem = 'Domain_View_Users_List';
5034: }
1.202 raeburn 5035: if ($env{'form.phase'} eq 'bulkchange') {
1.351 raeburn 5036: push(@{$brcrum},
5037: {href => '/adm/createuser?action=listusers',
5038: text => "List Users"},
5039: {href => "/adm/createuser",
5040: text => "Result",
1.406.2.14 raeburn 5041: help => $helpitem});
1.351 raeburn 5042: $bread_crumbs_component = 'Update Users';
5043: $args = {bread_crumbs => $brcrum,
5044: bread_crumbs_component => $bread_crumbs_component};
5045: $r->print(&header(undef,$args));
1.202 raeburn 5046: my $setting = $env{'form.roletype'};
5047: my $choice = $env{'form.bulkaction'};
5048: if ($permission->{'cusr'}) {
1.336 raeburn 5049: &Apache::lonuserutils::update_user_list($r,$context,$setting,$choice,$crstype);
1.221 raeburn 5050: } else {
5051: $r->print(&mt('You are not authorized to make bulk changes to user roles'));
1.223 raeburn 5052: $r->print('<p><a href="/adm/createuser?action=listusers">'.&mt('Display User Lists').'</a>');
1.202 raeburn 5053: }
5054: } else {
1.351 raeburn 5055: push(@{$brcrum},
5056: {href => '/adm/createuser?action=listusers',
5057: text => "List Users",
1.406.2.14 raeburn 5058: help => $helpitem});
1.351 raeburn 5059: $bread_crumbs_component = 'List Users';
5060: $args = {bread_crumbs => $brcrum,
5061: bread_crumbs_component => $bread_crumbs_component};
1.202 raeburn 5062: my ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles);
5063: my $formname = 'studentform';
1.364 raeburn 5064: my $hidecall = "hide_searching();";
1.321 raeburn 5065: if (($context eq 'domain') && (($env{'form.roletype'} eq 'course') ||
5066: ($env{'form.roletype'} eq 'community'))) {
5067: if ($env{'form.roletype'} eq 'course') {
5068: ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles) =
5069: &Apache::lonuserutils::courses_selector($env{'request.role.domain'},
5070: $formname);
5071: } elsif ($env{'form.roletype'} eq 'community') {
5072: $cb_jscript =
5073: &Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
5074: my %elements = (
5075: coursepick => 'radio',
5076: coursetotal => 'text',
5077: courselist => 'text',
5078: );
5079: $jscript = &Apache::lonhtmlcommon::set_form_elements(\%elements);
5080: }
1.364 raeburn 5081: $jscript .= &verify_user_display($context)."\n".
5082: &Apache::loncommon::check_uncheck_jscript();
1.202 raeburn 5083: my $js = &add_script($jscript).$cb_jscript;
5084: my $loadcode =
5085: &Apache::lonuserutils::course_selector_loadcode($formname);
5086: if ($loadcode ne '') {
1.364 raeburn 5087: $args->{add_entries} = {onload => "$loadcode;$hidecall"};
5088: } else {
5089: $args->{add_entries} = {onload => $hidecall};
1.202 raeburn 5090: }
1.351 raeburn 5091: $r->print(&header($js,$args));
1.191 raeburn 5092: } else {
1.364 raeburn 5093: $args->{add_entries} = {onload => $hidecall};
5094: $jscript = &verify_user_display($context).
5095: &Apache::loncommon::check_uncheck_jscript();
5096: $r->print(&header(&add_script($jscript),$args));
1.191 raeburn 5097: }
1.202 raeburn 5098: &Apache::lonuserutils::print_userlist($r,undef,$permission,$context,
1.375 raeburn 5099: $formname,$totcodes,$codetitles,$idlist,$idlist_titles,
5100: $showcredits);
1.191 raeburn 5101: }
1.213 raeburn 5102: } elsif ($env{'form.action'} eq 'drop' && $permission->{'cusr'}) {
1.318 raeburn 5103: my $brtext;
5104: if ($crstype eq 'Community') {
5105: $brtext = 'Drop Members';
5106: } else {
5107: $brtext = 'Drop Students';
5108: }
1.351 raeburn 5109: push(@{$brcrum},
5110: {href => '/adm/createuser?action=drop',
5111: text => $brtext,
5112: help => 'Course_Drop_Student'});
5113: if ($env{'form.state'} eq 'done') {
5114: push(@{$brcrum},
5115: {href=>'/adm/createuser?action=drop',
5116: text=>"Result"});
5117: }
5118: $bread_crumbs_component = $brtext;
5119: $args = {bread_crumbs => $brcrum,
5120: bread_crumbs_component => $bread_crumbs_component};
5121: $r->print(&header(undef,$args));
1.213 raeburn 5122: if (!exists($env{'form.state'})) {
1.318 raeburn 5123: &Apache::lonuserutils::print_drop_menu($r,$context,$permission,$crstype);
1.213 raeburn 5124: } elsif ($env{'form.state'} eq 'done') {
5125: &Apache::lonuserutils::update_user_list($r,$context,undef,
5126: $env{'form.action'});
5127: }
1.202 raeburn 5128: } elsif ($env{'form.action'} eq 'dateselect') {
5129: if ($permission->{'cusr'}) {
1.351 raeburn 5130: $r->print(&header(undef,{'no_nav_bar' => 1}).
1.375 raeburn 5131: &Apache::lonuserutils::date_section_selector($context,$permission,
5132: $crstype,$showcredits));
1.202 raeburn 5133: } else {
1.351 raeburn 5134: $r->print(&header(undef,{'no_nav_bar' => 1}).
5135: '<span class="LC_error">'.&mt('You do not have permission to modify dates or sections for users').'</span>');
1.202 raeburn 5136: }
1.237 raeburn 5137: } elsif ($env{'form.action'} eq 'selfenroll') {
1.398 raeburn 5138: if ($permission->{selfenrolladmin}) {
5139: my %currsettings = (
5140: selfenroll_types => $env{'course.'.$cid.'.internal.selfenroll_types'},
5141: selfenroll_registered => $env{'course.'.$cid.'.internal.selfenroll_registered'},
5142: selfenroll_section => $env{'course.'.$cid.'.internal.selfenroll_section'},
5143: selfenroll_notifylist => $env{'course.'.$cid.'.internal.selfenroll_notifylist'},
5144: selfenroll_approval => $env{'course.'.$cid.'.internal.selfenroll_approval'},
5145: selfenroll_limit => $env{'course.'.$cid.'.internal.selfenroll_limit'},
5146: selfenroll_cap => $env{'course.'.$cid.'.internal.selfenroll_cap'},
5147: selfenroll_start_date => $env{'course.'.$cid.'.internal.selfenroll_start_date'},
5148: selfenroll_end_date => $env{'course.'.$cid.'.internal.selfenroll_end_date'},
5149: selfenroll_start_access => $env{'course.'.$cid.'.internal.selfenroll_start_access'},
5150: selfenroll_end_access => $env{'course.'.$cid.'.internal.selfenroll_end_access'},
5151: default_enrollment_start_date => $env{'course.'.$cid.'.default_enrollment_start_date'},
5152: default_enrollment_end_date => $env{'course.'.$cid.'.default_enrollment_end_date'},
1.400 raeburn 5153: uniquecode => $env{'course.'.$cid.'.internal.uniquecode'},
1.398 raeburn 5154: );
5155: push(@{$brcrum},
5156: {href => '/adm/createuser?action=selfenroll',
5157: text => "Configure Self-enrollment",
5158: help => 'Course_Self_Enrollment'});
5159: if (!exists($env{'form.state'})) {
5160: $args = { bread_crumbs => $brcrum,
5161: bread_crumbs_component => 'Configure Self-enrollment'};
5162: $r->print(&header(undef,$args));
5163: $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n");
5164: &print_selfenroll_menu($r,'course',$cid,$cdom,$cnum,\%currsettings);
5165: } elsif ($env{'form.state'} eq 'done') {
5166: push (@{$brcrum},
5167: {href=>'/adm/createuser?action=selfenroll',
5168: text=>"Result"});
5169: $args = { bread_crumbs => $brcrum,
5170: bread_crumbs_component => 'Self-enrollment result'};
5171: $r->print(&header(undef,$args));
5172: $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n");
1.400 raeburn 5173: &update_selfenroll_config($r,$cid,$cdom,$cnum,$context,$crstype,\%currsettings);
1.398 raeburn 5174: }
5175: } else {
5176: $r->print(&header(undef,{'no_nav_bar' => 1}).
5177: '<span class="LC_error">'.&mt('You do not have permission to configure self-enrollment').'</span>');
1.237 raeburn 5178: }
1.277 raeburn 5179: } elsif ($env{'form.action'} eq 'selfenrollqueue') {
1.406.2.6 raeburn 5180: if ($permission->{selfenrolladmin}) {
1.351 raeburn 5181: push(@{$brcrum},
5182: {href => '/adm/createuser?action=selfenrollqueue',
1.406.2.6 raeburn 5183: text => 'Enrollment requests',
1.406.2.14 raeburn 5184: help => 'Course_Approve_Selfenroll'});
1.406.2.6 raeburn 5185: $bread_crumbs_component = 'Enrollment requests';
5186: if ($env{'form.state'} eq 'done') {
5187: push(@{$brcrum},
5188: {href => '/adm/createuser?action=selfenrollqueue',
5189: text => 'Result',
1.406.2.14 raeburn 5190: help => 'Course_Approve_Selfenroll'});
1.406.2.6 raeburn 5191: $bread_crumbs_component = 'Enrollment result';
5192: }
5193: $args = { bread_crumbs => $brcrum,
5194: bread_crumbs_component => $bread_crumbs_component};
5195: $r->print(&header(undef,$args));
5196: my $coursedesc = $env{'course.'.$cid.'.description'};
5197: if (!exists($env{'form.state'})) {
5198: $r->print('<h3>'.&mt('Pending enrollment requests').'</h3>'."\n");
5199: $r->print(&Apache::loncoursequeueadmin::display_queued_requests($context,
5200: $cdom,$cnum));
5201: } elsif ($env{'form.state'} eq 'done') {
5202: $r->print('<h3>'.&mt('Enrollment request processing').'</h3>'."\n");
5203: $r->print(&Apache::loncoursequeueadmin::update_request_queue($context,
5204: $cdom,$cnum,$coursedesc));
5205: }
5206: } else {
5207: $r->print(&header(undef,{'no_nav_bar' => 1}).
5208: '<span class="LC_error">'.&mt('You do not have permission to manage self-enrollment').'</span>');
1.277 raeburn 5209: }
1.239 raeburn 5210: } elsif ($env{'form.action'} eq 'changelogs') {
1.406.2.6 raeburn 5211: if ($permission->{cusr} || $permission->{view}) {
5212: &print_userchangelogs_display($r,$context,$permission,$brcrum);
5213: } else {
5214: $r->print(&header(undef,{'no_nav_bar' => 1}).
5215: '<span class="LC_error">'.&mt('You do not have permission to view change logs').'</span>');
5216: }
1.406.2.10 raeburn 5217: } elsif ($env{'form.action'} eq 'helpdesk') {
5218: if (($permission->{'owner'}) || ($permission->{'co-owner'})) {
5219: if ($env{'form.state'} eq 'process') {
5220: if ($permission->{'owner'}) {
5221: &update_helpdeskaccess($r,$permission,$brcrum);
5222: } else {
5223: &print_helpdeskaccess_display($r,$permission,$brcrum);
5224: }
5225: } else {
5226: &print_helpdeskaccess_display($r,$permission,$brcrum);
5227: }
5228: } else {
5229: $r->print(&header(undef,{'no_nav_bar' => 1}).
5230: '<span class="LC_error">'.&mt('You do not have permission to view helpdesk access').'</span>');
5231: }
1.190 raeburn 5232: } else {
1.351 raeburn 5233: $bread_crumbs_component = 'User Management';
5234: $args = { bread_crumbs => $brcrum,
5235: bread_crumbs_component => $bread_crumbs_component};
5236: $r->print(&header(undef,$args));
1.318 raeburn 5237: $r->print(&print_main_menu($permission,$context,$crstype));
1.190 raeburn 5238: }
1.351 raeburn 5239: $r->print(&Apache::loncommon::end_page());
1.190 raeburn 5240: return OK;
5241: }
5242:
5243: sub header {
1.351 raeburn 5244: my ($jscript,$args) = @_;
1.190 raeburn 5245: my $start_page;
1.351 raeburn 5246: if (ref($args) eq 'HASH') {
5247: $start_page=&Apache::loncommon::start_page('User Management',$jscript,$args);
1.190 raeburn 5248: } else {
1.351 raeburn 5249: $start_page=&Apache::loncommon::start_page('User Management',$jscript);
1.190 raeburn 5250: }
5251: return $start_page;
5252: }
1.2 www 5253:
1.191 raeburn 5254: sub add_script {
5255: my ($js) = @_;
1.301 bisitz 5256: return '<script type="text/javascript">'."\n"
5257: .'// <![CDATA['."\n"
5258: .$js."\n"
5259: .'// ]]>'."\n"
5260: .'</script>'."\n";
1.191 raeburn 5261: }
5262:
1.391 raeburn 5263: sub usernamerequest_javascript {
5264: my $js = <<ENDJS;
5265:
5266: function openusernamereqdisplay(dom,uname,queue) {
5267: var url = '/adm/createuser?action=displayuserreq';
5268: url += '&domain='+dom+'&username='+uname+'&queue='+queue;
5269: var title = 'Account_Request_Browser';
5270: var options = 'scrollbars=1,resizable=1,menubar=0';
5271: options += ',width=700,height=600';
5272: var stdeditbrowser = open(url,title,options,'1');
5273: stdeditbrowser.focus();
5274: return;
5275: }
5276:
5277: ENDJS
5278: }
5279:
5280: sub close_popup_form {
5281: my $close= &mt('Close Window');
5282: return << "END";
5283: <p><form name="displayreq" action="" method="post">
5284: <input type="button" name="closeme" value="$close" onclick="javascript:self.close();" />
5285: </form></p>
5286: END
5287: }
5288:
1.202 raeburn 5289: sub verify_user_display {
1.364 raeburn 5290: my ($context) = @_;
1.374 raeburn 5291: my %lt = &Apache::lonlocal::texthash (
5292: course => 'course(s): description, section(s), status',
5293: community => 'community(s): description, section(s), status',
5294: author => 'author',
5295: );
1.364 raeburn 5296: my $photos;
5297: if (($context eq 'course') && $env{'request.course.id'}) {
5298: $photos = $env{'course.'.$env{'request.course.id'}.'.internal.showphoto'};
5299: }
1.202 raeburn 5300: my $output = <<"END";
5301:
1.364 raeburn 5302: function hide_searching() {
5303: if (document.getElementById('searching')) {
5304: document.getElementById('searching').style.display = 'none';
5305: }
5306: return;
5307: }
5308:
1.202 raeburn 5309: function display_update() {
5310: document.studentform.action.value = 'listusers';
5311: document.studentform.phase.value = 'display';
5312: document.studentform.submit();
5313: }
5314:
1.364 raeburn 5315: function updateCols(caller) {
5316: var context = '$context';
5317: var photos = '$photos';
5318: if (caller == 'Status') {
1.374 raeburn 5319: if ((context == 'domain') &&
5320: ((document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'course') ||
5321: (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community'))) {
1.364 raeburn 5322: document.getElementById('showcolstatus').checked = false;
5323: document.getElementById('showcolstatus').disabled = 'disabled';
5324: document.getElementById('showcolstart').checked = false;
5325: document.getElementById('showcolend').checked = false;
1.374 raeburn 5326: } else {
5327: if (document.studentform.Status.options[document.studentform.Status.selectedIndex].value == 'Any') {
5328: document.getElementById('showcolstatus').checked = true;
5329: document.getElementById('showcolstatus').disabled = '';
5330: document.getElementById('showcolstart').checked = true;
5331: document.getElementById('showcolend').checked = true;
5332: } else {
5333: document.getElementById('showcolstatus').checked = false;
5334: document.getElementById('showcolstatus').disabled = 'disabled';
5335: document.getElementById('showcolstart').checked = false;
5336: document.getElementById('showcolend').checked = false;
5337: }
1.364 raeburn 5338: }
5339: }
5340: if (caller == 'output') {
5341: if (photos == 1) {
5342: if (document.getElementById('showcolphoto')) {
5343: var photoitem = document.getElementById('showcolphoto');
5344: if (document.studentform.output.options[document.studentform.output.selectedIndex].value == 'html') {
5345: photoitem.checked = true;
5346: photoitem.disabled = '';
5347: } else {
5348: photoitem.checked = false;
5349: photoitem.disabled = 'disabled';
5350: }
5351: }
5352: }
5353: }
5354: if (caller == 'showrole') {
1.371 raeburn 5355: if ((document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'Any') ||
5356: (document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'cr')) {
1.364 raeburn 5357: document.getElementById('showcolrole').checked = true;
5358: document.getElementById('showcolrole').disabled = '';
5359: } else {
5360: document.getElementById('showcolrole').checked = false;
5361: document.getElementById('showcolrole').disabled = 'disabled';
5362: }
1.374 raeburn 5363: if (context == 'domain') {
1.382 raeburn 5364: var quotausageshow = 0;
1.374 raeburn 5365: if ((document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'course') ||
5366: (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community')) {
5367: document.getElementById('showcolstatus').checked = false;
5368: document.getElementById('showcolstatus').disabled = 'disabled';
5369: document.getElementById('showcolstart').checked = false;
5370: document.getElementById('showcolend').checked = false;
5371: } else {
5372: if (document.studentform.Status.options[document.studentform.Status.selectedIndex].value == 'Any') {
5373: document.getElementById('showcolstatus').checked = true;
5374: document.getElementById('showcolstatus').disabled = '';
5375: document.getElementById('showcolstart').checked = true;
5376: document.getElementById('showcolend').checked = true;
5377: }
5378: }
5379: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'domain') {
5380: document.getElementById('showcolextent').disabled = 'disabled';
5381: document.getElementById('showcolextent').checked = 'false';
5382: document.getElementById('showextent').style.display='none';
5383: document.getElementById('showcoltextextent').innerHTML = '';
1.382 raeburn 5384: if ((document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'au') ||
5385: (document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'Any')) {
5386: if (document.getElementById('showcolauthorusage')) {
5387: document.getElementById('showcolauthorusage').disabled = '';
5388: }
5389: if (document.getElementById('showcolauthorquota')) {
5390: document.getElementById('showcolauthorquota').disabled = '';
5391: }
5392: quotausageshow = 1;
5393: }
1.374 raeburn 5394: } else {
5395: document.getElementById('showextent').style.display='block';
5396: document.getElementById('showextent').style.textAlign='left';
5397: document.getElementById('showextent').style.textFace='normal';
5398: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'author') {
5399: document.getElementById('showcolextent').disabled = '';
5400: document.getElementById('showcolextent').checked = 'true';
5401: document.getElementById('showcoltextextent').innerHTML="$lt{'author'}";
5402: } else {
5403: document.getElementById('showcolextent').disabled = '';
5404: document.getElementById('showcolextent').checked = 'true';
5405: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community') {
5406: document.getElementById('showcoltextextent').innerHTML="$lt{'community'}";
5407: } else {
5408: document.getElementById('showcoltextextent').innerHTML="$lt{'course'}";
5409: }
5410: }
5411: }
1.382 raeburn 5412: if (quotausageshow == 0) {
5413: if (document.getElementById('showcolauthorusage')) {
5414: document.getElementById('showcolauthorusage').checked = false;
5415: document.getElementById('showcolauthorusage').disabled = 'disabled';
5416: }
5417: if (document.getElementById('showcolauthorquota')) {
5418: document.getElementById('showcolauthorquota').checked = false;
5419: document.getElementById('showcolauthorquota').disabled = 'disabled';
5420: }
5421: }
1.374 raeburn 5422: }
1.364 raeburn 5423: }
5424: return;
5425: }
5426:
1.202 raeburn 5427: END
5428: return $output;
5429:
5430: }
5431:
1.190 raeburn 5432: ###############################################################
5433: ###############################################################
5434: # Menu Phase One
5435: sub print_main_menu {
1.318 raeburn 5436: my ($permission,$context,$crstype) = @_;
5437: my $linkcontext = $context;
5438: my $stuterm = lc(&Apache::lonnet::plaintext('st',$crstype));
5439: if (($context eq 'course') && ($crstype eq 'Community')) {
5440: $linkcontext = lc($crstype);
5441: $stuterm = 'Members';
5442: }
1.208 raeburn 5443: my %links = (
1.298 droeschl 5444: domain => {
5445: upload => 'Upload a File of Users',
5446: singleuser => 'Add/Modify a User',
5447: listusers => 'Manage Users',
5448: },
5449: author => {
5450: upload => 'Upload a File of Co-authors',
5451: singleuser => 'Add/Modify a Co-author',
5452: listusers => 'Manage Co-authors',
5453: },
5454: course => {
5455: upload => 'Upload a File of Course Users',
5456: singleuser => 'Add/Modify a Course User',
1.354 www 5457: listusers => 'List and Modify Multiple Course Users',
1.298 droeschl 5458: },
1.318 raeburn 5459: community => {
5460: upload => 'Upload a File of Community Users',
5461: singleuser => 'Add/Modify a Community User',
1.354 www 5462: listusers => 'List and Modify Multiple Community Users',
1.318 raeburn 5463: },
5464: );
5465: my %linktitles = (
5466: domain => {
5467: singleuser => 'Add a user to the domain, and/or a course or community in the domain.',
5468: listusers => 'Show and manage users in this domain.',
5469: },
5470: author => {
5471: singleuser => 'Add a user with a co- or assistant author role.',
5472: listusers => 'Show and manage co- or assistant authors.',
5473: },
5474: course => {
5475: singleuser => 'Add a user with a certain role to this course.',
5476: listusers => 'Show and manage users in this course.',
5477: },
5478: community => {
5479: singleuser => 'Add a user with a certain role to this community.',
5480: listusers => 'Show and manage users in this community.',
5481: },
1.298 droeschl 5482: );
1.406.2.6 raeburn 5483: if ($linkcontext eq 'domain') {
5484: unless ($permission->{'cusr'}) {
5485: $links{'domain'}{'singleuser'} = 'View a User';
5486: $linktitles{'domain'}{'singleuser'} = 'View information about a user in the domain';
5487: }
5488: } elsif ($linkcontext eq 'course') {
5489: unless ($permission->{'cusr'}) {
5490: $links{'course'}{'singleuser'} = 'View a Course User';
5491: $linktitles{'course'}{'singleuser'} = 'View information about a user in this course';
5492: $links{'course'}{'listusers'} = 'List Course Users';
5493: $linktitles{'course'}{'listusers'} = 'Show information about users in this course';
5494: }
5495: } elsif ($linkcontext eq 'community') {
5496: unless ($permission->{'cusr'}) {
5497: $links{'community'}{'singleuser'} = 'View a Community User';
5498: $linktitles{'community'}{'singleuser'} = 'View information about a user in this community';
5499: $links{'community'}{'listusers'} = 'List Community Users';
5500: $linktitles{'community'}{'listusers'} = 'Show information about users in this community';
5501: }
5502: }
1.298 droeschl 5503: my @menu = ( {categorytitle => 'Single Users',
5504: items =>
5505: [
5506: {
1.318 raeburn 5507: linktext => $links{$linkcontext}{'singleuser'},
1.298 droeschl 5508: icon => 'edit-redo.png',
5509: #help => 'Course_Change_Privileges',
5510: url => '/adm/createuser?action=singleuser',
1.406.2.6 raeburn 5511: permission => ($permission->{'view'} || $permission->{'cusr'}),
1.318 raeburn 5512: linktitle => $linktitles{$linkcontext}{'singleuser'},
1.298 droeschl 5513: },
5514: ]},
5515:
5516: {categorytitle => 'Multiple Users',
5517: items =>
5518: [
5519: {
1.318 raeburn 5520: linktext => $links{$linkcontext}{'upload'},
1.340 wenzelju 5521: icon => 'uplusr.png',
1.298 droeschl 5522: #help => 'Course_Create_Class_List',
5523: url => '/adm/createuser?action=upload',
5524: permission => $permission->{'cusr'},
5525: linktitle => 'Upload a CSV or a text file containing users.',
5526: },
5527: {
1.318 raeburn 5528: linktext => $links{$linkcontext}{'listusers'},
1.340 wenzelju 5529: icon => 'mngcu.png',
1.298 droeschl 5530: #help => 'Course_View_Class_List',
5531: url => '/adm/createuser?action=listusers',
5532: permission => ($permission->{'view'} || $permission->{'cusr'}),
1.318 raeburn 5533: linktitle => $linktitles{$linkcontext}{'listusers'},
1.298 droeschl 5534: },
5535:
5536: ]},
5537:
5538: {categorytitle => 'Administration',
5539: items => [ ]},
5540: );
1.406.2.5 raeburn 5541:
1.265 mielkec 5542: if ($context eq 'domain'){
1.406.2.5 raeburn 5543: push(@{ $menu[0]->{items} }, # Single Users
5544: {
5545: linktext => 'User Access Log',
5546: icon => 'document-properties.png',
1.406.2.8 raeburn 5547: #help => 'Domain_User_Access_Logs',
1.406.2.5 raeburn 5548: url => '/adm/createuser?action=accesslogs',
5549: permission => $permission->{'activity'},
5550: linktitle => 'View user access log.',
5551: }
5552: );
1.298 droeschl 5553:
5554: push(@{ $menu[2]->{items} }, #Category: Administration
5555: {
5556: linktext => 'Custom Roles',
5557: icon => 'emblem-photos.png',
5558: #help => 'Course_Editing_Custom_Roles',
5559: url => '/adm/createuser?action=custom',
5560: permission => $permission->{'custom'},
5561: linktitle => 'Configure a custom role.',
5562: },
1.362 raeburn 5563: {
5564: linktext => 'Authoring Space Requests',
5565: icon => 'selfenrl-queue.png',
5566: #help => 'Domain_Role_Approvals',
5567: url => '/adm/createuser?action=processauthorreq',
5568: permission => $permission->{'cusr'},
5569: linktitle => 'Approve or reject author role requests',
5570: },
1.363 raeburn 5571: {
1.391 raeburn 5572: linktext => 'LON-CAPA Account Requests',
5573: icon => 'list-add.png',
5574: #help => 'Domain_Username_Approvals',
5575: url => '/adm/createuser?action=processusernamereq',
5576: permission => $permission->{'cusr'},
5577: linktitle => 'Approve or reject LON-CAPA account requests',
5578: },
5579: {
1.363 raeburn 5580: linktext => 'Change Log',
5581: icon => 'document-properties.png',
5582: #help => 'Course_User_Logs',
5583: url => '/adm/createuser?action=changelogs',
1.406.2.6 raeburn 5584: permission => ($permission->{'cusr'} || $permission->{'view'}),
1.363 raeburn 5585: linktitle => 'View change log.',
5586: },
1.298 droeschl 5587: );
5588:
1.265 mielkec 5589: }elsif ($context eq 'course'){
1.298 droeschl 5590: my ($cnum,$cdom) = &Apache::lonuserutils::get_course_identity();
1.318 raeburn 5591:
5592: my %linktext = (
5593: 'Course' => {
5594: single => 'Add/Modify a Student',
5595: drop => 'Drop Students',
5596: groups => 'Course Groups',
5597: },
5598: 'Community' => {
5599: single => 'Add/Modify a Member',
5600: drop => 'Drop Members',
5601: groups => 'Community Groups',
5602: },
5603: );
5604:
5605: my %linktitle = (
5606: 'Course' => {
5607: single => 'Add a user with the role of student to this course',
5608: drop => 'Remove a student from this course.',
5609: groups => 'Manage course groups',
5610: },
5611: 'Community' => {
5612: single => 'Add a user with the role of member to this community',
5613: drop => 'Remove a member from this community.',
5614: groups => 'Manage community groups',
5615: },
5616: );
5617:
1.298 droeschl 5618: push(@{ $menu[0]->{items} }, #Category: Single Users
5619: {
1.318 raeburn 5620: linktext => $linktext{$crstype}{'single'},
1.298 droeschl 5621: #help => 'Course_Add_Student',
5622: icon => 'list-add.png',
5623: url => '/adm/createuser?action=singlestudent',
5624: permission => $permission->{'cusr'},
1.318 raeburn 5625: linktitle => $linktitle{$crstype}{'single'},
1.298 droeschl 5626: },
5627: );
5628:
5629: push(@{ $menu[1]->{items} }, #Category: Multiple Users
5630: {
1.318 raeburn 5631: linktext => $linktext{$crstype}{'drop'},
1.298 droeschl 5632: icon => 'edit-undo.png',
5633: #help => 'Course_Drop_Student',
5634: url => '/adm/createuser?action=drop',
5635: permission => $permission->{'cusr'},
1.318 raeburn 5636: linktitle => $linktitle{$crstype}{'drop'},
1.298 droeschl 5637: },
5638: );
5639: push(@{ $menu[2]->{items} }, #Category: Administration
1.406.2.11 raeburn 5640: {
5641: linktext => 'Helpdesk Access',
5642: icon => 'helpdesk-access.png',
5643: #help => 'Course_Helpdesk_Access',
5644: url => '/adm/createuser?action=helpdesk',
5645: permission => ($permission->{'owner'} || $permission->{'co-owner'}),
5646: linktitle => 'Helpdesk access options',
5647: },
5648: {
1.298 droeschl 5649: linktext => 'Custom Roles',
5650: icon => 'emblem-photos.png',
5651: #help => 'Course_Editing_Custom_Roles',
5652: url => '/adm/createuser?action=custom',
5653: permission => $permission->{'custom'},
5654: linktitle => 'Configure a custom role.',
5655: },
5656: {
1.318 raeburn 5657: linktext => $linktext{$crstype}{'groups'},
1.333 wenzelju 5658: icon => 'grps.png',
1.298 droeschl 5659: #help => 'Course_Manage_Group',
5660: url => '/adm/coursegroups?refpage=cusr',
5661: permission => $permission->{'grp_manage'},
1.318 raeburn 5662: linktitle => $linktitle{$crstype}{'groups'},
1.298 droeschl 5663: },
5664: {
1.328 wenzelju 5665: linktext => 'Change Log',
1.298 droeschl 5666: icon => 'document-properties.png',
5667: #help => 'Course_User_Logs',
5668: url => '/adm/createuser?action=changelogs',
1.406.2.6 raeburn 5669: permission => ($permission->{'view'} || $permission->{'cusr'}),
1.298 droeschl 5670: linktitle => 'View change log.',
5671: },
5672: );
1.277 raeburn 5673: if ($env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_approval'}) {
1.298 droeschl 5674: push(@{ $menu[2]->{items} },
1.398 raeburn 5675: {
1.298 droeschl 5676: linktext => 'Enrollment Requests',
5677: icon => 'selfenrl-queue.png',
5678: #help => 'Course_Approve_Selfenroll',
5679: url => '/adm/createuser?action=selfenrollqueue',
1.398 raeburn 5680: permission => $permission->{'selfenrolladmin'},
1.298 droeschl 5681: linktitle =>'Approve or reject enrollment requests.',
5682: },
5683: );
1.277 raeburn 5684: }
1.298 droeschl 5685:
1.265 mielkec 5686: if (!exists($permission->{'cusr_section'})){
1.320 raeburn 5687: if ($crstype ne 'Community') {
5688: push(@{ $menu[2]->{items} },
5689: {
5690: linktext => 'Automated Enrollment',
5691: icon => 'roles.png',
5692: #help => 'Course_Automated_Enrollment',
5693: permission => (&Apache::lonnet::auto_run($cnum,$cdom)
1.406.2.6 raeburn 5694: && (($permission->{'cusr'}) ||
5695: ($permission->{'view'}))),
1.320 raeburn 5696: url => '/adm/populate',
5697: linktitle => 'Automated enrollment manager.',
5698: }
5699: );
5700: }
5701: push(@{ $menu[2]->{items} },
1.298 droeschl 5702: {
5703: linktext => 'User Self-Enrollment',
1.342 wenzelju 5704: icon => 'self_enroll.png',
1.298 droeschl 5705: #help => 'Course_Self_Enrollment',
5706: url => '/adm/createuser?action=selfenroll',
1.398 raeburn 5707: permission => $permission->{'selfenrolladmin'},
1.317 bisitz 5708: linktitle => 'Configure user self-enrollment.',
1.298 droeschl 5709: },
5710: );
5711: }
1.363 raeburn 5712: } elsif ($context eq 'author') {
1.370 raeburn 5713: push(@{ $menu[2]->{items} }, #Category: Administration
1.363 raeburn 5714: {
5715: linktext => 'Change Log',
5716: icon => 'document-properties.png',
5717: #help => 'Course_User_Logs',
5718: url => '/adm/createuser?action=changelogs',
5719: permission => $permission->{'cusr'},
5720: linktitle => 'View change log.',
5721: },
1.370 raeburn 5722: );
1.363 raeburn 5723: }
5724: return Apache::lonhtmlcommon::generate_menu(@menu);
1.250 raeburn 5725: # { text => 'View Log-in History',
5726: # help => 'Course_User_Logins',
5727: # action => 'logins',
5728: # permission => $permission->{'cusr'},
5729: # });
1.190 raeburn 5730: }
5731:
1.189 albertel 5732: sub restore_prev_selections {
5733: my %saveable_parameters = ('srchby' => 'scalar',
5734: 'srchin' => 'scalar',
5735: 'srchtype' => 'scalar',
5736: );
5737: &Apache::loncommon::store_settings('user','user_picker',
5738: \%saveable_parameters);
5739: &Apache::loncommon::restore_settings('user','user_picker',
5740: \%saveable_parameters);
5741: }
5742:
1.237 raeburn 5743: sub print_selfenroll_menu {
1.406.2.6 raeburn 5744: my ($r,$context,$cid,$cdom,$cnum,$currsettings,$additional,$readonly) = @_;
1.322 raeburn 5745: my $crstype = &Apache::loncommon::course_type();
1.398 raeburn 5746: my $formname = 'selfenroll';
1.237 raeburn 5747: my $nolink = 1;
1.398 raeburn 5748: my ($row,$lt) = &Apache::lonuserutils::get_selfenroll_titles();
1.237 raeburn 5749: my $groupslist = &Apache::lonuserutils::get_groupslist();
5750: my $setsec_js =
5751: &Apache::lonuserutils::setsections_javascript($formname,$groupslist);
1.249 raeburn 5752: my %alerts = &Apache::lonlocal::texthash(
5753: acto => 'Activation of self-enrollment was selected for the following domain(s)',
5754: butn => 'but no user types have been checked.',
5755: wilf => "Please uncheck 'activate' or check at least one type.",
5756: );
1.406.2.6 raeburn 5757: my $disabled;
5758: if ($readonly) {
5759: $disabled = ' disabled="disabled"';
5760: }
1.405 damieng 5761: &js_escape(\%alerts);
1.249 raeburn 5762: my $selfenroll_js = <<"ENDSCRIPT";
5763: function update_types(caller,num) {
5764: var delidx = getIndexByName('selfenroll_delete');
5765: var actidx = getIndexByName('selfenroll_activate');
5766: if (caller == 'selfenroll_all') {
5767: var selall;
5768: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
5769: if (document.$formname.selfenroll_all[i].checked) {
5770: selall = document.$formname.selfenroll_all[i].value;
5771: }
5772: }
5773: if (selall == 1) {
5774: if (delidx != -1) {
5775: if (document.$formname.selfenroll_delete.length) {
5776: for (var j=0; j<document.$formname.selfenroll_delete.length; j++) {
5777: document.$formname.selfenroll_delete[j].checked = true;
5778: }
5779: } else {
5780: document.$formname.elements[delidx].checked = true;
5781: }
5782: }
5783: if (actidx != -1) {
5784: if (document.$formname.selfenroll_activate.length) {
5785: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
5786: document.$formname.selfenroll_activate[j].checked = false;
5787: }
5788: } else {
5789: document.$formname.elements[actidx].checked = false;
5790: }
5791: }
5792: document.$formname.selfenroll_newdom.selectedIndex = 0;
5793: }
5794: }
5795: if (caller == 'selfenroll_activate') {
5796: if (document.$formname.selfenroll_activate.length) {
5797: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
5798: if (document.$formname.selfenroll_activate[j].value == num) {
5799: if (document.$formname.selfenroll_activate[j].checked) {
5800: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
5801: if (document.$formname.selfenroll_all[i].value == '1') {
5802: document.$formname.selfenroll_all[i].checked = false;
5803: }
5804: if (document.$formname.selfenroll_all[i].value == '0') {
5805: document.$formname.selfenroll_all[i].checked = true;
5806: }
5807: }
5808: }
5809: }
5810: }
5811: } else {
5812: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
5813: if (document.$formname.selfenroll_all[i].value == '1') {
5814: document.$formname.selfenroll_all[i].checked = false;
5815: }
5816: if (document.$formname.selfenroll_all[i].value == '0') {
5817: document.$formname.selfenroll_all[i].checked = true;
5818: }
5819: }
5820: }
5821: }
5822: if (caller == 'selfenroll_delete') {
5823: if (document.$formname.selfenroll_delete.length) {
5824: for (var j=0; j<document.$formname.selfenroll_delete.length; j++) {
5825: if (document.$formname.selfenroll_delete[j].value == num) {
5826: if (document.$formname.selfenroll_delete[j].checked) {
5827: var delindex = getIndexByName('selfenroll_types_'+num);
5828: if (delindex != -1) {
5829: if (document.$formname.elements[delindex].length) {
5830: for (var k=0; k<document.$formname.elements[delindex].length; k++) {
5831: document.$formname.elements[delindex][k].checked = false;
5832: }
5833: } else {
5834: document.$formname.elements[delindex].checked = false;
5835: }
5836: }
5837: }
5838: }
5839: }
5840: } else {
5841: if (document.$formname.selfenroll_delete.checked) {
5842: var delindex = getIndexByName('selfenroll_types_'+num);
5843: if (delindex != -1) {
5844: if (document.$formname.elements[delindex].length) {
5845: for (var k=0; k<document.$formname.elements[delindex].length; k++) {
5846: document.$formname.elements[delindex][k].checked = false;
5847: }
5848: } else {
5849: document.$formname.elements[delindex].checked = false;
5850: }
5851: }
5852: }
5853: }
5854: }
5855: return;
5856: }
5857:
5858: function validate_types(form) {
5859: var needaction = new Array();
5860: var countfail = 0;
5861: var actidx = getIndexByName('selfenroll_activate');
5862: if (actidx != -1) {
5863: if (document.$formname.selfenroll_activate.length) {
5864: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
5865: var num = document.$formname.selfenroll_activate[j].value;
5866: if (document.$formname.selfenroll_activate[j].checked) {
5867: countfail = check_types(num,countfail,needaction)
5868: }
5869: }
5870: } else {
5871: if (document.$formname.selfenroll_activate.checked) {
1.398 raeburn 5872: var num = document.$formname.selfenroll_activate.value;
1.249 raeburn 5873: countfail = check_types(num,countfail,needaction)
5874: }
5875: }
5876: }
5877: if (countfail > 0) {
5878: var msg = "$alerts{'acto'}\\n";
5879: var loopend = needaction.length -1;
5880: if (loopend > 0) {
5881: for (var m=0; m<loopend; m++) {
5882: msg += needaction[m]+", ";
5883: }
5884: }
5885: msg += needaction[loopend]+"\\n$alerts{'butn'}\\n$alerts{'wilf'}";
5886: alert(msg);
5887: return;
5888: }
5889: setSections(form);
5890: }
5891:
5892: function check_types(num,countfail,needaction) {
1.406.2.14.2. (raeburn 5893:): var boxname = 'selfenroll_types_'+num;
5894:): var typeidx = getIndexByName(boxname);
1.249 raeburn 5895: var count = 0;
5896: if (typeidx != -1) {
1.406.2.14.2. (raeburn 5897:): if (document.$formname.elements[boxname].length) {
5898:): for (var k=0; k<document.$formname.elements[boxname].length; k++) {
5899:): if (document.$formname.elements[boxname][k].checked) {
1.249 raeburn 5900: count ++;
5901: }
5902: }
5903: } else {
5904: if (document.$formname.elements[typeidx].checked) {
5905: count ++;
5906: }
5907: }
5908: if (count == 0) {
5909: var domidx = getIndexByName('selfenroll_dom_'+num);
5910: if (domidx != -1) {
5911: var domname = document.$formname.elements[domidx].value;
5912: needaction[countfail] = domname;
5913: countfail ++;
5914: }
5915: }
5916: }
5917: return countfail;
5918: }
5919:
1.398 raeburn 5920: function toggleNotify() {
5921: var selfenrollApproval = 0;
5922: if (document.$formname.selfenroll_approval.length) {
5923: for (var i=0; i<document.$formname.selfenroll_approval.length; i++) {
5924: if (document.$formname.selfenroll_approval[i].checked) {
5925: selfenrollApproval = document.$formname.selfenroll_approval[i].value;
5926: break;
5927: }
5928: }
5929: }
5930: if (document.getElementById('notified')) {
5931: if (selfenrollApproval == 0) {
5932: document.getElementById('notified').style.display='none';
5933: } else {
5934: document.getElementById('notified').style.display='block';
5935: }
5936: }
5937: return;
5938: }
5939:
1.249 raeburn 5940: function getIndexByName(item) {
5941: for (var i=0;i<document.$formname.elements.length;i++) {
5942: if (document.$formname.elements[i].name == item) {
5943: return i;
5944: }
5945: }
5946: return -1;
5947: }
5948: ENDSCRIPT
1.256 raeburn 5949:
1.237 raeburn 5950: my $output = '<script type="text/javascript">'."\n".
1.301 bisitz 5951: '// <![CDATA['."\n".
1.249 raeburn 5952: $setsec_js."\n".$selfenroll_js."\n".
1.301 bisitz 5953: '// ]]>'."\n".
1.237 raeburn 5954: '</script>'."\n".
1.256 raeburn 5955: '<h3>'.$lt->{'selfenroll'}.'</h3>'."\n";
1.400 raeburn 5956:
5957: my $visactions = &cat_visibility();
5958: my ($cathash,%cattype);
5959: my %domconfig = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom);
5960: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
5961: $cathash = $domconfig{'coursecategories'}{'cats'};
5962: $cattype{'auth'} = $domconfig{'coursecategories'}{'auth'};
5963: $cattype{'unauth'} = $domconfig{'coursecategories'}{'unauth'};
1.406 raeburn 5964: if ($cattype{'auth'} eq '') {
5965: $cattype{'auth'} = 'std';
5966: }
5967: if ($cattype{'unauth'} eq '') {
5968: $cattype{'unauth'} = 'std';
5969: }
1.400 raeburn 5970: } else {
5971: $cathash = {};
5972: $cattype{'auth'} = 'std';
5973: $cattype{'unauth'} = 'std';
5974: }
5975: if (($cattype{'auth'} eq 'none') && ($cattype{'unauth'} eq 'none')) {
5976: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
5977: '<br />'.
5978: '<br />'.$visactions->{'take'}.'<ul>'.
5979: '<li>'.$visactions->{'dc_chgconf'}.'</li>'.
5980: '</ul>');
5981: } elsif (($cattype{'auth'} !~ /^(std|domonly)$/) && ($cattype{'unauth'} !~ /^(std|domonly)$/)) {
5982: if ($currsettings->{'uniquecode'}) {
5983: $r->print('<span class="LC_info">'.$visactions->{'vis'}.'</span>');
5984: } else {
5985: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
5986: '<br />'.
5987: '<br />'.$visactions->{'take'}.'<ul>'.
5988: '<li>'.$visactions->{'dc_setcode'}.'</li>'.
5989: '</ul><br />');
5990: }
5991: } else {
5992: my ($visible,$cansetvis,$vismsgs) = &visible_in_stdcat($cdom,$cnum,\%domconfig);
5993: if (ref($visactions) eq 'HASH') {
5994: if ($visible) {
5995: $output .= '<p class="LC_info">'.$visactions->{'vis'}.'</p>';
5996: } else {
5997: $output .= '<p class="LC_warning">'.$visactions->{'miss'}.'</p>'
5998: .$visactions->{'yous'}.
5999: '<p>'.$visactions->{'gen'}.'<br />'.$visactions->{'coca'};
6000: if (ref($vismsgs) eq 'ARRAY') {
6001: $output .= '<br />'.$visactions->{'make'}.'<ul>';
6002: foreach my $item (@{$vismsgs}) {
6003: $output .= '<li>'.$visactions->{$item}.'</li>';
6004: }
6005: $output .= '</ul>';
1.256 raeburn 6006: }
1.400 raeburn 6007: $output .= '</p>';
1.256 raeburn 6008: }
6009: }
6010: }
1.398 raeburn 6011: my $actionhref = '/adm/createuser';
6012: if ($context eq 'domain') {
6013: $actionhref = '/adm/modifycourse';
6014: }
1.400 raeburn 6015:
6016: my %noedit;
6017: unless ($context eq 'domain') {
6018: %noedit = &get_noedit_fields($cdom,$cnum,$crstype,$row);
6019: }
1.398 raeburn 6020: $output .= '<form name="'.$formname.'" method="post" action="'.$actionhref.'">'."\n".
1.256 raeburn 6021: &Apache::lonhtmlcommon::start_pick_box();
1.237 raeburn 6022: if (ref($row) eq 'ARRAY') {
6023: foreach my $item (@{$row}) {
6024: my $title = $item;
6025: if (ref($lt) eq 'HASH') {
6026: $title = $lt->{$item};
6027: }
1.297 bisitz 6028: $output .= &Apache::lonhtmlcommon::row_title($title);
1.237 raeburn 6029: if ($item eq 'types') {
1.398 raeburn 6030: my $curr_types;
6031: if (ref($currsettings) eq 'HASH') {
6032: $curr_types = $currsettings->{'selfenroll_types'};
6033: }
1.400 raeburn 6034: if ($noedit{$item}) {
6035: if ($curr_types eq '*') {
6036: $output .= &mt('Any user in any domain');
6037: } else {
6038: my @entries = split(/;/,$curr_types);
6039: if (@entries > 0) {
6040: $output .= '<ul>';
6041: foreach my $entry (@entries) {
6042: my ($currdom,$typestr) = split(/:/,$entry);
6043: next if ($typestr eq '');
6044: my $domdesc = &Apache::lonnet::domain($currdom);
6045: my @currinsttypes = split(',',$typestr);
6046: my ($othertitle,$usertypes,$types) =
6047: &Apache::loncommon::sorted_inst_types($currdom);
6048: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
6049: $usertypes->{'any'} = &mt('any user');
6050: if (keys(%{$usertypes}) > 0) {
6051: $usertypes->{'other'} = &mt('other users');
6052: }
6053: my @longinsttypes = map { $usertypes->{$_}; } @currinsttypes;
6054: $output .= '<li>'.$domdesc.':'.join(', ',@longinsttypes).'</li>';
6055: }
6056: }
6057: $output .= '</ul>';
6058: } else {
6059: $output .= &mt('None');
6060: }
6061: }
6062: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6063: next;
6064: }
1.241 raeburn 6065: my $showdomdesc = 1;
6066: my $includeempty = 1;
6067: my $num = 0;
6068: $output .= &Apache::loncommon::start_data_table().
6069: &Apache::loncommon::start_data_table_row()
6070: .'<td colspan="2"><span class="LC_nobreak"><label>'
6071: .&mt('Any user in any domain:')
6072: .' <input type="radio" name="selfenroll_all" value="1" ';
6073: if ($curr_types eq '*') {
6074: $output .= ' checked="checked" ';
6075: }
1.249 raeburn 6076: $output .= 'onchange="javascript:update_types('.
1.406.2.6 raeburn 6077: "'selfenroll_all'".');"'.$disabled.' />'.&mt('Yes').'</label>'.
1.249 raeburn 6078: ' <input type="radio" name="selfenroll_all" value="0" ';
1.241 raeburn 6079: if ($curr_types ne '*') {
6080: $output .= ' checked="checked" ';
6081: }
1.249 raeburn 6082: $output .= ' onchange="javascript:update_types('.
1.406.2.6 raeburn 6083: "'selfenroll_all'".');"'.$disabled.' />'.&mt('No').'</label></td>'.
1.249 raeburn 6084: &Apache::loncommon::end_data_table_row().
6085: &Apache::loncommon::end_data_table().
6086: &mt('Or').'<br />'.
6087: &Apache::loncommon::start_data_table();
1.241 raeburn 6088: my %currdoms;
1.249 raeburn 6089: if ($curr_types eq '') {
1.241 raeburn 6090: $output .= &new_selfenroll_dom_row($cdom,'0');
6091: } elsif ($curr_types ne '*') {
6092: my @entries = split(/;/,$curr_types);
6093: if (@entries > 0) {
6094: foreach my $entry (@entries) {
6095: my ($currdom,$typestr) = split(/:/,$entry);
6096: $currdoms{$currdom} = 1;
6097: my $domdesc = &Apache::lonnet::domain($currdom);
1.249 raeburn 6098: my @currinsttypes = split(',',$typestr);
1.241 raeburn 6099: $output .= &Apache::loncommon::start_data_table_row()
6100: .'<td valign="top"><span class="LC_nobreak">'.&mt('Domain:').'<b>'
6101: .' '.$domdesc.' ('.$currdom.')'
6102: .'</b><input type="hidden" name="selfenroll_dom_'.$num
6103: .'" value="'.$currdom.'" /></span><br />'
6104: .'<span class="LC_nobreak"><label><input type="checkbox" '
1.406.2.6 raeburn 6105: .'name="selfenroll_delete" value="'.$num.'" onchange="javascript:update_types('."'selfenroll_delete','$num'".');"'.$disabled.' />'
1.241 raeburn 6106: .&mt('Delete').'</label></span></td>';
1.249 raeburn 6107: $output .= '<td valign="top"> '.&mt('User types:').'<br />'
1.406.2.6 raeburn 6108: .&selfenroll_inst_types($num,$currdom,\@currinsttypes,$readonly).'</td>'
1.241 raeburn 6109: .&Apache::loncommon::end_data_table_row();
6110: $num ++;
6111: }
6112: }
6113: }
1.249 raeburn 6114: my $add_domtitle = &mt('Users in additional domain:');
1.241 raeburn 6115: if ($curr_types eq '*') {
1.249 raeburn 6116: $add_domtitle = &mt('Users in specific domain:');
1.241 raeburn 6117: } elsif ($curr_types eq '') {
1.249 raeburn 6118: $add_domtitle = &mt('Users in other domain:');
1.241 raeburn 6119: }
6120: $output .= &Apache::loncommon::start_data_table_row()
6121: .'<td colspan="2"><span class="LC_nobreak">'.$add_domtitle.'</span><br />'
6122: .&Apache::loncommon::select_dom_form('','selfenroll_newdom',
1.406.2.6 raeburn 6123: $includeempty,$showdomdesc,'','','',$readonly)
1.241 raeburn 6124: .'<input type="hidden" name="selfenroll_types_total" value="'.$num.'" />'
6125: .'</td>'.&Apache::loncommon::end_data_table_row()
6126: .&Apache::loncommon::end_data_table();
1.237 raeburn 6127: } elsif ($item eq 'registered') {
6128: my ($regon,$regoff);
1.398 raeburn 6129: my $registered;
6130: if (ref($currsettings) eq 'HASH') {
6131: $registered = $currsettings->{'selfenroll_registered'};
6132: }
1.400 raeburn 6133: if ($noedit{$item}) {
6134: if ($registered) {
6135: $output .= &mt('Must be registered in course');
6136: } else {
6137: $output .= &mt('No requirement');
6138: }
6139: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6140: next;
6141: }
1.398 raeburn 6142: if ($registered) {
1.237 raeburn 6143: $regon = ' checked="checked" ';
1.406.2.6 raeburn 6144: $regoff = '';
1.237 raeburn 6145: } else {
1.406.2.6 raeburn 6146: $regon = '';
1.237 raeburn 6147: $regoff = ' checked="checked" ';
6148: }
6149: $output .= '<label>'.
1.406.2.6 raeburn 6150: '<input type="radio" name="selfenroll_registered" value="1"'.$regon.$disabled.' />'.
1.244 bisitz 6151: &mt('Yes').'</label> <label>'.
1.406.2.6 raeburn 6152: '<input type="radio" name="selfenroll_registered" value="0"'.$regoff.$disabled.' />'.
1.244 bisitz 6153: &mt('No').'</label>';
1.237 raeburn 6154: } elsif ($item eq 'enroll_dates') {
1.398 raeburn 6155: my ($starttime,$endtime);
6156: if (ref($currsettings) eq 'HASH') {
6157: $starttime = $currsettings->{'selfenroll_start_date'};
6158: $endtime = $currsettings->{'selfenroll_end_date'};
6159: if ($starttime eq '') {
6160: $starttime = $currsettings->{'default_enrollment_start_date'};
6161: }
6162: if ($endtime eq '') {
6163: $endtime = $currsettings->{'default_enrollment_end_date'};
6164: }
1.237 raeburn 6165: }
1.400 raeburn 6166: if ($noedit{$item}) {
6167: $output .= &mt('From: [_1], to: [_2]',&Apache::lonlocal::locallocaltime($starttime),
6168: &Apache::lonlocal::locallocaltime($endtime));
6169: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6170: next;
6171: }
1.237 raeburn 6172: my $startform =
6173: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_start_date',$starttime,
1.406.2.6 raeburn 6174: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
1.237 raeburn 6175: my $endform =
6176: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_end_date',$endtime,
1.406.2.6 raeburn 6177: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
1.237 raeburn 6178: $output .= &selfenroll_date_forms($startform,$endform);
6179: } elsif ($item eq 'access_dates') {
1.398 raeburn 6180: my ($starttime,$endtime);
6181: if (ref($currsettings) eq 'HASH') {
6182: $starttime = $currsettings->{'selfenroll_start_access'};
6183: $endtime = $currsettings->{'selfenroll_end_access'};
6184: if ($starttime eq '') {
6185: $starttime = $currsettings->{'default_enrollment_start_date'};
6186: }
6187: if ($endtime eq '') {
6188: $endtime = $currsettings->{'default_enrollment_end_date'};
6189: }
1.237 raeburn 6190: }
1.400 raeburn 6191: if ($noedit{$item}) {
6192: $output .= &mt('From: [_1], to: [_2]',&Apache::lonlocal::locallocaltime($starttime),
6193: &Apache::lonlocal::locallocaltime($endtime));
6194: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6195: next;
6196: }
1.237 raeburn 6197: my $startform =
6198: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_start_access',$starttime,
1.406.2.6 raeburn 6199: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
1.237 raeburn 6200: my $endform =
6201: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_end_access',$endtime,
1.406.2.6 raeburn 6202: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
1.237 raeburn 6203: $output .= &selfenroll_date_forms($startform,$endform);
6204: } elsif ($item eq 'section') {
1.398 raeburn 6205: my $currsec;
6206: if (ref($currsettings) eq 'HASH') {
6207: $currsec = $currsettings->{'selfenroll_section'};
6208: }
1.237 raeburn 6209: my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum);
6210: my $newsecval;
6211: if ($currsec ne 'none' && $currsec ne '') {
6212: if (!defined($sections_count{$currsec})) {
6213: $newsecval = $currsec;
6214: }
6215: }
1.400 raeburn 6216: if ($noedit{$item}) {
6217: if ($currsec ne '') {
6218: $output .= $currsec;
6219: } else {
6220: $output .= &mt('No specific section');
6221: }
6222: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6223: next;
6224: }
1.237 raeburn 6225: my $sections_select =
1.406.2.6 raeburn 6226: &Apache::lonuserutils::course_sections(\%sections_count,'st',$currsec,$disabled);
1.237 raeburn 6227: $output .= '<table class="LC_createuser">'."\n".
6228: '<tr class="LC_section_row">'."\n".
6229: '<td align="center">'.&mt('Existing sections')."\n".
6230: '<br />'.$sections_select.'</td><td align="center">'.
6231: &mt('New section').'<br />'."\n".
1.406.2.6 raeburn 6232: '<input type="text" name="newsec" size="15" value="'.$newsecval.'"'.$disabled.' />'."\n".
1.237 raeburn 6233: '<input type="hidden" name="sections" value="" />'."\n".
6234: '</td></tr></table>'."\n";
1.276 raeburn 6235: } elsif ($item eq 'approval') {
1.398 raeburn 6236: my ($currnotified,$currapproval,%appchecked);
6237: my %selfdescs = &Apache::lonuserutils::selfenroll_default_descs();
1.406.2.6 raeburn 6238: if (ref($currsettings) eq 'HASH') {
1.398 raeburn 6239: $currnotified = $currsettings->{'selfenroll_notifylist'};
6240: $currapproval = $currsettings->{'selfenroll_approval'};
6241: }
6242: if ($currapproval !~ /^[012]$/) {
6243: $currapproval = 0;
6244: }
1.400 raeburn 6245: if ($noedit{$item}) {
6246: $output .= $selfdescs{'approval'}{$currapproval}.
6247: '<br />'.&mt('(Set by Domain Coordinator)');
6248: next;
6249: }
1.398 raeburn 6250: $appchecked{$currapproval} = ' checked="checked"';
6251: for my $i (0..2) {
6252: $output .= '<label>'.
6253: '<input type="radio" name="selfenroll_approval" value="'.$i.'"'.
1.406.2.6 raeburn 6254: $appchecked{$i}.' onclick="toggleNotify();"'.$disabled.' />'.
6255: $selfdescs{'approval'}{$i}.'</label>'.(' 'x2);
1.276 raeburn 6256: }
6257: my %advhash = &Apache::lonnet::get_course_adv_roles($cid,1);
6258: my (@ccs,%notified);
1.322 raeburn 6259: my $ccrole = 'cc';
6260: if ($crstype eq 'Community') {
6261: $ccrole = 'co';
6262: }
6263: if ($advhash{$ccrole}) {
6264: @ccs = split(/,/,$advhash{$ccrole});
1.276 raeburn 6265: }
6266: if ($currnotified) {
6267: foreach my $current (split(/,/,$currnotified)) {
6268: $notified{$current} = 1;
6269: if (!grep(/^\Q$current\E$/,@ccs)) {
6270: push(@ccs,$current);
6271: }
6272: }
6273: }
6274: if (@ccs) {
1.398 raeburn 6275: my $style;
6276: unless ($currapproval) {
6277: $style = ' style="display: none;"';
6278: }
6279: $output .= '<br /><div id="notified"'.$style.'>'.
6280: &mt('Personnel to be notified when an enrollment request needs approval, or has been approved:').' '.
6281: &Apache::loncommon::start_data_table().
1.276 raeburn 6282: &Apache::loncommon::start_data_table_row();
6283: my $count = 0;
6284: my $numcols = 4;
6285: foreach my $cc (sort(@ccs)) {
6286: my $notifyon;
6287: my ($ccuname,$ccudom) = split(/:/,$cc);
6288: if ($notified{$cc}) {
6289: $notifyon = ' checked="checked" ';
6290: }
6291: if ($count && !$count%$numcols) {
6292: $output .= &Apache::loncommon::end_data_table_row().
6293: &Apache::loncommon::start_data_table_row()
6294: }
6295: $output .= '<td><span class="LC_nobreak"><label>'.
1.406.2.6 raeburn 6296: '<input type="checkbox" name="selfenroll_notify"'.$notifyon.' value="'.$cc.'"'.$disabled.' />'.
1.276 raeburn 6297: &Apache::loncommon::plainname($ccuname,$ccudom).
6298: '</label></span></td>';
1.343 raeburn 6299: $count ++;
1.276 raeburn 6300: }
6301: my $rem = $count%$numcols;
6302: if ($rem) {
6303: my $emptycols = $numcols - $rem;
6304: for (my $i=0; $i<$emptycols; $i++) {
6305: $output .= '<td> </td>';
6306: }
6307: }
6308: $output .= &Apache::loncommon::end_data_table_row().
1.398 raeburn 6309: &Apache::loncommon::end_data_table().
6310: '</div>';
1.276 raeburn 6311: }
6312: } elsif ($item eq 'limit') {
1.398 raeburn 6313: my ($crslimit,$selflimit,$nolimit,$currlim,$currcap);
6314: if (ref($currsettings) eq 'HASH') {
6315: $currlim = $currsettings->{'selfenroll_limit'};
6316: $currcap = $currsettings->{'selfenroll_cap'};
6317: }
1.400 raeburn 6318: if ($noedit{$item}) {
6319: if (($currlim eq 'allstudents') || ($currlim eq 'selfenrolled')) {
6320: if ($currlim eq 'allstudents') {
6321: $output .= &mt('Limit by total students');
6322: } elsif ($currlim eq 'selfenrolled') {
6323: $output .= &mt('Limit by total self-enrolled students');
6324: }
6325: $output .= ' '.&mt('Maximum: [_1]',$currcap).
6326: '<br />'.&mt('(Set by Domain Coordinator)');
6327: } else {
6328: $output .= &mt('No limit').'<br />'.&mt('(Set by Domain Coordinator)');
6329: }
6330: next;
6331: }
1.276 raeburn 6332: if ($currlim eq 'allstudents') {
6333: $crslimit = ' checked="checked" ';
6334: $selflimit = ' ';
6335: $nolimit = ' ';
6336: } elsif ($currlim eq 'selfenrolled') {
6337: $crslimit = ' ';
6338: $selflimit = ' checked="checked" ';
6339: $nolimit = ' ';
6340: } else {
6341: $crslimit = ' ';
6342: $selflimit = ' ';
1.398 raeburn 6343: $nolimit = ' checked="checked" ';
1.276 raeburn 6344: }
6345: $output .= '<table><tr><td><label>'.
1.406.2.6 raeburn 6346: '<input type="radio" name="selfenroll_limit" value="none"'.$nolimit.$disabled.'/>'.
1.276 raeburn 6347: &mt('No limit').'</label></td><td><label>'.
1.406.2.6 raeburn 6348: '<input type="radio" name="selfenroll_limit" value="allstudents"'.$crslimit.$disabled.'/>'.
1.276 raeburn 6349: &mt('Limit by total students').'</label></td><td><label>'.
1.406.2.6 raeburn 6350: '<input type="radio" name="selfenroll_limit" value="selfenrolled"'.$selflimit.$disabled.'/>'.
1.276 raeburn 6351: &mt('Limit by total self-enrolled students').
6352: '</td></tr><tr>'.
6353: '<td> </td><td colspan="2"><span class="LC_nobreak">'.
6354: (' 'x3).&mt('Maximum number allowed: ').
1.406.2.6 raeburn 6355: '<input type="text" name="selfenroll_cap" size = "5" value="'.$currcap.'"'.$disabled.' /></td></tr></table>';
1.237 raeburn 6356: }
6357: $output .= &Apache::lonhtmlcommon::row_closure(1);
6358: }
6359: }
1.406.2.6 raeburn 6360: $output .= &Apache::lonhtmlcommon::end_pick_box().'<br />';
6361: unless ($readonly) {
6362: $output .= '<input type="button" name="selfenrollconf" value="'
6363: .&mt('Save').'" onclick="validate_types(this.form);" />';
6364: }
6365: $output .= '<input type="hidden" name="action" value="selfenroll" />'
1.406.2.11 raeburn 6366: .'<input type="hidden" name="state" value="done" />'."\n"
6367: .$additional.'</form>';
1.237 raeburn 6368: $r->print($output);
6369: return;
6370: }
6371:
1.400 raeburn 6372: sub get_noedit_fields {
6373: my ($cdom,$cnum,$crstype,$row) = @_;
6374: my %noedit;
6375: if (ref($row) eq 'ARRAY') {
6376: my %settings = &Apache::lonnet::get('environment',['internal.coursecode','internal.textbook',
6377: 'internal.selfenrollmgrdc',
6378: 'internal.selfenrollmgrcc'],$cdom,$cnum);
6379: my $type = &Apache::lonuserutils::get_extended_type($cdom,$cnum,$crstype,\%settings);
6380: my (%specific_managebydc,%specific_managebycc,%default_managebydc);
6381: map { $specific_managebydc{$_} = 1; } (split(/,/,$settings{'internal.selfenrollmgrdc'}));
6382: map { $specific_managebycc{$_} = 1; } (split(/,/,$settings{'internal.selfenrollmgrcc'}));
6383: my %domdefaults = &Apache::lonnet::get_domain_defaults($cdom);
6384: map { $default_managebydc{$_} = 1; } (split(/,/,$domdefaults{$type.'selfenrolladmdc'}));
6385:
6386: foreach my $item (@{$row}) {
6387: next if ($specific_managebycc{$item});
6388: if (($specific_managebydc{$item}) || ($default_managebydc{$item})) {
6389: $noedit{$item} = 1;
6390: }
6391: }
6392: }
6393: return %noedit;
6394: }
6395:
6396: sub visible_in_stdcat {
6397: my ($cdom,$cnum,$domconf) = @_;
6398: my ($cathash,%settable,@vismsgs,$cansetvis,$visible);
6399: unless (ref($domconf) eq 'HASH') {
6400: return ($visible,$cansetvis,\@vismsgs);
6401: }
6402: if (ref($domconf->{'coursecategories'}) eq 'HASH') {
6403: if ($domconf->{'coursecategories'}{'togglecats'} eq 'crs') {
1.256 raeburn 6404: $settable{'togglecats'} = 1;
6405: }
1.400 raeburn 6406: if ($domconf->{'coursecategories'}{'categorize'} eq 'crs') {
1.256 raeburn 6407: $settable{'categorize'} = 1;
6408: }
1.400 raeburn 6409: $cathash = $domconf->{'coursecategories'}{'cats'};
1.256 raeburn 6410: }
1.260 raeburn 6411: if ($settable{'togglecats'} && $settable{'categorize'}) {
1.256 raeburn 6412: $cansetvis = &mt('You are able to both assign a course category and choose to exclude this course from the catalog.');
6413: } elsif ($settable{'togglecats'}) {
6414: $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 6415: } elsif ($settable{'categorize'}) {
1.256 raeburn 6416: $cansetvis = &mt('You may assign a course category, but only a Domain Coordinator may choose to exclude this course from the catalog.');
6417: } else {
6418: $cansetvis = &mt('Only a Domain Coordinator may assign a course category or choose to exclude this course from the catalog.');
6419: }
6420:
6421: my %currsettings =
6422: &Apache::lonnet::get('environment',['hidefromcat','categories','internal.coursecode'],
6423: $cdom,$cnum);
1.400 raeburn 6424: $visible = 0;
1.256 raeburn 6425: if ($currsettings{'internal.coursecode'} ne '') {
1.400 raeburn 6426: if (ref($domconf->{'coursecategories'}) eq 'HASH') {
6427: $cathash = $domconf->{'coursecategories'}{'cats'};
1.256 raeburn 6428: if (ref($cathash) eq 'HASH') {
6429: if ($cathash->{'instcode::0'} eq '') {
6430: push(@vismsgs,'dc_addinst');
6431: } else {
6432: $visible = 1;
6433: }
6434: } else {
6435: $visible = 1;
6436: }
6437: } else {
6438: $visible = 1;
6439: }
6440: } else {
6441: if (ref($cathash) eq 'HASH') {
6442: if ($cathash->{'instcode::0'} ne '') {
6443: push(@vismsgs,'dc_instcode');
6444: }
6445: } else {
6446: push(@vismsgs,'dc_instcode');
6447: }
6448: }
6449: if ($currsettings{'categories'} ne '') {
6450: my $cathash;
1.400 raeburn 6451: if (ref($domconf->{'coursecategories'}) eq 'HASH') {
6452: $cathash = $domconf->{'coursecategories'}{'cats'};
1.256 raeburn 6453: if (ref($cathash) eq 'HASH') {
6454: if (keys(%{$cathash}) == 0) {
6455: push(@vismsgs,'dc_catalog');
6456: } elsif ((keys(%{$cathash}) == 1) && ($cathash->{'instcode::0'} ne '')) {
6457: push(@vismsgs,'dc_categories');
6458: } else {
6459: my @currcategories = split('&',$currsettings{'categories'});
6460: my $matched = 0;
6461: foreach my $cat (@currcategories) {
6462: if ($cathash->{$cat} ne '') {
6463: $visible = 1;
6464: $matched = 1;
6465: last;
6466: }
6467: }
6468: if (!$matched) {
1.260 raeburn 6469: if ($settable{'categorize'}) {
1.256 raeburn 6470: push(@vismsgs,'chgcat');
6471: } else {
6472: push(@vismsgs,'dc_chgcat');
6473: }
6474: }
6475: }
6476: }
6477: }
6478: } else {
6479: if (ref($cathash) eq 'HASH') {
6480: if ((keys(%{$cathash}) > 1) ||
6481: (keys(%{$cathash}) == 1) && ($cathash->{'instcode::0'} eq '')) {
1.260 raeburn 6482: if ($settable{'categorize'}) {
1.256 raeburn 6483: push(@vismsgs,'addcat');
6484: } else {
6485: push(@vismsgs,'dc_addcat');
6486: }
6487: }
6488: }
6489: }
6490: if ($currsettings{'hidefromcat'} eq 'yes') {
6491: $visible = 0;
6492: if ($settable{'togglecats'}) {
6493: unshift(@vismsgs,'unhide');
6494: } else {
6495: unshift(@vismsgs,'dc_unhide')
6496: }
6497: }
1.400 raeburn 6498: return ($visible,$cansetvis,\@vismsgs);
6499: }
6500:
6501: sub cat_visibility {
6502: my %visactions = &Apache::lonlocal::texthash(
6503: vis => 'This course/community currently appears in the Course/Community Catalog for this domain.',
6504: 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.',
6505: miss => 'This course/community does not currently appear in the Course/Community Catalog for this domain.',
6506: none => 'Display of a course catalog is disabled for this domain.',
6507: yous => 'You should remedy this if you plan to allow self-enrollment, otherwise students will have difficulty finding this course.',
6508: 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.',
6509: make => 'Make any changes to self-enrollment settings below, click "Save", then take action to include the course in the Catalog:',
6510: take => 'Take the following action to ensure the course appears in the Catalog:',
6511: dc_chgconf => 'Ask a domain coordinator to change the Catalog type for this domain.',
6512: dc_setcode => 'Ask a domain coordinator to assign a six character code to the course',
6513: dc_unhide => 'Ask a domain coordinator to change the "Exclude from course catalog" setting.',
6514: dc_addinst => 'Ask a domain coordinator to enable display the catalog of "Official courses (with institutional codes)".',
6515: dc_instcode => 'Ask a domain coordinator to assign an institutional code (if this is an official course).',
6516: dc_catalog => 'Ask a domain coordinator to enable or create at least one course category in the domain.',
6517: dc_categories => 'Ask a domain coordinator to create a hierarchy of categories and sub categories for courses in the domain.',
6518: 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',
6519: dc_addcat => 'Ask a domain coordinator to assign a category to the course.',
6520: );
6521: $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>"');
6522: $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>"');
6523: $visactions{'addcat'} = &mt('Use [_1]Categorize course[_2] to assign a category to the course.','"<a href="/adm/courseprefs?phase=display&actions=courseinfo">','</a>"');
6524: return \%visactions;
1.256 raeburn 6525: }
6526:
1.241 raeburn 6527: sub new_selfenroll_dom_row {
6528: my ($newdom,$num) = @_;
6529: my $domdesc = &Apache::lonnet::domain($newdom);
6530: my $output;
6531: if ($domdesc ne '') {
6532: $output .= &Apache::loncommon::start_data_table_row()
6533: .'<td valign="top"><span class="LC_nobreak">'.&mt('Domain:').' <b>'.$domdesc
6534: .' ('.$newdom.')</b><input type="hidden" name="selfenroll_dom_'.$num
1.249 raeburn 6535: .'" value="'.$newdom.'" /></span><br />'
6536: .'<span class="LC_nobreak"><label><input type="checkbox" '
6537: .'name="selfenroll_activate" value="'.$num.'" '
6538: .'onchange="javascript:update_types('
6539: ."'selfenroll_activate','$num'".');" />'
6540: .&mt('Activate').'</label></span></td>';
1.241 raeburn 6541: my @currinsttypes;
6542: $output .= '<td>'.&mt('User types:').'<br />'
6543: .&selfenroll_inst_types($num,$newdom,\@currinsttypes).'</td>'
6544: .&Apache::loncommon::end_data_table_row();
6545: }
6546: return $output;
6547: }
6548:
6549: sub selfenroll_inst_types {
1.406.2.6 raeburn 6550: my ($num,$currdom,$currinsttypes,$readonly) = @_;
1.241 raeburn 6551: my $output;
6552: my $numinrow = 4;
6553: my $count = 0;
6554: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($currdom);
1.247 raeburn 6555: my $othervalue = 'any';
1.406.2.6 raeburn 6556: my $disabled;
6557: if ($readonly) {
6558: $disabled = ' disabled="disabled"';
6559: }
1.241 raeburn 6560: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
1.251 raeburn 6561: if (keys(%{$usertypes}) > 0) {
1.247 raeburn 6562: $othervalue = 'other';
6563: }
1.241 raeburn 6564: $output .= '<table><tr>';
6565: foreach my $type (@{$types}) {
6566: if (($count > 0) && ($count%$numinrow == 0)) {
6567: $output .= '</tr><tr>';
6568: }
6569: if (defined($usertypes->{$type})) {
1.257 raeburn 6570: my $esc_type = &escape($type);
1.241 raeburn 6571: $output .= '<td><span class="LC_nobreak"><label><input type = "checkbox" value="'.
1.257 raeburn 6572: $esc_type.'" ';
1.241 raeburn 6573: if (ref($currinsttypes) eq 'ARRAY') {
6574: if (@{$currinsttypes} > 0) {
1.249 raeburn 6575: if (grep(/^any$/,@{$currinsttypes})) {
6576: $output .= 'checked="checked"';
1.257 raeburn 6577: } elsif (grep(/^\Q$esc_type\E$/,@{$currinsttypes})) {
1.241 raeburn 6578: $output .= 'checked="checked"';
6579: }
1.249 raeburn 6580: } else {
6581: $output .= 'checked="checked"';
1.241 raeburn 6582: }
6583: }
1.406.2.6 raeburn 6584: $output .= ' name="selfenroll_types_'.$num.'"'.$disabled.' />'.$usertypes->{$type}.'</label></span></td>';
1.241 raeburn 6585: }
6586: $count ++;
6587: }
6588: if (($count > 0) && ($count%$numinrow == 0)) {
6589: $output .= '</tr><tr>';
6590: }
1.249 raeburn 6591: $output .= '<td><span class="LC_nobreak"><label><input type = "checkbox" value="'.$othervalue.'"';
1.241 raeburn 6592: if (ref($currinsttypes) eq 'ARRAY') {
6593: if (@{$currinsttypes} > 0) {
1.249 raeburn 6594: if (grep(/^any$/,@{$currinsttypes})) {
6595: $output .= ' checked="checked"';
6596: } elsif ($othervalue eq 'other') {
6597: if (grep(/^\Q$othervalue\E$/,@{$currinsttypes})) {
6598: $output .= ' checked="checked"';
6599: }
1.241 raeburn 6600: }
1.249 raeburn 6601: } else {
6602: $output .= ' checked="checked"';
1.241 raeburn 6603: }
1.249 raeburn 6604: } else {
6605: $output .= ' checked="checked"';
1.241 raeburn 6606: }
1.406.2.6 raeburn 6607: $output .= ' name="selfenroll_types_'.$num.'"'.$disabled.' />'.$othertitle.'</label></span></td></tr></table>';
1.241 raeburn 6608: }
6609: return $output;
6610: }
6611:
1.237 raeburn 6612: sub selfenroll_date_forms {
6613: my ($startform,$endform) = @_;
6614: my $output .= &Apache::lonhtmlcommon::start_pick_box()."\n".
1.244 bisitz 6615: &Apache::lonhtmlcommon::row_title(&mt('Start date'),
1.237 raeburn 6616: 'LC_oddrow_value')."\n".
6617: $startform."\n".
6618: &Apache::lonhtmlcommon::row_closure(1).
1.244 bisitz 6619: &Apache::lonhtmlcommon::row_title(&mt('End date'),
1.237 raeburn 6620: 'LC_oddrow_value')."\n".
6621: $endform."\n".
6622: &Apache::lonhtmlcommon::row_closure(1).
6623: &Apache::lonhtmlcommon::end_pick_box();
6624: return $output;
6625: }
6626:
1.239 raeburn 6627: sub print_userchangelogs_display {
1.406.2.5 raeburn 6628: my ($r,$context,$permission,$brcrum) = @_;
1.363 raeburn 6629: my $formname = 'rolelog';
1.406.2.6 raeburn 6630: my ($username,$domain,$crstype,$viewablesec,%roleslog);
1.363 raeburn 6631: if ($context eq 'domain') {
6632: $domain = $env{'request.role.domain'};
6633: %roleslog=&Apache::lonnet::dump_dom('nohist_rolelog',$domain);
6634: } else {
6635: if ($context eq 'course') {
6636: $domain = $env{'course.'.$env{'request.course.id'}.'.domain'};
6637: $username = $env{'course.'.$env{'request.course.id'}.'.num'};
6638: $crstype = &Apache::loncommon::course_type();
1.406.2.6 raeburn 6639: $viewablesec = &Apache::lonuserutils::viewable_section($permission);
1.363 raeburn 6640: my %saveable_parameters = ('show' => 'scalar',);
6641: &Apache::loncommon::store_course_settings('roles_log',
6642: \%saveable_parameters);
6643: &Apache::loncommon::restore_course_settings('roles_log',
6644: \%saveable_parameters);
6645: } elsif ($context eq 'author') {
6646: $domain = $env{'user.domain'};
6647: if ($env{'request.role'} =~ m{^au\./\Q$domain\E/$}) {
6648: $username = $env{'user.name'};
6649: } else {
6650: undef($domain);
6651: }
6652: }
6653: if ($domain ne '' && $username ne '') {
6654: %roleslog=&Apache::lonnet::dump('nohist_rolelog',$domain,$username);
6655: }
6656: }
1.239 raeburn 6657: if ((keys(%roleslog))[0]=~/^error\:/) { undef(%roleslog); }
6658:
1.406.2.5 raeburn 6659: my $helpitem;
6660: if ($context eq 'course') {
6661: $helpitem = 'Course_User_Logs';
1.406.2.14 raeburn 6662: } elsif ($context eq 'domain') {
6663: $helpitem = 'Domain_Role_Logs';
6664: } elsif ($context eq 'author') {
6665: $helpitem = 'Author_User_Logs';
1.406.2.5 raeburn 6666: }
6667: push (@{$brcrum},
6668: {href => '/adm/createuser?action=changelogs',
6669: text => 'User Management Logs',
6670: help => $helpitem});
6671: my $bread_crumbs_component = 'User Changes';
6672: my $args = { bread_crumbs => $brcrum,
6673: bread_crumbs_component => $bread_crumbs_component};
6674:
6675: # Create navigation javascript
6676: my $jsnav = &userlogdisplay_js($formname);
6677:
6678: my $jscript = (<<ENDSCRIPT);
6679: <script type="text/javascript">
6680: // <![CDATA[
6681: $jsnav
6682: // ]]>
6683: </script>
6684: ENDSCRIPT
6685:
6686: # print page header
6687: $r->print(&header($jscript,$args));
6688:
1.239 raeburn 6689: # set defaults
6690: my $now = time();
6691: my $defstart = $now - (7*24*3600); #7 days ago
6692: my %defaults = (
6693: page => '1',
6694: show => '10',
6695: role => 'any',
6696: chgcontext => 'any',
6697: rolelog_start_date => $defstart,
6698: rolelog_end_date => $now,
6699: );
6700: my $more_records = 0;
6701:
6702: # set current
6703: my %curr;
6704: foreach my $item ('show','page','role','chgcontext') {
6705: $curr{$item} = $env{'form.'.$item};
6706: }
6707: my ($startdate,$enddate) =
6708: &Apache::lonuserutils::get_dates_from_form('rolelog_start_date','rolelog_end_date');
6709: $curr{'rolelog_start_date'} = $startdate;
6710: $curr{'rolelog_end_date'} = $enddate;
6711: foreach my $key (keys(%defaults)) {
6712: if ($curr{$key} eq '') {
6713: $curr{$key} = $defaults{$key};
6714: }
6715: }
1.248 raeburn 6716: my (%whodunit,%changed,$version);
6717: ($version) = ($r->dir_config('lonVersion') =~ /^([\d\.]+)\-/);
1.239 raeburn 6718: my ($minshown,$maxshown);
1.255 raeburn 6719: $minshown = 1;
1.239 raeburn 6720: my $count = 0;
1.406.2.5 raeburn 6721: if ($curr{'show'} =~ /\D/) {
6722: $curr{'page'} = 1;
6723: } else {
1.239 raeburn 6724: $maxshown = $curr{'page'} * $curr{'show'};
6725: if ($curr{'page'} > 1) {
6726: $minshown = 1 + ($curr{'page'} - 1) * $curr{'show'};
6727: }
6728: }
1.301 bisitz 6729:
1.327 raeburn 6730: # Form Header
6731: $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">'.
1.363 raeburn 6732: &role_display_filter($context,$formname,$domain,$username,\%curr,
6733: $version,$crstype));
1.327 raeburn 6734:
6735: my $showntableheader = 0;
6736:
6737: # Table Header
6738: my $tableheader =
6739: &Apache::loncommon::start_data_table_header_row()
6740: .'<th> </th>'
6741: .'<th>'.&mt('When').'</th>'
6742: .'<th>'.&mt('Who made the change').'</th>'
6743: .'<th>'.&mt('Changed User').'</th>'
1.363 raeburn 6744: .'<th>'.&mt('Role').'</th>';
6745:
6746: if ($context eq 'course') {
6747: $tableheader .= '<th>'.&mt('Section').'</th>';
6748: }
6749: $tableheader .=
6750: '<th>'.&mt('Context').'</th>'
1.327 raeburn 6751: .'<th>'.&mt('Start').'</th>'
6752: .'<th>'.&mt('End').'</th>'
6753: .&Apache::loncommon::end_data_table_header_row();
6754:
6755: # Display user change log data
1.239 raeburn 6756: foreach my $id (sort { $roleslog{$b}{'exe_time'}<=>$roleslog{$a}{'exe_time'} } (keys(%roleslog))) {
6757: next if (($roleslog{$id}{'exe_time'} < $curr{'rolelog_start_date'}) ||
6758: ($roleslog{$id}{'exe_time'} > $curr{'rolelog_end_date'}));
1.406.2.5 raeburn 6759: if ($curr{'show'} !~ /\D/) {
1.239 raeburn 6760: if ($count >= $curr{'page'} * $curr{'show'}) {
6761: $more_records = 1;
6762: last;
6763: }
6764: }
6765: if ($curr{'role'} ne 'any') {
6766: next if ($roleslog{$id}{'logentry'}{'role'} ne $curr{'role'});
6767: }
6768: if ($curr{'chgcontext'} ne 'any') {
6769: if ($curr{'chgcontext'} eq 'selfenroll') {
6770: next if (!$roleslog{$id}{'logentry'}{'selfenroll'});
6771: } else {
6772: next if ($roleslog{$id}{'logentry'}{'context'} ne $curr{'chgcontext'});
6773: }
6774: }
1.406.2.6 raeburn 6775: if (($context eq 'course') && ($viewablesec ne '')) {
6776: next if ($roleslog{$id}{'logentry'}{'section'} ne $viewablesec);
6777: }
1.239 raeburn 6778: $count ++;
6779: next if ($count < $minshown);
1.327 raeburn 6780: unless ($showntableheader) {
1.406.2.5 raeburn 6781: $r->print(&Apache::loncommon::start_data_table()
1.327 raeburn 6782: .$tableheader);
6783: $r->rflush();
6784: $showntableheader = 1;
6785: }
1.239 raeburn 6786: if ($whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}} eq '') {
6787: $whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}} =
6788: &Apache::loncommon::plainname($roleslog{$id}{'exe_uname'},$roleslog{$id}{'exe_udom'});
6789: }
6790: if ($changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}} eq '') {
6791: $changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}} =
6792: &Apache::loncommon::plainname($roleslog{$id}{'uname'},$roleslog{$id}{'udom'});
6793: }
6794: my $sec = $roleslog{$id}{'logentry'}{'section'};
6795: if ($sec eq '') {
6796: $sec = &mt('None');
6797: }
6798: my ($rolestart,$roleend);
6799: if ($roleslog{$id}{'delflag'}) {
6800: $rolestart = &mt('deleted');
6801: $roleend = &mt('deleted');
6802: } else {
6803: $rolestart = $roleslog{$id}{'logentry'}{'start'};
6804: $roleend = $roleslog{$id}{'logentry'}{'end'};
6805: if ($rolestart eq '' || $rolestart == 0) {
6806: $rolestart = &mt('No start date');
6807: } else {
6808: $rolestart = &Apache::lonlocal::locallocaltime($rolestart);
6809: }
6810: if ($roleend eq '' || $roleend == 0) {
6811: $roleend = &mt('No end date');
6812: } else {
6813: $roleend = &Apache::lonlocal::locallocaltime($roleend);
6814: }
6815: }
6816: my $chgcontext = $roleslog{$id}{'logentry'}{'context'};
6817: if ($roleslog{$id}{'logentry'}{'selfenroll'}) {
6818: $chgcontext = 'selfenroll';
6819: }
1.363 raeburn 6820: my %lt = &rolechg_contexts($context,$crstype);
1.239 raeburn 6821: if ($chgcontext ne '' && $lt{$chgcontext} ne '') {
6822: $chgcontext = $lt{$chgcontext};
6823: }
1.327 raeburn 6824: $r->print(
1.301 bisitz 6825: &Apache::loncommon::start_data_table_row()
6826: .'<td>'.$count.'</td>'
6827: .'<td>'.&Apache::lonlocal::locallocaltime($roleslog{$id}{'exe_time'}).'</td>'
6828: .'<td>'.$whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}}.'</td>'
6829: .'<td>'.$changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}}.'</td>'
1.363 raeburn 6830: .'<td>'.&Apache::lonnet::plaintext($roleslog{$id}{'logentry'}{'role'},$crstype).'</td>');
6831: if ($context eq 'course') {
6832: $r->print('<td>'.$sec.'</td>');
6833: }
6834: $r->print(
6835: '<td>'.$chgcontext.'</td>'
1.301 bisitz 6836: .'<td>'.$rolestart.'</td>'
6837: .'<td>'.$roleend.'</td>'
1.327 raeburn 6838: .&Apache::loncommon::end_data_table_row()."\n");
1.301 bisitz 6839: }
6840:
1.327 raeburn 6841: if ($showntableheader) { # Table footer, if content displayed above
1.406.2.5 raeburn 6842: $r->print(&Apache::loncommon::end_data_table().
6843: &userlogdisplay_navlinks(\%curr,$more_records));
1.327 raeburn 6844: } else { # No content displayed above
1.301 bisitz 6845: $r->print('<p class="LC_info">'
6846: .&mt('There are no records to display.')
6847: .'</p>'
6848: );
1.239 raeburn 6849: }
1.301 bisitz 6850:
1.327 raeburn 6851: # Form Footer
6852: $r->print(
6853: '<input type="hidden" name="page" value="'.$curr{'page'}.'" />'
6854: .'<input type="hidden" name="action" value="changelogs" />'
6855: .'</form>');
6856: return;
6857: }
1.301 bisitz 6858:
1.406.2.5 raeburn 6859: sub print_useraccesslogs_display {
6860: my ($r,$uname,$udom,$permission,$brcrum) = @_;
6861: my $formname = 'accesslog';
6862: my $form = 'document.accesslog';
6863:
6864: # set breadcrumbs
1.406.2.7 raeburn 6865: my %breadcrumb_text = &singleuser_breadcrumb('','domain',$udom);
1.406.2.12 raeburn 6866: my $prevphasestr;
6867: if ($env{'form.popup'}) {
6868: $brcrum = [];
6869: } else {
6870: push (@{$brcrum},
6871: {href => "javascript:backPage($form)",
6872: text => $breadcrumb_text{'search'}});
6873: my @prevphases;
6874: if ($env{'form.prevphases'}) {
6875: @prevphases = split(/,/,$env{'form.prevphases'});
6876: $prevphasestr = $env{'form.prevphases'};
6877: }
6878: if (($env{'form.phase'} eq 'userpicked') || (grep(/^userpicked$/,@prevphases))) {
6879: push(@{$brcrum},
6880: {href => "javascript:backPage($form,'get_user_info','select')",
6881: text => $breadcrumb_text{'userpicked'}});
6882: if ($env{'form.phase'} eq 'userpicked') {
6883: $prevphasestr = 'userpicked';
6884: }
1.406.2.5 raeburn 6885: }
6886: }
6887: push(@{$brcrum},
6888: {href => '/adm/createuser?action=accesslogs',
6889: text => 'User access logs',
1.406.2.8 raeburn 6890: help => 'Domain_User_Access_Logs'});
1.406.2.5 raeburn 6891: my $bread_crumbs_component = 'User Access Logs';
6892: my $args = { bread_crumbs => $brcrum,
6893: bread_crumbs_component => 'User Management'};
1.406.2.8 raeburn 6894: if ($env{'form.popup'}) {
6895: $args->{'no_nav_bar'} = 1;
1.406.2.12 raeburn 6896: $args->{'bread_crumbs_nomenu'} = 1;
1.406.2.8 raeburn 6897: }
1.406.2.5 raeburn 6898:
6899: # set javascript
6900: my ($jsback,$elements) = &crumb_utilities();
6901: my $jsnav = &userlogdisplay_js($formname);
6902:
6903: my $jscript = (<<ENDSCRIPT);
1.239 raeburn 6904: <script type="text/javascript">
1.301 bisitz 6905: // <![CDATA[
1.406.2.5 raeburn 6906:
6907: $jsback
6908: $jsnav
6909:
6910: // ]]>
6911: </script>
6912:
6913: ENDSCRIPT
6914:
6915: # print page header
6916: $r->print(&header($jscript,$args));
6917:
6918: # early out unless log data can be displayed.
6919: unless ($permission->{'activity'}) {
6920: $r->print('<p class="LC_warning">'
6921: .&mt('You do not have rights to display user access logs.')
1.406.2.12 raeburn 6922: .'</p>');
6923: if ($env{'form.popup'}) {
6924: $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a></p>');
6925: } else {
6926: $r->print(&earlyout_accesslog_form($formname,$prevphasestr,$udom));
6927: }
1.406.2.5 raeburn 6928: return;
6929: }
6930:
6931: unless ($udom eq $env{'request.role.domain'}) {
6932: $r->print('<p class="LC_warning">'
6933: .&mt("User's domain must match role's domain")
6934: .'</p>'
6935: .&earlyout_accesslog_form($formname,$prevphasestr,$udom));
6936: return;
6937: }
6938:
6939: if (($uname eq '') || ($udom eq '')) {
6940: $r->print('<p class="LC_warning">'
6941: .&mt('Invalid username or domain')
6942: .'</p>'
6943: .&earlyout_accesslog_form($formname,$prevphasestr,$udom));
6944: return;
6945: }
6946:
1.406.2.13 raeburn 6947: if (&Apache::lonnet::privileged($uname,$udom,
6948: [$env{'request.role.domain'}],['dc','su'])) {
6949: unless (&Apache::lonnet::privileged($env{'user.name'},$env{'user.domain'},
6950: [$env{'request.role.domain'}],['dc','su'])) {
6951: $r->print('<p class="LC_warning">'
6952: .&mt('You need to be a privileged user to display user access logs for [_1]',
6953: &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),
6954: $uname,$udom))
6955: .'</p>');
6956: if ($env{'form.popup'}) {
6957: $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a></p>');
6958: } else {
6959: $r->print(&earlyout_accesslog_form($formname,$prevphasestr,$udom));
6960: }
6961: return;
6962: }
6963: }
6964:
1.406.2.5 raeburn 6965: # set defaults
6966: my $now = time();
6967: my $defstart = $now - (7*24*3600);
6968: my %defaults = (
6969: page => '1',
6970: show => '10',
6971: activity => 'any',
6972: accesslog_start_date => $defstart,
6973: accesslog_end_date => $now,
6974: );
6975: my $more_records = 0;
6976:
6977: # set current
6978: my %curr;
6979: foreach my $item ('show','page','activity') {
6980: $curr{$item} = $env{'form.'.$item};
6981: }
6982: my ($startdate,$enddate) =
6983: &Apache::lonuserutils::get_dates_from_form('accesslog_start_date','accesslog_end_date');
6984: $curr{'accesslog_start_date'} = $startdate;
6985: $curr{'accesslog_end_date'} = $enddate;
6986: foreach my $key (keys(%defaults)) {
6987: if ($curr{$key} eq '') {
6988: $curr{$key} = $defaults{$key};
6989: }
6990: }
6991: my ($minshown,$maxshown);
6992: $minshown = 1;
6993: my $count = 0;
6994: if ($curr{'show'} =~ /\D/) {
6995: $curr{'page'} = 1;
6996: } else {
6997: $maxshown = $curr{'page'} * $curr{'show'};
6998: if ($curr{'page'} > 1) {
6999: $minshown = 1 + ($curr{'page'} - 1) * $curr{'show'};
7000: }
7001: }
7002:
7003: # form header
7004: $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">'.
7005: &activity_display_filter($formname,\%curr));
7006:
7007: my $showntableheader = 0;
7008: my ($nav_script,$nav_links);
7009:
7010: # table header
1.406.2.12 raeburn 7011: my $tableheader = '<h3>'.
7012: &mt('User access logs for: [_1]',
7013: &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),$uname,$udom)).'</h3>'
7014: .&Apache::loncommon::start_data_table_header_row()
1.406.2.5 raeburn 7015: .'<th> </th>'
7016: .'<th>'.&mt('When').'</th>'
7017: .'<th>'.&mt('HostID').'</th>'
7018: .'<th>'.&mt('Event').'</th>'
7019: .'<th>'.&mt('Other data').'</th>'
7020: .&Apache::loncommon::end_data_table_header_row();
7021:
7022: my %filters=(
7023: start => $curr{'accesslog_start_date'},
7024: end => $curr{'accesslog_end_date'},
7025: action => $curr{'activity'},
7026: );
7027:
7028: my $reply = &Apache::lonnet::userlog_query($uname,$udom,%filters);
7029: unless ( ($reply =~/^timeout/) || ($reply =~/^error/) ) {
7030: my (%courses,%missing);
7031: my @results = split(/\&/,$reply);
7032: foreach my $item (reverse(@results)) {
7033: my ($timestamp,$host,$event) = split(/:/,$item);
7034: next unless ($event =~ /^(Log|Role)/);
7035: if ($curr{'show'} !~ /\D/) {
7036: if ($count >= $curr{'page'} * $curr{'show'}) {
7037: $more_records = 1;
7038: last;
7039: }
7040: }
7041: $count ++;
7042: next if ($count < $minshown);
7043: unless ($showntableheader) {
7044: $r->print($nav_script
7045: .&Apache::loncommon::start_data_table()
7046: .$tableheader);
7047: $r->rflush();
7048: $showntableheader = 1;
7049: }
1.406.2.6 raeburn 7050: my ($shown,$extra);
1.406.2.13 raeburn 7051: my ($event,$data) = split(/\s+/,&unescape($event),2);
1.406.2.5 raeburn 7052: if ($event eq 'Role') {
7053: my ($rolecode,$extent) = split(/\./,$data,2);
7054: next if ($extent eq '');
7055: my ($crstype,$desc,$info);
1.406.2.6 raeburn 7056: if ($extent =~ m{^/($match_domain)/($match_courseid)(?:/(\w+)|)$}) {
7057: my ($cdom,$cnum,$sec) = ($1,$2,$3);
1.406.2.5 raeburn 7058: my $cid = $cdom.'_'.$cnum;
7059: if (exists($courses{$cid})) {
7060: $crstype = $courses{$cid}{'type'};
7061: $desc = $courses{$cid}{'description'};
7062: } elsif ($missing{$cid}) {
7063: $crstype = 'Course';
7064: $desc = 'Course/Community';
7065: } else {
7066: my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',$cnum,undef,undef,'.');
7067: if (ref($crsinfo{$cdom.'_'.$cnum}) eq 'HASH') {
7068: $courses{$cid} = $crsinfo{$cid};
7069: $crstype = $crsinfo{$cid}{'type'};
7070: $desc = $crsinfo{$cid}{'description'};
7071: } else {
7072: $missing{$cid} = 1;
7073: }
7074: }
7075: $extra = &mt($crstype).': <a href="/public/'.$cdom.'/'.$cnum.'/syllabus">'.$desc.'</a>';
1.406.2.6 raeburn 7076: if ($sec ne '') {
7077: $extra .= ' ('.&mt('Section: [_1]',$sec).')';
7078: }
1.406.2.5 raeburn 7079: } elsif ($extent =~ m{^/($match_domain)/($match_username|$)}) {
7080: my ($dom,$name) = ($1,$2);
7081: if ($rolecode eq 'au') {
7082: $extra = '';
7083: } elsif ($rolecode =~ /^(ca|aa)$/) {
7084: $extra = &mt('Authoring Space: [_1]',$name.':'.$dom);
7085: } elsif ($rolecode =~ /^(li|dg|dh|dc|sc)$/) {
7086: $extra = &mt('Domain: [_1]',$dom);
7087: }
7088: }
7089: my $rolename;
7090: if ($rolecode =~ m{^cr/($match_domain)/($match_username)/(\w+)}) {
7091: my $role = $3;
7092: my $owner = "($2:$1)";
7093: if ($2 eq $1.'-domainconfig') {
7094: $owner = '(ad hoc)';
7095: }
7096: $rolename = &mt('Custom role: [_1]',$role.' '.$owner);
7097: } else {
7098: $rolename = &Apache::lonnet::plaintext($rolecode,$crstype);
7099: }
7100: $shown = &mt('Role selection: [_1]',$rolename);
7101: } else {
7102: $shown = &mt($event);
1.406.2.13 raeburn 7103: if ($data =~ /^webdav/) {
7104: my ($path,$clientip) = split(/\s+/,$data,2);
7105: $path =~ s/^webdav//;
7106: if ($clientip ne '') {
7107: $extra = &mt('Client IP address: [_1]',$clientip);
7108: }
7109: if ($path ne '') {
7110: $shown .= ' '.&mt('(WebDAV access to [_1])',$path);
7111: }
7112: } elsif ($data ne '') {
7113: $extra = &mt('Client IP address: [_1]',$data);
1.406.2.5 raeburn 7114: }
7115: }
7116: $r->print(
7117: &Apache::loncommon::start_data_table_row()
7118: .'<td>'.$count.'</td>'
7119: .'<td>'.&Apache::lonlocal::locallocaltime($timestamp).'</td>'
7120: .'<td>'.$host.'</td>'
7121: .'<td>'.$shown.'</td>'
7122: .'<td>'.$extra.'</td>'
7123: .&Apache::loncommon::end_data_table_row()."\n");
7124: }
7125: }
7126:
7127: if ($showntableheader) { # Table footer, if content displayed above
7128: $r->print(&Apache::loncommon::end_data_table().
7129: &userlogdisplay_navlinks(\%curr,$more_records));
7130: } else { # No content displayed above
7131: $r->print('<p class="LC_info">'
7132: .&mt('There are no records to display.')
7133: .'</p>');
7134: }
7135:
1.406.2.8 raeburn 7136: if ($env{'form.popup'} == 1) {
7137: $r->print('<input type="hidden" name="popup" value="1" />'."\n");
7138: }
7139:
1.406.2.5 raeburn 7140: # Form Footer
7141: $r->print(
7142: '<input type="hidden" name="currstate" value="" />'
7143: .'<input type="hidden" name="accessuname" value="'.$uname.'" />'
7144: .'<input type="hidden" name="accessudom" value="'.$udom.'" />'
7145: .'<input type="hidden" name="page" value="'.$curr{'page'}.'" />'
7146: .'<input type="hidden" name="prevphases" value="'.$prevphasestr.'" />'
7147: .'<input type="hidden" name="phase" value="activity" />'
7148: .'<input type="hidden" name="action" value="accesslogs" />'
7149: .'<input type="hidden" name="srchdomain" value="'.$udom.'" />'
7150: .'<input type="hidden" name="srchby" value="'.$env{'form.srchby'}.'" />'
7151: .'<input type="hidden" name="srchtype" value="'.$env{'form.srchtype'}.'" />'
7152: .'<input type="hidden" name="srchterm" value="'.&HTML::Entities::encode($env{'form.srchterm'},'<>"&').'" />'
7153: .'<input type="hidden" name="srchin" value="'.$env{'form.srchin'}.'" />'
7154: .'</form>');
7155: return;
7156: }
7157:
7158: sub earlyout_accesslog_form {
7159: my ($formname,$prevphasestr,$udom) = @_;
7160: my $srchterm = &HTML::Entities::encode($env{'form.srchterm'},'<>"&');
7161: return <<"END";
7162: <form action="/adm/createuser" method="post" name="$formname">
7163: <input type="hidden" name="currstate" value="" />
7164: <input type="hidden" name="prevphases" value="$prevphasestr" />
7165: <input type="hidden" name="phase" value="activity" />
7166: <input type="hidden" name="action" value="accesslogs" />
7167: <input type="hidden" name="srchdomain" value="$udom" />
7168: <input type="hidden" name="srchby" value="$env{'form.srchby'}" />
7169: <input type="hidden" name="srchtype" value="$env{'form.srchtype'}" />
7170: <input type="hidden" name="srchterm" value="$srchterm" />
7171: <input type="hidden" name="srchin" value="$env{'form.srchin'}" />
7172: </form>
7173: END
7174: }
7175:
7176: sub activity_display_filter {
7177: my ($formname,$curr) = @_;
7178: my $nolink = 1;
7179: my $output = '<table><tr><td valign="top">'.
7180: '<span class="LC_nobreak"><b>'.&mt('Actions/page:').'</b></span><br />'.
7181: &Apache::lonmeta::selectbox('show',$curr->{'show'},undef,
7182: (&mt('all'),5,10,20,50,100,1000,10000)).
7183: '</td><td> </td>';
7184: my $startform =
7185: &Apache::lonhtmlcommon::date_setter($formname,'accesslog_start_date',
7186: $curr->{'accesslog_start_date'},undef,
7187: undef,undef,undef,undef,undef,undef,$nolink);
7188: my $endform =
7189: &Apache::lonhtmlcommon::date_setter($formname,'accesslog_end_date',
7190: $curr->{'accesslog_end_date'},undef,
7191: undef,undef,undef,undef,undef,undef,$nolink);
7192: my %lt = &Apache::lonlocal::texthash (
7193: activity => 'Activity',
7194: Role => 'Role selection',
7195: log => 'Log-in or Logout',
7196: );
7197: $output .= '<td valign="top"><b>'.&mt('Window during which actions occurred:').'</b><br />'.
7198: '<table><tr><td>'.&mt('After:').
7199: '</td><td>'.$startform.'</td></tr>'.
7200: '<tr><td>'.&mt('Before:').'</td>'.
7201: '<td>'.$endform.'</td></tr></table>'.
7202: '</td>'.
7203: '<td> </td>'.
7204: '<td valign="top"><b>'.&mt('Activities').'</b><br />'.
7205: '<select name="activity"><option value="any"';
7206: if ($curr->{'activity'} eq 'any') {
7207: $output .= ' selected="selected"';
7208: }
7209: $output .= '>'.&mt('Any').'</option>'."\n";
7210: foreach my $activity ('Role','log') {
7211: my $selstr = '';
7212: if ($activity eq $curr->{'activity'}) {
7213: $selstr = ' selected="selected"';
7214: }
7215: $output .= '<option value="'.$activity.'"'.$selstr.'>'.$lt{$activity}.'</option>';
7216: }
7217: $output .= '</select></td>'.
7218: '</tr></table>';
7219: # Update Display button
7220: $output .= '<p>'
7221: .'<input type="submit" value="'.&mt('Update Display').'" />'
1.406.2.12 raeburn 7222: .'</p><hr />';
1.406.2.5 raeburn 7223: return $output;
7224: }
7225:
7226: sub userlogdisplay_js {
7227: my ($formname) = @_;
7228: return <<"ENDSCRIPT";
7229:
1.239 raeburn 7230: function chgPage(caller) {
7231: if (caller == 'previous') {
7232: document.$formname.page.value --;
7233: }
7234: if (caller == 'next') {
7235: document.$formname.page.value ++;
7236: }
1.327 raeburn 7237: document.$formname.submit();
1.239 raeburn 7238: return;
7239: }
7240: ENDSCRIPT
1.406.2.5 raeburn 7241: }
7242:
7243: sub userlogdisplay_navlinks {
7244: my ($curr,$more_records) = @_;
7245: return unless(ref($curr) eq 'HASH');
7246: # Navigation Buttons
7247: my $nav_links = '<p>';
7248: if (($curr->{'page'} > 1) || ($more_records)) {
7249: if (($curr->{'page'} > 1) && ($curr->{'show'} !~ /\D/)) {
7250: $nav_links .= '<input type="button"'
7251: .' onclick="javascript:chgPage('."'previous'".');"'
7252: .' value="'.&mt('Previous [_1] changes',$curr->{'show'})
7253: .'" /> ';
7254: }
7255: if ($more_records) {
7256: $nav_links .= '<input type="button"'
7257: .' onclick="javascript:chgPage('."'next'".');"'
7258: .' value="'.&mt('Next [_1] changes',$curr->{'show'})
7259: .'" />';
1.301 bisitz 7260: }
7261: }
1.406.2.5 raeburn 7262: $nav_links .= '</p>';
7263: return $nav_links;
1.239 raeburn 7264: }
7265:
7266: sub role_display_filter {
1.363 raeburn 7267: my ($context,$formname,$cdom,$cnum,$curr,$version,$crstype) = @_;
7268: my $lctype;
7269: if ($context eq 'course') {
7270: $lctype = lc($crstype);
7271: }
1.239 raeburn 7272: my $nolink = 1;
7273: my $output = '<table><tr><td valign="top">'.
1.301 bisitz 7274: '<span class="LC_nobreak"><b>'.&mt('Changes/page:').'</b></span><br />'.
1.239 raeburn 7275: &Apache::lonmeta::selectbox('show',$curr->{'show'},undef,
7276: (&mt('all'),5,10,20,50,100,1000,10000)).
7277: '</td><td> </td>';
7278: my $startform =
7279: &Apache::lonhtmlcommon::date_setter($formname,'rolelog_start_date',
7280: $curr->{'rolelog_start_date'},undef,
7281: undef,undef,undef,undef,undef,undef,$nolink);
7282: my $endform =
7283: &Apache::lonhtmlcommon::date_setter($formname,'rolelog_end_date',
7284: $curr->{'rolelog_end_date'},undef,
7285: undef,undef,undef,undef,undef,undef,$nolink);
1.363 raeburn 7286: my %lt = &rolechg_contexts($context,$crstype);
1.301 bisitz 7287: $output .= '<td valign="top"><b>'.&mt('Window during which changes occurred:').'</b><br />'.
7288: '<table><tr><td>'.&mt('After:').
7289: '</td><td>'.$startform.'</td></tr>'.
7290: '<tr><td>'.&mt('Before:').'</td>'.
7291: '<td>'.$endform.'</td></tr></table>'.
7292: '</td>'.
7293: '<td> </td>'.
1.239 raeburn 7294: '<td valign="top"><b>'.&mt('Role:').'</b><br />'.
7295: '<select name="role"><option value="any"';
7296: if ($curr->{'role'} eq 'any') {
7297: $output .= ' selected="selected"';
7298: }
7299: $output .= '>'.&mt('Any').'</option>'."\n";
1.363 raeburn 7300: my @roles = &Apache::lonuserutils::roles_by_context($context,1,$crstype);
1.239 raeburn 7301: foreach my $role (@roles) {
7302: my $plrole;
7303: if ($role eq 'cr') {
7304: $plrole = &mt('Custom Role');
7305: } else {
1.318 raeburn 7306: $plrole=&Apache::lonnet::plaintext($role,$crstype);
1.239 raeburn 7307: }
7308: my $selstr = '';
7309: if ($role eq $curr->{'role'}) {
7310: $selstr = ' selected="selected"';
7311: }
7312: $output .= ' <option value="'.$role.'"'.$selstr.'>'.$plrole.'</option>';
7313: }
1.301 bisitz 7314: $output .= '</select></td>'.
7315: '<td> </td>'.
7316: '<td valign="top"><b>'.
1.239 raeburn 7317: &mt('Context:').'</b><br /><select name="chgcontext">';
1.363 raeburn 7318: my @posscontexts;
7319: if ($context eq 'course') {
1.376 raeburn 7320: @posscontexts = ('any','automated','updatenow','createcourse','course','domain','selfenroll','requestcourses');
1.363 raeburn 7321: } elsif ($context eq 'domain') {
7322: @posscontexts = ('any','domain','requestauthor','domconfig','server');
7323: } else {
7324: @posscontexts = ('any','author','domain');
7325: }
7326: foreach my $chgtype (@posscontexts) {
1.239 raeburn 7327: my $selstr = '';
7328: if ($curr->{'chgcontext'} eq $chgtype) {
1.301 bisitz 7329: $selstr = ' selected="selected"';
1.239 raeburn 7330: }
1.363 raeburn 7331: if ($context eq 'course') {
1.376 raeburn 7332: if (($chgtype eq 'automated') || ($chgtype eq 'updatenow')) {
1.363 raeburn 7333: next if (!&Apache::lonnet::auto_run($cnum,$cdom));
7334: }
1.239 raeburn 7335: }
7336: $output .= '<option value="'.$chgtype.'"'.$selstr.'>'.$lt{$chgtype}.'</option>'."\n";
1.248 raeburn 7337: }
1.303 bisitz 7338: $output .= '</select></td>'
7339: .'</tr></table>';
7340:
7341: # Update Display button
7342: $output .= '<p>'
7343: .'<input type="submit" value="'.&mt('Update Display').'" />'
7344: .'</p>';
7345:
7346: # Server version info
1.363 raeburn 7347: my $needsrev = '2.11.0';
7348: if ($context eq 'course') {
7349: $needsrev = '2.7.0';
7350: }
7351:
1.303 bisitz 7352: $output .= '<p class="LC_info">'
7353: .&mt('Only changes made from servers running LON-CAPA [_1] or later are displayed.'
1.363 raeburn 7354: ,$needsrev);
1.248 raeburn 7355: if ($version) {
1.303 bisitz 7356: $output .= ' '.&mt('This LON-CAPA server is version [_1]',$version);
7357: }
7358: $output .= '</p><hr />';
1.239 raeburn 7359: return $output;
7360: }
7361:
7362: sub rolechg_contexts {
1.363 raeburn 7363: my ($context,$crstype) = @_;
7364: my %lt;
7365: if ($context eq 'course') {
7366: %lt = &Apache::lonlocal::texthash (
1.239 raeburn 7367: any => 'Any',
1.376 raeburn 7368: automated => 'Automated Enrollment',
1.239 raeburn 7369: updatenow => 'Roster Update',
7370: createcourse => 'Course Creation',
7371: course => 'User Management in course',
7372: domain => 'User Management in domain',
1.313 raeburn 7373: selfenroll => 'Self-enrolled',
1.318 raeburn 7374: requestcourses => 'Course Request',
1.239 raeburn 7375: );
1.363 raeburn 7376: if ($crstype eq 'Community') {
7377: $lt{'createcourse'} = &mt('Community Creation');
7378: $lt{'course'} = &mt('User Management in community');
7379: $lt{'requestcourses'} = &mt('Community Request');
7380: }
7381: } elsif ($context eq 'domain') {
7382: %lt = &Apache::lonlocal::texthash (
7383: any => 'Any',
7384: domain => 'User Management in domain',
7385: requestauthor => 'Authoring Request',
7386: server => 'Command line script (DC role)',
7387: domconfig => 'Self-enrolled',
7388: );
7389: } else {
7390: %lt = &Apache::lonlocal::texthash (
7391: any => 'Any',
7392: domain => 'User Management in domain',
7393: author => 'User Management by author',
7394: );
7395: }
1.239 raeburn 7396: return %lt;
7397: }
7398:
1.406.2.10 raeburn 7399: sub print_helpdeskaccess_display {
7400: my ($r,$permission,$brcrum) = @_;
7401: my $formname = 'helpdeskaccess';
7402: my $helpitem = 'Course_Helpdesk_Access';
7403: push (@{$brcrum},
7404: {href => '/adm/createuser?action=helpdesk',
7405: text => 'Helpdesk Access',
7406: help => $helpitem});
7407: my $bread_crumbs_component = 'Helpdesk Staff Access';
7408: my $args = { bread_crumbs => $brcrum,
7409: bread_crumbs_component => $bread_crumbs_component};
7410:
7411: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
7412: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
7413: my $confname = $cdom.'-domainconfig';
7414: my $crstype = &Apache::loncommon::course_type();
7415:
1.406.2.12 raeburn 7416: my @accesstypes = ('all','dh','da','none');
1.406.2.10 raeburn 7417: my ($numstatustypes,@jsarray);
7418: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($cdom);
7419: if (ref($types) eq 'ARRAY') {
7420: if (@{$types} > 0) {
7421: $numstatustypes = scalar(@{$types});
7422: push(@accesstypes,'status');
7423: @jsarray = ('bystatus');
7424: }
7425: }
7426: my %customroles = &get_domain_customroles($cdom,$confname);
1.406.2.12 raeburn 7427: my %domhelpdesk = &Apache::lonnet::get_active_domroles($cdom,['dh','da']);
1.406.2.10 raeburn 7428: if (keys(%domhelpdesk)) {
7429: push(@accesstypes,('inc','exc'));
7430: push(@jsarray,('notinc','notexc'));
7431: }
7432: push(@jsarray,'privs');
7433: my $hiddenstr = join("','",@jsarray);
7434: my $rolestr = join("','",sort(keys(%customroles)));
7435:
7436: my $jscript;
7437: my (%settings,%overridden);
7438: if (keys(%customroles)) {
7439: &get_adhocrole_settings($env{'request.course.id'},\@accesstypes,
7440: $types,\%customroles,\%settings,\%overridden);
7441: my %jsfull=();
7442: my %jslevels= (
7443: course => {},
7444: domain => {},
7445: system => {},
7446: );
7447: my %jslevelscurrent=(
7448: course => {},
7449: domain => {},
7450: system => {},
7451: );
7452: my (%privs,%jsprivs);
7453: &Apache::lonuserutils::custom_role_privs(\%privs,\%jsfull,\%jslevels,\%jslevelscurrent);
7454: foreach my $priv (keys(%jsfull)) {
7455: if ($jslevels{'course'}{$priv}) {
7456: $jsprivs{$priv} = 1;
7457: }
7458: }
7459: my (%elements,%stored);
7460: foreach my $role (keys(%customroles)) {
7461: $elements{$role.'_access'} = 'radio';
7462: $elements{$role.'_incrs'} = 'radio';
7463: if ($numstatustypes) {
7464: $elements{$role.'_status'} = 'checkbox';
7465: }
7466: if (keys(%domhelpdesk) > 0) {
7467: $elements{$role.'_staff_inc'} = 'checkbox';
7468: $elements{$role.'_staff_exc'} = 'checkbox';
7469: }
7470: $elements{$role.'_override'} = 'checkbox';
7471: if (ref($settings{$role}) eq 'HASH') {
7472: if ($settings{$role}{'access'} ne '') {
7473: my $curraccess = $settings{$role}{'access'};
7474: $stored{$role.'_access'} = $curraccess;
7475: $stored{$role.'_incrs'} = 1;
7476: if ($curraccess eq 'status') {
7477: if (ref($settings{$role}{'status'}) eq 'ARRAY') {
7478: $stored{$role.'_status'} = $settings{$role}{'status'};
7479: }
7480: } elsif (($curraccess eq 'exc') || ($curraccess eq 'inc')) {
7481: if (ref($settings{$role}{$curraccess}) eq 'ARRAY') {
7482: $stored{$role.'_staff_'.$curraccess} = $settings{$role}{$curraccess};
7483: }
7484: }
7485: } else {
7486: $stored{$role.'_incrs'} = 0;
7487: }
7488: $stored{$role.'_override'} = [];
7489: if ($env{'course.'.$env{'request.course.id'}.'.internal.adhocpriv.'.$role}) {
7490: if (ref($settings{$role}{'off'}) eq 'ARRAY') {
7491: foreach my $priv (@{$settings{$role}{'off'}}) {
7492: push(@{$stored{$role.'_override'}},$priv);
7493: }
7494: }
7495: if (ref($settings{$role}{'on'}) eq 'ARRAY') {
7496: foreach my $priv (@{$settings{$role}{'on'}}) {
7497: unless (grep(/^$priv$/,@{$stored{$role.'_override'}})) {
7498: push(@{$stored{$role.'_override'}},$priv);
7499: }
7500: }
7501: }
7502: }
7503: } else {
7504: $stored{$role.'_incrs'} = 0;
7505: }
7506: }
7507: $jscript = &Apache::lonhtmlcommon::set_form_elements(\%elements,\%stored);
7508: }
7509:
7510: my $js = <<"ENDJS";
7511: <script type="text/javascript">
7512: // <![CDATA[
7513: $jscript;
7514:
7515: function switchRoleTab(caller,role) {
7516: if (document.getElementById(role+'_maindiv')) {
7517: if (caller.id != 'LC_current_minitab') {
7518: if (document.getElementById('LC_current_minitab')) {
7519: document.getElementById('LC_current_minitab').id=null;
7520: }
7521: var roledivs = Array('$rolestr');
7522: if (roledivs.length > 0) {
7523: for (var i=0; i<roledivs.length; i++) {
7524: if (document.getElementById(roledivs[i]+'_maindiv')) {
7525: document.getElementById(roledivs[i]+'_maindiv').style.display='none';
7526: }
7527: }
7528: }
7529: caller.id = 'LC_current_minitab';
7530: document.getElementById(role+'_maindiv').style.display='block';
7531: }
7532: }
7533: return false;
7534: }
7535:
7536: function helpdeskAccess(role) {
7537: var curraccess = null;
7538: if (document.$formname.elements[role+'_access'].length) {
7539: for (var i=0; i<document.$formname.elements[role+'_access'].length; i++) {
7540: if (document.$formname.elements[role+'_access'][i].checked) {
7541: curraccess = document.$formname.elements[role+'_access'][i].value;
7542: }
7543: }
7544: }
7545: var shown = Array();
7546: var hidden = Array();
7547: if (curraccess == 'none') {
7548: hidden = Array ('$hiddenstr');
7549: } else {
7550: if (curraccess == 'status') {
7551: shown = Array ('bystatus','privs');
7552: hidden = Array ('notinc','notexc');
7553: } else {
7554: if (curraccess == 'exc') {
7555: shown = Array ('notexc','privs');
7556: hidden = Array ('notinc','bystatus');
7557: }
7558: if (curraccess == 'inc') {
7559: shown = Array ('notinc','privs');
7560: hidden = Array ('notexc','bystatus');
7561: }
7562: if (curraccess == 'all') {
7563: shown = Array ('privs');
7564: hidden = Array ('notinc','notexc','bystatus');
7565: }
7566: }
7567: }
7568: if (hidden.length > 0) {
7569: for (var i=0; i<hidden.length; i++) {
7570: if (document.getElementById(role+'_'+hidden[i])) {
7571: document.getElementById(role+'_'+hidden[i]).style.display = 'none';
7572: }
7573: }
7574: }
7575: if (shown.length > 0) {
7576: for (var i=0; i<shown.length; i++) {
7577: if (document.getElementById(role+'_'+shown[i])) {
7578: if (shown[i] == 'privs') {
7579: document.getElementById(role+'_'+shown[i]).style.display = 'block';
7580: } else {
7581: document.getElementById(role+'_'+shown[i]).style.display = 'inline';
7582: }
7583: }
7584: }
7585: }
7586: return;
7587: }
7588:
7589: function toggleAccess(role) {
7590: if ((document.getElementById(role+'_setincrs')) &&
7591: (document.getElementById(role+'_setindom'))) {
7592: for (var i=0; i<document.$formname.elements[role+'_incrs'].length; i++) {
7593: if (document.$formname.elements[role+'_incrs'][i].checked) {
7594: if (document.$formname.elements[role+'_incrs'][i].value == 1) {
7595: document.getElementById(role+'_setindom').style.display = 'none';
7596: document.getElementById(role+'_setincrs').style.display = 'block';
7597: } else {
7598: document.getElementById(role+'_setincrs').style.display = 'none';
7599: document.getElementById(role+'_setindom').style.display = 'block';
7600: }
7601: break;
7602: }
7603: }
7604: }
7605: return;
7606: }
7607:
7608: // ]]>
7609: </script>
7610: ENDJS
7611:
7612: $args->{add_entries} = {onload => "javascript:setFormElements(document.$formname)"};
7613:
7614: # print page header
7615: $r->print(&header($js,$args));
7616: # print form header
7617: $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">');
7618:
7619: if (keys(%customroles)) {
7620: my %lt = &Apache::lonlocal::texthash(
7621: 'aco' => 'As course owner you may override the defaults set in the domain for role usage and/or privileges.',
7622: 'rou' => 'Role usage',
7623: 'whi' => 'Which helpdesk personnel may use this role?',
7624: 'udd' => 'Use domain default',
1.406.2.12 raeburn 7625: 'all' => 'All with domain helpdesk or helpdesk assistant role',
7626: 'dh' => 'All with domain helpdesk role',
7627: 'da' => 'All with domain helpdesk assistant role',
1.406.2.10 raeburn 7628: 'none' => 'None',
7629: 'status' => 'Determined based on institutional status',
7630: 'inc' => 'Include all, but exclude specific personnel',
7631: 'exc' => 'Exclude all, but include specific personnel',
7632: 'hel' => 'Helpdesk',
7633: 'rpr' => 'Role privileges',
7634: );
7635: $lt{'tfh'} = &mt("Custom [_1]ad hoc[_2] course roles available for use by the domain's helpdesk are as follows",'<i>','</i>');
7636: my %domconfig = &Apache::lonnet::get_dom('configuration',['helpsettings'],$cdom);
7637: my (%domcurrent,%ordered,%description,%domusage,$disabled);
7638: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
7639: if (ref($domconfig{'helpsettings'}{'adhoc'}) eq 'HASH') {
7640: %domcurrent = %{$domconfig{'helpsettings'}{'adhoc'}};
7641: }
7642: }
7643: my $count = 0;
7644: foreach my $role (sort(keys(%customroles))) {
7645: my ($order,$desc,$access_in_dom);
7646: if (ref($domcurrent{$role}) eq 'HASH') {
7647: $order = $domcurrent{$role}{'order'};
7648: $desc = $domcurrent{$role}{'desc'};
7649: $access_in_dom = $domcurrent{$role}{'access'};
7650: }
7651: if ($order eq '') {
7652: $order = $count;
7653: }
7654: $ordered{$order} = $role;
7655: if ($desc ne '') {
7656: $description{$role} = $desc;
7657: } else {
7658: $description{$role}= $role;
7659: }
7660: $count++;
7661: }
7662: %domusage = &domain_adhoc_access(\%customroles,\%domcurrent,\@accesstypes,$usertypes,$othertitle);
7663: my @roles_by_num = ();
7664: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
7665: push(@roles_by_num,$ordered{$item});
7666: }
7667: $r->print('<p>'.$lt{'tfh'}.': <i>'.join('</i>, <i>',map { $description{$_}; } @roles_by_num).'</i>.');
7668: if ($permission->{'owner'}) {
7669: $r->print('<br />'.$lt{'aco'}.'</p><p>');
7670: $r->print('<input type="hidden" name="state" value="process" />'.
7671: '<input type="submit" value="'.&mt('Save changes').'" />');
7672: } else {
7673: if ($env{'course.'.$env{'request.course.id'}.'.internal.courseowner'}) {
7674: my ($ownername,$ownerdom) = split(/:/,$env{'course.'.$env{'request.course.id'}.'.internal.courseowner'});
7675: $r->print('<br />'.&mt('The course owner -- [_1] -- can override the default access and/or privileges for these ad hoc roles.',
7676: &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($ownername,$ownerdom),$ownername,$ownerdom)));
7677: }
7678: $disabled = ' disabled="disabled"';
7679: }
7680: $r->print('</p>');
7681:
7682: $r->print('<div id="LC_minitab_header"><ul>');
7683: my $count = 0;
7684: my %visibility;
7685: foreach my $role (@roles_by_num) {
7686: my $id;
7687: if ($count == 0) {
7688: $id=' id="LC_current_minitab"';
7689: $visibility{$role} = ' style="display:block"';
7690: } else {
7691: $visibility{$role} = ' style="display:none"';
7692: }
7693: $count ++;
7694: $r->print('<li'.$id.'><a href="#" onclick="javascript:switchRoleTab(this.parentNode,'."'$role'".');">'.$description{$role}.'</a></li>');
7695: }
7696: $r->print('</ul></div>');
7697:
7698: foreach my $role (@roles_by_num) {
7699: my %usecheck = (
7700: all => ' checked="checked"',
7701: );
7702: my %displaydiv = (
7703: status => 'none',
7704: inc => 'none',
7705: exc => 'none',
7706: priv => 'block',
7707: );
7708: my (%selected,$overridden,$incrscheck,$indomcheck,$indomvis,$incrsvis);
7709: if (ref($settings{$role}) eq 'HASH') {
7710: if ($settings{$role}{'access'} ne '') {
7711: $indomvis = ' style="display:none"';
7712: $incrsvis = ' style="display:block"';
7713: $incrscheck = ' checked="checked"';
7714: if ($settings{$role}{'access'} ne 'all') {
7715: $usecheck{$settings{$role}{'access'}} = $usecheck{'all'};
7716: delete($usecheck{'all'});
7717: if ($settings{$role}{'access'} eq 'status') {
7718: my $access = 'status';
7719: $displaydiv{$access} = 'inline';
7720: if (ref($settings{$role}{$access}) eq 'ARRAY') {
7721: $selected{$access} = $settings{$role}{$access};
7722: }
7723: } elsif ($settings{$role}{'access'} =~ /^(inc|exc)$/) {
7724: my $access = $1;
7725: $displaydiv{$access} = 'inline';
7726: if (ref($settings{$role}{$access}) eq 'ARRAY') {
7727: $selected{$access} = $settings{$role}{$access};
7728: }
7729: } elsif ($settings{$role}{'access'} eq 'none') {
7730: $displaydiv{'priv'} = 'none';
7731: }
7732: }
7733: } else {
7734: $indomcheck = ' checked="checked"';
7735: $indomvis = ' style="display:block"';
7736: $incrsvis = ' style="display:none"';
7737: }
7738: } else {
7739: $indomcheck = ' checked="checked"';
7740: $indomvis = ' style="display:block"';
7741: $incrsvis = ' style="display:none"';
7742: }
7743: $r->print('<div class="LC_left_float" id="'.$role.'_maindiv"'.$visibility{$role}.'>'.
7744: '<fieldset><legend>'.$lt{'rou'}.'</legend>'.
7745: '<p>'.$lt{'whi'}.' <span class="LC_nobreak">'.
7746: '<label><input type="radio" name="'.$role.'_incrs" value="1"'.$incrscheck.' onclick="toggleAccess('."'$role'".');"'.$disabled.'>'.
7747: &mt('Set here in [_1]',lc($crstype)).'</label>'.
7748: '<span>'.(' 'x2).
7749: '<label><input type="radio" name="'.$role.'_incrs" value="0"'.$indomcheck.' onclick="toggleAccess('."'$role'".');"'.$disabled.'>'.
7750: $lt{'udd'}.'</label><span></p>'.
7751: '<div id="'.$role.'_setindom"'.$indomvis.'>'.
7752: '<span class="LC_cusr_emph">'.$domusage{$role}.'</span></div>'.
7753: '<div id="'.$role.'_setincrs"'.$incrsvis.'>');
7754: foreach my $access (@accesstypes) {
7755: $r->print('<p><label><input type="radio" name="'.$role.'_access" value="'.$access.'" '.$usecheck{$access}.
7756: ' onclick="helpdeskAccess('."'$role'".');"'.$disabled.' />'.$lt{$access}.'</label>');
7757: if ($access eq 'status') {
7758: $r->print('<div id="'.$role.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
7759: &Apache::lonuserutils::adhoc_status_types($cdom,undef,$role,$selected{$access},
7760: $othertitle,$usertypes,$types,$disabled).
7761: '</div>');
7762: } elsif (($access eq 'inc') && (keys(%domhelpdesk) > 0)) {
7763: $r->print('<div id="'.$role.'_notinc" style="display:'.$displaydiv{$access}.'">'.
7764: &Apache::lonuserutils::adhoc_staff($access,undef,$role,$selected{$access},
7765: \%domhelpdesk,$disabled).
7766: '</div>');
7767: } elsif (($access eq 'exc') && (keys(%domhelpdesk) > 0)) {
7768: $r->print('<div id="'.$role.'_notexc" style="display:'.$displaydiv{$access}.'">'.
7769: &Apache::lonuserutils::adhoc_staff($access,undef,$role,$selected{$access},
7770: \%domhelpdesk,$disabled).
7771: '</div>');
7772: }
7773: $r->print('</p>');
7774: }
7775: $r->print('</div></fieldset>');
7776: my %full=();
7777: my %levels= (
7778: course => {},
7779: domain => {},
7780: system => {},
7781: );
7782: my %levelscurrent=(
7783: course => {},
7784: domain => {},
7785: system => {},
7786: );
7787: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
7788: $r->print('<fieldset id="'.$role.'_privs" style="display:'.$displaydiv{'priv'}.'">'.
7789: '<legend>'.$lt{'rpr'}.'</legend>'.
7790: &role_priv_table($role,$permission,$crstype,\%full,\%levels,\%levelscurrent,$overridden{$role}).
7791: '</fieldset></div><div style="padding:0;clear:both;margin:0;border:0"></div>');
7792: }
7793: if ($permission->{'owner'}) {
7794: $r->print('<p><input type="submit" value="'.&mt('Save changes').'" /></p>');
7795: }
7796: } else {
7797: $r->print(&mt('Helpdesk roles have not yet been created in this domain.'));
7798: }
7799: # Form Footer
7800: $r->print('<input type="hidden" name="action" value="helpdesk" />'
7801: .'</form>');
7802: return;
7803: }
7804:
7805: sub domain_adhoc_access {
7806: my ($roles,$domcurrent,$accesstypes,$usertypes,$othertitle) = @_;
7807: my %domusage;
7808: return unless ((ref($roles) eq 'HASH') && (ref($domcurrent) eq 'HASH') && (ref($accesstypes) eq 'ARRAY'));
7809: foreach my $role (keys(%{$roles})) {
7810: if (ref($domcurrent->{$role}) eq 'HASH') {
7811: my $access = $domcurrent->{$role}{'access'};
7812: if (($access eq '') || (!grep(/^\Q$access\E$/,@{$accesstypes}))) {
7813: $access = 'all';
1.406.2.12 raeburn 7814: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role',&Apache::lonnet::plaintext('dh'),
7815: &Apache::lonnet::plaintext('da'));
1.406.2.10 raeburn 7816: } elsif ($access eq 'status') {
7817: if (ref($domcurrent->{$role}{$access}) eq 'ARRAY') {
7818: my @shown;
7819: foreach my $type (@{$domcurrent->{$role}{$access}}) {
7820: unless ($type eq 'default') {
7821: if ($usertypes->{$type}) {
7822: push(@shown,$usertypes->{$type});
7823: }
7824: }
7825: }
7826: if (grep(/^default$/,@{$domcurrent->{$role}{$access}})) {
7827: push(@shown,$othertitle);
7828: }
7829: if (@shown) {
7830: my $shownstatus = join(' '.&mt('or').' ',@shown);
1.406.2.12 raeburn 7831: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role, and institutional status: [_3]',
7832: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'),$shownstatus);
1.406.2.10 raeburn 7833: } else {
7834: $domusage{$role} = &mt('No one in the domain');
7835: }
7836: }
7837: } elsif ($access eq 'inc') {
7838: my @dominc = ();
7839: if (ref($domcurrent->{$role}{'inc'}) eq 'ARRAY') {
7840: foreach my $user (@{$domcurrent->{$role}{'inc'}}) {
7841: my ($uname,$udom) = split(/:/,$user);
7842: push(@dominc,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),$uname,$udom));
7843: }
7844: my $showninc = join(', ',@dominc);
7845: if ($showninc ne '') {
1.406.2.12 raeburn 7846: $domusage{$role} = &mt('Include any user in domain with active [_1] or [_2] role, except: [_3]',
7847: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'),$showninc);
1.406.2.10 raeburn 7848: } else {
1.406.2.12 raeburn 7849: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role',
7850: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'));
1.406.2.10 raeburn 7851: }
7852: }
7853: } elsif ($access eq 'exc') {
7854: my @domexc = ();
7855: if (ref($domcurrent->{$role}{'exc'}) eq 'ARRAY') {
7856: foreach my $user (@{$domcurrent->{$role}{'exc'}}) {
7857: my ($uname,$udom) = split(/:/,$user);
7858: push(@domexc,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),$uname,$udom));
7859: }
7860: }
7861: my $shownexc = join(', ',@domexc);
7862: if ($shownexc ne '') {
1.406.2.12 raeburn 7863: $domusage{$role} = &mt('Only the following in the domain with active [_1] or [_2] role: [_3]',
7864: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'),$shownexc);
1.406.2.10 raeburn 7865: } else {
7866: $domusage{$role} = &mt('No one in the domain');
7867: }
7868: } elsif ($access eq 'none') {
7869: $domusage{$role} = &mt('No one in the domain');
1.406.2.12 raeburn 7870: } elsif ($access eq 'dh') {
1.406.2.10 raeburn 7871: $domusage{$role} = &mt('Any user in domain with active [_1] role',&Apache::lonnet::plaintext('dh'));
1.406.2.12 raeburn 7872: } elsif ($access eq 'da') {
7873: $domusage{$role} = &mt('Any user in domain with active [_1] role',&Apache::lonnet::plaintext('da'));
7874: } elsif ($access eq 'all') {
7875: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role',
7876: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'));
1.406.2.10 raeburn 7877: }
7878: } else {
1.406.2.12 raeburn 7879: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role',
7880: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'));
1.406.2.10 raeburn 7881: }
7882: }
7883: return %domusage;
7884: }
7885:
7886: sub get_domain_customroles {
7887: my ($cdom,$confname) = @_;
7888: my %existing=&Apache::lonnet::dump('roles',$cdom,$confname,'rolesdef_');
7889: my %customroles;
7890: foreach my $key (keys(%existing)) {
7891: if ($key=~/^rolesdef\_(\w+)$/) {
7892: my $rolename = $1;
7893: my %privs;
7894: ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
7895: $customroles{$rolename} = \%privs;
7896: }
7897: }
7898: return %customroles;
7899: }
7900:
7901: sub role_priv_table {
7902: my ($role,$permission,$crstype,$full,$levels,$levelscurrent,$overridden) = @_;
7903: return unless ((ref($full) eq 'HASH') && (ref($levels) eq 'HASH') &&
7904: (ref($levelscurrent) eq 'HASH'));
7905: my %lt=&Apache::lonlocal::texthash (
7906: 'crl' => 'Course Level Privilege',
7907: 'def' => 'Domain Defaults',
7908: 'ove' => 'Override in Course',
7909: 'ine' => 'In effect',
7910: 'dis' => 'Disabled',
7911: 'ena' => 'Enabled',
7912: );
7913: if ($crstype eq 'Community') {
7914: $lt{'ove'} = 'Override in Community',
7915: }
7916: my @status = ('Disabled','Enabled');
7917: my (%on,%off);
7918: if (ref($overridden) eq 'HASH') {
7919: if (ref($overridden->{'on'}) eq 'ARRAY') {
7920: map { $on{$_} = 1; } (@{$overridden->{'on'}});
7921: }
7922: if (ref($overridden->{'off'}) eq 'ARRAY') {
7923: map { $off{$_} = 1; } (@{$overridden->{'off'}});
7924: }
7925: }
7926: my $output=&Apache::loncommon::start_data_table().
7927: &Apache::loncommon::start_data_table_header_row().
7928: '<th>'.$lt{'crl'}.'</th><th>'.$lt{'def'}.'</th><th>'.$lt{'ove'}.
7929: '</th><th>'.$lt{'ine'}.'</th>'.
7930: &Apache::loncommon::end_data_table_header_row();
7931: foreach my $priv (sort(keys(%{$full}))) {
7932: next unless ($levels->{'course'}{$priv});
7933: my $privtext = &Apache::lonnet::plaintext($priv,$crstype);
7934: my ($default,$ineffect);
7935: if ($levelscurrent->{'course'}{$priv}) {
7936: $default = '<img src="/adm/lonIcons/navmap.correct.gif" alt="'.$lt{'ena'}.'" />';
7937: $ineffect = $default;
7938: }
7939: my ($customstatus,$checked);
7940: $output .= &Apache::loncommon::start_data_table_row().
7941: '<td>'.$privtext.'</td>'.
7942: '<td>'.$default.'</td><td>';
7943: if (($levelscurrent->{'course'}{$priv}) && ($off{$priv})) {
7944: if ($permission->{'owner'}) {
7945: $checked = ' checked="checked"';
7946: }
7947: $customstatus = '<img src="/adm/lonIcons/navmap.wrong.gif" alt="'.$lt{'dis'}.'" />';
7948: $ineffect = $customstatus;
7949: } elsif ((!$levelscurrent->{'course'}{$priv}) && ($on{$priv})) {
7950: if ($permission->{'owner'}) {
7951: $checked = ' checked="checked"';
7952: }
7953: $customstatus = '<img src="/adm/lonIcons/navmap.correct.gif" alt="'.$lt{'ena'}.'" />';
7954: $ineffect = $customstatus;
7955: }
7956: if ($permission->{'owner'}) {
7957: $output .= '<input type="checkbox" name="'.$role.'_override" value="'.$priv.'"'.$checked.' />';
7958: } else {
7959: $output .= $customstatus;
7960: }
7961: $output .= '</td><td>'.$ineffect.'</td>'.
7962: &Apache::loncommon::end_data_table_row();
7963: }
7964: $output .= &Apache::loncommon::end_data_table();
7965: return $output;
7966: }
7967:
7968: sub get_adhocrole_settings {
7969: my ($cid,$accesstypes,$types,$customroles,$settings,$overridden) = @_;
7970: return unless ((ref($accesstypes) eq 'ARRAY') && (ref($customroles) eq 'HASH') &&
7971: (ref($settings) eq 'HASH') && (ref($overridden) eq 'HASH'));
7972: foreach my $role (split(/,/,$env{'course.'.$cid.'.internal.adhocaccess'})) {
7973: my ($curraccess,$rest) = split(/=/,$env{'course.'.$cid.'.internal.adhoc.'.$role});
7974: if (($curraccess ne '') && (grep(/^\Q$curraccess\E$/,@{$accesstypes}))) {
7975: $settings->{$role}{'access'} = $curraccess;
7976: if (($curraccess eq 'status') && (ref($types) eq 'ARRAY')) {
7977: my @status = split(/,/,$rest);
7978: my @currstatus;
7979: foreach my $type (@status) {
7980: if ($type eq 'default') {
7981: push(@currstatus,$type);
7982: } elsif (grep(/^\Q$type\E$/,@{$types})) {
7983: push(@currstatus,$type);
7984: }
7985: }
7986: if (@currstatus) {
7987: $settings->{$role}{$curraccess} = \@currstatus;
7988: } elsif (($curraccess eq 'exc') || ($curraccess eq 'inc')) {
7989: my @personnel = split(/,/,$rest);
7990: $settings->{$role}{$curraccess} = \@personnel;
7991: }
7992: }
7993: }
7994: }
7995: foreach my $role (keys(%{$customroles})) {
7996: if ($env{'course.'.$cid.'.internal.adhocpriv.'.$role}) {
7997: my %currentprivs;
7998: if (ref($customroles->{$role}) eq 'HASH') {
7999: if (exists($customroles->{$role}{'course'})) {
8000: my %full=();
8001: my %levels= (
8002: course => {},
8003: domain => {},
8004: system => {},
8005: );
8006: my %levelscurrent=(
8007: course => {},
8008: domain => {},
8009: system => {},
8010: );
8011: &Apache::lonuserutils::custom_role_privs($customroles->{$role},\%full,\%levels,\%levelscurrent);
8012: %currentprivs = %{$levelscurrent{'course'}};
8013: }
8014: }
8015: foreach my $item (split(/,/,$env{'course.'.$cid.'.internal.adhocpriv.'.$role})) {
8016: next if ($item eq '');
8017: my ($rule,$rest) = split(/=/,$item);
8018: next unless (($rule eq 'off') || ($rule eq 'on'));
8019: foreach my $priv (split(/:/,$rest)) {
8020: if ($priv ne '') {
8021: if ($rule eq 'off') {
8022: push(@{$overridden->{$role}{'off'}},$priv);
8023: if ($currentprivs{$priv}) {
8024: push(@{$settings->{$role}{'off'}},$priv);
8025: }
8026: } else {
8027: push(@{$overridden->{$role}{'on'}},$priv);
8028: unless ($currentprivs{$priv}) {
8029: push(@{$settings->{$role}{'on'}},$priv);
8030: }
8031: }
8032: }
8033: }
8034: }
8035: }
8036: }
8037: return;
8038: }
8039:
8040: sub update_helpdeskaccess {
8041: my ($r,$permission,$brcrum) = @_;
8042: my $helpitem = 'Course_Helpdesk_Access';
8043: push (@{$brcrum},
8044: {href => '/adm/createuser?action=helpdesk',
8045: text => 'Helpdesk Access',
8046: help => $helpitem},
8047: {href => '/adm/createuser?action=helpdesk',
8048: text => 'Result',
8049: help => $helpitem}
8050: );
8051: my $bread_crumbs_component = 'Helpdesk Staff Access';
8052: my $args = { bread_crumbs => $brcrum,
8053: bread_crumbs_component => $bread_crumbs_component};
8054:
8055: # print page header
8056: $r->print(&header('',$args));
8057: unless ((ref($permission) eq 'HASH') && ($permission->{'owner'})) {
8058: $r->print('<p class="LC_error">'.&mt('You do not have permission to change helpdesk access.').'</p>');
8059: return;
8060: }
1.406.2.12 raeburn 8061: my @accesstypes = ('all','dh','da','none','status','inc','exc');
1.406.2.10 raeburn 8062: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
8063: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
8064: my $confname = $cdom.'-domainconfig';
8065: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($cdom);
8066: my $crstype = &Apache::loncommon::course_type();
8067: my %customroles = &get_domain_customroles($cdom,$confname);
8068: my (%settings,%overridden);
8069: &get_adhocrole_settings($env{'request.course.id'},\@accesstypes,
8070: $types,\%customroles,\%settings,\%overridden);
1.406.2.12 raeburn 8071: my %domhelpdesk = &Apache::lonnet::get_active_domroles($cdom,['dh','da']);
1.406.2.10 raeburn 8072: my (%changed,%storehash,@todelete);
8073:
8074: if (keys(%customroles)) {
8075: my (%newsettings,@incrs);
8076: foreach my $role (keys(%customroles)) {
8077: $newsettings{$role} = {
8078: access => '',
8079: status => '',
8080: exc => '',
8081: inc => '',
8082: on => '',
8083: off => '',
8084: };
8085: my %current;
8086: if (ref($settings{$role}) eq 'HASH') {
8087: %current = %{$settings{$role}};
8088: }
8089: if (ref($overridden{$role}) eq 'HASH') {
8090: $current{'overridden'} = $overridden{$role};
8091: }
8092: if ($env{'form.'.$role.'_incrs'}) {
8093: my $access = $env{'form.'.$role.'_access'};
8094: if (grep(/^\Q$access\E$/,@accesstypes)) {
8095: push(@incrs,$role);
8096: unless ($current{'access'} eq $access) {
8097: $changed{$role}{'access'} = 1;
8098: $storehash{'internal.adhoc.'.$role} = $access;
8099: }
8100: if ($access eq 'status') {
8101: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$role.'_status');
8102: my @stored;
8103: my @shownstatus;
8104: if (ref($types) eq 'ARRAY') {
8105: foreach my $type (sort(@statuses)) {
8106: if ($type eq 'default') {
8107: push(@stored,$type);
8108: } elsif (grep(/^\Q$type\E$/,@{$types})) {
8109: push(@stored,$type);
8110: push(@shownstatus,$usertypes->{$type});
8111: }
8112: }
8113: if (grep(/^default$/,@statuses)) {
8114: push(@shownstatus,$othertitle);
8115: }
8116: $storehash{'internal.adhoc.'.$role} .= '='.join(',',@stored);
8117: }
8118: $newsettings{$role}{'status'} = join(' '.&mt('or').' ',@shownstatus);
8119: if (ref($current{'status'}) eq 'ARRAY') {
8120: my @diffs = &Apache::loncommon::compare_arrays(\@stored,$current{'status'});
8121: if (@diffs) {
8122: $changed{$role}{'status'} = 1;
8123: }
8124: } elsif (@stored) {
8125: $changed{$role}{'status'} = 1;
8126: }
8127: } elsif (($access eq 'inc') || ($access eq 'exc')) {
8128: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$role.'_staff_'.$access);
8129: my @newspecstaff;
8130: my @stored;
8131: my @currstaff;
8132: foreach my $person (sort(@personnel)) {
8133: if ($domhelpdesk{$person}) {
8134: push(@stored,$person);
8135: }
8136: }
8137: if (ref($current{$access}) eq 'ARRAY') {
8138: my @diffs = &Apache::loncommon::compare_arrays(\@stored,$current{$access});
8139: if (@diffs) {
8140: $changed{$role}{$access} = 1;
8141: }
8142: } elsif (@stored) {
8143: $changed{$role}{$access} = 1;
8144: }
8145: $storehash{'internal.adhoc.'.$role} .= '='.join(',',@stored);
8146: foreach my $person (@stored) {
8147: my ($uname,$udom) = split(/:/,$person);
8148: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
8149: }
8150: $newsettings{$role}{$access} = join(', ',sort(@newspecstaff));
8151: }
8152: $newsettings{$role}{'access'} = $access;
8153: }
8154: } else {
8155: if (($current{'access'} ne '') && (grep(/^\Q$current{'access'}\E$/,@accesstypes))) {
8156: $changed{$role}{'access'} = 1;
8157: $newsettings{$role} = {};
8158: push(@todelete,'internal.adhoc.'.$role);
8159: }
8160: }
8161: if (($env{'form.'.$role.'_incrs'}) && ($env{'form.'.$role.'_access'} eq 'none')) {
8162: if (ref($current{'overridden'}) eq 'HASH') {
8163: push(@todelete,'internal.adhocpriv.'.$role);
8164: }
8165: } else {
8166: my %full=();
8167: my %levels= (
8168: course => {},
8169: domain => {},
8170: system => {},
8171: );
8172: my %levelscurrent=(
8173: course => {},
8174: domain => {},
8175: system => {},
8176: );
8177: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
8178: my (@updatedon,@updatedoff,@override);
8179: @override = &Apache::loncommon::get_env_multiple('form.'.$role.'_override');
8180: if (@override) {
8181: foreach my $priv (sort(keys(%full))) {
8182: next unless ($levels{'course'}{$priv});
8183: if (grep(/^\Q$priv\E$/,@override)) {
8184: if ($levelscurrent{'course'}{$priv}) {
8185: push(@updatedoff,$priv);
8186: } else {
8187: push(@updatedon,$priv);
8188: }
8189: }
8190: }
8191: }
8192: if (@updatedon) {
8193: $newsettings{$role}{'on'} = join('</li><li>', map { &Apache::lonnet::plaintext($_,$crstype) } (@updatedon));
8194: }
8195: if (@updatedoff) {
8196: $newsettings{$role}{'off'} = join('</li><li>', map { &Apache::lonnet::plaintext($_,$crstype) } (@updatedoff));
8197: }
8198: if (ref($current{'overridden'}) eq 'HASH') {
8199: if (ref($current{'overridden'}{'on'}) eq 'ARRAY') {
8200: if (@updatedon) {
8201: my @diffs = &Apache::loncommon::compare_arrays(\@updatedon,$current{'overridden'}{'on'});
8202: if (@diffs) {
8203: $changed{$role}{'on'} = 1;
8204: }
8205: } else {
8206: $changed{$role}{'on'} = 1;
8207: }
8208: } elsif (@updatedon) {
8209: $changed{$role}{'on'} = 1;
8210: }
8211: if (ref($current{'overridden'}{'off'}) eq 'ARRAY') {
8212: if (@updatedoff) {
8213: my @diffs = &Apache::loncommon::compare_arrays(\@updatedoff,$current{'overridden'}{'off'});
8214: if (@diffs) {
8215: $changed{$role}{'off'} = 1;
8216: }
8217: } else {
8218: $changed{$role}{'off'} = 1;
8219: }
8220: } elsif (@updatedoff) {
8221: $changed{$role}{'off'} = 1;
8222: }
8223: } else {
8224: if (@updatedon) {
8225: $changed{$role}{'on'} = 1;
8226: }
8227: if (@updatedoff) {
8228: $changed{$role}{'off'} = 1;
8229: }
8230: }
8231: if (ref($changed{$role}) eq 'HASH') {
8232: if (($changed{$role}{'on'} || $changed{$role}{'off'})) {
8233: my $newpriv;
8234: if (@updatedon) {
8235: $newpriv = 'on='.join(':',@updatedon);
8236: }
8237: if (@updatedoff) {
8238: $newpriv .= ($newpriv ? ',' : '' ).'off='.join(':',@updatedoff);
8239: }
8240: if ($newpriv eq '') {
8241: push(@todelete,'internal.adhocpriv.'.$role);
8242: } else {
8243: $storehash{'internal.adhocpriv.'.$role} = $newpriv;
8244: }
8245: }
8246: }
8247: }
8248: }
8249: if (@incrs) {
8250: $storehash{'internal.adhocaccess'} = join(',',@incrs);
8251: } elsif (@todelete) {
8252: push(@todelete,'internal.adhocaccess');
8253: }
8254: if (keys(%changed)) {
8255: my ($putres,$delres);
8256: if (keys(%storehash)) {
8257: $putres = &Apache::lonnet::put('environment',\%storehash,$cdom,$cnum);
8258: my %newenvhash;
8259: foreach my $key (keys(%storehash)) {
8260: $newenvhash{'course.'.$env{'request.course.id'}.'.'.$key} = $storehash{$key};
8261: }
8262: &Apache::lonnet::appenv(\%newenvhash);
8263: }
8264: if (@todelete) {
8265: $delres = &Apache::lonnet::del('environment',\@todelete,$cdom,$cnum);
8266: foreach my $key (@todelete) {
8267: &Apache::lonnet::delenv('course.'.$env{'request.course.id'}.'.'.$key);
8268: }
8269: }
8270: if (($putres eq 'ok') || ($delres eq 'ok')) {
8271: my %domconfig = &Apache::lonnet::get_dom('configuration',['helpsettings'],$cdom);
8272: my (%domcurrent,%ordered,%description,%domusage);
8273: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
8274: if (ref($domconfig{'helpsettings'}{'adhoc'}) eq 'HASH') {
8275: %domcurrent = %{$domconfig{'helpsettings'}{'adhoc'}};
8276: }
8277: }
8278: my $count = 0;
8279: foreach my $role (sort(keys(%customroles))) {
8280: my ($order,$desc);
8281: if (ref($domcurrent{$role}) eq 'HASH') {
8282: $order = $domcurrent{$role}{'order'};
8283: $desc = $domcurrent{$role}{'desc'};
8284: }
8285: if ($order eq '') {
8286: $order = $count;
8287: }
8288: $ordered{$order} = $role;
8289: if ($desc ne '') {
8290: $description{$role} = $desc;
8291: } else {
8292: $description{$role}= $role;
8293: }
8294: $count++;
8295: }
8296: my @roles_by_num = ();
8297: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
8298: push(@roles_by_num,$ordered{$item});
8299: }
8300: %domusage = &domain_adhoc_access(\%changed,\%domcurrent,\@accesstypes,$usertypes,$othertitle);
8301: $r->print(&mt('Helpdesk access settings have been changed as follows').'<br />');
8302: $r->print('<ul>');
8303: foreach my $role (@roles_by_num) {
8304: next unless (ref($changed{$role}) eq 'HASH');
8305: $r->print('<li>'.&mt('Ad hoc role').': <b>'.$description{$role}.'</b>'.
8306: '<ul>');
8307: if ($changed{$role}{'access'} || $changed{$role}{'status'} || $changed{$role}{'inc'} || $changed{$role}{'exc'}) {
8308: $r->print('<li>');
8309: if ($env{'form.'.$role.'_incrs'}) {
8310: if ($newsettings{$role}{'access'} eq 'all') {
8311: $r->print(&mt('All helpdesk staff can access '.lc($crstype).' with this role.'));
1.406.2.12 raeburn 8312: } elsif ($newsettings{$role}{'access'} eq 'dh') {
8313: $r->print(&mt('Helpdesk staff can use this role if they have an active [_1] role',
8314: &Apache::lonnet::plaintext('dh')));
8315: } elsif ($newsettings{$role}{'access'} eq 'da') {
8316: $r->print(&mt('Helpdesk staff can use this role if they have an active [_1] role',
8317: &Apache::lonnet::plaintext('da')));
1.406.2.10 raeburn 8318: } elsif ($newsettings{$role}{'access'} eq 'none') {
8319: $r->print(&mt('No helpdesk staff can access '.lc($crstype).' with this role.'));
8320: } elsif ($newsettings{$role}{'access'} eq 'status') {
8321: if ($newsettings{$role}{'status'}) {
8322: my ($access,$rest) = split(/=/,$storehash{'internal.adhoc.'.$role});
8323: if (split(/,/,$rest) > 1) {
8324: $r->print(&mt('Helpdesk staff can use this role if their institutional type is one of: [_1].',
8325: $newsettings{$role}{'status'}));
8326: } else {
8327: $r->print(&mt('Helpdesk staff can use this role if their institutional type is: [_1].',
8328: $newsettings{$role}{'status'}));
8329: }
8330: } else {
8331: $r->print(&mt('No helpdesk staff can access '.lc($crstype).' with this role.'));
8332: }
8333: } elsif ($newsettings{$role}{'access'} eq 'exc') {
8334: if ($newsettings{$role}{'exc'}) {
8335: $r->print(&mt('Helpdesk staff who can use this role are as follows:').' '.$newsettings{$role}{'exc'}.'.');
8336: } else {
8337: $r->print(&mt('No helpdesk staff can access '.lc($crstype).' with this role.'));
8338: }
8339: } elsif ($newsettings{$role}{'access'} eq 'inc') {
8340: if ($newsettings{$role}{'inc'}) {
8341: $r->print(&mt('All helpdesk staff may use this role except the following:').' '.$newsettings{$role}{'inc'}.'.');
8342: } else {
8343: $r->print(&mt('All helpdesk staff may use this role.'));
8344: }
8345: }
8346: } else {
8347: $r->print(&mt('Default access set in the domain now applies.').'<br />'.
8348: '<span class="LC_cusr_emph">'.$domusage{$role}.'</span>');
8349: }
8350: $r->print('</li>');
8351: }
8352: unless ($newsettings{$role}{'access'} eq 'none') {
8353: if ($changed{$role}{'off'}) {
8354: if ($newsettings{$role}{'off'}) {
8355: $r->print('<li>'.&mt('Privileges which are available by default for this ad hoc role, but are disabled for this specific '.lc($crstype).':').
8356: '<ul><li>'.$newsettings{$role}{'off'}.'</li></ul></li>');
8357: } else {
8358: $r->print('<li>'.&mt('All privileges available by default for this ad hoc role are enabled.').'</li>');
8359: }
8360: }
8361: if ($changed{$role}{'on'}) {
8362: if ($newsettings{$role}{'on'}) {
8363: $r->print('<li>'.&mt('Privileges which are not available by default for this ad hoc role, but are enabled for this specific '.lc($crstype).':').
8364: '<ul><li>'.$newsettings{$role}{'on'}.'</li></ul></li>');
8365: } else {
8366: $r->print('<li>'.&mt('None of the privileges unavailable by default for this ad hoc role are enabled.').'</li>');
8367: }
8368: }
8369: }
8370: $r->print('</ul></li>');
8371: }
8372: $r->print('</ul>');
8373: }
8374: } else {
8375: $r->print(&mt('No changes made to helpdesk access settings.'));
8376: }
8377: }
8378: return;
8379: }
8380:
1.27 matthew 8381: #-------------------------------------------------- functions for &phase_two
1.160 raeburn 8382: sub user_search_result {
1.221 raeburn 8383: my ($context,$srch) = @_;
1.160 raeburn 8384: my %allhomes;
8385: my %inst_matches;
8386: my %srch_results;
1.181 raeburn 8387: my ($response,$currstate,$forcenewuser,$dirsrchres);
1.183 raeburn 8388: $srch->{'srchterm'} =~ s/\s+/ /g;
1.176 raeburn 8389: if ($srch->{'srchby'} !~ /^(uname|lastname|lastfirst)$/) {
1.160 raeburn 8390: $response = &mt('Invalid search.');
8391: }
8392: if ($srch->{'srchin'} !~ /^(crs|dom|alc|instd)$/) {
8393: $response = &mt('Invalid search.');
8394: }
1.177 raeburn 8395: if ($srch->{'srchtype'} !~ /^(exact|contains|begins)$/) {
1.160 raeburn 8396: $response = &mt('Invalid search.');
8397: }
8398: if ($srch->{'srchterm'} eq '') {
8399: $response = &mt('You must enter a search term.');
8400: }
1.183 raeburn 8401: if ($srch->{'srchterm'} =~ /^\s+$/) {
8402: $response = &mt('Your search term must contain more than just spaces.');
8403: }
1.160 raeburn 8404: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'instd')) {
8405: if (($srch->{'srchdomain'} eq '') ||
1.163 albertel 8406: ! (&Apache::lonnet::domain($srch->{'srchdomain'}))) {
1.160 raeburn 8407: $response = &mt('You must specify a valid domain when searching in a domain or institutional directory.')
8408: }
8409: }
8410: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs') ||
8411: ($srch->{'srchin'} eq 'alc')) {
1.176 raeburn 8412: if ($srch->{'srchby'} eq 'uname') {
1.243 raeburn 8413: my $unamecheck = $srch->{'srchterm'};
8414: if ($srch->{'srchtype'} eq 'contains') {
8415: if ($unamecheck !~ /^\w/) {
8416: $unamecheck = 'a'.$unamecheck;
8417: }
8418: }
8419: if ($unamecheck !~ /^$match_username$/) {
1.176 raeburn 8420: $response = &mt('You must specify a valid username. Only the following are allowed: letters numbers - . @');
8421: }
1.160 raeburn 8422: }
8423: }
1.180 raeburn 8424: if ($response ne '') {
1.406.2.4 raeburn 8425: $response = '<span class="LC_warning">'.$response.'</span><br />';
1.180 raeburn 8426: }
1.160 raeburn 8427: if ($srch->{'srchin'} eq 'instd') {
1.406.2.3 raeburn 8428: my $instd_chk = &instdirectorysrch_check($srch);
1.160 raeburn 8429: if ($instd_chk ne 'ok') {
1.406.2.3 raeburn 8430: my $domd_chk = &domdirectorysrch_check($srch);
1.406.2.4 raeburn 8431: $response .= '<span class="LC_warning">'.$instd_chk.'</span><br />';
1.406.2.3 raeburn 8432: if ($domd_chk eq 'ok') {
1.406.2.4 raeburn 8433: $response .= &mt('You may want to search in the LON-CAPA domain instead of the institutional directory.');
1.406.2.3 raeburn 8434: }
1.406.2.5 raeburn 8435: $response .= '<br />';
1.406.2.3 raeburn 8436: }
8437: } else {
8438: unless (($context eq 'requestcrs') && ($srch->{'srchtype'} eq 'exact')) {
8439: my $domd_chk = &domdirectorysrch_check($srch);
1.406.2.14 raeburn 8440: if (($domd_chk ne 'ok') && ($env{'form.action'} ne 'accesslogs')) {
1.406.2.3 raeburn 8441: my $instd_chk = &instdirectorysrch_check($srch);
1.406.2.4 raeburn 8442: $response .= '<span class="LC_warning">'.$domd_chk.'</span><br />';
1.406.2.3 raeburn 8443: if ($instd_chk eq 'ok') {
1.406.2.4 raeburn 8444: $response .= &mt('You may want to search in the institutional directory instead of the LON-CAPA domain.');
1.406.2.3 raeburn 8445: }
1.406.2.5 raeburn 8446: $response .= '<br />';
1.406.2.3 raeburn 8447: }
1.160 raeburn 8448: }
8449: }
8450: if ($response ne '') {
1.180 raeburn 8451: return ($currstate,$response);
1.160 raeburn 8452: }
8453: if ($srch->{'srchby'} eq 'uname') {
8454: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs')) {
8455: if ($env{'form.forcenew'}) {
8456: if ($srch->{'srchdomain'} ne $env{'request.role.domain'}) {
8457: my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
8458: if ($uhome eq 'no_host') {
8459: my $domdesc = &Apache::lonnet::domain($env{'request.role.domain'},'description');
1.180 raeburn 8460: my $showdom = &display_domain_info($env{'request.role.domain'});
8461: $response = &mt('New users can only be created in the domain to which your current role belongs - [_1].',$showdom);
1.160 raeburn 8462: } else {
1.179 raeburn 8463: $currstate = 'modify';
1.160 raeburn 8464: }
8465: } else {
1.179 raeburn 8466: $currstate = 'modify';
1.160 raeburn 8467: }
8468: } else {
8469: if ($srch->{'srchin'} eq 'dom') {
1.162 raeburn 8470: if ($srch->{'srchtype'} eq 'exact') {
8471: my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
8472: if ($uhome eq 'no_host') {
1.179 raeburn 8473: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8474: &build_search_response($context,$srch,%srch_results);
1.162 raeburn 8475: } else {
1.179 raeburn 8476: $currstate = 'modify';
1.406.2.5 raeburn 8477: if ($env{'form.action'} eq 'accesslogs') {
8478: $currstate = 'activity';
8479: }
1.310 raeburn 8480: my $uname = $srch->{'srchterm'};
8481: my $udom = $srch->{'srchdomain'};
8482: $srch_results{$uname.':'.$udom} =
8483: { &Apache::lonnet::get('environment',
8484: ['firstname',
8485: 'lastname',
8486: 'permanentemail'],
8487: $udom,$uname)
8488: };
1.162 raeburn 8489: }
8490: } else {
8491: %srch_results = &Apache::lonnet::usersearch($srch);
1.179 raeburn 8492: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8493: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 8494: }
8495: } else {
1.167 albertel 8496: my $courseusers = &get_courseusers();
1.162 raeburn 8497: if ($srch->{'srchtype'} eq 'exact') {
1.167 albertel 8498: if (exists($courseusers->{$srch->{'srchterm'}.':'.$srch->{'srchdomain'}})) {
1.179 raeburn 8499: $currstate = 'modify';
1.162 raeburn 8500: } else {
1.179 raeburn 8501: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8502: &build_search_response($context,$srch,%srch_results);
1.162 raeburn 8503: }
1.160 raeburn 8504: } else {
1.167 albertel 8505: foreach my $user (keys(%$courseusers)) {
1.162 raeburn 8506: my ($cuname,$cudomain) = split(/:/,$user);
8507: if ($cudomain eq $srch->{'srchdomain'}) {
1.177 raeburn 8508: my $matched = 0;
8509: if ($srch->{'srchtype'} eq 'begins') {
8510: if ($cuname =~ /^\Q$srch->{'srchterm'}\E/i) {
8511: $matched = 1;
8512: }
8513: } else {
8514: if ($cuname =~ /\Q$srch->{'srchterm'}\E/i) {
8515: $matched = 1;
8516: }
8517: }
8518: if ($matched) {
1.167 albertel 8519: $srch_results{$user} =
8520: {&Apache::lonnet::get('environment',
8521: ['firstname',
8522: 'lastname',
1.194 albertel 8523: 'permanentemail'],
8524: $cudomain,$cuname)};
1.162 raeburn 8525: }
8526: }
8527: }
1.179 raeburn 8528: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8529: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 8530: }
8531: }
8532: }
8533: } elsif ($srch->{'srchin'} eq 'alc') {
1.179 raeburn 8534: $currstate = 'query';
1.160 raeburn 8535: } elsif ($srch->{'srchin'} eq 'instd') {
1.181 raeburn 8536: ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
8537: if ($dirsrchres eq 'ok') {
8538: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8539: &build_search_response($context,$srch,%srch_results);
1.181 raeburn 8540: } else {
8541: my $showdom = &display_domain_info($srch->{'srchdomain'});
8542: $response = '<span class="LC_warning">'.
8543: &mt('Institutional directory search is not available in domain: [_1]',$showdom).
8544: '</span><br />'.
8545: &mt('You may want to search in the LON-CAPA domain instead of the institutional directory.').
1.406.2.5 raeburn 8546: '<br />';
1.181 raeburn 8547: }
1.160 raeburn 8548: }
8549: } else {
8550: if ($srch->{'srchin'} eq 'dom') {
8551: %srch_results = &Apache::lonnet::usersearch($srch);
1.179 raeburn 8552: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8553: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 8554: } elsif ($srch->{'srchin'} eq 'crs') {
1.167 albertel 8555: my $courseusers = &get_courseusers();
8556: foreach my $user (keys(%$courseusers)) {
1.160 raeburn 8557: my ($uname,$udom) = split(/:/,$user);
8558: my %names = &Apache::loncommon::getnames($uname,$udom);
8559: my %emails = &Apache::loncommon::getemails($uname,$udom);
8560: if ($srch->{'srchby'} eq 'lastname') {
8561: if ((($srch->{'srchtype'} eq 'exact') &&
8562: ($names{'lastname'} eq $srch->{'srchterm'})) ||
1.177 raeburn 8563: (($srch->{'srchtype'} eq 'begins') &&
8564: ($names{'lastname'} =~ /^\Q$srch->{'srchterm'}\E/i)) ||
1.160 raeburn 8565: (($srch->{'srchtype'} eq 'contains') &&
8566: ($names{'lastname'} =~ /\Q$srch->{'srchterm'}\E/i))) {
8567: $srch_results{$user} = {firstname => $names{'firstname'},
8568: lastname => $names{'lastname'},
8569: permanentemail => $emails{'permanentemail'},
8570: };
8571: }
8572: } elsif ($srch->{'srchby'} eq 'lastfirst') {
8573: my ($srchlast,$srchfirst) = split(/,/,$srch->{'srchterm'});
1.177 raeburn 8574: $srchlast =~ s/\s+$//;
8575: $srchfirst =~ s/^\s+//;
1.160 raeburn 8576: if ($srch->{'srchtype'} eq 'exact') {
8577: if (($names{'lastname'} eq $srchlast) &&
8578: ($names{'firstname'} eq $srchfirst)) {
8579: $srch_results{$user} = {firstname => $names{'firstname'},
8580: lastname => $names{'lastname'},
8581: permanentemail => $emails{'permanentemail'},
8582:
8583: };
8584: }
1.177 raeburn 8585: } elsif ($srch->{'srchtype'} eq 'begins') {
8586: if (($names{'lastname'} =~ /^\Q$srchlast\E/i) &&
8587: ($names{'firstname'} =~ /^\Q$srchfirst\E/i)) {
8588: $srch_results{$user} = {firstname => $names{'firstname'},
8589: lastname => $names{'lastname'},
8590: permanentemail => $emails{'permanentemail'},
8591: };
8592: }
8593: } else {
1.160 raeburn 8594: if (($names{'lastname'} =~ /\Q$srchlast\E/i) &&
8595: ($names{'firstname'} =~ /\Q$srchfirst\E/i)) {
8596: $srch_results{$user} = {firstname => $names{'firstname'},
8597: lastname => $names{'lastname'},
8598: permanentemail => $emails{'permanentemail'},
8599: };
8600: }
8601: }
8602: }
8603: }
1.179 raeburn 8604: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8605: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 8606: } elsif ($srch->{'srchin'} eq 'alc') {
1.179 raeburn 8607: $currstate = 'query';
1.160 raeburn 8608: } elsif ($srch->{'srchin'} eq 'instd') {
1.181 raeburn 8609: ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
8610: if ($dirsrchres eq 'ok') {
8611: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8612: &build_search_response($context,$srch,%srch_results);
1.181 raeburn 8613: } else {
1.406.2.5 raeburn 8614: my $showdom = &display_domain_info($srch->{'srchdomain'});
8615: $response = '<span class="LC_warning">'.
1.181 raeburn 8616: &mt('Institutional directory search is not available in domain: [_1]',$showdom).
8617: '</span><br />'.
8618: &mt('You may want to search in the LON-CAPA domain instead of the institutional directory.').
1.406.2.5 raeburn 8619: '<br />';
1.181 raeburn 8620: }
1.160 raeburn 8621: }
8622: }
1.179 raeburn 8623: return ($currstate,$response,$forcenewuser,\%srch_results);
1.160 raeburn 8624: }
8625:
1.406.2.3 raeburn 8626: sub domdirectorysrch_check {
8627: my ($srch) = @_;
8628: my $response;
8629: my %dom_inst_srch = &Apache::lonnet::get_dom('configuration',
8630: ['directorysrch'],$srch->{'srchdomain'});
8631: my $showdom = &display_domain_info($srch->{'srchdomain'});
8632: if (ref($dom_inst_srch{'directorysrch'}) eq 'HASH') {
8633: if ($dom_inst_srch{'directorysrch'}{'lcavailable'} eq '0') {
8634: return &mt('LON-CAPA directory search is not available in domain: [_1]',$showdom);
8635: }
8636: if ($dom_inst_srch{'directorysrch'}{'lclocalonly'}) {
8637: if ($env{'request.role.domain'} ne $srch->{'srchdomain'}) {
8638: return &mt('LON-CAPA directory search in domain: [_1] is only allowed for users with a current role in the domain.',$showdom);
8639: }
8640: }
8641: }
8642: return 'ok';
8643: }
8644:
8645: sub instdirectorysrch_check {
1.160 raeburn 8646: my ($srch) = @_;
8647: my $can_search = 0;
8648: my $response;
8649: my %dom_inst_srch = &Apache::lonnet::get_dom('configuration',
8650: ['directorysrch'],$srch->{'srchdomain'});
1.180 raeburn 8651: my $showdom = &display_domain_info($srch->{'srchdomain'});
1.160 raeburn 8652: if (ref($dom_inst_srch{'directorysrch'}) eq 'HASH') {
8653: if (!$dom_inst_srch{'directorysrch'}{'available'}) {
1.180 raeburn 8654: return &mt('Institutional directory search is not available in domain: [_1]',$showdom);
1.160 raeburn 8655: }
8656: if ($dom_inst_srch{'directorysrch'}{'localonly'}) {
8657: if ($env{'request.role.domain'} ne $srch->{'srchdomain'}) {
1.180 raeburn 8658: return &mt('Institutional directory search in domain: [_1] is only allowed for users with a current role in the domain.',$showdom);
1.160 raeburn 8659: }
8660: my @usertypes = split(/:/,$env{'environment.inststatus'});
8661: if (!@usertypes) {
8662: push(@usertypes,'default');
8663: }
8664: if (ref($dom_inst_srch{'directorysrch'}{'cansearch'}) eq 'ARRAY') {
8665: foreach my $type (@usertypes) {
8666: if (grep(/^\Q$type\E$/,@{$dom_inst_srch{'directorysrch'}{'cansearch'}})) {
8667: $can_search = 1;
8668: last;
8669: }
8670: }
8671: }
8672: if (!$can_search) {
8673: my ($insttypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($srch->{'srchdomain'});
8674: my @longtypes;
8675: foreach my $item (@usertypes) {
1.229 raeburn 8676: if (defined($insttypes->{$item})) {
8677: push (@longtypes,$insttypes->{$item});
8678: } elsif ($item eq 'default') {
8679: push (@longtypes,&mt('other'));
8680: }
1.160 raeburn 8681: }
8682: my $insttype_str = join(', ',@longtypes);
1.180 raeburn 8683: return &mt('Institutional directory search in domain: [_1] is not available to your user type: ',$showdom).$insttype_str;
1.229 raeburn 8684: }
1.160 raeburn 8685: } else {
8686: $can_search = 1;
8687: }
8688: } else {
1.180 raeburn 8689: return &mt('Institutional directory search has not been configured for domain: [_1]',$showdom);
1.160 raeburn 8690: }
8691: my %longtext = &Apache::lonlocal::texthash (
1.167 albertel 8692: uname => 'username',
1.160 raeburn 8693: lastfirst => 'last name, first name',
1.167 albertel 8694: lastname => 'last name',
1.172 raeburn 8695: contains => 'contains',
1.178 raeburn 8696: exact => 'as exact match to',
8697: begins => 'begins with',
1.160 raeburn 8698: );
8699: if ($can_search) {
8700: if (ref($dom_inst_srch{'directorysrch'}{'searchby'}) eq 'ARRAY') {
8701: if (!grep(/^\Q$srch->{'srchby'}\E$/,@{$dom_inst_srch{'directorysrch'}{'searchby'}})) {
1.180 raeburn 8702: return &mt('Institutional directory search in domain: [_1] is not available for searching by "[_2]"',$showdom,$longtext{$srch->{'srchby'}});
1.160 raeburn 8703: }
8704: } else {
1.180 raeburn 8705: return &mt('Institutional directory search in domain: [_1] is not available.', $showdom);
1.160 raeburn 8706: }
8707: }
8708: if ($can_search) {
1.178 raeburn 8709: if (ref($dom_inst_srch{'directorysrch'}{'searchtypes'}) eq 'ARRAY') {
8710: if (grep(/^\Q$srch->{'srchtype'}\E/,@{$dom_inst_srch{'directorysrch'}{'searchtypes'}})) {
8711: return 'ok';
8712: } else {
1.180 raeburn 8713: return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
1.178 raeburn 8714: }
8715: } else {
8716: if ((($dom_inst_srch{'directorysrch'}{'searchtypes'} eq 'specify') &&
8717: ($srch->{'srchtype'} eq 'exact' || $srch->{'srchtype'} eq 'contains')) ||
8718: ($dom_inst_srch{'directorysrch'}{'searchtypes'} eq $srch->{'srchtype'})) {
8719: return 'ok';
8720: } else {
1.180 raeburn 8721: return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
1.178 raeburn 8722: }
1.160 raeburn 8723: }
8724: }
8725: }
8726:
8727: sub get_courseusers {
8728: my %advhash;
1.167 albertel 8729: my $classlist = &Apache::loncoursedata::get_classlist();
1.160 raeburn 8730: my %coursepersonnel=&Apache::lonnet::get_course_adv_roles();
8731: foreach my $role (sort(keys(%coursepersonnel))) {
8732: foreach my $user (split(/\,/,$coursepersonnel{$role})) {
1.167 albertel 8733: if (!exists($classlist->{$user})) {
8734: $classlist->{$user} = [];
8735: }
1.160 raeburn 8736: }
8737: }
1.167 albertel 8738: return $classlist;
1.160 raeburn 8739: }
8740:
8741: sub build_search_response {
1.221 raeburn 8742: my ($context,$srch,%srch_results) = @_;
1.179 raeburn 8743: my ($currstate,$response,$forcenewuser);
1.160 raeburn 8744: my %names = (
1.330 bisitz 8745: 'uname' => 'username',
8746: 'lastname' => 'last name',
1.160 raeburn 8747: 'lastfirst' => 'last name, first name',
1.330 bisitz 8748: 'crs' => 'this course',
8749: 'dom' => 'LON-CAPA domain',
8750: 'instd' => 'the institutional directory for domain',
1.160 raeburn 8751: );
8752:
8753: my %single = (
1.180 raeburn 8754: begins => 'A match',
1.160 raeburn 8755: contains => 'A match',
1.180 raeburn 8756: exact => 'An exact match',
1.160 raeburn 8757: );
8758: my %nomatch = (
1.180 raeburn 8759: begins => 'No match',
1.160 raeburn 8760: contains => 'No match',
1.180 raeburn 8761: exact => 'No exact match',
1.160 raeburn 8762: );
8763: if (keys(%srch_results) > 1) {
1.179 raeburn 8764: $currstate = 'select';
1.160 raeburn 8765: } else {
8766: if (keys(%srch_results) == 1) {
1.406.2.5 raeburn 8767: if ($env{'form.action'} eq 'accesslogs') {
8768: $currstate = 'activity';
8769: } else {
8770: $currstate = 'modify';
8771: }
1.180 raeburn 8772: $response = &mt("$single{$srch->{'srchtype'}} was found for the $names{$srch->{'srchby'}} ([_1]) in $names{$srch->{'srchin'}}.",$srch->{'srchterm'});
8773: if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
1.330 bisitz 8774: $response .= ': '.&display_domain_info($srch->{'srchdomain'});
1.180 raeburn 8775: }
1.330 bisitz 8776: } else { # Search has nothing found. Prepare message to user.
8777: $response = '<span class="LC_warning">';
1.180 raeburn 8778: if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
1.330 bisitz 8779: $response .= &mt("$nomatch{$srch->{'srchtype'}} found for the $names{$srch->{'srchby'}} [_1] in $names{$srch->{'srchin'}}: [_2]",
8780: '<b>'.$srch->{'srchterm'}.'</b>',
8781: &display_domain_info($srch->{'srchdomain'}));
8782: } else {
8783: $response .= &mt("$nomatch{$srch->{'srchtype'}} found for the $names{$srch->{'srchby'}} [_1] in $names{$srch->{'srchin'}}.",
8784: '<b>'.$srch->{'srchterm'}.'</b>');
1.180 raeburn 8785: }
8786: $response .= '</span>';
1.330 bisitz 8787:
1.160 raeburn 8788: if ($srch->{'srchin'} ne 'alc') {
8789: $forcenewuser = 1;
8790: my $cansrchinst = 0;
1.406.2.14 raeburn 8791: if (($srch->{'srchdomain'}) && ($env{'form.action'} ne 'accesslogs')) {
1.160 raeburn 8792: my %domconfig = &Apache::lonnet::get_dom('configuration',['directorysrch'],$srch->{'srchdomain'});
8793: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
8794: if ($domconfig{'directorysrch'}{'available'}) {
8795: $cansrchinst = 1;
8796: }
8797: }
8798: }
1.180 raeburn 8799: if ((($srch->{'srchby'} eq 'lastfirst') ||
8800: ($srch->{'srchby'} eq 'lastname')) &&
8801: ($srch->{'srchin'} eq 'dom')) {
8802: if ($cansrchinst) {
8803: $response .= '<br />'.&mt('You may want to broaden your search to a search of the institutional directory for the domain.');
1.160 raeburn 8804: }
8805: }
1.180 raeburn 8806: if ($srch->{'srchin'} eq 'crs') {
8807: $response .= '<br />'.&mt('You may want to broaden your search to the selected LON-CAPA domain.');
8808: }
8809: }
1.305 raeburn 8810: my $createdom = $env{'request.role.domain'};
8811: if ($context eq 'requestcrs') {
8812: if ($env{'form.coursedom'} ne '') {
8813: $createdom = $env{'form.coursedom'};
8814: }
8815: }
1.406.2.5 raeburn 8816: unless (($env{'form.action'} eq 'accesslogs') || (($srch->{'srchby'} eq 'uname') && ($srch->{'srchin'} eq 'dom') &&
8817: ($srch->{'srchtype'} eq 'exact') && ($srch->{'srchdomain'} eq $createdom))) {
1.221 raeburn 8818: my $cancreate =
1.305 raeburn 8819: &Apache::lonuserutils::can_create_user($createdom,$context);
8820: my $targetdom = '<span class="LC_cusr_emph">'.$createdom.'</span>';
1.221 raeburn 8821: if ($cancreate) {
1.305 raeburn 8822: my $showdom = &display_domain_info($createdom);
1.266 bisitz 8823: $response .= '<br /><br />'
8824: .'<b>'.&mt('To add a new user:').'</b>'
1.305 raeburn 8825: .'<br />';
8826: if ($context eq 'requestcrs') {
8827: $response .= &mt("(You can only define new users in the new course's domain - [_1])",$targetdom);
8828: } else {
8829: $response .= &mt("(You can only create new users in your current role's domain - [_1])",$targetdom);
8830: }
8831: $response .='<ul><li>'
1.266 bisitz 8832: .&mt("Set 'Domain/institution to search' to: [_1]",'<span class="LC_cusr_emph">'.$showdom.'</span>')
8833: .'</li><li>'
8834: .&mt("Set 'Search criteria' to: [_1]username is ..... in selected LON-CAPA domain[_2]",'<span class="LC_cusr_emph">','</span>')
8835: .'</li><li>'
8836: .&mt('Provide the proposed username')
8837: .'</li><li>'
8838: .&mt("Click 'Search'")
8839: .'</li></ul><br />';
1.221 raeburn 8840: } else {
1.406.2.7 raeburn 8841: unless (($context eq 'domain') && ($env{'form.action'} eq 'singleuser')) {
8842: my $helplink = ' href="javascript:helpMenu('."'display'".')"';
8843: $response .= '<br /><br />';
8844: if ($context eq 'requestcrs') {
8845: $response .= &mt("You are not authorized to define new users in the new course's domain - [_1].",$targetdom);
8846: } else {
8847: $response .= &mt("You are not authorized to create new users in your current role's domain - [_1].",$targetdom);
8848: }
8849: $response .= '<br />'
8850: .&mt('Please contact the [_1]helpdesk[_2] if you need to create a new user.'
8851: ,' <a'.$helplink.'>'
8852: ,'</a>')
8853: .'<br />';
1.305 raeburn 8854: }
1.221 raeburn 8855: }
1.160 raeburn 8856: }
8857: }
8858: }
1.179 raeburn 8859: return ($currstate,$response,$forcenewuser);
1.160 raeburn 8860: }
8861:
1.180 raeburn 8862: sub display_domain_info {
8863: my ($dom) = @_;
8864: my $output = $dom;
8865: if ($dom ne '') {
8866: my $domdesc = &Apache::lonnet::domain($dom,'description');
8867: if ($domdesc ne '') {
8868: $output .= ' <span class="LC_cusr_emph">('.$domdesc.')</span>';
8869: }
8870: }
8871: return $output;
8872: }
8873:
1.160 raeburn 8874: sub crumb_utilities {
8875: my %elements = (
8876: crtuser => {
8877: srchterm => 'text',
1.172 raeburn 8878: srchin => 'selectbox',
1.160 raeburn 8879: srchby => 'selectbox',
8880: srchtype => 'selectbox',
8881: srchdomain => 'selectbox',
8882: },
1.207 raeburn 8883: crtusername => {
8884: srchterm => 'text',
8885: srchdomain => 'selectbox',
8886: },
1.160 raeburn 8887: docustom => {
8888: rolename => 'selectbox',
8889: newrolename => 'textbox',
8890: },
1.179 raeburn 8891: studentform => {
8892: srchterm => 'text',
8893: srchin => 'selectbox',
8894: srchby => 'selectbox',
8895: srchtype => 'selectbox',
8896: srchdomain => 'selectbox',
8897: },
1.160 raeburn 8898: );
8899:
8900: my $jsback .= qq|
8901: function backPage(formname,prevphase,prevstate) {
1.211 raeburn 8902: if (typeof prevphase == 'undefined') {
8903: formname.phase.value = '';
8904: }
8905: else {
8906: formname.phase.value = prevphase;
8907: }
8908: if (typeof prevstate == 'undefined') {
8909: formname.currstate.value = '';
8910: }
8911: else {
8912: formname.currstate.value = prevstate;
8913: }
1.160 raeburn 8914: formname.submit();
8915: }
8916: |;
8917: return ($jsback,\%elements);
8918: }
8919:
1.26 matthew 8920: sub course_level_table {
1.375 raeburn 8921: my ($inccourses,$showcredits,$defaultcredits) = @_;
8922: return unless (ref($inccourses) eq 'HASH');
1.26 matthew 8923: my $table = '';
1.62 www 8924: # Custom Roles?
8925:
1.190 raeburn 8926: my %customroles=&Apache::lonuserutils::my_custom_roles();
1.89 raeburn 8927: my %lt=&Apache::lonlocal::texthash(
8928: 'exs' => "Existing sections",
8929: 'new' => "Define new section",
8930: 'ssd' => "Set Start Date",
8931: 'sed' => "Set End Date",
1.131 raeburn 8932: 'crl' => "Course Level",
1.89 raeburn 8933: 'act' => "Activate",
8934: 'rol' => "Role",
8935: 'ext' => "Extent",
1.113 raeburn 8936: 'grs' => "Section",
1.375 raeburn 8937: 'crd' => "Credits",
1.89 raeburn 8938: 'sta' => "Start",
8939: 'end' => "End"
8940: );
1.62 www 8941:
1.375 raeburn 8942: foreach my $protectedcourse (sort(keys(%{$inccourses}))) {
1.135 raeburn 8943: my $thiscourse=$protectedcourse;
1.26 matthew 8944: $thiscourse=~s:_:/:g;
8945: my %coursedata=&Apache::lonnet::coursedescription($thiscourse);
1.365 raeburn 8946: my $isowner = &Apache::lonuserutils::is_courseowner($protectedcourse,$coursedata{'internal.courseowner'});
1.26 matthew 8947: my $area=$coursedata{'description'};
1.321 raeburn 8948: my $crstype=$coursedata{'type'};
1.135 raeburn 8949: if (!defined($area)) { $area=&mt('Unavailable course').': '.$protectedcourse; }
1.89 raeburn 8950: my ($domain,$cnum)=split(/\//,$thiscourse);
1.115 albertel 8951: my %sections_count;
1.101 albertel 8952: if (defined($env{'request.course.id'})) {
8953: if ($env{'request.course.id'} eq $domain.'_'.$cnum) {
1.115 albertel 8954: %sections_count =
8955: &Apache::loncommon::get_sections($domain,$cnum);
1.92 raeburn 8956: }
8957: }
1.321 raeburn 8958: my @roles = &Apache::lonuserutils::roles_by_context('course','',$crstype);
1.213 raeburn 8959: foreach my $role (@roles) {
1.321 raeburn 8960: my $plrole=&Apache::lonnet::plaintext($role,$crstype);
1.329 raeburn 8961: if ((&Apache::lonnet::allowed('c'.$role,$thiscourse)) ||
8962: ((($role eq 'cc') || ($role eq 'co')) && ($isowner))) {
1.221 raeburn 8963: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
1.375 raeburn 8964: $plrole,\%sections_count,\%lt,
1.402 raeburn 8965: $showcredits,$defaultcredits,$crstype);
1.221 raeburn 8966: } elsif ($env{'request.course.sec'} ne '') {
8967: if (&Apache::lonnet::allowed('c'.$role,$thiscourse.'/'.
8968: $env{'request.course.sec'})) {
8969: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
1.375 raeburn 8970: $plrole,\%sections_count,\%lt,
1.402 raeburn 8971: $showcredits,$defaultcredits,$crstype);
1.26 matthew 8972: }
8973: }
8974: }
1.221 raeburn 8975: if (&Apache::lonnet::allowed('ccr',$thiscourse)) {
1.324 raeburn 8976: foreach my $cust (sort(keys(%customroles))) {
8977: next if ($crstype eq 'Community' && $customroles{$cust} =~ /bre\&S/);
1.221 raeburn 8978: my $role = 'cr_cr_'.$env{'user.domain'}.'_'.$env{'user.name'}.'_'.$cust;
8979: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
1.402 raeburn 8980: $cust,\%sections_count,\%lt,
8981: $showcredits,$defaultcredits,$crstype);
1.221 raeburn 8982: }
1.62 www 8983: }
1.26 matthew 8984: }
8985: return '' if ($table eq ''); # return nothing if there is nothing
8986: # in the table
1.188 raeburn 8987: my $result;
8988: if (!$env{'request.course.id'}) {
8989: $result = '<h4>'.$lt{'crl'}.'</h4>'."\n";
8990: }
8991: $result .=
1.136 raeburn 8992: &Apache::loncommon::start_data_table().
8993: &Apache::loncommon::start_data_table_header_row().
1.375 raeburn 8994: '<th>'.$lt{'act'}.'</th><th>'.$lt{'rol'}.'</th>'."\n".
1.402 raeburn 8995: '<th>'.$lt{'ext'}.'</th><th>'."\n";
8996: if ($showcredits) {
8997: $result .= $lt{'crd'}.'</th>';
8998: }
8999: $result .=
1.375 raeburn 9000: '<th>'.$lt{'grs'}.'</th><th>'.$lt{'sta'}.'</th>'."\n".
9001: '<th>'.$lt{'end'}.'</th>'.
1.136 raeburn 9002: &Apache::loncommon::end_data_table_header_row().
9003: $table.
9004: &Apache::loncommon::end_data_table();
1.26 matthew 9005: return $result;
9006: }
1.88 raeburn 9007:
1.221 raeburn 9008: sub course_level_row {
1.375 raeburn 9009: my ($protectedcourse,$role,$area,$domain,$plrole,$sections_count,
1.402 raeburn 9010: $lt,$showcredits,$defaultcredits,$crstype) = @_;
1.375 raeburn 9011: my $creditem;
1.222 raeburn 9012: my $row = &Apache::loncommon::start_data_table_row().
9013: ' <td><input type="checkbox" name="act_'.
9014: $protectedcourse.'_'.$role.'" /></td>'."\n".
9015: ' <td>'.$plrole.'</td>'."\n".
9016: ' <td>'.$area.'<br />Domain: '.$domain.'</td>'."\n";
1.402 raeburn 9017: if (($showcredits) && ($role eq 'st') && ($crstype eq 'Course')) {
1.375 raeburn 9018: $row .=
9019: '<td><input type="text" name="credits_'.$protectedcourse.'_'.
9020: $role.'" size="3" value="'.$defaultcredits.'" /></td>';
9021: } else {
9022: $row .= '<td> </td>';
9023: }
1.322 raeburn 9024: if (($role eq 'cc') || ($role eq 'co')) {
1.222 raeburn 9025: $row .= '<td> </td>';
1.221 raeburn 9026: } elsif ($env{'request.course.sec'} ne '') {
1.222 raeburn 9027: $row .= ' <td><input type="hidden" value="'.
9028: $env{'request.course.sec'}.'" '.
9029: 'name="sec_'.$protectedcourse.'_'.$role.'" />'.
9030: $env{'request.course.sec'}.'</td>';
1.221 raeburn 9031: } else {
9032: if (ref($sections_count) eq 'HASH') {
9033: my $currsec =
9034: &Apache::lonuserutils::course_sections($sections_count,
9035: $protectedcourse.'_'.$role);
1.222 raeburn 9036: $row .= '<td><table class="LC_createuser">'."\n".
9037: '<tr class="LC_section_row">'."\n".
9038: ' <td valign="top">'.$lt->{'exs'}.'<br />'.
9039: $currsec.'</td>'."\n".
9040: ' <td> </td>'."\n".
9041: ' <td valign="top"> '.$lt->{'new'}.'<br />'.
1.221 raeburn 9042: '<input type="text" name="newsec_'.$protectedcourse.'_'.$role.
9043: '" value="" />'.
9044: '<input type="hidden" '.
9045: 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'."\n".
1.222 raeburn 9046: '</tr></table></td>'."\n";
1.221 raeburn 9047: } else {
1.222 raeburn 9048: $row .= '<td><input type="text" size="10" '.
1.375 raeburn 9049: 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'."\n";
1.221 raeburn 9050: }
9051: }
1.222 raeburn 9052: $row .= <<ENDTIMEENTRY;
9053: <td><input type="hidden" name="start_$protectedcourse\_$role" value="" />
1.221 raeburn 9054: <a href=
9055: "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 9056: <td><input type="hidden" name="end_$protectedcourse\_$role" value="" />
1.221 raeburn 9057: <a href=
9058: "javascript:pjump('date_end','End Date $plrole',document.cu.end_$protectedcourse\_$role.value,'end_$protectedcourse\_$role','cu.pres','dateset')">$lt->{'sed'}</a></td>
9059: ENDTIMEENTRY
1.222 raeburn 9060: $row .= &Apache::loncommon::end_data_table_row();
9061: return $row;
1.221 raeburn 9062: }
9063:
1.88 raeburn 9064: sub course_level_dc {
1.375 raeburn 9065: my ($dcdom,$showcredits) = @_;
1.190 raeburn 9066: my %customroles=&Apache::lonuserutils::my_custom_roles();
1.213 raeburn 9067: my @roles = &Apache::lonuserutils::roles_by_context('course');
1.88 raeburn 9068: my $hiddenitems = '<input type="hidden" name="dcdomain" value="'.$dcdom.'" />'.
9069: '<input type="hidden" name="origdom" value="'.$dcdom.'" />'.
1.133 raeburn 9070: '<input type="hidden" name="dccourse" value="" />';
1.355 www 9071: my $courseform=&Apache::loncommon::selectcourse_link
1.356 raeburn 9072: ('cu','dccourse','dcdomain','coursedesc',undef,undef,'Select','crstype');
1.375 raeburn 9073: my $credit_elem;
9074: if ($showcredits) {
9075: $credit_elem = 'credits';
9076: }
9077: my $cb_jscript = &Apache::loncommon::coursebrowser_javascript($dcdom,'currsec','cu','role','Course/Community Browser',$credit_elem);
1.88 raeburn 9078: my %lt=&Apache::lonlocal::texthash(
9079: 'rol' => "Role",
1.113 raeburn 9080: 'grs' => "Section",
1.88 raeburn 9081: 'exs' => "Existing sections",
9082: 'new' => "Define new section",
9083: 'sta' => "Start",
9084: 'end' => "End",
9085: 'ssd' => "Set Start Date",
1.355 www 9086: 'sed' => "Set End Date",
1.375 raeburn 9087: 'scc' => "Course/Community",
9088: 'crd' => "Credits",
1.88 raeburn 9089: );
1.323 raeburn 9090: my $header = '<h4>'.&mt('Course/Community Level').'</h4>'.
1.136 raeburn 9091: &Apache::loncommon::start_data_table().
9092: &Apache::loncommon::start_data_table_header_row().
1.375 raeburn 9093: '<th>'.$lt{'scc'}.'</th><th>'.$lt{'rol'}.'</th>'."\n".
1.397 bisitz 9094: '<th>'.$lt{'grs'}.'</th>'."\n";
9095: $header .= '<th>'.$lt{'crd'}.'</th>'."\n" if ($showcredits);
9096: $header .= '<th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'."\n".
1.136 raeburn 9097: &Apache::loncommon::end_data_table_header_row();
1.143 raeburn 9098: my $otheritems = &Apache::loncommon::start_data_table_row()."\n".
1.356 raeburn 9099: '<td><br /><span class="LC_nobreak"><input type="text" name="coursedesc" value="" onfocus="this.blur();opencrsbrowser('."'cu','dccourse','dcdomain','coursedesc','','','','crstype'".')" />'.
9100: $courseform.(' ' x4).'</span></td>'."\n".
1.389 bisitz 9101: '<td valign="top"><br /><select name="role">'."\n";
1.213 raeburn 9102: foreach my $role (@roles) {
1.135 raeburn 9103: my $plrole=&Apache::lonnet::plaintext($role);
1.389 bisitz 9104: $otheritems .= ' <option value="'.$role.'">'.$plrole.'</option>';
1.88 raeburn 9105: }
1.404 raeburn 9106: if ( keys(%customroles) > 0) {
9107: foreach my $cust (sort(keys(%customroles))) {
1.101 albertel 9108: my $custrole='cr_cr_'.$env{'user.domain'}.
1.135 raeburn 9109: '_'.$env{'user.name'}.'_'.$cust;
1.389 bisitz 9110: $otheritems .= ' <option value="'.$custrole.'">'.$cust.'</option>';
1.88 raeburn 9111: }
9112: }
9113: $otheritems .= '</select></td><td>'.
9114: '<table border="0" cellspacing="0" cellpadding="0">'.
9115: '<tr><td valign="top"><b>'.$lt{'exs'}.'</b><br /><select name="currsec">'.
1.389 bisitz 9116: ' <option value=""><--'.&mt('Pick course first').'</option></select></td>'.
1.88 raeburn 9117: '<td> </td>'.
9118: '<td valign="top"> <b>'.$lt{'new'}.'</b><br />'.
1.113 raeburn 9119: '<input type="text" name="newsec" value="" />'.
1.237 raeburn 9120: '<input type="hidden" name="section" value="" />'.
1.323 raeburn 9121: '<input type="hidden" name="groups" value="" />'.
9122: '<input type="hidden" name="crstype" value="" /></td>'.
1.375 raeburn 9123: '</tr></table></td>'."\n";
9124: if ($showcredits) {
9125: $otheritems .= '<td><br />'."\n".
1.397 bisitz 9126: '<input type="text" size="3" name="credits" value="" /></td>'."\n";
1.375 raeburn 9127: }
1.88 raeburn 9128: $otheritems .= <<ENDTIMEENTRY;
1.323 raeburn 9129: <td><br /><input type="hidden" name="start" value='' />
1.88 raeburn 9130: <a href=
9131: "javascript:pjump('date_start','Start Date',document.cu.start.value,'start','cu.pres','dateset')">$lt{'ssd'}</a></td>
1.323 raeburn 9132: <td><br /><input type="hidden" name="end" value='' />
1.88 raeburn 9133: <a href=
9134: "javascript:pjump('date_end','End Date',document.cu.end.value,'end','cu.pres','dateset')">$lt{'sed'}</a></td>
9135: ENDTIMEENTRY
1.136 raeburn 9136: $otheritems .= &Apache::loncommon::end_data_table_row().
9137: &Apache::loncommon::end_data_table()."\n";
1.88 raeburn 9138: return $cb_jscript.$header.$hiddenitems.$otheritems;
9139: }
9140:
1.237 raeburn 9141: sub update_selfenroll_config {
1.400 raeburn 9142: my ($r,$cid,$cdom,$cnum,$context,$crstype,$currsettings) = @_;
1.398 raeburn 9143: return unless (ref($currsettings) eq 'HASH');
9144: my ($row,$lt) = &Apache::lonuserutils::get_selfenroll_titles();
9145: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
1.237 raeburn 9146: my (%changes,%warning);
1.241 raeburn 9147: my $curr_types;
1.400 raeburn 9148: my %noedit;
9149: unless ($context eq 'domain') {
9150: %noedit = &get_noedit_fields($cdom,$cnum,$crstype,$row);
9151: }
1.237 raeburn 9152: if (ref($row) eq 'ARRAY') {
9153: foreach my $item (@{$row}) {
1.400 raeburn 9154: next if ($noedit{$item});
1.237 raeburn 9155: if ($item eq 'enroll_dates') {
9156: my (%currenrolldate,%newenrolldate);
9157: foreach my $type ('start','end') {
1.398 raeburn 9158: $currenrolldate{$type} = $currsettings->{'selfenroll_'.$type.'_date'};
1.237 raeburn 9159: $newenrolldate{$type} = &Apache::lonhtmlcommon::get_date_from_form('selfenroll_'.$type.'_date');
9160: if ($newenrolldate{$type} ne $currenrolldate{$type}) {
9161: $changes{'internal.selfenroll_'.$type.'_date'} = $newenrolldate{$type};
9162: }
9163: }
9164: } elsif ($item eq 'access_dates') {
9165: my (%currdate,%newdate);
9166: foreach my $type ('start','end') {
1.398 raeburn 9167: $currdate{$type} = $currsettings->{'selfenroll_'.$type.'_access'};
1.237 raeburn 9168: $newdate{$type} = &Apache::lonhtmlcommon::get_date_from_form('selfenroll_'.$type.'_access');
9169: if ($newdate{$type} ne $currdate{$type}) {
9170: $changes{'internal.selfenroll_'.$type.'_access'} = $newdate{$type};
9171: }
9172: }
1.241 raeburn 9173: } elsif ($item eq 'types') {
1.398 raeburn 9174: $curr_types = $currsettings->{'selfenroll_'.$item};
1.241 raeburn 9175: if ($env{'form.selfenroll_all'}) {
9176: if ($curr_types ne '*') {
9177: $changes{'internal.selfenroll_types'} = '*';
9178: } else {
9179: next;
9180: }
9181: } else {
1.249 raeburn 9182: my %currdoms;
1.241 raeburn 9183: my @entries = split(/;/,$curr_types);
9184: my @deletedoms = &Apache::loncommon::get_env_multiple('form.selfenroll_delete');
1.249 raeburn 9185: my @activations = &Apache::loncommon::get_env_multiple('form.selfenroll_activate');
1.241 raeburn 9186: my $newnum = 0;
1.249 raeburn 9187: my @latesttypes;
9188: foreach my $num (@activations) {
9189: my @types = &Apache::loncommon::get_env_multiple('form.selfenroll_types_'.$num);
9190: if (@types > 0) {
1.241 raeburn 9191: @types = sort(@types);
9192: my $typestr = join(',',@types);
1.249 raeburn 9193: my $typedom = $env{'form.selfenroll_dom_'.$num};
9194: $latesttypes[$newnum] = $typedom.':'.$typestr;
9195: $currdoms{$typedom} = 1;
1.241 raeburn 9196: $newnum ++;
9197: }
9198: }
1.338 raeburn 9199: for (my $j=0; $j<$env{'form.selfenroll_types_total'}; $j++) {
9200: if ((!grep(/^$j$/,@deletedoms)) && (!grep(/^$j$/,@activations))) {
1.249 raeburn 9201: my @types = &Apache::loncommon::get_env_multiple('form.selfenroll_types_'.$j);
9202: if (@types > 0) {
9203: @types = sort(@types);
9204: my $typestr = join(',',@types);
9205: my $typedom = $env{'form.selfenroll_dom_'.$j};
9206: $latesttypes[$newnum] = $typedom.':'.$typestr;
9207: $currdoms{$typedom} = 1;
9208: $newnum ++;
9209: }
9210: }
9211: }
9212: if ($env{'form.selfenroll_newdom'} ne '') {
9213: my $typedom = $env{'form.selfenroll_newdom'};
9214: if ((!defined($currdoms{$typedom})) &&
9215: (&Apache::lonnet::domain($typedom) ne '')) {
9216: my $typestr;
9217: my ($othertitle,$usertypes,$types) =
9218: &Apache::loncommon::sorted_inst_types($typedom);
9219: my $othervalue = 'any';
9220: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
9221: if (@{$types} > 0) {
1.257 raeburn 9222: my @esc_types = map { &escape($_); } @{$types};
1.249 raeburn 9223: $othervalue = 'other';
1.258 raeburn 9224: $typestr = join(',',(@esc_types,$othervalue));
1.249 raeburn 9225: }
9226: $typestr = $othervalue;
9227: } else {
9228: $typestr = $othervalue;
9229: }
9230: $latesttypes[$newnum] = $typedom.':'.$typestr;
9231: $newnum ++ ;
9232: }
9233: }
1.241 raeburn 9234: my $selfenroll_types = join(';',@latesttypes);
9235: if ($selfenroll_types ne $curr_types) {
9236: $changes{'internal.selfenroll_types'} = $selfenroll_types;
9237: }
9238: }
1.276 raeburn 9239: } elsif ($item eq 'limit') {
9240: my $newlimit = $env{'form.selfenroll_limit'};
9241: my $newcap = $env{'form.selfenroll_cap'};
9242: $newcap =~s/\s+//g;
1.398 raeburn 9243: my $currlimit = $currsettings->{'selfenroll_limit'};
1.276 raeburn 9244: $currlimit = 'none' if ($currlimit eq '');
1.398 raeburn 9245: my $currcap = $currsettings->{'selfenroll_cap'};
1.276 raeburn 9246: if ($newlimit ne $currlimit) {
9247: if ($newlimit ne 'none') {
9248: if ($newcap =~ /^\d+$/) {
9249: if ($newcap ne $currcap) {
9250: $changes{'internal.selfenroll_cap'} = $newcap;
9251: }
9252: $changes{'internal.selfenroll_limit'} = $newlimit;
9253: } else {
1.398 raeburn 9254: $warning{$item} = &mt('Maximum enrollment setting unchanged.').'<br />'.
9255: &mt('The value provided was invalid - it must be a positive integer if enrollment is being limited.');
1.276 raeburn 9256: }
9257: } elsif ($currcap ne '') {
9258: $changes{'internal.selfenroll_cap'} = '';
9259: $changes{'internal.selfenroll_limit'} = $newlimit;
9260: }
9261: } elsif ($currlimit ne 'none') {
9262: if ($newcap =~ /^\d+$/) {
9263: if ($newcap ne $currcap) {
9264: $changes{'internal.selfenroll_cap'} = $newcap;
9265: }
9266: } else {
1.398 raeburn 9267: $warning{$item} = &mt('Maximum enrollment setting unchanged.').'<br />'.
9268: &mt('The value provided was invalid - it must be a positive integer if enrollment is being limited.');
1.276 raeburn 9269: }
9270: }
9271: } elsif ($item eq 'approval') {
9272: my (@currnotified,@newnotified);
1.398 raeburn 9273: my $currapproval = $currsettings->{'selfenroll_approval'};
9274: my $currnotifylist = $currsettings->{'selfenroll_notifylist'};
1.276 raeburn 9275: if ($currnotifylist ne '') {
9276: @currnotified = split(/,/,$currnotifylist);
9277: @currnotified = sort(@currnotified);
9278: }
9279: my $newapproval = $env{'form.selfenroll_approval'};
9280: @newnotified = &Apache::loncommon::get_env_multiple('form.selfenroll_notify');
9281: @newnotified = sort(@newnotified);
9282: if ($newapproval ne $currapproval) {
9283: $changes{'internal.selfenroll_approval'} = $newapproval;
9284: if (!$newapproval) {
9285: if ($currnotifylist ne '') {
9286: $changes{'internal.selfenroll_notifylist'} = '';
9287: }
9288: } else {
9289: my @differences =
1.295 raeburn 9290: &Apache::loncommon::compare_arrays(\@currnotified,\@newnotified);
1.276 raeburn 9291: if (@differences > 0) {
9292: if (@newnotified > 0) {
9293: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
9294: } else {
9295: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
9296: }
9297: }
9298: }
9299: } else {
1.295 raeburn 9300: my @differences = &Apache::loncommon::compare_arrays(\@currnotified,\@newnotified);
1.276 raeburn 9301: if (@differences > 0) {
9302: if (@newnotified > 0) {
9303: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
9304: } else {
9305: $changes{'internal.selfenroll_notifylist'} = '';
9306: }
9307: }
9308: }
1.237 raeburn 9309: } else {
1.398 raeburn 9310: my $curr_val = $currsettings->{'selfenroll_'.$item};
1.237 raeburn 9311: my $newval = $env{'form.selfenroll_'.$item};
9312: if ($item eq 'section') {
9313: $newval = $env{'form.sections'};
1.241 raeburn 9314: if (defined($curr_groups{$newval})) {
1.237 raeburn 9315: $newval = $curr_val;
1.398 raeburn 9316: $warning{$item} = &mt('Section for self-enrolled users unchanged as the proposed section is a group').'<br />'.
9317: &mt('Group names and section names must be distinct');
1.237 raeburn 9318: } elsif ($newval eq 'all') {
9319: $newval = $curr_val;
1.274 bisitz 9320: $warning{$item} = &mt('Section for self-enrolled users unchanged, as "all" is a reserved section name.');
1.237 raeburn 9321: }
9322: if ($newval eq '') {
9323: $newval = 'none';
9324: }
9325: }
9326: if ($newval ne $curr_val) {
9327: $changes{'internal.selfenroll_'.$item} = $newval;
9328: }
1.241 raeburn 9329: }
1.237 raeburn 9330: }
9331: if (keys(%warning) > 0) {
9332: foreach my $item (@{$row}) {
9333: if (exists($warning{$item})) {
9334: $r->print($warning{$item}.'<br />');
9335: }
9336: }
9337: }
9338: if (keys(%changes) > 0) {
9339: my $putresult = &Apache::lonnet::put('environment',\%changes,$cdom,$cnum);
9340: if ($putresult eq 'ok') {
9341: if ((exists($changes{'internal.selfenroll_types'})) ||
9342: (exists($changes{'internal.selfenroll_start_date'})) ||
9343: (exists($changes{'internal.selfenroll_end_date'}))) {
9344: my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',
9345: $cnum,undef,undef,'Course');
9346: my $chome = &Apache::lonnet::homeserver($cnum,$cdom);
1.398 raeburn 9347: if (ref($crsinfo{$cid}) eq 'HASH') {
1.237 raeburn 9348: foreach my $item ('selfenroll_types','selfenroll_start_date','selfenroll_end_date') {
9349: if (exists($changes{'internal.'.$item})) {
1.398 raeburn 9350: $crsinfo{$cid}{$item} = $changes{'internal.'.$item};
1.237 raeburn 9351: }
9352: }
9353: my $crsputresult =
9354: &Apache::lonnet::courseidput($cdom,\%crsinfo,
9355: $chome,'notime');
9356: }
9357: }
9358: $r->print(&mt('The following changes were made to self-enrollment settings:').'<ul>');
9359: foreach my $item (@{$row}) {
9360: my $title = $item;
9361: if (ref($lt) eq 'HASH') {
9362: $title = $lt->{$item};
9363: }
9364: if ($item eq 'enroll_dates') {
9365: foreach my $type ('start','end') {
9366: if (exists($changes{'internal.selfenroll_'.$type.'_date'})) {
9367: my $newdate = &Apache::lonlocal::locallocaltime($changes{'internal.selfenroll_'.$type.'_date'});
1.244 bisitz 9368: $r->print('<li>'.&mt('[_1]: "[_2]" set to "[_3]".',
1.237 raeburn 9369: $title,$type,$newdate).'</li>');
9370: }
9371: }
9372: } elsif ($item eq 'access_dates') {
9373: foreach my $type ('start','end') {
9374: if (exists($changes{'internal.selfenroll_'.$type.'_access'})) {
9375: my $newdate = &Apache::lonlocal::locallocaltime($changes{'internal.selfenroll_'.$type.'_access'});
1.244 bisitz 9376: $r->print('<li>'.&mt('[_1]: "[_2]" set to "[_3]".',
1.237 raeburn 9377: $title,$type,$newdate).'</li>');
9378: }
9379: }
1.276 raeburn 9380: } elsif ($item eq 'limit') {
9381: if ((exists($changes{'internal.selfenroll_limit'})) ||
9382: (exists($changes{'internal.selfenroll_cap'}))) {
9383: my ($newval,$newcap);
9384: if ($changes{'internal.selfenroll_cap'} ne '') {
9385: $newcap = $changes{'internal.selfenroll_cap'}
9386: } else {
1.398 raeburn 9387: $newcap = $currsettings->{'selfenroll_cap'};
1.276 raeburn 9388: }
9389: if ($changes{'internal.selfenroll_limit'} eq 'none') {
9390: $newval = &mt('No limit');
9391: } elsif ($changes{'internal.selfenroll_limit'} eq
9392: 'allstudents') {
9393: $newval = &mt('New self-enrollment no longer allowed when total (all students) reaches [_1].',$newcap);
9394: } elsif ($changes{'internal.selfenroll_limit'} eq 'selfenrolled') {
9395: $newval = &mt('New self-enrollment no longer allowed when total number of self-enrolled students reaches [_1].',$newcap);
9396: } else {
1.398 raeburn 9397: my $currlimit = $currsettings->{'selfenroll_limit'};
1.276 raeburn 9398: if ($currlimit eq 'allstudents') {
9399: $newval = &mt('New self-enrollment no longer allowed when total (all students) reaches [_1].',$newcap);
9400: } elsif ($changes{'internal.selfenroll_limit'} eq 'selfenrolled') {
1.308 raeburn 9401: $newval = &mt('New self-enrollment no longer allowed when total number of self-enrolled students reaches [_1].',$newcap);
1.276 raeburn 9402: }
9403: }
9404: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval).'</li>'."\n");
9405: }
9406: } elsif ($item eq 'approval') {
9407: if ((exists($changes{'internal.selfenroll_approval'})) ||
9408: (exists($changes{'internal.selfenroll_notifylist'}))) {
1.398 raeburn 9409: my %selfdescs = &Apache::lonuserutils::selfenroll_default_descs();
1.276 raeburn 9410: my ($newval,$newnotify);
9411: if (exists($changes{'internal.selfenroll_notifylist'})) {
9412: $newnotify = $changes{'internal.selfenroll_notifylist'};
9413: } else {
1.398 raeburn 9414: $newnotify = $currsettings->{'selfenroll_notifylist'};
1.276 raeburn 9415: }
1.398 raeburn 9416: if (exists($changes{'internal.selfenroll_approval'})) {
9417: if ($changes{'internal.selfenroll_approval'} !~ /^[012]$/) {
9418: $changes{'internal.selfenroll_approval'} = '0';
9419: }
9420: $newval = $selfdescs{'approval'}{$changes{'internal.selfenroll_approval'}};
1.276 raeburn 9421: } else {
1.398 raeburn 9422: my $currapproval = $currsettings->{'selfenroll_approval'};
9423: if ($currapproval !~ /^[012]$/) {
9424: $currapproval = 0;
1.276 raeburn 9425: }
1.398 raeburn 9426: $newval = $selfdescs{'approval'}{$currapproval};
1.276 raeburn 9427: }
9428: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval));
9429: if ($newnotify) {
1.277 raeburn 9430: $r->print('<br />'.&mt('The following will be notified when an enrollment request needs approval, or has been approved: [_1].',$newnotify));
1.276 raeburn 9431: } else {
1.277 raeburn 9432: $r->print('<br />'.&mt('No notifications sent when an enrollment request needs approval, or has been approved.'));
1.276 raeburn 9433: }
9434: $r->print('</li>'."\n");
9435: }
1.237 raeburn 9436: } else {
9437: if (exists($changes{'internal.selfenroll_'.$item})) {
1.241 raeburn 9438: my $newval = $changes{'internal.selfenroll_'.$item};
9439: if ($item eq 'types') {
9440: if ($newval eq '') {
9441: $newval = &mt('None');
9442: } elsif ($newval eq '*') {
9443: $newval = &mt('Any user in any domain');
9444: }
1.245 raeburn 9445: } elsif ($item eq 'registered') {
9446: if ($newval eq '1') {
9447: $newval = &mt('Yes');
9448: } elsif ($newval eq '0') {
9449: $newval = &mt('No');
9450: }
1.241 raeburn 9451: }
1.244 bisitz 9452: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval).'</li>'."\n");
1.237 raeburn 9453: }
9454: }
9455: }
9456: $r->print('</ul>');
1.398 raeburn 9457: if ($env{'course.'.$cid.'.description'} ne '') {
9458: my %newenvhash;
9459: foreach my $key (keys(%changes)) {
9460: $newenvhash{'course.'.$cid.'.'.$key} = $changes{$key};
9461: }
9462: &Apache::lonnet::appenv(\%newenvhash);
1.237 raeburn 9463: }
9464: } else {
1.398 raeburn 9465: $r->print(&mt('An error occurred when saving changes to self-enrollment settings in this course.').'<br />'.
9466: &mt('The error was: [_1].',$putresult));
1.237 raeburn 9467: }
9468: } else {
1.249 raeburn 9469: $r->print(&mt('No changes were made to the existing self-enrollment settings in this course.'));
1.237 raeburn 9470: }
9471: } else {
1.249 raeburn 9472: $r->print(&mt('No changes were made to the existing self-enrollment settings in this course.'));
1.241 raeburn 9473: }
1.400 raeburn 9474: my $visactions = &cat_visibility();
9475: my ($cathash,%cattype);
9476: my %domconfig = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom);
9477: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
9478: $cathash = $domconfig{'coursecategories'}{'cats'};
9479: $cattype{'auth'} = $domconfig{'coursecategories'}{'auth'};
9480: $cattype{'unauth'} = $domconfig{'coursecategories'}{'unauth'};
9481: } else {
9482: $cathash = {};
9483: $cattype{'auth'} = 'std';
9484: $cattype{'unauth'} = 'std';
9485: }
9486: if (($cattype{'auth'} eq 'none') && ($cattype{'unauth'} eq 'none')) {
9487: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
9488: '<br />'.
9489: '<br />'.$visactions->{'take'}.'<ul>'.
9490: '<li>'.$visactions->{'dc_chgconf'}.'</li>'.
9491: '</ul>');
9492: } elsif (($cattype{'auth'} !~ /^(std|domonly)$/) && ($cattype{'unauth'} !~ /^(std|domonly)$/)) {
9493: if ($currsettings->{'uniquecode'}) {
9494: $r->print('<span class="LC_info">'.$visactions->{'vis'}.'</span>');
9495: } else {
1.366 bisitz 9496: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
1.400 raeburn 9497: '<br />'.
9498: '<br />'.$visactions->{'take'}.'<ul>'.
9499: '<li>'.$visactions->{'dc_setcode'}.'</li>'.
9500: '</ul><br />');
9501: }
9502: } else {
9503: my ($visible,$cansetvis,$vismsgs) = &visible_in_stdcat($cdom,$cnum,\%domconfig);
9504: if (ref($visactions) eq 'HASH') {
9505: if (!$visible) {
9506: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
9507: '<br />');
9508: if (ref($vismsgs) eq 'ARRAY') {
9509: $r->print('<br />'.$visactions->{'take'}.'<ul>');
9510: foreach my $item (@{$vismsgs}) {
9511: $r->print('<li>'.$visactions->{$item}.'</li>');
9512: }
9513: $r->print('</ul>');
1.256 raeburn 9514: }
1.400 raeburn 9515: $r->print($cansetvis);
1.256 raeburn 9516: }
9517: }
9518: }
1.237 raeburn 9519: return;
9520: }
9521:
1.27 matthew 9522: #---------------------------------------------- end functions for &phase_two
1.29 matthew 9523:
9524: #--------------------------------- functions for &phase_two and &phase_three
9525:
9526: #--------------------------end of functions for &phase_two and &phase_three
1.372 raeburn 9527:
1.1 www 9528: 1;
9529: __END__
1.2 www 9530:
9531:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>