Annotation of loncom/interface/loncreateuser.pm, revision 1.440
1.20 harris41 1: # The LearningOnline Network with CAPA
1.1 www 2: # Create a user
3: #
1.440 ! raeburn 4: # $Id: loncreateuser.pm,v 1.439 2017/04/01 14:00:23 raeburn Exp $
1.22 albertel 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
1.20 harris41 28: ###
29:
1.1 www 30: package Apache::loncreateuser;
1.66 bowersj2 31:
32: =pod
33:
34: =head1 NAME
35:
1.263 jms 36: Apache::loncreateuser.pm
1.66 bowersj2 37:
38: =head1 SYNOPSIS
39:
1.263 jms 40: Handler to create users and custom roles
41:
42: Provides an Apache handler for creating users,
1.66 bowersj2 43: editing their login parameters, roles, and removing roles, and
44: also creating and assigning custom roles.
45:
46: =head1 OVERVIEW
47:
48: =head2 Custom Roles
49:
50: In LON-CAPA, roles are actually collections of privileges. "Teaching
51: Assistant", "Course Coordinator", and other such roles are really just
52: collection of privileges that are useful in many circumstances.
53:
1.324 raeburn 54: Custom roles can be defined by a Domain Coordinator, Course Coordinator
55: or Community Coordinator via the Manage User functionality.
56: The custom role editor screen will show all privileges which can be
57: assigned to users. For a complete list of privileges, please see
58: C</home/httpd/lonTabs/rolesplain.tab>.
1.66 bowersj2 59:
1.324 raeburn 60: Custom role definitions are stored in the C<roles.db> file of the creator
61: of the role.
1.66 bowersj2 62:
63: =cut
1.1 www 64:
65: use strict;
66: use Apache::Constants qw(:common :http);
67: use Apache::lonnet;
1.54 bowersj2 68: use Apache::loncommon;
1.68 www 69: use Apache::lonlocal;
1.117 raeburn 70: use Apache::longroup;
1.190 raeburn 71: use Apache::lonuserutils;
1.307 raeburn 72: use Apache::loncoursequeueadmin;
1.139 albertel 73: use LONCAPA qw(:DEFAULT :match);
1.1 www 74:
1.20 harris41 75: my $loginscript; # piece of javascript used in two separate instances
76: my $authformnop;
77: my $authformkrb;
78: my $authformint;
79: my $authformfsys;
80: my $authformloc;
81:
1.94 matthew 82: sub initialize_authen_forms {
1.227 raeburn 83: my ($dom,$formname,$curr_authtype,$mode) = @_;
84: my ($krbdef,$krbdefdom) = &Apache::loncommon::get_kerberos_defaults($dom);
85: my %param = ( formname => $formname,
1.187 raeburn 86: kerb_def_dom => $krbdefdom,
1.227 raeburn 87: kerb_def_auth => $krbdef,
1.187 raeburn 88: domain => $dom,
89: );
1.188 raeburn 90: my %abv_auth = &auth_abbrev();
1.227 raeburn 91: if ($curr_authtype =~ /^(krb4|krb5|internal|localauth|unix):(.*)$/) {
1.188 raeburn 92: my $long_auth = $1;
1.227 raeburn 93: my $curr_autharg = $2;
1.188 raeburn 94: my %abv_auth = &auth_abbrev();
95: $param{'curr_authtype'} = $abv_auth{$long_auth};
96: if ($long_auth =~ /^krb(4|5)$/) {
97: $param{'curr_kerb_ver'} = $1;
1.227 raeburn 98: $param{'curr_autharg'} = $curr_autharg;
1.188 raeburn 99: }
1.205 raeburn 100: if ($mode eq 'modifyuser') {
101: $param{'mode'} = $mode;
102: }
1.187 raeburn 103: }
1.227 raeburn 104: $loginscript = &Apache::loncommon::authform_header(%param);
105: $authformkrb = &Apache::loncommon::authform_kerberos(%param);
1.31 matthew 106: $authformnop = &Apache::loncommon::authform_nochange(%param);
107: $authformint = &Apache::loncommon::authform_internal(%param);
108: $authformfsys = &Apache::loncommon::authform_filesystem(%param);
109: $authformloc = &Apache::loncommon::authform_local(%param);
1.20 harris41 110: }
111:
1.188 raeburn 112: sub auth_abbrev {
113: my %abv_auth = (
1.368 raeburn 114: krb5 => 'krb',
115: krb4 => 'krb',
116: internal => 'int',
117: localauth => 'loc',
118: unix => 'fsys',
1.188 raeburn 119: );
120: return %abv_auth;
121: }
1.43 www 122:
1.134 raeburn 123: # ====================================================
124:
1.378 raeburn 125: sub user_quotas {
1.134 raeburn 126: my ($ccuname,$ccdomain) = @_;
127: my %lt = &Apache::lonlocal::texthash(
1.267 raeburn 128: 'usrt' => "User Tools",
129: 'cust' => "Custom quota",
130: 'chqu' => "Change quota",
1.134 raeburn 131: );
1.378 raeburn 132:
1.149 raeburn 133: my $quota_javascript = <<"END_SCRIPT";
134: <script type="text/javascript">
1.301 bisitz 135: // <![CDATA[
1.378 raeburn 136: function quota_changes(caller,context) {
137: var customoff = document.getElementById('custom_'+context+'quota_off');
138: var customon = document.getElementById('custom_'+context+'quota_on');
139: var number = document.getElementById(context+'quota');
1.149 raeburn 140: if (caller == "custom") {
1.378 raeburn 141: if (customoff) {
142: if (customoff.checked) {
143: number.value = "";
144: }
1.149 raeburn 145: }
146: }
147: if (caller == "quota") {
1.378 raeburn 148: if (customon) {
149: customon.checked = true;
150: }
1.149 raeburn 151: }
1.378 raeburn 152: return;
1.149 raeburn 153: }
1.301 bisitz 154: // ]]>
1.149 raeburn 155: </script>
156: END_SCRIPT
1.378 raeburn 157: my $longinsttype;
158: my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($ccdomain);
1.267 raeburn 159: my $output = $quota_javascript."\n".
160: '<h3>'.$lt{'usrt'}.'</h3>'."\n".
161: &Apache::loncommon::start_data_table();
162:
1.418 raeburn 163: if ((&Apache::lonnet::allowed('mut',$ccdomain)) ||
164: (&Apache::lonnet::allowed('udp',$ccdomain))) {
1.275 raeburn 165: $output .= &build_tools_display($ccuname,$ccdomain,'tools');
1.267 raeburn 166: }
1.378 raeburn 167:
168: my %titles = &Apache::lonlocal::texthash (
169: portfolio => "Disk space allocated to user's portfolio files",
1.385 bisitz 170: author => "Disk space allocated to user's Authoring Space (if role assigned)",
1.378 raeburn 171: );
172: foreach my $name ('portfolio','author') {
173: my ($currquota,$quotatype,$inststatus,$defquota) =
174: &Apache::loncommon::get_user_quota($ccuname,$ccdomain,$name);
175: if ($longinsttype eq '') {
176: if ($inststatus ne '') {
177: if ($usertypes->{$inststatus} ne '') {
178: $longinsttype = $usertypes->{$inststatus};
179: }
180: }
181: }
182: my ($showquota,$custom_on,$custom_off,$defaultinfo);
183: $custom_on = ' ';
184: $custom_off = ' checked="checked" ';
185: if ($quotatype eq 'custom') {
186: $custom_on = $custom_off;
187: $custom_off = ' ';
188: $showquota = $currquota;
189: if ($longinsttype eq '') {
190: $defaultinfo = &mt('For this user, the default quota would be [_1]'
1.383 raeburn 191: .' MB.',$defquota);
1.378 raeburn 192: } else {
193: $defaultinfo = &mt("For this user, the default quota would be [_1]".
1.383 raeburn 194: " MB, as determined by the user's institutional".
1.378 raeburn 195: " affiliation ([_2]).",$defquota,$longinsttype);
196: }
197: } else {
198: if ($longinsttype eq '') {
199: $defaultinfo = &mt('For this user, the default quota is [_1]'
1.383 raeburn 200: .' MB.',$defquota);
1.378 raeburn 201: } else {
202: $defaultinfo = &mt("For this user, the default quota of [_1]".
1.383 raeburn 203: " MB, is determined by the user's institutional".
1.378 raeburn 204: " affiliation ([_2]).",$defquota,$longinsttype);
205: }
206: }
207:
208: if (&Apache::lonnet::allowed('mpq',$ccdomain)) {
209: $output .= '<tr class="LC_info_row">'."\n".
210: ' <td>'.$titles{$name}.'</td>'."\n".
211: ' </tr>'."\n".
212: &Apache::loncommon::start_data_table_row()."\n".
1.390 bisitz 213: ' <td><span class="LC_nobreak">'.
214: &mt('Current quota: [_1] MB',$currquota).'</span> '.
1.378 raeburn 215: $defaultinfo.'</td>'."\n".
216: &Apache::loncommon::end_data_table_row()."\n".
217: &Apache::loncommon::start_data_table_row()."\n".
218: ' <td><span class="LC_nobreak">'.$lt{'chqu'}.
219: ': <label>'.
220: '<input type="radio" name="custom_'.$name.'quota" id="custom_'.$name.'quota_off" '.
1.379 raeburn 221: 'value="0" '.$custom_off.' onchange="javascript:quota_changes('."'custom','$name'".');"'.
1.390 bisitz 222: ' /><span class="LC_nobreak">'.
223: &mt('Default ([_1] MB)',$defquota).'</span></label> '.
1.378 raeburn 224: ' <label><input type="radio" name="custom_'.$name.'quota" id="custom_'.$name.'quota_on" '.
1.379 raeburn 225: 'value="1" '.$custom_on.' onchange="javascript:quota_changes('."'custom','$name'".');"'.
1.378 raeburn 226: ' />'.$lt{'cust'}.':</label> '.
1.379 raeburn 227: '<input type="text" name="'.$name.'quota" id="'.$name.'quota" size ="5" '.
228: 'value="'.$showquota.'" onfocus="javascript:quota_changes('."'quota','$name'".');"'.
1.390 bisitz 229: ' /> '.&mt('MB').'</span></td>'."\n".
1.378 raeburn 230: &Apache::loncommon::end_data_table_row()."\n";
231: }
232: }
1.267 raeburn 233: $output .= &Apache::loncommon::end_data_table();
1.134 raeburn 234: return $output;
235: }
236:
1.275 raeburn 237: sub build_tools_display {
238: my ($ccuname,$ccdomain,$context) = @_;
1.306 raeburn 239: my (@usertools,%userenv,$output,@options,%validations,%reqtitles,%reqdisplay,
1.332 raeburn 240: $colspan,$isadv,%domconfig);
1.275 raeburn 241: my %lt = &Apache::lonlocal::texthash (
242: 'blog' => "Personal User Blog",
243: 'aboutme' => "Personal Information Page",
1.385 bisitz 244: 'webdav' => "WebDAV access to Authoring Spaces (if SSL and author/co-author)",
1.275 raeburn 245: 'portfolio' => "Personal User Portfolio",
246: 'avai' => "Available",
247: 'cusa' => "availability",
248: 'chse' => "Change setting",
249: 'usde' => "Use default",
250: 'uscu' => "Use custom",
251: 'official' => 'Can request creation of official courses',
1.299 raeburn 252: 'unofficial' => 'Can request creation of unofficial courses',
253: 'community' => 'Can request creation of communities',
1.384 raeburn 254: 'textbook' => 'Can request creation of textbook courses',
1.411 raeburn 255: 'placement' => 'Can request creation of placement tests',
1.362 raeburn 256: 'requestauthor' => 'Can request author space',
1.275 raeburn 257: );
1.279 raeburn 258: if ($context eq 'requestcourses') {
1.275 raeburn 259: %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
1.299 raeburn 260: 'requestcourses.official','requestcourses.unofficial',
1.411 raeburn 261: 'requestcourses.community','requestcourses.textbook',
262: 'requestcourses.placement');
263: @usertools = ('official','unofficial','community','textbook','placement');
1.309 raeburn 264: @options =('norequest','approval','autolimit','validate');
1.306 raeburn 265: %validations = &Apache::lonnet::auto_courserequest_checks($ccdomain);
266: %reqtitles = &courserequest_titles();
267: %reqdisplay = &courserequest_display();
268: $colspan = ' colspan="2"';
1.332 raeburn 269: %domconfig =
270: &Apache::lonnet::get_dom('configuration',['requestcourses'],$ccdomain);
1.418 raeburn 271: $isadv = &Apache::lonnet::is_advanced_user($ccdomain,$ccuname);
1.362 raeburn 272: } elsif ($context eq 'requestauthor') {
273: %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
274: 'requestauthor');
275: @usertools = ('requestauthor');
276: @options =('norequest','approval','automatic');
277: %reqtitles = &requestauthor_titles();
278: %reqdisplay = &requestauthor_display();
279: $colspan = ' colspan="2"';
280: %domconfig =
281: &Apache::lonnet::get_dom('configuration',['requestauthor'],$ccdomain);
1.275 raeburn 282: } else {
283: %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
1.361 raeburn 284: 'tools.aboutme','tools.portfolio','tools.blog',
285: 'tools.webdav');
286: @usertools = ('aboutme','blog','webdav','portfolio');
1.275 raeburn 287: }
288: foreach my $item (@usertools) {
1.306 raeburn 289: my ($custom_access,$curr_access,$cust_on,$cust_off,$tool_on,$tool_off,
290: $currdisp,$custdisp,$custradio);
1.275 raeburn 291: $cust_off = 'checked="checked" ';
292: $tool_on = 'checked="checked" ';
293: $curr_access =
294: &Apache::lonnet::usertools_access($ccuname,$ccdomain,$item,undef,
295: $context);
1.362 raeburn 296: if ($context eq 'requestauthor') {
297: if ($userenv{$context} ne '') {
298: $cust_on = ' checked="checked" ';
299: $cust_off = '';
300: }
301: } elsif ($userenv{$context.'.'.$item} ne '') {
1.306 raeburn 302: $cust_on = ' checked="checked" ';
303: $cust_off = '';
304: }
305: if ($context eq 'requestcourses') {
306: if ($userenv{$context.'.'.$item} eq '') {
1.314 raeburn 307: $custom_access = &mt('Currently from default setting.');
1.306 raeburn 308: } else {
309: $custom_access = &mt('Currently from custom setting.');
1.275 raeburn 310: }
1.362 raeburn 311: } elsif ($context eq 'requestauthor') {
312: if ($userenv{$context} eq '') {
313: $custom_access = &mt('Currently from default setting.');
314: } else {
315: $custom_access = &mt('Currently from custom setting.');
316: }
1.275 raeburn 317: } else {
1.306 raeburn 318: if ($userenv{$context.'.'.$item} eq '') {
1.314 raeburn 319: $custom_access =
1.306 raeburn 320: &mt('Availability determined currently from default setting.');
321: if (!$curr_access) {
322: $tool_off = 'checked="checked" ';
323: $tool_on = '';
324: }
325: } else {
1.314 raeburn 326: $custom_access =
1.306 raeburn 327: &mt('Availability determined currently from custom setting.');
328: if ($userenv{$context.'.'.$item} == 0) {
329: $tool_off = 'checked="checked" ';
330: $tool_on = '';
331: }
1.275 raeburn 332: }
333: }
334: $output .= ' <tr class="LC_info_row">'."\n".
1.306 raeburn 335: ' <td'.$colspan.'>'.$lt{$item}.'</td>'."\n".
1.275 raeburn 336: ' </tr>'."\n".
1.306 raeburn 337: &Apache::loncommon::start_data_table_row()."\n";
1.418 raeburn 338:
1.362 raeburn 339: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.306 raeburn 340: my ($curroption,$currlimit);
1.362 raeburn 341: my $envkey = $context.'.'.$item;
342: if ($context eq 'requestauthor') {
343: $envkey = $context;
344: }
345: if ($userenv{$envkey} ne '') {
346: $curroption = $userenv{$envkey};
1.332 raeburn 347: } else {
348: my (@inststatuses);
1.362 raeburn 349: if ($context eq 'requestcourses') {
350: $curroption =
351: &Apache::loncoursequeueadmin::get_processtype('course',$ccuname,$ccdomain,
352: $isadv,$ccdomain,$item,
353: \@inststatuses,\%domconfig);
354: } else {
355: $curroption =
356: &Apache::loncoursequeueadmin::get_processtype('requestauthor',$ccuname,$ccdomain,
357: $isadv,$ccdomain,undef,
358: \@inststatuses,\%domconfig);
359: }
1.332 raeburn 360: }
1.306 raeburn 361: if (!$curroption) {
362: $curroption = 'norequest';
363: }
364: if ($curroption =~ /^autolimit=(\d*)$/) {
365: $currlimit = $1;
1.314 raeburn 366: if ($currlimit eq '') {
367: $currdisp = &mt('Yes, automatic creation');
368: } else {
369: $currdisp = &mt('Yes, up to [quant,_1,request]/user',$currlimit);
370: }
1.306 raeburn 371: } else {
372: $currdisp = $reqdisplay{$curroption};
373: }
374: $custdisp = '<table>';
375: foreach my $option (@options) {
376: my $val = $option;
377: if ($option eq 'norequest') {
378: $val = 0;
379: }
380: if ($option eq 'validate') {
381: my $canvalidate = 0;
382: if (ref($validations{$item}) eq 'HASH') {
383: if ($validations{$item}{'_custom_'}) {
384: $canvalidate = 1;
385: }
386: }
387: next if (!$canvalidate);
388: }
389: my $checked = '';
390: if ($option eq $curroption) {
391: $checked = ' checked="checked"';
392: } elsif ($option eq 'autolimit') {
393: if ($curroption =~ /^autolimit/) {
394: $checked = ' checked="checked"';
395: }
396: }
1.362 raeburn 397: my $name = 'crsreq_'.$item;
398: if ($context eq 'requestauthor') {
399: $name = $item;
400: }
1.306 raeburn 401: $custdisp .= '<tr><td><span class="LC_nobreak"><label>'.
1.362 raeburn 402: '<input type="radio" name="'.$name.'" '.
403: 'value="'.$val.'"'.$checked.' />'.
1.306 raeburn 404: $reqtitles{$option}.'</label> ';
405: if ($option eq 'autolimit') {
1.362 raeburn 406: $custdisp .= '<input type="text" name="'.$name.
407: '_limit" size="1" '.
1.314 raeburn 408: 'value="'.$currlimit.'" /></span><br />'.
409: $reqtitles{'unlimited'};
1.362 raeburn 410: } else {
411: $custdisp .= '</span>';
412: }
413: $custdisp .= '</td></tr>';
1.306 raeburn 414: }
415: $custdisp .= '</table>';
416: $custradio = '</span></td><td>'.&mt('Custom setting').'<br />'.$custdisp;
417: } else {
418: $currdisp = ($curr_access?&mt('Yes'):&mt('No'));
1.362 raeburn 419: my $name = $context.'_'.$item;
420: if ($context eq 'requestauthor') {
421: $name = $context;
422: }
1.306 raeburn 423: $custdisp = '<span class="LC_nobreak"><label>'.
1.362 raeburn 424: '<input type="radio" name="'.$name.'"'.
1.361 raeburn 425: ' value="1" '.$tool_on.'/>'.&mt('On').'</label> <label>'.
1.362 raeburn 426: '<input type="radio" name="'.$name.'" value="0" '.
1.306 raeburn 427: $tool_off.'/>'.&mt('Off').'</label></span>';
428: $custradio = (' 'x2).'--'.$lt{'cusa'}.': '.$custdisp.
429: '</span>';
430: }
431: $output .= ' <td'.$colspan.'>'.$custom_access.(' 'x4).
1.419 raeburn 432: $lt{'avai'}.': '.$currdisp.'</td>'."\n".
1.418 raeburn 433: &Apache::loncommon::end_data_table_row()."\n";
434: unless (&Apache::lonnet::allowed('udp',$ccdomain)) {
435: $output .=
1.275 raeburn 436: &Apache::loncommon::start_data_table_row()."\n".
1.306 raeburn 437: ' <td style="vertical-align:top;"><span class="LC_nobreak">'.
438: $lt{'chse'}.': <label>'.
1.275 raeburn 439: '<input type="radio" name="custom'.$item.'" value="0" '.
1.306 raeburn 440: $cust_off.'/>'.$lt{'usde'}.'</label>'.(' ' x3).
441: '<label><input type="radio" name="custom'.$item.'" value="1" '.
442: $cust_on.'/>'.$lt{'uscu'}.'</label>'.$custradio.'</td>'.
1.275 raeburn 443: &Apache::loncommon::end_data_table_row()."\n";
1.418 raeburn 444: }
1.275 raeburn 445: }
446: return $output;
447: }
448:
1.300 raeburn 449: sub coursereq_externaluser {
450: my ($ccuname,$ccdomain,$cdom) = @_;
1.306 raeburn 451: my (@usertools,@options,%validations,%userenv,$output);
1.300 raeburn 452: my %lt = &Apache::lonlocal::texthash (
453: 'official' => 'Can request creation of official courses',
454: 'unofficial' => 'Can request creation of unofficial courses',
455: 'community' => 'Can request creation of communities',
1.384 raeburn 456: 'textbook' => 'Can request creation of textbook courses',
1.411 raeburn 457: 'placement' => 'Can request creation of placement tests',
1.300 raeburn 458: );
459:
460: %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
461: 'reqcrsotherdom.official','reqcrsotherdom.unofficial',
1.411 raeburn 462: 'reqcrsotherdom.community','reqcrsotherdom.textbook',
463: 'reqcrsotherdom.placement');
464: @usertools = ('official','unofficial','community','textbook','placement');
1.309 raeburn 465: @options = ('approval','validate','autolimit');
1.306 raeburn 466: %validations = &Apache::lonnet::auto_courserequest_checks($cdom);
467: my $optregex = join('|',@options);
468: my %reqtitles = &courserequest_titles();
1.300 raeburn 469: foreach my $item (@usertools) {
1.306 raeburn 470: my ($curroption,$currlimit,$tooloff);
1.300 raeburn 471: if ($userenv{'reqcrsotherdom.'.$item} ne '') {
472: my @curr = split(',',$userenv{'reqcrsotherdom.'.$item});
1.314 raeburn 473: foreach my $req (@curr) {
474: if ($req =~ /^\Q$cdom\E\:($optregex)=?(\d*)$/) {
475: $curroption = $1;
476: $currlimit = $2;
477: last;
1.306 raeburn 478: }
479: }
1.314 raeburn 480: if (!$curroption) {
481: $curroption = 'norequest';
482: $tooloff = ' checked="checked"';
483: }
1.306 raeburn 484: } else {
485: $curroption = 'norequest';
486: $tooloff = ' checked="checked"';
487: }
488: $output.= &Apache::loncommon::start_data_table_row()."\n".
1.314 raeburn 489: ' <td><span class="LC_nobreak">'.$lt{$item}.': </span></td><td>'.
490: '<table><tr><td valign="top">'."\n".
1.306 raeburn 491: '<label><input type="radio" name="reqcrsotherdom_'.$item.
1.314 raeburn 492: '" value=""'.$tooloff.' />'.$reqtitles{'norequest'}.
493: '</label></td>';
1.306 raeburn 494: foreach my $option (@options) {
495: if ($option eq 'validate') {
496: my $canvalidate = 0;
497: if (ref($validations{$item}) eq 'HASH') {
498: if ($validations{$item}{'_external_'}) {
499: $canvalidate = 1;
500: }
501: }
502: next if (!$canvalidate);
503: }
504: my $checked = '';
505: if ($option eq $curroption) {
506: $checked = ' checked="checked"';
507: }
1.314 raeburn 508: $output .= '<td valign="top"><span class="LC_nobreak"><label>'.
1.306 raeburn 509: '<input type="radio" name="reqcrsotherdom_'.$item.
510: '" value="'.$option.'"'.$checked.' />'.
1.314 raeburn 511: $reqtitles{$option}.'</label>';
1.306 raeburn 512: if ($option eq 'autolimit') {
1.314 raeburn 513: $output .= ' <input type="text" name="reqcrsotherdom_'.
1.306 raeburn 514: $item.'_limit" size="1" '.
1.314 raeburn 515: 'value="'.$currlimit.'" /></span>'.
516: '<br />'.$reqtitles{'unlimited'};
517: } else {
518: $output .= '</span>';
1.300 raeburn 519: }
1.314 raeburn 520: $output .= '</td>';
1.300 raeburn 521: }
1.314 raeburn 522: $output .= '</td></tr></table></td>'."\n".
1.300 raeburn 523: &Apache::loncommon::end_data_table_row()."\n";
524: }
525: return $output;
526: }
527:
1.362 raeburn 528: sub domainrole_req {
529: my ($ccuname,$ccdomain) = @_;
530: return '<br /><h3>'.
531: &mt('User Can Request Assignment of Domain Roles?').
532: '</h3>'."\n".
533: &Apache::loncommon::start_data_table().
534: &build_tools_display($ccuname,$ccdomain,
535: 'requestauthor').
536: &Apache::loncommon::end_data_table();
537: }
538:
1.306 raeburn 539: sub courserequest_titles {
540: my %titles = &Apache::lonlocal::texthash (
541: official => 'Official',
542: unofficial => 'Unofficial',
543: community => 'Communities',
1.384 raeburn 544: textbook => 'Textbook',
1.411 raeburn 545: placement => 'Placement Tests',
1.306 raeburn 546: norequest => 'Not allowed',
1.309 raeburn 547: approval => 'Approval by Dom. Coord.',
1.306 raeburn 548: validate => 'With validation',
549: autolimit => 'Numerical limit',
1.314 raeburn 550: unlimited => '(blank for unlimited)',
1.306 raeburn 551: );
552: return %titles;
553: }
554:
555: sub courserequest_display {
556: my %titles = &Apache::lonlocal::texthash (
1.309 raeburn 557: approval => 'Yes, need approval',
1.306 raeburn 558: validate => 'Yes, with validation',
559: norequest => 'No',
560: );
561: return %titles;
562: }
563:
1.362 raeburn 564: sub requestauthor_titles {
565: my %titles = &Apache::lonlocal::texthash (
566: norequest => 'Not allowed',
567: approval => 'Approval by Dom. Coord.',
568: automatic => 'Automatic approval',
569: );
570: return %titles;
571:
572: }
573:
574: sub requestauthor_display {
575: my %titles = &Apache::lonlocal::texthash (
576: approval => 'Yes, need approval',
577: automatic => 'Yes, automatic approval',
578: norequest => 'No',
579: );
580: return %titles;
581: }
582:
1.383 raeburn 583: sub requestchange_display {
584: my %titles = &Apache::lonlocal::texthash (
585: approval => "availability set to 'on' (approval required)",
586: automatic => "availability set to 'on' (automatic approval)",
587: norequest => "availability set to 'off'",
588: );
589: return %titles;
590: }
591:
1.362 raeburn 592: sub curr_requestauthor {
593: my ($uname,$udom,$isadv,$inststatuses,$domconfig) = @_;
594: return unless ((ref($inststatuses) eq 'ARRAY') && (ref($domconfig) eq 'HASH'));
595: if ($uname eq '' || $udom eq '') {
596: $uname = $env{'user.name'};
597: $udom = $env{'user.domain'};
598: $isadv = $env{'user.adv'};
599: }
600: my (%userenv,%settings,$val);
601: my @options = ('automatic','approval');
602: %userenv =
603: &Apache::lonnet::userenvironment($udom,$uname,'requestauthor','inststatus');
604: if ($userenv{'requestauthor'}) {
605: $val = $userenv{'requestauthor'};
606: @{$inststatuses} = ('_custom_');
607: } else {
608: my %alltasks;
609: if (ref($domconfig->{'requestauthor'}) eq 'HASH') {
610: %settings = %{$domconfig->{'requestauthor'}};
611: if (($isadv) && ($settings{'_LC_adv'} ne '')) {
612: $val = $settings{'_LC_adv'};
613: @{$inststatuses} = ('_LC_adv_');
614: } else {
615: if ($userenv{'inststatus'} ne '') {
616: @{$inststatuses} = split(',',$userenv{'inststatus'});
617: } else {
618: @{$inststatuses} = ('default');
619: }
620: foreach my $status (@{$inststatuses}) {
621: if (exists($settings{$status})) {
622: my $value = $settings{$status};
623: next unless ($value);
624: unless (exists($alltasks{$value})) {
625: if (ref($alltasks{$value}) eq 'ARRAY') {
626: unless(grep(/^\Q$status\E$/,@{$alltasks{$value}})) {
627: push(@{$alltasks{$value}},$status);
628: }
629: } else {
630: @{$alltasks{$value}} = ($status);
631: }
632: }
633: }
634: }
635: foreach my $option (@options) {
636: if ($alltasks{$option}) {
637: $val = $option;
638: last;
639: }
640: }
641: }
642: }
643: }
644: return $val;
645: }
646:
1.2 www 647: # =================================================================== Phase one
1.1 www 648:
1.42 matthew 649: sub print_username_entry_form {
1.439 raeburn 650: my ($r,$context,$response,$srch,$forcenewuser,$crstype,$brcrum,
651: $permission) = @_;
1.101 albertel 652: my $defdom=$env{'request.role.domain'};
1.160 raeburn 653: my $formtoset = 'crtuser';
654: if (exists($env{'form.startrolename'})) {
655: $formtoset = 'docustom';
656: $env{'form.rolename'} = $env{'form.startrolename'};
1.207 raeburn 657: } elsif ($env{'form.origform'} eq 'crtusername') {
658: $formtoset = $env{'form.origform'};
1.160 raeburn 659: }
660:
661: my ($jsback,$elements) = &crumb_utilities();
662:
663: my $jscript = &Apache::loncommon::studentbrowser_javascript()."\n".
1.165 albertel 664: '<script type="text/javascript">'."\n".
1.301 bisitz 665: '// <![CDATA['."\n".
666: &Apache::lonhtmlcommon::set_form_elements($elements->{$formtoset})."\n".
667: '// ]]>'."\n".
1.162 raeburn 668: '</script>'."\n";
1.160 raeburn 669:
1.324 raeburn 670: my %existingroles=&Apache::lonuserutils::my_custom_roles($crstype);
671: if (($env{'form.action'} eq 'custom') && (keys(%existingroles) > 0)
672: && (&Apache::lonnet::allowed('mcr','/'))) {
673: $jscript .= &customrole_javascript();
674: }
1.224 raeburn 675: my $helpitem = 'Course_Change_Privileges';
676: if ($env{'form.action'} eq 'custom') {
1.439 raeburn 677: if ($context eq 'course') {
678: $helpitem = 'Course_Editing_Custom_Roles';
679: } elsif ($context eq 'domain') {
680: $helpitem = 'Domain_Editing_Custom_Roles';
681: }
1.224 raeburn 682: } elsif ($env{'form.action'} eq 'singlestudent') {
683: $helpitem = 'Course_Add_Student';
1.416 raeburn 684: } elsif ($env{'form.action'} eq 'accesslogs') {
685: $helpitem = 'Domain_User_Access_Logs';
1.439 raeburn 686: } elsif ($context eq 'author') {
687: $helpitem = 'Author_Change_Privileges';
688: } elsif ($context eq 'domain') {
689: if ($permission->{'cusr'}) {
690: $helpitem = 'Domain_Change_Privileges';
691: } elsif ($permission->{'view'}) {
692: $helpitem = 'Domain_View_Privileges';
693: } else {
694: undef($helpitem);
695: }
1.224 raeburn 696: }
1.422 raeburn 697: my %breadcrumb_text = &singleuser_breadcrumb($crstype,$context,$defdom);
1.351 raeburn 698: if ($env{'form.action'} eq 'custom') {
699: push(@{$brcrum},
700: {href=>"javascript:backPage(document.crtuser)",
701: text=>"Pick custom role",
702: help => $helpitem,}
703: );
704: } else {
705: push (@{$brcrum},
706: {href => "javascript:backPage(document.crtuser)",
707: text => $breadcrumb_text{'search'},
708: help => $helpitem,
709: faq => 282,
710: bug => 'Instructor Interface',}
711: );
712: }
713: my %loaditems = (
714: 'onload' => "javascript:setFormElements(document.$formtoset)",
715: );
716: my $args = {bread_crumbs => $brcrum,
717: bread_crumbs_component => 'User Management',
718: add_entries => \%loaditems,};
719: $r->print(&Apache::loncommon::start_page('User Management',$jscript,$args));
720:
1.71 sakharuk 721: my %lt=&Apache::lonlocal::texthash(
1.229 raeburn 722: 'srst' => 'Search for a user and enroll as a student',
1.318 raeburn 723: 'srme' => 'Search for a user and enroll as a member',
1.229 raeburn 724: 'srad' => 'Search for a user and modify/add user information or roles',
1.422 raeburn 725: 'srvu' => 'Search for a user and view user information and roles',
1.416 raeburn 726: 'srva' => 'Search for a user and view access log information',
1.71 sakharuk 727: 'usr' => "Username",
728: 'dom' => "Domain",
1.324 raeburn 729: 'ecrp' => "Define or Edit Custom Role",
730: 'nr' => "role name",
1.282 schafran 731: 'cre' => "Next",
1.71 sakharuk 732: );
1.351 raeburn 733:
1.214 raeburn 734: if ($env{'form.action'} eq 'custom') {
1.190 raeburn 735: if (&Apache::lonnet::allowed('mcr','/')) {
1.324 raeburn 736: my $newroletext = &mt('Define new custom role:');
737: $r->print('<form action="/adm/createuser" method="post" name="docustom">'.
738: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'.
739: '<input type="hidden" name="phase" value="selected_custom_edit" />'.
740: '<h3>'.$lt{'ecrp'}.'</h3>'.
741: &Apache::loncommon::start_data_table().
742: &Apache::loncommon::start_data_table_row().
743: '<td>');
744: if (keys(%existingroles) > 0) {
745: $r->print('<br /><label><input type="radio" name="customroleaction" value="new" checked="checked" onclick="setCustomFields();" /><b>'.$newroletext.'</b></label>');
746: } else {
747: $r->print('<br /><input type="hidden" name="customroleaction" value="new" /><b>'.$newroletext.'</b>');
748: }
749: $r->print('</td><td align="center">'.$lt{'nr'}.'<br /><input type="text" size="15" name="newrolename" onfocus="setCustomAction('."'new'".');" /></td>'.
750: &Apache::loncommon::end_data_table_row());
751: if (keys(%existingroles) > 0) {
752: $r->print(&Apache::loncommon::start_data_table_row().'<td><br />'.
753: '<label><input type="radio" name="customroleaction" value="edit" onclick="setCustomFields();"/><b>'.
754: &mt('View/Modify existing role:').'</b></label></td>'.
755: '<td align="center"><br />'.
756: '<select name="rolename" onchange="setCustomAction('."'edit'".');">'.
1.326 raeburn 757: '<option value="" selected="selected">'.
1.324 raeburn 758: &mt('Select'));
759: foreach my $role (sort(keys(%existingroles))) {
1.326 raeburn 760: $r->print('<option value="'.$role.'">'.$role.'</option>');
1.324 raeburn 761: }
762: $r->print('</select>'.
763: '</td>'.
764: &Apache::loncommon::end_data_table_row());
765: }
766: $r->print(&Apache::loncommon::end_data_table().'<p>'.
767: '<input name="customeditor" type="submit" value="'.
768: $lt{'cre'}.'" /></p>'.
769: '</form>');
1.190 raeburn 770: }
1.213 raeburn 771: } else {
1.229 raeburn 772: my $actiontext = $lt{'srad'};
1.436 raeburn 773: my $fixeddom;
1.213 raeburn 774: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 775: if ($crstype eq 'Community') {
776: $actiontext = $lt{'srme'};
777: } else {
778: $actiontext = $lt{'srst'};
779: }
1.416 raeburn 780: } elsif ($env{'form.action'} eq 'accesslogs') {
1.417 raeburn 781: $actiontext = $lt{'srva'};
1.436 raeburn 782: $fixeddom = 1;
1.422 raeburn 783: } elsif (($env{'form.action'} eq 'singleuser') &&
784: ($context eq 'domain') && (!&Apache::lonnet::allowed('mau',$defdom))) {
785: $actiontext = $lt{'srvu'};
1.439 raeburn 786: $fixeddom = 1;
1.213 raeburn 787: }
1.324 raeburn 788: $r->print("<h3>$actiontext</h3>");
1.213 raeburn 789: if ($env{'form.origform'} ne 'crtusername') {
1.415 raeburn 790: if ($response) {
791: $r->print("\n<div>$response</div>".
792: '<br clear="all" />');
793: }
1.213 raeburn 794: }
1.436 raeburn 795: $r->print(&entry_form($defdom,$srch,$forcenewuser,$context,$response,$crstype,$fixeddom));
1.107 www 796: }
1.110 albertel 797: }
798:
1.324 raeburn 799: sub customrole_javascript {
800: my $js = <<"END";
801: <script type="text/javascript">
802: // <![CDATA[
803:
804: function setCustomFields() {
805: if (document.docustom.customroleaction.length > 0) {
806: for (var i=0; i<document.docustom.customroleaction.length; i++) {
807: if (document.docustom.customroleaction[i].checked) {
808: if (document.docustom.customroleaction[i].value == 'new') {
809: document.docustom.rolename.selectedIndex = 0;
810: } else {
811: document.docustom.newrolename.value = '';
812: }
813: }
814: }
815: }
816: return;
817: }
818:
819: function setCustomAction(caller) {
820: if (document.docustom.customroleaction.length > 0) {
821: for (var i=0; i<document.docustom.customroleaction.length; i++) {
822: if (document.docustom.customroleaction[i].value == caller) {
823: document.docustom.customroleaction[i].checked = true;
824: }
825: }
826: }
827: setCustomFields();
828: return;
829: }
830:
831: // ]]>
832: </script>
833: END
834: return $js;
835: }
836:
1.160 raeburn 837: sub entry_form {
1.416 raeburn 838: my ($dom,$srch,$forcenewuser,$context,$responsemsg,$crstype,$fixeddom) = @_;
1.229 raeburn 839: my ($usertype,$inexact);
1.214 raeburn 840: if (ref($srch) eq 'HASH') {
841: if (($srch->{'srchin'} eq 'dom') &&
842: ($srch->{'srchby'} eq 'uname') &&
843: ($srch->{'srchtype'} eq 'exact') &&
844: ($srch->{'srchdomain'} ne '') &&
845: ($srch->{'srchterm'} ne '')) {
1.353 raeburn 846: my (%curr_rules,%got_rules);
1.214 raeburn 847: my ($rules,$ruleorder) =
848: &Apache::lonnet::inst_userrules($srch->{'srchdomain'},'username');
1.353 raeburn 849: $usertype = &Apache::lonuserutils::check_usertype($srch->{'srchdomain'},$srch->{'srchterm'},$rules,\%curr_rules,\%got_rules);
1.229 raeburn 850: } else {
851: $inexact = 1;
1.214 raeburn 852: }
1.207 raeburn 853: }
1.438 raeburn 854: my ($cancreate,$noinstd);
855: if ($env{'form.action'} eq 'accesslogs') {
856: $noinstd = 1;
857: } else {
858: $cancreate =
859: &Apache::lonuserutils::can_create_user($dom,$context,$usertype);
860: }
1.412 raeburn 861: my ($userpicker,$cansearch) =
1.179 raeburn 862: &Apache::loncommon::user_picker($dom,$srch,$forcenewuser,
1.438 raeburn 863: 'document.crtuser',$cancreate,$usertype,$context,$fixeddom,$noinstd);
1.160 raeburn 864: my $srchbutton = &mt('Search');
1.229 raeburn 865: if ($env{'form.action'} eq 'singlestudent') {
866: $srchbutton = &mt('Search and Enroll');
1.416 raeburn 867: } elsif ($env{'form.action'} eq 'accesslogs') {
868: $srchbutton = &mt('Search');
1.229 raeburn 869: } elsif ($cancreate && $responsemsg ne '' && $inexact) {
870: $srchbutton = &mt('Search or Add New User');
871: }
1.412 raeburn 872: my $output;
873: if ($cansearch) {
874: $output = <<"ENDBLOCK";
1.160 raeburn 875: <form action="/adm/createuser" method="post" name="crtuser">
1.190 raeburn 876: <input type="hidden" name="action" value="$env{'form.action'}" />
1.160 raeburn 877: <input type="hidden" name="phase" value="get_user_info" />
878: $userpicker
1.179 raeburn 879: <input name="userrole" type="button" value="$srchbutton" onclick="javascript:validateEntry(document.crtuser)" />
1.160 raeburn 880: </form>
1.207 raeburn 881: ENDBLOCK
1.412 raeburn 882: } else {
883: $output = '<p>'.$userpicker.'</p>';
884: }
1.422 raeburn 885: if (($env{'form.phase'} eq '') && ($env{'form.action'} ne 'accesslogs') &&
1.430 raeburn 886: (!(($env{'form.action'} eq 'singleuser') && ($context eq 'domain') &&
1.422 raeburn 887: (!&Apache::lonnet::allowed('mau',$env{'request.role.domain'}))))) {
1.207 raeburn 888: my $defdom=$env{'request.role.domain'};
889: my $domform = &Apache::loncommon::select_dom_form($defdom,'srchdomain');
890: my %lt=&Apache::lonlocal::texthash(
1.229 raeburn 891: 'enro' => 'Enroll one student',
1.318 raeburn 892: 'enrm' => 'Enroll one member',
1.229 raeburn 893: 'admo' => 'Add/modify a single user',
894: 'crea' => 'create new user if required',
895: 'uskn' => "username is known",
1.207 raeburn 896: 'crnu' => 'Create a new user',
897: 'usr' => 'Username',
898: 'dom' => 'in domain',
1.229 raeburn 899: 'enrl' => 'Enroll',
900: 'cram' => 'Create/Modify user',
1.207 raeburn 901: );
1.229 raeburn 902: my $sellink=&Apache::loncommon::selectstudent_link('crtusername','srchterm','srchdomain');
903: my ($title,$buttontext,$showresponse);
1.318 raeburn 904: if ($env{'form.action'} eq 'singlestudent') {
905: if ($crstype eq 'Community') {
906: $title = $lt{'enrm'};
907: } else {
908: $title = $lt{'enro'};
909: }
1.229 raeburn 910: $buttontext = $lt{'enrl'};
911: } else {
912: $title = $lt{'admo'};
913: $buttontext = $lt{'cram'};
914: }
915: if ($cancreate) {
916: $title .= ' <span class="LC_cusr_subheading">('.$lt{'crea'}.')</span>';
917: } else {
918: $title .= ' <span class="LC_cusr_subheading">('.$lt{'uskn'}.')</span>';
919: }
920: if ($env{'form.origform'} eq 'crtusername') {
921: $showresponse = $responsemsg;
922: }
1.207 raeburn 923: $output .= <<"ENDDOCUMENT";
1.229 raeburn 924: <br />
1.207 raeburn 925: <form action="/adm/createuser" method="post" name="crtusername">
926: <input type="hidden" name="action" value="$env{'form.action'}" />
927: <input type="hidden" name="phase" value="createnewuser" />
928: <input type="hidden" name="srchtype" value="exact" />
1.233 raeburn 929: <input type="hidden" name="srchby" value="uname" />
1.207 raeburn 930: <input type="hidden" name="srchin" value="dom" />
931: <input type="hidden" name="forcenewuser" value="1" />
932: <input type="hidden" name="origform" value="crtusername" />
1.229 raeburn 933: <h3>$title</h3>
934: $showresponse
1.207 raeburn 935: <table>
936: <tr>
937: <td>$lt{'usr'}:</td>
938: <td><input type="text" size="15" name="srchterm" /></td>
939: <td> $lt{'dom'}:</td><td>$domform</td>
1.229 raeburn 940: <td> $sellink </td>
941: <td> <input name="userrole" type="submit" value="$buttontext" /></td>
1.207 raeburn 942: </tr>
943: </table>
944: </form>
1.160 raeburn 945: ENDDOCUMENT
1.207 raeburn 946: }
1.160 raeburn 947: return $output;
948: }
1.110 albertel 949:
950: sub user_modification_js {
1.113 raeburn 951: my ($pjump_def,$dc_setcourse_code,$nondc_setsection_code,$groupslist)=@_;
952:
1.110 albertel 953: return <<END;
954: <script type="text/javascript" language="Javascript">
1.301 bisitz 955: // <![CDATA[
1.314 raeburn 956:
1.110 albertel 957: $pjump_def
958: $dc_setcourse_code
959:
960: function dateset() {
961: eval("document.cu."+document.cu.pres_marker.value+
962: ".value=document.cu.pres_value.value");
1.359 www 963: modalWindow.close();
1.110 albertel 964: }
965:
1.113 raeburn 966: $nondc_setsection_code
1.301 bisitz 967: // ]]>
1.110 albertel 968: </script>
969: END
1.2 www 970: }
971:
972: # =================================================================== Phase two
1.160 raeburn 973: sub print_user_selection_page {
1.351 raeburn 974: my ($r,$response,$srch,$srch_results,$srcharray,$context,$opener_elements,$crstype,$brcrum) = @_;
1.160 raeburn 975: my @fields = ('username','domain','lastname','firstname','permanentemail');
976: my $sortby = $env{'form.sortby'};
977:
978: if (!grep(/^\Q$sortby\E$/,@fields)) {
979: $sortby = 'lastname';
980: }
981:
982: my ($jsback,$elements) = &crumb_utilities();
983:
984: my $jscript = (<<ENDSCRIPT);
985: <script type="text/javascript">
1.301 bisitz 986: // <![CDATA[
1.160 raeburn 987: function pickuser(uname,udom) {
988: document.usersrchform.seluname.value=uname;
989: document.usersrchform.seludom.value=udom;
990: document.usersrchform.phase.value="userpicked";
991: document.usersrchform.submit();
992: }
993:
994: $jsback
1.301 bisitz 995: // ]]>
1.160 raeburn 996: </script>
997: ENDSCRIPT
998:
999: my %lt=&Apache::lonlocal::texthash(
1.179 raeburn 1000: 'usrch' => "User Search to add/modify roles",
1001: 'stusrch' => "User Search to enroll student",
1.318 raeburn 1002: 'memsrch' => "User Search to enroll member",
1.416 raeburn 1003: 'srcva' => "Search for a user and view access log information",
1.422 raeburn 1004: 'usrvu' => "User Search to view user roles",
1.179 raeburn 1005: 'usel' => "Select a user to add/modify roles",
1.422 raeburn 1006: 'suvr' => "Select a user to view roles",
1.318 raeburn 1007: 'stusel' => "Select a user to enroll as a student",
1008: 'memsel' => "Select a user to enroll as a member",
1.416 raeburn 1009: 'vacsel' => "Select a user to view access log",
1.160 raeburn 1010: 'username' => "username",
1011: 'domain' => "domain",
1012: 'lastname' => "last name",
1013: 'firstname' => "first name",
1014: 'permanentemail' => "permanent e-mail",
1015: );
1.302 raeburn 1016: if ($context eq 'requestcrs') {
1017: $r->print('<div>');
1018: } else {
1.422 raeburn 1019: my %breadcrumb_text = &singleuser_breadcrumb($crstype,$context,$srch->{'srchdomain'});
1.351 raeburn 1020: my $helpitem;
1021: if ($env{'form.action'} eq 'singleuser') {
1022: $helpitem = 'Course_Change_Privileges';
1023: } elsif ($env{'form.action'} eq 'singlestudent') {
1024: $helpitem = 'Course_Add_Student';
1.439 raeburn 1025: } elsif ($context eq 'author') {
1026: $helpitem = 'Author_Change_Privileges';
1027: } elsif ($context eq 'domain') {
1028: $helpitem = 'Domain_Change_Privileges';
1.351 raeburn 1029: }
1030: push (@{$brcrum},
1031: {href => "javascript:backPage(document.usersrchform,'','')",
1032: text => $breadcrumb_text{'search'},
1033: faq => 282,
1034: bug => 'Instructor Interface',},
1035: {href => "javascript:backPage(document.usersrchform,'get_user_info','select')",
1036: text => $breadcrumb_text{'userpicked'},
1037: faq => 282,
1038: bug => 'Instructor Interface',
1039: help => $helpitem}
1040: );
1041: $r->print(&Apache::loncommon::start_page('User Management',$jscript,{bread_crumbs => $brcrum}));
1.302 raeburn 1042: if ($env{'form.action'} eq 'singleuser') {
1.422 raeburn 1043: my $readonly;
1044: if (($context eq 'domain') && (!&Apache::lonnet::allowed('mau',$srch->{'srchdomain'}))) {
1045: $readonly = 1;
1046: $r->print("<b>$lt{'usrvu'}</b><br />");
1047: } else {
1048: $r->print("<b>$lt{'usrch'}</b><br />");
1049: }
1.318 raeburn 1050: $r->print(&entry_form($srch->{'srchdomain'},$srch,undef,$context,undef,$crstype));
1.422 raeburn 1051: if ($readonly) {
1052: $r->print('<h3>'.$lt{'suvr'}.'</h3>');
1053: } else {
1054: $r->print('<h3>'.$lt{'usel'}.'</h3>');
1055: }
1.302 raeburn 1056: } elsif ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1057: $r->print($jscript."<b>");
1058: if ($crstype eq 'Community') {
1059: $r->print($lt{'memsrch'});
1060: } else {
1061: $r->print($lt{'stusrch'});
1062: }
1063: $r->print("</b><br />");
1064: $r->print(&entry_form($srch->{'srchdomain'},$srch,undef,$context,undef,$crstype));
1065: $r->print('</form><h3>');
1066: if ($crstype eq 'Community') {
1067: $r->print($lt{'memsel'});
1068: } else {
1069: $r->print($lt{'stusel'});
1070: }
1071: $r->print('</h3>');
1.416 raeburn 1072: } elsif ($env{'form.action'} eq 'accesslogs') {
1073: $r->print("<b>$lt{'srcva'}</b><br />");
1.438 raeburn 1074: $r->print(&entry_form($srch->{'srchdomain'},$srch,undef,$context,undef,undef,1));
1.416 raeburn 1075: $r->print('<h3>'.$lt{'vacsel'}.'</h3>');
1.302 raeburn 1076: }
1.179 raeburn 1077: }
1.380 bisitz 1078: $r->print('<form name="usersrchform" method="post" action="">'.
1.160 raeburn 1079: &Apache::loncommon::start_data_table()."\n".
1080: &Apache::loncommon::start_data_table_header_row()."\n".
1081: ' <th> </th>'."\n");
1082: foreach my $field (@fields) {
1083: $r->print(' <th><a href="javascript:document.usersrchform.sortby.value='.
1084: "'".$field."'".';document.usersrchform.submit();">'.
1085: $lt{$field}.'</a></th>'."\n");
1086: }
1087: $r->print(&Apache::loncommon::end_data_table_header_row());
1088:
1089: my @sorted_users = sort {
1.167 albertel 1090: lc($srch_results->{$a}->{$sortby}) cmp lc($srch_results->{$b}->{$sortby})
1.160 raeburn 1091: ||
1.167 albertel 1092: lc($srch_results->{$a}->{lastname}) cmp lc($srch_results->{$b}->{lastname})
1.160 raeburn 1093: ||
1094: lc($srch_results->{$a}->{firstname}) cmp lc($srch_results->{$b}->{firstname})
1.167 albertel 1095: ||
1096: lc($a) cmp lc($b)
1.160 raeburn 1097: } (keys(%$srch_results));
1098:
1099: foreach my $user (@sorted_users) {
1100: my ($uname,$udom) = split(/:/,$user);
1.302 raeburn 1101: my $onclick;
1102: if ($context eq 'requestcrs') {
1.314 raeburn 1103: $onclick =
1.302 raeburn 1104: 'onclick="javascript:gochoose('."'$uname','$udom',".
1105: "'$srch_results->{$user}->{firstname}',".
1106: "'$srch_results->{$user}->{lastname}',".
1107: "'$srch_results->{$user}->{permanentemail}'".');"';
1108: } else {
1.314 raeburn 1109: $onclick =
1.302 raeburn 1110: ' onclick="javascript:pickuser('."'".$uname."'".','."'".$udom."'".');"';
1111: }
1.160 raeburn 1112: $r->print(&Apache::loncommon::start_data_table_row().
1.302 raeburn 1113: '<td><input type="button" name="seluser" value="'.&mt('Select').'" '.
1114: $onclick.' /></td>'.
1.160 raeburn 1115: '<td><tt>'.$uname.'</tt></td>'.
1116: '<td><tt>'.$udom.'</tt></td>');
1117: foreach my $field ('lastname','firstname','permanentemail') {
1118: $r->print('<td>'.$srch_results->{$user}->{$field}.'</td>');
1119: }
1120: $r->print(&Apache::loncommon::end_data_table_row());
1121: }
1122: $r->print(&Apache::loncommon::end_data_table().'<br /><br />');
1.179 raeburn 1123: if (ref($srcharray) eq 'ARRAY') {
1124: foreach my $item (@{$srcharray}) {
1125: $r->print('<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n");
1126: }
1127: }
1.160 raeburn 1128: $r->print(' <input type="hidden" name="sortby" value="'.$sortby.'" />'."\n".
1129: ' <input type="hidden" name="seluname" value="" />'."\n".
1130: ' <input type="hidden" name="seludom" value="" />'."\n".
1.179 raeburn 1131: ' <input type="hidden" name="currstate" value="select" />'."\n".
1.190 raeburn 1132: ' <input type="hidden" name="phase" value="get_user_info" />'."\n".
1.214 raeburn 1133: ' <input type="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n");
1.302 raeburn 1134: if ($context eq 'requestcrs') {
1135: $r->print($opener_elements.'</form></div>');
1136: } else {
1.351 raeburn 1137: $r->print($response.'</form>');
1.302 raeburn 1138: }
1.160 raeburn 1139: }
1140:
1141: sub print_user_query_page {
1.351 raeburn 1142: my ($r,$caller,$brcrum) = @_;
1.160 raeburn 1143: # FIXME - this is for a network-wide name search (similar to catalog search)
1144: # To use frames with similar behavior to catalog/portfolio search.
1145: # To be implemented.
1146: return;
1147: }
1148:
1.42 matthew 1149: sub print_user_modification_page {
1.375 raeburn 1150: my ($r,$ccuname,$ccdomain,$srch,$response,$context,$permission,$crstype,
1151: $brcrum,$showcredits) = @_;
1.185 raeburn 1152: if (($ccuname eq '') || ($ccdomain eq '')) {
1.215 raeburn 1153: my $usermsg = &mt('No username and/or domain provided.');
1154: $env{'form.phase'} = '';
1.439 raeburn 1155: &print_username_entry_form($r,$context,$usermsg,'','',$crstype,$brcrum,
1156: $permission);
1.58 www 1157: return;
1158: }
1.213 raeburn 1159: my ($form,$formname);
1160: if ($env{'form.action'} eq 'singlestudent') {
1161: $form = 'document.enrollstudent';
1162: $formname = 'enrollstudent';
1163: } else {
1164: $form = 'document.cu';
1165: $formname = 'cu';
1166: }
1.188 raeburn 1167: my %abv_auth = &auth_abbrev();
1.227 raeburn 1168: my (%rulematch,%inst_results,$newuser,%alerts,%curr_rules,%got_rules);
1.185 raeburn 1169: my $uhome=&Apache::lonnet::homeserver($ccuname,$ccdomain);
1170: if ($uhome eq 'no_host') {
1.215 raeburn 1171: my $usertype;
1172: my ($rules,$ruleorder) =
1173: &Apache::lonnet::inst_userrules($ccdomain,'username');
1174: $usertype =
1.353 raeburn 1175: &Apache::lonuserutils::check_usertype($ccdomain,$ccuname,$rules,
1.362 raeburn 1176: \%curr_rules,\%got_rules);
1.215 raeburn 1177: my $cancreate =
1178: &Apache::lonuserutils::can_create_user($ccdomain,$context,
1179: $usertype);
1180: if (!$cancreate) {
1.292 bisitz 1181: my $helplink = 'javascript:helpMenu('."'display'".')';
1.215 raeburn 1182: my %usertypetext = (
1183: official => 'institutional',
1184: unofficial => 'non-institutional',
1185: );
1186: my $response;
1187: if ($env{'form.origform'} eq 'crtusername') {
1.362 raeburn 1188: $response = '<span class="LC_warning">'.
1189: &mt('No match found for the username [_1] in LON-CAPA domain: [_2]',
1190: '<b>'.$ccuname.'</b>',$ccdomain).
1.215 raeburn 1191: '</span><br />';
1192: }
1.292 bisitz 1193: $response .= '<p class="LC_warning">'
1194: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
1.418 raeburn 1195: .' ';
1196: if ($context eq 'domain') {
1197: $response .= &mt('Please contact a [_1] for assistance.',
1198: &Apache::lonnet::plaintext('dc'));
1199: } else {
1200: $response .= &mt('Please contact the [_1]helpdesk[_2] for assistance.'
1201: ,'<a href="'.$helplink.'">','</a>');
1202: }
1203: $response .= '</p><br />';
1.215 raeburn 1204: $env{'form.phase'} = '';
1.439 raeburn 1205: &print_username_entry_form($r,$context,$response,undef,undef,$crstype,$brcrum,
1206: $permission);
1.215 raeburn 1207: return;
1208: }
1.188 raeburn 1209: $newuser = 1;
1.193 raeburn 1210: my $checkhash;
1211: my $checks = { 'username' => 1 };
1.196 raeburn 1212: $checkhash->{$ccuname.':'.$ccdomain} = { 'newuser' => $newuser };
1.193 raeburn 1213: &Apache::loncommon::user_rule_check($checkhash,$checks,
1.196 raeburn 1214: \%alerts,\%rulematch,\%inst_results,\%curr_rules,\%got_rules);
1215: if (ref($alerts{'username'}) eq 'HASH') {
1216: if (ref($alerts{'username'}{$ccdomain}) eq 'HASH') {
1217: my $domdesc =
1.193 raeburn 1218: &Apache::lonnet::domain($ccdomain,'description');
1.196 raeburn 1219: if ($alerts{'username'}{$ccdomain}{$ccuname}) {
1220: my $userchkmsg;
1221: if (ref($curr_rules{$ccdomain}) eq 'HASH') {
1222: $userchkmsg =
1223: &Apache::loncommon::instrule_disallow_msg('username',
1.193 raeburn 1224: $domdesc,1).
1225: &Apache::loncommon::user_rule_formats($ccdomain,
1226: $domdesc,$curr_rules{$ccdomain}{'username'},
1227: 'username');
1.196 raeburn 1228: }
1.215 raeburn 1229: $env{'form.phase'} = '';
1.439 raeburn 1230: &print_username_entry_form($r,$context,$userchkmsg,undef,undef,$crstype,$brcrum,
1231: $permission);
1.196 raeburn 1232: return;
1.215 raeburn 1233: }
1.193 raeburn 1234: }
1.185 raeburn 1235: }
1.187 raeburn 1236: } else {
1.188 raeburn 1237: $newuser = 0;
1.185 raeburn 1238: }
1.160 raeburn 1239: if ($response) {
1.215 raeburn 1240: $response = '<br />'.$response;
1.160 raeburn 1241: }
1.149 raeburn 1242:
1.52 matthew 1243: my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
1.88 raeburn 1244: my $dc_setcourse_code = '';
1.119 raeburn 1245: my $nondc_setsection_code = '';
1.112 albertel 1246: my %loaditem;
1.114 albertel 1247:
1.216 raeburn 1248: my $groupslist = &Apache::lonuserutils::get_groupslist();
1.88 raeburn 1249:
1.375 raeburn 1250: my $js = &validation_javascript($context,$ccdomain,$pjump_def,$crstype,
1.216 raeburn 1251: $groupslist,$newuser,$formname,\%loaditem);
1.422 raeburn 1252: my %breadcrumb_text = &singleuser_breadcrumb($crstype,$context,$ccdomain);
1.224 raeburn 1253: my $helpitem = 'Course_Change_Privileges';
1254: if ($env{'form.action'} eq 'singlestudent') {
1255: $helpitem = 'Course_Add_Student';
1.439 raeburn 1256: } elsif ($context eq 'author') {
1257: $helpitem = 'Author_Change_Privileges';
1258: } elsif ($context eq 'domain') {
1259: $helpitem = 'Domain_Change_Privileges';
1.224 raeburn 1260: }
1.351 raeburn 1261: push (@{$brcrum},
1262: {href => "javascript:backPage($form)",
1263: text => $breadcrumb_text{'search'},
1264: faq => 282,
1265: bug => 'Instructor Interface',});
1266: if ($env{'form.phase'} eq 'userpicked') {
1267: push(@{$brcrum},
1268: {href => "javascript:backPage($form,'get_user_info','select')",
1269: text => $breadcrumb_text{'userpicked'},
1270: faq => 282,
1271: bug => 'Instructor Interface',});
1272: }
1273: push(@{$brcrum},
1274: {href => "javascript:backPage($form,'$env{'form.phase'}','modify')",
1275: text => $breadcrumb_text{'modify'},
1276: faq => 282,
1277: bug => 'Instructor Interface',
1278: help => $helpitem});
1279: my $args = {'add_entries' => \%loaditem,
1280: 'bread_crumbs' => $brcrum,
1281: 'bread_crumbs_component' => 'User Management'};
1282: if ($env{'form.popup'}) {
1283: $args->{'no_nav_bar'} = 1;
1284: }
1285: my $start_page =
1286: &Apache::loncommon::start_page('User Management',$js,$args);
1.3 www 1287:
1.25 matthew 1288: my $forminfo =<<"ENDFORMINFO";
1.216 raeburn 1289: <form action="/adm/createuser" method="post" name="$formname">
1.190 raeburn 1290: <input type="hidden" name="phase" value="update_user_data" />
1.188 raeburn 1291: <input type="hidden" name="ccuname" value="$ccuname" />
1292: <input type="hidden" name="ccdomain" value="$ccdomain" />
1.157 albertel 1293: <input type="hidden" name="pres_value" value="" />
1294: <input type="hidden" name="pres_type" value="" />
1295: <input type="hidden" name="pres_marker" value="" />
1.25 matthew 1296: ENDFORMINFO
1.375 raeburn 1297: my (%inccourses,$roledom,$defaultcredits);
1.329 raeburn 1298: if ($context eq 'course') {
1299: $inccourses{$env{'request.course.id'}}=1;
1300: $roledom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1.375 raeburn 1301: if ($showcredits) {
1302: $defaultcredits = &Apache::lonuserutils::get_defaultcredits();
1303: }
1.329 raeburn 1304: } elsif ($context eq 'author') {
1305: $roledom = $env{'request.role.domain'};
1306: } elsif ($context eq 'domain') {
1307: foreach my $key (keys(%env)) {
1308: $roledom = $env{'request.role.domain'};
1309: if ($key=~/^user\.priv\.cm\.\/($roledom)\/($match_username)/) {
1310: $inccourses{$1.'_'.$2}=1;
1311: }
1312: }
1313: } else {
1314: foreach my $key (keys(%env)) {
1315: if ($key=~/^user\.priv\.cm\.\/($match_domain)\/($match_username)/) {
1316: $inccourses{$1.'_'.$2}=1;
1317: }
1.2 www 1318: }
1.24 matthew 1319: }
1.389 bisitz 1320: my $title = '';
1.216 raeburn 1321: if ($newuser) {
1.427 raeburn 1322: my ($portfolioform,$domroleform);
1.267 raeburn 1323: if ((&Apache::lonnet::allowed('mpq',$env{'request.role.domain'})) ||
1324: (&Apache::lonnet::allowed('mut',$env{'request.role.domain'}))) {
1325: # Current user has quota or user tools modification privileges
1.378 raeburn 1326: $portfolioform = '<br />'.&user_quotas($ccuname,$ccdomain);
1.134 raeburn 1327: }
1.383 raeburn 1328: if ((&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) &&
1329: ($ccdomain eq $env{'request.role.domain'})) {
1.362 raeburn 1330: $domroleform = '<br />'.&domainrole_req($ccuname,$ccdomain);
1331: }
1.227 raeburn 1332: &initialize_authen_forms($ccdomain,$formname);
1.188 raeburn 1333: my %lt=&Apache::lonlocal::texthash(
1334: 'lg' => 'Login Data',
1.190 raeburn 1335: 'hs' => "Home Server",
1.188 raeburn 1336: );
1.185 raeburn 1337: $r->print(<<ENDTITLE);
1.110 albertel 1338: $start_page
1.160 raeburn 1339: $response
1.25 matthew 1340: $forminfo
1.31 matthew 1341: <script type="text/javascript" language="Javascript">
1.301 bisitz 1342: // <![CDATA[
1.20 harris41 1343: $loginscript
1.301 bisitz 1344: // ]]>
1.31 matthew 1345: </script>
1.20 harris41 1346: <input type='hidden' name='makeuser' value='1' />
1.185 raeburn 1347: ENDTITLE
1.213 raeburn 1348: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1349: if ($crstype eq 'Community') {
1.389 bisitz 1350: $title = &mt('Create New User [_1] in domain [_2] as a member',
1351: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.318 raeburn 1352: } else {
1.389 bisitz 1353: $title = &mt('Create New User [_1] in domain [_2] as a student',
1354: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.318 raeburn 1355: }
1.389 bisitz 1356: } else {
1357: $title = &mt('Create New User [_1] in domain [_2]',
1358: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.213 raeburn 1359: }
1.389 bisitz 1360: $r->print('<h2>'.$title.'</h2>'."\n");
1361: $r->print('<div class="LC_left_float">');
1.393 raeburn 1362: $r->print(&personal_data_display($ccuname,$ccdomain,$newuser,$context,
1363: $inst_results{$ccuname.':'.$ccdomain}));
1364: # Option to disable student/employee ID conflict checking not offerred for new users.
1.187 raeburn 1365: my ($home_server_pick,$numlib) =
1366: &Apache::loncommon::home_server_form_item($ccdomain,'hserver',
1367: 'default','hide');
1368: if ($numlib > 1) {
1369: $r->print("
1.185 raeburn 1370: <br />
1.187 raeburn 1371: $lt{'hs'}: $home_server_pick
1372: <br />");
1373: } else {
1374: $r->print($home_server_pick);
1375: }
1.304 raeburn 1376: if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
1.362 raeburn 1377: $r->print('<br /><h3>'.
1378: &mt('User Can Request Creation of Courses/Communities in this Domain?').'</h3>'.
1.304 raeburn 1379: &Apache::loncommon::start_data_table().
1380: &build_tools_display($ccuname,$ccdomain,
1381: 'requestcourses').
1382: &Apache::loncommon::end_data_table());
1383: }
1.188 raeburn 1384: $r->print('</div>'."\n".'<div class="LC_left_float"><h3>'.
1385: $lt{'lg'}.'</h3>');
1.185 raeburn 1386: my ($fixedauth,$varauth,$authmsg);
1.193 raeburn 1387: if (ref($rulematch{$ccuname.':'.$ccdomain}) eq 'HASH') {
1388: my $matchedrule = $rulematch{$ccuname.':'.$ccdomain}{'username'};
1389: my ($rules,$ruleorder) =
1390: &Apache::lonnet::inst_userrules($ccdomain,'username');
1.185 raeburn 1391: if (ref($rules) eq 'HASH') {
1.193 raeburn 1392: if (ref($rules->{$matchedrule}) eq 'HASH') {
1393: my $authtype = $rules->{$matchedrule}{'authtype'};
1.185 raeburn 1394: if ($authtype !~ /^(krb4|krb5|int|fsys|loc)$/) {
1.190 raeburn 1395: $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1.275 raeburn 1396: } else {
1.193 raeburn 1397: my $authparm = $rules->{$matchedrule}{'authparm'};
1.273 raeburn 1398: $authmsg = $rules->{$matchedrule}{'authmsg'};
1.185 raeburn 1399: if ($authtype =~ /^krb(4|5)$/) {
1400: my $ver = $1;
1401: if ($authparm ne '') {
1402: $fixedauth = <<"KERB";
1403: <input type="hidden" name="login" value="krb" />
1404: <input type="hidden" name="krbver" value="$ver" />
1405: <input type="hidden" name="krbarg" value="$authparm" />
1406: KERB
1407: }
1408: } else {
1409: $fixedauth =
1410: '<input type="hidden" name="login" value="'.$authtype.'" />'."\n";
1.193 raeburn 1411: if ($rules->{$matchedrule}{'authparmfixed'}) {
1.185 raeburn 1412: $fixedauth .=
1413: '<input type="hidden" name="'.$authtype.'arg" value="'.$authparm.'" />'."\n";
1414: } else {
1.273 raeburn 1415: if ($authtype eq 'int') {
1416: $varauth = '<br />'.
1.301 bisitz 1417: &mt('[_1] Internally authenticated (with initial password [_2])','','<input type="password" size="10" name="intarg" value="" />')."<label><input type=\"checkbox\" name=\"visible\" onclick='if (this.checked) { this.form.intarg.type=\"text\" } else { this.form.intarg.type=\"password\" }' />".&mt('Visible input').'</label>';
1.273 raeburn 1418: } elsif ($authtype eq 'loc') {
1419: $varauth = '<br />'.
1420: &mt('[_1] Local Authentication with argument [_2]','','<input type="text" name="'.$authtype.'arg" value="" />')."\n";
1421: } else {
1422: $varauth =
1.185 raeburn 1423: '<input type="text" name="'.$authtype.'arg" value="" />'."\n";
1.273 raeburn 1424: }
1.185 raeburn 1425: }
1426: }
1427: }
1428: } else {
1.190 raeburn 1429: $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1.185 raeburn 1430: }
1431: }
1432: if ($authmsg) {
1433: $r->print(<<ENDAUTH);
1434: $fixedauth
1435: $authmsg
1436: $varauth
1437: ENDAUTH
1438: }
1439: } else {
1.190 raeburn 1440: $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1.187 raeburn 1441: }
1.427 raeburn 1442: $r->print($portfolioform.$domroleform);
1.215 raeburn 1443: if ($env{'form.action'} eq 'singlestudent') {
1444: $r->print(&date_sections_select($context,$newuser,$formname,
1.375 raeburn 1445: $permission,$crstype,$ccuname,
1446: $ccdomain,$showcredits));
1.215 raeburn 1447: }
1448: $r->print('</div><div class="LC_clear_float_footer"></div>');
1.216 raeburn 1449: } else { # user already exists
1.389 bisitz 1450: $r->print($start_page.$forminfo);
1.213 raeburn 1451: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1452: if ($crstype eq 'Community') {
1.389 bisitz 1453: $title = &mt('Enroll one member: [_1] in domain [_2]',
1454: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.318 raeburn 1455: } else {
1.389 bisitz 1456: $title = &mt('Enroll one student: [_1] in domain [_2]',
1457: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.318 raeburn 1458: }
1.213 raeburn 1459: } else {
1.418 raeburn 1460: if ($permission->{'cusr'}) {
1461: $title = &mt('Modify existing user: [_1] in domain [_2]',
1462: '"'.$ccuname.'"','"'.$ccdomain.'"');
1463: } else {
1464: $title = &mt('Existing user: [_1] in domain [_2]',
1.389 bisitz 1465: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.418 raeburn 1466: }
1.213 raeburn 1467: }
1.389 bisitz 1468: $r->print('<h2>'.$title.'</h2>'."\n");
1469: $r->print('<div class="LC_left_float">');
1.393 raeburn 1470: $r->print(&personal_data_display($ccuname,$ccdomain,$newuser,$context,
1471: $inst_results{$ccuname.':'.$ccdomain}));
1.430 raeburn 1472: if ((&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) ||
1.418 raeburn 1473: (&Apache::lonnet::allowed('udp',$env{'request.role.domain'}))) {
1.362 raeburn 1474: $r->print('<br /><h3>'.&mt('User Can Request Creation of Courses/Communities in this Domain?').'</h3>'.
1.300 raeburn 1475: &Apache::loncommon::start_data_table());
1.314 raeburn 1476: if ($env{'request.role.domain'} eq $ccdomain) {
1.300 raeburn 1477: $r->print(&build_tools_display($ccuname,$ccdomain,'requestcourses'));
1478: } else {
1479: $r->print(&coursereq_externaluser($ccuname,$ccdomain,
1480: $env{'request.role.domain'}));
1481: }
1482: $r->print(&Apache::loncommon::end_data_table());
1.275 raeburn 1483: }
1.199 raeburn 1484: $r->print('</div>');
1.427 raeburn 1485: my @order = ('auth','quota','tools','requestauthor');
1.362 raeburn 1486: my %user_text;
1487: my ($isadv,$isauthor) =
1.418 raeburn 1488: &Apache::lonnet::is_advanced_user($ccdomain,$ccuname);
1.362 raeburn 1489: if ((!$isauthor) &&
1.418 raeburn 1490: ((&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) ||
1491: (&Apache::lonnet::allowed('udp',$env{'request.role.domain'}))) &&
1.430 raeburn 1492: ($env{'request.role.domain'} eq $ccdomain)) {
1.362 raeburn 1493: $user_text{'requestauthor'} = &domainrole_req($ccuname,$ccdomain);
1494: }
1495: $user_text{'auth'} = &user_authentication($ccuname,$ccdomain,$formname);
1.267 raeburn 1496: if ((&Apache::lonnet::allowed('mpq',$ccdomain)) ||
1.418 raeburn 1497: (&Apache::lonnet::allowed('mut',$ccdomain)) ||
1498: (&Apache::lonnet::allowed('udp',$ccdomain))) {
1.188 raeburn 1499: # Current user has quota modification privileges
1.378 raeburn 1500: $user_text{'quota'} = &user_quotas($ccuname,$ccdomain);
1.267 raeburn 1501: }
1502: if (!&Apache::lonnet::allowed('mpq',$ccdomain)) {
1503: if (&Apache::lonnet::allowed('mpq',$env{'request.role.domain'})) {
1504: my %lt=&Apache::lonlocal::texthash(
1.385 bisitz 1505: 'dska' => "Disk quotas for user's portfolio and Authoring Space",
1506: 'youd' => "You do not have privileges to modify the portfolio and/or Authoring Space quotas for this user.",
1.267 raeburn 1507: 'ichr' => "If a change is required, contact a domain coordinator for the domain",
1508: );
1.362 raeburn 1509: $user_text{'quota'} = <<ENDNOPORTPRIV;
1.188 raeburn 1510: <h3>$lt{'dska'}</h3>
1511: $lt{'youd'} $lt{'ichr'}: $ccdomain
1512: ENDNOPORTPRIV
1.267 raeburn 1513: }
1514: }
1515: if (!&Apache::lonnet::allowed('mut',$ccdomain)) {
1516: if (&Apache::lonnet::allowed('mut',$env{'request.role.domain'})) {
1517: my %lt=&Apache::lonlocal::texthash(
1518: 'utav' => "User Tools Availability",
1.361 raeburn 1519: 'yodo' => "You do not have privileges to modify Portfolio, Blog, WebDAV, or Personal Information Page settings for this user.",
1.267 raeburn 1520: 'ifch' => "If a change is required, contact a domain coordinator for the domain",
1521: );
1.362 raeburn 1522: $user_text{'tools'} = <<ENDNOTOOLSPRIV;
1.267 raeburn 1523: <h3>$lt{'utav'}</h3>
1524: $lt{'yodo'} $lt{'ifch'}: $ccdomain
1525: ENDNOTOOLSPRIV
1526: }
1.188 raeburn 1527: }
1.362 raeburn 1528: my $gotdiv = 0;
1529: foreach my $item (@order) {
1530: if ($user_text{$item} ne '') {
1531: unless ($gotdiv) {
1532: $r->print('<div class="LC_left_float">');
1533: $gotdiv = 1;
1534: }
1535: $r->print('<br />'.$user_text{$item});
1536: }
1537: }
1538: if ($env{'form.action'} eq 'singlestudent') {
1539: unless ($gotdiv) {
1540: $r->print('<div class="LC_left_float">');
1.213 raeburn 1541: }
1.375 raeburn 1542: my $credits;
1543: if ($showcredits) {
1544: $credits = &get_user_credits($ccuname,$ccdomain,$defaultcredits);
1545: if ($credits eq '') {
1546: $credits = $defaultcredits;
1547: }
1548: }
1.374 raeburn 1549: $r->print(&date_sections_select($context,$newuser,$formname,
1.375 raeburn 1550: $permission,$crstype,$ccuname,
1551: $ccdomain,$showcredits));
1.374 raeburn 1552: }
1.362 raeburn 1553: if ($gotdiv) {
1554: $r->print('</div><div class="LC_clear_float_footer"></div>');
1.188 raeburn 1555: }
1.418 raeburn 1556: my $statuses;
1557: if (($context eq 'domain') && (&Apache::lonnet::allowed('udp',$ccdomain)) &&
1558: (!&Apache::lonnet::allowed('mau',$ccdomain))) {
1559: $statuses = ['active'];
1560: } elsif (($context eq 'course') && ((&Apache::lonnet::allowed('vcl',$env{'request.course.id'})) ||
1561: ($env{'request.course.sec'} &&
1562: &Apache::lonnet::allowed('vcl',$env{'request.course.id'}.'/'.$env{'request.course.sec'})))) {
1.430 raeburn 1563: $statuses = ['active'];
1.418 raeburn 1564: }
1.217 raeburn 1565: if ($env{'form.action'} ne 'singlestudent') {
1.329 raeburn 1566: &display_existing_roles($r,$ccuname,$ccdomain,\%inccourses,$context,
1.418 raeburn 1567: $roledom,$crstype,$showcredits,$statuses);
1.217 raeburn 1568: }
1.25 matthew 1569: } ## End of new user/old user logic
1.218 raeburn 1570: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1571: my $btntxt;
1572: if ($crstype eq 'Community') {
1573: $btntxt = &mt('Enroll Member');
1574: } else {
1575: $btntxt = &mt('Enroll Student');
1576: }
1577: $r->print('<br /><input type="button" value="'.$btntxt.'" onclick="setSections(this.form)" />'."\n");
1.418 raeburn 1578: } elsif ($permission->{'cusr'}) {
1.393 raeburn 1579: $r->print('<div class="LC_left_float">'.
1580: '<fieldset><legend>'.&mt('Add Roles').'</legend>');
1.218 raeburn 1581: my $addrolesdisplay = 0;
1582: if ($context eq 'domain' || $context eq 'author') {
1583: $addrolesdisplay = &new_coauthor_roles($r,$ccuname,$ccdomain);
1584: }
1585: if ($context eq 'domain') {
1.357 raeburn 1586: my $add_domainroles = &new_domain_roles($r,$ccdomain);
1.218 raeburn 1587: if (!$addrolesdisplay) {
1588: $addrolesdisplay = $add_domainroles;
1.2 www 1589: }
1.375 raeburn 1590: $r->print(&course_level_dc($env{'request.role.domain'},$showcredits));
1.393 raeburn 1591: $r->print('</fieldset></div><div class="LC_clear_float_footer"></div>'.
1592: '<br /><input type="button" value="'.&mt('Save').'" onclick="setCourse()" />'."\n");
1.218 raeburn 1593: } elsif ($context eq 'author') {
1594: if ($addrolesdisplay) {
1.393 raeburn 1595: $r->print('</fieldset></div><div class="LC_clear_float_footer"></div>'.
1596: '<br /><input type="button" value="'.&mt('Save').'"');
1.218 raeburn 1597: if ($newuser) {
1.301 bisitz 1598: $r->print(' onclick="auth_check()" \>'."\n");
1.218 raeburn 1599: } else {
1.301 bisitz 1600: $r->print('onclick="this.form.submit()" \>'."\n");
1.218 raeburn 1601: }
1.188 raeburn 1602: } else {
1.393 raeburn 1603: $r->print('</fieldset></div>'.
1604: '<div class="LC_clear_float_footer"></div>'.
1605: '<br /><a href="javascript:backPage(document.cu)">'.
1.218 raeburn 1606: &mt('Back to previous page').'</a>');
1.188 raeburn 1607: }
1608: } else {
1.375 raeburn 1609: $r->print(&course_level_table(\%inccourses,$showcredits,$defaultcredits));
1.393 raeburn 1610: $r->print('</fieldset></div><div class="LC_clear_float_footer"></div>'.
1611: '<br /><input type="button" value="'.&mt('Save').'" onclick="setSections(this.form)" />'."\n");
1.188 raeburn 1612: }
1.88 raeburn 1613: }
1.188 raeburn 1614: $r->print(&Apache::lonhtmlcommon::echo_form_input(['phase','userrole','ccdomain','prevphase','currstate','ccuname','ccdomain']));
1.179 raeburn 1615: $r->print('<input type="hidden" name="currstate" value="" />');
1.393 raeburn 1616: $r->print('<input type="hidden" name="prevphase" value="'.$env{'form.phase'}.'" /></form><br /><br />');
1.218 raeburn 1617: return;
1.2 www 1618: }
1.1 www 1619:
1.213 raeburn 1620: sub singleuser_breadcrumb {
1.422 raeburn 1621: my ($crstype,$context,$domain) = @_;
1.213 raeburn 1622: my %breadcrumb_text;
1623: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1624: if ($crstype eq 'Community') {
1625: $breadcrumb_text{'search'} = 'Enroll a member';
1626: } else {
1627: $breadcrumb_text{'search'} = 'Enroll a student';
1628: }
1.422 raeburn 1629: $breadcrumb_text{'userpicked'} = 'Select a user';
1630: $breadcrumb_text{'modify'} = 'Set section/dates';
1.416 raeburn 1631: } elsif ($env{'form.action'} eq 'accesslogs') {
1632: $breadcrumb_text{'search'} = 'View access logs for a user';
1.422 raeburn 1633: $breadcrumb_text{'userpicked'} = 'Select a user';
1634: $breadcrumb_text{'activity'} = 'Activity';
1635: } elsif (($env{'form.action'} eq 'singleuser') && ($context eq 'domain') &&
1636: (!&Apache::lonnet::allowed('mau',$domain))) {
1637: $breadcrumb_text{'search'} = "View user's roles";
1638: $breadcrumb_text{'userpicked'} = 'Select a user';
1639: $breadcrumb_text{'modify'} = 'User roles';
1.213 raeburn 1640: } else {
1.229 raeburn 1641: $breadcrumb_text{'search'} = 'Create/modify a user';
1.422 raeburn 1642: $breadcrumb_text{'userpicked'} = 'Select a user';
1643: $breadcrumb_text{'modify'} = 'Set user role';
1.213 raeburn 1644: }
1645: return %breadcrumb_text;
1646: }
1647:
1648: sub date_sections_select {
1.375 raeburn 1649: my ($context,$newuser,$formname,$permission,$crstype,$ccuname,$ccdomain,
1650: $showcredits) = @_;
1651: my $credits;
1652: if ($showcredits) {
1653: my $defaultcredits = &Apache::lonuserutils::get_defaultcredits();
1654: $credits = &get_user_credits($ccuname,$ccdomain,$defaultcredits);
1655: if ($credits eq '') {
1656: $credits = $defaultcredits;
1657: }
1658: }
1.213 raeburn 1659: my $cid = $env{'request.course.id'};
1660: my ($cnum,$cdom) = &Apache::lonuserutils::get_course_identity($cid);
1661: my $date_table = '<h3>'.&mt('Starting and Ending Dates').'</h3>'."\n".
1662: &Apache::lonuserutils::date_setting_table(undef,undef,$context,
1663: undef,$formname,$permission);
1664: my $rowtitle = 'Section';
1.375 raeburn 1665: my $secbox = '<h3>'.&mt('Section and Credits').'</h3>'."\n".
1.213 raeburn 1666: &Apache::lonuserutils::section_picker($cdom,$cnum,'st',$rowtitle,
1.375 raeburn 1667: $permission,$context,'',$crstype,
1668: $showcredits,$credits);
1.213 raeburn 1669: my $output = $date_table.$secbox;
1670: return $output;
1671: }
1672:
1.216 raeburn 1673: sub validation_javascript {
1.375 raeburn 1674: my ($context,$ccdomain,$pjump_def,$crstype,$groupslist,$newuser,$formname,
1.216 raeburn 1675: $loaditem) = @_;
1676: my $dc_setcourse_code = '';
1677: my $nondc_setsection_code = '';
1678: if ($context eq 'domain') {
1679: my $dcdom = $env{'request.role.domain'};
1680: $loaditem->{'onload'} = "document.cu.coursedesc.value='';";
1.227 raeburn 1681: $dc_setcourse_code =
1682: &Apache::lonuserutils::dc_setcourse_js('cu','singleuser',$context);
1.216 raeburn 1683: } else {
1.227 raeburn 1684: my $checkauth;
1685: if (($newuser) || (&Apache::lonnet::allowed('mau',$ccdomain))) {
1686: $checkauth = 1;
1687: }
1688: if ($context eq 'course') {
1689: $nondc_setsection_code =
1690: &Apache::lonuserutils::setsections_javascript($formname,$groupslist,
1.375 raeburn 1691: undef,$checkauth,
1692: $crstype);
1.227 raeburn 1693: }
1694: if ($checkauth) {
1695: $nondc_setsection_code .=
1696: &Apache::lonuserutils::verify_authen($formname,$context);
1697: }
1.216 raeburn 1698: }
1699: my $js = &user_modification_js($pjump_def,$dc_setcourse_code,
1700: $nondc_setsection_code,$groupslist);
1701: my ($jsback,$elements) = &crumb_utilities();
1702: $js .= "\n".
1.301 bisitz 1703: '<script type="text/javascript">'."\n".
1704: '// <![CDATA['."\n".
1705: $jsback."\n".
1706: '// ]]>'."\n".
1707: '</script>'."\n";
1.216 raeburn 1708: return $js;
1709: }
1710:
1.217 raeburn 1711: sub display_existing_roles {
1.375 raeburn 1712: my ($r,$ccuname,$ccdomain,$inccourses,$context,$roledom,$crstype,
1.418 raeburn 1713: $showcredits,$statuses) = @_;
1.329 raeburn 1714: my $now=time;
1.418 raeburn 1715: my $showall = 1;
1716: my ($showexpired,$showactive);
1717: if ((ref($statuses) eq 'ARRAY') && (@{$statuses} > 0)) {
1718: $showall = 0;
1719: if (grep(/^expired$/,@{$statuses})) {
1720: $showexpired = 1;
1721: }
1722: if (grep(/^active$/,@{$statuses})) {
1723: $showactive = 1;
1724: }
1725: if ($showexpired && $showactive) {
1726: $showall = 1;
1727: }
1728: }
1.329 raeburn 1729: my %lt=&Apache::lonlocal::texthash(
1.217 raeburn 1730: 'rer' => "Existing Roles",
1731: 'rev' => "Revoke",
1732: 'del' => "Delete",
1733: 'ren' => "Re-Enable",
1734: 'rol' => "Role",
1735: 'ext' => "Extent",
1.375 raeburn 1736: 'crd' => "Credits",
1.217 raeburn 1737: 'sta' => "Start",
1738: 'end' => "End",
1739: );
1.329 raeburn 1740: my (%rolesdump,%roletext,%sortrole,%roleclass,%rolepriv);
1741: if ($context eq 'course' || $context eq 'author') {
1742: my @roles = &Apache::lonuserutils::roles_by_context($context,1,$crstype);
1743: my %roleshash =
1744: &Apache::lonnet::get_my_roles($ccuname,$ccdomain,'userroles',
1745: ['active','previous','future'],\@roles,$roledom,1);
1746: foreach my $key (keys(%roleshash)) {
1747: my ($start,$end) = split(':',$roleshash{$key});
1748: next if ($start eq '-1' || $end eq '-1');
1749: my ($rnum,$rdom,$role,$sec) = split(':',$key);
1750: if ($context eq 'course') {
1751: next unless (($rnum eq $env{'course.'.$env{'request.course.id'}.'.num'})
1752: && ($rdom eq $env{'course.'.$env{'request.course.id'}.'.domain'}));
1753: } elsif ($context eq 'author') {
1754: next unless (($rnum eq $env{'user.name'}) && ($rdom eq $env{'request.role.domain'}));
1755: }
1756: my ($newkey,$newvalue,$newrole);
1757: $newkey = '/'.$rdom.'/'.$rnum;
1758: if ($sec ne '') {
1759: $newkey .= '/'.$sec;
1760: }
1761: $newvalue = $role;
1762: if ($role =~ /^cr/) {
1763: $newrole = 'cr';
1764: } else {
1765: $newrole = $role;
1766: }
1767: $newkey .= '_'.$newrole;
1768: if ($start ne '' && $end ne '') {
1769: $newvalue .= '_'.$end.'_'.$start;
1.335 raeburn 1770: } elsif ($end ne '') {
1771: $newvalue .= '_'.$end;
1.329 raeburn 1772: }
1773: $rolesdump{$newkey} = $newvalue;
1774: }
1775: } else {
1.360 raeburn 1776: %rolesdump=&Apache::lonnet::dump('roles',$ccdomain,$ccuname);
1.329 raeburn 1777: }
1778: # Build up table of user roles to allow revocation and re-enabling of roles.
1779: my ($tmp) = keys(%rolesdump);
1780: return if ($tmp =~ /^(con_lost|error)/i);
1781: foreach my $area (sort { my $a1=join('_',(split('_',$a))[1,0]);
1782: my $b1=join('_',(split('_',$b))[1,0]);
1783: return $a1 cmp $b1;
1784: } keys(%rolesdump)) {
1785: next if ($area =~ /^rolesdef/);
1786: my $envkey=$area;
1787: my $role = $rolesdump{$area};
1788: my $thisrole=$area;
1789: $area =~ s/\_\w\w$//;
1790: my ($role_code,$role_end_time,$role_start_time) =
1791: split(/_/,$role);
1.418 raeburn 1792: my $active=1;
1793: $active=0 if (($role_end_time) && ($now>$role_end_time));
1794: if ($active) {
1795: next unless($showall || $showactive);
1796: } else {
1.430 raeburn 1797: next unless($showall || $showexpired);
1.418 raeburn 1798: }
1.217 raeburn 1799: # Is this a custom role? Get role owner and title.
1.329 raeburn 1800: my ($croleudom,$croleuname,$croletitle)=
1801: ($role_code=~m{^cr/($match_domain)/($match_username)/(\w+)$});
1802: my $allowed=0;
1803: my $delallowed=0;
1804: my $sortkey=$role_code;
1805: my $class='Unknown';
1.375 raeburn 1806: my $credits='';
1.418 raeburn 1807: my $csec;
1.421 raeburn 1808: if ($area =~ m{^/($match_domain)/($match_courseid)}) {
1.329 raeburn 1809: $class='Course';
1810: my ($coursedom,$coursedir) = ($1,$2);
1811: my $cid = $1.'_'.$2;
1812: # $1.'_'.$2 is the course id (eg. 103_12345abcef103l3).
1.421 raeburn 1813: next if ($envkey =~ m{^/$match_domain/$match_courseid/[A-Za-z0-9]+_gr$});
1.329 raeburn 1814: my %coursedata=
1815: &Apache::lonnet::coursedescription($cid);
1816: if ($coursedir =~ /^$match_community$/) {
1817: $class='Community';
1818: }
1819: $sortkey.="\0$coursedom";
1820: my $carea;
1821: if (defined($coursedata{'description'})) {
1822: $carea=$coursedata{'description'}.
1823: '<br />'.&mt('Domain').': '.$coursedom.(' 'x8).
1824: &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$coursedir,$coursedom);
1825: $sortkey.="\0".$coursedata{'description'};
1826: } else {
1827: if ($class eq 'Community') {
1828: $carea=&mt('Unavailable community').': '.$area;
1829: $sortkey.="\0".&mt('Unavailable community').': '.$area;
1.217 raeburn 1830: } else {
1831: $carea=&mt('Unavailable course').': '.$area;
1832: $sortkey.="\0".&mt('Unavailable course').': '.$area;
1833: }
1.329 raeburn 1834: }
1835: $sortkey.="\0$coursedir";
1836: $inccourses->{$cid}=1;
1.375 raeburn 1837: if (($showcredits) && ($class eq 'Course') && ($role_code eq 'st')) {
1838: my $defaultcredits = $coursedata{'internal.defaultcredits'};
1839: $credits =
1840: &get_user_credits($ccuname,$ccdomain,$defaultcredits,
1841: $coursedom,$coursedir);
1842: if ($credits eq '') {
1843: $credits = $defaultcredits;
1844: }
1845: }
1.329 raeburn 1846: if ((&Apache::lonnet::allowed('c'.$role_code,$coursedom.'/'.$coursedir)) ||
1847: (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) {
1848: $allowed=1;
1849: }
1850: unless ($allowed) {
1.365 raeburn 1851: my $isowner = &Apache::lonuserutils::is_courseowner($cid,$coursedata{'internal.courseowner'});
1.329 raeburn 1852: if ($isowner) {
1853: if (($role_code eq 'co') && ($class eq 'Community')) {
1854: $allowed = 1;
1855: } elsif (($role_code eq 'cc') && ($class eq 'Course')) {
1856: $allowed = 1;
1857: }
1.217 raeburn 1858: }
1.329 raeburn 1859: }
1860: if ((&Apache::lonnet::allowed('dro',$coursedom)) ||
1861: (&Apache::lonnet::allowed('dro',$ccdomain))) {
1862: $delallowed=1;
1863: }
1.217 raeburn 1864: # - custom role. Needs more info, too
1.329 raeburn 1865: if ($croletitle) {
1866: if (&Apache::lonnet::allowed('ccr',$coursedom.'/'.$coursedir)) {
1867: $allowed=1;
1868: $thisrole.='.'.$role_code;
1.217 raeburn 1869: }
1.329 raeburn 1870: }
1.418 raeburn 1871: if ($area=~m{^/($match_domain/$match_courseid/(\w+))}) {
1872: $csec = $2;
1873: $carea.='<br />'.&mt('Section: [_1]',$csec);
1874: $sortkey.="\0$csec";
1.329 raeburn 1875: if (!$allowed) {
1.418 raeburn 1876: if ($env{'request.course.sec'} eq $csec) {
1877: if (&Apache::lonnet::allowed('c'.$role_code,$1)) {
1.329 raeburn 1878: $allowed = 1;
1.217 raeburn 1879: }
1880: }
1881: }
1.329 raeburn 1882: }
1883: $area=$carea;
1884: } else {
1885: $sortkey.="\0".$area;
1886: # Determine if current user is able to revoke privileges
1887: if ($area=~m{^/($match_domain)/}) {
1888: if ((&Apache::lonnet::allowed('c'.$role_code,$1)) ||
1889: (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) {
1890: $allowed=1;
1.217 raeburn 1891: }
1.329 raeburn 1892: if (((&Apache::lonnet::allowed('dro',$1)) ||
1893: (&Apache::lonnet::allowed('dro',$ccdomain))) &&
1894: ($role_code ne 'dc')) {
1895: $delallowed=1;
1.217 raeburn 1896: }
1.329 raeburn 1897: } else {
1898: if (&Apache::lonnet::allowed('c'.$role_code,'/')) {
1.217 raeburn 1899: $allowed=1;
1900: }
1901: }
1.363 raeburn 1902: if ($role_code eq 'ca' || $role_code eq 'au' || $role_code eq 'aa') {
1.377 raeburn 1903: $class='Authoring Space';
1.329 raeburn 1904: } elsif ($role_code eq 'su') {
1905: $class='System';
1.217 raeburn 1906: } else {
1.329 raeburn 1907: $class='Domain';
1.217 raeburn 1908: }
1.329 raeburn 1909: }
1910: if (($role_code eq 'ca') || ($role_code eq 'aa')) {
1911: $area=~m{/($match_domain)/($match_username)};
1912: if (&Apache::lonuserutils::authorpriv($2,$1)) {
1913: $allowed=1;
1.217 raeburn 1914: } else {
1.329 raeburn 1915: $allowed=0;
1.217 raeburn 1916: }
1.329 raeburn 1917: }
1918: my $row = '';
1.418 raeburn 1919: if ($showall) {
1920: $row.= '<td>';
1921: if (($active) && ($allowed)) {
1922: $row.= '<input type="checkbox" name="rev:'.$thisrole.'" />';
1923: } else {
1924: if ($active) {
1925: $row.=' ';
1926: } else {
1927: $row.=&mt('expired or revoked');
1928: }
1929: }
1930: $row.='</td><td>';
1931: if ($allowed && !$active) {
1932: $row.= '<input type="checkbox" name="ren:'.$thisrole.'" />';
1933: } else {
1934: $row.=' ';
1935: }
1936: $row.='</td><td>';
1937: if ($delallowed) {
1938: $row.= '<input type="checkbox" name="del:'.$thisrole.'" />';
1.217 raeburn 1939: } else {
1.418 raeburn 1940: $row.=' ';
1.217 raeburn 1941: }
1.430 raeburn 1942: $row.= '</td>';
1.329 raeburn 1943: }
1944: my $plaintext='';
1945: if (!$croletitle) {
1.375 raeburn 1946: $plaintext=&Apache::lonnet::plaintext($role_code,$class);
1947: if (($showcredits) && ($credits ne '')) {
1948: $plaintext .= '<br/ ><span class="LC_nobreak">'.
1949: '<span class="LC_fontsize_small">'.
1950: &mt('Credits: [_1]',$credits).
1951: '</span></span>';
1952: }
1.329 raeburn 1953: } else {
1954: $plaintext=
1.395 bisitz 1955: &mt('Custom role [_1][_2]defined by [_3]',
1.346 bisitz 1956: '"'.$croletitle.'"',
1957: '<br />',
1958: $croleuname.':'.$croleudom);
1.329 raeburn 1959: }
1.418 raeburn 1960: $row.= '<td>'.$plaintext.'</td>'.
1961: '<td>'.$area.'</td>'.
1962: '<td>'.($role_start_time?&Apache::lonlocal::locallocaltime($role_start_time)
1963: : ' ' ).'</td>'.
1964: '<td>'.($role_end_time ?&Apache::lonlocal::locallocaltime($role_end_time)
1965: : ' ' ).'</td>';
1.329 raeburn 1966: $sortrole{$sortkey}=$envkey;
1967: $roletext{$envkey}=$row;
1968: $roleclass{$envkey}=$class;
1.418 raeburn 1969: if ($allowed) {
1970: $rolepriv{$envkey}='edit';
1971: } else {
1972: if ($context eq 'domain') {
1.420 raeburn 1973: if ((&Apache::lonnet::allowed('vur',$ccdomain)) &&
1.421 raeburn 1974: ($envkey=~m{^/$ccdomain/})) {
1.418 raeburn 1975: $rolepriv{$envkey}='view';
1976: }
1977: } elsif ($context eq 'course') {
1978: if ((&Apache::lonnet::allowed('vcl',$env{'request.course.id'})) ||
1979: ($env{'request.course.sec'} && ($env{'request.course.sec'} eq $csec) &&
1980: &Apache::lonnet::allowed('vcl',$env{'request.course.id'}.'/'.$env{'request.course.sec'}))) {
1981: $rolepriv{$envkey}='view';
1982: }
1983: }
1984: }
1.329 raeburn 1985: } # end of foreach (table building loop)
1986:
1987: my $rolesdisplay = 0;
1988: my %output = ();
1.377 raeburn 1989: foreach my $type ('Authoring Space','Course','Community','Domain','System','Unknown') {
1.329 raeburn 1990: $output{$type} = '';
1991: foreach my $which (sort {uc($a) cmp uc($b)} (keys(%sortrole))) {
1992: if ( ($roleclass{$sortrole{$which}} =~ /^\Q$type\E/ ) && ($rolepriv{$sortrole{$which}}) ) {
1993: $output{$type}.=
1994: &Apache::loncommon::start_data_table_row().
1995: $roletext{$sortrole{$which}}.
1996: &Apache::loncommon::end_data_table_row();
1.217 raeburn 1997: }
1.329 raeburn 1998: }
1999: unless($output{$type} eq '') {
2000: $output{$type} = '<tr class="LC_info_row">'.
2001: "<td align='center' colspan='7'>".&mt($type)."</td></tr>".
2002: $output{$type};
2003: $rolesdisplay = 1;
2004: }
2005: }
2006: if ($rolesdisplay == 1) {
2007: my $contextrole='';
2008: if ($env{'request.course.id'}) {
2009: if (&Apache::loncommon::course_type() eq 'Community') {
2010: $contextrole = &mt('Existing Roles in this Community');
1.290 bisitz 2011: } else {
1.329 raeburn 2012: $contextrole = &mt('Existing Roles in this Course');
1.290 bisitz 2013: }
1.329 raeburn 2014: } elsif ($env{'request.role'} =~ /^au\./) {
1.377 raeburn 2015: $contextrole = &mt('Existing Co-Author Roles in your Authoring Space');
1.329 raeburn 2016: } else {
1.418 raeburn 2017: if ($showall) {
2018: $contextrole = &mt('Existing Roles in this Domain');
2019: } elsif ($showactive) {
2020: $contextrole = &mt('Unexpired Roles in this Domain');
2021: } elsif ($showexpired) {
2022: $contextrole = &mt('Expired or Revoked Roles in this Domain');
2023: }
1.329 raeburn 2024: }
1.393 raeburn 2025: $r->print('<div class="LC_left_float">'.
1.375 raeburn 2026: '<fieldset><legend>'.$contextrole.'</legend>'.
1.217 raeburn 2027: &Apache::loncommon::start_data_table("LC_createuser").
1.418 raeburn 2028: &Apache::loncommon::start_data_table_header_row());
2029: if ($showall) {
2030: $r->print(
1.419 raeburn 2031: '<th>'.$lt{'rev'}.'</th><th>'.$lt{'ren'}.'</th><th>'.$lt{'del'}.'</th>'
1.418 raeburn 2032: );
2033: } elsif ($showexpired) {
2034: $r->print('<th>'.$lt{'rev'}.'</th>');
2035: }
2036: $r->print(
1.419 raeburn 2037: '<th>'.$lt{'rol'}.'</th><th>'.$lt{'ext'}.'</th>'.
2038: '<th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'.
1.217 raeburn 2039: &Apache::loncommon::end_data_table_header_row());
1.377 raeburn 2040: foreach my $type ('Authoring Space','Course','Community','Domain','System','Unknown') {
1.329 raeburn 2041: if ($output{$type}) {
2042: $r->print($output{$type}."\n");
1.217 raeburn 2043: }
2044: }
1.375 raeburn 2045: $r->print(&Apache::loncommon::end_data_table().
2046: '</fieldset></div>');
1.329 raeburn 2047: }
1.217 raeburn 2048: return;
2049: }
2050:
1.218 raeburn 2051: sub new_coauthor_roles {
2052: my ($r,$ccuname,$ccdomain) = @_;
2053: my $addrolesdisplay = 0;
2054: #
2055: # Co-Author
2056: #
2057: if (&Apache::lonuserutils::authorpriv($env{'user.name'},
2058: $env{'request.role.domain'}) &&
2059: ($env{'user.name'} ne $ccuname || $env{'user.domain'} ne $ccdomain)) {
2060: # No sense in assigning co-author role to yourself
2061: $addrolesdisplay = 1;
2062: my $cuname=$env{'user.name'};
2063: my $cudom=$env{'request.role.domain'};
2064: my %lt=&Apache::lonlocal::texthash(
1.377 raeburn 2065: 'cs' => "Authoring Space",
1.218 raeburn 2066: 'act' => "Activate",
2067: 'rol' => "Role",
2068: 'ext' => "Extent",
2069: 'sta' => "Start",
2070: 'end' => "End",
2071: 'cau' => "Co-Author",
2072: 'caa' => "Assistant Co-Author",
2073: 'ssd' => "Set Start Date",
2074: 'sed' => "Set End Date"
2075: );
2076: $r->print('<h4>'.$lt{'cs'}.'</h4>'."\n".
2077: &Apache::loncommon::start_data_table()."\n".
2078: &Apache::loncommon::start_data_table_header_row()."\n".
2079: '<th>'.$lt{'act'}.'</th><th>'.$lt{'rol'}.'</th>'.
2080: '<th>'.$lt{'ext'}.'</th><th>'.$lt{'sta'}.'</th>'.
2081: '<th>'.$lt{'end'}.'</th>'."\n".
2082: &Apache::loncommon::end_data_table_header_row()."\n".
2083: &Apache::loncommon::start_data_table_row().'
2084: <td>
1.291 bisitz 2085: <input type="checkbox" name="act_'.$cudom.'_'.$cuname.'_ca" />
1.218 raeburn 2086: </td>
2087: <td>'.$lt{'cau'}.'</td>
2088: <td>'.$cudom.'_'.$cuname.'</td>
2089: <td><input type="hidden" name="start_'.$cudom.'_'.$cuname.'_ca" value="" />
2090: <a href=
2091: "javascript:pjump('."'date_start','Start Date Co-Author',document.cu.start_$cudom\_$cuname\_ca.value,'start_$cudom\_$cuname\_ca','cu.pres','dateset'".')">'.$lt{'ssd'}.'</a></td>
2092: <td><input type="hidden" name="end_'.$cudom.'_'.$cuname.'_ca" value="" />
2093: <a href=
2094: "javascript:pjump('."'date_end','End Date Co-Author',document.cu.end_$cudom\_$cuname\_ca.value,'end_$cudom\_$cuname\_ca','cu.pres','dateset'".')">'.$lt{'sed'}.'</a></td>'."\n".
2095: &Apache::loncommon::end_data_table_row()."\n".
2096: &Apache::loncommon::start_data_table_row()."\n".
1.291 bisitz 2097: '<td><input type="checkbox" name="act_'.$cudom.'_'.$cuname.'_aa" /></td>
1.218 raeburn 2098: <td>'.$lt{'caa'}.'</td>
2099: <td>'.$cudom.'_'.$cuname.'</td>
2100: <td><input type="hidden" name="start_'.$cudom.'_'.$cuname.'_aa" value="" />
2101: <a href=
2102: "javascript:pjump('."'date_start','Start Date Assistant Co-Author',document.cu.start_$cudom\_$cuname\_aa.value,'start_$cudom\_$cuname\_aa','cu.pres','dateset'".')">'.$lt{'ssd'}.'</a></td>
2103: <td><input type="hidden" name="end_'.$cudom.'_'.$cuname.'_aa" value="" />
2104: <a href=
2105: "javascript:pjump('."'date_end','End Date Assistant Co-Author',document.cu.end_$cudom\_$cuname\_aa.value,'end_$cudom\_$cuname\_aa','cu.pres','dateset'".')">'.$lt{'sed'}.'</a></td>'."\n".
2106: &Apache::loncommon::end_data_table_row()."\n".
2107: &Apache::loncommon::end_data_table());
2108: } elsif ($env{'request.role'} =~ /^au\./) {
2109: if (!(&Apache::lonuserutils::authorpriv($env{'user.name'},
2110: $env{'request.role.domain'}))) {
2111: $r->print('<span class="LC_error">'.
2112: &mt('You do not have privileges to assign co-author roles.').
2113: '</span>');
2114: } elsif (($env{'user.name'} eq $ccuname) &&
2115: ($env{'user.domain'} eq $ccdomain)) {
1.377 raeburn 2116: $r->print(&mt('Assigning yourself a co-author or assistant co-author role in your own author area in Authoring Space is not permitted'));
1.218 raeburn 2117: }
2118: }
2119: return $addrolesdisplay;;
2120: }
2121:
2122: sub new_domain_roles {
1.357 raeburn 2123: my ($r,$ccdomain) = @_;
1.218 raeburn 2124: my $addrolesdisplay = 0;
2125: #
2126: # Domain level
2127: #
2128: my $num_domain_level = 0;
2129: my $domaintext =
2130: '<h4>'.&mt('Domain Level').'</h4>'.
2131: &Apache::loncommon::start_data_table().
2132: &Apache::loncommon::start_data_table_header_row().
2133: '<th>'.&mt('Activate').'</th><th>'.&mt('Role').'</th><th>'.
2134: &mt('Extent').'</th>'.
2135: '<th>'.&mt('Start').'</th><th>'.&mt('End').'</th>'.
2136: &Apache::loncommon::end_data_table_header_row();
1.312 raeburn 2137: my @allroles = &Apache::lonuserutils::roles_by_context('domain');
1.218 raeburn 2138: foreach my $thisdomain (sort(&Apache::lonnet::all_domains())) {
1.312 raeburn 2139: foreach my $role (@allroles) {
2140: next if ($role eq 'ad');
1.357 raeburn 2141: next if (($role eq 'au') && ($ccdomain ne $thisdomain));
1.218 raeburn 2142: if (&Apache::lonnet::allowed('c'.$role,$thisdomain)) {
2143: my $plrole=&Apache::lonnet::plaintext($role);
2144: my %lt=&Apache::lonlocal::texthash(
2145: 'ssd' => "Set Start Date",
2146: 'sed' => "Set End Date"
2147: );
2148: $num_domain_level ++;
2149: $domaintext .=
2150: &Apache::loncommon::start_data_table_row().
1.291 bisitz 2151: '<td><input type="checkbox" name="act_'.$thisdomain.'_'.$role.'" /></td>
1.218 raeburn 2152: <td>'.$plrole.'</td>
2153: <td>'.$thisdomain.'</td>
2154: <td><input type="hidden" name="start_'.$thisdomain.'_'.$role.'" value="" />
2155: <a href=
2156: "javascript:pjump('."'date_start','Start Date $plrole',document.cu.start_$thisdomain\_$role.value,'start_$thisdomain\_$role','cu.pres','dateset'".')">'.$lt{'ssd'}.'</a></td>
2157: <td><input type="hidden" name="end_'.$thisdomain.'_'.$role.'" value="" />
2158: <a href=
2159: "javascript:pjump('."'date_end','End Date $plrole',document.cu.end_$thisdomain\_$role.value,'end_$thisdomain\_$role','cu.pres','dateset'".')">'.$lt{'sed'}.'</a></td>'.
2160: &Apache::loncommon::end_data_table_row();
2161: }
2162: }
2163: }
2164: $domaintext.= &Apache::loncommon::end_data_table();
2165: if ($num_domain_level > 0) {
2166: $r->print($domaintext);
2167: $addrolesdisplay = 1;
2168: }
2169: return $addrolesdisplay;
2170: }
2171:
1.188 raeburn 2172: sub user_authentication {
1.227 raeburn 2173: my ($ccuname,$ccdomain,$formname) = @_;
1.188 raeburn 2174: my $currentauth=&Apache::lonnet::queryauthenticate($ccuname,$ccdomain);
1.227 raeburn 2175: my $outcome;
1.418 raeburn 2176: my %lt=&Apache::lonlocal::texthash(
2177: 'err' => "ERROR",
2178: 'uuas' => "This user has an unrecognized authentication scheme",
2179: 'adcs' => "Please alert a domain coordinator of this situation",
2180: 'sldb' => "Please specify login data below",
2181: 'ld' => "Login Data"
2182: );
1.188 raeburn 2183: # Check for a bad authentication type
2184: if ($currentauth !~ /^(krb4|krb5|unix|internal|localauth):/) {
2185: # bad authentication scheme
2186: if (&Apache::lonnet::allowed('mau',$ccdomain)) {
1.227 raeburn 2187: &initialize_authen_forms($ccdomain,$formname);
2188:
1.190 raeburn 2189: my $choices = &Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc);
1.188 raeburn 2190: $outcome = <<ENDBADAUTH;
2191: <script type="text/javascript" language="Javascript">
1.301 bisitz 2192: // <![CDATA[
1.188 raeburn 2193: $loginscript
1.301 bisitz 2194: // ]]>
1.188 raeburn 2195: </script>
2196: <span class="LC_error">$lt{'err'}:
2197: $lt{'uuas'} ($currentauth). $lt{'sldb'}.</span>
2198: <h3>$lt{'ld'}</h3>
2199: $choices
2200: ENDBADAUTH
2201: } else {
2202: # This user is not allowed to modify the user's
2203: # authentication scheme, so just notify them of the problem
2204: $outcome = <<ENDBADAUTH;
2205: <span class="LC_error"> $lt{'err'}:
2206: $lt{'uuas'} ($currentauth). $lt{'adcs'}.
2207: </span>
2208: ENDBADAUTH
2209: }
2210: } else { # Authentication type is valid
1.418 raeburn 2211:
1.227 raeburn 2212: &initialize_authen_forms($ccdomain,$formname,$currentauth,'modifyuser');
1.205 raeburn 2213: my ($authformcurrent,$can_modify,@authform_others) =
1.188 raeburn 2214: &modify_login_block($ccdomain,$currentauth);
2215: if (&Apache::lonnet::allowed('mau',$ccdomain)) {
2216: # Current user has login modification privileges
2217: $outcome =
2218: '<script type="text/javascript" language="Javascript">'."\n".
1.301 bisitz 2219: '// <![CDATA['."\n".
1.188 raeburn 2220: $loginscript."\n".
1.301 bisitz 2221: '// ]]>'."\n".
1.188 raeburn 2222: '</script>'."\n".
2223: '<h3>'.$lt{'ld'}.'</h3>'.
2224: &Apache::loncommon::start_data_table().
1.205 raeburn 2225: &Apache::loncommon::start_data_table_row().
1.188 raeburn 2226: '<td>'.$authformnop;
1.418 raeburn 2227: if (($can_modify) && (&Apache::lonnet::allowed('mau',$ccdomain))) {
1.188 raeburn 2228: $outcome .= '</td>'."\n".
2229: &Apache::loncommon::end_data_table_row().
2230: &Apache::loncommon::start_data_table_row().
2231: '<td>'.$authformcurrent.'</td>'.
2232: &Apache::loncommon::end_data_table_row()."\n";
2233: } else {
1.200 raeburn 2234: $outcome .= ' ('.$authformcurrent.')</td>'.
2235: &Apache::loncommon::end_data_table_row()."\n";
1.188 raeburn 2236: }
1.418 raeburn 2237: if (&Apache::lonnet::allowed('mau',$ccdomain)) {
2238: foreach my $item (@authform_others) {
2239: $outcome .= &Apache::loncommon::start_data_table_row().
2240: '<td>'.$item.'</td>'.
2241: &Apache::loncommon::end_data_table_row()."\n";
2242: }
1.188 raeburn 2243: }
1.205 raeburn 2244: $outcome .= &Apache::loncommon::end_data_table();
1.188 raeburn 2245: } else {
1.418 raeburn 2246: if (&Apache::lonnet::allowed('udp',$ccdomain)) {
2247: # Current user has rights to view domain preferences for user's domain
2248: my $result;
2249: if ($currentauth =~ /^krb(4|5):([^:]*)$/) {
2250: my ($krbver,$krbrealm) = ($1,$2);
2251: if ($krbrealm eq '') {
2252: $result = &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
2253: } else {
2254: $result = &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
1.426 raeburn 2255: $krbrealm,$krbver);
1.418 raeburn 2256: }
2257: } elsif ($currentauth =~ /^internal:/) {
2258: $result = &mt('Currently internally authenticated.');
2259: } elsif ($currentauth =~ /^localauth:/) {
2260: $result = &mt('Currently using local (institutional) authentication.');
2261: } elsif ($currentauth =~ /^unix:/) {
2262: $result = &mt('Currently Filesystem Authenticated.');
2263: }
2264: $outcome = '<h3>'.$lt{'ld'}.'</h3>'.
2265: &Apache::loncommon::start_data_table().
2266: &Apache::loncommon::start_data_table_row().
2267: '<td>'.$result.'</td>'.
2268: &Apache::loncommon::end_data_table_row()."\n".
2269: &Apache::loncommon::end_data_table();
2270: } elsif (&Apache::lonnet::allowed('mau',$env{'request.role.domain'})) {
1.188 raeburn 2271: my %lt=&Apache::lonlocal::texthash(
2272: 'ccld' => "Change Current Login Data",
2273: 'yodo' => "You do not have privileges to modify the authentication configuration for this user.",
2274: 'ifch' => "If a change is required, contact a domain coordinator for the domain",
2275: );
2276: $outcome .= <<ENDNOPRIV;
2277: <h3>$lt{'ccld'}</h3>
2278: $lt{'yodo'} $lt{'ifch'}: $ccdomain
1.235 raeburn 2279: <input type="hidden" name="login" value="nochange" />
1.188 raeburn 2280: ENDNOPRIV
2281: }
2282: }
2283: } ## End of "check for bad authentication type" logic
2284: return $outcome;
2285: }
2286:
1.187 raeburn 2287: sub modify_login_block {
2288: my ($dom,$currentauth) = @_;
2289: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
2290: my ($authnum,%can_assign) =
2291: &Apache::loncommon::get_assignable_auth($dom);
1.205 raeburn 2292: my ($authformcurrent,@authform_others,$show_override_msg);
1.187 raeburn 2293: if ($currentauth=~/^krb(4|5):/) {
2294: $authformcurrent=$authformkrb;
2295: if ($can_assign{'int'}) {
1.205 raeburn 2296: push(@authform_others,$authformint);
1.187 raeburn 2297: }
2298: if ($can_assign{'loc'}) {
1.205 raeburn 2299: push(@authform_others,$authformloc);
1.187 raeburn 2300: }
2301: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
2302: $show_override_msg = 1;
2303: }
2304: } elsif ($currentauth=~/^internal:/) {
2305: $authformcurrent=$authformint;
2306: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205 raeburn 2307: push(@authform_others,$authformkrb);
1.187 raeburn 2308: }
2309: if ($can_assign{'loc'}) {
1.205 raeburn 2310: push(@authform_others,$authformloc);
1.187 raeburn 2311: }
2312: if ($can_assign{'int'}) {
2313: $show_override_msg = 1;
2314: }
2315: } elsif ($currentauth=~/^unix:/) {
2316: $authformcurrent=$authformfsys;
2317: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205 raeburn 2318: push(@authform_others,$authformkrb);
1.187 raeburn 2319: }
2320: if ($can_assign{'int'}) {
1.205 raeburn 2321: push(@authform_others,$authformint);
1.187 raeburn 2322: }
2323: if ($can_assign{'loc'}) {
1.205 raeburn 2324: push(@authform_others,$authformloc);
1.187 raeburn 2325: }
2326: if ($can_assign{'fsys'}) {
2327: $show_override_msg = 1;
2328: }
2329: } elsif ($currentauth=~/^localauth:/) {
2330: $authformcurrent=$authformloc;
2331: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205 raeburn 2332: push(@authform_others,$authformkrb);
1.187 raeburn 2333: }
2334: if ($can_assign{'int'}) {
1.205 raeburn 2335: push(@authform_others,$authformint);
1.187 raeburn 2336: }
2337: if ($can_assign{'loc'}) {
2338: $show_override_msg = 1;
2339: }
2340: }
2341: if ($show_override_msg) {
1.205 raeburn 2342: $authformcurrent = '<table><tr><td colspan="3">'.$authformcurrent.
2343: '</td></tr>'."\n".
2344: '<tr><td> </td>'.
2345: '<td><b>'.&mt('Currently in use').'</b></td>'.
2346: '<td align="right"><span class="LC_cusr_emph">'.
1.187 raeburn 2347: &mt('will override current values').
1.205 raeburn 2348: '</span></td></tr></table>';
1.187 raeburn 2349: }
1.205 raeburn 2350: return ($authformcurrent,$show_override_msg,@authform_others);
1.187 raeburn 2351: }
2352:
1.188 raeburn 2353: sub personal_data_display {
1.391 raeburn 2354: my ($ccuname,$ccdomain,$newuser,$context,$inst_results,$rolesarray,
1.410 raeburn 2355: $now,$captchaform,$emailusername,$usertype) = @_;
1.388 bisitz 2356: my ($output,%userenv,%canmodify,%canmodify_status);
1.219 raeburn 2357: my @userinfo = ('firstname','middlename','lastname','generation',
2358: 'permanentemail','id');
1.252 raeburn 2359: my $rowcount = 0;
2360: my $editable = 0;
1.391 raeburn 2361: my %textboxsize = (
2362: firstname => '15',
2363: middlename => '15',
2364: lastname => '15',
2365: generation => '5',
2366: permanentemail => '25',
2367: id => '15',
2368: );
2369:
2370: my %lt=&Apache::lonlocal::texthash(
2371: 'pd' => "Personal Data",
2372: 'firstname' => "First Name",
2373: 'middlename' => "Middle Name",
2374: 'lastname' => "Last Name",
2375: 'generation' => "Generation",
2376: 'permanentemail' => "Permanent e-mail address",
2377: 'id' => "Student/Employee ID",
2378: 'lg' => "Login Data",
2379: 'inststatus' => "Affiliation",
2380: 'email' => 'E-mail address',
2381: 'valid' => 'Validation',
2382: );
2383:
2384: %canmodify_status =
1.286 raeburn 2385: &Apache::lonuserutils::can_modify_userinfo($context,$ccdomain,
2386: ['inststatus'],$rolesarray);
1.253 raeburn 2387: if (!$newuser) {
1.188 raeburn 2388: # Get the users information
2389: %userenv = &Apache::lonnet::get('environment',
2390: ['firstname','middlename','lastname','generation',
1.286 raeburn 2391: 'permanentemail','id','inststatus'],$ccdomain,$ccuname);
1.219 raeburn 2392: %canmodify =
2393: &Apache::lonuserutils::can_modify_userinfo($context,$ccdomain,
1.252 raeburn 2394: \@userinfo,$rolesarray);
1.257 raeburn 2395: } elsif ($context eq 'selfcreate') {
1.391 raeburn 2396: if ($newuser eq 'email') {
1.396 raeburn 2397: if (ref($emailusername) eq 'HASH') {
2398: if (ref($emailusername->{$usertype}) eq 'HASH') {
2399: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
2400: @userinfo = ();
2401: if ((ref($infofields) eq 'ARRAY') && (ref($infotitles) eq 'HASH')) {
2402: foreach my $field (@{$infofields}) {
2403: if ($emailusername->{$usertype}->{$field}) {
2404: push(@userinfo,$field);
2405: $canmodify{$field} = 1;
2406: unless ($textboxsize{$field}) {
2407: $textboxsize{$field} = 25;
2408: }
2409: unless ($lt{$field}) {
2410: $lt{$field} = $infotitles->{$field};
2411: }
2412: if ($emailusername->{$usertype}->{$field} eq 'required') {
2413: $lt{$field} .= '<b>*</b>';
2414: }
1.391 raeburn 2415: }
2416: }
2417: }
2418: }
2419: }
2420: } else {
2421: %canmodify = &selfcreate_canmodify($context,$ccdomain,\@userinfo,
2422: $inst_results,$rolesarray);
2423: }
1.188 raeburn 2424: }
1.391 raeburn 2425:
1.188 raeburn 2426: my $genhelp=&Apache::loncommon::help_open_topic('Generation');
2427: $output = '<h3>'.$lt{'pd'}.'</h3>'.
2428: &Apache::lonhtmlcommon::start_pick_box();
1.391 raeburn 2429: if (($context eq 'selfcreate') && ($newuser eq 'email')) {
1.396 raeburn 2430: $output .= &Apache::lonhtmlcommon::row_title($lt{'email'}.'<b>*</b>',undef,
1.391 raeburn 2431: 'LC_oddrow_value')."\n".
1.394 raeburn 2432: '<input type="text" name="uname" size="25" value="" autocomplete="off" />';
1.391 raeburn 2433: $rowcount ++;
2434: $output .= &Apache::lonhtmlcommon::row_closure(1);
1.408 raeburn 2435: my $upassone = '<input type="password" name="upass'.$now.'" size="20" autocomplete="off" />';
2436: my $upasstwo = '<input type="password" name="upasscheck'.$now.'" size="20" autocomplete="off" />';
1.396 raeburn 2437: $output .= &Apache::lonhtmlcommon::row_title(&mt('Password').'<b>*</b>',
1.391 raeburn 2438: 'LC_pick_box_title',
2439: 'LC_oddrow_value')."\n".
2440: $upassone."\n".
2441: &Apache::lonhtmlcommon::row_closure(1)."\n".
1.396 raeburn 2442: &Apache::lonhtmlcommon::row_title(&mt('Confirm password').'<b>*</b>',
1.391 raeburn 2443: 'LC_pick_box_title',
2444: 'LC_oddrow_value')."\n".
2445: $upasstwo.
2446: &Apache::lonhtmlcommon::row_closure()."\n";
2447: }
1.188 raeburn 2448: foreach my $item (@userinfo) {
2449: my $rowtitle = $lt{$item};
1.252 raeburn 2450: my $hiderow = 0;
1.188 raeburn 2451: if ($item eq 'generation') {
2452: $rowtitle = $genhelp.$rowtitle;
2453: }
1.252 raeburn 2454: my $row = &Apache::lonhtmlcommon::row_title($rowtitle,undef,'LC_oddrow_value')."\n";
1.188 raeburn 2455: if ($newuser) {
1.210 raeburn 2456: if (ref($inst_results) eq 'HASH') {
2457: if ($inst_results->{$item} ne '') {
1.252 raeburn 2458: $row .= '<input type="hidden" name="c'.$item.'" value="'.$inst_results->{$item}.'" />'.$inst_results->{$item};
1.210 raeburn 2459: } else {
1.252 raeburn 2460: if ($context eq 'selfcreate') {
1.391 raeburn 2461: if ($canmodify{$item}) {
1.394 raeburn 2462: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" autocomplete="off" />';
1.252 raeburn 2463: $editable ++;
2464: } else {
2465: $hiderow = 1;
2466: }
1.253 raeburn 2467: } else {
2468: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
1.252 raeburn 2469: }
1.210 raeburn 2470: }
1.188 raeburn 2471: } else {
1.252 raeburn 2472: if ($context eq 'selfcreate') {
1.401 raeburn 2473: if ($canmodify{$item}) {
2474: if ($newuser eq 'email') {
2475: $row .= '<input type="text" name="'.$item.'" size="'.$textboxsize{$item}.'" value="" autocomplete="off" />';
1.287 raeburn 2476: } else {
1.401 raeburn 2477: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" autocomplete="off" />';
1.287 raeburn 2478: }
1.401 raeburn 2479: $editable ++;
2480: } else {
2481: $hiderow = 1;
1.252 raeburn 2482: }
1.253 raeburn 2483: } else {
2484: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
1.252 raeburn 2485: }
1.188 raeburn 2486: }
2487: } else {
1.219 raeburn 2488: if ($canmodify{$item}) {
1.252 raeburn 2489: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="'.$userenv{$item}.'" />';
1.393 raeburn 2490: if (($item eq 'id') && (!$newuser)) {
2491: $row .= '<br />'.&Apache::lonuserutils::forceid_change($context);
2492: }
1.188 raeburn 2493: } else {
1.252 raeburn 2494: $row .= $userenv{$item};
1.188 raeburn 2495: }
2496: }
1.252 raeburn 2497: $row .= &Apache::lonhtmlcommon::row_closure(1);
2498: if (!$hiderow) {
2499: $output .= $row;
2500: $rowcount ++;
2501: }
1.188 raeburn 2502: }
1.286 raeburn 2503: if (($canmodify_status{'inststatus'}) || ($context ne 'selfcreate')) {
2504: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($ccdomain);
2505: if (ref($types) eq 'ARRAY') {
2506: if (@{$types} > 0) {
2507: my ($hiderow,$shown);
2508: if ($canmodify_status{'inststatus'}) {
2509: $shown = &pick_inst_statuses($userenv{'inststatus'},$usertypes,$types);
2510: } else {
2511: if ($userenv{'inststatus'} eq '') {
2512: $hiderow = 1;
1.334 raeburn 2513: } else {
2514: my @showitems;
2515: foreach my $item ( map { &unescape($_); } split(':',$userenv{'inststatus'})) {
2516: if (exists($usertypes->{$item})) {
2517: push(@showitems,$usertypes->{$item});
2518: } else {
2519: push(@showitems,$item);
2520: }
2521: }
2522: if (@showitems) {
2523: $shown = join(', ',@showitems);
2524: } else {
2525: $hiderow = 1;
2526: }
1.286 raeburn 2527: }
2528: }
2529: if (!$hiderow) {
1.389 bisitz 2530: my $row = &Apache::lonhtmlcommon::row_title(&mt('Affiliations'),undef,'LC_oddrow_value')."\n".
1.286 raeburn 2531: $shown.&Apache::lonhtmlcommon::row_closure(1);
2532: if ($context eq 'selfcreate') {
2533: $rowcount ++;
2534: }
2535: $output .= $row;
2536: }
2537: }
2538: }
2539: }
1.391 raeburn 2540: if (($context eq 'selfcreate') && ($newuser eq 'email')) {
2541: if ($captchaform) {
1.410 raeburn 2542: $output .= &Apache::lonhtmlcommon::row_title($lt{'valid'}.'*',
2543: 'LC_pick_box_title')."\n".
2544: $captchaform."\n".'<br /><br />'.
1.391 raeburn 2545: &Apache::lonhtmlcommon::row_closure(1);
2546: $rowcount ++;
2547: }
2548: my $submit_text = &mt('Create account');
2549: $output .= &Apache::lonhtmlcommon::row_title()."\n".
2550: '<br /><input type="submit" name="createaccount" value="'.
2551: $submit_text.'" />'.
1.396 raeburn 2552: '<input type="hidden" name="type" value="'.$usertype.'" />'.
1.391 raeburn 2553: &Apache::lonhtmlcommon::row_closure(1);
2554: }
1.188 raeburn 2555: $output .= &Apache::lonhtmlcommon::end_pick_box();
1.206 raeburn 2556: if (wantarray) {
1.252 raeburn 2557: if ($context eq 'selfcreate') {
2558: return($output,$rowcount,$editable);
2559: } else {
1.388 bisitz 2560: return $output;
1.252 raeburn 2561: }
1.206 raeburn 2562: } else {
2563: return $output;
2564: }
1.188 raeburn 2565: }
2566:
1.286 raeburn 2567: sub pick_inst_statuses {
2568: my ($curr,$usertypes,$types) = @_;
2569: my ($output,$rem,@currtypes);
2570: if ($curr ne '') {
2571: @currtypes = map { &unescape($_); } split(/:/,$curr);
2572: }
2573: my $numinrow = 2;
2574: if (ref($types) eq 'ARRAY') {
2575: $output = '<table>';
2576: my $lastcolspan;
2577: for (my $i=0; $i<@{$types}; $i++) {
2578: if (defined($usertypes->{$types->[$i]})) {
2579: my $rem = $i%($numinrow);
2580: if ($rem == 0) {
2581: if ($i<@{$types}-1) {
2582: if ($i > 0) {
2583: $output .= '</tr>';
2584: }
2585: $output .= '<tr>';
2586: }
2587: } elsif ($i==@{$types}-1) {
2588: my $colsleft = $numinrow - $rem;
2589: if ($colsleft > 1) {
2590: $lastcolspan = ' colspan="'.$colsleft.'"';
2591: }
2592: }
2593: my $check = ' ';
2594: if (grep(/^\Q$types->[$i]\E$/,@currtypes)) {
2595: $check = ' checked="checked" ';
2596: }
2597: $output .= '<td class="LC_left_item"'.$lastcolspan.'>'.
2598: '<span class="LC_nobreak"><label>'.
2599: '<input type="checkbox" name="inststatus" '.
2600: 'value="'.$types->[$i].'"'.$check.'/>'.
2601: $usertypes->{$types->[$i]}.'</label></span></td>';
2602: }
2603: }
2604: $output .= '</tr></table>';
2605: }
2606: return $output;
2607: }
2608:
1.257 raeburn 2609: sub selfcreate_canmodify {
2610: my ($context,$dom,$userinfo,$inst_results,$rolesarray) = @_;
2611: if (ref($inst_results) eq 'HASH') {
2612: my @inststatuses = &get_inststatuses($inst_results);
2613: if (@inststatuses == 0) {
2614: @inststatuses = ('default');
2615: }
2616: $rolesarray = \@inststatuses;
2617: }
2618: my %canmodify =
2619: &Apache::lonuserutils::can_modify_userinfo($context,$dom,$userinfo,
2620: $rolesarray);
2621: return %canmodify;
2622: }
2623:
1.252 raeburn 2624: sub get_inststatuses {
2625: my ($insthashref) = @_;
2626: my @inststatuses = ();
2627: if (ref($insthashref) eq 'HASH') {
2628: if (ref($insthashref->{'inststatus'}) eq 'ARRAY') {
2629: @inststatuses = @{$insthashref->{'inststatus'}};
2630: }
2631: }
2632: return @inststatuses;
2633: }
2634:
1.4 www 2635: # ================================================================= Phase Three
1.42 matthew 2636: sub update_user_data {
1.375 raeburn 2637: my ($r,$context,$crstype,$brcrum,$showcredits) = @_;
1.101 albertel 2638: my $uhome=&Apache::lonnet::homeserver($env{'form.ccuname'},
2639: $env{'form.ccdomain'});
1.27 matthew 2640: # Error messages
1.188 raeburn 2641: my $error = '<span class="LC_error">'.&mt('Error').': ';
1.193 raeburn 2642: my $end = '</span><br /><br />';
2643: my $rtnlink = '<a href="javascript:backPage(document.userupdate,'.
1.188 raeburn 2644: "'$env{'form.prevphase'}','modify')".'" />'.
1.219 raeburn 2645: &mt('Return to previous page').'</a>'.
2646: &Apache::loncommon::end_page();
2647: my $now = time;
1.40 www 2648: my $title;
1.101 albertel 2649: if (exists($env{'form.makeuser'})) {
1.40 www 2650: $title='Set Privileges for New User';
2651: } else {
2652: $title='Modify User Privileges';
2653: }
1.213 raeburn 2654: my $newuser = 0;
1.160 raeburn 2655: my ($jsback,$elements) = &crumb_utilities();
2656: my $jscript = '<script type="text/javascript">'."\n".
1.301 bisitz 2657: '// <![CDATA['."\n".
2658: $jsback."\n".
2659: '// ]]>'."\n".
2660: '</script>'."\n";
1.422 raeburn 2661: my %breadcrumb_text = &singleuser_breadcrumb($crstype,$context,$env{'form.ccdomain'});
1.351 raeburn 2662: push (@{$brcrum},
2663: {href => "javascript:backPage(document.userupdate)",
2664: text => $breadcrumb_text{'search'},
2665: faq => 282,
2666: bug => 'Instructor Interface',}
2667: );
2668: if ($env{'form.prevphase'} eq 'userpicked') {
2669: push(@{$brcrum},
2670: {href => "javascript:backPage(document.userupdate,'get_user_info','select')",
2671: text => $breadcrumb_text{'userpicked'},
2672: faq => 282,
2673: bug => 'Instructor Interface',});
1.233 raeburn 2674: }
1.224 raeburn 2675: my $helpitem = 'Course_Change_Privileges';
2676: if ($env{'form.action'} eq 'singlestudent') {
2677: $helpitem = 'Course_Add_Student';
1.439 raeburn 2678: } elsif ($context eq 'author') {
2679: $helpitem = 'Author_Change_Privileges';
2680: } elsif ($context eq 'domain') {
2681: $helpitem = 'Domain_Change_Privileges';
1.224 raeburn 2682: }
1.351 raeburn 2683: push(@{$brcrum},
2684: {href => "javascript:backPage(document.userupdate,'$env{'form.prevphase'}','modify')",
2685: text => $breadcrumb_text{'modify'},
2686: faq => 282,
2687: bug => 'Instructor Interface',},
2688: {href => "/adm/createuser",
2689: text => "Result",
2690: faq => 282,
2691: bug => 'Instructor Interface',
2692: help => $helpitem});
2693: my $args = {bread_crumbs => $brcrum,
2694: bread_crumbs_component => 'User Management'};
2695: if ($env{'form.popup'}) {
2696: $args->{'no_nav_bar'} = 1;
2697: }
2698: $r->print(&Apache::loncommon::start_page($title,$jscript,$args));
1.188 raeburn 2699: $r->print(&update_result_form($uhome));
1.27 matthew 2700: # Check Inputs
1.101 albertel 2701: if (! $env{'form.ccuname'} ) {
1.193 raeburn 2702: $r->print($error.&mt('No login name specified').'.'.$end.$rtnlink);
1.27 matthew 2703: return;
2704: }
1.138 albertel 2705: if ( $env{'form.ccuname'} ne
2706: &LONCAPA::clean_username($env{'form.ccuname'}) ) {
1.281 bisitz 2707: $r->print($error.&mt('Invalid login name.').' '.
2708: &mt('Only letters, numbers, periods, dashes, @, and underscores are valid.').
1.193 raeburn 2709: $end.$rtnlink);
1.27 matthew 2710: return;
2711: }
1.101 albertel 2712: if (! $env{'form.ccdomain'} ) {
1.193 raeburn 2713: $r->print($error.&mt('No domain specified').'.'.$end.$rtnlink);
1.27 matthew 2714: return;
2715: }
1.138 albertel 2716: if ( $env{'form.ccdomain'} ne
2717: &LONCAPA::clean_domain($env{'form.ccdomain'}) ) {
1.281 bisitz 2718: $r->print($error.&mt('Invalid domain name.').' '.
2719: &mt('Only letters, numbers, periods, dashes, and underscores are valid.').
1.193 raeburn 2720: $end.$rtnlink);
1.27 matthew 2721: return;
2722: }
1.219 raeburn 2723: if ($uhome eq 'no_host') {
2724: $newuser = 1;
2725: }
1.101 albertel 2726: if (! exists($env{'form.makeuser'})) {
1.29 matthew 2727: # Modifying an existing user, so check the validity of the name
2728: if ($uhome eq 'no_host') {
1.389 bisitz 2729: $r->print(
2730: $error
2731: .'<p class="LC_error">'
2732: .&mt('Unable to determine home server for [_1] in domain [_2].',
2733: '"'.$env{'form.ccuname'}.'"','"'.$env{'form.ccdomain'}.'"')
2734: .'</p>');
1.29 matthew 2735: return;
2736: }
2737: }
1.27 matthew 2738: # Determine authentication method and password for the user being modified
2739: my $amode='';
2740: my $genpwd='';
1.101 albertel 2741: if ($env{'form.login'} eq 'krb') {
1.41 albertel 2742: $amode='krb';
1.101 albertel 2743: $amode.=$env{'form.krbver'};
2744: $genpwd=$env{'form.krbarg'};
2745: } elsif ($env{'form.login'} eq 'int') {
1.27 matthew 2746: $amode='internal';
1.101 albertel 2747: $genpwd=$env{'form.intarg'};
2748: } elsif ($env{'form.login'} eq 'fsys') {
1.27 matthew 2749: $amode='unix';
1.101 albertel 2750: $genpwd=$env{'form.fsysarg'};
2751: } elsif ($env{'form.login'} eq 'loc') {
1.27 matthew 2752: $amode='localauth';
1.101 albertel 2753: $genpwd=$env{'form.locarg'};
1.27 matthew 2754: $genpwd=" " if (!$genpwd);
1.101 albertel 2755: } elsif (($env{'form.login'} eq 'nochange') ||
2756: ($env{'form.login'} eq '' )) {
1.34 matthew 2757: # There is no need to tell the user we did not change what they
2758: # did not ask us to change.
1.35 matthew 2759: # If they are creating a new user but have not specified login
2760: # information this will be caught below.
1.30 matthew 2761: } else {
1.367 golterma 2762: $r->print($error.&mt('Invalid login mode or password').$end.$rtnlink);
2763: return;
1.27 matthew 2764: }
1.164 albertel 2765:
1.188 raeburn 2766: $r->print('<h3>'.&mt('User [_1] in domain [_2]',
1.367 golterma 2767: $env{'form.ccuname'}.' ('.&Apache::loncommon::plainname($env{'form.ccuname'},
2768: $env{'form.ccdomain'}).')', $env{'form.ccdomain'}).'</h3>');
2769: my %prog_state = &Apache::lonhtmlcommon::Create_PrgWin($r,2);
1.344 bisitz 2770:
1.193 raeburn 2771: my (%alerts,%rulematch,%inst_results,%curr_rules);
1.334 raeburn 2772: my @userinfo = ('firstname','middlename','lastname','generation','permanentemail','id');
1.361 raeburn 2773: my @usertools = ('aboutme','blog','webdav','portfolio');
1.411 raeburn 2774: my @requestcourses = ('official','unofficial','community','textbook','placement');
1.362 raeburn 2775: my @requestauthor = ('requestauthor');
1.286 raeburn 2776: my ($othertitle,$usertypes,$types) =
2777: &Apache::loncommon::sorted_inst_types($env{'form.ccdomain'});
1.334 raeburn 2778: my %canmodify_status =
2779: &Apache::lonuserutils::can_modify_userinfo($context,$env{'form.ccdomain'},
2780: ['inststatus']);
1.101 albertel 2781: if ($env{'form.makeuser'}) {
1.164 albertel 2782: $r->print('<h3>'.&mt('Creating new account.').'</h3>');
1.27 matthew 2783: # Check for the authentication mode and password
2784: if (! $amode || ! $genpwd) {
1.193 raeburn 2785: $r->print($error.&mt('Invalid login mode or password').$end.$rtnlink);
1.27 matthew 2786: return;
1.18 albertel 2787: }
1.29 matthew 2788: # Determine desired host
1.101 albertel 2789: my $desiredhost = $env{'form.hserver'};
1.29 matthew 2790: if (lc($desiredhost) eq 'default') {
2791: $desiredhost = undef;
2792: } else {
1.147 albertel 2793: my %home_servers =
2794: &Apache::lonnet::get_servers($env{'form.ccdomain'},'library');
1.29 matthew 2795: if (! exists($home_servers{$desiredhost})) {
1.193 raeburn 2796: $r->print($error.&mt('Invalid home server specified').$end.$rtnlink);
2797: return;
2798: }
2799: }
2800: # Check ID format
2801: my %checkhash;
2802: my %checks = ('id' => 1);
2803: %{$checkhash{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}}} = (
1.219 raeburn 2804: 'newuser' => $newuser,
1.196 raeburn 2805: 'id' => $env{'form.cid'},
1.193 raeburn 2806: );
1.196 raeburn 2807: if ($env{'form.cid'} ne '') {
2808: &Apache::loncommon::user_rule_check(\%checkhash,\%checks,\%alerts,
2809: \%rulematch,\%inst_results,\%curr_rules);
2810: if (ref($alerts{'id'}) eq 'HASH') {
2811: if (ref($alerts{'id'}{$env{'form.ccdomain'}}) eq 'HASH') {
2812: my $domdesc =
2813: &Apache::lonnet::domain($env{'form.ccdomain'},'description');
2814: if ($alerts{'id'}{$env{'form.ccdomain'}}{$env{'form.cid'}}) {
2815: my $userchkmsg;
2816: if (ref($curr_rules{$env{'form.ccdomain'}}) eq 'HASH') {
2817: $userchkmsg =
2818: &Apache::loncommon::instrule_disallow_msg('id',
2819: $domdesc,1).
2820: &Apache::loncommon::user_rule_formats($env{'form.ccdomain'},
2821: $domdesc,$curr_rules{$env{'form.ccdomain'}}{'id'},'id');
2822: }
2823: $r->print($error.&mt('Invalid ID format').$end.
2824: $userchkmsg.$rtnlink);
2825: return;
2826: }
2827: }
1.29 matthew 2828: }
2829: }
1.367 golterma 2830: &Apache::lonhtmlcommon::Increment_PrgWin($r, \%prog_state);
1.27 matthew 2831: # Call modifyuser
2832: my $result = &Apache::lonnet::modifyuser
1.193 raeburn 2833: ($env{'form.ccdomain'},$env{'form.ccuname'},$env{'form.cid'},
1.188 raeburn 2834: $amode,$genpwd,$env{'form.cfirstname'},
2835: $env{'form.cmiddlename'},$env{'form.clastname'},
2836: $env{'form.cgeneration'},undef,$desiredhost,
2837: $env{'form.cpermanentemail'});
1.77 www 2838: $r->print(&mt('Generating user').': '.$result);
1.219 raeburn 2839: $uhome = &Apache::lonnet::homeserver($env{'form.ccuname'},
1.101 albertel 2840: $env{'form.ccdomain'});
1.334 raeburn 2841: my (%changeHash,%newcustom,%changed,%changedinfo);
1.267 raeburn 2842: if ($uhome ne 'no_host') {
1.334 raeburn 2843: if ($context eq 'domain') {
1.378 raeburn 2844: foreach my $name ('portfolio','author') {
2845: if ($env{'form.custom_'.$name.'quota'} == 1) {
2846: if ($env{'form.'.$name.'quota'} eq '') {
2847: $newcustom{$name.'quota'} = 0;
2848: } else {
2849: $newcustom{$name.'quota'} = $env{'form.'.$name.'quota'};
2850: $newcustom{$name.'quota'} =~ s/[^\d\.]//g;
2851: }
2852: if ("a_admin($newcustom{$name.'quota'},\%changeHash,$name)) {
2853: $changed{$name.'quota'} = 1;
2854: }
1.334 raeburn 2855: }
2856: }
2857: foreach my $item (@usertools) {
2858: if ($env{'form.custom'.$item} == 1) {
2859: $newcustom{$item} = $env{'form.tools_'.$item};
2860: $changed{$item} = &tool_admin($item,$newcustom{$item},
2861: \%changeHash,'tools');
2862: }
1.267 raeburn 2863: }
1.334 raeburn 2864: foreach my $item (@requestcourses) {
1.341 raeburn 2865: if ($env{'form.custom'.$item} == 1) {
2866: $newcustom{$item} = $env{'form.crsreq_'.$item};
2867: if ($env{'form.crsreq_'.$item} eq 'autolimit') {
2868: $newcustom{$item} .= '=';
1.383 raeburn 2869: $env{'form.crsreq_'.$item.'_limit'} =~ s/\D+//g;
2870: if ($env{'form.crsreq_'.$item.'_limit'}) {
1.341 raeburn 2871: $newcustom{$item} .= $env{'form.crsreq_'.$item.'_limit'};
2872: }
1.334 raeburn 2873: }
1.341 raeburn 2874: $changed{$item} = &tool_admin($item,$newcustom{$item},
2875: \%changeHash,'requestcourses');
1.334 raeburn 2876: }
1.275 raeburn 2877: }
1.362 raeburn 2878: if ($env{'form.customrequestauthor'} == 1) {
2879: $newcustom{'requestauthor'} = $env{'form.requestauthor'};
2880: $changed{'requestauthor'} = &tool_admin('requestauthor',
2881: $newcustom{'requestauthor'},
2882: \%changeHash,'requestauthor');
2883: }
1.275 raeburn 2884: }
1.334 raeburn 2885: if ($canmodify_status{'inststatus'}) {
2886: if (exists($env{'form.inststatus'})) {
2887: my @inststatuses = &Apache::loncommon::get_env_multiple('form.inststatus');
2888: if (@inststatuses > 0) {
2889: $changeHash{'inststatus'} = join(',',@inststatuses);
2890: $changed{'inststatus'} = $changeHash{'inststatus'};
1.306 raeburn 2891: }
2892: }
1.232 raeburn 2893: }
1.334 raeburn 2894: if (keys(%changed)) {
2895: foreach my $item (@userinfo) {
2896: $changeHash{$item} = $env{'form.c'.$item};
1.286 raeburn 2897: }
1.267 raeburn 2898: my $chgresult =
2899: &Apache::lonnet::put('environment',\%changeHash,
2900: $env{'form.ccdomain'},$env{'form.ccuname'});
2901: }
1.232 raeburn 2902: }
1.219 raeburn 2903: $r->print('<br />'.&mt('Home server').': '.$uhome.' '.
2904: &Apache::lonnet::hostname($uhome));
1.101 albertel 2905: } elsif (($env{'form.login'} ne 'nochange') &&
2906: ($env{'form.login'} ne '' )) {
1.27 matthew 2907: # Modify user privileges
2908: if (! $amode || ! $genpwd) {
1.193 raeburn 2909: $r->print($error.'Invalid login mode or password'.$end.$rtnlink);
1.27 matthew 2910: return;
1.20 harris41 2911: }
1.395 bisitz 2912: # Only allow authentication modification if the person has authority
1.101 albertel 2913: if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'})) {
1.20 harris41 2914: $r->print('Modifying authentication: '.
1.31 matthew 2915: &Apache::lonnet::modifyuserauth(
1.101 albertel 2916: $env{'form.ccdomain'},$env{'form.ccuname'},
1.21 harris41 2917: $amode,$genpwd));
1.102 albertel 2918: $r->print('<br />'.&mt('Home server').': '.&Apache::lonnet::homeserver
1.101 albertel 2919: ($env{'form.ccuname'},$env{'form.ccdomain'}));
1.4 www 2920: } else {
1.27 matthew 2921: # Okay, this is a non-fatal error.
1.395 bisitz 2922: $r->print($error.&mt('You do not have the authority to modify this users authentication information.').$end);
1.27 matthew 2923: }
1.28 matthew 2924: }
1.344 bisitz 2925: $r->rflush(); # Finish display of header before time consuming actions start
1.367 golterma 2926: &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state);
1.28 matthew 2927: ##
1.375 raeburn 2928: my (@userroles,%userupdate,$cnum,$cdom,$defaultcredits,%namechanged);
1.213 raeburn 2929: if ($context eq 'course') {
1.375 raeburn 2930: ($cnum,$cdom) =
2931: &Apache::lonuserutils::get_course_identity();
1.318 raeburn 2932: $crstype = &Apache::loncommon::course_type($cdom.'_'.$cnum);
1.375 raeburn 2933: if ($showcredits) {
2934: $defaultcredits = &Apache::lonuserutils::get_defaultcredits($cdom,$cnum);
2935: }
1.213 raeburn 2936: }
1.101 albertel 2937: if (! $env{'form.makeuser'} ) {
1.28 matthew 2938: # Check for need to change
2939: my %userenv = &Apache::lonnet::get
1.134 raeburn 2940: ('environment',['firstname','middlename','lastname','generation',
1.378 raeburn 2941: 'id','permanentemail','portfolioquota','authorquota','inststatus',
2942: 'tools.aboutme','tools.blog','tools.webdav','tools.portfolio',
1.361 raeburn 2943: 'requestcourses.official','requestcourses.unofficial',
1.384 raeburn 2944: 'requestcourses.community','requestcourses.textbook',
2945: 'reqcrsotherdom.official','reqcrsotherdom.unofficial',
2946: 'reqcrsotherdom.community','reqcrsotherdom.textbook',
1.427 raeburn 2947: 'reqcrsotherdom.placement','requestauthor'],
1.160 raeburn 2948: $env{'form.ccdomain'},$env{'form.ccuname'});
1.28 matthew 2949: my ($tmp) = keys(%userenv);
2950: if ($tmp =~ /^(con_lost|error)/i) {
2951: %userenv = ();
2952: }
1.206 raeburn 2953: my $no_forceid_alert;
2954: # Check to see if user information can be changed
2955: my %domconfig =
2956: &Apache::lonnet::get_dom('configuration',['usermodification'],
2957: $env{'form.ccdomain'});
1.213 raeburn 2958: my @statuses = ('active','future');
2959: my %roles = &Apache::lonnet::get_my_roles($env{'form.ccuname'},$env{'form.ccdomain'},'userroles',\@statuses,undef,$env{'request.role.domain'});
2960: my ($auname,$audom);
1.220 raeburn 2961: if ($context eq 'author') {
1.206 raeburn 2962: $auname = $env{'user.name'};
2963: $audom = $env{'user.domain'};
2964: }
2965: foreach my $item (keys(%roles)) {
1.220 raeburn 2966: my ($rolenum,$roledom,$role) = split(/:/,$item,-1);
1.206 raeburn 2967: if ($context eq 'course') {
2968: if ($cnum ne '' && $cdom ne '') {
2969: if ($rolenum eq $cnum && $roledom eq $cdom) {
2970: if (!grep(/^\Q$role\E$/,@userroles)) {
2971: push(@userroles,$role);
2972: }
2973: }
2974: }
2975: } elsif ($context eq 'author') {
2976: if ($rolenum eq $auname && $roledom eq $audom) {
2977: if (!grep(/^\Q$role\E$/,@userroles)) {
2978: push(@userroles,$role);
2979: }
2980: }
2981: }
2982: }
1.220 raeburn 2983: if ($env{'form.action'} eq 'singlestudent') {
2984: if (!grep(/^st$/,@userroles)) {
2985: push(@userroles,'st');
2986: }
2987: } else {
2988: # Check for course or co-author roles being activated or re-enabled
2989: if ($context eq 'author' || $context eq 'course') {
2990: foreach my $key (keys(%env)) {
2991: if ($context eq 'author') {
2992: if ($key=~/^form\.act_\Q$audom\E_\Q$auname\E_([^_]+)/) {
2993: if (!grep(/^\Q$1\E$/,@userroles)) {
2994: push(@userroles,$1);
2995: }
2996: } elsif ($key =~/^form\.ren\:\Q$audom\E\/\Q$auname\E_([^_]+)/) {
2997: if (!grep(/^\Q$1\E$/,@userroles)) {
2998: push(@userroles,$1);
2999: }
1.206 raeburn 3000: }
1.220 raeburn 3001: } elsif ($context eq 'course') {
3002: if ($key=~/^form\.act_\Q$cdom\E_\Q$cnum\E_([^_]+)/) {
3003: if (!grep(/^\Q$1\E$/,@userroles)) {
3004: push(@userroles,$1);
3005: }
3006: } elsif ($key =~/^form\.ren\:\Q$cdom\E\/\Q$cnum\E(\/?\w*)_([^_]+)/) {
3007: if (!grep(/^\Q$1\E$/,@userroles)) {
3008: push(@userroles,$1);
3009: }
1.206 raeburn 3010: }
3011: }
3012: }
3013: }
3014: }
3015: #Check to see if we can change personal data for the user
3016: my (@mod_disallowed,@longroles);
3017: foreach my $role (@userroles) {
3018: if ($role eq 'cr') {
3019: push(@longroles,'Custom');
3020: } else {
1.318 raeburn 3021: push(@longroles,&Apache::lonnet::plaintext($role,$crstype));
1.206 raeburn 3022: }
3023: }
1.219 raeburn 3024: my %canmodify = &Apache::lonuserutils::can_modify_userinfo($context,$env{'form.ccdomain'},\@userinfo,\@userroles);
3025: foreach my $item (@userinfo) {
1.28 matthew 3026: # Strip leading and trailing whitespace
1.203 raeburn 3027: $env{'form.c'.$item} =~ s/(\s+$|^\s+)//g;
1.219 raeburn 3028: if (!$canmodify{$item}) {
1.207 raeburn 3029: if (defined($env{'form.c'.$item})) {
3030: if ($env{'form.c'.$item} ne $userenv{$item}) {
3031: push(@mod_disallowed,$item);
3032: }
1.206 raeburn 3033: }
3034: $env{'form.c'.$item} = $userenv{$item};
3035: }
1.28 matthew 3036: }
1.259 bisitz 3037: # Check to see if we can change the Student/Employee ID
1.196 raeburn 3038: my $forceid = $env{'form.forceid'};
3039: my $recurseid = $env{'form.recurseid'};
3040: my (%alerts,%rulematch,%idinst_results,%curr_rules,%got_rules);
1.203 raeburn 3041: my %uidhash = &Apache::lonnet::idrget($env{'form.ccdomain'},
3042: $env{'form.ccuname'});
3043: if (($uidhash{$env{'form.ccuname'}}) &&
3044: ($uidhash{$env{'form.ccuname'}}!~/error\:/) &&
3045: (!$forceid)) {
3046: if ($env{'form.cid'} ne $uidhash{$env{'form.ccuname'}}) {
3047: $env{'form.cid'} = $userenv{'id'};
1.293 bisitz 3048: $no_forceid_alert = &mt('New student/employee ID does not match existing ID for this user.')
1.259 bisitz 3049: .'<br />'
3050: .&mt("Change is not permitted without checking the 'Force ID change' checkbox on the previous page.")
3051: .'<br />'."\n";
1.203 raeburn 3052: }
3053: }
3054: if ($env{'form.cid'} ne $userenv{'id'}) {
1.196 raeburn 3055: my $checkhash;
3056: my $checks = { 'id' => 1 };
3057: $checkhash->{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}} =
3058: { 'newuser' => $newuser,
3059: 'id' => $env{'form.cid'},
3060: };
3061: &Apache::loncommon::user_rule_check($checkhash,$checks,
3062: \%alerts,\%rulematch,\%idinst_results,\%curr_rules,\%got_rules);
3063: if (ref($alerts{'id'}) eq 'HASH') {
3064: if (ref($alerts{'id'}{$env{'form.ccdomain'}}) eq 'HASH') {
1.203 raeburn 3065: $env{'form.cid'} = $userenv{'id'};
1.196 raeburn 3066: }
3067: }
3068: }
1.378 raeburn 3069: my (%quotachanged,%oldquota,%newquota,%olddefquota,%newdefquota,
3070: $oldinststatus,$newinststatus,%oldisdefault,%newisdefault,%oldsettings,
1.339 raeburn 3071: %oldsettingstext,%newsettings,%newsettingstext,@disporder,
1.378 raeburn 3072: %oldsettingstatus,%newsettingstatus);
1.334 raeburn 3073: @disporder = ('inststatus');
3074: if ($env{'request.role.domain'} eq $env{'form.ccdomain'}) {
1.362 raeburn 3075: push(@disporder,'requestcourses','requestauthor');
1.334 raeburn 3076: } else {
3077: push(@disporder,'reqcrsotherdom');
3078: }
3079: push(@disporder,('quota','tools'));
1.338 raeburn 3080: $oldinststatus = $userenv{'inststatus'};
1.378 raeburn 3081: foreach my $name ('portfolio','author') {
3082: ($olddefquota{$name},$oldsettingstatus{$name}) =
3083: &Apache::loncommon::default_quota($env{'form.ccdomain'},$oldinststatus,$name);
3084: ($newdefquota{$name},$newsettingstatus{$name}) = ($olddefquota{$name},$oldsettingstatus{$name});
3085: }
1.334 raeburn 3086: my %canshow;
1.220 raeburn 3087: if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
1.334 raeburn 3088: $canshow{'quota'} = 1;
1.220 raeburn 3089: }
1.267 raeburn 3090: if (&Apache::lonnet::allowed('mut',$env{'form.ccdomain'})) {
1.334 raeburn 3091: $canshow{'tools'} = 1;
1.267 raeburn 3092: }
1.275 raeburn 3093: if (&Apache::lonnet::allowed('ccc',$env{'form.ccdomain'})) {
1.334 raeburn 3094: $canshow{'requestcourses'} = 1;
1.300 raeburn 3095: } elsif (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
1.334 raeburn 3096: $canshow{'reqcrsotherdom'} = 1;
1.275 raeburn 3097: }
1.286 raeburn 3098: if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'})) {
1.334 raeburn 3099: $canshow{'inststatus'} = 1;
1.286 raeburn 3100: }
1.362 raeburn 3101: if (&Apache::lonnet::allowed('cau',$env{'form.ccdomain'})) {
3102: $canshow{'requestauthor'} = 1;
3103: }
1.267 raeburn 3104: my (%changeHash,%changed);
1.286 raeburn 3105: if ($oldinststatus eq '') {
1.334 raeburn 3106: $oldsettings{'inststatus'} = $othertitle;
1.286 raeburn 3107: } else {
3108: if (ref($usertypes) eq 'HASH') {
1.334 raeburn 3109: $oldsettings{'inststatus'} = join(', ',map{ $usertypes->{ &unescape($_) }; } (split(/:/,$userenv{'inststatus'})));
1.286 raeburn 3110: } else {
1.334 raeburn 3111: $oldsettings{'inststatus'} = join(', ',map{ &unescape($_); } (split(/:/,$userenv{'inststatus'})));
1.286 raeburn 3112: }
3113: }
3114: $changeHash{'inststatus'} = $userenv{'inststatus'};
1.334 raeburn 3115: if ($canmodify_status{'inststatus'}) {
3116: $canshow{'inststatus'} = 1;
1.286 raeburn 3117: if (exists($env{'form.inststatus'})) {
3118: my @inststatuses = &Apache::loncommon::get_env_multiple('form.inststatus');
3119: if (@inststatuses > 0) {
3120: $newinststatus = join(':',map { &escape($_); } @inststatuses);
3121: $changeHash{'inststatus'} = $newinststatus;
3122: if ($newinststatus ne $oldinststatus) {
3123: $changed{'inststatus'} = $newinststatus;
1.378 raeburn 3124: foreach my $name ('portfolio','author') {
3125: ($newdefquota{$name},$newsettingstatus{$name}) =
3126: &Apache::loncommon::default_quota($env{'form.ccdomain'},$newinststatus,$name);
3127: }
1.286 raeburn 3128: }
3129: if (ref($usertypes) eq 'HASH') {
1.334 raeburn 3130: $newsettings{'inststatus'} = join(', ',map{ $usertypes->{$_}; } (@inststatuses));
1.286 raeburn 3131: } else {
1.337 raeburn 3132: $newsettings{'inststatus'} = join(', ',@inststatuses);
1.286 raeburn 3133: }
1.334 raeburn 3134: }
3135: } else {
3136: $newinststatus = '';
3137: $changeHash{'inststatus'} = $newinststatus;
3138: $newsettings{'inststatus'} = $othertitle;
3139: if ($newinststatus ne $oldinststatus) {
3140: $changed{'inststatus'} = $changeHash{'inststatus'};
1.378 raeburn 3141: foreach my $name ('portfolio','author') {
3142: ($newdefquota{$name},$newsettingstatus{$name}) =
3143: &Apache::loncommon::default_quota($env{'form.ccdomain'},$newinststatus,$name);
3144: }
1.286 raeburn 3145: }
3146: }
1.334 raeburn 3147: } elsif ($context ne 'selfcreate') {
3148: $canshow{'inststatus'} = 1;
1.337 raeburn 3149: $newsettings{'inststatus'} = $oldsettings{'inststatus'};
1.286 raeburn 3150: }
1.378 raeburn 3151: foreach my $name ('portfolio','author') {
3152: $changeHash{$name.'quota'} = $userenv{$name.'quota'};
3153: }
1.334 raeburn 3154: if ($context eq 'domain') {
1.378 raeburn 3155: foreach my $name ('portfolio','author') {
3156: if ($userenv{$name.'quota'} ne '') {
3157: $oldquota{$name} = $userenv{$name.'quota'};
3158: if ($env{'form.custom_'.$name.'quota'} == 1) {
3159: if ($env{'form.'.$name.'quota'} eq '') {
3160: $newquota{$name} = 0;
3161: } else {
3162: $newquota{$name} = $env{'form.'.$name.'quota'};
3163: $newquota{$name} =~ s/[^\d\.]//g;
3164: }
3165: if ($newquota{$name} != $oldquota{$name}) {
3166: if ("a_admin($newquota{$name},\%changeHash,$name)) {
3167: $changed{$name.'quota'} = 1;
3168: }
3169: }
1.334 raeburn 3170: } else {
1.378 raeburn 3171: if ("a_admin('',\%changeHash,$name)) {
3172: $changed{$name.'quota'} = 1;
3173: $newquota{$name} = $newdefquota{$name};
3174: $newisdefault{$name} = 1;
3175: }
1.334 raeburn 3176: }
1.149 raeburn 3177: } else {
1.378 raeburn 3178: $oldisdefault{$name} = 1;
3179: $oldquota{$name} = $olddefquota{$name};
3180: if ($env{'form.custom_'.$name.'quota'} == 1) {
3181: if ($env{'form.'.$name.'quota'} eq '') {
3182: $newquota{$name} = 0;
3183: } else {
3184: $newquota{$name} = $env{'form.'.$name.'quota'};
3185: $newquota{$name} =~ s/[^\d\.]//g;
3186: }
3187: if ("a_admin($newquota{$name},\%changeHash,$name)) {
3188: $changed{$name.'quota'} = 1;
3189: }
1.334 raeburn 3190: } else {
1.378 raeburn 3191: $newquota{$name} = $newdefquota{$name};
3192: $newisdefault{$name} = 1;
1.334 raeburn 3193: }
1.378 raeburn 3194: }
3195: if ($oldisdefault{$name}) {
3196: $oldsettingstext{'quota'}{$name} = &get_defaultquota_text($oldsettingstatus{$name});
1.383 raeburn 3197: } else {
3198: $oldsettingstext{'quota'}{$name} = &mt('custom quota: [_1] MB',$oldquota{$name});
1.378 raeburn 3199: }
3200: if ($newisdefault{$name}) {
3201: $newsettingstext{'quota'}{$name} = &get_defaultquota_text($newsettingstatus{$name});
1.383 raeburn 3202: } else {
3203: $newsettingstext{'quota'}{$name} = &mt('custom quota: [_1] MB',$newquota{$name});
1.134 raeburn 3204: }
3205: }
1.334 raeburn 3206: &tool_changes('tools',\@usertools,\%oldsettings,\%oldsettingstext,\%userenv,
3207: \%changeHash,\%changed,\%newsettings,\%newsettingstext);
3208: if ($env{'form.ccdomain'} eq $env{'request.role.domain'}) {
3209: &tool_changes('requestcourses',\@requestcourses,\%oldsettings,\%oldsettingstext,
3210: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
1.384 raeburn 3211: &tool_changes('requestauthor',\@requestauthor,\%oldsettings,\%oldsettingstext,
3212: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
1.149 raeburn 3213: } else {
1.334 raeburn 3214: &tool_changes('reqcrsotherdom',\@requestcourses,\%oldsettings,\%oldsettingstext,
3215: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
1.149 raeburn 3216: }
3217: }
1.334 raeburn 3218: foreach my $item (@userinfo) {
3219: if ($env{'form.c'.$item} ne $userenv{$item}) {
3220: $namechanged{$item} = 1;
3221: }
1.204 raeburn 3222: }
1.378 raeburn 3223: foreach my $name ('portfolio','author') {
1.390 bisitz 3224: $oldsettings{'quota'}{$name} = &mt('[_1] MB',$oldquota{$name});
3225: $newsettings{'quota'}{$name} = &mt('[_1] MB',$newquota{$name});
1.378 raeburn 3226: }
1.334 raeburn 3227: if ((keys(%namechanged) > 0) || (keys(%changed) > 0)) {
1.267 raeburn 3228: my ($chgresult,$namechgresult);
3229: if (keys(%changed) > 0) {
3230: $chgresult =
1.204 raeburn 3231: &Apache::lonnet::put('environment',\%changeHash,
3232: $env{'form.ccdomain'},$env{'form.ccuname'});
1.267 raeburn 3233: if ($chgresult eq 'ok') {
3234: if (($env{'user.name'} eq $env{'form.ccuname'}) &&
3235: ($env{'user.domain'} eq $env{'form.ccdomain'})) {
1.270 raeburn 3236: my %newenvhash;
3237: foreach my $key (keys(%changed)) {
1.411 raeburn 3238: if (($key eq 'official') || ($key eq 'unofficial') ||
3239: ($key eq 'community') || ($key eq 'textbook') ||
3240: ($key eq 'placement')) {
1.279 raeburn 3241: $newenvhash{'environment.requestcourses.'.$key} =
3242: $changeHash{'requestcourses.'.$key};
1.362 raeburn 3243: if ($changeHash{'requestcourses.'.$key}) {
1.332 raeburn 3244: $newenvhash{'environment.canrequest.'.$key} = 1;
1.279 raeburn 3245: } else {
3246: $newenvhash{'environment.canrequest.'.$key} =
3247: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
3248: $key,'reload','requestcourses');
3249: }
1.362 raeburn 3250: } elsif ($key eq 'requestauthor') {
3251: $newenvhash{'environment.'.$key} = $changeHash{$key};
3252: if ($changeHash{$key}) {
3253: $newenvhash{'environment.canrequest.author'} = 1;
3254: } else {
3255: $newenvhash{'environment.canrequest.author'} =
3256: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
3257: $key,'reload','requestauthor');
3258: }
1.275 raeburn 3259: } elsif ($key ne 'quota') {
1.270 raeburn 3260: $newenvhash{'environment.tools.'.$key} =
3261: $changeHash{'tools.'.$key};
1.279 raeburn 3262: if ($changeHash{'tools.'.$key} ne '') {
3263: $newenvhash{'environment.availabletools.'.$key} =
3264: $changeHash{'tools.'.$key};
3265: } else {
3266: $newenvhash{'environment.availabletools.'.$key} =
1.367 golterma 3267: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
3268: $key,'reload','tools');
1.279 raeburn 3269: }
1.270 raeburn 3270: }
3271: }
1.271 raeburn 3272: if (keys(%newenvhash)) {
3273: &Apache::lonnet::appenv(\%newenvhash);
3274: }
1.267 raeburn 3275: }
3276: }
1.204 raeburn 3277: }
1.334 raeburn 3278: if (keys(%namechanged) > 0) {
1.337 raeburn 3279: foreach my $field (@userinfo) {
3280: $changeHash{$field} = $env{'form.c'.$field};
3281: }
3282: # Make the change
1.204 raeburn 3283: $namechgresult =
3284: &Apache::lonnet::modifyuser($env{'form.ccdomain'},
3285: $env{'form.ccuname'},$changeHash{'id'},undef,undef,
3286: $changeHash{'firstname'},$changeHash{'middlename'},
3287: $changeHash{'lastname'},$changeHash{'generation'},
1.337 raeburn 3288: $changeHash{'id'},undef,$changeHash{'permanentemail'},undef,\@userinfo);
1.220 raeburn 3289: %userupdate = (
3290: lastname => $env{'form.clastname'},
3291: middlename => $env{'form.cmiddlename'},
3292: firstname => $env{'form.cfirstname'},
3293: generation => $env{'form.cgeneration'},
3294: id => $env{'form.cid'},
3295: );
1.204 raeburn 3296: }
1.334 raeburn 3297: if (((keys(%namechanged) > 0) && $namechgresult eq 'ok') ||
1.267 raeburn 3298: ((keys(%changed) > 0) && $chgresult eq 'ok')) {
1.28 matthew 3299: # Tell the user we changed the name
1.334 raeburn 3300: &display_userinfo($r,1,\@disporder,\%canshow,\@requestcourses,
1.362 raeburn 3301: \@usertools,\@requestauthor,\%userenv,\%changed,\%namechanged,
1.334 raeburn 3302: \%oldsettings, \%oldsettingstext,\%newsettings,
3303: \%newsettingstext);
1.203 raeburn 3304: if ($env{'form.cid'} ne $userenv{'id'}) {
3305: &Apache::lonnet::idput($env{'form.ccdomain'},
1.407 raeburn 3306: {$env{'form.ccuname'} => $env{'form.cid'}},$uhome,'ids');
1.203 raeburn 3307: if (($recurseid) &&
3308: (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'}))) {
3309: my $idresult =
3310: &Apache::lonuserutils::propagate_id_change(
3311: $env{'form.ccuname'},$env{'form.ccdomain'},
3312: \%userupdate);
3313: $r->print('<br />'.$idresult.'<br />');
3314: }
1.196 raeburn 3315: }
1.149 raeburn 3316: if (($env{'form.ccdomain'} eq $env{'user.domain'}) &&
3317: ($env{'form.ccuname'} eq $env{'user.name'})) {
3318: my %newenvhash;
3319: foreach my $key (keys(%changeHash)) {
3320: $newenvhash{'environment.'.$key} = $changeHash{$key};
3321: }
1.238 raeburn 3322: &Apache::lonnet::appenv(\%newenvhash);
1.149 raeburn 3323: }
1.28 matthew 3324: } else { # error occurred
1.389 bisitz 3325: $r->print(
3326: '<p class="LC_error">'
3327: .&mt('Unable to successfully change environment for [_1] in domain [_2].',
3328: '"'.$env{'form.ccuname'}.'"',
3329: '"'.$env{'form.ccdomain'}.'"')
3330: .'</p>');
1.28 matthew 3331: }
1.334 raeburn 3332: } else { # End of if ($env ... ) logic
1.275 raeburn 3333: # They did not want to change the users name, quota, tool availability,
3334: # or ability to request creation of courses,
1.267 raeburn 3335: # but we can still tell them what the name and quota and availabilities are
1.334 raeburn 3336: &display_userinfo($r,undef,\@disporder,\%canshow,\@requestcourses,
1.362 raeburn 3337: \@usertools,\@requestauthor,\%userenv,\%changed,\%namechanged,\%oldsettings,
1.334 raeburn 3338: \%oldsettingstext,\%newsettings,\%newsettingstext);
1.28 matthew 3339: }
1.206 raeburn 3340: if (@mod_disallowed) {
3341: my ($rolestr,$contextname);
3342: if (@longroles > 0) {
3343: $rolestr = join(', ',@longroles);
3344: } else {
3345: $rolestr = &mt('No roles');
3346: }
3347: if ($context eq 'course') {
1.399 bisitz 3348: $contextname = 'course';
1.206 raeburn 3349: } elsif ($context eq 'author') {
1.399 bisitz 3350: $contextname = 'co-author';
1.206 raeburn 3351: }
3352: $r->print(&mt('The following fields were not updated: ').'<ul>');
3353: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
3354: foreach my $field (@mod_disallowed) {
3355: $r->print('<li>'.$fieldtitles{$field}.'</li>'."\n");
3356: }
1.207 raeburn 3357: $r->print('</ul>');
3358: if (@mod_disallowed == 1) {
1.399 bisitz 3359: $r->print(&mt("You do not have the authority to change this field given the user's current set of active/future $contextname roles:"));
1.207 raeburn 3360: } else {
1.399 bisitz 3361: $r->print(&mt("You do not have the authority to change these fields given the user's current set of active/future $contextname roles:"));
1.207 raeburn 3362: }
1.292 bisitz 3363: my $helplink = 'javascript:helpMenu('."'display'".')';
3364: $r->print('<span class="LC_cusr_emph">'.$rolestr.'</span><br />'
3365: .&mt('Please contact your [_1]helpdesk[_2] for more information.'
3366: ,'<a href="'.$helplink.'">','</a>')
3367: .'<br />');
1.206 raeburn 3368: }
1.259 bisitz 3369: $r->print('<span class="LC_warning">'
3370: .$no_forceid_alert
3371: .&Apache::lonuserutils::print_namespacing_alerts($env{'form.ccdomain'},\%alerts,\%curr_rules)
3372: .'</span>');
1.4 www 3373: }
1.367 golterma 3374: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
1.220 raeburn 3375: if ($env{'form.action'} eq 'singlestudent') {
1.375 raeburn 3376: &enroll_single_student($r,$uhome,$amode,$genpwd,$now,$newuser,$context,
3377: $crstype,$showcredits,$defaultcredits);
1.386 bisitz 3378: my $linktext = ($crstype eq 'Community' ?
3379: &mt('Enroll Another Member') : &mt('Enroll Another Student'));
3380: $r->print(
3381: &Apache::lonhtmlcommon::actionbox([
3382: '<a href="javascript:backPage(document.userupdate)">'
3383: .($crstype eq 'Community' ?
3384: &mt('Enroll Another Member') : &mt('Enroll Another Student'))
3385: .'</a>']));
1.220 raeburn 3386: } else {
1.375 raeburn 3387: my @rolechanges = &update_roles($r,$context,$showcredits);
1.334 raeburn 3388: if (keys(%namechanged) > 0) {
1.220 raeburn 3389: if ($context eq 'course') {
3390: if (@userroles > 0) {
1.225 raeburn 3391: if ((@rolechanges == 0) ||
3392: (!(grep(/^st$/,@rolechanges)))) {
3393: if (grep(/^st$/,@userroles)) {
3394: my $classlistupdated =
3395: &Apache::lonuserutils::update_classlist($cdom,
1.220 raeburn 3396: $cnum,$env{'form.ccdomain'},
3397: $env{'form.ccuname'},\%userupdate);
1.225 raeburn 3398: }
1.220 raeburn 3399: }
3400: }
3401: }
3402: }
1.226 raeburn 3403: my $userinfo = &Apache::loncommon::plainname($env{'form.ccuname'},
1.233 raeburn 3404: $env{'form.ccdomain'});
3405: if ($env{'form.popup'}) {
3406: $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a></p>');
3407: } else {
1.367 golterma 3408: $r->print('<br />'.&Apache::lonhtmlcommon::actionbox(['<a href="javascript:backPage(document.userupdate,'."'$env{'form.prevphase'}','modify'".')">'
3409: .&mt('Modify this user: [_1]','<span class="LC_cusr_emph">'.$env{'form.ccuname'}.':'.$env{'form.ccdomain'}.' ('.$userinfo.')</span>').'</a>',
3410: '<a href="javascript:backPage(document.userupdate)">'.&mt('Create/Modify Another User').'</a>']));
1.233 raeburn 3411: }
1.220 raeburn 3412: }
3413: }
3414:
1.334 raeburn 3415: sub display_userinfo {
1.362 raeburn 3416: my ($r,$changed,$order,$canshow,$requestcourses,$usertools,$requestauthor,
3417: $userenv,$changedhash,$namechangedhash,$oldsetting,$oldsettingtext,
1.334 raeburn 3418: $newsetting,$newsettingtext) = @_;
3419: return unless (ref($order) eq 'ARRAY' &&
3420: ref($canshow) eq 'HASH' &&
3421: ref($requestcourses) eq 'ARRAY' &&
1.362 raeburn 3422: ref($requestauthor) eq 'ARRAY' &&
1.334 raeburn 3423: ref($usertools) eq 'ARRAY' &&
3424: ref($userenv) eq 'HASH' &&
3425: ref($changedhash) eq 'HASH' &&
3426: ref($oldsetting) eq 'HASH' &&
3427: ref($oldsettingtext) eq 'HASH' &&
3428: ref($newsetting) eq 'HASH' &&
3429: ref($newsettingtext) eq 'HASH');
3430: my %lt=&Apache::lonlocal::texthash(
1.372 raeburn 3431: 'ui' => 'User Information',
1.334 raeburn 3432: 'uic' => 'User Information Changed',
3433: 'firstname' => 'First Name',
3434: 'middlename' => 'Middle Name',
3435: 'lastname' => 'Last Name',
3436: 'generation' => 'Generation',
3437: 'id' => 'Student/Employee ID',
3438: 'permanentemail' => 'Permanent e-mail address',
1.378 raeburn 3439: 'portfolioquota' => 'Disk space allocated to portfolio files',
1.385 bisitz 3440: 'authorquota' => 'Disk space allocated to Authoring Space',
1.334 raeburn 3441: 'blog' => 'Blog Availability',
1.361 raeburn 3442: 'webdav' => 'WebDAV Availability',
1.334 raeburn 3443: 'aboutme' => 'Personal Information Page Availability',
3444: 'portfolio' => 'Portfolio Availability',
3445: 'official' => 'Can Request Official Courses',
3446: 'unofficial' => 'Can Request Unofficial Courses',
3447: 'community' => 'Can Request Communities',
1.384 raeburn 3448: 'textbook' => 'Can Request Textbook Courses',
1.411 raeburn 3449: 'placement' => 'Can Request Placement Tests',
1.362 raeburn 3450: 'requestauthor' => 'Can Request Author Role',
1.334 raeburn 3451: 'inststatus' => "Affiliation",
3452: 'prvs' => 'Previous Value:',
3453: 'chto' => 'Changed To:'
3454: );
3455: if ($changed) {
1.372 raeburn 3456: $r->print('<h3>'.$lt{'uic'}.'</h3>'.
1.367 golterma 3457: &Apache::loncommon::start_data_table().
3458: &Apache::loncommon::start_data_table_header_row());
1.334 raeburn 3459: $r->print("<th> </th>\n");
1.367 golterma 3460: $r->print('<th><b>'.$lt{'prvs'}.'</b></th>');
3461: $r->print('<th><span class="LC_nobreak"><b>'.$lt{'chto'}.'</b></span></th>');
3462: $r->print(&Apache::loncommon::end_data_table_header_row());
3463: my @userinfo = ('firstname','middlename','lastname','generation','permanentemail','id');
3464:
1.334 raeburn 3465: foreach my $item (@userinfo) {
3466: my $value = $env{'form.c'.$item};
1.367 golterma 3467: #show changes only:
1.383 raeburn 3468: unless ($value eq $userenv->{$item}){
1.367 golterma 3469: $r->print(&Apache::loncommon::start_data_table_row());
3470: $r->print("<td>$lt{$item}</td>\n");
1.383 raeburn 3471: $r->print("<td>".$userenv->{$item}."</td>\n");
1.367 golterma 3472: $r->print("<td>$value </td>\n");
3473: $r->print(&Apache::loncommon::end_data_table_row());
1.334 raeburn 3474: }
3475: }
3476: foreach my $entry (@{$order}) {
1.383 raeburn 3477: if ($canshow->{$entry}) {
3478: if (($entry eq 'requestcourses') || ($entry eq 'reqcrsotherdom') || ($entry eq 'requestauthor')) {
3479: my @items;
3480: if ($entry eq 'requestauthor') {
3481: @items = ($entry);
3482: } else {
3483: @items = @{$requestcourses};
1.384 raeburn 3484: }
1.383 raeburn 3485: foreach my $item (@items) {
3486: if (($newsetting->{$item} ne $oldsetting->{$item}) ||
3487: ($newsettingtext->{$item} ne $oldsettingtext->{$item})) {
3488: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3489: $r->print("<td>$lt{$item}</td>\n");
3490: $r->print("<td>".$oldsetting->{$item});
3491: if ($oldsettingtext->{$item}) {
3492: if ($oldsetting->{$item}) {
3493: $r->print(' -- ');
3494: }
3495: $r->print($oldsettingtext->{$item});
3496: }
3497: $r->print("</td>\n");
3498: $r->print("<td>".$newsetting->{$item});
3499: if ($newsettingtext->{$item}) {
3500: if ($newsetting->{$item}) {
3501: $r->print(' -- ');
3502: }
3503: $r->print($newsettingtext->{$item});
3504: }
3505: $r->print("</td>\n");
3506: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.334 raeburn 3507: }
3508: }
3509: } elsif ($entry eq 'tools') {
3510: foreach my $item (@{$usertools}) {
1.383 raeburn 3511: if ($newsetting->{$item} ne $oldsetting->{$item}) {
3512: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3513: $r->print("<td>$lt{$item}</td>\n");
3514: $r->print("<td>".$oldsetting->{$item}.' '.$oldsettingtext->{$item}."</td>\n");
3515: $r->print("<td>".$newsetting->{$item}.' '.$newsettingtext->{$item}."</td>\n");
3516: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.334 raeburn 3517: }
3518: }
1.378 raeburn 3519: } elsif ($entry eq 'quota') {
3520: if ((ref($oldsetting->{$entry}) eq 'HASH') && (ref($oldsettingtext->{$entry}) eq 'HASH') &&
3521: (ref($newsetting->{$entry}) eq 'HASH') && (ref($newsettingtext->{$entry}) eq 'HASH')) {
3522: foreach my $name ('portfolio','author') {
1.383 raeburn 3523: if ($newsetting->{$entry}->{$name} ne $oldsetting->{$entry}->{$name}) {
3524: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3525: $r->print("<td>$lt{$name.$entry}</td>\n");
3526: $r->print("<td>".$oldsettingtext->{$entry}->{$name}."</td>\n");
3527: $r->print("<td>".$newsettingtext->{$entry}->{$name}."</td>\n");
3528: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.378 raeburn 3529: }
3530: }
3531: }
1.334 raeburn 3532: } else {
1.383 raeburn 3533: if ($newsetting->{$entry} ne $oldsetting->{$entry}) {
3534: $r->print(&Apache::loncommon::start_data_table_row()."\n");
3535: $r->print("<td>$lt{$entry}</td>\n");
3536: $r->print("<td>".$oldsetting->{$entry}.' '.$oldsettingtext->{$entry}."</td>\n");
3537: $r->print("<td>".$newsetting->{$entry}.' '.$newsettingtext->{$entry}."</td>\n");
3538: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.334 raeburn 3539: }
3540: }
3541: }
3542: }
1.367 golterma 3543: $r->print(&Apache::loncommon::end_data_table().'<br />');
1.372 raeburn 3544: } else {
3545: $r->print('<h3>'.$lt{'ui'}.'</h3>'.
3546: '<p>'.&mt('No changes made to user information').'</p>');
1.334 raeburn 3547: }
3548: return;
3549: }
3550:
1.275 raeburn 3551: sub tool_changes {
3552: my ($context,$usertools,$oldaccess,$oldaccesstext,$userenv,$changeHash,
3553: $changed,$newaccess,$newaccesstext) = @_;
3554: if (!((ref($usertools) eq 'ARRAY') && (ref($oldaccess) eq 'HASH') &&
3555: (ref($oldaccesstext) eq 'HASH') && (ref($userenv) eq 'HASH') &&
3556: (ref($changeHash) eq 'HASH') && (ref($changed) eq 'HASH') &&
3557: (ref($newaccess) eq 'HASH') && (ref($newaccesstext) eq 'HASH'))) {
3558: return;
3559: }
1.383 raeburn 3560: my %reqdisplay = &requestchange_display();
1.300 raeburn 3561: if ($context eq 'reqcrsotherdom') {
1.309 raeburn 3562: my @options = ('approval','validate','autolimit');
1.306 raeburn 3563: my $optregex = join('|',@options);
1.300 raeburn 3564: my $cdom = $env{'request.role.domain'};
3565: foreach my $tool (@{$usertools}) {
1.383 raeburn 3566: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
1.314 raeburn 3567: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
1.300 raeburn 3568: $changeHash->{$context.'.'.$tool} = $userenv->{$context.'.'.$tool};
1.383 raeburn 3569: my ($newop,$limit);
1.314 raeburn 3570: if ($env{'form.'.$context.'_'.$tool}) {
3571: $newop = $env{'form.'.$context.'_'.$tool};
3572: if ($newop eq 'autolimit') {
1.383 raeburn 3573: $limit = $env{'form.'.$context.'_'.$tool.'_limit'};
1.314 raeburn 3574: $limit =~ s/\D+//g;
3575: $newop .= '='.$limit;
3576: }
3577: }
1.300 raeburn 3578: if ($userenv->{$context.'.'.$tool} eq '') {
1.314 raeburn 3579: if ($newop) {
3580: $changed->{$tool}=&tool_admin($tool,$cdom.':'.$newop,
1.300 raeburn 3581: $changeHash,$context);
3582: if ($changed->{$tool}) {
1.383 raeburn 3583: if ($newop =~ /^autolimit/) {
3584: if ($limit) {
3585: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3586: } else {
3587: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3588: }
3589: } else {
3590: $newaccesstext->{$tool} = $reqdisplay{$newop};
3591: }
1.300 raeburn 3592: } else {
3593: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
3594: }
3595: }
3596: } else {
3597: my @curr = split(',',$userenv->{$context.'.'.$tool});
3598: my @new;
3599: my $changedoms;
1.314 raeburn 3600: foreach my $req (@curr) {
3601: if ($req =~ /^\Q$cdom\E\:($optregex\=?\d*)$/) {
3602: my $oldop = $1;
1.383 raeburn 3603: if ($oldop =~ /^autolimit=(\d*)/) {
3604: my $limit = $1;
3605: if ($limit) {
3606: $oldaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3607: } else {
3608: $oldaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3609: }
3610: } else {
3611: $oldaccesstext->{$tool} = $reqdisplay{$oldop};
3612: }
1.314 raeburn 3613: if ($oldop ne $newop) {
3614: $changedoms = 1;
3615: foreach my $item (@curr) {
3616: my ($reqdom,$option) = split(':',$item);
3617: unless ($reqdom eq $cdom) {
3618: push(@new,$item);
3619: }
3620: }
3621: if ($newop) {
3622: push(@new,$cdom.':'.$newop);
1.300 raeburn 3623: }
1.314 raeburn 3624: @new = sort(@new);
1.300 raeburn 3625: }
1.314 raeburn 3626: last;
1.300 raeburn 3627: }
1.314 raeburn 3628: }
3629: if ((!$changedoms) && ($newop)) {
1.300 raeburn 3630: $changedoms = 1;
1.306 raeburn 3631: @new = sort(@curr,$cdom.':'.$newop);
1.300 raeburn 3632: }
3633: if ($changedoms) {
1.314 raeburn 3634: my $newdomstr;
1.300 raeburn 3635: if (@new) {
3636: $newdomstr = join(',',@new);
3637: }
3638: $changed->{$tool}=&tool_admin($tool,$newdomstr,$changeHash,
3639: $context);
3640: if ($changed->{$tool}) {
3641: if ($env{'form.'.$context.'_'.$tool}) {
1.306 raeburn 3642: if ($env{'form.'.$context.'_'.$tool} eq 'autolimit') {
1.314 raeburn 3643: my $limit = $env{'form.'.$context.'_'.$tool.'_limit'};
3644: $limit =~ s/\D+//g;
3645: if ($limit) {
1.383 raeburn 3646: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
1.314 raeburn 3647: } else {
1.383 raeburn 3648: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
1.306 raeburn 3649: }
1.314 raeburn 3650: } else {
1.306 raeburn 3651: $newaccesstext->{$tool} = $reqdisplay{$env{'form.'.$context.'_'.$tool}};
3652: }
1.300 raeburn 3653: } else {
1.383 raeburn 3654: $newaccesstext->{$tool} = &mt("availability set to 'off'");
1.300 raeburn 3655: }
3656: }
3657: }
3658: }
3659: }
3660: return;
3661: }
1.275 raeburn 3662: foreach my $tool (@{$usertools}) {
1.383 raeburn 3663: my ($newval,$limit,$envkey);
1.362 raeburn 3664: $envkey = $context.'.'.$tool;
1.306 raeburn 3665: if ($context eq 'requestcourses') {
3666: $newval = $env{'form.crsreq_'.$tool};
3667: if ($newval eq 'autolimit') {
1.383 raeburn 3668: $limit = $env{'form.crsreq_'.$tool.'_limit'};
3669: $limit =~ s/\D+//g;
3670: $newval .= '='.$limit;
1.306 raeburn 3671: }
1.362 raeburn 3672: } elsif ($context eq 'requestauthor') {
3673: $newval = $env{'form.'.$context};
3674: $envkey = $context;
1.314 raeburn 3675: } else {
1.306 raeburn 3676: $newval = $env{'form.'.$context.'_'.$tool};
3677: }
1.362 raeburn 3678: if ($userenv->{$envkey} ne '') {
1.275 raeburn 3679: $oldaccess->{$tool} = &mt('custom');
1.383 raeburn 3680: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3681: if ($userenv->{$envkey} =~ /^autolimit=(\d*)$/) {
3682: my $currlimit = $1;
3683: if ($currlimit eq '') {
3684: $oldaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3685: } else {
3686: $oldaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$currlimit);
3687: }
3688: } elsif ($userenv->{$envkey}) {
3689: $oldaccesstext->{$tool} = $reqdisplay{$userenv->{$envkey}};
3690: } else {
3691: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
3692: }
1.275 raeburn 3693: } else {
1.383 raeburn 3694: if ($userenv->{$envkey}) {
3695: $oldaccesstext->{$tool} = &mt("availability set to 'on'");
3696: } else {
3697: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
3698: }
1.275 raeburn 3699: }
1.362 raeburn 3700: $changeHash->{$envkey} = $userenv->{$envkey};
1.275 raeburn 3701: if ($env{'form.custom'.$tool} == 1) {
1.362 raeburn 3702: if ($newval ne $userenv->{$envkey}) {
1.306 raeburn 3703: $changed->{$tool} = &tool_admin($tool,$newval,$changeHash,
3704: $context);
1.275 raeburn 3705: if ($changed->{$tool}) {
3706: $newaccess->{$tool} = &mt('custom');
1.383 raeburn 3707: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3708: if ($newval =~ /^autolimit/) {
3709: if ($limit) {
3710: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3711: } else {
3712: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3713: }
3714: } elsif ($newval) {
3715: $newaccesstext->{$tool} = $reqdisplay{$newval};
3716: } else {
3717: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3718: }
1.275 raeburn 3719: } else {
1.383 raeburn 3720: if ($newval) {
3721: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3722: } else {
3723: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3724: }
1.275 raeburn 3725: }
3726: } else {
3727: $newaccess->{$tool} = $oldaccess->{$tool};
1.383 raeburn 3728: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3729: if ($newval =~ /^autolimit/) {
3730: if ($limit) {
3731: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3732: } else {
3733: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3734: }
3735: } elsif ($newval) {
3736: $newaccesstext->{$tool} = $reqdisplay{$newval};
3737: } else {
3738: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3739: }
1.275 raeburn 3740: } else {
1.383 raeburn 3741: if ($userenv->{$context.'.'.$tool}) {
3742: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3743: } else {
3744: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3745: }
1.275 raeburn 3746: }
3747: }
3748: } else {
3749: $newaccess->{$tool} = $oldaccess->{$tool};
3750: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
3751: }
3752: } else {
3753: $changed->{$tool} = &tool_admin($tool,'',$changeHash,$context);
3754: if ($changed->{$tool}) {
3755: $newaccess->{$tool} = &mt('default');
3756: } else {
3757: $newaccess->{$tool} = $oldaccess->{$tool};
1.383 raeburn 3758: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3759: if ($newval =~ /^autolimit/) {
3760: if ($limit) {
3761: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3762: } else {
3763: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3764: }
3765: } elsif ($newval) {
3766: $newaccesstext->{$tool} = $reqdisplay{$newval};
3767: } else {
3768: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3769: }
1.275 raeburn 3770: } else {
1.383 raeburn 3771: if ($userenv->{$context.'.'.$tool}) {
3772: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3773: } else {
3774: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3775: }
1.275 raeburn 3776: }
3777: }
3778: }
3779: } else {
3780: $oldaccess->{$tool} = &mt('default');
3781: if ($env{'form.custom'.$tool} == 1) {
1.306 raeburn 3782: $changed->{$tool} = &tool_admin($tool,$newval,$changeHash,
3783: $context);
1.275 raeburn 3784: if ($changed->{$tool}) {
3785: $newaccess->{$tool} = &mt('custom');
1.383 raeburn 3786: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
3787: if ($newval =~ /^autolimit/) {
3788: if ($limit) {
3789: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
3790: } else {
3791: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
3792: }
3793: } elsif ($newval) {
3794: $newaccesstext->{$tool} = $reqdisplay{$newval};
3795: } else {
3796: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3797: }
1.275 raeburn 3798: } else {
1.383 raeburn 3799: if ($newval) {
3800: $newaccesstext->{$tool} = &mt("availability set to 'on'");
3801: } else {
3802: $newaccesstext->{$tool} = &mt("availability set to 'off'");
3803: }
1.275 raeburn 3804: }
3805: } else {
3806: $newaccess->{$tool} = $oldaccess->{$tool};
3807: }
3808: } else {
3809: $newaccess->{$tool} = $oldaccess->{$tool};
3810: }
3811: }
3812: }
3813: return;
3814: }
3815:
1.220 raeburn 3816: sub update_roles {
1.375 raeburn 3817: my ($r,$context,$showcredits) = @_;
1.4 www 3818: my $now=time;
1.225 raeburn 3819: my @rolechanges;
1.220 raeburn 3820: my %disallowed;
1.73 sakharuk 3821: $r->print('<h3>'.&mt('Modifying Roles').'</h3>');
1.404 raeburn 3822: foreach my $key (keys(%env)) {
1.135 raeburn 3823: next if (! $env{$key});
1.190 raeburn 3824: next if ($key eq 'form.action');
1.27 matthew 3825: # Revoke roles
1.135 raeburn 3826: if ($key=~/^form\.rev/) {
3827: if ($key=~/^form\.rev\:([^\_]+)\_([^\_\.]+)$/) {
1.64 www 3828: # Revoke standard role
1.170 albertel 3829: my ($scope,$role) = ($1,$2);
3830: my $result =
3831: &Apache::lonnet::revokerole($env{'form.ccdomain'},
3832: $env{'form.ccuname'},
1.239 raeburn 3833: $scope,$role,'','',$context);
1.367 golterma 3834: $r->print(&Apache::lonhtmlcommon::confirm_success(
1.369 bisitz 3835: &mt('Revoking [_1] in [_2]',
3836: &Apache::lonnet::plaintext($role),
1.372 raeburn 3837: &Apache::loncommon::show_role_extent($scope,$context,$role)),
1.369 bisitz 3838: $result ne "ok").'<br />');
3839: if ($result ne "ok") {
3840: $r->print(&mt('Error: [_1]',$result).'<br />');
3841: }
1.170 albertel 3842: if ($role eq 'st') {
1.202 raeburn 3843: my $result =
1.198 raeburn 3844: &Apache::lonuserutils::classlist_drop($scope,
3845: $env{'form.ccuname'},$env{'form.ccdomain'},
1.202 raeburn 3846: $now);
1.367 golterma 3847: $r->print(&Apache::lonhtmlcommon::confirm_success($result));
1.53 www 3848: }
1.225 raeburn 3849: if (!grep(/^\Q$role\E$/,@rolechanges)) {
3850: push(@rolechanges,$role);
3851: }
1.196 raeburn 3852: }
1.195 raeburn 3853: if ($key=~m{^form\.rev\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}s) {
1.64 www 3854: # Revoke custom role
1.369 bisitz 3855: my $result = &Apache::lonnet::revokecustomrole(
3856: $env{'form.ccdomain'},$env{'form.ccuname'},$1,$2,$3,$4,'','',$context);
1.367 golterma 3857: $r->print(&Apache::lonhtmlcommon::confirm_success(
1.369 bisitz 3858: &mt('Revoking custom role [_1] by [_2] in [_3]',
1.372 raeburn 3859: $4,$3.':'.$2,&Apache::loncommon::show_role_extent($1,$context,'cr')),
1.369 bisitz 3860: $result ne 'ok').'<br />');
3861: if ($result ne "ok") {
3862: $r->print(&mt('Error: [_1]',$result).'<br />');
3863: }
1.225 raeburn 3864: if (!grep(/^cr$/,@rolechanges)) {
3865: push(@rolechanges,'cr');
3866: }
1.64 www 3867: }
1.135 raeburn 3868: } elsif ($key=~/^form\.del/) {
3869: if ($key=~/^form\.del\:([^\_]+)\_([^\_\.]+)$/) {
1.116 raeburn 3870: # Delete standard role
1.170 albertel 3871: my ($scope,$role) = ($1,$2);
3872: my $result =
3873: &Apache::lonnet::assignrole($env{'form.ccdomain'},
3874: $env{'form.ccuname'},
1.239 raeburn 3875: $scope,$role,$now,0,1,'',
3876: $context);
1.367 golterma 3877: $r->print(&Apache::lonhtmlcommon::confirm_success(
3878: &mt('Deleting [_1] in [_2]',
1.369 bisitz 3879: &Apache::lonnet::plaintext($role),
1.372 raeburn 3880: &Apache::loncommon::show_role_extent($scope,$context,$role)),
1.369 bisitz 3881: $result ne 'ok').'<br />');
3882: if ($result ne "ok") {
3883: $r->print(&mt('Error: [_1]',$result).'<br />');
3884: }
1.367 golterma 3885:
1.170 albertel 3886: if ($role eq 'st') {
1.202 raeburn 3887: my $result =
1.198 raeburn 3888: &Apache::lonuserutils::classlist_drop($scope,
3889: $env{'form.ccuname'},$env{'form.ccdomain'},
1.202 raeburn 3890: $now);
1.369 bisitz 3891: $r->print(&Apache::lonhtmlcommon::confirm_success($result));
1.81 albertel 3892: }
1.225 raeburn 3893: if (!grep(/^\Q$role\E$/,@rolechanges)) {
3894: push(@rolechanges,$role);
3895: }
1.116 raeburn 3896: }
1.139 albertel 3897: if ($key=~m{^form\.del\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
1.116 raeburn 3898: my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
3899: # Delete custom role
1.369 bisitz 3900: my $result =
3901: &Apache::lonnet::assigncustomrole($env{'form.ccdomain'},
3902: $env{'form.ccuname'},$url,$rdom,$rnam,$rolename,$now,
3903: 0,1,$context);
3904: $r->print(&Apache::lonhtmlcommon::confirm_success(&mt('Deleting custom role [_1] by [_2] in [_3]',
1.372 raeburn 3905: $rolename,$rnam.':'.$rdom,&Apache::loncommon::show_role_extent($1,$context,'cr')),
1.369 bisitz 3906: $result ne "ok").'<br />');
3907: if ($result ne "ok") {
3908: $r->print(&mt('Error: [_1]',$result).'<br />');
3909: }
1.367 golterma 3910:
1.225 raeburn 3911: if (!grep(/^cr$/,@rolechanges)) {
3912: push(@rolechanges,'cr');
3913: }
1.116 raeburn 3914: }
1.135 raeburn 3915: } elsif ($key=~/^form\.ren/) {
1.101 albertel 3916: my $udom = $env{'form.ccdomain'};
3917: my $uname = $env{'form.ccuname'};
1.116 raeburn 3918: # Re-enable standard role
1.135 raeburn 3919: if ($key=~/^form\.ren\:([^\_]+)\_([^\_\.]+)$/) {
1.89 raeburn 3920: my $url = $1;
3921: my $role = $2;
3922: my $logmsg;
3923: my $output;
3924: if ($role eq 'st') {
1.141 albertel 3925: if ($url =~ m-^/($match_domain)/($match_courseid)/?(\w*)$-) {
1.374 raeburn 3926: my ($cdom,$cnum,$csec) = ($1,$2,$3);
1.375 raeburn 3927: my $credits;
3928: if ($showcredits) {
3929: my $defaultcredits =
3930: &Apache::lonuserutils::get_defaultcredits($cdom,$cnum);
3931: $credits = &get_user_credits($defaultcredits,$cdom,$cnum);
3932: }
3933: my $result = &Apache::loncommon::commit_studentrole(\$logmsg,$udom,$uname,$url,$role,$now,0,$cdom,$cnum,$csec,$context,$credits);
1.220 raeburn 3934: if (($result =~ /^error/) || ($result eq 'not_in_class') || ($result eq 'unknown_course') || ($result eq 'refused')) {
1.223 raeburn 3935: if ($result eq 'refused' && $logmsg) {
3936: $output = $logmsg;
3937: } else {
1.369 bisitz 3938: $output = &mt('Error: [_1]',$result)."\n";
1.223 raeburn 3939: }
1.89 raeburn 3940: } else {
1.372 raeburn 3941: $output = &Apache::lonhtmlcommon::confirm_success(&mt('Assigning [_1] in [_2] starting [_3]',
3942: &Apache::lonnet::plaintext($role),
3943: &Apache::loncommon::show_role_extent($url,$context,'st'),
3944: &Apache::lonlocal::locallocaltime($now))).'<br />'.$logmsg.'<br />';
1.89 raeburn 3945: }
3946: }
3947: } else {
1.101 albertel 3948: my $result=&Apache::lonnet::assignrole($env{'form.ccdomain'},
1.239 raeburn 3949: $env{'form.ccuname'},$url,$role,0,$now,'','',
3950: $context);
1.367 golterma 3951: $output = &Apache::lonhtmlcommon::confirm_success(&mt('Re-enabling [_1] in [_2]',
1.372 raeburn 3952: &Apache::lonnet::plaintext($role),
3953: &Apache::loncommon::show_role_extent($url,$context,$role)),$result ne "ok").'<br />';
1.369 bisitz 3954: if ($result ne "ok") {
3955: $output .= &mt('Error: [_1]',$result).'<br />';
3956: }
3957: }
1.89 raeburn 3958: $r->print($output);
1.225 raeburn 3959: if (!grep(/^\Q$role\E$/,@rolechanges)) {
3960: push(@rolechanges,$role);
3961: }
1.113 raeburn 3962: }
1.116 raeburn 3963: # Re-enable custom role
1.139 albertel 3964: if ($key=~m{^form\.ren\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
1.116 raeburn 3965: my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
3966: my $result = &Apache::lonnet::assigncustomrole(
3967: $env{'form.ccdomain'}, $env{'form.ccuname'},
1.240 raeburn 3968: $url,$rdom,$rnam,$rolename,0,$now,undef,$context);
1.369 bisitz 3969: $r->print(&Apache::lonhtmlcommon::confirm_success(
3970: &mt('Re-enabling custom role [_1] by [_2] in [_3]',
1.372 raeburn 3971: $rolename,$rnam.':'.$rdom,&Apache::loncommon::show_role_extent($1,$context,'cr')),
1.369 bisitz 3972: $result ne "ok").'<br />');
3973: if ($result ne "ok") {
3974: $r->print(&mt('Error: [_1]',$result).'<br />');
3975: }
1.225 raeburn 3976: if (!grep(/^cr$/,@rolechanges)) {
3977: push(@rolechanges,'cr');
3978: }
1.116 raeburn 3979: }
1.135 raeburn 3980: } elsif ($key=~/^form\.act/) {
1.101 albertel 3981: my $udom = $env{'form.ccdomain'};
3982: my $uname = $env{'form.ccuname'};
1.141 albertel 3983: if ($key=~/^form\.act\_($match_domain)\_($match_courseid)\_cr_cr_($match_domain)_($match_username)_([^\_]+)$/) {
1.65 www 3984: # Activate a custom role
1.83 albertel 3985: my ($one,$two,$three,$four,$five)=($1,$2,$3,$4,$5);
3986: my $url='/'.$one.'/'.$two;
3987: my $full=$one.'_'.$two.'_cr_cr_'.$three.'_'.$four.'_'.$five;
1.65 www 3988:
1.101 albertel 3989: my $start = ( $env{'form.start_'.$full} ?
3990: $env{'form.start_'.$full} :
1.88 raeburn 3991: $now );
1.101 albertel 3992: my $end = ( $env{'form.end_'.$full} ?
3993: $env{'form.end_'.$full} :
1.88 raeburn 3994: 0 );
3995:
3996: # split multiple sections
3997: my %sections = ();
1.101 albertel 3998: my $num_sections = &build_roles($env{'form.sec_'.$full},\%sections,$5);
1.88 raeburn 3999: if ($num_sections == 0) {
1.240 raeburn 4000: $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$url,$three,$four,$five,$start,$end,$context));
1.88 raeburn 4001: } else {
1.114 albertel 4002: my %curr_groups =
1.117 raeburn 4003: &Apache::longroup::coursegroups($one,$two);
1.404 raeburn 4004: foreach my $sec (sort {$a cmp $b} keys(%sections)) {
1.113 raeburn 4005: if (($sec eq 'none') || ($sec eq 'all') ||
4006: exists($curr_groups{$sec})) {
4007: $disallowed{$sec} = $url;
4008: next;
4009: }
4010: my $securl = $url.'/'.$sec;
1.240 raeburn 4011: $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$securl,$three,$four,$five,$start,$end,$context));
1.88 raeburn 4012: }
4013: }
1.225 raeburn 4014: if (!grep(/^cr$/,@rolechanges)) {
4015: push(@rolechanges,'cr');
4016: }
1.142 raeburn 4017: } elsif ($key=~/^form\.act\_($match_domain)\_($match_name)\_([^\_]+)$/) {
1.27 matthew 4018: # Activate roles for sections with 3 id numbers
4019: # set start, end times, and the url for the class
1.83 albertel 4020: my ($one,$two,$three)=($1,$2,$3);
1.101 albertel 4021: my $start = ( $env{'form.start_'.$one.'_'.$two.'_'.$three} ?
4022: $env{'form.start_'.$one.'_'.$two.'_'.$three} :
1.27 matthew 4023: $now );
1.101 albertel 4024: my $end = ( $env{'form.end_'.$one.'_'.$two.'_'.$three} ?
4025: $env{'form.end_'.$one.'_'.$two.'_'.$three} :
1.27 matthew 4026: 0 );
1.83 albertel 4027: my $url='/'.$one.'/'.$two;
1.88 raeburn 4028: my $type = 'three';
4029: # split multiple sections
4030: my %sections = ();
1.101 albertel 4031: my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two.'_'.$three},\%sections,$three);
1.375 raeburn 4032: my $credits;
4033: if ($three eq 'st') {
4034: if ($showcredits) {
4035: my $defaultcredits =
4036: &Apache::lonuserutils::get_defaultcredits($one,$two);
4037: $credits = $env{'form.credits_'.$one.'_'.$two.'_'.$three};
4038: $credits =~ s/[^\d\.]//g;
4039: if ($credits eq $defaultcredits) {
4040: undef($credits);
4041: }
4042: }
4043: }
1.88 raeburn 4044: if ($num_sections == 0) {
1.375 raeburn 4045: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'',$context,$credits));
1.88 raeburn 4046: } else {
1.114 albertel 4047: my %curr_groups =
1.117 raeburn 4048: &Apache::longroup::coursegroups($one,$two);
1.88 raeburn 4049: my $emptysec = 0;
1.404 raeburn 4050: foreach my $sec (sort {$a cmp $b} keys(%sections)) {
1.88 raeburn 4051: $sec =~ s/\W//g;
1.113 raeburn 4052: if ($sec ne '') {
4053: if (($sec eq 'none') || ($sec eq 'all') ||
4054: exists($curr_groups{$sec})) {
4055: $disallowed{$sec} = $url;
4056: next;
4057: }
1.88 raeburn 4058: my $securl = $url.'/'.$sec;
1.375 raeburn 4059: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$three,$start,$end,$one,$two,$sec,$context,$credits));
1.88 raeburn 4060: } else {
4061: $emptysec = 1;
4062: }
4063: }
4064: if ($emptysec) {
1.375 raeburn 4065: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'',$context,$credits));
1.88 raeburn 4066: }
1.225 raeburn 4067: }
4068: if (!grep(/^\Q$three\E$/,@rolechanges)) {
4069: push(@rolechanges,$three);
4070: }
1.135 raeburn 4071: } elsif ($key=~/^form\.act\_([^\_]+)\_([^\_]+)$/) {
1.27 matthew 4072: # Activate roles for sections with two id numbers
4073: # set start, end times, and the url for the class
1.101 albertel 4074: my $start = ( $env{'form.start_'.$1.'_'.$2} ?
4075: $env{'form.start_'.$1.'_'.$2} :
1.27 matthew 4076: $now );
1.101 albertel 4077: my $end = ( $env{'form.end_'.$1.'_'.$2} ?
4078: $env{'form.end_'.$1.'_'.$2} :
1.27 matthew 4079: 0 );
1.225 raeburn 4080: my $one = $1;
4081: my $two = $2;
4082: my $url='/'.$one.'/';
1.88 raeburn 4083: # split multiple sections
4084: my %sections = ();
1.225 raeburn 4085: my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two},\%sections,$two);
1.88 raeburn 4086: if ($num_sections == 0) {
1.240 raeburn 4087: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,'',$context));
1.88 raeburn 4088: } else {
4089: my $emptysec = 0;
1.404 raeburn 4090: foreach my $sec (sort {$a cmp $b} keys(%sections)) {
1.88 raeburn 4091: if ($sec ne '') {
4092: my $securl = $url.'/'.$sec;
1.240 raeburn 4093: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$two,$start,$end,$one,undef,$sec,$context));
1.88 raeburn 4094: } else {
4095: $emptysec = 1;
4096: }
4097: }
4098: if ($emptysec) {
1.240 raeburn 4099: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,'',$context));
1.88 raeburn 4100: }
4101: }
1.225 raeburn 4102: if (!grep(/^\Q$two\E$/,@rolechanges)) {
4103: push(@rolechanges,$two);
4104: }
1.64 www 4105: } else {
1.190 raeburn 4106: $r->print('<p><span class="LC_error">'.&mt('ERROR').': '.&mt('Unknown command').' <tt>'.$key.'</tt></span></p><br />');
1.64 www 4107: }
1.113 raeburn 4108: foreach my $key (sort(keys(%disallowed))) {
1.274 bisitz 4109: $r->print('<p class="LC_warning">');
1.113 raeburn 4110: if (($key eq 'none') || ($key eq 'all')) {
1.274 bisitz 4111: $r->print(&mt('[_1] may not be used as the name for a section, as it is a reserved word.','<tt>'.$key.'</tt>'));
1.113 raeburn 4112: } else {
1.274 bisitz 4113: $r->print(&mt('[_1] may not be used as the name for a section, as it is the name of a course group.','<tt>'.$key.'</tt>'));
1.113 raeburn 4114: }
1.274 bisitz 4115: $r->print('</p><p>'
4116: .&mt('Please [_1]go back[_2] and choose a different section name.'
4117: ,'<a href="javascript:history.go(-1)'
4118: ,'</a>')
4119: .'</p><br />'
4120: );
1.113 raeburn 4121: }
4122: }
1.101 albertel 4123: } # End of foreach (keys(%env))
1.75 www 4124: # Flush the course logs so reverse user roles immediately updated
1.349 raeburn 4125: $r->register_cleanup(\&Apache::lonnet::flushcourselogs);
1.225 raeburn 4126: if (@rolechanges == 0) {
1.372 raeburn 4127: $r->print('<p>'.&mt('No roles to modify').'</p>');
1.193 raeburn 4128: }
1.225 raeburn 4129: return @rolechanges;
1.220 raeburn 4130: }
4131:
1.375 raeburn 4132: sub get_user_credits {
4133: my ($uname,$udom,$defaultcredits,$cdom,$cnum) = @_;
4134: if ($cdom eq '' || $cnum eq '') {
4135: return unless ($env{'request.course.id'});
4136: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
4137: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
4138: }
4139: my $credits;
4140: my %currhash =
4141: &Apache::lonnet::get('classlist',[$uname.':'.$udom],$cdom,$cnum);
4142: if (keys(%currhash) > 0) {
4143: my @items = split(/:/,$currhash{$uname.':'.$udom});
4144: my $crdidx = &Apache::loncoursedata::CL_CREDITS() - 3;
4145: $credits = $items[$crdidx];
4146: $credits =~ s/[^\d\.]//g;
4147: }
4148: if ($credits eq $defaultcredits) {
4149: undef($credits);
4150: }
4151: return $credits;
4152: }
4153:
1.220 raeburn 4154: sub enroll_single_student {
1.375 raeburn 4155: my ($r,$uhome,$amode,$genpwd,$now,$newuser,$context,$crstype,
4156: $showcredits,$defaultcredits) = @_;
1.318 raeburn 4157: $r->print('<h3>');
4158: if ($crstype eq 'Community') {
4159: $r->print(&mt('Enrolling Member'));
4160: } else {
4161: $r->print(&mt('Enrolling Student'));
4162: }
4163: $r->print('</h3>');
1.220 raeburn 4164:
4165: # Remove non alphanumeric values from section
4166: $env{'form.sections'}=~s/\W//g;
4167:
1.375 raeburn 4168: my $credits;
4169: if (($showcredits) && ($env{'form.credits'} ne '')) {
4170: $credits = $env{'form.credits'};
4171: $credits =~ s/[^\d\.]//g;
4172: if ($credits ne '') {
4173: if ($credits eq $defaultcredits) {
4174: undef($credits);
4175: }
4176: }
4177: }
4178:
1.220 raeburn 4179: # Clean out any old student roles the user has in this class.
4180: &Apache::lonuserutils::modifystudent($env{'form.ccdomain'},
4181: $env{'form.ccuname'},$env{'request.course.id'},undef,$uhome);
4182: my ($startdate,$enddate) = &Apache::lonuserutils::get_dates_from_form();
4183: my $enroll_result =
4184: &Apache::lonnet::modify_student_enrollment($env{'form.ccdomain'},
4185: $env{'form.ccuname'},$env{'form.cid'},$env{'form.cfirstname'},
4186: $env{'form.cmiddlename'},$env{'form.clastname'},
4187: $env{'form.generation'},$env{'form.sections'},$enddate,
1.375 raeburn 4188: $startdate,'manual',undef,$env{'request.course.id'},'',$context,
4189: $credits);
1.220 raeburn 4190: if ($enroll_result =~ /^ok/) {
1.381 bisitz 4191: $r->print(&mt('[_1] enrolled','<b>'.$env{'form.ccuname'}.':'.$env{'form.ccdomain'}.'</b>'));
1.220 raeburn 4192: if ($env{'form.sections'} ne '') {
4193: $r->print(' '.&mt('in section [_1]',$env{'form.sections'}));
4194: }
4195: my ($showstart,$showend);
4196: if ($startdate <= $now) {
4197: $showstart = &mt('Access starts immediately');
4198: } else {
4199: $showstart = &mt('Access starts: ').&Apache::lonlocal::locallocaltime($startdate);
4200: }
4201: if ($enddate == 0) {
4202: $showend = &mt('ends: no ending date');
4203: } else {
4204: $showend = &mt('ends: ').&Apache::lonlocal::locallocaltime($enddate);
4205: }
4206: $r->print('.<br />'.$showstart.'; '.$showend);
4207: if ($startdate <= $now && !$newuser) {
1.386 bisitz 4208: $r->print('<p class="LC_info">');
1.318 raeburn 4209: if ($crstype eq 'Community') {
1.392 raeburn 4210: $r->print(&mt('If the member is currently logged-in to LON-CAPA, the new role can be displayed by using the "Check for changes" link on the Roles/Courses page.'));
1.318 raeburn 4211: } else {
1.392 raeburn 4212: $r->print(&mt('If the student is currently logged-in to LON-CAPA, the new role can be displayed by using the "Check for changes" link on the Roles/Courses page.'));
1.318 raeburn 4213: }
4214: $r->print('</p>');
1.220 raeburn 4215: }
4216: } else {
4217: $r->print(&mt('unable to enroll').": ".$enroll_result);
4218: }
4219: return;
1.188 raeburn 4220: }
4221:
1.204 raeburn 4222: sub get_defaultquota_text {
4223: my ($settingstatus) = @_;
4224: my $defquotatext;
4225: if ($settingstatus eq '') {
1.383 raeburn 4226: $defquotatext = &mt('default');
1.204 raeburn 4227: } else {
4228: my ($usertypes,$order) =
4229: &Apache::lonnet::retrieve_inst_usertypes($env{'form.ccdomain'});
4230: if ($usertypes->{$settingstatus} eq '') {
1.383 raeburn 4231: $defquotatext = &mt('default');
1.204 raeburn 4232: } else {
1.383 raeburn 4233: $defquotatext = &mt('default for [_1]',$usertypes->{$settingstatus});
1.204 raeburn 4234: }
4235: }
4236: return $defquotatext;
4237: }
4238:
1.188 raeburn 4239: sub update_result_form {
4240: my ($uhome) = @_;
4241: my $outcome =
1.367 golterma 4242: '<form name="userupdate" method="post" action="">'."\n";
1.160 raeburn 4243: foreach my $item ('srchby','srchin','srchtype','srchterm','srchdomain','ccuname','ccdomain') {
1.188 raeburn 4244: $outcome .= '<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n";
1.160 raeburn 4245: }
1.207 raeburn 4246: if ($env{'form.origname'} ne '') {
4247: $outcome .= '<input type="hidden" name="origname" value="'.$env{'form.origname'}.'" />'."\n";
4248: }
1.160 raeburn 4249: foreach my $item ('sortby','seluname','seludom') {
4250: if (exists($env{'form.'.$item})) {
1.188 raeburn 4251: $outcome .= '<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n";
1.160 raeburn 4252: }
4253: }
1.188 raeburn 4254: if ($uhome eq 'no_host') {
4255: $outcome .= '<input type="hidden" name="forcenewuser" value="1" />'."\n";
4256: }
4257: $outcome .= '<input type="hidden" name="phase" value="" />'."\n".
1.383 raeburn 4258: '<input type="hidden" name="currstate" value="" />'."\n".
4259: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n".
1.188 raeburn 4260: '</form>';
4261: return $outcome;
1.4 www 4262: }
4263:
1.149 raeburn 4264: sub quota_admin {
1.378 raeburn 4265: my ($setquota,$changeHash,$name) = @_;
1.149 raeburn 4266: my $quotachanged;
4267: if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
4268: # Current user has quota modification privileges
1.267 raeburn 4269: if (ref($changeHash) eq 'HASH') {
4270: $quotachanged = 1;
1.378 raeburn 4271: $changeHash->{$name.'quota'} = $setquota;
1.267 raeburn 4272: }
1.149 raeburn 4273: }
4274: return $quotachanged;
4275: }
4276:
1.267 raeburn 4277: sub tool_admin {
1.275 raeburn 4278: my ($tool,$settool,$changeHash,$context) = @_;
4279: my $canchange = 0;
1.279 raeburn 4280: if ($context eq 'requestcourses') {
1.275 raeburn 4281: if (&Apache::lonnet::allowed('ccc',$env{'form.ccdomain'})) {
4282: $canchange = 1;
4283: }
1.300 raeburn 4284: } elsif ($context eq 'reqcrsotherdom') {
4285: if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
4286: $canchange = 1;
4287: }
1.362 raeburn 4288: } elsif ($context eq 'requestauthor') {
4289: if (&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) {
4290: $canchange = 1;
4291: }
1.275 raeburn 4292: } elsif (&Apache::lonnet::allowed('mut',$env{'form.ccdomain'})) {
4293: # Current user has quota modification privileges
4294: $canchange = 1;
4295: }
1.267 raeburn 4296: my $toolchanged;
1.275 raeburn 4297: if ($canchange) {
1.267 raeburn 4298: if (ref($changeHash) eq 'HASH') {
4299: $toolchanged = 1;
1.362 raeburn 4300: if ($tool eq 'requestauthor') {
4301: $changeHash->{$context} = $settool;
4302: } else {
4303: $changeHash->{$context.'.'.$tool} = $settool;
4304: }
1.267 raeburn 4305: }
4306: }
4307: return $toolchanged;
4308: }
4309:
1.88 raeburn 4310: sub build_roles {
1.89 raeburn 4311: my ($sectionstr,$sections,$role) = @_;
1.88 raeburn 4312: my $num_sections = 0;
4313: if ($sectionstr=~ /,/) {
4314: my @secnums = split/,/,$sectionstr;
1.89 raeburn 4315: if ($role eq 'st') {
4316: $secnums[0] =~ s/\W//g;
4317: $$sections{$secnums[0]} = 1;
4318: $num_sections = 1;
4319: } else {
4320: foreach my $sec (@secnums) {
4321: $sec =~ ~s/\W//g;
1.150 banghart 4322: if (!($sec eq "")) {
1.89 raeburn 4323: if (exists($$sections{$sec})) {
4324: $$sections{$sec} ++;
4325: } else {
4326: $$sections{$sec} = 1;
4327: $num_sections ++;
4328: }
1.88 raeburn 4329: }
4330: }
4331: }
4332: } else {
4333: $sectionstr=~s/\W//g;
4334: unless ($sectionstr eq '') {
4335: $$sections{$sectionstr} = 1;
4336: $num_sections ++;
4337: }
4338: }
1.129 albertel 4339:
1.88 raeburn 4340: return $num_sections;
4341: }
4342:
1.58 www 4343: # ========================================================== Custom Role Editor
4344:
4345: sub custom_role_editor {
1.439 raeburn 4346: my ($r,$context,$brcrum,$prefix,$permission) = @_;
1.324 raeburn 4347: my $action = $env{'form.customroleaction'};
1.439 raeburn 4348: my ($rolename,$helpitem);
1.324 raeburn 4349: if ($action eq 'new') {
4350: $rolename=$env{'form.newrolename'};
4351: } else {
4352: $rolename=$env{'form.rolename'};
1.59 www 4353: }
4354:
1.324 raeburn 4355: my ($crstype,$context);
4356: if ($env{'request.course.id'}) {
4357: $crstype = &Apache::loncommon::course_type();
4358: $context = 'course';
1.439 raeburn 4359: $helpitem = 'Course_Editing_Custom_Roles';
1.324 raeburn 4360: } else {
4361: $context = 'domain';
1.414 raeburn 4362: $crstype = 'course';
1.439 raeburn 4363: $helpitem = 'Domain_Editing_Custom_Roles';
1.324 raeburn 4364: }
1.351 raeburn 4365:
4366: $rolename=~s/[^A-Za-z0-9]//gs;
4367: if (!$rolename || $env{'form.phase'} eq 'pickrole') {
1.439 raeburn 4368: &print_username_entry_form($r,$context,undef,undef,undef,$crstype,$brcrum,
4369: $permission);
1.351 raeburn 4370: return;
4371: }
4372:
1.414 raeburn 4373: my $formname = 'form1';
4374: my %privs=();
4375: my $body_top = '<h2>';
4376: # ------------------------------------------------------- Does this role exist?
1.59 www 4377: my ($rdummy,$roledef)=
4378: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
4379: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1.414 raeburn 4380: $body_top .= &mt('Existing Role').' "';
1.61 www 4381: # ------------------------------------------------- Get current role privileges
1.414 raeburn 4382: ($privs{'system'},$privs{'domain'},$privs{'course'})=split(/\_/,$roledef);
4383: if ($privs{'system'} =~ /bre\&S/) {
4384: if ($context eq 'domain') {
1.417 raeburn 4385: $crstype = 'Course';
1.414 raeburn 4386: } elsif ($crstype eq 'Community') {
4387: $privs{'system'} =~ s/bre\&S//;
4388: }
4389: } elsif ($context eq 'domain') {
4390: $crstype = 'Course';
1.324 raeburn 4391: }
1.59 www 4392: } else {
1.414 raeburn 4393: $body_top .= &mt('New Role').' "';
4394: $roledef='';
1.59 www 4395: }
1.153 banghart 4396: $body_top .= $rolename.'"</h2>';
1.414 raeburn 4397:
4398: # ------------------------------------------------------- What can be assigned?
4399: my %full=();
1.417 raeburn 4400: my %levels=(
1.414 raeburn 4401: course => {},
4402: domain => {},
4403: system => {},
4404: );
4405: my %levelscurrent=(
4406: course => {},
4407: domain => {},
4408: system => {},
4409: );
4410: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
1.160 raeburn 4411: my ($jsback,$elements) = &crumb_utilities();
1.414 raeburn 4412: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
1.417 raeburn 4413: my $head_script =
1.414 raeburn 4414: &Apache::lonuserutils::custom_roledefs_js($context,$crstype,$formname,
4415: \%full,\@templateroles,$jsback);
1.351 raeburn 4416: push (@{$brcrum},
1.414 raeburn 4417: {href => "javascript:backPage(document.$formname,'pickrole','')",
1.351 raeburn 4418: text => "Pick custom role",
4419: faq => 282,bug=>'Instructor Interface',},
1.414 raeburn 4420: {href => "javascript:backPage(document.$formname,'','')",
1.351 raeburn 4421: text => "Edit custom role",
4422: faq => 282,
4423: bug => 'Instructor Interface',
1.439 raeburn 4424: help => $helpitem}
1.351 raeburn 4425: );
4426: my $args = { bread_crumbs => $brcrum,
4427: bread_crumbs_component => 'User Management'};
4428: $r->print(&Apache::loncommon::start_page('Custom Role Editor',
4429: $head_script,$args).
4430: $body_top);
1.414 raeburn 4431: $r->print('<form name="'.$formname.'" method="post" action="">'."\n".
4432: &Apache::lonuserutils::custom_role_header($context,$crstype,
4433: \@templateroles,$prefix));
1.264 bisitz 4434:
1.61 www 4435: $r->print(<<ENDCCF);
4436: <input type="hidden" name="phase" value="set_custom_roles" />
4437: <input type="hidden" name="rolename" value="$rolename" />
4438: ENDCCF
1.414 raeburn 4439: $r->print(&Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
4440: \%levelscurrent,$prefix));
1.135 raeburn 4441: $r->print(&Apache::loncommon::end_data_table().
1.190 raeburn 4442: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'.
1.160 raeburn 4443: '<input type="hidden" name="startrolename" value="'.$env{'form.rolename'}.
1.417 raeburn 4444: '" />'."\n".'<input type="hidden" name="currstate" value="" />'."\n".
1.160 raeburn 4445: '<input type="reset" value="'.&mt("Reset").'" />'."\n".
1.351 raeburn 4446: '<input type="submit" value="'.&mt('Save').'" /></form>');
1.61 www 4447: }
1.414 raeburn 4448:
1.61 www 4449: # ---------------------------------------------------------- Call to definerole
4450: sub set_custom_role {
1.439 raeburn 4451: my ($r,$context,$brcrum,$prefix,$permission) = @_;
1.101 albertel 4452: my $rolename=$env{'form.rolename'};
1.63 www 4453: $rolename=~s/[^A-Za-z0-9]//gs;
1.150 banghart 4454: if (!$rolename) {
1.439 raeburn 4455: &custom_role_editor($r,$context,$brcrum,$prefix,$permission);
1.61 www 4456: return;
4457: }
1.160 raeburn 4458: my ($jsback,$elements) = &crumb_utilities();
1.301 bisitz 4459: my $jscript = '<script type="text/javascript">'
4460: .'// <![CDATA['."\n"
4461: .$jsback."\n"
4462: .'// ]]>'."\n"
4463: .'</script>'."\n";
1.439 raeburn 4464: my $helpitem = 'Course_Editing_Custom_Roles';
4465: if ($context eq 'domain') {
4466: $helpitem = 'Domain_Editing_Custom_Roles';
4467: }
1.352 raeburn 4468: push(@{$brcrum},
4469: {href => "javascript:backPage(document.customresult,'pickrole','')",
4470: text => "Pick custom role",
4471: faq => 282,
4472: bug => 'Instructor Interface',},
4473: {href => "javascript:backPage(document.customresult,'selected_custom_edit','')",
4474: text => "Edit custom role",
4475: faq => 282,
4476: bug => 'Instructor Interface',},
4477: {href => "javascript:backPage(document.customresult,'set_custom_roles','')",
4478: text => "Result",
4479: faq => 282,
4480: bug => 'Instructor Interface',
1.439 raeburn 4481: help => $helpitem,}
1.352 raeburn 4482: );
4483: my $args = { bread_crumbs => $brcrum,
1.414 raeburn 4484: bread_crumbs_component => 'User Management'};
1.351 raeburn 4485: $r->print(&Apache::loncommon::start_page('Save Custom Role',$jscript,$args));
1.160 raeburn 4486:
1.393 raeburn 4487: my $newrole;
1.61 www 4488: my ($rdummy,$roledef)=
1.110 albertel 4489: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
4490:
1.61 www 4491: # ------------------------------------------------------- Does this role exist?
1.188 raeburn 4492: $r->print('<h3>');
1.61 www 4493: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1.73 sakharuk 4494: $r->print(&mt('Existing Role').' "');
1.61 www 4495: } else {
1.73 sakharuk 4496: $r->print(&mt('New Role').' "');
1.61 www 4497: $roledef='';
1.393 raeburn 4498: $newrole = 1;
1.61 www 4499: }
1.188 raeburn 4500: $r->print($rolename.'"</h3>');
1.414 raeburn 4501: # ------------------------------------------------- Assign role and show result
1.61 www 4502:
1.387 bisitz 4503: my $errmsg;
1.414 raeburn 4504: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$prefix);
4505: # Assign role and return result
4506: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
4507: $newprivs{'c'});
1.387 bisitz 4508: if ($result ne 'ok') {
4509: $errmsg = ': '.$result;
4510: }
4511: my $message =
4512: &Apache::lonhtmlcommon::confirm_success(
4513: &mt('Defining Role').$errmsg, ($result eq 'ok' ? 0 : 1));
1.101 albertel 4514: if ($env{'request.course.id'}) {
4515: my $url='/'.$env{'request.course.id'};
1.63 www 4516: $url=~s/\_/\//g;
1.387 bisitz 4517: $result =
4518: &Apache::lonnet::assigncustomrole(
4519: $env{'user.domain'},$env{'user.name'},
4520: $url,
4521: $env{'user.domain'},$env{'user.name'},
4522: $rolename,undef,undef,undef,$context);
4523: if ($result ne 'ok') {
4524: $errmsg = ': '.$result;
4525: }
4526: $message .=
4527: '<br />'
4528: .&Apache::lonhtmlcommon::confirm_success(
4529: &mt('Assigning Role to Self').$errmsg, ($result eq 'ok' ? 0 : 1));
1.63 www 4530: }
1.380 bisitz 4531: $r->print(
1.387 bisitz 4532: &Apache::loncommon::confirmwrapper($message)
4533: .'<br />'
4534: .&Apache::lonhtmlcommon::actionbox([
4535: '<a href="javascript:backPage(document.customresult,'."'pickrole'".')">'
4536: .&mt('Create or edit another custom role')
4537: .'</a>'])
1.380 bisitz 4538: .'<form name="customresult" method="post" action="">'
1.387 bisitz 4539: .&Apache::lonhtmlcommon::echo_form_input([])
4540: .'</form>'
1.380 bisitz 4541: );
1.58 www 4542: }
4543:
1.2 www 4544: # ================================================================ Main Handler
4545: sub handler {
4546: my $r = shift;
4547: if ($r->header_only) {
1.68 www 4548: &Apache::loncommon::content_type($r,'text/html');
1.2 www 4549: $r->send_http_header;
4550: return OK;
4551: }
1.439 raeburn 4552: my ($context,$crstype,$cid,$cnum,$cdom,$allhelpitems);
4553:
1.190 raeburn 4554: if ($env{'request.course.id'}) {
4555: $context = 'course';
1.318 raeburn 4556: $crstype = &Apache::loncommon::course_type();
1.190 raeburn 4557: } elsif ($env{'request.role'} =~ /^au\./) {
1.206 raeburn 4558: $context = 'author';
1.190 raeburn 4559: } else {
4560: $context = 'domain';
4561: }
1.375 raeburn 4562:
1.439 raeburn 4563: my ($permission,$allowed) =
4564: &Apache::lonuserutils::get_permission($context,$crstype);
4565:
4566: if ($allowed) {
4567: my @allhelp;
4568: if ($context eq 'course') {
4569: $cid = $env{'request.course.id'};
4570: $cdom = $env{'course.'.$cid.'.domain'};
4571: $cnum = $env{'course.'.$cid.'.num'};
4572:
4573: if ($permission->{'cusr'}) {
4574: push(@allhelp,'Course_Create_Class_List');
4575: }
4576: if ($permission->{'view'} || $permission->{'cusr'}) {
4577: push(@allhelp,('Course_Change_Privileges','Course_View_Class_List'));
4578: }
4579: if ($permission->{'custom'}) {
4580: push(@allhelp,'Course_Editing_Custom_Roles');
4581: }
4582: if ($permission->{'cusr'}) {
4583: push(@allhelp,('Course_Add_Student','Course_Drop_Student'));
4584: }
4585: unless ($permission->{'cusr_section'}) {
4586: if (&Apache::lonnet::auto_run($cnum,$cdom) && (($permission->{'cusr'}) || ($permission->{'view'}))) {
4587: push(@allhelp,'Course_Automated_Enrollment');
4588: }
4589: if ($permission->{'selfenrolladmin'}) {
4590: push(@allhelp,'Course_Approve_Selfenroll');
4591: }
4592: }
4593: if ($permission->{'grp_manage'}) {
4594: push(@allhelp,'Course_Manage_Group');
4595: }
4596: if ($permission->{'view'} || $permission->{'cusr'}) {
4597: push(@allhelp,'Course_User_Logs');
4598: }
4599: } elsif ($context eq 'author') {
4600: push(@allhelp,('Author_Change_Privileges','Author_Create_Coauthor_List',
4601: 'Author_View_Coauthor_List','Author_User_Logs'));
4602: } else {
4603: if ($permission->{'cusr'}) {
4604: push(@allhelp,'Domain_Change_Privileges');
4605: if ($permission->{'activity'}) {
4606: push(@allhelp,'Domain_User_Access_Logs');
4607: }
4608: push(@allhelp,('Domain_Create_Users','Domain_View_Users_List'));
4609: if ($permission->{'custom'}) {
4610: push(@allhelp,'Domain_Editing_Custom_Roles');
4611: }
4612: push(@allhelp,('Domain_Role_Approvals','Domain_Username_Approvals','Domain_Change_Logs'));
4613: } elsif ($permission->{'view'}) {
4614: push(@allhelp,'Domain_View_Privileges');
4615: if ($permission->{'activity'}) {
4616: push(@allhelp,'Domain_User_Access_Logs');
4617: }
4618: push(@allhelp,('Domain_View_Users_List','Domain_Change_Logs'));
4619: }
4620: }
4621: if (@allhelp) {
4622: $allhelpitems = join(',',@allhelp);
4623: }
4624: }
4625:
1.190 raeburn 4626: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.233 raeburn 4627: ['action','state','callingform','roletype','showrole','bulkaction','popup','phase',
1.391 raeburn 4628: 'username','domain','srchterm','srchdomain','srchin','srchby','srchtype','queue']);
1.190 raeburn 4629: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.351 raeburn 4630: my $args;
4631: my $brcrum = [];
4632: my $bread_crumbs_component = 'User Management';
1.391 raeburn 4633: if (($env{'form.action'} ne 'dateselect') && ($env{'form.action'} ne 'displayuserreq')) {
1.351 raeburn 4634: $brcrum = [{href=>"/adm/createuser",
4635: text=>"User Management",
1.439 raeburn 4636: help=>$allhelpitems}
1.351 raeburn 4637: ];
1.202 raeburn 4638: }
1.190 raeburn 4639: if (!$allowed) {
1.358 raeburn 4640: if ($context eq 'course') {
4641: $r->internal_redirect('/adm/viewclasslist');
4642: return OK;
4643: }
1.190 raeburn 4644: $env{'user.error.msg'}=
4645: "/adm/createuser:cst:0:0:Cannot create/modify user data ".
4646: "or view user status.";
4647: return HTTP_NOT_ACCEPTABLE;
4648: }
4649:
4650: &Apache::loncommon::content_type($r,'text/html');
4651: $r->send_http_header;
4652:
1.375 raeburn 4653: my $showcredits;
4654: if ((($context eq 'course') && ($crstype eq 'Course')) ||
4655: ($context eq 'domain')) {
4656: my %domdefaults =
4657: &Apache::lonnet::get_domain_defaults($env{'request.role.domain'});
4658: if ($domdefaults{'officialcredits'} || $domdefaults{'unofficialcredits'}) {
4659: $showcredits = 1;
4660: }
4661: }
4662:
1.190 raeburn 4663: # Main switch on form.action and form.state, as appropriate
4664: if (! exists($env{'form.action'})) {
1.351 raeburn 4665: $args = {bread_crumbs => $brcrum,
4666: bread_crumbs_component => $bread_crumbs_component};
4667: $r->print(&header(undef,$args));
1.318 raeburn 4668: $r->print(&print_main_menu($permission,$context,$crstype));
1.190 raeburn 4669: } elsif ($env{'form.action'} eq 'upload' && $permission->{'cusr'}) {
1.439 raeburn 4670: my $helpitem = 'Course_Create_Class_List';
4671: if ($context eq 'author') {
4672: $helpitem = 'Author_Create_Coauthor_List';
4673: } elsif ($context eq 'domain') {
4674: $helpitem = 'Domain_Create_Users';
4675: }
1.351 raeburn 4676: push(@{$brcrum},
4677: { href => '/adm/createuser?action=upload&state=',
4678: text => 'Upload Users List',
1.439 raeburn 4679: help => $helpitem,
1.351 raeburn 4680: });
4681: $bread_crumbs_component = 'Upload Users List';
4682: $args = {bread_crumbs => $brcrum,
4683: bread_crumbs_component => $bread_crumbs_component};
4684: $r->print(&header(undef,$args));
1.190 raeburn 4685: $r->print('<form name="studentform" method="post" '.
4686: 'enctype="multipart/form-data" '.
4687: ' action="/adm/createuser">'."\n");
4688: if (! exists($env{'form.state'})) {
4689: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
4690: } elsif ($env{'form.state'} eq 'got_file') {
1.375 raeburn 4691: &Apache::lonuserutils::print_upload_manager_form($r,$context,$permission,
4692: $crstype,$showcredits);
1.190 raeburn 4693: } elsif ($env{'form.state'} eq 'enrolling') {
4694: if ($env{'form.datatoken'}) {
1.375 raeburn 4695: &Apache::lonuserutils::upfile_drop_add($r,$context,$permission,
4696: $showcredits);
1.190 raeburn 4697: }
4698: } else {
4699: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
4700: }
1.416 raeburn 4701: } elsif (((($env{'form.action'} eq 'singleuser') || ($env{'form.action'}
4702: eq 'singlestudent')) && ($permission->{'cusr'})) ||
1.418 raeburn 4703: (($env{'form.action'} eq 'singleuser') && ($permission->{'view'})) ||
1.416 raeburn 4704: (($env{'form.action'} eq 'accesslogs') && ($permission->{'activity'}))) {
1.190 raeburn 4705: my $phase = $env{'form.phase'};
4706: my @search = ('srchterm','srchby','srchin','srchtype','srchdomain');
1.192 albertel 4707: &Apache::loncreateuser::restore_prev_selections();
4708: my $srch;
4709: foreach my $item (@search) {
4710: $srch->{$item} = $env{'form.'.$item};
4711: }
1.207 raeburn 4712: if (($phase eq 'get_user_info') || ($phase eq 'userpicked') ||
1.416 raeburn 4713: ($phase eq 'createnewuser') || ($phase eq 'activity')) {
1.207 raeburn 4714: if ($env{'form.phase'} eq 'createnewuser') {
4715: my $response;
4716: if ($env{'form.srchterm'} !~ /^$match_username$/) {
1.366 bisitz 4717: my $response =
4718: '<span class="LC_warning">'
4719: .&mt('You must specify a valid username. Only the following are allowed:'
4720: .' letters numbers - . @')
4721: .'</span>';
1.221 raeburn 4722: $env{'form.phase'} = '';
1.375 raeburn 4723: &print_username_entry_form($r,$context,$response,$srch,undef,
1.439 raeburn 4724: $crstype,$brcrum,$permission);
1.207 raeburn 4725: } else {
4726: my $ccuname =&LONCAPA::clean_username($srch->{'srchterm'});
4727: my $ccdomain=&LONCAPA::clean_domain($srch->{'srchdomain'});
4728: &print_user_modification_page($r,$ccuname,$ccdomain,
1.221 raeburn 4729: $srch,$response,$context,
1.375 raeburn 4730: $permission,$crstype,$brcrum,
4731: $showcredits);
1.207 raeburn 4732: }
4733: } elsif ($env{'form.phase'} eq 'get_user_info') {
1.190 raeburn 4734: my ($currstate,$response,$forcenewuser,$results) =
1.221 raeburn 4735: &user_search_result($context,$srch);
1.190 raeburn 4736: if ($env{'form.currstate'} eq 'modify') {
4737: $currstate = $env{'form.currstate'};
4738: }
4739: if ($currstate eq 'select') {
4740: &print_user_selection_page($r,$response,$srch,$results,
1.351 raeburn 4741: \@search,$context,undef,$crstype,
4742: $brcrum);
1.416 raeburn 4743: } elsif (($currstate eq 'modify') || ($env{'form.action'} eq 'accesslogs')) {
4744: my ($ccuname,$ccdomain,$uhome);
1.190 raeburn 4745: if (($srch->{'srchby'} eq 'uname') &&
4746: ($srch->{'srchtype'} eq 'exact')) {
4747: $ccuname = $srch->{'srchterm'};
4748: $ccdomain= $srch->{'srchdomain'};
4749: } else {
4750: my @matchedunames = keys(%{$results});
4751: ($ccuname,$ccdomain) = split(/:/,$matchedunames[0]);
4752: }
4753: $ccuname =&LONCAPA::clean_username($ccuname);
4754: $ccdomain=&LONCAPA::clean_domain($ccdomain);
1.416 raeburn 4755: if ($env{'form.action'} eq 'accesslogs') {
4756: my $uhome;
4757: if (($ccuname ne '') && ($ccdomain ne '')) {
4758: $uhome = &Apache::lonnet::homeserver($ccuname,$ccdomain);
4759: }
4760: if (($uhome eq '') || ($uhome eq 'no_host')) {
4761: $env{'form.phase'} = '';
4762: undef($forcenewuser);
4763: #if ($response) {
4764: # unless ($response =~ m{\Q<br /><br />\E$}) {
4765: # $response .= '<br /><br />';
4766: # }
4767: #}
4768: &print_username_entry_form($r,$context,$response,$srch,
1.439 raeburn 4769: $forcenewuser,$crstype,$brcrum,
4770: $permission);
1.416 raeburn 4771: } else {
4772: &print_useraccesslogs_display($r,$ccuname,$ccdomain,$permission,$brcrum);
4773: }
4774: } else {
4775: if ($env{'form.forcenewuser'}) {
4776: $response = '';
4777: }
4778: &print_user_modification_page($r,$ccuname,$ccdomain,
4779: $srch,$response,$context,
4780: $permission,$crstype,$brcrum);
1.190 raeburn 4781: }
4782: } elsif ($currstate eq 'query') {
1.351 raeburn 4783: &print_user_query_page($r,'createuser',$brcrum);
1.190 raeburn 4784: } else {
1.229 raeburn 4785: $env{'form.phase'} = '';
1.207 raeburn 4786: &print_username_entry_form($r,$context,$response,$srch,
1.439 raeburn 4787: $forcenewuser,$crstype,$brcrum,
4788: $permission);
1.190 raeburn 4789: }
4790: } elsif ($env{'form.phase'} eq 'userpicked') {
4791: my $ccuname = &LONCAPA::clean_username($env{'form.seluname'});
4792: my $ccdomain = &LONCAPA::clean_domain($env{'form.seludom'});
1.416 raeburn 4793: if ($env{'form.action'} eq 'accesslogs') {
4794: &print_useraccesslogs_display($r,$ccuname,$ccdomain,$permission,$brcrum);
4795: } else {
4796: &print_user_modification_page($r,$ccuname,$ccdomain,$srch,'',
4797: $context,$permission,$crstype,
4798: $brcrum);
4799: }
4800: } elsif ($env{'form.action'} eq 'accesslogs') {
4801: my $ccuname = &LONCAPA::clean_username($env{'form.accessuname'});
4802: my $ccdomain = &LONCAPA::clean_domain($env{'form.accessudom'});
4803: &print_useraccesslogs_display($r,$ccuname,$ccdomain,$permission,$brcrum);
1.190 raeburn 4804: }
4805: } elsif ($env{'form.phase'} eq 'update_user_data') {
1.375 raeburn 4806: &update_user_data($r,$context,$crstype,$brcrum,$showcredits);
1.190 raeburn 4807: } else {
1.351 raeburn 4808: &print_username_entry_form($r,$context,undef,$srch,undef,$crstype,
1.439 raeburn 4809: $brcrum,$permission);
1.190 raeburn 4810: }
4811: } elsif ($env{'form.action'} eq 'custom' && $permission->{'custom'}) {
1.414 raeburn 4812: my $prefix;
1.190 raeburn 4813: if ($env{'form.phase'} eq 'set_custom_roles') {
1.439 raeburn 4814: &set_custom_role($r,$context,$brcrum,$prefix,$permission);
1.190 raeburn 4815: } else {
1.439 raeburn 4816: &custom_role_editor($r,$context,$brcrum,$prefix,$permission);
1.190 raeburn 4817: }
1.362 raeburn 4818: } elsif (($env{'form.action'} eq 'processauthorreq') &&
4819: ($permission->{'cusr'}) &&
4820: (&Apache::lonnet::allowed('cau',$env{'request.role.domain'}))) {
4821: push(@{$brcrum},
4822: {href => '/adm/createuser?action=processauthorreq',
1.385 bisitz 4823: text => 'Authoring Space requests',
1.362 raeburn 4824: help => 'Domain_Role_Approvals'});
4825: $bread_crumbs_component = 'Authoring requests';
4826: if ($env{'form.state'} eq 'done') {
4827: push(@{$brcrum},
4828: {href => '/adm/createuser?action=authorreqqueue',
4829: text => 'Result',
4830: help => 'Domain_Role_Approvals'});
4831: $bread_crumbs_component = 'Authoring request result';
4832: }
4833: $args = { bread_crumbs => $brcrum,
4834: bread_crumbs_component => $bread_crumbs_component};
1.391 raeburn 4835: my $js = &usernamerequest_javascript();
4836: $r->print(&header(&add_script($js),$args));
1.362 raeburn 4837: if (!exists($env{'form.state'})) {
4838: $r->print(&Apache::loncoursequeueadmin::display_queued_requests('requestauthor',
4839: $env{'request.role.domain'}));
4840: } elsif ($env{'form.state'} eq 'done') {
4841: $r->print('<h3>'.&mt('Authoring request processing').'</h3>'."\n");
4842: $r->print(&Apache::loncoursequeueadmin::update_request_queue('requestauthor',
4843: $env{'request.role.domain'}));
4844: }
1.391 raeburn 4845: } elsif (($env{'form.action'} eq 'processusernamereq') &&
4846: ($permission->{'cusr'}) &&
4847: (&Apache::lonnet::allowed('cau',$env{'request.role.domain'}))) {
4848: push(@{$brcrum},
4849: {href => '/adm/createuser?action=processusernamereq',
4850: text => 'LON-CAPA account requests',
4851: help => 'Domain_Username_Approvals'});
4852: $bread_crumbs_component = 'Account requests';
4853: if ($env{'form.state'} eq 'done') {
4854: push(@{$brcrum},
4855: {href => '/adm/createuser?action=usernamereqqueue',
4856: text => 'Result',
4857: help => 'Domain_Username_Approvals'});
4858: $bread_crumbs_component = 'LON-CAPA account request result';
4859: }
4860: $args = { bread_crumbs => $brcrum,
4861: bread_crumbs_component => $bread_crumbs_component};
4862: my $js = &usernamerequest_javascript();
4863: $r->print(&header(&add_script($js),$args));
4864: if (!exists($env{'form.state'})) {
4865: $r->print(&Apache::loncoursequeueadmin::display_queued_requests('requestusername',
4866: $env{'request.role.domain'}));
4867: } elsif ($env{'form.state'} eq 'done') {
4868: $r->print('<h3>'.&mt('LON-CAPA account request processing').'</h3>'."\n");
4869: $r->print(&Apache::loncoursequeueadmin::update_request_queue('requestusername',
4870: $env{'request.role.domain'}));
4871: }
4872: } elsif (($env{'form.action'} eq 'displayuserreq') &&
4873: ($permission->{'cusr'})) {
4874: my $dom = $env{'form.domain'};
4875: my $uname = $env{'form.username'};
4876: my $warning;
4877: if (($dom =~ /^$match_domain$/) && (&Apache::lonnet::domain($dom) ne '')) {
4878: if (($dom eq $env{'request.role.domain'}) && (&Apache::lonnet::allowed('ccc',$dom))) {
4879: if (($uname =~ /^$match_username$/) && ($env{'form.queue'} eq 'approval')) {
4880: my $uhome = &Apache::lonnet::homeserver($uname,$dom);
4881: if ($uhome eq 'no_host') {
4882: my $queue = $env{'form.queue'};
4883: my $reqkey = &escape($uname).'_'.$queue;
4884: my $namespace = 'usernamequeue';
4885: my $domconfig = &Apache::lonnet::get_domainconfiguser($dom);
4886: my %queued =
4887: &Apache::lonnet::get($namespace,[$reqkey],$dom,$domconfig);
4888: unless ($queued{$reqkey}) {
4889: $warning = &mt('No information was found for this LON-CAPA account request.');
4890: }
4891: } else {
4892: $warning = &mt('A LON-CAPA account already exists for the requested username and domain.');
4893: }
4894: } else {
4895: $warning = &mt('LON-CAPA account request status check is for an invalid username.');
4896: }
4897: } else {
4898: $warning = &mt('You do not have rights to view LON-CAPA account requests in the domain specified.');
4899: }
4900: } else {
4901: $warning = &mt('LON-CAPA account request status check is for an invalid domain.');
4902: }
4903: my $args = { only_body => 1 };
4904: $r->print(&header(undef,$args).
4905: '<h3>'.&mt('LON-CAPA Account Request Details').'</h3>');
4906: if ($warning ne '') {
4907: $r->print('<div class="LC_warning">'.$warning.'</div>');
4908: } else {
4909: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
4910: my $domconfiguser = &Apache::lonnet::get_domainconfiguser($dom);
4911: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
4912: if (ref($domconfig{'usercreation'}) eq 'HASH') {
4913: if (ref($domconfig{'usercreation'}{'cancreate'}) eq 'HASH') {
4914: if (ref($domconfig{'usercreation'}{'cancreate'}{'emailusername'}) eq 'HASH') {
4915: my %info =
4916: &Apache::lonnet::get('nohist_requestedusernames',[$uname],$dom,$domconfiguser);
4917: if (ref($info{$uname}) eq 'HASH') {
1.396 raeburn 4918: my $usertype = $info{$uname}{'inststatus'};
4919: unless ($usertype) {
4920: $usertype = 'default';
4921: }
4922: if (ref($domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}) eq 'HASH') {
4923: if ((ref($infofields) eq 'ARRAY') && (ref($infotitles) eq 'HASH')) {
4924: $r->print('<div>'.&Apache::lonhtmlcommon::start_pick_box());
4925: my ($num,$count,$showstatus);
4926: $count = scalar(keys(%{$domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}}));
4927: unless ($usertype eq 'default') {
4928: my ($othertitle,$usertypes,$types) =
4929: &Apache::loncommon::sorted_inst_types($dom);
4930: if (ref($usertypes) eq 'HASH') {
4931: if ($usertypes->{$usertype}) {
4932: $showstatus = $usertypes->{$usertype};
4933: $count ++;
4934: }
4935: }
4936: }
4937: foreach my $field (@{$infofields}) {
4938: next unless ($domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}{$field});
4939: next unless ($infotitles->{$field});
4940: $r->print(&Apache::lonhtmlcommon::row_title($infotitles->{$field}).
4941: $info{$uname}{$field});
4942: $num ++;
4943: if ($count == $num) {
4944: $r->print(&Apache::lonhtmlcommon::row_closure(1));
4945: } else {
4946: $r->print(&Apache::lonhtmlcommon::row_closure());
4947: }
4948: }
4949: if ($showstatus) {
4950: $r->print(&Apache::lonhtmlcommon::row_title(&mt('Status type (self-reported)')).
4951: $showstatus.
4952: &Apache::lonhtmlcommon::row_closure(1));
1.391 raeburn 4953: }
1.396 raeburn 4954: $r->print(&Apache::lonhtmlcommon::end_pick_box().'</div>');
1.391 raeburn 4955: }
4956: }
4957: }
4958: }
4959: }
4960: }
4961: $r->print(&close_popup_form());
4962: }
1.207 raeburn 4963: } elsif (($env{'form.action'} eq 'listusers') &&
4964: ($permission->{'view'} || $permission->{'cusr'})) {
1.439 raeburn 4965: my $helpitem = 'Course_View_Class_List';
4966: if ($context eq 'author') {
4967: $helpitem = 'Author_View_Coauthor_List';
4968: } elsif ($context eq 'domain') {
4969: $helpitem = 'Domain_View_Users_List';
4970: }
1.202 raeburn 4971: if ($env{'form.phase'} eq 'bulkchange') {
1.351 raeburn 4972: push(@{$brcrum},
4973: {href => '/adm/createuser?action=listusers',
4974: text => "List Users"},
4975: {href => "/adm/createuser",
4976: text => "Result",
1.439 raeburn 4977: help => $helpitem});
1.351 raeburn 4978: $bread_crumbs_component = 'Update Users';
4979: $args = {bread_crumbs => $brcrum,
4980: bread_crumbs_component => $bread_crumbs_component};
4981: $r->print(&header(undef,$args));
1.202 raeburn 4982: my $setting = $env{'form.roletype'};
4983: my $choice = $env{'form.bulkaction'};
4984: if ($permission->{'cusr'}) {
1.336 raeburn 4985: &Apache::lonuserutils::update_user_list($r,$context,$setting,$choice,$crstype);
1.221 raeburn 4986: } else {
4987: $r->print(&mt('You are not authorized to make bulk changes to user roles'));
1.223 raeburn 4988: $r->print('<p><a href="/adm/createuser?action=listusers">'.&mt('Display User Lists').'</a>');
1.202 raeburn 4989: }
4990: } else {
1.351 raeburn 4991: push(@{$brcrum},
4992: {href => '/adm/createuser?action=listusers',
4993: text => "List Users",
1.439 raeburn 4994: help => $helpitem});
1.351 raeburn 4995: $bread_crumbs_component = 'List Users';
4996: $args = {bread_crumbs => $brcrum,
4997: bread_crumbs_component => $bread_crumbs_component};
1.202 raeburn 4998: my ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles);
4999: my $formname = 'studentform';
1.364 raeburn 5000: my $hidecall = "hide_searching();";
1.321 raeburn 5001: if (($context eq 'domain') && (($env{'form.roletype'} eq 'course') ||
5002: ($env{'form.roletype'} eq 'community'))) {
5003: if ($env{'form.roletype'} eq 'course') {
5004: ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles) =
5005: &Apache::lonuserutils::courses_selector($env{'request.role.domain'},
5006: $formname);
5007: } elsif ($env{'form.roletype'} eq 'community') {
5008: $cb_jscript =
5009: &Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
5010: my %elements = (
5011: coursepick => 'radio',
5012: coursetotal => 'text',
5013: courselist => 'text',
5014: );
5015: $jscript = &Apache::lonhtmlcommon::set_form_elements(\%elements);
5016: }
1.364 raeburn 5017: $jscript .= &verify_user_display($context)."\n".
5018: &Apache::loncommon::check_uncheck_jscript();
1.202 raeburn 5019: my $js = &add_script($jscript).$cb_jscript;
5020: my $loadcode =
5021: &Apache::lonuserutils::course_selector_loadcode($formname);
5022: if ($loadcode ne '') {
1.364 raeburn 5023: $args->{add_entries} = {onload => "$loadcode;$hidecall"};
5024: } else {
5025: $args->{add_entries} = {onload => $hidecall};
1.202 raeburn 5026: }
1.351 raeburn 5027: $r->print(&header($js,$args));
1.191 raeburn 5028: } else {
1.364 raeburn 5029: $args->{add_entries} = {onload => $hidecall};
5030: $jscript = &verify_user_display($context).
5031: &Apache::loncommon::check_uncheck_jscript();
5032: $r->print(&header(&add_script($jscript),$args));
1.191 raeburn 5033: }
1.202 raeburn 5034: &Apache::lonuserutils::print_userlist($r,undef,$permission,$context,
1.375 raeburn 5035: $formname,$totcodes,$codetitles,$idlist,$idlist_titles,
5036: $showcredits);
1.191 raeburn 5037: }
1.213 raeburn 5038: } elsif ($env{'form.action'} eq 'drop' && $permission->{'cusr'}) {
1.318 raeburn 5039: my $brtext;
5040: if ($crstype eq 'Community') {
5041: $brtext = 'Drop Members';
5042: } else {
5043: $brtext = 'Drop Students';
5044: }
1.351 raeburn 5045: push(@{$brcrum},
5046: {href => '/adm/createuser?action=drop',
5047: text => $brtext,
5048: help => 'Course_Drop_Student'});
5049: if ($env{'form.state'} eq 'done') {
5050: push(@{$brcrum},
5051: {href=>'/adm/createuser?action=drop',
5052: text=>"Result"});
5053: }
5054: $bread_crumbs_component = $brtext;
5055: $args = {bread_crumbs => $brcrum,
5056: bread_crumbs_component => $bread_crumbs_component};
5057: $r->print(&header(undef,$args));
1.213 raeburn 5058: if (!exists($env{'form.state'})) {
1.318 raeburn 5059: &Apache::lonuserutils::print_drop_menu($r,$context,$permission,$crstype);
1.213 raeburn 5060: } elsif ($env{'form.state'} eq 'done') {
5061: &Apache::lonuserutils::update_user_list($r,$context,undef,
5062: $env{'form.action'});
5063: }
1.202 raeburn 5064: } elsif ($env{'form.action'} eq 'dateselect') {
5065: if ($permission->{'cusr'}) {
1.351 raeburn 5066: $r->print(&header(undef,{'no_nav_bar' => 1}).
1.375 raeburn 5067: &Apache::lonuserutils::date_section_selector($context,$permission,
5068: $crstype,$showcredits));
1.202 raeburn 5069: } else {
1.351 raeburn 5070: $r->print(&header(undef,{'no_nav_bar' => 1}).
5071: '<span class="LC_error">'.&mt('You do not have permission to modify dates or sections for users').'</span>');
1.202 raeburn 5072: }
1.237 raeburn 5073: } elsif ($env{'form.action'} eq 'selfenroll') {
1.398 raeburn 5074: if ($permission->{selfenrolladmin}) {
5075: my %currsettings = (
5076: selfenroll_types => $env{'course.'.$cid.'.internal.selfenroll_types'},
5077: selfenroll_registered => $env{'course.'.$cid.'.internal.selfenroll_registered'},
5078: selfenroll_section => $env{'course.'.$cid.'.internal.selfenroll_section'},
5079: selfenroll_notifylist => $env{'course.'.$cid.'.internal.selfenroll_notifylist'},
5080: selfenroll_approval => $env{'course.'.$cid.'.internal.selfenroll_approval'},
5081: selfenroll_limit => $env{'course.'.$cid.'.internal.selfenroll_limit'},
5082: selfenroll_cap => $env{'course.'.$cid.'.internal.selfenroll_cap'},
5083: selfenroll_start_date => $env{'course.'.$cid.'.internal.selfenroll_start_date'},
5084: selfenroll_end_date => $env{'course.'.$cid.'.internal.selfenroll_end_date'},
5085: selfenroll_start_access => $env{'course.'.$cid.'.internal.selfenroll_start_access'},
5086: selfenroll_end_access => $env{'course.'.$cid.'.internal.selfenroll_end_access'},
5087: default_enrollment_start_date => $env{'course.'.$cid.'.default_enrollment_start_date'},
5088: default_enrollment_end_date => $env{'course.'.$cid.'.default_enrollment_end_date'},
1.400 raeburn 5089: uniquecode => $env{'course.'.$cid.'.internal.uniquecode'},
1.398 raeburn 5090: );
5091: push(@{$brcrum},
5092: {href => '/adm/createuser?action=selfenroll',
5093: text => "Configure Self-enrollment",
5094: help => 'Course_Self_Enrollment'});
5095: if (!exists($env{'form.state'})) {
5096: $args = { bread_crumbs => $brcrum,
5097: bread_crumbs_component => 'Configure Self-enrollment'};
5098: $r->print(&header(undef,$args));
5099: $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n");
5100: &print_selfenroll_menu($r,'course',$cid,$cdom,$cnum,\%currsettings);
5101: } elsif ($env{'form.state'} eq 'done') {
5102: push (@{$brcrum},
5103: {href=>'/adm/createuser?action=selfenroll',
5104: text=>"Result"});
5105: $args = { bread_crumbs => $brcrum,
5106: bread_crumbs_component => 'Self-enrollment result'};
5107: $r->print(&header(undef,$args));
5108: $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n");
1.400 raeburn 5109: &update_selfenroll_config($r,$cid,$cdom,$cnum,$context,$crstype,\%currsettings);
1.398 raeburn 5110: }
5111: } else {
5112: $r->print(&header(undef,{'no_nav_bar' => 1}).
5113: '<span class="LC_error">'.&mt('You do not have permission to configure self-enrollment').'</span>');
1.237 raeburn 5114: }
1.277 raeburn 5115: } elsif ($env{'form.action'} eq 'selfenrollqueue') {
1.418 raeburn 5116: if ($permission->{selfenrolladmin}) {
1.351 raeburn 5117: push(@{$brcrum},
5118: {href => '/adm/createuser?action=selfenrollqueue',
1.418 raeburn 5119: text => 'Enrollment requests',
1.439 raeburn 5120: help => 'Course_Approve_Selfenroll'});
1.418 raeburn 5121: $bread_crumbs_component = 'Enrollment requests';
5122: if ($env{'form.state'} eq 'done') {
5123: push(@{$brcrum},
5124: {href => '/adm/createuser?action=selfenrollqueue',
5125: text => 'Result',
1.439 raeburn 5126: help => 'Course_Approve_Selfenroll'});
1.418 raeburn 5127: $bread_crumbs_component = 'Enrollment result';
5128: }
5129: $args = { bread_crumbs => $brcrum,
5130: bread_crumbs_component => $bread_crumbs_component};
5131: $r->print(&header(undef,$args));
5132: my $coursedesc = $env{'course.'.$cid.'.description'};
5133: if (!exists($env{'form.state'})) {
5134: $r->print('<h3>'.&mt('Pending enrollment requests').'</h3>'."\n");
5135: $r->print(&Apache::loncoursequeueadmin::display_queued_requests($context,
5136: $cdom,$cnum));
5137: } elsif ($env{'form.state'} eq 'done') {
5138: $r->print('<h3>'.&mt('Enrollment request processing').'</h3>'."\n");
5139: $r->print(&Apache::loncoursequeueadmin::update_request_queue($context,
1.430 raeburn 5140: $cdom,$cnum,$coursedesc));
1.418 raeburn 5141: }
5142: } else {
5143: $r->print(&header(undef,{'no_nav_bar' => 1}).
5144: '<span class="LC_error">'.&mt('You do not have permission to manage self-enrollment').'</span>');
1.351 raeburn 5145: }
1.418 raeburn 5146: } elsif ($env{'form.action'} eq 'changelogs') {
5147: if ($permission->{cusr} || $permission->{view}) {
5148: &print_userchangelogs_display($r,$context,$permission,$brcrum);
5149: } else {
5150: $r->print(&header(undef,{'no_nav_bar' => 1}).
5151: '<span class="LC_error">'.&mt('You do not have permission to view change logs').'</span>');
1.277 raeburn 5152: }
1.428 raeburn 5153: } elsif ($env{'form.action'} eq 'helpdesk') {
5154: if (($permission->{'owner'}) || ($permission->{'co-owner'})) {
5155: if ($env{'form.state'} eq 'process') {
5156: if ($permission->{'owner'}) {
5157: &update_helpdeskaccess($r,$permission,$brcrum);
5158: } else {
5159: &print_helpdeskaccess_display($r,$permission,$brcrum);
1.430 raeburn 5160: }
1.428 raeburn 5161: } else {
5162: &print_helpdeskaccess_display($r,$permission,$brcrum);
5163: }
5164: } else {
5165: $r->print(&header(undef,{'no_nav_bar' => 1}).
5166: '<span class="LC_error">'.&mt('You do not have permission to view helpdesk access').'</span>');
5167: }
1.190 raeburn 5168: } else {
1.351 raeburn 5169: $bread_crumbs_component = 'User Management';
5170: $args = { bread_crumbs => $brcrum,
5171: bread_crumbs_component => $bread_crumbs_component};
5172: $r->print(&header(undef,$args));
1.318 raeburn 5173: $r->print(&print_main_menu($permission,$context,$crstype));
1.190 raeburn 5174: }
1.351 raeburn 5175: $r->print(&Apache::loncommon::end_page());
1.190 raeburn 5176: return OK;
5177: }
5178:
5179: sub header {
1.351 raeburn 5180: my ($jscript,$args) = @_;
1.190 raeburn 5181: my $start_page;
1.351 raeburn 5182: if (ref($args) eq 'HASH') {
5183: $start_page=&Apache::loncommon::start_page('User Management',$jscript,$args);
1.190 raeburn 5184: } else {
1.351 raeburn 5185: $start_page=&Apache::loncommon::start_page('User Management',$jscript);
1.190 raeburn 5186: }
5187: return $start_page;
5188: }
1.2 www 5189:
1.191 raeburn 5190: sub add_script {
5191: my ($js) = @_;
1.301 bisitz 5192: return '<script type="text/javascript">'."\n"
5193: .'// <![CDATA['."\n"
5194: .$js."\n"
5195: .'// ]]>'."\n"
5196: .'</script>'."\n";
1.191 raeburn 5197: }
5198:
1.391 raeburn 5199: sub usernamerequest_javascript {
5200: my $js = <<ENDJS;
5201:
5202: function openusernamereqdisplay(dom,uname,queue) {
5203: var url = '/adm/createuser?action=displayuserreq';
5204: url += '&domain='+dom+'&username='+uname+'&queue='+queue;
5205: var title = 'Account_Request_Browser';
5206: var options = 'scrollbars=1,resizable=1,menubar=0';
5207: options += ',width=700,height=600';
5208: var stdeditbrowser = open(url,title,options,'1');
5209: stdeditbrowser.focus();
5210: return;
5211: }
5212:
5213: ENDJS
5214: }
5215:
5216: sub close_popup_form {
5217: my $close= &mt('Close Window');
5218: return << "END";
5219: <p><form name="displayreq" action="" method="post">
5220: <input type="button" name="closeme" value="$close" onclick="javascript:self.close();" />
5221: </form></p>
5222: END
5223: }
5224:
1.202 raeburn 5225: sub verify_user_display {
1.364 raeburn 5226: my ($context) = @_;
1.374 raeburn 5227: my %lt = &Apache::lonlocal::texthash (
5228: course => 'course(s): description, section(s), status',
5229: community => 'community(s): description, section(s), status',
5230: author => 'author',
5231: );
1.364 raeburn 5232: my $photos;
5233: if (($context eq 'course') && $env{'request.course.id'}) {
5234: $photos = $env{'course.'.$env{'request.course.id'}.'.internal.showphoto'};
5235: }
1.202 raeburn 5236: my $output = <<"END";
5237:
1.364 raeburn 5238: function hide_searching() {
5239: if (document.getElementById('searching')) {
5240: document.getElementById('searching').style.display = 'none';
5241: }
5242: return;
5243: }
5244:
1.202 raeburn 5245: function display_update() {
5246: document.studentform.action.value = 'listusers';
5247: document.studentform.phase.value = 'display';
5248: document.studentform.submit();
5249: }
5250:
1.364 raeburn 5251: function updateCols(caller) {
5252: var context = '$context';
5253: var photos = '$photos';
5254: if (caller == 'Status') {
1.374 raeburn 5255: if ((context == 'domain') &&
5256: ((document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'course') ||
5257: (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community'))) {
1.364 raeburn 5258: document.getElementById('showcolstatus').checked = false;
5259: document.getElementById('showcolstatus').disabled = 'disabled';
5260: document.getElementById('showcolstart').checked = false;
5261: document.getElementById('showcolend').checked = false;
1.374 raeburn 5262: } else {
5263: if (document.studentform.Status.options[document.studentform.Status.selectedIndex].value == 'Any') {
5264: document.getElementById('showcolstatus').checked = true;
5265: document.getElementById('showcolstatus').disabled = '';
5266: document.getElementById('showcolstart').checked = true;
5267: document.getElementById('showcolend').checked = true;
5268: } else {
5269: document.getElementById('showcolstatus').checked = false;
5270: document.getElementById('showcolstatus').disabled = 'disabled';
5271: document.getElementById('showcolstart').checked = false;
5272: document.getElementById('showcolend').checked = false;
5273: }
1.364 raeburn 5274: }
5275: }
5276: if (caller == 'output') {
5277: if (photos == 1) {
5278: if (document.getElementById('showcolphoto')) {
5279: var photoitem = document.getElementById('showcolphoto');
5280: if (document.studentform.output.options[document.studentform.output.selectedIndex].value == 'html') {
5281: photoitem.checked = true;
5282: photoitem.disabled = '';
5283: } else {
5284: photoitem.checked = false;
5285: photoitem.disabled = 'disabled';
5286: }
5287: }
5288: }
5289: }
5290: if (caller == 'showrole') {
1.371 raeburn 5291: if ((document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'Any') ||
5292: (document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'cr')) {
1.364 raeburn 5293: document.getElementById('showcolrole').checked = true;
5294: document.getElementById('showcolrole').disabled = '';
5295: } else {
5296: document.getElementById('showcolrole').checked = false;
5297: document.getElementById('showcolrole').disabled = 'disabled';
5298: }
1.374 raeburn 5299: if (context == 'domain') {
1.382 raeburn 5300: var quotausageshow = 0;
1.374 raeburn 5301: if ((document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'course') ||
5302: (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community')) {
5303: document.getElementById('showcolstatus').checked = false;
5304: document.getElementById('showcolstatus').disabled = 'disabled';
5305: document.getElementById('showcolstart').checked = false;
5306: document.getElementById('showcolend').checked = false;
5307: } else {
5308: if (document.studentform.Status.options[document.studentform.Status.selectedIndex].value == 'Any') {
5309: document.getElementById('showcolstatus').checked = true;
5310: document.getElementById('showcolstatus').disabled = '';
5311: document.getElementById('showcolstart').checked = true;
5312: document.getElementById('showcolend').checked = true;
5313: }
5314: }
5315: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'domain') {
5316: document.getElementById('showcolextent').disabled = 'disabled';
5317: document.getElementById('showcolextent').checked = 'false';
5318: document.getElementById('showextent').style.display='none';
5319: document.getElementById('showcoltextextent').innerHTML = '';
1.382 raeburn 5320: if ((document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'au') ||
5321: (document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'Any')) {
5322: if (document.getElementById('showcolauthorusage')) {
5323: document.getElementById('showcolauthorusage').disabled = '';
5324: }
5325: if (document.getElementById('showcolauthorquota')) {
5326: document.getElementById('showcolauthorquota').disabled = '';
5327: }
5328: quotausageshow = 1;
5329: }
1.374 raeburn 5330: } else {
5331: document.getElementById('showextent').style.display='block';
5332: document.getElementById('showextent').style.textAlign='left';
5333: document.getElementById('showextent').style.textFace='normal';
5334: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'author') {
5335: document.getElementById('showcolextent').disabled = '';
5336: document.getElementById('showcolextent').checked = 'true';
5337: document.getElementById('showcoltextextent').innerHTML="$lt{'author'}";
5338: } else {
5339: document.getElementById('showcolextent').disabled = '';
5340: document.getElementById('showcolextent').checked = 'true';
5341: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community') {
5342: document.getElementById('showcoltextextent').innerHTML="$lt{'community'}";
5343: } else {
5344: document.getElementById('showcoltextextent').innerHTML="$lt{'course'}";
5345: }
5346: }
5347: }
1.382 raeburn 5348: if (quotausageshow == 0) {
5349: if (document.getElementById('showcolauthorusage')) {
5350: document.getElementById('showcolauthorusage').checked = false;
5351: document.getElementById('showcolauthorusage').disabled = 'disabled';
5352: }
5353: if (document.getElementById('showcolauthorquota')) {
5354: document.getElementById('showcolauthorquota').checked = false;
5355: document.getElementById('showcolauthorquota').disabled = 'disabled';
5356: }
5357: }
1.374 raeburn 5358: }
1.364 raeburn 5359: }
5360: return;
5361: }
5362:
1.202 raeburn 5363: END
5364: return $output;
5365:
5366: }
5367:
1.190 raeburn 5368: ###############################################################
5369: ###############################################################
5370: # Menu Phase One
5371: sub print_main_menu {
1.318 raeburn 5372: my ($permission,$context,$crstype) = @_;
5373: my $linkcontext = $context;
5374: my $stuterm = lc(&Apache::lonnet::plaintext('st',$crstype));
5375: if (($context eq 'course') && ($crstype eq 'Community')) {
5376: $linkcontext = lc($crstype);
5377: $stuterm = 'Members';
5378: }
1.208 raeburn 5379: my %links = (
1.298 droeschl 5380: domain => {
5381: upload => 'Upload a File of Users',
5382: singleuser => 'Add/Modify a User',
5383: listusers => 'Manage Users',
5384: },
5385: author => {
5386: upload => 'Upload a File of Co-authors',
5387: singleuser => 'Add/Modify a Co-author',
5388: listusers => 'Manage Co-authors',
5389: },
5390: course => {
5391: upload => 'Upload a File of Course Users',
5392: singleuser => 'Add/Modify a Course User',
1.354 www 5393: listusers => 'List and Modify Multiple Course Users',
1.298 droeschl 5394: },
1.318 raeburn 5395: community => {
5396: upload => 'Upload a File of Community Users',
5397: singleuser => 'Add/Modify a Community User',
1.354 www 5398: listusers => 'List and Modify Multiple Community Users',
1.318 raeburn 5399: },
5400: );
5401: my %linktitles = (
5402: domain => {
5403: singleuser => 'Add a user to the domain, and/or a course or community in the domain.',
5404: listusers => 'Show and manage users in this domain.',
5405: },
5406: author => {
5407: singleuser => 'Add a user with a co- or assistant author role.',
5408: listusers => 'Show and manage co- or assistant authors.',
5409: },
5410: course => {
5411: singleuser => 'Add a user with a certain role to this course.',
5412: listusers => 'Show and manage users in this course.',
5413: },
5414: community => {
5415: singleuser => 'Add a user with a certain role to this community.',
5416: listusers => 'Show and manage users in this community.',
5417: },
1.298 droeschl 5418: );
1.418 raeburn 5419: if ($linkcontext eq 'domain') {
5420: unless ($permission->{'cusr'}) {
1.430 raeburn 5421: $links{'domain'}{'singleuser'} = 'View a User';
1.418 raeburn 5422: $linktitles{'domain'}{'singleuser'} = 'View information about a user in the domain';
5423: }
5424: } elsif ($linkcontext eq 'course') {
5425: unless ($permission->{'cusr'}) {
5426: $links{'course'}{'singleuser'} = 'View a Course User';
5427: $linktitles{'course'}{'singleuser'} = 'View information about a user in this course';
5428: $links{'course'}{'listusers'} = 'List Course Users';
5429: $linktitles{'course'}{'listusers'} = 'Show information about users in this course';
5430: }
5431: } elsif ($linkcontext eq 'community') {
5432: unless ($permission->{'cusr'}) {
5433: $links{'community'}{'singleuser'} = 'View a Community User';
5434: $linktitles{'community'}{'singleuser'} = 'View information about a user in this community';
5435: $links{'community'}{'listusers'} = 'List Community Users';
5436: $linktitles{'community'}{'listusers'} = 'Show information about users in this community';
5437: }
5438: }
1.298 droeschl 5439: my @menu = ( {categorytitle => 'Single Users',
5440: items =>
5441: [
5442: {
1.318 raeburn 5443: linktext => $links{$linkcontext}{'singleuser'},
1.298 droeschl 5444: icon => 'edit-redo.png',
5445: #help => 'Course_Change_Privileges',
5446: url => '/adm/createuser?action=singleuser',
1.418 raeburn 5447: permission => ($permission->{'view'} || $permission->{'cusr'}),
1.318 raeburn 5448: linktitle => $linktitles{$linkcontext}{'singleuser'},
1.298 droeschl 5449: },
5450: ]},
5451:
5452: {categorytitle => 'Multiple Users',
5453: items =>
5454: [
5455: {
1.318 raeburn 5456: linktext => $links{$linkcontext}{'upload'},
1.340 wenzelju 5457: icon => 'uplusr.png',
1.298 droeschl 5458: #help => 'Course_Create_Class_List',
5459: url => '/adm/createuser?action=upload',
5460: permission => $permission->{'cusr'},
5461: linktitle => 'Upload a CSV or a text file containing users.',
5462: },
5463: {
1.318 raeburn 5464: linktext => $links{$linkcontext}{'listusers'},
1.340 wenzelju 5465: icon => 'mngcu.png',
1.298 droeschl 5466: #help => 'Course_View_Class_List',
5467: url => '/adm/createuser?action=listusers',
5468: permission => ($permission->{'view'} || $permission->{'cusr'}),
1.318 raeburn 5469: linktitle => $linktitles{$linkcontext}{'listusers'},
1.298 droeschl 5470: },
5471:
5472: ]},
5473:
5474: {categorytitle => 'Administration',
5475: items => [ ]},
5476: );
1.415 raeburn 5477:
1.265 mielkec 5478: if ($context eq 'domain'){
1.416 raeburn 5479: push(@{ $menu[0]->{items} }, # Single Users
5480: {
5481: linktext => 'User Access Log',
1.417 raeburn 5482: icon => 'document-properties.png',
1.425 raeburn 5483: #help => 'Domain_User_Access_Logs',
1.416 raeburn 5484: url => '/adm/createuser?action=accesslogs',
5485: permission => $permission->{'activity'},
5486: linktitle => 'View user access log.',
5487: }
5488: );
1.298 droeschl 5489:
5490: push(@{ $menu[2]->{items} }, #Category: Administration
5491: {
5492: linktext => 'Custom Roles',
5493: icon => 'emblem-photos.png',
5494: #help => 'Course_Editing_Custom_Roles',
5495: url => '/adm/createuser?action=custom',
5496: permission => $permission->{'custom'},
5497: linktitle => 'Configure a custom role.',
5498: },
1.362 raeburn 5499: {
5500: linktext => 'Authoring Space Requests',
5501: icon => 'selfenrl-queue.png',
5502: #help => 'Domain_Role_Approvals',
5503: url => '/adm/createuser?action=processauthorreq',
5504: permission => $permission->{'cusr'},
5505: linktitle => 'Approve or reject author role requests',
5506: },
1.363 raeburn 5507: {
1.391 raeburn 5508: linktext => 'LON-CAPA Account Requests',
5509: icon => 'list-add.png',
5510: #help => 'Domain_Username_Approvals',
5511: url => '/adm/createuser?action=processusernamereq',
5512: permission => $permission->{'cusr'},
5513: linktitle => 'Approve or reject LON-CAPA account requests',
5514: },
5515: {
1.363 raeburn 5516: linktext => 'Change Log',
5517: icon => 'document-properties.png',
5518: #help => 'Course_User_Logs',
5519: url => '/adm/createuser?action=changelogs',
1.418 raeburn 5520: permission => ($permission->{'cusr'} || $permission->{'view'}),
1.363 raeburn 5521: linktitle => 'View change log.',
5522: },
1.298 droeschl 5523: );
5524:
1.265 mielkec 5525: }elsif ($context eq 'course'){
1.298 droeschl 5526: my ($cnum,$cdom) = &Apache::lonuserutils::get_course_identity();
1.318 raeburn 5527:
5528: my %linktext = (
5529: 'Course' => {
5530: single => 'Add/Modify a Student',
5531: drop => 'Drop Students',
5532: groups => 'Course Groups',
5533: },
5534: 'Community' => {
5535: single => 'Add/Modify a Member',
5536: drop => 'Drop Members',
5537: groups => 'Community Groups',
5538: },
5539: );
1.411 raeburn 5540: $linktext{'Placement'} = $linktext{'Course'};
1.318 raeburn 5541:
5542: my %linktitle = (
5543: 'Course' => {
5544: single => 'Add a user with the role of student to this course',
5545: drop => 'Remove a student from this course.',
5546: groups => 'Manage course groups',
5547: },
5548: 'Community' => {
5549: single => 'Add a user with the role of member to this community',
5550: drop => 'Remove a member from this community.',
5551: groups => 'Manage community groups',
5552: },
5553: );
5554:
1.411 raeburn 5555: $linktitle{'Placement'} = $linktitle{'Course'};
5556:
1.298 droeschl 5557: push(@{ $menu[0]->{items} }, #Category: Single Users
5558: {
1.318 raeburn 5559: linktext => $linktext{$crstype}{'single'},
1.298 droeschl 5560: #help => 'Course_Add_Student',
5561: icon => 'list-add.png',
5562: url => '/adm/createuser?action=singlestudent',
5563: permission => $permission->{'cusr'},
1.318 raeburn 5564: linktitle => $linktitle{$crstype}{'single'},
1.298 droeschl 5565: },
5566: );
5567:
5568: push(@{ $menu[1]->{items} }, #Category: Multiple Users
5569: {
1.318 raeburn 5570: linktext => $linktext{$crstype}{'drop'},
1.298 droeschl 5571: icon => 'edit-undo.png',
5572: #help => 'Course_Drop_Student',
5573: url => '/adm/createuser?action=drop',
5574: permission => $permission->{'cusr'},
1.318 raeburn 5575: linktitle => $linktitle{$crstype}{'drop'},
1.298 droeschl 5576: },
5577: );
5578: push(@{ $menu[2]->{items} }, #Category: Administration
1.428 raeburn 5579: {
5580: linktext => 'Helpdesk Access',
5581: icon => 'helpdesk-access.png',
5582: #help => 'Course_Helpdesk_Access',
5583: url => '/adm/createuser?action=helpdesk',
5584: permission => ($permission->{'owner'} || $permission->{'co-owner'}),
5585: linktitle => 'Helpdesk access options',
5586: },
5587: {
1.298 droeschl 5588: linktext => 'Custom Roles',
5589: icon => 'emblem-photos.png',
5590: #help => 'Course_Editing_Custom_Roles',
5591: url => '/adm/createuser?action=custom',
5592: permission => $permission->{'custom'},
5593: linktitle => 'Configure a custom role.',
5594: },
5595: {
1.318 raeburn 5596: linktext => $linktext{$crstype}{'groups'},
1.333 wenzelju 5597: icon => 'grps.png',
1.298 droeschl 5598: #help => 'Course_Manage_Group',
5599: url => '/adm/coursegroups?refpage=cusr',
5600: permission => $permission->{'grp_manage'},
1.318 raeburn 5601: linktitle => $linktitle{$crstype}{'groups'},
1.298 droeschl 5602: },
5603: {
1.328 wenzelju 5604: linktext => 'Change Log',
1.298 droeschl 5605: icon => 'document-properties.png',
5606: #help => 'Course_User_Logs',
5607: url => '/adm/createuser?action=changelogs',
1.418 raeburn 5608: permission => ($permission->{'view'} || $permission->{'cusr'}),
1.298 droeschl 5609: linktitle => 'View change log.',
5610: },
5611: );
1.277 raeburn 5612: if ($env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_approval'}) {
1.298 droeschl 5613: push(@{ $menu[2]->{items} },
1.398 raeburn 5614: {
1.298 droeschl 5615: linktext => 'Enrollment Requests',
5616: icon => 'selfenrl-queue.png',
5617: #help => 'Course_Approve_Selfenroll',
5618: url => '/adm/createuser?action=selfenrollqueue',
1.398 raeburn 5619: permission => $permission->{'selfenrolladmin'},
1.298 droeschl 5620: linktitle =>'Approve or reject enrollment requests.',
5621: },
5622: );
1.277 raeburn 5623: }
1.298 droeschl 5624:
1.265 mielkec 5625: if (!exists($permission->{'cusr_section'})){
1.320 raeburn 5626: if ($crstype ne 'Community') {
5627: push(@{ $menu[2]->{items} },
5628: {
5629: linktext => 'Automated Enrollment',
5630: icon => 'roles.png',
5631: #help => 'Course_Automated_Enrollment',
5632: permission => (&Apache::lonnet::auto_run($cnum,$cdom)
1.418 raeburn 5633: && (($permission->{'cusr'}) ||
5634: ($permission->{'view'}))),
1.320 raeburn 5635: url => '/adm/populate',
5636: linktitle => 'Automated enrollment manager.',
5637: }
5638: );
5639: }
5640: push(@{ $menu[2]->{items} },
1.298 droeschl 5641: {
5642: linktext => 'User Self-Enrollment',
1.342 wenzelju 5643: icon => 'self_enroll.png',
1.298 droeschl 5644: #help => 'Course_Self_Enrollment',
5645: url => '/adm/createuser?action=selfenroll',
1.398 raeburn 5646: permission => $permission->{'selfenrolladmin'},
1.317 bisitz 5647: linktitle => 'Configure user self-enrollment.',
1.298 droeschl 5648: },
5649: );
5650: }
1.363 raeburn 5651: } elsif ($context eq 'author') {
1.370 raeburn 5652: push(@{ $menu[2]->{items} }, #Category: Administration
1.363 raeburn 5653: {
5654: linktext => 'Change Log',
5655: icon => 'document-properties.png',
5656: #help => 'Course_User_Logs',
5657: url => '/adm/createuser?action=changelogs',
5658: permission => $permission->{'cusr'},
5659: linktitle => 'View change log.',
5660: },
1.370 raeburn 5661: );
1.363 raeburn 5662: }
5663: return Apache::lonhtmlcommon::generate_menu(@menu);
1.250 raeburn 5664: # { text => 'View Log-in History',
5665: # help => 'Course_User_Logins',
5666: # action => 'logins',
5667: # permission => $permission->{'cusr'},
5668: # });
1.190 raeburn 5669: }
5670:
1.189 albertel 5671: sub restore_prev_selections {
5672: my %saveable_parameters = ('srchby' => 'scalar',
5673: 'srchin' => 'scalar',
5674: 'srchtype' => 'scalar',
5675: );
5676: &Apache::loncommon::store_settings('user','user_picker',
5677: \%saveable_parameters);
5678: &Apache::loncommon::restore_settings('user','user_picker',
5679: \%saveable_parameters);
5680: }
5681:
1.237 raeburn 5682: sub print_selfenroll_menu {
1.418 raeburn 5683: my ($r,$context,$cid,$cdom,$cnum,$currsettings,$additional,$readonly) = @_;
1.322 raeburn 5684: my $crstype = &Apache::loncommon::course_type();
1.398 raeburn 5685: my $formname = 'selfenroll';
1.237 raeburn 5686: my $nolink = 1;
1.398 raeburn 5687: my ($row,$lt) = &Apache::lonuserutils::get_selfenroll_titles();
1.237 raeburn 5688: my $groupslist = &Apache::lonuserutils::get_groupslist();
5689: my $setsec_js =
5690: &Apache::lonuserutils::setsections_javascript($formname,$groupslist);
1.249 raeburn 5691: my %alerts = &Apache::lonlocal::texthash(
5692: acto => 'Activation of self-enrollment was selected for the following domain(s)',
5693: butn => 'but no user types have been checked.',
5694: wilf => "Please uncheck 'activate' or check at least one type.",
5695: );
1.418 raeburn 5696: my $disabled;
5697: if ($readonly) {
5698: $disabled = ' disabled="disabled"';
5699: }
1.405 damieng 5700: &js_escape(\%alerts);
1.249 raeburn 5701: my $selfenroll_js = <<"ENDSCRIPT";
5702: function update_types(caller,num) {
5703: var delidx = getIndexByName('selfenroll_delete');
5704: var actidx = getIndexByName('selfenroll_activate');
5705: if (caller == 'selfenroll_all') {
5706: var selall;
5707: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
5708: if (document.$formname.selfenroll_all[i].checked) {
5709: selall = document.$formname.selfenroll_all[i].value;
5710: }
5711: }
5712: if (selall == 1) {
5713: if (delidx != -1) {
5714: if (document.$formname.selfenroll_delete.length) {
5715: for (var j=0; j<document.$formname.selfenroll_delete.length; j++) {
5716: document.$formname.selfenroll_delete[j].checked = true;
5717: }
5718: } else {
5719: document.$formname.elements[delidx].checked = true;
5720: }
5721: }
5722: if (actidx != -1) {
5723: if (document.$formname.selfenroll_activate.length) {
5724: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
5725: document.$formname.selfenroll_activate[j].checked = false;
5726: }
5727: } else {
5728: document.$formname.elements[actidx].checked = false;
5729: }
5730: }
5731: document.$formname.selfenroll_newdom.selectedIndex = 0;
5732: }
5733: }
5734: if (caller == 'selfenroll_activate') {
5735: if (document.$formname.selfenroll_activate.length) {
5736: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
5737: if (document.$formname.selfenroll_activate[j].value == num) {
5738: if (document.$formname.selfenroll_activate[j].checked) {
5739: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
5740: if (document.$formname.selfenroll_all[i].value == '1') {
5741: document.$formname.selfenroll_all[i].checked = false;
5742: }
5743: if (document.$formname.selfenroll_all[i].value == '0') {
5744: document.$formname.selfenroll_all[i].checked = true;
5745: }
5746: }
5747: }
5748: }
5749: }
5750: } else {
5751: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
5752: if (document.$formname.selfenroll_all[i].value == '1') {
5753: document.$formname.selfenroll_all[i].checked = false;
5754: }
5755: if (document.$formname.selfenroll_all[i].value == '0') {
5756: document.$formname.selfenroll_all[i].checked = true;
5757: }
5758: }
5759: }
5760: }
5761: if (caller == 'selfenroll_delete') {
5762: if (document.$formname.selfenroll_delete.length) {
5763: for (var j=0; j<document.$formname.selfenroll_delete.length; j++) {
5764: if (document.$formname.selfenroll_delete[j].value == num) {
5765: if (document.$formname.selfenroll_delete[j].checked) {
5766: var delindex = getIndexByName('selfenroll_types_'+num);
5767: if (delindex != -1) {
5768: if (document.$formname.elements[delindex].length) {
5769: for (var k=0; k<document.$formname.elements[delindex].length; k++) {
5770: document.$formname.elements[delindex][k].checked = false;
5771: }
5772: } else {
5773: document.$formname.elements[delindex].checked = false;
5774: }
5775: }
5776: }
5777: }
5778: }
5779: } else {
5780: if (document.$formname.selfenroll_delete.checked) {
5781: var delindex = getIndexByName('selfenroll_types_'+num);
5782: if (delindex != -1) {
5783: if (document.$formname.elements[delindex].length) {
5784: for (var k=0; k<document.$formname.elements[delindex].length; k++) {
5785: document.$formname.elements[delindex][k].checked = false;
5786: }
5787: } else {
5788: document.$formname.elements[delindex].checked = false;
5789: }
5790: }
5791: }
5792: }
5793: }
5794: return;
5795: }
5796:
5797: function validate_types(form) {
5798: var needaction = new Array();
5799: var countfail = 0;
5800: var actidx = getIndexByName('selfenroll_activate');
5801: if (actidx != -1) {
5802: if (document.$formname.selfenroll_activate.length) {
5803: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
5804: var num = document.$formname.selfenroll_activate[j].value;
5805: if (document.$formname.selfenroll_activate[j].checked) {
5806: countfail = check_types(num,countfail,needaction)
5807: }
5808: }
5809: } else {
5810: if (document.$formname.selfenroll_activate.checked) {
1.398 raeburn 5811: var num = document.$formname.selfenroll_activate.value;
1.249 raeburn 5812: countfail = check_types(num,countfail,needaction)
5813: }
5814: }
5815: }
5816: if (countfail > 0) {
5817: var msg = "$alerts{'acto'}\\n";
5818: var loopend = needaction.length -1;
5819: if (loopend > 0) {
5820: for (var m=0; m<loopend; m++) {
5821: msg += needaction[m]+", ";
5822: }
5823: }
5824: msg += needaction[loopend]+"\\n$alerts{'butn'}\\n$alerts{'wilf'}";
5825: alert(msg);
5826: return;
5827: }
5828: setSections(form);
5829: }
5830:
5831: function check_types(num,countfail,needaction) {
5832: var typeidx = getIndexByName('selfenroll_types_'+num);
5833: var count = 0;
5834: if (typeidx != -1) {
5835: if (document.$formname.elements[typeidx].length) {
5836: for (var k=0; k<document.$formname.elements[typeidx].length; k++) {
5837: if (document.$formname.elements[typeidx][k].checked) {
5838: count ++;
5839: }
5840: }
5841: } else {
5842: if (document.$formname.elements[typeidx].checked) {
5843: count ++;
5844: }
5845: }
5846: if (count == 0) {
5847: var domidx = getIndexByName('selfenroll_dom_'+num);
5848: if (domidx != -1) {
5849: var domname = document.$formname.elements[domidx].value;
5850: needaction[countfail] = domname;
5851: countfail ++;
5852: }
5853: }
5854: }
5855: return countfail;
5856: }
5857:
1.398 raeburn 5858: function toggleNotify() {
5859: var selfenrollApproval = 0;
5860: if (document.$formname.selfenroll_approval.length) {
5861: for (var i=0; i<document.$formname.selfenroll_approval.length; i++) {
5862: if (document.$formname.selfenroll_approval[i].checked) {
5863: selfenrollApproval = document.$formname.selfenroll_approval[i].value;
5864: break;
5865: }
5866: }
5867: }
5868: if (document.getElementById('notified')) {
5869: if (selfenrollApproval == 0) {
5870: document.getElementById('notified').style.display='none';
5871: } else {
5872: document.getElementById('notified').style.display='block';
5873: }
5874: }
5875: return;
5876: }
5877:
1.249 raeburn 5878: function getIndexByName(item) {
5879: for (var i=0;i<document.$formname.elements.length;i++) {
5880: if (document.$formname.elements[i].name == item) {
5881: return i;
5882: }
5883: }
5884: return -1;
5885: }
5886: ENDSCRIPT
1.256 raeburn 5887:
1.237 raeburn 5888: my $output = '<script type="text/javascript">'."\n".
1.301 bisitz 5889: '// <![CDATA['."\n".
1.249 raeburn 5890: $setsec_js."\n".$selfenroll_js."\n".
1.301 bisitz 5891: '// ]]>'."\n".
1.237 raeburn 5892: '</script>'."\n".
1.256 raeburn 5893: '<h3>'.$lt->{'selfenroll'}.'</h3>'."\n";
1.400 raeburn 5894:
5895: my $visactions = &cat_visibility();
5896: my ($cathash,%cattype);
5897: my %domconfig = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom);
5898: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
5899: $cathash = $domconfig{'coursecategories'}{'cats'};
5900: $cattype{'auth'} = $domconfig{'coursecategories'}{'auth'};
5901: $cattype{'unauth'} = $domconfig{'coursecategories'}{'unauth'};
1.406 raeburn 5902: if ($cattype{'auth'} eq '') {
5903: $cattype{'auth'} = 'std';
5904: }
5905: if ($cattype{'unauth'} eq '') {
5906: $cattype{'unauth'} = 'std';
5907: }
1.400 raeburn 5908: } else {
5909: $cathash = {};
5910: $cattype{'auth'} = 'std';
5911: $cattype{'unauth'} = 'std';
5912: }
5913: if (($cattype{'auth'} eq 'none') && ($cattype{'unauth'} eq 'none')) {
5914: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
5915: '<br />'.
5916: '<br />'.$visactions->{'take'}.'<ul>'.
5917: '<li>'.$visactions->{'dc_chgconf'}.'</li>'.
5918: '</ul>');
5919: } elsif (($cattype{'auth'} !~ /^(std|domonly)$/) && ($cattype{'unauth'} !~ /^(std|domonly)$/)) {
5920: if ($currsettings->{'uniquecode'}) {
5921: $r->print('<span class="LC_info">'.$visactions->{'vis'}.'</span>');
5922: } else {
5923: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
5924: '<br />'.
5925: '<br />'.$visactions->{'take'}.'<ul>'.
5926: '<li>'.$visactions->{'dc_setcode'}.'</li>'.
5927: '</ul><br />');
5928: }
5929: } else {
5930: my ($visible,$cansetvis,$vismsgs) = &visible_in_stdcat($cdom,$cnum,\%domconfig);
5931: if (ref($visactions) eq 'HASH') {
5932: if ($visible) {
5933: $output .= '<p class="LC_info">'.$visactions->{'vis'}.'</p>';
5934: } else {
5935: $output .= '<p class="LC_warning">'.$visactions->{'miss'}.'</p>'
5936: .$visactions->{'yous'}.
5937: '<p>'.$visactions->{'gen'}.'<br />'.$visactions->{'coca'};
5938: if (ref($vismsgs) eq 'ARRAY') {
5939: $output .= '<br />'.$visactions->{'make'}.'<ul>';
5940: foreach my $item (@{$vismsgs}) {
5941: $output .= '<li>'.$visactions->{$item}.'</li>';
5942: }
5943: $output .= '</ul>';
1.256 raeburn 5944: }
1.400 raeburn 5945: $output .= '</p>';
1.256 raeburn 5946: }
5947: }
5948: }
1.398 raeburn 5949: my $actionhref = '/adm/createuser';
5950: if ($context eq 'domain') {
5951: $actionhref = '/adm/modifycourse';
5952: }
1.400 raeburn 5953:
5954: my %noedit;
5955: unless ($context eq 'domain') {
5956: %noedit = &get_noedit_fields($cdom,$cnum,$crstype,$row);
5957: }
1.398 raeburn 5958: $output .= '<form name="'.$formname.'" method="post" action="'.$actionhref.'">'."\n".
1.256 raeburn 5959: &Apache::lonhtmlcommon::start_pick_box();
1.237 raeburn 5960: if (ref($row) eq 'ARRAY') {
5961: foreach my $item (@{$row}) {
5962: my $title = $item;
5963: if (ref($lt) eq 'HASH') {
5964: $title = $lt->{$item};
5965: }
1.297 bisitz 5966: $output .= &Apache::lonhtmlcommon::row_title($title);
1.237 raeburn 5967: if ($item eq 'types') {
1.398 raeburn 5968: my $curr_types;
5969: if (ref($currsettings) eq 'HASH') {
5970: $curr_types = $currsettings->{'selfenroll_types'};
5971: }
1.400 raeburn 5972: if ($noedit{$item}) {
5973: if ($curr_types eq '*') {
5974: $output .= &mt('Any user in any domain');
5975: } else {
5976: my @entries = split(/;/,$curr_types);
5977: if (@entries > 0) {
5978: $output .= '<ul>';
5979: foreach my $entry (@entries) {
5980: my ($currdom,$typestr) = split(/:/,$entry);
5981: next if ($typestr eq '');
5982: my $domdesc = &Apache::lonnet::domain($currdom);
5983: my @currinsttypes = split(',',$typestr);
5984: my ($othertitle,$usertypes,$types) =
5985: &Apache::loncommon::sorted_inst_types($currdom);
5986: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
5987: $usertypes->{'any'} = &mt('any user');
5988: if (keys(%{$usertypes}) > 0) {
5989: $usertypes->{'other'} = &mt('other users');
5990: }
5991: my @longinsttypes = map { $usertypes->{$_}; } @currinsttypes;
5992: $output .= '<li>'.$domdesc.':'.join(', ',@longinsttypes).'</li>';
5993: }
5994: }
5995: $output .= '</ul>';
5996: } else {
5997: $output .= &mt('None');
5998: }
5999: }
6000: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6001: next;
6002: }
1.241 raeburn 6003: my $showdomdesc = 1;
6004: my $includeempty = 1;
6005: my $num = 0;
6006: $output .= &Apache::loncommon::start_data_table().
6007: &Apache::loncommon::start_data_table_row()
6008: .'<td colspan="2"><span class="LC_nobreak"><label>'
6009: .&mt('Any user in any domain:')
6010: .' <input type="radio" name="selfenroll_all" value="1" ';
6011: if ($curr_types eq '*') {
6012: $output .= ' checked="checked" ';
6013: }
1.249 raeburn 6014: $output .= 'onchange="javascript:update_types('.
1.418 raeburn 6015: "'selfenroll_all'".');"'.$disabled.' />'.&mt('Yes').'</label>'.
1.249 raeburn 6016: ' <input type="radio" name="selfenroll_all" value="0" ';
1.241 raeburn 6017: if ($curr_types ne '*') {
6018: $output .= ' checked="checked" ';
6019: }
1.249 raeburn 6020: $output .= ' onchange="javascript:update_types('.
1.418 raeburn 6021: "'selfenroll_all'".');"'.$disabled.' />'.&mt('No').'</label></td>'.
1.249 raeburn 6022: &Apache::loncommon::end_data_table_row().
6023: &Apache::loncommon::end_data_table().
6024: &mt('Or').'<br />'.
6025: &Apache::loncommon::start_data_table();
1.241 raeburn 6026: my %currdoms;
1.249 raeburn 6027: if ($curr_types eq '') {
1.241 raeburn 6028: $output .= &new_selfenroll_dom_row($cdom,'0');
6029: } elsif ($curr_types ne '*') {
6030: my @entries = split(/;/,$curr_types);
6031: if (@entries > 0) {
6032: foreach my $entry (@entries) {
6033: my ($currdom,$typestr) = split(/:/,$entry);
6034: $currdoms{$currdom} = 1;
6035: my $domdesc = &Apache::lonnet::domain($currdom);
1.249 raeburn 6036: my @currinsttypes = split(',',$typestr);
1.241 raeburn 6037: $output .= &Apache::loncommon::start_data_table_row()
6038: .'<td valign="top"><span class="LC_nobreak">'.&mt('Domain:').'<b>'
6039: .' '.$domdesc.' ('.$currdom.')'
6040: .'</b><input type="hidden" name="selfenroll_dom_'.$num
6041: .'" value="'.$currdom.'" /></span><br />'
6042: .'<span class="LC_nobreak"><label><input type="checkbox" '
1.418 raeburn 6043: .'name="selfenroll_delete" value="'.$num.'" onchange="javascript:update_types('."'selfenroll_delete','$num'".');"'.$disabled.' />'
1.241 raeburn 6044: .&mt('Delete').'</label></span></td>';
1.249 raeburn 6045: $output .= '<td valign="top"> '.&mt('User types:').'<br />'
1.418 raeburn 6046: .&selfenroll_inst_types($num,$currdom,\@currinsttypes,$readonly).'</td>'
1.241 raeburn 6047: .&Apache::loncommon::end_data_table_row();
6048: $num ++;
6049: }
6050: }
6051: }
1.249 raeburn 6052: my $add_domtitle = &mt('Users in additional domain:');
1.241 raeburn 6053: if ($curr_types eq '*') {
1.249 raeburn 6054: $add_domtitle = &mt('Users in specific domain:');
1.241 raeburn 6055: } elsif ($curr_types eq '') {
1.249 raeburn 6056: $add_domtitle = &mt('Users in other domain:');
1.241 raeburn 6057: }
6058: $output .= &Apache::loncommon::start_data_table_row()
6059: .'<td colspan="2"><span class="LC_nobreak">'.$add_domtitle.'</span><br />'
6060: .&Apache::loncommon::select_dom_form('','selfenroll_newdom',
1.418 raeburn 6061: $includeempty,$showdomdesc,'','','',$readonly)
1.241 raeburn 6062: .'<input type="hidden" name="selfenroll_types_total" value="'.$num.'" />'
6063: .'</td>'.&Apache::loncommon::end_data_table_row()
6064: .&Apache::loncommon::end_data_table();
1.237 raeburn 6065: } elsif ($item eq 'registered') {
6066: my ($regon,$regoff);
1.398 raeburn 6067: my $registered;
6068: if (ref($currsettings) eq 'HASH') {
6069: $registered = $currsettings->{'selfenroll_registered'};
6070: }
1.400 raeburn 6071: if ($noedit{$item}) {
6072: if ($registered) {
6073: $output .= &mt('Must be registered in course');
6074: } else {
6075: $output .= &mt('No requirement');
6076: }
6077: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6078: next;
6079: }
1.398 raeburn 6080: if ($registered) {
1.237 raeburn 6081: $regon = ' checked="checked" ';
1.419 raeburn 6082: $regoff = '';
1.237 raeburn 6083: } else {
1.419 raeburn 6084: $regon = '';
1.237 raeburn 6085: $regoff = ' checked="checked" ';
6086: }
6087: $output .= '<label>'.
1.419 raeburn 6088: '<input type="radio" name="selfenroll_registered" value="1"'.$regon.$disabled.' />'.
1.244 bisitz 6089: &mt('Yes').'</label> <label>'.
1.419 raeburn 6090: '<input type="radio" name="selfenroll_registered" value="0"'.$regoff.$disabled.' />'.
1.244 bisitz 6091: &mt('No').'</label>';
1.237 raeburn 6092: } elsif ($item eq 'enroll_dates') {
1.398 raeburn 6093: my ($starttime,$endtime);
6094: if (ref($currsettings) eq 'HASH') {
6095: $starttime = $currsettings->{'selfenroll_start_date'};
6096: $endtime = $currsettings->{'selfenroll_end_date'};
6097: if ($starttime eq '') {
6098: $starttime = $currsettings->{'default_enrollment_start_date'};
6099: }
6100: if ($endtime eq '') {
6101: $endtime = $currsettings->{'default_enrollment_end_date'};
6102: }
1.237 raeburn 6103: }
1.400 raeburn 6104: if ($noedit{$item}) {
6105: $output .= &mt('From: [_1], to: [_2]',&Apache::lonlocal::locallocaltime($starttime),
6106: &Apache::lonlocal::locallocaltime($endtime));
6107: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6108: next;
6109: }
1.237 raeburn 6110: my $startform =
6111: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_start_date',$starttime,
1.418 raeburn 6112: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
1.237 raeburn 6113: my $endform =
6114: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_end_date',$endtime,
1.418 raeburn 6115: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
1.237 raeburn 6116: $output .= &selfenroll_date_forms($startform,$endform);
6117: } elsif ($item eq 'access_dates') {
1.398 raeburn 6118: my ($starttime,$endtime);
6119: if (ref($currsettings) eq 'HASH') {
6120: $starttime = $currsettings->{'selfenroll_start_access'};
6121: $endtime = $currsettings->{'selfenroll_end_access'};
6122: if ($starttime eq '') {
6123: $starttime = $currsettings->{'default_enrollment_start_date'};
6124: }
6125: if ($endtime eq '') {
6126: $endtime = $currsettings->{'default_enrollment_end_date'};
6127: }
1.237 raeburn 6128: }
1.400 raeburn 6129: if ($noedit{$item}) {
6130: $output .= &mt('From: [_1], to: [_2]',&Apache::lonlocal::locallocaltime($starttime),
6131: &Apache::lonlocal::locallocaltime($endtime));
6132: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6133: next;
6134: }
1.237 raeburn 6135: my $startform =
6136: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_start_access',$starttime,
1.418 raeburn 6137: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
1.237 raeburn 6138: my $endform =
6139: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_end_access',$endtime,
1.418 raeburn 6140: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
1.237 raeburn 6141: $output .= &selfenroll_date_forms($startform,$endform);
6142: } elsif ($item eq 'section') {
1.398 raeburn 6143: my $currsec;
6144: if (ref($currsettings) eq 'HASH') {
6145: $currsec = $currsettings->{'selfenroll_section'};
6146: }
1.237 raeburn 6147: my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum);
6148: my $newsecval;
6149: if ($currsec ne 'none' && $currsec ne '') {
6150: if (!defined($sections_count{$currsec})) {
6151: $newsecval = $currsec;
6152: }
6153: }
1.400 raeburn 6154: if ($noedit{$item}) {
6155: if ($currsec ne '') {
6156: $output .= $currsec;
6157: } else {
6158: $output .= &mt('No specific section');
6159: }
6160: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
6161: next;
6162: }
1.237 raeburn 6163: my $sections_select =
1.418 raeburn 6164: &Apache::lonuserutils::course_sections(\%sections_count,'st',$currsec,$disabled);
1.237 raeburn 6165: $output .= '<table class="LC_createuser">'."\n".
6166: '<tr class="LC_section_row">'."\n".
6167: '<td align="center">'.&mt('Existing sections')."\n".
6168: '<br />'.$sections_select.'</td><td align="center">'.
6169: &mt('New section').'<br />'."\n".
1.418 raeburn 6170: '<input type="text" name="newsec" size="15" value="'.$newsecval.'"'.$disabled.' />'."\n".
1.237 raeburn 6171: '<input type="hidden" name="sections" value="" />'."\n".
6172: '</td></tr></table>'."\n";
1.276 raeburn 6173: } elsif ($item eq 'approval') {
1.398 raeburn 6174: my ($currnotified,$currapproval,%appchecked);
6175: my %selfdescs = &Apache::lonuserutils::selfenroll_default_descs();
1.430 raeburn 6176: if (ref($currsettings) eq 'HASH') {
1.398 raeburn 6177: $currnotified = $currsettings->{'selfenroll_notifylist'};
6178: $currapproval = $currsettings->{'selfenroll_approval'};
6179: }
6180: if ($currapproval !~ /^[012]$/) {
6181: $currapproval = 0;
6182: }
1.400 raeburn 6183: if ($noedit{$item}) {
6184: $output .= $selfdescs{'approval'}{$currapproval}.
6185: '<br />'.&mt('(Set by Domain Coordinator)');
6186: next;
6187: }
1.398 raeburn 6188: $appchecked{$currapproval} = ' checked="checked"';
6189: for my $i (0..2) {
6190: $output .= '<label>'.
6191: '<input type="radio" name="selfenroll_approval" value="'.$i.'"'.
1.418 raeburn 6192: $appchecked{$i}.' onclick="toggleNotify();"'.$disabled.' />'.
6193: $selfdescs{'approval'}{$i}.'</label>'.(' 'x2);
1.276 raeburn 6194: }
6195: my %advhash = &Apache::lonnet::get_course_adv_roles($cid,1);
6196: my (@ccs,%notified);
1.322 raeburn 6197: my $ccrole = 'cc';
6198: if ($crstype eq 'Community') {
6199: $ccrole = 'co';
6200: }
6201: if ($advhash{$ccrole}) {
6202: @ccs = split(/,/,$advhash{$ccrole});
1.276 raeburn 6203: }
6204: if ($currnotified) {
6205: foreach my $current (split(/,/,$currnotified)) {
6206: $notified{$current} = 1;
6207: if (!grep(/^\Q$current\E$/,@ccs)) {
6208: push(@ccs,$current);
6209: }
6210: }
6211: }
6212: if (@ccs) {
1.398 raeburn 6213: my $style;
6214: unless ($currapproval) {
6215: $style = ' style="display: none;"';
6216: }
6217: $output .= '<br /><div id="notified"'.$style.'>'.
6218: &mt('Personnel to be notified when an enrollment request needs approval, or has been approved:').' '.
6219: &Apache::loncommon::start_data_table().
1.276 raeburn 6220: &Apache::loncommon::start_data_table_row();
6221: my $count = 0;
6222: my $numcols = 4;
6223: foreach my $cc (sort(@ccs)) {
6224: my $notifyon;
6225: my ($ccuname,$ccudom) = split(/:/,$cc);
6226: if ($notified{$cc}) {
6227: $notifyon = ' checked="checked" ';
6228: }
6229: if ($count && !$count%$numcols) {
6230: $output .= &Apache::loncommon::end_data_table_row().
6231: &Apache::loncommon::start_data_table_row()
6232: }
6233: $output .= '<td><span class="LC_nobreak"><label>'.
1.418 raeburn 6234: '<input type="checkbox" name="selfenroll_notify"'.$notifyon.' value="'.$cc.'"'.$disabled.' />'.
1.276 raeburn 6235: &Apache::loncommon::plainname($ccuname,$ccudom).
6236: '</label></span></td>';
1.343 raeburn 6237: $count ++;
1.276 raeburn 6238: }
6239: my $rem = $count%$numcols;
6240: if ($rem) {
6241: my $emptycols = $numcols - $rem;
6242: for (my $i=0; $i<$emptycols; $i++) {
6243: $output .= '<td> </td>';
6244: }
6245: }
6246: $output .= &Apache::loncommon::end_data_table_row().
1.398 raeburn 6247: &Apache::loncommon::end_data_table().
6248: '</div>';
1.276 raeburn 6249: }
6250: } elsif ($item eq 'limit') {
1.398 raeburn 6251: my ($crslimit,$selflimit,$nolimit,$currlim,$currcap);
6252: if (ref($currsettings) eq 'HASH') {
6253: $currlim = $currsettings->{'selfenroll_limit'};
6254: $currcap = $currsettings->{'selfenroll_cap'};
6255: }
1.400 raeburn 6256: if ($noedit{$item}) {
6257: if (($currlim eq 'allstudents') || ($currlim eq 'selfenrolled')) {
6258: if ($currlim eq 'allstudents') {
6259: $output .= &mt('Limit by total students');
6260: } elsif ($currlim eq 'selfenrolled') {
6261: $output .= &mt('Limit by total self-enrolled students');
6262: }
6263: $output .= ' '.&mt('Maximum: [_1]',$currcap).
6264: '<br />'.&mt('(Set by Domain Coordinator)');
6265: } else {
6266: $output .= &mt('No limit').'<br />'.&mt('(Set by Domain Coordinator)');
6267: }
6268: next;
6269: }
1.276 raeburn 6270: if ($currlim eq 'allstudents') {
6271: $crslimit = ' checked="checked" ';
6272: $selflimit = ' ';
6273: $nolimit = ' ';
6274: } elsif ($currlim eq 'selfenrolled') {
6275: $crslimit = ' ';
6276: $selflimit = ' checked="checked" ';
6277: $nolimit = ' ';
6278: } else {
6279: $crslimit = ' ';
6280: $selflimit = ' ';
1.398 raeburn 6281: $nolimit = ' checked="checked" ';
1.276 raeburn 6282: }
6283: $output .= '<table><tr><td><label>'.
1.418 raeburn 6284: '<input type="radio" name="selfenroll_limit" value="none"'.$nolimit.$disabled.'/>'.
1.276 raeburn 6285: &mt('No limit').'</label></td><td><label>'.
1.418 raeburn 6286: '<input type="radio" name="selfenroll_limit" value="allstudents"'.$crslimit.$disabled.'/>'.
1.276 raeburn 6287: &mt('Limit by total students').'</label></td><td><label>'.
1.418 raeburn 6288: '<input type="radio" name="selfenroll_limit" value="selfenrolled"'.$selflimit.$disabled.'/>'.
1.276 raeburn 6289: &mt('Limit by total self-enrolled students').
6290: '</td></tr><tr>'.
6291: '<td> </td><td colspan="2"><span class="LC_nobreak">'.
6292: (' 'x3).&mt('Maximum number allowed: ').
1.418 raeburn 6293: '<input type="text" name="selfenroll_cap" size = "5" value="'.$currcap.'"'.$disabled.' /></td></tr></table>';
1.237 raeburn 6294: }
6295: $output .= &Apache::lonhtmlcommon::row_closure(1);
6296: }
6297: }
1.418 raeburn 6298: $output .= &Apache::lonhtmlcommon::end_pick_box().'<br />';
6299: unless ($readonly) {
6300: $output .= '<input type="button" name="selfenrollconf" value="'
6301: .&mt('Save').'" onclick="validate_types(this.form);" />';
6302: }
6303: $output .= '<input type="hidden" name="action" value="selfenroll" />'
6304: .'<input type="hidden" name="state" value="done" />'."\n"
6305: .$additional.'</form>';
1.237 raeburn 6306: $r->print($output);
6307: return;
6308: }
6309:
1.400 raeburn 6310: sub get_noedit_fields {
6311: my ($cdom,$cnum,$crstype,$row) = @_;
6312: my %noedit;
6313: if (ref($row) eq 'ARRAY') {
6314: my %settings = &Apache::lonnet::get('environment',['internal.coursecode','internal.textbook',
6315: 'internal.selfenrollmgrdc',
6316: 'internal.selfenrollmgrcc'],$cdom,$cnum);
6317: my $type = &Apache::lonuserutils::get_extended_type($cdom,$cnum,$crstype,\%settings);
6318: my (%specific_managebydc,%specific_managebycc,%default_managebydc);
6319: map { $specific_managebydc{$_} = 1; } (split(/,/,$settings{'internal.selfenrollmgrdc'}));
6320: map { $specific_managebycc{$_} = 1; } (split(/,/,$settings{'internal.selfenrollmgrcc'}));
6321: my %domdefaults = &Apache::lonnet::get_domain_defaults($cdom);
6322: map { $default_managebydc{$_} = 1; } (split(/,/,$domdefaults{$type.'selfenrolladmdc'}));
6323:
6324: foreach my $item (@{$row}) {
6325: next if ($specific_managebycc{$item});
6326: if (($specific_managebydc{$item}) || ($default_managebydc{$item})) {
6327: $noedit{$item} = 1;
6328: }
6329: }
6330: }
6331: return %noedit;
6332: }
6333:
6334: sub visible_in_stdcat {
6335: my ($cdom,$cnum,$domconf) = @_;
6336: my ($cathash,%settable,@vismsgs,$cansetvis,$visible);
6337: unless (ref($domconf) eq 'HASH') {
6338: return ($visible,$cansetvis,\@vismsgs);
6339: }
6340: if (ref($domconf->{'coursecategories'}) eq 'HASH') {
6341: if ($domconf->{'coursecategories'}{'togglecats'} eq 'crs') {
1.256 raeburn 6342: $settable{'togglecats'} = 1;
6343: }
1.400 raeburn 6344: if ($domconf->{'coursecategories'}{'categorize'} eq 'crs') {
1.256 raeburn 6345: $settable{'categorize'} = 1;
6346: }
1.400 raeburn 6347: $cathash = $domconf->{'coursecategories'}{'cats'};
1.256 raeburn 6348: }
1.260 raeburn 6349: if ($settable{'togglecats'} && $settable{'categorize'}) {
1.256 raeburn 6350: $cansetvis = &mt('You are able to both assign a course category and choose to exclude this course from the catalog.');
6351: } elsif ($settable{'togglecats'}) {
6352: $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 6353: } elsif ($settable{'categorize'}) {
1.256 raeburn 6354: $cansetvis = &mt('You may assign a course category, but only a Domain Coordinator may choose to exclude this course from the catalog.');
6355: } else {
6356: $cansetvis = &mt('Only a Domain Coordinator may assign a course category or choose to exclude this course from the catalog.');
6357: }
6358:
6359: my %currsettings =
6360: &Apache::lonnet::get('environment',['hidefromcat','categories','internal.coursecode'],
6361: $cdom,$cnum);
1.400 raeburn 6362: $visible = 0;
1.256 raeburn 6363: if ($currsettings{'internal.coursecode'} ne '') {
1.400 raeburn 6364: if (ref($domconf->{'coursecategories'}) eq 'HASH') {
6365: $cathash = $domconf->{'coursecategories'}{'cats'};
1.256 raeburn 6366: if (ref($cathash) eq 'HASH') {
6367: if ($cathash->{'instcode::0'} eq '') {
6368: push(@vismsgs,'dc_addinst');
6369: } else {
6370: $visible = 1;
6371: }
6372: } else {
6373: $visible = 1;
6374: }
6375: } else {
6376: $visible = 1;
6377: }
6378: } else {
6379: if (ref($cathash) eq 'HASH') {
6380: if ($cathash->{'instcode::0'} ne '') {
6381: push(@vismsgs,'dc_instcode');
6382: }
6383: } else {
6384: push(@vismsgs,'dc_instcode');
6385: }
6386: }
6387: if ($currsettings{'categories'} ne '') {
6388: my $cathash;
1.400 raeburn 6389: if (ref($domconf->{'coursecategories'}) eq 'HASH') {
6390: $cathash = $domconf->{'coursecategories'}{'cats'};
1.256 raeburn 6391: if (ref($cathash) eq 'HASH') {
6392: if (keys(%{$cathash}) == 0) {
6393: push(@vismsgs,'dc_catalog');
6394: } elsif ((keys(%{$cathash}) == 1) && ($cathash->{'instcode::0'} ne '')) {
6395: push(@vismsgs,'dc_categories');
6396: } else {
6397: my @currcategories = split('&',$currsettings{'categories'});
6398: my $matched = 0;
6399: foreach my $cat (@currcategories) {
6400: if ($cathash->{$cat} ne '') {
6401: $visible = 1;
6402: $matched = 1;
6403: last;
6404: }
6405: }
6406: if (!$matched) {
1.260 raeburn 6407: if ($settable{'categorize'}) {
1.256 raeburn 6408: push(@vismsgs,'chgcat');
6409: } else {
6410: push(@vismsgs,'dc_chgcat');
6411: }
6412: }
6413: }
6414: }
6415: }
6416: } else {
6417: if (ref($cathash) eq 'HASH') {
6418: if ((keys(%{$cathash}) > 1) ||
6419: (keys(%{$cathash}) == 1) && ($cathash->{'instcode::0'} eq '')) {
1.260 raeburn 6420: if ($settable{'categorize'}) {
1.256 raeburn 6421: push(@vismsgs,'addcat');
6422: } else {
6423: push(@vismsgs,'dc_addcat');
6424: }
6425: }
6426: }
6427: }
6428: if ($currsettings{'hidefromcat'} eq 'yes') {
6429: $visible = 0;
6430: if ($settable{'togglecats'}) {
6431: unshift(@vismsgs,'unhide');
6432: } else {
6433: unshift(@vismsgs,'dc_unhide')
6434: }
6435: }
1.400 raeburn 6436: return ($visible,$cansetvis,\@vismsgs);
6437: }
6438:
6439: sub cat_visibility {
6440: my %visactions = &Apache::lonlocal::texthash(
6441: vis => 'This course/community currently appears in the Course/Community Catalog for this domain.',
6442: 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.',
6443: miss => 'This course/community does not currently appear in the Course/Community Catalog for this domain.',
6444: none => 'Display of a course catalog is disabled for this domain.',
6445: yous => 'You should remedy this if you plan to allow self-enrollment, otherwise students will have difficulty finding this course.',
6446: 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.',
6447: make => 'Make any changes to self-enrollment settings below, click "Save", then take action to include the course in the Catalog:',
6448: take => 'Take the following action to ensure the course appears in the Catalog:',
6449: dc_chgconf => 'Ask a domain coordinator to change the Catalog type for this domain.',
6450: dc_setcode => 'Ask a domain coordinator to assign a six character code to the course',
6451: dc_unhide => 'Ask a domain coordinator to change the "Exclude from course catalog" setting.',
6452: dc_addinst => 'Ask a domain coordinator to enable display the catalog of "Official courses (with institutional codes)".',
6453: dc_instcode => 'Ask a domain coordinator to assign an institutional code (if this is an official course).',
6454: dc_catalog => 'Ask a domain coordinator to enable or create at least one course category in the domain.',
6455: dc_categories => 'Ask a domain coordinator to create a hierarchy of categories and sub categories for courses in the domain.',
6456: 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',
6457: dc_addcat => 'Ask a domain coordinator to assign a category to the course.',
6458: );
6459: $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>"');
6460: $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>"');
6461: $visactions{'addcat'} = &mt('Use [_1]Categorize course[_2] to assign a category to the course.','"<a href="/adm/courseprefs?phase=display&actions=courseinfo">','</a>"');
6462: return \%visactions;
1.256 raeburn 6463: }
6464:
1.241 raeburn 6465: sub new_selfenroll_dom_row {
6466: my ($newdom,$num) = @_;
6467: my $domdesc = &Apache::lonnet::domain($newdom);
6468: my $output;
6469: if ($domdesc ne '') {
6470: $output .= &Apache::loncommon::start_data_table_row()
6471: .'<td valign="top"><span class="LC_nobreak">'.&mt('Domain:').' <b>'.$domdesc
6472: .' ('.$newdom.')</b><input type="hidden" name="selfenroll_dom_'.$num
1.249 raeburn 6473: .'" value="'.$newdom.'" /></span><br />'
6474: .'<span class="LC_nobreak"><label><input type="checkbox" '
6475: .'name="selfenroll_activate" value="'.$num.'" '
6476: .'onchange="javascript:update_types('
6477: ."'selfenroll_activate','$num'".');" />'
6478: .&mt('Activate').'</label></span></td>';
1.241 raeburn 6479: my @currinsttypes;
6480: $output .= '<td>'.&mt('User types:').'<br />'
6481: .&selfenroll_inst_types($num,$newdom,\@currinsttypes).'</td>'
6482: .&Apache::loncommon::end_data_table_row();
6483: }
6484: return $output;
6485: }
6486:
6487: sub selfenroll_inst_types {
1.418 raeburn 6488: my ($num,$currdom,$currinsttypes,$readonly) = @_;
1.241 raeburn 6489: my $output;
6490: my $numinrow = 4;
6491: my $count = 0;
6492: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($currdom);
1.247 raeburn 6493: my $othervalue = 'any';
1.418 raeburn 6494: my $disabled;
6495: if ($readonly) {
6496: $disabled = ' disabled="disabled"';
6497: }
1.241 raeburn 6498: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
1.251 raeburn 6499: if (keys(%{$usertypes}) > 0) {
1.247 raeburn 6500: $othervalue = 'other';
6501: }
1.241 raeburn 6502: $output .= '<table><tr>';
6503: foreach my $type (@{$types}) {
6504: if (($count > 0) && ($count%$numinrow == 0)) {
6505: $output .= '</tr><tr>';
6506: }
6507: if (defined($usertypes->{$type})) {
1.257 raeburn 6508: my $esc_type = &escape($type);
1.241 raeburn 6509: $output .= '<td><span class="LC_nobreak"><label><input type = "checkbox" value="'.
1.257 raeburn 6510: $esc_type.'" ';
1.241 raeburn 6511: if (ref($currinsttypes) eq 'ARRAY') {
6512: if (@{$currinsttypes} > 0) {
1.249 raeburn 6513: if (grep(/^any$/,@{$currinsttypes})) {
6514: $output .= 'checked="checked"';
1.257 raeburn 6515: } elsif (grep(/^\Q$esc_type\E$/,@{$currinsttypes})) {
1.241 raeburn 6516: $output .= 'checked="checked"';
6517: }
1.249 raeburn 6518: } else {
6519: $output .= 'checked="checked"';
1.241 raeburn 6520: }
6521: }
1.418 raeburn 6522: $output .= ' name="selfenroll_types_'.$num.'"'.$disabled.' />'.$usertypes->{$type}.'</label></span></td>';
1.241 raeburn 6523: }
6524: $count ++;
6525: }
6526: if (($count > 0) && ($count%$numinrow == 0)) {
6527: $output .= '</tr><tr>';
6528: }
1.249 raeburn 6529: $output .= '<td><span class="LC_nobreak"><label><input type = "checkbox" value="'.$othervalue.'"';
1.241 raeburn 6530: if (ref($currinsttypes) eq 'ARRAY') {
6531: if (@{$currinsttypes} > 0) {
1.249 raeburn 6532: if (grep(/^any$/,@{$currinsttypes})) {
6533: $output .= ' checked="checked"';
6534: } elsif ($othervalue eq 'other') {
6535: if (grep(/^\Q$othervalue\E$/,@{$currinsttypes})) {
6536: $output .= ' checked="checked"';
6537: }
1.241 raeburn 6538: }
1.249 raeburn 6539: } else {
6540: $output .= ' checked="checked"';
1.241 raeburn 6541: }
1.249 raeburn 6542: } else {
6543: $output .= ' checked="checked"';
1.241 raeburn 6544: }
1.418 raeburn 6545: $output .= ' name="selfenroll_types_'.$num.'"'.$disabled.' />'.$othertitle.'</label></span></td></tr></table>';
1.241 raeburn 6546: }
6547: return $output;
6548: }
6549:
1.237 raeburn 6550: sub selfenroll_date_forms {
6551: my ($startform,$endform) = @_;
6552: my $output .= &Apache::lonhtmlcommon::start_pick_box()."\n".
1.244 bisitz 6553: &Apache::lonhtmlcommon::row_title(&mt('Start date'),
1.237 raeburn 6554: 'LC_oddrow_value')."\n".
6555: $startform."\n".
6556: &Apache::lonhtmlcommon::row_closure(1).
1.244 bisitz 6557: &Apache::lonhtmlcommon::row_title(&mt('End date'),
1.237 raeburn 6558: 'LC_oddrow_value')."\n".
6559: $endform."\n".
6560: &Apache::lonhtmlcommon::row_closure(1).
6561: &Apache::lonhtmlcommon::end_pick_box();
6562: return $output;
6563: }
6564:
1.239 raeburn 6565: sub print_userchangelogs_display {
1.415 raeburn 6566: my ($r,$context,$permission,$brcrum) = @_;
1.363 raeburn 6567: my $formname = 'rolelog';
1.418 raeburn 6568: my ($username,$domain,$crstype,$viewablesec,%roleslog);
1.363 raeburn 6569: if ($context eq 'domain') {
6570: $domain = $env{'request.role.domain'};
6571: %roleslog=&Apache::lonnet::dump_dom('nohist_rolelog',$domain);
6572: } else {
6573: if ($context eq 'course') {
6574: $domain = $env{'course.'.$env{'request.course.id'}.'.domain'};
6575: $username = $env{'course.'.$env{'request.course.id'}.'.num'};
6576: $crstype = &Apache::loncommon::course_type();
1.418 raeburn 6577: $viewablesec = &Apache::lonuserutils::viewable_section($permission);
1.363 raeburn 6578: my %saveable_parameters = ('show' => 'scalar',);
6579: &Apache::loncommon::store_course_settings('roles_log',
6580: \%saveable_parameters);
6581: &Apache::loncommon::restore_course_settings('roles_log',
6582: \%saveable_parameters);
6583: } elsif ($context eq 'author') {
6584: $domain = $env{'user.domain'};
6585: if ($env{'request.role'} =~ m{^au\./\Q$domain\E/$}) {
6586: $username = $env{'user.name'};
6587: } else {
6588: undef($domain);
6589: }
6590: }
6591: if ($domain ne '' && $username ne '') {
6592: %roleslog=&Apache::lonnet::dump('nohist_rolelog',$domain,$username);
6593: }
6594: }
1.239 raeburn 6595: if ((keys(%roleslog))[0]=~/^error\:/) { undef(%roleslog); }
6596:
1.415 raeburn 6597: my $helpitem;
6598: if ($context eq 'course') {
6599: $helpitem = 'Course_User_Logs';
1.439 raeburn 6600: } elsif ($context eq 'domain') {
6601: $helpitem = 'Domain_Role_Logs';
6602: } elsif ($context eq 'author') {
6603: $helpitem = 'Author_User_Logs';
1.415 raeburn 6604: }
6605: push (@{$brcrum},
6606: {href => '/adm/createuser?action=changelogs',
6607: text => 'User Management Logs',
6608: help => $helpitem});
6609: my $bread_crumbs_component = 'User Changes';
6610: my $args = { bread_crumbs => $brcrum,
6611: bread_crumbs_component => $bread_crumbs_component};
6612:
6613: # Create navigation javascript
6614: my $jsnav = &userlogdisplay_js($formname);
6615:
6616: my $jscript = (<<ENDSCRIPT);
6617: <script type="text/javascript">
6618: // <![CDATA[
6619: $jsnav
6620: // ]]>
6621: </script>
6622: ENDSCRIPT
6623:
6624: # print page header
6625: $r->print(&header($jscript,$args));
6626:
1.239 raeburn 6627: # set defaults
6628: my $now = time();
6629: my $defstart = $now - (7*24*3600); #7 days ago
6630: my %defaults = (
6631: page => '1',
6632: show => '10',
6633: role => 'any',
6634: chgcontext => 'any',
6635: rolelog_start_date => $defstart,
6636: rolelog_end_date => $now,
6637: );
6638: my $more_records = 0;
6639:
6640: # set current
6641: my %curr;
6642: foreach my $item ('show','page','role','chgcontext') {
6643: $curr{$item} = $env{'form.'.$item};
6644: }
6645: my ($startdate,$enddate) =
6646: &Apache::lonuserutils::get_dates_from_form('rolelog_start_date','rolelog_end_date');
6647: $curr{'rolelog_start_date'} = $startdate;
6648: $curr{'rolelog_end_date'} = $enddate;
6649: foreach my $key (keys(%defaults)) {
6650: if ($curr{$key} eq '') {
6651: $curr{$key} = $defaults{$key};
6652: }
6653: }
1.248 raeburn 6654: my (%whodunit,%changed,$version);
6655: ($version) = ($r->dir_config('lonVersion') =~ /^([\d\.]+)\-/);
1.239 raeburn 6656: my ($minshown,$maxshown);
1.255 raeburn 6657: $minshown = 1;
1.239 raeburn 6658: my $count = 0;
1.415 raeburn 6659: if ($curr{'show'} =~ /\D/) {
6660: $curr{'page'} = 1;
6661: } else {
1.239 raeburn 6662: $maxshown = $curr{'page'} * $curr{'show'};
6663: if ($curr{'page'} > 1) {
6664: $minshown = 1 + ($curr{'page'} - 1) * $curr{'show'};
6665: }
6666: }
1.301 bisitz 6667:
1.327 raeburn 6668: # Form Header
6669: $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">'.
1.363 raeburn 6670: &role_display_filter($context,$formname,$domain,$username,\%curr,
6671: $version,$crstype));
1.327 raeburn 6672:
6673: my $showntableheader = 0;
6674:
6675: # Table Header
6676: my $tableheader =
6677: &Apache::loncommon::start_data_table_header_row()
6678: .'<th> </th>'
6679: .'<th>'.&mt('When').'</th>'
6680: .'<th>'.&mt('Who made the change').'</th>'
6681: .'<th>'.&mt('Changed User').'</th>'
1.363 raeburn 6682: .'<th>'.&mt('Role').'</th>';
6683:
6684: if ($context eq 'course') {
6685: $tableheader .= '<th>'.&mt('Section').'</th>';
6686: }
6687: $tableheader .=
6688: '<th>'.&mt('Context').'</th>'
1.327 raeburn 6689: .'<th>'.&mt('Start').'</th>'
6690: .'<th>'.&mt('End').'</th>'
6691: .&Apache::loncommon::end_data_table_header_row();
6692:
6693: # Display user change log data
1.239 raeburn 6694: foreach my $id (sort { $roleslog{$b}{'exe_time'}<=>$roleslog{$a}{'exe_time'} } (keys(%roleslog))) {
6695: next if (($roleslog{$id}{'exe_time'} < $curr{'rolelog_start_date'}) ||
6696: ($roleslog{$id}{'exe_time'} > $curr{'rolelog_end_date'}));
1.415 raeburn 6697: if ($curr{'show'} !~ /\D/) {
1.239 raeburn 6698: if ($count >= $curr{'page'} * $curr{'show'}) {
6699: $more_records = 1;
6700: last;
6701: }
6702: }
6703: if ($curr{'role'} ne 'any') {
6704: next if ($roleslog{$id}{'logentry'}{'role'} ne $curr{'role'});
6705: }
6706: if ($curr{'chgcontext'} ne 'any') {
6707: if ($curr{'chgcontext'} eq 'selfenroll') {
6708: next if (!$roleslog{$id}{'logentry'}{'selfenroll'});
6709: } else {
6710: next if ($roleslog{$id}{'logentry'}{'context'} ne $curr{'chgcontext'});
6711: }
6712: }
1.418 raeburn 6713: if (($context eq 'course') && ($viewablesec ne '')) {
1.430 raeburn 6714: next if ($roleslog{$id}{'logentry'}{'section'} ne $viewablesec);
1.418 raeburn 6715: }
1.239 raeburn 6716: $count ++;
6717: next if ($count < $minshown);
1.327 raeburn 6718: unless ($showntableheader) {
1.415 raeburn 6719: $r->print(&Apache::loncommon::start_data_table()
1.327 raeburn 6720: .$tableheader);
6721: $r->rflush();
6722: $showntableheader = 1;
6723: }
1.239 raeburn 6724: if ($whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}} eq '') {
6725: $whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}} =
6726: &Apache::loncommon::plainname($roleslog{$id}{'exe_uname'},$roleslog{$id}{'exe_udom'});
6727: }
6728: if ($changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}} eq '') {
6729: $changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}} =
6730: &Apache::loncommon::plainname($roleslog{$id}{'uname'},$roleslog{$id}{'udom'});
6731: }
6732: my $sec = $roleslog{$id}{'logentry'}{'section'};
6733: if ($sec eq '') {
6734: $sec = &mt('None');
6735: }
6736: my ($rolestart,$roleend);
6737: if ($roleslog{$id}{'delflag'}) {
6738: $rolestart = &mt('deleted');
6739: $roleend = &mt('deleted');
6740: } else {
6741: $rolestart = $roleslog{$id}{'logentry'}{'start'};
6742: $roleend = $roleslog{$id}{'logentry'}{'end'};
6743: if ($rolestart eq '' || $rolestart == 0) {
6744: $rolestart = &mt('No start date');
6745: } else {
6746: $rolestart = &Apache::lonlocal::locallocaltime($rolestart);
6747: }
6748: if ($roleend eq '' || $roleend == 0) {
6749: $roleend = &mt('No end date');
6750: } else {
6751: $roleend = &Apache::lonlocal::locallocaltime($roleend);
6752: }
6753: }
6754: my $chgcontext = $roleslog{$id}{'logentry'}{'context'};
6755: if ($roleslog{$id}{'logentry'}{'selfenroll'}) {
6756: $chgcontext = 'selfenroll';
6757: }
1.363 raeburn 6758: my %lt = &rolechg_contexts($context,$crstype);
1.239 raeburn 6759: if ($chgcontext ne '' && $lt{$chgcontext} ne '') {
6760: $chgcontext = $lt{$chgcontext};
6761: }
1.327 raeburn 6762: $r->print(
1.301 bisitz 6763: &Apache::loncommon::start_data_table_row()
6764: .'<td>'.$count.'</td>'
6765: .'<td>'.&Apache::lonlocal::locallocaltime($roleslog{$id}{'exe_time'}).'</td>'
6766: .'<td>'.$whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}}.'</td>'
6767: .'<td>'.$changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}}.'</td>'
1.363 raeburn 6768: .'<td>'.&Apache::lonnet::plaintext($roleslog{$id}{'logentry'}{'role'},$crstype).'</td>');
6769: if ($context eq 'course') {
6770: $r->print('<td>'.$sec.'</td>');
6771: }
6772: $r->print(
6773: '<td>'.$chgcontext.'</td>'
1.301 bisitz 6774: .'<td>'.$rolestart.'</td>'
6775: .'<td>'.$roleend.'</td>'
1.327 raeburn 6776: .&Apache::loncommon::end_data_table_row()."\n");
1.301 bisitz 6777: }
6778:
1.327 raeburn 6779: if ($showntableheader) { # Table footer, if content displayed above
1.415 raeburn 6780: $r->print(&Apache::loncommon::end_data_table().
6781: &userlogdisplay_navlinks(\%curr,$more_records));
1.327 raeburn 6782: } else { # No content displayed above
1.301 bisitz 6783: $r->print('<p class="LC_info">'
6784: .&mt('There are no records to display.')
6785: .'</p>'
6786: );
1.239 raeburn 6787: }
1.301 bisitz 6788:
1.327 raeburn 6789: # Form Footer
6790: $r->print(
6791: '<input type="hidden" name="page" value="'.$curr{'page'}.'" />'
6792: .'<input type="hidden" name="action" value="changelogs" />'
6793: .'</form>');
6794: return;
6795: }
1.301 bisitz 6796:
1.416 raeburn 6797: sub print_useraccesslogs_display {
6798: my ($r,$uname,$udom,$permission,$brcrum) = @_;
6799: my $formname = 'accesslog';
6800: my $form = 'document.accesslog';
6801:
6802: # set breadcrumbs
1.422 raeburn 6803: my %breadcrumb_text = &singleuser_breadcrumb('','domain',$udom);
1.431 raeburn 6804: my $prevphasestr;
6805: if ($env{'form.popup'}) {
6806: $brcrum = [];
6807: } else {
6808: push (@{$brcrum},
6809: {href => "javascript:backPage($form)",
6810: text => $breadcrumb_text{'search'}});
6811: my @prevphases;
6812: if ($env{'form.prevphases'}) {
6813: @prevphases = split(/,/,$env{'form.prevphases'});
6814: $prevphasestr = $env{'form.prevphases'};
6815: }
6816: if (($env{'form.phase'} eq 'userpicked') || (grep(/^userpicked$/,@prevphases))) {
6817: push(@{$brcrum},
6818: {href => "javascript:backPage($form,'get_user_info','select')",
6819: text => $breadcrumb_text{'userpicked'}});
6820: if ($env{'form.phase'} eq 'userpicked') {
6821: $prevphasestr = 'userpicked';
6822: }
1.416 raeburn 6823: }
6824: }
6825: push(@{$brcrum},
6826: {href => '/adm/createuser?action=accesslogs',
6827: text => 'User access logs',
1.424 raeburn 6828: help => 'Domain_User_Access_Logs'});
1.416 raeburn 6829: my $bread_crumbs_component = 'User Access Logs';
6830: my $args = { bread_crumbs => $brcrum,
6831: bread_crumbs_component => 'User Management'};
1.423 raeburn 6832: if ($env{'form.popup'}) {
6833: $args->{'no_nav_bar'} = 1;
1.431 raeburn 6834: $args->{'bread_crumbs_nomenu'} = 1;
1.423 raeburn 6835: }
1.416 raeburn 6836:
1.417 raeburn 6837: # set javascript
1.416 raeburn 6838: my ($jsback,$elements) = &crumb_utilities();
6839: my $jsnav = &userlogdisplay_js($formname);
6840:
6841: my $jscript = (<<ENDSCRIPT);
6842: <script type="text/javascript">
6843: // <![CDATA[
6844:
6845: $jsback
6846: $jsnav
6847:
6848: // ]]>
6849: </script>
6850:
6851: ENDSCRIPT
6852:
1.417 raeburn 6853: # print page header
1.416 raeburn 6854: $r->print(&header($jscript,$args));
6855:
6856: # early out unless log data can be displayed.
6857: unless ($permission->{'activity'}) {
6858: $r->print('<p class="LC_warning">'
6859: .&mt('You do not have rights to display user access logs.')
1.431 raeburn 6860: .'</p>');
6861: if ($env{'form.popup'}) {
6862: $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a></p>');
6863: } else {
6864: $r->print(&earlyout_accesslog_form($formname,$prevphasestr,$udom));
6865: }
1.416 raeburn 6866: return;
6867: }
6868:
6869: unless ($udom eq $env{'request.role.domain'}) {
6870: $r->print('<p class="LC_warning">'
6871: .&mt("User's domain must match role's domain")
6872: .'</p>'
6873: .&earlyout_accesslog_form($formname,$prevphasestr,$udom));
1.417 raeburn 6874: return;
1.416 raeburn 6875: }
6876:
6877: if (($uname eq '') || ($udom eq '')) {
6878: $r->print('<p class="LC_warning">'
6879: .&mt('Invalid username or domain')
6880: .'</p>'
6881: .&earlyout_accesslog_form($formname,$prevphasestr,$udom));
6882: return;
6883: }
6884:
1.437 raeburn 6885: if (&Apache::lonnet::privileged($uname,$udom,
6886: [$env{'request.role.domain'}],['dc','su'])) {
6887: unless (&Apache::lonnet::privileged($env{'user.name'},$env{'user.domain'},
6888: [$env{'request.role.domain'}],['dc','su'])) {
6889: $r->print('<p class="LC_warning">'
6890: .&mt('You need to be a privileged user to display user access logs for [_1]',
6891: &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),
6892: $uname,$udom))
6893: .'</p>');
6894: if ($env{'form.popup'}) {
6895: $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a></p>');
6896: } else {
6897: $r->print(&earlyout_accesslog_form($formname,$prevphasestr,$udom));
6898: }
6899: return;
6900: }
6901: }
6902:
1.416 raeburn 6903: # set defaults
6904: my $now = time();
6905: my $defstart = $now - (7*24*3600);
6906: my %defaults = (
6907: page => '1',
6908: show => '10',
6909: activity => 'any',
6910: accesslog_start_date => $defstart,
6911: accesslog_end_date => $now,
6912: );
6913: my $more_records = 0;
6914:
6915: # set current
6916: my %curr;
6917: foreach my $item ('show','page','activity') {
6918: $curr{$item} = $env{'form.'.$item};
6919: }
6920: my ($startdate,$enddate) =
6921: &Apache::lonuserutils::get_dates_from_form('accesslog_start_date','accesslog_end_date');
6922: $curr{'accesslog_start_date'} = $startdate;
6923: $curr{'accesslog_end_date'} = $enddate;
6924: foreach my $key (keys(%defaults)) {
6925: if ($curr{$key} eq '') {
6926: $curr{$key} = $defaults{$key};
6927: }
6928: }
6929: my ($minshown,$maxshown);
6930: $minshown = 1;
6931: my $count = 0;
6932: if ($curr{'show'} =~ /\D/) {
6933: $curr{'page'} = 1;
6934: } else {
6935: $maxshown = $curr{'page'} * $curr{'show'};
6936: if ($curr{'page'} > 1) {
6937: $minshown = 1 + ($curr{'page'} - 1) * $curr{'show'};
6938: }
6939: }
6940:
6941: # form header
6942: $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">'.
6943: &activity_display_filter($formname,\%curr));
6944:
6945: my $showntableheader = 0;
6946: my ($nav_script,$nav_links);
6947:
6948: # table header
1.431 raeburn 6949: my $tableheader = '<h3>'.
6950: &mt('User access logs for: [_1]',
6951: &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),$uname,$udom)).'</h3>'
6952: .&Apache::loncommon::start_data_table_header_row()
1.416 raeburn 6953: .'<th> </th>'
6954: .'<th>'.&mt('When').'</th>'
6955: .'<th>'.&mt('HostID').'</th>'
6956: .'<th>'.&mt('Event').'</th>'
6957: .'<th>'.&mt('Other data').'</th>'
6958: .&Apache::loncommon::end_data_table_header_row();
6959:
6960: my %filters=(
6961: start => $curr{'accesslog_start_date'},
6962: end => $curr{'accesslog_end_date'},
6963: action => $curr{'activity'},
6964: );
6965:
6966: my $reply = &Apache::lonnet::userlog_query($uname,$udom,%filters);
6967: unless ( ($reply =~/^timeout/) || ($reply =~/^error/) ) {
6968: my (%courses,%missing);
6969: my @results = split(/\&/,$reply);
6970: foreach my $item (reverse(@results)) {
6971: my ($timestamp,$host,$event) = split(/:/,$item);
6972: next unless ($event =~ /^(Log|Role)/);
6973: if ($curr{'show'} !~ /\D/) {
6974: if ($count >= $curr{'page'} * $curr{'show'}) {
6975: $more_records = 1;
6976: last;
6977: }
6978: }
6979: $count ++;
6980: next if ($count < $minshown);
6981: unless ($showntableheader) {
6982: $r->print($nav_script
6983: .&Apache::loncommon::start_data_table()
6984: .$tableheader);
6985: $r->rflush();
6986: $showntableheader = 1;
6987: }
1.418 raeburn 6988: my ($shown,$extra);
1.437 raeburn 6989: my ($event,$data) = split(/\s+/,&unescape($event),2);
1.416 raeburn 6990: if ($event eq 'Role') {
6991: my ($rolecode,$extent) = split(/\./,$data,2);
6992: next if ($extent eq '');
6993: my ($crstype,$desc,$info);
1.418 raeburn 6994: if ($extent =~ m{^/($match_domain)/($match_courseid)(?:/(\w+)|)$}) {
6995: my ($cdom,$cnum,$sec) = ($1,$2,$3);
1.416 raeburn 6996: my $cid = $cdom.'_'.$cnum;
6997: if (exists($courses{$cid})) {
6998: $crstype = $courses{$cid}{'type'};
6999: $desc = $courses{$cid}{'description'};
7000: } elsif ($missing{$cid}) {
7001: $crstype = 'Course';
7002: $desc = 'Course/Community';
7003: } else {
7004: my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',$cnum,undef,undef,'.');
7005: if (ref($crsinfo{$cdom.'_'.$cnum}) eq 'HASH') {
7006: $courses{$cid} = $crsinfo{$cid};
7007: $crstype = $crsinfo{$cid}{'type'};
7008: $desc = $crsinfo{$cid}{'description'};
7009: } else {
7010: $missing{$cid} = 1;
7011: }
7012: }
7013: $extra = &mt($crstype).': <a href="/public/'.$cdom.'/'.$cnum.'/syllabus">'.$desc.'</a>';
1.418 raeburn 7014: if ($sec ne '') {
7015: $extra .= ' ('.&mt('Section: [_1]',$sec).')';
7016: }
1.416 raeburn 7017: } elsif ($extent =~ m{^/($match_domain)/($match_username|$)}) {
7018: my ($dom,$name) = ($1,$2);
7019: if ($rolecode eq 'au') {
7020: $extra = '';
7021: } elsif ($rolecode =~ /^(ca|aa)$/) {
1.417 raeburn 7022: $extra = &mt('Authoring Space: [_1]',$name.':'.$dom);
1.416 raeburn 7023: } elsif ($rolecode =~ /^(li|dg|dh|dc|sc)$/) {
7024: $extra = &mt('Domain: [_1]',$dom);
7025: }
7026: }
7027: my $rolename;
7028: if ($rolecode =~ m{^cr/($match_domain)/($match_username)/(\w+)}) {
7029: my $role = $3;
1.417 raeburn 7030: my $owner = "($2:$1)";
1.416 raeburn 7031: if ($2 eq $1.'-domainconfig') {
7032: $owner = '(ad hoc)';
1.417 raeburn 7033: }
1.416 raeburn 7034: $rolename = &mt('Custom role: [_1]',$role.' '.$owner);
7035: } else {
7036: $rolename = &Apache::lonnet::plaintext($rolecode,$crstype);
7037: }
7038: $shown = &mt('Role selection: [_1]',$rolename);
7039: } else {
7040: $shown = &mt($event);
1.437 raeburn 7041: if ($data =~ /^webdav/) {
7042: my ($path,$clientip) = split(/\s+/,$data,2);
7043: $path =~ s/^webdav//;
7044: if ($clientip ne '') {
7045: $extra = &mt('Client IP address: [_1]',$clientip);
7046: }
7047: if ($path ne '') {
7048: $shown .= ' '.&mt('(WebDAV access to [_1])',$path);
7049: }
7050: } elsif ($data ne '') {
7051: $extra = &mt('Client IP address: [_1]',$data);
1.416 raeburn 7052: }
7053: }
7054: $r->print(
7055: &Apache::loncommon::start_data_table_row()
7056: .'<td>'.$count.'</td>'
7057: .'<td>'.&Apache::lonlocal::locallocaltime($timestamp).'</td>'
7058: .'<td>'.$host.'</td>'
7059: .'<td>'.$shown.'</td>'
7060: .'<td>'.$extra.'</td>'
7061: .&Apache::loncommon::end_data_table_row()."\n");
7062: }
7063: }
7064:
7065: if ($showntableheader) { # Table footer, if content displayed above
7066: $r->print(&Apache::loncommon::end_data_table().
7067: &userlogdisplay_navlinks(\%curr,$more_records));
7068: } else { # No content displayed above
7069: $r->print('<p class="LC_info">'
7070: .&mt('There are no records to display.')
7071: .'</p>');
7072: }
7073:
1.423 raeburn 7074: if ($env{'form.popup'} == 1) {
7075: $r->print('<input type="hidden" name="popup" value="1" />'."\n");
7076: }
7077:
1.416 raeburn 7078: # Form Footer
7079: $r->print(
7080: '<input type="hidden" name="currstate" value="" />'
7081: .'<input type="hidden" name="accessuname" value="'.$uname.'" />'
7082: .'<input type="hidden" name="accessudom" value="'.$udom.'" />'
7083: .'<input type="hidden" name="page" value="'.$curr{'page'}.'" />'
7084: .'<input type="hidden" name="prevphases" value="'.$prevphasestr.'" />'
7085: .'<input type="hidden" name="phase" value="activity" />'
7086: .'<input type="hidden" name="action" value="accesslogs" />'
7087: .'<input type="hidden" name="srchdomain" value="'.$udom.'" />'
7088: .'<input type="hidden" name="srchby" value="'.$env{'form.srchby'}.'" />'
7089: .'<input type="hidden" name="srchtype" value="'.$env{'form.srchtype'}.'" />'
7090: .'<input type="hidden" name="srchterm" value="'.&HTML::Entities::encode($env{'form.srchterm'},'<>"&').'" />'
7091: .'<input type="hidden" name="srchin" value="'.$env{'form.srchin'}.'" />'
7092: .'</form>');
7093: return;
7094: }
7095:
7096: sub earlyout_accesslog_form {
7097: my ($formname,$prevphasestr,$udom) = @_;
7098: my $srchterm = &HTML::Entities::encode($env{'form.srchterm'},'<>"&');
7099: return <<"END";
7100: <form action="/adm/createuser" method="post" name="$formname">
7101: <input type="hidden" name="currstate" value="" />
7102: <input type="hidden" name="prevphases" value="$prevphasestr" />
7103: <input type="hidden" name="phase" value="activity" />
7104: <input type="hidden" name="action" value="accesslogs" />
7105: <input type="hidden" name="srchdomain" value="$udom" />
7106: <input type="hidden" name="srchby" value="$env{'form.srchby'}" />
7107: <input type="hidden" name="srchtype" value="$env{'form.srchtype'}" />
7108: <input type="hidden" name="srchterm" value="$srchterm" />
7109: <input type="hidden" name="srchin" value="$env{'form.srchin'}" />
7110: </form>
7111: END
7112: }
7113:
7114: sub activity_display_filter {
7115: my ($formname,$curr) = @_;
7116: my $nolink = 1;
7117: my $output = '<table><tr><td valign="top">'.
7118: '<span class="LC_nobreak"><b>'.&mt('Actions/page:').'</b></span><br />'.
7119: &Apache::lonmeta::selectbox('show',$curr->{'show'},undef,
7120: (&mt('all'),5,10,20,50,100,1000,10000)).
7121: '</td><td> </td>';
7122: my $startform =
7123: &Apache::lonhtmlcommon::date_setter($formname,'accesslog_start_date',
7124: $curr->{'accesslog_start_date'},undef,
7125: undef,undef,undef,undef,undef,undef,$nolink);
7126: my $endform =
7127: &Apache::lonhtmlcommon::date_setter($formname,'accesslog_end_date',
7128: $curr->{'accesslog_end_date'},undef,
7129: undef,undef,undef,undef,undef,undef,$nolink);
7130: my %lt = &Apache::lonlocal::texthash (
7131: activity => 'Activity',
7132: Role => 'Role selection',
7133: log => 'Log-in or Logout',
7134: );
7135: $output .= '<td valign="top"><b>'.&mt('Window during which actions occurred:').'</b><br />'.
7136: '<table><tr><td>'.&mt('After:').
7137: '</td><td>'.$startform.'</td></tr>'.
7138: '<tr><td>'.&mt('Before:').'</td>'.
7139: '<td>'.$endform.'</td></tr></table>'.
7140: '</td>'.
7141: '<td> </td>'.
7142: '<td valign="top"><b>'.&mt('Activities').'</b><br />'.
7143: '<select name="activity"><option value="any"';
7144: if ($curr->{'activity'} eq 'any') {
7145: $output .= ' selected="selected"';
7146: }
7147: $output .= '>'.&mt('Any').'</option>'."\n";
7148: foreach my $activity ('Role','log') {
7149: my $selstr = '';
7150: if ($activity eq $curr->{'activity'}) {
7151: $selstr = ' selected="selected"';
7152: }
7153: $output .= '<option value="'.$activity.'"'.$selstr.'>'.$lt{$activity}.'</option>';
7154: }
7155: $output .= '</select></td>'.
7156: '</tr></table>';
7157: # Update Display button
7158: $output .= '<p>'
7159: .'<input type="submit" value="'.&mt('Update Display').'" />'
1.431 raeburn 7160: .'</p><hr />';
1.416 raeburn 7161: return $output;
7162: }
7163:
1.415 raeburn 7164: sub userlogdisplay_js {
7165: my ($formname) = @_;
7166: return <<"ENDSCRIPT";
7167:
1.239 raeburn 7168: function chgPage(caller) {
7169: if (caller == 'previous') {
7170: document.$formname.page.value --;
7171: }
7172: if (caller == 'next') {
7173: document.$formname.page.value ++;
7174: }
1.327 raeburn 7175: document.$formname.submit();
1.239 raeburn 7176: return;
7177: }
7178: ENDSCRIPT
1.415 raeburn 7179: }
7180:
7181: sub userlogdisplay_navlinks {
7182: my ($curr,$more_records) = @_;
7183: return unless(ref($curr) eq 'HASH');
7184: # Navigation Buttons
7185: my $nav_links = '<p>';
7186: if (($curr->{'page'} > 1) || ($more_records)) {
7187: if (($curr->{'page'} > 1) && ($curr->{'show'} !~ /\D/)) {
7188: $nav_links .= '<input type="button"'
7189: .' onclick="javascript:chgPage('."'previous'".');"'
7190: .' value="'.&mt('Previous [_1] changes',$curr->{'show'})
7191: .'" /> ';
7192: }
7193: if ($more_records) {
7194: $nav_links .= '<input type="button"'
7195: .' onclick="javascript:chgPage('."'next'".');"'
7196: .' value="'.&mt('Next [_1] changes',$curr->{'show'})
7197: .'" />';
1.301 bisitz 7198: }
7199: }
1.415 raeburn 7200: $nav_links .= '</p>';
7201: return $nav_links;
1.239 raeburn 7202: }
7203:
7204: sub role_display_filter {
1.363 raeburn 7205: my ($context,$formname,$cdom,$cnum,$curr,$version,$crstype) = @_;
7206: my $lctype;
7207: if ($context eq 'course') {
7208: $lctype = lc($crstype);
7209: }
1.239 raeburn 7210: my $nolink = 1;
7211: my $output = '<table><tr><td valign="top">'.
1.301 bisitz 7212: '<span class="LC_nobreak"><b>'.&mt('Changes/page:').'</b></span><br />'.
1.239 raeburn 7213: &Apache::lonmeta::selectbox('show',$curr->{'show'},undef,
7214: (&mt('all'),5,10,20,50,100,1000,10000)).
7215: '</td><td> </td>';
7216: my $startform =
7217: &Apache::lonhtmlcommon::date_setter($formname,'rolelog_start_date',
7218: $curr->{'rolelog_start_date'},undef,
7219: undef,undef,undef,undef,undef,undef,$nolink);
7220: my $endform =
7221: &Apache::lonhtmlcommon::date_setter($formname,'rolelog_end_date',
7222: $curr->{'rolelog_end_date'},undef,
7223: undef,undef,undef,undef,undef,undef,$nolink);
1.363 raeburn 7224: my %lt = &rolechg_contexts($context,$crstype);
1.301 bisitz 7225: $output .= '<td valign="top"><b>'.&mt('Window during which changes occurred:').'</b><br />'.
7226: '<table><tr><td>'.&mt('After:').
7227: '</td><td>'.$startform.'</td></tr>'.
7228: '<tr><td>'.&mt('Before:').'</td>'.
7229: '<td>'.$endform.'</td></tr></table>'.
7230: '</td>'.
7231: '<td> </td>'.
1.239 raeburn 7232: '<td valign="top"><b>'.&mt('Role:').'</b><br />'.
7233: '<select name="role"><option value="any"';
7234: if ($curr->{'role'} eq 'any') {
7235: $output .= ' selected="selected"';
7236: }
7237: $output .= '>'.&mt('Any').'</option>'."\n";
1.363 raeburn 7238: my @roles = &Apache::lonuserutils::roles_by_context($context,1,$crstype);
1.239 raeburn 7239: foreach my $role (@roles) {
7240: my $plrole;
7241: if ($role eq 'cr') {
7242: $plrole = &mt('Custom Role');
7243: } else {
1.318 raeburn 7244: $plrole=&Apache::lonnet::plaintext($role,$crstype);
1.239 raeburn 7245: }
7246: my $selstr = '';
7247: if ($role eq $curr->{'role'}) {
7248: $selstr = ' selected="selected"';
7249: }
7250: $output .= ' <option value="'.$role.'"'.$selstr.'>'.$plrole.'</option>';
7251: }
1.301 bisitz 7252: $output .= '</select></td>'.
7253: '<td> </td>'.
7254: '<td valign="top"><b>'.
1.239 raeburn 7255: &mt('Context:').'</b><br /><select name="chgcontext">';
1.363 raeburn 7256: my @posscontexts;
7257: if ($context eq 'course') {
1.376 raeburn 7258: @posscontexts = ('any','automated','updatenow','createcourse','course','domain','selfenroll','requestcourses');
1.363 raeburn 7259: } elsif ($context eq 'domain') {
7260: @posscontexts = ('any','domain','requestauthor','domconfig','server');
7261: } else {
7262: @posscontexts = ('any','author','domain');
7263: }
7264: foreach my $chgtype (@posscontexts) {
1.239 raeburn 7265: my $selstr = '';
7266: if ($curr->{'chgcontext'} eq $chgtype) {
1.301 bisitz 7267: $selstr = ' selected="selected"';
1.239 raeburn 7268: }
1.363 raeburn 7269: if ($context eq 'course') {
1.376 raeburn 7270: if (($chgtype eq 'automated') || ($chgtype eq 'updatenow')) {
1.363 raeburn 7271: next if (!&Apache::lonnet::auto_run($cnum,$cdom));
7272: }
1.239 raeburn 7273: }
7274: $output .= '<option value="'.$chgtype.'"'.$selstr.'>'.$lt{$chgtype}.'</option>'."\n";
1.248 raeburn 7275: }
1.303 bisitz 7276: $output .= '</select></td>'
7277: .'</tr></table>';
7278:
7279: # Update Display button
7280: $output .= '<p>'
7281: .'<input type="submit" value="'.&mt('Update Display').'" />'
7282: .'</p>';
7283:
7284: # Server version info
1.363 raeburn 7285: my $needsrev = '2.11.0';
7286: if ($context eq 'course') {
7287: $needsrev = '2.7.0';
7288: }
7289:
1.303 bisitz 7290: $output .= '<p class="LC_info">'
7291: .&mt('Only changes made from servers running LON-CAPA [_1] or later are displayed.'
1.363 raeburn 7292: ,$needsrev);
1.248 raeburn 7293: if ($version) {
1.303 bisitz 7294: $output .= ' '.&mt('This LON-CAPA server is version [_1]',$version);
7295: }
7296: $output .= '</p><hr />';
1.239 raeburn 7297: return $output;
7298: }
7299:
7300: sub rolechg_contexts {
1.363 raeburn 7301: my ($context,$crstype) = @_;
7302: my %lt;
7303: if ($context eq 'course') {
7304: %lt = &Apache::lonlocal::texthash (
1.239 raeburn 7305: any => 'Any',
1.376 raeburn 7306: automated => 'Automated Enrollment',
1.239 raeburn 7307: updatenow => 'Roster Update',
7308: createcourse => 'Course Creation',
7309: course => 'User Management in course',
7310: domain => 'User Management in domain',
1.313 raeburn 7311: selfenroll => 'Self-enrolled',
1.318 raeburn 7312: requestcourses => 'Course Request',
1.239 raeburn 7313: );
1.363 raeburn 7314: if ($crstype eq 'Community') {
7315: $lt{'createcourse'} = &mt('Community Creation');
7316: $lt{'course'} = &mt('User Management in community');
7317: $lt{'requestcourses'} = &mt('Community Request');
7318: }
7319: } elsif ($context eq 'domain') {
7320: %lt = &Apache::lonlocal::texthash (
7321: any => 'Any',
7322: domain => 'User Management in domain',
7323: requestauthor => 'Authoring Request',
7324: server => 'Command line script (DC role)',
7325: domconfig => 'Self-enrolled',
7326: );
7327: } else {
7328: %lt = &Apache::lonlocal::texthash (
7329: any => 'Any',
7330: domain => 'User Management in domain',
7331: author => 'User Management by author',
7332: );
7333: }
1.239 raeburn 7334: return %lt;
7335: }
7336:
1.428 raeburn 7337: sub print_helpdeskaccess_display {
7338: my ($r,$permission,$brcrum) = @_;
7339: my $formname = 'helpdeskaccess';
7340: my $helpitem = 'Course_Helpdesk_Access';
7341: push (@{$brcrum},
7342: {href => '/adm/createuser?action=helpdesk',
7343: text => 'Helpdesk Access',
7344: help => $helpitem});
7345: my $bread_crumbs_component = 'Helpdesk Staff Access';
7346: my $args = { bread_crumbs => $brcrum,
7347: bread_crumbs_component => $bread_crumbs_component};
7348:
7349: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
7350: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
7351: my $confname = $cdom.'-domainconfig';
7352: my $crstype = &Apache::loncommon::course_type();
7353:
1.434 raeburn 7354: my @accesstypes = ('all','dh','da','none');
1.428 raeburn 7355: my ($numstatustypes,@jsarray);
7356: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($cdom);
7357: if (ref($types) eq 'ARRAY') {
1.430 raeburn 7358: if (@{$types} > 0) {
1.428 raeburn 7359: $numstatustypes = scalar(@{$types});
7360: push(@accesstypes,'status');
7361: @jsarray = ('bystatus');
7362: }
7363: }
7364: my %customroles = &get_domain_customroles($cdom,$confname);
1.432 raeburn 7365: my %domhelpdesk = &Apache::lonnet::get_active_domroles($cdom,['dh','da']);
1.428 raeburn 7366: if (keys(%domhelpdesk)) {
7367: push(@accesstypes,('inc','exc'));
7368: push(@jsarray,('notinc','notexc'));
7369: }
7370: push(@jsarray,'privs');
7371: my $hiddenstr = join("','",@jsarray);
7372: my $rolestr = join("','",sort(keys(%customroles)));
7373:
7374: my $jscript;
7375: my (%settings,%overridden);
7376: if (keys(%customroles)) {
7377: &get_adhocrole_settings($env{'request.course.id'},\@accesstypes,
7378: $types,\%customroles,\%settings,\%overridden);
7379: my %jsfull=();
7380: my %jslevels= (
7381: course => {},
7382: domain => {},
7383: system => {},
7384: );
7385: my %jslevelscurrent=(
7386: course => {},
7387: domain => {},
7388: system => {},
7389: );
7390: my (%privs,%jsprivs);
7391: &Apache::lonuserutils::custom_role_privs(\%privs,\%jsfull,\%jslevels,\%jslevelscurrent);
7392: foreach my $priv (keys(%jsfull)) {
7393: if ($jslevels{'course'}{$priv}) {
7394: $jsprivs{$priv} = 1;
7395: }
7396: }
7397: my (%elements,%stored);
7398: foreach my $role (keys(%customroles)) {
7399: $elements{$role.'_access'} = 'radio';
7400: $elements{$role.'_incrs'} = 'radio';
7401: if ($numstatustypes) {
7402: $elements{$role.'_status'} = 'checkbox';
7403: }
7404: if (keys(%domhelpdesk) > 0) {
7405: $elements{$role.'_staff_inc'} = 'checkbox';
7406: $elements{$role.'_staff_exc'} = 'checkbox';
7407: }
1.430 raeburn 7408: $elements{$role.'_override'} = 'checkbox';
1.428 raeburn 7409: if (ref($settings{$role}) eq 'HASH') {
7410: if ($settings{$role}{'access'} ne '') {
7411: my $curraccess = $settings{$role}{'access'};
7412: $stored{$role.'_access'} = $curraccess;
7413: $stored{$role.'_incrs'} = 1;
7414: if ($curraccess eq 'status') {
7415: if (ref($settings{$role}{'status'}) eq 'ARRAY') {
7416: $stored{$role.'_status'} = $settings{$role}{'status'};
7417: }
7418: } elsif (($curraccess eq 'exc') || ($curraccess eq 'inc')) {
7419: if (ref($settings{$role}{$curraccess}) eq 'ARRAY') {
7420: $stored{$role.'_staff_'.$curraccess} = $settings{$role}{$curraccess};
7421: }
7422: }
7423: } else {
7424: $stored{$role.'_incrs'} = 0;
7425: }
7426: $stored{$role.'_override'} = [];
7427: if ($env{'course.'.$env{'request.course.id'}.'.internal.adhocpriv.'.$role}) {
7428: if (ref($settings{$role}{'off'}) eq 'ARRAY') {
7429: foreach my $priv (@{$settings{$role}{'off'}}) {
7430: push(@{$stored{$role.'_override'}},$priv);
7431: }
7432: }
7433: if (ref($settings{$role}{'on'}) eq 'ARRAY') {
7434: foreach my $priv (@{$settings{$role}{'on'}}) {
7435: unless (grep(/^$priv$/,@{$stored{$role.'_override'}})) {
7436: push(@{$stored{$role.'_override'}},$priv);
7437: }
7438: }
7439: }
7440: }
7441: } else {
7442: $stored{$role.'_incrs'} = 0;
7443: }
7444: }
7445: $jscript = &Apache::lonhtmlcommon::set_form_elements(\%elements,\%stored);
7446: }
7447:
7448: my $js = <<"ENDJS";
7449: <script type="text/javascript">
7450: // <![CDATA[
7451: $jscript;
7452:
7453: function switchRoleTab(caller,role) {
7454: if (document.getElementById(role+'_maindiv')) {
7455: if (caller.id != 'LC_current_minitab') {
7456: if (document.getElementById('LC_current_minitab')) {
7457: document.getElementById('LC_current_minitab').id=null;
7458: }
7459: var roledivs = Array('$rolestr');
7460: if (roledivs.length > 0) {
7461: for (var i=0; i<roledivs.length; i++) {
7462: if (document.getElementById(roledivs[i]+'_maindiv')) {
7463: document.getElementById(roledivs[i]+'_maindiv').style.display='none';
7464: }
7465: }
7466: }
7467: caller.id = 'LC_current_minitab';
7468: document.getElementById(role+'_maindiv').style.display='block';
7469: }
7470: }
7471: return false;
1.430 raeburn 7472: }
1.428 raeburn 7473:
7474: function helpdeskAccess(role) {
7475: var curraccess = null;
7476: if (document.$formname.elements[role+'_access'].length) {
7477: for (var i=0; i<document.$formname.elements[role+'_access'].length; i++) {
7478: if (document.$formname.elements[role+'_access'][i].checked) {
7479: curraccess = document.$formname.elements[role+'_access'][i].value;
7480: }
7481: }
7482: }
7483: var shown = Array();
7484: var hidden = Array();
7485: if (curraccess == 'none') {
1.430 raeburn 7486: hidden = Array ('$hiddenstr');
1.428 raeburn 7487: } else {
7488: if (curraccess == 'status') {
1.430 raeburn 7489: shown = Array ('bystatus','privs');
7490: hidden = Array ('notinc','notexc');
1.428 raeburn 7491: } else {
7492: if (curraccess == 'exc') {
7493: shown = Array ('notexc','privs');
7494: hidden = Array ('notinc','bystatus');
7495: }
7496: if (curraccess == 'inc') {
7497: shown = Array ('notinc','privs');
7498: hidden = Array ('notexc','bystatus');
7499: }
7500: if (curraccess == 'all') {
7501: shown = Array ('privs');
7502: hidden = Array ('notinc','notexc','bystatus');
7503: }
7504: }
7505: }
7506: if (hidden.length > 0) {
7507: for (var i=0; i<hidden.length; i++) {
7508: if (document.getElementById(role+'_'+hidden[i])) {
1.430 raeburn 7509: document.getElementById(role+'_'+hidden[i]).style.display = 'none';
1.428 raeburn 7510: }
7511: }
7512: }
7513: if (shown.length > 0) {
7514: for (var i=0; i<shown.length; i++) {
7515: if (document.getElementById(role+'_'+shown[i])) {
7516: if (shown[i] == 'privs') {
7517: document.getElementById(role+'_'+shown[i]).style.display = 'block';
7518: } else {
7519: document.getElementById(role+'_'+shown[i]).style.display = 'inline';
7520: }
7521: }
7522: }
7523: }
7524: return;
7525: }
7526:
7527: function toggleAccess(role) {
7528: if ((document.getElementById(role+'_setincrs')) &&
7529: (document.getElementById(role+'_setindom'))) {
7530: for (var i=0; i<document.$formname.elements[role+'_incrs'].length; i++) {
7531: if (document.$formname.elements[role+'_incrs'][i].checked) {
7532: if (document.$formname.elements[role+'_incrs'][i].value == 1) {
7533: document.getElementById(role+'_setindom').style.display = 'none';
1.430 raeburn 7534: document.getElementById(role+'_setincrs').style.display = 'block';
1.428 raeburn 7535: } else {
7536: document.getElementById(role+'_setincrs').style.display = 'none';
7537: document.getElementById(role+'_setindom').style.display = 'block';
7538: }
7539: break;
7540: }
7541: }
7542: }
7543: return;
7544: }
7545:
7546: // ]]>
7547: </script>
7548: ENDJS
7549:
7550: $args->{add_entries} = {onload => "javascript:setFormElements(document.$formname)"};
7551:
7552: # print page header
7553: $r->print(&header($js,$args));
7554: # print form header
7555: $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">');
7556:
7557: if (keys(%customroles)) {
7558: my %lt = &Apache::lonlocal::texthash(
7559: 'aco' => 'As course owner you may override the defaults set in the domain for role usage and/or privileges.',
7560: 'rou' => 'Role usage',
7561: 'whi' => 'Which helpdesk personnel may use this role?',
7562: 'udd' => 'Use domain default',
1.433 raeburn 7563: 'all' => 'All with domain helpdesk or helpdesk assistant role',
1.434 raeburn 7564: 'dh' => 'All with domain helpdesk role',
7565: 'da' => 'All with domain helpdesk assistant role',
1.428 raeburn 7566: 'none' => 'None',
7567: 'status' => 'Determined based on institutional status',
1.430 raeburn 7568: 'inc' => 'Include all, but exclude specific personnel',
1.428 raeburn 7569: 'exc' => 'Exclude all, but include specific personnel',
7570: 'hel' => 'Helpdesk',
7571: 'rpr' => 'Role privileges',
7572: );
7573: $lt{'tfh'} = &mt("Custom [_1]ad hoc[_2] course roles available for use by the domain's helpdesk are as follows",'<i>','</i>');
7574: my %domconfig = &Apache::lonnet::get_dom('configuration',['helpsettings'],$cdom);
7575: my (%domcurrent,%ordered,%description,%domusage,$disabled);
7576: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
7577: if (ref($domconfig{'helpsettings'}{'adhoc'}) eq 'HASH') {
7578: %domcurrent = %{$domconfig{'helpsettings'}{'adhoc'}};
7579: }
7580: }
7581: my $count = 0;
7582: foreach my $role (sort(keys(%customroles))) {
7583: my ($order,$desc,$access_in_dom);
7584: if (ref($domcurrent{$role}) eq 'HASH') {
7585: $order = $domcurrent{$role}{'order'};
7586: $desc = $domcurrent{$role}{'desc'};
7587: $access_in_dom = $domcurrent{$role}{'access'};
7588: }
7589: if ($order eq '') {
7590: $order = $count;
7591: }
7592: $ordered{$order} = $role;
7593: if ($desc ne '') {
7594: $description{$role} = $desc;
7595: } else {
7596: $description{$role}= $role;
7597: }
7598: $count++;
7599: }
7600: %domusage = &domain_adhoc_access(\%customroles,\%domcurrent,\@accesstypes,$usertypes,$othertitle);
7601: my @roles_by_num = ();
7602: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
7603: push(@roles_by_num,$ordered{$item});
1.430 raeburn 7604: }
1.429 raeburn 7605: $r->print('<p>'.$lt{'tfh'}.': <i>'.join('</i>, <i>',map { $description{$_}; } @roles_by_num).'</i>.');
1.428 raeburn 7606: if ($permission->{'owner'}) {
7607: $r->print('<br />'.$lt{'aco'}.'</p><p>');
7608: $r->print('<input type="hidden" name="state" value="process" />'.
7609: '<input type="submit" value="'.&mt('Save changes').'" />');
7610: } else {
7611: if ($env{'course.'.$env{'request.course.id'}.'.internal.courseowner'}) {
7612: my ($ownername,$ownerdom) = split(/:/,$env{'course.'.$env{'request.course.id'}.'.internal.courseowner'});
7613: $r->print('<br />'.&mt('The course owner -- [_1] -- can override the default access and/or privileges for these ad hoc roles.',
7614: &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($ownername,$ownerdom),$ownername,$ownerdom)));
7615: }
7616: $disabled = ' disabled="disabled"';
7617: }
7618: $r->print('</p>');
7619:
7620: $r->print('<div id="LC_minitab_header"><ul>');
7621: my $count = 0;
7622: my %visibility;
7623: foreach my $role (@roles_by_num) {
7624: my $id;
7625: if ($count == 0) {
7626: $id=' id="LC_current_minitab"';
1.430 raeburn 7627: $visibility{$role} = ' style="display:block"';
1.428 raeburn 7628: } else {
7629: $visibility{$role} = ' style="display:none"';
7630: }
7631: $count ++;
7632: $r->print('<li'.$id.'><a href="#" onclick="javascript:switchRoleTab(this.parentNode,'."'$role'".');">'.$description{$role}.'</a></li>');
7633: }
7634: $r->print('</ul></div>');
7635:
7636: foreach my $role (@roles_by_num) {
7637: my %usecheck = (
7638: all => ' checked="checked"',
7639: );
7640: my %displaydiv = (
7641: status => 'none',
7642: inc => 'none',
7643: exc => 'none',
7644: priv => 'block',
7645: );
7646: my (%selected,$overridden,$incrscheck,$indomcheck,$indomvis,$incrsvis);
1.430 raeburn 7647: if (ref($settings{$role}) eq 'HASH') {
1.428 raeburn 7648: if ($settings{$role}{'access'} ne '') {
7649: $indomvis = ' style="display:none"';
7650: $incrsvis = ' style="display:block"';
1.430 raeburn 7651: $incrscheck = ' checked="checked"';
1.428 raeburn 7652: if ($settings{$role}{'access'} ne 'all') {
7653: $usecheck{$settings{$role}{'access'}} = $usecheck{'all'};
7654: delete($usecheck{'all'});
7655: if ($settings{$role}{'access'} eq 'status') {
7656: my $access = 'status';
7657: $displaydiv{$access} = 'inline';
7658: if (ref($settings{$role}{$access}) eq 'ARRAY') {
7659: $selected{$access} = $settings{$role}{$access};
7660: }
7661: } elsif ($settings{$role}{'access'} =~ /^(inc|exc)$/) {
7662: my $access = $1;
7663: $displaydiv{$access} = 'inline';
7664: if (ref($settings{$role}{$access}) eq 'ARRAY') {
7665: $selected{$access} = $settings{$role}{$access};
7666: }
7667: } elsif ($settings{$role}{'access'} eq 'none') {
7668: $displaydiv{'priv'} = 'none';
7669: }
7670: }
7671: } else {
7672: $indomcheck = ' checked="checked"';
7673: $indomvis = ' style="display:block"';
7674: $incrsvis = ' style="display:none"';
7675: }
7676: } else {
7677: $indomcheck = ' checked="checked"';
1.430 raeburn 7678: $indomvis = ' style="display:block"';
1.428 raeburn 7679: $incrsvis = ' style="display:none"';
7680: }
7681: $r->print('<div class="LC_left_float" id="'.$role.'_maindiv"'.$visibility{$role}.'>'.
7682: '<fieldset><legend>'.$lt{'rou'}.'</legend>'.
7683: '<p>'.$lt{'whi'}.' <span class="LC_nobreak">'.
7684: '<label><input type="radio" name="'.$role.'_incrs" value="1"'.$incrscheck.' onclick="toggleAccess('."'$role'".');"'.$disabled.'>'.
7685: &mt('Set here in [_1]',lc($crstype)).'</label>'.
7686: '<span>'.(' 'x2).
7687: '<label><input type="radio" name="'.$role.'_incrs" value="0"'.$indomcheck.' onclick="toggleAccess('."'$role'".');"'.$disabled.'>'.
7688: $lt{'udd'}.'</label><span></p>'.
7689: '<div id="'.$role.'_setindom"'.$indomvis.'>'.
7690: '<span class="LC_cusr_emph">'.$domusage{$role}.'</span></div>'.
7691: '<div id="'.$role.'_setincrs"'.$incrsvis.'>');
7692: foreach my $access (@accesstypes) {
7693: $r->print('<p><label><input type="radio" name="'.$role.'_access" value="'.$access.'" '.$usecheck{$access}.
7694: ' onclick="helpdeskAccess('."'$role'".');"'.$disabled.' />'.$lt{$access}.'</label>');
7695: if ($access eq 'status') {
7696: $r->print('<div id="'.$role.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
7697: &Apache::lonuserutils::adhoc_status_types($cdom,undef,$role,$selected{$access},
7698: $othertitle,$usertypes,$types,$disabled).
7699: '</div>');
7700: } elsif (($access eq 'inc') && (keys(%domhelpdesk) > 0)) {
7701: $r->print('<div id="'.$role.'_notinc" style="display:'.$displaydiv{$access}.'">'.
7702: &Apache::lonuserutils::adhoc_staff($access,undef,$role,$selected{$access},
7703: \%domhelpdesk,$disabled).
7704: '</div>');
7705: } elsif (($access eq 'exc') && (keys(%domhelpdesk) > 0)) {
7706: $r->print('<div id="'.$role.'_notexc" style="display:'.$displaydiv{$access}.'">'.
7707: &Apache::lonuserutils::adhoc_staff($access,undef,$role,$selected{$access},
7708: \%domhelpdesk,$disabled).
7709: '</div>');
7710: }
7711: $r->print('</p>');
7712: }
7713: $r->print('</div></fieldset>');
7714: my %full=();
7715: my %levels= (
7716: course => {},
7717: domain => {},
7718: system => {},
7719: );
7720: my %levelscurrent=(
7721: course => {},
7722: domain => {},
7723: system => {},
7724: );
7725: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
7726: $r->print('<fieldset id="'.$role.'_privs" style="display:'.$displaydiv{'priv'}.'">'.
7727: '<legend>'.$lt{'rpr'}.'</legend>'.
7728: &role_priv_table($role,$permission,$crstype,\%full,\%levels,\%levelscurrent,$overridden{$role}).
7729: '</fieldset></div><div style="padding:0;clear:both;margin:0;border:0"></div>');
7730: }
1.429 raeburn 7731: if ($permission->{'owner'}) {
7732: $r->print('<p><input type="submit" value="'.&mt('Save changes').'" /></p>');
7733: }
1.428 raeburn 7734: } else {
7735: $r->print(&mt('Helpdesk roles have not yet been created in this domain.'));
7736: }
7737: # Form Footer
7738: $r->print('<input type="hidden" name="action" value="helpdesk" />'
7739: .'</form>');
7740: return;
7741: }
7742:
7743: sub domain_adhoc_access {
7744: my ($roles,$domcurrent,$accesstypes,$usertypes,$othertitle) = @_;
7745: my %domusage;
7746: return unless ((ref($roles) eq 'HASH') && (ref($domcurrent) eq 'HASH') && (ref($accesstypes) eq 'ARRAY'));
7747: foreach my $role (keys(%{$roles})) {
7748: if (ref($domcurrent->{$role}) eq 'HASH') {
7749: my $access = $domcurrent->{$role}{'access'};
7750: if (($access eq '') || (!grep(/^\Q$access\E$/,@{$accesstypes}))) {
7751: $access = 'all';
1.432 raeburn 7752: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role',&Apache::lonnet::plaintext('dh'),
7753: &Apache::lonnet::plaintext('da'));
1.428 raeburn 7754: } elsif ($access eq 'status') {
7755: if (ref($domcurrent->{$role}{$access}) eq 'ARRAY') {
7756: my @shown;
7757: foreach my $type (@{$domcurrent->{$role}{$access}}) {
7758: unless ($type eq 'default') {
7759: if ($usertypes->{$type}) {
7760: push(@shown,$usertypes->{$type});
7761: }
7762: }
7763: }
7764: if (grep(/^default$/,@{$domcurrent->{$role}{$access}})) {
7765: push(@shown,$othertitle);
7766: }
7767: if (@shown) {
7768: my $shownstatus = join(' '.&mt('or').' ',@shown);
1.432 raeburn 7769: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role, and institutional status: [_3]',
7770: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'),$shownstatus);
1.428 raeburn 7771: } else {
7772: $domusage{$role} = &mt('No one in the domain');
7773: }
7774: }
7775: } elsif ($access eq 'inc') {
7776: my @dominc = ();
7777: if (ref($domcurrent->{$role}{'inc'}) eq 'ARRAY') {
7778: foreach my $user (@{$domcurrent->{$role}{'inc'}}) {
7779: my ($uname,$udom) = split(/:/,$user);
7780: push(@dominc,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),$uname,$udom));
7781: }
7782: my $showninc = join(', ',@dominc);
7783: if ($showninc ne '') {
1.432 raeburn 7784: $domusage{$role} = &mt('Include any user in domain with active [_1] or [_2] role, except: [_3]',
7785: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'),$showninc);
1.428 raeburn 7786: } else {
1.432 raeburn 7787: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role',
7788: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'));
1.428 raeburn 7789: }
7790: }
7791: } elsif ($access eq 'exc') {
7792: my @domexc = ();
7793: if (ref($domcurrent->{$role}{'exc'}) eq 'ARRAY') {
7794: foreach my $user (@{$domcurrent->{$role}{'exc'}}) {
7795: my ($uname,$udom) = split(/:/,$user);
7796: push(@domexc,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),$uname,$udom));
7797: }
7798: }
7799: my $shownexc = join(', ',@domexc);
7800: if ($shownexc ne '') {
1.432 raeburn 7801: $domusage{$role} = &mt('Only the following in the domain with active [_1] or [_2] role: [_3]',
7802: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'),$shownexc);
1.428 raeburn 7803: } else {
7804: $domusage{$role} = &mt('No one in the domain');
7805: }
7806: } elsif ($access eq 'none') {
7807: $domusage{$role} = &mt('No one in the domain');
1.434 raeburn 7808: } elsif ($access eq 'dh') {
1.433 raeburn 7809: $domusage{$role} = &mt('Any user in domain with active [_1] role',&Apache::lonnet::plaintext('dh'));
1.434 raeburn 7810: } elsif ($access eq 'da') {
1.433 raeburn 7811: $domusage{$role} = &mt('Any user in domain with active [_1] role',&Apache::lonnet::plaintext('da'));
1.428 raeburn 7812: } elsif ($access eq 'all') {
1.432 raeburn 7813: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role',
7814: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'));
1.428 raeburn 7815: }
7816: } else {
1.432 raeburn 7817: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role',
7818: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'));
1.428 raeburn 7819: }
7820: }
7821: return %domusage;
7822: }
7823:
7824: sub get_domain_customroles {
7825: my ($cdom,$confname) = @_;
7826: my %existing=&Apache::lonnet::dump('roles',$cdom,$confname,'rolesdef_');
7827: my %customroles;
7828: foreach my $key (keys(%existing)) {
7829: if ($key=~/^rolesdef\_(\w+)$/) {
7830: my $rolename = $1;
7831: my %privs;
7832: ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
7833: $customroles{$rolename} = \%privs;
7834: }
7835: }
7836: return %customroles;
7837: }
7838:
7839: sub role_priv_table {
7840: my ($role,$permission,$crstype,$full,$levels,$levelscurrent,$overridden) = @_;
7841: return unless ((ref($full) eq 'HASH') && (ref($levels) eq 'HASH') &&
7842: (ref($levelscurrent) eq 'HASH'));
7843: my %lt=&Apache::lonlocal::texthash (
7844: 'crl' => 'Course Level Privilege',
7845: 'def' => 'Domain Defaults',
7846: 'ove' => 'Override in Course',
7847: 'ine' => 'In effect',
7848: 'dis' => 'Disabled',
7849: 'ena' => 'Enabled',
7850: );
7851: if ($crstype eq 'Community') {
7852: $lt{'ove'} = 'Override in Community',
7853: }
7854: my @status = ('Disabled','Enabled');
7855: my (%on,%off);
7856: if (ref($overridden) eq 'HASH') {
7857: if (ref($overridden->{'on'}) eq 'ARRAY') {
7858: map { $on{$_} = 1; } (@{$overridden->{'on'}});
7859: }
7860: if (ref($overridden->{'off'}) eq 'ARRAY') {
7861: map { $off{$_} = 1; } (@{$overridden->{'off'}});
7862: }
7863: }
7864: my $output=&Apache::loncommon::start_data_table().
7865: &Apache::loncommon::start_data_table_header_row().
7866: '<th>'.$lt{'crl'}.'</th><th>'.$lt{'def'}.'</th><th>'.$lt{'ove'}.
7867: '</th><th>'.$lt{'ine'}.'</th>'.
7868: &Apache::loncommon::end_data_table_header_row();
7869: foreach my $priv (sort(keys(%{$full}))) {
7870: next unless ($levels->{'course'}{$priv});
7871: my $privtext = &Apache::lonnet::plaintext($priv,$crstype);
7872: my ($default,$ineffect);
7873: if ($levelscurrent->{'course'}{$priv}) {
7874: $default = '<img src="/adm/lonIcons/navmap.correct.gif" alt="'.$lt{'ena'}.'" />';
7875: $ineffect = $default;
7876: }
7877: my ($customstatus,$checked);
7878: $output .= &Apache::loncommon::start_data_table_row().
7879: '<td>'.$privtext.'</td>'.
7880: '<td>'.$default.'</td><td>';
7881: if (($levelscurrent->{'course'}{$priv}) && ($off{$priv})) {
7882: if ($permission->{'owner'}) {
7883: $checked = ' checked="checked"';
7884: }
7885: $customstatus = '<img src="/adm/lonIcons/navmap.wrong.gif" alt="'.$lt{'dis'}.'" />';
1.430 raeburn 7886: $ineffect = $customstatus;
1.428 raeburn 7887: } elsif ((!$levelscurrent->{'course'}{$priv}) && ($on{$priv})) {
7888: if ($permission->{'owner'}) {
1.430 raeburn 7889: $checked = ' checked="checked"';
1.428 raeburn 7890: }
7891: $customstatus = '<img src="/adm/lonIcons/navmap.correct.gif" alt="'.$lt{'ena'}.'" />';
1.430 raeburn 7892: $ineffect = $customstatus;
1.428 raeburn 7893: }
7894: if ($permission->{'owner'}) {
7895: $output .= '<input type="checkbox" name="'.$role.'_override" value="'.$priv.'"'.$checked.' />';
7896: } else {
7897: $output .= $customstatus;
7898: }
7899: $output .= '</td><td>'.$ineffect.'</td>'.
7900: &Apache::loncommon::end_data_table_row();
7901: }
7902: $output .= &Apache::loncommon::end_data_table();
7903: return $output;
7904: }
7905:
7906: sub get_adhocrole_settings {
1.430 raeburn 7907: my ($cid,$accesstypes,$types,$customroles,$settings,$overridden) = @_;
1.428 raeburn 7908: return unless ((ref($accesstypes) eq 'ARRAY') && (ref($customroles) eq 'HASH') &&
7909: (ref($settings) eq 'HASH') && (ref($overridden) eq 'HASH'));
7910: foreach my $role (split(/,/,$env{'course.'.$cid.'.internal.adhocaccess'})) {
7911: my ($curraccess,$rest) = split(/=/,$env{'course.'.$cid.'.internal.adhoc.'.$role});
7912: if (($curraccess ne '') && (grep(/^\Q$curraccess\E$/,@{$accesstypes}))) {
7913: $settings->{$role}{'access'} = $curraccess;
7914: if (($curraccess eq 'status') && (ref($types) eq 'ARRAY')) {
7915: my @status = split(/,/,$rest);
7916: my @currstatus;
7917: foreach my $type (@status) {
7918: if ($type eq 'default') {
7919: push(@currstatus,$type);
7920: } elsif (grep(/^\Q$type\E$/,@{$types})) {
7921: push(@currstatus,$type);
7922: }
7923: }
7924: if (@currstatus) {
7925: $settings->{$role}{$curraccess} = \@currstatus;
7926: } elsif (($curraccess eq 'exc') || ($curraccess eq 'inc')) {
7927: my @personnel = split(/,/,$rest);
7928: $settings->{$role}{$curraccess} = \@personnel;
7929: }
7930: }
7931: }
7932: }
7933: foreach my $role (keys(%{$customroles})) {
7934: if ($env{'course.'.$cid.'.internal.adhocpriv.'.$role}) {
7935: my %currentprivs;
7936: if (ref($customroles->{$role}) eq 'HASH') {
7937: if (exists($customroles->{$role}{'course'})) {
7938: my %full=();
7939: my %levels= (
7940: course => {},
7941: domain => {},
7942: system => {},
7943: );
7944: my %levelscurrent=(
7945: course => {},
7946: domain => {},
7947: system => {},
7948: );
7949: &Apache::lonuserutils::custom_role_privs($customroles->{$role},\%full,\%levels,\%levelscurrent);
7950: %currentprivs = %{$levelscurrent{'course'}};
7951: }
7952: }
7953: foreach my $item (split(/,/,$env{'course.'.$cid.'.internal.adhocpriv.'.$role})) {
7954: next if ($item eq '');
7955: my ($rule,$rest) = split(/=/,$item);
7956: next unless (($rule eq 'off') || ($rule eq 'on'));
7957: foreach my $priv (split(/:/,$rest)) {
7958: if ($priv ne '') {
7959: if ($rule eq 'off') {
7960: push(@{$overridden->{$role}{'off'}},$priv);
7961: if ($currentprivs{$priv}) {
7962: push(@{$settings->{$role}{'off'}},$priv);
7963: }
7964: } else {
7965: push(@{$overridden->{$role}{'on'}},$priv);
7966: unless ($currentprivs{$priv}) {
7967: push(@{$settings->{$role}{'on'}},$priv);
7968: }
7969: }
7970: }
7971: }
7972: }
7973: }
7974: }
7975: return;
7976: }
7977:
7978: sub update_helpdeskaccess {
7979: my ($r,$permission,$brcrum) = @_;
7980: my $helpitem = 'Course_Helpdesk_Access';
7981: push (@{$brcrum},
7982: {href => '/adm/createuser?action=helpdesk',
7983: text => 'Helpdesk Access',
7984: help => $helpitem},
7985: {href => '/adm/createuser?action=helpdesk',
7986: text => 'Result',
7987: help => $helpitem}
7988: );
7989: my $bread_crumbs_component = 'Helpdesk Staff Access';
7990: my $args = { bread_crumbs => $brcrum,
7991: bread_crumbs_component => $bread_crumbs_component};
7992:
7993: # print page header
7994: $r->print(&header('',$args));
7995: unless ((ref($permission) eq 'HASH') && ($permission->{'owner'})) {
7996: $r->print('<p class="LC_error">'.&mt('You do not have permission to change helpdesk access.').'</p>');
7997: return;
7998: }
1.434 raeburn 7999: my @accesstypes = ('all','dh','da','none','status','inc','exc');
1.428 raeburn 8000: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
8001: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
8002: my $confname = $cdom.'-domainconfig';
8003: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($cdom);
8004: my $crstype = &Apache::loncommon::course_type();
8005: my %customroles = &get_domain_customroles($cdom,$confname);
8006: my (%settings,%overridden);
8007: &get_adhocrole_settings($env{'request.course.id'},\@accesstypes,
8008: $types,\%customroles,\%settings,\%overridden);
1.432 raeburn 8009: my %domhelpdesk = &Apache::lonnet::get_active_domroles($cdom,['dh','da']);
1.428 raeburn 8010: my (%changed,%storehash,@todelete);
8011:
8012: if (keys(%customroles)) {
8013: my (%newsettings,@incrs);
8014: foreach my $role (keys(%customroles)) {
8015: $newsettings{$role} = {
8016: access => '',
8017: status => '',
8018: exc => '',
8019: inc => '',
8020: on => '',
8021: off => '',
8022: };
8023: my %current;
8024: if (ref($settings{$role}) eq 'HASH') {
8025: %current = %{$settings{$role}};
8026: }
8027: if (ref($overridden{$role}) eq 'HASH') {
8028: $current{'overridden'} = $overridden{$role};
8029: }
8030: if ($env{'form.'.$role.'_incrs'}) {
8031: my $access = $env{'form.'.$role.'_access'};
8032: if (grep(/^\Q$access\E$/,@accesstypes)) {
8033: push(@incrs,$role);
8034: unless ($current{'access'} eq $access) {
8035: $changed{$role}{'access'} = 1;
1.430 raeburn 8036: $storehash{'internal.adhoc.'.$role} = $access;
1.428 raeburn 8037: }
8038: if ($access eq 'status') {
8039: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$role.'_status');
8040: my @stored;
8041: my @shownstatus;
8042: if (ref($types) eq 'ARRAY') {
8043: foreach my $type (sort(@statuses)) {
8044: if ($type eq 'default') {
8045: push(@stored,$type);
8046: } elsif (grep(/^\Q$type\E$/,@{$types})) {
8047: push(@stored,$type);
8048: push(@shownstatus,$usertypes->{$type});
8049: }
8050: }
8051: if (grep(/^default$/,@statuses)) {
8052: push(@shownstatus,$othertitle);
8053: }
8054: $storehash{'internal.adhoc.'.$role} .= '='.join(',',@stored);
8055: }
8056: $newsettings{$role}{'status'} = join(' '.&mt('or').' ',@shownstatus);
8057: if (ref($current{'status'}) eq 'ARRAY') {
8058: my @diffs = &Apache::loncommon::compare_arrays(\@stored,$current{'status'});
8059: if (@diffs) {
8060: $changed{$role}{'status'} = 1;
8061: }
8062: } elsif (@stored) {
8063: $changed{$role}{'status'} = 1;
8064: }
8065: } elsif (($access eq 'inc') || ($access eq 'exc')) {
8066: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$role.'_staff_'.$access);
8067: my @newspecstaff;
8068: my @stored;
8069: my @currstaff;
8070: foreach my $person (sort(@personnel)) {
8071: if ($domhelpdesk{$person}) {
1.430 raeburn 8072: push(@stored,$person);
1.428 raeburn 8073: }
8074: }
8075: if (ref($current{$access}) eq 'ARRAY') {
8076: my @diffs = &Apache::loncommon::compare_arrays(\@stored,$current{$access});
8077: if (@diffs) {
8078: $changed{$role}{$access} = 1;
8079: }
8080: } elsif (@stored) {
8081: $changed{$role}{$access} = 1;
8082: }
8083: $storehash{'internal.adhoc.'.$role} .= '='.join(',',@stored);
8084: foreach my $person (@stored) {
8085: my ($uname,$udom) = split(/:/,$person);
8086: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
8087: }
8088: $newsettings{$role}{$access} = join(', ',sort(@newspecstaff));
8089: }
8090: $newsettings{$role}{'access'} = $access;
8091: }
8092: } else {
8093: if (($current{'access'} ne '') && (grep(/^\Q$current{'access'}\E$/,@accesstypes))) {
8094: $changed{$role}{'access'} = 1;
8095: $newsettings{$role} = {};
8096: push(@todelete,'internal.adhoc.'.$role);
8097: }
8098: }
8099: if (($env{'form.'.$role.'_incrs'}) && ($env{'form.'.$role.'_access'} eq 'none')) {
8100: if (ref($current{'overridden'}) eq 'HASH') {
8101: push(@todelete,'internal.adhocpriv.'.$role);
8102: }
8103: } else {
8104: my %full=();
8105: my %levels= (
8106: course => {},
8107: domain => {},
8108: system => {},
8109: );
8110: my %levelscurrent=(
8111: course => {},
8112: domain => {},
8113: system => {},
8114: );
8115: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
8116: my (@updatedon,@updatedoff,@override);
8117: @override = &Apache::loncommon::get_env_multiple('form.'.$role.'_override');
1.430 raeburn 8118: if (@override) {
1.428 raeburn 8119: foreach my $priv (sort(keys(%full))) {
8120: next unless ($levels{'course'}{$priv});
8121: if (grep(/^\Q$priv\E$/,@override)) {
8122: if ($levelscurrent{'course'}{$priv}) {
8123: push(@updatedoff,$priv);
8124: } else {
8125: push(@updatedon,$priv);
8126: }
8127: }
8128: }
8129: }
8130: if (@updatedon) {
1.430 raeburn 8131: $newsettings{$role}{'on'} = join('</li><li>', map { &Apache::lonnet::plaintext($_,$crstype) } (@updatedon));
1.428 raeburn 8132: }
8133: if (@updatedoff) {
8134: $newsettings{$role}{'off'} = join('</li><li>', map { &Apache::lonnet::plaintext($_,$crstype) } (@updatedoff));
8135: }
8136: if (ref($current{'overridden'}) eq 'HASH') {
8137: if (ref($current{'overridden'}{'on'}) eq 'ARRAY') {
8138: if (@updatedon) {
8139: my @diffs = &Apache::loncommon::compare_arrays(\@updatedon,$current{'overridden'}{'on'});
8140: if (@diffs) {
8141: $changed{$role}{'on'} = 1;
8142: }
8143: } else {
8144: $changed{$role}{'on'} = 1;
8145: }
8146: } elsif (@updatedon) {
8147: $changed{$role}{'on'} = 1;
8148: }
8149: if (ref($current{'overridden'}{'off'}) eq 'ARRAY') {
8150: if (@updatedoff) {
8151: my @diffs = &Apache::loncommon::compare_arrays(\@updatedoff,$current{'overridden'}{'off'});
8152: if (@diffs) {
8153: $changed{$role}{'off'} = 1;
8154: }
8155: } else {
8156: $changed{$role}{'off'} = 1;
8157: }
8158: } elsif (@updatedoff) {
8159: $changed{$role}{'off'} = 1;
8160: }
8161: } else {
8162: if (@updatedon) {
8163: $changed{$role}{'on'} = 1;
8164: }
8165: if (@updatedoff) {
8166: $changed{$role}{'off'} = 1;
8167: }
8168: }
8169: if (ref($changed{$role}) eq 'HASH') {
8170: if (($changed{$role}{'on'} || $changed{$role}{'off'})) {
8171: my $newpriv;
8172: if (@updatedon) {
8173: $newpriv = 'on='.join(':',@updatedon);
8174: }
8175: if (@updatedoff) {
8176: $newpriv .= ($newpriv ? ',' : '' ).'off='.join(':',@updatedoff);
8177: }
8178: if ($newpriv eq '') {
8179: push(@todelete,'internal.adhocpriv.'.$role);
8180: } else {
8181: $storehash{'internal.adhocpriv.'.$role} = $newpriv;
8182: }
8183: }
8184: }
8185: }
8186: }
8187: if (@incrs) {
8188: $storehash{'internal.adhocaccess'} = join(',',@incrs);
8189: } elsif (@todelete) {
8190: push(@todelete,'internal.adhocaccess');
8191: }
8192: if (keys(%changed)) {
8193: my ($putres,$delres);
8194: if (keys(%storehash)) {
8195: $putres = &Apache::lonnet::put('environment',\%storehash,$cdom,$cnum);
8196: my %newenvhash;
8197: foreach my $key (keys(%storehash)) {
8198: $newenvhash{'course.'.$env{'request.course.id'}.'.'.$key} = $storehash{$key};
8199: }
8200: &Apache::lonnet::appenv(\%newenvhash);
8201: }
8202: if (@todelete) {
8203: $delres = &Apache::lonnet::del('environment',\@todelete,$cdom,$cnum);
8204: foreach my $key (@todelete) {
8205: &Apache::lonnet::delenv('course.'.$env{'request.course.id'}.'.'.$key);
8206: }
8207: }
8208: if (($putres eq 'ok') || ($delres eq 'ok')) {
8209: my %domconfig = &Apache::lonnet::get_dom('configuration',['helpsettings'],$cdom);
8210: my (%domcurrent,%ordered,%description,%domusage);
8211: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
8212: if (ref($domconfig{'helpsettings'}{'adhoc'}) eq 'HASH') {
8213: %domcurrent = %{$domconfig{'helpsettings'}{'adhoc'}};
8214: }
8215: }
8216: my $count = 0;
8217: foreach my $role (sort(keys(%customroles))) {
8218: my ($order,$desc);
8219: if (ref($domcurrent{$role}) eq 'HASH') {
8220: $order = $domcurrent{$role}{'order'};
8221: $desc = $domcurrent{$role}{'desc'};
8222: }
8223: if ($order eq '') {
8224: $order = $count;
8225: }
8226: $ordered{$order} = $role;
8227: if ($desc ne '') {
8228: $description{$role} = $desc;
8229: } else {
8230: $description{$role}= $role;
8231: }
8232: $count++;
8233: }
8234: my @roles_by_num = ();
8235: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
8236: push(@roles_by_num,$ordered{$item});
8237: }
8238: %domusage = &domain_adhoc_access(\%changed,\%domcurrent,\@accesstypes,$usertypes,$othertitle);
1.430 raeburn 8239: $r->print(&mt('Helpdesk access settings have been changed as follows').'<br />');
1.428 raeburn 8240: $r->print('<ul>');
8241: foreach my $role (@roles_by_num) {
8242: next unless (ref($changed{$role}) eq 'HASH');
8243: $r->print('<li>'.&mt('Ad hoc role').': <b>'.$description{$role}.'</b>'.
8244: '<ul>');
1.430 raeburn 8245: if ($changed{$role}{'access'} || $changed{$role}{'status'} || $changed{$role}{'inc'} || $changed{$role}{'exc'}) {
1.428 raeburn 8246: $r->print('<li>');
8247: if ($env{'form.'.$role.'_incrs'}) {
8248: if ($newsettings{$role}{'access'} eq 'all') {
8249: $r->print(&mt('All helpdesk staff can access '.lc($crstype).' with this role.'));
1.434 raeburn 8250: } elsif ($newsettings{$role}{'access'} eq 'dh') {
1.433 raeburn 8251: $r->print(&mt('Helpdesk staff can use this role if they have an active [_1] role',
8252: &Apache::lonnet::plaintext('dh')));
1.434 raeburn 8253: } elsif ($newsettings{$role}{'access'} eq 'da') {
1.433 raeburn 8254: $r->print(&mt('Helpdesk staff can use this role if they have an active [_1] role',
8255: &Apache::lonnet::plaintext('da')));
1.428 raeburn 8256: } elsif ($newsettings{$role}{'access'} eq 'none') {
8257: $r->print(&mt('No helpdesk staff can access '.lc($crstype).' with this role.'));
8258: } elsif ($newsettings{$role}{'access'} eq 'status') {
8259: if ($newsettings{$role}{'status'}) {
8260: my ($access,$rest) = split(/=/,$storehash{'internal.adhoc.'.$role});
1.430 raeburn 8261: if (split(/,/,$rest) > 1) {
1.428 raeburn 8262: $r->print(&mt('Helpdesk staff can use this role if their institutional type is one of: [_1].',
8263: $newsettings{$role}{'status'}));
8264: } else {
8265: $r->print(&mt('Helpdesk staff can use this role if their institutional type is: [_1].',
8266: $newsettings{$role}{'status'}));
8267: }
8268: } else {
8269: $r->print(&mt('No helpdesk staff can access '.lc($crstype).' with this role.'));
8270: }
8271: } elsif ($newsettings{$role}{'access'} eq 'exc') {
8272: if ($newsettings{$role}{'exc'}) {
8273: $r->print(&mt('Helpdesk staff who can use this role are as follows:').' '.$newsettings{$role}{'exc'}.'.');
8274: } else {
8275: $r->print(&mt('No helpdesk staff can access '.lc($crstype).' with this role.'));
8276: }
8277: } elsif ($newsettings{$role}{'access'} eq 'inc') {
8278: if ($newsettings{$role}{'inc'}) {
8279: $r->print(&mt('All helpdesk staff may use this role except the following:').' '.$newsettings{$role}{'inc'}.'.');
8280: } else {
8281: $r->print(&mt('All helpdesk staff may use this role.'));
8282: }
8283: }
8284: } else {
8285: $r->print(&mt('Default access set in the domain now applies.').'<br />'.
8286: '<span class="LC_cusr_emph">'.$domusage{$role}.'</span>');
8287: }
8288: $r->print('</li>');
8289: }
8290: unless ($newsettings{$role}{'access'} eq 'none') {
8291: if ($changed{$role}{'off'}) {
8292: if ($newsettings{$role}{'off'}) {
8293: $r->print('<li>'.&mt('Privileges which are available by default for this ad hoc role, but are disabled for this specific '.lc($crstype).':').
8294: '<ul><li>'.$newsettings{$role}{'off'}.'</li></ul></li>');
8295: } else {
1.430 raeburn 8296: $r->print('<li>'.&mt('All privileges available by default for this ad hoc role are enabled.').'</li>');
1.428 raeburn 8297: }
8298: }
1.430 raeburn 8299: if ($changed{$role}{'on'}) {
1.428 raeburn 8300: if ($newsettings{$role}{'on'}) {
8301: $r->print('<li>'.&mt('Privileges which are not available by default for this ad hoc role, but are enabled for this specific '.lc($crstype).':').
8302: '<ul><li>'.$newsettings{$role}{'on'}.'</li></ul></li>');
8303: } else {
1.430 raeburn 8304: $r->print('<li>'.&mt('None of the privileges unavailable by default for this ad hoc role are enabled.').'</li>');
1.428 raeburn 8305: }
8306: }
8307: }
8308: $r->print('</ul></li>');
8309: }
8310: $r->print('</ul>');
8311: }
8312: } else {
1.430 raeburn 8313: $r->print(&mt('No changes made to helpdesk access settings.'));
1.428 raeburn 8314: }
8315: }
8316: return;
8317: }
8318:
1.27 matthew 8319: #-------------------------------------------------- functions for &phase_two
1.160 raeburn 8320: sub user_search_result {
1.221 raeburn 8321: my ($context,$srch) = @_;
1.160 raeburn 8322: my %allhomes;
8323: my %inst_matches;
8324: my %srch_results;
1.181 raeburn 8325: my ($response,$currstate,$forcenewuser,$dirsrchres);
1.183 raeburn 8326: $srch->{'srchterm'} =~ s/\s+/ /g;
1.176 raeburn 8327: if ($srch->{'srchby'} !~ /^(uname|lastname|lastfirst)$/) {
1.160 raeburn 8328: $response = &mt('Invalid search.');
8329: }
8330: if ($srch->{'srchin'} !~ /^(crs|dom|alc|instd)$/) {
8331: $response = &mt('Invalid search.');
8332: }
1.177 raeburn 8333: if ($srch->{'srchtype'} !~ /^(exact|contains|begins)$/) {
1.160 raeburn 8334: $response = &mt('Invalid search.');
8335: }
8336: if ($srch->{'srchterm'} eq '') {
8337: $response = &mt('You must enter a search term.');
8338: }
1.183 raeburn 8339: if ($srch->{'srchterm'} =~ /^\s+$/) {
8340: $response = &mt('Your search term must contain more than just spaces.');
8341: }
1.160 raeburn 8342: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'instd')) {
8343: if (($srch->{'srchdomain'} eq '') ||
1.163 albertel 8344: ! (&Apache::lonnet::domain($srch->{'srchdomain'}))) {
1.160 raeburn 8345: $response = &mt('You must specify a valid domain when searching in a domain or institutional directory.')
8346: }
8347: }
8348: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs') ||
8349: ($srch->{'srchin'} eq 'alc')) {
1.176 raeburn 8350: if ($srch->{'srchby'} eq 'uname') {
1.243 raeburn 8351: my $unamecheck = $srch->{'srchterm'};
8352: if ($srch->{'srchtype'} eq 'contains') {
8353: if ($unamecheck !~ /^\w/) {
8354: $unamecheck = 'a'.$unamecheck;
8355: }
8356: }
8357: if ($unamecheck !~ /^$match_username$/) {
1.176 raeburn 8358: $response = &mt('You must specify a valid username. Only the following are allowed: letters numbers - . @');
8359: }
1.160 raeburn 8360: }
8361: }
1.180 raeburn 8362: if ($response ne '') {
1.413 raeburn 8363: $response = '<span class="LC_warning">'.$response.'</span><br />';
1.180 raeburn 8364: }
1.160 raeburn 8365: if ($srch->{'srchin'} eq 'instd') {
1.412 raeburn 8366: my $instd_chk = &instdirectorysrch_check($srch);
1.160 raeburn 8367: if ($instd_chk ne 'ok') {
1.412 raeburn 8368: my $domd_chk = &domdirectorysrch_check($srch);
1.413 raeburn 8369: $response .= '<span class="LC_warning">'.$instd_chk.'</span><br />';
1.412 raeburn 8370: if ($domd_chk eq 'ok') {
1.435 raeburn 8371: $response .= &mt('You may want to search in the LON-CAPA domain instead of in the institutional directory.');
1.412 raeburn 8372: }
1.415 raeburn 8373: $response .= '<br />';
1.412 raeburn 8374: }
8375: } else {
1.417 raeburn 8376: unless (($context eq 'requestcrs') && ($srch->{'srchtype'} eq 'exact')) {
1.412 raeburn 8377: my $domd_chk = &domdirectorysrch_check($srch);
1.438 raeburn 8378: if (($domd_chk ne 'ok') && ($env{'form.action'} ne 'accesslogs')) {
1.412 raeburn 8379: my $instd_chk = &instdirectorysrch_check($srch);
1.413 raeburn 8380: $response .= '<span class="LC_warning">'.$domd_chk.'</span><br />';
1.412 raeburn 8381: if ($instd_chk eq 'ok') {
1.435 raeburn 8382: $response .= &mt('You may want to search in the institutional directory instead of in the LON-CAPA domain.');
1.412 raeburn 8383: }
1.415 raeburn 8384: $response .= '<br />';
1.412 raeburn 8385: }
1.160 raeburn 8386: }
8387: }
8388: if ($response ne '') {
1.180 raeburn 8389: return ($currstate,$response);
1.160 raeburn 8390: }
8391: if ($srch->{'srchby'} eq 'uname') {
8392: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs')) {
8393: if ($env{'form.forcenew'}) {
8394: if ($srch->{'srchdomain'} ne $env{'request.role.domain'}) {
8395: my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
8396: if ($uhome eq 'no_host') {
8397: my $domdesc = &Apache::lonnet::domain($env{'request.role.domain'},'description');
1.180 raeburn 8398: my $showdom = &display_domain_info($env{'request.role.domain'});
8399: $response = &mt('New users can only be created in the domain to which your current role belongs - [_1].',$showdom);
1.160 raeburn 8400: } else {
1.179 raeburn 8401: $currstate = 'modify';
1.160 raeburn 8402: }
8403: } else {
1.179 raeburn 8404: $currstate = 'modify';
1.160 raeburn 8405: }
8406: } else {
8407: if ($srch->{'srchin'} eq 'dom') {
1.162 raeburn 8408: if ($srch->{'srchtype'} eq 'exact') {
8409: my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
8410: if ($uhome eq 'no_host') {
1.179 raeburn 8411: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8412: &build_search_response($context,$srch,%srch_results);
1.162 raeburn 8413: } else {
1.179 raeburn 8414: $currstate = 'modify';
1.416 raeburn 8415: if ($env{'form.action'} eq 'accesslogs') {
8416: $currstate = 'activity';
8417: }
1.310 raeburn 8418: my $uname = $srch->{'srchterm'};
8419: my $udom = $srch->{'srchdomain'};
8420: $srch_results{$uname.':'.$udom} =
8421: { &Apache::lonnet::get('environment',
8422: ['firstname',
8423: 'lastname',
8424: 'permanentemail'],
8425: $udom,$uname)
8426: };
1.162 raeburn 8427: }
8428: } else {
8429: %srch_results = &Apache::lonnet::usersearch($srch);
1.179 raeburn 8430: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8431: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 8432: }
8433: } else {
1.167 albertel 8434: my $courseusers = &get_courseusers();
1.162 raeburn 8435: if ($srch->{'srchtype'} eq 'exact') {
1.167 albertel 8436: if (exists($courseusers->{$srch->{'srchterm'}.':'.$srch->{'srchdomain'}})) {
1.179 raeburn 8437: $currstate = 'modify';
1.162 raeburn 8438: } else {
1.179 raeburn 8439: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8440: &build_search_response($context,$srch,%srch_results);
1.162 raeburn 8441: }
1.160 raeburn 8442: } else {
1.167 albertel 8443: foreach my $user (keys(%$courseusers)) {
1.162 raeburn 8444: my ($cuname,$cudomain) = split(/:/,$user);
8445: if ($cudomain eq $srch->{'srchdomain'}) {
1.177 raeburn 8446: my $matched = 0;
8447: if ($srch->{'srchtype'} eq 'begins') {
8448: if ($cuname =~ /^\Q$srch->{'srchterm'}\E/i) {
8449: $matched = 1;
8450: }
8451: } else {
8452: if ($cuname =~ /\Q$srch->{'srchterm'}\E/i) {
8453: $matched = 1;
8454: }
8455: }
8456: if ($matched) {
1.167 albertel 8457: $srch_results{$user} =
8458: {&Apache::lonnet::get('environment',
8459: ['firstname',
8460: 'lastname',
1.194 albertel 8461: 'permanentemail'],
8462: $cudomain,$cuname)};
1.162 raeburn 8463: }
8464: }
8465: }
1.179 raeburn 8466: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8467: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 8468: }
8469: }
8470: }
8471: } elsif ($srch->{'srchin'} eq 'alc') {
1.179 raeburn 8472: $currstate = 'query';
1.160 raeburn 8473: } elsif ($srch->{'srchin'} eq 'instd') {
1.181 raeburn 8474: ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
8475: if ($dirsrchres eq 'ok') {
8476: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8477: &build_search_response($context,$srch,%srch_results);
1.181 raeburn 8478: } else {
8479: my $showdom = &display_domain_info($srch->{'srchdomain'});
8480: $response = '<span class="LC_warning">'.
8481: &mt('Institutional directory search is not available in domain: [_1]',$showdom).
8482: '</span><br />'.
1.435 raeburn 8483: &mt('You may want to search in the LON-CAPA domain instead of in the institutional directory.').
1.415 raeburn 8484: '<br />';
1.181 raeburn 8485: }
1.160 raeburn 8486: }
8487: } else {
8488: if ($srch->{'srchin'} eq 'dom') {
8489: %srch_results = &Apache::lonnet::usersearch($srch);
1.179 raeburn 8490: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8491: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 8492: } elsif ($srch->{'srchin'} eq 'crs') {
1.167 albertel 8493: my $courseusers = &get_courseusers();
8494: foreach my $user (keys(%$courseusers)) {
1.160 raeburn 8495: my ($uname,$udom) = split(/:/,$user);
8496: my %names = &Apache::loncommon::getnames($uname,$udom);
8497: my %emails = &Apache::loncommon::getemails($uname,$udom);
8498: if ($srch->{'srchby'} eq 'lastname') {
8499: if ((($srch->{'srchtype'} eq 'exact') &&
8500: ($names{'lastname'} eq $srch->{'srchterm'})) ||
1.177 raeburn 8501: (($srch->{'srchtype'} eq 'begins') &&
8502: ($names{'lastname'} =~ /^\Q$srch->{'srchterm'}\E/i)) ||
1.160 raeburn 8503: (($srch->{'srchtype'} eq 'contains') &&
8504: ($names{'lastname'} =~ /\Q$srch->{'srchterm'}\E/i))) {
8505: $srch_results{$user} = {firstname => $names{'firstname'},
8506: lastname => $names{'lastname'},
8507: permanentemail => $emails{'permanentemail'},
8508: };
8509: }
8510: } elsif ($srch->{'srchby'} eq 'lastfirst') {
8511: my ($srchlast,$srchfirst) = split(/,/,$srch->{'srchterm'});
1.177 raeburn 8512: $srchlast =~ s/\s+$//;
8513: $srchfirst =~ s/^\s+//;
1.160 raeburn 8514: if ($srch->{'srchtype'} eq 'exact') {
8515: if (($names{'lastname'} eq $srchlast) &&
8516: ($names{'firstname'} eq $srchfirst)) {
8517: $srch_results{$user} = {firstname => $names{'firstname'},
8518: lastname => $names{'lastname'},
8519: permanentemail => $emails{'permanentemail'},
8520:
8521: };
8522: }
1.177 raeburn 8523: } elsif ($srch->{'srchtype'} eq 'begins') {
8524: if (($names{'lastname'} =~ /^\Q$srchlast\E/i) &&
8525: ($names{'firstname'} =~ /^\Q$srchfirst\E/i)) {
8526: $srch_results{$user} = {firstname => $names{'firstname'},
8527: lastname => $names{'lastname'},
8528: permanentemail => $emails{'permanentemail'},
8529: };
8530: }
8531: } else {
1.160 raeburn 8532: if (($names{'lastname'} =~ /\Q$srchlast\E/i) &&
8533: ($names{'firstname'} =~ /\Q$srchfirst\E/i)) {
8534: $srch_results{$user} = {firstname => $names{'firstname'},
8535: lastname => $names{'lastname'},
8536: permanentemail => $emails{'permanentemail'},
8537: };
8538: }
8539: }
8540: }
8541: }
1.179 raeburn 8542: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8543: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 8544: } elsif ($srch->{'srchin'} eq 'alc') {
1.179 raeburn 8545: $currstate = 'query';
1.160 raeburn 8546: } elsif ($srch->{'srchin'} eq 'instd') {
1.181 raeburn 8547: ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
8548: if ($dirsrchres eq 'ok') {
8549: ($currstate,$response,$forcenewuser) =
1.221 raeburn 8550: &build_search_response($context,$srch,%srch_results);
1.181 raeburn 8551: } else {
1.412 raeburn 8552: my $showdom = &display_domain_info($srch->{'srchdomain'});
8553: $response = '<span class="LC_warning">'.
1.181 raeburn 8554: &mt('Institutional directory search is not available in domain: [_1]',$showdom).
8555: '</span><br />'.
1.435 raeburn 8556: &mt('You may want to search in the LON-CAPA domain instead of in the institutional directory.').
1.415 raeburn 8557: '<br />';
1.181 raeburn 8558: }
1.160 raeburn 8559: }
8560: }
1.179 raeburn 8561: return ($currstate,$response,$forcenewuser,\%srch_results);
1.160 raeburn 8562: }
8563:
1.412 raeburn 8564: sub domdirectorysrch_check {
8565: my ($srch) = @_;
8566: my $response;
8567: my %dom_inst_srch = &Apache::lonnet::get_dom('configuration',
8568: ['directorysrch'],$srch->{'srchdomain'});
8569: my $showdom = &display_domain_info($srch->{'srchdomain'});
8570: if (ref($dom_inst_srch{'directorysrch'}) eq 'HASH') {
8571: if ($dom_inst_srch{'directorysrch'}{'lcavailable'} eq '0') {
8572: return &mt('LON-CAPA directory search is not available in domain: [_1]',$showdom);
8573: }
8574: if ($dom_inst_srch{'directorysrch'}{'lclocalonly'}) {
8575: if ($env{'request.role.domain'} ne $srch->{'srchdomain'}) {
8576: return &mt('LON-CAPA directory search in domain: [_1] is only allowed for users with a current role in the domain.',$showdom);
8577: }
8578: }
8579: }
8580: return 'ok';
8581: }
8582:
8583: sub instdirectorysrch_check {
1.160 raeburn 8584: my ($srch) = @_;
8585: my $can_search = 0;
8586: my $response;
8587: my %dom_inst_srch = &Apache::lonnet::get_dom('configuration',
8588: ['directorysrch'],$srch->{'srchdomain'});
1.180 raeburn 8589: my $showdom = &display_domain_info($srch->{'srchdomain'});
1.160 raeburn 8590: if (ref($dom_inst_srch{'directorysrch'}) eq 'HASH') {
8591: if (!$dom_inst_srch{'directorysrch'}{'available'}) {
1.180 raeburn 8592: return &mt('Institutional directory search is not available in domain: [_1]',$showdom);
1.160 raeburn 8593: }
8594: if ($dom_inst_srch{'directorysrch'}{'localonly'}) {
8595: if ($env{'request.role.domain'} ne $srch->{'srchdomain'}) {
1.180 raeburn 8596: return &mt('Institutional directory search in domain: [_1] is only allowed for users with a current role in the domain.',$showdom);
1.160 raeburn 8597: }
8598: my @usertypes = split(/:/,$env{'environment.inststatus'});
8599: if (!@usertypes) {
8600: push(@usertypes,'default');
8601: }
8602: if (ref($dom_inst_srch{'directorysrch'}{'cansearch'}) eq 'ARRAY') {
8603: foreach my $type (@usertypes) {
8604: if (grep(/^\Q$type\E$/,@{$dom_inst_srch{'directorysrch'}{'cansearch'}})) {
8605: $can_search = 1;
8606: last;
8607: }
8608: }
8609: }
8610: if (!$can_search) {
8611: my ($insttypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($srch->{'srchdomain'});
8612: my @longtypes;
8613: foreach my $item (@usertypes) {
1.229 raeburn 8614: if (defined($insttypes->{$item})) {
8615: push (@longtypes,$insttypes->{$item});
8616: } elsif ($item eq 'default') {
8617: push (@longtypes,&mt('other'));
8618: }
1.160 raeburn 8619: }
8620: my $insttype_str = join(', ',@longtypes);
1.180 raeburn 8621: return &mt('Institutional directory search in domain: [_1] is not available to your user type: ',$showdom).$insttype_str;
1.229 raeburn 8622: }
1.160 raeburn 8623: } else {
8624: $can_search = 1;
8625: }
8626: } else {
1.180 raeburn 8627: return &mt('Institutional directory search has not been configured for domain: [_1]',$showdom);
1.160 raeburn 8628: }
8629: my %longtext = &Apache::lonlocal::texthash (
1.167 albertel 8630: uname => 'username',
1.160 raeburn 8631: lastfirst => 'last name, first name',
1.167 albertel 8632: lastname => 'last name',
1.172 raeburn 8633: contains => 'contains',
1.178 raeburn 8634: exact => 'as exact match to',
8635: begins => 'begins with',
1.160 raeburn 8636: );
8637: if ($can_search) {
8638: if (ref($dom_inst_srch{'directorysrch'}{'searchby'}) eq 'ARRAY') {
8639: if (!grep(/^\Q$srch->{'srchby'}\E$/,@{$dom_inst_srch{'directorysrch'}{'searchby'}})) {
1.180 raeburn 8640: return &mt('Institutional directory search in domain: [_1] is not available for searching by "[_2]"',$showdom,$longtext{$srch->{'srchby'}});
1.160 raeburn 8641: }
8642: } else {
1.180 raeburn 8643: return &mt('Institutional directory search in domain: [_1] is not available.', $showdom);
1.160 raeburn 8644: }
8645: }
8646: if ($can_search) {
1.178 raeburn 8647: if (ref($dom_inst_srch{'directorysrch'}{'searchtypes'}) eq 'ARRAY') {
8648: if (grep(/^\Q$srch->{'srchtype'}\E/,@{$dom_inst_srch{'directorysrch'}{'searchtypes'}})) {
8649: return 'ok';
8650: } else {
1.180 raeburn 8651: return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
1.178 raeburn 8652: }
8653: } else {
8654: if ((($dom_inst_srch{'directorysrch'}{'searchtypes'} eq 'specify') &&
8655: ($srch->{'srchtype'} eq 'exact' || $srch->{'srchtype'} eq 'contains')) ||
8656: ($dom_inst_srch{'directorysrch'}{'searchtypes'} eq $srch->{'srchtype'})) {
8657: return 'ok';
8658: } else {
1.180 raeburn 8659: return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
1.178 raeburn 8660: }
1.160 raeburn 8661: }
8662: }
8663: }
8664:
8665: sub get_courseusers {
8666: my %advhash;
1.167 albertel 8667: my $classlist = &Apache::loncoursedata::get_classlist();
1.160 raeburn 8668: my %coursepersonnel=&Apache::lonnet::get_course_adv_roles();
8669: foreach my $role (sort(keys(%coursepersonnel))) {
8670: foreach my $user (split(/\,/,$coursepersonnel{$role})) {
1.167 albertel 8671: if (!exists($classlist->{$user})) {
8672: $classlist->{$user} = [];
8673: }
1.160 raeburn 8674: }
8675: }
1.167 albertel 8676: return $classlist;
1.160 raeburn 8677: }
8678:
8679: sub build_search_response {
1.221 raeburn 8680: my ($context,$srch,%srch_results) = @_;
1.179 raeburn 8681: my ($currstate,$response,$forcenewuser);
1.160 raeburn 8682: my %names = (
1.330 bisitz 8683: 'uname' => 'username',
8684: 'lastname' => 'last name',
1.160 raeburn 8685: 'lastfirst' => 'last name, first name',
1.330 bisitz 8686: 'crs' => 'this course',
8687: 'dom' => 'LON-CAPA domain',
8688: 'instd' => 'the institutional directory for domain',
1.160 raeburn 8689: );
8690:
8691: my %single = (
1.180 raeburn 8692: begins => 'A match',
1.160 raeburn 8693: contains => 'A match',
1.180 raeburn 8694: exact => 'An exact match',
1.160 raeburn 8695: );
8696: my %nomatch = (
1.180 raeburn 8697: begins => 'No match',
1.160 raeburn 8698: contains => 'No match',
1.180 raeburn 8699: exact => 'No exact match',
1.160 raeburn 8700: );
8701: if (keys(%srch_results) > 1) {
1.179 raeburn 8702: $currstate = 'select';
1.160 raeburn 8703: } else {
8704: if (keys(%srch_results) == 1) {
1.416 raeburn 8705: if ($env{'form.action'} eq 'accesslogs') {
8706: $currstate = 'activity';
8707: } else {
8708: $currstate = 'modify';
8709: }
1.180 raeburn 8710: $response = &mt("$single{$srch->{'srchtype'}} was found for the $names{$srch->{'srchby'}} ([_1]) in $names{$srch->{'srchin'}}.",$srch->{'srchterm'});
8711: if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
1.330 bisitz 8712: $response .= ': '.&display_domain_info($srch->{'srchdomain'});
1.180 raeburn 8713: }
1.330 bisitz 8714: } else { # Search has nothing found. Prepare message to user.
8715: $response = '<span class="LC_warning">';
1.180 raeburn 8716: if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
1.330 bisitz 8717: $response .= &mt("$nomatch{$srch->{'srchtype'}} found for the $names{$srch->{'srchby'}} [_1] in $names{$srch->{'srchin'}}: [_2]",
8718: '<b>'.$srch->{'srchterm'}.'</b>',
8719: &display_domain_info($srch->{'srchdomain'}));
8720: } else {
8721: $response .= &mt("$nomatch{$srch->{'srchtype'}} found for the $names{$srch->{'srchby'}} [_1] in $names{$srch->{'srchin'}}.",
8722: '<b>'.$srch->{'srchterm'}.'</b>');
1.180 raeburn 8723: }
8724: $response .= '</span>';
1.330 bisitz 8725:
1.160 raeburn 8726: if ($srch->{'srchin'} ne 'alc') {
8727: $forcenewuser = 1;
8728: my $cansrchinst = 0;
1.438 raeburn 8729: if (($srch->{'srchdomain'}) && ($env{'form.action'} ne 'accesslogs')) {
1.160 raeburn 8730: my %domconfig = &Apache::lonnet::get_dom('configuration',['directorysrch'],$srch->{'srchdomain'});
8731: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
8732: if ($domconfig{'directorysrch'}{'available'}) {
8733: $cansrchinst = 1;
8734: }
8735: }
8736: }
1.180 raeburn 8737: if ((($srch->{'srchby'} eq 'lastfirst') ||
8738: ($srch->{'srchby'} eq 'lastname')) &&
8739: ($srch->{'srchin'} eq 'dom')) {
8740: if ($cansrchinst) {
8741: $response .= '<br />'.&mt('You may want to broaden your search to a search of the institutional directory for the domain.');
1.160 raeburn 8742: }
8743: }
1.180 raeburn 8744: if ($srch->{'srchin'} eq 'crs') {
8745: $response .= '<br />'.&mt('You may want to broaden your search to the selected LON-CAPA domain.');
8746: }
8747: }
1.305 raeburn 8748: my $createdom = $env{'request.role.domain'};
8749: if ($context eq 'requestcrs') {
8750: if ($env{'form.coursedom'} ne '') {
8751: $createdom = $env{'form.coursedom'};
8752: }
8753: }
1.416 raeburn 8754: unless (($env{'form.action'} eq 'accesslogs') || (($srch->{'srchby'} eq 'uname') && ($srch->{'srchin'} eq 'dom') &&
8755: ($srch->{'srchtype'} eq 'exact') && ($srch->{'srchdomain'} eq $createdom))) {
1.221 raeburn 8756: my $cancreate =
1.305 raeburn 8757: &Apache::lonuserutils::can_create_user($createdom,$context);
8758: my $targetdom = '<span class="LC_cusr_emph">'.$createdom.'</span>';
1.221 raeburn 8759: if ($cancreate) {
1.305 raeburn 8760: my $showdom = &display_domain_info($createdom);
1.266 bisitz 8761: $response .= '<br /><br />'
8762: .'<b>'.&mt('To add a new user:').'</b>'
1.305 raeburn 8763: .'<br />';
8764: if ($context eq 'requestcrs') {
8765: $response .= &mt("(You can only define new users in the new course's domain - [_1])",$targetdom);
8766: } else {
8767: $response .= &mt("(You can only create new users in your current role's domain - [_1])",$targetdom);
8768: }
8769: $response .='<ul><li>'
1.266 bisitz 8770: .&mt("Set 'Domain/institution to search' to: [_1]",'<span class="LC_cusr_emph">'.$showdom.'</span>')
8771: .'</li><li>'
8772: .&mt("Set 'Search criteria' to: [_1]username is ..... in selected LON-CAPA domain[_2]",'<span class="LC_cusr_emph">','</span>')
8773: .'</li><li>'
8774: .&mt('Provide the proposed username')
8775: .'</li><li>'
8776: .&mt("Click 'Search'")
8777: .'</li></ul><br />';
1.221 raeburn 8778: } else {
1.422 raeburn 8779: unless (($context eq 'domain') && ($env{'form.action'} eq 'singleuser')) {
8780: my $helplink = ' href="javascript:helpMenu('."'display'".')"';
8781: $response .= '<br /><br />';
8782: if ($context eq 'requestcrs') {
8783: $response .= &mt("You are not authorized to define new users in the new course's domain - [_1].",$targetdom);
8784: } else {
8785: $response .= &mt("You are not authorized to create new users in your current role's domain - [_1].",$targetdom);
8786: }
8787: $response .= '<br />'
8788: .&mt('Please contact the [_1]helpdesk[_2] if you need to create a new user.'
8789: ,' <a'.$helplink.'>'
8790: ,'</a>')
8791: .'<br />';
1.305 raeburn 8792: }
1.221 raeburn 8793: }
1.160 raeburn 8794: }
8795: }
8796: }
1.179 raeburn 8797: return ($currstate,$response,$forcenewuser);
1.160 raeburn 8798: }
8799:
1.180 raeburn 8800: sub display_domain_info {
8801: my ($dom) = @_;
8802: my $output = $dom;
8803: if ($dom ne '') {
8804: my $domdesc = &Apache::lonnet::domain($dom,'description');
8805: if ($domdesc ne '') {
8806: $output .= ' <span class="LC_cusr_emph">('.$domdesc.')</span>';
8807: }
8808: }
8809: return $output;
8810: }
8811:
1.160 raeburn 8812: sub crumb_utilities {
8813: my %elements = (
8814: crtuser => {
8815: srchterm => 'text',
1.172 raeburn 8816: srchin => 'selectbox',
1.160 raeburn 8817: srchby => 'selectbox',
8818: srchtype => 'selectbox',
8819: srchdomain => 'selectbox',
8820: },
1.207 raeburn 8821: crtusername => {
8822: srchterm => 'text',
8823: srchdomain => 'selectbox',
8824: },
1.160 raeburn 8825: docustom => {
8826: rolename => 'selectbox',
8827: newrolename => 'textbox',
8828: },
1.179 raeburn 8829: studentform => {
8830: srchterm => 'text',
8831: srchin => 'selectbox',
8832: srchby => 'selectbox',
8833: srchtype => 'selectbox',
8834: srchdomain => 'selectbox',
8835: },
1.160 raeburn 8836: );
8837:
8838: my $jsback .= qq|
8839: function backPage(formname,prevphase,prevstate) {
1.211 raeburn 8840: if (typeof prevphase == 'undefined') {
8841: formname.phase.value = '';
8842: }
8843: else {
8844: formname.phase.value = prevphase;
8845: }
8846: if (typeof prevstate == 'undefined') {
8847: formname.currstate.value = '';
8848: }
8849: else {
8850: formname.currstate.value = prevstate;
8851: }
1.160 raeburn 8852: formname.submit();
8853: }
8854: |;
8855: return ($jsback,\%elements);
8856: }
8857:
1.26 matthew 8858: sub course_level_table {
1.375 raeburn 8859: my ($inccourses,$showcredits,$defaultcredits) = @_;
8860: return unless (ref($inccourses) eq 'HASH');
1.26 matthew 8861: my $table = '';
1.62 www 8862: # Custom Roles?
8863:
1.190 raeburn 8864: my %customroles=&Apache::lonuserutils::my_custom_roles();
1.89 raeburn 8865: my %lt=&Apache::lonlocal::texthash(
8866: 'exs' => "Existing sections",
8867: 'new' => "Define new section",
8868: 'ssd' => "Set Start Date",
8869: 'sed' => "Set End Date",
1.131 raeburn 8870: 'crl' => "Course Level",
1.89 raeburn 8871: 'act' => "Activate",
8872: 'rol' => "Role",
8873: 'ext' => "Extent",
1.113 raeburn 8874: 'grs' => "Section",
1.375 raeburn 8875: 'crd' => "Credits",
1.89 raeburn 8876: 'sta' => "Start",
8877: 'end' => "End"
8878: );
1.62 www 8879:
1.375 raeburn 8880: foreach my $protectedcourse (sort(keys(%{$inccourses}))) {
1.135 raeburn 8881: my $thiscourse=$protectedcourse;
1.26 matthew 8882: $thiscourse=~s:_:/:g;
8883: my %coursedata=&Apache::lonnet::coursedescription($thiscourse);
1.365 raeburn 8884: my $isowner = &Apache::lonuserutils::is_courseowner($protectedcourse,$coursedata{'internal.courseowner'});
1.26 matthew 8885: my $area=$coursedata{'description'};
1.321 raeburn 8886: my $crstype=$coursedata{'type'};
1.135 raeburn 8887: if (!defined($area)) { $area=&mt('Unavailable course').': '.$protectedcourse; }
1.89 raeburn 8888: my ($domain,$cnum)=split(/\//,$thiscourse);
1.115 albertel 8889: my %sections_count;
1.101 albertel 8890: if (defined($env{'request.course.id'})) {
8891: if ($env{'request.course.id'} eq $domain.'_'.$cnum) {
1.115 albertel 8892: %sections_count =
8893: &Apache::loncommon::get_sections($domain,$cnum);
1.92 raeburn 8894: }
8895: }
1.321 raeburn 8896: my @roles = &Apache::lonuserutils::roles_by_context('course','',$crstype);
1.213 raeburn 8897: foreach my $role (@roles) {
1.321 raeburn 8898: my $plrole=&Apache::lonnet::plaintext($role,$crstype);
1.329 raeburn 8899: if ((&Apache::lonnet::allowed('c'.$role,$thiscourse)) ||
8900: ((($role eq 'cc') || ($role eq 'co')) && ($isowner))) {
1.221 raeburn 8901: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
1.375 raeburn 8902: $plrole,\%sections_count,\%lt,
1.402 raeburn 8903: $showcredits,$defaultcredits,$crstype);
1.221 raeburn 8904: } elsif ($env{'request.course.sec'} ne '') {
8905: if (&Apache::lonnet::allowed('c'.$role,$thiscourse.'/'.
8906: $env{'request.course.sec'})) {
8907: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
1.375 raeburn 8908: $plrole,\%sections_count,\%lt,
1.402 raeburn 8909: $showcredits,$defaultcredits,$crstype);
1.26 matthew 8910: }
8911: }
8912: }
1.221 raeburn 8913: if (&Apache::lonnet::allowed('ccr',$thiscourse)) {
1.324 raeburn 8914: foreach my $cust (sort(keys(%customroles))) {
8915: next if ($crstype eq 'Community' && $customroles{$cust} =~ /bre\&S/);
1.221 raeburn 8916: my $role = 'cr_cr_'.$env{'user.domain'}.'_'.$env{'user.name'}.'_'.$cust;
8917: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
1.402 raeburn 8918: $cust,\%sections_count,\%lt,
8919: $showcredits,$defaultcredits,$crstype);
1.221 raeburn 8920: }
1.62 www 8921: }
1.26 matthew 8922: }
8923: return '' if ($table eq ''); # return nothing if there is nothing
8924: # in the table
1.188 raeburn 8925: my $result;
8926: if (!$env{'request.course.id'}) {
8927: $result = '<h4>'.$lt{'crl'}.'</h4>'."\n";
8928: }
8929: $result .=
1.136 raeburn 8930: &Apache::loncommon::start_data_table().
8931: &Apache::loncommon::start_data_table_header_row().
1.375 raeburn 8932: '<th>'.$lt{'act'}.'</th><th>'.$lt{'rol'}.'</th>'."\n".
1.402 raeburn 8933: '<th>'.$lt{'ext'}.'</th><th>'."\n";
8934: if ($showcredits) {
8935: $result .= $lt{'crd'}.'</th>';
8936: }
8937: $result .=
1.375 raeburn 8938: '<th>'.$lt{'grs'}.'</th><th>'.$lt{'sta'}.'</th>'."\n".
8939: '<th>'.$lt{'end'}.'</th>'.
1.136 raeburn 8940: &Apache::loncommon::end_data_table_header_row().
8941: $table.
8942: &Apache::loncommon::end_data_table();
1.26 matthew 8943: return $result;
8944: }
1.88 raeburn 8945:
1.221 raeburn 8946: sub course_level_row {
1.375 raeburn 8947: my ($protectedcourse,$role,$area,$domain,$plrole,$sections_count,
1.402 raeburn 8948: $lt,$showcredits,$defaultcredits,$crstype) = @_;
1.375 raeburn 8949: my $creditem;
1.222 raeburn 8950: my $row = &Apache::loncommon::start_data_table_row().
8951: ' <td><input type="checkbox" name="act_'.
8952: $protectedcourse.'_'.$role.'" /></td>'."\n".
8953: ' <td>'.$plrole.'</td>'."\n".
8954: ' <td>'.$area.'<br />Domain: '.$domain.'</td>'."\n";
1.402 raeburn 8955: if (($showcredits) && ($role eq 'st') && ($crstype eq 'Course')) {
1.375 raeburn 8956: $row .=
8957: '<td><input type="text" name="credits_'.$protectedcourse.'_'.
8958: $role.'" size="3" value="'.$defaultcredits.'" /></td>';
8959: } else {
8960: $row .= '<td> </td>';
8961: }
1.322 raeburn 8962: if (($role eq 'cc') || ($role eq 'co')) {
1.222 raeburn 8963: $row .= '<td> </td>';
1.221 raeburn 8964: } elsif ($env{'request.course.sec'} ne '') {
1.222 raeburn 8965: $row .= ' <td><input type="hidden" value="'.
8966: $env{'request.course.sec'}.'" '.
8967: 'name="sec_'.$protectedcourse.'_'.$role.'" />'.
8968: $env{'request.course.sec'}.'</td>';
1.221 raeburn 8969: } else {
8970: if (ref($sections_count) eq 'HASH') {
8971: my $currsec =
8972: &Apache::lonuserutils::course_sections($sections_count,
8973: $protectedcourse.'_'.$role);
1.222 raeburn 8974: $row .= '<td><table class="LC_createuser">'."\n".
8975: '<tr class="LC_section_row">'."\n".
8976: ' <td valign="top">'.$lt->{'exs'}.'<br />'.
8977: $currsec.'</td>'."\n".
8978: ' <td> </td>'."\n".
8979: ' <td valign="top"> '.$lt->{'new'}.'<br />'.
1.221 raeburn 8980: '<input type="text" name="newsec_'.$protectedcourse.'_'.$role.
8981: '" value="" />'.
8982: '<input type="hidden" '.
8983: 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'."\n".
1.222 raeburn 8984: '</tr></table></td>'."\n";
1.221 raeburn 8985: } else {
1.222 raeburn 8986: $row .= '<td><input type="text" size="10" '.
1.375 raeburn 8987: 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'."\n";
1.221 raeburn 8988: }
8989: }
1.222 raeburn 8990: $row .= <<ENDTIMEENTRY;
8991: <td><input type="hidden" name="start_$protectedcourse\_$role" value="" />
1.221 raeburn 8992: <a href=
8993: "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 8994: <td><input type="hidden" name="end_$protectedcourse\_$role" value="" />
1.221 raeburn 8995: <a href=
8996: "javascript:pjump('date_end','End Date $plrole',document.cu.end_$protectedcourse\_$role.value,'end_$protectedcourse\_$role','cu.pres','dateset')">$lt->{'sed'}</a></td>
8997: ENDTIMEENTRY
1.222 raeburn 8998: $row .= &Apache::loncommon::end_data_table_row();
8999: return $row;
1.221 raeburn 9000: }
9001:
1.88 raeburn 9002: sub course_level_dc {
1.375 raeburn 9003: my ($dcdom,$showcredits) = @_;
1.190 raeburn 9004: my %customroles=&Apache::lonuserutils::my_custom_roles();
1.213 raeburn 9005: my @roles = &Apache::lonuserutils::roles_by_context('course');
1.88 raeburn 9006: my $hiddenitems = '<input type="hidden" name="dcdomain" value="'.$dcdom.'" />'.
9007: '<input type="hidden" name="origdom" value="'.$dcdom.'" />'.
1.133 raeburn 9008: '<input type="hidden" name="dccourse" value="" />';
1.355 www 9009: my $courseform=&Apache::loncommon::selectcourse_link
1.356 raeburn 9010: ('cu','dccourse','dcdomain','coursedesc',undef,undef,'Select','crstype');
1.375 raeburn 9011: my $credit_elem;
9012: if ($showcredits) {
9013: $credit_elem = 'credits';
9014: }
9015: my $cb_jscript = &Apache::loncommon::coursebrowser_javascript($dcdom,'currsec','cu','role','Course/Community Browser',$credit_elem);
1.88 raeburn 9016: my %lt=&Apache::lonlocal::texthash(
9017: 'rol' => "Role",
1.113 raeburn 9018: 'grs' => "Section",
1.88 raeburn 9019: 'exs' => "Existing sections",
9020: 'new' => "Define new section",
9021: 'sta' => "Start",
9022: 'end' => "End",
9023: 'ssd' => "Set Start Date",
1.355 www 9024: 'sed' => "Set End Date",
1.375 raeburn 9025: 'scc' => "Course/Community",
9026: 'crd' => "Credits",
1.88 raeburn 9027: );
1.323 raeburn 9028: my $header = '<h4>'.&mt('Course/Community Level').'</h4>'.
1.136 raeburn 9029: &Apache::loncommon::start_data_table().
9030: &Apache::loncommon::start_data_table_header_row().
1.375 raeburn 9031: '<th>'.$lt{'scc'}.'</th><th>'.$lt{'rol'}.'</th>'."\n".
1.397 bisitz 9032: '<th>'.$lt{'grs'}.'</th>'."\n";
9033: $header .= '<th>'.$lt{'crd'}.'</th>'."\n" if ($showcredits);
9034: $header .= '<th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'."\n".
1.136 raeburn 9035: &Apache::loncommon::end_data_table_header_row();
1.143 raeburn 9036: my $otheritems = &Apache::loncommon::start_data_table_row()."\n".
1.356 raeburn 9037: '<td><br /><span class="LC_nobreak"><input type="text" name="coursedesc" value="" onfocus="this.blur();opencrsbrowser('."'cu','dccourse','dcdomain','coursedesc','','','','crstype'".')" />'.
9038: $courseform.(' ' x4).'</span></td>'."\n".
1.389 bisitz 9039: '<td valign="top"><br /><select name="role">'."\n";
1.213 raeburn 9040: foreach my $role (@roles) {
1.135 raeburn 9041: my $plrole=&Apache::lonnet::plaintext($role);
1.389 bisitz 9042: $otheritems .= ' <option value="'.$role.'">'.$plrole.'</option>';
1.88 raeburn 9043: }
1.404 raeburn 9044: if ( keys(%customroles) > 0) {
9045: foreach my $cust (sort(keys(%customroles))) {
1.101 albertel 9046: my $custrole='cr_cr_'.$env{'user.domain'}.
1.135 raeburn 9047: '_'.$env{'user.name'}.'_'.$cust;
1.389 bisitz 9048: $otheritems .= ' <option value="'.$custrole.'">'.$cust.'</option>';
1.88 raeburn 9049: }
9050: }
9051: $otheritems .= '</select></td><td>'.
9052: '<table border="0" cellspacing="0" cellpadding="0">'.
9053: '<tr><td valign="top"><b>'.$lt{'exs'}.'</b><br /><select name="currsec">'.
1.389 bisitz 9054: ' <option value=""><--'.&mt('Pick course first').'</option></select></td>'.
1.88 raeburn 9055: '<td> </td>'.
9056: '<td valign="top"> <b>'.$lt{'new'}.'</b><br />'.
1.113 raeburn 9057: '<input type="text" name="newsec" value="" />'.
1.237 raeburn 9058: '<input type="hidden" name="section" value="" />'.
1.323 raeburn 9059: '<input type="hidden" name="groups" value="" />'.
9060: '<input type="hidden" name="crstype" value="" /></td>'.
1.375 raeburn 9061: '</tr></table></td>'."\n";
9062: if ($showcredits) {
9063: $otheritems .= '<td><br />'."\n".
1.397 bisitz 9064: '<input type="text" size="3" name="credits" value="" /></td>'."\n";
1.375 raeburn 9065: }
1.88 raeburn 9066: $otheritems .= <<ENDTIMEENTRY;
1.323 raeburn 9067: <td><br /><input type="hidden" name="start" value='' />
1.88 raeburn 9068: <a href=
9069: "javascript:pjump('date_start','Start Date',document.cu.start.value,'start','cu.pres','dateset')">$lt{'ssd'}</a></td>
1.323 raeburn 9070: <td><br /><input type="hidden" name="end" value='' />
1.88 raeburn 9071: <a href=
9072: "javascript:pjump('date_end','End Date',document.cu.end.value,'end','cu.pres','dateset')">$lt{'sed'}</a></td>
9073: ENDTIMEENTRY
1.136 raeburn 9074: $otheritems .= &Apache::loncommon::end_data_table_row().
9075: &Apache::loncommon::end_data_table()."\n";
1.88 raeburn 9076: return $cb_jscript.$header.$hiddenitems.$otheritems;
9077: }
9078:
1.237 raeburn 9079: sub update_selfenroll_config {
1.400 raeburn 9080: my ($r,$cid,$cdom,$cnum,$context,$crstype,$currsettings) = @_;
1.398 raeburn 9081: return unless (ref($currsettings) eq 'HASH');
9082: my ($row,$lt) = &Apache::lonuserutils::get_selfenroll_titles();
9083: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
1.237 raeburn 9084: my (%changes,%warning);
1.241 raeburn 9085: my $curr_types;
1.400 raeburn 9086: my %noedit;
9087: unless ($context eq 'domain') {
9088: %noedit = &get_noedit_fields($cdom,$cnum,$crstype,$row);
9089: }
1.237 raeburn 9090: if (ref($row) eq 'ARRAY') {
9091: foreach my $item (@{$row}) {
1.400 raeburn 9092: next if ($noedit{$item});
1.237 raeburn 9093: if ($item eq 'enroll_dates') {
9094: my (%currenrolldate,%newenrolldate);
9095: foreach my $type ('start','end') {
1.398 raeburn 9096: $currenrolldate{$type} = $currsettings->{'selfenroll_'.$type.'_date'};
1.237 raeburn 9097: $newenrolldate{$type} = &Apache::lonhtmlcommon::get_date_from_form('selfenroll_'.$type.'_date');
9098: if ($newenrolldate{$type} ne $currenrolldate{$type}) {
9099: $changes{'internal.selfenroll_'.$type.'_date'} = $newenrolldate{$type};
9100: }
9101: }
9102: } elsif ($item eq 'access_dates') {
9103: my (%currdate,%newdate);
9104: foreach my $type ('start','end') {
1.398 raeburn 9105: $currdate{$type} = $currsettings->{'selfenroll_'.$type.'_access'};
1.237 raeburn 9106: $newdate{$type} = &Apache::lonhtmlcommon::get_date_from_form('selfenroll_'.$type.'_access');
9107: if ($newdate{$type} ne $currdate{$type}) {
9108: $changes{'internal.selfenroll_'.$type.'_access'} = $newdate{$type};
9109: }
9110: }
1.241 raeburn 9111: } elsif ($item eq 'types') {
1.398 raeburn 9112: $curr_types = $currsettings->{'selfenroll_'.$item};
1.241 raeburn 9113: if ($env{'form.selfenroll_all'}) {
9114: if ($curr_types ne '*') {
9115: $changes{'internal.selfenroll_types'} = '*';
9116: } else {
9117: next;
9118: }
9119: } else {
1.249 raeburn 9120: my %currdoms;
1.241 raeburn 9121: my @entries = split(/;/,$curr_types);
9122: my @deletedoms = &Apache::loncommon::get_env_multiple('form.selfenroll_delete');
1.249 raeburn 9123: my @activations = &Apache::loncommon::get_env_multiple('form.selfenroll_activate');
1.241 raeburn 9124: my $newnum = 0;
1.249 raeburn 9125: my @latesttypes;
9126: foreach my $num (@activations) {
9127: my @types = &Apache::loncommon::get_env_multiple('form.selfenroll_types_'.$num);
9128: if (@types > 0) {
1.241 raeburn 9129: @types = sort(@types);
9130: my $typestr = join(',',@types);
1.249 raeburn 9131: my $typedom = $env{'form.selfenroll_dom_'.$num};
9132: $latesttypes[$newnum] = $typedom.':'.$typestr;
9133: $currdoms{$typedom} = 1;
1.241 raeburn 9134: $newnum ++;
9135: }
9136: }
1.338 raeburn 9137: for (my $j=0; $j<$env{'form.selfenroll_types_total'}; $j++) {
9138: if ((!grep(/^$j$/,@deletedoms)) && (!grep(/^$j$/,@activations))) {
1.249 raeburn 9139: my @types = &Apache::loncommon::get_env_multiple('form.selfenroll_types_'.$j);
9140: if (@types > 0) {
9141: @types = sort(@types);
9142: my $typestr = join(',',@types);
9143: my $typedom = $env{'form.selfenroll_dom_'.$j};
9144: $latesttypes[$newnum] = $typedom.':'.$typestr;
9145: $currdoms{$typedom} = 1;
9146: $newnum ++;
9147: }
9148: }
9149: }
9150: if ($env{'form.selfenroll_newdom'} ne '') {
9151: my $typedom = $env{'form.selfenroll_newdom'};
9152: if ((!defined($currdoms{$typedom})) &&
9153: (&Apache::lonnet::domain($typedom) ne '')) {
9154: my $typestr;
9155: my ($othertitle,$usertypes,$types) =
9156: &Apache::loncommon::sorted_inst_types($typedom);
9157: my $othervalue = 'any';
9158: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
9159: if (@{$types} > 0) {
1.257 raeburn 9160: my @esc_types = map { &escape($_); } @{$types};
1.249 raeburn 9161: $othervalue = 'other';
1.258 raeburn 9162: $typestr = join(',',(@esc_types,$othervalue));
1.249 raeburn 9163: }
9164: $typestr = $othervalue;
9165: } else {
9166: $typestr = $othervalue;
9167: }
9168: $latesttypes[$newnum] = $typedom.':'.$typestr;
9169: $newnum ++ ;
9170: }
9171: }
1.241 raeburn 9172: my $selfenroll_types = join(';',@latesttypes);
9173: if ($selfenroll_types ne $curr_types) {
9174: $changes{'internal.selfenroll_types'} = $selfenroll_types;
9175: }
9176: }
1.276 raeburn 9177: } elsif ($item eq 'limit') {
9178: my $newlimit = $env{'form.selfenroll_limit'};
9179: my $newcap = $env{'form.selfenroll_cap'};
9180: $newcap =~s/\s+//g;
1.398 raeburn 9181: my $currlimit = $currsettings->{'selfenroll_limit'};
1.276 raeburn 9182: $currlimit = 'none' if ($currlimit eq '');
1.398 raeburn 9183: my $currcap = $currsettings->{'selfenroll_cap'};
1.276 raeburn 9184: if ($newlimit ne $currlimit) {
9185: if ($newlimit ne 'none') {
9186: if ($newcap =~ /^\d+$/) {
9187: if ($newcap ne $currcap) {
9188: $changes{'internal.selfenroll_cap'} = $newcap;
9189: }
9190: $changes{'internal.selfenroll_limit'} = $newlimit;
9191: } else {
1.398 raeburn 9192: $warning{$item} = &mt('Maximum enrollment setting unchanged.').'<br />'.
9193: &mt('The value provided was invalid - it must be a positive integer if enrollment is being limited.');
1.276 raeburn 9194: }
9195: } elsif ($currcap ne '') {
9196: $changes{'internal.selfenroll_cap'} = '';
9197: $changes{'internal.selfenroll_limit'} = $newlimit;
9198: }
9199: } elsif ($currlimit ne 'none') {
9200: if ($newcap =~ /^\d+$/) {
9201: if ($newcap ne $currcap) {
9202: $changes{'internal.selfenroll_cap'} = $newcap;
9203: }
9204: } else {
1.398 raeburn 9205: $warning{$item} = &mt('Maximum enrollment setting unchanged.').'<br />'.
9206: &mt('The value provided was invalid - it must be a positive integer if enrollment is being limited.');
1.276 raeburn 9207: }
9208: }
9209: } elsif ($item eq 'approval') {
9210: my (@currnotified,@newnotified);
1.398 raeburn 9211: my $currapproval = $currsettings->{'selfenroll_approval'};
9212: my $currnotifylist = $currsettings->{'selfenroll_notifylist'};
1.276 raeburn 9213: if ($currnotifylist ne '') {
9214: @currnotified = split(/,/,$currnotifylist);
9215: @currnotified = sort(@currnotified);
9216: }
9217: my $newapproval = $env{'form.selfenroll_approval'};
9218: @newnotified = &Apache::loncommon::get_env_multiple('form.selfenroll_notify');
9219: @newnotified = sort(@newnotified);
9220: if ($newapproval ne $currapproval) {
9221: $changes{'internal.selfenroll_approval'} = $newapproval;
9222: if (!$newapproval) {
9223: if ($currnotifylist ne '') {
9224: $changes{'internal.selfenroll_notifylist'} = '';
9225: }
9226: } else {
9227: my @differences =
1.295 raeburn 9228: &Apache::loncommon::compare_arrays(\@currnotified,\@newnotified);
1.276 raeburn 9229: if (@differences > 0) {
9230: if (@newnotified > 0) {
9231: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
9232: } else {
9233: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
9234: }
9235: }
9236: }
9237: } else {
1.295 raeburn 9238: my @differences = &Apache::loncommon::compare_arrays(\@currnotified,\@newnotified);
1.276 raeburn 9239: if (@differences > 0) {
9240: if (@newnotified > 0) {
9241: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
9242: } else {
9243: $changes{'internal.selfenroll_notifylist'} = '';
9244: }
9245: }
9246: }
1.237 raeburn 9247: } else {
1.398 raeburn 9248: my $curr_val = $currsettings->{'selfenroll_'.$item};
1.237 raeburn 9249: my $newval = $env{'form.selfenroll_'.$item};
9250: if ($item eq 'section') {
9251: $newval = $env{'form.sections'};
1.241 raeburn 9252: if (defined($curr_groups{$newval})) {
1.237 raeburn 9253: $newval = $curr_val;
1.398 raeburn 9254: $warning{$item} = &mt('Section for self-enrolled users unchanged as the proposed section is a group').'<br />'.
9255: &mt('Group names and section names must be distinct');
1.237 raeburn 9256: } elsif ($newval eq 'all') {
9257: $newval = $curr_val;
1.274 bisitz 9258: $warning{$item} = &mt('Section for self-enrolled users unchanged, as "all" is a reserved section name.');
1.237 raeburn 9259: }
9260: if ($newval eq '') {
9261: $newval = 'none';
9262: }
9263: }
9264: if ($newval ne $curr_val) {
9265: $changes{'internal.selfenroll_'.$item} = $newval;
9266: }
1.241 raeburn 9267: }
1.237 raeburn 9268: }
9269: if (keys(%warning) > 0) {
9270: foreach my $item (@{$row}) {
9271: if (exists($warning{$item})) {
9272: $r->print($warning{$item}.'<br />');
9273: }
9274: }
9275: }
9276: if (keys(%changes) > 0) {
9277: my $putresult = &Apache::lonnet::put('environment',\%changes,$cdom,$cnum);
9278: if ($putresult eq 'ok') {
9279: if ((exists($changes{'internal.selfenroll_types'})) ||
9280: (exists($changes{'internal.selfenroll_start_date'})) ||
9281: (exists($changes{'internal.selfenroll_end_date'}))) {
9282: my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',
9283: $cnum,undef,undef,'Course');
9284: my $chome = &Apache::lonnet::homeserver($cnum,$cdom);
1.398 raeburn 9285: if (ref($crsinfo{$cid}) eq 'HASH') {
1.237 raeburn 9286: foreach my $item ('selfenroll_types','selfenroll_start_date','selfenroll_end_date') {
9287: if (exists($changes{'internal.'.$item})) {
1.398 raeburn 9288: $crsinfo{$cid}{$item} = $changes{'internal.'.$item};
1.237 raeburn 9289: }
9290: }
9291: my $crsputresult =
9292: &Apache::lonnet::courseidput($cdom,\%crsinfo,
9293: $chome,'notime');
9294: }
9295: }
9296: $r->print(&mt('The following changes were made to self-enrollment settings:').'<ul>');
9297: foreach my $item (@{$row}) {
9298: my $title = $item;
9299: if (ref($lt) eq 'HASH') {
9300: $title = $lt->{$item};
9301: }
9302: if ($item eq 'enroll_dates') {
9303: foreach my $type ('start','end') {
9304: if (exists($changes{'internal.selfenroll_'.$type.'_date'})) {
9305: my $newdate = &Apache::lonlocal::locallocaltime($changes{'internal.selfenroll_'.$type.'_date'});
1.244 bisitz 9306: $r->print('<li>'.&mt('[_1]: "[_2]" set to "[_3]".',
1.237 raeburn 9307: $title,$type,$newdate).'</li>');
9308: }
9309: }
9310: } elsif ($item eq 'access_dates') {
9311: foreach my $type ('start','end') {
9312: if (exists($changes{'internal.selfenroll_'.$type.'_access'})) {
9313: my $newdate = &Apache::lonlocal::locallocaltime($changes{'internal.selfenroll_'.$type.'_access'});
1.244 bisitz 9314: $r->print('<li>'.&mt('[_1]: "[_2]" set to "[_3]".',
1.237 raeburn 9315: $title,$type,$newdate).'</li>');
9316: }
9317: }
1.276 raeburn 9318: } elsif ($item eq 'limit') {
9319: if ((exists($changes{'internal.selfenroll_limit'})) ||
9320: (exists($changes{'internal.selfenroll_cap'}))) {
9321: my ($newval,$newcap);
9322: if ($changes{'internal.selfenroll_cap'} ne '') {
9323: $newcap = $changes{'internal.selfenroll_cap'}
9324: } else {
1.398 raeburn 9325: $newcap = $currsettings->{'selfenroll_cap'};
1.276 raeburn 9326: }
9327: if ($changes{'internal.selfenroll_limit'} eq 'none') {
9328: $newval = &mt('No limit');
9329: } elsif ($changes{'internal.selfenroll_limit'} eq
9330: 'allstudents') {
9331: $newval = &mt('New self-enrollment no longer allowed when total (all students) reaches [_1].',$newcap);
9332: } elsif ($changes{'internal.selfenroll_limit'} eq 'selfenrolled') {
9333: $newval = &mt('New self-enrollment no longer allowed when total number of self-enrolled students reaches [_1].',$newcap);
9334: } else {
1.398 raeburn 9335: my $currlimit = $currsettings->{'selfenroll_limit'};
1.276 raeburn 9336: if ($currlimit eq 'allstudents') {
9337: $newval = &mt('New self-enrollment no longer allowed when total (all students) reaches [_1].',$newcap);
9338: } elsif ($changes{'internal.selfenroll_limit'} eq 'selfenrolled') {
1.308 raeburn 9339: $newval = &mt('New self-enrollment no longer allowed when total number of self-enrolled students reaches [_1].',$newcap);
1.276 raeburn 9340: }
9341: }
9342: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval).'</li>'."\n");
9343: }
9344: } elsif ($item eq 'approval') {
9345: if ((exists($changes{'internal.selfenroll_approval'})) ||
9346: (exists($changes{'internal.selfenroll_notifylist'}))) {
1.398 raeburn 9347: my %selfdescs = &Apache::lonuserutils::selfenroll_default_descs();
1.276 raeburn 9348: my ($newval,$newnotify);
9349: if (exists($changes{'internal.selfenroll_notifylist'})) {
9350: $newnotify = $changes{'internal.selfenroll_notifylist'};
9351: } else {
1.398 raeburn 9352: $newnotify = $currsettings->{'selfenroll_notifylist'};
1.276 raeburn 9353: }
1.398 raeburn 9354: if (exists($changes{'internal.selfenroll_approval'})) {
9355: if ($changes{'internal.selfenroll_approval'} !~ /^[012]$/) {
9356: $changes{'internal.selfenroll_approval'} = '0';
9357: }
9358: $newval = $selfdescs{'approval'}{$changes{'internal.selfenroll_approval'}};
1.276 raeburn 9359: } else {
1.398 raeburn 9360: my $currapproval = $currsettings->{'selfenroll_approval'};
9361: if ($currapproval !~ /^[012]$/) {
9362: $currapproval = 0;
1.276 raeburn 9363: }
1.398 raeburn 9364: $newval = $selfdescs{'approval'}{$currapproval};
1.276 raeburn 9365: }
9366: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval));
9367: if ($newnotify) {
1.277 raeburn 9368: $r->print('<br />'.&mt('The following will be notified when an enrollment request needs approval, or has been approved: [_1].',$newnotify));
1.276 raeburn 9369: } else {
1.277 raeburn 9370: $r->print('<br />'.&mt('No notifications sent when an enrollment request needs approval, or has been approved.'));
1.276 raeburn 9371: }
9372: $r->print('</li>'."\n");
9373: }
1.237 raeburn 9374: } else {
9375: if (exists($changes{'internal.selfenroll_'.$item})) {
1.241 raeburn 9376: my $newval = $changes{'internal.selfenroll_'.$item};
9377: if ($item eq 'types') {
9378: if ($newval eq '') {
9379: $newval = &mt('None');
9380: } elsif ($newval eq '*') {
9381: $newval = &mt('Any user in any domain');
9382: }
1.245 raeburn 9383: } elsif ($item eq 'registered') {
9384: if ($newval eq '1') {
9385: $newval = &mt('Yes');
9386: } elsif ($newval eq '0') {
9387: $newval = &mt('No');
9388: }
1.241 raeburn 9389: }
1.244 bisitz 9390: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval).'</li>'."\n");
1.237 raeburn 9391: }
9392: }
9393: }
9394: $r->print('</ul>');
1.398 raeburn 9395: if ($env{'course.'.$cid.'.description'} ne '') {
9396: my %newenvhash;
9397: foreach my $key (keys(%changes)) {
9398: $newenvhash{'course.'.$cid.'.'.$key} = $changes{$key};
9399: }
9400: &Apache::lonnet::appenv(\%newenvhash);
1.237 raeburn 9401: }
9402: } else {
1.398 raeburn 9403: $r->print(&mt('An error occurred when saving changes to self-enrollment settings in this course.').'<br />'.
9404: &mt('The error was: [_1].',$putresult));
1.237 raeburn 9405: }
9406: } else {
1.249 raeburn 9407: $r->print(&mt('No changes were made to the existing self-enrollment settings in this course.'));
1.237 raeburn 9408: }
9409: } else {
1.249 raeburn 9410: $r->print(&mt('No changes were made to the existing self-enrollment settings in this course.'));
1.241 raeburn 9411: }
1.400 raeburn 9412: my $visactions = &cat_visibility();
9413: my ($cathash,%cattype);
9414: my %domconfig = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom);
9415: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
9416: $cathash = $domconfig{'coursecategories'}{'cats'};
9417: $cattype{'auth'} = $domconfig{'coursecategories'}{'auth'};
9418: $cattype{'unauth'} = $domconfig{'coursecategories'}{'unauth'};
9419: } else {
9420: $cathash = {};
9421: $cattype{'auth'} = 'std';
9422: $cattype{'unauth'} = 'std';
9423: }
9424: if (($cattype{'auth'} eq 'none') && ($cattype{'unauth'} eq 'none')) {
9425: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
9426: '<br />'.
9427: '<br />'.$visactions->{'take'}.'<ul>'.
9428: '<li>'.$visactions->{'dc_chgconf'}.'</li>'.
9429: '</ul>');
9430: } elsif (($cattype{'auth'} !~ /^(std|domonly)$/) && ($cattype{'unauth'} !~ /^(std|domonly)$/)) {
9431: if ($currsettings->{'uniquecode'}) {
9432: $r->print('<span class="LC_info">'.$visactions->{'vis'}.'</span>');
9433: } else {
1.366 bisitz 9434: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
1.400 raeburn 9435: '<br />'.
9436: '<br />'.$visactions->{'take'}.'<ul>'.
9437: '<li>'.$visactions->{'dc_setcode'}.'</li>'.
9438: '</ul><br />');
9439: }
9440: } else {
9441: my ($visible,$cansetvis,$vismsgs) = &visible_in_stdcat($cdom,$cnum,\%domconfig);
9442: if (ref($visactions) eq 'HASH') {
9443: if (!$visible) {
9444: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
9445: '<br />');
9446: if (ref($vismsgs) eq 'ARRAY') {
9447: $r->print('<br />'.$visactions->{'take'}.'<ul>');
9448: foreach my $item (@{$vismsgs}) {
9449: $r->print('<li>'.$visactions->{$item}.'</li>');
9450: }
9451: $r->print('</ul>');
1.256 raeburn 9452: }
1.400 raeburn 9453: $r->print($cansetvis);
1.256 raeburn 9454: }
9455: }
9456: }
1.237 raeburn 9457: return;
9458: }
9459:
1.27 matthew 9460: #---------------------------------------------- end functions for &phase_two
1.29 matthew 9461:
9462: #--------------------------------- functions for &phase_two and &phase_three
9463:
9464: #--------------------------end of functions for &phase_two and &phase_three
1.372 raeburn 9465:
1.1 www 9466: 1;
9467: __END__
1.2 www 9468:
9469:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>