Annotation of loncom/interface/loncreateuser.pm, revision 1.441
1.20 harris41 1: # The LearningOnline Network with CAPA
1.1 www 2: # Create a user
3: #
1.441 ! raeburn 4: # $Id: loncreateuser.pm,v 1.440 2017/04/02 04:36:07 raeburn Exp $
1.22 albertel 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
1.20 harris41 28: ###
29:
1.1 www 30: package Apache::loncreateuser;
1.66 bowersj2 31:
32: =pod
33:
34: =head1 NAME
35:
1.263 jms 36: Apache::loncreateuser.pm
1.66 bowersj2 37:
38: =head1 SYNOPSIS
39:
1.263 jms 40: Handler to create users and custom roles
41:
42: Provides an Apache handler for creating users,
1.66 bowersj2 43: editing their login parameters, roles, and removing roles, and
44: also creating and assigning custom roles.
45:
46: =head1 OVERVIEW
47:
48: =head2 Custom Roles
49:
50: In LON-CAPA, roles are actually collections of privileges. "Teaching
51: Assistant", "Course Coordinator", and other such roles are really just
52: collection of privileges that are useful in many circumstances.
53:
1.324 raeburn 54: Custom roles can be defined by a Domain Coordinator, Course Coordinator
55: or Community Coordinator via the Manage User functionality.
56: The custom role editor screen will show all privileges which can be
57: assigned to users. For a complete list of privileges, please see
58: C</home/httpd/lonTabs/rolesplain.tab>.
1.66 bowersj2 59:
1.324 raeburn 60: Custom role definitions are stored in the C<roles.db> file of the creator
61: of the role.
1.66 bowersj2 62:
63: =cut
1.1 www 64:
65: use strict;
66: use Apache::Constants qw(:common :http);
67: use Apache::lonnet;
1.54 bowersj2 68: use Apache::loncommon;
1.68 www 69: use Apache::lonlocal;
1.117 raeburn 70: use Apache::longroup;
1.190 raeburn 71: use Apache::lonuserutils;
1.307 raeburn 72: use Apache::loncoursequeueadmin;
1.139 albertel 73: use LONCAPA qw(:DEFAULT :match);
1.1 www 74:
1.20 harris41 75: my $loginscript; # piece of javascript used in two separate instances
76: my $authformnop;
77: my $authformkrb;
78: my $authformint;
79: my $authformfsys;
80: my $authformloc;
81:
1.94 matthew 82: sub initialize_authen_forms {
1.227 raeburn 83: my ($dom,$formname,$curr_authtype,$mode) = @_;
84: my ($krbdef,$krbdefdom) = &Apache::loncommon::get_kerberos_defaults($dom);
85: my %param = ( formname => $formname,
1.187 raeburn 86: kerb_def_dom => $krbdefdom,
1.227 raeburn 87: kerb_def_auth => $krbdef,
1.187 raeburn 88: domain => $dom,
89: );
1.188 raeburn 90: my %abv_auth = &auth_abbrev();
1.227 raeburn 91: if ($curr_authtype =~ /^(krb4|krb5|internal|localauth|unix):(.*)$/) {
1.188 raeburn 92: my $long_auth = $1;
1.227 raeburn 93: my $curr_autharg = $2;
1.188 raeburn 94: my %abv_auth = &auth_abbrev();
95: $param{'curr_authtype'} = $abv_auth{$long_auth};
96: if ($long_auth =~ /^krb(4|5)$/) {
97: $param{'curr_kerb_ver'} = $1;
1.227 raeburn 98: $param{'curr_autharg'} = $curr_autharg;
1.188 raeburn 99: }
1.205 raeburn 100: if ($mode eq 'modifyuser') {
101: $param{'mode'} = $mode;
102: }
1.187 raeburn 103: }
1.227 raeburn 104: $loginscript = &Apache::loncommon::authform_header(%param);
105: $authformkrb = &Apache::loncommon::authform_kerberos(%param);
1.31 matthew 106: $authformnop = &Apache::loncommon::authform_nochange(%param);
107: $authformint = &Apache::loncommon::authform_internal(%param);
108: $authformfsys = &Apache::loncommon::authform_filesystem(%param);
109: $authformloc = &Apache::loncommon::authform_local(%param);
1.20 harris41 110: }
111:
1.188 raeburn 112: sub auth_abbrev {
113: my %abv_auth = (
1.368 raeburn 114: krb5 => 'krb',
115: krb4 => 'krb',
116: internal => 'int',
117: localauth => 'loc',
118: unix => 'fsys',
1.188 raeburn 119: );
120: return %abv_auth;
121: }
1.43 www 122:
1.134 raeburn 123: # ====================================================
124:
1.378 raeburn 125: sub user_quotas {
1.134 raeburn 126: my ($ccuname,$ccdomain) = @_;
127: my %lt = &Apache::lonlocal::texthash(
1.267 raeburn 128: 'usrt' => "User Tools",
129: 'cust' => "Custom quota",
130: 'chqu' => "Change quota",
1.134 raeburn 131: );
1.378 raeburn 132:
1.149 raeburn 133: my $quota_javascript = <<"END_SCRIPT";
134: <script type="text/javascript">
1.301 bisitz 135: // <![CDATA[
1.378 raeburn 136: function quota_changes(caller,context) {
137: var customoff = document.getElementById('custom_'+context+'quota_off');
138: var customon = document.getElementById('custom_'+context+'quota_on');
139: var number = document.getElementById(context+'quota');
1.149 raeburn 140: if (caller == "custom") {
1.378 raeburn 141: if (customoff) {
142: if (customoff.checked) {
143: number.value = "";
144: }
1.149 raeburn 145: }
146: }
147: if (caller == "quota") {
1.378 raeburn 148: if (customon) {
149: customon.checked = true;
150: }
1.149 raeburn 151: }
1.378 raeburn 152: return;
1.149 raeburn 153: }
1.301 bisitz 154: // ]]>
1.149 raeburn 155: </script>
156: END_SCRIPT
1.378 raeburn 157: my $longinsttype;
158: my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($ccdomain);
1.267 raeburn 159: my $output = $quota_javascript."\n".
160: '<h3>'.$lt{'usrt'}.'</h3>'."\n".
161: &Apache::loncommon::start_data_table();
162:
1.418 raeburn 163: if ((&Apache::lonnet::allowed('mut',$ccdomain)) ||
164: (&Apache::lonnet::allowed('udp',$ccdomain))) {
1.275 raeburn 165: $output .= &build_tools_display($ccuname,$ccdomain,'tools');
1.267 raeburn 166: }
1.378 raeburn 167:
168: my %titles = &Apache::lonlocal::texthash (
169: portfolio => "Disk space allocated to user's portfolio files",
1.385 bisitz 170: author => "Disk space allocated to user's Authoring Space (if role assigned)",
1.378 raeburn 171: );
172: foreach my $name ('portfolio','author') {
173: my ($currquota,$quotatype,$inststatus,$defquota) =
174: &Apache::loncommon::get_user_quota($ccuname,$ccdomain,$name);
175: if ($longinsttype eq '') {
176: if ($inststatus ne '') {
177: if ($usertypes->{$inststatus} ne '') {
178: $longinsttype = $usertypes->{$inststatus};
179: }
180: }
181: }
182: my ($showquota,$custom_on,$custom_off,$defaultinfo);
183: $custom_on = ' ';
184: $custom_off = ' checked="checked" ';
185: if ($quotatype eq 'custom') {
186: $custom_on = $custom_off;
187: $custom_off = ' ';
188: $showquota = $currquota;
189: if ($longinsttype eq '') {
190: $defaultinfo = &mt('For this user, the default quota would be [_1]'
1.383 raeburn 191: .' MB.',$defquota);
1.378 raeburn 192: } else {
193: $defaultinfo = &mt("For this user, the default quota would be [_1]".
1.383 raeburn 194: " MB, as determined by the user's institutional".
1.378 raeburn 195: " affiliation ([_2]).",$defquota,$longinsttype);
196: }
197: } else {
198: if ($longinsttype eq '') {
199: $defaultinfo = &mt('For this user, the default quota is [_1]'
1.383 raeburn 200: .' MB.',$defquota);
1.378 raeburn 201: } else {
202: $defaultinfo = &mt("For this user, the default quota of [_1]".
1.383 raeburn 203: " MB, is determined by the user's institutional".
1.378 raeburn 204: " affiliation ([_2]).",$defquota,$longinsttype);
205: }
206: }
207:
208: if (&Apache::lonnet::allowed('mpq',$ccdomain)) {
209: $output .= '<tr class="LC_info_row">'."\n".
210: ' <td>'.$titles{$name}.'</td>'."\n".
211: ' </tr>'."\n".
212: &Apache::loncommon::start_data_table_row()."\n".
1.390 bisitz 213: ' <td><span class="LC_nobreak">'.
214: &mt('Current quota: [_1] MB',$currquota).'</span> '.
1.378 raeburn 215: $defaultinfo.'</td>'."\n".
216: &Apache::loncommon::end_data_table_row()."\n".
217: &Apache::loncommon::start_data_table_row()."\n".
218: ' <td><span class="LC_nobreak">'.$lt{'chqu'}.
219: ': <label>'.
220: '<input type="radio" name="custom_'.$name.'quota" id="custom_'.$name.'quota_off" '.
1.379 raeburn 221: 'value="0" '.$custom_off.' onchange="javascript:quota_changes('."'custom','$name'".');"'.
1.390 bisitz 222: ' /><span class="LC_nobreak">'.
223: &mt('Default ([_1] MB)',$defquota).'</span></label> '.
1.378 raeburn 224: ' <label><input type="radio" name="custom_'.$name.'quota" id="custom_'.$name.'quota_on" '.
1.379 raeburn 225: 'value="1" '.$custom_on.' onchange="javascript:quota_changes('."'custom','$name'".');"'.
1.378 raeburn 226: ' />'.$lt{'cust'}.':</label> '.
1.379 raeburn 227: '<input type="text" name="'.$name.'quota" id="'.$name.'quota" size ="5" '.
228: 'value="'.$showquota.'" onfocus="javascript:quota_changes('."'quota','$name'".');"'.
1.390 bisitz 229: ' /> '.&mt('MB').'</span></td>'."\n".
1.378 raeburn 230: &Apache::loncommon::end_data_table_row()."\n";
231: }
232: }
1.267 raeburn 233: $output .= &Apache::loncommon::end_data_table();
1.134 raeburn 234: return $output;
235: }
236:
1.275 raeburn 237: sub build_tools_display {
238: my ($ccuname,$ccdomain,$context) = @_;
1.306 raeburn 239: my (@usertools,%userenv,$output,@options,%validations,%reqtitles,%reqdisplay,
1.332 raeburn 240: $colspan,$isadv,%domconfig);
1.275 raeburn 241: my %lt = &Apache::lonlocal::texthash (
242: 'blog' => "Personal User Blog",
243: 'aboutme' => "Personal Information Page",
1.385 bisitz 244: 'webdav' => "WebDAV access to Authoring Spaces (if SSL and author/co-author)",
1.275 raeburn 245: 'portfolio' => "Personal User Portfolio",
246: 'avai' => "Available",
247: 'cusa' => "availability",
248: 'chse' => "Change setting",
249: 'usde' => "Use default",
250: 'uscu' => "Use custom",
251: 'official' => 'Can request creation of official courses',
1.299 raeburn 252: 'unofficial' => 'Can request creation of unofficial courses',
253: 'community' => 'Can request creation of communities',
1.384 raeburn 254: 'textbook' => 'Can request creation of textbook courses',
1.411 raeburn 255: 'placement' => 'Can request creation of placement tests',
1.362 raeburn 256: 'requestauthor' => 'Can request author space',
1.275 raeburn 257: );
1.279 raeburn 258: if ($context eq 'requestcourses') {
1.275 raeburn 259: %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
1.299 raeburn 260: 'requestcourses.official','requestcourses.unofficial',
1.411 raeburn 261: 'requestcourses.community','requestcourses.textbook',
262: 'requestcourses.placement');
263: @usertools = ('official','unofficial','community','textbook','placement');
1.309 raeburn 264: @options =('norequest','approval','autolimit','validate');
1.306 raeburn 265: %validations = &Apache::lonnet::auto_courserequest_checks($ccdomain);
266: %reqtitles = &courserequest_titles();
267: %reqdisplay = &courserequest_display();
268: $colspan = ' colspan="2"';
1.332 raeburn 269: %domconfig =
270: &Apache::lonnet::get_dom('configuration',['requestcourses'],$ccdomain);
1.418 raeburn 271: $isadv = &Apache::lonnet::is_advanced_user($ccdomain,$ccuname);
1.362 raeburn 272: } elsif ($context eq 'requestauthor') {
273: %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
274: 'requestauthor');
275: @usertools = ('requestauthor');
276: @options =('norequest','approval','automatic');
277: %reqtitles = &requestauthor_titles();
278: %reqdisplay = &requestauthor_display();
279: $colspan = ' colspan="2"';
280: %domconfig =
281: &Apache::lonnet::get_dom('configuration',['requestauthor'],$ccdomain);
1.275 raeburn 282: } else {
283: %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
1.361 raeburn 284: 'tools.aboutme','tools.portfolio','tools.blog',
285: 'tools.webdav');
286: @usertools = ('aboutme','blog','webdav','portfolio');
1.275 raeburn 287: }
288: foreach my $item (@usertools) {
1.306 raeburn 289: my ($custom_access,$curr_access,$cust_on,$cust_off,$tool_on,$tool_off,
290: $currdisp,$custdisp,$custradio);
1.275 raeburn 291: $cust_off = 'checked="checked" ';
292: $tool_on = 'checked="checked" ';
293: $curr_access =
294: &Apache::lonnet::usertools_access($ccuname,$ccdomain,$item,undef,
295: $context);
1.362 raeburn 296: if ($context eq 'requestauthor') {
297: if ($userenv{$context} ne '') {
298: $cust_on = ' checked="checked" ';
299: $cust_off = '';
300: }
301: } elsif ($userenv{$context.'.'.$item} ne '') {
1.306 raeburn 302: $cust_on = ' checked="checked" ';
303: $cust_off = '';
304: }
305: if ($context eq 'requestcourses') {
306: if ($userenv{$context.'.'.$item} eq '') {
1.314 raeburn 307: $custom_access = &mt('Currently from default setting.');
1.306 raeburn 308: } else {
309: $custom_access = &mt('Currently from custom setting.');
1.275 raeburn 310: }
1.362 raeburn 311: } elsif ($context eq 'requestauthor') {
312: if ($userenv{$context} eq '') {
313: $custom_access = &mt('Currently from default setting.');
314: } else {
315: $custom_access = &mt('Currently from custom setting.');
316: }
1.275 raeburn 317: } else {
1.306 raeburn 318: if ($userenv{$context.'.'.$item} eq '') {
1.314 raeburn 319: $custom_access =
1.306 raeburn 320: &mt('Availability determined currently from default setting.');
321: if (!$curr_access) {
322: $tool_off = 'checked="checked" ';
323: $tool_on = '';
324: }
325: } else {
1.314 raeburn 326: $custom_access =
1.306 raeburn 327: &mt('Availability determined currently from custom setting.');
328: if ($userenv{$context.'.'.$item} == 0) {
329: $tool_off = 'checked="checked" ';
330: $tool_on = '';
331: }
1.275 raeburn 332: }
333: }
334: $output .= ' <tr class="LC_info_row">'."\n".
1.306 raeburn 335: ' <td'.$colspan.'>'.$lt{$item}.'</td>'."\n".
1.275 raeburn 336: ' </tr>'."\n".
1.306 raeburn 337: &Apache::loncommon::start_data_table_row()."\n";
1.418 raeburn 338:
1.362 raeburn 339: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.306 raeburn 340: my ($curroption,$currlimit);
1.362 raeburn 341: my $envkey = $context.'.'.$item;
342: if ($context eq 'requestauthor') {
343: $envkey = $context;
344: }
345: if ($userenv{$envkey} ne '') {
346: $curroption = $userenv{$envkey};
1.332 raeburn 347: } else {
348: my (@inststatuses);
1.362 raeburn 349: if ($context eq 'requestcourses') {
350: $curroption =
351: &Apache::loncoursequeueadmin::get_processtype('course',$ccuname,$ccdomain,
352: $isadv,$ccdomain,$item,
353: \@inststatuses,\%domconfig);
354: } else {
355: $curroption =
356: &Apache::loncoursequeueadmin::get_processtype('requestauthor',$ccuname,$ccdomain,
357: $isadv,$ccdomain,undef,
358: \@inststatuses,\%domconfig);
359: }
1.332 raeburn 360: }
1.306 raeburn 361: if (!$curroption) {
362: $curroption = 'norequest';
363: }
364: if ($curroption =~ /^autolimit=(\d*)$/) {
365: $currlimit = $1;
1.314 raeburn 366: if ($currlimit eq '') {
367: $currdisp = &mt('Yes, automatic creation');
368: } else {
369: $currdisp = &mt('Yes, up to [quant,_1,request]/user',$currlimit);
370: }
1.306 raeburn 371: } else {
372: $currdisp = $reqdisplay{$curroption};
373: }
374: $custdisp = '<table>';
375: foreach my $option (@options) {
376: my $val = $option;
377: if ($option eq 'norequest') {
378: $val = 0;
379: }
380: if ($option eq 'validate') {
381: my $canvalidate = 0;
382: if (ref($validations{$item}) eq 'HASH') {
383: if ($validations{$item}{'_custom_'}) {
384: $canvalidate = 1;
385: }
386: }
387: next if (!$canvalidate);
388: }
389: my $checked = '';
390: if ($option eq $curroption) {
391: $checked = ' checked="checked"';
392: } elsif ($option eq 'autolimit') {
393: if ($curroption =~ /^autolimit/) {
394: $checked = ' checked="checked"';
395: }
396: }
1.362 raeburn 397: my $name = 'crsreq_'.$item;
398: if ($context eq 'requestauthor') {
399: $name = $item;
400: }
1.306 raeburn 401: $custdisp .= '<tr><td><span class="LC_nobreak"><label>'.
1.362 raeburn 402: '<input type="radio" name="'.$name.'" '.
403: 'value="'.$val.'"'.$checked.' />'.
1.306 raeburn 404: $reqtitles{$option}.'</label> ';
405: if ($option eq 'autolimit') {
1.362 raeburn 406: $custdisp .= '<input type="text" name="'.$name.
407: '_limit" size="1" '.
1.314 raeburn 408: 'value="'.$currlimit.'" /></span><br />'.
409: $reqtitles{'unlimited'};
1.362 raeburn 410: } else {
411: $custdisp .= '</span>';
412: }
413: $custdisp .= '</td></tr>';
1.306 raeburn 414: }
415: $custdisp .= '</table>';
416: $custradio = '</span></td><td>'.&mt('Custom setting').'<br />'.$custdisp;
417: } else {
418: $currdisp = ($curr_access?&mt('Yes'):&mt('No'));
1.362 raeburn 419: my $name = $context.'_'.$item;
420: if ($context eq 'requestauthor') {
421: $name = $context;
422: }
1.306 raeburn 423: $custdisp = '<span class="LC_nobreak"><label>'.
1.362 raeburn 424: '<input type="radio" name="'.$name.'"'.
1.361 raeburn 425: ' value="1" '.$tool_on.'/>'.&mt('On').'</label> <label>'.
1.362 raeburn 426: '<input type="radio" name="'.$name.'" value="0" '.
1.306 raeburn 427: $tool_off.'/>'.&mt('Off').'</label></span>';
428: $custradio = (' 'x2).'--'.$lt{'cusa'}.': '.$custdisp.
429: '</span>';
430: }
431: $output .= ' <td'.$colspan.'>'.$custom_access.(' 'x4).
1.419 raeburn 432: $lt{'avai'}.': '.$currdisp.'</td>'."\n".
1.418 raeburn 433: &Apache::loncommon::end_data_table_row()."\n";
434: unless (&Apache::lonnet::allowed('udp',$ccdomain)) {
435: $output .=
1.275 raeburn 436: &Apache::loncommon::start_data_table_row()."\n".
1.306 raeburn 437: ' <td style="vertical-align:top;"><span class="LC_nobreak">'.
438: $lt{'chse'}.': <label>'.
1.275 raeburn 439: '<input type="radio" name="custom'.$item.'" value="0" '.
1.306 raeburn 440: $cust_off.'/>'.$lt{'usde'}.'</label>'.(' ' x3).
441: '<label><input type="radio" name="custom'.$item.'" value="1" '.
442: $cust_on.'/>'.$lt{'uscu'}.'</label>'.$custradio.'</td>'.
1.275 raeburn 443: &Apache::loncommon::end_data_table_row()."\n";
1.418 raeburn 444: }
1.275 raeburn 445: }
446: return $output;
447: }
448:
1.300 raeburn 449: sub coursereq_externaluser {
450: my ($ccuname,$ccdomain,$cdom) = @_;
1.306 raeburn 451: my (@usertools,@options,%validations,%userenv,$output);
1.300 raeburn 452: my %lt = &Apache::lonlocal::texthash (
453: 'official' => 'Can request creation of official courses',
454: 'unofficial' => 'Can request creation of unofficial courses',
455: 'community' => 'Can request creation of communities',
1.384 raeburn 456: 'textbook' => 'Can request creation of textbook courses',
1.411 raeburn 457: 'placement' => 'Can request creation of placement tests',
1.300 raeburn 458: );
459:
460: %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
461: 'reqcrsotherdom.official','reqcrsotherdom.unofficial',
1.411 raeburn 462: 'reqcrsotherdom.community','reqcrsotherdom.textbook',
463: 'reqcrsotherdom.placement');
464: @usertools = ('official','unofficial','community','textbook','placement');
1.309 raeburn 465: @options = ('approval','validate','autolimit');
1.306 raeburn 466: %validations = &Apache::lonnet::auto_courserequest_checks($cdom);
467: my $optregex = join('|',@options);
468: my %reqtitles = &courserequest_titles();
1.300 raeburn 469: foreach my $item (@usertools) {
1.306 raeburn 470: my ($curroption,$currlimit,$tooloff);
1.300 raeburn 471: if ($userenv{'reqcrsotherdom.'.$item} ne '') {
472: my @curr = split(',',$userenv{'reqcrsotherdom.'.$item});
1.314 raeburn 473: foreach my $req (@curr) {
474: if ($req =~ /^\Q$cdom\E\:($optregex)=?(\d*)$/) {
475: $curroption = $1;
476: $currlimit = $2;
477: last;
1.306 raeburn 478: }
479: }
1.314 raeburn 480: if (!$curroption) {
481: $curroption = 'norequest';
482: $tooloff = ' checked="checked"';
483: }
1.306 raeburn 484: } else {
485: $curroption = 'norequest';
486: $tooloff = ' checked="checked"';
487: }
488: $output.= &Apache::loncommon::start_data_table_row()."\n".
1.314 raeburn 489: ' <td><span class="LC_nobreak">'.$lt{$item}.': </span></td><td>'.
490: '<table><tr><td valign="top">'."\n".
1.306 raeburn 491: '<label><input type="radio" name="reqcrsotherdom_'.$item.
1.314 raeburn 492: '" value=""'.$tooloff.' />'.$reqtitles{'norequest'}.
493: '</label></td>';
1.306 raeburn 494: foreach my $option (@options) {
495: if ($option eq 'validate') {
496: my $canvalidate = 0;
497: if (ref($validations{$item}) eq 'HASH') {
498: if ($validations{$item}{'_external_'}) {
499: $canvalidate = 1;
500: }
501: }
502: next if (!$canvalidate);
503: }
504: my $checked = '';
505: if ($option eq $curroption) {
506: $checked = ' checked="checked"';
507: }
1.314 raeburn 508: $output .= '<td valign="top"><span class="LC_nobreak"><label>'.
1.306 raeburn 509: '<input type="radio" name="reqcrsotherdom_'.$item.
510: '" value="'.$option.'"'.$checked.' />'.
1.314 raeburn 511: $reqtitles{$option}.'</label>';
1.306 raeburn 512: if ($option eq 'autolimit') {
1.314 raeburn 513: $output .= ' <input type="text" name="reqcrsotherdom_'.
1.306 raeburn 514: $item.'_limit" size="1" '.
1.314 raeburn 515: 'value="'.$currlimit.'" /></span>'.
516: '<br />'.$reqtitles{'unlimited'};
517: } else {
518: $output .= '</span>';
1.300 raeburn 519: }
1.314 raeburn 520: $output .= '</td>';
1.300 raeburn 521: }
1.314 raeburn 522: $output .= '</td></tr></table></td>'."\n".
1.300 raeburn 523: &Apache::loncommon::end_data_table_row()."\n";
524: }
525: return $output;
526: }
527:
1.362 raeburn 528: sub domainrole_req {
529: my ($ccuname,$ccdomain) = @_;
530: return '<br /><h3>'.
531: &mt('User Can Request Assignment of Domain Roles?').
532: '</h3>'."\n".
533: &Apache::loncommon::start_data_table().
534: &build_tools_display($ccuname,$ccdomain,
535: 'requestauthor').
536: &Apache::loncommon::end_data_table();
537: }
538:
1.306 raeburn 539: sub courserequest_titles {
540: my %titles = &Apache::lonlocal::texthash (
541: official => 'Official',
542: unofficial => 'Unofficial',
543: community => 'Communities',
1.384 raeburn 544: textbook => 'Textbook',
1.411 raeburn 545: placement => 'Placement Tests',
1.306 raeburn 546: norequest => 'Not allowed',
1.309 raeburn 547: approval => 'Approval by Dom. Coord.',
1.306 raeburn 548: validate => 'With validation',
549: autolimit => 'Numerical limit',
1.314 raeburn 550: unlimited => '(blank for unlimited)',
1.306 raeburn 551: );
552: return %titles;
553: }
554:
555: sub courserequest_display {
556: my %titles = &Apache::lonlocal::texthash (
1.309 raeburn 557: approval => 'Yes, need approval',
1.306 raeburn 558: validate => 'Yes, with validation',
559: norequest => 'No',
560: );
561: return %titles;
562: }
563:
1.362 raeburn 564: sub requestauthor_titles {
565: my %titles = &Apache::lonlocal::texthash (
566: norequest => 'Not allowed',
567: approval => 'Approval by Dom. Coord.',
568: automatic => 'Automatic approval',
569: );
570: return %titles;
571:
572: }
573:
574: sub requestauthor_display {
575: my %titles = &Apache::lonlocal::texthash (
576: approval => 'Yes, need approval',
577: automatic => 'Yes, automatic approval',
578: norequest => 'No',
579: );
580: return %titles;
581: }
582:
1.383 raeburn 583: sub requestchange_display {
584: my %titles = &Apache::lonlocal::texthash (
585: approval => "availability set to 'on' (approval required)",
586: automatic => "availability set to 'on' (automatic approval)",
587: norequest => "availability set to 'off'",
588: );
589: return %titles;
590: }
591:
1.362 raeburn 592: sub curr_requestauthor {
593: my ($uname,$udom,$isadv,$inststatuses,$domconfig) = @_;
594: return unless ((ref($inststatuses) eq 'ARRAY') && (ref($domconfig) eq 'HASH'));
595: if ($uname eq '' || $udom eq '') {
596: $uname = $env{'user.name'};
597: $udom = $env{'user.domain'};
598: $isadv = $env{'user.adv'};
599: }
600: my (%userenv,%settings,$val);
601: my @options = ('automatic','approval');
602: %userenv =
603: &Apache::lonnet::userenvironment($udom,$uname,'requestauthor','inststatus');
604: if ($userenv{'requestauthor'}) {
605: $val = $userenv{'requestauthor'};
606: @{$inststatuses} = ('_custom_');
607: } else {
608: my %alltasks;
609: if (ref($domconfig->{'requestauthor'}) eq 'HASH') {
610: %settings = %{$domconfig->{'requestauthor'}};
611: if (($isadv) && ($settings{'_LC_adv'} ne '')) {
612: $val = $settings{'_LC_adv'};
613: @{$inststatuses} = ('_LC_adv_');
614: } else {
615: if ($userenv{'inststatus'} ne '') {
616: @{$inststatuses} = split(',',$userenv{'inststatus'});
617: } else {
618: @{$inststatuses} = ('default');
619: }
620: foreach my $status (@{$inststatuses}) {
621: if (exists($settings{$status})) {
622: my $value = $settings{$status};
623: next unless ($value);
624: unless (exists($alltasks{$value})) {
625: if (ref($alltasks{$value}) eq 'ARRAY') {
626: unless(grep(/^\Q$status\E$/,@{$alltasks{$value}})) {
627: push(@{$alltasks{$value}},$status);
628: }
629: } else {
630: @{$alltasks{$value}} = ($status);
631: }
632: }
633: }
634: }
635: foreach my $option (@options) {
636: if ($alltasks{$option}) {
637: $val = $option;
638: last;
639: }
640: }
641: }
642: }
643: }
644: return $val;
645: }
646:
1.2 www 647: # =================================================================== Phase one
1.1 www 648:
1.42 matthew 649: sub print_username_entry_form {
1.439 raeburn 650: my ($r,$context,$response,$srch,$forcenewuser,$crstype,$brcrum,
651: $permission) = @_;
1.101 albertel 652: my $defdom=$env{'request.role.domain'};
1.160 raeburn 653: my $formtoset = 'crtuser';
654: if (exists($env{'form.startrolename'})) {
655: $formtoset = 'docustom';
656: $env{'form.rolename'} = $env{'form.startrolename'};
1.207 raeburn 657: } elsif ($env{'form.origform'} eq 'crtusername') {
658: $formtoset = $env{'form.origform'};
1.160 raeburn 659: }
660:
661: my ($jsback,$elements) = &crumb_utilities();
662:
663: my $jscript = &Apache::loncommon::studentbrowser_javascript()."\n".
1.165 albertel 664: '<script type="text/javascript">'."\n".
1.301 bisitz 665: '// <![CDATA['."\n".
666: &Apache::lonhtmlcommon::set_form_elements($elements->{$formtoset})."\n".
667: '// ]]>'."\n".
1.162 raeburn 668: '</script>'."\n";
1.160 raeburn 669:
1.324 raeburn 670: my %existingroles=&Apache::lonuserutils::my_custom_roles($crstype);
671: if (($env{'form.action'} eq 'custom') && (keys(%existingroles) > 0)
672: && (&Apache::lonnet::allowed('mcr','/'))) {
673: $jscript .= &customrole_javascript();
674: }
1.224 raeburn 675: my $helpitem = 'Course_Change_Privileges';
676: if ($env{'form.action'} eq 'custom') {
1.439 raeburn 677: if ($context eq 'course') {
678: $helpitem = 'Course_Editing_Custom_Roles';
679: } elsif ($context eq 'domain') {
680: $helpitem = 'Domain_Editing_Custom_Roles';
681: }
1.224 raeburn 682: } elsif ($env{'form.action'} eq 'singlestudent') {
683: $helpitem = 'Course_Add_Student';
1.416 raeburn 684: } elsif ($env{'form.action'} eq 'accesslogs') {
685: $helpitem = 'Domain_User_Access_Logs';
1.439 raeburn 686: } elsif ($context eq 'author') {
687: $helpitem = 'Author_Change_Privileges';
688: } elsif ($context eq 'domain') {
689: if ($permission->{'cusr'}) {
690: $helpitem = 'Domain_Change_Privileges';
691: } elsif ($permission->{'view'}) {
692: $helpitem = 'Domain_View_Privileges';
693: } else {
694: undef($helpitem);
695: }
1.224 raeburn 696: }
1.422 raeburn 697: my %breadcrumb_text = &singleuser_breadcrumb($crstype,$context,$defdom);
1.351 raeburn 698: if ($env{'form.action'} eq 'custom') {
699: push(@{$brcrum},
700: {href=>"javascript:backPage(document.crtuser)",
701: text=>"Pick custom role",
702: help => $helpitem,}
703: );
704: } else {
705: push (@{$brcrum},
706: {href => "javascript:backPage(document.crtuser)",
707: text => $breadcrumb_text{'search'},
708: help => $helpitem,
709: faq => 282,
710: bug => 'Instructor Interface',}
711: );
712: }
713: my %loaditems = (
714: 'onload' => "javascript:setFormElements(document.$formtoset)",
715: );
716: my $args = {bread_crumbs => $brcrum,
717: bread_crumbs_component => 'User Management',
718: add_entries => \%loaditems,};
719: $r->print(&Apache::loncommon::start_page('User Management',$jscript,$args));
720:
1.71 sakharuk 721: my %lt=&Apache::lonlocal::texthash(
1.229 raeburn 722: 'srst' => 'Search for a user and enroll as a student',
1.318 raeburn 723: 'srme' => 'Search for a user and enroll as a member',
1.229 raeburn 724: 'srad' => 'Search for a user and modify/add user information or roles',
1.422 raeburn 725: 'srvu' => 'Search for a user and view user information and roles',
1.416 raeburn 726: 'srva' => 'Search for a user and view access log information',
1.71 sakharuk 727: 'usr' => "Username",
728: 'dom' => "Domain",
1.324 raeburn 729: 'ecrp' => "Define or Edit Custom Role",
730: 'nr' => "role name",
1.282 schafran 731: 'cre' => "Next",
1.71 sakharuk 732: );
1.351 raeburn 733:
1.214 raeburn 734: if ($env{'form.action'} eq 'custom') {
1.190 raeburn 735: if (&Apache::lonnet::allowed('mcr','/')) {
1.324 raeburn 736: my $newroletext = &mt('Define new custom role:');
737: $r->print('<form action="/adm/createuser" method="post" name="docustom">'.
738: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'.
739: '<input type="hidden" name="phase" value="selected_custom_edit" />'.
740: '<h3>'.$lt{'ecrp'}.'</h3>'.
741: &Apache::loncommon::start_data_table().
742: &Apache::loncommon::start_data_table_row().
743: '<td>');
744: if (keys(%existingroles) > 0) {
745: $r->print('<br /><label><input type="radio" name="customroleaction" value="new" checked="checked" onclick="setCustomFields();" /><b>'.$newroletext.'</b></label>');
746: } else {
747: $r->print('<br /><input type="hidden" name="customroleaction" value="new" /><b>'.$newroletext.'</b>');
748: }
749: $r->print('</td><td align="center">'.$lt{'nr'}.'<br /><input type="text" size="15" name="newrolename" onfocus="setCustomAction('."'new'".');" /></td>'.
750: &Apache::loncommon::end_data_table_row());
751: if (keys(%existingroles) > 0) {
752: $r->print(&Apache::loncommon::start_data_table_row().'<td><br />'.
753: '<label><input type="radio" name="customroleaction" value="edit" onclick="setCustomFields();"/><b>'.
754: &mt('View/Modify existing role:').'</b></label></td>'.
755: '<td align="center"><br />'.
756: '<select name="rolename" onchange="setCustomAction('."'edit'".');">'.
1.326 raeburn 757: '<option value="" selected="selected">'.
1.324 raeburn 758: &mt('Select'));
759: foreach my $role (sort(keys(%existingroles))) {
1.326 raeburn 760: $r->print('<option value="'.$role.'">'.$role.'</option>');
1.324 raeburn 761: }
762: $r->print('</select>'.
763: '</td>'.
764: &Apache::loncommon::end_data_table_row());
765: }
766: $r->print(&Apache::loncommon::end_data_table().'<p>'.
767: '<input name="customeditor" type="submit" value="'.
768: $lt{'cre'}.'" /></p>'.
769: '</form>');
1.190 raeburn 770: }
1.213 raeburn 771: } else {
1.229 raeburn 772: my $actiontext = $lt{'srad'};
1.436 raeburn 773: my $fixeddom;
1.213 raeburn 774: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 775: if ($crstype eq 'Community') {
776: $actiontext = $lt{'srme'};
777: } else {
778: $actiontext = $lt{'srst'};
779: }
1.416 raeburn 780: } elsif ($env{'form.action'} eq 'accesslogs') {
1.417 raeburn 781: $actiontext = $lt{'srva'};
1.436 raeburn 782: $fixeddom = 1;
1.422 raeburn 783: } elsif (($env{'form.action'} eq 'singleuser') &&
784: ($context eq 'domain') && (!&Apache::lonnet::allowed('mau',$defdom))) {
785: $actiontext = $lt{'srvu'};
1.439 raeburn 786: $fixeddom = 1;
1.213 raeburn 787: }
1.324 raeburn 788: $r->print("<h3>$actiontext</h3>");
1.213 raeburn 789: if ($env{'form.origform'} ne 'crtusername') {
1.415 raeburn 790: if ($response) {
791: $r->print("\n<div>$response</div>".
792: '<br clear="all" />');
793: }
1.213 raeburn 794: }
1.436 raeburn 795: $r->print(&entry_form($defdom,$srch,$forcenewuser,$context,$response,$crstype,$fixeddom));
1.107 www 796: }
1.110 albertel 797: }
798:
1.324 raeburn 799: sub customrole_javascript {
800: my $js = <<"END";
801: <script type="text/javascript">
802: // <![CDATA[
803:
804: function setCustomFields() {
805: if (document.docustom.customroleaction.length > 0) {
806: for (var i=0; i<document.docustom.customroleaction.length; i++) {
807: if (document.docustom.customroleaction[i].checked) {
808: if (document.docustom.customroleaction[i].value == 'new') {
809: document.docustom.rolename.selectedIndex = 0;
810: } else {
811: document.docustom.newrolename.value = '';
812: }
813: }
814: }
815: }
816: return;
817: }
818:
819: function setCustomAction(caller) {
820: if (document.docustom.customroleaction.length > 0) {
821: for (var i=0; i<document.docustom.customroleaction.length; i++) {
822: if (document.docustom.customroleaction[i].value == caller) {
823: document.docustom.customroleaction[i].checked = true;
824: }
825: }
826: }
827: setCustomFields();
828: return;
829: }
830:
831: // ]]>
832: </script>
833: END
834: return $js;
835: }
836:
1.160 raeburn 837: sub entry_form {
1.416 raeburn 838: my ($dom,$srch,$forcenewuser,$context,$responsemsg,$crstype,$fixeddom) = @_;
1.229 raeburn 839: my ($usertype,$inexact);
1.214 raeburn 840: if (ref($srch) eq 'HASH') {
841: if (($srch->{'srchin'} eq 'dom') &&
842: ($srch->{'srchby'} eq 'uname') &&
843: ($srch->{'srchtype'} eq 'exact') &&
844: ($srch->{'srchdomain'} ne '') &&
845: ($srch->{'srchterm'} ne '')) {
1.353 raeburn 846: my (%curr_rules,%got_rules);
1.214 raeburn 847: my ($rules,$ruleorder) =
848: &Apache::lonnet::inst_userrules($srch->{'srchdomain'},'username');
1.353 raeburn 849: $usertype = &Apache::lonuserutils::check_usertype($srch->{'srchdomain'},$srch->{'srchterm'},$rules,\%curr_rules,\%got_rules);
1.229 raeburn 850: } else {
851: $inexact = 1;
1.214 raeburn 852: }
1.207 raeburn 853: }
1.438 raeburn 854: my ($cancreate,$noinstd);
855: if ($env{'form.action'} eq 'accesslogs') {
856: $noinstd = 1;
857: } else {
858: $cancreate =
859: &Apache::lonuserutils::can_create_user($dom,$context,$usertype);
860: }
1.412 raeburn 861: my ($userpicker,$cansearch) =
1.179 raeburn 862: &Apache::loncommon::user_picker($dom,$srch,$forcenewuser,
1.438 raeburn 863: 'document.crtuser',$cancreate,$usertype,$context,$fixeddom,$noinstd);
1.160 raeburn 864: my $srchbutton = &mt('Search');
1.229 raeburn 865: if ($env{'form.action'} eq 'singlestudent') {
866: $srchbutton = &mt('Search and Enroll');
1.416 raeburn 867: } elsif ($env{'form.action'} eq 'accesslogs') {
868: $srchbutton = &mt('Search');
1.229 raeburn 869: } elsif ($cancreate && $responsemsg ne '' && $inexact) {
870: $srchbutton = &mt('Search or Add New User');
871: }
1.412 raeburn 872: my $output;
873: if ($cansearch) {
874: $output = <<"ENDBLOCK";
1.160 raeburn 875: <form action="/adm/createuser" method="post" name="crtuser">
1.190 raeburn 876: <input type="hidden" name="action" value="$env{'form.action'}" />
1.160 raeburn 877: <input type="hidden" name="phase" value="get_user_info" />
878: $userpicker
1.179 raeburn 879: <input name="userrole" type="button" value="$srchbutton" onclick="javascript:validateEntry(document.crtuser)" />
1.160 raeburn 880: </form>
1.207 raeburn 881: ENDBLOCK
1.412 raeburn 882: } else {
883: $output = '<p>'.$userpicker.'</p>';
884: }
1.422 raeburn 885: if (($env{'form.phase'} eq '') && ($env{'form.action'} ne 'accesslogs') &&
1.430 raeburn 886: (!(($env{'form.action'} eq 'singleuser') && ($context eq 'domain') &&
1.422 raeburn 887: (!&Apache::lonnet::allowed('mau',$env{'request.role.domain'}))))) {
1.207 raeburn 888: my $defdom=$env{'request.role.domain'};
889: my $domform = &Apache::loncommon::select_dom_form($defdom,'srchdomain');
890: my %lt=&Apache::lonlocal::texthash(
1.229 raeburn 891: 'enro' => 'Enroll one student',
1.318 raeburn 892: 'enrm' => 'Enroll one member',
1.229 raeburn 893: 'admo' => 'Add/modify a single user',
894: 'crea' => 'create new user if required',
895: 'uskn' => "username is known",
1.207 raeburn 896: 'crnu' => 'Create a new user',
897: 'usr' => 'Username',
898: 'dom' => 'in domain',
1.229 raeburn 899: 'enrl' => 'Enroll',
900: 'cram' => 'Create/Modify user',
1.207 raeburn 901: );
1.229 raeburn 902: my $sellink=&Apache::loncommon::selectstudent_link('crtusername','srchterm','srchdomain');
903: my ($title,$buttontext,$showresponse);
1.318 raeburn 904: if ($env{'form.action'} eq 'singlestudent') {
905: if ($crstype eq 'Community') {
906: $title = $lt{'enrm'};
907: } else {
908: $title = $lt{'enro'};
909: }
1.229 raeburn 910: $buttontext = $lt{'enrl'};
911: } else {
912: $title = $lt{'admo'};
913: $buttontext = $lt{'cram'};
914: }
915: if ($cancreate) {
916: $title .= ' <span class="LC_cusr_subheading">('.$lt{'crea'}.')</span>';
917: } else {
918: $title .= ' <span class="LC_cusr_subheading">('.$lt{'uskn'}.')</span>';
919: }
920: if ($env{'form.origform'} eq 'crtusername') {
921: $showresponse = $responsemsg;
922: }
1.207 raeburn 923: $output .= <<"ENDDOCUMENT";
1.229 raeburn 924: <br />
1.207 raeburn 925: <form action="/adm/createuser" method="post" name="crtusername">
926: <input type="hidden" name="action" value="$env{'form.action'}" />
927: <input type="hidden" name="phase" value="createnewuser" />
928: <input type="hidden" name="srchtype" value="exact" />
1.233 raeburn 929: <input type="hidden" name="srchby" value="uname" />
1.207 raeburn 930: <input type="hidden" name="srchin" value="dom" />
931: <input type="hidden" name="forcenewuser" value="1" />
932: <input type="hidden" name="origform" value="crtusername" />
1.229 raeburn 933: <h3>$title</h3>
934: $showresponse
1.207 raeburn 935: <table>
936: <tr>
937: <td>$lt{'usr'}:</td>
938: <td><input type="text" size="15" name="srchterm" /></td>
939: <td> $lt{'dom'}:</td><td>$domform</td>
1.229 raeburn 940: <td> $sellink </td>
941: <td> <input name="userrole" type="submit" value="$buttontext" /></td>
1.207 raeburn 942: </tr>
943: </table>
944: </form>
1.160 raeburn 945: ENDDOCUMENT
1.207 raeburn 946: }
1.160 raeburn 947: return $output;
948: }
1.110 albertel 949:
950: sub user_modification_js {
1.113 raeburn 951: my ($pjump_def,$dc_setcourse_code,$nondc_setsection_code,$groupslist)=@_;
952:
1.110 albertel 953: return <<END;
954: <script type="text/javascript" language="Javascript">
1.301 bisitz 955: // <![CDATA[
1.314 raeburn 956:
1.110 albertel 957: $pjump_def
958: $dc_setcourse_code
959:
960: function dateset() {
961: eval("document.cu."+document.cu.pres_marker.value+
962: ".value=document.cu.pres_value.value");
1.359 www 963: modalWindow.close();
1.110 albertel 964: }
965:
1.113 raeburn 966: $nondc_setsection_code
1.301 bisitz 967: // ]]>
1.110 albertel 968: </script>
969: END
1.2 www 970: }
971:
972: # =================================================================== Phase two
1.160 raeburn 973: sub print_user_selection_page {
1.351 raeburn 974: my ($r,$response,$srch,$srch_results,$srcharray,$context,$opener_elements,$crstype,$brcrum) = @_;
1.160 raeburn 975: my @fields = ('username','domain','lastname','firstname','permanentemail');
976: my $sortby = $env{'form.sortby'};
977:
978: if (!grep(/^\Q$sortby\E$/,@fields)) {
979: $sortby = 'lastname';
980: }
981:
982: my ($jsback,$elements) = &crumb_utilities();
983:
984: my $jscript = (<<ENDSCRIPT);
985: <script type="text/javascript">
1.301 bisitz 986: // <![CDATA[
1.160 raeburn 987: function pickuser(uname,udom) {
988: document.usersrchform.seluname.value=uname;
989: document.usersrchform.seludom.value=udom;
990: document.usersrchform.phase.value="userpicked";
991: document.usersrchform.submit();
992: }
993:
994: $jsback
1.301 bisitz 995: // ]]>
1.160 raeburn 996: </script>
997: ENDSCRIPT
998:
999: my %lt=&Apache::lonlocal::texthash(
1.179 raeburn 1000: 'usrch' => "User Search to add/modify roles",
1001: 'stusrch' => "User Search to enroll student",
1.318 raeburn 1002: 'memsrch' => "User Search to enroll member",
1.416 raeburn 1003: 'srcva' => "Search for a user and view access log information",
1.422 raeburn 1004: 'usrvu' => "User Search to view user roles",
1.179 raeburn 1005: 'usel' => "Select a user to add/modify roles",
1.422 raeburn 1006: 'suvr' => "Select a user to view roles",
1.318 raeburn 1007: 'stusel' => "Select a user to enroll as a student",
1008: 'memsel' => "Select a user to enroll as a member",
1.416 raeburn 1009: 'vacsel' => "Select a user to view access log",
1.160 raeburn 1010: 'username' => "username",
1011: 'domain' => "domain",
1012: 'lastname' => "last name",
1013: 'firstname' => "first name",
1014: 'permanentemail' => "permanent e-mail",
1015: );
1.302 raeburn 1016: if ($context eq 'requestcrs') {
1017: $r->print('<div>');
1018: } else {
1.422 raeburn 1019: my %breadcrumb_text = &singleuser_breadcrumb($crstype,$context,$srch->{'srchdomain'});
1.351 raeburn 1020: my $helpitem;
1021: if ($env{'form.action'} eq 'singleuser') {
1022: $helpitem = 'Course_Change_Privileges';
1023: } elsif ($env{'form.action'} eq 'singlestudent') {
1024: $helpitem = 'Course_Add_Student';
1.439 raeburn 1025: } elsif ($context eq 'author') {
1026: $helpitem = 'Author_Change_Privileges';
1027: } elsif ($context eq 'domain') {
1028: $helpitem = 'Domain_Change_Privileges';
1.351 raeburn 1029: }
1030: push (@{$brcrum},
1031: {href => "javascript:backPage(document.usersrchform,'','')",
1032: text => $breadcrumb_text{'search'},
1033: faq => 282,
1034: bug => 'Instructor Interface',},
1035: {href => "javascript:backPage(document.usersrchform,'get_user_info','select')",
1036: text => $breadcrumb_text{'userpicked'},
1037: faq => 282,
1038: bug => 'Instructor Interface',
1039: help => $helpitem}
1040: );
1041: $r->print(&Apache::loncommon::start_page('User Management',$jscript,{bread_crumbs => $brcrum}));
1.302 raeburn 1042: if ($env{'form.action'} eq 'singleuser') {
1.422 raeburn 1043: my $readonly;
1044: if (($context eq 'domain') && (!&Apache::lonnet::allowed('mau',$srch->{'srchdomain'}))) {
1045: $readonly = 1;
1046: $r->print("<b>$lt{'usrvu'}</b><br />");
1047: } else {
1048: $r->print("<b>$lt{'usrch'}</b><br />");
1049: }
1.318 raeburn 1050: $r->print(&entry_form($srch->{'srchdomain'},$srch,undef,$context,undef,$crstype));
1.422 raeburn 1051: if ($readonly) {
1052: $r->print('<h3>'.$lt{'suvr'}.'</h3>');
1053: } else {
1054: $r->print('<h3>'.$lt{'usel'}.'</h3>');
1055: }
1.302 raeburn 1056: } elsif ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1057: $r->print($jscript."<b>");
1058: if ($crstype eq 'Community') {
1059: $r->print($lt{'memsrch'});
1060: } else {
1061: $r->print($lt{'stusrch'});
1062: }
1063: $r->print("</b><br />");
1064: $r->print(&entry_form($srch->{'srchdomain'},$srch,undef,$context,undef,$crstype));
1065: $r->print('</form><h3>');
1066: if ($crstype eq 'Community') {
1067: $r->print($lt{'memsel'});
1068: } else {
1069: $r->print($lt{'stusel'});
1070: }
1071: $r->print('</h3>');
1.416 raeburn 1072: } elsif ($env{'form.action'} eq 'accesslogs') {
1073: $r->print("<b>$lt{'srcva'}</b><br />");
1.438 raeburn 1074: $r->print(&entry_form($srch->{'srchdomain'},$srch,undef,$context,undef,undef,1));
1.416 raeburn 1075: $r->print('<h3>'.$lt{'vacsel'}.'</h3>');
1.302 raeburn 1076: }
1.179 raeburn 1077: }
1.380 bisitz 1078: $r->print('<form name="usersrchform" method="post" action="">'.
1.160 raeburn 1079: &Apache::loncommon::start_data_table()."\n".
1080: &Apache::loncommon::start_data_table_header_row()."\n".
1081: ' <th> </th>'."\n");
1082: foreach my $field (@fields) {
1083: $r->print(' <th><a href="javascript:document.usersrchform.sortby.value='.
1084: "'".$field."'".';document.usersrchform.submit();">'.
1085: $lt{$field}.'</a></th>'."\n");
1086: }
1087: $r->print(&Apache::loncommon::end_data_table_header_row());
1088:
1089: my @sorted_users = sort {
1.167 albertel 1090: lc($srch_results->{$a}->{$sortby}) cmp lc($srch_results->{$b}->{$sortby})
1.160 raeburn 1091: ||
1.167 albertel 1092: lc($srch_results->{$a}->{lastname}) cmp lc($srch_results->{$b}->{lastname})
1.160 raeburn 1093: ||
1094: lc($srch_results->{$a}->{firstname}) cmp lc($srch_results->{$b}->{firstname})
1.167 albertel 1095: ||
1096: lc($a) cmp lc($b)
1.160 raeburn 1097: } (keys(%$srch_results));
1098:
1099: foreach my $user (@sorted_users) {
1100: my ($uname,$udom) = split(/:/,$user);
1.302 raeburn 1101: my $onclick;
1102: if ($context eq 'requestcrs') {
1.314 raeburn 1103: $onclick =
1.302 raeburn 1104: 'onclick="javascript:gochoose('."'$uname','$udom',".
1105: "'$srch_results->{$user}->{firstname}',".
1106: "'$srch_results->{$user}->{lastname}',".
1107: "'$srch_results->{$user}->{permanentemail}'".');"';
1108: } else {
1.314 raeburn 1109: $onclick =
1.302 raeburn 1110: ' onclick="javascript:pickuser('."'".$uname."'".','."'".$udom."'".');"';
1111: }
1.160 raeburn 1112: $r->print(&Apache::loncommon::start_data_table_row().
1.302 raeburn 1113: '<td><input type="button" name="seluser" value="'.&mt('Select').'" '.
1114: $onclick.' /></td>'.
1.160 raeburn 1115: '<td><tt>'.$uname.'</tt></td>'.
1116: '<td><tt>'.$udom.'</tt></td>');
1117: foreach my $field ('lastname','firstname','permanentemail') {
1118: $r->print('<td>'.$srch_results->{$user}->{$field}.'</td>');
1119: }
1120: $r->print(&Apache::loncommon::end_data_table_row());
1121: }
1122: $r->print(&Apache::loncommon::end_data_table().'<br /><br />');
1.179 raeburn 1123: if (ref($srcharray) eq 'ARRAY') {
1124: foreach my $item (@{$srcharray}) {
1125: $r->print('<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n");
1126: }
1127: }
1.160 raeburn 1128: $r->print(' <input type="hidden" name="sortby" value="'.$sortby.'" />'."\n".
1129: ' <input type="hidden" name="seluname" value="" />'."\n".
1130: ' <input type="hidden" name="seludom" value="" />'."\n".
1.179 raeburn 1131: ' <input type="hidden" name="currstate" value="select" />'."\n".
1.190 raeburn 1132: ' <input type="hidden" name="phase" value="get_user_info" />'."\n".
1.214 raeburn 1133: ' <input type="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n");
1.302 raeburn 1134: if ($context eq 'requestcrs') {
1135: $r->print($opener_elements.'</form></div>');
1136: } else {
1.351 raeburn 1137: $r->print($response.'</form>');
1.302 raeburn 1138: }
1.160 raeburn 1139: }
1140:
1141: sub print_user_query_page {
1.351 raeburn 1142: my ($r,$caller,$brcrum) = @_;
1.160 raeburn 1143: # FIXME - this is for a network-wide name search (similar to catalog search)
1144: # To use frames with similar behavior to catalog/portfolio search.
1145: # To be implemented.
1146: return;
1147: }
1148:
1.42 matthew 1149: sub print_user_modification_page {
1.375 raeburn 1150: my ($r,$ccuname,$ccdomain,$srch,$response,$context,$permission,$crstype,
1151: $brcrum,$showcredits) = @_;
1.185 raeburn 1152: if (($ccuname eq '') || ($ccdomain eq '')) {
1.215 raeburn 1153: my $usermsg = &mt('No username and/or domain provided.');
1154: $env{'form.phase'} = '';
1.439 raeburn 1155: &print_username_entry_form($r,$context,$usermsg,'','',$crstype,$brcrum,
1156: $permission);
1.58 www 1157: return;
1158: }
1.213 raeburn 1159: my ($form,$formname);
1160: if ($env{'form.action'} eq 'singlestudent') {
1161: $form = 'document.enrollstudent';
1162: $formname = 'enrollstudent';
1163: } else {
1164: $form = 'document.cu';
1165: $formname = 'cu';
1166: }
1.188 raeburn 1167: my %abv_auth = &auth_abbrev();
1.227 raeburn 1168: my (%rulematch,%inst_results,$newuser,%alerts,%curr_rules,%got_rules);
1.185 raeburn 1169: my $uhome=&Apache::lonnet::homeserver($ccuname,$ccdomain);
1170: if ($uhome eq 'no_host') {
1.215 raeburn 1171: my $usertype;
1172: my ($rules,$ruleorder) =
1173: &Apache::lonnet::inst_userrules($ccdomain,'username');
1174: $usertype =
1.353 raeburn 1175: &Apache::lonuserutils::check_usertype($ccdomain,$ccuname,$rules,
1.362 raeburn 1176: \%curr_rules,\%got_rules);
1.215 raeburn 1177: my $cancreate =
1178: &Apache::lonuserutils::can_create_user($ccdomain,$context,
1179: $usertype);
1180: if (!$cancreate) {
1.292 bisitz 1181: my $helplink = 'javascript:helpMenu('."'display'".')';
1.215 raeburn 1182: my %usertypetext = (
1183: official => 'institutional',
1184: unofficial => 'non-institutional',
1185: );
1186: my $response;
1187: if ($env{'form.origform'} eq 'crtusername') {
1.362 raeburn 1188: $response = '<span class="LC_warning">'.
1189: &mt('No match found for the username [_1] in LON-CAPA domain: [_2]',
1190: '<b>'.$ccuname.'</b>',$ccdomain).
1.215 raeburn 1191: '</span><br />';
1192: }
1.292 bisitz 1193: $response .= '<p class="LC_warning">'
1194: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
1.418 raeburn 1195: .' ';
1196: if ($context eq 'domain') {
1197: $response .= &mt('Please contact a [_1] for assistance.',
1198: &Apache::lonnet::plaintext('dc'));
1199: } else {
1200: $response .= &mt('Please contact the [_1]helpdesk[_2] for assistance.'
1201: ,'<a href="'.$helplink.'">','</a>');
1202: }
1203: $response .= '</p><br />';
1.215 raeburn 1204: $env{'form.phase'} = '';
1.439 raeburn 1205: &print_username_entry_form($r,$context,$response,undef,undef,$crstype,$brcrum,
1206: $permission);
1.215 raeburn 1207: return;
1208: }
1.188 raeburn 1209: $newuser = 1;
1.193 raeburn 1210: my $checkhash;
1211: my $checks = { 'username' => 1 };
1.196 raeburn 1212: $checkhash->{$ccuname.':'.$ccdomain} = { 'newuser' => $newuser };
1.193 raeburn 1213: &Apache::loncommon::user_rule_check($checkhash,$checks,
1.196 raeburn 1214: \%alerts,\%rulematch,\%inst_results,\%curr_rules,\%got_rules);
1215: if (ref($alerts{'username'}) eq 'HASH') {
1216: if (ref($alerts{'username'}{$ccdomain}) eq 'HASH') {
1217: my $domdesc =
1.193 raeburn 1218: &Apache::lonnet::domain($ccdomain,'description');
1.196 raeburn 1219: if ($alerts{'username'}{$ccdomain}{$ccuname}) {
1220: my $userchkmsg;
1221: if (ref($curr_rules{$ccdomain}) eq 'HASH') {
1222: $userchkmsg =
1223: &Apache::loncommon::instrule_disallow_msg('username',
1.193 raeburn 1224: $domdesc,1).
1225: &Apache::loncommon::user_rule_formats($ccdomain,
1226: $domdesc,$curr_rules{$ccdomain}{'username'},
1227: 'username');
1.196 raeburn 1228: }
1.215 raeburn 1229: $env{'form.phase'} = '';
1.439 raeburn 1230: &print_username_entry_form($r,$context,$userchkmsg,undef,undef,$crstype,$brcrum,
1231: $permission);
1.196 raeburn 1232: return;
1.215 raeburn 1233: }
1.193 raeburn 1234: }
1.185 raeburn 1235: }
1.187 raeburn 1236: } else {
1.188 raeburn 1237: $newuser = 0;
1.185 raeburn 1238: }
1.160 raeburn 1239: if ($response) {
1.215 raeburn 1240: $response = '<br />'.$response;
1.160 raeburn 1241: }
1.149 raeburn 1242:
1.52 matthew 1243: my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
1.88 raeburn 1244: my $dc_setcourse_code = '';
1.119 raeburn 1245: my $nondc_setsection_code = '';
1.112 albertel 1246: my %loaditem;
1.114 albertel 1247:
1.216 raeburn 1248: my $groupslist = &Apache::lonuserutils::get_groupslist();
1.88 raeburn 1249:
1.375 raeburn 1250: my $js = &validation_javascript($context,$ccdomain,$pjump_def,$crstype,
1.216 raeburn 1251: $groupslist,$newuser,$formname,\%loaditem);
1.422 raeburn 1252: my %breadcrumb_text = &singleuser_breadcrumb($crstype,$context,$ccdomain);
1.224 raeburn 1253: my $helpitem = 'Course_Change_Privileges';
1254: if ($env{'form.action'} eq 'singlestudent') {
1255: $helpitem = 'Course_Add_Student';
1.439 raeburn 1256: } elsif ($context eq 'author') {
1257: $helpitem = 'Author_Change_Privileges';
1258: } elsif ($context eq 'domain') {
1259: $helpitem = 'Domain_Change_Privileges';
1.224 raeburn 1260: }
1.351 raeburn 1261: push (@{$brcrum},
1262: {href => "javascript:backPage($form)",
1263: text => $breadcrumb_text{'search'},
1264: faq => 282,
1265: bug => 'Instructor Interface',});
1266: if ($env{'form.phase'} eq 'userpicked') {
1267: push(@{$brcrum},
1268: {href => "javascript:backPage($form,'get_user_info','select')",
1269: text => $breadcrumb_text{'userpicked'},
1270: faq => 282,
1271: bug => 'Instructor Interface',});
1272: }
1273: push(@{$brcrum},
1274: {href => "javascript:backPage($form,'$env{'form.phase'}','modify')",
1275: text => $breadcrumb_text{'modify'},
1276: faq => 282,
1277: bug => 'Instructor Interface',
1278: help => $helpitem});
1279: my $args = {'add_entries' => \%loaditem,
1280: 'bread_crumbs' => $brcrum,
1281: 'bread_crumbs_component' => 'User Management'};
1282: if ($env{'form.popup'}) {
1283: $args->{'no_nav_bar'} = 1;
1284: }
1285: my $start_page =
1286: &Apache::loncommon::start_page('User Management',$js,$args);
1.3 www 1287:
1.25 matthew 1288: my $forminfo =<<"ENDFORMINFO";
1.216 raeburn 1289: <form action="/adm/createuser" method="post" name="$formname">
1.190 raeburn 1290: <input type="hidden" name="phase" value="update_user_data" />
1.188 raeburn 1291: <input type="hidden" name="ccuname" value="$ccuname" />
1292: <input type="hidden" name="ccdomain" value="$ccdomain" />
1.157 albertel 1293: <input type="hidden" name="pres_value" value="" />
1294: <input type="hidden" name="pres_type" value="" />
1295: <input type="hidden" name="pres_marker" value="" />
1.25 matthew 1296: ENDFORMINFO
1.375 raeburn 1297: my (%inccourses,$roledom,$defaultcredits);
1.329 raeburn 1298: if ($context eq 'course') {
1299: $inccourses{$env{'request.course.id'}}=1;
1300: $roledom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1.375 raeburn 1301: if ($showcredits) {
1302: $defaultcredits = &Apache::lonuserutils::get_defaultcredits();
1303: }
1.329 raeburn 1304: } elsif ($context eq 'author') {
1305: $roledom = $env{'request.role.domain'};
1306: } elsif ($context eq 'domain') {
1307: foreach my $key (keys(%env)) {
1308: $roledom = $env{'request.role.domain'};
1309: if ($key=~/^user\.priv\.cm\.\/($roledom)\/($match_username)/) {
1310: $inccourses{$1.'_'.$2}=1;
1311: }
1312: }
1313: } else {
1314: foreach my $key (keys(%env)) {
1315: if ($key=~/^user\.priv\.cm\.\/($match_domain)\/($match_username)/) {
1316: $inccourses{$1.'_'.$2}=1;
1317: }
1.2 www 1318: }
1.24 matthew 1319: }
1.389 bisitz 1320: my $title = '';
1.216 raeburn 1321: if ($newuser) {
1.427 raeburn 1322: my ($portfolioform,$domroleform);
1.267 raeburn 1323: if ((&Apache::lonnet::allowed('mpq',$env{'request.role.domain'})) ||
1324: (&Apache::lonnet::allowed('mut',$env{'request.role.domain'}))) {
1325: # Current user has quota or user tools modification privileges
1.378 raeburn 1326: $portfolioform = '<br />'.&user_quotas($ccuname,$ccdomain);
1.134 raeburn 1327: }
1.383 raeburn 1328: if ((&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) &&
1329: ($ccdomain eq $env{'request.role.domain'})) {
1.362 raeburn 1330: $domroleform = '<br />'.&domainrole_req($ccuname,$ccdomain);
1331: }
1.227 raeburn 1332: &initialize_authen_forms($ccdomain,$formname);
1.188 raeburn 1333: my %lt=&Apache::lonlocal::texthash(
1334: 'lg' => 'Login Data',
1.190 raeburn 1335: 'hs' => "Home Server",
1.188 raeburn 1336: );
1.185 raeburn 1337: $r->print(<<ENDTITLE);
1.110 albertel 1338: $start_page
1.160 raeburn 1339: $response
1.25 matthew 1340: $forminfo
1.31 matthew 1341: <script type="text/javascript" language="Javascript">
1.301 bisitz 1342: // <![CDATA[
1.20 harris41 1343: $loginscript
1.301 bisitz 1344: // ]]>
1.31 matthew 1345: </script>
1.20 harris41 1346: <input type='hidden' name='makeuser' value='1' />
1.185 raeburn 1347: ENDTITLE
1.213 raeburn 1348: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1349: if ($crstype eq 'Community') {
1.389 bisitz 1350: $title = &mt('Create New User [_1] in domain [_2] as a member',
1351: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.318 raeburn 1352: } else {
1.389 bisitz 1353: $title = &mt('Create New User [_1] in domain [_2] as a student',
1354: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.318 raeburn 1355: }
1.389 bisitz 1356: } else {
1357: $title = &mt('Create New User [_1] in domain [_2]',
1358: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.213 raeburn 1359: }
1.389 bisitz 1360: $r->print('<h2>'.$title.'</h2>'."\n");
1361: $r->print('<div class="LC_left_float">');
1.393 raeburn 1362: $r->print(&personal_data_display($ccuname,$ccdomain,$newuser,$context,
1363: $inst_results{$ccuname.':'.$ccdomain}));
1364: # Option to disable student/employee ID conflict checking not offerred for new users.
1.187 raeburn 1365: my ($home_server_pick,$numlib) =
1366: &Apache::loncommon::home_server_form_item($ccdomain,'hserver',
1367: 'default','hide');
1368: if ($numlib > 1) {
1369: $r->print("
1.185 raeburn 1370: <br />
1.187 raeburn 1371: $lt{'hs'}: $home_server_pick
1372: <br />");
1373: } else {
1374: $r->print($home_server_pick);
1375: }
1.304 raeburn 1376: if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
1.362 raeburn 1377: $r->print('<br /><h3>'.
1378: &mt('User Can Request Creation of Courses/Communities in this Domain?').'</h3>'.
1.304 raeburn 1379: &Apache::loncommon::start_data_table().
1380: &build_tools_display($ccuname,$ccdomain,
1381: 'requestcourses').
1382: &Apache::loncommon::end_data_table());
1383: }
1.188 raeburn 1384: $r->print('</div>'."\n".'<div class="LC_left_float"><h3>'.
1385: $lt{'lg'}.'</h3>');
1.185 raeburn 1386: my ($fixedauth,$varauth,$authmsg);
1.193 raeburn 1387: if (ref($rulematch{$ccuname.':'.$ccdomain}) eq 'HASH') {
1388: my $matchedrule = $rulematch{$ccuname.':'.$ccdomain}{'username'};
1389: my ($rules,$ruleorder) =
1390: &Apache::lonnet::inst_userrules($ccdomain,'username');
1.185 raeburn 1391: if (ref($rules) eq 'HASH') {
1.193 raeburn 1392: if (ref($rules->{$matchedrule}) eq 'HASH') {
1393: my $authtype = $rules->{$matchedrule}{'authtype'};
1.185 raeburn 1394: if ($authtype !~ /^(krb4|krb5|int|fsys|loc)$/) {
1.190 raeburn 1395: $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1.275 raeburn 1396: } else {
1.193 raeburn 1397: my $authparm = $rules->{$matchedrule}{'authparm'};
1.273 raeburn 1398: $authmsg = $rules->{$matchedrule}{'authmsg'};
1.185 raeburn 1399: if ($authtype =~ /^krb(4|5)$/) {
1400: my $ver = $1;
1401: if ($authparm ne '') {
1402: $fixedauth = <<"KERB";
1403: <input type="hidden" name="login" value="krb" />
1404: <input type="hidden" name="krbver" value="$ver" />
1405: <input type="hidden" name="krbarg" value="$authparm" />
1406: KERB
1407: }
1408: } else {
1409: $fixedauth =
1410: '<input type="hidden" name="login" value="'.$authtype.'" />'."\n";
1.193 raeburn 1411: if ($rules->{$matchedrule}{'authparmfixed'}) {
1.185 raeburn 1412: $fixedauth .=
1413: '<input type="hidden" name="'.$authtype.'arg" value="'.$authparm.'" />'."\n";
1414: } else {
1.273 raeburn 1415: if ($authtype eq 'int') {
1416: $varauth = '<br />'.
1.301 bisitz 1417: &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 1418: } elsif ($authtype eq 'loc') {
1419: $varauth = '<br />'.
1420: &mt('[_1] Local Authentication with argument [_2]','','<input type="text" name="'.$authtype.'arg" value="" />')."\n";
1421: } else {
1422: $varauth =
1.185 raeburn 1423: '<input type="text" name="'.$authtype.'arg" value="" />'."\n";
1.273 raeburn 1424: }
1.185 raeburn 1425: }
1426: }
1427: }
1428: } else {
1.190 raeburn 1429: $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1.185 raeburn 1430: }
1431: }
1432: if ($authmsg) {
1433: $r->print(<<ENDAUTH);
1434: $fixedauth
1435: $authmsg
1436: $varauth
1437: ENDAUTH
1438: }
1439: } else {
1.190 raeburn 1440: $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1.187 raeburn 1441: }
1.427 raeburn 1442: $r->print($portfolioform.$domroleform);
1.215 raeburn 1443: if ($env{'form.action'} eq 'singlestudent') {
1444: $r->print(&date_sections_select($context,$newuser,$formname,
1.375 raeburn 1445: $permission,$crstype,$ccuname,
1446: $ccdomain,$showcredits));
1.215 raeburn 1447: }
1448: $r->print('</div><div class="LC_clear_float_footer"></div>');
1.216 raeburn 1449: } else { # user already exists
1.389 bisitz 1450: $r->print($start_page.$forminfo);
1.213 raeburn 1451: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1452: if ($crstype eq 'Community') {
1.389 bisitz 1453: $title = &mt('Enroll one member: [_1] in domain [_2]',
1454: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.318 raeburn 1455: } else {
1.389 bisitz 1456: $title = &mt('Enroll one student: [_1] in domain [_2]',
1457: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.318 raeburn 1458: }
1.213 raeburn 1459: } else {
1.418 raeburn 1460: if ($permission->{'cusr'}) {
1461: $title = &mt('Modify existing user: [_1] in domain [_2]',
1462: '"'.$ccuname.'"','"'.$ccdomain.'"');
1463: } else {
1464: $title = &mt('Existing user: [_1] in domain [_2]',
1.389 bisitz 1465: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.418 raeburn 1466: }
1.213 raeburn 1467: }
1.389 bisitz 1468: $r->print('<h2>'.$title.'</h2>'."\n");
1469: $r->print('<div class="LC_left_float">');
1.393 raeburn 1470: $r->print(&personal_data_display($ccuname,$ccdomain,$newuser,$context,
1471: $inst_results{$ccuname.':'.$ccdomain}));
1.430 raeburn 1472: if ((&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) ||
1.418 raeburn 1473: (&Apache::lonnet::allowed('udp',$env{'request.role.domain'}))) {
1.362 raeburn 1474: $r->print('<br /><h3>'.&mt('User Can Request Creation of Courses/Communities in this Domain?').'</h3>'.
1.300 raeburn 1475: &Apache::loncommon::start_data_table());
1.314 raeburn 1476: if ($env{'request.role.domain'} eq $ccdomain) {
1.300 raeburn 1477: $r->print(&build_tools_display($ccuname,$ccdomain,'requestcourses'));
1478: } else {
1479: $r->print(&coursereq_externaluser($ccuname,$ccdomain,
1480: $env{'request.role.domain'}));
1481: }
1482: $r->print(&Apache::loncommon::end_data_table());
1.275 raeburn 1483: }
1.199 raeburn 1484: $r->print('</div>');
1.427 raeburn 1485: my @order = ('auth','quota','tools','requestauthor');
1.362 raeburn 1486: my %user_text;
1487: my ($isadv,$isauthor) =
1.418 raeburn 1488: &Apache::lonnet::is_advanced_user($ccdomain,$ccuname);
1.362 raeburn 1489: if ((!$isauthor) &&
1.418 raeburn 1490: ((&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) ||
1491: (&Apache::lonnet::allowed('udp',$env{'request.role.domain'}))) &&
1.430 raeburn 1492: ($env{'request.role.domain'} eq $ccdomain)) {
1.362 raeburn 1493: $user_text{'requestauthor'} = &domainrole_req($ccuname,$ccdomain);
1494: }
1495: $user_text{'auth'} = &user_authentication($ccuname,$ccdomain,$formname);
1.267 raeburn 1496: if ((&Apache::lonnet::allowed('mpq',$ccdomain)) ||
1.418 raeburn 1497: (&Apache::lonnet::allowed('mut',$ccdomain)) ||
1498: (&Apache::lonnet::allowed('udp',$ccdomain))) {
1.188 raeburn 1499: # Current user has quota modification privileges
1.378 raeburn 1500: $user_text{'quota'} = &user_quotas($ccuname,$ccdomain);
1.267 raeburn 1501: }
1502: if (!&Apache::lonnet::allowed('mpq',$ccdomain)) {
1503: if (&Apache::lonnet::allowed('mpq',$env{'request.role.domain'})) {
1504: my %lt=&Apache::lonlocal::texthash(
1.385 bisitz 1505: 'dska' => "Disk quotas for user's portfolio and Authoring Space",
1506: 'youd' => "You do not have privileges to modify the portfolio and/or Authoring Space quotas for this user.",
1.267 raeburn 1507: 'ichr' => "If a change is required, contact a domain coordinator for the domain",
1508: );
1.362 raeburn 1509: $user_text{'quota'} = <<ENDNOPORTPRIV;
1.188 raeburn 1510: <h3>$lt{'dska'}</h3>
1511: $lt{'youd'} $lt{'ichr'}: $ccdomain
1512: ENDNOPORTPRIV
1.267 raeburn 1513: }
1514: }
1515: if (!&Apache::lonnet::allowed('mut',$ccdomain)) {
1516: if (&Apache::lonnet::allowed('mut',$env{'request.role.domain'})) {
1517: my %lt=&Apache::lonlocal::texthash(
1518: 'utav' => "User Tools Availability",
1.361 raeburn 1519: 'yodo' => "You do not have privileges to modify Portfolio, Blog, WebDAV, or Personal Information Page settings for this user.",
1.267 raeburn 1520: 'ifch' => "If a change is required, contact a domain coordinator for the domain",
1521: );
1.362 raeburn 1522: $user_text{'tools'} = <<ENDNOTOOLSPRIV;
1.267 raeburn 1523: <h3>$lt{'utav'}</h3>
1524: $lt{'yodo'} $lt{'ifch'}: $ccdomain
1525: ENDNOTOOLSPRIV
1526: }
1.188 raeburn 1527: }
1.362 raeburn 1528: my $gotdiv = 0;
1529: foreach my $item (@order) {
1530: if ($user_text{$item} ne '') {
1531: unless ($gotdiv) {
1532: $r->print('<div class="LC_left_float">');
1533: $gotdiv = 1;
1534: }
1535: $r->print('<br />'.$user_text{$item});
1536: }
1537: }
1538: if ($env{'form.action'} eq 'singlestudent') {
1539: unless ($gotdiv) {
1540: $r->print('<div class="LC_left_float">');
1.213 raeburn 1541: }
1.375 raeburn 1542: my $credits;
1543: if ($showcredits) {
1544: $credits = &get_user_credits($ccuname,$ccdomain,$defaultcredits);
1545: if ($credits eq '') {
1546: $credits = $defaultcredits;
1547: }
1548: }
1.374 raeburn 1549: $r->print(&date_sections_select($context,$newuser,$formname,
1.375 raeburn 1550: $permission,$crstype,$ccuname,
1551: $ccdomain,$showcredits));
1.374 raeburn 1552: }
1.362 raeburn 1553: if ($gotdiv) {
1554: $r->print('</div><div class="LC_clear_float_footer"></div>');
1.188 raeburn 1555: }
1.418 raeburn 1556: my $statuses;
1557: if (($context eq 'domain') && (&Apache::lonnet::allowed('udp',$ccdomain)) &&
1558: (!&Apache::lonnet::allowed('mau',$ccdomain))) {
1559: $statuses = ['active'];
1560: } elsif (($context eq 'course') && ((&Apache::lonnet::allowed('vcl',$env{'request.course.id'})) ||
1561: ($env{'request.course.sec'} &&
1562: &Apache::lonnet::allowed('vcl',$env{'request.course.id'}.'/'.$env{'request.course.sec'})))) {
1.430 raeburn 1563: $statuses = ['active'];
1.418 raeburn 1564: }
1.217 raeburn 1565: if ($env{'form.action'} ne 'singlestudent') {
1.329 raeburn 1566: &display_existing_roles($r,$ccuname,$ccdomain,\%inccourses,$context,
1.418 raeburn 1567: $roledom,$crstype,$showcredits,$statuses);
1.217 raeburn 1568: }
1.25 matthew 1569: } ## End of new user/old user logic
1.218 raeburn 1570: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1571: my $btntxt;
1572: if ($crstype eq 'Community') {
1573: $btntxt = &mt('Enroll Member');
1574: } else {
1575: $btntxt = &mt('Enroll Student');
1576: }
1577: $r->print('<br /><input type="button" value="'.$btntxt.'" onclick="setSections(this.form)" />'."\n");
1.418 raeburn 1578: } elsif ($permission->{'cusr'}) {
1.393 raeburn 1579: $r->print('<div class="LC_left_float">'.
1580: '<fieldset><legend>'.&mt('Add Roles').'</legend>');
1.218 raeburn 1581: my $addrolesdisplay = 0;
1582: if ($context eq 'domain' || $context eq 'author') {
1583: $addrolesdisplay = &new_coauthor_roles($r,$ccuname,$ccdomain);
1584: }
1585: if ($context eq 'domain') {
1.357 raeburn 1586: my $add_domainroles = &new_domain_roles($r,$ccdomain);
1.218 raeburn 1587: if (!$addrolesdisplay) {
1588: $addrolesdisplay = $add_domainroles;
1.2 www 1589: }
1.375 raeburn 1590: $r->print(&course_level_dc($env{'request.role.domain'},$showcredits));
1.393 raeburn 1591: $r->print('</fieldset></div><div class="LC_clear_float_footer"></div>'.
1592: '<br /><input type="button" value="'.&mt('Save').'" onclick="setCourse()" />'."\n");
1.218 raeburn 1593: } elsif ($context eq 'author') {
1594: if ($addrolesdisplay) {
1.393 raeburn 1595: $r->print('</fieldset></div><div class="LC_clear_float_footer"></div>'.
1596: '<br /><input type="button" value="'.&mt('Save').'"');
1.218 raeburn 1597: if ($newuser) {
1.301 bisitz 1598: $r->print(' onclick="auth_check()" \>'."\n");
1.218 raeburn 1599: } else {
1.301 bisitz 1600: $r->print('onclick="this.form.submit()" \>'."\n");
1.218 raeburn 1601: }
1.188 raeburn 1602: } else {
1.393 raeburn 1603: $r->print('</fieldset></div>'.
1604: '<div class="LC_clear_float_footer"></div>'.
1605: '<br /><a href="javascript:backPage(document.cu)">'.
1.218 raeburn 1606: &mt('Back to previous page').'</a>');
1.188 raeburn 1607: }
1608: } else {
1.375 raeburn 1609: $r->print(&course_level_table(\%inccourses,$showcredits,$defaultcredits));
1.393 raeburn 1610: $r->print('</fieldset></div><div class="LC_clear_float_footer"></div>'.
1611: '<br /><input type="button" value="'.&mt('Save').'" onclick="setSections(this.form)" />'."\n");
1.188 raeburn 1612: }
1.88 raeburn 1613: }
1.188 raeburn 1614: $r->print(&Apache::lonhtmlcommon::echo_form_input(['phase','userrole','ccdomain','prevphase','currstate','ccuname','ccdomain']));
1.179 raeburn 1615: $r->print('<input type="hidden" name="currstate" value="" />');
1.393 raeburn 1616: $r->print('<input type="hidden" name="prevphase" value="'.$env{'form.phase'}.'" /></form><br /><br />');
1.218 raeburn 1617: return;
1.2 www 1618: }
1.1 www 1619:
1.213 raeburn 1620: sub singleuser_breadcrumb {
1.422 raeburn 1621: my ($crstype,$context,$domain) = @_;
1.213 raeburn 1622: my %breadcrumb_text;
1623: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1624: if ($crstype eq 'Community') {
1625: $breadcrumb_text{'search'} = 'Enroll a member';
1626: } else {
1627: $breadcrumb_text{'search'} = 'Enroll a student';
1628: }
1.422 raeburn 1629: $breadcrumb_text{'userpicked'} = 'Select a user';
1630: $breadcrumb_text{'modify'} = 'Set section/dates';
1.416 raeburn 1631: } elsif ($env{'form.action'} eq 'accesslogs') {
1632: $breadcrumb_text{'search'} = 'View access logs for a user';
1.422 raeburn 1633: $breadcrumb_text{'userpicked'} = 'Select a user';
1634: $breadcrumb_text{'activity'} = 'Activity';
1635: } elsif (($env{'form.action'} eq 'singleuser') && ($context eq 'domain') &&
1636: (!&Apache::lonnet::allowed('mau',$domain))) {
1637: $breadcrumb_text{'search'} = "View user's roles";
1638: $breadcrumb_text{'userpicked'} = 'Select a user';
1639: $breadcrumb_text{'modify'} = 'User roles';
1.213 raeburn 1640: } else {
1.229 raeburn 1641: $breadcrumb_text{'search'} = 'Create/modify a user';
1.422 raeburn 1642: $breadcrumb_text{'userpicked'} = 'Select a user';
1643: $breadcrumb_text{'modify'} = 'Set user role';
1.213 raeburn 1644: }
1645: return %breadcrumb_text;
1646: }
1647:
1648: sub date_sections_select {
1.375 raeburn 1649: my ($context,$newuser,$formname,$permission,$crstype,$ccuname,$ccdomain,
1650: $showcredits) = @_;
1651: my $credits;
1652: if ($showcredits) {
1653: my $defaultcredits = &Apache::lonuserutils::get_defaultcredits();
1654: $credits = &get_user_credits($ccuname,$ccdomain,$defaultcredits);
1655: if ($credits eq '') {
1656: $credits = $defaultcredits;
1657: }
1658: }
1.213 raeburn 1659: my $cid = $env{'request.course.id'};
1660: my ($cnum,$cdom) = &Apache::lonuserutils::get_course_identity($cid);
1661: my $date_table = '<h3>'.&mt('Starting and Ending Dates').'</h3>'."\n".
1662: &Apache::lonuserutils::date_setting_table(undef,undef,$context,
1663: undef,$formname,$permission);
1664: my $rowtitle = 'Section';
1.375 raeburn 1665: my $secbox = '<h3>'.&mt('Section and Credits').'</h3>'."\n".
1.213 raeburn 1666: &Apache::lonuserutils::section_picker($cdom,$cnum,'st',$rowtitle,
1.375 raeburn 1667: $permission,$context,'',$crstype,
1668: $showcredits,$credits);
1.213 raeburn 1669: my $output = $date_table.$secbox;
1670: return $output;
1671: }
1672:
1.216 raeburn 1673: sub validation_javascript {
1.375 raeburn 1674: my ($context,$ccdomain,$pjump_def,$crstype,$groupslist,$newuser,$formname,
1.216 raeburn 1675: $loaditem) = @_;
1676: my $dc_setcourse_code = '';
1677: my $nondc_setsection_code = '';
1678: if ($context eq 'domain') {
1679: my $dcdom = $env{'request.role.domain'};
1680: $loaditem->{'onload'} = "document.cu.coursedesc.value='';";
1.227 raeburn 1681: $dc_setcourse_code =
1682: &Apache::lonuserutils::dc_setcourse_js('cu','singleuser',$context);
1.216 raeburn 1683: } else {
1.227 raeburn 1684: my $checkauth;
1685: if (($newuser) || (&Apache::lonnet::allowed('mau',$ccdomain))) {
1686: $checkauth = 1;
1687: }
1688: if ($context eq 'course') {
1689: $nondc_setsection_code =
1690: &Apache::lonuserutils::setsections_javascript($formname,$groupslist,
1.375 raeburn 1691: undef,$checkauth,
1692: $crstype);
1.227 raeburn 1693: }
1694: if ($checkauth) {
1695: $nondc_setsection_code .=
1696: &Apache::lonuserutils::verify_authen($formname,$context);
1697: }
1.216 raeburn 1698: }
1699: my $js = &user_modification_js($pjump_def,$dc_setcourse_code,
1700: $nondc_setsection_code,$groupslist);
1701: my ($jsback,$elements) = &crumb_utilities();
1702: $js .= "\n".
1.301 bisitz 1703: '<script type="text/javascript">'."\n".
1704: '// <![CDATA['."\n".
1705: $jsback."\n".
1706: '// ]]>'."\n".
1707: '</script>'."\n";
1.216 raeburn 1708: return $js;
1709: }
1710:
1.217 raeburn 1711: sub display_existing_roles {
1.375 raeburn 1712: my ($r,$ccuname,$ccdomain,$inccourses,$context,$roledom,$crstype,
1.418 raeburn 1713: $showcredits,$statuses) = @_;
1.329 raeburn 1714: my $now=time;
1.418 raeburn 1715: my $showall = 1;
1716: my ($showexpired,$showactive);
1717: if ((ref($statuses) eq 'ARRAY') && (@{$statuses} > 0)) {
1718: $showall = 0;
1719: if (grep(/^expired$/,@{$statuses})) {
1720: $showexpired = 1;
1721: }
1722: if (grep(/^active$/,@{$statuses})) {
1723: $showactive = 1;
1724: }
1725: if ($showexpired && $showactive) {
1726: $showall = 1;
1727: }
1728: }
1.329 raeburn 1729: my %lt=&Apache::lonlocal::texthash(
1.217 raeburn 1730: 'rer' => "Existing Roles",
1731: 'rev' => "Revoke",
1732: 'del' => "Delete",
1733: 'ren' => "Re-Enable",
1734: 'rol' => "Role",
1735: 'ext' => "Extent",
1.375 raeburn 1736: 'crd' => "Credits",
1.217 raeburn 1737: 'sta' => "Start",
1738: 'end' => "End",
1739: );
1.329 raeburn 1740: my (%rolesdump,%roletext,%sortrole,%roleclass,%rolepriv);
1741: if ($context eq 'course' || $context eq 'author') {
1742: my @roles = &Apache::lonuserutils::roles_by_context($context,1,$crstype);
1743: my %roleshash =
1744: &Apache::lonnet::get_my_roles($ccuname,$ccdomain,'userroles',
1745: ['active','previous','future'],\@roles,$roledom,1);
1746: foreach my $key (keys(%roleshash)) {
1747: my ($start,$end) = split(':',$roleshash{$key});
1748: next if ($start eq '-1' || $end eq '-1');
1749: my ($rnum,$rdom,$role,$sec) = split(':',$key);
1750: if ($context eq 'course') {
1751: next unless (($rnum eq $env{'course.'.$env{'request.course.id'}.'.num'})
1752: && ($rdom eq $env{'course.'.$env{'request.course.id'}.'.domain'}));
1753: } elsif ($context eq 'author') {
1754: next unless (($rnum eq $env{'user.name'}) && ($rdom eq $env{'request.role.domain'}));
1755: }
1756: my ($newkey,$newvalue,$newrole);
1757: $newkey = '/'.$rdom.'/'.$rnum;
1758: if ($sec ne '') {
1759: $newkey .= '/'.$sec;
1760: }
1761: $newvalue = $role;
1762: if ($role =~ /^cr/) {
1763: $newrole = 'cr';
1764: } else {
1765: $newrole = $role;
1766: }
1767: $newkey .= '_'.$newrole;
1768: if ($start ne '' && $end ne '') {
1769: $newvalue .= '_'.$end.'_'.$start;
1.335 raeburn 1770: } elsif ($end ne '') {
1771: $newvalue .= '_'.$end;
1.329 raeburn 1772: }
1773: $rolesdump{$newkey} = $newvalue;
1774: }
1775: } else {
1.360 raeburn 1776: %rolesdump=&Apache::lonnet::dump('roles',$ccdomain,$ccuname);
1.329 raeburn 1777: }
1778: # Build up table of user roles to allow revocation and re-enabling of roles.
1779: my ($tmp) = keys(%rolesdump);
1780: return if ($tmp =~ /^(con_lost|error)/i);
1781: foreach my $area (sort { my $a1=join('_',(split('_',$a))[1,0]);
1782: my $b1=join('_',(split('_',$b))[1,0]);
1783: return $a1 cmp $b1;
1784: } keys(%rolesdump)) {
1785: next if ($area =~ /^rolesdef/);
1786: my $envkey=$area;
1787: my $role = $rolesdump{$area};
1788: my $thisrole=$area;
1789: $area =~ s/\_\w\w$//;
1790: my ($role_code,$role_end_time,$role_start_time) =
1791: split(/_/,$role);
1.418 raeburn 1792: my $active=1;
1793: $active=0 if (($role_end_time) && ($now>$role_end_time));
1794: if ($active) {
1795: next unless($showall || $showactive);
1796: } else {
1.430 raeburn 1797: next unless($showall || $showexpired);
1.418 raeburn 1798: }
1.217 raeburn 1799: # Is this a custom role? Get role owner and title.
1.329 raeburn 1800: my ($croleudom,$croleuname,$croletitle)=
1801: ($role_code=~m{^cr/($match_domain)/($match_username)/(\w+)$});
1802: my $allowed=0;
1803: my $delallowed=0;
1804: my $sortkey=$role_code;
1805: my $class='Unknown';
1.375 raeburn 1806: my $credits='';
1.418 raeburn 1807: my $csec;
1.421 raeburn 1808: if ($area =~ m{^/($match_domain)/($match_courseid)}) {
1.329 raeburn 1809: $class='Course';
1810: my ($coursedom,$coursedir) = ($1,$2);
1811: my $cid = $1.'_'.$2;
1812: # $1.'_'.$2 is the course id (eg. 103_12345abcef103l3).
1.421 raeburn 1813: next if ($envkey =~ m{^/$match_domain/$match_courseid/[A-Za-z0-9]+_gr$});
1.329 raeburn 1814: my %coursedata=
1815: &Apache::lonnet::coursedescription($cid);
1816: if ($coursedir =~ /^$match_community$/) {
1817: $class='Community';
1818: }
1819: $sortkey.="\0$coursedom";
1820: my $carea;
1821: if (defined($coursedata{'description'})) {
1822: $carea=$coursedata{'description'}.
1823: '<br />'.&mt('Domain').': '.$coursedom.(' 'x8).
1824: &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$coursedir,$coursedom);
1825: $sortkey.="\0".$coursedata{'description'};
1826: } else {
1827: if ($class eq 'Community') {
1828: $carea=&mt('Unavailable community').': '.$area;
1829: $sortkey.="\0".&mt('Unavailable community').': '.$area;
1.217 raeburn 1830: } else {
1831: $carea=&mt('Unavailable course').': '.$area;
1832: $sortkey.="\0".&mt('Unavailable course').': '.$area;
1833: }
1.329 raeburn 1834: }
1835: $sortkey.="\0$coursedir";
1836: $inccourses->{$cid}=1;
1.375 raeburn 1837: if (($showcredits) && ($class eq 'Course') && ($role_code eq 'st')) {
1838: my $defaultcredits = $coursedata{'internal.defaultcredits'};
1839: $credits =
1840: &get_user_credits($ccuname,$ccdomain,$defaultcredits,
1841: $coursedom,$coursedir);
1842: if ($credits eq '') {
1843: $credits = $defaultcredits;
1844: }
1845: }
1.329 raeburn 1846: if ((&Apache::lonnet::allowed('c'.$role_code,$coursedom.'/'.$coursedir)) ||
1847: (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) {
1848: $allowed=1;
1849: }
1850: unless ($allowed) {
1.365 raeburn 1851: my $isowner = &Apache::lonuserutils::is_courseowner($cid,$coursedata{'internal.courseowner'});
1.329 raeburn 1852: if ($isowner) {
1853: if (($role_code eq 'co') && ($class eq 'Community')) {
1854: $allowed = 1;
1855: } elsif (($role_code eq 'cc') && ($class eq 'Course')) {
1856: $allowed = 1;
1857: }
1.217 raeburn 1858: }
1.329 raeburn 1859: }
1860: if ((&Apache::lonnet::allowed('dro',$coursedom)) ||
1861: (&Apache::lonnet::allowed('dro',$ccdomain))) {
1862: $delallowed=1;
1863: }
1.217 raeburn 1864: # - custom role. Needs more info, too
1.329 raeburn 1865: if ($croletitle) {
1866: if (&Apache::lonnet::allowed('ccr',$coursedom.'/'.$coursedir)) {
1867: $allowed=1;
1868: $thisrole.='.'.$role_code;
1.217 raeburn 1869: }
1.329 raeburn 1870: }
1.418 raeburn 1871: if ($area=~m{^/($match_domain/$match_courseid/(\w+))}) {
1872: $csec = $2;
1873: $carea.='<br />'.&mt('Section: [_1]',$csec);
1874: $sortkey.="\0$csec";
1.329 raeburn 1875: if (!$allowed) {
1.418 raeburn 1876: if ($env{'request.course.sec'} eq $csec) {
1877: if (&Apache::lonnet::allowed('c'.$role_code,$1)) {
1.329 raeburn 1878: $allowed = 1;
1.217 raeburn 1879: }
1880: }
1881: }
1.329 raeburn 1882: }
1883: $area=$carea;
1884: } else {
1885: $sortkey.="\0".$area;
1886: # Determine if current user is able to revoke privileges
1887: if ($area=~m{^/($match_domain)/}) {
1888: if ((&Apache::lonnet::allowed('c'.$role_code,$1)) ||
1889: (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) {
1890: $allowed=1;
1.217 raeburn 1891: }
1.329 raeburn 1892: if (((&Apache::lonnet::allowed('dro',$1)) ||
1893: (&Apache::lonnet::allowed('dro',$ccdomain))) &&
1894: ($role_code ne 'dc')) {
1895: $delallowed=1;
1.217 raeburn 1896: }
1.329 raeburn 1897: } else {
1898: if (&Apache::lonnet::allowed('c'.$role_code,'/')) {
1.217 raeburn 1899: $allowed=1;
1900: }
1901: }
1.363 raeburn 1902: if ($role_code eq 'ca' || $role_code eq 'au' || $role_code eq 'aa') {
1.377 raeburn 1903: $class='Authoring Space';
1.329 raeburn 1904: } elsif ($role_code eq 'su') {
1905: $class='System';
1.217 raeburn 1906: } else {
1.329 raeburn 1907: $class='Domain';
1.217 raeburn 1908: }
1.329 raeburn 1909: }
1910: if (($role_code eq 'ca') || ($role_code eq 'aa')) {
1911: $area=~m{/($match_domain)/($match_username)};
1912: if (&Apache::lonuserutils::authorpriv($2,$1)) {
1913: $allowed=1;
1.217 raeburn 1914: } else {
1.329 raeburn 1915: $allowed=0;
1.217 raeburn 1916: }
1.329 raeburn 1917: }
1918: my $row = '';
1.418 raeburn 1919: if ($showall) {
1920: $row.= '<td>';
1921: if (($active) && ($allowed)) {
1922: $row.= '<input type="checkbox" name="rev:'.$thisrole.'" />';
1923: } else {
1924: if ($active) {
1925: $row.=' ';
1926: } else {
1927: $row.=&mt('expired or revoked');
1928: }
1929: }
1930: $row.='</td><td>';
1931: if ($allowed && !$active) {
1932: $row.= '<input type="checkbox" name="ren:'.$thisrole.'" />';
1933: } else {
1934: $row.=' ';
1935: }
1936: $row.='</td><td>';
1937: if ($delallowed) {
1938: $row.= '<input type="checkbox" name="del:'.$thisrole.'" />';
1.217 raeburn 1939: } else {
1.418 raeburn 1940: $row.=' ';
1.217 raeburn 1941: }
1.430 raeburn 1942: $row.= '</td>';
1.329 raeburn 1943: }
1944: my $plaintext='';
1945: if (!$croletitle) {
1.375 raeburn 1946: $plaintext=&Apache::lonnet::plaintext($role_code,$class);
1947: if (($showcredits) && ($credits ne '')) {
1948: $plaintext .= '<br/ ><span class="LC_nobreak">'.
1949: '<span class="LC_fontsize_small">'.
1950: &mt('Credits: [_1]',$credits).
1951: '</span></span>';
1952: }
1.329 raeburn 1953: } else {
1954: $plaintext=
1.395 bisitz 1955: &mt('Custom role [_1][_2]defined by [_3]',
1.346 bisitz 1956: '"'.$croletitle.'"',
1957: '<br />',
1958: $croleuname.':'.$croleudom);
1.329 raeburn 1959: }
1.418 raeburn 1960: $row.= '<td>'.$plaintext.'</td>'.
1961: '<td>'.$area.'</td>'.
1962: '<td>'.($role_start_time?&Apache::lonlocal::locallocaltime($role_start_time)
1963: : ' ' ).'</td>'.
1964: '<td>'.($role_end_time ?&Apache::lonlocal::locallocaltime($role_end_time)
1965: : ' ' ).'</td>';
1.329 raeburn 1966: $sortrole{$sortkey}=$envkey;
1967: $roletext{$envkey}=$row;
1968: $roleclass{$envkey}=$class;
1.418 raeburn 1969: if ($allowed) {
1970: $rolepriv{$envkey}='edit';
1971: } else {
1972: if ($context eq 'domain') {
1.420 raeburn 1973: if ((&Apache::lonnet::allowed('vur',$ccdomain)) &&
1.421 raeburn 1974: ($envkey=~m{^/$ccdomain/})) {
1.418 raeburn 1975: $rolepriv{$envkey}='view';
1976: }
1977: } elsif ($context eq 'course') {
1978: if ((&Apache::lonnet::allowed('vcl',$env{'request.course.id'})) ||
1979: ($env{'request.course.sec'} && ($env{'request.course.sec'} eq $csec) &&
1980: &Apache::lonnet::allowed('vcl',$env{'request.course.id'}.'/'.$env{'request.course.sec'}))) {
1981: $rolepriv{$envkey}='view';
1982: }
1983: }
1984: }
1.329 raeburn 1985: } # end of foreach (table building loop)
1986:
1987: my $rolesdisplay = 0;
1988: my %output = ();
1.377 raeburn 1989: foreach my $type ('Authoring Space','Course','Community','Domain','System','Unknown') {
1.329 raeburn 1990: $output{$type} = '';
1991: foreach my $which (sort {uc($a) cmp uc($b)} (keys(%sortrole))) {
1992: if ( ($roleclass{$sortrole{$which}} =~ /^\Q$type\E/ ) && ($rolepriv{$sortrole{$which}}) ) {
1993: $output{$type}.=
1994: &Apache::loncommon::start_data_table_row().
1995: $roletext{$sortrole{$which}}.
1996: &Apache::loncommon::end_data_table_row();
1.217 raeburn 1997: }
1.329 raeburn 1998: }
1999: unless($output{$type} eq '') {
2000: $output{$type} = '<tr class="LC_info_row">'.
2001: "<td align='center' colspan='7'>".&mt($type)."</td></tr>".
2002: $output{$type};
2003: $rolesdisplay = 1;
2004: }
2005: }
2006: if ($rolesdisplay == 1) {
2007: my $contextrole='';
2008: if ($env{'request.course.id'}) {
2009: if (&Apache::loncommon::course_type() eq 'Community') {
2010: $contextrole = &mt('Existing Roles in this Community');
1.290 bisitz 2011: } else {
1.329 raeburn 2012: $contextrole = &mt('Existing Roles in this Course');
1.290 bisitz 2013: }
1.329 raeburn 2014: } elsif ($env{'request.role'} =~ /^au\./) {
1.377 raeburn 2015: $contextrole = &mt('Existing Co-Author Roles in your Authoring Space');
1.329 raeburn 2016: } else {
1.418 raeburn 2017: if ($showall) {
2018: $contextrole = &mt('Existing Roles in this Domain');
2019: } elsif ($showactive) {
2020: $contextrole = &mt('Unexpired Roles in this Domain');
2021: } elsif ($showexpired) {
2022: $contextrole = &mt('Expired or Revoked Roles in this Domain');
2023: }
1.329 raeburn 2024: }
1.393 raeburn 2025: $r->print('<div class="LC_left_float">'.
1.375 raeburn 2026: '<fieldset><legend>'.$contextrole.'</legend>'.
1.217 raeburn 2027: &Apache::loncommon::start_data_table("LC_createuser").
1.418 raeburn 2028: &Apache::loncommon::start_data_table_header_row());
2029: if ($showall) {
2030: $r->print(
1.419 raeburn 2031: '<th>'.$lt{'rev'}.'</th><th>'.$lt{'ren'}.'</th><th>'.$lt{'del'}.'</th>'
1.418 raeburn 2032: );
2033: } elsif ($showexpired) {
2034: $r->print('<th>'.$lt{'rev'}.'</th>');
2035: }
2036: $r->print(
1.419 raeburn 2037: '<th>'.$lt{'rol'}.'</th><th>'.$lt{'ext'}.'</th>'.
2038: '<th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'.
1.217 raeburn 2039: &Apache::loncommon::end_data_table_header_row());
1.377 raeburn 2040: foreach my $type ('Authoring Space','Course','Community','Domain','System','Unknown') {
1.329 raeburn 2041: if ($output{$type}) {
2042: $r->print($output{$type}."\n");
1.217 raeburn 2043: }
2044: }
1.375 raeburn 2045: $r->print(&Apache::loncommon::end_data_table().
2046: '</fieldset></div>');
1.329 raeburn 2047: }
1.217 raeburn 2048: return;
2049: }
2050:
1.218 raeburn 2051: sub new_coauthor_roles {
2052: my ($r,$ccuname,$ccdomain) = @_;
2053: my $addrolesdisplay = 0;
2054: #
2055: # Co-Author
2056: #
2057: if (&Apache::lonuserutils::authorpriv($env{'user.name'},
2058: $env{'request.role.domain'}) &&
2059: ($env{'user.name'} ne $ccuname || $env{'user.domain'} ne $ccdomain)) {
2060: # No sense in assigning co-author role to yourself
2061: $addrolesdisplay = 1;
2062: my $cuname=$env{'user.name'};
2063: my $cudom=$env{'request.role.domain'};
2064: my %lt=&Apache::lonlocal::texthash(
1.377 raeburn 2065: 'cs' => "Authoring Space",
1.218 raeburn 2066: 'act' => "Activate",
2067: 'rol' => "Role",
2068: 'ext' => "Extent",
2069: 'sta' => "Start",
2070: 'end' => "End",
2071: 'cau' => "Co-Author",
2072: 'caa' => "Assistant Co-Author",
2073: 'ssd' => "Set Start Date",
2074: 'sed' => "Set End Date"
2075: );
2076: $r->print('<h4>'.$lt{'cs'}.'</h4>'."\n".
2077: &Apache::loncommon::start_data_table()."\n".
2078: &Apache::loncommon::start_data_table_header_row()."\n".
2079: '<th>'.$lt{'act'}.'</th><th>'.$lt{'rol'}.'</th>'.
2080: '<th>'.$lt{'ext'}.'</th><th>'.$lt{'sta'}.'</th>'.
2081: '<th>'.$lt{'end'}.'</th>'."\n".
2082: &Apache::loncommon::end_data_table_header_row()."\n".
2083: &Apache::loncommon::start_data_table_row().'
2084: <td>
1.291 bisitz 2085: <input type="checkbox" name="act_'.$cudom.'_'.$cuname.'_ca" />
1.218 raeburn 2086: </td>
2087: <td>'.$lt{'cau'}.'</td>
2088: <td>'.$cudom.'_'.$cuname.'</td>
2089: <td><input type="hidden" name="start_'.$cudom.'_'.$cuname.'_ca" value="" />
2090: <a href=
2091: "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>
2092: <td><input type="hidden" name="end_'.$cudom.'_'.$cuname.'_ca" value="" />
2093: <a href=
2094: "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".
2095: &Apache::loncommon::end_data_table_row()."\n".
2096: &Apache::loncommon::start_data_table_row()."\n".
1.291 bisitz 2097: '<td><input type="checkbox" name="act_'.$cudom.'_'.$cuname.'_aa" /></td>
1.218 raeburn 2098: <td>'.$lt{'caa'}.'</td>
2099: <td>'.$cudom.'_'.$cuname.'</td>
2100: <td><input type="hidden" name="start_'.$cudom.'_'.$cuname.'_aa" value="" />
2101: <a href=
2102: "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>
2103: <td><input type="hidden" name="end_'.$cudom.'_'.$cuname.'_aa" value="" />
2104: <a href=
2105: "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".
2106: &Apache::loncommon::end_data_table_row()."\n".
2107: &Apache::loncommon::end_data_table());
2108: } elsif ($env{'request.role'} =~ /^au\./) {
2109: if (!(&Apache::lonuserutils::authorpriv($env{'user.name'},
2110: $env{'request.role.domain'}))) {
2111: $r->print('<span class="LC_error">'.
2112: &mt('You do not have privileges to assign co-author roles.').
2113: '</span>');
2114: } elsif (($env{'user.name'} eq $ccuname) &&
2115: ($env{'user.domain'} eq $ccdomain)) {
1.377 raeburn 2116: $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 2117: }
2118: }
2119: return $addrolesdisplay;;
2120: }
2121:
2122: sub new_domain_roles {
1.357 raeburn 2123: my ($r,$ccdomain) = @_;
1.218 raeburn 2124: my $addrolesdisplay = 0;
2125: #
2126: # Domain level
2127: #
2128: my $num_domain_level = 0;
2129: my $domaintext =
2130: '<h4>'.&mt('Domain Level').'</h4>'.
2131: &Apache::loncommon::start_data_table().
2132: &Apache::loncommon::start_data_table_header_row().
2133: '<th>'.&mt('Activate').'</th><th>'.&mt('Role').'</th><th>'.
2134: &mt('Extent').'</th>'.
2135: '<th>'.&mt('Start').'</th><th>'.&mt('End').'</th>'.
2136: &Apache::loncommon::end_data_table_header_row();
1.312 raeburn 2137: my @allroles = &Apache::lonuserutils::roles_by_context('domain');
1.218 raeburn 2138: foreach my $thisdomain (sort(&Apache::lonnet::all_domains())) {
1.312 raeburn 2139: foreach my $role (@allroles) {
2140: next if ($role eq 'ad');
1.357 raeburn 2141: next if (($role eq 'au') && ($ccdomain ne $thisdomain));
1.218 raeburn 2142: if (&Apache::lonnet::allowed('c'.$role,$thisdomain)) {
2143: my $plrole=&Apache::lonnet::plaintext($role);
2144: my %lt=&Apache::lonlocal::texthash(
2145: 'ssd' => "Set Start Date",
2146: 'sed' => "Set End Date"
2147: );
2148: $num_domain_level ++;
2149: $domaintext .=
2150: &Apache::loncommon::start_data_table_row().
1.291 bisitz 2151: '<td><input type="checkbox" name="act_'.$thisdomain.'_'.$role.'" /></td>
1.218 raeburn 2152: <td>'.$plrole.'</td>
2153: <td>'.$thisdomain.'</td>
2154: <td><input type="hidden" name="start_'.$thisdomain.'_'.$role.'" value="" />
2155: <a href=
2156: "javascript:pjump('."'date_start','Start Date $plrole',document.cu.start_$thisdomain\_$role.value,'start_$thisdomain\_$role','cu.pres','dateset'".')">'.$lt{'ssd'}.'</a></td>
2157: <td><input type="hidden" name="end_'.$thisdomain.'_'.$role.'" value="" />
2158: <a href=
2159: "javascript:pjump('."'date_end','End Date $plrole',document.cu.end_$thisdomain\_$role.value,'end_$thisdomain\_$role','cu.pres','dateset'".')">'.$lt{'sed'}.'</a></td>'.
2160: &Apache::loncommon::end_data_table_row();
2161: }
2162: }
2163: }
2164: $domaintext.= &Apache::loncommon::end_data_table();
2165: if ($num_domain_level > 0) {
2166: $r->print($domaintext);
2167: $addrolesdisplay = 1;
2168: }
2169: return $addrolesdisplay;
2170: }
2171:
1.188 raeburn 2172: sub user_authentication {
1.227 raeburn 2173: my ($ccuname,$ccdomain,$formname) = @_;
1.188 raeburn 2174: my $currentauth=&Apache::lonnet::queryauthenticate($ccuname,$ccdomain);
1.227 raeburn 2175: my $outcome;
1.418 raeburn 2176: my %lt=&Apache::lonlocal::texthash(
2177: 'err' => "ERROR",
2178: 'uuas' => "This user has an unrecognized authentication scheme",
2179: 'adcs' => "Please alert a domain coordinator of this situation",
2180: 'sldb' => "Please specify login data below",
2181: 'ld' => "Login Data"
2182: );
1.188 raeburn 2183: # Check for a bad authentication type
2184: if ($currentauth !~ /^(krb4|krb5|unix|internal|localauth):/) {
2185: # bad authentication scheme
2186: if (&Apache::lonnet::allowed('mau',$ccdomain)) {
1.227 raeburn 2187: &initialize_authen_forms($ccdomain,$formname);
2188:
1.190 raeburn 2189: my $choices = &Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc);
1.188 raeburn 2190: $outcome = <<ENDBADAUTH;
2191: <script type="text/javascript" language="Javascript">
1.301 bisitz 2192: // <![CDATA[
1.188 raeburn 2193: $loginscript
1.301 bisitz 2194: // ]]>
1.188 raeburn 2195: </script>
2196: <span class="LC_error">$lt{'err'}:
2197: $lt{'uuas'} ($currentauth). $lt{'sldb'}.</span>
2198: <h3>$lt{'ld'}</h3>
2199: $choices
2200: ENDBADAUTH
2201: } else {
2202: # This user is not allowed to modify the user's
2203: # authentication scheme, so just notify them of the problem
2204: $outcome = <<ENDBADAUTH;
2205: <span class="LC_error"> $lt{'err'}:
2206: $lt{'uuas'} ($currentauth). $lt{'adcs'}.
2207: </span>
2208: ENDBADAUTH
2209: }
2210: } else { # Authentication type is valid
1.418 raeburn 2211:
1.227 raeburn 2212: &initialize_authen_forms($ccdomain,$formname,$currentauth,'modifyuser');
1.205 raeburn 2213: my ($authformcurrent,$can_modify,@authform_others) =
1.188 raeburn 2214: &modify_login_block($ccdomain,$currentauth);
2215: if (&Apache::lonnet::allowed('mau',$ccdomain)) {
2216: # Current user has login modification privileges
2217: $outcome =
2218: '<script type="text/javascript" language="Javascript">'."\n".
1.301 bisitz 2219: '// <![CDATA['."\n".
1.188 raeburn 2220: $loginscript."\n".
1.301 bisitz 2221: '// ]]>'."\n".
1.188 raeburn 2222: '</script>'."\n".
2223: '<h3>'.$lt{'ld'}.'</h3>'.
2224: &Apache::loncommon::start_data_table().
1.205 raeburn 2225: &Apache::loncommon::start_data_table_row().
1.188 raeburn 2226: '<td>'.$authformnop;
1.418 raeburn 2227: if (($can_modify) && (&Apache::lonnet::allowed('mau',$ccdomain))) {
1.188 raeburn 2228: $outcome .= '</td>'."\n".
2229: &Apache::loncommon::end_data_table_row().
2230: &Apache::loncommon::start_data_table_row().
2231: '<td>'.$authformcurrent.'</td>'.
2232: &Apache::loncommon::end_data_table_row()."\n";
2233: } else {
1.200 raeburn 2234: $outcome .= ' ('.$authformcurrent.')</td>'.
2235: &Apache::loncommon::end_data_table_row()."\n";
1.188 raeburn 2236: }
1.418 raeburn 2237: if (&Apache::lonnet::allowed('mau',$ccdomain)) {
2238: foreach my $item (@authform_others) {
2239: $outcome .= &Apache::loncommon::start_data_table_row().
2240: '<td>'.$item.'</td>'.
2241: &Apache::loncommon::end_data_table_row()."\n";
2242: }
1.188 raeburn 2243: }
1.205 raeburn 2244: $outcome .= &Apache::loncommon::end_data_table();
1.188 raeburn 2245: } else {
1.418 raeburn 2246: if (&Apache::lonnet::allowed('udp',$ccdomain)) {
2247: # Current user has rights to view domain preferences for user's domain
2248: my $result;
2249: if ($currentauth =~ /^krb(4|5):([^:]*)$/) {
2250: my ($krbver,$krbrealm) = ($1,$2);
2251: if ($krbrealm eq '') {
2252: $result = &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
2253: } else {
2254: $result = &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
1.426 raeburn 2255: $krbrealm,$krbver);
1.418 raeburn 2256: }
2257: } elsif ($currentauth =~ /^internal:/) {
2258: $result = &mt('Currently internally authenticated.');
2259: } elsif ($currentauth =~ /^localauth:/) {
2260: $result = &mt('Currently using local (institutional) authentication.');
2261: } elsif ($currentauth =~ /^unix:/) {
2262: $result = &mt('Currently Filesystem Authenticated.');
2263: }
2264: $outcome = '<h3>'.$lt{'ld'}.'</h3>'.
2265: &Apache::loncommon::start_data_table().
2266: &Apache::loncommon::start_data_table_row().
2267: '<td>'.$result.'</td>'.
2268: &Apache::loncommon::end_data_table_row()."\n".
2269: &Apache::loncommon::end_data_table();
2270: } elsif (&Apache::lonnet::allowed('mau',$env{'request.role.domain'})) {
1.188 raeburn 2271: my %lt=&Apache::lonlocal::texthash(
2272: 'ccld' => "Change Current Login Data",
2273: 'yodo' => "You do not have privileges to modify the authentication configuration for this user.",
2274: 'ifch' => "If a change is required, contact a domain coordinator for the domain",
2275: );
2276: $outcome .= <<ENDNOPRIV;
2277: <h3>$lt{'ccld'}</h3>
2278: $lt{'yodo'} $lt{'ifch'}: $ccdomain
1.235 raeburn 2279: <input type="hidden" name="login" value="nochange" />
1.188 raeburn 2280: ENDNOPRIV
2281: }
2282: }
2283: } ## End of "check for bad authentication type" logic
2284: return $outcome;
2285: }
2286:
1.187 raeburn 2287: sub modify_login_block {
2288: my ($dom,$currentauth) = @_;
2289: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
2290: my ($authnum,%can_assign) =
2291: &Apache::loncommon::get_assignable_auth($dom);
1.205 raeburn 2292: my ($authformcurrent,@authform_others,$show_override_msg);
1.187 raeburn 2293: if ($currentauth=~/^krb(4|5):/) {
2294: $authformcurrent=$authformkrb;
2295: if ($can_assign{'int'}) {
1.205 raeburn 2296: push(@authform_others,$authformint);
1.187 raeburn 2297: }
2298: if ($can_assign{'loc'}) {
1.205 raeburn 2299: push(@authform_others,$authformloc);
1.187 raeburn 2300: }
2301: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
2302: $show_override_msg = 1;
2303: }
2304: } elsif ($currentauth=~/^internal:/) {
2305: $authformcurrent=$authformint;
2306: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205 raeburn 2307: push(@authform_others,$authformkrb);
1.187 raeburn 2308: }
2309: if ($can_assign{'loc'}) {
1.205 raeburn 2310: push(@authform_others,$authformloc);
1.187 raeburn 2311: }
2312: if ($can_assign{'int'}) {
2313: $show_override_msg = 1;
2314: }
2315: } elsif ($currentauth=~/^unix:/) {
2316: $authformcurrent=$authformfsys;
2317: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205 raeburn 2318: push(@authform_others,$authformkrb);
1.187 raeburn 2319: }
2320: if ($can_assign{'int'}) {
1.205 raeburn 2321: push(@authform_others,$authformint);
1.187 raeburn 2322: }
2323: if ($can_assign{'loc'}) {
1.205 raeburn 2324: push(@authform_others,$authformloc);
1.187 raeburn 2325: }
2326: if ($can_assign{'fsys'}) {
2327: $show_override_msg = 1;
2328: }
2329: } elsif ($currentauth=~/^localauth:/) {
2330: $authformcurrent=$authformloc;
2331: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205 raeburn 2332: push(@authform_others,$authformkrb);
1.187 raeburn 2333: }
2334: if ($can_assign{'int'}) {
1.205 raeburn 2335: push(@authform_others,$authformint);
1.187 raeburn 2336: }
2337: if ($can_assign{'loc'}) {
2338: $show_override_msg = 1;
2339: }
2340: }
2341: if ($show_override_msg) {
1.205 raeburn 2342: $authformcurrent = '<table><tr><td colspan="3">'.$authformcurrent.
2343: '</td></tr>'."\n".
2344: '<tr><td> </td>'.
2345: '<td><b>'.&mt('Currently in use').'</b></td>'.
2346: '<td align="right"><span class="LC_cusr_emph">'.
1.187 raeburn 2347: &mt('will override current values').
1.205 raeburn 2348: '</span></td></tr></table>';
1.187 raeburn 2349: }
1.205 raeburn 2350: return ($authformcurrent,$show_override_msg,@authform_others);
1.187 raeburn 2351: }
2352:
1.188 raeburn 2353: sub personal_data_display {
1.391 raeburn 2354: my ($ccuname,$ccdomain,$newuser,$context,$inst_results,$rolesarray,
1.410 raeburn 2355: $now,$captchaform,$emailusername,$usertype) = @_;
1.388 bisitz 2356: my ($output,%userenv,%canmodify,%canmodify_status);
1.219 raeburn 2357: my @userinfo = ('firstname','middlename','lastname','generation',
2358: 'permanentemail','id');
1.252 raeburn 2359: my $rowcount = 0;
2360: my $editable = 0;
1.391 raeburn 2361: my %textboxsize = (
2362: firstname => '15',
2363: middlename => '15',
2364: lastname => '15',
2365: generation => '5',
2366: permanentemail => '25',
2367: id => '15',
2368: );
2369:
2370: my %lt=&Apache::lonlocal::texthash(
2371: 'pd' => "Personal Data",
2372: 'firstname' => "First Name",
2373: 'middlename' => "Middle Name",
2374: 'lastname' => "Last Name",
2375: 'generation' => "Generation",
2376: 'permanentemail' => "Permanent e-mail address",
2377: 'id' => "Student/Employee ID",
2378: 'lg' => "Login Data",
2379: 'inststatus' => "Affiliation",
2380: 'email' => 'E-mail address',
2381: 'valid' => 'Validation',
2382: );
2383:
2384: %canmodify_status =
1.286 raeburn 2385: &Apache::lonuserutils::can_modify_userinfo($context,$ccdomain,
2386: ['inststatus'],$rolesarray);
1.253 raeburn 2387: if (!$newuser) {
1.188 raeburn 2388: # Get the users information
2389: %userenv = &Apache::lonnet::get('environment',
2390: ['firstname','middlename','lastname','generation',
1.286 raeburn 2391: 'permanentemail','id','inststatus'],$ccdomain,$ccuname);
1.219 raeburn 2392: %canmodify =
2393: &Apache::lonuserutils::can_modify_userinfo($context,$ccdomain,
1.252 raeburn 2394: \@userinfo,$rolesarray);
1.257 raeburn 2395: } elsif ($context eq 'selfcreate') {
1.391 raeburn 2396: if ($newuser eq 'email') {
1.396 raeburn 2397: if (ref($emailusername) eq 'HASH') {
2398: if (ref($emailusername->{$usertype}) eq 'HASH') {
2399: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
2400: @userinfo = ();
2401: if ((ref($infofields) eq 'ARRAY') && (ref($infotitles) eq 'HASH')) {
2402: foreach my $field (@{$infofields}) {
2403: if ($emailusername->{$usertype}->{$field}) {
2404: push(@userinfo,$field);
2405: $canmodify{$field} = 1;
2406: unless ($textboxsize{$field}) {
2407: $textboxsize{$field} = 25;
2408: }
2409: unless ($lt{$field}) {
2410: $lt{$field} = $infotitles->{$field};
2411: }
2412: if ($emailusername->{$usertype}->{$field} eq 'required') {
2413: $lt{$field} .= '<b>*</b>';
2414: }
1.391 raeburn 2415: }
2416: }
2417: }
2418: }
2419: }
2420: } else {
2421: %canmodify = &selfcreate_canmodify($context,$ccdomain,\@userinfo,
2422: $inst_results,$rolesarray);
2423: }
1.188 raeburn 2424: }
1.391 raeburn 2425:
1.188 raeburn 2426: my $genhelp=&Apache::loncommon::help_open_topic('Generation');
2427: $output = '<h3>'.$lt{'pd'}.'</h3>'.
2428: &Apache::lonhtmlcommon::start_pick_box();
1.391 raeburn 2429: if (($context eq 'selfcreate') && ($newuser eq 'email')) {
1.396 raeburn 2430: $output .= &Apache::lonhtmlcommon::row_title($lt{'email'}.'<b>*</b>',undef,
1.391 raeburn 2431: 'LC_oddrow_value')."\n".
1.394 raeburn 2432: '<input type="text" name="uname" size="25" value="" autocomplete="off" />';
1.391 raeburn 2433: $rowcount ++;
2434: $output .= &Apache::lonhtmlcommon::row_closure(1);
1.408 raeburn 2435: my $upassone = '<input type="password" name="upass'.$now.'" size="20" autocomplete="off" />';
2436: my $upasstwo = '<input type="password" name="upasscheck'.$now.'" size="20" autocomplete="off" />';
1.396 raeburn 2437: $output .= &Apache::lonhtmlcommon::row_title(&mt('Password').'<b>*</b>',
1.391 raeburn 2438: 'LC_pick_box_title',
2439: 'LC_oddrow_value')."\n".
2440: $upassone."\n".
2441: &Apache::lonhtmlcommon::row_closure(1)."\n".
1.396 raeburn 2442: &Apache::lonhtmlcommon::row_title(&mt('Confirm password').'<b>*</b>',
1.391 raeburn 2443: 'LC_pick_box_title',
2444: 'LC_oddrow_value')."\n".
2445: $upasstwo.
2446: &Apache::lonhtmlcommon::row_closure()."\n";
2447: }
1.188 raeburn 2448: foreach my $item (@userinfo) {
2449: my $rowtitle = $lt{$item};
1.252 raeburn 2450: my $hiderow = 0;
1.188 raeburn 2451: if ($item eq 'generation') {
2452: $rowtitle = $genhelp.$rowtitle;
2453: }
1.252 raeburn 2454: my $row = &Apache::lonhtmlcommon::row_title($rowtitle,undef,'LC_oddrow_value')."\n";
1.188 raeburn 2455: if ($newuser) {
1.210 raeburn 2456: if (ref($inst_results) eq 'HASH') {
2457: if ($inst_results->{$item} ne '') {
1.252 raeburn 2458: $row .= '<input type="hidden" name="c'.$item.'" value="'.$inst_results->{$item}.'" />'.$inst_results->{$item};
1.210 raeburn 2459: } else {
1.252 raeburn 2460: if ($context eq 'selfcreate') {
1.391 raeburn 2461: if ($canmodify{$item}) {
1.394 raeburn 2462: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" autocomplete="off" />';
1.252 raeburn 2463: $editable ++;
2464: } else {
2465: $hiderow = 1;
2466: }
1.253 raeburn 2467: } else {
2468: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
1.252 raeburn 2469: }
1.210 raeburn 2470: }
1.188 raeburn 2471: } else {
1.252 raeburn 2472: if ($context eq 'selfcreate') {
1.401 raeburn 2473: if ($canmodify{$item}) {
2474: if ($newuser eq 'email') {
2475: $row .= '<input type="text" name="'.$item.'" size="'.$textboxsize{$item}.'" value="" autocomplete="off" />';
1.287 raeburn 2476: } else {
1.401 raeburn 2477: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" autocomplete="off" />';
1.287 raeburn 2478: }
1.401 raeburn 2479: $editable ++;
2480: } else {
2481: $hiderow = 1;
1.252 raeburn 2482: }
1.253 raeburn 2483: } else {
2484: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
1.252 raeburn 2485: }
1.188 raeburn 2486: }
2487: } else {
1.219 raeburn 2488: if ($canmodify{$item}) {
1.252 raeburn 2489: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="'.$userenv{$item}.'" />';
1.393 raeburn 2490: if (($item eq 'id') && (!$newuser)) {
2491: $row .= '<br />'.&Apache::lonuserutils::forceid_change($context);
2492: }
1.188 raeburn 2493: } else {
1.252 raeburn 2494: $row .= $userenv{$item};
1.188 raeburn 2495: }
2496: }
1.252 raeburn 2497: $row .= &Apache::lonhtmlcommon::row_closure(1);
2498: if (!$hiderow) {
2499: $output .= $row;
2500: $rowcount ++;
2501: }
1.188 raeburn 2502: }
1.286 raeburn 2503: if (($canmodify_status{'inststatus'}) || ($context ne 'selfcreate')) {
2504: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($ccdomain);
2505: if (ref($types) eq 'ARRAY') {
2506: if (@{$types} > 0) {
2507: my ($hiderow,$shown);
2508: if ($canmodify_status{'inststatus'}) {
2509: $shown = &pick_inst_statuses($userenv{'inststatus'},$usertypes,$types);
2510: } else {
2511: if ($userenv{'inststatus'} eq '') {
2512: $hiderow = 1;
1.334 raeburn 2513: } else {
2514: my @showitems;
2515: foreach my $item ( map { &unescape($_); } split(':',$userenv{'inststatus'})) {
2516: if (exists($usertypes->{$item})) {
2517: push(@showitems,$usertypes->{$item});
2518: } else {
2519: push(@showitems,$item);
2520: }
2521: }
2522: if (@showitems) {
2523: $shown = join(', ',@showitems);
2524: } else {
2525: $hiderow = 1;
2526: }
1.286 raeburn 2527: }
2528: }
2529: if (!$hiderow) {
1.389 bisitz 2530: my $row = &Apache::lonhtmlcommon::row_title(&mt('Affiliations'),undef,'LC_oddrow_value')."\n".
1.286 raeburn 2531: $shown.&Apache::lonhtmlcommon::row_closure(1);
2532: if ($context eq 'selfcreate') {
2533: $rowcount ++;
2534: }
2535: $output .= $row;
2536: }
2537: }
2538: }
2539: }
1.391 raeburn 2540: if (($context eq 'selfcreate') && ($newuser eq 'email')) {
2541: if ($captchaform) {
1.410 raeburn 2542: $output .= &Apache::lonhtmlcommon::row_title($lt{'valid'}.'*',
2543: 'LC_pick_box_title')."\n".
2544: $captchaform."\n".'<br /><br />'.
1.391 raeburn 2545: &Apache::lonhtmlcommon::row_closure(1);
2546: $rowcount ++;
2547: }
2548: my $submit_text = &mt('Create account');
2549: $output .= &Apache::lonhtmlcommon::row_title()."\n".
2550: '<br /><input type="submit" name="createaccount" value="'.
2551: $submit_text.'" />'.
1.396 raeburn 2552: '<input type="hidden" name="type" value="'.$usertype.'" />'.
1.391 raeburn 2553: &Apache::lonhtmlcommon::row_closure(1);
2554: }
1.188 raeburn 2555: $output .= &Apache::lonhtmlcommon::end_pick_box();
1.206 raeburn 2556: if (wantarray) {
1.252 raeburn 2557: if ($context eq 'selfcreate') {
2558: return($output,$rowcount,$editable);
2559: } else {
1.388 bisitz 2560: return $output;
1.252 raeburn 2561: }
1.206 raeburn 2562: } else {
2563: return $output;
2564: }
1.188 raeburn 2565: }
2566:
1.286 raeburn 2567: sub pick_inst_statuses {
2568: my ($curr,$usertypes,$types) = @_;
2569: my ($output,$rem,@currtypes);
2570: if ($curr ne '') {
2571: @currtypes = map { &unescape($_); } split(/:/,$curr);
2572: }
2573: my $numinrow = 2;
2574: if (ref($types) eq 'ARRAY') {
2575: $output = '<table>';
2576: my $lastcolspan;
2577: for (my $i=0; $i<@{$types}; $i++) {
2578: if (defined($usertypes->{$types->[$i]})) {
2579: my $rem = $i%($numinrow);
2580: if ($rem == 0) {
2581: if ($i<@{$types}-1) {
2582: if ($i > 0) {
2583: $output .= '</tr>';
2584: }
2585: $output .= '<tr>';
2586: }
2587: } elsif ($i==@{$types}-1) {
2588: my $colsleft = $numinrow - $rem;
2589: if ($colsleft > 1) {
2590: $lastcolspan = ' colspan="'.$colsleft.'"';
2591: }
2592: }
2593: my $check = ' ';
2594: if (grep(/^\Q$types->[$i]\E$/,@currtypes)) {
2595: $check = ' checked="checked" ';
2596: }
2597: $output .= '<td class="LC_left_item"'.$lastcolspan.'>'.
2598: '<span class="LC_nobreak"><label>'.
2599: '<input type="checkbox" name="inststatus" '.
2600: 'value="'.$types->[$i].'"'.$check.'/>'.
2601: $usertypes->{$types->[$i]}.'</label></span></td>';
2602: }
2603: }
2604: $output .= '</tr></table>';
2605: }
2606: return $output;
2607: }
2608:
1.257 raeburn 2609: sub selfcreate_canmodify {
2610: my ($context,$dom,$userinfo,$inst_results,$rolesarray) = @_;
2611: if (ref($inst_results) eq 'HASH') {
2612: my @inststatuses = &get_inststatuses($inst_results);
2613: if (@inststatuses == 0) {
2614: @inststatuses = ('default');
2615: }
2616: $rolesarray = \@inststatuses;
2617: }
2618: my %canmodify =
2619: &Apache::lonuserutils::can_modify_userinfo($context,$dom,$userinfo,
2620: $rolesarray);
2621: return %canmodify;
2622: }
2623:
1.252 raeburn 2624: sub get_inststatuses {
2625: my ($insthashref) = @_;
2626: my @inststatuses = ();
2627: if (ref($insthashref) eq 'HASH') {
2628: if (ref($insthashref->{'inststatus'}) eq 'ARRAY') {
2629: @inststatuses = @{$insthashref->{'inststatus'}};
2630: }
2631: }
2632: return @inststatuses;
2633: }
2634:
1.4 www 2635: # ================================================================= Phase Three
1.42 matthew 2636: sub update_user_data {
1.375 raeburn 2637: my ($r,$context,$crstype,$brcrum,$showcredits) = @_;
1.101 albertel 2638: my $uhome=&Apache::lonnet::homeserver($env{'form.ccuname'},
2639: $env{'form.ccdomain'});
1.27 matthew 2640: # Error messages
1.188 raeburn 2641: my $error = '<span class="LC_error">'.&mt('Error').': ';
1.193 raeburn 2642: my $end = '</span><br /><br />';
2643: my $rtnlink = '<a href="javascript:backPage(document.userupdate,'.
1.188 raeburn 2644: "'$env{'form.prevphase'}','modify')".'" />'.
1.219 raeburn 2645: &mt('Return to previous page').'</a>'.
2646: &Apache::loncommon::end_page();
2647: my $now = time;
1.40 www 2648: my $title;
1.101 albertel 2649: if (exists($env{'form.makeuser'})) {
1.40 www 2650: $title='Set Privileges for New User';
2651: } else {
2652: $title='Modify User Privileges';
2653: }
1.213 raeburn 2654: my $newuser = 0;
1.160 raeburn 2655: my ($jsback,$elements) = &crumb_utilities();
2656: my $jscript = '<script type="text/javascript">'."\n".
1.301 bisitz 2657: '// <![CDATA['."\n".
2658: $jsback."\n".
2659: '// ]]>'."\n".
2660: '</script>'."\n";
1.422 raeburn 2661: my %breadcrumb_text = &singleuser_breadcrumb($crstype,$context,$env{'form.ccdomain'});
1.351 raeburn 2662: push (@{$brcrum},
2663: {href => "javascript:backPage(document.userupdate)",
2664: text => $breadcrumb_text{'search'},
2665: faq => 282,
2666: bug => 'Instructor Interface',}
2667: );
2668: if ($env{'form.prevphase'} eq 'userpicked') {
2669: push(@{$brcrum},
2670: {href => "javascript:backPage(document.userupdate,'get_user_info','select')",
2671: text => $breadcrumb_text{'userpicked'},
2672: faq => 282,
2673: bug => 'Instructor Interface',});
1.233 raeburn 2674: }
1.224 raeburn 2675: my $helpitem = 'Course_Change_Privileges';
2676: if ($env{'form.action'} eq 'singlestudent') {
2677: $helpitem = 'Course_Add_Student';
1.439 raeburn 2678: } elsif ($context eq 'author') {
2679: $helpitem = 'Author_Change_Privileges';
2680: } elsif ($context eq 'domain') {
2681: $helpitem = 'Domain_Change_Privileges';
1.224 raeburn 2682: }
1.351 raeburn 2683: push(@{$brcrum},
2684: {href => "javascript:backPage(document.userupdate,'$env{'form.prevphase'}','modify')",
2685: text => $breadcrumb_text{'modify'},
2686: faq => 282,
2687: bug => 'Instructor Interface',},
2688: {href => "/adm/createuser",
2689: text => "Result",
2690: faq => 282,
2691: bug => 'Instructor Interface',
2692: help => $helpitem});
2693: my $args = {bread_crumbs => $brcrum,
2694: bread_crumbs_component => 'User Management'};
2695: if ($env{'form.popup'}) {
2696: $args->{'no_nav_bar'} = 1;
2697: }
2698: $r->print(&Apache::loncommon::start_page($title,$jscript,$args));
1.188 raeburn 2699: $r->print(&update_result_form($uhome));
1.27 matthew 2700: # Check Inputs
1.101 albertel 2701: if (! $env{'form.ccuname'} ) {
1.193 raeburn 2702: $r->print($error.&mt('No login name specified').'.'.$end.$rtnlink);
1.27 matthew 2703: return;
2704: }
1.138 albertel 2705: if ( $env{'form.ccuname'} ne
2706: &LONCAPA::clean_username($env{'form.ccuname'}) ) {
1.281 bisitz 2707: $r->print($error.&mt('Invalid login name.').' '.
2708: &mt('Only letters, numbers, periods, dashes, @, and underscores are valid.').
1.193 raeburn 2709: $end.$rtnlink);
1.27 matthew 2710: return;
2711: }
1.101 albertel 2712: if (! $env{'form.ccdomain'} ) {
1.193 raeburn 2713: $r->print($error.&mt('No domain specified').'.'.$end.$rtnlink);
1.27 matthew 2714: return;
2715: }
1.138 albertel 2716: if ( $env{'form.ccdomain'} ne
2717: &LONCAPA::clean_domain($env{'form.ccdomain'}) ) {
1.281 bisitz 2718: $r->print($error.&mt('Invalid domain name.').' '.
2719: &mt('Only letters, numbers, periods, dashes, and underscores are valid.').
1.193 raeburn 2720: $end.$rtnlink);
1.27 matthew 2721: return;
2722: }
1.219 raeburn 2723: if ($uhome eq 'no_host') {
2724: $newuser = 1;
2725: }
1.101 albertel 2726: if (! exists($env{'form.makeuser'})) {
1.29 matthew 2727: # Modifying an existing user, so check the validity of the name
2728: if ($uhome eq 'no_host') {
1.389 bisitz 2729: $r->print(
2730: $error
2731: .'<p class="LC_error">'
2732: .&mt('Unable to determine home server for [_1] in domain [_2].',
2733: '"'.$env{'form.ccuname'}.'"','"'.$env{'form.ccdomain'}.'"')
2734: .'</p>');
1.29 matthew 2735: return;
2736: }
2737: }
1.27 matthew 2738: # Determine authentication method and password for the user being modified
2739: my $amode='';
2740: my $genpwd='';
1.101 albertel 2741: if ($env{'form.login'} eq 'krb') {
1.41 albertel 2742: $amode='krb';
1.101 albertel 2743: $amode.=$env{'form.krbver'};
2744: $genpwd=$env{'form.krbarg'};
2745: } elsif ($env{'form.login'} eq 'int') {
1.27 matthew 2746: $amode='internal';
1.101 albertel 2747: $genpwd=$env{'form.intarg'};
2748: } elsif ($env{'form.login'} eq 'fsys') {
1.27 matthew 2749: $amode='unix';
1.101 albertel 2750: $genpwd=$env{'form.fsysarg'};
2751: } elsif ($env{'form.login'} eq 'loc') {
1.27 matthew 2752: $amode='localauth';
1.101 albertel 2753: $genpwd=$env{'form.locarg'};
1.27 matthew 2754: $genpwd=" " if (!$genpwd);
1.101 albertel 2755: } elsif (($env{'form.login'} eq 'nochange') ||
2756: ($env{'form.login'} eq '' )) {
1.34 matthew 2757: # There is no need to tell the user we did not change what they
2758: # did not ask us to change.
1.35 matthew 2759: # If they are creating a new user but have not specified login
2760: # information this will be caught below.
1.30 matthew 2761: } else {
1.367 golterma 2762: $r->print($error.&mt('Invalid login mode or password').$end.$rtnlink);
2763: return;
1.27 matthew 2764: }
1.164 albertel 2765:
1.188 raeburn 2766: $r->print('<h3>'.&mt('User [_1] in domain [_2]',
1.367 golterma 2767: $env{'form.ccuname'}.' ('.&Apache::loncommon::plainname($env{'form.ccuname'},
2768: $env{'form.ccdomain'}).')', $env{'form.ccdomain'}).'</h3>');
2769: my %prog_state = &Apache::lonhtmlcommon::Create_PrgWin($r,2);
1.344 bisitz 2770:
1.193 raeburn 2771: my (%alerts,%rulematch,%inst_results,%curr_rules);
1.334 raeburn 2772: my @userinfo = ('firstname','middlename','lastname','generation','permanentemail','id');
1.361 raeburn 2773: my @usertools = ('aboutme','blog','webdav','portfolio');
1.411 raeburn 2774: my @requestcourses = ('official','unofficial','community','textbook','placement');
1.362 raeburn 2775: my @requestauthor = ('requestauthor');
1.286 raeburn 2776: my ($othertitle,$usertypes,$types) =
2777: &Apache::loncommon::sorted_inst_types($env{'form.ccdomain'});
1.334 raeburn 2778: my %canmodify_status =
2779: &Apache::lonuserutils::can_modify_userinfo($context,$env{'form.ccdomain'},
2780: ['inststatus']);
1.101 albertel 2781: if ($env{'form.makeuser'}) {
1.164 albertel 2782: $r->print('<h3>'.&mt('Creating new account.').'</h3>');
1.27 matthew 2783: # Check for the authentication mode and password
2784: if (! $amode || ! $genpwd) {
1.193 raeburn 2785: $r->print($error.&mt('Invalid login mode or password').$end.$rtnlink);
1.27 matthew 2786: return;
1.18 albertel 2787: }
1.29 matthew 2788: # Determine desired host
1.101 albertel 2789: my $desiredhost = $env{'form.hserver'};
1.29 matthew 2790: if (lc($desiredhost) eq 'default') {
2791: $desiredhost = undef;
2792: } else {
1.147 albertel 2793: my %home_servers =
2794: &Apache::lonnet::get_servers($env{'form.ccdomain'},'library');
1.29 matthew 2795: if (! exists($home_servers{$desiredhost})) {
1.193 raeburn 2796: $r->print($error.&mt('Invalid home server specified').$end.$rtnlink);
2797: return;
2798: }
2799: }
2800: # Check ID format
2801: my %checkhash;
2802: my %checks = ('id' => 1);
2803: %{$checkhash{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}}} = (
1.219 raeburn 2804: 'newuser' => $newuser,
1.196 raeburn 2805: 'id' => $env{'form.cid'},
1.193 raeburn 2806: );
1.196 raeburn 2807: if ($env{'form.cid'} ne '') {
2808: &Apache::loncommon::user_rule_check(\%checkhash,\%checks,\%alerts,
2809: \%rulematch,\%inst_results,\%curr_rules);
2810: if (ref($alerts{'id'}) eq 'HASH') {
2811: if (ref($alerts{'id'}{$env{'form.ccdomain'}}) eq 'HASH') {
2812: my $domdesc =
2813: &Apache::lonnet::domain($env{'form.ccdomain'},'description');
2814: if ($alerts{'id'}{$env{'form.ccdomain'}}{$env{'form.cid'}}) {
2815: my $userchkmsg;
2816: if (ref($curr_rules{$env{'form.ccdomain'}}) eq 'HASH') {
2817: $userchkmsg =
2818: &Apache::loncommon::instrule_disallow_msg('id',
2819: $domdesc,1).
2820: &Apache::loncommon::user_rule_formats($env{'form.ccdomain'},
2821: $domdesc,$curr_rules{$env{'form.ccdomain'}}{'id'},'id');
2822: }
2823: $r->print($error.&mt('Invalid ID format').$end.
2824: $userchkmsg.$rtnlink);
2825: return;
2826: }
2827: }
1.29 matthew 2828: }
2829: }
1.367 golterma 2830: &Apache::lonhtmlcommon::Increment_PrgWin($r, \%prog_state);
1.27 matthew 2831: # Call modifyuser
2832: my $result = &Apache::lonnet::modifyuser
1.193 raeburn 2833: ($env{'form.ccdomain'},$env{'form.ccuname'},$env{'form.cid'},
1.188 raeburn 2834: $amode,$genpwd,$env{'form.cfirstname'},
2835: $env{'form.cmiddlename'},$env{'form.clastname'},
2836: $env{'form.cgeneration'},undef,$desiredhost,
2837: $env{'form.cpermanentemail'});
1.77 www 2838: $r->print(&mt('Generating user').': '.$result);
1.219 raeburn 2839: $uhome = &Apache::lonnet::homeserver($env{'form.ccuname'},
1.101 albertel 2840: $env{'form.ccdomain'});
1.334 raeburn 2841: my (%changeHash,%newcustom,%changed,%changedinfo);
1.267 raeburn 2842: if ($uhome ne 'no_host') {
1.334 raeburn 2843: if ($context eq 'domain') {
1.378 raeburn 2844: foreach my $name ('portfolio','author') {
2845: if ($env{'form.custom_'.$name.'quota'} == 1) {
2846: if ($env{'form.'.$name.'quota'} eq '') {
2847: $newcustom{$name.'quota'} = 0;
2848: } else {
2849: $newcustom{$name.'quota'} = $env{'form.'.$name.'quota'};
2850: $newcustom{$name.'quota'} =~ s/[^\d\.]//g;
2851: }
2852: if ("a_admin($newcustom{$name.'quota'},\%changeHash,$name)) {
2853: $changed{$name.'quota'} = 1;
2854: }
1.334 raeburn 2855: }
2856: }
2857: foreach my $item (@usertools) {
2858: if ($env{'form.custom'.$item} == 1) {
2859: $newcustom{$item} = $env{'form.tools_'.$item};
2860: $changed{$item} = &tool_admin($item,$newcustom{$item},
2861: \%changeHash,'tools');
2862: }
1.267 raeburn 2863: }
1.334 raeburn 2864: foreach my $item (@requestcourses) {
1.341 raeburn 2865: if ($env{'form.custom'.$item} == 1) {
2866: $newcustom{$item} = $env{'form.crsreq_'.$item};
2867: if ($env{'form.crsreq_'.$item} eq 'autolimit') {
2868: $newcustom{$item} .= '=';
1.383 raeburn 2869: $env{'form.crsreq_'.$item.'_limit'} =~ s/\D+//g;
2870: if ($env{'form.crsreq_'.$item.'_limit'}) {
1.341 raeburn 2871: $newcustom{$item} .= $env{'form.crsreq_'.$item.'_limit'};
2872: }
1.334 raeburn 2873: }
1.341 raeburn 2874: $changed{$item} = &tool_admin($item,$newcustom{$item},
2875: \%changeHash,'requestcourses');
1.334 raeburn 2876: }
1.275 raeburn 2877: }
1.362 raeburn 2878: if ($env{'form.customrequestauthor'} == 1) {
2879: $newcustom{'requestauthor'} = $env{'form.requestauthor'};
2880: $changed{'requestauthor'} = &tool_admin('requestauthor',
2881: $newcustom{'requestauthor'},
2882: \%changeHash,'requestauthor');
2883: }
1.275 raeburn 2884: }
1.334 raeburn 2885: if ($canmodify_status{'inststatus'}) {
2886: if (exists($env{'form.inststatus'})) {
2887: my @inststatuses = &Apache::loncommon::get_env_multiple('form.inststatus');
2888: if (@inststatuses > 0) {
2889: $changeHash{'inststatus'} = join(',',@inststatuses);
2890: $changed{'inststatus'} = $changeHash{'inststatus'};
1.306 raeburn 2891: }
2892: }
1.232 raeburn 2893: }
1.334 raeburn 2894: if (keys(%changed)) {
2895: foreach my $item (@userinfo) {
2896: $changeHash{$item} = $env{'form.c'.$item};
1.286 raeburn 2897: }
1.267 raeburn 2898: my $chgresult =
2899: &Apache::lonnet::put('environment',\%changeHash,
2900: $env{'form.ccdomain'},$env{'form.ccuname'});
2901: }
1.232 raeburn 2902: }
1.219 raeburn 2903: $r->print('<br />'.&mt('Home server').': '.$uhome.' '.
2904: &Apache::lonnet::hostname($uhome));
1.101 albertel 2905: } elsif (($env{'form.login'} ne 'nochange') &&
2906: ($env{'form.login'} ne '' )) {
1.27 matthew 2907: # Modify user privileges
2908: if (! $amode || ! $genpwd) {
1.193 raeburn 2909: $r->print($error.'Invalid login mode or password'.$end.$rtnlink);
1.27 matthew 2910: return;
1.20 harris41 2911: }
1.395 bisitz 2912: # Only allow authentication modification if the person has authority
1.101 albertel 2913: if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'})) {
1.20 harris41 2914: $r->print('Modifying authentication: '.
1.31 matthew 2915: &Apache::lonnet::modifyuserauth(
1.101 albertel 2916: $env{'form.ccdomain'},$env{'form.ccuname'},
1.21 harris41 2917: $amode,$genpwd));
1.102 albertel 2918: $r->print('<br />'.&mt('Home server').': '.&Apache::lonnet::homeserver
1.101 albertel 2919: ($env{'form.ccuname'},$env{'form.ccdomain'}));
1.4 www 2920: } else {
1.27 matthew 2921: # Okay, this is a non-fatal error.
1.395 bisitz 2922: $r->print($error.&mt('You do not have the authority to modify this users authentication information.').$end);
1.27 matthew 2923: }
1.28 matthew 2924: }
1.344 bisitz 2925: $r->rflush(); # Finish display of header before time consuming actions start
1.367 golterma 2926: &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state);
1.28 matthew 2927: ##
1.375 raeburn 2928: my (@userroles,%userupdate,$cnum,$cdom,$defaultcredits,%namechanged);
1.213 raeburn 2929: if ($context eq 'course') {
1.375 raeburn 2930: ($cnum,$cdom) =
2931: &Apache::lonuserutils::get_course_identity();
1.318 raeburn 2932: $crstype = &Apache::loncommon::course_type($cdom.'_'.$cnum);
1.375 raeburn 2933: if ($showcredits) {
2934: $defaultcredits = &Apache::lonuserutils::get_defaultcredits($cdom,$cnum);
2935: }
1.213 raeburn 2936: }
1.101 albertel 2937: if (! $env{'form.makeuser'} ) {
1.28 matthew 2938: # Check for need to change
2939: my %userenv = &Apache::lonnet::get
1.134 raeburn 2940: ('environment',['firstname','middlename','lastname','generation',
1.378 raeburn 2941: 'id','permanentemail','portfolioquota','authorquota','inststatus',
2942: 'tools.aboutme','tools.blog','tools.webdav','tools.portfolio',
1.361 raeburn 2943: 'requestcourses.official','requestcourses.unofficial',
1.384 raeburn 2944: 'requestcourses.community','requestcourses.textbook',
2945: 'reqcrsotherdom.official','reqcrsotherdom.unofficial',
2946: 'reqcrsotherdom.community','reqcrsotherdom.textbook',
1.427 raeburn 2947: 'reqcrsotherdom.placement','requestauthor'],
1.160 raeburn 2948: $env{'form.ccdomain'},$env{'form.ccuname'});
1.28 matthew 2949: my ($tmp) = keys(%userenv);
2950: if ($tmp =~ /^(con_lost|error)/i) {
2951: %userenv = ();
2952: }
1.206 raeburn 2953: my $no_forceid_alert;
2954: # Check to see if user information can be changed
2955: my %domconfig =
2956: &Apache::lonnet::get_dom('configuration',['usermodification'],
2957: $env{'form.ccdomain'});
1.213 raeburn 2958: my @statuses = ('active','future');
2959: my %roles = &Apache::lonnet::get_my_roles($env{'form.ccuname'},$env{'form.ccdomain'},'userroles',\@statuses,undef,$env{'request.role.domain'});
2960: my ($auname,$audom);
1.220 raeburn 2961: if ($context eq 'author') {
1.206 raeburn 2962: $auname = $env{'user.name'};
2963: $audom = $env{'user.domain'};
2964: }
2965: foreach my $item (keys(%roles)) {
1.220 raeburn 2966: my ($rolenum,$roledom,$role) = split(/:/,$item,-1);
1.206 raeburn 2967: if ($context eq 'course') {
2968: if ($cnum ne '' && $cdom ne '') {
2969: if ($rolenum eq $cnum && $roledom eq $cdom) {
2970: if (!grep(/^\Q$role\E$/,@userroles)) {
2971: push(@userroles,$role);
2972: }
2973: }
2974: }
2975: } elsif ($context eq 'author') {
2976: if ($rolenum eq $auname && $roledom eq $audom) {
2977: if (!grep(/^\Q$role\E$/,@userroles)) {
2978: push(@userroles,$role);
2979: }
2980: }
2981: }
2982: }
1.220 raeburn 2983: if ($env{'form.action'} eq 'singlestudent') {
2984: if (!grep(/^st$/,@userroles)) {
2985: push(@userroles,'st');
2986: }
2987: } else {
2988: # Check for course or co-author roles being activated or re-enabled
2989: if ($context eq 'author' || $context eq 'course') {
2990: foreach my $key (keys(%env)) {
2991: if ($context eq 'author') {
2992: if ($key=~/^form\.act_\Q$audom\E_\Q$auname\E_([^_]+)/) {
2993: if (!grep(/^\Q$1\E$/,@userroles)) {
2994: push(@userroles,$1);
2995: }
2996: } elsif ($key =~/^form\.ren\:\Q$audom\E\/\Q$auname\E_([^_]+)/) {
2997: if (!grep(/^\Q$1\E$/,@userroles)) {
2998: push(@userroles,$1);
2999: }
1.206 raeburn 3000: }
1.220 raeburn 3001: } elsif ($context eq 'course') {
3002: if ($key=~/^form\.act_\Q$cdom\E_\Q$cnum\E_([^_]+)/) {
3003: if (!grep(/^\Q$1\E$/,@userroles)) {
3004: push(@userroles,$1);
3005: }
3006: } elsif ($key =~/^form\.ren\:\Q$cdom\E\/\Q$cnum\E(\/?\w*)_([^_]+)/) {
3007: if (!grep(/^\Q$1\E$/,@userroles)) {
3008: push(@userroles,$1);
3009: }
1.206 raeburn 3010: }
3011: }
3012: }
3013: }
3014: }
3015: #Check to see if we can change personal data for the user
3016: my (@mod_disallowed,@longroles);
3017: foreach my $role (@userroles) {
3018: if ($role eq 'cr') {
3019: push(@longroles,'Custom');
3020: } else {
1.318 raeburn 3021: push(@longroles,&Apache::lonnet::plaintext($role,$crstype));
1.206 raeburn 3022: }
3023: }
1.219 raeburn 3024: my %canmodify = &Apache::lonuserutils::can_modify_userinfo($context,$env{'form.ccdomain'},\@userinfo,\@userroles);
3025: foreach my $item (@userinfo) {
1.28 matthew 3026: # Strip leading and trailing whitespace
1.203 raeburn 3027: $env{'form.c'.$item} =~ s/(\s+$|^\s+)//g;
1.219 raeburn 3028: if (!$canmodify{$item}) {
1.207 raeburn 3029: if (defined($env{'form.c'.$item})) {
3030: if ($env{'form.c'.$item} ne $userenv{$item}) {
3031: push(@mod_disallowed,$item);
3032: }
1.206 raeburn 3033: }
3034: $env{'form.c'.$item} = $userenv{$item};
3035: }
1.28 matthew 3036: }
1.259 bisitz 3037: # Check to see if we can change the Student/Employee ID
1.196 raeburn 3038: my $forceid = $env{'form.forceid'};
3039: my $recurseid = $env{'form.recurseid'};
3040: my (%alerts,%rulematch,%idinst_results,%curr_rules,%got_rules);
1.203 raeburn 3041: my %uidhash = &Apache::lonnet::idrget($env{'form.ccdomain'},
3042: $env{'form.ccuname'});
3043: if (($uidhash{$env{'form.ccuname'}}) &&
3044: ($uidhash{$env{'form.ccuname'}}!~/error\:/) &&
3045: (!$forceid)) {
3046: if ($env{'form.cid'} ne $uidhash{$env{'form.ccuname'}}) {
3047: $env{'form.cid'} = $userenv{'id'};
1.293 bisitz 3048: $no_forceid_alert = &mt('New student/employee ID does not match existing ID for this user.')
1.259 bisitz 3049: .'<br />'
3050: .&mt("Change is not permitted without checking the 'Force ID change' checkbox on the previous page.")
3051: .'<br />'."\n";
1.203 raeburn 3052: }
3053: }
3054: if ($env{'form.cid'} ne $userenv{'id'}) {
1.196 raeburn 3055: my $checkhash;
3056: my $checks = { 'id' => 1 };
3057: $checkhash->{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}} =
3058: { 'newuser' => $newuser,
3059: 'id' => $env{'form.cid'},
3060: };
3061: &Apache::loncommon::user_rule_check($checkhash,$checks,
3062: \%alerts,\%rulematch,\%idinst_results,\%curr_rules,\%got_rules);
3063: if (ref($alerts{'id'}) eq 'HASH') {
3064: if (ref($alerts{'id'}{$env{'form.ccdomain'}}) eq 'HASH') {
1.203 raeburn 3065: $env{'form.cid'} = $userenv{'id'};
1.196 raeburn 3066: }
3067: }
3068: }
1.378 raeburn 3069: my (%quotachanged,%oldquota,%newquota,%olddefquota,%newdefquota,
3070: $oldinststatus,$newinststatus,%oldisdefault,%newisdefault,%oldsettings,
1.339 raeburn 3071: %oldsettingstext,%newsettings,%newsettingstext,@disporder,
1.378 raeburn 3072: %oldsettingstatus,%newsettingstatus);
1.334 raeburn 3073: @disporder = ('inststatus');
3074: if ($env{'request.role.domain'} eq $env{'form.ccdomain'}) {
1.362 raeburn 3075: push(@disporder,'requestcourses','requestauthor');
1.334 raeburn 3076: } else {
3077: push(@disporder,'reqcrsotherdom');
3078: }
3079: push(@disporder,('quota','tools'));
1.338 raeburn 3080: $oldinststatus = $userenv{'inststatus'};
1.378 raeburn 3081: foreach my $name ('portfolio','author') {
3082: ($olddefquota{$name},$oldsettingstatus{$name}) =
3083: &Apache::loncommon::default_quota($env{'form.ccdomain'},$oldinststatus,$name);
3084: ($newdefquota{$name},$newsettingstatus{$name}) = ($olddefquota{$name},$oldsettingstatus{$name});
3085: }
1.334 raeburn 3086: my %canshow;
1.220 raeburn 3087: if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
1.334 raeburn 3088: $canshow{'quota'} = 1;
1.220 raeburn 3089: }
1.267 raeburn 3090: if (&Apache::lonnet::allowed('mut',$env{'form.ccdomain'})) {
1.334 raeburn 3091: $canshow{'tools'} = 1;
1.267 raeburn 3092: }
1.275 raeburn 3093: if (&Apache::lonnet::allowed('ccc',$env{'form.ccdomain'})) {
1.334 raeburn 3094: $canshow{'requestcourses'} = 1;
1.300 raeburn 3095: } elsif (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
1.334 raeburn 3096: $canshow{'reqcrsotherdom'} = 1;
1.275 raeburn 3097: }
1.286 raeburn 3098: if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'})) {
1.334 raeburn 3099: $canshow{'inststatus'} = 1;
1.286 raeburn 3100: }
1.362 raeburn 3101: if (&Apache::lonnet::allowed('cau',$env{'form.ccdomain'})) {
3102: $canshow{'requestauthor'} = 1;
3103: }
1.267 raeburn 3104: my (%changeHash,%changed);
1.286 raeburn 3105: if ($oldinststatus eq '') {
1.334 raeburn 3106: $oldsettings{'inststatus'} = $othertitle;
1.286 raeburn 3107: } else {
3108: if (ref($usertypes) eq 'HASH') {
1.334 raeburn 3109: $oldsettings{'inststatus'} = join(', ',map{ $usertypes->{ &unescape($_) }; } (split(/:/,$userenv{'inststatus'})));
1.286 raeburn 3110: } else {
1.334 raeburn 3111: $oldsettings{'inststatus'} = join(', ',map{ &unescape($_); } (split(/:/,$userenv{'inststatus'})));
1.286 raeburn 3112: }
3113: }
3114: $changeHash{'inststatus'} = $userenv{'inststatus'};
1.334 raeburn 3115: if ($canmodify_status{'inststatus'}) {
3116: $canshow{'inststatus'} = 1;
1.286 raeburn 3117: if (exists($env{'form.inststatus'})) {
3118: my @inststatuses = &Apache::loncommon::get_env_multiple('form.inststatus');
3119: if (@inststatuses > 0) {
3120: $newinststatus = join(':',map { &escape($_); } @inststatuses);
3121: $changeHash{'inststatus'} = $newinststatus;
3122: if ($newinststatus ne $oldinststatus) {
3123: $changed{'inststatus'} = $newinststatus;
1.378 raeburn 3124: foreach my $name ('portfolio','author') {
3125: ($newdefquota{$name},$newsettingstatus{$name}) =
3126: &Apache::loncommon::default_quota($env{'form.ccdomain'},$newinststatus,$name);
3127: }
1.286 raeburn 3128: }
3129: if (ref($usertypes) eq 'HASH') {
1.334 raeburn 3130: $newsettings{'inststatus'} = join(', ',map{ $usertypes->{$_}; } (@inststatuses));
1.286 raeburn 3131: } else {
1.337 raeburn 3132: $newsettings{'inststatus'} = join(', ',@inststatuses);
1.286 raeburn 3133: }
1.334 raeburn 3134: }
3135: } else {
3136: $newinststatus = '';
3137: $changeHash{'inststatus'} = $newinststatus;
3138: $newsettings{'inststatus'} = $othertitle;
3139: if ($newinststatus ne $oldinststatus) {
3140: $changed{'inststatus'} = $changeHash{'inststatus'};
1.378 raeburn 3141: foreach my $name ('portfolio','author') {
3142: ($newdefquota{$name},$newsettingstatus{$name}) =
3143: &Apache::loncommon::default_quota($env{'form.ccdomain'},$newinststatus,$name);
3144: }
1.286 raeburn 3145: }
3146: }
1.334 raeburn 3147: } elsif ($context ne 'selfcreate') {
3148: $canshow{'inststatus'} = 1;
1.337 raeburn 3149: $newsettings{'inststatus'} = $oldsettings{'inststatus'};
1.286 raeburn 3150: }
1.378 raeburn 3151: foreach my $name ('portfolio','author') {
3152: $changeHash{$name.'quota'} = $userenv{$name.'quota'};
3153: }
1.334 raeburn 3154: if ($context eq 'domain') {
1.378 raeburn 3155: foreach my $name ('portfolio','author') {
3156: if ($userenv{$name.'quota'} ne '') {
3157: $oldquota{$name} = $userenv{$name.'quota'};
3158: if ($env{'form.custom_'.$name.'quota'} == 1) {
3159: if ($env{'form.'.$name.'quota'} eq '') {
3160: $newquota{$name} = 0;
3161: } else {
3162: $newquota{$name} = $env{'form.'.$name.'quota'};
3163: $newquota{$name} =~ s/[^\d\.]//g;
3164: }
3165: if ($newquota{$name} != $oldquota{$name}) {
3166: if ("a_admin($newquota{$name},\%changeHash,$name)) {
3167: $changed{$name.'quota'} = 1;
3168: }
3169: }
1.334 raeburn 3170: } else {
1.378 raeburn 3171: if ("a_admin('',\%changeHash,$name)) {
3172: $changed{$name.'quota'} = 1;
3173: $newquota{$name} = $newdefquota{$name};
3174: $newisdefault{$name} = 1;
3175: }
1.334 raeburn 3176: }
1.149 raeburn 3177: } else {
1.378 raeburn 3178: $oldisdefault{$name} = 1;
3179: $oldquota{$name} = $olddefquota{$name};
3180: if ($env{'form.custom_'.$name.'quota'} == 1) {
3181: if ($env{'form.'.$name.'quota'} eq '') {
3182: $newquota{$name} = 0;
3183: } else {
3184: $newquota{$name} = $env{'form.'.$name.'quota'};
3185: $newquota{$name} =~ s/[^\d\.]//g;
3186: }
3187: if ("a_admin($newquota{$name},\%changeHash,$name)) {
3188: $changed{$name.'quota'} = 1;
3189: }
1.334 raeburn 3190: } else {
1.378 raeburn 3191: $newquota{$name} = $newdefquota{$name};
3192: $newisdefault{$name} = 1;
1.334 raeburn 3193: }
1.378 raeburn 3194: }
3195: if ($oldisdefault{$name}) {
3196: $oldsettingstext{'quota'}{$name} = &get_defaultquota_text($oldsettingstatus{$name});
1.383 raeburn 3197: } else {
3198: $oldsettingstext{'quota'}{$name} = &mt('custom quota: [_1] MB',$oldquota{$name});
1.378 raeburn 3199: }
3200: if ($newisdefault{$name}) {
3201: $newsettingstext{'quota'}{$name} = &get_defaultquota_text($newsettingstatus{$name});
1.383 raeburn 3202: } else {
3203: $newsettingstext{'quota'}{$name} = &mt('custom quota: [_1] MB',$newquota{$name});
1.134 raeburn 3204: }
3205: }
1.334 raeburn 3206: &tool_changes('tools',\@usertools,\%oldsettings,\%oldsettingstext,\%userenv,
3207: \%changeHash,\%changed,\%newsettings,\%newsettingstext);
3208: if ($env{'form.ccdomain'} eq $env{'request.role.domain'}) {
3209: &tool_changes('requestcourses',\@requestcourses,\%oldsettings,\%oldsettingstext,
3210: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
1.384 raeburn 3211: &tool_changes('requestauthor',\@requestauthor,\%oldsettings,\%oldsettingstext,
3212: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
1.149 raeburn 3213: } else {
1.334 raeburn 3214: &tool_changes('reqcrsotherdom',\@requestcourses,\%oldsettings,\%oldsettingstext,
3215: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
1.149 raeburn 3216: }
3217: }
1.334 raeburn 3218: foreach my $item (@userinfo) {
3219: if ($env{'form.c'.$item} ne $userenv{$item}) {
3220: $namechanged{$item} = 1;
3221: }
1.204 raeburn 3222: }
1.378 raeburn 3223: foreach my $name ('portfolio','author') {
1.390 bisitz 3224: $oldsettings{'quota'}{$name} = &mt('[_1] MB',$oldquota{$name});
3225: $newsettings{'quota'}{$name} = &mt('[_1] MB',$newquota{$name});
1.378 raeburn 3226: }
1.334 raeburn 3227: if ((keys(%namechanged) > 0) || (keys(%changed) > 0)) {
1.267 raeburn 3228: my ($chgresult,$namechgresult);
3229: if (keys(%changed) > 0) {
3230: $chgresult =
1.204 raeburn 3231: &Apache::lonnet::put('environment',\%changeHash,
3232: $env{'form.ccdomain'},$env{'form.ccuname'});
1.267 raeburn 3233: if ($chgresult eq 'ok') {
3234: if (($env{'user.name'} eq $env{'form.ccuname'}) &&
3235: ($env{'user.domain'} eq $env{'form.ccdomain'})) {
1.270 raeburn 3236: my %newenvhash;
3237: foreach my $key (keys(%changed)) {
1.411 raeburn 3238: if (($key eq 'official') || ($key eq 'unofficial') ||
3239: ($key eq 'community') || ($key eq 'textbook') ||
3240: ($key eq 'placement')) {
1.279 raeburn 3241: $newenvhash{'environment.requestcourses.'.$key} =
3242: $changeHash{'requestcourses.'.$key};
1.362 raeburn 3243: if ($changeHash{'requestcourses.'.$key}) {
1.332 raeburn 3244: $newenvhash{'environment.canrequest.'.$key} = 1;
1.279 raeburn 3245: } else {
3246: $newenvhash{'environment.canrequest.'.$key} =
3247: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
3248: $key,'reload','requestcourses');
3249: }
1.362 raeburn 3250: } elsif ($key eq 'requestauthor') {
3251: $newenvhash{'environment.'.$key} = $changeHash{$key};
3252: if ($changeHash{$key}) {
3253: $newenvhash{'environment.canrequest.author'} = 1;
3254: } else {
3255: $newenvhash{'environment.canrequest.author'} =
3256: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
3257: $key,'reload','requestauthor');
3258: }
1.275 raeburn 3259: } elsif ($key ne 'quota') {
1.270 raeburn 3260: $newenvhash{'environment.tools.'.$key} =
3261: $changeHash{'tools.'.$key};
1.279 raeburn 3262: if ($changeHash{'tools.'.$key} ne '') {
3263: $newenvhash{'environment.availabletools.'.$key} =
3264: $changeHash{'tools.'.$key};
3265: } else {
3266: $newenvhash{'environment.availabletools.'.$key} =
1.367 golterma 3267: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
3268: $key,'reload','tools');
1.279 raeburn 3269: }
1.270 raeburn 3270: }
3271: }
1.271 raeburn 3272: if (keys(%newenvhash)) {
3273: &Apache::lonnet::appenv(\%newenvhash);
3274: }
1.267 raeburn 3275: }
3276: }
1.204 raeburn 3277: }
1.334 raeburn 3278: if (keys(%namechanged) > 0) {
1.337 raeburn 3279: foreach my $field (@userinfo) {
3280: $changeHash{$field} = $env{'form.c'.$field};
3281: }
3282: # Make the change
1.204 raeburn 3283: $namechgresult =
3284: &Apache::lonnet::modifyuser($env{'form.ccdomain'},
3285: $env{'form.ccuname'},$changeHash{'id'},undef,undef,
3286: $changeHash{'firstname'},$changeHash{'middlename'},
3287: $changeHash{'lastname'},$changeHash{'generation'},
1.337 raeburn 3288: $changeHash{'id'},undef,$changeHash{'permanentemail'},undef,\@userinfo);
1.220 raeburn 3289: %userupdate = (
3290: lastname => $env{'form.clastname'},
3291: middlename => $env{'form.cmiddlename'},
3292: firstname => $env{'form.cfirstname'},
3293: generation => $env{'form.cgeneration'},
3294: id => $env{'form.cid'},
3295: );
1.204 raeburn 3296: }
1.334 raeburn 3297: if (((keys(%namechanged) > 0) && $namechgresult eq 'ok') ||
1.267 raeburn 3298: ((keys(%changed) > 0) && $chgresult eq 'ok')) {
1.28 matthew 3299: # Tell the user we changed the name
1.334 raeburn 3300: &display_userinfo($r,1,\@disporder,\%canshow,\@requestcourses,
1.362 raeburn 3301: \@usertools,\@requestauthor,\%userenv,\%changed,\%namechanged,
1.334 raeburn 3302: \%oldsettings, \%oldsettingstext,\%newsettings,
3303: \%newsettingstext);
1.203 raeburn 3304: if ($env{'form.cid'} ne $userenv{'id'}) {
3305: &Apache::lonnet::idput($env{'form.ccdomain'},
1.407 raeburn 3306: {$env{'form.ccuname'} => $env{'form.cid'}},$uhome,'ids');
1.203 raeburn 3307: if (($recurseid) &&
3308: (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'}))) {
3309: my $idresult =
3310: &Apache::lonuserutils::propagate_id_change(
3311: $env{'form.ccuname'},$env{'form.ccdomain'},
3312: \%userupdate);
3313: $r->print('<br />'.$idresult.'<br />');
3314: }
1.196 raeburn 3315: }
1.149 raeburn 3316: if (($env{'form.ccdomain'} eq $env{'user.domain'}) &&
3317: ($env{'form.ccuname'} eq $env{'user.name'})) {
3318: my %newenvhash;
3319: foreach my $key (keys(%changeHash)) {
3320: $newenvhash{'environment.'.$key} = $changeHash{$key};
3321: }
1.238 raeburn 3322: &Apache::lonnet::appenv(\%newenvhash);
1.149 raeburn 3323: }
1.28 matthew 3324: } else { # error occurred
1.389 bisitz 3325: $r->print(
3326: '<p class="LC_error">'
3327: .&mt('Unable to successfully change environment for [_1] in domain [_2].',
3328: '"'.$env{'form.ccuname'}.'"',
3329: '"'.$env{'form.ccdomain'}.'"')
3330: .'</p>');
1.28 matthew 3331: }
1.334 raeburn 3332: } else { # End of if ($env ... ) logic
1.275 raeburn 3333: # They did not want to change the users name, quota, tool availability,
3334: # or ability to request creation of courses,
1.267 raeburn 3335: # but we can still tell them what the name and quota and availabilities are
1.334 raeburn 3336: &display_userinfo($r,undef,\@disporder,\%canshow,\@requestcourses,
1.362 raeburn 3337: \@usertools,\@requestauthor,\%userenv,\%changed,\%namechanged,\%oldsettings,
1.334 raeburn 3338: \%oldsettingstext,\%newsettings,\%newsettingstext);
1.28 matthew 3339: }
1.206 raeburn 3340: if (@mod_disallowed) {
3341: my ($rolestr,$contextname);
3342: if (@longroles > 0) {
3343: $rolestr = join(', ',@longroles);
3344: } else {
3345: $rolestr = &mt('No roles');
3346: }
3347: if ($context eq 'course') {
1.399 bisitz 3348: $contextname = 'course';
1.206 raeburn 3349: } elsif ($context eq 'author') {
1.399 bisitz 3350: $contextname = 'co-author';
1.206 raeburn 3351: }
3352: $r->print(&mt('The following fields were not updated: ').'<ul>');
3353: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
3354: foreach my $field (@mod_disallowed) {
3355: $r->print('<li>'.$fieldtitles{$field}.'</li>'."\n");
3356: }
1.207 raeburn 3357: $r->print('</ul>');
3358: if (@mod_disallowed == 1) {
1.399 bisitz 3359: $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 3360: } else {
1.399 bisitz 3361: $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 3362: }
1.292 bisitz 3363: my $helplink = 'javascript:helpMenu('."'display'".')';
3364: $r->print('<span class="LC_cusr_emph">'.$rolestr.'</span><br />'
3365: .&mt('Please contact your [_1]helpdesk[_2] for more information.'
3366: ,'<a href="'.$helplink.'">','</a>')
3367: .'<br />');
1.206 raeburn 3368: }
1.259 bisitz 3369: $r->print('<span class="LC_warning">'
3370: .$no_forceid_alert
3371: .&Apache::lonuserutils::print_namespacing_alerts($env{'form.ccdomain'},\%alerts,\%curr_rules)
3372: .'</span>');
1.4 www 3373: }
1.367 golterma 3374: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
1.220 raeburn 3375: if ($env{'form.action'} eq 'singlestudent') {
1.375 raeburn 3376: &enroll_single_student($r,$uhome,$amode,$genpwd,$now,$newuser,$context,
3377: $crstype,$showcredits,$defaultcredits);
1.386 bisitz 3378: my $linktext = ($crstype eq 'Community' ?
3379: &mt('Enroll Another Member') : &mt('Enroll Another Student'));
3380: $r->print(
3381: &Apache::lonhtmlcommon::actionbox([
3382: '<a href="javascript:backPage(document.userupdate)">'
3383: .($crstype eq 'Community' ?
3384: &mt('Enroll Another Member') : &mt('Enroll Another Student'))
3385: .'</a>']));
1.220 raeburn 3386: } else {
1.375 raeburn 3387: my @rolechanges = &update_roles($r,$context,$showcredits);
1.334 raeburn 3388: if (keys(%namechanged) > 0) {
1.220 raeburn 3389: if ($context eq 'course') {
3390: if (@userroles > 0) {
1.225 raeburn 3391: if ((@rolechanges == 0) ||
3392: (!(grep(/^st$/,@rolechanges)))) {
3393: if (grep(/^st$/,@userroles)) {
3394: my $classlistupdated =
3395: &Apache::lonuserutils::update_classlist($cdom,
1.220 raeburn 3396: $cnum,$env{'form.ccdomain'},
3397: $env{'form.ccuname'},\%userupdate);
1.225 raeburn 3398: }
1.220 raeburn 3399: }
3400: }
3401: }
3402: }
1.226 raeburn 3403: my $userinfo = &Apache::loncommon::plainname($env{'form.ccuname'},
1.233 raeburn 3404: $env{'form.ccdomain'});
3405: if ($env{'form.popup'}) {
3406: $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a></p>');
3407: } else {
1.367 golterma 3408: $r->print('<br />'.&Apache::lonhtmlcommon::actionbox(['<a href="javascript:backPage(document.userupdate,'."'$env{'form.prevphase'}','modify'".')">'
3409: .&mt('Modify this user: [_1]','<span class="LC_cusr_emph">'.$env{'form.ccuname'}.':'.$env{'form.ccdomain'}.' ('.$userinfo.')</span>').'</a>',
3410: '<a href="javascript:backPage(document.userupdate)">'.&mt('Create/Modify Another User').'</a>']));
1.233 raeburn 3411: }
1.220 raeburn 3412: }
3413: }
3414:
1.334 raeburn 3415: sub display_userinfo {
1.362 raeburn 3416: my ($r,$changed,$order,$canshow,$requestcourses,$usertools,$requestauthor,
3417: $userenv,$changedhash,$namechangedhash,$oldsetting,$oldsettingtext,
1.334 raeburn 3418: $newsetting,$newsettingtext) = @_;
3419: return unless (ref($order) eq 'ARRAY' &&
3420: ref($canshow) eq 'HASH' &&
3421: ref($requestcourses) eq 'ARRAY' &&
1.362 raeburn 3422: ref($requestauthor) eq 'ARRAY' &&
1.334 raeburn 3423: ref($usertools) eq 'ARRAY' &&
3424: ref($userenv) eq 'HASH' &&
3425: ref($changedhash) eq 'HASH' &&
3426: ref($oldsetting) eq 'HASH' &&
3427: ref($oldsettingtext) eq 'HASH' &&
3428: ref($newsetting) eq 'HASH' &&
3429: ref($newsettingtext) eq 'HASH');
3430: my %lt=&Apache::lonlocal::texthash(
1.372 raeburn 3431: 'ui' => 'User Information',
1.334 raeburn 3432: 'uic' => 'User Information Changed',
3433: 'firstname' => 'First Name',
3434: 'middlename' => 'Middle Name',
3435: 'lastname' => 'Last Name',
3436: 'generation' => 'Generation',
3437: 'id' => 'Student/Employee ID',
3438: 'permanentemail' => 'Permanent e-mail address',
1.378 raeburn 3439: 'portfolioquota' => 'Disk space allocated to portfolio files',
1.385 bisitz 3440: 'authorquota' => 'Disk space allocated to Authoring Space',
1.334 raeburn 3441: 'blog' => 'Blog Availability',
1.361 raeburn 3442: 'webdav' => 'WebDAV Availability',
1.334 raeburn 3443: 'aboutme' => 'Personal Information Page Availability',
3444: 'portfolio' => 'Portfolio Availability',
3445: 'official' => 'Can Request Official Courses',
3446: 'unofficial' => 'Can Request Unofficial Courses',
3447: 'community' => 'Can Request Communities',
1.384 raeburn 3448: 'textbook' => 'Can Request Textbook Courses',
1.411 raeburn 3449: 'placement' => 'Can Request Placement Tests',
1.362 raeburn 3450: 'requestauthor' => 'Can Request Author Role',
1.334 raeburn 3451: 'inststatus' => "Affiliation",
3452: 'prvs' => 'Previous Value:',
3453: 'chto' => 'Changed To:'
3454: );
3455: if ($changed) {
1.372 raeburn 3456: $r->print('<h3>'.$lt{'uic'}.'</h3>'.
1.367 golterma 3457: &Apache::loncommon::start_data_table().
3458: &Apache::loncommon::start_data_table_header_row());
1.334 raeburn 3459: $r->print("<th> </th>\n");
1.367 golterma 3460: $r->print('<th><b>'.$lt{'prvs'}.'</b></th>');
3461: $r->print('<th><span class="LC_nobreak"><b>'.$lt{'chto'}.'</b></span></th>');
3462: $r->print(&Apache::loncommon::end_data_table_header_row());
3463: my @userinfo = ('firstname','middlename','lastname','generation','permanentemail','id');
3464:
1.334 raeburn 3465: foreach my $item (@userinfo) {
3466: my $value = $env{'form.c'.$item};
1.367 golterma 3467: #show changes only:
1.383 raeburn 3468: unless ($value eq $userenv->{$item}){
1.367 golterma 3469: $r->print(&Apache::loncommon::start_data_table_row());
3470: $r->print("<td>$lt{$item}</td>\n");
1.383 raeburn 3471: $r->print("<td>".$userenv->{$item}."</td>\n");
1.367 golterma 3472: $r->print("<td>$value </td>\n");
3473: $r->print(&Apache::loncommon::end_data_table_row());
1.334 raeburn 3474: }
3475: }
3476: foreach my $entry (@{$order}) {
1.383 raeburn 3477: if ($canshow->{$entry}) {
3478: if (($entry eq 'requestcourses') || ($entry eq 'reqcrsotherdom') || ($entry eq 'requestauthor')) {
3479: my @items;
3480: if ($entry eq 'requestauthor') {
3481: @items = ($entry);
3482: } else {
3483: @items = @{$requestcourses};
1.384 raeburn 3484: }
1.383 raeburn 3485: foreach my $item (@items) {
3486: if (($newsetting->{$item} ne $oldsetting->{$item}) ||
3487: ($newsettingtext->{$item} ne $oldsettingtext->{$item})) {
3488: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3489: $r->print("<td>$lt{$item}</td>\n");
3490: $r->print("<td>".$oldsetting->{$item});
3491: if ($oldsettingtext->{$item}) {
3492: if ($oldsetting->{$item}) {
3493: $r->print(' -- ');
3494: }
3495: $r->print($oldsettingtext->{$item});
3496: }
3497: $r->print("</td>\n");
3498: $r->print("<td>".$newsetting->{$item});
3499: if ($newsettingtext->{$item}) {
3500: if ($newsetting->{$item}) {
3501: $r->print(' -- ');
3502: }
3503: $r->print($newsettingtext->{$item});
3504: }
3505: $r->print("</td>\n");
3506: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.334 raeburn 3507: }
3508: }
3509: } elsif ($entry eq 'tools') {
3510: foreach my $item (@{$usertools}) {
1.383 raeburn 3511: if ($newsetting->{$item} ne $oldsetting->{$item}) {
3512: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3513: $r->print("<td>$lt{$item}</td>\n");
3514: $r->print("<td>".$oldsetting->{$item}.' '.$oldsettingtext->{$item}."</td>\n");
3515: $r->print("<td>".$newsetting->{$item}.' '.$newsettingtext->{$item}."</td>\n");
3516: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.334 raeburn 3517: }
3518: }
1.378 raeburn 3519: } elsif ($entry eq 'quota') {
3520: if ((ref($oldsetting->{$entry}) eq 'HASH') && (ref($oldsettingtext->{$entry}) eq 'HASH') &&
3521: (ref($newsetting->{$entry}) eq 'HASH') && (ref($newsettingtext->{$entry}) eq 'HASH')) {
3522: foreach my $name ('portfolio','author') {
1.383 raeburn 3523: if ($newsetting->{$entry}->{$name} ne $oldsetting->{$entry}->{$name}) {
3524: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3525: $r->print("<td>$lt{$name.$entry}</td>\n");
3526: $r->print("<td>".$oldsettingtext->{$entry}->{$name}."</td>\n");
3527: $r->print("<td>".$newsettingtext->{$entry}->{$name}."</td>\n");
3528: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.378 raeburn 3529: }
3530: }
3531: }
1.334 raeburn 3532: } else {
1.383 raeburn 3533: if ($newsetting->{$entry} ne $oldsetting->{$entry}) {
3534: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3535: $r->print("<td>$lt{$entry}</td>\n");
3536: $r->print("<td>".$oldsetting->{$entry}.' '.$oldsettingtext->{$entry}."</td>\n");
3537: $r->print("<td>".$newsetting->{$entry}.' '.$newsettingtext->{$entry}."</td>\n");
3538: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.334 raeburn 3539: }
3540: }
3541: }
3542: }
1.367 golterma 3543: $r->print(&Apache::loncommon::end_data_table().'<br />');
1.372 raeburn 3544: } else {
3545: $r->print('<h3>'.$lt{'ui'}.'</h3>'.
3546: '<p>'.&mt('No changes made to user information').'</p>');
1.334 raeburn 3547: }
3548: return;
3549: }
3550:
1.275 raeburn 3551: sub tool_changes {
3552: my ($context,$usertools,$oldaccess,$oldaccesstext,$userenv,$changeHash,
3553: $changed,$newaccess,$newaccesstext) = @_;
3554: if (!((ref($usertools) eq 'ARRAY') && (ref($oldaccess) eq 'HASH') &&
3555: (ref($oldaccesstext) eq 'HASH') && (ref($userenv) eq 'HASH') &&
3556: (ref($changeHash) eq 'HASH') && (ref($changed) eq 'HASH') &&
3557: (ref($newaccess) eq 'HASH') && (ref($newaccesstext) eq 'HASH'))) {
3558: return;
3559: }
1.383 raeburn 3560: my %reqdisplay = &requestchange_display();
1.300 raeburn 3561: if ($context eq 'reqcrsotherdom') {
1.309 raeburn 3562: my @options = ('approval','validate','autolimit');
1.306 raeburn 3563: my $optregex = join('|',@options);
1.300 raeburn 3564: my $cdom = $env{'request.role.domain'};
3565: foreach my $tool (@{$usertools}) {
1.383 raeburn 3566: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
1.314 raeburn 3567: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
1.300 raeburn 3568: $changeHash->{$context.'.'.$tool} = $userenv->{$context.'.'.$tool};
1.383 raeburn 3569: my ($newop,$limit);
1.314 raeburn 3570: if ($env{'form.'.$context.'_'.$tool}) {
3571: $newop = $env{'form.'.$context.'_'.$tool};
3572: if ($newop eq 'autolimit') {
1.383 raeburn 3573: $limit = $env{'form.'.$context.'_'.$tool.'_limit'};
1.314 raeburn 3574: $limit =~ s/\D+//g;
3575: $newop .= '='.$limit;
3576: }
3577: }
1.300 raeburn 3578: if ($userenv->{$context.'.'.$tool} eq '') {
1.314 raeburn 3579: if ($newop) {
3580: $changed->{$tool}=&tool_admin($tool,$cdom.':'.$newop,
1.300 raeburn 3581: $changeHash,$context);
3582: if ($changed->{$tool}) {
1.383 raeburn 3583: if ($newop =~ /^autolimit/) {
3584: if ($limit) {
3585: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3586: } else {
3587: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3588: }
3589: } else {
3590: $newaccesstext->{$tool} = $reqdisplay{$newop};
3591: }
1.300 raeburn 3592: } else {
3593: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
3594: }
3595: }
3596: } else {
3597: my @curr = split(',',$userenv->{$context.'.'.$tool});
3598: my @new;
3599: my $changedoms;
1.314 raeburn 3600: foreach my $req (@curr) {
3601: if ($req =~ /^\Q$cdom\E\:($optregex\=?\d*)$/) {
3602: my $oldop = $1;
1.383 raeburn 3603: if ($oldop =~ /^autolimit=(\d*)/) {
3604: my $limit = $1;
3605: if ($limit) {
3606: $oldaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3607: } else {
3608: $oldaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3609: }
3610: } else {
3611: $oldaccesstext->{$tool} = $reqdisplay{$oldop};
3612: }
1.314 raeburn 3613: if ($oldop ne $newop) {
3614: $changedoms = 1;
3615: foreach my $item (@curr) {
3616: my ($reqdom,$option) = split(':',$item);
3617: unless ($reqdom eq $cdom) {
3618: push(@new,$item);
3619: }
3620: }
3621: if ($newop) {
3622: push(@new,$cdom.':'.$newop);
1.300 raeburn 3623: }
1.314 raeburn 3624: @new = sort(@new);
1.300 raeburn 3625: }
1.314 raeburn 3626: last;
1.300 raeburn 3627: }
1.314 raeburn 3628: }
3629: if ((!$changedoms) && ($newop)) {
1.300 raeburn 3630: $changedoms = 1;
1.306 raeburn 3631: @new = sort(@curr,$cdom.':'.$newop);
1.300 raeburn 3632: }
3633: if ($changedoms) {
1.314 raeburn 3634: my $newdomstr;
1.300 raeburn 3635: if (@new) {
3636: $newdomstr = join(',',@new);
3637: }
3638: $changed->{$tool}=&tool_admin($tool,$newdomstr,$changeHash,
3639: $context);
3640: if ($changed->{$tool}) {
3641: if ($env{'form.'.$context.'_'.$tool}) {
1.306 raeburn 3642: if ($env{'form.'.$context.'_'.$tool} eq 'autolimit') {
1.314 raeburn 3643: my $limit = $env{'form.'.$context.'_'.$tool.'_limit'};
3644: $limit =~ s/\D+//g;
3645: if ($limit) {
1.383 raeburn 3646: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
1.314 raeburn 3647: } else {
1.383 raeburn 3648: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
1.306 raeburn 3649: }
1.314 raeburn 3650: } else {
1.306 raeburn 3651: $newaccesstext->{$tool} = $reqdisplay{$env{'form.'.$context.'_'.$tool}};
3652: }
1.300 raeburn 3653: } else {
1.383 raeburn 3654: $newaccesstext->{$tool} = &mt("availability set to 'off'");
1.300 raeburn 3655: }
3656: }
3657: }
3658: }
3659: }
3660: return;
3661: }
1.275 raeburn 3662: foreach my $tool (@{$usertools}) {
1.383 raeburn 3663: my ($newval,$limit,$envkey);
1.362 raeburn 3664: $envkey = $context.'.'.$tool;
1.306 raeburn 3665: if ($context eq 'requestcourses') {
3666: $newval = $env{'form.crsreq_'.$tool};
3667: if ($newval eq 'autolimit') {
1.383 raeburn 3668: $limit = $env{'form.crsreq_'.$tool.'_limit'};
3669: $limit =~ s/\D+//g;
3670: $newval .= '='.$limit;
1.306 raeburn 3671: }
1.362 raeburn 3672: } elsif ($context eq 'requestauthor') {
3673: $newval = $env{'form.'.$context};
3674: $envkey = $context;
1.314 raeburn 3675: } else {
1.306 raeburn 3676: $newval = $env{'form.'.$context.'_'.$tool};
3677: }
1.362 raeburn 3678: if ($userenv->{$envkey} ne '') {
1.275 raeburn 3679: $oldaccess->{$tool} = &mt('custom');
1.383 raeburn 3680: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3681: if ($userenv->{$envkey} =~ /^autolimit=(\d*)$/) {
3682: my $currlimit = $1;
3683: if ($currlimit eq '') {
3684: $oldaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3685: } else {
3686: $oldaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$currlimit);
3687: }
3688: } elsif ($userenv->{$envkey}) {
3689: $oldaccesstext->{$tool} = $reqdisplay{$userenv->{$envkey}};
3690: } else {
3691: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
3692: }
1.275 raeburn 3693: } else {
1.383 raeburn 3694: if ($userenv->{$envkey}) {
3695: $oldaccesstext->{$tool} = &mt("availability set to 'on'");
3696: } else {
3697: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
3698: }
1.275 raeburn 3699: }
1.362 raeburn 3700: $changeHash->{$envkey} = $userenv->{$envkey};
1.275 raeburn 3701: if ($env{'form.custom'.$tool} == 1) {
1.362 raeburn 3702: if ($newval ne $userenv->{$envkey}) {
1.306 raeburn 3703: $changed->{$tool} = &tool_admin($tool,$newval,$changeHash,
3704: $context);
1.275 raeburn 3705: if ($changed->{$tool}) {
3706: $newaccess->{$tool} = &mt('custom');
1.383 raeburn 3707: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3708: if ($newval =~ /^autolimit/) {
3709: if ($limit) {
3710: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3711: } else {
3712: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3713: }
3714: } elsif ($newval) {
3715: $newaccesstext->{$tool} = $reqdisplay{$newval};
3716: } else {
3717: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3718: }
1.275 raeburn 3719: } else {
1.383 raeburn 3720: if ($newval) {
3721: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3722: } else {
3723: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3724: }
1.275 raeburn 3725: }
3726: } else {
3727: $newaccess->{$tool} = $oldaccess->{$tool};
1.383 raeburn 3728: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3729: if ($newval =~ /^autolimit/) {
3730: if ($limit) {
3731: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3732: } else {
3733: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3734: }
3735: } elsif ($newval) {
3736: $newaccesstext->{$tool} = $reqdisplay{$newval};
3737: } else {
3738: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3739: }
1.275 raeburn 3740: } else {
1.383 raeburn 3741: if ($userenv->{$context.'.'.$tool}) {
3742: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3743: } else {
3744: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3745: }
1.275 raeburn 3746: }
3747: }
3748: } else {
3749: $newaccess->{$tool} = $oldaccess->{$tool};
3750: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
3751: }
3752: } else {
3753: $changed->{$tool} = &tool_admin($tool,'',$changeHash,$context);
3754: if ($changed->{$tool}) {
3755: $newaccess->{$tool} = &mt('default');
3756: } else {
3757: $newaccess->{$tool} = $oldaccess->{$tool};
1.383 raeburn 3758: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3759: if ($newval =~ /^autolimit/) {
3760: if ($limit) {
3761: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3762: } else {
3763: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3764: }
3765: } elsif ($newval) {
3766: $newaccesstext->{$tool} = $reqdisplay{$newval};
3767: } else {
3768: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3769: }
1.275 raeburn 3770: } else {
1.383 raeburn 3771: if ($userenv->{$context.'.'.$tool}) {
3772: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3773: } else {
3774: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3775: }
1.275 raeburn 3776: }
3777: }
3778: }
3779: } else {
3780: $oldaccess->{$tool} = &mt('default');
3781: if ($env{'form.custom'.$tool} == 1) {
1.306 raeburn 3782: $changed->{$tool} = &tool_admin($tool,$newval,$changeHash,
3783: $context);
1.275 raeburn 3784: if ($changed->{$tool}) {
3785: $newaccess->{$tool} = &mt('custom');
1.383 raeburn 3786: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3787: if ($newval =~ /^autolimit/) {
3788: if ($limit) {
3789: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3790: } else {
3791: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3792: }
3793: } elsif ($newval) {
3794: $newaccesstext->{$tool} = $reqdisplay{$newval};
3795: } else {
3796: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3797: }
1.275 raeburn 3798: } else {
1.383 raeburn 3799: if ($newval) {
3800: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3801: } else {
3802: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3803: }
1.275 raeburn 3804: }
3805: } else {
3806: $newaccess->{$tool} = $oldaccess->{$tool};
3807: }
3808: } else {
3809: $newaccess->{$tool} = $oldaccess->{$tool};
3810: }
3811: }
3812: }
3813: return;
3814: }
3815:
1.220 raeburn 3816: sub update_roles {
1.375 raeburn 3817: my ($r,$context,$showcredits) = @_;
1.4 www 3818: my $now=time;
1.225 raeburn 3819: my @rolechanges;
1.220 raeburn 3820: my %disallowed;
1.73 sakharuk 3821: $r->print('<h3>'.&mt('Modifying Roles').'</h3>');
1.404 raeburn 3822: foreach my $key (keys(%env)) {
1.135 raeburn 3823: next if (! $env{$key});
1.190 raeburn 3824: next if ($key eq 'form.action');
1.27 matthew 3825: # Revoke roles
1.135 raeburn 3826: if ($key=~/^form\.rev/) {
3827: if ($key=~/^form\.rev\:([^\_]+)\_([^\_\.]+)$/) {
1.64 www 3828: # Revoke standard role
1.170 albertel 3829: my ($scope,$role) = ($1,$2);
3830: my $result =
3831: &Apache::lonnet::revokerole($env{'form.ccdomain'},
3832: $env{'form.ccuname'},
1.239 raeburn 3833: $scope,$role,'','',$context);
1.367 golterma 3834: $r->print(&Apache::lonhtmlcommon::confirm_success(
1.369 bisitz 3835: &mt('Revoking [_1] in [_2]',
3836: &Apache::lonnet::plaintext($role),
1.372 raeburn 3837: &Apache::loncommon::show_role_extent($scope,$context,$role)),
1.369 bisitz 3838: $result ne "ok").'<br />');
3839: if ($result ne "ok") {
3840: $r->print(&mt('Error: [_1]',$result).'<br />');
3841: }
1.170 albertel 3842: if ($role eq 'st') {
1.202 raeburn 3843: my $result =
1.198 raeburn 3844: &Apache::lonuserutils::classlist_drop($scope,
3845: $env{'form.ccuname'},$env{'form.ccdomain'},
1.202 raeburn 3846: $now);
1.367 golterma 3847: $r->print(&Apache::lonhtmlcommon::confirm_success($result));
1.53 www 3848: }
1.225 raeburn 3849: if (!grep(/^\Q$role\E$/,@rolechanges)) {
3850: push(@rolechanges,$role);
3851: }
1.196 raeburn 3852: }
1.195 raeburn 3853: if ($key=~m{^form\.rev\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}s) {
1.64 www 3854: # Revoke custom role
1.369 bisitz 3855: my $result = &Apache::lonnet::revokecustomrole(
3856: $env{'form.ccdomain'},$env{'form.ccuname'},$1,$2,$3,$4,'','',$context);
1.367 golterma 3857: $r->print(&Apache::lonhtmlcommon::confirm_success(
1.369 bisitz 3858: &mt('Revoking custom role [_1] by [_2] in [_3]',
1.372 raeburn 3859: $4,$3.':'.$2,&Apache::loncommon::show_role_extent($1,$context,'cr')),
1.369 bisitz 3860: $result ne 'ok').'<br />');
3861: if ($result ne "ok") {
3862: $r->print(&mt('Error: [_1]',$result).'<br />');
3863: }
1.225 raeburn 3864: if (!grep(/^cr$/,@rolechanges)) {
3865: push(@rolechanges,'cr');
3866: }
1.64 www 3867: }
1.135 raeburn 3868: } elsif ($key=~/^form\.del/) {
3869: if ($key=~/^form\.del\:([^\_]+)\_([^\_\.]+)$/) {
1.116 raeburn 3870: # Delete standard role
1.170 albertel 3871: my ($scope,$role) = ($1,$2);
3872: my $result =
3873: &Apache::lonnet::assignrole($env{'form.ccdomain'},
3874: $env{'form.ccuname'},
1.239 raeburn 3875: $scope,$role,$now,0,1,'',
3876: $context);
1.367 golterma 3877: $r->print(&Apache::lonhtmlcommon::confirm_success(
3878: &mt('Deleting [_1] in [_2]',
1.369 bisitz 3879: &Apache::lonnet::plaintext($role),
1.372 raeburn 3880: &Apache::loncommon::show_role_extent($scope,$context,$role)),
1.369 bisitz 3881: $result ne 'ok').'<br />');
3882: if ($result ne "ok") {
3883: $r->print(&mt('Error: [_1]',$result).'<br />');
3884: }
1.367 golterma 3885:
1.170 albertel 3886: if ($role eq 'st') {
1.202 raeburn 3887: my $result =
1.198 raeburn 3888: &Apache::lonuserutils::classlist_drop($scope,
3889: $env{'form.ccuname'},$env{'form.ccdomain'},
1.202 raeburn 3890: $now);
1.369 bisitz 3891: $r->print(&Apache::lonhtmlcommon::confirm_success($result));
1.81 albertel 3892: }
1.225 raeburn 3893: if (!grep(/^\Q$role\E$/,@rolechanges)) {
3894: push(@rolechanges,$role);
3895: }
1.116 raeburn 3896: }
1.139 albertel 3897: if ($key=~m{^form\.del\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
1.116 raeburn 3898: my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
3899: # Delete custom role
1.369 bisitz 3900: my $result =
3901: &Apache::lonnet::assigncustomrole($env{'form.ccdomain'},
3902: $env{'form.ccuname'},$url,$rdom,$rnam,$rolename,$now,
3903: 0,1,$context);
3904: $r->print(&Apache::lonhtmlcommon::confirm_success(&mt('Deleting custom role [_1] by [_2] in [_3]',
1.372 raeburn 3905: $rolename,$rnam.':'.$rdom,&Apache::loncommon::show_role_extent($1,$context,'cr')),
1.369 bisitz 3906: $result ne "ok").'<br />');
3907: if ($result ne "ok") {
3908: $r->print(&mt('Error: [_1]',$result).'<br />');
3909: }
1.367 golterma 3910:
1.225 raeburn 3911: if (!grep(/^cr$/,@rolechanges)) {
3912: push(@rolechanges,'cr');
3913: }
1.116 raeburn 3914: }
1.135 raeburn 3915: } elsif ($key=~/^form\.ren/) {
1.101 albertel 3916: my $udom = $env{'form.ccdomain'};
3917: my $uname = $env{'form.ccuname'};
1.116 raeburn 3918: # Re-enable standard role
1.135 raeburn 3919: if ($key=~/^form\.ren\:([^\_]+)\_([^\_\.]+)$/) {
1.89 raeburn 3920: my $url = $1;
3921: my $role = $2;
3922: my $logmsg;
3923: my $output;
3924: if ($role eq 'st') {
1.141 albertel 3925: if ($url =~ m-^/($match_domain)/($match_courseid)/?(\w*)$-) {
1.374 raeburn 3926: my ($cdom,$cnum,$csec) = ($1,$2,$3);
1.375 raeburn 3927: my $credits;
3928: if ($showcredits) {
3929: my $defaultcredits =
3930: &Apache::lonuserutils::get_defaultcredits($cdom,$cnum);
3931: $credits = &get_user_credits($defaultcredits,$cdom,$cnum);
3932: }
3933: my $result = &Apache::loncommon::commit_studentrole(\$logmsg,$udom,$uname,$url,$role,$now,0,$cdom,$cnum,$csec,$context,$credits);
1.220 raeburn 3934: if (($result =~ /^error/) || ($result eq 'not_in_class') || ($result eq 'unknown_course') || ($result eq 'refused')) {
1.223 raeburn 3935: if ($result eq 'refused' && $logmsg) {
3936: $output = $logmsg;
3937: } else {
1.369 bisitz 3938: $output = &mt('Error: [_1]',$result)."\n";
1.223 raeburn 3939: }
1.89 raeburn 3940: } else {
1.372 raeburn 3941: $output = &Apache::lonhtmlcommon::confirm_success(&mt('Assigning [_1] in [_2] starting [_3]',
3942: &Apache::lonnet::plaintext($role),
3943: &Apache::loncommon::show_role_extent($url,$context,'st'),
3944: &Apache::lonlocal::locallocaltime($now))).'<br />'.$logmsg.'<br />';
1.89 raeburn 3945: }
3946: }
3947: } else {
1.101 albertel 3948: my $result=&Apache::lonnet::assignrole($env{'form.ccdomain'},
1.239 raeburn 3949: $env{'form.ccuname'},$url,$role,0,$now,'','',
3950: $context);
1.367 golterma 3951: $output = &Apache::lonhtmlcommon::confirm_success(&mt('Re-enabling [_1] in [_2]',
1.372 raeburn 3952: &Apache::lonnet::plaintext($role),
3953: &Apache::loncommon::show_role_extent($url,$context,$role)),$result ne "ok").'<br />';
1.369 bisitz 3954: if ($result ne "ok") {
3955: $output .= &mt('Error: [_1]',$result).'<br />';
3956: }
3957: }
1.89 raeburn 3958: $r->print($output);
1.225 raeburn 3959: if (!grep(/^\Q$role\E$/,@rolechanges)) {
3960: push(@rolechanges,$role);
3961: }
1.113 raeburn 3962: }
1.116 raeburn 3963: # Re-enable custom role
1.139 albertel 3964: if ($key=~m{^form\.ren\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
1.116 raeburn 3965: my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
3966: my $result = &Apache::lonnet::assigncustomrole(
3967: $env{'form.ccdomain'}, $env{'form.ccuname'},
1.240 raeburn 3968: $url,$rdom,$rnam,$rolename,0,$now,undef,$context);
1.369 bisitz 3969: $r->print(&Apache::lonhtmlcommon::confirm_success(
3970: &mt('Re-enabling custom role [_1] by [_2] in [_3]',
1.372 raeburn 3971: $rolename,$rnam.':'.$rdom,&Apache::loncommon::show_role_extent($1,$context,'cr')),
1.369 bisitz 3972: $result ne "ok").'<br />');
3973: if ($result ne "ok") {
3974: $r->print(&mt('Error: [_1]',$result).'<br />');
3975: }
1.225 raeburn 3976: if (!grep(/^cr$/,@rolechanges)) {
3977: push(@rolechanges,'cr');
3978: }
1.116 raeburn 3979: }
1.135 raeburn 3980: } elsif ($key=~/^form\.act/) {
1.101 albertel 3981: my $udom = $env{'form.ccdomain'};
3982: my $uname = $env{'form.ccuname'};
1.141 albertel 3983: if ($key=~/^form\.act\_($match_domain)\_($match_courseid)\_cr_cr_($match_domain)_($match_username)_([^\_]+)$/) {
1.65 www 3984: # Activate a custom role
1.83 albertel 3985: my ($one,$two,$three,$four,$five)=($1,$2,$3,$4,$5);
3986: my $url='/'.$one.'/'.$two;
3987: my $full=$one.'_'.$two.'_cr_cr_'.$three.'_'.$four.'_'.$five;
1.65 www 3988:
1.101 albertel 3989: my $start = ( $env{'form.start_'.$full} ?
3990: $env{'form.start_'.$full} :
1.88 raeburn 3991: $now );
1.101 albertel 3992: my $end = ( $env{'form.end_'.$full} ?
3993: $env{'form.end_'.$full} :
1.88 raeburn 3994: 0 );
3995:
3996: # split multiple sections
3997: my %sections = ();
1.101 albertel 3998: my $num_sections = &build_roles($env{'form.sec_'.$full},\%sections,$5);
1.88 raeburn 3999: if ($num_sections == 0) {
1.240 raeburn 4000: $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$url,$three,$four,$five,$start,$end,$context));
1.88 raeburn 4001: } else {
1.114 albertel 4002: my %curr_groups =
1.117 raeburn 4003: &Apache::longroup::coursegroups($one,$two);
1.404 raeburn 4004: foreach my $sec (sort {$a cmp $b} keys(%sections)) {
1.113 raeburn 4005: if (($sec eq 'none') || ($sec eq 'all') ||
4006: exists($curr_groups{$sec})) {
4007: $disallowed{$sec} = $url;
4008: next;
4009: }
4010: my $securl = $url.'/'.$sec;
1.240 raeburn 4011: $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$securl,$three,$four,$five,$start,$end,$context));
1.88 raeburn 4012: }
4013: }
1.225 raeburn 4014: if (!grep(/^cr$/,@rolechanges)) {
4015: push(@rolechanges,'cr');
4016: }
1.142 raeburn 4017: } elsif ($key=~/^form\.act\_($match_domain)\_($match_name)\_([^\_]+)$/) {
1.27 matthew 4018: # Activate roles for sections with 3 id numbers
4019: # set start, end times, and the url for the class
1.83 albertel 4020: my ($one,$two,$three)=($1,$2,$3);
1.101 albertel 4021: my $start = ( $env{'form.start_'.$one.'_'.$two.'_'.$three} ?
4022: $env{'form.start_'.$one.'_'.$two.'_'.$three} :
1.27 matthew 4023: $now );
1.101 albertel 4024: my $end = ( $env{'form.end_'.$one.'_'.$two.'_'.$three} ?
4025: $env{'form.end_'.$one.'_'.$two.'_'.$three} :
1.27 matthew 4026: 0 );
1.83 albertel 4027: my $url='/'.$one.'/'.$two;
1.88 raeburn 4028: my $type = 'three';
4029: # split multiple sections
4030: my %sections = ();
1.101 albertel 4031: my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two.'_'.$three},\%sections,$three);
1.375 raeburn 4032: my $credits;
4033: if ($three eq 'st') {
4034: if ($showcredits) {
4035: my $defaultcredits =
4036: &Apache::lonuserutils::get_defaultcredits($one,$two);
4037: $credits = $env{'form.credits_'.$one.'_'.$two.'_'.$three};
4038: $credits =~ s/[^\d\.]//g;
4039: if ($credits eq $defaultcredits) {
4040: undef($credits);
4041: }
4042: }
4043: }
1.88 raeburn 4044: if ($num_sections == 0) {
1.375 raeburn 4045: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'',$context,$credits));
1.88 raeburn 4046: } else {
1.114 albertel 4047: my %curr_groups =
1.117 raeburn 4048: &Apache::longroup::coursegroups($one,$two);
1.88 raeburn 4049: my $emptysec = 0;
1.404 raeburn 4050: foreach my $sec (sort {$a cmp $b} keys(%sections)) {
1.88 raeburn 4051: $sec =~ s/\W//g;
1.113 raeburn 4052: if ($sec ne '') {
4053: if (($sec eq 'none') || ($sec eq 'all') ||
4054: exists($curr_groups{$sec})) {
4055: $disallowed{$sec} = $url;
4056: next;
4057: }
1.88 raeburn 4058: my $securl = $url.'/'.$sec;
1.375 raeburn 4059: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$three,$start,$end,$one,$two,$sec,$context,$credits));
1.88 raeburn 4060: } else {
4061: $emptysec = 1;
4062: }
4063: }
4064: if ($emptysec) {
1.375 raeburn 4065: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'',$context,$credits));
1.88 raeburn 4066: }
1.225 raeburn 4067: }
4068: if (!grep(/^\Q$three\E$/,@rolechanges)) {
4069: push(@rolechanges,$three);
4070: }
1.135 raeburn 4071: } elsif ($key=~/^form\.act\_([^\_]+)\_([^\_]+)$/) {
1.27 matthew 4072: # Activate roles for sections with two id numbers
4073: # set start, end times, and the url for the class
1.101 albertel 4074: my $start = ( $env{'form.start_'.$1.'_'.$2} ?
4075: $env{'form.start_'.$1.'_'.$2} :
1.27 matthew 4076: $now );
1.101 albertel 4077: my $end = ( $env{'form.end_'.$1.'_'.$2} ?
4078: $env{'form.end_'.$1.'_'.$2} :
1.27 matthew 4079: 0 );
1.225 raeburn 4080: my $one = $1;
4081: my $two = $2;
4082: my $url='/'.$one.'/';
1.88 raeburn 4083: # split multiple sections
4084: my %sections = ();
1.225 raeburn 4085: my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two},\%sections,$two);
1.88 raeburn 4086: if ($num_sections == 0) {
1.240 raeburn 4087: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,'',$context));
1.88 raeburn 4088: } else {
4089: my $emptysec = 0;
1.404 raeburn 4090: foreach my $sec (sort {$a cmp $b} keys(%sections)) {
1.88 raeburn 4091: if ($sec ne '') {
4092: my $securl = $url.'/'.$sec;
1.240 raeburn 4093: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$two,$start,$end,$one,undef,$sec,$context));
1.88 raeburn 4094: } else {
4095: $emptysec = 1;
4096: }
4097: }
4098: if ($emptysec) {
1.240 raeburn 4099: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,'',$context));
1.88 raeburn 4100: }
4101: }
1.225 raeburn 4102: if (!grep(/^\Q$two\E$/,@rolechanges)) {
4103: push(@rolechanges,$two);
4104: }
1.64 www 4105: } else {
1.190 raeburn 4106: $r->print('<p><span class="LC_error">'.&mt('ERROR').': '.&mt('Unknown command').' <tt>'.$key.'</tt></span></p><br />');
1.64 www 4107: }
1.113 raeburn 4108: foreach my $key (sort(keys(%disallowed))) {
1.274 bisitz 4109: $r->print('<p class="LC_warning">');
1.113 raeburn 4110: if (($key eq 'none') || ($key eq 'all')) {
1.274 bisitz 4111: $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 4112: } else {
1.274 bisitz 4113: $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 4114: }
1.274 bisitz 4115: $r->print('</p><p>'
4116: .&mt('Please [_1]go back[_2] and choose a different section name.'
4117: ,'<a href="javascript:history.go(-1)'
4118: ,'</a>')
4119: .'</p><br />'
4120: );
1.113 raeburn 4121: }
4122: }
1.101 albertel 4123: } # End of foreach (keys(%env))
1.75 www 4124: # Flush the course logs so reverse user roles immediately updated
1.349 raeburn 4125: $r->register_cleanup(\&Apache::lonnet::flushcourselogs);
1.225 raeburn 4126: if (@rolechanges == 0) {
1.372 raeburn 4127: $r->print('<p>'.&mt('No roles to modify').'</p>');
1.193 raeburn 4128: }
1.225 raeburn 4129: return @rolechanges;
1.220 raeburn 4130: }
4131:
1.375 raeburn 4132: sub get_user_credits {
4133: my ($uname,$udom,$defaultcredits,$cdom,$cnum) = @_;
4134: if ($cdom eq '' || $cnum eq '') {
4135: return unless ($env{'request.course.id'});
4136: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
4137: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
4138: }
4139: my $credits;
4140: my %currhash =
4141: &Apache::lonnet::get('classlist',[$uname.':'.$udom],$cdom,$cnum);
4142: if (keys(%currhash) > 0) {
4143: my @items = split(/:/,$currhash{$uname.':'.$udom});
4144: my $crdidx = &Apache::loncoursedata::CL_CREDITS() - 3;
4145: $credits = $items[$crdidx];
4146: $credits =~ s/[^\d\.]//g;
4147: }
4148: if ($credits eq $defaultcredits) {
4149: undef($credits);
4150: }
4151: return $credits;
4152: }
4153:
1.220 raeburn 4154: sub enroll_single_student {
1.375 raeburn 4155: my ($r,$uhome,$amode,$genpwd,$now,$newuser,$context,$crstype,
4156: $showcredits,$defaultcredits) = @_;
1.318 raeburn 4157: $r->print('<h3>');
4158: if ($crstype eq 'Community') {
4159: $r->print(&mt('Enrolling Member'));
4160: } else {
4161: $r->print(&mt('Enrolling Student'));
4162: }
4163: $r->print('</h3>');
1.220 raeburn 4164:
4165: # Remove non alphanumeric values from section
4166: $env{'form.sections'}=~s/\W//g;
4167:
1.375 raeburn 4168: my $credits;
4169: if (($showcredits) && ($env{'form.credits'} ne '')) {
4170: $credits = $env{'form.credits'};
4171: $credits =~ s/[^\d\.]//g;
4172: if ($credits ne '') {
4173: if ($credits eq $defaultcredits) {
4174: undef($credits);
4175: }
4176: }
4177: }
4178:
1.220 raeburn 4179: # Clean out any old student roles the user has in this class.
4180: &Apache::lonuserutils::modifystudent($env{'form.ccdomain'},
4181: $env{'form.ccuname'},$env{'request.course.id'},undef,$uhome);
4182: my ($startdate,$enddate) = &Apache::lonuserutils::get_dates_from_form();
4183: my $enroll_result =
4184: &Apache::lonnet::modify_student_enrollment($env{'form.ccdomain'},
4185: $env{'form.ccuname'},$env{'form.cid'},$env{'form.cfirstname'},
4186: $env{'form.cmiddlename'},$env{'form.clastname'},
4187: $env{'form.generation'},$env{'form.sections'},$enddate,
1.375 raeburn 4188: $startdate,'manual',undef,$env{'request.course.id'},'',$context,
4189: $credits);
1.220 raeburn 4190: if ($enroll_result =~ /^ok/) {
1.381 bisitz 4191: $r->print(&mt('[_1] enrolled','<b>'.$env{'form.ccuname'}.':'.$env{'form.ccdomain'}.'</b>'));
1.220 raeburn 4192: if ($env{'form.sections'} ne '') {
4193: $r->print(' '.&mt('in section [_1]',$env{'form.sections'}));
4194: }
4195: my ($showstart,$showend);
4196: if ($startdate <= $now) {
4197: $showstart = &mt('Access starts immediately');
4198: } else {
4199: $showstart = &mt('Access starts: ').&Apache::lonlocal::locallocaltime($startdate);
4200: }
4201: if ($enddate == 0) {
4202: $showend = &mt('ends: no ending date');
4203: } else {
4204: $showend = &mt('ends: ').&Apache::lonlocal::locallocaltime($enddate);
4205: }
4206: $r->print('.<br />'.$showstart.'; '.$showend);
4207: if ($startdate <= $now && !$newuser) {
1.386 bisitz 4208: $r->print('<p class="LC_info">');
1.318 raeburn 4209: if ($crstype eq 'Community') {
1.392 raeburn 4210: $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 4211: } else {
1.392 raeburn 4212: $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 4213: }
4214: $r->print('</p>');
1.220 raeburn 4215: }
4216: } else {
4217: $r->print(&mt('unable to enroll').": ".$enroll_result);
4218: }
4219: return;
1.188 raeburn 4220: }
4221:
1.204 raeburn 4222: sub get_defaultquota_text {
4223: my ($settingstatus) = @_;
4224: my $defquotatext;
4225: if ($settingstatus eq '') {
1.383 raeburn 4226: $defquotatext = &mt('default');
1.204 raeburn 4227: } else {
4228: my ($usertypes,$order) =
4229: &Apache::lonnet::retrieve_inst_usertypes($env{'form.ccdomain'});
4230: if ($usertypes->{$settingstatus} eq '') {
1.383 raeburn 4231: $defquotatext = &mt('default');
1.204 raeburn 4232: } else {
1.383 raeburn 4233: $defquotatext = &mt('default for [_1]',$usertypes->{$settingstatus});
1.204 raeburn 4234: }
4235: }
4236: return $defquotatext;
4237: }
4238:
1.188 raeburn 4239: sub update_result_form {
4240: my ($uhome) = @_;
4241: my $outcome =
1.367 golterma 4242: '<form name="userupdate" method="post" action="">'."\n";
1.160 raeburn 4243: foreach my $item ('srchby','srchin','srchtype','srchterm','srchdomain','ccuname','ccdomain') {
1.188 raeburn 4244: $outcome .= '<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n";
1.160 raeburn 4245: }
1.207 raeburn 4246: if ($env{'form.origname'} ne '') {
4247: $outcome .= '<input type="hidden" name="origname" value="'.$env{'form.origname'}.'" />'."\n";
4248: }
1.160 raeburn 4249: foreach my $item ('sortby','seluname','seludom') {
4250: if (exists($env{'form.'.$item})) {
1.188 raeburn 4251: $outcome .= '<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n";
1.160 raeburn 4252: }
4253: }
1.188 raeburn 4254: if ($uhome eq 'no_host') {
4255: $outcome .= '<input type="hidden" name="forcenewuser" value="1" />'."\n";
4256: }
4257: $outcome .= '<input type="hidden" name="phase" value="" />'."\n".
1.383 raeburn 4258: '<input type="hidden" name="currstate" value="" />'."\n".
4259: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n".
1.188 raeburn 4260: '</form>';
4261: return $outcome;
1.4 www 4262: }
4263:
1.149 raeburn 4264: sub quota_admin {
1.378 raeburn 4265: my ($setquota,$changeHash,$name) = @_;
1.149 raeburn 4266: my $quotachanged;
4267: if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
4268: # Current user has quota modification privileges
1.267 raeburn 4269: if (ref($changeHash) eq 'HASH') {
4270: $quotachanged = 1;
1.378 raeburn 4271: $changeHash->{$name.'quota'} = $setquota;
1.267 raeburn 4272: }
1.149 raeburn 4273: }
4274: return $quotachanged;
4275: }
4276:
1.267 raeburn 4277: sub tool_admin {
1.275 raeburn 4278: my ($tool,$settool,$changeHash,$context) = @_;
4279: my $canchange = 0;
1.279 raeburn 4280: if ($context eq 'requestcourses') {
1.275 raeburn 4281: if (&Apache::lonnet::allowed('ccc',$env{'form.ccdomain'})) {
4282: $canchange = 1;
4283: }
1.300 raeburn 4284: } elsif ($context eq 'reqcrsotherdom') {
4285: if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
4286: $canchange = 1;
4287: }
1.362 raeburn 4288: } elsif ($context eq 'requestauthor') {
4289: if (&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) {
4290: $canchange = 1;
4291: }
1.275 raeburn 4292: } elsif (&Apache::lonnet::allowed('mut',$env{'form.ccdomain'})) {
4293: # Current user has quota modification privileges
4294: $canchange = 1;
4295: }
1.267 raeburn 4296: my $toolchanged;
1.275 raeburn 4297: if ($canchange) {
1.267 raeburn 4298: if (ref($changeHash) eq 'HASH') {
4299: $toolchanged = 1;
1.362 raeburn 4300: if ($tool eq 'requestauthor') {
4301: $changeHash->{$context} = $settool;
4302: } else {
4303: $changeHash->{$context.'.'.$tool} = $settool;
4304: }
1.267 raeburn 4305: }
4306: }
4307: return $toolchanged;
4308: }
4309:
1.88 raeburn 4310: sub build_roles {
1.89 raeburn 4311: my ($sectionstr,$sections,$role) = @_;
1.88 raeburn 4312: my $num_sections = 0;
4313: if ($sectionstr=~ /,/) {
4314: my @secnums = split/,/,$sectionstr;
1.89 raeburn 4315: if ($role eq 'st') {
4316: $secnums[0] =~ s/\W//g;
4317: $$sections{$secnums[0]} = 1;
4318: $num_sections = 1;
4319: } else {
4320: foreach my $sec (@secnums) {
4321: $sec =~ ~s/\W//g;
1.150 banghart 4322: if (!($sec eq "")) {
1.89 raeburn 4323: if (exists($$sections{$sec})) {
4324: $$sections{$sec} ++;
4325: } else {
4326: $$sections{$sec} = 1;
4327: $num_sections ++;
4328: }
1.88 raeburn 4329: }
4330: }
4331: }
4332: } else {
4333: $sectionstr=~s/\W//g;
4334: unless ($sectionstr eq '') {
4335: $$sections{$sectionstr} = 1;
4336: $num_sections ++;
4337: }
4338: }
1.129 albertel 4339:
1.88 raeburn 4340: return $num_sections;
4341: }
4342:
1.58 www 4343: # ========================================================== Custom Role Editor
4344:
4345: sub custom_role_editor {
1.439 raeburn 4346: my ($r,$context,$brcrum,$prefix,$permission) = @_;
1.324 raeburn 4347: my $action = $env{'form.customroleaction'};
1.439 raeburn 4348: my ($rolename,$helpitem);
1.324 raeburn 4349: if ($action eq 'new') {
4350: $rolename=$env{'form.newrolename'};
4351: } else {
4352: $rolename=$env{'form.rolename'};
1.59 www 4353: }
4354:
1.324 raeburn 4355: my ($crstype,$context);
4356: if ($env{'request.course.id'}) {
4357: $crstype = &Apache::loncommon::course_type();
4358: $context = 'course';
1.439 raeburn 4359: $helpitem = 'Course_Editing_Custom_Roles';
1.324 raeburn 4360: } else {
4361: $context = 'domain';
1.414 raeburn 4362: $crstype = 'course';
1.439 raeburn 4363: $helpitem = 'Domain_Editing_Custom_Roles';
1.324 raeburn 4364: }
1.351 raeburn 4365:
4366: $rolename=~s/[^A-Za-z0-9]//gs;
4367: if (!$rolename || $env{'form.phase'} eq 'pickrole') {
1.439 raeburn 4368: &print_username_entry_form($r,$context,undef,undef,undef,$crstype,$brcrum,
4369: $permission);
1.351 raeburn 4370: return;
4371: }
4372:
1.414 raeburn 4373: my $formname = 'form1';
4374: my %privs=();
4375: my $body_top = '<h2>';
4376: # ------------------------------------------------------- Does this role exist?
1.59 www 4377: my ($rdummy,$roledef)=
4378: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
4379: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1.414 raeburn 4380: $body_top .= &mt('Existing Role').' "';
1.61 www 4381: # ------------------------------------------------- Get current role privileges
1.414 raeburn 4382: ($privs{'system'},$privs{'domain'},$privs{'course'})=split(/\_/,$roledef);
4383: if ($privs{'system'} =~ /bre\&S/) {
4384: if ($context eq 'domain') {
1.417 raeburn 4385: $crstype = 'Course';
1.414 raeburn 4386: } elsif ($crstype eq 'Community') {
4387: $privs{'system'} =~ s/bre\&S//;
4388: }
4389: } elsif ($context eq 'domain') {
4390: $crstype = 'Course';
1.324 raeburn 4391: }
1.59 www 4392: } else {
1.414 raeburn 4393: $body_top .= &mt('New Role').' "';
4394: $roledef='';
1.59 www 4395: }
1.153 banghart 4396: $body_top .= $rolename.'"</h2>';
1.414 raeburn 4397:
4398: # ------------------------------------------------------- What can be assigned?
4399: my %full=();
1.417 raeburn 4400: my %levels=(
1.414 raeburn 4401: course => {},
4402: domain => {},
4403: system => {},
4404: );
4405: my %levelscurrent=(
4406: course => {},
4407: domain => {},
4408: system => {},
4409: );
4410: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
1.160 raeburn 4411: my ($jsback,$elements) = &crumb_utilities();
1.414 raeburn 4412: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
1.417 raeburn 4413: my $head_script =
1.414 raeburn 4414: &Apache::lonuserutils::custom_roledefs_js($context,$crstype,$formname,
4415: \%full,\@templateroles,$jsback);
1.351 raeburn 4416: push (@{$brcrum},
1.414 raeburn 4417: {href => "javascript:backPage(document.$formname,'pickrole','')",
1.351 raeburn 4418: text => "Pick custom role",
4419: faq => 282,bug=>'Instructor Interface',},
1.414 raeburn 4420: {href => "javascript:backPage(document.$formname,'','')",
1.351 raeburn 4421: text => "Edit custom role",
4422: faq => 282,
4423: bug => 'Instructor Interface',
1.439 raeburn 4424: help => $helpitem}
1.351 raeburn 4425: );
4426: my $args = { bread_crumbs => $brcrum,
4427: bread_crumbs_component => 'User Management'};
4428: $r->print(&Apache::loncommon::start_page('Custom Role Editor',
4429: $head_script,$args).
4430: $body_top);
1.414 raeburn 4431: $r->print('<form name="'.$formname.'" method="post" action="">'."\n".
4432: &Apache::lonuserutils::custom_role_header($context,$crstype,
4433: \@templateroles,$prefix));
1.264 bisitz 4434:
1.61 www 4435: $r->print(<<ENDCCF);
4436: <input type="hidden" name="phase" value="set_custom_roles" />
4437: <input type="hidden" name="rolename" value="$rolename" />
4438: ENDCCF
1.414 raeburn 4439: $r->print(&Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
4440: \%levelscurrent,$prefix));
1.135 raeburn 4441: $r->print(&Apache::loncommon::end_data_table().
1.190 raeburn 4442: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'.
1.160 raeburn 4443: '<input type="hidden" name="startrolename" value="'.$env{'form.rolename'}.
1.417 raeburn 4444: '" />'."\n".'<input type="hidden" name="currstate" value="" />'."\n".
1.160 raeburn 4445: '<input type="reset" value="'.&mt("Reset").'" />'."\n".
1.351 raeburn 4446: '<input type="submit" value="'.&mt('Save').'" /></form>');
1.61 www 4447: }
1.414 raeburn 4448:
1.61 www 4449: # ---------------------------------------------------------- Call to definerole
4450: sub set_custom_role {
1.439 raeburn 4451: my ($r,$context,$brcrum,$prefix,$permission) = @_;
1.101 albertel 4452: my $rolename=$env{'form.rolename'};
1.63 www 4453: $rolename=~s/[^A-Za-z0-9]//gs;
1.150 banghart 4454: if (!$rolename) {
1.439 raeburn 4455: &custom_role_editor($r,$context,$brcrum,$prefix,$permission);
1.61 www 4456: return;
4457: }
1.160 raeburn 4458: my ($jsback,$elements) = &crumb_utilities();
1.301 bisitz 4459: my $jscript = '<script type="text/javascript">'
4460: .'// <![CDATA['."\n"
4461: .$jsback."\n"
4462: .'// ]]>'."\n"
4463: .'</script>'."\n";
1.439 raeburn 4464: my $helpitem = 'Course_Editing_Custom_Roles';
4465: if ($context eq 'domain') {
4466: $helpitem = 'Domain_Editing_Custom_Roles';
4467: }
1.352 raeburn 4468: push(@{$brcrum},
4469: {href => "javascript:backPage(document.customresult,'pickrole','')",
4470: text => "Pick custom role",
4471: faq => 282,
4472: bug => 'Instructor Interface',},
4473: {href => "javascript:backPage(document.customresult,'selected_custom_edit','')",
4474: text => "Edit custom role",
4475: faq => 282,
4476: bug => 'Instructor Interface',},
4477: {href => "javascript:backPage(document.customresult,'set_custom_roles','')",
4478: text => "Result",
4479: faq => 282,
4480: bug => 'Instructor Interface',
1.439 raeburn 4481: help => $helpitem,}
1.352 raeburn 4482: );
4483: my $args = { bread_crumbs => $brcrum,
1.414 raeburn 4484: bread_crumbs_component => 'User Management'};
1.351 raeburn 4485: $r->print(&Apache::loncommon::start_page('Save Custom Role',$jscript,$args));
1.160 raeburn 4486:
1.393 raeburn 4487: my $newrole;
1.61 www 4488: my ($rdummy,$roledef)=
1.110 albertel 4489: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
4490:
1.61 www 4491: # ------------------------------------------------------- Does this role exist?
1.188 raeburn 4492: $r->print('<h3>');
1.61 www 4493: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1.73 sakharuk 4494: $r->print(&mt('Existing Role').' "');
1.61 www 4495: } else {
1.73 sakharuk 4496: $r->print(&mt('New Role').' "');
1.61 www 4497: $roledef='';
1.393 raeburn 4498: $newrole = 1;
1.61 www 4499: }
1.188 raeburn 4500: $r->print($rolename.'"</h3>');
1.414 raeburn 4501: # ------------------------------------------------- Assign role and show result
1.61 www 4502:
1.387 bisitz 4503: my $errmsg;
1.414 raeburn 4504: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$prefix);
4505: # Assign role and return result
4506: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
4507: $newprivs{'c'});
1.387 bisitz 4508: if ($result ne 'ok') {
4509: $errmsg = ': '.$result;
4510: }
4511: my $message =
4512: &Apache::lonhtmlcommon::confirm_success(
4513: &mt('Defining Role').$errmsg, ($result eq 'ok' ? 0 : 1));
1.101 albertel 4514: if ($env{'request.course.id'}) {
4515: my $url='/'.$env{'request.course.id'};
1.63 www 4516: $url=~s/\_/\//g;
1.387 bisitz 4517: $result =
4518: &Apache::lonnet::assigncustomrole(
4519: $env{'user.domain'},$env{'user.name'},
4520: $url,
4521: $env{'user.domain'},$env{'user.name'},
4522: $rolename,undef,undef,undef,$context);
4523: if ($result ne 'ok') {
4524: $errmsg = ': '.$result;
4525: }
4526: $message .=
4527: '<br />'
4528: .&Apache::lonhtmlcommon::confirm_success(
4529: &mt('Assigning Role to Self').$errmsg, ($result eq 'ok' ? 0 : 1));
1.63 www 4530: }
1.380 bisitz 4531: $r->print(
1.387 bisitz 4532: &Apache::loncommon::confirmwrapper($message)
4533: .'<br />'
4534: .&Apache::lonhtmlcommon::actionbox([
4535: '<a href="javascript:backPage(document.customresult,'."'pickrole'".')">'
4536: .&mt('Create or edit another custom role')
4537: .'</a>'])
1.380 bisitz 4538: .'<form name="customresult" method="post" action="">'
1.387 bisitz 4539: .&Apache::lonhtmlcommon::echo_form_input([])
4540: .'</form>'
1.380 bisitz 4541: );
1.58 www 4542: }
4543:
1.2 www 4544: # ================================================================ Main Handler
4545: sub handler {
4546: my $r = shift;
4547: if ($r->header_only) {
1.68 www 4548: &Apache::loncommon::content_type($r,'text/html');
1.2 www 4549: $r->send_http_header;
4550: return OK;
4551: }
1.439 raeburn 4552: my ($context,$crstype,$cid,$cnum,$cdom,$allhelpitems);
4553:
1.190 raeburn 4554: if ($env{'request.course.id'}) {
4555: $context = 'course';
1.318 raeburn 4556: $crstype = &Apache::loncommon::course_type();
1.190 raeburn 4557: } elsif ($env{'request.role'} =~ /^au\./) {
1.206 raeburn 4558: $context = 'author';
1.190 raeburn 4559: } else {
4560: $context = 'domain';
4561: }
1.375 raeburn 4562:
1.439 raeburn 4563: my ($permission,$allowed) =
4564: &Apache::lonuserutils::get_permission($context,$crstype);
4565:
4566: if ($allowed) {
4567: my @allhelp;
4568: if ($context eq 'course') {
4569: $cid = $env{'request.course.id'};
4570: $cdom = $env{'course.'.$cid.'.domain'};
4571: $cnum = $env{'course.'.$cid.'.num'};
4572:
4573: if ($permission->{'cusr'}) {
4574: push(@allhelp,'Course_Create_Class_List');
4575: }
4576: if ($permission->{'view'} || $permission->{'cusr'}) {
4577: push(@allhelp,('Course_Change_Privileges','Course_View_Class_List'));
4578: }
4579: if ($permission->{'custom'}) {
4580: push(@allhelp,'Course_Editing_Custom_Roles');
4581: }
4582: if ($permission->{'cusr'}) {
4583: push(@allhelp,('Course_Add_Student','Course_Drop_Student'));
4584: }
4585: unless ($permission->{'cusr_section'}) {
4586: if (&Apache::lonnet::auto_run($cnum,$cdom) && (($permission->{'cusr'}) || ($permission->{'view'}))) {
4587: push(@allhelp,'Course_Automated_Enrollment');
4588: }
4589: if ($permission->{'selfenrolladmin'}) {
4590: push(@allhelp,'Course_Approve_Selfenroll');
4591: }
4592: }
4593: if ($permission->{'grp_manage'}) {
4594: push(@allhelp,'Course_Manage_Group');
4595: }
4596: if ($permission->{'view'} || $permission->{'cusr'}) {
4597: push(@allhelp,'Course_User_Logs');
4598: }
4599: } elsif ($context eq 'author') {
4600: push(@allhelp,('Author_Change_Privileges','Author_Create_Coauthor_List',
4601: 'Author_View_Coauthor_List','Author_User_Logs'));
4602: } else {
4603: if ($permission->{'cusr'}) {
4604: push(@allhelp,'Domain_Change_Privileges');
4605: if ($permission->{'activity'}) {
4606: push(@allhelp,'Domain_User_Access_Logs');
4607: }
4608: push(@allhelp,('Domain_Create_Users','Domain_View_Users_List'));
4609: if ($permission->{'custom'}) {
4610: push(@allhelp,'Domain_Editing_Custom_Roles');
4611: }
4612: push(@allhelp,('Domain_Role_Approvals','Domain_Username_Approvals','Domain_Change_Logs'));
4613: } elsif ($permission->{'view'}) {
4614: push(@allhelp,'Domain_View_Privileges');
4615: if ($permission->{'activity'}) {
4616: push(@allhelp,'Domain_User_Access_Logs');
4617: }
4618: push(@allhelp,('Domain_View_Users_List','Domain_Change_Logs'));
4619: }
4620: }
4621: if (@allhelp) {
4622: $allhelpitems = join(',',@allhelp);
4623: }
4624: }
4625:
1.190 raeburn 4626: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.233 raeburn 4627: ['action','state','callingform','roletype','showrole','bulkaction','popup','phase',
1.391 raeburn 4628: 'username','domain','srchterm','srchdomain','srchin','srchby','srchtype','queue']);
1.190 raeburn 4629: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.351 raeburn 4630: my $args;
4631: my $brcrum = [];
4632: my $bread_crumbs_component = 'User Management';
1.391 raeburn 4633: if (($env{'form.action'} ne 'dateselect') && ($env{'form.action'} ne 'displayuserreq')) {
1.351 raeburn 4634: $brcrum = [{href=>"/adm/createuser",
4635: text=>"User Management",
1.439 raeburn 4636: help=>$allhelpitems}
1.351 raeburn 4637: ];
1.202 raeburn 4638: }
1.190 raeburn 4639: if (!$allowed) {
1.358 raeburn 4640: if ($context eq 'course') {
4641: $r->internal_redirect('/adm/viewclasslist');
4642: return OK;
4643: }
1.190 raeburn 4644: $env{'user.error.msg'}=
4645: "/adm/createuser:cst:0:0:Cannot create/modify user data ".
4646: "or view user status.";
4647: return HTTP_NOT_ACCEPTABLE;
4648: }
4649:
4650: &Apache::loncommon::content_type($r,'text/html');
4651: $r->send_http_header;
4652:
1.375 raeburn 4653: my $showcredits;
4654: if ((($context eq 'course') && ($crstype eq 'Course')) ||
4655: ($context eq 'domain')) {
4656: my %domdefaults =
4657: &Apache::lonnet::get_domain_defaults($env{'request.role.domain'});
4658: if ($domdefaults{'officialcredits'} || $domdefaults{'unofficialcredits'}) {
4659: $showcredits = 1;
4660: }
4661: }
4662:
1.190 raeburn 4663: # Main switch on form.action and form.state, as appropriate
4664: if (! exists($env{'form.action'})) {
1.351 raeburn 4665: $args = {bread_crumbs => $brcrum,
4666: bread_crumbs_component => $bread_crumbs_component};
4667: $r->print(&header(undef,$args));
1.318 raeburn 4668: $r->print(&print_main_menu($permission,$context,$crstype));
1.190 raeburn 4669: } elsif ($env{'form.action'} eq 'upload' && $permission->{'cusr'}) {
1.439 raeburn 4670: my $helpitem = 'Course_Create_Class_List';
4671: if ($context eq 'author') {
4672: $helpitem = 'Author_Create_Coauthor_List';
4673: } elsif ($context eq 'domain') {
4674: $helpitem = 'Domain_Create_Users';
4675: }
1.351 raeburn 4676: push(@{$brcrum},
4677: { href => '/adm/createuser?action=upload&state=',
4678: text => 'Upload Users List',
1.439 raeburn 4679: help => $helpitem,
1.351 raeburn 4680: });
4681: $bread_crumbs_component = 'Upload Users List';
4682: $args = {bread_crumbs => $brcrum,
4683: bread_crumbs_component => $bread_crumbs_component};
4684: $r->print(&header(undef,$args));
1.190 raeburn 4685: $r->print('<form name="studentform" method="post" '.
4686: 'enctype="multipart/form-data" '.
4687: ' action="/adm/createuser">'."\n");
4688: if (! exists($env{'form.state'})) {
4689: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
4690: } elsif ($env{'form.state'} eq 'got_file') {
1.375 raeburn 4691: &Apache::lonuserutils::print_upload_manager_form($r,$context,$permission,
4692: $crstype,$showcredits);
1.190 raeburn 4693: } elsif ($env{'form.state'} eq 'enrolling') {
4694: if ($env{'form.datatoken'}) {
1.375 raeburn 4695: &Apache::lonuserutils::upfile_drop_add($r,$context,$permission,
4696: $showcredits);
1.190 raeburn 4697: }
4698: } else {
4699: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
4700: }
1.416 raeburn 4701: } elsif (((($env{'form.action'} eq 'singleuser') || ($env{'form.action'}
4702: eq 'singlestudent')) && ($permission->{'cusr'})) ||
1.418 raeburn 4703: (($env{'form.action'} eq 'singleuser') && ($permission->{'view'})) ||
1.416 raeburn 4704: (($env{'form.action'} eq 'accesslogs') && ($permission->{'activity'}))) {
1.190 raeburn 4705: my $phase = $env{'form.phase'};
4706: my @search = ('srchterm','srchby','srchin','srchtype','srchdomain');
1.192 albertel 4707: &Apache::loncreateuser::restore_prev_selections();
4708: my $srch;
4709: foreach my $item (@search) {
4710: $srch->{$item} = $env{'form.'.$item};
4711: }
1.207 raeburn 4712: if (($phase eq 'get_user_info') || ($phase eq 'userpicked') ||
1.416 raeburn 4713: ($phase eq 'createnewuser') || ($phase eq 'activity')) {
1.207 raeburn 4714: if ($env{'form.phase'} eq 'createnewuser') {
4715: my $response;
4716: if ($env{'form.srchterm'} !~ /^$match_username$/) {
1.366 bisitz 4717: my $response =
4718: '<span class="LC_warning">'
4719: .&mt('You must specify a valid username. Only the following are allowed:'
4720: .' letters numbers - . @')
4721: .'</span>';
1.221 raeburn 4722: $env{'form.phase'} = '';
1.375 raeburn 4723: &print_username_entry_form($r,$context,$response,$srch,undef,
1.439 raeburn 4724: $crstype,$brcrum,$permission);
1.207 raeburn 4725: } else {
4726: my $ccuname =&LONCAPA::clean_username($srch->{'srchterm'});
4727: my $ccdomain=&LONCAPA::clean_domain($srch->{'srchdomain'});
4728: &print_user_modification_page($r,$ccuname,$ccdomain,
1.221 raeburn 4729: $srch,$response,$context,
1.375 raeburn 4730: $permission,$crstype,$brcrum,
4731: $showcredits);
1.207 raeburn 4732: }
4733: } elsif ($env{'form.phase'} eq 'get_user_info') {
1.190 raeburn 4734: my ($currstate,$response,$forcenewuser,$results) =
1.221 raeburn 4735: &user_search_result($context,$srch);
1.190 raeburn 4736: if ($env{'form.currstate'} eq 'modify') {
4737: $currstate = $env{'form.currstate'};
4738: }
4739: if ($currstate eq 'select') {
4740: &print_user_selection_page($r,$response,$srch,$results,
1.351 raeburn 4741: \@search,$context,undef,$crstype,
4742: $brcrum);
1.416 raeburn 4743: } elsif (($currstate eq 'modify') || ($env{'form.action'} eq 'accesslogs')) {
4744: my ($ccuname,$ccdomain,$uhome);
1.190 raeburn 4745: if (($srch->{'srchby'} eq 'uname') &&
4746: ($srch->{'srchtype'} eq 'exact')) {
4747: $ccuname = $srch->{'srchterm'};
4748: $ccdomain= $srch->{'srchdomain'};
4749: } else {
4750: my @matchedunames = keys(%{$results});
4751: ($ccuname,$ccdomain) = split(/:/,$matchedunames[0]);
4752: }
4753: $ccuname =&LONCAPA::clean_username($ccuname);
4754: $ccdomain=&LONCAPA::clean_domain($ccdomain);
1.416 raeburn 4755: if ($env{'form.action'} eq 'accesslogs') {
4756: my $uhome;
4757: if (($ccuname ne '') && ($ccdomain ne '')) {
4758: $uhome = &Apache::lonnet::homeserver($ccuname,$ccdomain);
4759: }
4760: if (($uhome eq '') || ($uhome eq 'no_host')) {
4761: $env{'form.phase'} = '';
4762: undef($forcenewuser);
4763: #if ($response) {
4764: # unless ($response =~ m{\Q<br /><br />\E$}) {
4765: # $response .= '<br /><br />';
4766: # }
4767: #}
4768: &print_username_entry_form($r,$context,$response,$srch,
1.439 raeburn 4769: $forcenewuser,$crstype,$brcrum,
4770: $permission);
1.416 raeburn 4771: } else {
4772: &print_useraccesslogs_display($r,$ccuname,$ccdomain,$permission,$brcrum);
4773: }
4774: } else {
4775: if ($env{'form.forcenewuser'}) {
4776: $response = '';
4777: }
4778: &print_user_modification_page($r,$ccuname,$ccdomain,
4779: $srch,$response,$context,
4780: $permission,$crstype,$brcrum);
1.190 raeburn 4781: }
4782: } elsif ($currstate eq 'query') {
1.351 raeburn 4783: &print_user_query_page($r,'createuser',$brcrum);
1.190 raeburn 4784: } else {
1.229 raeburn 4785: $env{'form.phase'} = '';
1.207 raeburn 4786: &print_username_entry_form($r,$context,$response,$srch,
1.439 raeburn 4787: $forcenewuser,$crstype,$brcrum,
4788: $permission);
1.190 raeburn 4789: }
4790: } elsif ($env{'form.phase'} eq 'userpicked') {
4791: my $ccuname = &LONCAPA::clean_username($env{'form.seluname'});
4792: my $ccdomain = &LONCAPA::clean_domain($env{'form.seludom'});
1.416 raeburn 4793: if ($env{'form.action'} eq 'accesslogs') {
4794: &print_useraccesslogs_display($r,$ccuname,$ccdomain,$permission,$brcrum);
4795: } else {
4796: &print_user_modification_page($r,$ccuname,$ccdomain,$srch,'',
4797: $context,$permission,$crstype,
4798: $brcrum);
4799: }
4800: } elsif ($env{'form.action'} eq 'accesslogs') {
4801: my $ccuname = &LONCAPA::clean_username($env{'form.accessuname'});
4802: my $ccdomain = &LONCAPA::clean_domain($env{'form.accessudom'});
4803: &print_useraccesslogs_display($r,$ccuname,$ccdomain,$permission,$brcrum);
1.190 raeburn 4804: }
4805: } elsif ($env{'form.phase'} eq 'update_user_data') {
1.375 raeburn 4806: &update_user_data($r,$context,$crstype,$brcrum,$showcredits);
1.190 raeburn 4807: } else {
1.351 raeburn 4808: &print_username_entry_form($r,$context,undef,$srch,undef,$crstype,
1.439 raeburn 4809: $brcrum,$permission);
1.190 raeburn 4810: }
4811: } elsif ($env{'form.action'} eq 'custom' && $permission->{'custom'}) {
1.414 raeburn 4812: my $prefix;
1.190 raeburn 4813: if ($env{'form.phase'} eq 'set_custom_roles') {
1.439 raeburn 4814: &set_custom_role($r,$context,$brcrum,$prefix,$permission);
1.190 raeburn 4815: } else {
1.439 raeburn 4816: &custom_role_editor($r,$context,$brcrum,$prefix,$permission);
1.190 raeburn 4817: }
1.362 raeburn 4818: } elsif (($env{'form.action'} eq 'processauthorreq') &&
4819: ($permission->{'cusr'}) &&
4820: (&Apache::lonnet::allowed('cau',$env{'request.role.domain'}))) {
4821: push(@{$brcrum},
4822: {href => '/adm/createuser?action=processauthorreq',
1.385 bisitz 4823: text => 'Authoring Space requests',
1.362 raeburn 4824: help => 'Domain_Role_Approvals'});
4825: $bread_crumbs_component = 'Authoring requests';
4826: if ($env{'form.state'} eq 'done') {
4827: push(@{$brcrum},
4828: {href => '/adm/createuser?action=authorreqqueue',
4829: text => 'Result',
4830: help => 'Domain_Role_Approvals'});
4831: $bread_crumbs_component = 'Authoring request result';
4832: }
4833: $args = { bread_crumbs => $brcrum,
4834: bread_crumbs_component => $bread_crumbs_component};
1.391 raeburn 4835: my $js = &usernamerequest_javascript();
4836: $r->print(&header(&add_script($js),$args));
1.362 raeburn 4837: if (!exists($env{'form.state'})) {
4838: $r->print(&Apache::loncoursequeueadmin::display_queued_requests('requestauthor',
4839: $env{'request.role.domain'}));
4840: } elsif ($env{'form.state'} eq 'done') {
4841: $r->print('<h3>'.&mt('Authoring request processing').'</h3>'."\n");
4842: $r->print(&Apache::loncoursequeueadmin::update_request_queue('requestauthor',
4843: $env{'request.role.domain'}));
4844: }
1.391 raeburn 4845: } elsif (($env{'form.action'} eq 'processusernamereq') &&
4846: ($permission->{'cusr'}) &&
4847: (&Apache::lonnet::allowed('cau',$env{'request.role.domain'}))) {
4848: push(@{$brcrum},
4849: {href => '/adm/createuser?action=processusernamereq',
4850: text => 'LON-CAPA account requests',
4851: help => 'Domain_Username_Approvals'});
4852: $bread_crumbs_component = 'Account requests';
4853: if ($env{'form.state'} eq 'done') {
4854: push(@{$brcrum},
4855: {href => '/adm/createuser?action=usernamereqqueue',
4856: text => 'Result',
4857: help => 'Domain_Username_Approvals'});
4858: $bread_crumbs_component = 'LON-CAPA account request result';
4859: }
4860: $args = { bread_crumbs => $brcrum,
4861: bread_crumbs_component => $bread_crumbs_component};
4862: my $js = &usernamerequest_javascript();
4863: $r->print(&header(&add_script($js),$args));
4864: if (!exists($env{'form.state'})) {
4865: $r->print(&Apache::loncoursequeueadmin::display_queued_requests('requestusername',
4866: $env{'request.role.domain'}));
4867: } elsif ($env{'form.state'} eq 'done') {
4868: $r->print('<h3>'.&mt('LON-CAPA account request processing').'</h3>'."\n");
4869: $r->print(&Apache::loncoursequeueadmin::update_request_queue('requestusername',
4870: $env{'request.role.domain'}));
4871: }
4872: } elsif (($env{'form.action'} eq 'displayuserreq') &&
4873: ($permission->{'cusr'})) {
4874: my $dom = $env{'form.domain'};
4875: my $uname = $env{'form.username'};
4876: my $warning;
4877: if (($dom =~ /^$match_domain$/) && (&Apache::lonnet::domain($dom) ne '')) {
4878: if (($dom eq $env{'request.role.domain'}) && (&Apache::lonnet::allowed('ccc',$dom))) {
4879: if (($uname =~ /^$match_username$/) && ($env{'form.queue'} eq 'approval')) {
4880: my $uhome = &Apache::lonnet::homeserver($uname,$dom);
4881: if ($uhome eq 'no_host') {
4882: my $queue = $env{'form.queue'};
4883: my $reqkey = &escape($uname).'_'.$queue;
4884: my $namespace = 'usernamequeue';
4885: my $domconfig = &Apache::lonnet::get_domainconfiguser($dom);
4886: my %queued =
4887: &Apache::lonnet::get($namespace,[$reqkey],$dom,$domconfig);
4888: unless ($queued{$reqkey}) {
4889: $warning = &mt('No information was found for this LON-CAPA account request.');
4890: }
4891: } else {
4892: $warning = &mt('A LON-CAPA account already exists for the requested username and domain.');
4893: }
4894: } else {
4895: $warning = &mt('LON-CAPA account request status check is for an invalid username.');
4896: }
4897: } else {
4898: $warning = &mt('You do not have rights to view LON-CAPA account requests in the domain specified.');
4899: }
4900: } else {
4901: $warning = &mt('LON-CAPA account request status check is for an invalid domain.');
4902: }
4903: my $args = { only_body => 1 };
4904: $r->print(&header(undef,$args).
4905: '<h3>'.&mt('LON-CAPA Account Request Details').'</h3>');
4906: if ($warning ne '') {
4907: $r->print('<div class="LC_warning">'.$warning.'</div>');
4908: } else {
4909: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
4910: my $domconfiguser = &Apache::lonnet::get_domainconfiguser($dom);
4911: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
4912: if (ref($domconfig{'usercreation'}) eq 'HASH') {
4913: if (ref($domconfig{'usercreation'}{'cancreate'}) eq 'HASH') {
4914: if (ref($domconfig{'usercreation'}{'cancreate'}{'emailusername'}) eq 'HASH') {
4915: my %info =
4916: &Apache::lonnet::get('nohist_requestedusernames',[$uname],$dom,$domconfiguser);
4917: if (ref($info{$uname}) eq 'HASH') {
1.396 raeburn 4918: my $usertype = $info{$uname}{'inststatus'};
4919: unless ($usertype) {
4920: $usertype = 'default';
4921: }
4922: if (ref($domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}) eq 'HASH') {
4923: if ((ref($infofields) eq 'ARRAY') && (ref($infotitles) eq 'HASH')) {
4924: $r->print('<div>'.&Apache::lonhtmlcommon::start_pick_box());
4925: my ($num,$count,$showstatus);
4926: $count = scalar(keys(%{$domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}}));
4927: unless ($usertype eq 'default') {
4928: my ($othertitle,$usertypes,$types) =
4929: &Apache::loncommon::sorted_inst_types($dom);
4930: if (ref($usertypes) eq 'HASH') {
4931: if ($usertypes->{$usertype}) {
4932: $showstatus = $usertypes->{$usertype};
4933: $count ++;
4934: }
4935: }
4936: }
4937: foreach my $field (@{$infofields}) {
4938: next unless ($domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}{$field});
4939: next unless ($infotitles->{$field});
4940: $r->print(&Apache::lonhtmlcommon::row_title($infotitles->{$field}).
4941: $info{$uname}{$field});
4942: $num ++;
4943: if ($count == $num) {
4944: $r->print(&Apache::lonhtmlcommon::row_closure(1));
4945: } else {
4946: $r->print(&Apache::lonhtmlcommon::row_closure());
4947: }
4948: }
4949: if ($showstatus) {
4950: $r->print(&Apache::lonhtmlcommon::row_title(&mt('Status type (self-reported)')).
4951: $showstatus.
4952: &Apache::lonhtmlcommon::row_closure(1));
1.391 raeburn 4953: }
1.396 raeburn 4954: $r->print(&Apache::lonhtmlcommon::end_pick_box().'</div>');
1.391 raeburn 4955: }
4956: }
4957: }
4958: }
4959: }
4960: }
4961: $r->print(&close_popup_form());
4962: }
1.207 raeburn 4963: } elsif (($env{'form.action'} eq 'listusers') &&
4964: ($permission->{'view'} || $permission->{'cusr'})) {
1.439 raeburn 4965: my $helpitem = 'Course_View_Class_List';
4966: if ($context eq 'author') {
4967: $helpitem = 'Author_View_Coauthor_List';
4968: } elsif ($context eq 'domain') {
4969: $helpitem = 'Domain_View_Users_List';
4970: }
1.202 raeburn 4971: if ($env{'form.phase'} eq 'bulkchange') {
1.351 raeburn 4972: push(@{$brcrum},
4973: {href => '/adm/createuser?action=listusers',
4974: text => "List Users"},
4975: {href => "/adm/createuser",
4976: text => "Result",
1.439 raeburn 4977: help => $helpitem});
1.351 raeburn 4978: $bread_crumbs_component = 'Update Users';
4979: $args = {bread_crumbs => $brcrum,
4980: bread_crumbs_component => $bread_crumbs_component};
4981: $r->print(&header(undef,$args));
1.202 raeburn 4982: my $setting = $env{'form.roletype'};
4983: my $choice = $env{'form.bulkaction'};
4984: if ($permission->{'cusr'}) {
1.336 raeburn 4985: &Apache::lonuserutils::update_user_list($r,$context,$setting,$choice,$crstype);
1.221 raeburn 4986: } else {
4987: $r->print(&mt('You are not authorized to make bulk changes to user roles'));
1.223 raeburn 4988: $r->print('<p><a href="/adm/createuser?action=listusers">'.&mt('Display User Lists').'</a>');
1.202 raeburn 4989: }
4990: } else {
1.351 raeburn 4991: push(@{$brcrum},
4992: {href => '/adm/createuser?action=listusers',
4993: text => "List Users",
1.439 raeburn 4994: help => $helpitem});
1.351 raeburn 4995: $bread_crumbs_component = 'List Users';
4996: $args = {bread_crumbs => $brcrum,
4997: bread_crumbs_component => $bread_crumbs_component};
1.202 raeburn 4998: my ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles);
4999: my $formname = 'studentform';
1.364 raeburn 5000: my $hidecall = "hide_searching();";
1.321 raeburn 5001: if (($context eq 'domain') && (($env{'form.roletype'} eq 'course') ||
5002: ($env{'form.roletype'} eq 'community'))) {
5003: if ($env{'form.roletype'} eq 'course') {
5004: ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles) =
5005: &Apache::lonuserutils::courses_selector($env{'request.role.domain'},
5006: $formname);
5007: } elsif ($env{'form.roletype'} eq 'community') {
5008: $cb_jscript =
5009: &Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
5010: my %elements = (
5011: coursepick => 'radio',
5012: coursetotal => 'text',
5013: courselist => 'text',
5014: );
5015: $jscript = &Apache::lonhtmlcommon::set_form_elements(\%elements);
5016: }
1.364 raeburn 5017: $jscript .= &verify_user_display($context)."\n".
5018: &Apache::loncommon::check_uncheck_jscript();
1.202 raeburn 5019: my $js = &add_script($jscript).$cb_jscript;
5020: my $loadcode =
5021: &Apache::lonuserutils::course_selector_loadcode($formname);
5022: if ($loadcode ne '') {
1.364 raeburn 5023: $args->{add_entries} = {onload => "$loadcode;$hidecall"};
5024: } else {
5025: $args->{add_entries} = {onload => $hidecall};
1.202 raeburn 5026: }
1.351 raeburn 5027: $r->print(&header($js,$args));
1.191 raeburn 5028: } else {
1.364 raeburn 5029: $args->{add_entries} = {onload => $hidecall};
5030: $jscript = &verify_user_display($context).
5031: &Apache::loncommon::check_uncheck_jscript();
5032: $r->print(&header(&add_script($jscript),$args));
1.191 raeburn 5033: }
1.202 raeburn 5034: &Apache::lonuserutils::print_userlist($r,undef,$permission,$context,
1.375 raeburn 5035: $formname,$totcodes,$codetitles,$idlist,$idlist_titles,
5036: $showcredits);
1.191 raeburn 5037: }
1.213 raeburn 5038: } elsif ($env{'form.action'} eq 'drop' && $permission->{'cusr'}) {
1.318 raeburn 5039: my $brtext;
5040: if ($crstype eq 'Community') {
5041: $brtext = 'Drop Members';
5042: } else {
5043: $brtext = 'Drop Students';
5044: }
1.351 raeburn 5045: push(@{$brcrum},
5046: {href => '/adm/createuser?action=drop',
5047: text => $brtext,
5048: help => 'Course_Drop_Student'});
5049: if ($env{'form.state'} eq 'done') {
5050: push(@{$brcrum},
5051: {href=>'/adm/createuser?action=drop',
5052: text=>"Result"});
5053: }
5054: $bread_crumbs_component = $brtext;
5055: $args = {bread_crumbs => $brcrum,
5056: bread_crumbs_component => $bread_crumbs_component};
5057: $r->print(&header(undef,$args));
1.213 raeburn 5058: if (!exists($env{'form.state'})) {
1.318 raeburn 5059: &Apache::lonuserutils::print_drop_menu($r,$context,$permission,$crstype);
1.213 raeburn 5060: } elsif ($env{'form.state'} eq 'done') {
5061: &Apache::lonuserutils::update_user_list($r,$context,undef,
5062: $env{'form.action'});
5063: }
1.202 raeburn 5064: } elsif ($env{'form.action'} eq 'dateselect') {
5065: if ($permission->{'cusr'}) {
1.351 raeburn 5066: $r->print(&header(undef,{'no_nav_bar' => 1}).
1.375 raeburn 5067: &Apache::lonuserutils::date_section_selector($context,$permission,
5068: $crstype,$showcredits));
1.202 raeburn 5069: } else {
1.351 raeburn 5070: $r->print(&header(undef,{'no_nav_bar' => 1}).
5071: '<span class="LC_error">'.&mt('You do not have permission to modify dates or sections for users').'</span>');
1.202 raeburn 5072: }
1.237 raeburn 5073: } elsif ($env{'form.action'} eq 'selfenroll') {
1.398 raeburn 5074: if ($permission->{selfenrolladmin}) {
5075: my %currsettings = (
5076: selfenroll_types => $env{'course.'.$cid.'.internal.selfenroll_types'},
5077: selfenroll_registered => $env{'course.'.$cid.'.internal.selfenroll_registered'},
5078: selfenroll_section => $env{'course.'.$cid.'.internal.selfenroll_section'},
5079: selfenroll_notifylist => $env{'course.'.$cid.'.internal.selfenroll_notifylist'},
5080: selfenroll_approval => $env{'course.'.$cid.'.internal.selfenroll_approval'},
5081: selfenroll_limit => $env{'course.'.$cid.'.internal.selfenroll_limit'},
5082: selfenroll_cap => $env{'course.'.$cid.'.internal.selfenroll_cap'},
5083: selfenroll_start_date => $env{'course.'.$cid.'.internal.selfenroll_start_date'},
5084: selfenroll_end_date => $env{'course.'.$cid.'.internal.selfenroll_end_date'},
5085: selfenroll_start_access => $env{'course.'.$cid.'.internal.selfenroll_start_access'},
5086: selfenroll_end_access => $env{'course.'.$cid.'.internal.selfenroll_end_access'},
5087: default_enrollment_start_date => $env{'course.'.$cid.'.default_enrollment_start_date'},
5088: default_enrollment_end_date => $env{'course.'.$cid.'.default_enrollment_end_date'},
1.400 raeburn 5089: uniquecode => $env{'course.'.$cid.'.internal.uniquecode'},
1.398 raeburn 5090: );
5091: push(@{$brcrum},
5092: {href => '/adm/createuser?action=selfenroll',
5093: text => "Configure Self-enrollment",
5094: help => 'Course_Self_Enrollment'});
5095: if (!exists($env{'form.state'})) {
5096: $args = { bread_crumbs => $brcrum,
5097: bread_crumbs_component => 'Configure Self-enrollment'};
5098: $r->print(&header(undef,$args));
5099: $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n");
5100: &print_selfenroll_menu($r,'course',$cid,$cdom,$cnum,\%currsettings);
5101: } elsif ($env{'form.state'} eq 'done') {
5102: push (@{$brcrum},
5103: {href=>'/adm/createuser?action=selfenroll',
5104: text=>"Result"});
5105: $args = { bread_crumbs => $brcrum,
5106: bread_crumbs_component => 'Self-enrollment result'};
5107: $r->print(&header(undef,$args));
5108: $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n");
1.400 raeburn 5109: &update_selfenroll_config($r,$cid,$cdom,$cnum,$context,$crstype,\%currsettings);
1.398 raeburn 5110: }
5111: } else {
5112: $r->print(&header(undef,{'no_nav_bar' => 1}).
5113: '<span class="LC_error">'.&mt('You do not have permission to configure self-enrollment').'</span>');
1.237 raeburn 5114: }
1.277 raeburn 5115: } elsif ($env{'form.action'} eq 'selfenrollqueue') {
1.418 raeburn 5116: if ($permission->{selfenrolladmin}) {
1.351 raeburn 5117: push(@{$brcrum},
5118: {href => '/adm/createuser?action=selfenrollqueue',
1.418 raeburn 5119: text => 'Enrollment requests',
1.439 raeburn 5120: help => 'Course_Approve_Selfenroll'});
1.418 raeburn 5121: $bread_crumbs_component = 'Enrollment requests';
5122: if ($env{'form.state'} eq 'done') {
5123: push(@{$brcrum},
5124: {href => '/adm/createuser?action=selfenrollqueue',
5125: text => 'Result',
1.439 raeburn 5126: help => 'Course_Approve_Selfenroll'});
1.418 raeburn 5127: $bread_crumbs_component = 'Enrollment result';
5128: }
5129: $args = { bread_crumbs => $brcrum,
5130: bread_crumbs_component => $bread_crumbs_component};
5131: $r->print(&header(undef,$args));
5132: my $coursedesc = $env{'course.'.$cid.'.description'};
5133: if (!exists($env{'form.state'})) {
5134: $r->print('<h3>'.&mt('Pending enrollment requests').'</h3>'."\n");
5135: $r->print(&Apache::loncoursequeueadmin::display_queued_requests($context,
5136: $cdom,$cnum));
5137: } elsif ($env{'form.state'} eq 'done') {
5138: $r->print('<h3>'.&mt('Enrollment request processing').'</h3>'."\n");
5139: $r->print(&Apache::loncoursequeueadmin::update_request_queue($context,
1.430 raeburn 5140: $cdom,$cnum,$coursedesc));
1.418 raeburn 5141: }
5142: } else {
5143: $r->print(&header(undef,{'no_nav_bar' => 1}).
5144: '<span class="LC_error">'.&mt('You do not have permission to manage self-enrollment').'</span>');
1.351 raeburn 5145: }
1.418 raeburn 5146: } elsif ($env{'form.action'} eq 'changelogs') {
5147: if ($permission->{cusr} || $permission->{view}) {
5148: &print_userchangelogs_display($r,$context,$permission,$brcrum);
5149: } else {
5150: $r->print(&header(undef,{'no_nav_bar' => 1}).
5151: '<span class="LC_error">'.&mt('You do not have permission to view change logs').'</span>');
1.277 raeburn 5152: }
1.428 raeburn 5153: } elsif ($env{'form.action'} eq 'helpdesk') {
5154: if (($permission->{'owner'}) || ($permission->{'co-owner'})) {
5155: if ($env{'form.state'} eq 'process') {
5156: if ($permission->{'owner'}) {
5157: &update_helpdeskaccess($r,$permission,$brcrum);
5158: } else {
5159: &print_helpdeskaccess_display($r,$permission,$brcrum);
1.430 raeburn 5160: }
1.428 raeburn 5161: } else {
5162: &print_helpdeskaccess_display($r,$permission,$brcrum);
5163: }
5164: } else {
5165: $r->print(&header(undef,{'no_nav_bar' => 1}).
5166: '<span class="LC_error">'.&mt('You do not have permission to view helpdesk access').'</span>');
5167: }
1.190 raeburn 5168: } else {
1.351 raeburn 5169: $bread_crumbs_component = 'User Management';
5170: $args = { bread_crumbs => $brcrum,
5171: bread_crumbs_component => $bread_crumbs_component};
5172: $r->print(&header(undef,$args));
1.318 raeburn 5173: $r->print(&print_main_menu($permission,$context,$crstype));
1.190 raeburn 5174: }
1.351 raeburn 5175: $r->print(&Apache::loncommon::end_page());
1.190 raeburn 5176: return OK;
5177: }
5178:
5179: sub header {
1.351 raeburn 5180: my ($jscript,$args) = @_;
1.190 raeburn 5181: my $start_page;
1.351 raeburn 5182: if (ref($args) eq 'HASH') {
5183: $start_page=&Apache::loncommon::start_page('User Management',$jscript,$args);
1.190 raeburn 5184: } else {
1.351 raeburn 5185: $start_page=&Apache::loncommon::start_page('User Management',$jscript);
1.190 raeburn 5186: }
5187: return $start_page;
5188: }
1.2 www 5189:
1.191 raeburn 5190: sub add_script {
5191: my ($js) = @_;
1.301 bisitz 5192: return '<script type="text/javascript">'."\n"
5193: .'// <![CDATA['."\n"
5194: .$js."\n"
5195: .'// ]]>'."\n"
5196: .'</script>'."\n";
1.191 raeburn 5197: }
5198:
1.391 raeburn 5199: sub usernamerequest_javascript {
5200: my $js = <<ENDJS;
5201:
5202: function openusernamereqdisplay(dom,uname,queue) {
5203: var url = '/adm/createuser?action=displayuserreq';
5204: url += '&domain='+dom+'&username='+uname+'&queue='+queue;
5205: var title = 'Account_Request_Browser';
5206: var options = 'scrollbars=1,resizable=1,menubar=0';
5207: options += ',width=700,height=600';
5208: var stdeditbrowser = open(url,title,options,'1');
5209: stdeditbrowser.focus();
5210: return;
5211: }
5212:
5213: ENDJS
5214: }
5215:
5216: sub close_popup_form {
5217: my $close= &mt('Close Window');
5218: return << "END";
5219: <p><form name="displayreq" action="" method="post">
5220: <input type="button" name="closeme" value="$close" onclick="javascript:self.close();" />
5221: </form></p>
5222: END
5223: }
5224:
1.202 raeburn 5225: sub verify_user_display {
1.364 raeburn 5226: my ($context) = @_;
1.374 raeburn 5227: my %lt = &Apache::lonlocal::texthash (
5228: course => 'course(s): description, section(s), status',
5229: community => 'community(s): description, section(s), status',
5230: author => 'author',
5231: );
1.364 raeburn 5232: my $photos;
5233: if (($context eq 'course') && $env{'request.course.id'}) {
5234: $photos = $env{'course.'.$env{'request.course.id'}.'.internal.showphoto'};
5235: }
1.202 raeburn 5236: my $output = <<"END";
5237:
1.364 raeburn 5238: function hide_searching() {
5239: if (document.getElementById('searching')) {
5240: document.getElementById('searching').style.display = 'none';
5241: }
5242: return;
5243: }
5244:
1.202 raeburn 5245: function display_update() {
5246: document.studentform.action.value = 'listusers';
5247: document.studentform.phase.value = 'display';
5248: document.studentform.submit();
5249: }
5250:
1.364 raeburn 5251: function updateCols(caller) {
5252: var context = '$context';
5253: var photos = '$photos';
5254: if (caller == 'Status') {
1.374 raeburn 5255: if ((context == 'domain') &&
5256: ((document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'course') ||
5257: (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community'))) {
1.364 raeburn 5258: document.getElementById('showcolstatus').checked = false;
5259: document.getElementById('showcolstatus').disabled = 'disabled';
5260: document.getElementById('showcolstart').checked = false;
5261: document.getElementById('showcolend').checked = false;
1.374 raeburn 5262: } else {
5263: if (document.studentform.Status.options[document.studentform.Status.selectedIndex].value == 'Any') {
5264: document.getElementById('showcolstatus').checked = true;
5265: document.getElementById('showcolstatus').disabled = '';
5266: document.getElementById('showcolstart').checked = true;
5267: document.getElementById('showcolend').checked = true;
5268: } else {
5269: document.getElementById('showcolstatus').checked = false;
5270: document.getElementById('showcolstatus').disabled = 'disabled';
5271: document.getElementById('showcolstart').checked = false;
5272: document.getElementById('showcolend').checked = false;
5273: }
1.364 raeburn 5274: }
5275: }
5276: if (caller == 'output') {
5277: if (photos == 1) {
5278: if (document.getElementById('showcolphoto')) {
5279: var photoitem = document.getElementById('showcolphoto');
5280: if (document.studentform.output.options[document.studentform.output.selectedIndex].value == 'html') {
5281: photoitem.checked = true;
5282: photoitem.disabled = '';
5283: } else {
5284: photoitem.checked = false;
5285: photoitem.disabled = 'disabled';
5286: }
5287: }
5288: }
5289: }
5290: if (caller == 'showrole') {
1.371 raeburn 5291: if ((document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'Any') ||
5292: (document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'cr')) {
1.364 raeburn 5293: document.getElementById('showcolrole').checked = true;
5294: document.getElementById('showcolrole').disabled = '';
5295: } else {
5296: document.getElementById('showcolrole').checked = false;
5297: document.getElementById('showcolrole').disabled = 'disabled';
5298: }
1.374 raeburn 5299: if (context == 'domain') {
1.382 raeburn 5300: var quotausageshow = 0;
1.374 raeburn 5301: if ((document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'course') ||
5302: (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community')) {
5303: document.getElementById('showcolstatus').checked = false;
5304: document.getElementById('showcolstatus').disabled = 'disabled';
5305: document.getElementById('showcolstart').checked = false;
5306: document.getElementById('showcolend').checked = false;
5307: } else {
5308: if (document.studentform.Status.options[document.studentform.Status.selectedIndex].value == 'Any') {
5309: document.getElementById('showcolstatus').checked = true;
5310: document.getElementById('showcolstatus').disabled = '';
5311: document.getElementById('showcolstart').checked = true;
5312: document.getElementById('showcolend').checked = true;
5313: }
5314: }
5315: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'domain') {
5316: document.getElementById('showcolextent').disabled = 'disabled';
5317: document.getElementById('showcolextent').checked = 'false';
5318: document.getElementById('showextent').style.display='none';
5319: document.getElementById('showcoltextextent').innerHTML = '';
1.382 raeburn 5320: if ((document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'au') ||
5321: (document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'Any')) {
5322: if (document.getElementById('showcolauthorusage')) {
5323: document.getElementById('showcolauthorusage').disabled = '';
5324: }
5325: if (document.getElementById('showcolauthorquota')) {
5326: document.getElementById('showcolauthorquota').disabled = '';
5327: }
5328: quotausageshow = 1;
5329: }
1.374 raeburn 5330: } else {
5331: document.getElementById('showextent').style.display='block';
5332: document.getElementById('showextent').style.textAlign='left';
5333: document.getElementById('showextent').style.textFace='normal';
5334: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'author') {
5335: document.getElementById('showcolextent').disabled = '';
5336: document.getElementById('showcolextent').checked = 'true';
5337: document.getElementById('showcoltextextent').innerHTML="$lt{'author'}";
5338: } else {
5339: document.getElementById('showcolextent').disabled = '';
5340: document.getElementById('showcolextent').checked = 'true';
5341: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community') {
5342: document.getElementById('showcoltextextent').innerHTML="$lt{'community'}";
5343: } else {
5344: document.getElementById('showcoltextextent').innerHTML="$lt{'course'}";
5345: }
5346: }
5347: }
1.382 raeburn 5348: if (quotausageshow == 0) {
5349: if (document.getElementById('showcolauthorusage')) {
5350: document.getElementById('showcolauthorusage').checked = false;
5351: document.getElementById('showcolauthorusage').disabled = 'disabled';
5352: }
5353: if (document.getElementById('showcolauthorquota')) {
5354: document.getElementById('showcolauthorquota').checked = false;
5355: document.getElementById('showcolauthorquota').disabled = 'disabled';
5356: }
5357: }
1.374 raeburn 5358: }
1.364 raeburn 5359: }
5360: return;
5361: }
5362:
1.202 raeburn 5363: END
5364: return $output;
5365:
5366: }
5367:
1.190 raeburn 5368: ###############################################################
5369: ###############################################################
5370: # Menu Phase One
5371: sub print_main_menu {
1.318 raeburn 5372: my ($permission,$context,$crstype) = @_;
5373: my $linkcontext = $context;
5374: my $stuterm = lc(&Apache::lonnet::plaintext('st',$crstype));
5375: if (($context eq 'course') && ($crstype eq 'Community')) {
5376: $linkcontext = lc($crstype);
5377: $stuterm = 'Members';
5378: }
1.208 raeburn 5379: my %links = (
1.298 droeschl 5380: domain => {
5381: upload => 'Upload a File of Users',
5382: singleuser => 'Add/Modify a User',
5383: listusers => 'Manage Users',
5384: },
5385: author => {
5386: upload => 'Upload a File of Co-authors',
5387: singleuser => 'Add/Modify a Co-author',
5388: listusers => 'Manage Co-authors',
5389: },
5390: course => {
5391: upload => 'Upload a File of Course Users',
5392: singleuser => 'Add/Modify a Course User',
1.354 www 5393: listusers => 'List and Modify Multiple Course Users',
1.298 droeschl 5394: },
1.318 raeburn 5395: community => {
5396: upload => 'Upload a File of Community Users',
5397: singleuser => 'Add/Modify a Community User',
1.354 www 5398: listusers => 'List and Modify Multiple Community Users',
1.318 raeburn 5399: },
5400: );
5401: my %linktitles = (
5402: domain => {
5403: singleuser => 'Add a user to the domain, and/or a course or community in the domain.',
5404: listusers => 'Show and manage users in this domain.',
5405: },
5406: author => {
5407: singleuser => 'Add a user with a co- or assistant author role.',
5408: listusers => 'Show and manage co- or assistant authors.',
5409: },
5410: course => {
5411: singleuser => 'Add a user with a certain role to this course.',
5412: listusers => 'Show and manage users in this course.',
5413: },
5414: community => {
5415: singleuser => 'Add a user with a certain role to this community.',
5416: listusers => 'Show and manage users in this community.',
5417: },
1.298 droeschl 5418: );
1.418 raeburn 5419: if ($linkcontext eq 'domain') {
5420: unless ($permission->{'cusr'}) {
1.430 raeburn 5421: $links{'domain'}{'singleuser'} = 'View a User';
1.418 raeburn 5422: $linktitles{'domain'}{'singleuser'} = 'View information about a user in the domain';
5423: }
5424: } elsif ($linkcontext eq 'course') {
5425: unless ($permission->{'cusr'}) {
5426: $links{'course'}{'singleuser'} = 'View a Course User';
5427: $linktitles{'course'}{'singleuser'} = 'View information about a user in this course';
5428: $links{'course'}{'listusers'} = 'List Course Users';
5429: $linktitles{'course'}{'listusers'} = 'Show information about users in this course';
5430: }
5431: } elsif ($linkcontext eq 'community') {
5432: unless ($permission->{'cusr'}) {
5433: $links{'community'}{'singleuser'} = 'View a Community User';
5434: $linktitles{'community'}{'singleuser'} = 'View information about a user in this community';
5435: $links{'community'}{'listusers'} = 'List Community Users';
5436: $linktitles{'community'}{'listusers'} = 'Show information about users in this community';
5437: }
5438: }
1.298 droeschl 5439: my @menu = ( {categorytitle => 'Single Users',
5440: items =>
5441: [
5442: {
1.318 raeburn 5443: linktext => $links{$linkcontext}{'singleuser'},
1.298 droeschl 5444: icon => 'edit-redo.png',
5445: #help => 'Course_Change_Privileges',
5446: url => '/adm/createuser?action=singleuser',
1.418 raeburn 5447: permission => ($permission->{'view'} || $permission->{'cusr'}),
1.318 raeburn 5448: linktitle => $linktitles{$linkcontext}{'singleuser'},
1.298 droeschl 5449: },
5450: ]},
5451:
5452: {categorytitle => 'Multiple Users',
5453: items =>
5454: [
5455: {
1.318 raeburn 5456: linktext => $links{$linkcontext}{'upload'},
1.340 wenzelju 5457: icon => 'uplusr.png',
1.298 droeschl 5458: #help => 'Course_Create_Class_List',
5459: url => '/adm/createuser?action=upload',
5460: permission => $permission->{'cusr'},
5461: linktitle => 'Upload a CSV or a text file containing users.',
5462: },
5463: {
1.318 raeburn 5464: linktext => $links{$linkcontext}{'listusers'},
1.340 wenzelju 5465: icon => 'mngcu.png',
1.298 droeschl 5466: #help => 'Course_View_Class_List',
5467: url => '/adm/createuser?action=listusers',
5468: permission => ($permission->{'view'} || $permission->{'cusr'}),
1.318 raeburn 5469: linktitle => $linktitles{$linkcontext}{'listusers'},
1.298 droeschl 5470: },
5471:
5472: ]},
5473:
5474: {categorytitle => 'Administration',
5475: items => [ ]},
5476: );
1.415 raeburn 5477:
1.265 mielkec 5478: if ($context eq 'domain'){
1.416 raeburn 5479: push(@{ $menu[0]->{items} }, # Single Users
5480: {
5481: linktext => 'User Access Log',
1.417 raeburn 5482: icon => 'document-properties.png',
1.425 raeburn 5483: #help => 'Domain_User_Access_Logs',
1.416 raeburn 5484: url => '/adm/createuser?action=accesslogs',
5485: permission => $permission->{'activity'},
5486: linktitle => 'View user access log.',
5487: }
5488: );
1.298 droeschl 5489:
5490: push(@{ $menu[2]->{items} }, #Category: Administration
5491: {
5492: linktext => 'Custom Roles',
5493: icon => 'emblem-photos.png',
5494: #help => 'Course_Editing_Custom_Roles',
5495: url => '/adm/createuser?action=custom',
5496: permission => $permission->{'custom'},
5497: linktitle => 'Configure a custom role.',
5498: },
1.362 raeburn 5499: {
5500: linktext => 'Authoring Space Requests',
5501: icon => 'selfenrl-queue.png',
5502: #help => 'Domain_Role_Approvals',
5503: url => '/adm/createuser?action=processauthorreq',
5504: permission => $permission->{'cusr'},
5505: linktitle => 'Approve or reject author role requests',
5506: },
1.363 raeburn 5507: {
1.391 raeburn 5508: linktext => 'LON-CAPA Account Requests',
5509: icon => 'list-add.png',
5510: #help => 'Domain_Username_Approvals',
5511: url => '/adm/createuser?action=processusernamereq',
5512: permission => $permission->{'cusr'},
5513: linktitle => 'Approve or reject LON-CAPA account requests',
5514: },
5515: {
1.363 raeburn 5516: linktext => 'Change Log',
5517: icon => 'document-properties.png',
5518: #help => 'Course_User_Logs',
5519: url => '/adm/createuser?action=changelogs',
1.418 raeburn 5520: permission => ($permission->{'cusr'} || $permission->{'view'}),
1.363 raeburn 5521: linktitle => 'View change log.',
5522: },
1.298 droeschl 5523: );
5524:
1.265 mielkec 5525: }elsif ($context eq 'course'){
1.298 droeschl 5526: my ($cnum,$cdom) = &Apache::lonuserutils::get_course_identity();
1.318 raeburn 5527:
5528: my %linktext = (
5529: 'Course' => {
5530: single => 'Add/Modify a Student',
5531: drop => 'Drop Students',
5532: groups => 'Course Groups',
5533: },
5534: 'Community' => {
5535: single => 'Add/Modify a Member',
5536: drop => 'Drop Members',
5537: groups => 'Community Groups',
5538: },
5539: );
1.411 raeburn 5540: $linktext{'Placement'} = $linktext{'Course'};
1.318 raeburn 5541:
5542: my %linktitle = (
5543: 'Course' => {
5544: single => 'Add a user with the role of student to this course',
5545: drop => 'Remove a student from this course.',
5546: groups => 'Manage course groups',
5547: },
5548: 'Community' => {
5549: single => 'Add a user with the role of member to this community',
5550: drop => 'Remove a member from this community.',
5551: groups => 'Manage community groups',
5552: },
5553: );
5554:
1.411 raeburn 5555: $linktitle{'Placement'} = $linktitle{'Course'};
5556:
1.298 droeschl 5557: push(@{ $menu[0]->{items} }, #Category: Single Users
5558: {
1.318 raeburn 5559: linktext => $linktext{$crstype}{'single'},
1.298 droeschl 5560: #help => 'Course_Add_Student',
5561: icon => 'list-add.png',
5562: url => '/adm/createuser?action=singlestudent',
5563: permission => $permission->{'cusr'},
1.318 raeburn 5564: linktitle => $linktitle{$crstype}{'single'},
1.298 droeschl 5565: },
5566: );
5567:
5568: push(@{ $menu[1]->{items} }, #Category: Multiple Users
5569: {
1.318 raeburn 5570: linktext => $linktext{$crstype}{'drop'},
1.298 droeschl 5571: icon => 'edit-undo.png',
5572: #help => 'Course_Drop_Student',
5573: url => '/adm/createuser?action=drop',
5574: permission => $permission->{'cusr'},
1.318 raeburn 5575: linktitle => $linktitle{$crstype}{'drop'},
1.298 droeschl 5576: },
5577: );
5578: push(@{ $menu[2]->{items} }, #Category: Administration
1.428 raeburn 5579: {
5580: linktext => 'Helpdesk Access',
5581: icon => 'helpdesk-access.png',
5582: #help => 'Course_Helpdesk_Access',
5583: url => '/adm/createuser?action=helpdesk',
5584: permission => ($permission->{'owner'} || $permission->{'co-owner'}),
5585: linktitle => 'Helpdesk access options',
5586: },
5587: {
1.298 droeschl 5588: linktext => 'Custom Roles',
5589: icon => 'emblem-photos.png',
5590: #help => 'Course_Editing_Custom_Roles',
5591: url => '/adm/createuser?action=custom',
5592: permission => $permission->{'custom'},
5593: linktitle => 'Configure a custom role.',
5594: },
5595: {
1.318 raeburn 5596: linktext => $linktext{$crstype}{'groups'},
1.333 wenzelju 5597: icon => 'grps.png',
1.298 droeschl 5598: #help => 'Course_Manage_Group',
5599: url => '/adm/coursegroups?refpage=cusr',
5600: permission => $permission->{'grp_manage'},
1.318 raeburn 5601: linktitle => $linktitle{$crstype}{'groups'},
1.298 droeschl 5602: },
5603: {
1.328 wenzelju 5604: linktext => 'Change Log',
1.298 droeschl 5605: icon => 'document-properties.png',
5606: #help => 'Course_User_Logs',
5607: url => '/adm/createuser?action=changelogs',
1.418 raeburn 5608: permission => ($permission->{'view'} || $permission->{'cusr'}),
1.298 droeschl 5609: linktitle => 'View change log.',
5610: },
5611: );
1.277 raeburn 5612: if ($env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_approval'}) {
1.298 droeschl 5613: push(@{ $menu[2]->{items} },
1.398 raeburn 5614: {
1.298 droeschl 5615: linktext => 'Enrollment Requests',
5616: icon => 'selfenrl-queue.png',
5617: #help => 'Course_Approve_Selfenroll',
5618: url => '/adm/createuser?action=selfenrollqueue',
1.398 raeburn 5619: permission => $permission->{'selfenrolladmin'},
1.298 droeschl 5620: linktitle =>'Approve or reject enrollment requests.',
5621: },
5622: );
1.277 raeburn 5623: }
1.298 droeschl 5624:
1.265 mielkec 5625: if (!exists($permission->{'cusr_section'})){
1.320 raeburn 5626: if ($crstype ne 'Community') {
5627: push(@{ $menu[2]->{items} },
5628: {
5629: linktext => 'Automated Enrollment',
5630: icon => 'roles.png',
5631: #help => 'Course_Automated_Enrollment',
5632: permission => (&Apache::lonnet::auto_run($cnum,$cdom)
1.418 raeburn 5633: && (($permission->{'cusr'}) ||
5634: ($permission->{'view'}))),
1.320 raeburn 5635: url => '/adm/populate',
5636: linktitle => 'Automated enrollment manager.',
5637: }
5638: );
5639: }
5640: push(@{ $menu[2]->{items} },
1.298 droeschl 5641: {
5642: linktext => 'User Self-Enrollment',
1.342 wenzelju 5643: icon => 'self_enroll.png',
1.298 droeschl 5644: #help => 'Course_Self_Enrollment',
5645: url => '/adm/createuser?action=selfenroll',
1.398 raeburn 5646: permission => $permission->{'selfenrolladmin'},
1.317 bisitz 5647: linktitle => 'Configure user self-enrollment.',
1.298 droeschl 5648: },
5649: );
5650: }
1.363 raeburn 5651: } elsif ($context eq 'author') {
1.370 raeburn 5652: push(@{ $menu[2]->{items} }, #Category: Administration
1.363 raeburn 5653: {
5654: linktext => 'Change Log',
5655: icon => 'document-properties.png',
5656: #help => 'Course_User_Logs',
5657: url => '/adm/createuser?action=changelogs',
5658: permission => $permission->{'cusr'},
5659: linktitle => 'View change log.',
5660: },
1.370 raeburn 5661: );
1.363 raeburn 5662: }
5663: return Apache::lonhtmlcommon::generate_menu(@menu);
1.250 raeburn 5664: # { text => 'View Log-in History',
5665: # help => 'Course_User_Logins',
5666: # action => 'logins',
5667: # permission => $permission->{'cusr'},
5668: # });
1.190 raeburn 5669: }
5670:
1.189 albertel 5671: sub restore_prev_selections {
5672: my %saveable_parameters = ('srchby' => 'scalar',
5673: 'srchin' => 'scalar',
5674: 'srchtype' => 'scalar',
5675: );
5676: &Apache::loncommon::store_settings('user','user_picker',
5677: \%saveable_parameters);
5678: &Apache::loncommon::restore_settings('user','user_picker',
5679: \%saveable_parameters);
5680: }
5681:
1.237 raeburn 5682: sub print_selfenroll_menu {
1.418 raeburn 5683: my ($r,$context,$cid,$cdom,$cnum,$currsettings,$additional,$readonly) = @_;
1.322 raeburn 5684: my $crstype = &Apache::loncommon::course_type();
1.398 raeburn 5685: my $formname = 'selfenroll';
1.237 raeburn 5686: my $nolink = 1;
1.398 raeburn 5687: my ($row,$lt) = &Apache::lonuserutils::get_selfenroll_titles();
1.237 raeburn 5688: my $groupslist = &Apache::lonuserutils::get_groupslist();
5689: my $setsec_js =
5690: &Apache::lonuserutils::setsections_javascript($formname,$groupslist);
1.249 raeburn 5691: my %alerts = &Apache::lonlocal::texthash(
5692: acto => 'Activation of self-enrollment was selected for the following domain(s)',
5693: butn => 'but no user types have been checked.',
5694: wilf => "Please uncheck 'activate' or check at least one type.",
5695: );
1.418 raeburn 5696: my $disabled;
5697: if ($readonly) {
5698: $disabled = ' disabled="disabled"';
5699: }
1.405 damieng 5700: &js_escape(\%alerts);
1.249 raeburn 5701: my $selfenroll_js = <<"ENDSCRIPT";
5702: function update_types(caller,num) {
5703: var delidx = getIndexByName('selfenroll_delete');
5704: var actidx = getIndexByName('selfenroll_activate');
5705: if (caller == 'selfenroll_all') {
5706: var selall;
5707: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
5708: if (document.$formname.selfenroll_all[i].checked) {
5709: selall = document.$formname.selfenroll_all[i].value;
5710: }
5711: }
5712: if (selall == 1) {
5713: if (delidx != -1) {
5714: if (document.$formname.selfenroll_delete.length) {
5715: for (var j=0; j<document.$formname.selfenroll_delete.length; j++) {
5716: document.$formname.selfenroll_delete[j].checked = true;
5717: }
5718: } else {
5719: document.$formname.elements[delidx].checked = true;
5720: }
5721: }
5722: if (actidx != -1) {
5723: if (document.$formname.selfenroll_activate.length) {
5724: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
5725: document.$formname.selfenroll_activate[j].checked = false;
5726: }
5727: } else {
5728: document.$formname.elements[actidx].checked = false;
5729: }
5730: }
5731: document.$formname.selfenroll_newdom.selectedIndex = 0;
5732: }
5733: }
5734: if (caller == 'selfenroll_activate') {
5735: if (document.$formname.selfenroll_activate.length) {
5736: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
5737: if (document.$formname.selfenroll_activate[j].value == num) {
5738: if (document.$formname.selfenroll_activate[j].checked) {
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: }
5750: } else {
5751: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
5752: if (document.$formname.selfenroll_all[i].value == '1') {
5753: document.$formname.selfenroll_all[i].checked = false;
5754: }
5755: if (document.$formname.selfenroll_all[i].value == '0') {
5756: document.$formname.selfenroll_all[i].checked = true;
5757: }
5758: }
5759: }
5760: }
5761: if (caller == 'selfenroll_delete') {
5762: if (document.$formname.selfenroll_delete.length) {
5763: for (var j=0; j<document.$formname.selfenroll_delete.length; j++) {
5764: if (document.$formname.selfenroll_delete[j].value == num) {
5765: if (document.$formname.selfenroll_delete[j].checked) {
5766: var delindex = getIndexByName('selfenroll_types_'+num);
5767: if (delindex != -1) {
5768: if (document.$formname.elements[delindex].length) {
5769: for (var k=0; k<document.$formname.elements[delindex].length; k++) {
5770: document.$formname.elements[delindex][k].checked = false;
5771: }
5772: } else {
5773: document.$formname.elements[delindex].checked = false;
5774: }
5775: }
5776: }
5777: }
5778: }
5779: } else {
5780: if (document.$formname.selfenroll_delete.checked) {
5781: var delindex = getIndexByName('selfenroll_types_'+num);
5782: if (delindex != -1) {
5783: if (document.$formname.elements[delindex].length) {
5784: for (var k=0; k<document.$formname.elements[delindex].length; k++) {
5785: document.$formname.elements[delindex][k].checked = false;
5786: }
5787: } else {
5788: document.$formname.elements[delindex].checked = false;
5789: }
5790: }
5791: }
5792: }
5793: }
5794: return;
5795: }
5796:
5797: function validate_types(form) {
5798: var needaction = new Array();
5799: var countfail = 0;
5800: var actidx = getIndexByName('selfenroll_activate');
5801: if (actidx != -1) {
5802: if (document.$formname.selfenroll_activate.length) {
5803: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
5804: var num = document.$formname.selfenroll_activate[j].value;
5805: if (document.$formname.selfenroll_activate[j].checked) {
5806: countfail = check_types(num,countfail,needaction)
5807: }
5808: }
5809: } else {
5810: if (document.$formname.selfenroll_activate.checked) {
1.398 raeburn 5811: var num = document.$formname.selfenroll_activate.value;
1.249 raeburn 5812: countfail = check_types(num,countfail,needaction)
5813: }
5814: }
5815: }
5816: if (countfail > 0) {
5817: var msg = "$alerts{'acto'}\\n";
5818: var loopend = needaction.length -1;
5819: if (loopend > 0) {
5820: for (var m=0; m<loopend; m++) {
5821: msg += needaction[m]+", ";
5822: }
5823: }
5824: msg += needaction[loopend]+"\\n$alerts{'butn'}\\n$alerts{'wilf'}";
5825: alert(msg);
5826: return;
5827: }
5828: setSections(form);
5829: }
5830:
5831: function check_types(num,countfail,needaction) {
1.441 ! raeburn 5832: var boxname = 'selfenroll_types_'+num;
! 5833: var typeidx = getIndexByName(boxname);
1.249 raeburn 5834: var count = 0;
5835: if (typeidx != -1) {
1.441 ! raeburn 5836: if (document.$formname.elements[boxname].length) {
! 5837: for (var k=0; k<document.$formname.elements[boxname].length; k++) {
! 5838: if (document.$formname.elements[boxname][k].checked) {
1.249 raeburn 5839: count ++;
5840: }
5841: }
5842: } else {
5843: if (document.$formname.elements[typeidx].checked) {
5844: count ++;
5845: }
5846: }
5847: if (count == 0) {
5848: var domidx = getIndexByName('selfenroll_dom_'+num);
5849: if (domidx != -1) {
5850: var domname = document.$formname.elements[domidx].value;
5851: needaction[countfail] = domname;
5852: countfail ++;
5853: }
5854: }
5855: }
5856: return countfail;
5857: }
5858:
1.398 raeburn 5859: function toggleNotify() {
5860: var selfenrollApproval = 0;
5861: if (document.$formname.selfenroll_approval.length) {
5862: for (var i=0; i<document.$formname.selfenroll_approval.length; i++) {
5863: if (document.$formname.selfenroll_approval[i].checked) {
5864: selfenrollApproval = document.$formname.selfenroll_approval[i].value;
5865: break;
5866: }
5867: }
5868: }
5869: if (document.getElementById('notified')) {
5870: if (selfenrollApproval == 0) {
5871: document.getElementById('notified').style.display='none';
5872: } else {
5873: document.getElementById('notified').style.display='block';
5874: }
5875: }
5876: return;
5877: }
5878:
1.249 raeburn 5879: function getIndexByName(item) {
5880: for (var i=0;i<document.$formname.elements.length;i++) {
5881: if (document.$formname.elements[i].name == item) {
5882: return i;
5883: }
5884: }
5885: return -1;
5886: }
5887: ENDSCRIPT
1.256 raeburn 5888:
1.237 raeburn 5889: my $output = '<script type="text/javascript">'."\n".
1.301 bisitz 5890: '// <![CDATA['."\n".
1.249 raeburn 5891: $setsec_js."\n".$selfenroll_js."\n".
1.301 bisitz 5892: '// ]]>'."\n".
1.237 raeburn 5893: '</script>'."\n".
1.256 raeburn 5894: '<h3>'.$lt->{'selfenroll'}.'</h3>'."\n";
1.400 raeburn 5895:
5896: my $visactions = &cat_visibility();
5897: my ($cathash,%cattype);
5898: my %domconfig = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom);
5899: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
5900: $cathash = $domconfig{'coursecategories'}{'cats'};
5901: $cattype{'auth'} = $domconfig{'coursecategories'}{'auth'};
5902: $cattype{'unauth'} = $domconfig{'coursecategories'}{'unauth'};
1.406 raeburn 5903: if ($cattype{'auth'} eq '') {
5904: $cattype{'auth'} = 'std';
5905: }
5906: if ($cattype{'unauth'} eq '') {
5907: $cattype{'unauth'} = 'std';
5908: }
1.400 raeburn 5909: } else {
5910: $cathash = {};
5911: $cattype{'auth'} = 'std';
5912: $cattype{'unauth'} = 'std';
5913: }
5914: if (($cattype{'auth'} eq 'none') && ($cattype{'unauth'} eq 'none')) {
5915: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
5916: '<br />'.
5917: '<br />'.$visactions->{'take'}.'<ul>'.
5918: '<li>'.$visactions->{'dc_chgconf'}.'</li>'.
5919: '</ul>');
5920: } elsif (($cattype{'auth'} !~ /^(std|domonly)$/) && ($cattype{'unauth'} !~ /^(std|domonly)$/)) {
5921: if ($currsettings->{'uniquecode'}) {
5922: $r->print('<span class="LC_info">'.$visactions->{'vis'}.'</span>');
5923: } else {
5924: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
5925: '<br />'.
5926: '<br />'.$visactions->{'take'}.'<ul>'.
5927: '<li>'.$visactions->{'dc_setcode'}.'</li>'.
5928: '</ul><br />');
5929: }
5930: } else {
5931: my ($visible,$cansetvis,$vismsgs) = &visible_in_stdcat($cdom,$cnum,\%domconfig);
5932: if (ref($visactions) eq 'HASH') {
5933: if ($visible) {
5934: $output .= '<p class="LC_info">'.$visactions->{'vis'}.'</p>';
5935: } else {
5936: $output .= '<p class="LC_warning">'.$visactions->{'miss'}.'</p>'
5937: .$visactions->{'yous'}.
5938: '<p>'.$visactions->{'gen'}.'<br />'.$visactions->{'coca'};
5939: if (ref($vismsgs) eq 'ARRAY') {
5940: $output .= '<br />'.$visactions->{'make'}.'<ul>';
5941: foreach my $item (@{$vismsgs}) {
5942: $output .= '<li>'.$visactions->{$item}.'</li>';
5943: }
5944: $output .= '</ul>';
1.256 raeburn 5945: }
1.400 raeburn 5946: $output .= '</p>';
1.256 raeburn 5947: }
5948: }
5949: }
1.398 raeburn 5950: my $actionhref = '/adm/createuser';
5951: if ($context eq 'domain') {
5952: $actionhref = '/adm/modifycourse';
5953: }
1.400 raeburn 5954:
5955: my %noedit;
5956: unless ($context eq 'domain') {
5957: %noedit = &get_noedit_fields($cdom,$cnum,$crstype,$row);
5958: }
1.398 raeburn 5959: $output .= '<form name="'.$formname.'" method="post" action="'.$actionhref.'">'."\n".
1.256 raeburn 5960: &Apache::lonhtmlcommon::start_pick_box();
1.237 raeburn 5961: if (ref($row) eq 'ARRAY') {
5962: foreach my $item (@{$row}) {
5963: my $title = $item;
5964: if (ref($lt) eq 'HASH') {
5965: $title = $lt->{$item};
5966: }
1.297 bisitz 5967: $output .= &Apache::lonhtmlcommon::row_title($title);
1.237 raeburn 5968: if ($item eq 'types') {
1.398 raeburn 5969: my $curr_types;
5970: if (ref($currsettings) eq 'HASH') {
5971: $curr_types = $currsettings->{'selfenroll_types'};
5972: }
1.400 raeburn 5973: if ($noedit{$item}) {
5974: if ($curr_types eq '*') {
5975: $output .= &mt('Any user in any domain');
5976: } else {
5977: my @entries = split(/;/,$curr_types);
5978: if (@entries > 0) {
5979: $output .= '<ul>';
5980: foreach my $entry (@entries) {
5981: my ($currdom,$typestr) = split(/:/,$entry);
5982: next if ($typestr eq '');
5983: my $domdesc = &Apache::lonnet::domain($currdom);
5984: my @currinsttypes = split(',',$typestr);
5985: my ($othertitle,$usertypes,$types) =
5986: &Apache::loncommon::sorted_inst_types($currdom);
5987: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
5988: $usertypes->{'any'} = &mt('any user');
5989: if (keys(%{$usertypes}) > 0) {
5990: $usertypes->{'other'} = &mt('other users');
5991: }
5992: my @longinsttypes = map { $usertypes->{$_}; } @currinsttypes;
5993: $output .= '<li>'.$domdesc.':'.join(', ',@longinsttypes).'</li>';
5994: }
5995: }
5996: $output .= '</ul>';
5997: } else {
5998: $output .= &mt('None');
5999: }
6000: }
6001: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6002: next;
6003: }
1.241 raeburn 6004: my $showdomdesc = 1;
6005: my $includeempty = 1;
6006: my $num = 0;
6007: $output .= &Apache::loncommon::start_data_table().
6008: &Apache::loncommon::start_data_table_row()
6009: .'<td colspan="2"><span class="LC_nobreak"><label>'
6010: .&mt('Any user in any domain:')
6011: .' <input type="radio" name="selfenroll_all" value="1" ';
6012: if ($curr_types eq '*') {
6013: $output .= ' checked="checked" ';
6014: }
1.249 raeburn 6015: $output .= 'onchange="javascript:update_types('.
1.418 raeburn 6016: "'selfenroll_all'".');"'.$disabled.' />'.&mt('Yes').'</label>'.
1.249 raeburn 6017: ' <input type="radio" name="selfenroll_all" value="0" ';
1.241 raeburn 6018: if ($curr_types ne '*') {
6019: $output .= ' checked="checked" ';
6020: }
1.249 raeburn 6021: $output .= ' onchange="javascript:update_types('.
1.418 raeburn 6022: "'selfenroll_all'".');"'.$disabled.' />'.&mt('No').'</label></td>'.
1.249 raeburn 6023: &Apache::loncommon::end_data_table_row().
6024: &Apache::loncommon::end_data_table().
6025: &mt('Or').'<br />'.
6026: &Apache::loncommon::start_data_table();
1.241 raeburn 6027: my %currdoms;
1.249 raeburn 6028: if ($curr_types eq '') {
1.241 raeburn 6029: $output .= &new_selfenroll_dom_row($cdom,'0');
6030: } elsif ($curr_types ne '*') {
6031: my @entries = split(/;/,$curr_types);
6032: if (@entries > 0) {
6033: foreach my $entry (@entries) {
6034: my ($currdom,$typestr) = split(/:/,$entry);
6035: $currdoms{$currdom} = 1;
6036: my $domdesc = &Apache::lonnet::domain($currdom);
1.249 raeburn 6037: my @currinsttypes = split(',',$typestr);
1.241 raeburn 6038: $output .= &Apache::loncommon::start_data_table_row()
6039: .'<td valign="top"><span class="LC_nobreak">'.&mt('Domain:').'<b>'
6040: .' '.$domdesc.' ('.$currdom.')'
6041: .'</b><input type="hidden" name="selfenroll_dom_'.$num
6042: .'" value="'.$currdom.'" /></span><br />'
6043: .'<span class="LC_nobreak"><label><input type="checkbox" '
1.418 raeburn 6044: .'name="selfenroll_delete" value="'.$num.'" onchange="javascript:update_types('."'selfenroll_delete','$num'".');"'.$disabled.' />'
1.241 raeburn 6045: .&mt('Delete').'</label></span></td>';
1.249 raeburn 6046: $output .= '<td valign="top"> '.&mt('User types:').'<br />'
1.418 raeburn 6047: .&selfenroll_inst_types($num,$currdom,\@currinsttypes,$readonly).'</td>'
1.241 raeburn 6048: .&Apache::loncommon::end_data_table_row();
6049: $num ++;
6050: }
6051: }
6052: }
1.249 raeburn 6053: my $add_domtitle = &mt('Users in additional domain:');
1.241 raeburn 6054: if ($curr_types eq '*') {
1.249 raeburn 6055: $add_domtitle = &mt('Users in specific domain:');
1.241 raeburn 6056: } elsif ($curr_types eq '') {
1.249 raeburn 6057: $add_domtitle = &mt('Users in other domain:');
1.241 raeburn 6058: }
6059: $output .= &Apache::loncommon::start_data_table_row()
6060: .'<td colspan="2"><span class="LC_nobreak">'.$add_domtitle.'</span><br />'
6061: .&Apache::loncommon::select_dom_form('','selfenroll_newdom',
1.418 raeburn 6062: $includeempty,$showdomdesc,'','','',$readonly)
1.241 raeburn 6063: .'<input type="hidden" name="selfenroll_types_total" value="'.$num.'" />'
6064: .'</td>'.&Apache::loncommon::end_data_table_row()
6065: .&Apache::loncommon::end_data_table();
1.237 raeburn 6066: } elsif ($item eq 'registered') {
6067: my ($regon,$regoff);
1.398 raeburn 6068: my $registered;
6069: if (ref($currsettings) eq 'HASH') {
6070: $registered = $currsettings->{'selfenroll_registered'};
6071: }
1.400 raeburn 6072: if ($noedit{$item}) {
6073: if ($registered) {
6074: $output .= &mt('Must be registered in course');
6075: } else {
6076: $output .= &mt('No requirement');
6077: }
6078: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6079: next;
6080: }
1.398 raeburn 6081: if ($registered) {
1.237 raeburn 6082: $regon = ' checked="checked" ';
1.419 raeburn 6083: $regoff = '';
1.237 raeburn 6084: } else {
1.419 raeburn 6085: $regon = '';
1.237 raeburn 6086: $regoff = ' checked="checked" ';
6087: }
6088: $output .= '<label>'.
1.419 raeburn 6089: '<input type="radio" name="selfenroll_registered" value="1"'.$regon.$disabled.' />'.
1.244 bisitz 6090: &mt('Yes').'</label> <label>'.
1.419 raeburn 6091: '<input type="radio" name="selfenroll_registered" value="0"'.$regoff.$disabled.' />'.
1.244 bisitz 6092: &mt('No').'</label>';
1.237 raeburn 6093: } elsif ($item eq 'enroll_dates') {
1.398 raeburn 6094: my ($starttime,$endtime);
6095: if (ref($currsettings) eq 'HASH') {
6096: $starttime = $currsettings->{'selfenroll_start_date'};
6097: $endtime = $currsettings->{'selfenroll_end_date'};
6098: if ($starttime eq '') {
6099: $starttime = $currsettings->{'default_enrollment_start_date'};
6100: }
6101: if ($endtime eq '') {
6102: $endtime = $currsettings->{'default_enrollment_end_date'};
6103: }
1.237 raeburn 6104: }
1.400 raeburn 6105: if ($noedit{$item}) {
6106: $output .= &mt('From: [_1], to: [_2]',&Apache::lonlocal::locallocaltime($starttime),
6107: &Apache::lonlocal::locallocaltime($endtime));
6108: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6109: next;
6110: }
1.237 raeburn 6111: my $startform =
6112: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_start_date',$starttime,
1.418 raeburn 6113: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
1.237 raeburn 6114: my $endform =
6115: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_end_date',$endtime,
1.418 raeburn 6116: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
1.237 raeburn 6117: $output .= &selfenroll_date_forms($startform,$endform);
6118: } elsif ($item eq 'access_dates') {
1.398 raeburn 6119: my ($starttime,$endtime);
6120: if (ref($currsettings) eq 'HASH') {
6121: $starttime = $currsettings->{'selfenroll_start_access'};
6122: $endtime = $currsettings->{'selfenroll_end_access'};
6123: if ($starttime eq '') {
6124: $starttime = $currsettings->{'default_enrollment_start_date'};
6125: }
6126: if ($endtime eq '') {
6127: $endtime = $currsettings->{'default_enrollment_end_date'};
6128: }
1.237 raeburn 6129: }
1.400 raeburn 6130: if ($noedit{$item}) {
6131: $output .= &mt('From: [_1], to: [_2]',&Apache::lonlocal::locallocaltime($starttime),
6132: &Apache::lonlocal::locallocaltime($endtime));
6133: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6134: next;
6135: }
1.237 raeburn 6136: my $startform =
6137: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_start_access',$starttime,
1.418 raeburn 6138: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
1.237 raeburn 6139: my $endform =
6140: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_end_access',$endtime,
1.418 raeburn 6141: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
1.237 raeburn 6142: $output .= &selfenroll_date_forms($startform,$endform);
6143: } elsif ($item eq 'section') {
1.398 raeburn 6144: my $currsec;
6145: if (ref($currsettings) eq 'HASH') {
6146: $currsec = $currsettings->{'selfenroll_section'};
6147: }
1.237 raeburn 6148: my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum);
6149: my $newsecval;
6150: if ($currsec ne 'none' && $currsec ne '') {
6151: if (!defined($sections_count{$currsec})) {
6152: $newsecval = $currsec;
6153: }
6154: }
1.400 raeburn 6155: if ($noedit{$item}) {
6156: if ($currsec ne '') {
6157: $output .= $currsec;
6158: } else {
6159: $output .= &mt('No specific section');
6160: }
6161: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6162: next;
6163: }
1.237 raeburn 6164: my $sections_select =
1.418 raeburn 6165: &Apache::lonuserutils::course_sections(\%sections_count,'st',$currsec,$disabled);
1.237 raeburn 6166: $output .= '<table class="LC_createuser">'."\n".
6167: '<tr class="LC_section_row">'."\n".
6168: '<td align="center">'.&mt('Existing sections')."\n".
6169: '<br />'.$sections_select.'</td><td align="center">'.
6170: &mt('New section').'<br />'."\n".
1.418 raeburn 6171: '<input type="text" name="newsec" size="15" value="'.$newsecval.'"'.$disabled.' />'."\n".
1.237 raeburn 6172: '<input type="hidden" name="sections" value="" />'."\n".
6173: '</td></tr></table>'."\n";
1.276 raeburn 6174: } elsif ($item eq 'approval') {
1.398 raeburn 6175: my ($currnotified,$currapproval,%appchecked);
6176: my %selfdescs = &Apache::lonuserutils::selfenroll_default_descs();
1.430 raeburn 6177: if (ref($currsettings) eq 'HASH') {
1.398 raeburn 6178: $currnotified = $currsettings->{'selfenroll_notifylist'};
6179: $currapproval = $currsettings->{'selfenroll_approval'};
6180: }
6181: if ($currapproval !~ /^[012]$/) {
6182: $currapproval = 0;
6183: }
1.400 raeburn 6184: if ($noedit{$item}) {
6185: $output .= $selfdescs{'approval'}{$currapproval}.
6186: '<br />'.&mt('(Set by Domain Coordinator)');
6187: next;
6188: }
1.398 raeburn 6189: $appchecked{$currapproval} = ' checked="checked"';
6190: for my $i (0..2) {
6191: $output .= '<label>'.
6192: '<input type="radio" name="selfenroll_approval" value="'.$i.'"'.
1.418 raeburn 6193: $appchecked{$i}.' onclick="toggleNotify();"'.$disabled.' />'.
6194: $selfdescs{'approval'}{$i}.'</label>'.(' 'x2);
1.276 raeburn 6195: }
6196: my %advhash = &Apache::lonnet::get_course_adv_roles($cid,1);
6197: my (@ccs,%notified);
1.322 raeburn 6198: my $ccrole = 'cc';
6199: if ($crstype eq 'Community') {
6200: $ccrole = 'co';
6201: }
6202: if ($advhash{$ccrole}) {
6203: @ccs = split(/,/,$advhash{$ccrole});
1.276 raeburn 6204: }
6205: if ($currnotified) {
6206: foreach my $current (split(/,/,$currnotified)) {
6207: $notified{$current} = 1;
6208: if (!grep(/^\Q$current\E$/,@ccs)) {
6209: push(@ccs,$current);
6210: }
6211: }
6212: }
6213: if (@ccs) {
1.398 raeburn 6214: my $style;
6215: unless ($currapproval) {
6216: $style = ' style="display: none;"';
6217: }
6218: $output .= '<br /><div id="notified"'.$style.'>'.
6219: &mt('Personnel to be notified when an enrollment request needs approval, or has been approved:').' '.
6220: &Apache::loncommon::start_data_table().
1.276 raeburn 6221: &Apache::loncommon::start_data_table_row();
6222: my $count = 0;
6223: my $numcols = 4;
6224: foreach my $cc (sort(@ccs)) {
6225: my $notifyon;
6226: my ($ccuname,$ccudom) = split(/:/,$cc);
6227: if ($notified{$cc}) {
6228: $notifyon = ' checked="checked" ';
6229: }
6230: if ($count && !$count%$numcols) {
6231: $output .= &Apache::loncommon::end_data_table_row().
6232: &Apache::loncommon::start_data_table_row()
6233: }
6234: $output .= '<td><span class="LC_nobreak"><label>'.
1.418 raeburn 6235: '<input type="checkbox" name="selfenroll_notify"'.$notifyon.' value="'.$cc.'"'.$disabled.' />'.
1.276 raeburn 6236: &Apache::loncommon::plainname($ccuname,$ccudom).
6237: '</label></span></td>';
1.343 raeburn 6238: $count ++;
1.276 raeburn 6239: }
6240: my $rem = $count%$numcols;
6241: if ($rem) {
6242: my $emptycols = $numcols - $rem;
6243: for (my $i=0; $i<$emptycols; $i++) {
6244: $output .= '<td> </td>';
6245: }
6246: }
6247: $output .= &Apache::loncommon::end_data_table_row().
1.398 raeburn 6248: &Apache::loncommon::end_data_table().
6249: '</div>';
1.276 raeburn 6250: }
6251: } elsif ($item eq 'limit') {
1.398 raeburn 6252: my ($crslimit,$selflimit,$nolimit,$currlim,$currcap);
6253: if (ref($currsettings) eq 'HASH') {
6254: $currlim = $currsettings->{'selfenroll_limit'};
6255: $currcap = $currsettings->{'selfenroll_cap'};
6256: }
1.400 raeburn 6257: if ($noedit{$item}) {
6258: if (($currlim eq 'allstudents') || ($currlim eq 'selfenrolled')) {
6259: if ($currlim eq 'allstudents') {
6260: $output .= &mt('Limit by total students');
6261: } elsif ($currlim eq 'selfenrolled') {
6262: $output .= &mt('Limit by total self-enrolled students');
6263: }
6264: $output .= ' '.&mt('Maximum: [_1]',$currcap).
6265: '<br />'.&mt('(Set by Domain Coordinator)');
6266: } else {
6267: $output .= &mt('No limit').'<br />'.&mt('(Set by Domain Coordinator)');
6268: }
6269: next;
6270: }
1.276 raeburn 6271: if ($currlim eq 'allstudents') {
6272: $crslimit = ' checked="checked" ';
6273: $selflimit = ' ';
6274: $nolimit = ' ';
6275: } elsif ($currlim eq 'selfenrolled') {
6276: $crslimit = ' ';
6277: $selflimit = ' checked="checked" ';
6278: $nolimit = ' ';
6279: } else {
6280: $crslimit = ' ';
6281: $selflimit = ' ';
1.398 raeburn 6282: $nolimit = ' checked="checked" ';
1.276 raeburn 6283: }
6284: $output .= '<table><tr><td><label>'.
1.418 raeburn 6285: '<input type="radio" name="selfenroll_limit" value="none"'.$nolimit.$disabled.'/>'.
1.276 raeburn 6286: &mt('No limit').'</label></td><td><label>'.
1.418 raeburn 6287: '<input type="radio" name="selfenroll_limit" value="allstudents"'.$crslimit.$disabled.'/>'.
1.276 raeburn 6288: &mt('Limit by total students').'</label></td><td><label>'.
1.418 raeburn 6289: '<input type="radio" name="selfenroll_limit" value="selfenrolled"'.$selflimit.$disabled.'/>'.
1.276 raeburn 6290: &mt('Limit by total self-enrolled students').
6291: '</td></tr><tr>'.
6292: '<td> </td><td colspan="2"><span class="LC_nobreak">'.
6293: (' 'x3).&mt('Maximum number allowed: ').
1.418 raeburn 6294: '<input type="text" name="selfenroll_cap" size = "5" value="'.$currcap.'"'.$disabled.' /></td></tr></table>';
1.237 raeburn 6295: }
6296: $output .= &Apache::lonhtmlcommon::row_closure(1);
6297: }
6298: }
1.418 raeburn 6299: $output .= &Apache::lonhtmlcommon::end_pick_box().'<br />';
6300: unless ($readonly) {
6301: $output .= '<input type="button" name="selfenrollconf" value="'
6302: .&mt('Save').'" onclick="validate_types(this.form);" />';
6303: }
6304: $output .= '<input type="hidden" name="action" value="selfenroll" />'
6305: .'<input type="hidden" name="state" value="done" />'."\n"
6306: .$additional.'</form>';
1.237 raeburn 6307: $r->print($output);
6308: return;
6309: }
6310:
1.400 raeburn 6311: sub get_noedit_fields {
6312: my ($cdom,$cnum,$crstype,$row) = @_;
6313: my %noedit;
6314: if (ref($row) eq 'ARRAY') {
6315: my %settings = &Apache::lonnet::get('environment',['internal.coursecode','internal.textbook',
6316: 'internal.selfenrollmgrdc',
6317: 'internal.selfenrollmgrcc'],$cdom,$cnum);
6318: my $type = &Apache::lonuserutils::get_extended_type($cdom,$cnum,$crstype,\%settings);
6319: my (%specific_managebydc,%specific_managebycc,%default_managebydc);
6320: map { $specific_managebydc{$_} = 1; } (split(/,/,$settings{'internal.selfenrollmgrdc'}));
6321: map { $specific_managebycc{$_} = 1; } (split(/,/,$settings{'internal.selfenrollmgrcc'}));
6322: my %domdefaults = &Apache::lonnet::get_domain_defaults($cdom);
6323: map { $default_managebydc{$_} = 1; } (split(/,/,$domdefaults{$type.'selfenrolladmdc'}));
6324:
6325: foreach my $item (@{$row}) {
6326: next if ($specific_managebycc{$item});
6327: if (($specific_managebydc{$item}) || ($default_managebydc{$item})) {
6328: $noedit{$item} = 1;
6329: }
6330: }
6331: }
6332: return %noedit;
6333: }
6334:
6335: sub visible_in_stdcat {
6336: my ($cdom,$cnum,$domconf) = @_;
6337: my ($cathash,%settable,@vismsgs,$cansetvis,$visible);
6338: unless (ref($domconf) eq 'HASH') {
6339: return ($visible,$cansetvis,\@vismsgs);
6340: }
6341: if (ref($domconf->{'coursecategories'}) eq 'HASH') {
6342: if ($domconf->{'coursecategories'}{'togglecats'} eq 'crs') {
1.256 raeburn 6343: $settable{'togglecats'} = 1;
6344: }
1.400 raeburn 6345: if ($domconf->{'coursecategories'}{'categorize'} eq 'crs') {
1.256 raeburn 6346: $settable{'categorize'} = 1;
6347: }
1.400 raeburn 6348: $cathash = $domconf->{'coursecategories'}{'cats'};
1.256 raeburn 6349: }
1.260 raeburn 6350: if ($settable{'togglecats'} && $settable{'categorize'}) {
1.256 raeburn 6351: $cansetvis = &mt('You are able to both assign a course category and choose to exclude this course from the catalog.');
6352: } elsif ($settable{'togglecats'}) {
6353: $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 6354: } elsif ($settable{'categorize'}) {
1.256 raeburn 6355: $cansetvis = &mt('You may assign a course category, but only a Domain Coordinator may choose to exclude this course from the catalog.');
6356: } else {
6357: $cansetvis = &mt('Only a Domain Coordinator may assign a course category or choose to exclude this course from the catalog.');
6358: }
6359:
6360: my %currsettings =
6361: &Apache::lonnet::get('environment',['hidefromcat','categories','internal.coursecode'],
6362: $cdom,$cnum);
1.400 raeburn 6363: $visible = 0;
1.256 raeburn 6364: if ($currsettings{'internal.coursecode'} ne '') {
1.400 raeburn 6365: if (ref($domconf->{'coursecategories'}) eq 'HASH') {
6366: $cathash = $domconf->{'coursecategories'}{'cats'};
1.256 raeburn 6367: if (ref($cathash) eq 'HASH') {
6368: if ($cathash->{'instcode::0'} eq '') {
6369: push(@vismsgs,'dc_addinst');
6370: } else {
6371: $visible = 1;
6372: }
6373: } else {
6374: $visible = 1;
6375: }
6376: } else {
6377: $visible = 1;
6378: }
6379: } else {
6380: if (ref($cathash) eq 'HASH') {
6381: if ($cathash->{'instcode::0'} ne '') {
6382: push(@vismsgs,'dc_instcode');
6383: }
6384: } else {
6385: push(@vismsgs,'dc_instcode');
6386: }
6387: }
6388: if ($currsettings{'categories'} ne '') {
6389: my $cathash;
1.400 raeburn 6390: if (ref($domconf->{'coursecategories'}) eq 'HASH') {
6391: $cathash = $domconf->{'coursecategories'}{'cats'};
1.256 raeburn 6392: if (ref($cathash) eq 'HASH') {
6393: if (keys(%{$cathash}) == 0) {
6394: push(@vismsgs,'dc_catalog');
6395: } elsif ((keys(%{$cathash}) == 1) && ($cathash->{'instcode::0'} ne '')) {
6396: push(@vismsgs,'dc_categories');
6397: } else {
6398: my @currcategories = split('&',$currsettings{'categories'});
6399: my $matched = 0;
6400: foreach my $cat (@currcategories) {
6401: if ($cathash->{$cat} ne '') {
6402: $visible = 1;
6403: $matched = 1;
6404: last;
6405: }
6406: }
6407: if (!$matched) {
1.260 raeburn 6408: if ($settable{'categorize'}) {
1.256 raeburn 6409: push(@vismsgs,'chgcat');
6410: } else {
6411: push(@vismsgs,'dc_chgcat');
6412: }
6413: }
6414: }
6415: }
6416: }
6417: } else {
6418: if (ref($cathash) eq 'HASH') {
6419: if ((keys(%{$cathash}) > 1) ||
6420: (keys(%{$cathash}) == 1) && ($cathash->{'instcode::0'} eq '')) {
1.260 raeburn 6421: if ($settable{'categorize'}) {
1.256 raeburn 6422: push(@vismsgs,'addcat');
6423: } else {
6424: push(@vismsgs,'dc_addcat');
6425: }
6426: }
6427: }
6428: }
6429: if ($currsettings{'hidefromcat'} eq 'yes') {
6430: $visible = 0;
6431: if ($settable{'togglecats'}) {
6432: unshift(@vismsgs,'unhide');
6433: } else {
6434: unshift(@vismsgs,'dc_unhide')
6435: }
6436: }
1.400 raeburn 6437: return ($visible,$cansetvis,\@vismsgs);
6438: }
6439:
6440: sub cat_visibility {
6441: my %visactions = &Apache::lonlocal::texthash(
6442: vis => 'This course/community currently appears in the Course/Community Catalog for this domain.',
6443: 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.',
6444: miss => 'This course/community does not currently appear in the Course/Community Catalog for this domain.',
6445: none => 'Display of a course catalog is disabled for this domain.',
6446: yous => 'You should remedy this if you plan to allow self-enrollment, otherwise students will have difficulty finding this course.',
6447: 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.',
6448: make => 'Make any changes to self-enrollment settings below, click "Save", then take action to include the course in the Catalog:',
6449: take => 'Take the following action to ensure the course appears in the Catalog:',
6450: dc_chgconf => 'Ask a domain coordinator to change the Catalog type for this domain.',
6451: dc_setcode => 'Ask a domain coordinator to assign a six character code to the course',
6452: dc_unhide => 'Ask a domain coordinator to change the "Exclude from course catalog" setting.',
6453: dc_addinst => 'Ask a domain coordinator to enable display the catalog of "Official courses (with institutional codes)".',
6454: dc_instcode => 'Ask a domain coordinator to assign an institutional code (if this is an official course).',
6455: dc_catalog => 'Ask a domain coordinator to enable or create at least one course category in the domain.',
6456: dc_categories => 'Ask a domain coordinator to create a hierarchy of categories and sub categories for courses in the domain.',
6457: 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',
6458: dc_addcat => 'Ask a domain coordinator to assign a category to the course.',
6459: );
6460: $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>"');
6461: $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>"');
6462: $visactions{'addcat'} = &mt('Use [_1]Categorize course[_2] to assign a category to the course.','"<a href="/adm/courseprefs?phase=display&actions=courseinfo">','</a>"');
6463: return \%visactions;
1.256 raeburn 6464: }
6465:
1.241 raeburn 6466: sub new_selfenroll_dom_row {
6467: my ($newdom,$num) = @_;
6468: my $domdesc = &Apache::lonnet::domain($newdom);
6469: my $output;
6470: if ($domdesc ne '') {
6471: $output .= &Apache::loncommon::start_data_table_row()
6472: .'<td valign="top"><span class="LC_nobreak">'.&mt('Domain:').' <b>'.$domdesc
6473: .' ('.$newdom.')</b><input type="hidden" name="selfenroll_dom_'.$num
1.249 raeburn 6474: .'" value="'.$newdom.'" /></span><br />'
6475: .'<span class="LC_nobreak"><label><input type="checkbox" '
6476: .'name="selfenroll_activate" value="'.$num.'" '
6477: .'onchange="javascript:update_types('
6478: ."'selfenroll_activate','$num'".');" />'
6479: .&mt('Activate').'</label></span></td>';
1.241 raeburn 6480: my @currinsttypes;
6481: $output .= '<td>'.&mt('User types:').'<br />'
6482: .&selfenroll_inst_types($num,$newdom,\@currinsttypes).'</td>'
6483: .&Apache::loncommon::end_data_table_row();
6484: }
6485: return $output;
6486: }
6487:
6488: sub selfenroll_inst_types {
1.418 raeburn 6489: my ($num,$currdom,$currinsttypes,$readonly) = @_;
1.241 raeburn 6490: my $output;
6491: my $numinrow = 4;
6492: my $count = 0;
6493: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($currdom);
1.247 raeburn 6494: my $othervalue = 'any';
1.418 raeburn 6495: my $disabled;
6496: if ($readonly) {
6497: $disabled = ' disabled="disabled"';
6498: }
1.241 raeburn 6499: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
1.251 raeburn 6500: if (keys(%{$usertypes}) > 0) {
1.247 raeburn 6501: $othervalue = 'other';
6502: }
1.241 raeburn 6503: $output .= '<table><tr>';
6504: foreach my $type (@{$types}) {
6505: if (($count > 0) && ($count%$numinrow == 0)) {
6506: $output .= '</tr><tr>';
6507: }
6508: if (defined($usertypes->{$type})) {
1.257 raeburn 6509: my $esc_type = &escape($type);
1.241 raeburn 6510: $output .= '<td><span class="LC_nobreak"><label><input type = "checkbox" value="'.
1.257 raeburn 6511: $esc_type.'" ';
1.241 raeburn 6512: if (ref($currinsttypes) eq 'ARRAY') {
6513: if (@{$currinsttypes} > 0) {
1.249 raeburn 6514: if (grep(/^any$/,@{$currinsttypes})) {
6515: $output .= 'checked="checked"';
1.257 raeburn 6516: } elsif (grep(/^\Q$esc_type\E$/,@{$currinsttypes})) {
1.241 raeburn 6517: $output .= 'checked="checked"';
6518: }
1.249 raeburn 6519: } else {
6520: $output .= 'checked="checked"';
1.241 raeburn 6521: }
6522: }
1.418 raeburn 6523: $output .= ' name="selfenroll_types_'.$num.'"'.$disabled.' />'.$usertypes->{$type}.'</label></span></td>';
1.241 raeburn 6524: }
6525: $count ++;
6526: }
6527: if (($count > 0) && ($count%$numinrow == 0)) {
6528: $output .= '</tr><tr>';
6529: }
1.249 raeburn 6530: $output .= '<td><span class="LC_nobreak"><label><input type = "checkbox" value="'.$othervalue.'"';
1.241 raeburn 6531: if (ref($currinsttypes) eq 'ARRAY') {
6532: if (@{$currinsttypes} > 0) {
1.249 raeburn 6533: if (grep(/^any$/,@{$currinsttypes})) {
6534: $output .= ' checked="checked"';
6535: } elsif ($othervalue eq 'other') {
6536: if (grep(/^\Q$othervalue\E$/,@{$currinsttypes})) {
6537: $output .= ' checked="checked"';
6538: }
1.241 raeburn 6539: }
1.249 raeburn 6540: } else {
6541: $output .= ' checked="checked"';
1.241 raeburn 6542: }
1.249 raeburn 6543: } else {
6544: $output .= ' checked="checked"';
1.241 raeburn 6545: }
1.418 raeburn 6546: $output .= ' name="selfenroll_types_'.$num.'"'.$disabled.' />'.$othertitle.'</label></span></td></tr></table>';
1.241 raeburn 6547: }
6548: return $output;
6549: }
6550:
1.237 raeburn 6551: sub selfenroll_date_forms {
6552: my ($startform,$endform) = @_;
6553: my $output .= &Apache::lonhtmlcommon::start_pick_box()."\n".
1.244 bisitz 6554: &Apache::lonhtmlcommon::row_title(&mt('Start date'),
1.237 raeburn 6555: 'LC_oddrow_value')."\n".
6556: $startform."\n".
6557: &Apache::lonhtmlcommon::row_closure(1).
1.244 bisitz 6558: &Apache::lonhtmlcommon::row_title(&mt('End date'),
1.237 raeburn 6559: 'LC_oddrow_value')."\n".
6560: $endform."\n".
6561: &Apache::lonhtmlcommon::row_closure(1).
6562: &Apache::lonhtmlcommon::end_pick_box();
6563: return $output;
6564: }
6565:
1.239 raeburn 6566: sub print_userchangelogs_display {
1.415 raeburn 6567: my ($r,$context,$permission,$brcrum) = @_;
1.363 raeburn 6568: my $formname = 'rolelog';
1.418 raeburn 6569: my ($username,$domain,$crstype,$viewablesec,%roleslog);
1.363 raeburn 6570: if ($context eq 'domain') {
6571: $domain = $env{'request.role.domain'};
6572: %roleslog=&Apache::lonnet::dump_dom('nohist_rolelog',$domain);
6573: } else {
6574: if ($context eq 'course') {
6575: $domain = $env{'course.'.$env{'request.course.id'}.'.domain'};
6576: $username = $env{'course.'.$env{'request.course.id'}.'.num'};
6577: $crstype = &Apache::loncommon::course_type();
1.418 raeburn 6578: $viewablesec = &Apache::lonuserutils::viewable_section($permission);
1.363 raeburn 6579: my %saveable_parameters = ('show' => 'scalar',);
6580: &Apache::loncommon::store_course_settings('roles_log',
6581: \%saveable_parameters);
6582: &Apache::loncommon::restore_course_settings('roles_log',
6583: \%saveable_parameters);
6584: } elsif ($context eq 'author') {
6585: $domain = $env{'user.domain'};
6586: if ($env{'request.role'} =~ m{^au\./\Q$domain\E/$}) {
6587: $username = $env{'user.name'};
6588: } else {
6589: undef($domain);
6590: }
6591: }
6592: if ($domain ne '' && $username ne '') {
6593: %roleslog=&Apache::lonnet::dump('nohist_rolelog',$domain,$username);
6594: }
6595: }
1.239 raeburn 6596: if ((keys(%roleslog))[0]=~/^error\:/) { undef(%roleslog); }
6597:
1.415 raeburn 6598: my $helpitem;
6599: if ($context eq 'course') {
6600: $helpitem = 'Course_User_Logs';
1.439 raeburn 6601: } elsif ($context eq 'domain') {
6602: $helpitem = 'Domain_Role_Logs';
6603: } elsif ($context eq 'author') {
6604: $helpitem = 'Author_User_Logs';
1.415 raeburn 6605: }
6606: push (@{$brcrum},
6607: {href => '/adm/createuser?action=changelogs',
6608: text => 'User Management Logs',
6609: help => $helpitem});
6610: my $bread_crumbs_component = 'User Changes';
6611: my $args = { bread_crumbs => $brcrum,
6612: bread_crumbs_component => $bread_crumbs_component};
6613:
6614: # Create navigation javascript
6615: my $jsnav = &userlogdisplay_js($formname);
6616:
6617: my $jscript = (<<ENDSCRIPT);
6618: <script type="text/javascript">
6619: // <![CDATA[
6620: $jsnav
6621: // ]]>
6622: </script>
6623: ENDSCRIPT
6624:
6625: # print page header
6626: $r->print(&header($jscript,$args));
6627:
1.239 raeburn 6628: # set defaults
6629: my $now = time();
6630: my $defstart = $now - (7*24*3600); #7 days ago
6631: my %defaults = (
6632: page => '1',
6633: show => '10',
6634: role => 'any',
6635: chgcontext => 'any',
6636: rolelog_start_date => $defstart,
6637: rolelog_end_date => $now,
6638: );
6639: my $more_records = 0;
6640:
6641: # set current
6642: my %curr;
6643: foreach my $item ('show','page','role','chgcontext') {
6644: $curr{$item} = $env{'form.'.$item};
6645: }
6646: my ($startdate,$enddate) =
6647: &Apache::lonuserutils::get_dates_from_form('rolelog_start_date','rolelog_end_date');
6648: $curr{'rolelog_start_date'} = $startdate;
6649: $curr{'rolelog_end_date'} = $enddate;
6650: foreach my $key (keys(%defaults)) {
6651: if ($curr{$key} eq '') {
6652: $curr{$key} = $defaults{$key};
6653: }
6654: }
1.248 raeburn 6655: my (%whodunit,%changed,$version);
6656: ($version) = ($r->dir_config('lonVersion') =~ /^([\d\.]+)\-/);
1.239 raeburn 6657: my ($minshown,$maxshown);
1.255 raeburn 6658: $minshown = 1;
1.239 raeburn 6659: my $count = 0;
1.415 raeburn 6660: if ($curr{'show'} =~ /\D/) {
6661: $curr{'page'} = 1;
6662: } else {
1.239 raeburn 6663: $maxshown = $curr{'page'} * $curr{'show'};
6664: if ($curr{'page'} > 1) {
6665: $minshown = 1 + ($curr{'page'} - 1) * $curr{'show'};
6666: }
6667: }
1.301 bisitz 6668:
1.327 raeburn 6669: # Form Header
6670: $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">'.
1.363 raeburn 6671: &role_display_filter($context,$formname,$domain,$username,\%curr,
6672: $version,$crstype));
1.327 raeburn 6673:
6674: my $showntableheader = 0;
6675:
6676: # Table Header
6677: my $tableheader =
6678: &Apache::loncommon::start_data_table_header_row()
6679: .'<th> </th>'
6680: .'<th>'.&mt('When').'</th>'
6681: .'<th>'.&mt('Who made the change').'</th>'
6682: .'<th>'.&mt('Changed User').'</th>'
1.363 raeburn 6683: .'<th>'.&mt('Role').'</th>';
6684:
6685: if ($context eq 'course') {
6686: $tableheader .= '<th>'.&mt('Section').'</th>';
6687: }
6688: $tableheader .=
6689: '<th>'.&mt('Context').'</th>'
1.327 raeburn 6690: .'<th>'.&mt('Start').'</th>'
6691: .'<th>'.&mt('End').'</th>'
6692: .&Apache::loncommon::end_data_table_header_row();
6693:
6694: # Display user change log data
1.239 raeburn 6695: foreach my $id (sort { $roleslog{$b}{'exe_time'}<=>$roleslog{$a}{'exe_time'} } (keys(%roleslog))) {
6696: next if (($roleslog{$id}{'exe_time'} < $curr{'rolelog_start_date'}) ||
6697: ($roleslog{$id}{'exe_time'} > $curr{'rolelog_end_date'}));
1.415 raeburn 6698: if ($curr{'show'} !~ /\D/) {
1.239 raeburn 6699: if ($count >= $curr{'page'} * $curr{'show'}) {
6700: $more_records = 1;
6701: last;
6702: }
6703: }
6704: if ($curr{'role'} ne 'any') {
6705: next if ($roleslog{$id}{'logentry'}{'role'} ne $curr{'role'});
6706: }
6707: if ($curr{'chgcontext'} ne 'any') {
6708: if ($curr{'chgcontext'} eq 'selfenroll') {
6709: next if (!$roleslog{$id}{'logentry'}{'selfenroll'});
6710: } else {
6711: next if ($roleslog{$id}{'logentry'}{'context'} ne $curr{'chgcontext'});
6712: }
6713: }
1.418 raeburn 6714: if (($context eq 'course') && ($viewablesec ne '')) {
1.430 raeburn 6715: next if ($roleslog{$id}{'logentry'}{'section'} ne $viewablesec);
1.418 raeburn 6716: }
1.239 raeburn 6717: $count ++;
6718: next if ($count < $minshown);
1.327 raeburn 6719: unless ($showntableheader) {
1.415 raeburn 6720: $r->print(&Apache::loncommon::start_data_table()
1.327 raeburn 6721: .$tableheader);
6722: $r->rflush();
6723: $showntableheader = 1;
6724: }
1.239 raeburn 6725: if ($whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}} eq '') {
6726: $whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}} =
6727: &Apache::loncommon::plainname($roleslog{$id}{'exe_uname'},$roleslog{$id}{'exe_udom'});
6728: }
6729: if ($changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}} eq '') {
6730: $changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}} =
6731: &Apache::loncommon::plainname($roleslog{$id}{'uname'},$roleslog{$id}{'udom'});
6732: }
6733: my $sec = $roleslog{$id}{'logentry'}{'section'};
6734: if ($sec eq '') {
6735: $sec = &mt('None');
6736: }
6737: my ($rolestart,$roleend);
6738: if ($roleslog{$id}{'delflag'}) {
6739: $rolestart = &mt('deleted');
6740: $roleend = &mt('deleted');
6741: } else {
6742: $rolestart = $roleslog{$id}{'logentry'}{'start'};
6743: $roleend = $roleslog{$id}{'logentry'}{'end'};
6744: if ($rolestart eq '' || $rolestart == 0) {
6745: $rolestart = &mt('No start date');
6746: } else {
6747: $rolestart = &Apache::lonlocal::locallocaltime($rolestart);
6748: }
6749: if ($roleend eq '' || $roleend == 0) {
6750: $roleend = &mt('No end date');
6751: } else {
6752: $roleend = &Apache::lonlocal::locallocaltime($roleend);
6753: }
6754: }
6755: my $chgcontext = $roleslog{$id}{'logentry'}{'context'};
6756: if ($roleslog{$id}{'logentry'}{'selfenroll'}) {
6757: $chgcontext = 'selfenroll';
6758: }
1.363 raeburn 6759: my %lt = &rolechg_contexts($context,$crstype);
1.239 raeburn 6760: if ($chgcontext ne '' && $lt{$chgcontext} ne '') {
6761: $chgcontext = $lt{$chgcontext};
6762: }
1.327 raeburn 6763: $r->print(
1.301 bisitz 6764: &Apache::loncommon::start_data_table_row()
6765: .'<td>'.$count.'</td>'
6766: .'<td>'.&Apache::lonlocal::locallocaltime($roleslog{$id}{'exe_time'}).'</td>'
6767: .'<td>'.$whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}}.'</td>'
6768: .'<td>'.$changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}}.'</td>'
1.363 raeburn 6769: .'<td>'.&Apache::lonnet::plaintext($roleslog{$id}{'logentry'}{'role'},$crstype).'</td>');
6770: if ($context eq 'course') {
6771: $r->print('<td>'.$sec.'</td>');
6772: }
6773: $r->print(
6774: '<td>'.$chgcontext.'</td>'
1.301 bisitz 6775: .'<td>'.$rolestart.'</td>'
6776: .'<td>'.$roleend.'</td>'
1.327 raeburn 6777: .&Apache::loncommon::end_data_table_row()."\n");
1.301 bisitz 6778: }
6779:
1.327 raeburn 6780: if ($showntableheader) { # Table footer, if content displayed above
1.415 raeburn 6781: $r->print(&Apache::loncommon::end_data_table().
6782: &userlogdisplay_navlinks(\%curr,$more_records));
1.327 raeburn 6783: } else { # No content displayed above
1.301 bisitz 6784: $r->print('<p class="LC_info">'
6785: .&mt('There are no records to display.')
6786: .'</p>'
6787: );
1.239 raeburn 6788: }
1.301 bisitz 6789:
1.327 raeburn 6790: # Form Footer
6791: $r->print(
6792: '<input type="hidden" name="page" value="'.$curr{'page'}.'" />'
6793: .'<input type="hidden" name="action" value="changelogs" />'
6794: .'</form>');
6795: return;
6796: }
1.301 bisitz 6797:
1.416 raeburn 6798: sub print_useraccesslogs_display {
6799: my ($r,$uname,$udom,$permission,$brcrum) = @_;
6800: my $formname = 'accesslog';
6801: my $form = 'document.accesslog';
6802:
6803: # set breadcrumbs
1.422 raeburn 6804: my %breadcrumb_text = &singleuser_breadcrumb('','domain',$udom);
1.431 raeburn 6805: my $prevphasestr;
6806: if ($env{'form.popup'}) {
6807: $brcrum = [];
6808: } else {
6809: push (@{$brcrum},
6810: {href => "javascript:backPage($form)",
6811: text => $breadcrumb_text{'search'}});
6812: my @prevphases;
6813: if ($env{'form.prevphases'}) {
6814: @prevphases = split(/,/,$env{'form.prevphases'});
6815: $prevphasestr = $env{'form.prevphases'};
6816: }
6817: if (($env{'form.phase'} eq 'userpicked') || (grep(/^userpicked$/,@prevphases))) {
6818: push(@{$brcrum},
6819: {href => "javascript:backPage($form,'get_user_info','select')",
6820: text => $breadcrumb_text{'userpicked'}});
6821: if ($env{'form.phase'} eq 'userpicked') {
6822: $prevphasestr = 'userpicked';
6823: }
1.416 raeburn 6824: }
6825: }
6826: push(@{$brcrum},
6827: {href => '/adm/createuser?action=accesslogs',
6828: text => 'User access logs',
1.424 raeburn 6829: help => 'Domain_User_Access_Logs'});
1.416 raeburn 6830: my $bread_crumbs_component = 'User Access Logs';
6831: my $args = { bread_crumbs => $brcrum,
6832: bread_crumbs_component => 'User Management'};
1.423 raeburn 6833: if ($env{'form.popup'}) {
6834: $args->{'no_nav_bar'} = 1;
1.431 raeburn 6835: $args->{'bread_crumbs_nomenu'} = 1;
1.423 raeburn 6836: }
1.416 raeburn 6837:
1.417 raeburn 6838: # set javascript
1.416 raeburn 6839: my ($jsback,$elements) = &crumb_utilities();
6840: my $jsnav = &userlogdisplay_js($formname);
6841:
6842: my $jscript = (<<ENDSCRIPT);
6843: <script type="text/javascript">
6844: // <![CDATA[
6845:
6846: $jsback
6847: $jsnav
6848:
6849: // ]]>
6850: </script>
6851:
6852: ENDSCRIPT
6853:
1.417 raeburn 6854: # print page header
1.416 raeburn 6855: $r->print(&header($jscript,$args));
6856:
6857: # early out unless log data can be displayed.
6858: unless ($permission->{'activity'}) {
6859: $r->print('<p class="LC_warning">'
6860: .&mt('You do not have rights to display user access logs.')
1.431 raeburn 6861: .'</p>');
6862: if ($env{'form.popup'}) {
6863: $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a></p>');
6864: } else {
6865: $r->print(&earlyout_accesslog_form($formname,$prevphasestr,$udom));
6866: }
1.416 raeburn 6867: return;
6868: }
6869:
6870: unless ($udom eq $env{'request.role.domain'}) {
6871: $r->print('<p class="LC_warning">'
6872: .&mt("User's domain must match role's domain")
6873: .'</p>'
6874: .&earlyout_accesslog_form($formname,$prevphasestr,$udom));
1.417 raeburn 6875: return;
1.416 raeburn 6876: }
6877:
6878: if (($uname eq '') || ($udom eq '')) {
6879: $r->print('<p class="LC_warning">'
6880: .&mt('Invalid username or domain')
6881: .'</p>'
6882: .&earlyout_accesslog_form($formname,$prevphasestr,$udom));
6883: return;
6884: }
6885:
1.437 raeburn 6886: if (&Apache::lonnet::privileged($uname,$udom,
6887: [$env{'request.role.domain'}],['dc','su'])) {
6888: unless (&Apache::lonnet::privileged($env{'user.name'},$env{'user.domain'},
6889: [$env{'request.role.domain'}],['dc','su'])) {
6890: $r->print('<p class="LC_warning">'
6891: .&mt('You need to be a privileged user to display user access logs for [_1]',
6892: &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),
6893: $uname,$udom))
6894: .'</p>');
6895: if ($env{'form.popup'}) {
6896: $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a></p>');
6897: } else {
6898: $r->print(&earlyout_accesslog_form($formname,$prevphasestr,$udom));
6899: }
6900: return;
6901: }
6902: }
6903:
1.416 raeburn 6904: # set defaults
6905: my $now = time();
6906: my $defstart = $now - (7*24*3600);
6907: my %defaults = (
6908: page => '1',
6909: show => '10',
6910: activity => 'any',
6911: accesslog_start_date => $defstart,
6912: accesslog_end_date => $now,
6913: );
6914: my $more_records = 0;
6915:
6916: # set current
6917: my %curr;
6918: foreach my $item ('show','page','activity') {
6919: $curr{$item} = $env{'form.'.$item};
6920: }
6921: my ($startdate,$enddate) =
6922: &Apache::lonuserutils::get_dates_from_form('accesslog_start_date','accesslog_end_date');
6923: $curr{'accesslog_start_date'} = $startdate;
6924: $curr{'accesslog_end_date'} = $enddate;
6925: foreach my $key (keys(%defaults)) {
6926: if ($curr{$key} eq '') {
6927: $curr{$key} = $defaults{$key};
6928: }
6929: }
6930: my ($minshown,$maxshown);
6931: $minshown = 1;
6932: my $count = 0;
6933: if ($curr{'show'} =~ /\D/) {
6934: $curr{'page'} = 1;
6935: } else {
6936: $maxshown = $curr{'page'} * $curr{'show'};
6937: if ($curr{'page'} > 1) {
6938: $minshown = 1 + ($curr{'page'} - 1) * $curr{'show'};
6939: }
6940: }
6941:
6942: # form header
6943: $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">'.
6944: &activity_display_filter($formname,\%curr));
6945:
6946: my $showntableheader = 0;
6947: my ($nav_script,$nav_links);
6948:
6949: # table header
1.431 raeburn 6950: my $tableheader = '<h3>'.
6951: &mt('User access logs for: [_1]',
6952: &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),$uname,$udom)).'</h3>'
6953: .&Apache::loncommon::start_data_table_header_row()
1.416 raeburn 6954: .'<th> </th>'
6955: .'<th>'.&mt('When').'</th>'
6956: .'<th>'.&mt('HostID').'</th>'
6957: .'<th>'.&mt('Event').'</th>'
6958: .'<th>'.&mt('Other data').'</th>'
6959: .&Apache::loncommon::end_data_table_header_row();
6960:
6961: my %filters=(
6962: start => $curr{'accesslog_start_date'},
6963: end => $curr{'accesslog_end_date'},
6964: action => $curr{'activity'},
6965: );
6966:
6967: my $reply = &Apache::lonnet::userlog_query($uname,$udom,%filters);
6968: unless ( ($reply =~/^timeout/) || ($reply =~/^error/) ) {
6969: my (%courses,%missing);
6970: my @results = split(/\&/,$reply);
6971: foreach my $item (reverse(@results)) {
6972: my ($timestamp,$host,$event) = split(/:/,$item);
6973: next unless ($event =~ /^(Log|Role)/);
6974: if ($curr{'show'} !~ /\D/) {
6975: if ($count >= $curr{'page'} * $curr{'show'}) {
6976: $more_records = 1;
6977: last;
6978: }
6979: }
6980: $count ++;
6981: next if ($count < $minshown);
6982: unless ($showntableheader) {
6983: $r->print($nav_script
6984: .&Apache::loncommon::start_data_table()
6985: .$tableheader);
6986: $r->rflush();
6987: $showntableheader = 1;
6988: }
1.418 raeburn 6989: my ($shown,$extra);
1.437 raeburn 6990: my ($event,$data) = split(/\s+/,&unescape($event),2);
1.416 raeburn 6991: if ($event eq 'Role') {
6992: my ($rolecode,$extent) = split(/\./,$data,2);
6993: next if ($extent eq '');
6994: my ($crstype,$desc,$info);
1.418 raeburn 6995: if ($extent =~ m{^/($match_domain)/($match_courseid)(?:/(\w+)|)$}) {
6996: my ($cdom,$cnum,$sec) = ($1,$2,$3);
1.416 raeburn 6997: my $cid = $cdom.'_'.$cnum;
6998: if (exists($courses{$cid})) {
6999: $crstype = $courses{$cid}{'type'};
7000: $desc = $courses{$cid}{'description'};
7001: } elsif ($missing{$cid}) {
7002: $crstype = 'Course';
7003: $desc = 'Course/Community';
7004: } else {
7005: my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',$cnum,undef,undef,'.');
7006: if (ref($crsinfo{$cdom.'_'.$cnum}) eq 'HASH') {
7007: $courses{$cid} = $crsinfo{$cid};
7008: $crstype = $crsinfo{$cid}{'type'};
7009: $desc = $crsinfo{$cid}{'description'};
7010: } else {
7011: $missing{$cid} = 1;
7012: }
7013: }
7014: $extra = &mt($crstype).': <a href="/public/'.$cdom.'/'.$cnum.'/syllabus">'.$desc.'</a>';
1.418 raeburn 7015: if ($sec ne '') {
7016: $extra .= ' ('.&mt('Section: [_1]',$sec).')';
7017: }
1.416 raeburn 7018: } elsif ($extent =~ m{^/($match_domain)/($match_username|$)}) {
7019: my ($dom,$name) = ($1,$2);
7020: if ($rolecode eq 'au') {
7021: $extra = '';
7022: } elsif ($rolecode =~ /^(ca|aa)$/) {
1.417 raeburn 7023: $extra = &mt('Authoring Space: [_1]',$name.':'.$dom);
1.416 raeburn 7024: } elsif ($rolecode =~ /^(li|dg|dh|dc|sc)$/) {
7025: $extra = &mt('Domain: [_1]',$dom);
7026: }
7027: }
7028: my $rolename;
7029: if ($rolecode =~ m{^cr/($match_domain)/($match_username)/(\w+)}) {
7030: my $role = $3;
1.417 raeburn 7031: my $owner = "($2:$1)";
1.416 raeburn 7032: if ($2 eq $1.'-domainconfig') {
7033: $owner = '(ad hoc)';
1.417 raeburn 7034: }
1.416 raeburn 7035: $rolename = &mt('Custom role: [_1]',$role.' '.$owner);
7036: } else {
7037: $rolename = &Apache::lonnet::plaintext($rolecode,$crstype);
7038: }
7039: $shown = &mt('Role selection: [_1]',$rolename);
7040: } else {
7041: $shown = &mt($event);
1.437 raeburn 7042: if ($data =~ /^webdav/) {
7043: my ($path,$clientip) = split(/\s+/,$data,2);
7044: $path =~ s/^webdav//;
7045: if ($clientip ne '') {
7046: $extra = &mt('Client IP address: [_1]',$clientip);
7047: }
7048: if ($path ne '') {
7049: $shown .= ' '.&mt('(WebDAV access to [_1])',$path);
7050: }
7051: } elsif ($data ne '') {
7052: $extra = &mt('Client IP address: [_1]',$data);
1.416 raeburn 7053: }
7054: }
7055: $r->print(
7056: &Apache::loncommon::start_data_table_row()
7057: .'<td>'.$count.'</td>'
7058: .'<td>'.&Apache::lonlocal::locallocaltime($timestamp).'</td>'
7059: .'<td>'.$host.'</td>'
7060: .'<td>'.$shown.'</td>'
7061: .'<td>'.$extra.'</td>'
7062: .&Apache::loncommon::end_data_table_row()."\n");
7063: }
7064: }
7065:
7066: if ($showntableheader) { # Table footer, if content displayed above
7067: $r->print(&Apache::loncommon::end_data_table().
7068: &userlogdisplay_navlinks(\%curr,$more_records));
7069: } else { # No content displayed above
7070: $r->print('<p class="LC_info">'
7071: .&mt('There are no records to display.')
7072: .'</p>');
7073: }
7074:
1.423 raeburn 7075: if ($env{'form.popup'} == 1) {
7076: $r->print('<input type="hidden" name="popup" value="1" />'."\n");
7077: }
7078:
1.416 raeburn 7079: # Form Footer
7080: $r->print(
7081: '<input type="hidden" name="currstate" value="" />'
7082: .'<input type="hidden" name="accessuname" value="'.$uname.'" />'
7083: .'<input type="hidden" name="accessudom" value="'.$udom.'" />'
7084: .'<input type="hidden" name="page" value="'.$curr{'page'}.'" />'
7085: .'<input type="hidden" name="prevphases" value="'.$prevphasestr.'" />'
7086: .'<input type="hidden" name="phase" value="activity" />'
7087: .'<input type="hidden" name="action" value="accesslogs" />'
7088: .'<input type="hidden" name="srchdomain" value="'.$udom.'" />'
7089: .'<input type="hidden" name="srchby" value="'.$env{'form.srchby'}.'" />'
7090: .'<input type="hidden" name="srchtype" value="'.$env{'form.srchtype'}.'" />'
7091: .'<input type="hidden" name="srchterm" value="'.&HTML::Entities::encode($env{'form.srchterm'},'<>"&').'" />'
7092: .'<input type="hidden" name="srchin" value="'.$env{'form.srchin'}.'" />'
7093: .'</form>');
7094: return;
7095: }
7096:
7097: sub earlyout_accesslog_form {
7098: my ($formname,$prevphasestr,$udom) = @_;
7099: my $srchterm = &HTML::Entities::encode($env{'form.srchterm'},'<>"&');
7100: return <<"END";
7101: <form action="/adm/createuser" method="post" name="$formname">
7102: <input type="hidden" name="currstate" value="" />
7103: <input type="hidden" name="prevphases" value="$prevphasestr" />
7104: <input type="hidden" name="phase" value="activity" />
7105: <input type="hidden" name="action" value="accesslogs" />
7106: <input type="hidden" name="srchdomain" value="$udom" />
7107: <input type="hidden" name="srchby" value="$env{'form.srchby'}" />
7108: <input type="hidden" name="srchtype" value="$env{'form.srchtype'}" />
7109: <input type="hidden" name="srchterm" value="$srchterm" />
7110: <input type="hidden" name="srchin" value="$env{'form.srchin'}" />
7111: </form>
7112: END
7113: }
7114:
7115: sub activity_display_filter {
7116: my ($formname,$curr) = @_;
7117: my $nolink = 1;
7118: my $output = '<table><tr><td valign="top">'.
7119: '<span class="LC_nobreak"><b>'.&mt('Actions/page:').'</b></span><br />'.
7120: &Apache::lonmeta::selectbox('show',$curr->{'show'},undef,
7121: (&mt('all'),5,10,20,50,100,1000,10000)).
7122: '</td><td> </td>';
7123: my $startform =
7124: &Apache::lonhtmlcommon::date_setter($formname,'accesslog_start_date',
7125: $curr->{'accesslog_start_date'},undef,
7126: undef,undef,undef,undef,undef,undef,$nolink);
7127: my $endform =
7128: &Apache::lonhtmlcommon::date_setter($formname,'accesslog_end_date',
7129: $curr->{'accesslog_end_date'},undef,
7130: undef,undef,undef,undef,undef,undef,$nolink);
7131: my %lt = &Apache::lonlocal::texthash (
7132: activity => 'Activity',
7133: Role => 'Role selection',
7134: log => 'Log-in or Logout',
7135: );
7136: $output .= '<td valign="top"><b>'.&mt('Window during which actions occurred:').'</b><br />'.
7137: '<table><tr><td>'.&mt('After:').
7138: '</td><td>'.$startform.'</td></tr>'.
7139: '<tr><td>'.&mt('Before:').'</td>'.
7140: '<td>'.$endform.'</td></tr></table>'.
7141: '</td>'.
7142: '<td> </td>'.
7143: '<td valign="top"><b>'.&mt('Activities').'</b><br />'.
7144: '<select name="activity"><option value="any"';
7145: if ($curr->{'activity'} eq 'any') {
7146: $output .= ' selected="selected"';
7147: }
7148: $output .= '>'.&mt('Any').'</option>'."\n";
7149: foreach my $activity ('Role','log') {
7150: my $selstr = '';
7151: if ($activity eq $curr->{'activity'}) {
7152: $selstr = ' selected="selected"';
7153: }
7154: $output .= '<option value="'.$activity.'"'.$selstr.'>'.$lt{$activity}.'</option>';
7155: }
7156: $output .= '</select></td>'.
7157: '</tr></table>';
7158: # Update Display button
7159: $output .= '<p>'
7160: .'<input type="submit" value="'.&mt('Update Display').'" />'
1.431 raeburn 7161: .'</p><hr />';
1.416 raeburn 7162: return $output;
7163: }
7164:
1.415 raeburn 7165: sub userlogdisplay_js {
7166: my ($formname) = @_;
7167: return <<"ENDSCRIPT";
7168:
1.239 raeburn 7169: function chgPage(caller) {
7170: if (caller == 'previous') {
7171: document.$formname.page.value --;
7172: }
7173: if (caller == 'next') {
7174: document.$formname.page.value ++;
7175: }
1.327 raeburn 7176: document.$formname.submit();
1.239 raeburn 7177: return;
7178: }
7179: ENDSCRIPT
1.415 raeburn 7180: }
7181:
7182: sub userlogdisplay_navlinks {
7183: my ($curr,$more_records) = @_;
7184: return unless(ref($curr) eq 'HASH');
7185: # Navigation Buttons
7186: my $nav_links = '<p>';
7187: if (($curr->{'page'} > 1) || ($more_records)) {
7188: if (($curr->{'page'} > 1) && ($curr->{'show'} !~ /\D/)) {
7189: $nav_links .= '<input type="button"'
7190: .' onclick="javascript:chgPage('."'previous'".');"'
7191: .' value="'.&mt('Previous [_1] changes',$curr->{'show'})
7192: .'" /> ';
7193: }
7194: if ($more_records) {
7195: $nav_links .= '<input type="button"'
7196: .' onclick="javascript:chgPage('."'next'".');"'
7197: .' value="'.&mt('Next [_1] changes',$curr->{'show'})
7198: .'" />';
1.301 bisitz 7199: }
7200: }
1.415 raeburn 7201: $nav_links .= '</p>';
7202: return $nav_links;
1.239 raeburn 7203: }
7204:
7205: sub role_display_filter {
1.363 raeburn 7206: my ($context,$formname,$cdom,$cnum,$curr,$version,$crstype) = @_;
7207: my $lctype;
7208: if ($context eq 'course') {
7209: $lctype = lc($crstype);
7210: }
1.239 raeburn 7211: my $nolink = 1;
7212: my $output = '<table><tr><td valign="top">'.
1.301 bisitz 7213: '<span class="LC_nobreak"><b>'.&mt('Changes/page:').'</b></span><br />'.
1.239 raeburn 7214: &Apache::lonmeta::selectbox('show',$curr->{'show'},undef,
7215: (&mt('all'),5,10,20,50,100,1000,10000)).
7216: '</td><td> </td>';
7217: my $startform =
7218: &Apache::lonhtmlcommon::date_setter($formname,'rolelog_start_date',
7219: $curr->{'rolelog_start_date'},undef,
7220: undef,undef,undef,undef,undef,undef,$nolink);
7221: my $endform =
7222: &Apache::lonhtmlcommon::date_setter($formname,'rolelog_end_date',
7223: $curr->{'rolelog_end_date'},undef,
7224: undef,undef,undef,undef,undef,undef,$nolink);
1.363 raeburn 7225: my %lt = &rolechg_contexts($context,$crstype);
1.301 bisitz 7226: $output .= '<td valign="top"><b>'.&mt('Window during which changes occurred:').'</b><br />'.
7227: '<table><tr><td>'.&mt('After:').
7228: '</td><td>'.$startform.'</td></tr>'.
7229: '<tr><td>'.&mt('Before:').'</td>'.
7230: '<td>'.$endform.'</td></tr></table>'.
7231: '</td>'.
7232: '<td> </td>'.
1.239 raeburn 7233: '<td valign="top"><b>'.&mt('Role:').'</b><br />'.
7234: '<select name="role"><option value="any"';
7235: if ($curr->{'role'} eq 'any') {
7236: $output .= ' selected="selected"';
7237: }
7238: $output .= '>'.&mt('Any').'</option>'."\n";
1.363 raeburn 7239: my @roles = &Apache::lonuserutils::roles_by_context($context,1,$crstype);
1.239 raeburn 7240: foreach my $role (@roles) {
7241: my $plrole;
7242: if ($role eq 'cr') {
7243: $plrole = &mt('Custom Role');
7244: } else {
1.318 raeburn 7245: $plrole=&Apache::lonnet::plaintext($role,$crstype);
1.239 raeburn 7246: }
7247: my $selstr = '';
7248: if ($role eq $curr->{'role'}) {
7249: $selstr = ' selected="selected"';
7250: }
7251: $output .= ' <option value="'.$role.'"'.$selstr.'>'.$plrole.'</option>';
7252: }
1.301 bisitz 7253: $output .= '</select></td>'.
7254: '<td> </td>'.
7255: '<td valign="top"><b>'.
1.239 raeburn 7256: &mt('Context:').'</b><br /><select name="chgcontext">';
1.363 raeburn 7257: my @posscontexts;
7258: if ($context eq 'course') {
1.376 raeburn 7259: @posscontexts = ('any','automated','updatenow','createcourse','course','domain','selfenroll','requestcourses');
1.363 raeburn 7260: } elsif ($context eq 'domain') {
7261: @posscontexts = ('any','domain','requestauthor','domconfig','server');
7262: } else {
7263: @posscontexts = ('any','author','domain');
7264: }
7265: foreach my $chgtype (@posscontexts) {
1.239 raeburn 7266: my $selstr = '';
7267: if ($curr->{'chgcontext'} eq $chgtype) {
1.301 bisitz 7268: $selstr = ' selected="selected"';
1.239 raeburn 7269: }
1.363 raeburn 7270: if ($context eq 'course') {
1.376 raeburn 7271: if (($chgtype eq 'automated') || ($chgtype eq 'updatenow')) {
1.363 raeburn 7272: next if (!&Apache::lonnet::auto_run($cnum,$cdom));
7273: }
1.239 raeburn 7274: }
7275: $output .= '<option value="'.$chgtype.'"'.$selstr.'>'.$lt{$chgtype}.'</option>'."\n";
1.248 raeburn 7276: }
1.303 bisitz 7277: $output .= '</select></td>'
7278: .'</tr></table>';
7279:
7280: # Update Display button
7281: $output .= '<p>'
7282: .'<input type="submit" value="'.&mt('Update Display').'" />'
7283: .'</p>';
7284:
7285: # Server version info
1.363 raeburn 7286: my $needsrev = '2.11.0';
7287: if ($context eq 'course') {
7288: $needsrev = '2.7.0';
7289: }
7290:
1.303 bisitz 7291: $output .= '<p class="LC_info">'
7292: .&mt('Only changes made from servers running LON-CAPA [_1] or later are displayed.'
1.363 raeburn 7293: ,$needsrev);
1.248 raeburn 7294: if ($version) {
1.303 bisitz 7295: $output .= ' '.&mt('This LON-CAPA server is version [_1]',$version);
7296: }
7297: $output .= '</p><hr />';
1.239 raeburn 7298: return $output;
7299: }
7300:
7301: sub rolechg_contexts {
1.363 raeburn 7302: my ($context,$crstype) = @_;
7303: my %lt;
7304: if ($context eq 'course') {
7305: %lt = &Apache::lonlocal::texthash (
1.239 raeburn 7306: any => 'Any',
1.376 raeburn 7307: automated => 'Automated Enrollment',
1.239 raeburn 7308: updatenow => 'Roster Update',
7309: createcourse => 'Course Creation',
7310: course => 'User Management in course',
7311: domain => 'User Management in domain',
1.313 raeburn 7312: selfenroll => 'Self-enrolled',
1.318 raeburn 7313: requestcourses => 'Course Request',
1.239 raeburn 7314: );
1.363 raeburn 7315: if ($crstype eq 'Community') {
7316: $lt{'createcourse'} = &mt('Community Creation');
7317: $lt{'course'} = &mt('User Management in community');
7318: $lt{'requestcourses'} = &mt('Community Request');
7319: }
7320: } elsif ($context eq 'domain') {
7321: %lt = &Apache::lonlocal::texthash (
7322: any => 'Any',
7323: domain => 'User Management in domain',
7324: requestauthor => 'Authoring Request',
7325: server => 'Command line script (DC role)',
7326: domconfig => 'Self-enrolled',
7327: );
7328: } else {
7329: %lt = &Apache::lonlocal::texthash (
7330: any => 'Any',
7331: domain => 'User Management in domain',
7332: author => 'User Management by author',
7333: );
7334: }
1.239 raeburn 7335: return %lt;
7336: }
7337:
1.428 raeburn 7338: sub print_helpdeskaccess_display {
7339: my ($r,$permission,$brcrum) = @_;
7340: my $formname = 'helpdeskaccess';
7341: my $helpitem = 'Course_Helpdesk_Access';
7342: push (@{$brcrum},
7343: {href => '/adm/createuser?action=helpdesk',
7344: text => 'Helpdesk Access',
7345: help => $helpitem});
7346: my $bread_crumbs_component = 'Helpdesk Staff Access';
7347: my $args = { bread_crumbs => $brcrum,
7348: bread_crumbs_component => $bread_crumbs_component};
7349:
7350: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
7351: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
7352: my $confname = $cdom.'-domainconfig';
7353: my $crstype = &Apache::loncommon::course_type();
7354:
1.434 raeburn 7355: my @accesstypes = ('all','dh','da','none');
1.428 raeburn 7356: my ($numstatustypes,@jsarray);
7357: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($cdom);
7358: if (ref($types) eq 'ARRAY') {
1.430 raeburn 7359: if (@{$types} > 0) {
1.428 raeburn 7360: $numstatustypes = scalar(@{$types});
7361: push(@accesstypes,'status');
7362: @jsarray = ('bystatus');
7363: }
7364: }
7365: my %customroles = &get_domain_customroles($cdom,$confname);
1.432 raeburn 7366: my %domhelpdesk = &Apache::lonnet::get_active_domroles($cdom,['dh','da']);
1.428 raeburn 7367: if (keys(%domhelpdesk)) {
7368: push(@accesstypes,('inc','exc'));
7369: push(@jsarray,('notinc','notexc'));
7370: }
7371: push(@jsarray,'privs');
7372: my $hiddenstr = join("','",@jsarray);
7373: my $rolestr = join("','",sort(keys(%customroles)));
7374:
7375: my $jscript;
7376: my (%settings,%overridden);
7377: if (keys(%customroles)) {
7378: &get_adhocrole_settings($env{'request.course.id'},\@accesstypes,
7379: $types,\%customroles,\%settings,\%overridden);
7380: my %jsfull=();
7381: my %jslevels= (
7382: course => {},
7383: domain => {},
7384: system => {},
7385: );
7386: my %jslevelscurrent=(
7387: course => {},
7388: domain => {},
7389: system => {},
7390: );
7391: my (%privs,%jsprivs);
7392: &Apache::lonuserutils::custom_role_privs(\%privs,\%jsfull,\%jslevels,\%jslevelscurrent);
7393: foreach my $priv (keys(%jsfull)) {
7394: if ($jslevels{'course'}{$priv}) {
7395: $jsprivs{$priv} = 1;
7396: }
7397: }
7398: my (%elements,%stored);
7399: foreach my $role (keys(%customroles)) {
7400: $elements{$role.'_access'} = 'radio';
7401: $elements{$role.'_incrs'} = 'radio';
7402: if ($numstatustypes) {
7403: $elements{$role.'_status'} = 'checkbox';
7404: }
7405: if (keys(%domhelpdesk) > 0) {
7406: $elements{$role.'_staff_inc'} = 'checkbox';
7407: $elements{$role.'_staff_exc'} = 'checkbox';
7408: }
1.430 raeburn 7409: $elements{$role.'_override'} = 'checkbox';
1.428 raeburn 7410: if (ref($settings{$role}) eq 'HASH') {
7411: if ($settings{$role}{'access'} ne '') {
7412: my $curraccess = $settings{$role}{'access'};
7413: $stored{$role.'_access'} = $curraccess;
7414: $stored{$role.'_incrs'} = 1;
7415: if ($curraccess eq 'status') {
7416: if (ref($settings{$role}{'status'}) eq 'ARRAY') {
7417: $stored{$role.'_status'} = $settings{$role}{'status'};
7418: }
7419: } elsif (($curraccess eq 'exc') || ($curraccess eq 'inc')) {
7420: if (ref($settings{$role}{$curraccess}) eq 'ARRAY') {
7421: $stored{$role.'_staff_'.$curraccess} = $settings{$role}{$curraccess};
7422: }
7423: }
7424: } else {
7425: $stored{$role.'_incrs'} = 0;
7426: }
7427: $stored{$role.'_override'} = [];
7428: if ($env{'course.'.$env{'request.course.id'}.'.internal.adhocpriv.'.$role}) {
7429: if (ref($settings{$role}{'off'}) eq 'ARRAY') {
7430: foreach my $priv (@{$settings{$role}{'off'}}) {
7431: push(@{$stored{$role.'_override'}},$priv);
7432: }
7433: }
7434: if (ref($settings{$role}{'on'}) eq 'ARRAY') {
7435: foreach my $priv (@{$settings{$role}{'on'}}) {
7436: unless (grep(/^$priv$/,@{$stored{$role.'_override'}})) {
7437: push(@{$stored{$role.'_override'}},$priv);
7438: }
7439: }
7440: }
7441: }
7442: } else {
7443: $stored{$role.'_incrs'} = 0;
7444: }
7445: }
7446: $jscript = &Apache::lonhtmlcommon::set_form_elements(\%elements,\%stored);
7447: }
7448:
7449: my $js = <<"ENDJS";
7450: <script type="text/javascript">
7451: // <![CDATA[
7452: $jscript;
7453:
7454: function switchRoleTab(caller,role) {
7455: if (document.getElementById(role+'_maindiv')) {
7456: if (caller.id != 'LC_current_minitab') {
7457: if (document.getElementById('LC_current_minitab')) {
7458: document.getElementById('LC_current_minitab').id=null;
7459: }
7460: var roledivs = Array('$rolestr');
7461: if (roledivs.length > 0) {
7462: for (var i=0; i<roledivs.length; i++) {
7463: if (document.getElementById(roledivs[i]+'_maindiv')) {
7464: document.getElementById(roledivs[i]+'_maindiv').style.display='none';
7465: }
7466: }
7467: }
7468: caller.id = 'LC_current_minitab';
7469: document.getElementById(role+'_maindiv').style.display='block';
7470: }
7471: }
7472: return false;
1.430 raeburn 7473: }
1.428 raeburn 7474:
7475: function helpdeskAccess(role) {
7476: var curraccess = null;
7477: if (document.$formname.elements[role+'_access'].length) {
7478: for (var i=0; i<document.$formname.elements[role+'_access'].length; i++) {
7479: if (document.$formname.elements[role+'_access'][i].checked) {
7480: curraccess = document.$formname.elements[role+'_access'][i].value;
7481: }
7482: }
7483: }
7484: var shown = Array();
7485: var hidden = Array();
7486: if (curraccess == 'none') {
1.430 raeburn 7487: hidden = Array ('$hiddenstr');
1.428 raeburn 7488: } else {
7489: if (curraccess == 'status') {
1.430 raeburn 7490: shown = Array ('bystatus','privs');
7491: hidden = Array ('notinc','notexc');
1.428 raeburn 7492: } else {
7493: if (curraccess == 'exc') {
7494: shown = Array ('notexc','privs');
7495: hidden = Array ('notinc','bystatus');
7496: }
7497: if (curraccess == 'inc') {
7498: shown = Array ('notinc','privs');
7499: hidden = Array ('notexc','bystatus');
7500: }
7501: if (curraccess == 'all') {
7502: shown = Array ('privs');
7503: hidden = Array ('notinc','notexc','bystatus');
7504: }
7505: }
7506: }
7507: if (hidden.length > 0) {
7508: for (var i=0; i<hidden.length; i++) {
7509: if (document.getElementById(role+'_'+hidden[i])) {
1.430 raeburn 7510: document.getElementById(role+'_'+hidden[i]).style.display = 'none';
1.428 raeburn 7511: }
7512: }
7513: }
7514: if (shown.length > 0) {
7515: for (var i=0; i<shown.length; i++) {
7516: if (document.getElementById(role+'_'+shown[i])) {
7517: if (shown[i] == 'privs') {
7518: document.getElementById(role+'_'+shown[i]).style.display = 'block';
7519: } else {
7520: document.getElementById(role+'_'+shown[i]).style.display = 'inline';
7521: }
7522: }
7523: }
7524: }
7525: return;
7526: }
7527:
7528: function toggleAccess(role) {
7529: if ((document.getElementById(role+'_setincrs')) &&
7530: (document.getElementById(role+'_setindom'))) {
7531: for (var i=0; i<document.$formname.elements[role+'_incrs'].length; i++) {
7532: if (document.$formname.elements[role+'_incrs'][i].checked) {
7533: if (document.$formname.elements[role+'_incrs'][i].value == 1) {
7534: document.getElementById(role+'_setindom').style.display = 'none';
1.430 raeburn 7535: document.getElementById(role+'_setincrs').style.display = 'block';
1.428 raeburn 7536: } else {
7537: document.getElementById(role+'_setincrs').style.display = 'none';
7538: document.getElementById(role+'_setindom').style.display = 'block';
7539: }
7540: break;
7541: }
7542: }
7543: }
7544: return;
7545: }
7546:
7547: // ]]>
7548: </script>
7549: ENDJS
7550:
7551: $args->{add_entries} = {onload => "javascript:setFormElements(document.$formname)"};
7552:
7553: # print page header
7554: $r->print(&header($js,$args));
7555: # print form header
7556: $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">');
7557:
7558: if (keys(%customroles)) {
7559: my %lt = &Apache::lonlocal::texthash(
7560: 'aco' => 'As course owner you may override the defaults set in the domain for role usage and/or privileges.',
7561: 'rou' => 'Role usage',
7562: 'whi' => 'Which helpdesk personnel may use this role?',
7563: 'udd' => 'Use domain default',
1.433 raeburn 7564: 'all' => 'All with domain helpdesk or helpdesk assistant role',
1.434 raeburn 7565: 'dh' => 'All with domain helpdesk role',
7566: 'da' => 'All with domain helpdesk assistant role',
1.428 raeburn 7567: 'none' => 'None',
7568: 'status' => 'Determined based on institutional status',
1.430 raeburn 7569: 'inc' => 'Include all, but exclude specific personnel',
1.428 raeburn 7570: 'exc' => 'Exclude all, but include specific personnel',
7571: 'hel' => 'Helpdesk',
7572: 'rpr' => 'Role privileges',
7573: );
7574: $lt{'tfh'} = &mt("Custom [_1]ad hoc[_2] course roles available for use by the domain's helpdesk are as follows",'<i>','</i>');
7575: my %domconfig = &Apache::lonnet::get_dom('configuration',['helpsettings'],$cdom);
7576: my (%domcurrent,%ordered,%description,%domusage,$disabled);
7577: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
7578: if (ref($domconfig{'helpsettings'}{'adhoc'}) eq 'HASH') {
7579: %domcurrent = %{$domconfig{'helpsettings'}{'adhoc'}};
7580: }
7581: }
7582: my $count = 0;
7583: foreach my $role (sort(keys(%customroles))) {
7584: my ($order,$desc,$access_in_dom);
7585: if (ref($domcurrent{$role}) eq 'HASH') {
7586: $order = $domcurrent{$role}{'order'};
7587: $desc = $domcurrent{$role}{'desc'};
7588: $access_in_dom = $domcurrent{$role}{'access'};
7589: }
7590: if ($order eq '') {
7591: $order = $count;
7592: }
7593: $ordered{$order} = $role;
7594: if ($desc ne '') {
7595: $description{$role} = $desc;
7596: } else {
7597: $description{$role}= $role;
7598: }
7599: $count++;
7600: }
7601: %domusage = &domain_adhoc_access(\%customroles,\%domcurrent,\@accesstypes,$usertypes,$othertitle);
7602: my @roles_by_num = ();
7603: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
7604: push(@roles_by_num,$ordered{$item});
1.430 raeburn 7605: }
1.429 raeburn 7606: $r->print('<p>'.$lt{'tfh'}.': <i>'.join('</i>, <i>',map { $description{$_}; } @roles_by_num).'</i>.');
1.428 raeburn 7607: if ($permission->{'owner'}) {
7608: $r->print('<br />'.$lt{'aco'}.'</p><p>');
7609: $r->print('<input type="hidden" name="state" value="process" />'.
7610: '<input type="submit" value="'.&mt('Save changes').'" />');
7611: } else {
7612: if ($env{'course.'.$env{'request.course.id'}.'.internal.courseowner'}) {
7613: my ($ownername,$ownerdom) = split(/:/,$env{'course.'.$env{'request.course.id'}.'.internal.courseowner'});
7614: $r->print('<br />'.&mt('The course owner -- [_1] -- can override the default access and/or privileges for these ad hoc roles.',
7615: &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($ownername,$ownerdom),$ownername,$ownerdom)));
7616: }
7617: $disabled = ' disabled="disabled"';
7618: }
7619: $r->print('</p>');
7620:
7621: $r->print('<div id="LC_minitab_header"><ul>');
7622: my $count = 0;
7623: my %visibility;
7624: foreach my $role (@roles_by_num) {
7625: my $id;
7626: if ($count == 0) {
7627: $id=' id="LC_current_minitab"';
1.430 raeburn 7628: $visibility{$role} = ' style="display:block"';
1.428 raeburn 7629: } else {
7630: $visibility{$role} = ' style="display:none"';
7631: }
7632: $count ++;
7633: $r->print('<li'.$id.'><a href="#" onclick="javascript:switchRoleTab(this.parentNode,'."'$role'".');">'.$description{$role}.'</a></li>');
7634: }
7635: $r->print('</ul></div>');
7636:
7637: foreach my $role (@roles_by_num) {
7638: my %usecheck = (
7639: all => ' checked="checked"',
7640: );
7641: my %displaydiv = (
7642: status => 'none',
7643: inc => 'none',
7644: exc => 'none',
7645: priv => 'block',
7646: );
7647: my (%selected,$overridden,$incrscheck,$indomcheck,$indomvis,$incrsvis);
1.430 raeburn 7648: if (ref($settings{$role}) eq 'HASH') {
1.428 raeburn 7649: if ($settings{$role}{'access'} ne '') {
7650: $indomvis = ' style="display:none"';
7651: $incrsvis = ' style="display:block"';
1.430 raeburn 7652: $incrscheck = ' checked="checked"';
1.428 raeburn 7653: if ($settings{$role}{'access'} ne 'all') {
7654: $usecheck{$settings{$role}{'access'}} = $usecheck{'all'};
7655: delete($usecheck{'all'});
7656: if ($settings{$role}{'access'} eq 'status') {
7657: my $access = 'status';
7658: $displaydiv{$access} = 'inline';
7659: if (ref($settings{$role}{$access}) eq 'ARRAY') {
7660: $selected{$access} = $settings{$role}{$access};
7661: }
7662: } elsif ($settings{$role}{'access'} =~ /^(inc|exc)$/) {
7663: my $access = $1;
7664: $displaydiv{$access} = 'inline';
7665: if (ref($settings{$role}{$access}) eq 'ARRAY') {
7666: $selected{$access} = $settings{$role}{$access};
7667: }
7668: } elsif ($settings{$role}{'access'} eq 'none') {
7669: $displaydiv{'priv'} = 'none';
7670: }
7671: }
7672: } else {
7673: $indomcheck = ' checked="checked"';
7674: $indomvis = ' style="display:block"';
7675: $incrsvis = ' style="display:none"';
7676: }
7677: } else {
7678: $indomcheck = ' checked="checked"';
1.430 raeburn 7679: $indomvis = ' style="display:block"';
1.428 raeburn 7680: $incrsvis = ' style="display:none"';
7681: }
7682: $r->print('<div class="LC_left_float" id="'.$role.'_maindiv"'.$visibility{$role}.'>'.
7683: '<fieldset><legend>'.$lt{'rou'}.'</legend>'.
7684: '<p>'.$lt{'whi'}.' <span class="LC_nobreak">'.
7685: '<label><input type="radio" name="'.$role.'_incrs" value="1"'.$incrscheck.' onclick="toggleAccess('."'$role'".');"'.$disabled.'>'.
7686: &mt('Set here in [_1]',lc($crstype)).'</label>'.
7687: '<span>'.(' 'x2).
7688: '<label><input type="radio" name="'.$role.'_incrs" value="0"'.$indomcheck.' onclick="toggleAccess('."'$role'".');"'.$disabled.'>'.
7689: $lt{'udd'}.'</label><span></p>'.
7690: '<div id="'.$role.'_setindom"'.$indomvis.'>'.
7691: '<span class="LC_cusr_emph">'.$domusage{$role}.'</span></div>'.
7692: '<div id="'.$role.'_setincrs"'.$incrsvis.'>');
7693: foreach my $access (@accesstypes) {
7694: $r->print('<p><label><input type="radio" name="'.$role.'_access" value="'.$access.'" '.$usecheck{$access}.
7695: ' onclick="helpdeskAccess('."'$role'".');"'.$disabled.' />'.$lt{$access}.'</label>');
7696: if ($access eq 'status') {
7697: $r->print('<div id="'.$role.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
7698: &Apache::lonuserutils::adhoc_status_types($cdom,undef,$role,$selected{$access},
7699: $othertitle,$usertypes,$types,$disabled).
7700: '</div>');
7701: } elsif (($access eq 'inc') && (keys(%domhelpdesk) > 0)) {
7702: $r->print('<div id="'.$role.'_notinc" style="display:'.$displaydiv{$access}.'">'.
7703: &Apache::lonuserutils::adhoc_staff($access,undef,$role,$selected{$access},
7704: \%domhelpdesk,$disabled).
7705: '</div>');
7706: } elsif (($access eq 'exc') && (keys(%domhelpdesk) > 0)) {
7707: $r->print('<div id="'.$role.'_notexc" style="display:'.$displaydiv{$access}.'">'.
7708: &Apache::lonuserutils::adhoc_staff($access,undef,$role,$selected{$access},
7709: \%domhelpdesk,$disabled).
7710: '</div>');
7711: }
7712: $r->print('</p>');
7713: }
7714: $r->print('</div></fieldset>');
7715: my %full=();
7716: my %levels= (
7717: course => {},
7718: domain => {},
7719: system => {},
7720: );
7721: my %levelscurrent=(
7722: course => {},
7723: domain => {},
7724: system => {},
7725: );
7726: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
7727: $r->print('<fieldset id="'.$role.'_privs" style="display:'.$displaydiv{'priv'}.'">'.
7728: '<legend>'.$lt{'rpr'}.'</legend>'.
7729: &role_priv_table($role,$permission,$crstype,\%full,\%levels,\%levelscurrent,$overridden{$role}).
7730: '</fieldset></div><div style="padding:0;clear:both;margin:0;border:0"></div>');
7731: }
1.429 raeburn 7732: if ($permission->{'owner'}) {
7733: $r->print('<p><input type="submit" value="'.&mt('Save changes').'" /></p>');
7734: }
1.428 raeburn 7735: } else {
7736: $r->print(&mt('Helpdesk roles have not yet been created in this domain.'));
7737: }
7738: # Form Footer
7739: $r->print('<input type="hidden" name="action" value="helpdesk" />'
7740: .'</form>');
7741: return;
7742: }
7743:
7744: sub domain_adhoc_access {
7745: my ($roles,$domcurrent,$accesstypes,$usertypes,$othertitle) = @_;
7746: my %domusage;
7747: return unless ((ref($roles) eq 'HASH') && (ref($domcurrent) eq 'HASH') && (ref($accesstypes) eq 'ARRAY'));
7748: foreach my $role (keys(%{$roles})) {
7749: if (ref($domcurrent->{$role}) eq 'HASH') {
7750: my $access = $domcurrent->{$role}{'access'};
7751: if (($access eq '') || (!grep(/^\Q$access\E$/,@{$accesstypes}))) {
7752: $access = 'all';
1.432 raeburn 7753: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role',&Apache::lonnet::plaintext('dh'),
7754: &Apache::lonnet::plaintext('da'));
1.428 raeburn 7755: } elsif ($access eq 'status') {
7756: if (ref($domcurrent->{$role}{$access}) eq 'ARRAY') {
7757: my @shown;
7758: foreach my $type (@{$domcurrent->{$role}{$access}}) {
7759: unless ($type eq 'default') {
7760: if ($usertypes->{$type}) {
7761: push(@shown,$usertypes->{$type});
7762: }
7763: }
7764: }
7765: if (grep(/^default$/,@{$domcurrent->{$role}{$access}})) {
7766: push(@shown,$othertitle);
7767: }
7768: if (@shown) {
7769: my $shownstatus = join(' '.&mt('or').' ',@shown);
1.432 raeburn 7770: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role, and institutional status: [_3]',
7771: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'),$shownstatus);
1.428 raeburn 7772: } else {
7773: $domusage{$role} = &mt('No one in the domain');
7774: }
7775: }
7776: } elsif ($access eq 'inc') {
7777: my @dominc = ();
7778: if (ref($domcurrent->{$role}{'inc'}) eq 'ARRAY') {
7779: foreach my $user (@{$domcurrent->{$role}{'inc'}}) {
7780: my ($uname,$udom) = split(/:/,$user);
7781: push(@dominc,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),$uname,$udom));
7782: }
7783: my $showninc = join(', ',@dominc);
7784: if ($showninc ne '') {
1.432 raeburn 7785: $domusage{$role} = &mt('Include any user in domain with active [_1] or [_2] role, except: [_3]',
7786: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'),$showninc);
1.428 raeburn 7787: } else {
1.432 raeburn 7788: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role',
7789: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'));
1.428 raeburn 7790: }
7791: }
7792: } elsif ($access eq 'exc') {
7793: my @domexc = ();
7794: if (ref($domcurrent->{$role}{'exc'}) eq 'ARRAY') {
7795: foreach my $user (@{$domcurrent->{$role}{'exc'}}) {
7796: my ($uname,$udom) = split(/:/,$user);
7797: push(@domexc,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),$uname,$udom));
7798: }
7799: }
7800: my $shownexc = join(', ',@domexc);
7801: if ($shownexc ne '') {
1.432 raeburn 7802: $domusage{$role} = &mt('Only the following in the domain with active [_1] or [_2] role: [_3]',
7803: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'),$shownexc);
1.428 raeburn 7804: } else {
7805: $domusage{$role} = &mt('No one in the domain');
7806: }
7807: } elsif ($access eq 'none') {
7808: $domusage{$role} = &mt('No one in the domain');
1.434 raeburn 7809: } elsif ($access eq 'dh') {
1.433 raeburn 7810: $domusage{$role} = &mt('Any user in domain with active [_1] role',&Apache::lonnet::plaintext('dh'));
1.434 raeburn 7811: } elsif ($access eq 'da') {
1.433 raeburn 7812: $domusage{$role} = &mt('Any user in domain with active [_1] role',&Apache::lonnet::plaintext('da'));
1.428 raeburn 7813: } elsif ($access eq 'all') {
1.432 raeburn 7814: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role',
7815: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'));
1.428 raeburn 7816: }
7817: } else {
1.432 raeburn 7818: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role',
7819: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'));
1.428 raeburn 7820: }
7821: }
7822: return %domusage;
7823: }
7824:
7825: sub get_domain_customroles {
7826: my ($cdom,$confname) = @_;
7827: my %existing=&Apache::lonnet::dump('roles',$cdom,$confname,'rolesdef_');
7828: my %customroles;
7829: foreach my $key (keys(%existing)) {
7830: if ($key=~/^rolesdef\_(\w+)$/) {
7831: my $rolename = $1;
7832: my %privs;
7833: ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
7834: $customroles{$rolename} = \%privs;
7835: }
7836: }
7837: return %customroles;
7838: }
7839:
7840: sub role_priv_table {
7841: my ($role,$permission,$crstype,$full,$levels,$levelscurrent,$overridden) = @_;
7842: return unless ((ref($full) eq 'HASH') && (ref($levels) eq 'HASH') &&
7843: (ref($levelscurrent) eq 'HASH'));
7844: my %lt=&Apache::lonlocal::texthash (
7845: 'crl' => 'Course Level Privilege',
7846: 'def' => 'Domain Defaults',
7847: 'ove' => 'Override in Course',
7848: 'ine' => 'In effect',
7849: 'dis' => 'Disabled',
7850: 'ena' => 'Enabled',
7851: );
7852: if ($crstype eq 'Community') {
7853: $lt{'ove'} = 'Override in Community',
7854: }
7855: my @status = ('Disabled','Enabled');
7856: my (%on,%off);
7857: if (ref($overridden) eq 'HASH') {
7858: if (ref($overridden->{'on'}) eq 'ARRAY') {
7859: map { $on{$_} = 1; } (@{$overridden->{'on'}});
7860: }
7861: if (ref($overridden->{'off'}) eq 'ARRAY') {
7862: map { $off{$_} = 1; } (@{$overridden->{'off'}});
7863: }
7864: }
7865: my $output=&Apache::loncommon::start_data_table().
7866: &Apache::loncommon::start_data_table_header_row().
7867: '<th>'.$lt{'crl'}.'</th><th>'.$lt{'def'}.'</th><th>'.$lt{'ove'}.
7868: '</th><th>'.$lt{'ine'}.'</th>'.
7869: &Apache::loncommon::end_data_table_header_row();
7870: foreach my $priv (sort(keys(%{$full}))) {
7871: next unless ($levels->{'course'}{$priv});
7872: my $privtext = &Apache::lonnet::plaintext($priv,$crstype);
7873: my ($default,$ineffect);
7874: if ($levelscurrent->{'course'}{$priv}) {
7875: $default = '<img src="/adm/lonIcons/navmap.correct.gif" alt="'.$lt{'ena'}.'" />';
7876: $ineffect = $default;
7877: }
7878: my ($customstatus,$checked);
7879: $output .= &Apache::loncommon::start_data_table_row().
7880: '<td>'.$privtext.'</td>'.
7881: '<td>'.$default.'</td><td>';
7882: if (($levelscurrent->{'course'}{$priv}) && ($off{$priv})) {
7883: if ($permission->{'owner'}) {
7884: $checked = ' checked="checked"';
7885: }
7886: $customstatus = '<img src="/adm/lonIcons/navmap.wrong.gif" alt="'.$lt{'dis'}.'" />';
1.430 raeburn 7887: $ineffect = $customstatus;
1.428 raeburn 7888: } elsif ((!$levelscurrent->{'course'}{$priv}) && ($on{$priv})) {
7889: if ($permission->{'owner'}) {
1.430 raeburn 7890: $checked = ' checked="checked"';
1.428 raeburn 7891: }
7892: $customstatus = '<img src="/adm/lonIcons/navmap.correct.gif" alt="'.$lt{'ena'}.'" />';
1.430 raeburn 7893: $ineffect = $customstatus;
1.428 raeburn 7894: }
7895: if ($permission->{'owner'}) {
7896: $output .= '<input type="checkbox" name="'.$role.'_override" value="'.$priv.'"'.$checked.' />';
7897: } else {
7898: $output .= $customstatus;
7899: }
7900: $output .= '</td><td>'.$ineffect.'</td>'.
7901: &Apache::loncommon::end_data_table_row();
7902: }
7903: $output .= &Apache::loncommon::end_data_table();
7904: return $output;
7905: }
7906:
7907: sub get_adhocrole_settings {
1.430 raeburn 7908: my ($cid,$accesstypes,$types,$customroles,$settings,$overridden) = @_;
1.428 raeburn 7909: return unless ((ref($accesstypes) eq 'ARRAY') && (ref($customroles) eq 'HASH') &&
7910: (ref($settings) eq 'HASH') && (ref($overridden) eq 'HASH'));
7911: foreach my $role (split(/,/,$env{'course.'.$cid.'.internal.adhocaccess'})) {
7912: my ($curraccess,$rest) = split(/=/,$env{'course.'.$cid.'.internal.adhoc.'.$role});
7913: if (($curraccess ne '') && (grep(/^\Q$curraccess\E$/,@{$accesstypes}))) {
7914: $settings->{$role}{'access'} = $curraccess;
7915: if (($curraccess eq 'status') && (ref($types) eq 'ARRAY')) {
7916: my @status = split(/,/,$rest);
7917: my @currstatus;
7918: foreach my $type (@status) {
7919: if ($type eq 'default') {
7920: push(@currstatus,$type);
7921: } elsif (grep(/^\Q$type\E$/,@{$types})) {
7922: push(@currstatus,$type);
7923: }
7924: }
7925: if (@currstatus) {
7926: $settings->{$role}{$curraccess} = \@currstatus;
7927: } elsif (($curraccess eq 'exc') || ($curraccess eq 'inc')) {
7928: my @personnel = split(/,/,$rest);
7929: $settings->{$role}{$curraccess} = \@personnel;
7930: }
7931: }
7932: }
7933: }
7934: foreach my $role (keys(%{$customroles})) {
7935: if ($env{'course.'.$cid.'.internal.adhocpriv.'.$role}) {
7936: my %currentprivs;
7937: if (ref($customroles->{$role}) eq 'HASH') {
7938: if (exists($customroles->{$role}{'course'})) {
7939: my %full=();
7940: my %levels= (
7941: course => {},
7942: domain => {},
7943: system => {},
7944: );
7945: my %levelscurrent=(
7946: course => {},
7947: domain => {},
7948: system => {},
7949: );
7950: &Apache::lonuserutils::custom_role_privs($customroles->{$role},\%full,\%levels,\%levelscurrent);
7951: %currentprivs = %{$levelscurrent{'course'}};
7952: }
7953: }
7954: foreach my $item (split(/,/,$env{'course.'.$cid.'.internal.adhocpriv.'.$role})) {
7955: next if ($item eq '');
7956: my ($rule,$rest) = split(/=/,$item);
7957: next unless (($rule eq 'off') || ($rule eq 'on'));
7958: foreach my $priv (split(/:/,$rest)) {
7959: if ($priv ne '') {
7960: if ($rule eq 'off') {
7961: push(@{$overridden->{$role}{'off'}},$priv);
7962: if ($currentprivs{$priv}) {
7963: push(@{$settings->{$role}{'off'}},$priv);
7964: }
7965: } else {
7966: push(@{$overridden->{$role}{'on'}},$priv);
7967: unless ($currentprivs{$priv}) {
7968: push(@{$settings->{$role}{'on'}},$priv);
7969: }
7970: }
7971: }
7972: }
7973: }
7974: }
7975: }
7976: return;
7977: }
7978:
7979: sub update_helpdeskaccess {
7980: my ($r,$permission,$brcrum) = @_;
7981: my $helpitem = 'Course_Helpdesk_Access';
7982: push (@{$brcrum},
7983: {href => '/adm/createuser?action=helpdesk',
7984: text => 'Helpdesk Access',
7985: help => $helpitem},
7986: {href => '/adm/createuser?action=helpdesk',
7987: text => 'Result',
7988: help => $helpitem}
7989: );
7990: my $bread_crumbs_component = 'Helpdesk Staff Access';
7991: my $args = { bread_crumbs => $brcrum,
7992: bread_crumbs_component => $bread_crumbs_component};
7993:
7994: # print page header
7995: $r->print(&header('',$args));
7996: unless ((ref($permission) eq 'HASH') && ($permission->{'owner'})) {
7997: $r->print('<p class="LC_error">'.&mt('You do not have permission to change helpdesk access.').'</p>');
7998: return;
7999: }
1.434 raeburn 8000: my @accesstypes = ('all','dh','da','none','status','inc','exc');
1.428 raeburn 8001: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
8002: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
8003: my $confname = $cdom.'-domainconfig';
8004: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($cdom);
8005: my $crstype = &Apache::loncommon::course_type();
8006: my %customroles = &get_domain_customroles($cdom,$confname);
8007: my (%settings,%overridden);
8008: &get_adhocrole_settings($env{'request.course.id'},\@accesstypes,
8009: $types,\%customroles,\%settings,\%overridden);
1.432 raeburn 8010: my %domhelpdesk = &Apache::lonnet::get_active_domroles($cdom,['dh','da']);
1.428 raeburn 8011: my (%changed,%storehash,@todelete);
8012:
8013: if (keys(%customroles)) {
8014: my (%newsettings,@incrs);
8015: foreach my $role (keys(%customroles)) {
8016: $newsettings{$role} = {
8017: access => '',
8018: status => '',
8019: exc => '',
8020: inc => '',
8021: on => '',
8022: off => '',
8023: };
8024: my %current;
8025: if (ref($settings{$role}) eq 'HASH') {
8026: %current = %{$settings{$role}};
8027: }
8028: if (ref($overridden{$role}) eq 'HASH') {
8029: $current{'overridden'} = $overridden{$role};
8030: }
8031: if ($env{'form.'.$role.'_incrs'}) {
8032: my $access = $env{'form.'.$role.'_access'};
8033: if (grep(/^\Q$access\E$/,@accesstypes)) {
8034: push(@incrs,$role);
8035: unless ($current{'access'} eq $access) {
8036: $changed{$role}{'access'} = 1;
1.430 raeburn 8037: $storehash{'internal.adhoc.'.$role} = $access;
1.428 raeburn 8038: }
8039: if ($access eq 'status') {
8040: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$role.'_status');
8041: my @stored;
8042: my @shownstatus;
8043: if (ref($types) eq 'ARRAY') {
8044: foreach my $type (sort(@statuses)) {
8045: if ($type eq 'default') {
8046: push(@stored,$type);
8047: } elsif (grep(/^\Q$type\E$/,@{$types})) {
8048: push(@stored,$type);
8049: push(@shownstatus,$usertypes->{$type});
8050: }
8051: }
8052: if (grep(/^default$/,@statuses)) {
8053: push(@shownstatus,$othertitle);
8054: }
8055: $storehash{'internal.adhoc.'.$role} .= '='.join(',',@stored);
8056: }
8057: $newsettings{$role}{'status'} = join(' '.&mt('or').' ',@shownstatus);
8058: if (ref($current{'status'}) eq 'ARRAY') {
8059: my @diffs = &Apache::loncommon::compare_arrays(\@stored,$current{'status'});
8060: if (@diffs) {
8061: $changed{$role}{'status'} = 1;
8062: }
8063: } elsif (@stored) {
8064: $changed{$role}{'status'} = 1;
8065: }
8066: } elsif (($access eq 'inc') || ($access eq 'exc')) {
8067: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$role.'_staff_'.$access);
8068: my @newspecstaff;
8069: my @stored;
8070: my @currstaff;
8071: foreach my $person (sort(@personnel)) {
8072: if ($domhelpdesk{$person}) {
1.430 raeburn 8073: push(@stored,$person);
1.428 raeburn 8074: }
8075: }
8076: if (ref($current{$access}) eq 'ARRAY') {
8077: my @diffs = &Apache::loncommon::compare_arrays(\@stored,$current{$access});
8078: if (@diffs) {
8079: $changed{$role}{$access} = 1;
8080: }
8081: } elsif (@stored) {
8082: $changed{$role}{$access} = 1;
8083: }
8084: $storehash{'internal.adhoc.'.$role} .= '='.join(',',@stored);
8085: foreach my $person (@stored) {
8086: my ($uname,$udom) = split(/:/,$person);
8087: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
8088: }
8089: $newsettings{$role}{$access} = join(', ',sort(@newspecstaff));
8090: }
8091: $newsettings{$role}{'access'} = $access;
8092: }
8093: } else {
8094: if (($current{'access'} ne '') && (grep(/^\Q$current{'access'}\E$/,@accesstypes))) {
8095: $changed{$role}{'access'} = 1;
8096: $newsettings{$role} = {};
8097: push(@todelete,'internal.adhoc.'.$role);
8098: }
8099: }
8100: if (($env{'form.'.$role.'_incrs'}) && ($env{'form.'.$role.'_access'} eq 'none')) {
8101: if (ref($current{'overridden'}) eq 'HASH') {
8102: push(@todelete,'internal.adhocpriv.'.$role);
8103: }
8104: } else {
8105: my %full=();
8106: my %levels= (
8107: course => {},
8108: domain => {},
8109: system => {},
8110: );
8111: my %levelscurrent=(
8112: course => {},
8113: domain => {},
8114: system => {},
8115: );
8116: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
8117: my (@updatedon,@updatedoff,@override);
8118: @override = &Apache::loncommon::get_env_multiple('form.'.$role.'_override');
1.430 raeburn 8119: if (@override) {
1.428 raeburn 8120: foreach my $priv (sort(keys(%full))) {
8121: next unless ($levels{'course'}{$priv});
8122: if (grep(/^\Q$priv\E$/,@override)) {
8123: if ($levelscurrent{'course'}{$priv}) {
8124: push(@updatedoff,$priv);
8125: } else {
8126: push(@updatedon,$priv);
8127: }
8128: }
8129: }
8130: }
8131: if (@updatedon) {
1.430 raeburn 8132: $newsettings{$role}{'on'} = join('</li><li>', map { &Apache::lonnet::plaintext($_,$crstype) } (@updatedon));
1.428 raeburn 8133: }
8134: if (@updatedoff) {
8135: $newsettings{$role}{'off'} = join('</li><li>', map { &Apache::lonnet::plaintext($_,$crstype) } (@updatedoff));
8136: }
8137: if (ref($current{'overridden'}) eq 'HASH') {
8138: if (ref($current{'overridden'}{'on'}) eq 'ARRAY') {
8139: if (@updatedon) {
8140: my @diffs = &Apache::loncommon::compare_arrays(\@updatedon,$current{'overridden'}{'on'});
8141: if (@diffs) {
8142: $changed{$role}{'on'} = 1;
8143: }
8144: } else {
8145: $changed{$role}{'on'} = 1;
8146: }
8147: } elsif (@updatedon) {
8148: $changed{$role}{'on'} = 1;
8149: }
8150: if (ref($current{'overridden'}{'off'}) eq 'ARRAY') {
8151: if (@updatedoff) {
8152: my @diffs = &Apache::loncommon::compare_arrays(\@updatedoff,$current{'overridden'}{'off'});
8153: if (@diffs) {
8154: $changed{$role}{'off'} = 1;
8155: }
8156: } else {
8157: $changed{$role}{'off'} = 1;
8158: }
8159: } elsif (@updatedoff) {
8160: $changed{$role}{'off'} = 1;
8161: }
8162: } else {
8163: if (@updatedon) {
8164: $changed{$role}{'on'} = 1;
8165: }
8166: if (@updatedoff) {
8167: $changed{$role}{'off'} = 1;
8168: }
8169: }
8170: if (ref($changed{$role}) eq 'HASH') {
8171: if (($changed{$role}{'on'} || $changed{$role}{'off'})) {
8172: my $newpriv;
8173: if (@updatedon) {
8174: $newpriv = 'on='.join(':',@updatedon);
8175: }
8176: if (@updatedoff) {
8177: $newpriv .= ($newpriv ? ',' : '' ).'off='.join(':',@updatedoff);
8178: }
8179: if ($newpriv eq '') {
8180: push(@todelete,'internal.adhocpriv.'.$role);
8181: } else {
8182: $storehash{'internal.adhocpriv.'.$role} = $newpriv;
8183: }
8184: }
8185: }
8186: }
8187: }
8188: if (@incrs) {
8189: $storehash{'internal.adhocaccess'} = join(',',@incrs);
8190: } elsif (@todelete) {
8191: push(@todelete,'internal.adhocaccess');
8192: }
8193: if (keys(%changed)) {
8194: my ($putres,$delres);
8195: if (keys(%storehash)) {
8196: $putres = &Apache::lonnet::put('environment',\%storehash,$cdom,$cnum);
8197: my %newenvhash;
8198: foreach my $key (keys(%storehash)) {
8199: $newenvhash{'course.'.$env{'request.course.id'}.'.'.$key} = $storehash{$key};
8200: }
8201: &Apache::lonnet::appenv(\%newenvhash);
8202: }
8203: if (@todelete) {
8204: $delres = &Apache::lonnet::del('environment',\@todelete,$cdom,$cnum);
8205: foreach my $key (@todelete) {
8206: &Apache::lonnet::delenv('course.'.$env{'request.course.id'}.'.'.$key);
8207: }
8208: }
8209: if (($putres eq 'ok') || ($delres eq 'ok')) {
8210: my %domconfig = &Apache::lonnet::get_dom('configuration',['helpsettings'],$cdom);
8211: my (%domcurrent,%ordered,%description,%domusage);
8212: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
8213: if (ref($domconfig{'helpsettings'}{'adhoc'}) eq 'HASH') {
8214: %domcurrent = %{$domconfig{'helpsettings'}{'adhoc'}};
8215: }
8216: }
8217: my $count = 0;
8218: foreach my $role (sort(keys(%customroles))) {
8219: my ($order,$desc);
8220: if (ref($domcurrent{$role}) eq 'HASH') {
8221: $order = $domcurrent{$role}{'order'};
8222: $desc = $domcurrent{$role}{'desc'};
8223: }
8224: if ($order eq '') {
8225: $order = $count;
8226: }
8227: $ordered{$order} = $role;
8228: if ($desc ne '') {
8229: $description{$role} = $desc;
8230: } else {
8231: $description{$role}= $role;
8232: }
8233: $count++;
8234: }
8235: my @roles_by_num = ();
8236: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
8237: push(@roles_by_num,$ordered{$item});
8238: }
8239: %domusage = &domain_adhoc_access(\%changed,\%domcurrent,\@accesstypes,$usertypes,$othertitle);
1.430 raeburn 8240: $r->print(&mt('Helpdesk access settings have been changed as follows').'<br />');
1.428 raeburn 8241: $r->print('<ul>');
8242: foreach my $role (@roles_by_num) {
8243: next unless (ref($changed{$role}) eq 'HASH');
8244: $r->print('<li>'.&mt('Ad hoc role').': <b>'.$description{$role}.'</b>'.
8245: '<ul>');
1.430 raeburn 8246: if ($changed{$role}{'access'} || $changed{$role}{'status'} || $changed{$role}{'inc'} || $changed{$role}{'exc'}) {
1.428 raeburn 8247: $r->print('<li>');
8248: if ($env{'form.'.$role.'_incrs'}) {
8249: if ($newsettings{$role}{'access'} eq 'all') {
8250: $r->print(&mt('All helpdesk staff can access '.lc($crstype).' with this role.'));
1.434 raeburn 8251: } elsif ($newsettings{$role}{'access'} eq 'dh') {
1.433 raeburn 8252: $r->print(&mt('Helpdesk staff can use this role if they have an active [_1] role',
8253: &Apache::lonnet::plaintext('dh')));
1.434 raeburn 8254: } elsif ($newsettings{$role}{'access'} eq 'da') {
1.433 raeburn 8255: $r->print(&mt('Helpdesk staff can use this role if they have an active [_1] role',
8256: &Apache::lonnet::plaintext('da')));
1.428 raeburn 8257: } elsif ($newsettings{$role}{'access'} eq 'none') {
8258: $r->print(&mt('No helpdesk staff can access '.lc($crstype).' with this role.'));
8259: } elsif ($newsettings{$role}{'access'} eq 'status') {
8260: if ($newsettings{$role}{'status'}) {
8261: my ($access,$rest) = split(/=/,$storehash{'internal.adhoc.'.$role});
1.430 raeburn 8262: if (split(/,/,$rest) > 1) {
1.428 raeburn 8263: $r->print(&mt('Helpdesk staff can use this role if their institutional type is one of: [_1].',
8264: $newsettings{$role}{'status'}));
8265: } else {
8266: $r->print(&mt('Helpdesk staff can use this role if their institutional type is: [_1].',
8267: $newsettings{$role}{'status'}));
8268: }
8269: } else {
8270: $r->print(&mt('No helpdesk staff can access '.lc($crstype).' with this role.'));
8271: }
8272: } elsif ($newsettings{$role}{'access'} eq 'exc') {
8273: if ($newsettings{$role}{'exc'}) {
8274: $r->print(&mt('Helpdesk staff who can use this role are as follows:').' '.$newsettings{$role}{'exc'}.'.');
8275: } else {
8276: $r->print(&mt('No helpdesk staff can access '.lc($crstype).' with this role.'));
8277: }
8278: } elsif ($newsettings{$role}{'access'} eq 'inc') {
8279: if ($newsettings{$role}{'inc'}) {
8280: $r->print(&mt('All helpdesk staff may use this role except the following:').' '.$newsettings{$role}{'inc'}.'.');
8281: } else {
8282: $r->print(&mt('All helpdesk staff may use this role.'));
8283: }
8284: }
8285: } else {
8286: $r->print(&mt('Default access set in the domain now applies.').'<br />'.
8287: '<span class="LC_cusr_emph">'.$domusage{$role}.'</span>');
8288: }
8289: $r->print('</li>');
8290: }
8291: unless ($newsettings{$role}{'access'} eq 'none') {
8292: if ($changed{$role}{'off'}) {
8293: if ($newsettings{$role}{'off'}) {
8294: $r->print('<li>'.&mt('Privileges which are available by default for this ad hoc role, but are disabled for this specific '.lc($crstype).':').
8295: '<ul><li>'.$newsettings{$role}{'off'}.'</li></ul></li>');
8296: } else {
1.430 raeburn 8297: $r->print('<li>'.&mt('All privileges available by default for this ad hoc role are enabled.').'</li>');
1.428 raeburn 8298: }
8299: }
1.430 raeburn 8300: if ($changed{$role}{'on'}) {
1.428 raeburn 8301: if ($newsettings{$role}{'on'}) {
8302: $r->print('<li>'.&mt('Privileges which are not available by default for this ad hoc role, but are enabled for this specific '.lc($crstype).':').
8303: '<ul><li>'.$newsettings{$role}{'on'}.'</li></ul></li>');
8304: } else {
1.430 raeburn 8305: $r->print('<li>'.&mt('None of the privileges unavailable by default for this ad hoc role are enabled.').'</li>');
1.428 raeburn 8306: }
8307: }
8308: }
8309: $r->print('</ul></li>');
8310: }
8311: $r->print('</ul>');
8312: }
8313: } else {
1.430 raeburn 8314: $r->print(&mt('No changes made to helpdesk access settings.'));
1.428 raeburn 8315: }
8316: }
8317: return;
8318: }
8319:
1.27 matthew 8320: #-------------------------------------------------- functions for &phase_two
1.160 raeburn 8321: sub user_search_result {
1.221 raeburn 8322: my ($context,$srch) = @_;
1.160 raeburn 8323: my %allhomes;
8324: my %inst_matches;
8325: my %srch_results;
1.181 raeburn 8326: my ($response,$currstate,$forcenewuser,$dirsrchres);
1.183 raeburn 8327: $srch->{'srchterm'} =~ s/\s+/ /g;
1.176 raeburn 8328: if ($srch->{'srchby'} !~ /^(uname|lastname|lastfirst)$/) {
1.160 raeburn 8329: $response = &mt('Invalid search.');
8330: }
8331: if ($srch->{'srchin'} !~ /^(crs|dom|alc|instd)$/) {
8332: $response = &mt('Invalid search.');
8333: }
1.177 raeburn 8334: if ($srch->{'srchtype'} !~ /^(exact|contains|begins)$/) {
1.160 raeburn 8335: $response = &mt('Invalid search.');
8336: }
8337: if ($srch->{'srchterm'} eq '') {
8338: $response = &mt('You must enter a search term.');
8339: }
1.183 raeburn 8340: if ($srch->{'srchterm'} =~ /^\s+$/) {
8341: $response = &mt('Your search term must contain more than just spaces.');
8342: }
1.160 raeburn 8343: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'instd')) {
8344: if (($srch->{'srchdomain'} eq '') ||
1.163 albertel 8345: ! (&Apache::lonnet::domain($srch->{'srchdomain'}))) {
1.160 raeburn 8346: $response = &mt('You must specify a valid domain when searching in a domain or institutional directory.')
8347: }
8348: }
8349: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs') ||
8350: ($srch->{'srchin'} eq 'alc')) {
1.176 raeburn 8351: if ($srch->{'srchby'} eq 'uname') {
1.243 raeburn 8352: my $unamecheck = $srch->{'srchterm'};
8353: if ($srch->{'srchtype'} eq 'contains') {
8354: if ($unamecheck !~ /^\w/) {
8355: $unamecheck = 'a'.$unamecheck;
8356: }
8357: }
8358: if ($unamecheck !~ /^$match_username$/) {
1.176 raeburn 8359: $response = &mt('You must specify a valid username. Only the following are allowed: letters numbers - . @');
8360: }
1.160 raeburn 8361: }
8362: }
1.180 raeburn 8363: if ($response ne '') {
1.413 raeburn 8364: $response = '<span class="LC_warning">'.$response.'</span><br />';
1.180 raeburn 8365: }
1.160 raeburn 8366: if ($srch->{'srchin'} eq 'instd') {
1.412 raeburn 8367: my $instd_chk = &instdirectorysrch_check($srch);
1.160 raeburn 8368: if ($instd_chk ne 'ok') {
1.412 raeburn 8369: my $domd_chk = &domdirectorysrch_check($srch);
1.413 raeburn 8370: $response .= '<span class="LC_warning">'.$instd_chk.'</span><br />';
1.412 raeburn 8371: if ($domd_chk eq 'ok') {
1.435 raeburn 8372: $response .= &mt('You may want to search in the LON-CAPA domain instead of in the institutional directory.');
1.412 raeburn 8373: }
1.415 raeburn 8374: $response .= '<br />';
1.412 raeburn 8375: }
8376: } else {
1.417 raeburn 8377: unless (($context eq 'requestcrs') && ($srch->{'srchtype'} eq 'exact')) {
1.412 raeburn 8378: my $domd_chk = &domdirectorysrch_check($srch);
1.438 raeburn 8379: if (($domd_chk ne 'ok') && ($env{'form.action'} ne 'accesslogs')) {
1.412 raeburn 8380: my $instd_chk = &instdirectorysrch_check($srch);
1.413 raeburn 8381: $response .= '<span class="LC_warning">'.$domd_chk.'</span><br />';
1.412 raeburn 8382: if ($instd_chk eq 'ok') {
1.435 raeburn 8383: $response .= &mt('You may want to search in the institutional directory instead of in the LON-CAPA domain.');
1.412 raeburn 8384: }
1.415 raeburn 8385: $response .= '<br />';
1.412 raeburn 8386: }
1.160 raeburn 8387: }
8388: }
8389: if ($response ne '') {
1.180 raeburn 8390: return ($currstate,$response);
1.160 raeburn 8391: }
8392: if ($srch->{'srchby'} eq 'uname') {
8393: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs')) {
8394: if ($env{'form.forcenew'}) {
8395: if ($srch->{'srchdomain'} ne $env{'request.role.domain'}) {
8396: my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
8397: if ($uhome eq 'no_host') {
8398: my $domdesc = &Apache::lonnet::domain($env{'request.role.domain'},'description');
1.180 raeburn 8399: my $showdom = &display_domain_info($env{'request.role.domain'});
8400: $response = &mt('New users can only be created in the domain to which your current role belongs - [_1].',$showdom);
1.160 raeburn 8401: } else {
1.179 raeburn 8402: $currstate = 'modify';
1.160 raeburn 8403: }
8404: } else {
1.179 raeburn 8405: $currstate = 'modify';
1.160 raeburn 8406: }
8407: } else {
8408: if ($srch->{'srchin'} eq 'dom') {
1.162 raeburn 8409: if ($srch->{'srchtype'} eq 'exact') {
8410: my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
8411: if ($uhome eq 'no_host') {
1.179 raeburn 8412: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8413: &build_search_response($context,$srch,%srch_results);
1.162 raeburn 8414: } else {
1.179 raeburn 8415: $currstate = 'modify';
1.416 raeburn 8416: if ($env{'form.action'} eq 'accesslogs') {
8417: $currstate = 'activity';
8418: }
1.310 raeburn 8419: my $uname = $srch->{'srchterm'};
8420: my $udom = $srch->{'srchdomain'};
8421: $srch_results{$uname.':'.$udom} =
8422: { &Apache::lonnet::get('environment',
8423: ['firstname',
8424: 'lastname',
8425: 'permanentemail'],
8426: $udom,$uname)
8427: };
1.162 raeburn 8428: }
8429: } else {
8430: %srch_results = &Apache::lonnet::usersearch($srch);
1.179 raeburn 8431: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8432: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 8433: }
8434: } else {
1.167 albertel 8435: my $courseusers = &get_courseusers();
1.162 raeburn 8436: if ($srch->{'srchtype'} eq 'exact') {
1.167 albertel 8437: if (exists($courseusers->{$srch->{'srchterm'}.':'.$srch->{'srchdomain'}})) {
1.179 raeburn 8438: $currstate = 'modify';
1.162 raeburn 8439: } else {
1.179 raeburn 8440: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8441: &build_search_response($context,$srch,%srch_results);
1.162 raeburn 8442: }
1.160 raeburn 8443: } else {
1.167 albertel 8444: foreach my $user (keys(%$courseusers)) {
1.162 raeburn 8445: my ($cuname,$cudomain) = split(/:/,$user);
8446: if ($cudomain eq $srch->{'srchdomain'}) {
1.177 raeburn 8447: my $matched = 0;
8448: if ($srch->{'srchtype'} eq 'begins') {
8449: if ($cuname =~ /^\Q$srch->{'srchterm'}\E/i) {
8450: $matched = 1;
8451: }
8452: } else {
8453: if ($cuname =~ /\Q$srch->{'srchterm'}\E/i) {
8454: $matched = 1;
8455: }
8456: }
8457: if ($matched) {
1.167 albertel 8458: $srch_results{$user} =
8459: {&Apache::lonnet::get('environment',
8460: ['firstname',
8461: 'lastname',
1.194 albertel 8462: 'permanentemail'],
8463: $cudomain,$cuname)};
1.162 raeburn 8464: }
8465: }
8466: }
1.179 raeburn 8467: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8468: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 8469: }
8470: }
8471: }
8472: } elsif ($srch->{'srchin'} eq 'alc') {
1.179 raeburn 8473: $currstate = 'query';
1.160 raeburn 8474: } elsif ($srch->{'srchin'} eq 'instd') {
1.181 raeburn 8475: ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
8476: if ($dirsrchres eq 'ok') {
8477: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8478: &build_search_response($context,$srch,%srch_results);
1.181 raeburn 8479: } else {
8480: my $showdom = &display_domain_info($srch->{'srchdomain'});
8481: $response = '<span class="LC_warning">'.
8482: &mt('Institutional directory search is not available in domain: [_1]',$showdom).
8483: '</span><br />'.
1.435 raeburn 8484: &mt('You may want to search in the LON-CAPA domain instead of in the institutional directory.').
1.415 raeburn 8485: '<br />';
1.181 raeburn 8486: }
1.160 raeburn 8487: }
8488: } else {
8489: if ($srch->{'srchin'} eq 'dom') {
8490: %srch_results = &Apache::lonnet::usersearch($srch);
1.179 raeburn 8491: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8492: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 8493: } elsif ($srch->{'srchin'} eq 'crs') {
1.167 albertel 8494: my $courseusers = &get_courseusers();
8495: foreach my $user (keys(%$courseusers)) {
1.160 raeburn 8496: my ($uname,$udom) = split(/:/,$user);
8497: my %names = &Apache::loncommon::getnames($uname,$udom);
8498: my %emails = &Apache::loncommon::getemails($uname,$udom);
8499: if ($srch->{'srchby'} eq 'lastname') {
8500: if ((($srch->{'srchtype'} eq 'exact') &&
8501: ($names{'lastname'} eq $srch->{'srchterm'})) ||
1.177 raeburn 8502: (($srch->{'srchtype'} eq 'begins') &&
8503: ($names{'lastname'} =~ /^\Q$srch->{'srchterm'}\E/i)) ||
1.160 raeburn 8504: (($srch->{'srchtype'} eq 'contains') &&
8505: ($names{'lastname'} =~ /\Q$srch->{'srchterm'}\E/i))) {
8506: $srch_results{$user} = {firstname => $names{'firstname'},
8507: lastname => $names{'lastname'},
8508: permanentemail => $emails{'permanentemail'},
8509: };
8510: }
8511: } elsif ($srch->{'srchby'} eq 'lastfirst') {
8512: my ($srchlast,$srchfirst) = split(/,/,$srch->{'srchterm'});
1.177 raeburn 8513: $srchlast =~ s/\s+$//;
8514: $srchfirst =~ s/^\s+//;
1.160 raeburn 8515: if ($srch->{'srchtype'} eq 'exact') {
8516: if (($names{'lastname'} eq $srchlast) &&
8517: ($names{'firstname'} eq $srchfirst)) {
8518: $srch_results{$user} = {firstname => $names{'firstname'},
8519: lastname => $names{'lastname'},
8520: permanentemail => $emails{'permanentemail'},
8521:
8522: };
8523: }
1.177 raeburn 8524: } elsif ($srch->{'srchtype'} eq 'begins') {
8525: if (($names{'lastname'} =~ /^\Q$srchlast\E/i) &&
8526: ($names{'firstname'} =~ /^\Q$srchfirst\E/i)) {
8527: $srch_results{$user} = {firstname => $names{'firstname'},
8528: lastname => $names{'lastname'},
8529: permanentemail => $emails{'permanentemail'},
8530: };
8531: }
8532: } else {
1.160 raeburn 8533: if (($names{'lastname'} =~ /\Q$srchlast\E/i) &&
8534: ($names{'firstname'} =~ /\Q$srchfirst\E/i)) {
8535: $srch_results{$user} = {firstname => $names{'firstname'},
8536: lastname => $names{'lastname'},
8537: permanentemail => $emails{'permanentemail'},
8538: };
8539: }
8540: }
8541: }
8542: }
1.179 raeburn 8543: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8544: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 8545: } elsif ($srch->{'srchin'} eq 'alc') {
1.179 raeburn 8546: $currstate = 'query';
1.160 raeburn 8547: } elsif ($srch->{'srchin'} eq 'instd') {
1.181 raeburn 8548: ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
8549: if ($dirsrchres eq 'ok') {
8550: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8551: &build_search_response($context,$srch,%srch_results);
1.181 raeburn 8552: } else {
1.412 raeburn 8553: my $showdom = &display_domain_info($srch->{'srchdomain'});
8554: $response = '<span class="LC_warning">'.
1.181 raeburn 8555: &mt('Institutional directory search is not available in domain: [_1]',$showdom).
8556: '</span><br />'.
1.435 raeburn 8557: &mt('You may want to search in the LON-CAPA domain instead of in the institutional directory.').
1.415 raeburn 8558: '<br />';
1.181 raeburn 8559: }
1.160 raeburn 8560: }
8561: }
1.179 raeburn 8562: return ($currstate,$response,$forcenewuser,\%srch_results);
1.160 raeburn 8563: }
8564:
1.412 raeburn 8565: sub domdirectorysrch_check {
8566: my ($srch) = @_;
8567: my $response;
8568: my %dom_inst_srch = &Apache::lonnet::get_dom('configuration',
8569: ['directorysrch'],$srch->{'srchdomain'});
8570: my $showdom = &display_domain_info($srch->{'srchdomain'});
8571: if (ref($dom_inst_srch{'directorysrch'}) eq 'HASH') {
8572: if ($dom_inst_srch{'directorysrch'}{'lcavailable'} eq '0') {
8573: return &mt('LON-CAPA directory search is not available in domain: [_1]',$showdom);
8574: }
8575: if ($dom_inst_srch{'directorysrch'}{'lclocalonly'}) {
8576: if ($env{'request.role.domain'} ne $srch->{'srchdomain'}) {
8577: return &mt('LON-CAPA directory search in domain: [_1] is only allowed for users with a current role in the domain.',$showdom);
8578: }
8579: }
8580: }
8581: return 'ok';
8582: }
8583:
8584: sub instdirectorysrch_check {
1.160 raeburn 8585: my ($srch) = @_;
8586: my $can_search = 0;
8587: my $response;
8588: my %dom_inst_srch = &Apache::lonnet::get_dom('configuration',
8589: ['directorysrch'],$srch->{'srchdomain'});
1.180 raeburn 8590: my $showdom = &display_domain_info($srch->{'srchdomain'});
1.160 raeburn 8591: if (ref($dom_inst_srch{'directorysrch'}) eq 'HASH') {
8592: if (!$dom_inst_srch{'directorysrch'}{'available'}) {
1.180 raeburn 8593: return &mt('Institutional directory search is not available in domain: [_1]',$showdom);
1.160 raeburn 8594: }
8595: if ($dom_inst_srch{'directorysrch'}{'localonly'}) {
8596: if ($env{'request.role.domain'} ne $srch->{'srchdomain'}) {
1.180 raeburn 8597: return &mt('Institutional directory search in domain: [_1] is only allowed for users with a current role in the domain.',$showdom);
1.160 raeburn 8598: }
8599: my @usertypes = split(/:/,$env{'environment.inststatus'});
8600: if (!@usertypes) {
8601: push(@usertypes,'default');
8602: }
8603: if (ref($dom_inst_srch{'directorysrch'}{'cansearch'}) eq 'ARRAY') {
8604: foreach my $type (@usertypes) {
8605: if (grep(/^\Q$type\E$/,@{$dom_inst_srch{'directorysrch'}{'cansearch'}})) {
8606: $can_search = 1;
8607: last;
8608: }
8609: }
8610: }
8611: if (!$can_search) {
8612: my ($insttypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($srch->{'srchdomain'});
8613: my @longtypes;
8614: foreach my $item (@usertypes) {
1.229 raeburn 8615: if (defined($insttypes->{$item})) {
8616: push (@longtypes,$insttypes->{$item});
8617: } elsif ($item eq 'default') {
8618: push (@longtypes,&mt('other'));
8619: }
1.160 raeburn 8620: }
8621: my $insttype_str = join(', ',@longtypes);
1.180 raeburn 8622: return &mt('Institutional directory search in domain: [_1] is not available to your user type: ',$showdom).$insttype_str;
1.229 raeburn 8623: }
1.160 raeburn 8624: } else {
8625: $can_search = 1;
8626: }
8627: } else {
1.180 raeburn 8628: return &mt('Institutional directory search has not been configured for domain: [_1]',$showdom);
1.160 raeburn 8629: }
8630: my %longtext = &Apache::lonlocal::texthash (
1.167 albertel 8631: uname => 'username',
1.160 raeburn 8632: lastfirst => 'last name, first name',
1.167 albertel 8633: lastname => 'last name',
1.172 raeburn 8634: contains => 'contains',
1.178 raeburn 8635: exact => 'as exact match to',
8636: begins => 'begins with',
1.160 raeburn 8637: );
8638: if ($can_search) {
8639: if (ref($dom_inst_srch{'directorysrch'}{'searchby'}) eq 'ARRAY') {
8640: if (!grep(/^\Q$srch->{'srchby'}\E$/,@{$dom_inst_srch{'directorysrch'}{'searchby'}})) {
1.180 raeburn 8641: return &mt('Institutional directory search in domain: [_1] is not available for searching by "[_2]"',$showdom,$longtext{$srch->{'srchby'}});
1.160 raeburn 8642: }
8643: } else {
1.180 raeburn 8644: return &mt('Institutional directory search in domain: [_1] is not available.', $showdom);
1.160 raeburn 8645: }
8646: }
8647: if ($can_search) {
1.178 raeburn 8648: if (ref($dom_inst_srch{'directorysrch'}{'searchtypes'}) eq 'ARRAY') {
8649: if (grep(/^\Q$srch->{'srchtype'}\E/,@{$dom_inst_srch{'directorysrch'}{'searchtypes'}})) {
8650: return 'ok';
8651: } else {
1.180 raeburn 8652: return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
1.178 raeburn 8653: }
8654: } else {
8655: if ((($dom_inst_srch{'directorysrch'}{'searchtypes'} eq 'specify') &&
8656: ($srch->{'srchtype'} eq 'exact' || $srch->{'srchtype'} eq 'contains')) ||
8657: ($dom_inst_srch{'directorysrch'}{'searchtypes'} eq $srch->{'srchtype'})) {
8658: return 'ok';
8659: } else {
1.180 raeburn 8660: return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
1.178 raeburn 8661: }
1.160 raeburn 8662: }
8663: }
8664: }
8665:
8666: sub get_courseusers {
8667: my %advhash;
1.167 albertel 8668: my $classlist = &Apache::loncoursedata::get_classlist();
1.160 raeburn 8669: my %coursepersonnel=&Apache::lonnet::get_course_adv_roles();
8670: foreach my $role (sort(keys(%coursepersonnel))) {
8671: foreach my $user (split(/\,/,$coursepersonnel{$role})) {
1.167 albertel 8672: if (!exists($classlist->{$user})) {
8673: $classlist->{$user} = [];
8674: }
1.160 raeburn 8675: }
8676: }
1.167 albertel 8677: return $classlist;
1.160 raeburn 8678: }
8679:
8680: sub build_search_response {
1.221 raeburn 8681: my ($context,$srch,%srch_results) = @_;
1.179 raeburn 8682: my ($currstate,$response,$forcenewuser);
1.160 raeburn 8683: my %names = (
1.330 bisitz 8684: 'uname' => 'username',
8685: 'lastname' => 'last name',
1.160 raeburn 8686: 'lastfirst' => 'last name, first name',
1.330 bisitz 8687: 'crs' => 'this course',
8688: 'dom' => 'LON-CAPA domain',
8689: 'instd' => 'the institutional directory for domain',
1.160 raeburn 8690: );
8691:
8692: my %single = (
1.180 raeburn 8693: begins => 'A match',
1.160 raeburn 8694: contains => 'A match',
1.180 raeburn 8695: exact => 'An exact match',
1.160 raeburn 8696: );
8697: my %nomatch = (
1.180 raeburn 8698: begins => 'No match',
1.160 raeburn 8699: contains => 'No match',
1.180 raeburn 8700: exact => 'No exact match',
1.160 raeburn 8701: );
8702: if (keys(%srch_results) > 1) {
1.179 raeburn 8703: $currstate = 'select';
1.160 raeburn 8704: } else {
8705: if (keys(%srch_results) == 1) {
1.416 raeburn 8706: if ($env{'form.action'} eq 'accesslogs') {
8707: $currstate = 'activity';
8708: } else {
8709: $currstate = 'modify';
8710: }
1.180 raeburn 8711: $response = &mt("$single{$srch->{'srchtype'}} was found for the $names{$srch->{'srchby'}} ([_1]) in $names{$srch->{'srchin'}}.",$srch->{'srchterm'});
8712: if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
1.330 bisitz 8713: $response .= ': '.&display_domain_info($srch->{'srchdomain'});
1.180 raeburn 8714: }
1.330 bisitz 8715: } else { # Search has nothing found. Prepare message to user.
8716: $response = '<span class="LC_warning">';
1.180 raeburn 8717: if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
1.330 bisitz 8718: $response .= &mt("$nomatch{$srch->{'srchtype'}} found for the $names{$srch->{'srchby'}} [_1] in $names{$srch->{'srchin'}}: [_2]",
8719: '<b>'.$srch->{'srchterm'}.'</b>',
8720: &display_domain_info($srch->{'srchdomain'}));
8721: } else {
8722: $response .= &mt("$nomatch{$srch->{'srchtype'}} found for the $names{$srch->{'srchby'}} [_1] in $names{$srch->{'srchin'}}.",
8723: '<b>'.$srch->{'srchterm'}.'</b>');
1.180 raeburn 8724: }
8725: $response .= '</span>';
1.330 bisitz 8726:
1.160 raeburn 8727: if ($srch->{'srchin'} ne 'alc') {
8728: $forcenewuser = 1;
8729: my $cansrchinst = 0;
1.438 raeburn 8730: if (($srch->{'srchdomain'}) && ($env{'form.action'} ne 'accesslogs')) {
1.160 raeburn 8731: my %domconfig = &Apache::lonnet::get_dom('configuration',['directorysrch'],$srch->{'srchdomain'});
8732: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
8733: if ($domconfig{'directorysrch'}{'available'}) {
8734: $cansrchinst = 1;
8735: }
8736: }
8737: }
1.180 raeburn 8738: if ((($srch->{'srchby'} eq 'lastfirst') ||
8739: ($srch->{'srchby'} eq 'lastname')) &&
8740: ($srch->{'srchin'} eq 'dom')) {
8741: if ($cansrchinst) {
8742: $response .= '<br />'.&mt('You may want to broaden your search to a search of the institutional directory for the domain.');
1.160 raeburn 8743: }
8744: }
1.180 raeburn 8745: if ($srch->{'srchin'} eq 'crs') {
8746: $response .= '<br />'.&mt('You may want to broaden your search to the selected LON-CAPA domain.');
8747: }
8748: }
1.305 raeburn 8749: my $createdom = $env{'request.role.domain'};
8750: if ($context eq 'requestcrs') {
8751: if ($env{'form.coursedom'} ne '') {
8752: $createdom = $env{'form.coursedom'};
8753: }
8754: }
1.416 raeburn 8755: unless (($env{'form.action'} eq 'accesslogs') || (($srch->{'srchby'} eq 'uname') && ($srch->{'srchin'} eq 'dom') &&
8756: ($srch->{'srchtype'} eq 'exact') && ($srch->{'srchdomain'} eq $createdom))) {
1.221 raeburn 8757: my $cancreate =
1.305 raeburn 8758: &Apache::lonuserutils::can_create_user($createdom,$context);
8759: my $targetdom = '<span class="LC_cusr_emph">'.$createdom.'</span>';
1.221 raeburn 8760: if ($cancreate) {
1.305 raeburn 8761: my $showdom = &display_domain_info($createdom);
1.266 bisitz 8762: $response .= '<br /><br />'
8763: .'<b>'.&mt('To add a new user:').'</b>'
1.305 raeburn 8764: .'<br />';
8765: if ($context eq 'requestcrs') {
8766: $response .= &mt("(You can only define new users in the new course's domain - [_1])",$targetdom);
8767: } else {
8768: $response .= &mt("(You can only create new users in your current role's domain - [_1])",$targetdom);
8769: }
8770: $response .='<ul><li>'
1.266 bisitz 8771: .&mt("Set 'Domain/institution to search' to: [_1]",'<span class="LC_cusr_emph">'.$showdom.'</span>')
8772: .'</li><li>'
8773: .&mt("Set 'Search criteria' to: [_1]username is ..... in selected LON-CAPA domain[_2]",'<span class="LC_cusr_emph">','</span>')
8774: .'</li><li>'
8775: .&mt('Provide the proposed username')
8776: .'</li><li>'
8777: .&mt("Click 'Search'")
8778: .'</li></ul><br />';
1.221 raeburn 8779: } else {
1.422 raeburn 8780: unless (($context eq 'domain') && ($env{'form.action'} eq 'singleuser')) {
8781: my $helplink = ' href="javascript:helpMenu('."'display'".')"';
8782: $response .= '<br /><br />';
8783: if ($context eq 'requestcrs') {
8784: $response .= &mt("You are not authorized to define new users in the new course's domain - [_1].",$targetdom);
8785: } else {
8786: $response .= &mt("You are not authorized to create new users in your current role's domain - [_1].",$targetdom);
8787: }
8788: $response .= '<br />'
8789: .&mt('Please contact the [_1]helpdesk[_2] if you need to create a new user.'
8790: ,' <a'.$helplink.'>'
8791: ,'</a>')
8792: .'<br />';
1.305 raeburn 8793: }
1.221 raeburn 8794: }
1.160 raeburn 8795: }
8796: }
8797: }
1.179 raeburn 8798: return ($currstate,$response,$forcenewuser);
1.160 raeburn 8799: }
8800:
1.180 raeburn 8801: sub display_domain_info {
8802: my ($dom) = @_;
8803: my $output = $dom;
8804: if ($dom ne '') {
8805: my $domdesc = &Apache::lonnet::domain($dom,'description');
8806: if ($domdesc ne '') {
8807: $output .= ' <span class="LC_cusr_emph">('.$domdesc.')</span>';
8808: }
8809: }
8810: return $output;
8811: }
8812:
1.160 raeburn 8813: sub crumb_utilities {
8814: my %elements = (
8815: crtuser => {
8816: srchterm => 'text',
1.172 raeburn 8817: srchin => 'selectbox',
1.160 raeburn 8818: srchby => 'selectbox',
8819: srchtype => 'selectbox',
8820: srchdomain => 'selectbox',
8821: },
1.207 raeburn 8822: crtusername => {
8823: srchterm => 'text',
8824: srchdomain => 'selectbox',
8825: },
1.160 raeburn 8826: docustom => {
8827: rolename => 'selectbox',
8828: newrolename => 'textbox',
8829: },
1.179 raeburn 8830: studentform => {
8831: srchterm => 'text',
8832: srchin => 'selectbox',
8833: srchby => 'selectbox',
8834: srchtype => 'selectbox',
8835: srchdomain => 'selectbox',
8836: },
1.160 raeburn 8837: );
8838:
8839: my $jsback .= qq|
8840: function backPage(formname,prevphase,prevstate) {
1.211 raeburn 8841: if (typeof prevphase == 'undefined') {
8842: formname.phase.value = '';
8843: }
8844: else {
8845: formname.phase.value = prevphase;
8846: }
8847: if (typeof prevstate == 'undefined') {
8848: formname.currstate.value = '';
8849: }
8850: else {
8851: formname.currstate.value = prevstate;
8852: }
1.160 raeburn 8853: formname.submit();
8854: }
8855: |;
8856: return ($jsback,\%elements);
8857: }
8858:
1.26 matthew 8859: sub course_level_table {
1.375 raeburn 8860: my ($inccourses,$showcredits,$defaultcredits) = @_;
8861: return unless (ref($inccourses) eq 'HASH');
1.26 matthew 8862: my $table = '';
1.62 www 8863: # Custom Roles?
8864:
1.190 raeburn 8865: my %customroles=&Apache::lonuserutils::my_custom_roles();
1.89 raeburn 8866: my %lt=&Apache::lonlocal::texthash(
8867: 'exs' => "Existing sections",
8868: 'new' => "Define new section",
8869: 'ssd' => "Set Start Date",
8870: 'sed' => "Set End Date",
1.131 raeburn 8871: 'crl' => "Course Level",
1.89 raeburn 8872: 'act' => "Activate",
8873: 'rol' => "Role",
8874: 'ext' => "Extent",
1.113 raeburn 8875: 'grs' => "Section",
1.375 raeburn 8876: 'crd' => "Credits",
1.89 raeburn 8877: 'sta' => "Start",
8878: 'end' => "End"
8879: );
1.62 www 8880:
1.375 raeburn 8881: foreach my $protectedcourse (sort(keys(%{$inccourses}))) {
1.135 raeburn 8882: my $thiscourse=$protectedcourse;
1.26 matthew 8883: $thiscourse=~s:_:/:g;
8884: my %coursedata=&Apache::lonnet::coursedescription($thiscourse);
1.365 raeburn 8885: my $isowner = &Apache::lonuserutils::is_courseowner($protectedcourse,$coursedata{'internal.courseowner'});
1.26 matthew 8886: my $area=$coursedata{'description'};
1.321 raeburn 8887: my $crstype=$coursedata{'type'};
1.135 raeburn 8888: if (!defined($area)) { $area=&mt('Unavailable course').': '.$protectedcourse; }
1.89 raeburn 8889: my ($domain,$cnum)=split(/\//,$thiscourse);
1.115 albertel 8890: my %sections_count;
1.101 albertel 8891: if (defined($env{'request.course.id'})) {
8892: if ($env{'request.course.id'} eq $domain.'_'.$cnum) {
1.115 albertel 8893: %sections_count =
8894: &Apache::loncommon::get_sections($domain,$cnum);
1.92 raeburn 8895: }
8896: }
1.321 raeburn 8897: my @roles = &Apache::lonuserutils::roles_by_context('course','',$crstype);
1.213 raeburn 8898: foreach my $role (@roles) {
1.321 raeburn 8899: my $plrole=&Apache::lonnet::plaintext($role,$crstype);
1.329 raeburn 8900: if ((&Apache::lonnet::allowed('c'.$role,$thiscourse)) ||
8901: ((($role eq 'cc') || ($role eq 'co')) && ($isowner))) {
1.221 raeburn 8902: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
1.375 raeburn 8903: $plrole,\%sections_count,\%lt,
1.402 raeburn 8904: $showcredits,$defaultcredits,$crstype);
1.221 raeburn 8905: } elsif ($env{'request.course.sec'} ne '') {
8906: if (&Apache::lonnet::allowed('c'.$role,$thiscourse.'/'.
8907: $env{'request.course.sec'})) {
8908: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
1.375 raeburn 8909: $plrole,\%sections_count,\%lt,
1.402 raeburn 8910: $showcredits,$defaultcredits,$crstype);
1.26 matthew 8911: }
8912: }
8913: }
1.221 raeburn 8914: if (&Apache::lonnet::allowed('ccr',$thiscourse)) {
1.324 raeburn 8915: foreach my $cust (sort(keys(%customroles))) {
8916: next if ($crstype eq 'Community' && $customroles{$cust} =~ /bre\&S/);
1.221 raeburn 8917: my $role = 'cr_cr_'.$env{'user.domain'}.'_'.$env{'user.name'}.'_'.$cust;
8918: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
1.402 raeburn 8919: $cust,\%sections_count,\%lt,
8920: $showcredits,$defaultcredits,$crstype);
1.221 raeburn 8921: }
1.62 www 8922: }
1.26 matthew 8923: }
8924: return '' if ($table eq ''); # return nothing if there is nothing
8925: # in the table
1.188 raeburn 8926: my $result;
8927: if (!$env{'request.course.id'}) {
8928: $result = '<h4>'.$lt{'crl'}.'</h4>'."\n";
8929: }
8930: $result .=
1.136 raeburn 8931: &Apache::loncommon::start_data_table().
8932: &Apache::loncommon::start_data_table_header_row().
1.375 raeburn 8933: '<th>'.$lt{'act'}.'</th><th>'.$lt{'rol'}.'</th>'."\n".
1.402 raeburn 8934: '<th>'.$lt{'ext'}.'</th><th>'."\n";
8935: if ($showcredits) {
8936: $result .= $lt{'crd'}.'</th>';
8937: }
8938: $result .=
1.375 raeburn 8939: '<th>'.$lt{'grs'}.'</th><th>'.$lt{'sta'}.'</th>'."\n".
8940: '<th>'.$lt{'end'}.'</th>'.
1.136 raeburn 8941: &Apache::loncommon::end_data_table_header_row().
8942: $table.
8943: &Apache::loncommon::end_data_table();
1.26 matthew 8944: return $result;
8945: }
1.88 raeburn 8946:
1.221 raeburn 8947: sub course_level_row {
1.375 raeburn 8948: my ($protectedcourse,$role,$area,$domain,$plrole,$sections_count,
1.402 raeburn 8949: $lt,$showcredits,$defaultcredits,$crstype) = @_;
1.375 raeburn 8950: my $creditem;
1.222 raeburn 8951: my $row = &Apache::loncommon::start_data_table_row().
8952: ' <td><input type="checkbox" name="act_'.
8953: $protectedcourse.'_'.$role.'" /></td>'."\n".
8954: ' <td>'.$plrole.'</td>'."\n".
8955: ' <td>'.$area.'<br />Domain: '.$domain.'</td>'."\n";
1.402 raeburn 8956: if (($showcredits) && ($role eq 'st') && ($crstype eq 'Course')) {
1.375 raeburn 8957: $row .=
8958: '<td><input type="text" name="credits_'.$protectedcourse.'_'.
8959: $role.'" size="3" value="'.$defaultcredits.'" /></td>';
8960: } else {
8961: $row .= '<td> </td>';
8962: }
1.322 raeburn 8963: if (($role eq 'cc') || ($role eq 'co')) {
1.222 raeburn 8964: $row .= '<td> </td>';
1.221 raeburn 8965: } elsif ($env{'request.course.sec'} ne '') {
1.222 raeburn 8966: $row .= ' <td><input type="hidden" value="'.
8967: $env{'request.course.sec'}.'" '.
8968: 'name="sec_'.$protectedcourse.'_'.$role.'" />'.
8969: $env{'request.course.sec'}.'</td>';
1.221 raeburn 8970: } else {
8971: if (ref($sections_count) eq 'HASH') {
8972: my $currsec =
8973: &Apache::lonuserutils::course_sections($sections_count,
8974: $protectedcourse.'_'.$role);
1.222 raeburn 8975: $row .= '<td><table class="LC_createuser">'."\n".
8976: '<tr class="LC_section_row">'."\n".
8977: ' <td valign="top">'.$lt->{'exs'}.'<br />'.
8978: $currsec.'</td>'."\n".
8979: ' <td> </td>'."\n".
8980: ' <td valign="top"> '.$lt->{'new'}.'<br />'.
1.221 raeburn 8981: '<input type="text" name="newsec_'.$protectedcourse.'_'.$role.
8982: '" value="" />'.
8983: '<input type="hidden" '.
8984: 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'."\n".
1.222 raeburn 8985: '</tr></table></td>'."\n";
1.221 raeburn 8986: } else {
1.222 raeburn 8987: $row .= '<td><input type="text" size="10" '.
1.375 raeburn 8988: 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'."\n";
1.221 raeburn 8989: }
8990: }
1.222 raeburn 8991: $row .= <<ENDTIMEENTRY;
8992: <td><input type="hidden" name="start_$protectedcourse\_$role" value="" />
1.221 raeburn 8993: <a href=
8994: "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 8995: <td><input type="hidden" name="end_$protectedcourse\_$role" value="" />
1.221 raeburn 8996: <a href=
8997: "javascript:pjump('date_end','End Date $plrole',document.cu.end_$protectedcourse\_$role.value,'end_$protectedcourse\_$role','cu.pres','dateset')">$lt->{'sed'}</a></td>
8998: ENDTIMEENTRY
1.222 raeburn 8999: $row .= &Apache::loncommon::end_data_table_row();
9000: return $row;
1.221 raeburn 9001: }
9002:
1.88 raeburn 9003: sub course_level_dc {
1.375 raeburn 9004: my ($dcdom,$showcredits) = @_;
1.190 raeburn 9005: my %customroles=&Apache::lonuserutils::my_custom_roles();
1.213 raeburn 9006: my @roles = &Apache::lonuserutils::roles_by_context('course');
1.88 raeburn 9007: my $hiddenitems = '<input type="hidden" name="dcdomain" value="'.$dcdom.'" />'.
9008: '<input type="hidden" name="origdom" value="'.$dcdom.'" />'.
1.133 raeburn 9009: '<input type="hidden" name="dccourse" value="" />';
1.355 www 9010: my $courseform=&Apache::loncommon::selectcourse_link
1.356 raeburn 9011: ('cu','dccourse','dcdomain','coursedesc',undef,undef,'Select','crstype');
1.375 raeburn 9012: my $credit_elem;
9013: if ($showcredits) {
9014: $credit_elem = 'credits';
9015: }
9016: my $cb_jscript = &Apache::loncommon::coursebrowser_javascript($dcdom,'currsec','cu','role','Course/Community Browser',$credit_elem);
1.88 raeburn 9017: my %lt=&Apache::lonlocal::texthash(
9018: 'rol' => "Role",
1.113 raeburn 9019: 'grs' => "Section",
1.88 raeburn 9020: 'exs' => "Existing sections",
9021: 'new' => "Define new section",
9022: 'sta' => "Start",
9023: 'end' => "End",
9024: 'ssd' => "Set Start Date",
1.355 www 9025: 'sed' => "Set End Date",
1.375 raeburn 9026: 'scc' => "Course/Community",
9027: 'crd' => "Credits",
1.88 raeburn 9028: );
1.323 raeburn 9029: my $header = '<h4>'.&mt('Course/Community Level').'</h4>'.
1.136 raeburn 9030: &Apache::loncommon::start_data_table().
9031: &Apache::loncommon::start_data_table_header_row().
1.375 raeburn 9032: '<th>'.$lt{'scc'}.'</th><th>'.$lt{'rol'}.'</th>'."\n".
1.397 bisitz 9033: '<th>'.$lt{'grs'}.'</th>'."\n";
9034: $header .= '<th>'.$lt{'crd'}.'</th>'."\n" if ($showcredits);
9035: $header .= '<th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'."\n".
1.136 raeburn 9036: &Apache::loncommon::end_data_table_header_row();
1.143 raeburn 9037: my $otheritems = &Apache::loncommon::start_data_table_row()."\n".
1.356 raeburn 9038: '<td><br /><span class="LC_nobreak"><input type="text" name="coursedesc" value="" onfocus="this.blur();opencrsbrowser('."'cu','dccourse','dcdomain','coursedesc','','','','crstype'".')" />'.
9039: $courseform.(' ' x4).'</span></td>'."\n".
1.389 bisitz 9040: '<td valign="top"><br /><select name="role">'."\n";
1.213 raeburn 9041: foreach my $role (@roles) {
1.135 raeburn 9042: my $plrole=&Apache::lonnet::plaintext($role);
1.389 bisitz 9043: $otheritems .= ' <option value="'.$role.'">'.$plrole.'</option>';
1.88 raeburn 9044: }
1.404 raeburn 9045: if ( keys(%customroles) > 0) {
9046: foreach my $cust (sort(keys(%customroles))) {
1.101 albertel 9047: my $custrole='cr_cr_'.$env{'user.domain'}.
1.135 raeburn 9048: '_'.$env{'user.name'}.'_'.$cust;
1.389 bisitz 9049: $otheritems .= ' <option value="'.$custrole.'">'.$cust.'</option>';
1.88 raeburn 9050: }
9051: }
9052: $otheritems .= '</select></td><td>'.
9053: '<table border="0" cellspacing="0" cellpadding="0">'.
9054: '<tr><td valign="top"><b>'.$lt{'exs'}.'</b><br /><select name="currsec">'.
1.389 bisitz 9055: ' <option value=""><--'.&mt('Pick course first').'</option></select></td>'.
1.88 raeburn 9056: '<td> </td>'.
9057: '<td valign="top"> <b>'.$lt{'new'}.'</b><br />'.
1.113 raeburn 9058: '<input type="text" name="newsec" value="" />'.
1.237 raeburn 9059: '<input type="hidden" name="section" value="" />'.
1.323 raeburn 9060: '<input type="hidden" name="groups" value="" />'.
9061: '<input type="hidden" name="crstype" value="" /></td>'.
1.375 raeburn 9062: '</tr></table></td>'."\n";
9063: if ($showcredits) {
9064: $otheritems .= '<td><br />'."\n".
1.397 bisitz 9065: '<input type="text" size="3" name="credits" value="" /></td>'."\n";
1.375 raeburn 9066: }
1.88 raeburn 9067: $otheritems .= <<ENDTIMEENTRY;
1.323 raeburn 9068: <td><br /><input type="hidden" name="start" value='' />
1.88 raeburn 9069: <a href=
9070: "javascript:pjump('date_start','Start Date',document.cu.start.value,'start','cu.pres','dateset')">$lt{'ssd'}</a></td>
1.323 raeburn 9071: <td><br /><input type="hidden" name="end" value='' />
1.88 raeburn 9072: <a href=
9073: "javascript:pjump('date_end','End Date',document.cu.end.value,'end','cu.pres','dateset')">$lt{'sed'}</a></td>
9074: ENDTIMEENTRY
1.136 raeburn 9075: $otheritems .= &Apache::loncommon::end_data_table_row().
9076: &Apache::loncommon::end_data_table()."\n";
1.88 raeburn 9077: return $cb_jscript.$header.$hiddenitems.$otheritems;
9078: }
9079:
1.237 raeburn 9080: sub update_selfenroll_config {
1.400 raeburn 9081: my ($r,$cid,$cdom,$cnum,$context,$crstype,$currsettings) = @_;
1.398 raeburn 9082: return unless (ref($currsettings) eq 'HASH');
9083: my ($row,$lt) = &Apache::lonuserutils::get_selfenroll_titles();
9084: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
1.237 raeburn 9085: my (%changes,%warning);
1.241 raeburn 9086: my $curr_types;
1.400 raeburn 9087: my %noedit;
9088: unless ($context eq 'domain') {
9089: %noedit = &get_noedit_fields($cdom,$cnum,$crstype,$row);
9090: }
1.237 raeburn 9091: if (ref($row) eq 'ARRAY') {
9092: foreach my $item (@{$row}) {
1.400 raeburn 9093: next if ($noedit{$item});
1.237 raeburn 9094: if ($item eq 'enroll_dates') {
9095: my (%currenrolldate,%newenrolldate);
9096: foreach my $type ('start','end') {
1.398 raeburn 9097: $currenrolldate{$type} = $currsettings->{'selfenroll_'.$type.'_date'};
1.237 raeburn 9098: $newenrolldate{$type} = &Apache::lonhtmlcommon::get_date_from_form('selfenroll_'.$type.'_date');
9099: if ($newenrolldate{$type} ne $currenrolldate{$type}) {
9100: $changes{'internal.selfenroll_'.$type.'_date'} = $newenrolldate{$type};
9101: }
9102: }
9103: } elsif ($item eq 'access_dates') {
9104: my (%currdate,%newdate);
9105: foreach my $type ('start','end') {
1.398 raeburn 9106: $currdate{$type} = $currsettings->{'selfenroll_'.$type.'_access'};
1.237 raeburn 9107: $newdate{$type} = &Apache::lonhtmlcommon::get_date_from_form('selfenroll_'.$type.'_access');
9108: if ($newdate{$type} ne $currdate{$type}) {
9109: $changes{'internal.selfenroll_'.$type.'_access'} = $newdate{$type};
9110: }
9111: }
1.241 raeburn 9112: } elsif ($item eq 'types') {
1.398 raeburn 9113: $curr_types = $currsettings->{'selfenroll_'.$item};
1.241 raeburn 9114: if ($env{'form.selfenroll_all'}) {
9115: if ($curr_types ne '*') {
9116: $changes{'internal.selfenroll_types'} = '*';
9117: } else {
9118: next;
9119: }
9120: } else {
1.249 raeburn 9121: my %currdoms;
1.241 raeburn 9122: my @entries = split(/;/,$curr_types);
9123: my @deletedoms = &Apache::loncommon::get_env_multiple('form.selfenroll_delete');
1.249 raeburn 9124: my @activations = &Apache::loncommon::get_env_multiple('form.selfenroll_activate');
1.241 raeburn 9125: my $newnum = 0;
1.249 raeburn 9126: my @latesttypes;
9127: foreach my $num (@activations) {
9128: my @types = &Apache::loncommon::get_env_multiple('form.selfenroll_types_'.$num);
9129: if (@types > 0) {
1.241 raeburn 9130: @types = sort(@types);
9131: my $typestr = join(',',@types);
1.249 raeburn 9132: my $typedom = $env{'form.selfenroll_dom_'.$num};
9133: $latesttypes[$newnum] = $typedom.':'.$typestr;
9134: $currdoms{$typedom} = 1;
1.241 raeburn 9135: $newnum ++;
9136: }
9137: }
1.338 raeburn 9138: for (my $j=0; $j<$env{'form.selfenroll_types_total'}; $j++) {
9139: if ((!grep(/^$j$/,@deletedoms)) && (!grep(/^$j$/,@activations))) {
1.249 raeburn 9140: my @types = &Apache::loncommon::get_env_multiple('form.selfenroll_types_'.$j);
9141: if (@types > 0) {
9142: @types = sort(@types);
9143: my $typestr = join(',',@types);
9144: my $typedom = $env{'form.selfenroll_dom_'.$j};
9145: $latesttypes[$newnum] = $typedom.':'.$typestr;
9146: $currdoms{$typedom} = 1;
9147: $newnum ++;
9148: }
9149: }
9150: }
9151: if ($env{'form.selfenroll_newdom'} ne '') {
9152: my $typedom = $env{'form.selfenroll_newdom'};
9153: if ((!defined($currdoms{$typedom})) &&
9154: (&Apache::lonnet::domain($typedom) ne '')) {
9155: my $typestr;
9156: my ($othertitle,$usertypes,$types) =
9157: &Apache::loncommon::sorted_inst_types($typedom);
9158: my $othervalue = 'any';
9159: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
9160: if (@{$types} > 0) {
1.257 raeburn 9161: my @esc_types = map { &escape($_); } @{$types};
1.249 raeburn 9162: $othervalue = 'other';
1.258 raeburn 9163: $typestr = join(',',(@esc_types,$othervalue));
1.249 raeburn 9164: }
9165: $typestr = $othervalue;
9166: } else {
9167: $typestr = $othervalue;
9168: }
9169: $latesttypes[$newnum] = $typedom.':'.$typestr;
9170: $newnum ++ ;
9171: }
9172: }
1.241 raeburn 9173: my $selfenroll_types = join(';',@latesttypes);
9174: if ($selfenroll_types ne $curr_types) {
9175: $changes{'internal.selfenroll_types'} = $selfenroll_types;
9176: }
9177: }
1.276 raeburn 9178: } elsif ($item eq 'limit') {
9179: my $newlimit = $env{'form.selfenroll_limit'};
9180: my $newcap = $env{'form.selfenroll_cap'};
9181: $newcap =~s/\s+//g;
1.398 raeburn 9182: my $currlimit = $currsettings->{'selfenroll_limit'};
1.276 raeburn 9183: $currlimit = 'none' if ($currlimit eq '');
1.398 raeburn 9184: my $currcap = $currsettings->{'selfenroll_cap'};
1.276 raeburn 9185: if ($newlimit ne $currlimit) {
9186: if ($newlimit ne 'none') {
9187: if ($newcap =~ /^\d+$/) {
9188: if ($newcap ne $currcap) {
9189: $changes{'internal.selfenroll_cap'} = $newcap;
9190: }
9191: $changes{'internal.selfenroll_limit'} = $newlimit;
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: } elsif ($currcap ne '') {
9197: $changes{'internal.selfenroll_cap'} = '';
9198: $changes{'internal.selfenroll_limit'} = $newlimit;
9199: }
9200: } elsif ($currlimit ne 'none') {
9201: if ($newcap =~ /^\d+$/) {
9202: if ($newcap ne $currcap) {
9203: $changes{'internal.selfenroll_cap'} = $newcap;
9204: }
9205: } else {
1.398 raeburn 9206: $warning{$item} = &mt('Maximum enrollment setting unchanged.').'<br />'.
9207: &mt('The value provided was invalid - it must be a positive integer if enrollment is being limited.');
1.276 raeburn 9208: }
9209: }
9210: } elsif ($item eq 'approval') {
9211: my (@currnotified,@newnotified);
1.398 raeburn 9212: my $currapproval = $currsettings->{'selfenroll_approval'};
9213: my $currnotifylist = $currsettings->{'selfenroll_notifylist'};
1.276 raeburn 9214: if ($currnotifylist ne '') {
9215: @currnotified = split(/,/,$currnotifylist);
9216: @currnotified = sort(@currnotified);
9217: }
9218: my $newapproval = $env{'form.selfenroll_approval'};
9219: @newnotified = &Apache::loncommon::get_env_multiple('form.selfenroll_notify');
9220: @newnotified = sort(@newnotified);
9221: if ($newapproval ne $currapproval) {
9222: $changes{'internal.selfenroll_approval'} = $newapproval;
9223: if (!$newapproval) {
9224: if ($currnotifylist ne '') {
9225: $changes{'internal.selfenroll_notifylist'} = '';
9226: }
9227: } else {
9228: my @differences =
1.295 raeburn 9229: &Apache::loncommon::compare_arrays(\@currnotified,\@newnotified);
1.276 raeburn 9230: if (@differences > 0) {
9231: if (@newnotified > 0) {
9232: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
9233: } else {
9234: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
9235: }
9236: }
9237: }
9238: } else {
1.295 raeburn 9239: my @differences = &Apache::loncommon::compare_arrays(\@currnotified,\@newnotified);
1.276 raeburn 9240: if (@differences > 0) {
9241: if (@newnotified > 0) {
9242: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
9243: } else {
9244: $changes{'internal.selfenroll_notifylist'} = '';
9245: }
9246: }
9247: }
1.237 raeburn 9248: } else {
1.398 raeburn 9249: my $curr_val = $currsettings->{'selfenroll_'.$item};
1.237 raeburn 9250: my $newval = $env{'form.selfenroll_'.$item};
9251: if ($item eq 'section') {
9252: $newval = $env{'form.sections'};
1.241 raeburn 9253: if (defined($curr_groups{$newval})) {
1.237 raeburn 9254: $newval = $curr_val;
1.398 raeburn 9255: $warning{$item} = &mt('Section for self-enrolled users unchanged as the proposed section is a group').'<br />'.
9256: &mt('Group names and section names must be distinct');
1.237 raeburn 9257: } elsif ($newval eq 'all') {
9258: $newval = $curr_val;
1.274 bisitz 9259: $warning{$item} = &mt('Section for self-enrolled users unchanged, as "all" is a reserved section name.');
1.237 raeburn 9260: }
9261: if ($newval eq '') {
9262: $newval = 'none';
9263: }
9264: }
9265: if ($newval ne $curr_val) {
9266: $changes{'internal.selfenroll_'.$item} = $newval;
9267: }
1.241 raeburn 9268: }
1.237 raeburn 9269: }
9270: if (keys(%warning) > 0) {
9271: foreach my $item (@{$row}) {
9272: if (exists($warning{$item})) {
9273: $r->print($warning{$item}.'<br />');
9274: }
9275: }
9276: }
9277: if (keys(%changes) > 0) {
9278: my $putresult = &Apache::lonnet::put('environment',\%changes,$cdom,$cnum);
9279: if ($putresult eq 'ok') {
9280: if ((exists($changes{'internal.selfenroll_types'})) ||
9281: (exists($changes{'internal.selfenroll_start_date'})) ||
9282: (exists($changes{'internal.selfenroll_end_date'}))) {
9283: my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',
9284: $cnum,undef,undef,'Course');
9285: my $chome = &Apache::lonnet::homeserver($cnum,$cdom);
1.398 raeburn 9286: if (ref($crsinfo{$cid}) eq 'HASH') {
1.237 raeburn 9287: foreach my $item ('selfenroll_types','selfenroll_start_date','selfenroll_end_date') {
9288: if (exists($changes{'internal.'.$item})) {
1.398 raeburn 9289: $crsinfo{$cid}{$item} = $changes{'internal.'.$item};
1.237 raeburn 9290: }
9291: }
9292: my $crsputresult =
9293: &Apache::lonnet::courseidput($cdom,\%crsinfo,
9294: $chome,'notime');
9295: }
9296: }
9297: $r->print(&mt('The following changes were made to self-enrollment settings:').'<ul>');
9298: foreach my $item (@{$row}) {
9299: my $title = $item;
9300: if (ref($lt) eq 'HASH') {
9301: $title = $lt->{$item};
9302: }
9303: if ($item eq 'enroll_dates') {
9304: foreach my $type ('start','end') {
9305: if (exists($changes{'internal.selfenroll_'.$type.'_date'})) {
9306: my $newdate = &Apache::lonlocal::locallocaltime($changes{'internal.selfenroll_'.$type.'_date'});
1.244 bisitz 9307: $r->print('<li>'.&mt('[_1]: "[_2]" set to "[_3]".',
1.237 raeburn 9308: $title,$type,$newdate).'</li>');
9309: }
9310: }
9311: } elsif ($item eq 'access_dates') {
9312: foreach my $type ('start','end') {
9313: if (exists($changes{'internal.selfenroll_'.$type.'_access'})) {
9314: my $newdate = &Apache::lonlocal::locallocaltime($changes{'internal.selfenroll_'.$type.'_access'});
1.244 bisitz 9315: $r->print('<li>'.&mt('[_1]: "[_2]" set to "[_3]".',
1.237 raeburn 9316: $title,$type,$newdate).'</li>');
9317: }
9318: }
1.276 raeburn 9319: } elsif ($item eq 'limit') {
9320: if ((exists($changes{'internal.selfenroll_limit'})) ||
9321: (exists($changes{'internal.selfenroll_cap'}))) {
9322: my ($newval,$newcap);
9323: if ($changes{'internal.selfenroll_cap'} ne '') {
9324: $newcap = $changes{'internal.selfenroll_cap'}
9325: } else {
1.398 raeburn 9326: $newcap = $currsettings->{'selfenroll_cap'};
1.276 raeburn 9327: }
9328: if ($changes{'internal.selfenroll_limit'} eq 'none') {
9329: $newval = &mt('No limit');
9330: } elsif ($changes{'internal.selfenroll_limit'} eq
9331: 'allstudents') {
9332: $newval = &mt('New self-enrollment no longer allowed when total (all students) reaches [_1].',$newcap);
9333: } elsif ($changes{'internal.selfenroll_limit'} eq 'selfenrolled') {
9334: $newval = &mt('New self-enrollment no longer allowed when total number of self-enrolled students reaches [_1].',$newcap);
9335: } else {
1.398 raeburn 9336: my $currlimit = $currsettings->{'selfenroll_limit'};
1.276 raeburn 9337: if ($currlimit eq 'allstudents') {
9338: $newval = &mt('New self-enrollment no longer allowed when total (all students) reaches [_1].',$newcap);
9339: } elsif ($changes{'internal.selfenroll_limit'} eq 'selfenrolled') {
1.308 raeburn 9340: $newval = &mt('New self-enrollment no longer allowed when total number of self-enrolled students reaches [_1].',$newcap);
1.276 raeburn 9341: }
9342: }
9343: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval).'</li>'."\n");
9344: }
9345: } elsif ($item eq 'approval') {
9346: if ((exists($changes{'internal.selfenroll_approval'})) ||
9347: (exists($changes{'internal.selfenroll_notifylist'}))) {
1.398 raeburn 9348: my %selfdescs = &Apache::lonuserutils::selfenroll_default_descs();
1.276 raeburn 9349: my ($newval,$newnotify);
9350: if (exists($changes{'internal.selfenroll_notifylist'})) {
9351: $newnotify = $changes{'internal.selfenroll_notifylist'};
9352: } else {
1.398 raeburn 9353: $newnotify = $currsettings->{'selfenroll_notifylist'};
1.276 raeburn 9354: }
1.398 raeburn 9355: if (exists($changes{'internal.selfenroll_approval'})) {
9356: if ($changes{'internal.selfenroll_approval'} !~ /^[012]$/) {
9357: $changes{'internal.selfenroll_approval'} = '0';
9358: }
9359: $newval = $selfdescs{'approval'}{$changes{'internal.selfenroll_approval'}};
1.276 raeburn 9360: } else {
1.398 raeburn 9361: my $currapproval = $currsettings->{'selfenroll_approval'};
9362: if ($currapproval !~ /^[012]$/) {
9363: $currapproval = 0;
1.276 raeburn 9364: }
1.398 raeburn 9365: $newval = $selfdescs{'approval'}{$currapproval};
1.276 raeburn 9366: }
9367: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval));
9368: if ($newnotify) {
1.277 raeburn 9369: $r->print('<br />'.&mt('The following will be notified when an enrollment request needs approval, or has been approved: [_1].',$newnotify));
1.276 raeburn 9370: } else {
1.277 raeburn 9371: $r->print('<br />'.&mt('No notifications sent when an enrollment request needs approval, or has been approved.'));
1.276 raeburn 9372: }
9373: $r->print('</li>'."\n");
9374: }
1.237 raeburn 9375: } else {
9376: if (exists($changes{'internal.selfenroll_'.$item})) {
1.241 raeburn 9377: my $newval = $changes{'internal.selfenroll_'.$item};
9378: if ($item eq 'types') {
9379: if ($newval eq '') {
9380: $newval = &mt('None');
9381: } elsif ($newval eq '*') {
9382: $newval = &mt('Any user in any domain');
9383: }
1.245 raeburn 9384: } elsif ($item eq 'registered') {
9385: if ($newval eq '1') {
9386: $newval = &mt('Yes');
9387: } elsif ($newval eq '0') {
9388: $newval = &mt('No');
9389: }
1.241 raeburn 9390: }
1.244 bisitz 9391: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval).'</li>'."\n");
1.237 raeburn 9392: }
9393: }
9394: }
9395: $r->print('</ul>');
1.398 raeburn 9396: if ($env{'course.'.$cid.'.description'} ne '') {
9397: my %newenvhash;
9398: foreach my $key (keys(%changes)) {
9399: $newenvhash{'course.'.$cid.'.'.$key} = $changes{$key};
9400: }
9401: &Apache::lonnet::appenv(\%newenvhash);
1.237 raeburn 9402: }
9403: } else {
1.398 raeburn 9404: $r->print(&mt('An error occurred when saving changes to self-enrollment settings in this course.').'<br />'.
9405: &mt('The error was: [_1].',$putresult));
1.237 raeburn 9406: }
9407: } else {
1.249 raeburn 9408: $r->print(&mt('No changes were made to the existing self-enrollment settings in this course.'));
1.237 raeburn 9409: }
9410: } else {
1.249 raeburn 9411: $r->print(&mt('No changes were made to the existing self-enrollment settings in this course.'));
1.241 raeburn 9412: }
1.400 raeburn 9413: my $visactions = &cat_visibility();
9414: my ($cathash,%cattype);
9415: my %domconfig = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom);
9416: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
9417: $cathash = $domconfig{'coursecategories'}{'cats'};
9418: $cattype{'auth'} = $domconfig{'coursecategories'}{'auth'};
9419: $cattype{'unauth'} = $domconfig{'coursecategories'}{'unauth'};
9420: } else {
9421: $cathash = {};
9422: $cattype{'auth'} = 'std';
9423: $cattype{'unauth'} = 'std';
9424: }
9425: if (($cattype{'auth'} eq 'none') && ($cattype{'unauth'} eq 'none')) {
9426: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
9427: '<br />'.
9428: '<br />'.$visactions->{'take'}.'<ul>'.
9429: '<li>'.$visactions->{'dc_chgconf'}.'</li>'.
9430: '</ul>');
9431: } elsif (($cattype{'auth'} !~ /^(std|domonly)$/) && ($cattype{'unauth'} !~ /^(std|domonly)$/)) {
9432: if ($currsettings->{'uniquecode'}) {
9433: $r->print('<span class="LC_info">'.$visactions->{'vis'}.'</span>');
9434: } else {
1.366 bisitz 9435: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
1.400 raeburn 9436: '<br />'.
9437: '<br />'.$visactions->{'take'}.'<ul>'.
9438: '<li>'.$visactions->{'dc_setcode'}.'</li>'.
9439: '</ul><br />');
9440: }
9441: } else {
9442: my ($visible,$cansetvis,$vismsgs) = &visible_in_stdcat($cdom,$cnum,\%domconfig);
9443: if (ref($visactions) eq 'HASH') {
9444: if (!$visible) {
9445: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
9446: '<br />');
9447: if (ref($vismsgs) eq 'ARRAY') {
9448: $r->print('<br />'.$visactions->{'take'}.'<ul>');
9449: foreach my $item (@{$vismsgs}) {
9450: $r->print('<li>'.$visactions->{$item}.'</li>');
9451: }
9452: $r->print('</ul>');
1.256 raeburn 9453: }
1.400 raeburn 9454: $r->print($cansetvis);
1.256 raeburn 9455: }
9456: }
9457: }
1.237 raeburn 9458: return;
9459: }
9460:
1.27 matthew 9461: #---------------------------------------------- end functions for &phase_two
1.29 matthew 9462:
9463: #--------------------------------- functions for &phase_two and &phase_three
9464:
9465: #--------------------------end of functions for &phase_two and &phase_three
1.372 raeburn 9466:
1.1 www 9467: 1;
9468: __END__
1.2 www 9469:
9470:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>