Annotation of loncom/interface/loncreateuser.pm, revision 1.443
1.20 harris41 1: # The LearningOnline Network with CAPA
1.1 www 2: # Create a user
3: #
1.443 ! raeburn 4: # $Id: loncreateuser.pm,v 1.442 2017/07/26 19:45:45 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.443 ! raeburn 2355: $now,$captchaform,$emailusername,$usertype,$usernameset,$condition,$excluded) = @_;
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',
1.442 raeburn 2382: 'username' => 'Username',
1.391 raeburn 2383: );
2384:
2385: %canmodify_status =
1.286 raeburn 2386: &Apache::lonuserutils::can_modify_userinfo($context,$ccdomain,
2387: ['inststatus'],$rolesarray);
1.253 raeburn 2388: if (!$newuser) {
1.188 raeburn 2389: # Get the users information
2390: %userenv = &Apache::lonnet::get('environment',
2391: ['firstname','middlename','lastname','generation',
1.286 raeburn 2392: 'permanentemail','id','inststatus'],$ccdomain,$ccuname);
1.219 raeburn 2393: %canmodify =
2394: &Apache::lonuserutils::can_modify_userinfo($context,$ccdomain,
1.252 raeburn 2395: \@userinfo,$rolesarray);
1.257 raeburn 2396: } elsif ($context eq 'selfcreate') {
1.391 raeburn 2397: if ($newuser eq 'email') {
1.396 raeburn 2398: if (ref($emailusername) eq 'HASH') {
2399: if (ref($emailusername->{$usertype}) eq 'HASH') {
2400: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
1.442 raeburn 2401: @userinfo = ();
1.396 raeburn 2402: if ((ref($infofields) eq 'ARRAY') && (ref($infotitles) eq 'HASH')) {
2403: foreach my $field (@{$infofields}) {
2404: if ($emailusername->{$usertype}->{$field}) {
2405: push(@userinfo,$field);
2406: $canmodify{$field} = 1;
2407: unless ($textboxsize{$field}) {
2408: $textboxsize{$field} = 25;
2409: }
2410: unless ($lt{$field}) {
2411: $lt{$field} = $infotitles->{$field};
2412: }
2413: if ($emailusername->{$usertype}->{$field} eq 'required') {
2414: $lt{$field} .= '<b>*</b>';
2415: }
1.391 raeburn 2416: }
2417: }
2418: }
2419: }
2420: }
2421: } else {
2422: %canmodify = &selfcreate_canmodify($context,$ccdomain,\@userinfo,
2423: $inst_results,$rolesarray);
2424: }
1.188 raeburn 2425: }
1.391 raeburn 2426:
1.188 raeburn 2427: my $genhelp=&Apache::loncommon::help_open_topic('Generation');
2428: $output = '<h3>'.$lt{'pd'}.'</h3>'.
2429: &Apache::lonhtmlcommon::start_pick_box();
1.391 raeburn 2430: if (($context eq 'selfcreate') && ($newuser eq 'email')) {
1.443 ! raeburn 2431: my $size = 25;
1.442 raeburn 2432: if ($condition) {
1.443 ! raeburn 2433: if ($condition =~ /^\@[^\@]+$/) {
! 2434: $size = 10;
1.442 raeburn 2435: } else {
2436: undef($condition);
2437: }
1.443 ! raeburn 2438: }
! 2439: if ($excluded) {
! 2440: unless ($excluded =~ /^\@[^\@]+$/) {
! 2441: undef($condition);
! 2442: }
1.442 raeburn 2443: }
1.396 raeburn 2444: $output .= &Apache::lonhtmlcommon::row_title($lt{'email'}.'<b>*</b>',undef,
1.391 raeburn 2445: 'LC_oddrow_value')."\n".
1.443 ! raeburn 2446: '<input type="text" name="uname" size="'.$size.'" value="" autocomplete="off" />';
! 2447: if ($condition) {
! 2448: $output .= $condition;
! 2449: } elsif ($excluded) {
! 2450: $output .= '<br /><span style="font-size: smaller">'.&mt('You must use an e-mail address that does not end with [_1]',
! 2451: $excluded).'</span>';
! 2452: }
! 2453: if ($usernameset eq 'first') {
! 2454: $output .= '<br /><span style="font-size: smaller">';
! 2455: if ($condition) {
! 2456: $output .= &mt('Your username in LON-CAPA will be the part of your e-mail address before [_1]',
! 2457: $condition);
! 2458: } else {
! 2459: $output .= &mt('Your username in LON-CAPA will be the part of your e-mail address before the @');
! 2460: }
! 2461: $output .= '</span>';
! 2462: }
1.391 raeburn 2463: $rowcount ++;
2464: $output .= &Apache::lonhtmlcommon::row_closure(1);
1.408 raeburn 2465: my $upassone = '<input type="password" name="upass'.$now.'" size="20" autocomplete="off" />';
2466: my $upasstwo = '<input type="password" name="upasscheck'.$now.'" size="20" autocomplete="off" />';
1.396 raeburn 2467: $output .= &Apache::lonhtmlcommon::row_title(&mt('Password').'<b>*</b>',
1.391 raeburn 2468: 'LC_pick_box_title',
2469: 'LC_oddrow_value')."\n".
2470: $upassone."\n".
2471: &Apache::lonhtmlcommon::row_closure(1)."\n".
1.396 raeburn 2472: &Apache::lonhtmlcommon::row_title(&mt('Confirm password').'<b>*</b>',
1.391 raeburn 2473: 'LC_pick_box_title',
2474: 'LC_oddrow_value')."\n".
2475: $upasstwo.
2476: &Apache::lonhtmlcommon::row_closure()."\n";
1.443 ! raeburn 2477: if ($usernameset eq 'free') {
! 2478: my $onclick = "toggleUsernameDisp(this,'selfcreateusername');";
1.442 raeburn 2479: $output .= &Apache::lonhtmlcommon::row_title($lt{'username'},undef,'LC_oddrow_value')."\n".
2480: &mt('Use e-mail address: ').
2481: '<label><input type="radio" name="emailused" value="1" checked="checked" onclick="'.$onclick.'" />'.&mt('Yes').'</label>'."\n".
2482: (' 'x2).
2483: '<label><input type="radio" name="emailused" value="0" onclick="'.$onclick.'" />'.&mt('No').'</label>'."\n".
2484: '<div id="selfcreateusername" style="display: none; font-size: smaller">'.
2485: '<br /><span class="LC_nobreak">'.&mt('Preferred username').
2486: ' <input type="text" name="username" value="" size="20" autocomplete="off"/>'.
2487: '</span></div>'."\n".&Apache::lonhtmlcommon::row_closure(1);
2488: $rowcount ++;
2489: }
1.391 raeburn 2490: }
1.188 raeburn 2491: foreach my $item (@userinfo) {
2492: my $rowtitle = $lt{$item};
1.252 raeburn 2493: my $hiderow = 0;
1.188 raeburn 2494: if ($item eq 'generation') {
2495: $rowtitle = $genhelp.$rowtitle;
2496: }
1.252 raeburn 2497: my $row = &Apache::lonhtmlcommon::row_title($rowtitle,undef,'LC_oddrow_value')."\n";
1.188 raeburn 2498: if ($newuser) {
1.210 raeburn 2499: if (ref($inst_results) eq 'HASH') {
2500: if ($inst_results->{$item} ne '') {
1.252 raeburn 2501: $row .= '<input type="hidden" name="c'.$item.'" value="'.$inst_results->{$item}.'" />'.$inst_results->{$item};
1.210 raeburn 2502: } else {
1.252 raeburn 2503: if ($context eq 'selfcreate') {
1.391 raeburn 2504: if ($canmodify{$item}) {
1.394 raeburn 2505: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" autocomplete="off" />';
1.252 raeburn 2506: $editable ++;
2507: } else {
2508: $hiderow = 1;
2509: }
1.253 raeburn 2510: } else {
2511: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
1.252 raeburn 2512: }
1.210 raeburn 2513: }
1.188 raeburn 2514: } else {
1.252 raeburn 2515: if ($context eq 'selfcreate') {
1.401 raeburn 2516: if ($canmodify{$item}) {
2517: if ($newuser eq 'email') {
2518: $row .= '<input type="text" name="'.$item.'" size="'.$textboxsize{$item}.'" value="" autocomplete="off" />';
1.287 raeburn 2519: } else {
1.401 raeburn 2520: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" autocomplete="off" />';
1.287 raeburn 2521: }
1.401 raeburn 2522: $editable ++;
2523: } else {
2524: $hiderow = 1;
1.252 raeburn 2525: }
1.253 raeburn 2526: } else {
2527: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
1.252 raeburn 2528: }
1.188 raeburn 2529: }
2530: } else {
1.219 raeburn 2531: if ($canmodify{$item}) {
1.252 raeburn 2532: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="'.$userenv{$item}.'" />';
1.393 raeburn 2533: if (($item eq 'id') && (!$newuser)) {
2534: $row .= '<br />'.&Apache::lonuserutils::forceid_change($context);
2535: }
1.188 raeburn 2536: } else {
1.252 raeburn 2537: $row .= $userenv{$item};
1.188 raeburn 2538: }
2539: }
1.252 raeburn 2540: $row .= &Apache::lonhtmlcommon::row_closure(1);
2541: if (!$hiderow) {
2542: $output .= $row;
2543: $rowcount ++;
2544: }
1.188 raeburn 2545: }
1.286 raeburn 2546: if (($canmodify_status{'inststatus'}) || ($context ne 'selfcreate')) {
2547: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($ccdomain);
2548: if (ref($types) eq 'ARRAY') {
2549: if (@{$types} > 0) {
2550: my ($hiderow,$shown);
2551: if ($canmodify_status{'inststatus'}) {
2552: $shown = &pick_inst_statuses($userenv{'inststatus'},$usertypes,$types);
2553: } else {
2554: if ($userenv{'inststatus'} eq '') {
2555: $hiderow = 1;
1.334 raeburn 2556: } else {
2557: my @showitems;
2558: foreach my $item ( map { &unescape($_); } split(':',$userenv{'inststatus'})) {
2559: if (exists($usertypes->{$item})) {
2560: push(@showitems,$usertypes->{$item});
2561: } else {
2562: push(@showitems,$item);
2563: }
2564: }
2565: if (@showitems) {
2566: $shown = join(', ',@showitems);
2567: } else {
2568: $hiderow = 1;
2569: }
1.286 raeburn 2570: }
2571: }
2572: if (!$hiderow) {
1.389 bisitz 2573: my $row = &Apache::lonhtmlcommon::row_title(&mt('Affiliations'),undef,'LC_oddrow_value')."\n".
1.286 raeburn 2574: $shown.&Apache::lonhtmlcommon::row_closure(1);
2575: if ($context eq 'selfcreate') {
2576: $rowcount ++;
2577: }
2578: $output .= $row;
2579: }
2580: }
2581: }
2582: }
1.391 raeburn 2583: if (($context eq 'selfcreate') && ($newuser eq 'email')) {
2584: if ($captchaform) {
1.410 raeburn 2585: $output .= &Apache::lonhtmlcommon::row_title($lt{'valid'}.'*',
2586: 'LC_pick_box_title')."\n".
2587: $captchaform."\n".'<br /><br />'.
1.391 raeburn 2588: &Apache::lonhtmlcommon::row_closure(1);
2589: $rowcount ++;
2590: }
2591: my $submit_text = &mt('Create account');
2592: $output .= &Apache::lonhtmlcommon::row_title()."\n".
2593: '<br /><input type="submit" name="createaccount" value="'.
2594: $submit_text.'" />'.
1.396 raeburn 2595: '<input type="hidden" name="type" value="'.$usertype.'" />'.
1.391 raeburn 2596: &Apache::lonhtmlcommon::row_closure(1);
2597: }
1.188 raeburn 2598: $output .= &Apache::lonhtmlcommon::end_pick_box();
1.206 raeburn 2599: if (wantarray) {
1.252 raeburn 2600: if ($context eq 'selfcreate') {
2601: return($output,$rowcount,$editable);
2602: } else {
1.388 bisitz 2603: return $output;
1.252 raeburn 2604: }
1.206 raeburn 2605: } else {
2606: return $output;
2607: }
1.188 raeburn 2608: }
2609:
1.286 raeburn 2610: sub pick_inst_statuses {
2611: my ($curr,$usertypes,$types) = @_;
2612: my ($output,$rem,@currtypes);
2613: if ($curr ne '') {
2614: @currtypes = map { &unescape($_); } split(/:/,$curr);
2615: }
2616: my $numinrow = 2;
2617: if (ref($types) eq 'ARRAY') {
2618: $output = '<table>';
2619: my $lastcolspan;
2620: for (my $i=0; $i<@{$types}; $i++) {
2621: if (defined($usertypes->{$types->[$i]})) {
2622: my $rem = $i%($numinrow);
2623: if ($rem == 0) {
2624: if ($i<@{$types}-1) {
2625: if ($i > 0) {
2626: $output .= '</tr>';
2627: }
2628: $output .= '<tr>';
2629: }
2630: } elsif ($i==@{$types}-1) {
2631: my $colsleft = $numinrow - $rem;
2632: if ($colsleft > 1) {
2633: $lastcolspan = ' colspan="'.$colsleft.'"';
2634: }
2635: }
2636: my $check = ' ';
2637: if (grep(/^\Q$types->[$i]\E$/,@currtypes)) {
2638: $check = ' checked="checked" ';
2639: }
2640: $output .= '<td class="LC_left_item"'.$lastcolspan.'>'.
2641: '<span class="LC_nobreak"><label>'.
2642: '<input type="checkbox" name="inststatus" '.
2643: 'value="'.$types->[$i].'"'.$check.'/>'.
2644: $usertypes->{$types->[$i]}.'</label></span></td>';
2645: }
2646: }
2647: $output .= '</tr></table>';
2648: }
2649: return $output;
2650: }
2651:
1.257 raeburn 2652: sub selfcreate_canmodify {
2653: my ($context,$dom,$userinfo,$inst_results,$rolesarray) = @_;
2654: if (ref($inst_results) eq 'HASH') {
2655: my @inststatuses = &get_inststatuses($inst_results);
2656: if (@inststatuses == 0) {
2657: @inststatuses = ('default');
2658: }
2659: $rolesarray = \@inststatuses;
2660: }
2661: my %canmodify =
2662: &Apache::lonuserutils::can_modify_userinfo($context,$dom,$userinfo,
2663: $rolesarray);
2664: return %canmodify;
2665: }
2666:
1.252 raeburn 2667: sub get_inststatuses {
2668: my ($insthashref) = @_;
2669: my @inststatuses = ();
2670: if (ref($insthashref) eq 'HASH') {
2671: if (ref($insthashref->{'inststatus'}) eq 'ARRAY') {
2672: @inststatuses = @{$insthashref->{'inststatus'}};
2673: }
2674: }
2675: return @inststatuses;
2676: }
2677:
1.4 www 2678: # ================================================================= Phase Three
1.42 matthew 2679: sub update_user_data {
1.375 raeburn 2680: my ($r,$context,$crstype,$brcrum,$showcredits) = @_;
1.101 albertel 2681: my $uhome=&Apache::lonnet::homeserver($env{'form.ccuname'},
2682: $env{'form.ccdomain'});
1.27 matthew 2683: # Error messages
1.188 raeburn 2684: my $error = '<span class="LC_error">'.&mt('Error').': ';
1.193 raeburn 2685: my $end = '</span><br /><br />';
2686: my $rtnlink = '<a href="javascript:backPage(document.userupdate,'.
1.188 raeburn 2687: "'$env{'form.prevphase'}','modify')".'" />'.
1.219 raeburn 2688: &mt('Return to previous page').'</a>'.
2689: &Apache::loncommon::end_page();
2690: my $now = time;
1.40 www 2691: my $title;
1.101 albertel 2692: if (exists($env{'form.makeuser'})) {
1.40 www 2693: $title='Set Privileges for New User';
2694: } else {
2695: $title='Modify User Privileges';
2696: }
1.213 raeburn 2697: my $newuser = 0;
1.160 raeburn 2698: my ($jsback,$elements) = &crumb_utilities();
2699: my $jscript = '<script type="text/javascript">'."\n".
1.301 bisitz 2700: '// <![CDATA['."\n".
2701: $jsback."\n".
2702: '// ]]>'."\n".
2703: '</script>'."\n";
1.422 raeburn 2704: my %breadcrumb_text = &singleuser_breadcrumb($crstype,$context,$env{'form.ccdomain'});
1.351 raeburn 2705: push (@{$brcrum},
2706: {href => "javascript:backPage(document.userupdate)",
2707: text => $breadcrumb_text{'search'},
2708: faq => 282,
2709: bug => 'Instructor Interface',}
2710: );
2711: if ($env{'form.prevphase'} eq 'userpicked') {
2712: push(@{$brcrum},
2713: {href => "javascript:backPage(document.userupdate,'get_user_info','select')",
2714: text => $breadcrumb_text{'userpicked'},
2715: faq => 282,
2716: bug => 'Instructor Interface',});
1.233 raeburn 2717: }
1.224 raeburn 2718: my $helpitem = 'Course_Change_Privileges';
2719: if ($env{'form.action'} eq 'singlestudent') {
2720: $helpitem = 'Course_Add_Student';
1.439 raeburn 2721: } elsif ($context eq 'author') {
2722: $helpitem = 'Author_Change_Privileges';
2723: } elsif ($context eq 'domain') {
2724: $helpitem = 'Domain_Change_Privileges';
1.224 raeburn 2725: }
1.351 raeburn 2726: push(@{$brcrum},
2727: {href => "javascript:backPage(document.userupdate,'$env{'form.prevphase'}','modify')",
2728: text => $breadcrumb_text{'modify'},
2729: faq => 282,
2730: bug => 'Instructor Interface',},
2731: {href => "/adm/createuser",
2732: text => "Result",
2733: faq => 282,
2734: bug => 'Instructor Interface',
2735: help => $helpitem});
2736: my $args = {bread_crumbs => $brcrum,
2737: bread_crumbs_component => 'User Management'};
2738: if ($env{'form.popup'}) {
2739: $args->{'no_nav_bar'} = 1;
2740: }
2741: $r->print(&Apache::loncommon::start_page($title,$jscript,$args));
1.188 raeburn 2742: $r->print(&update_result_form($uhome));
1.27 matthew 2743: # Check Inputs
1.101 albertel 2744: if (! $env{'form.ccuname'} ) {
1.193 raeburn 2745: $r->print($error.&mt('No login name specified').'.'.$end.$rtnlink);
1.27 matthew 2746: return;
2747: }
1.138 albertel 2748: if ( $env{'form.ccuname'} ne
2749: &LONCAPA::clean_username($env{'form.ccuname'}) ) {
1.281 bisitz 2750: $r->print($error.&mt('Invalid login name.').' '.
2751: &mt('Only letters, numbers, periods, dashes, @, and underscores are valid.').
1.193 raeburn 2752: $end.$rtnlink);
1.27 matthew 2753: return;
2754: }
1.101 albertel 2755: if (! $env{'form.ccdomain'} ) {
1.193 raeburn 2756: $r->print($error.&mt('No domain specified').'.'.$end.$rtnlink);
1.27 matthew 2757: return;
2758: }
1.138 albertel 2759: if ( $env{'form.ccdomain'} ne
2760: &LONCAPA::clean_domain($env{'form.ccdomain'}) ) {
1.281 bisitz 2761: $r->print($error.&mt('Invalid domain name.').' '.
2762: &mt('Only letters, numbers, periods, dashes, and underscores are valid.').
1.193 raeburn 2763: $end.$rtnlink);
1.27 matthew 2764: return;
2765: }
1.219 raeburn 2766: if ($uhome eq 'no_host') {
2767: $newuser = 1;
2768: }
1.101 albertel 2769: if (! exists($env{'form.makeuser'})) {
1.29 matthew 2770: # Modifying an existing user, so check the validity of the name
2771: if ($uhome eq 'no_host') {
1.389 bisitz 2772: $r->print(
2773: $error
2774: .'<p class="LC_error">'
2775: .&mt('Unable to determine home server for [_1] in domain [_2].',
2776: '"'.$env{'form.ccuname'}.'"','"'.$env{'form.ccdomain'}.'"')
2777: .'</p>');
1.29 matthew 2778: return;
2779: }
2780: }
1.27 matthew 2781: # Determine authentication method and password for the user being modified
2782: my $amode='';
2783: my $genpwd='';
1.101 albertel 2784: if ($env{'form.login'} eq 'krb') {
1.41 albertel 2785: $amode='krb';
1.101 albertel 2786: $amode.=$env{'form.krbver'};
2787: $genpwd=$env{'form.krbarg'};
2788: } elsif ($env{'form.login'} eq 'int') {
1.27 matthew 2789: $amode='internal';
1.101 albertel 2790: $genpwd=$env{'form.intarg'};
2791: } elsif ($env{'form.login'} eq 'fsys') {
1.27 matthew 2792: $amode='unix';
1.101 albertel 2793: $genpwd=$env{'form.fsysarg'};
2794: } elsif ($env{'form.login'} eq 'loc') {
1.27 matthew 2795: $amode='localauth';
1.101 albertel 2796: $genpwd=$env{'form.locarg'};
1.27 matthew 2797: $genpwd=" " if (!$genpwd);
1.101 albertel 2798: } elsif (($env{'form.login'} eq 'nochange') ||
2799: ($env{'form.login'} eq '' )) {
1.34 matthew 2800: # There is no need to tell the user we did not change what they
2801: # did not ask us to change.
1.35 matthew 2802: # If they are creating a new user but have not specified login
2803: # information this will be caught below.
1.30 matthew 2804: } else {
1.367 golterma 2805: $r->print($error.&mt('Invalid login mode or password').$end.$rtnlink);
2806: return;
1.27 matthew 2807: }
1.164 albertel 2808:
1.188 raeburn 2809: $r->print('<h3>'.&mt('User [_1] in domain [_2]',
1.367 golterma 2810: $env{'form.ccuname'}.' ('.&Apache::loncommon::plainname($env{'form.ccuname'},
2811: $env{'form.ccdomain'}).')', $env{'form.ccdomain'}).'</h3>');
2812: my %prog_state = &Apache::lonhtmlcommon::Create_PrgWin($r,2);
1.344 bisitz 2813:
1.193 raeburn 2814: my (%alerts,%rulematch,%inst_results,%curr_rules);
1.334 raeburn 2815: my @userinfo = ('firstname','middlename','lastname','generation','permanentemail','id');
1.361 raeburn 2816: my @usertools = ('aboutme','blog','webdav','portfolio');
1.411 raeburn 2817: my @requestcourses = ('official','unofficial','community','textbook','placement');
1.362 raeburn 2818: my @requestauthor = ('requestauthor');
1.286 raeburn 2819: my ($othertitle,$usertypes,$types) =
2820: &Apache::loncommon::sorted_inst_types($env{'form.ccdomain'});
1.334 raeburn 2821: my %canmodify_status =
2822: &Apache::lonuserutils::can_modify_userinfo($context,$env{'form.ccdomain'},
2823: ['inststatus']);
1.101 albertel 2824: if ($env{'form.makeuser'}) {
1.164 albertel 2825: $r->print('<h3>'.&mt('Creating new account.').'</h3>');
1.27 matthew 2826: # Check for the authentication mode and password
2827: if (! $amode || ! $genpwd) {
1.193 raeburn 2828: $r->print($error.&mt('Invalid login mode or password').$end.$rtnlink);
1.27 matthew 2829: return;
1.18 albertel 2830: }
1.29 matthew 2831: # Determine desired host
1.101 albertel 2832: my $desiredhost = $env{'form.hserver'};
1.29 matthew 2833: if (lc($desiredhost) eq 'default') {
2834: $desiredhost = undef;
2835: } else {
1.147 albertel 2836: my %home_servers =
2837: &Apache::lonnet::get_servers($env{'form.ccdomain'},'library');
1.29 matthew 2838: if (! exists($home_servers{$desiredhost})) {
1.193 raeburn 2839: $r->print($error.&mt('Invalid home server specified').$end.$rtnlink);
2840: return;
2841: }
2842: }
2843: # Check ID format
2844: my %checkhash;
2845: my %checks = ('id' => 1);
2846: %{$checkhash{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}}} = (
1.219 raeburn 2847: 'newuser' => $newuser,
1.196 raeburn 2848: 'id' => $env{'form.cid'},
1.193 raeburn 2849: );
1.196 raeburn 2850: if ($env{'form.cid'} ne '') {
2851: &Apache::loncommon::user_rule_check(\%checkhash,\%checks,\%alerts,
2852: \%rulematch,\%inst_results,\%curr_rules);
2853: if (ref($alerts{'id'}) eq 'HASH') {
2854: if (ref($alerts{'id'}{$env{'form.ccdomain'}}) eq 'HASH') {
2855: my $domdesc =
2856: &Apache::lonnet::domain($env{'form.ccdomain'},'description');
2857: if ($alerts{'id'}{$env{'form.ccdomain'}}{$env{'form.cid'}}) {
2858: my $userchkmsg;
2859: if (ref($curr_rules{$env{'form.ccdomain'}}) eq 'HASH') {
2860: $userchkmsg =
2861: &Apache::loncommon::instrule_disallow_msg('id',
2862: $domdesc,1).
2863: &Apache::loncommon::user_rule_formats($env{'form.ccdomain'},
2864: $domdesc,$curr_rules{$env{'form.ccdomain'}}{'id'},'id');
2865: }
2866: $r->print($error.&mt('Invalid ID format').$end.
2867: $userchkmsg.$rtnlink);
2868: return;
2869: }
2870: }
1.29 matthew 2871: }
2872: }
1.367 golterma 2873: &Apache::lonhtmlcommon::Increment_PrgWin($r, \%prog_state);
1.27 matthew 2874: # Call modifyuser
2875: my $result = &Apache::lonnet::modifyuser
1.193 raeburn 2876: ($env{'form.ccdomain'},$env{'form.ccuname'},$env{'form.cid'},
1.188 raeburn 2877: $amode,$genpwd,$env{'form.cfirstname'},
2878: $env{'form.cmiddlename'},$env{'form.clastname'},
2879: $env{'form.cgeneration'},undef,$desiredhost,
2880: $env{'form.cpermanentemail'});
1.77 www 2881: $r->print(&mt('Generating user').': '.$result);
1.219 raeburn 2882: $uhome = &Apache::lonnet::homeserver($env{'form.ccuname'},
1.101 albertel 2883: $env{'form.ccdomain'});
1.334 raeburn 2884: my (%changeHash,%newcustom,%changed,%changedinfo);
1.267 raeburn 2885: if ($uhome ne 'no_host') {
1.334 raeburn 2886: if ($context eq 'domain') {
1.378 raeburn 2887: foreach my $name ('portfolio','author') {
2888: if ($env{'form.custom_'.$name.'quota'} == 1) {
2889: if ($env{'form.'.$name.'quota'} eq '') {
2890: $newcustom{$name.'quota'} = 0;
2891: } else {
2892: $newcustom{$name.'quota'} = $env{'form.'.$name.'quota'};
2893: $newcustom{$name.'quota'} =~ s/[^\d\.]//g;
2894: }
2895: if ("a_admin($newcustom{$name.'quota'},\%changeHash,$name)) {
2896: $changed{$name.'quota'} = 1;
2897: }
1.334 raeburn 2898: }
2899: }
2900: foreach my $item (@usertools) {
2901: if ($env{'form.custom'.$item} == 1) {
2902: $newcustom{$item} = $env{'form.tools_'.$item};
2903: $changed{$item} = &tool_admin($item,$newcustom{$item},
2904: \%changeHash,'tools');
2905: }
1.267 raeburn 2906: }
1.334 raeburn 2907: foreach my $item (@requestcourses) {
1.341 raeburn 2908: if ($env{'form.custom'.$item} == 1) {
2909: $newcustom{$item} = $env{'form.crsreq_'.$item};
2910: if ($env{'form.crsreq_'.$item} eq 'autolimit') {
2911: $newcustom{$item} .= '=';
1.383 raeburn 2912: $env{'form.crsreq_'.$item.'_limit'} =~ s/\D+//g;
2913: if ($env{'form.crsreq_'.$item.'_limit'}) {
1.341 raeburn 2914: $newcustom{$item} .= $env{'form.crsreq_'.$item.'_limit'};
2915: }
1.334 raeburn 2916: }
1.341 raeburn 2917: $changed{$item} = &tool_admin($item,$newcustom{$item},
2918: \%changeHash,'requestcourses');
1.334 raeburn 2919: }
1.275 raeburn 2920: }
1.362 raeburn 2921: if ($env{'form.customrequestauthor'} == 1) {
2922: $newcustom{'requestauthor'} = $env{'form.requestauthor'};
2923: $changed{'requestauthor'} = &tool_admin('requestauthor',
2924: $newcustom{'requestauthor'},
2925: \%changeHash,'requestauthor');
2926: }
1.275 raeburn 2927: }
1.334 raeburn 2928: if ($canmodify_status{'inststatus'}) {
2929: if (exists($env{'form.inststatus'})) {
2930: my @inststatuses = &Apache::loncommon::get_env_multiple('form.inststatus');
2931: if (@inststatuses > 0) {
2932: $changeHash{'inststatus'} = join(',',@inststatuses);
2933: $changed{'inststatus'} = $changeHash{'inststatus'};
1.306 raeburn 2934: }
2935: }
1.232 raeburn 2936: }
1.334 raeburn 2937: if (keys(%changed)) {
2938: foreach my $item (@userinfo) {
2939: $changeHash{$item} = $env{'form.c'.$item};
1.286 raeburn 2940: }
1.267 raeburn 2941: my $chgresult =
2942: &Apache::lonnet::put('environment',\%changeHash,
2943: $env{'form.ccdomain'},$env{'form.ccuname'});
2944: }
1.232 raeburn 2945: }
1.219 raeburn 2946: $r->print('<br />'.&mt('Home server').': '.$uhome.' '.
2947: &Apache::lonnet::hostname($uhome));
1.101 albertel 2948: } elsif (($env{'form.login'} ne 'nochange') &&
2949: ($env{'form.login'} ne '' )) {
1.27 matthew 2950: # Modify user privileges
2951: if (! $amode || ! $genpwd) {
1.193 raeburn 2952: $r->print($error.'Invalid login mode or password'.$end.$rtnlink);
1.27 matthew 2953: return;
1.20 harris41 2954: }
1.395 bisitz 2955: # Only allow authentication modification if the person has authority
1.101 albertel 2956: if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'})) {
1.20 harris41 2957: $r->print('Modifying authentication: '.
1.31 matthew 2958: &Apache::lonnet::modifyuserauth(
1.101 albertel 2959: $env{'form.ccdomain'},$env{'form.ccuname'},
1.21 harris41 2960: $amode,$genpwd));
1.102 albertel 2961: $r->print('<br />'.&mt('Home server').': '.&Apache::lonnet::homeserver
1.101 albertel 2962: ($env{'form.ccuname'},$env{'form.ccdomain'}));
1.4 www 2963: } else {
1.27 matthew 2964: # Okay, this is a non-fatal error.
1.395 bisitz 2965: $r->print($error.&mt('You do not have the authority to modify this users authentication information.').$end);
1.27 matthew 2966: }
1.28 matthew 2967: }
1.344 bisitz 2968: $r->rflush(); # Finish display of header before time consuming actions start
1.367 golterma 2969: &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state);
1.28 matthew 2970: ##
1.375 raeburn 2971: my (@userroles,%userupdate,$cnum,$cdom,$defaultcredits,%namechanged);
1.213 raeburn 2972: if ($context eq 'course') {
1.375 raeburn 2973: ($cnum,$cdom) =
2974: &Apache::lonuserutils::get_course_identity();
1.318 raeburn 2975: $crstype = &Apache::loncommon::course_type($cdom.'_'.$cnum);
1.375 raeburn 2976: if ($showcredits) {
2977: $defaultcredits = &Apache::lonuserutils::get_defaultcredits($cdom,$cnum);
2978: }
1.213 raeburn 2979: }
1.101 albertel 2980: if (! $env{'form.makeuser'} ) {
1.28 matthew 2981: # Check for need to change
2982: my %userenv = &Apache::lonnet::get
1.134 raeburn 2983: ('environment',['firstname','middlename','lastname','generation',
1.378 raeburn 2984: 'id','permanentemail','portfolioquota','authorquota','inststatus',
2985: 'tools.aboutme','tools.blog','tools.webdav','tools.portfolio',
1.361 raeburn 2986: 'requestcourses.official','requestcourses.unofficial',
1.384 raeburn 2987: 'requestcourses.community','requestcourses.textbook',
2988: 'reqcrsotherdom.official','reqcrsotherdom.unofficial',
2989: 'reqcrsotherdom.community','reqcrsotherdom.textbook',
1.427 raeburn 2990: 'reqcrsotherdom.placement','requestauthor'],
1.160 raeburn 2991: $env{'form.ccdomain'},$env{'form.ccuname'});
1.28 matthew 2992: my ($tmp) = keys(%userenv);
2993: if ($tmp =~ /^(con_lost|error)/i) {
2994: %userenv = ();
2995: }
1.206 raeburn 2996: my $no_forceid_alert;
2997: # Check to see if user information can be changed
2998: my %domconfig =
2999: &Apache::lonnet::get_dom('configuration',['usermodification'],
3000: $env{'form.ccdomain'});
1.213 raeburn 3001: my @statuses = ('active','future');
3002: my %roles = &Apache::lonnet::get_my_roles($env{'form.ccuname'},$env{'form.ccdomain'},'userroles',\@statuses,undef,$env{'request.role.domain'});
3003: my ($auname,$audom);
1.220 raeburn 3004: if ($context eq 'author') {
1.206 raeburn 3005: $auname = $env{'user.name'};
3006: $audom = $env{'user.domain'};
3007: }
3008: foreach my $item (keys(%roles)) {
1.220 raeburn 3009: my ($rolenum,$roledom,$role) = split(/:/,$item,-1);
1.206 raeburn 3010: if ($context eq 'course') {
3011: if ($cnum ne '' && $cdom ne '') {
3012: if ($rolenum eq $cnum && $roledom eq $cdom) {
3013: if (!grep(/^\Q$role\E$/,@userroles)) {
3014: push(@userroles,$role);
3015: }
3016: }
3017: }
3018: } elsif ($context eq 'author') {
3019: if ($rolenum eq $auname && $roledom eq $audom) {
3020: if (!grep(/^\Q$role\E$/,@userroles)) {
3021: push(@userroles,$role);
3022: }
3023: }
3024: }
3025: }
1.220 raeburn 3026: if ($env{'form.action'} eq 'singlestudent') {
3027: if (!grep(/^st$/,@userroles)) {
3028: push(@userroles,'st');
3029: }
3030: } else {
3031: # Check for course or co-author roles being activated or re-enabled
3032: if ($context eq 'author' || $context eq 'course') {
3033: foreach my $key (keys(%env)) {
3034: if ($context eq 'author') {
3035: if ($key=~/^form\.act_\Q$audom\E_\Q$auname\E_([^_]+)/) {
3036: if (!grep(/^\Q$1\E$/,@userroles)) {
3037: push(@userroles,$1);
3038: }
3039: } elsif ($key =~/^form\.ren\:\Q$audom\E\/\Q$auname\E_([^_]+)/) {
3040: if (!grep(/^\Q$1\E$/,@userroles)) {
3041: push(@userroles,$1);
3042: }
1.206 raeburn 3043: }
1.220 raeburn 3044: } elsif ($context eq 'course') {
3045: if ($key=~/^form\.act_\Q$cdom\E_\Q$cnum\E_([^_]+)/) {
3046: if (!grep(/^\Q$1\E$/,@userroles)) {
3047: push(@userroles,$1);
3048: }
3049: } elsif ($key =~/^form\.ren\:\Q$cdom\E\/\Q$cnum\E(\/?\w*)_([^_]+)/) {
3050: if (!grep(/^\Q$1\E$/,@userroles)) {
3051: push(@userroles,$1);
3052: }
1.206 raeburn 3053: }
3054: }
3055: }
3056: }
3057: }
3058: #Check to see if we can change personal data for the user
3059: my (@mod_disallowed,@longroles);
3060: foreach my $role (@userroles) {
3061: if ($role eq 'cr') {
3062: push(@longroles,'Custom');
3063: } else {
1.318 raeburn 3064: push(@longroles,&Apache::lonnet::plaintext($role,$crstype));
1.206 raeburn 3065: }
3066: }
1.219 raeburn 3067: my %canmodify = &Apache::lonuserutils::can_modify_userinfo($context,$env{'form.ccdomain'},\@userinfo,\@userroles);
3068: foreach my $item (@userinfo) {
1.28 matthew 3069: # Strip leading and trailing whitespace
1.203 raeburn 3070: $env{'form.c'.$item} =~ s/(\s+$|^\s+)//g;
1.219 raeburn 3071: if (!$canmodify{$item}) {
1.207 raeburn 3072: if (defined($env{'form.c'.$item})) {
3073: if ($env{'form.c'.$item} ne $userenv{$item}) {
3074: push(@mod_disallowed,$item);
3075: }
1.206 raeburn 3076: }
3077: $env{'form.c'.$item} = $userenv{$item};
3078: }
1.28 matthew 3079: }
1.259 bisitz 3080: # Check to see if we can change the Student/Employee ID
1.196 raeburn 3081: my $forceid = $env{'form.forceid'};
3082: my $recurseid = $env{'form.recurseid'};
3083: my (%alerts,%rulematch,%idinst_results,%curr_rules,%got_rules);
1.203 raeburn 3084: my %uidhash = &Apache::lonnet::idrget($env{'form.ccdomain'},
3085: $env{'form.ccuname'});
3086: if (($uidhash{$env{'form.ccuname'}}) &&
3087: ($uidhash{$env{'form.ccuname'}}!~/error\:/) &&
3088: (!$forceid)) {
3089: if ($env{'form.cid'} ne $uidhash{$env{'form.ccuname'}}) {
3090: $env{'form.cid'} = $userenv{'id'};
1.293 bisitz 3091: $no_forceid_alert = &mt('New student/employee ID does not match existing ID for this user.')
1.259 bisitz 3092: .'<br />'
3093: .&mt("Change is not permitted without checking the 'Force ID change' checkbox on the previous page.")
3094: .'<br />'."\n";
1.203 raeburn 3095: }
3096: }
3097: if ($env{'form.cid'} ne $userenv{'id'}) {
1.196 raeburn 3098: my $checkhash;
3099: my $checks = { 'id' => 1 };
3100: $checkhash->{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}} =
3101: { 'newuser' => $newuser,
3102: 'id' => $env{'form.cid'},
3103: };
3104: &Apache::loncommon::user_rule_check($checkhash,$checks,
3105: \%alerts,\%rulematch,\%idinst_results,\%curr_rules,\%got_rules);
3106: if (ref($alerts{'id'}) eq 'HASH') {
3107: if (ref($alerts{'id'}{$env{'form.ccdomain'}}) eq 'HASH') {
1.203 raeburn 3108: $env{'form.cid'} = $userenv{'id'};
1.196 raeburn 3109: }
3110: }
3111: }
1.378 raeburn 3112: my (%quotachanged,%oldquota,%newquota,%olddefquota,%newdefquota,
3113: $oldinststatus,$newinststatus,%oldisdefault,%newisdefault,%oldsettings,
1.339 raeburn 3114: %oldsettingstext,%newsettings,%newsettingstext,@disporder,
1.378 raeburn 3115: %oldsettingstatus,%newsettingstatus);
1.334 raeburn 3116: @disporder = ('inststatus');
3117: if ($env{'request.role.domain'} eq $env{'form.ccdomain'}) {
1.362 raeburn 3118: push(@disporder,'requestcourses','requestauthor');
1.334 raeburn 3119: } else {
3120: push(@disporder,'reqcrsotherdom');
3121: }
3122: push(@disporder,('quota','tools'));
1.338 raeburn 3123: $oldinststatus = $userenv{'inststatus'};
1.378 raeburn 3124: foreach my $name ('portfolio','author') {
3125: ($olddefquota{$name},$oldsettingstatus{$name}) =
3126: &Apache::loncommon::default_quota($env{'form.ccdomain'},$oldinststatus,$name);
3127: ($newdefquota{$name},$newsettingstatus{$name}) = ($olddefquota{$name},$oldsettingstatus{$name});
3128: }
1.334 raeburn 3129: my %canshow;
1.220 raeburn 3130: if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
1.334 raeburn 3131: $canshow{'quota'} = 1;
1.220 raeburn 3132: }
1.267 raeburn 3133: if (&Apache::lonnet::allowed('mut',$env{'form.ccdomain'})) {
1.334 raeburn 3134: $canshow{'tools'} = 1;
1.267 raeburn 3135: }
1.275 raeburn 3136: if (&Apache::lonnet::allowed('ccc',$env{'form.ccdomain'})) {
1.334 raeburn 3137: $canshow{'requestcourses'} = 1;
1.300 raeburn 3138: } elsif (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
1.334 raeburn 3139: $canshow{'reqcrsotherdom'} = 1;
1.275 raeburn 3140: }
1.286 raeburn 3141: if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'})) {
1.334 raeburn 3142: $canshow{'inststatus'} = 1;
1.286 raeburn 3143: }
1.362 raeburn 3144: if (&Apache::lonnet::allowed('cau',$env{'form.ccdomain'})) {
3145: $canshow{'requestauthor'} = 1;
3146: }
1.267 raeburn 3147: my (%changeHash,%changed);
1.286 raeburn 3148: if ($oldinststatus eq '') {
1.334 raeburn 3149: $oldsettings{'inststatus'} = $othertitle;
1.286 raeburn 3150: } else {
3151: if (ref($usertypes) eq 'HASH') {
1.334 raeburn 3152: $oldsettings{'inststatus'} = join(', ',map{ $usertypes->{ &unescape($_) }; } (split(/:/,$userenv{'inststatus'})));
1.286 raeburn 3153: } else {
1.334 raeburn 3154: $oldsettings{'inststatus'} = join(', ',map{ &unescape($_); } (split(/:/,$userenv{'inststatus'})));
1.286 raeburn 3155: }
3156: }
3157: $changeHash{'inststatus'} = $userenv{'inststatus'};
1.334 raeburn 3158: if ($canmodify_status{'inststatus'}) {
3159: $canshow{'inststatus'} = 1;
1.286 raeburn 3160: if (exists($env{'form.inststatus'})) {
3161: my @inststatuses = &Apache::loncommon::get_env_multiple('form.inststatus');
3162: if (@inststatuses > 0) {
3163: $newinststatus = join(':',map { &escape($_); } @inststatuses);
3164: $changeHash{'inststatus'} = $newinststatus;
3165: if ($newinststatus ne $oldinststatus) {
3166: $changed{'inststatus'} = $newinststatus;
1.378 raeburn 3167: foreach my $name ('portfolio','author') {
3168: ($newdefquota{$name},$newsettingstatus{$name}) =
3169: &Apache::loncommon::default_quota($env{'form.ccdomain'},$newinststatus,$name);
3170: }
1.286 raeburn 3171: }
3172: if (ref($usertypes) eq 'HASH') {
1.334 raeburn 3173: $newsettings{'inststatus'} = join(', ',map{ $usertypes->{$_}; } (@inststatuses));
1.286 raeburn 3174: } else {
1.337 raeburn 3175: $newsettings{'inststatus'} = join(', ',@inststatuses);
1.286 raeburn 3176: }
1.334 raeburn 3177: }
3178: } else {
3179: $newinststatus = '';
3180: $changeHash{'inststatus'} = $newinststatus;
3181: $newsettings{'inststatus'} = $othertitle;
3182: if ($newinststatus ne $oldinststatus) {
3183: $changed{'inststatus'} = $changeHash{'inststatus'};
1.378 raeburn 3184: foreach my $name ('portfolio','author') {
3185: ($newdefquota{$name},$newsettingstatus{$name}) =
3186: &Apache::loncommon::default_quota($env{'form.ccdomain'},$newinststatus,$name);
3187: }
1.286 raeburn 3188: }
3189: }
1.334 raeburn 3190: } elsif ($context ne 'selfcreate') {
3191: $canshow{'inststatus'} = 1;
1.337 raeburn 3192: $newsettings{'inststatus'} = $oldsettings{'inststatus'};
1.286 raeburn 3193: }
1.378 raeburn 3194: foreach my $name ('portfolio','author') {
3195: $changeHash{$name.'quota'} = $userenv{$name.'quota'};
3196: }
1.334 raeburn 3197: if ($context eq 'domain') {
1.378 raeburn 3198: foreach my $name ('portfolio','author') {
3199: if ($userenv{$name.'quota'} ne '') {
3200: $oldquota{$name} = $userenv{$name.'quota'};
3201: if ($env{'form.custom_'.$name.'quota'} == 1) {
3202: if ($env{'form.'.$name.'quota'} eq '') {
3203: $newquota{$name} = 0;
3204: } else {
3205: $newquota{$name} = $env{'form.'.$name.'quota'};
3206: $newquota{$name} =~ s/[^\d\.]//g;
3207: }
3208: if ($newquota{$name} != $oldquota{$name}) {
3209: if ("a_admin($newquota{$name},\%changeHash,$name)) {
3210: $changed{$name.'quota'} = 1;
3211: }
3212: }
1.334 raeburn 3213: } else {
1.378 raeburn 3214: if ("a_admin('',\%changeHash,$name)) {
3215: $changed{$name.'quota'} = 1;
3216: $newquota{$name} = $newdefquota{$name};
3217: $newisdefault{$name} = 1;
3218: }
1.334 raeburn 3219: }
1.149 raeburn 3220: } else {
1.378 raeburn 3221: $oldisdefault{$name} = 1;
3222: $oldquota{$name} = $olddefquota{$name};
3223: if ($env{'form.custom_'.$name.'quota'} == 1) {
3224: if ($env{'form.'.$name.'quota'} eq '') {
3225: $newquota{$name} = 0;
3226: } else {
3227: $newquota{$name} = $env{'form.'.$name.'quota'};
3228: $newquota{$name} =~ s/[^\d\.]//g;
3229: }
3230: if ("a_admin($newquota{$name},\%changeHash,$name)) {
3231: $changed{$name.'quota'} = 1;
3232: }
1.334 raeburn 3233: } else {
1.378 raeburn 3234: $newquota{$name} = $newdefquota{$name};
3235: $newisdefault{$name} = 1;
1.334 raeburn 3236: }
1.378 raeburn 3237: }
3238: if ($oldisdefault{$name}) {
3239: $oldsettingstext{'quota'}{$name} = &get_defaultquota_text($oldsettingstatus{$name});
1.383 raeburn 3240: } else {
3241: $oldsettingstext{'quota'}{$name} = &mt('custom quota: [_1] MB',$oldquota{$name});
1.378 raeburn 3242: }
3243: if ($newisdefault{$name}) {
3244: $newsettingstext{'quota'}{$name} = &get_defaultquota_text($newsettingstatus{$name});
1.383 raeburn 3245: } else {
3246: $newsettingstext{'quota'}{$name} = &mt('custom quota: [_1] MB',$newquota{$name});
1.134 raeburn 3247: }
3248: }
1.334 raeburn 3249: &tool_changes('tools',\@usertools,\%oldsettings,\%oldsettingstext,\%userenv,
3250: \%changeHash,\%changed,\%newsettings,\%newsettingstext);
3251: if ($env{'form.ccdomain'} eq $env{'request.role.domain'}) {
3252: &tool_changes('requestcourses',\@requestcourses,\%oldsettings,\%oldsettingstext,
3253: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
1.384 raeburn 3254: &tool_changes('requestauthor',\@requestauthor,\%oldsettings,\%oldsettingstext,
3255: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
1.149 raeburn 3256: } else {
1.334 raeburn 3257: &tool_changes('reqcrsotherdom',\@requestcourses,\%oldsettings,\%oldsettingstext,
3258: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
1.149 raeburn 3259: }
3260: }
1.334 raeburn 3261: foreach my $item (@userinfo) {
3262: if ($env{'form.c'.$item} ne $userenv{$item}) {
3263: $namechanged{$item} = 1;
3264: }
1.204 raeburn 3265: }
1.378 raeburn 3266: foreach my $name ('portfolio','author') {
1.390 bisitz 3267: $oldsettings{'quota'}{$name} = &mt('[_1] MB',$oldquota{$name});
3268: $newsettings{'quota'}{$name} = &mt('[_1] MB',$newquota{$name});
1.378 raeburn 3269: }
1.334 raeburn 3270: if ((keys(%namechanged) > 0) || (keys(%changed) > 0)) {
1.267 raeburn 3271: my ($chgresult,$namechgresult);
3272: if (keys(%changed) > 0) {
3273: $chgresult =
1.204 raeburn 3274: &Apache::lonnet::put('environment',\%changeHash,
3275: $env{'form.ccdomain'},$env{'form.ccuname'});
1.267 raeburn 3276: if ($chgresult eq 'ok') {
3277: if (($env{'user.name'} eq $env{'form.ccuname'}) &&
3278: ($env{'user.domain'} eq $env{'form.ccdomain'})) {
1.270 raeburn 3279: my %newenvhash;
3280: foreach my $key (keys(%changed)) {
1.411 raeburn 3281: if (($key eq 'official') || ($key eq 'unofficial') ||
3282: ($key eq 'community') || ($key eq 'textbook') ||
3283: ($key eq 'placement')) {
1.279 raeburn 3284: $newenvhash{'environment.requestcourses.'.$key} =
3285: $changeHash{'requestcourses.'.$key};
1.362 raeburn 3286: if ($changeHash{'requestcourses.'.$key}) {
1.332 raeburn 3287: $newenvhash{'environment.canrequest.'.$key} = 1;
1.279 raeburn 3288: } else {
3289: $newenvhash{'environment.canrequest.'.$key} =
3290: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
3291: $key,'reload','requestcourses');
3292: }
1.362 raeburn 3293: } elsif ($key eq 'requestauthor') {
3294: $newenvhash{'environment.'.$key} = $changeHash{$key};
3295: if ($changeHash{$key}) {
3296: $newenvhash{'environment.canrequest.author'} = 1;
3297: } else {
3298: $newenvhash{'environment.canrequest.author'} =
3299: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
3300: $key,'reload','requestauthor');
3301: }
1.275 raeburn 3302: } elsif ($key ne 'quota') {
1.270 raeburn 3303: $newenvhash{'environment.tools.'.$key} =
3304: $changeHash{'tools.'.$key};
1.279 raeburn 3305: if ($changeHash{'tools.'.$key} ne '') {
3306: $newenvhash{'environment.availabletools.'.$key} =
3307: $changeHash{'tools.'.$key};
3308: } else {
3309: $newenvhash{'environment.availabletools.'.$key} =
1.367 golterma 3310: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
3311: $key,'reload','tools');
1.279 raeburn 3312: }
1.270 raeburn 3313: }
3314: }
1.271 raeburn 3315: if (keys(%newenvhash)) {
3316: &Apache::lonnet::appenv(\%newenvhash);
3317: }
1.267 raeburn 3318: }
3319: }
1.204 raeburn 3320: }
1.334 raeburn 3321: if (keys(%namechanged) > 0) {
1.337 raeburn 3322: foreach my $field (@userinfo) {
3323: $changeHash{$field} = $env{'form.c'.$field};
3324: }
3325: # Make the change
1.204 raeburn 3326: $namechgresult =
3327: &Apache::lonnet::modifyuser($env{'form.ccdomain'},
3328: $env{'form.ccuname'},$changeHash{'id'},undef,undef,
3329: $changeHash{'firstname'},$changeHash{'middlename'},
3330: $changeHash{'lastname'},$changeHash{'generation'},
1.337 raeburn 3331: $changeHash{'id'},undef,$changeHash{'permanentemail'},undef,\@userinfo);
1.220 raeburn 3332: %userupdate = (
3333: lastname => $env{'form.clastname'},
3334: middlename => $env{'form.cmiddlename'},
3335: firstname => $env{'form.cfirstname'},
3336: generation => $env{'form.cgeneration'},
3337: id => $env{'form.cid'},
3338: );
1.204 raeburn 3339: }
1.334 raeburn 3340: if (((keys(%namechanged) > 0) && $namechgresult eq 'ok') ||
1.267 raeburn 3341: ((keys(%changed) > 0) && $chgresult eq 'ok')) {
1.28 matthew 3342: # Tell the user we changed the name
1.334 raeburn 3343: &display_userinfo($r,1,\@disporder,\%canshow,\@requestcourses,
1.362 raeburn 3344: \@usertools,\@requestauthor,\%userenv,\%changed,\%namechanged,
1.334 raeburn 3345: \%oldsettings, \%oldsettingstext,\%newsettings,
3346: \%newsettingstext);
1.203 raeburn 3347: if ($env{'form.cid'} ne $userenv{'id'}) {
3348: &Apache::lonnet::idput($env{'form.ccdomain'},
1.407 raeburn 3349: {$env{'form.ccuname'} => $env{'form.cid'}},$uhome,'ids');
1.203 raeburn 3350: if (($recurseid) &&
3351: (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'}))) {
3352: my $idresult =
3353: &Apache::lonuserutils::propagate_id_change(
3354: $env{'form.ccuname'},$env{'form.ccdomain'},
3355: \%userupdate);
3356: $r->print('<br />'.$idresult.'<br />');
3357: }
1.196 raeburn 3358: }
1.149 raeburn 3359: if (($env{'form.ccdomain'} eq $env{'user.domain'}) &&
3360: ($env{'form.ccuname'} eq $env{'user.name'})) {
3361: my %newenvhash;
3362: foreach my $key (keys(%changeHash)) {
3363: $newenvhash{'environment.'.$key} = $changeHash{$key};
3364: }
1.238 raeburn 3365: &Apache::lonnet::appenv(\%newenvhash);
1.149 raeburn 3366: }
1.28 matthew 3367: } else { # error occurred
1.389 bisitz 3368: $r->print(
3369: '<p class="LC_error">'
3370: .&mt('Unable to successfully change environment for [_1] in domain [_2].',
3371: '"'.$env{'form.ccuname'}.'"',
3372: '"'.$env{'form.ccdomain'}.'"')
3373: .'</p>');
1.28 matthew 3374: }
1.334 raeburn 3375: } else { # End of if ($env ... ) logic
1.275 raeburn 3376: # They did not want to change the users name, quota, tool availability,
3377: # or ability to request creation of courses,
1.267 raeburn 3378: # but we can still tell them what the name and quota and availabilities are
1.334 raeburn 3379: &display_userinfo($r,undef,\@disporder,\%canshow,\@requestcourses,
1.362 raeburn 3380: \@usertools,\@requestauthor,\%userenv,\%changed,\%namechanged,\%oldsettings,
1.334 raeburn 3381: \%oldsettingstext,\%newsettings,\%newsettingstext);
1.28 matthew 3382: }
1.206 raeburn 3383: if (@mod_disallowed) {
3384: my ($rolestr,$contextname);
3385: if (@longroles > 0) {
3386: $rolestr = join(', ',@longroles);
3387: } else {
3388: $rolestr = &mt('No roles');
3389: }
3390: if ($context eq 'course') {
1.399 bisitz 3391: $contextname = 'course';
1.206 raeburn 3392: } elsif ($context eq 'author') {
1.399 bisitz 3393: $contextname = 'co-author';
1.206 raeburn 3394: }
3395: $r->print(&mt('The following fields were not updated: ').'<ul>');
3396: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
3397: foreach my $field (@mod_disallowed) {
3398: $r->print('<li>'.$fieldtitles{$field}.'</li>'."\n");
3399: }
1.207 raeburn 3400: $r->print('</ul>');
3401: if (@mod_disallowed == 1) {
1.399 bisitz 3402: $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 3403: } else {
1.399 bisitz 3404: $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 3405: }
1.292 bisitz 3406: my $helplink = 'javascript:helpMenu('."'display'".')';
3407: $r->print('<span class="LC_cusr_emph">'.$rolestr.'</span><br />'
3408: .&mt('Please contact your [_1]helpdesk[_2] for more information.'
3409: ,'<a href="'.$helplink.'">','</a>')
3410: .'<br />');
1.206 raeburn 3411: }
1.259 bisitz 3412: $r->print('<span class="LC_warning">'
3413: .$no_forceid_alert
3414: .&Apache::lonuserutils::print_namespacing_alerts($env{'form.ccdomain'},\%alerts,\%curr_rules)
3415: .'</span>');
1.4 www 3416: }
1.367 golterma 3417: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
1.220 raeburn 3418: if ($env{'form.action'} eq 'singlestudent') {
1.375 raeburn 3419: &enroll_single_student($r,$uhome,$amode,$genpwd,$now,$newuser,$context,
3420: $crstype,$showcredits,$defaultcredits);
1.386 bisitz 3421: my $linktext = ($crstype eq 'Community' ?
3422: &mt('Enroll Another Member') : &mt('Enroll Another Student'));
3423: $r->print(
3424: &Apache::lonhtmlcommon::actionbox([
3425: '<a href="javascript:backPage(document.userupdate)">'
3426: .($crstype eq 'Community' ?
3427: &mt('Enroll Another Member') : &mt('Enroll Another Student'))
3428: .'</a>']));
1.220 raeburn 3429: } else {
1.375 raeburn 3430: my @rolechanges = &update_roles($r,$context,$showcredits);
1.334 raeburn 3431: if (keys(%namechanged) > 0) {
1.220 raeburn 3432: if ($context eq 'course') {
3433: if (@userroles > 0) {
1.225 raeburn 3434: if ((@rolechanges == 0) ||
3435: (!(grep(/^st$/,@rolechanges)))) {
3436: if (grep(/^st$/,@userroles)) {
3437: my $classlistupdated =
3438: &Apache::lonuserutils::update_classlist($cdom,
1.220 raeburn 3439: $cnum,$env{'form.ccdomain'},
3440: $env{'form.ccuname'},\%userupdate);
1.225 raeburn 3441: }
1.220 raeburn 3442: }
3443: }
3444: }
3445: }
1.226 raeburn 3446: my $userinfo = &Apache::loncommon::plainname($env{'form.ccuname'},
1.233 raeburn 3447: $env{'form.ccdomain'});
3448: if ($env{'form.popup'}) {
3449: $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a></p>');
3450: } else {
1.367 golterma 3451: $r->print('<br />'.&Apache::lonhtmlcommon::actionbox(['<a href="javascript:backPage(document.userupdate,'."'$env{'form.prevphase'}','modify'".')">'
3452: .&mt('Modify this user: [_1]','<span class="LC_cusr_emph">'.$env{'form.ccuname'}.':'.$env{'form.ccdomain'}.' ('.$userinfo.')</span>').'</a>',
3453: '<a href="javascript:backPage(document.userupdate)">'.&mt('Create/Modify Another User').'</a>']));
1.233 raeburn 3454: }
1.220 raeburn 3455: }
3456: }
3457:
1.334 raeburn 3458: sub display_userinfo {
1.362 raeburn 3459: my ($r,$changed,$order,$canshow,$requestcourses,$usertools,$requestauthor,
3460: $userenv,$changedhash,$namechangedhash,$oldsetting,$oldsettingtext,
1.334 raeburn 3461: $newsetting,$newsettingtext) = @_;
3462: return unless (ref($order) eq 'ARRAY' &&
3463: ref($canshow) eq 'HASH' &&
3464: ref($requestcourses) eq 'ARRAY' &&
1.362 raeburn 3465: ref($requestauthor) eq 'ARRAY' &&
1.334 raeburn 3466: ref($usertools) eq 'ARRAY' &&
3467: ref($userenv) eq 'HASH' &&
3468: ref($changedhash) eq 'HASH' &&
3469: ref($oldsetting) eq 'HASH' &&
3470: ref($oldsettingtext) eq 'HASH' &&
3471: ref($newsetting) eq 'HASH' &&
3472: ref($newsettingtext) eq 'HASH');
3473: my %lt=&Apache::lonlocal::texthash(
1.372 raeburn 3474: 'ui' => 'User Information',
1.334 raeburn 3475: 'uic' => 'User Information Changed',
3476: 'firstname' => 'First Name',
3477: 'middlename' => 'Middle Name',
3478: 'lastname' => 'Last Name',
3479: 'generation' => 'Generation',
3480: 'id' => 'Student/Employee ID',
3481: 'permanentemail' => 'Permanent e-mail address',
1.378 raeburn 3482: 'portfolioquota' => 'Disk space allocated to portfolio files',
1.385 bisitz 3483: 'authorquota' => 'Disk space allocated to Authoring Space',
1.334 raeburn 3484: 'blog' => 'Blog Availability',
1.361 raeburn 3485: 'webdav' => 'WebDAV Availability',
1.334 raeburn 3486: 'aboutme' => 'Personal Information Page Availability',
3487: 'portfolio' => 'Portfolio Availability',
3488: 'official' => 'Can Request Official Courses',
3489: 'unofficial' => 'Can Request Unofficial Courses',
3490: 'community' => 'Can Request Communities',
1.384 raeburn 3491: 'textbook' => 'Can Request Textbook Courses',
1.411 raeburn 3492: 'placement' => 'Can Request Placement Tests',
1.362 raeburn 3493: 'requestauthor' => 'Can Request Author Role',
1.334 raeburn 3494: 'inststatus' => "Affiliation",
3495: 'prvs' => 'Previous Value:',
3496: 'chto' => 'Changed To:'
3497: );
3498: if ($changed) {
1.372 raeburn 3499: $r->print('<h3>'.$lt{'uic'}.'</h3>'.
1.367 golterma 3500: &Apache::loncommon::start_data_table().
3501: &Apache::loncommon::start_data_table_header_row());
1.334 raeburn 3502: $r->print("<th> </th>\n");
1.367 golterma 3503: $r->print('<th><b>'.$lt{'prvs'}.'</b></th>');
3504: $r->print('<th><span class="LC_nobreak"><b>'.$lt{'chto'}.'</b></span></th>');
3505: $r->print(&Apache::loncommon::end_data_table_header_row());
3506: my @userinfo = ('firstname','middlename','lastname','generation','permanentemail','id');
3507:
1.334 raeburn 3508: foreach my $item (@userinfo) {
3509: my $value = $env{'form.c'.$item};
1.367 golterma 3510: #show changes only:
1.383 raeburn 3511: unless ($value eq $userenv->{$item}){
1.367 golterma 3512: $r->print(&Apache::loncommon::start_data_table_row());
3513: $r->print("<td>$lt{$item}</td>\n");
1.383 raeburn 3514: $r->print("<td>".$userenv->{$item}."</td>\n");
1.367 golterma 3515: $r->print("<td>$value </td>\n");
3516: $r->print(&Apache::loncommon::end_data_table_row());
1.334 raeburn 3517: }
3518: }
3519: foreach my $entry (@{$order}) {
1.383 raeburn 3520: if ($canshow->{$entry}) {
3521: if (($entry eq 'requestcourses') || ($entry eq 'reqcrsotherdom') || ($entry eq 'requestauthor')) {
3522: my @items;
3523: if ($entry eq 'requestauthor') {
3524: @items = ($entry);
3525: } else {
3526: @items = @{$requestcourses};
1.384 raeburn 3527: }
1.383 raeburn 3528: foreach my $item (@items) {
3529: if (($newsetting->{$item} ne $oldsetting->{$item}) ||
3530: ($newsettingtext->{$item} ne $oldsettingtext->{$item})) {
3531: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3532: $r->print("<td>$lt{$item}</td>\n");
3533: $r->print("<td>".$oldsetting->{$item});
3534: if ($oldsettingtext->{$item}) {
3535: if ($oldsetting->{$item}) {
3536: $r->print(' -- ');
3537: }
3538: $r->print($oldsettingtext->{$item});
3539: }
3540: $r->print("</td>\n");
3541: $r->print("<td>".$newsetting->{$item});
3542: if ($newsettingtext->{$item}) {
3543: if ($newsetting->{$item}) {
3544: $r->print(' -- ');
3545: }
3546: $r->print($newsettingtext->{$item});
3547: }
3548: $r->print("</td>\n");
3549: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.334 raeburn 3550: }
3551: }
3552: } elsif ($entry eq 'tools') {
3553: foreach my $item (@{$usertools}) {
1.383 raeburn 3554: if ($newsetting->{$item} ne $oldsetting->{$item}) {
3555: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3556: $r->print("<td>$lt{$item}</td>\n");
3557: $r->print("<td>".$oldsetting->{$item}.' '.$oldsettingtext->{$item}."</td>\n");
3558: $r->print("<td>".$newsetting->{$item}.' '.$newsettingtext->{$item}."</td>\n");
3559: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.334 raeburn 3560: }
3561: }
1.378 raeburn 3562: } elsif ($entry eq 'quota') {
3563: if ((ref($oldsetting->{$entry}) eq 'HASH') && (ref($oldsettingtext->{$entry}) eq 'HASH') &&
3564: (ref($newsetting->{$entry}) eq 'HASH') && (ref($newsettingtext->{$entry}) eq 'HASH')) {
3565: foreach my $name ('portfolio','author') {
1.383 raeburn 3566: if ($newsetting->{$entry}->{$name} ne $oldsetting->{$entry}->{$name}) {
3567: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3568: $r->print("<td>$lt{$name.$entry}</td>\n");
3569: $r->print("<td>".$oldsettingtext->{$entry}->{$name}."</td>\n");
3570: $r->print("<td>".$newsettingtext->{$entry}->{$name}."</td>\n");
3571: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.378 raeburn 3572: }
3573: }
3574: }
1.334 raeburn 3575: } else {
1.383 raeburn 3576: if ($newsetting->{$entry} ne $oldsetting->{$entry}) {
3577: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3578: $r->print("<td>$lt{$entry}</td>\n");
3579: $r->print("<td>".$oldsetting->{$entry}.' '.$oldsettingtext->{$entry}."</td>\n");
3580: $r->print("<td>".$newsetting->{$entry}.' '.$newsettingtext->{$entry}."</td>\n");
3581: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.334 raeburn 3582: }
3583: }
3584: }
3585: }
1.367 golterma 3586: $r->print(&Apache::loncommon::end_data_table().'<br />');
1.372 raeburn 3587: } else {
3588: $r->print('<h3>'.$lt{'ui'}.'</h3>'.
3589: '<p>'.&mt('No changes made to user information').'</p>');
1.334 raeburn 3590: }
3591: return;
3592: }
3593:
1.275 raeburn 3594: sub tool_changes {
3595: my ($context,$usertools,$oldaccess,$oldaccesstext,$userenv,$changeHash,
3596: $changed,$newaccess,$newaccesstext) = @_;
3597: if (!((ref($usertools) eq 'ARRAY') && (ref($oldaccess) eq 'HASH') &&
3598: (ref($oldaccesstext) eq 'HASH') && (ref($userenv) eq 'HASH') &&
3599: (ref($changeHash) eq 'HASH') && (ref($changed) eq 'HASH') &&
3600: (ref($newaccess) eq 'HASH') && (ref($newaccesstext) eq 'HASH'))) {
3601: return;
3602: }
1.383 raeburn 3603: my %reqdisplay = &requestchange_display();
1.300 raeburn 3604: if ($context eq 'reqcrsotherdom') {
1.309 raeburn 3605: my @options = ('approval','validate','autolimit');
1.306 raeburn 3606: my $optregex = join('|',@options);
1.300 raeburn 3607: my $cdom = $env{'request.role.domain'};
3608: foreach my $tool (@{$usertools}) {
1.383 raeburn 3609: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
1.314 raeburn 3610: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
1.300 raeburn 3611: $changeHash->{$context.'.'.$tool} = $userenv->{$context.'.'.$tool};
1.383 raeburn 3612: my ($newop,$limit);
1.314 raeburn 3613: if ($env{'form.'.$context.'_'.$tool}) {
3614: $newop = $env{'form.'.$context.'_'.$tool};
3615: if ($newop eq 'autolimit') {
1.383 raeburn 3616: $limit = $env{'form.'.$context.'_'.$tool.'_limit'};
1.314 raeburn 3617: $limit =~ s/\D+//g;
3618: $newop .= '='.$limit;
3619: }
3620: }
1.300 raeburn 3621: if ($userenv->{$context.'.'.$tool} eq '') {
1.314 raeburn 3622: if ($newop) {
3623: $changed->{$tool}=&tool_admin($tool,$cdom.':'.$newop,
1.300 raeburn 3624: $changeHash,$context);
3625: if ($changed->{$tool}) {
1.383 raeburn 3626: if ($newop =~ /^autolimit/) {
3627: if ($limit) {
3628: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3629: } else {
3630: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3631: }
3632: } else {
3633: $newaccesstext->{$tool} = $reqdisplay{$newop};
3634: }
1.300 raeburn 3635: } else {
3636: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
3637: }
3638: }
3639: } else {
3640: my @curr = split(',',$userenv->{$context.'.'.$tool});
3641: my @new;
3642: my $changedoms;
1.314 raeburn 3643: foreach my $req (@curr) {
3644: if ($req =~ /^\Q$cdom\E\:($optregex\=?\d*)$/) {
3645: my $oldop = $1;
1.383 raeburn 3646: if ($oldop =~ /^autolimit=(\d*)/) {
3647: my $limit = $1;
3648: if ($limit) {
3649: $oldaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3650: } else {
3651: $oldaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3652: }
3653: } else {
3654: $oldaccesstext->{$tool} = $reqdisplay{$oldop};
3655: }
1.314 raeburn 3656: if ($oldop ne $newop) {
3657: $changedoms = 1;
3658: foreach my $item (@curr) {
3659: my ($reqdom,$option) = split(':',$item);
3660: unless ($reqdom eq $cdom) {
3661: push(@new,$item);
3662: }
3663: }
3664: if ($newop) {
3665: push(@new,$cdom.':'.$newop);
1.300 raeburn 3666: }
1.314 raeburn 3667: @new = sort(@new);
1.300 raeburn 3668: }
1.314 raeburn 3669: last;
1.300 raeburn 3670: }
1.314 raeburn 3671: }
3672: if ((!$changedoms) && ($newop)) {
1.300 raeburn 3673: $changedoms = 1;
1.306 raeburn 3674: @new = sort(@curr,$cdom.':'.$newop);
1.300 raeburn 3675: }
3676: if ($changedoms) {
1.314 raeburn 3677: my $newdomstr;
1.300 raeburn 3678: if (@new) {
3679: $newdomstr = join(',',@new);
3680: }
3681: $changed->{$tool}=&tool_admin($tool,$newdomstr,$changeHash,
3682: $context);
3683: if ($changed->{$tool}) {
3684: if ($env{'form.'.$context.'_'.$tool}) {
1.306 raeburn 3685: if ($env{'form.'.$context.'_'.$tool} eq 'autolimit') {
1.314 raeburn 3686: my $limit = $env{'form.'.$context.'_'.$tool.'_limit'};
3687: $limit =~ s/\D+//g;
3688: if ($limit) {
1.383 raeburn 3689: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
1.314 raeburn 3690: } else {
1.383 raeburn 3691: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
1.306 raeburn 3692: }
1.314 raeburn 3693: } else {
1.306 raeburn 3694: $newaccesstext->{$tool} = $reqdisplay{$env{'form.'.$context.'_'.$tool}};
3695: }
1.300 raeburn 3696: } else {
1.383 raeburn 3697: $newaccesstext->{$tool} = &mt("availability set to 'off'");
1.300 raeburn 3698: }
3699: }
3700: }
3701: }
3702: }
3703: return;
3704: }
1.275 raeburn 3705: foreach my $tool (@{$usertools}) {
1.383 raeburn 3706: my ($newval,$limit,$envkey);
1.362 raeburn 3707: $envkey = $context.'.'.$tool;
1.306 raeburn 3708: if ($context eq 'requestcourses') {
3709: $newval = $env{'form.crsreq_'.$tool};
3710: if ($newval eq 'autolimit') {
1.383 raeburn 3711: $limit = $env{'form.crsreq_'.$tool.'_limit'};
3712: $limit =~ s/\D+//g;
3713: $newval .= '='.$limit;
1.306 raeburn 3714: }
1.362 raeburn 3715: } elsif ($context eq 'requestauthor') {
3716: $newval = $env{'form.'.$context};
3717: $envkey = $context;
1.314 raeburn 3718: } else {
1.306 raeburn 3719: $newval = $env{'form.'.$context.'_'.$tool};
3720: }
1.362 raeburn 3721: if ($userenv->{$envkey} ne '') {
1.275 raeburn 3722: $oldaccess->{$tool} = &mt('custom');
1.383 raeburn 3723: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3724: if ($userenv->{$envkey} =~ /^autolimit=(\d*)$/) {
3725: my $currlimit = $1;
3726: if ($currlimit eq '') {
3727: $oldaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3728: } else {
3729: $oldaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$currlimit);
3730: }
3731: } elsif ($userenv->{$envkey}) {
3732: $oldaccesstext->{$tool} = $reqdisplay{$userenv->{$envkey}};
3733: } else {
3734: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
3735: }
1.275 raeburn 3736: } else {
1.383 raeburn 3737: if ($userenv->{$envkey}) {
3738: $oldaccesstext->{$tool} = &mt("availability set to 'on'");
3739: } else {
3740: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
3741: }
1.275 raeburn 3742: }
1.362 raeburn 3743: $changeHash->{$envkey} = $userenv->{$envkey};
1.275 raeburn 3744: if ($env{'form.custom'.$tool} == 1) {
1.362 raeburn 3745: if ($newval ne $userenv->{$envkey}) {
1.306 raeburn 3746: $changed->{$tool} = &tool_admin($tool,$newval,$changeHash,
3747: $context);
1.275 raeburn 3748: if ($changed->{$tool}) {
3749: $newaccess->{$tool} = &mt('custom');
1.383 raeburn 3750: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3751: if ($newval =~ /^autolimit/) {
3752: if ($limit) {
3753: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3754: } else {
3755: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3756: }
3757: } elsif ($newval) {
3758: $newaccesstext->{$tool} = $reqdisplay{$newval};
3759: } else {
3760: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3761: }
1.275 raeburn 3762: } else {
1.383 raeburn 3763: if ($newval) {
3764: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3765: } else {
3766: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3767: }
1.275 raeburn 3768: }
3769: } else {
3770: $newaccess->{$tool} = $oldaccess->{$tool};
1.383 raeburn 3771: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3772: if ($newval =~ /^autolimit/) {
3773: if ($limit) {
3774: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3775: } else {
3776: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3777: }
3778: } elsif ($newval) {
3779: $newaccesstext->{$tool} = $reqdisplay{$newval};
3780: } else {
3781: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3782: }
1.275 raeburn 3783: } else {
1.383 raeburn 3784: if ($userenv->{$context.'.'.$tool}) {
3785: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3786: } else {
3787: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3788: }
1.275 raeburn 3789: }
3790: }
3791: } else {
3792: $newaccess->{$tool} = $oldaccess->{$tool};
3793: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
3794: }
3795: } else {
3796: $changed->{$tool} = &tool_admin($tool,'',$changeHash,$context);
3797: if ($changed->{$tool}) {
3798: $newaccess->{$tool} = &mt('default');
3799: } else {
3800: $newaccess->{$tool} = $oldaccess->{$tool};
1.383 raeburn 3801: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3802: if ($newval =~ /^autolimit/) {
3803: if ($limit) {
3804: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3805: } else {
3806: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3807: }
3808: } elsif ($newval) {
3809: $newaccesstext->{$tool} = $reqdisplay{$newval};
3810: } else {
3811: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3812: }
1.275 raeburn 3813: } else {
1.383 raeburn 3814: if ($userenv->{$context.'.'.$tool}) {
3815: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3816: } else {
3817: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3818: }
1.275 raeburn 3819: }
3820: }
3821: }
3822: } else {
3823: $oldaccess->{$tool} = &mt('default');
3824: if ($env{'form.custom'.$tool} == 1) {
1.306 raeburn 3825: $changed->{$tool} = &tool_admin($tool,$newval,$changeHash,
3826: $context);
1.275 raeburn 3827: if ($changed->{$tool}) {
3828: $newaccess->{$tool} = &mt('custom');
1.383 raeburn 3829: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3830: if ($newval =~ /^autolimit/) {
3831: if ($limit) {
3832: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3833: } else {
3834: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3835: }
3836: } elsif ($newval) {
3837: $newaccesstext->{$tool} = $reqdisplay{$newval};
3838: } else {
3839: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3840: }
1.275 raeburn 3841: } else {
1.383 raeburn 3842: if ($newval) {
3843: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3844: } else {
3845: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3846: }
1.275 raeburn 3847: }
3848: } else {
3849: $newaccess->{$tool} = $oldaccess->{$tool};
3850: }
3851: } else {
3852: $newaccess->{$tool} = $oldaccess->{$tool};
3853: }
3854: }
3855: }
3856: return;
3857: }
3858:
1.220 raeburn 3859: sub update_roles {
1.375 raeburn 3860: my ($r,$context,$showcredits) = @_;
1.4 www 3861: my $now=time;
1.225 raeburn 3862: my @rolechanges;
1.220 raeburn 3863: my %disallowed;
1.73 sakharuk 3864: $r->print('<h3>'.&mt('Modifying Roles').'</h3>');
1.404 raeburn 3865: foreach my $key (keys(%env)) {
1.135 raeburn 3866: next if (! $env{$key});
1.190 raeburn 3867: next if ($key eq 'form.action');
1.27 matthew 3868: # Revoke roles
1.135 raeburn 3869: if ($key=~/^form\.rev/) {
3870: if ($key=~/^form\.rev\:([^\_]+)\_([^\_\.]+)$/) {
1.64 www 3871: # Revoke standard role
1.170 albertel 3872: my ($scope,$role) = ($1,$2);
3873: my $result =
3874: &Apache::lonnet::revokerole($env{'form.ccdomain'},
3875: $env{'form.ccuname'},
1.239 raeburn 3876: $scope,$role,'','',$context);
1.367 golterma 3877: $r->print(&Apache::lonhtmlcommon::confirm_success(
1.369 bisitz 3878: &mt('Revoking [_1] in [_2]',
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.170 albertel 3885: if ($role eq 'st') {
1.202 raeburn 3886: my $result =
1.198 raeburn 3887: &Apache::lonuserutils::classlist_drop($scope,
3888: $env{'form.ccuname'},$env{'form.ccdomain'},
1.202 raeburn 3889: $now);
1.367 golterma 3890: $r->print(&Apache::lonhtmlcommon::confirm_success($result));
1.53 www 3891: }
1.225 raeburn 3892: if (!grep(/^\Q$role\E$/,@rolechanges)) {
3893: push(@rolechanges,$role);
3894: }
1.196 raeburn 3895: }
1.195 raeburn 3896: if ($key=~m{^form\.rev\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}s) {
1.64 www 3897: # Revoke custom role
1.369 bisitz 3898: my $result = &Apache::lonnet::revokecustomrole(
3899: $env{'form.ccdomain'},$env{'form.ccuname'},$1,$2,$3,$4,'','',$context);
1.367 golterma 3900: $r->print(&Apache::lonhtmlcommon::confirm_success(
1.369 bisitz 3901: &mt('Revoking custom role [_1] by [_2] in [_3]',
1.372 raeburn 3902: $4,$3.':'.$2,&Apache::loncommon::show_role_extent($1,$context,'cr')),
1.369 bisitz 3903: $result ne 'ok').'<br />');
3904: if ($result ne "ok") {
3905: $r->print(&mt('Error: [_1]',$result).'<br />');
3906: }
1.225 raeburn 3907: if (!grep(/^cr$/,@rolechanges)) {
3908: push(@rolechanges,'cr');
3909: }
1.64 www 3910: }
1.135 raeburn 3911: } elsif ($key=~/^form\.del/) {
3912: if ($key=~/^form\.del\:([^\_]+)\_([^\_\.]+)$/) {
1.116 raeburn 3913: # Delete standard role
1.170 albertel 3914: my ($scope,$role) = ($1,$2);
3915: my $result =
3916: &Apache::lonnet::assignrole($env{'form.ccdomain'},
3917: $env{'form.ccuname'},
1.239 raeburn 3918: $scope,$role,$now,0,1,'',
3919: $context);
1.367 golterma 3920: $r->print(&Apache::lonhtmlcommon::confirm_success(
3921: &mt('Deleting [_1] in [_2]',
1.369 bisitz 3922: &Apache::lonnet::plaintext($role),
1.372 raeburn 3923: &Apache::loncommon::show_role_extent($scope,$context,$role)),
1.369 bisitz 3924: $result ne 'ok').'<br />');
3925: if ($result ne "ok") {
3926: $r->print(&mt('Error: [_1]',$result).'<br />');
3927: }
1.367 golterma 3928:
1.170 albertel 3929: if ($role eq 'st') {
1.202 raeburn 3930: my $result =
1.198 raeburn 3931: &Apache::lonuserutils::classlist_drop($scope,
3932: $env{'form.ccuname'},$env{'form.ccdomain'},
1.202 raeburn 3933: $now);
1.369 bisitz 3934: $r->print(&Apache::lonhtmlcommon::confirm_success($result));
1.81 albertel 3935: }
1.225 raeburn 3936: if (!grep(/^\Q$role\E$/,@rolechanges)) {
3937: push(@rolechanges,$role);
3938: }
1.116 raeburn 3939: }
1.139 albertel 3940: if ($key=~m{^form\.del\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
1.116 raeburn 3941: my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
3942: # Delete custom role
1.369 bisitz 3943: my $result =
3944: &Apache::lonnet::assigncustomrole($env{'form.ccdomain'},
3945: $env{'form.ccuname'},$url,$rdom,$rnam,$rolename,$now,
3946: 0,1,$context);
3947: $r->print(&Apache::lonhtmlcommon::confirm_success(&mt('Deleting custom role [_1] by [_2] in [_3]',
1.372 raeburn 3948: $rolename,$rnam.':'.$rdom,&Apache::loncommon::show_role_extent($1,$context,'cr')),
1.369 bisitz 3949: $result ne "ok").'<br />');
3950: if ($result ne "ok") {
3951: $r->print(&mt('Error: [_1]',$result).'<br />');
3952: }
1.367 golterma 3953:
1.225 raeburn 3954: if (!grep(/^cr$/,@rolechanges)) {
3955: push(@rolechanges,'cr');
3956: }
1.116 raeburn 3957: }
1.135 raeburn 3958: } elsif ($key=~/^form\.ren/) {
1.101 albertel 3959: my $udom = $env{'form.ccdomain'};
3960: my $uname = $env{'form.ccuname'};
1.116 raeburn 3961: # Re-enable standard role
1.135 raeburn 3962: if ($key=~/^form\.ren\:([^\_]+)\_([^\_\.]+)$/) {
1.89 raeburn 3963: my $url = $1;
3964: my $role = $2;
3965: my $logmsg;
3966: my $output;
3967: if ($role eq 'st') {
1.141 albertel 3968: if ($url =~ m-^/($match_domain)/($match_courseid)/?(\w*)$-) {
1.374 raeburn 3969: my ($cdom,$cnum,$csec) = ($1,$2,$3);
1.375 raeburn 3970: my $credits;
3971: if ($showcredits) {
3972: my $defaultcredits =
3973: &Apache::lonuserutils::get_defaultcredits($cdom,$cnum);
3974: $credits = &get_user_credits($defaultcredits,$cdom,$cnum);
3975: }
3976: my $result = &Apache::loncommon::commit_studentrole(\$logmsg,$udom,$uname,$url,$role,$now,0,$cdom,$cnum,$csec,$context,$credits);
1.220 raeburn 3977: if (($result =~ /^error/) || ($result eq 'not_in_class') || ($result eq 'unknown_course') || ($result eq 'refused')) {
1.223 raeburn 3978: if ($result eq 'refused' && $logmsg) {
3979: $output = $logmsg;
3980: } else {
1.369 bisitz 3981: $output = &mt('Error: [_1]',$result)."\n";
1.223 raeburn 3982: }
1.89 raeburn 3983: } else {
1.372 raeburn 3984: $output = &Apache::lonhtmlcommon::confirm_success(&mt('Assigning [_1] in [_2] starting [_3]',
3985: &Apache::lonnet::plaintext($role),
3986: &Apache::loncommon::show_role_extent($url,$context,'st'),
3987: &Apache::lonlocal::locallocaltime($now))).'<br />'.$logmsg.'<br />';
1.89 raeburn 3988: }
3989: }
3990: } else {
1.101 albertel 3991: my $result=&Apache::lonnet::assignrole($env{'form.ccdomain'},
1.239 raeburn 3992: $env{'form.ccuname'},$url,$role,0,$now,'','',
3993: $context);
1.367 golterma 3994: $output = &Apache::lonhtmlcommon::confirm_success(&mt('Re-enabling [_1] in [_2]',
1.372 raeburn 3995: &Apache::lonnet::plaintext($role),
3996: &Apache::loncommon::show_role_extent($url,$context,$role)),$result ne "ok").'<br />';
1.369 bisitz 3997: if ($result ne "ok") {
3998: $output .= &mt('Error: [_1]',$result).'<br />';
3999: }
4000: }
1.89 raeburn 4001: $r->print($output);
1.225 raeburn 4002: if (!grep(/^\Q$role\E$/,@rolechanges)) {
4003: push(@rolechanges,$role);
4004: }
1.113 raeburn 4005: }
1.116 raeburn 4006: # Re-enable custom role
1.139 albertel 4007: if ($key=~m{^form\.ren\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
1.116 raeburn 4008: my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
4009: my $result = &Apache::lonnet::assigncustomrole(
4010: $env{'form.ccdomain'}, $env{'form.ccuname'},
1.240 raeburn 4011: $url,$rdom,$rnam,$rolename,0,$now,undef,$context);
1.369 bisitz 4012: $r->print(&Apache::lonhtmlcommon::confirm_success(
4013: &mt('Re-enabling custom role [_1] by [_2] in [_3]',
1.372 raeburn 4014: $rolename,$rnam.':'.$rdom,&Apache::loncommon::show_role_extent($1,$context,'cr')),
1.369 bisitz 4015: $result ne "ok").'<br />');
4016: if ($result ne "ok") {
4017: $r->print(&mt('Error: [_1]',$result).'<br />');
4018: }
1.225 raeburn 4019: if (!grep(/^cr$/,@rolechanges)) {
4020: push(@rolechanges,'cr');
4021: }
1.116 raeburn 4022: }
1.135 raeburn 4023: } elsif ($key=~/^form\.act/) {
1.101 albertel 4024: my $udom = $env{'form.ccdomain'};
4025: my $uname = $env{'form.ccuname'};
1.141 albertel 4026: if ($key=~/^form\.act\_($match_domain)\_($match_courseid)\_cr_cr_($match_domain)_($match_username)_([^\_]+)$/) {
1.65 www 4027: # Activate a custom role
1.83 albertel 4028: my ($one,$two,$three,$four,$five)=($1,$2,$3,$4,$5);
4029: my $url='/'.$one.'/'.$two;
4030: my $full=$one.'_'.$two.'_cr_cr_'.$three.'_'.$four.'_'.$five;
1.65 www 4031:
1.101 albertel 4032: my $start = ( $env{'form.start_'.$full} ?
4033: $env{'form.start_'.$full} :
1.88 raeburn 4034: $now );
1.101 albertel 4035: my $end = ( $env{'form.end_'.$full} ?
4036: $env{'form.end_'.$full} :
1.88 raeburn 4037: 0 );
4038:
4039: # split multiple sections
4040: my %sections = ();
1.101 albertel 4041: my $num_sections = &build_roles($env{'form.sec_'.$full},\%sections,$5);
1.88 raeburn 4042: if ($num_sections == 0) {
1.240 raeburn 4043: $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$url,$three,$four,$five,$start,$end,$context));
1.88 raeburn 4044: } else {
1.114 albertel 4045: my %curr_groups =
1.117 raeburn 4046: &Apache::longroup::coursegroups($one,$two);
1.404 raeburn 4047: foreach my $sec (sort {$a cmp $b} keys(%sections)) {
1.113 raeburn 4048: if (($sec eq 'none') || ($sec eq 'all') ||
4049: exists($curr_groups{$sec})) {
4050: $disallowed{$sec} = $url;
4051: next;
4052: }
4053: my $securl = $url.'/'.$sec;
1.240 raeburn 4054: $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$securl,$three,$four,$five,$start,$end,$context));
1.88 raeburn 4055: }
4056: }
1.225 raeburn 4057: if (!grep(/^cr$/,@rolechanges)) {
4058: push(@rolechanges,'cr');
4059: }
1.142 raeburn 4060: } elsif ($key=~/^form\.act\_($match_domain)\_($match_name)\_([^\_]+)$/) {
1.27 matthew 4061: # Activate roles for sections with 3 id numbers
4062: # set start, end times, and the url for the class
1.83 albertel 4063: my ($one,$two,$three)=($1,$2,$3);
1.101 albertel 4064: my $start = ( $env{'form.start_'.$one.'_'.$two.'_'.$three} ?
4065: $env{'form.start_'.$one.'_'.$two.'_'.$three} :
1.27 matthew 4066: $now );
1.101 albertel 4067: my $end = ( $env{'form.end_'.$one.'_'.$two.'_'.$three} ?
4068: $env{'form.end_'.$one.'_'.$two.'_'.$three} :
1.27 matthew 4069: 0 );
1.83 albertel 4070: my $url='/'.$one.'/'.$two;
1.88 raeburn 4071: my $type = 'three';
4072: # split multiple sections
4073: my %sections = ();
1.101 albertel 4074: my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two.'_'.$three},\%sections,$three);
1.375 raeburn 4075: my $credits;
4076: if ($three eq 'st') {
4077: if ($showcredits) {
4078: my $defaultcredits =
4079: &Apache::lonuserutils::get_defaultcredits($one,$two);
4080: $credits = $env{'form.credits_'.$one.'_'.$two.'_'.$three};
4081: $credits =~ s/[^\d\.]//g;
4082: if ($credits eq $defaultcredits) {
4083: undef($credits);
4084: }
4085: }
4086: }
1.88 raeburn 4087: if ($num_sections == 0) {
1.375 raeburn 4088: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'',$context,$credits));
1.88 raeburn 4089: } else {
1.114 albertel 4090: my %curr_groups =
1.117 raeburn 4091: &Apache::longroup::coursegroups($one,$two);
1.88 raeburn 4092: my $emptysec = 0;
1.404 raeburn 4093: foreach my $sec (sort {$a cmp $b} keys(%sections)) {
1.88 raeburn 4094: $sec =~ s/\W//g;
1.113 raeburn 4095: if ($sec ne '') {
4096: if (($sec eq 'none') || ($sec eq 'all') ||
4097: exists($curr_groups{$sec})) {
4098: $disallowed{$sec} = $url;
4099: next;
4100: }
1.88 raeburn 4101: my $securl = $url.'/'.$sec;
1.375 raeburn 4102: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$three,$start,$end,$one,$two,$sec,$context,$credits));
1.88 raeburn 4103: } else {
4104: $emptysec = 1;
4105: }
4106: }
4107: if ($emptysec) {
1.375 raeburn 4108: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'',$context,$credits));
1.88 raeburn 4109: }
1.225 raeburn 4110: }
4111: if (!grep(/^\Q$three\E$/,@rolechanges)) {
4112: push(@rolechanges,$three);
4113: }
1.135 raeburn 4114: } elsif ($key=~/^form\.act\_([^\_]+)\_([^\_]+)$/) {
1.27 matthew 4115: # Activate roles for sections with two id numbers
4116: # set start, end times, and the url for the class
1.101 albertel 4117: my $start = ( $env{'form.start_'.$1.'_'.$2} ?
4118: $env{'form.start_'.$1.'_'.$2} :
1.27 matthew 4119: $now );
1.101 albertel 4120: my $end = ( $env{'form.end_'.$1.'_'.$2} ?
4121: $env{'form.end_'.$1.'_'.$2} :
1.27 matthew 4122: 0 );
1.225 raeburn 4123: my $one = $1;
4124: my $two = $2;
4125: my $url='/'.$one.'/';
1.88 raeburn 4126: # split multiple sections
4127: my %sections = ();
1.225 raeburn 4128: my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two},\%sections,$two);
1.88 raeburn 4129: if ($num_sections == 0) {
1.240 raeburn 4130: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,'',$context));
1.88 raeburn 4131: } else {
4132: my $emptysec = 0;
1.404 raeburn 4133: foreach my $sec (sort {$a cmp $b} keys(%sections)) {
1.88 raeburn 4134: if ($sec ne '') {
4135: my $securl = $url.'/'.$sec;
1.240 raeburn 4136: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$two,$start,$end,$one,undef,$sec,$context));
1.88 raeburn 4137: } else {
4138: $emptysec = 1;
4139: }
4140: }
4141: if ($emptysec) {
1.240 raeburn 4142: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,'',$context));
1.88 raeburn 4143: }
4144: }
1.225 raeburn 4145: if (!grep(/^\Q$two\E$/,@rolechanges)) {
4146: push(@rolechanges,$two);
4147: }
1.64 www 4148: } else {
1.190 raeburn 4149: $r->print('<p><span class="LC_error">'.&mt('ERROR').': '.&mt('Unknown command').' <tt>'.$key.'</tt></span></p><br />');
1.64 www 4150: }
1.113 raeburn 4151: foreach my $key (sort(keys(%disallowed))) {
1.274 bisitz 4152: $r->print('<p class="LC_warning">');
1.113 raeburn 4153: if (($key eq 'none') || ($key eq 'all')) {
1.274 bisitz 4154: $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 4155: } else {
1.274 bisitz 4156: $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 4157: }
1.274 bisitz 4158: $r->print('</p><p>'
4159: .&mt('Please [_1]go back[_2] and choose a different section name.'
4160: ,'<a href="javascript:history.go(-1)'
4161: ,'</a>')
4162: .'</p><br />'
4163: );
1.113 raeburn 4164: }
4165: }
1.101 albertel 4166: } # End of foreach (keys(%env))
1.75 www 4167: # Flush the course logs so reverse user roles immediately updated
1.349 raeburn 4168: $r->register_cleanup(\&Apache::lonnet::flushcourselogs);
1.225 raeburn 4169: if (@rolechanges == 0) {
1.372 raeburn 4170: $r->print('<p>'.&mt('No roles to modify').'</p>');
1.193 raeburn 4171: }
1.225 raeburn 4172: return @rolechanges;
1.220 raeburn 4173: }
4174:
1.375 raeburn 4175: sub get_user_credits {
4176: my ($uname,$udom,$defaultcredits,$cdom,$cnum) = @_;
4177: if ($cdom eq '' || $cnum eq '') {
4178: return unless ($env{'request.course.id'});
4179: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
4180: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
4181: }
4182: my $credits;
4183: my %currhash =
4184: &Apache::lonnet::get('classlist',[$uname.':'.$udom],$cdom,$cnum);
4185: if (keys(%currhash) > 0) {
4186: my @items = split(/:/,$currhash{$uname.':'.$udom});
4187: my $crdidx = &Apache::loncoursedata::CL_CREDITS() - 3;
4188: $credits = $items[$crdidx];
4189: $credits =~ s/[^\d\.]//g;
4190: }
4191: if ($credits eq $defaultcredits) {
4192: undef($credits);
4193: }
4194: return $credits;
4195: }
4196:
1.220 raeburn 4197: sub enroll_single_student {
1.375 raeburn 4198: my ($r,$uhome,$amode,$genpwd,$now,$newuser,$context,$crstype,
4199: $showcredits,$defaultcredits) = @_;
1.318 raeburn 4200: $r->print('<h3>');
4201: if ($crstype eq 'Community') {
4202: $r->print(&mt('Enrolling Member'));
4203: } else {
4204: $r->print(&mt('Enrolling Student'));
4205: }
4206: $r->print('</h3>');
1.220 raeburn 4207:
4208: # Remove non alphanumeric values from section
4209: $env{'form.sections'}=~s/\W//g;
4210:
1.375 raeburn 4211: my $credits;
4212: if (($showcredits) && ($env{'form.credits'} ne '')) {
4213: $credits = $env{'form.credits'};
4214: $credits =~ s/[^\d\.]//g;
4215: if ($credits ne '') {
4216: if ($credits eq $defaultcredits) {
4217: undef($credits);
4218: }
4219: }
4220: }
4221:
1.220 raeburn 4222: # Clean out any old student roles the user has in this class.
4223: &Apache::lonuserutils::modifystudent($env{'form.ccdomain'},
4224: $env{'form.ccuname'},$env{'request.course.id'},undef,$uhome);
4225: my ($startdate,$enddate) = &Apache::lonuserutils::get_dates_from_form();
4226: my $enroll_result =
4227: &Apache::lonnet::modify_student_enrollment($env{'form.ccdomain'},
4228: $env{'form.ccuname'},$env{'form.cid'},$env{'form.cfirstname'},
4229: $env{'form.cmiddlename'},$env{'form.clastname'},
4230: $env{'form.generation'},$env{'form.sections'},$enddate,
1.375 raeburn 4231: $startdate,'manual',undef,$env{'request.course.id'},'',$context,
4232: $credits);
1.220 raeburn 4233: if ($enroll_result =~ /^ok/) {
1.381 bisitz 4234: $r->print(&mt('[_1] enrolled','<b>'.$env{'form.ccuname'}.':'.$env{'form.ccdomain'}.'</b>'));
1.220 raeburn 4235: if ($env{'form.sections'} ne '') {
4236: $r->print(' '.&mt('in section [_1]',$env{'form.sections'}));
4237: }
4238: my ($showstart,$showend);
4239: if ($startdate <= $now) {
4240: $showstart = &mt('Access starts immediately');
4241: } else {
4242: $showstart = &mt('Access starts: ').&Apache::lonlocal::locallocaltime($startdate);
4243: }
4244: if ($enddate == 0) {
4245: $showend = &mt('ends: no ending date');
4246: } else {
4247: $showend = &mt('ends: ').&Apache::lonlocal::locallocaltime($enddate);
4248: }
4249: $r->print('.<br />'.$showstart.'; '.$showend);
4250: if ($startdate <= $now && !$newuser) {
1.386 bisitz 4251: $r->print('<p class="LC_info">');
1.318 raeburn 4252: if ($crstype eq 'Community') {
1.392 raeburn 4253: $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 4254: } else {
1.392 raeburn 4255: $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 4256: }
4257: $r->print('</p>');
1.220 raeburn 4258: }
4259: } else {
4260: $r->print(&mt('unable to enroll').": ".$enroll_result);
4261: }
4262: return;
1.188 raeburn 4263: }
4264:
1.204 raeburn 4265: sub get_defaultquota_text {
4266: my ($settingstatus) = @_;
4267: my $defquotatext;
4268: if ($settingstatus eq '') {
1.383 raeburn 4269: $defquotatext = &mt('default');
1.204 raeburn 4270: } else {
4271: my ($usertypes,$order) =
4272: &Apache::lonnet::retrieve_inst_usertypes($env{'form.ccdomain'});
4273: if ($usertypes->{$settingstatus} eq '') {
1.383 raeburn 4274: $defquotatext = &mt('default');
1.204 raeburn 4275: } else {
1.383 raeburn 4276: $defquotatext = &mt('default for [_1]',$usertypes->{$settingstatus});
1.204 raeburn 4277: }
4278: }
4279: return $defquotatext;
4280: }
4281:
1.188 raeburn 4282: sub update_result_form {
4283: my ($uhome) = @_;
4284: my $outcome =
1.367 golterma 4285: '<form name="userupdate" method="post" action="">'."\n";
1.160 raeburn 4286: foreach my $item ('srchby','srchin','srchtype','srchterm','srchdomain','ccuname','ccdomain') {
1.188 raeburn 4287: $outcome .= '<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n";
1.160 raeburn 4288: }
1.207 raeburn 4289: if ($env{'form.origname'} ne '') {
4290: $outcome .= '<input type="hidden" name="origname" value="'.$env{'form.origname'}.'" />'."\n";
4291: }
1.160 raeburn 4292: foreach my $item ('sortby','seluname','seludom') {
4293: if (exists($env{'form.'.$item})) {
1.188 raeburn 4294: $outcome .= '<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n";
1.160 raeburn 4295: }
4296: }
1.188 raeburn 4297: if ($uhome eq 'no_host') {
4298: $outcome .= '<input type="hidden" name="forcenewuser" value="1" />'."\n";
4299: }
4300: $outcome .= '<input type="hidden" name="phase" value="" />'."\n".
1.383 raeburn 4301: '<input type="hidden" name="currstate" value="" />'."\n".
4302: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n".
1.188 raeburn 4303: '</form>';
4304: return $outcome;
1.4 www 4305: }
4306:
1.149 raeburn 4307: sub quota_admin {
1.378 raeburn 4308: my ($setquota,$changeHash,$name) = @_;
1.149 raeburn 4309: my $quotachanged;
4310: if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
4311: # Current user has quota modification privileges
1.267 raeburn 4312: if (ref($changeHash) eq 'HASH') {
4313: $quotachanged = 1;
1.378 raeburn 4314: $changeHash->{$name.'quota'} = $setquota;
1.267 raeburn 4315: }
1.149 raeburn 4316: }
4317: return $quotachanged;
4318: }
4319:
1.267 raeburn 4320: sub tool_admin {
1.275 raeburn 4321: my ($tool,$settool,$changeHash,$context) = @_;
4322: my $canchange = 0;
1.279 raeburn 4323: if ($context eq 'requestcourses') {
1.275 raeburn 4324: if (&Apache::lonnet::allowed('ccc',$env{'form.ccdomain'})) {
4325: $canchange = 1;
4326: }
1.300 raeburn 4327: } elsif ($context eq 'reqcrsotherdom') {
4328: if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
4329: $canchange = 1;
4330: }
1.362 raeburn 4331: } elsif ($context eq 'requestauthor') {
4332: if (&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) {
4333: $canchange = 1;
4334: }
1.275 raeburn 4335: } elsif (&Apache::lonnet::allowed('mut',$env{'form.ccdomain'})) {
4336: # Current user has quota modification privileges
4337: $canchange = 1;
4338: }
1.267 raeburn 4339: my $toolchanged;
1.275 raeburn 4340: if ($canchange) {
1.267 raeburn 4341: if (ref($changeHash) eq 'HASH') {
4342: $toolchanged = 1;
1.362 raeburn 4343: if ($tool eq 'requestauthor') {
4344: $changeHash->{$context} = $settool;
4345: } else {
4346: $changeHash->{$context.'.'.$tool} = $settool;
4347: }
1.267 raeburn 4348: }
4349: }
4350: return $toolchanged;
4351: }
4352:
1.88 raeburn 4353: sub build_roles {
1.89 raeburn 4354: my ($sectionstr,$sections,$role) = @_;
1.88 raeburn 4355: my $num_sections = 0;
4356: if ($sectionstr=~ /,/) {
4357: my @secnums = split/,/,$sectionstr;
1.89 raeburn 4358: if ($role eq 'st') {
4359: $secnums[0] =~ s/\W//g;
4360: $$sections{$secnums[0]} = 1;
4361: $num_sections = 1;
4362: } else {
4363: foreach my $sec (@secnums) {
4364: $sec =~ ~s/\W//g;
1.150 banghart 4365: if (!($sec eq "")) {
1.89 raeburn 4366: if (exists($$sections{$sec})) {
4367: $$sections{$sec} ++;
4368: } else {
4369: $$sections{$sec} = 1;
4370: $num_sections ++;
4371: }
1.88 raeburn 4372: }
4373: }
4374: }
4375: } else {
4376: $sectionstr=~s/\W//g;
4377: unless ($sectionstr eq '') {
4378: $$sections{$sectionstr} = 1;
4379: $num_sections ++;
4380: }
4381: }
1.129 albertel 4382:
1.88 raeburn 4383: return $num_sections;
4384: }
4385:
1.58 www 4386: # ========================================================== Custom Role Editor
4387:
4388: sub custom_role_editor {
1.439 raeburn 4389: my ($r,$context,$brcrum,$prefix,$permission) = @_;
1.324 raeburn 4390: my $action = $env{'form.customroleaction'};
1.439 raeburn 4391: my ($rolename,$helpitem);
1.324 raeburn 4392: if ($action eq 'new') {
4393: $rolename=$env{'form.newrolename'};
4394: } else {
4395: $rolename=$env{'form.rolename'};
1.59 www 4396: }
4397:
1.324 raeburn 4398: my ($crstype,$context);
4399: if ($env{'request.course.id'}) {
4400: $crstype = &Apache::loncommon::course_type();
4401: $context = 'course';
1.439 raeburn 4402: $helpitem = 'Course_Editing_Custom_Roles';
1.324 raeburn 4403: } else {
4404: $context = 'domain';
1.414 raeburn 4405: $crstype = 'course';
1.439 raeburn 4406: $helpitem = 'Domain_Editing_Custom_Roles';
1.324 raeburn 4407: }
1.351 raeburn 4408:
4409: $rolename=~s/[^A-Za-z0-9]//gs;
4410: if (!$rolename || $env{'form.phase'} eq 'pickrole') {
1.439 raeburn 4411: &print_username_entry_form($r,$context,undef,undef,undef,$crstype,$brcrum,
4412: $permission);
1.351 raeburn 4413: return;
4414: }
4415:
1.414 raeburn 4416: my $formname = 'form1';
4417: my %privs=();
4418: my $body_top = '<h2>';
4419: # ------------------------------------------------------- Does this role exist?
1.59 www 4420: my ($rdummy,$roledef)=
4421: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
4422: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1.414 raeburn 4423: $body_top .= &mt('Existing Role').' "';
1.61 www 4424: # ------------------------------------------------- Get current role privileges
1.414 raeburn 4425: ($privs{'system'},$privs{'domain'},$privs{'course'})=split(/\_/,$roledef);
4426: if ($privs{'system'} =~ /bre\&S/) {
4427: if ($context eq 'domain') {
1.417 raeburn 4428: $crstype = 'Course';
1.414 raeburn 4429: } elsif ($crstype eq 'Community') {
4430: $privs{'system'} =~ s/bre\&S//;
4431: }
4432: } elsif ($context eq 'domain') {
4433: $crstype = 'Course';
1.324 raeburn 4434: }
1.59 www 4435: } else {
1.414 raeburn 4436: $body_top .= &mt('New Role').' "';
4437: $roledef='';
1.59 www 4438: }
1.153 banghart 4439: $body_top .= $rolename.'"</h2>';
1.414 raeburn 4440:
4441: # ------------------------------------------------------- What can be assigned?
4442: my %full=();
1.417 raeburn 4443: my %levels=(
1.414 raeburn 4444: course => {},
4445: domain => {},
4446: system => {},
4447: );
4448: my %levelscurrent=(
4449: course => {},
4450: domain => {},
4451: system => {},
4452: );
4453: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
1.160 raeburn 4454: my ($jsback,$elements) = &crumb_utilities();
1.414 raeburn 4455: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
1.417 raeburn 4456: my $head_script =
1.414 raeburn 4457: &Apache::lonuserutils::custom_roledefs_js($context,$crstype,$formname,
4458: \%full,\@templateroles,$jsback);
1.351 raeburn 4459: push (@{$brcrum},
1.414 raeburn 4460: {href => "javascript:backPage(document.$formname,'pickrole','')",
1.351 raeburn 4461: text => "Pick custom role",
4462: faq => 282,bug=>'Instructor Interface',},
1.414 raeburn 4463: {href => "javascript:backPage(document.$formname,'','')",
1.351 raeburn 4464: text => "Edit custom role",
4465: faq => 282,
4466: bug => 'Instructor Interface',
1.439 raeburn 4467: help => $helpitem}
1.351 raeburn 4468: );
4469: my $args = { bread_crumbs => $brcrum,
4470: bread_crumbs_component => 'User Management'};
4471: $r->print(&Apache::loncommon::start_page('Custom Role Editor',
4472: $head_script,$args).
4473: $body_top);
1.414 raeburn 4474: $r->print('<form name="'.$formname.'" method="post" action="">'."\n".
4475: &Apache::lonuserutils::custom_role_header($context,$crstype,
4476: \@templateroles,$prefix));
1.264 bisitz 4477:
1.61 www 4478: $r->print(<<ENDCCF);
4479: <input type="hidden" name="phase" value="set_custom_roles" />
4480: <input type="hidden" name="rolename" value="$rolename" />
4481: ENDCCF
1.414 raeburn 4482: $r->print(&Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
4483: \%levelscurrent,$prefix));
1.135 raeburn 4484: $r->print(&Apache::loncommon::end_data_table().
1.190 raeburn 4485: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'.
1.160 raeburn 4486: '<input type="hidden" name="startrolename" value="'.$env{'form.rolename'}.
1.417 raeburn 4487: '" />'."\n".'<input type="hidden" name="currstate" value="" />'."\n".
1.160 raeburn 4488: '<input type="reset" value="'.&mt("Reset").'" />'."\n".
1.351 raeburn 4489: '<input type="submit" value="'.&mt('Save').'" /></form>');
1.61 www 4490: }
1.414 raeburn 4491:
1.61 www 4492: # ---------------------------------------------------------- Call to definerole
4493: sub set_custom_role {
1.439 raeburn 4494: my ($r,$context,$brcrum,$prefix,$permission) = @_;
1.101 albertel 4495: my $rolename=$env{'form.rolename'};
1.63 www 4496: $rolename=~s/[^A-Za-z0-9]//gs;
1.150 banghart 4497: if (!$rolename) {
1.439 raeburn 4498: &custom_role_editor($r,$context,$brcrum,$prefix,$permission);
1.61 www 4499: return;
4500: }
1.160 raeburn 4501: my ($jsback,$elements) = &crumb_utilities();
1.301 bisitz 4502: my $jscript = '<script type="text/javascript">'
4503: .'// <![CDATA['."\n"
4504: .$jsback."\n"
4505: .'// ]]>'."\n"
4506: .'</script>'."\n";
1.439 raeburn 4507: my $helpitem = 'Course_Editing_Custom_Roles';
4508: if ($context eq 'domain') {
4509: $helpitem = 'Domain_Editing_Custom_Roles';
4510: }
1.352 raeburn 4511: push(@{$brcrum},
4512: {href => "javascript:backPage(document.customresult,'pickrole','')",
4513: text => "Pick custom role",
4514: faq => 282,
4515: bug => 'Instructor Interface',},
4516: {href => "javascript:backPage(document.customresult,'selected_custom_edit','')",
4517: text => "Edit custom role",
4518: faq => 282,
4519: bug => 'Instructor Interface',},
4520: {href => "javascript:backPage(document.customresult,'set_custom_roles','')",
4521: text => "Result",
4522: faq => 282,
4523: bug => 'Instructor Interface',
1.439 raeburn 4524: help => $helpitem,}
1.352 raeburn 4525: );
4526: my $args = { bread_crumbs => $brcrum,
1.414 raeburn 4527: bread_crumbs_component => 'User Management'};
1.351 raeburn 4528: $r->print(&Apache::loncommon::start_page('Save Custom Role',$jscript,$args));
1.160 raeburn 4529:
1.393 raeburn 4530: my $newrole;
1.61 www 4531: my ($rdummy,$roledef)=
1.110 albertel 4532: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
4533:
1.61 www 4534: # ------------------------------------------------------- Does this role exist?
1.188 raeburn 4535: $r->print('<h3>');
1.61 www 4536: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1.73 sakharuk 4537: $r->print(&mt('Existing Role').' "');
1.61 www 4538: } else {
1.73 sakharuk 4539: $r->print(&mt('New Role').' "');
1.61 www 4540: $roledef='';
1.393 raeburn 4541: $newrole = 1;
1.61 www 4542: }
1.188 raeburn 4543: $r->print($rolename.'"</h3>');
1.414 raeburn 4544: # ------------------------------------------------- Assign role and show result
1.61 www 4545:
1.387 bisitz 4546: my $errmsg;
1.414 raeburn 4547: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$prefix);
4548: # Assign role and return result
4549: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
4550: $newprivs{'c'});
1.387 bisitz 4551: if ($result ne 'ok') {
4552: $errmsg = ': '.$result;
4553: }
4554: my $message =
4555: &Apache::lonhtmlcommon::confirm_success(
4556: &mt('Defining Role').$errmsg, ($result eq 'ok' ? 0 : 1));
1.101 albertel 4557: if ($env{'request.course.id'}) {
4558: my $url='/'.$env{'request.course.id'};
1.63 www 4559: $url=~s/\_/\//g;
1.387 bisitz 4560: $result =
4561: &Apache::lonnet::assigncustomrole(
4562: $env{'user.domain'},$env{'user.name'},
4563: $url,
4564: $env{'user.domain'},$env{'user.name'},
4565: $rolename,undef,undef,undef,$context);
4566: if ($result ne 'ok') {
4567: $errmsg = ': '.$result;
4568: }
4569: $message .=
4570: '<br />'
4571: .&Apache::lonhtmlcommon::confirm_success(
4572: &mt('Assigning Role to Self').$errmsg, ($result eq 'ok' ? 0 : 1));
1.63 www 4573: }
1.380 bisitz 4574: $r->print(
1.387 bisitz 4575: &Apache::loncommon::confirmwrapper($message)
4576: .'<br />'
4577: .&Apache::lonhtmlcommon::actionbox([
4578: '<a href="javascript:backPage(document.customresult,'."'pickrole'".')">'
4579: .&mt('Create or edit another custom role')
4580: .'</a>'])
1.380 bisitz 4581: .'<form name="customresult" method="post" action="">'
1.387 bisitz 4582: .&Apache::lonhtmlcommon::echo_form_input([])
4583: .'</form>'
1.380 bisitz 4584: );
1.58 www 4585: }
4586:
1.2 www 4587: # ================================================================ Main Handler
4588: sub handler {
4589: my $r = shift;
4590: if ($r->header_only) {
1.68 www 4591: &Apache::loncommon::content_type($r,'text/html');
1.2 www 4592: $r->send_http_header;
4593: return OK;
4594: }
1.439 raeburn 4595: my ($context,$crstype,$cid,$cnum,$cdom,$allhelpitems);
4596:
1.190 raeburn 4597: if ($env{'request.course.id'}) {
4598: $context = 'course';
1.318 raeburn 4599: $crstype = &Apache::loncommon::course_type();
1.190 raeburn 4600: } elsif ($env{'request.role'} =~ /^au\./) {
1.206 raeburn 4601: $context = 'author';
1.190 raeburn 4602: } else {
4603: $context = 'domain';
4604: }
1.375 raeburn 4605:
1.439 raeburn 4606: my ($permission,$allowed) =
4607: &Apache::lonuserutils::get_permission($context,$crstype);
4608:
4609: if ($allowed) {
4610: my @allhelp;
4611: if ($context eq 'course') {
4612: $cid = $env{'request.course.id'};
4613: $cdom = $env{'course.'.$cid.'.domain'};
4614: $cnum = $env{'course.'.$cid.'.num'};
4615:
4616: if ($permission->{'cusr'}) {
4617: push(@allhelp,'Course_Create_Class_List');
4618: }
4619: if ($permission->{'view'} || $permission->{'cusr'}) {
4620: push(@allhelp,('Course_Change_Privileges','Course_View_Class_List'));
4621: }
4622: if ($permission->{'custom'}) {
4623: push(@allhelp,'Course_Editing_Custom_Roles');
4624: }
4625: if ($permission->{'cusr'}) {
4626: push(@allhelp,('Course_Add_Student','Course_Drop_Student'));
4627: }
4628: unless ($permission->{'cusr_section'}) {
4629: if (&Apache::lonnet::auto_run($cnum,$cdom) && (($permission->{'cusr'}) || ($permission->{'view'}))) {
4630: push(@allhelp,'Course_Automated_Enrollment');
4631: }
4632: if ($permission->{'selfenrolladmin'}) {
4633: push(@allhelp,'Course_Approve_Selfenroll');
4634: }
4635: }
4636: if ($permission->{'grp_manage'}) {
4637: push(@allhelp,'Course_Manage_Group');
4638: }
4639: if ($permission->{'view'} || $permission->{'cusr'}) {
4640: push(@allhelp,'Course_User_Logs');
4641: }
4642: } elsif ($context eq 'author') {
4643: push(@allhelp,('Author_Change_Privileges','Author_Create_Coauthor_List',
4644: 'Author_View_Coauthor_List','Author_User_Logs'));
4645: } else {
4646: if ($permission->{'cusr'}) {
4647: push(@allhelp,'Domain_Change_Privileges');
4648: if ($permission->{'activity'}) {
4649: push(@allhelp,'Domain_User_Access_Logs');
4650: }
4651: push(@allhelp,('Domain_Create_Users','Domain_View_Users_List'));
4652: if ($permission->{'custom'}) {
4653: push(@allhelp,'Domain_Editing_Custom_Roles');
4654: }
4655: push(@allhelp,('Domain_Role_Approvals','Domain_Username_Approvals','Domain_Change_Logs'));
4656: } elsif ($permission->{'view'}) {
4657: push(@allhelp,'Domain_View_Privileges');
4658: if ($permission->{'activity'}) {
4659: push(@allhelp,'Domain_User_Access_Logs');
4660: }
4661: push(@allhelp,('Domain_View_Users_List','Domain_Change_Logs'));
4662: }
4663: }
4664: if (@allhelp) {
4665: $allhelpitems = join(',',@allhelp);
4666: }
4667: }
4668:
1.190 raeburn 4669: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.233 raeburn 4670: ['action','state','callingform','roletype','showrole','bulkaction','popup','phase',
1.391 raeburn 4671: 'username','domain','srchterm','srchdomain','srchin','srchby','srchtype','queue']);
1.190 raeburn 4672: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.351 raeburn 4673: my $args;
4674: my $brcrum = [];
4675: my $bread_crumbs_component = 'User Management';
1.391 raeburn 4676: if (($env{'form.action'} ne 'dateselect') && ($env{'form.action'} ne 'displayuserreq')) {
1.351 raeburn 4677: $brcrum = [{href=>"/adm/createuser",
4678: text=>"User Management",
1.439 raeburn 4679: help=>$allhelpitems}
1.351 raeburn 4680: ];
1.202 raeburn 4681: }
1.190 raeburn 4682: if (!$allowed) {
1.358 raeburn 4683: if ($context eq 'course') {
4684: $r->internal_redirect('/adm/viewclasslist');
4685: return OK;
4686: }
1.190 raeburn 4687: $env{'user.error.msg'}=
4688: "/adm/createuser:cst:0:0:Cannot create/modify user data ".
4689: "or view user status.";
4690: return HTTP_NOT_ACCEPTABLE;
4691: }
4692:
4693: &Apache::loncommon::content_type($r,'text/html');
4694: $r->send_http_header;
4695:
1.375 raeburn 4696: my $showcredits;
4697: if ((($context eq 'course') && ($crstype eq 'Course')) ||
4698: ($context eq 'domain')) {
4699: my %domdefaults =
4700: &Apache::lonnet::get_domain_defaults($env{'request.role.domain'});
4701: if ($domdefaults{'officialcredits'} || $domdefaults{'unofficialcredits'}) {
4702: $showcredits = 1;
4703: }
4704: }
4705:
1.190 raeburn 4706: # Main switch on form.action and form.state, as appropriate
4707: if (! exists($env{'form.action'})) {
1.351 raeburn 4708: $args = {bread_crumbs => $brcrum,
4709: bread_crumbs_component => $bread_crumbs_component};
4710: $r->print(&header(undef,$args));
1.318 raeburn 4711: $r->print(&print_main_menu($permission,$context,$crstype));
1.190 raeburn 4712: } elsif ($env{'form.action'} eq 'upload' && $permission->{'cusr'}) {
1.439 raeburn 4713: my $helpitem = 'Course_Create_Class_List';
4714: if ($context eq 'author') {
4715: $helpitem = 'Author_Create_Coauthor_List';
4716: } elsif ($context eq 'domain') {
4717: $helpitem = 'Domain_Create_Users';
4718: }
1.351 raeburn 4719: push(@{$brcrum},
4720: { href => '/adm/createuser?action=upload&state=',
4721: text => 'Upload Users List',
1.439 raeburn 4722: help => $helpitem,
1.351 raeburn 4723: });
4724: $bread_crumbs_component = 'Upload Users List';
4725: $args = {bread_crumbs => $brcrum,
4726: bread_crumbs_component => $bread_crumbs_component};
4727: $r->print(&header(undef,$args));
1.190 raeburn 4728: $r->print('<form name="studentform" method="post" '.
4729: 'enctype="multipart/form-data" '.
4730: ' action="/adm/createuser">'."\n");
4731: if (! exists($env{'form.state'})) {
4732: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
4733: } elsif ($env{'form.state'} eq 'got_file') {
1.375 raeburn 4734: &Apache::lonuserutils::print_upload_manager_form($r,$context,$permission,
4735: $crstype,$showcredits);
1.190 raeburn 4736: } elsif ($env{'form.state'} eq 'enrolling') {
4737: if ($env{'form.datatoken'}) {
1.375 raeburn 4738: &Apache::lonuserutils::upfile_drop_add($r,$context,$permission,
4739: $showcredits);
1.190 raeburn 4740: }
4741: } else {
4742: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
4743: }
1.416 raeburn 4744: } elsif (((($env{'form.action'} eq 'singleuser') || ($env{'form.action'}
4745: eq 'singlestudent')) && ($permission->{'cusr'})) ||
1.418 raeburn 4746: (($env{'form.action'} eq 'singleuser') && ($permission->{'view'})) ||
1.416 raeburn 4747: (($env{'form.action'} eq 'accesslogs') && ($permission->{'activity'}))) {
1.190 raeburn 4748: my $phase = $env{'form.phase'};
4749: my @search = ('srchterm','srchby','srchin','srchtype','srchdomain');
1.192 albertel 4750: &Apache::loncreateuser::restore_prev_selections();
4751: my $srch;
4752: foreach my $item (@search) {
4753: $srch->{$item} = $env{'form.'.$item};
4754: }
1.207 raeburn 4755: if (($phase eq 'get_user_info') || ($phase eq 'userpicked') ||
1.416 raeburn 4756: ($phase eq 'createnewuser') || ($phase eq 'activity')) {
1.207 raeburn 4757: if ($env{'form.phase'} eq 'createnewuser') {
4758: my $response;
4759: if ($env{'form.srchterm'} !~ /^$match_username$/) {
1.366 bisitz 4760: my $response =
4761: '<span class="LC_warning">'
4762: .&mt('You must specify a valid username. Only the following are allowed:'
4763: .' letters numbers - . @')
4764: .'</span>';
1.221 raeburn 4765: $env{'form.phase'} = '';
1.375 raeburn 4766: &print_username_entry_form($r,$context,$response,$srch,undef,
1.439 raeburn 4767: $crstype,$brcrum,$permission);
1.207 raeburn 4768: } else {
4769: my $ccuname =&LONCAPA::clean_username($srch->{'srchterm'});
4770: my $ccdomain=&LONCAPA::clean_domain($srch->{'srchdomain'});
4771: &print_user_modification_page($r,$ccuname,$ccdomain,
1.221 raeburn 4772: $srch,$response,$context,
1.375 raeburn 4773: $permission,$crstype,$brcrum,
4774: $showcredits);
1.207 raeburn 4775: }
4776: } elsif ($env{'form.phase'} eq 'get_user_info') {
1.190 raeburn 4777: my ($currstate,$response,$forcenewuser,$results) =
1.221 raeburn 4778: &user_search_result($context,$srch);
1.190 raeburn 4779: if ($env{'form.currstate'} eq 'modify') {
4780: $currstate = $env{'form.currstate'};
4781: }
4782: if ($currstate eq 'select') {
4783: &print_user_selection_page($r,$response,$srch,$results,
1.351 raeburn 4784: \@search,$context,undef,$crstype,
4785: $brcrum);
1.416 raeburn 4786: } elsif (($currstate eq 'modify') || ($env{'form.action'} eq 'accesslogs')) {
4787: my ($ccuname,$ccdomain,$uhome);
1.190 raeburn 4788: if (($srch->{'srchby'} eq 'uname') &&
4789: ($srch->{'srchtype'} eq 'exact')) {
4790: $ccuname = $srch->{'srchterm'};
4791: $ccdomain= $srch->{'srchdomain'};
4792: } else {
4793: my @matchedunames = keys(%{$results});
4794: ($ccuname,$ccdomain) = split(/:/,$matchedunames[0]);
4795: }
4796: $ccuname =&LONCAPA::clean_username($ccuname);
4797: $ccdomain=&LONCAPA::clean_domain($ccdomain);
1.416 raeburn 4798: if ($env{'form.action'} eq 'accesslogs') {
4799: my $uhome;
4800: if (($ccuname ne '') && ($ccdomain ne '')) {
4801: $uhome = &Apache::lonnet::homeserver($ccuname,$ccdomain);
4802: }
4803: if (($uhome eq '') || ($uhome eq 'no_host')) {
4804: $env{'form.phase'} = '';
4805: undef($forcenewuser);
4806: #if ($response) {
4807: # unless ($response =~ m{\Q<br /><br />\E$}) {
4808: # $response .= '<br /><br />';
4809: # }
4810: #}
4811: &print_username_entry_form($r,$context,$response,$srch,
1.439 raeburn 4812: $forcenewuser,$crstype,$brcrum,
4813: $permission);
1.416 raeburn 4814: } else {
4815: &print_useraccesslogs_display($r,$ccuname,$ccdomain,$permission,$brcrum);
4816: }
4817: } else {
4818: if ($env{'form.forcenewuser'}) {
4819: $response = '';
4820: }
4821: &print_user_modification_page($r,$ccuname,$ccdomain,
4822: $srch,$response,$context,
4823: $permission,$crstype,$brcrum);
1.190 raeburn 4824: }
4825: } elsif ($currstate eq 'query') {
1.351 raeburn 4826: &print_user_query_page($r,'createuser',$brcrum);
1.190 raeburn 4827: } else {
1.229 raeburn 4828: $env{'form.phase'} = '';
1.207 raeburn 4829: &print_username_entry_form($r,$context,$response,$srch,
1.439 raeburn 4830: $forcenewuser,$crstype,$brcrum,
4831: $permission);
1.190 raeburn 4832: }
4833: } elsif ($env{'form.phase'} eq 'userpicked') {
4834: my $ccuname = &LONCAPA::clean_username($env{'form.seluname'});
4835: my $ccdomain = &LONCAPA::clean_domain($env{'form.seludom'});
1.416 raeburn 4836: if ($env{'form.action'} eq 'accesslogs') {
4837: &print_useraccesslogs_display($r,$ccuname,$ccdomain,$permission,$brcrum);
4838: } else {
4839: &print_user_modification_page($r,$ccuname,$ccdomain,$srch,'',
4840: $context,$permission,$crstype,
4841: $brcrum);
4842: }
4843: } elsif ($env{'form.action'} eq 'accesslogs') {
4844: my $ccuname = &LONCAPA::clean_username($env{'form.accessuname'});
4845: my $ccdomain = &LONCAPA::clean_domain($env{'form.accessudom'});
4846: &print_useraccesslogs_display($r,$ccuname,$ccdomain,$permission,$brcrum);
1.190 raeburn 4847: }
4848: } elsif ($env{'form.phase'} eq 'update_user_data') {
1.375 raeburn 4849: &update_user_data($r,$context,$crstype,$brcrum,$showcredits);
1.190 raeburn 4850: } else {
1.351 raeburn 4851: &print_username_entry_form($r,$context,undef,$srch,undef,$crstype,
1.439 raeburn 4852: $brcrum,$permission);
1.190 raeburn 4853: }
4854: } elsif ($env{'form.action'} eq 'custom' && $permission->{'custom'}) {
1.414 raeburn 4855: my $prefix;
1.190 raeburn 4856: if ($env{'form.phase'} eq 'set_custom_roles') {
1.439 raeburn 4857: &set_custom_role($r,$context,$brcrum,$prefix,$permission);
1.190 raeburn 4858: } else {
1.439 raeburn 4859: &custom_role_editor($r,$context,$brcrum,$prefix,$permission);
1.190 raeburn 4860: }
1.362 raeburn 4861: } elsif (($env{'form.action'} eq 'processauthorreq') &&
4862: ($permission->{'cusr'}) &&
4863: (&Apache::lonnet::allowed('cau',$env{'request.role.domain'}))) {
4864: push(@{$brcrum},
4865: {href => '/adm/createuser?action=processauthorreq',
1.385 bisitz 4866: text => 'Authoring Space requests',
1.362 raeburn 4867: help => 'Domain_Role_Approvals'});
4868: $bread_crumbs_component = 'Authoring requests';
4869: if ($env{'form.state'} eq 'done') {
4870: push(@{$brcrum},
4871: {href => '/adm/createuser?action=authorreqqueue',
4872: text => 'Result',
4873: help => 'Domain_Role_Approvals'});
4874: $bread_crumbs_component = 'Authoring request result';
4875: }
4876: $args = { bread_crumbs => $brcrum,
4877: bread_crumbs_component => $bread_crumbs_component};
1.391 raeburn 4878: my $js = &usernamerequest_javascript();
4879: $r->print(&header(&add_script($js),$args));
1.362 raeburn 4880: if (!exists($env{'form.state'})) {
4881: $r->print(&Apache::loncoursequeueadmin::display_queued_requests('requestauthor',
4882: $env{'request.role.domain'}));
4883: } elsif ($env{'form.state'} eq 'done') {
4884: $r->print('<h3>'.&mt('Authoring request processing').'</h3>'."\n");
4885: $r->print(&Apache::loncoursequeueadmin::update_request_queue('requestauthor',
4886: $env{'request.role.domain'}));
4887: }
1.391 raeburn 4888: } elsif (($env{'form.action'} eq 'processusernamereq') &&
4889: ($permission->{'cusr'}) &&
4890: (&Apache::lonnet::allowed('cau',$env{'request.role.domain'}))) {
4891: push(@{$brcrum},
4892: {href => '/adm/createuser?action=processusernamereq',
4893: text => 'LON-CAPA account requests',
4894: help => 'Domain_Username_Approvals'});
4895: $bread_crumbs_component = 'Account requests';
4896: if ($env{'form.state'} eq 'done') {
4897: push(@{$brcrum},
4898: {href => '/adm/createuser?action=usernamereqqueue',
4899: text => 'Result',
4900: help => 'Domain_Username_Approvals'});
4901: $bread_crumbs_component = 'LON-CAPA account request result';
4902: }
4903: $args = { bread_crumbs => $brcrum,
4904: bread_crumbs_component => $bread_crumbs_component};
4905: my $js = &usernamerequest_javascript();
4906: $r->print(&header(&add_script($js),$args));
4907: if (!exists($env{'form.state'})) {
4908: $r->print(&Apache::loncoursequeueadmin::display_queued_requests('requestusername',
4909: $env{'request.role.domain'}));
4910: } elsif ($env{'form.state'} eq 'done') {
4911: $r->print('<h3>'.&mt('LON-CAPA account request processing').'</h3>'."\n");
4912: $r->print(&Apache::loncoursequeueadmin::update_request_queue('requestusername',
4913: $env{'request.role.domain'}));
4914: }
4915: } elsif (($env{'form.action'} eq 'displayuserreq') &&
4916: ($permission->{'cusr'})) {
4917: my $dom = $env{'form.domain'};
4918: my $uname = $env{'form.username'};
4919: my $warning;
4920: if (($dom =~ /^$match_domain$/) && (&Apache::lonnet::domain($dom) ne '')) {
4921: if (($dom eq $env{'request.role.domain'}) && (&Apache::lonnet::allowed('ccc',$dom))) {
4922: if (($uname =~ /^$match_username$/) && ($env{'form.queue'} eq 'approval')) {
4923: my $uhome = &Apache::lonnet::homeserver($uname,$dom);
4924: if ($uhome eq 'no_host') {
4925: my $queue = $env{'form.queue'};
4926: my $reqkey = &escape($uname).'_'.$queue;
4927: my $namespace = 'usernamequeue';
4928: my $domconfig = &Apache::lonnet::get_domainconfiguser($dom);
4929: my %queued =
4930: &Apache::lonnet::get($namespace,[$reqkey],$dom,$domconfig);
4931: unless ($queued{$reqkey}) {
4932: $warning = &mt('No information was found for this LON-CAPA account request.');
4933: }
4934: } else {
4935: $warning = &mt('A LON-CAPA account already exists for the requested username and domain.');
4936: }
4937: } else {
4938: $warning = &mt('LON-CAPA account request status check is for an invalid username.');
4939: }
4940: } else {
4941: $warning = &mt('You do not have rights to view LON-CAPA account requests in the domain specified.');
4942: }
4943: } else {
4944: $warning = &mt('LON-CAPA account request status check is for an invalid domain.');
4945: }
4946: my $args = { only_body => 1 };
4947: $r->print(&header(undef,$args).
4948: '<h3>'.&mt('LON-CAPA Account Request Details').'</h3>');
4949: if ($warning ne '') {
4950: $r->print('<div class="LC_warning">'.$warning.'</div>');
4951: } else {
4952: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
4953: my $domconfiguser = &Apache::lonnet::get_domainconfiguser($dom);
4954: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
4955: if (ref($domconfig{'usercreation'}) eq 'HASH') {
4956: if (ref($domconfig{'usercreation'}{'cancreate'}) eq 'HASH') {
4957: if (ref($domconfig{'usercreation'}{'cancreate'}{'emailusername'}) eq 'HASH') {
4958: my %info =
4959: &Apache::lonnet::get('nohist_requestedusernames',[$uname],$dom,$domconfiguser);
4960: if (ref($info{$uname}) eq 'HASH') {
1.396 raeburn 4961: my $usertype = $info{$uname}{'inststatus'};
4962: unless ($usertype) {
4963: $usertype = 'default';
4964: }
1.442 raeburn 4965: my ($showstatus,$showemail,$pickstart);
4966: my $numextras = 0;
4967: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.443 ! raeburn 4968: if ((ref($types) eq 'ARRAY') && (@{$types} > 0)) {
! 4969: if (ref($usertypes) eq 'HASH') {
! 4970: if ($usertypes->{$usertype}) {
! 4971: $showstatus = $usertypes->{$usertype};
! 4972: } else {
! 4973: $showstatus = $othertitle;
! 4974: }
! 4975: if ($showstatus) {
! 4976: $numextras ++;
! 4977: }
1.442 raeburn 4978: }
4979: }
4980: if (($info{$uname}{'email'} ne '') && ($info{$uname}{'email'} ne $uname)) {
4981: $showemail = $info{$uname}{'email'};
4982: $numextras ++;
4983: }
1.396 raeburn 4984: if (ref($domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}) eq 'HASH') {
4985: if ((ref($infofields) eq 'ARRAY') && (ref($infotitles) eq 'HASH')) {
1.442 raeburn 4986: $pickstart = 1;
1.396 raeburn 4987: $r->print('<div>'.&Apache::lonhtmlcommon::start_pick_box());
1.442 raeburn 4988: my ($num,$count);
1.396 raeburn 4989: $count = scalar(keys(%{$domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}}));
1.442 raeburn 4990: $count += $numextras;
1.396 raeburn 4991: foreach my $field (@{$infofields}) {
4992: next unless ($domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}{$field});
4993: next unless ($infotitles->{$field});
4994: $r->print(&Apache::lonhtmlcommon::row_title($infotitles->{$field}).
4995: $info{$uname}{$field});
4996: $num ++;
1.442 raeburn 4997: unless ($count == $num) {
1.396 raeburn 4998: $r->print(&Apache::lonhtmlcommon::row_closure());
4999: }
5000: }
1.442 raeburn 5001: }
5002: }
5003: if ($numextras) {
5004: unless ($pickstart) {
5005: $r->print('<div>'.&Apache::lonhtmlcommon::start_pick_box());
5006: $pickstart = 1;
5007: }
5008: if ($showemail) {
5009: my $closure = '';
5010: unless ($showstatus) {
5011: $closure = 1;
1.391 raeburn 5012: }
1.442 raeburn 5013: $r->print(&Apache::lonhtmlcommon::row_title(&mt('E-mail address')).
5014: $showemail.
5015: &Apache::lonhtmlcommon::row_closure($closure));
1.391 raeburn 5016: }
1.442 raeburn 5017: if ($showstatus) {
5018: $r->print(&Apache::lonhtmlcommon::row_title(&mt('Status type[_1](self-reported)','<br />')).
5019: $showstatus.
5020: &Apache::lonhtmlcommon::row_closure(1));
5021: }
5022: }
5023: if ($pickstart) {
5024: $r->print(&Apache::lonhtmlcommon::end_pick_box().'</div>');
5025: } else {
5026: $r->print('<div>'.&mt('No information to display for this account request.').'</div>');
1.391 raeburn 5027: }
1.442 raeburn 5028: } else {
5029: $r->print('<div>'.&mt('No information available for this account request.').'</div>');
1.391 raeburn 5030: }
5031: }
5032: }
5033: }
5034: }
1.442 raeburn 5035: $r->print(&close_popup_form());
1.207 raeburn 5036: } elsif (($env{'form.action'} eq 'listusers') &&
5037: ($permission->{'view'} || $permission->{'cusr'})) {
1.439 raeburn 5038: my $helpitem = 'Course_View_Class_List';
5039: if ($context eq 'author') {
5040: $helpitem = 'Author_View_Coauthor_List';
5041: } elsif ($context eq 'domain') {
5042: $helpitem = 'Domain_View_Users_List';
5043: }
1.202 raeburn 5044: if ($env{'form.phase'} eq 'bulkchange') {
1.351 raeburn 5045: push(@{$brcrum},
5046: {href => '/adm/createuser?action=listusers',
5047: text => "List Users"},
5048: {href => "/adm/createuser",
5049: text => "Result",
1.439 raeburn 5050: help => $helpitem});
1.351 raeburn 5051: $bread_crumbs_component = 'Update Users';
5052: $args = {bread_crumbs => $brcrum,
5053: bread_crumbs_component => $bread_crumbs_component};
5054: $r->print(&header(undef,$args));
1.202 raeburn 5055: my $setting = $env{'form.roletype'};
5056: my $choice = $env{'form.bulkaction'};
5057: if ($permission->{'cusr'}) {
1.336 raeburn 5058: &Apache::lonuserutils::update_user_list($r,$context,$setting,$choice,$crstype);
1.221 raeburn 5059: } else {
5060: $r->print(&mt('You are not authorized to make bulk changes to user roles'));
1.223 raeburn 5061: $r->print('<p><a href="/adm/createuser?action=listusers">'.&mt('Display User Lists').'</a>');
1.202 raeburn 5062: }
5063: } else {
1.351 raeburn 5064: push(@{$brcrum},
5065: {href => '/adm/createuser?action=listusers',
5066: text => "List Users",
1.439 raeburn 5067: help => $helpitem});
1.351 raeburn 5068: $bread_crumbs_component = 'List Users';
5069: $args = {bread_crumbs => $brcrum,
5070: bread_crumbs_component => $bread_crumbs_component};
1.202 raeburn 5071: my ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles);
5072: my $formname = 'studentform';
1.364 raeburn 5073: my $hidecall = "hide_searching();";
1.321 raeburn 5074: if (($context eq 'domain') && (($env{'form.roletype'} eq 'course') ||
5075: ($env{'form.roletype'} eq 'community'))) {
5076: if ($env{'form.roletype'} eq 'course') {
5077: ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles) =
5078: &Apache::lonuserutils::courses_selector($env{'request.role.domain'},
5079: $formname);
5080: } elsif ($env{'form.roletype'} eq 'community') {
5081: $cb_jscript =
5082: &Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
5083: my %elements = (
5084: coursepick => 'radio',
5085: coursetotal => 'text',
5086: courselist => 'text',
5087: );
5088: $jscript = &Apache::lonhtmlcommon::set_form_elements(\%elements);
5089: }
1.364 raeburn 5090: $jscript .= &verify_user_display($context)."\n".
5091: &Apache::loncommon::check_uncheck_jscript();
1.202 raeburn 5092: my $js = &add_script($jscript).$cb_jscript;
5093: my $loadcode =
5094: &Apache::lonuserutils::course_selector_loadcode($formname);
5095: if ($loadcode ne '') {
1.364 raeburn 5096: $args->{add_entries} = {onload => "$loadcode;$hidecall"};
5097: } else {
5098: $args->{add_entries} = {onload => $hidecall};
1.202 raeburn 5099: }
1.351 raeburn 5100: $r->print(&header($js,$args));
1.191 raeburn 5101: } else {
1.364 raeburn 5102: $args->{add_entries} = {onload => $hidecall};
5103: $jscript = &verify_user_display($context).
5104: &Apache::loncommon::check_uncheck_jscript();
5105: $r->print(&header(&add_script($jscript),$args));
1.191 raeburn 5106: }
1.202 raeburn 5107: &Apache::lonuserutils::print_userlist($r,undef,$permission,$context,
1.375 raeburn 5108: $formname,$totcodes,$codetitles,$idlist,$idlist_titles,
5109: $showcredits);
1.191 raeburn 5110: }
1.213 raeburn 5111: } elsif ($env{'form.action'} eq 'drop' && $permission->{'cusr'}) {
1.318 raeburn 5112: my $brtext;
5113: if ($crstype eq 'Community') {
5114: $brtext = 'Drop Members';
5115: } else {
5116: $brtext = 'Drop Students';
5117: }
1.351 raeburn 5118: push(@{$brcrum},
5119: {href => '/adm/createuser?action=drop',
5120: text => $brtext,
5121: help => 'Course_Drop_Student'});
5122: if ($env{'form.state'} eq 'done') {
5123: push(@{$brcrum},
5124: {href=>'/adm/createuser?action=drop',
5125: text=>"Result"});
5126: }
5127: $bread_crumbs_component = $brtext;
5128: $args = {bread_crumbs => $brcrum,
5129: bread_crumbs_component => $bread_crumbs_component};
5130: $r->print(&header(undef,$args));
1.213 raeburn 5131: if (!exists($env{'form.state'})) {
1.318 raeburn 5132: &Apache::lonuserutils::print_drop_menu($r,$context,$permission,$crstype);
1.213 raeburn 5133: } elsif ($env{'form.state'} eq 'done') {
5134: &Apache::lonuserutils::update_user_list($r,$context,undef,
5135: $env{'form.action'});
5136: }
1.202 raeburn 5137: } elsif ($env{'form.action'} eq 'dateselect') {
5138: if ($permission->{'cusr'}) {
1.351 raeburn 5139: $r->print(&header(undef,{'no_nav_bar' => 1}).
1.375 raeburn 5140: &Apache::lonuserutils::date_section_selector($context,$permission,
5141: $crstype,$showcredits));
1.202 raeburn 5142: } else {
1.351 raeburn 5143: $r->print(&header(undef,{'no_nav_bar' => 1}).
5144: '<span class="LC_error">'.&mt('You do not have permission to modify dates or sections for users').'</span>');
1.202 raeburn 5145: }
1.237 raeburn 5146: } elsif ($env{'form.action'} eq 'selfenroll') {
1.398 raeburn 5147: if ($permission->{selfenrolladmin}) {
5148: my %currsettings = (
5149: selfenroll_types => $env{'course.'.$cid.'.internal.selfenroll_types'},
5150: selfenroll_registered => $env{'course.'.$cid.'.internal.selfenroll_registered'},
5151: selfenroll_section => $env{'course.'.$cid.'.internal.selfenroll_section'},
5152: selfenroll_notifylist => $env{'course.'.$cid.'.internal.selfenroll_notifylist'},
5153: selfenroll_approval => $env{'course.'.$cid.'.internal.selfenroll_approval'},
5154: selfenroll_limit => $env{'course.'.$cid.'.internal.selfenroll_limit'},
5155: selfenroll_cap => $env{'course.'.$cid.'.internal.selfenroll_cap'},
5156: selfenroll_start_date => $env{'course.'.$cid.'.internal.selfenroll_start_date'},
5157: selfenroll_end_date => $env{'course.'.$cid.'.internal.selfenroll_end_date'},
5158: selfenroll_start_access => $env{'course.'.$cid.'.internal.selfenroll_start_access'},
5159: selfenroll_end_access => $env{'course.'.$cid.'.internal.selfenroll_end_access'},
5160: default_enrollment_start_date => $env{'course.'.$cid.'.default_enrollment_start_date'},
5161: default_enrollment_end_date => $env{'course.'.$cid.'.default_enrollment_end_date'},
1.400 raeburn 5162: uniquecode => $env{'course.'.$cid.'.internal.uniquecode'},
1.398 raeburn 5163: );
5164: push(@{$brcrum},
5165: {href => '/adm/createuser?action=selfenroll',
5166: text => "Configure Self-enrollment",
5167: help => 'Course_Self_Enrollment'});
5168: if (!exists($env{'form.state'})) {
5169: $args = { bread_crumbs => $brcrum,
5170: bread_crumbs_component => 'Configure Self-enrollment'};
5171: $r->print(&header(undef,$args));
5172: $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n");
5173: &print_selfenroll_menu($r,'course',$cid,$cdom,$cnum,\%currsettings);
5174: } elsif ($env{'form.state'} eq 'done') {
5175: push (@{$brcrum},
5176: {href=>'/adm/createuser?action=selfenroll',
5177: text=>"Result"});
5178: $args = { bread_crumbs => $brcrum,
5179: bread_crumbs_component => 'Self-enrollment result'};
5180: $r->print(&header(undef,$args));
5181: $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n");
1.400 raeburn 5182: &update_selfenroll_config($r,$cid,$cdom,$cnum,$context,$crstype,\%currsettings);
1.398 raeburn 5183: }
5184: } else {
5185: $r->print(&header(undef,{'no_nav_bar' => 1}).
5186: '<span class="LC_error">'.&mt('You do not have permission to configure self-enrollment').'</span>');
1.237 raeburn 5187: }
1.277 raeburn 5188: } elsif ($env{'form.action'} eq 'selfenrollqueue') {
1.418 raeburn 5189: if ($permission->{selfenrolladmin}) {
1.351 raeburn 5190: push(@{$brcrum},
5191: {href => '/adm/createuser?action=selfenrollqueue',
1.418 raeburn 5192: text => 'Enrollment requests',
1.439 raeburn 5193: help => 'Course_Approve_Selfenroll'});
1.418 raeburn 5194: $bread_crumbs_component = 'Enrollment requests';
5195: if ($env{'form.state'} eq 'done') {
5196: push(@{$brcrum},
5197: {href => '/adm/createuser?action=selfenrollqueue',
5198: text => 'Result',
1.439 raeburn 5199: help => 'Course_Approve_Selfenroll'});
1.418 raeburn 5200: $bread_crumbs_component = 'Enrollment result';
5201: }
5202: $args = { bread_crumbs => $brcrum,
5203: bread_crumbs_component => $bread_crumbs_component};
5204: $r->print(&header(undef,$args));
5205: my $coursedesc = $env{'course.'.$cid.'.description'};
5206: if (!exists($env{'form.state'})) {
5207: $r->print('<h3>'.&mt('Pending enrollment requests').'</h3>'."\n");
5208: $r->print(&Apache::loncoursequeueadmin::display_queued_requests($context,
5209: $cdom,$cnum));
5210: } elsif ($env{'form.state'} eq 'done') {
5211: $r->print('<h3>'.&mt('Enrollment request processing').'</h3>'."\n");
5212: $r->print(&Apache::loncoursequeueadmin::update_request_queue($context,
1.430 raeburn 5213: $cdom,$cnum,$coursedesc));
1.418 raeburn 5214: }
5215: } else {
5216: $r->print(&header(undef,{'no_nav_bar' => 1}).
5217: '<span class="LC_error">'.&mt('You do not have permission to manage self-enrollment').'</span>');
1.351 raeburn 5218: }
1.418 raeburn 5219: } elsif ($env{'form.action'} eq 'changelogs') {
5220: if ($permission->{cusr} || $permission->{view}) {
5221: &print_userchangelogs_display($r,$context,$permission,$brcrum);
5222: } else {
5223: $r->print(&header(undef,{'no_nav_bar' => 1}).
5224: '<span class="LC_error">'.&mt('You do not have permission to view change logs').'</span>');
1.277 raeburn 5225: }
1.428 raeburn 5226: } elsif ($env{'form.action'} eq 'helpdesk') {
5227: if (($permission->{'owner'}) || ($permission->{'co-owner'})) {
5228: if ($env{'form.state'} eq 'process') {
5229: if ($permission->{'owner'}) {
5230: &update_helpdeskaccess($r,$permission,$brcrum);
5231: } else {
5232: &print_helpdeskaccess_display($r,$permission,$brcrum);
1.430 raeburn 5233: }
1.428 raeburn 5234: } else {
5235: &print_helpdeskaccess_display($r,$permission,$brcrum);
5236: }
5237: } else {
5238: $r->print(&header(undef,{'no_nav_bar' => 1}).
5239: '<span class="LC_error">'.&mt('You do not have permission to view helpdesk access').'</span>');
5240: }
1.190 raeburn 5241: } else {
1.351 raeburn 5242: $bread_crumbs_component = 'User Management';
5243: $args = { bread_crumbs => $brcrum,
5244: bread_crumbs_component => $bread_crumbs_component};
5245: $r->print(&header(undef,$args));
1.318 raeburn 5246: $r->print(&print_main_menu($permission,$context,$crstype));
1.190 raeburn 5247: }
1.351 raeburn 5248: $r->print(&Apache::loncommon::end_page());
1.190 raeburn 5249: return OK;
5250: }
5251:
5252: sub header {
1.351 raeburn 5253: my ($jscript,$args) = @_;
1.190 raeburn 5254: my $start_page;
1.351 raeburn 5255: if (ref($args) eq 'HASH') {
5256: $start_page=&Apache::loncommon::start_page('User Management',$jscript,$args);
1.190 raeburn 5257: } else {
1.351 raeburn 5258: $start_page=&Apache::loncommon::start_page('User Management',$jscript);
1.190 raeburn 5259: }
5260: return $start_page;
5261: }
1.2 www 5262:
1.191 raeburn 5263: sub add_script {
5264: my ($js) = @_;
1.301 bisitz 5265: return '<script type="text/javascript">'."\n"
5266: .'// <![CDATA['."\n"
5267: .$js."\n"
5268: .'// ]]>'."\n"
5269: .'</script>'."\n";
1.191 raeburn 5270: }
5271:
1.391 raeburn 5272: sub usernamerequest_javascript {
5273: my $js = <<ENDJS;
5274:
5275: function openusernamereqdisplay(dom,uname,queue) {
5276: var url = '/adm/createuser?action=displayuserreq';
5277: url += '&domain='+dom+'&username='+uname+'&queue='+queue;
5278: var title = 'Account_Request_Browser';
5279: var options = 'scrollbars=1,resizable=1,menubar=0';
5280: options += ',width=700,height=600';
5281: var stdeditbrowser = open(url,title,options,'1');
5282: stdeditbrowser.focus();
5283: return;
5284: }
5285:
5286: ENDJS
5287: }
5288:
5289: sub close_popup_form {
5290: my $close= &mt('Close Window');
5291: return << "END";
5292: <p><form name="displayreq" action="" method="post">
5293: <input type="button" name="closeme" value="$close" onclick="javascript:self.close();" />
5294: </form></p>
5295: END
5296: }
5297:
1.202 raeburn 5298: sub verify_user_display {
1.364 raeburn 5299: my ($context) = @_;
1.374 raeburn 5300: my %lt = &Apache::lonlocal::texthash (
5301: course => 'course(s): description, section(s), status',
5302: community => 'community(s): description, section(s), status',
5303: author => 'author',
5304: );
1.364 raeburn 5305: my $photos;
5306: if (($context eq 'course') && $env{'request.course.id'}) {
5307: $photos = $env{'course.'.$env{'request.course.id'}.'.internal.showphoto'};
5308: }
1.202 raeburn 5309: my $output = <<"END";
5310:
1.364 raeburn 5311: function hide_searching() {
5312: if (document.getElementById('searching')) {
5313: document.getElementById('searching').style.display = 'none';
5314: }
5315: return;
5316: }
5317:
1.202 raeburn 5318: function display_update() {
5319: document.studentform.action.value = 'listusers';
5320: document.studentform.phase.value = 'display';
5321: document.studentform.submit();
5322: }
5323:
1.364 raeburn 5324: function updateCols(caller) {
5325: var context = '$context';
5326: var photos = '$photos';
5327: if (caller == 'Status') {
1.374 raeburn 5328: if ((context == 'domain') &&
5329: ((document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'course') ||
5330: (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community'))) {
1.364 raeburn 5331: document.getElementById('showcolstatus').checked = false;
5332: document.getElementById('showcolstatus').disabled = 'disabled';
5333: document.getElementById('showcolstart').checked = false;
5334: document.getElementById('showcolend').checked = false;
1.374 raeburn 5335: } else {
5336: if (document.studentform.Status.options[document.studentform.Status.selectedIndex].value == 'Any') {
5337: document.getElementById('showcolstatus').checked = true;
5338: document.getElementById('showcolstatus').disabled = '';
5339: document.getElementById('showcolstart').checked = true;
5340: document.getElementById('showcolend').checked = true;
5341: } else {
5342: document.getElementById('showcolstatus').checked = false;
5343: document.getElementById('showcolstatus').disabled = 'disabled';
5344: document.getElementById('showcolstart').checked = false;
5345: document.getElementById('showcolend').checked = false;
5346: }
1.364 raeburn 5347: }
5348: }
5349: if (caller == 'output') {
5350: if (photos == 1) {
5351: if (document.getElementById('showcolphoto')) {
5352: var photoitem = document.getElementById('showcolphoto');
5353: if (document.studentform.output.options[document.studentform.output.selectedIndex].value == 'html') {
5354: photoitem.checked = true;
5355: photoitem.disabled = '';
5356: } else {
5357: photoitem.checked = false;
5358: photoitem.disabled = 'disabled';
5359: }
5360: }
5361: }
5362: }
5363: if (caller == 'showrole') {
1.371 raeburn 5364: if ((document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'Any') ||
5365: (document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'cr')) {
1.364 raeburn 5366: document.getElementById('showcolrole').checked = true;
5367: document.getElementById('showcolrole').disabled = '';
5368: } else {
5369: document.getElementById('showcolrole').checked = false;
5370: document.getElementById('showcolrole').disabled = 'disabled';
5371: }
1.374 raeburn 5372: if (context == 'domain') {
1.382 raeburn 5373: var quotausageshow = 0;
1.374 raeburn 5374: if ((document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'course') ||
5375: (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community')) {
5376: document.getElementById('showcolstatus').checked = false;
5377: document.getElementById('showcolstatus').disabled = 'disabled';
5378: document.getElementById('showcolstart').checked = false;
5379: document.getElementById('showcolend').checked = false;
5380: } else {
5381: if (document.studentform.Status.options[document.studentform.Status.selectedIndex].value == 'Any') {
5382: document.getElementById('showcolstatus').checked = true;
5383: document.getElementById('showcolstatus').disabled = '';
5384: document.getElementById('showcolstart').checked = true;
5385: document.getElementById('showcolend').checked = true;
5386: }
5387: }
5388: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'domain') {
5389: document.getElementById('showcolextent').disabled = 'disabled';
5390: document.getElementById('showcolextent').checked = 'false';
5391: document.getElementById('showextent').style.display='none';
5392: document.getElementById('showcoltextextent').innerHTML = '';
1.382 raeburn 5393: if ((document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'au') ||
5394: (document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'Any')) {
5395: if (document.getElementById('showcolauthorusage')) {
5396: document.getElementById('showcolauthorusage').disabled = '';
5397: }
5398: if (document.getElementById('showcolauthorquota')) {
5399: document.getElementById('showcolauthorquota').disabled = '';
5400: }
5401: quotausageshow = 1;
5402: }
1.374 raeburn 5403: } else {
5404: document.getElementById('showextent').style.display='block';
5405: document.getElementById('showextent').style.textAlign='left';
5406: document.getElementById('showextent').style.textFace='normal';
5407: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'author') {
5408: document.getElementById('showcolextent').disabled = '';
5409: document.getElementById('showcolextent').checked = 'true';
5410: document.getElementById('showcoltextextent').innerHTML="$lt{'author'}";
5411: } else {
5412: document.getElementById('showcolextent').disabled = '';
5413: document.getElementById('showcolextent').checked = 'true';
5414: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community') {
5415: document.getElementById('showcoltextextent').innerHTML="$lt{'community'}";
5416: } else {
5417: document.getElementById('showcoltextextent').innerHTML="$lt{'course'}";
5418: }
5419: }
5420: }
1.382 raeburn 5421: if (quotausageshow == 0) {
5422: if (document.getElementById('showcolauthorusage')) {
5423: document.getElementById('showcolauthorusage').checked = false;
5424: document.getElementById('showcolauthorusage').disabled = 'disabled';
5425: }
5426: if (document.getElementById('showcolauthorquota')) {
5427: document.getElementById('showcolauthorquota').checked = false;
5428: document.getElementById('showcolauthorquota').disabled = 'disabled';
5429: }
5430: }
1.374 raeburn 5431: }
1.364 raeburn 5432: }
5433: return;
5434: }
5435:
1.202 raeburn 5436: END
5437: return $output;
5438:
5439: }
5440:
1.190 raeburn 5441: ###############################################################
5442: ###############################################################
5443: # Menu Phase One
5444: sub print_main_menu {
1.318 raeburn 5445: my ($permission,$context,$crstype) = @_;
5446: my $linkcontext = $context;
5447: my $stuterm = lc(&Apache::lonnet::plaintext('st',$crstype));
5448: if (($context eq 'course') && ($crstype eq 'Community')) {
5449: $linkcontext = lc($crstype);
5450: $stuterm = 'Members';
5451: }
1.208 raeburn 5452: my %links = (
1.298 droeschl 5453: domain => {
5454: upload => 'Upload a File of Users',
5455: singleuser => 'Add/Modify a User',
5456: listusers => 'Manage Users',
5457: },
5458: author => {
5459: upload => 'Upload a File of Co-authors',
5460: singleuser => 'Add/Modify a Co-author',
5461: listusers => 'Manage Co-authors',
5462: },
5463: course => {
5464: upload => 'Upload a File of Course Users',
5465: singleuser => 'Add/Modify a Course User',
1.354 www 5466: listusers => 'List and Modify Multiple Course Users',
1.298 droeschl 5467: },
1.318 raeburn 5468: community => {
5469: upload => 'Upload a File of Community Users',
5470: singleuser => 'Add/Modify a Community User',
1.354 www 5471: listusers => 'List and Modify Multiple Community Users',
1.318 raeburn 5472: },
5473: );
5474: my %linktitles = (
5475: domain => {
5476: singleuser => 'Add a user to the domain, and/or a course or community in the domain.',
5477: listusers => 'Show and manage users in this domain.',
5478: },
5479: author => {
5480: singleuser => 'Add a user with a co- or assistant author role.',
5481: listusers => 'Show and manage co- or assistant authors.',
5482: },
5483: course => {
5484: singleuser => 'Add a user with a certain role to this course.',
5485: listusers => 'Show and manage users in this course.',
5486: },
5487: community => {
5488: singleuser => 'Add a user with a certain role to this community.',
5489: listusers => 'Show and manage users in this community.',
5490: },
1.298 droeschl 5491: );
1.418 raeburn 5492: if ($linkcontext eq 'domain') {
5493: unless ($permission->{'cusr'}) {
1.430 raeburn 5494: $links{'domain'}{'singleuser'} = 'View a User';
1.418 raeburn 5495: $linktitles{'domain'}{'singleuser'} = 'View information about a user in the domain';
5496: }
5497: } elsif ($linkcontext eq 'course') {
5498: unless ($permission->{'cusr'}) {
5499: $links{'course'}{'singleuser'} = 'View a Course User';
5500: $linktitles{'course'}{'singleuser'} = 'View information about a user in this course';
5501: $links{'course'}{'listusers'} = 'List Course Users';
5502: $linktitles{'course'}{'listusers'} = 'Show information about users in this course';
5503: }
5504: } elsif ($linkcontext eq 'community') {
5505: unless ($permission->{'cusr'}) {
5506: $links{'community'}{'singleuser'} = 'View a Community User';
5507: $linktitles{'community'}{'singleuser'} = 'View information about a user in this community';
5508: $links{'community'}{'listusers'} = 'List Community Users';
5509: $linktitles{'community'}{'listusers'} = 'Show information about users in this community';
5510: }
5511: }
1.298 droeschl 5512: my @menu = ( {categorytitle => 'Single Users',
5513: items =>
5514: [
5515: {
1.318 raeburn 5516: linktext => $links{$linkcontext}{'singleuser'},
1.298 droeschl 5517: icon => 'edit-redo.png',
5518: #help => 'Course_Change_Privileges',
5519: url => '/adm/createuser?action=singleuser',
1.418 raeburn 5520: permission => ($permission->{'view'} || $permission->{'cusr'}),
1.318 raeburn 5521: linktitle => $linktitles{$linkcontext}{'singleuser'},
1.298 droeschl 5522: },
5523: ]},
5524:
5525: {categorytitle => 'Multiple Users',
5526: items =>
5527: [
5528: {
1.318 raeburn 5529: linktext => $links{$linkcontext}{'upload'},
1.340 wenzelju 5530: icon => 'uplusr.png',
1.298 droeschl 5531: #help => 'Course_Create_Class_List',
5532: url => '/adm/createuser?action=upload',
5533: permission => $permission->{'cusr'},
5534: linktitle => 'Upload a CSV or a text file containing users.',
5535: },
5536: {
1.318 raeburn 5537: linktext => $links{$linkcontext}{'listusers'},
1.340 wenzelju 5538: icon => 'mngcu.png',
1.298 droeschl 5539: #help => 'Course_View_Class_List',
5540: url => '/adm/createuser?action=listusers',
5541: permission => ($permission->{'view'} || $permission->{'cusr'}),
1.318 raeburn 5542: linktitle => $linktitles{$linkcontext}{'listusers'},
1.298 droeschl 5543: },
5544:
5545: ]},
5546:
5547: {categorytitle => 'Administration',
5548: items => [ ]},
5549: );
1.415 raeburn 5550:
1.265 mielkec 5551: if ($context eq 'domain'){
1.416 raeburn 5552: push(@{ $menu[0]->{items} }, # Single Users
5553: {
5554: linktext => 'User Access Log',
1.417 raeburn 5555: icon => 'document-properties.png',
1.425 raeburn 5556: #help => 'Domain_User_Access_Logs',
1.416 raeburn 5557: url => '/adm/createuser?action=accesslogs',
5558: permission => $permission->{'activity'},
5559: linktitle => 'View user access log.',
5560: }
5561: );
1.298 droeschl 5562:
5563: push(@{ $menu[2]->{items} }, #Category: Administration
5564: {
5565: linktext => 'Custom Roles',
5566: icon => 'emblem-photos.png',
5567: #help => 'Course_Editing_Custom_Roles',
5568: url => '/adm/createuser?action=custom',
5569: permission => $permission->{'custom'},
5570: linktitle => 'Configure a custom role.',
5571: },
1.362 raeburn 5572: {
5573: linktext => 'Authoring Space Requests',
5574: icon => 'selfenrl-queue.png',
5575: #help => 'Domain_Role_Approvals',
5576: url => '/adm/createuser?action=processauthorreq',
5577: permission => $permission->{'cusr'},
5578: linktitle => 'Approve or reject author role requests',
5579: },
1.363 raeburn 5580: {
1.391 raeburn 5581: linktext => 'LON-CAPA Account Requests',
5582: icon => 'list-add.png',
5583: #help => 'Domain_Username_Approvals',
5584: url => '/adm/createuser?action=processusernamereq',
5585: permission => $permission->{'cusr'},
5586: linktitle => 'Approve or reject LON-CAPA account requests',
5587: },
5588: {
1.363 raeburn 5589: linktext => 'Change Log',
5590: icon => 'document-properties.png',
5591: #help => 'Course_User_Logs',
5592: url => '/adm/createuser?action=changelogs',
1.418 raeburn 5593: permission => ($permission->{'cusr'} || $permission->{'view'}),
1.363 raeburn 5594: linktitle => 'View change log.',
5595: },
1.298 droeschl 5596: );
5597:
1.265 mielkec 5598: }elsif ($context eq 'course'){
1.298 droeschl 5599: my ($cnum,$cdom) = &Apache::lonuserutils::get_course_identity();
1.318 raeburn 5600:
5601: my %linktext = (
5602: 'Course' => {
5603: single => 'Add/Modify a Student',
5604: drop => 'Drop Students',
5605: groups => 'Course Groups',
5606: },
5607: 'Community' => {
5608: single => 'Add/Modify a Member',
5609: drop => 'Drop Members',
5610: groups => 'Community Groups',
5611: },
5612: );
1.411 raeburn 5613: $linktext{'Placement'} = $linktext{'Course'};
1.318 raeburn 5614:
5615: my %linktitle = (
5616: 'Course' => {
5617: single => 'Add a user with the role of student to this course',
5618: drop => 'Remove a student from this course.',
5619: groups => 'Manage course groups',
5620: },
5621: 'Community' => {
5622: single => 'Add a user with the role of member to this community',
5623: drop => 'Remove a member from this community.',
5624: groups => 'Manage community groups',
5625: },
5626: );
5627:
1.411 raeburn 5628: $linktitle{'Placement'} = $linktitle{'Course'};
5629:
1.298 droeschl 5630: push(@{ $menu[0]->{items} }, #Category: Single Users
5631: {
1.318 raeburn 5632: linktext => $linktext{$crstype}{'single'},
1.298 droeschl 5633: #help => 'Course_Add_Student',
5634: icon => 'list-add.png',
5635: url => '/adm/createuser?action=singlestudent',
5636: permission => $permission->{'cusr'},
1.318 raeburn 5637: linktitle => $linktitle{$crstype}{'single'},
1.298 droeschl 5638: },
5639: );
5640:
5641: push(@{ $menu[1]->{items} }, #Category: Multiple Users
5642: {
1.318 raeburn 5643: linktext => $linktext{$crstype}{'drop'},
1.298 droeschl 5644: icon => 'edit-undo.png',
5645: #help => 'Course_Drop_Student',
5646: url => '/adm/createuser?action=drop',
5647: permission => $permission->{'cusr'},
1.318 raeburn 5648: linktitle => $linktitle{$crstype}{'drop'},
1.298 droeschl 5649: },
5650: );
5651: push(@{ $menu[2]->{items} }, #Category: Administration
1.428 raeburn 5652: {
5653: linktext => 'Helpdesk Access',
5654: icon => 'helpdesk-access.png',
5655: #help => 'Course_Helpdesk_Access',
5656: url => '/adm/createuser?action=helpdesk',
5657: permission => ($permission->{'owner'} || $permission->{'co-owner'}),
5658: linktitle => 'Helpdesk access options',
5659: },
5660: {
1.298 droeschl 5661: linktext => 'Custom Roles',
5662: icon => 'emblem-photos.png',
5663: #help => 'Course_Editing_Custom_Roles',
5664: url => '/adm/createuser?action=custom',
5665: permission => $permission->{'custom'},
5666: linktitle => 'Configure a custom role.',
5667: },
5668: {
1.318 raeburn 5669: linktext => $linktext{$crstype}{'groups'},
1.333 wenzelju 5670: icon => 'grps.png',
1.298 droeschl 5671: #help => 'Course_Manage_Group',
5672: url => '/adm/coursegroups?refpage=cusr',
5673: permission => $permission->{'grp_manage'},
1.318 raeburn 5674: linktitle => $linktitle{$crstype}{'groups'},
1.298 droeschl 5675: },
5676: {
1.328 wenzelju 5677: linktext => 'Change Log',
1.298 droeschl 5678: icon => 'document-properties.png',
5679: #help => 'Course_User_Logs',
5680: url => '/adm/createuser?action=changelogs',
1.418 raeburn 5681: permission => ($permission->{'view'} || $permission->{'cusr'}),
1.298 droeschl 5682: linktitle => 'View change log.',
5683: },
5684: );
1.277 raeburn 5685: if ($env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_approval'}) {
1.298 droeschl 5686: push(@{ $menu[2]->{items} },
1.398 raeburn 5687: {
1.298 droeschl 5688: linktext => 'Enrollment Requests',
5689: icon => 'selfenrl-queue.png',
5690: #help => 'Course_Approve_Selfenroll',
5691: url => '/adm/createuser?action=selfenrollqueue',
1.398 raeburn 5692: permission => $permission->{'selfenrolladmin'},
1.298 droeschl 5693: linktitle =>'Approve or reject enrollment requests.',
5694: },
5695: );
1.277 raeburn 5696: }
1.298 droeschl 5697:
1.265 mielkec 5698: if (!exists($permission->{'cusr_section'})){
1.320 raeburn 5699: if ($crstype ne 'Community') {
5700: push(@{ $menu[2]->{items} },
5701: {
5702: linktext => 'Automated Enrollment',
5703: icon => 'roles.png',
5704: #help => 'Course_Automated_Enrollment',
5705: permission => (&Apache::lonnet::auto_run($cnum,$cdom)
1.418 raeburn 5706: && (($permission->{'cusr'}) ||
5707: ($permission->{'view'}))),
1.320 raeburn 5708: url => '/adm/populate',
5709: linktitle => 'Automated enrollment manager.',
5710: }
5711: );
5712: }
5713: push(@{ $menu[2]->{items} },
1.298 droeschl 5714: {
5715: linktext => 'User Self-Enrollment',
1.342 wenzelju 5716: icon => 'self_enroll.png',
1.298 droeschl 5717: #help => 'Course_Self_Enrollment',
5718: url => '/adm/createuser?action=selfenroll',
1.398 raeburn 5719: permission => $permission->{'selfenrolladmin'},
1.317 bisitz 5720: linktitle => 'Configure user self-enrollment.',
1.298 droeschl 5721: },
5722: );
5723: }
1.363 raeburn 5724: } elsif ($context eq 'author') {
1.370 raeburn 5725: push(@{ $menu[2]->{items} }, #Category: Administration
1.363 raeburn 5726: {
5727: linktext => 'Change Log',
5728: icon => 'document-properties.png',
5729: #help => 'Course_User_Logs',
5730: url => '/adm/createuser?action=changelogs',
5731: permission => $permission->{'cusr'},
5732: linktitle => 'View change log.',
5733: },
1.370 raeburn 5734: );
1.363 raeburn 5735: }
5736: return Apache::lonhtmlcommon::generate_menu(@menu);
1.250 raeburn 5737: # { text => 'View Log-in History',
5738: # help => 'Course_User_Logins',
5739: # action => 'logins',
5740: # permission => $permission->{'cusr'},
5741: # });
1.190 raeburn 5742: }
5743:
1.189 albertel 5744: sub restore_prev_selections {
5745: my %saveable_parameters = ('srchby' => 'scalar',
5746: 'srchin' => 'scalar',
5747: 'srchtype' => 'scalar',
5748: );
5749: &Apache::loncommon::store_settings('user','user_picker',
5750: \%saveable_parameters);
5751: &Apache::loncommon::restore_settings('user','user_picker',
5752: \%saveable_parameters);
5753: }
5754:
1.237 raeburn 5755: sub print_selfenroll_menu {
1.418 raeburn 5756: my ($r,$context,$cid,$cdom,$cnum,$currsettings,$additional,$readonly) = @_;
1.322 raeburn 5757: my $crstype = &Apache::loncommon::course_type();
1.398 raeburn 5758: my $formname = 'selfenroll';
1.237 raeburn 5759: my $nolink = 1;
1.398 raeburn 5760: my ($row,$lt) = &Apache::lonuserutils::get_selfenroll_titles();
1.237 raeburn 5761: my $groupslist = &Apache::lonuserutils::get_groupslist();
5762: my $setsec_js =
5763: &Apache::lonuserutils::setsections_javascript($formname,$groupslist);
1.249 raeburn 5764: my %alerts = &Apache::lonlocal::texthash(
5765: acto => 'Activation of self-enrollment was selected for the following domain(s)',
5766: butn => 'but no user types have been checked.',
5767: wilf => "Please uncheck 'activate' or check at least one type.",
5768: );
1.418 raeburn 5769: my $disabled;
5770: if ($readonly) {
5771: $disabled = ' disabled="disabled"';
5772: }
1.405 damieng 5773: &js_escape(\%alerts);
1.249 raeburn 5774: my $selfenroll_js = <<"ENDSCRIPT";
5775: function update_types(caller,num) {
5776: var delidx = getIndexByName('selfenroll_delete');
5777: var actidx = getIndexByName('selfenroll_activate');
5778: if (caller == 'selfenroll_all') {
5779: var selall;
5780: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
5781: if (document.$formname.selfenroll_all[i].checked) {
5782: selall = document.$formname.selfenroll_all[i].value;
5783: }
5784: }
5785: if (selall == 1) {
5786: if (delidx != -1) {
5787: if (document.$formname.selfenroll_delete.length) {
5788: for (var j=0; j<document.$formname.selfenroll_delete.length; j++) {
5789: document.$formname.selfenroll_delete[j].checked = true;
5790: }
5791: } else {
5792: document.$formname.elements[delidx].checked = true;
5793: }
5794: }
5795: if (actidx != -1) {
5796: if (document.$formname.selfenroll_activate.length) {
5797: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
5798: document.$formname.selfenroll_activate[j].checked = false;
5799: }
5800: } else {
5801: document.$formname.elements[actidx].checked = false;
5802: }
5803: }
5804: document.$formname.selfenroll_newdom.selectedIndex = 0;
5805: }
5806: }
5807: if (caller == 'selfenroll_activate') {
5808: if (document.$formname.selfenroll_activate.length) {
5809: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
5810: if (document.$formname.selfenroll_activate[j].value == num) {
5811: if (document.$formname.selfenroll_activate[j].checked) {
5812: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
5813: if (document.$formname.selfenroll_all[i].value == '1') {
5814: document.$formname.selfenroll_all[i].checked = false;
5815: }
5816: if (document.$formname.selfenroll_all[i].value == '0') {
5817: document.$formname.selfenroll_all[i].checked = true;
5818: }
5819: }
5820: }
5821: }
5822: }
5823: } else {
5824: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
5825: if (document.$formname.selfenroll_all[i].value == '1') {
5826: document.$formname.selfenroll_all[i].checked = false;
5827: }
5828: if (document.$formname.selfenroll_all[i].value == '0') {
5829: document.$formname.selfenroll_all[i].checked = true;
5830: }
5831: }
5832: }
5833: }
5834: if (caller == 'selfenroll_delete') {
5835: if (document.$formname.selfenroll_delete.length) {
5836: for (var j=0; j<document.$formname.selfenroll_delete.length; j++) {
5837: if (document.$formname.selfenroll_delete[j].value == num) {
5838: if (document.$formname.selfenroll_delete[j].checked) {
5839: var delindex = getIndexByName('selfenroll_types_'+num);
5840: if (delindex != -1) {
5841: if (document.$formname.elements[delindex].length) {
5842: for (var k=0; k<document.$formname.elements[delindex].length; k++) {
5843: document.$formname.elements[delindex][k].checked = false;
5844: }
5845: } else {
5846: document.$formname.elements[delindex].checked = false;
5847: }
5848: }
5849: }
5850: }
5851: }
5852: } else {
5853: if (document.$formname.selfenroll_delete.checked) {
5854: var delindex = getIndexByName('selfenroll_types_'+num);
5855: if (delindex != -1) {
5856: if (document.$formname.elements[delindex].length) {
5857: for (var k=0; k<document.$formname.elements[delindex].length; k++) {
5858: document.$formname.elements[delindex][k].checked = false;
5859: }
5860: } else {
5861: document.$formname.elements[delindex].checked = false;
5862: }
5863: }
5864: }
5865: }
5866: }
5867: return;
5868: }
5869:
5870: function validate_types(form) {
5871: var needaction = new Array();
5872: var countfail = 0;
5873: var actidx = getIndexByName('selfenroll_activate');
5874: if (actidx != -1) {
5875: if (document.$formname.selfenroll_activate.length) {
5876: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
5877: var num = document.$formname.selfenroll_activate[j].value;
5878: if (document.$formname.selfenroll_activate[j].checked) {
5879: countfail = check_types(num,countfail,needaction)
5880: }
5881: }
5882: } else {
5883: if (document.$formname.selfenroll_activate.checked) {
1.398 raeburn 5884: var num = document.$formname.selfenroll_activate.value;
1.249 raeburn 5885: countfail = check_types(num,countfail,needaction)
5886: }
5887: }
5888: }
5889: if (countfail > 0) {
5890: var msg = "$alerts{'acto'}\\n";
5891: var loopend = needaction.length -1;
5892: if (loopend > 0) {
5893: for (var m=0; m<loopend; m++) {
5894: msg += needaction[m]+", ";
5895: }
5896: }
5897: msg += needaction[loopend]+"\\n$alerts{'butn'}\\n$alerts{'wilf'}";
5898: alert(msg);
5899: return;
5900: }
5901: setSections(form);
5902: }
5903:
5904: function check_types(num,countfail,needaction) {
1.441 raeburn 5905: var boxname = 'selfenroll_types_'+num;
5906: var typeidx = getIndexByName(boxname);
1.249 raeburn 5907: var count = 0;
5908: if (typeidx != -1) {
1.441 raeburn 5909: if (document.$formname.elements[boxname].length) {
5910: for (var k=0; k<document.$formname.elements[boxname].length; k++) {
5911: if (document.$formname.elements[boxname][k].checked) {
1.249 raeburn 5912: count ++;
5913: }
5914: }
5915: } else {
5916: if (document.$formname.elements[typeidx].checked) {
5917: count ++;
5918: }
5919: }
5920: if (count == 0) {
5921: var domidx = getIndexByName('selfenroll_dom_'+num);
5922: if (domidx != -1) {
5923: var domname = document.$formname.elements[domidx].value;
5924: needaction[countfail] = domname;
5925: countfail ++;
5926: }
5927: }
5928: }
5929: return countfail;
5930: }
5931:
1.398 raeburn 5932: function toggleNotify() {
5933: var selfenrollApproval = 0;
5934: if (document.$formname.selfenroll_approval.length) {
5935: for (var i=0; i<document.$formname.selfenroll_approval.length; i++) {
5936: if (document.$formname.selfenroll_approval[i].checked) {
5937: selfenrollApproval = document.$formname.selfenroll_approval[i].value;
5938: break;
5939: }
5940: }
5941: }
5942: if (document.getElementById('notified')) {
5943: if (selfenrollApproval == 0) {
5944: document.getElementById('notified').style.display='none';
5945: } else {
5946: document.getElementById('notified').style.display='block';
5947: }
5948: }
5949: return;
5950: }
5951:
1.249 raeburn 5952: function getIndexByName(item) {
5953: for (var i=0;i<document.$formname.elements.length;i++) {
5954: if (document.$formname.elements[i].name == item) {
5955: return i;
5956: }
5957: }
5958: return -1;
5959: }
5960: ENDSCRIPT
1.256 raeburn 5961:
1.237 raeburn 5962: my $output = '<script type="text/javascript">'."\n".
1.301 bisitz 5963: '// <![CDATA['."\n".
1.249 raeburn 5964: $setsec_js."\n".$selfenroll_js."\n".
1.301 bisitz 5965: '// ]]>'."\n".
1.237 raeburn 5966: '</script>'."\n".
1.256 raeburn 5967: '<h3>'.$lt->{'selfenroll'}.'</h3>'."\n";
1.400 raeburn 5968:
5969: my $visactions = &cat_visibility();
5970: my ($cathash,%cattype);
5971: my %domconfig = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom);
5972: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
5973: $cathash = $domconfig{'coursecategories'}{'cats'};
5974: $cattype{'auth'} = $domconfig{'coursecategories'}{'auth'};
5975: $cattype{'unauth'} = $domconfig{'coursecategories'}{'unauth'};
1.406 raeburn 5976: if ($cattype{'auth'} eq '') {
5977: $cattype{'auth'} = 'std';
5978: }
5979: if ($cattype{'unauth'} eq '') {
5980: $cattype{'unauth'} = 'std';
5981: }
1.400 raeburn 5982: } else {
5983: $cathash = {};
5984: $cattype{'auth'} = 'std';
5985: $cattype{'unauth'} = 'std';
5986: }
5987: if (($cattype{'auth'} eq 'none') && ($cattype{'unauth'} eq 'none')) {
5988: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
5989: '<br />'.
5990: '<br />'.$visactions->{'take'}.'<ul>'.
5991: '<li>'.$visactions->{'dc_chgconf'}.'</li>'.
5992: '</ul>');
5993: } elsif (($cattype{'auth'} !~ /^(std|domonly)$/) && ($cattype{'unauth'} !~ /^(std|domonly)$/)) {
5994: if ($currsettings->{'uniquecode'}) {
5995: $r->print('<span class="LC_info">'.$visactions->{'vis'}.'</span>');
5996: } else {
5997: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
5998: '<br />'.
5999: '<br />'.$visactions->{'take'}.'<ul>'.
6000: '<li>'.$visactions->{'dc_setcode'}.'</li>'.
6001: '</ul><br />');
6002: }
6003: } else {
6004: my ($visible,$cansetvis,$vismsgs) = &visible_in_stdcat($cdom,$cnum,\%domconfig);
6005: if (ref($visactions) eq 'HASH') {
6006: if ($visible) {
6007: $output .= '<p class="LC_info">'.$visactions->{'vis'}.'</p>';
6008: } else {
6009: $output .= '<p class="LC_warning">'.$visactions->{'miss'}.'</p>'
6010: .$visactions->{'yous'}.
6011: '<p>'.$visactions->{'gen'}.'<br />'.$visactions->{'coca'};
6012: if (ref($vismsgs) eq 'ARRAY') {
6013: $output .= '<br />'.$visactions->{'make'}.'<ul>';
6014: foreach my $item (@{$vismsgs}) {
6015: $output .= '<li>'.$visactions->{$item}.'</li>';
6016: }
6017: $output .= '</ul>';
1.256 raeburn 6018: }
1.400 raeburn 6019: $output .= '</p>';
1.256 raeburn 6020: }
6021: }
6022: }
1.398 raeburn 6023: my $actionhref = '/adm/createuser';
6024: if ($context eq 'domain') {
6025: $actionhref = '/adm/modifycourse';
6026: }
1.400 raeburn 6027:
6028: my %noedit;
6029: unless ($context eq 'domain') {
6030: %noedit = &get_noedit_fields($cdom,$cnum,$crstype,$row);
6031: }
1.398 raeburn 6032: $output .= '<form name="'.$formname.'" method="post" action="'.$actionhref.'">'."\n".
1.256 raeburn 6033: &Apache::lonhtmlcommon::start_pick_box();
1.237 raeburn 6034: if (ref($row) eq 'ARRAY') {
6035: foreach my $item (@{$row}) {
6036: my $title = $item;
6037: if (ref($lt) eq 'HASH') {
6038: $title = $lt->{$item};
6039: }
1.297 bisitz 6040: $output .= &Apache::lonhtmlcommon::row_title($title);
1.237 raeburn 6041: if ($item eq 'types') {
1.398 raeburn 6042: my $curr_types;
6043: if (ref($currsettings) eq 'HASH') {
6044: $curr_types = $currsettings->{'selfenroll_types'};
6045: }
1.400 raeburn 6046: if ($noedit{$item}) {
6047: if ($curr_types eq '*') {
6048: $output .= &mt('Any user in any domain');
6049: } else {
6050: my @entries = split(/;/,$curr_types);
6051: if (@entries > 0) {
6052: $output .= '<ul>';
6053: foreach my $entry (@entries) {
6054: my ($currdom,$typestr) = split(/:/,$entry);
6055: next if ($typestr eq '');
6056: my $domdesc = &Apache::lonnet::domain($currdom);
6057: my @currinsttypes = split(',',$typestr);
6058: my ($othertitle,$usertypes,$types) =
6059: &Apache::loncommon::sorted_inst_types($currdom);
6060: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
6061: $usertypes->{'any'} = &mt('any user');
6062: if (keys(%{$usertypes}) > 0) {
6063: $usertypes->{'other'} = &mt('other users');
6064: }
6065: my @longinsttypes = map { $usertypes->{$_}; } @currinsttypes;
6066: $output .= '<li>'.$domdesc.':'.join(', ',@longinsttypes).'</li>';
6067: }
6068: }
6069: $output .= '</ul>';
6070: } else {
6071: $output .= &mt('None');
6072: }
6073: }
6074: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6075: next;
6076: }
1.241 raeburn 6077: my $showdomdesc = 1;
6078: my $includeempty = 1;
6079: my $num = 0;
6080: $output .= &Apache::loncommon::start_data_table().
6081: &Apache::loncommon::start_data_table_row()
6082: .'<td colspan="2"><span class="LC_nobreak"><label>'
6083: .&mt('Any user in any domain:')
6084: .' <input type="radio" name="selfenroll_all" value="1" ';
6085: if ($curr_types eq '*') {
6086: $output .= ' checked="checked" ';
6087: }
1.249 raeburn 6088: $output .= 'onchange="javascript:update_types('.
1.418 raeburn 6089: "'selfenroll_all'".');"'.$disabled.' />'.&mt('Yes').'</label>'.
1.249 raeburn 6090: ' <input type="radio" name="selfenroll_all" value="0" ';
1.241 raeburn 6091: if ($curr_types ne '*') {
6092: $output .= ' checked="checked" ';
6093: }
1.249 raeburn 6094: $output .= ' onchange="javascript:update_types('.
1.418 raeburn 6095: "'selfenroll_all'".');"'.$disabled.' />'.&mt('No').'</label></td>'.
1.249 raeburn 6096: &Apache::loncommon::end_data_table_row().
6097: &Apache::loncommon::end_data_table().
6098: &mt('Or').'<br />'.
6099: &Apache::loncommon::start_data_table();
1.241 raeburn 6100: my %currdoms;
1.249 raeburn 6101: if ($curr_types eq '') {
1.241 raeburn 6102: $output .= &new_selfenroll_dom_row($cdom,'0');
6103: } elsif ($curr_types ne '*') {
6104: my @entries = split(/;/,$curr_types);
6105: if (@entries > 0) {
6106: foreach my $entry (@entries) {
6107: my ($currdom,$typestr) = split(/:/,$entry);
6108: $currdoms{$currdom} = 1;
6109: my $domdesc = &Apache::lonnet::domain($currdom);
1.249 raeburn 6110: my @currinsttypes = split(',',$typestr);
1.241 raeburn 6111: $output .= &Apache::loncommon::start_data_table_row()
6112: .'<td valign="top"><span class="LC_nobreak">'.&mt('Domain:').'<b>'
6113: .' '.$domdesc.' ('.$currdom.')'
6114: .'</b><input type="hidden" name="selfenroll_dom_'.$num
6115: .'" value="'.$currdom.'" /></span><br />'
6116: .'<span class="LC_nobreak"><label><input type="checkbox" '
1.418 raeburn 6117: .'name="selfenroll_delete" value="'.$num.'" onchange="javascript:update_types('."'selfenroll_delete','$num'".');"'.$disabled.' />'
1.241 raeburn 6118: .&mt('Delete').'</label></span></td>';
1.249 raeburn 6119: $output .= '<td valign="top"> '.&mt('User types:').'<br />'
1.418 raeburn 6120: .&selfenroll_inst_types($num,$currdom,\@currinsttypes,$readonly).'</td>'
1.241 raeburn 6121: .&Apache::loncommon::end_data_table_row();
6122: $num ++;
6123: }
6124: }
6125: }
1.249 raeburn 6126: my $add_domtitle = &mt('Users in additional domain:');
1.241 raeburn 6127: if ($curr_types eq '*') {
1.249 raeburn 6128: $add_domtitle = &mt('Users in specific domain:');
1.241 raeburn 6129: } elsif ($curr_types eq '') {
1.249 raeburn 6130: $add_domtitle = &mt('Users in other domain:');
1.241 raeburn 6131: }
6132: $output .= &Apache::loncommon::start_data_table_row()
6133: .'<td colspan="2"><span class="LC_nobreak">'.$add_domtitle.'</span><br />'
6134: .&Apache::loncommon::select_dom_form('','selfenroll_newdom',
1.418 raeburn 6135: $includeempty,$showdomdesc,'','','',$readonly)
1.241 raeburn 6136: .'<input type="hidden" name="selfenroll_types_total" value="'.$num.'" />'
6137: .'</td>'.&Apache::loncommon::end_data_table_row()
6138: .&Apache::loncommon::end_data_table();
1.237 raeburn 6139: } elsif ($item eq 'registered') {
6140: my ($regon,$regoff);
1.398 raeburn 6141: my $registered;
6142: if (ref($currsettings) eq 'HASH') {
6143: $registered = $currsettings->{'selfenroll_registered'};
6144: }
1.400 raeburn 6145: if ($noedit{$item}) {
6146: if ($registered) {
6147: $output .= &mt('Must be registered in course');
6148: } else {
6149: $output .= &mt('No requirement');
6150: }
6151: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6152: next;
6153: }
1.398 raeburn 6154: if ($registered) {
1.237 raeburn 6155: $regon = ' checked="checked" ';
1.419 raeburn 6156: $regoff = '';
1.237 raeburn 6157: } else {
1.419 raeburn 6158: $regon = '';
1.237 raeburn 6159: $regoff = ' checked="checked" ';
6160: }
6161: $output .= '<label>'.
1.419 raeburn 6162: '<input type="radio" name="selfenroll_registered" value="1"'.$regon.$disabled.' />'.
1.244 bisitz 6163: &mt('Yes').'</label> <label>'.
1.419 raeburn 6164: '<input type="radio" name="selfenroll_registered" value="0"'.$regoff.$disabled.' />'.
1.244 bisitz 6165: &mt('No').'</label>';
1.237 raeburn 6166: } elsif ($item eq 'enroll_dates') {
1.398 raeburn 6167: my ($starttime,$endtime);
6168: if (ref($currsettings) eq 'HASH') {
6169: $starttime = $currsettings->{'selfenroll_start_date'};
6170: $endtime = $currsettings->{'selfenroll_end_date'};
6171: if ($starttime eq '') {
6172: $starttime = $currsettings->{'default_enrollment_start_date'};
6173: }
6174: if ($endtime eq '') {
6175: $endtime = $currsettings->{'default_enrollment_end_date'};
6176: }
1.237 raeburn 6177: }
1.400 raeburn 6178: if ($noedit{$item}) {
6179: $output .= &mt('From: [_1], to: [_2]',&Apache::lonlocal::locallocaltime($starttime),
6180: &Apache::lonlocal::locallocaltime($endtime));
6181: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6182: next;
6183: }
1.237 raeburn 6184: my $startform =
6185: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_start_date',$starttime,
1.418 raeburn 6186: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
1.237 raeburn 6187: my $endform =
6188: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_end_date',$endtime,
1.418 raeburn 6189: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
1.237 raeburn 6190: $output .= &selfenroll_date_forms($startform,$endform);
6191: } elsif ($item eq 'access_dates') {
1.398 raeburn 6192: my ($starttime,$endtime);
6193: if (ref($currsettings) eq 'HASH') {
6194: $starttime = $currsettings->{'selfenroll_start_access'};
6195: $endtime = $currsettings->{'selfenroll_end_access'};
6196: if ($starttime eq '') {
6197: $starttime = $currsettings->{'default_enrollment_start_date'};
6198: }
6199: if ($endtime eq '') {
6200: $endtime = $currsettings->{'default_enrollment_end_date'};
6201: }
1.237 raeburn 6202: }
1.400 raeburn 6203: if ($noedit{$item}) {
6204: $output .= &mt('From: [_1], to: [_2]',&Apache::lonlocal::locallocaltime($starttime),
6205: &Apache::lonlocal::locallocaltime($endtime));
6206: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6207: next;
6208: }
1.237 raeburn 6209: my $startform =
6210: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_start_access',$starttime,
1.418 raeburn 6211: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
1.237 raeburn 6212: my $endform =
6213: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_end_access',$endtime,
1.418 raeburn 6214: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
1.237 raeburn 6215: $output .= &selfenroll_date_forms($startform,$endform);
6216: } elsif ($item eq 'section') {
1.398 raeburn 6217: my $currsec;
6218: if (ref($currsettings) eq 'HASH') {
6219: $currsec = $currsettings->{'selfenroll_section'};
6220: }
1.237 raeburn 6221: my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum);
6222: my $newsecval;
6223: if ($currsec ne 'none' && $currsec ne '') {
6224: if (!defined($sections_count{$currsec})) {
6225: $newsecval = $currsec;
6226: }
6227: }
1.400 raeburn 6228: if ($noedit{$item}) {
6229: if ($currsec ne '') {
6230: $output .= $currsec;
6231: } else {
6232: $output .= &mt('No specific section');
6233: }
6234: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6235: next;
6236: }
1.237 raeburn 6237: my $sections_select =
1.418 raeburn 6238: &Apache::lonuserutils::course_sections(\%sections_count,'st',$currsec,$disabled);
1.237 raeburn 6239: $output .= '<table class="LC_createuser">'."\n".
6240: '<tr class="LC_section_row">'."\n".
6241: '<td align="center">'.&mt('Existing sections')."\n".
6242: '<br />'.$sections_select.'</td><td align="center">'.
6243: &mt('New section').'<br />'."\n".
1.418 raeburn 6244: '<input type="text" name="newsec" size="15" value="'.$newsecval.'"'.$disabled.' />'."\n".
1.237 raeburn 6245: '<input type="hidden" name="sections" value="" />'."\n".
6246: '</td></tr></table>'."\n";
1.276 raeburn 6247: } elsif ($item eq 'approval') {
1.398 raeburn 6248: my ($currnotified,$currapproval,%appchecked);
6249: my %selfdescs = &Apache::lonuserutils::selfenroll_default_descs();
1.430 raeburn 6250: if (ref($currsettings) eq 'HASH') {
1.398 raeburn 6251: $currnotified = $currsettings->{'selfenroll_notifylist'};
6252: $currapproval = $currsettings->{'selfenroll_approval'};
6253: }
6254: if ($currapproval !~ /^[012]$/) {
6255: $currapproval = 0;
6256: }
1.400 raeburn 6257: if ($noedit{$item}) {
6258: $output .= $selfdescs{'approval'}{$currapproval}.
6259: '<br />'.&mt('(Set by Domain Coordinator)');
6260: next;
6261: }
1.398 raeburn 6262: $appchecked{$currapproval} = ' checked="checked"';
6263: for my $i (0..2) {
6264: $output .= '<label>'.
6265: '<input type="radio" name="selfenroll_approval" value="'.$i.'"'.
1.418 raeburn 6266: $appchecked{$i}.' onclick="toggleNotify();"'.$disabled.' />'.
6267: $selfdescs{'approval'}{$i}.'</label>'.(' 'x2);
1.276 raeburn 6268: }
6269: my %advhash = &Apache::lonnet::get_course_adv_roles($cid,1);
6270: my (@ccs,%notified);
1.322 raeburn 6271: my $ccrole = 'cc';
6272: if ($crstype eq 'Community') {
6273: $ccrole = 'co';
6274: }
6275: if ($advhash{$ccrole}) {
6276: @ccs = split(/,/,$advhash{$ccrole});
1.276 raeburn 6277: }
6278: if ($currnotified) {
6279: foreach my $current (split(/,/,$currnotified)) {
6280: $notified{$current} = 1;
6281: if (!grep(/^\Q$current\E$/,@ccs)) {
6282: push(@ccs,$current);
6283: }
6284: }
6285: }
6286: if (@ccs) {
1.398 raeburn 6287: my $style;
6288: unless ($currapproval) {
6289: $style = ' style="display: none;"';
6290: }
6291: $output .= '<br /><div id="notified"'.$style.'>'.
6292: &mt('Personnel to be notified when an enrollment request needs approval, or has been approved:').' '.
6293: &Apache::loncommon::start_data_table().
1.276 raeburn 6294: &Apache::loncommon::start_data_table_row();
6295: my $count = 0;
6296: my $numcols = 4;
6297: foreach my $cc (sort(@ccs)) {
6298: my $notifyon;
6299: my ($ccuname,$ccudom) = split(/:/,$cc);
6300: if ($notified{$cc}) {
6301: $notifyon = ' checked="checked" ';
6302: }
6303: if ($count && !$count%$numcols) {
6304: $output .= &Apache::loncommon::end_data_table_row().
6305: &Apache::loncommon::start_data_table_row()
6306: }
6307: $output .= '<td><span class="LC_nobreak"><label>'.
1.418 raeburn 6308: '<input type="checkbox" name="selfenroll_notify"'.$notifyon.' value="'.$cc.'"'.$disabled.' />'.
1.276 raeburn 6309: &Apache::loncommon::plainname($ccuname,$ccudom).
6310: '</label></span></td>';
1.343 raeburn 6311: $count ++;
1.276 raeburn 6312: }
6313: my $rem = $count%$numcols;
6314: if ($rem) {
6315: my $emptycols = $numcols - $rem;
6316: for (my $i=0; $i<$emptycols; $i++) {
6317: $output .= '<td> </td>';
6318: }
6319: }
6320: $output .= &Apache::loncommon::end_data_table_row().
1.398 raeburn 6321: &Apache::loncommon::end_data_table().
6322: '</div>';
1.276 raeburn 6323: }
6324: } elsif ($item eq 'limit') {
1.398 raeburn 6325: my ($crslimit,$selflimit,$nolimit,$currlim,$currcap);
6326: if (ref($currsettings) eq 'HASH') {
6327: $currlim = $currsettings->{'selfenroll_limit'};
6328: $currcap = $currsettings->{'selfenroll_cap'};
6329: }
1.400 raeburn 6330: if ($noedit{$item}) {
6331: if (($currlim eq 'allstudents') || ($currlim eq 'selfenrolled')) {
6332: if ($currlim eq 'allstudents') {
6333: $output .= &mt('Limit by total students');
6334: } elsif ($currlim eq 'selfenrolled') {
6335: $output .= &mt('Limit by total self-enrolled students');
6336: }
6337: $output .= ' '.&mt('Maximum: [_1]',$currcap).
6338: '<br />'.&mt('(Set by Domain Coordinator)');
6339: } else {
6340: $output .= &mt('No limit').'<br />'.&mt('(Set by Domain Coordinator)');
6341: }
6342: next;
6343: }
1.276 raeburn 6344: if ($currlim eq 'allstudents') {
6345: $crslimit = ' checked="checked" ';
6346: $selflimit = ' ';
6347: $nolimit = ' ';
6348: } elsif ($currlim eq 'selfenrolled') {
6349: $crslimit = ' ';
6350: $selflimit = ' checked="checked" ';
6351: $nolimit = ' ';
6352: } else {
6353: $crslimit = ' ';
6354: $selflimit = ' ';
1.398 raeburn 6355: $nolimit = ' checked="checked" ';
1.276 raeburn 6356: }
6357: $output .= '<table><tr><td><label>'.
1.418 raeburn 6358: '<input type="radio" name="selfenroll_limit" value="none"'.$nolimit.$disabled.'/>'.
1.276 raeburn 6359: &mt('No limit').'</label></td><td><label>'.
1.418 raeburn 6360: '<input type="radio" name="selfenroll_limit" value="allstudents"'.$crslimit.$disabled.'/>'.
1.276 raeburn 6361: &mt('Limit by total students').'</label></td><td><label>'.
1.418 raeburn 6362: '<input type="radio" name="selfenroll_limit" value="selfenrolled"'.$selflimit.$disabled.'/>'.
1.276 raeburn 6363: &mt('Limit by total self-enrolled students').
6364: '</td></tr><tr>'.
6365: '<td> </td><td colspan="2"><span class="LC_nobreak">'.
6366: (' 'x3).&mt('Maximum number allowed: ').
1.418 raeburn 6367: '<input type="text" name="selfenroll_cap" size = "5" value="'.$currcap.'"'.$disabled.' /></td></tr></table>';
1.237 raeburn 6368: }
6369: $output .= &Apache::lonhtmlcommon::row_closure(1);
6370: }
6371: }
1.418 raeburn 6372: $output .= &Apache::lonhtmlcommon::end_pick_box().'<br />';
6373: unless ($readonly) {
6374: $output .= '<input type="button" name="selfenrollconf" value="'
6375: .&mt('Save').'" onclick="validate_types(this.form);" />';
6376: }
6377: $output .= '<input type="hidden" name="action" value="selfenroll" />'
6378: .'<input type="hidden" name="state" value="done" />'."\n"
6379: .$additional.'</form>';
1.237 raeburn 6380: $r->print($output);
6381: return;
6382: }
6383:
1.400 raeburn 6384: sub get_noedit_fields {
6385: my ($cdom,$cnum,$crstype,$row) = @_;
6386: my %noedit;
6387: if (ref($row) eq 'ARRAY') {
6388: my %settings = &Apache::lonnet::get('environment',['internal.coursecode','internal.textbook',
6389: 'internal.selfenrollmgrdc',
6390: 'internal.selfenrollmgrcc'],$cdom,$cnum);
6391: my $type = &Apache::lonuserutils::get_extended_type($cdom,$cnum,$crstype,\%settings);
6392: my (%specific_managebydc,%specific_managebycc,%default_managebydc);
6393: map { $specific_managebydc{$_} = 1; } (split(/,/,$settings{'internal.selfenrollmgrdc'}));
6394: map { $specific_managebycc{$_} = 1; } (split(/,/,$settings{'internal.selfenrollmgrcc'}));
6395: my %domdefaults = &Apache::lonnet::get_domain_defaults($cdom);
6396: map { $default_managebydc{$_} = 1; } (split(/,/,$domdefaults{$type.'selfenrolladmdc'}));
6397:
6398: foreach my $item (@{$row}) {
6399: next if ($specific_managebycc{$item});
6400: if (($specific_managebydc{$item}) || ($default_managebydc{$item})) {
6401: $noedit{$item} = 1;
6402: }
6403: }
6404: }
6405: return %noedit;
6406: }
6407:
6408: sub visible_in_stdcat {
6409: my ($cdom,$cnum,$domconf) = @_;
6410: my ($cathash,%settable,@vismsgs,$cansetvis,$visible);
6411: unless (ref($domconf) eq 'HASH') {
6412: return ($visible,$cansetvis,\@vismsgs);
6413: }
6414: if (ref($domconf->{'coursecategories'}) eq 'HASH') {
6415: if ($domconf->{'coursecategories'}{'togglecats'} eq 'crs') {
1.256 raeburn 6416: $settable{'togglecats'} = 1;
6417: }
1.400 raeburn 6418: if ($domconf->{'coursecategories'}{'categorize'} eq 'crs') {
1.256 raeburn 6419: $settable{'categorize'} = 1;
6420: }
1.400 raeburn 6421: $cathash = $domconf->{'coursecategories'}{'cats'};
1.256 raeburn 6422: }
1.260 raeburn 6423: if ($settable{'togglecats'} && $settable{'categorize'}) {
1.256 raeburn 6424: $cansetvis = &mt('You are able to both assign a course category and choose to exclude this course from the catalog.');
6425: } elsif ($settable{'togglecats'}) {
6426: $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 6427: } elsif ($settable{'categorize'}) {
1.256 raeburn 6428: $cansetvis = &mt('You may assign a course category, but only a Domain Coordinator may choose to exclude this course from the catalog.');
6429: } else {
6430: $cansetvis = &mt('Only a Domain Coordinator may assign a course category or choose to exclude this course from the catalog.');
6431: }
6432:
6433: my %currsettings =
6434: &Apache::lonnet::get('environment',['hidefromcat','categories','internal.coursecode'],
6435: $cdom,$cnum);
1.400 raeburn 6436: $visible = 0;
1.256 raeburn 6437: if ($currsettings{'internal.coursecode'} ne '') {
1.400 raeburn 6438: if (ref($domconf->{'coursecategories'}) eq 'HASH') {
6439: $cathash = $domconf->{'coursecategories'}{'cats'};
1.256 raeburn 6440: if (ref($cathash) eq 'HASH') {
6441: if ($cathash->{'instcode::0'} eq '') {
6442: push(@vismsgs,'dc_addinst');
6443: } else {
6444: $visible = 1;
6445: }
6446: } else {
6447: $visible = 1;
6448: }
6449: } else {
6450: $visible = 1;
6451: }
6452: } else {
6453: if (ref($cathash) eq 'HASH') {
6454: if ($cathash->{'instcode::0'} ne '') {
6455: push(@vismsgs,'dc_instcode');
6456: }
6457: } else {
6458: push(@vismsgs,'dc_instcode');
6459: }
6460: }
6461: if ($currsettings{'categories'} ne '') {
6462: my $cathash;
1.400 raeburn 6463: if (ref($domconf->{'coursecategories'}) eq 'HASH') {
6464: $cathash = $domconf->{'coursecategories'}{'cats'};
1.256 raeburn 6465: if (ref($cathash) eq 'HASH') {
6466: if (keys(%{$cathash}) == 0) {
6467: push(@vismsgs,'dc_catalog');
6468: } elsif ((keys(%{$cathash}) == 1) && ($cathash->{'instcode::0'} ne '')) {
6469: push(@vismsgs,'dc_categories');
6470: } else {
6471: my @currcategories = split('&',$currsettings{'categories'});
6472: my $matched = 0;
6473: foreach my $cat (@currcategories) {
6474: if ($cathash->{$cat} ne '') {
6475: $visible = 1;
6476: $matched = 1;
6477: last;
6478: }
6479: }
6480: if (!$matched) {
1.260 raeburn 6481: if ($settable{'categorize'}) {
1.256 raeburn 6482: push(@vismsgs,'chgcat');
6483: } else {
6484: push(@vismsgs,'dc_chgcat');
6485: }
6486: }
6487: }
6488: }
6489: }
6490: } else {
6491: if (ref($cathash) eq 'HASH') {
6492: if ((keys(%{$cathash}) > 1) ||
6493: (keys(%{$cathash}) == 1) && ($cathash->{'instcode::0'} eq '')) {
1.260 raeburn 6494: if ($settable{'categorize'}) {
1.256 raeburn 6495: push(@vismsgs,'addcat');
6496: } else {
6497: push(@vismsgs,'dc_addcat');
6498: }
6499: }
6500: }
6501: }
6502: if ($currsettings{'hidefromcat'} eq 'yes') {
6503: $visible = 0;
6504: if ($settable{'togglecats'}) {
6505: unshift(@vismsgs,'unhide');
6506: } else {
6507: unshift(@vismsgs,'dc_unhide')
6508: }
6509: }
1.400 raeburn 6510: return ($visible,$cansetvis,\@vismsgs);
6511: }
6512:
6513: sub cat_visibility {
6514: my %visactions = &Apache::lonlocal::texthash(
6515: vis => 'This course/community currently appears in the Course/Community Catalog for this domain.',
6516: 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.',
6517: miss => 'This course/community does not currently appear in the Course/Community Catalog for this domain.',
6518: none => 'Display of a course catalog is disabled for this domain.',
6519: yous => 'You should remedy this if you plan to allow self-enrollment, otherwise students will have difficulty finding this course.',
6520: 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.',
6521: make => 'Make any changes to self-enrollment settings below, click "Save", then take action to include the course in the Catalog:',
6522: take => 'Take the following action to ensure the course appears in the Catalog:',
6523: dc_chgconf => 'Ask a domain coordinator to change the Catalog type for this domain.',
6524: dc_setcode => 'Ask a domain coordinator to assign a six character code to the course',
6525: dc_unhide => 'Ask a domain coordinator to change the "Exclude from course catalog" setting.',
6526: dc_addinst => 'Ask a domain coordinator to enable display the catalog of "Official courses (with institutional codes)".',
6527: dc_instcode => 'Ask a domain coordinator to assign an institutional code (if this is an official course).',
6528: dc_catalog => 'Ask a domain coordinator to enable or create at least one course category in the domain.',
6529: dc_categories => 'Ask a domain coordinator to create a hierarchy of categories and sub categories for courses in the domain.',
6530: 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',
6531: dc_addcat => 'Ask a domain coordinator to assign a category to the course.',
6532: );
6533: $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>"');
6534: $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>"');
6535: $visactions{'addcat'} = &mt('Use [_1]Categorize course[_2] to assign a category to the course.','"<a href="/adm/courseprefs?phase=display&actions=courseinfo">','</a>"');
6536: return \%visactions;
1.256 raeburn 6537: }
6538:
1.241 raeburn 6539: sub new_selfenroll_dom_row {
6540: my ($newdom,$num) = @_;
6541: my $domdesc = &Apache::lonnet::domain($newdom);
6542: my $output;
6543: if ($domdesc ne '') {
6544: $output .= &Apache::loncommon::start_data_table_row()
6545: .'<td valign="top"><span class="LC_nobreak">'.&mt('Domain:').' <b>'.$domdesc
6546: .' ('.$newdom.')</b><input type="hidden" name="selfenroll_dom_'.$num
1.249 raeburn 6547: .'" value="'.$newdom.'" /></span><br />'
6548: .'<span class="LC_nobreak"><label><input type="checkbox" '
6549: .'name="selfenroll_activate" value="'.$num.'" '
6550: .'onchange="javascript:update_types('
6551: ."'selfenroll_activate','$num'".');" />'
6552: .&mt('Activate').'</label></span></td>';
1.241 raeburn 6553: my @currinsttypes;
6554: $output .= '<td>'.&mt('User types:').'<br />'
6555: .&selfenroll_inst_types($num,$newdom,\@currinsttypes).'</td>'
6556: .&Apache::loncommon::end_data_table_row();
6557: }
6558: return $output;
6559: }
6560:
6561: sub selfenroll_inst_types {
1.418 raeburn 6562: my ($num,$currdom,$currinsttypes,$readonly) = @_;
1.241 raeburn 6563: my $output;
6564: my $numinrow = 4;
6565: my $count = 0;
6566: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($currdom);
1.247 raeburn 6567: my $othervalue = 'any';
1.418 raeburn 6568: my $disabled;
6569: if ($readonly) {
6570: $disabled = ' disabled="disabled"';
6571: }
1.241 raeburn 6572: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
1.251 raeburn 6573: if (keys(%{$usertypes}) > 0) {
1.247 raeburn 6574: $othervalue = 'other';
6575: }
1.241 raeburn 6576: $output .= '<table><tr>';
6577: foreach my $type (@{$types}) {
6578: if (($count > 0) && ($count%$numinrow == 0)) {
6579: $output .= '</tr><tr>';
6580: }
6581: if (defined($usertypes->{$type})) {
1.257 raeburn 6582: my $esc_type = &escape($type);
1.241 raeburn 6583: $output .= '<td><span class="LC_nobreak"><label><input type = "checkbox" value="'.
1.257 raeburn 6584: $esc_type.'" ';
1.241 raeburn 6585: if (ref($currinsttypes) eq 'ARRAY') {
6586: if (@{$currinsttypes} > 0) {
1.249 raeburn 6587: if (grep(/^any$/,@{$currinsttypes})) {
6588: $output .= 'checked="checked"';
1.257 raeburn 6589: } elsif (grep(/^\Q$esc_type\E$/,@{$currinsttypes})) {
1.241 raeburn 6590: $output .= 'checked="checked"';
6591: }
1.249 raeburn 6592: } else {
6593: $output .= 'checked="checked"';
1.241 raeburn 6594: }
6595: }
1.418 raeburn 6596: $output .= ' name="selfenroll_types_'.$num.'"'.$disabled.' />'.$usertypes->{$type}.'</label></span></td>';
1.241 raeburn 6597: }
6598: $count ++;
6599: }
6600: if (($count > 0) && ($count%$numinrow == 0)) {
6601: $output .= '</tr><tr>';
6602: }
1.249 raeburn 6603: $output .= '<td><span class="LC_nobreak"><label><input type = "checkbox" value="'.$othervalue.'"';
1.241 raeburn 6604: if (ref($currinsttypes) eq 'ARRAY') {
6605: if (@{$currinsttypes} > 0) {
1.249 raeburn 6606: if (grep(/^any$/,@{$currinsttypes})) {
6607: $output .= ' checked="checked"';
6608: } elsif ($othervalue eq 'other') {
6609: if (grep(/^\Q$othervalue\E$/,@{$currinsttypes})) {
6610: $output .= ' checked="checked"';
6611: }
1.241 raeburn 6612: }
1.249 raeburn 6613: } else {
6614: $output .= ' checked="checked"';
1.241 raeburn 6615: }
1.249 raeburn 6616: } else {
6617: $output .= ' checked="checked"';
1.241 raeburn 6618: }
1.418 raeburn 6619: $output .= ' name="selfenroll_types_'.$num.'"'.$disabled.' />'.$othertitle.'</label></span></td></tr></table>';
1.241 raeburn 6620: }
6621: return $output;
6622: }
6623:
1.237 raeburn 6624: sub selfenroll_date_forms {
6625: my ($startform,$endform) = @_;
6626: my $output .= &Apache::lonhtmlcommon::start_pick_box()."\n".
1.244 bisitz 6627: &Apache::lonhtmlcommon::row_title(&mt('Start date'),
1.237 raeburn 6628: 'LC_oddrow_value')."\n".
6629: $startform."\n".
6630: &Apache::lonhtmlcommon::row_closure(1).
1.244 bisitz 6631: &Apache::lonhtmlcommon::row_title(&mt('End date'),
1.237 raeburn 6632: 'LC_oddrow_value')."\n".
6633: $endform."\n".
6634: &Apache::lonhtmlcommon::row_closure(1).
6635: &Apache::lonhtmlcommon::end_pick_box();
6636: return $output;
6637: }
6638:
1.239 raeburn 6639: sub print_userchangelogs_display {
1.415 raeburn 6640: my ($r,$context,$permission,$brcrum) = @_;
1.363 raeburn 6641: my $formname = 'rolelog';
1.418 raeburn 6642: my ($username,$domain,$crstype,$viewablesec,%roleslog);
1.363 raeburn 6643: if ($context eq 'domain') {
6644: $domain = $env{'request.role.domain'};
6645: %roleslog=&Apache::lonnet::dump_dom('nohist_rolelog',$domain);
6646: } else {
6647: if ($context eq 'course') {
6648: $domain = $env{'course.'.$env{'request.course.id'}.'.domain'};
6649: $username = $env{'course.'.$env{'request.course.id'}.'.num'};
6650: $crstype = &Apache::loncommon::course_type();
1.418 raeburn 6651: $viewablesec = &Apache::lonuserutils::viewable_section($permission);
1.363 raeburn 6652: my %saveable_parameters = ('show' => 'scalar',);
6653: &Apache::loncommon::store_course_settings('roles_log',
6654: \%saveable_parameters);
6655: &Apache::loncommon::restore_course_settings('roles_log',
6656: \%saveable_parameters);
6657: } elsif ($context eq 'author') {
6658: $domain = $env{'user.domain'};
6659: if ($env{'request.role'} =~ m{^au\./\Q$domain\E/$}) {
6660: $username = $env{'user.name'};
6661: } else {
6662: undef($domain);
6663: }
6664: }
6665: if ($domain ne '' && $username ne '') {
6666: %roleslog=&Apache::lonnet::dump('nohist_rolelog',$domain,$username);
6667: }
6668: }
1.239 raeburn 6669: if ((keys(%roleslog))[0]=~/^error\:/) { undef(%roleslog); }
6670:
1.415 raeburn 6671: my $helpitem;
6672: if ($context eq 'course') {
6673: $helpitem = 'Course_User_Logs';
1.439 raeburn 6674: } elsif ($context eq 'domain') {
6675: $helpitem = 'Domain_Role_Logs';
6676: } elsif ($context eq 'author') {
6677: $helpitem = 'Author_User_Logs';
1.415 raeburn 6678: }
6679: push (@{$brcrum},
6680: {href => '/adm/createuser?action=changelogs',
6681: text => 'User Management Logs',
6682: help => $helpitem});
6683: my $bread_crumbs_component = 'User Changes';
6684: my $args = { bread_crumbs => $brcrum,
6685: bread_crumbs_component => $bread_crumbs_component};
6686:
6687: # Create navigation javascript
6688: my $jsnav = &userlogdisplay_js($formname);
6689:
6690: my $jscript = (<<ENDSCRIPT);
6691: <script type="text/javascript">
6692: // <![CDATA[
6693: $jsnav
6694: // ]]>
6695: </script>
6696: ENDSCRIPT
6697:
6698: # print page header
6699: $r->print(&header($jscript,$args));
6700:
1.239 raeburn 6701: # set defaults
6702: my $now = time();
6703: my $defstart = $now - (7*24*3600); #7 days ago
6704: my %defaults = (
6705: page => '1',
6706: show => '10',
6707: role => 'any',
6708: chgcontext => 'any',
6709: rolelog_start_date => $defstart,
6710: rolelog_end_date => $now,
6711: );
6712: my $more_records = 0;
6713:
6714: # set current
6715: my %curr;
6716: foreach my $item ('show','page','role','chgcontext') {
6717: $curr{$item} = $env{'form.'.$item};
6718: }
6719: my ($startdate,$enddate) =
6720: &Apache::lonuserutils::get_dates_from_form('rolelog_start_date','rolelog_end_date');
6721: $curr{'rolelog_start_date'} = $startdate;
6722: $curr{'rolelog_end_date'} = $enddate;
6723: foreach my $key (keys(%defaults)) {
6724: if ($curr{$key} eq '') {
6725: $curr{$key} = $defaults{$key};
6726: }
6727: }
1.248 raeburn 6728: my (%whodunit,%changed,$version);
6729: ($version) = ($r->dir_config('lonVersion') =~ /^([\d\.]+)\-/);
1.239 raeburn 6730: my ($minshown,$maxshown);
1.255 raeburn 6731: $minshown = 1;
1.239 raeburn 6732: my $count = 0;
1.415 raeburn 6733: if ($curr{'show'} =~ /\D/) {
6734: $curr{'page'} = 1;
6735: } else {
1.239 raeburn 6736: $maxshown = $curr{'page'} * $curr{'show'};
6737: if ($curr{'page'} > 1) {
6738: $minshown = 1 + ($curr{'page'} - 1) * $curr{'show'};
6739: }
6740: }
1.301 bisitz 6741:
1.327 raeburn 6742: # Form Header
6743: $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">'.
1.363 raeburn 6744: &role_display_filter($context,$formname,$domain,$username,\%curr,
6745: $version,$crstype));
1.327 raeburn 6746:
6747: my $showntableheader = 0;
6748:
6749: # Table Header
6750: my $tableheader =
6751: &Apache::loncommon::start_data_table_header_row()
6752: .'<th> </th>'
6753: .'<th>'.&mt('When').'</th>'
6754: .'<th>'.&mt('Who made the change').'</th>'
6755: .'<th>'.&mt('Changed User').'</th>'
1.363 raeburn 6756: .'<th>'.&mt('Role').'</th>';
6757:
6758: if ($context eq 'course') {
6759: $tableheader .= '<th>'.&mt('Section').'</th>';
6760: }
6761: $tableheader .=
6762: '<th>'.&mt('Context').'</th>'
1.327 raeburn 6763: .'<th>'.&mt('Start').'</th>'
6764: .'<th>'.&mt('End').'</th>'
6765: .&Apache::loncommon::end_data_table_header_row();
6766:
6767: # Display user change log data
1.239 raeburn 6768: foreach my $id (sort { $roleslog{$b}{'exe_time'}<=>$roleslog{$a}{'exe_time'} } (keys(%roleslog))) {
6769: next if (($roleslog{$id}{'exe_time'} < $curr{'rolelog_start_date'}) ||
6770: ($roleslog{$id}{'exe_time'} > $curr{'rolelog_end_date'}));
1.415 raeburn 6771: if ($curr{'show'} !~ /\D/) {
1.239 raeburn 6772: if ($count >= $curr{'page'} * $curr{'show'}) {
6773: $more_records = 1;
6774: last;
6775: }
6776: }
6777: if ($curr{'role'} ne 'any') {
6778: next if ($roleslog{$id}{'logentry'}{'role'} ne $curr{'role'});
6779: }
6780: if ($curr{'chgcontext'} ne 'any') {
6781: if ($curr{'chgcontext'} eq 'selfenroll') {
6782: next if (!$roleslog{$id}{'logentry'}{'selfenroll'});
6783: } else {
6784: next if ($roleslog{$id}{'logentry'}{'context'} ne $curr{'chgcontext'});
6785: }
6786: }
1.418 raeburn 6787: if (($context eq 'course') && ($viewablesec ne '')) {
1.430 raeburn 6788: next if ($roleslog{$id}{'logentry'}{'section'} ne $viewablesec);
1.418 raeburn 6789: }
1.239 raeburn 6790: $count ++;
6791: next if ($count < $minshown);
1.327 raeburn 6792: unless ($showntableheader) {
1.415 raeburn 6793: $r->print(&Apache::loncommon::start_data_table()
1.327 raeburn 6794: .$tableheader);
6795: $r->rflush();
6796: $showntableheader = 1;
6797: }
1.239 raeburn 6798: if ($whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}} eq '') {
6799: $whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}} =
6800: &Apache::loncommon::plainname($roleslog{$id}{'exe_uname'},$roleslog{$id}{'exe_udom'});
6801: }
6802: if ($changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}} eq '') {
6803: $changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}} =
6804: &Apache::loncommon::plainname($roleslog{$id}{'uname'},$roleslog{$id}{'udom'});
6805: }
6806: my $sec = $roleslog{$id}{'logentry'}{'section'};
6807: if ($sec eq '') {
6808: $sec = &mt('None');
6809: }
6810: my ($rolestart,$roleend);
6811: if ($roleslog{$id}{'delflag'}) {
6812: $rolestart = &mt('deleted');
6813: $roleend = &mt('deleted');
6814: } else {
6815: $rolestart = $roleslog{$id}{'logentry'}{'start'};
6816: $roleend = $roleslog{$id}{'logentry'}{'end'};
6817: if ($rolestart eq '' || $rolestart == 0) {
6818: $rolestart = &mt('No start date');
6819: } else {
6820: $rolestart = &Apache::lonlocal::locallocaltime($rolestart);
6821: }
6822: if ($roleend eq '' || $roleend == 0) {
6823: $roleend = &mt('No end date');
6824: } else {
6825: $roleend = &Apache::lonlocal::locallocaltime($roleend);
6826: }
6827: }
6828: my $chgcontext = $roleslog{$id}{'logentry'}{'context'};
6829: if ($roleslog{$id}{'logentry'}{'selfenroll'}) {
6830: $chgcontext = 'selfenroll';
6831: }
1.363 raeburn 6832: my %lt = &rolechg_contexts($context,$crstype);
1.239 raeburn 6833: if ($chgcontext ne '' && $lt{$chgcontext} ne '') {
6834: $chgcontext = $lt{$chgcontext};
6835: }
1.327 raeburn 6836: $r->print(
1.301 bisitz 6837: &Apache::loncommon::start_data_table_row()
6838: .'<td>'.$count.'</td>'
6839: .'<td>'.&Apache::lonlocal::locallocaltime($roleslog{$id}{'exe_time'}).'</td>'
6840: .'<td>'.$whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}}.'</td>'
6841: .'<td>'.$changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}}.'</td>'
1.363 raeburn 6842: .'<td>'.&Apache::lonnet::plaintext($roleslog{$id}{'logentry'}{'role'},$crstype).'</td>');
6843: if ($context eq 'course') {
6844: $r->print('<td>'.$sec.'</td>');
6845: }
6846: $r->print(
6847: '<td>'.$chgcontext.'</td>'
1.301 bisitz 6848: .'<td>'.$rolestart.'</td>'
6849: .'<td>'.$roleend.'</td>'
1.327 raeburn 6850: .&Apache::loncommon::end_data_table_row()."\n");
1.301 bisitz 6851: }
6852:
1.327 raeburn 6853: if ($showntableheader) { # Table footer, if content displayed above
1.415 raeburn 6854: $r->print(&Apache::loncommon::end_data_table().
6855: &userlogdisplay_navlinks(\%curr,$more_records));
1.327 raeburn 6856: } else { # No content displayed above
1.301 bisitz 6857: $r->print('<p class="LC_info">'
6858: .&mt('There are no records to display.')
6859: .'</p>'
6860: );
1.239 raeburn 6861: }
1.301 bisitz 6862:
1.327 raeburn 6863: # Form Footer
6864: $r->print(
6865: '<input type="hidden" name="page" value="'.$curr{'page'}.'" />'
6866: .'<input type="hidden" name="action" value="changelogs" />'
6867: .'</form>');
6868: return;
6869: }
1.301 bisitz 6870:
1.416 raeburn 6871: sub print_useraccesslogs_display {
6872: my ($r,$uname,$udom,$permission,$brcrum) = @_;
6873: my $formname = 'accesslog';
6874: my $form = 'document.accesslog';
6875:
6876: # set breadcrumbs
1.422 raeburn 6877: my %breadcrumb_text = &singleuser_breadcrumb('','domain',$udom);
1.431 raeburn 6878: my $prevphasestr;
6879: if ($env{'form.popup'}) {
6880: $brcrum = [];
6881: } else {
6882: push (@{$brcrum},
6883: {href => "javascript:backPage($form)",
6884: text => $breadcrumb_text{'search'}});
6885: my @prevphases;
6886: if ($env{'form.prevphases'}) {
6887: @prevphases = split(/,/,$env{'form.prevphases'});
6888: $prevphasestr = $env{'form.prevphases'};
6889: }
6890: if (($env{'form.phase'} eq 'userpicked') || (grep(/^userpicked$/,@prevphases))) {
6891: push(@{$brcrum},
6892: {href => "javascript:backPage($form,'get_user_info','select')",
6893: text => $breadcrumb_text{'userpicked'}});
6894: if ($env{'form.phase'} eq 'userpicked') {
6895: $prevphasestr = 'userpicked';
6896: }
1.416 raeburn 6897: }
6898: }
6899: push(@{$brcrum},
6900: {href => '/adm/createuser?action=accesslogs',
6901: text => 'User access logs',
1.424 raeburn 6902: help => 'Domain_User_Access_Logs'});
1.416 raeburn 6903: my $bread_crumbs_component = 'User Access Logs';
6904: my $args = { bread_crumbs => $brcrum,
6905: bread_crumbs_component => 'User Management'};
1.423 raeburn 6906: if ($env{'form.popup'}) {
6907: $args->{'no_nav_bar'} = 1;
1.431 raeburn 6908: $args->{'bread_crumbs_nomenu'} = 1;
1.423 raeburn 6909: }
1.416 raeburn 6910:
1.417 raeburn 6911: # set javascript
1.416 raeburn 6912: my ($jsback,$elements) = &crumb_utilities();
6913: my $jsnav = &userlogdisplay_js($formname);
6914:
6915: my $jscript = (<<ENDSCRIPT);
6916: <script type="text/javascript">
6917: // <![CDATA[
6918:
6919: $jsback
6920: $jsnav
6921:
6922: // ]]>
6923: </script>
6924:
6925: ENDSCRIPT
6926:
1.417 raeburn 6927: # print page header
1.416 raeburn 6928: $r->print(&header($jscript,$args));
6929:
6930: # early out unless log data can be displayed.
6931: unless ($permission->{'activity'}) {
6932: $r->print('<p class="LC_warning">'
6933: .&mt('You do not have rights to display user access logs.')
1.431 raeburn 6934: .'</p>');
6935: if ($env{'form.popup'}) {
6936: $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a></p>');
6937: } else {
6938: $r->print(&earlyout_accesslog_form($formname,$prevphasestr,$udom));
6939: }
1.416 raeburn 6940: return;
6941: }
6942:
6943: unless ($udom eq $env{'request.role.domain'}) {
6944: $r->print('<p class="LC_warning">'
6945: .&mt("User's domain must match role's domain")
6946: .'</p>'
6947: .&earlyout_accesslog_form($formname,$prevphasestr,$udom));
1.417 raeburn 6948: return;
1.416 raeburn 6949: }
6950:
6951: if (($uname eq '') || ($udom eq '')) {
6952: $r->print('<p class="LC_warning">'
6953: .&mt('Invalid username or domain')
6954: .'</p>'
6955: .&earlyout_accesslog_form($formname,$prevphasestr,$udom));
6956: return;
6957: }
6958:
1.437 raeburn 6959: if (&Apache::lonnet::privileged($uname,$udom,
6960: [$env{'request.role.domain'}],['dc','su'])) {
6961: unless (&Apache::lonnet::privileged($env{'user.name'},$env{'user.domain'},
6962: [$env{'request.role.domain'}],['dc','su'])) {
6963: $r->print('<p class="LC_warning">'
6964: .&mt('You need to be a privileged user to display user access logs for [_1]',
6965: &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),
6966: $uname,$udom))
6967: .'</p>');
6968: if ($env{'form.popup'}) {
6969: $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a></p>');
6970: } else {
6971: $r->print(&earlyout_accesslog_form($formname,$prevphasestr,$udom));
6972: }
6973: return;
6974: }
6975: }
6976:
1.416 raeburn 6977: # set defaults
6978: my $now = time();
6979: my $defstart = $now - (7*24*3600);
6980: my %defaults = (
6981: page => '1',
6982: show => '10',
6983: activity => 'any',
6984: accesslog_start_date => $defstart,
6985: accesslog_end_date => $now,
6986: );
6987: my $more_records = 0;
6988:
6989: # set current
6990: my %curr;
6991: foreach my $item ('show','page','activity') {
6992: $curr{$item} = $env{'form.'.$item};
6993: }
6994: my ($startdate,$enddate) =
6995: &Apache::lonuserutils::get_dates_from_form('accesslog_start_date','accesslog_end_date');
6996: $curr{'accesslog_start_date'} = $startdate;
6997: $curr{'accesslog_end_date'} = $enddate;
6998: foreach my $key (keys(%defaults)) {
6999: if ($curr{$key} eq '') {
7000: $curr{$key} = $defaults{$key};
7001: }
7002: }
7003: my ($minshown,$maxshown);
7004: $minshown = 1;
7005: my $count = 0;
7006: if ($curr{'show'} =~ /\D/) {
7007: $curr{'page'} = 1;
7008: } else {
7009: $maxshown = $curr{'page'} * $curr{'show'};
7010: if ($curr{'page'} > 1) {
7011: $minshown = 1 + ($curr{'page'} - 1) * $curr{'show'};
7012: }
7013: }
7014:
7015: # form header
7016: $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">'.
7017: &activity_display_filter($formname,\%curr));
7018:
7019: my $showntableheader = 0;
7020: my ($nav_script,$nav_links);
7021:
7022: # table header
1.431 raeburn 7023: my $tableheader = '<h3>'.
7024: &mt('User access logs for: [_1]',
7025: &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),$uname,$udom)).'</h3>'
7026: .&Apache::loncommon::start_data_table_header_row()
1.416 raeburn 7027: .'<th> </th>'
7028: .'<th>'.&mt('When').'</th>'
7029: .'<th>'.&mt('HostID').'</th>'
7030: .'<th>'.&mt('Event').'</th>'
7031: .'<th>'.&mt('Other data').'</th>'
7032: .&Apache::loncommon::end_data_table_header_row();
7033:
7034: my %filters=(
7035: start => $curr{'accesslog_start_date'},
7036: end => $curr{'accesslog_end_date'},
7037: action => $curr{'activity'},
7038: );
7039:
7040: my $reply = &Apache::lonnet::userlog_query($uname,$udom,%filters);
7041: unless ( ($reply =~/^timeout/) || ($reply =~/^error/) ) {
7042: my (%courses,%missing);
7043: my @results = split(/\&/,$reply);
7044: foreach my $item (reverse(@results)) {
7045: my ($timestamp,$host,$event) = split(/:/,$item);
7046: next unless ($event =~ /^(Log|Role)/);
7047: if ($curr{'show'} !~ /\D/) {
7048: if ($count >= $curr{'page'} * $curr{'show'}) {
7049: $more_records = 1;
7050: last;
7051: }
7052: }
7053: $count ++;
7054: next if ($count < $minshown);
7055: unless ($showntableheader) {
7056: $r->print($nav_script
7057: .&Apache::loncommon::start_data_table()
7058: .$tableheader);
7059: $r->rflush();
7060: $showntableheader = 1;
7061: }
1.418 raeburn 7062: my ($shown,$extra);
1.437 raeburn 7063: my ($event,$data) = split(/\s+/,&unescape($event),2);
1.416 raeburn 7064: if ($event eq 'Role') {
7065: my ($rolecode,$extent) = split(/\./,$data,2);
7066: next if ($extent eq '');
7067: my ($crstype,$desc,$info);
1.418 raeburn 7068: if ($extent =~ m{^/($match_domain)/($match_courseid)(?:/(\w+)|)$}) {
7069: my ($cdom,$cnum,$sec) = ($1,$2,$3);
1.416 raeburn 7070: my $cid = $cdom.'_'.$cnum;
7071: if (exists($courses{$cid})) {
7072: $crstype = $courses{$cid}{'type'};
7073: $desc = $courses{$cid}{'description'};
7074: } elsif ($missing{$cid}) {
7075: $crstype = 'Course';
7076: $desc = 'Course/Community';
7077: } else {
7078: my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',$cnum,undef,undef,'.');
7079: if (ref($crsinfo{$cdom.'_'.$cnum}) eq 'HASH') {
7080: $courses{$cid} = $crsinfo{$cid};
7081: $crstype = $crsinfo{$cid}{'type'};
7082: $desc = $crsinfo{$cid}{'description'};
7083: } else {
7084: $missing{$cid} = 1;
7085: }
7086: }
7087: $extra = &mt($crstype).': <a href="/public/'.$cdom.'/'.$cnum.'/syllabus">'.$desc.'</a>';
1.418 raeburn 7088: if ($sec ne '') {
7089: $extra .= ' ('.&mt('Section: [_1]',$sec).')';
7090: }
1.416 raeburn 7091: } elsif ($extent =~ m{^/($match_domain)/($match_username|$)}) {
7092: my ($dom,$name) = ($1,$2);
7093: if ($rolecode eq 'au') {
7094: $extra = '';
7095: } elsif ($rolecode =~ /^(ca|aa)$/) {
1.417 raeburn 7096: $extra = &mt('Authoring Space: [_1]',$name.':'.$dom);
1.416 raeburn 7097: } elsif ($rolecode =~ /^(li|dg|dh|dc|sc)$/) {
7098: $extra = &mt('Domain: [_1]',$dom);
7099: }
7100: }
7101: my $rolename;
7102: if ($rolecode =~ m{^cr/($match_domain)/($match_username)/(\w+)}) {
7103: my $role = $3;
1.417 raeburn 7104: my $owner = "($2:$1)";
1.416 raeburn 7105: if ($2 eq $1.'-domainconfig') {
7106: $owner = '(ad hoc)';
1.417 raeburn 7107: }
1.416 raeburn 7108: $rolename = &mt('Custom role: [_1]',$role.' '.$owner);
7109: } else {
7110: $rolename = &Apache::lonnet::plaintext($rolecode,$crstype);
7111: }
7112: $shown = &mt('Role selection: [_1]',$rolename);
7113: } else {
7114: $shown = &mt($event);
1.437 raeburn 7115: if ($data =~ /^webdav/) {
7116: my ($path,$clientip) = split(/\s+/,$data,2);
7117: $path =~ s/^webdav//;
7118: if ($clientip ne '') {
7119: $extra = &mt('Client IP address: [_1]',$clientip);
7120: }
7121: if ($path ne '') {
7122: $shown .= ' '.&mt('(WebDAV access to [_1])',$path);
7123: }
7124: } elsif ($data ne '') {
7125: $extra = &mt('Client IP address: [_1]',$data);
1.416 raeburn 7126: }
7127: }
7128: $r->print(
7129: &Apache::loncommon::start_data_table_row()
7130: .'<td>'.$count.'</td>'
7131: .'<td>'.&Apache::lonlocal::locallocaltime($timestamp).'</td>'
7132: .'<td>'.$host.'</td>'
7133: .'<td>'.$shown.'</td>'
7134: .'<td>'.$extra.'</td>'
7135: .&Apache::loncommon::end_data_table_row()."\n");
7136: }
7137: }
7138:
7139: if ($showntableheader) { # Table footer, if content displayed above
7140: $r->print(&Apache::loncommon::end_data_table().
7141: &userlogdisplay_navlinks(\%curr,$more_records));
7142: } else { # No content displayed above
7143: $r->print('<p class="LC_info">'
7144: .&mt('There are no records to display.')
7145: .'</p>');
7146: }
7147:
1.423 raeburn 7148: if ($env{'form.popup'} == 1) {
7149: $r->print('<input type="hidden" name="popup" value="1" />'."\n");
7150: }
7151:
1.416 raeburn 7152: # Form Footer
7153: $r->print(
7154: '<input type="hidden" name="currstate" value="" />'
7155: .'<input type="hidden" name="accessuname" value="'.$uname.'" />'
7156: .'<input type="hidden" name="accessudom" value="'.$udom.'" />'
7157: .'<input type="hidden" name="page" value="'.$curr{'page'}.'" />'
7158: .'<input type="hidden" name="prevphases" value="'.$prevphasestr.'" />'
7159: .'<input type="hidden" name="phase" value="activity" />'
7160: .'<input type="hidden" name="action" value="accesslogs" />'
7161: .'<input type="hidden" name="srchdomain" value="'.$udom.'" />'
7162: .'<input type="hidden" name="srchby" value="'.$env{'form.srchby'}.'" />'
7163: .'<input type="hidden" name="srchtype" value="'.$env{'form.srchtype'}.'" />'
7164: .'<input type="hidden" name="srchterm" value="'.&HTML::Entities::encode($env{'form.srchterm'},'<>"&').'" />'
7165: .'<input type="hidden" name="srchin" value="'.$env{'form.srchin'}.'" />'
7166: .'</form>');
7167: return;
7168: }
7169:
7170: sub earlyout_accesslog_form {
7171: my ($formname,$prevphasestr,$udom) = @_;
7172: my $srchterm = &HTML::Entities::encode($env{'form.srchterm'},'<>"&');
7173: return <<"END";
7174: <form action="/adm/createuser" method="post" name="$formname">
7175: <input type="hidden" name="currstate" value="" />
7176: <input type="hidden" name="prevphases" value="$prevphasestr" />
7177: <input type="hidden" name="phase" value="activity" />
7178: <input type="hidden" name="action" value="accesslogs" />
7179: <input type="hidden" name="srchdomain" value="$udom" />
7180: <input type="hidden" name="srchby" value="$env{'form.srchby'}" />
7181: <input type="hidden" name="srchtype" value="$env{'form.srchtype'}" />
7182: <input type="hidden" name="srchterm" value="$srchterm" />
7183: <input type="hidden" name="srchin" value="$env{'form.srchin'}" />
7184: </form>
7185: END
7186: }
7187:
7188: sub activity_display_filter {
7189: my ($formname,$curr) = @_;
7190: my $nolink = 1;
7191: my $output = '<table><tr><td valign="top">'.
7192: '<span class="LC_nobreak"><b>'.&mt('Actions/page:').'</b></span><br />'.
7193: &Apache::lonmeta::selectbox('show',$curr->{'show'},undef,
7194: (&mt('all'),5,10,20,50,100,1000,10000)).
7195: '</td><td> </td>';
7196: my $startform =
7197: &Apache::lonhtmlcommon::date_setter($formname,'accesslog_start_date',
7198: $curr->{'accesslog_start_date'},undef,
7199: undef,undef,undef,undef,undef,undef,$nolink);
7200: my $endform =
7201: &Apache::lonhtmlcommon::date_setter($formname,'accesslog_end_date',
7202: $curr->{'accesslog_end_date'},undef,
7203: undef,undef,undef,undef,undef,undef,$nolink);
7204: my %lt = &Apache::lonlocal::texthash (
7205: activity => 'Activity',
7206: Role => 'Role selection',
7207: log => 'Log-in or Logout',
7208: );
7209: $output .= '<td valign="top"><b>'.&mt('Window during which actions occurred:').'</b><br />'.
7210: '<table><tr><td>'.&mt('After:').
7211: '</td><td>'.$startform.'</td></tr>'.
7212: '<tr><td>'.&mt('Before:').'</td>'.
7213: '<td>'.$endform.'</td></tr></table>'.
7214: '</td>'.
7215: '<td> </td>'.
7216: '<td valign="top"><b>'.&mt('Activities').'</b><br />'.
7217: '<select name="activity"><option value="any"';
7218: if ($curr->{'activity'} eq 'any') {
7219: $output .= ' selected="selected"';
7220: }
7221: $output .= '>'.&mt('Any').'</option>'."\n";
7222: foreach my $activity ('Role','log') {
7223: my $selstr = '';
7224: if ($activity eq $curr->{'activity'}) {
7225: $selstr = ' selected="selected"';
7226: }
7227: $output .= '<option value="'.$activity.'"'.$selstr.'>'.$lt{$activity}.'</option>';
7228: }
7229: $output .= '</select></td>'.
7230: '</tr></table>';
7231: # Update Display button
7232: $output .= '<p>'
7233: .'<input type="submit" value="'.&mt('Update Display').'" />'
1.431 raeburn 7234: .'</p><hr />';
1.416 raeburn 7235: return $output;
7236: }
7237:
1.415 raeburn 7238: sub userlogdisplay_js {
7239: my ($formname) = @_;
7240: return <<"ENDSCRIPT";
7241:
1.239 raeburn 7242: function chgPage(caller) {
7243: if (caller == 'previous') {
7244: document.$formname.page.value --;
7245: }
7246: if (caller == 'next') {
7247: document.$formname.page.value ++;
7248: }
1.327 raeburn 7249: document.$formname.submit();
1.239 raeburn 7250: return;
7251: }
7252: ENDSCRIPT
1.415 raeburn 7253: }
7254:
7255: sub userlogdisplay_navlinks {
7256: my ($curr,$more_records) = @_;
7257: return unless(ref($curr) eq 'HASH');
7258: # Navigation Buttons
7259: my $nav_links = '<p>';
7260: if (($curr->{'page'} > 1) || ($more_records)) {
7261: if (($curr->{'page'} > 1) && ($curr->{'show'} !~ /\D/)) {
7262: $nav_links .= '<input type="button"'
7263: .' onclick="javascript:chgPage('."'previous'".');"'
7264: .' value="'.&mt('Previous [_1] changes',$curr->{'show'})
7265: .'" /> ';
7266: }
7267: if ($more_records) {
7268: $nav_links .= '<input type="button"'
7269: .' onclick="javascript:chgPage('."'next'".');"'
7270: .' value="'.&mt('Next [_1] changes',$curr->{'show'})
7271: .'" />';
1.301 bisitz 7272: }
7273: }
1.415 raeburn 7274: $nav_links .= '</p>';
7275: return $nav_links;
1.239 raeburn 7276: }
7277:
7278: sub role_display_filter {
1.363 raeburn 7279: my ($context,$formname,$cdom,$cnum,$curr,$version,$crstype) = @_;
7280: my $lctype;
7281: if ($context eq 'course') {
7282: $lctype = lc($crstype);
7283: }
1.239 raeburn 7284: my $nolink = 1;
7285: my $output = '<table><tr><td valign="top">'.
1.301 bisitz 7286: '<span class="LC_nobreak"><b>'.&mt('Changes/page:').'</b></span><br />'.
1.239 raeburn 7287: &Apache::lonmeta::selectbox('show',$curr->{'show'},undef,
7288: (&mt('all'),5,10,20,50,100,1000,10000)).
7289: '</td><td> </td>';
7290: my $startform =
7291: &Apache::lonhtmlcommon::date_setter($formname,'rolelog_start_date',
7292: $curr->{'rolelog_start_date'},undef,
7293: undef,undef,undef,undef,undef,undef,$nolink);
7294: my $endform =
7295: &Apache::lonhtmlcommon::date_setter($formname,'rolelog_end_date',
7296: $curr->{'rolelog_end_date'},undef,
7297: undef,undef,undef,undef,undef,undef,$nolink);
1.363 raeburn 7298: my %lt = &rolechg_contexts($context,$crstype);
1.301 bisitz 7299: $output .= '<td valign="top"><b>'.&mt('Window during which changes occurred:').'</b><br />'.
7300: '<table><tr><td>'.&mt('After:').
7301: '</td><td>'.$startform.'</td></tr>'.
7302: '<tr><td>'.&mt('Before:').'</td>'.
7303: '<td>'.$endform.'</td></tr></table>'.
7304: '</td>'.
7305: '<td> </td>'.
1.239 raeburn 7306: '<td valign="top"><b>'.&mt('Role:').'</b><br />'.
7307: '<select name="role"><option value="any"';
7308: if ($curr->{'role'} eq 'any') {
7309: $output .= ' selected="selected"';
7310: }
7311: $output .= '>'.&mt('Any').'</option>'."\n";
1.363 raeburn 7312: my @roles = &Apache::lonuserutils::roles_by_context($context,1,$crstype);
1.239 raeburn 7313: foreach my $role (@roles) {
7314: my $plrole;
7315: if ($role eq 'cr') {
7316: $plrole = &mt('Custom Role');
7317: } else {
1.318 raeburn 7318: $plrole=&Apache::lonnet::plaintext($role,$crstype);
1.239 raeburn 7319: }
7320: my $selstr = '';
7321: if ($role eq $curr->{'role'}) {
7322: $selstr = ' selected="selected"';
7323: }
7324: $output .= ' <option value="'.$role.'"'.$selstr.'>'.$plrole.'</option>';
7325: }
1.301 bisitz 7326: $output .= '</select></td>'.
7327: '<td> </td>'.
7328: '<td valign="top"><b>'.
1.239 raeburn 7329: &mt('Context:').'</b><br /><select name="chgcontext">';
1.363 raeburn 7330: my @posscontexts;
7331: if ($context eq 'course') {
1.376 raeburn 7332: @posscontexts = ('any','automated','updatenow','createcourse','course','domain','selfenroll','requestcourses');
1.363 raeburn 7333: } elsif ($context eq 'domain') {
7334: @posscontexts = ('any','domain','requestauthor','domconfig','server');
7335: } else {
7336: @posscontexts = ('any','author','domain');
7337: }
7338: foreach my $chgtype (@posscontexts) {
1.239 raeburn 7339: my $selstr = '';
7340: if ($curr->{'chgcontext'} eq $chgtype) {
1.301 bisitz 7341: $selstr = ' selected="selected"';
1.239 raeburn 7342: }
1.363 raeburn 7343: if ($context eq 'course') {
1.376 raeburn 7344: if (($chgtype eq 'automated') || ($chgtype eq 'updatenow')) {
1.363 raeburn 7345: next if (!&Apache::lonnet::auto_run($cnum,$cdom));
7346: }
1.239 raeburn 7347: }
7348: $output .= '<option value="'.$chgtype.'"'.$selstr.'>'.$lt{$chgtype}.'</option>'."\n";
1.248 raeburn 7349: }
1.303 bisitz 7350: $output .= '</select></td>'
7351: .'</tr></table>';
7352:
7353: # Update Display button
7354: $output .= '<p>'
7355: .'<input type="submit" value="'.&mt('Update Display').'" />'
7356: .'</p>';
7357:
7358: # Server version info
1.363 raeburn 7359: my $needsrev = '2.11.0';
7360: if ($context eq 'course') {
7361: $needsrev = '2.7.0';
7362: }
7363:
1.303 bisitz 7364: $output .= '<p class="LC_info">'
7365: .&mt('Only changes made from servers running LON-CAPA [_1] or later are displayed.'
1.363 raeburn 7366: ,$needsrev);
1.248 raeburn 7367: if ($version) {
1.303 bisitz 7368: $output .= ' '.&mt('This LON-CAPA server is version [_1]',$version);
7369: }
7370: $output .= '</p><hr />';
1.239 raeburn 7371: return $output;
7372: }
7373:
7374: sub rolechg_contexts {
1.363 raeburn 7375: my ($context,$crstype) = @_;
7376: my %lt;
7377: if ($context eq 'course') {
7378: %lt = &Apache::lonlocal::texthash (
1.239 raeburn 7379: any => 'Any',
1.376 raeburn 7380: automated => 'Automated Enrollment',
1.239 raeburn 7381: updatenow => 'Roster Update',
7382: createcourse => 'Course Creation',
7383: course => 'User Management in course',
7384: domain => 'User Management in domain',
1.313 raeburn 7385: selfenroll => 'Self-enrolled',
1.318 raeburn 7386: requestcourses => 'Course Request',
1.239 raeburn 7387: );
1.363 raeburn 7388: if ($crstype eq 'Community') {
7389: $lt{'createcourse'} = &mt('Community Creation');
7390: $lt{'course'} = &mt('User Management in community');
7391: $lt{'requestcourses'} = &mt('Community Request');
7392: }
7393: } elsif ($context eq 'domain') {
7394: %lt = &Apache::lonlocal::texthash (
7395: any => 'Any',
7396: domain => 'User Management in domain',
7397: requestauthor => 'Authoring Request',
7398: server => 'Command line script (DC role)',
7399: domconfig => 'Self-enrolled',
7400: );
7401: } else {
7402: %lt = &Apache::lonlocal::texthash (
7403: any => 'Any',
7404: domain => 'User Management in domain',
7405: author => 'User Management by author',
7406: );
7407: }
1.239 raeburn 7408: return %lt;
7409: }
7410:
1.428 raeburn 7411: sub print_helpdeskaccess_display {
7412: my ($r,$permission,$brcrum) = @_;
7413: my $formname = 'helpdeskaccess';
7414: my $helpitem = 'Course_Helpdesk_Access';
7415: push (@{$brcrum},
7416: {href => '/adm/createuser?action=helpdesk',
7417: text => 'Helpdesk Access',
7418: help => $helpitem});
7419: my $bread_crumbs_component = 'Helpdesk Staff Access';
7420: my $args = { bread_crumbs => $brcrum,
7421: bread_crumbs_component => $bread_crumbs_component};
7422:
7423: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
7424: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
7425: my $confname = $cdom.'-domainconfig';
7426: my $crstype = &Apache::loncommon::course_type();
7427:
1.434 raeburn 7428: my @accesstypes = ('all','dh','da','none');
1.428 raeburn 7429: my ($numstatustypes,@jsarray);
7430: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($cdom);
7431: if (ref($types) eq 'ARRAY') {
1.430 raeburn 7432: if (@{$types} > 0) {
1.428 raeburn 7433: $numstatustypes = scalar(@{$types});
7434: push(@accesstypes,'status');
7435: @jsarray = ('bystatus');
7436: }
7437: }
7438: my %customroles = &get_domain_customroles($cdom,$confname);
1.432 raeburn 7439: my %domhelpdesk = &Apache::lonnet::get_active_domroles($cdom,['dh','da']);
1.428 raeburn 7440: if (keys(%domhelpdesk)) {
7441: push(@accesstypes,('inc','exc'));
7442: push(@jsarray,('notinc','notexc'));
7443: }
7444: push(@jsarray,'privs');
7445: my $hiddenstr = join("','",@jsarray);
7446: my $rolestr = join("','",sort(keys(%customroles)));
7447:
7448: my $jscript;
7449: my (%settings,%overridden);
7450: if (keys(%customroles)) {
7451: &get_adhocrole_settings($env{'request.course.id'},\@accesstypes,
7452: $types,\%customroles,\%settings,\%overridden);
7453: my %jsfull=();
7454: my %jslevels= (
7455: course => {},
7456: domain => {},
7457: system => {},
7458: );
7459: my %jslevelscurrent=(
7460: course => {},
7461: domain => {},
7462: system => {},
7463: );
7464: my (%privs,%jsprivs);
7465: &Apache::lonuserutils::custom_role_privs(\%privs,\%jsfull,\%jslevels,\%jslevelscurrent);
7466: foreach my $priv (keys(%jsfull)) {
7467: if ($jslevels{'course'}{$priv}) {
7468: $jsprivs{$priv} = 1;
7469: }
7470: }
7471: my (%elements,%stored);
7472: foreach my $role (keys(%customroles)) {
7473: $elements{$role.'_access'} = 'radio';
7474: $elements{$role.'_incrs'} = 'radio';
7475: if ($numstatustypes) {
7476: $elements{$role.'_status'} = 'checkbox';
7477: }
7478: if (keys(%domhelpdesk) > 0) {
7479: $elements{$role.'_staff_inc'} = 'checkbox';
7480: $elements{$role.'_staff_exc'} = 'checkbox';
7481: }
1.430 raeburn 7482: $elements{$role.'_override'} = 'checkbox';
1.428 raeburn 7483: if (ref($settings{$role}) eq 'HASH') {
7484: if ($settings{$role}{'access'} ne '') {
7485: my $curraccess = $settings{$role}{'access'};
7486: $stored{$role.'_access'} = $curraccess;
7487: $stored{$role.'_incrs'} = 1;
7488: if ($curraccess eq 'status') {
7489: if (ref($settings{$role}{'status'}) eq 'ARRAY') {
7490: $stored{$role.'_status'} = $settings{$role}{'status'};
7491: }
7492: } elsif (($curraccess eq 'exc') || ($curraccess eq 'inc')) {
7493: if (ref($settings{$role}{$curraccess}) eq 'ARRAY') {
7494: $stored{$role.'_staff_'.$curraccess} = $settings{$role}{$curraccess};
7495: }
7496: }
7497: } else {
7498: $stored{$role.'_incrs'} = 0;
7499: }
7500: $stored{$role.'_override'} = [];
7501: if ($env{'course.'.$env{'request.course.id'}.'.internal.adhocpriv.'.$role}) {
7502: if (ref($settings{$role}{'off'}) eq 'ARRAY') {
7503: foreach my $priv (@{$settings{$role}{'off'}}) {
7504: push(@{$stored{$role.'_override'}},$priv);
7505: }
7506: }
7507: if (ref($settings{$role}{'on'}) eq 'ARRAY') {
7508: foreach my $priv (@{$settings{$role}{'on'}}) {
7509: unless (grep(/^$priv$/,@{$stored{$role.'_override'}})) {
7510: push(@{$stored{$role.'_override'}},$priv);
7511: }
7512: }
7513: }
7514: }
7515: } else {
7516: $stored{$role.'_incrs'} = 0;
7517: }
7518: }
7519: $jscript = &Apache::lonhtmlcommon::set_form_elements(\%elements,\%stored);
7520: }
7521:
7522: my $js = <<"ENDJS";
7523: <script type="text/javascript">
7524: // <![CDATA[
7525: $jscript;
7526:
7527: function switchRoleTab(caller,role) {
7528: if (document.getElementById(role+'_maindiv')) {
7529: if (caller.id != 'LC_current_minitab') {
7530: if (document.getElementById('LC_current_minitab')) {
7531: document.getElementById('LC_current_minitab').id=null;
7532: }
7533: var roledivs = Array('$rolestr');
7534: if (roledivs.length > 0) {
7535: for (var i=0; i<roledivs.length; i++) {
7536: if (document.getElementById(roledivs[i]+'_maindiv')) {
7537: document.getElementById(roledivs[i]+'_maindiv').style.display='none';
7538: }
7539: }
7540: }
7541: caller.id = 'LC_current_minitab';
7542: document.getElementById(role+'_maindiv').style.display='block';
7543: }
7544: }
7545: return false;
1.430 raeburn 7546: }
1.428 raeburn 7547:
7548: function helpdeskAccess(role) {
7549: var curraccess = null;
7550: if (document.$formname.elements[role+'_access'].length) {
7551: for (var i=0; i<document.$formname.elements[role+'_access'].length; i++) {
7552: if (document.$formname.elements[role+'_access'][i].checked) {
7553: curraccess = document.$formname.elements[role+'_access'][i].value;
7554: }
7555: }
7556: }
7557: var shown = Array();
7558: var hidden = Array();
7559: if (curraccess == 'none') {
1.430 raeburn 7560: hidden = Array ('$hiddenstr');
1.428 raeburn 7561: } else {
7562: if (curraccess == 'status') {
1.430 raeburn 7563: shown = Array ('bystatus','privs');
7564: hidden = Array ('notinc','notexc');
1.428 raeburn 7565: } else {
7566: if (curraccess == 'exc') {
7567: shown = Array ('notexc','privs');
7568: hidden = Array ('notinc','bystatus');
7569: }
7570: if (curraccess == 'inc') {
7571: shown = Array ('notinc','privs');
7572: hidden = Array ('notexc','bystatus');
7573: }
7574: if (curraccess == 'all') {
7575: shown = Array ('privs');
7576: hidden = Array ('notinc','notexc','bystatus');
7577: }
7578: }
7579: }
7580: if (hidden.length > 0) {
7581: for (var i=0; i<hidden.length; i++) {
7582: if (document.getElementById(role+'_'+hidden[i])) {
1.430 raeburn 7583: document.getElementById(role+'_'+hidden[i]).style.display = 'none';
1.428 raeburn 7584: }
7585: }
7586: }
7587: if (shown.length > 0) {
7588: for (var i=0; i<shown.length; i++) {
7589: if (document.getElementById(role+'_'+shown[i])) {
7590: if (shown[i] == 'privs') {
7591: document.getElementById(role+'_'+shown[i]).style.display = 'block';
7592: } else {
7593: document.getElementById(role+'_'+shown[i]).style.display = 'inline';
7594: }
7595: }
7596: }
7597: }
7598: return;
7599: }
7600:
7601: function toggleAccess(role) {
7602: if ((document.getElementById(role+'_setincrs')) &&
7603: (document.getElementById(role+'_setindom'))) {
7604: for (var i=0; i<document.$formname.elements[role+'_incrs'].length; i++) {
7605: if (document.$formname.elements[role+'_incrs'][i].checked) {
7606: if (document.$formname.elements[role+'_incrs'][i].value == 1) {
7607: document.getElementById(role+'_setindom').style.display = 'none';
1.430 raeburn 7608: document.getElementById(role+'_setincrs').style.display = 'block';
1.428 raeburn 7609: } else {
7610: document.getElementById(role+'_setincrs').style.display = 'none';
7611: document.getElementById(role+'_setindom').style.display = 'block';
7612: }
7613: break;
7614: }
7615: }
7616: }
7617: return;
7618: }
7619:
7620: // ]]>
7621: </script>
7622: ENDJS
7623:
7624: $args->{add_entries} = {onload => "javascript:setFormElements(document.$formname)"};
7625:
7626: # print page header
7627: $r->print(&header($js,$args));
7628: # print form header
7629: $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">');
7630:
7631: if (keys(%customroles)) {
7632: my %lt = &Apache::lonlocal::texthash(
7633: 'aco' => 'As course owner you may override the defaults set in the domain for role usage and/or privileges.',
7634: 'rou' => 'Role usage',
7635: 'whi' => 'Which helpdesk personnel may use this role?',
7636: 'udd' => 'Use domain default',
1.433 raeburn 7637: 'all' => 'All with domain helpdesk or helpdesk assistant role',
1.434 raeburn 7638: 'dh' => 'All with domain helpdesk role',
7639: 'da' => 'All with domain helpdesk assistant role',
1.428 raeburn 7640: 'none' => 'None',
7641: 'status' => 'Determined based on institutional status',
1.430 raeburn 7642: 'inc' => 'Include all, but exclude specific personnel',
1.428 raeburn 7643: 'exc' => 'Exclude all, but include specific personnel',
7644: 'hel' => 'Helpdesk',
7645: 'rpr' => 'Role privileges',
7646: );
7647: $lt{'tfh'} = &mt("Custom [_1]ad hoc[_2] course roles available for use by the domain's helpdesk are as follows",'<i>','</i>');
7648: my %domconfig = &Apache::lonnet::get_dom('configuration',['helpsettings'],$cdom);
7649: my (%domcurrent,%ordered,%description,%domusage,$disabled);
7650: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
7651: if (ref($domconfig{'helpsettings'}{'adhoc'}) eq 'HASH') {
7652: %domcurrent = %{$domconfig{'helpsettings'}{'adhoc'}};
7653: }
7654: }
7655: my $count = 0;
7656: foreach my $role (sort(keys(%customroles))) {
7657: my ($order,$desc,$access_in_dom);
7658: if (ref($domcurrent{$role}) eq 'HASH') {
7659: $order = $domcurrent{$role}{'order'};
7660: $desc = $domcurrent{$role}{'desc'};
7661: $access_in_dom = $domcurrent{$role}{'access'};
7662: }
7663: if ($order eq '') {
7664: $order = $count;
7665: }
7666: $ordered{$order} = $role;
7667: if ($desc ne '') {
7668: $description{$role} = $desc;
7669: } else {
7670: $description{$role}= $role;
7671: }
7672: $count++;
7673: }
7674: %domusage = &domain_adhoc_access(\%customroles,\%domcurrent,\@accesstypes,$usertypes,$othertitle);
7675: my @roles_by_num = ();
7676: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
7677: push(@roles_by_num,$ordered{$item});
1.430 raeburn 7678: }
1.429 raeburn 7679: $r->print('<p>'.$lt{'tfh'}.': <i>'.join('</i>, <i>',map { $description{$_}; } @roles_by_num).'</i>.');
1.428 raeburn 7680: if ($permission->{'owner'}) {
7681: $r->print('<br />'.$lt{'aco'}.'</p><p>');
7682: $r->print('<input type="hidden" name="state" value="process" />'.
7683: '<input type="submit" value="'.&mt('Save changes').'" />');
7684: } else {
7685: if ($env{'course.'.$env{'request.course.id'}.'.internal.courseowner'}) {
7686: my ($ownername,$ownerdom) = split(/:/,$env{'course.'.$env{'request.course.id'}.'.internal.courseowner'});
7687: $r->print('<br />'.&mt('The course owner -- [_1] -- can override the default access and/or privileges for these ad hoc roles.',
7688: &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($ownername,$ownerdom),$ownername,$ownerdom)));
7689: }
7690: $disabled = ' disabled="disabled"';
7691: }
7692: $r->print('</p>');
7693:
7694: $r->print('<div id="LC_minitab_header"><ul>');
7695: my $count = 0;
7696: my %visibility;
7697: foreach my $role (@roles_by_num) {
7698: my $id;
7699: if ($count == 0) {
7700: $id=' id="LC_current_minitab"';
1.430 raeburn 7701: $visibility{$role} = ' style="display:block"';
1.428 raeburn 7702: } else {
7703: $visibility{$role} = ' style="display:none"';
7704: }
7705: $count ++;
7706: $r->print('<li'.$id.'><a href="#" onclick="javascript:switchRoleTab(this.parentNode,'."'$role'".');">'.$description{$role}.'</a></li>');
7707: }
7708: $r->print('</ul></div>');
7709:
7710: foreach my $role (@roles_by_num) {
7711: my %usecheck = (
7712: all => ' checked="checked"',
7713: );
7714: my %displaydiv = (
7715: status => 'none',
7716: inc => 'none',
7717: exc => 'none',
7718: priv => 'block',
7719: );
7720: my (%selected,$overridden,$incrscheck,$indomcheck,$indomvis,$incrsvis);
1.430 raeburn 7721: if (ref($settings{$role}) eq 'HASH') {
1.428 raeburn 7722: if ($settings{$role}{'access'} ne '') {
7723: $indomvis = ' style="display:none"';
7724: $incrsvis = ' style="display:block"';
1.430 raeburn 7725: $incrscheck = ' checked="checked"';
1.428 raeburn 7726: if ($settings{$role}{'access'} ne 'all') {
7727: $usecheck{$settings{$role}{'access'}} = $usecheck{'all'};
7728: delete($usecheck{'all'});
7729: if ($settings{$role}{'access'} eq 'status') {
7730: my $access = 'status';
7731: $displaydiv{$access} = 'inline';
7732: if (ref($settings{$role}{$access}) eq 'ARRAY') {
7733: $selected{$access} = $settings{$role}{$access};
7734: }
7735: } elsif ($settings{$role}{'access'} =~ /^(inc|exc)$/) {
7736: my $access = $1;
7737: $displaydiv{$access} = 'inline';
7738: if (ref($settings{$role}{$access}) eq 'ARRAY') {
7739: $selected{$access} = $settings{$role}{$access};
7740: }
7741: } elsif ($settings{$role}{'access'} eq 'none') {
7742: $displaydiv{'priv'} = 'none';
7743: }
7744: }
7745: } else {
7746: $indomcheck = ' checked="checked"';
7747: $indomvis = ' style="display:block"';
7748: $incrsvis = ' style="display:none"';
7749: }
7750: } else {
7751: $indomcheck = ' checked="checked"';
1.430 raeburn 7752: $indomvis = ' style="display:block"';
1.428 raeburn 7753: $incrsvis = ' style="display:none"';
7754: }
7755: $r->print('<div class="LC_left_float" id="'.$role.'_maindiv"'.$visibility{$role}.'>'.
7756: '<fieldset><legend>'.$lt{'rou'}.'</legend>'.
7757: '<p>'.$lt{'whi'}.' <span class="LC_nobreak">'.
7758: '<label><input type="radio" name="'.$role.'_incrs" value="1"'.$incrscheck.' onclick="toggleAccess('."'$role'".');"'.$disabled.'>'.
7759: &mt('Set here in [_1]',lc($crstype)).'</label>'.
7760: '<span>'.(' 'x2).
7761: '<label><input type="radio" name="'.$role.'_incrs" value="0"'.$indomcheck.' onclick="toggleAccess('."'$role'".');"'.$disabled.'>'.
7762: $lt{'udd'}.'</label><span></p>'.
7763: '<div id="'.$role.'_setindom"'.$indomvis.'>'.
7764: '<span class="LC_cusr_emph">'.$domusage{$role}.'</span></div>'.
7765: '<div id="'.$role.'_setincrs"'.$incrsvis.'>');
7766: foreach my $access (@accesstypes) {
7767: $r->print('<p><label><input type="radio" name="'.$role.'_access" value="'.$access.'" '.$usecheck{$access}.
7768: ' onclick="helpdeskAccess('."'$role'".');"'.$disabled.' />'.$lt{$access}.'</label>');
7769: if ($access eq 'status') {
7770: $r->print('<div id="'.$role.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
7771: &Apache::lonuserutils::adhoc_status_types($cdom,undef,$role,$selected{$access},
7772: $othertitle,$usertypes,$types,$disabled).
7773: '</div>');
7774: } elsif (($access eq 'inc') && (keys(%domhelpdesk) > 0)) {
7775: $r->print('<div id="'.$role.'_notinc" style="display:'.$displaydiv{$access}.'">'.
7776: &Apache::lonuserutils::adhoc_staff($access,undef,$role,$selected{$access},
7777: \%domhelpdesk,$disabled).
7778: '</div>');
7779: } elsif (($access eq 'exc') && (keys(%domhelpdesk) > 0)) {
7780: $r->print('<div id="'.$role.'_notexc" style="display:'.$displaydiv{$access}.'">'.
7781: &Apache::lonuserutils::adhoc_staff($access,undef,$role,$selected{$access},
7782: \%domhelpdesk,$disabled).
7783: '</div>');
7784: }
7785: $r->print('</p>');
7786: }
7787: $r->print('</div></fieldset>');
7788: my %full=();
7789: my %levels= (
7790: course => {},
7791: domain => {},
7792: system => {},
7793: );
7794: my %levelscurrent=(
7795: course => {},
7796: domain => {},
7797: system => {},
7798: );
7799: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
7800: $r->print('<fieldset id="'.$role.'_privs" style="display:'.$displaydiv{'priv'}.'">'.
7801: '<legend>'.$lt{'rpr'}.'</legend>'.
7802: &role_priv_table($role,$permission,$crstype,\%full,\%levels,\%levelscurrent,$overridden{$role}).
7803: '</fieldset></div><div style="padding:0;clear:both;margin:0;border:0"></div>');
7804: }
1.429 raeburn 7805: if ($permission->{'owner'}) {
7806: $r->print('<p><input type="submit" value="'.&mt('Save changes').'" /></p>');
7807: }
1.428 raeburn 7808: } else {
7809: $r->print(&mt('Helpdesk roles have not yet been created in this domain.'));
7810: }
7811: # Form Footer
7812: $r->print('<input type="hidden" name="action" value="helpdesk" />'
7813: .'</form>');
7814: return;
7815: }
7816:
7817: sub domain_adhoc_access {
7818: my ($roles,$domcurrent,$accesstypes,$usertypes,$othertitle) = @_;
7819: my %domusage;
7820: return unless ((ref($roles) eq 'HASH') && (ref($domcurrent) eq 'HASH') && (ref($accesstypes) eq 'ARRAY'));
7821: foreach my $role (keys(%{$roles})) {
7822: if (ref($domcurrent->{$role}) eq 'HASH') {
7823: my $access = $domcurrent->{$role}{'access'};
7824: if (($access eq '') || (!grep(/^\Q$access\E$/,@{$accesstypes}))) {
7825: $access = 'all';
1.432 raeburn 7826: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role',&Apache::lonnet::plaintext('dh'),
7827: &Apache::lonnet::plaintext('da'));
1.428 raeburn 7828: } elsif ($access eq 'status') {
7829: if (ref($domcurrent->{$role}{$access}) eq 'ARRAY') {
7830: my @shown;
7831: foreach my $type (@{$domcurrent->{$role}{$access}}) {
7832: unless ($type eq 'default') {
7833: if ($usertypes->{$type}) {
7834: push(@shown,$usertypes->{$type});
7835: }
7836: }
7837: }
7838: if (grep(/^default$/,@{$domcurrent->{$role}{$access}})) {
7839: push(@shown,$othertitle);
7840: }
7841: if (@shown) {
7842: my $shownstatus = join(' '.&mt('or').' ',@shown);
1.432 raeburn 7843: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role, and institutional status: [_3]',
7844: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'),$shownstatus);
1.428 raeburn 7845: } else {
7846: $domusage{$role} = &mt('No one in the domain');
7847: }
7848: }
7849: } elsif ($access eq 'inc') {
7850: my @dominc = ();
7851: if (ref($domcurrent->{$role}{'inc'}) eq 'ARRAY') {
7852: foreach my $user (@{$domcurrent->{$role}{'inc'}}) {
7853: my ($uname,$udom) = split(/:/,$user);
7854: push(@dominc,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),$uname,$udom));
7855: }
7856: my $showninc = join(', ',@dominc);
7857: if ($showninc ne '') {
1.432 raeburn 7858: $domusage{$role} = &mt('Include any user in domain with active [_1] or [_2] role, except: [_3]',
7859: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'),$showninc);
1.428 raeburn 7860: } else {
1.432 raeburn 7861: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role',
7862: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'));
1.428 raeburn 7863: }
7864: }
7865: } elsif ($access eq 'exc') {
7866: my @domexc = ();
7867: if (ref($domcurrent->{$role}{'exc'}) eq 'ARRAY') {
7868: foreach my $user (@{$domcurrent->{$role}{'exc'}}) {
7869: my ($uname,$udom) = split(/:/,$user);
7870: push(@domexc,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),$uname,$udom));
7871: }
7872: }
7873: my $shownexc = join(', ',@domexc);
7874: if ($shownexc ne '') {
1.432 raeburn 7875: $domusage{$role} = &mt('Only the following in the domain with active [_1] or [_2] role: [_3]',
7876: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'),$shownexc);
1.428 raeburn 7877: } else {
7878: $domusage{$role} = &mt('No one in the domain');
7879: }
7880: } elsif ($access eq 'none') {
7881: $domusage{$role} = &mt('No one in the domain');
1.434 raeburn 7882: } elsif ($access eq 'dh') {
1.433 raeburn 7883: $domusage{$role} = &mt('Any user in domain with active [_1] role',&Apache::lonnet::plaintext('dh'));
1.434 raeburn 7884: } elsif ($access eq 'da') {
1.433 raeburn 7885: $domusage{$role} = &mt('Any user in domain with active [_1] role',&Apache::lonnet::plaintext('da'));
1.428 raeburn 7886: } elsif ($access eq 'all') {
1.432 raeburn 7887: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role',
7888: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'));
1.428 raeburn 7889: }
7890: } else {
1.432 raeburn 7891: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role',
7892: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'));
1.428 raeburn 7893: }
7894: }
7895: return %domusage;
7896: }
7897:
7898: sub get_domain_customroles {
7899: my ($cdom,$confname) = @_;
7900: my %existing=&Apache::lonnet::dump('roles',$cdom,$confname,'rolesdef_');
7901: my %customroles;
7902: foreach my $key (keys(%existing)) {
7903: if ($key=~/^rolesdef\_(\w+)$/) {
7904: my $rolename = $1;
7905: my %privs;
7906: ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
7907: $customroles{$rolename} = \%privs;
7908: }
7909: }
7910: return %customroles;
7911: }
7912:
7913: sub role_priv_table {
7914: my ($role,$permission,$crstype,$full,$levels,$levelscurrent,$overridden) = @_;
7915: return unless ((ref($full) eq 'HASH') && (ref($levels) eq 'HASH') &&
7916: (ref($levelscurrent) eq 'HASH'));
7917: my %lt=&Apache::lonlocal::texthash (
7918: 'crl' => 'Course Level Privilege',
7919: 'def' => 'Domain Defaults',
7920: 'ove' => 'Override in Course',
7921: 'ine' => 'In effect',
7922: 'dis' => 'Disabled',
7923: 'ena' => 'Enabled',
7924: );
7925: if ($crstype eq 'Community') {
7926: $lt{'ove'} = 'Override in Community',
7927: }
7928: my @status = ('Disabled','Enabled');
7929: my (%on,%off);
7930: if (ref($overridden) eq 'HASH') {
7931: if (ref($overridden->{'on'}) eq 'ARRAY') {
7932: map { $on{$_} = 1; } (@{$overridden->{'on'}});
7933: }
7934: if (ref($overridden->{'off'}) eq 'ARRAY') {
7935: map { $off{$_} = 1; } (@{$overridden->{'off'}});
7936: }
7937: }
7938: my $output=&Apache::loncommon::start_data_table().
7939: &Apache::loncommon::start_data_table_header_row().
7940: '<th>'.$lt{'crl'}.'</th><th>'.$lt{'def'}.'</th><th>'.$lt{'ove'}.
7941: '</th><th>'.$lt{'ine'}.'</th>'.
7942: &Apache::loncommon::end_data_table_header_row();
7943: foreach my $priv (sort(keys(%{$full}))) {
7944: next unless ($levels->{'course'}{$priv});
7945: my $privtext = &Apache::lonnet::plaintext($priv,$crstype);
7946: my ($default,$ineffect);
7947: if ($levelscurrent->{'course'}{$priv}) {
7948: $default = '<img src="/adm/lonIcons/navmap.correct.gif" alt="'.$lt{'ena'}.'" />';
7949: $ineffect = $default;
7950: }
7951: my ($customstatus,$checked);
7952: $output .= &Apache::loncommon::start_data_table_row().
7953: '<td>'.$privtext.'</td>'.
7954: '<td>'.$default.'</td><td>';
7955: if (($levelscurrent->{'course'}{$priv}) && ($off{$priv})) {
7956: if ($permission->{'owner'}) {
7957: $checked = ' checked="checked"';
7958: }
7959: $customstatus = '<img src="/adm/lonIcons/navmap.wrong.gif" alt="'.$lt{'dis'}.'" />';
1.430 raeburn 7960: $ineffect = $customstatus;
1.428 raeburn 7961: } elsif ((!$levelscurrent->{'course'}{$priv}) && ($on{$priv})) {
7962: if ($permission->{'owner'}) {
1.430 raeburn 7963: $checked = ' checked="checked"';
1.428 raeburn 7964: }
7965: $customstatus = '<img src="/adm/lonIcons/navmap.correct.gif" alt="'.$lt{'ena'}.'" />';
1.430 raeburn 7966: $ineffect = $customstatus;
1.428 raeburn 7967: }
7968: if ($permission->{'owner'}) {
7969: $output .= '<input type="checkbox" name="'.$role.'_override" value="'.$priv.'"'.$checked.' />';
7970: } else {
7971: $output .= $customstatus;
7972: }
7973: $output .= '</td><td>'.$ineffect.'</td>'.
7974: &Apache::loncommon::end_data_table_row();
7975: }
7976: $output .= &Apache::loncommon::end_data_table();
7977: return $output;
7978: }
7979:
7980: sub get_adhocrole_settings {
1.430 raeburn 7981: my ($cid,$accesstypes,$types,$customroles,$settings,$overridden) = @_;
1.428 raeburn 7982: return unless ((ref($accesstypes) eq 'ARRAY') && (ref($customroles) eq 'HASH') &&
7983: (ref($settings) eq 'HASH') && (ref($overridden) eq 'HASH'));
7984: foreach my $role (split(/,/,$env{'course.'.$cid.'.internal.adhocaccess'})) {
7985: my ($curraccess,$rest) = split(/=/,$env{'course.'.$cid.'.internal.adhoc.'.$role});
7986: if (($curraccess ne '') && (grep(/^\Q$curraccess\E$/,@{$accesstypes}))) {
7987: $settings->{$role}{'access'} = $curraccess;
7988: if (($curraccess eq 'status') && (ref($types) eq 'ARRAY')) {
7989: my @status = split(/,/,$rest);
7990: my @currstatus;
7991: foreach my $type (@status) {
7992: if ($type eq 'default') {
7993: push(@currstatus,$type);
7994: } elsif (grep(/^\Q$type\E$/,@{$types})) {
7995: push(@currstatus,$type);
7996: }
7997: }
7998: if (@currstatus) {
7999: $settings->{$role}{$curraccess} = \@currstatus;
8000: } elsif (($curraccess eq 'exc') || ($curraccess eq 'inc')) {
8001: my @personnel = split(/,/,$rest);
8002: $settings->{$role}{$curraccess} = \@personnel;
8003: }
8004: }
8005: }
8006: }
8007: foreach my $role (keys(%{$customroles})) {
8008: if ($env{'course.'.$cid.'.internal.adhocpriv.'.$role}) {
8009: my %currentprivs;
8010: if (ref($customroles->{$role}) eq 'HASH') {
8011: if (exists($customroles->{$role}{'course'})) {
8012: my %full=();
8013: my %levels= (
8014: course => {},
8015: domain => {},
8016: system => {},
8017: );
8018: my %levelscurrent=(
8019: course => {},
8020: domain => {},
8021: system => {},
8022: );
8023: &Apache::lonuserutils::custom_role_privs($customroles->{$role},\%full,\%levels,\%levelscurrent);
8024: %currentprivs = %{$levelscurrent{'course'}};
8025: }
8026: }
8027: foreach my $item (split(/,/,$env{'course.'.$cid.'.internal.adhocpriv.'.$role})) {
8028: next if ($item eq '');
8029: my ($rule,$rest) = split(/=/,$item);
8030: next unless (($rule eq 'off') || ($rule eq 'on'));
8031: foreach my $priv (split(/:/,$rest)) {
8032: if ($priv ne '') {
8033: if ($rule eq 'off') {
8034: push(@{$overridden->{$role}{'off'}},$priv);
8035: if ($currentprivs{$priv}) {
8036: push(@{$settings->{$role}{'off'}},$priv);
8037: }
8038: } else {
8039: push(@{$overridden->{$role}{'on'}},$priv);
8040: unless ($currentprivs{$priv}) {
8041: push(@{$settings->{$role}{'on'}},$priv);
8042: }
8043: }
8044: }
8045: }
8046: }
8047: }
8048: }
8049: return;
8050: }
8051:
8052: sub update_helpdeskaccess {
8053: my ($r,$permission,$brcrum) = @_;
8054: my $helpitem = 'Course_Helpdesk_Access';
8055: push (@{$brcrum},
8056: {href => '/adm/createuser?action=helpdesk',
8057: text => 'Helpdesk Access',
8058: help => $helpitem},
8059: {href => '/adm/createuser?action=helpdesk',
8060: text => 'Result',
8061: help => $helpitem}
8062: );
8063: my $bread_crumbs_component = 'Helpdesk Staff Access';
8064: my $args = { bread_crumbs => $brcrum,
8065: bread_crumbs_component => $bread_crumbs_component};
8066:
8067: # print page header
8068: $r->print(&header('',$args));
8069: unless ((ref($permission) eq 'HASH') && ($permission->{'owner'})) {
8070: $r->print('<p class="LC_error">'.&mt('You do not have permission to change helpdesk access.').'</p>');
8071: return;
8072: }
1.434 raeburn 8073: my @accesstypes = ('all','dh','da','none','status','inc','exc');
1.428 raeburn 8074: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
8075: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
8076: my $confname = $cdom.'-domainconfig';
8077: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($cdom);
8078: my $crstype = &Apache::loncommon::course_type();
8079: my %customroles = &get_domain_customroles($cdom,$confname);
8080: my (%settings,%overridden);
8081: &get_adhocrole_settings($env{'request.course.id'},\@accesstypes,
8082: $types,\%customroles,\%settings,\%overridden);
1.432 raeburn 8083: my %domhelpdesk = &Apache::lonnet::get_active_domroles($cdom,['dh','da']);
1.428 raeburn 8084: my (%changed,%storehash,@todelete);
8085:
8086: if (keys(%customroles)) {
8087: my (%newsettings,@incrs);
8088: foreach my $role (keys(%customroles)) {
8089: $newsettings{$role} = {
8090: access => '',
8091: status => '',
8092: exc => '',
8093: inc => '',
8094: on => '',
8095: off => '',
8096: };
8097: my %current;
8098: if (ref($settings{$role}) eq 'HASH') {
8099: %current = %{$settings{$role}};
8100: }
8101: if (ref($overridden{$role}) eq 'HASH') {
8102: $current{'overridden'} = $overridden{$role};
8103: }
8104: if ($env{'form.'.$role.'_incrs'}) {
8105: my $access = $env{'form.'.$role.'_access'};
8106: if (grep(/^\Q$access\E$/,@accesstypes)) {
8107: push(@incrs,$role);
8108: unless ($current{'access'} eq $access) {
8109: $changed{$role}{'access'} = 1;
1.430 raeburn 8110: $storehash{'internal.adhoc.'.$role} = $access;
1.428 raeburn 8111: }
8112: if ($access eq 'status') {
8113: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$role.'_status');
8114: my @stored;
8115: my @shownstatus;
8116: if (ref($types) eq 'ARRAY') {
8117: foreach my $type (sort(@statuses)) {
8118: if ($type eq 'default') {
8119: push(@stored,$type);
8120: } elsif (grep(/^\Q$type\E$/,@{$types})) {
8121: push(@stored,$type);
8122: push(@shownstatus,$usertypes->{$type});
8123: }
8124: }
8125: if (grep(/^default$/,@statuses)) {
8126: push(@shownstatus,$othertitle);
8127: }
8128: $storehash{'internal.adhoc.'.$role} .= '='.join(',',@stored);
8129: }
8130: $newsettings{$role}{'status'} = join(' '.&mt('or').' ',@shownstatus);
8131: if (ref($current{'status'}) eq 'ARRAY') {
8132: my @diffs = &Apache::loncommon::compare_arrays(\@stored,$current{'status'});
8133: if (@diffs) {
8134: $changed{$role}{'status'} = 1;
8135: }
8136: } elsif (@stored) {
8137: $changed{$role}{'status'} = 1;
8138: }
8139: } elsif (($access eq 'inc') || ($access eq 'exc')) {
8140: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$role.'_staff_'.$access);
8141: my @newspecstaff;
8142: my @stored;
8143: my @currstaff;
8144: foreach my $person (sort(@personnel)) {
8145: if ($domhelpdesk{$person}) {
1.430 raeburn 8146: push(@stored,$person);
1.428 raeburn 8147: }
8148: }
8149: if (ref($current{$access}) eq 'ARRAY') {
8150: my @diffs = &Apache::loncommon::compare_arrays(\@stored,$current{$access});
8151: if (@diffs) {
8152: $changed{$role}{$access} = 1;
8153: }
8154: } elsif (@stored) {
8155: $changed{$role}{$access} = 1;
8156: }
8157: $storehash{'internal.adhoc.'.$role} .= '='.join(',',@stored);
8158: foreach my $person (@stored) {
8159: my ($uname,$udom) = split(/:/,$person);
8160: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
8161: }
8162: $newsettings{$role}{$access} = join(', ',sort(@newspecstaff));
8163: }
8164: $newsettings{$role}{'access'} = $access;
8165: }
8166: } else {
8167: if (($current{'access'} ne '') && (grep(/^\Q$current{'access'}\E$/,@accesstypes))) {
8168: $changed{$role}{'access'} = 1;
8169: $newsettings{$role} = {};
8170: push(@todelete,'internal.adhoc.'.$role);
8171: }
8172: }
8173: if (($env{'form.'.$role.'_incrs'}) && ($env{'form.'.$role.'_access'} eq 'none')) {
8174: if (ref($current{'overridden'}) eq 'HASH') {
8175: push(@todelete,'internal.adhocpriv.'.$role);
8176: }
8177: } else {
8178: my %full=();
8179: my %levels= (
8180: course => {},
8181: domain => {},
8182: system => {},
8183: );
8184: my %levelscurrent=(
8185: course => {},
8186: domain => {},
8187: system => {},
8188: );
8189: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
8190: my (@updatedon,@updatedoff,@override);
8191: @override = &Apache::loncommon::get_env_multiple('form.'.$role.'_override');
1.430 raeburn 8192: if (@override) {
1.428 raeburn 8193: foreach my $priv (sort(keys(%full))) {
8194: next unless ($levels{'course'}{$priv});
8195: if (grep(/^\Q$priv\E$/,@override)) {
8196: if ($levelscurrent{'course'}{$priv}) {
8197: push(@updatedoff,$priv);
8198: } else {
8199: push(@updatedon,$priv);
8200: }
8201: }
8202: }
8203: }
8204: if (@updatedon) {
1.430 raeburn 8205: $newsettings{$role}{'on'} = join('</li><li>', map { &Apache::lonnet::plaintext($_,$crstype) } (@updatedon));
1.428 raeburn 8206: }
8207: if (@updatedoff) {
8208: $newsettings{$role}{'off'} = join('</li><li>', map { &Apache::lonnet::plaintext($_,$crstype) } (@updatedoff));
8209: }
8210: if (ref($current{'overridden'}) eq 'HASH') {
8211: if (ref($current{'overridden'}{'on'}) eq 'ARRAY') {
8212: if (@updatedon) {
8213: my @diffs = &Apache::loncommon::compare_arrays(\@updatedon,$current{'overridden'}{'on'});
8214: if (@diffs) {
8215: $changed{$role}{'on'} = 1;
8216: }
8217: } else {
8218: $changed{$role}{'on'} = 1;
8219: }
8220: } elsif (@updatedon) {
8221: $changed{$role}{'on'} = 1;
8222: }
8223: if (ref($current{'overridden'}{'off'}) eq 'ARRAY') {
8224: if (@updatedoff) {
8225: my @diffs = &Apache::loncommon::compare_arrays(\@updatedoff,$current{'overridden'}{'off'});
8226: if (@diffs) {
8227: $changed{$role}{'off'} = 1;
8228: }
8229: } else {
8230: $changed{$role}{'off'} = 1;
8231: }
8232: } elsif (@updatedoff) {
8233: $changed{$role}{'off'} = 1;
8234: }
8235: } else {
8236: if (@updatedon) {
8237: $changed{$role}{'on'} = 1;
8238: }
8239: if (@updatedoff) {
8240: $changed{$role}{'off'} = 1;
8241: }
8242: }
8243: if (ref($changed{$role}) eq 'HASH') {
8244: if (($changed{$role}{'on'} || $changed{$role}{'off'})) {
8245: my $newpriv;
8246: if (@updatedon) {
8247: $newpriv = 'on='.join(':',@updatedon);
8248: }
8249: if (@updatedoff) {
8250: $newpriv .= ($newpriv ? ',' : '' ).'off='.join(':',@updatedoff);
8251: }
8252: if ($newpriv eq '') {
8253: push(@todelete,'internal.adhocpriv.'.$role);
8254: } else {
8255: $storehash{'internal.adhocpriv.'.$role} = $newpriv;
8256: }
8257: }
8258: }
8259: }
8260: }
8261: if (@incrs) {
8262: $storehash{'internal.adhocaccess'} = join(',',@incrs);
8263: } elsif (@todelete) {
8264: push(@todelete,'internal.adhocaccess');
8265: }
8266: if (keys(%changed)) {
8267: my ($putres,$delres);
8268: if (keys(%storehash)) {
8269: $putres = &Apache::lonnet::put('environment',\%storehash,$cdom,$cnum);
8270: my %newenvhash;
8271: foreach my $key (keys(%storehash)) {
8272: $newenvhash{'course.'.$env{'request.course.id'}.'.'.$key} = $storehash{$key};
8273: }
8274: &Apache::lonnet::appenv(\%newenvhash);
8275: }
8276: if (@todelete) {
8277: $delres = &Apache::lonnet::del('environment',\@todelete,$cdom,$cnum);
8278: foreach my $key (@todelete) {
8279: &Apache::lonnet::delenv('course.'.$env{'request.course.id'}.'.'.$key);
8280: }
8281: }
8282: if (($putres eq 'ok') || ($delres eq 'ok')) {
8283: my %domconfig = &Apache::lonnet::get_dom('configuration',['helpsettings'],$cdom);
8284: my (%domcurrent,%ordered,%description,%domusage);
8285: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
8286: if (ref($domconfig{'helpsettings'}{'adhoc'}) eq 'HASH') {
8287: %domcurrent = %{$domconfig{'helpsettings'}{'adhoc'}};
8288: }
8289: }
8290: my $count = 0;
8291: foreach my $role (sort(keys(%customroles))) {
8292: my ($order,$desc);
8293: if (ref($domcurrent{$role}) eq 'HASH') {
8294: $order = $domcurrent{$role}{'order'};
8295: $desc = $domcurrent{$role}{'desc'};
8296: }
8297: if ($order eq '') {
8298: $order = $count;
8299: }
8300: $ordered{$order} = $role;
8301: if ($desc ne '') {
8302: $description{$role} = $desc;
8303: } else {
8304: $description{$role}= $role;
8305: }
8306: $count++;
8307: }
8308: my @roles_by_num = ();
8309: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
8310: push(@roles_by_num,$ordered{$item});
8311: }
8312: %domusage = &domain_adhoc_access(\%changed,\%domcurrent,\@accesstypes,$usertypes,$othertitle);
1.430 raeburn 8313: $r->print(&mt('Helpdesk access settings have been changed as follows').'<br />');
1.428 raeburn 8314: $r->print('<ul>');
8315: foreach my $role (@roles_by_num) {
8316: next unless (ref($changed{$role}) eq 'HASH');
8317: $r->print('<li>'.&mt('Ad hoc role').': <b>'.$description{$role}.'</b>'.
8318: '<ul>');
1.430 raeburn 8319: if ($changed{$role}{'access'} || $changed{$role}{'status'} || $changed{$role}{'inc'} || $changed{$role}{'exc'}) {
1.428 raeburn 8320: $r->print('<li>');
8321: if ($env{'form.'.$role.'_incrs'}) {
8322: if ($newsettings{$role}{'access'} eq 'all') {
8323: $r->print(&mt('All helpdesk staff can access '.lc($crstype).' with this role.'));
1.434 raeburn 8324: } elsif ($newsettings{$role}{'access'} eq 'dh') {
1.433 raeburn 8325: $r->print(&mt('Helpdesk staff can use this role if they have an active [_1] role',
8326: &Apache::lonnet::plaintext('dh')));
1.434 raeburn 8327: } elsif ($newsettings{$role}{'access'} eq 'da') {
1.433 raeburn 8328: $r->print(&mt('Helpdesk staff can use this role if they have an active [_1] role',
8329: &Apache::lonnet::plaintext('da')));
1.428 raeburn 8330: } elsif ($newsettings{$role}{'access'} eq 'none') {
8331: $r->print(&mt('No helpdesk staff can access '.lc($crstype).' with this role.'));
8332: } elsif ($newsettings{$role}{'access'} eq 'status') {
8333: if ($newsettings{$role}{'status'}) {
8334: my ($access,$rest) = split(/=/,$storehash{'internal.adhoc.'.$role});
1.430 raeburn 8335: if (split(/,/,$rest) > 1) {
1.428 raeburn 8336: $r->print(&mt('Helpdesk staff can use this role if their institutional type is one of: [_1].',
8337: $newsettings{$role}{'status'}));
8338: } else {
8339: $r->print(&mt('Helpdesk staff can use this role if their institutional type is: [_1].',
8340: $newsettings{$role}{'status'}));
8341: }
8342: } else {
8343: $r->print(&mt('No helpdesk staff can access '.lc($crstype).' with this role.'));
8344: }
8345: } elsif ($newsettings{$role}{'access'} eq 'exc') {
8346: if ($newsettings{$role}{'exc'}) {
8347: $r->print(&mt('Helpdesk staff who can use this role are as follows:').' '.$newsettings{$role}{'exc'}.'.');
8348: } else {
8349: $r->print(&mt('No helpdesk staff can access '.lc($crstype).' with this role.'));
8350: }
8351: } elsif ($newsettings{$role}{'access'} eq 'inc') {
8352: if ($newsettings{$role}{'inc'}) {
8353: $r->print(&mt('All helpdesk staff may use this role except the following:').' '.$newsettings{$role}{'inc'}.'.');
8354: } else {
8355: $r->print(&mt('All helpdesk staff may use this role.'));
8356: }
8357: }
8358: } else {
8359: $r->print(&mt('Default access set in the domain now applies.').'<br />'.
8360: '<span class="LC_cusr_emph">'.$domusage{$role}.'</span>');
8361: }
8362: $r->print('</li>');
8363: }
8364: unless ($newsettings{$role}{'access'} eq 'none') {
8365: if ($changed{$role}{'off'}) {
8366: if ($newsettings{$role}{'off'}) {
8367: $r->print('<li>'.&mt('Privileges which are available by default for this ad hoc role, but are disabled for this specific '.lc($crstype).':').
8368: '<ul><li>'.$newsettings{$role}{'off'}.'</li></ul></li>');
8369: } else {
1.430 raeburn 8370: $r->print('<li>'.&mt('All privileges available by default for this ad hoc role are enabled.').'</li>');
1.428 raeburn 8371: }
8372: }
1.430 raeburn 8373: if ($changed{$role}{'on'}) {
1.428 raeburn 8374: if ($newsettings{$role}{'on'}) {
8375: $r->print('<li>'.&mt('Privileges which are not available by default for this ad hoc role, but are enabled for this specific '.lc($crstype).':').
8376: '<ul><li>'.$newsettings{$role}{'on'}.'</li></ul></li>');
8377: } else {
1.430 raeburn 8378: $r->print('<li>'.&mt('None of the privileges unavailable by default for this ad hoc role are enabled.').'</li>');
1.428 raeburn 8379: }
8380: }
8381: }
8382: $r->print('</ul></li>');
8383: }
8384: $r->print('</ul>');
8385: }
8386: } else {
1.430 raeburn 8387: $r->print(&mt('No changes made to helpdesk access settings.'));
1.428 raeburn 8388: }
8389: }
8390: return;
8391: }
8392:
1.27 matthew 8393: #-------------------------------------------------- functions for &phase_two
1.160 raeburn 8394: sub user_search_result {
1.221 raeburn 8395: my ($context,$srch) = @_;
1.160 raeburn 8396: my %allhomes;
8397: my %inst_matches;
8398: my %srch_results;
1.181 raeburn 8399: my ($response,$currstate,$forcenewuser,$dirsrchres);
1.183 raeburn 8400: $srch->{'srchterm'} =~ s/\s+/ /g;
1.176 raeburn 8401: if ($srch->{'srchby'} !~ /^(uname|lastname|lastfirst)$/) {
1.160 raeburn 8402: $response = &mt('Invalid search.');
8403: }
8404: if ($srch->{'srchin'} !~ /^(crs|dom|alc|instd)$/) {
8405: $response = &mt('Invalid search.');
8406: }
1.177 raeburn 8407: if ($srch->{'srchtype'} !~ /^(exact|contains|begins)$/) {
1.160 raeburn 8408: $response = &mt('Invalid search.');
8409: }
8410: if ($srch->{'srchterm'} eq '') {
8411: $response = &mt('You must enter a search term.');
8412: }
1.183 raeburn 8413: if ($srch->{'srchterm'} =~ /^\s+$/) {
8414: $response = &mt('Your search term must contain more than just spaces.');
8415: }
1.160 raeburn 8416: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'instd')) {
8417: if (($srch->{'srchdomain'} eq '') ||
1.163 albertel 8418: ! (&Apache::lonnet::domain($srch->{'srchdomain'}))) {
1.160 raeburn 8419: $response = &mt('You must specify a valid domain when searching in a domain or institutional directory.')
8420: }
8421: }
8422: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs') ||
8423: ($srch->{'srchin'} eq 'alc')) {
1.176 raeburn 8424: if ($srch->{'srchby'} eq 'uname') {
1.243 raeburn 8425: my $unamecheck = $srch->{'srchterm'};
8426: if ($srch->{'srchtype'} eq 'contains') {
8427: if ($unamecheck !~ /^\w/) {
8428: $unamecheck = 'a'.$unamecheck;
8429: }
8430: }
8431: if ($unamecheck !~ /^$match_username$/) {
1.176 raeburn 8432: $response = &mt('You must specify a valid username. Only the following are allowed: letters numbers - . @');
8433: }
1.160 raeburn 8434: }
8435: }
1.180 raeburn 8436: if ($response ne '') {
1.413 raeburn 8437: $response = '<span class="LC_warning">'.$response.'</span><br />';
1.180 raeburn 8438: }
1.160 raeburn 8439: if ($srch->{'srchin'} eq 'instd') {
1.412 raeburn 8440: my $instd_chk = &instdirectorysrch_check($srch);
1.160 raeburn 8441: if ($instd_chk ne 'ok') {
1.412 raeburn 8442: my $domd_chk = &domdirectorysrch_check($srch);
1.413 raeburn 8443: $response .= '<span class="LC_warning">'.$instd_chk.'</span><br />';
1.412 raeburn 8444: if ($domd_chk eq 'ok') {
1.435 raeburn 8445: $response .= &mt('You may want to search in the LON-CAPA domain instead of in the institutional directory.');
1.412 raeburn 8446: }
1.415 raeburn 8447: $response .= '<br />';
1.412 raeburn 8448: }
8449: } else {
1.417 raeburn 8450: unless (($context eq 'requestcrs') && ($srch->{'srchtype'} eq 'exact')) {
1.412 raeburn 8451: my $domd_chk = &domdirectorysrch_check($srch);
1.438 raeburn 8452: if (($domd_chk ne 'ok') && ($env{'form.action'} ne 'accesslogs')) {
1.412 raeburn 8453: my $instd_chk = &instdirectorysrch_check($srch);
1.413 raeburn 8454: $response .= '<span class="LC_warning">'.$domd_chk.'</span><br />';
1.412 raeburn 8455: if ($instd_chk eq 'ok') {
1.435 raeburn 8456: $response .= &mt('You may want to search in the institutional directory instead of in the LON-CAPA domain.');
1.412 raeburn 8457: }
1.415 raeburn 8458: $response .= '<br />';
1.412 raeburn 8459: }
1.160 raeburn 8460: }
8461: }
8462: if ($response ne '') {
1.180 raeburn 8463: return ($currstate,$response);
1.160 raeburn 8464: }
8465: if ($srch->{'srchby'} eq 'uname') {
8466: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs')) {
8467: if ($env{'form.forcenew'}) {
8468: if ($srch->{'srchdomain'} ne $env{'request.role.domain'}) {
8469: my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
8470: if ($uhome eq 'no_host') {
8471: my $domdesc = &Apache::lonnet::domain($env{'request.role.domain'},'description');
1.180 raeburn 8472: my $showdom = &display_domain_info($env{'request.role.domain'});
8473: $response = &mt('New users can only be created in the domain to which your current role belongs - [_1].',$showdom);
1.160 raeburn 8474: } else {
1.179 raeburn 8475: $currstate = 'modify';
1.160 raeburn 8476: }
8477: } else {
1.179 raeburn 8478: $currstate = 'modify';
1.160 raeburn 8479: }
8480: } else {
8481: if ($srch->{'srchin'} eq 'dom') {
1.162 raeburn 8482: if ($srch->{'srchtype'} eq 'exact') {
8483: my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
8484: if ($uhome eq 'no_host') {
1.179 raeburn 8485: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8486: &build_search_response($context,$srch,%srch_results);
1.162 raeburn 8487: } else {
1.179 raeburn 8488: $currstate = 'modify';
1.416 raeburn 8489: if ($env{'form.action'} eq 'accesslogs') {
8490: $currstate = 'activity';
8491: }
1.310 raeburn 8492: my $uname = $srch->{'srchterm'};
8493: my $udom = $srch->{'srchdomain'};
8494: $srch_results{$uname.':'.$udom} =
8495: { &Apache::lonnet::get('environment',
8496: ['firstname',
8497: 'lastname',
8498: 'permanentemail'],
8499: $udom,$uname)
8500: };
1.162 raeburn 8501: }
8502: } else {
8503: %srch_results = &Apache::lonnet::usersearch($srch);
1.179 raeburn 8504: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8505: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 8506: }
8507: } else {
1.167 albertel 8508: my $courseusers = &get_courseusers();
1.162 raeburn 8509: if ($srch->{'srchtype'} eq 'exact') {
1.167 albertel 8510: if (exists($courseusers->{$srch->{'srchterm'}.':'.$srch->{'srchdomain'}})) {
1.179 raeburn 8511: $currstate = 'modify';
1.162 raeburn 8512: } else {
1.179 raeburn 8513: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8514: &build_search_response($context,$srch,%srch_results);
1.162 raeburn 8515: }
1.160 raeburn 8516: } else {
1.167 albertel 8517: foreach my $user (keys(%$courseusers)) {
1.162 raeburn 8518: my ($cuname,$cudomain) = split(/:/,$user);
8519: if ($cudomain eq $srch->{'srchdomain'}) {
1.177 raeburn 8520: my $matched = 0;
8521: if ($srch->{'srchtype'} eq 'begins') {
8522: if ($cuname =~ /^\Q$srch->{'srchterm'}\E/i) {
8523: $matched = 1;
8524: }
8525: } else {
8526: if ($cuname =~ /\Q$srch->{'srchterm'}\E/i) {
8527: $matched = 1;
8528: }
8529: }
8530: if ($matched) {
1.167 albertel 8531: $srch_results{$user} =
8532: {&Apache::lonnet::get('environment',
8533: ['firstname',
8534: 'lastname',
1.194 albertel 8535: 'permanentemail'],
8536: $cudomain,$cuname)};
1.162 raeburn 8537: }
8538: }
8539: }
1.179 raeburn 8540: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8541: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 8542: }
8543: }
8544: }
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 {
8553: my $showdom = &display_domain_info($srch->{'srchdomain'});
8554: $response = '<span class="LC_warning">'.
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: } else {
8562: if ($srch->{'srchin'} eq 'dom') {
8563: %srch_results = &Apache::lonnet::usersearch($srch);
1.179 raeburn 8564: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8565: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 8566: } elsif ($srch->{'srchin'} eq 'crs') {
1.167 albertel 8567: my $courseusers = &get_courseusers();
8568: foreach my $user (keys(%$courseusers)) {
1.160 raeburn 8569: my ($uname,$udom) = split(/:/,$user);
8570: my %names = &Apache::loncommon::getnames($uname,$udom);
8571: my %emails = &Apache::loncommon::getemails($uname,$udom);
8572: if ($srch->{'srchby'} eq 'lastname') {
8573: if ((($srch->{'srchtype'} eq 'exact') &&
8574: ($names{'lastname'} eq $srch->{'srchterm'})) ||
1.177 raeburn 8575: (($srch->{'srchtype'} eq 'begins') &&
8576: ($names{'lastname'} =~ /^\Q$srch->{'srchterm'}\E/i)) ||
1.160 raeburn 8577: (($srch->{'srchtype'} eq 'contains') &&
8578: ($names{'lastname'} =~ /\Q$srch->{'srchterm'}\E/i))) {
8579: $srch_results{$user} = {firstname => $names{'firstname'},
8580: lastname => $names{'lastname'},
8581: permanentemail => $emails{'permanentemail'},
8582: };
8583: }
8584: } elsif ($srch->{'srchby'} eq 'lastfirst') {
8585: my ($srchlast,$srchfirst) = split(/,/,$srch->{'srchterm'});
1.177 raeburn 8586: $srchlast =~ s/\s+$//;
8587: $srchfirst =~ s/^\s+//;
1.160 raeburn 8588: if ($srch->{'srchtype'} eq 'exact') {
8589: if (($names{'lastname'} eq $srchlast) &&
8590: ($names{'firstname'} eq $srchfirst)) {
8591: $srch_results{$user} = {firstname => $names{'firstname'},
8592: lastname => $names{'lastname'},
8593: permanentemail => $emails{'permanentemail'},
8594:
8595: };
8596: }
1.177 raeburn 8597: } elsif ($srch->{'srchtype'} eq 'begins') {
8598: if (($names{'lastname'} =~ /^\Q$srchlast\E/i) &&
8599: ($names{'firstname'} =~ /^\Q$srchfirst\E/i)) {
8600: $srch_results{$user} = {firstname => $names{'firstname'},
8601: lastname => $names{'lastname'},
8602: permanentemail => $emails{'permanentemail'},
8603: };
8604: }
8605: } else {
1.160 raeburn 8606: if (($names{'lastname'} =~ /\Q$srchlast\E/i) &&
8607: ($names{'firstname'} =~ /\Q$srchfirst\E/i)) {
8608: $srch_results{$user} = {firstname => $names{'firstname'},
8609: lastname => $names{'lastname'},
8610: permanentemail => $emails{'permanentemail'},
8611: };
8612: }
8613: }
8614: }
8615: }
1.179 raeburn 8616: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8617: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 8618: } elsif ($srch->{'srchin'} eq 'alc') {
1.179 raeburn 8619: $currstate = 'query';
1.160 raeburn 8620: } elsif ($srch->{'srchin'} eq 'instd') {
1.181 raeburn 8621: ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
8622: if ($dirsrchres eq 'ok') {
8623: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8624: &build_search_response($context,$srch,%srch_results);
1.181 raeburn 8625: } else {
1.412 raeburn 8626: my $showdom = &display_domain_info($srch->{'srchdomain'});
8627: $response = '<span class="LC_warning">'.
1.181 raeburn 8628: &mt('Institutional directory search is not available in domain: [_1]',$showdom).
8629: '</span><br />'.
1.435 raeburn 8630: &mt('You may want to search in the LON-CAPA domain instead of in the institutional directory.').
1.415 raeburn 8631: '<br />';
1.181 raeburn 8632: }
1.160 raeburn 8633: }
8634: }
1.179 raeburn 8635: return ($currstate,$response,$forcenewuser,\%srch_results);
1.160 raeburn 8636: }
8637:
1.412 raeburn 8638: sub domdirectorysrch_check {
8639: my ($srch) = @_;
8640: my $response;
8641: my %dom_inst_srch = &Apache::lonnet::get_dom('configuration',
8642: ['directorysrch'],$srch->{'srchdomain'});
8643: my $showdom = &display_domain_info($srch->{'srchdomain'});
8644: if (ref($dom_inst_srch{'directorysrch'}) eq 'HASH') {
8645: if ($dom_inst_srch{'directorysrch'}{'lcavailable'} eq '0') {
8646: return &mt('LON-CAPA directory search is not available in domain: [_1]',$showdom);
8647: }
8648: if ($dom_inst_srch{'directorysrch'}{'lclocalonly'}) {
8649: if ($env{'request.role.domain'} ne $srch->{'srchdomain'}) {
8650: return &mt('LON-CAPA directory search in domain: [_1] is only allowed for users with a current role in the domain.',$showdom);
8651: }
8652: }
8653: }
8654: return 'ok';
8655: }
8656:
8657: sub instdirectorysrch_check {
1.160 raeburn 8658: my ($srch) = @_;
8659: my $can_search = 0;
8660: my $response;
8661: my %dom_inst_srch = &Apache::lonnet::get_dom('configuration',
8662: ['directorysrch'],$srch->{'srchdomain'});
1.180 raeburn 8663: my $showdom = &display_domain_info($srch->{'srchdomain'});
1.160 raeburn 8664: if (ref($dom_inst_srch{'directorysrch'}) eq 'HASH') {
8665: if (!$dom_inst_srch{'directorysrch'}{'available'}) {
1.180 raeburn 8666: return &mt('Institutional directory search is not available in domain: [_1]',$showdom);
1.160 raeburn 8667: }
8668: if ($dom_inst_srch{'directorysrch'}{'localonly'}) {
8669: if ($env{'request.role.domain'} ne $srch->{'srchdomain'}) {
1.180 raeburn 8670: return &mt('Institutional directory search in domain: [_1] is only allowed for users with a current role in the domain.',$showdom);
1.160 raeburn 8671: }
8672: my @usertypes = split(/:/,$env{'environment.inststatus'});
8673: if (!@usertypes) {
8674: push(@usertypes,'default');
8675: }
8676: if (ref($dom_inst_srch{'directorysrch'}{'cansearch'}) eq 'ARRAY') {
8677: foreach my $type (@usertypes) {
8678: if (grep(/^\Q$type\E$/,@{$dom_inst_srch{'directorysrch'}{'cansearch'}})) {
8679: $can_search = 1;
8680: last;
8681: }
8682: }
8683: }
8684: if (!$can_search) {
8685: my ($insttypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($srch->{'srchdomain'});
8686: my @longtypes;
8687: foreach my $item (@usertypes) {
1.229 raeburn 8688: if (defined($insttypes->{$item})) {
8689: push (@longtypes,$insttypes->{$item});
8690: } elsif ($item eq 'default') {
8691: push (@longtypes,&mt('other'));
8692: }
1.160 raeburn 8693: }
8694: my $insttype_str = join(', ',@longtypes);
1.180 raeburn 8695: return &mt('Institutional directory search in domain: [_1] is not available to your user type: ',$showdom).$insttype_str;
1.229 raeburn 8696: }
1.160 raeburn 8697: } else {
8698: $can_search = 1;
8699: }
8700: } else {
1.180 raeburn 8701: return &mt('Institutional directory search has not been configured for domain: [_1]',$showdom);
1.160 raeburn 8702: }
8703: my %longtext = &Apache::lonlocal::texthash (
1.167 albertel 8704: uname => 'username',
1.160 raeburn 8705: lastfirst => 'last name, first name',
1.167 albertel 8706: lastname => 'last name',
1.172 raeburn 8707: contains => 'contains',
1.178 raeburn 8708: exact => 'as exact match to',
8709: begins => 'begins with',
1.160 raeburn 8710: );
8711: if ($can_search) {
8712: if (ref($dom_inst_srch{'directorysrch'}{'searchby'}) eq 'ARRAY') {
8713: if (!grep(/^\Q$srch->{'srchby'}\E$/,@{$dom_inst_srch{'directorysrch'}{'searchby'}})) {
1.180 raeburn 8714: return &mt('Institutional directory search in domain: [_1] is not available for searching by "[_2]"',$showdom,$longtext{$srch->{'srchby'}});
1.160 raeburn 8715: }
8716: } else {
1.180 raeburn 8717: return &mt('Institutional directory search in domain: [_1] is not available.', $showdom);
1.160 raeburn 8718: }
8719: }
8720: if ($can_search) {
1.178 raeburn 8721: if (ref($dom_inst_srch{'directorysrch'}{'searchtypes'}) eq 'ARRAY') {
8722: if (grep(/^\Q$srch->{'srchtype'}\E/,@{$dom_inst_srch{'directorysrch'}{'searchtypes'}})) {
8723: return 'ok';
8724: } else {
1.180 raeburn 8725: return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
1.178 raeburn 8726: }
8727: } else {
8728: if ((($dom_inst_srch{'directorysrch'}{'searchtypes'} eq 'specify') &&
8729: ($srch->{'srchtype'} eq 'exact' || $srch->{'srchtype'} eq 'contains')) ||
8730: ($dom_inst_srch{'directorysrch'}{'searchtypes'} eq $srch->{'srchtype'})) {
8731: return 'ok';
8732: } else {
1.180 raeburn 8733: return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
1.178 raeburn 8734: }
1.160 raeburn 8735: }
8736: }
8737: }
8738:
8739: sub get_courseusers {
8740: my %advhash;
1.167 albertel 8741: my $classlist = &Apache::loncoursedata::get_classlist();
1.160 raeburn 8742: my %coursepersonnel=&Apache::lonnet::get_course_adv_roles();
8743: foreach my $role (sort(keys(%coursepersonnel))) {
8744: foreach my $user (split(/\,/,$coursepersonnel{$role})) {
1.167 albertel 8745: if (!exists($classlist->{$user})) {
8746: $classlist->{$user} = [];
8747: }
1.160 raeburn 8748: }
8749: }
1.167 albertel 8750: return $classlist;
1.160 raeburn 8751: }
8752:
8753: sub build_search_response {
1.221 raeburn 8754: my ($context,$srch,%srch_results) = @_;
1.179 raeburn 8755: my ($currstate,$response,$forcenewuser);
1.160 raeburn 8756: my %names = (
1.330 bisitz 8757: 'uname' => 'username',
8758: 'lastname' => 'last name',
1.160 raeburn 8759: 'lastfirst' => 'last name, first name',
1.330 bisitz 8760: 'crs' => 'this course',
8761: 'dom' => 'LON-CAPA domain',
8762: 'instd' => 'the institutional directory for domain',
1.160 raeburn 8763: );
8764:
8765: my %single = (
1.180 raeburn 8766: begins => 'A match',
1.160 raeburn 8767: contains => 'A match',
1.180 raeburn 8768: exact => 'An exact match',
1.160 raeburn 8769: );
8770: my %nomatch = (
1.180 raeburn 8771: begins => 'No match',
1.160 raeburn 8772: contains => 'No match',
1.180 raeburn 8773: exact => 'No exact match',
1.160 raeburn 8774: );
8775: if (keys(%srch_results) > 1) {
1.179 raeburn 8776: $currstate = 'select';
1.160 raeburn 8777: } else {
8778: if (keys(%srch_results) == 1) {
1.416 raeburn 8779: if ($env{'form.action'} eq 'accesslogs') {
8780: $currstate = 'activity';
8781: } else {
8782: $currstate = 'modify';
8783: }
1.180 raeburn 8784: $response = &mt("$single{$srch->{'srchtype'}} was found for the $names{$srch->{'srchby'}} ([_1]) in $names{$srch->{'srchin'}}.",$srch->{'srchterm'});
8785: if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
1.330 bisitz 8786: $response .= ': '.&display_domain_info($srch->{'srchdomain'});
1.180 raeburn 8787: }
1.330 bisitz 8788: } else { # Search has nothing found. Prepare message to user.
8789: $response = '<span class="LC_warning">';
1.180 raeburn 8790: if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
1.330 bisitz 8791: $response .= &mt("$nomatch{$srch->{'srchtype'}} found for the $names{$srch->{'srchby'}} [_1] in $names{$srch->{'srchin'}}: [_2]",
8792: '<b>'.$srch->{'srchterm'}.'</b>',
8793: &display_domain_info($srch->{'srchdomain'}));
8794: } else {
8795: $response .= &mt("$nomatch{$srch->{'srchtype'}} found for the $names{$srch->{'srchby'}} [_1] in $names{$srch->{'srchin'}}.",
8796: '<b>'.$srch->{'srchterm'}.'</b>');
1.180 raeburn 8797: }
8798: $response .= '</span>';
1.330 bisitz 8799:
1.160 raeburn 8800: if ($srch->{'srchin'} ne 'alc') {
8801: $forcenewuser = 1;
8802: my $cansrchinst = 0;
1.438 raeburn 8803: if (($srch->{'srchdomain'}) && ($env{'form.action'} ne 'accesslogs')) {
1.160 raeburn 8804: my %domconfig = &Apache::lonnet::get_dom('configuration',['directorysrch'],$srch->{'srchdomain'});
8805: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
8806: if ($domconfig{'directorysrch'}{'available'}) {
8807: $cansrchinst = 1;
8808: }
8809: }
8810: }
1.180 raeburn 8811: if ((($srch->{'srchby'} eq 'lastfirst') ||
8812: ($srch->{'srchby'} eq 'lastname')) &&
8813: ($srch->{'srchin'} eq 'dom')) {
8814: if ($cansrchinst) {
8815: $response .= '<br />'.&mt('You may want to broaden your search to a search of the institutional directory for the domain.');
1.160 raeburn 8816: }
8817: }
1.180 raeburn 8818: if ($srch->{'srchin'} eq 'crs') {
8819: $response .= '<br />'.&mt('You may want to broaden your search to the selected LON-CAPA domain.');
8820: }
8821: }
1.305 raeburn 8822: my $createdom = $env{'request.role.domain'};
8823: if ($context eq 'requestcrs') {
8824: if ($env{'form.coursedom'} ne '') {
8825: $createdom = $env{'form.coursedom'};
8826: }
8827: }
1.416 raeburn 8828: unless (($env{'form.action'} eq 'accesslogs') || (($srch->{'srchby'} eq 'uname') && ($srch->{'srchin'} eq 'dom') &&
8829: ($srch->{'srchtype'} eq 'exact') && ($srch->{'srchdomain'} eq $createdom))) {
1.221 raeburn 8830: my $cancreate =
1.305 raeburn 8831: &Apache::lonuserutils::can_create_user($createdom,$context);
8832: my $targetdom = '<span class="LC_cusr_emph">'.$createdom.'</span>';
1.221 raeburn 8833: if ($cancreate) {
1.305 raeburn 8834: my $showdom = &display_domain_info($createdom);
1.266 bisitz 8835: $response .= '<br /><br />'
8836: .'<b>'.&mt('To add a new user:').'</b>'
1.305 raeburn 8837: .'<br />';
8838: if ($context eq 'requestcrs') {
8839: $response .= &mt("(You can only define new users in the new course's domain - [_1])",$targetdom);
8840: } else {
8841: $response .= &mt("(You can only create new users in your current role's domain - [_1])",$targetdom);
8842: }
8843: $response .='<ul><li>'
1.266 bisitz 8844: .&mt("Set 'Domain/institution to search' to: [_1]",'<span class="LC_cusr_emph">'.$showdom.'</span>')
8845: .'</li><li>'
8846: .&mt("Set 'Search criteria' to: [_1]username is ..... in selected LON-CAPA domain[_2]",'<span class="LC_cusr_emph">','</span>')
8847: .'</li><li>'
8848: .&mt('Provide the proposed username')
8849: .'</li><li>'
8850: .&mt("Click 'Search'")
8851: .'</li></ul><br />';
1.221 raeburn 8852: } else {
1.422 raeburn 8853: unless (($context eq 'domain') && ($env{'form.action'} eq 'singleuser')) {
8854: my $helplink = ' href="javascript:helpMenu('."'display'".')"';
8855: $response .= '<br /><br />';
8856: if ($context eq 'requestcrs') {
8857: $response .= &mt("You are not authorized to define new users in the new course's domain - [_1].",$targetdom);
8858: } else {
8859: $response .= &mt("You are not authorized to create new users in your current role's domain - [_1].",$targetdom);
8860: }
8861: $response .= '<br />'
8862: .&mt('Please contact the [_1]helpdesk[_2] if you need to create a new user.'
8863: ,' <a'.$helplink.'>'
8864: ,'</a>')
8865: .'<br />';
1.305 raeburn 8866: }
1.221 raeburn 8867: }
1.160 raeburn 8868: }
8869: }
8870: }
1.179 raeburn 8871: return ($currstate,$response,$forcenewuser);
1.160 raeburn 8872: }
8873:
1.180 raeburn 8874: sub display_domain_info {
8875: my ($dom) = @_;
8876: my $output = $dom;
8877: if ($dom ne '') {
8878: my $domdesc = &Apache::lonnet::domain($dom,'description');
8879: if ($domdesc ne '') {
8880: $output .= ' <span class="LC_cusr_emph">('.$domdesc.')</span>';
8881: }
8882: }
8883: return $output;
8884: }
8885:
1.160 raeburn 8886: sub crumb_utilities {
8887: my %elements = (
8888: crtuser => {
8889: srchterm => 'text',
1.172 raeburn 8890: srchin => 'selectbox',
1.160 raeburn 8891: srchby => 'selectbox',
8892: srchtype => 'selectbox',
8893: srchdomain => 'selectbox',
8894: },
1.207 raeburn 8895: crtusername => {
8896: srchterm => 'text',
8897: srchdomain => 'selectbox',
8898: },
1.160 raeburn 8899: docustom => {
8900: rolename => 'selectbox',
8901: newrolename => 'textbox',
8902: },
1.179 raeburn 8903: studentform => {
8904: srchterm => 'text',
8905: srchin => 'selectbox',
8906: srchby => 'selectbox',
8907: srchtype => 'selectbox',
8908: srchdomain => 'selectbox',
8909: },
1.160 raeburn 8910: );
8911:
8912: my $jsback .= qq|
8913: function backPage(formname,prevphase,prevstate) {
1.211 raeburn 8914: if (typeof prevphase == 'undefined') {
8915: formname.phase.value = '';
8916: }
8917: else {
8918: formname.phase.value = prevphase;
8919: }
8920: if (typeof prevstate == 'undefined') {
8921: formname.currstate.value = '';
8922: }
8923: else {
8924: formname.currstate.value = prevstate;
8925: }
1.160 raeburn 8926: formname.submit();
8927: }
8928: |;
8929: return ($jsback,\%elements);
8930: }
8931:
1.26 matthew 8932: sub course_level_table {
1.375 raeburn 8933: my ($inccourses,$showcredits,$defaultcredits) = @_;
8934: return unless (ref($inccourses) eq 'HASH');
1.26 matthew 8935: my $table = '';
1.62 www 8936: # Custom Roles?
8937:
1.190 raeburn 8938: my %customroles=&Apache::lonuserutils::my_custom_roles();
1.89 raeburn 8939: my %lt=&Apache::lonlocal::texthash(
8940: 'exs' => "Existing sections",
8941: 'new' => "Define new section",
8942: 'ssd' => "Set Start Date",
8943: 'sed' => "Set End Date",
1.131 raeburn 8944: 'crl' => "Course Level",
1.89 raeburn 8945: 'act' => "Activate",
8946: 'rol' => "Role",
8947: 'ext' => "Extent",
1.113 raeburn 8948: 'grs' => "Section",
1.375 raeburn 8949: 'crd' => "Credits",
1.89 raeburn 8950: 'sta' => "Start",
8951: 'end' => "End"
8952: );
1.62 www 8953:
1.375 raeburn 8954: foreach my $protectedcourse (sort(keys(%{$inccourses}))) {
1.135 raeburn 8955: my $thiscourse=$protectedcourse;
1.26 matthew 8956: $thiscourse=~s:_:/:g;
8957: my %coursedata=&Apache::lonnet::coursedescription($thiscourse);
1.365 raeburn 8958: my $isowner = &Apache::lonuserutils::is_courseowner($protectedcourse,$coursedata{'internal.courseowner'});
1.26 matthew 8959: my $area=$coursedata{'description'};
1.321 raeburn 8960: my $crstype=$coursedata{'type'};
1.135 raeburn 8961: if (!defined($area)) { $area=&mt('Unavailable course').': '.$protectedcourse; }
1.89 raeburn 8962: my ($domain,$cnum)=split(/\//,$thiscourse);
1.115 albertel 8963: my %sections_count;
1.101 albertel 8964: if (defined($env{'request.course.id'})) {
8965: if ($env{'request.course.id'} eq $domain.'_'.$cnum) {
1.115 albertel 8966: %sections_count =
8967: &Apache::loncommon::get_sections($domain,$cnum);
1.92 raeburn 8968: }
8969: }
1.321 raeburn 8970: my @roles = &Apache::lonuserutils::roles_by_context('course','',$crstype);
1.213 raeburn 8971: foreach my $role (@roles) {
1.321 raeburn 8972: my $plrole=&Apache::lonnet::plaintext($role,$crstype);
1.329 raeburn 8973: if ((&Apache::lonnet::allowed('c'.$role,$thiscourse)) ||
8974: ((($role eq 'cc') || ($role eq 'co')) && ($isowner))) {
1.221 raeburn 8975: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
1.375 raeburn 8976: $plrole,\%sections_count,\%lt,
1.402 raeburn 8977: $showcredits,$defaultcredits,$crstype);
1.221 raeburn 8978: } elsif ($env{'request.course.sec'} ne '') {
8979: if (&Apache::lonnet::allowed('c'.$role,$thiscourse.'/'.
8980: $env{'request.course.sec'})) {
8981: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
1.375 raeburn 8982: $plrole,\%sections_count,\%lt,
1.402 raeburn 8983: $showcredits,$defaultcredits,$crstype);
1.26 matthew 8984: }
8985: }
8986: }
1.221 raeburn 8987: if (&Apache::lonnet::allowed('ccr',$thiscourse)) {
1.324 raeburn 8988: foreach my $cust (sort(keys(%customroles))) {
8989: next if ($crstype eq 'Community' && $customroles{$cust} =~ /bre\&S/);
1.221 raeburn 8990: my $role = 'cr_cr_'.$env{'user.domain'}.'_'.$env{'user.name'}.'_'.$cust;
8991: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
1.402 raeburn 8992: $cust,\%sections_count,\%lt,
8993: $showcredits,$defaultcredits,$crstype);
1.221 raeburn 8994: }
1.62 www 8995: }
1.26 matthew 8996: }
8997: return '' if ($table eq ''); # return nothing if there is nothing
8998: # in the table
1.188 raeburn 8999: my $result;
9000: if (!$env{'request.course.id'}) {
9001: $result = '<h4>'.$lt{'crl'}.'</h4>'."\n";
9002: }
9003: $result .=
1.136 raeburn 9004: &Apache::loncommon::start_data_table().
9005: &Apache::loncommon::start_data_table_header_row().
1.375 raeburn 9006: '<th>'.$lt{'act'}.'</th><th>'.$lt{'rol'}.'</th>'."\n".
1.402 raeburn 9007: '<th>'.$lt{'ext'}.'</th><th>'."\n";
9008: if ($showcredits) {
9009: $result .= $lt{'crd'}.'</th>';
9010: }
9011: $result .=
1.375 raeburn 9012: '<th>'.$lt{'grs'}.'</th><th>'.$lt{'sta'}.'</th>'."\n".
9013: '<th>'.$lt{'end'}.'</th>'.
1.136 raeburn 9014: &Apache::loncommon::end_data_table_header_row().
9015: $table.
9016: &Apache::loncommon::end_data_table();
1.26 matthew 9017: return $result;
9018: }
1.88 raeburn 9019:
1.221 raeburn 9020: sub course_level_row {
1.375 raeburn 9021: my ($protectedcourse,$role,$area,$domain,$plrole,$sections_count,
1.402 raeburn 9022: $lt,$showcredits,$defaultcredits,$crstype) = @_;
1.375 raeburn 9023: my $creditem;
1.222 raeburn 9024: my $row = &Apache::loncommon::start_data_table_row().
9025: ' <td><input type="checkbox" name="act_'.
9026: $protectedcourse.'_'.$role.'" /></td>'."\n".
9027: ' <td>'.$plrole.'</td>'."\n".
9028: ' <td>'.$area.'<br />Domain: '.$domain.'</td>'."\n";
1.402 raeburn 9029: if (($showcredits) && ($role eq 'st') && ($crstype eq 'Course')) {
1.375 raeburn 9030: $row .=
9031: '<td><input type="text" name="credits_'.$protectedcourse.'_'.
9032: $role.'" size="3" value="'.$defaultcredits.'" /></td>';
9033: } else {
9034: $row .= '<td> </td>';
9035: }
1.322 raeburn 9036: if (($role eq 'cc') || ($role eq 'co')) {
1.222 raeburn 9037: $row .= '<td> </td>';
1.221 raeburn 9038: } elsif ($env{'request.course.sec'} ne '') {
1.222 raeburn 9039: $row .= ' <td><input type="hidden" value="'.
9040: $env{'request.course.sec'}.'" '.
9041: 'name="sec_'.$protectedcourse.'_'.$role.'" />'.
9042: $env{'request.course.sec'}.'</td>';
1.221 raeburn 9043: } else {
9044: if (ref($sections_count) eq 'HASH') {
9045: my $currsec =
9046: &Apache::lonuserutils::course_sections($sections_count,
9047: $protectedcourse.'_'.$role);
1.222 raeburn 9048: $row .= '<td><table class="LC_createuser">'."\n".
9049: '<tr class="LC_section_row">'."\n".
9050: ' <td valign="top">'.$lt->{'exs'}.'<br />'.
9051: $currsec.'</td>'."\n".
9052: ' <td> </td>'."\n".
9053: ' <td valign="top"> '.$lt->{'new'}.'<br />'.
1.221 raeburn 9054: '<input type="text" name="newsec_'.$protectedcourse.'_'.$role.
9055: '" value="" />'.
9056: '<input type="hidden" '.
9057: 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'."\n".
1.222 raeburn 9058: '</tr></table></td>'."\n";
1.221 raeburn 9059: } else {
1.222 raeburn 9060: $row .= '<td><input type="text" size="10" '.
1.375 raeburn 9061: 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'."\n";
1.221 raeburn 9062: }
9063: }
1.222 raeburn 9064: $row .= <<ENDTIMEENTRY;
9065: <td><input type="hidden" name="start_$protectedcourse\_$role" value="" />
1.221 raeburn 9066: <a href=
9067: "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 9068: <td><input type="hidden" name="end_$protectedcourse\_$role" value="" />
1.221 raeburn 9069: <a href=
9070: "javascript:pjump('date_end','End Date $plrole',document.cu.end_$protectedcourse\_$role.value,'end_$protectedcourse\_$role','cu.pres','dateset')">$lt->{'sed'}</a></td>
9071: ENDTIMEENTRY
1.222 raeburn 9072: $row .= &Apache::loncommon::end_data_table_row();
9073: return $row;
1.221 raeburn 9074: }
9075:
1.88 raeburn 9076: sub course_level_dc {
1.375 raeburn 9077: my ($dcdom,$showcredits) = @_;
1.190 raeburn 9078: my %customroles=&Apache::lonuserutils::my_custom_roles();
1.213 raeburn 9079: my @roles = &Apache::lonuserutils::roles_by_context('course');
1.88 raeburn 9080: my $hiddenitems = '<input type="hidden" name="dcdomain" value="'.$dcdom.'" />'.
9081: '<input type="hidden" name="origdom" value="'.$dcdom.'" />'.
1.133 raeburn 9082: '<input type="hidden" name="dccourse" value="" />';
1.355 www 9083: my $courseform=&Apache::loncommon::selectcourse_link
1.356 raeburn 9084: ('cu','dccourse','dcdomain','coursedesc',undef,undef,'Select','crstype');
1.375 raeburn 9085: my $credit_elem;
9086: if ($showcredits) {
9087: $credit_elem = 'credits';
9088: }
9089: my $cb_jscript = &Apache::loncommon::coursebrowser_javascript($dcdom,'currsec','cu','role','Course/Community Browser',$credit_elem);
1.88 raeburn 9090: my %lt=&Apache::lonlocal::texthash(
9091: 'rol' => "Role",
1.113 raeburn 9092: 'grs' => "Section",
1.88 raeburn 9093: 'exs' => "Existing sections",
9094: 'new' => "Define new section",
9095: 'sta' => "Start",
9096: 'end' => "End",
9097: 'ssd' => "Set Start Date",
1.355 www 9098: 'sed' => "Set End Date",
1.375 raeburn 9099: 'scc' => "Course/Community",
9100: 'crd' => "Credits",
1.88 raeburn 9101: );
1.323 raeburn 9102: my $header = '<h4>'.&mt('Course/Community Level').'</h4>'.
1.136 raeburn 9103: &Apache::loncommon::start_data_table().
9104: &Apache::loncommon::start_data_table_header_row().
1.375 raeburn 9105: '<th>'.$lt{'scc'}.'</th><th>'.$lt{'rol'}.'</th>'."\n".
1.397 bisitz 9106: '<th>'.$lt{'grs'}.'</th>'."\n";
9107: $header .= '<th>'.$lt{'crd'}.'</th>'."\n" if ($showcredits);
9108: $header .= '<th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'."\n".
1.136 raeburn 9109: &Apache::loncommon::end_data_table_header_row();
1.143 raeburn 9110: my $otheritems = &Apache::loncommon::start_data_table_row()."\n".
1.356 raeburn 9111: '<td><br /><span class="LC_nobreak"><input type="text" name="coursedesc" value="" onfocus="this.blur();opencrsbrowser('."'cu','dccourse','dcdomain','coursedesc','','','','crstype'".')" />'.
9112: $courseform.(' ' x4).'</span></td>'."\n".
1.389 bisitz 9113: '<td valign="top"><br /><select name="role">'."\n";
1.213 raeburn 9114: foreach my $role (@roles) {
1.135 raeburn 9115: my $plrole=&Apache::lonnet::plaintext($role);
1.389 bisitz 9116: $otheritems .= ' <option value="'.$role.'">'.$plrole.'</option>';
1.88 raeburn 9117: }
1.404 raeburn 9118: if ( keys(%customroles) > 0) {
9119: foreach my $cust (sort(keys(%customroles))) {
1.101 albertel 9120: my $custrole='cr_cr_'.$env{'user.domain'}.
1.135 raeburn 9121: '_'.$env{'user.name'}.'_'.$cust;
1.389 bisitz 9122: $otheritems .= ' <option value="'.$custrole.'">'.$cust.'</option>';
1.88 raeburn 9123: }
9124: }
9125: $otheritems .= '</select></td><td>'.
9126: '<table border="0" cellspacing="0" cellpadding="0">'.
9127: '<tr><td valign="top"><b>'.$lt{'exs'}.'</b><br /><select name="currsec">'.
1.389 bisitz 9128: ' <option value=""><--'.&mt('Pick course first').'</option></select></td>'.
1.88 raeburn 9129: '<td> </td>'.
9130: '<td valign="top"> <b>'.$lt{'new'}.'</b><br />'.
1.113 raeburn 9131: '<input type="text" name="newsec" value="" />'.
1.237 raeburn 9132: '<input type="hidden" name="section" value="" />'.
1.323 raeburn 9133: '<input type="hidden" name="groups" value="" />'.
9134: '<input type="hidden" name="crstype" value="" /></td>'.
1.375 raeburn 9135: '</tr></table></td>'."\n";
9136: if ($showcredits) {
9137: $otheritems .= '<td><br />'."\n".
1.397 bisitz 9138: '<input type="text" size="3" name="credits" value="" /></td>'."\n";
1.375 raeburn 9139: }
1.88 raeburn 9140: $otheritems .= <<ENDTIMEENTRY;
1.323 raeburn 9141: <td><br /><input type="hidden" name="start" value='' />
1.88 raeburn 9142: <a href=
9143: "javascript:pjump('date_start','Start Date',document.cu.start.value,'start','cu.pres','dateset')">$lt{'ssd'}</a></td>
1.323 raeburn 9144: <td><br /><input type="hidden" name="end" value='' />
1.88 raeburn 9145: <a href=
9146: "javascript:pjump('date_end','End Date',document.cu.end.value,'end','cu.pres','dateset')">$lt{'sed'}</a></td>
9147: ENDTIMEENTRY
1.136 raeburn 9148: $otheritems .= &Apache::loncommon::end_data_table_row().
9149: &Apache::loncommon::end_data_table()."\n";
1.88 raeburn 9150: return $cb_jscript.$header.$hiddenitems.$otheritems;
9151: }
9152:
1.237 raeburn 9153: sub update_selfenroll_config {
1.400 raeburn 9154: my ($r,$cid,$cdom,$cnum,$context,$crstype,$currsettings) = @_;
1.398 raeburn 9155: return unless (ref($currsettings) eq 'HASH');
9156: my ($row,$lt) = &Apache::lonuserutils::get_selfenroll_titles();
9157: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
1.237 raeburn 9158: my (%changes,%warning);
1.241 raeburn 9159: my $curr_types;
1.400 raeburn 9160: my %noedit;
9161: unless ($context eq 'domain') {
9162: %noedit = &get_noedit_fields($cdom,$cnum,$crstype,$row);
9163: }
1.237 raeburn 9164: if (ref($row) eq 'ARRAY') {
9165: foreach my $item (@{$row}) {
1.400 raeburn 9166: next if ($noedit{$item});
1.237 raeburn 9167: if ($item eq 'enroll_dates') {
9168: my (%currenrolldate,%newenrolldate);
9169: foreach my $type ('start','end') {
1.398 raeburn 9170: $currenrolldate{$type} = $currsettings->{'selfenroll_'.$type.'_date'};
1.237 raeburn 9171: $newenrolldate{$type} = &Apache::lonhtmlcommon::get_date_from_form('selfenroll_'.$type.'_date');
9172: if ($newenrolldate{$type} ne $currenrolldate{$type}) {
9173: $changes{'internal.selfenroll_'.$type.'_date'} = $newenrolldate{$type};
9174: }
9175: }
9176: } elsif ($item eq 'access_dates') {
9177: my (%currdate,%newdate);
9178: foreach my $type ('start','end') {
1.398 raeburn 9179: $currdate{$type} = $currsettings->{'selfenroll_'.$type.'_access'};
1.237 raeburn 9180: $newdate{$type} = &Apache::lonhtmlcommon::get_date_from_form('selfenroll_'.$type.'_access');
9181: if ($newdate{$type} ne $currdate{$type}) {
9182: $changes{'internal.selfenroll_'.$type.'_access'} = $newdate{$type};
9183: }
9184: }
1.241 raeburn 9185: } elsif ($item eq 'types') {
1.398 raeburn 9186: $curr_types = $currsettings->{'selfenroll_'.$item};
1.241 raeburn 9187: if ($env{'form.selfenroll_all'}) {
9188: if ($curr_types ne '*') {
9189: $changes{'internal.selfenroll_types'} = '*';
9190: } else {
9191: next;
9192: }
9193: } else {
1.249 raeburn 9194: my %currdoms;
1.241 raeburn 9195: my @entries = split(/;/,$curr_types);
9196: my @deletedoms = &Apache::loncommon::get_env_multiple('form.selfenroll_delete');
1.249 raeburn 9197: my @activations = &Apache::loncommon::get_env_multiple('form.selfenroll_activate');
1.241 raeburn 9198: my $newnum = 0;
1.249 raeburn 9199: my @latesttypes;
9200: foreach my $num (@activations) {
9201: my @types = &Apache::loncommon::get_env_multiple('form.selfenroll_types_'.$num);
9202: if (@types > 0) {
1.241 raeburn 9203: @types = sort(@types);
9204: my $typestr = join(',',@types);
1.249 raeburn 9205: my $typedom = $env{'form.selfenroll_dom_'.$num};
9206: $latesttypes[$newnum] = $typedom.':'.$typestr;
9207: $currdoms{$typedom} = 1;
1.241 raeburn 9208: $newnum ++;
9209: }
9210: }
1.338 raeburn 9211: for (my $j=0; $j<$env{'form.selfenroll_types_total'}; $j++) {
9212: if ((!grep(/^$j$/,@deletedoms)) && (!grep(/^$j$/,@activations))) {
1.249 raeburn 9213: my @types = &Apache::loncommon::get_env_multiple('form.selfenroll_types_'.$j);
9214: if (@types > 0) {
9215: @types = sort(@types);
9216: my $typestr = join(',',@types);
9217: my $typedom = $env{'form.selfenroll_dom_'.$j};
9218: $latesttypes[$newnum] = $typedom.':'.$typestr;
9219: $currdoms{$typedom} = 1;
9220: $newnum ++;
9221: }
9222: }
9223: }
9224: if ($env{'form.selfenroll_newdom'} ne '') {
9225: my $typedom = $env{'form.selfenroll_newdom'};
9226: if ((!defined($currdoms{$typedom})) &&
9227: (&Apache::lonnet::domain($typedom) ne '')) {
9228: my $typestr;
9229: my ($othertitle,$usertypes,$types) =
9230: &Apache::loncommon::sorted_inst_types($typedom);
9231: my $othervalue = 'any';
9232: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
9233: if (@{$types} > 0) {
1.257 raeburn 9234: my @esc_types = map { &escape($_); } @{$types};
1.249 raeburn 9235: $othervalue = 'other';
1.258 raeburn 9236: $typestr = join(',',(@esc_types,$othervalue));
1.249 raeburn 9237: }
9238: $typestr = $othervalue;
9239: } else {
9240: $typestr = $othervalue;
9241: }
9242: $latesttypes[$newnum] = $typedom.':'.$typestr;
9243: $newnum ++ ;
9244: }
9245: }
1.241 raeburn 9246: my $selfenroll_types = join(';',@latesttypes);
9247: if ($selfenroll_types ne $curr_types) {
9248: $changes{'internal.selfenroll_types'} = $selfenroll_types;
9249: }
9250: }
1.276 raeburn 9251: } elsif ($item eq 'limit') {
9252: my $newlimit = $env{'form.selfenroll_limit'};
9253: my $newcap = $env{'form.selfenroll_cap'};
9254: $newcap =~s/\s+//g;
1.398 raeburn 9255: my $currlimit = $currsettings->{'selfenroll_limit'};
1.276 raeburn 9256: $currlimit = 'none' if ($currlimit eq '');
1.398 raeburn 9257: my $currcap = $currsettings->{'selfenroll_cap'};
1.276 raeburn 9258: if ($newlimit ne $currlimit) {
9259: if ($newlimit ne 'none') {
9260: if ($newcap =~ /^\d+$/) {
9261: if ($newcap ne $currcap) {
9262: $changes{'internal.selfenroll_cap'} = $newcap;
9263: }
9264: $changes{'internal.selfenroll_limit'} = $newlimit;
9265: } else {
1.398 raeburn 9266: $warning{$item} = &mt('Maximum enrollment setting unchanged.').'<br />'.
9267: &mt('The value provided was invalid - it must be a positive integer if enrollment is being limited.');
1.276 raeburn 9268: }
9269: } elsif ($currcap ne '') {
9270: $changes{'internal.selfenroll_cap'} = '';
9271: $changes{'internal.selfenroll_limit'} = $newlimit;
9272: }
9273: } elsif ($currlimit ne 'none') {
9274: if ($newcap =~ /^\d+$/) {
9275: if ($newcap ne $currcap) {
9276: $changes{'internal.selfenroll_cap'} = $newcap;
9277: }
9278: } else {
1.398 raeburn 9279: $warning{$item} = &mt('Maximum enrollment setting unchanged.').'<br />'.
9280: &mt('The value provided was invalid - it must be a positive integer if enrollment is being limited.');
1.276 raeburn 9281: }
9282: }
9283: } elsif ($item eq 'approval') {
9284: my (@currnotified,@newnotified);
1.398 raeburn 9285: my $currapproval = $currsettings->{'selfenroll_approval'};
9286: my $currnotifylist = $currsettings->{'selfenroll_notifylist'};
1.276 raeburn 9287: if ($currnotifylist ne '') {
9288: @currnotified = split(/,/,$currnotifylist);
9289: @currnotified = sort(@currnotified);
9290: }
9291: my $newapproval = $env{'form.selfenroll_approval'};
9292: @newnotified = &Apache::loncommon::get_env_multiple('form.selfenroll_notify');
9293: @newnotified = sort(@newnotified);
9294: if ($newapproval ne $currapproval) {
9295: $changes{'internal.selfenroll_approval'} = $newapproval;
9296: if (!$newapproval) {
9297: if ($currnotifylist ne '') {
9298: $changes{'internal.selfenroll_notifylist'} = '';
9299: }
9300: } else {
9301: my @differences =
1.295 raeburn 9302: &Apache::loncommon::compare_arrays(\@currnotified,\@newnotified);
1.276 raeburn 9303: if (@differences > 0) {
9304: if (@newnotified > 0) {
9305: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
9306: } else {
9307: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
9308: }
9309: }
9310: }
9311: } else {
1.295 raeburn 9312: my @differences = &Apache::loncommon::compare_arrays(\@currnotified,\@newnotified);
1.276 raeburn 9313: if (@differences > 0) {
9314: if (@newnotified > 0) {
9315: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
9316: } else {
9317: $changes{'internal.selfenroll_notifylist'} = '';
9318: }
9319: }
9320: }
1.237 raeburn 9321: } else {
1.398 raeburn 9322: my $curr_val = $currsettings->{'selfenroll_'.$item};
1.237 raeburn 9323: my $newval = $env{'form.selfenroll_'.$item};
9324: if ($item eq 'section') {
9325: $newval = $env{'form.sections'};
1.241 raeburn 9326: if (defined($curr_groups{$newval})) {
1.237 raeburn 9327: $newval = $curr_val;
1.398 raeburn 9328: $warning{$item} = &mt('Section for self-enrolled users unchanged as the proposed section is a group').'<br />'.
9329: &mt('Group names and section names must be distinct');
1.237 raeburn 9330: } elsif ($newval eq 'all') {
9331: $newval = $curr_val;
1.274 bisitz 9332: $warning{$item} = &mt('Section for self-enrolled users unchanged, as "all" is a reserved section name.');
1.237 raeburn 9333: }
9334: if ($newval eq '') {
9335: $newval = 'none';
9336: }
9337: }
9338: if ($newval ne $curr_val) {
9339: $changes{'internal.selfenroll_'.$item} = $newval;
9340: }
1.241 raeburn 9341: }
1.237 raeburn 9342: }
9343: if (keys(%warning) > 0) {
9344: foreach my $item (@{$row}) {
9345: if (exists($warning{$item})) {
9346: $r->print($warning{$item}.'<br />');
9347: }
9348: }
9349: }
9350: if (keys(%changes) > 0) {
9351: my $putresult = &Apache::lonnet::put('environment',\%changes,$cdom,$cnum);
9352: if ($putresult eq 'ok') {
9353: if ((exists($changes{'internal.selfenroll_types'})) ||
9354: (exists($changes{'internal.selfenroll_start_date'})) ||
9355: (exists($changes{'internal.selfenroll_end_date'}))) {
9356: my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',
9357: $cnum,undef,undef,'Course');
9358: my $chome = &Apache::lonnet::homeserver($cnum,$cdom);
1.398 raeburn 9359: if (ref($crsinfo{$cid}) eq 'HASH') {
1.237 raeburn 9360: foreach my $item ('selfenroll_types','selfenroll_start_date','selfenroll_end_date') {
9361: if (exists($changes{'internal.'.$item})) {
1.398 raeburn 9362: $crsinfo{$cid}{$item} = $changes{'internal.'.$item};
1.237 raeburn 9363: }
9364: }
9365: my $crsputresult =
9366: &Apache::lonnet::courseidput($cdom,\%crsinfo,
9367: $chome,'notime');
9368: }
9369: }
9370: $r->print(&mt('The following changes were made to self-enrollment settings:').'<ul>');
9371: foreach my $item (@{$row}) {
9372: my $title = $item;
9373: if (ref($lt) eq 'HASH') {
9374: $title = $lt->{$item};
9375: }
9376: if ($item eq 'enroll_dates') {
9377: foreach my $type ('start','end') {
9378: if (exists($changes{'internal.selfenroll_'.$type.'_date'})) {
9379: my $newdate = &Apache::lonlocal::locallocaltime($changes{'internal.selfenroll_'.$type.'_date'});
1.244 bisitz 9380: $r->print('<li>'.&mt('[_1]: "[_2]" set to "[_3]".',
1.237 raeburn 9381: $title,$type,$newdate).'</li>');
9382: }
9383: }
9384: } elsif ($item eq 'access_dates') {
9385: foreach my $type ('start','end') {
9386: if (exists($changes{'internal.selfenroll_'.$type.'_access'})) {
9387: my $newdate = &Apache::lonlocal::locallocaltime($changes{'internal.selfenroll_'.$type.'_access'});
1.244 bisitz 9388: $r->print('<li>'.&mt('[_1]: "[_2]" set to "[_3]".',
1.237 raeburn 9389: $title,$type,$newdate).'</li>');
9390: }
9391: }
1.276 raeburn 9392: } elsif ($item eq 'limit') {
9393: if ((exists($changes{'internal.selfenroll_limit'})) ||
9394: (exists($changes{'internal.selfenroll_cap'}))) {
9395: my ($newval,$newcap);
9396: if ($changes{'internal.selfenroll_cap'} ne '') {
9397: $newcap = $changes{'internal.selfenroll_cap'}
9398: } else {
1.398 raeburn 9399: $newcap = $currsettings->{'selfenroll_cap'};
1.276 raeburn 9400: }
9401: if ($changes{'internal.selfenroll_limit'} eq 'none') {
9402: $newval = &mt('No limit');
9403: } elsif ($changes{'internal.selfenroll_limit'} eq
9404: 'allstudents') {
9405: $newval = &mt('New self-enrollment no longer allowed when total (all students) reaches [_1].',$newcap);
9406: } elsif ($changes{'internal.selfenroll_limit'} eq 'selfenrolled') {
9407: $newval = &mt('New self-enrollment no longer allowed when total number of self-enrolled students reaches [_1].',$newcap);
9408: } else {
1.398 raeburn 9409: my $currlimit = $currsettings->{'selfenroll_limit'};
1.276 raeburn 9410: if ($currlimit eq 'allstudents') {
9411: $newval = &mt('New self-enrollment no longer allowed when total (all students) reaches [_1].',$newcap);
9412: } elsif ($changes{'internal.selfenroll_limit'} eq 'selfenrolled') {
1.308 raeburn 9413: $newval = &mt('New self-enrollment no longer allowed when total number of self-enrolled students reaches [_1].',$newcap);
1.276 raeburn 9414: }
9415: }
9416: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval).'</li>'."\n");
9417: }
9418: } elsif ($item eq 'approval') {
9419: if ((exists($changes{'internal.selfenroll_approval'})) ||
9420: (exists($changes{'internal.selfenroll_notifylist'}))) {
1.398 raeburn 9421: my %selfdescs = &Apache::lonuserutils::selfenroll_default_descs();
1.276 raeburn 9422: my ($newval,$newnotify);
9423: if (exists($changes{'internal.selfenroll_notifylist'})) {
9424: $newnotify = $changes{'internal.selfenroll_notifylist'};
9425: } else {
1.398 raeburn 9426: $newnotify = $currsettings->{'selfenroll_notifylist'};
1.276 raeburn 9427: }
1.398 raeburn 9428: if (exists($changes{'internal.selfenroll_approval'})) {
9429: if ($changes{'internal.selfenroll_approval'} !~ /^[012]$/) {
9430: $changes{'internal.selfenroll_approval'} = '0';
9431: }
9432: $newval = $selfdescs{'approval'}{$changes{'internal.selfenroll_approval'}};
1.276 raeburn 9433: } else {
1.398 raeburn 9434: my $currapproval = $currsettings->{'selfenroll_approval'};
9435: if ($currapproval !~ /^[012]$/) {
9436: $currapproval = 0;
1.276 raeburn 9437: }
1.398 raeburn 9438: $newval = $selfdescs{'approval'}{$currapproval};
1.276 raeburn 9439: }
9440: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval));
9441: if ($newnotify) {
1.277 raeburn 9442: $r->print('<br />'.&mt('The following will be notified when an enrollment request needs approval, or has been approved: [_1].',$newnotify));
1.276 raeburn 9443: } else {
1.277 raeburn 9444: $r->print('<br />'.&mt('No notifications sent when an enrollment request needs approval, or has been approved.'));
1.276 raeburn 9445: }
9446: $r->print('</li>'."\n");
9447: }
1.237 raeburn 9448: } else {
9449: if (exists($changes{'internal.selfenroll_'.$item})) {
1.241 raeburn 9450: my $newval = $changes{'internal.selfenroll_'.$item};
9451: if ($item eq 'types') {
9452: if ($newval eq '') {
9453: $newval = &mt('None');
9454: } elsif ($newval eq '*') {
9455: $newval = &mt('Any user in any domain');
9456: }
1.245 raeburn 9457: } elsif ($item eq 'registered') {
9458: if ($newval eq '1') {
9459: $newval = &mt('Yes');
9460: } elsif ($newval eq '0') {
9461: $newval = &mt('No');
9462: }
1.241 raeburn 9463: }
1.244 bisitz 9464: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval).'</li>'."\n");
1.237 raeburn 9465: }
9466: }
9467: }
9468: $r->print('</ul>');
1.398 raeburn 9469: if ($env{'course.'.$cid.'.description'} ne '') {
9470: my %newenvhash;
9471: foreach my $key (keys(%changes)) {
9472: $newenvhash{'course.'.$cid.'.'.$key} = $changes{$key};
9473: }
9474: &Apache::lonnet::appenv(\%newenvhash);
1.237 raeburn 9475: }
9476: } else {
1.398 raeburn 9477: $r->print(&mt('An error occurred when saving changes to self-enrollment settings in this course.').'<br />'.
9478: &mt('The error was: [_1].',$putresult));
1.237 raeburn 9479: }
9480: } else {
1.249 raeburn 9481: $r->print(&mt('No changes were made to the existing self-enrollment settings in this course.'));
1.237 raeburn 9482: }
9483: } else {
1.249 raeburn 9484: $r->print(&mt('No changes were made to the existing self-enrollment settings in this course.'));
1.241 raeburn 9485: }
1.400 raeburn 9486: my $visactions = &cat_visibility();
9487: my ($cathash,%cattype);
9488: my %domconfig = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom);
9489: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
9490: $cathash = $domconfig{'coursecategories'}{'cats'};
9491: $cattype{'auth'} = $domconfig{'coursecategories'}{'auth'};
9492: $cattype{'unauth'} = $domconfig{'coursecategories'}{'unauth'};
9493: } else {
9494: $cathash = {};
9495: $cattype{'auth'} = 'std';
9496: $cattype{'unauth'} = 'std';
9497: }
9498: if (($cattype{'auth'} eq 'none') && ($cattype{'unauth'} eq 'none')) {
9499: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
9500: '<br />'.
9501: '<br />'.$visactions->{'take'}.'<ul>'.
9502: '<li>'.$visactions->{'dc_chgconf'}.'</li>'.
9503: '</ul>');
9504: } elsif (($cattype{'auth'} !~ /^(std|domonly)$/) && ($cattype{'unauth'} !~ /^(std|domonly)$/)) {
9505: if ($currsettings->{'uniquecode'}) {
9506: $r->print('<span class="LC_info">'.$visactions->{'vis'}.'</span>');
9507: } else {
1.366 bisitz 9508: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
1.400 raeburn 9509: '<br />'.
9510: '<br />'.$visactions->{'take'}.'<ul>'.
9511: '<li>'.$visactions->{'dc_setcode'}.'</li>'.
9512: '</ul><br />');
9513: }
9514: } else {
9515: my ($visible,$cansetvis,$vismsgs) = &visible_in_stdcat($cdom,$cnum,\%domconfig);
9516: if (ref($visactions) eq 'HASH') {
9517: if (!$visible) {
9518: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
9519: '<br />');
9520: if (ref($vismsgs) eq 'ARRAY') {
9521: $r->print('<br />'.$visactions->{'take'}.'<ul>');
9522: foreach my $item (@{$vismsgs}) {
9523: $r->print('<li>'.$visactions->{$item}.'</li>');
9524: }
9525: $r->print('</ul>');
1.256 raeburn 9526: }
1.400 raeburn 9527: $r->print($cansetvis);
1.256 raeburn 9528: }
9529: }
9530: }
1.237 raeburn 9531: return;
9532: }
9533:
1.27 matthew 9534: #---------------------------------------------- end functions for &phase_two
1.29 matthew 9535:
9536: #--------------------------------- functions for &phase_two and &phase_three
9537:
9538: #--------------------------end of functions for &phase_two and &phase_three
1.372 raeburn 9539:
1.1 www 9540: 1;
9541: __END__
1.2 www 9542:
9543:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>