Annotation of loncom/interface/loncreateuser.pm, revision 1.406.2.14
1.20 harris41 1: # The LearningOnline Network with CAPA
1.1 www 2: # Create a user
3: #
1.406.2.14! raeburn 4: # $Id: loncreateuser.pm,v 1.406.2.13 2017/03/26 23:33:46 raeburn Exp $
1.22 albertel 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
1.20 harris41 28: ###
29:
1.1 www 30: package Apache::loncreateuser;
1.66 bowersj2 31:
32: =pod
33:
34: =head1 NAME
35:
1.263 jms 36: Apache::loncreateuser.pm
1.66 bowersj2 37:
38: =head1 SYNOPSIS
39:
1.263 jms 40: Handler to create users and custom roles
41:
42: Provides an Apache handler for creating users,
1.66 bowersj2 43: editing their login parameters, roles, and removing roles, and
44: also creating and assigning custom roles.
45:
46: =head1 OVERVIEW
47:
48: =head2 Custom Roles
49:
50: In LON-CAPA, roles are actually collections of privileges. "Teaching
51: Assistant", "Course Coordinator", and other such roles are really just
52: collection of privileges that are useful in many circumstances.
53:
1.324 raeburn 54: Custom roles can be defined by a Domain Coordinator, Course Coordinator
55: or Community Coordinator via the Manage User functionality.
56: The custom role editor screen will show all privileges which can be
57: assigned to users. For a complete list of privileges, please see
58: C</home/httpd/lonTabs/rolesplain.tab>.
1.66 bowersj2 59:
1.324 raeburn 60: Custom role definitions are stored in the C<roles.db> file of the creator
61: of the role.
1.66 bowersj2 62:
63: =cut
1.1 www 64:
65: use strict;
66: use Apache::Constants qw(:common :http);
67: use Apache::lonnet;
1.54 bowersj2 68: use Apache::loncommon;
1.68 www 69: use Apache::lonlocal;
1.117 raeburn 70: use Apache::longroup;
1.190 raeburn 71: use Apache::lonuserutils;
1.307 raeburn 72: use Apache::loncoursequeueadmin;
1.139 albertel 73: use LONCAPA qw(:DEFAULT :match);
1.1 www 74:
1.20 harris41 75: my $loginscript; # piece of javascript used in two separate instances
76: my $authformnop;
77: my $authformkrb;
78: my $authformint;
79: my $authformfsys;
80: my $authformloc;
81:
1.94 matthew 82: sub initialize_authen_forms {
1.227 raeburn 83: my ($dom,$formname,$curr_authtype,$mode) = @_;
84: my ($krbdef,$krbdefdom) = &Apache::loncommon::get_kerberos_defaults($dom);
85: my %param = ( formname => $formname,
1.187 raeburn 86: kerb_def_dom => $krbdefdom,
1.227 raeburn 87: kerb_def_auth => $krbdef,
1.187 raeburn 88: domain => $dom,
89: );
1.188 raeburn 90: my %abv_auth = &auth_abbrev();
1.227 raeburn 91: if ($curr_authtype =~ /^(krb4|krb5|internal|localauth|unix):(.*)$/) {
1.188 raeburn 92: my $long_auth = $1;
1.227 raeburn 93: my $curr_autharg = $2;
1.188 raeburn 94: my %abv_auth = &auth_abbrev();
95: $param{'curr_authtype'} = $abv_auth{$long_auth};
96: if ($long_auth =~ /^krb(4|5)$/) {
97: $param{'curr_kerb_ver'} = $1;
1.227 raeburn 98: $param{'curr_autharg'} = $curr_autharg;
1.188 raeburn 99: }
1.205 raeburn 100: if ($mode eq 'modifyuser') {
101: $param{'mode'} = $mode;
102: }
1.187 raeburn 103: }
1.227 raeburn 104: $loginscript = &Apache::loncommon::authform_header(%param);
105: $authformkrb = &Apache::loncommon::authform_kerberos(%param);
1.31 matthew 106: $authformnop = &Apache::loncommon::authform_nochange(%param);
107: $authformint = &Apache::loncommon::authform_internal(%param);
108: $authformfsys = &Apache::loncommon::authform_filesystem(%param);
109: $authformloc = &Apache::loncommon::authform_local(%param);
1.20 harris41 110: }
111:
1.188 raeburn 112: sub auth_abbrev {
113: my %abv_auth = (
1.368 raeburn 114: krb5 => 'krb',
115: krb4 => 'krb',
116: internal => 'int',
117: localauth => 'loc',
118: unix => 'fsys',
1.188 raeburn 119: );
120: return %abv_auth;
121: }
1.43 www 122:
1.134 raeburn 123: # ====================================================
124:
1.378 raeburn 125: sub user_quotas {
1.134 raeburn 126: my ($ccuname,$ccdomain) = @_;
127: my %lt = &Apache::lonlocal::texthash(
1.267 raeburn 128: 'usrt' => "User Tools",
129: 'cust' => "Custom quota",
130: 'chqu' => "Change quota",
1.134 raeburn 131: );
1.378 raeburn 132:
1.149 raeburn 133: my $quota_javascript = <<"END_SCRIPT";
134: <script type="text/javascript">
1.301 bisitz 135: // <![CDATA[
1.378 raeburn 136: function quota_changes(caller,context) {
137: var customoff = document.getElementById('custom_'+context+'quota_off');
138: var customon = document.getElementById('custom_'+context+'quota_on');
139: var number = document.getElementById(context+'quota');
1.149 raeburn 140: if (caller == "custom") {
1.378 raeburn 141: if (customoff) {
142: if (customoff.checked) {
143: number.value = "";
144: }
1.149 raeburn 145: }
146: }
147: if (caller == "quota") {
1.378 raeburn 148: if (customon) {
149: customon.checked = true;
150: }
1.149 raeburn 151: }
1.378 raeburn 152: return;
1.149 raeburn 153: }
1.301 bisitz 154: // ]]>
1.149 raeburn 155: </script>
156: END_SCRIPT
1.378 raeburn 157: my $longinsttype;
158: my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($ccdomain);
1.267 raeburn 159: my $output = $quota_javascript."\n".
160: '<h3>'.$lt{'usrt'}.'</h3>'."\n".
161: &Apache::loncommon::start_data_table();
162:
1.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.396 raeburn 2348: $now,$captchaform,$emailusername,$usertype) = @_;
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',
2375: );
2376:
2377: %canmodify_status =
1.286 raeburn 2378: &Apache::lonuserutils::can_modify_userinfo($context,$ccdomain,
2379: ['inststatus'],$rolesarray);
1.253 raeburn 2380: if (!$newuser) {
1.188 raeburn 2381: # Get the users information
2382: %userenv = &Apache::lonnet::get('environment',
2383: ['firstname','middlename','lastname','generation',
1.286 raeburn 2384: 'permanentemail','id','inststatus'],$ccdomain,$ccuname);
1.219 raeburn 2385: %canmodify =
2386: &Apache::lonuserutils::can_modify_userinfo($context,$ccdomain,
1.252 raeburn 2387: \@userinfo,$rolesarray);
1.257 raeburn 2388: } elsif ($context eq 'selfcreate') {
1.391 raeburn 2389: if ($newuser eq 'email') {
1.396 raeburn 2390: if (ref($emailusername) eq 'HASH') {
2391: if (ref($emailusername->{$usertype}) eq 'HASH') {
2392: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
2393: @userinfo = ();
2394: if ((ref($infofields) eq 'ARRAY') && (ref($infotitles) eq 'HASH')) {
2395: foreach my $field (@{$infofields}) {
2396: if ($emailusername->{$usertype}->{$field}) {
2397: push(@userinfo,$field);
2398: $canmodify{$field} = 1;
2399: unless ($textboxsize{$field}) {
2400: $textboxsize{$field} = 25;
2401: }
2402: unless ($lt{$field}) {
2403: $lt{$field} = $infotitles->{$field};
2404: }
2405: if ($emailusername->{$usertype}->{$field} eq 'required') {
2406: $lt{$field} .= '<b>*</b>';
2407: }
1.391 raeburn 2408: }
2409: }
2410: }
2411: }
2412: }
2413: } else {
2414: %canmodify = &selfcreate_canmodify($context,$ccdomain,\@userinfo,
2415: $inst_results,$rolesarray);
2416: }
1.188 raeburn 2417: }
1.391 raeburn 2418:
1.188 raeburn 2419: my $genhelp=&Apache::loncommon::help_open_topic('Generation');
2420: $output = '<h3>'.$lt{'pd'}.'</h3>'.
2421: &Apache::lonhtmlcommon::start_pick_box();
1.391 raeburn 2422: if (($context eq 'selfcreate') && ($newuser eq 'email')) {
1.396 raeburn 2423: $output .= &Apache::lonhtmlcommon::row_title($lt{'email'}.'<b>*</b>',undef,
1.391 raeburn 2424: 'LC_oddrow_value')."\n".
1.394 raeburn 2425: '<input type="text" name="uname" size="25" value="" autocomplete="off" />';
1.391 raeburn 2426: $rowcount ++;
2427: $output .= &Apache::lonhtmlcommon::row_closure(1);
1.406.2.1 raeburn 2428: my $upassone = '<input type="password" name="upass'.$now.'" size="20" autocomplete="off" />';
2429: my $upasstwo = '<input type="password" name="upasscheck'.$now.'" size="20" autocomplete="off" />';
1.396 raeburn 2430: $output .= &Apache::lonhtmlcommon::row_title(&mt('Password').'<b>*</b>',
1.391 raeburn 2431: 'LC_pick_box_title',
2432: 'LC_oddrow_value')."\n".
2433: $upassone."\n".
2434: &Apache::lonhtmlcommon::row_closure(1)."\n".
1.396 raeburn 2435: &Apache::lonhtmlcommon::row_title(&mt('Confirm password').'<b>*</b>',
1.391 raeburn 2436: 'LC_pick_box_title',
2437: 'LC_oddrow_value')."\n".
2438: $upasstwo.
2439: &Apache::lonhtmlcommon::row_closure()."\n";
2440: }
1.188 raeburn 2441: foreach my $item (@userinfo) {
2442: my $rowtitle = $lt{$item};
1.252 raeburn 2443: my $hiderow = 0;
1.188 raeburn 2444: if ($item eq 'generation') {
2445: $rowtitle = $genhelp.$rowtitle;
2446: }
1.252 raeburn 2447: my $row = &Apache::lonhtmlcommon::row_title($rowtitle,undef,'LC_oddrow_value')."\n";
1.188 raeburn 2448: if ($newuser) {
1.210 raeburn 2449: if (ref($inst_results) eq 'HASH') {
2450: if ($inst_results->{$item} ne '') {
1.252 raeburn 2451: $row .= '<input type="hidden" name="c'.$item.'" value="'.$inst_results->{$item}.'" />'.$inst_results->{$item};
1.210 raeburn 2452: } else {
1.252 raeburn 2453: if ($context eq 'selfcreate') {
1.391 raeburn 2454: if ($canmodify{$item}) {
1.394 raeburn 2455: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" autocomplete="off" />';
1.252 raeburn 2456: $editable ++;
2457: } else {
2458: $hiderow = 1;
2459: }
1.253 raeburn 2460: } else {
2461: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
1.252 raeburn 2462: }
1.210 raeburn 2463: }
1.188 raeburn 2464: } else {
1.252 raeburn 2465: if ($context eq 'selfcreate') {
1.401 raeburn 2466: if ($canmodify{$item}) {
2467: if ($newuser eq 'email') {
2468: $row .= '<input type="text" name="'.$item.'" size="'.$textboxsize{$item}.'" value="" autocomplete="off" />';
1.287 raeburn 2469: } else {
1.401 raeburn 2470: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" autocomplete="off" />';
1.287 raeburn 2471: }
1.401 raeburn 2472: $editable ++;
2473: } else {
2474: $hiderow = 1;
1.252 raeburn 2475: }
1.253 raeburn 2476: } else {
2477: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
1.252 raeburn 2478: }
1.188 raeburn 2479: }
2480: } else {
1.219 raeburn 2481: if ($canmodify{$item}) {
1.252 raeburn 2482: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="'.$userenv{$item}.'" />';
1.393 raeburn 2483: if (($item eq 'id') && (!$newuser)) {
2484: $row .= '<br />'.&Apache::lonuserutils::forceid_change($context);
2485: }
1.188 raeburn 2486: } else {
1.252 raeburn 2487: $row .= $userenv{$item};
1.188 raeburn 2488: }
2489: }
1.252 raeburn 2490: $row .= &Apache::lonhtmlcommon::row_closure(1);
2491: if (!$hiderow) {
2492: $output .= $row;
2493: $rowcount ++;
2494: }
1.188 raeburn 2495: }
1.286 raeburn 2496: if (($canmodify_status{'inststatus'}) || ($context ne 'selfcreate')) {
2497: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($ccdomain);
2498: if (ref($types) eq 'ARRAY') {
2499: if (@{$types} > 0) {
2500: my ($hiderow,$shown);
2501: if ($canmodify_status{'inststatus'}) {
2502: $shown = &pick_inst_statuses($userenv{'inststatus'},$usertypes,$types);
2503: } else {
2504: if ($userenv{'inststatus'} eq '') {
2505: $hiderow = 1;
1.334 raeburn 2506: } else {
2507: my @showitems;
2508: foreach my $item ( map { &unescape($_); } split(':',$userenv{'inststatus'})) {
2509: if (exists($usertypes->{$item})) {
2510: push(@showitems,$usertypes->{$item});
2511: } else {
2512: push(@showitems,$item);
2513: }
2514: }
2515: if (@showitems) {
2516: $shown = join(', ',@showitems);
2517: } else {
2518: $hiderow = 1;
2519: }
1.286 raeburn 2520: }
2521: }
2522: if (!$hiderow) {
1.389 bisitz 2523: my $row = &Apache::lonhtmlcommon::row_title(&mt('Affiliations'),undef,'LC_oddrow_value')."\n".
1.286 raeburn 2524: $shown.&Apache::lonhtmlcommon::row_closure(1);
2525: if ($context eq 'selfcreate') {
2526: $rowcount ++;
2527: }
2528: $output .= $row;
2529: }
2530: }
2531: }
2532: }
1.391 raeburn 2533: if (($context eq 'selfcreate') && ($newuser eq 'email')) {
2534: if ($captchaform) {
1.406.2.2 raeburn 2535: $output .= &Apache::lonhtmlcommon::row_title($lt{'valid'}.'*',
1.391 raeburn 2536: 'LC_pick_box_title')."\n".
2537: $captchaform."\n".'<br /><br />'.
2538: &Apache::lonhtmlcommon::row_closure(1);
2539: $rowcount ++;
2540: }
2541: my $submit_text = &mt('Create account');
2542: $output .= &Apache::lonhtmlcommon::row_title()."\n".
2543: '<br /><input type="submit" name="createaccount" value="'.
2544: $submit_text.'" />'.
1.396 raeburn 2545: '<input type="hidden" name="type" value="'.$usertype.'" />'.
1.391 raeburn 2546: &Apache::lonhtmlcommon::row_closure(1);
2547: }
1.188 raeburn 2548: $output .= &Apache::lonhtmlcommon::end_pick_box();
1.206 raeburn 2549: if (wantarray) {
1.252 raeburn 2550: if ($context eq 'selfcreate') {
2551: return($output,$rowcount,$editable);
2552: } else {
1.388 bisitz 2553: return $output;
1.252 raeburn 2554: }
1.206 raeburn 2555: } else {
2556: return $output;
2557: }
1.188 raeburn 2558: }
2559:
1.286 raeburn 2560: sub pick_inst_statuses {
2561: my ($curr,$usertypes,$types) = @_;
2562: my ($output,$rem,@currtypes);
2563: if ($curr ne '') {
2564: @currtypes = map { &unescape($_); } split(/:/,$curr);
2565: }
2566: my $numinrow = 2;
2567: if (ref($types) eq 'ARRAY') {
2568: $output = '<table>';
2569: my $lastcolspan;
2570: for (my $i=0; $i<@{$types}; $i++) {
2571: if (defined($usertypes->{$types->[$i]})) {
2572: my $rem = $i%($numinrow);
2573: if ($rem == 0) {
2574: if ($i<@{$types}-1) {
2575: if ($i > 0) {
2576: $output .= '</tr>';
2577: }
2578: $output .= '<tr>';
2579: }
2580: } elsif ($i==@{$types}-1) {
2581: my $colsleft = $numinrow - $rem;
2582: if ($colsleft > 1) {
2583: $lastcolspan = ' colspan="'.$colsleft.'"';
2584: }
2585: }
2586: my $check = ' ';
2587: if (grep(/^\Q$types->[$i]\E$/,@currtypes)) {
2588: $check = ' checked="checked" ';
2589: }
2590: $output .= '<td class="LC_left_item"'.$lastcolspan.'>'.
2591: '<span class="LC_nobreak"><label>'.
2592: '<input type="checkbox" name="inststatus" '.
2593: 'value="'.$types->[$i].'"'.$check.'/>'.
2594: $usertypes->{$types->[$i]}.'</label></span></td>';
2595: }
2596: }
2597: $output .= '</tr></table>';
2598: }
2599: return $output;
2600: }
2601:
1.257 raeburn 2602: sub selfcreate_canmodify {
2603: my ($context,$dom,$userinfo,$inst_results,$rolesarray) = @_;
2604: if (ref($inst_results) eq 'HASH') {
2605: my @inststatuses = &get_inststatuses($inst_results);
2606: if (@inststatuses == 0) {
2607: @inststatuses = ('default');
2608: }
2609: $rolesarray = \@inststatuses;
2610: }
2611: my %canmodify =
2612: &Apache::lonuserutils::can_modify_userinfo($context,$dom,$userinfo,
2613: $rolesarray);
2614: return %canmodify;
2615: }
2616:
1.252 raeburn 2617: sub get_inststatuses {
2618: my ($insthashref) = @_;
2619: my @inststatuses = ();
2620: if (ref($insthashref) eq 'HASH') {
2621: if (ref($insthashref->{'inststatus'}) eq 'ARRAY') {
2622: @inststatuses = @{$insthashref->{'inststatus'}};
2623: }
2624: }
2625: return @inststatuses;
2626: }
2627:
1.4 www 2628: # ================================================================= Phase Three
1.42 matthew 2629: sub update_user_data {
1.375 raeburn 2630: my ($r,$context,$crstype,$brcrum,$showcredits) = @_;
1.101 albertel 2631: my $uhome=&Apache::lonnet::homeserver($env{'form.ccuname'},
2632: $env{'form.ccdomain'});
1.27 matthew 2633: # Error messages
1.188 raeburn 2634: my $error = '<span class="LC_error">'.&mt('Error').': ';
1.193 raeburn 2635: my $end = '</span><br /><br />';
2636: my $rtnlink = '<a href="javascript:backPage(document.userupdate,'.
1.188 raeburn 2637: "'$env{'form.prevphase'}','modify')".'" />'.
1.219 raeburn 2638: &mt('Return to previous page').'</a>'.
2639: &Apache::loncommon::end_page();
2640: my $now = time;
1.40 www 2641: my $title;
1.101 albertel 2642: if (exists($env{'form.makeuser'})) {
1.40 www 2643: $title='Set Privileges for New User';
2644: } else {
2645: $title='Modify User Privileges';
2646: }
1.213 raeburn 2647: my $newuser = 0;
1.160 raeburn 2648: my ($jsback,$elements) = &crumb_utilities();
2649: my $jscript = '<script type="text/javascript">'."\n".
1.301 bisitz 2650: '// <![CDATA['."\n".
2651: $jsback."\n".
2652: '// ]]>'."\n".
2653: '</script>'."\n";
1.406.2.7 raeburn 2654: my %breadcrumb_text = &singleuser_breadcrumb($crstype,$context,$env{'form.ccdomain'});
1.351 raeburn 2655: push (@{$brcrum},
2656: {href => "javascript:backPage(document.userupdate)",
2657: text => $breadcrumb_text{'search'},
2658: faq => 282,
2659: bug => 'Instructor Interface',}
2660: );
2661: if ($env{'form.prevphase'} eq 'userpicked') {
2662: push(@{$brcrum},
2663: {href => "javascript:backPage(document.userupdate,'get_user_info','select')",
2664: text => $breadcrumb_text{'userpicked'},
2665: faq => 282,
2666: bug => 'Instructor Interface',});
1.233 raeburn 2667: }
1.224 raeburn 2668: my $helpitem = 'Course_Change_Privileges';
2669: if ($env{'form.action'} eq 'singlestudent') {
2670: $helpitem = 'Course_Add_Student';
1.406.2.14! raeburn 2671: } elsif ($context eq 'author') {
! 2672: $helpitem = 'Author_Change_Privileges';
! 2673: } elsif ($context eq 'domain') {
! 2674: $helpitem = 'Domain_Change_Privileges';
1.224 raeburn 2675: }
1.351 raeburn 2676: push(@{$brcrum},
2677: {href => "javascript:backPage(document.userupdate,'$env{'form.prevphase'}','modify')",
2678: text => $breadcrumb_text{'modify'},
2679: faq => 282,
2680: bug => 'Instructor Interface',},
2681: {href => "/adm/createuser",
2682: text => "Result",
2683: faq => 282,
2684: bug => 'Instructor Interface',
2685: help => $helpitem});
2686: my $args = {bread_crumbs => $brcrum,
2687: bread_crumbs_component => 'User Management'};
2688: if ($env{'form.popup'}) {
2689: $args->{'no_nav_bar'} = 1;
2690: }
2691: $r->print(&Apache::loncommon::start_page($title,$jscript,$args));
1.188 raeburn 2692: $r->print(&update_result_form($uhome));
1.27 matthew 2693: # Check Inputs
1.101 albertel 2694: if (! $env{'form.ccuname'} ) {
1.193 raeburn 2695: $r->print($error.&mt('No login name specified').'.'.$end.$rtnlink);
1.27 matthew 2696: return;
2697: }
1.138 albertel 2698: if ( $env{'form.ccuname'} ne
2699: &LONCAPA::clean_username($env{'form.ccuname'}) ) {
1.281 bisitz 2700: $r->print($error.&mt('Invalid login name.').' '.
2701: &mt('Only letters, numbers, periods, dashes, @, and underscores are valid.').
1.193 raeburn 2702: $end.$rtnlink);
1.27 matthew 2703: return;
2704: }
1.101 albertel 2705: if (! $env{'form.ccdomain'} ) {
1.193 raeburn 2706: $r->print($error.&mt('No domain specified').'.'.$end.$rtnlink);
1.27 matthew 2707: return;
2708: }
1.138 albertel 2709: if ( $env{'form.ccdomain'} ne
2710: &LONCAPA::clean_domain($env{'form.ccdomain'}) ) {
1.281 bisitz 2711: $r->print($error.&mt('Invalid domain name.').' '.
2712: &mt('Only letters, numbers, periods, dashes, and underscores are valid.').
1.193 raeburn 2713: $end.$rtnlink);
1.27 matthew 2714: return;
2715: }
1.219 raeburn 2716: if ($uhome eq 'no_host') {
2717: $newuser = 1;
2718: }
1.101 albertel 2719: if (! exists($env{'form.makeuser'})) {
1.29 matthew 2720: # Modifying an existing user, so check the validity of the name
2721: if ($uhome eq 'no_host') {
1.389 bisitz 2722: $r->print(
2723: $error
2724: .'<p class="LC_error">'
2725: .&mt('Unable to determine home server for [_1] in domain [_2].',
2726: '"'.$env{'form.ccuname'}.'"','"'.$env{'form.ccdomain'}.'"')
2727: .'</p>');
1.29 matthew 2728: return;
2729: }
2730: }
1.27 matthew 2731: # Determine authentication method and password for the user being modified
2732: my $amode='';
2733: my $genpwd='';
1.101 albertel 2734: if ($env{'form.login'} eq 'krb') {
1.41 albertel 2735: $amode='krb';
1.101 albertel 2736: $amode.=$env{'form.krbver'};
2737: $genpwd=$env{'form.krbarg'};
2738: } elsif ($env{'form.login'} eq 'int') {
1.27 matthew 2739: $amode='internal';
1.101 albertel 2740: $genpwd=$env{'form.intarg'};
2741: } elsif ($env{'form.login'} eq 'fsys') {
1.27 matthew 2742: $amode='unix';
1.101 albertel 2743: $genpwd=$env{'form.fsysarg'};
2744: } elsif ($env{'form.login'} eq 'loc') {
1.27 matthew 2745: $amode='localauth';
1.101 albertel 2746: $genpwd=$env{'form.locarg'};
1.27 matthew 2747: $genpwd=" " if (!$genpwd);
1.101 albertel 2748: } elsif (($env{'form.login'} eq 'nochange') ||
2749: ($env{'form.login'} eq '' )) {
1.34 matthew 2750: # There is no need to tell the user we did not change what they
2751: # did not ask us to change.
1.35 matthew 2752: # If they are creating a new user but have not specified login
2753: # information this will be caught below.
1.30 matthew 2754: } else {
1.367 golterma 2755: $r->print($error.&mt('Invalid login mode or password').$end.$rtnlink);
2756: return;
1.27 matthew 2757: }
1.164 albertel 2758:
1.188 raeburn 2759: $r->print('<h3>'.&mt('User [_1] in domain [_2]',
1.367 golterma 2760: $env{'form.ccuname'}.' ('.&Apache::loncommon::plainname($env{'form.ccuname'},
2761: $env{'form.ccdomain'}).')', $env{'form.ccdomain'}).'</h3>');
2762: my %prog_state = &Apache::lonhtmlcommon::Create_PrgWin($r,2);
1.344 bisitz 2763:
1.193 raeburn 2764: my (%alerts,%rulematch,%inst_results,%curr_rules);
1.334 raeburn 2765: my @userinfo = ('firstname','middlename','lastname','generation','permanentemail','id');
1.361 raeburn 2766: my @usertools = ('aboutme','blog','webdav','portfolio');
1.384 raeburn 2767: my @requestcourses = ('official','unofficial','community','textbook');
1.362 raeburn 2768: my @requestauthor = ('requestauthor');
1.286 raeburn 2769: my ($othertitle,$usertypes,$types) =
2770: &Apache::loncommon::sorted_inst_types($env{'form.ccdomain'});
1.334 raeburn 2771: my %canmodify_status =
2772: &Apache::lonuserutils::can_modify_userinfo($context,$env{'form.ccdomain'},
2773: ['inststatus']);
1.101 albertel 2774: if ($env{'form.makeuser'}) {
1.164 albertel 2775: $r->print('<h3>'.&mt('Creating new account.').'</h3>');
1.27 matthew 2776: # Check for the authentication mode and password
2777: if (! $amode || ! $genpwd) {
1.193 raeburn 2778: $r->print($error.&mt('Invalid login mode or password').$end.$rtnlink);
1.27 matthew 2779: return;
1.18 albertel 2780: }
1.29 matthew 2781: # Determine desired host
1.101 albertel 2782: my $desiredhost = $env{'form.hserver'};
1.29 matthew 2783: if (lc($desiredhost) eq 'default') {
2784: $desiredhost = undef;
2785: } else {
1.147 albertel 2786: my %home_servers =
2787: &Apache::lonnet::get_servers($env{'form.ccdomain'},'library');
1.29 matthew 2788: if (! exists($home_servers{$desiredhost})) {
1.193 raeburn 2789: $r->print($error.&mt('Invalid home server specified').$end.$rtnlink);
2790: return;
2791: }
2792: }
2793: # Check ID format
2794: my %checkhash;
2795: my %checks = ('id' => 1);
2796: %{$checkhash{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}}} = (
1.219 raeburn 2797: 'newuser' => $newuser,
1.196 raeburn 2798: 'id' => $env{'form.cid'},
1.193 raeburn 2799: );
1.196 raeburn 2800: if ($env{'form.cid'} ne '') {
2801: &Apache::loncommon::user_rule_check(\%checkhash,\%checks,\%alerts,
2802: \%rulematch,\%inst_results,\%curr_rules);
2803: if (ref($alerts{'id'}) eq 'HASH') {
2804: if (ref($alerts{'id'}{$env{'form.ccdomain'}}) eq 'HASH') {
2805: my $domdesc =
2806: &Apache::lonnet::domain($env{'form.ccdomain'},'description');
2807: if ($alerts{'id'}{$env{'form.ccdomain'}}{$env{'form.cid'}}) {
2808: my $userchkmsg;
2809: if (ref($curr_rules{$env{'form.ccdomain'}}) eq 'HASH') {
2810: $userchkmsg =
2811: &Apache::loncommon::instrule_disallow_msg('id',
2812: $domdesc,1).
2813: &Apache::loncommon::user_rule_formats($env{'form.ccdomain'},
2814: $domdesc,$curr_rules{$env{'form.ccdomain'}}{'id'},'id');
2815: }
2816: $r->print($error.&mt('Invalid ID format').$end.
2817: $userchkmsg.$rtnlink);
2818: return;
2819: }
2820: }
1.29 matthew 2821: }
2822: }
1.367 golterma 2823: &Apache::lonhtmlcommon::Increment_PrgWin($r, \%prog_state);
1.27 matthew 2824: # Call modifyuser
2825: my $result = &Apache::lonnet::modifyuser
1.193 raeburn 2826: ($env{'form.ccdomain'},$env{'form.ccuname'},$env{'form.cid'},
1.188 raeburn 2827: $amode,$genpwd,$env{'form.cfirstname'},
2828: $env{'form.cmiddlename'},$env{'form.clastname'},
2829: $env{'form.cgeneration'},undef,$desiredhost,
2830: $env{'form.cpermanentemail'});
1.77 www 2831: $r->print(&mt('Generating user').': '.$result);
1.219 raeburn 2832: $uhome = &Apache::lonnet::homeserver($env{'form.ccuname'},
1.101 albertel 2833: $env{'form.ccdomain'});
1.334 raeburn 2834: my (%changeHash,%newcustom,%changed,%changedinfo);
1.267 raeburn 2835: if ($uhome ne 'no_host') {
1.334 raeburn 2836: if ($context eq 'domain') {
1.378 raeburn 2837: foreach my $name ('portfolio','author') {
2838: if ($env{'form.custom_'.$name.'quota'} == 1) {
2839: if ($env{'form.'.$name.'quota'} eq '') {
2840: $newcustom{$name.'quota'} = 0;
2841: } else {
2842: $newcustom{$name.'quota'} = $env{'form.'.$name.'quota'};
2843: $newcustom{$name.'quota'} =~ s/[^\d\.]//g;
2844: }
2845: if ("a_admin($newcustom{$name.'quota'},\%changeHash,$name)) {
2846: $changed{$name.'quota'} = 1;
2847: }
1.334 raeburn 2848: }
2849: }
2850: foreach my $item (@usertools) {
2851: if ($env{'form.custom'.$item} == 1) {
2852: $newcustom{$item} = $env{'form.tools_'.$item};
2853: $changed{$item} = &tool_admin($item,$newcustom{$item},
2854: \%changeHash,'tools');
2855: }
1.267 raeburn 2856: }
1.334 raeburn 2857: foreach my $item (@requestcourses) {
1.341 raeburn 2858: if ($env{'form.custom'.$item} == 1) {
2859: $newcustom{$item} = $env{'form.crsreq_'.$item};
2860: if ($env{'form.crsreq_'.$item} eq 'autolimit') {
2861: $newcustom{$item} .= '=';
1.383 raeburn 2862: $env{'form.crsreq_'.$item.'_limit'} =~ s/\D+//g;
2863: if ($env{'form.crsreq_'.$item.'_limit'}) {
1.341 raeburn 2864: $newcustom{$item} .= $env{'form.crsreq_'.$item.'_limit'};
2865: }
1.334 raeburn 2866: }
1.341 raeburn 2867: $changed{$item} = &tool_admin($item,$newcustom{$item},
2868: \%changeHash,'requestcourses');
1.334 raeburn 2869: }
1.275 raeburn 2870: }
1.362 raeburn 2871: if ($env{'form.customrequestauthor'} == 1) {
2872: $newcustom{'requestauthor'} = $env{'form.requestauthor'};
2873: $changed{'requestauthor'} = &tool_admin('requestauthor',
2874: $newcustom{'requestauthor'},
2875: \%changeHash,'requestauthor');
2876: }
1.275 raeburn 2877: }
1.334 raeburn 2878: if ($canmodify_status{'inststatus'}) {
2879: if (exists($env{'form.inststatus'})) {
2880: my @inststatuses = &Apache::loncommon::get_env_multiple('form.inststatus');
2881: if (@inststatuses > 0) {
2882: $changeHash{'inststatus'} = join(',',@inststatuses);
2883: $changed{'inststatus'} = $changeHash{'inststatus'};
1.306 raeburn 2884: }
2885: }
1.232 raeburn 2886: }
1.334 raeburn 2887: if (keys(%changed)) {
2888: foreach my $item (@userinfo) {
2889: $changeHash{$item} = $env{'form.c'.$item};
1.286 raeburn 2890: }
1.267 raeburn 2891: my $chgresult =
2892: &Apache::lonnet::put('environment',\%changeHash,
2893: $env{'form.ccdomain'},$env{'form.ccuname'});
2894: }
1.232 raeburn 2895: }
1.219 raeburn 2896: $r->print('<br />'.&mt('Home server').': '.$uhome.' '.
2897: &Apache::lonnet::hostname($uhome));
1.101 albertel 2898: } elsif (($env{'form.login'} ne 'nochange') &&
2899: ($env{'form.login'} ne '' )) {
1.27 matthew 2900: # Modify user privileges
2901: if (! $amode || ! $genpwd) {
1.193 raeburn 2902: $r->print($error.'Invalid login mode or password'.$end.$rtnlink);
1.27 matthew 2903: return;
1.20 harris41 2904: }
1.395 bisitz 2905: # Only allow authentication modification if the person has authority
1.101 albertel 2906: if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'})) {
1.20 harris41 2907: $r->print('Modifying authentication: '.
1.31 matthew 2908: &Apache::lonnet::modifyuserauth(
1.101 albertel 2909: $env{'form.ccdomain'},$env{'form.ccuname'},
1.21 harris41 2910: $amode,$genpwd));
1.102 albertel 2911: $r->print('<br />'.&mt('Home server').': '.&Apache::lonnet::homeserver
1.101 albertel 2912: ($env{'form.ccuname'},$env{'form.ccdomain'}));
1.4 www 2913: } else {
1.27 matthew 2914: # Okay, this is a non-fatal error.
1.395 bisitz 2915: $r->print($error.&mt('You do not have the authority to modify this users authentication information.').$end);
1.27 matthew 2916: }
1.28 matthew 2917: }
1.344 bisitz 2918: $r->rflush(); # Finish display of header before time consuming actions start
1.367 golterma 2919: &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state);
1.28 matthew 2920: ##
1.375 raeburn 2921: my (@userroles,%userupdate,$cnum,$cdom,$defaultcredits,%namechanged);
1.213 raeburn 2922: if ($context eq 'course') {
1.375 raeburn 2923: ($cnum,$cdom) =
2924: &Apache::lonuserutils::get_course_identity();
1.318 raeburn 2925: $crstype = &Apache::loncommon::course_type($cdom.'_'.$cnum);
1.375 raeburn 2926: if ($showcredits) {
2927: $defaultcredits = &Apache::lonuserutils::get_defaultcredits($cdom,$cnum);
2928: }
1.213 raeburn 2929: }
1.101 albertel 2930: if (! $env{'form.makeuser'} ) {
1.28 matthew 2931: # Check for need to change
2932: my %userenv = &Apache::lonnet::get
1.134 raeburn 2933: ('environment',['firstname','middlename','lastname','generation',
1.378 raeburn 2934: 'id','permanentemail','portfolioquota','authorquota','inststatus',
2935: 'tools.aboutme','tools.blog','tools.webdav','tools.portfolio',
1.361 raeburn 2936: 'requestcourses.official','requestcourses.unofficial',
1.384 raeburn 2937: 'requestcourses.community','requestcourses.textbook',
2938: 'reqcrsotherdom.official','reqcrsotherdom.unofficial',
2939: 'reqcrsotherdom.community','reqcrsotherdom.textbook',
1.406.2.9 raeburn 2940: 'requestauthor'],
1.160 raeburn 2941: $env{'form.ccdomain'},$env{'form.ccuname'});
1.28 matthew 2942: my ($tmp) = keys(%userenv);
2943: if ($tmp =~ /^(con_lost|error)/i) {
2944: %userenv = ();
2945: }
1.206 raeburn 2946: my $no_forceid_alert;
2947: # Check to see if user information can be changed
2948: my %domconfig =
2949: &Apache::lonnet::get_dom('configuration',['usermodification'],
2950: $env{'form.ccdomain'});
1.213 raeburn 2951: my @statuses = ('active','future');
2952: my %roles = &Apache::lonnet::get_my_roles($env{'form.ccuname'},$env{'form.ccdomain'},'userroles',\@statuses,undef,$env{'request.role.domain'});
2953: my ($auname,$audom);
1.220 raeburn 2954: if ($context eq 'author') {
1.206 raeburn 2955: $auname = $env{'user.name'};
2956: $audom = $env{'user.domain'};
2957: }
2958: foreach my $item (keys(%roles)) {
1.220 raeburn 2959: my ($rolenum,$roledom,$role) = split(/:/,$item,-1);
1.206 raeburn 2960: if ($context eq 'course') {
2961: if ($cnum ne '' && $cdom ne '') {
2962: if ($rolenum eq $cnum && $roledom eq $cdom) {
2963: if (!grep(/^\Q$role\E$/,@userroles)) {
2964: push(@userroles,$role);
2965: }
2966: }
2967: }
2968: } elsif ($context eq 'author') {
2969: if ($rolenum eq $auname && $roledom eq $audom) {
2970: if (!grep(/^\Q$role\E$/,@userroles)) {
2971: push(@userroles,$role);
2972: }
2973: }
2974: }
2975: }
1.220 raeburn 2976: if ($env{'form.action'} eq 'singlestudent') {
2977: if (!grep(/^st$/,@userroles)) {
2978: push(@userroles,'st');
2979: }
2980: } else {
2981: # Check for course or co-author roles being activated or re-enabled
2982: if ($context eq 'author' || $context eq 'course') {
2983: foreach my $key (keys(%env)) {
2984: if ($context eq 'author') {
2985: if ($key=~/^form\.act_\Q$audom\E_\Q$auname\E_([^_]+)/) {
2986: if (!grep(/^\Q$1\E$/,@userroles)) {
2987: push(@userroles,$1);
2988: }
2989: } elsif ($key =~/^form\.ren\:\Q$audom\E\/\Q$auname\E_([^_]+)/) {
2990: if (!grep(/^\Q$1\E$/,@userroles)) {
2991: push(@userroles,$1);
2992: }
1.206 raeburn 2993: }
1.220 raeburn 2994: } elsif ($context eq 'course') {
2995: if ($key=~/^form\.act_\Q$cdom\E_\Q$cnum\E_([^_]+)/) {
2996: if (!grep(/^\Q$1\E$/,@userroles)) {
2997: push(@userroles,$1);
2998: }
2999: } elsif ($key =~/^form\.ren\:\Q$cdom\E\/\Q$cnum\E(\/?\w*)_([^_]+)/) {
3000: if (!grep(/^\Q$1\E$/,@userroles)) {
3001: push(@userroles,$1);
3002: }
1.206 raeburn 3003: }
3004: }
3005: }
3006: }
3007: }
3008: #Check to see if we can change personal data for the user
3009: my (@mod_disallowed,@longroles);
3010: foreach my $role (@userroles) {
3011: if ($role eq 'cr') {
3012: push(@longroles,'Custom');
3013: } else {
1.318 raeburn 3014: push(@longroles,&Apache::lonnet::plaintext($role,$crstype));
1.206 raeburn 3015: }
3016: }
1.219 raeburn 3017: my %canmodify = &Apache::lonuserutils::can_modify_userinfo($context,$env{'form.ccdomain'},\@userinfo,\@userroles);
3018: foreach my $item (@userinfo) {
1.28 matthew 3019: # Strip leading and trailing whitespace
1.203 raeburn 3020: $env{'form.c'.$item} =~ s/(\s+$|^\s+)//g;
1.219 raeburn 3021: if (!$canmodify{$item}) {
1.207 raeburn 3022: if (defined($env{'form.c'.$item})) {
3023: if ($env{'form.c'.$item} ne $userenv{$item}) {
3024: push(@mod_disallowed,$item);
3025: }
1.206 raeburn 3026: }
3027: $env{'form.c'.$item} = $userenv{$item};
3028: }
1.28 matthew 3029: }
1.259 bisitz 3030: # Check to see if we can change the Student/Employee ID
1.196 raeburn 3031: my $forceid = $env{'form.forceid'};
3032: my $recurseid = $env{'form.recurseid'};
3033: my (%alerts,%rulematch,%idinst_results,%curr_rules,%got_rules);
1.203 raeburn 3034: my %uidhash = &Apache::lonnet::idrget($env{'form.ccdomain'},
3035: $env{'form.ccuname'});
3036: if (($uidhash{$env{'form.ccuname'}}) &&
3037: ($uidhash{$env{'form.ccuname'}}!~/error\:/) &&
3038: (!$forceid)) {
3039: if ($env{'form.cid'} ne $uidhash{$env{'form.ccuname'}}) {
3040: $env{'form.cid'} = $userenv{'id'};
1.293 bisitz 3041: $no_forceid_alert = &mt('New student/employee ID does not match existing ID for this user.')
1.259 bisitz 3042: .'<br />'
3043: .&mt("Change is not permitted without checking the 'Force ID change' checkbox on the previous page.")
3044: .'<br />'."\n";
1.203 raeburn 3045: }
3046: }
3047: if ($env{'form.cid'} ne $userenv{'id'}) {
1.196 raeburn 3048: my $checkhash;
3049: my $checks = { 'id' => 1 };
3050: $checkhash->{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}} =
3051: { 'newuser' => $newuser,
3052: 'id' => $env{'form.cid'},
3053: };
3054: &Apache::loncommon::user_rule_check($checkhash,$checks,
3055: \%alerts,\%rulematch,\%idinst_results,\%curr_rules,\%got_rules);
3056: if (ref($alerts{'id'}) eq 'HASH') {
3057: if (ref($alerts{'id'}{$env{'form.ccdomain'}}) eq 'HASH') {
1.203 raeburn 3058: $env{'form.cid'} = $userenv{'id'};
1.196 raeburn 3059: }
3060: }
3061: }
1.378 raeburn 3062: my (%quotachanged,%oldquota,%newquota,%olddefquota,%newdefquota,
3063: $oldinststatus,$newinststatus,%oldisdefault,%newisdefault,%oldsettings,
1.339 raeburn 3064: %oldsettingstext,%newsettings,%newsettingstext,@disporder,
1.378 raeburn 3065: %oldsettingstatus,%newsettingstatus);
1.334 raeburn 3066: @disporder = ('inststatus');
3067: if ($env{'request.role.domain'} eq $env{'form.ccdomain'}) {
1.362 raeburn 3068: push(@disporder,'requestcourses','requestauthor');
1.334 raeburn 3069: } else {
3070: push(@disporder,'reqcrsotherdom');
3071: }
3072: push(@disporder,('quota','tools'));
1.338 raeburn 3073: $oldinststatus = $userenv{'inststatus'};
1.378 raeburn 3074: foreach my $name ('portfolio','author') {
3075: ($olddefquota{$name},$oldsettingstatus{$name}) =
3076: &Apache::loncommon::default_quota($env{'form.ccdomain'},$oldinststatus,$name);
3077: ($newdefquota{$name},$newsettingstatus{$name}) = ($olddefquota{$name},$oldsettingstatus{$name});
3078: }
1.334 raeburn 3079: my %canshow;
1.220 raeburn 3080: if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
1.334 raeburn 3081: $canshow{'quota'} = 1;
1.220 raeburn 3082: }
1.267 raeburn 3083: if (&Apache::lonnet::allowed('mut',$env{'form.ccdomain'})) {
1.334 raeburn 3084: $canshow{'tools'} = 1;
1.267 raeburn 3085: }
1.275 raeburn 3086: if (&Apache::lonnet::allowed('ccc',$env{'form.ccdomain'})) {
1.334 raeburn 3087: $canshow{'requestcourses'} = 1;
1.300 raeburn 3088: } elsif (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
1.334 raeburn 3089: $canshow{'reqcrsotherdom'} = 1;
1.275 raeburn 3090: }
1.286 raeburn 3091: if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'})) {
1.334 raeburn 3092: $canshow{'inststatus'} = 1;
1.286 raeburn 3093: }
1.362 raeburn 3094: if (&Apache::lonnet::allowed('cau',$env{'form.ccdomain'})) {
3095: $canshow{'requestauthor'} = 1;
3096: }
1.267 raeburn 3097: my (%changeHash,%changed);
1.286 raeburn 3098: if ($oldinststatus eq '') {
1.334 raeburn 3099: $oldsettings{'inststatus'} = $othertitle;
1.286 raeburn 3100: } else {
3101: if (ref($usertypes) eq 'HASH') {
1.334 raeburn 3102: $oldsettings{'inststatus'} = join(', ',map{ $usertypes->{ &unescape($_) }; } (split(/:/,$userenv{'inststatus'})));
1.286 raeburn 3103: } else {
1.334 raeburn 3104: $oldsettings{'inststatus'} = join(', ',map{ &unescape($_); } (split(/:/,$userenv{'inststatus'})));
1.286 raeburn 3105: }
3106: }
3107: $changeHash{'inststatus'} = $userenv{'inststatus'};
1.334 raeburn 3108: if ($canmodify_status{'inststatus'}) {
3109: $canshow{'inststatus'} = 1;
1.286 raeburn 3110: if (exists($env{'form.inststatus'})) {
3111: my @inststatuses = &Apache::loncommon::get_env_multiple('form.inststatus');
3112: if (@inststatuses > 0) {
3113: $newinststatus = join(':',map { &escape($_); } @inststatuses);
3114: $changeHash{'inststatus'} = $newinststatus;
3115: if ($newinststatus ne $oldinststatus) {
3116: $changed{'inststatus'} = $newinststatus;
1.378 raeburn 3117: foreach my $name ('portfolio','author') {
3118: ($newdefquota{$name},$newsettingstatus{$name}) =
3119: &Apache::loncommon::default_quota($env{'form.ccdomain'},$newinststatus,$name);
3120: }
1.286 raeburn 3121: }
3122: if (ref($usertypes) eq 'HASH') {
1.334 raeburn 3123: $newsettings{'inststatus'} = join(', ',map{ $usertypes->{$_}; } (@inststatuses));
1.286 raeburn 3124: } else {
1.337 raeburn 3125: $newsettings{'inststatus'} = join(', ',@inststatuses);
1.286 raeburn 3126: }
1.334 raeburn 3127: }
3128: } else {
3129: $newinststatus = '';
3130: $changeHash{'inststatus'} = $newinststatus;
3131: $newsettings{'inststatus'} = $othertitle;
3132: if ($newinststatus ne $oldinststatus) {
3133: $changed{'inststatus'} = $changeHash{'inststatus'};
1.378 raeburn 3134: foreach my $name ('portfolio','author') {
3135: ($newdefquota{$name},$newsettingstatus{$name}) =
3136: &Apache::loncommon::default_quota($env{'form.ccdomain'},$newinststatus,$name);
3137: }
1.286 raeburn 3138: }
3139: }
1.334 raeburn 3140: } elsif ($context ne 'selfcreate') {
3141: $canshow{'inststatus'} = 1;
1.337 raeburn 3142: $newsettings{'inststatus'} = $oldsettings{'inststatus'};
1.286 raeburn 3143: }
1.378 raeburn 3144: foreach my $name ('portfolio','author') {
3145: $changeHash{$name.'quota'} = $userenv{$name.'quota'};
3146: }
1.334 raeburn 3147: if ($context eq 'domain') {
1.378 raeburn 3148: foreach my $name ('portfolio','author') {
3149: if ($userenv{$name.'quota'} ne '') {
3150: $oldquota{$name} = $userenv{$name.'quota'};
3151: if ($env{'form.custom_'.$name.'quota'} == 1) {
3152: if ($env{'form.'.$name.'quota'} eq '') {
3153: $newquota{$name} = 0;
3154: } else {
3155: $newquota{$name} = $env{'form.'.$name.'quota'};
3156: $newquota{$name} =~ s/[^\d\.]//g;
3157: }
3158: if ($newquota{$name} != $oldquota{$name}) {
3159: if ("a_admin($newquota{$name},\%changeHash,$name)) {
3160: $changed{$name.'quota'} = 1;
3161: }
3162: }
1.334 raeburn 3163: } else {
1.378 raeburn 3164: if ("a_admin('',\%changeHash,$name)) {
3165: $changed{$name.'quota'} = 1;
3166: $newquota{$name} = $newdefquota{$name};
3167: $newisdefault{$name} = 1;
3168: }
1.334 raeburn 3169: }
1.149 raeburn 3170: } else {
1.378 raeburn 3171: $oldisdefault{$name} = 1;
3172: $oldquota{$name} = $olddefquota{$name};
3173: if ($env{'form.custom_'.$name.'quota'} == 1) {
3174: if ($env{'form.'.$name.'quota'} eq '') {
3175: $newquota{$name} = 0;
3176: } else {
3177: $newquota{$name} = $env{'form.'.$name.'quota'};
3178: $newquota{$name} =~ s/[^\d\.]//g;
3179: }
3180: if ("a_admin($newquota{$name},\%changeHash,$name)) {
3181: $changed{$name.'quota'} = 1;
3182: }
1.334 raeburn 3183: } else {
1.378 raeburn 3184: $newquota{$name} = $newdefquota{$name};
3185: $newisdefault{$name} = 1;
1.334 raeburn 3186: }
1.378 raeburn 3187: }
3188: if ($oldisdefault{$name}) {
3189: $oldsettingstext{'quota'}{$name} = &get_defaultquota_text($oldsettingstatus{$name});
1.383 raeburn 3190: } else {
3191: $oldsettingstext{'quota'}{$name} = &mt('custom quota: [_1] MB',$oldquota{$name});
1.378 raeburn 3192: }
3193: if ($newisdefault{$name}) {
3194: $newsettingstext{'quota'}{$name} = &get_defaultquota_text($newsettingstatus{$name});
1.383 raeburn 3195: } else {
3196: $newsettingstext{'quota'}{$name} = &mt('custom quota: [_1] MB',$newquota{$name});
1.134 raeburn 3197: }
3198: }
1.334 raeburn 3199: &tool_changes('tools',\@usertools,\%oldsettings,\%oldsettingstext,\%userenv,
3200: \%changeHash,\%changed,\%newsettings,\%newsettingstext);
3201: if ($env{'form.ccdomain'} eq $env{'request.role.domain'}) {
3202: &tool_changes('requestcourses',\@requestcourses,\%oldsettings,\%oldsettingstext,
3203: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
1.384 raeburn 3204: &tool_changes('requestauthor',\@requestauthor,\%oldsettings,\%oldsettingstext,
3205: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
1.149 raeburn 3206: } else {
1.334 raeburn 3207: &tool_changes('reqcrsotherdom',\@requestcourses,\%oldsettings,\%oldsettingstext,
3208: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
1.149 raeburn 3209: }
3210: }
1.334 raeburn 3211: foreach my $item (@userinfo) {
3212: if ($env{'form.c'.$item} ne $userenv{$item}) {
3213: $namechanged{$item} = 1;
3214: }
1.204 raeburn 3215: }
1.378 raeburn 3216: foreach my $name ('portfolio','author') {
1.390 bisitz 3217: $oldsettings{'quota'}{$name} = &mt('[_1] MB',$oldquota{$name});
3218: $newsettings{'quota'}{$name} = &mt('[_1] MB',$newquota{$name});
1.378 raeburn 3219: }
1.334 raeburn 3220: if ((keys(%namechanged) > 0) || (keys(%changed) > 0)) {
1.267 raeburn 3221: my ($chgresult,$namechgresult);
3222: if (keys(%changed) > 0) {
3223: $chgresult =
1.204 raeburn 3224: &Apache::lonnet::put('environment',\%changeHash,
3225: $env{'form.ccdomain'},$env{'form.ccuname'});
1.267 raeburn 3226: if ($chgresult eq 'ok') {
3227: if (($env{'user.name'} eq $env{'form.ccuname'}) &&
3228: ($env{'user.domain'} eq $env{'form.ccdomain'})) {
1.270 raeburn 3229: my %newenvhash;
3230: foreach my $key (keys(%changed)) {
1.299 raeburn 3231: if (($key eq 'official') || ($key eq 'unofficial')
1.403 raeburn 3232: || ($key eq 'community') || ($key eq 'textbook')) {
1.279 raeburn 3233: $newenvhash{'environment.requestcourses.'.$key} =
3234: $changeHash{'requestcourses.'.$key};
1.362 raeburn 3235: if ($changeHash{'requestcourses.'.$key}) {
1.332 raeburn 3236: $newenvhash{'environment.canrequest.'.$key} = 1;
1.279 raeburn 3237: } else {
3238: $newenvhash{'environment.canrequest.'.$key} =
3239: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
3240: $key,'reload','requestcourses');
3241: }
1.362 raeburn 3242: } elsif ($key eq 'requestauthor') {
3243: $newenvhash{'environment.'.$key} = $changeHash{$key};
3244: if ($changeHash{$key}) {
3245: $newenvhash{'environment.canrequest.author'} = 1;
3246: } else {
3247: $newenvhash{'environment.canrequest.author'} =
3248: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
3249: $key,'reload','requestauthor');
3250: }
1.275 raeburn 3251: } elsif ($key ne 'quota') {
1.270 raeburn 3252: $newenvhash{'environment.tools.'.$key} =
3253: $changeHash{'tools.'.$key};
1.279 raeburn 3254: if ($changeHash{'tools.'.$key} ne '') {
3255: $newenvhash{'environment.availabletools.'.$key} =
3256: $changeHash{'tools.'.$key};
3257: } else {
3258: $newenvhash{'environment.availabletools.'.$key} =
1.367 golterma 3259: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
3260: $key,'reload','tools');
1.279 raeburn 3261: }
1.270 raeburn 3262: }
3263: }
1.271 raeburn 3264: if (keys(%newenvhash)) {
3265: &Apache::lonnet::appenv(\%newenvhash);
3266: }
1.267 raeburn 3267: }
3268: }
1.204 raeburn 3269: }
1.334 raeburn 3270: if (keys(%namechanged) > 0) {
1.337 raeburn 3271: foreach my $field (@userinfo) {
3272: $changeHash{$field} = $env{'form.c'.$field};
3273: }
3274: # Make the change
1.204 raeburn 3275: $namechgresult =
3276: &Apache::lonnet::modifyuser($env{'form.ccdomain'},
3277: $env{'form.ccuname'},$changeHash{'id'},undef,undef,
3278: $changeHash{'firstname'},$changeHash{'middlename'},
3279: $changeHash{'lastname'},$changeHash{'generation'},
1.337 raeburn 3280: $changeHash{'id'},undef,$changeHash{'permanentemail'},undef,\@userinfo);
1.220 raeburn 3281: %userupdate = (
3282: lastname => $env{'form.clastname'},
3283: middlename => $env{'form.cmiddlename'},
3284: firstname => $env{'form.cfirstname'},
3285: generation => $env{'form.cgeneration'},
3286: id => $env{'form.cid'},
3287: );
1.204 raeburn 3288: }
1.334 raeburn 3289: if (((keys(%namechanged) > 0) && $namechgresult eq 'ok') ||
1.267 raeburn 3290: ((keys(%changed) > 0) && $chgresult eq 'ok')) {
1.28 matthew 3291: # Tell the user we changed the name
1.334 raeburn 3292: &display_userinfo($r,1,\@disporder,\%canshow,\@requestcourses,
1.362 raeburn 3293: \@usertools,\@requestauthor,\%userenv,\%changed,\%namechanged,
1.334 raeburn 3294: \%oldsettings, \%oldsettingstext,\%newsettings,
3295: \%newsettingstext);
1.203 raeburn 3296: if ($env{'form.cid'} ne $userenv{'id'}) {
3297: &Apache::lonnet::idput($env{'form.ccdomain'},
1.406.2.5 raeburn 3298: {$env{'form.ccuname'} => $env{'form.cid'}});
1.203 raeburn 3299: if (($recurseid) &&
3300: (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'}))) {
3301: my $idresult =
3302: &Apache::lonuserutils::propagate_id_change(
3303: $env{'form.ccuname'},$env{'form.ccdomain'},
3304: \%userupdate);
3305: $r->print('<br />'.$idresult.'<br />');
3306: }
1.196 raeburn 3307: }
1.149 raeburn 3308: if (($env{'form.ccdomain'} eq $env{'user.domain'}) &&
3309: ($env{'form.ccuname'} eq $env{'user.name'})) {
3310: my %newenvhash;
3311: foreach my $key (keys(%changeHash)) {
3312: $newenvhash{'environment.'.$key} = $changeHash{$key};
3313: }
1.238 raeburn 3314: &Apache::lonnet::appenv(\%newenvhash);
1.149 raeburn 3315: }
1.28 matthew 3316: } else { # error occurred
1.389 bisitz 3317: $r->print(
3318: '<p class="LC_error">'
3319: .&mt('Unable to successfully change environment for [_1] in domain [_2].',
3320: '"'.$env{'form.ccuname'}.'"',
3321: '"'.$env{'form.ccdomain'}.'"')
3322: .'</p>');
1.28 matthew 3323: }
1.334 raeburn 3324: } else { # End of if ($env ... ) logic
1.275 raeburn 3325: # They did not want to change the users name, quota, tool availability,
3326: # or ability to request creation of courses,
1.267 raeburn 3327: # but we can still tell them what the name and quota and availabilities are
1.334 raeburn 3328: &display_userinfo($r,undef,\@disporder,\%canshow,\@requestcourses,
1.362 raeburn 3329: \@usertools,\@requestauthor,\%userenv,\%changed,\%namechanged,\%oldsettings,
1.334 raeburn 3330: \%oldsettingstext,\%newsettings,\%newsettingstext);
1.28 matthew 3331: }
1.206 raeburn 3332: if (@mod_disallowed) {
3333: my ($rolestr,$contextname);
3334: if (@longroles > 0) {
3335: $rolestr = join(', ',@longroles);
3336: } else {
3337: $rolestr = &mt('No roles');
3338: }
3339: if ($context eq 'course') {
1.399 bisitz 3340: $contextname = 'course';
1.206 raeburn 3341: } elsif ($context eq 'author') {
1.399 bisitz 3342: $contextname = 'co-author';
1.206 raeburn 3343: }
3344: $r->print(&mt('The following fields were not updated: ').'<ul>');
3345: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
3346: foreach my $field (@mod_disallowed) {
3347: $r->print('<li>'.$fieldtitles{$field}.'</li>'."\n");
3348: }
1.207 raeburn 3349: $r->print('</ul>');
3350: if (@mod_disallowed == 1) {
1.399 bisitz 3351: $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 3352: } else {
1.399 bisitz 3353: $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 3354: }
1.292 bisitz 3355: my $helplink = 'javascript:helpMenu('."'display'".')';
3356: $r->print('<span class="LC_cusr_emph">'.$rolestr.'</span><br />'
3357: .&mt('Please contact your [_1]helpdesk[_2] for more information.'
3358: ,'<a href="'.$helplink.'">','</a>')
3359: .'<br />');
1.206 raeburn 3360: }
1.259 bisitz 3361: $r->print('<span class="LC_warning">'
3362: .$no_forceid_alert
3363: .&Apache::lonuserutils::print_namespacing_alerts($env{'form.ccdomain'},\%alerts,\%curr_rules)
3364: .'</span>');
1.4 www 3365: }
1.367 golterma 3366: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
1.220 raeburn 3367: if ($env{'form.action'} eq 'singlestudent') {
1.375 raeburn 3368: &enroll_single_student($r,$uhome,$amode,$genpwd,$now,$newuser,$context,
3369: $crstype,$showcredits,$defaultcredits);
1.386 bisitz 3370: my $linktext = ($crstype eq 'Community' ?
3371: &mt('Enroll Another Member') : &mt('Enroll Another Student'));
3372: $r->print(
3373: &Apache::lonhtmlcommon::actionbox([
3374: '<a href="javascript:backPage(document.userupdate)">'
3375: .($crstype eq 'Community' ?
3376: &mt('Enroll Another Member') : &mt('Enroll Another Student'))
3377: .'</a>']));
1.220 raeburn 3378: } else {
1.375 raeburn 3379: my @rolechanges = &update_roles($r,$context,$showcredits);
1.334 raeburn 3380: if (keys(%namechanged) > 0) {
1.220 raeburn 3381: if ($context eq 'course') {
3382: if (@userroles > 0) {
1.225 raeburn 3383: if ((@rolechanges == 0) ||
3384: (!(grep(/^st$/,@rolechanges)))) {
3385: if (grep(/^st$/,@userroles)) {
3386: my $classlistupdated =
3387: &Apache::lonuserutils::update_classlist($cdom,
1.220 raeburn 3388: $cnum,$env{'form.ccdomain'},
3389: $env{'form.ccuname'},\%userupdate);
1.225 raeburn 3390: }
1.220 raeburn 3391: }
3392: }
3393: }
3394: }
1.226 raeburn 3395: my $userinfo = &Apache::loncommon::plainname($env{'form.ccuname'},
1.233 raeburn 3396: $env{'form.ccdomain'});
3397: if ($env{'form.popup'}) {
3398: $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a></p>');
3399: } else {
1.367 golterma 3400: $r->print('<br />'.&Apache::lonhtmlcommon::actionbox(['<a href="javascript:backPage(document.userupdate,'."'$env{'form.prevphase'}','modify'".')">'
3401: .&mt('Modify this user: [_1]','<span class="LC_cusr_emph">'.$env{'form.ccuname'}.':'.$env{'form.ccdomain'}.' ('.$userinfo.')</span>').'</a>',
3402: '<a href="javascript:backPage(document.userupdate)">'.&mt('Create/Modify Another User').'</a>']));
1.233 raeburn 3403: }
1.220 raeburn 3404: }
3405: }
3406:
1.334 raeburn 3407: sub display_userinfo {
1.362 raeburn 3408: my ($r,$changed,$order,$canshow,$requestcourses,$usertools,$requestauthor,
3409: $userenv,$changedhash,$namechangedhash,$oldsetting,$oldsettingtext,
1.334 raeburn 3410: $newsetting,$newsettingtext) = @_;
3411: return unless (ref($order) eq 'ARRAY' &&
3412: ref($canshow) eq 'HASH' &&
3413: ref($requestcourses) eq 'ARRAY' &&
1.362 raeburn 3414: ref($requestauthor) eq 'ARRAY' &&
1.334 raeburn 3415: ref($usertools) eq 'ARRAY' &&
3416: ref($userenv) eq 'HASH' &&
3417: ref($changedhash) eq 'HASH' &&
3418: ref($oldsetting) eq 'HASH' &&
3419: ref($oldsettingtext) eq 'HASH' &&
3420: ref($newsetting) eq 'HASH' &&
3421: ref($newsettingtext) eq 'HASH');
3422: my %lt=&Apache::lonlocal::texthash(
1.372 raeburn 3423: 'ui' => 'User Information',
1.334 raeburn 3424: 'uic' => 'User Information Changed',
3425: 'firstname' => 'First Name',
3426: 'middlename' => 'Middle Name',
3427: 'lastname' => 'Last Name',
3428: 'generation' => 'Generation',
3429: 'id' => 'Student/Employee ID',
3430: 'permanentemail' => 'Permanent e-mail address',
1.378 raeburn 3431: 'portfolioquota' => 'Disk space allocated to portfolio files',
1.385 bisitz 3432: 'authorquota' => 'Disk space allocated to Authoring Space',
1.334 raeburn 3433: 'blog' => 'Blog Availability',
1.361 raeburn 3434: 'webdav' => 'WebDAV Availability',
1.334 raeburn 3435: 'aboutme' => 'Personal Information Page Availability',
3436: 'portfolio' => 'Portfolio Availability',
3437: 'official' => 'Can Request Official Courses',
3438: 'unofficial' => 'Can Request Unofficial Courses',
3439: 'community' => 'Can Request Communities',
1.384 raeburn 3440: 'textbook' => 'Can Request Textbook Courses',
1.362 raeburn 3441: 'requestauthor' => 'Can Request Author Role',
1.334 raeburn 3442: 'inststatus' => "Affiliation",
3443: 'prvs' => 'Previous Value:',
3444: 'chto' => 'Changed To:'
3445: );
3446: if ($changed) {
1.372 raeburn 3447: $r->print('<h3>'.$lt{'uic'}.'</h3>'.
1.367 golterma 3448: &Apache::loncommon::start_data_table().
3449: &Apache::loncommon::start_data_table_header_row());
1.334 raeburn 3450: $r->print("<th> </th>\n");
1.367 golterma 3451: $r->print('<th><b>'.$lt{'prvs'}.'</b></th>');
3452: $r->print('<th><span class="LC_nobreak"><b>'.$lt{'chto'}.'</b></span></th>');
3453: $r->print(&Apache::loncommon::end_data_table_header_row());
3454: my @userinfo = ('firstname','middlename','lastname','generation','permanentemail','id');
3455:
1.334 raeburn 3456: foreach my $item (@userinfo) {
3457: my $value = $env{'form.c'.$item};
1.367 golterma 3458: #show changes only:
1.383 raeburn 3459: unless ($value eq $userenv->{$item}){
1.367 golterma 3460: $r->print(&Apache::loncommon::start_data_table_row());
3461: $r->print("<td>$lt{$item}</td>\n");
1.383 raeburn 3462: $r->print("<td>".$userenv->{$item}."</td>\n");
1.367 golterma 3463: $r->print("<td>$value </td>\n");
3464: $r->print(&Apache::loncommon::end_data_table_row());
1.334 raeburn 3465: }
3466: }
3467: foreach my $entry (@{$order}) {
1.383 raeburn 3468: if ($canshow->{$entry}) {
3469: if (($entry eq 'requestcourses') || ($entry eq 'reqcrsotherdom') || ($entry eq 'requestauthor')) {
3470: my @items;
3471: if ($entry eq 'requestauthor') {
3472: @items = ($entry);
3473: } else {
3474: @items = @{$requestcourses};
1.384 raeburn 3475: }
1.383 raeburn 3476: foreach my $item (@items) {
3477: if (($newsetting->{$item} ne $oldsetting->{$item}) ||
3478: ($newsettingtext->{$item} ne $oldsettingtext->{$item})) {
3479: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3480: $r->print("<td>$lt{$item}</td>\n");
3481: $r->print("<td>".$oldsetting->{$item});
3482: if ($oldsettingtext->{$item}) {
3483: if ($oldsetting->{$item}) {
3484: $r->print(' -- ');
3485: }
3486: $r->print($oldsettingtext->{$item});
3487: }
3488: $r->print("</td>\n");
3489: $r->print("<td>".$newsetting->{$item});
3490: if ($newsettingtext->{$item}) {
3491: if ($newsetting->{$item}) {
3492: $r->print(' -- ');
3493: }
3494: $r->print($newsettingtext->{$item});
3495: }
3496: $r->print("</td>\n");
3497: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.334 raeburn 3498: }
3499: }
3500: } elsif ($entry eq 'tools') {
3501: foreach my $item (@{$usertools}) {
1.383 raeburn 3502: if ($newsetting->{$item} ne $oldsetting->{$item}) {
3503: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3504: $r->print("<td>$lt{$item}</td>\n");
3505: $r->print("<td>".$oldsetting->{$item}.' '.$oldsettingtext->{$item}."</td>\n");
3506: $r->print("<td>".$newsetting->{$item}.' '.$newsettingtext->{$item}."</td>\n");
3507: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.334 raeburn 3508: }
3509: }
1.378 raeburn 3510: } elsif ($entry eq 'quota') {
3511: if ((ref($oldsetting->{$entry}) eq 'HASH') && (ref($oldsettingtext->{$entry}) eq 'HASH') &&
3512: (ref($newsetting->{$entry}) eq 'HASH') && (ref($newsettingtext->{$entry}) eq 'HASH')) {
3513: foreach my $name ('portfolio','author') {
1.383 raeburn 3514: if ($newsetting->{$entry}->{$name} ne $oldsetting->{$entry}->{$name}) {
3515: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3516: $r->print("<td>$lt{$name.$entry}</td>\n");
3517: $r->print("<td>".$oldsettingtext->{$entry}->{$name}."</td>\n");
3518: $r->print("<td>".$newsettingtext->{$entry}->{$name}."</td>\n");
3519: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.378 raeburn 3520: }
3521: }
3522: }
1.334 raeburn 3523: } else {
1.383 raeburn 3524: if ($newsetting->{$entry} ne $oldsetting->{$entry}) {
3525: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3526: $r->print("<td>$lt{$entry}</td>\n");
3527: $r->print("<td>".$oldsetting->{$entry}.' '.$oldsettingtext->{$entry}."</td>\n");
3528: $r->print("<td>".$newsetting->{$entry}.' '.$newsettingtext->{$entry}."</td>\n");
3529: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.334 raeburn 3530: }
3531: }
3532: }
3533: }
1.367 golterma 3534: $r->print(&Apache::loncommon::end_data_table().'<br />');
1.372 raeburn 3535: } else {
3536: $r->print('<h3>'.$lt{'ui'}.'</h3>'.
3537: '<p>'.&mt('No changes made to user information').'</p>');
1.334 raeburn 3538: }
3539: return;
3540: }
3541:
1.275 raeburn 3542: sub tool_changes {
3543: my ($context,$usertools,$oldaccess,$oldaccesstext,$userenv,$changeHash,
3544: $changed,$newaccess,$newaccesstext) = @_;
3545: if (!((ref($usertools) eq 'ARRAY') && (ref($oldaccess) eq 'HASH') &&
3546: (ref($oldaccesstext) eq 'HASH') && (ref($userenv) eq 'HASH') &&
3547: (ref($changeHash) eq 'HASH') && (ref($changed) eq 'HASH') &&
3548: (ref($newaccess) eq 'HASH') && (ref($newaccesstext) eq 'HASH'))) {
3549: return;
3550: }
1.383 raeburn 3551: my %reqdisplay = &requestchange_display();
1.300 raeburn 3552: if ($context eq 'reqcrsotherdom') {
1.309 raeburn 3553: my @options = ('approval','validate','autolimit');
1.306 raeburn 3554: my $optregex = join('|',@options);
1.300 raeburn 3555: my $cdom = $env{'request.role.domain'};
3556: foreach my $tool (@{$usertools}) {
1.383 raeburn 3557: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
1.314 raeburn 3558: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
1.300 raeburn 3559: $changeHash->{$context.'.'.$tool} = $userenv->{$context.'.'.$tool};
1.383 raeburn 3560: my ($newop,$limit);
1.314 raeburn 3561: if ($env{'form.'.$context.'_'.$tool}) {
3562: $newop = $env{'form.'.$context.'_'.$tool};
3563: if ($newop eq 'autolimit') {
1.383 raeburn 3564: $limit = $env{'form.'.$context.'_'.$tool.'_limit'};
1.314 raeburn 3565: $limit =~ s/\D+//g;
3566: $newop .= '='.$limit;
3567: }
3568: }
1.300 raeburn 3569: if ($userenv->{$context.'.'.$tool} eq '') {
1.314 raeburn 3570: if ($newop) {
3571: $changed->{$tool}=&tool_admin($tool,$cdom.':'.$newop,
1.300 raeburn 3572: $changeHash,$context);
3573: if ($changed->{$tool}) {
1.383 raeburn 3574: if ($newop =~ /^autolimit/) {
3575: if ($limit) {
3576: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3577: } else {
3578: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3579: }
3580: } else {
3581: $newaccesstext->{$tool} = $reqdisplay{$newop};
3582: }
1.300 raeburn 3583: } else {
3584: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
3585: }
3586: }
3587: } else {
3588: my @curr = split(',',$userenv->{$context.'.'.$tool});
3589: my @new;
3590: my $changedoms;
1.314 raeburn 3591: foreach my $req (@curr) {
3592: if ($req =~ /^\Q$cdom\E\:($optregex\=?\d*)$/) {
3593: my $oldop = $1;
1.383 raeburn 3594: if ($oldop =~ /^autolimit=(\d*)/) {
3595: my $limit = $1;
3596: if ($limit) {
3597: $oldaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3598: } else {
3599: $oldaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3600: }
3601: } else {
3602: $oldaccesstext->{$tool} = $reqdisplay{$oldop};
3603: }
1.314 raeburn 3604: if ($oldop ne $newop) {
3605: $changedoms = 1;
3606: foreach my $item (@curr) {
3607: my ($reqdom,$option) = split(':',$item);
3608: unless ($reqdom eq $cdom) {
3609: push(@new,$item);
3610: }
3611: }
3612: if ($newop) {
3613: push(@new,$cdom.':'.$newop);
1.300 raeburn 3614: }
1.314 raeburn 3615: @new = sort(@new);
1.300 raeburn 3616: }
1.314 raeburn 3617: last;
1.300 raeburn 3618: }
1.314 raeburn 3619: }
3620: if ((!$changedoms) && ($newop)) {
1.300 raeburn 3621: $changedoms = 1;
1.306 raeburn 3622: @new = sort(@curr,$cdom.':'.$newop);
1.300 raeburn 3623: }
3624: if ($changedoms) {
1.314 raeburn 3625: my $newdomstr;
1.300 raeburn 3626: if (@new) {
3627: $newdomstr = join(',',@new);
3628: }
3629: $changed->{$tool}=&tool_admin($tool,$newdomstr,$changeHash,
3630: $context);
3631: if ($changed->{$tool}) {
3632: if ($env{'form.'.$context.'_'.$tool}) {
1.306 raeburn 3633: if ($env{'form.'.$context.'_'.$tool} eq 'autolimit') {
1.314 raeburn 3634: my $limit = $env{'form.'.$context.'_'.$tool.'_limit'};
3635: $limit =~ s/\D+//g;
3636: if ($limit) {
1.383 raeburn 3637: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
1.314 raeburn 3638: } else {
1.383 raeburn 3639: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
1.306 raeburn 3640: }
1.314 raeburn 3641: } else {
1.306 raeburn 3642: $newaccesstext->{$tool} = $reqdisplay{$env{'form.'.$context.'_'.$tool}};
3643: }
1.300 raeburn 3644: } else {
1.383 raeburn 3645: $newaccesstext->{$tool} = &mt("availability set to 'off'");
1.300 raeburn 3646: }
3647: }
3648: }
3649: }
3650: }
3651: return;
3652: }
1.275 raeburn 3653: foreach my $tool (@{$usertools}) {
1.383 raeburn 3654: my ($newval,$limit,$envkey);
1.362 raeburn 3655: $envkey = $context.'.'.$tool;
1.306 raeburn 3656: if ($context eq 'requestcourses') {
3657: $newval = $env{'form.crsreq_'.$tool};
3658: if ($newval eq 'autolimit') {
1.383 raeburn 3659: $limit = $env{'form.crsreq_'.$tool.'_limit'};
3660: $limit =~ s/\D+//g;
3661: $newval .= '='.$limit;
1.306 raeburn 3662: }
1.362 raeburn 3663: } elsif ($context eq 'requestauthor') {
3664: $newval = $env{'form.'.$context};
3665: $envkey = $context;
1.314 raeburn 3666: } else {
1.306 raeburn 3667: $newval = $env{'form.'.$context.'_'.$tool};
3668: }
1.362 raeburn 3669: if ($userenv->{$envkey} ne '') {
1.275 raeburn 3670: $oldaccess->{$tool} = &mt('custom');
1.383 raeburn 3671: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3672: if ($userenv->{$envkey} =~ /^autolimit=(\d*)$/) {
3673: my $currlimit = $1;
3674: if ($currlimit eq '') {
3675: $oldaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3676: } else {
3677: $oldaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$currlimit);
3678: }
3679: } elsif ($userenv->{$envkey}) {
3680: $oldaccesstext->{$tool} = $reqdisplay{$userenv->{$envkey}};
3681: } else {
3682: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
3683: }
1.275 raeburn 3684: } else {
1.383 raeburn 3685: if ($userenv->{$envkey}) {
3686: $oldaccesstext->{$tool} = &mt("availability set to 'on'");
3687: } else {
3688: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
3689: }
1.275 raeburn 3690: }
1.362 raeburn 3691: $changeHash->{$envkey} = $userenv->{$envkey};
1.275 raeburn 3692: if ($env{'form.custom'.$tool} == 1) {
1.362 raeburn 3693: if ($newval ne $userenv->{$envkey}) {
1.306 raeburn 3694: $changed->{$tool} = &tool_admin($tool,$newval,$changeHash,
3695: $context);
1.275 raeburn 3696: if ($changed->{$tool}) {
3697: $newaccess->{$tool} = &mt('custom');
1.383 raeburn 3698: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3699: if ($newval =~ /^autolimit/) {
3700: if ($limit) {
3701: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3702: } else {
3703: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3704: }
3705: } elsif ($newval) {
3706: $newaccesstext->{$tool} = $reqdisplay{$newval};
3707: } else {
3708: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3709: }
1.275 raeburn 3710: } else {
1.383 raeburn 3711: if ($newval) {
3712: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3713: } else {
3714: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3715: }
1.275 raeburn 3716: }
3717: } else {
3718: $newaccess->{$tool} = $oldaccess->{$tool};
1.383 raeburn 3719: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3720: if ($newval =~ /^autolimit/) {
3721: if ($limit) {
3722: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3723: } else {
3724: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3725: }
3726: } elsif ($newval) {
3727: $newaccesstext->{$tool} = $reqdisplay{$newval};
3728: } else {
3729: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3730: }
1.275 raeburn 3731: } else {
1.383 raeburn 3732: if ($userenv->{$context.'.'.$tool}) {
3733: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3734: } else {
3735: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3736: }
1.275 raeburn 3737: }
3738: }
3739: } else {
3740: $newaccess->{$tool} = $oldaccess->{$tool};
3741: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
3742: }
3743: } else {
3744: $changed->{$tool} = &tool_admin($tool,'',$changeHash,$context);
3745: if ($changed->{$tool}) {
3746: $newaccess->{$tool} = &mt('default');
3747: } else {
3748: $newaccess->{$tool} = $oldaccess->{$tool};
1.383 raeburn 3749: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3750: if ($newval =~ /^autolimit/) {
3751: if ($limit) {
3752: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3753: } else {
3754: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3755: }
3756: } elsif ($newval) {
3757: $newaccesstext->{$tool} = $reqdisplay{$newval};
3758: } else {
3759: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3760: }
1.275 raeburn 3761: } else {
1.383 raeburn 3762: if ($userenv->{$context.'.'.$tool}) {
3763: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3764: } else {
3765: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3766: }
1.275 raeburn 3767: }
3768: }
3769: }
3770: } else {
3771: $oldaccess->{$tool} = &mt('default');
3772: if ($env{'form.custom'.$tool} == 1) {
1.306 raeburn 3773: $changed->{$tool} = &tool_admin($tool,$newval,$changeHash,
3774: $context);
1.275 raeburn 3775: if ($changed->{$tool}) {
3776: $newaccess->{$tool} = &mt('custom');
1.383 raeburn 3777: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3778: if ($newval =~ /^autolimit/) {
3779: if ($limit) {
3780: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3781: } else {
3782: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3783: }
3784: } elsif ($newval) {
3785: $newaccesstext->{$tool} = $reqdisplay{$newval};
3786: } else {
3787: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3788: }
1.275 raeburn 3789: } else {
1.383 raeburn 3790: if ($newval) {
3791: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3792: } else {
3793: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3794: }
1.275 raeburn 3795: }
3796: } else {
3797: $newaccess->{$tool} = $oldaccess->{$tool};
3798: }
3799: } else {
3800: $newaccess->{$tool} = $oldaccess->{$tool};
3801: }
3802: }
3803: }
3804: return;
3805: }
3806:
1.220 raeburn 3807: sub update_roles {
1.375 raeburn 3808: my ($r,$context,$showcredits) = @_;
1.4 www 3809: my $now=time;
1.225 raeburn 3810: my @rolechanges;
1.220 raeburn 3811: my %disallowed;
1.73 sakharuk 3812: $r->print('<h3>'.&mt('Modifying Roles').'</h3>');
1.404 raeburn 3813: foreach my $key (keys(%env)) {
1.135 raeburn 3814: next if (! $env{$key});
1.190 raeburn 3815: next if ($key eq 'form.action');
1.27 matthew 3816: # Revoke roles
1.135 raeburn 3817: if ($key=~/^form\.rev/) {
3818: if ($key=~/^form\.rev\:([^\_]+)\_([^\_\.]+)$/) {
1.64 www 3819: # Revoke standard role
1.170 albertel 3820: my ($scope,$role) = ($1,$2);
3821: my $result =
3822: &Apache::lonnet::revokerole($env{'form.ccdomain'},
3823: $env{'form.ccuname'},
1.239 raeburn 3824: $scope,$role,'','',$context);
1.367 golterma 3825: $r->print(&Apache::lonhtmlcommon::confirm_success(
1.369 bisitz 3826: &mt('Revoking [_1] in [_2]',
3827: &Apache::lonnet::plaintext($role),
1.372 raeburn 3828: &Apache::loncommon::show_role_extent($scope,$context,$role)),
1.369 bisitz 3829: $result ne "ok").'<br />');
3830: if ($result ne "ok") {
3831: $r->print(&mt('Error: [_1]',$result).'<br />');
3832: }
1.170 albertel 3833: if ($role eq 'st') {
1.202 raeburn 3834: my $result =
1.198 raeburn 3835: &Apache::lonuserutils::classlist_drop($scope,
3836: $env{'form.ccuname'},$env{'form.ccdomain'},
1.202 raeburn 3837: $now);
1.367 golterma 3838: $r->print(&Apache::lonhtmlcommon::confirm_success($result));
1.53 www 3839: }
1.225 raeburn 3840: if (!grep(/^\Q$role\E$/,@rolechanges)) {
3841: push(@rolechanges,$role);
3842: }
1.196 raeburn 3843: }
1.195 raeburn 3844: if ($key=~m{^form\.rev\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}s) {
1.64 www 3845: # Revoke custom role
1.369 bisitz 3846: my $result = &Apache::lonnet::revokecustomrole(
3847: $env{'form.ccdomain'},$env{'form.ccuname'},$1,$2,$3,$4,'','',$context);
1.367 golterma 3848: $r->print(&Apache::lonhtmlcommon::confirm_success(
1.369 bisitz 3849: &mt('Revoking custom role [_1] by [_2] in [_3]',
1.372 raeburn 3850: $4,$3.':'.$2,&Apache::loncommon::show_role_extent($1,$context,'cr')),
1.369 bisitz 3851: $result ne 'ok').'<br />');
3852: if ($result ne "ok") {
3853: $r->print(&mt('Error: [_1]',$result).'<br />');
3854: }
1.225 raeburn 3855: if (!grep(/^cr$/,@rolechanges)) {
3856: push(@rolechanges,'cr');
3857: }
1.64 www 3858: }
1.135 raeburn 3859: } elsif ($key=~/^form\.del/) {
3860: if ($key=~/^form\.del\:([^\_]+)\_([^\_\.]+)$/) {
1.116 raeburn 3861: # Delete standard role
1.170 albertel 3862: my ($scope,$role) = ($1,$2);
3863: my $result =
3864: &Apache::lonnet::assignrole($env{'form.ccdomain'},
3865: $env{'form.ccuname'},
1.239 raeburn 3866: $scope,$role,$now,0,1,'',
3867: $context);
1.367 golterma 3868: $r->print(&Apache::lonhtmlcommon::confirm_success(
3869: &mt('Deleting [_1] in [_2]',
1.369 bisitz 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.367 golterma 3876:
1.170 albertel 3877: if ($role eq 'st') {
1.202 raeburn 3878: my $result =
1.198 raeburn 3879: &Apache::lonuserutils::classlist_drop($scope,
3880: $env{'form.ccuname'},$env{'form.ccdomain'},
1.202 raeburn 3881: $now);
1.369 bisitz 3882: $r->print(&Apache::lonhtmlcommon::confirm_success($result));
1.81 albertel 3883: }
1.225 raeburn 3884: if (!grep(/^\Q$role\E$/,@rolechanges)) {
3885: push(@rolechanges,$role);
3886: }
1.116 raeburn 3887: }
1.139 albertel 3888: if ($key=~m{^form\.del\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
1.116 raeburn 3889: my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
3890: # Delete custom role
1.369 bisitz 3891: my $result =
3892: &Apache::lonnet::assigncustomrole($env{'form.ccdomain'},
3893: $env{'form.ccuname'},$url,$rdom,$rnam,$rolename,$now,
3894: 0,1,$context);
3895: $r->print(&Apache::lonhtmlcommon::confirm_success(&mt('Deleting custom role [_1] by [_2] in [_3]',
1.372 raeburn 3896: $rolename,$rnam.':'.$rdom,&Apache::loncommon::show_role_extent($1,$context,'cr')),
1.369 bisitz 3897: $result ne "ok").'<br />');
3898: if ($result ne "ok") {
3899: $r->print(&mt('Error: [_1]',$result).'<br />');
3900: }
1.367 golterma 3901:
1.225 raeburn 3902: if (!grep(/^cr$/,@rolechanges)) {
3903: push(@rolechanges,'cr');
3904: }
1.116 raeburn 3905: }
1.135 raeburn 3906: } elsif ($key=~/^form\.ren/) {
1.101 albertel 3907: my $udom = $env{'form.ccdomain'};
3908: my $uname = $env{'form.ccuname'};
1.116 raeburn 3909: # Re-enable standard role
1.135 raeburn 3910: if ($key=~/^form\.ren\:([^\_]+)\_([^\_\.]+)$/) {
1.89 raeburn 3911: my $url = $1;
3912: my $role = $2;
3913: my $logmsg;
3914: my $output;
3915: if ($role eq 'st') {
1.141 albertel 3916: if ($url =~ m-^/($match_domain)/($match_courseid)/?(\w*)$-) {
1.374 raeburn 3917: my ($cdom,$cnum,$csec) = ($1,$2,$3);
1.375 raeburn 3918: my $credits;
3919: if ($showcredits) {
3920: my $defaultcredits =
3921: &Apache::lonuserutils::get_defaultcredits($cdom,$cnum);
3922: $credits = &get_user_credits($defaultcredits,$cdom,$cnum);
3923: }
3924: my $result = &Apache::loncommon::commit_studentrole(\$logmsg,$udom,$uname,$url,$role,$now,0,$cdom,$cnum,$csec,$context,$credits);
1.220 raeburn 3925: if (($result =~ /^error/) || ($result eq 'not_in_class') || ($result eq 'unknown_course') || ($result eq 'refused')) {
1.223 raeburn 3926: if ($result eq 'refused' && $logmsg) {
3927: $output = $logmsg;
3928: } else {
1.369 bisitz 3929: $output = &mt('Error: [_1]',$result)."\n";
1.223 raeburn 3930: }
1.89 raeburn 3931: } else {
1.372 raeburn 3932: $output = &Apache::lonhtmlcommon::confirm_success(&mt('Assigning [_1] in [_2] starting [_3]',
3933: &Apache::lonnet::plaintext($role),
3934: &Apache::loncommon::show_role_extent($url,$context,'st'),
3935: &Apache::lonlocal::locallocaltime($now))).'<br />'.$logmsg.'<br />';
1.89 raeburn 3936: }
3937: }
3938: } else {
1.101 albertel 3939: my $result=&Apache::lonnet::assignrole($env{'form.ccdomain'},
1.239 raeburn 3940: $env{'form.ccuname'},$url,$role,0,$now,'','',
3941: $context);
1.367 golterma 3942: $output = &Apache::lonhtmlcommon::confirm_success(&mt('Re-enabling [_1] in [_2]',
1.372 raeburn 3943: &Apache::lonnet::plaintext($role),
3944: &Apache::loncommon::show_role_extent($url,$context,$role)),$result ne "ok").'<br />';
1.369 bisitz 3945: if ($result ne "ok") {
3946: $output .= &mt('Error: [_1]',$result).'<br />';
3947: }
3948: }
1.89 raeburn 3949: $r->print($output);
1.225 raeburn 3950: if (!grep(/^\Q$role\E$/,@rolechanges)) {
3951: push(@rolechanges,$role);
3952: }
1.113 raeburn 3953: }
1.116 raeburn 3954: # Re-enable custom role
1.139 albertel 3955: if ($key=~m{^form\.ren\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
1.116 raeburn 3956: my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
3957: my $result = &Apache::lonnet::assigncustomrole(
3958: $env{'form.ccdomain'}, $env{'form.ccuname'},
1.240 raeburn 3959: $url,$rdom,$rnam,$rolename,0,$now,undef,$context);
1.369 bisitz 3960: $r->print(&Apache::lonhtmlcommon::confirm_success(
3961: &mt('Re-enabling custom role [_1] by [_2] in [_3]',
1.372 raeburn 3962: $rolename,$rnam.':'.$rdom,&Apache::loncommon::show_role_extent($1,$context,'cr')),
1.369 bisitz 3963: $result ne "ok").'<br />');
3964: if ($result ne "ok") {
3965: $r->print(&mt('Error: [_1]',$result).'<br />');
3966: }
1.225 raeburn 3967: if (!grep(/^cr$/,@rolechanges)) {
3968: push(@rolechanges,'cr');
3969: }
1.116 raeburn 3970: }
1.135 raeburn 3971: } elsif ($key=~/^form\.act/) {
1.101 albertel 3972: my $udom = $env{'form.ccdomain'};
3973: my $uname = $env{'form.ccuname'};
1.141 albertel 3974: if ($key=~/^form\.act\_($match_domain)\_($match_courseid)\_cr_cr_($match_domain)_($match_username)_([^\_]+)$/) {
1.65 www 3975: # Activate a custom role
1.83 albertel 3976: my ($one,$two,$three,$four,$five)=($1,$2,$3,$4,$5);
3977: my $url='/'.$one.'/'.$two;
3978: my $full=$one.'_'.$two.'_cr_cr_'.$three.'_'.$four.'_'.$five;
1.65 www 3979:
1.101 albertel 3980: my $start = ( $env{'form.start_'.$full} ?
3981: $env{'form.start_'.$full} :
1.88 raeburn 3982: $now );
1.101 albertel 3983: my $end = ( $env{'form.end_'.$full} ?
3984: $env{'form.end_'.$full} :
1.88 raeburn 3985: 0 );
3986:
3987: # split multiple sections
3988: my %sections = ();
1.101 albertel 3989: my $num_sections = &build_roles($env{'form.sec_'.$full},\%sections,$5);
1.88 raeburn 3990: if ($num_sections == 0) {
1.240 raeburn 3991: $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$url,$three,$four,$five,$start,$end,$context));
1.88 raeburn 3992: } else {
1.114 albertel 3993: my %curr_groups =
1.117 raeburn 3994: &Apache::longroup::coursegroups($one,$two);
1.404 raeburn 3995: foreach my $sec (sort {$a cmp $b} keys(%sections)) {
1.113 raeburn 3996: if (($sec eq 'none') || ($sec eq 'all') ||
3997: exists($curr_groups{$sec})) {
3998: $disallowed{$sec} = $url;
3999: next;
4000: }
4001: my $securl = $url.'/'.$sec;
1.240 raeburn 4002: $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$securl,$three,$four,$five,$start,$end,$context));
1.88 raeburn 4003: }
4004: }
1.225 raeburn 4005: if (!grep(/^cr$/,@rolechanges)) {
4006: push(@rolechanges,'cr');
4007: }
1.142 raeburn 4008: } elsif ($key=~/^form\.act\_($match_domain)\_($match_name)\_([^\_]+)$/) {
1.27 matthew 4009: # Activate roles for sections with 3 id numbers
4010: # set start, end times, and the url for the class
1.83 albertel 4011: my ($one,$two,$three)=($1,$2,$3);
1.101 albertel 4012: my $start = ( $env{'form.start_'.$one.'_'.$two.'_'.$three} ?
4013: $env{'form.start_'.$one.'_'.$two.'_'.$three} :
1.27 matthew 4014: $now );
1.101 albertel 4015: my $end = ( $env{'form.end_'.$one.'_'.$two.'_'.$three} ?
4016: $env{'form.end_'.$one.'_'.$two.'_'.$three} :
1.27 matthew 4017: 0 );
1.83 albertel 4018: my $url='/'.$one.'/'.$two;
1.88 raeburn 4019: my $type = 'three';
4020: # split multiple sections
4021: my %sections = ();
1.101 albertel 4022: my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two.'_'.$three},\%sections,$three);
1.375 raeburn 4023: my $credits;
4024: if ($three eq 'st') {
4025: if ($showcredits) {
4026: my $defaultcredits =
4027: &Apache::lonuserutils::get_defaultcredits($one,$two);
4028: $credits = $env{'form.credits_'.$one.'_'.$two.'_'.$three};
4029: $credits =~ s/[^\d\.]//g;
4030: if ($credits eq $defaultcredits) {
4031: undef($credits);
4032: }
4033: }
4034: }
1.88 raeburn 4035: if ($num_sections == 0) {
1.375 raeburn 4036: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'',$context,$credits));
1.88 raeburn 4037: } else {
1.114 albertel 4038: my %curr_groups =
1.117 raeburn 4039: &Apache::longroup::coursegroups($one,$two);
1.88 raeburn 4040: my $emptysec = 0;
1.404 raeburn 4041: foreach my $sec (sort {$a cmp $b} keys(%sections)) {
1.88 raeburn 4042: $sec =~ s/\W//g;
1.113 raeburn 4043: if ($sec ne '') {
4044: if (($sec eq 'none') || ($sec eq 'all') ||
4045: exists($curr_groups{$sec})) {
4046: $disallowed{$sec} = $url;
4047: next;
4048: }
1.88 raeburn 4049: my $securl = $url.'/'.$sec;
1.375 raeburn 4050: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$three,$start,$end,$one,$two,$sec,$context,$credits));
1.88 raeburn 4051: } else {
4052: $emptysec = 1;
4053: }
4054: }
4055: if ($emptysec) {
1.375 raeburn 4056: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'',$context,$credits));
1.88 raeburn 4057: }
1.225 raeburn 4058: }
4059: if (!grep(/^\Q$three\E$/,@rolechanges)) {
4060: push(@rolechanges,$three);
4061: }
1.135 raeburn 4062: } elsif ($key=~/^form\.act\_([^\_]+)\_([^\_]+)$/) {
1.27 matthew 4063: # Activate roles for sections with two id numbers
4064: # set start, end times, and the url for the class
1.101 albertel 4065: my $start = ( $env{'form.start_'.$1.'_'.$2} ?
4066: $env{'form.start_'.$1.'_'.$2} :
1.27 matthew 4067: $now );
1.101 albertel 4068: my $end = ( $env{'form.end_'.$1.'_'.$2} ?
4069: $env{'form.end_'.$1.'_'.$2} :
1.27 matthew 4070: 0 );
1.225 raeburn 4071: my $one = $1;
4072: my $two = $2;
4073: my $url='/'.$one.'/';
1.88 raeburn 4074: # split multiple sections
4075: my %sections = ();
1.225 raeburn 4076: my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two},\%sections,$two);
1.88 raeburn 4077: if ($num_sections == 0) {
1.240 raeburn 4078: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,'',$context));
1.88 raeburn 4079: } else {
4080: my $emptysec = 0;
1.404 raeburn 4081: foreach my $sec (sort {$a cmp $b} keys(%sections)) {
1.88 raeburn 4082: if ($sec ne '') {
4083: my $securl = $url.'/'.$sec;
1.240 raeburn 4084: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$two,$start,$end,$one,undef,$sec,$context));
1.88 raeburn 4085: } else {
4086: $emptysec = 1;
4087: }
4088: }
4089: if ($emptysec) {
1.240 raeburn 4090: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,'',$context));
1.88 raeburn 4091: }
4092: }
1.225 raeburn 4093: if (!grep(/^\Q$two\E$/,@rolechanges)) {
4094: push(@rolechanges,$two);
4095: }
1.64 www 4096: } else {
1.190 raeburn 4097: $r->print('<p><span class="LC_error">'.&mt('ERROR').': '.&mt('Unknown command').' <tt>'.$key.'</tt></span></p><br />');
1.64 www 4098: }
1.113 raeburn 4099: foreach my $key (sort(keys(%disallowed))) {
1.274 bisitz 4100: $r->print('<p class="LC_warning">');
1.113 raeburn 4101: if (($key eq 'none') || ($key eq 'all')) {
1.274 bisitz 4102: $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 4103: } else {
1.274 bisitz 4104: $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 4105: }
1.274 bisitz 4106: $r->print('</p><p>'
4107: .&mt('Please [_1]go back[_2] and choose a different section name.'
4108: ,'<a href="javascript:history.go(-1)'
4109: ,'</a>')
4110: .'</p><br />'
4111: );
1.113 raeburn 4112: }
4113: }
1.101 albertel 4114: } # End of foreach (keys(%env))
1.75 www 4115: # Flush the course logs so reverse user roles immediately updated
1.349 raeburn 4116: $r->register_cleanup(\&Apache::lonnet::flushcourselogs);
1.225 raeburn 4117: if (@rolechanges == 0) {
1.372 raeburn 4118: $r->print('<p>'.&mt('No roles to modify').'</p>');
1.193 raeburn 4119: }
1.225 raeburn 4120: return @rolechanges;
1.220 raeburn 4121: }
4122:
1.375 raeburn 4123: sub get_user_credits {
4124: my ($uname,$udom,$defaultcredits,$cdom,$cnum) = @_;
4125: if ($cdom eq '' || $cnum eq '') {
4126: return unless ($env{'request.course.id'});
4127: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
4128: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
4129: }
4130: my $credits;
4131: my %currhash =
4132: &Apache::lonnet::get('classlist',[$uname.':'.$udom],$cdom,$cnum);
4133: if (keys(%currhash) > 0) {
4134: my @items = split(/:/,$currhash{$uname.':'.$udom});
4135: my $crdidx = &Apache::loncoursedata::CL_CREDITS() - 3;
4136: $credits = $items[$crdidx];
4137: $credits =~ s/[^\d\.]//g;
4138: }
4139: if ($credits eq $defaultcredits) {
4140: undef($credits);
4141: }
4142: return $credits;
4143: }
4144:
1.220 raeburn 4145: sub enroll_single_student {
1.375 raeburn 4146: my ($r,$uhome,$amode,$genpwd,$now,$newuser,$context,$crstype,
4147: $showcredits,$defaultcredits) = @_;
1.318 raeburn 4148: $r->print('<h3>');
4149: if ($crstype eq 'Community') {
4150: $r->print(&mt('Enrolling Member'));
4151: } else {
4152: $r->print(&mt('Enrolling Student'));
4153: }
4154: $r->print('</h3>');
1.220 raeburn 4155:
4156: # Remove non alphanumeric values from section
4157: $env{'form.sections'}=~s/\W//g;
4158:
1.375 raeburn 4159: my $credits;
4160: if (($showcredits) && ($env{'form.credits'} ne '')) {
4161: $credits = $env{'form.credits'};
4162: $credits =~ s/[^\d\.]//g;
4163: if ($credits ne '') {
4164: if ($credits eq $defaultcredits) {
4165: undef($credits);
4166: }
4167: }
4168: }
4169:
1.220 raeburn 4170: # Clean out any old student roles the user has in this class.
4171: &Apache::lonuserutils::modifystudent($env{'form.ccdomain'},
4172: $env{'form.ccuname'},$env{'request.course.id'},undef,$uhome);
4173: my ($startdate,$enddate) = &Apache::lonuserutils::get_dates_from_form();
4174: my $enroll_result =
4175: &Apache::lonnet::modify_student_enrollment($env{'form.ccdomain'},
4176: $env{'form.ccuname'},$env{'form.cid'},$env{'form.cfirstname'},
4177: $env{'form.cmiddlename'},$env{'form.clastname'},
4178: $env{'form.generation'},$env{'form.sections'},$enddate,
1.375 raeburn 4179: $startdate,'manual',undef,$env{'request.course.id'},'',$context,
4180: $credits);
1.220 raeburn 4181: if ($enroll_result =~ /^ok/) {
1.381 bisitz 4182: $r->print(&mt('[_1] enrolled','<b>'.$env{'form.ccuname'}.':'.$env{'form.ccdomain'}.'</b>'));
1.220 raeburn 4183: if ($env{'form.sections'} ne '') {
4184: $r->print(' '.&mt('in section [_1]',$env{'form.sections'}));
4185: }
4186: my ($showstart,$showend);
4187: if ($startdate <= $now) {
4188: $showstart = &mt('Access starts immediately');
4189: } else {
4190: $showstart = &mt('Access starts: ').&Apache::lonlocal::locallocaltime($startdate);
4191: }
4192: if ($enddate == 0) {
4193: $showend = &mt('ends: no ending date');
4194: } else {
4195: $showend = &mt('ends: ').&Apache::lonlocal::locallocaltime($enddate);
4196: }
4197: $r->print('.<br />'.$showstart.'; '.$showend);
4198: if ($startdate <= $now && !$newuser) {
1.386 bisitz 4199: $r->print('<p class="LC_info">');
1.318 raeburn 4200: if ($crstype eq 'Community') {
1.392 raeburn 4201: $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 4202: } else {
1.392 raeburn 4203: $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 4204: }
4205: $r->print('</p>');
1.220 raeburn 4206: }
4207: } else {
4208: $r->print(&mt('unable to enroll').": ".$enroll_result);
4209: }
4210: return;
1.188 raeburn 4211: }
4212:
1.204 raeburn 4213: sub get_defaultquota_text {
4214: my ($settingstatus) = @_;
4215: my $defquotatext;
4216: if ($settingstatus eq '') {
1.383 raeburn 4217: $defquotatext = &mt('default');
1.204 raeburn 4218: } else {
4219: my ($usertypes,$order) =
4220: &Apache::lonnet::retrieve_inst_usertypes($env{'form.ccdomain'});
4221: if ($usertypes->{$settingstatus} eq '') {
1.383 raeburn 4222: $defquotatext = &mt('default');
1.204 raeburn 4223: } else {
1.383 raeburn 4224: $defquotatext = &mt('default for [_1]',$usertypes->{$settingstatus});
1.204 raeburn 4225: }
4226: }
4227: return $defquotatext;
4228: }
4229:
1.188 raeburn 4230: sub update_result_form {
4231: my ($uhome) = @_;
4232: my $outcome =
1.367 golterma 4233: '<form name="userupdate" method="post" action="">'."\n";
1.160 raeburn 4234: foreach my $item ('srchby','srchin','srchtype','srchterm','srchdomain','ccuname','ccdomain') {
1.188 raeburn 4235: $outcome .= '<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n";
1.160 raeburn 4236: }
1.207 raeburn 4237: if ($env{'form.origname'} ne '') {
4238: $outcome .= '<input type="hidden" name="origname" value="'.$env{'form.origname'}.'" />'."\n";
4239: }
1.160 raeburn 4240: foreach my $item ('sortby','seluname','seludom') {
4241: if (exists($env{'form.'.$item})) {
1.188 raeburn 4242: $outcome .= '<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n";
1.160 raeburn 4243: }
4244: }
1.188 raeburn 4245: if ($uhome eq 'no_host') {
4246: $outcome .= '<input type="hidden" name="forcenewuser" value="1" />'."\n";
4247: }
4248: $outcome .= '<input type="hidden" name="phase" value="" />'."\n".
1.383 raeburn 4249: '<input type="hidden" name="currstate" value="" />'."\n".
4250: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n".
1.188 raeburn 4251: '</form>';
4252: return $outcome;
1.4 www 4253: }
4254:
1.149 raeburn 4255: sub quota_admin {
1.378 raeburn 4256: my ($setquota,$changeHash,$name) = @_;
1.149 raeburn 4257: my $quotachanged;
4258: if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
4259: # Current user has quota modification privileges
1.267 raeburn 4260: if (ref($changeHash) eq 'HASH') {
4261: $quotachanged = 1;
1.378 raeburn 4262: $changeHash->{$name.'quota'} = $setquota;
1.267 raeburn 4263: }
1.149 raeburn 4264: }
4265: return $quotachanged;
4266: }
4267:
1.267 raeburn 4268: sub tool_admin {
1.275 raeburn 4269: my ($tool,$settool,$changeHash,$context) = @_;
4270: my $canchange = 0;
1.279 raeburn 4271: if ($context eq 'requestcourses') {
1.275 raeburn 4272: if (&Apache::lonnet::allowed('ccc',$env{'form.ccdomain'})) {
4273: $canchange = 1;
4274: }
1.300 raeburn 4275: } elsif ($context eq 'reqcrsotherdom') {
4276: if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
4277: $canchange = 1;
4278: }
1.362 raeburn 4279: } elsif ($context eq 'requestauthor') {
4280: if (&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) {
4281: $canchange = 1;
4282: }
1.275 raeburn 4283: } elsif (&Apache::lonnet::allowed('mut',$env{'form.ccdomain'})) {
4284: # Current user has quota modification privileges
4285: $canchange = 1;
4286: }
1.267 raeburn 4287: my $toolchanged;
1.275 raeburn 4288: if ($canchange) {
1.267 raeburn 4289: if (ref($changeHash) eq 'HASH') {
4290: $toolchanged = 1;
1.362 raeburn 4291: if ($tool eq 'requestauthor') {
4292: $changeHash->{$context} = $settool;
4293: } else {
4294: $changeHash->{$context.'.'.$tool} = $settool;
4295: }
1.267 raeburn 4296: }
4297: }
4298: return $toolchanged;
4299: }
4300:
1.88 raeburn 4301: sub build_roles {
1.89 raeburn 4302: my ($sectionstr,$sections,$role) = @_;
1.88 raeburn 4303: my $num_sections = 0;
4304: if ($sectionstr=~ /,/) {
4305: my @secnums = split/,/,$sectionstr;
1.89 raeburn 4306: if ($role eq 'st') {
4307: $secnums[0] =~ s/\W//g;
4308: $$sections{$secnums[0]} = 1;
4309: $num_sections = 1;
4310: } else {
4311: foreach my $sec (@secnums) {
4312: $sec =~ ~s/\W//g;
1.150 banghart 4313: if (!($sec eq "")) {
1.89 raeburn 4314: if (exists($$sections{$sec})) {
4315: $$sections{$sec} ++;
4316: } else {
4317: $$sections{$sec} = 1;
4318: $num_sections ++;
4319: }
1.88 raeburn 4320: }
4321: }
4322: }
4323: } else {
4324: $sectionstr=~s/\W//g;
4325: unless ($sectionstr eq '') {
4326: $$sections{$sectionstr} = 1;
4327: $num_sections ++;
4328: }
4329: }
1.129 albertel 4330:
1.88 raeburn 4331: return $num_sections;
4332: }
4333:
1.58 www 4334: # ========================================================== Custom Role Editor
4335:
4336: sub custom_role_editor {
1.406.2.14! raeburn 4337: my ($r,$context,$brcrum,$prefix,$permission) = @_;
1.324 raeburn 4338: my $action = $env{'form.customroleaction'};
1.406.2.14! raeburn 4339: my ($rolename,$helpitem);
1.324 raeburn 4340: if ($action eq 'new') {
4341: $rolename=$env{'form.newrolename'};
4342: } else {
4343: $rolename=$env{'form.rolename'};
1.59 www 4344: }
4345:
1.324 raeburn 4346: my ($crstype,$context);
4347: if ($env{'request.course.id'}) {
4348: $crstype = &Apache::loncommon::course_type();
4349: $context = 'course';
1.406.2.14! raeburn 4350: $helpitem = 'Course_Editing_Custom_Roles';
1.324 raeburn 4351: } else {
4352: $context = 'domain';
1.406.2.5 raeburn 4353: $crstype = 'course';
1.406.2.14! raeburn 4354: $helpitem = 'Domain_Editing_Custom_Roles';
1.324 raeburn 4355: }
1.351 raeburn 4356:
4357: $rolename=~s/[^A-Za-z0-9]//gs;
4358: if (!$rolename || $env{'form.phase'} eq 'pickrole') {
1.406.2.14! raeburn 4359: &print_username_entry_form($r,$context,undef,undef,undef,$crstype,$brcrum,
! 4360: $permission);
1.351 raeburn 4361: return;
4362: }
4363:
1.406.2.5 raeburn 4364: my $formname = 'form1';
4365: my %privs=();
4366: my $body_top = '<h2>';
4367: # ------------------------------------------------------- Does this role exist?
1.59 www 4368: my ($rdummy,$roledef)=
4369: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
4370: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1.406.2.5 raeburn 4371: $body_top .= &mt('Existing Role').' "';
1.61 www 4372: # ------------------------------------------------- Get current role privileges
1.406.2.5 raeburn 4373: ($privs{'system'},$privs{'domain'},$privs{'course'})=split(/\_/,$roledef);
4374: if ($privs{'system'} =~ /bre\&S/) {
4375: if ($context eq 'domain') {
4376: $crstype = 'Course';
4377: } elsif ($crstype eq 'Community') {
4378: $privs{'system'} =~ s/bre\&S//;
4379: }
4380: } elsif ($context eq 'domain') {
4381: $crstype = 'Course';
1.324 raeburn 4382: }
1.59 www 4383: } else {
1.406.2.5 raeburn 4384: $body_top .= &mt('New Role').' "';
4385: $roledef='';
1.59 www 4386: }
1.153 banghart 4387: $body_top .= $rolename.'"</h2>';
1.406.2.5 raeburn 4388:
4389: # ------------------------------------------------------- What can be assigned?
4390: my %full=();
4391: my %levels=(
4392: course => {},
4393: domain => {},
4394: system => {},
4395: );
4396: my %levelscurrent=(
4397: course => {},
4398: domain => {},
4399: system => {},
4400: );
4401: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
1.160 raeburn 4402: my ($jsback,$elements) = &crumb_utilities();
1.406.2.5 raeburn 4403: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
4404: my $head_script =
4405: &Apache::lonuserutils::custom_roledefs_js($context,$crstype,$formname,
4406: \%full,\@templateroles,$jsback);
1.351 raeburn 4407: push (@{$brcrum},
1.406.2.5 raeburn 4408: {href => "javascript:backPage(document.$formname,'pickrole','')",
1.351 raeburn 4409: text => "Pick custom role",
4410: faq => 282,bug=>'Instructor Interface',},
1.406.2.5 raeburn 4411: {href => "javascript:backPage(document.$formname,'','')",
1.351 raeburn 4412: text => "Edit custom role",
4413: faq => 282,
4414: bug => 'Instructor Interface',
1.406.2.14! raeburn 4415: help => $helpitem}
1.351 raeburn 4416: );
4417: my $args = { bread_crumbs => $brcrum,
4418: bread_crumbs_component => 'User Management'};
4419: $r->print(&Apache::loncommon::start_page('Custom Role Editor',
4420: $head_script,$args).
4421: $body_top);
1.406.2.5 raeburn 4422: $r->print('<form name="'.$formname.'" method="post" action="">'."\n".
4423: &Apache::lonuserutils::custom_role_header($context,$crstype,
4424: \@templateroles,$prefix));
1.264 bisitz 4425:
1.61 www 4426: $r->print(<<ENDCCF);
4427: <input type="hidden" name="phase" value="set_custom_roles" />
4428: <input type="hidden" name="rolename" value="$rolename" />
4429: ENDCCF
1.406.2.5 raeburn 4430: $r->print(&Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
4431: \%levelscurrent,$prefix));
1.135 raeburn 4432: $r->print(&Apache::loncommon::end_data_table().
1.190 raeburn 4433: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'.
1.160 raeburn 4434: '<input type="hidden" name="startrolename" value="'.$env{'form.rolename'}.
1.406.2.5 raeburn 4435: '" />'."\n".'<input type="hidden" name="currstate" value="" />'."\n".
1.160 raeburn 4436: '<input type="reset" value="'.&mt("Reset").'" />'."\n".
1.351 raeburn 4437: '<input type="submit" value="'.&mt('Save').'" /></form>');
1.61 www 4438: }
1.406.2.5 raeburn 4439:
1.61 www 4440: # ---------------------------------------------------------- Call to definerole
4441: sub set_custom_role {
1.406.2.14! raeburn 4442: my ($r,$context,$brcrum,$prefix,$permission) = @_;
1.101 albertel 4443: my $rolename=$env{'form.rolename'};
1.63 www 4444: $rolename=~s/[^A-Za-z0-9]//gs;
1.150 banghart 4445: if (!$rolename) {
1.406.2.14! raeburn 4446: &custom_role_editor($r,$context,$brcrum,$prefix,$permission);
1.61 www 4447: return;
4448: }
1.160 raeburn 4449: my ($jsback,$elements) = &crumb_utilities();
1.301 bisitz 4450: my $jscript = '<script type="text/javascript">'
4451: .'// <![CDATA['."\n"
4452: .$jsback."\n"
4453: .'// ]]>'."\n"
4454: .'</script>'."\n";
1.406.2.14! raeburn 4455: my $helpitem = 'Course_Editing_Custom_Roles';
! 4456: if ($context eq 'domain') {
! 4457: $helpitem = 'Domain_Editing_Custom_Roles';
! 4458: }
1.352 raeburn 4459: push(@{$brcrum},
4460: {href => "javascript:backPage(document.customresult,'pickrole','')",
4461: text => "Pick custom role",
4462: faq => 282,
4463: bug => 'Instructor Interface',},
4464: {href => "javascript:backPage(document.customresult,'selected_custom_edit','')",
4465: text => "Edit custom role",
4466: faq => 282,
4467: bug => 'Instructor Interface',},
4468: {href => "javascript:backPage(document.customresult,'set_custom_roles','')",
4469: text => "Result",
4470: faq => 282,
4471: bug => 'Instructor Interface',
1.406.2.14! raeburn 4472: help => $helpitem,}
1.352 raeburn 4473: );
4474: my $args = { bread_crumbs => $brcrum,
1.406.2.5 raeburn 4475: bread_crumbs_component => 'User Management'};
1.351 raeburn 4476: $r->print(&Apache::loncommon::start_page('Save Custom Role',$jscript,$args));
1.160 raeburn 4477:
1.393 raeburn 4478: my $newrole;
1.61 www 4479: my ($rdummy,$roledef)=
1.110 albertel 4480: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
4481:
1.61 www 4482: # ------------------------------------------------------- Does this role exist?
1.188 raeburn 4483: $r->print('<h3>');
1.61 www 4484: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1.73 sakharuk 4485: $r->print(&mt('Existing Role').' "');
1.61 www 4486: } else {
1.73 sakharuk 4487: $r->print(&mt('New Role').' "');
1.61 www 4488: $roledef='';
1.393 raeburn 4489: $newrole = 1;
1.61 www 4490: }
1.188 raeburn 4491: $r->print($rolename.'"</h3>');
1.406.2.5 raeburn 4492: # ------------------------------------------------- Assign role and show result
1.61 www 4493:
1.387 bisitz 4494: my $errmsg;
1.406.2.5 raeburn 4495: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$prefix);
4496: # Assign role and return result
4497: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
4498: $newprivs{'c'});
1.387 bisitz 4499: if ($result ne 'ok') {
4500: $errmsg = ': '.$result;
4501: }
4502: my $message =
4503: &Apache::lonhtmlcommon::confirm_success(
4504: &mt('Defining Role').$errmsg, ($result eq 'ok' ? 0 : 1));
1.101 albertel 4505: if ($env{'request.course.id'}) {
4506: my $url='/'.$env{'request.course.id'};
1.63 www 4507: $url=~s/\_/\//g;
1.387 bisitz 4508: $result =
4509: &Apache::lonnet::assigncustomrole(
4510: $env{'user.domain'},$env{'user.name'},
4511: $url,
4512: $env{'user.domain'},$env{'user.name'},
4513: $rolename,undef,undef,undef,$context);
4514: if ($result ne 'ok') {
4515: $errmsg = ': '.$result;
4516: }
4517: $message .=
4518: '<br />'
4519: .&Apache::lonhtmlcommon::confirm_success(
4520: &mt('Assigning Role to Self').$errmsg, ($result eq 'ok' ? 0 : 1));
1.63 www 4521: }
1.380 bisitz 4522: $r->print(
1.387 bisitz 4523: &Apache::loncommon::confirmwrapper($message)
4524: .'<br />'
4525: .&Apache::lonhtmlcommon::actionbox([
4526: '<a href="javascript:backPage(document.customresult,'."'pickrole'".')">'
4527: .&mt('Create or edit another custom role')
4528: .'</a>'])
1.380 bisitz 4529: .'<form name="customresult" method="post" action="">'
1.387 bisitz 4530: .&Apache::lonhtmlcommon::echo_form_input([])
4531: .'</form>'
1.380 bisitz 4532: );
1.58 www 4533: }
4534:
1.2 www 4535: # ================================================================ Main Handler
4536: sub handler {
4537: my $r = shift;
4538: if ($r->header_only) {
1.68 www 4539: &Apache::loncommon::content_type($r,'text/html');
1.2 www 4540: $r->send_http_header;
4541: return OK;
4542: }
1.406.2.14! raeburn 4543: my ($context,$crstype,$cid,$cnum,$cdom,$allhelpitems);
! 4544:
1.190 raeburn 4545: if ($env{'request.course.id'}) {
4546: $context = 'course';
1.318 raeburn 4547: $crstype = &Apache::loncommon::course_type();
1.190 raeburn 4548: } elsif ($env{'request.role'} =~ /^au\./) {
1.206 raeburn 4549: $context = 'author';
1.190 raeburn 4550: } else {
4551: $context = 'domain';
4552: }
1.375 raeburn 4553:
1.406.2.14! raeburn 4554: my ($permission,$allowed) =
! 4555: &Apache::lonuserutils::get_permission($context,$crstype);
! 4556:
! 4557: if ($allowed) {
! 4558: my @allhelp;
! 4559: if ($context eq 'course') {
! 4560: $cid = $env{'request.course.id'};
! 4561: $cdom = $env{'course.'.$cid.'.domain'};
! 4562: $cnum = $env{'course.'.$cid.'.num'};
! 4563:
! 4564: if ($permission->{'cusr'}) {
! 4565: push(@allhelp,'Course_Create_Class_List');
! 4566: }
! 4567: if ($permission->{'view'} || $permission->{'cusr'}) {
! 4568: push(@allhelp,('Course_Change_Privileges','Course_View_Class_List'));
! 4569: }
! 4570: if ($permission->{'custom'}) {
! 4571: push(@allhelp,'Course_Editing_Custom_Roles');
! 4572: }
! 4573: if ($permission->{'cusr'}) {
! 4574: push(@allhelp,('Course_Add_Student','Course_Drop_Student'));
! 4575: }
! 4576: unless ($permission->{'cusr_section'}) {
! 4577: if (&Apache::lonnet::auto_run($cnum,$cdom) && (($permission->{'cusr'}) || ($permission->{'view'}))) {
! 4578: push(@allhelp,'Course_Automated_Enrollment');
! 4579: }
! 4580: if ($permission->{'selfenrolladmin'}) {
! 4581: push(@allhelp,'Course_Approve_Selfenroll');
! 4582: }
! 4583: }
! 4584: if ($permission->{'grp_manage'}) {
! 4585: push(@allhelp,'Course_Manage_Group');
! 4586: }
! 4587: if ($permission->{'view'} || $permission->{'cusr'}) {
! 4588: push(@allhelp,'Course_User_Logs');
! 4589: }
! 4590: } elsif ($context eq 'author') {
! 4591: push(@allhelp,('Author_Change_Privileges','Author_Create_Coauthor_List',
! 4592: 'Author_View_Coauthor_List','Author_User_Logs'));
! 4593: } else {
! 4594: if ($permission->{'cusr'}) {
! 4595: push(@allhelp,'Domain_Change_Privileges');
! 4596: if ($permission->{'activity'}) {
! 4597: push(@allhelp,'Domain_User_Access_Logs');
! 4598: }
! 4599: push(@allhelp,('Domain_Create_Users','Domain_View_Users_List'));
! 4600: if ($permission->{'custom'}) {
! 4601: push(@allhelp,'Domain_Editing_Custom_Roles');
! 4602: }
! 4603: push(@allhelp,('Domain_Role_Approvals','Domain_Username_Approvals','Domain_Change_Logs'));
! 4604: } elsif ($permission->{'view'}) {
! 4605: push(@allhelp,'Domain_View_Privileges');
! 4606: if ($permission->{'activity'}) {
! 4607: push(@allhelp,'Domain_User_Access_Logs');
! 4608: }
! 4609: push(@allhelp,('Domain_View_Users_List','Domain_Change_Logs'));
! 4610: }
! 4611: }
! 4612: if (@allhelp) {
! 4613: $allhelpitems = join(',',@allhelp);
! 4614: }
! 4615: }
! 4616:
1.190 raeburn 4617: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.233 raeburn 4618: ['action','state','callingform','roletype','showrole','bulkaction','popup','phase',
1.391 raeburn 4619: 'username','domain','srchterm','srchdomain','srchin','srchby','srchtype','queue']);
1.190 raeburn 4620: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.351 raeburn 4621: my $args;
4622: my $brcrum = [];
4623: my $bread_crumbs_component = 'User Management';
1.391 raeburn 4624: if (($env{'form.action'} ne 'dateselect') && ($env{'form.action'} ne 'displayuserreq')) {
1.351 raeburn 4625: $brcrum = [{href=>"/adm/createuser",
4626: text=>"User Management",
1.406.2.14! raeburn 4627: help=>$allhelpitems}
1.351 raeburn 4628: ];
1.202 raeburn 4629: }
1.190 raeburn 4630: if (!$allowed) {
1.358 raeburn 4631: if ($context eq 'course') {
4632: $r->internal_redirect('/adm/viewclasslist');
4633: return OK;
4634: }
1.190 raeburn 4635: $env{'user.error.msg'}=
4636: "/adm/createuser:cst:0:0:Cannot create/modify user data ".
4637: "or view user status.";
4638: return HTTP_NOT_ACCEPTABLE;
4639: }
4640:
4641: &Apache::loncommon::content_type($r,'text/html');
4642: $r->send_http_header;
4643:
1.375 raeburn 4644: my $showcredits;
4645: if ((($context eq 'course') && ($crstype eq 'Course')) ||
4646: ($context eq 'domain')) {
4647: my %domdefaults =
4648: &Apache::lonnet::get_domain_defaults($env{'request.role.domain'});
4649: if ($domdefaults{'officialcredits'} || $domdefaults{'unofficialcredits'}) {
4650: $showcredits = 1;
4651: }
4652: }
4653:
1.190 raeburn 4654: # Main switch on form.action and form.state, as appropriate
4655: if (! exists($env{'form.action'})) {
1.351 raeburn 4656: $args = {bread_crumbs => $brcrum,
4657: bread_crumbs_component => $bread_crumbs_component};
4658: $r->print(&header(undef,$args));
1.318 raeburn 4659: $r->print(&print_main_menu($permission,$context,$crstype));
1.190 raeburn 4660: } elsif ($env{'form.action'} eq 'upload' && $permission->{'cusr'}) {
1.406.2.14! raeburn 4661: my $helpitem = 'Course_Create_Class_List';
! 4662: if ($context eq 'author') {
! 4663: $helpitem = 'Author_Create_Coauthor_List';
! 4664: } elsif ($context eq 'domain') {
! 4665: $helpitem = 'Domain_Create_Users';
! 4666: }
1.351 raeburn 4667: push(@{$brcrum},
4668: { href => '/adm/createuser?action=upload&state=',
4669: text => 'Upload Users List',
1.406.2.14! raeburn 4670: help => $helpitem,
1.351 raeburn 4671: });
4672: $bread_crumbs_component = 'Upload Users List';
4673: $args = {bread_crumbs => $brcrum,
4674: bread_crumbs_component => $bread_crumbs_component};
4675: $r->print(&header(undef,$args));
1.190 raeburn 4676: $r->print('<form name="studentform" method="post" '.
4677: 'enctype="multipart/form-data" '.
4678: ' action="/adm/createuser">'."\n");
4679: if (! exists($env{'form.state'})) {
4680: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
4681: } elsif ($env{'form.state'} eq 'got_file') {
1.375 raeburn 4682: &Apache::lonuserutils::print_upload_manager_form($r,$context,$permission,
4683: $crstype,$showcredits);
1.190 raeburn 4684: } elsif ($env{'form.state'} eq 'enrolling') {
4685: if ($env{'form.datatoken'}) {
1.375 raeburn 4686: &Apache::lonuserutils::upfile_drop_add($r,$context,$permission,
4687: $showcredits);
1.190 raeburn 4688: }
4689: } else {
4690: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
4691: }
1.406.2.5 raeburn 4692: } elsif (((($env{'form.action'} eq 'singleuser') || ($env{'form.action'}
4693: eq 'singlestudent')) && ($permission->{'cusr'})) ||
1.406.2.6 raeburn 4694: (($env{'form.action'} eq 'singleuser') && ($permission->{'view'})) ||
1.406.2.5 raeburn 4695: (($env{'form.action'} eq 'accesslogs') && ($permission->{'activity'}))) {
1.190 raeburn 4696: my $phase = $env{'form.phase'};
4697: my @search = ('srchterm','srchby','srchin','srchtype','srchdomain');
1.192 albertel 4698: &Apache::loncreateuser::restore_prev_selections();
4699: my $srch;
4700: foreach my $item (@search) {
4701: $srch->{$item} = $env{'form.'.$item};
4702: }
1.207 raeburn 4703: if (($phase eq 'get_user_info') || ($phase eq 'userpicked') ||
1.406.2.5 raeburn 4704: ($phase eq 'createnewuser') || ($phase eq 'activity')) {
1.207 raeburn 4705: if ($env{'form.phase'} eq 'createnewuser') {
4706: my $response;
4707: if ($env{'form.srchterm'} !~ /^$match_username$/) {
1.366 bisitz 4708: my $response =
4709: '<span class="LC_warning">'
4710: .&mt('You must specify a valid username. Only the following are allowed:'
4711: .' letters numbers - . @')
4712: .'</span>';
1.221 raeburn 4713: $env{'form.phase'} = '';
1.375 raeburn 4714: &print_username_entry_form($r,$context,$response,$srch,undef,
1.406.2.14! raeburn 4715: $crstype,$brcrum,$permission);
1.207 raeburn 4716: } else {
4717: my $ccuname =&LONCAPA::clean_username($srch->{'srchterm'});
4718: my $ccdomain=&LONCAPA::clean_domain($srch->{'srchdomain'});
4719: &print_user_modification_page($r,$ccuname,$ccdomain,
1.221 raeburn 4720: $srch,$response,$context,
1.375 raeburn 4721: $permission,$crstype,$brcrum,
4722: $showcredits);
1.207 raeburn 4723: }
4724: } elsif ($env{'form.phase'} eq 'get_user_info') {
1.190 raeburn 4725: my ($currstate,$response,$forcenewuser,$results) =
1.221 raeburn 4726: &user_search_result($context,$srch);
1.190 raeburn 4727: if ($env{'form.currstate'} eq 'modify') {
4728: $currstate = $env{'form.currstate'};
4729: }
4730: if ($currstate eq 'select') {
4731: &print_user_selection_page($r,$response,$srch,$results,
1.351 raeburn 4732: \@search,$context,undef,$crstype,
4733: $brcrum);
1.406.2.5 raeburn 4734: } elsif (($currstate eq 'modify') || ($env{'form.action'} eq 'accesslogs')) {
4735: my ($ccuname,$ccdomain,$uhome);
1.190 raeburn 4736: if (($srch->{'srchby'} eq 'uname') &&
4737: ($srch->{'srchtype'} eq 'exact')) {
4738: $ccuname = $srch->{'srchterm'};
4739: $ccdomain= $srch->{'srchdomain'};
4740: } else {
4741: my @matchedunames = keys(%{$results});
4742: ($ccuname,$ccdomain) = split(/:/,$matchedunames[0]);
4743: }
4744: $ccuname =&LONCAPA::clean_username($ccuname);
4745: $ccdomain=&LONCAPA::clean_domain($ccdomain);
1.406.2.5 raeburn 4746: if ($env{'form.action'} eq 'accesslogs') {
4747: my $uhome;
4748: if (($ccuname ne '') && ($ccdomain ne '')) {
4749: $uhome = &Apache::lonnet::homeserver($ccuname,$ccdomain);
4750: }
4751: if (($uhome eq '') || ($uhome eq 'no_host')) {
4752: $env{'form.phase'} = '';
4753: undef($forcenewuser);
4754: #if ($response) {
4755: # unless ($response =~ m{\Q<br /><br />\E$}) {
4756: # $response .= '<br /><br />';
4757: # }
4758: #}
4759: &print_username_entry_form($r,$context,$response,$srch,
1.406.2.14! raeburn 4760: $forcenewuser,$crstype,$brcrum,
! 4761: $permission);
1.406.2.5 raeburn 4762: } else {
4763: &print_useraccesslogs_display($r,$ccuname,$ccdomain,$permission,$brcrum);
4764: }
4765: } else {
4766: if ($env{'form.forcenewuser'}) {
4767: $response = '';
4768: }
4769: &print_user_modification_page($r,$ccuname,$ccdomain,
4770: $srch,$response,$context,
4771: $permission,$crstype,$brcrum);
1.190 raeburn 4772: }
4773: } elsif ($currstate eq 'query') {
1.351 raeburn 4774: &print_user_query_page($r,'createuser',$brcrum);
1.190 raeburn 4775: } else {
1.229 raeburn 4776: $env{'form.phase'} = '';
1.207 raeburn 4777: &print_username_entry_form($r,$context,$response,$srch,
1.406.2.14! raeburn 4778: $forcenewuser,$crstype,$brcrum,
! 4779: $permission);
1.190 raeburn 4780: }
4781: } elsif ($env{'form.phase'} eq 'userpicked') {
4782: my $ccuname = &LONCAPA::clean_username($env{'form.seluname'});
4783: my $ccdomain = &LONCAPA::clean_domain($env{'form.seludom'});
1.406.2.5 raeburn 4784: if ($env{'form.action'} eq 'accesslogs') {
4785: &print_useraccesslogs_display($r,$ccuname,$ccdomain,$permission,$brcrum);
4786: } else {
4787: &print_user_modification_page($r,$ccuname,$ccdomain,$srch,'',
4788: $context,$permission,$crstype,
4789: $brcrum);
4790: }
4791: } elsif ($env{'form.action'} eq 'accesslogs') {
4792: my $ccuname = &LONCAPA::clean_username($env{'form.accessuname'});
4793: my $ccdomain = &LONCAPA::clean_domain($env{'form.accessudom'});
4794: &print_useraccesslogs_display($r,$ccuname,$ccdomain,$permission,$brcrum);
1.190 raeburn 4795: }
4796: } elsif ($env{'form.phase'} eq 'update_user_data') {
1.375 raeburn 4797: &update_user_data($r,$context,$crstype,$brcrum,$showcredits);
1.190 raeburn 4798: } else {
1.351 raeburn 4799: &print_username_entry_form($r,$context,undef,$srch,undef,$crstype,
1.406.2.14! raeburn 4800: $brcrum,$permission);
1.190 raeburn 4801: }
4802: } elsif ($env{'form.action'} eq 'custom' && $permission->{'custom'}) {
1.406.2.5 raeburn 4803: my $prefix;
1.190 raeburn 4804: if ($env{'form.phase'} eq 'set_custom_roles') {
1.406.2.14! raeburn 4805: &set_custom_role($r,$context,$brcrum,$prefix,$permission);
1.190 raeburn 4806: } else {
1.406.2.14! raeburn 4807: &custom_role_editor($r,$context,$brcrum,$prefix,$permission);
1.190 raeburn 4808: }
1.362 raeburn 4809: } elsif (($env{'form.action'} eq 'processauthorreq') &&
4810: ($permission->{'cusr'}) &&
4811: (&Apache::lonnet::allowed('cau',$env{'request.role.domain'}))) {
4812: push(@{$brcrum},
4813: {href => '/adm/createuser?action=processauthorreq',
1.385 bisitz 4814: text => 'Authoring Space requests',
1.362 raeburn 4815: help => 'Domain_Role_Approvals'});
4816: $bread_crumbs_component = 'Authoring requests';
4817: if ($env{'form.state'} eq 'done') {
4818: push(@{$brcrum},
4819: {href => '/adm/createuser?action=authorreqqueue',
4820: text => 'Result',
4821: help => 'Domain_Role_Approvals'});
4822: $bread_crumbs_component = 'Authoring request result';
4823: }
4824: $args = { bread_crumbs => $brcrum,
4825: bread_crumbs_component => $bread_crumbs_component};
1.391 raeburn 4826: my $js = &usernamerequest_javascript();
4827: $r->print(&header(&add_script($js),$args));
1.362 raeburn 4828: if (!exists($env{'form.state'})) {
4829: $r->print(&Apache::loncoursequeueadmin::display_queued_requests('requestauthor',
4830: $env{'request.role.domain'}));
4831: } elsif ($env{'form.state'} eq 'done') {
4832: $r->print('<h3>'.&mt('Authoring request processing').'</h3>'."\n");
4833: $r->print(&Apache::loncoursequeueadmin::update_request_queue('requestauthor',
4834: $env{'request.role.domain'}));
4835: }
1.391 raeburn 4836: } elsif (($env{'form.action'} eq 'processusernamereq') &&
4837: ($permission->{'cusr'}) &&
4838: (&Apache::lonnet::allowed('cau',$env{'request.role.domain'}))) {
4839: push(@{$brcrum},
4840: {href => '/adm/createuser?action=processusernamereq',
4841: text => 'LON-CAPA account requests',
4842: help => 'Domain_Username_Approvals'});
4843: $bread_crumbs_component = 'Account requests';
4844: if ($env{'form.state'} eq 'done') {
4845: push(@{$brcrum},
4846: {href => '/adm/createuser?action=usernamereqqueue',
4847: text => 'Result',
4848: help => 'Domain_Username_Approvals'});
4849: $bread_crumbs_component = 'LON-CAPA account request result';
4850: }
4851: $args = { bread_crumbs => $brcrum,
4852: bread_crumbs_component => $bread_crumbs_component};
4853: my $js = &usernamerequest_javascript();
4854: $r->print(&header(&add_script($js),$args));
4855: if (!exists($env{'form.state'})) {
4856: $r->print(&Apache::loncoursequeueadmin::display_queued_requests('requestusername',
4857: $env{'request.role.domain'}));
4858: } elsif ($env{'form.state'} eq 'done') {
4859: $r->print('<h3>'.&mt('LON-CAPA account request processing').'</h3>'."\n");
4860: $r->print(&Apache::loncoursequeueadmin::update_request_queue('requestusername',
4861: $env{'request.role.domain'}));
4862: }
4863: } elsif (($env{'form.action'} eq 'displayuserreq') &&
4864: ($permission->{'cusr'})) {
4865: my $dom = $env{'form.domain'};
4866: my $uname = $env{'form.username'};
4867: my $warning;
4868: if (($dom =~ /^$match_domain$/) && (&Apache::lonnet::domain($dom) ne '')) {
4869: if (($dom eq $env{'request.role.domain'}) && (&Apache::lonnet::allowed('ccc',$dom))) {
4870: if (($uname =~ /^$match_username$/) && ($env{'form.queue'} eq 'approval')) {
4871: my $uhome = &Apache::lonnet::homeserver($uname,$dom);
4872: if ($uhome eq 'no_host') {
4873: my $queue = $env{'form.queue'};
4874: my $reqkey = &escape($uname).'_'.$queue;
4875: my $namespace = 'usernamequeue';
4876: my $domconfig = &Apache::lonnet::get_domainconfiguser($dom);
4877: my %queued =
4878: &Apache::lonnet::get($namespace,[$reqkey],$dom,$domconfig);
4879: unless ($queued{$reqkey}) {
4880: $warning = &mt('No information was found for this LON-CAPA account request.');
4881: }
4882: } else {
4883: $warning = &mt('A LON-CAPA account already exists for the requested username and domain.');
4884: }
4885: } else {
4886: $warning = &mt('LON-CAPA account request status check is for an invalid username.');
4887: }
4888: } else {
4889: $warning = &mt('You do not have rights to view LON-CAPA account requests in the domain specified.');
4890: }
4891: } else {
4892: $warning = &mt('LON-CAPA account request status check is for an invalid domain.');
4893: }
4894: my $args = { only_body => 1 };
4895: $r->print(&header(undef,$args).
4896: '<h3>'.&mt('LON-CAPA Account Request Details').'</h3>');
4897: if ($warning ne '') {
4898: $r->print('<div class="LC_warning">'.$warning.'</div>');
4899: } else {
4900: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
4901: my $domconfiguser = &Apache::lonnet::get_domainconfiguser($dom);
4902: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
4903: if (ref($domconfig{'usercreation'}) eq 'HASH') {
4904: if (ref($domconfig{'usercreation'}{'cancreate'}) eq 'HASH') {
4905: if (ref($domconfig{'usercreation'}{'cancreate'}{'emailusername'}) eq 'HASH') {
4906: my %info =
4907: &Apache::lonnet::get('nohist_requestedusernames',[$uname],$dom,$domconfiguser);
4908: if (ref($info{$uname}) eq 'HASH') {
1.396 raeburn 4909: my $usertype = $info{$uname}{'inststatus'};
4910: unless ($usertype) {
4911: $usertype = 'default';
4912: }
4913: if (ref($domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}) eq 'HASH') {
4914: if ((ref($infofields) eq 'ARRAY') && (ref($infotitles) eq 'HASH')) {
4915: $r->print('<div>'.&Apache::lonhtmlcommon::start_pick_box());
4916: my ($num,$count,$showstatus);
4917: $count = scalar(keys(%{$domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}}));
4918: unless ($usertype eq 'default') {
4919: my ($othertitle,$usertypes,$types) =
4920: &Apache::loncommon::sorted_inst_types($dom);
4921: if (ref($usertypes) eq 'HASH') {
4922: if ($usertypes->{$usertype}) {
4923: $showstatus = $usertypes->{$usertype};
4924: $count ++;
4925: }
4926: }
4927: }
4928: foreach my $field (@{$infofields}) {
4929: next unless ($domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}{$field});
4930: next unless ($infotitles->{$field});
4931: $r->print(&Apache::lonhtmlcommon::row_title($infotitles->{$field}).
4932: $info{$uname}{$field});
4933: $num ++;
4934: if ($count == $num) {
4935: $r->print(&Apache::lonhtmlcommon::row_closure(1));
4936: } else {
4937: $r->print(&Apache::lonhtmlcommon::row_closure());
4938: }
4939: }
4940: if ($showstatus) {
4941: $r->print(&Apache::lonhtmlcommon::row_title(&mt('Status type (self-reported)')).
4942: $showstatus.
4943: &Apache::lonhtmlcommon::row_closure(1));
1.391 raeburn 4944: }
1.396 raeburn 4945: $r->print(&Apache::lonhtmlcommon::end_pick_box().'</div>');
1.391 raeburn 4946: }
4947: }
4948: }
4949: }
4950: }
4951: }
4952: $r->print(&close_popup_form());
4953: }
1.207 raeburn 4954: } elsif (($env{'form.action'} eq 'listusers') &&
4955: ($permission->{'view'} || $permission->{'cusr'})) {
1.406.2.14! raeburn 4956: my $helpitem = 'Course_View_Class_List';
! 4957: if ($context eq 'author') {
! 4958: $helpitem = 'Author_View_Coauthor_List';
! 4959: } elsif ($context eq 'domain') {
! 4960: $helpitem = 'Domain_View_Users_List';
! 4961: }
1.202 raeburn 4962: if ($env{'form.phase'} eq 'bulkchange') {
1.351 raeburn 4963: push(@{$brcrum},
4964: {href => '/adm/createuser?action=listusers',
4965: text => "List Users"},
4966: {href => "/adm/createuser",
4967: text => "Result",
1.406.2.14! raeburn 4968: help => $helpitem});
1.351 raeburn 4969: $bread_crumbs_component = 'Update Users';
4970: $args = {bread_crumbs => $brcrum,
4971: bread_crumbs_component => $bread_crumbs_component};
4972: $r->print(&header(undef,$args));
1.202 raeburn 4973: my $setting = $env{'form.roletype'};
4974: my $choice = $env{'form.bulkaction'};
4975: if ($permission->{'cusr'}) {
1.336 raeburn 4976: &Apache::lonuserutils::update_user_list($r,$context,$setting,$choice,$crstype);
1.221 raeburn 4977: } else {
4978: $r->print(&mt('You are not authorized to make bulk changes to user roles'));
1.223 raeburn 4979: $r->print('<p><a href="/adm/createuser?action=listusers">'.&mt('Display User Lists').'</a>');
1.202 raeburn 4980: }
4981: } else {
1.351 raeburn 4982: push(@{$brcrum},
4983: {href => '/adm/createuser?action=listusers',
4984: text => "List Users",
1.406.2.14! raeburn 4985: help => $helpitem});
1.351 raeburn 4986: $bread_crumbs_component = 'List Users';
4987: $args = {bread_crumbs => $brcrum,
4988: bread_crumbs_component => $bread_crumbs_component};
1.202 raeburn 4989: my ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles);
4990: my $formname = 'studentform';
1.364 raeburn 4991: my $hidecall = "hide_searching();";
1.321 raeburn 4992: if (($context eq 'domain') && (($env{'form.roletype'} eq 'course') ||
4993: ($env{'form.roletype'} eq 'community'))) {
4994: if ($env{'form.roletype'} eq 'course') {
4995: ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles) =
4996: &Apache::lonuserutils::courses_selector($env{'request.role.domain'},
4997: $formname);
4998: } elsif ($env{'form.roletype'} eq 'community') {
4999: $cb_jscript =
5000: &Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
5001: my %elements = (
5002: coursepick => 'radio',
5003: coursetotal => 'text',
5004: courselist => 'text',
5005: );
5006: $jscript = &Apache::lonhtmlcommon::set_form_elements(\%elements);
5007: }
1.364 raeburn 5008: $jscript .= &verify_user_display($context)."\n".
5009: &Apache::loncommon::check_uncheck_jscript();
1.202 raeburn 5010: my $js = &add_script($jscript).$cb_jscript;
5011: my $loadcode =
5012: &Apache::lonuserutils::course_selector_loadcode($formname);
5013: if ($loadcode ne '') {
1.364 raeburn 5014: $args->{add_entries} = {onload => "$loadcode;$hidecall"};
5015: } else {
5016: $args->{add_entries} = {onload => $hidecall};
1.202 raeburn 5017: }
1.351 raeburn 5018: $r->print(&header($js,$args));
1.191 raeburn 5019: } else {
1.364 raeburn 5020: $args->{add_entries} = {onload => $hidecall};
5021: $jscript = &verify_user_display($context).
5022: &Apache::loncommon::check_uncheck_jscript();
5023: $r->print(&header(&add_script($jscript),$args));
1.191 raeburn 5024: }
1.202 raeburn 5025: &Apache::lonuserutils::print_userlist($r,undef,$permission,$context,
1.375 raeburn 5026: $formname,$totcodes,$codetitles,$idlist,$idlist_titles,
5027: $showcredits);
1.191 raeburn 5028: }
1.213 raeburn 5029: } elsif ($env{'form.action'} eq 'drop' && $permission->{'cusr'}) {
1.318 raeburn 5030: my $brtext;
5031: if ($crstype eq 'Community') {
5032: $brtext = 'Drop Members';
5033: } else {
5034: $brtext = 'Drop Students';
5035: }
1.351 raeburn 5036: push(@{$brcrum},
5037: {href => '/adm/createuser?action=drop',
5038: text => $brtext,
5039: help => 'Course_Drop_Student'});
5040: if ($env{'form.state'} eq 'done') {
5041: push(@{$brcrum},
5042: {href=>'/adm/createuser?action=drop',
5043: text=>"Result"});
5044: }
5045: $bread_crumbs_component = $brtext;
5046: $args = {bread_crumbs => $brcrum,
5047: bread_crumbs_component => $bread_crumbs_component};
5048: $r->print(&header(undef,$args));
1.213 raeburn 5049: if (!exists($env{'form.state'})) {
1.318 raeburn 5050: &Apache::lonuserutils::print_drop_menu($r,$context,$permission,$crstype);
1.213 raeburn 5051: } elsif ($env{'form.state'} eq 'done') {
5052: &Apache::lonuserutils::update_user_list($r,$context,undef,
5053: $env{'form.action'});
5054: }
1.202 raeburn 5055: } elsif ($env{'form.action'} eq 'dateselect') {
5056: if ($permission->{'cusr'}) {
1.351 raeburn 5057: $r->print(&header(undef,{'no_nav_bar' => 1}).
1.375 raeburn 5058: &Apache::lonuserutils::date_section_selector($context,$permission,
5059: $crstype,$showcredits));
1.202 raeburn 5060: } else {
1.351 raeburn 5061: $r->print(&header(undef,{'no_nav_bar' => 1}).
5062: '<span class="LC_error">'.&mt('You do not have permission to modify dates or sections for users').'</span>');
1.202 raeburn 5063: }
1.237 raeburn 5064: } elsif ($env{'form.action'} eq 'selfenroll') {
1.398 raeburn 5065: if ($permission->{selfenrolladmin}) {
5066: my %currsettings = (
5067: selfenroll_types => $env{'course.'.$cid.'.internal.selfenroll_types'},
5068: selfenroll_registered => $env{'course.'.$cid.'.internal.selfenroll_registered'},
5069: selfenroll_section => $env{'course.'.$cid.'.internal.selfenroll_section'},
5070: selfenroll_notifylist => $env{'course.'.$cid.'.internal.selfenroll_notifylist'},
5071: selfenroll_approval => $env{'course.'.$cid.'.internal.selfenroll_approval'},
5072: selfenroll_limit => $env{'course.'.$cid.'.internal.selfenroll_limit'},
5073: selfenroll_cap => $env{'course.'.$cid.'.internal.selfenroll_cap'},
5074: selfenroll_start_date => $env{'course.'.$cid.'.internal.selfenroll_start_date'},
5075: selfenroll_end_date => $env{'course.'.$cid.'.internal.selfenroll_end_date'},
5076: selfenroll_start_access => $env{'course.'.$cid.'.internal.selfenroll_start_access'},
5077: selfenroll_end_access => $env{'course.'.$cid.'.internal.selfenroll_end_access'},
5078: default_enrollment_start_date => $env{'course.'.$cid.'.default_enrollment_start_date'},
5079: default_enrollment_end_date => $env{'course.'.$cid.'.default_enrollment_end_date'},
1.400 raeburn 5080: uniquecode => $env{'course.'.$cid.'.internal.uniquecode'},
1.398 raeburn 5081: );
5082: push(@{$brcrum},
5083: {href => '/adm/createuser?action=selfenroll',
5084: text => "Configure Self-enrollment",
5085: help => 'Course_Self_Enrollment'});
5086: if (!exists($env{'form.state'})) {
5087: $args = { bread_crumbs => $brcrum,
5088: bread_crumbs_component => 'Configure Self-enrollment'};
5089: $r->print(&header(undef,$args));
5090: $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n");
5091: &print_selfenroll_menu($r,'course',$cid,$cdom,$cnum,\%currsettings);
5092: } elsif ($env{'form.state'} eq 'done') {
5093: push (@{$brcrum},
5094: {href=>'/adm/createuser?action=selfenroll',
5095: text=>"Result"});
5096: $args = { bread_crumbs => $brcrum,
5097: bread_crumbs_component => 'Self-enrollment result'};
5098: $r->print(&header(undef,$args));
5099: $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n");
1.400 raeburn 5100: &update_selfenroll_config($r,$cid,$cdom,$cnum,$context,$crstype,\%currsettings);
1.398 raeburn 5101: }
5102: } else {
5103: $r->print(&header(undef,{'no_nav_bar' => 1}).
5104: '<span class="LC_error">'.&mt('You do not have permission to configure self-enrollment').'</span>');
1.237 raeburn 5105: }
1.277 raeburn 5106: } elsif ($env{'form.action'} eq 'selfenrollqueue') {
1.406.2.6 raeburn 5107: if ($permission->{selfenrolladmin}) {
1.351 raeburn 5108: push(@{$brcrum},
5109: {href => '/adm/createuser?action=selfenrollqueue',
1.406.2.6 raeburn 5110: text => 'Enrollment requests',
1.406.2.14! raeburn 5111: help => 'Course_Approve_Selfenroll'});
1.406.2.6 raeburn 5112: $bread_crumbs_component = 'Enrollment requests';
5113: if ($env{'form.state'} eq 'done') {
5114: push(@{$brcrum},
5115: {href => '/adm/createuser?action=selfenrollqueue',
5116: text => 'Result',
1.406.2.14! raeburn 5117: help => 'Course_Approve_Selfenroll'});
1.406.2.6 raeburn 5118: $bread_crumbs_component = 'Enrollment result';
5119: }
5120: $args = { bread_crumbs => $brcrum,
5121: bread_crumbs_component => $bread_crumbs_component};
5122: $r->print(&header(undef,$args));
5123: my $coursedesc = $env{'course.'.$cid.'.description'};
5124: if (!exists($env{'form.state'})) {
5125: $r->print('<h3>'.&mt('Pending enrollment requests').'</h3>'."\n");
5126: $r->print(&Apache::loncoursequeueadmin::display_queued_requests($context,
5127: $cdom,$cnum));
5128: } elsif ($env{'form.state'} eq 'done') {
5129: $r->print('<h3>'.&mt('Enrollment request processing').'</h3>'."\n");
5130: $r->print(&Apache::loncoursequeueadmin::update_request_queue($context,
5131: $cdom,$cnum,$coursedesc));
5132: }
5133: } else {
5134: $r->print(&header(undef,{'no_nav_bar' => 1}).
5135: '<span class="LC_error">'.&mt('You do not have permission to manage self-enrollment').'</span>');
1.277 raeburn 5136: }
1.239 raeburn 5137: } elsif ($env{'form.action'} eq 'changelogs') {
1.406.2.6 raeburn 5138: if ($permission->{cusr} || $permission->{view}) {
5139: &print_userchangelogs_display($r,$context,$permission,$brcrum);
5140: } else {
5141: $r->print(&header(undef,{'no_nav_bar' => 1}).
5142: '<span class="LC_error">'.&mt('You do not have permission to view change logs').'</span>');
5143: }
1.406.2.10 raeburn 5144: } elsif ($env{'form.action'} eq 'helpdesk') {
5145: if (($permission->{'owner'}) || ($permission->{'co-owner'})) {
5146: if ($env{'form.state'} eq 'process') {
5147: if ($permission->{'owner'}) {
5148: &update_helpdeskaccess($r,$permission,$brcrum);
5149: } else {
5150: &print_helpdeskaccess_display($r,$permission,$brcrum);
5151: }
5152: } else {
5153: &print_helpdeskaccess_display($r,$permission,$brcrum);
5154: }
5155: } else {
5156: $r->print(&header(undef,{'no_nav_bar' => 1}).
5157: '<span class="LC_error">'.&mt('You do not have permission to view helpdesk access').'</span>');
5158: }
1.190 raeburn 5159: } else {
1.351 raeburn 5160: $bread_crumbs_component = 'User Management';
5161: $args = { bread_crumbs => $brcrum,
5162: bread_crumbs_component => $bread_crumbs_component};
5163: $r->print(&header(undef,$args));
1.318 raeburn 5164: $r->print(&print_main_menu($permission,$context,$crstype));
1.190 raeburn 5165: }
1.351 raeburn 5166: $r->print(&Apache::loncommon::end_page());
1.190 raeburn 5167: return OK;
5168: }
5169:
5170: sub header {
1.351 raeburn 5171: my ($jscript,$args) = @_;
1.190 raeburn 5172: my $start_page;
1.351 raeburn 5173: if (ref($args) eq 'HASH') {
5174: $start_page=&Apache::loncommon::start_page('User Management',$jscript,$args);
1.190 raeburn 5175: } else {
1.351 raeburn 5176: $start_page=&Apache::loncommon::start_page('User Management',$jscript);
1.190 raeburn 5177: }
5178: return $start_page;
5179: }
1.2 www 5180:
1.191 raeburn 5181: sub add_script {
5182: my ($js) = @_;
1.301 bisitz 5183: return '<script type="text/javascript">'."\n"
5184: .'// <![CDATA['."\n"
5185: .$js."\n"
5186: .'// ]]>'."\n"
5187: .'</script>'."\n";
1.191 raeburn 5188: }
5189:
1.391 raeburn 5190: sub usernamerequest_javascript {
5191: my $js = <<ENDJS;
5192:
5193: function openusernamereqdisplay(dom,uname,queue) {
5194: var url = '/adm/createuser?action=displayuserreq';
5195: url += '&domain='+dom+'&username='+uname+'&queue='+queue;
5196: var title = 'Account_Request_Browser';
5197: var options = 'scrollbars=1,resizable=1,menubar=0';
5198: options += ',width=700,height=600';
5199: var stdeditbrowser = open(url,title,options,'1');
5200: stdeditbrowser.focus();
5201: return;
5202: }
5203:
5204: ENDJS
5205: }
5206:
5207: sub close_popup_form {
5208: my $close= &mt('Close Window');
5209: return << "END";
5210: <p><form name="displayreq" action="" method="post">
5211: <input type="button" name="closeme" value="$close" onclick="javascript:self.close();" />
5212: </form></p>
5213: END
5214: }
5215:
1.202 raeburn 5216: sub verify_user_display {
1.364 raeburn 5217: my ($context) = @_;
1.374 raeburn 5218: my %lt = &Apache::lonlocal::texthash (
5219: course => 'course(s): description, section(s), status',
5220: community => 'community(s): description, section(s), status',
5221: author => 'author',
5222: );
1.364 raeburn 5223: my $photos;
5224: if (($context eq 'course') && $env{'request.course.id'}) {
5225: $photos = $env{'course.'.$env{'request.course.id'}.'.internal.showphoto'};
5226: }
1.202 raeburn 5227: my $output = <<"END";
5228:
1.364 raeburn 5229: function hide_searching() {
5230: if (document.getElementById('searching')) {
5231: document.getElementById('searching').style.display = 'none';
5232: }
5233: return;
5234: }
5235:
1.202 raeburn 5236: function display_update() {
5237: document.studentform.action.value = 'listusers';
5238: document.studentform.phase.value = 'display';
5239: document.studentform.submit();
5240: }
5241:
1.364 raeburn 5242: function updateCols(caller) {
5243: var context = '$context';
5244: var photos = '$photos';
5245: if (caller == 'Status') {
1.374 raeburn 5246: if ((context == 'domain') &&
5247: ((document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'course') ||
5248: (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community'))) {
1.364 raeburn 5249: document.getElementById('showcolstatus').checked = false;
5250: document.getElementById('showcolstatus').disabled = 'disabled';
5251: document.getElementById('showcolstart').checked = false;
5252: document.getElementById('showcolend').checked = false;
1.374 raeburn 5253: } else {
5254: if (document.studentform.Status.options[document.studentform.Status.selectedIndex].value == 'Any') {
5255: document.getElementById('showcolstatus').checked = true;
5256: document.getElementById('showcolstatus').disabled = '';
5257: document.getElementById('showcolstart').checked = true;
5258: document.getElementById('showcolend').checked = true;
5259: } else {
5260: document.getElementById('showcolstatus').checked = false;
5261: document.getElementById('showcolstatus').disabled = 'disabled';
5262: document.getElementById('showcolstart').checked = false;
5263: document.getElementById('showcolend').checked = false;
5264: }
1.364 raeburn 5265: }
5266: }
5267: if (caller == 'output') {
5268: if (photos == 1) {
5269: if (document.getElementById('showcolphoto')) {
5270: var photoitem = document.getElementById('showcolphoto');
5271: if (document.studentform.output.options[document.studentform.output.selectedIndex].value == 'html') {
5272: photoitem.checked = true;
5273: photoitem.disabled = '';
5274: } else {
5275: photoitem.checked = false;
5276: photoitem.disabled = 'disabled';
5277: }
5278: }
5279: }
5280: }
5281: if (caller == 'showrole') {
1.371 raeburn 5282: if ((document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'Any') ||
5283: (document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'cr')) {
1.364 raeburn 5284: document.getElementById('showcolrole').checked = true;
5285: document.getElementById('showcolrole').disabled = '';
5286: } else {
5287: document.getElementById('showcolrole').checked = false;
5288: document.getElementById('showcolrole').disabled = 'disabled';
5289: }
1.374 raeburn 5290: if (context == 'domain') {
1.382 raeburn 5291: var quotausageshow = 0;
1.374 raeburn 5292: if ((document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'course') ||
5293: (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community')) {
5294: document.getElementById('showcolstatus').checked = false;
5295: document.getElementById('showcolstatus').disabled = 'disabled';
5296: document.getElementById('showcolstart').checked = false;
5297: document.getElementById('showcolend').checked = false;
5298: } else {
5299: if (document.studentform.Status.options[document.studentform.Status.selectedIndex].value == 'Any') {
5300: document.getElementById('showcolstatus').checked = true;
5301: document.getElementById('showcolstatus').disabled = '';
5302: document.getElementById('showcolstart').checked = true;
5303: document.getElementById('showcolend').checked = true;
5304: }
5305: }
5306: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'domain') {
5307: document.getElementById('showcolextent').disabled = 'disabled';
5308: document.getElementById('showcolextent').checked = 'false';
5309: document.getElementById('showextent').style.display='none';
5310: document.getElementById('showcoltextextent').innerHTML = '';
1.382 raeburn 5311: if ((document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'au') ||
5312: (document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'Any')) {
5313: if (document.getElementById('showcolauthorusage')) {
5314: document.getElementById('showcolauthorusage').disabled = '';
5315: }
5316: if (document.getElementById('showcolauthorquota')) {
5317: document.getElementById('showcolauthorquota').disabled = '';
5318: }
5319: quotausageshow = 1;
5320: }
1.374 raeburn 5321: } else {
5322: document.getElementById('showextent').style.display='block';
5323: document.getElementById('showextent').style.textAlign='left';
5324: document.getElementById('showextent').style.textFace='normal';
5325: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'author') {
5326: document.getElementById('showcolextent').disabled = '';
5327: document.getElementById('showcolextent').checked = 'true';
5328: document.getElementById('showcoltextextent').innerHTML="$lt{'author'}";
5329: } else {
5330: document.getElementById('showcolextent').disabled = '';
5331: document.getElementById('showcolextent').checked = 'true';
5332: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community') {
5333: document.getElementById('showcoltextextent').innerHTML="$lt{'community'}";
5334: } else {
5335: document.getElementById('showcoltextextent').innerHTML="$lt{'course'}";
5336: }
5337: }
5338: }
1.382 raeburn 5339: if (quotausageshow == 0) {
5340: if (document.getElementById('showcolauthorusage')) {
5341: document.getElementById('showcolauthorusage').checked = false;
5342: document.getElementById('showcolauthorusage').disabled = 'disabled';
5343: }
5344: if (document.getElementById('showcolauthorquota')) {
5345: document.getElementById('showcolauthorquota').checked = false;
5346: document.getElementById('showcolauthorquota').disabled = 'disabled';
5347: }
5348: }
1.374 raeburn 5349: }
1.364 raeburn 5350: }
5351: return;
5352: }
5353:
1.202 raeburn 5354: END
5355: return $output;
5356:
5357: }
5358:
1.190 raeburn 5359: ###############################################################
5360: ###############################################################
5361: # Menu Phase One
5362: sub print_main_menu {
1.318 raeburn 5363: my ($permission,$context,$crstype) = @_;
5364: my $linkcontext = $context;
5365: my $stuterm = lc(&Apache::lonnet::plaintext('st',$crstype));
5366: if (($context eq 'course') && ($crstype eq 'Community')) {
5367: $linkcontext = lc($crstype);
5368: $stuterm = 'Members';
5369: }
1.208 raeburn 5370: my %links = (
1.298 droeschl 5371: domain => {
5372: upload => 'Upload a File of Users',
5373: singleuser => 'Add/Modify a User',
5374: listusers => 'Manage Users',
5375: },
5376: author => {
5377: upload => 'Upload a File of Co-authors',
5378: singleuser => 'Add/Modify a Co-author',
5379: listusers => 'Manage Co-authors',
5380: },
5381: course => {
5382: upload => 'Upload a File of Course Users',
5383: singleuser => 'Add/Modify a Course User',
1.354 www 5384: listusers => 'List and Modify Multiple Course Users',
1.298 droeschl 5385: },
1.318 raeburn 5386: community => {
5387: upload => 'Upload a File of Community Users',
5388: singleuser => 'Add/Modify a Community User',
1.354 www 5389: listusers => 'List and Modify Multiple Community Users',
1.318 raeburn 5390: },
5391: );
5392: my %linktitles = (
5393: domain => {
5394: singleuser => 'Add a user to the domain, and/or a course or community in the domain.',
5395: listusers => 'Show and manage users in this domain.',
5396: },
5397: author => {
5398: singleuser => 'Add a user with a co- or assistant author role.',
5399: listusers => 'Show and manage co- or assistant authors.',
5400: },
5401: course => {
5402: singleuser => 'Add a user with a certain role to this course.',
5403: listusers => 'Show and manage users in this course.',
5404: },
5405: community => {
5406: singleuser => 'Add a user with a certain role to this community.',
5407: listusers => 'Show and manage users in this community.',
5408: },
1.298 droeschl 5409: );
1.406.2.6 raeburn 5410: if ($linkcontext eq 'domain') {
5411: unless ($permission->{'cusr'}) {
5412: $links{'domain'}{'singleuser'} = 'View a User';
5413: $linktitles{'domain'}{'singleuser'} = 'View information about a user in the domain';
5414: }
5415: } elsif ($linkcontext eq 'course') {
5416: unless ($permission->{'cusr'}) {
5417: $links{'course'}{'singleuser'} = 'View a Course User';
5418: $linktitles{'course'}{'singleuser'} = 'View information about a user in this course';
5419: $links{'course'}{'listusers'} = 'List Course Users';
5420: $linktitles{'course'}{'listusers'} = 'Show information about users in this course';
5421: }
5422: } elsif ($linkcontext eq 'community') {
5423: unless ($permission->{'cusr'}) {
5424: $links{'community'}{'singleuser'} = 'View a Community User';
5425: $linktitles{'community'}{'singleuser'} = 'View information about a user in this community';
5426: $links{'community'}{'listusers'} = 'List Community Users';
5427: $linktitles{'community'}{'listusers'} = 'Show information about users in this community';
5428: }
5429: }
1.298 droeschl 5430: my @menu = ( {categorytitle => 'Single Users',
5431: items =>
5432: [
5433: {
1.318 raeburn 5434: linktext => $links{$linkcontext}{'singleuser'},
1.298 droeschl 5435: icon => 'edit-redo.png',
5436: #help => 'Course_Change_Privileges',
5437: url => '/adm/createuser?action=singleuser',
1.406.2.6 raeburn 5438: permission => ($permission->{'view'} || $permission->{'cusr'}),
1.318 raeburn 5439: linktitle => $linktitles{$linkcontext}{'singleuser'},
1.298 droeschl 5440: },
5441: ]},
5442:
5443: {categorytitle => 'Multiple Users',
5444: items =>
5445: [
5446: {
1.318 raeburn 5447: linktext => $links{$linkcontext}{'upload'},
1.340 wenzelju 5448: icon => 'uplusr.png',
1.298 droeschl 5449: #help => 'Course_Create_Class_List',
5450: url => '/adm/createuser?action=upload',
5451: permission => $permission->{'cusr'},
5452: linktitle => 'Upload a CSV or a text file containing users.',
5453: },
5454: {
1.318 raeburn 5455: linktext => $links{$linkcontext}{'listusers'},
1.340 wenzelju 5456: icon => 'mngcu.png',
1.298 droeschl 5457: #help => 'Course_View_Class_List',
5458: url => '/adm/createuser?action=listusers',
5459: permission => ($permission->{'view'} || $permission->{'cusr'}),
1.318 raeburn 5460: linktitle => $linktitles{$linkcontext}{'listusers'},
1.298 droeschl 5461: },
5462:
5463: ]},
5464:
5465: {categorytitle => 'Administration',
5466: items => [ ]},
5467: );
1.406.2.5 raeburn 5468:
1.265 mielkec 5469: if ($context eq 'domain'){
1.406.2.5 raeburn 5470: push(@{ $menu[0]->{items} }, # Single Users
5471: {
5472: linktext => 'User Access Log',
5473: icon => 'document-properties.png',
1.406.2.8 raeburn 5474: #help => 'Domain_User_Access_Logs',
1.406.2.5 raeburn 5475: url => '/adm/createuser?action=accesslogs',
5476: permission => $permission->{'activity'},
5477: linktitle => 'View user access log.',
5478: }
5479: );
1.298 droeschl 5480:
5481: push(@{ $menu[2]->{items} }, #Category: Administration
5482: {
5483: linktext => 'Custom Roles',
5484: icon => 'emblem-photos.png',
5485: #help => 'Course_Editing_Custom_Roles',
5486: url => '/adm/createuser?action=custom',
5487: permission => $permission->{'custom'},
5488: linktitle => 'Configure a custom role.',
5489: },
1.362 raeburn 5490: {
5491: linktext => 'Authoring Space Requests',
5492: icon => 'selfenrl-queue.png',
5493: #help => 'Domain_Role_Approvals',
5494: url => '/adm/createuser?action=processauthorreq',
5495: permission => $permission->{'cusr'},
5496: linktitle => 'Approve or reject author role requests',
5497: },
1.363 raeburn 5498: {
1.391 raeburn 5499: linktext => 'LON-CAPA Account Requests',
5500: icon => 'list-add.png',
5501: #help => 'Domain_Username_Approvals',
5502: url => '/adm/createuser?action=processusernamereq',
5503: permission => $permission->{'cusr'},
5504: linktitle => 'Approve or reject LON-CAPA account requests',
5505: },
5506: {
1.363 raeburn 5507: linktext => 'Change Log',
5508: icon => 'document-properties.png',
5509: #help => 'Course_User_Logs',
5510: url => '/adm/createuser?action=changelogs',
1.406.2.6 raeburn 5511: permission => ($permission->{'cusr'} || $permission->{'view'}),
1.363 raeburn 5512: linktitle => 'View change log.',
5513: },
1.298 droeschl 5514: );
5515:
1.265 mielkec 5516: }elsif ($context eq 'course'){
1.298 droeschl 5517: my ($cnum,$cdom) = &Apache::lonuserutils::get_course_identity();
1.318 raeburn 5518:
5519: my %linktext = (
5520: 'Course' => {
5521: single => 'Add/Modify a Student',
5522: drop => 'Drop Students',
5523: groups => 'Course Groups',
5524: },
5525: 'Community' => {
5526: single => 'Add/Modify a Member',
5527: drop => 'Drop Members',
5528: groups => 'Community Groups',
5529: },
5530: );
5531:
5532: my %linktitle = (
5533: 'Course' => {
5534: single => 'Add a user with the role of student to this course',
5535: drop => 'Remove a student from this course.',
5536: groups => 'Manage course groups',
5537: },
5538: 'Community' => {
5539: single => 'Add a user with the role of member to this community',
5540: drop => 'Remove a member from this community.',
5541: groups => 'Manage community groups',
5542: },
5543: );
5544:
1.298 droeschl 5545: push(@{ $menu[0]->{items} }, #Category: Single Users
5546: {
1.318 raeburn 5547: linktext => $linktext{$crstype}{'single'},
1.298 droeschl 5548: #help => 'Course_Add_Student',
5549: icon => 'list-add.png',
5550: url => '/adm/createuser?action=singlestudent',
5551: permission => $permission->{'cusr'},
1.318 raeburn 5552: linktitle => $linktitle{$crstype}{'single'},
1.298 droeschl 5553: },
5554: );
5555:
5556: push(@{ $menu[1]->{items} }, #Category: Multiple Users
5557: {
1.318 raeburn 5558: linktext => $linktext{$crstype}{'drop'},
1.298 droeschl 5559: icon => 'edit-undo.png',
5560: #help => 'Course_Drop_Student',
5561: url => '/adm/createuser?action=drop',
5562: permission => $permission->{'cusr'},
1.318 raeburn 5563: linktitle => $linktitle{$crstype}{'drop'},
1.298 droeschl 5564: },
5565: );
5566: push(@{ $menu[2]->{items} }, #Category: Administration
1.406.2.11 raeburn 5567: {
5568: linktext => 'Helpdesk Access',
5569: icon => 'helpdesk-access.png',
5570: #help => 'Course_Helpdesk_Access',
5571: url => '/adm/createuser?action=helpdesk',
5572: permission => ($permission->{'owner'} || $permission->{'co-owner'}),
5573: linktitle => 'Helpdesk access options',
5574: },
5575: {
1.298 droeschl 5576: linktext => 'Custom Roles',
5577: icon => 'emblem-photos.png',
5578: #help => 'Course_Editing_Custom_Roles',
5579: url => '/adm/createuser?action=custom',
5580: permission => $permission->{'custom'},
5581: linktitle => 'Configure a custom role.',
5582: },
5583: {
1.318 raeburn 5584: linktext => $linktext{$crstype}{'groups'},
1.333 wenzelju 5585: icon => 'grps.png',
1.298 droeschl 5586: #help => 'Course_Manage_Group',
5587: url => '/adm/coursegroups?refpage=cusr',
5588: permission => $permission->{'grp_manage'},
1.318 raeburn 5589: linktitle => $linktitle{$crstype}{'groups'},
1.298 droeschl 5590: },
5591: {
1.328 wenzelju 5592: linktext => 'Change Log',
1.298 droeschl 5593: icon => 'document-properties.png',
5594: #help => 'Course_User_Logs',
5595: url => '/adm/createuser?action=changelogs',
1.406.2.6 raeburn 5596: permission => ($permission->{'view'} || $permission->{'cusr'}),
1.298 droeschl 5597: linktitle => 'View change log.',
5598: },
5599: );
1.277 raeburn 5600: if ($env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_approval'}) {
1.298 droeschl 5601: push(@{ $menu[2]->{items} },
1.398 raeburn 5602: {
1.298 droeschl 5603: linktext => 'Enrollment Requests',
5604: icon => 'selfenrl-queue.png',
5605: #help => 'Course_Approve_Selfenroll',
5606: url => '/adm/createuser?action=selfenrollqueue',
1.398 raeburn 5607: permission => $permission->{'selfenrolladmin'},
1.298 droeschl 5608: linktitle =>'Approve or reject enrollment requests.',
5609: },
5610: );
1.277 raeburn 5611: }
1.298 droeschl 5612:
1.265 mielkec 5613: if (!exists($permission->{'cusr_section'})){
1.320 raeburn 5614: if ($crstype ne 'Community') {
5615: push(@{ $menu[2]->{items} },
5616: {
5617: linktext => 'Automated Enrollment',
5618: icon => 'roles.png',
5619: #help => 'Course_Automated_Enrollment',
5620: permission => (&Apache::lonnet::auto_run($cnum,$cdom)
1.406.2.6 raeburn 5621: && (($permission->{'cusr'}) ||
5622: ($permission->{'view'}))),
1.320 raeburn 5623: url => '/adm/populate',
5624: linktitle => 'Automated enrollment manager.',
5625: }
5626: );
5627: }
5628: push(@{ $menu[2]->{items} },
1.298 droeschl 5629: {
5630: linktext => 'User Self-Enrollment',
1.342 wenzelju 5631: icon => 'self_enroll.png',
1.298 droeschl 5632: #help => 'Course_Self_Enrollment',
5633: url => '/adm/createuser?action=selfenroll',
1.398 raeburn 5634: permission => $permission->{'selfenrolladmin'},
1.317 bisitz 5635: linktitle => 'Configure user self-enrollment.',
1.298 droeschl 5636: },
5637: );
5638: }
1.363 raeburn 5639: } elsif ($context eq 'author') {
1.370 raeburn 5640: push(@{ $menu[2]->{items} }, #Category: Administration
1.363 raeburn 5641: {
5642: linktext => 'Change Log',
5643: icon => 'document-properties.png',
5644: #help => 'Course_User_Logs',
5645: url => '/adm/createuser?action=changelogs',
5646: permission => $permission->{'cusr'},
5647: linktitle => 'View change log.',
5648: },
1.370 raeburn 5649: );
1.363 raeburn 5650: }
5651: return Apache::lonhtmlcommon::generate_menu(@menu);
1.250 raeburn 5652: # { text => 'View Log-in History',
5653: # help => 'Course_User_Logins',
5654: # action => 'logins',
5655: # permission => $permission->{'cusr'},
5656: # });
1.190 raeburn 5657: }
5658:
1.189 albertel 5659: sub restore_prev_selections {
5660: my %saveable_parameters = ('srchby' => 'scalar',
5661: 'srchin' => 'scalar',
5662: 'srchtype' => 'scalar',
5663: );
5664: &Apache::loncommon::store_settings('user','user_picker',
5665: \%saveable_parameters);
5666: &Apache::loncommon::restore_settings('user','user_picker',
5667: \%saveable_parameters);
5668: }
5669:
1.237 raeburn 5670: sub print_selfenroll_menu {
1.406.2.6 raeburn 5671: my ($r,$context,$cid,$cdom,$cnum,$currsettings,$additional,$readonly) = @_;
1.322 raeburn 5672: my $crstype = &Apache::loncommon::course_type();
1.398 raeburn 5673: my $formname = 'selfenroll';
1.237 raeburn 5674: my $nolink = 1;
1.398 raeburn 5675: my ($row,$lt) = &Apache::lonuserutils::get_selfenroll_titles();
1.237 raeburn 5676: my $groupslist = &Apache::lonuserutils::get_groupslist();
5677: my $setsec_js =
5678: &Apache::lonuserutils::setsections_javascript($formname,$groupslist);
1.249 raeburn 5679: my %alerts = &Apache::lonlocal::texthash(
5680: acto => 'Activation of self-enrollment was selected for the following domain(s)',
5681: butn => 'but no user types have been checked.',
5682: wilf => "Please uncheck 'activate' or check at least one type.",
5683: );
1.406.2.6 raeburn 5684: my $disabled;
5685: if ($readonly) {
5686: $disabled = ' disabled="disabled"';
5687: }
1.405 damieng 5688: &js_escape(\%alerts);
1.249 raeburn 5689: my $selfenroll_js = <<"ENDSCRIPT";
5690: function update_types(caller,num) {
5691: var delidx = getIndexByName('selfenroll_delete');
5692: var actidx = getIndexByName('selfenroll_activate');
5693: if (caller == 'selfenroll_all') {
5694: var selall;
5695: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
5696: if (document.$formname.selfenroll_all[i].checked) {
5697: selall = document.$formname.selfenroll_all[i].value;
5698: }
5699: }
5700: if (selall == 1) {
5701: if (delidx != -1) {
5702: if (document.$formname.selfenroll_delete.length) {
5703: for (var j=0; j<document.$formname.selfenroll_delete.length; j++) {
5704: document.$formname.selfenroll_delete[j].checked = true;
5705: }
5706: } else {
5707: document.$formname.elements[delidx].checked = true;
5708: }
5709: }
5710: if (actidx != -1) {
5711: if (document.$formname.selfenroll_activate.length) {
5712: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
5713: document.$formname.selfenroll_activate[j].checked = false;
5714: }
5715: } else {
5716: document.$formname.elements[actidx].checked = false;
5717: }
5718: }
5719: document.$formname.selfenroll_newdom.selectedIndex = 0;
5720: }
5721: }
5722: if (caller == 'selfenroll_activate') {
5723: if (document.$formname.selfenroll_activate.length) {
5724: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
5725: if (document.$formname.selfenroll_activate[j].value == num) {
5726: if (document.$formname.selfenroll_activate[j].checked) {
5727: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
5728: if (document.$formname.selfenroll_all[i].value == '1') {
5729: document.$formname.selfenroll_all[i].checked = false;
5730: }
5731: if (document.$formname.selfenroll_all[i].value == '0') {
5732: document.$formname.selfenroll_all[i].checked = true;
5733: }
5734: }
5735: }
5736: }
5737: }
5738: } else {
5739: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
5740: if (document.$formname.selfenroll_all[i].value == '1') {
5741: document.$formname.selfenroll_all[i].checked = false;
5742: }
5743: if (document.$formname.selfenroll_all[i].value == '0') {
5744: document.$formname.selfenroll_all[i].checked = true;
5745: }
5746: }
5747: }
5748: }
5749: if (caller == 'selfenroll_delete') {
5750: if (document.$formname.selfenroll_delete.length) {
5751: for (var j=0; j<document.$formname.selfenroll_delete.length; j++) {
5752: if (document.$formname.selfenroll_delete[j].value == num) {
5753: if (document.$formname.selfenroll_delete[j].checked) {
5754: var delindex = getIndexByName('selfenroll_types_'+num);
5755: if (delindex != -1) {
5756: if (document.$formname.elements[delindex].length) {
5757: for (var k=0; k<document.$formname.elements[delindex].length; k++) {
5758: document.$formname.elements[delindex][k].checked = false;
5759: }
5760: } else {
5761: document.$formname.elements[delindex].checked = false;
5762: }
5763: }
5764: }
5765: }
5766: }
5767: } else {
5768: if (document.$formname.selfenroll_delete.checked) {
5769: var delindex = getIndexByName('selfenroll_types_'+num);
5770: if (delindex != -1) {
5771: if (document.$formname.elements[delindex].length) {
5772: for (var k=0; k<document.$formname.elements[delindex].length; k++) {
5773: document.$formname.elements[delindex][k].checked = false;
5774: }
5775: } else {
5776: document.$formname.elements[delindex].checked = false;
5777: }
5778: }
5779: }
5780: }
5781: }
5782: return;
5783: }
5784:
5785: function validate_types(form) {
5786: var needaction = new Array();
5787: var countfail = 0;
5788: var actidx = getIndexByName('selfenroll_activate');
5789: if (actidx != -1) {
5790: if (document.$formname.selfenroll_activate.length) {
5791: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
5792: var num = document.$formname.selfenroll_activate[j].value;
5793: if (document.$formname.selfenroll_activate[j].checked) {
5794: countfail = check_types(num,countfail,needaction)
5795: }
5796: }
5797: } else {
5798: if (document.$formname.selfenroll_activate.checked) {
1.398 raeburn 5799: var num = document.$formname.selfenroll_activate.value;
1.249 raeburn 5800: countfail = check_types(num,countfail,needaction)
5801: }
5802: }
5803: }
5804: if (countfail > 0) {
5805: var msg = "$alerts{'acto'}\\n";
5806: var loopend = needaction.length -1;
5807: if (loopend > 0) {
5808: for (var m=0; m<loopend; m++) {
5809: msg += needaction[m]+", ";
5810: }
5811: }
5812: msg += needaction[loopend]+"\\n$alerts{'butn'}\\n$alerts{'wilf'}";
5813: alert(msg);
5814: return;
5815: }
5816: setSections(form);
5817: }
5818:
5819: function check_types(num,countfail,needaction) {
5820: var typeidx = getIndexByName('selfenroll_types_'+num);
5821: var count = 0;
5822: if (typeidx != -1) {
5823: if (document.$formname.elements[typeidx].length) {
5824: for (var k=0; k<document.$formname.elements[typeidx].length; k++) {
5825: if (document.$formname.elements[typeidx][k].checked) {
5826: count ++;
5827: }
5828: }
5829: } else {
5830: if (document.$formname.elements[typeidx].checked) {
5831: count ++;
5832: }
5833: }
5834: if (count == 0) {
5835: var domidx = getIndexByName('selfenroll_dom_'+num);
5836: if (domidx != -1) {
5837: var domname = document.$formname.elements[domidx].value;
5838: needaction[countfail] = domname;
5839: countfail ++;
5840: }
5841: }
5842: }
5843: return countfail;
5844: }
5845:
1.398 raeburn 5846: function toggleNotify() {
5847: var selfenrollApproval = 0;
5848: if (document.$formname.selfenroll_approval.length) {
5849: for (var i=0; i<document.$formname.selfenroll_approval.length; i++) {
5850: if (document.$formname.selfenroll_approval[i].checked) {
5851: selfenrollApproval = document.$formname.selfenroll_approval[i].value;
5852: break;
5853: }
5854: }
5855: }
5856: if (document.getElementById('notified')) {
5857: if (selfenrollApproval == 0) {
5858: document.getElementById('notified').style.display='none';
5859: } else {
5860: document.getElementById('notified').style.display='block';
5861: }
5862: }
5863: return;
5864: }
5865:
1.249 raeburn 5866: function getIndexByName(item) {
5867: for (var i=0;i<document.$formname.elements.length;i++) {
5868: if (document.$formname.elements[i].name == item) {
5869: return i;
5870: }
5871: }
5872: return -1;
5873: }
5874: ENDSCRIPT
1.256 raeburn 5875:
1.237 raeburn 5876: my $output = '<script type="text/javascript">'."\n".
1.301 bisitz 5877: '// <![CDATA['."\n".
1.249 raeburn 5878: $setsec_js."\n".$selfenroll_js."\n".
1.301 bisitz 5879: '// ]]>'."\n".
1.237 raeburn 5880: '</script>'."\n".
1.256 raeburn 5881: '<h3>'.$lt->{'selfenroll'}.'</h3>'."\n";
1.400 raeburn 5882:
5883: my $visactions = &cat_visibility();
5884: my ($cathash,%cattype);
5885: my %domconfig = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom);
5886: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
5887: $cathash = $domconfig{'coursecategories'}{'cats'};
5888: $cattype{'auth'} = $domconfig{'coursecategories'}{'auth'};
5889: $cattype{'unauth'} = $domconfig{'coursecategories'}{'unauth'};
1.406 raeburn 5890: if ($cattype{'auth'} eq '') {
5891: $cattype{'auth'} = 'std';
5892: }
5893: if ($cattype{'unauth'} eq '') {
5894: $cattype{'unauth'} = 'std';
5895: }
1.400 raeburn 5896: } else {
5897: $cathash = {};
5898: $cattype{'auth'} = 'std';
5899: $cattype{'unauth'} = 'std';
5900: }
5901: if (($cattype{'auth'} eq 'none') && ($cattype{'unauth'} eq 'none')) {
5902: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
5903: '<br />'.
5904: '<br />'.$visactions->{'take'}.'<ul>'.
5905: '<li>'.$visactions->{'dc_chgconf'}.'</li>'.
5906: '</ul>');
5907: } elsif (($cattype{'auth'} !~ /^(std|domonly)$/) && ($cattype{'unauth'} !~ /^(std|domonly)$/)) {
5908: if ($currsettings->{'uniquecode'}) {
5909: $r->print('<span class="LC_info">'.$visactions->{'vis'}.'</span>');
5910: } else {
5911: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
5912: '<br />'.
5913: '<br />'.$visactions->{'take'}.'<ul>'.
5914: '<li>'.$visactions->{'dc_setcode'}.'</li>'.
5915: '</ul><br />');
5916: }
5917: } else {
5918: my ($visible,$cansetvis,$vismsgs) = &visible_in_stdcat($cdom,$cnum,\%domconfig);
5919: if (ref($visactions) eq 'HASH') {
5920: if ($visible) {
5921: $output .= '<p class="LC_info">'.$visactions->{'vis'}.'</p>';
5922: } else {
5923: $output .= '<p class="LC_warning">'.$visactions->{'miss'}.'</p>'
5924: .$visactions->{'yous'}.
5925: '<p>'.$visactions->{'gen'}.'<br />'.$visactions->{'coca'};
5926: if (ref($vismsgs) eq 'ARRAY') {
5927: $output .= '<br />'.$visactions->{'make'}.'<ul>';
5928: foreach my $item (@{$vismsgs}) {
5929: $output .= '<li>'.$visactions->{$item}.'</li>';
5930: }
5931: $output .= '</ul>';
1.256 raeburn 5932: }
1.400 raeburn 5933: $output .= '</p>';
1.256 raeburn 5934: }
5935: }
5936: }
1.398 raeburn 5937: my $actionhref = '/adm/createuser';
5938: if ($context eq 'domain') {
5939: $actionhref = '/adm/modifycourse';
5940: }
1.400 raeburn 5941:
5942: my %noedit;
5943: unless ($context eq 'domain') {
5944: %noedit = &get_noedit_fields($cdom,$cnum,$crstype,$row);
5945: }
1.398 raeburn 5946: $output .= '<form name="'.$formname.'" method="post" action="'.$actionhref.'">'."\n".
1.256 raeburn 5947: &Apache::lonhtmlcommon::start_pick_box();
1.237 raeburn 5948: if (ref($row) eq 'ARRAY') {
5949: foreach my $item (@{$row}) {
5950: my $title = $item;
5951: if (ref($lt) eq 'HASH') {
5952: $title = $lt->{$item};
5953: }
1.297 bisitz 5954: $output .= &Apache::lonhtmlcommon::row_title($title);
1.237 raeburn 5955: if ($item eq 'types') {
1.398 raeburn 5956: my $curr_types;
5957: if (ref($currsettings) eq 'HASH') {
5958: $curr_types = $currsettings->{'selfenroll_types'};
5959: }
1.400 raeburn 5960: if ($noedit{$item}) {
5961: if ($curr_types eq '*') {
5962: $output .= &mt('Any user in any domain');
5963: } else {
5964: my @entries = split(/;/,$curr_types);
5965: if (@entries > 0) {
5966: $output .= '<ul>';
5967: foreach my $entry (@entries) {
5968: my ($currdom,$typestr) = split(/:/,$entry);
5969: next if ($typestr eq '');
5970: my $domdesc = &Apache::lonnet::domain($currdom);
5971: my @currinsttypes = split(',',$typestr);
5972: my ($othertitle,$usertypes,$types) =
5973: &Apache::loncommon::sorted_inst_types($currdom);
5974: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
5975: $usertypes->{'any'} = &mt('any user');
5976: if (keys(%{$usertypes}) > 0) {
5977: $usertypes->{'other'} = &mt('other users');
5978: }
5979: my @longinsttypes = map { $usertypes->{$_}; } @currinsttypes;
5980: $output .= '<li>'.$domdesc.':'.join(', ',@longinsttypes).'</li>';
5981: }
5982: }
5983: $output .= '</ul>';
5984: } else {
5985: $output .= &mt('None');
5986: }
5987: }
5988: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
5989: next;
5990: }
1.241 raeburn 5991: my $showdomdesc = 1;
5992: my $includeempty = 1;
5993: my $num = 0;
5994: $output .= &Apache::loncommon::start_data_table().
5995: &Apache::loncommon::start_data_table_row()
5996: .'<td colspan="2"><span class="LC_nobreak"><label>'
5997: .&mt('Any user in any domain:')
5998: .' <input type="radio" name="selfenroll_all" value="1" ';
5999: if ($curr_types eq '*') {
6000: $output .= ' checked="checked" ';
6001: }
1.249 raeburn 6002: $output .= 'onchange="javascript:update_types('.
1.406.2.6 raeburn 6003: "'selfenroll_all'".');"'.$disabled.' />'.&mt('Yes').'</label>'.
1.249 raeburn 6004: ' <input type="radio" name="selfenroll_all" value="0" ';
1.241 raeburn 6005: if ($curr_types ne '*') {
6006: $output .= ' checked="checked" ';
6007: }
1.249 raeburn 6008: $output .= ' onchange="javascript:update_types('.
1.406.2.6 raeburn 6009: "'selfenroll_all'".');"'.$disabled.' />'.&mt('No').'</label></td>'.
1.249 raeburn 6010: &Apache::loncommon::end_data_table_row().
6011: &Apache::loncommon::end_data_table().
6012: &mt('Or').'<br />'.
6013: &Apache::loncommon::start_data_table();
1.241 raeburn 6014: my %currdoms;
1.249 raeburn 6015: if ($curr_types eq '') {
1.241 raeburn 6016: $output .= &new_selfenroll_dom_row($cdom,'0');
6017: } elsif ($curr_types ne '*') {
6018: my @entries = split(/;/,$curr_types);
6019: if (@entries > 0) {
6020: foreach my $entry (@entries) {
6021: my ($currdom,$typestr) = split(/:/,$entry);
6022: $currdoms{$currdom} = 1;
6023: my $domdesc = &Apache::lonnet::domain($currdom);
1.249 raeburn 6024: my @currinsttypes = split(',',$typestr);
1.241 raeburn 6025: $output .= &Apache::loncommon::start_data_table_row()
6026: .'<td valign="top"><span class="LC_nobreak">'.&mt('Domain:').'<b>'
6027: .' '.$domdesc.' ('.$currdom.')'
6028: .'</b><input type="hidden" name="selfenroll_dom_'.$num
6029: .'" value="'.$currdom.'" /></span><br />'
6030: .'<span class="LC_nobreak"><label><input type="checkbox" '
1.406.2.6 raeburn 6031: .'name="selfenroll_delete" value="'.$num.'" onchange="javascript:update_types('."'selfenroll_delete','$num'".');"'.$disabled.' />'
1.241 raeburn 6032: .&mt('Delete').'</label></span></td>';
1.249 raeburn 6033: $output .= '<td valign="top"> '.&mt('User types:').'<br />'
1.406.2.6 raeburn 6034: .&selfenroll_inst_types($num,$currdom,\@currinsttypes,$readonly).'</td>'
1.241 raeburn 6035: .&Apache::loncommon::end_data_table_row();
6036: $num ++;
6037: }
6038: }
6039: }
1.249 raeburn 6040: my $add_domtitle = &mt('Users in additional domain:');
1.241 raeburn 6041: if ($curr_types eq '*') {
1.249 raeburn 6042: $add_domtitle = &mt('Users in specific domain:');
1.241 raeburn 6043: } elsif ($curr_types eq '') {
1.249 raeburn 6044: $add_domtitle = &mt('Users in other domain:');
1.241 raeburn 6045: }
6046: $output .= &Apache::loncommon::start_data_table_row()
6047: .'<td colspan="2"><span class="LC_nobreak">'.$add_domtitle.'</span><br />'
6048: .&Apache::loncommon::select_dom_form('','selfenroll_newdom',
1.406.2.6 raeburn 6049: $includeempty,$showdomdesc,'','','',$readonly)
1.241 raeburn 6050: .'<input type="hidden" name="selfenroll_types_total" value="'.$num.'" />'
6051: .'</td>'.&Apache::loncommon::end_data_table_row()
6052: .&Apache::loncommon::end_data_table();
1.237 raeburn 6053: } elsif ($item eq 'registered') {
6054: my ($regon,$regoff);
1.398 raeburn 6055: my $registered;
6056: if (ref($currsettings) eq 'HASH') {
6057: $registered = $currsettings->{'selfenroll_registered'};
6058: }
1.400 raeburn 6059: if ($noedit{$item}) {
6060: if ($registered) {
6061: $output .= &mt('Must be registered in course');
6062: } else {
6063: $output .= &mt('No requirement');
6064: }
6065: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6066: next;
6067: }
1.398 raeburn 6068: if ($registered) {
1.237 raeburn 6069: $regon = ' checked="checked" ';
1.406.2.6 raeburn 6070: $regoff = '';
1.237 raeburn 6071: } else {
1.406.2.6 raeburn 6072: $regon = '';
1.237 raeburn 6073: $regoff = ' checked="checked" ';
6074: }
6075: $output .= '<label>'.
1.406.2.6 raeburn 6076: '<input type="radio" name="selfenroll_registered" value="1"'.$regon.$disabled.' />'.
1.244 bisitz 6077: &mt('Yes').'</label> <label>'.
1.406.2.6 raeburn 6078: '<input type="radio" name="selfenroll_registered" value="0"'.$regoff.$disabled.' />'.
1.244 bisitz 6079: &mt('No').'</label>';
1.237 raeburn 6080: } elsif ($item eq 'enroll_dates') {
1.398 raeburn 6081: my ($starttime,$endtime);
6082: if (ref($currsettings) eq 'HASH') {
6083: $starttime = $currsettings->{'selfenroll_start_date'};
6084: $endtime = $currsettings->{'selfenroll_end_date'};
6085: if ($starttime eq '') {
6086: $starttime = $currsettings->{'default_enrollment_start_date'};
6087: }
6088: if ($endtime eq '') {
6089: $endtime = $currsettings->{'default_enrollment_end_date'};
6090: }
1.237 raeburn 6091: }
1.400 raeburn 6092: if ($noedit{$item}) {
6093: $output .= &mt('From: [_1], to: [_2]',&Apache::lonlocal::locallocaltime($starttime),
6094: &Apache::lonlocal::locallocaltime($endtime));
6095: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6096: next;
6097: }
1.237 raeburn 6098: my $startform =
6099: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_start_date',$starttime,
1.406.2.6 raeburn 6100: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
1.237 raeburn 6101: my $endform =
6102: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_end_date',$endtime,
1.406.2.6 raeburn 6103: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
1.237 raeburn 6104: $output .= &selfenroll_date_forms($startform,$endform);
6105: } elsif ($item eq 'access_dates') {
1.398 raeburn 6106: my ($starttime,$endtime);
6107: if (ref($currsettings) eq 'HASH') {
6108: $starttime = $currsettings->{'selfenroll_start_access'};
6109: $endtime = $currsettings->{'selfenroll_end_access'};
6110: if ($starttime eq '') {
6111: $starttime = $currsettings->{'default_enrollment_start_date'};
6112: }
6113: if ($endtime eq '') {
6114: $endtime = $currsettings->{'default_enrollment_end_date'};
6115: }
1.237 raeburn 6116: }
1.400 raeburn 6117: if ($noedit{$item}) {
6118: $output .= &mt('From: [_1], to: [_2]',&Apache::lonlocal::locallocaltime($starttime),
6119: &Apache::lonlocal::locallocaltime($endtime));
6120: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6121: next;
6122: }
1.237 raeburn 6123: my $startform =
6124: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_start_access',$starttime,
1.406.2.6 raeburn 6125: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
1.237 raeburn 6126: my $endform =
6127: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_end_access',$endtime,
1.406.2.6 raeburn 6128: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
1.237 raeburn 6129: $output .= &selfenroll_date_forms($startform,$endform);
6130: } elsif ($item eq 'section') {
1.398 raeburn 6131: my $currsec;
6132: if (ref($currsettings) eq 'HASH') {
6133: $currsec = $currsettings->{'selfenroll_section'};
6134: }
1.237 raeburn 6135: my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum);
6136: my $newsecval;
6137: if ($currsec ne 'none' && $currsec ne '') {
6138: if (!defined($sections_count{$currsec})) {
6139: $newsecval = $currsec;
6140: }
6141: }
1.400 raeburn 6142: if ($noedit{$item}) {
6143: if ($currsec ne '') {
6144: $output .= $currsec;
6145: } else {
6146: $output .= &mt('No specific section');
6147: }
6148: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6149: next;
6150: }
1.237 raeburn 6151: my $sections_select =
1.406.2.6 raeburn 6152: &Apache::lonuserutils::course_sections(\%sections_count,'st',$currsec,$disabled);
1.237 raeburn 6153: $output .= '<table class="LC_createuser">'."\n".
6154: '<tr class="LC_section_row">'."\n".
6155: '<td align="center">'.&mt('Existing sections')."\n".
6156: '<br />'.$sections_select.'</td><td align="center">'.
6157: &mt('New section').'<br />'."\n".
1.406.2.6 raeburn 6158: '<input type="text" name="newsec" size="15" value="'.$newsecval.'"'.$disabled.' />'."\n".
1.237 raeburn 6159: '<input type="hidden" name="sections" value="" />'."\n".
6160: '</td></tr></table>'."\n";
1.276 raeburn 6161: } elsif ($item eq 'approval') {
1.398 raeburn 6162: my ($currnotified,$currapproval,%appchecked);
6163: my %selfdescs = &Apache::lonuserutils::selfenroll_default_descs();
1.406.2.6 raeburn 6164: if (ref($currsettings) eq 'HASH') {
1.398 raeburn 6165: $currnotified = $currsettings->{'selfenroll_notifylist'};
6166: $currapproval = $currsettings->{'selfenroll_approval'};
6167: }
6168: if ($currapproval !~ /^[012]$/) {
6169: $currapproval = 0;
6170: }
1.400 raeburn 6171: if ($noedit{$item}) {
6172: $output .= $selfdescs{'approval'}{$currapproval}.
6173: '<br />'.&mt('(Set by Domain Coordinator)');
6174: next;
6175: }
1.398 raeburn 6176: $appchecked{$currapproval} = ' checked="checked"';
6177: for my $i (0..2) {
6178: $output .= '<label>'.
6179: '<input type="radio" name="selfenroll_approval" value="'.$i.'"'.
1.406.2.6 raeburn 6180: $appchecked{$i}.' onclick="toggleNotify();"'.$disabled.' />'.
6181: $selfdescs{'approval'}{$i}.'</label>'.(' 'x2);
1.276 raeburn 6182: }
6183: my %advhash = &Apache::lonnet::get_course_adv_roles($cid,1);
6184: my (@ccs,%notified);
1.322 raeburn 6185: my $ccrole = 'cc';
6186: if ($crstype eq 'Community') {
6187: $ccrole = 'co';
6188: }
6189: if ($advhash{$ccrole}) {
6190: @ccs = split(/,/,$advhash{$ccrole});
1.276 raeburn 6191: }
6192: if ($currnotified) {
6193: foreach my $current (split(/,/,$currnotified)) {
6194: $notified{$current} = 1;
6195: if (!grep(/^\Q$current\E$/,@ccs)) {
6196: push(@ccs,$current);
6197: }
6198: }
6199: }
6200: if (@ccs) {
1.398 raeburn 6201: my $style;
6202: unless ($currapproval) {
6203: $style = ' style="display: none;"';
6204: }
6205: $output .= '<br /><div id="notified"'.$style.'>'.
6206: &mt('Personnel to be notified when an enrollment request needs approval, or has been approved:').' '.
6207: &Apache::loncommon::start_data_table().
1.276 raeburn 6208: &Apache::loncommon::start_data_table_row();
6209: my $count = 0;
6210: my $numcols = 4;
6211: foreach my $cc (sort(@ccs)) {
6212: my $notifyon;
6213: my ($ccuname,$ccudom) = split(/:/,$cc);
6214: if ($notified{$cc}) {
6215: $notifyon = ' checked="checked" ';
6216: }
6217: if ($count && !$count%$numcols) {
6218: $output .= &Apache::loncommon::end_data_table_row().
6219: &Apache::loncommon::start_data_table_row()
6220: }
6221: $output .= '<td><span class="LC_nobreak"><label>'.
1.406.2.6 raeburn 6222: '<input type="checkbox" name="selfenroll_notify"'.$notifyon.' value="'.$cc.'"'.$disabled.' />'.
1.276 raeburn 6223: &Apache::loncommon::plainname($ccuname,$ccudom).
6224: '</label></span></td>';
1.343 raeburn 6225: $count ++;
1.276 raeburn 6226: }
6227: my $rem = $count%$numcols;
6228: if ($rem) {
6229: my $emptycols = $numcols - $rem;
6230: for (my $i=0; $i<$emptycols; $i++) {
6231: $output .= '<td> </td>';
6232: }
6233: }
6234: $output .= &Apache::loncommon::end_data_table_row().
1.398 raeburn 6235: &Apache::loncommon::end_data_table().
6236: '</div>';
1.276 raeburn 6237: }
6238: } elsif ($item eq 'limit') {
1.398 raeburn 6239: my ($crslimit,$selflimit,$nolimit,$currlim,$currcap);
6240: if (ref($currsettings) eq 'HASH') {
6241: $currlim = $currsettings->{'selfenroll_limit'};
6242: $currcap = $currsettings->{'selfenroll_cap'};
6243: }
1.400 raeburn 6244: if ($noedit{$item}) {
6245: if (($currlim eq 'allstudents') || ($currlim eq 'selfenrolled')) {
6246: if ($currlim eq 'allstudents') {
6247: $output .= &mt('Limit by total students');
6248: } elsif ($currlim eq 'selfenrolled') {
6249: $output .= &mt('Limit by total self-enrolled students');
6250: }
6251: $output .= ' '.&mt('Maximum: [_1]',$currcap).
6252: '<br />'.&mt('(Set by Domain Coordinator)');
6253: } else {
6254: $output .= &mt('No limit').'<br />'.&mt('(Set by Domain Coordinator)');
6255: }
6256: next;
6257: }
1.276 raeburn 6258: if ($currlim eq 'allstudents') {
6259: $crslimit = ' checked="checked" ';
6260: $selflimit = ' ';
6261: $nolimit = ' ';
6262: } elsif ($currlim eq 'selfenrolled') {
6263: $crslimit = ' ';
6264: $selflimit = ' checked="checked" ';
6265: $nolimit = ' ';
6266: } else {
6267: $crslimit = ' ';
6268: $selflimit = ' ';
1.398 raeburn 6269: $nolimit = ' checked="checked" ';
1.276 raeburn 6270: }
6271: $output .= '<table><tr><td><label>'.
1.406.2.6 raeburn 6272: '<input type="radio" name="selfenroll_limit" value="none"'.$nolimit.$disabled.'/>'.
1.276 raeburn 6273: &mt('No limit').'</label></td><td><label>'.
1.406.2.6 raeburn 6274: '<input type="radio" name="selfenroll_limit" value="allstudents"'.$crslimit.$disabled.'/>'.
1.276 raeburn 6275: &mt('Limit by total students').'</label></td><td><label>'.
1.406.2.6 raeburn 6276: '<input type="radio" name="selfenroll_limit" value="selfenrolled"'.$selflimit.$disabled.'/>'.
1.276 raeburn 6277: &mt('Limit by total self-enrolled students').
6278: '</td></tr><tr>'.
6279: '<td> </td><td colspan="2"><span class="LC_nobreak">'.
6280: (' 'x3).&mt('Maximum number allowed: ').
1.406.2.6 raeburn 6281: '<input type="text" name="selfenroll_cap" size = "5" value="'.$currcap.'"'.$disabled.' /></td></tr></table>';
1.237 raeburn 6282: }
6283: $output .= &Apache::lonhtmlcommon::row_closure(1);
6284: }
6285: }
1.406.2.6 raeburn 6286: $output .= &Apache::lonhtmlcommon::end_pick_box().'<br />';
6287: unless ($readonly) {
6288: $output .= '<input type="button" name="selfenrollconf" value="'
6289: .&mt('Save').'" onclick="validate_types(this.form);" />';
6290: }
6291: $output .= '<input type="hidden" name="action" value="selfenroll" />'
1.406.2.11 raeburn 6292: .'<input type="hidden" name="state" value="done" />'."\n"
6293: .$additional.'</form>';
1.237 raeburn 6294: $r->print($output);
6295: return;
6296: }
6297:
1.400 raeburn 6298: sub get_noedit_fields {
6299: my ($cdom,$cnum,$crstype,$row) = @_;
6300: my %noedit;
6301: if (ref($row) eq 'ARRAY') {
6302: my %settings = &Apache::lonnet::get('environment',['internal.coursecode','internal.textbook',
6303: 'internal.selfenrollmgrdc',
6304: 'internal.selfenrollmgrcc'],$cdom,$cnum);
6305: my $type = &Apache::lonuserutils::get_extended_type($cdom,$cnum,$crstype,\%settings);
6306: my (%specific_managebydc,%specific_managebycc,%default_managebydc);
6307: map { $specific_managebydc{$_} = 1; } (split(/,/,$settings{'internal.selfenrollmgrdc'}));
6308: map { $specific_managebycc{$_} = 1; } (split(/,/,$settings{'internal.selfenrollmgrcc'}));
6309: my %domdefaults = &Apache::lonnet::get_domain_defaults($cdom);
6310: map { $default_managebydc{$_} = 1; } (split(/,/,$domdefaults{$type.'selfenrolladmdc'}));
6311:
6312: foreach my $item (@{$row}) {
6313: next if ($specific_managebycc{$item});
6314: if (($specific_managebydc{$item}) || ($default_managebydc{$item})) {
6315: $noedit{$item} = 1;
6316: }
6317: }
6318: }
6319: return %noedit;
6320: }
6321:
6322: sub visible_in_stdcat {
6323: my ($cdom,$cnum,$domconf) = @_;
6324: my ($cathash,%settable,@vismsgs,$cansetvis,$visible);
6325: unless (ref($domconf) eq 'HASH') {
6326: return ($visible,$cansetvis,\@vismsgs);
6327: }
6328: if (ref($domconf->{'coursecategories'}) eq 'HASH') {
6329: if ($domconf->{'coursecategories'}{'togglecats'} eq 'crs') {
1.256 raeburn 6330: $settable{'togglecats'} = 1;
6331: }
1.400 raeburn 6332: if ($domconf->{'coursecategories'}{'categorize'} eq 'crs') {
1.256 raeburn 6333: $settable{'categorize'} = 1;
6334: }
1.400 raeburn 6335: $cathash = $domconf->{'coursecategories'}{'cats'};
1.256 raeburn 6336: }
1.260 raeburn 6337: if ($settable{'togglecats'} && $settable{'categorize'}) {
1.256 raeburn 6338: $cansetvis = &mt('You are able to both assign a course category and choose to exclude this course from the catalog.');
6339: } elsif ($settable{'togglecats'}) {
6340: $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 6341: } elsif ($settable{'categorize'}) {
1.256 raeburn 6342: $cansetvis = &mt('You may assign a course category, but only a Domain Coordinator may choose to exclude this course from the catalog.');
6343: } else {
6344: $cansetvis = &mt('Only a Domain Coordinator may assign a course category or choose to exclude this course from the catalog.');
6345: }
6346:
6347: my %currsettings =
6348: &Apache::lonnet::get('environment',['hidefromcat','categories','internal.coursecode'],
6349: $cdom,$cnum);
1.400 raeburn 6350: $visible = 0;
1.256 raeburn 6351: if ($currsettings{'internal.coursecode'} ne '') {
1.400 raeburn 6352: if (ref($domconf->{'coursecategories'}) eq 'HASH') {
6353: $cathash = $domconf->{'coursecategories'}{'cats'};
1.256 raeburn 6354: if (ref($cathash) eq 'HASH') {
6355: if ($cathash->{'instcode::0'} eq '') {
6356: push(@vismsgs,'dc_addinst');
6357: } else {
6358: $visible = 1;
6359: }
6360: } else {
6361: $visible = 1;
6362: }
6363: } else {
6364: $visible = 1;
6365: }
6366: } else {
6367: if (ref($cathash) eq 'HASH') {
6368: if ($cathash->{'instcode::0'} ne '') {
6369: push(@vismsgs,'dc_instcode');
6370: }
6371: } else {
6372: push(@vismsgs,'dc_instcode');
6373: }
6374: }
6375: if ($currsettings{'categories'} ne '') {
6376: my $cathash;
1.400 raeburn 6377: if (ref($domconf->{'coursecategories'}) eq 'HASH') {
6378: $cathash = $domconf->{'coursecategories'}{'cats'};
1.256 raeburn 6379: if (ref($cathash) eq 'HASH') {
6380: if (keys(%{$cathash}) == 0) {
6381: push(@vismsgs,'dc_catalog');
6382: } elsif ((keys(%{$cathash}) == 1) && ($cathash->{'instcode::0'} ne '')) {
6383: push(@vismsgs,'dc_categories');
6384: } else {
6385: my @currcategories = split('&',$currsettings{'categories'});
6386: my $matched = 0;
6387: foreach my $cat (@currcategories) {
6388: if ($cathash->{$cat} ne '') {
6389: $visible = 1;
6390: $matched = 1;
6391: last;
6392: }
6393: }
6394: if (!$matched) {
1.260 raeburn 6395: if ($settable{'categorize'}) {
1.256 raeburn 6396: push(@vismsgs,'chgcat');
6397: } else {
6398: push(@vismsgs,'dc_chgcat');
6399: }
6400: }
6401: }
6402: }
6403: }
6404: } else {
6405: if (ref($cathash) eq 'HASH') {
6406: if ((keys(%{$cathash}) > 1) ||
6407: (keys(%{$cathash}) == 1) && ($cathash->{'instcode::0'} eq '')) {
1.260 raeburn 6408: if ($settable{'categorize'}) {
1.256 raeburn 6409: push(@vismsgs,'addcat');
6410: } else {
6411: push(@vismsgs,'dc_addcat');
6412: }
6413: }
6414: }
6415: }
6416: if ($currsettings{'hidefromcat'} eq 'yes') {
6417: $visible = 0;
6418: if ($settable{'togglecats'}) {
6419: unshift(@vismsgs,'unhide');
6420: } else {
6421: unshift(@vismsgs,'dc_unhide')
6422: }
6423: }
1.400 raeburn 6424: return ($visible,$cansetvis,\@vismsgs);
6425: }
6426:
6427: sub cat_visibility {
6428: my %visactions = &Apache::lonlocal::texthash(
6429: vis => 'This course/community currently appears in the Course/Community Catalog for this domain.',
6430: 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.',
6431: miss => 'This course/community does not currently appear in the Course/Community Catalog for this domain.',
6432: none => 'Display of a course catalog is disabled for this domain.',
6433: yous => 'You should remedy this if you plan to allow self-enrollment, otherwise students will have difficulty finding this course.',
6434: 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.',
6435: make => 'Make any changes to self-enrollment settings below, click "Save", then take action to include the course in the Catalog:',
6436: take => 'Take the following action to ensure the course appears in the Catalog:',
6437: dc_chgconf => 'Ask a domain coordinator to change the Catalog type for this domain.',
6438: dc_setcode => 'Ask a domain coordinator to assign a six character code to the course',
6439: dc_unhide => 'Ask a domain coordinator to change the "Exclude from course catalog" setting.',
6440: dc_addinst => 'Ask a domain coordinator to enable display the catalog of "Official courses (with institutional codes)".',
6441: dc_instcode => 'Ask a domain coordinator to assign an institutional code (if this is an official course).',
6442: dc_catalog => 'Ask a domain coordinator to enable or create at least one course category in the domain.',
6443: dc_categories => 'Ask a domain coordinator to create a hierarchy of categories and sub categories for courses in the domain.',
6444: 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',
6445: dc_addcat => 'Ask a domain coordinator to assign a category to the course.',
6446: );
6447: $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>"');
6448: $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>"');
6449: $visactions{'addcat'} = &mt('Use [_1]Categorize course[_2] to assign a category to the course.','"<a href="/adm/courseprefs?phase=display&actions=courseinfo">','</a>"');
6450: return \%visactions;
1.256 raeburn 6451: }
6452:
1.241 raeburn 6453: sub new_selfenroll_dom_row {
6454: my ($newdom,$num) = @_;
6455: my $domdesc = &Apache::lonnet::domain($newdom);
6456: my $output;
6457: if ($domdesc ne '') {
6458: $output .= &Apache::loncommon::start_data_table_row()
6459: .'<td valign="top"><span class="LC_nobreak">'.&mt('Domain:').' <b>'.$domdesc
6460: .' ('.$newdom.')</b><input type="hidden" name="selfenroll_dom_'.$num
1.249 raeburn 6461: .'" value="'.$newdom.'" /></span><br />'
6462: .'<span class="LC_nobreak"><label><input type="checkbox" '
6463: .'name="selfenroll_activate" value="'.$num.'" '
6464: .'onchange="javascript:update_types('
6465: ."'selfenroll_activate','$num'".');" />'
6466: .&mt('Activate').'</label></span></td>';
1.241 raeburn 6467: my @currinsttypes;
6468: $output .= '<td>'.&mt('User types:').'<br />'
6469: .&selfenroll_inst_types($num,$newdom,\@currinsttypes).'</td>'
6470: .&Apache::loncommon::end_data_table_row();
6471: }
6472: return $output;
6473: }
6474:
6475: sub selfenroll_inst_types {
1.406.2.6 raeburn 6476: my ($num,$currdom,$currinsttypes,$readonly) = @_;
1.241 raeburn 6477: my $output;
6478: my $numinrow = 4;
6479: my $count = 0;
6480: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($currdom);
1.247 raeburn 6481: my $othervalue = 'any';
1.406.2.6 raeburn 6482: my $disabled;
6483: if ($readonly) {
6484: $disabled = ' disabled="disabled"';
6485: }
1.241 raeburn 6486: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
1.251 raeburn 6487: if (keys(%{$usertypes}) > 0) {
1.247 raeburn 6488: $othervalue = 'other';
6489: }
1.241 raeburn 6490: $output .= '<table><tr>';
6491: foreach my $type (@{$types}) {
6492: if (($count > 0) && ($count%$numinrow == 0)) {
6493: $output .= '</tr><tr>';
6494: }
6495: if (defined($usertypes->{$type})) {
1.257 raeburn 6496: my $esc_type = &escape($type);
1.241 raeburn 6497: $output .= '<td><span class="LC_nobreak"><label><input type = "checkbox" value="'.
1.257 raeburn 6498: $esc_type.'" ';
1.241 raeburn 6499: if (ref($currinsttypes) eq 'ARRAY') {
6500: if (@{$currinsttypes} > 0) {
1.249 raeburn 6501: if (grep(/^any$/,@{$currinsttypes})) {
6502: $output .= 'checked="checked"';
1.257 raeburn 6503: } elsif (grep(/^\Q$esc_type\E$/,@{$currinsttypes})) {
1.241 raeburn 6504: $output .= 'checked="checked"';
6505: }
1.249 raeburn 6506: } else {
6507: $output .= 'checked="checked"';
1.241 raeburn 6508: }
6509: }
1.406.2.6 raeburn 6510: $output .= ' name="selfenroll_types_'.$num.'"'.$disabled.' />'.$usertypes->{$type}.'</label></span></td>';
1.241 raeburn 6511: }
6512: $count ++;
6513: }
6514: if (($count > 0) && ($count%$numinrow == 0)) {
6515: $output .= '</tr><tr>';
6516: }
1.249 raeburn 6517: $output .= '<td><span class="LC_nobreak"><label><input type = "checkbox" value="'.$othervalue.'"';
1.241 raeburn 6518: if (ref($currinsttypes) eq 'ARRAY') {
6519: if (@{$currinsttypes} > 0) {
1.249 raeburn 6520: if (grep(/^any$/,@{$currinsttypes})) {
6521: $output .= ' checked="checked"';
6522: } elsif ($othervalue eq 'other') {
6523: if (grep(/^\Q$othervalue\E$/,@{$currinsttypes})) {
6524: $output .= ' checked="checked"';
6525: }
1.241 raeburn 6526: }
1.249 raeburn 6527: } else {
6528: $output .= ' checked="checked"';
1.241 raeburn 6529: }
1.249 raeburn 6530: } else {
6531: $output .= ' checked="checked"';
1.241 raeburn 6532: }
1.406.2.6 raeburn 6533: $output .= ' name="selfenroll_types_'.$num.'"'.$disabled.' />'.$othertitle.'</label></span></td></tr></table>';
1.241 raeburn 6534: }
6535: return $output;
6536: }
6537:
1.237 raeburn 6538: sub selfenroll_date_forms {
6539: my ($startform,$endform) = @_;
6540: my $output .= &Apache::lonhtmlcommon::start_pick_box()."\n".
1.244 bisitz 6541: &Apache::lonhtmlcommon::row_title(&mt('Start date'),
1.237 raeburn 6542: 'LC_oddrow_value')."\n".
6543: $startform."\n".
6544: &Apache::lonhtmlcommon::row_closure(1).
1.244 bisitz 6545: &Apache::lonhtmlcommon::row_title(&mt('End date'),
1.237 raeburn 6546: 'LC_oddrow_value')."\n".
6547: $endform."\n".
6548: &Apache::lonhtmlcommon::row_closure(1).
6549: &Apache::lonhtmlcommon::end_pick_box();
6550: return $output;
6551: }
6552:
1.239 raeburn 6553: sub print_userchangelogs_display {
1.406.2.5 raeburn 6554: my ($r,$context,$permission,$brcrum) = @_;
1.363 raeburn 6555: my $formname = 'rolelog';
1.406.2.6 raeburn 6556: my ($username,$domain,$crstype,$viewablesec,%roleslog);
1.363 raeburn 6557: if ($context eq 'domain') {
6558: $domain = $env{'request.role.domain'};
6559: %roleslog=&Apache::lonnet::dump_dom('nohist_rolelog',$domain);
6560: } else {
6561: if ($context eq 'course') {
6562: $domain = $env{'course.'.$env{'request.course.id'}.'.domain'};
6563: $username = $env{'course.'.$env{'request.course.id'}.'.num'};
6564: $crstype = &Apache::loncommon::course_type();
1.406.2.6 raeburn 6565: $viewablesec = &Apache::lonuserutils::viewable_section($permission);
1.363 raeburn 6566: my %saveable_parameters = ('show' => 'scalar',);
6567: &Apache::loncommon::store_course_settings('roles_log',
6568: \%saveable_parameters);
6569: &Apache::loncommon::restore_course_settings('roles_log',
6570: \%saveable_parameters);
6571: } elsif ($context eq 'author') {
6572: $domain = $env{'user.domain'};
6573: if ($env{'request.role'} =~ m{^au\./\Q$domain\E/$}) {
6574: $username = $env{'user.name'};
6575: } else {
6576: undef($domain);
6577: }
6578: }
6579: if ($domain ne '' && $username ne '') {
6580: %roleslog=&Apache::lonnet::dump('nohist_rolelog',$domain,$username);
6581: }
6582: }
1.239 raeburn 6583: if ((keys(%roleslog))[0]=~/^error\:/) { undef(%roleslog); }
6584:
1.406.2.5 raeburn 6585: my $helpitem;
6586: if ($context eq 'course') {
6587: $helpitem = 'Course_User_Logs';
1.406.2.14! raeburn 6588: } elsif ($context eq 'domain') {
! 6589: $helpitem = 'Domain_Role_Logs';
! 6590: } elsif ($context eq 'author') {
! 6591: $helpitem = 'Author_User_Logs';
1.406.2.5 raeburn 6592: }
6593: push (@{$brcrum},
6594: {href => '/adm/createuser?action=changelogs',
6595: text => 'User Management Logs',
6596: help => $helpitem});
6597: my $bread_crumbs_component = 'User Changes';
6598: my $args = { bread_crumbs => $brcrum,
6599: bread_crumbs_component => $bread_crumbs_component};
6600:
6601: # Create navigation javascript
6602: my $jsnav = &userlogdisplay_js($formname);
6603:
6604: my $jscript = (<<ENDSCRIPT);
6605: <script type="text/javascript">
6606: // <![CDATA[
6607: $jsnav
6608: // ]]>
6609: </script>
6610: ENDSCRIPT
6611:
6612: # print page header
6613: $r->print(&header($jscript,$args));
6614:
1.239 raeburn 6615: # set defaults
6616: my $now = time();
6617: my $defstart = $now - (7*24*3600); #7 days ago
6618: my %defaults = (
6619: page => '1',
6620: show => '10',
6621: role => 'any',
6622: chgcontext => 'any',
6623: rolelog_start_date => $defstart,
6624: rolelog_end_date => $now,
6625: );
6626: my $more_records = 0;
6627:
6628: # set current
6629: my %curr;
6630: foreach my $item ('show','page','role','chgcontext') {
6631: $curr{$item} = $env{'form.'.$item};
6632: }
6633: my ($startdate,$enddate) =
6634: &Apache::lonuserutils::get_dates_from_form('rolelog_start_date','rolelog_end_date');
6635: $curr{'rolelog_start_date'} = $startdate;
6636: $curr{'rolelog_end_date'} = $enddate;
6637: foreach my $key (keys(%defaults)) {
6638: if ($curr{$key} eq '') {
6639: $curr{$key} = $defaults{$key};
6640: }
6641: }
1.248 raeburn 6642: my (%whodunit,%changed,$version);
6643: ($version) = ($r->dir_config('lonVersion') =~ /^([\d\.]+)\-/);
1.239 raeburn 6644: my ($minshown,$maxshown);
1.255 raeburn 6645: $minshown = 1;
1.239 raeburn 6646: my $count = 0;
1.406.2.5 raeburn 6647: if ($curr{'show'} =~ /\D/) {
6648: $curr{'page'} = 1;
6649: } else {
1.239 raeburn 6650: $maxshown = $curr{'page'} * $curr{'show'};
6651: if ($curr{'page'} > 1) {
6652: $minshown = 1 + ($curr{'page'} - 1) * $curr{'show'};
6653: }
6654: }
1.301 bisitz 6655:
1.327 raeburn 6656: # Form Header
6657: $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">'.
1.363 raeburn 6658: &role_display_filter($context,$formname,$domain,$username,\%curr,
6659: $version,$crstype));
1.327 raeburn 6660:
6661: my $showntableheader = 0;
6662:
6663: # Table Header
6664: my $tableheader =
6665: &Apache::loncommon::start_data_table_header_row()
6666: .'<th> </th>'
6667: .'<th>'.&mt('When').'</th>'
6668: .'<th>'.&mt('Who made the change').'</th>'
6669: .'<th>'.&mt('Changed User').'</th>'
1.363 raeburn 6670: .'<th>'.&mt('Role').'</th>';
6671:
6672: if ($context eq 'course') {
6673: $tableheader .= '<th>'.&mt('Section').'</th>';
6674: }
6675: $tableheader .=
6676: '<th>'.&mt('Context').'</th>'
1.327 raeburn 6677: .'<th>'.&mt('Start').'</th>'
6678: .'<th>'.&mt('End').'</th>'
6679: .&Apache::loncommon::end_data_table_header_row();
6680:
6681: # Display user change log data
1.239 raeburn 6682: foreach my $id (sort { $roleslog{$b}{'exe_time'}<=>$roleslog{$a}{'exe_time'} } (keys(%roleslog))) {
6683: next if (($roleslog{$id}{'exe_time'} < $curr{'rolelog_start_date'}) ||
6684: ($roleslog{$id}{'exe_time'} > $curr{'rolelog_end_date'}));
1.406.2.5 raeburn 6685: if ($curr{'show'} !~ /\D/) {
1.239 raeburn 6686: if ($count >= $curr{'page'} * $curr{'show'}) {
6687: $more_records = 1;
6688: last;
6689: }
6690: }
6691: if ($curr{'role'} ne 'any') {
6692: next if ($roleslog{$id}{'logentry'}{'role'} ne $curr{'role'});
6693: }
6694: if ($curr{'chgcontext'} ne 'any') {
6695: if ($curr{'chgcontext'} eq 'selfenroll') {
6696: next if (!$roleslog{$id}{'logentry'}{'selfenroll'});
6697: } else {
6698: next if ($roleslog{$id}{'logentry'}{'context'} ne $curr{'chgcontext'});
6699: }
6700: }
1.406.2.6 raeburn 6701: if (($context eq 'course') && ($viewablesec ne '')) {
6702: next if ($roleslog{$id}{'logentry'}{'section'} ne $viewablesec);
6703: }
1.239 raeburn 6704: $count ++;
6705: next if ($count < $minshown);
1.327 raeburn 6706: unless ($showntableheader) {
1.406.2.5 raeburn 6707: $r->print(&Apache::loncommon::start_data_table()
1.327 raeburn 6708: .$tableheader);
6709: $r->rflush();
6710: $showntableheader = 1;
6711: }
1.239 raeburn 6712: if ($whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}} eq '') {
6713: $whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}} =
6714: &Apache::loncommon::plainname($roleslog{$id}{'exe_uname'},$roleslog{$id}{'exe_udom'});
6715: }
6716: if ($changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}} eq '') {
6717: $changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}} =
6718: &Apache::loncommon::plainname($roleslog{$id}{'uname'},$roleslog{$id}{'udom'});
6719: }
6720: my $sec = $roleslog{$id}{'logentry'}{'section'};
6721: if ($sec eq '') {
6722: $sec = &mt('None');
6723: }
6724: my ($rolestart,$roleend);
6725: if ($roleslog{$id}{'delflag'}) {
6726: $rolestart = &mt('deleted');
6727: $roleend = &mt('deleted');
6728: } else {
6729: $rolestart = $roleslog{$id}{'logentry'}{'start'};
6730: $roleend = $roleslog{$id}{'logentry'}{'end'};
6731: if ($rolestart eq '' || $rolestart == 0) {
6732: $rolestart = &mt('No start date');
6733: } else {
6734: $rolestart = &Apache::lonlocal::locallocaltime($rolestart);
6735: }
6736: if ($roleend eq '' || $roleend == 0) {
6737: $roleend = &mt('No end date');
6738: } else {
6739: $roleend = &Apache::lonlocal::locallocaltime($roleend);
6740: }
6741: }
6742: my $chgcontext = $roleslog{$id}{'logentry'}{'context'};
6743: if ($roleslog{$id}{'logentry'}{'selfenroll'}) {
6744: $chgcontext = 'selfenroll';
6745: }
1.363 raeburn 6746: my %lt = &rolechg_contexts($context,$crstype);
1.239 raeburn 6747: if ($chgcontext ne '' && $lt{$chgcontext} ne '') {
6748: $chgcontext = $lt{$chgcontext};
6749: }
1.327 raeburn 6750: $r->print(
1.301 bisitz 6751: &Apache::loncommon::start_data_table_row()
6752: .'<td>'.$count.'</td>'
6753: .'<td>'.&Apache::lonlocal::locallocaltime($roleslog{$id}{'exe_time'}).'</td>'
6754: .'<td>'.$whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}}.'</td>'
6755: .'<td>'.$changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}}.'</td>'
1.363 raeburn 6756: .'<td>'.&Apache::lonnet::plaintext($roleslog{$id}{'logentry'}{'role'},$crstype).'</td>');
6757: if ($context eq 'course') {
6758: $r->print('<td>'.$sec.'</td>');
6759: }
6760: $r->print(
6761: '<td>'.$chgcontext.'</td>'
1.301 bisitz 6762: .'<td>'.$rolestart.'</td>'
6763: .'<td>'.$roleend.'</td>'
1.327 raeburn 6764: .&Apache::loncommon::end_data_table_row()."\n");
1.301 bisitz 6765: }
6766:
1.327 raeburn 6767: if ($showntableheader) { # Table footer, if content displayed above
1.406.2.5 raeburn 6768: $r->print(&Apache::loncommon::end_data_table().
6769: &userlogdisplay_navlinks(\%curr,$more_records));
1.327 raeburn 6770: } else { # No content displayed above
1.301 bisitz 6771: $r->print('<p class="LC_info">'
6772: .&mt('There are no records to display.')
6773: .'</p>'
6774: );
1.239 raeburn 6775: }
1.301 bisitz 6776:
1.327 raeburn 6777: # Form Footer
6778: $r->print(
6779: '<input type="hidden" name="page" value="'.$curr{'page'}.'" />'
6780: .'<input type="hidden" name="action" value="changelogs" />'
6781: .'</form>');
6782: return;
6783: }
1.301 bisitz 6784:
1.406.2.5 raeburn 6785: sub print_useraccesslogs_display {
6786: my ($r,$uname,$udom,$permission,$brcrum) = @_;
6787: my $formname = 'accesslog';
6788: my $form = 'document.accesslog';
6789:
6790: # set breadcrumbs
1.406.2.7 raeburn 6791: my %breadcrumb_text = &singleuser_breadcrumb('','domain',$udom);
1.406.2.12 raeburn 6792: my $prevphasestr;
6793: if ($env{'form.popup'}) {
6794: $brcrum = [];
6795: } else {
6796: push (@{$brcrum},
6797: {href => "javascript:backPage($form)",
6798: text => $breadcrumb_text{'search'}});
6799: my @prevphases;
6800: if ($env{'form.prevphases'}) {
6801: @prevphases = split(/,/,$env{'form.prevphases'});
6802: $prevphasestr = $env{'form.prevphases'};
6803: }
6804: if (($env{'form.phase'} eq 'userpicked') || (grep(/^userpicked$/,@prevphases))) {
6805: push(@{$brcrum},
6806: {href => "javascript:backPage($form,'get_user_info','select')",
6807: text => $breadcrumb_text{'userpicked'}});
6808: if ($env{'form.phase'} eq 'userpicked') {
6809: $prevphasestr = 'userpicked';
6810: }
1.406.2.5 raeburn 6811: }
6812: }
6813: push(@{$brcrum},
6814: {href => '/adm/createuser?action=accesslogs',
6815: text => 'User access logs',
1.406.2.8 raeburn 6816: help => 'Domain_User_Access_Logs'});
1.406.2.5 raeburn 6817: my $bread_crumbs_component = 'User Access Logs';
6818: my $args = { bread_crumbs => $brcrum,
6819: bread_crumbs_component => 'User Management'};
1.406.2.8 raeburn 6820: if ($env{'form.popup'}) {
6821: $args->{'no_nav_bar'} = 1;
1.406.2.12 raeburn 6822: $args->{'bread_crumbs_nomenu'} = 1;
1.406.2.8 raeburn 6823: }
1.406.2.5 raeburn 6824:
6825: # set javascript
6826: my ($jsback,$elements) = &crumb_utilities();
6827: my $jsnav = &userlogdisplay_js($formname);
6828:
6829: my $jscript = (<<ENDSCRIPT);
1.239 raeburn 6830: <script type="text/javascript">
1.301 bisitz 6831: // <![CDATA[
1.406.2.5 raeburn 6832:
6833: $jsback
6834: $jsnav
6835:
6836: // ]]>
6837: </script>
6838:
6839: ENDSCRIPT
6840:
6841: # print page header
6842: $r->print(&header($jscript,$args));
6843:
6844: # early out unless log data can be displayed.
6845: unless ($permission->{'activity'}) {
6846: $r->print('<p class="LC_warning">'
6847: .&mt('You do not have rights to display user access logs.')
1.406.2.12 raeburn 6848: .'</p>');
6849: if ($env{'form.popup'}) {
6850: $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a></p>');
6851: } else {
6852: $r->print(&earlyout_accesslog_form($formname,$prevphasestr,$udom));
6853: }
1.406.2.5 raeburn 6854: return;
6855: }
6856:
6857: unless ($udom eq $env{'request.role.domain'}) {
6858: $r->print('<p class="LC_warning">'
6859: .&mt("User's domain must match role's domain")
6860: .'</p>'
6861: .&earlyout_accesslog_form($formname,$prevphasestr,$udom));
6862: return;
6863: }
6864:
6865: if (($uname eq '') || ($udom eq '')) {
6866: $r->print('<p class="LC_warning">'
6867: .&mt('Invalid username or domain')
6868: .'</p>'
6869: .&earlyout_accesslog_form($formname,$prevphasestr,$udom));
6870: return;
6871: }
6872:
1.406.2.13 raeburn 6873: if (&Apache::lonnet::privileged($uname,$udom,
6874: [$env{'request.role.domain'}],['dc','su'])) {
6875: unless (&Apache::lonnet::privileged($env{'user.name'},$env{'user.domain'},
6876: [$env{'request.role.domain'}],['dc','su'])) {
6877: $r->print('<p class="LC_warning">'
6878: .&mt('You need to be a privileged user to display user access logs for [_1]',
6879: &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),
6880: $uname,$udom))
6881: .'</p>');
6882: if ($env{'form.popup'}) {
6883: $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a></p>');
6884: } else {
6885: $r->print(&earlyout_accesslog_form($formname,$prevphasestr,$udom));
6886: }
6887: return;
6888: }
6889: }
6890:
1.406.2.5 raeburn 6891: # set defaults
6892: my $now = time();
6893: my $defstart = $now - (7*24*3600);
6894: my %defaults = (
6895: page => '1',
6896: show => '10',
6897: activity => 'any',
6898: accesslog_start_date => $defstart,
6899: accesslog_end_date => $now,
6900: );
6901: my $more_records = 0;
6902:
6903: # set current
6904: my %curr;
6905: foreach my $item ('show','page','activity') {
6906: $curr{$item} = $env{'form.'.$item};
6907: }
6908: my ($startdate,$enddate) =
6909: &Apache::lonuserutils::get_dates_from_form('accesslog_start_date','accesslog_end_date');
6910: $curr{'accesslog_start_date'} = $startdate;
6911: $curr{'accesslog_end_date'} = $enddate;
6912: foreach my $key (keys(%defaults)) {
6913: if ($curr{$key} eq '') {
6914: $curr{$key} = $defaults{$key};
6915: }
6916: }
6917: my ($minshown,$maxshown);
6918: $minshown = 1;
6919: my $count = 0;
6920: if ($curr{'show'} =~ /\D/) {
6921: $curr{'page'} = 1;
6922: } else {
6923: $maxshown = $curr{'page'} * $curr{'show'};
6924: if ($curr{'page'} > 1) {
6925: $minshown = 1 + ($curr{'page'} - 1) * $curr{'show'};
6926: }
6927: }
6928:
6929: # form header
6930: $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">'.
6931: &activity_display_filter($formname,\%curr));
6932:
6933: my $showntableheader = 0;
6934: my ($nav_script,$nav_links);
6935:
6936: # table header
1.406.2.12 raeburn 6937: my $tableheader = '<h3>'.
6938: &mt('User access logs for: [_1]',
6939: &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),$uname,$udom)).'</h3>'
6940: .&Apache::loncommon::start_data_table_header_row()
1.406.2.5 raeburn 6941: .'<th> </th>'
6942: .'<th>'.&mt('When').'</th>'
6943: .'<th>'.&mt('HostID').'</th>'
6944: .'<th>'.&mt('Event').'</th>'
6945: .'<th>'.&mt('Other data').'</th>'
6946: .&Apache::loncommon::end_data_table_header_row();
6947:
6948: my %filters=(
6949: start => $curr{'accesslog_start_date'},
6950: end => $curr{'accesslog_end_date'},
6951: action => $curr{'activity'},
6952: );
6953:
6954: my $reply = &Apache::lonnet::userlog_query($uname,$udom,%filters);
6955: unless ( ($reply =~/^timeout/) || ($reply =~/^error/) ) {
6956: my (%courses,%missing);
6957: my @results = split(/\&/,$reply);
6958: foreach my $item (reverse(@results)) {
6959: my ($timestamp,$host,$event) = split(/:/,$item);
6960: next unless ($event =~ /^(Log|Role)/);
6961: if ($curr{'show'} !~ /\D/) {
6962: if ($count >= $curr{'page'} * $curr{'show'}) {
6963: $more_records = 1;
6964: last;
6965: }
6966: }
6967: $count ++;
6968: next if ($count < $minshown);
6969: unless ($showntableheader) {
6970: $r->print($nav_script
6971: .&Apache::loncommon::start_data_table()
6972: .$tableheader);
6973: $r->rflush();
6974: $showntableheader = 1;
6975: }
1.406.2.6 raeburn 6976: my ($shown,$extra);
1.406.2.13 raeburn 6977: my ($event,$data) = split(/\s+/,&unescape($event),2);
1.406.2.5 raeburn 6978: if ($event eq 'Role') {
6979: my ($rolecode,$extent) = split(/\./,$data,2);
6980: next if ($extent eq '');
6981: my ($crstype,$desc,$info);
1.406.2.6 raeburn 6982: if ($extent =~ m{^/($match_domain)/($match_courseid)(?:/(\w+)|)$}) {
6983: my ($cdom,$cnum,$sec) = ($1,$2,$3);
1.406.2.5 raeburn 6984: my $cid = $cdom.'_'.$cnum;
6985: if (exists($courses{$cid})) {
6986: $crstype = $courses{$cid}{'type'};
6987: $desc = $courses{$cid}{'description'};
6988: } elsif ($missing{$cid}) {
6989: $crstype = 'Course';
6990: $desc = 'Course/Community';
6991: } else {
6992: my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',$cnum,undef,undef,'.');
6993: if (ref($crsinfo{$cdom.'_'.$cnum}) eq 'HASH') {
6994: $courses{$cid} = $crsinfo{$cid};
6995: $crstype = $crsinfo{$cid}{'type'};
6996: $desc = $crsinfo{$cid}{'description'};
6997: } else {
6998: $missing{$cid} = 1;
6999: }
7000: }
7001: $extra = &mt($crstype).': <a href="/public/'.$cdom.'/'.$cnum.'/syllabus">'.$desc.'</a>';
1.406.2.6 raeburn 7002: if ($sec ne '') {
7003: $extra .= ' ('.&mt('Section: [_1]',$sec).')';
7004: }
1.406.2.5 raeburn 7005: } elsif ($extent =~ m{^/($match_domain)/($match_username|$)}) {
7006: my ($dom,$name) = ($1,$2);
7007: if ($rolecode eq 'au') {
7008: $extra = '';
7009: } elsif ($rolecode =~ /^(ca|aa)$/) {
7010: $extra = &mt('Authoring Space: [_1]',$name.':'.$dom);
7011: } elsif ($rolecode =~ /^(li|dg|dh|dc|sc)$/) {
7012: $extra = &mt('Domain: [_1]',$dom);
7013: }
7014: }
7015: my $rolename;
7016: if ($rolecode =~ m{^cr/($match_domain)/($match_username)/(\w+)}) {
7017: my $role = $3;
7018: my $owner = "($2:$1)";
7019: if ($2 eq $1.'-domainconfig') {
7020: $owner = '(ad hoc)';
7021: }
7022: $rolename = &mt('Custom role: [_1]',$role.' '.$owner);
7023: } else {
7024: $rolename = &Apache::lonnet::plaintext($rolecode,$crstype);
7025: }
7026: $shown = &mt('Role selection: [_1]',$rolename);
7027: } else {
7028: $shown = &mt($event);
1.406.2.13 raeburn 7029: if ($data =~ /^webdav/) {
7030: my ($path,$clientip) = split(/\s+/,$data,2);
7031: $path =~ s/^webdav//;
7032: if ($clientip ne '') {
7033: $extra = &mt('Client IP address: [_1]',$clientip);
7034: }
7035: if ($path ne '') {
7036: $shown .= ' '.&mt('(WebDAV access to [_1])',$path);
7037: }
7038: } elsif ($data ne '') {
7039: $extra = &mt('Client IP address: [_1]',$data);
1.406.2.5 raeburn 7040: }
7041: }
7042: $r->print(
7043: &Apache::loncommon::start_data_table_row()
7044: .'<td>'.$count.'</td>'
7045: .'<td>'.&Apache::lonlocal::locallocaltime($timestamp).'</td>'
7046: .'<td>'.$host.'</td>'
7047: .'<td>'.$shown.'</td>'
7048: .'<td>'.$extra.'</td>'
7049: .&Apache::loncommon::end_data_table_row()."\n");
7050: }
7051: }
7052:
7053: if ($showntableheader) { # Table footer, if content displayed above
7054: $r->print(&Apache::loncommon::end_data_table().
7055: &userlogdisplay_navlinks(\%curr,$more_records));
7056: } else { # No content displayed above
7057: $r->print('<p class="LC_info">'
7058: .&mt('There are no records to display.')
7059: .'</p>');
7060: }
7061:
1.406.2.8 raeburn 7062: if ($env{'form.popup'} == 1) {
7063: $r->print('<input type="hidden" name="popup" value="1" />'."\n");
7064: }
7065:
1.406.2.5 raeburn 7066: # Form Footer
7067: $r->print(
7068: '<input type="hidden" name="currstate" value="" />'
7069: .'<input type="hidden" name="accessuname" value="'.$uname.'" />'
7070: .'<input type="hidden" name="accessudom" value="'.$udom.'" />'
7071: .'<input type="hidden" name="page" value="'.$curr{'page'}.'" />'
7072: .'<input type="hidden" name="prevphases" value="'.$prevphasestr.'" />'
7073: .'<input type="hidden" name="phase" value="activity" />'
7074: .'<input type="hidden" name="action" value="accesslogs" />'
7075: .'<input type="hidden" name="srchdomain" value="'.$udom.'" />'
7076: .'<input type="hidden" name="srchby" value="'.$env{'form.srchby'}.'" />'
7077: .'<input type="hidden" name="srchtype" value="'.$env{'form.srchtype'}.'" />'
7078: .'<input type="hidden" name="srchterm" value="'.&HTML::Entities::encode($env{'form.srchterm'},'<>"&').'" />'
7079: .'<input type="hidden" name="srchin" value="'.$env{'form.srchin'}.'" />'
7080: .'</form>');
7081: return;
7082: }
7083:
7084: sub earlyout_accesslog_form {
7085: my ($formname,$prevphasestr,$udom) = @_;
7086: my $srchterm = &HTML::Entities::encode($env{'form.srchterm'},'<>"&');
7087: return <<"END";
7088: <form action="/adm/createuser" method="post" name="$formname">
7089: <input type="hidden" name="currstate" value="" />
7090: <input type="hidden" name="prevphases" value="$prevphasestr" />
7091: <input type="hidden" name="phase" value="activity" />
7092: <input type="hidden" name="action" value="accesslogs" />
7093: <input type="hidden" name="srchdomain" value="$udom" />
7094: <input type="hidden" name="srchby" value="$env{'form.srchby'}" />
7095: <input type="hidden" name="srchtype" value="$env{'form.srchtype'}" />
7096: <input type="hidden" name="srchterm" value="$srchterm" />
7097: <input type="hidden" name="srchin" value="$env{'form.srchin'}" />
7098: </form>
7099: END
7100: }
7101:
7102: sub activity_display_filter {
7103: my ($formname,$curr) = @_;
7104: my $nolink = 1;
7105: my $output = '<table><tr><td valign="top">'.
7106: '<span class="LC_nobreak"><b>'.&mt('Actions/page:').'</b></span><br />'.
7107: &Apache::lonmeta::selectbox('show',$curr->{'show'},undef,
7108: (&mt('all'),5,10,20,50,100,1000,10000)).
7109: '</td><td> </td>';
7110: my $startform =
7111: &Apache::lonhtmlcommon::date_setter($formname,'accesslog_start_date',
7112: $curr->{'accesslog_start_date'},undef,
7113: undef,undef,undef,undef,undef,undef,$nolink);
7114: my $endform =
7115: &Apache::lonhtmlcommon::date_setter($formname,'accesslog_end_date',
7116: $curr->{'accesslog_end_date'},undef,
7117: undef,undef,undef,undef,undef,undef,$nolink);
7118: my %lt = &Apache::lonlocal::texthash (
7119: activity => 'Activity',
7120: Role => 'Role selection',
7121: log => 'Log-in or Logout',
7122: );
7123: $output .= '<td valign="top"><b>'.&mt('Window during which actions occurred:').'</b><br />'.
7124: '<table><tr><td>'.&mt('After:').
7125: '</td><td>'.$startform.'</td></tr>'.
7126: '<tr><td>'.&mt('Before:').'</td>'.
7127: '<td>'.$endform.'</td></tr></table>'.
7128: '</td>'.
7129: '<td> </td>'.
7130: '<td valign="top"><b>'.&mt('Activities').'</b><br />'.
7131: '<select name="activity"><option value="any"';
7132: if ($curr->{'activity'} eq 'any') {
7133: $output .= ' selected="selected"';
7134: }
7135: $output .= '>'.&mt('Any').'</option>'."\n";
7136: foreach my $activity ('Role','log') {
7137: my $selstr = '';
7138: if ($activity eq $curr->{'activity'}) {
7139: $selstr = ' selected="selected"';
7140: }
7141: $output .= '<option value="'.$activity.'"'.$selstr.'>'.$lt{$activity}.'</option>';
7142: }
7143: $output .= '</select></td>'.
7144: '</tr></table>';
7145: # Update Display button
7146: $output .= '<p>'
7147: .'<input type="submit" value="'.&mt('Update Display').'" />'
1.406.2.12 raeburn 7148: .'</p><hr />';
1.406.2.5 raeburn 7149: return $output;
7150: }
7151:
7152: sub userlogdisplay_js {
7153: my ($formname) = @_;
7154: return <<"ENDSCRIPT";
7155:
1.239 raeburn 7156: function chgPage(caller) {
7157: if (caller == 'previous') {
7158: document.$formname.page.value --;
7159: }
7160: if (caller == 'next') {
7161: document.$formname.page.value ++;
7162: }
1.327 raeburn 7163: document.$formname.submit();
1.239 raeburn 7164: return;
7165: }
7166: ENDSCRIPT
1.406.2.5 raeburn 7167: }
7168:
7169: sub userlogdisplay_navlinks {
7170: my ($curr,$more_records) = @_;
7171: return unless(ref($curr) eq 'HASH');
7172: # Navigation Buttons
7173: my $nav_links = '<p>';
7174: if (($curr->{'page'} > 1) || ($more_records)) {
7175: if (($curr->{'page'} > 1) && ($curr->{'show'} !~ /\D/)) {
7176: $nav_links .= '<input type="button"'
7177: .' onclick="javascript:chgPage('."'previous'".');"'
7178: .' value="'.&mt('Previous [_1] changes',$curr->{'show'})
7179: .'" /> ';
7180: }
7181: if ($more_records) {
7182: $nav_links .= '<input type="button"'
7183: .' onclick="javascript:chgPage('."'next'".');"'
7184: .' value="'.&mt('Next [_1] changes',$curr->{'show'})
7185: .'" />';
1.301 bisitz 7186: }
7187: }
1.406.2.5 raeburn 7188: $nav_links .= '</p>';
7189: return $nav_links;
1.239 raeburn 7190: }
7191:
7192: sub role_display_filter {
1.363 raeburn 7193: my ($context,$formname,$cdom,$cnum,$curr,$version,$crstype) = @_;
7194: my $lctype;
7195: if ($context eq 'course') {
7196: $lctype = lc($crstype);
7197: }
1.239 raeburn 7198: my $nolink = 1;
7199: my $output = '<table><tr><td valign="top">'.
1.301 bisitz 7200: '<span class="LC_nobreak"><b>'.&mt('Changes/page:').'</b></span><br />'.
1.239 raeburn 7201: &Apache::lonmeta::selectbox('show',$curr->{'show'},undef,
7202: (&mt('all'),5,10,20,50,100,1000,10000)).
7203: '</td><td> </td>';
7204: my $startform =
7205: &Apache::lonhtmlcommon::date_setter($formname,'rolelog_start_date',
7206: $curr->{'rolelog_start_date'},undef,
7207: undef,undef,undef,undef,undef,undef,$nolink);
7208: my $endform =
7209: &Apache::lonhtmlcommon::date_setter($formname,'rolelog_end_date',
7210: $curr->{'rolelog_end_date'},undef,
7211: undef,undef,undef,undef,undef,undef,$nolink);
1.363 raeburn 7212: my %lt = &rolechg_contexts($context,$crstype);
1.301 bisitz 7213: $output .= '<td valign="top"><b>'.&mt('Window during which changes occurred:').'</b><br />'.
7214: '<table><tr><td>'.&mt('After:').
7215: '</td><td>'.$startform.'</td></tr>'.
7216: '<tr><td>'.&mt('Before:').'</td>'.
7217: '<td>'.$endform.'</td></tr></table>'.
7218: '</td>'.
7219: '<td> </td>'.
1.239 raeburn 7220: '<td valign="top"><b>'.&mt('Role:').'</b><br />'.
7221: '<select name="role"><option value="any"';
7222: if ($curr->{'role'} eq 'any') {
7223: $output .= ' selected="selected"';
7224: }
7225: $output .= '>'.&mt('Any').'</option>'."\n";
1.363 raeburn 7226: my @roles = &Apache::lonuserutils::roles_by_context($context,1,$crstype);
1.239 raeburn 7227: foreach my $role (@roles) {
7228: my $plrole;
7229: if ($role eq 'cr') {
7230: $plrole = &mt('Custom Role');
7231: } else {
1.318 raeburn 7232: $plrole=&Apache::lonnet::plaintext($role,$crstype);
1.239 raeburn 7233: }
7234: my $selstr = '';
7235: if ($role eq $curr->{'role'}) {
7236: $selstr = ' selected="selected"';
7237: }
7238: $output .= ' <option value="'.$role.'"'.$selstr.'>'.$plrole.'</option>';
7239: }
1.301 bisitz 7240: $output .= '</select></td>'.
7241: '<td> </td>'.
7242: '<td valign="top"><b>'.
1.239 raeburn 7243: &mt('Context:').'</b><br /><select name="chgcontext">';
1.363 raeburn 7244: my @posscontexts;
7245: if ($context eq 'course') {
1.376 raeburn 7246: @posscontexts = ('any','automated','updatenow','createcourse','course','domain','selfenroll','requestcourses');
1.363 raeburn 7247: } elsif ($context eq 'domain') {
7248: @posscontexts = ('any','domain','requestauthor','domconfig','server');
7249: } else {
7250: @posscontexts = ('any','author','domain');
7251: }
7252: foreach my $chgtype (@posscontexts) {
1.239 raeburn 7253: my $selstr = '';
7254: if ($curr->{'chgcontext'} eq $chgtype) {
1.301 bisitz 7255: $selstr = ' selected="selected"';
1.239 raeburn 7256: }
1.363 raeburn 7257: if ($context eq 'course') {
1.376 raeburn 7258: if (($chgtype eq 'automated') || ($chgtype eq 'updatenow')) {
1.363 raeburn 7259: next if (!&Apache::lonnet::auto_run($cnum,$cdom));
7260: }
1.239 raeburn 7261: }
7262: $output .= '<option value="'.$chgtype.'"'.$selstr.'>'.$lt{$chgtype}.'</option>'."\n";
1.248 raeburn 7263: }
1.303 bisitz 7264: $output .= '</select></td>'
7265: .'</tr></table>';
7266:
7267: # Update Display button
7268: $output .= '<p>'
7269: .'<input type="submit" value="'.&mt('Update Display').'" />'
7270: .'</p>';
7271:
7272: # Server version info
1.363 raeburn 7273: my $needsrev = '2.11.0';
7274: if ($context eq 'course') {
7275: $needsrev = '2.7.0';
7276: }
7277:
1.303 bisitz 7278: $output .= '<p class="LC_info">'
7279: .&mt('Only changes made from servers running LON-CAPA [_1] or later are displayed.'
1.363 raeburn 7280: ,$needsrev);
1.248 raeburn 7281: if ($version) {
1.303 bisitz 7282: $output .= ' '.&mt('This LON-CAPA server is version [_1]',$version);
7283: }
7284: $output .= '</p><hr />';
1.239 raeburn 7285: return $output;
7286: }
7287:
7288: sub rolechg_contexts {
1.363 raeburn 7289: my ($context,$crstype) = @_;
7290: my %lt;
7291: if ($context eq 'course') {
7292: %lt = &Apache::lonlocal::texthash (
1.239 raeburn 7293: any => 'Any',
1.376 raeburn 7294: automated => 'Automated Enrollment',
1.239 raeburn 7295: updatenow => 'Roster Update',
7296: createcourse => 'Course Creation',
7297: course => 'User Management in course',
7298: domain => 'User Management in domain',
1.313 raeburn 7299: selfenroll => 'Self-enrolled',
1.318 raeburn 7300: requestcourses => 'Course Request',
1.239 raeburn 7301: );
1.363 raeburn 7302: if ($crstype eq 'Community') {
7303: $lt{'createcourse'} = &mt('Community Creation');
7304: $lt{'course'} = &mt('User Management in community');
7305: $lt{'requestcourses'} = &mt('Community Request');
7306: }
7307: } elsif ($context eq 'domain') {
7308: %lt = &Apache::lonlocal::texthash (
7309: any => 'Any',
7310: domain => 'User Management in domain',
7311: requestauthor => 'Authoring Request',
7312: server => 'Command line script (DC role)',
7313: domconfig => 'Self-enrolled',
7314: );
7315: } else {
7316: %lt = &Apache::lonlocal::texthash (
7317: any => 'Any',
7318: domain => 'User Management in domain',
7319: author => 'User Management by author',
7320: );
7321: }
1.239 raeburn 7322: return %lt;
7323: }
7324:
1.406.2.10 raeburn 7325: sub print_helpdeskaccess_display {
7326: my ($r,$permission,$brcrum) = @_;
7327: my $formname = 'helpdeskaccess';
7328: my $helpitem = 'Course_Helpdesk_Access';
7329: push (@{$brcrum},
7330: {href => '/adm/createuser?action=helpdesk',
7331: text => 'Helpdesk Access',
7332: help => $helpitem});
7333: my $bread_crumbs_component = 'Helpdesk Staff Access';
7334: my $args = { bread_crumbs => $brcrum,
7335: bread_crumbs_component => $bread_crumbs_component};
7336:
7337: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
7338: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
7339: my $confname = $cdom.'-domainconfig';
7340: my $crstype = &Apache::loncommon::course_type();
7341:
1.406.2.12 raeburn 7342: my @accesstypes = ('all','dh','da','none');
1.406.2.10 raeburn 7343: my ($numstatustypes,@jsarray);
7344: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($cdom);
7345: if (ref($types) eq 'ARRAY') {
7346: if (@{$types} > 0) {
7347: $numstatustypes = scalar(@{$types});
7348: push(@accesstypes,'status');
7349: @jsarray = ('bystatus');
7350: }
7351: }
7352: my %customroles = &get_domain_customroles($cdom,$confname);
1.406.2.12 raeburn 7353: my %domhelpdesk = &Apache::lonnet::get_active_domroles($cdom,['dh','da']);
1.406.2.10 raeburn 7354: if (keys(%domhelpdesk)) {
7355: push(@accesstypes,('inc','exc'));
7356: push(@jsarray,('notinc','notexc'));
7357: }
7358: push(@jsarray,'privs');
7359: my $hiddenstr = join("','",@jsarray);
7360: my $rolestr = join("','",sort(keys(%customroles)));
7361:
7362: my $jscript;
7363: my (%settings,%overridden);
7364: if (keys(%customroles)) {
7365: &get_adhocrole_settings($env{'request.course.id'},\@accesstypes,
7366: $types,\%customroles,\%settings,\%overridden);
7367: my %jsfull=();
7368: my %jslevels= (
7369: course => {},
7370: domain => {},
7371: system => {},
7372: );
7373: my %jslevelscurrent=(
7374: course => {},
7375: domain => {},
7376: system => {},
7377: );
7378: my (%privs,%jsprivs);
7379: &Apache::lonuserutils::custom_role_privs(\%privs,\%jsfull,\%jslevels,\%jslevelscurrent);
7380: foreach my $priv (keys(%jsfull)) {
7381: if ($jslevels{'course'}{$priv}) {
7382: $jsprivs{$priv} = 1;
7383: }
7384: }
7385: my (%elements,%stored);
7386: foreach my $role (keys(%customroles)) {
7387: $elements{$role.'_access'} = 'radio';
7388: $elements{$role.'_incrs'} = 'radio';
7389: if ($numstatustypes) {
7390: $elements{$role.'_status'} = 'checkbox';
7391: }
7392: if (keys(%domhelpdesk) > 0) {
7393: $elements{$role.'_staff_inc'} = 'checkbox';
7394: $elements{$role.'_staff_exc'} = 'checkbox';
7395: }
7396: $elements{$role.'_override'} = 'checkbox';
7397: if (ref($settings{$role}) eq 'HASH') {
7398: if ($settings{$role}{'access'} ne '') {
7399: my $curraccess = $settings{$role}{'access'};
7400: $stored{$role.'_access'} = $curraccess;
7401: $stored{$role.'_incrs'} = 1;
7402: if ($curraccess eq 'status') {
7403: if (ref($settings{$role}{'status'}) eq 'ARRAY') {
7404: $stored{$role.'_status'} = $settings{$role}{'status'};
7405: }
7406: } elsif (($curraccess eq 'exc') || ($curraccess eq 'inc')) {
7407: if (ref($settings{$role}{$curraccess}) eq 'ARRAY') {
7408: $stored{$role.'_staff_'.$curraccess} = $settings{$role}{$curraccess};
7409: }
7410: }
7411: } else {
7412: $stored{$role.'_incrs'} = 0;
7413: }
7414: $stored{$role.'_override'} = [];
7415: if ($env{'course.'.$env{'request.course.id'}.'.internal.adhocpriv.'.$role}) {
7416: if (ref($settings{$role}{'off'}) eq 'ARRAY') {
7417: foreach my $priv (@{$settings{$role}{'off'}}) {
7418: push(@{$stored{$role.'_override'}},$priv);
7419: }
7420: }
7421: if (ref($settings{$role}{'on'}) eq 'ARRAY') {
7422: foreach my $priv (@{$settings{$role}{'on'}}) {
7423: unless (grep(/^$priv$/,@{$stored{$role.'_override'}})) {
7424: push(@{$stored{$role.'_override'}},$priv);
7425: }
7426: }
7427: }
7428: }
7429: } else {
7430: $stored{$role.'_incrs'} = 0;
7431: }
7432: }
7433: $jscript = &Apache::lonhtmlcommon::set_form_elements(\%elements,\%stored);
7434: }
7435:
7436: my $js = <<"ENDJS";
7437: <script type="text/javascript">
7438: // <![CDATA[
7439: $jscript;
7440:
7441: function switchRoleTab(caller,role) {
7442: if (document.getElementById(role+'_maindiv')) {
7443: if (caller.id != 'LC_current_minitab') {
7444: if (document.getElementById('LC_current_minitab')) {
7445: document.getElementById('LC_current_minitab').id=null;
7446: }
7447: var roledivs = Array('$rolestr');
7448: if (roledivs.length > 0) {
7449: for (var i=0; i<roledivs.length; i++) {
7450: if (document.getElementById(roledivs[i]+'_maindiv')) {
7451: document.getElementById(roledivs[i]+'_maindiv').style.display='none';
7452: }
7453: }
7454: }
7455: caller.id = 'LC_current_minitab';
7456: document.getElementById(role+'_maindiv').style.display='block';
7457: }
7458: }
7459: return false;
7460: }
7461:
7462: function helpdeskAccess(role) {
7463: var curraccess = null;
7464: if (document.$formname.elements[role+'_access'].length) {
7465: for (var i=0; i<document.$formname.elements[role+'_access'].length; i++) {
7466: if (document.$formname.elements[role+'_access'][i].checked) {
7467: curraccess = document.$formname.elements[role+'_access'][i].value;
7468: }
7469: }
7470: }
7471: var shown = Array();
7472: var hidden = Array();
7473: if (curraccess == 'none') {
7474: hidden = Array ('$hiddenstr');
7475: } else {
7476: if (curraccess == 'status') {
7477: shown = Array ('bystatus','privs');
7478: hidden = Array ('notinc','notexc');
7479: } else {
7480: if (curraccess == 'exc') {
7481: shown = Array ('notexc','privs');
7482: hidden = Array ('notinc','bystatus');
7483: }
7484: if (curraccess == 'inc') {
7485: shown = Array ('notinc','privs');
7486: hidden = Array ('notexc','bystatus');
7487: }
7488: if (curraccess == 'all') {
7489: shown = Array ('privs');
7490: hidden = Array ('notinc','notexc','bystatus');
7491: }
7492: }
7493: }
7494: if (hidden.length > 0) {
7495: for (var i=0; i<hidden.length; i++) {
7496: if (document.getElementById(role+'_'+hidden[i])) {
7497: document.getElementById(role+'_'+hidden[i]).style.display = 'none';
7498: }
7499: }
7500: }
7501: if (shown.length > 0) {
7502: for (var i=0; i<shown.length; i++) {
7503: if (document.getElementById(role+'_'+shown[i])) {
7504: if (shown[i] == 'privs') {
7505: document.getElementById(role+'_'+shown[i]).style.display = 'block';
7506: } else {
7507: document.getElementById(role+'_'+shown[i]).style.display = 'inline';
7508: }
7509: }
7510: }
7511: }
7512: return;
7513: }
7514:
7515: function toggleAccess(role) {
7516: if ((document.getElementById(role+'_setincrs')) &&
7517: (document.getElementById(role+'_setindom'))) {
7518: for (var i=0; i<document.$formname.elements[role+'_incrs'].length; i++) {
7519: if (document.$formname.elements[role+'_incrs'][i].checked) {
7520: if (document.$formname.elements[role+'_incrs'][i].value == 1) {
7521: document.getElementById(role+'_setindom').style.display = 'none';
7522: document.getElementById(role+'_setincrs').style.display = 'block';
7523: } else {
7524: document.getElementById(role+'_setincrs').style.display = 'none';
7525: document.getElementById(role+'_setindom').style.display = 'block';
7526: }
7527: break;
7528: }
7529: }
7530: }
7531: return;
7532: }
7533:
7534: // ]]>
7535: </script>
7536: ENDJS
7537:
7538: $args->{add_entries} = {onload => "javascript:setFormElements(document.$formname)"};
7539:
7540: # print page header
7541: $r->print(&header($js,$args));
7542: # print form header
7543: $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">');
7544:
7545: if (keys(%customroles)) {
7546: my %lt = &Apache::lonlocal::texthash(
7547: 'aco' => 'As course owner you may override the defaults set in the domain for role usage and/or privileges.',
7548: 'rou' => 'Role usage',
7549: 'whi' => 'Which helpdesk personnel may use this role?',
7550: 'udd' => 'Use domain default',
1.406.2.12 raeburn 7551: 'all' => 'All with domain helpdesk or helpdesk assistant role',
7552: 'dh' => 'All with domain helpdesk role',
7553: 'da' => 'All with domain helpdesk assistant role',
1.406.2.10 raeburn 7554: 'none' => 'None',
7555: 'status' => 'Determined based on institutional status',
7556: 'inc' => 'Include all, but exclude specific personnel',
7557: 'exc' => 'Exclude all, but include specific personnel',
7558: 'hel' => 'Helpdesk',
7559: 'rpr' => 'Role privileges',
7560: );
7561: $lt{'tfh'} = &mt("Custom [_1]ad hoc[_2] course roles available for use by the domain's helpdesk are as follows",'<i>','</i>');
7562: my %domconfig = &Apache::lonnet::get_dom('configuration',['helpsettings'],$cdom);
7563: my (%domcurrent,%ordered,%description,%domusage,$disabled);
7564: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
7565: if (ref($domconfig{'helpsettings'}{'adhoc'}) eq 'HASH') {
7566: %domcurrent = %{$domconfig{'helpsettings'}{'adhoc'}};
7567: }
7568: }
7569: my $count = 0;
7570: foreach my $role (sort(keys(%customroles))) {
7571: my ($order,$desc,$access_in_dom);
7572: if (ref($domcurrent{$role}) eq 'HASH') {
7573: $order = $domcurrent{$role}{'order'};
7574: $desc = $domcurrent{$role}{'desc'};
7575: $access_in_dom = $domcurrent{$role}{'access'};
7576: }
7577: if ($order eq '') {
7578: $order = $count;
7579: }
7580: $ordered{$order} = $role;
7581: if ($desc ne '') {
7582: $description{$role} = $desc;
7583: } else {
7584: $description{$role}= $role;
7585: }
7586: $count++;
7587: }
7588: %domusage = &domain_adhoc_access(\%customroles,\%domcurrent,\@accesstypes,$usertypes,$othertitle);
7589: my @roles_by_num = ();
7590: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
7591: push(@roles_by_num,$ordered{$item});
7592: }
7593: $r->print('<p>'.$lt{'tfh'}.': <i>'.join('</i>, <i>',map { $description{$_}; } @roles_by_num).'</i>.');
7594: if ($permission->{'owner'}) {
7595: $r->print('<br />'.$lt{'aco'}.'</p><p>');
7596: $r->print('<input type="hidden" name="state" value="process" />'.
7597: '<input type="submit" value="'.&mt('Save changes').'" />');
7598: } else {
7599: if ($env{'course.'.$env{'request.course.id'}.'.internal.courseowner'}) {
7600: my ($ownername,$ownerdom) = split(/:/,$env{'course.'.$env{'request.course.id'}.'.internal.courseowner'});
7601: $r->print('<br />'.&mt('The course owner -- [_1] -- can override the default access and/or privileges for these ad hoc roles.',
7602: &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($ownername,$ownerdom),$ownername,$ownerdom)));
7603: }
7604: $disabled = ' disabled="disabled"';
7605: }
7606: $r->print('</p>');
7607:
7608: $r->print('<div id="LC_minitab_header"><ul>');
7609: my $count = 0;
7610: my %visibility;
7611: foreach my $role (@roles_by_num) {
7612: my $id;
7613: if ($count == 0) {
7614: $id=' id="LC_current_minitab"';
7615: $visibility{$role} = ' style="display:block"';
7616: } else {
7617: $visibility{$role} = ' style="display:none"';
7618: }
7619: $count ++;
7620: $r->print('<li'.$id.'><a href="#" onclick="javascript:switchRoleTab(this.parentNode,'."'$role'".');">'.$description{$role}.'</a></li>');
7621: }
7622: $r->print('</ul></div>');
7623:
7624: foreach my $role (@roles_by_num) {
7625: my %usecheck = (
7626: all => ' checked="checked"',
7627: );
7628: my %displaydiv = (
7629: status => 'none',
7630: inc => 'none',
7631: exc => 'none',
7632: priv => 'block',
7633: );
7634: my (%selected,$overridden,$incrscheck,$indomcheck,$indomvis,$incrsvis);
7635: if (ref($settings{$role}) eq 'HASH') {
7636: if ($settings{$role}{'access'} ne '') {
7637: $indomvis = ' style="display:none"';
7638: $incrsvis = ' style="display:block"';
7639: $incrscheck = ' checked="checked"';
7640: if ($settings{$role}{'access'} ne 'all') {
7641: $usecheck{$settings{$role}{'access'}} = $usecheck{'all'};
7642: delete($usecheck{'all'});
7643: if ($settings{$role}{'access'} eq 'status') {
7644: my $access = 'status';
7645: $displaydiv{$access} = 'inline';
7646: if (ref($settings{$role}{$access}) eq 'ARRAY') {
7647: $selected{$access} = $settings{$role}{$access};
7648: }
7649: } elsif ($settings{$role}{'access'} =~ /^(inc|exc)$/) {
7650: my $access = $1;
7651: $displaydiv{$access} = 'inline';
7652: if (ref($settings{$role}{$access}) eq 'ARRAY') {
7653: $selected{$access} = $settings{$role}{$access};
7654: }
7655: } elsif ($settings{$role}{'access'} eq 'none') {
7656: $displaydiv{'priv'} = 'none';
7657: }
7658: }
7659: } else {
7660: $indomcheck = ' checked="checked"';
7661: $indomvis = ' style="display:block"';
7662: $incrsvis = ' style="display:none"';
7663: }
7664: } else {
7665: $indomcheck = ' checked="checked"';
7666: $indomvis = ' style="display:block"';
7667: $incrsvis = ' style="display:none"';
7668: }
7669: $r->print('<div class="LC_left_float" id="'.$role.'_maindiv"'.$visibility{$role}.'>'.
7670: '<fieldset><legend>'.$lt{'rou'}.'</legend>'.
7671: '<p>'.$lt{'whi'}.' <span class="LC_nobreak">'.
7672: '<label><input type="radio" name="'.$role.'_incrs" value="1"'.$incrscheck.' onclick="toggleAccess('."'$role'".');"'.$disabled.'>'.
7673: &mt('Set here in [_1]',lc($crstype)).'</label>'.
7674: '<span>'.(' 'x2).
7675: '<label><input type="radio" name="'.$role.'_incrs" value="0"'.$indomcheck.' onclick="toggleAccess('."'$role'".');"'.$disabled.'>'.
7676: $lt{'udd'}.'</label><span></p>'.
7677: '<div id="'.$role.'_setindom"'.$indomvis.'>'.
7678: '<span class="LC_cusr_emph">'.$domusage{$role}.'</span></div>'.
7679: '<div id="'.$role.'_setincrs"'.$incrsvis.'>');
7680: foreach my $access (@accesstypes) {
7681: $r->print('<p><label><input type="radio" name="'.$role.'_access" value="'.$access.'" '.$usecheck{$access}.
7682: ' onclick="helpdeskAccess('."'$role'".');"'.$disabled.' />'.$lt{$access}.'</label>');
7683: if ($access eq 'status') {
7684: $r->print('<div id="'.$role.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
7685: &Apache::lonuserutils::adhoc_status_types($cdom,undef,$role,$selected{$access},
7686: $othertitle,$usertypes,$types,$disabled).
7687: '</div>');
7688: } elsif (($access eq 'inc') && (keys(%domhelpdesk) > 0)) {
7689: $r->print('<div id="'.$role.'_notinc" style="display:'.$displaydiv{$access}.'">'.
7690: &Apache::lonuserutils::adhoc_staff($access,undef,$role,$selected{$access},
7691: \%domhelpdesk,$disabled).
7692: '</div>');
7693: } elsif (($access eq 'exc') && (keys(%domhelpdesk) > 0)) {
7694: $r->print('<div id="'.$role.'_notexc" style="display:'.$displaydiv{$access}.'">'.
7695: &Apache::lonuserutils::adhoc_staff($access,undef,$role,$selected{$access},
7696: \%domhelpdesk,$disabled).
7697: '</div>');
7698: }
7699: $r->print('</p>');
7700: }
7701: $r->print('</div></fieldset>');
7702: my %full=();
7703: my %levels= (
7704: course => {},
7705: domain => {},
7706: system => {},
7707: );
7708: my %levelscurrent=(
7709: course => {},
7710: domain => {},
7711: system => {},
7712: );
7713: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
7714: $r->print('<fieldset id="'.$role.'_privs" style="display:'.$displaydiv{'priv'}.'">'.
7715: '<legend>'.$lt{'rpr'}.'</legend>'.
7716: &role_priv_table($role,$permission,$crstype,\%full,\%levels,\%levelscurrent,$overridden{$role}).
7717: '</fieldset></div><div style="padding:0;clear:both;margin:0;border:0"></div>');
7718: }
7719: if ($permission->{'owner'}) {
7720: $r->print('<p><input type="submit" value="'.&mt('Save changes').'" /></p>');
7721: }
7722: } else {
7723: $r->print(&mt('Helpdesk roles have not yet been created in this domain.'));
7724: }
7725: # Form Footer
7726: $r->print('<input type="hidden" name="action" value="helpdesk" />'
7727: .'</form>');
7728: return;
7729: }
7730:
7731: sub domain_adhoc_access {
7732: my ($roles,$domcurrent,$accesstypes,$usertypes,$othertitle) = @_;
7733: my %domusage;
7734: return unless ((ref($roles) eq 'HASH') && (ref($domcurrent) eq 'HASH') && (ref($accesstypes) eq 'ARRAY'));
7735: foreach my $role (keys(%{$roles})) {
7736: if (ref($domcurrent->{$role}) eq 'HASH') {
7737: my $access = $domcurrent->{$role}{'access'};
7738: if (($access eq '') || (!grep(/^\Q$access\E$/,@{$accesstypes}))) {
7739: $access = 'all';
1.406.2.12 raeburn 7740: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role',&Apache::lonnet::plaintext('dh'),
7741: &Apache::lonnet::plaintext('da'));
1.406.2.10 raeburn 7742: } elsif ($access eq 'status') {
7743: if (ref($domcurrent->{$role}{$access}) eq 'ARRAY') {
7744: my @shown;
7745: foreach my $type (@{$domcurrent->{$role}{$access}}) {
7746: unless ($type eq 'default') {
7747: if ($usertypes->{$type}) {
7748: push(@shown,$usertypes->{$type});
7749: }
7750: }
7751: }
7752: if (grep(/^default$/,@{$domcurrent->{$role}{$access}})) {
7753: push(@shown,$othertitle);
7754: }
7755: if (@shown) {
7756: my $shownstatus = join(' '.&mt('or').' ',@shown);
1.406.2.12 raeburn 7757: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role, and institutional status: [_3]',
7758: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'),$shownstatus);
1.406.2.10 raeburn 7759: } else {
7760: $domusage{$role} = &mt('No one in the domain');
7761: }
7762: }
7763: } elsif ($access eq 'inc') {
7764: my @dominc = ();
7765: if (ref($domcurrent->{$role}{'inc'}) eq 'ARRAY') {
7766: foreach my $user (@{$domcurrent->{$role}{'inc'}}) {
7767: my ($uname,$udom) = split(/:/,$user);
7768: push(@dominc,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),$uname,$udom));
7769: }
7770: my $showninc = join(', ',@dominc);
7771: if ($showninc ne '') {
1.406.2.12 raeburn 7772: $domusage{$role} = &mt('Include any user in domain with active [_1] or [_2] role, except: [_3]',
7773: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'),$showninc);
1.406.2.10 raeburn 7774: } else {
1.406.2.12 raeburn 7775: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role',
7776: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'));
1.406.2.10 raeburn 7777: }
7778: }
7779: } elsif ($access eq 'exc') {
7780: my @domexc = ();
7781: if (ref($domcurrent->{$role}{'exc'}) eq 'ARRAY') {
7782: foreach my $user (@{$domcurrent->{$role}{'exc'}}) {
7783: my ($uname,$udom) = split(/:/,$user);
7784: push(@domexc,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),$uname,$udom));
7785: }
7786: }
7787: my $shownexc = join(', ',@domexc);
7788: if ($shownexc ne '') {
1.406.2.12 raeburn 7789: $domusage{$role} = &mt('Only the following in the domain with active [_1] or [_2] role: [_3]',
7790: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'),$shownexc);
1.406.2.10 raeburn 7791: } else {
7792: $domusage{$role} = &mt('No one in the domain');
7793: }
7794: } elsif ($access eq 'none') {
7795: $domusage{$role} = &mt('No one in the domain');
1.406.2.12 raeburn 7796: } elsif ($access eq 'dh') {
1.406.2.10 raeburn 7797: $domusage{$role} = &mt('Any user in domain with active [_1] role',&Apache::lonnet::plaintext('dh'));
1.406.2.12 raeburn 7798: } elsif ($access eq 'da') {
7799: $domusage{$role} = &mt('Any user in domain with active [_1] role',&Apache::lonnet::plaintext('da'));
7800: } elsif ($access eq 'all') {
7801: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role',
7802: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'));
1.406.2.10 raeburn 7803: }
7804: } else {
1.406.2.12 raeburn 7805: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role',
7806: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'));
1.406.2.10 raeburn 7807: }
7808: }
7809: return %domusage;
7810: }
7811:
7812: sub get_domain_customroles {
7813: my ($cdom,$confname) = @_;
7814: my %existing=&Apache::lonnet::dump('roles',$cdom,$confname,'rolesdef_');
7815: my %customroles;
7816: foreach my $key (keys(%existing)) {
7817: if ($key=~/^rolesdef\_(\w+)$/) {
7818: my $rolename = $1;
7819: my %privs;
7820: ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
7821: $customroles{$rolename} = \%privs;
7822: }
7823: }
7824: return %customroles;
7825: }
7826:
7827: sub role_priv_table {
7828: my ($role,$permission,$crstype,$full,$levels,$levelscurrent,$overridden) = @_;
7829: return unless ((ref($full) eq 'HASH') && (ref($levels) eq 'HASH') &&
7830: (ref($levelscurrent) eq 'HASH'));
7831: my %lt=&Apache::lonlocal::texthash (
7832: 'crl' => 'Course Level Privilege',
7833: 'def' => 'Domain Defaults',
7834: 'ove' => 'Override in Course',
7835: 'ine' => 'In effect',
7836: 'dis' => 'Disabled',
7837: 'ena' => 'Enabled',
7838: );
7839: if ($crstype eq 'Community') {
7840: $lt{'ove'} = 'Override in Community',
7841: }
7842: my @status = ('Disabled','Enabled');
7843: my (%on,%off);
7844: if (ref($overridden) eq 'HASH') {
7845: if (ref($overridden->{'on'}) eq 'ARRAY') {
7846: map { $on{$_} = 1; } (@{$overridden->{'on'}});
7847: }
7848: if (ref($overridden->{'off'}) eq 'ARRAY') {
7849: map { $off{$_} = 1; } (@{$overridden->{'off'}});
7850: }
7851: }
7852: my $output=&Apache::loncommon::start_data_table().
7853: &Apache::loncommon::start_data_table_header_row().
7854: '<th>'.$lt{'crl'}.'</th><th>'.$lt{'def'}.'</th><th>'.$lt{'ove'}.
7855: '</th><th>'.$lt{'ine'}.'</th>'.
7856: &Apache::loncommon::end_data_table_header_row();
7857: foreach my $priv (sort(keys(%{$full}))) {
7858: next unless ($levels->{'course'}{$priv});
7859: my $privtext = &Apache::lonnet::plaintext($priv,$crstype);
7860: my ($default,$ineffect);
7861: if ($levelscurrent->{'course'}{$priv}) {
7862: $default = '<img src="/adm/lonIcons/navmap.correct.gif" alt="'.$lt{'ena'}.'" />';
7863: $ineffect = $default;
7864: }
7865: my ($customstatus,$checked);
7866: $output .= &Apache::loncommon::start_data_table_row().
7867: '<td>'.$privtext.'</td>'.
7868: '<td>'.$default.'</td><td>';
7869: if (($levelscurrent->{'course'}{$priv}) && ($off{$priv})) {
7870: if ($permission->{'owner'}) {
7871: $checked = ' checked="checked"';
7872: }
7873: $customstatus = '<img src="/adm/lonIcons/navmap.wrong.gif" alt="'.$lt{'dis'}.'" />';
7874: $ineffect = $customstatus;
7875: } elsif ((!$levelscurrent->{'course'}{$priv}) && ($on{$priv})) {
7876: if ($permission->{'owner'}) {
7877: $checked = ' checked="checked"';
7878: }
7879: $customstatus = '<img src="/adm/lonIcons/navmap.correct.gif" alt="'.$lt{'ena'}.'" />';
7880: $ineffect = $customstatus;
7881: }
7882: if ($permission->{'owner'}) {
7883: $output .= '<input type="checkbox" name="'.$role.'_override" value="'.$priv.'"'.$checked.' />';
7884: } else {
7885: $output .= $customstatus;
7886: }
7887: $output .= '</td><td>'.$ineffect.'</td>'.
7888: &Apache::loncommon::end_data_table_row();
7889: }
7890: $output .= &Apache::loncommon::end_data_table();
7891: return $output;
7892: }
7893:
7894: sub get_adhocrole_settings {
7895: my ($cid,$accesstypes,$types,$customroles,$settings,$overridden) = @_;
7896: return unless ((ref($accesstypes) eq 'ARRAY') && (ref($customroles) eq 'HASH') &&
7897: (ref($settings) eq 'HASH') && (ref($overridden) eq 'HASH'));
7898: foreach my $role (split(/,/,$env{'course.'.$cid.'.internal.adhocaccess'})) {
7899: my ($curraccess,$rest) = split(/=/,$env{'course.'.$cid.'.internal.adhoc.'.$role});
7900: if (($curraccess ne '') && (grep(/^\Q$curraccess\E$/,@{$accesstypes}))) {
7901: $settings->{$role}{'access'} = $curraccess;
7902: if (($curraccess eq 'status') && (ref($types) eq 'ARRAY')) {
7903: my @status = split(/,/,$rest);
7904: my @currstatus;
7905: foreach my $type (@status) {
7906: if ($type eq 'default') {
7907: push(@currstatus,$type);
7908: } elsif (grep(/^\Q$type\E$/,@{$types})) {
7909: push(@currstatus,$type);
7910: }
7911: }
7912: if (@currstatus) {
7913: $settings->{$role}{$curraccess} = \@currstatus;
7914: } elsif (($curraccess eq 'exc') || ($curraccess eq 'inc')) {
7915: my @personnel = split(/,/,$rest);
7916: $settings->{$role}{$curraccess} = \@personnel;
7917: }
7918: }
7919: }
7920: }
7921: foreach my $role (keys(%{$customroles})) {
7922: if ($env{'course.'.$cid.'.internal.adhocpriv.'.$role}) {
7923: my %currentprivs;
7924: if (ref($customroles->{$role}) eq 'HASH') {
7925: if (exists($customroles->{$role}{'course'})) {
7926: my %full=();
7927: my %levels= (
7928: course => {},
7929: domain => {},
7930: system => {},
7931: );
7932: my %levelscurrent=(
7933: course => {},
7934: domain => {},
7935: system => {},
7936: );
7937: &Apache::lonuserutils::custom_role_privs($customroles->{$role},\%full,\%levels,\%levelscurrent);
7938: %currentprivs = %{$levelscurrent{'course'}};
7939: }
7940: }
7941: foreach my $item (split(/,/,$env{'course.'.$cid.'.internal.adhocpriv.'.$role})) {
7942: next if ($item eq '');
7943: my ($rule,$rest) = split(/=/,$item);
7944: next unless (($rule eq 'off') || ($rule eq 'on'));
7945: foreach my $priv (split(/:/,$rest)) {
7946: if ($priv ne '') {
7947: if ($rule eq 'off') {
7948: push(@{$overridden->{$role}{'off'}},$priv);
7949: if ($currentprivs{$priv}) {
7950: push(@{$settings->{$role}{'off'}},$priv);
7951: }
7952: } else {
7953: push(@{$overridden->{$role}{'on'}},$priv);
7954: unless ($currentprivs{$priv}) {
7955: push(@{$settings->{$role}{'on'}},$priv);
7956: }
7957: }
7958: }
7959: }
7960: }
7961: }
7962: }
7963: return;
7964: }
7965:
7966: sub update_helpdeskaccess {
7967: my ($r,$permission,$brcrum) = @_;
7968: my $helpitem = 'Course_Helpdesk_Access';
7969: push (@{$brcrum},
7970: {href => '/adm/createuser?action=helpdesk',
7971: text => 'Helpdesk Access',
7972: help => $helpitem},
7973: {href => '/adm/createuser?action=helpdesk',
7974: text => 'Result',
7975: help => $helpitem}
7976: );
7977: my $bread_crumbs_component = 'Helpdesk Staff Access';
7978: my $args = { bread_crumbs => $brcrum,
7979: bread_crumbs_component => $bread_crumbs_component};
7980:
7981: # print page header
7982: $r->print(&header('',$args));
7983: unless ((ref($permission) eq 'HASH') && ($permission->{'owner'})) {
7984: $r->print('<p class="LC_error">'.&mt('You do not have permission to change helpdesk access.').'</p>');
7985: return;
7986: }
1.406.2.12 raeburn 7987: my @accesstypes = ('all','dh','da','none','status','inc','exc');
1.406.2.10 raeburn 7988: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
7989: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
7990: my $confname = $cdom.'-domainconfig';
7991: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($cdom);
7992: my $crstype = &Apache::loncommon::course_type();
7993: my %customroles = &get_domain_customroles($cdom,$confname);
7994: my (%settings,%overridden);
7995: &get_adhocrole_settings($env{'request.course.id'},\@accesstypes,
7996: $types,\%customroles,\%settings,\%overridden);
1.406.2.12 raeburn 7997: my %domhelpdesk = &Apache::lonnet::get_active_domroles($cdom,['dh','da']);
1.406.2.10 raeburn 7998: my (%changed,%storehash,@todelete);
7999:
8000: if (keys(%customroles)) {
8001: my (%newsettings,@incrs);
8002: foreach my $role (keys(%customroles)) {
8003: $newsettings{$role} = {
8004: access => '',
8005: status => '',
8006: exc => '',
8007: inc => '',
8008: on => '',
8009: off => '',
8010: };
8011: my %current;
8012: if (ref($settings{$role}) eq 'HASH') {
8013: %current = %{$settings{$role}};
8014: }
8015: if (ref($overridden{$role}) eq 'HASH') {
8016: $current{'overridden'} = $overridden{$role};
8017: }
8018: if ($env{'form.'.$role.'_incrs'}) {
8019: my $access = $env{'form.'.$role.'_access'};
8020: if (grep(/^\Q$access\E$/,@accesstypes)) {
8021: push(@incrs,$role);
8022: unless ($current{'access'} eq $access) {
8023: $changed{$role}{'access'} = 1;
8024: $storehash{'internal.adhoc.'.$role} = $access;
8025: }
8026: if ($access eq 'status') {
8027: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$role.'_status');
8028: my @stored;
8029: my @shownstatus;
8030: if (ref($types) eq 'ARRAY') {
8031: foreach my $type (sort(@statuses)) {
8032: if ($type eq 'default') {
8033: push(@stored,$type);
8034: } elsif (grep(/^\Q$type\E$/,@{$types})) {
8035: push(@stored,$type);
8036: push(@shownstatus,$usertypes->{$type});
8037: }
8038: }
8039: if (grep(/^default$/,@statuses)) {
8040: push(@shownstatus,$othertitle);
8041: }
8042: $storehash{'internal.adhoc.'.$role} .= '='.join(',',@stored);
8043: }
8044: $newsettings{$role}{'status'} = join(' '.&mt('or').' ',@shownstatus);
8045: if (ref($current{'status'}) eq 'ARRAY') {
8046: my @diffs = &Apache::loncommon::compare_arrays(\@stored,$current{'status'});
8047: if (@diffs) {
8048: $changed{$role}{'status'} = 1;
8049: }
8050: } elsif (@stored) {
8051: $changed{$role}{'status'} = 1;
8052: }
8053: } elsif (($access eq 'inc') || ($access eq 'exc')) {
8054: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$role.'_staff_'.$access);
8055: my @newspecstaff;
8056: my @stored;
8057: my @currstaff;
8058: foreach my $person (sort(@personnel)) {
8059: if ($domhelpdesk{$person}) {
8060: push(@stored,$person);
8061: }
8062: }
8063: if (ref($current{$access}) eq 'ARRAY') {
8064: my @diffs = &Apache::loncommon::compare_arrays(\@stored,$current{$access});
8065: if (@diffs) {
8066: $changed{$role}{$access} = 1;
8067: }
8068: } elsif (@stored) {
8069: $changed{$role}{$access} = 1;
8070: }
8071: $storehash{'internal.adhoc.'.$role} .= '='.join(',',@stored);
8072: foreach my $person (@stored) {
8073: my ($uname,$udom) = split(/:/,$person);
8074: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
8075: }
8076: $newsettings{$role}{$access} = join(', ',sort(@newspecstaff));
8077: }
8078: $newsettings{$role}{'access'} = $access;
8079: }
8080: } else {
8081: if (($current{'access'} ne '') && (grep(/^\Q$current{'access'}\E$/,@accesstypes))) {
8082: $changed{$role}{'access'} = 1;
8083: $newsettings{$role} = {};
8084: push(@todelete,'internal.adhoc.'.$role);
8085: }
8086: }
8087: if (($env{'form.'.$role.'_incrs'}) && ($env{'form.'.$role.'_access'} eq 'none')) {
8088: if (ref($current{'overridden'}) eq 'HASH') {
8089: push(@todelete,'internal.adhocpriv.'.$role);
8090: }
8091: } else {
8092: my %full=();
8093: my %levels= (
8094: course => {},
8095: domain => {},
8096: system => {},
8097: );
8098: my %levelscurrent=(
8099: course => {},
8100: domain => {},
8101: system => {},
8102: );
8103: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
8104: my (@updatedon,@updatedoff,@override);
8105: @override = &Apache::loncommon::get_env_multiple('form.'.$role.'_override');
8106: if (@override) {
8107: foreach my $priv (sort(keys(%full))) {
8108: next unless ($levels{'course'}{$priv});
8109: if (grep(/^\Q$priv\E$/,@override)) {
8110: if ($levelscurrent{'course'}{$priv}) {
8111: push(@updatedoff,$priv);
8112: } else {
8113: push(@updatedon,$priv);
8114: }
8115: }
8116: }
8117: }
8118: if (@updatedon) {
8119: $newsettings{$role}{'on'} = join('</li><li>', map { &Apache::lonnet::plaintext($_,$crstype) } (@updatedon));
8120: }
8121: if (@updatedoff) {
8122: $newsettings{$role}{'off'} = join('</li><li>', map { &Apache::lonnet::plaintext($_,$crstype) } (@updatedoff));
8123: }
8124: if (ref($current{'overridden'}) eq 'HASH') {
8125: if (ref($current{'overridden'}{'on'}) eq 'ARRAY') {
8126: if (@updatedon) {
8127: my @diffs = &Apache::loncommon::compare_arrays(\@updatedon,$current{'overridden'}{'on'});
8128: if (@diffs) {
8129: $changed{$role}{'on'} = 1;
8130: }
8131: } else {
8132: $changed{$role}{'on'} = 1;
8133: }
8134: } elsif (@updatedon) {
8135: $changed{$role}{'on'} = 1;
8136: }
8137: if (ref($current{'overridden'}{'off'}) eq 'ARRAY') {
8138: if (@updatedoff) {
8139: my @diffs = &Apache::loncommon::compare_arrays(\@updatedoff,$current{'overridden'}{'off'});
8140: if (@diffs) {
8141: $changed{$role}{'off'} = 1;
8142: }
8143: } else {
8144: $changed{$role}{'off'} = 1;
8145: }
8146: } elsif (@updatedoff) {
8147: $changed{$role}{'off'} = 1;
8148: }
8149: } else {
8150: if (@updatedon) {
8151: $changed{$role}{'on'} = 1;
8152: }
8153: if (@updatedoff) {
8154: $changed{$role}{'off'} = 1;
8155: }
8156: }
8157: if (ref($changed{$role}) eq 'HASH') {
8158: if (($changed{$role}{'on'} || $changed{$role}{'off'})) {
8159: my $newpriv;
8160: if (@updatedon) {
8161: $newpriv = 'on='.join(':',@updatedon);
8162: }
8163: if (@updatedoff) {
8164: $newpriv .= ($newpriv ? ',' : '' ).'off='.join(':',@updatedoff);
8165: }
8166: if ($newpriv eq '') {
8167: push(@todelete,'internal.adhocpriv.'.$role);
8168: } else {
8169: $storehash{'internal.adhocpriv.'.$role} = $newpriv;
8170: }
8171: }
8172: }
8173: }
8174: }
8175: if (@incrs) {
8176: $storehash{'internal.adhocaccess'} = join(',',@incrs);
8177: } elsif (@todelete) {
8178: push(@todelete,'internal.adhocaccess');
8179: }
8180: if (keys(%changed)) {
8181: my ($putres,$delres);
8182: if (keys(%storehash)) {
8183: $putres = &Apache::lonnet::put('environment',\%storehash,$cdom,$cnum);
8184: my %newenvhash;
8185: foreach my $key (keys(%storehash)) {
8186: $newenvhash{'course.'.$env{'request.course.id'}.'.'.$key} = $storehash{$key};
8187: }
8188: &Apache::lonnet::appenv(\%newenvhash);
8189: }
8190: if (@todelete) {
8191: $delres = &Apache::lonnet::del('environment',\@todelete,$cdom,$cnum);
8192: foreach my $key (@todelete) {
8193: &Apache::lonnet::delenv('course.'.$env{'request.course.id'}.'.'.$key);
8194: }
8195: }
8196: if (($putres eq 'ok') || ($delres eq 'ok')) {
8197: my %domconfig = &Apache::lonnet::get_dom('configuration',['helpsettings'],$cdom);
8198: my (%domcurrent,%ordered,%description,%domusage);
8199: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
8200: if (ref($domconfig{'helpsettings'}{'adhoc'}) eq 'HASH') {
8201: %domcurrent = %{$domconfig{'helpsettings'}{'adhoc'}};
8202: }
8203: }
8204: my $count = 0;
8205: foreach my $role (sort(keys(%customroles))) {
8206: my ($order,$desc);
8207: if (ref($domcurrent{$role}) eq 'HASH') {
8208: $order = $domcurrent{$role}{'order'};
8209: $desc = $domcurrent{$role}{'desc'};
8210: }
8211: if ($order eq '') {
8212: $order = $count;
8213: }
8214: $ordered{$order} = $role;
8215: if ($desc ne '') {
8216: $description{$role} = $desc;
8217: } else {
8218: $description{$role}= $role;
8219: }
8220: $count++;
8221: }
8222: my @roles_by_num = ();
8223: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
8224: push(@roles_by_num,$ordered{$item});
8225: }
8226: %domusage = &domain_adhoc_access(\%changed,\%domcurrent,\@accesstypes,$usertypes,$othertitle);
8227: $r->print(&mt('Helpdesk access settings have been changed as follows').'<br />');
8228: $r->print('<ul>');
8229: foreach my $role (@roles_by_num) {
8230: next unless (ref($changed{$role}) eq 'HASH');
8231: $r->print('<li>'.&mt('Ad hoc role').': <b>'.$description{$role}.'</b>'.
8232: '<ul>');
8233: if ($changed{$role}{'access'} || $changed{$role}{'status'} || $changed{$role}{'inc'} || $changed{$role}{'exc'}) {
8234: $r->print('<li>');
8235: if ($env{'form.'.$role.'_incrs'}) {
8236: if ($newsettings{$role}{'access'} eq 'all') {
8237: $r->print(&mt('All helpdesk staff can access '.lc($crstype).' with this role.'));
1.406.2.12 raeburn 8238: } elsif ($newsettings{$role}{'access'} eq 'dh') {
8239: $r->print(&mt('Helpdesk staff can use this role if they have an active [_1] role',
8240: &Apache::lonnet::plaintext('dh')));
8241: } elsif ($newsettings{$role}{'access'} eq 'da') {
8242: $r->print(&mt('Helpdesk staff can use this role if they have an active [_1] role',
8243: &Apache::lonnet::plaintext('da')));
1.406.2.10 raeburn 8244: } elsif ($newsettings{$role}{'access'} eq 'none') {
8245: $r->print(&mt('No helpdesk staff can access '.lc($crstype).' with this role.'));
8246: } elsif ($newsettings{$role}{'access'} eq 'status') {
8247: if ($newsettings{$role}{'status'}) {
8248: my ($access,$rest) = split(/=/,$storehash{'internal.adhoc.'.$role});
8249: if (split(/,/,$rest) > 1) {
8250: $r->print(&mt('Helpdesk staff can use this role if their institutional type is one of: [_1].',
8251: $newsettings{$role}{'status'}));
8252: } else {
8253: $r->print(&mt('Helpdesk staff can use this role if their institutional type is: [_1].',
8254: $newsettings{$role}{'status'}));
8255: }
8256: } else {
8257: $r->print(&mt('No helpdesk staff can access '.lc($crstype).' with this role.'));
8258: }
8259: } elsif ($newsettings{$role}{'access'} eq 'exc') {
8260: if ($newsettings{$role}{'exc'}) {
8261: $r->print(&mt('Helpdesk staff who can use this role are as follows:').' '.$newsettings{$role}{'exc'}.'.');
8262: } else {
8263: $r->print(&mt('No helpdesk staff can access '.lc($crstype).' with this role.'));
8264: }
8265: } elsif ($newsettings{$role}{'access'} eq 'inc') {
8266: if ($newsettings{$role}{'inc'}) {
8267: $r->print(&mt('All helpdesk staff may use this role except the following:').' '.$newsettings{$role}{'inc'}.'.');
8268: } else {
8269: $r->print(&mt('All helpdesk staff may use this role.'));
8270: }
8271: }
8272: } else {
8273: $r->print(&mt('Default access set in the domain now applies.').'<br />'.
8274: '<span class="LC_cusr_emph">'.$domusage{$role}.'</span>');
8275: }
8276: $r->print('</li>');
8277: }
8278: unless ($newsettings{$role}{'access'} eq 'none') {
8279: if ($changed{$role}{'off'}) {
8280: if ($newsettings{$role}{'off'}) {
8281: $r->print('<li>'.&mt('Privileges which are available by default for this ad hoc role, but are disabled for this specific '.lc($crstype).':').
8282: '<ul><li>'.$newsettings{$role}{'off'}.'</li></ul></li>');
8283: } else {
8284: $r->print('<li>'.&mt('All privileges available by default for this ad hoc role are enabled.').'</li>');
8285: }
8286: }
8287: if ($changed{$role}{'on'}) {
8288: if ($newsettings{$role}{'on'}) {
8289: $r->print('<li>'.&mt('Privileges which are not available by default for this ad hoc role, but are enabled for this specific '.lc($crstype).':').
8290: '<ul><li>'.$newsettings{$role}{'on'}.'</li></ul></li>');
8291: } else {
8292: $r->print('<li>'.&mt('None of the privileges unavailable by default for this ad hoc role are enabled.').'</li>');
8293: }
8294: }
8295: }
8296: $r->print('</ul></li>');
8297: }
8298: $r->print('</ul>');
8299: }
8300: } else {
8301: $r->print(&mt('No changes made to helpdesk access settings.'));
8302: }
8303: }
8304: return;
8305: }
8306:
1.27 matthew 8307: #-------------------------------------------------- functions for &phase_two
1.160 raeburn 8308: sub user_search_result {
1.221 raeburn 8309: my ($context,$srch) = @_;
1.160 raeburn 8310: my %allhomes;
8311: my %inst_matches;
8312: my %srch_results;
1.181 raeburn 8313: my ($response,$currstate,$forcenewuser,$dirsrchres);
1.183 raeburn 8314: $srch->{'srchterm'} =~ s/\s+/ /g;
1.176 raeburn 8315: if ($srch->{'srchby'} !~ /^(uname|lastname|lastfirst)$/) {
1.160 raeburn 8316: $response = &mt('Invalid search.');
8317: }
8318: if ($srch->{'srchin'} !~ /^(crs|dom|alc|instd)$/) {
8319: $response = &mt('Invalid search.');
8320: }
1.177 raeburn 8321: if ($srch->{'srchtype'} !~ /^(exact|contains|begins)$/) {
1.160 raeburn 8322: $response = &mt('Invalid search.');
8323: }
8324: if ($srch->{'srchterm'} eq '') {
8325: $response = &mt('You must enter a search term.');
8326: }
1.183 raeburn 8327: if ($srch->{'srchterm'} =~ /^\s+$/) {
8328: $response = &mt('Your search term must contain more than just spaces.');
8329: }
1.160 raeburn 8330: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'instd')) {
8331: if (($srch->{'srchdomain'} eq '') ||
1.163 albertel 8332: ! (&Apache::lonnet::domain($srch->{'srchdomain'}))) {
1.160 raeburn 8333: $response = &mt('You must specify a valid domain when searching in a domain or institutional directory.')
8334: }
8335: }
8336: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs') ||
8337: ($srch->{'srchin'} eq 'alc')) {
1.176 raeburn 8338: if ($srch->{'srchby'} eq 'uname') {
1.243 raeburn 8339: my $unamecheck = $srch->{'srchterm'};
8340: if ($srch->{'srchtype'} eq 'contains') {
8341: if ($unamecheck !~ /^\w/) {
8342: $unamecheck = 'a'.$unamecheck;
8343: }
8344: }
8345: if ($unamecheck !~ /^$match_username$/) {
1.176 raeburn 8346: $response = &mt('You must specify a valid username. Only the following are allowed: letters numbers - . @');
8347: }
1.160 raeburn 8348: }
8349: }
1.180 raeburn 8350: if ($response ne '') {
1.406.2.4 raeburn 8351: $response = '<span class="LC_warning">'.$response.'</span><br />';
1.180 raeburn 8352: }
1.160 raeburn 8353: if ($srch->{'srchin'} eq 'instd') {
1.406.2.3 raeburn 8354: my $instd_chk = &instdirectorysrch_check($srch);
1.160 raeburn 8355: if ($instd_chk ne 'ok') {
1.406.2.3 raeburn 8356: my $domd_chk = &domdirectorysrch_check($srch);
1.406.2.4 raeburn 8357: $response .= '<span class="LC_warning">'.$instd_chk.'</span><br />';
1.406.2.3 raeburn 8358: if ($domd_chk eq 'ok') {
1.406.2.4 raeburn 8359: $response .= &mt('You may want to search in the LON-CAPA domain instead of the institutional directory.');
1.406.2.3 raeburn 8360: }
1.406.2.5 raeburn 8361: $response .= '<br />';
1.406.2.3 raeburn 8362: }
8363: } else {
8364: unless (($context eq 'requestcrs') && ($srch->{'srchtype'} eq 'exact')) {
8365: my $domd_chk = &domdirectorysrch_check($srch);
1.406.2.14! raeburn 8366: if (($domd_chk ne 'ok') && ($env{'form.action'} ne 'accesslogs')) {
1.406.2.3 raeburn 8367: my $instd_chk = &instdirectorysrch_check($srch);
1.406.2.4 raeburn 8368: $response .= '<span class="LC_warning">'.$domd_chk.'</span><br />';
1.406.2.3 raeburn 8369: if ($instd_chk eq 'ok') {
1.406.2.4 raeburn 8370: $response .= &mt('You may want to search in the institutional directory instead of the LON-CAPA domain.');
1.406.2.3 raeburn 8371: }
1.406.2.5 raeburn 8372: $response .= '<br />';
1.406.2.3 raeburn 8373: }
1.160 raeburn 8374: }
8375: }
8376: if ($response ne '') {
1.180 raeburn 8377: return ($currstate,$response);
1.160 raeburn 8378: }
8379: if ($srch->{'srchby'} eq 'uname') {
8380: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs')) {
8381: if ($env{'form.forcenew'}) {
8382: if ($srch->{'srchdomain'} ne $env{'request.role.domain'}) {
8383: my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
8384: if ($uhome eq 'no_host') {
8385: my $domdesc = &Apache::lonnet::domain($env{'request.role.domain'},'description');
1.180 raeburn 8386: my $showdom = &display_domain_info($env{'request.role.domain'});
8387: $response = &mt('New users can only be created in the domain to which your current role belongs - [_1].',$showdom);
1.160 raeburn 8388: } else {
1.179 raeburn 8389: $currstate = 'modify';
1.160 raeburn 8390: }
8391: } else {
1.179 raeburn 8392: $currstate = 'modify';
1.160 raeburn 8393: }
8394: } else {
8395: if ($srch->{'srchin'} eq 'dom') {
1.162 raeburn 8396: if ($srch->{'srchtype'} eq 'exact') {
8397: my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
8398: if ($uhome eq 'no_host') {
1.179 raeburn 8399: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8400: &build_search_response($context,$srch,%srch_results);
1.162 raeburn 8401: } else {
1.179 raeburn 8402: $currstate = 'modify';
1.406.2.5 raeburn 8403: if ($env{'form.action'} eq 'accesslogs') {
8404: $currstate = 'activity';
8405: }
1.310 raeburn 8406: my $uname = $srch->{'srchterm'};
8407: my $udom = $srch->{'srchdomain'};
8408: $srch_results{$uname.':'.$udom} =
8409: { &Apache::lonnet::get('environment',
8410: ['firstname',
8411: 'lastname',
8412: 'permanentemail'],
8413: $udom,$uname)
8414: };
1.162 raeburn 8415: }
8416: } else {
8417: %srch_results = &Apache::lonnet::usersearch($srch);
1.179 raeburn 8418: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8419: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 8420: }
8421: } else {
1.167 albertel 8422: my $courseusers = &get_courseusers();
1.162 raeburn 8423: if ($srch->{'srchtype'} eq 'exact') {
1.167 albertel 8424: if (exists($courseusers->{$srch->{'srchterm'}.':'.$srch->{'srchdomain'}})) {
1.179 raeburn 8425: $currstate = 'modify';
1.162 raeburn 8426: } else {
1.179 raeburn 8427: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8428: &build_search_response($context,$srch,%srch_results);
1.162 raeburn 8429: }
1.160 raeburn 8430: } else {
1.167 albertel 8431: foreach my $user (keys(%$courseusers)) {
1.162 raeburn 8432: my ($cuname,$cudomain) = split(/:/,$user);
8433: if ($cudomain eq $srch->{'srchdomain'}) {
1.177 raeburn 8434: my $matched = 0;
8435: if ($srch->{'srchtype'} eq 'begins') {
8436: if ($cuname =~ /^\Q$srch->{'srchterm'}\E/i) {
8437: $matched = 1;
8438: }
8439: } else {
8440: if ($cuname =~ /\Q$srch->{'srchterm'}\E/i) {
8441: $matched = 1;
8442: }
8443: }
8444: if ($matched) {
1.167 albertel 8445: $srch_results{$user} =
8446: {&Apache::lonnet::get('environment',
8447: ['firstname',
8448: 'lastname',
1.194 albertel 8449: 'permanentemail'],
8450: $cudomain,$cuname)};
1.162 raeburn 8451: }
8452: }
8453: }
1.179 raeburn 8454: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8455: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 8456: }
8457: }
8458: }
8459: } elsif ($srch->{'srchin'} eq 'alc') {
1.179 raeburn 8460: $currstate = 'query';
1.160 raeburn 8461: } elsif ($srch->{'srchin'} eq 'instd') {
1.181 raeburn 8462: ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
8463: if ($dirsrchres eq 'ok') {
8464: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8465: &build_search_response($context,$srch,%srch_results);
1.181 raeburn 8466: } else {
8467: my $showdom = &display_domain_info($srch->{'srchdomain'});
8468: $response = '<span class="LC_warning">'.
8469: &mt('Institutional directory search is not available in domain: [_1]',$showdom).
8470: '</span><br />'.
8471: &mt('You may want to search in the LON-CAPA domain instead of the institutional directory.').
1.406.2.5 raeburn 8472: '<br />';
1.181 raeburn 8473: }
1.160 raeburn 8474: }
8475: } else {
8476: if ($srch->{'srchin'} eq 'dom') {
8477: %srch_results = &Apache::lonnet::usersearch($srch);
1.179 raeburn 8478: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8479: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 8480: } elsif ($srch->{'srchin'} eq 'crs') {
1.167 albertel 8481: my $courseusers = &get_courseusers();
8482: foreach my $user (keys(%$courseusers)) {
1.160 raeburn 8483: my ($uname,$udom) = split(/:/,$user);
8484: my %names = &Apache::loncommon::getnames($uname,$udom);
8485: my %emails = &Apache::loncommon::getemails($uname,$udom);
8486: if ($srch->{'srchby'} eq 'lastname') {
8487: if ((($srch->{'srchtype'} eq 'exact') &&
8488: ($names{'lastname'} eq $srch->{'srchterm'})) ||
1.177 raeburn 8489: (($srch->{'srchtype'} eq 'begins') &&
8490: ($names{'lastname'} =~ /^\Q$srch->{'srchterm'}\E/i)) ||
1.160 raeburn 8491: (($srch->{'srchtype'} eq 'contains') &&
8492: ($names{'lastname'} =~ /\Q$srch->{'srchterm'}\E/i))) {
8493: $srch_results{$user} = {firstname => $names{'firstname'},
8494: lastname => $names{'lastname'},
8495: permanentemail => $emails{'permanentemail'},
8496: };
8497: }
8498: } elsif ($srch->{'srchby'} eq 'lastfirst') {
8499: my ($srchlast,$srchfirst) = split(/,/,$srch->{'srchterm'});
1.177 raeburn 8500: $srchlast =~ s/\s+$//;
8501: $srchfirst =~ s/^\s+//;
1.160 raeburn 8502: if ($srch->{'srchtype'} eq 'exact') {
8503: if (($names{'lastname'} eq $srchlast) &&
8504: ($names{'firstname'} eq $srchfirst)) {
8505: $srch_results{$user} = {firstname => $names{'firstname'},
8506: lastname => $names{'lastname'},
8507: permanentemail => $emails{'permanentemail'},
8508:
8509: };
8510: }
1.177 raeburn 8511: } elsif ($srch->{'srchtype'} eq 'begins') {
8512: if (($names{'lastname'} =~ /^\Q$srchlast\E/i) &&
8513: ($names{'firstname'} =~ /^\Q$srchfirst\E/i)) {
8514: $srch_results{$user} = {firstname => $names{'firstname'},
8515: lastname => $names{'lastname'},
8516: permanentemail => $emails{'permanentemail'},
8517: };
8518: }
8519: } else {
1.160 raeburn 8520: if (($names{'lastname'} =~ /\Q$srchlast\E/i) &&
8521: ($names{'firstname'} =~ /\Q$srchfirst\E/i)) {
8522: $srch_results{$user} = {firstname => $names{'firstname'},
8523: lastname => $names{'lastname'},
8524: permanentemail => $emails{'permanentemail'},
8525: };
8526: }
8527: }
8528: }
8529: }
1.179 raeburn 8530: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8531: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 8532: } elsif ($srch->{'srchin'} eq 'alc') {
1.179 raeburn 8533: $currstate = 'query';
1.160 raeburn 8534: } elsif ($srch->{'srchin'} eq 'instd') {
1.181 raeburn 8535: ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
8536: if ($dirsrchres eq 'ok') {
8537: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8538: &build_search_response($context,$srch,%srch_results);
1.181 raeburn 8539: } else {
1.406.2.5 raeburn 8540: my $showdom = &display_domain_info($srch->{'srchdomain'});
8541: $response = '<span class="LC_warning">'.
1.181 raeburn 8542: &mt('Institutional directory search is not available in domain: [_1]',$showdom).
8543: '</span><br />'.
8544: &mt('You may want to search in the LON-CAPA domain instead of the institutional directory.').
1.406.2.5 raeburn 8545: '<br />';
1.181 raeburn 8546: }
1.160 raeburn 8547: }
8548: }
1.179 raeburn 8549: return ($currstate,$response,$forcenewuser,\%srch_results);
1.160 raeburn 8550: }
8551:
1.406.2.3 raeburn 8552: sub domdirectorysrch_check {
8553: my ($srch) = @_;
8554: my $response;
8555: my %dom_inst_srch = &Apache::lonnet::get_dom('configuration',
8556: ['directorysrch'],$srch->{'srchdomain'});
8557: my $showdom = &display_domain_info($srch->{'srchdomain'});
8558: if (ref($dom_inst_srch{'directorysrch'}) eq 'HASH') {
8559: if ($dom_inst_srch{'directorysrch'}{'lcavailable'} eq '0') {
8560: return &mt('LON-CAPA directory search is not available in domain: [_1]',$showdom);
8561: }
8562: if ($dom_inst_srch{'directorysrch'}{'lclocalonly'}) {
8563: if ($env{'request.role.domain'} ne $srch->{'srchdomain'}) {
8564: return &mt('LON-CAPA directory search in domain: [_1] is only allowed for users with a current role in the domain.',$showdom);
8565: }
8566: }
8567: }
8568: return 'ok';
8569: }
8570:
8571: sub instdirectorysrch_check {
1.160 raeburn 8572: my ($srch) = @_;
8573: my $can_search = 0;
8574: my $response;
8575: my %dom_inst_srch = &Apache::lonnet::get_dom('configuration',
8576: ['directorysrch'],$srch->{'srchdomain'});
1.180 raeburn 8577: my $showdom = &display_domain_info($srch->{'srchdomain'});
1.160 raeburn 8578: if (ref($dom_inst_srch{'directorysrch'}) eq 'HASH') {
8579: if (!$dom_inst_srch{'directorysrch'}{'available'}) {
1.180 raeburn 8580: return &mt('Institutional directory search is not available in domain: [_1]',$showdom);
1.160 raeburn 8581: }
8582: if ($dom_inst_srch{'directorysrch'}{'localonly'}) {
8583: if ($env{'request.role.domain'} ne $srch->{'srchdomain'}) {
1.180 raeburn 8584: return &mt('Institutional directory search in domain: [_1] is only allowed for users with a current role in the domain.',$showdom);
1.160 raeburn 8585: }
8586: my @usertypes = split(/:/,$env{'environment.inststatus'});
8587: if (!@usertypes) {
8588: push(@usertypes,'default');
8589: }
8590: if (ref($dom_inst_srch{'directorysrch'}{'cansearch'}) eq 'ARRAY') {
8591: foreach my $type (@usertypes) {
8592: if (grep(/^\Q$type\E$/,@{$dom_inst_srch{'directorysrch'}{'cansearch'}})) {
8593: $can_search = 1;
8594: last;
8595: }
8596: }
8597: }
8598: if (!$can_search) {
8599: my ($insttypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($srch->{'srchdomain'});
8600: my @longtypes;
8601: foreach my $item (@usertypes) {
1.229 raeburn 8602: if (defined($insttypes->{$item})) {
8603: push (@longtypes,$insttypes->{$item});
8604: } elsif ($item eq 'default') {
8605: push (@longtypes,&mt('other'));
8606: }
1.160 raeburn 8607: }
8608: my $insttype_str = join(', ',@longtypes);
1.180 raeburn 8609: return &mt('Institutional directory search in domain: [_1] is not available to your user type: ',$showdom).$insttype_str;
1.229 raeburn 8610: }
1.160 raeburn 8611: } else {
8612: $can_search = 1;
8613: }
8614: } else {
1.180 raeburn 8615: return &mt('Institutional directory search has not been configured for domain: [_1]',$showdom);
1.160 raeburn 8616: }
8617: my %longtext = &Apache::lonlocal::texthash (
1.167 albertel 8618: uname => 'username',
1.160 raeburn 8619: lastfirst => 'last name, first name',
1.167 albertel 8620: lastname => 'last name',
1.172 raeburn 8621: contains => 'contains',
1.178 raeburn 8622: exact => 'as exact match to',
8623: begins => 'begins with',
1.160 raeburn 8624: );
8625: if ($can_search) {
8626: if (ref($dom_inst_srch{'directorysrch'}{'searchby'}) eq 'ARRAY') {
8627: if (!grep(/^\Q$srch->{'srchby'}\E$/,@{$dom_inst_srch{'directorysrch'}{'searchby'}})) {
1.180 raeburn 8628: return &mt('Institutional directory search in domain: [_1] is not available for searching by "[_2]"',$showdom,$longtext{$srch->{'srchby'}});
1.160 raeburn 8629: }
8630: } else {
1.180 raeburn 8631: return &mt('Institutional directory search in domain: [_1] is not available.', $showdom);
1.160 raeburn 8632: }
8633: }
8634: if ($can_search) {
1.178 raeburn 8635: if (ref($dom_inst_srch{'directorysrch'}{'searchtypes'}) eq 'ARRAY') {
8636: if (grep(/^\Q$srch->{'srchtype'}\E/,@{$dom_inst_srch{'directorysrch'}{'searchtypes'}})) {
8637: return 'ok';
8638: } else {
1.180 raeburn 8639: return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
1.178 raeburn 8640: }
8641: } else {
8642: if ((($dom_inst_srch{'directorysrch'}{'searchtypes'} eq 'specify') &&
8643: ($srch->{'srchtype'} eq 'exact' || $srch->{'srchtype'} eq 'contains')) ||
8644: ($dom_inst_srch{'directorysrch'}{'searchtypes'} eq $srch->{'srchtype'})) {
8645: return 'ok';
8646: } else {
1.180 raeburn 8647: return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
1.178 raeburn 8648: }
1.160 raeburn 8649: }
8650: }
8651: }
8652:
8653: sub get_courseusers {
8654: my %advhash;
1.167 albertel 8655: my $classlist = &Apache::loncoursedata::get_classlist();
1.160 raeburn 8656: my %coursepersonnel=&Apache::lonnet::get_course_adv_roles();
8657: foreach my $role (sort(keys(%coursepersonnel))) {
8658: foreach my $user (split(/\,/,$coursepersonnel{$role})) {
1.167 albertel 8659: if (!exists($classlist->{$user})) {
8660: $classlist->{$user} = [];
8661: }
1.160 raeburn 8662: }
8663: }
1.167 albertel 8664: return $classlist;
1.160 raeburn 8665: }
8666:
8667: sub build_search_response {
1.221 raeburn 8668: my ($context,$srch,%srch_results) = @_;
1.179 raeburn 8669: my ($currstate,$response,$forcenewuser);
1.160 raeburn 8670: my %names = (
1.330 bisitz 8671: 'uname' => 'username',
8672: 'lastname' => 'last name',
1.160 raeburn 8673: 'lastfirst' => 'last name, first name',
1.330 bisitz 8674: 'crs' => 'this course',
8675: 'dom' => 'LON-CAPA domain',
8676: 'instd' => 'the institutional directory for domain',
1.160 raeburn 8677: );
8678:
8679: my %single = (
1.180 raeburn 8680: begins => 'A match',
1.160 raeburn 8681: contains => 'A match',
1.180 raeburn 8682: exact => 'An exact match',
1.160 raeburn 8683: );
8684: my %nomatch = (
1.180 raeburn 8685: begins => 'No match',
1.160 raeburn 8686: contains => 'No match',
1.180 raeburn 8687: exact => 'No exact match',
1.160 raeburn 8688: );
8689: if (keys(%srch_results) > 1) {
1.179 raeburn 8690: $currstate = 'select';
1.160 raeburn 8691: } else {
8692: if (keys(%srch_results) == 1) {
1.406.2.5 raeburn 8693: if ($env{'form.action'} eq 'accesslogs') {
8694: $currstate = 'activity';
8695: } else {
8696: $currstate = 'modify';
8697: }
1.180 raeburn 8698: $response = &mt("$single{$srch->{'srchtype'}} was found for the $names{$srch->{'srchby'}} ([_1]) in $names{$srch->{'srchin'}}.",$srch->{'srchterm'});
8699: if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
1.330 bisitz 8700: $response .= ': '.&display_domain_info($srch->{'srchdomain'});
1.180 raeburn 8701: }
1.330 bisitz 8702: } else { # Search has nothing found. Prepare message to user.
8703: $response = '<span class="LC_warning">';
1.180 raeburn 8704: if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
1.330 bisitz 8705: $response .= &mt("$nomatch{$srch->{'srchtype'}} found for the $names{$srch->{'srchby'}} [_1] in $names{$srch->{'srchin'}}: [_2]",
8706: '<b>'.$srch->{'srchterm'}.'</b>',
8707: &display_domain_info($srch->{'srchdomain'}));
8708: } else {
8709: $response .= &mt("$nomatch{$srch->{'srchtype'}} found for the $names{$srch->{'srchby'}} [_1] in $names{$srch->{'srchin'}}.",
8710: '<b>'.$srch->{'srchterm'}.'</b>');
1.180 raeburn 8711: }
8712: $response .= '</span>';
1.330 bisitz 8713:
1.160 raeburn 8714: if ($srch->{'srchin'} ne 'alc') {
8715: $forcenewuser = 1;
8716: my $cansrchinst = 0;
1.406.2.14! raeburn 8717: if (($srch->{'srchdomain'}) && ($env{'form.action'} ne 'accesslogs')) {
1.160 raeburn 8718: my %domconfig = &Apache::lonnet::get_dom('configuration',['directorysrch'],$srch->{'srchdomain'});
8719: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
8720: if ($domconfig{'directorysrch'}{'available'}) {
8721: $cansrchinst = 1;
8722: }
8723: }
8724: }
1.180 raeburn 8725: if ((($srch->{'srchby'} eq 'lastfirst') ||
8726: ($srch->{'srchby'} eq 'lastname')) &&
8727: ($srch->{'srchin'} eq 'dom')) {
8728: if ($cansrchinst) {
8729: $response .= '<br />'.&mt('You may want to broaden your search to a search of the institutional directory for the domain.');
1.160 raeburn 8730: }
8731: }
1.180 raeburn 8732: if ($srch->{'srchin'} eq 'crs') {
8733: $response .= '<br />'.&mt('You may want to broaden your search to the selected LON-CAPA domain.');
8734: }
8735: }
1.305 raeburn 8736: my $createdom = $env{'request.role.domain'};
8737: if ($context eq 'requestcrs') {
8738: if ($env{'form.coursedom'} ne '') {
8739: $createdom = $env{'form.coursedom'};
8740: }
8741: }
1.406.2.5 raeburn 8742: unless (($env{'form.action'} eq 'accesslogs') || (($srch->{'srchby'} eq 'uname') && ($srch->{'srchin'} eq 'dom') &&
8743: ($srch->{'srchtype'} eq 'exact') && ($srch->{'srchdomain'} eq $createdom))) {
1.221 raeburn 8744: my $cancreate =
1.305 raeburn 8745: &Apache::lonuserutils::can_create_user($createdom,$context);
8746: my $targetdom = '<span class="LC_cusr_emph">'.$createdom.'</span>';
1.221 raeburn 8747: if ($cancreate) {
1.305 raeburn 8748: my $showdom = &display_domain_info($createdom);
1.266 bisitz 8749: $response .= '<br /><br />'
8750: .'<b>'.&mt('To add a new user:').'</b>'
1.305 raeburn 8751: .'<br />';
8752: if ($context eq 'requestcrs') {
8753: $response .= &mt("(You can only define new users in the new course's domain - [_1])",$targetdom);
8754: } else {
8755: $response .= &mt("(You can only create new users in your current role's domain - [_1])",$targetdom);
8756: }
8757: $response .='<ul><li>'
1.266 bisitz 8758: .&mt("Set 'Domain/institution to search' to: [_1]",'<span class="LC_cusr_emph">'.$showdom.'</span>')
8759: .'</li><li>'
8760: .&mt("Set 'Search criteria' to: [_1]username is ..... in selected LON-CAPA domain[_2]",'<span class="LC_cusr_emph">','</span>')
8761: .'</li><li>'
8762: .&mt('Provide the proposed username')
8763: .'</li><li>'
8764: .&mt("Click 'Search'")
8765: .'</li></ul><br />';
1.221 raeburn 8766: } else {
1.406.2.7 raeburn 8767: unless (($context eq 'domain') && ($env{'form.action'} eq 'singleuser')) {
8768: my $helplink = ' href="javascript:helpMenu('."'display'".')"';
8769: $response .= '<br /><br />';
8770: if ($context eq 'requestcrs') {
8771: $response .= &mt("You are not authorized to define new users in the new course's domain - [_1].",$targetdom);
8772: } else {
8773: $response .= &mt("You are not authorized to create new users in your current role's domain - [_1].",$targetdom);
8774: }
8775: $response .= '<br />'
8776: .&mt('Please contact the [_1]helpdesk[_2] if you need to create a new user.'
8777: ,' <a'.$helplink.'>'
8778: ,'</a>')
8779: .'<br />';
1.305 raeburn 8780: }
1.221 raeburn 8781: }
1.160 raeburn 8782: }
8783: }
8784: }
1.179 raeburn 8785: return ($currstate,$response,$forcenewuser);
1.160 raeburn 8786: }
8787:
1.180 raeburn 8788: sub display_domain_info {
8789: my ($dom) = @_;
8790: my $output = $dom;
8791: if ($dom ne '') {
8792: my $domdesc = &Apache::lonnet::domain($dom,'description');
8793: if ($domdesc ne '') {
8794: $output .= ' <span class="LC_cusr_emph">('.$domdesc.')</span>';
8795: }
8796: }
8797: return $output;
8798: }
8799:
1.160 raeburn 8800: sub crumb_utilities {
8801: my %elements = (
8802: crtuser => {
8803: srchterm => 'text',
1.172 raeburn 8804: srchin => 'selectbox',
1.160 raeburn 8805: srchby => 'selectbox',
8806: srchtype => 'selectbox',
8807: srchdomain => 'selectbox',
8808: },
1.207 raeburn 8809: crtusername => {
8810: srchterm => 'text',
8811: srchdomain => 'selectbox',
8812: },
1.160 raeburn 8813: docustom => {
8814: rolename => 'selectbox',
8815: newrolename => 'textbox',
8816: },
1.179 raeburn 8817: studentform => {
8818: srchterm => 'text',
8819: srchin => 'selectbox',
8820: srchby => 'selectbox',
8821: srchtype => 'selectbox',
8822: srchdomain => 'selectbox',
8823: },
1.160 raeburn 8824: );
8825:
8826: my $jsback .= qq|
8827: function backPage(formname,prevphase,prevstate) {
1.211 raeburn 8828: if (typeof prevphase == 'undefined') {
8829: formname.phase.value = '';
8830: }
8831: else {
8832: formname.phase.value = prevphase;
8833: }
8834: if (typeof prevstate == 'undefined') {
8835: formname.currstate.value = '';
8836: }
8837: else {
8838: formname.currstate.value = prevstate;
8839: }
1.160 raeburn 8840: formname.submit();
8841: }
8842: |;
8843: return ($jsback,\%elements);
8844: }
8845:
1.26 matthew 8846: sub course_level_table {
1.375 raeburn 8847: my ($inccourses,$showcredits,$defaultcredits) = @_;
8848: return unless (ref($inccourses) eq 'HASH');
1.26 matthew 8849: my $table = '';
1.62 www 8850: # Custom Roles?
8851:
1.190 raeburn 8852: my %customroles=&Apache::lonuserutils::my_custom_roles();
1.89 raeburn 8853: my %lt=&Apache::lonlocal::texthash(
8854: 'exs' => "Existing sections",
8855: 'new' => "Define new section",
8856: 'ssd' => "Set Start Date",
8857: 'sed' => "Set End Date",
1.131 raeburn 8858: 'crl' => "Course Level",
1.89 raeburn 8859: 'act' => "Activate",
8860: 'rol' => "Role",
8861: 'ext' => "Extent",
1.113 raeburn 8862: 'grs' => "Section",
1.375 raeburn 8863: 'crd' => "Credits",
1.89 raeburn 8864: 'sta' => "Start",
8865: 'end' => "End"
8866: );
1.62 www 8867:
1.375 raeburn 8868: foreach my $protectedcourse (sort(keys(%{$inccourses}))) {
1.135 raeburn 8869: my $thiscourse=$protectedcourse;
1.26 matthew 8870: $thiscourse=~s:_:/:g;
8871: my %coursedata=&Apache::lonnet::coursedescription($thiscourse);
1.365 raeburn 8872: my $isowner = &Apache::lonuserutils::is_courseowner($protectedcourse,$coursedata{'internal.courseowner'});
1.26 matthew 8873: my $area=$coursedata{'description'};
1.321 raeburn 8874: my $crstype=$coursedata{'type'};
1.135 raeburn 8875: if (!defined($area)) { $area=&mt('Unavailable course').': '.$protectedcourse; }
1.89 raeburn 8876: my ($domain,$cnum)=split(/\//,$thiscourse);
1.115 albertel 8877: my %sections_count;
1.101 albertel 8878: if (defined($env{'request.course.id'})) {
8879: if ($env{'request.course.id'} eq $domain.'_'.$cnum) {
1.115 albertel 8880: %sections_count =
8881: &Apache::loncommon::get_sections($domain,$cnum);
1.92 raeburn 8882: }
8883: }
1.321 raeburn 8884: my @roles = &Apache::lonuserutils::roles_by_context('course','',$crstype);
1.213 raeburn 8885: foreach my $role (@roles) {
1.321 raeburn 8886: my $plrole=&Apache::lonnet::plaintext($role,$crstype);
1.329 raeburn 8887: if ((&Apache::lonnet::allowed('c'.$role,$thiscourse)) ||
8888: ((($role eq 'cc') || ($role eq 'co')) && ($isowner))) {
1.221 raeburn 8889: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
1.375 raeburn 8890: $plrole,\%sections_count,\%lt,
1.402 raeburn 8891: $showcredits,$defaultcredits,$crstype);
1.221 raeburn 8892: } elsif ($env{'request.course.sec'} ne '') {
8893: if (&Apache::lonnet::allowed('c'.$role,$thiscourse.'/'.
8894: $env{'request.course.sec'})) {
8895: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
1.375 raeburn 8896: $plrole,\%sections_count,\%lt,
1.402 raeburn 8897: $showcredits,$defaultcredits,$crstype);
1.26 matthew 8898: }
8899: }
8900: }
1.221 raeburn 8901: if (&Apache::lonnet::allowed('ccr',$thiscourse)) {
1.324 raeburn 8902: foreach my $cust (sort(keys(%customroles))) {
8903: next if ($crstype eq 'Community' && $customroles{$cust} =~ /bre\&S/);
1.221 raeburn 8904: my $role = 'cr_cr_'.$env{'user.domain'}.'_'.$env{'user.name'}.'_'.$cust;
8905: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
1.402 raeburn 8906: $cust,\%sections_count,\%lt,
8907: $showcredits,$defaultcredits,$crstype);
1.221 raeburn 8908: }
1.62 www 8909: }
1.26 matthew 8910: }
8911: return '' if ($table eq ''); # return nothing if there is nothing
8912: # in the table
1.188 raeburn 8913: my $result;
8914: if (!$env{'request.course.id'}) {
8915: $result = '<h4>'.$lt{'crl'}.'</h4>'."\n";
8916: }
8917: $result .=
1.136 raeburn 8918: &Apache::loncommon::start_data_table().
8919: &Apache::loncommon::start_data_table_header_row().
1.375 raeburn 8920: '<th>'.$lt{'act'}.'</th><th>'.$lt{'rol'}.'</th>'."\n".
1.402 raeburn 8921: '<th>'.$lt{'ext'}.'</th><th>'."\n";
8922: if ($showcredits) {
8923: $result .= $lt{'crd'}.'</th>';
8924: }
8925: $result .=
1.375 raeburn 8926: '<th>'.$lt{'grs'}.'</th><th>'.$lt{'sta'}.'</th>'."\n".
8927: '<th>'.$lt{'end'}.'</th>'.
1.136 raeburn 8928: &Apache::loncommon::end_data_table_header_row().
8929: $table.
8930: &Apache::loncommon::end_data_table();
1.26 matthew 8931: return $result;
8932: }
1.88 raeburn 8933:
1.221 raeburn 8934: sub course_level_row {
1.375 raeburn 8935: my ($protectedcourse,$role,$area,$domain,$plrole,$sections_count,
1.402 raeburn 8936: $lt,$showcredits,$defaultcredits,$crstype) = @_;
1.375 raeburn 8937: my $creditem;
1.222 raeburn 8938: my $row = &Apache::loncommon::start_data_table_row().
8939: ' <td><input type="checkbox" name="act_'.
8940: $protectedcourse.'_'.$role.'" /></td>'."\n".
8941: ' <td>'.$plrole.'</td>'."\n".
8942: ' <td>'.$area.'<br />Domain: '.$domain.'</td>'."\n";
1.402 raeburn 8943: if (($showcredits) && ($role eq 'st') && ($crstype eq 'Course')) {
1.375 raeburn 8944: $row .=
8945: '<td><input type="text" name="credits_'.$protectedcourse.'_'.
8946: $role.'" size="3" value="'.$defaultcredits.'" /></td>';
8947: } else {
8948: $row .= '<td> </td>';
8949: }
1.322 raeburn 8950: if (($role eq 'cc') || ($role eq 'co')) {
1.222 raeburn 8951: $row .= '<td> </td>';
1.221 raeburn 8952: } elsif ($env{'request.course.sec'} ne '') {
1.222 raeburn 8953: $row .= ' <td><input type="hidden" value="'.
8954: $env{'request.course.sec'}.'" '.
8955: 'name="sec_'.$protectedcourse.'_'.$role.'" />'.
8956: $env{'request.course.sec'}.'</td>';
1.221 raeburn 8957: } else {
8958: if (ref($sections_count) eq 'HASH') {
8959: my $currsec =
8960: &Apache::lonuserutils::course_sections($sections_count,
8961: $protectedcourse.'_'.$role);
1.222 raeburn 8962: $row .= '<td><table class="LC_createuser">'."\n".
8963: '<tr class="LC_section_row">'."\n".
8964: ' <td valign="top">'.$lt->{'exs'}.'<br />'.
8965: $currsec.'</td>'."\n".
8966: ' <td> </td>'."\n".
8967: ' <td valign="top"> '.$lt->{'new'}.'<br />'.
1.221 raeburn 8968: '<input type="text" name="newsec_'.$protectedcourse.'_'.$role.
8969: '" value="" />'.
8970: '<input type="hidden" '.
8971: 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'."\n".
1.222 raeburn 8972: '</tr></table></td>'."\n";
1.221 raeburn 8973: } else {
1.222 raeburn 8974: $row .= '<td><input type="text" size="10" '.
1.375 raeburn 8975: 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'."\n";
1.221 raeburn 8976: }
8977: }
1.222 raeburn 8978: $row .= <<ENDTIMEENTRY;
8979: <td><input type="hidden" name="start_$protectedcourse\_$role" value="" />
1.221 raeburn 8980: <a href=
8981: "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 8982: <td><input type="hidden" name="end_$protectedcourse\_$role" value="" />
1.221 raeburn 8983: <a href=
8984: "javascript:pjump('date_end','End Date $plrole',document.cu.end_$protectedcourse\_$role.value,'end_$protectedcourse\_$role','cu.pres','dateset')">$lt->{'sed'}</a></td>
8985: ENDTIMEENTRY
1.222 raeburn 8986: $row .= &Apache::loncommon::end_data_table_row();
8987: return $row;
1.221 raeburn 8988: }
8989:
1.88 raeburn 8990: sub course_level_dc {
1.375 raeburn 8991: my ($dcdom,$showcredits) = @_;
1.190 raeburn 8992: my %customroles=&Apache::lonuserutils::my_custom_roles();
1.213 raeburn 8993: my @roles = &Apache::lonuserutils::roles_by_context('course');
1.88 raeburn 8994: my $hiddenitems = '<input type="hidden" name="dcdomain" value="'.$dcdom.'" />'.
8995: '<input type="hidden" name="origdom" value="'.$dcdom.'" />'.
1.133 raeburn 8996: '<input type="hidden" name="dccourse" value="" />';
1.355 www 8997: my $courseform=&Apache::loncommon::selectcourse_link
1.356 raeburn 8998: ('cu','dccourse','dcdomain','coursedesc',undef,undef,'Select','crstype');
1.375 raeburn 8999: my $credit_elem;
9000: if ($showcredits) {
9001: $credit_elem = 'credits';
9002: }
9003: my $cb_jscript = &Apache::loncommon::coursebrowser_javascript($dcdom,'currsec','cu','role','Course/Community Browser',$credit_elem);
1.88 raeburn 9004: my %lt=&Apache::lonlocal::texthash(
9005: 'rol' => "Role",
1.113 raeburn 9006: 'grs' => "Section",
1.88 raeburn 9007: 'exs' => "Existing sections",
9008: 'new' => "Define new section",
9009: 'sta' => "Start",
9010: 'end' => "End",
9011: 'ssd' => "Set Start Date",
1.355 www 9012: 'sed' => "Set End Date",
1.375 raeburn 9013: 'scc' => "Course/Community",
9014: 'crd' => "Credits",
1.88 raeburn 9015: );
1.323 raeburn 9016: my $header = '<h4>'.&mt('Course/Community Level').'</h4>'.
1.136 raeburn 9017: &Apache::loncommon::start_data_table().
9018: &Apache::loncommon::start_data_table_header_row().
1.375 raeburn 9019: '<th>'.$lt{'scc'}.'</th><th>'.$lt{'rol'}.'</th>'."\n".
1.397 bisitz 9020: '<th>'.$lt{'grs'}.'</th>'."\n";
9021: $header .= '<th>'.$lt{'crd'}.'</th>'."\n" if ($showcredits);
9022: $header .= '<th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'."\n".
1.136 raeburn 9023: &Apache::loncommon::end_data_table_header_row();
1.143 raeburn 9024: my $otheritems = &Apache::loncommon::start_data_table_row()."\n".
1.356 raeburn 9025: '<td><br /><span class="LC_nobreak"><input type="text" name="coursedesc" value="" onfocus="this.blur();opencrsbrowser('."'cu','dccourse','dcdomain','coursedesc','','','','crstype'".')" />'.
9026: $courseform.(' ' x4).'</span></td>'."\n".
1.389 bisitz 9027: '<td valign="top"><br /><select name="role">'."\n";
1.213 raeburn 9028: foreach my $role (@roles) {
1.135 raeburn 9029: my $plrole=&Apache::lonnet::plaintext($role);
1.389 bisitz 9030: $otheritems .= ' <option value="'.$role.'">'.$plrole.'</option>';
1.88 raeburn 9031: }
1.404 raeburn 9032: if ( keys(%customroles) > 0) {
9033: foreach my $cust (sort(keys(%customroles))) {
1.101 albertel 9034: my $custrole='cr_cr_'.$env{'user.domain'}.
1.135 raeburn 9035: '_'.$env{'user.name'}.'_'.$cust;
1.389 bisitz 9036: $otheritems .= ' <option value="'.$custrole.'">'.$cust.'</option>';
1.88 raeburn 9037: }
9038: }
9039: $otheritems .= '</select></td><td>'.
9040: '<table border="0" cellspacing="0" cellpadding="0">'.
9041: '<tr><td valign="top"><b>'.$lt{'exs'}.'</b><br /><select name="currsec">'.
1.389 bisitz 9042: ' <option value=""><--'.&mt('Pick course first').'</option></select></td>'.
1.88 raeburn 9043: '<td> </td>'.
9044: '<td valign="top"> <b>'.$lt{'new'}.'</b><br />'.
1.113 raeburn 9045: '<input type="text" name="newsec" value="" />'.
1.237 raeburn 9046: '<input type="hidden" name="section" value="" />'.
1.323 raeburn 9047: '<input type="hidden" name="groups" value="" />'.
9048: '<input type="hidden" name="crstype" value="" /></td>'.
1.375 raeburn 9049: '</tr></table></td>'."\n";
9050: if ($showcredits) {
9051: $otheritems .= '<td><br />'."\n".
1.397 bisitz 9052: '<input type="text" size="3" name="credits" value="" /></td>'."\n";
1.375 raeburn 9053: }
1.88 raeburn 9054: $otheritems .= <<ENDTIMEENTRY;
1.323 raeburn 9055: <td><br /><input type="hidden" name="start" value='' />
1.88 raeburn 9056: <a href=
9057: "javascript:pjump('date_start','Start Date',document.cu.start.value,'start','cu.pres','dateset')">$lt{'ssd'}</a></td>
1.323 raeburn 9058: <td><br /><input type="hidden" name="end" value='' />
1.88 raeburn 9059: <a href=
9060: "javascript:pjump('date_end','End Date',document.cu.end.value,'end','cu.pres','dateset')">$lt{'sed'}</a></td>
9061: ENDTIMEENTRY
1.136 raeburn 9062: $otheritems .= &Apache::loncommon::end_data_table_row().
9063: &Apache::loncommon::end_data_table()."\n";
1.88 raeburn 9064: return $cb_jscript.$header.$hiddenitems.$otheritems;
9065: }
9066:
1.237 raeburn 9067: sub update_selfenroll_config {
1.400 raeburn 9068: my ($r,$cid,$cdom,$cnum,$context,$crstype,$currsettings) = @_;
1.398 raeburn 9069: return unless (ref($currsettings) eq 'HASH');
9070: my ($row,$lt) = &Apache::lonuserutils::get_selfenroll_titles();
9071: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
1.237 raeburn 9072: my (%changes,%warning);
1.241 raeburn 9073: my $curr_types;
1.400 raeburn 9074: my %noedit;
9075: unless ($context eq 'domain') {
9076: %noedit = &get_noedit_fields($cdom,$cnum,$crstype,$row);
9077: }
1.237 raeburn 9078: if (ref($row) eq 'ARRAY') {
9079: foreach my $item (@{$row}) {
1.400 raeburn 9080: next if ($noedit{$item});
1.237 raeburn 9081: if ($item eq 'enroll_dates') {
9082: my (%currenrolldate,%newenrolldate);
9083: foreach my $type ('start','end') {
1.398 raeburn 9084: $currenrolldate{$type} = $currsettings->{'selfenroll_'.$type.'_date'};
1.237 raeburn 9085: $newenrolldate{$type} = &Apache::lonhtmlcommon::get_date_from_form('selfenroll_'.$type.'_date');
9086: if ($newenrolldate{$type} ne $currenrolldate{$type}) {
9087: $changes{'internal.selfenroll_'.$type.'_date'} = $newenrolldate{$type};
9088: }
9089: }
9090: } elsif ($item eq 'access_dates') {
9091: my (%currdate,%newdate);
9092: foreach my $type ('start','end') {
1.398 raeburn 9093: $currdate{$type} = $currsettings->{'selfenroll_'.$type.'_access'};
1.237 raeburn 9094: $newdate{$type} = &Apache::lonhtmlcommon::get_date_from_form('selfenroll_'.$type.'_access');
9095: if ($newdate{$type} ne $currdate{$type}) {
9096: $changes{'internal.selfenroll_'.$type.'_access'} = $newdate{$type};
9097: }
9098: }
1.241 raeburn 9099: } elsif ($item eq 'types') {
1.398 raeburn 9100: $curr_types = $currsettings->{'selfenroll_'.$item};
1.241 raeburn 9101: if ($env{'form.selfenroll_all'}) {
9102: if ($curr_types ne '*') {
9103: $changes{'internal.selfenroll_types'} = '*';
9104: } else {
9105: next;
9106: }
9107: } else {
1.249 raeburn 9108: my %currdoms;
1.241 raeburn 9109: my @entries = split(/;/,$curr_types);
9110: my @deletedoms = &Apache::loncommon::get_env_multiple('form.selfenroll_delete');
1.249 raeburn 9111: my @activations = &Apache::loncommon::get_env_multiple('form.selfenroll_activate');
1.241 raeburn 9112: my $newnum = 0;
1.249 raeburn 9113: my @latesttypes;
9114: foreach my $num (@activations) {
9115: my @types = &Apache::loncommon::get_env_multiple('form.selfenroll_types_'.$num);
9116: if (@types > 0) {
1.241 raeburn 9117: @types = sort(@types);
9118: my $typestr = join(',',@types);
1.249 raeburn 9119: my $typedom = $env{'form.selfenroll_dom_'.$num};
9120: $latesttypes[$newnum] = $typedom.':'.$typestr;
9121: $currdoms{$typedom} = 1;
1.241 raeburn 9122: $newnum ++;
9123: }
9124: }
1.338 raeburn 9125: for (my $j=0; $j<$env{'form.selfenroll_types_total'}; $j++) {
9126: if ((!grep(/^$j$/,@deletedoms)) && (!grep(/^$j$/,@activations))) {
1.249 raeburn 9127: my @types = &Apache::loncommon::get_env_multiple('form.selfenroll_types_'.$j);
9128: if (@types > 0) {
9129: @types = sort(@types);
9130: my $typestr = join(',',@types);
9131: my $typedom = $env{'form.selfenroll_dom_'.$j};
9132: $latesttypes[$newnum] = $typedom.':'.$typestr;
9133: $currdoms{$typedom} = 1;
9134: $newnum ++;
9135: }
9136: }
9137: }
9138: if ($env{'form.selfenroll_newdom'} ne '') {
9139: my $typedom = $env{'form.selfenroll_newdom'};
9140: if ((!defined($currdoms{$typedom})) &&
9141: (&Apache::lonnet::domain($typedom) ne '')) {
9142: my $typestr;
9143: my ($othertitle,$usertypes,$types) =
9144: &Apache::loncommon::sorted_inst_types($typedom);
9145: my $othervalue = 'any';
9146: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
9147: if (@{$types} > 0) {
1.257 raeburn 9148: my @esc_types = map { &escape($_); } @{$types};
1.249 raeburn 9149: $othervalue = 'other';
1.258 raeburn 9150: $typestr = join(',',(@esc_types,$othervalue));
1.249 raeburn 9151: }
9152: $typestr = $othervalue;
9153: } else {
9154: $typestr = $othervalue;
9155: }
9156: $latesttypes[$newnum] = $typedom.':'.$typestr;
9157: $newnum ++ ;
9158: }
9159: }
1.241 raeburn 9160: my $selfenroll_types = join(';',@latesttypes);
9161: if ($selfenroll_types ne $curr_types) {
9162: $changes{'internal.selfenroll_types'} = $selfenroll_types;
9163: }
9164: }
1.276 raeburn 9165: } elsif ($item eq 'limit') {
9166: my $newlimit = $env{'form.selfenroll_limit'};
9167: my $newcap = $env{'form.selfenroll_cap'};
9168: $newcap =~s/\s+//g;
1.398 raeburn 9169: my $currlimit = $currsettings->{'selfenroll_limit'};
1.276 raeburn 9170: $currlimit = 'none' if ($currlimit eq '');
1.398 raeburn 9171: my $currcap = $currsettings->{'selfenroll_cap'};
1.276 raeburn 9172: if ($newlimit ne $currlimit) {
9173: if ($newlimit ne 'none') {
9174: if ($newcap =~ /^\d+$/) {
9175: if ($newcap ne $currcap) {
9176: $changes{'internal.selfenroll_cap'} = $newcap;
9177: }
9178: $changes{'internal.selfenroll_limit'} = $newlimit;
9179: } else {
1.398 raeburn 9180: $warning{$item} = &mt('Maximum enrollment setting unchanged.').'<br />'.
9181: &mt('The value provided was invalid - it must be a positive integer if enrollment is being limited.');
1.276 raeburn 9182: }
9183: } elsif ($currcap ne '') {
9184: $changes{'internal.selfenroll_cap'} = '';
9185: $changes{'internal.selfenroll_limit'} = $newlimit;
9186: }
9187: } elsif ($currlimit ne 'none') {
9188: if ($newcap =~ /^\d+$/) {
9189: if ($newcap ne $currcap) {
9190: $changes{'internal.selfenroll_cap'} = $newcap;
9191: }
9192: } else {
1.398 raeburn 9193: $warning{$item} = &mt('Maximum enrollment setting unchanged.').'<br />'.
9194: &mt('The value provided was invalid - it must be a positive integer if enrollment is being limited.');
1.276 raeburn 9195: }
9196: }
9197: } elsif ($item eq 'approval') {
9198: my (@currnotified,@newnotified);
1.398 raeburn 9199: my $currapproval = $currsettings->{'selfenroll_approval'};
9200: my $currnotifylist = $currsettings->{'selfenroll_notifylist'};
1.276 raeburn 9201: if ($currnotifylist ne '') {
9202: @currnotified = split(/,/,$currnotifylist);
9203: @currnotified = sort(@currnotified);
9204: }
9205: my $newapproval = $env{'form.selfenroll_approval'};
9206: @newnotified = &Apache::loncommon::get_env_multiple('form.selfenroll_notify');
9207: @newnotified = sort(@newnotified);
9208: if ($newapproval ne $currapproval) {
9209: $changes{'internal.selfenroll_approval'} = $newapproval;
9210: if (!$newapproval) {
9211: if ($currnotifylist ne '') {
9212: $changes{'internal.selfenroll_notifylist'} = '';
9213: }
9214: } else {
9215: my @differences =
1.295 raeburn 9216: &Apache::loncommon::compare_arrays(\@currnotified,\@newnotified);
1.276 raeburn 9217: if (@differences > 0) {
9218: if (@newnotified > 0) {
9219: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
9220: } else {
9221: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
9222: }
9223: }
9224: }
9225: } else {
1.295 raeburn 9226: my @differences = &Apache::loncommon::compare_arrays(\@currnotified,\@newnotified);
1.276 raeburn 9227: if (@differences > 0) {
9228: if (@newnotified > 0) {
9229: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
9230: } else {
9231: $changes{'internal.selfenroll_notifylist'} = '';
9232: }
9233: }
9234: }
1.237 raeburn 9235: } else {
1.398 raeburn 9236: my $curr_val = $currsettings->{'selfenroll_'.$item};
1.237 raeburn 9237: my $newval = $env{'form.selfenroll_'.$item};
9238: if ($item eq 'section') {
9239: $newval = $env{'form.sections'};
1.241 raeburn 9240: if (defined($curr_groups{$newval})) {
1.237 raeburn 9241: $newval = $curr_val;
1.398 raeburn 9242: $warning{$item} = &mt('Section for self-enrolled users unchanged as the proposed section is a group').'<br />'.
9243: &mt('Group names and section names must be distinct');
1.237 raeburn 9244: } elsif ($newval eq 'all') {
9245: $newval = $curr_val;
1.274 bisitz 9246: $warning{$item} = &mt('Section for self-enrolled users unchanged, as "all" is a reserved section name.');
1.237 raeburn 9247: }
9248: if ($newval eq '') {
9249: $newval = 'none';
9250: }
9251: }
9252: if ($newval ne $curr_val) {
9253: $changes{'internal.selfenroll_'.$item} = $newval;
9254: }
1.241 raeburn 9255: }
1.237 raeburn 9256: }
9257: if (keys(%warning) > 0) {
9258: foreach my $item (@{$row}) {
9259: if (exists($warning{$item})) {
9260: $r->print($warning{$item}.'<br />');
9261: }
9262: }
9263: }
9264: if (keys(%changes) > 0) {
9265: my $putresult = &Apache::lonnet::put('environment',\%changes,$cdom,$cnum);
9266: if ($putresult eq 'ok') {
9267: if ((exists($changes{'internal.selfenroll_types'})) ||
9268: (exists($changes{'internal.selfenroll_start_date'})) ||
9269: (exists($changes{'internal.selfenroll_end_date'}))) {
9270: my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',
9271: $cnum,undef,undef,'Course');
9272: my $chome = &Apache::lonnet::homeserver($cnum,$cdom);
1.398 raeburn 9273: if (ref($crsinfo{$cid}) eq 'HASH') {
1.237 raeburn 9274: foreach my $item ('selfenroll_types','selfenroll_start_date','selfenroll_end_date') {
9275: if (exists($changes{'internal.'.$item})) {
1.398 raeburn 9276: $crsinfo{$cid}{$item} = $changes{'internal.'.$item};
1.237 raeburn 9277: }
9278: }
9279: my $crsputresult =
9280: &Apache::lonnet::courseidput($cdom,\%crsinfo,
9281: $chome,'notime');
9282: }
9283: }
9284: $r->print(&mt('The following changes were made to self-enrollment settings:').'<ul>');
9285: foreach my $item (@{$row}) {
9286: my $title = $item;
9287: if (ref($lt) eq 'HASH') {
9288: $title = $lt->{$item};
9289: }
9290: if ($item eq 'enroll_dates') {
9291: foreach my $type ('start','end') {
9292: if (exists($changes{'internal.selfenroll_'.$type.'_date'})) {
9293: my $newdate = &Apache::lonlocal::locallocaltime($changes{'internal.selfenroll_'.$type.'_date'});
1.244 bisitz 9294: $r->print('<li>'.&mt('[_1]: "[_2]" set to "[_3]".',
1.237 raeburn 9295: $title,$type,$newdate).'</li>');
9296: }
9297: }
9298: } elsif ($item eq 'access_dates') {
9299: foreach my $type ('start','end') {
9300: if (exists($changes{'internal.selfenroll_'.$type.'_access'})) {
9301: my $newdate = &Apache::lonlocal::locallocaltime($changes{'internal.selfenroll_'.$type.'_access'});
1.244 bisitz 9302: $r->print('<li>'.&mt('[_1]: "[_2]" set to "[_3]".',
1.237 raeburn 9303: $title,$type,$newdate).'</li>');
9304: }
9305: }
1.276 raeburn 9306: } elsif ($item eq 'limit') {
9307: if ((exists($changes{'internal.selfenroll_limit'})) ||
9308: (exists($changes{'internal.selfenroll_cap'}))) {
9309: my ($newval,$newcap);
9310: if ($changes{'internal.selfenroll_cap'} ne '') {
9311: $newcap = $changes{'internal.selfenroll_cap'}
9312: } else {
1.398 raeburn 9313: $newcap = $currsettings->{'selfenroll_cap'};
1.276 raeburn 9314: }
9315: if ($changes{'internal.selfenroll_limit'} eq 'none') {
9316: $newval = &mt('No limit');
9317: } elsif ($changes{'internal.selfenroll_limit'} eq
9318: 'allstudents') {
9319: $newval = &mt('New self-enrollment no longer allowed when total (all students) reaches [_1].',$newcap);
9320: } elsif ($changes{'internal.selfenroll_limit'} eq 'selfenrolled') {
9321: $newval = &mt('New self-enrollment no longer allowed when total number of self-enrolled students reaches [_1].',$newcap);
9322: } else {
1.398 raeburn 9323: my $currlimit = $currsettings->{'selfenroll_limit'};
1.276 raeburn 9324: if ($currlimit eq 'allstudents') {
9325: $newval = &mt('New self-enrollment no longer allowed when total (all students) reaches [_1].',$newcap);
9326: } elsif ($changes{'internal.selfenroll_limit'} eq 'selfenrolled') {
1.308 raeburn 9327: $newval = &mt('New self-enrollment no longer allowed when total number of self-enrolled students reaches [_1].',$newcap);
1.276 raeburn 9328: }
9329: }
9330: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval).'</li>'."\n");
9331: }
9332: } elsif ($item eq 'approval') {
9333: if ((exists($changes{'internal.selfenroll_approval'})) ||
9334: (exists($changes{'internal.selfenroll_notifylist'}))) {
1.398 raeburn 9335: my %selfdescs = &Apache::lonuserutils::selfenroll_default_descs();
1.276 raeburn 9336: my ($newval,$newnotify);
9337: if (exists($changes{'internal.selfenroll_notifylist'})) {
9338: $newnotify = $changes{'internal.selfenroll_notifylist'};
9339: } else {
1.398 raeburn 9340: $newnotify = $currsettings->{'selfenroll_notifylist'};
1.276 raeburn 9341: }
1.398 raeburn 9342: if (exists($changes{'internal.selfenroll_approval'})) {
9343: if ($changes{'internal.selfenroll_approval'} !~ /^[012]$/) {
9344: $changes{'internal.selfenroll_approval'} = '0';
9345: }
9346: $newval = $selfdescs{'approval'}{$changes{'internal.selfenroll_approval'}};
1.276 raeburn 9347: } else {
1.398 raeburn 9348: my $currapproval = $currsettings->{'selfenroll_approval'};
9349: if ($currapproval !~ /^[012]$/) {
9350: $currapproval = 0;
1.276 raeburn 9351: }
1.398 raeburn 9352: $newval = $selfdescs{'approval'}{$currapproval};
1.276 raeburn 9353: }
9354: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval));
9355: if ($newnotify) {
1.277 raeburn 9356: $r->print('<br />'.&mt('The following will be notified when an enrollment request needs approval, or has been approved: [_1].',$newnotify));
1.276 raeburn 9357: } else {
1.277 raeburn 9358: $r->print('<br />'.&mt('No notifications sent when an enrollment request needs approval, or has been approved.'));
1.276 raeburn 9359: }
9360: $r->print('</li>'."\n");
9361: }
1.237 raeburn 9362: } else {
9363: if (exists($changes{'internal.selfenroll_'.$item})) {
1.241 raeburn 9364: my $newval = $changes{'internal.selfenroll_'.$item};
9365: if ($item eq 'types') {
9366: if ($newval eq '') {
9367: $newval = &mt('None');
9368: } elsif ($newval eq '*') {
9369: $newval = &mt('Any user in any domain');
9370: }
1.245 raeburn 9371: } elsif ($item eq 'registered') {
9372: if ($newval eq '1') {
9373: $newval = &mt('Yes');
9374: } elsif ($newval eq '0') {
9375: $newval = &mt('No');
9376: }
1.241 raeburn 9377: }
1.244 bisitz 9378: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval).'</li>'."\n");
1.237 raeburn 9379: }
9380: }
9381: }
9382: $r->print('</ul>');
1.398 raeburn 9383: if ($env{'course.'.$cid.'.description'} ne '') {
9384: my %newenvhash;
9385: foreach my $key (keys(%changes)) {
9386: $newenvhash{'course.'.$cid.'.'.$key} = $changes{$key};
9387: }
9388: &Apache::lonnet::appenv(\%newenvhash);
1.237 raeburn 9389: }
9390: } else {
1.398 raeburn 9391: $r->print(&mt('An error occurred when saving changes to self-enrollment settings in this course.').'<br />'.
9392: &mt('The error was: [_1].',$putresult));
1.237 raeburn 9393: }
9394: } else {
1.249 raeburn 9395: $r->print(&mt('No changes were made to the existing self-enrollment settings in this course.'));
1.237 raeburn 9396: }
9397: } else {
1.249 raeburn 9398: $r->print(&mt('No changes were made to the existing self-enrollment settings in this course.'));
1.241 raeburn 9399: }
1.400 raeburn 9400: my $visactions = &cat_visibility();
9401: my ($cathash,%cattype);
9402: my %domconfig = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom);
9403: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
9404: $cathash = $domconfig{'coursecategories'}{'cats'};
9405: $cattype{'auth'} = $domconfig{'coursecategories'}{'auth'};
9406: $cattype{'unauth'} = $domconfig{'coursecategories'}{'unauth'};
9407: } else {
9408: $cathash = {};
9409: $cattype{'auth'} = 'std';
9410: $cattype{'unauth'} = 'std';
9411: }
9412: if (($cattype{'auth'} eq 'none') && ($cattype{'unauth'} eq 'none')) {
9413: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
9414: '<br />'.
9415: '<br />'.$visactions->{'take'}.'<ul>'.
9416: '<li>'.$visactions->{'dc_chgconf'}.'</li>'.
9417: '</ul>');
9418: } elsif (($cattype{'auth'} !~ /^(std|domonly)$/) && ($cattype{'unauth'} !~ /^(std|domonly)$/)) {
9419: if ($currsettings->{'uniquecode'}) {
9420: $r->print('<span class="LC_info">'.$visactions->{'vis'}.'</span>');
9421: } else {
1.366 bisitz 9422: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
1.400 raeburn 9423: '<br />'.
9424: '<br />'.$visactions->{'take'}.'<ul>'.
9425: '<li>'.$visactions->{'dc_setcode'}.'</li>'.
9426: '</ul><br />');
9427: }
9428: } else {
9429: my ($visible,$cansetvis,$vismsgs) = &visible_in_stdcat($cdom,$cnum,\%domconfig);
9430: if (ref($visactions) eq 'HASH') {
9431: if (!$visible) {
9432: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
9433: '<br />');
9434: if (ref($vismsgs) eq 'ARRAY') {
9435: $r->print('<br />'.$visactions->{'take'}.'<ul>');
9436: foreach my $item (@{$vismsgs}) {
9437: $r->print('<li>'.$visactions->{$item}.'</li>');
9438: }
9439: $r->print('</ul>');
1.256 raeburn 9440: }
1.400 raeburn 9441: $r->print($cansetvis);
1.256 raeburn 9442: }
9443: }
9444: }
1.237 raeburn 9445: return;
9446: }
9447:
1.27 matthew 9448: #---------------------------------------------- end functions for &phase_two
1.29 matthew 9449:
9450: #--------------------------------- functions for &phase_two and &phase_three
9451:
9452: #--------------------------end of functions for &phase_two and &phase_three
1.372 raeburn 9453:
1.1 www 9454: 1;
9455: __END__
1.2 www 9456:
9457:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>